@paramrig/web 0.1.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/LICENSE +21 -0
- package/README.md +359 -0
- package/dist/index-L3Zm-CoX.js +512 -0
- package/dist/paramrig-web.js +533 -0
- package/dist/rigs/extended-types.d.ts +184 -0
- package/dist/rigs/types.d.ts +199 -0
- package/dist/web/contracts.d.ts +287 -0
- package/dist/web/geometry.d.ts +5 -0
- package/dist/web/sdk.d.ts +20 -0
- package/package.json +40 -0
- package/schemas/batch.schema.json +126 -0
- package/schemas/manifest.schema.json +83 -0
- package/schemas/response.schema.json +33 -0
|
@@ -0,0 +1,533 @@
|
|
|
1
|
+
const be = "paramrig.web";
|
|
2
|
+
function m(t) {
|
|
3
|
+
return !!t && typeof t == "object" && !Array.isArray(t);
|
|
4
|
+
}
|
|
5
|
+
function N(t) {
|
|
6
|
+
return typeof t == "string" && /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,127}$/.test(t);
|
|
7
|
+
}
|
|
8
|
+
function k(t) {
|
|
9
|
+
return typeof t == "string" && t.length > 0 && t.length <= 2e3;
|
|
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);
|
|
15
|
+
}
|
|
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);
|
|
30
|
+
}
|
|
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;
|
|
33
|
+
}
|
|
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);
|
|
37
|
+
}
|
|
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);
|
|
41
|
+
}
|
|
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));
|
|
44
|
+
}
|
|
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));
|
|
47
|
+
}
|
|
48
|
+
function Xe(t, s) {
|
|
49
|
+
return { channel: be, version: 1, sessionId: t, payload: s };
|
|
50
|
+
}
|
|
51
|
+
function ft(t, s) {
|
|
52
|
+
return { channel: be, version: 1, type: "sdk-present", projectId: t, instanceId: s };
|
|
53
|
+
}
|
|
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";
|
|
56
|
+
}
|
|
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
|
+
}
|
|
78
|
+
}
|
|
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 }));
|
|
83
|
+
}
|
|
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 };
|
|
86
|
+
}
|
|
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 };
|
|
90
|
+
}
|
|
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(" ");
|
|
103
|
+
}
|
|
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;
|
|
123
|
+
}
|
|
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;
|
|
128
|
+
}
|
|
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;
|
|
139
|
+
}
|
|
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;
|
|
528
|
+
}
|
|
529
|
+
export {
|
|
530
|
+
wt as DEFAULT_HOST_ORIGINS,
|
|
531
|
+
St as connectWeb,
|
|
532
|
+
lt as parseManifest
|
|
533
|
+
};
|