@paramrig/web 0.1.0 → 0.1.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.
@@ -1,533 +1,830 @@
1
- const be = "paramrig.web";
2
- function m(t) {
3
- return !!t && typeof t == "object" && !Array.isArray(t);
1
+ var e = "paramrig.web";
2
+ function t(e) {
3
+ return !!e && typeof e == "object" && !Array.isArray(e);
4
4
  }
5
- function N(t) {
6
- return typeof t == "string" && /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,127}$/.test(t);
5
+ function n(e) {
6
+ return typeof e == "string" && /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,127}$/.test(e);
7
7
  }
8
- function k(t) {
9
- return typeof t == "string" && t.length > 0 && t.length <= 2e3;
8
+ function r(e) {
9
+ return typeof e == "string" && e.length > 0 && e.length <= 2e3;
10
10
  }
11
- function Ze(t) {
12
- if (!m(t)) return !1;
13
- const s = (c, a) => a < 12 && (c === null || typeof c == "boolean" || typeof c == "string" && c.length <= 1e5 || typeof c == "number" && Number.isFinite(c) || Array.isArray(c) && c.length <= 1e3 && c.every((d) => s(d, a + 1)) || m(c) && Object.keys(c).length <= 1e3 && Object.entries(c).every(([d, p]) => !["__proto__", "prototype", "constructor"].includes(d) && s(p, a + 1)));
14
- return s(t, 0);
11
+ function i(e) {
12
+ if (!t(e)) return !1;
13
+ let n = (e, r) => r < 12 && (e === null || typeof e == "boolean" || typeof e == "string" && e.length <= 1e5 || typeof e == "number" && Number.isFinite(e) || Array.isArray(e) && e.length <= 1e3 && e.every((e) => n(e, r + 1)) || t(e) && Object.keys(e).length <= 1e3 && Object.entries(e).every(([e, t]) => ![
14
+ "__proto__",
15
+ "prototype",
16
+ "constructor"
17
+ ].includes(e) && n(t, r + 1)));
18
+ return n(e, 0);
15
19
  }
16
- function lt(t) {
17
- if (!m(t) || t.version !== 1 || !N(t.id) || !k(t.name) || !k(t.revision) || typeof t.origin != "string") throw new Error("Invalid web project manifest.");
18
- const s = new URL(t.origin);
19
- if (!["http:", "https:"].includes(s.protocol) || s.origin !== t.origin || s.username || s.password) throw new Error("The project origin must be an HTTP or HTTPS origin.");
20
- if (!Array.isArray(t.pages) || !t.pages.length || t.pages.length > 100 || !t.pages.every((o) => m(o) && N(o.id) && k(o.name) && typeof o.path == "string" && o.path.startsWith("/") && new URL(o.path, s).origin === s.origin)) throw new Error("Declare valid project pages.");
21
- if (!Array.isArray(t.groups) || !t.groups.every((o) => m(o) && N(o.id) && k(o.label))) throw new Error("Invalid control groups.");
22
- if (!Array.isArray(t.parameters) || t.parameters.length > 500) throw new Error("Invalid controls.");
23
- const c = /* @__PURE__ */ new Set(["number", "color", "select", "curve", "switch", "gradient", "text", "vector", "range", "palette", "points", "radial", "group", "list", "resource", "gizmo2d", "gizmo3d", "camera", "textureFrame", "multiselect", "action", "preset"]), a = (o, x = 0) => !(x > 8 || !m(o) || !N(o.id) || !k(o.label) || typeof o.group != "string" || !c.has(String(o.kind)) || !Ze({ value: o.defaultValue }) || o.kind === "number" && !(typeof o.min == "number" && typeof o.max == "number" && o.min <= o.max && typeof o.step == "number" && o.step > 0) || ["select", "preset", "multiselect"].includes(String(o.kind)) && !(Array.isArray(o.options) && o.options.every((y) => m(y) && typeof y.value == "string" && k(y.label))) || o.kind === "group" && !(Array.isArray(o.fields) && o.fields.every((y) => a(y, x + 1))) || o.kind === "list" && !a(o.item, x + 1));
24
- if (!t.parameters.every((o) => a(o))) throw new Error("Invalid control definition.");
25
- const d = t.parameters.map((o) => o.id);
26
- if (new Set(d).size !== d.length || new Set(t.pages.map((o) => o.id)).size !== t.pages.length) throw new Error("Control and page IDs must be unique.");
27
- const p = t.pages;
28
- if (!Array.isArray(t.bindings) || !t.bindings.every((o) => m(o) && d.includes(String(o.paramId)) && ["global", "page", "element"].includes(String(o.scope)) && ["css-variable", "style", "adapter"].includes(String(o.kind)) && k(o.property) && (o.scope !== "element" || m(o.target) && k(o.target.id)) && (o.scope !== "page" || p.some((x) => x.id === o.pageId)))) throw new Error("Invalid web bindings.");
29
- return structuredClone(t);
20
+ function a(e) {
21
+ if (!t(e) || e.version !== 1 || !n(e.id) || !r(e.name) || !r(e.revision) || typeof e.origin != "string") throw Error("Invalid web project manifest.");
22
+ let a = new URL(e.origin);
23
+ if (!["http:", "https:"].includes(a.protocol) || a.origin !== e.origin || a.username || a.password) throw Error("The project origin must be an HTTP or HTTPS origin.");
24
+ if (!Array.isArray(e.pages) || !e.pages.length || e.pages.length > 100 || !e.pages.every((e) => t(e) && n(e.id) && r(e.name) && typeof e.path == "string" && e.path.startsWith("/") && new URL(e.path, a).origin === a.origin)) throw Error("Declare valid project pages.");
25
+ if (!Array.isArray(e.groups) || !e.groups.every((e) => t(e) && n(e.id) && r(e.label))) throw Error("Invalid control groups.");
26
+ if (!Array.isArray(e.parameters) || e.parameters.length > 500) throw Error("Invalid controls.");
27
+ let o = /* @__PURE__ */ new Set([
28
+ "number",
29
+ "color",
30
+ "select",
31
+ "curve",
32
+ "switch",
33
+ "gradient",
34
+ "text",
35
+ "vector",
36
+ "range",
37
+ "palette",
38
+ "points",
39
+ "radial",
40
+ "group",
41
+ "list",
42
+ "resource",
43
+ "gizmo2d",
44
+ "gizmo3d",
45
+ "camera",
46
+ "textureFrame",
47
+ "multiselect",
48
+ "action",
49
+ "preset"
50
+ ]), s = (e, a = 0) => !(a > 8 || !t(e) || !n(e.id) || !r(e.label) || typeof e.group != "string" || !o.has(String(e.kind)) || !i({ value: e.defaultValue }) || e.kind === "number" && !(typeof e.min == "number" && typeof e.max == "number" && e.min <= e.max && typeof e.step == "number" && e.step > 0) || [
51
+ "select",
52
+ "preset",
53
+ "multiselect"
54
+ ].includes(String(e.kind)) && !(Array.isArray(e.options) && e.options.every((e) => t(e) && typeof e.value == "string" && r(e.label))) || e.kind === "group" && !(Array.isArray(e.fields) && e.fields.every((e) => s(e, a + 1))) || e.kind === "list" && !s(e.item, a + 1));
55
+ if (!e.parameters.every((e) => s(e))) throw Error("Invalid control definition.");
56
+ let c = e.parameters.map((e) => e.id);
57
+ if (new Set(c).size !== c.length || new Set(e.pages.map((e) => e.id)).size !== e.pages.length) throw Error("Control and page IDs must be unique.");
58
+ let l = e.pages;
59
+ if (!Array.isArray(e.bindings) || !e.bindings.every((e) => t(e) && c.includes(String(e.paramId)) && [
60
+ "global",
61
+ "page",
62
+ "element"
63
+ ].includes(String(e.scope)) && [
64
+ "css-variable",
65
+ "style",
66
+ "adapter"
67
+ ].includes(String(e.kind)) && r(e.property) && (e.scope !== "element" || t(e.target) && r(e.target.id)) && (e.scope !== "page" || l.some((t) => t.id === e.pageId)))) throw Error("Invalid web bindings.");
68
+ return structuredClone(e);
30
69
  }
31
- function Ve(t) {
32
- return m(t) && ["x", "y", "width", "height"].every((s) => Number.isFinite(t[s])) && Number(t.width) >= 0 && Number(t.height) >= 0;
70
+ function o(e) {
71
+ return t(e) && [
72
+ "x",
73
+ "y",
74
+ "width",
75
+ "height"
76
+ ].every((t) => Number.isFinite(e[t])) && Number(e.width) >= 0 && Number(e.height) >= 0;
33
77
  }
34
- function se(t) {
35
- const s = (c) => c === void 0 || m(c) && k(c.id) && (c.instance === void 0 || k(c.instance));
36
- return m(t) && k(t.key) && typeof t.tag == "string" && s(t.stable) && typeof t.selector == "string" && typeof t.fingerprint == "string" && typeof t.label == "string" && typeof t.pageId == "string" && Array.isArray(t.ancestors) && t.ancestors.every((c) => m(c) && k(c.key) && typeof c.label == "string" && s(c.stable)) && Ve(t.rect) && (t.clip === void 0 || Ve(t.clip)) && ["resolved", "provisional", "missing", "ambiguous"].includes(String(t.status)) && (t.controls === void 0 || Number.isInteger(t.controls) && Number(t.controls) >= 0 && Number(t.controls) <= 1e3);
78
+ function s(e) {
79
+ let n = (e) => e === void 0 || t(e) && r(e.id) && (e.instance === void 0 || r(e.instance));
80
+ return t(e) && r(e.key) && typeof e.tag == "string" && n(e.stable) && typeof e.selector == "string" && typeof e.fingerprint == "string" && typeof e.label == "string" && typeof e.pageId == "string" && Array.isArray(e.ancestors) && e.ancestors.every((e) => t(e) && r(e.key) && typeof e.label == "string" && n(e.stable)) && o(e.rect) && (e.clip === void 0 || o(e.clip)) && [
81
+ "resolved",
82
+ "provisional",
83
+ "missing",
84
+ "ambiguous"
85
+ ].includes(String(e.status)) && (e.controls === void 0 || Number.isInteger(e.controls) && Number(e.controls) >= 0 && Number(e.controls) <= 1e3);
37
86
  }
38
- const he = (t) => typeof t == "string" && /^#[\da-f]{3,8}$/i.test(t);
39
- function dt(t) {
40
- return m(t) && he(t.outline) && he(t.chip) && he(t.chipText);
87
+ var c = (e) => typeof e == "string" && /^#[\da-f]{3,8}$/i.test(e);
88
+ function l(e) {
89
+ return t(e) && c(e.outline) && c(e.chip) && c(e.chipText);
41
90
  }
42
- function ut(t) {
43
- return m(t) && typeof t.pageId == "string" && typeof t.url == "string" && m(t.viewport) && ["width", "height", "dpr"].every((s) => Number.isFinite(t.viewport[s]) && Number(t.viewport[s]) > 0) && m(t.scroll) && Number.isFinite(t.scroll.x) && Number.isFinite(t.scroll.y) && Array.isArray(t.scrollers) && t.scrollers.length <= 1e3 && t.scrollers.every((s) => m(s) && se(s.target) && Number.isFinite(s.x) && Number.isFinite(s.y));
91
+ function u(e) {
92
+ return t(e) && typeof e.pageId == "string" && typeof e.url == "string" && t(e.viewport) && [
93
+ "width",
94
+ "height",
95
+ "dpr"
96
+ ].every((t) => Number.isFinite(e.viewport[t]) && Number(e.viewport[t]) > 0) && t(e.scroll) && Number.isFinite(e.scroll.x) && Number.isFinite(e.scroll.y) && Array.isArray(e.scrollers) && e.scrollers.length <= 1e3 && e.scrollers.every((e) => t(e) && s(e.target) && Number.isFinite(e.x) && Number.isFinite(e.y));
44
97
  }
45
- function pt(t) {
46
- return m(t) && N(t.id) && ["note", "arrow", "rectangle", "ellipse", "highlight", "pen"].includes(String(t.tool)) && typeof t.color == "string" && /^#[\da-f]{6}$/i.test(t.color) && typeof t.width == "number" && t.width > 0 && t.width <= 32 && typeof t.pageId == "string" && m(t.viewport) && Number.isFinite(t.viewport.width) && Number.isFinite(t.viewport.height) && Array.isArray(t.points) && t.points.length <= 1e4 && t.points.every((s) => m(s) && Number.isFinite(s.x) && Number.isFinite(s.y));
98
+ function d(e) {
99
+ return t(e) && n(e.id) && [
100
+ "note",
101
+ "arrow",
102
+ "rectangle",
103
+ "ellipse",
104
+ "highlight",
105
+ "pen"
106
+ ].includes(String(e.tool)) && typeof e.color == "string" && /^#[\da-f]{6}$/i.test(e.color) && typeof e.width == "number" && e.width > 0 && e.width <= 32 && typeof e.pageId == "string" && t(e.viewport) && Number.isFinite(e.viewport.width) && Number.isFinite(e.viewport.height) && Array.isArray(e.points) && e.points.length <= 1e4 && e.points.every((e) => t(e) && Number.isFinite(e.x) && Number.isFinite(e.y));
47
107
  }
48
- function Xe(t, s) {
49
- return { channel: be, version: 1, sessionId: t, payload: s };
108
+ function f(t, n) {
109
+ return {
110
+ channel: e,
111
+ version: 1,
112
+ sessionId: t,
113
+ payload: n
114
+ };
50
115
  }
51
- function ft(t, s) {
52
- return { channel: be, version: 1, type: "sdk-present", projectId: t, instanceId: s };
116
+ function ee(t, n) {
117
+ return {
118
+ channel: e,
119
+ version: 1,
120
+ type: "sdk-present",
121
+ projectId: t,
122
+ instanceId: n
123
+ };
53
124
  }
54
- function gt(t) {
55
- return m(t) && t.channel === be && typeof t.version == "number" && N(t.sessionId) && m(t.payload) && typeof t.payload.type == "string";
125
+ function te(e) {
126
+ return t(e) && e.channel === "paramrig.web" && typeof e.version == "number" && n(e.sessionId) && t(e.payload) && typeof e.payload.type == "string";
56
127
  }
57
- function mt(t) {
58
- switch (t.type) {
59
- case "hello":
60
- return N(t.projectId);
61
- case "values":
62
- return Ze(t.values) && typeof t.source == "boolean";
63
- case "select":
64
- return se(t.target);
65
- case "reveal-target":
66
- return se(t.target);
67
- case "restore-context":
68
- return ut(t.context);
69
- case "navigate":
70
- return typeof t.path == "string";
71
- case "capture":
72
- return N(t.requestId);
73
- case "configure":
74
- return (t.chrome === void 0 || dt(t.chrome)) && (t.activeMarks === void 0 || Array.isArray(t.activeMarks) && t.activeMarks.every(N)) && (t.activeTargets === void 0 || Array.isArray(t.activeTargets) && t.activeTargets.every((s) => typeof s == "string" && s.length < 2e3)) && (t.displayScale === void 0 || typeof t.displayScale == "number" && t.displayScale >= 0.05 && t.displayScale <= 4) && ["browse", "select", "annotate"].includes(String(t.mode)) && ["note", "arrow", "rectangle", "ellipse", "highlight", "pen"].includes(String(t.tool)) && typeof t.color == "string" && /^#[\da-f]{6}$/i.test(t.color) && Array.isArray(t.targets) && t.targets.every(se) && Array.isArray(t.marks) && t.marks.every(pt);
75
- default:
76
- return !1;
77
- }
128
+ function ne(e) {
129
+ switch (e.type) {
130
+ case "hello": return n(e.projectId);
131
+ case "values": return i(e.values) && typeof e.source == "boolean";
132
+ case "select": return s(e.target);
133
+ case "reveal-target": return s(e.target);
134
+ case "restore-context": return u(e.context);
135
+ case "navigate": return typeof e.path == "string";
136
+ case "capture": return n(e.requestId);
137
+ case "configure": return (e.chrome === void 0 || l(e.chrome)) && (e.activeMarks === void 0 || Array.isArray(e.activeMarks) && e.activeMarks.every(n)) && (e.activeTargets === void 0 || Array.isArray(e.activeTargets) && e.activeTargets.every((e) => typeof e == "string" && e.length < 2e3)) && (e.displayScale === void 0 || typeof e.displayScale == "number" && e.displayScale >= .05 && e.displayScale <= 4) && [
138
+ "browse",
139
+ "select",
140
+ "annotate"
141
+ ].includes(String(e.mode)) && [
142
+ "note",
143
+ "arrow",
144
+ "rectangle",
145
+ "ellipse",
146
+ "highlight",
147
+ "pen"
148
+ ].includes(String(e.tool)) && typeof e.color == "string" && /^#[\da-f]{6}$/i.test(e.color) && Array.isArray(e.targets) && e.targets.every(s) && Array.isArray(e.marks) && e.marks.every(d);
149
+ default: return !1;
150
+ }
78
151
  }
79
- function Ye(t, s, c) {
80
- if (!t.targetKey) return t.points.map((d) => ({ x: d.x - c.x, y: d.y - c.y }));
81
- const a = s.find((d) => d.key === t.targetKey);
82
- return !a || a.status === "missing" || a.status === "ambiguous" ? null : t.points.map((d) => ({ x: a.rect.x + d.x * a.rect.width, y: a.rect.y + d.y * a.rect.height }));
152
+ //#endregion
153
+ //#region src/web/geometry.ts
154
+ function re(e, t, n) {
155
+ if (!e.targetKey) return e.points.map((e) => ({
156
+ x: e.x - n.x,
157
+ y: e.y - n.y
158
+ }));
159
+ let r = t.find((t) => t.key === e.targetKey);
160
+ return !r || r.status === "missing" || r.status === "ambiguous" ? null : e.points.map((e) => ({
161
+ x: r.rect.x + e.x * r.rect.width,
162
+ y: r.rect.y + e.y * r.rect.height
163
+ }));
83
164
  }
84
- function Be(t, s, c) {
85
- return s ? { x: (t.x - s.rect.x) / Math.max(1, s.rect.width), y: (t.y - s.rect.y) / Math.max(1, s.rect.height) } : { x: t.x + c.x, y: t.y + c.y };
165
+ function ie(e, t, n) {
166
+ return t ? {
167
+ x: (e.x - t.rect.x) / Math.max(1, t.rect.width),
168
+ y: (e.y - t.rect.y) / Math.max(1, t.rect.height)
169
+ } : {
170
+ x: e.x + n.x,
171
+ y: e.y + n.y
172
+ };
86
173
  }
87
- function yt(t) {
88
- const s = t.map((p) => p.x), c = t.map((p) => p.y), a = Math.min(...s), d = Math.min(...c);
89
- return { x: a, y: d, width: Math.max(...s) - a, height: Math.max(...c) - d };
174
+ function p(e) {
175
+ let t = e.map((e) => e.x), n = e.map((e) => e.y), r = Math.min(...t), i = Math.min(...n);
176
+ return {
177
+ x: r,
178
+ y: i,
179
+ width: Math.max(...t) - r,
180
+ height: Math.max(...n) - i
181
+ };
90
182
  }
91
- function ht(t, s) {
92
- const c = s[0], a = s.at(-1);
93
- if (!c || !a) return "";
94
- const d = yt([c, a]);
95
- if (t.tool === "rectangle" || t.tool === "highlight") return `M${d.x},${d.y}h${d.width}v${d.height}h${-d.width}Z`;
96
- if (t.tool === "ellipse") return `M${d.x},${d.y + d.height / 2}a${d.width / 2},${d.height / 2} 0 1 0 ${d.width},0a${d.width / 2},${d.height / 2} 0 1 0 ${-d.width},0`;
97
- if (t.tool === "note") return `M${c.x - 6},${c.y}a6,6 0 1 0 12,0a6,6 0 1 0 -12,0`;
98
- if (t.tool === "arrow") {
99
- const p = Math.atan2(a.y - c.y, a.x - c.x), o = 12;
100
- return `M${c.x},${c.y}L${a.x},${a.y}M${a.x - Math.cos(p - 0.5) * o},${a.y - Math.sin(p - 0.5) * o}L${a.x},${a.y}L${a.x - Math.cos(p + 0.5) * o},${a.y - Math.sin(p + 0.5) * o}`;
101
- }
102
- return s.map((p, o) => `${o ? "L" : "M"}${p.x},${p.y}`).join(" ");
183
+ function ae(e, t) {
184
+ let n = t[0], r = t.at(-1);
185
+ if (!n || !r) return "";
186
+ let i = p([n, r]);
187
+ if (e.tool === "rectangle" || e.tool === "highlight") return `M${i.x},${i.y}h${i.width}v${i.height}h${-i.width}Z`;
188
+ if (e.tool === "ellipse") return `M${i.x},${i.y + i.height / 2}a${i.width / 2},${i.height / 2} 0 1 0 ${i.width},0a${i.width / 2},${i.height / 2} 0 1 0 ${-i.width},0`;
189
+ if (e.tool === "note") return `M${n.x - 6},${n.y}a6,6 0 1 0 12,0a6,6 0 1 0 -12,0`;
190
+ if (e.tool === "arrow") {
191
+ let e = Math.atan2(r.y - n.y, r.x - n.x);
192
+ return `M${n.x},${n.y}L${r.x},${r.y}M${r.x - Math.cos(e - .5) * 12},${r.y - Math.sin(e - .5) * 12}L${r.x},${r.y}L${r.x - Math.cos(e + .5) * 12},${r.y - Math.sin(e + .5) * 12}`;
193
+ }
194
+ return t.map((e, t) => `${t ? "L" : "M"}${e.x},${e.y}`).join(" ");
103
195
  }
104
- const wt = ["http://localhost:5174", "http://127.0.0.1:5174"], qe = (t) => {
105
- try {
106
- return typeof t == "string" && new URL(t).origin === t;
107
- } catch {
108
- return !1;
109
- }
110
- }, we = () => ({ dispose() {
111
- } });
112
- let q = null;
113
- const Je = { px: 1, pt: 96 / 72, pc: 16, in: 96, cm: 96 / 2.54, mm: 96 / 25.4, q: 96 / 101.6 }, bt = { s: 1, ms: 1 / 1e3 }, xt = { deg: 1, grad: 0.9, rad: 180 / Math.PI, turn: 360 };
114
- function Ge(t, s, c) {
115
- if (t in Je) return Je[t];
116
- const a = (d) => parseFloat(getComputedStyle(d).fontSize) || 16;
117
- if (t === "rem") return a(document.documentElement);
118
- if (t === "em") return a(c === "font-size" && s.parentElement ? s.parentElement : s);
119
- if (t === "vw") return window.innerWidth / 100;
120
- if (t === "vh") return window.innerHeight / 100;
121
- if (t === "vmin") return Math.min(window.innerWidth, window.innerHeight) / 100;
122
- if (t === "vmax") return Math.max(window.innerWidth, window.innerHeight) / 100;
196
+ //#endregion
197
+ //#region src/web/sdk.ts
198
+ var oe = ["http://localhost:5174", "http://127.0.0.1:5174"], se = (e) => {
199
+ try {
200
+ return typeof e == "string" && new URL(e).origin === e;
201
+ } catch {
202
+ return !1;
203
+ }
204
+ }, ce = () => ({ dispose() {} }), m = null, h = {
205
+ px: 1,
206
+ pt: 96 / 72,
207
+ pc: 16,
208
+ in: 96,
209
+ cm: 96 / 2.54,
210
+ mm: 96 / 25.4,
211
+ q: 96 / 101.6
212
+ }, g = {
213
+ s: 1,
214
+ ms: 1 / 1e3
215
+ }, _ = {
216
+ deg: 1,
217
+ grad: .9,
218
+ rad: 180 / Math.PI,
219
+ turn: 360
220
+ };
221
+ function v(e, t, n) {
222
+ if (e in h) return h[e];
223
+ let r = (e) => parseFloat(getComputedStyle(e).fontSize) || 16;
224
+ if (e === "rem") return r(document.documentElement);
225
+ if (e === "em") return r(n === "font-size" && t.parentElement ? t.parentElement : t);
226
+ if (e === "vw") return window.innerWidth / 100;
227
+ if (e === "vh") return window.innerHeight / 100;
228
+ if (e === "vmin") return Math.min(window.innerWidth, window.innerHeight) / 100;
229
+ if (e === "vmax") return Math.max(window.innerWidth, window.innerHeight) / 100;
123
230
  }
124
- function Et(t, s, c, a, d) {
125
- for (const x of [bt, xt]) if (s in x && c in x) return t * x[s] / x[c];
126
- const p = Ge(s, a, d), o = Ge(c, a, d);
127
- return p !== void 0 && o !== void 0 && o > 0 ? t * p / o : void 0;
231
+ function y(e, t, n, r, i) {
232
+ for (let r of [g, _]) if (t in r && n in r) return e * r[t] / r[n];
233
+ let a = v(t, r, i), o = v(n, r, i);
234
+ return a !== void 0 && o !== void 0 && o > 0 ? e * a / o : void 0;
128
235
  }
129
- function At(t, s, c) {
130
- const a = /^(-?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?)([a-z%]*)$/i.exec(t);
131
- if (!a) {
132
- const y = parseFloat(t);
133
- return Number.isFinite(y) ? y : void 0;
134
- }
135
- const d = Number(a[1]), p = a[2].toLowerCase(), o = (s.unit ?? "").toLowerCase();
136
- if (!p || p === o) return d;
137
- const x = Et(d, p, o, c, s.property);
138
- return x === void 0 ? void 0 : Math.round(x * 1e6) / 1e6;
236
+ function le(e, t, n) {
237
+ let r = /^(-?(?:\d+\.?\d*|\.\d+)(?:e[-+]?\d+)?)([a-z%]*)$/i.exec(e);
238
+ if (!r) {
239
+ let t = parseFloat(e);
240
+ return Number.isFinite(t) ? t : void 0;
241
+ }
242
+ let i = Number(r[1]), a = r[2].toLowerCase(), o = (t.unit ?? "").toLowerCase();
243
+ if (!a || a === o) return i;
244
+ let s = y(i, a, o, n, t.property);
245
+ return s === void 0 ? void 0 : Math.round(s * 1e6) / 1e6;
139
246
  }
140
- function St({ manifest: t, hostOrigin: s = wt, adapters: c = {} }) {
141
- const a = lt(t), d = typeof s == "string" ? [s] : [...s];
142
- if (!d.length || d.some((e) => !qe(e)))
143
- return console.warn(`ParamRig: hostOrigin must be one or more workbench origins such as "http://localhost:5174", but is ${JSON.stringify(s)}. The page is left untouched.`), we();
144
- if (a.origin !== location.origin)
145
- return console.warn(`ParamRig: this page is at ${location.origin} and .paramrig/manifest.json declares ${a.origin}. Open the page at the manifest origin, or set the manifest's "origin" to ${location.origin}. The page is left untouched.`), we();
146
- if (window.parent === window) return we();
147
- q && (console.warn("ParamRig: connectWeb was called again before the previous connection was disposed. The previous one is replaced; call dispose() in the effect cleanup and in the hot-reload handler."), q.dispose());
148
- let p = "", o = "";
149
- const x = crypto.randomUUID();
150
- let y = "browse", J = "note", xe = "#df7757", ae = 1, Ee, ce = [], le = [], I = [], T = [], A = null, K = null, b = null, L, H, z, G = null, V = null, de = !1, ue = !1, Z = 0, Ae = "", Se = "", pe = "", $e = [], D = { outline: "#488a99", chip: "#1e2423", chipText: "#eef2f1" };
151
- const fe = document.documentElement.style.touchAction, Q = /* @__PURE__ */ new Map(), F = /* @__PURE__ */ new Map(), O = Object.fromEntries(a.parameters.map((e) => [e.id, structuredClone(e.defaultValue)])), M = "http://www.w3.org/2000/svg", E = document.createElement("paramrig-overlay");
152
- E.tabIndex = -1, E.setAttribute("aria-label", "Page selection. Use arrow keys to select ancestors, children and siblings."), Object.assign(E.style, { position: "fixed", inset: "0", pointerEvents: "none", zIndex: "2147483647", contain: "strict", outline: "none" });
153
- const Qe = E.attachShadow({ mode: "closed" }), C = document.createElementNS(M, "svg");
154
- C.setAttribute("width", "100%"), C.setAttribute("height", "100%"), C.style.overflow = "visible", Qe.append(C);
155
- const S = () => a.pages.find((e) => new URL(e.path, a.origin).pathname === location.pathname)?.id ?? location.pathname, Ie = (e) => `id:${encodeURIComponent(S())}:${encodeURIComponent(e.id)}:${encodeURIComponent(e.instance ?? "")}`, X = (e) => {
156
- const r = e.getAttribute("data-paramrig-id");
157
- if (!r) return;
158
- const n = e.getAttribute("data-paramrig-instance") ?? e.closest("[data-paramrig-instance]")?.getAttribute("data-paramrig-instance") ?? void 0;
159
- return { id: r, ...n ? { instance: n } : {} };
160
- }, ge = (e, r = !1) => [...document.querySelectorAll(`[data-paramrig-id="${CSS.escape(e.id)}"]`)].filter((n) => !r && e.instance === void 0 || X(n)?.instance === e.instance);
161
- function ve(e) {
162
- const r = [];
163
- let n = e;
164
- for (; n && n !== document.documentElement; ) {
165
- if (n.id && document.querySelectorAll(`#${CSS.escape(n.id)}`).length === 1) {
166
- r.unshift(`#${CSS.escape(n.id)}`);
167
- break;
168
- }
169
- const i = n.parentElement ? [...n.parentElement.children].filter((l) => l.tagName === n.tagName) : [];
170
- r.unshift(`${n.localName}:nth-of-type(${i.indexOf(n) + 1})`), n = n.parentElement;
171
- }
172
- return r.join(" > ") || "html";
173
- }
174
- const et = (e) => `${e.localName}|${e.getAttribute("role") ?? ""}|${e.getAttribute("aria-label") ?? ""}|${(e.textContent ?? "").trim().replace(/\s+/g, " ").slice(0, 160)}`, ke = (e) => {
175
- const r = e.replace(/[-_]+/g, " ").trim();
176
- return r ? r[0].toUpperCase() + r.slice(1) : "";
177
- }, Le = (e) => {
178
- const r = e.getAttribute("data-paramrig-label");
179
- if (r) return r.slice(0, 90);
180
- const n = e.getAttribute("data-paramrig-id");
181
- if (n && ke(n)) return ke(n).slice(0, 60);
182
- const i = e.getAttribute("aria-label");
183
- return i ? i.slice(0, 90) : ((e.matches("a,button,p,h1,h2,h3,h4,h5,h6,label,span,li,em,strong,small,figcaption,summary,td,th,dt,dd,legend") ? (e.textContent ?? "").trim().replace(/\s+/g, " ") : "") || `Unnamed ${e.localName}`).slice(0, 60);
184
- }, tt = (e) => {
185
- const r = X(e);
186
- return r ? new Set(a.bindings.filter((n) => te(n) && n.scope === "element" && n.target?.id === r.id && (n.target.instance === void 0 || n.target.instance === r.instance)).map((n) => n.paramId)).size : 0;
187
- };
188
- function P(e, r = !0) {
189
- const n = X(e), i = ve(e), l = n ? Ie(n) : `dom:${S()}:${i}`, u = e.getBoundingClientRect();
190
- let g = 0, h = 0, f = innerWidth, W = innerHeight;
191
- for (let $ = e.parentElement; $; $ = $.parentElement) {
192
- const _ = getComputedStyle($), U = $.getBoundingClientRect();
193
- /(auto|scroll|hidden|clip)/.test(_.overflowX) && (g = Math.max(g, U.left), f = Math.min(f, U.right)), /(auto|scroll|hidden|clip)/.test(_.overflowY) && (h = Math.max(h, U.top), W = Math.min(W, U.bottom));
194
- }
195
- const oe = { x: g, y: h, width: Math.max(0, f - g), height: Math.max(0, W - h) }, Y = e.closest("[data-paramrig-source]")?.getAttribute("data-paramrig-source");
196
- Q.set(l, e);
197
- const B = [];
198
- if (r) {
199
- let $ = e.parentElement;
200
- for (; $ && B.length < 12; ) {
201
- const _ = X($), U = _ ? Ie(_) : `dom:${S()}:${ve($)}`;
202
- Q.set(U, $), B.push({ key: U, label: Le($), stable: _ }), $ = $.parentElement;
203
- }
204
- }
205
- return { key: l, stable: n, selector: i, fingerprint: et(e), label: Le(e), tag: e.localName, ...Y ? { source: Y } : {}, pageId: S(), rect: { x: u.x, y: u.y, width: u.width, height: u.height }, clip: oe, ancestors: B, controls: tt(e), status: n ? ge(n, !0).length === 1 ? "resolved" : "ambiguous" : "provisional" };
206
- }
207
- function ee(e) {
208
- if (e.pageId !== S()) return { target: { ...e, status: "missing" } };
209
- if (e.stable) {
210
- const n = ge(e.stable, !0);
211
- return n.length !== 1 ? { target: { ...e, status: n.length ? "ambiguous" : "missing" } } : { element: n[0], target: { ...P(n[0]), key: e.key } };
212
- }
213
- const r = Q.get(e.key);
214
- return r?.isConnected ? { element: r, target: { ...P(r), key: e.key } } : { target: { ...e, status: "missing" } };
215
- }
216
- function nt() {
217
- const e = [...document.querySelectorAll("[data-paramrig-id]")].slice(0, 200), r = `${S()}|${e.map((n) => `${n.getAttribute("data-paramrig-id")}/${X(n)?.instance ?? ""}`).join(",")}`;
218
- return r !== pe && (pe = r, $e = e.map((n) => P(n, !1))), $e;
219
- }
220
- function me() {
221
- const e = [];
222
- for (const r of document.querySelectorAll("[data-paramrig-id]")) (r.scrollTop || r.scrollLeft) && e.push({ target: P(r, !1), x: r.scrollLeft, y: r.scrollTop });
223
- return { pageId: S(), url: location.href, viewport: { width: innerWidth, height: innerHeight, dpr: devicePixelRatio }, scroll: { x: scrollX, y: scrollY }, scrollers: e };
224
- }
225
- function v(e) {
226
- p && o && !ue && window.parent.postMessage(Xe(p, e), o);
227
- }
228
- function rt() {
229
- C.replaceChildren(), delete E.dataset.hover;
230
- const e = (n) => {
231
- if (!n?.clip) return C;
232
- const i = document.createElementNS(M, "clipPath"), l = document.createElementNS(M, "rect"), u = `paramrig-clip-${C.childElementCount}`;
233
- i.id = u;
234
- for (const h of ["x", "y", "width", "height"]) l.setAttribute(h, String(n.clip[h]));
235
- i.append(l), C.append(i);
236
- const g = document.createElementNS(M, "g");
237
- return g.setAttribute("clip-path", `url(#${u})`), C.append(g), g;
238
- }, r = y === "browse" ? [] : [A, ...I.filter((n) => ce.includes(n.key))];
239
- for (const n of r.filter((i) => !!i && !["missing", "ambiguous"].includes(i.status))) {
240
- const i = e(n), l = document.createElementNS(M, "rect");
241
- for (const u of ["x", "y", "width", "height"]) l.setAttribute(u, String(n.rect[u]));
242
- l.setAttribute("fill", `${D.outline.slice(0, 7)}14`), l.setAttribute("stroke", D.outline), l.setAttribute("stroke-width", "1.5"), i.append(l), n === A && it(i, n);
243
- }
244
- for (const n of [...T.filter((i) => i.id !== b?.id), ...b ? [b] : []]) {
245
- if (n.pageId !== S()) continue;
246
- const i = Ye(n, [...I, ...L ? [L] : []], { x: scrollX, y: scrollY });
247
- if (!i) continue;
248
- const l = e(n.targetKey ? [...I, ...L ? [L] : []].find((h) => h.key === n.targetKey) : void 0), u = document.createElementNS(M, "path"), g = y !== "annotate" || le.includes(n.id);
249
- if (u.setAttribute("d", ht(n, i)), u.setAttribute("stroke", n.color), u.setAttribute("stroke-width", String(n.width)), u.setAttribute("stroke-linecap", "round"), u.setAttribute("stroke-linejoin", "round"), u.setAttribute("fill", n.tool === "highlight" ? `${n.color}33` : n.tool === "note" ? n.color : "none"), l.append(u), g || u.setAttribute("opacity", ".35"), y === "annotate" && g) for (const h of [i[0], i.at(-1)].filter((f) => !!f)) {
250
- const f = document.createElementNS(M, "circle");
251
- f.setAttribute("cx", String(h.x)), f.setAttribute("cy", String(h.y)), f.setAttribute("r", "3"), f.setAttribute("fill", n.color), l.append(f);
252
- }
253
- }
254
- }
255
- function it(e, r) {
256
- const n = 1 / Math.max(0.05, ae), i = 11 * n, l = 18 * n, u = 6 * n, g = r.controls ? `${r.label} · ${r.controls} control${r.controls === 1 ? "" : "s"}` : r.label;
257
- E.dataset.hover = g;
258
- const h = document.createElementNS(M, "rect"), f = document.createElementNS(M, "text");
259
- f.textContent = g, f.setAttribute("font-family", "system-ui, -apple-system, Segoe UI, sans-serif"), f.setAttribute("font-size", String(i)), f.setAttribute("fill", D.chipText), f.setAttribute("dominant-baseline", "central"), e.append(h, f);
260
- const W = Math.min((f.getComputedTextLength?.() ?? g.length * i * 0.55) + u * 2, innerWidth), oe = Math.max(0, Math.min(innerWidth - W, r.rect.x)), Y = r.rect.y - l - 2 * n >= 0 ? r.rect.y - l - 2 * n : Math.min(innerHeight - l, r.rect.y + 2 * n);
261
- for (const [B, $] of [["x", oe], ["y", Y], ["width", W], ["height", l], ["rx", 3 * n]]) h.setAttribute(B, String($));
262
- h.setAttribute("fill", D.chip), h.setAttribute("stroke", D.outline), h.setAttribute("stroke-width", String(n)), f.setAttribute("x", String(oe + u)), f.setAttribute("y", String(Y + l / 2));
263
- }
264
- function ot() {
265
- if (Z = 0, !p || ue) return;
266
- if (I = I.map((l) => ee(l).target), A) {
267
- const l = Q.get(A.key);
268
- A = l?.isConnected ? P(l) : null;
269
- }
270
- const e = JSON.stringify([A, I, ce, T, b, y, scrollX, scrollY]);
271
- e !== Se && (rt(), Se = e);
272
- const r = me(), n = nt(), i = JSON.stringify([r, I, pe]);
273
- i !== Ae && (Ae = i, v({ type: "scene", context: r, targets: I, page: n })), !document.hidden && (y !== "browse" || T.length > 0 || I.length > 0) && w();
274
- }
275
- function w() {
276
- !Z && p && (Z = requestAnimationFrame(ot));
277
- }
278
- function Me(e) {
279
- return e.target ? ge(e.target) : [document.documentElement];
280
- }
281
- function te(e) {
282
- return !e.pageId || e.pageId === S();
283
- }
284
- function ne() {
285
- for (const [e, r] of F) if (e instanceof HTMLElement || e instanceof SVGElement) for (const [n, i] of r)
286
- i.value ? e.style.setProperty(n, i.value, i.priority) : e.style.removeProperty(n);
287
- F.clear();
288
- for (const e of Object.values(c)) e.restore();
289
- }
290
- function Ce() {
291
- for (const e of a.bindings.filter(te)) {
292
- const r = a.parameters.find((l) => l.id === e.paramId);
293
- if (e.kind === "adapter") {
294
- c[e.property] && (O[e.paramId] = c[e.property].read());
295
- continue;
296
- }
297
- const n = Me(e)[0];
298
- if (!n) continue;
299
- const i = getComputedStyle(n).getPropertyValue(e.property).trim();
300
- if (i)
301
- if (r.kind === "number") {
302
- const l = At(i, e, n);
303
- l !== void 0 && (O[r.id] = l);
304
- } else if (r.kind === "color") {
305
- if (/^#[\da-f]{6}([\da-f]{2})?$/i.test(i)) {
306
- O[r.id] = i.toLowerCase();
307
- continue;
308
- }
309
- const l = document.createElement("canvas").getContext("2d");
310
- if (l) {
311
- l.fillStyle = i, l.fillRect(0, 0, 1, 1);
312
- const u = l.getImageData(0, 0, 1, 1).data;
313
- O[r.id] = `#${[...u].slice(0, r.alpha ? 4 : 3).map((g) => g.toString(16).padStart(2, "0")).join("")}`;
314
- }
315
- } else O[r.id] = i;
316
- }
317
- }
318
- function Pe() {
319
- if (ne(), !V || de) {
320
- w();
321
- return;
322
- }
323
- for (const e of a.bindings.filter(te)) {
324
- const r = V[e.paramId];
325
- if (!(r === void 0 || JSON.stringify(r) === JSON.stringify(O[e.paramId])) && e.kind === "adapter") {
326
- if (!c[e.property]) {
327
- v({ type: "error", message: `Missing adapter: ${e.property}` });
328
- continue;
329
- }
330
- c[e.property].apply(r);
331
- }
332
- }
333
- Ne(), w();
334
- }
335
- function Ne() {
336
- if (!(!V || de)) {
337
- for (const [e] of F) e.isConnected || F.delete(e);
338
- for (const e of a.bindings.filter((r) => te(r) && r.kind !== "adapter")) {
339
- const r = V[e.paramId];
340
- if (!(r === void 0 || JSON.stringify(r) === JSON.stringify(O[e.paramId])) && !(typeof r != "string" && typeof r != "number")) {
341
- for (const n of Me(e)) if (n instanceof HTMLElement || n instanceof SVGElement) {
342
- const i = F.get(n) ?? /* @__PURE__ */ new Map();
343
- i.has(e.property) || i.set(e.property, { value: n.style.getPropertyValue(e.property), priority: n.style.getPropertyPriority(e.property) }), F.set(n, i);
344
- const l = `${r}${e.unit ?? ""}`, u = document.createElement("span").style;
345
- u.setProperty(e.property, l, "important");
346
- const g = u.getPropertyValue(e.property);
347
- g && (n.style.getPropertyValue(e.property) !== g || n.style.getPropertyPriority(e.property) !== u.getPropertyPriority(e.property)) && n.style.setProperty(e.property, g, "important");
348
- }
349
- }
350
- }
351
- }
352
- }
353
- function Te() {
354
- v({ type: "ready", instanceId: x, manifest: a, sourceValues: O, context: me() }), w();
355
- }
356
- function re(e, r = !1) {
357
- K = e, A = P(e), v({ type: "selection", target: A, additive: r }), w();
358
- }
359
- async function st(e) {
360
- try {
361
- const { toPng: r } = await import("./index-L3Zm-CoX.js"), n = await r(document.documentElement, { filter: (i) => i !== E, pixelRatio: 1, width: innerWidth, height: innerHeight, style: { transform: `translate(${-scrollX}px, ${-scrollY}px)`, transformOrigin: "0 0" } });
362
- v({ type: "capture", requestId: e, dataUrl: n });
363
- } catch (r) {
364
- v({ type: "capture", requestId: e, error: r instanceof Error ? r.message : "DOM capture is unavailable." });
365
- }
366
- }
367
- function Oe(e) {
368
- if (e.source !== window.parent || !gt(e.data) || (o ? e.origin !== o : !d.includes(e.origin))) return;
369
- const r = e.data;
370
- if (r.payload.type === "hello") {
371
- if (r.payload.projectId !== a.id) return;
372
- if (r.version !== 1) {
373
- window.parent.postMessage(Xe(r.sessionId, { type: "error", message: "Incompatible web protocol. Update the project integration." }), e.origin);
374
- return;
375
- }
376
- if (o = e.origin, p !== r.sessionId) {
377
- p = r.sessionId;
378
- try {
379
- ne(), Ce();
380
- } catch (i) {
381
- v({ type: "error", message: `Cannot read the source controls: ${String(i)}` });
382
- return;
383
- }
384
- E.isConnected || document.documentElement.append(E);
385
- }
386
- Te();
387
- return;
388
- }
389
- if (r.sessionId !== p || r.version !== 1 || !mt(r.payload)) return;
390
- const n = r.payload;
391
- if (n.type === "configure" && ((n.mode !== y || n.tool !== J) && R(), y = n.mode, ae = n.displayScale ?? 1, n.chrome && (D = n.chrome), y === "browse" && (A = null), J = n.tool, xe = n.color, I = n.targets, T = n.marks, Ee = n.activeTarget, ce = n.activeTargets ?? (n.activeTarget ? [n.activeTarget] : []), le = n.activeMarks ?? T.map((i) => i.id), document.documentElement.style.touchAction = y === "annotate" ? "none" : fe, w()), n.type === "values") {
392
- V = n.values, de = n.source;
393
- try {
394
- Pe();
395
- } catch (i) {
396
- v({ type: "error", message: String(i) });
397
- }
398
- }
399
- if (n.type === "select") {
400
- const i = ee(n.target);
401
- i.element && (i.element.scrollIntoView({ block: "nearest", inline: "nearest" }), re(i.element));
402
- }
403
- if (n.type === "reveal-target" && ee(n.target).element?.scrollIntoView({ block: "nearest", inline: "nearest" }), n.type === "restore-context" && n.context.pageId === S()) {
404
- for (const i of n.context.scrollers) ee(i.target).element?.scrollTo(i.x, i.y);
405
- window.scrollTo(n.context.scroll.x, n.context.scroll.y), w();
406
- }
407
- if (n.type === "navigate") {
408
- const i = new URL(n.path, a.origin);
409
- i.origin === a.origin && a.pages.some((l) => l.path === n.path) && location.assign(i);
410
- }
411
- n.type === "capture" && st(n.requestId);
412
- }
413
- function j() {
414
- return p && y !== "browse";
415
- }
416
- function Re(e) {
417
- return e.composedPath().find((r) => r instanceof Element && r !== E && !E.contains(r));
418
- }
419
- function Ue(e) {
420
- if (!j() || e.button !== 0) return;
421
- e.preventDefault(), e.stopImmediatePropagation();
422
- const r = Re(e);
423
- if (!r) return;
424
- if (E.focus({ preventScroll: !0 }), y === "select") {
425
- re(r, e.shiftKey);
426
- return;
427
- }
428
- const n = { x: e.clientX, y: e.clientY };
429
- H = void 0;
430
- for (const i of [...T].reverse().filter((l) => l.pageId === S() && le.includes(l.id))) {
431
- const l = Ye(i, I, { x: scrollX, y: scrollY });
432
- if (!l) continue;
433
- const u = I.find((f) => f.key === i.targetKey)?.clip;
434
- if (u && (n.x < u.x || n.y < u.y || n.x > u.x + u.width || n.y > u.y + u.height)) continue;
435
- const g = (e.pointerType === "touch" ? 22 : 16) / ae, h = [0, l.length - 1].find((f) => Math.hypot(l[f].x - n.x, l[f].y - n.y) <= g);
436
- if (h !== void 0) {
437
- b = structuredClone(i), H = h, L = I.find((f) => f.key === i.targetKey);
438
- break;
439
- }
440
- }
441
- if (!b) {
442
- L = J === "note" ? P(r) : I.find((l) => l.key === Ee && !["missing", "ambiguous"].includes(l.status));
443
- const i = Be(n, L, { x: scrollX, y: scrollY });
444
- b = { id: crypto.randomUUID(), tool: J, color: xe, width: 2, points: [i, i], targetKey: L?.key, pageId: S(), viewport: { width: innerWidth, height: innerHeight } };
445
- }
446
- z = e.pointerId, G = r;
447
- try {
448
- r.setPointerCapture(e.pointerId);
449
- } catch {
450
- }
451
- w();
452
- }
453
- function ze(e) {
454
- if (j()) {
455
- if (b && e.pointerId === z) {
456
- e.preventDefault(), e.stopImmediatePropagation();
457
- const r = Be({ x: e.clientX, y: e.clientY }, L, { x: scrollX, y: scrollY });
458
- H !== void 0 ? b.points[H] = r : b.tool === "pen" ? b.points.length < 1e4 && b.points.push(r) : b.points[b.points.length - 1] = r;
459
- } else {
460
- const r = Re(e);
461
- A = r ? P(r) : null;
462
- }
463
- w();
464
- }
465
- }
466
- function De(e) {
467
- j() && (e.preventDefault(), e.stopImmediatePropagation(), b && e.pointerId === z && (v({ type: "mark", mark: b, target: L, context: me() }), T = [...T.filter((r) => r.id !== b.id), b], R()));
468
- }
469
- function R() {
470
- if (G && z !== void 0)
471
- try {
472
- G.releasePointerCapture(z);
473
- } catch {
474
- }
475
- b = null, z = void 0, G = null, L = void 0, H = void 0, w();
476
- }
477
- function ie(e) {
478
- !j() || e.relatedTarget || !A || (A = null, w());
479
- }
480
- function Fe() {
481
- R(), A && (A = null, w());
482
- }
483
- function je(e) {
484
- j() && (e.preventDefault(), e.stopImmediatePropagation());
485
- }
486
- function We(e) {
487
- if (!j()) return;
488
- if (e.key === "Escape") {
489
- R(), A = null, y = "browse", document.documentElement.style.touchAction = fe, v({ type: "exit-tool" }), w(), e.preventDefault();
490
- return;
491
- }
492
- if (e.key.toLowerCase() === "c" && !e.metaKey && !e.ctrlKey && !e.altKey && K?.isConnected) {
493
- e.preventDefault(), e.stopImmediatePropagation(), v({ type: "comment", target: P(K) });
494
- return;
495
- }
496
- if ((e.metaKey || e.ctrlKey) && ["z", "y"].includes(e.key.toLowerCase())) {
497
- e.preventDefault(), e.stopImmediatePropagation(), v({ type: "history", direction: e.shiftKey || e.key === "y" ? "redo" : "undo" });
498
- return;
499
- }
500
- const r = K?.isConnected ? K : document.body, n = e.key === "ArrowUp" ? r.parentElement : e.key === "ArrowDown" ? r.firstElementChild : e.key === "ArrowRight" ? r.nextElementSibling : e.key === "ArrowLeft" ? r.previousElementSibling : null;
501
- n && n !== E && (e.preventDefault(), e.stopImmediatePropagation(), re(n)), e.key === "Enter" && (e.preventDefault(), re(r));
502
- }
503
- const _e = new MutationObserver((e) => {
504
- !p || e.every((r) => r.target === E || E.contains(r.target)) || (Ne(), w());
505
- });
506
- _e.observe(document.documentElement, { subtree: !0, childList: !0, attributes: !0, characterData: !0 });
507
- const Ke = new ResizeObserver(w);
508
- Ke.observe(document.documentElement), window.addEventListener("message", Oe), window.addEventListener("scroll", w, !0), window.addEventListener("resize", w), window.addEventListener("pointerdown", Ue, !0), window.addEventListener("pointermove", ze, !0), window.addEventListener("pointerup", De, !0), window.addEventListener("pointercancel", R, !0), window.addEventListener("click", je, !0), window.addEventListener("keydown", We, !0), window.addEventListener("blur", Fe), window.addEventListener("pointerout", ie, !0), window.addEventListener("pointerleave", ie, !0);
509
- const at = () => {
510
- const e = location.ancestorOrigins?.[0];
511
- if (qe(e)) return e;
512
- try {
513
- return document.referrer ? new URL(document.referrer).origin : void 0;
514
- } catch {
515
- return;
516
- }
517
- };
518
- window.parent.postMessage(ft(a.id, x), at() ?? "*");
519
- let He = S();
520
- const ct = setInterval(() => {
521
- p && (He !== S() && (He = S(), ne(), Ce(), Pe(), Te()), w());
522
- }, 750), ye = {
523
- dispose() {
524
- q === ye && (q = null), ue = !0, R(), ne(), document.documentElement.style.touchAction = fe, E.remove(), _e.disconnect(), Ke.disconnect(), clearInterval(ct), cancelAnimationFrame(Z), window.removeEventListener("message", Oe), window.removeEventListener("scroll", w, !0), window.removeEventListener("resize", w), window.removeEventListener("pointerdown", Ue, !0), window.removeEventListener("pointermove", ze, !0), window.removeEventListener("pointerup", De, !0), window.removeEventListener("pointercancel", R, !0), window.removeEventListener("click", je, !0), window.removeEventListener("keydown", We, !0), window.removeEventListener("blur", Fe), window.removeEventListener("pointerout", ie, !0), window.removeEventListener("pointerleave", ie, !0);
525
- }
526
- };
527
- return q = ye, ye;
247
+ function b({ manifest: e, hostOrigin: t = oe, adapters: n = {} }) {
248
+ let r = a(e), i = typeof t == "string" ? [t] : [...t];
249
+ if (!i.length || i.some((e) => !se(e))) return console.warn(`ParamRig: hostOrigin must be one or more workbench origins such as "http://localhost:5174", but is ${JSON.stringify(t)}. The page is left untouched.`), ce();
250
+ if (r.origin !== location.origin) return console.warn(`ParamRig: this page is at ${location.origin} and .paramrig/manifest.json declares ${r.origin}. Open the page at the manifest origin, or set the manifest's "origin" to ${location.origin}. The page is left untouched.`), ce();
251
+ if (window.parent === window) return ce();
252
+ m && (console.warn("ParamRig: connectWeb was called again before the previous connection was disposed. The previous one is replaced; call dispose() in the effect cleanup and in the hot-reload handler."), m.dispose());
253
+ let o = "", s = "", c = crypto.randomUUID(), l = "browse", u = "note", d = "#df7757", p = 1, h, g = [], _ = [], v = [], y = [], b = null, x = null, S = null, C, w, T, E = null, D = null, O = !1, k = !1, A = 0, ue = "", de = "", j = "", fe = [], M = {
254
+ outline: "#488a99",
255
+ chip: "#1e2423",
256
+ chipText: "#eef2f1"
257
+ }, N = document.documentElement.style.touchAction, P = /* @__PURE__ */ new Map(), F = /* @__PURE__ */ new Map(), I = Object.fromEntries(r.parameters.map((e) => [e.id, structuredClone(e.defaultValue)])), L = "http://www.w3.org/2000/svg", R = document.createElement("paramrig-overlay");
258
+ R.tabIndex = -1, R.setAttribute("aria-label", "Page selection. Use arrow keys to select ancestors, children and siblings."), Object.assign(R.style, {
259
+ position: "fixed",
260
+ inset: "0",
261
+ pointerEvents: "none",
262
+ zIndex: "2147483647",
263
+ contain: "strict",
264
+ outline: "none"
265
+ });
266
+ let pe = R.attachShadow({ mode: "closed" }), z = document.createElementNS(L, "svg");
267
+ z.setAttribute("width", "100%"), z.setAttribute("height", "100%"), z.style.overflow = "visible", pe.append(z);
268
+ let B = () => r.pages.find((e) => new URL(e.path, r.origin).pathname === location.pathname)?.id ?? location.pathname, me = (e) => `id:${encodeURIComponent(B())}:${encodeURIComponent(e.id)}:${encodeURIComponent(e.instance ?? "")}`, V = (e) => {
269
+ let t = e.getAttribute("data-paramrig-id");
270
+ if (!t) return;
271
+ let n = e.getAttribute("data-paramrig-instance") ?? e.closest("[data-paramrig-instance]")?.getAttribute("data-paramrig-instance") ?? void 0;
272
+ return {
273
+ id: t,
274
+ ...n ? { instance: n } : {}
275
+ };
276
+ }, H = (e, t = !1) => [...document.querySelectorAll(`[data-paramrig-id="${CSS.escape(e.id)}"]`)].filter((n) => !t && e.instance === void 0 || V(n)?.instance === e.instance);
277
+ function he(e) {
278
+ let t = [], n = e;
279
+ for (; n && n !== document.documentElement;) {
280
+ if (n.id && document.querySelectorAll(`#${CSS.escape(n.id)}`).length === 1) {
281
+ t.unshift(`#${CSS.escape(n.id)}`);
282
+ break;
283
+ }
284
+ let e = n.parentElement ? [...n.parentElement.children].filter((e) => e.tagName === n.tagName) : [];
285
+ t.unshift(`${n.localName}:nth-of-type(${e.indexOf(n) + 1})`), n = n.parentElement;
286
+ }
287
+ return t.join(" > ") || "html";
288
+ }
289
+ let ge = (e) => `${e.localName}|${e.getAttribute("role") ?? ""}|${e.getAttribute("aria-label") ?? ""}|${(e.textContent ?? "").trim().replace(/\s+/g, " ").slice(0, 160)}`, _e = (e) => {
290
+ let t = e.replace(/[-_]+/g, " ").trim();
291
+ return t ? t[0].toUpperCase() + t.slice(1) : "";
292
+ }, ve = (e) => {
293
+ let t = e.getAttribute("data-paramrig-label");
294
+ if (t) return t.slice(0, 90);
295
+ let n = e.getAttribute("data-paramrig-id");
296
+ if (n && _e(n)) return _e(n).slice(0, 60);
297
+ let r = e.getAttribute("aria-label");
298
+ return r ? r.slice(0, 90) : ((e.matches("a,button,p,h1,h2,h3,h4,h5,h6,label,span,li,em,strong,small,figcaption,summary,td,th,dt,dd,legend") ? (e.textContent ?? "").trim().replace(/\s+/g, " ") : "") || `Unnamed ${e.localName}`).slice(0, 60);
299
+ }, ye = (e) => {
300
+ let t = V(e);
301
+ return t ? new Set(r.bindings.filter((e) => J(e) && e.scope === "element" && e.target?.id === t.id && (e.target.instance === void 0 || e.target.instance === t.instance)).map((e) => e.paramId)).size : 0;
302
+ };
303
+ function U(e, t = !0) {
304
+ let n = V(e), r = he(e), i = n ? me(n) : `dom:${B()}:${r}`, a = e.getBoundingClientRect(), o = 0, s = 0, c = innerWidth, l = innerHeight;
305
+ for (let t = e.parentElement; t; t = t.parentElement) {
306
+ let e = getComputedStyle(t), n = t.getBoundingClientRect();
307
+ /(auto|scroll|hidden|clip)/.test(e.overflowX) && (o = Math.max(o, n.left), c = Math.min(c, n.right)), /(auto|scroll|hidden|clip)/.test(e.overflowY) && (s = Math.max(s, n.top), l = Math.min(l, n.bottom));
308
+ }
309
+ let u = {
310
+ x: o,
311
+ y: s,
312
+ width: Math.max(0, c - o),
313
+ height: Math.max(0, l - s)
314
+ }, d = e.closest("[data-paramrig-source]")?.getAttribute("data-paramrig-source");
315
+ P.set(i, e);
316
+ let f = [];
317
+ if (t) {
318
+ let t = e.parentElement;
319
+ for (; t && f.length < 12;) {
320
+ let e = V(t), n = e ? me(e) : `dom:${B()}:${he(t)}`;
321
+ P.set(n, t), f.push({
322
+ key: n,
323
+ label: ve(t),
324
+ stable: e
325
+ }), t = t.parentElement;
326
+ }
327
+ }
328
+ return {
329
+ key: i,
330
+ stable: n,
331
+ selector: r,
332
+ fingerprint: ge(e),
333
+ label: ve(e),
334
+ tag: e.localName,
335
+ ...d ? { source: d } : {},
336
+ pageId: B(),
337
+ rect: {
338
+ x: a.x,
339
+ y: a.y,
340
+ width: a.width,
341
+ height: a.height
342
+ },
343
+ clip: u,
344
+ ancestors: f,
345
+ controls: ye(e),
346
+ status: n ? H(n, !0).length === 1 ? "resolved" : "ambiguous" : "provisional"
347
+ };
348
+ }
349
+ function W(e) {
350
+ if (e.pageId !== B()) return { target: {
351
+ ...e,
352
+ status: "missing"
353
+ } };
354
+ if (e.stable) {
355
+ let t = H(e.stable, !0);
356
+ return t.length === 1 ? {
357
+ element: t[0],
358
+ target: {
359
+ ...U(t[0]),
360
+ key: e.key
361
+ }
362
+ } : { target: {
363
+ ...e,
364
+ status: t.length ? "ambiguous" : "missing"
365
+ } };
366
+ }
367
+ let t = P.get(e.key);
368
+ return t?.isConnected ? {
369
+ element: t,
370
+ target: {
371
+ ...U(t),
372
+ key: e.key
373
+ }
374
+ } : { target: {
375
+ ...e,
376
+ status: "missing"
377
+ } };
378
+ }
379
+ function be() {
380
+ let e = [...document.querySelectorAll("[data-paramrig-id]")].slice(0, 200), t = `${B()}|${e.map((e) => `${e.getAttribute("data-paramrig-id")}/${V(e)?.instance ?? ""}`).join(",")}`;
381
+ return t !== j && (j = t, fe = e.map((e) => U(e, !1))), fe;
382
+ }
383
+ function G() {
384
+ let e = [];
385
+ for (let t of document.querySelectorAll("[data-paramrig-id]")) (t.scrollTop || t.scrollLeft) && e.push({
386
+ target: U(t, !1),
387
+ x: t.scrollLeft,
388
+ y: t.scrollTop
389
+ });
390
+ return {
391
+ pageId: B(),
392
+ url: location.href,
393
+ viewport: {
394
+ width: innerWidth,
395
+ height: innerHeight,
396
+ dpr: devicePixelRatio
397
+ },
398
+ scroll: {
399
+ x: scrollX,
400
+ y: scrollY
401
+ },
402
+ scrollers: e
403
+ };
404
+ }
405
+ function K(e) {
406
+ o && s && !k && window.parent.postMessage(f(o, e), s);
407
+ }
408
+ function xe() {
409
+ z.replaceChildren(), delete R.dataset.hover;
410
+ let e = (e) => {
411
+ if (!e?.clip) return z;
412
+ let t = document.createElementNS(L, "clipPath"), n = document.createElementNS(L, "rect"), r = `paramrig-clip-${z.childElementCount}`;
413
+ t.id = r;
414
+ for (let t of [
415
+ "x",
416
+ "y",
417
+ "width",
418
+ "height"
419
+ ]) n.setAttribute(t, String(e.clip[t]));
420
+ t.append(n), z.append(t);
421
+ let i = document.createElementNS(L, "g");
422
+ return i.setAttribute("clip-path", `url(#${r})`), z.append(i), i;
423
+ }, t = l === "browse" ? [] : [b, ...v.filter((e) => g.includes(e.key))];
424
+ for (let n of t.filter((e) => !!e && !["missing", "ambiguous"].includes(e.status))) {
425
+ let t = e(n), r = document.createElementNS(L, "rect");
426
+ for (let e of [
427
+ "x",
428
+ "y",
429
+ "width",
430
+ "height"
431
+ ]) r.setAttribute(e, String(n.rect[e]));
432
+ r.setAttribute("fill", `${M.outline.slice(0, 7)}14`), r.setAttribute("stroke", M.outline), r.setAttribute("stroke-width", "1.5"), t.append(r), n === b && Se(t, n);
433
+ }
434
+ for (let t of [...y.filter((e) => e.id !== S?.id), ...S ? [S] : []]) {
435
+ if (t.pageId !== B()) continue;
436
+ let n = re(t, [...v, ...C ? [C] : []], {
437
+ x: scrollX,
438
+ y: scrollY
439
+ });
440
+ if (!n) continue;
441
+ let r = e(t.targetKey ? [...v, ...C ? [C] : []].find((e) => e.key === t.targetKey) : void 0), i = document.createElementNS(L, "path"), a = l !== "annotate" || _.includes(t.id);
442
+ if (i.setAttribute("d", ae(t, n)), i.setAttribute("stroke", t.color), i.setAttribute("stroke-width", String(t.width)), i.setAttribute("stroke-linecap", "round"), i.setAttribute("stroke-linejoin", "round"), i.setAttribute("fill", t.tool === "highlight" ? `${t.color}33` : t.tool === "note" ? t.color : "none"), r.append(i), a || i.setAttribute("opacity", ".35"), l === "annotate" && a) for (let e of [n[0], n.at(-1)].filter((e) => !!e)) {
443
+ let n = document.createElementNS(L, "circle");
444
+ n.setAttribute("cx", String(e.x)), n.setAttribute("cy", String(e.y)), n.setAttribute("r", "3"), n.setAttribute("fill", t.color), r.append(n);
445
+ }
446
+ }
447
+ }
448
+ function Se(e, t) {
449
+ let n = 1 / Math.max(.05, p), r = 11 * n, i = 18 * n, a = 6 * n, o = t.controls ? `${t.label} · ${t.controls} control${t.controls === 1 ? "" : "s"}` : t.label;
450
+ R.dataset.hover = o;
451
+ let s = document.createElementNS(L, "rect"), c = document.createElementNS(L, "text");
452
+ c.textContent = o, c.setAttribute("font-family", "system-ui, -apple-system, Segoe UI, sans-serif"), c.setAttribute("font-size", String(r)), c.setAttribute("fill", M.chipText), c.setAttribute("dominant-baseline", "central"), e.append(s, c);
453
+ let l = Math.min((c.getComputedTextLength?.() ?? o.length * r * .55) + a * 2, innerWidth), u = Math.max(0, Math.min(innerWidth - l, t.rect.x)), d = t.rect.y - i - 2 * n >= 0 ? t.rect.y - i - 2 * n : Math.min(innerHeight - i, t.rect.y + 2 * n);
454
+ for (let [e, t] of [
455
+ ["x", u],
456
+ ["y", d],
457
+ ["width", l],
458
+ ["height", i],
459
+ ["rx", 3 * n]
460
+ ]) s.setAttribute(e, String(t));
461
+ s.setAttribute("fill", M.chip), s.setAttribute("stroke", M.outline), s.setAttribute("stroke-width", String(n)), c.setAttribute("x", String(u + a)), c.setAttribute("y", String(d + i / 2));
462
+ }
463
+ function Ce() {
464
+ if (A = 0, !o || k) return;
465
+ if (v = v.map((e) => W(e).target), b) {
466
+ let e = P.get(b.key);
467
+ b = e?.isConnected ? U(e) : null;
468
+ }
469
+ let e = JSON.stringify([
470
+ b,
471
+ v,
472
+ g,
473
+ y,
474
+ S,
475
+ l,
476
+ scrollX,
477
+ scrollY
478
+ ]);
479
+ e !== de && (xe(), de = e);
480
+ let t = G(), n = be(), r = JSON.stringify([
481
+ t,
482
+ v,
483
+ j
484
+ ]);
485
+ r !== ue && (ue = r, K({
486
+ type: "scene",
487
+ context: t,
488
+ targets: v,
489
+ page: n
490
+ })), !document.hidden && (l !== "browse" || y.length > 0 || v.length > 0) && q();
491
+ }
492
+ function q() {
493
+ !A && o && (A = requestAnimationFrame(Ce));
494
+ }
495
+ function we(e) {
496
+ return e.target ? H(e.target) : [document.documentElement];
497
+ }
498
+ function J(e) {
499
+ return !e.pageId || e.pageId === B();
500
+ }
501
+ function Y() {
502
+ for (let [e, t] of F) if (e instanceof HTMLElement || e instanceof SVGElement) for (let [n, r] of t) r.value ? e.style.setProperty(n, r.value, r.priority) : e.style.removeProperty(n);
503
+ F.clear();
504
+ for (let e of Object.values(n)) e.restore();
505
+ }
506
+ function Te() {
507
+ for (let e of r.bindings.filter(J)) {
508
+ let t = r.parameters.find((t) => t.id === e.paramId);
509
+ if (e.kind === "adapter") {
510
+ n[e.property] && (I[e.paramId] = n[e.property].read());
511
+ continue;
512
+ }
513
+ let i = we(e)[0];
514
+ if (!i) continue;
515
+ let a = getComputedStyle(i).getPropertyValue(e.property).trim();
516
+ if (a) {
517
+ if (t.kind === "number") {
518
+ let n = le(a, e, i);
519
+ n !== void 0 && (I[t.id] = n);
520
+ } else if (t.kind === "color") {
521
+ if (/^#[\da-f]{6}([\da-f]{2})?$/i.test(a)) {
522
+ I[t.id] = a.toLowerCase();
523
+ continue;
524
+ }
525
+ let e = document.createElement("canvas").getContext("2d");
526
+ if (e) {
527
+ e.fillStyle = a, e.fillRect(0, 0, 1, 1);
528
+ let n = e.getImageData(0, 0, 1, 1).data;
529
+ I[t.id] = `#${[...n].slice(0, t.alpha ? 4 : 3).map((e) => e.toString(16).padStart(2, "0")).join("")}`;
530
+ }
531
+ } else I[t.id] = a;
532
+ }
533
+ }
534
+ }
535
+ function Ee() {
536
+ if (Y(), !D || O) {
537
+ q();
538
+ return;
539
+ }
540
+ for (let e of r.bindings.filter(J)) {
541
+ let t = D[e.paramId];
542
+ if (t !== void 0 && JSON.stringify(t) !== JSON.stringify(I[e.paramId]) && e.kind === "adapter") {
543
+ if (!n[e.property]) {
544
+ K({
545
+ type: "error",
546
+ message: `Missing adapter: ${e.property}`
547
+ });
548
+ continue;
549
+ }
550
+ n[e.property].apply(t);
551
+ }
552
+ }
553
+ De(), q();
554
+ }
555
+ function De() {
556
+ if (D && !O) {
557
+ for (let [e] of F) e.isConnected || F.delete(e);
558
+ for (let e of r.bindings.filter((e) => J(e) && e.kind !== "adapter")) {
559
+ let t = D[e.paramId];
560
+ if (t !== void 0 && JSON.stringify(t) !== JSON.stringify(I[e.paramId]) && (typeof t == "string" || typeof t == "number")) {
561
+ for (let n of we(e)) if (n instanceof HTMLElement || n instanceof SVGElement) {
562
+ let r = F.get(n) ?? /* @__PURE__ */ new Map();
563
+ r.has(e.property) || r.set(e.property, {
564
+ value: n.style.getPropertyValue(e.property),
565
+ priority: n.style.getPropertyPriority(e.property)
566
+ }), F.set(n, r);
567
+ let i = `${t}${e.unit ?? ""}`, a = document.createElement("span").style;
568
+ a.setProperty(e.property, i, "important");
569
+ let o = a.getPropertyValue(e.property);
570
+ o && (n.style.getPropertyValue(e.property) !== o || n.style.getPropertyPriority(e.property) !== a.getPropertyPriority(e.property)) && n.style.setProperty(e.property, o, "important");
571
+ }
572
+ }
573
+ }
574
+ }
575
+ }
576
+ function Oe() {
577
+ K({
578
+ type: "ready",
579
+ instanceId: c,
580
+ manifest: r,
581
+ sourceValues: I,
582
+ context: G()
583
+ }), q();
584
+ }
585
+ function X(e, t = !1) {
586
+ x = e, b = U(e), K({
587
+ type: "selection",
588
+ target: b,
589
+ additive: t
590
+ }), q();
591
+ }
592
+ async function ke(e) {
593
+ try {
594
+ let { toPng: t } = await import("./es-DC0_iRTj.js");
595
+ K({
596
+ type: "capture",
597
+ requestId: e,
598
+ dataUrl: await t(document.documentElement, {
599
+ filter: (e) => e !== R,
600
+ pixelRatio: 1,
601
+ width: innerWidth,
602
+ height: innerHeight,
603
+ style: {
604
+ transform: `translate(${-scrollX}px, ${-scrollY}px)`,
605
+ transformOrigin: "0 0"
606
+ }
607
+ })
608
+ });
609
+ } catch (t) {
610
+ K({
611
+ type: "capture",
612
+ requestId: e,
613
+ error: t instanceof Error ? t.message : "DOM capture is unavailable."
614
+ });
615
+ }
616
+ }
617
+ function Ae(e) {
618
+ if (e.source !== window.parent || !te(e.data) || (s ? e.origin !== s : !i.includes(e.origin))) return;
619
+ let t = e.data;
620
+ if (t.payload.type === "hello") {
621
+ if (t.payload.projectId !== r.id) return;
622
+ if (t.version !== 1) {
623
+ window.parent.postMessage(f(t.sessionId, {
624
+ type: "error",
625
+ message: "Incompatible web protocol. Update the project integration."
626
+ }), e.origin);
627
+ return;
628
+ }
629
+ if (s = e.origin, o !== t.sessionId) {
630
+ o = t.sessionId;
631
+ try {
632
+ Y(), Te();
633
+ } catch (e) {
634
+ K({
635
+ type: "error",
636
+ message: `Cannot read the source controls: ${String(e)}`
637
+ });
638
+ return;
639
+ }
640
+ R.isConnected || document.documentElement.append(R);
641
+ }
642
+ Oe();
643
+ return;
644
+ }
645
+ if (t.sessionId !== o || t.version !== 1 || !ne(t.payload)) return;
646
+ let n = t.payload;
647
+ if (n.type === "configure" && ((n.mode !== l || n.tool !== u) && Q(), l = n.mode, p = n.displayScale ?? 1, n.chrome && (M = n.chrome), l === "browse" && (b = null), u = n.tool, d = n.color, v = n.targets, y = n.marks, h = n.activeTarget, g = n.activeTargets ?? (n.activeTarget ? [n.activeTarget] : []), _ = n.activeMarks ?? y.map((e) => e.id), document.documentElement.style.touchAction = l === "annotate" ? "none" : N, q()), n.type === "values") {
648
+ D = n.values, O = n.source;
649
+ try {
650
+ Ee();
651
+ } catch (e) {
652
+ K({
653
+ type: "error",
654
+ message: String(e)
655
+ });
656
+ }
657
+ }
658
+ if (n.type === "select") {
659
+ let e = W(n.target);
660
+ e.element && (e.element.scrollIntoView({
661
+ block: "nearest",
662
+ inline: "nearest"
663
+ }), X(e.element));
664
+ }
665
+ if (n.type === "reveal-target" && W(n.target).element?.scrollIntoView({
666
+ block: "nearest",
667
+ inline: "nearest"
668
+ }), n.type === "restore-context" && n.context.pageId === B()) {
669
+ for (let e of n.context.scrollers) W(e.target).element?.scrollTo(e.x, e.y);
670
+ window.scrollTo(n.context.scroll.x, n.context.scroll.y), q();
671
+ }
672
+ if (n.type === "navigate") {
673
+ let e = new URL(n.path, r.origin);
674
+ e.origin === r.origin && r.pages.some((e) => e.path === n.path) && location.assign(e);
675
+ }
676
+ n.type === "capture" && ke(n.requestId);
677
+ }
678
+ function Z() {
679
+ return o && l !== "browse";
680
+ }
681
+ function je(e) {
682
+ return e.composedPath().find((e) => e instanceof Element && e !== R && !R.contains(e));
683
+ }
684
+ function Me(e) {
685
+ if (!Z() || e.button !== 0) return;
686
+ e.preventDefault(), e.stopImmediatePropagation();
687
+ let t = je(e);
688
+ if (!t) return;
689
+ if (R.focus({ preventScroll: !0 }), l === "select") {
690
+ X(t, e.shiftKey);
691
+ return;
692
+ }
693
+ let n = {
694
+ x: e.clientX,
695
+ y: e.clientY
696
+ };
697
+ w = void 0;
698
+ for (let t of [...y].reverse().filter((e) => e.pageId === B() && _.includes(e.id))) {
699
+ let r = re(t, v, {
700
+ x: scrollX,
701
+ y: scrollY
702
+ });
703
+ if (!r) continue;
704
+ let i = v.find((e) => e.key === t.targetKey)?.clip;
705
+ if (i && (n.x < i.x || n.y < i.y || n.x > i.x + i.width || n.y > i.y + i.height)) continue;
706
+ let a = (e.pointerType === "touch" ? 22 : 16) / p, o = [0, r.length - 1].find((e) => Math.hypot(r[e].x - n.x, r[e].y - n.y) <= a);
707
+ if (o !== void 0) {
708
+ S = structuredClone(t), w = o, C = v.find((e) => e.key === t.targetKey);
709
+ break;
710
+ }
711
+ }
712
+ if (!S) {
713
+ C = u === "note" ? U(t) : v.find((e) => e.key === h && !["missing", "ambiguous"].includes(e.status));
714
+ let e = ie(n, C, {
715
+ x: scrollX,
716
+ y: scrollY
717
+ });
718
+ S = {
719
+ id: crypto.randomUUID(),
720
+ tool: u,
721
+ color: d,
722
+ width: 2,
723
+ points: [e, e],
724
+ targetKey: C?.key,
725
+ pageId: B(),
726
+ viewport: {
727
+ width: innerWidth,
728
+ height: innerHeight
729
+ }
730
+ };
731
+ }
732
+ T = e.pointerId, E = t;
733
+ try {
734
+ t.setPointerCapture(e.pointerId);
735
+ } catch {}
736
+ q();
737
+ }
738
+ function Ne(e) {
739
+ if (Z()) {
740
+ if (S && e.pointerId === T) {
741
+ e.preventDefault(), e.stopImmediatePropagation();
742
+ let t = ie({
743
+ x: e.clientX,
744
+ y: e.clientY
745
+ }, C, {
746
+ x: scrollX,
747
+ y: scrollY
748
+ });
749
+ w === void 0 ? S.tool === "pen" ? S.points.length < 1e4 && S.points.push(t) : S.points[S.points.length - 1] = t : S.points[w] = t;
750
+ } else {
751
+ let t = je(e);
752
+ b = t ? U(t) : null;
753
+ }
754
+ q();
755
+ }
756
+ }
757
+ function Pe(e) {
758
+ Z() && (e.preventDefault(), e.stopImmediatePropagation(), S && e.pointerId === T && (K({
759
+ type: "mark",
760
+ mark: S,
761
+ target: C,
762
+ context: G()
763
+ }), y = [...y.filter((e) => e.id !== S.id), S], Q()));
764
+ }
765
+ function Q() {
766
+ if (E && T !== void 0) try {
767
+ E.releasePointerCapture(T);
768
+ } catch {}
769
+ S = null, T = void 0, E = null, C = void 0, w = void 0, q();
770
+ }
771
+ function $(e) {
772
+ Z() && !e.relatedTarget && b && (b = null, q());
773
+ }
774
+ function Fe() {
775
+ Q(), b && (b = null, q());
776
+ }
777
+ function Ie(e) {
778
+ Z() && (e.preventDefault(), e.stopImmediatePropagation());
779
+ }
780
+ function Le(e) {
781
+ if (!Z()) return;
782
+ if (e.key === "Escape") {
783
+ Q(), b = null, l = "browse", document.documentElement.style.touchAction = N, K({ type: "exit-tool" }), q(), e.preventDefault();
784
+ return;
785
+ }
786
+ if (e.key.toLowerCase() === "c" && !e.metaKey && !e.ctrlKey && !e.altKey && x?.isConnected) {
787
+ e.preventDefault(), e.stopImmediatePropagation(), K({
788
+ type: "comment",
789
+ target: U(x)
790
+ });
791
+ return;
792
+ }
793
+ if ((e.metaKey || e.ctrlKey) && ["z", "y"].includes(e.key.toLowerCase())) {
794
+ e.preventDefault(), e.stopImmediatePropagation(), K({
795
+ type: "history",
796
+ direction: e.shiftKey || e.key === "y" ? "redo" : "undo"
797
+ });
798
+ return;
799
+ }
800
+ let t = x?.isConnected ? x : document.body, n = e.key === "ArrowUp" ? t.parentElement : e.key === "ArrowDown" ? t.firstElementChild : e.key === "ArrowRight" ? t.nextElementSibling : e.key === "ArrowLeft" ? t.previousElementSibling : null;
801
+ n && n !== R && (e.preventDefault(), e.stopImmediatePropagation(), X(n)), e.key === "Enter" && (e.preventDefault(), X(t));
802
+ }
803
+ let Re = new MutationObserver((e) => {
804
+ o && !e.every((e) => e.target === R || R.contains(e.target)) && (De(), q());
805
+ });
806
+ Re.observe(document.documentElement, {
807
+ subtree: !0,
808
+ childList: !0,
809
+ attributes: !0,
810
+ characterData: !0
811
+ });
812
+ let ze = new ResizeObserver(q);
813
+ ze.observe(document.documentElement), window.addEventListener("message", Ae), window.addEventListener("scroll", q, !0), window.addEventListener("resize", q), window.addEventListener("pointerdown", Me, !0), window.addEventListener("pointermove", Ne, !0), window.addEventListener("pointerup", Pe, !0), window.addEventListener("pointercancel", Q, !0), window.addEventListener("click", Ie, !0), window.addEventListener("keydown", Le, !0), window.addEventListener("blur", Fe), window.addEventListener("pointerout", $, !0), window.addEventListener("pointerleave", $, !0), window.parent.postMessage(ee(r.id, c), (() => {
814
+ let e = location.ancestorOrigins?.[0];
815
+ if (se(e)) return e;
816
+ try {
817
+ return document.referrer ? new URL(document.referrer).origin : void 0;
818
+ } catch {
819
+ return;
820
+ }
821
+ })() ?? "*");
822
+ let Be = B(), Ve = setInterval(() => {
823
+ o && (Be !== B() && (Be = B(), Y(), Te(), Ee(), Oe()), q());
824
+ }, 750), He = { dispose() {
825
+ m === He && (m = null), k = !0, Q(), Y(), document.documentElement.style.touchAction = N, R.remove(), Re.disconnect(), ze.disconnect(), clearInterval(Ve), cancelAnimationFrame(A), window.removeEventListener("message", Ae), window.removeEventListener("scroll", q, !0), window.removeEventListener("resize", q), window.removeEventListener("pointerdown", Me, !0), window.removeEventListener("pointermove", Ne, !0), window.removeEventListener("pointerup", Pe, !0), window.removeEventListener("pointercancel", Q, !0), window.removeEventListener("click", Ie, !0), window.removeEventListener("keydown", Le, !0), window.removeEventListener("blur", Fe), window.removeEventListener("pointerout", $, !0), window.removeEventListener("pointerleave", $, !0);
826
+ } };
827
+ return m = He, He;
528
828
  }
529
- export {
530
- wt as DEFAULT_HOST_ORIGINS,
531
- St as connectWeb,
532
- lt as parseManifest
533
- };
829
+ //#endregion
830
+ export { oe as DEFAULT_HOST_ORIGINS, b as connectWeb, a as parseManifest };