tempo-sdk 0.0.93 → 0.0.99

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.
Files changed (48) hide show
  1. package/dist/assets/index.js +3 -3
  2. package/dist/astro/asset-preview-client.js +3 -3
  3. package/dist/astro.js +2 -2
  4. package/dist/canvas/astro.js +3 -3
  5. package/dist/canvas/index.js +36 -7
  6. package/dist/canvas/index.js.map +1 -1
  7. package/dist/canvas/interact-projection.js +4 -4
  8. package/dist/canvas/svelte.js +3 -3
  9. package/dist/canvas/vue.js +3 -3
  10. package/dist/{chunk-Y7EHQREO.js → chunk-27WT3XUG.js} +2 -2
  11. package/dist/{chunk-Y7EHQREO.js.map → chunk-27WT3XUG.js.map} +1 -1
  12. package/dist/{chunk-M7OOVEAR.js → chunk-6HYKKP5N.js} +3 -2
  13. package/dist/{chunk-M7OOVEAR.js.map → chunk-6HYKKP5N.js.map} +1 -1
  14. package/dist/{chunk-N5MWY4H6.js → chunk-CYDF4LYJ.js} +2 -2
  15. package/dist/{chunk-N5MWY4H6.js.map → chunk-CYDF4LYJ.js.map} +1 -1
  16. package/dist/{chunk-XB6GU4CE.js → chunk-I7VF4ZOV.js} +48 -37
  17. package/dist/chunk-I7VF4ZOV.js.map +1 -0
  18. package/dist/{chunk-HNNZM2XM.js → chunk-MIXQVPDH.js} +461 -185
  19. package/dist/chunk-MIXQVPDH.js.map +1 -0
  20. package/dist/{chunk-GHNHPVEI.js → chunk-SGTGDLOX.js} +2 -2
  21. package/dist/{chunk-GHNHPVEI.js.map → chunk-SGTGDLOX.js.map} +1 -1
  22. package/dist/chunk-T364NBR3.js +1440 -0
  23. package/dist/chunk-T364NBR3.js.map +1 -0
  24. package/dist/{chunk-FZVJVL3T.js → chunk-X5DJKVBT.js} +10 -17
  25. package/dist/chunk-X5DJKVBT.js.map +1 -0
  26. package/dist/{chunk-CVUNZBRV.js → chunk-ZT7HJ6YU.js} +3 -3
  27. package/dist/{chunk-3L4RRKC3.js → chunk-ZW26VZHX.js} +42 -3
  28. package/dist/chunk-ZW26VZHX.js.map +1 -0
  29. package/dist/index.js +2 -2
  30. package/dist/nextjs/plugin.cjs +1 -1
  31. package/dist/nextjs/plugin.cjs.map +1 -1
  32. package/dist/nextjs/plugin.js +1 -1
  33. package/dist/nextjs-loader.cjs +1 -1
  34. package/dist/nextjs-loader.cjs.map +1 -1
  35. package/dist/nextjs.cjs +1 -1
  36. package/dist/nextjs.cjs.map +1 -1
  37. package/dist/nextjs.js +1 -1
  38. package/dist/nuxt/runtime/identity.js +1 -1
  39. package/dist/nuxt.js +1 -1
  40. package/dist/vue.js +1 -1
  41. package/package.json +1 -1
  42. package/dist/chunk-3L4RRKC3.js.map +0 -1
  43. package/dist/chunk-FZVJVL3T.js.map +0 -1
  44. package/dist/chunk-HNNZM2XM.js.map +0 -1
  45. package/dist/chunk-LEBVQBDH.js +0 -643
  46. package/dist/chunk-LEBVQBDH.js.map +0 -1
  47. package/dist/chunk-XB6GU4CE.js.map +0 -1
  48. /package/dist/{chunk-CVUNZBRV.js.map → chunk-ZT7HJ6YU.js.map} +0 -0
@@ -0,0 +1,1440 @@
1
+ // ../../modules/iframe-projection/html/faithful-css-text.ts
2
+ var CSS_RUNTIME_MUTATION = "tempo:css-runtime-mutation";
3
+ function dropsValues(cssText) {
4
+ return /: (?: !important)?;/.test(cssText) && /(?<![\w-])(?!--)-?[a-zA-Z][\w-]*: (?: !important)?;/.test(cssText);
5
+ }
6
+ var BACKSLASH = 92;
7
+ var SLASH = 47;
8
+ var STAR = 42;
9
+ var DOUBLE_QUOTE = 34;
10
+ var SINGLE_QUOTE = 39;
11
+ var OPEN_PAREN = 40;
12
+ var CLOSE_PAREN = 41;
13
+ var OPEN_BRACKET = 91;
14
+ var CLOSE_BRACKET = 93;
15
+ var OPEN_BRACE = 123;
16
+ var CLOSE_BRACE = 125;
17
+ var SEMICOLON = 59;
18
+ var SPACE = 32;
19
+ var mayStartInert = (code) => code === BACKSLASH || code === SLASH || code === DOUBLE_QUOTE || code === SINGLE_QUOTE || code === OPEN_PAREN;
20
+ function pastInert(text, index) {
21
+ const code = text.charCodeAt(index);
22
+ if (code === BACKSLASH) return index + 2;
23
+ if (code === SLASH && text.charCodeAt(index + 1) === STAR) {
24
+ const end = text.indexOf("*/", index + 2);
25
+ return end < 0 ? text.length : end + 2;
26
+ }
27
+ if (code === DOUBLE_QUOTE || code === SINGLE_QUOTE) {
28
+ let at2 = index + 1;
29
+ while (at2 < text.length && text.charCodeAt(at2) !== code)
30
+ at2 += text.charCodeAt(at2) === BACKSLASH ? 2 : 1;
31
+ return at2 + 1;
32
+ }
33
+ const isUrl = code === OPEN_PAREN && index >= 3 && text.slice(index - 3, index).toLowerCase() === "url";
34
+ if (!isUrl || /^\(\s*["']/.test(text.slice(index, index + 16))) return index;
35
+ let at = index + 1;
36
+ while (at < text.length && text.charCodeAt(at) !== CLOSE_PAREN)
37
+ at += text.charCodeAt(at) === BACKSLASH ? 2 : 1;
38
+ return at + 1;
39
+ }
40
+ var SCAN_STEP = 32 * 1024;
41
+ function* cssItems(text) {
42
+ const customProperty = /\s*--/y;
43
+ let depth = 0;
44
+ let start = 0;
45
+ let hasContent = false;
46
+ let index = 0;
47
+ let nextPause = SCAN_STEP;
48
+ function* end() {
49
+ const item = text.slice(start, index).trim();
50
+ if (item && item !== ";") yield item;
51
+ start = index;
52
+ hasContent = false;
53
+ }
54
+ while (index < text.length) {
55
+ if (index >= nextPause) {
56
+ nextPause = index + SCAN_STEP;
57
+ yield null;
58
+ }
59
+ const code = text.charCodeAt(index);
60
+ const next = mayStartInert(code) ? pastInert(text, index) : index;
61
+ if (next !== index) {
62
+ const isLeadingComment = !hasContent && depth === 0 && code === SLASH;
63
+ if (isLeadingComment) start = next;
64
+ else hasContent = true;
65
+ index = next;
66
+ continue;
67
+ }
68
+ index++;
69
+ if (code === OPEN_BRACE || code === OPEN_PAREN || code === OPEN_BRACKET) {
70
+ depth++;
71
+ hasContent = true;
72
+ } else if (code === CLOSE_BRACE || code === CLOSE_PAREN || code === CLOSE_BRACKET) {
73
+ depth = Math.max(0, depth - 1);
74
+ if (code !== CLOSE_BRACE || depth !== 0) continue;
75
+ customProperty.lastIndex = start;
76
+ if (!customProperty.test(text)) yield* end();
77
+ } else if (code === SEMICOLON && depth === 0) yield* end();
78
+ else if (code > SPACE) hasContent = true;
79
+ }
80
+ yield* end();
81
+ }
82
+ function splitCssItems(text) {
83
+ const items = [];
84
+ for (const item of cssItems(text)) if (item !== null) items.push(item);
85
+ return items;
86
+ }
87
+ function blockOpen(ruleText) {
88
+ let depth = 0;
89
+ for (let index = 0; index < ruleText.length; ) {
90
+ const code = ruleText.charCodeAt(index);
91
+ const next = mayStartInert(code) ? pastInert(ruleText, index) : index;
92
+ if (next !== index) {
93
+ index = next;
94
+ continue;
95
+ }
96
+ index++;
97
+ if (code === OPEN_BRACE && depth === 0) return index - 1;
98
+ if (code === OPEN_PAREN || code === OPEN_BRACKET) depth++;
99
+ else if (code === CLOSE_PAREN || code === CLOSE_BRACKET) depth--;
100
+ }
101
+ return -1;
102
+ }
103
+ function ruleBody(ruleText) {
104
+ const open = blockOpen(ruleText);
105
+ if (open < 0) return void 0;
106
+ return ruleText.slice(open + 1, ruleText.lastIndexOf("}"));
107
+ }
108
+ var isRuleItem = (item) => item.startsWith("@") ? !/^@charset\b/i.test(item) : item.endsWith("}") && !item.startsWith("--");
109
+ var GROUP_PRELUDE = /^@(?:media|supports|layer|container|scope|starting-style|document)\b/i;
110
+ var isGroupRule = (rule) => "cssRules" in rule && !("style" in rule) && !("appendRule" in rule);
111
+ function ownDeclarations(bodyItems) {
112
+ const firstRule = bodyItems.findIndex(isRuleItem);
113
+ return firstRule < 0 ? bodyItems : bodyItems.slice(0, firstRule);
114
+ }
115
+ function parseDeclaration(item) {
116
+ const colon = item.indexOf(":");
117
+ if (colon < 0) return null;
118
+ const name = item.slice(0, colon).trim();
119
+ let value = item.slice(colon + 1).trim();
120
+ if (value.endsWith(";")) value = value.slice(0, -1).trimEnd();
121
+ const important = /!\s*important$/i.exec(value);
122
+ if (important) value = value.slice(0, important.index).trimEnd();
123
+ return {
124
+ name: name.startsWith("--") ? name : name.toLowerCase(),
125
+ value,
126
+ important: important !== null
127
+ };
128
+ }
129
+ function* ruleTexts(text) {
130
+ for (const item of cssItems(text)) {
131
+ if (item === null || !isRuleItem(item)) {
132
+ yield null;
133
+ continue;
134
+ }
135
+ if (GROUP_PRELUDE.test(item)) {
136
+ const body = ruleBody(item);
137
+ if (body !== void 0) yield* ruleTexts(body);
138
+ continue;
139
+ }
140
+ yield item.includes("(") ? item : null;
141
+ }
142
+ }
143
+ function createCssEngine(view) {
144
+ const sheet = new view.CSSStyleSheet();
145
+ sheet.insertRule("a {}", 0);
146
+ sheet.insertRule("a {}", 1);
147
+ const probe = sheet.cssRules[0].style;
148
+ const work = sheet.cssRules[1].style;
149
+ const longhands = /* @__PURE__ */ new Map();
150
+ const longhandsOf = (property) => {
151
+ let known = longhands.get(property);
152
+ if (known === void 0) {
153
+ probe.cssText = "";
154
+ probe.setProperty(property, "inherit");
155
+ known = probe.length > 1 ? Array.from(probe) : null;
156
+ longhands.set(property, known);
157
+ }
158
+ return known;
159
+ };
160
+ return {
161
+ sheet,
162
+ probe,
163
+ work,
164
+ longhandsOf,
165
+ /** What the browser prints for a rule parsed from `text`; null when it parses to none. */
166
+ printRule(text) {
167
+ try {
168
+ const index = sheet.insertRule(text, sheet.cssRules.length);
169
+ const printed = sheet.cssRules[index].cssText;
170
+ sheet.deleteRule(index);
171
+ return printed;
172
+ } catch {
173
+ return null;
174
+ }
175
+ },
176
+ /**
177
+ * The value just written to shorthand `name`, when its longhands now wait
178
+ * on it. Right after the write every longhand waits on the same value, so
179
+ * the browser still prints it whole. Null for anything else.
180
+ */
181
+ waitingShorthand(block, name) {
182
+ const parts = longhandsOf(name);
183
+ if (!parts) return null;
184
+ const value = block.getPropertyValue(name);
185
+ const isWaiting = value !== "" && block.getPropertyValue(parts[0]) === "";
186
+ return isWaiting ? value : null;
187
+ }
188
+ };
189
+ }
190
+ var MAX_SHEET_TEXT_LENGTH = 5 * 1024 * 1024;
191
+ var INLINE_INDEX_LENGTH = 64 * 1024;
192
+ var INDEX_SLICE_MS = 4;
193
+ var FLOW_RELATIVE = /(?:^|-)(?:inline|block)(?:-|$)|-(?:start|end)-(?:start|end)-/;
194
+ var REPAIR_READY = "repairReady";
195
+ var documents = /* @__PURE__ */ new WeakMap();
196
+ function cssSourcesFor(doc) {
197
+ let sources = documents.get(doc);
198
+ if (!sources) {
199
+ sources = createCssSources(doc);
200
+ documents.set(doc, sources);
201
+ }
202
+ return sources;
203
+ }
204
+ function createCssSources(doc) {
205
+ let parsed = /* @__PURE__ */ new WeakMap();
206
+ let assigned = /* @__PURE__ */ new WeakMap();
207
+ let sheetTexts = /* @__PURE__ */ new WeakMap();
208
+ let insertedLater = /* @__PURE__ */ new WeakSet();
209
+ let editedRules = /* @__PURE__ */ new WeakSet();
210
+ let printBeforeEdit = /* @__PURE__ */ new WeakMap();
211
+ let insertTexts = /* @__PURE__ */ new WeakMap();
212
+ let insertQueue = [];
213
+ let unobservable = /* @__PURE__ */ new WeakSet();
214
+ let checkedBeforeChange = /* @__PURE__ */ new WeakSet();
215
+ let awaitingDeclarations = /* @__PURE__ */ new WeakSet();
216
+ let trusted = false;
217
+ let preexisting = /* @__PURE__ */ new WeakSet();
218
+ let everStopped = false;
219
+ let writesUnreported = false;
220
+ let reader;
221
+ const linkReads = /* @__PURE__ */ new WeakSet();
222
+ const indexes = /* @__PURE__ */ new WeakMap();
223
+ let engine;
224
+ const engineOrNull = () => {
225
+ if (engine !== void 0) return engine;
226
+ engine = null;
227
+ try {
228
+ const candidate = createCssEngine(
229
+ doc.defaultView
230
+ );
231
+ candidate.work.cssText = "margin: var(--m); margin-top: 0";
232
+ if (dropsValues(candidate.work.cssText)) engine = candidate;
233
+ } catch {
234
+ }
235
+ return engine;
236
+ };
237
+ const isScratch = (rule) => engine != null && rule.parentStyleSheet === engine.sheet;
238
+ const announceRepair = (sheet) => {
239
+ const view = doc.defaultView;
240
+ if (!view) return;
241
+ doc.dispatchEvent(
242
+ new view.CustomEvent(CSS_RUNTIME_MUTATION, {
243
+ detail: {
244
+ ownerNode: sheet.ownerNode,
245
+ sheet,
246
+ mutable: false,
247
+ [REPAIR_READY]: true
248
+ }
249
+ })
250
+ );
251
+ };
252
+ const addToIndex = (css, byPrint, chunk) => {
253
+ const print = css.printRule(chunk);
254
+ if (print === null || !dropsValues(print)) return;
255
+ const known = byPrint.get(print);
256
+ byPrint.set(print, known === void 0 || known === chunk ? chunk : null);
257
+ };
258
+ const indexFor = (css, sheet, text) => {
259
+ const known = indexes.get(sheet);
260
+ if (known?.text === text) return known.byPrint ?? void 0;
261
+ const byPrint = /* @__PURE__ */ new Map();
262
+ if (text.length <= INLINE_INDEX_LENGTH) {
263
+ for (const chunk of ruleTexts(text))
264
+ if (chunk !== null) addToIndex(css, byPrint, chunk);
265
+ indexes.set(sheet, { text, byPrint });
266
+ return byPrint;
267
+ }
268
+ const entry = { text, byPrint: null };
269
+ indexes.set(sheet, entry);
270
+ const chunks = ruleTexts(text);
271
+ const view = doc.defaultView;
272
+ const step = () => {
273
+ if (indexes.get(sheet) !== entry) return;
274
+ const deadline = performance.now() + INDEX_SLICE_MS;
275
+ for (; ; ) {
276
+ const next = chunks.next();
277
+ if (next.done) {
278
+ entry.byPrint = byPrint;
279
+ announceRepair(sheet);
280
+ return;
281
+ }
282
+ if (next.value !== null) addToIndex(css, byPrint, next.value);
283
+ if (performance.now() >= deadline) break;
284
+ }
285
+ view?.setTimeout(step, 0);
286
+ };
287
+ view?.setTimeout(step, 0);
288
+ return void 0;
289
+ };
290
+ const readLinkText = (sheet) => {
291
+ const link = sheet.ownerNode;
292
+ const url = sheet.href;
293
+ if (!reader || !url || link?.tagName !== "LINK" || linkReads.has(sheet))
294
+ return;
295
+ linkReads.add(sheet);
296
+ let reading;
297
+ try {
298
+ reading = Promise.resolve(reader(url));
299
+ } catch {
300
+ return;
301
+ }
302
+ reading.then(
303
+ (text) => {
304
+ const isCurrent = typeof text === "string" && text.length <= MAX_SHEET_TEXT_LENGTH && link.sheet === sheet;
305
+ if (!isCurrent) return;
306
+ sheetTexts.set(sheet, text);
307
+ announceRepair(sheet);
308
+ },
309
+ () => {
310
+ }
311
+ );
312
+ };
313
+ const sheetTextOf = (sheet) => {
314
+ let text = sheetTexts.get(sheet);
315
+ const owner = sheet.ownerNode;
316
+ if (text === void 0 && owner?.tagName === "STYLE") {
317
+ text = owner.textContent ?? "";
318
+ sheetTexts.set(sheet, text);
319
+ }
320
+ if (text === void 0) readLinkText(sheet);
321
+ return text !== void 0 && text.length <= MAX_SHEET_TEXT_LENGTH ? text : void 0;
322
+ };
323
+ const note = (css, entries, block, name) => {
324
+ const value = css.waitingShorthand(block, name);
325
+ entries.delete(name);
326
+ if (value === null) return;
327
+ const important = block.getPropertyPriority(name) === "important";
328
+ entries.set(name, { value, important });
329
+ };
330
+ const seedAssignments = (rule, declarations) => {
331
+ const css = engineOrNull();
332
+ if (!css) return;
333
+ const seeds = /* @__PURE__ */ new Map();
334
+ css.work.cssText = "";
335
+ for (const item of declarations) {
336
+ const declaration = parseDeclaration(item);
337
+ if (!declaration) continue;
338
+ const priority = declaration.important ? "important" : "";
339
+ css.work.setProperty(declaration.name, declaration.value, priority);
340
+ if (!declaration.name.startsWith("--"))
341
+ note(css, seeds, css.work, declaration.name);
342
+ }
343
+ if (!seeds.size) return;
344
+ assigned.set(rule, new Map([...seeds, ...assigned.get(rule) ?? []]));
345
+ };
346
+ const assignmentsOf = (rule) => {
347
+ const source = parsed.get(rule);
348
+ if (source && !source.seeded) {
349
+ source.seeded = true;
350
+ const body = ruleBody(source.text);
351
+ if (body !== void 0)
352
+ seedAssignments(rule, ownDeclarations(splitCssItems(body)));
353
+ }
354
+ return assigned.get(rule);
355
+ };
356
+ const settleInsert = (rule) => {
357
+ const text = insertTexts.get(rule);
358
+ if (text === void 0) return;
359
+ insertTexts.delete(rule);
360
+ if (!editedRules.has(rule) && !parsed.has(rule) && dropsValues(rule.cssText))
361
+ parsed.set(rule, { text });
362
+ };
363
+ const settleInsertsLater = () => {
364
+ if (insertQueue.length !== 1) return;
365
+ const view = doc.defaultView;
366
+ const step = () => {
367
+ const deadline = performance.now() + INDEX_SLICE_MS;
368
+ while (insertQueue.length && performance.now() < deadline)
369
+ settleInsert(insertQueue.shift());
370
+ if (insertQueue.length) view?.setTimeout(step, 0);
371
+ };
372
+ view?.setTimeout(step, 0);
373
+ };
374
+ const cameFromInsert = (rule) => {
375
+ for (let at = rule; at; at = at.parentRule)
376
+ if (insertedLater.has(at)) return true;
377
+ return false;
378
+ };
379
+ const sourceOf = (css, rule) => {
380
+ if (!trusted || unobservable.has(rule)) return void 0;
381
+ settleInsert(rule);
382
+ const known = parsed.get(rule);
383
+ if (known) return known;
384
+ if (isGroupRule(rule) || cameFromInsert(rule)) return void 0;
385
+ const print = editedRules.has(rule) ? printBeforeEdit.get(rule) : rule.cssText;
386
+ const sheet = rule.parentStyleSheet;
387
+ if (print === void 0 || !dropsValues(print) || !sheet) return void 0;
388
+ if (preexisting.has(sheet)) return void 0;
389
+ const text = sheetTextOf(sheet);
390
+ if (text === void 0) return void 0;
391
+ const chunk = indexFor(css, sheet, text)?.get(print);
392
+ if (!chunk) return void 0;
393
+ const source = { text: chunk, printed: print };
394
+ parsed.set(rule, source);
395
+ return source;
396
+ };
397
+ const declarationsText = (css, rule, items) => {
398
+ const printed = items.join(" ");
399
+ const names = items.map((item) => parseDeclaration(item)?.name ?? "");
400
+ const waiting = new Set(
401
+ items.flatMap((item, at) => {
402
+ const isEmpty = parseDeclaration(item)?.value === "";
403
+ return isEmpty && !names[at].startsWith("--") ? [names[at]] : [];
404
+ })
405
+ );
406
+ const entries = waiting.size && trusted && !unobservable.has(rule) ? assignmentsOf(rule) : void 0;
407
+ if (!entries) return printed;
408
+ const placed = [];
409
+ const covered = /* @__PURE__ */ new Set();
410
+ for (const [name, entry] of [...entries].reverse()) {
411
+ const longhands = css.longhandsOf(name) ?? [];
412
+ const mine = longhands.filter(
413
+ (longhand) => waiting.has(longhand) && !covered.has(longhand)
414
+ );
415
+ if (!mine.length) continue;
416
+ for (const longhand of mine) covered.add(longhand);
417
+ const newerOverlapping = placed.filter((newer) => newer.longhands.some((l) => longhands.includes(l))).map((newer) => newer.at);
418
+ const at = Math.min(
419
+ names.findIndex((item) => longhands.includes(item)),
420
+ ...newerOverlapping
421
+ );
422
+ const priority = entry.important ? " !important" : "";
423
+ const declaration = `${name}: ${entry.value}${priority};`;
424
+ placed.push({ at, longhands, declaration });
425
+ }
426
+ const shorthandsAt = (at) => placed.filter((shorthand) => shorthand.at === at).map((shorthand) => shorthand.declaration).reverse();
427
+ if (covered.size !== waiting.size) return printed;
428
+ const candidate = items.flatMap((item, at) => [
429
+ ...shorthandsAt(at),
430
+ ...waiting.has(names[at]) ? [] : [item]
431
+ ]).join(" ");
432
+ css.work.cssText = candidate;
433
+ const reprinted = splitCssItems(css.work.cssText);
434
+ const orderDecides = names.some((name) => FLOW_RELATIVE.test(name));
435
+ const [got, want] = orderDecides ? [reprinted, items] : [reprinted.sort(), [...items].sort()];
436
+ const isSame = got.length === want.length && got.every((item, at) => item === want[at]);
437
+ return isSame ? candidate : printed;
438
+ };
439
+ const rebuild = (css, rule, printed) => {
440
+ const open = blockOpen(printed);
441
+ if (open < 0) return declarationsText(css, rule, splitCssItems(printed));
442
+ const items = splitCssItems(
443
+ printed.slice(open + 1, printed.lastIndexOf("}"))
444
+ );
445
+ const own = ownDeclarations(items);
446
+ const children = "cssRules" in rule ? Array.from(
447
+ rule.cssRules,
448
+ (child) => ruleText(child)
449
+ ) : [];
450
+ const hasUnreadChildren = own.length !== items.length && !children.length;
451
+ if (hasUnreadChildren) return printed;
452
+ const body = [declarationsText(css, rule, own), ...children];
453
+ return `${printed.slice(0, open)}{ ${body.filter(Boolean).join(" ")} }`;
454
+ };
455
+ function ruleText(rule) {
456
+ const printed = rule.cssText;
457
+ if (!dropsValues(printed)) return printed;
458
+ const css = engineOrNull();
459
+ if (!css) return printed;
460
+ const source = sourceOf(css, rule);
461
+ if (source && !editedRules.has(rule)) {
462
+ if (source.printed === void 0)
463
+ source.printed = css.printRule(source.text);
464
+ if (source.printed === printed) return source.text;
465
+ }
466
+ return rebuild(css, rule, printed);
467
+ }
468
+ const keepWholeShorthands = (css, rule, block, printed) => {
469
+ const entries = assigned.get(rule) ?? /* @__PURE__ */ new Map();
470
+ for (const item of ownDeclarations(
471
+ splitCssItems(ruleBody(printed) ?? "")
472
+ )) {
473
+ const name = parseDeclaration(item)?.name;
474
+ if (name && !name.startsWith("--")) note(css, entries, block, name);
475
+ }
476
+ if (entries.size) assigned.set(rule, entries);
477
+ };
478
+ const beforeFirstChange = (rule, block) => {
479
+ settleInsert(rule);
480
+ if (!("style" in rule) || parsed.has(rule)) return;
481
+ const printed = rule.cssText;
482
+ if (dropsValues(printed)) {
483
+ printBeforeEdit.set(rule, printed);
484
+ return;
485
+ }
486
+ if (!printed.includes("(")) return;
487
+ const css = engineOrNull();
488
+ if (!css) return;
489
+ if (block) keepWholeShorthands(css, rule, block, printed);
490
+ else awaitingDeclarations.add(rule);
491
+ };
492
+ const inputs = {
493
+ namedShorthands() {
494
+ const css = engineOrNull();
495
+ if (!css) return [];
496
+ const keys = /* @__PURE__ */ new Map();
497
+ for (const key in css.work) {
498
+ const property = key.replace(/^webkit(?=[A-Z])/, "-webkit").replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
499
+ if (!css.longhandsOf(property)) continue;
500
+ keys.set(key, property);
501
+ keys.set(property, property);
502
+ if (key.startsWith("webkit")) keys.set(`W${key.slice(1)}`, property);
503
+ }
504
+ return [...keys];
505
+ },
506
+ ruleChanging(rule, block) {
507
+ if (isScratch(rule)) return;
508
+ if (!checkedBeforeChange.has(rule)) {
509
+ checkedBeforeChange.add(rule);
510
+ beforeFirstChange(rule, block);
511
+ } else if (block && awaitingDeclarations.delete(rule)) {
512
+ const css = engineOrNull();
513
+ if (css) keepWholeShorthands(css, rule, block, rule.cssText);
514
+ }
515
+ editedRules.add(rule);
516
+ for (let at = rule.parentRule; at; at = at.parentRule) {
517
+ if (isGroupRule(at) || editedRules.has(at)) continue;
518
+ if (!checkedBeforeChange.has(at)) {
519
+ checkedBeforeChange.add(at);
520
+ beforeFirstChange(at, void 0);
521
+ }
522
+ editedRules.add(at);
523
+ }
524
+ },
525
+ ruleInserted(parent, index, text) {
526
+ if (parent === engine?.sheet) return;
527
+ const rule = parent.cssRules[index];
528
+ if (!rule) return;
529
+ insertedLater.add(rule);
530
+ if (text === void 0 || !text.includes("(") || isGroupRule(rule))
531
+ return;
532
+ insertTexts.set(rule, text);
533
+ insertQueue.push(rule);
534
+ settleInsertsLater();
535
+ },
536
+ sheetReplaced(sheet, text) {
537
+ if (sheet === engine?.sheet) return;
538
+ preexisting.delete(sheet);
539
+ if (text === void 0) sheetTexts.delete(sheet);
540
+ else sheetTexts.set(sheet, text);
541
+ },
542
+ declarationWritten(rule, block, name) {
543
+ if (isScratch(rule)) return;
544
+ if (name === void 0) {
545
+ assigned.delete(rule);
546
+ return;
547
+ }
548
+ const css = name.startsWith("--") ? null : engineOrNull();
549
+ if (!css) return;
550
+ const property = name.toLowerCase();
551
+ let entries = assigned.get(rule);
552
+ if (!entries) {
553
+ if (css.waitingShorthand(block, property) === null) return;
554
+ entries = /* @__PURE__ */ new Map();
555
+ assigned.set(rule, entries);
556
+ }
557
+ note(css, entries, block, property);
558
+ },
559
+ declarationsReplaced(rule, text) {
560
+ if (isScratch(rule)) return;
561
+ assigned.delete(rule);
562
+ if (text?.includes("(")) seedAssignments(rule, splitCssItems(text));
563
+ },
564
+ declarationsExposed(rule) {
565
+ if (isScratch(rule)) return;
566
+ for (let at = rule; at; at = at.parentRule)
567
+ if (!isGroupRule(at)) unobservable.add(at);
568
+ }
569
+ };
570
+ const forgetReports = () => {
571
+ parsed = /* @__PURE__ */ new WeakMap();
572
+ assigned = /* @__PURE__ */ new WeakMap();
573
+ sheetTexts = /* @__PURE__ */ new WeakMap();
574
+ insertTexts = /* @__PURE__ */ new WeakMap();
575
+ insertQueue = [];
576
+ insertedLater = /* @__PURE__ */ new WeakSet();
577
+ editedRules = /* @__PURE__ */ new WeakSet();
578
+ printBeforeEdit = /* @__PURE__ */ new WeakMap();
579
+ unobservable = /* @__PURE__ */ new WeakSet();
580
+ checkedBeforeChange = /* @__PURE__ */ new WeakSet();
581
+ awaitingDeclarations = /* @__PURE__ */ new WeakSet();
582
+ };
583
+ return {
584
+ ruleText,
585
+ inputs,
586
+ startObserving({ beforePageScripts }) {
587
+ if (everStopped) return;
588
+ trusted = true;
589
+ if (beforePageScripts) return;
590
+ for (const sheet of Array.from(doc.styleSheets)) preexisting.add(sheet);
591
+ for (const sheet of doc.adoptedStyleSheets ?? []) preexisting.add(sheet);
592
+ },
593
+ stopObserving() {
594
+ everStopped = true;
595
+ trusted = false;
596
+ forgetReports();
597
+ },
598
+ markWritesUnreported() {
599
+ if (writesUnreported) return;
600
+ writesUnreported = true;
601
+ trusted = !everStopped;
602
+ doc.addEventListener(CSS_RUNTIME_MUTATION, (event) => {
603
+ const detail = event.detail;
604
+ if (detail?.[REPAIR_READY] || !trusted) return;
605
+ trusted = false;
606
+ everStopped = true;
607
+ forgetReports();
608
+ });
609
+ },
610
+ get writesUnreported() {
611
+ return writesUnreported;
612
+ },
613
+ readStylesheetsWith(next) {
614
+ reader = next;
615
+ }
616
+ };
617
+ }
618
+
619
+ // ../../modules/iframe-projection/html/runtime-mutations-runtime.js
620
+ function installRuntimeMutations(scope, inputs) {
621
+ const doc = scope.document;
622
+ const undo = [];
623
+ let active = true;
624
+ const emit = (target, kind, detail) => {
625
+ if (active)
626
+ target.dispatchEvent(
627
+ detail ? new scope.CustomEvent(kind, { bubbles: true, detail }) : new scope.Event(kind, { bubbles: true })
628
+ );
629
+ };
630
+ const form = (target) => {
631
+ if (target instanceof scope.HTMLOptionElement)
632
+ target = target.closest("select");
633
+ if (target && target.isConnected)
634
+ emit(target, "tempo:form-runtime-mutation");
635
+ };
636
+ const css = (target, mutable = false) => {
637
+ const sheet = target instanceof scope.CSSStyleSheet ? target : target.parentStyleSheet;
638
+ if (target === doc || sheet && (sheet.ownerNode?.isConnected || doc.adoptedStyleSheets.includes(sheet)))
639
+ emit(doc, "tempo:css-runtime-mutation", {
640
+ ownerNode: sheet?.ownerNode ?? null,
641
+ sheet: sheet ?? null,
642
+ mutable
643
+ });
644
+ };
645
+ const cssChanged = (target) => css(target);
646
+ const report = (name, a, b, c) => {
647
+ if (!inputs || !active) return;
648
+ try {
649
+ inputs[name](a, b, c);
650
+ } catch {
651
+ }
652
+ };
653
+ const text = (value) => typeof value === "string" ? value : void 0;
654
+ const setter = (proto, key, changed, before, told) => {
655
+ if (!proto) return;
656
+ const original = Object.getOwnPropertyDescriptor(proto, key);
657
+ if (!original?.set || !original.configurable) return;
658
+ const set = function(value) {
659
+ const previous = original.get?.call(this);
660
+ before?.(this);
661
+ original.set.call(this, value);
662
+ if (key === "adoptedStyleSheets" || previous !== original.get?.call(this))
663
+ changed(this);
664
+ told?.(this, value);
665
+ };
666
+ Object.defineProperty(proto, key, { ...original, set });
667
+ undo.push(() => {
668
+ if (Object.getOwnPropertyDescriptor(proto, key)?.set === set)
669
+ Object.defineProperty(proto, key, original);
670
+ });
671
+ };
672
+ const method = (proto, key, changed, before) => {
673
+ if (!proto) return;
674
+ const original = Object.getOwnPropertyDescriptor(proto, key);
675
+ if (typeof original?.value !== "function" || !original.configurable) return;
676
+ const value = function(...args) {
677
+ before?.(this);
678
+ const result = original.value.apply(this, args);
679
+ if (result instanceof scope.Promise)
680
+ result.then(
681
+ () => changed(this, args, result),
682
+ () => {
683
+ }
684
+ );
685
+ else changed(this, args, result);
686
+ return result;
687
+ };
688
+ Object.defineProperty(proto, key, { ...original, value });
689
+ undo.push(() => {
690
+ if (Object.getOwnPropertyDescriptor(proto, key)?.value === value)
691
+ Object.defineProperty(proto, key, original);
692
+ });
693
+ };
694
+ for (const [type, keys] of [
695
+ ["HTMLInputElement", ["value", "checked", "valueAsNumber", "valueAsDate"]],
696
+ ["HTMLTextAreaElement", ["value"]],
697
+ ["HTMLSelectElement", ["value", "selectedIndex"]],
698
+ ["HTMLOptionElement", ["selected"]]
699
+ ])
700
+ for (const key of keys) setter(scope[type]?.prototype, key, form);
701
+ for (const type of ["HTMLInputElement", "HTMLTextAreaElement"])
702
+ method(scope[type]?.prototype, "setRangeText", form);
703
+ for (const key of ["stepUp", "stepDown"])
704
+ method(scope.HTMLInputElement?.prototype, key, form);
705
+ const ruleChanging = (rule) => report("ruleChanging", rule);
706
+ const inserted = (parent, args, index) => {
707
+ css(parent);
708
+ if (typeof index === "number")
709
+ report("ruleInserted", parent, index, text(args[0]));
710
+ };
711
+ method(scope.CSSStyleSheet?.prototype, "insertRule", inserted);
712
+ method(scope.CSSStyleSheet?.prototype, "addRule", (sheet, args) => {
713
+ css(sheet);
714
+ const index = typeof args[2] === "number" ? args[2] : sheet.cssRules.length - 1;
715
+ report("ruleInserted", sheet, index, void 0);
716
+ });
717
+ for (const key of ["deleteRule", "removeRule"])
718
+ method(scope.CSSStyleSheet?.prototype, key, cssChanged);
719
+ for (const key of ["replace", "replaceSync"])
720
+ method(scope.CSSStyleSheet?.prototype, key, (sheet, args) => {
721
+ css(sheet);
722
+ report("sheetReplaced", sheet, text(args[0]));
723
+ });
724
+ method(
725
+ scope.CSSGroupingRule?.prototype,
726
+ "insertRule",
727
+ inserted,
728
+ ruleChanging
729
+ );
730
+ method(
731
+ scope.CSSGroupingRule?.prototype,
732
+ "deleteRule",
733
+ cssChanged,
734
+ ruleChanging
735
+ );
736
+ const declarations = scope.CSSStyleDeclaration?.prototype;
737
+ const setProperty = declarations?.setProperty;
738
+ const getPropertyValue = declarations?.getPropertyValue;
739
+ const ruleStyle = scope.CSSStyleRule ? Object.getOwnPropertyDescriptor(scope.CSSStyleRule.prototype, "style")?.get : void 0;
740
+ const writing = (block) => {
741
+ const rule = block.parentRule;
742
+ if (rule) report("ruleChanging", rule, block);
743
+ };
744
+ const written = (block, name) => {
745
+ const rule = block.parentRule;
746
+ if (!rule) return;
747
+ css(rule);
748
+ report("declarationWritten", rule, block, text(name));
749
+ };
750
+ setter(
751
+ declarations,
752
+ "cssText",
753
+ (block) => {
754
+ if (block.parentRule) css(block.parentRule);
755
+ },
756
+ writing,
757
+ // Told even when the print is unchanged: one variable shorthand can
758
+ // replace another and print exactly the same empty values.
759
+ (block, value) => {
760
+ const rule = block.parentRule;
761
+ if (rule)
762
+ report("declarationsReplaced", rule, value === null ? "" : text(value));
763
+ }
764
+ );
765
+ for (const key of ["setProperty", "removeProperty"])
766
+ method(
767
+ declarations,
768
+ key,
769
+ (block, args) => written(block, args[0]),
770
+ writing
771
+ );
772
+ const rulesOfMaps = /* @__PURE__ */ new WeakMap();
773
+ const mapOf = scope.CSSStyleRule && Object.getOwnPropertyDescriptor(scope.CSSStyleRule.prototype, "styleMap");
774
+ if (mapOf?.get && mapOf.configurable && ruleStyle) {
775
+ const get = function() {
776
+ const map = mapOf.get.call(this);
777
+ rulesOfMaps.set(map, this);
778
+ return map;
779
+ };
780
+ const proto = scope.CSSStyleRule.prototype;
781
+ Object.defineProperty(proto, "styleMap", { ...mapOf, get });
782
+ undo.push(() => {
783
+ if (Object.getOwnPropertyDescriptor(proto, "styleMap")?.get === get)
784
+ Object.defineProperty(proto, "styleMap", mapOf);
785
+ });
786
+ const mapWriting = (map) => {
787
+ const rule = rulesOfMaps.get(map);
788
+ if (rule) report("ruleChanging", rule, ruleStyle.call(rule));
789
+ };
790
+ for (const key of ["set", "append", "delete"])
791
+ method(
792
+ scope.StylePropertyMap?.prototype,
793
+ key,
794
+ (map, args) => {
795
+ const rule = rulesOfMaps.get(map);
796
+ if (!rule) return;
797
+ css(rule);
798
+ report(
799
+ "declarationWritten",
800
+ rule,
801
+ ruleStyle.call(rule),
802
+ text(args[0])
803
+ );
804
+ },
805
+ mapWriting
806
+ );
807
+ method(
808
+ scope.StylePropertyMap?.prototype,
809
+ "clear",
810
+ (map) => {
811
+ const rule = rulesOfMaps.get(map);
812
+ if (!rule) return;
813
+ css(rule);
814
+ report("declarationsReplaced", rule, "");
815
+ },
816
+ mapWriting
817
+ );
818
+ }
819
+ const printSource = scope.Function?.prototype.toString;
820
+ const isNative = (call) => typeof call === "function" && typeof printSource === "function" && printSource.call(call).includes("[native code]");
821
+ const canDefine = inputs && declarations && Object.isExtensible(declarations) && isNative(setProperty) && isNative(getPropertyValue);
822
+ let namedShorthands = [];
823
+ if (canDefine)
824
+ try {
825
+ namedShorthands = inputs.namedShorthands();
826
+ } catch {
827
+ }
828
+ let accessorsInstalled = false;
829
+ for (const [key, property] of namedShorthands) {
830
+ if (key in declarations) continue;
831
+ const accessor = {
832
+ configurable: true,
833
+ enumerable: true,
834
+ get() {
835
+ return getPropertyValue.call(this, property);
836
+ },
837
+ set(value) {
838
+ writing(this);
839
+ setProperty.call(this, property, value);
840
+ written(this, property);
841
+ }
842
+ };
843
+ Object.defineProperty(declarations, key, accessor);
844
+ accessorsInstalled = true;
845
+ undo.push(() => {
846
+ if (Object.getOwnPropertyDescriptor(declarations, key)?.set === accessor.set)
847
+ delete declarations[key];
848
+ });
849
+ }
850
+ for (const proto of [
851
+ scope.CSSStyleRule?.prototype,
852
+ scope.CSSKeyframeRule?.prototype
853
+ ]) {
854
+ const original = proto && Object.getOwnPropertyDescriptor(proto, "style");
855
+ if (!original?.get || !original.configurable) continue;
856
+ const get = function() {
857
+ css(this, true);
858
+ if (!accessorsInstalled) report("declarationsExposed", this);
859
+ return original.get.call(this);
860
+ };
861
+ Object.defineProperty(proto, "style", { ...original, get });
862
+ undo.push(() => {
863
+ if (Object.getOwnPropertyDescriptor(proto, "style")?.get === get)
864
+ Object.defineProperty(proto, "style", original);
865
+ });
866
+ }
867
+ setter(scope.CSSStyleRule?.prototype, "selectorText", css, ruleChanging);
868
+ setter(scope.CSSKeyframeRule?.prototype, "keyText", css, ruleChanging);
869
+ method(
870
+ scope.CSSKeyframesRule?.prototype,
871
+ "appendRule",
872
+ (rule, args) => {
873
+ css(rule);
874
+ report("ruleInserted", rule, rule.cssRules.length - 1, text(args[0]));
875
+ },
876
+ ruleChanging
877
+ );
878
+ method(
879
+ scope.CSSKeyframesRule?.prototype,
880
+ "deleteRule",
881
+ cssChanged,
882
+ ruleChanging
883
+ );
884
+ setter(scope.MediaList?.prototype, "mediaText", () => css(doc));
885
+ for (const key of ["appendMedium", "deleteMedium"])
886
+ method(scope.MediaList?.prototype, key, () => css(doc));
887
+ setter(scope.Document?.prototype, "adoptedStyleSheets", css);
888
+ setter(scope.StyleSheet?.prototype, "disabled", css);
889
+ setter(scope.HTMLStyleElement?.prototype, "disabled", (style) => {
890
+ if (style.sheet) css(style.sheet);
891
+ });
892
+ method(scope.HTMLFormElement?.prototype, "reset", (target) => {
893
+ for (const element of target.elements) form(element);
894
+ });
895
+ const dispose = () => {
896
+ if (!active) return;
897
+ active = false;
898
+ for (const restore of undo.reverse()) restore();
899
+ };
900
+ return dispose;
901
+ }
902
+
903
+ // ../../modules/iframe-projection/html/runtime-mutations.ts
904
+ var FORM_RUNTIME_MUTATION = "tempo:form-runtime-mutation";
905
+ var CSS_RUNTIME_MUTATION2 = "tempo:css-runtime-mutation";
906
+ var owners = /* @__PURE__ */ new WeakMap();
907
+ function observe(doc, recording) {
908
+ const view = doc.defaultView;
909
+ if (!view) return () => {
910
+ };
911
+ let owner = owners.get(doc);
912
+ if (!owner) {
913
+ owner = {
914
+ count: 0,
915
+ stop: installRuntimeMutations(view, recording?.inputs),
916
+ sources: recording?.sources
917
+ };
918
+ owners.set(doc, owner);
919
+ recording?.sources.startObserving({
920
+ beforePageScripts: recording.beforePageScripts
921
+ });
922
+ }
923
+ owner.count++;
924
+ const shared = owner;
925
+ let released = false;
926
+ return () => {
927
+ if (released) return;
928
+ released = true;
929
+ if (--shared.count === 0) {
930
+ shared.stop();
931
+ shared.sources?.stopObserving();
932
+ owners.delete(doc);
933
+ }
934
+ };
935
+ }
936
+ function observeRuntimeMutations(doc) {
937
+ return observe(doc);
938
+ }
939
+ function observeCssInputs(doc, {
940
+ beforePageScripts = false,
941
+ namedShorthands = false
942
+ } = {}) {
943
+ const sources = cssSourcesFor(doc);
944
+ if (sources.writesUnreported || owners.has(doc)) return observe(doc);
945
+ const inputs = namedShorthands && beforePageScripts ? sources.inputs : { ...sources.inputs, namedShorthands: () => [] };
946
+ return observe(doc, { sources, inputs, beforePageScripts });
947
+ }
948
+
949
+ // ../../modules/iframe-projection/html/declared-facts.ts
950
+ var SOURCE_ANNOTATED_SELECTOR = "[data-tempo-filepath]";
951
+ function computeDeclaredFacts(targetElement, captureRoot, scopeSelector, portalElements) {
952
+ const observedVersions = {};
953
+ const observedSourceVersions = {};
954
+ const anchorSet = /* @__PURE__ */ new Set();
955
+ const visit = (element) => {
956
+ const filepath = element.getAttribute("data-tempo-filepath");
957
+ if (filepath == null || filepath.length === 0) return;
958
+ const modifiedTsRaw = element.getAttribute("data-tempo-modifiedts");
959
+ if (modifiedTsRaw != null) {
960
+ const modifiedTs = Number(modifiedTsRaw);
961
+ if (!Number.isNaN(modifiedTs)) {
962
+ const existing = observedVersions[filepath];
963
+ if (existing === void 0 || modifiedTs > existing) {
964
+ observedVersions[filepath] = modifiedTs;
965
+ const version = element.getAttribute("data-tempo-source-version");
966
+ if (version != null && version.length > 0) {
967
+ observedSourceVersions[filepath] = version;
968
+ } else {
969
+ delete observedSourceVersions[filepath];
970
+ }
971
+ }
972
+ }
973
+ }
974
+ const position = element.getAttribute("data-tempo-position");
975
+ if (position != null && position.length > 0) {
976
+ anchorSet.add(`${filepath} ${position}`);
977
+ }
978
+ };
979
+ const walkRoots = [targetElement, ...portalElements];
980
+ for (const root of walkRoots) {
981
+ if (root.matches(SOURCE_ANNOTATED_SELECTOR)) visit(root);
982
+ for (const annotated of root.querySelectorAll(SOURCE_ANNOTATED_SELECTOR)) {
983
+ visit(annotated);
984
+ }
985
+ }
986
+ const complete = targetElement === captureRoot;
987
+ return {
988
+ complete,
989
+ scopeSelector: complete ? null : scopeSelector,
990
+ observedVersions,
991
+ observedSourceVersions,
992
+ containedAnchors: Array.from(anchorSet),
993
+ renderError: computeRenderError(captureRoot)
994
+ };
995
+ }
996
+ function computeRenderError(captureRoot) {
997
+ const errorElement = captureRoot.matches('[data-render-error="true"]') ? captureRoot : captureRoot.querySelector('[data-render-error="true"]');
998
+ if (!errorElement) return null;
999
+ return {
1000
+ message: errorElement.getAttribute("data-render-error-message")
1001
+ };
1002
+ }
1003
+
1004
+ // ../../modules/iframe-projection/shared/capture-perf.ts
1005
+ var counters = {
1006
+ styleReadCount: 0,
1007
+ identityNodesVisited: 0,
1008
+ sourceVersionDomScanNodes: 0,
1009
+ sourceVersionFiberSerializeNodes: 0,
1010
+ sourceVersionFiberReductionNodes: 0,
1011
+ sourceVersionFallbackScanNodes: 0
1012
+ };
1013
+ var producerReferencesByDocument = /* @__PURE__ */ new Map();
1014
+ var activeDocumentProducers = 0;
1015
+ var activeRootObservers = 0;
1016
+ var activeReactCommitSubscriptions = 0;
1017
+ function registerDocumentCaptureProducer(document2) {
1018
+ const references = producerReferencesByDocument.get(document2) ?? 0;
1019
+ if (references === 0) activeDocumentProducers += 1;
1020
+ producerReferencesByDocument.set(document2, references + 1);
1021
+ activeReactCommitSubscriptions += 1;
1022
+ let active = true;
1023
+ return () => {
1024
+ if (!active) return;
1025
+ active = false;
1026
+ const current = producerReferencesByDocument.get(document2) ?? 0;
1027
+ if (current <= 1) {
1028
+ producerReferencesByDocument.delete(document2);
1029
+ activeDocumentProducers = Math.max(0, activeDocumentProducers - 1);
1030
+ } else {
1031
+ producerReferencesByDocument.set(document2, current - 1);
1032
+ }
1033
+ activeReactCommitSubscriptions = Math.max(
1034
+ 0,
1035
+ activeReactCommitSubscriptions - 1
1036
+ );
1037
+ };
1038
+ }
1039
+ function registerCaptureRootObserver() {
1040
+ activeRootObservers += 1;
1041
+ let active = true;
1042
+ return () => {
1043
+ if (!active) return;
1044
+ active = false;
1045
+ activeRootObservers = Math.max(0, activeRootObservers - 1);
1046
+ };
1047
+ }
1048
+ function readCaptureProducerCardinality() {
1049
+ return {
1050
+ activeDocumentProducers,
1051
+ activeRootObservers,
1052
+ reactCommitSubscriptions: activeReactCommitSubscriptions
1053
+ };
1054
+ }
1055
+ function countCaptureStyleRead() {
1056
+ counters.styleReadCount += 1;
1057
+ }
1058
+ function countIdentityNodeVisited() {
1059
+ counters.identityNodesVisited += 1;
1060
+ }
1061
+ function resetCaptureFlushCounters() {
1062
+ counters.styleReadCount = 0;
1063
+ counters.identityNodesVisited = 0;
1064
+ counters.sourceVersionDomScanNodes = 0;
1065
+ counters.sourceVersionFiberSerializeNodes = 0;
1066
+ counters.sourceVersionFiberReductionNodes = 0;
1067
+ counters.sourceVersionFallbackScanNodes = 0;
1068
+ }
1069
+ function readCaptureFlushCounters() {
1070
+ return { ...counters };
1071
+ }
1072
+
1073
+ // ../../modules/iframe-projection/html/displayability.ts
1074
+ var IGNORED_CONTENT_TAGS = /* @__PURE__ */ new Set([
1075
+ "DATALIST",
1076
+ "LINK",
1077
+ "META",
1078
+ "NOSCRIPT",
1079
+ "SCRIPT",
1080
+ "STYLE",
1081
+ "TEMPLATE"
1082
+ ]);
1083
+ var VISUAL_ASSET_TAGS = /* @__PURE__ */ new Set([
1084
+ "AUDIO",
1085
+ "CANVAS",
1086
+ "EMBED",
1087
+ "IFRAME",
1088
+ "IMG",
1089
+ "INPUT",
1090
+ "OBJECT",
1091
+ "SELECT",
1092
+ "SVG",
1093
+ "TEXTAREA",
1094
+ "VIDEO"
1095
+ ]);
1096
+ function measureComputedDisplayability(captureRoot, supplementalRoots = []) {
1097
+ const doc = captureRoot.ownerDocument;
1098
+ const view = doc.defaultView;
1099
+ if (!view || !captureRoot.isConnected || supplementalRoots.some(
1100
+ (root) => root.ownerDocument !== doc || !root.isConnected
1101
+ )) {
1102
+ return null;
1103
+ }
1104
+ const result = {
1105
+ version: 1,
1106
+ elementCount: 0,
1107
+ paintedElementCount: 0,
1108
+ nonEmptyTextNodeCount: 0,
1109
+ visualAssetCount: 0
1110
+ };
1111
+ try {
1112
+ const rootBlocked = hasBlockingElementInChain(captureRoot, view);
1113
+ const rootTextVisible = !rootBlocked && elementHasVisibleComputedVisibility(captureRoot, view);
1114
+ for (const child of Array.from(captureRoot.childNodes)) {
1115
+ visitNode(child, rootBlocked, rootTextVisible, view, result);
1116
+ }
1117
+ for (const supplementalRoot of supplementalRoots) {
1118
+ visitNode(
1119
+ supplementalRoot,
1120
+ hasBlockingElementInChain(supplementalRoot.parentElement, view),
1121
+ true,
1122
+ view,
1123
+ result
1124
+ );
1125
+ }
1126
+ } catch {
1127
+ return null;
1128
+ }
1129
+ return result;
1130
+ }
1131
+ function visitNode(node, blockedByAncestor, parentTextVisible, view, result) {
1132
+ if (node.nodeType === 3) {
1133
+ if (!blockedByAncestor && parentTextVisible && (node.textContent?.trim().length ?? 0) > 0) {
1134
+ result.nonEmptyTextNodeCount += 1;
1135
+ }
1136
+ return;
1137
+ }
1138
+ if (node.nodeType !== 1) return;
1139
+ const element = node;
1140
+ const blocked = blockedByAncestor || elementBlocksSubtree(element, view);
1141
+ if (blocked) return;
1142
+ const visible = elementHasVisibleComputedVisibility(element, view);
1143
+ if (visible) {
1144
+ result.elementCount += 1;
1145
+ if (elementPaintsOwnPixels(element, view)) {
1146
+ result.paintedElementCount = (result.paintedElementCount ?? 0) + 1;
1147
+ }
1148
+ if (VISUAL_ASSET_TAGS.has(element.tagName)) {
1149
+ result.visualAssetCount += 1;
1150
+ }
1151
+ }
1152
+ for (const child of Array.from(element.childNodes)) {
1153
+ visitNode(child, false, visible, view, result);
1154
+ }
1155
+ }
1156
+ function elementPaintsOwnPixels(element, view) {
1157
+ countCaptureStyleRead();
1158
+ const style = view.getComputedStyle(element);
1159
+ if (colorCanPaint(style.backgroundColor)) return true;
1160
+ if (style.backgroundImage && style.backgroundImage !== "none") return true;
1161
+ if (style.boxShadow && style.boxShadow !== "none") return true;
1162
+ if (style.outlineStyle !== "none" && parseFloat(style.outlineWidth) > 0 && colorCanPaint(style.outlineColor)) {
1163
+ return true;
1164
+ }
1165
+ for (const side of ["Top", "Right", "Bottom", "Left"]) {
1166
+ if (style[`border${side}Style`] !== "none" && parseFloat(style[`border${side}Width`]) > 0 && colorCanPaint(style[`border${side}Color`])) {
1167
+ return true;
1168
+ }
1169
+ }
1170
+ return false;
1171
+ }
1172
+ function colorCanPaint(value) {
1173
+ const normalized = value.trim().toLowerCase().replace(/ /g, "");
1174
+ if (!normalized || normalized === "transparent") return false;
1175
+ return !(/^rgba\([^)]*,0(?:\.0+)?\)$/.test(normalized) || /^rgb\([^)]*\/0(?:\.0+)?\)$/.test(normalized));
1176
+ }
1177
+ function hasBlockingElementInChain(start, view) {
1178
+ for (let element = start; element; element = element.parentElement) {
1179
+ if (elementBlocksSubtree(element, view)) return true;
1180
+ }
1181
+ return false;
1182
+ }
1183
+ function elementBlocksSubtree(element, view) {
1184
+ if (IGNORED_CONTENT_TAGS.has(element.tagName)) return true;
1185
+ if (element.hasAttribute("hidden")) return true;
1186
+ if (element.tagName === "DIALOG" && !element.hasAttribute("open")) {
1187
+ return true;
1188
+ }
1189
+ if (element.tagName === "INPUT" && element.getAttribute("type")?.trim().toLowerCase() === "hidden") {
1190
+ return true;
1191
+ }
1192
+ countCaptureStyleRead();
1193
+ const style = view.getComputedStyle(element);
1194
+ const opacity = style.opacity.trim();
1195
+ return style.display === "none" || opacity.length > 0 && Number(opacity) <= 0 || style.getPropertyValue("content-visibility") === "hidden";
1196
+ }
1197
+ function elementHasVisibleComputedVisibility(element, view) {
1198
+ countCaptureStyleRead();
1199
+ const visibility = view.getComputedStyle(element).visibility;
1200
+ return visibility !== "hidden" && visibility !== "collapse";
1201
+ }
1202
+
1203
+ // ../../modules/iframe-projection/html/selectors.ts
1204
+ function generateSelector(element, root) {
1205
+ if (!root) {
1206
+ if (element === document.documentElement) return ":root";
1207
+ if (element === document.head) return "head";
1208
+ if (element === document.body) return "body";
1209
+ }
1210
+ if (root && element === root) return "";
1211
+ const parts = [];
1212
+ let current = element;
1213
+ const stopAt = root ?? document.documentElement;
1214
+ while (current && current !== stopAt) {
1215
+ const parent = current.parentElement;
1216
+ if (!parent) break;
1217
+ const tagName = current.tagName.toLowerCase();
1218
+ let index = 1;
1219
+ let sibling = current.previousElementSibling;
1220
+ while (sibling) {
1221
+ if (sibling.tagName === current.tagName) index++;
1222
+ sibling = sibling.previousElementSibling;
1223
+ }
1224
+ let sameTypeSiblings = 0;
1225
+ for (const child of parent.children) {
1226
+ if (child.tagName === current.tagName) sameTypeSiblings++;
1227
+ }
1228
+ if (sameTypeSiblings > 1) {
1229
+ parts.unshift(`${tagName}:nth-of-type(${index})`);
1230
+ } else {
1231
+ parts.unshift(tagName);
1232
+ }
1233
+ current = parent;
1234
+ }
1235
+ if (parts.length === 0) {
1236
+ if (element === document.body) return "body";
1237
+ if (element === document.head) return "head";
1238
+ return "";
1239
+ }
1240
+ const path = parts.join(" > ");
1241
+ if (root) return `:scope > ${path}`;
1242
+ return path;
1243
+ }
1244
+ function findLowestCommonAncestor(nodes) {
1245
+ if (nodes.size === 0) return null;
1246
+ const ancestorChains = [];
1247
+ for (const node of nodes) {
1248
+ const chain = [];
1249
+ let current = node instanceof Element ? node : node.parentElement;
1250
+ while (current && current !== document) {
1251
+ if (current instanceof Element) {
1252
+ chain.unshift(current);
1253
+ }
1254
+ current = current.parentNode;
1255
+ }
1256
+ if (chain.length > 0) {
1257
+ ancestorChains.push(chain);
1258
+ }
1259
+ }
1260
+ if (ancestorChains.length === 0) {
1261
+ return document.documentElement;
1262
+ }
1263
+ let lca = document.documentElement;
1264
+ const firstChain = ancestorChains[0];
1265
+ const minLength = Math.min(...ancestorChains.map((c) => c.length));
1266
+ for (let i = 0; i < minLength; i++) {
1267
+ const candidate = firstChain[i];
1268
+ if (candidate && ancestorChains.every((chain) => chain[i] === candidate)) {
1269
+ lca = candidate;
1270
+ } else {
1271
+ break;
1272
+ }
1273
+ }
1274
+ return lca;
1275
+ }
1276
+
1277
+ // ../../modules/iframe-projection/html/capture.ts
1278
+ function capture(element) {
1279
+ return captureWithSupplementalRoots(element, []);
1280
+ }
1281
+ function captureWithSupplementalRoots(element, supplementalRoots) {
1282
+ syncFormStateToAttributes(element);
1283
+ const selector = generateSelector(element, element);
1284
+ const html = removeScriptTags(element.innerHTML);
1285
+ const attributes = captureAttributes(element);
1286
+ const documentElementAttributes = element.ownerDocument ? captureAttributes(element.ownerDocument.documentElement) : void 0;
1287
+ const bodyAttributes = element.ownerDocument?.body ? captureAttributes(element.ownerDocument.body) : void 0;
1288
+ const baseUrl = element.ownerDocument?.baseURI;
1289
+ const states = collectElementStates(element);
1290
+ const displayability = measureComputedDisplayability(
1291
+ element,
1292
+ supplementalRoots
1293
+ );
1294
+ return {
1295
+ // Whole-surface one-shot: the element is both the capture root and the
1296
+ // serialized scope, so `complete` is true and there is no scope selector.
1297
+ declared: computeDeclaredFacts(element, element, "", supplementalRoots),
1298
+ ...displayability && { displayability },
1299
+ dom: {
1300
+ selector,
1301
+ html,
1302
+ attributes,
1303
+ documentElementAttributes,
1304
+ bodyAttributes
1305
+ },
1306
+ states,
1307
+ baseUrl
1308
+ };
1309
+ }
1310
+ function syncFormStateToAttributes(root) {
1311
+ for (const input of root.querySelectorAll(
1312
+ 'input[type="checkbox"], input[type="radio"]'
1313
+ )) {
1314
+ const el = input;
1315
+ if (el.checked) {
1316
+ el.setAttribute("checked", "");
1317
+ } else {
1318
+ el.removeAttribute("checked");
1319
+ }
1320
+ }
1321
+ for (const input of root.querySelectorAll(
1322
+ 'input:not([type="checkbox"]):not([type="radio"])'
1323
+ )) {
1324
+ const el = input;
1325
+ if (el.value !== el.getAttribute("value")) {
1326
+ el.setAttribute("value", el.value);
1327
+ }
1328
+ }
1329
+ for (const textarea of root.querySelectorAll("textarea")) {
1330
+ const el = textarea;
1331
+ if (el.value !== el.textContent) {
1332
+ el.textContent = el.value;
1333
+ }
1334
+ if (el.hasAttribute("value")) {
1335
+ el.removeAttribute("value");
1336
+ }
1337
+ }
1338
+ for (const select of root.querySelectorAll("select")) {
1339
+ const el = select;
1340
+ for (const option of el.options) {
1341
+ if (option.selected) {
1342
+ option.setAttribute("selected", "");
1343
+ } else {
1344
+ option.removeAttribute("selected");
1345
+ }
1346
+ }
1347
+ }
1348
+ }
1349
+ function removeScriptTags(html) {
1350
+ return html.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi, "");
1351
+ }
1352
+ function captureAttributes(element) {
1353
+ const attrs = {};
1354
+ for (const attr of Array.from(element.attributes)) {
1355
+ attrs[attr.name] = attr.value;
1356
+ }
1357
+ return attrs;
1358
+ }
1359
+ function collectElementStates(root, options = {}) {
1360
+ const { includeDocumentScroll = true } = options;
1361
+ const states = [];
1362
+ for (const input of root.querySelectorAll("input")) {
1363
+ const el = input;
1364
+ const isCheckable = el.type === "checkbox" || el.type === "radio";
1365
+ const hasNonDefault = isCheckable ? el.checked !== el.defaultChecked : el.value !== el.defaultValue;
1366
+ if (hasNonDefault) {
1367
+ const selector = generateSelector(el, root);
1368
+ if (isCheckable) {
1369
+ states.push({ selector, checked: el.checked });
1370
+ } else {
1371
+ states.push({ selector, value: el.value });
1372
+ }
1373
+ }
1374
+ }
1375
+ for (const textarea of root.querySelectorAll("textarea")) {
1376
+ const el = textarea;
1377
+ if (el.value !== el.defaultValue) {
1378
+ const selector = generateSelector(el, root);
1379
+ states.push({ selector, value: el.value });
1380
+ }
1381
+ }
1382
+ for (const select of root.querySelectorAll("select")) {
1383
+ const el = select;
1384
+ for (const option of el.options) {
1385
+ if (option.selected !== option.defaultSelected) {
1386
+ const selector = generateSelector(option, root);
1387
+ states.push({ selector, selected: option.selected });
1388
+ }
1389
+ }
1390
+ }
1391
+ states.push({
1392
+ selector: "",
1393
+ scrollTop: root.scrollTop,
1394
+ scrollLeft: root.scrollLeft
1395
+ });
1396
+ if (includeDocumentScroll) {
1397
+ const scrollingEl = root.ownerDocument?.scrollingElement;
1398
+ if (scrollingEl && scrollingEl !== root) {
1399
+ states.push({
1400
+ selector: ":root",
1401
+ scrollTop: scrollingEl.scrollTop,
1402
+ scrollLeft: scrollingEl.scrollLeft
1403
+ });
1404
+ }
1405
+ }
1406
+ for (const el of root.querySelectorAll("*")) {
1407
+ if (el.scrollTop > 0 || el.scrollLeft > 0) {
1408
+ const selector = generateSelector(el, root);
1409
+ states.push({
1410
+ selector,
1411
+ scrollTop: el.scrollTop,
1412
+ scrollLeft: el.scrollLeft
1413
+ });
1414
+ }
1415
+ }
1416
+ return states;
1417
+ }
1418
+
1419
+ export {
1420
+ cssSourcesFor,
1421
+ FORM_RUNTIME_MUTATION,
1422
+ CSS_RUNTIME_MUTATION2 as CSS_RUNTIME_MUTATION,
1423
+ observeRuntimeMutations,
1424
+ observeCssInputs,
1425
+ generateSelector,
1426
+ findLowestCommonAncestor,
1427
+ registerDocumentCaptureProducer,
1428
+ registerCaptureRootObserver,
1429
+ readCaptureProducerCardinality,
1430
+ countCaptureStyleRead,
1431
+ countIdentityNodeVisited,
1432
+ resetCaptureFlushCounters,
1433
+ readCaptureFlushCounters,
1434
+ capture,
1435
+ captureWithSupplementalRoots,
1436
+ removeScriptTags,
1437
+ captureAttributes,
1438
+ collectElementStates
1439
+ };
1440
+ //# sourceMappingURL=chunk-T364NBR3.js.map