@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 @@
1
+ {"version":3,"sources":["../../src/admin/resolveContainerChain.ts"],"sourcesContent":["// Resolves a data path (e.g. `translation.forms.privacyPolicy` or `layout.2.heading`)\n// against the raw Payload fields config into an ordered chain of DOM operations\n// needed to make the target field visible before focus.\n//\n// Three instruction kinds — see `executor` in expandAndFocus.ts:\n// - tab → click the tabs-field button at `tabIndex` (scope narrowed by\n// earlier row/collapsible instructions)\n// - collapsible → click the toggle inside `#field-collapsible-<path__>`\n// - row → click the toggle inside `#<rowContainerId>`\n//\n// Collapsible DOM ids use Payload's `path` (see `getFieldPaths.js`), which is\n// the data-shape path with `_index-<N-M-...>` segments for unnamed ancestors.\n// Unnamed containers inside other unnamed containers *accumulate* indices with\n// hyphens, e.g. an unnamed group at index 0 containing a collapsible at index\n// 12 becomes `_index-0-12`, not `_index-0._index-12`. We track this via the\n// `indexStack`, which resets at every named descent and extends at every\n// unnamed descent.\n\nexport type ResolverField = {\n type: string;\n name?: string;\n fields?: ResolverField[];\n tabs?: ResolverTab[];\n blocks?: ResolverBlock[];\n};\n\nexport type ResolverTab = {\n name?: string;\n fields: ResolverField[];\n};\n\nexport type ResolverBlock = {\n slug?: string;\n fields: ResolverField[];\n};\n\nexport type ContainerInstruction =\n | { kind: \"tab\"; tabIndex: number }\n | { kind: \"collapsible\"; path: string }\n | { kind: \"row\"; rowContainerId: string };\n\nexport type ResolvedPath = {\n chain: ContainerInstruction[];\n fieldId: string | null;\n};\n\nexport const resolveContainerChain = (\n path: string,\n fields: readonly ResolverField[]\n): ResolvedPath | null => {\n if (!path) return null;\n const segments = path.split(\".\");\n const chain = walkFields(fields, segments, 0, \"\", []);\n if (chain === null) return null;\n\n const last = segments[segments.length - 1]!;\n const fieldId = /^\\d+$/.test(last) ? null : `field-${path.replace(/\\./g, \"__\")}`;\n return { chain, fieldId };\n};\n\n// `dataPath` is the path up to the current named ancestor (drops all `_index`).\n// `indexStack` accumulates positions inside unnamed ancestors since the last\n// named descent — matches Payload's `parentIndexPath` + trailing `index`.\nconst walkFields = (\n fields: readonly ResolverField[],\n segments: readonly string[],\n segIndex: number,\n dataPath: string,\n indexStack: readonly number[]\n): ContainerInstruction[] | null => {\n if (segIndex >= segments.length) return [];\n const segment = segments[segIndex]!;\n\n for (let i = 0; i < fields.length; i++) {\n const field = fields[i]!;\n const result = descendInto(field, i, segment, segments, segIndex, dataPath, indexStack);\n if (result !== null) return result;\n }\n return null;\n};\n\n// Payload's path for an unnamed container: `<named-ancestor-path>._index-<idx-stack>`.\nconst unnamedPath = (dataPath: string, indexStack: readonly number[], index: number): string => {\n const suffix = `_index-${[...indexStack, index].join(\"-\")}`;\n return dataPath ? `${dataPath}.${suffix}` : suffix;\n};\n\nconst descendInto = (\n field: ResolverField,\n i: number,\n segment: string,\n segments: readonly string[],\n segIndex: number,\n dataPath: string,\n indexStack: readonly number[]\n): ContainerInstruction[] | null => {\n switch (field.type) {\n case \"row\": {\n if (!field.fields) return null;\n // Transparent. Extend indexStack so nested collapsible paths stay aligned with Payload.\n return walkFields(field.fields, segments, segIndex, dataPath, [...indexStack, i]);\n }\n case \"collapsible\": {\n if (!field.fields) return null;\n const sub = walkFields(field.fields, segments, segIndex, dataPath, [...indexStack, i]);\n if (sub === null) return null;\n return [{ kind: \"collapsible\", path: unnamedPath(dataPath, indexStack, i) }, ...sub];\n }\n case \"tabs\": {\n if (!field.tabs) return null;\n // The tabs field itself occupies an index slot among its siblings. If the\n // match lives inside an unnamed tab, that tab's index also extends the\n // stack. Named tabs reset everything.\n for (let t = 0; t < field.tabs.length; t++) {\n const tab = field.tabs[t]!;\n let advance: number;\n let nextDataPath: string;\n let nextIndexStack: readonly number[];\n if (tab.name) {\n if (tab.name !== segment) continue;\n advance = 1;\n nextDataPath = dataPath ? `${dataPath}.${tab.name}` : tab.name;\n nextIndexStack = [];\n } else {\n advance = 0;\n nextDataPath = dataPath;\n nextIndexStack = [...indexStack, i, t];\n }\n const sub = walkFields(\n tab.fields,\n segments,\n segIndex + advance,\n nextDataPath,\n nextIndexStack\n );\n if (sub === null) continue;\n return [{ kind: \"tab\", tabIndex: t }, ...sub];\n }\n return null;\n }\n case \"group\": {\n if (!field.fields) return null;\n if (!field.name) {\n return walkFields(field.fields, segments, segIndex, dataPath, [...indexStack, i]);\n }\n if (field.name !== segment) return null;\n const nextData = dataPath ? `${dataPath}.${field.name}` : field.name;\n return walkFields(field.fields, segments, segIndex + 1, nextData, []);\n }\n case \"array\":\n case \"blocks\": {\n if (field.name !== segment) return null;\n const nextData = dataPath ? `${dataPath}.${field.name}` : field.name;\n\n if (segIndex + 1 >= segments.length) return [];\n const rawIndex = segments[segIndex + 1]!;\n if (!/^\\d+$/.test(rawIndex)) return null;\n\n const rowContainerId = `${nextData.replace(/\\./g, \"-\")}-row-${rawIndex}`;\n const rowInstruction: ContainerInstruction = { kind: \"row\", rowContainerId };\n const descendedData = `${nextData}.${rawIndex}`;\n\n if (segIndex + 2 >= segments.length) return [rowInstruction];\n\n if (field.type === \"array\") {\n if (!field.fields) return null;\n const sub = walkFields(field.fields, segments, segIndex + 2, descendedData, []);\n return sub === null ? null : [rowInstruction, ...sub];\n }\n if (!field.blocks) return null;\n for (const block of field.blocks) {\n const sub = walkFields(block.fields, segments, segIndex + 2, descendedData, []);\n if (sub !== null) return [rowInstruction, ...sub];\n }\n return null;\n }\n default: {\n if (field.name === segment && segIndex === segments.length - 1) return [];\n return null;\n }\n }\n};\n"],"names":["resolveContainerChain","path","fields","segments","split","chain","walkFields","last","length","fieldId","test","replace","segIndex","dataPath","indexStack","segment","i","field","result","descendInto","unnamedPath","index","suffix","join","type","sub","kind","tabs","t","tab","advance","nextDataPath","nextIndexStack","name","tabIndex","nextData","rawIndex","rowContainerId","rowInstruction","descendedData","blocks","block"],"mappings":"AAAA,sFAAsF;AACtF,gFAAgF;AAChF,wDAAwD;AACxD,EAAE;AACF,iEAAiE;AACjE,iFAAiF;AACjF,0DAA0D;AAC1D,0EAA0E;AAC1E,gEAAgE;AAChE,EAAE;AACF,8EAA8E;AAC9E,8EAA8E;AAC9E,+EAA+E;AAC/E,8EAA8E;AAC9E,4EAA4E;AAC5E,yEAAyE;AACzE,mBAAmB;AA8BnB,OAAO,MAAMA,wBAAwB,CACnCC,MACAC;IAEA,IAAI,CAACD,MAAM,OAAO;IAClB,MAAME,WAAWF,KAAKG,KAAK,CAAC;IAC5B,MAAMC,QAAQC,WAAWJ,QAAQC,UAAU,GAAG,IAAI,EAAE;IACpD,IAAIE,UAAU,MAAM,OAAO;IAE3B,MAAME,OAAOJ,QAAQ,CAACA,SAASK,MAAM,GAAG,EAAE;IAC1C,MAAMC,UAAU,QAAQC,IAAI,CAACH,QAAQ,OAAO,CAAC,MAAM,EAAEN,KAAKU,OAAO,CAAC,OAAO,MAAM,CAAC;IAChF,OAAO;QAAEN;QAAOI;IAAQ;AAC1B,EAAE;AAEF,gFAAgF;AAChF,6EAA6E;AAC7E,0EAA0E;AAC1E,MAAMH,aAAa,CACjBJ,QACAC,UACAS,UACAC,UACAC;IAEA,IAAIF,YAAYT,SAASK,MAAM,EAAE,OAAO,EAAE;IAC1C,MAAMO,UAAUZ,QAAQ,CAACS,SAAS;IAElC,IAAK,IAAII,IAAI,GAAGA,IAAId,OAAOM,MAAM,EAAEQ,IAAK;QACtC,MAAMC,QAAQf,MAAM,CAACc,EAAE;QACvB,MAAME,SAASC,YAAYF,OAAOD,GAAGD,SAASZ,UAAUS,UAAUC,UAAUC;QAC5E,IAAII,WAAW,MAAM,O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,KAAK,EAAEyB,SAAS,CAAC;gBACxE,MAAME,iBAAuC;oBAAEZ,MAAM;oBAAOW;gBAAe;gBAC3E,MAAME,gBAAgB,CAAC,EAAEJ,SAAS,CAAC,EAAEC,SAAS,CAAC;gBAE/C,IAAIxB,WAAW,KAAKT,SAASK,MAAM,EAAE,OAAO;oBAAC8B;iBAAe;gBAE5D,IAAIrB,MAAMO,IAAI,KAAK,SAAS;oBAC1B,IAAI,CAACP,MAAMf,MAAM,EAAE,OAAO;oBAC1B,MAAMuB,MAAMnB,WAAWW,MAAMf,MAAM,EAAEC,UAAUS,WAAW,GAAG2B,eAAe,EAAE;oBAC9E,OAAOd,QAAQ,OAAO,OAAO;wBAACa;2BAAmBb;qBAAI;gBACvD;gBACA,IAAI,CAACR,MAAMuB,MAAM,EAAE,OAAO;gBAC1B,KAAK,MAAMC,SAASxB,MAAMuB,MAAM,CAAE;oBAChC,MAAMf,MAAMnB,WAAWmC,MAAMvC,MAAM,EAAEC,UAAUS,WAAW,GAAG2B,eAAe,EAAE;oBAC9E,IAAId,QAAQ,MAAM,OAAO;wBAACa;2BAAmBb;qBAAI;gBACnD;gBACA,OAAO;YACT;QACA;YAAS;gBACP,IAAIR,MAAMgB,IAAI,KAAKlB,WAAWH,aAAaT,SAASK,MAAM,GAAG,GAAG,OAAO,EAAE;gBACzE,OAAO;YACT;IACF;AACF"}
@@ -0,0 +1,4 @@
1
+ export declare function VisualEditingOverlay({ locale, children, }: {
2
+ locale?: string;
3
+ children: React.ReactNode;
4
+ }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,30 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { useRef } from "react";
4
+ import { useVisualEditingOverlay } from "./useVisualEditingOverlay.js";
5
+ import { useVisualEditing } from "./VisualEditingProvider.js";
6
+ export function VisualEditingOverlay({ locale, children }) {
7
+ const { enabled, mode, buildAdminEditUrl, adminOrigin, adminBasePath } = useVisualEditing();
8
+ const rootRef = useRef(null);
9
+ // The overlay is never mounted in 'off' mode (enabled === false), so 'always'|'hover' is safe here.
10
+ useVisualEditingOverlay(enabled, rootRef, {
11
+ buildAdminEditUrl,
12
+ adminOrigin,
13
+ adminBasePath,
14
+ locale,
15
+ mode: mode === "off" ? "hover" : mode
16
+ });
17
+ // `display: contents` keeps the wrapper in the DOM tree (so the overlay has a
18
+ // scan root that matches exactly what the caller chose to wrap) without
19
+ // introducing a layout/BFC boundary that could alter the child flow.
20
+ return /*#__PURE__*/ _jsx("div", {
21
+ ref: rootRef,
22
+ "data-ve-root": "",
23
+ style: {
24
+ display: "contents"
25
+ },
26
+ children: children
27
+ });
28
+ }
29
+
30
+ //# sourceMappingURL=VisualEditingOverlay.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/client/VisualEditingOverlay.tsx"],"sourcesContent":["\"use client\";\n\nimport { useRef } from \"react\";\n\nimport { useVisualEditingOverlay } from \"./useVisualEditingOverlay.js\";\nimport { useVisualEditing } from \"./VisualEditingProvider.js\";\n\nexport function VisualEditingOverlay({\n locale,\n children,\n}: {\n locale?: string;\n children: React.ReactNode;\n}) {\n const { enabled, mode, buildAdminEditUrl, adminOrigin, adminBasePath } = useVisualEditing();\n const rootRef = useRef<HTMLDivElement | null>(null);\n // The overlay is never mounted in 'off' mode (enabled === false), so 'always'|'hover' is safe here.\n useVisualEditingOverlay(enabled, rootRef, {\n buildAdminEditUrl,\n adminOrigin,\n adminBasePath,\n locale,\n mode: mode === \"off\" ? \"hover\" : mode,\n });\n // `display: contents` keeps the wrapper in the DOM tree (so the overlay has a\n // scan root that matches exactly what the caller chose to wrap) without\n // introducing a layout/BFC boundary that could alter the child flow.\n return (\n <div ref={rootRef} data-ve-root=\"\" style={{ display: \"contents\" }}>\n {children}\n </div>\n );\n}\n"],"names":["useRef","useVisualEditingOverlay","useVisualEditing","VisualEditingOverlay","locale","children","enabled","mode","buildAdminEditUrl","adminOrigin","adminBasePath","rootRef","div","ref","data-ve-root","style","display"],"mappings":"AAAA;;AAEA,SAASA,MAAM,QAAQ,QAAQ;AAE/B,SAASC,uBAAuB,QAAQ,+BAA+B;AACvE,SAASC,gBAAgB,QAAQ,6BAA6B;AAE9D,OAAO,SAASC,qBAAqB,EACnCC,MAAM,EACNC,QAAQ,EAIT;IACC,MAAM,EAAEC,OAAO,EAAEC,IAAI,EAAEC,iBAAiB,EAAEC,WAAW,EAAEC,aAAa,EAAE,GAAGR;IACzE,MAAMS,UAAUX,OAA8B;IAC9C,oGAAoG;IACpGC,wBAAwBK,SAASK,SAAS;QACxCH;QACAC;QACAC;QACAN;QACAG,MAAMA,SAAS,QAAQ,UAAUA;IACnC;IACA,8EAA8E;IAC9E,wEAAwE;IACxE,qEAAqE;IACrE,qBACE,KAACK;QAAIC,KAAKF;QAASG,gBAAa;QAAGC,OAAO;YAAEC,SAAS;QAAW;kBAC7DX;;AAGP"}
@@ -0,0 +1,23 @@
1
+ import type { VisualEditingMode } from "../constants.js";
2
+ import type { BuildAdminEditUrl } from "./buildAdminEditUrl.js";
3
+ type VisualEditingContextType = {
4
+ available: boolean;
5
+ enabled: boolean;
6
+ mode: VisualEditingMode;
7
+ setMode: (mode: VisualEditingMode) => void;
8
+ toggleEnabled: () => void;
9
+ buildAdminEditUrl: BuildAdminEditUrl;
10
+ adminOrigin: string;
11
+ adminBasePath: string;
12
+ };
13
+ export declare function VisualEditingProvider({ available: availableProp, framedOnly, buildAdminEditUrl, adminOrigin, adminBasePath, children, }: {
14
+ available?: boolean;
15
+ /** Restrict the overlay to the CMS preview iframe — hidden when opened in a standalone tab. */
16
+ framedOnly?: boolean;
17
+ buildAdminEditUrl?: BuildAdminEditUrl;
18
+ adminOrigin?: string;
19
+ adminBasePath?: string;
20
+ children: React.ReactNode;
21
+ }): import("react/jsx-runtime").JSX.Element;
22
+ export declare const useVisualEditing: () => VisualEditingContextType;
23
+ export {};
@@ -0,0 +1,68 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { createContext, useContext, useEffect, useMemo, useState } from "react";
4
+ import { STORAGE_KEY } from "../constants.js";
5
+ import { defaultBuildAdminEditUrl } from "./buildAdminEditUrl.js";
6
+ const noop = ()=>undefined;
7
+ const VisualEditingContext = /*#__PURE__*/ createContext({
8
+ available: false,
9
+ enabled: false,
10
+ mode: "off",
11
+ setMode: noop,
12
+ toggleEnabled: noop,
13
+ buildAdminEditUrl: defaultBuildAdminEditUrl,
14
+ adminOrigin: "",
15
+ adminBasePath: "/admin"
16
+ });
17
+ // Pre-3-state builds persisted `'true'` / `'false'` — promote them so existing
18
+ // users keep their enabled state across this change.
19
+ function readStoredMode() {
20
+ const raw = localStorage.getItem(STORAGE_KEY);
21
+ if (raw === "always" || raw === "hover" || raw === "off") return raw;
22
+ if (raw === "true") return "always";
23
+ return "off";
24
+ }
25
+ export function VisualEditingProvider({ available: availableProp = false, framedOnly = false, buildAdminEditUrl = defaultBuildAdminEditUrl, adminOrigin, adminBasePath = "/admin", children }) {
26
+ const [mode, setModeState] = useState("off");
27
+ const [resolvedOrigin, setResolvedOrigin] = useState(adminOrigin ?? "");
28
+ // The CMS side preview renders us in an iframe; a separate tab is top-level.
29
+ const [isFramed, setIsFramed] = useState(false);
30
+ useEffect(()=>{
31
+ setModeState(readStoredMode());
32
+ setIsFramed(window.self !== window.top);
33
+ if (!adminOrigin) setResolvedOrigin(window.location.origin);
34
+ }, [
35
+ adminOrigin
36
+ ]);
37
+ const setMode = (next)=>{
38
+ setModeState(next);
39
+ localStorage.setItem(STORAGE_KEY, next);
40
+ };
41
+ const toggleEnabled = ()=>setMode(mode === "off" ? "always" : "off");
42
+ const available = availableProp && (!framedOnly || isFramed);
43
+ const enabled = available && mode !== "off";
44
+ const value = useMemo(()=>({
45
+ available,
46
+ enabled,
47
+ mode,
48
+ setMode,
49
+ toggleEnabled,
50
+ buildAdminEditUrl,
51
+ adminOrigin: resolvedOrigin,
52
+ adminBasePath
53
+ }), [
54
+ available,
55
+ enabled,
56
+ mode,
57
+ buildAdminEditUrl,
58
+ resolvedOrigin,
59
+ adminBasePath
60
+ ]);
61
+ return /*#__PURE__*/ _jsx(VisualEditingContext.Provider, {
62
+ value: value,
63
+ children: children
64
+ });
65
+ }
66
+ export const useVisualEditing = ()=>useContext(VisualEditingContext);
67
+
68
+ //# sourceMappingURL=VisualEditingProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/client/VisualEditingProvider.tsx"],"sourcesContent":["\"use client\";\n\nimport { createContext, useContext, useEffect, useMemo, useState } from \"react\";\n\nimport { STORAGE_KEY } from \"../constants.js\";\nimport type { VisualEditingMode } from \"../constants.js\";\nimport { defaultBuildAdminEditUrl } from \"./buildAdminEditUrl.js\";\nimport type { BuildAdminEditUrl } from \"./buildAdminEditUrl.js\";\n\ntype VisualEditingContextType = {\n available: boolean;\n enabled: boolean;\n mode: VisualEditingMode;\n setMode: (mode: VisualEditingMode) => void;\n toggleEnabled: () => void;\n buildAdminEditUrl: BuildAdminEditUrl;\n adminOrigin: string;\n adminBasePath: string;\n};\n\nconst noop = (): void => undefined;\n\nconst VisualEditingContext = createContext<VisualEditingContextType>({\n available: false,\n enabled: false,\n mode: \"off\",\n setMode: noop,\n toggleEnabled: noop,\n buildAdminEditUrl: defaultBuildAdminEditUrl,\n adminOrigin: \"\",\n adminBasePath: \"/admin\",\n});\n\n// Pre-3-state builds persisted `'true'` / `'false'` — promote them so existing\n// users keep their enabled state across this change.\nfunction readStoredMode(): VisualEditingMode {\n const raw = localStorage.getItem(STORAGE_KEY);\n if (raw === \"always\" || raw === \"hover\" || raw === \"off\") return raw;\n if (raw === \"true\") return \"always\";\n return \"off\";\n}\n\nexport function VisualEditingProvider({\n available: availableProp = false,\n framedOnly = false,\n buildAdminEditUrl = defaultBuildAdminEditUrl,\n adminOrigin,\n adminBasePath = \"/admin\",\n children,\n}: {\n available?: boolean;\n /** Restrict the overlay to the CMS preview iframe — hidden when opened in a standalone tab. */\n framedOnly?: boolean;\n buildAdminEditUrl?: BuildAdminEditUrl;\n adminOrigin?: string;\n adminBasePath?: string;\n children: React.ReactNode;\n}) {\n const [mode, setModeState] = useState<VisualEditingMode>(\"off\");\n const [resolvedOrigin, setResolvedOrigin] = useState(adminOrigin ?? \"\");\n // The CMS side preview renders us in an iframe; a separate tab is top-level.\n const [isFramed, setIsFramed] = useState(false);\n\n useEffect(() => {\n setModeState(readStoredMode());\n setIsFramed(window.self !== window.top);\n if (!adminOrigin) setResolvedOrigin(window.location.origin);\n }, [adminOrigin]);\n\n const setMode = (next: VisualEditingMode) => {\n setModeState(next);\n localStorage.setItem(STORAGE_KEY, next);\n };\n\n const toggleEnabled = () => setMode(mode === \"off\" ? \"always\" : \"off\");\n\n const available = availableProp && (!framedOnly || isFramed);\n const enabled = available && mode !== \"off\";\n\n const value = useMemo(\n () => ({\n available,\n enabled,\n mode,\n setMode,\n toggleEnabled,\n buildAdminEditUrl,\n adminOrigin: resolvedOrigin,\n adminBasePath,\n }),\n [available, enabled, mode, buildAdminEditUrl, resolvedOrigin, adminBasePath]\n );\n\n return <VisualEditingContext.Provider value={value}>{children}</VisualEditingContext.Provider>;\n}\n\nexport const useVisualEditing = () => useContext(VisualEditingContext);\n"],"names":["createContext","useContext","useEffect","useMemo","useState","STORAGE_KEY","defaultBuildAdminEditUrl","noop","undefined","VisualEditingContext","available","enabled","mode","setMode","toggleEnabled","buildAdminEditUrl","adminOrigin","adminBasePath","readStoredMode","raw","localStorage","getItem","VisualEditingProvider","availableProp","framedOnly","children","setModeState","resolvedOrigin","setResolvedOrigin","isFramed","setIsFramed","window","self","top","location","origin","next","setItem","value","Provider","useVisualEditing"],"mappings":"AAAA;;AAEA,SAASA,aAAa,EAAEC,UAAU,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAQ;AAEhF,SAASC,WAAW,QAAQ,kBAAkB;AAE9C,SAASC,wBAAwB,QAAQ,yBAAyB;AAclE,MAAMC,OAAO,IAAYC;AAEzB,MAAMC,qCAAuBT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Q;QAACD,OAAOA;kBAAQb;;AACvD;AAEA,OAAO,MAAMe,mBAAmB,IAAMvC,WAAWQ,sBAAsB"}
@@ -0,0 +1 @@
1
+ export declare function VisualEditingToggle(): React.ReactElement | null;
@@ -0,0 +1,163 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useEffect, useState } from "react";
4
+ import { createPortal } from "react-dom";
5
+ import { VISUAL_EDITING_MODES } from "../constants.js";
6
+ import { useVisualEditing } from "./VisualEditingProvider.js";
7
+ // Pseudo-classes (:hover, :focus-visible) can't live on React style objects,
8
+ // so the rules are injected once into <head> under a dedicated id. The
9
+ // component reuses its own marker attribute to scope them without polluting
10
+ // global selectors.
11
+ const STYLE_ID = "ve-toggle-styles";
12
+ // `body[data-ve-hovering='true']` is set by the overlay's hoverController
13
+ // whenever an Edit badge is painted on a target. The badge sits at the target's
14
+ // top-right (see `editBadge.ts` LABEL_STYLES), so for targets near the page
15
+ // bottom it overlaps this toggle. Fading the toggle out during hover + a short
16
+ // grace period on clearing activeTarget (CLEAR_GRACE_MS in hoverController)
17
+ // keeps the toggle out of the way while the user navigates target → label.
18
+ const SCOPED_STYLES = `
19
+ [data-ve-toggle-root] {
20
+ transition: opacity 140ms ease, transform 140ms ease;
21
+ }
22
+ body[data-ve-hovering='true'] [data-ve-toggle-root] {
23
+ opacity: 0;
24
+ transform: translateY(8px);
25
+ pointer-events: none;
26
+ }
27
+ [data-ve-toggle-btn][data-ve-active="false"]:hover {
28
+ background: rgba(255, 255, 255, 0.06);
29
+ color: rgba(255, 255, 255, 0.92);
30
+ }
31
+ [data-ve-toggle-btn]:focus-visible {
32
+ outline: 2px solid #34d399;
33
+ outline-offset: 2px;
34
+ }
35
+ `;
36
+ const MODE_LABELS = {
37
+ off: "Off",
38
+ always: "Always",
39
+ hover: "Hover"
40
+ };
41
+ const MODE_DESCRIPTIONS = {
42
+ off: "Disable visual editing",
43
+ always: "Always show edit outlines",
44
+ hover: "Show edit outline on hover only"
45
+ };
46
+ const CONTAINER_STYLE = {
47
+ position: "fixed",
48
+ right: "20px",
49
+ bottom: "20px",
50
+ zIndex: 2147483646,
51
+ display: "inline-flex",
52
+ alignItems: "center",
53
+ gap: "2px",
54
+ padding: "4px",
55
+ background: "rgba(18, 18, 18, 0.92)",
56
+ backdropFilter: "blur(12px) saturate(140%)",
57
+ WebkitBackdropFilter: "blur(12px) saturate(140%)",
58
+ border: "1px solid rgba(255, 255, 255, 0.08)",
59
+ borderRadius: "10px",
60
+ boxShadow: "0 12px 32px -8px rgba(0, 0, 0, 0.4), 0 4px 12px -2px rgba(0, 0, 0, 0.24), inset 0 1px 0 rgba(255, 255, 255, 0.05)",
61
+ fontFamily: 'system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif',
62
+ pointerEvents: "auto"
63
+ };
64
+ const BRAND_STYLE = {
65
+ display: "inline-flex",
66
+ alignItems: "center",
67
+ justifyContent: "center",
68
+ width: "26px",
69
+ height: "26px",
70
+ color: "rgba(52, 211, 153, 0.85)",
71
+ pointerEvents: "none"
72
+ };
73
+ const BUTTON_BASE = {
74
+ appearance: "none",
75
+ border: 0,
76
+ margin: 0,
77
+ padding: "6px 11px",
78
+ fontSize: "11px",
79
+ fontFamily: "inherit",
80
+ fontWeight: 600,
81
+ letterSpacing: "0.06em",
82
+ textTransform: "uppercase",
83
+ borderRadius: "6px",
84
+ cursor: "pointer",
85
+ background: "transparent",
86
+ color: "rgba(255, 255, 255, 0.55)",
87
+ transition: "background-color 160ms ease, color 160ms ease",
88
+ lineHeight: 1,
89
+ WebkitTapHighlightColor: "transparent"
90
+ };
91
+ const ACTIVE_BUTTON = {
92
+ background: "#34d399",
93
+ color: "#022c22",
94
+ boxShadow: "0 1px 2px rgba(0, 0, 0, 0.24)"
95
+ };
96
+ function ensureStylesInjected() {
97
+ // oxlint-disable-next-line unicorn/prefer-query-selector -- ids are not guaranteed to be valid CSS selectors
98
+ if (document.getElementById(STYLE_ID)) return;
99
+ const style = document.createElement("style");
100
+ style.id = STYLE_ID;
101
+ style.textContent = SCOPED_STYLES;
102
+ document.head.append(style);
103
+ }
104
+ export function VisualEditingToggle() {
105
+ const { available, mode, setMode } = useVisualEditing();
106
+ const [mounted, setMounted] = useState(false);
107
+ useEffect(()=>{
108
+ setMounted(true);
109
+ ensureStylesInjected();
110
+ }, []);
111
+ if (!mounted || !available) return null;
112
+ const control = /*#__PURE__*/ _jsxs("div", {
113
+ role: "radiogroup",
114
+ "aria-label": "Visual editing mode",
115
+ "data-ve-toggle-root": "",
116
+ style: CONTAINER_STYLE,
117
+ children: [
118
+ /*#__PURE__*/ _jsx("span", {
119
+ "aria-hidden": "true",
120
+ style: BRAND_STYLE,
121
+ children: /*#__PURE__*/ _jsxs("svg", {
122
+ width: "14",
123
+ height: "14",
124
+ viewBox: "0 0 16 16",
125
+ fill: "none",
126
+ stroke: "currentColor",
127
+ strokeWidth: "1.6",
128
+ strokeLinecap: "round",
129
+ strokeLinejoin: "round",
130
+ children: [
131
+ /*#__PURE__*/ _jsx("path", {
132
+ d: "M11.2 2.2l2.6 2.6-8.5 8.5L1.5 14l.7-3.8z"
133
+ }),
134
+ /*#__PURE__*/ _jsx("path", {
135
+ d: "M10 3.4l2.6 2.6"
136
+ })
137
+ ]
138
+ })
139
+ }),
140
+ VISUAL_EDITING_MODES.map((m)=>{
141
+ const active = m === mode;
142
+ return /*#__PURE__*/ _jsx("button", {
143
+ type: "button",
144
+ role: "radio",
145
+ "aria-checked": active,
146
+ "aria-label": MODE_DESCRIPTIONS[m],
147
+ title: MODE_DESCRIPTIONS[m],
148
+ "data-ve-toggle-btn": "",
149
+ "data-ve-active": String(active),
150
+ onClick: ()=>setMode(m),
151
+ style: active ? {
152
+ ...BUTTON_BASE,
153
+ ...ACTIVE_BUTTON
154
+ } : BUTTON_BASE,
155
+ children: MODE_LABELS[m]
156
+ }, m);
157
+ })
158
+ ]
159
+ });
160
+ return /*#__PURE__*/ createPortal(control, document.body);
161
+ }
162
+
163
+ //# sourceMappingURL=VisualEditingToggle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/client/VisualEditingToggle.tsx"],"sourcesContent":["\"use client\";\n\nimport { useEffect, useState } from \"react\";\nimport { createPortal } from \"react-dom\";\n\nimport type { VisualEditingMode } from \"../constants.js\";\n\nimport { VISUAL_EDITING_MODES } from \"../constants.js\";\nimport { useVisualEditing } from \"./VisualEditingProvider.js\";\n\n// Pseudo-classes (:hover, :focus-visible) can't live on React style objects,\n// so the rules are injected once into <head> under a dedicated id. The\n// component reuses its own marker attribute to scope them without polluting\n// global selectors.\nconst STYLE_ID = \"ve-toggle-styles\";\n\n// `body[data-ve-hovering='true']` is set by the overlay's hoverController\n// whenever an Edit badge is painted on a target. The badge sits at the target's\n// top-right (see `editBadge.ts` LABEL_STYLES), so for targets near the page\n// bottom it overlaps this toggle. Fading the toggle out during hover + a short\n// grace period on clearing activeTarget (CLEAR_GRACE_MS in hoverController)\n// keeps the toggle out of the way while the user navigates target → label.\nconst SCOPED_STYLES = `\n[data-ve-toggle-root] {\n\ttransition: opacity 140ms ease, transform 140ms ease;\n}\nbody[data-ve-hovering='true'] [data-ve-toggle-root] {\n\topacity: 0;\n\ttransform: translateY(8px);\n\tpointer-events: none;\n}\n[data-ve-toggle-btn][data-ve-active=\"false\"]:hover {\n\tbackground: rgba(255, 255, 255, 0.06);\n\tcolor: rgba(255, 255, 255, 0.92);\n}\n[data-ve-toggle-btn]:focus-visible {\n\toutline: 2px solid #34d399;\n\toutline-offset: 2px;\n}\n`;\n\nconst MODE_LABELS: Record<VisualEditingMode, string> = {\n off: \"Off\",\n always: \"Always\",\n hover: \"Hover\",\n};\n\nconst MODE_DESCRIPTIONS: Record<VisualEditingMode, string> = {\n off: \"Disable visual editing\",\n always: \"Always show edit outlines\",\n hover: \"Show edit outline on hover only\",\n};\n\nconst CONTAINER_STYLE: React.CSSProperties = {\n position: \"fixed\",\n right: \"20px\",\n bottom: \"20px\",\n zIndex: 2147483646,\n display: \"inline-flex\",\n alignItems: \"center\",\n gap: \"2px\",\n padding: \"4px\",\n background: \"rgba(18, 18, 18, 0.92)\",\n backdropFilter: \"blur(12px) saturate(140%)\",\n WebkitBackdropFilter: \"blur(12px) saturate(140%)\",\n border: \"1px solid rgba(255, 255, 255, 0.08)\",\n borderRadius: \"10px\",\n boxShadow:\n \"0 12px 32px -8px rgba(0, 0, 0, 0.4), 0 4px 12px -2px rgba(0, 0, 0, 0.24), inset 0 1px 0 rgba(255, 255, 255, 0.05)\",\n fontFamily: 'system-ui, -apple-system, \"Segoe UI\", Roboto, \"Helvetica Neue\", Arial, sans-serif',\n pointerEvents: \"auto\",\n};\n\nconst BRAND_STYLE: React.CSSProperties = {\n display: \"inline-flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n width: \"26px\",\n height: \"26px\",\n color: \"rgba(52, 211, 153, 0.85)\",\n pointerEvents: \"none\",\n};\n\nconst BUTTON_BASE: React.CSSProperties = {\n appearance: \"none\",\n border: 0,\n margin: 0,\n padding: \"6px 11px\",\n fontSize: \"11px\",\n fontFamily: \"inherit\",\n fontWeight: 600,\n letterSpacing: \"0.06em\",\n textTransform: \"uppercase\",\n borderRadius: \"6px\",\n cursor: \"pointer\",\n background: \"transparent\",\n color: \"rgba(255, 255, 255, 0.55)\",\n transition: \"background-color 160ms ease, color 160ms ease\",\n lineHeight: 1,\n WebkitTapHighlightColor: \"transparent\",\n};\n\nconst ACTIVE_BUTTON: React.CSSProperties = {\n background: \"#34d399\",\n color: \"#022c22\",\n boxShadow: \"0 1px 2px rgba(0, 0, 0, 0.24)\",\n};\n\nfunction ensureStylesInjected(): void {\n // oxlint-disable-next-line unicorn/prefer-query-selector -- ids are not guaranteed to be valid CSS selectors\n if (document.getElementById(STYLE_ID)) return;\n const style = document.createElement(\"style\");\n style.id = STYLE_ID;\n style.textContent = SCOPED_STYLES;\n document.head.append(style);\n}\n\nexport function VisualEditingToggle(): React.ReactElement | null {\n const { available, mode, setMode } = useVisualEditing();\n const [mounted, setMounted] = useState(false);\n\n useEffect(() => {\n setMounted(true);\n ensureStylesInjected();\n }, []);\n\n if (!mounted || !available) return null;\n\n const control = (\n <div\n role=\"radiogroup\"\n aria-label=\"Visual editing mode\"\n data-ve-toggle-root=\"\"\n style={CONTAINER_STYLE}\n >\n <span aria-hidden=\"true\" style={BRAND_STYLE}>\n <svg\n width=\"14\"\n height=\"14\"\n viewBox=\"0 0 16 16\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"1.6\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n >\n <path d=\"M11.2 2.2l2.6 2.6-8.5 8.5L1.5 14l.7-3.8z\" />\n <path d=\"M10 3.4l2.6 2.6\" />\n </svg>\n </span>\n {VISUAL_EDITING_MODES.map((m) => {\n const active = m === mode;\n return (\n <button\n key={m}\n type=\"button\"\n role=\"radio\"\n aria-checked={active}\n aria-label={MODE_DESCRIPTIONS[m]}\n title={MODE_DESCRIPTIONS[m]}\n data-ve-toggle-btn=\"\"\n data-ve-active={String(active)}\n onClick={() => setMode(m)}\n style={active ? { ...BUTTON_BASE, ...ACTIVE_BUTTON } : BUTTON_BASE}\n >\n {MODE_LABELS[m]}\n </button>\n );\n })}\n </div>\n );\n\n return createPortal(control, document.body);\n}\n"],"names":["useEffect","useState","createPortal","VISUAL_EDITING_MODES","useVisualEditing","STYLE_ID","SCOPED_STYLES","MODE_LABELS","off","always","hover","MODE_DESCRIPTIONS","CONTAINER_STYLE","position","right","bottom","zIndex","display","alignItems","gap","padding","background","backdropFilter","WebkitBackdropFilter","border","borderRadius","boxShadow","fontFamily","pointerEvents","BRAND_STYLE","justifyContent","width","height","color","BUTTON_BASE","appearance","margin","fontSize","fontWeight","letterSpacing","textTransform","cursor","transition","lineHeight","WebkitTapHighlightColor","ACTIVE_BUTTON","ensureStylesInjected","document","getElementById","style","createElement","id","textContent","head","append","VisualEditingToggle","available","mode","setMode","mounted","setMounted","control","div","role","aria-label","data-ve-toggle-root","span","aria-hidden","svg","viewBox","fill","stroke","strokeWidth","strokeLinecap","strokeLinejoin","path","d","map","m","active","button","type","aria-checked","title","data-ve-toggle-btn","data-ve-active","String","onClick","body"],"mappings":"AAAA;;AAEA,SAASA,SAAS,EAAEC,QAAQ,QAAQ,QAAQ;AAC5C,SAASC,YAAY,QAAQ,YAAY;AAIzC,SAASC,oBAAoB,QAAQ,kBAAkB;AACvD,SAASC,gBAAgB,QAAQ,6BAA6B;AAE9D,6EAA6E;AAC7E,uEAAuE;AACvE,4EAA4E;AAC5E,oBAAoB;AACpB,MAAMC,WAAW;AAEjB,0EAA0E;AAC1E,gFAAgF;AAChF,4EAA4E;AAC5E,+EAA+E;AAC/E,4EAA4E;AAC5E,2EAA2E;AAC3E,MAAMC,gBAAgB,CAAC;;;;;;;;;;;;;;;;;AAiBvB,CAAC;AAED,MAAMC,cAAiD;IACrDC,KAAK;IACLC,QAAQ;IACRC,OAAO;AACT;AAEA,MAAMC,oBAAuD;IAC3DH,KAAK;IACLC,QAAQ;IACRC,OAAO;AACT;AAEA,MAAME,kBAAuC;IAC3CC,UAAU;IACVC,OAAO;IACPC,QAAQ;IACRC,QAAQ;IACRC,SAAS;IACTC,YAAY;IACZC,KAAK;IACLC,SAAS;IACTC,YAAY;IACZC,gBAAgB;IAChBC,sBAAsB;IACtBC,QAAQ;IACRC,cAAc;IACdC,WACE;IACFC,YAAY;IACZC,eAAe;AACjB;AAEA,MAAMC,cAAmC;IACvCZ,SAAS;IACTC,YAAY;IACZY,gBAAgB;IAChBC,OAAO;IACPC,QAAQ;IACRC,OAAO;IACPL,eAAe;AACjB;AAEA,MAAMM,cAAmC;IACvCC,YAAY;IACZX,QAAQ;IACRY,QAAQ;IACRhB,SAAS;IACTiB,UAAU;IACVV,YAAY;IACZW,YAAY;IACZC,eAAe;IACfC,eAAe;IACff,cAAc;IACdgB,QAAQ;IACRpB,YAAY;IACZY,OAAO;IACPS,YAAY;IACZC,YAAY;IACZC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XVA;YAcX;;;IAIJ,qBAAO5E,aAAa2D,SAASd,SAASyC,IAAI;AAC5C"}
@@ -0,0 +1,7 @@
1
+ import type { VeIdentity } from "../internal/shared.js";
2
+ export type BuildAdminEditUrlArgs = VeIdentity & {
3
+ locale?: string;
4
+ adminBasePath?: string;
5
+ };
6
+ export type BuildAdminEditUrl = (args: BuildAdminEditUrlArgs) => string;
7
+ export declare const defaultBuildAdminEditUrl: BuildAdminEditUrl;
@@ -0,0 +1,9 @@
1
+ export const defaultBuildAdminEditUrl = ({ docId, collectionSlug, kind, path, locale, adminBasePath = "/admin" })=>{
2
+ const base = kind === "global" ? `${adminBasePath}/globals/${collectionSlug}` : `${adminBasePath}/collections/${collectionSlug}/${docId}`;
3
+ const parts = [];
4
+ if (path) parts.push(`veFocus=${encodeURIComponent(path)}`);
5
+ if (locale) parts.push(`locale=${encodeURIComponent(locale)}`);
6
+ return parts.length ? `${base}?${parts.join("&")}` : base;
7
+ };
8
+
9
+ //# sourceMappingURL=buildAdminEditUrl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/client/buildAdminEditUrl.ts"],"sourcesContent":["import type { VeIdentity } from \"../internal/shared.js\";\n\nexport type BuildAdminEditUrlArgs = VeIdentity & {\n locale?: string;\n adminBasePath?: string;\n};\n\nexport type BuildAdminEditUrl = (args: BuildAdminEditUrlArgs) => string;\n\nexport const defaultBuildAdminEditUrl: BuildAdminEditUrl = ({\n docId,\n collectionSlug,\n kind,\n path,\n locale,\n adminBasePath = \"/admin\",\n}) => {\n const base =\n kind === \"global\"\n ? `${adminBasePath}/globals/${collectionSlug}`\n : `${adminBasePath}/collections/${collectionSlug}/${docId}`;\n const parts: string[] = [];\n if (path) parts.push(`veFocus=${encodeURIComponent(path)}`);\n if (locale) parts.push(`locale=${encodeURIComponent(locale)}`);\n return parts.length ? `${base}?${parts.join(\"&\")}` : base;\n};\n"],"names":["defaultBuildAdminEditUrl","docId","collectionSlug","kind","path","locale","adminBasePath","base","parts","push","encodeURIComponent","length","join"],"mappings":"AASA,OAAO,MAAMA,2BAA8C,CAAC,EAC1DC,KAAK,EACLC,cAAc,EACdC,IAAI,EACJC,IAAI,EACJC,MAAM,EACNC,gBAAgB,QAAQ,EACzB;IACC,MAAMC,OACJJ,SAAS,WACL,CAAC,EAAEG,cAAc,SAAS,EAAEJ,eAAe,CAAC,GAC5C,CAAC,EAAEI,cAAc,aAAa,EAAEJ,eAAe,CAAC,EAAED,MAAM,CAAC;IAC/D,MAAMO,QAAkB,EAAE;IAC1B,IAAIJ,MAAMI,MAAMC,IAAI,CAAC,CAAC,QAAQ,EAAEC,mBAAmBN,MAAM,CAAC;IAC1D,IAAIC,QAAQG,MAAMC,IAAI,CAAC,CAAC,OAAO,EAAEC,mBAAmBL,QAAQ,CAAC;IAC7D,OAAOG,MAAMG,MAAM,GAAG,CAAC,EAAEJ,KAAK,CAAC,EAAEC,MAAMI,IAAI,CAAC,KAAK,CAAC,GAAGL;AACvD,EAAE"}
@@ -0,0 +1,11 @@
1
+ import { VisualEditingOverlay } from "./VisualEditingOverlay.js";
2
+ import { VisualEditingProvider } from "./VisualEditingProvider.js";
3
+ import { VisualEditingToggle } from "./VisualEditingToggle.js";
4
+ export { type BuildAdminEditUrl, type BuildAdminEditUrlArgs, defaultBuildAdminEditUrl, } from "./buildAdminEditUrl.js";
5
+ export { useVisualEditing } from "./VisualEditingProvider.js";
6
+ export { withVisualEditingPath } from "./withVisualEditingPath.js";
7
+ export declare const VisualEditing: {
8
+ Provider: typeof VisualEditingProvider;
9
+ Overlay: typeof VisualEditingOverlay;
10
+ Toggle: typeof VisualEditingToggle;
11
+ };
@@ -0,0 +1,13 @@
1
+ import { VisualEditingOverlay } from "./VisualEditingOverlay.js";
2
+ import { VisualEditingProvider } from "./VisualEditingProvider.js";
3
+ import { VisualEditingToggle } from "./VisualEditingToggle.js";
4
+ export { defaultBuildAdminEditUrl } from "./buildAdminEditUrl.js";
5
+ export { useVisualEditing } from "./VisualEditingProvider.js";
6
+ export { withVisualEditingPath } from "./withVisualEditingPath.js";
7
+ export const VisualEditing = {
8
+ Provider: VisualEditingProvider,
9
+ Overlay: VisualEditingOverlay,
10
+ Toggle: VisualEditingToggle
11
+ };
12
+
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/client/index.ts"],"sourcesContent":["import { VisualEditingOverlay } from \"./VisualEditingOverlay.js\";\nimport { VisualEditingProvider } from \"./VisualEditingProvider.js\";\nimport { VisualEditingToggle } from \"./VisualEditingToggle.js\";\n\nexport {\n type BuildAdminEditUrl,\n type BuildAdminEditUrlArgs,\n defaultBuildAdminEditUrl,\n} from \"./buildAdminEditUrl.js\";\nexport { useVisualEditing } from \"./VisualEditingProvider.js\";\nexport { withVisualEditingPath } from \"./withVisualEditingPath.js\";\n\nexport const VisualEditing = {\n Provider: VisualEditingProvider,\n Overlay: VisualEditingOverlay,\n Toggle: VisualEditingToggle,\n};\n"],"names":["VisualEditingOverlay","VisualEditingProvider","VisualEditingToggle","defaultBuildAdminEditUrl","useVisualEditing","withVisualEditingPath","VisualEditing","Provider","Overlay","Toggle"],"mappings":"AAAA,SAASA,oBAAoB,QAAQ,4BAA4B;AACjE,SAASC,qBAAqB,QAAQ,6BAA6B;AACnE,SAASC,mBAAmB,QAAQ,2BAA2B;AAE/D,SAGEC,wBAAwB,QACnB,yBAAyB;AAChC,SAASC,gBAAgB,QAAQ,6BAA6B;AAC9D,SAASC,qBAAqB,QAAQ,6BAA6B;AAEnE,OAAO,MAAMC,gBAAgB;IAC3BC,UAAUN;IACVO,SAASR;IACTS,QAAQP;AACV,EAAE"}
@@ -0,0 +1,9 @@
1
+ export declare const STEGA_PREFILTER: RegExp;
2
+ export declare const DATA_VE_TARGET_ATTR = "data-ve-target";
3
+ export declare const DATA_VE_FOR_ATTR = "data-ve-for";
4
+ export declare const LABEL_CLASS = "ve-edit-label";
5
+ export declare const OUTLINE_COLOR = "#34d399";
6
+ export declare const LABEL_TEXT_COLOR = "#022c22";
7
+ export declare const OUTLINE_STYLE = "1px solid #34d399";
8
+ export declare const STEGA_ATTRS: Set<string>;
9
+ export declare const LABEL_STYLES: Partial<CSSStyleDeclaration>;
@@ -0,0 +1,49 @@
1
+ // Skip decoding text nodes that can't possibly carry stega's zero-width chars.
2
+ export const STEGA_PREFILTER = /[\u200B-\u202F\uFEFF]/;
3
+ export const DATA_VE_TARGET_ATTR = "data-ve-target";
4
+ export const DATA_VE_FOR_ATTR = "data-ve-for";
5
+ export const LABEL_CLASS = "ve-edit-label";
6
+ // Match the visual-editing-mvp reference: a single flat emerald treatment,
7
+ // revealed only on hover. Outline hugs the content (no offset), 1px solid,
8
+ // same tailwind emerald-400 / emerald-950 palette used by SectionContainer
9
+ // and EditableField in the MVP.
10
+ export const OUTLINE_COLOR = "#34d399"; // tailwind emerald-400
11
+ export const LABEL_TEXT_COLOR = "#022c22"; // tailwind emerald-950
12
+ export const OUTLINE_STYLE = `1px solid ${OUTLINE_COLOR}`;
13
+ // Attribute names that legitimately carry stega (localized props forwarded to
14
+ // inputs, images, etc.). Narrowing the walk from "every attribute" to this
15
+ // allowlist cuts the element pass dramatically.
16
+ export const STEGA_ATTRS = new Set([
17
+ "alt",
18
+ "title",
19
+ "aria-label",
20
+ "placeholder"
21
+ ]);
22
+ export const LABEL_STYLES = {
23
+ position: "absolute",
24
+ top: "0",
25
+ right: "0",
26
+ transform: "translateY(-100%)",
27
+ background: OUTLINE_COLOR,
28
+ color: LABEL_TEXT_COLOR,
29
+ padding: "5px 11px",
30
+ fontSize: "13px",
31
+ fontFamily: "system-ui, -apple-system, sans-serif",
32
+ fontWeight: "600",
33
+ lineHeight: "1",
34
+ letterSpacing: "0.025em",
35
+ textTransform: "uppercase",
36
+ textDecoration: "none",
37
+ border: "0",
38
+ borderRadius: "0",
39
+ cursor: "pointer",
40
+ pointerEvents: "auto",
41
+ zIndex: "9999",
42
+ whiteSpace: "nowrap",
43
+ // Neutralize typography inherited from the target so the label looks the
44
+ // same over every field (headings, buttons, rich text, etc.).
45
+ fontStyle: "normal",
46
+ fontVariant: "normal"
47
+ };
48
+
49
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/client/overlay/constants.ts"],"sourcesContent":["// Skip decoding text nodes that can't possibly carry stega's zero-width chars.\nexport const STEGA_PREFILTER = /[\\u200B-\\u202F\\uFEFF]/;\n\nexport const DATA_VE_TARGET_ATTR = \"data-ve-target\";\nexport const DATA_VE_FOR_ATTR = \"data-ve-for\";\nexport const LABEL_CLASS = \"ve-edit-label\";\n\n// Match the visual-editing-mvp reference: a single flat emerald treatment,\n// revealed only on hover. Outline hugs the content (no offset), 1px solid,\n// same tailwind emerald-400 / emerald-950 palette used by SectionContainer\n// and EditableField in the MVP.\nexport const OUTLINE_COLOR = \"#34d399\"; // tailwind emerald-400\nexport const LABEL_TEXT_COLOR = \"#022c22\"; // tailwind emerald-950\nexport const OUTLINE_STYLE = `1px solid ${OUTLINE_COLOR}`;\n\n// Attribute names that legitimately carry stega (localized props forwarded to\n// inputs, images, etc.). Narrowing the walk from \"every attribute\" to this\n// allowlist cuts the element pass dramatically.\nexport const STEGA_ATTRS = new Set([\"alt\", \"title\", \"aria-label\", \"placeholder\"]);\n\nexport const LABEL_STYLES: Partial<CSSStyleDeclaration> = {\n position: \"absolute\",\n top: \"0\",\n right: \"0\",\n transform: \"translateY(-100%)\",\n background: OUTLINE_COLOR,\n color: LABEL_TEXT_COLOR,\n padding: \"5px 11px\",\n fontSize: \"13px\",\n fontFamily: \"system-ui, -apple-system, sans-serif\",\n fontWeight: \"600\",\n lineHeight: \"1\",\n letterSpacing: \"0.025em\",\n textTransform: \"uppercase\",\n textDecoration: \"none\",\n border: \"0\",\n borderRadius: \"0\",\n cursor: \"pointer\",\n pointerEvents: \"auto\",\n zIndex: \"9999\",\n whiteSpace: \"nowrap\",\n // Neutralize typography inherited from the target so the label looks the\n // same over every field (headings, buttons, rich text, etc.).\n fontStyle: \"normal\",\n fontVariant: \"normal\",\n};\n"],"names":["STEGA_PREFILTER","DATA_VE_TARGET_ATTR","DATA_VE_FOR_ATTR","LABEL_CLASS","OUTLINE_COLOR","LABEL_TEXT_COLOR","OUTLINE_STYLE","STEGA_ATTRS","Set","LABEL_STYLES","position","top","right","transform","background","color","padding","fontSize","fontFamily","fontWeight","lineHeight","letterSpacing","textTransform","textDecoration","border","borderRadius","cursor","pointerEvents","zIndex","whiteSpace","fontStyle","fontVariant"],"mappings":"AAAA,+EAA+E;AAC/E,OAAO,MAAMA,kBAAkB,wBAAwB;AAEvD,OAAO,MAAMC,sBAAsB,iBAAiB;AACpD,OAAO,MAAMC,mBAAmB,cAAc;AAC9C,OAAO,MAAMC,cAAc,gBAAgB;AAE3C,2EAA2E;AAC3E,2EAA2E;AAC3E,2EAA2E;AAC3E,gCAAgC;AAChC,OAAO,MAAMC,gBAAgB,UAAU,CAAC,uBAAuB;AAC/D,OAAO,MAAMC,mBAAmB,UAAU,CAAC,uBAAuB;AAClE,OAAO,MAAMC,gBAAgB,CAAC,UAAU,EAAEF,cAAc,CAAC,CAAC;AAE1D,8EAA8E;AAC9E,2EAA2E;AAC3E,gDAAgD;AAChD,OAAO,MAAMG,cAAc,IAAIC,IAAI;IAAC;IAAO;IAAS;IAAc;CAAc,EAAE;AAElF,OAAO,MAAMC,eAA6C;IACxDC,UAAU;IACVC,KAAK;IACLC,OAAO;IACPC,WAAW;IACXC,YAAYV;IACZW,OAAOV;IACPW,SAAS;IACTC,UAAU;IACVC,YAAY;IACZC,YAAY;IACZC,YAAY;IACZC,eAAe;IACfC,eAAe;IACfC,gBAAgB;IAChBC,QAAQ;IACRC,cAAc;IACdC,QAAQ;IACRC,eAAe;IACfC,QAAQ;IACRC,YAAY;IACZ,yEAAyE;IACzE,8DAA8D;IAC9DC,WAAW;IACXC,aAAa;AACf,EAAE"}
@@ -0,0 +1,11 @@
1
+ import type { BuildAdminEditUrl } from "../buildAdminEditUrl.js";
2
+ export type OverlayCtx = {
3
+ buildAdminEditUrl: BuildAdminEditUrl;
4
+ adminOrigin: string;
5
+ adminBasePath: string;
6
+ locale?: string;
7
+ /** 'always' paints outlines on every editable target; 'hover' paints only the hovered one.
8
+ * 'off' is handled by not mounting the overlay at all, so it never reaches this module. */
9
+ mode: "always" | "hover";
10
+ };
11
+ export declare function createOverlay(main: HTMLElement, getCtx: () => OverlayCtx): () => void;
@@ -0,0 +1,80 @@
1
+ import { DATA_VE_PATH_ATTR } from "../../constants.js";
2
+ import { LABEL_CLASS } from "./constants.js";
3
+ import { createEditBadge } from "./editBadge.js";
4
+ import { createHoverController } from "./hoverController.js";
5
+ import { groupNodesByPath, readMarkerFromAttrs } from "./markerExtractor.js";
6
+ import { createMutationPipeline } from "./mutationPipeline.js";
7
+ import { createStegaBookkeeper } from "./stegaBookkeeper.js";
8
+ import { collectAttrMatches, collectTextMatches } from "./stegaScanner.js";
9
+ import { createTargetRegistry } from "./targetRegistry.js";
10
+ import { pickTargetForGroup } from "./targetSelector.js";
11
+ // Wires every overlay submodule and returns a dispose that tears them down in reverse order.
12
+ // `getCtx` is a getter so the callsite (the hook) can stabilize its useEffect dependency array
13
+ // on just `[enabled]` while still seeing fresh ctx when a target is registered.
14
+ export function createOverlay(main, getCtx) {
15
+ // Fast Refresh may skip the cleanup from a previous effect run — purge any leftover labels.
16
+ // Outline and target attrs are owned by the registry now (disposal restores them), so leftover
17
+ // attrs only exist if a crash skipped cleanup entirely; rare enough to not warrant a scan.
18
+ for (const leftover of Array.from(document.querySelectorAll(`.${LABEL_CLASS}`))){
19
+ leftover.remove();
20
+ }
21
+ const bookkeeper = createStegaBookkeeper();
22
+ const registry = createTargetRegistry();
23
+ const badge = createEditBadge();
24
+ const hover = createHoverController(badge, registry);
25
+ const applyOverlay = (target, marker)=>{
26
+ const existing = registry.get(target);
27
+ if (existing && existing.path === marker.path) return false;
28
+ registry.upsert(target, marker, getCtx());
29
+ if (existing) {
30
+ hover.refresh(target);
31
+ } else {
32
+ hover.attach(target);
33
+ }
34
+ return true;
35
+ };
36
+ const scan = (root)=>{
37
+ if (!root.isConnected) return;
38
+ // Our own `appendChild(label)` triggers childList mutations the observer will forward
39
+ // back here. The label has no stega and no wrapper — short-circuit to avoid TreeWalker work.
40
+ if (root.classList?.contains(LABEL_CLASS)) return;
41
+ const newMatches = [];
42
+ for (const match of collectTextMatches(root)){
43
+ if (bookkeeper.recordText(match.textNode)) newMatches.push(match);
44
+ }
45
+ for (const match of collectAttrMatches(root)){
46
+ bookkeeper.recordAttr(match.el, match.attr, match.value);
47
+ }
48
+ for (const { nodes, ctx: marker } of groupNodesByPath(newMatches)){
49
+ const target = pickTargetForGroup(nodes, main);
50
+ if (!(target instanceof HTMLElement)) continue;
51
+ applyOverlay(target, marker);
52
+ }
53
+ // Rich text and other renderers that own their own text nodes carry the path on a wrapper
54
+ // attr instead of inline stega.
55
+ const wrappers = [];
56
+ if (root.matches(`[${DATA_VE_PATH_ATTR}]`)) wrappers.push(root);
57
+ wrappers.push(...Array.from(root.querySelectorAll(`[${DATA_VE_PATH_ATTR}]`)));
58
+ for (const target of wrappers){
59
+ const marker = readMarkerFromAttrs(target);
60
+ if (!marker) continue;
61
+ applyOverlay(target, marker);
62
+ }
63
+ };
64
+ scan(main);
65
+ const pipeline = createMutationPipeline(main, {
66
+ onRoots: (roots)=>{
67
+ for (const root of roots)scan(root);
68
+ },
69
+ onTextReset: (node)=>bookkeeper.forgetText(node)
70
+ });
71
+ return ()=>{
72
+ pipeline.dispose();
73
+ hover.dispose();
74
+ registry.disposeAll();
75
+ badge.dispose();
76
+ bookkeeper.restoreAll();
77
+ };
78
+ }
79
+
80
+ //# sourceMappingURL=createOverlay.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/client/overlay/createOverlay.ts"],"sourcesContent":["import type { BuildAdminEditUrl } from \"../buildAdminEditUrl.js\";\nimport type { Marker } from \"./markerExtractor.js\";\nimport type { TextMatch } from \"./stegaScanner.js\";\n\nimport { DATA_VE_PATH_ATTR } from \"../../constants.js\";\nimport { LABEL_CLASS } from \"./constants.js\";\nimport { createEditBadge } from \"./editBadge.js\";\nimport { createHoverController } from \"./hoverController.js\";\nimport { groupNodesByPath, readMarkerFromAttrs } from \"./markerExtractor.js\";\nimport { createMutationPipeline } from \"./mutationPipeline.js\";\nimport { createStegaBookkeeper } from \"./stegaBookkeeper.js\";\nimport { collectAttrMatches, collectTextMatches } from \"./stegaScanner.js\";\nimport { createTargetRegistry } from \"./targetRegistry.js\";\nimport { pickTargetForGroup } from \"./targetSelector.js\";\n\nexport type OverlayCtx = {\n buildAdminEditUrl: BuildAdminEditUrl;\n adminOrigin: string;\n adminBasePath: string;\n locale?: string;\n /** 'always' paints outlines on every editable target; 'hover' paints only the hovered one.\n * 'off' is handled by not mounting the overlay at all, so it never reaches this module. */\n mode: \"always\" | \"hover\";\n};\n\n// Wires every overlay submodule and returns a dispose that tears them down in reverse order.\n// `getCtx` is a getter so the callsite (the hook) can stabilize its useEffect dependency array\n// on just `[enabled]` while still seeing fresh ctx when a target is registered.\nexport function createOverlay(main: HTMLElement, getCtx: () => OverlayCtx): () => void {\n // Fast Refresh may skip the cleanup from a previous effect run — purge any leftover labels.\n // Outline and target attrs are owned by the registry now (disposal restores them), so leftover\n // attrs only exist if a crash skipped cleanup entirely; rare enough to not warrant a scan.\n for (const leftover of Array.from(document.querySelectorAll<HTMLElement>(`.${LABEL_CLASS}`))) {\n leftover.remove();\n }\n\n const bookkeeper = createStegaBookkeeper();\n const registry = createTargetRegistry();\n const badge = createEditBadge();\n const hover = createHoverController(badge, registry);\n\n const applyOverlay = (target: HTMLElement, marker: Marker): boolean => {\n const existing = registry.get(target);\n if (existing && existing.path === marker.path) return false;\n registry.upsert(target, marker, getCtx());\n if (existing) {\n hover.refresh(target);\n } else {\n hover.attach(target);\n }\n return true;\n };\n\n const scan = (root: Element) => {\n if (!root.isConnected) return;\n // Our own `appendChild(label)` triggers childList mutations the observer will forward\n // back here. The label has no stega and no wrapper — short-circuit to avoid TreeWalker work.\n if (root.classList?.contains(LABEL_CLASS)) return;\n\n const newMatches: TextMatch[] = [];\n for (const match of collectTextMatches(root)) {\n if (bookkeeper.recordText(match.textNode)) newMatches.push(match);\n }\n\n for (const match of collectAttrMatches(root)) {\n bookkeeper.recordAttr(match.el, match.attr, match.value);\n }\n\n for (const { nodes, ctx: marker } of groupNodesByPath(newMatches)) {\n const target = pickTargetForGroup(nodes, main);\n if (!(target instanceof HTMLElement)) continue;\n applyOverlay(target, marker);\n }\n\n // Rich text and other renderers that own their own text nodes carry the path on a wrapper\n // attr instead of inline stega.\n const wrappers: HTMLElement[] = [];\n if (root.matches(`[${DATA_VE_PATH_ATTR}]`)) wrappers.push(root as HTMLElement);\n wrappers.push(...Array.from(root.querySelectorAll<HTMLElement>(`[${DATA_VE_PATH_ATTR}]`)));\n\n for (const target of wrappers) {\n const marker = readMarkerFromAttrs(target);\n if (!marker) continue;\n applyOverlay(target, marker);\n }\n };\n\n scan(main);\n\n const pipeline = createMutationPipeline(main, {\n onRoots: (roots) => {\n for (const root of roots) scan(root);\n },\n onTextReset: (node) => bookkeeper.forgetText(node),\n });\n\n return () => {\n pipeline.dispose();\n hover.dispose();\n registry.disposeAll();\n badge.dispose();\n bookkeeper.restoreAll();\n };\n}\n"],"names":["DATA_VE_PATH_ATTR","LABEL_CLASS","createEditBadge","createHoverController","groupNodesByPath","readMarkerFromAttrs","createMutationPipeline","createStegaBookkeeper","collectAttrMatches","collectTextMatches","createTargetRegistry","pickTargetForGroup","createOverlay","main","getCtx","leftover","Array","from","document","querySelectorAll","remove","bookkeeper","registry","badge","hover","applyOverlay","target","marker","existing","get","path","upsert","refresh","attach","scan","root","isConnected","classList","contains","newMatches","match","recordText","textNode","push","recordAttr","el","attr","value","nodes","ctx","HTMLElement","wrappers","matches","pipeline","onRoots","roots","onTextReset","node","forgetText","dispose","disposeAll","restoreAll"],"mappings":"AAIA,SAASA,iBAAiB,QAAQ,qBAAqB;AACvD,SAAS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