@seeqdev/qomponents 0.0.20 → 0.0.22

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 (104) hide show
  1. package/README.md +135 -135
  2. package/dist/Button/Button.types.d.ts +4 -0
  3. package/dist/FontCustom.woff +0 -0
  4. package/dist/FontCustom.woff2 +0 -0
  5. package/dist/Icon/Icon.types.d.ts +4 -6
  6. package/dist/Tooltip/QTip.stories.d.ts +5 -0
  7. package/dist/Tooltip/QTip.types.d.ts +13 -0
  8. package/dist/Tooltip/QTipPerformance.stories.d.ts +5 -0
  9. package/dist/Tooltip/Qtip.d.ts +25 -0
  10. package/dist/Tooltip/Tooltip.d.ts +7 -1
  11. package/dist/Tooltip/TooltipPerformance.stories.d.ts +5 -0
  12. package/dist/Tooltip/index.d.ts +2 -1
  13. package/dist/example/.eslintrc.cjs +14 -14
  14. package/dist/example/README.md +33 -33
  15. package/dist/example/index.html +13 -13
  16. package/dist/example/package.json +30 -30
  17. package/dist/example/src/ComplexSelectExample.tsx +81 -81
  18. package/dist/example/src/Example.tsx +167 -158
  19. package/dist/example/src/index.css +102 -93
  20. package/dist/example/src/main.tsx +10 -10
  21. package/dist/example/src/vite-env.d.ts +1 -1
  22. package/dist/example/tsconfig.json +33 -33
  23. package/dist/example/tsconfig.node.json +12 -12
  24. package/dist/example/vite.config.ts +12 -12
  25. package/dist/index.d.ts +2 -1
  26. package/dist/index.esm.js +3132 -220
  27. package/dist/index.esm.js.map +1 -1
  28. package/dist/index.js +3132 -219
  29. package/dist/index.js.map +1 -1
  30. package/dist/styles.css +2178 -2121
  31. package/package.json +78 -73
  32. package/dist/Button/Button.js +0 -74
  33. package/dist/Button/Button.js.map +0 -1
  34. package/dist/Button/Button.stories.js +0 -77
  35. package/dist/Button/Button.stories.js.map +0 -1
  36. package/dist/Button/Button.test.js +0 -49
  37. package/dist/Button/Button.test.js.map +0 -1
  38. package/dist/Button/Button.types.js +0 -4
  39. package/dist/Button/Button.types.js.map +0 -1
  40. package/dist/Button/index.js +0 -2
  41. package/dist/Button/index.js.map +0 -1
  42. package/dist/Checkbox/Checkbox.js +0 -23
  43. package/dist/Checkbox/Checkbox.js.map +0 -1
  44. package/dist/Checkbox/Checkbox.stories.js +0 -29
  45. package/dist/Checkbox/Checkbox.stories.js.map +0 -1
  46. package/dist/Checkbox/Checkbox.test.js +0 -94
  47. package/dist/Checkbox/Checkbox.test.js.map +0 -1
  48. package/dist/Checkbox/Checkbox.types.js +0 -2
  49. package/dist/Checkbox/Checkbox.types.js.map +0 -1
  50. package/dist/Checkbox/index.js +0 -2
  51. package/dist/Checkbox/index.js.map +0 -1
  52. package/dist/Icon/Icon.js +0 -54
  53. package/dist/Icon/Icon.js.map +0 -1
  54. package/dist/Icon/Icon.stories.js +0 -40
  55. package/dist/Icon/Icon.stories.js.map +0 -1
  56. package/dist/Icon/Icon.test.js +0 -55
  57. package/dist/Icon/Icon.test.js.map +0 -1
  58. package/dist/Icon/Icon.types.js +0 -16
  59. package/dist/Icon/Icon.types.js.map +0 -1
  60. package/dist/Icon/index.js +0 -2
  61. package/dist/Icon/index.js.map +0 -1
  62. package/dist/Select/Select.js +0 -168
  63. package/dist/Select/Select.js.map +0 -1
  64. package/dist/Select/Select.stories.js +0 -72
  65. package/dist/Select/Select.stories.js.map +0 -1
  66. package/dist/Select/Select.test.js +0 -161
  67. package/dist/Select/Select.test.js.map +0 -1
  68. package/dist/Select/Select.types.js +0 -2
  69. package/dist/Select/Select.types.js.map +0 -1
  70. package/dist/Select/index.js +0 -2
  71. package/dist/Select/index.js.map +0 -1
  72. package/dist/TextArea/TextArea.js +0 -17
  73. package/dist/TextArea/TextArea.js.map +0 -1
  74. package/dist/TextArea/TextArea.stories.js +0 -39
  75. package/dist/TextArea/TextArea.stories.js.map +0 -1
  76. package/dist/TextArea/TextArea.test.js +0 -68
  77. package/dist/TextArea/TextArea.test.js.map +0 -1
  78. package/dist/TextArea/TextArea.types.js +0 -2
  79. package/dist/TextArea/TextArea.types.js.map +0 -1
  80. package/dist/TextArea/index.js +0 -2
  81. package/dist/TextArea/index.js.map +0 -1
  82. package/dist/TextField/TextField.js +0 -58
  83. package/dist/TextField/TextField.js.map +0 -1
  84. package/dist/TextField/TextField.stories.js +0 -41
  85. package/dist/TextField/TextField.stories.js.map +0 -1
  86. package/dist/TextField/TextField.test.js +0 -35
  87. package/dist/TextField/TextField.test.js.map +0 -1
  88. package/dist/TextField/TextField.types.js +0 -2
  89. package/dist/TextField/TextField.types.js.map +0 -1
  90. package/dist/TextField/index.js +0 -2
  91. package/dist/TextField/index.js.map +0 -1
  92. package/dist/Tooltip/Tooltip.js +0 -30
  93. package/dist/Tooltip/Tooltip.js.map +0 -1
  94. package/dist/Tooltip/Tooltip.stories.js +0 -32
  95. package/dist/Tooltip/Tooltip.stories.js.map +0 -1
  96. package/dist/Tooltip/Tooltip.types.js +0 -3
  97. package/dist/Tooltip/Tooltip.types.js.map +0 -1
  98. package/dist/Tooltip/index.js +0 -2
  99. package/dist/Tooltip/index.js.map +0 -1
  100. package/dist/example/package-lock.json +0 -3369
  101. package/dist/types.js +0 -2
  102. package/dist/types.js.map +0 -1
  103. package/dist/utils/browserId.js +0 -29
  104. package/dist/utils/browserId.js.map +0 -1
package/dist/index.esm.js CHANGED
@@ -30,22 +30,267 @@ const browserName = browserId && browserId.split(' ', 2)[0];
30
30
  browserId && parseInt(browserId.split(' ', 2)[1], 10);
31
31
  const browserIsFirefox = browserId && browserName === 'Firefox';
32
32
 
33
+ const colorClassesThemeLight = {
34
+ 'theme': 'tw-text-sq-color-dark',
35
+ 'white': 'tw-text-white',
36
+ 'dark-gray': 'tw-text-sq-fairly-dark-gray',
37
+ 'warning': 'tw-text-sq-warning-color',
38
+ 'darkish-gray': 'tw-text-sq-darkish-gray',
39
+ 'gray': 'tw-text-sq-disabled-gray',
40
+ 'color': '',
41
+ 'info': 'tw-text-sq-link',
42
+ 'text': 'tw-text-sq-text-color',
43
+ 'inherit': '',
44
+ 'danger': 'tw-text-sq-danger-color',
45
+ 'theme-light': 'tw-text-sq-color-light',
46
+ 'success': 'tw-text-sq-success-color',
47
+ };
48
+ const colorClassesThemeDark = {
49
+ 'theme': 'dark:tw-text-sq-color-dark-dark',
50
+ 'white': '',
51
+ 'dark-gray': 'tw-text-sq-fairly-dark-gray',
52
+ 'warning': '',
53
+ 'darkish-gray': 'tw-text-sq-darkish-gray',
54
+ 'gray': 'dark:tw-text-sq-dark-disabled-gray',
55
+ 'color': '',
56
+ 'info': 'dark:tw-text-sq-link-dark',
57
+ 'text': 'dark:tw-text-sq-dark-text',
58
+ 'inherit': '',
59
+ 'danger': 'tw-text-sq-danger-color',
60
+ 'theme-light': 'tw-text-sq-color-light',
61
+ 'success': 'tw-text-sq-success-color',
62
+ };
63
+ /**
64
+ * Icon:
65
+ * - access to Seeq custom icons by providing the desired icon
66
+ * - leverage "type" to style your icon
67
+ */
68
+ const Icon = ({ onClick, icon, type = 'theme', extraClassNames, id, large, small, color, testId, customId, tooltip, tooltipPlacement, number, isHtmlTooltip = false, tooltipTestId, tooltipDelay = 0, }) => {
69
+ if ((type === 'color' && (color === undefined || color === '')) || (color && type !== 'color')) {
70
+ const errorMessage = color === undefined || color === ''
71
+ ? 'Icon with type="color" must have prop color specified.'
72
+ : 'Icon with prop color must have type="color".';
73
+ return React__default.createElement("div", { className: "tw-text-sq-danger-color" }, errorMessage);
74
+ }
75
+ const iconPrefix = icon.startsWith('fc') ? 'fc' : 'fa';
76
+ const style = type === 'color' && color ? { color } : {};
77
+ const appliedClassNames = `${iconPrefix} ${icon} ${small ? 'fa-sm' : ''} ${large ? 'fa-lg' : ''}
78
+ ${colorClassesThemeLight[type]} ${colorClassesThemeDark[type]} ${onClick ? 'cursor-pointer' : ''} ${extraClassNames}`;
79
+ const tooltipData = tooltip
80
+ ? {
81
+ 'data-qtip-text': tooltip,
82
+ 'data-qtip-placement': tooltipPlacement,
83
+ 'data-qtip-is-html': isHtmlTooltip,
84
+ 'data-qtip-testid': tooltipTestId,
85
+ 'data-qtip-delay': tooltipDelay,
86
+ }
87
+ : undefined;
88
+ return (React__default.createElement("i", { className: appliedClassNames, style: style, onClick: onClick, "data-testid": testId, "data-customid": customId, id: id, "data-number": number, ...tooltipData }));
89
+ };
90
+
91
+ /**
92
+ * All-in-one Button:
93
+ * - use "variant" to achieve the desired style
94
+ * - include tooltips and/or icons
95
+ */
96
+ const Button = ({ onClick, label, variant = 'outline', type = 'button', size = 'sm', disabled, extraClassNames, id, testId, stopPropagation = true, tooltip, tooltipOptions, iconStyle = 'text', icon, iconColor, preventBlur = false, isHtmlTooltip = false, tooltipTestId, }) => {
97
+ const baseClasses = 'tw-py-1 tw-px-2.5 tw-rounded-sm focus:tw-ring-0 disabled:tw-pointer-events-none';
98
+ const baseClassesByVariant = {
99
+ 'outline': 'tw-border-solid tw-border',
100
+ 'theme': 'disabled:tw-opacity-50',
101
+ 'danger': 'tw-bg-sq-danger-color hover:tw-bg-sq-danger-color-hover disabled:tw-opacity-50',
102
+ 'theme-light': 'disabled:tw-opacity-50',
103
+ 'no-border': '',
104
+ 'warning': 'tw-bg-sq-warning-color',
105
+ };
106
+ const textClassesByVariantLightTheme = {
107
+ 'outline': 'tw-text-sq-text-color',
108
+ 'theme': 'tw-text-white',
109
+ 'theme-light': 'tw-text-white',
110
+ 'danger': 'tw-text-white',
111
+ 'no-border': 'tw-text-sq-text-color',
112
+ 'warning': 'tw-text-white',
113
+ };
114
+ const textClassesByVariantDarkTheme = {
115
+ 'outline': 'dark:tw-text-sq-dark-text',
116
+ 'theme': 'dark:tw-text-white',
117
+ 'theme-light': 'dark:tw-text-white',
118
+ 'danger': 'dark:tw-text-white',
119
+ 'no-border': 'dark:tw-text-sq-dark-text',
120
+ 'warning': 'dark:tw-text-white',
121
+ };
122
+ const classesByVariantLightTheme = {
123
+ 'outline': 'tw-border-sq-disabled-gray hover:tw-bg-sq-light-gray' +
124
+ ' focus:tw-bg-sq-dark-gray active:tw-bg-sq-dark-gray focus:tw-border-sq-color-dark active:tw-border-sq-color-dark',
125
+ 'theme': 'tw-bg-sq-color-dark hover:tw-bg-sq-color-highlight',
126
+ 'danger': '',
127
+ 'theme-light': 'tw-bg-sq-icon hover:tw-bg-sq-link',
128
+ 'no-border': '',
129
+ 'warning': 'tw-bg-sq-warning-color',
130
+ };
131
+ const classesByVariantDarkTheme = {
132
+ 'outline': 'dark:tw-border-sq-dark-disabled-gray dark:hover:tw-bg-sq-highlight-color-dark' +
133
+ ' dark:focus:tw-bg-sq-dark-gray dark:active:tw-bg-sq-dark-gray dark:focus:tw-border-sq-color-dark' +
134
+ ' dark:active:tw-border-sq-color-dark',
135
+ 'theme': 'dark:tw-bg-sq-color-dark dark:hover:tw-bg-sq-color-highlight',
136
+ 'danger': '',
137
+ 'theme-light': 'dark:tw-bg-sq-icon-dark dark:hover:tw-bg-sq-link-dark',
138
+ 'no-border': '',
139
+ 'warning': '',
140
+ };
141
+ const sizeClasses = {
142
+ sm: 'tw-text-sm',
143
+ lg: 'tw-text-xl',
144
+ };
145
+ const appliedClasses = `${baseClasses} ${baseClassesByVariant[variant]} ${sizeClasses[size]} ${classesByVariantLightTheme[variant]} ${classesByVariantDarkTheme[variant]} ${textClassesByVariantLightTheme[variant]} ${textClassesByVariantDarkTheme[variant]} ${extraClassNames}`;
146
+ let tooltipData = undefined;
147
+ if (tooltip) {
148
+ tooltipData = {
149
+ 'data-qtip-text': tooltip,
150
+ 'data-qtip-placement': tooltipOptions?.position,
151
+ 'data-qtip-is-html': isHtmlTooltip,
152
+ 'data-qtip-testid': tooltipTestId,
153
+ 'data-qtip-delay': tooltipOptions?.delay ?? 0,
154
+ };
155
+ }
156
+ return (React__default.createElement("button", { id: id, ...tooltipData, disabled: disabled, "data-testid": testId, type: type === 'link' || (type === 'submit' && browserIsFirefox) ? 'button' : type, onClick: (e) => {
157
+ stopPropagation && e.stopPropagation();
158
+ onClick && onClick();
159
+ }, onMouseDown: (e) => {
160
+ if (preventBlur) {
161
+ e.preventDefault();
162
+ }
163
+ }, className: appliedClasses },
164
+ icon && (React__default.createElement(Icon, { icon: icon, type: iconStyle, color: iconColor, extraClassNames: label ? `tw-mr-1 ${textClassesByVariantLightTheme[variant]} ${textClassesByVariantDarkTheme[variant]}` : '', testId: `${id}_spinner` })),
165
+ label));
166
+ };
167
+
168
+ const errorClasses$2 = 'tw-border-sq-danger-color';
169
+ const borderColorClasses$2 = [
170
+ 'tw-border-sq-disabled-gray',
171
+ 'dark:tw-border-sq-dark-disabled-gray',
172
+ 'dark:focus:tw-border-sq-color-dark-dark',
173
+ 'dark:active:tw-border-sq-color-dark-dark',
174
+ 'focus:tw-border-sq-color-dark',
175
+ 'active:tw-border-sq-color-dark',
176
+ ].join(' ');
177
+ const baseClasses$3 = 'tw-h-inputs tw-leading-normal tw-outline-none tw-py-1 tw-px-3' +
178
+ ' disabled:tw-pointer-events-none' +
179
+ ' disabled:tw-cursor-not-allowed tw-p-1 tw-border-solid tw-border tw-placeholder-gray-400' +
180
+ ' dark:tw-placeholder-sq-dark-text-lighter specTextField';
181
+ const darkTheme$1 = 'dark:tw-bg-sq-dark-background dark:tw-text-sq-dark-text';
182
+ const lightTheme$1 = 'tw-text-sq-text-color';
183
+ const sizeClasses = {
184
+ sm: 'tw-text-sm',
185
+ lg: 'tw-text-xl',
186
+ };
187
+ /**
188
+ * Textfield.
189
+ */
190
+ const TextField = React__default.forwardRef((props, ref) => {
191
+ const { readonly = false, onChange, onKeyUp, id, name, size = 'sm', value, placeholder, extraClassNames, testId, type = 'text', inputGroup, step, showError, } = props;
192
+ const internalRef = useRef(null);
193
+ const [cursor, setCursor] = useState(null);
194
+ const setAllRefs = (receivedRef) => {
195
+ if (ref)
196
+ ref.current = receivedRef;
197
+ internalRef.current = receivedRef;
198
+ };
199
+ useEffect(() => {
200
+ const input = internalRef.current;
201
+ if (input && type !== 'number')
202
+ input.setSelectionRange(cursor, cursor);
203
+ }, [ref, cursor, value]);
204
+ const handleChange = (e) => {
205
+ setCursor(e.target.selectionStart);
206
+ onChange && onChange(e);
207
+ };
208
+ useEffect(() => {
209
+ /**
210
+ * we need to change the value only if it's different since the internal state of "input" will change it anyway
211
+ * this will only be the case when the value has been changed externally via store (undo / redo)
212
+ */
213
+ if (value !== null && value !== undefined && value !== internalRef.current?.value && internalRef.current) {
214
+ // we need to use this method because using the value props directly will switch the input to a "controlled"
215
+ // component
216
+ internalRef.current.value = `${value}`;
217
+ }
218
+ }, [value]);
219
+ let borderRadius = 'tw-rounded-sm';
220
+ if (inputGroup === 'left') {
221
+ borderRadius = 'tw-rounded-l-sm tw-border-r-0 focus:tw-border-r' + ' active:tw-border-r';
222
+ }
223
+ else if (inputGroup === 'right') {
224
+ borderRadius = 'tw-rounded-r-sm tw-border-l-0 focus:tw-border-l active:tw-border-l';
225
+ }
226
+ const appliedClasses = `${baseClasses$3} ${sizeClasses[size]} ${extraClassNames} ${lightTheme$1} ${darkTheme$1} ${borderRadius} ${showError ? errorClasses$2 : borderColorClasses$2} `;
227
+ return (React__default.createElement("input", { ref: setAllRefs, "data-testid": testId, name: name, id: id, type: type, value: value, className: appliedClasses, placeholder: placeholder, disabled: readonly, autoComplete: "none", onChange: handleChange, onKeyUp: onKeyUp, step: step }));
228
+ });
229
+
230
+ const alignment = 'tw-flex tw-items-center';
231
+ const labelClasses = 'tw-ml-1.5 tw-text-sm';
232
+ const baseClasses$2 = 'tw-border-1 tw-h-3.5 tw-w-3.5 focus:tw-ring-0 focus:tw-ring-offset-0 tw-outline-none focus:tw-outline-none' +
233
+ ' dark:tw-bg-sq-dark-background dark:tw-border-sq-dark-text dark:checked:tw-bg-sq-dark-text' +
234
+ ' checked:tw-text-sq-text-color' +
235
+ ' disabled:tw-text-sq-fairly-dark-gray';
236
+ const checkboxClasses = `tw-form-checkbox tw-rounded ${baseClasses$2}`;
237
+ const radioClasses = `tw-form-radio ${baseClasses$2}`;
238
+ /**
239
+ * Checkbox and Radio Box Component.
240
+ */
241
+ const Checkbox = (props) => {
242
+ const { type = 'checkbox', value, disabled = false, label, onChange, onClick, onKeyDown, checked, defaultChecked, id, name, extraClassNames, extraLabelClassNames, testId, } = props;
243
+ const assignedId = id ?? 'checkbox_' + Math.random();
244
+ return (React__default.createElement("span", { className: `${alignment} ${extraClassNames}` },
245
+ React__default.createElement("input", { value: value, type: type, "data-testid": testId, name: name, id: assignedId, checked: checked, defaultChecked: defaultChecked, className: `${type === 'checkbox' ? checkboxClasses : radioClasses} ${disabled ? 'tw-cursor-not-allowed' : 'tw-cursor-pointer'}`, disabled: disabled, onClick: onClick, onChange: onChange, onKeyDown: onKeyDown }),
246
+ React__default.createElement("label", { htmlFor: assignedId, className: `${labelClasses} ${extraLabelClassNames} ${disabled
247
+ ? 'tw-cursor-not-allowed dark:tw-text-sq-fairly-dark-gray tw-text-sq-fairly-dark-gray'
248
+ : 'tw-cursor-pointer tw-text-sq-text-color dark:tw-text-sq-dark-text'}` }, label)));
249
+ };
250
+
251
+ const baseClasses$1 = 'tw-leading-normal tw-outline-none tw-py-1 tw-px-3 tw-rounded-sm' +
252
+ ' disabled:tw-cursor-not-allowed tw-p-1 tw-border-solid tw-border tw-text-sm';
253
+ const darkTheme = 'dark:tw-bg-sq-dark-background dark:tw-text-sq-dark-text ' + 'dark:tw-placeholder-sq-dark-text-lighter';
254
+ const lightTheme = 'tw-text-sq-text-color tw-placeholder-gray-400';
255
+ const errorClasses$1 = 'tw-border-sq-danger-color';
256
+ const borderColorClasses$1 = [
257
+ 'tw-border-sq-disabled-gray',
258
+ 'dark:tw-border-sq-dark-disabled-gray',
259
+ 'dark:focus:tw-border-sq-color-dark-dark',
260
+ 'dark:active:tw-border-sq-color-dark-dark',
261
+ 'focus:tw-border-sq-color-dark',
262
+ 'active:tw-border-sq-color-dark',
263
+ ].join(' ');
264
+ /**
265
+ * TextArea.
266
+ */
267
+ const TextArea = ({ readonly = false, onChange, onKeyUp, id, name, rows = 3, cols = undefined, value, placeholder, extraClassNames, testId, autofocus = false, showError, }) => {
268
+ const appliedClasses = `${baseClasses$1} ${extraClassNames} ${lightTheme} ${darkTheme} ${showError ? errorClasses$1 : borderColorClasses$1}`;
269
+ return (React__default.createElement("textarea", { "data-testid": testId, name: name, id: id, value: value, className: appliedClasses, placeholder: placeholder, disabled: readonly, onChange: onChange, onKeyUp: onKeyUp, rows: rows, cols: cols, autoFocus: autofocus }));
270
+ };
271
+
33
272
  const DEFAULT_TOOL_TIP_DELAY = 1000;
34
273
 
35
274
  /**
36
- * This component displays a Tooltip for the provided children.
275
+ * @deprecated
276
+ * Note: Tooltip has been replaced by QTip - a singleton JS tooltip that behaves well even with overflow settings :)
277
+ * See @QTip for more info!
278
+ *
279
+ * This component displays a Tooltip for the provided children. It is a CSS only tooltip that will not display
280
+ * correctly if a parent element has an overflow CSS property assigned. Please use QTip to ensure your tooltips
281
+ * display correctly.
37
282
  */
38
283
  const Tooltip = ({ position = 'bottom', children, text, delay = DEFAULT_TOOL_TIP_DELAY, }) => {
39
284
  const arrowBaseClasses = "before:tw-content-[''] before:tw-absolute before:tw-border-8";
40
285
  const centerArrowVertically = 'before:tw-top-1/2 before:-tw-translate-y-1/2';
41
286
  const centerArrowHorizontally = 'before:tw-left-1/2 before:-tw-translate-x-1/2';
42
- const arrowRight = `${arrowBaseClasses} ${centerArrowVertically} before:tw-right-[100%] before:tw-border-y-transparent
287
+ const arrowRight = `${arrowBaseClasses} ${centerArrowVertically} before:tw-right-[100%] before:tw-border-y-transparent
43
288
  before:tw-border-l-transparent before:tw-border-r-black`;
44
- const arrowLeft = `${arrowBaseClasses} ${centerArrowVertically} before:tw-left-[100%] before:tw-border-y-transparent
289
+ const arrowLeft = `${arrowBaseClasses} ${centerArrowVertically} before:tw-left-[100%] before:tw-border-y-transparent
45
290
  before:tw-border-l-black before:tw-border-r-transparent`;
46
- const arrowBottom = `${arrowBaseClasses} ${centerArrowHorizontally} before:-tw-top-4 before:tw-border-b-black
291
+ const arrowBottom = `${arrowBaseClasses} ${centerArrowHorizontally} before:-tw-top-4 before:tw-border-b-black
47
292
  before:tw-border-r-transparent before:tw-border-l-transparent before:tw-border-t-transparent`;
48
- const arrowTop = `${arrowBaseClasses} ${centerArrowHorizontally} before:-tw-bottom-4 before:tw-border-b-transparent
293
+ const arrowTop = `${arrowBaseClasses} ${centerArrowHorizontally} before:-tw-bottom-4 before:tw-border-b-transparent
49
294
  before:tw-border-t-black before:tw-border-l-transparent before:tw-border-r-transparent`;
50
295
  const placements = {
51
296
  top: `-tw-top-2 -tw-translate-y-full tw-left-1/2 -tw-translate-x-1/2 ${arrowTop}`,
@@ -55,230 +300,2901 @@ const Tooltip = ({ position = 'bottom', children, text, delay = DEFAULT_TOOL_TIP
55
300
  };
56
301
  return (React__default.createElement("div", { className: "tw-group tw-relative tw-inline-block" },
57
302
  children,
58
- React__default.createElement("div", { className: `tw-z-50 tw-whitespace-nowrap tw-hidden group-hover:tw-inline-block group-hover:tw-delay-[${delay}ms]
303
+ React__default.createElement("div", { className: `tw-z-50 tw-whitespace-nowrap tw-hidden group-hover:tw-inline-block group-hover:tw-delay-[${delay}ms]
59
304
  tw-absolute tw-opacity-0 group-hover:tw-opacity-100 tw-rounded tw-bg-black tw-p-2 tw-text-xs tw-text-white ${placements[position]}` }, text)));
60
305
  };
61
306
 
62
- /**
63
- * Icon:
64
- * - access to Seeq custom icons by providing the desired icon
65
- * - leverage "type" to style your icon
66
- */
67
- const Icon = ({ onClick, icon, type = 'theme', extraClassNames, id, large, small, color, testId, customId, tooltip, tooltipDelay, tooltipPlacement, number, hasExternalTooltipHandler = false, }) => {
68
- if ((type === 'color' && (color === undefined || color === '')) || (color && type !== 'color')) {
69
- const errorMessage = color === undefined || color === ''
70
- ? 'Icon with type="color" must have prop color specified.'
71
- : 'Icon with prop color must have type="color".';
72
- return React__default.createElement("div", { className: "tw-text-sq-danger-color" }, errorMessage);
73
- }
74
- const colorClassesThemeLight = {
75
- 'theme': 'tw-text-sq-color-dark',
76
- 'white': 'tw-text-white',
77
- 'dark-gray': 'tw-text-sq-fairly-dark-gray',
78
- 'warning': 'tw-text-sq-warning-color',
79
- 'darkish-gray': 'tw-text-sq-darkish-gray',
80
- 'gray': 'tw-text-sq-disabled-gray',
81
- 'color': '',
82
- 'info': 'tw-text-sq-link',
83
- 'text': 'tw-text-sq-text-color',
84
- 'inherit': '',
85
- 'danger': 'tw-text-sq-danger-color',
86
- 'theme-light': 'tw-text-sq-color-light',
87
- 'success': 'tw-text-sq-success-color',
88
- };
89
- const colorClassesThemeDark = {
90
- 'theme': 'dark:tw-text-sq-color-dark-dark',
91
- 'white': '',
92
- 'dark-gray': 'tw-text-sq-fairly-dark-gray',
93
- 'warning': '',
94
- 'darkish-gray': 'tw-text-sq-darkish-gray',
95
- 'gray': 'dark:tw-text-sq-dark-disabled-gray',
96
- 'color': '',
97
- 'info': 'dark:tw-text-sq-link-dark',
98
- 'text': 'dark:tw-text-sq-dark-text',
99
- 'inherit': '',
100
- 'danger': 'tw-text-sq-danger-color',
101
- 'theme-light': 'tw-text-sq-color-light',
102
- 'success': 'tw-text-sq-success-color',
103
- };
104
- const iconPrefix = icon.startsWith('fc') ? 'fc' : 'fa';
105
- const style = type === 'color' && color ? { color } : {};
106
- const appliedClassNames = `${iconPrefix} ${icon} ${small ? 'fa-sm' : ''} ${large ? 'fa-lg' : ''}
107
- ${colorClassesThemeLight[type]} ${colorClassesThemeDark[type]} ${onClick ? 'cursor-pointer' : ''} ${extraClassNames}`;
108
- const iconTag = (React__default.createElement("i", { className: appliedClassNames, style: style, onClick: onClick, "data-testid": testId, "data-customid": customId, id: id, "data-number": number }));
109
- return !hasExternalTooltipHandler && tooltip && tooltip !== '' ? (React__default.createElement(Tooltip, { text: tooltip, delay: tooltipDelay, position: tooltipPlacement }, iconTag)) : (iconTag);
307
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
308
+
309
+ var purifyExports = {};
310
+ var purify = {
311
+ get exports(){ return purifyExports; },
312
+ set exports(v){ purifyExports = v; },
313
+ };
314
+
315
+ /*! @license DOMPurify 3.0.5 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.0.5/LICENSE */
316
+
317
+ (function (module, exports) {
318
+ (function (global, factory) {
319
+ module.exports = factory() ;
320
+ })(commonjsGlobal, (function () {
321
+ const {
322
+ entries,
323
+ setPrototypeOf,
324
+ isFrozen,
325
+ getPrototypeOf,
326
+ getOwnPropertyDescriptor
327
+ } = Object;
328
+ let {
329
+ freeze,
330
+ seal,
331
+ create
332
+ } = Object; // eslint-disable-line import/no-mutable-exports
333
+
334
+ let {
335
+ apply,
336
+ construct
337
+ } = typeof Reflect !== 'undefined' && Reflect;
338
+
339
+ if (!apply) {
340
+ apply = function apply(fun, thisValue, args) {
341
+ return fun.apply(thisValue, args);
342
+ };
343
+ }
344
+
345
+ if (!freeze) {
346
+ freeze = function freeze(x) {
347
+ return x;
348
+ };
349
+ }
350
+
351
+ if (!seal) {
352
+ seal = function seal(x) {
353
+ return x;
354
+ };
355
+ }
356
+
357
+ if (!construct) {
358
+ construct = function construct(Func, args) {
359
+ return new Func(...args);
360
+ };
361
+ }
362
+
363
+ const arrayForEach = unapply(Array.prototype.forEach);
364
+ const arrayPop = unapply(Array.prototype.pop);
365
+ const arrayPush = unapply(Array.prototype.push);
366
+ const stringToLowerCase = unapply(String.prototype.toLowerCase);
367
+ const stringToString = unapply(String.prototype.toString);
368
+ const stringMatch = unapply(String.prototype.match);
369
+ const stringReplace = unapply(String.prototype.replace);
370
+ const stringIndexOf = unapply(String.prototype.indexOf);
371
+ const stringTrim = unapply(String.prototype.trim);
372
+ const regExpTest = unapply(RegExp.prototype.test);
373
+ const typeErrorCreate = unconstruct(TypeError);
374
+ function unapply(func) {
375
+ return function (thisArg) {
376
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
377
+ args[_key - 1] = arguments[_key];
378
+ }
379
+
380
+ return apply(func, thisArg, args);
381
+ };
382
+ }
383
+ function unconstruct(func) {
384
+ return function () {
385
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
386
+ args[_key2] = arguments[_key2];
387
+ }
388
+
389
+ return construct(func, args);
390
+ };
391
+ }
392
+ /* Add properties to a lookup table */
393
+
394
+ function addToSet(set, array, transformCaseFunc) {
395
+ var _transformCaseFunc;
396
+
397
+ transformCaseFunc = (_transformCaseFunc = transformCaseFunc) !== null && _transformCaseFunc !== void 0 ? _transformCaseFunc : stringToLowerCase;
398
+
399
+ if (setPrototypeOf) {
400
+ // Make 'in' and truthy checks like Boolean(set.constructor)
401
+ // independent of any properties defined on Object.prototype.
402
+ // Prevent prototype setters from intercepting set as a this value.
403
+ setPrototypeOf(set, null);
404
+ }
405
+
406
+ let l = array.length;
407
+
408
+ while (l--) {
409
+ let element = array[l];
410
+
411
+ if (typeof element === 'string') {
412
+ const lcElement = transformCaseFunc(element);
413
+
414
+ if (lcElement !== element) {
415
+ // Config presets (e.g. tags.js, attrs.js) are immutable.
416
+ if (!isFrozen(array)) {
417
+ array[l] = lcElement;
418
+ }
419
+
420
+ element = lcElement;
421
+ }
422
+ }
423
+
424
+ set[element] = true;
425
+ }
426
+
427
+ return set;
428
+ }
429
+ /* Shallow clone an object */
430
+
431
+ function clone(object) {
432
+ const newObject = create(null);
433
+
434
+ for (const [property, value] of entries(object)) {
435
+ newObject[property] = value;
436
+ }
437
+
438
+ return newObject;
439
+ }
440
+ /* This method automatically checks if the prop is function
441
+ * or getter and behaves accordingly. */
442
+
443
+ function lookupGetter(object, prop) {
444
+ while (object !== null) {
445
+ const desc = getOwnPropertyDescriptor(object, prop);
446
+
447
+ if (desc) {
448
+ if (desc.get) {
449
+ return unapply(desc.get);
450
+ }
451
+
452
+ if (typeof desc.value === 'function') {
453
+ return unapply(desc.value);
454
+ }
455
+ }
456
+
457
+ object = getPrototypeOf(object);
458
+ }
459
+
460
+ function fallbackValue(element) {
461
+ console.warn('fallback value for', element);
462
+ return null;
463
+ }
464
+
465
+ return fallbackValue;
466
+ }
467
+
468
+ const html$1 = freeze(['a', 'abbr', 'acronym', 'address', 'area', 'article', 'aside', 'audio', 'b', 'bdi', 'bdo', 'big', 'blink', 'blockquote', 'body', 'br', 'button', 'canvas', 'caption', 'center', 'cite', 'code', 'col', 'colgroup', 'content', 'data', 'datalist', 'dd', 'decorator', 'del', 'details', 'dfn', 'dialog', 'dir', 'div', 'dl', 'dt', 'element', 'em', 'fieldset', 'figcaption', 'figure', 'font', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hgroup', 'hr', 'html', 'i', 'img', 'input', 'ins', 'kbd', 'label', 'legend', 'li', 'main', 'map', 'mark', 'marquee', 'menu', 'menuitem', 'meter', 'nav', 'nobr', 'ol', 'optgroup', 'option', 'output', 'p', 'picture', 'pre', 'progress', 'q', 'rp', 'rt', 'ruby', 's', 'samp', 'section', 'select', 'shadow', 'small', 'source', 'spacer', 'span', 'strike', 'strong', 'style', 'sub', 'summary', 'sup', 'table', 'tbody', 'td', 'template', 'textarea', 'tfoot', 'th', 'thead', 'time', 'tr', 'track', 'tt', 'u', 'ul', 'var', 'video', 'wbr']); // SVG
469
+
470
+ const svg$1 = freeze(['svg', 'a', 'altglyph', 'altglyphdef', 'altglyphitem', 'animatecolor', 'animatemotion', 'animatetransform', 'circle', 'clippath', 'defs', 'desc', 'ellipse', 'filter', 'font', 'g', 'glyph', 'glyphref', 'hkern', 'image', 'line', 'lineargradient', 'marker', 'mask', 'metadata', 'mpath', 'path', 'pattern', 'polygon', 'polyline', 'radialgradient', 'rect', 'stop', 'style', 'switch', 'symbol', 'text', 'textpath', 'title', 'tref', 'tspan', 'view', 'vkern']);
471
+ const svgFilters = freeze(['feBlend', 'feColorMatrix', 'feComponentTransfer', 'feComposite', 'feConvolveMatrix', 'feDiffuseLighting', 'feDisplacementMap', 'feDistantLight', 'feDropShadow', 'feFlood', 'feFuncA', 'feFuncB', 'feFuncG', 'feFuncR', 'feGaussianBlur', 'feImage', 'feMerge', 'feMergeNode', 'feMorphology', 'feOffset', 'fePointLight', 'feSpecularLighting', 'feSpotLight', 'feTile', 'feTurbulence']); // List of SVG elements that are disallowed by default.
472
+ // We still need to know them so that we can do namespace
473
+ // checks properly in case one wants to add them to
474
+ // allow-list.
475
+
476
+ const svgDisallowed = freeze(['animate', 'color-profile', 'cursor', 'discard', 'font-face', 'font-face-format', 'font-face-name', 'font-face-src', 'font-face-uri', 'foreignobject', 'hatch', 'hatchpath', 'mesh', 'meshgradient', 'meshpatch', 'meshrow', 'missing-glyph', 'script', 'set', 'solidcolor', 'unknown', 'use']);
477
+ const mathMl$1 = freeze(['math', 'menclose', 'merror', 'mfenced', 'mfrac', 'mglyph', 'mi', 'mlabeledtr', 'mmultiscripts', 'mn', 'mo', 'mover', 'mpadded', 'mphantom', 'mroot', 'mrow', 'ms', 'mspace', 'msqrt', 'mstyle', 'msub', 'msup', 'msubsup', 'mtable', 'mtd', 'mtext', 'mtr', 'munder', 'munderover', 'mprescripts']); // Similarly to SVG, we want to know all MathML elements,
478
+ // even those that we disallow by default.
479
+
480
+ const mathMlDisallowed = freeze(['maction', 'maligngroup', 'malignmark', 'mlongdiv', 'mscarries', 'mscarry', 'msgroup', 'mstack', 'msline', 'msrow', 'semantics', 'annotation', 'annotation-xml', 'mprescripts', 'none']);
481
+ const text = freeze(['#text']);
482
+
483
+ const html = freeze(['accept', 'action', 'align', 'alt', 'autocapitalize', 'autocomplete', 'autopictureinpicture', 'autoplay', 'background', 'bgcolor', 'border', 'capture', 'cellpadding', 'cellspacing', 'checked', 'cite', 'class', 'clear', 'color', 'cols', 'colspan', 'controls', 'controlslist', 'coords', 'crossorigin', 'datetime', 'decoding', 'default', 'dir', 'disabled', 'disablepictureinpicture', 'disableremoteplayback', 'download', 'draggable', 'enctype', 'enterkeyhint', 'face', 'for', 'headers', 'height', 'hidden', 'high', 'href', 'hreflang', 'id', 'inputmode', 'integrity', 'ismap', 'kind', 'label', 'lang', 'list', 'loading', 'loop', 'low', 'max', 'maxlength', 'media', 'method', 'min', 'minlength', 'multiple', 'muted', 'name', 'nonce', 'noshade', 'novalidate', 'nowrap', 'open', 'optimum', 'pattern', 'placeholder', 'playsinline', 'poster', 'preload', 'pubdate', 'radiogroup', 'readonly', 'rel', 'required', 'rev', 'reversed', 'role', 'rows', 'rowspan', 'spellcheck', 'scope', 'selected', 'shape', 'size', 'sizes', 'span', 'srclang', 'start', 'src', 'srcset', 'step', 'style', 'summary', 'tabindex', 'title', 'translate', 'type', 'usemap', 'valign', 'value', 'width', 'xmlns', 'slot']);
484
+ const svg = freeze(['accent-height', 'accumulate', 'additive', 'alignment-baseline', 'ascent', 'attributename', 'attributetype', 'azimuth', 'basefrequency', 'baseline-shift', 'begin', 'bias', 'by', 'class', 'clip', 'clippathunits', 'clip-path', 'clip-rule', 'color', 'color-interpolation', 'color-interpolation-filters', 'color-profile', 'color-rendering', 'cx', 'cy', 'd', 'dx', 'dy', 'diffuseconstant', 'direction', 'display', 'divisor', 'dur', 'edgemode', 'elevation', 'end', 'fill', 'fill-opacity', 'fill-rule', 'filter', 'filterunits', 'flood-color', 'flood-opacity', 'font-family', 'font-size', 'font-size-adjust', 'font-stretch', 'font-style', 'font-variant', 'font-weight', 'fx', 'fy', 'g1', 'g2', 'glyph-name', 'glyphref', 'gradientunits', 'gradienttransform', 'height', 'href', 'id', 'image-rendering', 'in', 'in2', 'k', 'k1', 'k2', 'k3', 'k4', 'kerning', 'keypoints', 'keysplines', 'keytimes', 'lang', 'lengthadjust', 'letter-spacing', 'kernelmatrix', 'kernelunitlength', 'lighting-color', 'local', 'marker-end', 'marker-mid', 'marker-start', 'markerheight', 'markerunits', 'markerwidth', 'maskcontentunits', 'maskunits', 'max', 'mask', 'media', 'method', 'mode', 'min', 'name', 'numoctaves', 'offset', 'operator', 'opacity', 'order', 'orient', 'orientation', 'origin', 'overflow', 'paint-order', 'path', 'pathlength', 'patterncontentunits', 'patterntransform', 'patternunits', 'points', 'preservealpha', 'preserveaspectratio', 'primitiveunits', 'r', 'rx', 'ry', 'radius', 'refx', 'refy', 'repeatcount', 'repeatdur', 'restart', 'result', 'rotate', 'scale', 'seed', 'shape-rendering', 'specularconstant', 'specularexponent', 'spreadmethod', 'startoffset', 'stddeviation', 'stitchtiles', 'stop-color', 'stop-opacity', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity', 'stroke', 'stroke-width', 'style', 'surfacescale', 'systemlanguage', 'tabindex', 'targetx', 'targety', 'transform', 'transform-origin', 'text-anchor', 'text-decoration', 'text-rendering', 'textlength', 'type', 'u1', 'u2', 'unicode', 'values', 'viewbox', 'visibility', 'version', 'vert-adv-y', 'vert-origin-x', 'vert-origin-y', 'width', 'word-spacing', 'wrap', 'writing-mode', 'xchannelselector', 'ychannelselector', 'x', 'x1', 'x2', 'xmlns', 'y', 'y1', 'y2', 'z', 'zoomandpan']);
485
+ const mathMl = freeze(['accent', 'accentunder', 'align', 'bevelled', 'close', 'columnsalign', 'columnlines', 'columnspan', 'denomalign', 'depth', 'dir', 'display', 'displaystyle', 'encoding', 'fence', 'frame', 'height', 'href', 'id', 'largeop', 'length', 'linethickness', 'lspace', 'lquote', 'mathbackground', 'mathcolor', 'mathsize', 'mathvariant', 'maxsize', 'minsize', 'movablelimits', 'notation', 'numalign', 'open', 'rowalign', 'rowlines', 'rowspacing', 'rowspan', 'rspace', 'rquote', 'scriptlevel', 'scriptminsize', 'scriptsizemultiplier', 'selection', 'separator', 'separators', 'stretchy', 'subscriptshift', 'supscriptshift', 'symmetric', 'voffset', 'width', 'xmlns']);
486
+ const xml = freeze(['xlink:href', 'xml:id', 'xlink:title', 'xml:space', 'xmlns:xlink']);
487
+
488
+ const MUSTACHE_EXPR = seal(/\{\{[\w\W]*|[\w\W]*\}\}/gm); // Specify template detection regex for SAFE_FOR_TEMPLATES mode
489
+
490
+ const ERB_EXPR = seal(/<%[\w\W]*|[\w\W]*%>/gm);
491
+ const TMPLIT_EXPR = seal(/\${[\w\W]*}/gm);
492
+ const DATA_ATTR = seal(/^data-[\-\w.\u00B7-\uFFFF]/); // eslint-disable-line no-useless-escape
493
+
494
+ const ARIA_ATTR = seal(/^aria-[\-\w]+$/); // eslint-disable-line no-useless-escape
495
+
496
+ const IS_ALLOWED_URI = seal(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i // eslint-disable-line no-useless-escape
497
+ );
498
+ const IS_SCRIPT_OR_DATA = seal(/^(?:\w+script|data):/i);
499
+ const ATTR_WHITESPACE = seal(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g // eslint-disable-line no-control-regex
500
+ );
501
+ const DOCTYPE_NAME = seal(/^html$/i);
502
+
503
+ var EXPRESSIONS = /*#__PURE__*/Object.freeze({
504
+ __proto__: null,
505
+ MUSTACHE_EXPR: MUSTACHE_EXPR,
506
+ ERB_EXPR: ERB_EXPR,
507
+ TMPLIT_EXPR: TMPLIT_EXPR,
508
+ DATA_ATTR: DATA_ATTR,
509
+ ARIA_ATTR: ARIA_ATTR,
510
+ IS_ALLOWED_URI: IS_ALLOWED_URI,
511
+ IS_SCRIPT_OR_DATA: IS_SCRIPT_OR_DATA,
512
+ ATTR_WHITESPACE: ATTR_WHITESPACE,
513
+ DOCTYPE_NAME: DOCTYPE_NAME
514
+ });
515
+
516
+ const getGlobal = () => typeof window === 'undefined' ? null : window;
517
+ /**
518
+ * Creates a no-op policy for internal use only.
519
+ * Don't export this function outside this module!
520
+ * @param {?TrustedTypePolicyFactory} trustedTypes The policy factory.
521
+ * @param {HTMLScriptElement} purifyHostElement The Script element used to load DOMPurify (to determine policy name suffix).
522
+ * @return {?TrustedTypePolicy} The policy created (or null, if Trusted Types
523
+ * are not supported or creating the policy failed).
524
+ */
525
+
526
+
527
+ const _createTrustedTypesPolicy = function _createTrustedTypesPolicy(trustedTypes, purifyHostElement) {
528
+ if (typeof trustedTypes !== 'object' || typeof trustedTypes.createPolicy !== 'function') {
529
+ return null;
530
+ } // Allow the callers to control the unique policy name
531
+ // by adding a data-tt-policy-suffix to the script element with the DOMPurify.
532
+ // Policy creation with duplicate names throws in Trusted Types.
533
+
534
+
535
+ let suffix = null;
536
+ const ATTR_NAME = 'data-tt-policy-suffix';
537
+
538
+ if (purifyHostElement && purifyHostElement.hasAttribute(ATTR_NAME)) {
539
+ suffix = purifyHostElement.getAttribute(ATTR_NAME);
540
+ }
541
+
542
+ const policyName = 'dompurify' + (suffix ? '#' + suffix : '');
543
+
544
+ try {
545
+ return trustedTypes.createPolicy(policyName, {
546
+ createHTML(html) {
547
+ return html;
548
+ },
549
+
550
+ createScriptURL(scriptUrl) {
551
+ return scriptUrl;
552
+ }
553
+
554
+ });
555
+ } catch (_) {
556
+ // Policy creation failed (most likely another DOMPurify script has
557
+ // already run). Skip creating the policy, as this will only cause errors
558
+ // if TT are enforced.
559
+ console.warn('TrustedTypes policy ' + policyName + ' could not be created.');
560
+ return null;
561
+ }
562
+ };
563
+
564
+ function createDOMPurify() {
565
+ let window = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getGlobal();
566
+
567
+ const DOMPurify = root => createDOMPurify(root);
568
+ /**
569
+ * Version label, exposed for easier checks
570
+ * if DOMPurify is up to date or not
571
+ */
572
+
573
+
574
+ DOMPurify.version = '3.0.5';
575
+ /**
576
+ * Array of elements that DOMPurify removed during sanitation.
577
+ * Empty if nothing was removed.
578
+ */
579
+
580
+ DOMPurify.removed = [];
581
+
582
+ if (!window || !window.document || window.document.nodeType !== 9) {
583
+ // Not running in a browser, provide a factory function
584
+ // so that you can pass your own Window
585
+ DOMPurify.isSupported = false;
586
+ return DOMPurify;
587
+ }
588
+
589
+ const originalDocument = window.document;
590
+ const currentScript = originalDocument.currentScript;
591
+ let {
592
+ document
593
+ } = window;
594
+ const {
595
+ DocumentFragment,
596
+ HTMLTemplateElement,
597
+ Node,
598
+ Element,
599
+ NodeFilter,
600
+ NamedNodeMap = window.NamedNodeMap || window.MozNamedAttrMap,
601
+ HTMLFormElement,
602
+ DOMParser,
603
+ trustedTypes
604
+ } = window;
605
+ const ElementPrototype = Element.prototype;
606
+ const cloneNode = lookupGetter(ElementPrototype, 'cloneNode');
607
+ const getNextSibling = lookupGetter(ElementPrototype, 'nextSibling');
608
+ const getChildNodes = lookupGetter(ElementPrototype, 'childNodes');
609
+ const getParentNode = lookupGetter(ElementPrototype, 'parentNode'); // As per issue #47, the web-components registry is inherited by a
610
+ // new document created via createHTMLDocument. As per the spec
611
+ // (http://w3c.github.io/webcomponents/spec/custom/#creating-and-passing-registries)
612
+ // a new empty registry is used when creating a template contents owner
613
+ // document, so we use that as our parent document to ensure nothing
614
+ // is inherited.
615
+
616
+ if (typeof HTMLTemplateElement === 'function') {
617
+ const template = document.createElement('template');
618
+
619
+ if (template.content && template.content.ownerDocument) {
620
+ document = template.content.ownerDocument;
621
+ }
622
+ }
623
+
624
+ let trustedTypesPolicy;
625
+ let emptyHTML = '';
626
+ const {
627
+ implementation,
628
+ createNodeIterator,
629
+ createDocumentFragment,
630
+ getElementsByTagName
631
+ } = document;
632
+ const {
633
+ importNode
634
+ } = originalDocument;
635
+ let hooks = {};
636
+ /**
637
+ * Expose whether this browser supports running the full DOMPurify.
638
+ */
639
+
640
+ DOMPurify.isSupported = typeof entries === 'function' && typeof getParentNode === 'function' && implementation && implementation.createHTMLDocument !== undefined;
641
+ const {
642
+ MUSTACHE_EXPR,
643
+ ERB_EXPR,
644
+ TMPLIT_EXPR,
645
+ DATA_ATTR,
646
+ ARIA_ATTR,
647
+ IS_SCRIPT_OR_DATA,
648
+ ATTR_WHITESPACE
649
+ } = EXPRESSIONS;
650
+ let {
651
+ IS_ALLOWED_URI: IS_ALLOWED_URI$1
652
+ } = EXPRESSIONS;
653
+ /**
654
+ * We consider the elements and attributes below to be safe. Ideally
655
+ * don't add any new ones but feel free to remove unwanted ones.
656
+ */
657
+
658
+ /* allowed element names */
659
+
660
+ let ALLOWED_TAGS = null;
661
+ const DEFAULT_ALLOWED_TAGS = addToSet({}, [...html$1, ...svg$1, ...svgFilters, ...mathMl$1, ...text]);
662
+ /* Allowed attribute names */
663
+
664
+ let ALLOWED_ATTR = null;
665
+ const DEFAULT_ALLOWED_ATTR = addToSet({}, [...html, ...svg, ...mathMl, ...xml]);
666
+ /*
667
+ * Configure how DOMPUrify should handle custom elements and their attributes as well as customized built-in elements.
668
+ * @property {RegExp|Function|null} tagNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any custom elements)
669
+ * @property {RegExp|Function|null} attributeNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any attributes not on the allow list)
670
+ * @property {boolean} allowCustomizedBuiltInElements allow custom elements derived from built-ins if they pass CUSTOM_ELEMENT_HANDLING.tagNameCheck. Default: `false`.
671
+ */
672
+
673
+ let CUSTOM_ELEMENT_HANDLING = Object.seal(Object.create(null, {
674
+ tagNameCheck: {
675
+ writable: true,
676
+ configurable: false,
677
+ enumerable: true,
678
+ value: null
679
+ },
680
+ attributeNameCheck: {
681
+ writable: true,
682
+ configurable: false,
683
+ enumerable: true,
684
+ value: null
685
+ },
686
+ allowCustomizedBuiltInElements: {
687
+ writable: true,
688
+ configurable: false,
689
+ enumerable: true,
690
+ value: false
691
+ }
692
+ }));
693
+ /* Explicitly forbidden tags (overrides ALLOWED_TAGS/ADD_TAGS) */
694
+
695
+ let FORBID_TAGS = null;
696
+ /* Explicitly forbidden attributes (overrides ALLOWED_ATTR/ADD_ATTR) */
697
+
698
+ let FORBID_ATTR = null;
699
+ /* Decide if ARIA attributes are okay */
700
+
701
+ let ALLOW_ARIA_ATTR = true;
702
+ /* Decide if custom data attributes are okay */
703
+
704
+ let ALLOW_DATA_ATTR = true;
705
+ /* Decide if unknown protocols are okay */
706
+
707
+ let ALLOW_UNKNOWN_PROTOCOLS = false;
708
+ /* Decide if self-closing tags in attributes are allowed.
709
+ * Usually removed due to a mXSS issue in jQuery 3.0 */
710
+
711
+ let ALLOW_SELF_CLOSE_IN_ATTR = true;
712
+ /* Output should be safe for common template engines.
713
+ * This means, DOMPurify removes data attributes, mustaches and ERB
714
+ */
715
+
716
+ let SAFE_FOR_TEMPLATES = false;
717
+ /* Decide if document with <html>... should be returned */
718
+
719
+ let WHOLE_DOCUMENT = false;
720
+ /* Track whether config is already set on this instance of DOMPurify. */
721
+
722
+ let SET_CONFIG = false;
723
+ /* Decide if all elements (e.g. style, script) must be children of
724
+ * document.body. By default, browsers might move them to document.head */
725
+
726
+ let FORCE_BODY = false;
727
+ /* Decide if a DOM `HTMLBodyElement` should be returned, instead of a html
728
+ * string (or a TrustedHTML object if Trusted Types are supported).
729
+ * If `WHOLE_DOCUMENT` is enabled a `HTMLHtmlElement` will be returned instead
730
+ */
731
+
732
+ let RETURN_DOM = false;
733
+ /* Decide if a DOM `DocumentFragment` should be returned, instead of a html
734
+ * string (or a TrustedHTML object if Trusted Types are supported) */
735
+
736
+ let RETURN_DOM_FRAGMENT = false;
737
+ /* Try to return a Trusted Type object instead of a string, return a string in
738
+ * case Trusted Types are not supported */
739
+
740
+ let RETURN_TRUSTED_TYPE = false;
741
+ /* Output should be free from DOM clobbering attacks?
742
+ * This sanitizes markups named with colliding, clobberable built-in DOM APIs.
743
+ */
744
+
745
+ let SANITIZE_DOM = true;
746
+ /* Achieve full DOM Clobbering protection by isolating the namespace of named
747
+ * properties and JS variables, mitigating attacks that abuse the HTML/DOM spec rules.
748
+ *
749
+ * HTML/DOM spec rules that enable DOM Clobbering:
750
+ * - Named Access on Window (§7.3.3)
751
+ * - DOM Tree Accessors (§3.1.5)
752
+ * - Form Element Parent-Child Relations (§4.10.3)
753
+ * - Iframe srcdoc / Nested WindowProxies (§4.8.5)
754
+ * - HTMLCollection (§4.2.10.2)
755
+ *
756
+ * Namespace isolation is implemented by prefixing `id` and `name` attributes
757
+ * with a constant string, i.e., `user-content-`
758
+ */
759
+
760
+ let SANITIZE_NAMED_PROPS = false;
761
+ const SANITIZE_NAMED_PROPS_PREFIX = 'user-content-';
762
+ /* Keep element content when removing element? */
763
+
764
+ let KEEP_CONTENT = true;
765
+ /* If a `Node` is passed to sanitize(), then performs sanitization in-place instead
766
+ * of importing it into a new Document and returning a sanitized copy */
767
+
768
+ let IN_PLACE = false;
769
+ /* Allow usage of profiles like html, svg and mathMl */
770
+
771
+ let USE_PROFILES = {};
772
+ /* Tags to ignore content of when KEEP_CONTENT is true */
773
+
774
+ let FORBID_CONTENTS = null;
775
+ const DEFAULT_FORBID_CONTENTS = addToSet({}, ['annotation-xml', 'audio', 'colgroup', 'desc', 'foreignobject', 'head', 'iframe', 'math', 'mi', 'mn', 'mo', 'ms', 'mtext', 'noembed', 'noframes', 'noscript', 'plaintext', 'script', 'style', 'svg', 'template', 'thead', 'title', 'video', 'xmp']);
776
+ /* Tags that are safe for data: URIs */
777
+
778
+ let DATA_URI_TAGS = null;
779
+ const DEFAULT_DATA_URI_TAGS = addToSet({}, ['audio', 'video', 'img', 'source', 'image', 'track']);
780
+ /* Attributes safe for values like "javascript:" */
781
+
782
+ let URI_SAFE_ATTRIBUTES = null;
783
+ const DEFAULT_URI_SAFE_ATTRIBUTES = addToSet({}, ['alt', 'class', 'for', 'id', 'label', 'name', 'pattern', 'placeholder', 'role', 'summary', 'title', 'value', 'style', 'xmlns']);
784
+ const MATHML_NAMESPACE = 'http://www.w3.org/1998/Math/MathML';
785
+ const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
786
+ const HTML_NAMESPACE = 'http://www.w3.org/1999/xhtml';
787
+ /* Document namespace */
788
+
789
+ let NAMESPACE = HTML_NAMESPACE;
790
+ let IS_EMPTY_INPUT = false;
791
+ /* Allowed XHTML+XML namespaces */
792
+
793
+ let ALLOWED_NAMESPACES = null;
794
+ const DEFAULT_ALLOWED_NAMESPACES = addToSet({}, [MATHML_NAMESPACE, SVG_NAMESPACE, HTML_NAMESPACE], stringToString);
795
+ /* Parsing of strict XHTML documents */
796
+
797
+ let PARSER_MEDIA_TYPE;
798
+ const SUPPORTED_PARSER_MEDIA_TYPES = ['application/xhtml+xml', 'text/html'];
799
+ const DEFAULT_PARSER_MEDIA_TYPE = 'text/html';
800
+ let transformCaseFunc;
801
+ /* Keep a reference to config to pass to hooks */
802
+
803
+ let CONFIG = null;
804
+ /* Ideally, do not touch anything below this line */
805
+
806
+ /* ______________________________________________ */
807
+
808
+ const formElement = document.createElement('form');
809
+
810
+ const isRegexOrFunction = function isRegexOrFunction(testValue) {
811
+ return testValue instanceof RegExp || testValue instanceof Function;
812
+ };
813
+ /**
814
+ * _parseConfig
815
+ *
816
+ * @param {Object} cfg optional config literal
817
+ */
818
+ // eslint-disable-next-line complexity
819
+
820
+
821
+ const _parseConfig = function _parseConfig(cfg) {
822
+ if (CONFIG && CONFIG === cfg) {
823
+ return;
824
+ }
825
+ /* Shield configuration object from tampering */
826
+
827
+
828
+ if (!cfg || typeof cfg !== 'object') {
829
+ cfg = {};
830
+ }
831
+ /* Shield configuration object from prototype pollution */
832
+
833
+
834
+ cfg = clone(cfg);
835
+ PARSER_MEDIA_TYPE = // eslint-disable-next-line unicorn/prefer-includes
836
+ SUPPORTED_PARSER_MEDIA_TYPES.indexOf(cfg.PARSER_MEDIA_TYPE) === -1 ? PARSER_MEDIA_TYPE = DEFAULT_PARSER_MEDIA_TYPE : PARSER_MEDIA_TYPE = cfg.PARSER_MEDIA_TYPE; // HTML tags and attributes are not case-sensitive, converting to lowercase. Keeping XHTML as is.
837
+
838
+ transformCaseFunc = PARSER_MEDIA_TYPE === 'application/xhtml+xml' ? stringToString : stringToLowerCase;
839
+ /* Set configuration parameters */
840
+
841
+ ALLOWED_TAGS = 'ALLOWED_TAGS' in cfg ? addToSet({}, cfg.ALLOWED_TAGS, transformCaseFunc) : DEFAULT_ALLOWED_TAGS;
842
+ ALLOWED_ATTR = 'ALLOWED_ATTR' in cfg ? addToSet({}, cfg.ALLOWED_ATTR, transformCaseFunc) : DEFAULT_ALLOWED_ATTR;
843
+ ALLOWED_NAMESPACES = 'ALLOWED_NAMESPACES' in cfg ? addToSet({}, cfg.ALLOWED_NAMESPACES, stringToString) : DEFAULT_ALLOWED_NAMESPACES;
844
+ URI_SAFE_ATTRIBUTES = 'ADD_URI_SAFE_ATTR' in cfg ? addToSet(clone(DEFAULT_URI_SAFE_ATTRIBUTES), // eslint-disable-line indent
845
+ cfg.ADD_URI_SAFE_ATTR, // eslint-disable-line indent
846
+ transformCaseFunc // eslint-disable-line indent
847
+ ) // eslint-disable-line indent
848
+ : DEFAULT_URI_SAFE_ATTRIBUTES;
849
+ DATA_URI_TAGS = 'ADD_DATA_URI_TAGS' in cfg ? addToSet(clone(DEFAULT_DATA_URI_TAGS), // eslint-disable-line indent
850
+ cfg.ADD_DATA_URI_TAGS, // eslint-disable-line indent
851
+ transformCaseFunc // eslint-disable-line indent
852
+ ) // eslint-disable-line indent
853
+ : DEFAULT_DATA_URI_TAGS;
854
+ FORBID_CONTENTS = 'FORBID_CONTENTS' in cfg ? addToSet({}, cfg.FORBID_CONTENTS, transformCaseFunc) : DEFAULT_FORBID_CONTENTS;
855
+ FORBID_TAGS = 'FORBID_TAGS' in cfg ? addToSet({}, cfg.FORBID_TAGS, transformCaseFunc) : {};
856
+ FORBID_ATTR = 'FORBID_ATTR' in cfg ? addToSet({}, cfg.FORBID_ATTR, transformCaseFunc) : {};
857
+ USE_PROFILES = 'USE_PROFILES' in cfg ? cfg.USE_PROFILES : false;
858
+ ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false; // Default true
859
+
860
+ ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false; // Default true
861
+
862
+ ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false; // Default false
863
+
864
+ ALLOW_SELF_CLOSE_IN_ATTR = cfg.ALLOW_SELF_CLOSE_IN_ATTR !== false; // Default true
865
+
866
+ SAFE_FOR_TEMPLATES = cfg.SAFE_FOR_TEMPLATES || false; // Default false
867
+
868
+ WHOLE_DOCUMENT = cfg.WHOLE_DOCUMENT || false; // Default false
869
+
870
+ RETURN_DOM = cfg.RETURN_DOM || false; // Default false
871
+
872
+ RETURN_DOM_FRAGMENT = cfg.RETURN_DOM_FRAGMENT || false; // Default false
873
+
874
+ RETURN_TRUSTED_TYPE = cfg.RETURN_TRUSTED_TYPE || false; // Default false
875
+
876
+ FORCE_BODY = cfg.FORCE_BODY || false; // Default false
877
+
878
+ SANITIZE_DOM = cfg.SANITIZE_DOM !== false; // Default true
879
+
880
+ SANITIZE_NAMED_PROPS = cfg.SANITIZE_NAMED_PROPS || false; // Default false
881
+
882
+ KEEP_CONTENT = cfg.KEEP_CONTENT !== false; // Default true
883
+
884
+ IN_PLACE = cfg.IN_PLACE || false; // Default false
885
+
886
+ IS_ALLOWED_URI$1 = cfg.ALLOWED_URI_REGEXP || IS_ALLOWED_URI;
887
+ NAMESPACE = cfg.NAMESPACE || HTML_NAMESPACE;
888
+ CUSTOM_ELEMENT_HANDLING = cfg.CUSTOM_ELEMENT_HANDLING || {};
889
+
890
+ if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck)) {
891
+ CUSTOM_ELEMENT_HANDLING.tagNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck;
892
+ }
893
+
894
+ if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)) {
895
+ CUSTOM_ELEMENT_HANDLING.attributeNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck;
896
+ }
897
+
898
+ if (cfg.CUSTOM_ELEMENT_HANDLING && typeof cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements === 'boolean') {
899
+ CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements;
900
+ }
901
+
902
+ if (SAFE_FOR_TEMPLATES) {
903
+ ALLOW_DATA_ATTR = false;
904
+ }
905
+
906
+ if (RETURN_DOM_FRAGMENT) {
907
+ RETURN_DOM = true;
908
+ }
909
+ /* Parse profile info */
910
+
911
+
912
+ if (USE_PROFILES) {
913
+ ALLOWED_TAGS = addToSet({}, [...text]);
914
+ ALLOWED_ATTR = [];
915
+
916
+ if (USE_PROFILES.html === true) {
917
+ addToSet(ALLOWED_TAGS, html$1);
918
+ addToSet(ALLOWED_ATTR, html);
919
+ }
920
+
921
+ if (USE_PROFILES.svg === true) {
922
+ addToSet(ALLOWED_TAGS, svg$1);
923
+ addToSet(ALLOWED_ATTR, svg);
924
+ addToSet(ALLOWED_ATTR, xml);
925
+ }
926
+
927
+ if (USE_PROFILES.svgFilters === true) {
928
+ addToSet(ALLOWED_TAGS, svgFilters);
929
+ addToSet(ALLOWED_ATTR, svg);
930
+ addToSet(ALLOWED_ATTR, xml);
931
+ }
932
+
933
+ if (USE_PROFILES.mathMl === true) {
934
+ addToSet(ALLOWED_TAGS, mathMl$1);
935
+ addToSet(ALLOWED_ATTR, mathMl);
936
+ addToSet(ALLOWED_ATTR, xml);
937
+ }
938
+ }
939
+ /* Merge configuration parameters */
940
+
941
+
942
+ if (cfg.ADD_TAGS) {
943
+ if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) {
944
+ ALLOWED_TAGS = clone(ALLOWED_TAGS);
945
+ }
946
+
947
+ addToSet(ALLOWED_TAGS, cfg.ADD_TAGS, transformCaseFunc);
948
+ }
949
+
950
+ if (cfg.ADD_ATTR) {
951
+ if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) {
952
+ ALLOWED_ATTR = clone(ALLOWED_ATTR);
953
+ }
954
+
955
+ addToSet(ALLOWED_ATTR, cfg.ADD_ATTR, transformCaseFunc);
956
+ }
957
+
958
+ if (cfg.ADD_URI_SAFE_ATTR) {
959
+ addToSet(URI_SAFE_ATTRIBUTES, cfg.ADD_URI_SAFE_ATTR, transformCaseFunc);
960
+ }
961
+
962
+ if (cfg.FORBID_CONTENTS) {
963
+ if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
964
+ FORBID_CONTENTS = clone(FORBID_CONTENTS);
965
+ }
966
+
967
+ addToSet(FORBID_CONTENTS, cfg.FORBID_CONTENTS, transformCaseFunc);
968
+ }
969
+ /* Add #text in case KEEP_CONTENT is set to true */
970
+
971
+
972
+ if (KEEP_CONTENT) {
973
+ ALLOWED_TAGS['#text'] = true;
974
+ }
975
+ /* Add html, head and body to ALLOWED_TAGS in case WHOLE_DOCUMENT is true */
976
+
977
+
978
+ if (WHOLE_DOCUMENT) {
979
+ addToSet(ALLOWED_TAGS, ['html', 'head', 'body']);
980
+ }
981
+ /* Add tbody to ALLOWED_TAGS in case tables are permitted, see #286, #365 */
982
+
983
+
984
+ if (ALLOWED_TAGS.table) {
985
+ addToSet(ALLOWED_TAGS, ['tbody']);
986
+ delete FORBID_TAGS.tbody;
987
+ }
988
+
989
+ if (cfg.TRUSTED_TYPES_POLICY) {
990
+ if (typeof cfg.TRUSTED_TYPES_POLICY.createHTML !== 'function') {
991
+ throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');
992
+ }
993
+
994
+ if (typeof cfg.TRUSTED_TYPES_POLICY.createScriptURL !== 'function') {
995
+ throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');
996
+ } // Overwrite existing TrustedTypes policy.
997
+
998
+
999
+ trustedTypesPolicy = cfg.TRUSTED_TYPES_POLICY; // Sign local variables required by `sanitize`.
1000
+
1001
+ emptyHTML = trustedTypesPolicy.createHTML('');
1002
+ } else {
1003
+ // Uninitialized policy, attempt to initialize the internal dompurify policy.
1004
+ if (trustedTypesPolicy === undefined) {
1005
+ trustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, currentScript);
1006
+ } // If creating the internal policy succeeded sign internal variables.
1007
+
1008
+
1009
+ if (trustedTypesPolicy !== null && typeof emptyHTML === 'string') {
1010
+ emptyHTML = trustedTypesPolicy.createHTML('');
1011
+ }
1012
+ } // Prevent further manipulation of configuration.
1013
+ // Not available in IE8, Safari 5, etc.
1014
+
1015
+
1016
+ if (freeze) {
1017
+ freeze(cfg);
1018
+ }
1019
+
1020
+ CONFIG = cfg;
1021
+ };
1022
+
1023
+ const MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, ['mi', 'mo', 'mn', 'ms', 'mtext']);
1024
+ const HTML_INTEGRATION_POINTS = addToSet({}, ['foreignobject', 'desc', 'title', 'annotation-xml']); // Certain elements are allowed in both SVG and HTML
1025
+ // namespace. We need to specify them explicitly
1026
+ // so that they don't get erroneously deleted from
1027
+ // HTML namespace.
1028
+
1029
+ const COMMON_SVG_AND_HTML_ELEMENTS = addToSet({}, ['title', 'style', 'font', 'a', 'script']);
1030
+ /* Keep track of all possible SVG and MathML tags
1031
+ * so that we can perform the namespace checks
1032
+ * correctly. */
1033
+
1034
+ const ALL_SVG_TAGS = addToSet({}, svg$1);
1035
+ addToSet(ALL_SVG_TAGS, svgFilters);
1036
+ addToSet(ALL_SVG_TAGS, svgDisallowed);
1037
+ const ALL_MATHML_TAGS = addToSet({}, mathMl$1);
1038
+ addToSet(ALL_MATHML_TAGS, mathMlDisallowed);
1039
+ /**
1040
+ *
1041
+ *
1042
+ * @param {Element} element a DOM element whose namespace is being checked
1043
+ * @returns {boolean} Return false if the element has a
1044
+ * namespace that a spec-compliant parser would never
1045
+ * return. Return true otherwise.
1046
+ */
1047
+
1048
+ const _checkValidNamespace = function _checkValidNamespace(element) {
1049
+ let parent = getParentNode(element); // In JSDOM, if we're inside shadow DOM, then parentNode
1050
+ // can be null. We just simulate parent in this case.
1051
+
1052
+ if (!parent || !parent.tagName) {
1053
+ parent = {
1054
+ namespaceURI: NAMESPACE,
1055
+ tagName: 'template'
1056
+ };
1057
+ }
1058
+
1059
+ const tagName = stringToLowerCase(element.tagName);
1060
+ const parentTagName = stringToLowerCase(parent.tagName);
1061
+
1062
+ if (!ALLOWED_NAMESPACES[element.namespaceURI]) {
1063
+ return false;
1064
+ }
1065
+
1066
+ if (element.namespaceURI === SVG_NAMESPACE) {
1067
+ // The only way to switch from HTML namespace to SVG
1068
+ // is via <svg>. If it happens via any other tag, then
1069
+ // it should be killed.
1070
+ if (parent.namespaceURI === HTML_NAMESPACE) {
1071
+ return tagName === 'svg';
1072
+ } // The only way to switch from MathML to SVG is via`
1073
+ // svg if parent is either <annotation-xml> or MathML
1074
+ // text integration points.
1075
+
1076
+
1077
+ if (parent.namespaceURI === MATHML_NAMESPACE) {
1078
+ return tagName === 'svg' && (parentTagName === 'annotation-xml' || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
1079
+ } // We only allow elements that are defined in SVG
1080
+ // spec. All others are disallowed in SVG namespace.
1081
+
1082
+
1083
+ return Boolean(ALL_SVG_TAGS[tagName]);
1084
+ }
1085
+
1086
+ if (element.namespaceURI === MATHML_NAMESPACE) {
1087
+ // The only way to switch from HTML namespace to MathML
1088
+ // is via <math>. If it happens via any other tag, then
1089
+ // it should be killed.
1090
+ if (parent.namespaceURI === HTML_NAMESPACE) {
1091
+ return tagName === 'math';
1092
+ } // The only way to switch from SVG to MathML is via
1093
+ // <math> and HTML integration points
1094
+
1095
+
1096
+ if (parent.namespaceURI === SVG_NAMESPACE) {
1097
+ return tagName === 'math' && HTML_INTEGRATION_POINTS[parentTagName];
1098
+ } // We only allow elements that are defined in MathML
1099
+ // spec. All others are disallowed in MathML namespace.
1100
+
1101
+
1102
+ return Boolean(ALL_MATHML_TAGS[tagName]);
1103
+ }
1104
+
1105
+ if (element.namespaceURI === HTML_NAMESPACE) {
1106
+ // The only way to switch from SVG to HTML is via
1107
+ // HTML integration points, and from MathML to HTML
1108
+ // is via MathML text integration points
1109
+ if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {
1110
+ return false;
1111
+ }
1112
+
1113
+ if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {
1114
+ return false;
1115
+ } // We disallow tags that are specific for MathML
1116
+ // or SVG and should never appear in HTML namespace
1117
+
1118
+
1119
+ return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
1120
+ } // For XHTML and XML documents that support custom namespaces
1121
+
1122
+
1123
+ if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && ALLOWED_NAMESPACES[element.namespaceURI]) {
1124
+ return true;
1125
+ } // The code should never reach this place (this means
1126
+ // that the element somehow got namespace that is not
1127
+ // HTML, SVG, MathML or allowed via ALLOWED_NAMESPACES).
1128
+ // Return false just in case.
1129
+
1130
+
1131
+ return false;
1132
+ };
1133
+ /**
1134
+ * _forceRemove
1135
+ *
1136
+ * @param {Node} node a DOM node
1137
+ */
1138
+
1139
+
1140
+ const _forceRemove = function _forceRemove(node) {
1141
+ arrayPush(DOMPurify.removed, {
1142
+ element: node
1143
+ });
1144
+
1145
+ try {
1146
+ // eslint-disable-next-line unicorn/prefer-dom-node-remove
1147
+ node.parentNode.removeChild(node);
1148
+ } catch (_) {
1149
+ node.remove();
1150
+ }
1151
+ };
1152
+ /**
1153
+ * _removeAttribute
1154
+ *
1155
+ * @param {String} name an Attribute name
1156
+ * @param {Node} node a DOM node
1157
+ */
1158
+
1159
+
1160
+ const _removeAttribute = function _removeAttribute(name, node) {
1161
+ try {
1162
+ arrayPush(DOMPurify.removed, {
1163
+ attribute: node.getAttributeNode(name),
1164
+ from: node
1165
+ });
1166
+ } catch (_) {
1167
+ arrayPush(DOMPurify.removed, {
1168
+ attribute: null,
1169
+ from: node
1170
+ });
1171
+ }
1172
+
1173
+ node.removeAttribute(name); // We void attribute values for unremovable "is"" attributes
1174
+
1175
+ if (name === 'is' && !ALLOWED_ATTR[name]) {
1176
+ if (RETURN_DOM || RETURN_DOM_FRAGMENT) {
1177
+ try {
1178
+ _forceRemove(node);
1179
+ } catch (_) {}
1180
+ } else {
1181
+ try {
1182
+ node.setAttribute(name, '');
1183
+ } catch (_) {}
1184
+ }
1185
+ }
1186
+ };
1187
+ /**
1188
+ * _initDocument
1189
+ *
1190
+ * @param {String} dirty a string of dirty markup
1191
+ * @return {Document} a DOM, filled with the dirty markup
1192
+ */
1193
+
1194
+
1195
+ const _initDocument = function _initDocument(dirty) {
1196
+ /* Create a HTML document */
1197
+ let doc;
1198
+ let leadingWhitespace;
1199
+
1200
+ if (FORCE_BODY) {
1201
+ dirty = '<remove></remove>' + dirty;
1202
+ } else {
1203
+ /* If FORCE_BODY isn't used, leading whitespace needs to be preserved manually */
1204
+ const matches = stringMatch(dirty, /^[\r\n\t ]+/);
1205
+ leadingWhitespace = matches && matches[0];
1206
+ }
1207
+
1208
+ if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && NAMESPACE === HTML_NAMESPACE) {
1209
+ // Root of XHTML doc must contain xmlns declaration (see https://www.w3.org/TR/xhtml1/normative.html#strict)
1210
+ dirty = '<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>' + dirty + '</body></html>';
1211
+ }
1212
+
1213
+ const dirtyPayload = trustedTypesPolicy ? trustedTypesPolicy.createHTML(dirty) : dirty;
1214
+ /*
1215
+ * Use the DOMParser API by default, fallback later if needs be
1216
+ * DOMParser not work for svg when has multiple root element.
1217
+ */
1218
+
1219
+ if (NAMESPACE === HTML_NAMESPACE) {
1220
+ try {
1221
+ doc = new DOMParser().parseFromString(dirtyPayload, PARSER_MEDIA_TYPE);
1222
+ } catch (_) {}
1223
+ }
1224
+ /* Use createHTMLDocument in case DOMParser is not available */
1225
+
1226
+
1227
+ if (!doc || !doc.documentElement) {
1228
+ doc = implementation.createDocument(NAMESPACE, 'template', null);
1229
+
1230
+ try {
1231
+ doc.documentElement.innerHTML = IS_EMPTY_INPUT ? emptyHTML : dirtyPayload;
1232
+ } catch (_) {// Syntax error if dirtyPayload is invalid xml
1233
+ }
1234
+ }
1235
+
1236
+ const body = doc.body || doc.documentElement;
1237
+
1238
+ if (dirty && leadingWhitespace) {
1239
+ body.insertBefore(document.createTextNode(leadingWhitespace), body.childNodes[0] || null);
1240
+ }
1241
+ /* Work on whole document or just its body */
1242
+
1243
+
1244
+ if (NAMESPACE === HTML_NAMESPACE) {
1245
+ return getElementsByTagName.call(doc, WHOLE_DOCUMENT ? 'html' : 'body')[0];
1246
+ }
1247
+
1248
+ return WHOLE_DOCUMENT ? doc.documentElement : body;
1249
+ };
1250
+ /**
1251
+ * _createIterator
1252
+ *
1253
+ * @param {Document} root document/fragment to create iterator for
1254
+ * @return {Iterator} iterator instance
1255
+ */
1256
+
1257
+
1258
+ const _createIterator = function _createIterator(root) {
1259
+ return createNodeIterator.call(root.ownerDocument || root, root, // eslint-disable-next-line no-bitwise
1260
+ NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT, null, false);
1261
+ };
1262
+ /**
1263
+ * _isClobbered
1264
+ *
1265
+ * @param {Node} elm element to check for clobbering attacks
1266
+ * @return {Boolean} true if clobbered, false if safe
1267
+ */
1268
+
1269
+
1270
+ const _isClobbered = function _isClobbered(elm) {
1271
+ return elm instanceof HTMLFormElement && (typeof elm.nodeName !== 'string' || typeof elm.textContent !== 'string' || typeof elm.removeChild !== 'function' || !(elm.attributes instanceof NamedNodeMap) || typeof elm.removeAttribute !== 'function' || typeof elm.setAttribute !== 'function' || typeof elm.namespaceURI !== 'string' || typeof elm.insertBefore !== 'function' || typeof elm.hasChildNodes !== 'function');
1272
+ };
1273
+ /**
1274
+ * _isNode
1275
+ *
1276
+ * @param {Node} obj object to check whether it's a DOM node
1277
+ * @return {Boolean} true is object is a DOM node
1278
+ */
1279
+
1280
+
1281
+ const _isNode = function _isNode(object) {
1282
+ return typeof Node === 'object' ? object instanceof Node : object && typeof object === 'object' && typeof object.nodeType === 'number' && typeof object.nodeName === 'string';
1283
+ };
1284
+ /**
1285
+ * _executeHook
1286
+ * Execute user configurable hooks
1287
+ *
1288
+ * @param {String} entryPoint Name of the hook's entry point
1289
+ * @param {Node} currentNode node to work on with the hook
1290
+ * @param {Object} data additional hook parameters
1291
+ */
1292
+
1293
+
1294
+ const _executeHook = function _executeHook(entryPoint, currentNode, data) {
1295
+ if (!hooks[entryPoint]) {
1296
+ return;
1297
+ }
1298
+
1299
+ arrayForEach(hooks[entryPoint], hook => {
1300
+ hook.call(DOMPurify, currentNode, data, CONFIG);
1301
+ });
1302
+ };
1303
+ /**
1304
+ * _sanitizeElements
1305
+ *
1306
+ * @protect nodeName
1307
+ * @protect textContent
1308
+ * @protect removeChild
1309
+ *
1310
+ * @param {Node} currentNode to check for permission to exist
1311
+ * @return {Boolean} true if node was killed, false if left alive
1312
+ */
1313
+
1314
+
1315
+ const _sanitizeElements = function _sanitizeElements(currentNode) {
1316
+ let content;
1317
+ /* Execute a hook if present */
1318
+
1319
+ _executeHook('beforeSanitizeElements', currentNode, null);
1320
+ /* Check if element is clobbered or can clobber */
1321
+
1322
+
1323
+ if (_isClobbered(currentNode)) {
1324
+ _forceRemove(currentNode);
1325
+
1326
+ return true;
1327
+ }
1328
+ /* Now let's check the element's type and name */
1329
+
1330
+
1331
+ const tagName = transformCaseFunc(currentNode.nodeName);
1332
+ /* Execute a hook if present */
1333
+
1334
+ _executeHook('uponSanitizeElement', currentNode, {
1335
+ tagName,
1336
+ allowedTags: ALLOWED_TAGS
1337
+ });
1338
+ /* Detect mXSS attempts abusing namespace confusion */
1339
+
1340
+
1341
+ if (currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && (!_isNode(currentNode.content) || !_isNode(currentNode.content.firstElementChild)) && regExpTest(/<[/\w]/g, currentNode.innerHTML) && regExpTest(/<[/\w]/g, currentNode.textContent)) {
1342
+ _forceRemove(currentNode);
1343
+
1344
+ return true;
1345
+ }
1346
+ /* Remove element if anything forbids its presence */
1347
+
1348
+
1349
+ if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
1350
+ /* Check if we have a custom element to handle */
1351
+ if (!FORBID_TAGS[tagName] && _basicCustomElementTest(tagName)) {
1352
+ if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) return false;
1353
+ if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) return false;
1354
+ }
1355
+ /* Keep content except for bad-listed elements */
1356
+
1357
+
1358
+ if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
1359
+ const parentNode = getParentNode(currentNode) || currentNode.parentNode;
1360
+ const childNodes = getChildNodes(currentNode) || currentNode.childNodes;
1361
+
1362
+ if (childNodes && parentNode) {
1363
+ const childCount = childNodes.length;
1364
+
1365
+ for (let i = childCount - 1; i >= 0; --i) {
1366
+ parentNode.insertBefore(cloneNode(childNodes[i], true), getNextSibling(currentNode));
1367
+ }
1368
+ }
1369
+ }
1370
+
1371
+ _forceRemove(currentNode);
1372
+
1373
+ return true;
1374
+ }
1375
+ /* Check whether element has a valid namespace */
1376
+
1377
+
1378
+ if (currentNode instanceof Element && !_checkValidNamespace(currentNode)) {
1379
+ _forceRemove(currentNode);
1380
+
1381
+ return true;
1382
+ }
1383
+ /* Make sure that older browsers don't get fallback-tag mXSS */
1384
+
1385
+
1386
+ if ((tagName === 'noscript' || tagName === 'noembed' || tagName === 'noframes') && regExpTest(/<\/no(script|embed|frames)/i, currentNode.innerHTML)) {
1387
+ _forceRemove(currentNode);
1388
+
1389
+ return true;
1390
+ }
1391
+ /* Sanitize element content to be template-safe */
1392
+
1393
+
1394
+ if (SAFE_FOR_TEMPLATES && currentNode.nodeType === 3) {
1395
+ /* Get the element's text content */
1396
+ content = currentNode.textContent;
1397
+ content = stringReplace(content, MUSTACHE_EXPR, ' ');
1398
+ content = stringReplace(content, ERB_EXPR, ' ');
1399
+ content = stringReplace(content, TMPLIT_EXPR, ' ');
1400
+
1401
+ if (currentNode.textContent !== content) {
1402
+ arrayPush(DOMPurify.removed, {
1403
+ element: currentNode.cloneNode()
1404
+ });
1405
+ currentNode.textContent = content;
1406
+ }
1407
+ }
1408
+ /* Execute a hook if present */
1409
+
1410
+
1411
+ _executeHook('afterSanitizeElements', currentNode, null);
1412
+
1413
+ return false;
1414
+ };
1415
+ /**
1416
+ * _isValidAttribute
1417
+ *
1418
+ * @param {string} lcTag Lowercase tag name of containing element.
1419
+ * @param {string} lcName Lowercase attribute name.
1420
+ * @param {string} value Attribute value.
1421
+ * @return {Boolean} Returns true if `value` is valid, otherwise false.
1422
+ */
1423
+ // eslint-disable-next-line complexity
1424
+
1425
+
1426
+ const _isValidAttribute = function _isValidAttribute(lcTag, lcName, value) {
1427
+ /* Make sure attribute cannot clobber */
1428
+ if (SANITIZE_DOM && (lcName === 'id' || lcName === 'name') && (value in document || value in formElement)) {
1429
+ return false;
1430
+ }
1431
+ /* Allow valid data-* attributes: At least one character after "-"
1432
+ (https://html.spec.whatwg.org/multipage/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes)
1433
+ XML-compatible (https://html.spec.whatwg.org/multipage/infrastructure.html#xml-compatible and http://www.w3.org/TR/xml/#d0e804)
1434
+ We don't need to check the value; it's always URI safe. */
1435
+
1436
+
1437
+ if (ALLOW_DATA_ATTR && !FORBID_ATTR[lcName] && regExpTest(DATA_ATTR, lcName)) ; else if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR, lcName)) ; else if (!ALLOWED_ATTR[lcName] || FORBID_ATTR[lcName]) {
1438
+ if ( // First condition does a very basic check if a) it's basically a valid custom element tagname AND
1439
+ // b) if the tagName passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
1440
+ // and c) if the attribute name passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.attributeNameCheck
1441
+ _basicCustomElementTest(lcTag) && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, lcTag) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(lcTag)) && (CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.attributeNameCheck, lcName) || CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.attributeNameCheck(lcName)) || // Alternative, second condition checks if it's an `is`-attribute, AND
1442
+ // the value passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
1443
+ lcName === 'is' && CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, value) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(value))) ; else {
1444
+ return false;
1445
+ }
1446
+ /* Check value is safe. First, is attr inert? If so, is safe */
1447
+
1448
+ } else if (URI_SAFE_ATTRIBUTES[lcName]) ; else if (regExpTest(IS_ALLOWED_URI$1, stringReplace(value, ATTR_WHITESPACE, ''))) ; else if ((lcName === 'src' || lcName === 'xlink:href' || lcName === 'href') && lcTag !== 'script' && stringIndexOf(value, 'data:') === 0 && DATA_URI_TAGS[lcTag]) ; else if (ALLOW_UNKNOWN_PROTOCOLS && !regExpTest(IS_SCRIPT_OR_DATA, stringReplace(value, ATTR_WHITESPACE, ''))) ; else if (value) {
1449
+ return false;
1450
+ } else ;
1451
+
1452
+ return true;
1453
+ };
1454
+ /**
1455
+ * _basicCustomElementCheck
1456
+ * checks if at least one dash is included in tagName, and it's not the first char
1457
+ * for more sophisticated checking see https://github.com/sindresorhus/validate-element-name
1458
+ * @param {string} tagName name of the tag of the node to sanitize
1459
+ */
1460
+
1461
+
1462
+ const _basicCustomElementTest = function _basicCustomElementTest(tagName) {
1463
+ return tagName.indexOf('-') > 0;
1464
+ };
1465
+ /**
1466
+ * _sanitizeAttributes
1467
+ *
1468
+ * @protect attributes
1469
+ * @protect nodeName
1470
+ * @protect removeAttribute
1471
+ * @protect setAttribute
1472
+ *
1473
+ * @param {Node} currentNode to sanitize
1474
+ */
1475
+
1476
+
1477
+ const _sanitizeAttributes = function _sanitizeAttributes(currentNode) {
1478
+ let attr;
1479
+ let value;
1480
+ let lcName;
1481
+ let l;
1482
+ /* Execute a hook if present */
1483
+
1484
+ _executeHook('beforeSanitizeAttributes', currentNode, null);
1485
+
1486
+ const {
1487
+ attributes
1488
+ } = currentNode;
1489
+ /* Check if we have attributes; if not we might have a text node */
1490
+
1491
+ if (!attributes) {
1492
+ return;
1493
+ }
1494
+
1495
+ const hookEvent = {
1496
+ attrName: '',
1497
+ attrValue: '',
1498
+ keepAttr: true,
1499
+ allowedAttributes: ALLOWED_ATTR
1500
+ };
1501
+ l = attributes.length;
1502
+ /* Go backwards over all attributes; safely remove bad ones */
1503
+
1504
+ while (l--) {
1505
+ attr = attributes[l];
1506
+ const {
1507
+ name,
1508
+ namespaceURI
1509
+ } = attr;
1510
+ value = name === 'value' ? attr.value : stringTrim(attr.value);
1511
+ lcName = transformCaseFunc(name);
1512
+ /* Execute a hook if present */
1513
+
1514
+ hookEvent.attrName = lcName;
1515
+ hookEvent.attrValue = value;
1516
+ hookEvent.keepAttr = true;
1517
+ hookEvent.forceKeepAttr = undefined; // Allows developers to see this is a property they can set
1518
+
1519
+ _executeHook('uponSanitizeAttribute', currentNode, hookEvent);
1520
+
1521
+ value = hookEvent.attrValue;
1522
+ /* Did the hooks approve of the attribute? */
1523
+
1524
+ if (hookEvent.forceKeepAttr) {
1525
+ continue;
1526
+ }
1527
+ /* Remove attribute */
1528
+
1529
+
1530
+ _removeAttribute(name, currentNode);
1531
+ /* Did the hooks approve of the attribute? */
1532
+
1533
+
1534
+ if (!hookEvent.keepAttr) {
1535
+ continue;
1536
+ }
1537
+ /* Work around a security issue in jQuery 3.0 */
1538
+
1539
+
1540
+ if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(/\/>/i, value)) {
1541
+ _removeAttribute(name, currentNode);
1542
+
1543
+ continue;
1544
+ }
1545
+ /* Sanitize attribute content to be template-safe */
1546
+
1547
+
1548
+ if (SAFE_FOR_TEMPLATES) {
1549
+ value = stringReplace(value, MUSTACHE_EXPR, ' ');
1550
+ value = stringReplace(value, ERB_EXPR, ' ');
1551
+ value = stringReplace(value, TMPLIT_EXPR, ' ');
1552
+ }
1553
+ /* Is `value` valid for this attribute? */
1554
+
1555
+
1556
+ const lcTag = transformCaseFunc(currentNode.nodeName);
1557
+
1558
+ if (!_isValidAttribute(lcTag, lcName, value)) {
1559
+ continue;
1560
+ }
1561
+ /* Full DOM Clobbering protection via namespace isolation,
1562
+ * Prefix id and name attributes with `user-content-`
1563
+ */
1564
+
1565
+
1566
+ if (SANITIZE_NAMED_PROPS && (lcName === 'id' || lcName === 'name')) {
1567
+ // Remove the attribute with this value
1568
+ _removeAttribute(name, currentNode); // Prefix the value and later re-create the attribute with the sanitized value
1569
+
1570
+
1571
+ value = SANITIZE_NAMED_PROPS_PREFIX + value;
1572
+ }
1573
+ /* Handle attributes that require Trusted Types */
1574
+
1575
+
1576
+ if (trustedTypesPolicy && typeof trustedTypes === 'object' && typeof trustedTypes.getAttributeType === 'function') {
1577
+ if (namespaceURI) ; else {
1578
+ switch (trustedTypes.getAttributeType(lcTag, lcName)) {
1579
+ case 'TrustedHTML':
1580
+ {
1581
+ value = trustedTypesPolicy.createHTML(value);
1582
+ break;
1583
+ }
1584
+
1585
+ case 'TrustedScriptURL':
1586
+ {
1587
+ value = trustedTypesPolicy.createScriptURL(value);
1588
+ break;
1589
+ }
1590
+ }
1591
+ }
1592
+ }
1593
+ /* Handle invalid data-* attribute set by try-catching it */
1594
+
1595
+
1596
+ try {
1597
+ if (namespaceURI) {
1598
+ currentNode.setAttributeNS(namespaceURI, name, value);
1599
+ } else {
1600
+ /* Fallback to setAttribute() for browser-unrecognized namespaces e.g. "x-schema". */
1601
+ currentNode.setAttribute(name, value);
1602
+ }
1603
+
1604
+ arrayPop(DOMPurify.removed);
1605
+ } catch (_) {}
1606
+ }
1607
+ /* Execute a hook if present */
1608
+
1609
+
1610
+ _executeHook('afterSanitizeAttributes', currentNode, null);
1611
+ };
1612
+ /**
1613
+ * _sanitizeShadowDOM
1614
+ *
1615
+ * @param {DocumentFragment} fragment to iterate over recursively
1616
+ */
1617
+
1618
+
1619
+ const _sanitizeShadowDOM = function _sanitizeShadowDOM(fragment) {
1620
+ let shadowNode;
1621
+
1622
+ const shadowIterator = _createIterator(fragment);
1623
+ /* Execute a hook if present */
1624
+
1625
+
1626
+ _executeHook('beforeSanitizeShadowDOM', fragment, null);
1627
+
1628
+ while (shadowNode = shadowIterator.nextNode()) {
1629
+ /* Execute a hook if present */
1630
+ _executeHook('uponSanitizeShadowNode', shadowNode, null);
1631
+ /* Sanitize tags and elements */
1632
+
1633
+
1634
+ if (_sanitizeElements(shadowNode)) {
1635
+ continue;
1636
+ }
1637
+ /* Deep shadow DOM detected */
1638
+
1639
+
1640
+ if (shadowNode.content instanceof DocumentFragment) {
1641
+ _sanitizeShadowDOM(shadowNode.content);
1642
+ }
1643
+ /* Check attributes, sanitize if necessary */
1644
+
1645
+
1646
+ _sanitizeAttributes(shadowNode);
1647
+ }
1648
+ /* Execute a hook if present */
1649
+
1650
+
1651
+ _executeHook('afterSanitizeShadowDOM', fragment, null);
1652
+ };
1653
+ /**
1654
+ * Sanitize
1655
+ * Public method providing core sanitation functionality
1656
+ *
1657
+ * @param {String|Node} dirty string or DOM node
1658
+ * @param {Object} configuration object
1659
+ */
1660
+ // eslint-disable-next-line complexity
1661
+
1662
+
1663
+ DOMPurify.sanitize = function (dirty) {
1664
+ let cfg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1665
+ let body;
1666
+ let importedNode;
1667
+ let currentNode;
1668
+ let returnNode;
1669
+ /* Make sure we have a string to sanitize.
1670
+ DO NOT return early, as this will return the wrong type if
1671
+ the user has requested a DOM object rather than a string */
1672
+
1673
+ IS_EMPTY_INPUT = !dirty;
1674
+
1675
+ if (IS_EMPTY_INPUT) {
1676
+ dirty = '<!-->';
1677
+ }
1678
+ /* Stringify, in case dirty is an object */
1679
+
1680
+
1681
+ if (typeof dirty !== 'string' && !_isNode(dirty)) {
1682
+ if (typeof dirty.toString === 'function') {
1683
+ dirty = dirty.toString();
1684
+
1685
+ if (typeof dirty !== 'string') {
1686
+ throw typeErrorCreate('dirty is not a string, aborting');
1687
+ }
1688
+ } else {
1689
+ throw typeErrorCreate('toString is not a function');
1690
+ }
1691
+ }
1692
+ /* Return dirty HTML if DOMPurify cannot run */
1693
+
1694
+
1695
+ if (!DOMPurify.isSupported) {
1696
+ return dirty;
1697
+ }
1698
+ /* Assign config vars */
1699
+
1700
+
1701
+ if (!SET_CONFIG) {
1702
+ _parseConfig(cfg);
1703
+ }
1704
+ /* Clean up removed elements */
1705
+
1706
+
1707
+ DOMPurify.removed = [];
1708
+ /* Check if dirty is correctly typed for IN_PLACE */
1709
+
1710
+ if (typeof dirty === 'string') {
1711
+ IN_PLACE = false;
1712
+ }
1713
+
1714
+ if (IN_PLACE) {
1715
+ /* Do some early pre-sanitization to avoid unsafe root nodes */
1716
+ if (dirty.nodeName) {
1717
+ const tagName = transformCaseFunc(dirty.nodeName);
1718
+
1719
+ if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
1720
+ throw typeErrorCreate('root node is forbidden and cannot be sanitized in-place');
1721
+ }
1722
+ }
1723
+ } else if (dirty instanceof Node) {
1724
+ /* If dirty is a DOM element, append to an empty document to avoid
1725
+ elements being stripped by the parser */
1726
+ body = _initDocument('<!---->');
1727
+ importedNode = body.ownerDocument.importNode(dirty, true);
1728
+
1729
+ if (importedNode.nodeType === 1 && importedNode.nodeName === 'BODY') {
1730
+ /* Node is already a body, use as is */
1731
+ body = importedNode;
1732
+ } else if (importedNode.nodeName === 'HTML') {
1733
+ body = importedNode;
1734
+ } else {
1735
+ // eslint-disable-next-line unicorn/prefer-dom-node-append
1736
+ body.appendChild(importedNode);
1737
+ }
1738
+ } else {
1739
+ /* Exit directly if we have nothing to do */
1740
+ if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT && // eslint-disable-next-line unicorn/prefer-includes
1741
+ dirty.indexOf('<') === -1) {
1742
+ return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(dirty) : dirty;
1743
+ }
1744
+ /* Initialize the document to work on */
1745
+
1746
+
1747
+ body = _initDocument(dirty);
1748
+ /* Check we have a DOM node from the data */
1749
+
1750
+ if (!body) {
1751
+ return RETURN_DOM ? null : RETURN_TRUSTED_TYPE ? emptyHTML : '';
1752
+ }
1753
+ }
1754
+ /* Remove first element node (ours) if FORCE_BODY is set */
1755
+
1756
+
1757
+ if (body && FORCE_BODY) {
1758
+ _forceRemove(body.firstChild);
1759
+ }
1760
+ /* Get node iterator */
1761
+
1762
+
1763
+ const nodeIterator = _createIterator(IN_PLACE ? dirty : body);
1764
+ /* Now start iterating over the created document */
1765
+
1766
+
1767
+ while (currentNode = nodeIterator.nextNode()) {
1768
+ /* Sanitize tags and elements */
1769
+ if (_sanitizeElements(currentNode)) {
1770
+ continue;
1771
+ }
1772
+ /* Shadow DOM detected, sanitize it */
1773
+
1774
+
1775
+ if (currentNode.content instanceof DocumentFragment) {
1776
+ _sanitizeShadowDOM(currentNode.content);
1777
+ }
1778
+ /* Check attributes, sanitize if necessary */
1779
+
1780
+
1781
+ _sanitizeAttributes(currentNode);
1782
+ }
1783
+ /* If we sanitized `dirty` in-place, return it. */
1784
+
1785
+
1786
+ if (IN_PLACE) {
1787
+ return dirty;
1788
+ }
1789
+ /* Return sanitized string or DOM */
1790
+
1791
+
1792
+ if (RETURN_DOM) {
1793
+ if (RETURN_DOM_FRAGMENT) {
1794
+ returnNode = createDocumentFragment.call(body.ownerDocument);
1795
+
1796
+ while (body.firstChild) {
1797
+ // eslint-disable-next-line unicorn/prefer-dom-node-append
1798
+ returnNode.appendChild(body.firstChild);
1799
+ }
1800
+ } else {
1801
+ returnNode = body;
1802
+ }
1803
+
1804
+ if (ALLOWED_ATTR.shadowroot || ALLOWED_ATTR.shadowrootmode) {
1805
+ /*
1806
+ AdoptNode() is not used because internal state is not reset
1807
+ (e.g. the past names map of a HTMLFormElement), this is safe
1808
+ in theory but we would rather not risk another attack vector.
1809
+ The state that is cloned by importNode() is explicitly defined
1810
+ by the specs.
1811
+ */
1812
+ returnNode = importNode.call(originalDocument, returnNode, true);
1813
+ }
1814
+
1815
+ return returnNode;
1816
+ }
1817
+
1818
+ let serializedHTML = WHOLE_DOCUMENT ? body.outerHTML : body.innerHTML;
1819
+ /* Serialize doctype if allowed */
1820
+
1821
+ if (WHOLE_DOCUMENT && ALLOWED_TAGS['!doctype'] && body.ownerDocument && body.ownerDocument.doctype && body.ownerDocument.doctype.name && regExpTest(DOCTYPE_NAME, body.ownerDocument.doctype.name)) {
1822
+ serializedHTML = '<!DOCTYPE ' + body.ownerDocument.doctype.name + '>\n' + serializedHTML;
1823
+ }
1824
+ /* Sanitize final string template-safe */
1825
+
1826
+
1827
+ if (SAFE_FOR_TEMPLATES) {
1828
+ serializedHTML = stringReplace(serializedHTML, MUSTACHE_EXPR, ' ');
1829
+ serializedHTML = stringReplace(serializedHTML, ERB_EXPR, ' ');
1830
+ serializedHTML = stringReplace(serializedHTML, TMPLIT_EXPR, ' ');
1831
+ }
1832
+
1833
+ return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(serializedHTML) : serializedHTML;
1834
+ };
1835
+ /**
1836
+ * Public method to set the configuration once
1837
+ * setConfig
1838
+ *
1839
+ * @param {Object} cfg configuration object
1840
+ */
1841
+
1842
+
1843
+ DOMPurify.setConfig = function (cfg) {
1844
+ _parseConfig(cfg);
1845
+
1846
+ SET_CONFIG = true;
1847
+ };
1848
+ /**
1849
+ * Public method to remove the configuration
1850
+ * clearConfig
1851
+ *
1852
+ */
1853
+
1854
+
1855
+ DOMPurify.clearConfig = function () {
1856
+ CONFIG = null;
1857
+ SET_CONFIG = false;
1858
+ };
1859
+ /**
1860
+ * Public method to check if an attribute value is valid.
1861
+ * Uses last set config, if any. Otherwise, uses config defaults.
1862
+ * isValidAttribute
1863
+ *
1864
+ * @param {string} tag Tag name of containing element.
1865
+ * @param {string} attr Attribute name.
1866
+ * @param {string} value Attribute value.
1867
+ * @return {Boolean} Returns true if `value` is valid. Otherwise, returns false.
1868
+ */
1869
+
1870
+
1871
+ DOMPurify.isValidAttribute = function (tag, attr, value) {
1872
+ /* Initialize shared config vars if necessary. */
1873
+ if (!CONFIG) {
1874
+ _parseConfig({});
1875
+ }
1876
+
1877
+ const lcTag = transformCaseFunc(tag);
1878
+ const lcName = transformCaseFunc(attr);
1879
+ return _isValidAttribute(lcTag, lcName, value);
1880
+ };
1881
+ /**
1882
+ * AddHook
1883
+ * Public method to add DOMPurify hooks
1884
+ *
1885
+ * @param {String} entryPoint entry point for the hook to add
1886
+ * @param {Function} hookFunction function to execute
1887
+ */
1888
+
1889
+
1890
+ DOMPurify.addHook = function (entryPoint, hookFunction) {
1891
+ if (typeof hookFunction !== 'function') {
1892
+ return;
1893
+ }
1894
+
1895
+ hooks[entryPoint] = hooks[entryPoint] || [];
1896
+ arrayPush(hooks[entryPoint], hookFunction);
1897
+ };
1898
+ /**
1899
+ * RemoveHook
1900
+ * Public method to remove a DOMPurify hook at a given entryPoint
1901
+ * (pops it from the stack of hooks if more are present)
1902
+ *
1903
+ * @param {String} entryPoint entry point for the hook to remove
1904
+ * @return {Function} removed(popped) hook
1905
+ */
1906
+
1907
+
1908
+ DOMPurify.removeHook = function (entryPoint) {
1909
+ if (hooks[entryPoint]) {
1910
+ return arrayPop(hooks[entryPoint]);
1911
+ }
1912
+ };
1913
+ /**
1914
+ * RemoveHooks
1915
+ * Public method to remove all DOMPurify hooks at a given entryPoint
1916
+ *
1917
+ * @param {String} entryPoint entry point for the hooks to remove
1918
+ */
1919
+
1920
+
1921
+ DOMPurify.removeHooks = function (entryPoint) {
1922
+ if (hooks[entryPoint]) {
1923
+ hooks[entryPoint] = [];
1924
+ }
1925
+ };
1926
+ /**
1927
+ * RemoveAllHooks
1928
+ * Public method to remove all DOMPurify hooks
1929
+ *
1930
+ */
1931
+
1932
+
1933
+ DOMPurify.removeAllHooks = function () {
1934
+ hooks = {};
1935
+ };
1936
+
1937
+ return DOMPurify;
1938
+ }
1939
+
1940
+ var purify = createDOMPurify();
1941
+
1942
+ return purify;
1943
+
1944
+ }));
1945
+
1946
+ } (purify));
1947
+
1948
+ var DOMPurify = purifyExports;
1949
+
1950
+ const min = Math.min;
1951
+ const max = Math.max;
1952
+ const round = Math.round;
1953
+ const floor = Math.floor;
1954
+ const createCoords = v => ({
1955
+ x: v,
1956
+ y: v
1957
+ });
1958
+ function clamp(start, value, end) {
1959
+ return max(start, min(value, end));
1960
+ }
1961
+ function evaluate(value, param) {
1962
+ return typeof value === 'function' ? value(param) : value;
1963
+ }
1964
+ function getSide(placement) {
1965
+ return placement.split('-')[0];
1966
+ }
1967
+ function getAlignment(placement) {
1968
+ return placement.split('-')[1];
1969
+ }
1970
+ function getOppositeAxis(axis) {
1971
+ return axis === 'x' ? 'y' : 'x';
1972
+ }
1973
+ function getAxisLength(axis) {
1974
+ return axis === 'y' ? 'height' : 'width';
1975
+ }
1976
+ function getSideAxis(placement) {
1977
+ return ['top', 'bottom'].includes(getSide(placement)) ? 'y' : 'x';
1978
+ }
1979
+ function getAlignmentAxis(placement) {
1980
+ return getOppositeAxis(getSideAxis(placement));
1981
+ }
1982
+ function expandPaddingObject(padding) {
1983
+ return {
1984
+ top: 0,
1985
+ right: 0,
1986
+ bottom: 0,
1987
+ left: 0,
1988
+ ...padding
1989
+ };
1990
+ }
1991
+ function getPaddingObject(padding) {
1992
+ return typeof padding !== 'number' ? expandPaddingObject(padding) : {
1993
+ top: padding,
1994
+ right: padding,
1995
+ bottom: padding,
1996
+ left: padding
1997
+ };
1998
+ }
1999
+ function rectToClientRect(rect) {
2000
+ return {
2001
+ ...rect,
2002
+ top: rect.y,
2003
+ left: rect.x,
2004
+ right: rect.x + rect.width,
2005
+ bottom: rect.y + rect.height
2006
+ };
2007
+ }
2008
+
2009
+ function computeCoordsFromPlacement(_ref, placement, rtl) {
2010
+ let {
2011
+ reference,
2012
+ floating
2013
+ } = _ref;
2014
+ const sideAxis = getSideAxis(placement);
2015
+ const alignmentAxis = getAlignmentAxis(placement);
2016
+ const alignLength = getAxisLength(alignmentAxis);
2017
+ const side = getSide(placement);
2018
+ const isVertical = sideAxis === 'y';
2019
+ const commonX = reference.x + reference.width / 2 - floating.width / 2;
2020
+ const commonY = reference.y + reference.height / 2 - floating.height / 2;
2021
+ const commonAlign = reference[alignLength] / 2 - floating[alignLength] / 2;
2022
+ let coords;
2023
+ switch (side) {
2024
+ case 'top':
2025
+ coords = {
2026
+ x: commonX,
2027
+ y: reference.y - floating.height
2028
+ };
2029
+ break;
2030
+ case 'bottom':
2031
+ coords = {
2032
+ x: commonX,
2033
+ y: reference.y + reference.height
2034
+ };
2035
+ break;
2036
+ case 'right':
2037
+ coords = {
2038
+ x: reference.x + reference.width,
2039
+ y: commonY
2040
+ };
2041
+ break;
2042
+ case 'left':
2043
+ coords = {
2044
+ x: reference.x - floating.width,
2045
+ y: commonY
2046
+ };
2047
+ break;
2048
+ default:
2049
+ coords = {
2050
+ x: reference.x,
2051
+ y: reference.y
2052
+ };
2053
+ }
2054
+ switch (getAlignment(placement)) {
2055
+ case 'start':
2056
+ coords[alignmentAxis] -= commonAlign * (rtl && isVertical ? -1 : 1);
2057
+ break;
2058
+ case 'end':
2059
+ coords[alignmentAxis] += commonAlign * (rtl && isVertical ? -1 : 1);
2060
+ break;
2061
+ }
2062
+ return coords;
2063
+ }
2064
+
2065
+ /**
2066
+ * Computes the `x` and `y` coordinates that will place the floating element
2067
+ * next to a reference element when it is given a certain positioning strategy.
2068
+ *
2069
+ * This export does not have any `platform` interface logic. You will need to
2070
+ * write one for the platform you are using Floating UI with.
2071
+ */
2072
+ const computePosition$1 = async (reference, floating, config) => {
2073
+ const {
2074
+ placement = 'bottom',
2075
+ strategy = 'absolute',
2076
+ middleware = [],
2077
+ platform
2078
+ } = config;
2079
+ const validMiddleware = middleware.filter(Boolean);
2080
+ const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(floating));
2081
+ let rects = await platform.getElementRects({
2082
+ reference,
2083
+ floating,
2084
+ strategy
2085
+ });
2086
+ let {
2087
+ x,
2088
+ y
2089
+ } = computeCoordsFromPlacement(rects, placement, rtl);
2090
+ let statefulPlacement = placement;
2091
+ let middlewareData = {};
2092
+ let resetCount = 0;
2093
+ for (let i = 0; i < validMiddleware.length; i++) {
2094
+ const {
2095
+ name,
2096
+ fn
2097
+ } = validMiddleware[i];
2098
+ const {
2099
+ x: nextX,
2100
+ y: nextY,
2101
+ data,
2102
+ reset
2103
+ } = await fn({
2104
+ x,
2105
+ y,
2106
+ initialPlacement: placement,
2107
+ placement: statefulPlacement,
2108
+ strategy,
2109
+ middlewareData,
2110
+ rects,
2111
+ platform,
2112
+ elements: {
2113
+ reference,
2114
+ floating
2115
+ }
2116
+ });
2117
+ x = nextX != null ? nextX : x;
2118
+ y = nextY != null ? nextY : y;
2119
+ middlewareData = {
2120
+ ...middlewareData,
2121
+ [name]: {
2122
+ ...middlewareData[name],
2123
+ ...data
2124
+ }
2125
+ };
2126
+ if (reset && resetCount <= 50) {
2127
+ resetCount++;
2128
+ if (typeof reset === 'object') {
2129
+ if (reset.placement) {
2130
+ statefulPlacement = reset.placement;
2131
+ }
2132
+ if (reset.rects) {
2133
+ rects = reset.rects === true ? await platform.getElementRects({
2134
+ reference,
2135
+ floating,
2136
+ strategy
2137
+ }) : reset.rects;
2138
+ }
2139
+ ({
2140
+ x,
2141
+ y
2142
+ } = computeCoordsFromPlacement(rects, statefulPlacement, rtl));
2143
+ }
2144
+ i = -1;
2145
+ continue;
2146
+ }
2147
+ }
2148
+ return {
2149
+ x,
2150
+ y,
2151
+ placement: statefulPlacement,
2152
+ strategy,
2153
+ middlewareData
2154
+ };
2155
+ };
2156
+
2157
+ /**
2158
+ * Provides data to position an inner element of the floating element so that it
2159
+ * appears centered to the reference element.
2160
+ * @see https://floating-ui.com/docs/arrow
2161
+ */
2162
+ const arrow = options => ({
2163
+ name: 'arrow',
2164
+ options,
2165
+ async fn(state) {
2166
+ const {
2167
+ x,
2168
+ y,
2169
+ placement,
2170
+ rects,
2171
+ platform,
2172
+ elements
2173
+ } = state;
2174
+ // Since `element` is required, we don't Partial<> the type.
2175
+ const {
2176
+ element,
2177
+ padding = 0
2178
+ } = evaluate(options, state) || {};
2179
+ if (element == null) {
2180
+ return {};
2181
+ }
2182
+ const paddingObject = getPaddingObject(padding);
2183
+ const coords = {
2184
+ x,
2185
+ y
2186
+ };
2187
+ const axis = getAlignmentAxis(placement);
2188
+ const length = getAxisLength(axis);
2189
+ const arrowDimensions = await platform.getDimensions(element);
2190
+ const isYAxis = axis === 'y';
2191
+ const minProp = isYAxis ? 'top' : 'left';
2192
+ const maxProp = isYAxis ? 'bottom' : 'right';
2193
+ const clientProp = isYAxis ? 'clientHeight' : 'clientWidth';
2194
+ const endDiff = rects.reference[length] + rects.reference[axis] - coords[axis] - rects.floating[length];
2195
+ const startDiff = coords[axis] - rects.reference[axis];
2196
+ const arrowOffsetParent = await (platform.getOffsetParent == null ? void 0 : platform.getOffsetParent(element));
2197
+ let clientSize = arrowOffsetParent ? arrowOffsetParent[clientProp] : 0;
2198
+
2199
+ // DOM platform can return `window` as the `offsetParent`.
2200
+ if (!clientSize || !(await (platform.isElement == null ? void 0 : platform.isElement(arrowOffsetParent)))) {
2201
+ clientSize = elements.floating[clientProp] || rects.floating[length];
2202
+ }
2203
+ const centerToReference = endDiff / 2 - startDiff / 2;
2204
+
2205
+ // If the padding is large enough that it causes the arrow to no longer be
2206
+ // centered, modify the padding so that it is centered.
2207
+ const largestPossiblePadding = clientSize / 2 - arrowDimensions[length] / 2 - 1;
2208
+ const minPadding = min(paddingObject[minProp], largestPossiblePadding);
2209
+ const maxPadding = min(paddingObject[maxProp], largestPossiblePadding);
2210
+
2211
+ // Make sure the arrow doesn't overflow the floating element if the center
2212
+ // point is outside the floating element's bounds.
2213
+ const min$1 = minPadding;
2214
+ const max = clientSize - arrowDimensions[length] - maxPadding;
2215
+ const center = clientSize / 2 - arrowDimensions[length] / 2 + centerToReference;
2216
+ const offset = clamp(min$1, center, max);
2217
+
2218
+ // If the reference is small enough that the arrow's padding causes it to
2219
+ // to point to nothing for an aligned placement, adjust the offset of the
2220
+ // floating element itself. This stops `shift()` from taking action, but can
2221
+ // be worked around by calling it again after the `arrow()` if desired.
2222
+ const shouldAddOffset = getAlignment(placement) != null && center != offset && rects.reference[length] / 2 - (center < min$1 ? minPadding : maxPadding) - arrowDimensions[length] / 2 < 0;
2223
+ const alignmentOffset = shouldAddOffset ? center < min$1 ? min$1 - center : max - center : 0;
2224
+ return {
2225
+ [axis]: coords[axis] - alignmentOffset,
2226
+ data: {
2227
+ [axis]: offset,
2228
+ centerOffset: center - offset + alignmentOffset
2229
+ }
2230
+ };
2231
+ }
2232
+ });
2233
+
2234
+ // For type backwards-compatibility, the `OffsetOptions` type was also
2235
+ // Derivable.
2236
+ async function convertValueToCoords(state, options) {
2237
+ const {
2238
+ placement,
2239
+ platform,
2240
+ elements
2241
+ } = state;
2242
+ const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating));
2243
+ const side = getSide(placement);
2244
+ const alignment = getAlignment(placement);
2245
+ const isVertical = getSideAxis(placement) === 'y';
2246
+ const mainAxisMulti = ['left', 'top'].includes(side) ? -1 : 1;
2247
+ const crossAxisMulti = rtl && isVertical ? -1 : 1;
2248
+ const rawValue = evaluate(options, state);
2249
+
2250
+ // eslint-disable-next-line prefer-const
2251
+ let {
2252
+ mainAxis,
2253
+ crossAxis,
2254
+ alignmentAxis
2255
+ } = typeof rawValue === 'number' ? {
2256
+ mainAxis: rawValue,
2257
+ crossAxis: 0,
2258
+ alignmentAxis: null
2259
+ } : {
2260
+ mainAxis: 0,
2261
+ crossAxis: 0,
2262
+ alignmentAxis: null,
2263
+ ...rawValue
2264
+ };
2265
+ if (alignment && typeof alignmentAxis === 'number') {
2266
+ crossAxis = alignment === 'end' ? alignmentAxis * -1 : alignmentAxis;
2267
+ }
2268
+ return isVertical ? {
2269
+ x: crossAxis * crossAxisMulti,
2270
+ y: mainAxis * mainAxisMulti
2271
+ } : {
2272
+ x: mainAxis * mainAxisMulti,
2273
+ y: crossAxis * crossAxisMulti
2274
+ };
2275
+ }
2276
+
2277
+ /**
2278
+ * Modifies the placement by translating the floating element along the
2279
+ * specified axes.
2280
+ * A number (shorthand for `mainAxis` or distance), or an axes configuration
2281
+ * object may be passed.
2282
+ * @see https://floating-ui.com/docs/offset
2283
+ */
2284
+ const offset = function (options) {
2285
+ if (options === void 0) {
2286
+ options = 0;
2287
+ }
2288
+ return {
2289
+ name: 'offset',
2290
+ options,
2291
+ async fn(state) {
2292
+ const {
2293
+ x,
2294
+ y
2295
+ } = state;
2296
+ const diffCoords = await convertValueToCoords(state, options);
2297
+ return {
2298
+ x: x + diffCoords.x,
2299
+ y: y + diffCoords.y,
2300
+ data: diffCoords
2301
+ };
2302
+ }
2303
+ };
2304
+ };
2305
+
2306
+ function getNodeName(node) {
2307
+ if (isNode(node)) {
2308
+ return (node.nodeName || '').toLowerCase();
2309
+ }
2310
+ // Mocked nodes in testing environments may not be instances of Node. By
2311
+ // returning `#document` an infinite loop won't occur.
2312
+ // https://github.com/floating-ui/floating-ui/issues/2317
2313
+ return '#document';
2314
+ }
2315
+ function getWindow(node) {
2316
+ var _node$ownerDocument;
2317
+ return (node == null ? void 0 : (_node$ownerDocument = node.ownerDocument) == null ? void 0 : _node$ownerDocument.defaultView) || window;
2318
+ }
2319
+ function getDocumentElement(node) {
2320
+ var _ref;
2321
+ return (_ref = (isNode(node) ? node.ownerDocument : node.document) || window.document) == null ? void 0 : _ref.documentElement;
2322
+ }
2323
+ function isNode(value) {
2324
+ return value instanceof Node || value instanceof getWindow(value).Node;
2325
+ }
2326
+ function isElement(value) {
2327
+ return value instanceof Element || value instanceof getWindow(value).Element;
2328
+ }
2329
+ function isHTMLElement(value) {
2330
+ return value instanceof HTMLElement || value instanceof getWindow(value).HTMLElement;
2331
+ }
2332
+ function isShadowRoot(value) {
2333
+ // Browsers without `ShadowRoot` support.
2334
+ if (typeof ShadowRoot === 'undefined') {
2335
+ return false;
2336
+ }
2337
+ return value instanceof ShadowRoot || value instanceof getWindow(value).ShadowRoot;
2338
+ }
2339
+ function isOverflowElement(element) {
2340
+ const {
2341
+ overflow,
2342
+ overflowX,
2343
+ overflowY,
2344
+ display
2345
+ } = getComputedStyle$1(element);
2346
+ return /auto|scroll|overlay|hidden|clip/.test(overflow + overflowY + overflowX) && !['inline', 'contents'].includes(display);
2347
+ }
2348
+ function isTableElement(element) {
2349
+ return ['table', 'td', 'th'].includes(getNodeName(element));
2350
+ }
2351
+ function isContainingBlock(element) {
2352
+ const webkit = isWebKit();
2353
+ const css = getComputedStyle$1(element);
2354
+
2355
+ // https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block#identifying_the_containing_block
2356
+ return css.transform !== 'none' || css.perspective !== 'none' || (css.containerType ? css.containerType !== 'normal' : false) || !webkit && (css.backdropFilter ? css.backdropFilter !== 'none' : false) || !webkit && (css.filter ? css.filter !== 'none' : false) || ['transform', 'perspective', 'filter'].some(value => (css.willChange || '').includes(value)) || ['paint', 'layout', 'strict', 'content'].some(value => (css.contain || '').includes(value));
2357
+ }
2358
+ function getContainingBlock(element) {
2359
+ let currentNode = getParentNode(element);
2360
+ while (isHTMLElement(currentNode) && !isLastTraversableNode(currentNode)) {
2361
+ if (isContainingBlock(currentNode)) {
2362
+ return currentNode;
2363
+ } else {
2364
+ currentNode = getParentNode(currentNode);
2365
+ }
2366
+ }
2367
+ return null;
2368
+ }
2369
+ function isWebKit() {
2370
+ if (typeof CSS === 'undefined' || !CSS.supports) return false;
2371
+ return CSS.supports('-webkit-backdrop-filter', 'none');
2372
+ }
2373
+ function isLastTraversableNode(node) {
2374
+ return ['html', 'body', '#document'].includes(getNodeName(node));
2375
+ }
2376
+ function getComputedStyle$1(element) {
2377
+ return getWindow(element).getComputedStyle(element);
2378
+ }
2379
+ function getNodeScroll(element) {
2380
+ if (isElement(element)) {
2381
+ return {
2382
+ scrollLeft: element.scrollLeft,
2383
+ scrollTop: element.scrollTop
2384
+ };
2385
+ }
2386
+ return {
2387
+ scrollLeft: element.pageXOffset,
2388
+ scrollTop: element.pageYOffset
2389
+ };
2390
+ }
2391
+ function getParentNode(node) {
2392
+ if (getNodeName(node) === 'html') {
2393
+ return node;
2394
+ }
2395
+ const result =
2396
+ // Step into the shadow DOM of the parent of a slotted node.
2397
+ node.assignedSlot ||
2398
+ // DOM Element detected.
2399
+ node.parentNode ||
2400
+ // ShadowRoot detected.
2401
+ isShadowRoot(node) && node.host ||
2402
+ // Fallback.
2403
+ getDocumentElement(node);
2404
+ return isShadowRoot(result) ? result.host : result;
2405
+ }
2406
+ function getNearestOverflowAncestor(node) {
2407
+ const parentNode = getParentNode(node);
2408
+ if (isLastTraversableNode(parentNode)) {
2409
+ return node.ownerDocument ? node.ownerDocument.body : node.body;
2410
+ }
2411
+ if (isHTMLElement(parentNode) && isOverflowElement(parentNode)) {
2412
+ return parentNode;
2413
+ }
2414
+ return getNearestOverflowAncestor(parentNode);
2415
+ }
2416
+ function getOverflowAncestors(node, list) {
2417
+ var _node$ownerDocument2;
2418
+ if (list === void 0) {
2419
+ list = [];
2420
+ }
2421
+ const scrollableAncestor = getNearestOverflowAncestor(node);
2422
+ const isBody = scrollableAncestor === ((_node$ownerDocument2 = node.ownerDocument) == null ? void 0 : _node$ownerDocument2.body);
2423
+ const win = getWindow(scrollableAncestor);
2424
+ if (isBody) {
2425
+ return list.concat(win, win.visualViewport || [], isOverflowElement(scrollableAncestor) ? scrollableAncestor : []);
2426
+ }
2427
+ return list.concat(scrollableAncestor, getOverflowAncestors(scrollableAncestor));
2428
+ }
2429
+
2430
+ function getCssDimensions(element) {
2431
+ const css = getComputedStyle$1(element);
2432
+ // In testing environments, the `width` and `height` properties are empty
2433
+ // strings for SVG elements, returning NaN. Fallback to `0` in this case.
2434
+ let width = parseFloat(css.width) || 0;
2435
+ let height = parseFloat(css.height) || 0;
2436
+ const hasOffset = isHTMLElement(element);
2437
+ const offsetWidth = hasOffset ? element.offsetWidth : width;
2438
+ const offsetHeight = hasOffset ? element.offsetHeight : height;
2439
+ const shouldFallback = round(width) !== offsetWidth || round(height) !== offsetHeight;
2440
+ if (shouldFallback) {
2441
+ width = offsetWidth;
2442
+ height = offsetHeight;
2443
+ }
2444
+ return {
2445
+ width,
2446
+ height,
2447
+ $: shouldFallback
2448
+ };
2449
+ }
2450
+
2451
+ function unwrapElement(element) {
2452
+ return !isElement(element) ? element.contextElement : element;
2453
+ }
2454
+
2455
+ function getScale(element) {
2456
+ const domElement = unwrapElement(element);
2457
+ if (!isHTMLElement(domElement)) {
2458
+ return createCoords(1);
2459
+ }
2460
+ const rect = domElement.getBoundingClientRect();
2461
+ const {
2462
+ width,
2463
+ height,
2464
+ $
2465
+ } = getCssDimensions(domElement);
2466
+ let x = ($ ? round(rect.width) : rect.width) / width;
2467
+ let y = ($ ? round(rect.height) : rect.height) / height;
2468
+
2469
+ // 0, NaN, or Infinity should always fallback to 1.
2470
+
2471
+ if (!x || !Number.isFinite(x)) {
2472
+ x = 1;
2473
+ }
2474
+ if (!y || !Number.isFinite(y)) {
2475
+ y = 1;
2476
+ }
2477
+ return {
2478
+ x,
2479
+ y
2480
+ };
2481
+ }
2482
+
2483
+ const noOffsets = /*#__PURE__*/createCoords(0);
2484
+ function getVisualOffsets(element) {
2485
+ const win = getWindow(element);
2486
+ if (!isWebKit() || !win.visualViewport) {
2487
+ return noOffsets;
2488
+ }
2489
+ return {
2490
+ x: win.visualViewport.offsetLeft,
2491
+ y: win.visualViewport.offsetTop
2492
+ };
2493
+ }
2494
+ function shouldAddVisualOffsets(element, isFixed, floatingOffsetParent) {
2495
+ if (isFixed === void 0) {
2496
+ isFixed = false;
2497
+ }
2498
+ if (!floatingOffsetParent || isFixed && floatingOffsetParent !== getWindow(element)) {
2499
+ return false;
2500
+ }
2501
+ return isFixed;
2502
+ }
2503
+
2504
+ function getBoundingClientRect(element, includeScale, isFixedStrategy, offsetParent) {
2505
+ if (includeScale === void 0) {
2506
+ includeScale = false;
2507
+ }
2508
+ if (isFixedStrategy === void 0) {
2509
+ isFixedStrategy = false;
2510
+ }
2511
+ const clientRect = element.getBoundingClientRect();
2512
+ const domElement = unwrapElement(element);
2513
+ let scale = createCoords(1);
2514
+ if (includeScale) {
2515
+ if (offsetParent) {
2516
+ if (isElement(offsetParent)) {
2517
+ scale = getScale(offsetParent);
2518
+ }
2519
+ } else {
2520
+ scale = getScale(element);
2521
+ }
2522
+ }
2523
+ const visualOffsets = shouldAddVisualOffsets(domElement, isFixedStrategy, offsetParent) ? getVisualOffsets(domElement) : createCoords(0);
2524
+ let x = (clientRect.left + visualOffsets.x) / scale.x;
2525
+ let y = (clientRect.top + visualOffsets.y) / scale.y;
2526
+ let width = clientRect.width / scale.x;
2527
+ let height = clientRect.height / scale.y;
2528
+ if (domElement) {
2529
+ const win = getWindow(domElement);
2530
+ const offsetWin = offsetParent && isElement(offsetParent) ? getWindow(offsetParent) : offsetParent;
2531
+ let currentIFrame = win.frameElement;
2532
+ while (currentIFrame && offsetParent && offsetWin !== win) {
2533
+ const iframeScale = getScale(currentIFrame);
2534
+ const iframeRect = currentIFrame.getBoundingClientRect();
2535
+ const css = getComputedStyle$1(currentIFrame);
2536
+ const left = iframeRect.left + (currentIFrame.clientLeft + parseFloat(css.paddingLeft)) * iframeScale.x;
2537
+ const top = iframeRect.top + (currentIFrame.clientTop + parseFloat(css.paddingTop)) * iframeScale.y;
2538
+ x *= iframeScale.x;
2539
+ y *= iframeScale.y;
2540
+ width *= iframeScale.x;
2541
+ height *= iframeScale.y;
2542
+ x += left;
2543
+ y += top;
2544
+ currentIFrame = getWindow(currentIFrame).frameElement;
2545
+ }
2546
+ }
2547
+ return rectToClientRect({
2548
+ width,
2549
+ height,
2550
+ x,
2551
+ y
2552
+ });
2553
+ }
2554
+
2555
+ function convertOffsetParentRelativeRectToViewportRelativeRect(_ref) {
2556
+ let {
2557
+ rect,
2558
+ offsetParent,
2559
+ strategy
2560
+ } = _ref;
2561
+ const isOffsetParentAnElement = isHTMLElement(offsetParent);
2562
+ const documentElement = getDocumentElement(offsetParent);
2563
+ if (offsetParent === documentElement) {
2564
+ return rect;
2565
+ }
2566
+ let scroll = {
2567
+ scrollLeft: 0,
2568
+ scrollTop: 0
2569
+ };
2570
+ let scale = createCoords(1);
2571
+ const offsets = createCoords(0);
2572
+ if (isOffsetParentAnElement || !isOffsetParentAnElement && strategy !== 'fixed') {
2573
+ if (getNodeName(offsetParent) !== 'body' || isOverflowElement(documentElement)) {
2574
+ scroll = getNodeScroll(offsetParent);
2575
+ }
2576
+ if (isHTMLElement(offsetParent)) {
2577
+ const offsetRect = getBoundingClientRect(offsetParent);
2578
+ scale = getScale(offsetParent);
2579
+ offsets.x = offsetRect.x + offsetParent.clientLeft;
2580
+ offsets.y = offsetRect.y + offsetParent.clientTop;
2581
+ }
2582
+ }
2583
+ return {
2584
+ width: rect.width * scale.x,
2585
+ height: rect.height * scale.y,
2586
+ x: rect.x * scale.x - scroll.scrollLeft * scale.x + offsets.x,
2587
+ y: rect.y * scale.y - scroll.scrollTop * scale.y + offsets.y
2588
+ };
2589
+ }
2590
+
2591
+ function getClientRects(element) {
2592
+ return Array.from(element.getClientRects());
2593
+ }
2594
+
2595
+ function getWindowScrollBarX(element) {
2596
+ // If <html> has a CSS width greater than the viewport, then this will be
2597
+ // incorrect for RTL.
2598
+ return getBoundingClientRect(getDocumentElement(element)).left + getNodeScroll(element).scrollLeft;
2599
+ }
2600
+
2601
+ // Gets the entire size of the scrollable document area, even extending outside
2602
+ // of the `<html>` and `<body>` rect bounds if horizontally scrollable.
2603
+ function getDocumentRect(element) {
2604
+ const html = getDocumentElement(element);
2605
+ const scroll = getNodeScroll(element);
2606
+ const body = element.ownerDocument.body;
2607
+ const width = max(html.scrollWidth, html.clientWidth, body.scrollWidth, body.clientWidth);
2608
+ const height = max(html.scrollHeight, html.clientHeight, body.scrollHeight, body.clientHeight);
2609
+ let x = -scroll.scrollLeft + getWindowScrollBarX(element);
2610
+ const y = -scroll.scrollTop;
2611
+ if (getComputedStyle$1(body).direction === 'rtl') {
2612
+ x += max(html.clientWidth, body.clientWidth) - width;
2613
+ }
2614
+ return {
2615
+ width,
2616
+ height,
2617
+ x,
2618
+ y
2619
+ };
2620
+ }
2621
+
2622
+ function getViewportRect(element, strategy) {
2623
+ const win = getWindow(element);
2624
+ const html = getDocumentElement(element);
2625
+ const visualViewport = win.visualViewport;
2626
+ let width = html.clientWidth;
2627
+ let height = html.clientHeight;
2628
+ let x = 0;
2629
+ let y = 0;
2630
+ if (visualViewport) {
2631
+ width = visualViewport.width;
2632
+ height = visualViewport.height;
2633
+ const visualViewportBased = isWebKit();
2634
+ if (!visualViewportBased || visualViewportBased && strategy === 'fixed') {
2635
+ x = visualViewport.offsetLeft;
2636
+ y = visualViewport.offsetTop;
2637
+ }
2638
+ }
2639
+ return {
2640
+ width,
2641
+ height,
2642
+ x,
2643
+ y
2644
+ };
2645
+ }
2646
+
2647
+ // Returns the inner client rect, subtracting scrollbars if present.
2648
+ function getInnerBoundingClientRect(element, strategy) {
2649
+ const clientRect = getBoundingClientRect(element, true, strategy === 'fixed');
2650
+ const top = clientRect.top + element.clientTop;
2651
+ const left = clientRect.left + element.clientLeft;
2652
+ const scale = isHTMLElement(element) ? getScale(element) : createCoords(1);
2653
+ const width = element.clientWidth * scale.x;
2654
+ const height = element.clientHeight * scale.y;
2655
+ const x = left * scale.x;
2656
+ const y = top * scale.y;
2657
+ return {
2658
+ width,
2659
+ height,
2660
+ x,
2661
+ y
2662
+ };
2663
+ }
2664
+ function getClientRectFromClippingAncestor(element, clippingAncestor, strategy) {
2665
+ let rect;
2666
+ if (clippingAncestor === 'viewport') {
2667
+ rect = getViewportRect(element, strategy);
2668
+ } else if (clippingAncestor === 'document') {
2669
+ rect = getDocumentRect(getDocumentElement(element));
2670
+ } else if (isElement(clippingAncestor)) {
2671
+ rect = getInnerBoundingClientRect(clippingAncestor, strategy);
2672
+ } else {
2673
+ const visualOffsets = getVisualOffsets(element);
2674
+ rect = {
2675
+ ...clippingAncestor,
2676
+ x: clippingAncestor.x - visualOffsets.x,
2677
+ y: clippingAncestor.y - visualOffsets.y
2678
+ };
2679
+ }
2680
+ return rectToClientRect(rect);
2681
+ }
2682
+ function hasFixedPositionAncestor(element, stopNode) {
2683
+ const parentNode = getParentNode(element);
2684
+ if (parentNode === stopNode || !isElement(parentNode) || isLastTraversableNode(parentNode)) {
2685
+ return false;
2686
+ }
2687
+ return getComputedStyle$1(parentNode).position === 'fixed' || hasFixedPositionAncestor(parentNode, stopNode);
2688
+ }
2689
+
2690
+ // A "clipping ancestor" is an `overflow` element with the characteristic of
2691
+ // clipping (or hiding) child elements. This returns all clipping ancestors
2692
+ // of the given element up the tree.
2693
+ function getClippingElementAncestors(element, cache) {
2694
+ const cachedResult = cache.get(element);
2695
+ if (cachedResult) {
2696
+ return cachedResult;
2697
+ }
2698
+ let result = getOverflowAncestors(element).filter(el => isElement(el) && getNodeName(el) !== 'body');
2699
+ let currentContainingBlockComputedStyle = null;
2700
+ const elementIsFixed = getComputedStyle$1(element).position === 'fixed';
2701
+ let currentNode = elementIsFixed ? getParentNode(element) : element;
2702
+
2703
+ // https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block#identifying_the_containing_block
2704
+ while (isElement(currentNode) && !isLastTraversableNode(currentNode)) {
2705
+ const computedStyle = getComputedStyle$1(currentNode);
2706
+ const currentNodeIsContaining = isContainingBlock(currentNode);
2707
+ if (!currentNodeIsContaining && computedStyle.position === 'fixed') {
2708
+ currentContainingBlockComputedStyle = null;
2709
+ }
2710
+ const shouldDropCurrentNode = elementIsFixed ? !currentNodeIsContaining && !currentContainingBlockComputedStyle : !currentNodeIsContaining && computedStyle.position === 'static' && !!currentContainingBlockComputedStyle && ['absolute', 'fixed'].includes(currentContainingBlockComputedStyle.position) || isOverflowElement(currentNode) && !currentNodeIsContaining && hasFixedPositionAncestor(element, currentNode);
2711
+ if (shouldDropCurrentNode) {
2712
+ // Drop non-containing blocks.
2713
+ result = result.filter(ancestor => ancestor !== currentNode);
2714
+ } else {
2715
+ // Record last containing block for next iteration.
2716
+ currentContainingBlockComputedStyle = computedStyle;
2717
+ }
2718
+ currentNode = getParentNode(currentNode);
2719
+ }
2720
+ cache.set(element, result);
2721
+ return result;
2722
+ }
2723
+
2724
+ // Gets the maximum area that the element is visible in due to any number of
2725
+ // clipping ancestors.
2726
+ function getClippingRect(_ref) {
2727
+ let {
2728
+ element,
2729
+ boundary,
2730
+ rootBoundary,
2731
+ strategy
2732
+ } = _ref;
2733
+ const elementClippingAncestors = boundary === 'clippingAncestors' ? getClippingElementAncestors(element, this._c) : [].concat(boundary);
2734
+ const clippingAncestors = [...elementClippingAncestors, rootBoundary];
2735
+ const firstClippingAncestor = clippingAncestors[0];
2736
+ const clippingRect = clippingAncestors.reduce((accRect, clippingAncestor) => {
2737
+ const rect = getClientRectFromClippingAncestor(element, clippingAncestor, strategy);
2738
+ accRect.top = max(rect.top, accRect.top);
2739
+ accRect.right = min(rect.right, accRect.right);
2740
+ accRect.bottom = min(rect.bottom, accRect.bottom);
2741
+ accRect.left = max(rect.left, accRect.left);
2742
+ return accRect;
2743
+ }, getClientRectFromClippingAncestor(element, firstClippingAncestor, strategy));
2744
+ return {
2745
+ width: clippingRect.right - clippingRect.left,
2746
+ height: clippingRect.bottom - clippingRect.top,
2747
+ x: clippingRect.left,
2748
+ y: clippingRect.top
2749
+ };
2750
+ }
2751
+
2752
+ function getDimensions(element) {
2753
+ return getCssDimensions(element);
2754
+ }
2755
+
2756
+ function getRectRelativeToOffsetParent(element, offsetParent, strategy) {
2757
+ const isOffsetParentAnElement = isHTMLElement(offsetParent);
2758
+ const documentElement = getDocumentElement(offsetParent);
2759
+ const isFixed = strategy === 'fixed';
2760
+ const rect = getBoundingClientRect(element, true, isFixed, offsetParent);
2761
+ let scroll = {
2762
+ scrollLeft: 0,
2763
+ scrollTop: 0
2764
+ };
2765
+ const offsets = createCoords(0);
2766
+ if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {
2767
+ if (getNodeName(offsetParent) !== 'body' || isOverflowElement(documentElement)) {
2768
+ scroll = getNodeScroll(offsetParent);
2769
+ }
2770
+ if (isOffsetParentAnElement) {
2771
+ const offsetRect = getBoundingClientRect(offsetParent, true, isFixed, offsetParent);
2772
+ offsets.x = offsetRect.x + offsetParent.clientLeft;
2773
+ offsets.y = offsetRect.y + offsetParent.clientTop;
2774
+ } else if (documentElement) {
2775
+ offsets.x = getWindowScrollBarX(documentElement);
2776
+ }
2777
+ }
2778
+ return {
2779
+ x: rect.left + scroll.scrollLeft - offsets.x,
2780
+ y: rect.top + scroll.scrollTop - offsets.y,
2781
+ width: rect.width,
2782
+ height: rect.height
2783
+ };
2784
+ }
2785
+
2786
+ function getTrueOffsetParent(element, polyfill) {
2787
+ if (!isHTMLElement(element) || getComputedStyle$1(element).position === 'fixed') {
2788
+ return null;
2789
+ }
2790
+ if (polyfill) {
2791
+ return polyfill(element);
2792
+ }
2793
+ return element.offsetParent;
2794
+ }
2795
+
2796
+ // Gets the closest ancestor positioned element. Handles some edge cases,
2797
+ // such as table ancestors and cross browser bugs.
2798
+ function getOffsetParent(element, polyfill) {
2799
+ const window = getWindow(element);
2800
+ if (!isHTMLElement(element)) {
2801
+ return window;
2802
+ }
2803
+ let offsetParent = getTrueOffsetParent(element, polyfill);
2804
+ while (offsetParent && isTableElement(offsetParent) && getComputedStyle$1(offsetParent).position === 'static') {
2805
+ offsetParent = getTrueOffsetParent(offsetParent, polyfill);
2806
+ }
2807
+ if (offsetParent && (getNodeName(offsetParent) === 'html' || getNodeName(offsetParent) === 'body' && getComputedStyle$1(offsetParent).position === 'static' && !isContainingBlock(offsetParent))) {
2808
+ return window;
2809
+ }
2810
+ return offsetParent || getContainingBlock(element) || window;
2811
+ }
2812
+
2813
+ const getElementRects = async function (_ref) {
2814
+ let {
2815
+ reference,
2816
+ floating,
2817
+ strategy
2818
+ } = _ref;
2819
+ const getOffsetParentFn = this.getOffsetParent || getOffsetParent;
2820
+ const getDimensionsFn = this.getDimensions;
2821
+ return {
2822
+ reference: getRectRelativeToOffsetParent(reference, await getOffsetParentFn(floating), strategy),
2823
+ floating: {
2824
+ x: 0,
2825
+ y: 0,
2826
+ ...(await getDimensionsFn(floating))
2827
+ }
2828
+ };
110
2829
  };
111
2830
 
112
- /**
113
- * All-in-one Button:
114
- * - use "variant" to achieve the desired style
115
- * - include tooltips and/or icons
116
- */
117
- const Button = ({ onClick, label, variant = 'outline', type = 'button', size = 'sm', disabled, extraClassNames, id, testId, stopPropagation = true, tooltip, tooltipOptions, iconStyle = 'text', icon, iconColor, preventBlur = false, }) => {
118
- const baseClasses = 'tw-py-1 tw-px-2.5 tw-rounded-sm focus:tw-ring-0 disabled:tw-pointer-events-none';
119
- const baseClassesByVariant = {
120
- 'outline': 'tw-border-solid tw-border',
121
- 'theme': 'disabled:tw-opacity-50',
122
- 'danger': 'tw-bg-sq-danger-color hover:tw-bg-sq-danger-color-hover disabled:tw-opacity-50',
123
- 'theme-light': 'disabled:tw-opacity-50',
124
- 'no-border': '',
125
- 'warning': 'tw-bg-sq-warning-color',
126
- };
127
- const textClassesByVariantLightTheme = {
128
- 'outline': 'tw-text-sq-text-color',
129
- 'theme': 'tw-text-white',
130
- 'theme-light': 'tw-text-white',
131
- 'danger': 'tw-text-white',
132
- 'no-border': 'tw-text-sq-text-color',
133
- 'warning': 'tw-text-white',
134
- };
135
- const textClassesByVariantDarkTheme = {
136
- 'outline': 'dark:tw-text-sq-dark-text',
137
- 'theme': 'dark:tw-text-white',
138
- 'theme-light': 'dark:tw-text-white',
139
- 'danger': 'dark:tw-text-white',
140
- 'no-border': 'dark:tw-text-sq-dark-text',
141
- 'warning': 'dark:tw-text-white',
142
- };
143
- const classesByVariantLightTheme = {
144
- 'outline': 'tw-border-sq-disabled-gray hover:tw-bg-sq-light-gray' +
145
- ' focus:tw-bg-sq-dark-gray active:tw-bg-sq-dark-gray focus:tw-border-sq-color-dark active:tw-border-sq-color-dark',
146
- 'theme': 'tw-bg-sq-color-dark hover:tw-bg-sq-color-highlight',
147
- 'danger': '',
148
- 'theme-light': 'tw-bg-sq-icon hover:tw-bg-sq-link',
149
- 'no-border': '',
150
- 'warning': 'tw-bg-sq-warning-color',
151
- };
152
- const classesByVariantDarkTheme = {
153
- 'outline': 'dark:tw-border-sq-dark-disabled-gray dark:hover:tw-bg-sq-highlight-color-dark' +
154
- ' dark:focus:tw-bg-sq-dark-gray dark:active:tw-bg-sq-dark-gray dark:focus:tw-border-sq-color-dark' +
155
- ' dark:active:tw-border-sq-color-dark',
156
- 'theme': 'dark:tw-bg-sq-color-dark dark:hover:tw-bg-sq-color-highlight',
157
- 'danger': '',
158
- 'theme-light': 'dark:tw-bg-sq-icon-dark dark:hover:tw-bg-sq-link-dark',
159
- 'no-border': '',
160
- 'warning': '',
161
- };
162
- const sizeClasses = {
163
- sm: 'tw-text-sm',
164
- lg: 'tw-text-xl',
165
- };
166
- const appliedClasses = `${baseClasses} ${baseClassesByVariant[variant]} ${sizeClasses[size]} ${classesByVariantLightTheme[variant]} ${classesByVariantDarkTheme[variant]} ${textClassesByVariantLightTheme[variant]} ${textClassesByVariantDarkTheme[variant]} ${extraClassNames}`;
167
- const button = (React__default.createElement("button", { id: id, disabled: disabled, "data-testid": testId, type: type === 'link' || (type === 'submit' && browserIsFirefox) ? 'button' : type, onClick: (e) => {
168
- stopPropagation && e.stopPropagation();
169
- onClick && onClick();
170
- }, onMouseDown: (e) => {
171
- if (preventBlur) {
172
- e.preventDefault();
173
- }
174
- }, className: appliedClasses },
175
- icon && (React__default.createElement(Icon, { icon: icon, type: iconStyle, color: iconColor, extraClassNames: label ? `tw-mr-1 ${textClassesByVariantLightTheme[variant]} ${textClassesByVariantDarkTheme[variant]}` : '', testId: `${id}_spinner` })),
176
- label));
177
- return tooltip ? (React__default.createElement(Tooltip, { text: tooltip, ...tooltipOptions }, button)) : (button);
2831
+ function isRTL(element) {
2832
+ return getComputedStyle$1(element).direction === 'rtl';
2833
+ }
2834
+
2835
+ const platform = {
2836
+ convertOffsetParentRelativeRectToViewportRelativeRect,
2837
+ getDocumentElement,
2838
+ getClippingRect,
2839
+ getOffsetParent,
2840
+ getElementRects,
2841
+ getClientRects,
2842
+ getDimensions,
2843
+ getScale,
2844
+ isElement,
2845
+ isRTL
2846
+ };
2847
+
2848
+ // https://samthor.au/2021/observing-dom/
2849
+ function observeMove(element, onMove) {
2850
+ let io = null;
2851
+ let timeoutId;
2852
+ const root = getDocumentElement(element);
2853
+ function cleanup() {
2854
+ clearTimeout(timeoutId);
2855
+ io && io.disconnect();
2856
+ io = null;
2857
+ }
2858
+ function refresh(skip, threshold) {
2859
+ if (skip === void 0) {
2860
+ skip = false;
2861
+ }
2862
+ if (threshold === void 0) {
2863
+ threshold = 1;
2864
+ }
2865
+ cleanup();
2866
+ const {
2867
+ left,
2868
+ top,
2869
+ width,
2870
+ height
2871
+ } = element.getBoundingClientRect();
2872
+ if (!skip) {
2873
+ onMove();
2874
+ }
2875
+ if (!width || !height) {
2876
+ return;
2877
+ }
2878
+ const insetTop = floor(top);
2879
+ const insetRight = floor(root.clientWidth - (left + width));
2880
+ const insetBottom = floor(root.clientHeight - (top + height));
2881
+ const insetLeft = floor(left);
2882
+ const rootMargin = -insetTop + "px " + -insetRight + "px " + -insetBottom + "px " + -insetLeft + "px";
2883
+ const options = {
2884
+ rootMargin,
2885
+ threshold: max(0, min(1, threshold)) || 1
2886
+ };
2887
+ let isFirstUpdate = true;
2888
+ function handleObserve(entries) {
2889
+ const ratio = entries[0].intersectionRatio;
2890
+ if (ratio !== threshold) {
2891
+ if (!isFirstUpdate) {
2892
+ return refresh();
2893
+ }
2894
+ if (!ratio) {
2895
+ timeoutId = setTimeout(() => {
2896
+ refresh(false, 1e-7);
2897
+ }, 100);
2898
+ } else {
2899
+ refresh(false, ratio);
2900
+ }
2901
+ }
2902
+ isFirstUpdate = false;
2903
+ }
2904
+
2905
+ // Older browsers don't support a `document` as the root and will throw an
2906
+ // error.
2907
+ try {
2908
+ io = new IntersectionObserver(handleObserve, {
2909
+ ...options,
2910
+ // Handle <iframe>s
2911
+ root: root.ownerDocument
2912
+ });
2913
+ } catch (e) {
2914
+ io = new IntersectionObserver(handleObserve, options);
2915
+ }
2916
+ io.observe(element);
2917
+ }
2918
+ refresh(true);
2919
+ return cleanup;
2920
+ }
2921
+
2922
+ /**
2923
+ * Automatically updates the position of the floating element when necessary.
2924
+ * Should only be called when the floating element is mounted on the DOM or
2925
+ * visible on the screen.
2926
+ * @returns cleanup function that should be invoked when the floating element is
2927
+ * removed from the DOM or hidden from the screen.
2928
+ * @see https://floating-ui.com/docs/autoUpdate
2929
+ */
2930
+ function autoUpdate(reference, floating, update, options) {
2931
+ if (options === void 0) {
2932
+ options = {};
2933
+ }
2934
+ const {
2935
+ ancestorScroll = true,
2936
+ ancestorResize = true,
2937
+ elementResize = typeof ResizeObserver === 'function',
2938
+ layoutShift = typeof IntersectionObserver === 'function',
2939
+ animationFrame = false
2940
+ } = options;
2941
+ const referenceEl = unwrapElement(reference);
2942
+ const ancestors = ancestorScroll || ancestorResize ? [...(referenceEl ? getOverflowAncestors(referenceEl) : []), ...getOverflowAncestors(floating)] : [];
2943
+ ancestors.forEach(ancestor => {
2944
+ ancestorScroll && ancestor.addEventListener('scroll', update, {
2945
+ passive: true
2946
+ });
2947
+ ancestorResize && ancestor.addEventListener('resize', update);
2948
+ });
2949
+ const cleanupIo = referenceEl && layoutShift ? observeMove(referenceEl, update) : null;
2950
+ let reobserveFrame = -1;
2951
+ let resizeObserver = null;
2952
+ if (elementResize) {
2953
+ resizeObserver = new ResizeObserver(_ref => {
2954
+ let [firstEntry] = _ref;
2955
+ if (firstEntry && firstEntry.target === referenceEl && resizeObserver) {
2956
+ // Prevent update loops when using the `size` middleware.
2957
+ // https://github.com/floating-ui/floating-ui/issues/1740
2958
+ resizeObserver.unobserve(floating);
2959
+ cancelAnimationFrame(reobserveFrame);
2960
+ reobserveFrame = requestAnimationFrame(() => {
2961
+ resizeObserver && resizeObserver.observe(floating);
2962
+ });
2963
+ }
2964
+ update();
2965
+ });
2966
+ if (referenceEl && !animationFrame) {
2967
+ resizeObserver.observe(referenceEl);
2968
+ }
2969
+ resizeObserver.observe(floating);
2970
+ }
2971
+ let frameId;
2972
+ let prevRefRect = animationFrame ? getBoundingClientRect(reference) : null;
2973
+ if (animationFrame) {
2974
+ frameLoop();
2975
+ }
2976
+ function frameLoop() {
2977
+ const nextRefRect = getBoundingClientRect(reference);
2978
+ if (prevRefRect && (nextRefRect.x !== prevRefRect.x || nextRefRect.y !== prevRefRect.y || nextRefRect.width !== prevRefRect.width || nextRefRect.height !== prevRefRect.height)) {
2979
+ update();
2980
+ }
2981
+ prevRefRect = nextRefRect;
2982
+ frameId = requestAnimationFrame(frameLoop);
2983
+ }
2984
+ update();
2985
+ return () => {
2986
+ ancestors.forEach(ancestor => {
2987
+ ancestorScroll && ancestor.removeEventListener('scroll', update);
2988
+ ancestorResize && ancestor.removeEventListener('resize', update);
2989
+ });
2990
+ cleanupIo && cleanupIo();
2991
+ resizeObserver && resizeObserver.disconnect();
2992
+ resizeObserver = null;
2993
+ if (animationFrame) {
2994
+ cancelAnimationFrame(frameId);
2995
+ }
2996
+ };
2997
+ }
2998
+
2999
+ /**
3000
+ * Computes the `x` and `y` coordinates that will place the floating element
3001
+ * next to a reference element when it is given a certain CSS positioning
3002
+ * strategy.
3003
+ */
3004
+ const computePosition = (reference, floating, options) => {
3005
+ // This caches the expensive `getClippingElementAncestors` function so that
3006
+ // multiple lifecycle resets re-use the same result. It only lives for a
3007
+ // single call. If other functions become expensive, we can add them as well.
3008
+ const cache = new Map();
3009
+ const mergedOptions = {
3010
+ platform,
3011
+ ...options
3012
+ };
3013
+ const platformWithCache = {
3014
+ ...mergedOptions.platform,
3015
+ _c: cache
3016
+ };
3017
+ return computePosition$1(reference, floating, {
3018
+ ...mergedOptions,
3019
+ platform: platformWithCache
3020
+ });
178
3021
  };
179
3022
 
180
- const errorClasses$2 = 'tw-border-sq-danger-color';
181
- const borderColorClasses$2 = [
182
- 'tw-border-sq-disabled-gray',
183
- 'dark:tw-border-sq-dark-disabled-gray',
184
- 'dark:focus:tw-border-sq-color-dark-dark',
185
- 'dark:active:tw-border-sq-color-dark-dark',
186
- 'focus:tw-border-sq-color-dark',
187
- 'active:tw-border-sq-color-dark',
188
- ].join(' ');
189
- const baseClasses$3 = 'tw-h-inputs tw-leading-normal tw-outline-none tw-py-1 tw-px-3' +
190
- ' disabled:tw-pointer-events-none' +
191
- ' disabled:tw-cursor-not-allowed tw-p-1 tw-border-solid tw-border tw-placeholder-gray-400' +
192
- ' dark:tw-placeholder-sq-dark-text-lighter specTextField';
193
- const darkTheme$1 = 'dark:tw-bg-sq-dark-background dark:tw-text-sq-dark-text';
194
- const lightTheme$1 = 'tw-text-sq-text-color';
195
- const sizeClasses = {
196
- sm: 'tw-text-sm',
197
- lg: 'tw-text-xl',
198
- };
3023
+ const noop$1 = () => { };
3024
+
199
3025
  /**
200
- * Textfield.
3026
+ * A setInterval hook that calls a callback after a interval duration
3027
+ * when a condition is true
3028
+ *
3029
+ * @param callback The callback to be invoked after interval
3030
+ * @param intervalDurationMs Amount of time in ms after which to invoke
3031
+ * @param when The condition which when true, sets the interval
3032
+ * @param startImmediate If the callback should be invoked immediately
3033
+ * @see https://rooks.vercel.app/docs/useIntervalWhen
201
3034
  */
202
- const TextField = React__default.forwardRef((props, ref) => {
203
- const { readonly = false, onChange, onKeyUp, id, name, size = 'sm', value, placeholder, extraClassNames, testId, type = 'text', inputGroup, step, showError, } = props;
204
- const internalRef = useRef(null);
205
- const [cursor, setCursor] = useState(null);
206
- const setAllRefs = (receivedRef) => {
207
- if (ref)
208
- ref.current = receivedRef;
209
- internalRef.current = receivedRef;
210
- };
3035
+ function useIntervalWhen(callback, intervalDurationMs = 0, when = true, startImmediate = false) {
3036
+ const savedRefCallback = useRef();
211
3037
  useEffect(() => {
212
- const input = internalRef.current;
213
- if (input && type !== 'number')
214
- input.setSelectionRange(cursor, cursor);
215
- }, [ref, cursor, value]);
216
- const handleChange = (e) => {
217
- setCursor(e.target.selectionStart);
218
- onChange && onChange(e);
219
- };
3038
+ savedRefCallback.current = callback;
3039
+ });
220
3040
  useEffect(() => {
221
- /**
222
- * we need to change the value only if it's different since the internal state of "input" will change it anyway
223
- * this will only be the case when the value has been changed externally via store (undo / redo)
224
- */
225
- if (value !== null && value !== undefined && value !== internalRef.current?.value && internalRef.current) {
226
- // we need to use this method because using the value props directly will switch the input to a "controlled"
227
- // component
228
- internalRef.current.value = `${value}`;
3041
+ if (when) {
3042
+ function internalCallback() {
3043
+ var _a;
3044
+ (_a = savedRefCallback.current) === null || _a === void 0 ? void 0 : _a.call(savedRefCallback);
3045
+ }
3046
+ if (startImmediate) {
3047
+ internalCallback();
3048
+ }
3049
+ const interval = window.setInterval(internalCallback, intervalDurationMs);
3050
+ return () => {
3051
+ window.clearInterval(interval);
3052
+ };
229
3053
  }
230
- }, [value]);
231
- let borderRadius = 'tw-rounded-sm';
232
- if (inputGroup === 'left') {
233
- borderRadius = 'tw-rounded-l-sm tw-border-r-0 focus:tw-border-r' + ' active:tw-border-r';
234
- }
235
- else if (inputGroup === 'right') {
236
- borderRadius = 'tw-rounded-r-sm tw-border-l-0 focus:tw-border-l active:tw-border-l';
3054
+ return noop$1;
3055
+ }, [when, intervalDurationMs, startImmediate]);
3056
+ }
3057
+
3058
+ const getArrowStyle = (position, x, arrowWidth, tooltipHeight, tooltipWidth) => {
3059
+ switch (position) {
3060
+ case 'bottom':
3061
+ return {
3062
+ left: `${x}px`,
3063
+ top: `${-arrowWidth}px`,
3064
+ };
3065
+ case 'left':
3066
+ return {
3067
+ left: `${tooltipWidth - arrowWidth}px`,
3068
+ top: `${tooltipHeight / 2 - arrowWidth}px`,
3069
+ };
3070
+ case 'right':
3071
+ return {
3072
+ left: `${-arrowWidth}px`,
3073
+ top: `${tooltipHeight / 2 - arrowWidth}px`,
3074
+ };
3075
+ default: // 'top':
3076
+ return {
3077
+ left: `${x}px`,
3078
+ top: `${tooltipHeight - 10 + arrowWidth}px`,
3079
+ };
237
3080
  }
238
- const appliedClasses = `${baseClasses$3} ${sizeClasses[size]} ${extraClassNames} ${lightTheme$1} ${darkTheme$1} ${borderRadius} ${showError ? errorClasses$2 : borderColorClasses$2} `;
239
- return (React__default.createElement("input", { ref: setAllRefs, "data-testid": testId, name: name, id: id, type: type, value: value, className: appliedClasses, placeholder: placeholder, disabled: readonly, autoComplete: "none", onChange: handleChange, onKeyUp: onKeyUp, step: step }));
240
- });
241
-
242
- const alignment = 'tw-flex tw-items-center';
243
- const labelClasses = 'tw-ml-1.5 tw-text-sm';
244
- const baseClasses$2 = 'tw-border-1 tw-h-3.5 tw-w-3.5 focus:tw-ring-0 focus:tw-ring-offset-0 tw-outline-none focus:tw-outline-none' +
245
- ' dark:tw-bg-sq-dark-background dark:tw-border-sq-dark-text dark:checked:tw-bg-sq-dark-text' +
246
- ' checked:tw-text-sq-text-color' +
247
- ' disabled:tw-text-sq-fairly-dark-gray';
248
- const checkboxClasses = `tw-form-checkbox tw-rounded ${baseClasses$2}`;
249
- const radioClasses = `tw-form-radio ${baseClasses$2}`;
250
- /**
251
- * Checkbox and Radio Box Component.
252
- */
253
- const Checkbox = (props) => {
254
- const { type = 'checkbox', value, disabled = false, label, onChange, onClick, onKeyDown, checked, defaultChecked, id, name, extraClassNames, extraLabelClassNames, testId, } = props;
255
- const assignedId = id ?? 'checkbox_' + Math.random();
256
- return (React__default.createElement("span", { className: `${alignment} ${extraClassNames}` },
257
- React__default.createElement("input", { value: value, type: type, "data-testid": testId, name: name, id: assignedId, checked: checked, defaultChecked: defaultChecked, className: `${type === 'checkbox' ? checkboxClasses : radioClasses} ${disabled ? 'tw-cursor-not-allowed' : 'tw-cursor-pointer'}`, disabled: disabled, onClick: onClick, onChange: onChange, onKeyDown: onKeyDown }),
258
- React__default.createElement("label", { htmlFor: assignedId, className: `${labelClasses} ${extraLabelClassNames} ${disabled
259
- ? 'tw-cursor-not-allowed dark:tw-text-sq-fairly-dark-gray tw-text-sq-fairly-dark-gray'
260
- : 'tw-cursor-pointer tw-text-sq-text-color dark:tw-text-sq-dark-text'}` }, label)));
261
- };
262
-
263
- const baseClasses$1 = 'tw-leading-normal tw-outline-none tw-py-1 tw-px-3 tw-rounded-sm' +
264
- ' disabled:tw-cursor-not-allowed tw-p-1 tw-border-solid tw-border tw-text-sm';
265
- const darkTheme = 'dark:tw-bg-sq-dark-background dark:tw-text-sq-dark-text ' + 'dark:tw-placeholder-sq-dark-text-lighter';
266
- const lightTheme = 'tw-text-sq-text-color tw-placeholder-gray-400';
267
- const errorClasses$1 = 'tw-border-sq-danger-color';
268
- const borderColorClasses$1 = [
269
- 'tw-border-sq-disabled-gray',
270
- 'dark:tw-border-sq-dark-disabled-gray',
271
- 'dark:focus:tw-border-sq-color-dark-dark',
272
- 'dark:active:tw-border-sq-color-dark-dark',
273
- 'focus:tw-border-sq-color-dark',
274
- 'active:tw-border-sq-color-dark',
275
- ].join(' ');
3081
+ };
3082
+ const HTMLTip = ({ text }) => {
3083
+ return React__default.createElement('div', {
3084
+ dangerouslySetInnerHTML: { __html: DOMPurify.sanitize(text) },
3085
+ });
3086
+ };
276
3087
  /**
277
- * TextArea.
3088
+ * QTip
3089
+ *
3090
+ * QTip is a Singleton Tooltip component that guarantees high-performance and reduces component wrappers!
3091
+ *
3092
+ * QTip is used by all qomponents that support the display of tooltips.
3093
+ * If you want to add a Tooltip to your application you can do so by adding the following html data-attributes:
3094
+ *
3095
+ * 'data-qtip-text': the tooltip text to display; this can also be a string containing valid HTML
3096
+ * 'data-qtip-placement': one of TooltipPosition (top, bottom, right, or left)
3097
+ * 'data-qtip-is-html': set this to true if you provided a text that contains HTML,
3098
+ * 'data-qtip-delay': this can be used to delay the showing of the tooltip. this should be a number representing
3099
+ * the # of milliseconds you want to delay the tooltip for.
3100
+ * 'data-qtip-testid': use this attribute to provide a value for a data-testid of your tooltip; this is useful
3101
+ * for tests
3102
+ *
3103
+ * In order for QTip to be able to display Tooltips you must add the QTip component to your top-most component
3104
+ * (often that's App or Application) - simply add:
3105
+ *
3106
+ * <QTip />
3107
+ *
3108
+ * and enjoy beautiful & performant tooltips!
278
3109
  */
279
- const TextArea = ({ readonly = false, onChange, onKeyUp, id, name, rows = 3, cols = undefined, value, placeholder, extraClassNames, testId, autofocus = false, showError, }) => {
280
- const appliedClasses = `${baseClasses$1} ${extraClassNames} ${lightTheme} ${darkTheme} ${showError ? errorClasses$1 : borderColorClasses$1}`;
281
- return (React__default.createElement("textarea", { "data-testid": testId, name: name, id: id, value: value, className: appliedClasses, placeholder: placeholder, disabled: readonly, onChange: onChange, onKeyUp: onKeyUp, rows: rows, cols: cols, autoFocus: autofocus }));
3110
+ const QTip = () => {
3111
+ const tooltipRef = useRef(null);
3112
+ const tooltipTarget = useRef(null);
3113
+ const tooltipArrowRef = useRef(null);
3114
+ const [tooltipText, setTooltipText] = useState('');
3115
+ const [tooltipTargetOriginalPosition, setTooltipTargetOriginalPosition] = useState(null);
3116
+ const [show, setShow] = useState(false);
3117
+ const [html, setHtml] = useState(false);
3118
+ const [tooltipTestId, setTooltipTestId] = useState('');
3119
+ const [overTooltip, setOverTooltip] = useState(false);
3120
+ // Check every 300ms if the tooltip target position has changed and hide the tooltip if this happens.
3121
+ useIntervalWhen(() => {
3122
+ const currentPosition = tooltipTarget?.current?.getBoundingClientRect();
3123
+ if (overTooltip) {
3124
+ return;
3125
+ }
3126
+ if (tooltipTargetOriginalPosition?.y !== currentPosition?.y ||
3127
+ tooltipTargetOriginalPosition?.x !== currentPosition?.x) {
3128
+ setShow(false);
3129
+ }
3130
+ }, 300, show);
3131
+ useEffect(() => {
3132
+ document.body.addEventListener('mousemove', onMouseMove);
3133
+ return () => {
3134
+ document.removeEventListener('mousemove', onMouseMove);
3135
+ };
3136
+ }, []);
3137
+ const ttTimeout = useRef();
3138
+ const onMouseMove = (e) => {
3139
+ clearTimeout(ttTimeout.current);
3140
+ if (!(e.target instanceof HTMLElement)) {
3141
+ return;
3142
+ }
3143
+ tooltipTarget.current = e.target;
3144
+ let dataset = e.target?.dataset;
3145
+ let text = dataset?.qtipText;
3146
+ // Buttons support React.Nodes as children, the tooltip however is applied to the actual button component.
3147
+ // we only check one level up - alternatively the tooltip can also be provided on the React.Node
3148
+ if (!text || text === '') {
3149
+ dataset = e.target?.parentElement?.dataset;
3150
+ text = dataset?.qtipText;
3151
+ tooltipTarget.current = e.target?.parentElement;
3152
+ }
3153
+ if (text) {
3154
+ const delay = parseInt(dataset?.qtipDelay ?? '0');
3155
+ ttTimeout.current = setTimeout(() => makeTooltip(text, dataset?.qtipPlacement, dataset?.qtipIsHtml === 'true', dataset?.qtipTestid, delay), delay);
3156
+ }
3157
+ };
3158
+ const makeTooltip = (tooltipText, position = 'top', isHtml, dataTestId, delay) => {
3159
+ if (tooltipText && tooltipTarget.current) {
3160
+ setHtml(isHtml);
3161
+ setTooltipText(tooltipText);
3162
+ setTooltipTestId(dataTestId);
3163
+ setTooltipTargetOriginalPosition(tooltipTarget.current.getBoundingClientRect());
3164
+ const positionTooltip = () => {
3165
+ if (tooltipRef.current && tooltipTarget.current) {
3166
+ computePosition(tooltipTarget.current, tooltipRef.current, {
3167
+ placement: position,
3168
+ middleware: [offset(10), arrow({ element: tooltipArrowRef.current })],
3169
+ }).then(({ x, y, middlewareData }) => {
3170
+ Object.assign(tooltipRef.current?.style, {
3171
+ left: `${x}px`,
3172
+ top: `${y}px`,
3173
+ });
3174
+ if (middlewareData.arrow) {
3175
+ const { x, y } = middlewareData.arrow;
3176
+ const arrowWidth = tooltipArrowRef.current?.offsetHeight / 2;
3177
+ const tooltipHeight = tooltipRef.current?.offsetHeight;
3178
+ const tooltipWidth = tooltipRef.current?.offsetWidth;
3179
+ const style = getArrowStyle(position, x || y, arrowWidth, tooltipHeight, tooltipWidth);
3180
+ Object.assign(tooltipArrowRef.current.style, style);
3181
+ }
3182
+ setShow(true);
3183
+ });
3184
+ }
3185
+ };
3186
+ delay > 0
3187
+ ? requestAnimationFrame(() => {
3188
+ positionTooltip();
3189
+ })
3190
+ : positionTooltip();
3191
+ }
3192
+ };
3193
+ return (React__default.createElement(React__default.Fragment, null,
3194
+ React__default.createElement("div", { onMouseEnter: () => setOverTooltip(true), onMouseLeave: () => setOverTooltip(false), "data-testid": tooltipTestId, ref: tooltipRef, className: 'tw-absolute tw-rounded tw-bg-black tw-p-2 tw-text-xs tw-text-white tw-z-[9999] fade-in ' +
3195
+ (show ? 'tw-visible' : 'tw-invisible tw-pointer-events-none') },
3196
+ html ? React__default.createElement(HTMLTip, { text: tooltipText }) : tooltipText,
3197
+ React__default.createElement("div", { className: "tw-absolute tw-w-[10px] tw-h-[10px] tw-rotate-45 tw-bg-black", ref: tooltipArrowRef }))));
282
3198
  };
283
3199
 
284
3200
  function _typeof(obj) {
@@ -3256,10 +6172,6 @@ function _taggedTemplateLiteral(strings, raw) {
3256
6172
  }));
3257
6173
  }
3258
6174
 
3259
- function l$1(t){return {...t,top:t.y,left:t.x,right:t.x+t.width,bottom:t.y+t.height}}const g$1=["top","right","bottom","left"];g$1.reduce(((t,e)=>t.concat(e,e+"-start",e+"-end")),[]);
3260
-
3261
- function n(t){var e;return (null==(e=t.ownerDocument)?void 0:e.defaultView)||window}function o(t){return n(t).getComputedStyle(t)}function i$1(t){return t instanceof n(t).Node}function r(t){return i$1(t)?(t.nodeName||"").toLowerCase():""}let l;function c(){if(l)return l;const t=navigator.userAgentData;return t&&Array.isArray(t.brands)?(l=t.brands.map((t=>t.brand+"/"+t.version)).join(" "),l):navigator.userAgent}function s(t){return t instanceof n(t).HTMLElement}function f(t){return t instanceof n(t).Element}function u(t){if("undefined"==typeof ShadowRoot)return !1;return t instanceof n(t).ShadowRoot||t instanceof ShadowRoot}function a(t){const{overflow:e,overflowX:n,overflowY:i,display:r}=o(t);return /auto|scroll|overlay|hidden|clip/.test(e+i+n)&&!["inline","contents"].includes(r)}function p(){return /^((?!chrome|android).)*safari/i.test(c())}function g(t){return ["html","body","#document"].includes(r(t))}const x=Math.round;function w$1(t){const e=o(t);let n=parseFloat(e.width)||0,i=parseFloat(e.height)||0;const r=s(t),l=r?t.offsetWidth:n,c=r?t.offsetHeight:i,f=x(n)!==l||x(i)!==c;return f&&(n=l,i=c),{width:n,height:i,fallback:f}}function v(t){return f(t)?t:t.contextElement}const b={x:1,y:1};function L(t){const e=v(t);if(!s(e))return b;const n=e.getBoundingClientRect(),{width:o,height:i,fallback:r}=w$1(e);let l=(r?x(n.width):n.width)/o,c=(r?x(n.height):n.height)/i;return l&&Number.isFinite(l)||(l=1),c&&Number.isFinite(c)||(c=1),{x:l,y:c}}function E(e,o,i,r){var l,c;void 0===o&&(o=!1),void 0===i&&(i=!1);const s=e.getBoundingClientRect(),u=v(e);let a=b;o&&(r?f(r)&&(a=L(r)):a=L(e));const d=u?n(u):window,h=p()&&i;let g=(s.left+(h&&(null==(l=d.visualViewport)?void 0:l.offsetLeft)||0))/a.x,m=(s.top+(h&&(null==(c=d.visualViewport)?void 0:c.offsetTop)||0))/a.y,y=s.width/a.x,x=s.height/a.y;if(u){const t=n(u),e=r&&f(r)?n(r):r;let o=t.frameElement;for(;o&&r&&e!==t;){const t=L(o),e=o.getBoundingClientRect(),i=getComputedStyle(o);e.x+=(o.clientLeft+parseFloat(i.paddingLeft))*t.x,e.y+=(o.clientTop+parseFloat(i.paddingTop))*t.y,g*=t.x,m*=t.y,y*=t.x,x*=t.y,g+=e.x,m+=e.y,o=n(o).frameElement;}}return l$1({width:y,height:x,x:g,y:m})}function T(t){return ((i$1(t)?t.ownerDocument:t.document)||window.document).documentElement}function F(t){if("html"===r(t))return t;const e=t.assignedSlot||t.parentNode||u(t)&&t.host||T(t);return u(e)?e.host:e}function S(t){const e=F(t);return g(e)?e.ownerDocument.body:s(e)&&a(e)?e:S(e)}function W(t,e){var o;void 0===e&&(e=[]);const i=S(t),r=i===(null==(o=t.ownerDocument)?void 0:o.body),l=n(i);return r?e.concat(l,l.visualViewport||[],a(i)?i:[]):e.concat(i,W(i))}function z(t,e,n,o){void 0===o&&(o={});const{ancestorScroll:i=!0,ancestorResize:r=!0,elementResize:l=!0,animationFrame:c=!1}=o,s=i||r?[...f(t)?W(t):t.contextElement?W(t.contextElement):[],...W(e)]:[];s.forEach((t=>{const e=!f(t)&&t.toString().includes("V");!i||c&&!e||t.addEventListener("scroll",n,{passive:!0}),r&&t.addEventListener("resize",n);}));let u,a=null;l&&(a=new ResizeObserver((()=>{n();})),f(t)&&!c&&a.observe(t),f(t)||!t.contextElement||c||a.observe(t.contextElement),a.observe(e));let d=c?E(t):null;return c&&function e(){const o=E(t);!d||o.x===d.x&&o.y===d.y&&o.width===d.width&&o.height===d.height||n();d=o,u=requestAnimationFrame(e);}(),n(),()=>{var t;s.forEach((t=>{i&&t.removeEventListener("scroll",n),r&&t.removeEventListener("resize",n);})),null==(t=a)||t.disconnect(),a=null,c&&cancelAnimationFrame(u);}}
3262
-
3263
6175
  var index = useLayoutEffect ;
3264
6176
 
3265
6177
  var _excluded$3 = ["className", "clearValue", "cx", "getStyles", "getClassNames", "getValue", "hasValue", "isMulti", "isRtl", "options", "selectOption", "selectProps", "setValue", "theme"];
@@ -3929,7 +6841,7 @@ var MenuPortal = function MenuPortal(props) {
3929
6841
  cleanupRef.current = null;
3930
6842
  }
3931
6843
  if (controlElement && menuPortalRef.current) {
3932
- cleanupRef.current = z(controlElement, menuPortalRef.current, updateComputedPosition, {
6844
+ cleanupRef.current = autoUpdate(controlElement, menuPortalRef.current, updateComputedPosition, {
3933
6845
  elementResize: 'ResizeObserver' in window
3934
6846
  });
3935
6847
  }
@@ -7475,5 +10387,5 @@ const Select = ({ options, value, placeholder = 'select', noOptionsMessage = 'no
7475
10387
  return creatable ? React__default.createElement(CreatableSelect$1, { ...props }) : React__default.createElement(StateManagedSelect$1, { ...props });
7476
10388
  };
7477
10389
 
7478
- export { Button, Checkbox, Icon, Select, TextArea, TextField, Tooltip };
10390
+ export { Button, Checkbox, Icon, QTip, Select, TextArea, TextField, Tooltip };
7479
10391
  //# sourceMappingURL=index.esm.js.map