tempo-sdk 0.0.26 → 0.0.27

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.
@@ -887,207 +887,6 @@ function buildProjectionCapturePerf(input) {
887
887
  };
888
888
  }
889
889
 
890
- // ../../modules/iframe-projection/html/declared-facts.ts
891
- var SOURCE_ANNOTATED_SELECTOR = "[data-tempo-filepath], [data-tempo-html-filepath]";
892
- var NAMESPACES = [
893
- {
894
- filepathAttr: "data-tempo-filepath",
895
- positionAttr: "data-tempo-position",
896
- modifiedTsAttr: "data-tempo-modifiedts",
897
- sourceVersionAttr: "data-tempo-source-version"
898
- },
899
- {
900
- filepathAttr: "data-tempo-html-filepath",
901
- positionAttr: "data-tempo-html-offset",
902
- modifiedTsAttr: "data-tempo-html-modifiedts",
903
- sourceVersionAttr: "data-tempo-html-source-version"
904
- }
905
- ];
906
- function computeDeclaredFacts(targetElement, captureRoot, scopeSelector, portalElements) {
907
- const observedVersions = {};
908
- const observedSourceVersions = {};
909
- const anchorSet = /* @__PURE__ */ new Set();
910
- const visit = (element) => {
911
- for (const ns of NAMESPACES) {
912
- const filepath = element.getAttribute(ns.filepathAttr);
913
- if (filepath == null || filepath.length === 0) continue;
914
- const modifiedTsRaw = element.getAttribute(ns.modifiedTsAttr);
915
- if (modifiedTsRaw != null) {
916
- const modifiedTs = Number(modifiedTsRaw);
917
- if (!Number.isNaN(modifiedTs)) {
918
- const existing = observedVersions[filepath];
919
- if (existing === void 0 || modifiedTs > existing) {
920
- observedVersions[filepath] = modifiedTs;
921
- const version = element.getAttribute(ns.sourceVersionAttr);
922
- if (version != null && version.length > 0) {
923
- observedSourceVersions[filepath] = version;
924
- } else {
925
- delete observedSourceVersions[filepath];
926
- }
927
- }
928
- }
929
- }
930
- const position = element.getAttribute(ns.positionAttr);
931
- if (position != null && position.length > 0) {
932
- anchorSet.add(`${filepath} ${position}`);
933
- }
934
- }
935
- };
936
- const walkRoots = [targetElement, ...portalElements];
937
- for (const root of walkRoots) {
938
- if (root.matches(SOURCE_ANNOTATED_SELECTOR)) visit(root);
939
- for (const annotated of root.querySelectorAll(SOURCE_ANNOTATED_SELECTOR)) {
940
- visit(annotated);
941
- }
942
- }
943
- const complete = targetElement === captureRoot;
944
- return {
945
- complete,
946
- scopeSelector: complete ? null : scopeSelector,
947
- observedVersions,
948
- observedSourceVersions,
949
- containedAnchors: Array.from(anchorSet),
950
- renderError: computeRenderError(captureRoot)
951
- };
952
- }
953
- function computeRenderError(captureRoot) {
954
- const errorElement = captureRoot.matches('[data-render-error="true"]') ? captureRoot : captureRoot.querySelector('[data-render-error="true"]');
955
- if (!errorElement) return null;
956
- return {
957
- message: errorElement.getAttribute("data-render-error-message")
958
- };
959
- }
960
-
961
- // ../../modules/iframe-projection/html/displayability.ts
962
- var IGNORED_CONTENT_TAGS = /* @__PURE__ */ new Set([
963
- "DATALIST",
964
- "LINK",
965
- "META",
966
- "NOSCRIPT",
967
- "SCRIPT",
968
- "STYLE",
969
- "TEMPLATE"
970
- ]);
971
- var VISUAL_ASSET_TAGS = /* @__PURE__ */ new Set([
972
- "AUDIO",
973
- "CANVAS",
974
- "EMBED",
975
- "IFRAME",
976
- "IMG",
977
- "INPUT",
978
- "OBJECT",
979
- "SELECT",
980
- "SVG",
981
- "TEXTAREA",
982
- "VIDEO"
983
- ]);
984
- function measureComputedDisplayability(captureRoot, supplementalRoots = []) {
985
- const doc = captureRoot.ownerDocument;
986
- const view = doc.defaultView;
987
- if (!view || !captureRoot.isConnected || supplementalRoots.some(
988
- (root) => root.ownerDocument !== doc || !root.isConnected
989
- )) {
990
- return null;
991
- }
992
- const result = {
993
- version: 1,
994
- elementCount: 0,
995
- paintedElementCount: 0,
996
- nonEmptyTextNodeCount: 0,
997
- visualAssetCount: 0
998
- };
999
- try {
1000
- const rootBlocked = hasBlockingElementInChain(captureRoot, view);
1001
- const rootTextVisible = !rootBlocked && elementHasVisibleComputedVisibility(captureRoot, view);
1002
- for (const child of Array.from(captureRoot.childNodes)) {
1003
- visitNode(child, rootBlocked, rootTextVisible, view, result);
1004
- }
1005
- for (const supplementalRoot of supplementalRoots) {
1006
- visitNode(
1007
- supplementalRoot,
1008
- hasBlockingElementInChain(supplementalRoot.parentElement, view),
1009
- true,
1010
- view,
1011
- result
1012
- );
1013
- }
1014
- } catch {
1015
- return null;
1016
- }
1017
- return result;
1018
- }
1019
- function visitNode(node, blockedByAncestor, parentTextVisible, view, result) {
1020
- if (node.nodeType === 3) {
1021
- if (!blockedByAncestor && parentTextVisible && (node.textContent?.trim().length ?? 0) > 0) {
1022
- result.nonEmptyTextNodeCount += 1;
1023
- }
1024
- return;
1025
- }
1026
- if (node.nodeType !== 1) return;
1027
- const element = node;
1028
- const blocked = blockedByAncestor || elementBlocksSubtree(element, view);
1029
- if (blocked) return;
1030
- const visible = elementHasVisibleComputedVisibility(element, view);
1031
- if (visible) {
1032
- result.elementCount += 1;
1033
- if (elementPaintsOwnPixels(element, view)) {
1034
- result.paintedElementCount = (result.paintedElementCount ?? 0) + 1;
1035
- }
1036
- if (VISUAL_ASSET_TAGS.has(element.tagName)) {
1037
- result.visualAssetCount += 1;
1038
- }
1039
- }
1040
- for (const child of Array.from(element.childNodes)) {
1041
- visitNode(child, false, visible, view, result);
1042
- }
1043
- }
1044
- function elementPaintsOwnPixels(element, view) {
1045
- countCaptureStyleRead();
1046
- const style = view.getComputedStyle(element);
1047
- if (colorCanPaint(style.backgroundColor)) return true;
1048
- if (style.backgroundImage && style.backgroundImage !== "none") return true;
1049
- if (style.boxShadow && style.boxShadow !== "none") return true;
1050
- if (style.outlineStyle !== "none" && parseFloat(style.outlineWidth) > 0 && colorCanPaint(style.outlineColor)) {
1051
- return true;
1052
- }
1053
- for (const side of ["Top", "Right", "Bottom", "Left"]) {
1054
- if (style[`border${side}Style`] !== "none" && parseFloat(style[`border${side}Width`]) > 0 && colorCanPaint(style[`border${side}Color`])) {
1055
- return true;
1056
- }
1057
- }
1058
- return false;
1059
- }
1060
- function colorCanPaint(value) {
1061
- const normalized = value.trim().toLowerCase().replace(/ /g, "");
1062
- if (!normalized || normalized === "transparent") return false;
1063
- return !(/^rgba\([^)]*,0(?:\.0+)?\)$/.test(normalized) || /^rgb\([^)]*\/0(?:\.0+)?\)$/.test(normalized));
1064
- }
1065
- function hasBlockingElementInChain(start, view) {
1066
- for (let element = start; element; element = element.parentElement) {
1067
- if (elementBlocksSubtree(element, view)) return true;
1068
- }
1069
- return false;
1070
- }
1071
- function elementBlocksSubtree(element, view) {
1072
- if (IGNORED_CONTENT_TAGS.has(element.tagName)) return true;
1073
- if (element.hasAttribute("hidden")) return true;
1074
- if (element.tagName === "DIALOG" && !element.hasAttribute("open")) {
1075
- return true;
1076
- }
1077
- if (element.tagName === "INPUT" && element.getAttribute("type")?.trim().toLowerCase() === "hidden") {
1078
- return true;
1079
- }
1080
- countCaptureStyleRead();
1081
- const style = view.getComputedStyle(element);
1082
- const opacity = style.opacity.trim();
1083
- return style.display === "none" || opacity.length > 0 && Number(opacity) <= 0 || style.getPropertyValue("content-visibility") === "hidden";
1084
- }
1085
- function elementHasVisibleComputedVisibility(element, view) {
1086
- countCaptureStyleRead();
1087
- const visibility = view.getComputedStyle(element).visibility;
1088
- return visibility !== "hidden" && visibility !== "collapse";
1089
- }
1090
-
1091
890
  // ../../modules/iframe-projection/html/selectors.ts
1092
891
  function generateSelector(element, root) {
1093
892
  if (!root) {
@@ -1162,159 +961,20 @@ function findLowestCommonAncestor(nodes) {
1162
961
  return lca;
1163
962
  }
1164
963
 
1165
- // ../../modules/iframe-projection/html/capture.ts
1166
- function captureWithSupplementalRoots(element, supplementalRoots) {
1167
- syncFormStateToAttributes(element);
1168
- const selector = generateSelector(element, element);
1169
- const html = removeScriptTags(element.innerHTML);
1170
- const attributes = captureAttributes(element);
1171
- const documentElementAttributes = element.ownerDocument ? captureAttributes(element.ownerDocument.documentElement) : void 0;
1172
- const bodyAttributes = element.ownerDocument?.body ? captureAttributes(element.ownerDocument.body) : void 0;
1173
- const baseUrl = element.ownerDocument?.baseURI;
1174
- const states = collectElementStates(element);
1175
- const displayability = measureComputedDisplayability(
1176
- element,
1177
- supplementalRoots
1178
- );
1179
- return {
1180
- // Whole-surface one-shot: the element is both the capture root and the
1181
- // serialized scope, so `complete` is true and there is no scope selector.
1182
- declared: computeDeclaredFacts(element, element, "", supplementalRoots),
1183
- ...displayability && { displayability },
1184
- dom: {
1185
- selector,
1186
- html,
1187
- attributes,
1188
- documentElementAttributes,
1189
- bodyAttributes
1190
- },
1191
- states,
1192
- baseUrl
1193
- };
964
+ // ../../modules/iframe-projection/html/watch-dom.ts
965
+ var DOM_ID_ATTR = "data-dom-id";
966
+ var sessionHash = null;
967
+ var idCounter = 0;
968
+ function getOrCreateSessionHash() {
969
+ if (sessionHash === null) {
970
+ sessionHash = Math.random().toString(36).substring(2, 6);
971
+ }
972
+ return sessionHash;
1194
973
  }
1195
- function syncFormStateToAttributes(root) {
1196
- for (const input of root.querySelectorAll(
1197
- 'input[type="checkbox"], input[type="radio"]'
1198
- )) {
1199
- const el = input;
1200
- if (el.checked) {
1201
- el.setAttribute("checked", "");
1202
- } else {
1203
- el.removeAttribute("checked");
1204
- }
1205
- }
1206
- for (const input of root.querySelectorAll(
1207
- 'input:not([type="checkbox"]):not([type="radio"])'
1208
- )) {
1209
- const el = input;
1210
- if (el.value !== el.getAttribute("value")) {
1211
- el.setAttribute("value", el.value);
1212
- }
1213
- }
1214
- for (const textarea of root.querySelectorAll("textarea")) {
1215
- const el = textarea;
1216
- if (el.value !== el.textContent) {
1217
- el.textContent = el.value;
1218
- }
1219
- if (el.hasAttribute("value")) {
1220
- el.removeAttribute("value");
1221
- }
1222
- }
1223
- for (const select of root.querySelectorAll("select")) {
1224
- const el = select;
1225
- for (const option of el.options) {
1226
- if (option.selected) {
1227
- option.setAttribute("selected", "");
1228
- } else {
1229
- option.removeAttribute("selected");
1230
- }
1231
- }
1232
- }
1233
- }
1234
- function removeScriptTags(html) {
1235
- return html.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi, "");
1236
- }
1237
- function captureAttributes(element) {
1238
- const attrs = {};
1239
- for (const attr of Array.from(element.attributes)) {
1240
- attrs[attr.name] = attr.value;
1241
- }
1242
- return attrs;
1243
- }
1244
- function collectElementStates(root, options = {}) {
1245
- const { includeDocumentScroll = true } = options;
1246
- const states = [];
1247
- for (const input of root.querySelectorAll("input")) {
1248
- const el = input;
1249
- const isCheckable = el.type === "checkbox" || el.type === "radio";
1250
- const hasNonDefault = isCheckable ? el.checked !== el.defaultChecked : el.value !== el.defaultValue;
1251
- if (hasNonDefault) {
1252
- const selector = generateSelector(el, root);
1253
- if (isCheckable) {
1254
- states.push({ selector, checked: el.checked });
1255
- } else {
1256
- states.push({ selector, value: el.value });
1257
- }
1258
- }
1259
- }
1260
- for (const textarea of root.querySelectorAll("textarea")) {
1261
- const el = textarea;
1262
- if (el.value !== el.defaultValue) {
1263
- const selector = generateSelector(el, root);
1264
- states.push({ selector, value: el.value });
1265
- }
1266
- }
1267
- for (const select of root.querySelectorAll("select")) {
1268
- const el = select;
1269
- for (const option of el.options) {
1270
- if (option.selected !== option.defaultSelected) {
1271
- const selector = generateSelector(option, root);
1272
- states.push({ selector, selected: option.selected });
1273
- }
1274
- }
1275
- }
1276
- states.push({
1277
- selector: "",
1278
- scrollTop: root.scrollTop,
1279
- scrollLeft: root.scrollLeft
1280
- });
1281
- if (includeDocumentScroll) {
1282
- const scrollingEl = root.ownerDocument?.scrollingElement;
1283
- if (scrollingEl && scrollingEl !== root) {
1284
- states.push({
1285
- selector: ":root",
1286
- scrollTop: scrollingEl.scrollTop,
1287
- scrollLeft: scrollingEl.scrollLeft
1288
- });
1289
- }
1290
- }
1291
- for (const el of root.querySelectorAll("*")) {
1292
- if (el.scrollTop > 0 || el.scrollLeft > 0) {
1293
- const selector = generateSelector(el, root);
1294
- states.push({
1295
- selector,
1296
- scrollTop: el.scrollTop,
1297
- scrollLeft: el.scrollLeft
1298
- });
1299
- }
1300
- }
1301
- return states;
1302
- }
1303
-
1304
- // ../../modules/iframe-projection/html/watch-dom.ts
1305
- var DOM_ID_ATTR = "data-dom-id";
1306
- var sessionHash = null;
1307
- var idCounter = 0;
1308
- function getOrCreateSessionHash() {
1309
- if (sessionHash === null) {
1310
- sessionHash = Math.random().toString(36).substring(2, 6);
1311
- }
1312
- return sessionHash;
1313
- }
1314
- function assignDomId(element) {
1315
- const existing = element.getAttribute(DOM_ID_ATTR);
1316
- if (existing !== null) {
1317
- return existing;
974
+ function assignDomId(element) {
975
+ const existing = element.getAttribute(DOM_ID_ATTR);
976
+ if (existing !== null) {
977
+ return existing;
1318
978
  }
1319
979
  const id = `${getOrCreateSessionHash()}-${idCounter++}`;
1320
980
  element.setAttribute(DOM_ID_ATTR, id);
@@ -1511,598 +1171,676 @@ function hasPendingMutations(watcher) {
1511
1171
  return watcher.mutatedElements.size > 0;
1512
1172
  }
1513
1173
 
1514
- // ../../modules/iframe-projection/html/watch-state.ts
1515
- function watchState(root, onStateChange) {
1516
- const scrolledElements = /* @__PURE__ */ new Set();
1517
- const changedFormElements = /* @__PURE__ */ new Set();
1518
- const handleScroll = (event) => {
1519
- const target = event.target;
1520
- if (target instanceof Element && root.contains(target)) {
1521
- scrolledElements.add(target);
1522
- watcher.stateRecordCount += 1;
1523
- onStateChange();
1524
- } else if (target === document) {
1525
- const scrollTarget = document.scrollingElement || document.documentElement;
1526
- if (scrollTarget) {
1527
- scrolledElements.add(scrollTarget);
1528
- watcher.stateRecordCount += 1;
1529
- onStateChange();
1174
+ // ../../modules/iframe-projection/html/declared-facts.ts
1175
+ var SOURCE_ANNOTATED_SELECTOR = "[data-tempo-filepath], [data-tempo-html-filepath]";
1176
+ var NAMESPACES = [
1177
+ {
1178
+ filepathAttr: "data-tempo-filepath",
1179
+ positionAttr: "data-tempo-position",
1180
+ modifiedTsAttr: "data-tempo-modifiedts",
1181
+ sourceVersionAttr: "data-tempo-source-version"
1182
+ },
1183
+ {
1184
+ filepathAttr: "data-tempo-html-filepath",
1185
+ positionAttr: "data-tempo-html-offset",
1186
+ modifiedTsAttr: "data-tempo-html-modifiedts",
1187
+ sourceVersionAttr: "data-tempo-html-source-version"
1188
+ }
1189
+ ];
1190
+ function computeDeclaredFacts(targetElement, captureRoot, scopeSelector, portalElements) {
1191
+ const observedVersions = {};
1192
+ const observedSourceVersions = {};
1193
+ const anchorSet = /* @__PURE__ */ new Set();
1194
+ const visit = (element) => {
1195
+ for (const ns of NAMESPACES) {
1196
+ const filepath = element.getAttribute(ns.filepathAttr);
1197
+ if (filepath == null || filepath.length === 0) continue;
1198
+ const modifiedTsRaw = element.getAttribute(ns.modifiedTsAttr);
1199
+ if (modifiedTsRaw != null) {
1200
+ const modifiedTs = Number(modifiedTsRaw);
1201
+ if (!Number.isNaN(modifiedTs)) {
1202
+ const existing = observedVersions[filepath];
1203
+ if (existing === void 0 || modifiedTs > existing) {
1204
+ observedVersions[filepath] = modifiedTs;
1205
+ const version = element.getAttribute(ns.sourceVersionAttr);
1206
+ if (version != null && version.length > 0) {
1207
+ observedSourceVersions[filepath] = version;
1208
+ } else {
1209
+ delete observedSourceVersions[filepath];
1210
+ }
1211
+ }
1212
+ }
1213
+ }
1214
+ const position = element.getAttribute(ns.positionAttr);
1215
+ if (position != null && position.length > 0) {
1216
+ anchorSet.add(`${filepath} ${position}`);
1530
1217
  }
1531
1218
  }
1532
1219
  };
1533
- const handleFormChange = (event) => {
1534
- if (event.target instanceof Element && root.contains(event.target)) {
1535
- changedFormElements.add(event.target);
1536
- watcher.projectionFormEvents.set(
1537
- event.target,
1538
- event.type === "change" ? "change" : "input"
1539
- );
1540
- watcher.stateRecordCount += 1;
1541
- onStateChange();
1220
+ const walkRoots = [targetElement, ...portalElements];
1221
+ for (const root of walkRoots) {
1222
+ if (root.matches(SOURCE_ANNOTATED_SELECTOR)) visit(root);
1223
+ for (const annotated of root.querySelectorAll(SOURCE_ANNOTATED_SELECTOR)) {
1224
+ visit(annotated);
1542
1225
  }
1226
+ }
1227
+ const complete = targetElement === captureRoot;
1228
+ return {
1229
+ complete,
1230
+ scopeSelector: complete ? null : scopeSelector,
1231
+ observedVersions,
1232
+ observedSourceVersions,
1233
+ containedAnchors: Array.from(anchorSet),
1234
+ renderError: computeRenderError(captureRoot)
1543
1235
  };
1544
- document.addEventListener("scroll", handleScroll, true);
1545
- document.addEventListener("input", handleFormChange, true);
1546
- document.addEventListener("change", handleFormChange, true);
1547
- const watcher = {
1548
- root,
1549
- scrolledElements,
1550
- changedFormElements,
1551
- stateRecordCount: 0,
1552
- projectionFormEvents: /* @__PURE__ */ new Map(),
1553
- stop: () => {
1554
- document.removeEventListener("scroll", handleScroll, true);
1555
- document.removeEventListener("input", handleFormChange, true);
1556
- document.removeEventListener("change", handleFormChange, true);
1557
- scrolledElements.clear();
1558
- changedFormElements.clear();
1559
- watcher.stateRecordCount = 0;
1560
- watcher.projectionFormEvents.clear();
1561
- }
1236
+ }
1237
+ function computeRenderError(captureRoot) {
1238
+ const errorElement = captureRoot.matches('[data-render-error="true"]') ? captureRoot : captureRoot.querySelector('[data-render-error="true"]');
1239
+ if (!errorElement) return null;
1240
+ return {
1241
+ message: errorElement.getAttribute("data-render-error-message")
1562
1242
  };
1563
- return watcher;
1564
1243
  }
1565
- function flushStateWatcher(watcher) {
1566
- const { root, scrolledElements, changedFormElements } = watcher;
1567
- watcher.stateRecordCount = 0;
1568
- watcher.projectionFormEvents.clear();
1569
- const states = [];
1570
- const scrolled = new Set(scrolledElements);
1571
- const changed = new Set(changedFormElements);
1572
- scrolledElements.clear();
1573
- changedFormElements.clear();
1574
- for (const el of scrolled) {
1575
- const isDocumentScroll = el === document.scrollingElement || el === document.documentElement;
1576
- if (!isDocumentScroll && !root.contains(el)) continue;
1577
- const selector = isDocumentScroll ? ":root" : generateSelector(el, root);
1578
- states.push({
1579
- selector,
1580
- scrollTop: el.scrollTop,
1581
- scrollLeft: el.scrollLeft
1582
- });
1583
- }
1584
- for (const el of changed) {
1585
- if (!root.contains(el)) continue;
1586
- if (el instanceof HTMLInputElement) {
1587
- const isCheckable = el.type === "checkbox" || el.type === "radio";
1588
- const hasNonDefault = isCheckable ? el.checked !== el.defaultChecked : el.value !== el.defaultValue;
1589
- if (hasNonDefault) {
1590
- const selector = generateSelector(el, root);
1591
- if (isCheckable) {
1592
- states.push({ selector, checked: el.checked });
1593
- } else {
1594
- states.push({ selector, value: el.value });
1595
- }
1596
- changedFormElements.add(el);
1597
- }
1598
- } else if (el instanceof HTMLTextAreaElement) {
1599
- if (el.value !== el.defaultValue) {
1600
- const selector = generateSelector(el, root);
1601
- states.push({ selector, value: el.value });
1602
- changedFormElements.add(el);
1603
- }
1604
- } else if (el instanceof HTMLSelectElement) {
1605
- let hasNonDefault = false;
1606
- for (const option of el.options) {
1607
- if (option.selected !== option.defaultSelected) {
1608
- const selector = generateSelector(option, root);
1609
- states.push({ selector, selected: option.selected });
1610
- hasNonDefault = true;
1611
- }
1612
- }
1613
- if (hasNonDefault) {
1614
- changedFormElements.add(el);
1615
- }
1244
+
1245
+ // ../../modules/iframe-projection/html/displayability.ts
1246
+ var IGNORED_CONTENT_TAGS = /* @__PURE__ */ new Set([
1247
+ "DATALIST",
1248
+ "LINK",
1249
+ "META",
1250
+ "NOSCRIPT",
1251
+ "SCRIPT",
1252
+ "STYLE",
1253
+ "TEMPLATE"
1254
+ ]);
1255
+ var VISUAL_ASSET_TAGS = /* @__PURE__ */ new Set([
1256
+ "AUDIO",
1257
+ "CANVAS",
1258
+ "EMBED",
1259
+ "IFRAME",
1260
+ "IMG",
1261
+ "INPUT",
1262
+ "OBJECT",
1263
+ "SELECT",
1264
+ "SVG",
1265
+ "TEXTAREA",
1266
+ "VIDEO"
1267
+ ]);
1268
+ function measureComputedDisplayability(captureRoot, supplementalRoots = []) {
1269
+ const doc = captureRoot.ownerDocument;
1270
+ const view = doc.defaultView;
1271
+ if (!view || !captureRoot.isConnected || supplementalRoots.some(
1272
+ (root) => root.ownerDocument !== doc || !root.isConnected
1273
+ )) {
1274
+ return null;
1275
+ }
1276
+ const result = {
1277
+ version: 1,
1278
+ elementCount: 0,
1279
+ paintedElementCount: 0,
1280
+ nonEmptyTextNodeCount: 0,
1281
+ visualAssetCount: 0
1282
+ };
1283
+ try {
1284
+ const rootBlocked = hasBlockingElementInChain(captureRoot, view);
1285
+ const rootTextVisible = !rootBlocked && elementHasVisibleComputedVisibility(captureRoot, view);
1286
+ for (const child of Array.from(captureRoot.childNodes)) {
1287
+ visitNode(child, rootBlocked, rootTextVisible, view, result);
1288
+ }
1289
+ for (const supplementalRoot of supplementalRoots) {
1290
+ visitNode(
1291
+ supplementalRoot,
1292
+ hasBlockingElementInChain(supplementalRoot.parentElement, view),
1293
+ true,
1294
+ view,
1295
+ result
1296
+ );
1616
1297
  }
1298
+ } catch {
1299
+ return null;
1617
1300
  }
1618
- return states;
1301
+ return result;
1619
1302
  }
1620
- function drainProjectionStateEvents(watcher) {
1621
- const events = [];
1622
- for (const element of watcher.scrolledElements) {
1623
- const isDocumentScroll = element === watcher.root.ownerDocument.scrollingElement || element === watcher.root.ownerDocument.documentElement;
1624
- events.push({
1625
- element: isDocumentScroll ? watcher.root : element,
1626
- eventKind: "scroll"
1627
- });
1303
+ function visitNode(node, blockedByAncestor, parentTextVisible, view, result) {
1304
+ if (node.nodeType === 3) {
1305
+ if (!blockedByAncestor && parentTextVisible && (node.textContent?.trim().length ?? 0) > 0) {
1306
+ result.nonEmptyTextNodeCount += 1;
1307
+ }
1308
+ return;
1628
1309
  }
1629
- for (const [element, eventKind] of watcher.projectionFormEvents) {
1630
- events.push({ element, eventKind });
1310
+ if (node.nodeType !== 1) return;
1311
+ const element = node;
1312
+ const blocked = blockedByAncestor || elementBlocksSubtree(element, view);
1313
+ if (blocked) return;
1314
+ const visible = elementHasVisibleComputedVisibility(element, view);
1315
+ if (visible) {
1316
+ result.elementCount += 1;
1317
+ if (elementPaintsOwnPixels(element, view)) {
1318
+ result.paintedElementCount = (result.paintedElementCount ?? 0) + 1;
1319
+ }
1320
+ if (VISUAL_ASSET_TAGS.has(element.tagName)) {
1321
+ result.visualAssetCount += 1;
1322
+ }
1323
+ }
1324
+ for (const child of Array.from(element.childNodes)) {
1325
+ visitNode(child, false, visible, view, result);
1631
1326
  }
1632
- watcher.scrolledElements.clear();
1633
- watcher.changedFormElements.clear();
1634
- watcher.projectionFormEvents.clear();
1635
- watcher.stateRecordCount = 0;
1636
- return events;
1637
1327
  }
1638
- function hasPendingStateChanges(watcher) {
1639
- return watcher.scrolledElements.size > 0 || watcher.changedFormElements.size > 0;
1328
+ function elementPaintsOwnPixels(element, view) {
1329
+ countCaptureStyleRead();
1330
+ const style = view.getComputedStyle(element);
1331
+ if (colorCanPaint(style.backgroundColor)) return true;
1332
+ if (style.backgroundImage && style.backgroundImage !== "none") return true;
1333
+ if (style.boxShadow && style.boxShadow !== "none") return true;
1334
+ if (style.outlineStyle !== "none" && parseFloat(style.outlineWidth) > 0 && colorCanPaint(style.outlineColor)) {
1335
+ return true;
1336
+ }
1337
+ for (const side of ["Top", "Right", "Bottom", "Left"]) {
1338
+ if (style[`border${side}Style`] !== "none" && parseFloat(style[`border${side}Width`]) > 0 && colorCanPaint(style[`border${side}Color`])) {
1339
+ return true;
1340
+ }
1341
+ }
1342
+ return false;
1640
1343
  }
1641
-
1642
- // ../../modules/iframe-projection/html/watch-portal.ts
1643
- var portalIdCounter = 0;
1644
- var PORTAL_ID_ATTR = "data-projection-portal-id";
1645
- function getOrAssignPortalId(element) {
1646
- const existing = element.getAttribute(PORTAL_ID_ATTR);
1647
- if (existing) return existing;
1648
- const id = `portal-${++portalIdCounter}`;
1649
- element.setAttribute(PORTAL_ID_ATTR, id);
1650
- return id;
1344
+ function colorCanPaint(value) {
1345
+ const normalized = value.trim().toLowerCase().replace(/ /g, "");
1346
+ if (!normalized || normalized === "transparent") return false;
1347
+ return !(/^rgba\([^)]*,0(?:\.0+)?\)$/.test(normalized) || /^rgb\([^)]*\/0(?:\.0+)?\)$/.test(normalized));
1651
1348
  }
1652
- function watchPortal(element, onTrigger, coordinateRoot) {
1653
- const id = getOrAssignPortalId(element);
1654
- const domWatcher = watchDom(element, onTrigger);
1655
- const stateWatcher = watchState(element, onTrigger);
1656
- return {
1657
- id,
1349
+ function hasBlockingElementInChain(start, view) {
1350
+ for (let element = start; element; element = element.parentElement) {
1351
+ if (elementBlocksSubtree(element, view)) return true;
1352
+ }
1353
+ return false;
1354
+ }
1355
+ function elementBlocksSubtree(element, view) {
1356
+ if (IGNORED_CONTENT_TAGS.has(element.tagName)) return true;
1357
+ if (element.hasAttribute("hidden")) return true;
1358
+ if (element.tagName === "DIALOG" && !element.hasAttribute("open")) {
1359
+ return true;
1360
+ }
1361
+ if (element.tagName === "INPUT" && element.getAttribute("type")?.trim().toLowerCase() === "hidden") {
1362
+ return true;
1363
+ }
1364
+ countCaptureStyleRead();
1365
+ const style = view.getComputedStyle(element);
1366
+ const opacity = style.opacity.trim();
1367
+ return style.display === "none" || opacity.length > 0 && Number(opacity) <= 0 || style.getPropertyValue("content-visibility") === "hidden";
1368
+ }
1369
+ function elementHasVisibleComputedVisibility(element, view) {
1370
+ countCaptureStyleRead();
1371
+ const visibility = view.getComputedStyle(element).visibility;
1372
+ return visibility !== "hidden" && visibility !== "collapse";
1373
+ }
1374
+
1375
+ // ../../modules/iframe-projection/html/capture.ts
1376
+ function captureWithSupplementalRoots(element, supplementalRoots) {
1377
+ syncFormStateToAttributes(element);
1378
+ const selector = generateSelector(element, element);
1379
+ const html = removeScriptTags(element.innerHTML);
1380
+ const attributes = captureAttributes(element);
1381
+ const documentElementAttributes = element.ownerDocument ? captureAttributes(element.ownerDocument.documentElement) : void 0;
1382
+ const bodyAttributes = element.ownerDocument?.body ? captureAttributes(element.ownerDocument.body) : void 0;
1383
+ const baseUrl = element.ownerDocument?.baseURI;
1384
+ const states = collectElementStates(element);
1385
+ const displayability = measureComputedDisplayability(
1658
1386
  element,
1659
- hasPendingChanges() {
1660
- return hasPendingMutations(domWatcher) || hasPendingStateChanges(stateWatcher);
1661
- },
1662
- pendingRecordCount() {
1663
- return domWatcher.mutationRecordCount + stateWatcher.stateRecordCount;
1664
- },
1665
- clearPendingChanges() {
1666
- drainProjectionDomMutations(domWatcher);
1667
- return drainProjectionStateEvents(stateWatcher);
1668
- },
1669
- flush(isInitial = false) {
1670
- const hasDomChanges = hasPendingMutations(domWatcher);
1671
- const hasStateChanges = hasPendingStateChanges(stateWatcher);
1672
- if (!isInitial && !hasDomChanges && !hasStateChanges) {
1673
- return null;
1674
- }
1675
- let targetElement = element;
1676
- if (!isInitial && hasDomChanges) {
1677
- const lca = flushDomWatcher(domWatcher);
1678
- if (lca && element.contains(lca)) {
1679
- targetElement = lca;
1680
- }
1681
- } else {
1682
- flushDomWatcher(domWatcher);
1683
- }
1684
- const states = flushStateWatcher(stateWatcher);
1685
- const selector = generateSelector(targetElement, element);
1686
- const html = removeScriptTags(targetElement.outerHTML);
1687
- const coordinateSpace = coordinateRoot ? capturePortalCoordinateSpace(coordinateRoot, element) : void 0;
1688
- return {
1689
- id,
1690
- selector,
1691
- html,
1692
- states,
1693
- ...coordinateSpace && { coordinateSpace }
1694
- };
1695
- },
1696
- resampleCoordinates() {
1697
- const coordinateSpace = coordinateRoot ? capturePortalCoordinateSpace(coordinateRoot, element) : void 0;
1698
- if (!coordinateSpace) return null;
1699
- return {
1700
- id,
1701
- selector: "",
1702
- html: "",
1703
- states: [],
1704
- coordinateSpace,
1705
- coordinatesOnly: true
1706
- };
1387
+ supplementalRoots
1388
+ );
1389
+ return {
1390
+ // Whole-surface one-shot: the element is both the capture root and the
1391
+ // serialized scope, so `complete` is true and there is no scope selector.
1392
+ declared: computeDeclaredFacts(element, element, "", supplementalRoots),
1393
+ ...displayability && { displayability },
1394
+ dom: {
1395
+ selector,
1396
+ html,
1397
+ attributes,
1398
+ documentElementAttributes,
1399
+ bodyAttributes
1707
1400
  },
1708
- stop() {
1709
- domWatcher.stop();
1710
- stateWatcher.stop();
1711
- }
1401
+ states,
1402
+ baseUrl
1712
1403
  };
1713
1404
  }
1714
- function capturePortalCoordinateSpace(root, portal) {
1715
- const viewport = root.ownerDocument?.defaultView;
1716
- if (!viewport) return void 0;
1717
- const rect = root.getBoundingClientRect();
1718
- return {
1719
- origin: portal ? choosePortalCoordinateOrigin(rect, portal) : "root",
1720
- rootViewportLeft: rect.left,
1721
- rootViewportTop: rect.top,
1722
- viewportWidth: viewport.innerWidth,
1723
- viewportHeight: viewport.innerHeight
1724
- };
1725
- }
1726
- function choosePortalCoordinateOrigin(rootRect, portal) {
1727
- const portalRect = measurePortalBounds(portal);
1728
- const localViewport = {
1729
- left: 0,
1730
- top: 0,
1731
- right: rootRect.width,
1732
- bottom: rootRect.height
1733
- };
1734
- const coversSourceViewport = portalRect.left <= 0 && portalRect.top <= 0 && portalRect.right >= (portal.ownerDocument.defaultView?.innerWidth ?? 0) && portalRect.bottom >= (portal.ownerDocument.defaultView?.innerHeight ?? 0);
1735
- if (coversSourceViewport) return "viewport";
1736
- if (rectanglesOverlap(rootRect, portalRect)) return "root";
1737
- const directScore = visibleArea(portalRect, localViewport);
1738
- const rebasedScore = visibleArea(
1739
- {
1740
- left: portalRect.left - rootRect.left,
1741
- top: portalRect.top - rootRect.top,
1742
- right: portalRect.right - rootRect.left,
1743
- bottom: portalRect.bottom - rootRect.top
1744
- },
1745
- localViewport
1746
- );
1747
- if (rebasedScore > directScore) return "root";
1748
- if (directScore > rebasedScore) return "viewport";
1749
- return "viewport";
1750
- }
1751
- function measurePortalBounds(portal) {
1752
- const ownRect = portal.getBoundingClientRect();
1753
- if (hasArea(ownRect)) return ownRect;
1754
- let left = Number.POSITIVE_INFINITY;
1755
- let top = Number.POSITIVE_INFINITY;
1756
- let right = Number.NEGATIVE_INFINITY;
1757
- let bottom = Number.NEGATIVE_INFINITY;
1758
- for (const descendant of Array.from(portal.querySelectorAll("*"))) {
1759
- const rect = descendant.getBoundingClientRect();
1760
- if (!hasArea(rect)) continue;
1761
- left = Math.min(left, rect.left);
1762
- top = Math.min(top, rect.top);
1763
- right = Math.max(right, rect.right);
1764
- bottom = Math.max(bottom, rect.bottom);
1405
+ function syncFormStateToAttributes(root) {
1406
+ for (const input of root.querySelectorAll(
1407
+ 'input[type="checkbox"], input[type="radio"]'
1408
+ )) {
1409
+ const el = input;
1410
+ if (el.checked) {
1411
+ el.setAttribute("checked", "");
1412
+ } else {
1413
+ el.removeAttribute("checked");
1414
+ }
1415
+ }
1416
+ for (const input of root.querySelectorAll(
1417
+ 'input:not([type="checkbox"]):not([type="radio"])'
1418
+ )) {
1419
+ const el = input;
1420
+ if (el.value !== el.getAttribute("value")) {
1421
+ el.setAttribute("value", el.value);
1422
+ }
1423
+ }
1424
+ for (const textarea of root.querySelectorAll("textarea")) {
1425
+ const el = textarea;
1426
+ if (el.value !== el.textContent) {
1427
+ el.textContent = el.value;
1428
+ }
1429
+ if (el.hasAttribute("value")) {
1430
+ el.removeAttribute("value");
1431
+ }
1432
+ }
1433
+ for (const select of root.querySelectorAll("select")) {
1434
+ const el = select;
1435
+ for (const option of el.options) {
1436
+ if (option.selected) {
1437
+ option.setAttribute("selected", "");
1438
+ } else {
1439
+ option.removeAttribute("selected");
1440
+ }
1441
+ }
1765
1442
  }
1766
- return Number.isFinite(left) ? { left, top, right, bottom } : ownRect;
1767
- }
1768
- function hasArea(rect) {
1769
- return rect.right > rect.left && rect.bottom > rect.top;
1770
- }
1771
- function visibleArea(rect, viewport) {
1772
- const width = Math.max(
1773
- 0,
1774
- Math.min(rect.right, viewport.right) - Math.max(rect.left, viewport.left)
1775
- );
1776
- const height = Math.max(
1777
- 0,
1778
- Math.min(rect.bottom, viewport.bottom) - Math.max(rect.top, viewport.top)
1779
- );
1780
- return width * height;
1781
- }
1782
- function rectanglesOverlap(a, b) {
1783
- return a.left < b.right && a.right > b.left && a.top < b.bottom && a.bottom > b.top;
1784
1443
  }
1785
-
1786
- // ../../modules/iframe-projection/combined/css-escape.ts
1787
- function cssEscape(value) {
1788
- return globalThis.CSS?.escape ? globalThis.CSS.escape(value) : value.replace(/["\\]/g, "\\$&");
1444
+ function removeScriptTags(html) {
1445
+ return html.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi, "");
1789
1446
  }
1790
-
1791
- // ../../modules/iframe-projection/combined/projection-observed-files.ts
1792
- var ProjectionObservedFileAccumulator = class {
1793
- constructor() {
1794
- this.files = /* @__PURE__ */ new Map();
1447
+ function captureAttributes(element) {
1448
+ const attrs = {};
1449
+ for (const attr of Array.from(element.attributes)) {
1450
+ attrs[attr.name] = attr.value;
1795
1451
  }
1796
- add(filepath, modifiedTsRaw, sourceVersionRaw) {
1797
- if (typeof filepath !== "string" || filepath.length === 0) return;
1798
- const modifiedTs = typeof modifiedTsRaw === "number" ? modifiedTsRaw : typeof modifiedTsRaw === "string" ? Number(modifiedTsRaw) : Number.NaN;
1799
- if (!Number.isFinite(modifiedTs)) return;
1800
- const sourceVersion = typeof sourceVersionRaw === "string" && sourceVersionRaw.length > 0 ? sourceVersionRaw : void 0;
1801
- const current = this.files.get(filepath);
1802
- if (!current) {
1803
- this.files.set(filepath, {
1804
- modifiedTs,
1805
- sourceVersion
1806
- });
1807
- return;
1452
+ return attrs;
1453
+ }
1454
+ function collectElementStates(root, options = {}) {
1455
+ const { includeDocumentScroll = true } = options;
1456
+ const states = [];
1457
+ for (const input of root.querySelectorAll("input")) {
1458
+ const el = input;
1459
+ const isCheckable = el.type === "checkbox" || el.type === "radio";
1460
+ const hasNonDefault = isCheckable ? el.checked !== el.defaultChecked : el.value !== el.defaultValue;
1461
+ if (hasNonDefault) {
1462
+ const selector = generateSelector(el, root);
1463
+ if (isCheckable) {
1464
+ states.push({ selector, checked: el.checked });
1465
+ } else {
1466
+ states.push({ selector, value: el.value });
1467
+ }
1808
1468
  }
1809
- current.modifiedTs = Math.min(current.modifiedTs, modifiedTs);
1810
- if (sourceVersion === void 0 || current.sourceVersion === void 0 || current.sourceVersion !== sourceVersion) {
1811
- current.sourceVersion = void 0;
1469
+ }
1470
+ for (const textarea of root.querySelectorAll("textarea")) {
1471
+ const el = textarea;
1472
+ if (el.value !== el.defaultValue) {
1473
+ const selector = generateSelector(el, root);
1474
+ states.push({ selector, value: el.value });
1812
1475
  }
1813
1476
  }
1814
- merge(files) {
1815
- if (!files) return;
1816
- for (const [filepath, fact] of Object.entries(files)) {
1817
- this.add(filepath, fact.modifiedTs, fact.sourceVersion);
1477
+ for (const select of root.querySelectorAll("select")) {
1478
+ const el = select;
1479
+ for (const option of el.options) {
1480
+ if (option.selected !== option.defaultSelected) {
1481
+ const selector = generateSelector(option, root);
1482
+ states.push({ selector, selected: option.selected });
1483
+ }
1818
1484
  }
1819
1485
  }
1820
- addElement(element) {
1821
- this.add(
1822
- element.getAttribute("data-tempo-filepath"),
1823
- element.getAttribute("data-tempo-modifiedts"),
1824
- element.getAttribute("data-tempo-source-version")
1825
- );
1826
- this.add(
1827
- element.getAttribute("data-tempo-html-filepath"),
1828
- element.getAttribute("data-tempo-html-modifiedts"),
1829
- element.getAttribute("data-tempo-html-source-version")
1830
- );
1486
+ states.push({
1487
+ selector: "",
1488
+ scrollTop: root.scrollTop,
1489
+ scrollLeft: root.scrollLeft
1490
+ });
1491
+ if (includeDocumentScroll) {
1492
+ const scrollingEl = root.ownerDocument?.scrollingElement;
1493
+ if (scrollingEl && scrollingEl !== root) {
1494
+ states.push({
1495
+ selector: ":root",
1496
+ scrollTop: scrollingEl.scrollTop,
1497
+ scrollLeft: scrollingEl.scrollLeft
1498
+ });
1499
+ }
1831
1500
  }
1832
- snapshot() {
1833
- return Object.fromEntries(
1834
- Array.from(this.files, ([filepath, fact]) => [
1835
- filepath,
1836
- {
1837
- modifiedTs: fact.modifiedTs,
1838
- ...fact.sourceVersion !== void 0 ? { sourceVersion: fact.sourceVersion } : {}
1839
- }
1840
- ])
1841
- );
1501
+ for (const el of root.querySelectorAll("*")) {
1502
+ if (el.scrollTop > 0 || el.scrollLeft > 0) {
1503
+ const selector = generateSelector(el, root);
1504
+ states.push({
1505
+ selector,
1506
+ scrollTop: el.scrollTop,
1507
+ scrollLeft: el.scrollLeft
1508
+ });
1509
+ }
1842
1510
  }
1843
- };
1511
+ return states;
1512
+ }
1844
1513
 
1845
- // ../../modules/iframe-projection/combined/projection-layer-snapshot.ts
1846
- var COMPONENT_TAGS = /* @__PURE__ */ new Set([
1847
- FiberTag.FunctionComponent,
1848
- FiberTag.ClassComponent,
1849
- FiberTag.ForwardRef,
1850
- FiberTag.MemoComponent,
1851
- FiberTag.SimpleMemoComponent,
1852
- FiberTag.LazyComponent
1853
- ]);
1854
- function createProjectionLayerSerializer() {
1855
- let nextFiberId2 = 1;
1856
- const fiberIds = /* @__PURE__ */ new WeakMap();
1857
- const fiberId = (fiber) => {
1858
- const direct = fiberIds.get(fiber);
1859
- if (direct) return direct;
1860
- const alternate = fiber.alternate ? fiberIds.get(fiber.alternate) : null;
1861
- if (alternate) {
1862
- fiberIds.set(fiber, alternate);
1863
- return alternate;
1514
+ // ../../modules/iframe-projection/html/watch-state.ts
1515
+ function watchState(root, onStateChange) {
1516
+ const scrolledElements = /* @__PURE__ */ new Set();
1517
+ const changedFormElements = /* @__PURE__ */ new Set();
1518
+ const handleScroll = (event) => {
1519
+ const target = event.target;
1520
+ if (target instanceof Element && root.contains(target)) {
1521
+ scrolledElements.add(target);
1522
+ watcher.stateRecordCount += 1;
1523
+ onStateChange();
1524
+ } else if (target === document) {
1525
+ const scrollTarget = document.scrollingElement || document.documentElement;
1526
+ if (scrollTarget) {
1527
+ scrolledElements.add(scrollTarget);
1528
+ watcher.stateRecordCount += 1;
1529
+ onStateChange();
1530
+ }
1864
1531
  }
1865
- const id = String(nextFiberId2++);
1866
- fiberIds.set(fiber, id);
1867
- if (fiber.alternate) fiberIds.set(fiber.alternate, id);
1868
- return id;
1869
1532
  };
1870
- const knownFiberId = (fiber) => fiberIds.get(fiber) ?? (fiber.alternate ? fiberIds.get(fiber.alternate) : void 0) ?? null;
1871
- const serialize = (root) => {
1872
- const observedFiles = new ProjectionObservedFileAccumulator();
1873
- let fiberNodesVisited = 0;
1874
- let semanticNodesSerialized = 0;
1875
- const visit = (fiber, emitLayer) => {
1876
- fiberNodesVisited += 1;
1877
- const name = getDisplayName(fiber);
1878
- const kind = projectionKindForTag(fiber.tag);
1879
- const included = isProjectionLayerFiber(fiber);
1880
- const element = kind === "host" ? getDomElement(fiber) : null;
1881
- const domId = element ? ensureProjectionDomId(element) : null;
1882
- const props = included ? captureProjectionLayerProps(fiber, element) : void 0;
1883
- if (props) {
1884
- observedFiles.add(
1885
- props["data-tempo-filepath"],
1886
- props["data-tempo-modifiedts"],
1887
- props["data-tempo-source-version"]
1888
- );
1889
- observedFiles.add(
1890
- props["data-tempo-html-filepath"],
1891
- props["data-tempo-html-modifiedts"],
1892
- props["data-tempo-html-source-version"]
1893
- );
1533
+ const handleFormChange = (event) => {
1534
+ if (event.target instanceof Element && root.contains(event.target)) {
1535
+ changedFormElements.add(event.target);
1536
+ watcher.projectionFormEvents.set(
1537
+ event.target,
1538
+ event.type === "change" ? "change" : "input"
1539
+ );
1540
+ watcher.stateRecordCount += 1;
1541
+ onStateChange();
1542
+ }
1543
+ };
1544
+ document.addEventListener("scroll", handleScroll, true);
1545
+ document.addEventListener("input", handleFormChange, true);
1546
+ document.addEventListener("change", handleFormChange, true);
1547
+ const watcher = {
1548
+ root,
1549
+ scrolledElements,
1550
+ changedFormElements,
1551
+ stateRecordCount: 0,
1552
+ projectionFormEvents: /* @__PURE__ */ new Map(),
1553
+ stop: () => {
1554
+ document.removeEventListener("scroll", handleScroll, true);
1555
+ document.removeEventListener("input", handleFormChange, true);
1556
+ document.removeEventListener("change", handleFormChange, true);
1557
+ scrolledElements.clear();
1558
+ changedFormElements.clear();
1559
+ watcher.stateRecordCount = 0;
1560
+ watcher.projectionFormEvents.clear();
1561
+ }
1562
+ };
1563
+ return watcher;
1564
+ }
1565
+ function flushStateWatcher(watcher) {
1566
+ const { root, scrolledElements, changedFormElements } = watcher;
1567
+ watcher.stateRecordCount = 0;
1568
+ watcher.projectionFormEvents.clear();
1569
+ const states = [];
1570
+ const scrolled = new Set(scrolledElements);
1571
+ const changed = new Set(changedFormElements);
1572
+ scrolledElements.clear();
1573
+ changedFormElements.clear();
1574
+ for (const el of scrolled) {
1575
+ const isDocumentScroll = el === document.scrollingElement || el === document.documentElement;
1576
+ if (!isDocumentScroll && !root.contains(el)) continue;
1577
+ const selector = isDocumentScroll ? ":root" : generateSelector(el, root);
1578
+ states.push({
1579
+ selector,
1580
+ scrollTop: el.scrollTop,
1581
+ scrollLeft: el.scrollLeft
1582
+ });
1583
+ }
1584
+ for (const el of changed) {
1585
+ if (!root.contains(el)) continue;
1586
+ if (el instanceof HTMLInputElement) {
1587
+ const isCheckable = el.type === "checkbox" || el.type === "radio";
1588
+ const hasNonDefault = isCheckable ? el.checked !== el.defaultChecked : el.value !== el.defaultValue;
1589
+ if (hasNonDefault) {
1590
+ const selector = generateSelector(el, root);
1591
+ if (isCheckable) {
1592
+ states.push({ selector, checked: el.checked });
1593
+ } else {
1594
+ states.push({ selector, value: el.value });
1595
+ }
1596
+ changedFormElements.add(el);
1894
1597
  }
1895
- const isSvgLeaf = included && kind === "host" && name.toLowerCase() === "svg";
1896
- const isContentEditableBoundary2 = included && kind === "host" && element?.getAttribute("contenteditable") !== null;
1897
- const children = [];
1898
- if (!isContentEditableBoundary2) {
1899
- for (let child = fiber.child; child; child = child.sibling) {
1900
- children.push(...visit(child, emitLayer && !isSvgLeaf));
1598
+ } else if (el instanceof HTMLTextAreaElement) {
1599
+ if (el.value !== el.defaultValue) {
1600
+ const selector = generateSelector(el, root);
1601
+ states.push({ selector, value: el.value });
1602
+ changedFormElements.add(el);
1603
+ }
1604
+ } else if (el instanceof HTMLSelectElement) {
1605
+ let hasNonDefault = false;
1606
+ for (const option of el.options) {
1607
+ if (option.selected !== option.defaultSelected) {
1608
+ const selector = generateSelector(option, root);
1609
+ states.push({ selector, selected: option.selected });
1610
+ hasNonDefault = true;
1901
1611
  }
1902
1612
  }
1903
- if (!emitLayer) return [];
1904
- if (!included) return children;
1905
- if (kind === null) return children;
1906
- const source = {
1907
- kind: "react-fiber",
1908
- fiber: { tag: fiber.tag, name, id: fiberId(fiber) }
1909
- };
1910
- let node;
1911
- if (kind === "host") {
1912
- node = {
1913
- kind,
1914
- name,
1915
- domId,
1916
- elementTag: name,
1917
- props,
1918
- source,
1919
- children: isSvgLeaf || isContentEditableBoundary2 ? [] : children
1920
- };
1921
- } else {
1922
- node = {
1923
- kind,
1924
- name,
1925
- domId: null,
1926
- elementTag: null,
1927
- props,
1928
- source,
1929
- children
1930
- };
1613
+ if (hasNonDefault) {
1614
+ changedFormElements.add(el);
1931
1615
  }
1932
- semanticNodesSerialized += 1;
1933
- return [node];
1934
- };
1935
- const branches = visit(root, true);
1936
- let tree;
1937
- if (branches.length === 1) {
1938
- tree = branches[0] ?? null;
1939
- } else if (root.tag === FiberTag.HostRoot) {
1940
- const name = getDisplayName(root);
1941
- tree = {
1942
- kind: "fragment",
1943
- name,
1944
- domId: null,
1945
- elementTag: null,
1946
- source: {
1947
- kind: "react-fiber",
1948
- fiber: { tag: root.tag, name, id: fiberId(root) }
1949
- },
1950
- children: branches
1951
- };
1952
- semanticNodesSerialized += 1;
1953
- } else {
1954
- tree = null;
1955
1616
  }
1956
- return {
1957
- snapshot: {
1958
- semantic: { kind: "layers", tree },
1959
- observedFiles: observedFiles.snapshot()
1960
- },
1961
- fiberNodesVisited,
1962
- semanticNodesSerialized
1963
- };
1964
- };
1617
+ }
1618
+ return states;
1619
+ }
1620
+ function drainProjectionStateEvents(watcher) {
1621
+ const events = [];
1622
+ for (const element of watcher.scrolledElements) {
1623
+ const isDocumentScroll = element === watcher.root.ownerDocument.scrollingElement || element === watcher.root.ownerDocument.documentElement;
1624
+ events.push({
1625
+ element: isDocumentScroll ? watcher.root : element,
1626
+ eventKind: "scroll"
1627
+ });
1628
+ }
1629
+ for (const [element, eventKind] of watcher.projectionFormEvents) {
1630
+ events.push({ element, eventKind });
1631
+ }
1632
+ watcher.scrolledElements.clear();
1633
+ watcher.changedFormElements.clear();
1634
+ watcher.projectionFormEvents.clear();
1635
+ watcher.stateRecordCount = 0;
1636
+ return events;
1637
+ }
1638
+ function hasPendingStateChanges(watcher) {
1639
+ return watcher.scrolledElements.size > 0 || watcher.changedFormElements.size > 0;
1640
+ }
1641
+
1642
+ // ../../modules/iframe-projection/html/watch-portal.ts
1643
+ var portalIdCounter = 0;
1644
+ var PORTAL_ID_ATTR = "data-projection-portal-id";
1645
+ function getOrAssignPortalId(element) {
1646
+ const existing = element.getAttribute(PORTAL_ID_ATTR);
1647
+ if (existing) return existing;
1648
+ const id = `portal-${++portalIdCounter}`;
1649
+ element.setAttribute(PORTAL_ID_ATTR, id);
1650
+ return id;
1651
+ }
1652
+ function watchPortal(element, onTrigger, coordinateRoot) {
1653
+ const id = getOrAssignPortalId(element);
1654
+ const domWatcher = watchDom(element, onTrigger);
1655
+ const stateWatcher = watchState(element, onTrigger);
1965
1656
  return {
1966
- serialize,
1967
- fiberId,
1968
- knownFiberId,
1969
- serializeRegion(root) {
1970
- const targetFiberId = fiberId(root);
1971
- const serialized = serialize(root);
1657
+ id,
1658
+ element,
1659
+ hasPendingChanges() {
1660
+ return hasPendingMutations(domWatcher) || hasPendingStateChanges(stateWatcher);
1661
+ },
1662
+ pendingRecordCount() {
1663
+ return domWatcher.mutationRecordCount + stateWatcher.stateRecordCount;
1664
+ },
1665
+ clearPendingChanges() {
1666
+ drainProjectionDomMutations(domWatcher);
1667
+ return drainProjectionStateEvents(stateWatcher);
1668
+ },
1669
+ flush(isInitial = false) {
1670
+ const hasDomChanges = hasPendingMutations(domWatcher);
1671
+ const hasStateChanges = hasPendingStateChanges(stateWatcher);
1672
+ if (!isInitial && !hasDomChanges && !hasStateChanges) {
1673
+ return null;
1674
+ }
1675
+ let targetElement = element;
1676
+ if (!isInitial && hasDomChanges) {
1677
+ const lca = flushDomWatcher(domWatcher);
1678
+ if (lca && element.contains(lca)) {
1679
+ targetElement = lca;
1680
+ }
1681
+ } else {
1682
+ flushDomWatcher(domWatcher);
1683
+ }
1684
+ const states = flushStateWatcher(stateWatcher);
1685
+ const selector = generateSelector(targetElement, element);
1686
+ const html = removeScriptTags(targetElement.outerHTML);
1687
+ const coordinateSpace = coordinateRoot ? capturePortalCoordinateSpace(coordinateRoot, element) : void 0;
1972
1688
  return {
1973
- region: {
1974
- targetFiberId,
1975
- tree: serialized.snapshot.semantic.kind === "layers" ? serialized.snapshot.semantic.tree : null,
1976
- observedFiles: serialized.snapshot.observedFiles
1977
- },
1978
- fiberNodesVisited: serialized.fiberNodesVisited,
1979
- semanticNodesSerialized: serialized.semanticNodesSerialized
1689
+ id,
1690
+ selector,
1691
+ html,
1692
+ states,
1693
+ ...coordinateSpace && { coordinateSpace }
1980
1694
  };
1981
1695
  },
1982
- captureMetadata(root, options) {
1696
+ resampleCoordinates() {
1697
+ const coordinateSpace = coordinateRoot ? capturePortalCoordinateSpace(coordinateRoot, element) : void 0;
1698
+ if (!coordinateSpace) return null;
1983
1699
  return {
1984
- targetFiberId: fiberId(root),
1985
- props: captureProjectionLayerProps(
1986
- root,
1987
- root.tag === FiberTag.HostComponent ? getDomElement(root) : null,
1988
- options?.sourceAnnotations ?? "fiber"
1989
- )
1700
+ id,
1701
+ selector: "",
1702
+ html: "",
1703
+ states: [],
1704
+ coordinateSpace,
1705
+ coordinatesOnly: true
1990
1706
  };
1707
+ },
1708
+ stop() {
1709
+ domWatcher.stop();
1710
+ stateWatcher.stop();
1991
1711
  }
1992
1712
  };
1993
1713
  }
1994
- function isProjectionLayerFiber(fiber) {
1995
- if (isTempoHiddenFiber(fiber)) return false;
1996
- const kind = projectionKindForTag(fiber.tag);
1997
- if (kind === null) return false;
1998
- if (kind === "host") return true;
1999
- const sourceKey = projectionFiberSourceKey(fiber);
2000
- if (!sourceKey) return true;
2001
- for (let parent = fiber.return; parent; parent = parent.return) {
2002
- if (isTempoHiddenFiber(parent)) continue;
2003
- const parentKind = projectionKindForTag(parent.tag);
2004
- if (parentKind === null) continue;
2005
- if (parentKind === "host") return true;
2006
- return projectionFiberSourceKey(parent) !== sourceKey;
1714
+ function capturePortalCoordinateSpace(root, portal) {
1715
+ const viewport = root.ownerDocument?.defaultView;
1716
+ if (!viewport) return void 0;
1717
+ const rect = root.getBoundingClientRect();
1718
+ return {
1719
+ origin: portal ? choosePortalCoordinateOrigin(rect, portal) : "root",
1720
+ rootViewportLeft: rect.left,
1721
+ rootViewportTop: rect.top,
1722
+ viewportWidth: viewport.innerWidth,
1723
+ viewportHeight: viewport.innerHeight
1724
+ };
1725
+ }
1726
+ function choosePortalCoordinateOrigin(rootRect, portal) {
1727
+ const portalRect = measurePortalBounds(portal);
1728
+ const localViewport = {
1729
+ left: 0,
1730
+ top: 0,
1731
+ right: rootRect.width,
1732
+ bottom: rootRect.height
1733
+ };
1734
+ const coversSourceViewport = portalRect.left <= 0 && portalRect.top <= 0 && portalRect.right >= (portal.ownerDocument.defaultView?.innerWidth ?? 0) && portalRect.bottom >= (portal.ownerDocument.defaultView?.innerHeight ?? 0);
1735
+ if (coversSourceViewport) return "viewport";
1736
+ if (rectanglesOverlap(rootRect, portalRect)) return "root";
1737
+ const directScore = visibleArea(portalRect, localViewport);
1738
+ const rebasedScore = visibleArea(
1739
+ {
1740
+ left: portalRect.left - rootRect.left,
1741
+ top: portalRect.top - rootRect.top,
1742
+ right: portalRect.right - rootRect.left,
1743
+ bottom: portalRect.bottom - rootRect.top
1744
+ },
1745
+ localViewport
1746
+ );
1747
+ if (rebasedScore > directScore) return "root";
1748
+ if (directScore > rebasedScore) return "viewport";
1749
+ return "viewport";
1750
+ }
1751
+ function measurePortalBounds(portal) {
1752
+ const ownRect = portal.getBoundingClientRect();
1753
+ if (hasArea(ownRect)) return ownRect;
1754
+ let left = Number.POSITIVE_INFINITY;
1755
+ let top = Number.POSITIVE_INFINITY;
1756
+ let right = Number.NEGATIVE_INFINITY;
1757
+ let bottom = Number.NEGATIVE_INFINITY;
1758
+ for (const descendant of Array.from(portal.querySelectorAll("*"))) {
1759
+ const rect = descendant.getBoundingClientRect();
1760
+ if (!hasArea(rect)) continue;
1761
+ left = Math.min(left, rect.left);
1762
+ top = Math.min(top, rect.top);
1763
+ right = Math.max(right, rect.right);
1764
+ bottom = Math.max(bottom, rect.bottom);
2007
1765
  }
2008
- return true;
1766
+ return Number.isFinite(left) ? { left, top, right, bottom } : ownRect;
2009
1767
  }
2010
- function projectionKindForTag(tag) {
2011
- if (tag === FiberTag.HostComponent) return "host";
2012
- if (COMPONENT_TAGS.has(tag)) return "component";
2013
- return null;
1768
+ function hasArea(rect) {
1769
+ return rect.right > rect.left && rect.bottom > rect.top;
2014
1770
  }
2015
- function ascendToAnnotatedComponentRoot(fiber) {
2016
- let topmost = fiber;
2017
- for (let parent = fiber.return; parent; parent = parent.return) {
2018
- if (parent.tag === FiberTag.HostRoot || parent.tag === FiberTag.HostPortal) {
2019
- break;
1771
+ function visibleArea(rect, viewport) {
1772
+ const width = Math.max(
1773
+ 0,
1774
+ Math.min(rect.right, viewport.right) - Math.max(rect.left, viewport.left)
1775
+ );
1776
+ const height = Math.max(
1777
+ 0,
1778
+ Math.min(rect.bottom, viewport.bottom) - Math.max(rect.top, viewport.top)
1779
+ );
1780
+ return width * height;
1781
+ }
1782
+ function rectanglesOverlap(a, b) {
1783
+ return a.left < b.right && a.right > b.left && a.top < b.bottom && a.bottom > b.top;
1784
+ }
1785
+
1786
+ // ../../modules/iframe-projection/combined/css-escape.ts
1787
+ function cssEscape(value) {
1788
+ return globalThis.CSS?.escape ? globalThis.CSS.escape(value) : value.replace(/["\\]/g, "\\$&");
1789
+ }
1790
+
1791
+ // ../../modules/iframe-projection/combined/projection-observed-files.ts
1792
+ var ProjectionObservedFileAccumulator = class {
1793
+ constructor() {
1794
+ this.files = /* @__PURE__ */ new Map();
1795
+ }
1796
+ add(filepath, modifiedTsRaw, sourceVersionRaw) {
1797
+ if (typeof filepath !== "string" || filepath.length === 0) return;
1798
+ const modifiedTs = typeof modifiedTsRaw === "number" ? modifiedTsRaw : typeof modifiedTsRaw === "string" ? Number(modifiedTsRaw) : Number.NaN;
1799
+ if (!Number.isFinite(modifiedTs)) return;
1800
+ const sourceVersion = typeof sourceVersionRaw === "string" && sourceVersionRaw.length > 0 ? sourceVersionRaw : void 0;
1801
+ const current = this.files.get(filepath);
1802
+ if (!current) {
1803
+ this.files.set(filepath, {
1804
+ modifiedTs,
1805
+ sourceVersion
1806
+ });
1807
+ return;
2020
1808
  }
2021
- const kind = projectionKindForTag(parent.tag);
2022
- if (kind === "host") break;
2023
- if (isTempoHiddenFiber(parent)) break;
2024
- if (kind === "component") {
2025
- if (projectionFiberSourceKey(parent) === null) break;
2026
- topmost = parent;
1809
+ current.modifiedTs = Math.min(current.modifiedTs, modifiedTs);
1810
+ if (sourceVersion === void 0 || current.sourceVersion === void 0 || current.sourceVersion !== sourceVersion) {
1811
+ current.sourceVersion = void 0;
2027
1812
  }
2028
1813
  }
2029
- return topmost;
2030
- }
2031
- function isTempoHiddenFiber(fiber) {
2032
- const props = getProps(fiber);
2033
- const direct = props?.["data-tempo-hide-fiber"];
2034
- const dataSet = props?.dataSet;
2035
- const native = dataSet && typeof dataSet === "object" ? dataSet.tempoHideFiber : void 0;
2036
- const value = native ?? direct;
2037
- return value === true || value === "true";
2038
- }
2039
- function captureProjectionLayerProps(fiber, element, sourceAnnotations = "fiber") {
2040
- const raw = getProps(fiber);
2041
- const dataSet = raw?.dataSet && typeof raw.dataSet === "object" ? raw.dataSet : void 0;
2042
- const read = (flatKey, dataSetKey, authority = "source") => {
2043
- if (authority === "source" && element && sourceAnnotations === "live-host") {
2044
- return element.getAttribute(flatKey);
2045
- }
2046
- return dataSet && Object.hasOwn(dataSet, dataSetKey) ? dataSet[dataSetKey] : raw?.[flatKey];
2047
- };
2048
- const props = {};
2049
- const putString = (flatKey, dataSetKey) => {
2050
- const value = read(flatKey, dataSetKey);
2051
- if (typeof value === "string") props[flatKey] = value;
2052
- };
2053
- const putFiniteNumber = (flatKey, dataSetKey) => {
2054
- const value = read(flatKey, dataSetKey);
2055
- const numeric = typeof value === "number" ? value : typeof value === "string" ? Number(value) : Number.NaN;
2056
- if (Number.isFinite(numeric)) props[flatKey] = numeric;
2057
- };
2058
- const putStringified = (flatKey, dataSetKey) => {
2059
- const value = read(flatKey, dataSetKey);
2060
- if (typeof value === "string" || typeof value === "number") {
2061
- props[flatKey] = String(value);
1814
+ merge(files) {
1815
+ if (!files) return;
1816
+ for (const [filepath, fact] of Object.entries(files)) {
1817
+ this.add(filepath, fact.modifiedTs, fact.sourceVersion);
2062
1818
  }
2063
- };
2064
- const putBoolean = (flatKey, dataSetKey) => {
2065
- const value = read(flatKey, dataSetKey, "fiber");
2066
- if (value === true || value === "true") props[flatKey] = true;
2067
- if (value === false || value === "false") props[flatKey] = false;
2068
- };
2069
- putString("data-tempo-filepath", "tempoFilepath");
2070
- putFiniteNumber("data-tempo-position", "tempoPosition");
2071
- putFiniteNumber("data-tempo-modifiedts", "tempoModifiedts");
2072
- putString("data-tempo-source-version", "tempoSourceVersion");
2073
- putString("data-tempo-html-filepath", "tempoHtmlFilepath");
2074
- putStringified("data-tempo-html-offset", "tempoHtmlOffset");
2075
- putStringified("data-tempo-html-modifiedts", "tempoHtmlModifiedts");
2076
- putString("data-tempo-html-source-version", "tempoHtmlSourceVersion");
2077
- putBoolean("data-tempo-supports-style", "tempoSupportsStyle");
2078
- putBoolean("data-tempo-supports-classname", "tempoSupportsClassname");
2079
- putBoolean("data-tempo-supports-children", "tempoSupportsChildren");
2080
- if (element) {
2081
- const className = element.getAttribute("class");
2082
- if (className !== null && className !== "") props.className = className;
2083
- const style = parseInlineStyle(element.getAttribute("style"));
2084
- if (style) props.style = style;
2085
1819
  }
2086
- return Object.keys(props).length > 0 ? props : void 0;
2087
- }
2088
- function parseInlineStyle(value) {
2089
- if (!value) return void 0;
2090
- const style = {};
2091
- for (const declaration of value.split(";")) {
2092
- const colon = declaration.indexOf(":");
2093
- if (colon < 0) continue;
2094
- const property = declaration.slice(0, colon).trim();
2095
- const propertyValue = declaration.slice(colon + 1).trim();
2096
- if (property) style[property] = propertyValue;
1820
+ addElement(element) {
1821
+ this.add(
1822
+ element.getAttribute("data-tempo-filepath"),
1823
+ element.getAttribute("data-tempo-modifiedts"),
1824
+ element.getAttribute("data-tempo-source-version")
1825
+ );
1826
+ this.add(
1827
+ element.getAttribute("data-tempo-html-filepath"),
1828
+ element.getAttribute("data-tempo-html-modifiedts"),
1829
+ element.getAttribute("data-tempo-html-source-version")
1830
+ );
2097
1831
  }
2098
- return Object.keys(style).length > 0 ? style : void 0;
2099
- }
2100
- function projectionFiberSourceKey(fiber) {
2101
- const props = captureProjectionLayerProps(fiber, null);
2102
- const filepath = props?.["data-tempo-filepath"];
2103
- const position = props?.["data-tempo-position"];
2104
- return filepath && position !== void 0 ? `${filepath}:${position}` : null;
2105
- }
1832
+ snapshot() {
1833
+ return Object.fromEntries(
1834
+ Array.from(this.files, ([filepath, fact]) => [
1835
+ filepath,
1836
+ {
1837
+ modifiedTs: fact.modifiedTs,
1838
+ ...fact.sourceVersion !== void 0 ? { sourceVersion: fact.sourceVersion } : {}
1839
+ }
1840
+ ])
1841
+ );
1842
+ }
1843
+ };
2106
1844
 
2107
1845
  // ../../modules/iframe-projection/combined/projection-patch.ts
2108
1846
  var SOURCE_ANNOTATION_ATTRIBUTES = /* @__PURE__ */ new Set([
@@ -2360,181 +2098,650 @@ function captureProjectionStatePatch(root, element, eventKind) {
2360
2098
  for (let index = 0; index < element.options.length; index += 1) {
2361
2099
  if (element.options[index]?.selected) selectedIndices.push(index);
2362
2100
  }
2363
- return { targetId, kind: "selected", selectedIndices, ancestorIds };
2101
+ return { targetId, kind: "selected", selectedIndices, ancestorIds };
2102
+ }
2103
+ return null;
2104
+ }
2105
+ function captureProjectionPortalRegion(element, removed = false, coordinateRoot) {
2106
+ const portalId = element.getAttribute(PORTAL_ID_ATTR);
2107
+ if (!portalId) return null;
2108
+ if (removed) {
2109
+ return {
2110
+ portal: { kind: "remove", portalId },
2111
+ annotations: [],
2112
+ observedFiles: {}
2113
+ };
2114
+ }
2115
+ const liveElements = [element, ...element.querySelectorAll("*")];
2116
+ for (const live of liveElements) ensureProjectionDomId(live);
2117
+ const clone = element.cloneNode(true);
2118
+ for (const script of clone.querySelectorAll("script")) script.remove();
2119
+ const cloneElements = [clone, ...clone.querySelectorAll("*")];
2120
+ const annotations = [];
2121
+ const observedFiles = new ProjectionObservedFileAccumulator();
2122
+ for (const detached of detachSourceAnnotations(liveElements, cloneElements)) {
2123
+ annotations.push({
2124
+ targetId: detached.targetId,
2125
+ attributes: captureFinalAttributes(detached.element, detached.names),
2126
+ ancestorIds: captureProjectionAncestorIds(element, detached.element)
2127
+ });
2128
+ observedFiles.addElement(detached.element);
2129
+ }
2130
+ const coordinateSpace = coordinateRoot ? capturePortalCoordinateSpace(coordinateRoot, element) : void 0;
2131
+ return {
2132
+ portal: {
2133
+ kind: "replace",
2134
+ portalId,
2135
+ html: removeScriptTags(clone.outerHTML),
2136
+ ...coordinateSpace && { coordinateSpace }
2137
+ },
2138
+ annotations,
2139
+ observedFiles: observedFiles.snapshot()
2140
+ };
2141
+ }
2142
+ function captureProjectionPortalCoordinates(root, element) {
2143
+ const portalId = element.getAttribute(PORTAL_ID_ATTR);
2144
+ const coordinateSpace = capturePortalCoordinateSpace(root, element);
2145
+ if (!portalId || !coordinateSpace) return null;
2146
+ return {
2147
+ kind: "replace",
2148
+ portalId,
2149
+ html: "",
2150
+ coordinateSpace,
2151
+ coordinatesOnly: true
2152
+ };
2153
+ }
2154
+ function mutationTargetElement(target) {
2155
+ return target instanceof Element ? target : target.parentElement;
2156
+ }
2157
+ function projectionTargetId(root, element) {
2158
+ return element === root ? PROJECTION_ROOT_TARGET_ID : element.getAttribute(DOM_ID_ATTR);
2159
+ }
2160
+ function coalesceElements(elements) {
2161
+ const unique = Array.from(new Set(elements));
2162
+ return unique.filter(
2163
+ (candidate) => !unique.some((other) => other !== candidate && other.contains(candidate))
2164
+ );
2165
+ }
2166
+ function reverseDocumentOrder(left, right) {
2167
+ if (left === right) return 0;
2168
+ const position = left.compareDocumentPosition(right);
2169
+ if (position & 4) return 1;
2170
+ if (position & 2) return -1;
2171
+ return 0;
2172
+ }
2173
+ function nextElementSibling(node) {
2174
+ let current = node.nextSibling;
2175
+ while (current && !(current instanceof Element))
2176
+ current = current.nextSibling;
2177
+ return current;
2178
+ }
2179
+ function survivingNextElement(parent, mutation) {
2180
+ const next = mutation.nextSibling;
2181
+ if (next?.parentNode === parent) {
2182
+ return next instanceof Element ? next : nextElementSibling(next);
2183
+ }
2184
+ const previous = mutation.previousSibling;
2185
+ if (previous?.parentNode === parent) return nextElementSibling(previous);
2186
+ return parent.childNodes.length === 0 ? null : void 0;
2187
+ }
2188
+ function captureNonElementGap(parent, before) {
2189
+ const nodes = [];
2190
+ let current = before ? before.previousSibling : parent.lastChild;
2191
+ while (current && !(current instanceof Element)) {
2192
+ nodes.unshift(current.cloneNode(true));
2193
+ current = current.previousSibling;
2194
+ }
2195
+ const container = parent.ownerDocument.createElement("div");
2196
+ container.append(...nodes);
2197
+ return container.innerHTML;
2198
+ }
2199
+ function capturePlacedElementWithoutAnnotations(element) {
2200
+ const liveElements = [element, ...element.querySelectorAll("*")];
2201
+ for (const live of liveElements) ensureProjectionDomId(live);
2202
+ const clone = element.cloneNode(true);
2203
+ if (clone.tagName.toLowerCase() === "script") {
2204
+ return { html: "", annotations: [] };
2205
+ }
2206
+ for (const script of clone.querySelectorAll("script")) script.remove();
2207
+ const cloneElements = [clone, ...clone.querySelectorAll("*")];
2208
+ const annotations = detachSourceAnnotations(liveElements, cloneElements);
2209
+ return { html: clone.outerHTML, annotations };
2210
+ }
2211
+ function mergeCapturedAnnotations(target, observedFiles, incoming) {
2212
+ for (const { element, names } of incoming) {
2213
+ const existing = target.get(element) ?? /* @__PURE__ */ new Set();
2214
+ for (const name of names) existing.add(name);
2215
+ target.set(element, existing);
2216
+ observedFiles.addElement(element);
2217
+ }
2218
+ }
2219
+ function isCoveredTargetId(root, regions, targetId) {
2220
+ const target = targetId === PROJECTION_ROOT_TARGET_ID ? root : root.querySelector(`[${DOM_ID_ATTR}="${cssEscape(targetId)}"]`);
2221
+ return target ? regions.some((region) => region === target || region.contains(target)) : false;
2222
+ }
2223
+ function coalesceRegions(regions) {
2224
+ const candidates = Array.from(regions);
2225
+ return candidates.filter(
2226
+ (candidate) => !candidates.some(
2227
+ (other) => other !== candidate && other.contains(candidate)
2228
+ )
2229
+ );
2230
+ }
2231
+ function captureFinalAttributes(element, names) {
2232
+ return Object.fromEntries(
2233
+ Array.from(names, (name) => [name, element.getAttribute(name)])
2234
+ );
2235
+ }
2236
+ function detachSourceAnnotations(live, clone) {
2237
+ const detached = [];
2238
+ for (let index = 0; index < live.length; index += 1) {
2239
+ const element = live[index];
2240
+ const copy = clone[index];
2241
+ if (!element || !copy) continue;
2242
+ const targetId = element.getAttribute(DOM_ID_ATTR);
2243
+ if (!targetId) continue;
2244
+ const names = /* @__PURE__ */ new Set();
2245
+ for (const name of SOURCE_ANNOTATION_ATTRIBUTES) {
2246
+ if (!element.hasAttribute(name)) continue;
2247
+ names.add(name);
2248
+ copy.removeAttribute(name);
2249
+ }
2250
+ if (names.size > 0) detached.push({ element, targetId, names });
2364
2251
  }
2365
- return null;
2252
+ return detached;
2366
2253
  }
2367
- function captureProjectionPortalRegion(element, removed = false, coordinateRoot) {
2368
- const portalId = element.getAttribute(PORTAL_ID_ATTR);
2369
- if (!portalId) return null;
2370
- if (removed) {
2371
- return {
2372
- portal: { kind: "remove", portalId },
2373
- annotations: [],
2374
- observedFiles: {}
2375
- };
2376
- }
2377
- const liveElements = [element, ...element.querySelectorAll("*")];
2378
- for (const live of liveElements) ensureProjectionDomId(live);
2254
+ function captureRegionWithoutAnnotations(element) {
2255
+ const liveDescendants = Array.from(element.querySelectorAll("*"));
2256
+ for (const live of liveDescendants) ensureProjectionDomId(live);
2379
2257
  const clone = element.cloneNode(true);
2380
2258
  for (const script of clone.querySelectorAll("script")) script.remove();
2381
- const cloneElements = [clone, ...clone.querySelectorAll("*")];
2382
- const annotations = [];
2383
- const observedFiles = new ProjectionObservedFileAccumulator();
2384
- for (const detached of detachSourceAnnotations(liveElements, cloneElements)) {
2385
- annotations.push({
2386
- targetId: detached.targetId,
2387
- attributes: captureFinalAttributes(detached.element, detached.names),
2388
- ancestorIds: captureProjectionAncestorIds(element, detached.element)
2259
+ const cloneDescendants = Array.from(clone.querySelectorAll("*"));
2260
+ const annotations = detachSourceAnnotations(liveDescendants, cloneDescendants);
2261
+ return { html: clone.innerHTML, annotations };
2262
+ }
2263
+ function widenToIdentifiableRegion(root, element) {
2264
+ for (let current = element; current && current !== root; current = current.parentElement) {
2265
+ if (current.getAttribute(DOM_ID_ATTR)) return current;
2266
+ }
2267
+ return root;
2268
+ }
2269
+ function captureProjectionAncestorIds(root, element) {
2270
+ const ids = [];
2271
+ for (let current = element.parentElement; current && current !== root; current = current.parentElement) {
2272
+ const id = current.getAttribute(DOM_ID_ATTR);
2273
+ if (id) ids.push(id);
2274
+ }
2275
+ return ids;
2276
+ }
2277
+
2278
+ // ../../modules/iframe-projection/combined/projection-dom-layers.ts
2279
+ var DOM_LAYER_ROOT_ID = "dom:$projection-root";
2280
+ var DOM_LAYER_FIBER_PREFIX = "dom:";
2281
+ function createProjectionDomLayerSerializer() {
2282
+ let nextElementId = 1;
2283
+ const elementIds = /* @__PURE__ */ new WeakMap();
2284
+ const domIdOwners = /* @__PURE__ */ new Map();
2285
+ const identity = {
2286
+ layerIdForElement(_root, element) {
2287
+ const existing = elementIds.get(element);
2288
+ if (existing) return existing;
2289
+ const id = `${DOM_LAYER_FIBER_PREFIX}element:${nextElementId++}`;
2290
+ elementIds.set(element, id);
2291
+ return id;
2292
+ },
2293
+ bindableDomIdForElement(root, element) {
2294
+ const domId = ensureProjectionDomId(element);
2295
+ if (!domId) return null;
2296
+ const owner = domIdOwners.get(domId);
2297
+ if (owner === element) return domId;
2298
+ if (!owner || !root.contains(owner)) {
2299
+ domIdOwners.set(domId, element);
2300
+ return domId;
2301
+ }
2302
+ return null;
2303
+ }
2304
+ };
2305
+ return {
2306
+ serializeRoot(root, observedFiles = {}) {
2307
+ return serializeProjectionDomLayerRootWithIdentity(
2308
+ root,
2309
+ observedFiles,
2310
+ identity
2311
+ );
2312
+ },
2313
+ capturePatch(root, targets, observedFiles = {}) {
2314
+ return captureProjectionDomLayerPatchFromTargets(
2315
+ root,
2316
+ targets,
2317
+ observedFiles,
2318
+ identity
2319
+ );
2320
+ }
2321
+ };
2322
+ }
2323
+ var dataDomLayerIdentity = {
2324
+ layerIdForElement: domLayerIdForElement,
2325
+ bindableDomIdForElement: (_root, element) => ensureProjectionDomId(element)
2326
+ };
2327
+ function serializeProjectionDomLayerRoot(root, observedFiles = {}) {
2328
+ return serializeProjectionDomLayerRootWithIdentity(
2329
+ root,
2330
+ observedFiles,
2331
+ dataDomLayerIdentity
2332
+ );
2333
+ }
2334
+ function serializeProjectionDomLayerRootWithIdentity(root, observedFiles, identity) {
2335
+ return {
2336
+ semantic: {
2337
+ kind: "layers",
2338
+ tree: serializeDomLayerRootNode(root, identity)
2339
+ },
2340
+ observedFiles
2341
+ };
2342
+ }
2343
+ function captureProjectionDomLayerPatchFromTargets(root, targets, observedFiles, identity) {
2344
+ const structuralTargets = new Set(
2345
+ targets.structural.filter(
2346
+ (target) => target === root || root.contains(target)
2347
+ )
2348
+ );
2349
+ const metadataTargets = new Set(
2350
+ targets.metadata.filter(
2351
+ (target) => target === root || root.contains(target)
2352
+ )
2353
+ );
2354
+ const regions = Array.from(structuralTargets).filter(
2355
+ (candidate) => !Array.from(structuralTargets).some(
2356
+ (other) => other !== candidate && other.contains(candidate)
2357
+ )
2358
+ );
2359
+ const regionSnapshots = regions.map(
2360
+ (target) => ({
2361
+ targetFiberId: layerIdForTarget(root, target, identity),
2362
+ tree: target === root ? serializeDomLayerRootNode(root, identity) : serializeDomLayerNode(root, target, identity),
2363
+ observedFiles
2364
+ })
2365
+ );
2366
+ const metadataSnapshots = [];
2367
+ for (const target of metadataTargets) {
2368
+ if (target !== root && regions.some((region) => region === root || region.contains(target))) {
2369
+ continue;
2370
+ }
2371
+ metadataSnapshots.push({
2372
+ targetFiberId: layerIdForTarget(root, target, identity),
2373
+ props: captureProjectionDomLayerProps(target)
2389
2374
  });
2390
- observedFiles.addElement(detached.element);
2391
2375
  }
2392
- const coordinateSpace = coordinateRoot ? capturePortalCoordinateSpace(coordinateRoot, element) : void 0;
2376
+ if (regionSnapshots.length === 0 && metadataSnapshots.length === 0) {
2377
+ return void 0;
2378
+ }
2393
2379
  return {
2394
- portal: {
2395
- kind: "replace",
2396
- portalId,
2397
- html: removeScriptTags(clone.outerHTML),
2398
- ...coordinateSpace && { coordinateSpace }
2380
+ ...regionSnapshots.length > 0 ? { regions: regionSnapshots } : {},
2381
+ ...metadataSnapshots.length > 0 ? { metadata: metadataSnapshots } : {}
2382
+ };
2383
+ }
2384
+ function serializeDomLayerRootNode(root, identity) {
2385
+ const name = root.tagName.toLowerCase();
2386
+ return {
2387
+ kind: "fragment",
2388
+ name,
2389
+ domId: null,
2390
+ elementTag: null,
2391
+ source: {
2392
+ kind: "react-fiber",
2393
+ fiber: {
2394
+ tag: FiberTag.HostRoot,
2395
+ name,
2396
+ id: DOM_LAYER_ROOT_ID
2397
+ }
2399
2398
  },
2400
- annotations,
2401
- observedFiles: observedFiles.snapshot()
2399
+ children: Array.from(root.children).map(
2400
+ (child) => serializeDomLayerNode(root, child, identity)
2401
+ )
2402
2402
  };
2403
2403
  }
2404
- function captureProjectionPortalCoordinates(root, element) {
2405
- const portalId = element.getAttribute(PORTAL_ID_ATTR);
2406
- const coordinateSpace = capturePortalCoordinateSpace(root, element);
2407
- if (!portalId || !coordinateSpace) return null;
2404
+ function serializeDomLayerNode(root, element, identity) {
2405
+ const domId = identity.bindableDomIdForElement(root, element);
2406
+ const name = element.tagName.toLowerCase();
2407
+ return {
2408
+ kind: "host",
2409
+ name,
2410
+ domId,
2411
+ elementTag: name,
2412
+ props: captureProjectionDomLayerProps(element),
2413
+ source: {
2414
+ kind: "react-fiber",
2415
+ fiber: {
2416
+ tag: FiberTag.HostComponent,
2417
+ name,
2418
+ id: identity.layerIdForElement(root, element)
2419
+ }
2420
+ },
2421
+ children: Array.from(element.children).map(
2422
+ (child) => serializeDomLayerNode(root, child, identity)
2423
+ )
2424
+ };
2425
+ }
2426
+ function layerIdForTarget(root, target, identity) {
2427
+ if (target === root) return DOM_LAYER_ROOT_ID;
2428
+ return identity.layerIdForElement(root, target);
2429
+ }
2430
+ function projectionDomLayerId(domId) {
2431
+ return `${DOM_LAYER_FIBER_PREFIX}${domId}`;
2432
+ }
2433
+ function domLayerIdForElement(root, element) {
2434
+ const domId = ensureProjectionDomId(element);
2435
+ if (domId) return projectionDomLayerId(domId);
2436
+ const path = [];
2437
+ let current = element;
2438
+ while (current && current !== root) {
2439
+ const parent = current.parentElement;
2440
+ if (!parent) break;
2441
+ path.push(Array.from(parent.children).indexOf(current));
2442
+ current = parent;
2443
+ }
2444
+ return `${DOM_LAYER_FIBER_PREFIX}path:${path.reverse().join(".")}`;
2445
+ }
2446
+ function captureProjectionDomLayerProps(element) {
2447
+ const props = {};
2448
+ const className = element.getAttribute("class");
2449
+ if (className) props.className = className;
2450
+ const style = parseInlineStyle(element.getAttribute("style"));
2451
+ if (style) props.style = style;
2452
+ for (const name of SOURCE_ANNOTATION_ATTRIBUTES) {
2453
+ const value = element.getAttribute(name);
2454
+ if (value === null) continue;
2455
+ if (name === "data-tempo-position" || name === "data-tempo-modifiedts") {
2456
+ const numeric = Number(value);
2457
+ if (Number.isFinite(numeric)) props[name] = numeric;
2458
+ } else {
2459
+ props[name] = value;
2460
+ }
2461
+ }
2462
+ for (const name of [
2463
+ "data-tempo-supports-style",
2464
+ "data-tempo-supports-classname",
2465
+ "data-tempo-supports-children"
2466
+ ]) {
2467
+ const value = element.getAttribute(name);
2468
+ if (value === "true" || value === "false") props[name] = value === "true";
2469
+ }
2470
+ return Object.keys(props).length > 0 ? props : void 0;
2471
+ }
2472
+ function parseInlineStyle(value) {
2473
+ if (!value) return void 0;
2474
+ const style = {};
2475
+ for (const declaration of value.split(";")) {
2476
+ const separator = declaration.indexOf(":");
2477
+ if (separator < 0) continue;
2478
+ const property = declaration.slice(0, separator).trim();
2479
+ const propertyValue = declaration.slice(separator + 1).trim();
2480
+ if (property && propertyValue) style[property] = propertyValue;
2481
+ }
2482
+ return Object.keys(style).length > 0 ? style : void 0;
2483
+ }
2484
+
2485
+ // ../../modules/iframe-projection/combined/projection-layer-snapshot.ts
2486
+ var COMPONENT_TAGS = /* @__PURE__ */ new Set([
2487
+ FiberTag.FunctionComponent,
2488
+ FiberTag.ClassComponent,
2489
+ FiberTag.ForwardRef,
2490
+ FiberTag.MemoComponent,
2491
+ FiberTag.SimpleMemoComponent,
2492
+ FiberTag.LazyComponent
2493
+ ]);
2494
+ function createProjectionLayerSerializer() {
2495
+ let nextFiberId2 = 1;
2496
+ const fiberIds = /* @__PURE__ */ new WeakMap();
2497
+ const fiberId = (fiber) => {
2498
+ const direct = fiberIds.get(fiber);
2499
+ if (direct) return direct;
2500
+ const alternate = fiber.alternate ? fiberIds.get(fiber.alternate) : null;
2501
+ if (alternate) {
2502
+ fiberIds.set(fiber, alternate);
2503
+ return alternate;
2504
+ }
2505
+ const id = String(nextFiberId2++);
2506
+ fiberIds.set(fiber, id);
2507
+ if (fiber.alternate) fiberIds.set(fiber.alternate, id);
2508
+ return id;
2509
+ };
2510
+ const knownFiberId = (fiber) => fiberIds.get(fiber) ?? (fiber.alternate ? fiberIds.get(fiber.alternate) : void 0) ?? null;
2511
+ const serialize = (root) => {
2512
+ const observedFiles = new ProjectionObservedFileAccumulator();
2513
+ let fiberNodesVisited = 0;
2514
+ let semanticNodesSerialized = 0;
2515
+ const visit = (fiber, emitLayer) => {
2516
+ fiberNodesVisited += 1;
2517
+ const name = getDisplayName(fiber);
2518
+ const kind = projectionKindForTag(fiber.tag);
2519
+ const included = isProjectionLayerFiber(fiber);
2520
+ const element = kind === "host" ? getDomElement(fiber) : null;
2521
+ const domId = element ? ensureProjectionDomId(element) : null;
2522
+ const props = included ? captureProjectionLayerProps(fiber, element) : void 0;
2523
+ if (props) {
2524
+ observedFiles.add(
2525
+ props["data-tempo-filepath"],
2526
+ props["data-tempo-modifiedts"],
2527
+ props["data-tempo-source-version"]
2528
+ );
2529
+ observedFiles.add(
2530
+ props["data-tempo-html-filepath"],
2531
+ props["data-tempo-html-modifiedts"],
2532
+ props["data-tempo-html-source-version"]
2533
+ );
2534
+ }
2535
+ const isSvgLeaf = included && kind === "host" && name.toLowerCase() === "svg";
2536
+ const isContentEditableBoundary2 = included && kind === "host" && element?.getAttribute("contenteditable") !== null;
2537
+ const children = [];
2538
+ if (!isContentEditableBoundary2) {
2539
+ for (let child = fiber.child; child; child = child.sibling) {
2540
+ children.push(...visit(child, emitLayer && !isSvgLeaf));
2541
+ }
2542
+ }
2543
+ if (!emitLayer) return [];
2544
+ if (!included) return children;
2545
+ if (kind === null) return children;
2546
+ const source = {
2547
+ kind: "react-fiber",
2548
+ fiber: { tag: fiber.tag, name, id: fiberId(fiber) }
2549
+ };
2550
+ let node;
2551
+ if (kind === "host") {
2552
+ node = {
2553
+ kind,
2554
+ name,
2555
+ domId,
2556
+ elementTag: name,
2557
+ props,
2558
+ source,
2559
+ children: isSvgLeaf || isContentEditableBoundary2 ? [] : children
2560
+ };
2561
+ } else {
2562
+ node = {
2563
+ kind,
2564
+ name,
2565
+ domId: null,
2566
+ elementTag: null,
2567
+ props,
2568
+ source,
2569
+ children
2570
+ };
2571
+ }
2572
+ semanticNodesSerialized += 1;
2573
+ return [node];
2574
+ };
2575
+ const branches = visit(root, true);
2576
+ let tree;
2577
+ if (branches.length === 1) {
2578
+ tree = branches[0] ?? null;
2579
+ } else if (root.tag === FiberTag.HostRoot) {
2580
+ const name = getDisplayName(root);
2581
+ tree = {
2582
+ kind: "fragment",
2583
+ name,
2584
+ domId: null,
2585
+ elementTag: null,
2586
+ source: {
2587
+ kind: "react-fiber",
2588
+ fiber: { tag: root.tag, name, id: fiberId(root) }
2589
+ },
2590
+ children: branches
2591
+ };
2592
+ semanticNodesSerialized += 1;
2593
+ } else {
2594
+ tree = null;
2595
+ }
2596
+ return {
2597
+ snapshot: {
2598
+ semantic: { kind: "layers", tree },
2599
+ observedFiles: observedFiles.snapshot()
2600
+ },
2601
+ fiberNodesVisited,
2602
+ semanticNodesSerialized
2603
+ };
2604
+ };
2408
2605
  return {
2409
- kind: "replace",
2410
- portalId,
2411
- html: "",
2412
- coordinateSpace,
2413
- coordinatesOnly: true
2606
+ serialize,
2607
+ fiberId,
2608
+ knownFiberId,
2609
+ serializeRegion(root) {
2610
+ const targetFiberId = fiberId(root);
2611
+ const serialized = serialize(root);
2612
+ return {
2613
+ region: {
2614
+ targetFiberId,
2615
+ tree: serialized.snapshot.semantic.kind === "layers" ? serialized.snapshot.semantic.tree : null,
2616
+ observedFiles: serialized.snapshot.observedFiles
2617
+ },
2618
+ fiberNodesVisited: serialized.fiberNodesVisited,
2619
+ semanticNodesSerialized: serialized.semanticNodesSerialized
2620
+ };
2621
+ },
2622
+ captureMetadata(root, options) {
2623
+ return {
2624
+ targetFiberId: fiberId(root),
2625
+ props: captureProjectionLayerProps(
2626
+ root,
2627
+ root.tag === FiberTag.HostComponent ? getDomElement(root) : null,
2628
+ options?.sourceAnnotations ?? "fiber"
2629
+ )
2630
+ };
2631
+ }
2414
2632
  };
2415
2633
  }
2416
- function mutationTargetElement(target) {
2417
- return target instanceof Element ? target : target.parentElement;
2418
- }
2419
- function projectionTargetId(root, element) {
2420
- return element === root ? PROJECTION_ROOT_TARGET_ID : element.getAttribute(DOM_ID_ATTR);
2421
- }
2422
- function coalesceElements(elements) {
2423
- const unique = Array.from(new Set(elements));
2424
- return unique.filter(
2425
- (candidate) => !unique.some((other) => other !== candidate && other.contains(candidate))
2426
- );
2427
- }
2428
- function reverseDocumentOrder(left, right) {
2429
- if (left === right) return 0;
2430
- const position = left.compareDocumentPosition(right);
2431
- if (position & 4) return 1;
2432
- if (position & 2) return -1;
2433
- return 0;
2434
- }
2435
- function nextElementSibling(node) {
2436
- let current = node.nextSibling;
2437
- while (current && !(current instanceof Element))
2438
- current = current.nextSibling;
2439
- return current;
2440
- }
2441
- function survivingNextElement(parent, mutation) {
2442
- const next = mutation.nextSibling;
2443
- if (next?.parentNode === parent) {
2444
- return next instanceof Element ? next : nextElementSibling(next);
2445
- }
2446
- const previous = mutation.previousSibling;
2447
- if (previous?.parentNode === parent) return nextElementSibling(previous);
2448
- return parent.childNodes.length === 0 ? null : void 0;
2449
- }
2450
- function captureNonElementGap(parent, before) {
2451
- const nodes = [];
2452
- let current = before ? before.previousSibling : parent.lastChild;
2453
- while (current && !(current instanceof Element)) {
2454
- nodes.unshift(current.cloneNode(true));
2455
- current = current.previousSibling;
2634
+ function isProjectionLayerFiber(fiber) {
2635
+ if (isTempoHiddenFiber(fiber)) return false;
2636
+ const kind = projectionKindForTag(fiber.tag);
2637
+ if (kind === null) return false;
2638
+ if (kind === "host") return true;
2639
+ const sourceKey = projectionFiberSourceKey(fiber);
2640
+ if (!sourceKey) return true;
2641
+ for (let parent = fiber.return; parent; parent = parent.return) {
2642
+ if (isTempoHiddenFiber(parent)) continue;
2643
+ const parentKind = projectionKindForTag(parent.tag);
2644
+ if (parentKind === null) continue;
2645
+ if (parentKind === "host") return true;
2646
+ return projectionFiberSourceKey(parent) !== sourceKey;
2456
2647
  }
2457
- const container = parent.ownerDocument.createElement("div");
2458
- container.append(...nodes);
2459
- return container.innerHTML;
2648
+ return true;
2460
2649
  }
2461
- function capturePlacedElementWithoutAnnotations(element) {
2462
- const liveElements = [element, ...element.querySelectorAll("*")];
2463
- for (const live of liveElements) ensureProjectionDomId(live);
2464
- const clone = element.cloneNode(true);
2465
- if (clone.tagName.toLowerCase() === "script") {
2466
- return { html: "", annotations: [] };
2467
- }
2468
- for (const script of clone.querySelectorAll("script")) script.remove();
2469
- const cloneElements = [clone, ...clone.querySelectorAll("*")];
2470
- const annotations = detachSourceAnnotations(liveElements, cloneElements);
2471
- return { html: clone.outerHTML, annotations };
2650
+ function projectionKindForTag(tag) {
2651
+ if (tag === FiberTag.HostComponent) return "host";
2652
+ if (COMPONENT_TAGS.has(tag)) return "component";
2653
+ return null;
2472
2654
  }
2473
- function mergeCapturedAnnotations(target, observedFiles, incoming) {
2474
- for (const { element, names } of incoming) {
2475
- const existing = target.get(element) ?? /* @__PURE__ */ new Set();
2476
- for (const name of names) existing.add(name);
2477
- target.set(element, existing);
2478
- observedFiles.addElement(element);
2655
+ function ascendToAnnotatedComponentRoot(fiber) {
2656
+ let topmost = fiber;
2657
+ for (let parent = fiber.return; parent; parent = parent.return) {
2658
+ if (parent.tag === FiberTag.HostRoot || parent.tag === FiberTag.HostPortal) {
2659
+ break;
2660
+ }
2661
+ const kind = projectionKindForTag(parent.tag);
2662
+ if (kind === "host") break;
2663
+ if (isTempoHiddenFiber(parent)) break;
2664
+ if (kind === "component") {
2665
+ if (projectionFiberSourceKey(parent) === null) break;
2666
+ topmost = parent;
2667
+ }
2479
2668
  }
2669
+ return topmost;
2480
2670
  }
2481
- function isCoveredTargetId(root, regions, targetId) {
2482
- const target = targetId === PROJECTION_ROOT_TARGET_ID ? root : root.querySelector(`[${DOM_ID_ATTR}="${cssEscape(targetId)}"]`);
2483
- return target ? regions.some((region) => region === target || region.contains(target)) : false;
2484
- }
2485
- function coalesceRegions(regions) {
2486
- const candidates = Array.from(regions);
2487
- return candidates.filter(
2488
- (candidate) => !candidates.some(
2489
- (other) => other !== candidate && other.contains(candidate)
2490
- )
2491
- );
2492
- }
2493
- function captureFinalAttributes(element, names) {
2494
- return Object.fromEntries(
2495
- Array.from(names, (name) => [name, element.getAttribute(name)])
2496
- );
2671
+ function isTempoHiddenFiber(fiber) {
2672
+ const props = getProps(fiber);
2673
+ const direct = props?.["data-tempo-hide-fiber"];
2674
+ const dataSet = props?.dataSet;
2675
+ const native = dataSet && typeof dataSet === "object" ? dataSet.tempoHideFiber : void 0;
2676
+ const value = native ?? direct;
2677
+ return value === true || value === "true";
2497
2678
  }
2498
- function detachSourceAnnotations(live, clone) {
2499
- const detached = [];
2500
- for (let index = 0; index < live.length; index += 1) {
2501
- const element = live[index];
2502
- const copy = clone[index];
2503
- if (!element || !copy) continue;
2504
- const targetId = element.getAttribute(DOM_ID_ATTR);
2505
- if (!targetId) continue;
2506
- const names = /* @__PURE__ */ new Set();
2507
- for (const name of SOURCE_ANNOTATION_ATTRIBUTES) {
2508
- if (!element.hasAttribute(name)) continue;
2509
- names.add(name);
2510
- copy.removeAttribute(name);
2679
+ function captureProjectionLayerProps(fiber, element, sourceAnnotations = "fiber") {
2680
+ const raw = getProps(fiber);
2681
+ const dataSet = raw?.dataSet && typeof raw.dataSet === "object" ? raw.dataSet : void 0;
2682
+ const read = (flatKey, dataSetKey, authority = "source") => {
2683
+ if (authority === "source" && element && sourceAnnotations === "live-host") {
2684
+ return element.getAttribute(flatKey);
2511
2685
  }
2512
- if (names.size > 0) detached.push({ element, targetId, names });
2686
+ return dataSet && Object.hasOwn(dataSet, dataSetKey) ? dataSet[dataSetKey] : raw?.[flatKey];
2687
+ };
2688
+ const props = {};
2689
+ const putString = (flatKey, dataSetKey) => {
2690
+ const value = read(flatKey, dataSetKey);
2691
+ if (typeof value === "string") props[flatKey] = value;
2692
+ };
2693
+ const putFiniteNumber = (flatKey, dataSetKey) => {
2694
+ const value = read(flatKey, dataSetKey);
2695
+ const numeric = typeof value === "number" ? value : typeof value === "string" ? Number(value) : Number.NaN;
2696
+ if (Number.isFinite(numeric)) props[flatKey] = numeric;
2697
+ };
2698
+ const putStringified = (flatKey, dataSetKey) => {
2699
+ const value = read(flatKey, dataSetKey);
2700
+ if (typeof value === "string" || typeof value === "number") {
2701
+ props[flatKey] = String(value);
2702
+ }
2703
+ };
2704
+ const putBoolean = (flatKey, dataSetKey) => {
2705
+ const value = read(flatKey, dataSetKey, "fiber");
2706
+ if (value === true || value === "true") props[flatKey] = true;
2707
+ if (value === false || value === "false") props[flatKey] = false;
2708
+ };
2709
+ putString("data-tempo-filepath", "tempoFilepath");
2710
+ putFiniteNumber("data-tempo-position", "tempoPosition");
2711
+ putFiniteNumber("data-tempo-modifiedts", "tempoModifiedts");
2712
+ putString("data-tempo-source-version", "tempoSourceVersion");
2713
+ putString("data-tempo-html-filepath", "tempoHtmlFilepath");
2714
+ putStringified("data-tempo-html-offset", "tempoHtmlOffset");
2715
+ putStringified("data-tempo-html-modifiedts", "tempoHtmlModifiedts");
2716
+ putString("data-tempo-html-source-version", "tempoHtmlSourceVersion");
2717
+ putBoolean("data-tempo-supports-style", "tempoSupportsStyle");
2718
+ putBoolean("data-tempo-supports-classname", "tempoSupportsClassname");
2719
+ putBoolean("data-tempo-supports-children", "tempoSupportsChildren");
2720
+ if (element) {
2721
+ const className = element.getAttribute("class");
2722
+ if (className !== null && className !== "") props.className = className;
2723
+ const style = parseInlineStyle2(element.getAttribute("style"));
2724
+ if (style) props.style = style;
2513
2725
  }
2514
- return detached;
2515
- }
2516
- function captureRegionWithoutAnnotations(element) {
2517
- const liveDescendants = Array.from(element.querySelectorAll("*"));
2518
- for (const live of liveDescendants) ensureProjectionDomId(live);
2519
- const clone = element.cloneNode(true);
2520
- for (const script of clone.querySelectorAll("script")) script.remove();
2521
- const cloneDescendants = Array.from(clone.querySelectorAll("*"));
2522
- const annotations = detachSourceAnnotations(liveDescendants, cloneDescendants);
2523
- return { html: clone.innerHTML, annotations };
2726
+ return Object.keys(props).length > 0 ? props : void 0;
2524
2727
  }
2525
- function widenToIdentifiableRegion(root, element) {
2526
- for (let current = element; current && current !== root; current = current.parentElement) {
2527
- if (current.getAttribute(DOM_ID_ATTR)) return current;
2728
+ function parseInlineStyle2(value) {
2729
+ if (!value) return void 0;
2730
+ const style = {};
2731
+ for (const declaration of value.split(";")) {
2732
+ const colon = declaration.indexOf(":");
2733
+ if (colon < 0) continue;
2734
+ const property = declaration.slice(0, colon).trim();
2735
+ const propertyValue = declaration.slice(colon + 1).trim();
2736
+ if (property) style[property] = propertyValue;
2528
2737
  }
2529
- return root;
2738
+ return Object.keys(style).length > 0 ? style : void 0;
2530
2739
  }
2531
- function captureProjectionAncestorIds(root, element) {
2532
- const ids = [];
2533
- for (let current = element.parentElement; current && current !== root; current = current.parentElement) {
2534
- const id = current.getAttribute(DOM_ID_ATTR);
2535
- if (id) ids.push(id);
2536
- }
2537
- return ids;
2740
+ function projectionFiberSourceKey(fiber) {
2741
+ const props = captureProjectionLayerProps(fiber, null);
2742
+ const filepath = props?.["data-tempo-filepath"];
2743
+ const position = props?.["data-tempo-position"];
2744
+ return filepath && position !== void 0 ? `${filepath}:${position}` : null;
2538
2745
  }
2539
2746
 
2540
2747
  // ../../modules/iframe-projection/combined/projection-full-snapshot.ts
@@ -2542,18 +2749,13 @@ function captureProjectionFullSnapshot(options) {
2542
2749
  const fiberTarget = options.fiberTarget ?? options.root.firstElementChild;
2543
2750
  const serializer = options.layerSerializer ?? createProjectionLayerSerializer();
2544
2751
  const rawFiber = fiberTarget ? getFiberFromElement(fiberTarget) : null;
2545
- const layers = rawFiber ? serializer.serialize(
2752
+ const fiberLayers = rawFiber ? serializer.serialize(
2546
2753
  ascendToAnnotatedComponentRoot(resolveCommittedFiber(rawFiber))
2547
- ) : {
2548
- snapshot: {
2549
- semantic: { kind: "dom-only" },
2550
- observedFiles: {}
2551
- },
2552
- fiberNodesVisited: 0,
2553
- semanticNodesSerialized: 0
2554
- };
2754
+ ) : null;
2555
2755
  const observedFiles = new ProjectionObservedFileAccumulator();
2556
- for (const [file, fact] of Object.entries(layers.snapshot.observedFiles)) {
2756
+ for (const [file, fact] of Object.entries(
2757
+ fiberLayers?.snapshot.observedFiles ?? {}
2758
+ )) {
2557
2759
  observedFiles.add(file, fact.modifiedTs, fact.sourceVersion);
2558
2760
  }
2559
2761
  const { dom, hostDomIdCount } = captureFullDom(
@@ -2561,14 +2763,19 @@ function captureProjectionFullSnapshot(options) {
2561
2763
  options.portals ?? [],
2562
2764
  observedFiles
2563
2765
  );
2766
+ const observedFileSnapshot = observedFiles.snapshot();
2767
+ const layers = fiberLayers?.snapshot ?? options.domLayerSerializer?.serializeRoot(
2768
+ options.root,
2769
+ observedFileSnapshot
2770
+ ) ?? serializeProjectionDomLayerRoot(options.root, observedFileSnapshot);
2564
2771
  return {
2565
2772
  snapshot: {
2566
2773
  dom,
2567
- layers: layers.snapshot,
2568
- observedFiles: observedFiles.snapshot()
2774
+ layers,
2775
+ observedFiles: observedFileSnapshot
2569
2776
  },
2570
- fiberNodesVisited: layers.fiberNodesVisited,
2571
- semanticNodesSerialized: layers.semanticNodesSerialized,
2777
+ fiberNodesVisited: fiberLayers?.fiberNodesVisited ?? 0,
2778
+ semanticNodesSerialized: fiberLayers?.semanticNodesSerialized ?? hostDomIdCount + 1,
2572
2779
  hostDomIdCount
2573
2780
  };
2574
2781
  }
@@ -3196,9 +3403,11 @@ function createProjectionRootAccumulator(options) {
3196
3403
  },
3197
3404
  capturePatch(captureOptions) {
3198
3405
  if (stopped) throw new Error("Projection root accumulator has stopped");
3406
+ const domMutations = drainProjectionDomMutations(dom);
3407
+ const localDomLayerTargets = captureOptions?.retainDomLayerTargets ? collectDomLayerTargets(options.root, domMutations) : void 0;
3199
3408
  const mutationPatch = captureProjectionMutationPatch(
3200
3409
  options.root,
3201
- drainProjectionDomMutations(dom),
3410
+ domMutations,
3202
3411
  captureOptions
3203
3412
  );
3204
3413
  const states = [];
@@ -3267,10 +3476,12 @@ function createProjectionRootAccumulator(options) {
3267
3476
  ...portalPatches.length > 0 ? { portals: portalPatches } : {},
3268
3477
  ...Object.keys(observedSnapshot).length > 0 ? { observedFiles: observedSnapshot } : {}
3269
3478
  };
3270
- return Object.keys(patch).length === 0 ? { kind: "empty" } : {
3479
+ const hasLocalDomLayerTargets = localDomLayerTargets !== void 0 && (localDomLayerTargets.structural.length > 0 || localDomLayerTargets.metadata.length > 0);
3480
+ return Object.keys(patch).length === 0 && !hasLocalDomLayerTargets ? { kind: "empty" } : {
3271
3481
  kind: "patch",
3272
3482
  patch,
3273
- localMetadataTargets: mutationPatch.localMetadataTargets
3483
+ localMetadataTargets: mutationPatch.localMetadataTargets,
3484
+ ...hasLocalDomLayerTargets ? { localDomLayerTargets } : {}
3274
3485
  };
3275
3486
  },
3276
3487
  portalElements() {
@@ -3302,6 +3513,20 @@ function createProjectionRootAccumulator(options) {
3302
3513
  }
3303
3514
  };
3304
3515
  }
3516
+ function collectDomLayerTargets(root, mutations) {
3517
+ const structural = /* @__PURE__ */ new Set();
3518
+ const metadata = /* @__PURE__ */ new Set();
3519
+ for (const mutation of mutations) {
3520
+ const target = mutation.target instanceof Element ? mutation.target : mutation.target.parentElement;
3521
+ if (!target || target !== root && !root.contains(target)) continue;
3522
+ if (mutation.type === "childList") structural.add(target);
3523
+ else if (mutation.type === "attributes") metadata.add(target);
3524
+ }
3525
+ return {
3526
+ structural: Array.from(structural),
3527
+ metadata: Array.from(metadata)
3528
+ };
3529
+ }
3305
3530
 
3306
3531
  // ../../modules/iframe-projection/combined/enriched-to-serialized-fiber.ts
3307
3532
  function detachTagFromFiberTag(tag) {
@@ -3632,7 +3857,9 @@ function createCombinedDocumentProducer(options) {
3632
3857
  void 0,
3633
3858
  runtime.options
3634
3859
  );
3635
- const fullRequested = flushContext.fullRequested || runtime.deferredFullRequest || endedSuspendedEpisode;
3860
+ const semanticMode = runtime.committedFiber ? "fiber" : "dom";
3861
+ const semanticModeChanged = runtime.semanticMode !== null && runtime.semanticMode !== semanticMode;
3862
+ const fullRequested = flushContext.fullRequested || runtime.deferredFullRequest || endedSuspendedEpisode || semanticModeChanged;
3636
3863
  if (fullRequested) {
3637
3864
  runtime.deferredFullRequest = false;
3638
3865
  runtime.accumulator.capturePatch();
@@ -3644,9 +3871,11 @@ function createCombinedDocumentProducer(options) {
3644
3871
  root: runtime.options.element,
3645
3872
  fiberTarget,
3646
3873
  portals: runtime.accumulator.portalElements(),
3647
- layerSerializer: runtime.layerSerializer
3874
+ layerSerializer: runtime.layerSerializer,
3875
+ domLayerSerializer: runtime.domLayerSerializer
3648
3876
  });
3649
3877
  const { snapshot } = captured;
3878
+ runtime.semanticMode = semanticMode;
3650
3879
  captureStats.set(snapshot, {
3651
3880
  perf: makePerf({
3652
3881
  flushContext,
@@ -3671,7 +3900,8 @@ function createCombinedDocumentProducer(options) {
3671
3900
  const accumulated = runtime.accumulator.capturePatch({
3672
3901
  // MutationObserver's parent is stable across a React commit. The
3673
3902
  // unkeyed child ids React may reuse within that parent are not.
3674
- regionalChildLists: true
3903
+ regionalChildLists: true,
3904
+ retainDomLayerTargets: semanticMode === "dom"
3675
3905
  });
3676
3906
  if (accumulated.kind === "patch") {
3677
3907
  for (const element of accumulated.localMetadataTargets) {
@@ -3692,9 +3922,17 @@ function createCombinedDocumentProducer(options) {
3692
3922
  observedFiles.merge(region.observedFiles);
3693
3923
  }
3694
3924
  const observedSnapshot = observedFiles.snapshot();
3925
+ const domLayerPatch = semanticMode === "dom" ? runtime.domLayerSerializer.capturePatch(
3926
+ runtime.options.element,
3927
+ accumulated.kind === "patch" ? accumulated.localDomLayerTargets ?? {
3928
+ structural: [],
3929
+ metadata: []
3930
+ } : { structural: [], metadata: [] },
3931
+ observedSnapshot
3932
+ ) : void 0;
3695
3933
  const patch = {
3696
3934
  ...basePatch,
3697
- ...regions.snapshots.length > 0 || metadata.length > 0 ? {
3935
+ ...domLayerPatch ? { layers: domLayerPatch } : regions.snapshots.length > 0 || metadata.length > 0 ? {
3698
3936
  layers: {
3699
3937
  ...regions.snapshots.length > 0 ? { regions: regions.snapshots } : {},
3700
3938
  ...metadata.length > 0 ? { metadata } : {}
@@ -3809,11 +4047,13 @@ function createCombinedDocumentProducer(options) {
3809
4047
  return {
3810
4048
  options: rootOptions,
3811
4049
  layerSerializer: createProjectionLayerSerializer(),
4050
+ domLayerSerializer: createProjectionDomLayerSerializer(),
3812
4051
  dormant: false,
3813
4052
  accumulator: null,
3814
4053
  stopObserver: null,
3815
4054
  references,
3816
4055
  committedFiber: resolveWatchedCommittedFiber(void 0, rootOptions),
4056
+ semanticMode: null,
3817
4057
  renderError: readProjectionRenderError(rootOptions.element),
3818
4058
  pendingRegions: /* @__PURE__ */ new Map(),
3819
4059
  pendingMetadata: /* @__PURE__ */ new Map(),
@@ -3828,6 +4068,7 @@ function createCombinedDocumentProducer(options) {
3828
4068
  }));
3829
4069
  runtime.dormant = true;
3830
4070
  runtime.committedFiber = null;
4071
+ runtime.semanticMode = null;
3831
4072
  runtime.renderError = null;
3832
4073
  runtime.pendingRegions.clear();
3833
4074
  runtime.pendingMetadata.clear();