pele-animate 0.16.1 → 0.16.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -18,6 +18,7 @@ pnpm build # builds the site (a placeholder until the site lands)
18
18
  - The package is plain ESM at the repository root: no build step. The site lives in `site/`.
19
19
  - Docs are the Markdown files in `docs/`. A fenced block marked `mermaid` must render, and every `@{ icon }` name in it must exist.
20
20
  - Fence convention: ```` ```mermaid live ```` is a diagram GitHub can also draw; the site animates it. A diagram with `@{ icon }` nodes uses ```` ```mermaid-icons live ````, because GitHub's Mermaid cannot draw icons (it shows "?" boxes), so GitHub shows the source text and the site animates it.
21
+ - Every `live` fence carries a title after the word `live`: `title="Flowchart: cache hit or miss"`. The playground's examples menu shows it (grouped by page), so write "Type: what it shows".
21
22
  - Tabler packs are generated: `node scripts/build-tabler.mjs <path to a tabler-icons checkout>` rewrites `tabler/*.js`. Do not edit those
22
23
  files by hand. The Tabler version is recorded in each file header and in `THIRD-PARTY-NOTICES.md`.
23
24
  - Add an entry to `CHANGELOG.md` for any user-visible change. Breaking changes also get a section in `docs/migrating.md`.
@@ -36,7 +36,7 @@ are kept. Icon nodes (`@{ icon }`) work here; see [icons](./icons.md).
36
36
 
37
37
  The pins below put "Serve" (the cache hit) before "Fetch", then draw the `Fetch` to `Serve` edge as its own last step. Without them, `Serve` and `Fetch` would appear together.
38
38
 
39
- ```mermaid live
39
+ ```mermaid live title="Flowchart: cache hit or miss, with pins and an edge pin"
40
40
  flowchart LR
41
41
  %% pa: 1=A 2=B 3=C 4=D 5=D>C
42
42
  A[Client] --> B{Cached?}
@@ -48,7 +48,7 @@ flowchart LR
48
48
 
49
49
  Actors appear first, then one step per message in source order, so a cache miss reads as five short steps. Participant boxes in a row get the same height, and group titles are bold.
50
50
 
51
- ```mermaid live
51
+ ```mermaid live title="Sequence: API request with a cache miss"
52
52
  sequenceDiagram
53
53
  Client->>API: request
54
54
  API->>Cache: lookup
@@ -66,7 +66,7 @@ sequenceDiagram
66
66
  and `%% pa:` pins work the same way. The icon in parentheses is looked up in your icon packs, so Tabler names and `doverunner-*`
67
67
  names work (import the packs as for [icons](./icons.md)). The pins here follow a request: the user, the CDN, the API, the cache and database together, then the queue and worker.
68
68
 
69
- ```mermaid-icons live
69
+ ```mermaid-icons live title="Architecture: request path through CDN, API, cache, database and worker"
70
70
  architecture-beta
71
71
  %% pa: 1=user 2=cdn 3=api 4=cache,db 5=queue 6=worker
72
72
  group edge(cloud)[Edge]
@@ -94,7 +94,7 @@ Icons here are small and fixed in size; `form` and `h` apply to flowcharts only.
94
94
  `stateDiagram-v2`: states appear in step order, transitions draw from their source state, and transition labels fade in. The
95
95
  start and end markers are nodes too, with the ids `root_start` and `root_end`, so pins can name them.
96
96
 
97
- ```mermaid live
97
+ ```mermaid live title="State: media player with loading, error and retry"
98
98
  stateDiagram-v2
99
99
  %% pa: 1=root_start 2=Idle 3=Loading 4=Playing 5=Paused 6=Error 7=root_end
100
100
  [*] --> Idle
@@ -116,7 +116,7 @@ states and forks are untested. State diagrams take no icons.
116
116
  `C4Context`: people and systems appear in step order and each `Rel` draws from its source, with its label. Pins use the ids you
117
117
  give `Person(...)` and `System(...)`; an edge pin is `3=app>drm`. The example adds the DRM service, CDN and analytics one at a time, then the operator who reads the analytics.
118
118
 
119
- ```mermaid live
119
+ ```mermaid live title="C4 context: player app and the systems around it"
120
120
  C4Context
121
121
  %% pa: 1=viewer 2=app 3=drm 4=cdn 5=analytics 6=admin
122
122
  Person(viewer, "Viewer", "Watches video")
@@ -140,7 +140,7 @@ keep `Rel` labels short. Only `C4Context` has been checked; the other C4 types a
140
140
 
141
141
  `block-beta`: blocks appear in step order and each arrow draws from its source block. Pins use the block ids.
142
142
 
143
- ```mermaid live
143
+ ```mermaid live title="Block: video pipeline with a storage branch"
144
144
  block-beta
145
145
  columns 4
146
146
  %% pa: 1=src 2=enc 3=pkg 4=cdn 5=store
@@ -160,7 +160,7 @@ neighbour can give a bent arrow that runs along another one. Block diagrams take
160
160
  `classDiagram`: classes appear in step order, relationships draw from the class written first. `Media <|-- Video` reveals `Media`
161
161
  and then `Video`, whichever way the arrowhead points. Pins use the class names; the example shows the base class, its subtypes, then the classes that use them.
162
162
 
163
- ```mermaid live
163
+ ```mermaid live title="Class: media types, player and license"
164
164
  classDiagram
165
165
  %% pa: 1=Media 2=Video,Audio 3=Player 4=License 5=Session
166
166
  Media <|-- Video
@@ -179,7 +179,7 @@ classDiagram
179
179
  `erDiagram`: entities appear in step order, relationships draw from the entity written first (`CUSTOMER ||--o{ ORDER` reveals
180
180
  `CUSTOMER`, then `ORDER`). The example reads from the customer down to the supplier.
181
181
 
182
- ```mermaid live
182
+ ```mermaid live title="ER: customer orders and product suppliers"
183
183
  erDiagram
184
184
  %% pa: 1=CUSTOMER 2=ORDER 3=LINE 4=PRODUCT 5=SUPPLIER
185
185
  CUSTOMER ||--o{ ORDER : places
@@ -197,7 +197,7 @@ diagrams). Section headers, axes, grids and legends stay visible.
197
197
 
198
198
  - **`timeline`:** one step per time period, with its events. List periods in time order.
199
199
 
200
- ```mermaid live
200
+ ```mermaid live title="Timeline: product history in two phases"
201
201
  timeline
202
202
  title Product history
203
203
  section Build
@@ -211,7 +211,7 @@ timeline
211
211
 
212
212
  - **`journey`:** one step per task: the task, its face, and the line segment that joins it to the task before.
213
213
 
214
- ```mermaid live
214
+ ```mermaid live title="User journey: watching a protected video"
215
215
  journey
216
216
  title Watching a protected video
217
217
  section Find
@@ -228,7 +228,7 @@ journey
228
228
  - **`gitGraph`:** one step per commit in the order written, with the edge that ends on it. A branch's label and lane appear with
229
229
  its first commit.
230
230
 
231
- ```mermaid live
231
+ ```mermaid live title="Git graph: feature branch, merge and release"
232
232
  gitGraph
233
233
  commit id: "init"
234
234
  branch feature
@@ -243,7 +243,7 @@ gitGraph
243
243
 
244
244
  - **`gantt`:** one step per task, top to bottom: write tasks in the order you want them to appear.
245
245
 
246
- ```mermaid live
246
+ ```mermaid live title="Gantt: plan, build and ship"
247
247
  gantt
248
248
  dateFormat YYYY-MM-DD
249
249
  section Plan
@@ -43,7 +43,7 @@ watch(el, src); // pele-animate animates it, and re-applies when Pele
43
43
 
44
44
  The Mermaid source:
45
45
 
46
- ```mermaid-icons live
46
+ ```mermaid-icons live title="Icons: request, load balancer and cloud service"
47
47
  flowchart LR
48
48
  %% pa: 1=C 2=L 3=S
49
49
  C@{ icon: "http-get", form: "square", h: 88, label: "Request" }
package/docs/icons.md CHANGED
@@ -9,7 +9,7 @@ section: Guides
9
9
 
10
10
  A flowchart node becomes an illustrated node with Mermaid's own `@{ }` syntax:
11
11
 
12
- ```mermaid-icons live
12
+ ```mermaid-icons live title="Icons: laptop sending a request to a server"
13
13
  flowchart LR
14
14
  A@{ icon: "device-desktop", form: "square", h: 88, label: "Laptop" }
15
15
  B@{ icon: "server", form: "square", h: 88, label: "Server" }
@@ -26,7 +26,7 @@ them. By default, the order follows the edges. A `%% pa:` comment lets you set i
26
26
 
27
27
  Add one comment line anywhere in the source:
28
28
 
29
- ```mermaid live
29
+ ```mermaid live title="Pins: request, validate, respond with a shortcut"
30
30
  flowchart LR
31
31
  %% pa: 1=A 2=B 3=C
32
32
  A[Request] --> B[Validate] --> C[Respond]
@@ -40,7 +40,7 @@ level.
40
40
 
41
41
  `X>Y` pins the edge from X to Y to its own step, so an edge between two nodes that are already visible can be a step:
42
42
 
43
- ```mermaid live
43
+ ```mermaid live title="Edge pins: a reply as its own step"
44
44
  flowchart LR
45
45
  %% pa: 1=A,B 2=C 3=A>B
46
46
  A[Client] --> B[Server]
@@ -52,6 +52,7 @@ Rules that avoid surprises:
52
52
 
53
53
  - **Pin the nodes first.** An edge pinned before its target appears lands early.
54
54
  - A two-way edge (`A <--> B`) is pinned in the direction you wrote it first (`A>B`).
55
+ - The ends may be named in either order (`Video>Media` or `Media>Video`), unless the diagram also has the opposite edge: then the order picks which of the two is meant.
55
56
  - Do not rename node ids after pinning: pins match ids.
56
57
  - Translated pages keep the same ids, so copy the `%% pa:` line across languages after checking the ids match.
57
58
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pele-animate",
3
- "version": "0.16.1",
3
+ "version": "0.16.2",
4
4
  "description": "Step-by-step animated Mermaid diagrams with icons: an unofficial add-on for the Pele renderer.",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/pele-animate.js CHANGED
@@ -219,13 +219,17 @@ export function animate(svg, { hover = svg, source = '' } = {}) {
219
219
  return geoEndpoints(e, boxes);
220
220
  });
221
221
  const level = bfs(ids, pairs.filter(Boolean), parseOrder(source));
222
+ // An edge pin may name the ends in either order (`Video>Media` for `Media <|-- Video`, or either end of an undirected edge),
223
+ // unless the diagram also has the opposite edge, where the order picks which of the two is meant.
224
+ const real = new Set(pairs.filter(Boolean).map(([a, b]) => `${a}>${b}`));
225
+ const pinOf = (s, d) => level.get(`${s}>${d}`) ?? (real.has(`${d}>${s}`) ? undefined : level.get(`${d}>${s}`));
222
226
  const u = Math.min(UNIT, MAX_INTRO / (Math.max(0, ...level.values()) + 1));
223
227
  const k = u / UNIT;
224
228
  nodes.forEach((n) => { set(n, level.get(n.dataset.id) * u); step.set(n, level.get(n.dataset.id)); });
225
229
  // Start after the source is up, but never so early that the arrow lands before its target appears (pinned steps).
226
230
  edges.forEach((e, i) => {
227
231
  const [s, d] = pairs[i] ?? [];
228
- const pin = level.get(`${s}>${d}`); // edge pinned to a step: starts with that step, once its source is up
232
+ const pin = pinOf(s, d); // edge pinned to a step: starts with that step, once its source is up
229
233
  step.set(e, pin ?? Math.max(level.get(s) ?? 0, level.get(d) ?? 0));
230
234
  times.set(e, pin !== undefined
231
235
  ? Math.max(pin * u, (level.get(s) ?? 0) * u + 0.3 * k)