Compare commits
No commits in common. "14b0d6fa85d93abd8c685e5e707120a519740e7e" and "4fe620f50a05f6263add1305a7a1c5a34907fac7" have entirely different histories.
14b0d6fa85
...
4fe620f50a
30 changed files with 223 additions and 992 deletions
|
|
@ -18,31 +18,14 @@ and PUTs with ordinary CSRF protection — no endpoint in this app is exempt.
|
|||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>arthur</title>
|
||||
<link rel="stylesheet" href="{% static 'arthur/app.css' %}?v={{ css_version }}">
|
||||
<link rel="manifest" href="{% static 'arthur/manifest.webmanifest' %}">
|
||||
<meta name="theme-color" content="#e4e4e1">
|
||||
<link rel="icon" type="image/png" href="{% static 'arthur/icons/icon-192.png' %}">
|
||||
<link rel="apple-touch-icon" href="{% static 'arthur/icons/icon-180.png' %}">
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
<meta name="apple-mobile-web-app-title" content="arthur">
|
||||
</head>
|
||||
<body>
|
||||
{% csrf_token %}
|
||||
<div id="app"></div>
|
||||
<script src="{% static 'mediapipe/vision_bundle.js' %}"></script>
|
||||
<script src="{% static 'arthur/js/main.js' %}?v={{ js_version }}"></script>
|
||||
<script>
|
||||
// An installable app that opens offline, and keeps what projects load —
|
||||
// see `static/arthur/sw.js`.
|
||||
if ('serviceWorker' in navigator) {
|
||||
navigator.serviceWorker.register('/sw.js');
|
||||
navigator.serviceWorker.ready.then(reg => reg.active.postMessage({
|
||||
keep: [...document.querySelectorAll('link[rel=stylesheet], script[src]')]
|
||||
.map(el => el.href || el.src)
|
||||
}));
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -760,17 +760,6 @@ class PageTests(TestCase):
|
|||
# save path reads to write the X-CSRFToken header.
|
||||
self.assertIn("csrfmiddlewaretoken", body)
|
||||
|
||||
def test_the_service_worker_is_served_from_the_root(self):
|
||||
# At the root so its scope is every page — a project is /p/<id> — and
|
||||
# never cached, or a browser would keep an old worker for good.
|
||||
response = self.client.get("/sw.js")
|
||||
self.assertEqual(200, response.status_code)
|
||||
self.assertEqual("application/javascript", response["Content-Type"])
|
||||
self.assertEqual("no-cache", response["Cache-Control"])
|
||||
body = self.client.get("/").content.decode()
|
||||
self.assertIn("manifest.webmanifest", body)
|
||||
self.assertIn("serviceWorker.register('/sw.js')", body)
|
||||
|
||||
def test_the_detector_reports_a_version_derived_from_the_model(self):
|
||||
# The version is the package version plus the model asset's own hash,
|
||||
# because a version string in the client is one somebody has to remember to
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ from django.contrib.auth import login as auth_login, logout as auth_logout
|
|||
from django.core.exceptions import ValidationError
|
||||
from django.db import transaction
|
||||
from django.db.models import Q
|
||||
from django.http import FileResponse, Http404, HttpResponse, JsonResponse
|
||||
from django.http import FileResponse, HttpResponse, JsonResponse
|
||||
from django.shortcuts import render
|
||||
from django.views.decorators.http import require_http_methods
|
||||
|
||||
|
|
@ -146,22 +146,6 @@ def page(request, project_id=None, slug=None):
|
|||
})
|
||||
|
||||
|
||||
def service_worker(request):
|
||||
"""`static/arthur/sw.js`, at the root of the site.
|
||||
|
||||
A service worker controls only the paths under where it is served from, and
|
||||
a project is `/p/<id>`, so `/static/arthur/sw.js` would control nothing that
|
||||
matters. Never cached itself: a browser compares this file to decide whether
|
||||
there is a new worker, so a stale copy would keep the old one for good."""
|
||||
for root in settings.STATICFILES_DIRS:
|
||||
path = Path(root) / "arthur" / "sw.js"
|
||||
if path.exists():
|
||||
response = HttpResponse(path.read_bytes(), content_type="application/javascript")
|
||||
response["Cache-Control"] = "no-cache"
|
||||
return response
|
||||
raise Http404("no service worker")
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# the detector
|
||||
#
|
||||
|
|
|
|||
|
|
@ -66,55 +66,10 @@
|
|||
[sym]
|
||||
(= :trace (:type sym)))
|
||||
|
||||
(defonce ^:private placed-cache (atom nil))
|
||||
|
||||
(defn placements
|
||||
"Where every symbol is placed: `{sid [[owner frame] ...]}`, earliest first,
|
||||
where `owner` is the symbol whose node places it and `frame` is where in the
|
||||
owner that node starts.
|
||||
|
||||
Cached by IDENTITY of the document, as `raster` caches a palette: a document
|
||||
is a value, so the same object means the same answer, and names and the pool
|
||||
ask this once per symbol per render."
|
||||
[clip]
|
||||
(let [cached @placed-cache]
|
||||
(if (identical? clip (:clip cached))
|
||||
(:index cached)
|
||||
(let [index (-> (reduce (fn [m [owner sym]]
|
||||
(reduce (fn [m [_ n]]
|
||||
(if-let [sid (node/source n)]
|
||||
(update m sid (fnil conj [])
|
||||
[owner (:at (node/time-of n))])
|
||||
m))
|
||||
m (:nodes sym)))
|
||||
{} (:symbols clip))
|
||||
(update-vals #(vec (sort-by second %))))]
|
||||
(reset! placed-cache {:clip clip :index index})
|
||||
index))))
|
||||
|
||||
(defn owners
|
||||
"The symbols that place `sid`, each once."
|
||||
[clip sid]
|
||||
(into [] (comp (map first) (distinct)) (get (placements clip) sid)))
|
||||
|
||||
(defn symbol-name
|
||||
"What to call a symbol: its `:name`, or where it is when it has none.
|
||||
|
||||
A DRAWING IS NAMED BY WHERE IT IS DRAWN. One placed by exactly one symbol
|
||||
reads as that symbol's name and the frame it starts on — `body 12` — worked
|
||||
out on every read, so renaming the lane renames its drawings and moving one
|
||||
renames it. A symbol placed nowhere, or in two places, has no one place to be
|
||||
named by and reads as its id."
|
||||
([clip sid] (symbol-name clip sid #{}))
|
||||
([clip sid seen]
|
||||
(let [given (:name (symbol clip sid))
|
||||
[owner :as os] (owners clip sid)]
|
||||
(cond
|
||||
given given
|
||||
(and (= 1 (count os)) (not (seen owner)))
|
||||
(str (symbol-name clip owner (conj seen sid)) " "
|
||||
(js/Math.floor (second (first (get (placements clip) sid)))))
|
||||
:else (name sid)))))
|
||||
"What to call a symbol: its `:name`, or its id when it has none."
|
||||
[clip sid]
|
||||
(or (:name (symbol clip sid)) (name sid)))
|
||||
|
||||
(defn node-label
|
||||
"What to call node `n` on screen.
|
||||
|
|
|
|||
|
|
@ -253,23 +253,6 @@
|
|||
[clip sid id]
|
||||
(clip/update-symbol clip sid update :nodes #(apply dissoc % (subtree % id))))
|
||||
|
||||
(defn delete-symbol
|
||||
"Symbol `sid` gone from the library, with every node that places it — as
|
||||
deleting a library item in Flash takes its instances with it. What it placed
|
||||
stays, placed nowhere now, for whoever deletes it next. `{:clip}`, or
|
||||
`{:refused why}` for the root, which is what the document opens on."
|
||||
[clip sid]
|
||||
(cond
|
||||
(not (clip/symbol clip sid)) {:refused "there is no such symbol"}
|
||||
(= sid (clip/opens-on clip)) {:refused "the project opens on this symbol; it cannot be deleted"}
|
||||
:else
|
||||
{:clip (reduce (fn [c [owner _]]
|
||||
(reduce (fn [c [id n]]
|
||||
(if (= sid (node/source n)) (delete-node c owner id) c))
|
||||
c (:nodes (clip/symbol c owner))))
|
||||
(update clip :symbols dissoc sid)
|
||||
(:symbols clip))}))
|
||||
|
||||
(defn- transplant
|
||||
"Move node `id` from symbol `host`, where frame `frame` is showing, into symbol
|
||||
`target`, keeping where it is on screen and when. `carry` is the matrix from
|
||||
|
|
|
|||
|
|
@ -701,7 +701,7 @@
|
|||
(when (clip/symbol clip drawing-id) "the new drawing ID is already used"))]
|
||||
{:refused why}
|
||||
(place (assoc-in clip [:symbols drawing-id]
|
||||
{:id drawing-id :frames 1 :nodes {}})
|
||||
{:id drawing-id :name (name drawing-id) :frames 1 :nodes {}})
|
||||
sid id drawing-id at extent true)))
|
||||
|
||||
(defn reuse-drawing
|
||||
|
|
@ -774,7 +774,7 @@
|
|||
(clip/symbol clip drawing-id) "the new drawing ID is already used")]
|
||||
{:refused why}
|
||||
(let [c (assoc-in clip [:symbols drawing-id]
|
||||
{:id drawing-id :frames 1 :nodes {}})
|
||||
{:id drawing-id :name (name drawing-id) :frames 1 :nodes {}})
|
||||
nodes (assoc nodes id (held id drawing-id at))]
|
||||
(claim c sid nodes id extent remainder-id)))))
|
||||
|
||||
|
|
@ -810,10 +810,10 @@
|
|||
:else
|
||||
(let [c (assoc-in clip [:symbols drawing-id]
|
||||
(if from
|
||||
;; No name: it is a new drawing, named by where it
|
||||
;; is drawn, and two of one name is a question nobody asked.
|
||||
(-> (clip/symbol clip from) (assoc :id drawing-id) (dissoc :name))
|
||||
{:id drawing-id :frames 1 :nodes {}}))]
|
||||
;; Its own name: it is a new drawing, and two of one
|
||||
;; name in the library is a question nobody asked.
|
||||
(assoc (clip/symbol clip from) :id drawing-id :name (name drawing-id))
|
||||
{:id drawing-id :name (name drawing-id) :frames 1 :nodes {}}))]
|
||||
(if (= f next-lo)
|
||||
;; A cel starts right here, so there is no room: make some.
|
||||
(place c sid new-id drawing-id f extent true)
|
||||
|
|
|
|||
|
|
@ -694,9 +694,9 @@
|
|||
;; a rename coalesce with whatever edit happened next.
|
||||
;;
|
||||
;; BLANK REMOVES THE NAME rather than storing an empty one. `clip/symbol-name`
|
||||
;; falls back to where the symbol is drawn, or its id, so a symbol cleared of
|
||||
;; its name reads as `body 12` or `main` again instead of as a row with
|
||||
;; nothing on it — and the document carries no field it did not need.
|
||||
;; falls back to the id, so a symbol cleared of its name reads as `main`
|
||||
;; again instead of as a row with nothing on it — and the document carries no
|
||||
;; field it did not need.
|
||||
(let [value (not-empty (str/trim (str value)))]
|
||||
(if-not (clip/symbol (:clip (store/entry (:clip/current db))) sid)
|
||||
db
|
||||
|
|
|
|||
|
|
@ -584,31 +584,11 @@
|
|||
(edit/transaction (constantly (:clip r)))
|
||||
(select-results []))))))))
|
||||
|
||||
(defn- paste-anchor
|
||||
"The selection a paste goes by: the selection, except in Figma's two cases.
|
||||
|
||||
A paste goes into what is selected and selects what it made. Pasting again
|
||||
onto your own paste therefore means another one beside it, not one inside the
|
||||
last — so while the selection is still exactly what the last paste made, it
|
||||
goes where that one went. And pasting with the very thing you copied still
|
||||
selected means a copy of it beside it: inside itself is a cycle, and was
|
||||
refused. Select anything else and paste follows the selection again."
|
||||
[db]
|
||||
(let [{:keys [made from]} (get-in db [:ui :paste])
|
||||
primary (get-in db [:ui :selection])
|
||||
path (nth primary 3 nil)
|
||||
copied (into #{} (map :path) (get-in db [:ui :clipboard :items]))]
|
||||
(cond
|
||||
(and made (= made (current-selections db))) from
|
||||
(and (seq path) (contains? copied path)) (let [up (pop (vec path))]
|
||||
[:node nil (peek up) up])
|
||||
:else primary)))
|
||||
|
||||
(defn paste-destination
|
||||
"The effective creation context at the playhead, in the destination's frames."
|
||||
[db clip st]
|
||||
(creation/target clip st (get-in db [:ui :open])
|
||||
(paste-anchor db) (editing-frame db clip)))
|
||||
(get-in db [:ui :selection]) (editing-frame db clip)))
|
||||
|
||||
(rf/reg-event-db
|
||||
::paste
|
||||
|
|
@ -622,11 +602,10 @@
|
|||
r (clipboard/paste clip payload sid frame {:fresh-id random-uuid})]
|
||||
(if-let [why (:refused r)]
|
||||
(command-refused db why)
|
||||
(let [made (mapv (fn [id] [:node sid id (conj path id)]) (:roots r))]
|
||||
(-> db
|
||||
(edit/transaction (constantly (:clip r)))
|
||||
(select-results made)
|
||||
(assoc-in [:ui :paste] {:from (paste-anchor db) :made made})))))))))
|
||||
(-> db
|
||||
(edit/transaction (constantly (:clip r)))
|
||||
(select-results
|
||||
(mapv (fn [id] [:node sid id (conj path id)]) (:roots r))))))))))
|
||||
|
||||
(defn- duplicate-selected [db unique?]
|
||||
(let [clip (:clip (store/entry (:clip/current db)))
|
||||
|
|
@ -711,8 +690,12 @@
|
|||
(fn [db [_ size]] (assoc-in db [:ui :brush] (-> size js/Math.round (max 1) (min 64)))))
|
||||
|
||||
(defn new-lane-drawing
|
||||
"Create the one-frame drawing cel implied by drawing with a lane row active,
|
||||
where the lane shows nothing at the playhead — see `polygon-landing`.
|
||||
"Create the one-frame drawing cel implied by drawing with a lane row active.
|
||||
|
||||
A lane is an insertion surface, so this always makes a new cel at the
|
||||
playhead. Existing content at that frame is claimed and trimmed by
|
||||
`overwrite-drawing`. Selecting an existing cel resolves to that cel's ordinary
|
||||
source symbol before this function is reached, and therefore draws inside it.
|
||||
|
||||
`overwrite-drawing` rather than `append-drawing`, because a gap already has
|
||||
the room. Appending RIPPLES everything after it later by the new clip's
|
||||
|
|
@ -731,31 +714,17 @@
|
|||
made
|
||||
{:clip (:clip made) :sid sid :path (conj (vec path) cel-id)}))))
|
||||
|
||||
(defn- showing
|
||||
"The id of the clip of lane `sid` that is on screen at the lane's frame `f`,
|
||||
or nil where the lane shows nothing."
|
||||
[clip sid f]
|
||||
(some (fn [[id n]]
|
||||
(when-let [[lo hi] (node/placed-span n)]
|
||||
(when (and (node/source n) (<= lo f) (< f hi)) id)))
|
||||
(get-in clip [:symbols sid :nodes])))
|
||||
|
||||
(defn polygon-landing
|
||||
"Choose the document and row path a finished polygon is drawn into.
|
||||
|
||||
DRAWING IN A LANE DRAWS INTO WHAT IT SHOWS. With the lane as the target, the
|
||||
drawing on screen at the playhead is what you are drawing on, so the shape
|
||||
goes into it — exactly as if that cel were selected. Only where the lane shows
|
||||
nothing is a new cel made; a new drawing over an old one is K's job, and ⇧K's,
|
||||
not a side effect of the brush."
|
||||
A resolved lane always gets a new drawing cel. A selected cel resolves to its
|
||||
source symbol instead, so drawing there adds a child to that existing cel."
|
||||
[clip st db]
|
||||
(let [into (creation/target clip st (get-in db [:ui :open])
|
||||
(get-in db [:ui :selection]) (editing-frame db clip))
|
||||
cel (when (= :lane (:kind into)) (showing clip (:sid into) (:frame into)))]
|
||||
(cond
|
||||
cel {:clip clip :path (conj (vec (:path into)) cel) :lane? false}
|
||||
(= :lane (:kind into)) (assoc (new-lane-drawing clip into) :lane? true)
|
||||
:else {:clip clip :sid (:sid into) :path (:path into) :lane? false})))
|
||||
(get-in db [:ui :selection]) (editing-frame db clip))]
|
||||
(if (= :lane (:kind into))
|
||||
(assoc (new-lane-drawing clip into) :lane? true)
|
||||
{:clip clip :sid (:sid into) :path (:path into) :lane? false})))
|
||||
|
||||
(defn beginning-polygon
|
||||
"Enter polygon mode, first materializing a new drawing at the playhead when
|
||||
|
|
@ -1001,7 +970,7 @@
|
|||
(or (nil? end) (>= at end))
|
||||
{:refused "the playhead is past the end of this symbol"}
|
||||
:else
|
||||
(let [new-symbol (cond-> {:id sid
|
||||
(let [new-symbol (cond-> {:id sid :name (name sid)
|
||||
;; A fresh cel is one frame for
|
||||
;; frame-by-frame work. In an
|
||||
;; ordinary composition the new
|
||||
|
|
@ -1194,8 +1163,10 @@
|
|||
(if (:refused where)
|
||||
(update db :project merge {:status (:refused where)})
|
||||
(let [seeded (assoc-in document [:symbols sid]
|
||||
(cond-> {:id sid :frames 1 :nodes {}}
|
||||
palette? (assoc :type :palette :name "palette transition")))
|
||||
(cond-> {:id sid
|
||||
:name (if palette? "palette transition" (name sid))
|
||||
:frames 1 :nodes {}}
|
||||
palette? (assoc :type :palette)))
|
||||
result (span/place-symbol seeded st (:sid where) uuid sid (:at where)
|
||||
{:extent :grow-symbol
|
||||
:remainder-id (random-uuid)
|
||||
|
|
@ -1470,73 +1441,30 @@
|
|||
(boolean (get-in db [:ui :auto-key?])) st))
|
||||
% edits))))))
|
||||
|
||||
(rf/reg-fx
|
||||
::confirm
|
||||
(fn [{:keys [message then]}]
|
||||
(when (js/confirm message) (rf/dispatch then))))
|
||||
|
||||
(rf/reg-event-fx
|
||||
::delete-symbol
|
||||
;; Out of the library, with its placements; see `nest/delete-symbol`. Its tab
|
||||
;; closes, and if it was on screen the root takes its place.
|
||||
;;
|
||||
;; ASKED FIRST WHEN IT IS PLACED, because then the delete reaches past the row
|
||||
;; you pointed at, into every symbol that uses it. One placed nowhere goes
|
||||
;; without a question; undo is there either way.
|
||||
(fn [{:keys [db]} [_ sid sure?]]
|
||||
(let [clip (:clip (store/entry (:clip/current db)))
|
||||
{gone :clip why :refused} (nest/delete-symbol clip sid)
|
||||
uses (clip/uses clip sid)]
|
||||
(cond
|
||||
why
|
||||
{:db (refused db why)}
|
||||
|
||||
(and (pos? uses) (not sure?))
|
||||
{::confirm {:message (str "Delete " (clip/symbol-name clip sid) "? It is used "
|
||||
(if (= 1 uses) "once" (str uses " times")) ", in "
|
||||
(str/join ", " (map #(clip/symbol-name clip %)
|
||||
(clip/owners clip sid)))
|
||||
", and every use of it goes too.")
|
||||
:then [::delete-symbol sid true]}}
|
||||
|
||||
:else
|
||||
(cond-> {:db (-> db
|
||||
(edit/transaction (constantly gone))
|
||||
(update-in [:ui :tabs] #(vec (remove #{sid} %)))
|
||||
(update :ui (fn [ui]
|
||||
(cond-> ui
|
||||
(= [:symbol sid] (:selection ui))
|
||||
(assoc :selection nil :selections [])))))}
|
||||
(= sid (get-in db [:ui :open]))
|
||||
(assoc :dispatch [::playback/open-symbol (clip/opens-on gone)]))))))
|
||||
|
||||
(rf/reg-event-fx
|
||||
(rf/reg-event-db
|
||||
::delete-selected
|
||||
;; Backspace while drawing takes the last point back, as in Illustrator; on
|
||||
;; the pen, with a point of the selected shape picked, it takes that point. A
|
||||
;; symbol picked in the pool is deleted from the library.
|
||||
(fn [{:keys [db]} _]
|
||||
;; the pen, with a point of the selected shape picked, it takes that point.
|
||||
(fn [db _]
|
||||
(let [[vsid vid i] (get-in db [:ui :vertex])
|
||||
primary (get-in db [:ui :selection])]
|
||||
(cond
|
||||
(seq (get-in db [:ui :draft]))
|
||||
{:db (update-in db [:ui :draft] #(subvec % 0 (- (count %) 2)))}
|
||||
(update-in db [:ui :draft] #(subvec % 0 (- (count %) 2)))
|
||||
|
||||
(and i (= :pen (get-in db [:ui :tool])) (= [:node vsid vid] (take 3 primary)))
|
||||
{:db (deleting-vertex db vsid vid i)}
|
||||
|
||||
(= :symbol (first primary))
|
||||
{:dispatch [::delete-symbol (second primary)]}
|
||||
(deleting-vertex db vsid vid i)
|
||||
|
||||
:else
|
||||
(let [many (vec (get-in db [:ui :selections]))
|
||||
selections (if (some #{primary} many) many (if primary [primary] []))
|
||||
nodes (distinct (keep (fn [[kind sid id]] (when (= :node kind) [sid id])) selections))]
|
||||
(when (seq nodes)
|
||||
{:db (-> db
|
||||
(edit/transaction #(reduce (fn [c [sid id]] (nest/delete-node c sid id)) % nodes))
|
||||
(assoc-in [:ui :selection] nil)
|
||||
(assoc-in [:ui :selections] []))}))))))
|
||||
(if (seq nodes)
|
||||
(-> db
|
||||
(edit/transaction #(reduce (fn [c [sid id]] (nest/delete-node c sid id)) % nodes))
|
||||
(assoc-in [:ui :selection] nil)
|
||||
(assoc-in [:ui :selections] []))
|
||||
db))))))
|
||||
|
||||
(rf/reg-event-db
|
||||
::restack
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@
|
|||
[arthur.domain.nest :as nest]
|
||||
[arthur.domain.node :as node]
|
||||
[arthur.domain.pick :as pick]
|
||||
[arthur.domain.symbol :as symbol]
|
||||
[arthur.footage.store :as store]
|
||||
[arthur.subs.playback :as playback]
|
||||
[arthur.subs.render :as render]
|
||||
|
|
@ -109,30 +108,6 @@
|
|||
(when clip
|
||||
(creation/target clip (:store (store/entry clip-id)) open selection f))))
|
||||
|
||||
(rf/reg-sub
|
||||
::onion-scope
|
||||
:<- [::selection]
|
||||
:<- [::render/clip]
|
||||
:<- [::render/clip-id]
|
||||
:<- [::render/open]
|
||||
:<- [::render/open-frame]
|
||||
;; WHAT ONION SKIN GHOSTS: the selection's row, or the lane it is in. A cel,
|
||||
;; and anything drawn in one, is on screen for its own few frames, so ghosting
|
||||
;; it ghosts nothing either side — and drawing selects the shape just drawn,
|
||||
;; which put the onion out at the first stroke. A lane's neighbours are its
|
||||
;; other drawings, which is what onion skin is for. The nearest lane, so a
|
||||
;; lane drawn inside a cel of another ghosts its own drawings.
|
||||
(fn [[[kind _ id path] clip clip-id open f] _]
|
||||
(if-not (= :node kind)
|
||||
[]
|
||||
(let [path (vec (or path [id]))
|
||||
st (some-> clip-id store/entry :store)
|
||||
lane? #(when-let [{:keys [sid]} (and clip (nest/inside clip st open % f))]
|
||||
(symbol/lane? (clip/symbol clip sid)))]
|
||||
(or (some #(let [up (pop %)] (when (and (seq up) (lane? up)) up))
|
||||
(take-while seq (iterate pop path)))
|
||||
path)))))
|
||||
|
||||
(rf/reg-sub
|
||||
::creation-placement
|
||||
:<- [::creation-target]
|
||||
|
|
|
|||
|
|
@ -30,7 +30,6 @@
|
|||
(def ^:private glyphs
|
||||
{:start {:fill ["M2 2.5h1.3v7H2z" ; the bar it stops against
|
||||
"M10 2.5v7L4.2 6z"]} ; and the triangle into it
|
||||
:end {:fill ["M8.7 2.5H10v7H8.7z" "M2 2.5v7L7.8 6z"]}
|
||||
:play {:fill ["M3.4 2.3L10 6 3.4 9.7z"]}
|
||||
:pause {:fill ["M3.3 2.4h1.9v7.2H3.3z"
|
||||
"M6.8 2.4h1.9v7.2H6.8z"]}
|
||||
|
|
@ -61,19 +60,7 @@
|
|||
:hold {:fill ["M1.5 8h2v2h-2z" "M8.5 2h2v2h-2z"] :stroke ["M3.5 9H9.5V4"]}
|
||||
;; How an instance plays: through once into a stop, round, or one frame.
|
||||
:once {:fill ["M2.4 2.6 7.6 6 2.4 9.4z" "M8.4 2.6h1.4v6.8H8.4z"]}
|
||||
:still {:stroke ["M3.5 2.5h5v7h-5z"] :fill ["M5 4.5h2v3H5z"]}
|
||||
;; A new drawing in a lane: a sheet, with a line on it — the one at the
|
||||
;; playhead carried on — or bare.
|
||||
:drawing {:stroke ["M3 1.5h4.5l2 2v7h-6.5z" "M4.6 7.8 5.9 6.1 7.4 7.3"]}
|
||||
:blank {:stroke ["M3 1.5h4.5l2 2v7h-6.5z"]}
|
||||
;; The clipboard, as every editor draws it: two sheets, scissors, a board,
|
||||
;; and two sheets with one more.
|
||||
:copy {:stroke ["M4.5 4.5h5v5h-5z" "M2.5 7.5v-5h5"]}
|
||||
:cut {:stroke ["M2 9a1.5 1.5 0 1 0 3 0a1.5 1.5 0 1 0 -3 0"
|
||||
"M7 9a1.5 1.5 0 1 0 3 0a1.5 1.5 0 1 0 -3 0"
|
||||
"M4.4 7.8 8.5 2" "M7.6 7.8 3.5 2"]}
|
||||
:paste {:stroke ["M3.8 2.5H2.5v8h7v-8H8.2" "M4.5 1.5h3v2h-3z"]}
|
||||
:duplicate {:stroke ["M4.5 4.5h5v5h-5z" "M2.5 7.5v-5h5" "M7 5.8v2.4" "M5.8 7h2.4"]}})
|
||||
:still {:stroke ["M3.5 2.5h5v7h-5z"] :fill ["M5 4.5h2v3H5z"]}})
|
||||
|
||||
(defn view
|
||||
"The glyph named `k`, sized by CSS and inked in `currentColor` — so a button's
|
||||
|
|
|
|||
|
|
@ -140,8 +140,7 @@
|
|||
;; symbol's stacking context.
|
||||
:target (rf/subscribe [::ui-sub/creation-target])
|
||||
:onion (rf/subscribe [::layout/onion])
|
||||
:selection (rf/subscribe [::ui-sub/selection])
|
||||
:ghosting (rf/subscribe [::ui-sub/onion-scope])})
|
||||
:selection (rf/subscribe [::ui-sub/selection])})
|
||||
(fn [{:keys [draft hover tone fit target] :as s} _]
|
||||
(-> s
|
||||
(dissoc :draft :hover :tone :fit :target)
|
||||
|
|
@ -164,8 +163,8 @@
|
|||
;; in the editor's own state, so it changes what the canvases should
|
||||
;; show without touching the frame number OR the resolver.
|
||||
(when-not (and (identical? (:resolver before) (:resolver now))
|
||||
(= (select-keys before [:tracing :pen :mat :onion :selection :ghosting :playing? :preview :solo?])
|
||||
(select-keys now [:tracing :pen :mat :onion :selection :ghosting :playing? :preview :solo?])))
|
||||
(= (select-keys before [:tracing :pen :mat :onion :selection :playing? :preview :solo?])
|
||||
(select-keys now [:tracing :pen :mat :onion :selection :playing? :preview :solo?])))
|
||||
(repaint!))))))
|
||||
|
||||
;; The brush or eraser stroke being painted: its mask, mutated in place as the
|
||||
|
|
@ -196,14 +195,14 @@
|
|||
(declare op-path reach)
|
||||
|
||||
(defn- paint-onions!
|
||||
"Ghost the picture `onion/frames` either side of `f`: the ops of
|
||||
`::ui-sub/onion-scope` — the selection's row, or the lane it is in —
|
||||
everything when nothing is selected. Each ghost is rasterised as
|
||||
"Ghost the picture `onion/frames` either side of `f`: the selected node's ops
|
||||
when a node is selected, everything otherwise. Each ghost is rasterised as
|
||||
far as it reaches inside `[vx vy wx wy]`, what is on screen, as the picture
|
||||
is, and the canvas covers them all."
|
||||
[f [vx vy wx wy]]
|
||||
(let [{:keys [onion-canvas]} @state
|
||||
{:keys [onion playing? resolver frames width height] path :ghosting} @snapshot
|
||||
{:keys [onion playing? resolver frames selection width height]} @snapshot
|
||||
path (if (= :node (first selection)) (or (nth selection 3 nil) [(nth selection 2)]) [])
|
||||
ghosts (when (and onion-canvas (:on? onion) (not playing?))
|
||||
(into []
|
||||
(keep (fn [{:keys [frame direction]}]
|
||||
|
|
|
|||
|
|
@ -15,12 +15,13 @@
|
|||
looking at and puts the number on its tab.
|
||||
|
||||
THE MAIN TIMELINE LEADS, and it is `clip/opens-on`'s answer rather than a
|
||||
name: the symbol the project plays and the one the work happens in, so it gets
|
||||
the top of the pane and a row drawn at a size you can read a pose off. Every
|
||||
other symbol is the tree under it: what nothing places beside it at the top,
|
||||
and the rest under whatever places it — see `this-project`. None of it is
|
||||
`:main` being special either: rename it, place it inside something else, and
|
||||
the pool follows the document.
|
||||
name: the longest symbol nothing else places is the one the project plays and
|
||||
the one the work happens in, so it gets the top of the pane and a row drawn at
|
||||
a size you can read a pose off. Every other symbol is the list under it. That
|
||||
is one list and not two — every symbol here IS a timeline, and heading a
|
||||
section TIMELINES and the next one SYMBOLS would name the same thing twice.
|
||||
None of it is `:main` being special either: rename it, place it inside
|
||||
something else, and the pool follows the document.
|
||||
|
||||
Every row is a drag source, and what it carries says what it is:
|
||||
`symbol:<id>` for a symbol of this document, `import:<project>|<cid>|<id>` for
|
||||
|
|
@ -198,27 +199,13 @@
|
|||
its own under the name — `sub2` — rather than one of them out at the edge.
|
||||
|
||||
`rename` is `{:key :value :begin! :commit!}` and is what makes a row
|
||||
renameable at all: a row without one has no pencil and does not answer F2.
|
||||
|
||||
`depth` puts a row in a tree: indented that far, with a twisty ahead of it.
|
||||
`inside` is `{:count :open? :flip!}` for a row with rows under it; a row with
|
||||
none keeps the twisty's room, so names line up down a level.
|
||||
|
||||
`delete!` puts a cross beside the pencil, on hover as the pencil is."
|
||||
[{:keys [label sub sub2 title thumb on? open? main? disabled? rename depth inside delete!]
|
||||
:as opts}]
|
||||
renameable at all: a row without one has no pencil and does not answer F2."
|
||||
[{:keys [label sub sub2 title thumb on? open? main? disabled? rename] :as opts}]
|
||||
(let [{:keys [key value begin! commit!]} rename
|
||||
editing? (boolean (and key (= key (:editing rename))))]
|
||||
[:div.pool-row {:class (str (when main? "main ") (when on? "on ")
|
||||
(when open? "open ") (when disabled? "disabled ")
|
||||
(when editing? "editing"))
|
||||
:style (when depth {:padding-left (+ 4 (* 10 depth))})}
|
||||
(when depth
|
||||
(if-let [{:keys [count open? flip!]} inside]
|
||||
[:span.pool-twisty {:title (str count " inside")
|
||||
:on-click (fn [^js e] (.stopPropagation e) (flip!))}
|
||||
(if open? "\u25BE" "\u25B8")]
|
||||
[:span.pool-twisty]))
|
||||
(when editing? "editing"))}
|
||||
(if editing?
|
||||
;; The input REPLACES the row rather than floating over it, so the list
|
||||
;; does not change height while you type in it.
|
||||
|
|
@ -248,7 +235,7 @@
|
|||
(.preventDefault e)
|
||||
(begin! key))))}
|
||||
(dissoc opts :label :sub :sub2 :title :on? :open? :main?
|
||||
:disabled? :thumb :rename :depth :inside :delete!))
|
||||
:disabled? :thumb :rename))
|
||||
thumb
|
||||
[:span.text
|
||||
;; The label is `.text`'s first child and stays that way: it is how
|
||||
|
|
@ -263,19 +250,13 @@
|
|||
;; being avoided, and F2 already reaches it from the keyboard.
|
||||
:on-click (fn [^js e] (.stopPropagation e) (begin! key))}
|
||||
"\u270E"])
|
||||
(when delete!
|
||||
[:span.pool-rename.pool-delete
|
||||
{:title (str "delete " label " (Delete)")
|
||||
:on-click (fn [^js e] (.stopPropagation e) (delete!))}
|
||||
"\u00D7"])
|
||||
;; The main row says both its facts under the name instead.
|
||||
(when (and sub (not main?)) [:span.sub sub])]])]))
|
||||
|
||||
;; ---------------------------------------------------------------------------
|
||||
;; the rows of each kind
|
||||
|
||||
(defn- symbol-row [document sid {:keys [clip-id store palette selection open main rename
|
||||
depth inside]}]
|
||||
(defn- symbol-row [document sid {:keys [clip-id store palette selection open main rename]}]
|
||||
(let [sym (clip/symbol document sid)
|
||||
label (clip/symbol-name document sid)
|
||||
nodes (count (:nodes sym))]
|
||||
|
|
@ -295,9 +276,6 @@
|
|||
:on? (= selection [:symbol sid])
|
||||
:open? (= sid open)
|
||||
:main? (= sid main)
|
||||
:depth depth
|
||||
:inside inside
|
||||
:delete! (when-not (= sid main) #(rf/dispatch [::ui/delete-symbol sid]))
|
||||
:rename (assoc rename
|
||||
:key [:symbol sid]
|
||||
:value label
|
||||
|
|
@ -449,62 +427,23 @@
|
|||
[:div.pool-empty "no match in this scope"]
|
||||
(into [:<>] (map section) children)))
|
||||
|
||||
(def ^:private own-section?
|
||||
"Symbols with a section of their own, kept out of the tree."
|
||||
#{:palette :palette-track :trace})
|
||||
|
||||
(defn- listed? [document sid]
|
||||
(not (own-section? (:type (clip/symbol document sid)))))
|
||||
|
||||
(defn- placed-in
|
||||
"What each symbol places, as `{owner [sid ...]}`: each once, in the order they
|
||||
first start in it."
|
||||
[document]
|
||||
(reduce-kv (fn [m sid at]
|
||||
(if (listed? document sid)
|
||||
(reduce-kv (fn [m owner [[_ f]]] (update m owner (fnil conj []) [f sid]))
|
||||
m (group-by first at))
|
||||
m))
|
||||
{} (clip/placements document)))
|
||||
|
||||
(defn- tree
|
||||
"`sid`'s row and, while it is open, the rows of what it places under it. A
|
||||
symbol placed in two symbols is under both. `path` is what this row is under,
|
||||
which keys the row and stops a cycle."
|
||||
[{:keys [document placed expanded flip! main] :as ctx} sid depth path]
|
||||
(let [kids (->> (get placed sid) (sort-by (juxt first (comp str second)))
|
||||
(map second) (remove (set (conj path sid))))
|
||||
root? (and (= main sid) (empty? path))
|
||||
open? (and (seq kids) (or root? (contains? expanded [path sid])))]
|
||||
(into [(with-meta (symbol-row document sid
|
||||
(assoc ctx :depth depth
|
||||
:inside (when (and (seq kids) (not root?))
|
||||
{:count (count kids) :open? open?
|
||||
:flip! #(flip! [path sid])})))
|
||||
{:key (str (conj path sid))})]
|
||||
(when open?
|
||||
(mapcat #(tree ctx % (inc depth) (conj path sid)) kids)))))
|
||||
|
||||
(defn- this-project
|
||||
"The open document's own: its symbols as the tree of what places what, then
|
||||
each kind with a section of its own.
|
||||
"The open document's own, with the main timeline at the top and every other
|
||||
symbol under it.
|
||||
|
||||
WHAT NOTHING PLACES IS AT THE TOP, and everything else is under what places
|
||||
it. Drawing makes a symbol per drawing, and a flat list of every one buries the
|
||||
few that matter; a drawing is under its lane, its lane under its scene. What
|
||||
is left at the top is the root the project opens on, drawn big and first with
|
||||
what it places always showing under it, and
|
||||
whatever is placed nowhere — a scene, something made to be placed later, or
|
||||
something left behind — which is what wants looking at: keep it, place it, or
|
||||
delete it. Nothing is ever cleared away for you.
|
||||
NOT \"TIMELINES AND SYMBOLS\". Every symbol in this model IS a timeline — it
|
||||
has frames and nodes and you open it and work in it — so a pair of headings
|
||||
naming those two things names one thing twice, and invites a reader to go
|
||||
looking for the difference. There is one list of symbols. What is true is that
|
||||
exactly one of them is where the work happens: `clip/opens-on`'s answer, the
|
||||
longest symbol nothing else places. That gets the top of the pane and a row
|
||||
drawn like the thing it is, and the rest of the library is the list below it.
|
||||
|
||||
One rule for every symbol, worked out from the document on each render and
|
||||
stored nowhere: place it, unplace it, and the pool follows.
|
||||
|
||||
A SEARCH IS FLAT: you asked for it by name, and a hit inside a closed twisty is
|
||||
a hit you cannot see."
|
||||
Still not `:main` being special. The document says which symbol that is by its
|
||||
structure; rename it, place it inside something else, and the pool follows."
|
||||
[{:keys [document query searching? media sounds images chosen rename main selection] :as ctx}]
|
||||
(let [named? #(hit? query (clip/symbol-name document %))
|
||||
top (when (and main (named? main)) main)
|
||||
symbol-ids (sort-by str (keys (:symbols document)))
|
||||
transition-ids (into #{} (mapcat (fn [sym]
|
||||
(when (= :palette-track (:type sym))
|
||||
|
|
@ -515,24 +454,22 @@
|
|||
transitions (filterv #(and (named? %) (transition? %)) symbol-ids)
|
||||
tracing (filterv #(and (named? %) (clip/trace? (clip/symbol document %)))
|
||||
symbol-ids)
|
||||
listed (filterv #(listed? document %) symbol-ids)
|
||||
symbols (if searching?
|
||||
(mapv #(symbol-row document % ctx) (filterv named? listed))
|
||||
(let [ctx (assoc ctx :placed (placed-in document))
|
||||
top (cond->> (filterv #(and (not= main %)
|
||||
(empty? (clip/owners document %)))
|
||||
listed)
|
||||
(contains? (:symbols document) main) (into [main]))]
|
||||
(into [] (mapcat #(tree ctx % 0 [])) top)))
|
||||
rest (filterv #(and (named? %) (not= main %)
|
||||
(not (#{:palette :palette-track :trace}
|
||||
(:type (clip/symbol document %)))))
|
||||
symbol-ids)
|
||||
media (filterv #(hit? query (:label %)) media)
|
||||
sounds (filterv #(hit? query (:label %)) sounds)
|
||||
images (filterv #(hit? query (:label %)) images)]
|
||||
[sections searching?
|
||||
(+ (count symbols) (count transitions) (count tracing)
|
||||
(+ (if top 1 0) (count rest) (count transitions) (count tracing)
|
||||
(count media) (count sounds) (count images))
|
||||
[{:title "symbols" :searching? searching?
|
||||
[{:title "project" :searching? searching?
|
||||
:blank "nothing to open yet"
|
||||
:rows symbols}
|
||||
:rows (when top [(symbol-row document top ctx)])}
|
||||
{:title "symbols" :searching? searching?
|
||||
:blank "nothing else in the library"
|
||||
:rows (mapv #(symbol-row document % ctx) rest)}
|
||||
{:title "tracing layers" :searching? searching?
|
||||
:blank "no tracing layers yet"
|
||||
:rows (mapv #(symbol-row document % ctx) tracing)}
|
||||
|
|
@ -622,10 +559,7 @@
|
|||
;; Which row is being renamed, as `[kind id]`. One atom rather
|
||||
;; than a flag per row: exactly one name is ever being edited, and
|
||||
;; opening a second input has to close the first.
|
||||
editing (r/atom nil)
|
||||
;; Which tree rows are open, as `[path sid]`. Everything under
|
||||
;; the root's own children starts shut — see `tree`.
|
||||
expanded (r/atom #{})]
|
||||
editing (r/atom nil)]
|
||||
(let [{:keys [loading? status available sounds images uploaded chosen]}
|
||||
@(rf/subscribe [::playback/footage])
|
||||
document @(rf/subscribe [::sub/settled-clip])
|
||||
|
|
@ -662,9 +596,7 @@
|
|||
;; else places is the timeline the work happens in, and it is the
|
||||
;; one row in this pane drawn big enough to read a pose off.
|
||||
:main (clip/opens-on document)
|
||||
:rename {:editing @editing :begin! #(reset! editing %)}
|
||||
:expanded @expanded
|
||||
:flip! #(swap! expanded (fn [open] (if (open %) (disj open %) (conj open %))))}
|
||||
:rename {:editing @editing :begin! #(reset! editing %)}}
|
||||
tallies (counts ctx)
|
||||
files? (fn [^js e] (some #{"Files"} (array-seq (.. e -dataTransfer -types))))]
|
||||
[:section.pane.pool
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@
|
|||
(:require [arthur.events.history :as history]
|
||||
[arthur.events.playback :as pb]
|
||||
[arthur.events.ui :as ui]
|
||||
[arthur.footage.store :as store]
|
||||
[arthur.ui.layout :as layout]
|
||||
[arthur.ui.timeline :as timeline]
|
||||
[clojure.string :as str]
|
||||
|
|
@ -31,6 +32,27 @@
|
|||
[re-frame.db :as db]
|
||||
[reagent.core :as r]))
|
||||
|
||||
(defn stops
|
||||
"The frames ↑ and ↓ stop on: every key and every clip edge the timeline shows,
|
||||
as frames of the open symbol. In a lane that is drawing to drawing, on a tween
|
||||
key to key — one rule, read off the rows the timeline draws, so a jump lands
|
||||
on something you can see."
|
||||
[db]
|
||||
(let [{document :clip} (store/entry (:clip/current db))
|
||||
selection (get-in db [:ui :selection])
|
||||
n (pb/frames db)]
|
||||
(into (sorted-set)
|
||||
(comp (mapcat (fn [{:keys [keys span cels]}]
|
||||
(concat keys span (mapcat (juxt :span :keys) cels))))
|
||||
(mapcat #(if (number? %) [%] %))
|
||||
;; The first whole frame that shows it, forgiving the rounding
|
||||
;; a mapped key picks up on its way through a clock.
|
||||
(map #(js/Math.ceil (- % 1e-6)))
|
||||
(filter #(< -1 % n)))
|
||||
(when document
|
||||
(timeline/rows document (get-in db [:ui :open]) (get-in db [:ui :expanded])
|
||||
(when (= :node (first selection)) (nth selection 3)))))))
|
||||
|
||||
(defn- frame [db] (get-in db [:playback :frame] 0))
|
||||
(defn- seek [f] [::pb/seek f])
|
||||
|
||||
|
|
@ -40,10 +62,12 @@
|
|||
:note "hold and drag on the stage to pan"}
|
||||
{:label "Previous frame" :keys ["ArrowLeft" "a"] :run #(seek (dec (frame %)))}
|
||||
{:label "Next frame" :keys ["ArrowRight" "d"] :run #(seek (inc (frame %)))}
|
||||
{:label "Previous key" :keys ["ArrowDown" "s"] :run timeline/prev-key}
|
||||
{:label "Next key" :keys ["ArrowUp" "w"] :run timeline/next-key}
|
||||
{:label "Previous key" :keys ["ArrowDown" "s"]
|
||||
:run #(some-> (first (rsubseq (stops %) < (frame %))) seek)}
|
||||
{:label "Next key" :keys ["ArrowUp" "w"]
|
||||
:run #(some-> (first (subseq (stops %) > (frame %))) seek)}
|
||||
{:label "First frame" :keys ["Home" "shift+ArrowLeft" "shift+a"] :run (constantly (seek 0))}
|
||||
{:label "Last frame" :keys ["End" "shift+ArrowRight" "shift+d"] :run timeline/last-frame}
|
||||
{:label "Last frame" :keys ["End" "shift+ArrowRight" "shift+d"] :run #(seek (dec (pb/frames %)))}
|
||||
{:label "Mark in" :keys ["i"] :run (constantly [::pb/mark :in])
|
||||
:note "playback loops between the marks"}
|
||||
{:label "Mark out" :keys ["o"] :run (constantly [::pb/mark :out])}
|
||||
|
|
@ -59,12 +83,12 @@
|
|||
["Animate"
|
||||
[{:label "Key here" :keys ["k"]
|
||||
:note "in a lane, a copy of the drawing from the playhead on"
|
||||
:run timeline/key-here}
|
||||
:run #(if (ui/lane-here %) [::ui/drawing-here true] [::ui/key-selected])}
|
||||
{:label "Blank drawing here" :keys ["shift+k"] :run (constantly [::ui/drawing-here false])}
|
||||
{:label "One frame longer" :keys ["=" "+"] :note "moves the end of the selection's span"
|
||||
:run (timeline/hold 1)}
|
||||
:run #(when-let [p (ui/span-path %)] [::ui/slide p 1 :out true])}
|
||||
{:label "One frame shorter" :keys ["-"]
|
||||
:run (timeline/hold -1)}]]
|
||||
:run #(when-let [p (ui/span-path %)] [::ui/slide p -1 :out true])}]]
|
||||
["Make"
|
||||
[{:label "New symbol" :keys ["n"] :run (constantly [::ui/new :inside false])
|
||||
:note "in the selected symbol; in a lane, a blank drawing"}
|
||||
|
|
|
|||
|
|
@ -601,14 +601,6 @@
|
|||
[:circle {:class (str "first" (when (and hover (closes? draft hover)) " closing"))
|
||||
:cx fx :cy fy :r 1.8}]])))
|
||||
|
||||
(defn- abandon!
|
||||
"Whatever a pointer was doing on the stage, dropped rather than finished: the
|
||||
browser took the pointer back, or a second finger came down to move the view."
|
||||
[]
|
||||
(reset! dragging nil) (reset! marquee nil)
|
||||
(reset! painting nil) (player/stroke! nil)
|
||||
(let-go! false))
|
||||
|
||||
(defn- overlay [w h zoom [x0 y0 x1 y1]]
|
||||
(let [tool @(rf/subscribe [::sub/tool])
|
||||
draft @(rf/subscribe [::sub/draft])
|
||||
|
|
@ -642,16 +634,10 @@
|
|||
:view-box (str x0 " " y0 " " (- x1 x0) " " (- y1 y0))
|
||||
:tab-index -1
|
||||
:on-pointer-down
|
||||
;; ONE POINTER DRAWS: the first finger down. A second is the view's —
|
||||
;; see `navigation` — and fed into a stroke it zigzags between the two.
|
||||
(fn [^js event]
|
||||
(when (.-isPrimary event)
|
||||
(let [svg (.-currentTarget event)
|
||||
p (xy svg event w h)]
|
||||
;; Without scrolling it into view: the overlay is the whole work
|
||||
;; area, and a phone scrolled to show its corner, which threw the
|
||||
;; stage off screen on a tap and every point after it sideways.
|
||||
(.focus svg #js {:preventScroll true})
|
||||
(.focus svg)
|
||||
(case tool
|
||||
:pen
|
||||
(let [q (snapped draft (stage-point event w h) event)
|
||||
|
|
@ -702,7 +688,7 @@
|
|||
(.setPointerCapture svg (.-pointerId event))
|
||||
(if (and (> (count placements) 1) (contains? selected-paths path))
|
||||
(begin-many! ctx :move placements p)
|
||||
(begin! ctx :move path p))))))))
|
||||
(begin! ctx :move path p)))))))
|
||||
:on-double-click (fn [^js event]
|
||||
(when (= :select tool)
|
||||
(let [p (xy (.-currentTarget event) event w h)
|
||||
|
|
@ -720,7 +706,6 @@
|
|||
:on-pointer-leave (fn [_] (reset! pointer nil))
|
||||
:on-pointer-move
|
||||
(fn [^js event]
|
||||
(when (.-isPrimary event)
|
||||
(let [p (xy (.-currentTarget event) event w h)]
|
||||
(reset! pointer p)
|
||||
(cond
|
||||
|
|
@ -734,9 +719,8 @@
|
|||
(when (not= q hover) (rf/dispatch [::ui/hover q])))
|
||||
@repivot (swap! repivot assoc :p p)
|
||||
@marquee (swap! marquee assoc :p p)
|
||||
@gesture (drag! p event)))))
|
||||
:on-pointer-up (fn [^js event]
|
||||
(when (.-isPrimary event)
|
||||
@gesture (drag! p event))))
|
||||
:on-pointer-up (fn [_]
|
||||
(reset! dragging nil)
|
||||
(stroke-end!)
|
||||
;; One edit, at the end: see `::ui/repivot`.
|
||||
|
|
@ -751,8 +735,11 @@
|
|||
old (if more? selections [])]
|
||||
(reset! marquee nil)
|
||||
(rf/dispatch [::ui/select-many (into old addresses)]))
|
||||
(let-go! true))))
|
||||
:on-pointer-cancel (fn [_] (abandon!))}
|
||||
(let-go! true)))
|
||||
:on-pointer-cancel (fn [_]
|
||||
(reset! dragging nil) (reset! marquee nil)
|
||||
(reset! painting nil) (player/stroke! nil)
|
||||
(let-go! false))}
|
||||
[ghost]
|
||||
(when (seq selected-pts)
|
||||
[:polygon.selected-paint-outline
|
||||
|
|
@ -779,18 +766,6 @@
|
|||
|
||||
(defonce pinch-start-zoom (atom nil))
|
||||
|
||||
;; Two fingers on the stage: `{:zoom :spread :at}` as they came down, and where
|
||||
;; their middle was last.
|
||||
(defonce ^:private two (atom nil))
|
||||
|
||||
(defn- middle [^js touches]
|
||||
(let [a (aget touches 0) b (aget touches 1)]
|
||||
[(/ (+ (.-clientX a) (.-clientX b)) 2) (/ (+ (.-clientY a) (.-clientY b)) 2)]))
|
||||
|
||||
(defn- apart [^js touches]
|
||||
(let [a (aget touches 0) b (aget touches 1)]
|
||||
(js/Math.hypot (- (.-clientX a) (.-clientX b)) (- (.-clientY a) (.-clientY b)))))
|
||||
|
||||
(defn- navigation []
|
||||
{:title "Two-finger scroll to pan · Pinch or ⌘/Ctrl-wheel to zoom · Space-drag or middle-drag to pan"
|
||||
;; The picture is what is on screen, so moving or resizing the view paints
|
||||
|
|
@ -815,48 +790,11 @@
|
|||
(do
|
||||
(set! (.-scrollLeft el) (+ (.-scrollLeft el) dx))
|
||||
(set! (.-scrollTop el) (+ (.-scrollTop el) dy))))))))
|
||||
;; ON A PHONE ONE FINGER IS THE PEN AND TWO ARE THE VIEW. Nothing on
|
||||
;; the stage scrolls under one finger — `touch-action` says so, and
|
||||
;; is not trusted on an SVG in iOS — and two pan by their middle and
|
||||
;; zoom by their spread, with whatever the first had begun dropped.
|
||||
;; Properties rather than listeners, as `onwheel` is: this ref runs on
|
||||
;; every render. Not passive, being on an element, so they can stop
|
||||
;; the page.
|
||||
(set! (.-ontouchstart el)
|
||||
(fn [^js e]
|
||||
(let [ts (.-touches e)]
|
||||
(when (<= 2 (.-length ts))
|
||||
(.preventDefault e)
|
||||
(abandon!)
|
||||
(reset! two {:zoom @(rf/subscribe [::layout/zoom :stage])
|
||||
:spread (apart ts) :at (middle ts)})))))
|
||||
(set! (.-ontouchmove el)
|
||||
(fn [^js e]
|
||||
(let [ts (.-touches e)]
|
||||
(cond
|
||||
(and @two (<= 2 (.-length ts)))
|
||||
(let [{:keys [zoom at] s0 :spread} @two
|
||||
[x y :as m] (middle ts)
|
||||
z (* zoom (/ (apart ts) (max 1 s0)))]
|
||||
(.preventDefault e)
|
||||
(if (< (js/Math.abs (- 1 (/ z @(rf/subscribe [::layout/zoom :stage])))) 0.02)
|
||||
(do (set! (.-scrollLeft el) (+ (.-scrollLeft el) (- (first at) x)))
|
||||
(set! (.-scrollTop el) (+ (.-scrollTop el) (- (second at) y))))
|
||||
(layout/zoom-at! el x y z))
|
||||
(swap! two assoc :at m))
|
||||
|
||||
(.closest (.-target e) ".paint-overlay")
|
||||
(.preventDefault e)))))
|
||||
(set! (.-ontouchend el)
|
||||
(fn [^js e] (when (< (.-length (.-touches e)) 2) (reset! two nil))))
|
||||
(set! (.-ontouchcancel el) (.-ontouchend el))
|
||||
;; Safari exposes pinch as GestureEvents, with cumulative scale. On a
|
||||
;; phone the touches above have it already.
|
||||
;; Safari exposes pinch as GestureEvents, with cumulative scale.
|
||||
(set! (.-ongesturestart el)
|
||||
(fn [e]
|
||||
(.preventDefault e)
|
||||
(when-not @two
|
||||
(reset! pinch-start-zoom @(rf/subscribe [::layout/zoom :stage])))))
|
||||
(reset! pinch-start-zoom @(rf/subscribe [::layout/zoom :stage]))))
|
||||
(set! (.-ongesturechange el)
|
||||
(fn [e]
|
||||
(.preventDefault e)
|
||||
|
|
|
|||
|
|
@ -41,7 +41,6 @@
|
|||
[arthur.ui.layout :as layout]
|
||||
[arthur.ui.player :as player]
|
||||
[re-frame.core :as rf]
|
||||
[re-frame.db :as rf-db]
|
||||
[reagent.core :as r]))
|
||||
|
||||
;; ---------------------------------------------------------------------------
|
||||
|
|
@ -498,71 +497,9 @@
|
|||
(aget cel "arthurCel")))
|
||||
(array-seq (.elementsFromPoint js/document (.-clientX event) (.-clientY event)))))
|
||||
|
||||
(defn stops
|
||||
"The frames ↑ and ↓ stop on: every key and every clip edge the timeline shows,
|
||||
as frames of the open symbol. In a lane that is drawing to drawing, on a tween
|
||||
key to key — one rule, read off the rows the timeline draws, so a jump lands
|
||||
on something you can see."
|
||||
[db]
|
||||
(let [{document :clip} (store/entry (:clip/current db))
|
||||
selection (get-in db [:ui :selection])
|
||||
n (pb/frames db)]
|
||||
(into (sorted-set)
|
||||
(comp (mapcat (fn [{:keys [keys span cels]}]
|
||||
(concat keys span (mapcat (juxt :span :keys) cels))))
|
||||
(mapcat #(if (number? %) [%] %))
|
||||
;; The first whole frame that shows it, forgiving the rounding
|
||||
;; a mapped key picks up on its way through a clock.
|
||||
(map #(js/Math.ceil (- % 1e-6)))
|
||||
(filter #(< -1 % n)))
|
||||
(when document
|
||||
(rows document (get-in db [:ui :open]) (get-in db [:ui :expanded])
|
||||
(when (= :node (first selection)) (nth selection 3)))))))
|
||||
|
||||
(defn- at [db] (get-in db [:playback :frame] 0))
|
||||
|
||||
;; WHAT A KEY AND ITS BUTTON BOTH SEND, as functions of the db answering the
|
||||
;; event, or nil for nothing to do. `ui/shortcuts` puts them on keys and the
|
||||
;; toolbar on buttons, so the two cannot come to mean different things.
|
||||
|
||||
(defn prev-key [db] (some->> (first (rsubseq (stops db) < (at db))) (vector ::pb/seek)))
|
||||
(defn next-key [db] (some->> (first (subseq (stops db) > (at db))) (vector ::pb/seek)))
|
||||
(defn last-frame [db] [::pb/seek (dec (pb/frames db))])
|
||||
|
||||
(defn key-here
|
||||
"K: in a lane, a new drawing from the playhead on, copying the one there; on
|
||||
anything else, a key of what is selected."
|
||||
[db]
|
||||
(if (ui/lane-here db) [::ui/drawing-here true] [::ui/key-selected]))
|
||||
|
||||
(defn hold
|
||||
"= and −: the end of the selection's span, `delta` frames later."
|
||||
[delta]
|
||||
(fn [db] (when-let [p (ui/span-path db)] [::ui/slide p delta :out true])))
|
||||
|
||||
(defn- places-lane?
|
||||
"Does the row at `path` in the open symbol place a lane? Holding a lane
|
||||
longer is not lengthening a drawing, which is what = and − are on the bar for."
|
||||
[db path]
|
||||
(let [{document :clip st :store} (store/entry (:clip/current db))
|
||||
f (ui/editing-frame db document)
|
||||
host (nest/inside document st (get-in db [:ui :open]) (pop path) f)
|
||||
n (get-in document [:symbols (:sid host) :nodes (peek path)])]
|
||||
(boolean (some->> (node/source n) (clip/symbol document) symbol/lane?))))
|
||||
|
||||
(rf/reg-sub
|
||||
::here
|
||||
;; Which of the toolbar's commands mean something for the selection right now.
|
||||
(fn [db _]
|
||||
(let [p (ui/span-path db)]
|
||||
{:lane? (some? (ui/lane-here db))
|
||||
:span? (and (some? p) (not (places-lane? db p)))})))
|
||||
|
||||
;; ---------------------------------------------------------------------------
|
||||
;; the panes
|
||||
|
||||
(def ^:private speeds [[0.25 "¼×"] [0.5 "½×"] [1 "1×"] [2 "2×"] [4 "4×"]])
|
||||
|
||||
(defn- transport []
|
||||
(let [playing? @(rf/subscribe [::playback/playing?])
|
||||
rate @(rf/subscribe [::playback/rate])
|
||||
|
|
@ -599,28 +536,14 @@
|
|||
host (when (number? owner-frame) (span/host-frame clip sid id owner-frame))
|
||||
cuttable? (and span? (integer? host)
|
||||
(let [[lo hi] (node/placed-span n)] (< lo host hi)))
|
||||
act (fn [event] #(rf/dispatch event))
|
||||
;; A command that reads the db when it is pressed, as a key does.
|
||||
run (fn [f] #(some-> (f @rf-db/app-db) rf/dispatch))
|
||||
here @(rf/subscribe [::here])
|
||||
marks @(rf/subscribe [::playback/range])
|
||||
selections @(rf/subscribe [::sub/selections])
|
||||
clipboard @(rf/subscribe [::sub/clipboard])
|
||||
;; A peg goes over ONE node: it takes that node's place in the
|
||||
;; hierarchy, and there is no one place a pair of them would go.
|
||||
one-node (when (= 1 (count selections))
|
||||
(let [[kind _ _ path] (first selections)]
|
||||
(when (and (= :node kind) (seq path)) path)))]
|
||||
act (fn [event] #(rf/dispatch event))]
|
||||
[:div.pane-head
|
||||
;; ----------------------------------------------------------------- time
|
||||
;; Where the playhead is and how it moves. Nothing here depends on a
|
||||
;; selection, which is why it is the one group that is never greyed.
|
||||
;; Blender's timeline header: the ends, the keys, a frame, play.
|
||||
[:div.group
|
||||
[:button.ico {:aria-label "go to start" :title "go to the first frame (Home)"
|
||||
:on-click (act [::pb/seek 0])} [icon/view :start]]
|
||||
[:button.ico {:aria-label "previous key" :title "back to the key or drawing before (↓ or S)"
|
||||
:on-click (run prev-key)} [icon/view :prev]]
|
||||
[:button {:aria-label "−1" :title "step back one frame (← or A)"
|
||||
:on-click (act [::pb/step -1])} "−1"]
|
||||
[:button.ico.ico-play {:aria-label (if playing? "pause" "play")
|
||||
|
|
@ -628,11 +551,7 @@
|
|||
:on-click (act [::pb/toggle])}
|
||||
[icon/view (if playing? :pause :play)]]
|
||||
[:button {:aria-label "+1" :title "step forward one frame (→ or D)"
|
||||
:on-click (act [::pb/step 1])} "+1"]
|
||||
[:button.ico {:aria-label "next key" :title "on to the key or drawing after (↑ or W)"
|
||||
:on-click (run next-key)} [icon/view :next]]
|
||||
[:button.ico {:aria-label "go to end" :title "go to the last frame (End)"
|
||||
:on-click (run last-frame)} [icon/view :end]]]
|
||||
:on-click (act [::pb/step 1])} "+1"]]
|
||||
[:div.group
|
||||
[:button.ico {:class (when loop? "on") :aria-label "loop"
|
||||
:title "loop playback" :on-click (act [::pb/toggle-loop])}
|
||||
|
|
@ -644,87 +563,38 @@
|
|||
;; read WHILE scrubbing, and tabular figures keep it from twitching as it
|
||||
;; counts.
|
||||
[:span.readout.at-frame (str frame " / " frames)]
|
||||
;; ONE BUTTON THAT SAYS THE SPEED AND STEPS IT, rather than a menu: it is
|
||||
;; 1× almost always, and a click is all the other four are away. Shift goes
|
||||
;; back. playbackRate on the audio element and nothing else: the sound
|
||||
;; slows, currentTime advances proportionally, and the derived frame
|
||||
;; follows. Slow motion cannot desync by construction.
|
||||
(let [i (or (first (keep-indexed #(when (= rate (first %2)) %1) speeds)) 2)]
|
||||
[:button.speed {:class (when (not= 1 rate) "on") :aria-label "playback speed"
|
||||
:title "playback speed · click for faster, shift-click for slower"
|
||||
:on-click (fn [^js e]
|
||||
(let [j (mod (+ i (if (.-shiftKey e) -1 1)) (count speeds))]
|
||||
(rf/dispatch [::pb/set-rate (first (nth speeds j))])))}
|
||||
(second (nth speeds i))])
|
||||
;; Resolve's I and O: where playback loops in the open tab. Lit while set,
|
||||
;; and shift takes one away, as on the keys.
|
||||
[:div.group {:aria-label "loop marks"}
|
||||
(doall
|
||||
(for [[which word k] [[:in "in" "I"] [:out "out" "O"]]]
|
||||
^{:key which}
|
||||
[:button {:class (when (get marks which) "on")
|
||||
:title (str "mark " word " at the playhead (" k ")"
|
||||
" · shift-click clears it (⇧" k ")")
|
||||
:on-click (fn [^js e]
|
||||
(rf/dispatch (if (.-shiftKey e)
|
||||
[::pb/clear-mark which]
|
||||
[::pb/mark which])))}
|
||||
word]))]
|
||||
;; Five buttons for one mutually exclusive choice that is 1× almost always.
|
||||
;; A select says "pick one of these" in the width of the answer.
|
||||
;; playbackRate on the audio element and nothing else: the sound slows,
|
||||
;; currentTime advances proportionally, and the derived frame follows. Slow
|
||||
;; motion cannot desync by construction.
|
||||
[:span.pick
|
||||
[:select {:value rate :aria-label "playback speed" :title "playback speed"
|
||||
:on-change #(rf/dispatch [::pb/set-rate
|
||||
(js/parseFloat (.. % -target -value))])}
|
||||
(doall (for [[r label] [[0.25 "¼×"] [0.5 "½×"] [1.0 "1×"] [2.0 "2×"] [4.0 "4×"]]]
|
||||
^{:key r} [:option {:value r} label]))]]
|
||||
[:span.sep]
|
||||
;; The same direct timing operations apply to any selected symbol clip,
|
||||
;; whether it is placed freely or lives in a lane.
|
||||
[:div.group.timing-controls {:aria-label "timing"}
|
||||
[:button {:disabled (not cuttable?) :aria-label "split"
|
||||
:title "split the selected clip at the playhead"
|
||||
:on-click (act [::ui/split])} "split"]
|
||||
[:button {:disabled (not cuttable?) :aria-label "trim in"
|
||||
:title "move the selected clip's start to the playhead"
|
||||
:on-click (act [::ui/trim :in])} "in"]
|
||||
[:button {:disabled (not cuttable?) :aria-label "trim out"
|
||||
:title "move the selected clip's end to the playhead"
|
||||
:on-click (act [::ui/trim :out])} "out"]]
|
||||
[:span.sep]
|
||||
;; WHAT THE SELECTION CAN HAVE DONE TO IT, and nothing else. A drawing in
|
||||
;; a lane takes a new drawing and a longer hold; a symbol placed anywhere
|
||||
;; takes a cut and a longer span; a node takes a peg. Shown, not
|
||||
;; greyed, so the strip says what is possible here, and each says its key.
|
||||
(let [{:keys [lane?] hold? :span?} here]
|
||||
[:div.group.context-controls {:aria-label "selection"}
|
||||
;; In a lane, K is a new drawing, which is Flash's F6 and has nothing
|
||||
;; to do with a channel's key. Keying a node stays on the key: auto-key
|
||||
;; and the inspector's marks already do it where the value is.
|
||||
(when lane?
|
||||
[:<>
|
||||
[:button {:title "a new drawing from the playhead on, carrying on the one there (K)"
|
||||
:on-click (run key-here)}
|
||||
[icon/view :drawing] " drawing"]
|
||||
[:button {:title "a blank drawing from the playhead on (⇧K)"
|
||||
:on-click (act [::ui/drawing-here false])}
|
||||
[icon/view :blank] " blank"]])
|
||||
(when hold?
|
||||
[:<>
|
||||
[:button {:aria-label "one frame shorter" :title "one frame shorter (−)"
|
||||
:on-click (run (hold -1))} "−"]
|
||||
[:button {:aria-label "one frame longer" :title "one frame longer (=)"
|
||||
:on-click (run (hold 1))} "="]])
|
||||
(when cuttable?
|
||||
[:button {:title "split the selected clip at the playhead"
|
||||
:on-click (act [::ui/split])} "split"])
|
||||
;; THE CLIPBOARD, which has keys everywhere but a phone. Copy, cut and
|
||||
;; duplicate while something is selected, paste while something is
|
||||
;; copied.
|
||||
(when (seq selections)
|
||||
[:<>
|
||||
[:button.ico {:aria-label "copy" :title "copy (⌘C)"
|
||||
:on-click (act [::ui/copy])} [icon/view :copy]]
|
||||
[:button.ico {:aria-label "cut" :title "cut (⌘X)"
|
||||
:on-click (act [::ui/cut])} [icon/view :cut]]
|
||||
[:button.ico {:aria-label "duplicate" :title "duplicate beside it (⌘D)"
|
||||
:on-click (act [::ui/duplicate])} [icon/view :duplicate]]])
|
||||
(when clipboard
|
||||
[:button.ico {:aria-label "paste" :title "paste at the playhead (⌘V)"
|
||||
:on-click (act [::ui/paste])} [icon/view :paste]])
|
||||
(when (and one-node (not lane?))
|
||||
;; The only way to keep a pivot, and the only way to transform a
|
||||
;; measured part by hand — which is what `gesture/refusal` tells you
|
||||
;; to do, so it has to be reachable from somewhere.
|
||||
[:button {:title "a transform node over the selection · ⌃/⌘-drag its cross to place the pivot"
|
||||
:on-click (act [::ui/peg one-node])} "peg"])])
|
||||
[:span.spacer]
|
||||
[:div.group.creation-controls {:aria-label "create"}
|
||||
[:button {:title "create a symbol in the selected location (N)"
|
||||
[:button {:title "create a symbol in the selected location"
|
||||
:on-click (act [::ui/new-symbol :inside])}
|
||||
[icon/view :symbol] " + symbol"]
|
||||
[:button {:title "create a lane in the selected location (⇧N)"
|
||||
[icon/view :symbol] " symbol"]
|
||||
[:button {:title "create a lane in the selected location"
|
||||
:on-click (act [::ui/new-lane])}
|
||||
[icon/view :lane] " + lane"]]
|
||||
[icon/view :lane] " lane"]]
|
||||
[:button.auto-key {:class (when auto? "on")
|
||||
:aria-pressed auto?
|
||||
:title (if auto?
|
||||
|
|
@ -732,7 +602,7 @@
|
|||
"auto-key edited parameters at this frame")
|
||||
:on-click (act [::ui/toggle-auto-key])}
|
||||
"◆ auto key"]
|
||||
[:span.sep]
|
||||
[:span.spacer]
|
||||
;; How many pixels a frame is. The tracks are positioned in percentages of
|
||||
;; their own width, so this is one custom property on the grid and no
|
||||
;; arithmetic here — see `ui/layout`.
|
||||
|
|
@ -982,7 +852,7 @@
|
|||
(cond
|
||||
(= k "Escape") (reset! chosen [])
|
||||
(#{"Delete" "Backspace"} k)
|
||||
(do (.focus (.closest (.-currentTarget e) "section.time") #js {:preventScroll true})
|
||||
(do (.focus (.closest (.-currentTarget e) "section.time"))
|
||||
(rf/dispatch [::ui/edit-keyframes @chosen nil]) (reset! chosen []))
|
||||
:else (let [df (* (if (= k "ArrowLeft") -1 1) (if (.-shiftKey e) 10 1))
|
||||
xs @chosen]
|
||||
|
|
@ -991,7 +861,7 @@
|
|||
:on-pointer-down
|
||||
(fn [e]
|
||||
(.stopPropagation e)
|
||||
(.focus (.-currentTarget e) #js {:preventScroll true})
|
||||
(.focus (.-currentTarget e))
|
||||
(let [ids (set (map keyframes/identity-of items))
|
||||
selected? (some (:ids @key-state) (map keyframes/identity-of items))]
|
||||
(cond
|
||||
|
|
@ -1183,7 +1053,7 @@
|
|||
begin! (fn [^js e actual-path gesture-kind actual-select other drag]
|
||||
(let [track (.closest (.-currentTarget e) ".tl-track")]
|
||||
(.stopPropagation e)
|
||||
(.focus track #js {:preventScroll true})
|
||||
(.focus track)
|
||||
;; SELECTING WAITS FOR THE RELEASE. Selecting on the press
|
||||
;; changed what the timeline was showing before the gesture
|
||||
;; had said anything: an expanded lane follows the
|
||||
|
|
@ -1302,8 +1172,6 @@
|
|||
:on-click (when (and select unmapped?)
|
||||
(fn [^js e] (.stopPropagation e)
|
||||
(choose-row! e select)))
|
||||
:ref (when (and select (not unmapped?))
|
||||
(fn [^js el] (when el (aset el "arthurSelect" select))))
|
||||
:on-pointer-down
|
||||
(when (and select (not unmapped?))
|
||||
#(begin! % (or slides path) :slide select nil nil))}
|
||||
|
|
@ -1480,29 +1348,6 @@
|
|||
(when (pos? lo) [:div.tl-outside {:style {:left 0 :width (edge% lo frames)}}])
|
||||
(when (< hi frames) [:div.tl-outside {:style {:left (edge% hi frames) :right 0}}])]))))
|
||||
|
||||
(defn- swept
|
||||
"The clips and bars inside `tracks` that the box from `[x y]` to `[x2 y2]`, in
|
||||
client pixels, touches, as their selection addresses with their elements."
|
||||
[^js tracks x y x2 y2]
|
||||
(let [l (min x x2) r (max x x2) t (min y y2) b (max y y2)]
|
||||
(keep (fn [^js el]
|
||||
(when-let [select (or (some-> (aget el "arthurCel") :select)
|
||||
(aget el "arthurSelect"))]
|
||||
(let [box (.getBoundingClientRect el)]
|
||||
(when (and (< (.-left box) r) (< l (.-right box))
|
||||
(< (.-top box) b) (< t (.-bottom box)))
|
||||
[el select]))))
|
||||
(array-seq (.querySelectorAll tracks ".tl-cel, .tl-span")))))
|
||||
|
||||
(defn- mark-swept!
|
||||
"Show what the box holds by a class on the blocks themselves, not by
|
||||
selecting: selecting re-lays the pane — an expanded lane follows the
|
||||
selection — and the rows would move under the box being drawn over them."
|
||||
[^js tracks els]
|
||||
(doseq [^js el (array-seq (.querySelectorAll tracks ".swept"))]
|
||||
(.remove (.-classList el) "swept"))
|
||||
(doseq [^js el els] (.add (.-classList el) "swept")))
|
||||
|
||||
(defn- key-marquee [marquee]
|
||||
(when-let [{:keys [x y x2 y2]} @marquee]
|
||||
(when (and x2 y2)
|
||||
|
|
@ -1555,13 +1400,7 @@
|
|||
key-context (atom nil)
|
||||
key-anchor (atom nil)
|
||||
row-anchor (atom nil)
|
||||
marquee (r/atom nil)
|
||||
;; A box dragged from empty track space over clips and bars:
|
||||
;; `{:x :y :base}` pressed, then `:x2 :y2 :hits` once it has moved
|
||||
;; far enough to be a drag and not a click. `swept?` swallows the
|
||||
;; click a drag ends in, which would otherwise select nothing.
|
||||
sweep (r/atom nil)
|
||||
swept? (atom false)]
|
||||
marquee (r/atom nil)]
|
||||
(let [clip-id @(rf/subscribe [::render/clip-id])
|
||||
clip @(rf/subscribe [::render/clip])
|
||||
;; THE RULER IS THE OPEN SYMBOL'S OWN FRAME SPACE. Every span, key and
|
||||
|
|
@ -1671,37 +1510,7 @@
|
|||
;; own events; the target check keeps ordinary row/bar clicks local.
|
||||
{:on-click (fn [^js e]
|
||||
(when (= (.-target e) (.-currentTarget e))
|
||||
(rf/dispatch [::ui/select nil])))
|
||||
;; ON A PHONE ONE FINGER IS THE POINTER AND TWO SCROLL, as on the
|
||||
;; stage: one drags a clip, a box or the playhead, and the rows only
|
||||
;; move under two, by their middle. Properties, not listeners, since
|
||||
;; this runs on every render; on an element, so not passive.
|
||||
:ref (fn [^js el]
|
||||
(when el
|
||||
(let [middle (fn [^js ts]
|
||||
(let [a (aget ts 0) b (aget ts 1)]
|
||||
[(/ (+ (.-clientX a) (.-clientX b)) 2)
|
||||
(/ (+ (.-clientY a) (.-clientY b)) 2)]))]
|
||||
(set! (.-ontouchstart el)
|
||||
(fn [^js e]
|
||||
(when (<= 2 (.. e -touches -length))
|
||||
(when @sweep
|
||||
(reset! sweep nil)
|
||||
(mark-swept! el []))
|
||||
(aset el "arthurTwo" (middle (.-touches e))))))
|
||||
(set! (.-ontouchmove el)
|
||||
(fn [^js e]
|
||||
(when-let [[x y] (and (<= 2 (.. e -touches -length))
|
||||
(aget el "arthurTwo"))]
|
||||
(.preventDefault e)
|
||||
(let [[x2 y2 :as m] (middle (.-touches e))]
|
||||
(set! (.-scrollLeft el) (+ (.-scrollLeft el) (- x x2)))
|
||||
(set! (.-scrollTop el) (+ (.-scrollTop el) (- y y2)))
|
||||
(aset el "arthurTwo" m)))))
|
||||
(set! (.-ontouchend el)
|
||||
(fn [^js e]
|
||||
(when (< (.. e -touches -length) 2)
|
||||
(aset el "arthurTwo" nil)))))))}
|
||||
(rf/dispatch [::ui/select nil])))}
|
||||
[:div.tl-labels
|
||||
;; Empty label space takes a row back out to the top of the open symbol.
|
||||
{:on-click (fn [^js e]
|
||||
|
|
@ -1729,21 +1538,11 @@
|
|||
[:div.tl-tracks
|
||||
{:on-pointer-down-capture
|
||||
(fn [e]
|
||||
;; DRAG TO SELECT, FROM EMPTY SPACE: anywhere a press would
|
||||
;; otherwise do nothing. Not yet a box — a press that does not move
|
||||
;; is still a click, and a double-click in a lane still makes a
|
||||
;; drawing — so nothing is stopped until it moves.
|
||||
(reset! swept? false)
|
||||
(when (and (= 0 (.-button e)) (.-isPrimary e)
|
||||
(not (.closest (.-target e) ".tl-track.automation"))
|
||||
(not (.closest (.-target e) "button, .tl-span, .tl-edge, .tl-junction, .tl-ruler, input")))
|
||||
(reset! sweep {:x (.-clientX e) :y (.-clientY e)
|
||||
:base (if (or (.-metaKey e) (.-ctrlKey e) (.-shiftKey e)) selections [])}))
|
||||
(when (and (= 0 (.-button e))
|
||||
(.closest (.-target e) ".tl-track.automation")
|
||||
(not (.closest (.-target e) "button, .movable, .unmapped, .tl-edge")))
|
||||
(.stopPropagation e) (.preventDefault e)
|
||||
(.focus (.-currentTarget e) #js {:preventScroll true})
|
||||
(.focus (.-currentTarget e))
|
||||
(reset! marquee {:x (.-clientX e) :y (.-clientY e)
|
||||
:hits (let [container (.-currentTarget e)]
|
||||
(vec (mapcat
|
||||
|
|
@ -1760,16 +1559,6 @@
|
|||
(try (.setPointerCapture (.-currentTarget e) (.-pointerId e)) (catch :default _ nil))))
|
||||
:on-pointer-move
|
||||
(fn [e]
|
||||
(when-let [{:keys [x y x2]} @sweep]
|
||||
(let [cx (.-clientX e) cy (.-clientY e) tracks (.-currentTarget e)]
|
||||
;; Four pixels, as a drag begins anywhere else in the app.
|
||||
(when (or x2 (< 4 (js/Math.hypot (- cx x) (- cy y))))
|
||||
(.stopPropagation e)
|
||||
(when-not x2
|
||||
(try (.setPointerCapture tracks (.-pointerId e)) (catch :default _ nil)))
|
||||
(let [hits (swept tracks x y cx cy)]
|
||||
(mark-swept! tracks (map first hits))
|
||||
(swap! sweep assoc :x2 cx :y2 cy :hits (mapv second hits))))))
|
||||
(when-let [{:keys [x y base hits]} @marquee]
|
||||
(.stopPropagation e)
|
||||
(let [x2 (.-clientX e) y2 (.-clientY e)]
|
||||
|
|
@ -1779,20 +1568,8 @@
|
|||
(mapcat (fn [{cx :x cy :y :keys [items]}]
|
||||
(when (and (<= (min x x2) cx (max x x2))
|
||||
(<= (min y y2) cy (max y y2))) items)) hits))))))))
|
||||
:on-pointer-up (fn [e]
|
||||
(when-let [{:keys [x2 base hits]} @sweep]
|
||||
(reset! sweep nil)
|
||||
(when x2
|
||||
(.stopPropagation e)
|
||||
(mark-swept! (.-currentTarget e) [])
|
||||
(reset! swept? true)
|
||||
(rf/dispatch [::ui/select-many (into (vec base) hits)])))
|
||||
(when @marquee (.stopPropagation e) (reset! marquee nil)))
|
||||
:on-pointer-cancel (fn [e]
|
||||
(when @sweep
|
||||
(reset! sweep nil)
|
||||
(mark-swept! (.-currentTarget e) []))
|
||||
(when @marquee (reset! key-selection (:base @marquee)) (reset! marquee nil)))
|
||||
:on-pointer-up (fn [e] (when @marquee (.stopPropagation e) (reset! marquee nil)))
|
||||
:on-pointer-cancel (fn [_] (when @marquee (reset! key-selection (:base @marquee)) (reset! marquee nil)))
|
||||
:tab-index 0
|
||||
:on-key-down
|
||||
(fn [e]
|
||||
|
|
@ -1811,9 +1588,8 @@
|
|||
(rf/dispatch [::ui/edit-keyframes xs df])
|
||||
(reset! key-selection (keyframes/shifted xs df))))))))
|
||||
:on-click (fn [^js e]
|
||||
(cond
|
||||
@swept? (reset! swept? false)
|
||||
(= (.-target e) (.-currentTarget e)) (rf/dispatch [::ui/select nil])))
|
||||
(when (= (.-target e) (.-currentTarget e))
|
||||
(rf/dispatch [::ui/select nil])))
|
||||
:on-drag-enter (fn [^js e] (when (drag/accepts?) (.preventDefault e)))
|
||||
:on-drag-over (fn [^js e]
|
||||
(when (drag/accepts?)
|
||||
|
|
@ -1885,8 +1661,7 @@
|
|||
[:div.tl-grid {:class (when-not fine "coarse")}]
|
||||
[outside-marks frames false]
|
||||
[playhead :div.tl-playhead frames]
|
||||
[key-marquee marquee]
|
||||
[key-marquee sweep]]]
|
||||
[key-marquee marquee]]]
|
||||
[cursor-hint hint]])
|
||||
(finally (.disconnect sizer))))
|
||||
|
||||
|
|
|
|||
|
|
@ -8,8 +8,11 @@
|
|||
(:require [arthur.events.collab :as collab]
|
||||
[arthur.events.export :as export]
|
||||
[arthur.events.project :as project]
|
||||
[arthur.events.ui :as ui]
|
||||
[arthur.subs.playback :as playback]
|
||||
[arthur.subs.ui :as sub]
|
||||
[arthur.ui.layout :as layout]
|
||||
[arthur.ui.menu :as menu]
|
||||
[arthur.ui.openmenu :as openmenu]
|
||||
[arthur.ui.settings :as settings]
|
||||
[arthur.ui.share :as share]
|
||||
|
|
@ -54,6 +57,14 @@
|
|||
(let [{project-name :name project-seq :seq :keys [busy? status]} @(rf/subscribe [::playback/project])
|
||||
{footage-status :status} @(rf/subscribe [::playback/footage])
|
||||
{export-status :status} @(rf/subscribe [::export/state])
|
||||
selections @(rf/subscribe [::sub/selections])
|
||||
clipboard @(rf/subscribe [::sub/clipboard])
|
||||
selected? (boolean (seq selections))
|
||||
;; A peg goes over ONE node: it takes that node's place in the
|
||||
;; hierarchy, and there is no one place a pair of them would go.
|
||||
one-node (when (= 1 (count selections))
|
||||
(let [[kind _ _ path] (first selections)]
|
||||
(when (and (= :node kind) (seq path)) path)))
|
||||
title (or project-name "untitled")
|
||||
commit! (fn []
|
||||
(rf/dispatch [::project/rename @draft])
|
||||
|
|
@ -68,6 +79,27 @@
|
|||
[settings/new-project "new"]
|
||||
[openmenu/view]
|
||||
[undo/view]
|
||||
[menu/view
|
||||
{:label "edit" :title "selection and clipboard"
|
||||
:items [{:label "copy" :sub "Copy selection · ⌘/Ctrl C"
|
||||
:disabled? (not selected?) :on-click #(rf/dispatch [::ui/copy])}
|
||||
{:label "cut" :sub "Cut selection · ⌘/Ctrl X"
|
||||
:disabled? (not selected?) :on-click #(rf/dispatch [::ui/cut])}
|
||||
{:label "paste" :sub "Paste at playhead into the active row · ⌘/Ctrl V"
|
||||
:disabled? (nil? clipboard) :on-click #(rf/dispatch [::ui/paste])}
|
||||
{:label "duplicate" :sub "Duplicate beside selection; lanes repeat forward · ⌘/Ctrl D"
|
||||
:disabled? (not selected?) :on-click #(rf/dispatch [::ui/duplicate])}
|
||||
{:label "duplicate unique"
|
||||
:sub "Duplicate with a private nested symbol graph · ⇧⌘/Ctrl D"
|
||||
:disabled? (not selected?)
|
||||
:on-click #(rf/dispatch [::ui/duplicate-unique])}
|
||||
;; The only way to keep a pivot, and the only way to transform a
|
||||
;; measured part by hand — which is what `gesture/refusal` tells
|
||||
;; you to do, so it has to be reachable from somewhere.
|
||||
{:label "add peg"
|
||||
:sub "A transform node over the selection · ⌃/⌘-drag its cross to place the pivot"
|
||||
:disabled? (nil? one-node)
|
||||
:on-click #(rf/dispatch [::ui/peg one-node])}]}]
|
||||
[snapshots/view]
|
||||
(if @renaming?
|
||||
[:input.project-name {:auto-focus true :value @draft
|
||||
|
|
|
|||
|
|
@ -267,24 +267,6 @@
|
|||
(is (= (get-in c [:symbols :outer :nodes])
|
||||
(get-in (leaf/clip "c" (leaf/leaves "c" c)) [:symbols :outer :nodes]))))))
|
||||
|
||||
(deftest a-drawing-is-named-by-where-it-is-drawn
|
||||
(let [c (assoc-in (nested) [:symbols :outer :name] "body")]
|
||||
(testing "placed by one symbol: that symbol's name and the frame it starts on"
|
||||
(is (= [:outer] (clip/owners c :inner)))
|
||||
(is (= "body 5" (clip/symbol-name c :inner)))
|
||||
(is (= "lane 5" (clip/symbol-name (assoc-in c [:symbols :outer :name] "lane") :inner))
|
||||
"renaming the lane renames its drawings"))
|
||||
(testing "a name of its own wins"
|
||||
(is (= "hand" (clip/symbol-name (assoc-in c [:symbols :inner :name] "hand") :inner))))
|
||||
(testing "placed nowhere, or in two symbols, it is its id"
|
||||
(is (= "loose" (clip/symbol-name c :loose)))
|
||||
(is (= "inner" (clip/symbol-name (clip/place-symbol c nil :loose :inner 0 (random-uuid) nil)
|
||||
:inner))))
|
||||
(testing "a cycle of unnamed symbols ends rather than recurring"
|
||||
(let [loop (clip/place-symbol (update-in c [:symbols :outer] dissoc :name)
|
||||
nil :inner :outer 0 (random-uuid) nil)]
|
||||
(is (string? (clip/symbol-name loop :inner)))))))
|
||||
|
||||
(deftest an-instance-is-labelled-by-what-it-places
|
||||
(let [c (-> (nested)
|
||||
(assoc-in [:symbols :inner :name] "mouth"))
|
||||
|
|
@ -296,9 +278,9 @@
|
|||
(is (= "mouth" (clip/node-label c id n)))
|
||||
(is (= "jaw" (clip/node-label (assoc-in c [:symbols :inner :name] "jaw") id n))
|
||||
"renaming the symbol renames every row that shows an instance of it"))
|
||||
(testing "an unnamed symbol is named by where it is drawn, not by the node's uuid"
|
||||
(is (= "outer 5" (clip/node-label (update-in c [:symbols :inner] dissoc :name)
|
||||
id n))))
|
||||
(testing "an unnamed symbol falls back to its id, not to the node's uuid"
|
||||
(is (= "inner" (clip/node-label (update-in c [:symbols :inner] dissoc :name)
|
||||
id n))))
|
||||
(testing "and a name left on the instance is not read: it has none of its own"
|
||||
(is (= "mouth" (clip/node-label c id (assoc n :name "left eye")))))
|
||||
(testing "every placement of a symbol is counted"
|
||||
|
|
|
|||
|
|
@ -560,16 +560,3 @@
|
|||
(is (near? [10 90] (piv c)))
|
||||
(is (near? [10 90] (piv grown))
|
||||
"the pivot moved because something else was drawn, which is the bug")))
|
||||
|
||||
(deftest deleting-a-symbol-takes-its-placements-and-leaves-what-it-placed
|
||||
(let [c (-> (clip/blank)
|
||||
(assoc-in [:symbols :lane] {:id :lane :frames 10 :nodes {}})
|
||||
(assoc-in [:symbols :cel] {:id :cel :frames 1 :nodes {}})
|
||||
(clip/place-symbol nil :main :lane 0 (random-uuid) nil)
|
||||
(clip/place-symbol nil :lane :cel 3 (random-uuid) nil))
|
||||
{gone :clip} (nest/delete-symbol c :lane)]
|
||||
(is (nil? (clip/symbol gone :lane)))
|
||||
(is (empty? (:nodes (clip/symbol gone :main))) "its instance in the root went with it")
|
||||
(is (clip/symbol gone :cel) "what it placed stays")
|
||||
(is (empty? (clip/owners gone :cel)) "placed nowhere now")
|
||||
(is (:refused (nest/delete-symbol c :main)) "the root cannot be deleted")))
|
||||
|
|
|
|||
|
|
@ -67,11 +67,11 @@
|
|||
:kind :instance :parent :root :z "a1"
|
||||
:source {:symbol :sym/face}}
|
||||
:a-rect {:id :a-rect :kind :rect :parent :root :z "a3"}}}
|
||||
:sym/face {:name "head" :frames 40 :nodes {:root {:id :root :kind :group :z "a1"}}}}})
|
||||
:sym/face {:frames 40 :nodes {:root {:id :root :kind :group :z "a1"}}}}})
|
||||
|
||||
(deftest the-picker-offers-every-symbol-then-every-instance-in-the-open-one
|
||||
(let [ts (export/targets clip :main)]
|
||||
(is (= ["main" "face" "head 1" "head 2"] (mapv :label ts))
|
||||
(is (= ["main" "face" "face 1" "face 2"] (mapv :label ts))
|
||||
"every symbol, then the instances in the open one")
|
||||
(testing "the instances isolate a node in the open symbol and the symbols do not"
|
||||
(is (= [nil nil] (mapv :isolate (take 2 ts))))
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
(ns arthur.events.lane-test
|
||||
(:require [cljs.test :refer [deftest is testing]]
|
||||
(:require [cljs.test :refer [deftest is]]
|
||||
[arthur.domain.clip :as clip]
|
||||
[arthur.domain.creation :as creation]
|
||||
[arthur.domain.history :as history]
|
||||
|
|
@ -316,56 +316,6 @@
|
|||
(select-keys (ui/paste-destination db doc nil) [:sid :path :frame]))
|
||||
"an inactive selected symbol falls back to the open symbol")))
|
||||
|
||||
(deftest pasting-onto-your-own-paste-goes-beside-it
|
||||
(let [doc {:fps 24 :width 20 :height 20
|
||||
:symbols
|
||||
{:main {:id :main :frames 40
|
||||
:nodes {:drawing {:id :drawing :kind :instance :z "a"
|
||||
:span [0 10] :time {:at 0 :rate 1}
|
||||
:source {:symbol :inside}
|
||||
:playback {:in 0 :speed 1 :end :stop}}
|
||||
:other {:id :other :kind :instance :z "b"
|
||||
:span [0 10] :time {:at 0 :rate 1}
|
||||
:source {:symbol :inside}
|
||||
:playback {:in 0 :speed 1 :end :stop}}}}
|
||||
:inside {:id :inside :frames 10 :nodes {}}}}
|
||||
id (store/install! {:clip doc :store {}} "paste-beside")
|
||||
instances #(count (get-in (store/entry id) [:clip :symbols % :nodes]))]
|
||||
(reset! rf-db/app-db {:clip/current id :paint/revision 0
|
||||
:ui {:open :main :selection [:node :main :drawing [:drawing]]}
|
||||
:playback {:frame 2}})
|
||||
(rf/dispatch-sync [::ui/copy])
|
||||
(rf/dispatch-sync [::ui/select [:node :main nil []]])
|
||||
(rf/dispatch-sync [::ui/paste])
|
||||
(is (= 3 (instances :main)))
|
||||
(rf/dispatch-sync [::ui/paste])
|
||||
(rf/dispatch-sync [::ui/paste])
|
||||
(is (= 5 (instances :main))
|
||||
"the selected copy is a symbol under the playhead, and the paste still goes beside it")
|
||||
(is (= 0 (instances :inside)))
|
||||
(testing "selecting something else makes paste follow the selection again"
|
||||
(rf/dispatch-sync [::ui/select [:node :main :other [:other]]])
|
||||
(is (= :inside (:sid (ui/paste-destination @rf-db/app-db
|
||||
(:clip (store/entry id)) {})))))))
|
||||
|
||||
(deftest pasting-onto-what-you-copied-goes-beside-it
|
||||
(let [doc {:fps 24 :width 20 :height 20
|
||||
:symbols
|
||||
{:main {:id :main :frames 40
|
||||
:nodes {:drawing {:id :drawing :kind :instance :z "a"
|
||||
:span [0 10] :time {:at 0 :rate 1}
|
||||
:source {:symbol :inside}
|
||||
:playback {:in 0 :speed 1 :end :stop}}}}
|
||||
:inside {:id :inside :frames 10 :nodes {}}}}
|
||||
id (store/install! {:clip doc :store {}} "paste-beside-copied")]
|
||||
(reset! rf-db/app-db {:clip/current id :paint/revision 0
|
||||
:ui {:open :main :selection [:node :main :drawing [:drawing]]}
|
||||
:playback {:frame 2}})
|
||||
(rf/dispatch-sync [::ui/copy])
|
||||
(rf/dispatch-sync [::ui/paste])
|
||||
(is (= 2 (count (get-in (store/entry id) [:clip :symbols :main :nodes])))
|
||||
"a symbol pasted with itself selected lands beside it, not refused as a cycle")))
|
||||
|
||||
(deftest multi-paste-uses-one-current-primary-target-and-selects-the-batch
|
||||
(let [doc (fixture/document)
|
||||
id (store/install! {:clip doc :store {}} "multi-paste-target")
|
||||
|
|
@ -392,14 +342,10 @@
|
|||
|
||||
(deftest polygon-landing-obeys-the-destination-symbol-mode
|
||||
(let [lane (fixture/document)
|
||||
gap (update-in lane [:symbols :main :nodes] dissoc :b)
|
||||
ordinary (update-in lane [:symbols :main] dissoc :display)
|
||||
db {:ui {:open :main :selection [:node :main :plate [:plate]]}
|
||||
:playback {:frame 5}}]
|
||||
(is (= {:lane? false :path [:b]} (select-keys (ui/polygon-landing lane {} db) [:lane? :path]))
|
||||
"a lane draws into the cel it shows at the playhead")
|
||||
(is (true? (:lane? (ui/polygon-landing gap {} db)))
|
||||
"and makes a new one only where it shows nothing")
|
||||
(is (true? (:lane? (ui/polygon-landing lane {} db))))
|
||||
(is (false? (:lane? (ui/polygon-landing ordinary {} db))))))
|
||||
|
||||
(deftest beginning-a-polygon-does-not-invent-a-lane
|
||||
|
|
@ -415,27 +361,18 @@
|
|||
(is (nil? (get-in saved [:symbols :main :display])))
|
||||
(is (nil? (get-in (store/entry (:clip/current after)) [:history :done])))))
|
||||
|
||||
(deftest drawing-with-the-lane-row-active-draws-into-what-it-shows
|
||||
(deftest drawing-with-the-lane-row-active-creates-a-new-cel
|
||||
(let [doc (fixture/document)
|
||||
id (store/install! {:clip doc :store {}} "draw-into-lane-cel")
|
||||
db {:clip/current id :paint/revision 0
|
||||
:ui {:open :main :selection [:node :main nil []]}
|
||||
:playback {:frame 1}}
|
||||
after (ui/beginning-polygon db)]
|
||||
(is (= doc (:clip (store/entry id))) "no cel is made over the one showing")
|
||||
(is (= [] (get-in after [:ui :draft])))))
|
||||
|
||||
(deftest drawing-with-the-lane-row-active-in-a-gap-creates-a-new-cel
|
||||
(let [doc (update-in (fixture/document) [:symbols :main :nodes] dissoc :b)
|
||||
id (store/install! {:clip doc :store {}} "draw-new-lane-cel")
|
||||
db {:clip/current id :paint/revision 0
|
||||
:ui {:open :main :selection [:node :main nil []]}
|
||||
:playback {:frame 5}}
|
||||
:playback {:frame 1}}
|
||||
after (ui/beginning-polygon db)
|
||||
[_ sid cel-id] (get-in after [:ui :selection])
|
||||
saved (:clip (store/entry id))]
|
||||
(is (= :main sid))
|
||||
(is (= [5 6] (node/placed-span (get-in saved [:symbols sid :nodes cel-id]))))
|
||||
(is (not= :a cel-id) "the occupied cel is not reused")
|
||||
(is (= [1 2] (node/placed-span (get-in saved [:symbols sid :nodes cel-id]))))
|
||||
(is (= 1 (clip/frames saved (node/source (get-in saved [:symbols sid :nodes cel-id])))))
|
||||
(is (= [] (get-in after [:ui :draft])))))
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
(:require [cljs.test :refer [deftest is]]
|
||||
[arthur.domain.sequence-test :as fixture]
|
||||
[arthur.footage.store :as store]
|
||||
[arthur.ui.timeline :as timeline]))
|
||||
[arthur.ui.shortcuts :as shortcuts]))
|
||||
|
||||
(deftest the-key-jumps-stop-on-every-cel-edge-and-key-the-timeline-shows
|
||||
;; Cels at 0, 4 and 8; `:b` keyed on its own frames 0 and 1, which it shows
|
||||
|
|
@ -10,4 +10,4 @@
|
|||
;; last frame and is not somewhere to stand.
|
||||
(let [id (store/install! {:clip (fixture/document) :store {}} "shortcut-stops")]
|
||||
(is (= [0 4 5 8 11]
|
||||
(vec (timeline/stops {:clip/current id :ui {:open :main}}))))))
|
||||
(vec (shortcuts/stops {:clip/current id :ui {:open :main}}))))))
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ try {
|
|||
k('source'), m(k('symbol'), k('box')), k('span'), v(0, 60),
|
||||
k('time'), m(k('at'), 0, k('rate'), 1),
|
||||
k('playback'), m(k('in'), 0, k('speed'), 1, k('end'), k('stop')));
|
||||
c = cljs.core.assoc_in(c, v(k('symbols'), k('box')), m(k('id'), k('box'), k('name'), 'box', k('frames'), 60, k('nodes'), m()));
|
||||
c = cljs.core.assoc_in(c, v(k('symbols'), k('box')), m(k('id'), k('box'), k('frames'), 60, k('nodes'), m()));
|
||||
c = cljs.core.assoc_in(c, v(k('symbols'), k('main'), k('nodes')), m(k('a'), rect('a',0,true), k('b'), rect('b',4,false), k('target'), target));
|
||||
const id = arthur.footage.store.install_BANG_(m(k('clip'), c, k('store'), m()), 'timeline-browser');
|
||||
const a = v(k('node'),k('main'),k('a'),v(k('a'))), b = v(k('node'),k('main'),k('b'),v(k('b')));
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>arthur</title>
|
||||
<style>
|
||||
:root { --bg:#0b0d13; --panel:#12151f; --line:#232836; --fg:#e8eaf0;
|
||||
|
|
|
|||
|
|
@ -14,9 +14,6 @@ urlpatterns = [
|
|||
# same page; the client reads the id out of the path and opens it.
|
||||
path("p/<uuid:project_id>", views.page),
|
||||
path("p/<uuid:project_id>/<slug:slug>", views.page),
|
||||
# The service worker, at the root so it can control every page; see
|
||||
# `views.service_worker`.
|
||||
path("sw.js", views.service_worker),
|
||||
path("api/", include("clips.urls")),
|
||||
path("blob/<str:digest>", views.blob, name="blob"),
|
||||
path("admin/", admin.site.urls),
|
||||
|
|
|
|||
|
|
@ -85,11 +85,6 @@
|
|||
* { box-sizing: border-box; }
|
||||
|
||||
html, body { margin: 0; height: 100%; overflow: hidden; }
|
||||
/* AN EDITOR, NOT A PAGE: a tap is a click, never the first half of a
|
||||
double-tap zoom. Set on the root, it reaches everything under it, and an
|
||||
element that says `none` — the stage, a grip — still gets its own way. The
|
||||
zoom on focusing a small field is the viewport's `maximum-scale`. */
|
||||
html { touch-action: manipulation; }
|
||||
|
||||
body {
|
||||
background: var(--desk);
|
||||
|
|
@ -605,19 +600,6 @@ button.share-button:hover, button.share-button.on { filter: brightness(1.1); }
|
|||
}
|
||||
|
||||
.pool-row:hover:not(.disabled) { background: #fff; }
|
||||
|
||||
/* A tree row's disclosure: what this symbol places, shut until asked. A row
|
||||
with nothing under it keeps the width, so names line up down a level. */
|
||||
.pool-twisty {
|
||||
flex: none;
|
||||
width: 10px;
|
||||
color: var(--dim);
|
||||
cursor: pointer;
|
||||
text-align: center;
|
||||
user-select: none;
|
||||
}
|
||||
.pool-twisty:empty { cursor: default; }
|
||||
.pool-twisty:hover:not(:empty) { color: var(--fg); }
|
||||
.pool-row.on { background: var(--sel-bg); border-color: var(--sel); }
|
||||
|
||||
/* WHICH ONE IS OPEN, as a mark and not as the word "open" — a list this narrow
|
||||
|
|
@ -1028,11 +1010,8 @@ button.share-button:hover, button.share-button.on { filter: brightness(1.1); }
|
|||
.loc-fact::before, .loc-shared::before { content: "· "; color: var(--line); }
|
||||
.loc-shared { flex: 0 0 auto; display: inline-flex; align-items: baseline; gap: 5px; }
|
||||
.loc .spacer { flex: 1; }
|
||||
.creation-controls button, .context-controls button { display: inline-flex; align-items: center; gap: 4px; }
|
||||
/* Wide enough for the widest speed it steps through, so the strip does not
|
||||
shift as it changes. */
|
||||
.pane-head button.speed { min-width: 3.2em; font-variant-numeric: tabular-nums; }
|
||||
.creation-controls svg, .context-controls svg { width: 11px; height: 11px; }
|
||||
.creation-controls button { display: inline-flex; align-items: center; gap: 4px; }
|
||||
.creation-controls svg { width: 11px; height: 11px; }
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
timeline */
|
||||
|
|
@ -1115,9 +1094,6 @@ button.share-button:hover, button.share-button.on { filter: brightness(1.1); }
|
|||
first one, full height — which reads as "the timeline draws nothing" rather
|
||||
than as a positioning bug. */
|
||||
.tl-track { position: relative; }
|
||||
/* One finger on the rows is a pointer — a clip, a box, a key — and never a
|
||||
scroll; two fingers scroll, which `ui/timeline` does itself. */
|
||||
.tl-tracks { touch-action: none; }
|
||||
|
||||
.tl-label {
|
||||
/* Scrolled to from the stage: clear of the sticky ruler above. */
|
||||
|
|
@ -1213,9 +1189,6 @@ button.share-button:hover, button.share-button.on { filter: brightness(1.1); }
|
|||
.tl-ruler {
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
/* A drag along the ruler is a scrub, never a scroll: on a phone the
|
||||
timeline's own scrolling took it otherwise, and the playhead hardly moved. */
|
||||
touch-action: none;
|
||||
/* The fine grid's ticks along its foot, so the frames under the numbers can
|
||||
be counted too. */
|
||||
background-image: repeating-linear-gradient(90deg, var(--line) 0 1px, transparent 1px var(--fine));
|
||||
|
|
@ -1292,8 +1265,6 @@ button.share-button:hover, button.share-button.on { filter: brightness(1.1); }
|
|||
.tl-cel.on:hover:not(:disabled) { background: var(--pick); filter: brightness(1.12); }
|
||||
.tl-span.on { background: var(--pick-bg); border-color: var(--pick); }
|
||||
.tl-cel.target, .tl-span.target { outline: 2px solid var(--target); outline-offset: -2px; }
|
||||
/* Inside a box being dragged over the rows: selected when it is let go. */
|
||||
.tl-cel.swept, .tl-span.swept { outline: 2px solid var(--pick); outline-offset: -2px; }
|
||||
.tl-span.on.dense {
|
||||
background: repeating-linear-gradient(
|
||||
-45deg, var(--pick-bg) 0 3px, #f0bf77 3px 6px);
|
||||
|
|
@ -1662,9 +1633,6 @@ button.tl-gap:hover { background: rgba(47, 111, 192, .28); }
|
|||
/* The picture, not the desk around it. */
|
||||
.stage-area { padding: 5px; }
|
||||
|
||||
/* The scrubber is a strip a finger can hold. */
|
||||
:root { --ruler: 26px; }
|
||||
|
||||
/* Touch targets, in the strips that are all buttons. */
|
||||
.pane-head, .options-bar { gap: 7px; }
|
||||
.options-bar button, .pane-head button, .top button { min-height: 24px; }
|
||||
|
|
|
|||
Binary file not shown.
|
Before Width: | Height: | Size: 540 B |
Binary file not shown.
|
Before Width: | Height: | Size: 587 B |
Binary file not shown.
|
Before Width: | Height: | Size: 2.3 KiB |
|
|
@ -1,15 +0,0 @@
|
|||
{
|
||||
"name": "arthur",
|
||||
"short_name": "arthur",
|
||||
"description": "Draw and animate, frame by frame.",
|
||||
"start_url": "/",
|
||||
"scope": "/",
|
||||
"display": "standalone",
|
||||
"orientation": "any",
|
||||
"background_color": "#8e8e8e",
|
||||
"theme_color": "#e4e4e1",
|
||||
"icons": [
|
||||
{"src": "/static/arthur/icons/icon-192.png", "sizes": "192x192", "type": "image/png", "purpose": "any maskable"},
|
||||
{"src": "/static/arthur/icons/icon-512.png", "sizes": "512x512", "type": "image/png", "purpose": "any maskable"}
|
||||
]
|
||||
}
|
||||
|
|
@ -1,109 +0,0 @@
|
|||
// The service worker: what arthur keeps so it opens, and shows what it has
|
||||
// already shown, without the network. Served from `/sw.js` by `clips.views`
|
||||
// so its scope is the whole site; see `server/urls.py`.
|
||||
//
|
||||
// ONE RULE PER KIND OF URL, chosen by whether what is at it can change:
|
||||
//
|
||||
// - CONTENT-ADDRESSED — `/blob/<digest>`, `/api/blocks/<key>` — is named by its
|
||||
// own hash, so a copy cannot be stale: cache first, keep for good. These are
|
||||
// a project's frames, footage and drawings, cached as they load.
|
||||
// - VERSIONED — the bundle and the stylesheet, `?v=<mtime>` — is a new URL
|
||||
// for every build: cache first, and drop the versions it replaces.
|
||||
// - EVERYTHING ELSE of ours — the page, `/api/` reads, unversioned statics —
|
||||
// can change under the same URL: the network first, the last copy offline.
|
||||
//
|
||||
// A Range request is left to the browser: a `<video>` seeking a blob asks for
|
||||
// slices, and the Cache API cannot store a 206.
|
||||
|
||||
const KEEP = 'arthur-keep-v1'; // content-addressed, never stale
|
||||
const BUILD = 'arthur-build-v1'; // versioned bundle and styles
|
||||
const LAST = 'arthur-last-v1'; // last good copy of everything else
|
||||
|
||||
// The page every address opens, kept at install, so the app opens offline
|
||||
// even at an address it was never opened at.
|
||||
self.addEventListener('install', event => {
|
||||
event.waitUntil(caches.open(LAST).then(cache => cache.add('/')).catch(() => {}));
|
||||
self.skipWaiting();
|
||||
});
|
||||
|
||||
self.addEventListener('activate', event => {
|
||||
const ours = new Set([KEEP, BUILD, LAST]);
|
||||
event.waitUntil((async () => {
|
||||
for (const name of await caches.keys()) {
|
||||
if (!ours.has(name)) await caches.delete(name);
|
||||
}
|
||||
await self.clients.claim();
|
||||
})());
|
||||
});
|
||||
|
||||
const immutable = url =>
|
||||
url.pathname.startsWith('/blob/') || url.pathname.startsWith('/api/blocks/');
|
||||
|
||||
const versioned = url =>
|
||||
url.pathname.startsWith('/static/') && url.searchParams.has('v');
|
||||
|
||||
async function keep(cache, request) {
|
||||
const hit = await cache.match(request);
|
||||
if (hit) return hit;
|
||||
const response = await fetch(request);
|
||||
if (response.ok) await cache.put(request, response.clone());
|
||||
return response;
|
||||
}
|
||||
|
||||
async function build(request) {
|
||||
const cache = await caches.open(BUILD);
|
||||
const hit = await cache.match(request);
|
||||
if (hit) return hit;
|
||||
const response = await fetch(request);
|
||||
if (response.ok) {
|
||||
// A new build of this file replaces the old ones rather than piling up.
|
||||
const path = new URL(request.url).pathname;
|
||||
for (const old of await cache.keys()) {
|
||||
if (new URL(old.url).pathname === path) await cache.delete(old);
|
||||
}
|
||||
await cache.put(request, response.clone());
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
async function last(request, fallback) {
|
||||
const cache = await caches.open(LAST);
|
||||
try {
|
||||
const response = await fetch(request);
|
||||
if (response.ok) await cache.put(request, response.clone());
|
||||
return response;
|
||||
} catch (offline) {
|
||||
const hit = (await cache.match(request)) || (fallback && (await cache.match(fallback)));
|
||||
if (hit) return hit;
|
||||
throw offline;
|
||||
}
|
||||
}
|
||||
|
||||
// The rule for one request, or nil for the browser's own handling.
|
||||
function handle(request) {
|
||||
const url = new URL(request.url);
|
||||
if (request.method !== 'GET' || url.origin !== self.location.origin) return null;
|
||||
if (request.headers.has('range')) return null;
|
||||
if (url.pathname === '/sw.js') return null;
|
||||
|
||||
if (immutable(url)) return caches.open(KEEP).then(cache => keep(cache, request));
|
||||
if (versioned(url)) return build(request);
|
||||
// Every page is the same shell, which opens whichever project the path
|
||||
// names: offline, any copy of it will do.
|
||||
if (request.mode === 'navigate') return last(request, '/');
|
||||
if (url.pathname.startsWith('/api/') || url.pathname.startsWith('/static/')) return last(request);
|
||||
return null;
|
||||
}
|
||||
|
||||
self.addEventListener('fetch', event => {
|
||||
const answer = handle(event.request);
|
||||
if (answer) event.respondWith(answer);
|
||||
});
|
||||
|
||||
// The first page a worker sees loaded its bundle and styles before the worker
|
||||
// was there to keep them; it sends their URLs once the worker is ready.
|
||||
self.addEventListener('message', event => {
|
||||
const urls = (event.data && event.data.keep) || [];
|
||||
event.waitUntil(Promise.all(urls.map(u => handle(new Request(u))).filter(Boolean))
|
||||
.catch(() => {}));
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue