ponzu 1.77.0 → 1.78.0

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.
package/dist/chromium.js CHANGED
@@ -8599,6 +8599,13 @@ var BLOCKED_TAGS = new Set([
8599
8599
  ]);
8600
8600
  var URL_ATTRS = new Set(["href", "src", "xlink:href", "action", "formaction", "poster", "data"]);
8601
8601
  var RAW_TEXT = new Set(["style"]);
8602
+ var ACT_SCRIPT_TYPE = "ponzu/act";
8603
+ function isActScript(el) {
8604
+ if (el.tagName.toLowerCase() !== "script")
8605
+ return false;
8606
+ const type = el.attrs.find((a) => !a.prefix && a.name.toLowerCase() === "type")?.value;
8607
+ return type?.trim().toLowerCase() === ACT_SCRIPT_TYPE;
8608
+ }
8602
8609
  function parseHtml(html, opts = {}) {
8603
8610
  const dropped = [];
8604
8611
  const context = opts.parent ? foreignContext(opts.parent) : null;
@@ -8655,7 +8662,7 @@ function convertChildren(list, path, ids, dropped) {
8655
8662
  continue;
8656
8663
  const el = child;
8657
8664
  const tag = el.tagName;
8658
- if (BLOCKED_TAGS.has(tag.toLowerCase())) {
8665
+ if (BLOCKED_TAGS.has(tag.toLowerCase()) && !isActScript(el)) {
8659
8666
  dropped.push({ what: `<${tag}>` });
8660
8667
  continue;
8661
8668
  }
@@ -8694,6 +8701,22 @@ function convertElement(el, path, ids, dropped) {
8694
8701
  if (!id || ids.seen.has(id))
8695
8702
  id = makeUpId(ids, path);
8696
8703
  ids.seen.add(id);
8704
+ if (el.tagName === "script") {
8705
+ for (const k of Object.keys(attrs)) {
8706
+ if (k.toLowerCase() === "type")
8707
+ continue;
8708
+ dropped.push({ what: `${k} on <script>` });
8709
+ delete attrs[k];
8710
+ }
8711
+ attrs.type = ACT_SCRIPT_TYPE;
8712
+ const text = el.childNodes.map((c) => c.nodeName === "#text" ? c.value : "").join("");
8713
+ const node = { kind: "el", id, tag: "script", attrs, style: {}, children: [] };
8714
+ if (name !== undefined)
8715
+ node.name = name;
8716
+ if (text)
8717
+ node.children.push({ kind: "text", value: text });
8718
+ return node;
8719
+ }
8697
8720
  const ns = el.namespaceURI === NS_SVG ? "svg" : el.namespaceURI === NS_MATH ? "math" : undefined;
8698
8721
  const node = { kind: "el", id, tag: el.tagName, attrs, style, children: [] };
8699
8722
  if (ns)
@@ -8728,6 +8751,8 @@ function serializeNodes(nodes, opts = {}) {
8728
8751
  function serializeNode(node, opts = {}, rawText = false, inForeign) {
8729
8752
  if (node.kind === "text")
8730
8753
  return rawText ? node.value : escapeText(node.value);
8754
+ if (node.tag === "script" && !node.ns)
8755
+ return serializeActScript(node, opts);
8731
8756
  let out = `<${node.tag}`;
8732
8757
  if (!opts.omitIds)
8733
8758
  out += ` data-id="${node.id}"`;
@@ -8762,6 +8787,18 @@ function serializeNode(node, opts = {}, rawText = false, inForeign) {
8762
8787
  }
8763
8788
  return `${out}</${node.tag}>`;
8764
8789
  }
8790
+ function serializeActScript(node, opts) {
8791
+ let out = "<script";
8792
+ if (!opts.omitIds)
8793
+ out += ` data-id="${node.id}"`;
8794
+ if (node.name !== undefined)
8795
+ out += ` data-name="${escapeAttr(node.name)}"`;
8796
+ out += ` type="${ACT_SCRIPT_TYPE}">`;
8797
+ for (const c of node.children)
8798
+ if (c.kind === "text")
8799
+ out += c.value.replace(/<(\/script|!--)/gi, "<\\$1");
8800
+ return `${out}</script>`;
8801
+ }
8765
8802
  var SVG_HTML_INTEGRATION = new Set(["foreignObject", "desc", "title"]);
8766
8803
  var MATHML_TEXT_INTEGRATION = new Set(["mi", "mo", "mn", "ms", "mtext"]);
8767
8804
  function childrenAreForeign(node) {
@@ -11856,6 +11893,1833 @@ function resolveAsset(url, base) {
11856
11893
  return `${base.replace(/\/$/, "")}/${clean}`;
11857
11894
  }
11858
11895
 
11896
+ // packages/render/src/act.ts
11897
+ function actCore() {
11898
+ const CURVES = {
11899
+ house: "cubic-bezier(0.65, 0, 0.1, 1)",
11900
+ through: "cubic-bezier(0.8, 0, 0.1, 1)",
11901
+ settle: "cubic-bezier(0.05, 0.85, 0.3, 1)",
11902
+ enter: "cubic-bezier(0.1, 0.8, 0.3, 0.95)",
11903
+ trip: "cubic-bezier(0.78, 0, 0.17, 1)",
11904
+ camera: "cubic-bezier(0.45, 0, 0.1, 1)",
11905
+ out: "cubic-bezier(0.22, 1, 0.36, 1)",
11906
+ in: "cubic-bezier(0.55, 0, 1, 0.45)",
11907
+ inout: "cubic-bezier(0.65, 0, 0.35, 1)"
11908
+ };
11909
+ const NAMED = {
11910
+ ease: [0.25, 0.1, 0.25, 1],
11911
+ "ease-in": [0.42, 0, 1, 1],
11912
+ "ease-out": [0, 0, 0.58, 1],
11913
+ "ease-in-out": [0.42, 0, 0.58, 1]
11914
+ };
11915
+ const VERBS = new Set([
11916
+ "loop",
11917
+ "once",
11918
+ "cursor",
11919
+ "move",
11920
+ "hover",
11921
+ "enter",
11922
+ "click",
11923
+ "tap",
11924
+ "drag",
11925
+ "swipe",
11926
+ "type",
11927
+ "stream",
11928
+ "key",
11929
+ "show",
11930
+ "hide",
11931
+ "set",
11932
+ "unset",
11933
+ "focus",
11934
+ "blur",
11935
+ "count",
11936
+ "slide",
11937
+ "zoom",
11938
+ "scroll",
11939
+ "wait",
11940
+ "poster",
11941
+ "reset"
11942
+ ]);
11943
+ function curve(name, fallback) {
11944
+ if (!name)
11945
+ return fallback;
11946
+ return CURVES[name] ?? name;
11947
+ }
11948
+ function ms(v) {
11949
+ if (v === undefined)
11950
+ return null;
11951
+ const m = /^(-?\d*\.?\d+)(ms|s)?$/.exec(v.trim());
11952
+ if (!m)
11953
+ return null;
11954
+ return m[2] === "s" ? Number(m[1]) * 1000 : Number(m[1]);
11955
+ }
11956
+ function easer(css) {
11957
+ let p = NAMED[css.trim()];
11958
+ const m = /^cubic-bezier\(([^)]+)\)$/.exec(css.trim());
11959
+ if (m) {
11960
+ const n = m[1].split(",").map(Number);
11961
+ if (n.length === 4 && n.every(Number.isFinite))
11962
+ p = n;
11963
+ }
11964
+ if (!p)
11965
+ return (t) => t;
11966
+ const [x1, y1, x2, y2] = p;
11967
+ const cx = 3 * x1;
11968
+ const bx = 3 * (x2 - x1) - cx;
11969
+ const ax = 1 - cx - bx;
11970
+ const cy = 3 * y1;
11971
+ const by = 3 * (y2 - y1) - cy;
11972
+ const ay = 1 - cy - by;
11973
+ const x = (u) => ((ax * u + bx) * u + cx) * u;
11974
+ const dx = (u) => (3 * ax * u + 2 * bx) * u + cx;
11975
+ return (t) => {
11976
+ if (t <= 0)
11977
+ return 0;
11978
+ if (t >= 1)
11979
+ return 1;
11980
+ let u = t;
11981
+ for (let i = 0;i < 8; i++) {
11982
+ const d = dx(u);
11983
+ if (Math.abs(d) < 0.000001)
11984
+ break;
11985
+ const next = u - (x(u) - t) / d;
11986
+ if (next < 0 || next > 1)
11987
+ break;
11988
+ u = next;
11989
+ }
11990
+ if (Math.abs(x(u) - t) > 0.000001) {
11991
+ let lo = 0;
11992
+ let hi = 1;
11993
+ for (let i = 0;i < 40; i++) {
11994
+ u = (lo + hi) / 2;
11995
+ if (x(u) < t)
11996
+ lo = u;
11997
+ else
11998
+ hi = u;
11999
+ }
12000
+ }
12001
+ return ((ay * u + by) * u + cy) * u;
12002
+ };
12003
+ }
12004
+ function words(line) {
12005
+ const out = [];
12006
+ let i = 0;
12007
+ const n = line.length;
12008
+ while (i < n) {
12009
+ while (i < n && /\s/.test(line[i]))
12010
+ i++;
12011
+ if (i >= n || line.startsWith("//", i))
12012
+ break;
12013
+ let tok = "";
12014
+ let depth = 0;
12015
+ while (i < n && (depth > 0 || !/\s/.test(line[i]))) {
12016
+ const c = line[i];
12017
+ if (c === '"' || c === "'") {
12018
+ const close = line.indexOf(c, i + 1);
12019
+ const end = close < 0 ? n : close;
12020
+ tok += depth > 0 ? line.slice(i, end + 1) : line.slice(i + 1, end);
12021
+ i = end + 1;
12022
+ continue;
12023
+ }
12024
+ if (c === "[" || c === "(")
12025
+ depth++;
12026
+ else if ((c === "]" || c === ")") && depth > 0)
12027
+ depth--;
12028
+ tok += c;
12029
+ i++;
12030
+ }
12031
+ out.push(tok);
12032
+ }
12033
+ return out;
12034
+ }
12035
+ function parse(text) {
12036
+ const lines = [];
12037
+ const issues = [];
12038
+ let loop = true;
12039
+ const rows = text.split(/\r?\n/);
12040
+ for (let i = 0;i < rows.length; i++) {
12041
+ const raw = rows[i].trim();
12042
+ if (!raw || raw.startsWith("//"))
12043
+ continue;
12044
+ let ws = words(raw);
12045
+ let together = false;
12046
+ if (ws[0] === "&") {
12047
+ together = true;
12048
+ ws = ws.slice(1);
12049
+ } else if (ws[0]?.startsWith("&")) {
12050
+ together = true;
12051
+ ws[0] = ws[0].slice(1);
12052
+ }
12053
+ const verb = (ws[0] ?? "").toLowerCase();
12054
+ if (!verb)
12055
+ continue;
12056
+ if (!VERBS.has(verb)) {
12057
+ issues.push({ line: i + 1, message: `"${ws[0]}" isn't a beat` });
12058
+ continue;
12059
+ }
12060
+ if (verb === "loop" || verb === "once") {
12061
+ loop = verb === "loop";
12062
+ continue;
12063
+ }
12064
+ const args = [];
12065
+ const opts = {};
12066
+ for (const w of ws.slice(1)) {
12067
+ const m = /^([a-z][\w-]*)=(.*)$/i.exec(w);
12068
+ if (m)
12069
+ opts[m[1].toLowerCase()] = m[2];
12070
+ else
12071
+ args.push(w);
12072
+ }
12073
+ lines.push({
12074
+ line: i + 1,
12075
+ text: raw.replace(/\s+\/\/.*$/, ""),
12076
+ verb,
12077
+ args,
12078
+ opts,
12079
+ with: together
12080
+ });
12081
+ }
12082
+ return { loop, lines, issues };
12083
+ }
12084
+ function random(seed) {
12085
+ let h = 1779033703 ^ seed.length;
12086
+ for (let i = 0;i < seed.length; i++) {
12087
+ h = Math.imul(h ^ seed.charCodeAt(i), 3432918353);
12088
+ h = h << 13 | h >>> 19;
12089
+ }
12090
+ let a = h >>> 0;
12091
+ return () => {
12092
+ a = a + 1831565813 >>> 0;
12093
+ let t = a;
12094
+ t = Math.imul(t ^ t >>> 15, t | 1);
12095
+ t ^= t + Math.imul(t ^ t >>> 7, t | 61);
12096
+ return ((t ^ t >>> 14) >>> 0) / 4294967296;
12097
+ };
12098
+ }
12099
+ function cadence(units, each, seed) {
12100
+ const r = random(seed);
12101
+ const out = [];
12102
+ let t = 0;
12103
+ for (let i = 0;i < units.length; i++) {
12104
+ out.push(Math.round(t));
12105
+ const u = units[i];
12106
+ const pause = /[.!?,;:]\s*$/.test(u) ? 2.6 : /\s$/.test(u) ? 1.4 : 1;
12107
+ t += each * pause * (0.6 + r() * 0.8);
12108
+ }
12109
+ return out;
12110
+ }
12111
+ function arc(a, b, ease, bow, samples) {
12112
+ const e = easer(ease);
12113
+ const dist = Math.hypot(b.x - a.x, b.y - a.y) || 1;
12114
+ const nx = -(b.y - a.y) / dist;
12115
+ const ny = (b.x - a.x) / dist;
12116
+ const out = [];
12117
+ for (let i = 0;i <= samples; i++) {
12118
+ const t = i / samples;
12119
+ const p = e(t);
12120
+ const lift = Math.sin(Math.PI * p) * bow;
12121
+ out.push({ t, x: a.x + (b.x - a.x) * p + nx * lift, y: a.y + (b.y - a.y) * p + ny * lift });
12122
+ }
12123
+ return out;
12124
+ }
12125
+ function columns(from, to) {
12126
+ const a = [...from];
12127
+ const b = [...to];
12128
+ const n = Math.max(a.length, b.length);
12129
+ return Array.from({ length: n }, (_, i) => ({
12130
+ from: a[a.length - n + i] ?? "",
12131
+ to: b[b.length - n + i] ?? ""
12132
+ }));
12133
+ }
12134
+ function caps(combo) {
12135
+ const GLYPHS = {
12136
+ cmd: "\u2318",
12137
+ command: "\u2318",
12138
+ meta: "\u2318",
12139
+ shift: "\u21E7",
12140
+ opt: "\u2325",
12141
+ option: "\u2325",
12142
+ alt: "\u2325",
12143
+ ctrl: "\u2303",
12144
+ control: "\u2303",
12145
+ enter: "\u21A9",
12146
+ return: "\u21A9",
12147
+ tab: "\u21E5",
12148
+ esc: "esc",
12149
+ escape: "esc",
12150
+ space: "space",
12151
+ backspace: "\u232B",
12152
+ delete: "\u232B",
12153
+ up: "\u2191",
12154
+ down: "\u2193",
12155
+ left: "\u2190",
12156
+ right: "\u2192"
12157
+ };
12158
+ return combo.split("+").filter(Boolean).map((k) => GLYPHS[k.toLowerCase()] ?? (k.length === 1 ? k.toUpperCase() : k));
12159
+ }
12160
+ function frames(initial, segs, total) {
12161
+ const out = [{ offset: 0, value: initial, easing: "linear" }];
12162
+ const at = (t) => Math.min(1, Math.max(out[out.length - 1].offset, t / total));
12163
+ const push = (offset, value, easing) => {
12164
+ const last = out[out.length - 1];
12165
+ if (last.offset === offset && last.value === value) {
12166
+ last.easing = easing;
12167
+ return;
12168
+ }
12169
+ out.push({ offset, value, easing });
12170
+ };
12171
+ let last = initial;
12172
+ for (const s of segs) {
12173
+ const o0 = at(s.t0);
12174
+ if (s.from !== last)
12175
+ push(o0, last, "linear");
12176
+ push(o0, s.from, s.ease);
12177
+ push(at(s.t1), s.to, "linear");
12178
+ last = s.to;
12179
+ }
12180
+ if (out[out.length - 1].offset < 1)
12181
+ push(1, last, "linear");
12182
+ return out;
12183
+ }
12184
+ return { CURVES, curve, ms, easer, words, parse, random, cadence, arc, columns, caps, frames };
12185
+ }
12186
+ function actRuntime(core) {
12187
+ const w = window;
12188
+ if (w.__ponzuAct)
12189
+ return;
12190
+ const STATE_BOOLEANS = "open, hidden, disabled, checked, selected or inert";
12191
+ const STATE_ATTR = /^(\.[A-Za-z_][\w-]*|data-(?!id$|artboard$)[\w-]+|aria-[\w-]+|open|hidden|disabled|checked|selected|inert)$/;
12192
+ const ID = "ponzu-act";
12193
+ const handles = new WeakMap;
12194
+ const rewrittenRules = new WeakSet;
12195
+ let order = 0;
12196
+ const SVG = (body, size, box = "0 0 32 32") => `<svg width="${size}" height="${size}" viewBox="${box}" fill="none" xmlns="http://www.w3.org/2000/svg">${body}</svg>`;
12197
+ const RESIZE_TIP = "M0-8.4 2.55-3.65H-2.55ZM0 8.4 2.55 3.65H-2.55Z";
12198
+ const resize = (turn) => SVG(`<g transform="rotate(${turn})" stroke-linejoin="round"><path d="${RESIZE_TIP}" fill="#fff" stroke="#fff" stroke-width="3.2"/><path d="${RESIZE_TIP}" fill="#000" stroke="#000" stroke-width="1.2"/></g>`, 21, "-14 -14 28 28");
12199
+ const GLYPHS = {
12200
+ arrow: {
12201
+ svg: SVG('<g transform="translate(10 7)"><path d="m6.148 18.473 1.863-1.003 1.615-.839-2.568-4.816h4.332l-11.379-11.408v16.015l3.316-3.221z" fill="#fff"/><path d="m6.431 17 1.765-.941-2.775-5.202h3.604l-8.025-8.043v11.188l2.53-2.442z" fill="#000"/></g>', 24),
12202
+ hot: { x: 7.5, y: 5.25 }
12203
+ },
12204
+ hand: {
12205
+ svg: SVG('<path d="M10.6 6a1.7 1.7 0 0 1 3.4 0v6.6a1.3 1.3 0 0 1 2.6 0v.7a1.3 1.3 0 0 1 2.6 0v.7a1.3 1.3 0 0 1 2.6 0V19c0 3.1-2 5.6-5 5.6h-2.6c-2 0-3.3-.9-4.4-2.4l-3.1-4.1c-.6-.9-.4-2 .5-2.5.8-.4 1.7-.2 2.3.5l1.1 1.4V6Z" fill="#fff" stroke="#000" stroke-width="1.1" stroke-linejoin="round"/><path d="M14 12.6v3.6M16.6 13.3v3M19.2 14v2.6" stroke="#000" stroke-width="1" stroke-linecap="round"/>', 26),
12206
+ hot: { x: 9.75, y: 3.25 }
12207
+ },
12208
+ ibeam: {
12209
+ svg: `<svg width="10" height="16" viewBox="0 0 10 16" fill="none" overflow="visible" xmlns="http://www.w3.org/2000/svg"><path d="M3 1H7M3 15H7M5 1V15" stroke="#fff" stroke-width="2.6" stroke-linecap="round"/><path d="M3 1H7M3 15H7M5 1V15" stroke="#000" stroke-width="1" stroke-linecap="round"/></svg>`,
12210
+ hot: { x: 5, y: 8 }
12211
+ },
12212
+ crosshair: {
12213
+ svg: `<svg width="17" height="17" viewBox="0 0 17 17" fill="none" overflow="visible" xmlns="http://www.w3.org/2000/svg"><path d="M8.5 0V17M0 8.5H17" stroke="#fff" stroke-width="2.6"/><path d="M8.5 0V17M0 8.5H17" stroke="#000" stroke-width="1"/></svg>`,
12214
+ hot: { x: 8.5, y: 8.5 }
12215
+ },
12216
+ open: {
12217
+ svg: SVG('<path d="M11 15.5V8.4a1.4 1.4 0 0 1 2.8 0v5.4V6.9a1.4 1.4 0 0 1 2.8 0v6.9V7.6a1.4 1.4 0 0 1 2.8 0v6.6V9.9a1.4 1.4 0 0 1 2.8 0v8.4c0 3.6-2.4 6.2-5.8 6.2h-1.7c-2.1 0-3.5-.8-4.7-2.4l-3.4-4.5c-.6-.8-.5-1.9.3-2.4.8-.5 1.8-.3 2.4.4l2 2.3" fill="#fff" stroke="#000" stroke-width="1.1" stroke-linejoin="round" stroke-linecap="round"/>', 26),
12218
+ hot: { x: 11.7, y: 10.4 }
12219
+ },
12220
+ grab: {
12221
+ svg: SVG('<path d="M11.2 13.3c0-1 .7-1.6 1.5-1.6s1.4.6 1.4 1.4v-.6c0-.9.6-1.5 1.4-1.5s1.4.6 1.4 1.5v.4c0-.9.6-1.5 1.4-1.5s1.4.6 1.4 1.5v.6c0-.8.6-1.4 1.4-1.4s1.3.6 1.3 1.4v4.6c0 3.3-2.3 5.8-5.6 5.8h-1.9c-2 0-3.3-.8-4.4-2.3l-1.6-2.3c-.5-.8-.4-1.8.4-2.3.7-.4 1.6-.3 2.1.4l.5.7Z" fill="#fff" stroke="#000" stroke-width="1.1" stroke-linejoin="round"/><path d="M14.1 13.2v2.2M16.9 13v2.4M19.7 13.2v2.2" stroke="#000" stroke-width="1" stroke-linecap="round"/>', 30),
12222
+ hot: { x: 15, y: 15 }
12223
+ },
12224
+ "resize-ns": { svg: resize(0), hot: { x: 10.5, y: 10.5 } },
12225
+ "resize-ew": { svg: resize(90), hot: { x: 10.5, y: 10.5 } },
12226
+ "resize-nwse": { svg: resize(-45), hot: { x: 10.5, y: 10.5 } },
12227
+ "resize-nesw": { svg: resize(45), hot: { x: 10.5, y: 10.5 } },
12228
+ solid: {
12229
+ svg: `<svg width="22" height="22" viewBox="0 0 22 22" xmlns="http://www.w3.org/2000/svg"><path d="M4 3 18.5 9.6 11.8 11.8 9.6 18.5Z" fill="#111" stroke="#fff" stroke-width="1.6" stroke-linejoin="round" paint-order="stroke"/></svg>`,
12230
+ hot: { x: 4, y: 3 }
12231
+ }
12232
+ };
12233
+ const LAYER_CSS = `
12234
+ [data-act-layer]{position:absolute;inset:0;pointer-events:none;z-index:2147483000;overflow:visible;color-scheme:light}
12235
+ [data-act-cursor]{position:absolute;left:0;top:0;width:0;height:0;--act-size:1;transition:opacity .25s ease}
12236
+ [data-act-cursor][data-act-off]{opacity:0}
12237
+ [data-act-dip]{position:absolute;left:0;top:0;transform-origin:0 0;scale:var(--act-size);transition:transform .26s cubic-bezier(.22,1,.36,1)}
12238
+ [data-act-cursor][data-act-pressed] [data-act-dip]{transform:scale(.9);transition:transform .08s ease-out}
12239
+ [data-act-glyph]{position:absolute;display:block;opacity:0;scale:.5;filter:drop-shadow(0 1px 1.5px rgba(0,0,0,.28));transition:opacity .16s ease,scale .2s cubic-bezier(.22,1,.36,1)}
12240
+ [data-act-glyph] svg{display:block}
12241
+ ${Object.keys(GLYPHS).filter((k) => k !== "solid").map((k) => `[data-act-cursor][data-act-style=mac][data-act-kind=${k}] [data-act-glyph=${k}]{opacity:1;scale:1}`).join(`
12242
+ `)}
12243
+ [data-act-cursor][data-act-style=arrow]:not([data-act-kind=ibeam]) [data-act-glyph=solid]{opacity:1;scale:1}
12244
+ [data-act-cursor][data-act-style=arrow][data-act-kind=ibeam] [data-act-glyph=ibeam]{opacity:1;scale:1}
12245
+ [data-act-cursor][data-act-kind=grab] [data-act-glyph=open],[data-act-cursor][data-act-kind=open] [data-act-glyph=grab]{transition:opacity .08s linear}
12246
+ [data-act-dot]{position:absolute;left:-17px;top:-17px;width:34px;height:34px;border-radius:50%;background:rgba(118,118,128,.16);box-shadow:inset 0 0 0 1px rgba(255,255,255,.35),0 2px 10px rgba(0,0,0,.1);opacity:0;scale:.7;transition:opacity .4s ease,scale .45s cubic-bezier(.22,1,.36,1),background-color .1s ease}
12247
+ [data-act-cursor][data-act-style=touch][data-act-touching] [data-act-dot]{opacity:1;scale:1;transition:opacity .14s ease,scale .16s cubic-bezier(.22,1,.36,1)}
12248
+ [data-act-cursor][data-act-style=touch][data-act-pressed] [data-act-dot]{background-color:rgba(118,118,128,.26);scale:.84;transition:background-color .08s ease,scale .1s ease-out}
12249
+ [data-act-ripple]{position:absolute;left:-14px;top:-14px;width:28px;height:28px;border-radius:50%;border:2px solid rgba(70,110,255,.55);opacity:0}
12250
+ [data-act-caret]{position:absolute;left:0;top:0;width:2px;border-radius:1px;opacity:0}
12251
+ [data-act-keys]{position:absolute;left:0;right:0;display:flex;justify-content:center;gap:6px;opacity:0}
12252
+ [data-act-keys][data-at=bottom]{bottom:22px}
12253
+ [data-act-keys][data-at=top]{top:22px}
12254
+ [data-act-cap]{min-width:34px;height:34px;padding:0 10px;border-radius:9px;background:#fff;color:#1d1d1f;font:500 15px/34px -apple-system,BlinkMacSystemFont,"Segoe UI",system-ui,sans-serif;text-align:center;box-shadow:0 0 0 .5px rgba(0,0,0,.14),0 1px 0 rgba(0,0,0,.1),0 6px 18px rgba(0,0,0,.14)}
12255
+ `;
12256
+ const camel = (p) => p.startsWith("--") ? p : p === "float" ? "cssFloat" : p === "offset" ? "cssOffset" : p.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
12257
+ const idOf = (el) => el?.closest("[data-id]")?.getAttribute("data-id") ?? "";
12258
+ const round = (n) => Math.round(n * 10) / 10;
12259
+ const px = (n) => `${round(n)}px`;
12260
+ function splitTop(s) {
12261
+ const out = [];
12262
+ let depth = 0;
12263
+ let cur = "";
12264
+ for (const c of s) {
12265
+ if (c === "(")
12266
+ depth++;
12267
+ else if (c === ")")
12268
+ depth--;
12269
+ if (c === "," && depth === 0) {
12270
+ out.push(cur.trim());
12271
+ cur = "";
12272
+ } else
12273
+ cur += c;
12274
+ }
12275
+ if (cur.trim())
12276
+ out.push(cur.trim());
12277
+ return out;
12278
+ }
12279
+ function rulesOf(scope) {
12280
+ const out = [];
12281
+ const walk = (rules) => {
12282
+ for (const r of [...rules]) {
12283
+ if (r instanceof CSSStyleRule)
12284
+ out.push(r);
12285
+ if ("cssRules" in r && r.cssRules)
12286
+ walk(r.cssRules);
12287
+ }
12288
+ };
12289
+ for (const sheet of [...scope.styleSheets]) {
12290
+ try {
12291
+ walk(sheet.cssRules);
12292
+ } catch {}
12293
+ }
12294
+ return out;
12295
+ }
12296
+ function rewriteStates(scope) {
12297
+ const pattern = /:(hover|active|focus-visible|focus-within|focus)(?![\w-])/g;
12298
+ const alt = {
12299
+ hover: "[data-act-hover]",
12300
+ active: "[data-act-pressed]",
12301
+ focus: "[data-act-focus]",
12302
+ "focus-visible": "[data-act-focus]",
12303
+ "focus-within": "[data-act-focus],:has([data-act-focus])"
12304
+ };
12305
+ for (const rule of rulesOf(scope)) {
12306
+ if (rewrittenRules.has(rule))
12307
+ continue;
12308
+ rewrittenRules.add(rule);
12309
+ if (!pattern.test(rule.selectorText))
12310
+ continue;
12311
+ pattern.lastIndex = 0;
12312
+ rule.selectorText = rule.selectorText.replace(pattern, (_, s) => `:is(:${s},${alt[s]})`);
12313
+ pattern.lastIndex = 0;
12314
+ }
12315
+ }
12316
+ function kindOf(el, style) {
12317
+ if (!el)
12318
+ return "arrow";
12319
+ const named = el.closest("[data-cursor]")?.getAttribute("data-cursor");
12320
+ const css = named ?? getComputedStyle(el).cursor;
12321
+ const map = {
12322
+ pointer: "hand",
12323
+ hand: "hand",
12324
+ text: "ibeam",
12325
+ "vertical-text": "ibeam",
12326
+ ibeam: "ibeam",
12327
+ grab: "open",
12328
+ open: "open",
12329
+ grabbing: "grab",
12330
+ move: "open",
12331
+ crosshair: "crosshair",
12332
+ "ns-resize": "resize-ns",
12333
+ "row-resize": "resize-ns",
12334
+ "n-resize": "resize-ns",
12335
+ "s-resize": "resize-ns",
12336
+ "ew-resize": "resize-ew",
12337
+ "col-resize": "resize-ew",
12338
+ "e-resize": "resize-ew",
12339
+ "w-resize": "resize-ew",
12340
+ "nwse-resize": "resize-nwse",
12341
+ "nesw-resize": "resize-nesw"
12342
+ };
12343
+ const kind = map[css] ?? (GLYPHS[css] ? css : "arrow");
12344
+ return style === "arrow" && kind !== "ibeam" ? "arrow" : kind;
12345
+ }
12346
+ function find(section, target) {
12347
+ let sel = target;
12348
+ if (target.startsWith("@"))
12349
+ sel = `[data-name="${CSS.escape(target.slice(1))}"]`;
12350
+ try {
12351
+ const all = [...section.querySelectorAll(sel)];
12352
+ return section.matches(sel) ? [section, ...all] : all;
12353
+ } catch {
12354
+ return [];
12355
+ }
12356
+ }
12357
+ function mount(section) {
12358
+ handles.get(section)?.cancel();
12359
+ handles.delete(section);
12360
+ const script = section.querySelector('script[type="ponzu/act"]');
12361
+ if (!script)
12362
+ return null;
12363
+ let current = compile(section, script.textContent ?? "");
12364
+ const handle = {
12365
+ get animations() {
12366
+ return current.animations;
12367
+ },
12368
+ get summary() {
12369
+ return current.summary;
12370
+ },
12371
+ get issues() {
12372
+ return current.issues;
12373
+ },
12374
+ cancel() {
12375
+ for (const a of current.animations)
12376
+ a.cancel();
12377
+ current.animations = [];
12378
+ if (handles.get(section) === handle)
12379
+ handles.delete(section);
12380
+ },
12381
+ rebuild() {
12382
+ const was = current.animations[0];
12383
+ const time = was ? Number(was.currentTime ?? 0) : 0;
12384
+ const paused = was ? was.playState === "paused" : false;
12385
+ const rate = was ? was.playbackRate : 1;
12386
+ for (const a of current.animations)
12387
+ a.cancel();
12388
+ current = compile(section, script.textContent ?? "");
12389
+ for (const a of current.animations) {
12390
+ a.currentTime = time;
12391
+ a.playbackRate = rate;
12392
+ if (paused)
12393
+ a.pause();
12394
+ }
12395
+ }
12396
+ };
12397
+ handles.set(section, handle);
12398
+ return handle;
12399
+ }
12400
+ function compile(section, text) {
12401
+ const script = core.parse(text);
12402
+ const issues = [];
12403
+ const scriptId = idOf(section.querySelector('script[type="ponzu/act"]'));
12404
+ const issue = (line, message) => issues.push({ id: scriptId, kind: "act", message: `line ${line}: ${message}` });
12405
+ for (const i of script.issues)
12406
+ issue(i.line, i.message);
12407
+ const scope = section.getRootNode();
12408
+ rewriteStates(scope);
12409
+ const bases = new Map;
12410
+ const memo = new Map;
12411
+ const first = schedule(section, script, null, bases, memo, () => {});
12412
+ const draft = build(finish(section, scope, first), first, true);
12413
+ const plan = schedule(section, script, draft, bases, memo, issue);
12414
+ for (const a of draft)
12415
+ a.cancel();
12416
+ const animations = build(finish(section, scope, plan), plan, false);
12417
+ return {
12418
+ animations,
12419
+ issues,
12420
+ summary: {
12421
+ duration: plan.total,
12422
+ loop: plan.loop,
12423
+ poster: plan.poster,
12424
+ beats: plan.beats,
12425
+ animations: animations.length
12426
+ }
12427
+ };
12428
+ }
12429
+ function layer(section) {
12430
+ let el = section.querySelector(":scope > [data-act-layer]");
12431
+ if (el)
12432
+ return el;
12433
+ el = document.createElement("div");
12434
+ el.setAttribute("data-act-layer", "");
12435
+ el.setAttribute("aria-hidden", "true");
12436
+ const style = document.createElement("style");
12437
+ style.textContent = LAYER_CSS;
12438
+ el.appendChild(style);
12439
+ section.appendChild(el);
12440
+ return el;
12441
+ }
12442
+ function cursorEl(section) {
12443
+ const host = layer(section);
12444
+ let el = host.querySelector("[data-act-cursor]");
12445
+ if (el)
12446
+ return el;
12447
+ el = document.createElement("div");
12448
+ el.setAttribute("data-act-cursor", "");
12449
+ el.setAttribute("data-act-style", "mac");
12450
+ el.setAttribute("data-act-kind", "arrow");
12451
+ const dip = document.createElement("div");
12452
+ dip.setAttribute("data-act-dip", "");
12453
+ for (const [name, g] of Object.entries(GLYPHS)) {
12454
+ const span = document.createElement("span");
12455
+ span.setAttribute("data-act-glyph", name);
12456
+ span.style.left = `${-g.hot.x}px`;
12457
+ span.style.top = `${-g.hot.y}px`;
12458
+ span.style.transformOrigin = `${g.hot.x}px ${g.hot.y}px`;
12459
+ span.innerHTML = g.svg;
12460
+ dip.appendChild(span);
12461
+ }
12462
+ const dot = document.createElement("span");
12463
+ dot.setAttribute("data-act-dot", "");
12464
+ dip.appendChild(dot);
12465
+ el.appendChild(dip);
12466
+ host.appendChild(el);
12467
+ return el;
12468
+ }
12469
+ function helper(section, key, make) {
12470
+ const host = layer(section);
12471
+ const found = [...host.children].find((c) => c.getAttribute("data-act-key") === key);
12472
+ if (found)
12473
+ return found;
12474
+ const el = make();
12475
+ el.setAttribute("data-act-key", key);
12476
+ host.appendChild(el);
12477
+ return el;
12478
+ }
12479
+ function schedule(section, script, draft, bases, memo, issue) {
12480
+ const tracks = new Map;
12481
+ const states = [];
12482
+ const beats = [];
12483
+ const k = section.getBoundingClientRect().width / (section.offsetWidth || 1) || 1;
12484
+ const W = section.clientWidth;
12485
+ const H = section.clientHeight;
12486
+ const CURVE_INOUT = core.CURVES.inout;
12487
+ let presses = 0;
12488
+ const at = (t) => {
12489
+ if (draft)
12490
+ for (const a of draft)
12491
+ a.currentTime = t;
12492
+ };
12493
+ const box = (el, t) => {
12494
+ at(t);
12495
+ const r = el.getBoundingClientRect();
12496
+ const s = section.getBoundingClientRect();
12497
+ return {
12498
+ x: (r.left - s.left) / k - section.clientLeft,
12499
+ y: (r.top - s.top) / k - section.clientTop,
12500
+ width: r.width / k,
12501
+ height: r.height / k
12502
+ };
12503
+ };
12504
+ const inside = (p, b) => !!b && p.x >= b.x && p.x <= b.x + b.width && p.y >= b.y && p.y <= b.y + b.height;
12505
+ const key = (el, pseudo, prop) => {
12506
+ let id = el.__actKey;
12507
+ if (id === undefined) {
12508
+ id = ++order;
12509
+ el.__actKey = id;
12510
+ }
12511
+ return `${id}|${pseudo}|${prop}`;
12512
+ };
12513
+ const base = (el, prop, pseudo = "") => {
12514
+ const k_ = key(el, pseudo, prop);
12515
+ let v = bases.get(k_);
12516
+ if (v === undefined) {
12517
+ v = getComputedStyle(el, pseudo || null).getPropertyValue(prop);
12518
+ bases.set(k_, v);
12519
+ }
12520
+ return v;
12521
+ };
12522
+ const naturalHeight = (el) => {
12523
+ const k_ = key(el, "", "act:height");
12524
+ let v = bases.get(k_);
12525
+ if (v === undefined) {
12526
+ v = String(draft ? box(el, 0).height : el.getBoundingClientRect().height / k);
12527
+ bases.set(k_, v);
12528
+ }
12529
+ return Number(v);
12530
+ };
12531
+ const now_ = (el, prop, t) => {
12532
+ at(t);
12533
+ return getComputedStyle(el).getPropertyValue(prop);
12534
+ };
12535
+ const change = (el, prop, t0, t1, to, ease = "linear", from, pseudo = "") => {
12536
+ const k_ = key(el, pseudo, prop);
12537
+ let tr = tracks.get(k_);
12538
+ if (!tr) {
12539
+ tr = { el, pseudo, prop, initial: null, segs: [] };
12540
+ tracks.set(k_, tr);
12541
+ }
12542
+ tr.segs.push({ t0, t1: Math.max(t0, t1), to, from, ease, order: ++order });
12543
+ };
12544
+ const state = (t, el, attr, value) => states.push({ t, el, attr, value, order: ++order });
12545
+ const translateOf = (el, t) => {
12546
+ const v = now_(el, "translate", t).trim();
12547
+ if (!v || v === "none")
12548
+ return { x: 0, y: 0 };
12549
+ const [x, y] = v.split(/\s+/).map((s) => Number.parseFloat(s) || 0);
12550
+ return { x: x ?? 0, y: y ?? 0 };
12551
+ };
12552
+ let cursor = null;
12553
+ let style = "mac";
12554
+ let pos = null;
12555
+ let kind = "arrow";
12556
+ let hovered = [];
12557
+ let hoverTarget = null;
12558
+ let focused = null;
12559
+ let ripple = false;
12560
+ let caret = null;
12561
+ let keys = null;
12562
+ let rested = null;
12563
+ let idle = false;
12564
+ const IDLE_MS = 4000;
12565
+ const wake = (t) => {
12566
+ if (rested !== null && !idle && t - rested > IDLE_MS && cursor) {
12567
+ state(rested + IDLE_MS, cursor, "data-act-off", "");
12568
+ idle = true;
12569
+ }
12570
+ if (idle && cursor)
12571
+ state(t, cursor, "data-act-off", null);
12572
+ idle = false;
12573
+ };
12574
+ const getCursor = () => {
12575
+ if (!cursor) {
12576
+ cursor = cursorEl(section);
12577
+ state(0, cursor, "data-act-style", style);
12578
+ state(0, cursor, "data-act-kind", "arrow");
12579
+ }
12580
+ return cursor;
12581
+ };
12582
+ const chain = (el) => {
12583
+ const out = [];
12584
+ for (let n = el;n; n = n === section ? null : n.parentElement)
12585
+ out.push(n);
12586
+ return out;
12587
+ };
12588
+ const place = (p, t) => {
12589
+ const v = `${px(p.x)} ${px(p.y)}`;
12590
+ change(getCursor(), "translate", t, t, v, "linear", v);
12591
+ pos = p;
12592
+ };
12593
+ const setKind = (next, t) => {
12594
+ if (next === kind)
12595
+ return;
12596
+ kind = next;
12597
+ state(t, getCursor(), "data-act-kind", next);
12598
+ };
12599
+ const hover = (el, t) => {
12600
+ const next = chain(el);
12601
+ for (const n of hovered)
12602
+ if (!next.includes(n))
12603
+ state(t, n, "data-act-hover", null);
12604
+ for (const n of next)
12605
+ if (!hovered.includes(n))
12606
+ state(t, n, "data-act-hover", "");
12607
+ hovered = next;
12608
+ hoverTarget = el;
12609
+ };
12610
+ const focus = (el, t) => {
12611
+ if (focused === el)
12612
+ return;
12613
+ if (focused)
12614
+ state(t, focused, "data-act-focus", null);
12615
+ if (el)
12616
+ state(t, el, "data-act-focus", "");
12617
+ focused = el;
12618
+ closeCaret(t);
12619
+ };
12620
+ const closeCaret = (t) => {
12621
+ if (!caret)
12622
+ return;
12623
+ const c = caret;
12624
+ caret = null;
12625
+ for (let s = c.from + 530;s < t; s += 1060) {
12626
+ change(c.el, "opacity", s, s, "0");
12627
+ if (s + 530 < t)
12628
+ change(c.el, "opacity", s + 530, s + 530, "1");
12629
+ }
12630
+ change(c.el, "opacity", t, t, "0");
12631
+ };
12632
+ const point = (target, opts, t, line) => {
12633
+ if (!target)
12634
+ return null;
12635
+ const xy = /^(-?\d*\.?\d+)(%?),(-?\d*\.?\d+)(%?)$/.exec(target);
12636
+ if (xy) {
12637
+ const x = Number(xy[1]) * (xy[2] ? W / 100 : 1);
12638
+ const y = Number(xy[3]) * (xy[4] ? H / 100 : 1);
12639
+ return { p: { x, y }, el: null };
12640
+ }
12641
+ const el = find(section, target)[0];
12642
+ if (!el) {
12643
+ issue(line, `nothing matches ${target}`);
12644
+ return null;
12645
+ }
12646
+ const b = box(el, t);
12647
+ if (!b.width && !b.height)
12648
+ issue(line, `${target} isn't on screen at ${Math.round(t)}ms`);
12649
+ if (opts.at) {
12650
+ const [fx, fy] = opts.at.split(",").map(Number);
12651
+ return { p: { x: b.x + b.width * (fx ?? 0.5), y: b.y + b.height * (fy ?? 0.5) }, el };
12652
+ }
12653
+ if (b.width < 48 || b.height > 72)
12654
+ return { p: { x: b.x + b.width / 2, y: b.y + b.height / 2 }, el };
12655
+ const words = document.createRange();
12656
+ words.selectNodeContents(el);
12657
+ const w_ = words.getBoundingClientRect();
12658
+ const s = section.getBoundingClientRect();
12659
+ const right = (w_.right - s.left) / k - section.clientLeft;
12660
+ const mid = (w_.top + w_.height / 2 - s.top) / k - section.clientTop;
12661
+ if (w_.width / k > b.width * 0.5 && right + 3 < b.x + b.width - 4)
12662
+ return { p: { x: right + 3, y: mid + 2 }, el };
12663
+ return { p: { x: b.x + b.width * 0.78, y: b.y + b.height * 0.62 }, el };
12664
+ };
12665
+ const travel = (to, t, opts, drag) => {
12666
+ getCursor();
12667
+ const toBox = to.el ? box(to.el, t) : null;
12668
+ let from = pos;
12669
+ let ease = core.curve(opts.ease, CURVE_INOUT);
12670
+ let dur;
12671
+ let bow;
12672
+ if (!from) {
12673
+ const out = 40;
12674
+ const gaps = [to.p.x, W - to.p.x, to.p.y, H - to.p.y];
12675
+ const side = gaps.indexOf(Math.min(...gaps));
12676
+ from = side === 0 ? { x: -out, y: to.p.y + H * 0.12 } : side === 1 ? { x: W + out, y: to.p.y + H * 0.12 } : side === 2 ? { x: to.p.x - W * 0.06, y: -out } : { x: to.p.x + W * 0.06, y: H + out };
12677
+ place(from, t);
12678
+ ease = core.curve(opts.ease, core.CURVES.enter);
12679
+ dur = core.ms(opts.dur) ?? 700;
12680
+ bow = 0;
12681
+ } else {
12682
+ const dist = Math.hypot(to.p.x - from.x, to.p.y - from.y);
12683
+ if (dist < 0.5) {
12684
+ if (!drag) {
12685
+ hover(to.el ?? hoverTarget, t);
12686
+ if (to.el)
12687
+ setKind(kindOf(to.el, style), t);
12688
+ }
12689
+ return t;
12690
+ }
12691
+ dur = core.ms(opts.dur) ?? (drag ? Math.min(900, Math.max(450, 360 + dist * 1.1)) : Math.min(650, Math.max(300, 260 + dist * 0.9)));
12692
+ bow = Math.min(dist * (drag ? 0.06 : 0.08), drag ? 18 : 24);
12693
+ }
12694
+ const fromBox = hoverTarget ? box(hoverTarget, t) : null;
12695
+ const samples = Math.max(8, Math.round(dur / 28));
12696
+ const path = core.arc(from, to.p, ease, bow, samples);
12697
+ const cur = getCursor();
12698
+ let entered = false;
12699
+ let left = !fromBox;
12700
+ if (!drag && !left && toBox && hoverTarget && to.el && hoverTarget.contains(to.el))
12701
+ left = true;
12702
+ for (const s of path) {
12703
+ const ts = t + s.t * dur;
12704
+ if (s.t > 0)
12705
+ change(cur, "translate", ts - dur / samples, ts, `${px(s.x)} ${px(s.y)}`);
12706
+ if (drag?.carry) {
12707
+ change(drag.carry, "translate", ts - (s.t > 0 ? dur / samples : 0), ts, `${px(drag.offset.x + s.x - drag.grip.x)} ${px(drag.offset.y + s.y - drag.grip.y)}`);
12708
+ }
12709
+ if (drag)
12710
+ continue;
12711
+ if (!left && !inside(s, fromBox)) {
12712
+ left = true;
12713
+ hover(to.el && inside(s, toBox) ? to.el : null, ts);
12714
+ if (kind !== "arrow" && !inside(s, toBox))
12715
+ setKind("arrow", ts);
12716
+ }
12717
+ if (!entered && to.el && inside(s, toBox)) {
12718
+ entered = true;
12719
+ hover(to.el, ts);
12720
+ setKind(kindOf(to.el, style), ts);
12721
+ }
12722
+ }
12723
+ const end = t + dur;
12724
+ if (!drag) {
12725
+ if (!entered) {
12726
+ hover(to.el ?? null, end);
12727
+ setKind(to.el ? kindOf(to.el, style) : "arrow", end);
12728
+ }
12729
+ }
12730
+ pos = to.p;
12731
+ return end;
12732
+ };
12733
+ const press = (t, hold, el, right = false) => {
12734
+ const cur = getCursor();
12735
+ const touch = style === "touch";
12736
+ if (touch)
12737
+ state(t - 140, cur, "data-act-touching", "");
12738
+ state(t, cur, "data-act-pressed", "");
12739
+ const pressed = chain(el);
12740
+ for (const n of pressed)
12741
+ state(t, n, "data-act-pressed", right ? "right" : "");
12742
+ state(t + hold, cur, "data-act-pressed", null);
12743
+ for (const n of pressed)
12744
+ state(t + hold, n, "data-act-pressed", null);
12745
+ if (touch)
12746
+ state(t + hold + 60, cur, "data-act-touching", null);
12747
+ if (ripple && pos) {
12748
+ const p = pos;
12749
+ const ring = helper(section, `ripple:${++presses}`, () => {
12750
+ const r = document.createElement("span");
12751
+ r.setAttribute("data-act-ripple", "");
12752
+ return r;
12753
+ });
12754
+ change(ring, "translate", t, t, `${px(p.x)} ${px(p.y)}`);
12755
+ change(ring, "opacity", t, t, "0.9");
12756
+ change(ring, "scale", t, t, "0.4");
12757
+ change(ring, "scale", t, t + 520, "1.7", core.CURVES.out);
12758
+ change(ring, "opacity", t + 80, t + 520, "0", "ease-out");
12759
+ }
12760
+ };
12761
+ const reveal = (el, byWord) => {
12762
+ const known = memo.get(el);
12763
+ if (known && known.byWord === byWord)
12764
+ return known;
12765
+ const out = measureText(el, byWord);
12766
+ memo.set(el, out);
12767
+ return out;
12768
+ };
12769
+ const measureText = (target, byWord) => {
12770
+ const el = textHost(target);
12771
+ const own = el.getBoundingClientRect();
12772
+ const steps = [];
12773
+ const walker = document.createTreeWalker(el, NodeFilter.SHOW_TEXT);
12774
+ const range = document.createRange();
12775
+ for (let n = walker.nextNode();n; n = walker.nextNode()) {
12776
+ const s = n.data;
12777
+ const parts = byWord ? s.match(/\S+\s*|\s+/g) ?? [] : [...s];
12778
+ let i = 0;
12779
+ for (const part of parts) {
12780
+ const start = i;
12781
+ i += part.length;
12782
+ if (!part.trim()) {
12783
+ if (steps.length)
12784
+ steps[steps.length - 1].text += part;
12785
+ continue;
12786
+ }
12787
+ const end = start + part.trimEnd().length;
12788
+ range.setStart(n, end - 1);
12789
+ range.setEnd(n, end);
12790
+ const r = [...range.getClientRects()].pop();
12791
+ if (!r)
12792
+ continue;
12793
+ steps.push({
12794
+ x: (r.right - own.left) / k,
12795
+ top: (r.top - own.top) / k,
12796
+ bottom: (r.bottom - own.top) / k,
12797
+ glyphTop: (r.top - own.top) / k,
12798
+ glyphBottom: (r.bottom - own.top) / k,
12799
+ text: part
12800
+ });
12801
+ }
12802
+ }
12803
+ const lines = [...new Set(steps.map((s) => Math.round(s.top)))].sort((a, b) => a - b);
12804
+ const bottoms = new Map;
12805
+ for (const s of steps) {
12806
+ const l = Math.round(s.top);
12807
+ bottoms.set(l, Math.max(bottoms.get(l) ?? s.bottom, s.bottom));
12808
+ }
12809
+ for (const s of steps) {
12810
+ const i = lines.indexOf(Math.round(s.top));
12811
+ const prev = lines[i - 1];
12812
+ const next = lines[i + 1];
12813
+ const bottom = bottoms.get(lines[i]);
12814
+ s.top = prev === undefined ? s.top - 12 : (bottoms.get(prev) + s.top) / 2;
12815
+ s.bottom = next === undefined ? bottom + 12 : (bottom + next) / 2;
12816
+ }
12817
+ return { host: el, steps, width: own.width / k, height: own.height / k, byWord };
12818
+ };
12819
+ const clipTo = (s, width) => {
12820
+ const P = 12;
12821
+ return `polygon(${-P}px ${-P}px, ${px(width + P)} ${-P}px, ${px(width + P)} ${px(s.top)}, ${px(s.x)} ${px(s.top)}, ${px(s.x)} ${px(s.bottom)}, ${-P}px ${px(s.bottom)})`;
12822
+ };
12823
+ const HIDDEN_CLIP = "polygon(0px 0px, 0px 0px, 0px 0px, 0px 0px, 0px 0px, 0px 0px)";
12824
+ const PRESETS = {
12825
+ fade: 240,
12826
+ rise: 420,
12827
+ drop: 380,
12828
+ pop: 320,
12829
+ grow: 420,
12830
+ blur: 380,
12831
+ "from-left": 420,
12832
+ "from-right": 420
12833
+ };
12834
+ const appear = (el, show, preset, t, dur, ease) => {
12835
+ const opacity = base(el, "opacity") || "1";
12836
+ const t1 = t + dur;
12837
+ const fade = (fadeDur) => {
12838
+ if (show)
12839
+ change(el, "opacity", t, t + fadeDur, opacity, ease, "0");
12840
+ else
12841
+ change(el, "opacity", t, t + fadeDur, "0", ease);
12842
+ };
12843
+ if (preset === "grow") {
12844
+ const h = naturalHeight(el);
12845
+ const parent = el.parentElement;
12846
+ const pcs = parent ? getComputedStyle(parent) : null;
12847
+ const gap = pcs && /flex|grid/.test(pcs.display) ? Number.parseFloat(pcs.rowGap) || 0 : 0;
12848
+ const lead = gap && el.previousElementSibling ? -gap : 0;
12849
+ const props = [
12850
+ ["height", "0px", px(h)],
12851
+ ["padding-top", "0px", base(el, "padding-top")],
12852
+ ["padding-bottom", "0px", base(el, "padding-bottom")],
12853
+ ["margin-top", px(lead), base(el, "margin-top")],
12854
+ ["margin-bottom", "0px", base(el, "margin-bottom")]
12855
+ ];
12856
+ const display = base(el, "display");
12857
+ if (show) {
12858
+ change(el, "display", t, t, display, "linear", "none");
12859
+ change(el, "overflow", t, t, "clip", "linear", base(el, "overflow"));
12860
+ for (const [p, hid, shown] of props)
12861
+ change(el, p, t, t1, shown, ease, hid);
12862
+ change(el, "overflow", t1, t1, base(el, "overflow"));
12863
+ change(el, "opacity", t + dur * 0.25, t1, opacity, ease, "0");
12864
+ } else {
12865
+ change(el, "overflow", t, t, "clip");
12866
+ change(el, "opacity", t, t + dur * 0.6, "0", ease);
12867
+ for (const [p, hid] of props)
12868
+ change(el, p, t, t1, hid, ease, p === "height" ? px(h) : undefined);
12869
+ change(el, "display", t1, t1, "none");
12870
+ }
12871
+ return;
12872
+ }
12873
+ const tr = translateOf(el, t);
12874
+ const shift = {
12875
+ rise: { x: 0, y: 10 },
12876
+ drop: { x: 0, y: -8 },
12877
+ "from-left": { x: -16, y: 0 },
12878
+ "from-right": { x: 16, y: 0 }
12879
+ };
12880
+ const d = shift[preset];
12881
+ if (d) {
12882
+ const hid = `${px(tr.x + d.x)} ${px(tr.y + d.y)}`;
12883
+ const here = `${px(tr.x)} ${px(tr.y)}`;
12884
+ if (show)
12885
+ change(el, "translate", t, t1, here, ease, hid);
12886
+ else
12887
+ change(el, "translate", t, t1, hid, ease);
12888
+ }
12889
+ if (preset === "pop") {
12890
+ const s = base(el, "scale");
12891
+ const shown = s && s !== "none" ? s : "1";
12892
+ if (show)
12893
+ change(el, "scale", t, t1, shown, ease, "0.94");
12894
+ else
12895
+ change(el, "scale", t, t1, "0.96", ease);
12896
+ }
12897
+ if (preset === "blur") {
12898
+ const f = base(el, "filter");
12899
+ const shown = f && f !== "none" ? f : "blur(0px)";
12900
+ if (show)
12901
+ change(el, "filter", t, t1, shown, ease, "blur(6px)");
12902
+ else
12903
+ change(el, "filter", t, t1, "blur(6px)", ease);
12904
+ }
12905
+ fade(preset === "fade" ? dur : Math.min(dur, 260));
12906
+ };
12907
+ let now = 0;
12908
+ let lastStart = 0;
12909
+ let poster = null;
12910
+ let reset = null;
12911
+ const POINTER = new Set(["move", "hover", "enter", "click", "tap", "drag", "swipe", "scroll"]);
12912
+ for (const line of script.lines) {
12913
+ const { verb, args, opts } = line;
12914
+ const start = (line.with ? lastStart : now) + (core.ms(opts.delay) ?? 0);
12915
+ let end = start;
12916
+ let anchor = start;
12917
+ if (POINTER.has(verb) && pos)
12918
+ wake(start);
12919
+ const ease = (fallback) => core.curve(opts.ease, fallback);
12920
+ const targets = (i = 0) => {
12921
+ const t = args[i];
12922
+ if (!t) {
12923
+ issue(line.line, `${verb} needs a target`);
12924
+ return [];
12925
+ }
12926
+ const els = find(section, t);
12927
+ if (!els.length)
12928
+ issue(line.line, `nothing matches ${t}`);
12929
+ return els;
12930
+ };
12931
+ switch (verb) {
12932
+ case "cursor": {
12933
+ const cur = getCursor();
12934
+ for (const a of args) {
12935
+ if (a === "mac" || a === "arrow" || a === "touch") {
12936
+ style = a;
12937
+ state(start, cur, "data-act-style", a);
12938
+ } else if (a === "hide")
12939
+ state(start, cur, "data-act-off", "");
12940
+ else if (a === "show")
12941
+ state(start, cur, "data-act-off", null);
12942
+ else if (a === "ripple")
12943
+ ripple = true;
12944
+ }
12945
+ if (opts.size)
12946
+ cur.style.setProperty("--act-size", opts.size);
12947
+ const i = args.indexOf("at");
12948
+ if (i >= 0) {
12949
+ const to = point(args[i + 1], opts, start, line.line);
12950
+ if (to) {
12951
+ place(to.p, start);
12952
+ hover(to.el, start);
12953
+ setKind(kindOf(to.el, style), start);
12954
+ }
12955
+ }
12956
+ break;
12957
+ }
12958
+ case "move":
12959
+ case "hover":
12960
+ case "enter": {
12961
+ const to = point(args[0], opts, start, line.line);
12962
+ if (!to)
12963
+ break;
12964
+ if (verb === "enter")
12965
+ pos = null;
12966
+ const guess = travelTime(to.p);
12967
+ const there = point(args[0], opts, start + guess, line.line) ?? to;
12968
+ end = travel(there, start, opts);
12969
+ break;
12970
+ }
12971
+ case "click":
12972
+ case "tap": {
12973
+ let t = start;
12974
+ let el = hoverTarget;
12975
+ if (args[0]) {
12976
+ const to = point(args[0], opts, start, line.line);
12977
+ if (to) {
12978
+ const there = point(args[0], opts, start + travelTime(to.p), line.line) ?? to;
12979
+ const arrived = travel(there, start, opts);
12980
+ t = arrived > start ? arrived + 120 : start;
12981
+ el = to.el ?? hoverTarget;
12982
+ }
12983
+ }
12984
+ if (focused && el && !chain(el).includes(focused))
12985
+ focus(null, t);
12986
+ anchor = t;
12987
+ const double = args.includes("double");
12988
+ const right = args.includes("right");
12989
+ press(t, double ? 80 : 100, el, right);
12990
+ end = t + (double ? 80 : 100);
12991
+ if (double) {
12992
+ press(end + 70, 80, el, right);
12993
+ end += 150;
12994
+ }
12995
+ break;
12996
+ }
12997
+ case "drag":
12998
+ case "swipe": {
12999
+ const toAt = args.indexOf("to");
13000
+ const fromT = toAt > 0 ? args[0] : undefined;
13001
+ const toT = toAt >= 0 ? args[toAt + 1] : args[0];
13002
+ let t = start;
13003
+ if (fromT) {
13004
+ const from = point(fromT, {}, start, line.line);
13005
+ if (from) {
13006
+ const arrived = travel(from, start, {});
13007
+ t = arrived > start ? arrived + 120 : start;
13008
+ }
13009
+ }
13010
+ const carrySel = opts.carry ?? (args.includes("carry") ? fromT : undefined);
13011
+ const carry = carrySel ? find(section, carrySel)[0] ?? null : null;
13012
+ if (carrySel && !carry)
13013
+ issue(line.line, `nothing matches ${carrySel}`);
13014
+ const to = point(toT, opts, t, line.line);
13015
+ if (!to || !pos)
13016
+ break;
13017
+ const grip = pos;
13018
+ anchor = t;
13019
+ const offset = carry ? translateOf(carry, t) : { x: 0, y: 0 };
13020
+ const before = kind;
13021
+ const closes = before !== "ibeam" && before !== "crosshair" && !before.startsWith("resize");
13022
+ const cur = getCursor();
13023
+ if (style === "touch")
13024
+ state(t - 140, cur, "data-act-touching", "");
13025
+ state(t, cur, "data-act-pressed", "");
13026
+ state(t + 90, cur, "data-act-pressed", null);
13027
+ if (closes)
13028
+ setKind("grab", t + 60);
13029
+ if (carry)
13030
+ state(t + 60, carry, "data-act-dragging", "");
13031
+ const pressed = chain(hoverTarget);
13032
+ for (const n of pressed)
13033
+ state(t, n, "data-act-pressed", "");
13034
+ const landed = travel(to, t + 110, opts, { carry, grip, offset });
13035
+ for (const n of pressed)
13036
+ state(landed, n, "data-act-pressed", null);
13037
+ if (carry)
13038
+ state(landed, carry, "data-act-dragging", null);
13039
+ if (style === "touch")
13040
+ state(landed + 60, cur, "data-act-touching", null);
13041
+ hover(to.el, landed);
13042
+ setKind(to.el ? kindOf(to.el, style) : closes ? "open" : before, landed);
13043
+ end = landed;
13044
+ break;
13045
+ }
13046
+ case "type":
13047
+ case "stream": {
13048
+ const el = targets()[0];
13049
+ if (!el)
13050
+ break;
13051
+ const word = verb === "stream";
13052
+ const { host, steps, width } = reveal(el, word);
13053
+ if (!steps.length) {
13054
+ issue(line.line, `${args[0]} has no text to ${verb}`);
13055
+ break;
13056
+ }
13057
+ const each = core.ms(opts.speed) ?? (word ? 45 : 38);
13058
+ const times = core.cadence(steps.map((s) => s.text), each, `${line.line}:${el.textContent}`).map((t) => t + (word ? 0 : each));
13059
+ if (opts.placeholder)
13060
+ for (const p of find(section, opts.placeholder)) {
13061
+ const at = start + times[0];
13062
+ change(p, "opacity", at, at, "0");
13063
+ }
13064
+ closeCaret(start);
13065
+ if (!word)
13066
+ focus(el, start);
13067
+ const t0 = start + times[0];
13068
+ change(host, "clip-path", start, start, HIDDEN_CLIP, "linear", HIDDEN_CLIP);
13069
+ change(host, "clip-path", t0, t0, clipTo(steps[0], width));
13070
+ for (let i = 1;i < steps.length; i++) {
13071
+ const ts = start + times[i];
13072
+ change(host, "clip-path", ts, ts, clipTo(steps[i], width));
13073
+ }
13074
+ const last = start + times[times.length - 1];
13075
+ change(host, "clip-path", last + each, last + each, "none");
13076
+ end = last + each;
13077
+ if (!word && !args.includes("nocaret")) {
13078
+ const color = getComputedStyle(el).color;
13079
+ const c = helper(section, `caret:${line.line}`, () => {
13080
+ const s = document.createElement("span");
13081
+ s.setAttribute("data-act-caret", "");
13082
+ return s;
13083
+ });
13084
+ c.style.background = color;
13085
+ const origin = box(host, start);
13086
+ const lineH = steps[0].glyphBottom - steps[0].glyphTop;
13087
+ c.style.height = px(lineH);
13088
+ change(c, "opacity", start, start, "1");
13089
+ change(c, "translate", start, start, `${px(origin.x)} ${px(origin.y + steps[0].glyphTop)}`);
13090
+ for (let i = 0;i < steps.length; i++) {
13091
+ const s = steps[i];
13092
+ const ts = start + times[i];
13093
+ change(c, "translate", ts, ts, `${px(origin.x + s.x + 1)} ${px(origin.y + s.glyphTop)}`);
13094
+ }
13095
+ caret = { el: c, from: end, color };
13096
+ }
13097
+ break;
13098
+ }
13099
+ case "key": {
13100
+ const combo = args[0];
13101
+ if (!combo) {
13102
+ issue(line.line, "key needs keys, like cmd+k");
13103
+ break;
13104
+ }
13105
+ const where = opts.at === "top" ? "top" : "bottom";
13106
+ const group = helper(section, `keys:${line.line}`, () => {
13107
+ const g = document.createElement("div");
13108
+ g.setAttribute("data-act-keys", "");
13109
+ for (const cap of core.caps(combo)) {
13110
+ const c = document.createElement("span");
13111
+ c.setAttribute("data-act-cap", "");
13112
+ c.textContent = cap;
13113
+ g.appendChild(c);
13114
+ }
13115
+ return g;
13116
+ });
13117
+ group.setAttribute("data-at", where);
13118
+ if (keys && keys.hide > start) {
13119
+ change(keys.el, "opacity", start, start + 120, "0", "ease-in");
13120
+ }
13121
+ change(group, "opacity", start, start + 180, "1", core.CURVES.out, "0");
13122
+ change(group, "translate", start, start + 180, "0px 0px", core.CURVES.out, "0px 6px");
13123
+ change(group, "scale", start + 180, start + 240, "0.94", "ease-out", "1");
13124
+ change(group, "scale", start + 320, start + 460, "1", core.CURVES.out);
13125
+ change(group, "opacity", start + 1100, start + 1300, "0", "ease-in");
13126
+ keys = { el: group, hide: start + 1100 };
13127
+ end = start + 320;
13128
+ break;
13129
+ }
13130
+ case "show":
13131
+ case "hide": {
13132
+ const els = targets();
13133
+ const preset = args.slice(1).find((a) => (a in PRESETS)) ?? "fade";
13134
+ const dur = core.ms(opts.dur) ?? PRESETS[preset];
13135
+ const gap = core.ms(opts.stagger) ?? (els.length > 1 ? 60 : 0);
13136
+ const curveFor = verb === "show" ? core.CURVES.out : preset === "grow" ? CURVE_INOUT : "ease-in";
13137
+ els.forEach((el, i) => {
13138
+ appear(el, verb === "show", preset, start + i * gap, dur, ease(curveFor));
13139
+ });
13140
+ end = start + Math.max(0, els.length - 1) * gap + dur;
13141
+ break;
13142
+ }
13143
+ case "set":
13144
+ case "unset": {
13145
+ const els = targets();
13146
+ const names = args.slice(1);
13147
+ const asked = names.map((n) => [n, ""]);
13148
+ for (const [kk, v] of Object.entries(opts))
13149
+ if (!["dur", "delay", "ease", "stagger"].includes(kk))
13150
+ asked.push([kk, v]);
13151
+ const values = asked.filter(([name]) => {
13152
+ if (STATE_ATTR.test(name))
13153
+ return true;
13154
+ issue(line.line, `${name} isn't a state; set takes a .class, data-*, aria-* or ${STATE_BOOLEANS}`);
13155
+ return false;
13156
+ });
13157
+ if (!asked.length)
13158
+ issue(line.line, `${verb} needs an attribute or .class`);
13159
+ const gap = core.ms(opts.stagger) ?? 0;
13160
+ els.forEach((el, i) => {
13161
+ for (const [name, v] of values)
13162
+ state(start + i * gap, el, name, verb === "set" ? v ?? "" : null);
13163
+ });
13164
+ end = start + Math.max(0, els.length - 1) * gap + (core.ms(opts.dur) ?? 0);
13165
+ break;
13166
+ }
13167
+ case "focus": {
13168
+ const el = targets()[0];
13169
+ if (el)
13170
+ focus(el, start);
13171
+ break;
13172
+ }
13173
+ case "blur":
13174
+ focus(null, start);
13175
+ break;
13176
+ case "count": {
13177
+ const els = targets();
13178
+ const fromAt = args.indexOf("from");
13179
+ const old = fromAt >= 0 ? args[fromAt + 1] : undefined;
13180
+ if (old === undefined) {
13181
+ issue(line.line, "count needs from <old value>, like count .total from $1,180");
13182
+ break;
13183
+ }
13184
+ const dur = core.ms(opts.dur) ?? 600;
13185
+ const gap = core.ms(opts.stagger) ?? 50;
13186
+ let last = start;
13187
+ for (const el of els) {
13188
+ const rolls = rollColumns(el, old);
13189
+ let n = 0;
13190
+ for (let i = rolls.length - 1;i >= 0; i--) {
13191
+ const r = rolls[i];
13192
+ if (!r)
13193
+ continue;
13194
+ const t0 = start + n * gap;
13195
+ if (Math.abs(r.from - r.to) > 0.5)
13196
+ change(r.col, "width", t0, t0 + dur, px(r.to), ease(core.CURVES.house), px(r.from));
13197
+ change(r.strip, "translate", t0, t0 + dur, `0px ${px(-r.h)}`, ease(core.CURVES.house), "0px 0px");
13198
+ last = Math.max(last, t0 + dur);
13199
+ n++;
13200
+ }
13201
+ }
13202
+ end = last;
13203
+ break;
13204
+ }
13205
+ case "slide": {
13206
+ const els = targets();
13207
+ const toAt = args.indexOf("to");
13208
+ const byAt = args.indexOf("by");
13209
+ const dur = core.ms(opts.dur) ?? 520;
13210
+ const gap = core.ms(opts.stagger) ?? 0;
13211
+ els.forEach((el, i) => {
13212
+ const t = start + i * gap;
13213
+ const tr = translateOf(el, t);
13214
+ let d = null;
13215
+ if (byAt >= 0) {
13216
+ const [dx, dy] = (args[byAt + 1] ?? "").split(",").map(Number);
13217
+ d = { x: dx || 0, y: dy || 0 };
13218
+ } else if (toAt >= 0) {
13219
+ const dest = point(args[toAt + 1], opts, t, line.line);
13220
+ const b = box(el, t);
13221
+ if (dest)
13222
+ d = { x: dest.p.x - (b.x + b.width / 2), y: dest.p.y - (b.y + b.height / 2) };
13223
+ } else
13224
+ issue(line.line, "slide needs to <target> or by dx,dy");
13225
+ if (d)
13226
+ change(el, "translate", t, t + dur, `${px(tr.x + d.x)} ${px(tr.y + d.y)}`, ease(core.CURVES.house));
13227
+ });
13228
+ end = start + Math.max(0, els.length - 1) * gap + dur;
13229
+ break;
13230
+ }
13231
+ case "zoom": {
13232
+ const scene = targets()[0];
13233
+ if (!scene)
13234
+ break;
13235
+ const dur = core.ms(opts.dur) ?? 900;
13236
+ const out = args[1] === "out";
13237
+ let to = base(scene, "transform") || "none";
13238
+ if (!out) {
13239
+ const target = args[1] === "to" || args[1] === "on" ? args[2] : args[1];
13240
+ const el = target ? find(section, target)[0] : undefined;
13241
+ if (!el) {
13242
+ issue(line.line, `zoom needs to <target> or out`);
13243
+ break;
13244
+ }
13245
+ const sb = box(scene, start);
13246
+ const tb = box(el, start);
13247
+ const s = Number(opts.scale) || Math.min(2.2, Math.max(1.1, 0.7 * Math.min(sb.width / tb.width, sb.height / tb.height)));
13248
+ const qx = tb.x + tb.width / 2 - (sb.x + sb.width / 2);
13249
+ const qy = tb.y + tb.height / 2 - (sb.y + sb.height / 2);
13250
+ to = `translate(${px(-s * qx)}, ${px(-s * qy)}) scale(${round(s * 100) / 100})`;
13251
+ }
13252
+ change(scene, "transform", start, start + dur, to, ease(core.CURVES.camera));
13253
+ end = start + dur;
13254
+ break;
13255
+ }
13256
+ case "scroll": {
13257
+ const content = targets()[0];
13258
+ if (!content)
13259
+ break;
13260
+ const viewport = content.parentElement ?? section;
13261
+ const toAt = args.indexOf("to");
13262
+ const where = toAt >= 0 ? args[toAt + 1] : args[1];
13263
+ const tr = translateOf(content, start);
13264
+ const vb = box(viewport, start);
13265
+ const cb = box(content, start);
13266
+ let delta = 0;
13267
+ const n = Number(where);
13268
+ if (where !== undefined && Number.isFinite(n))
13269
+ delta = n - -tr.y;
13270
+ else if (where) {
13271
+ const el = find(section, where)[0];
13272
+ if (!el)
13273
+ issue(line.line, `nothing matches ${where}`);
13274
+ else
13275
+ delta = box(el, start).y - vb.y - (core.ms(opts.offset) ?? 0);
13276
+ }
13277
+ const max = Math.max(0, cb.height - vb.height);
13278
+ const y = Math.min(max, Math.max(0, -tr.y + delta));
13279
+ let t = start;
13280
+ if (pos && !inside(pos, { x: vb.x + 8, y: vb.y + 8, width: vb.width - 16, height: vb.height - 16 })) {
13281
+ t = travel({ p: { x: vb.x + vb.width * 0.6, y: vb.y + vb.height * 0.55 }, el: viewport }, start, {}) + 120;
13282
+ }
13283
+ const dur = core.ms(opts.dur) ?? Math.min(1400, Math.max(500, 420 + Math.abs(y + tr.y) * 1.2));
13284
+ change(content, "translate", t, t + dur, `${px(tr.x)} ${px(-y)}`, ease(CURVE_INOUT));
13285
+ end = t + dur;
13286
+ break;
13287
+ }
13288
+ case "wait":
13289
+ end = start + (core.ms(args[0]) ?? 0);
13290
+ if (core.ms(args[0]) === null)
13291
+ issue(line.line, `wait needs a time, like wait 600`);
13292
+ break;
13293
+ case "poster":
13294
+ poster = start;
13295
+ break;
13296
+ case "reset": {
13297
+ const dur = core.ms(args[0]) ?? core.ms(opts.dur) ?? 700;
13298
+ closeCaret(start);
13299
+ reset = { at: start, dur };
13300
+ end = start + dur;
13301
+ break;
13302
+ }
13303
+ }
13304
+ if (POINTER.has(verb) && pos)
13305
+ rested = end;
13306
+ beats.push({ line: line.line, text: line.text, start: round(start), end: round(end) });
13307
+ if (!line.with)
13308
+ lastStart = anchor;
13309
+ now = Math.max(now, end);
13310
+ }
13311
+ const total = Math.max(1, Math.round(reset ? reset.at + reset.dur : now));
13312
+ if (rested !== null && cursor && !idle && (reset ? reset.at : total) - rested > IDLE_MS)
13313
+ state(rested + IDLE_MS, cursor, "data-act-off", "");
13314
+ closeCaret(reset ? reset.at : total);
13315
+ if (cursor && !pos)
13316
+ state(0, cursor, "data-act-off", "");
13317
+ const loop = script.loop;
13318
+ if (loop && !reset && script.lines.length)
13319
+ issue(script.lines[script.lines.length - 1].line, "the scene loops without a reset, so it snaps back to the start; end it with reset (or say once)");
13320
+ const posterAt = poster ?? (reset ? reset.at : loop ? Math.max(0, total - 1) : total);
13321
+ return { tracks, states, total, loop, poster: round(posterAt), reset, beats };
13322
+ function travelTime(p) {
13323
+ if (!pos)
13324
+ return 700;
13325
+ const dist = Math.hypot(p.x - pos.x, p.y - pos.y);
13326
+ return Math.min(650, Math.max(300, 260 + dist * 0.9));
13327
+ }
13328
+ }
13329
+ function textHost(el) {
13330
+ const made = el.__actHost;
13331
+ if (made?.parentElement === el)
13332
+ return made;
13333
+ const cs = getComputedStyle(el);
13334
+ const paints = !/^(rgba\(0, 0, 0, 0\)|transparent)$/.test(cs.backgroundColor) || cs.backgroundImage !== "none" || cs.boxShadow !== "none" || ["Top", "Right", "Bottom", "Left"].some((s) => Number.parseFloat(cs[`border${s}Width`]) > 0 && cs[`border${s}Style`] !== "none");
13335
+ if (!paints)
13336
+ return el;
13337
+ const wrap = document.createElement("span");
13338
+ wrap.setAttribute("data-act-text", "");
13339
+ wrap.style.display = cs.display === "inline" ? "inline-block" : "block";
13340
+ while (el.firstChild)
13341
+ wrap.appendChild(el.firstChild);
13342
+ el.appendChild(wrap);
13343
+ el.__actHost = wrap;
13344
+ return wrap;
13345
+ }
13346
+ function rollColumns(el, old) {
13347
+ const cached = el.__actRoll;
13348
+ if (cached && cached.old === old)
13349
+ return cached.cols;
13350
+ const next = el.__actText ?? el.textContent ?? "";
13351
+ el.__actText = next;
13352
+ const lineH = el.getBoundingClientRect().height || 16;
13353
+ const k = el.getBoundingClientRect().width / (el.offsetWidth || 1) || 1;
13354
+ const h = lineH / k;
13355
+ const probe = document.createElement("span");
13356
+ probe.style.whiteSpace = "pre";
13357
+ el.textContent = "";
13358
+ el.appendChild(probe);
13359
+ const widthOf = (ch) => {
13360
+ if (!ch)
13361
+ return 0;
13362
+ probe.textContent = ch;
13363
+ return probe.getBoundingClientRect().width / k;
13364
+ };
13365
+ const pairs = core.columns(old, next).map((c) => ({ ...c, from_w: widthOf(c.from), to_w: widthOf(c.to) }));
13366
+ probe.remove();
13367
+ const cols = pairs.map((c) => {
13368
+ if (c.from === c.to) {
13369
+ el.appendChild(document.createTextNode(c.to));
13370
+ return null;
13371
+ }
13372
+ const col = document.createElement("span");
13373
+ col.setAttribute("data-act-roll", "");
13374
+ col.style.cssText = `display:inline-block;vertical-align:top;overflow:hidden;height:${h}px`;
13375
+ const strip = document.createElement("span");
13376
+ strip.style.cssText = "display:flex;flex-direction:column";
13377
+ for (const ch of [c.from, c.to]) {
13378
+ const s = document.createElement("span");
13379
+ s.style.height = `${h}px`;
13380
+ s.style.lineHeight = `${h}px`;
13381
+ s.style.whiteSpace = "pre";
13382
+ s.textContent = ch;
13383
+ strip.appendChild(s);
13384
+ }
13385
+ col.appendChild(strip);
13386
+ el.appendChild(col);
13387
+ return { col, strip, h, from: c.from_w, to: c.to_w };
13388
+ });
13389
+ el.__actRoll = { old, cols };
13390
+ return cols;
13391
+ }
13392
+ function finish(section, scope, plan) {
13393
+ const tracks = plan.tracks;
13394
+ stateTracks(section, scope, plan);
13395
+ const all = [...tracks.values()];
13396
+ for (const tr of all) {
13397
+ if (tr.initial === null) {
13398
+ const first = [...tr.segs].sort((a, b) => a.t0 - b.t0 || a.order - b.order)[0];
13399
+ tr.initial = first?.from ?? tr.stateInitial ?? getComputedStyle(tr.el, tr.pseudo || null).getPropertyValue(tr.prop);
13400
+ }
13401
+ }
13402
+ for (const tr of all)
13403
+ settle(tr);
13404
+ if (plan.reset) {
13405
+ const { at, dur } = plan.reset;
13406
+ const hidden = new Set;
13407
+ for (const tr of all) {
13408
+ const v = valueAt(tr, at).trim();
13409
+ if (tr.prop === "opacity" && Number(v) === 0 || tr.prop === "display" && v === "none")
13410
+ hidden.add(tr.el);
13411
+ }
13412
+ for (const tr of all) {
13413
+ const snap = hidden.has(tr.el) && tr.prop !== "opacity";
13414
+ tr.segs.push({
13415
+ t0: at,
13416
+ t1: snap ? at : at + dur,
13417
+ to: tr.initial,
13418
+ ease: core.CURVES.inout,
13419
+ order: ++order
13420
+ });
13421
+ settle(tr);
13422
+ }
13423
+ }
13424
+ return all;
13425
+ }
13426
+ function valueAt(tr, t) {
13427
+ let v = tr.initial;
13428
+ for (const s of tr.segs) {
13429
+ if (s.t0 > t)
13430
+ break;
13431
+ v = s.to;
13432
+ }
13433
+ return v;
13434
+ }
13435
+ function settle(tr) {
13436
+ tr.segs.sort((a, b) => a.t0 - b.t0 || a.order - b.order);
13437
+ let cur = tr.initial;
13438
+ let prev = null;
13439
+ const out = [];
13440
+ for (const s of tr.segs) {
13441
+ if (prev && s.t0 < prev.t1) {
13442
+ const p = (s.t0 - prev.t0) / (prev.t1 - prev.t0 || 1);
13443
+ cur = sample(tr, prev.from, prev.to, prev.ease, p);
13444
+ prev.t1 = s.t0;
13445
+ prev.to = cur;
13446
+ }
13447
+ const seg = { ...s, from: s.from ?? cur };
13448
+ out.push(seg);
13449
+ cur = seg.to;
13450
+ prev = seg;
13451
+ }
13452
+ tr.segs = out;
13453
+ }
13454
+ function sample(tr, from, to, ease, p) {
13455
+ const prop = camel(tr.prop);
13456
+ try {
13457
+ const a = tr.el.animate([{ [prop]: from }, { [prop]: to }], {
13458
+ duration: 1000,
13459
+ easing: ease,
13460
+ fill: "both",
13461
+ pseudoElement: tr.pseudo || undefined
13462
+ });
13463
+ a.pause();
13464
+ a.currentTime = Math.max(0, Math.min(1, p)) * 1000;
13465
+ const v = getComputedStyle(tr.el, tr.pseudo || null).getPropertyValue(tr.prop);
13466
+ a.cancel();
13467
+ return v;
13468
+ } catch {
13469
+ return p < 0.5 ? from : to;
13470
+ }
13471
+ }
13472
+ function stateTracks(section, scope, plan) {
13473
+ if (!plan.states.length)
13474
+ return;
13475
+ const names = new Set(plan.states.map((s) => s.attr));
13476
+ const markers = [...names].map((n) => n.startsWith(".") ? new RegExp(`\\.${CSS.escape(n.slice(1))}(?![\\w-])`) : n);
13477
+ const rules = rulesOf(scope).filter((r) => r.selectorText.includes("data-act-") || markers.some((m) => typeof m === "string" ? r.selectorText.includes(`[${m}`) : m.test(r.selectorText)));
13478
+ if (!rules.length)
13479
+ return;
13480
+ const ALWAYS = [
13481
+ "opacity",
13482
+ "transform",
13483
+ "translate",
13484
+ "scale",
13485
+ "rotate",
13486
+ "color",
13487
+ "background-color",
13488
+ "border-top-color",
13489
+ "border-right-color",
13490
+ "border-bottom-color",
13491
+ "border-left-color",
13492
+ "box-shadow",
13493
+ "filter",
13494
+ "visibility",
13495
+ "display",
13496
+ "outline-color",
13497
+ "outline-style"
13498
+ ];
13499
+ const targets = rules.map((r) => {
13500
+ const parts = splitTop(r.selectorText);
13501
+ return parts.map((sel) => {
13502
+ const pseudo = /::(before|after)\b/.exec(sel)?.[0] ?? "";
13503
+ const clean = sel.replace(/::?(before|after|marker|placeholder|selection)(?![\w-])/g, "");
13504
+ const props = new Set;
13505
+ for (let i = 0;i < r.style.length; i++) {
13506
+ const p = r.style[i];
13507
+ if (!/^(transition|animation)/.test(p))
13508
+ props.add(p);
13509
+ }
13510
+ return { sel: clean || "*", pseudo, props };
13511
+ });
13512
+ });
13513
+ const events = [...plan.states].sort((a, b) => a.t - b.t || a.order - b.order);
13514
+ const moments = [{ t: 0, events: [] }];
13515
+ for (const e of events) {
13516
+ const last = moments[moments.length - 1];
13517
+ if (e.t <= 0.5)
13518
+ moments[0].events.push(e);
13519
+ else if (Math.abs(last.t - e.t) < 0.5)
13520
+ last.events.push(e);
13521
+ else
13522
+ moments.push({ t: e.t, events: [e] });
13523
+ }
13524
+ const original = new Map;
13525
+ const apply = (e) => {
13526
+ let saved = original.get(e.el);
13527
+ if (!saved) {
13528
+ saved = new Map;
13529
+ original.set(e.el, saved);
13530
+ }
13531
+ if (e.attr.startsWith(".")) {
13532
+ const cls = e.attr.slice(1);
13533
+ if (!saved.has(e.attr))
13534
+ saved.set(e.attr, e.el.classList.contains(cls) ? "" : null);
13535
+ e.el.classList.toggle(cls, e.value !== null);
13536
+ return;
13537
+ }
13538
+ if (!saved.has(e.attr))
13539
+ saved.set(e.attr, e.el.getAttribute(e.attr));
13540
+ if (e.value === null)
13541
+ e.el.removeAttribute(e.attr);
13542
+ else
13543
+ e.el.setAttribute(e.attr, e.value);
13544
+ };
13545
+ const restore = () => {
13546
+ for (const [el, saved] of original) {
13547
+ for (const [attr, v] of saved) {
13548
+ if (attr.startsWith("."))
13549
+ el.classList.toggle(attr.slice(1), v !== null);
13550
+ else if (v === null)
13551
+ el.removeAttribute(attr);
13552
+ else
13553
+ el.setAttribute(attr, v);
13554
+ }
13555
+ }
13556
+ };
13557
+ const watched = new Map;
13558
+ const look = () => {
13559
+ targets.forEach((parts) => {
13560
+ for (const part of parts) {
13561
+ let els;
13562
+ try {
13563
+ els = [...section.querySelectorAll(part.sel)];
13564
+ if (section.matches(part.sel))
13565
+ els.push(section);
13566
+ } catch {
13567
+ continue;
13568
+ }
13569
+ for (const el of els) {
13570
+ if (watched.size >= 600)
13571
+ return;
13572
+ if (el.__actKey === undefined)
13573
+ el.__actKey = ++order;
13574
+ const id = `${el.__actKey}|${part.pseudo}`;
13575
+ let w_ = watched.get(id);
13576
+ if (!w_) {
13577
+ w_ = { el, pseudo: part.pseudo, props: new Set(part.pseudo ? [] : ALWAYS) };
13578
+ watched.set(id, w_);
13579
+ }
13580
+ for (const p of part.props)
13581
+ w_.props.add(p);
13582
+ }
13583
+ }
13584
+ });
13585
+ };
13586
+ for (const m of moments) {
13587
+ for (const e of m.events)
13588
+ apply(e);
13589
+ look();
13590
+ }
13591
+ restore();
13592
+ const list = [...watched.values()];
13593
+ const reads = [];
13594
+ for (const m of moments) {
13595
+ for (const e of m.events)
13596
+ apply(e);
13597
+ reads.push(list.map((wt) => {
13598
+ const cs = getComputedStyle(wt.el, wt.pseudo || null);
13599
+ return {
13600
+ values: [],
13601
+ transition: [
13602
+ cs.transitionProperty,
13603
+ cs.transitionDuration,
13604
+ cs.transitionDelay,
13605
+ cs.transitionTimingFunction
13606
+ ]
13607
+ };
13608
+ }));
13609
+ }
13610
+ restore();
13611
+ const still = document.createElement("style");
13612
+ still.textContent = "*,*::before,*::after{transition:none!important}";
13613
+ (scope instanceof Document ? scope.head : scope).appendChild(still);
13614
+ moments.forEach((m, mi) => {
13615
+ for (const e of m.events)
13616
+ apply(e);
13617
+ list.forEach((wt, i) => {
13618
+ const cs = getComputedStyle(wt.el, wt.pseudo || null);
13619
+ reads[mi][i].values = [...wt.props].map((p) => cs.getPropertyValue(p));
13620
+ });
13621
+ });
13622
+ restore();
13623
+ for (const e of moments[0].events)
13624
+ apply(e);
13625
+ section.offsetHeight;
13626
+ still.remove();
13627
+ for (const a of scope.getAnimations ? scope.getAnimations() : document.getAnimations()) {
13628
+ if ("transitionProperty" in a) {
13629
+ const t = a.effect?.target;
13630
+ if (t && section.contains(t))
13631
+ a.cancel();
13632
+ }
13633
+ }
13634
+ list.forEach((wt, i) => {
13635
+ const props = [...wt.props];
13636
+ props.forEach((prop, j) => {
13637
+ const first = reads[0][i].values[j];
13638
+ let last = first;
13639
+ const segs = [];
13640
+ for (let m = 1;m < moments.length; m++) {
13641
+ const v = reads[m][i].values[j];
13642
+ if (v === last)
13643
+ continue;
13644
+ const [tp, td, tdl, tf] = reads[m][i].transition;
13645
+ const timing = transitionFor(prop, tp, td, tdl, tf);
13646
+ const t0 = moments[m].t + timing.delay;
13647
+ segs.push({ t0, t1: t0 + timing.duration, to: v, ease: timing.ease });
13648
+ last = v;
13649
+ }
13650
+ if (!segs.length)
13651
+ return;
13652
+ const key = `${wt.el.__actKey}|${wt.pseudo}|${prop}`;
13653
+ let tr = plan.tracks.get(key);
13654
+ if (!tr) {
13655
+ tr = { el: wt.el, pseudo: wt.pseudo, prop, initial: null, segs: [] };
13656
+ plan.tracks.set(key, tr);
13657
+ }
13658
+ tr.stateInitial = first;
13659
+ for (const s of segs)
13660
+ tr.segs.push({ ...s, order: ++order });
13661
+ });
13662
+ });
13663
+ }
13664
+ function transitionFor(prop, props, durs, delays, eases) {
13665
+ const ps = splitTop(props);
13666
+ const ds = splitTop(durs);
13667
+ const dl = splitTop(delays);
13668
+ const es = splitTop(eases);
13669
+ const toMs = (v) => {
13670
+ if (!v)
13671
+ return 0;
13672
+ const n = Number.parseFloat(v);
13673
+ return v.trim().endsWith("ms") ? n : n * 1000;
13674
+ };
13675
+ for (let i = ps.length - 1;i >= 0; i--) {
13676
+ const p = ps[i];
13677
+ const sides = /^border-(color|width|style)$/.exec(p);
13678
+ const matches = p === "all" || p === prop || prop.startsWith(`${p}-`) || sides && new RegExp(`^border-(top|right|bottom|left)-${sides[1]}$`).test(prop) || p === "inset" && /^(top|right|bottom|left)$/.test(prop);
13679
+ if (!matches)
13680
+ continue;
13681
+ return {
13682
+ duration: toMs(ds[i % ds.length]),
13683
+ delay: toMs(dl[i % dl.length]),
13684
+ ease: es[i % es.length] ?? "ease"
13685
+ };
13686
+ }
13687
+ return { duration: 0, delay: 0, ease: "linear" };
13688
+ }
13689
+ function build(tracks, plan, paused) {
13690
+ const out = [];
13691
+ for (const tr of tracks) {
13692
+ if (!tr.segs.length)
13693
+ continue;
13694
+ const kf = core.frames(tr.initial, tr.segs, plan.total);
13695
+ if (kf.every((f) => f.value === kf[0].value))
13696
+ continue;
13697
+ const prop = camel(tr.prop);
13698
+ try {
13699
+ const a = tr.el.animate(kf.map((f) => ({ offset: f.offset, easing: f.easing, [prop]: f.value })), {
13700
+ duration: plan.total,
13701
+ iterations: plan.loop ? Number.POSITIVE_INFINITY : 1,
13702
+ fill: "both",
13703
+ pseudoElement: tr.pseudo || undefined
13704
+ });
13705
+ a.id = ID;
13706
+ if (paused) {
13707
+ a.pause();
13708
+ a.currentTime = 0;
13709
+ }
13710
+ out.push(a);
13711
+ } catch {}
13712
+ }
13713
+ return out;
13714
+ }
13715
+ w.__ponzuAct = {
13716
+ mount,
13717
+ get: (section) => handles.get(section) ?? null,
13718
+ isAct: (a) => a.id === ID
13719
+ };
13720
+ }
13721
+ var ACT_SCRIPT = `(${actRuntime.toString()})((${actCore.toString()})())`;
13722
+
11859
13723
  // packages/render/src/renderer.ts
11860
13724
  var ARTBOARD_FIT = `((root) => {
11861
13725
  const height = root.getBoundingClientRect().height;
@@ -12182,6 +14046,8 @@ function motionRuntime() {
12182
14046
  let scroller = null;
12183
14047
  let rewritten = null;
12184
14048
  const issues = [];
14049
+ let act = null;
14050
+ const isAct = (a) => a.id === "ponzu-act";
12185
14051
  const frame = () => new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(() => r())));
12186
14052
  const round = (n) => Math.round(n * 10) / 10;
12187
14053
  const idOf = (el) => el?.closest("[data-id]")?.getAttribute("data-id") ?? "";
@@ -12290,10 +14156,10 @@ function motionRuntime() {
12290
14156
  timeline: "time"
12291
14157
  };
12292
14158
  }
12293
- function list() {
14159
+ function list(scene = true) {
12294
14160
  const out = [];
12295
14161
  for (const e of entries) {
12296
- if (e.trigger !== trigger)
14162
+ if (e.trigger !== trigger || !scene && isAct(e.anim))
12297
14163
  continue;
12298
14164
  const d = describe(e);
12299
14165
  if (d)
@@ -12364,9 +14230,9 @@ function motionRuntime() {
12364
14230
  loopEnd = Math.max(loopEnd, a.delay + one);
12365
14231
  }
12366
14232
  }
12367
- return {
14233
+ const out = {
12368
14234
  trigger,
12369
- animations: animations.slice(0, 60),
14235
+ animations: (act ? list(false) : animations).slice(0, 60),
12370
14236
  settled: round(settled),
12371
14237
  loops,
12372
14238
  cycle: round(cycle),
@@ -12374,6 +14240,9 @@ function motionRuntime() {
12374
14240
  end: round(Math.max(settled, loopEnd)),
12375
14241
  at: round(now)
12376
14242
  };
14243
+ if (act && trigger === "load")
14244
+ out.act = act.summary;
14245
+ return out;
12377
14246
  }
12378
14247
  function setTime(t) {
12379
14248
  now = t;
@@ -12411,6 +14280,7 @@ function motionRuntime() {
12411
14280
  parent.removeChild(root);
12412
14281
  document.body.offsetHeight;
12413
14282
  parent.insertBefore(root, next);
14283
+ act = w.__ponzuAct?.mount(root) ?? null;
12414
14284
  entries = [];
12415
14285
  adopt(document.getAnimations(), "load");
12416
14286
  for (const s of svgs()) {
@@ -12605,9 +14475,12 @@ function motionRuntime() {
12605
14475
  if ("error" in r)
12606
14476
  return r;
12607
14477
  }
12608
- await seek(opts.at ?? info().settled);
14478
+ await seek(opts.at ?? rest());
12609
14479
  return info();
12610
14480
  }
14481
+ function rest() {
14482
+ return act && trigger === "load" ? act.summary.poster : info().settled;
14483
+ }
12611
14484
  function plan(spec) {
12612
14485
  const n = Math.max(1, Math.min(24, Math.round(spec.frames ?? 9)));
12613
14486
  const spread = (from, to) => n === 1 || to <= from ? [from] : Array.from({ length: n }, (_, i) => round(from + (to - from) * i / (n - 1)));
@@ -12631,8 +14504,25 @@ function motionRuntime() {
12631
14504
  };
12632
14505
  }
12633
14506
  const i = info();
14507
+ const story = act && trigger === "load" && !spec.frames && spec.from === undefined && spec.to === undefined;
14508
+ if (story) {
14509
+ const s = act.summary;
14510
+ const last = s.loop ? s.duration - 1 : s.duration;
14511
+ const beats = s.beats.filter((b) => b.end > b.start || /^(poster|reset)/.test(b.text));
14512
+ const picks = beats.length > 23 ? Array.from({ length: 23 }, (_, k) => beats[Math.round(k * (beats.length - 1) / 22)]) : beats;
14513
+ const steps = [{ t: 0, label: "0ms start" }];
14514
+ for (const b of picks) {
14515
+ const t = round(Math.min(last, /^reset/.test(b.text) ? b.start : b.end));
14516
+ if (steps.some((x) => x.t === t))
14517
+ continue;
14518
+ const text = b.text.length > 34 ? `${b.text.slice(0, 33)}\u2026` : b.text;
14519
+ steps.push({ t, label: `${Math.round(t)}ms ${text}` });
14520
+ }
14521
+ steps.sort((a, b) => a.t - b.t);
14522
+ return { steps };
14523
+ }
12634
14524
  const from = spec.from ?? 0;
12635
- const to = spec.to ?? Math.min(i.end, 1e4);
14525
+ const to = spec.to ?? Math.min(i.end, act ? Math.max(1e4, act.summary.duration) : 1e4);
12636
14526
  return {
12637
14527
  steps: spread(from, Math.max(from, to)).map((t) => ({
12638
14528
  t,
@@ -12684,10 +14574,10 @@ function motionRuntime() {
12684
14574
  }
12685
14575
  async function settle() {
12686
14576
  scrollTo(0);
12687
- await seek(info().settled);
14577
+ await seek(rest());
12688
14578
  }
12689
14579
  function lint() {
12690
- const out = [...issues];
14580
+ const out = [...issues, ...act?.issues ?? []];
12691
14581
  if (!root)
12692
14582
  return out;
12693
14583
  const defined = new Set;
@@ -12842,7 +14732,7 @@ img{display:block;background:repeating-conic-gradient(#fff 0 25%,#f4f4f4 0 50%)
12842
14732
  }
12843
14733
  var FULL_LINT_SCRIPT = `[...${FONT_LINT_SCRIPT}, ...${LINT_SCRIPT}, ...(window.__ponzuMotion ? ${motionCall("lint")} : []), ...${THEME_LINT_SCRIPT}].slice(0, 30)`;
12844
14734
  function prepareScript(opts) {
12845
- return `(${MOTION_SCRIPT}, ${motionCall("prepare", opts)})`;
14735
+ return `(${ACT_SCRIPT}, ${MOTION_SCRIPT}, ${motionCall("prepare", opts)})`;
12846
14736
  }
12847
14737
  async function recordFrames(page, opts) {
12848
14738
  const prepared = await page.evaluate(prepareScript({ interact: opts.interact, at: opts.scroll ? undefined : 0 }));