Compare commits

..

2 commits

Author SHA1 Message Date
Olive Vaughn
2eb5944a78 A clip says where what it plays runs out
Lengthening a placement past the end of the symbol it plays made the bar
longer and the picture empty, with nothing on the bar to say so: a symbol
made at the playhead near the end is only a few frames long, and moving it
back and stretching it showed those few frames and then nothing. The
frames past the symbol's end are now drawn empty inside the clip's outline,
as Flash leaves an empty frame unfilled, on a row's bar and on a lane's
clip alike. A held or looping placement always has a frame to show and is
never marked.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-11 15:26:19 -04:00
Olive Vaughn
fce76dfaa6 A pointer finds what it points at by name; following takes a tool as a tool
A step of a pointer's path is matched first by what the element is called —
its id, aria-label or a field's name — then by its classes. The pool, the
inspector and the timeline say which pane they are, so a path names the
inspector rather than the second section.pane.

Taking a facet back catches up on that facet alone, not on everything a
mate last said: their frame has moved on since if they are playing. A
mate's tool and selection are taken through the app's own functions, so a
tool change finishes your open pen polygon as it would if you made it.
On your own, an event no longer builds the shared view twice to find out
nobody is listening, and a pointer that has arrived is redrawn four times
a second rather than every frame.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-11 13:51:09 -04:00
8 changed files with 178 additions and 59 deletions

View file

@ -665,16 +665,17 @@
(declare finishing-polygon)
(rf/reg-event-db
::set-tool
;; Leaving the pen commits what it was drawing, as Esc does: an unfinished
;; polygon is not a thing the document can hold.
(fn [db [_ tool]]
(if (contains? tools tool)
(-> (if (= tool (get-in db [:ui :tool])) db (finishing-polygon db))
(update :ui merge {:tool tool :draft []})
(update :ui dissoc :hover))
db)))
(defn with-tool
"`db` on `tool`. Leaving the pen commits what it was drawing, as Esc does: an
unfinished polygon is not a thing the document can hold."
[db tool]
(if (contains? tools tool)
(-> (if (= tool (get-in db [:ui :tool])) db (finishing-polygon db))
(update :ui merge {:tool tool :draft []})
(update :ui dissoc :hover))
db))
(rf/reg-event-db ::set-tool (fn [db [_ tool]] (with-tool db tool)))
(rf/reg-event-db
::cancel-polygon

View file

@ -21,6 +21,7 @@
own clock, and a play goes out once with its frame rather than streamed."
(:require [arthur.events.collab :as collab]
[arthur.events.playback :as pb]
[arthur.events.ui :as ui]
[arthur.follow.page :as page]
[arthur.follow.party :as party]
[arthur.ui.menu :as menu]
@ -52,14 +53,23 @@
[:scroll "panel scroll" nil]
[:pointers "pointers" nil]])
(defn- facet-paths [k] (some (fn [[fk _ ps]] (when (= fk k) ps)) facets))
(def ^:private takes
"Values taken the way the app takes them, not written over, because writing
would skip what it does on the way: a new tool commits the pen's unfinished
polygon, and a selection carries the multi-selection along with it."
{[:ui :tool] ui/with-tool
[:ui :selection] ui/selected})
;; ---------------------------------------------------------------------------
;; what we keep
;;
;; `[:presence :party]` and `[:presence :joinable]` are what we tell the room;
;; `collab` says them again when the socket comes back, which is the rejoin.
;; `:follow` is ours alone: the facets let go of, a move we could not take yet
;; (`:parked`), and the last move a mate made, to catch up to on taking a facet
;; back.
;; (`:parked`), and `:last`, everything mates have said of where they are, to
;; catch up to on taking a facet back.
(def ^:private stored {:joinable "arthur/followable" :off "arthur/follow-off"})
@ -119,19 +129,26 @@
;; taken only on the tab it was made on.
(fn [{:keys [db]} [_ cid v]]
(let [open (get v [:ui :open])
last (second (get-in db [:follow :last]))
place? (and (contains? v [:ui :open]) (not (contains? (off db) :place)))
taken (select-keys v (remove #{[:ui :open]} (paths db)))]
(cond
(not (party/mirrors? (:peers db) (me db) cid)) {}
(and place? (not (pb/openable? db open)))
{:db (update db :follow assoc :parked [cid v] :last [cid v])}
{:db (update db :follow assoc :parked [cid v] :last [cid (merge last v)])}
:else
(let [switch? (and place? (not= open (get-in db [:ui :open])))
db (cond-> (update db :follow assoc :parked nil :last [cid v])
db (cond-> (update db :follow assoc :parked nil :last [cid (merge last v)])
switch? (pb/open open))
;; In facet order, so `:selections` lands after the `:selection`
;; it belongs to.
db (cond-> db
(= (get v ::tab) (get-in db [:ui :open]))
(as-> db (reduce-kv #(assoc-in %1 (at %1 %2) %3) db taken)))
(as-> db (reduce (fn [db p]
(if (contains? taken p)
((takes p #(assoc-in %1 (at %1 p) %2)) db (taken p))
db))
db (paths db))))
n (pb/frames db)
f (-> (get-in db [:playback :frame] 0) (max 0) (min (dec n)))
db (assoc-in db [:playback :frame] f)]
@ -157,19 +174,22 @@
(rf/->interceptor
:id ::steer
:after (fn [ctx]
(let [event (first (get-in ctx [:coeffects :event]))
before (get-in ctx [:coeffects :db])
after (get-in ctx [:effects :db])
[_ v :as parked] (get-in after [:follow :parked])]
(cond-> ctx
(and parked (pb/openable? after (get v [:ui :open])))
(update-in [:effects :fx] (fnil conj []) [:dispatch (into [::moved] parked)])
(let [after (get-in ctx [:effects :db])]
;; On your own, which is nearly always, an event costs this and
;; nothing more.
(if-not (and after (together? after))
ctx
(let [event (first (get-in ctx [:coeffects :event]))
before (get-in ctx [:coeffects :db])
[_ v :as parked] (get-in after [:follow :parked])]
(cond-> ctx
(and parked (pb/openable? after (get v [:ui :open])))
(update-in [:effects :fx] (fnil conj []) [:dispatch (into [::moved] parked)])
(not (or (nil? after) (#{::pb/tick ::moved} event)
(= (view before (paths after)) (view after))
(not= (get-in before [:project :id]) (get-in after [:project :id]))
(not (together? after))))
(update-in [:effects :fx] (fnil conj []) [::nav! (view-msg after)]))))))
(not (or (#{::pb/tick ::moved} event)
(not= (get-in before [:project :id]) (get-in after [:project :id]))
(= (view before (paths after)) (view after))))
(update-in [:effects :fx] (fnil conj []) [::nav! (view-msg after)]))))))))
;; ---------------------------------------------------------------------------
;; the room
@ -243,15 +263,18 @@
(rf/reg-event-fx
::toggle
;; Taking a facet back catches up to where the party last was.
;; Taking a facet back catches up on that facet — and only that one: the rest
;; of what they last said is as old as it is, and their frame, say, has moved
;; on since if they are playing.
(fn [{:keys [db]} [_ k]]
(let [was (off db)
now (if (contains? was k) (disj was k) (conj was k))
db (assoc-in db [:follow :off] now)]
db (assoc-in db [:follow :off] now)
[cid v] (get-in db [:follow :last])]
(cond-> {:db db ::remember [:off (.join (to-array (map name now)) ",")]}
(= :pointers k) (assoc ::forget :all)
(and (contains? was k) (get-in db [:follow :last]))
(assoc :dispatch (into [::moved] (get-in db [:follow :last])))))))
(and (contains? was k) cid (facet-paths k))
(assoc :dispatch [::moved cid (select-keys v (conj (facet-paths k) ::tab))])))))
(rf/reg-sub ::joinable? (fn [db _] (get-in db [:presence :joinable] true)))
(rf/reg-sub ::together? (fn [db _] (together? db)))

View file

@ -27,6 +27,14 @@
(defn- classes [^js el] (.getAttribute el "class"))
(defn- kind [^js el] [(.-localName el) (.. el -classList (item 0))])
(defn- label
"What `el` is called, if anything says: an id, an aria-label, a field's name.
Written for people and screen readers, so it says WHICH thing it is — the
inspector, not the second `section.pane` — and it does not change when the
layout does."
[^js el]
(some (fn [a] (some->> (.getAttribute el a) not-empty (str a "="))) ["id" "aria-label" "name"]))
(defn- nth-like
"Which of `el`'s siblings that `same?` says are like it, it is."
[^js el same?]
@ -34,22 +42,22 @@
(filter same? (array-seq (.. el -parentElement -children))))))
(defn- step
"`el` as one step of a path: its tag and classes, which of its siblings with
those it is, and which of those with its tag and FIRST class. The pool and the
inspector are both a `section.pane`, so the first class alone takes one for
the other whenever a pane is shut on one page and not the other; but the rest
come and go with state — `on`, `selected` — and a row lit on one page is still
the same row on the other, so that is what a step falls back to."
"`el` as one step of a path, three ways from surest to least: by what it is
called, among its siblings called that; by its tag and classes; and by its tag
and FIRST class, because the rest come and go with state — `on`, `selected` —
and a row lit on one page is still the same row on the other."
[^js el]
(let [tag (.-localName el) cls (classes el) k (kind el)]
(let [tag (.-localName el) cls (classes el) k (kind el) l (label el)]
[tag cls
(nth-like el #(and (= tag (.-localName %)) (= cls (classes %))))
(nth-like el #(= k (kind %)))]))
(nth-like el #(= k (kind %)))
l (when l (nth-like el #(= l (label %))))]))
(defn- child [^js parent [tag cls n m]]
(defn- child [^js parent [tag cls n m l i]]
(let [kids (array-seq (.-children parent))
k [tag (not-empty (first (some-> cls (.split " "))))]]
(or (nth (filter #(and (= tag (.-localName %)) (= cls (classes %))) kids) n nil)
(or (when l (nth (filter #(= l (label %)) kids) i nil))
(nth (filter #(and (= tag (.-localName %)) (= cls (classes %))) kids) n nil)
(nth (filter #(= k (kind %)) kids) m nil))))
(defn- lineage
@ -94,7 +102,7 @@
;; drawing them
(defonce ^:private shown (atom {})) ; cid → {:msg :found :clip :xy :el}
(defonce ^:private raf (atom nil))
(defonce ^:private ticking (atom nil)) ; [:frame id] or [:idle id]
(defn- layer []
(or (.getElementById js/document "follow-layer")
@ -141,18 +149,36 @@
cx (max l (min r x)) cy (max t (min b y))]
{:xy [cx cy] :lost? (< d (count path)) :away? (not= [x y] [cx cy])}))
(declare frame!)
(defn- tick!
"Draw again: next frame while a pointer is on its way, and four times a
second once they have all arrived — only to notice a layout that moved
under one, a pane opened or a list scrolled, which no message announces."
[moving?]
(reset! ticking (cond (empty? @shown) nil
moving? [:frame (js/requestAnimationFrame frame!)]
:else [:idle (js/setTimeout frame! 250)])))
(defn- frame! [_]
(doseq [[cid {:keys [found xy ^js el] :as s}] @shown]
(let [s (cond-> s (not (.-isConnected ^js (peek found))) resolved)
{[tx ty] :xy :keys [lost? away?]} (target s)
;; Halfway there each frame: messages come every 40ms, frames every
;; 16, and a pointer that jumps between them looks like it stutters.
[x y] (if xy [(+ (xy 0) (* 0.5 (- tx (xy 0)))) (+ (xy 1) (* 0.5 (- ty (xy 1))))] [tx ty])]
(set! (.. el -style -transform) (str "translate(" x "px," y "px)"))
(.toggle (.-classList el) "lost" lost?)
(.toggle (.-classList el) "away" away?)
(swap! shown assoc cid (assoc s :xy [x y]))))
(reset! raf (when (seq @shown) (js/requestAnimationFrame frame!))))
(tick!
(reduce
(fn [moving? [cid {:keys [found xy ^js el] :as s}]]
(let [s (cond-> s (not (.-isConnected ^js (peek found))) resolved)
{[tx ty] :xy :keys [lost? away?]} (target s)
;; Halfway there each frame: messages come every 40ms, frames every
;; 16, and a pointer that jumps between them looks like it stutters.
;; Within half a pixel, there.
[x y] (if (and xy (< 0.5 (js/Math.hypot (- tx (xy 0)) (- ty (xy 1)))))
[(+ (xy 0) (* 0.5 (- tx (xy 0)))) (+ (xy 1) (* 0.5 (- ty (xy 1))))]
[tx ty])]
(when (not= xy [x y])
(set! (.. el -style -transform) (str "translate(" x "px," y "px)")))
(.toggle (.-classList el) "lost" lost?)
(.toggle (.-classList el) "away" away?)
(swap! shown assoc cid (assoc s :xy [x y]))
(or moving? (not= [x y] [tx ty]))))
false @shown)))
(defn gone! [cid]
(some-> (get-in @shown [cid :el]) .remove)
@ -174,7 +200,10 @@
#js [#js {:transform "scale(.3)" :opacity 1} #js {:transform "scale(1.6)" :opacity 0}]
450))
(swap! shown assoc cid (-> (resolved m) (assoc :msg m :el el :xy (:xy was))))
(when-not @raf (reset! raf (js/requestAnimationFrame frame!))))))
(let [[how id] @ticking]
(when-not (= :frame how)
(some-> id js/clearTimeout)
(tick! true))))))
;; ---------------------------------------------------------------------------
;; scroll

View file

@ -937,7 +937,7 @@
;; the open symbol; the open symbol itself is at no path at all.
path (if placed (or (nth selection 3 nil) [(second node)]) [])
a-face? (and face (face? clip face) (not layer?))]
[:section.pane.params
[:section.pane.params {:aria-label "inspector"}
[:div.pane-head "inspector"]
[:div.inspect
(cond

View file

@ -698,7 +698,8 @@
tallies (counts ctx)
files? (fn [^js e] (some #{"Files"} (array-seq (.. e -dataTransfer -types))))]
[:section.pane.pool
{:class (when (pos? @depth) "dropping")
{:aria-label "media pool"
:class (when (pos? @depth) "dropping")
;; Only a FILE lights the pane up: a row dragged out of the pool is on
;; its way somewhere else.
:on-drag-enter (fn [^js e] (when (files? e) (.preventDefault e) (swap! depth inc)))

View file

@ -79,6 +79,20 @@
(+ at (/ (or (clip/frames clip (node/source n)) 0) rate))
(clip/frames clip sid)))
(defn- shows
"Where on the ruler `n` has something to show, as `[from to)`, given `->open`
from its own frames to the ruler's; nil where it places nothing or shows
something across all of its span.
A SPAN IS NOT CONTENT. Lengthening a placement past the end of the symbol it
plays leaves the bar longer and the picture empty — `node/placed-frame` runs
out — so the row has to say where the symbol does. A held or looping
placement always has a frame to show, so only a playing one answers."
[clip n ->open]
(when-let [t (and (node/source n) (node/source-time n))]
(mapv (comp ->open (time->parent t))
[0 (or (clip/frames clip (node/source n)) 0)])))
(defn- node-label
"What to call a node in the label column.
@ -194,6 +208,7 @@
:expandable? true
:expanded? open?
:span cspan
:shows (shows clip child cself)
:key-items (key-items child sid cself)
:keys (into [] (comp (mapcat keyed-frames)
(map cself)
@ -242,6 +257,7 @@
(node-label clip (:id child) child))
:source (node/source child)
:span (mapv ->open (node/placed-span child))
:shows (shows clip child (comp ->open (local->parent child)))
:key-items (key-items child sid (comp ->open (local->parent child)))
:keys (into []
(comp (mapcat keyed-frames)
@ -306,6 +322,7 @@
:expandable? true
:expanded? open?
:span span
:shows (shows clip n self)
:key-items (key-items n sid self)
:keys (into [] (comp (mapcat keyed-frames)
(map self)
@ -328,6 +345,7 @@
(some-> (node/source child) name))
:source (node/source child)
:span (mapv source-self (node/placed-span child))
:shows (shows clip child (comp source-self (local->parent child)))
;; The clip's own keys, on the
;; block, so a collapsed lane
;; still says where it changes.
@ -1046,12 +1064,24 @@
(reset! gesture nil) (when @preview (reset! preview nil)))
:on-pointer-cancel (fn [e] (.stopPropagation e) (reset! gesture nil) (reset! preview nil))}])))
(defn- runout
"The stretches of a bar drawn from `in` to `out` where what it places has
nothing to show — see `shows` — as Flash draws empty frames: unfilled, inside
the outline of a clip that still lasts there."
[in out shows]
(when-let [[from to] shows]
(for [[a b] [[in (min out from)] [(max in to) out]]
:when (< a b)]
^{:key a}
[:span.tl-runout {:style {:left (str (* 100 (/ (- a in) (- out in))) "%")
:width (str (* 100 (/ (- b a) (- out in))) "%")}}])))
(defn- track-cell
"`sliding` is the gesture in flight: `{:row :path :kind :from :df}`, where
`:from` is the frame the press was on and `:df` how many frames the pointer has
moved since. What it looks like mid-drag is `[:ui :sliding]`, which the clip
every row and the stage are drawn from already has in it."
[{:keys [path span keys key-items gaps dense? kind node-kind select slides cels lane? of unmapped? owner]}
[{:keys [path span shows keys key-items gaps dense? kind node-kind select slides cels lane? of unmapped? owner]}
frames sliding hint {:keys [clip store open selection selections target-path key-selection key-preview key-anchor key-state key-elements choose-row!]}]
(let [selected-set (set selections)
active-row (:row @sliding)
@ -1313,6 +1343,7 @@
:on-pointer-down
(when (and select (not unmapped?))
#(begin! % (or slides path) :slide select nil nil))}
(runout in out shows)
(when (and select (not unmapped?))
[:span.tl-edge.in {:title "Drag start"
:on-pointer-down #(begin! % path :in select nil nil)}])
@ -1320,7 +1351,7 @@
[:span.tl-edge.out {:title "Drag endpoint · Shift-drag ripples later clips"
:on-pointer-down #(begin! % path :out select nil nil)}])]))
(doall
(for [[i {:keys [id label source span select ghost?]}]
(for [[i {:keys [id label source span shows select ghost?]}]
(map-indexed vector
(cond-> (vec cels)
(= select (:target-lane @sliding))
@ -1377,6 +1408,7 @@
{:selection select :label label
:in (js/Math.floor in)
:duration (- out in)}))}
(runout in out shows)
[:span.tl-cel-label label]
(when select
(if joined?
@ -1667,7 +1699,8 @@
(when (not= [clip-id open] @key-context)
(reset! key-context [clip-id open]) (reset! key-selection []) (reset! key-preview nil) (reset! key-anchor nil) (reset! row-anchor nil))
[:section.pane.time
{:tab-index -1
{:aria-label "timeline"
:tab-index -1
:on-key-down (fn [e]
(when (and (= (.-target e) (.-currentTarget e))
(#{"Delete" "Backspace"} (.-key e)))

View file

@ -225,6 +225,28 @@
(is (= [[2 3]] (mapv :span (:cels lane)))
"a lane placed at twice the speed draws its frames 4–6 on ruler frames 2–3")))
(deftest a-bar-says-where-what-it-plays-runs-out
(let [placed {:id :short :kind :instance :z "a" :span [0 10]
:time {:at 6 :rate 1}
:source {:symbol :short}
:playback {:in 0 :speed 1 :end :stop}}
doc (-> (clip/blank)
(assoc-in [:symbols :main :frames] 24)
(assoc-in [:symbols :main :nodes] {:short placed})
(assoc-in [:symbols :short] {:id :short :frames 4 :nodes {}}))
row #(first (timeline/rows % :main #{}))]
(is (= [6 16] (:span (row doc))))
(is (= [6 10] (:shows (row doc)))
"four frames of symbol, stretched to ten, show from 6 to 10 only")
(is (nil? (:shows (row (assoc-in doc [:symbols :main :nodes :short :playback :speed] 0))))
"a held placement shows its frame across the whole span")
(let [lane (-> (assoc-in doc [:symbols :main :display] :lane)
(assoc-in [:symbols :main :nodes :short :playback :speed] 2)
(timeline/rows :main #{})
first)]
(is (= [[6 8]] (mapv :shows (:cels lane)))
"a clip in a lane says it too, at its own speed"))))
(deftest an-ordinary-symbol-keeps-a-row-per-node
(let [doc (update-in (fixture/document) [:symbols :main] dissoc :display)
rows (timeline/rows doc :main #{})]

View file

@ -1372,6 +1372,16 @@ button.followable svg { width: 12px; height: 12px; display: block; }
text-overflow: ellipsis;
pointer-events: none;
}
/* Frames of a clip past the end of what it plays: still the clip's — the outline
and the handles go on — but empty, as Flash leaves an empty frame unfilled. */
.tl-runout {
position: absolute;
top: 0;
bottom: 0;
background: repeating-linear-gradient(135deg, var(--pane) 0 3px, var(--sunk) 3px 6px);
pointer-events: none;
}
.tl-cel-label { position: relative; }
.tl-span.ghost {
background: transparent;
border: 1px dashed var(--sel);