@focus-reactive/payload-plugin-visual-editing 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. package/README.md +264 -0
  2. package/dist/admin/VisualEditingBridgeProvider.d.ts +4 -0
  3. package/dist/admin/VisualEditingBridgeProvider.js +144 -0
  4. package/dist/admin/VisualEditingBridgeProvider.js.map +1 -0
  5. package/dist/admin/expandAndFocus.d.ts +6 -0
  6. package/dist/admin/expandAndFocus.js +356 -0
  7. package/dist/admin/expandAndFocus.js.map +1 -0
  8. package/dist/admin/index.d.ts +1 -0
  9. package/dist/admin/index.js +3 -0
  10. package/dist/admin/index.js.map +1 -0
  11. package/dist/admin/parseFieldPath.d.ts +4 -0
  12. package/dist/admin/parseFieldPath.js +25 -0
  13. package/dist/admin/parseFieldPath.js.map +1 -0
  14. package/dist/admin/resolveContainerChain.d.ts +30 -0
  15. package/dist/admin/resolveContainerChain.js +171 -0
  16. package/dist/admin/resolveContainerChain.js.map +1 -0
  17. package/dist/client/VisualEditingOverlay.d.ts +4 -0
  18. package/dist/client/VisualEditingOverlay.js +30 -0
  19. package/dist/client/VisualEditingOverlay.js.map +1 -0
  20. package/dist/client/VisualEditingProvider.d.ts +23 -0
  21. package/dist/client/VisualEditingProvider.js +68 -0
  22. package/dist/client/VisualEditingProvider.js.map +1 -0
  23. package/dist/client/VisualEditingToggle.d.ts +1 -0
  24. package/dist/client/VisualEditingToggle.js +163 -0
  25. package/dist/client/VisualEditingToggle.js.map +1 -0
  26. package/dist/client/buildAdminEditUrl.d.ts +7 -0
  27. package/dist/client/buildAdminEditUrl.js +9 -0
  28. package/dist/client/buildAdminEditUrl.js.map +1 -0
  29. package/dist/client/index.d.ts +11 -0
  30. package/dist/client/index.js +13 -0
  31. package/dist/client/index.js.map +1 -0
  32. package/dist/client/overlay/constants.d.ts +9 -0
  33. package/dist/client/overlay/constants.js +49 -0
  34. package/dist/client/overlay/constants.js.map +1 -0
  35. package/dist/client/overlay/createOverlay.d.ts +11 -0
  36. package/dist/client/overlay/createOverlay.js +80 -0
  37. package/dist/client/overlay/createOverlay.js.map +1 -0
  38. package/dist/client/overlay/editBadge.d.ts +21 -0
  39. package/dist/client/overlay/editBadge.js +99 -0
  40. package/dist/client/overlay/editBadge.js.map +1 -0
  41. package/dist/client/overlay/hoverController.d.ts +14 -0
  42. package/dist/client/overlay/hoverController.js +137 -0
  43. package/dist/client/overlay/hoverController.js.map +1 -0
  44. package/dist/client/overlay/markerExtractor.d.ts +8 -0
  45. package/dist/client/overlay/markerExtractor.js +47 -0
  46. package/dist/client/overlay/markerExtractor.js.map +1 -0
  47. package/dist/client/overlay/mutationPipeline.d.ts +10 -0
  48. package/dist/client/overlay/mutationPipeline.js +78 -0
  49. package/dist/client/overlay/mutationPipeline.js.map +1 -0
  50. package/dist/client/overlay/stegaBookkeeper.d.ts +11 -0
  51. package/dist/client/overlay/stegaBookkeeper.js +36 -0
  52. package/dist/client/overlay/stegaBookkeeper.js.map +1 -0
  53. package/dist/client/overlay/stegaScanner.d.ts +11 -0
  54. package/dist/client/overlay/stegaScanner.js +54 -0
  55. package/dist/client/overlay/stegaScanner.js.map +1 -0
  56. package/dist/client/overlay/targetRegistry.d.ts +34 -0
  57. package/dist/client/overlay/targetRegistry.js +70 -0
  58. package/dist/client/overlay/targetRegistry.js.map +1 -0
  59. package/dist/client/overlay/targetSelector.d.ts +2 -0
  60. package/dist/client/overlay/targetSelector.js +67 -0
  61. package/dist/client/overlay/targetSelector.js.map +1 -0
  62. package/dist/client/overlayClickHandler.d.ts +7 -0
  63. package/dist/client/overlayClickHandler.js +24 -0
  64. package/dist/client/overlayClickHandler.js.map +1 -0
  65. package/dist/client/useVisualEditingOverlay.d.ts +4 -0
  66. package/dist/client/useVisualEditingOverlay.js +21 -0
  67. package/dist/client/useVisualEditingOverlay.js.map +1 -0
  68. package/dist/client/withVisualEditingPath.d.ts +9 -0
  69. package/dist/client/withVisualEditingPath.js +17 -0
  70. package/dist/client/withVisualEditingPath.js.map +1 -0
  71. package/dist/constants.d.ts +16 -0
  72. package/dist/constants.js +15 -0
  73. package/dist/constants.js.map +1 -0
  74. package/dist/excludeValues.d.ts +6 -0
  75. package/dist/excludeValues.js +24 -0
  76. package/dist/excludeValues.js.map +1 -0
  77. package/dist/index.d.ts +13 -0
  78. package/dist/index.js +107 -0
  79. package/dist/index.js.map +1 -0
  80. package/dist/internal/afterOperationHook.d.ts +10 -0
  81. package/dist/internal/afterOperationHook.js +28 -0
  82. package/dist/internal/afterOperationHook.js.map +1 -0
  83. package/dist/internal/afterReadHook.d.ts +2 -0
  84. package/dist/internal/afterReadHook.js +16 -0
  85. package/dist/internal/afterReadHook.js.map +1 -0
  86. package/dist/internal/beforeOperationHook.d.ts +4 -0
  87. package/dist/internal/beforeOperationHook.js +16 -0
  88. package/dist/internal/beforeOperationHook.js.map +1 -0
  89. package/dist/internal/buildFieldSchema.d.ts +3 -0
  90. package/dist/internal/buildFieldSchema.js +67 -0
  91. package/dist/internal/buildFieldSchema.js.map +1 -0
  92. package/dist/internal/encodeStega.d.ts +7 -0
  93. package/dist/internal/encodeStega.js +171 -0
  94. package/dist/internal/encodeStega.js.map +1 -0
  95. package/dist/internal/enrichWithPathMeta.d.ts +4 -0
  96. package/dist/internal/enrichWithPathMeta.js +76 -0
  97. package/dist/internal/enrichWithPathMeta.js.map +1 -0
  98. package/dist/internal/filterEditableFields.d.ts +2 -0
  99. package/dist/internal/filterEditableFields.js +88 -0
  100. package/dist/internal/filterEditableFields.js.map +1 -0
  101. package/dist/internal/gate.d.ts +2 -0
  102. package/dist/internal/gate.js +15 -0
  103. package/dist/internal/gate.js.map +1 -0
  104. package/dist/internal/globalAfterReadHook.d.ts +10 -0
  105. package/dist/internal/globalAfterReadHook.js +19 -0
  106. package/dist/internal/globalAfterReadHook.js.map +1 -0
  107. package/dist/internal/markTerminalUploads.d.ts +13 -0
  108. package/dist/internal/markTerminalUploads.js +79 -0
  109. package/dist/internal/markTerminalUploads.js.map +1 -0
  110. package/dist/internal/schemaCache.d.ts +10 -0
  111. package/dist/internal/schemaCache.js +29 -0
  112. package/dist/internal/schemaCache.js.map +1 -0
  113. package/dist/internal/shared.d.ts +32 -0
  114. package/dist/internal/shared.js +55 -0
  115. package/dist/internal/shared.js.map +1 -0
  116. package/dist/internal/stripStegaHook.d.ts +2 -0
  117. package/dist/internal/stripStegaHook.js +29 -0
  118. package/dist/internal/stripStegaHook.js.map +1 -0
  119. package/package.json +105 -0
@@ -0,0 +1,21 @@
1
+ export type EditBadgeConfig = {
2
+ href: string;
3
+ clickHandler: (event: MouseEvent) => void;
4
+ originalOutline: string;
5
+ /** Whether the badge should paint/restore the outline. False when the registry already painted
6
+ * a persistent outline ('always' mode) — the badge only manages the Edit link then. */
7
+ paintOutline: boolean;
8
+ };
9
+ export interface EditBadge {
10
+ /** The <a> label element — HoverController references it for the `relatedTarget === label` transition. */
11
+ readonly labelElement: HTMLAnchorElement;
12
+ /** Show the badge anchored to `target`, set its href and click listener, paint the outline. */
13
+ show(target: HTMLElement, config: EditBadgeConfig): void;
14
+ /** Hide the badge and restore the outline that was on the currently-shown target. */
15
+ hide(): void;
16
+ /** Re-position the anchor to the given target's current bounding rect. */
17
+ reposition(target: HTMLElement): void;
18
+ /** Remove the badge DOM and all internally-attached listeners. */
19
+ dispose(): void;
20
+ }
21
+ export declare function createEditBadge(): EditBadge;
@@ -0,0 +1,99 @@
1
+ import { DATA_VE_FOR_ATTR, DATA_VE_TARGET_ATTR, LABEL_CLASS, LABEL_STYLES, OUTLINE_STYLE } from "./constants.js";
2
+ // Portal-rendered Edit badge. We deliberately DO NOT append the badge into
3
+ // the target's subtree: doing so changes the target's child count and can
4
+ // trigger sibling-selector recalculation (Tailwind `space-y-*` / `:last-child`
5
+ // margin resets / `* + *` spacing), causing visible layout jumps on hover.
6
+ // The layer lives on <body>, uses `position: fixed` with `pointer-events: none`
7
+ // (so it never blocks pointer events against real content), and an inner
8
+ // `anchor` element is sized/translated to match the active target's
9
+ // `getBoundingClientRect()` each time the active target changes.
10
+ export function createEditBadge() {
11
+ const layer = document.createElement("div");
12
+ layer.dataset.veLayer = "true";
13
+ Object.assign(layer.style, {
14
+ position: "fixed",
15
+ top: "0",
16
+ left: "0",
17
+ width: "0",
18
+ height: "0",
19
+ pointerEvents: "none",
20
+ zIndex: "2147483647",
21
+ visibility: "hidden"
22
+ });
23
+ const anchor = document.createElement("div");
24
+ Object.assign(anchor.style, {
25
+ position: "absolute",
26
+ top: "0",
27
+ left: "0",
28
+ width: "0",
29
+ height: "0",
30
+ pointerEvents: "none",
31
+ transform: "translate(0, 0)"
32
+ });
33
+ const label = document.createElement("a");
34
+ label.textContent = "Edit";
35
+ label.className = LABEL_CLASS;
36
+ label.target = "_blank";
37
+ label.rel = "noopener noreferrer";
38
+ Object.assign(label.style, LABEL_STYLES);
39
+ anchor.append(label);
40
+ layer.append(anchor);
41
+ document.body.append(layer);
42
+ let currentClickHandler = null;
43
+ let currentTarget = null;
44
+ let currentOriginalOutline = "";
45
+ let currentPaintedOutline = false;
46
+ const reposition = (target)=>{
47
+ const rect = target.getBoundingClientRect();
48
+ anchor.style.transform = `translate(${rect.left}px, ${rect.top}px)`;
49
+ anchor.style.width = `${rect.width}px`;
50
+ anchor.style.height = `${rect.height}px`;
51
+ };
52
+ return {
53
+ get labelElement () {
54
+ return label;
55
+ },
56
+ show (target, config) {
57
+ if (config.paintOutline) {
58
+ target.style.outline = OUTLINE_STYLE;
59
+ currentPaintedOutline = true;
60
+ } else {
61
+ currentPaintedOutline = false;
62
+ }
63
+ reposition(target);
64
+ label.href = config.href;
65
+ label.setAttribute(DATA_VE_FOR_ATTR, target.getAttribute(DATA_VE_TARGET_ATTR) ?? "");
66
+ if (currentClickHandler) label.removeEventListener("click", currentClickHandler);
67
+ label.addEventListener("click", config.clickHandler);
68
+ currentClickHandler = config.clickHandler;
69
+ currentTarget = target;
70
+ currentOriginalOutline = config.originalOutline;
71
+ layer.style.visibility = "visible";
72
+ },
73
+ hide () {
74
+ if (currentTarget) {
75
+ if (currentPaintedOutline) {
76
+ currentTarget.style.outline = currentOriginalOutline;
77
+ }
78
+ currentTarget = null;
79
+ currentOriginalOutline = "";
80
+ currentPaintedOutline = false;
81
+ }
82
+ layer.style.visibility = "hidden";
83
+ if (currentClickHandler) {
84
+ label.removeEventListener("click", currentClickHandler);
85
+ currentClickHandler = null;
86
+ }
87
+ },
88
+ reposition,
89
+ dispose () {
90
+ if (currentClickHandler) {
91
+ label.removeEventListener("click", currentClickHandler);
92
+ currentClickHandler = null;
93
+ }
94
+ layer.remove();
95
+ }
96
+ };
97
+ }
98
+
99
+ //# sourceMappingURL=editBadge.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/client/overlay/editBadge.ts"],"sourcesContent":["import {\n DATA_VE_FOR_ATTR,\n DATA_VE_TARGET_ATTR,\n LABEL_CLASS,\n LABEL_STYLES,\n OUTLINE_STYLE,\n} from \"./constants.js\";\n\nexport type EditBadgeConfig = {\n href: string;\n clickHandler: (event: MouseEvent) => void;\n originalOutline: string;\n /** Whether the badge should paint/restore the outline. False when the registry already painted\n * a persistent outline ('always' mode) — the badge only manages the Edit link then. */\n paintOutline: boolean;\n};\n\nexport interface EditBadge {\n /** The <a> label element — HoverController references it for the `relatedTarget === label` transition. */\n readonly labelElement: HTMLAnchorElement;\n /** Show the badge anchored to `target`, set its href and click listener, paint the outline. */\n show(target: HTMLElement, config: EditBadgeConfig): void;\n /** Hide the badge and restore the outline that was on the currently-shown target. */\n hide(): void;\n /** Re-position the anchor to the given target's current bounding rect. */\n reposition(target: HTMLElement): void;\n /** Remove the badge DOM and all internally-attached listeners. */\n dispose(): void;\n}\n\n// Portal-rendered Edit badge. We deliberately DO NOT append the badge into\n// the target's subtree: doing so changes the target's child count and can\n// trigger sibling-selector recalculation (Tailwind `space-y-*` / `:last-child`\n// margin resets / `* + *` spacing), causing visible layout jumps on hover.\n// The layer lives on <body>, uses `position: fixed` with `pointer-events: none`\n// (so it never blocks pointer events against real content), and an inner\n// `anchor` element is sized/translated to match the active target's\n// `getBoundingClientRect()` each time the active target changes.\nexport function createEditBadge(): EditBadge {\n const layer = document.createElement(\"div\");\n layer.dataset.veLayer = \"true\";\n Object.assign(layer.style, {\n position: \"fixed\",\n top: \"0\",\n left: \"0\",\n width: \"0\",\n height: \"0\",\n pointerEvents: \"none\",\n zIndex: \"2147483647\",\n visibility: \"hidden\",\n } as Partial<CSSStyleDeclaration>);\n\n const anchor = document.createElement(\"div\");\n Object.assign(anchor.style, {\n position: \"absolute\",\n top: \"0\",\n left: \"0\",\n width: \"0\",\n height: \"0\",\n pointerEvents: \"none\",\n transform: \"translate(0, 0)\",\n } as Partial<CSSStyleDeclaration>);\n\n const label = document.createElement(\"a\");\n label.textContent = \"Edit\";\n label.className = LABEL_CLASS;\n label.target = \"_blank\";\n label.rel = \"noopener noreferrer\";\n Object.assign(label.style, LABEL_STYLES);\n\n anchor.append(label);\n layer.append(anchor);\n document.body.append(layer);\n\n let currentClickHandler: ((event: MouseEvent) => void) | null = null;\n let currentTarget: HTMLElement | null = null;\n let currentOriginalOutline = \"\";\n let currentPaintedOutline = false;\n\n const reposition = (target: HTMLElement) => {\n const rect = target.getBoundingClientRect();\n anchor.style.transform = `translate(${rect.left}px, ${rect.top}px)`;\n anchor.style.width = `${rect.width}px`;\n anchor.style.height = `${rect.height}px`;\n };\n\n return {\n get labelElement() {\n return label;\n },\n show(target, config) {\n if (config.paintOutline) {\n target.style.outline = OUTLINE_STYLE;\n currentPaintedOutline = true;\n } else {\n currentPaintedOutline = false;\n }\n reposition(target);\n label.href = config.href;\n label.setAttribute(DATA_VE_FOR_ATTR, target.getAttribute(DATA_VE_TARGET_ATTR) ?? \"\");\n if (currentClickHandler) label.removeEventListener(\"click\", currentClickHandler);\n label.addEventListener(\"click\", config.clickHandler);\n currentClickHandler = config.clickHandler;\n currentTarget = target;\n currentOriginalOutline = config.originalOutline;\n layer.style.visibility = \"visible\";\n },\n hide() {\n if (currentTarget) {\n if (currentPaintedOutline) {\n currentTarget.style.outline = currentOriginalOutline;\n }\n currentTarget = null;\n currentOriginalOutline = \"\";\n currentPaintedOutline = false;\n }\n layer.style.visibility = \"hidden\";\n if (currentClickHandler) {\n label.removeEventListener(\"click\", currentClickHandler);\n currentClickHandler = null;\n }\n },\n reposition,\n dispose() {\n if (currentClickHandler) {\n label.removeEventListener(\"click\", currentClickHandler);\n currentClickHandler = null;\n }\n layer.remove();\n },\n };\n}\n"],"names":["DATA_VE_FOR_ATTR","DATA_VE_TARGET_ATTR","LABEL_CLASS","LABEL_STYLES","OUTLINE_STYLE","createEditBadge","layer","document","createElement","dataset","veLayer","Object","assign","style","position","top","left","width","height","pointerEvents","zIndex","visibility","anchor","transform","label","textContent","className","target","rel","append","body","currentClickHandler","currentTarget","currentOriginalOutline","currentPaintedOutline","reposition","rect","getBoundingClientRect","labelElement","show","config","paintOutline","outline","href","setAttribute","getAttribute","removeEventListener","addEventListener","clickHandler","originalOutline","hide","dispose","remove"],"mappings":"AAAA,SACEA,gBAAgB,EAChBC,mBAAmB,EACnBC,WAAW,EACXC,YAAY,EACZC,aAAa,QACR,iBAAiB;AAwBxB,2EAA2E;AAC3E,0EAA0E;AAC1E,+EAA+E;AAC/E,2EAA2E;AAC3E,gFAAgF;AAChF,yEAAyE;AACzE,oEAAoE;AACpE,iEAAiE;AACjE,OAAO,SAASC;IACd,MAAMC,QAAQC,SAASC,aAAa,CAAC;IACrCF,MAAMG,OAAO,CAACC,OAAO,GAAG;IACxBC,OAAOC,MAAM,CAACN,MAAMO,KAAK,EAAE;QACzBC,UAAU;QACVC,KAAK;QACLC,MAAM;QACNC,OAAO;QACPC,QAAQ;QACRC,eAAe;QACfC,QAAQ;QACRC,YAAY;IACd;IAEA,MAAMC,SAASf,SAASC,aAAa,CAAC;IACtCG,OAAOC,MAAM,CAACU,OAAOT,KAAK,EAAE;QAC1BC,UAAU;QACVC,KAAK;QACLC,MAAM;Q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AAOQ,YAAY;YACnDjB,sBAAsBS,OAAOQ,YAAY;YACzChB,gBAAgBL;YAChBM,yBAAyBO,OAAOS,eAAe;YAC/C3C,MAAMO,KAAK,CAACQ,UAAU,GAAG;QAC3B;QACA6B;YACE,IAAIlB,eAAe;gBACjB,IAAIE,uBAAuB;oBACzBF,cAAcnB,KAAK,CAAC6B,OAAO,GAAGT;gBAChC;gBACAD,gBAAgB;gBAChBC,yBAAyB;gBACzBC,wBAAwB;YAC1B;YACA5B,MAAMO,KAAK,CAACQ,UAAU,GAAG;YACzB,IAAIU,qBAAqB;gBACvBP,MAAMsB,mBAAmB,CAAC,SAASf;gBACnCA,sBAAsB;YACxB;QACF;QACAI;QACAgB;YACE,IAAIpB,qBAAqB;gBACvBP,MAAMsB,mBAAmB,CAAC,SAASf;gBACnCA,sBAAsB;YACxB;YACAzB,MAAM8C,MAAM;QACd;IACF;AACF"}
@@ -0,0 +1,14 @@
1
+ import type { EditBadge } from "./editBadge.js";
2
+ import type { TargetRegistry } from "./targetRegistry.js";
3
+ export interface HoverController {
4
+ /** Bind mouseenter/mouseleave listeners to `target`. Target must already be in the registry. */
5
+ attach(target: HTMLElement): void;
6
+ /** Remove listeners from `target`; hides the badge if `target` was the active one. */
7
+ detach(target: HTMLElement): void;
8
+ /** If `target` is currently active, re-show the badge with its latest registry config.
9
+ * Called after a same-element marker change so the visible Edit link points at the new path. */
10
+ refresh(target: HTMLElement): void;
11
+ /** Remove all global listeners (scroll/resize/label) and any remaining per-target listeners. */
12
+ dispose(): void;
13
+ }
14
+ export declare function createHoverController(badge: EditBadge, registry: TargetRegistry): HoverController;
@@ -0,0 +1,137 @@
1
+ import { findTargetAncestor } from "./targetSelector.js";
2
+ const HOVER_FLAG_ATTR = "data-ve-hovering";
3
+ const setHoverFlag = (on)=>{
4
+ const body = typeof document === "undefined" ? null : document.body;
5
+ if (!body) return;
6
+ if (on) body.setAttribute(HOVER_FLAG_ATTR, "true");
7
+ else body.removeAttribute(HOVER_FLAG_ATTR);
8
+ };
9
+ // Grace period on clearing `activeTarget`
10
+ const CLEAR_GRACE_MS = 250;
11
+ // Only the innermost target under the cursor shows an overlay. Nested targets would otherwise
12
+ // all stay "hovered" simultaneously (mouseleave doesn't fire on an ancestor when the mouse
13
+ // enters a descendant), which stacks outlines and overlaps Edit badges. We track a single
14
+ // `activeTarget` and swap it on each mouseenter/mouseleave transition.
15
+ export function createHoverController(badge, registry) {
16
+ const label = badge.labelElement;
17
+ let activeTarget = null;
18
+ let pendingClear = null;
19
+ const targetListeners = new Map();
20
+ const cancelPendingClear = ()=>{
21
+ if (pendingClear === null) return;
22
+ clearTimeout(pendingClear);
23
+ pendingClear = null;
24
+ };
25
+ const setActive = (next)=>{
26
+ cancelPendingClear();
27
+ if (next === activeTarget) return;
28
+ if (activeTarget) badge.hide();
29
+ if (next) {
30
+ const config = registry.get(next);
31
+ if (config) badge.show(next, config);
32
+ }
33
+ activeTarget = next;
34
+ setHoverFlag(next !== null);
35
+ };
36
+ const scheduleClear = ()=>{
37
+ if (pendingClear !== null) return;
38
+ pendingClear = setTimeout(()=>{
39
+ pendingClear = null;
40
+ setActive(null);
41
+ }, CLEAR_GRACE_MS);
42
+ };
43
+ // The Edit badge lives outside the target in the DOM, so moving the mouse from the target
44
+ // up onto the badge fires a mouseleave on the target. We intercept that specific transition
45
+ // (relatedTarget === label) to keep the overlay open, and rely on the label's own
46
+ // mouseleave to decide what to do next when the user leaves the badge.
47
+ const onLabelLeave = (event)=>{
48
+ if (!activeTarget) return;
49
+ const related = event.relatedTarget;
50
+ if (related && (related === activeTarget || activeTarget.contains(related))) return;
51
+ const nextTarget = related ? findTargetAncestor(related) : null;
52
+ if (nextTarget) setActive(nextTarget);
53
+ else scheduleClear();
54
+ };
55
+ label.addEventListener("mouseleave", onLabelLeave);
56
+ // Cursor reaching the label via the dead-zone between target.top and the
57
+ // badge resolves the pending clear scheduled from target.mouseleave.
58
+ const onLabelEnter = ()=>cancelPendingClear();
59
+ label.addEventListener("mouseenter", onLabelEnter);
60
+ const repositionIfActive = ()=>{
61
+ if (!activeTarget) return;
62
+ if (!activeTarget.isConnected) {
63
+ setActive(null);
64
+ return;
65
+ }
66
+ badge.reposition(activeTarget);
67
+ };
68
+ window.addEventListener("scroll", repositionIfActive, {
69
+ capture: true,
70
+ passive: true
71
+ });
72
+ window.addEventListener("resize", repositionIfActive, {
73
+ passive: true
74
+ });
75
+ return {
76
+ attach (target) {
77
+ if (targetListeners.has(target)) return;
78
+ const enter = ()=>setActive(target);
79
+ const leave = (event)=>{
80
+ if (activeTarget !== target) return;
81
+ const related = event.relatedTarget;
82
+ // Mouse crossed into our own Edit badge — keep the overlay open,
83
+ // the label's own mouseleave will take over from here.
84
+ if (related === label) return;
85
+ const nextTarget = related ? findTargetAncestor(related) : null;
86
+ // Committing null immediately is the dead-zone bug (see CLEAR_GRACE_MS):
87
+ // the cursor is often mid-transit to the Edit label and a label.mouseenter
88
+ // is about to cancel this. Schedule instead.
89
+ if (nextTarget) setActive(nextTarget);
90
+ else scheduleClear();
91
+ };
92
+ target.addEventListener("mouseenter", enter);
93
+ target.addEventListener("mouseleave", leave);
94
+ targetListeners.set(target, {
95
+ enter,
96
+ leave
97
+ });
98
+ },
99
+ detach (target) {
100
+ const listeners = targetListeners.get(target);
101
+ if (!listeners) return;
102
+ target.removeEventListener("mouseenter", listeners.enter);
103
+ target.removeEventListener("mouseleave", listeners.leave);
104
+ targetListeners.delete(target);
105
+ if (activeTarget === target) {
106
+ cancelPendingClear();
107
+ badge.hide();
108
+ activeTarget = null;
109
+ setHoverFlag(false);
110
+ }
111
+ },
112
+ refresh (target) {
113
+ if (activeTarget !== target) return;
114
+ const config = registry.get(target);
115
+ if (config) badge.show(target, config);
116
+ },
117
+ dispose () {
118
+ cancelPendingClear();
119
+ window.removeEventListener("scroll", repositionIfActive, true);
120
+ window.removeEventListener("resize", repositionIfActive);
121
+ label.removeEventListener("mouseleave", onLabelLeave);
122
+ label.removeEventListener("mouseenter", onLabelEnter);
123
+ for (const [target, listeners] of targetListeners){
124
+ target.removeEventListener("mouseenter", listeners.enter);
125
+ target.removeEventListener("mouseleave", listeners.leave);
126
+ }
127
+ targetListeners.clear();
128
+ if (activeTarget) {
129
+ badge.hide();
130
+ activeTarget = null;
131
+ }
132
+ setHoverFlag(false);
133
+ }
134
+ };
135
+ }
136
+
137
+ //# sourceMappingURL=hoverController.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/client/overlay/hoverController.ts"],"sourcesContent":["import type { EditBadge } from \"./editBadge.js\";\nimport type { TargetRegistry } from \"./targetRegistry.js\";\n\nimport { findTargetAncestor } from \"./targetSelector.js\";\n\nexport interface HoverController {\n /** Bind mouseenter/mouseleave listeners to `target`. Target must already be in the registry. */\n attach(target: HTMLElement): void;\n /** Remove listeners from `target`; hides the badge if `target` was the active one. */\n detach(target: HTMLElement): void;\n /** If `target` is currently active, re-show the badge with its latest registry config.\n * Called after a same-element marker change so the visible Edit link points at the new path. */\n refresh(target: HTMLElement): void;\n /** Remove all global listeners (scroll/resize/label) and any remaining per-target listeners. */\n dispose(): void;\n}\n\nconst HOVER_FLAG_ATTR = \"data-ve-hovering\";\nconst setHoverFlag = (on: boolean): void => {\n const body = typeof document === \"undefined\" ? null : document.body;\n if (!body) return;\n if (on) body.setAttribute(HOVER_FLAG_ATTR, \"true\");\n else body.removeAttribute(HOVER_FLAG_ATTR);\n};\n\n// Grace period on clearing `activeTarget`\nconst CLEAR_GRACE_MS = 250;\n\n// Only the innermost target under the cursor shows an overlay. Nested targets would otherwise\n// all stay \"hovered\" simultaneously (mouseleave doesn't fire on an ancestor when the mouse\n// enters a descendant), which stacks outlines and overlaps Edit badges. We track a single\n// `activeTarget` and swap it on each mouseenter/mouseleave transition.\nexport function createHoverController(badge: EditBadge, registry: TargetRegistry): HoverController {\n const label = badge.labelElement;\n let activeTarget: HTMLElement | null = null;\n let pendingClear: ReturnType<typeof setTimeout> | null = null;\n const targetListeners = new Map<\n HTMLElement,\n { enter: () => void; leave: (event: MouseEvent) => void }\n >();\n\n const cancelPendingClear = (): void => {\n if (pendingClear === null) return;\n clearTimeout(pendingClear);\n pendingClear = null;\n };\n\n const setActive = (next: HTMLElement | null) => {\n cancelPendingClear();\n if (next === activeTarget) return;\n if (activeTarget) badge.hide();\n if (next) {\n const config = registry.get(next);\n if (config) badge.show(next, config);\n }\n activeTarget = next;\n setHoverFlag(next !== null);\n };\n\n const scheduleClear = (): void => {\n if (pendingClear !== null) return;\n pendingClear = setTimeout(() => {\n pendingClear = null;\n setActive(null);\n }, CLEAR_GRACE_MS);\n };\n\n // The Edit badge lives outside the target in the DOM, so moving the mouse from the target\n // up onto the badge fires a mouseleave on the target. We intercept that specific transition\n // (relatedTarget === label) to keep the overlay open, and rely on the label's own\n // mouseleave to decide what to do next when the user leaves the badge.\n const onLabelLeave = (event: MouseEvent) => {\n if (!activeTarget) return;\n const related = event.relatedTarget as Element | null;\n if (related && (related === activeTarget || activeTarget.contains(related))) return;\n const nextTarget = related ? findTargetAncestor(related) : null;\n if (nextTarget) setActive(nextTarget);\n else scheduleClear();\n };\n label.addEventListener(\"mouseleave\", onLabelLeave);\n // Cursor reaching the label via the dead-zone between target.top and the\n // badge resolves the pending clear scheduled from target.mouseleave.\n const onLabelEnter = () => cancelPendingClear();\n label.addEventListener(\"mouseenter\", onLabelEnter);\n\n const repositionIfActive = () => {\n if (!activeTarget) return;\n if (!activeTarget.isConnected) {\n setActive(null);\n return;\n }\n badge.reposition(activeTarget);\n };\n window.addEventListener(\"scroll\", repositionIfActive, { capture: true, passive: true });\n window.addEventListener(\"resize\", repositionIfActive, { passive: true });\n\n return {\n attach(target) {\n if (targetListeners.has(target)) return;\n const enter = () => setActive(target);\n const leave = (event: MouseEvent) => {\n if (activeTarget !== target) return;\n const related = event.relatedTarget as Element | null;\n // Mouse crossed into our own Edit badge — keep the overlay open,\n // the label's own mouseleave will take over from here.\n if (related === label) return;\n const nextTarget = related ? findTargetAncestor(related) : null;\n // Committing null immediately is the dead-zone bug (see CLEAR_GRACE_MS):\n // the cursor is often mid-transit to the Edit label and a label.mouseenter\n // is about to cancel this. Schedule instead.\n if (nextTarget) setActive(nextTarget);\n else scheduleClear();\n };\n target.addEventListener(\"mouseenter\", enter);\n target.addEventListener(\"mouseleave\", leave);\n targetListeners.set(target, { enter, leave });\n },\n detach(target) {\n const listeners = targetListeners.get(target);\n if (!listeners) return;\n target.removeEventListener(\"mouseenter\", listeners.enter);\n target.removeEventListener(\"mouseleave\", listeners.leave);\n targetListeners.delete(target);\n if (activeTarget === target) {\n cancelPendingClear();\n badge.hide();\n activeTarget = null;\n setHoverFlag(false);\n }\n },\n refresh(target) {\n if (activeTarget !== target) return;\n const config = registry.get(target);\n if (config) badge.show(target, config);\n },\n dispose() {\n cancelPendingClear();\n window.removeEventListener(\"scroll\", repositionIfActive, true);\n window.removeEventListener(\"resize\", repositionIfActive);\n label.removeEventListener(\"mouseleave\", onLabelLeave);\n label.removeEventListener(\"mouseenter\", onLabelEnter);\n for (const [target, listeners] of targetListeners) {\n target.removeEventListener(\"mouseenter\", listeners.enter);\n target.removeEventListener(\"mouseleave\", listeners.leave);\n }\n targetListeners.clear();\n if (activeTarget) {\n badge.hide();\n activeTarget = null;\n }\n setHoverFlag(false);\n },\n };\n}\n"],"names":["findTargetAncestor","HOVER_FLAG_ATTR","setHoverFlag","on","body","document","setAttribute","removeAttribute","CLEAR_GRACE_MS","createHoverController","badge","registry","label","labelElement","activeTarget","pendingClear","targetListeners","Map","cancelPendingClear","clearTimeout","setActive","next","hide","config","get","show","scheduleClear","setTimeout","onLabelLeave","event","related","relatedTarget","contains","nextTarget","addEventListener","onLabelEnter","repositionIfActive","isConnected","reposition","window","capture","passive","attach","target","has","enter","leave","set","detach","listeners","removeEventListener","delete","refresh","dispose","clear"],"mappings":"AAGA,SAASA,kBAAkB,QAAQ,sBAAsB;AAczD,MAAMC,kBAAkB;AACxB,MAAMC,eAAe,CAACC;IACpB,MAAMC,OAAO,OAAOC,a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iB6B,QAAQ;YAC7B,MAAMpB,SAASZ,SAASa,GAAG,CAACmB;YAC5B,IAAIpB,QAAQb,MAAMe,IAAI,CAACkB,QAAQpB;QACjC;QACA8B;YACEnC;YACAqB,OAAOW,mBAAmB,CAAC,UAAUd,oBAAoB;YACzDG,OAAOW,mBAAmB,CAAC,UAAUd;YACrCxB,MAAMsC,mBAAmB,CAAC,cAActB;YACxChB,MAAMsC,mBAAmB,CAAC,cAAcf;YACxC,KAAK,MAAM,CAACQ,QAAQM,UAAU,IAAIjC,gBAAiB;gBACjD2B,OAAOO,mBAAmB,CAAC,cAAcD,UAAUJ,KAAK;gBACxDF,OAAOO,mBAAmB,CAAC,cAAcD,UAAUH,KAAK;YAC1D;YACA9B,gBAAgBsC,KAAK;YACrB,IAAIxC,cAAc;gBAChBJ,MAAMY,IAAI;gBACVR,eAAe;YACjB;YACAZ,aAAa;QACf;IACF;AACF"}
@@ -0,0 +1,8 @@
1
+ import type { VeIdentity } from "../../internal/shared.js";
2
+ import type { TextMatch } from "./stegaScanner.js";
3
+ export type Marker = VeIdentity;
4
+ export declare function readMarkerFromAttrs(target: HTMLElement): Marker | null;
5
+ export declare function groupNodesByPath(matches: readonly TextMatch[]): Array<{
6
+ nodes: Text[];
7
+ ctx: Marker;
8
+ }>;
@@ -0,0 +1,47 @@
1
+ import { DATA_VE_COLLECTION_ATTR, DATA_VE_DOC_ID_ATTR, DATA_VE_KIND_ATTR, DATA_VE_PATH_ATTR } from "../../constants.js";
2
+ export function readMarkerFromAttrs(target) {
3
+ const rawPath = target.getAttribute(DATA_VE_PATH_ATTR);
4
+ const collectionSlug = target.getAttribute(DATA_VE_COLLECTION_ATTR) ?? "";
5
+ if (rawPath === null || !collectionSlug) return null;
6
+ const kind = target.getAttribute(DATA_VE_KIND_ATTR) ?? "collection";
7
+ const docId = target.getAttribute(DATA_VE_DOC_ID_ATTR) ?? undefined;
8
+ const marker = {
9
+ path: rawPath,
10
+ collectionSlug: collectionSlug,
11
+ kind
12
+ };
13
+ if (docId !== undefined) marker.docId = docId;
14
+ return marker;
15
+ }
16
+ // Group text matches by full doc identity AND their nearest <a>/<button>
17
+ // ancestor. Two matches that share a relative path but come from different
18
+ // documents (e.g. three sibling FeatureSet cards each with `title`) must not
19
+ // collapse into one group — their LCA would be the wrapper around all cards,
20
+ // producing one giant target instead of a per-card one. The anchor check
21
+ // handles the remaining case of the same field rendered twice inside one doc
22
+ // (e.g. a link label duplicated for mobile + desktop).
23
+ export function groupNodesByPath(matches) {
24
+ const groups = [];
25
+ for (const m of matches){
26
+ const anchor = m.textNode.parentElement?.closest("a, button") ?? null;
27
+ const existing = groups.find((g)=>g.ctx.path === m.path && g.ctx.collectionSlug === m.collectionSlug && g.ctx.docId === m.docId && g.anchor === anchor);
28
+ if (existing) {
29
+ if (!existing.nodes.includes(m.textNode)) existing.nodes.push(m.textNode);
30
+ } else {
31
+ const { textNode: _textNode, ...id } = m;
32
+ groups.push({
33
+ anchor,
34
+ nodes: [
35
+ m.textNode
36
+ ],
37
+ ctx: id
38
+ });
39
+ }
40
+ }
41
+ return groups.map(({ nodes, ctx })=>({
42
+ nodes,
43
+ ctx
44
+ }));
45
+ }
46
+
47
+ //# sourceMappingURL=markerExtractor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/client/overlay/markerExtractor.ts"],"sourcesContent":["import type { DocKind, VeIdentity } from \"../../internal/shared.js\";\nimport type { TextMatch } from \"./stegaScanner.js\";\n\nimport {\n DATA_VE_COLLECTION_ATTR,\n DATA_VE_DOC_ID_ATTR,\n DATA_VE_KIND_ATTR,\n DATA_VE_PATH_ATTR,\n} from \"../../constants.js\";\n\nexport type Marker = VeIdentity;\n\nexport function readMarkerFromAttrs(target: HTMLElement): Marker | null {\n const rawPath = target.getAttribute(DATA_VE_PATH_ATTR);\n const collectionSlug = target.getAttribute(DATA_VE_COLLECTION_ATTR) ?? \"\";\n if (rawPath === null || !collectionSlug) return null;\n const kind = (target.getAttribute(DATA_VE_KIND_ATTR) as DocKind | null) ?? \"collection\";\n const docId = target.getAttribute(DATA_VE_DOC_ID_ATTR) ?? undefined;\n const marker: Marker = {\n path: rawPath,\n collectionSlug: collectionSlug as Marker[\"collectionSlug\"],\n kind,\n };\n if (docId !== undefined) marker.docId = docId;\n return marker;\n}\n\n// Group text matches by full doc identity AND their nearest <a>/<button>\n// ancestor. Two matches that share a relative path but come from different\n// documents (e.g. three sibling FeatureSet cards each with `title`) must not\n// collapse into one group — their LCA would be the wrapper around all cards,\n// producing one giant target instead of a per-card one. The anchor check\n// handles the remaining case of the same field rendered twice inside one doc\n// (e.g. a link label duplicated for mobile + desktop).\nexport function groupNodesByPath(\n matches: readonly TextMatch[]\n): Array<{ nodes: Text[]; ctx: Marker }> {\n const groups: Array<{ anchor: Element | null; nodes: Text[]; ctx: Marker }> = [];\n for (const m of matches) {\n const anchor = m.textNode.parentElement?.closest(\"a, button\") ?? null;\n const existing = groups.find(\n (g) =>\n g.ctx.path === m.path &&\n g.ctx.collectionSlug === m.collectionSlug &&\n g.ctx.docId === m.docId &&\n g.anchor === anchor\n );\n if (existing) {\n if (!existing.nodes.includes(m.textNode)) existing.nodes.push(m.textNode);\n } else {\n const { textNode: _textNode, ...id } = m;\n groups.push({ anchor, nodes: [m.textNode], ctx: id });\n }\n }\n return groups.map(({ nodes, ctx }) => ({ nodes, ctx }));\n}\n"],"names":["DATA_VE_COLLECTION_ATTR","DATA_VE_DOC_ID_ATTR","DATA_VE_KIND_ATTR","DATA_VE_PATH_ATTR","readMarkerFromAttrs","target","rawPath","getAttribute","collectionSlug","kind","docId","undefined","marker","path","groupNodesByPath","matches","groups","m","anchor","textNode","parentElement","closest","existing","find","g","ctx","nodes","includes","push","_textNode","id","map"],"mappings":"AAGA,SACEA,uBAAuB,EACvBC,mBAAmB,EACnBC,iBAAiB,EACjBC,iBAAiB,QACZ,qBAAqB;AAI5B,OAAO,SAASC,oBAAoBC,MAAmB;IACrD,MAAMC,UAAUD,OAAOE,YAAY,CAAC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AAA;YAAEC;YAAOD;QAAI,CAAA;AACtD"}
@@ -0,0 +1,10 @@
1
+ export type MutationPipelineCallbacks = {
2
+ /** Called with a minimal, de-duplicated set of roots to rescan. No root contains another. */
3
+ onRoots(roots: Element[]): void;
4
+ /** Called when React rewrote a stega-bearing value on top of a previously cleaned node. */
5
+ onTextReset(node: Text): void;
6
+ };
7
+ export interface MutationPipeline {
8
+ dispose(): void;
9
+ }
10
+ export declare function createMutationPipeline(root: Element, callbacks: MutationPipelineCallbacks): MutationPipeline;
@@ -0,0 +1,78 @@
1
+ import { LABEL_CLASS, STEGA_PREFILTER } from "./constants.js";
2
+ // Coalesces mutation bursts into a single microtask-scheduled flush, then drops descendants of
3
+ // already-kept ancestors so callers receive a minimal set of roots to rescan.
4
+ export function createMutationPipeline(root, callbacks) {
5
+ const pending = new Set();
6
+ let scheduled = false;
7
+ const flush = ()=>{
8
+ scheduled = false;
9
+ const connected = [];
10
+ for (const node of pending){
11
+ if (node.isConnected) connected.push(node);
12
+ }
13
+ pending.clear();
14
+ if (connected.length === 0) return;
15
+ // Sort by document order so ancestors come before descendants, then keep each node only
16
+ // when it's not contained by the most recently kept one. Because any descendant of an
17
+ // ancestor A appears contiguously after A in document order, comparing against just the
18
+ // last kept node is sufficient — a previously kept ancestor can't be separated from its
19
+ // descendants by a non-descendant in this traversal.
20
+ connected.sort((a, b)=>{
21
+ if (a === b) return 0;
22
+ const pos = a.compareDocumentPosition(b);
23
+ if (pos & Node.DOCUMENT_POSITION_FOLLOWING) return -1;
24
+ if (pos & Node.DOCUMENT_POSITION_PRECEDING) return 1;
25
+ return 0;
26
+ });
27
+ const kept = [];
28
+ for (const node of connected){
29
+ const last = kept[kept.length - 1];
30
+ if (last && last.contains(node)) continue;
31
+ kept.push(node);
32
+ }
33
+ callbacks.onRoots(kept);
34
+ };
35
+ const schedule = ()=>{
36
+ if (scheduled) return;
37
+ scheduled = true;
38
+ queueMicrotask(flush);
39
+ };
40
+ const observer = new MutationObserver((mutations)=>{
41
+ for (const mutation of mutations){
42
+ if (mutation.type === "childList") {
43
+ for (const node of Array.from(mutation.addedNodes)){
44
+ if (!(node instanceof Element)) continue;
45
+ // Our own `appendChild(label)` bubbles back through the observer; skip it.
46
+ if (node.classList.contains(LABEL_CLASS)) continue;
47
+ pending.add(node);
48
+ }
49
+ } else if (mutation.type === "characterData") {
50
+ const textNode = mutation.target;
51
+ if (!(textNode instanceof Text)) continue;
52
+ // Our own writes strip stega out; if the prefilter still matches, React has rewritten
53
+ // a fresh stega-bearing value over a node we already processed. Tell the caller so it
54
+ // can drop its bookkeeping before the next scan re-records the new original.
55
+ const text = textNode.textContent ?? "";
56
+ if (!STEGA_PREFILTER.test(text)) continue;
57
+ callbacks.onTextReset(textNode);
58
+ const parent = textNode.parentElement;
59
+ if (parent) pending.add(parent);
60
+ }
61
+ }
62
+ if (pending.size > 0) schedule();
63
+ });
64
+ observer.observe(root, {
65
+ childList: true,
66
+ subtree: true,
67
+ characterData: true
68
+ });
69
+ return {
70
+ dispose () {
71
+ observer.disconnect();
72
+ pending.clear();
73
+ scheduled = false;
74
+ }
75
+ };
76
+ }
77
+
78
+ //# sourceMappingURL=mutationPipeline.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/client/overlay/mutationPipeline.ts"],"sourcesContent":["import { LABEL_CLASS, STEGA_PREFILTER } from \"./constants.js\";\n\nexport type MutationPipelineCallbacks = {\n /** Called with a minimal, de-duplicated set of roots to rescan. No root contains another. */\n onRoots(roots: Element[]): void;\n /** Called when React rewrote a stega-bearing value on top of a previously cleaned node. */\n onTextReset(node: Text): void;\n};\n\nexport interface MutationPipeline {\n dispose(): void;\n}\n\n// Coalesces mutation bursts into a single microtask-scheduled flush, then drops descendants of\n// already-kept ancestors so callers receive a minimal set of roots to rescan.\nexport function createMutationPipeline(\n root: Element,\n callbacks: MutationPipelineCallbacks\n): MutationPipeline {\n const pending = new Set<Element>();\n let scheduled = false;\n\n const flush = () => {\n scheduled = false;\n const connected: Element[] = [];\n for (const node of pending) {\n if (node.isConnected) connected.push(node);\n }\n pending.clear();\n if (connected.length === 0) return;\n\n // Sort by document order so ancestors come before descendants, then keep each node only\n // when it's not contained by the most recently kept one. Because any descendant of an\n // ancestor A appears contiguously after A in document order, comparing against just the\n // last kept node is sufficient — a previously kept ancestor can't be separated from its\n // descendants by a non-descendant in this traversal.\n connected.sort((a, b) => {\n if (a === b) return 0;\n const pos = a.compareDocumentPosition(b);\n if (pos & Node.DOCUMENT_POSITION_FOLLOWING) return -1;\n if (pos & Node.DOCUMENT_POSITION_PRECEDING) return 1;\n return 0;\n });\n const kept: Element[] = [];\n for (const node of connected) {\n const last = kept[kept.length - 1];\n if (last && last.contains(node)) continue;\n kept.push(node);\n }\n callbacks.onRoots(kept);\n };\n\n const schedule = () => {\n if (scheduled) return;\n scheduled = true;\n queueMicrotask(flush);\n };\n\n const observer = new MutationObserver((mutations) => {\n for (const mutation of mutations) {\n if (mutation.type === \"childList\") {\n for (const node of Array.from(mutation.addedNodes)) {\n if (!(node instanceof Element)) continue;\n // Our own `appendChild(label)` bubbles back through the observer; skip it.\n if (node.classList.contains(LABEL_CLASS)) continue;\n pending.add(node);\n }\n } else if (mutation.type === \"characterData\") {\n const textNode = mutation.target;\n if (!(textNode instanceof Text)) continue;\n // Our own writes strip stega out; if the prefilter still matches, React has rewritten\n // a fresh stega-bearing value over a node we already processed. Tell the caller so it\n // can drop its bookkeeping before the next scan re-records the new original.\n const text = textNode.textContent ?? \"\";\n if (!STEGA_PREFILTER.test(text)) continue;\n callbacks.onTextReset(textNode);\n const parent = textNode.parentElement;\n if (parent) pending.add(parent);\n }\n }\n if (pending.size > 0) schedule();\n });\n observer.observe(root, { childList: true, subtree: true, characterData: true });\n\n return {\n dispose() {\n observer.disconnect();\n pending.clear();\n scheduled = false;\n },\n };\n}\n"],"names":["LABEL_CLASS","STEGA_PREFILTER","createMutationPipeline","root","callbacks","pending","Set","scheduled","flush","connected","node","isConnected","push","clear","length","sort","a","b","pos","compareDocumentPosition","Node","DOCUMENT_POSITION_FOLLOWING","DOCUMENT_POSITION_PRECEDING","kept","last","contains","onRoots","schedule","queueMicrotask","observer","MutationObserver","mutations","mutation","type","Array","from","addedNodes","Element","classList","add","textNode","target","Text","text","textContent","test","onTextReset","parent","parentElement","size","observe","childList","subtree","characterData","dispose","disconnect"],"mappings":"AAAA,SAASA,WAAW,EAAEC,eAAe,QAAQ,iBAAiB;AAa9D,+FAA+F;AAC/F,8EAA8E;AAC9E,OAAO,SAASC,uBACdC,IAAa,EACbC,SAAoC;IAEpC,MAAMC,UAAU,IAAIC;IACpB,IAAIC,YAAY;IAEhB,MAAMC,QAAQ;QACZD,YAAY;QACZ,MAAME,YAAuB,EAAE;QAC/B,KAAK,MAAMC,QAAQL,QAAS;YAC1B,IAAIK,KAAKC,WAAW,EAAEF,UAAUG,IAAI,CAACF;QACvC;QACAL,QAAQQ,KAAK;QACb,IAAIJ,UAAUK,MAAM,KAAK,GAAG;QAE5B,wFAAwF;QACxF,sFAAsF;QACtF,wFAAwF;QACxF,wFAAwF;QACxF,qDAAqD;QACrDL,UAAUM,IAAI,CAAC,CAACC,GAAGC;YACjB,IAAID,MAAMC,GAAG,OAAO;YACpB,MAAMC,MAAMF,EAAEG,uBAAuB,CAACF;YACtC,IAAIC,MAAME,KAAKC,2BAA2B,EAAE,OAAO,CAAC;YACpD,IAAIH,MAAME,KAAKE,2BAA2B,EAAE,OAAO;YACnD,OAAO;QACT;QACA,MAAMC,OAAkB,EAAE;QAC1B,KAAK,MAAMb,QAAQD,UAAW;YAC5B,MAAMe,OAAOD,IAAI,CAACA,KAAKT,MAAM,GAAG,EAAE;YAClC,IAAIU,QAAQA,KAAKC,QAAQ,CAACf,OAAO;YACjCa,KAAKX,IAAI,CAACF;QACZ;QACAN,UAAUsB,OAAO,CAACH;IACpB;IAEA,MAAMI,WAAW;QACf,IAAIpB,WAAW;QACfA,YAAY;QACZqB,eAAepB;IACjB;IAEA,MAAMqB,WAAW,IAAIC,iBAAiB,CAACC;QACrC,KAAK,MAAMC,YAAYD,UAAW;YAChC,IAAIC,SAASC,IAAI,KAAK,aAAa;gBACjC,KAAK,MAAMvB,QAAQwB,MAAMC,IAAI,CAACH,SAASI,UAAU,EAAG;oBAClD,IAAI,CAAE1B,CAAAA,gBAAgB2B,OAAM,GAAI;oBAChC,2EAA2E;oBAC3E,IAAI3B,KAAK4B,SAAS,CAACb,QAAQ,CAACzB,cAAc;oBAC1CK,QAAQkC,GAAG,CAAC7B;gBACd;YACF,OAAO,IAAIsB,SAASC,IAAI,KAAK,iBAAiB;gBAC5C,MAAMO,WAAWR,SAASS,MAAM;gBAChC,IAAI,CAAED,CAAAA,oBAAoBE,IAAG,GAAI;gBACjC,sFAAsF;gBACtF,sFAAsF;gBACtF,6EAA6E;gBAC7E,MAAMC,OAAOH,SAASI,WAAW,IAAI;gBACrC,IAAI,CAAC3C,gBAAgB4C,IAAI,CAACF,OAAO;gBACjCvC,UAAU0C,WAAW,CAACN;gBACtB,MAAMO,SAASP,SAASQ,aAAa;gBACrC,IAAID,QAAQ1C,QAAQkC,GAAG,CAACQ;YAC1B;QACF;QACA,IAAI1C,QAAQ4C,IAAI,GAAG,GAAGtB;IACxB;IACAE,SAASqB,OAAO,CAAC/C,MAAM;QAAEgD,WAAW;QAAMC,SAAS;QAAMC,eAAe;IAAK;IAE7E,OAAO;QACLC;YACEzB,SAAS0B,UAAU;YACnBlD,QAAQQ,KAAK;YACbN,YAAY;QACd;IACF;AACF"}
@@ -0,0 +1,11 @@
1
+ export interface StegaBookkeeper {
2
+ /** Strips stega from `node` and records its original text. Returns true when newly recorded. */
3
+ recordText(node: Text): boolean;
4
+ /** Strips stega from `el[attr]` and records the original value. Returns true when newly recorded. */
5
+ recordAttr(el: Element, attr: string, rawValue: string): boolean;
6
+ /** Called when React rewrote a stega-bearing value on top of a node we already cleaned. */
7
+ forgetText(node: Text): void;
8
+ /** Restore original stega-bearing text/attrs on every still-connected node. */
9
+ restoreAll(): void;
10
+ }
11
+ export declare function createStegaBookkeeper(): StegaBookkeeper;
@@ -0,0 +1,36 @@
1
+ import { vercelStegaSplit } from "@vercel/stega";
2
+ export function createStegaBookkeeper() {
3
+ const textOriginals = new Map();
4
+ const attrOriginals = new Map();
5
+ return {
6
+ recordText (node) {
7
+ if (textOriginals.has(node)) return false;
8
+ const text = node.textContent ?? "";
9
+ textOriginals.set(node, text);
10
+ node.textContent = vercelStegaSplit(text).cleaned;
11
+ return true;
12
+ },
13
+ recordAttr (el, attr, rawValue) {
14
+ const byAttr = attrOriginals.get(el) ?? new Map();
15
+ if (byAttr.has(attr)) return false;
16
+ byAttr.set(attr, rawValue);
17
+ attrOriginals.set(el, byAttr);
18
+ el.setAttribute(attr, vercelStegaSplit(rawValue).cleaned);
19
+ return true;
20
+ },
21
+ forgetText (node) {
22
+ textOriginals.delete(node);
23
+ },
24
+ restoreAll () {
25
+ for (const [node, original] of textOriginals){
26
+ if (node.isConnected) node.textContent = original;
27
+ }
28
+ for (const [el, byAttr] of attrOriginals){
29
+ if (!el.isConnected) continue;
30
+ for (const [attr, value] of byAttr)el.setAttribute(attr, value);
31
+ }
32
+ }
33
+ };
34
+ }
35
+
36
+ //# sourceMappingURL=stegaBookkeeper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/client/overlay/stegaBookkeeper.ts"],"sourcesContent":["import { vercelStegaSplit } from \"@vercel/stega\";\n\n// Per-node bookkeeping. Maps (not arrays) prevent double-stripping — a second\n// pass of `vercelStegaSplit` over already-cleaned text returns an empty string,\n// which would silently blank real content. The text map also lets us tell our\n// own characterData mutations from React's updates: when React rewrites a node\n// we previously cleaned, `forgetText` drops the stale entry so the next scan\n// re-records the new original.\nexport interface StegaBookkeeper {\n /** Strips stega from `node` and records its original text. Returns true when newly recorded. */\n recordText(node: Text): boolean;\n /** Strips stega from `el[attr]` and records the original value. Returns true when newly recorded. */\n recordAttr(el: Element, attr: string, rawValue: string): boolean;\n /** Called when React rewrote a stega-bearing value on top of a node we already cleaned. */\n forgetText(node: Text): void;\n /** Restore original stega-bearing text/attrs on every still-connected node. */\n restoreAll(): void;\n}\n\nexport function createStegaBookkeeper(): StegaBookkeeper {\n const textOriginals = new Map<Text, string>();\n const attrOriginals = new Map<Element, Map<string, string>>();\n\n return {\n recordText(node) {\n if (textOriginals.has(node)) return false;\n const text = node.textContent ?? \"\";\n textOriginals.set(node, text);\n node.textContent = vercelStegaSplit(text).cleaned;\n return true;\n },\n recordAttr(el, attr, rawValue) {\n const byAttr = attrOriginals.get(el) ?? new Map<string, string>();\n if (byAttr.has(attr)) return false;\n byAttr.set(attr, rawValue);\n attrOriginals.set(el, byAttr);\n el.setAttribute(attr, vercelStegaSplit(rawValue).cleaned);\n return true;\n },\n forgetText(node) {\n textOriginals.delete(node);\n },\n restoreAll() {\n for (const [node, original] of textOriginals) {\n if (node.isConnected) node.textContent = original;\n }\n for (const [el, byAttr] of attrOriginals) {\n if (!el.isConnected) continue;\n for (const [attr, value] of byAttr) el.setAttribute(attr, value);\n }\n },\n };\n}\n"],"names":["vercelStegaSplit","createStegaBookkeeper","textOriginals","Map","attrOriginals","recordText","node","has","text","textContent","set","cleaned","recordAttr","el","attr","rawValue","byAttr","get","setAttribute","forgetText","delete","restoreAll","original","isConnected","value"],"mappings":"AAAA,SAASA,gBAAgB,QAAQ,gBAAgB;AAmBjD,OAAO,SAASC;IACd,MAAMC,gBAAgB,IAAIC;IAC1B,MAAMC,gBAAgB,IAAID;IAE1B,OAAO;QACLE,YAAWC,IAAI;YACb,IAAIJ,cAAcK,GAAG,CAACD,OAAO,OAAO;YACpC,MAAME,OAAOF,KAAKG,WAAW,IAAI;YACjCP,cAAcQ,GAAG,CAACJ,MAAME;YACxBF,KAAKG,WAAW,GAAGT,iBAAiBQ,MAAMG,OAAO;YACjD,OAAO;QACT;QACAC,YAAWC,EAAE,EAAEC,IAAI,EAAEC,QAAQ;YAC3B,MAAMC,SAASZ,cAAca,GAAG,CAACJ,OAAO,IAAIV;YAC5C,IAAIa,OAAOT,GAAG,CAACO,OAAO,OAAO;YAC7BE,OAAON,GAAG,CAACI,MAAMC;YACjBX,cAAcM,GAAG,CAACG,IAAIG;YACtBH,GAAGK,YAAY,CAACJ,MAAMd,iBAAiBe,UAAUJ,OAAO;YACxD,OAAO;QACT;QACAQ,YAAWb,IAAI;YACbJ,cAAckB,MAAM,CAACd;QACvB;QACAe;YACE,KAAK,MAAM,CAACf,MAAMgB,SAAS,IAAIpB,cAAe;gBAC5C,IAAII,KAAKiB,WAAW,EAAEjB,KAAKG,WAAW,GAAGa;YAC3C;YACA,KAAK,MAAM,CAACT,IAAIG,OAAO,IAAIZ,cAAe;gBACxC,IAAI,CAACS,GAAGU,WAAW,EAAE;gBACrB,KAAK,MAAM,CAACT,MAAMU,MAAM,IAAIR,OAAQH,GAAGK,YAAY,CAACJ,MAAMU;YAC5D;QACF;IACF;AACF"}
@@ -0,0 +1,11 @@
1
+ import type { VeIdentity } from "../../internal/shared.js";
2
+ export type TextMatch = VeIdentity & {
3
+ textNode: Text;
4
+ };
5
+ export type AttrMatch = {
6
+ el: Element;
7
+ attr: string;
8
+ value: string;
9
+ };
10
+ export declare function collectTextMatches(root: Element): TextMatch[];
11
+ export declare function collectAttrMatches(root: Element): AttrMatch[];
@@ -0,0 +1,54 @@
1
+ import { vercelStegaDecode } from "@vercel/stega";
2
+ import { fromStegaPayload } from "../../internal/shared.js";
3
+ import { STEGA_ATTRS, STEGA_PREFILTER } from "./constants.js";
4
+ // Tags whose text content is never user-facing and must not produce edit targets.
5
+ // `<script>` routinely contains stega via JSON.stringify output (JSON-LD, RSC streams);
6
+ // decoding those payloads drags real H1/H4 targets up to a common ancestor. `<style>`
7
+ // and `<noscript>` are skipped for the same reason — they aren't hoverable content.
8
+ const SKIP_TEXT_PARENT_TAGS = new Set([
9
+ "SCRIPT",
10
+ "STYLE",
11
+ "NOSCRIPT",
12
+ "TEMPLATE"
13
+ ]);
14
+ export function collectTextMatches(root) {
15
+ const matches = [];
16
+ const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT, {
17
+ acceptNode: (node)=>{
18
+ const parent = node.parentElement;
19
+ if (parent && SKIP_TEXT_PARENT_TAGS.has(parent.tagName)) return NodeFilter.FILTER_REJECT;
20
+ return NodeFilter.FILTER_ACCEPT;
21
+ }
22
+ });
23
+ for(let node = walker.nextNode(); node; node = walker.nextNode()){
24
+ const text = node.textContent ?? "";
25
+ if (!STEGA_PREFILTER.test(text)) continue;
26
+ const id = fromStegaPayload(vercelStegaDecode(text));
27
+ if (!id) continue;
28
+ matches.push({
29
+ textNode: node,
30
+ ...id
31
+ });
32
+ }
33
+ return matches;
34
+ }
35
+ export function collectAttrMatches(root) {
36
+ const result = [];
37
+ const walker = document.createTreeWalker(root, NodeFilter.SHOW_ELEMENT);
38
+ for(let el = walker.nextNode(); el; el = walker.nextNode()){
39
+ const element = el;
40
+ for (const attr of Array.from(element.attributes)){
41
+ if (!STEGA_ATTRS.has(attr.name)) continue;
42
+ if (STEGA_PREFILTER.test(attr.value)) {
43
+ result.push({
44
+ el: element,
45
+ attr: attr.name,
46
+ value: attr.value
47
+ });
48
+ }
49
+ }
50
+ }
51
+ return result;
52
+ }
53
+
54
+ //# sourceMappingURL=stegaScanner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/client/overlay/stegaScanner.ts"],"sourcesContent":["import type { VeIdentity } from \"../../internal/shared.js\";\n\nimport { vercelStegaDecode } from \"@vercel/stega\";\n\nimport { fromStegaPayload } from \"../../internal/shared.js\";\nimport { STEGA_ATTRS, STEGA_PREFILTER } from \"./constants.js\";\n\nexport type TextMatch = VeIdentity & { textNode: Text };\nexport type AttrMatch = { el: Element; attr: string; value: string };\n\n// Tags whose text content is never user-facing and must not produce edit targets.\n// `<script>` routinely contains stega via JSON.stringify output (JSON-LD, RSC streams);\n// decoding those payloads drags real H1/H4 targets up to a common ancestor. `<style>`\n// and `<noscript>` are skipped for the same reason — they aren't hoverable content.\nconst SKIP_TEXT_PARENT_TAGS = new Set([\"SCRIPT\", \"STYLE\", \"NOSCRIPT\", \"TEMPLATE\"]);\n\nexport function collectTextMatches(root: Element): TextMatch[] {\n const matches: TextMatch[] = [];\n const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT, {\n acceptNode: (node) => {\n const parent = node.parentElement;\n if (parent && SKIP_TEXT_PARENT_TAGS.has(parent.tagName)) return NodeFilter.FILTER_REJECT;\n return NodeFilter.FILTER_ACCEPT;\n },\n });\n for (let node = walker.nextNode(); node; node = walker.nextNode()) {\n const text = node.textContent ?? \"\";\n if (!STEGA_PREFILTER.test(text)) continue;\n const id = fromStegaPayload(vercelStegaDecode(text));\n if (!id) continue;\n matches.push({ textNode: node as Text, ...id });\n }\n return matches;\n}\n\nexport function collectAttrMatches(root: Element): AttrMatch[] {\n const result: AttrMatch[] = [];\n const walker = document.createTreeWalker(root, NodeFilter.SHOW_ELEMENT);\n for (let el = walker.nextNode(); el; el = walker.nextNode()) {\n const element = el as Element;\n for (const attr of Array.from(element.attributes)) {\n if (!STEGA_ATTRS.has(attr.name)) continue;\n if (STEGA_PREFILTER.test(attr.value)) {\n result.push({ el: element, attr: attr.name, value: attr.value });\n }\n }\n }\n return result;\n}\n"],"names":["vercelStegaDecode","fromStegaPayload","STEGA_ATTRS","STEGA_PREFILTER","SKIP_TEXT_PARENT_TAGS","Set","collectTextMatches","root","matches","walker","document","createTreeWalker","NodeFilter","SHOW_TEXT","acceptNode","node","parent","parentElement","has","tagName","FILTER_REJECT","FILTER_ACCEPT","nextNode","text","textContent","test","id","push","textNode","collectAttrMatches","result","SHOW_ELEMENT","el","element","attr","Array","from","attributes","name","value"],"mappings":"AAEA,SAASA,iBAAiB,QAAQ,gBAAgB;AAElD,SAASC,gBAAgB,QAAQ,2BAA2B;AAC5D,SAASC,WAAW,EAAEC,eAAe,QAAQ,iBAAiB;AAK9D,kFAAkF;AAClF,wFAAwF;AACxF,sFAAsF;AACtF,oFAAoF;AACpF,MAAM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