@intlayer/editor 9.6.0 → 9.7.1

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 (92) hide show
  1. package/dist/cjs/_virtual/_rolldown/runtime.cjs +1 -2
  2. package/dist/cjs/compareUrls.cjs +1 -2
  3. package/dist/cjs/components/ContentSelector.cjs +70 -17
  4. package/dist/cjs/components/ContentSelector.cjs.map +1 -1
  5. package/dist/cjs/components/ContentSelectorWrapper.cjs +63 -6
  6. package/dist/cjs/components/ContentSelectorWrapper.cjs.map +1 -1
  7. package/dist/cjs/components/index.cjs +2 -2
  8. package/dist/cjs/components/isInteractiveClickTarget.cjs +65 -0
  9. package/dist/cjs/components/isInteractiveClickTarget.cjs.map +1 -0
  10. package/dist/cjs/core/CrossFrameMessenger.cjs +2 -3
  11. package/dist/cjs/core/CrossFrameStateManager.cjs +1 -2
  12. package/dist/cjs/core/EditorStateManager.cjs +79 -18
  13. package/dist/cjs/core/EditorStateManager.cjs.map +1 -1
  14. package/dist/cjs/core/IframeClickInterceptor.cjs +17 -10
  15. package/dist/cjs/core/IframeClickInterceptor.cjs.map +1 -1
  16. package/dist/cjs/core/UrlStateManager.cjs +2 -3
  17. package/dist/cjs/core/getLocalEditorParentOrigin.cjs +32 -0
  18. package/dist/cjs/core/getLocalEditorParentOrigin.cjs.map +1 -0
  19. package/dist/cjs/core/globalManager.cjs +1 -2
  20. package/dist/cjs/core/index.cjs +10 -8
  21. package/dist/cjs/core/initEditorClient.cjs +8 -6
  22. package/dist/cjs/core/initEditorClient.cjs.map +1 -1
  23. package/dist/cjs/core/selectionClick.cjs +24 -0
  24. package/dist/cjs/core/selectionClick.cjs.map +1 -0
  25. package/dist/cjs/core/sharedWindowState.cjs +1 -2
  26. package/dist/cjs/index.cjs +13 -11
  27. package/dist/cjs/isEnabled.cjs +1 -2
  28. package/dist/cjs/messageKey.cjs +5 -2
  29. package/dist/cjs/messageKey.cjs.map +1 -1
  30. package/dist/esm/compareUrls.mjs +1 -2
  31. package/dist/esm/components/ContentSelector.mjs +69 -16
  32. package/dist/esm/components/ContentSelector.mjs.map +1 -1
  33. package/dist/esm/components/ContentSelectorWrapper.mjs +61 -4
  34. package/dist/esm/components/ContentSelectorWrapper.mjs.map +1 -1
  35. package/dist/esm/components/index.mjs +1 -1
  36. package/dist/esm/components/isInteractiveClickTarget.mjs +64 -0
  37. package/dist/esm/components/isInteractiveClickTarget.mjs.map +1 -0
  38. package/dist/esm/core/CrossFrameMessenger.mjs +1 -2
  39. package/dist/esm/core/CrossFrameStateManager.mjs +1 -2
  40. package/dist/esm/core/EditorStateManager.mjs +71 -12
  41. package/dist/esm/core/EditorStateManager.mjs.map +1 -1
  42. package/dist/esm/core/IframeClickInterceptor.mjs +16 -9
  43. package/dist/esm/core/IframeClickInterceptor.mjs.map +1 -1
  44. package/dist/esm/core/UrlStateManager.mjs +1 -2
  45. package/dist/esm/core/getLocalEditorParentOrigin.mjs +31 -0
  46. package/dist/esm/core/getLocalEditorParentOrigin.mjs.map +1 -0
  47. package/dist/esm/core/globalManager.mjs +1 -2
  48. package/dist/esm/core/index.mjs +4 -4
  49. package/dist/esm/core/initEditorClient.mjs +6 -4
  50. package/dist/esm/core/initEditorClient.mjs.map +1 -1
  51. package/dist/esm/core/selectionClick.mjs +22 -0
  52. package/dist/esm/core/selectionClick.mjs.map +1 -0
  53. package/dist/esm/core/sharedWindowState.mjs +1 -2
  54. package/dist/esm/index.mjs +3 -3
  55. package/dist/esm/isEnabled.mjs +1 -2
  56. package/dist/esm/messageKey.mjs +5 -2
  57. package/dist/esm/messageKey.mjs.map +1 -1
  58. package/dist/types/compareUrls.d.ts +0 -2
  59. package/dist/types/compareUrls.d.ts.map +1 -1
  60. package/dist/types/components/ContentSelector.d.ts +10 -4
  61. package/dist/types/components/ContentSelector.d.ts.map +1 -1
  62. package/dist/types/components/ContentSelectorWrapper.d.ts +5 -2
  63. package/dist/types/components/ContentSelectorWrapper.d.ts.map +1 -1
  64. package/dist/types/components/isInteractiveClickTarget.d.ts +14 -0
  65. package/dist/types/components/isInteractiveClickTarget.d.ts.map +1 -0
  66. package/dist/types/core/CrossFrameMessenger.d.ts +1 -2
  67. package/dist/types/core/CrossFrameMessenger.d.ts.map +1 -1
  68. package/dist/types/core/CrossFrameStateManager.d.ts +0 -2
  69. package/dist/types/core/CrossFrameStateManager.d.ts.map +1 -1
  70. package/dist/types/core/EditorStateManager.d.ts +34 -3
  71. package/dist/types/core/EditorStateManager.d.ts.map +1 -1
  72. package/dist/types/core/IframeClickInterceptor.d.ts +8 -4
  73. package/dist/types/core/IframeClickInterceptor.d.ts.map +1 -1
  74. package/dist/types/core/UrlStateManager.d.ts +0 -2
  75. package/dist/types/core/UrlStateManager.d.ts.map +1 -1
  76. package/dist/types/core/getLocalEditorParentOrigin.d.ts +11 -0
  77. package/dist/types/core/getLocalEditorParentOrigin.d.ts.map +1 -0
  78. package/dist/types/core/globalManager.d.ts +0 -2
  79. package/dist/types/core/globalManager.d.ts.map +1 -1
  80. package/dist/types/core/index.d.ts +4 -4
  81. package/dist/types/core/initEditorClient.d.ts +0 -2
  82. package/dist/types/core/initEditorClient.d.ts.map +1 -1
  83. package/dist/types/core/selectionClick.d.ts +15 -0
  84. package/dist/types/core/selectionClick.d.ts.map +1 -0
  85. package/dist/types/core/sharedWindowState.d.ts +1 -2
  86. package/dist/types/core/sharedWindowState.d.ts.map +1 -1
  87. package/dist/types/index.d.ts +3 -2
  88. package/dist/types/isEnabled.d.ts +0 -2
  89. package/dist/types/isEnabled.d.ts.map +1 -1
  90. package/dist/types/messageKey.d.ts +5 -3
  91. package/dist/types/messageKey.d.ts.map +1 -1
  92. package/package.json +8 -8
@@ -1,16 +1,18 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_messageKey = require('./messageKey.cjs');
3
- const require_core_globalManager = require('./core/globalManager.cjs');
4
- const require_components_ContentSelectorWrapper = require('./components/ContentSelectorWrapper.cjs');
5
- const require_components_ContentSelector = require('./components/ContentSelector.cjs');
6
- const require_core_CrossFrameMessenger = require('./core/CrossFrameMessenger.cjs');
7
- const require_core_CrossFrameStateManager = require('./core/CrossFrameStateManager.cjs');
8
- const require_core_IframeClickInterceptor = require('./core/IframeClickInterceptor.cjs');
9
- const require_core_sharedWindowState = require('./core/sharedWindowState.cjs');
10
- const require_core_UrlStateManager = require('./core/UrlStateManager.cjs');
11
- const require_core_EditorStateManager = require('./core/EditorStateManager.cjs');
12
- const require_core_initEditorClient = require('./core/initEditorClient.cjs');
2
+ const require_core_globalManager = require("./core/globalManager.cjs");
3
+ const require_messageKey = require("./messageKey.cjs");
4
+ const require_components_ContentSelectorWrapper = require("./components/ContentSelectorWrapper.cjs");
5
+ const require_components_ContentSelector = require("./components/ContentSelector.cjs");
6
+ const require_core_CrossFrameMessenger = require("./core/CrossFrameMessenger.cjs");
7
+ const require_core_CrossFrameStateManager = require("./core/CrossFrameStateManager.cjs");
8
+ const require_core_IframeClickInterceptor = require("./core/IframeClickInterceptor.cjs");
9
+ const require_core_sharedWindowState = require("./core/sharedWindowState.cjs");
10
+ const require_core_UrlStateManager = require("./core/UrlStateManager.cjs");
11
+ const require_core_EditorStateManager = require("./core/EditorStateManager.cjs");
12
+ const require_core_initEditorClient = require("./core/initEditorClient.cjs");
13
13
 
14
+ exports.CLIENT_HEARTBEAT_INTERVAL_MS = require_core_EditorStateManager.CLIENT_HEARTBEAT_INTERVAL_MS;
15
+ exports.CLIENT_HEARTBEAT_TIMEOUT_MS = require_core_EditorStateManager.CLIENT_HEARTBEAT_TIMEOUT_MS;
14
16
  exports.CrossFrameMessenger = require_core_CrossFrameMessenger.CrossFrameMessenger;
15
17
  exports.CrossFrameStateManager = require_core_CrossFrameStateManager.CrossFrameStateManager;
16
18
  exports.EditorStateManager = require_core_EditorStateManager.EditorStateManager;
@@ -1,10 +1,9 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  let _intlayer_config_built = require("@intlayer/config/built");
3
3
 
4
- //#region src/isEnabled.ts
4
+ // src/isEnabled.ts
5
5
  const TREE_SHAKE_EDITOR = process.env.INTLAYER_EDITOR_ENABLED === "false";
6
6
  const isEnabled = !TREE_SHAKE_EDITOR && _intlayer_config_built.editor?.enabled && typeof window !== "undefined" && window.self !== window.top;
7
7
 
8
- //#endregion
9
8
  exports.isEnabled = isEnabled;
10
9
  //# sourceMappingURL=isEnabled.cjs.map
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- //#region src/messageKey.ts
2
+ // src/messageKey.ts
3
3
  let MessageKey = /* @__PURE__ */ function(MessageKey) {
4
4
  /** Client → editor: announces the client is ready (also used as response to ARE_YOU_THERE) */
5
5
  MessageKey["INTLAYER_CLIENT_READY"] = "INTLAYER_CLIENT_READY";
@@ -13,6 +13,8 @@ let MessageKey = /* @__PURE__ */ function(MessageKey) {
13
13
  MessageKey["INTLAYER_CONFIGURATION"] = "INTLAYER_CONFIGURATION";
14
14
  MessageKey["INTLAYER_CURRENT_LOCALE"] = "INTLAYER_CURRENT_LOCALE";
15
15
  MessageKey["INTLAYER_URL_CHANGE"] = "INTLAYER_URL_CHANGE";
16
+ /** Editor → client: asks the client to switch to the given locale */
17
+ MessageKey["INTLAYER_LOCALE_CHANGE_REQUESTED"] = "INTLAYER_LOCALE_CHANGE_REQUESTED";
16
18
  /** Client → editor: load and update content */
17
19
  MessageKey["INTLAYER_LOCALE_DICTIONARIES_CHANGED"] = "INTLAYER_LOCALE_DICTIONARIES_CHANGED";
18
20
  MessageKey["INTLAYER_DISTANT_DICTIONARIES_CHANGED"] = "INTLAYER_DISTANT_DICTIONARIES_CHANGED";
@@ -24,9 +26,10 @@ let MessageKey = /* @__PURE__ */ function(MessageKey) {
24
26
  MessageKey["INTLAYER_IFRAME_CLICKED"] = "INTLAYER_IFRAME_CLICKED";
25
27
  /** Client → editor: list of dictionary keys currently rendered in the iframe */
26
28
  MessageKey["INTLAYER_DISPLAYED_DICTIONARY_KEYS"] = "INTLAYER_DISPLAYED_DICTIONARY_KEYS";
29
+ /** IDE host → editor: colour theme of the IDE embedding the editor */
30
+ MessageKey["INTLAYER_HOST_THEME_CHANGED"] = "INTLAYER_HOST_THEME_CHANGED";
27
31
  return MessageKey;
28
32
  }({});
29
33
 
30
- //#endregion
31
34
  exports.MessageKey = MessageKey;
32
35
  //# sourceMappingURL=messageKey.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"messageKey.cjs","names":[],"sources":["../../src/messageKey.ts"],"sourcesContent":["export enum MessageKey {\n /** Client → editor: announces the client is ready (also used as response to ARE_YOU_THERE) */\n INTLAYER_CLIENT_READY = 'INTLAYER_CLIENT_READY',\n /** Editor → client: asks if the client is still alive */\n INTLAYER_ARE_YOU_THERE = 'INTLAYER_ARE_YOU_THERE',\n /** Editor → client: instructs the client to activate the editor selector */\n INTLAYER_EDITOR_ACTIVATE = 'INTLAYER_EDITOR_ACTIVATE',\n /** Client → editor: instructs the editor that the client is enabled */\n INTLAYER_EDITOR_ENABLED = 'INTLAYER_EDITOR_ENABLED',\n\n /** Client → editor: send information related the app */\n INTLAYER_CONFIGURATION = 'INTLAYER_CONFIGURATION',\n INTLAYER_CURRENT_LOCALE = 'INTLAYER_CURRENT_LOCALE',\n INTLAYER_URL_CHANGE = 'INTLAYER_URL_CHANGE',\n\n /** Client → editor: load and update content */\n INTLAYER_LOCALE_DICTIONARIES_CHANGED = 'INTLAYER_LOCALE_DICTIONARIES_CHANGED',\n INTLAYER_DISTANT_DICTIONARIES_CHANGED = 'INTLAYER_DISTANT_DICTIONARIES_CHANGED',\n\n /** Client → editor & Editor → client: Update focus and changed content */\n INTLAYER_HOVERED_CONTENT_CHANGED = 'INTLAYER_HOVERED_CONTENT_CHANGED',\n INTLAYER_FOCUSED_CONTENT_CHANGED = 'INTLAYER_FOCUSED_CONTENT_CHANGED',\n INTLAYER_EDITED_CONTENT_CHANGED = 'INTLAYER_EDITED_CONTENT_CHANGED',\n\n /** Client → editor: Helper to sync iframe client reactivity on click client */\n INTLAYER_IFRAME_CLICKED = 'INTLAYER_IFRAME_CLICKED',\n\n /** Client → editor: list of dictionary keys currently rendered in the iframe */\n INTLAYER_DISPLAYED_DICTIONARY_KEYS = 'INTLAYER_DISPLAYED_DICTIONARY_KEYS',\n}\n"],"mappings":";;AAAA,IAAY,aAAL;;CAEL;;CAEA;;CAEA;;CAEA;;CAGA;CACA;CACA;;CAGA;CACA;;CAGA;CACA;CACA;;CAGA;;CAGA;;AACF"}
1
+ {"version":3,"file":"messageKey.cjs","names":[],"sources":["../../src/messageKey.ts"],"sourcesContent":["export enum MessageKey {\n /** Client → editor: announces the client is ready (also used as response to ARE_YOU_THERE) */\n INTLAYER_CLIENT_READY = 'INTLAYER_CLIENT_READY',\n /** Editor → client: asks if the client is still alive */\n INTLAYER_ARE_YOU_THERE = 'INTLAYER_ARE_YOU_THERE',\n /** Editor → client: instructs the client to activate the editor selector */\n INTLAYER_EDITOR_ACTIVATE = 'INTLAYER_EDITOR_ACTIVATE',\n /** Client → editor: instructs the editor that the client is enabled */\n INTLAYER_EDITOR_ENABLED = 'INTLAYER_EDITOR_ENABLED',\n\n /** Client → editor: send information related the app */\n INTLAYER_CONFIGURATION = 'INTLAYER_CONFIGURATION',\n INTLAYER_CURRENT_LOCALE = 'INTLAYER_CURRENT_LOCALE',\n INTLAYER_URL_CHANGE = 'INTLAYER_URL_CHANGE',\n /** Editor → client: asks the client to switch to the given locale */\n INTLAYER_LOCALE_CHANGE_REQUESTED = 'INTLAYER_LOCALE_CHANGE_REQUESTED',\n\n /** Client → editor: load and update content */\n INTLAYER_LOCALE_DICTIONARIES_CHANGED = 'INTLAYER_LOCALE_DICTIONARIES_CHANGED',\n INTLAYER_DISTANT_DICTIONARIES_CHANGED = 'INTLAYER_DISTANT_DICTIONARIES_CHANGED',\n\n /** Client → editor & Editor → client: Update focus and changed content */\n INTLAYER_HOVERED_CONTENT_CHANGED = 'INTLAYER_HOVERED_CONTENT_CHANGED',\n INTLAYER_FOCUSED_CONTENT_CHANGED = 'INTLAYER_FOCUSED_CONTENT_CHANGED',\n INTLAYER_EDITED_CONTENT_CHANGED = 'INTLAYER_EDITED_CONTENT_CHANGED',\n\n /** Client → editor: Helper to sync iframe client reactivity on click client */\n INTLAYER_IFRAME_CLICKED = 'INTLAYER_IFRAME_CLICKED',\n\n /** Client → editor: list of dictionary keys currently rendered in the iframe */\n INTLAYER_DISPLAYED_DICTIONARY_KEYS = 'INTLAYER_DISPLAYED_DICTIONARY_KEYS',\n\n /** IDE host → editor: colour theme of the IDE embedding the editor */\n INTLAYER_HOST_THEME_CHANGED = 'INTLAYER_HOST_THEME_CHANGED',\n}\n"],"mappings":";;AAAA,IAAY,aAAL;;CAEL;;CAEA;;CAEA;;CAEA;;CAGA;CACA;CACA;;CAEA;;CAGA;CACA;;CAGA;CACA;CACA;;CAGA;;CAGA;;CAGA;;AACF"}
@@ -1,4 +1,4 @@
1
- //#region src/compareUrls.ts
1
+ // src/compareUrls.ts
2
2
  /**
3
3
  * Compare two URLs for equality.
4
4
  * This function is used to determine if a message originates from the same origin.
@@ -33,6 +33,5 @@ const compareUrls = (url1, url2) => {
33
33
  }
34
34
  };
35
35
 
36
- //#endregion
37
36
  export { compareUrls };
38
37
  //# sourceMappingURL=compareUrls.mjs.map
@@ -1,6 +1,8 @@
1
+ import { isSelectionClick, markSelectionClick } from "../core/selectionClick.mjs";
1
2
  import { defineIntlayerContentSelectorWrapper } from "./ContentSelectorWrapper.mjs";
3
+ import { isInteractiveClickTarget } from "./isInteractiveClickTarget.mjs";
2
4
 
3
- //#region src/components/ContentSelector.ts
5
+ // src/components/ContentSelector.ts
4
6
  const DEFAULT_PRESS_DURATION = 250;
5
7
  const STYLES = `
6
8
  :host {
@@ -22,15 +24,49 @@ const STYLES = `
22
24
  .wrapper[data-active] {
23
25
  outline-color: inherit;
24
26
  }
27
+
28
+ /*
29
+ * Text content wraps over several lines: an outline would frame the whole
30
+ * block, so each line fragment gets its own ring instead. The padding keeps
31
+ * the ring 4px away from the text, the negative margin cancels its layout.
32
+ */
33
+ .wrapper[data-text] {
34
+ display: inline;
35
+ outline: none;
36
+ padding: 4px;
37
+ margin: -4px;
38
+ box-shadow: 0 0 0 2px transparent;
39
+ -webkit-box-decoration-break: clone;
40
+ box-decoration-break: clone;
41
+ }
42
+
43
+ .wrapper[data-text][data-active] {
44
+ box-shadow: 0 0 0 2px currentColor;
45
+ }
25
46
  `;
47
+ /**
48
+ * Whether the slotted content is only text, so it can be rendered inline and
49
+ * highlighted line by line. Elements (markdown blocks, framework nodes) may
50
+ * not lay out inline, and fall back to the outline.
51
+ */
52
+ const isTextOnlyContent = (slot) => {
53
+ const assignedNodes = slot.assignedNodes({ flatten: true });
54
+ return assignedNodes.length > 0 && assignedNodes.every((node) => node.nodeType === Node.TEXT_NODE);
55
+ };
26
56
  const _HTMLElement = typeof HTMLElement !== "undefined" ? HTMLElement : class {};
27
57
  /**
28
58
  * <intlayer-content-selector>
29
59
  *
30
60
  * A framework-agnostic web component that wraps content with Intlayer editor
31
- * selection UI (hover outline, long-press to select, click-outside to deselect).
61
+ * selection UI (hover outline, click to select, click-outside to deselect).
62
+ *
63
+ * Content is selected by:
64
+ * - a click, unless it lands on something the app handles (link, button,
65
+ * form control, clickable ancestor), which keeps its behavior
66
+ * - a long press, on any content
67
+ * - a ⌘ / Ctrl + click, on any content, cancelling the click's own action
32
68
  *
33
- * @fires intlayer:press - Fired after a long press (pressDuration ms). Bubbles.
69
+ * @fires intlayer:press - Fired when the content is selected. Bubbles.
34
70
  * @fires intlayer:hover - Fired on mouseenter. Bubbles.
35
71
  * @fires intlayer:unhover - Fired on mouseleave / mouseup. Bubbles.
36
72
  * @fires intlayer:click-outside - Fired when a click occurs outside the element. Bubbles.
@@ -72,9 +108,11 @@ var IntlayerContentSelectorElement = class extends _HTMLElement {
72
108
  wrapper.className = "wrapper";
73
109
  wrapper.setAttribute("role", "button");
74
110
  wrapper.setAttribute("tabindex", "0");
75
- wrapper.appendChild(document.createElement("slot"));
111
+ const slot = document.createElement("slot");
112
+ wrapper.appendChild(slot);
76
113
  shadow.appendChild(wrapper);
77
114
  this._wrapper = wrapper;
115
+ slot.addEventListener("slotchange", () => wrapper.toggleAttribute("data-text", isTextOnlyContent(slot)));
78
116
  wrapper.addEventListener("mousedown", () => this._handleMouseDown());
79
117
  wrapper.addEventListener("mouseup", () => this._handleMouseUpOrLeave());
80
118
  wrapper.addEventListener("mouseleave", () => this._handleMouseUpOrLeave());
@@ -93,17 +131,23 @@ var IntlayerContentSelectorElement = class extends _HTMLElement {
93
131
  }
94
132
  connectedCallback() {
95
133
  this._clickOutsideHandler = (e) => {
134
+ if (!this._isSelecting && !this._isSelectingState) return;
96
135
  if (!e.composedPath().includes(this)) {
136
+ this._clearPressTimer();
97
137
  this._isSelectingState = false;
98
- this._dispatch("intlayer:click-outside");
138
+ this._isSelecting = false;
139
+ this.removeAttribute("is-selecting");
140
+ this._dispatch("intlayer:click-outside", { originalEvent: e });
99
141
  this._updateActiveState();
100
142
  }
101
143
  };
102
144
  document.addEventListener("mousedown", this._clickOutsideHandler);
145
+ document.addEventListener("touchstart", this._clickOutsideHandler);
103
146
  }
104
147
  disconnectedCallback() {
105
148
  if (this._clickOutsideHandler) {
106
149
  document.removeEventListener("mousedown", this._clickOutsideHandler);
150
+ document.removeEventListener("touchstart", this._clickOutsideHandler);
107
151
  this._clickOutsideHandler = null;
108
152
  }
109
153
  this._clearPressTimer();
@@ -118,19 +162,22 @@ var IntlayerContentSelectorElement = class extends _HTMLElement {
118
162
  this._pressTimer = null;
119
163
  }
120
164
  }
121
- _dispatch(eventName) {
165
+ _dispatch(eventName, detail) {
122
166
  this.dispatchEvent(new CustomEvent(eventName, {
167
+ detail,
123
168
  bubbles: true,
124
169
  composed: true
125
170
  }));
126
171
  }
172
+ _select() {
173
+ this._clearPressTimer();
174
+ this._isSelectingState = true;
175
+ this._updateActiveState();
176
+ this._dispatch("intlayer:press");
177
+ }
127
178
  _handleMouseDown() {
128
179
  this._clearPressTimer();
129
- this._pressTimer = setTimeout(() => {
130
- this._isSelectingState = true;
131
- this._updateActiveState();
132
- this._dispatch("intlayer:press");
133
- }, this._pressDuration);
180
+ this._pressTimer = setTimeout(() => this._select(), this._pressDuration);
134
181
  }
135
182
  _handleMouseEnter() {
136
183
  this._isHovered = true;
@@ -145,11 +192,18 @@ var IntlayerContentSelectorElement = class extends _HTMLElement {
145
192
  this._clearPressTimer();
146
193
  this._updateActiveState();
147
194
  }
148
- _handleClick(e) {
149
- if (this._isSelecting || this._isSelectingState) {
150
- e.preventDefault();
151
- e.stopPropagation();
195
+ _handleClick(event) {
196
+ if (isSelectionClick(event)) return;
197
+ const isModifierClick = event.metaKey || event.ctrlKey;
198
+ if (this._isSelecting || this._isSelectingState || isModifierClick) {
199
+ event.preventDefault();
200
+ event.stopPropagation();
201
+ if (isModifierClick) this._select();
202
+ return;
152
203
  }
204
+ if (isInteractiveClickTarget(event)) return;
205
+ markSelectionClick(event);
206
+ this._select();
153
207
  }
154
208
  _handleBlur() {
155
209
  this._isSelectingState = false;
@@ -167,6 +221,5 @@ const defineIntlayerElements = () => {
167
221
  defineIntlayerContentSelectorWrapper();
168
222
  };
169
223
 
170
- //#endregion
171
224
  export { IntlayerContentSelectorElement, defineIntlayerElements };
172
225
  //# sourceMappingURL=ContentSelector.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"ContentSelector.mjs","names":[],"sources":["../../../src/components/ContentSelector.ts"],"sourcesContent":["import { defineIntlayerContentSelectorWrapper } from './ContentSelectorWrapper';\n\nconst DEFAULT_PRESS_DURATION = 250;\n\nconst STYLES = `\n :host {\n display: contents;\n }\n\n .wrapper {\n display: inline-block;\n cursor: pointer;\n user-select: none;\n border-radius: 0.375rem;\n outline-width: 2px;\n outline-offset: 4px;\n outline-style: solid;\n outline-color: transparent;\n transition: all 100ms 50ms ease-in-out;\n }\n\n .wrapper[data-active] {\n outline-color: inherit;\n }\n`;\n\nconst _HTMLElement =\n typeof HTMLElement !== 'undefined'\n ? HTMLElement\n : (class {} as unknown as typeof HTMLElement);\n\n/**\n * <intlayer-content-selector>\n *\n * A framework-agnostic web component that wraps content with Intlayer editor\n * selection UI (hover outline, long-press to select, click-outside to deselect).\n *\n * @fires intlayer:press - Fired after a long press (pressDuration ms). Bubbles.\n * @fires intlayer:hover - Fired on mouseenter. Bubbles.\n * @fires intlayer:unhover - Fired on mouseleave / mouseup. Bubbles.\n * @fires intlayer:click-outside - Fired when a click occurs outside the element. Bubbles.\n *\n * @prop {boolean} isSelecting - Whether this element is currently selected (external state)\n * @prop {number} pressDuration - Long-press threshold in ms. Default: 250\n */\nexport class IntlayerContentSelectorElement extends _HTMLElement {\n private _isSelecting = false;\n private _pressDuration = DEFAULT_PRESS_DURATION;\n private _isHovered = false;\n private _isSelectingState = false;\n private _wrapper: HTMLSpanElement;\n private _pressTimer: ReturnType<typeof setTimeout> | null = null;\n private _clickOutsideHandler: ((e: MouseEvent) => void) | null = null;\n\n static get observedAttributes(): string[] {\n return ['is-selecting', 'press-duration'];\n }\n\n get isSelecting(): boolean {\n return this._isSelecting;\n }\n set isSelecting(v: boolean) {\n this._isSelecting = v;\n this._updateActiveState();\n }\n\n get pressDuration(): number {\n return this._pressDuration;\n }\n set pressDuration(v: number) {\n this._pressDuration = v;\n }\n\n constructor() {\n super();\n const shadow = this.attachShadow({ mode: 'open' });\n\n const style = document.createElement('style');\n style.textContent = STYLES;\n shadow.appendChild(style);\n\n const wrapper = document.createElement('span');\n wrapper.className = 'wrapper';\n wrapper.setAttribute('role', 'button');\n wrapper.setAttribute('tabindex', '0');\n wrapper.appendChild(document.createElement('slot'));\n shadow.appendChild(wrapper);\n this._wrapper = wrapper;\n\n wrapper.addEventListener('mousedown', () => this._handleMouseDown());\n wrapper.addEventListener('mouseup', () => this._handleMouseUpOrLeave());\n wrapper.addEventListener('mouseleave', () => this._handleMouseUpOrLeave());\n wrapper.addEventListener('mouseenter', () => this._handleMouseEnter());\n wrapper.addEventListener('click', (e) => this._handleClick(e));\n wrapper.addEventListener('touchstart', () => this._handleMouseDown());\n wrapper.addEventListener('touchend', () => this._handleMouseUpOrLeave());\n wrapper.addEventListener('touchcancel', () => this._handleMouseUpOrLeave());\n wrapper.addEventListener('blur', () => this._handleBlur());\n }\n\n attributeChangedCallback(\n name: string,\n _oldVal: string | null,\n newVal: string | null\n ): void {\n if (name === 'is-selecting') {\n this._isSelecting = newVal !== null;\n this._updateActiveState();\n } else if (name === 'press-duration') {\n this._pressDuration =\n newVal !== null ? parseInt(newVal, 10) : DEFAULT_PRESS_DURATION;\n }\n }\n\n connectedCallback(): void {\n this._clickOutsideHandler = (e: MouseEvent) => {\n // composedPath() pierces shadow boundaries\n if (!e.composedPath().includes(this)) {\n this._isSelectingState = false;\n this._dispatch('intlayer:click-outside');\n this._updateActiveState();\n }\n };\n document.addEventListener('mousedown', this._clickOutsideHandler);\n }\n\n disconnectedCallback(): void {\n if (this._clickOutsideHandler) {\n document.removeEventListener('mousedown', this._clickOutsideHandler);\n this._clickOutsideHandler = null;\n }\n this._clearPressTimer();\n }\n\n private _updateActiveState(): void {\n const isActive =\n this._isSelecting || this._isSelectingState || this._isHovered;\n if (isActive) {\n this._wrapper.setAttribute('data-active', '');\n } else {\n this._wrapper.removeAttribute('data-active');\n }\n }\n\n private _clearPressTimer(): void {\n if (this._pressTimer !== null) {\n clearTimeout(this._pressTimer);\n this._pressTimer = null;\n }\n }\n\n private _dispatch(eventName: string): void {\n this.dispatchEvent(\n new CustomEvent(eventName, { bubbles: true, composed: true })\n );\n }\n\n private _handleMouseDown(): void {\n this._clearPressTimer();\n this._pressTimer = setTimeout(() => {\n this._isSelectingState = true;\n this._updateActiveState();\n this._dispatch('intlayer:press');\n }, this._pressDuration);\n }\n\n private _handleMouseEnter(): void {\n this._isHovered = true;\n this._updateActiveState();\n this._dispatch('intlayer:hover');\n }\n\n private _handleMouseUpOrLeave(): void {\n if (this._isHovered) {\n this._isHovered = false;\n this._dispatch('intlayer:unhover');\n }\n this._clearPressTimer();\n this._updateActiveState();\n }\n\n private _handleClick(e: MouseEvent): void {\n if (this._isSelecting || this._isSelectingState) {\n e.preventDefault();\n e.stopPropagation();\n }\n }\n\n private _handleBlur(): void {\n this._isSelectingState = false;\n this._updateActiveState();\n }\n}\n\n/**\n * Register all Intlayer custom elements.\n * Call this once at application startup (inside IntlayerEditorProvider or similar).\n * Safe to call multiple times — only registers elements that are not yet defined.\n */\nexport const defineIntlayerElements = (): void => {\n if (typeof customElements === 'undefined') return;\n if (!customElements.get('intlayer-content-selector')) {\n customElements.define(\n 'intlayer-content-selector',\n IntlayerContentSelectorElement\n );\n }\n defineIntlayerContentSelectorWrapper();\n};\n"],"mappings":";;;AAEA,MAAM,yBAAyB;AAE/B,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;AAsBf,MAAM,eACJ,OAAO,gBAAgB,cACnB,cACC,MAAM,CAAC;;;;;;;;;;;;;;;AAgBd,IAAa,iCAAb,cAAoD,aAAa;CAC/D,AAAQ,eAAe;CACvB,AAAQ,iBAAiB;CACzB,AAAQ,aAAa;CACrB,AAAQ,oBAAoB;CAC5B,AAAQ;CACR,AAAQ,cAAoD;CAC5D,AAAQ,uBAAyD;CAEjE,WAAW,qBAA+B;EACxC,OAAO,CAAC,gBAAgB,gBAAgB;CAC1C;CAEA,IAAI,cAAuB;EACzB,OAAO,KAAK;CACd;CACA,IAAI,YAAY,GAAY;EAC1B,KAAK,eAAe;EACpB,KAAK,mBAAmB;CAC1B;CAEA,IAAI,gBAAwB;EAC1B,OAAO,KAAK;CACd;CACA,IAAI,cAAc,GAAW;EAC3B,KAAK,iBAAiB;CACxB;CAEA,cAAc;EACZ,MAAM;EACN,MAAM,SAAS,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;EAEjD,MAAM,QAAQ,SAAS,cAAc,OAAO;EAC5C,MAAM,cAAc;EACpB,OAAO,YAAY,KAAK;EAExB,MAAM,UAAU,S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EAGjC,IADE,KAAK,gBAAgB,KAAK,qBAAqB,KAAK,YAEpD,KAAK,SAAS,aAAa,eAAe,EAAE;OAE5C,KAAK,SAAS,gBAAgB,aAAa;CAE/C;CAEA,AAAQ,mBAAyB;EAC/B,IAAI,KAAK,gBAAgB,MAAM;GAC7B,aAAa,KAAK,WAAW;GAC7B,KAAK,cAAc;EACrB;CACF;CAEA,AAAQ,UAAU,WAAyB;EACzC,KAAK,cACH,IAAI,YAAY,WAAW;GAAE,SAAS;GAAM,UAAU;EAAK,CAAC,CAC9D;CACF;CAEA,AAAQ,mBAAyB;EAC/B,KAAK,iBAAiB;EACtB,KAAK,cAAc,iBAAiB;GAClC,KAAK,oBAAoB;GACzB,KAAK,mBAAmB;GACxB,KAAK,UAAU,gBAAgB;EACjC,GAAG,KAAK,cAAc;CACxB;CAEA,AAAQ,oBAA0B;EAChC,KAAK,aAAa;EAClB,KAAK,mBAAmB;EACxB,KAAK,UAAU,gBAAgB;CACjC;CAEA,AAAQ,wBAA8B;EACpC,IAAI,KAAK,YAAY;GACnB,KAAK,aAAa;GAClB,KAAK,UAAU,kBAAkB;EACnC;EACA,KAAK,iBAAiB;EACtB,KAAK,mBAAmB;CAC1B;CAEA,AAAQ,aAAa,GAAqB;EACxC,IAAI,KAAK,gBAAgB,KAAK,mBAAmB;GAC/C,EAAE,eAAe;GACjB,EAAE,gBAAgB;EACpB;CACF;CAEA,AAAQ,cAAoB;EAC1B,KAAK,oBAAoB;EACzB,KAAK,mBAAmB;CAC1B;AACF;;;;;;AAOA,MAAa,+BAAqC;CAChD,IAAI,OAAO,mBAAmB,aAAa;CAC3C,IAAI,CAAC,eAAe,IAAI,2BAA2B,GACjD,eAAe,OACb,6BACA,8BACF;CAEF,qCAAqC;AACvC"}
1
+ {"version":3,"file":"ContentSelector.mjs","names":[],"sources":["../../../src/components/ContentSelector.ts"],"sourcesContent":["import { isSelectionClick, markSelectionClick } from '../core/selectionClick';\nimport { defineIntlayerContentSelectorWrapper } from './ContentSelectorWrapper';\nimport { isInteractiveClickTarget } from './isInteractiveClickTarget';\n\nconst DEFAULT_PRESS_DURATION = 250;\n\nconst STYLES = `\n :host {\n display: contents;\n }\n\n .wrapper {\n display: inline-block;\n cursor: pointer;\n user-select: none;\n border-radius: 0.375rem;\n outline-width: 2px;\n outline-offset: 4px;\n outline-style: solid;\n outline-color: transparent;\n transition: all 100ms 50ms ease-in-out;\n }\n\n .wrapper[data-active] {\n outline-color: inherit;\n }\n\n /*\n * Text content wraps over several lines: an outline would frame the whole\n * block, so each line fragment gets its own ring instead. The padding keeps\n * the ring 4px away from the text, the negative margin cancels its layout.\n */\n .wrapper[data-text] {\n display: inline;\n outline: none;\n padding: 4px;\n margin: -4px;\n box-shadow: 0 0 0 2px transparent;\n -webkit-box-decoration-break: clone;\n box-decoration-break: clone;\n }\n\n .wrapper[data-text][data-active] {\n box-shadow: 0 0 0 2px currentColor;\n }\n`;\n\n/**\n * Whether the slotted content is only text, so it can be rendered inline and\n * highlighted line by line. Elements (markdown blocks, framework nodes) may\n * not lay out inline, and fall back to the outline.\n */\nconst isTextOnlyContent = (slot: HTMLSlotElement): boolean => {\n const assignedNodes = slot.assignedNodes({ flatten: true });\n\n return (\n assignedNodes.length > 0 &&\n assignedNodes.every((node) => node.nodeType === Node.TEXT_NODE)\n );\n};\n\nconst _HTMLElement =\n typeof HTMLElement !== 'undefined'\n ? HTMLElement\n : (class {} as unknown as typeof HTMLElement);\n\n/**\n * <intlayer-content-selector>\n *\n * A framework-agnostic web component that wraps content with Intlayer editor\n * selection UI (hover outline, click to select, click-outside to deselect).\n *\n * Content is selected by:\n * - a click, unless it lands on something the app handles (link, button,\n * form control, clickable ancestor), which keeps its behavior\n * - a long press, on any content\n * - a ⌘ / Ctrl + click, on any content, cancelling the click's own action\n *\n * @fires intlayer:press - Fired when the content is selected. Bubbles.\n * @fires intlayer:hover - Fired on mouseenter. Bubbles.\n * @fires intlayer:unhover - Fired on mouseleave / mouseup. Bubbles.\n * @fires intlayer:click-outside - Fired when a click occurs outside the element. Bubbles.\n *\n * @prop {boolean} isSelecting - Whether this element is currently selected (external state)\n * @prop {number} pressDuration - Long-press threshold in ms. Default: 250\n */\nexport class IntlayerContentSelectorElement extends _HTMLElement {\n private _isSelecting = false;\n private _pressDuration = DEFAULT_PRESS_DURATION;\n private _isHovered = false;\n private _isSelectingState = false;\n private _wrapper: HTMLSpanElement;\n private _pressTimer: ReturnType<typeof setTimeout> | null = null;\n private _clickOutsideHandler: ((e: Event) => void) | null = null;\n\n static get observedAttributes(): string[] {\n return ['is-selecting', 'press-duration'];\n }\n\n get isSelecting(): boolean {\n return this._isSelecting;\n }\n set isSelecting(v: boolean) {\n this._isSelecting = v;\n this._updateActiveState();\n }\n\n get pressDuration(): number {\n return this._pressDuration;\n }\n set pressDuration(v: number) {\n this._pressDuration = v;\n }\n\n constructor() {\n super();\n const shadow = this.attachShadow({ mode: 'open' });\n\n const style = document.createElement('style');\n style.textContent = STYLES;\n shadow.appendChild(style);\n\n const wrapper = document.createElement('span');\n wrapper.className = 'wrapper';\n wrapper.setAttribute('role', 'button');\n wrapper.setAttribute('tabindex', '0');\n const slot = document.createElement('slot');\n wrapper.appendChild(slot);\n shadow.appendChild(wrapper);\n this._wrapper = wrapper;\n\n slot.addEventListener('slotchange', () =>\n wrapper.toggleAttribute('data-text', isTextOnlyContent(slot))\n );\n\n wrapper.addEventListener('mousedown', () => this._handleMouseDown());\n wrapper.addEventListener('mouseup', () => this._handleMouseUpOrLeave());\n wrapper.addEventListener('mouseleave', () => this._handleMouseUpOrLeave());\n wrapper.addEventListener('mouseenter', () => this._handleMouseEnter());\n wrapper.addEventListener('click', (e) => this._handleClick(e));\n wrapper.addEventListener('touchstart', () => this._handleMouseDown());\n wrapper.addEventListener('touchend', () => this._handleMouseUpOrLeave());\n wrapper.addEventListener('touchcancel', () => this._handleMouseUpOrLeave());\n wrapper.addEventListener('blur', () => this._handleBlur());\n }\n\n attributeChangedCallback(\n name: string,\n _oldVal: string | null,\n newVal: string | null\n ): void {\n if (name === 'is-selecting') {\n this._isSelecting = newVal !== null;\n this._updateActiveState();\n } else if (name === 'press-duration') {\n this._pressDuration =\n newVal !== null ? parseInt(newVal, 10) : DEFAULT_PRESS_DURATION;\n }\n }\n\n connectedCallback(): void {\n this._clickOutsideHandler = (e: Event) => {\n if (!this._isSelecting && !this._isSelectingState) return;\n\n // composedPath() pierces shadow boundaries\n if (!e.composedPath().includes(this)) {\n this._clearPressTimer();\n this._isSelectingState = false;\n this._isSelecting = false;\n this.removeAttribute('is-selecting');\n this._dispatch('intlayer:click-outside', { originalEvent: e });\n this._updateActiveState();\n }\n };\n document.addEventListener('mousedown', this._clickOutsideHandler);\n document.addEventListener('touchstart', this._clickOutsideHandler);\n }\n\n disconnectedCallback(): void {\n if (this._clickOutsideHandler) {\n document.removeEventListener('mousedown', this._clickOutsideHandler);\n document.removeEventListener('touchstart', this._clickOutsideHandler);\n this._clickOutsideHandler = null;\n }\n this._clearPressTimer();\n }\n\n private _updateActiveState(): void {\n const isActive =\n this._isSelecting || this._isSelectingState || this._isHovered;\n if (isActive) {\n this._wrapper.setAttribute('data-active', '');\n } else {\n this._wrapper.removeAttribute('data-active');\n }\n }\n\n private _clearPressTimer(): void {\n if (this._pressTimer !== null) {\n clearTimeout(this._pressTimer);\n this._pressTimer = null;\n }\n }\n\n private _dispatch(eventName: string, detail?: unknown): void {\n this.dispatchEvent(\n new CustomEvent(eventName, { detail, bubbles: true, composed: true })\n );\n }\n\n private _select(): void {\n this._clearPressTimer();\n this._isSelectingState = true;\n this._updateActiveState();\n this._dispatch('intlayer:press');\n }\n\n private _handleMouseDown(): void {\n this._clearPressTimer();\n this._pressTimer = setTimeout(() => this._select(), this._pressDuration);\n }\n\n private _handleMouseEnter(): void {\n this._isHovered = true;\n this._updateActiveState();\n this._dispatch('intlayer:hover');\n }\n\n private _handleMouseUpOrLeave(): void {\n if (this._isHovered) {\n this._isHovered = false;\n this._dispatch('intlayer:unhover');\n }\n this._clearPressTimer();\n this._updateActiveState();\n }\n\n private _handleClick(event: MouseEvent): void {\n // A nested selector already selected its own content\n if (isSelectionClick(event)) return;\n\n const isModifierClick = event.metaKey || event.ctrlKey;\n\n // Selected content (by a long press, or from the editor) and modifier\n // clicks never reach the app, so a link or button doesn't fire\n if (this._isSelecting || this._isSelectingState || isModifierClick) {\n event.preventDefault();\n event.stopPropagation();\n\n if (isModifierClick) this._select();\n return;\n }\n\n if (isInteractiveClickTarget(event)) return;\n\n // Left to propagate: the app's own handlers still run\n markSelectionClick(event);\n this._select();\n }\n\n private _handleBlur(): void {\n this._isSelectingState = false;\n this._updateActiveState();\n }\n}\n\n/**\n * Register all Intlayer custom elements.\n * Call this once at application startup (inside IntlayerEditorProvider or similar).\n * Safe to call multiple times — only registers elements that are not yet defined.\n */\nexport const defineIntlayerElements = (): void => {\n if (typeof customElements === 'undefined') return;\n if (!customElements.get('intlayer-content-selector')) {\n customElements.define(\n 'intlayer-content-selector',\n IntlayerContentSelectorElement\n );\n }\n defineIntlayerContentSelectorWrapper();\n};\n"],"mappings":";;;;;AAIA,MAAM,yBAAyB;AAE/B,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8Cf,MAAM,qBAAqB,SAAmC;CAC5D,MAAM,gBAAgB,KAAK,cAAc,EAAE,SAAS,KAAK,CAAC;CAE1D,OACE,cAAc,SAAS,KACvB,cAAc,OAAO,SAAS,KAAK,aAAa,KAAK,SAAS;AAElE;AAEA,MAAM,eACJ,OAAO,gBAAgB,cACnB,cACC,MAAM,CAAC;;;;;;;;;;;;;;;;;;;;;AAsBd,IAAa,iCAAb,cAAoD,aAAa;CAC/D,AAAQ,eAAe;CACvB,AAAQ,iBAAiB;CACzB,AAAQ,aAAa;CACrB,AAAQ,oBAAoB;CAC5B,AAAQ;CACR,AAAQ,cAAoD;CAC5D,AAAQ,uBAAoD;CAE5D,WAAW,qBAA+B;EACxC,OAAO,CAAC,gBAAgB,gBA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B;EACtB,KAAK,cAAc,iBAAiB,KAAK,QAAQ,GAAG,KAAK,cAAc;CACzE;CAEA,AAAQ,oBAA0B;EAChC,KAAK,aAAa;EAClB,KAAK,mBAAmB;EACxB,KAAK,UAAU,gBAAgB;CACjC;CAEA,AAAQ,wBAA8B;EACpC,IAAI,KAAK,YAAY;GACnB,KAAK,aAAa;GAClB,KAAK,UAAU,kBAAkB;EACnC;EACA,KAAK,iBAAiB;EACtB,KAAK,mBAAmB;CAC1B;CAEA,AAAQ,aAAa,OAAyB;EAE5C,IAAI,iBAAiB,KAAK,GAAG;EAE7B,MAAM,kBAAkB,MAAM,WAAW,MAAM;EAI/C,IAAI,KAAK,gBAAgB,KAAK,qBAAqB,iBAAiB;GAClE,MAAM,eAAe;GACrB,MAAM,gBAAgB;GAEtB,IAAI,iBAAiB,KAAK,QAAQ;GAClC;EACF;EAEA,IAAI,yBAAyB,KAAK,GAAG;EAGrC,mBAAmB,KAAK;EACxB,KAAK,QAAQ;CACf;CAEA,AAAQ,cAAoB;EAC1B,KAAK,oBAAoB;EACzB,KAAK,mBAAmB;CAC1B;AACF;;;;;;AAOA,MAAa,+BAAqC;CAChD,IAAI,OAAO,mBAAmB,aAAa;CAC3C,IAAI,CAAC,eAAe,IAAI,2BAA2B,GACjD,eAAe,OACb,6BACA,8BACF;CAEF,qCAAqC;AACvC"}
@@ -1,9 +1,9 @@
1
- import { MessageKey } from "../messageKey.mjs";
2
1
  import { getGlobalEditorManager, onGlobalEditorManagerChange } from "../core/globalManager.mjs";
2
+ import { MessageKey } from "../messageKey.mjs";
3
3
  import { isSameKeyPath } from "@intlayer/core/utils";
4
4
  import * as NodeTypes from "@intlayer/types/nodeType";
5
5
 
6
- //#region src/components/ContentSelectorWrapper.ts
6
+ // src/components/ContentSelectorWrapper.ts
7
7
  /**
8
8
  * Share of the viewport height left above content scrolled into view (30vh),
9
9
  * keeping it clear of fixed navbars.
@@ -34,6 +34,34 @@ const getPendingRevealOffset = (element) => {
34
34
  }
35
35
  return offset;
36
36
  };
37
+ /**
38
+ * Reveal callbacks of the wrappers selected by the current focus change, keyed
39
+ * by wrapper. A focus matches every wrapper under its key path (list items,
40
+ * content rendered twice…), so they are batched and only the first is revealed.
41
+ */
42
+ const pendingReveals = /* @__PURE__ */ new Map();
43
+ /** Whether `element` comes after `reference` in document order. */
44
+ const isAfterInDocument = (element, reference) => {
45
+ const position = reference.compareDocumentPosition(element);
46
+ if (position & Node.DOCUMENT_POSITION_DISCONNECTED) return true;
47
+ return Boolean(position & Node.DOCUMENT_POSITION_FOLLOWING);
48
+ };
49
+ /** Reveals the first wrapper, in document order, among the pending ones. */
50
+ const flushPendingReveals = () => {
51
+ let firstWrapper = null;
52
+ for (const wrapper of pendingReveals.keys()) {
53
+ if (!wrapper.isConnected) continue;
54
+ if (!firstWrapper || !isAfterInDocument(wrapper, firstWrapper)) firstWrapper = wrapper;
55
+ }
56
+ const reveal = firstWrapper ? pendingReveals.get(firstWrapper) : void 0;
57
+ pendingReveals.clear();
58
+ reveal?.();
59
+ };
60
+ /** Queues a wrapper to reveal once every wrapper handled the focus change. */
61
+ const scheduleReveal = (wrapper, reveal) => {
62
+ if (pendingReveals.size === 0) queueMicrotask(flushPendingReveals);
63
+ pendingReveals.set(wrapper, reveal);
64
+ };
37
65
  const _HTMLElement = typeof HTMLElement !== "undefined" ? HTMLElement : class {};
38
66
  /**
39
67
  * <intlayer-content-selector-wrapper>
@@ -64,6 +92,12 @@ var IntlayerContentSelectorWrapperElement = class extends _HTMLElement {
64
92
  static get observedAttributes() {
65
93
  return ["key-path", "dictionary-key"];
66
94
  }
95
+ get dictionaryKey() {
96
+ return this._dictionaryKey;
97
+ }
98
+ get filteredKeyPath() {
99
+ return this._getFilteredKeyPath();
100
+ }
67
101
  constructor() {
68
102
  super();
69
103
  const shadow = this.attachShadow({ mode: "open" });
@@ -123,6 +157,7 @@ var IntlayerContentSelectorWrapperElement = class extends _HTMLElement {
123
157
  _updateIsSelected(focusedContent) {
124
158
  if (!focusedContent) {
125
159
  this._isSelected = false;
160
+ pendingReveals.delete(this);
126
161
  this._updateSelectorAttr();
127
162
  return;
128
163
  }
@@ -130,7 +165,8 @@ var IntlayerContentSelectorWrapperElement = class extends _HTMLElement {
130
165
  const wasSelected = this._isSelected;
131
166
  this._isSelected = focusedContent.dictionaryKey === this._dictionaryKey && (focusedContent.keyPath?.length ?? 0) > 0 && isSameKeyPath(focusedContent.keyPath ?? [], keyPath);
132
167
  this._updateSelectorAttr();
133
- if (this._isSelected && !wasSelected) this._scrollIntoViewIfNeeded();
168
+ if (this._isSelected && !wasSelected) scheduleReveal(this, () => this._scrollIntoViewIfNeeded());
169
+ else if (!this._isSelected) pendingReveals.delete(this);
134
170
  }
135
171
  /**
136
172
  * Scrolls the selected content to 30vh, unless it is already fully visible
@@ -221,6 +257,27 @@ var IntlayerContentSelectorWrapperElement = class extends _HTMLElement {
221
257
  e.stopPropagation();
222
258
  getGlobalEditorManager()?.messenger.send(`${"INTLAYER_HOVERED_CONTENT_CHANGED"}/post`, null);
223
259
  }
260
+ _handleClickOutside(e) {
261
+ e.stopPropagation();
262
+ if (e.target !== this._selector) return;
263
+ if (!this._isSelected) return;
264
+ const originalEvent = e.detail?.originalEvent;
265
+ if (originalEvent) {
266
+ if (originalEvent.composedPath().some((target) => {
267
+ if (target instanceof HTMLElement && target.tagName === "INTLAYER-CONTENT-SELECTOR-WRAPPER") {
268
+ const wrapper = target;
269
+ return wrapper.dictionaryKey === this._dictionaryKey && isSameKeyPath(wrapper.filteredKeyPath, this._getFilteredKeyPath());
270
+ }
271
+ return false;
272
+ })) {
273
+ this._selector?.setAttribute("is-selecting", "");
274
+ return;
275
+ }
276
+ }
277
+ const manager = getGlobalEditorManager();
278
+ if (!manager) return;
279
+ manager.focusedContent.set(null);
280
+ }
224
281
  _render() {
225
282
  const useWrapper = this._isInIframe && this._editorEnabled;
226
283
  const editedValue = this._editedValue;
@@ -246,6 +303,7 @@ var IntlayerContentSelectorWrapperElement = class extends _HTMLElement {
246
303
  selector.addEventListener("intlayer:press", (e) => this._handlePress(e));
247
304
  selector.addEventListener("intlayer:hover", (e) => this._handleHover(e));
248
305
  selector.addEventListener("intlayer:unhover", (e) => this._handleUnhover(e));
306
+ selector.addEventListener("intlayer:click-outside", (e) => this._handleClickOutside(e));
249
307
  if (state === "wrapped-text") selector.appendChild(document.createTextNode(String(this._editedValue)));
250
308
  else selector.appendChild(document.createElement("slot"));
251
309
  shadow.appendChild(selector);
@@ -258,6 +316,5 @@ const defineIntlayerContentSelectorWrapper = () => {
258
316
  if (!customElements.get("intlayer-content-selector-wrapper")) customElements.define("intlayer-content-selector-wrapper", IntlayerContentSelectorWrapperElement);
259
317
  };
260
318
 
261
- //#endregion
262
319
  export { IntlayerContentSelectorWrapperElement, defineIntlayerContentSelectorWrapper };
263
320
  //# sourceMappingURL=ContentSelectorWrapper.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"ContentSelectorWrapper.mjs","names":["node"],"sources":["../../../src/components/ContentSelectorWrapper.ts"],"sourcesContent":["import { isSameKeyPath } from '@intlayer/core/utils';\n\nimport type { ContentNode } from '@intlayer/types/dictionary';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type { TypedNodeModel } from '@intlayer/types/nodeType';\nimport * as NodeTypes from '@intlayer/types/nodeType';\nimport type {\n EditorStateManager,\n FileContent,\n} from '../core/EditorStateManager';\nimport {\n getGlobalEditorManager,\n onGlobalEditorManagerChange,\n} from '../core/globalManager';\nimport { MessageKey } from '../messageKey';\n\ntype RenderState = 'simple' | 'wrapped-slot' | 'wrapped-text';\n\n/**\n * Share of the viewport height left above content scrolled into view (30vh),\n * keeping it clear of fixed navbars.\n */\nconst SCROLL_TOP_OFFSET_RATIO = 0.3;\n\n/** Parent in the flattened tree, crossing shadow roots up to their host. */\nconst getComposedParent = (element: Element): Element | null =>\n element.parentElement ??\n ((element.getRootNode() as ShadowRoot).host as Element | undefined) ??\n null;\n\n/** Vertical translation applied to an element, by `transform` or `translate`. */\nconst getTranslateY = (style: CSSStyleDeclaration): number => {\n const transformOffset =\n style.transform && style.transform !== 'none'\n ? new DOMMatrixReadOnly(style.transform).m42\n : 0;\n // `translate: <x> <y>` — a single value only moves along x\n const translateOffset = Number.parseFloat(\n style.translate?.split(' ')[1] ?? ''\n );\n\n return (\n transformOffset + (Number.isNaN(translateOffset) ? 0 : translateOffset)\n );\n};\n\n/**\n * Vertical offset the element will lose once its reveal animations end.\n *\n * Scroll-reveal effects (`whileInView`, AOS…) keep off-screen content\n * transparent and shifted until it enters the viewport, then slide it into\n * place: measuring it as-is would scroll too far by that shift. Only\n * translucent ancestors are counted, so permanent transforms (centering…)\n * stay part of the position.\n */\nconst getPendingRevealOffset = (element: Element): number => {\n let offset = 0;\n\n for (\n let ancestor: Element | null = element;\n ancestor;\n ancestor = getComposedParent(ancestor)\n ) {\n const style = getComputedStyle(ancestor);\n\n if (Number.parseFloat(style.opacity) < 1) offset += getTranslateY(style);\n }\n\n return offset;\n};\n\nconst _HTMLElement =\n typeof HTMLElement !== 'undefined'\n ? HTMLElement\n : (class {} as unknown as typeof HTMLElement);\n\n/**\n * <intlayer-content-selector-wrapper>\n *\n * Framework-agnostic web component that wraps content with the Intlayer editor\n * selection UI. It replaces the per-framework ContentSelectorWrapper components\n * (Vue, Svelte, Solid, Preact).\n *\n * It reads from the global EditorStateManager singleton (set by initEditorClient)\n * and conditionally renders <intlayer-content-selector> around its slot content\n * when the editor is active and the app is running inside an iframe.\n *\n * @attr {string} key-path - JSON-serialized KeyPath[] for this content node\n * @attr {string} dictionary-key - The dictionary key owning this content node\n */\nexport class IntlayerContentSelectorWrapperElement extends _HTMLElement {\n private _keyPathJson = '[]';\n private _dictionaryKey = '';\n private _editorEnabled = false;\n private _isInIframe = false;\n private _isSelected = false;\n private _editedValue: ContentNode | undefined = undefined;\n\n private _renderState: RenderState | null = null;\n private _selector: HTMLElement | null = null;\n\n private _unsubManager: (() => void) | null = null;\n /** Removes the listeners attached to the current manager's states */\n private _unsubManagerState: (() => void) | null = null;\n\n static get observedAttributes(): string[] {\n return ['key-path', 'dictionary-key'];\n }\n\n constructor() {\n super();\n const shadow = this.attachShadow({ mode: 'open' });\n const style = document.createElement('style');\n style.textContent = ':host { display: contents; }';\n shadow.appendChild(style);\n }\n\n attributeChangedCallback(\n name: string,\n _oldValue: string | null,\n newValue: string | null\n ): void {\n if (name === 'key-path') {\n this._keyPathJson = newValue ?? '[]';\n } else {\n this._dictionaryKey = newValue ?? '';\n }\n\n const manager = getGlobalEditorManager();\n if (manager) this._updateEditedValue(manager);\n }\n\n connectedCallback(): void {\n if (typeof window !== 'undefined') {\n this._isInIframe = window.self !== window.top;\n }\n this._subscribeToManager();\n this._render();\n }\n\n disconnectedCallback(): void {\n this._unsubManager?.();\n this._unsubManager = null;\n this._unsubManagerState?.();\n this._unsubManagerState = null;\n }\n\n private _getRawKeyPath(): KeyPath[] {\n try {\n return JSON.parse(this._keyPathJson) as KeyPath[];\n } catch {\n return [];\n }\n }\n\n private _getFilteredKeyPath(): KeyPath[] {\n return this._getRawKeyPath().filter(\n (keyPath) => keyPath.type !== NodeTypes.TRANSLATION\n );\n }\n\n private _updateEditedValue(manager: EditorStateManager): void {\n const filteredKeyPath = this._getFilteredKeyPath();\n if (!this._dictionaryKey || filteredKeyPath.length === 0) {\n this._editedValue = undefined;\n this._render();\n return;\n }\n\n // Node types whose display requires framework-level rendering (markdown,\n // HTML, insertion, file): do not override the slot — the framework handles\n // those. Only plain / translated strings can be substituted here.\n const rawKeyPath = this._getRawKeyPath();\n const lastStepType = rawKeyPath[rawKeyPath.length - 1]?.type;\n if (\n lastStepType === NodeTypes.MARKDOWN ||\n lastStepType === NodeTypes.HTML ||\n lastStepType === NodeTypes.INSERTION ||\n lastStepType === NodeTypes.FILE\n ) {\n this._editedValue = undefined;\n this._render();\n return;\n }\n\n let value = manager.getContentValue(this._dictionaryKey, filteredKeyPath);\n\n // getContentNodeByKeyPath resolves translation nodes only at intermediate\n // steps, not the final leaf. Resolve manually when the returned value is\n // still a translation object (happens when Translation steps are filtered\n // out and the leaf IS the translation object).\n if (\n value !== null &&\n value !== undefined &&\n typeof value === 'object' &&\n (value as { nodeType?: unknown }).nodeType === NodeTypes.TRANSLATION\n ) {\n const locale = manager.currentLocale.value as string | undefined;\n // TypedNodeModel<Translation, …> structurally satisfies TypedNode<BaseNode>\n // (both have nodeType), so this narrowing cast is sound.\n const node = value as TypedNodeModel<\n typeof NodeTypes.TRANSLATION,\n Record<string, ContentNode>\n >;\n value = locale ? node[NodeTypes.TRANSLATION][locale] : undefined;\n }\n\n this._editedValue = value;\n this._render();\n }\n\n private _updateIsSelected(\n focusedContent: FileContent | null | undefined\n ): void {\n if (!focusedContent) {\n this._isSelected = false;\n this._updateSelectorAttr();\n return;\n }\n const keyPath = this._getFilteredKeyPath();\n const wasSelected = this._isSelected;\n this._isSelected =\n focusedContent.dictionaryKey === this._dictionaryKey &&\n (focusedContent.keyPath?.length ?? 0) > 0 &&\n isSameKeyPath(focusedContent.keyPath ?? [], keyPath);\n this._updateSelectorAttr();\n\n // Reveal content the editor focuses while it is off-screen in the app\n if (this._isSelected && !wasSelected) {\n this._scrollIntoViewIfNeeded();\n }\n }\n\n /**\n * Scrolls the selected content to 30vh, unless it is already fully visible\n * in this frame's viewport.\n */\n private _scrollIntoViewIfNeeded(): void {\n // `.wrapper` is the only real box: this host and the selector are\n // `display: contents`. No selector means the editor UI is inactive.\n const target = this._selector?.shadowRoot?.querySelector('.wrapper');\n if (!target) return;\n\n const rect = target.getBoundingClientRect();\n // Where the content settles once revealed\n const top = rect.top - getPendingRevealOffset(target);\n const bottom = top + rect.height;\n\n const isFullyVisible = top >= 0 && bottom <= window.innerHeight;\n if (\n isFullyVisible &&\n !this._isCoveredAt((rect.left + rect.right) / 2, top + 1)\n ) {\n return;\n }\n\n window.scrollBy({\n top: top - window.innerHeight * SCROLL_TOP_OFFSET_RATIO,\n behavior: 'smooth',\n });\n }\n\n /**\n * Whether another element (a fixed navbar, a sticky header…) is painted over\n * this content at the given viewport point.\n */\n private _isCoveredAt(x: number, y: number): boolean {\n // Query from this element's own root so apps rendered in a shadow root\n // (Lit…) don't get their outer host back\n const root = this.getRootNode() as Document | ShadowRoot;\n if (typeof root.elementFromPoint !== 'function') return false;\n\n const topElement = root.elementFromPoint(x, y);\n\n return Boolean(topElement) && !this.contains(topElement);\n }\n\n private _updateSelectorAttr(): void {\n if (!this._selector) return;\n if (this._isSelected) {\n this._selector.setAttribute('is-selecting', '');\n } else {\n this._selector.removeAttribute('is-selecting');\n }\n }\n\n private _subscribeToManager(): void {\n const manager = getGlobalEditorManager();\n if (manager) {\n this._setupManagerSubscriptions(manager);\n }\n // Keep listening for manager changes (handles stop + re-init cycles)\n this._unsubManager = onGlobalEditorManagerChange((nextManager) => {\n this._unsubManagerState?.();\n this._unsubManagerState = null;\n if (nextManager) {\n this._setupManagerSubscriptions(nextManager);\n } else {\n this._editorEnabled = false;\n this._isSelected = false;\n this._editedValue = undefined;\n this._render();\n }\n });\n }\n\n private _setupManagerSubscriptions(manager: EditorStateManager): void {\n this._editorEnabled = manager.editorEnabled.value ?? false;\n this._updateIsSelected(manager.focusedContent.value);\n this._updateEditedValue(manager);\n\n const handleEnabledChange = (e: Event) => {\n this._editorEnabled = (e as CustomEvent<boolean>).detail;\n this._render();\n };\n const handleFocusedChange = (e: Event) => {\n this._updateIsSelected((e as CustomEvent<FileContent | null>).detail);\n };\n const handleEditedContentChange = () => {\n this._updateEditedValue(manager);\n };\n\n manager.editorEnabled.addEventListener('change', handleEnabledChange);\n manager.focusedContent.addEventListener('change', handleFocusedChange);\n manager.editedContent.addEventListener('change', handleEditedContentChange);\n\n this._unsubManagerState = () => {\n manager.editorEnabled.removeEventListener('change', handleEnabledChange);\n manager.focusedContent.removeEventListener('change', handleFocusedChange);\n manager.editedContent.removeEventListener(\n 'change',\n handleEditedContentChange\n );\n };\n }\n\n private _handlePress(e: Event): void {\n // Stop propagation so nested wrappers don't also fire (composed + bubbles)\n e.stopPropagation();\n const manager = getGlobalEditorManager();\n if (!manager) return;\n manager.focusedContent.set({\n dictionaryKey: this._dictionaryKey,\n keyPath: this._getFilteredKeyPath(),\n });\n }\n\n private _handleHover(e: Event): void {\n e.stopPropagation();\n getGlobalEditorManager()?.messenger.send(\n `${MessageKey.INTLAYER_HOVERED_CONTENT_CHANGED}/post`,\n {\n dictionaryKey: this._dictionaryKey,\n keyPath: this._getFilteredKeyPath(),\n }\n );\n }\n\n private _handleUnhover(e: Event): void {\n e.stopPropagation();\n getGlobalEditorManager()?.messenger.send(\n `${MessageKey.INTLAYER_HOVERED_CONTENT_CHANGED}/post`,\n null\n );\n }\n\n private _render(): void {\n const useWrapper = this._isInIframe && this._editorEnabled;\n const editedValue = this._editedValue;\n const isSimpleValue =\n typeof editedValue === 'string' ||\n typeof editedValue === 'number' ||\n typeof editedValue === 'boolean';\n\n const newState: RenderState = !useWrapper\n ? 'simple'\n : isSimpleValue\n ? 'wrapped-text'\n : 'wrapped-slot';\n\n if (this._renderState !== newState) {\n this._rebuildContent(newState);\n return;\n }\n\n // Structure unchanged — update only dynamic parts\n if (newState !== 'simple' && this._selector) {\n this._updateSelectorAttr();\n if (\n newState === 'wrapped-text' &&\n this._selector.firstChild?.nodeType === Node.TEXT_NODE\n ) {\n (this._selector.firstChild as Text).data = String(editedValue);\n }\n }\n }\n\n private _rebuildContent(state: RenderState): void {\n const shadow = this.shadowRoot!;\n // Remove all nodes except the style element (first child)\n while (shadow.childNodes.length > 1) {\n shadow.removeChild(shadow.lastChild!);\n }\n this._selector = null;\n\n if (state === 'simple') {\n shadow.appendChild(document.createElement('slot'));\n } else {\n const selector = document.createElement('intlayer-content-selector');\n this._selector = selector;\n if (this._isSelected) selector.setAttribute('is-selecting', '');\n selector.addEventListener('intlayer:press', (e) => this._handlePress(e));\n selector.addEventListener('intlayer:hover', (e) => this._handleHover(e));\n selector.addEventListener('intlayer:unhover', (e) =>\n this._handleUnhover(e)\n );\n\n if (state === 'wrapped-text') {\n selector.appendChild(\n document.createTextNode(String(this._editedValue))\n );\n } else {\n selector.appendChild(document.createElement('slot'));\n }\n shadow.appendChild(selector);\n }\n\n this._renderState = state;\n }\n}\n\nexport const defineIntlayerContentSelectorWrapper = (): void => {\n if (typeof customElements === 'undefined') return;\n\n if (!customElements.get('intlayer-content-selector-wrapper')) {\n customElements.define(\n 'intlayer-content-selector-wrapper',\n IntlayerContentSelectorWrapperElement\n );\n }\n};\n"],"mappings":";;;;;;;;;;AAsBA,MAAM,0BAA0B;;AAGhC,MAAM,qBAAqB,YACzB,QAAQ,iBACN,QAAQ,YAAY,CAAC,CAAgB,QACvC;;AAGF,MAAM,iBAAiB,UAAuC;CAC5D,MAAM,kBACJ,MAAM,aAAa,MAAM,cAAc,SACnC,IAAI,kBAAkB,MAAM,SAAS,CAAC,CAAC,MACvC;CAEN,MAAM,kBAAkB,OAAO,WAC7B,MAAM,WAAW,MAAM,GAAG,CAAC,CAAC,MAAM,EACpC;CAEA,OACE,mBAAmB,OAAO,MAAM,eAAe,IAAI,IAAI;AAE3D;;;;;;;;;;AAWA,MAAM,0BAA0B,YAA6B;CAC3D,IAAI,SAAS;CAEb,KACE,IAAI,WAA2B,SAC/B,UACA,WAAW,kBAAkB,QAAQ,GACrC;EACA,MAAM,QAAQ,iBAAiB,QAAQ;EAEvC,IAAI,OAAO,WAAW,MAAM,OAAO,IAAI,GAAG,UAAU,cAAc,KAAK;CACzE;CAEA,OAAO;AACT;AAEA,MAAM,eACJ,OAAO,gBAAgB,cACnB,cACC,MAAM,CAAC;;;;;;;;;;;;;;;AAgBd,IAAa,wCAAb,cAA2D,aAAa;CACtE,AAAQ,eAAe;CACvB,AAAQ,iBAAiB;CACzB,AAAQ,iBAAiB;CACzB,AAAQ,cAAc;CACtB,AAAQ,cAAc;CACtB,AAAQ,eAAwC;CAEhD,AAAQ,eAAmC;CAC3C,AAAQ,YAAgC;CAExC,AAAQ,gBAAqC;;CAE7C,AAAQ,qBAA0C;CAElD,WAAW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YAAY,CAAC,CACnD;QAEA,SAAS,YAAY,SAAS,cAAc,MAAM,CAAC;GAErD,OAAO,YAAY,QAAQ;EAC7B;EAEA,KAAK,eAAe;CACtB;AACF;AAEA,MAAa,6CAAmD;CAC9D,IAAI,OAAO,mBAAmB,aAAa;CAE3C,IAAI,CAAC,eAAe,IAAI,mCAAmC,GACzD,eAAe,OACb,qCACA,qCACF;AAEJ"}
1
+ {"version":3,"file":"ContentSelectorWrapper.mjs","names":["node","customEvent"],"sources":["../../../src/components/ContentSelectorWrapper.ts"],"sourcesContent":["import { isSameKeyPath } from '@intlayer/core/utils';\n\nimport type { ContentNode } from '@intlayer/types/dictionary';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type { TypedNodeModel } from '@intlayer/types/nodeType';\nimport * as NodeTypes from '@intlayer/types/nodeType';\nimport type {\n EditorStateManager,\n FileContent,\n} from '../core/EditorStateManager';\nimport {\n getGlobalEditorManager,\n onGlobalEditorManagerChange,\n} from '../core/globalManager';\nimport { MessageKey } from '../messageKey';\n\ntype RenderState = 'simple' | 'wrapped-slot' | 'wrapped-text';\n\n/**\n * Share of the viewport height left above content scrolled into view (30vh),\n * keeping it clear of fixed navbars.\n */\nconst SCROLL_TOP_OFFSET_RATIO = 0.3;\n\n/** Parent in the flattened tree, crossing shadow roots up to their host. */\nconst getComposedParent = (element: Element): Element | null =>\n element.parentElement ??\n ((element.getRootNode() as ShadowRoot).host as Element | undefined) ??\n null;\n\n/** Vertical translation applied to an element, by `transform` or `translate`. */\nconst getTranslateY = (style: CSSStyleDeclaration): number => {\n const transformOffset =\n style.transform && style.transform !== 'none'\n ? new DOMMatrixReadOnly(style.transform).m42\n : 0;\n // `translate: <x> <y>` — a single value only moves along x\n const translateOffset = Number.parseFloat(\n style.translate?.split(' ')[1] ?? ''\n );\n\n return (\n transformOffset + (Number.isNaN(translateOffset) ? 0 : translateOffset)\n );\n};\n\n/**\n * Vertical offset the element will lose once its reveal animations end.\n *\n * Scroll-reveal effects (`whileInView`, AOS…) keep off-screen content\n * transparent and shifted until it enters the viewport, then slide it into\n * place: measuring it as-is would scroll too far by that shift. Only\n * translucent ancestors are counted, so permanent transforms (centering…)\n * stay part of the position.\n */\nconst getPendingRevealOffset = (element: Element): number => {\n let offset = 0;\n\n for (\n let ancestor: Element | null = element;\n ancestor;\n ancestor = getComposedParent(ancestor)\n ) {\n const style = getComputedStyle(ancestor);\n\n if (Number.parseFloat(style.opacity) < 1) offset += getTranslateY(style);\n }\n\n return offset;\n};\n\n/**\n * Reveal callbacks of the wrappers selected by the current focus change, keyed\n * by wrapper. A focus matches every wrapper under its key path (list items,\n * content rendered twice…), so they are batched and only the first is revealed.\n */\nconst pendingReveals = new Map<Element, () => void>();\n\n/** Whether `element` comes after `reference` in document order. */\nconst isAfterInDocument = (element: Element, reference: Element): boolean => {\n const position = reference.compareDocumentPosition(element);\n\n // Across unrelated trees the order is arbitrary: keep the earlier selection\n if (position & Node.DOCUMENT_POSITION_DISCONNECTED) return true;\n\n return Boolean(position & Node.DOCUMENT_POSITION_FOLLOWING);\n};\n\n/** Reveals the first wrapper, in document order, among the pending ones. */\nconst flushPendingReveals = (): void => {\n let firstWrapper: Element | null = null;\n\n for (const wrapper of pendingReveals.keys()) {\n if (!wrapper.isConnected) continue;\n if (!firstWrapper || !isAfterInDocument(wrapper, firstWrapper)) {\n firstWrapper = wrapper;\n }\n }\n\n const reveal = firstWrapper ? pendingReveals.get(firstWrapper) : undefined;\n pendingReveals.clear();\n reveal?.();\n};\n\n/** Queues a wrapper to reveal once every wrapper handled the focus change. */\nconst scheduleReveal = (wrapper: Element, reveal: () => void): void => {\n if (pendingReveals.size === 0) queueMicrotask(flushPendingReveals);\n pendingReveals.set(wrapper, reveal);\n};\n\nconst _HTMLElement =\n typeof HTMLElement !== 'undefined'\n ? HTMLElement\n : (class {} as unknown as typeof HTMLElement);\n\n/**\n * <intlayer-content-selector-wrapper>\n *\n * Framework-agnostic web component that wraps content with the Intlayer editor\n * selection UI. It replaces the per-framework ContentSelectorWrapper components\n * (Vue, Svelte, Solid, Preact).\n *\n * It reads from the global EditorStateManager singleton (set by initEditorClient)\n * and conditionally renders <intlayer-content-selector> around its slot content\n * when the editor is active and the app is running inside an iframe.\n *\n * @attr {string} key-path - JSON-serialized KeyPath[] for this content node\n * @attr {string} dictionary-key - The dictionary key owning this content node\n */\nexport class IntlayerContentSelectorWrapperElement extends _HTMLElement {\n private _keyPathJson = '[]';\n private _dictionaryKey = '';\n private _editorEnabled = false;\n private _isInIframe = false;\n private _isSelected = false;\n private _editedValue: ContentNode | undefined = undefined;\n\n private _renderState: RenderState | null = null;\n private _selector: HTMLElement | null = null;\n\n private _unsubManager: (() => void) | null = null;\n /** Removes the listeners attached to the current manager's states */\n private _unsubManagerState: (() => void) | null = null;\n\n static get observedAttributes(): string[] {\n return ['key-path', 'dictionary-key'];\n }\n\n get dictionaryKey(): string {\n return this._dictionaryKey;\n }\n\n get filteredKeyPath(): KeyPath[] {\n return this._getFilteredKeyPath();\n }\n\n constructor() {\n super();\n const shadow = this.attachShadow({ mode: 'open' });\n const style = document.createElement('style');\n style.textContent = ':host { display: contents; }';\n shadow.appendChild(style);\n }\n\n attributeChangedCallback(\n name: string,\n _oldValue: string | null,\n newValue: string | null\n ): void {\n if (name === 'key-path') {\n this._keyPathJson = newValue ?? '[]';\n } else {\n this._dictionaryKey = newValue ?? '';\n }\n\n const manager = getGlobalEditorManager();\n if (manager) this._updateEditedValue(manager);\n }\n\n connectedCallback(): void {\n if (typeof window !== 'undefined') {\n this._isInIframe = window.self !== window.top;\n }\n this._subscribeToManager();\n this._render();\n }\n\n disconnectedCallback(): void {\n this._unsubManager?.();\n this._unsubManager = null;\n this._unsubManagerState?.();\n this._unsubManagerState = null;\n }\n\n private _getRawKeyPath(): KeyPath[] {\n try {\n return JSON.parse(this._keyPathJson) as KeyPath[];\n } catch {\n return [];\n }\n }\n\n private _getFilteredKeyPath(): KeyPath[] {\n return this._getRawKeyPath().filter(\n (keyPath) => keyPath.type !== NodeTypes.TRANSLATION\n );\n }\n\n private _updateEditedValue(manager: EditorStateManager): void {\n const filteredKeyPath = this._getFilteredKeyPath();\n if (!this._dictionaryKey || filteredKeyPath.length === 0) {\n this._editedValue = undefined;\n this._render();\n return;\n }\n\n // Node types whose display requires framework-level rendering (markdown,\n // HTML, insertion, file): do not override the slot — the framework handles\n // those. Only plain / translated strings can be substituted here.\n const rawKeyPath = this._getRawKeyPath();\n const lastStepType = rawKeyPath[rawKeyPath.length - 1]?.type;\n if (\n lastStepType === NodeTypes.MARKDOWN ||\n lastStepType === NodeTypes.HTML ||\n lastStepType === NodeTypes.INSERTION ||\n lastStepType === NodeTypes.FILE\n ) {\n this._editedValue = undefined;\n this._render();\n return;\n }\n\n let value = manager.getContentValue(this._dictionaryKey, filteredKeyPath);\n\n // getContentNodeByKeyPath resolves translation nodes only at intermediate\n // steps, not the final leaf. Resolve manually when the returned value is\n // still a translation object (happens when Translation steps are filtered\n // out and the leaf IS the translation object).\n if (\n value !== null &&\n value !== undefined &&\n typeof value === 'object' &&\n (value as { nodeType?: unknown }).nodeType === NodeTypes.TRANSLATION\n ) {\n const locale = manager.currentLocale.value as string | undefined;\n // TypedNodeModel<Translation, …> structurally satisfies TypedNode<BaseNode>\n // (both have nodeType), so this narrowing cast is sound.\n const node = value as TypedNodeModel<\n typeof NodeTypes.TRANSLATION,\n Record<string, ContentNode>\n >;\n value = locale ? node[NodeTypes.TRANSLATION][locale] : undefined;\n }\n\n this._editedValue = value;\n this._render();\n }\n\n private _updateIsSelected(\n focusedContent: FileContent | null | undefined\n ): void {\n if (!focusedContent) {\n this._isSelected = false;\n pendingReveals.delete(this);\n this._updateSelectorAttr();\n return;\n }\n const keyPath = this._getFilteredKeyPath();\n const wasSelected = this._isSelected;\n this._isSelected =\n focusedContent.dictionaryKey === this._dictionaryKey &&\n (focusedContent.keyPath?.length ?? 0) > 0 &&\n isSameKeyPath(focusedContent.keyPath ?? [], keyPath);\n this._updateSelectorAttr();\n\n // Reveal content the editor focuses while it is off-screen in the app\n if (this._isSelected && !wasSelected) {\n scheduleReveal(this, () => this._scrollIntoViewIfNeeded());\n } else if (!this._isSelected) {\n pendingReveals.delete(this);\n }\n }\n\n /**\n * Scrolls the selected content to 30vh, unless it is already fully visible\n * in this frame's viewport.\n */\n private _scrollIntoViewIfNeeded(): void {\n // `.wrapper` is the only real box: this host and the selector are\n // `display: contents`. No selector means the editor UI is inactive.\n const target = this._selector?.shadowRoot?.querySelector('.wrapper');\n if (!target) return;\n\n const rect = target.getBoundingClientRect();\n // Where the content settles once revealed\n const top = rect.top - getPendingRevealOffset(target);\n const bottom = top + rect.height;\n\n const isFullyVisible = top >= 0 && bottom <= window.innerHeight;\n if (\n isFullyVisible &&\n !this._isCoveredAt((rect.left + rect.right) / 2, top + 1)\n ) {\n return;\n }\n\n window.scrollBy({\n top: top - window.innerHeight * SCROLL_TOP_OFFSET_RATIO,\n behavior: 'smooth',\n });\n }\n\n /**\n * Whether another element (a fixed navbar, a sticky header…) is painted over\n * this content at the given viewport point.\n */\n private _isCoveredAt(x: number, y: number): boolean {\n // Query from this element's own root so apps rendered in a shadow root\n // (Lit…) don't get their outer host back\n const root = this.getRootNode() as Document | ShadowRoot;\n if (typeof root.elementFromPoint !== 'function') return false;\n\n const topElement = root.elementFromPoint(x, y);\n\n return Boolean(topElement) && !this.contains(topElement);\n }\n\n private _updateSelectorAttr(): void {\n if (!this._selector) return;\n if (this._isSelected) {\n this._selector.setAttribute('is-selecting', '');\n } else {\n this._selector.removeAttribute('is-selecting');\n }\n }\n\n private _subscribeToManager(): void {\n const manager = getGlobalEditorManager();\n if (manager) {\n this._setupManagerSubscriptions(manager);\n }\n // Keep listening for manager changes (handles stop + re-init cycles)\n this._unsubManager = onGlobalEditorManagerChange((nextManager) => {\n this._unsubManagerState?.();\n this._unsubManagerState = null;\n if (nextManager) {\n this._setupManagerSubscriptions(nextManager);\n } else {\n this._editorEnabled = false;\n this._isSelected = false;\n this._editedValue = undefined;\n this._render();\n }\n });\n }\n\n private _setupManagerSubscriptions(manager: EditorStateManager): void {\n this._editorEnabled = manager.editorEnabled.value ?? false;\n this._updateIsSelected(manager.focusedContent.value);\n this._updateEditedValue(manager);\n\n const handleEnabledChange = (e: Event) => {\n this._editorEnabled = (e as CustomEvent<boolean>).detail;\n this._render();\n };\n const handleFocusedChange = (e: Event) => {\n this._updateIsSelected((e as CustomEvent<FileContent | null>).detail);\n };\n const handleEditedContentChange = () => {\n this._updateEditedValue(manager);\n };\n\n manager.editorEnabled.addEventListener('change', handleEnabledChange);\n manager.focusedContent.addEventListener('change', handleFocusedChange);\n manager.editedContent.addEventListener('change', handleEditedContentChange);\n\n this._unsubManagerState = () => {\n manager.editorEnabled.removeEventListener('change', handleEnabledChange);\n manager.focusedContent.removeEventListener('change', handleFocusedChange);\n manager.editedContent.removeEventListener(\n 'change',\n handleEditedContentChange\n );\n };\n }\n\n private _handlePress(e: Event): void {\n // Stop propagation so nested wrappers don't also fire (composed + bubbles)\n e.stopPropagation();\n const manager = getGlobalEditorManager();\n if (!manager) return;\n manager.focusedContent.set({\n dictionaryKey: this._dictionaryKey,\n keyPath: this._getFilteredKeyPath(),\n });\n }\n\n private _handleHover(e: Event): void {\n e.stopPropagation();\n getGlobalEditorManager()?.messenger.send(\n `${MessageKey.INTLAYER_HOVERED_CONTENT_CHANGED}/post`,\n {\n dictionaryKey: this._dictionaryKey,\n keyPath: this._getFilteredKeyPath(),\n }\n );\n }\n\n private _handleUnhover(e: Event): void {\n e.stopPropagation();\n getGlobalEditorManager()?.messenger.send(\n `${MessageKey.INTLAYER_HOVERED_CONTENT_CHANGED}/post`,\n null\n );\n }\n\n private _handleClickOutside(e: Event): void {\n e.stopPropagation();\n if (e.target !== this._selector) return;\n if (!this._isSelected) return;\n\n const customEvent = e as CustomEvent<{ originalEvent?: Event }>;\n const originalEvent = customEvent.detail?.originalEvent;\n if (originalEvent) {\n const path = originalEvent.composedPath();\n const isClickedOnSameContent = path.some((target) => {\n if (\n target instanceof HTMLElement &&\n target.tagName === 'INTLAYER-CONTENT-SELECTOR-WRAPPER'\n ) {\n const wrapper = target as IntlayerContentSelectorWrapperElement;\n return (\n wrapper.dictionaryKey === this._dictionaryKey &&\n isSameKeyPath(wrapper.filteredKeyPath, this._getFilteredKeyPath())\n );\n }\n return false;\n });\n if (isClickedOnSameContent) {\n this._selector?.setAttribute('is-selecting', '');\n return;\n }\n }\n\n const manager = getGlobalEditorManager();\n if (!manager) return;\n manager.focusedContent.set(null);\n }\n\n private _render(): void {\n const useWrapper = this._isInIframe && this._editorEnabled;\n const editedValue = this._editedValue;\n const isSimpleValue =\n typeof editedValue === 'string' ||\n typeof editedValue === 'number' ||\n typeof editedValue === 'boolean';\n\n const newState: RenderState = !useWrapper\n ? 'simple'\n : isSimpleValue\n ? 'wrapped-text'\n : 'wrapped-slot';\n\n if (this._renderState !== newState) {\n this._rebuildContent(newState);\n return;\n }\n\n // Structure unchanged — update only dynamic parts\n if (newState !== 'simple' && this._selector) {\n this._updateSelectorAttr();\n if (\n newState === 'wrapped-text' &&\n this._selector.firstChild?.nodeType === Node.TEXT_NODE\n ) {\n (this._selector.firstChild as Text).data = String(editedValue);\n }\n }\n }\n\n private _rebuildContent(state: RenderState): void {\n const shadow = this.shadowRoot!;\n // Remove all nodes except the style element (first child)\n while (shadow.childNodes.length > 1) {\n shadow.removeChild(shadow.lastChild!);\n }\n this._selector = null;\n\n if (state === 'simple') {\n shadow.appendChild(document.createElement('slot'));\n } else {\n const selector = document.createElement('intlayer-content-selector');\n this._selector = selector;\n if (this._isSelected) selector.setAttribute('is-selecting', '');\n selector.addEventListener('intlayer:press', (e) => this._handlePress(e));\n selector.addEventListener('intlayer:hover', (e) => this._handleHover(e));\n selector.addEventListener('intlayer:unhover', (e) =>\n this._handleUnhover(e)\n );\n selector.addEventListener('intlayer:click-outside', (e) =>\n this._handleClickOutside(e)\n );\n\n if (state === 'wrapped-text') {\n selector.appendChild(\n document.createTextNode(String(this._editedValue))\n );\n } else {\n selector.appendChild(document.createElement('slot'));\n }\n shadow.appendChild(selector);\n }\n\n this._renderState = state;\n }\n}\n\nexport const defineIntlayerContentSelectorWrapper = (): void => {\n if (typeof customElements === 'undefined') return;\n\n if (!customElements.get('intlayer-content-selector-wrapper')) {\n customElements.define(\n 'intlayer-content-selector-wrapper',\n IntlayerContentSelectorWrapperElement\n );\n }\n};\n"],"mappings":";;;;;;;;;;AAsBA,MAAM,0BAA0B;;AAGhC,MAAM,qBAAqB,YACzB,QAAQ,iBACN,QAAQ,YAAY,CAAC,CAAgB,QACvC;;AAGF,MAAM,iBAAiB,UAAuC;CAC5D,MAAM,kBACJ,MAAM,aAAa,MAAM,cAAc,SACnC,IAAI,kBAAkB,MAAM,SAAS,CAAC,CAAC,MACvC;CAEN,MAAM,kBAAkB,OAAO,WAC7B,MAAM,WAAW,MAAM,GAAG,CAAC,CAAC,MAAM,EACpC;CAEA,OACE,mBAAmB,OAAO,MAAM,eAAe,IAAI,IAAI;AAE3D;;;;;;;;;;AAWA,MAAM,0BAA0B,YAA6B;CAC3D,IAAI,SAAS;CAEb,KACE,IAAI,WAA2B,SAC/B,UACA,WAAW,kBAAkB,QAAQ,GACrC;EACA,MAAM,QAAQ,iBAAiB,QAAQ;EAEvC,IAAI,OAAO,WAAW,MAAM,OAAO,IAAI,GAAG,UAAU,cAAc,KAAK;CACzE;CAEA,OAAO;AACT;;;;;;AAOA,MAAM,iCAAiB,IAAI,IAAyB;;AAGpD,MAAM,qBAAqB,SAAkB,cAAgC;CAC3E,MAAM,WAAW,UAAU,wBAAwB,OAAO;CAG1D,IAAI,WAAW,KAAK,gCAAgC,OAAO;CAE3D,OAAO,QAAQ,WAAW,KAAK,2BAA2B;AAC5D;;AAGA,MAAM,4BAAkC;CACtC,IAAI,eAA+B;CAEnC,KAAK,MAAM,WAAW,eAAe,KAAK,GAAG;EAC3C,IAAI,CAAC,QAAQ,aAAa;EAC1B,IAAI,CAAC,gBAAgB,CAAC,kBAAkB,SAA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,2BAA2B,MACnD,KAAK,oBAAoB,CAAC,CAC5B;GAEA,IAAI,UAAU,gBACZ,SAAS,YACP,SAAS,eAAe,OAAO,KAAK,YAAY,CAAC,CACnD;QAEA,SAAS,YAAY,SAAS,cAAc,MAAM,CAAC;GAErD,OAAO,YAAY,QAAQ;EAC7B;EAEA,KAAK,eAAe;CACtB;AACF;AAEA,MAAa,6CAAmD;CAC9D,IAAI,OAAO,mBAAmB,aAAa;CAE3C,IAAI,CAAC,eAAe,IAAI,mCAAmC,GACzD,eAAe,OACb,qCACA,qCACF;AAEJ"}
@@ -1,4 +1,4 @@
1
- import { IntlayerContentSelectorWrapperElement, defineIntlayerContentSelectorWrapper } from "./ContentSelectorWrapper.mjs";
2
1
  import { IntlayerContentSelectorElement, defineIntlayerElements } from "./ContentSelector.mjs";
2
+ import { IntlayerContentSelectorWrapperElement, defineIntlayerContentSelectorWrapper } from "./ContentSelectorWrapper.mjs";
3
3
 
4
4
  export { IntlayerContentSelectorElement, IntlayerContentSelectorWrapperElement, defineIntlayerContentSelectorWrapper, defineIntlayerElements };
@@ -0,0 +1,64 @@
1
+ // src/components/isInteractiveClickTarget.ts
2
+ /** Elements whose click already does something in the application. */
3
+ const INTERACTIVE_ELEMENT_SELECTOR = [
4
+ "a[href]",
5
+ "button",
6
+ "input",
7
+ "select",
8
+ "textarea",
9
+ "label",
10
+ "summary",
11
+ "option",
12
+ "video[controls]",
13
+ "audio[controls]",
14
+ "[contenteditable=\"\"]",
15
+ "[contenteditable=\"true\"]",
16
+ "[onclick]",
17
+ ...[
18
+ "button",
19
+ "link",
20
+ "checkbox",
21
+ "radio",
22
+ "switch",
23
+ "tab",
24
+ "menuitem",
25
+ "menuitemcheckbox",
26
+ "menuitemradio",
27
+ "option",
28
+ "combobox",
29
+ "slider",
30
+ "spinbutton",
31
+ "textbox"
32
+ ].map((role) => `[role="${role}"]`)
33
+ ].join(",");
34
+ /** Tag prefix of the editor's own elements, which are never app controls. */
35
+ const EDITOR_ELEMENT_PREFIX = "intlayer-";
36
+ const isEditorElement = (element) => {
37
+ if (element.localName.startsWith(EDITOR_ELEMENT_PREFIX)) return true;
38
+ const root = element.getRootNode();
39
+ return root instanceof ShadowRoot && root.host.localName.startsWith(EDITOR_ELEMENT_PREFIX);
40
+ };
41
+ /**
42
+ * Whether a click on editable content lands on something the application
43
+ * handles itself: a link, a button, a form control, or an ancestor rendered as
44
+ * clickable (`cursor: pointer`, the mark of delegated handlers such as React
45
+ * `onClick`). Such clicks keep their behavior; the content is then selected
46
+ * with a long press or a modifier click instead.
47
+ *
48
+ * The cursor is only read on ancestors of the editor elements: content inside
49
+ * them inherits the selector's own pointer cursor.
50
+ *
51
+ * @param event - Click event, read through its composed path
52
+ */
53
+ const isInteractiveClickTarget = (event) => {
54
+ const elements = event.composedPath().filter((node) => node instanceof Element);
55
+ const outermostEditorIndex = elements.findLastIndex(isEditorElement);
56
+ return elements.some((element, index) => {
57
+ if (isEditorElement(element)) return false;
58
+ if (element.matches(INTERACTIVE_ELEMENT_SELECTOR)) return true;
59
+ return index > outermostEditorIndex && getComputedStyle(element).cursor === "pointer";
60
+ });
61
+ };
62
+
63
+ export { isInteractiveClickTarget };
64
+ //# sourceMappingURL=isInteractiveClickTarget.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isInteractiveClickTarget.mjs","names":[],"sources":["../../../src/components/isInteractiveClickTarget.ts"],"sourcesContent":["/** Elements whose click already does something in the application. */\nconst INTERACTIVE_ELEMENT_SELECTOR = [\n 'a[href]',\n 'button',\n 'input',\n 'select',\n 'textarea',\n 'label',\n 'summary',\n 'option',\n 'video[controls]',\n 'audio[controls]',\n '[contenteditable=\"\"]',\n '[contenteditable=\"true\"]',\n '[onclick]',\n ...[\n 'button',\n 'link',\n 'checkbox',\n 'radio',\n 'switch',\n 'tab',\n 'menuitem',\n 'menuitemcheckbox',\n 'menuitemradio',\n 'option',\n 'combobox',\n 'slider',\n 'spinbutton',\n 'textbox',\n ].map((role) => `[role=\"${role}\"]`),\n].join(',');\n\n/** Tag prefix of the editor's own elements, which are never app controls. */\nconst EDITOR_ELEMENT_PREFIX = 'intlayer-';\n\nconst isEditorElement = (element: Element): boolean => {\n if (element.localName.startsWith(EDITOR_ELEMENT_PREFIX)) return true;\n\n const root = element.getRootNode();\n\n // Internals of the editor elements (their `role=\"button\"` wrapper, slots…)\n return (\n root instanceof ShadowRoot &&\n root.host.localName.startsWith(EDITOR_ELEMENT_PREFIX)\n );\n};\n\n/**\n * Whether a click on editable content lands on something the application\n * handles itself: a link, a button, a form control, or an ancestor rendered as\n * clickable (`cursor: pointer`, the mark of delegated handlers such as React\n * `onClick`). Such clicks keep their behavior; the content is then selected\n * with a long press or a modifier click instead.\n *\n * The cursor is only read on ancestors of the editor elements: content inside\n * them inherits the selector's own pointer cursor.\n *\n * @param event - Click event, read through its composed path\n */\nexport const isInteractiveClickTarget = (event: Event): boolean => {\n const elements = event\n .composedPath()\n .filter((node): node is Element => node instanceof Element);\n\n const outermostEditorIndex = elements.findLastIndex(isEditorElement);\n\n return elements.some((element, index) => {\n if (isEditorElement(element)) return false;\n if (element.matches(INTERACTIVE_ELEMENT_SELECTOR)) return true;\n\n const isAncestorOfEditorElement = index > outermostEditorIndex;\n\n return (\n isAncestorOfEditorElement &&\n getComputedStyle(element).cursor === 'pointer'\n );\n });\n};\n"],"mappings":";;AACA,MAAM,+BAA+B;CACnC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA,GAAG;EACD;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC,CAAC,KAAK,SAAS,UAAU,KAAK,GAAG;AACpC,CAAC,CAAC,KAAK,GAAG;;AAGV,MAAM,wBAAwB;AAE9B,MAAM,mBAAmB,YAA8B;CACrD,IAAI,QAAQ,UAAU,WAAW,qBAAqB,GAAG,OAAO;CAEhE,MAAM,OAAO,QAAQ,YAAY;CAGjC,OACE,gBAAgB,cAChB,KAAK,KAAK,UAAU,WAAW,qBAAqB;AAExD;;;;;;;;;;;;;AAcA,MAAa,4BAA4B,UAA0B;CACjE,MAAM,WAAW,MACd,aAAa,CAAC,CACd,QAAQ,SAA0B,gBAAgB,OAAO;CAE5D,MAAM,uBAAuB,SAAS,cAAc,eAAe;CAEnE,OAAO,SAAS,MAAM,SAAS,UAAU;EACvC,IAAI,gBAAgB,OAAO,GAAG,OAAO;EACrC,IAAI,QAAQ,QAAQ,4BAA4B,GAAG,OAAO;EAI1D,OAFkC,QAAQ,wBAIxC,iBAAiB,OAAO,CAAC,CAAC,WAAW;CAEzC,CAAC;AACH"}