@jsenv/navi 0.10.2 → 0.11.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 (207) hide show
  1. package/dist/jsenv_navi.js +13838 -23291
  2. package/dist/jsenv_navi.js.map +1281 -0
  3. package/package.json +6 -8
  4. package/index.js +0 -122
  5. package/src/action_private_properties.js +0 -11
  6. package/src/action_proxy_test.html +0 -353
  7. package/src/action_run_states.js +0 -5
  8. package/src/actions.js +0 -1401
  9. package/src/browser_integration/browser_integration.js +0 -216
  10. package/src/browser_integration/document_back_and_forward.js +0 -17
  11. package/src/browser_integration/document_loading_signal.js +0 -100
  12. package/src/browser_integration/document_state_signal.js +0 -9
  13. package/src/browser_integration/document_url_signal.js +0 -9
  14. package/src/browser_integration/use_is_visited.js +0 -19
  15. package/src/browser_integration/via_history.js +0 -232
  16. package/src/browser_integration/via_navigation.js +0 -168
  17. package/src/components/action_execution/form_context.js +0 -5
  18. package/src/components/action_execution/render_actionable_component.jsx +0 -29
  19. package/src/components/action_execution/use_action.js +0 -99
  20. package/src/components/action_execution/use_execute_action.js +0 -193
  21. package/src/components/action_execution/use_run_on_mount.js +0 -9
  22. package/src/components/action_renderer.jsx +0 -125
  23. package/src/components/callout/callout.js +0 -990
  24. package/src/components/callout/callout_demo.html +0 -201
  25. package/src/components/callout/test_dynamic_positioning.html +0 -161
  26. package/src/components/callout/test_html_document_iframe.html +0 -182
  27. package/src/components/demos/0_button_demo.html +0 -707
  28. package/src/components/demos/10_column_reordering_debug.html +0 -277
  29. package/src/components/demos/11_table_selection_debug.html +0 -432
  30. package/src/components/demos/1_checkbox_demo.html +0 -754
  31. package/src/components/demos/2_input_textual_demo.html +0 -286
  32. package/src/components/demos/3_radio_demo.html +0 -874
  33. package/src/components/demos/4_select_demo.html +0 -100
  34. package/src/components/demos/5_list_scrollable_demo.html +0 -153
  35. package/src/components/demos/6_tablist_demo.html +0 -77
  36. package/src/components/demos/7_table_selection_demo.html +0 -176
  37. package/src/components/demos/8_table_fixed_headers_demo.html +0 -584
  38. package/src/components/demos/9_table_column_drag_demo.html +0 -325
  39. package/src/components/demos/action/0_button_demo.html +0 -204
  40. package/src/components/demos/action/10_shortcuts_demo.html +0 -189
  41. package/src/components/demos/action/11_nested_shortcuts_demo.xhtml +0 -401
  42. package/src/components/demos/action/1_input_text_demo.html +0 -876
  43. package/src/components/demos/action/2_form_multiple.html +0 -303
  44. package/src/components/demos/action/3_details_demo.html +0 -203
  45. package/src/components/demos/action/4_input_checkbox_demo.html +0 -731
  46. package/src/components/demos/action/5_input_checkbox_state_demo.html +0 -270
  47. package/src/components/demos/action/6_checkbox_list_demo.html +0 -341
  48. package/src/components/demos/action/7_radio_list_demo.html +0 -357
  49. package/src/components/demos/action/8_editable_demo.html +0 -431
  50. package/src/components/demos/action/9_link_demo.html +0 -194
  51. package/src/components/demos/demo.md +0 -0
  52. package/src/components/demos/route/basic/basic.html +0 -14
  53. package/src/components/demos/route/basic/basic_route_demo.jsx +0 -224
  54. package/src/components/demos/route/multi/multi.html +0 -14
  55. package/src/components/demos/route/multi/multi_route_demo.jsx +0 -277
  56. package/src/components/demos/ui_transition/0_action_renderer_ui_transition_demo.html +0 -695
  57. package/src/components/demos/ui_transition/1_nested_ui_transition_demo.html +0 -429
  58. package/src/components/demos/ui_transition/2_height_transition_test.html +0 -295
  59. package/src/components/details/details.jsx +0 -245
  60. package/src/components/details/summary_marker.jsx +0 -141
  61. package/src/components/edition/editable.jsx +0 -186
  62. package/src/components/error_boundary_context.js +0 -9
  63. package/src/components/field/README.md +0 -247
  64. package/src/components/field/button.jsx +0 -429
  65. package/src/components/field/checkbox_list.jsx +0 -185
  66. package/src/components/field/collect_form_element_values.js +0 -82
  67. package/src/components/field/custom_field.js +0 -106
  68. package/src/components/field/form.jsx +0 -209
  69. package/src/components/field/input.jsx +0 -16
  70. package/src/components/field/input_checkbox.jsx +0 -434
  71. package/src/components/field/input_radio.jsx +0 -432
  72. package/src/components/field/input_textual.jsx +0 -389
  73. package/src/components/field/label.jsx +0 -46
  74. package/src/components/field/radio_list.jsx +0 -183
  75. package/src/components/field/select.jsx +0 -256
  76. package/src/components/field/use_action_events.js +0 -132
  77. package/src/components/field/use_form_events.js +0 -59
  78. package/src/components/field/use_ui_state_controller.js +0 -506
  79. package/src/components/item_tracker/README.md +0 -461
  80. package/src/components/item_tracker/use_isolated_item_tracker.jsx +0 -209
  81. package/src/components/item_tracker/use_isolated_item_tracker_demo.html +0 -148
  82. package/src/components/item_tracker/use_isolated_item_tracker_demo.jsx +0 -460
  83. package/src/components/item_tracker/use_item_tracker.jsx +0 -143
  84. package/src/components/item_tracker/use_item_tracker_demo.html +0 -207
  85. package/src/components/item_tracker/use_item_tracker_demo.jsx +0 -216
  86. package/src/components/keyboard_shortcuts/active_keyboard_shortcuts.jsx +0 -87
  87. package/src/components/keyboard_shortcuts/aria_key_shortcuts.js +0 -61
  88. package/src/components/keyboard_shortcuts/keyboard_key_meta.js +0 -17
  89. package/src/components/keyboard_shortcuts/keyboard_shortcuts.js +0 -371
  90. package/src/components/keyboard_shortcuts/os.js +0 -9
  91. package/src/components/layout/demos/demo_flex.html +0 -638
  92. package/src/components/layout/demos/demo_layout_style_buttons.html +0 -351
  93. package/src/components/layout/demos/demo_layout_style_input.html +0 -226
  94. package/src/components/layout/demos/demo_layout_style_text.html +0 -514
  95. package/src/components/layout/flex.jsx +0 -109
  96. package/src/components/layout/layout_context.jsx +0 -3
  97. package/src/components/layout/spacing.jsx +0 -20
  98. package/src/components/layout/use_layout_style.js +0 -249
  99. package/src/components/link/link.jsx +0 -267
  100. package/src/components/link/link_with_icon.jsx +0 -52
  101. package/src/components/loader/loader_background.jsx +0 -372
  102. package/src/components/loader/loading_spinner.jsx +0 -68
  103. package/src/components/loader/network_speed.js +0 -83
  104. package/src/components/loader/rectangle_loading.jsx +0 -244
  105. package/src/components/props_composition/demos/demo_with_props_style.html +0 -81
  106. package/src/components/props_composition/with_props_class_name.js +0 -37
  107. package/src/components/props_composition/with_props_style.js +0 -26
  108. package/src/components/route.jsx +0 -19
  109. package/src/components/selection/selection.jsx +0 -1583
  110. package/src/components/svg/font_sized_svg.jsx +0 -59
  111. package/src/components/svg/icon_and_text.jsx +0 -21
  112. package/src/components/svg/svg_mask_overlay.jsx +0 -105
  113. package/src/components/table/drag/table_drag.jsx +0 -506
  114. package/src/components/table/resize/table_resize.jsx +0 -650
  115. package/src/components/table/resize/table_size.js +0 -43
  116. package/src/components/table/selection/table_selection.js +0 -106
  117. package/src/components/table/selection/table_selection.jsx +0 -203
  118. package/src/components/table/sticky/sticky_group.js +0 -354
  119. package/src/components/table/sticky/table_sticky.js +0 -25
  120. package/src/components/table/sticky/table_sticky.jsx +0 -501
  121. package/src/components/table/table.jsx +0 -721
  122. package/src/components/table/table_css.js +0 -211
  123. package/src/components/table/table_ui.jsx +0 -49
  124. package/src/components/table/use_cells_and_columns.js +0 -90
  125. package/src/components/table/use_object_array_to_cells.js +0 -46
  126. package/src/components/table/z_indexes.js +0 -23
  127. package/src/components/tablist/tablist.jsx +0 -99
  128. package/src/components/text/demos/demo_text_and_icon.html +0 -421
  129. package/src/components/text/overflow.jsx +0 -15
  130. package/src/components/text/text.jsx +0 -83
  131. package/src/components/text/text_and_count.jsx +0 -28
  132. package/src/components/ui_transition.jsx +0 -128
  133. package/src/components/use_auto_focus.js +0 -94
  134. package/src/components/use_batch_during_render.js +0 -33
  135. package/src/components/use_debounce_true.js +0 -31
  136. package/src/components/use_dependencies_diff.js +0 -35
  137. package/src/components/use_focus_group.js +0 -20
  138. package/src/components/use_initial_value.js +0 -78
  139. package/src/components/use_is_visited.js +0 -19
  140. package/src/components/use_ref_array.js +0 -38
  141. package/src/components/use_signal_sync.js +0 -50
  142. package/src/components/use_stable_callback.js +0 -68
  143. package/src/components/use_state_array.js +0 -47
  144. package/src/docs/actions.md +0 -250
  145. package/src/docs/demos/resource/action_status.jsx +0 -42
  146. package/src/docs/demos/resource/demo.md +0 -1
  147. package/src/docs/demos/resource/resource_demo_0.html +0 -84
  148. package/src/docs/demos/resource/resource_demo_10_post_gc.html +0 -364
  149. package/src/docs/demos/resource/resource_demo_11_describe_many.html +0 -362
  150. package/src/docs/demos/resource/resource_demo_2.html +0 -173
  151. package/src/docs/demos/resource/resource_demo_3_filtered_users.html +0 -415
  152. package/src/docs/demos/resource/resource_demo_4_details.html +0 -284
  153. package/src/docs/demos/resource/resource_demo_5_renderer_lazy.html +0 -115
  154. package/src/docs/demos/resource/resource_demo_6_gc.html +0 -217
  155. package/src/docs/demos/resource/resource_demo_7_child_gc.html +0 -240
  156. package/src/docs/demos/resource/resource_demo_8_proxy_gc.html +0 -319
  157. package/src/docs/demos/resource/resource_demo_9_describe_one.html +0 -472
  158. package/src/docs/demos/resource/tata.jsx +0 -3
  159. package/src/docs/demos/resource/toto.jsx +0 -3
  160. package/src/docs/demos/user_nav/user_nav.html +0 -12
  161. package/src/docs/demos/user_nav/user_nav.jsx +0 -330
  162. package/src/docs/resource_dependencies.md +0 -103
  163. package/src/docs/resource_with_params.md +0 -80
  164. package/src/navi_css_vars.js +0 -14
  165. package/src/notes.md +0 -34
  166. package/src/route/route.js +0 -596
  167. package/src/route/route.xtest.html +0 -228
  168. package/src/store/array_signal_store.js +0 -537
  169. package/src/store/local_storage_signal.js +0 -17
  170. package/src/store/resource_graph.js +0 -1304
  171. package/src/store/tests/resource_graph_autoreload_demo.html +0 -12
  172. package/src/store/tests/resource_graph_autoreload_demo.jsx +0 -964
  173. package/src/store/tests/resource_graph_dependencies.test_manual.js +0 -95
  174. package/src/store/value_in_local_storage.js +0 -187
  175. package/src/symbol_object_signal.js +0 -1
  176. package/src/use_action_data.js +0 -10
  177. package/src/use_action_status.js +0 -47
  178. package/src/utils/add_many_event_listeners.js +0 -15
  179. package/src/utils/array_add_remove.js +0 -61
  180. package/src/utils/array_signal.js +0 -15
  181. package/src/utils/compare_two_js_values.js +0 -172
  182. package/src/utils/execute_with_cleanup.js +0 -21
  183. package/src/utils/get_caller_info.js +0 -85
  184. package/src/utils/is_signal.js +0 -20
  185. package/src/utils/js_value_weak_map.js +0 -162
  186. package/src/utils/js_value_weak_map_demo.html +0 -690
  187. package/src/utils/merge_two_js_values.js +0 -53
  188. package/src/utils/stringify_for_display.js +0 -131
  189. package/src/utils/weak_effect.js +0 -48
  190. package/src/validation/constraints/confirm_constraint.js +0 -14
  191. package/src/validation/constraints/create_unique_value_constraint.js +0 -27
  192. package/src/validation/constraints/native_constraints.js +0 -338
  193. package/src/validation/constraints/readonly_constraint.js +0 -41
  194. package/src/validation/constraints/same_as_constraint.js +0 -42
  195. package/src/validation/constraints/single_space_constraint.js +0 -13
  196. package/src/validation/custom_constraint_validation.js +0 -793
  197. package/src/validation/custom_message.js +0 -18
  198. package/src/validation/demos/browser_style.png +0 -0
  199. package/src/validation/demos/demo_same_as_constraint.html +0 -259
  200. package/src/validation/demos/form_validation_demo.html +0 -142
  201. package/src/validation/demos/form_validation_demo_preact.html +0 -87
  202. package/src/validation/demos/form_validation_native_popover_demo.html +0 -168
  203. package/src/validation/demos/form_validation_vs_native_demo.html +0 -172
  204. package/src/validation/hooks/use_constraints.js +0 -23
  205. package/src/validation/hooks/use_custom_validation_ref.js +0 -73
  206. package/src/validation/hooks/use_validation_message.js +0 -19
  207. package/src/validation/input_change_effect.js +0 -106
@@ -1,990 +0,0 @@
1
- import {
2
- allowWheelThrough,
3
- createPubSub,
4
- createStyleController,
5
- createValueEffect,
6
- getBorderSizes,
7
- getFirstVisuallyVisibleAncestor,
8
- getPaddingSizes,
9
- getVisuallyVisibleInfo,
10
- pickPositionRelativeTo,
11
- visibleRectEffect,
12
- } from "@jsenv/dom";
13
-
14
- /**
15
- * A callout component that mimics native browser validation messages.
16
- * Features:
17
- * - Positions above or below target element based on available space
18
- * - Follows target element during scrolling and resizing
19
- * - Automatically hides when target element is not visible
20
- * - Arrow automatically shows when pointing at a valid anchor element
21
- * - Centers in viewport when no anchor element provided or anchor is too big
22
- */
23
-
24
- /**
25
- * Shows a callout attached to the specified element
26
- * @param {string} message - HTML content for the callout
27
- * @param {Object} options - Configuration options
28
- * @param {HTMLElement} [options.anchorElement] - Element the callout should follow. If not provided or too big, callout will be centered in viewport
29
- * @param {string} [options.level="warning"] - Callout level: "info" | "warning" | "error"
30
- * @param {Function} [options.onClose] - Callback when callout is closed
31
- * @param {boolean} [options.closeOnClickOutside] - Whether to close on outside clicks (defaults to true for "info" level)
32
- * @param {boolean} [options.debug=false] - Enable debug logging
33
- * @returns {Object} - Callout object with properties:
34
- * - {Function} close - Function to close the callout
35
- * - {Function} update - Function to update message and options
36
- * - {Function} updatePosition - Function to update position
37
- * - {HTMLElement} element - The callout DOM element
38
- * - {boolean} opened - Whether the callout is currently open
39
- */
40
- export const openCallout = (
41
- message,
42
- {
43
- anchorElement,
44
- // Level determines visual styling and behavior:
45
- // "info" - polite announcement (e.g., "This element cannot be modified")
46
- // "warning" - expected failure requiring user action (e.g., "Field is required")
47
- // "error" - unexpected failure, may not be actionable (e.g., "Server error")
48
- level = "warning",
49
- onClose,
50
- closeOnClickOutside = level === "info",
51
- showErrorStack,
52
- debug = false,
53
- } = {},
54
- ) => {
55
- const callout = {
56
- opened: true,
57
- close: null,
58
- level: undefined,
59
-
60
- update: null,
61
- updatePosition: null,
62
-
63
- element: null,
64
- };
65
-
66
- if (debug) {
67
- console.debug("open callout", {
68
- anchorElement,
69
- message,
70
- level,
71
- });
72
- }
73
-
74
- const [teardown, addTeardown] = createPubSub(true);
75
- const close = (reason) => {
76
- if (!callout.opened) {
77
- return;
78
- }
79
- if (debug) {
80
- console.debug(`callout closed (reason: ${reason})`);
81
- }
82
- callout.opened = false;
83
- teardown(reason);
84
- };
85
- if (onClose) {
86
- addTeardown(onClose);
87
- }
88
-
89
- const [updateLevel, addLevelEffect, cleanupLevelEffects] =
90
- createValueEffect(undefined);
91
- addTeardown(cleanupLevelEffects);
92
-
93
- // Create and add callout to document
94
- const calloutElement = createCalloutElement();
95
- const calloutMessageElement = calloutElement.querySelector(
96
- ".navi_callout_message",
97
- );
98
- const calloutCloseButton = calloutElement.querySelector(
99
- ".navi_callout_close_button",
100
- );
101
- calloutCloseButton.onclick = () => {
102
- close("click_close_button");
103
- };
104
- const calloutId = `navi_callout_${Date.now()}`;
105
- calloutElement.id = calloutId;
106
- calloutStyleController.set(calloutElement, { opacity: 0 });
107
- const update = (newMessage, options = {}) => {
108
- // Connect callout with target element for accessibility
109
- if (options.level && options.level !== callout.level) {
110
- callout.level = level;
111
- updateLevel(level);
112
- }
113
-
114
- if (options.closeOnClickOutside) {
115
- closeOnClickOutside = options.closeOnClickOutside;
116
- }
117
-
118
- if (Error.isError(newMessage)) {
119
- const error = newMessage;
120
- newMessage = error.message;
121
- if (showErrorStack && error.stack) {
122
- newMessage += `<pre class="navi_callout_error_stack">${escapeHtml(String(error.stack))}</pre>`;
123
- }
124
- }
125
-
126
- // Check if the message is a full HTML document (starts with DOCTYPE)
127
- if (typeof newMessage === "string" && isHtmlDocument(newMessage)) {
128
- // Create iframe to isolate the HTML document
129
- const iframe = document.createElement("iframe");
130
- iframe.style.border = "none";
131
- iframe.style.width = "100%";
132
- iframe.style.backgroundColor = "white";
133
- iframe.srcdoc = newMessage;
134
-
135
- // Clear existing content and add iframe
136
- calloutMessageElement.innerHTML = "";
137
- calloutMessageElement.appendChild(iframe);
138
- } else {
139
- calloutMessageElement.innerHTML = newMessage;
140
- }
141
- };
142
- close_on_click_outside: {
143
- const handleClickOutside = (event) => {
144
- if (!closeOnClickOutside) {
145
- return;
146
- }
147
-
148
- const clickTarget = event.target;
149
- if (
150
- clickTarget === calloutElement ||
151
- calloutElement.contains(clickTarget)
152
- ) {
153
- return;
154
- }
155
- // if (
156
- // clickTarget === targetElement ||
157
- // targetElement.contains(clickTarget)
158
- // ) {
159
- // return;
160
- // }
161
- close("click_outside");
162
- };
163
- document.addEventListener("click", handleClickOutside, true);
164
- addTeardown(() => {
165
- document.removeEventListener("click", handleClickOutside, true);
166
- });
167
- }
168
- Object.assign(callout, {
169
- element: calloutElement,
170
- update,
171
- close,
172
- });
173
- addLevelEffect(() => {
174
- calloutElement.setAttribute("data-level", level);
175
- if (level === "info") {
176
- calloutElement.setAttribute("role", "status");
177
- } else {
178
- calloutElement.setAttribute("role", "alert");
179
- }
180
- });
181
- document.body.appendChild(calloutElement);
182
- addTeardown(() => {
183
- calloutElement.remove();
184
- });
185
-
186
- if (anchorElement) {
187
- const anchorVisuallyVisibleInfo = getVisuallyVisibleInfo(anchorElement, {
188
- countOffscreenAsVisible: true,
189
- });
190
- if (!anchorVisuallyVisibleInfo.visible) {
191
- console.warn(
192
- `anchor element is not visually visible (${anchorVisuallyVisibleInfo.reason}) -> will be anchored to first visually visible ancestor`,
193
- );
194
- anchorElement = getFirstVisuallyVisibleAncestor(anchorElement);
195
- }
196
-
197
- allowWheelThrough(calloutElement, anchorElement);
198
- anchorElement.setAttribute("data-callout", calloutId);
199
- addTeardown(() => {
200
- anchorElement.removeAttribute("data-callout");
201
- });
202
-
203
- addLevelEffect(() => {
204
- anchorElement.style.setProperty(
205
- "--callout-color",
206
- `var(--navi-${level}-color)`,
207
- );
208
- return () => {
209
- anchorElement.style.removeProperty("--callout-color");
210
- };
211
- });
212
- addLevelEffect((level) => {
213
- if (level === "info") {
214
- anchorElement.setAttribute("aria-describedby", calloutId);
215
- return () => {
216
- anchorElement.removeAttribute("aria-describedby");
217
- };
218
- }
219
- anchorElement.setAttribute("aria-errormessage", calloutId);
220
- anchorElement.setAttribute("aria-invalid", "true");
221
- return () => {
222
- anchorElement.removeAttribute("aria-errormessage");
223
- anchorElement.removeAttribute("aria-invalid");
224
- };
225
- });
226
-
227
- close_on_anchor_focus: {
228
- const onfocus = () => {
229
- if (level === "error") {
230
- // error messages must be explicitely closed by the user
231
- return;
232
- }
233
- if (anchorElement.hasAttribute("data-callout-stay-on-focus")) {
234
- return;
235
- }
236
- close("target_element_focus");
237
- };
238
- anchorElement.addEventListener("focus", onfocus);
239
- addTeardown(() => {
240
- anchorElement.removeEventListener("focus", onfocus);
241
- });
242
- }
243
- anchorElement.callout = callout;
244
- addTeardown(() => {
245
- delete anchorElement.callout;
246
- });
247
- }
248
-
249
- update(message, { level });
250
-
251
- positioning: {
252
- const documentScrollLeftAtOpen = document.documentElement.scrollLeft;
253
- const documentScrollTopAtOpen = document.documentElement.scrollTop;
254
-
255
- let positioner;
256
- let strategy;
257
- const determine = () => {
258
- if (!anchorElement) {
259
- return "centered";
260
- }
261
- // Check if anchor element is too big to reasonably position callout relative to it
262
- const anchorRect = anchorElement.getBoundingClientRect();
263
- const viewportHeight = window.innerHeight;
264
- const anchorTooBig = anchorRect.height > viewportHeight - 50;
265
- if (anchorTooBig) {
266
- return "centered";
267
- }
268
- return "anchored";
269
- };
270
- const updatePositioner = () => {
271
- const newStrategy = determine(anchorElement);
272
- if (newStrategy === strategy) {
273
- return;
274
- }
275
- positioner?.stop();
276
- if (newStrategy === "centered") {
277
- positioner = centerCalloutInViewport(calloutElement, {
278
- documentScrollLeftAtOpen,
279
- documentScrollTopAtOpen,
280
- });
281
- } else {
282
- positioner = stickCalloutToAnchor(calloutElement, anchorElement);
283
- }
284
- strategy = newStrategy;
285
- };
286
- updatePositioner();
287
- addTeardown(() => {
288
- positioner.stop();
289
- });
290
- auto_update_positioner: {
291
- const handleResize = () => {
292
- updatePositioner();
293
- };
294
- window.addEventListener("resize", handleResize);
295
- addTeardown(() => {
296
- window.removeEventListener("resize", handleResize);
297
- });
298
- }
299
- callout.updatePosition = () => positioner.update();
300
- }
301
-
302
- return callout;
303
- };
304
-
305
- // Configuration parameters for callout appearance
306
- const BORDER_WIDTH = 1;
307
- const CORNER_RADIUS = 3;
308
- const ARROW_WIDTH = 16;
309
- const ARROW_HEIGHT = 8;
310
- const ARROW_SPACING = 8;
311
-
312
- import.meta.css = /* css */ `
313
- @layer navi {
314
- :root {
315
- --navi-callout-background-color: white;
316
- --navi-callout-padding: 8px;
317
- }
318
-
319
- .navi_callout {
320
- position: absolute;
321
- top: 0;
322
- left: 0;
323
- z-index: 1;
324
- display: block;
325
- height: auto;
326
- opacity: 0;
327
- /* will be positioned with transform: translate */
328
- transition: opacity 0.2s ease-in-out;
329
- overflow: visible;
330
- }
331
-
332
- .navi_callout_frame {
333
- position: absolute;
334
- filter: drop-shadow(4px 4px 3px rgba(0, 0, 0, 0.2));
335
- pointer-events: none;
336
- }
337
- .navi_callout[data-level="info"] .navi_callout_border {
338
- fill: var(--navi-info-color);
339
- }
340
- .navi_callout[data-level="warning"] .navi_callout_border {
341
- fill: var(--navi-warning-color);
342
- }
343
- .navi_callout[data-level="error"] .navi_callout_border {
344
- fill: var(--navi-error-color);
345
- }
346
- .navi_callout_frame svg {
347
- position: absolute;
348
- inset: 0;
349
- overflow: visible;
350
- }
351
- .navi_callout_background {
352
- fill: var(--navi-callout-background-color);
353
- }
354
-
355
- .navi_callout_box {
356
- position: relative;
357
- border-style: solid;
358
- border-color: transparent;
359
- }
360
- .navi_callout_body {
361
- position: relative;
362
- display: flex;
363
- max-width: 47vw;
364
- padding: var(--navi-callout-padding);
365
- flex-direction: row;
366
- gap: 10px;
367
- }
368
- .navi_callout_icon {
369
- display: flex;
370
- width: 22px;
371
- height: 22px;
372
- flex-shrink: 0;
373
- align-items: center;
374
- align-self: flex-start;
375
- justify-content: center;
376
- border-radius: 2px;
377
- }
378
- .navi_callout_icon_svg {
379
- width: 16px;
380
- height: 12px;
381
- color: white;
382
- }
383
- .navi_callout[data-level="info"] .navi_callout_icon {
384
- background-color: var(--navi-info-color);
385
- }
386
- .navi_callout[data-level="warning"] .navi_callout_icon {
387
- background-color: var(--navi-warning-color);
388
- }
389
- .navi_callout[data-level="error"] .navi_callout_icon {
390
- background-color: var(--navi-error-color);
391
- }
392
- .navi_callout_message {
393
- min-width: 0;
394
- align-self: center;
395
- word-break: break-word;
396
- overflow-wrap: anywhere;
397
- }
398
- .navi_callout_message iframe {
399
- display: block;
400
- margin: 0;
401
- }
402
- .navi_callout_close_button_column {
403
- display: flex;
404
- height: 22px;
405
- }
406
- .navi_callout_close_button {
407
- width: 1em;
408
- height: 1em;
409
- padding: 0;
410
- align-self: center;
411
- color: currentColor;
412
- font-size: inherit;
413
- background: none;
414
- border: none;
415
- border-radius: 0.2em;
416
- cursor: pointer;
417
- }
418
- .navi_callout_close_button:hover {
419
- background: rgba(0, 0, 0, 0.1);
420
- }
421
- .navi_callout_close_button_svg {
422
- width: 100%;
423
- height: 100%;
424
- }
425
- .navi_callout_error_stack {
426
- max-height: 200px;
427
- overflow: auto;
428
- }
429
- }
430
- `;
431
-
432
- // HTML template for the callout
433
- const calloutTemplate = /* html */ `
434
- <div class="navi_callout">
435
- <div class="navi_callout_box">
436
- <div class="navi_callout_frame"></div>
437
- <div class="navi_callout_body">
438
- <div class="navi_callout_icon">
439
- <svg
440
- class="navi_callout_icon_svg"
441
- viewBox="0 0 125 300"
442
- xmlns="http://www.w3.org/2000/svg"
443
- >
444
- <path
445
- fill="currentColor"
446
- d="m25,1 8,196h59l8-196zm37,224a37,37 0 1,0 2,0z"
447
- />
448
- </svg>
449
- </div>
450
- <div class="navi_callout_message">Default message</div>
451
- <div class="navi_callout_close_button_column">
452
- <button class="navi_callout_close_button">
453
- <svg
454
- class="navi_callout_close_button_svg"
455
- viewBox="0 0 24 24"
456
- fill="none"
457
- xmlns="http://www.w3.org/2000/svg"
458
- >
459
- <path
460
- fill-rule="evenodd"
461
- clip-rule="evenodd"
462
- d="M5.29289 5.29289C5.68342 4.90237 6.31658 4.90237 6.70711 5.29289L12 10.5858L17.2929 5.29289C17.6834 4.90237 18.3166 4.90237 18.7071 5.29289C19.0976 5.68342 19.0976 6.31658 18.7071 6.70711L13.4142 12L18.7071 17.2929C19.0976 17.6834 19.0976 18.3166 18.7071 18.7071C18.3166 19.0976 17.6834 19.0976 17.2929 18.7071L12 13.4142L6.70711 18.7071C6.31658 19.0976 5.68342 19.0976 5.29289 18.7071C4.90237 18.3166 4.90237 17.6834 5.29289 17.2929L10.5858 12L5.29289 6.70711C4.90237 6.31658 4.90237 5.68342 5.29289 5.29289Z"
463
- fill="currentColor"
464
- />
465
- </svg>
466
- </button>
467
- </div>
468
- </div>
469
- </div>
470
- </div>
471
- `;
472
-
473
- const calloutStyleController = createStyleController("callout");
474
-
475
- /**
476
- * Creates a new callout element from template
477
- * @returns {HTMLElement} - The callout element
478
- */
479
- const createCalloutElement = () => {
480
- const div = document.createElement("div");
481
- div.innerHTML = calloutTemplate;
482
- const calloutElement = div.firstElementChild;
483
- return calloutElement;
484
- };
485
-
486
- const centerCalloutInViewport = (
487
- calloutElement,
488
- { documentScrollLeftAtOpen, documentScrollTopAtOpen },
489
- ) => {
490
- // Set up initial styles for centered positioning
491
- const calloutBoxElement = calloutElement.querySelector(".navi_callout_box");
492
- const calloutFrameElement = calloutElement.querySelector(
493
- ".navi_callout_frame",
494
- );
495
- const calloutBodyElement = calloutElement.querySelector(".navi_callout_body");
496
- const calloutMessageElement = calloutElement.querySelector(
497
- ".navi_callout_message",
498
- );
499
-
500
- // Remove any margins and set frame positioning for no arrow
501
- calloutBoxElement.style.marginTop = "";
502
- calloutBoxElement.style.marginBottom = "";
503
- calloutBoxElement.style.borderWidth = `${BORDER_WIDTH}px`;
504
- calloutFrameElement.style.left = `-${BORDER_WIDTH}px`;
505
- calloutFrameElement.style.right = `-${BORDER_WIDTH}px`;
506
- calloutFrameElement.style.top = `-${BORDER_WIDTH}px`;
507
- calloutFrameElement.style.bottom = `-${BORDER_WIDTH}px`;
508
-
509
- // Generate simple rectangle SVG without arrow and position in center
510
- const updateCenteredPosition = () => {
511
- const calloutElementClone =
512
- cloneCalloutToMeasureNaturalSize(calloutElement);
513
- const { height } = calloutElementClone.getBoundingClientRect();
514
- calloutElementClone.remove();
515
-
516
- // Handle content overflow when viewport is too small
517
- const viewportHeight = window.innerHeight;
518
- const maxAllowedHeight = viewportHeight - 40; // Leave some margin from viewport edges
519
-
520
- if (height > maxAllowedHeight) {
521
- const paddingSizes = getPaddingSizes(calloutBodyElement);
522
- const paddingY = paddingSizes.top + paddingSizes.bottom;
523
- const spaceNeededAroundContent = BORDER_WIDTH * 2 + paddingY;
524
- const spaceAvailableForContent =
525
- maxAllowedHeight - spaceNeededAroundContent;
526
- calloutMessageElement.style.maxHeight = `${spaceAvailableForContent}px`;
527
- calloutMessageElement.style.overflowY = "scroll";
528
- } else {
529
- // Reset overflow styles if not needed
530
- calloutMessageElement.style.maxHeight = "";
531
- calloutMessageElement.style.overflowY = "";
532
- }
533
-
534
- // Get final dimensions after potential overflow adjustments
535
- const { width: finalWidth, height: finalHeight } =
536
- calloutElement.getBoundingClientRect();
537
- calloutFrameElement.innerHTML = generateSvgWithoutArrow(
538
- finalWidth,
539
- finalHeight,
540
- );
541
-
542
- // Center in viewport (accounting for document scroll)
543
- const viewportWidth = window.innerWidth;
544
- const left = documentScrollLeftAtOpen + (viewportWidth - finalWidth) / 2;
545
- const top = documentScrollTopAtOpen + (viewportHeight - finalHeight) / 2;
546
-
547
- calloutStyleController.set(calloutElement, {
548
- opacity: 1,
549
- transform: {
550
- translateX: left,
551
- translateY: top,
552
- },
553
- });
554
- };
555
-
556
- // Initial positioning
557
- updateCenteredPosition();
558
- window.addEventListener("resize", updateCenteredPosition);
559
-
560
- // Return positioning function for dynamic updates
561
- return {
562
- update: updateCenteredPosition,
563
- stop: () => {
564
- window.removeEventListener("resize", updateCenteredPosition);
565
- },
566
- };
567
- };
568
-
569
- /**
570
- * Positions a callout relative to an anchor element with an arrow pointing to it
571
- * @param {HTMLElement} calloutElement - The callout element to position
572
- * @param {HTMLElement} anchorElement - The anchor element to stick to
573
- * @returns {Object} - Object with update and stop functions
574
- */
575
- const stickCalloutToAnchor = (calloutElement, anchorElement) => {
576
- // Get references to callout parts
577
- const calloutBoxElement = calloutElement.querySelector(".navi_callout_box");
578
- const calloutFrameElement = calloutElement.querySelector(
579
- ".navi_callout_frame",
580
- );
581
- const calloutBodyElement = calloutElement.querySelector(".navi_callout_body");
582
- const calloutMessageElement = calloutElement.querySelector(
583
- ".navi_callout_message",
584
- );
585
-
586
- // Set initial border styles
587
- calloutBoxElement.style.borderWidth = `${BORDER_WIDTH}px`;
588
- calloutFrameElement.style.left = `-${BORDER_WIDTH}px`;
589
- calloutFrameElement.style.right = `-${BORDER_WIDTH}px`;
590
-
591
- const anchorVisibleRectEffect = visibleRectEffect(
592
- anchorElement,
593
- ({ left: anchorLeft, right: anchorRight, visibilityRatio }) => {
594
- const calloutElementClone =
595
- cloneCalloutToMeasureNaturalSize(calloutElement);
596
- const {
597
- position,
598
- left: calloutLeft,
599
- top: calloutTop,
600
- width: calloutWidth,
601
- height: calloutHeight,
602
- spaceAboveTarget,
603
- spaceBelowTarget,
604
- } = pickPositionRelativeTo(calloutElementClone, anchorElement, {
605
- alignToViewportEdgeWhenTargetNearEdge: 20,
606
- // when fully to the left, the border color is collé to the browser window making it hard to see
607
- minLeft: 1,
608
- });
609
- calloutElementClone.remove();
610
-
611
- // Calculate arrow position to point at anchorElement element
612
- let arrowLeftPosOnCallout;
613
- // Determine arrow target position based on attribute
614
- const arrowPositionAttribute = anchorElement.getAttribute(
615
- "data-callout-arrow-x",
616
- );
617
- let arrowAnchorLeft;
618
- if (arrowPositionAttribute === "center") {
619
- // Target the center of the anchorElement element
620
- arrowAnchorLeft = (anchorLeft + anchorRight) / 2;
621
- } else {
622
- const anchorBorderSizes = getBorderSizes(anchorElement);
623
- // Default behavior: target the left edge of the anchorElement element (after borders)
624
- arrowAnchorLeft = anchorLeft + anchorBorderSizes.left;
625
- }
626
-
627
- // Calculate arrow position within the callout
628
- if (calloutLeft < arrowAnchorLeft) {
629
- // Callout is left of the target point, move arrow right
630
- const diff = arrowAnchorLeft - calloutLeft;
631
- arrowLeftPosOnCallout = diff;
632
- } else if (calloutLeft + calloutWidth < arrowAnchorLeft) {
633
- // Edge case: target point is beyond right edge of callout
634
- arrowLeftPosOnCallout = calloutWidth - ARROW_WIDTH;
635
- } else {
636
- // Target point is within callout width
637
- arrowLeftPosOnCallout = arrowAnchorLeft - calloutLeft;
638
- }
639
-
640
- // Ensure arrow stays within callout bounds with some padding
641
- const minArrowPos = CORNER_RADIUS + ARROW_WIDTH / 2 + ARROW_SPACING;
642
- const maxArrowPos = calloutWidth - minArrowPos;
643
- arrowLeftPosOnCallout = Math.max(
644
- minArrowPos,
645
- Math.min(arrowLeftPosOnCallout, maxArrowPos),
646
- );
647
-
648
- // Force content overflow when there is not enough space to display
649
- // the entirety of the callout
650
- const spaceAvailable =
651
- position === "below" ? spaceBelowTarget : spaceAboveTarget;
652
- const paddingSizes = getPaddingSizes(calloutBodyElement);
653
- const paddingY = paddingSizes.top + paddingSizes.bottom;
654
- const spaceNeededAroundContent =
655
- ARROW_HEIGHT + BORDER_WIDTH * 2 + paddingY;
656
- const spaceAvailableForContent =
657
- spaceAvailable - spaceNeededAroundContent;
658
- const contentHeight = calloutHeight - spaceNeededAroundContent;
659
- const spaceRemainingAfterContent =
660
- spaceAvailableForContent - contentHeight;
661
- if (spaceRemainingAfterContent < 2) {
662
- const maxHeight = spaceAvailableForContent;
663
- calloutMessageElement.style.maxHeight = `${maxHeight}px`;
664
- calloutMessageElement.style.overflowY = "scroll";
665
- } else {
666
- calloutMessageElement.style.maxHeight = "";
667
- calloutMessageElement.style.overflowY = "";
668
- }
669
-
670
- const { width, height } = calloutElement.getBoundingClientRect();
671
- if (position === "above") {
672
- // Position above target element
673
- calloutBoxElement.style.marginTop = "";
674
- calloutBoxElement.style.marginBottom = `${ARROW_HEIGHT}px`;
675
- calloutFrameElement.style.top = `-${BORDER_WIDTH}px`;
676
- calloutFrameElement.style.bottom = `-${BORDER_WIDTH + ARROW_HEIGHT - 0.5}px`;
677
- calloutFrameElement.innerHTML = generateSvgWithBottomArrow(
678
- width,
679
- height,
680
- arrowLeftPosOnCallout,
681
- );
682
- } else {
683
- calloutBoxElement.style.marginTop = `${ARROW_HEIGHT}px`;
684
- calloutBoxElement.style.marginBottom = "";
685
- calloutFrameElement.style.top = `-${BORDER_WIDTH + ARROW_HEIGHT - 0.5}px`;
686
- calloutFrameElement.style.bottom = `-${BORDER_WIDTH}px`;
687
- calloutFrameElement.innerHTML = generateSvgWithTopArrow(
688
- width,
689
- height,
690
- arrowLeftPosOnCallout,
691
- );
692
- }
693
-
694
- calloutElement.setAttribute("data-position", position);
695
- calloutStyleController.set(calloutElement, {
696
- opacity: visibilityRatio ? 1 : 0,
697
- transform: {
698
- translateX: calloutLeft,
699
- translateY: calloutTop,
700
- },
701
- });
702
- },
703
- );
704
- const calloutSizeChangeObserver = observeCalloutSizeChange(
705
- calloutMessageElement,
706
- (width, height) => {
707
- anchorVisibleRectEffect.check(`callout_size_change (${width}x${height})`);
708
- },
709
- );
710
- anchorVisibleRectEffect.onBeforeAutoCheck(() => {
711
- // prevent feedback loop because check triggers size change which triggers check...
712
- calloutSizeChangeObserver.disable();
713
- return () => {
714
- calloutSizeChangeObserver.enable();
715
- };
716
- });
717
-
718
- return {
719
- update: anchorVisibleRectEffect.check,
720
- stop: () => {
721
- calloutSizeChangeObserver.disconnect();
722
- anchorVisibleRectEffect.disconnect();
723
- },
724
- };
725
- };
726
-
727
- const observeCalloutSizeChange = (elementSizeToObserve, callback) => {
728
- let lastContentWidth;
729
- let lastContentHeight;
730
- const resizeObserver = new ResizeObserver((entries) => {
731
- const [entry] = entries;
732
- const { width, height } = entry.contentRect;
733
- // Debounce tiny changes that are likely sub-pixel rounding
734
- if (lastContentWidth !== undefined) {
735
- const widthDiff = Math.abs(width - lastContentWidth);
736
- const heightDiff = Math.abs(height - lastContentHeight);
737
- const threshold = 1; // Ignore changes smaller than 1px
738
- if (widthDiff < threshold && heightDiff < threshold) {
739
- return;
740
- }
741
- }
742
- lastContentWidth = width;
743
- lastContentHeight = height;
744
- callback(width, height);
745
- });
746
- resizeObserver.observe(elementSizeToObserve);
747
-
748
- return {
749
- disable: () => {
750
- resizeObserver.unobserve(elementSizeToObserve);
751
- },
752
- enable: () => {
753
- resizeObserver.observe(elementSizeToObserve);
754
- },
755
- disconnect: () => {
756
- resizeObserver.disconnect();
757
- },
758
- };
759
- };
760
-
761
- const escapeHtml = (string) => {
762
- return string
763
- .replace(/&/g, "&amp;")
764
- .replace(/</g, "&lt;")
765
- .replace(/>/g, "&gt;")
766
- .replace(/"/g, "&quot;")
767
- .replace(/'/g, "&#039;");
768
- };
769
-
770
- /**
771
- * Checks if a string is a full HTML document (starts with DOCTYPE)
772
- * @param {string} content - The content to check
773
- * @returns {boolean} - True if it looks like a complete HTML document
774
- */
775
- const isHtmlDocument = (content) => {
776
- if (typeof content !== "string") {
777
- return false;
778
- }
779
- // Trim whitespace and check if it starts with DOCTYPE (case insensitive)
780
- const trimmed = content.trim();
781
- return /^<!doctype\s+html/i.test(trimmed);
782
- };
783
-
784
- // It's ok to do this because the element is absolutely positioned
785
- const cloneCalloutToMeasureNaturalSize = (calloutElement) => {
786
- // Create invisible clone to measure natural size
787
- const calloutElementClone = calloutElement.cloneNode(true);
788
- calloutElementClone.style.visibility = "hidden";
789
- const calloutMessageElementClone = calloutElementClone.querySelector(
790
- ".navi_callout_message",
791
- );
792
- // Reset any overflow constraints on the clone
793
- calloutMessageElementClone.style.maxHeight = "";
794
- calloutMessageElementClone.style.overflowY = "";
795
-
796
- // Add clone to DOM to measure
797
- calloutElement.parentNode.appendChild(calloutElementClone);
798
-
799
- return calloutElementClone;
800
- };
801
-
802
- /**
803
- * Generates SVG path for callout with arrow on top
804
- * @param {number} width - Callout width
805
- * @param {number} height - Callout height
806
- * @param {number} arrowPosition - Horizontal position of arrow
807
- * @returns {string} - SVG markup
808
- */
809
- const generateSvgWithTopArrow = (width, height, arrowPosition) => {
810
- // Calculate valid arrow position range
811
- const arrowLeft =
812
- ARROW_WIDTH / 2 + CORNER_RADIUS + BORDER_WIDTH + ARROW_SPACING;
813
- const minArrowPos = arrowLeft;
814
- const maxArrowPos = width - arrowLeft;
815
- const constrainedArrowPos = Math.max(
816
- minArrowPos,
817
- Math.min(arrowPosition, maxArrowPos),
818
- );
819
-
820
- // Calculate content height
821
- const contentHeight = height - ARROW_HEIGHT;
822
-
823
- // Create two paths: one for the border (outer) and one for the content (inner)
824
- const adjustedWidth = width;
825
- const adjustedHeight = contentHeight + ARROW_HEIGHT;
826
-
827
- // Slight adjustment for visual balance
828
- const innerArrowWidthReduction = Math.min(BORDER_WIDTH * 0.3, 1);
829
-
830
- // Outer path (border)
831
- const outerPath = `
832
- M${CORNER_RADIUS},${ARROW_HEIGHT}
833
- H${constrainedArrowPos - ARROW_WIDTH / 2}
834
- L${constrainedArrowPos},0
835
- L${constrainedArrowPos + ARROW_WIDTH / 2},${ARROW_HEIGHT}
836
- H${width - CORNER_RADIUS}
837
- Q${width},${ARROW_HEIGHT} ${width},${ARROW_HEIGHT + CORNER_RADIUS}
838
- V${adjustedHeight - CORNER_RADIUS}
839
- Q${width},${adjustedHeight} ${width - CORNER_RADIUS},${adjustedHeight}
840
- H${CORNER_RADIUS}
841
- Q0,${adjustedHeight} 0,${adjustedHeight - CORNER_RADIUS}
842
- V${ARROW_HEIGHT + CORNER_RADIUS}
843
- Q0,${ARROW_HEIGHT} ${CORNER_RADIUS},${ARROW_HEIGHT}
844
- `;
845
-
846
- // Inner path (content) - keep arrow width almost the same
847
- const innerRadius = Math.max(0, CORNER_RADIUS - BORDER_WIDTH);
848
- const innerPath = `
849
- M${innerRadius + BORDER_WIDTH},${ARROW_HEIGHT + BORDER_WIDTH}
850
- H${constrainedArrowPos - ARROW_WIDTH / 2 + innerArrowWidthReduction}
851
- L${constrainedArrowPos},${BORDER_WIDTH}
852
- L${constrainedArrowPos + ARROW_WIDTH / 2 - innerArrowWidthReduction},${ARROW_HEIGHT + BORDER_WIDTH}
853
- H${width - innerRadius - BORDER_WIDTH}
854
- Q${width - BORDER_WIDTH},${ARROW_HEIGHT + BORDER_WIDTH} ${width - BORDER_WIDTH},${ARROW_HEIGHT + innerRadius + BORDER_WIDTH}
855
- V${adjustedHeight - innerRadius - BORDER_WIDTH}
856
- Q${width - BORDER_WIDTH},${adjustedHeight - BORDER_WIDTH} ${width - innerRadius - BORDER_WIDTH},${adjustedHeight - BORDER_WIDTH}
857
- H${innerRadius + BORDER_WIDTH}
858
- Q${BORDER_WIDTH},${adjustedHeight - BORDER_WIDTH} ${BORDER_WIDTH},${adjustedHeight - innerRadius - BORDER_WIDTH}
859
- V${ARROW_HEIGHT + innerRadius + BORDER_WIDTH}
860
- Q${BORDER_WIDTH},${ARROW_HEIGHT + BORDER_WIDTH} ${innerRadius + BORDER_WIDTH},${ARROW_HEIGHT + BORDER_WIDTH}
861
- `;
862
-
863
- return /* html */ `
864
- <svg
865
- width="${adjustedWidth}"
866
- height="${adjustedHeight}"
867
- viewBox="0 0 ${adjustedWidth} ${adjustedHeight}"
868
- fill="none"
869
- xmlns="http://www.w3.org/2000/svg"
870
- role="presentation"
871
- aria-hidden="true"
872
- >
873
- <path d="${outerPath}" class="navi_callout_border" />
874
- <path d="${innerPath}" class="navi_callout_background" />
875
- </svg>`;
876
- };
877
-
878
- /**
879
- * Generates SVG path for callout with arrow on bottom
880
- * @param {number} width - Callout width
881
- * @param {number} height - Callout height
882
- * @param {number} arrowPosition - Horizontal position of arrow
883
- * @returns {string} - SVG markup
884
- */
885
- const generateSvgWithBottomArrow = (width, height, arrowPosition) => {
886
- // Calculate valid arrow position range
887
- const arrowLeft =
888
- ARROW_WIDTH / 2 + CORNER_RADIUS + BORDER_WIDTH + ARROW_SPACING;
889
- const minArrowPos = arrowLeft;
890
- const maxArrowPos = width - arrowLeft;
891
- const constrainedArrowPos = Math.max(
892
- minArrowPos,
893
- Math.min(arrowPosition, maxArrowPos),
894
- );
895
-
896
- // Calculate content height
897
- const contentHeight = height - ARROW_HEIGHT;
898
-
899
- // Create two paths: one for the border (outer) and one for the content (inner)
900
- const adjustedWidth = width;
901
- const adjustedHeight = contentHeight + ARROW_HEIGHT;
902
-
903
- // For small border widths, keep inner arrow nearly the same size as outer
904
- const innerArrowWidthReduction = Math.min(BORDER_WIDTH * 0.3, 1);
905
-
906
- // Outer path with rounded corners
907
- const outerPath = `
908
- M${CORNER_RADIUS},0
909
- H${width - CORNER_RADIUS}
910
- Q${width},0 ${width},${CORNER_RADIUS}
911
- V${contentHeight - CORNER_RADIUS}
912
- Q${width},${contentHeight} ${width - CORNER_RADIUS},${contentHeight}
913
- H${constrainedArrowPos + ARROW_WIDTH / 2}
914
- L${constrainedArrowPos},${adjustedHeight}
915
- L${constrainedArrowPos - ARROW_WIDTH / 2},${contentHeight}
916
- H${CORNER_RADIUS}
917
- Q0,${contentHeight} 0,${contentHeight - CORNER_RADIUS}
918
- V${CORNER_RADIUS}
919
- Q0,0 ${CORNER_RADIUS},0
920
- `;
921
-
922
- // Inner path with correct arrow direction and color
923
- const innerRadius = Math.max(0, CORNER_RADIUS - BORDER_WIDTH);
924
- const innerPath = `
925
- M${innerRadius + BORDER_WIDTH},${BORDER_WIDTH}
926
- H${width - innerRadius - BORDER_WIDTH}
927
- Q${width - BORDER_WIDTH},${BORDER_WIDTH} ${width - BORDER_WIDTH},${innerRadius + BORDER_WIDTH}
928
- V${contentHeight - innerRadius - BORDER_WIDTH}
929
- Q${width - BORDER_WIDTH},${contentHeight - BORDER_WIDTH} ${width - innerRadius - BORDER_WIDTH},${contentHeight - BORDER_WIDTH}
930
- H${constrainedArrowPos + ARROW_WIDTH / 2 - innerArrowWidthReduction}
931
- L${constrainedArrowPos},${adjustedHeight - BORDER_WIDTH}
932
- L${constrainedArrowPos - ARROW_WIDTH / 2 + innerArrowWidthReduction},${contentHeight - BORDER_WIDTH}
933
- H${innerRadius + BORDER_WIDTH}
934
- Q${BORDER_WIDTH},${contentHeight - BORDER_WIDTH} ${BORDER_WIDTH},${contentHeight - innerRadius - BORDER_WIDTH}
935
- V${innerRadius + BORDER_WIDTH}
936
- Q${BORDER_WIDTH},${BORDER_WIDTH} ${innerRadius + BORDER_WIDTH},${BORDER_WIDTH}
937
- `;
938
-
939
- return /* html */ `
940
- <svg
941
- width="${adjustedWidth}"
942
- height="${adjustedHeight}"
943
- viewBox="0 0 ${adjustedWidth} ${adjustedHeight}"
944
- fill="none"
945
- xmlns="http://www.w3.org/2000/svg"
946
- role="presentation"
947
- aria-hidden="true"
948
- >
949
- <path d="${outerPath}" class="navi_callout_border" />
950
- <path d="${innerPath}" class="navi_callout_background" />
951
- </svg>`;
952
- };
953
-
954
- /**
955
- * Generates SVG path for callout without arrow (simple rectangle)
956
- * @param {number} width - Callout width
957
- * @param {number} height - Callout height
958
- * @returns {string} - SVG markup
959
- */
960
- const generateSvgWithoutArrow = (width, height) => {
961
- return /* html */ `
962
- <svg
963
- width="${width}"
964
- height="${height}"
965
- viewBox="0 0 ${width} ${height}"
966
- fill="none"
967
- xmlns="http://www.w3.org/2000/svg"
968
- role="presentation"
969
- aria-hidden="true"
970
- >
971
- <rect
972
- class="navi_callout_border"
973
- x="0"
974
- y="0"
975
- width="${width}"
976
- height="${height}"
977
- rx="${CORNER_RADIUS}"
978
- ry="${CORNER_RADIUS}"
979
- />
980
- <rect
981
- class="navi_callout_background"
982
- x="${BORDER_WIDTH}"
983
- y="${BORDER_WIDTH}"
984
- width="${width - BORDER_WIDTH * 2}"
985
- height="${height - BORDER_WIDTH * 2}"
986
- rx="${Math.max(0, CORNER_RADIUS - BORDER_WIDTH)}"
987
- ry="${Math.max(0, CORNER_RADIUS - BORDER_WIDTH)}"
988
- />
989
- </svg>`;
990
- };