@eightshift/ui-components 3.0.1 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. package/package.json +101 -101
  2. package/dist/Button-BPLceDeW.js +0 -185
  3. package/dist/Collection-CZxddMZS.js +0 -2332
  4. package/dist/Color-MV5kBVXr.js +0 -2452
  5. package/dist/ColorSwatch-BqQfVu4L.js +0 -64
  6. package/dist/ComboBox-_RfyhwZw.js +0 -1906
  7. package/dist/Dialog-8tYeQ9n4.js +0 -2300
  8. package/dist/FieldError-52GVSGgC.js +0 -42
  9. package/dist/FocusScope-Cri5BFRz.js +0 -831
  10. package/dist/Form-Cq3fu75_.js +0 -5
  11. package/dist/Group-_emcIVxI.js +0 -48
  12. package/dist/Heading-B2153VXe.js +0 -16
  13. package/dist/Hidden-rE6uR-lr.js +0 -41
  14. package/dist/Input-BxpFEIXV.js +0 -133
  15. package/dist/Label-icmbmNdI.js +0 -17
  16. package/dist/List-CZMUbkFU.js +0 -593
  17. package/dist/ListBox-Ca6hiCqz.js +0 -581
  18. package/dist/NumberFormatter-DA8u1Ot7.js +0 -140
  19. package/dist/OverlayArrow-CYXQSlEU.js +0 -629
  20. package/dist/RSPContexts-2lR5GG9p.js +0 -14
  21. package/dist/Select-aab027f3.esm-PDJCDE95.js +0 -2469
  22. package/dist/Separator-4IIDRlV_.js +0 -322
  23. package/dist/Slider-rz2XRMGm.js +0 -853
  24. package/dist/Text-DVSAPY-K.js +0 -16
  25. package/dist/VisuallyHidden-f9zX67a_.js +0 -48
  26. package/dist/_commonjsHelpers-CUmg6egw.js +0 -6
  27. package/dist/assets/index.css +0 -37
  28. package/dist/assets/style-admin.css +0 -5255
  29. package/dist/assets/style-editor.css +0 -5255
  30. package/dist/assets/style.css +0 -5261
  31. package/dist/assets/wp-font-enhancements.css +0 -8
  32. package/dist/assets/wp-ui-enhancements.css +0 -299
  33. package/dist/components/animated-visibility/animated-visibility.js +0 -105
  34. package/dist/components/base-control/base-control.js +0 -86
  35. package/dist/components/breakpoint-preview/breakpoint-preview.js +0 -161
  36. package/dist/components/button/button.js +0 -387
  37. package/dist/components/checkbox/checkbox.js +0 -320
  38. package/dist/components/color-pickers/color-picker.js +0 -272
  39. package/dist/components/color-pickers/color-swatch.js +0 -58
  40. package/dist/components/color-pickers/gradient-editor.js +0 -534
  41. package/dist/components/color-pickers/solid-color-picker.js +0 -1567
  42. package/dist/components/component-toggle/component-toggle.js +0 -158
  43. package/dist/components/container-panel/container-panel.js +0 -131
  44. package/dist/components/draggable/draggable-context.js +0 -5
  45. package/dist/components/draggable/draggable-handle.js +0 -46
  46. package/dist/components/draggable/draggable.js +0 -6207
  47. package/dist/components/draggable-list/draggable-list-context.js +0 -5
  48. package/dist/components/draggable-list/draggable-list-item.js +0 -77
  49. package/dist/components/draggable-list/draggable-list.js +0 -151
  50. package/dist/components/expandable/expandable.js +0 -342
  51. package/dist/components/index.js +0 -137
  52. package/dist/components/input-field/input-field.js +0 -231
  53. package/dist/components/item-collection/item-collection.js +0 -59
  54. package/dist/components/layout/hstack.js +0 -30
  55. package/dist/components/layout/vstack.js +0 -30
  56. package/dist/components/link-input/link-input.js +0 -293
  57. package/dist/components/matrix-align/matrix-align.js +0 -134
  58. package/dist/components/menu/menu.js +0 -285
  59. package/dist/components/modal/modal.js +0 -305
  60. package/dist/components/notice/notice.js +0 -123
  61. package/dist/components/number-picker/number-picker.js +0 -292
  62. package/dist/components/option-select/option-select.js +0 -264
  63. package/dist/components/options-panel/options-panel.js +0 -158
  64. package/dist/components/placeholders/file-placeholder.js +0 -42
  65. package/dist/components/placeholders/image-placeholder.js +0 -88
  66. package/dist/components/placeholders/media-placeholder.js +0 -63
  67. package/dist/components/popover/popover.js +0 -207
  68. package/dist/components/radio/radio.js +0 -579
  69. package/dist/components/repeater/repeater-context.js +0 -5
  70. package/dist/components/repeater/repeater-item.js +0 -119
  71. package/dist/components/repeater/repeater.js +0 -280
  72. package/dist/components/responsive/mini-responsive.js +0 -498
  73. package/dist/components/responsive/responsive-legacy.js +0 -343
  74. package/dist/components/responsive/responsive.js +0 -580
  75. package/dist/components/responsive-preview/responsive-preview.js +0 -123
  76. package/dist/components/rich-label/rich-label.js +0 -66
  77. package/dist/components/select/async-multi-select.js +0 -157
  78. package/dist/components/select/async-single-select.js +0 -137
  79. package/dist/components/select/custom-select-default-components.js +0 -38
  80. package/dist/components/select/multi-select-components.js +0 -8
  81. package/dist/components/select/multi-select.js +0 -151
  82. package/dist/components/select/react-select-component-wrappers.js +0 -90
  83. package/dist/components/select/shared.js +0 -26
  84. package/dist/components/select/single-select.js +0 -131
  85. package/dist/components/select/styles.js +0 -49
  86. package/dist/components/select/v2/async-select.js +0 -297
  87. package/dist/components/select/v2/shared.js +0 -24
  88. package/dist/components/select/v2/single-select.js +0 -990
  89. package/dist/components/slider/column-config-slider.js +0 -210
  90. package/dist/components/slider/slider.js +0 -343
  91. package/dist/components/slider/utils.js +0 -84
  92. package/dist/components/spacer/spacer.js +0 -97
  93. package/dist/components/tabs/tabs.js +0 -702
  94. package/dist/components/toggle/switch.js +0 -155
  95. package/dist/components/toggle/toggle.js +0 -64
  96. package/dist/components/toggle-button/toggle-button.js +0 -324
  97. package/dist/components/tooltip/tooltip.js +0 -525
  98. package/dist/context-D2KUdwNL.js +0 -92
  99. package/dist/default-i18n-CT_oS1Fy.js +0 -922
  100. package/dist/filterDOMProps-EDDcM64A.js +0 -28
  101. package/dist/icons/block-icon.js +0 -42
  102. package/dist/icons/generic-color-swatch.js +0 -113
  103. package/dist/icons/icons.js +0 -30371
  104. package/dist/icons/index.js +0 -11
  105. package/dist/icons/jsx-svg.js +0 -50
  106. package/dist/index-641ee5b8.esm-DIuJijyT.js +0 -3137
  107. package/dist/index-BKGQ6jGS.js +0 -44
  108. package/dist/index-CFozsmNS.js +0 -28321
  109. package/dist/index.js +0 -139
  110. package/dist/lite-DVmmD_-j.js +0 -7
  111. package/dist/modifiers.esm-BuJQPI1X.js +0 -31
  112. package/dist/multi-select-components-Sp-JEFEX.js +0 -3744
  113. package/dist/number-GajL10e1.js +0 -36
  114. package/dist/react-jsx-parser.min-DZCiis5V.js +0 -11753
  115. package/dist/react-select-async.esm-Bql4G5iV.js +0 -107
  116. package/dist/react-select.esm-B_TudhTU.js +0 -15
  117. package/dist/style-admin.js +0 -1
  118. package/dist/style-editor.js +0 -1
  119. package/dist/style.js +0 -1
  120. package/dist/textSelection-0UUS8Yfg.js +0 -46
  121. package/dist/useButton-Cg474OYB.js +0 -71
  122. package/dist/useEvent-B0b-6KBr.js +0 -23
  123. package/dist/useFocusRing-CV5l3lf6.js +0 -107
  124. package/dist/useFormReset-C5OggHsw.js +0 -22
  125. package/dist/useFormValidation-DhDNSjws.js +0 -224
  126. package/dist/useHover-DwDr6ozG.js +0 -900
  127. package/dist/useLabel-D7HkNEHT.js +0 -27
  128. package/dist/useLabels-D8cxd1Z8.js +0 -23
  129. package/dist/useListState-DVr6aYd_.js +0 -161
  130. package/dist/useLocalizedStringFormatter-CFP1YZWQ.js +0 -121
  131. package/dist/useNumberField-TwM0Z9D1.js +0 -1204
  132. package/dist/useNumberFormatter-321rAb4J.js +0 -13
  133. package/dist/usePress-Cucx-xSA.js +0 -664
  134. package/dist/useSingleSelectListState-CMGsRHHh.js +0 -38
  135. package/dist/useToggle-C0I3vs0g.js +0 -59
  136. package/dist/useToggleState-CmQX3SoX.js +0 -19
  137. package/dist/utilities/array-helpers.js +0 -56
  138. package/dist/utilities/debounce-throttle.js +0 -123
  139. package/dist/utilities/es-dash.js +0 -376
  140. package/dist/utilities/index.js +0 -27
  141. package/dist/utilities/text-helpers.js +0 -136
  142. package/dist/utils-DkCSC521.js +0 -370
  143. package/dist/wp/wp-font-enhancements.js +0 -1
  144. package/dist/wp/wp-ui-enhancements.js +0 -1
@@ -1,922 +0,0 @@
1
- import { g as getDefaultExportFromCjs } from "./_commonjsHelpers-CUmg6egw.js";
2
- function memize(fn, options) {
3
- var size = 0;
4
- var head;
5
- var tail;
6
- options = options || {};
7
- function memoized() {
8
- var node = head, len = arguments.length, args, i;
9
- searchCache: while (node) {
10
- if (node.args.length !== arguments.length) {
11
- node = node.next;
12
- continue;
13
- }
14
- for (i = 0; i < len; i++) {
15
- if (node.args[i] !== arguments[i]) {
16
- node = node.next;
17
- continue searchCache;
18
- }
19
- }
20
- if (node !== head) {
21
- if (node === tail) {
22
- tail = node.prev;
23
- }
24
- node.prev.next = node.next;
25
- if (node.next) {
26
- node.next.prev = node.prev;
27
- }
28
- node.next = head;
29
- node.prev = null;
30
- head.prev = node;
31
- head = node;
32
- }
33
- return node.val;
34
- }
35
- args = new Array(len);
36
- for (i = 0; i < len; i++) {
37
- args[i] = arguments[i];
38
- }
39
- node = {
40
- args,
41
- // Generate the result from original function
42
- val: fn.apply(null, args)
43
- };
44
- if (head) {
45
- head.prev = node;
46
- node.next = head;
47
- } else {
48
- tail = node;
49
- }
50
- if (size === /** @type {MemizeOptions} */
51
- options.maxSize) {
52
- tail = /** @type {MemizeCacheNode} */
53
- tail.prev;
54
- tail.next = null;
55
- } else {
56
- size++;
57
- }
58
- head = node;
59
- return node.val;
60
- }
61
- memoized.clear = function() {
62
- head = null;
63
- tail = null;
64
- size = 0;
65
- };
66
- return memoized;
67
- }
68
- var sprintf$1 = {};
69
- var hasRequiredSprintf;
70
- function requireSprintf() {
71
- if (hasRequiredSprintf) return sprintf$1;
72
- hasRequiredSprintf = 1;
73
- (function(exports) {
74
- !function() {
75
- var re = {
76
- not_type: /[^T]/,
77
- not_primitive: /[^v]/,
78
- number: /[diefg]/,
79
- numeric_arg: /[bcdiefguxX]/,
80
- json: /[j]/,
81
- text: /^[^\x25]+/,
82
- modulo: /^\x25{2}/,
83
- placeholder: /^\x25(?:([1-9]\d*)\$|\(([^)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-gijostTuvxX])/,
84
- key: /^([a-z_][a-z_\d]*)/i,
85
- key_access: /^\.([a-z_][a-z_\d]*)/i,
86
- index_access: /^\[(\d+)\]/,
87
- sign: /^[+-]/
88
- };
89
- function sprintf2(key) {
90
- return sprintf_format(sprintf_parse(key), arguments);
91
- }
92
- function vsprintf(fmt, argv) {
93
- return sprintf2.apply(null, [fmt].concat(argv || []));
94
- }
95
- function sprintf_format(parse_tree, argv) {
96
- var cursor = 1, tree_length = parse_tree.length, arg, output = "", i, k, ph, pad, pad_character, pad_length, is_positive, sign;
97
- for (i = 0; i < tree_length; i++) {
98
- if (typeof parse_tree[i] === "string") {
99
- output += parse_tree[i];
100
- } else if (typeof parse_tree[i] === "object") {
101
- ph = parse_tree[i];
102
- if (ph.keys) {
103
- arg = argv[cursor];
104
- for (k = 0; k < ph.keys.length; k++) {
105
- if (arg == void 0) {
106
- throw new Error(sprintf2('[sprintf] Cannot access property "%s" of undefined value "%s"', ph.keys[k], ph.keys[k - 1]));
107
- }
108
- arg = arg[ph.keys[k]];
109
- }
110
- } else if (ph.param_no) {
111
- arg = argv[ph.param_no];
112
- } else {
113
- arg = argv[cursor++];
114
- }
115
- if (re.not_type.test(ph.type) && re.not_primitive.test(ph.type) && arg instanceof Function) {
116
- arg = arg();
117
- }
118
- if (re.numeric_arg.test(ph.type) && (typeof arg !== "number" && isNaN(arg))) {
119
- throw new TypeError(sprintf2("[sprintf] expecting number but found %T", arg));
120
- }
121
- if (re.number.test(ph.type)) {
122
- is_positive = arg >= 0;
123
- }
124
- switch (ph.type) {
125
- case "b":
126
- arg = parseInt(arg, 10).toString(2);
127
- break;
128
- case "c":
129
- arg = String.fromCharCode(parseInt(arg, 10));
130
- break;
131
- case "d":
132
- case "i":
133
- arg = parseInt(arg, 10);
134
- break;
135
- case "j":
136
- arg = JSON.stringify(arg, null, ph.width ? parseInt(ph.width) : 0);
137
- break;
138
- case "e":
139
- arg = ph.precision ? parseFloat(arg).toExponential(ph.precision) : parseFloat(arg).toExponential();
140
- break;
141
- case "f":
142
- arg = ph.precision ? parseFloat(arg).toFixed(ph.precision) : parseFloat(arg);
143
- break;
144
- case "g":
145
- arg = ph.precision ? String(Number(arg.toPrecision(ph.precision))) : parseFloat(arg);
146
- break;
147
- case "o":
148
- arg = (parseInt(arg, 10) >>> 0).toString(8);
149
- break;
150
- case "s":
151
- arg = String(arg);
152
- arg = ph.precision ? arg.substring(0, ph.precision) : arg;
153
- break;
154
- case "t":
155
- arg = String(!!arg);
156
- arg = ph.precision ? arg.substring(0, ph.precision) : arg;
157
- break;
158
- case "T":
159
- arg = Object.prototype.toString.call(arg).slice(8, -1).toLowerCase();
160
- arg = ph.precision ? arg.substring(0, ph.precision) : arg;
161
- break;
162
- case "u":
163
- arg = parseInt(arg, 10) >>> 0;
164
- break;
165
- case "v":
166
- arg = arg.valueOf();
167
- arg = ph.precision ? arg.substring(0, ph.precision) : arg;
168
- break;
169
- case "x":
170
- arg = (parseInt(arg, 10) >>> 0).toString(16);
171
- break;
172
- case "X":
173
- arg = (parseInt(arg, 10) >>> 0).toString(16).toUpperCase();
174
- break;
175
- }
176
- if (re.json.test(ph.type)) {
177
- output += arg;
178
- } else {
179
- if (re.number.test(ph.type) && (!is_positive || ph.sign)) {
180
- sign = is_positive ? "+" : "-";
181
- arg = arg.toString().replace(re.sign, "");
182
- } else {
183
- sign = "";
184
- }
185
- pad_character = ph.pad_char ? ph.pad_char === "0" ? "0" : ph.pad_char.charAt(1) : " ";
186
- pad_length = ph.width - (sign + arg).length;
187
- pad = ph.width ? pad_length > 0 ? pad_character.repeat(pad_length) : "" : "";
188
- output += ph.align ? sign + arg + pad : pad_character === "0" ? sign + pad + arg : pad + sign + arg;
189
- }
190
- }
191
- }
192
- return output;
193
- }
194
- var sprintf_cache = /* @__PURE__ */ Object.create(null);
195
- function sprintf_parse(fmt) {
196
- if (sprintf_cache[fmt]) {
197
- return sprintf_cache[fmt];
198
- }
199
- var _fmt = fmt, match, parse_tree = [], arg_names = 0;
200
- while (_fmt) {
201
- if ((match = re.text.exec(_fmt)) !== null) {
202
- parse_tree.push(match[0]);
203
- } else if ((match = re.modulo.exec(_fmt)) !== null) {
204
- parse_tree.push("%");
205
- } else if ((match = re.placeholder.exec(_fmt)) !== null) {
206
- if (match[2]) {
207
- arg_names |= 1;
208
- var field_list = [], replacement_field = match[2], field_match = [];
209
- if ((field_match = re.key.exec(replacement_field)) !== null) {
210
- field_list.push(field_match[1]);
211
- while ((replacement_field = replacement_field.substring(field_match[0].length)) !== "") {
212
- if ((field_match = re.key_access.exec(replacement_field)) !== null) {
213
- field_list.push(field_match[1]);
214
- } else if ((field_match = re.index_access.exec(replacement_field)) !== null) {
215
- field_list.push(field_match[1]);
216
- } else {
217
- throw new SyntaxError("[sprintf] failed to parse named argument key");
218
- }
219
- }
220
- } else {
221
- throw new SyntaxError("[sprintf] failed to parse named argument key");
222
- }
223
- match[2] = field_list;
224
- } else {
225
- arg_names |= 2;
226
- }
227
- if (arg_names === 3) {
228
- throw new Error("[sprintf] mixing positional and named placeholders is not (yet) supported");
229
- }
230
- parse_tree.push(
231
- {
232
- placeholder: match[0],
233
- param_no: match[1],
234
- keys: match[2],
235
- sign: match[3],
236
- pad_char: match[4],
237
- align: match[5],
238
- width: match[6],
239
- precision: match[7],
240
- type: match[8]
241
- }
242
- );
243
- } else {
244
- throw new SyntaxError("[sprintf] unexpected placeholder");
245
- }
246
- _fmt = _fmt.substring(match[0].length);
247
- }
248
- return sprintf_cache[fmt] = parse_tree;
249
- }
250
- {
251
- exports["sprintf"] = sprintf2;
252
- exports["vsprintf"] = vsprintf;
253
- }
254
- if (typeof window !== "undefined") {
255
- window["sprintf"] = sprintf2;
256
- window["vsprintf"] = vsprintf;
257
- }
258
- }();
259
- })(sprintf$1);
260
- return sprintf$1;
261
- }
262
- var sprintfExports = requireSprintf();
263
- const sprintfjs = /* @__PURE__ */ getDefaultExportFromCjs(sprintfExports);
264
- const logErrorOnce = memize(console.error);
265
- function sprintf(format, ...args) {
266
- try {
267
- return sprintfjs.sprintf(format, ...args);
268
- } catch (error) {
269
- if (error instanceof Error) {
270
- logErrorOnce("sprintf error: \n\n" + error.toString());
271
- }
272
- return format;
273
- }
274
- }
275
- var PRECEDENCE, OPENERS, TERMINATORS, PATTERN;
276
- PRECEDENCE = {
277
- "(": 9,
278
- "!": 8,
279
- "*": 7,
280
- "/": 7,
281
- "%": 7,
282
- "+": 6,
283
- "-": 6,
284
- "<": 5,
285
- "<=": 5,
286
- ">": 5,
287
- ">=": 5,
288
- "==": 4,
289
- "!=": 4,
290
- "&&": 3,
291
- "||": 2,
292
- "?": 1,
293
- "?:": 1
294
- };
295
- OPENERS = ["(", "?"];
296
- TERMINATORS = {
297
- ")": ["("],
298
- ":": ["?", "?:"]
299
- };
300
- PATTERN = /<=|>=|==|!=|&&|\|\||\?:|\(|!|\*|\/|%|\+|-|<|>|\?|\)|:/;
301
- function postfix(expression) {
302
- var terms = [], stack = [], match, operator, term, element;
303
- while (match = expression.match(PATTERN)) {
304
- operator = match[0];
305
- term = expression.substr(0, match.index).trim();
306
- if (term) {
307
- terms.push(term);
308
- }
309
- while (element = stack.pop()) {
310
- if (TERMINATORS[operator]) {
311
- if (TERMINATORS[operator][0] === element) {
312
- operator = TERMINATORS[operator][1] || operator;
313
- break;
314
- }
315
- } else if (OPENERS.indexOf(element) >= 0 || PRECEDENCE[element] < PRECEDENCE[operator]) {
316
- stack.push(element);
317
- break;
318
- }
319
- terms.push(element);
320
- }
321
- if (!TERMINATORS[operator]) {
322
- stack.push(operator);
323
- }
324
- expression = expression.substr(match.index + operator.length);
325
- }
326
- expression = expression.trim();
327
- if (expression) {
328
- terms.push(expression);
329
- }
330
- return terms.concat(stack.reverse());
331
- }
332
- var OPERATORS = {
333
- "!": function(a) {
334
- return !a;
335
- },
336
- "*": function(a, b) {
337
- return a * b;
338
- },
339
- "/": function(a, b) {
340
- return a / b;
341
- },
342
- "%": function(a, b) {
343
- return a % b;
344
- },
345
- "+": function(a, b) {
346
- return a + b;
347
- },
348
- "-": function(a, b) {
349
- return a - b;
350
- },
351
- "<": function(a, b) {
352
- return a < b;
353
- },
354
- "<=": function(a, b) {
355
- return a <= b;
356
- },
357
- ">": function(a, b) {
358
- return a > b;
359
- },
360
- ">=": function(a, b) {
361
- return a >= b;
362
- },
363
- "==": function(a, b) {
364
- return a === b;
365
- },
366
- "!=": function(a, b) {
367
- return a !== b;
368
- },
369
- "&&": function(a, b) {
370
- return a && b;
371
- },
372
- "||": function(a, b) {
373
- return a || b;
374
- },
375
- "?:": function(a, b, c) {
376
- if (a) {
377
- throw b;
378
- }
379
- return c;
380
- }
381
- };
382
- function evaluate(postfix2, variables) {
383
- var stack = [], i, j, args, getOperatorResult, term, value;
384
- for (i = 0; i < postfix2.length; i++) {
385
- term = postfix2[i];
386
- getOperatorResult = OPERATORS[term];
387
- if (getOperatorResult) {
388
- j = getOperatorResult.length;
389
- args = Array(j);
390
- while (j--) {
391
- args[j] = stack.pop();
392
- }
393
- try {
394
- value = getOperatorResult.apply(null, args);
395
- } catch (earlyReturn) {
396
- return earlyReturn;
397
- }
398
- } else if (variables.hasOwnProperty(term)) {
399
- value = variables[term];
400
- } else {
401
- value = +term;
402
- }
403
- stack.push(value);
404
- }
405
- return stack[0];
406
- }
407
- function compile(expression) {
408
- var terms = postfix(expression);
409
- return function(variables) {
410
- return evaluate(terms, variables);
411
- };
412
- }
413
- function pluralForms(expression) {
414
- var evaluate2 = compile(expression);
415
- return function(n) {
416
- return +evaluate2({ n });
417
- };
418
- }
419
- var DEFAULT_OPTIONS = {
420
- contextDelimiter: "",
421
- onMissingKey: null
422
- };
423
- function getPluralExpression(pf) {
424
- var parts, i, part;
425
- parts = pf.split(";");
426
- for (i = 0; i < parts.length; i++) {
427
- part = parts[i].trim();
428
- if (part.indexOf("plural=") === 0) {
429
- return part.substr(7);
430
- }
431
- }
432
- }
433
- function Tannin(data, options) {
434
- var key;
435
- this.data = data;
436
- this.pluralForms = {};
437
- this.options = {};
438
- for (key in DEFAULT_OPTIONS) {
439
- this.options[key] = options !== void 0 && key in options ? options[key] : DEFAULT_OPTIONS[key];
440
- }
441
- }
442
- Tannin.prototype.getPluralForm = function(domain, n) {
443
- var getPluralForm = this.pluralForms[domain], config, plural, pf;
444
- if (!getPluralForm) {
445
- config = this.data[domain][""];
446
- pf = config["Plural-Forms"] || config["plural-forms"] || // Ignore reason: As known, there's no way to document the empty
447
- // string property on a key to guarantee this as metadata.
448
- // @ts-ignore
449
- config.plural_forms;
450
- if (typeof pf !== "function") {
451
- plural = getPluralExpression(
452
- config["Plural-Forms"] || config["plural-forms"] || // Ignore reason: As known, there's no way to document the empty
453
- // string property on a key to guarantee this as metadata.
454
- // @ts-ignore
455
- config.plural_forms
456
- );
457
- pf = pluralForms(plural);
458
- }
459
- getPluralForm = this.pluralForms[domain] = pf;
460
- }
461
- return getPluralForm(n);
462
- };
463
- Tannin.prototype.dcnpgettext = function(domain, context, singular, plural, n) {
464
- var index, key, entry;
465
- if (n === void 0) {
466
- index = 0;
467
- } else {
468
- index = this.getPluralForm(domain, n);
469
- }
470
- key = singular;
471
- if (context) {
472
- key = context + this.options.contextDelimiter + singular;
473
- }
474
- entry = this.data[domain][key];
475
- if (entry && entry[index]) {
476
- return entry[index];
477
- }
478
- if (this.options.onMissingKey) {
479
- this.options.onMissingKey(singular, domain);
480
- }
481
- return index === 0 ? singular : plural;
482
- };
483
- const DEFAULT_LOCALE_DATA = {
484
- "": {
485
- /** @param {number} n */
486
- plural_forms(n) {
487
- return n === 1 ? 0 : 1;
488
- }
489
- }
490
- };
491
- const I18N_HOOK_REGEXP = /^i18n\.(n?gettext|has_translation)(_|$)/;
492
- const createI18n = (initialData, initialDomain, hooks) => {
493
- const tannin = new Tannin({});
494
- const listeners = /* @__PURE__ */ new Set();
495
- const notifyListeners = () => {
496
- listeners.forEach((listener) => listener());
497
- };
498
- const subscribe = (callback) => {
499
- listeners.add(callback);
500
- return () => listeners.delete(callback);
501
- };
502
- const getLocaleData = (domain = "default") => tannin.data[domain];
503
- const doSetLocaleData = (data, domain = "default") => {
504
- var _a;
505
- tannin.data[domain] = {
506
- ...tannin.data[domain],
507
- ...data
508
- };
509
- tannin.data[domain][""] = {
510
- ...DEFAULT_LOCALE_DATA[""],
511
- ...(_a = tannin.data[domain]) == null ? void 0 : _a[""]
512
- };
513
- delete tannin.pluralForms[domain];
514
- };
515
- const setLocaleData = (data, domain) => {
516
- doSetLocaleData(data, domain);
517
- notifyListeners();
518
- };
519
- const addLocaleData = (data, domain = "default") => {
520
- var _a;
521
- tannin.data[domain] = {
522
- ...tannin.data[domain],
523
- ...data,
524
- // Populate default domain configuration (supported locale date which omits
525
- // a plural forms expression).
526
- "": {
527
- ...DEFAULT_LOCALE_DATA[""],
528
- ...(_a = tannin.data[domain]) == null ? void 0 : _a[""],
529
- ...data == null ? void 0 : data[""]
530
- }
531
- };
532
- delete tannin.pluralForms[domain];
533
- notifyListeners();
534
- };
535
- const resetLocaleData = (data, domain) => {
536
- tannin.data = {};
537
- tannin.pluralForms = {};
538
- setLocaleData(data, domain);
539
- };
540
- const dcnpgettext = (domain = "default", context, single, plural, number) => {
541
- if (!tannin.data[domain]) {
542
- doSetLocaleData(void 0, domain);
543
- }
544
- return tannin.dcnpgettext(domain, context, single, plural, number);
545
- };
546
- const getFilterDomain = (domain = "default") => domain;
547
- const __2 = (text, domain) => {
548
- let translation = dcnpgettext(domain, void 0, text);
549
- if (!hooks) {
550
- return translation;
551
- }
552
- translation = /** @type {string} */
553
- /** @type {*} */
554
- hooks.applyFilters("i18n.gettext", translation, text, domain);
555
- return (
556
- /** @type {string} */
557
- /** @type {*} */
558
- hooks.applyFilters("i18n.gettext_" + getFilterDomain(domain), translation, text, domain)
559
- );
560
- };
561
- const _x = (text, context, domain) => {
562
- let translation = dcnpgettext(domain, context, text);
563
- if (!hooks) {
564
- return translation;
565
- }
566
- translation = /** @type {string} */
567
- /** @type {*} */
568
- hooks.applyFilters("i18n.gettext_with_context", translation, text, context, domain);
569
- return (
570
- /** @type {string} */
571
- /** @type {*} */
572
- hooks.applyFilters("i18n.gettext_with_context_" + getFilterDomain(domain), translation, text, context, domain)
573
- );
574
- };
575
- const _n2 = (single, plural, number, domain) => {
576
- let translation = dcnpgettext(domain, void 0, single, plural, number);
577
- if (!hooks) {
578
- return translation;
579
- }
580
- translation = /** @type {string} */
581
- /** @type {*} */
582
- hooks.applyFilters("i18n.ngettext", translation, single, plural, number, domain);
583
- return (
584
- /** @type {string} */
585
- /** @type {*} */
586
- hooks.applyFilters("i18n.ngettext_" + getFilterDomain(domain), translation, single, plural, number, domain)
587
- );
588
- };
589
- const _nx = (single, plural, number, context, domain) => {
590
- let translation = dcnpgettext(domain, context, single, plural, number);
591
- if (!hooks) {
592
- return translation;
593
- }
594
- translation = /** @type {string} */
595
- /** @type {*} */
596
- hooks.applyFilters("i18n.ngettext_with_context", translation, single, plural, number, context, domain);
597
- return (
598
- /** @type {string} */
599
- /** @type {*} */
600
- hooks.applyFilters("i18n.ngettext_with_context_" + getFilterDomain(domain), translation, single, plural, number, context, domain)
601
- );
602
- };
603
- const isRTL = () => {
604
- return "rtl" === _x("ltr", "text direction");
605
- };
606
- const hasTranslation = (single, context, domain) => {
607
- var _a, _b;
608
- const key = context ? context + "" + single : single;
609
- let result = !!((_b = (_a = tannin.data) == null ? void 0 : _a[domain !== null && domain !== void 0 ? domain : "default"]) == null ? void 0 : _b[key]);
610
- if (hooks) {
611
- result = /** @type { boolean } */
612
- /** @type {*} */
613
- hooks.applyFilters("i18n.has_translation", result, single, context, domain);
614
- result = /** @type { boolean } */
615
- /** @type {*} */
616
- hooks.applyFilters("i18n.has_translation_" + getFilterDomain(domain), result, single, context, domain);
617
- }
618
- return result;
619
- };
620
- if (hooks) {
621
- const onHookAddedOrRemoved = (hookName) => {
622
- if (I18N_HOOK_REGEXP.test(hookName)) {
623
- notifyListeners();
624
- }
625
- };
626
- hooks.addAction("hookAdded", "core/i18n", onHookAddedOrRemoved);
627
- hooks.addAction("hookRemoved", "core/i18n", onHookAddedOrRemoved);
628
- }
629
- return {
630
- getLocaleData,
631
- setLocaleData,
632
- addLocaleData,
633
- resetLocaleData,
634
- subscribe,
635
- __: __2,
636
- _x,
637
- _n: _n2,
638
- _nx,
639
- isRTL,
640
- hasTranslation
641
- };
642
- };
643
- function validateNamespace(namespace) {
644
- if ("string" !== typeof namespace || "" === namespace) {
645
- console.error("The namespace must be a non-empty string.");
646
- return false;
647
- }
648
- if (!/^[a-zA-Z][a-zA-Z0-9_.\-\/]*$/.test(namespace)) {
649
- console.error("The namespace can only contain numbers, letters, dashes, periods, underscores and slashes.");
650
- return false;
651
- }
652
- return true;
653
- }
654
- function validateHookName(hookName) {
655
- if ("string" !== typeof hookName || "" === hookName) {
656
- console.error("The hook name must be a non-empty string.");
657
- return false;
658
- }
659
- if (/^__/.test(hookName)) {
660
- console.error("The hook name cannot begin with `__`.");
661
- return false;
662
- }
663
- if (!/^[a-zA-Z][a-zA-Z0-9_.-]*$/.test(hookName)) {
664
- console.error("The hook name can only contain numbers, letters, dashes, periods and underscores.");
665
- return false;
666
- }
667
- return true;
668
- }
669
- function createAddHook(hooks, storeKey) {
670
- return function addHook(hookName, namespace, callback, priority = 10) {
671
- const hooksStore = hooks[storeKey];
672
- if (!validateHookName(hookName)) {
673
- return;
674
- }
675
- if (!validateNamespace(namespace)) {
676
- return;
677
- }
678
- if ("function" !== typeof callback) {
679
- console.error("The hook callback must be a function.");
680
- return;
681
- }
682
- if ("number" !== typeof priority) {
683
- console.error("If specified, the hook priority must be a number.");
684
- return;
685
- }
686
- const handler = {
687
- callback,
688
- priority,
689
- namespace
690
- };
691
- if (hooksStore[hookName]) {
692
- const handlers = hooksStore[hookName].handlers;
693
- let i;
694
- for (i = handlers.length; i > 0; i--) {
695
- if (priority >= handlers[i - 1].priority) {
696
- break;
697
- }
698
- }
699
- if (i === handlers.length) {
700
- handlers[i] = handler;
701
- } else {
702
- handlers.splice(i, 0, handler);
703
- }
704
- hooksStore.__current.forEach((hookInfo) => {
705
- if (hookInfo.name === hookName && hookInfo.currentIndex >= i) {
706
- hookInfo.currentIndex++;
707
- }
708
- });
709
- } else {
710
- hooksStore[hookName] = {
711
- handlers: [handler],
712
- runs: 0
713
- };
714
- }
715
- if (hookName !== "hookAdded") {
716
- hooks.doAction("hookAdded", hookName, namespace, callback, priority);
717
- }
718
- };
719
- }
720
- function createRemoveHook(hooks, storeKey, removeAll = false) {
721
- return function removeHook(hookName, namespace) {
722
- const hooksStore = hooks[storeKey];
723
- if (!validateHookName(hookName)) {
724
- return;
725
- }
726
- if (!removeAll && !validateNamespace(namespace)) {
727
- return;
728
- }
729
- if (!hooksStore[hookName]) {
730
- return 0;
731
- }
732
- let handlersRemoved = 0;
733
- if (removeAll) {
734
- handlersRemoved = hooksStore[hookName].handlers.length;
735
- hooksStore[hookName] = {
736
- runs: hooksStore[hookName].runs,
737
- handlers: []
738
- };
739
- } else {
740
- const handlers = hooksStore[hookName].handlers;
741
- for (let i = handlers.length - 1; i >= 0; i--) {
742
- if (handlers[i].namespace === namespace) {
743
- handlers.splice(i, 1);
744
- handlersRemoved++;
745
- hooksStore.__current.forEach((hookInfo) => {
746
- if (hookInfo.name === hookName && hookInfo.currentIndex >= i) {
747
- hookInfo.currentIndex--;
748
- }
749
- });
750
- }
751
- }
752
- }
753
- if (hookName !== "hookRemoved") {
754
- hooks.doAction("hookRemoved", hookName, namespace);
755
- }
756
- return handlersRemoved;
757
- };
758
- }
759
- function createHasHook(hooks, storeKey) {
760
- return function hasHook(hookName, namespace) {
761
- const hooksStore = hooks[storeKey];
762
- if ("undefined" !== typeof namespace) {
763
- return hookName in hooksStore && hooksStore[hookName].handlers.some((hook) => hook.namespace === namespace);
764
- }
765
- return hookName in hooksStore;
766
- };
767
- }
768
- function createRunHook(hooks, storeKey, returnFirstArg, async) {
769
- return function runHook(hookName, ...args) {
770
- const hooksStore = hooks[storeKey];
771
- if (!hooksStore[hookName]) {
772
- hooksStore[hookName] = {
773
- handlers: [],
774
- runs: 0
775
- };
776
- }
777
- hooksStore[hookName].runs++;
778
- const handlers = hooksStore[hookName].handlers;
779
- if ("production" !== process.env.NODE_ENV) {
780
- if ("hookAdded" !== hookName && hooksStore.all) {
781
- handlers.push(...hooksStore.all.handlers);
782
- }
783
- }
784
- if (!handlers || !handlers.length) {
785
- return returnFirstArg ? args[0] : void 0;
786
- }
787
- const hookInfo = {
788
- name: hookName,
789
- currentIndex: 0
790
- };
791
- async function asyncRunner() {
792
- try {
793
- hooksStore.__current.add(hookInfo);
794
- let result = returnFirstArg ? args[0] : void 0;
795
- while (hookInfo.currentIndex < handlers.length) {
796
- const handler = handlers[hookInfo.currentIndex];
797
- result = await handler.callback.apply(null, args);
798
- if (returnFirstArg) {
799
- args[0] = result;
800
- }
801
- hookInfo.currentIndex++;
802
- }
803
- return returnFirstArg ? result : void 0;
804
- } finally {
805
- hooksStore.__current.delete(hookInfo);
806
- }
807
- }
808
- function syncRunner() {
809
- try {
810
- hooksStore.__current.add(hookInfo);
811
- let result = returnFirstArg ? args[0] : void 0;
812
- while (hookInfo.currentIndex < handlers.length) {
813
- const handler = handlers[hookInfo.currentIndex];
814
- result = handler.callback.apply(null, args);
815
- if (returnFirstArg) {
816
- args[0] = result;
817
- }
818
- hookInfo.currentIndex++;
819
- }
820
- return returnFirstArg ? result : void 0;
821
- } finally {
822
- hooksStore.__current.delete(hookInfo);
823
- }
824
- }
825
- return (async ? asyncRunner : syncRunner)();
826
- };
827
- }
828
- function createCurrentHook(hooks, storeKey) {
829
- return function currentHook() {
830
- var _a;
831
- var _currentArray$at$name;
832
- const hooksStore = hooks[storeKey];
833
- const currentArray = Array.from(hooksStore.__current);
834
- return (_currentArray$at$name = (_a = currentArray.at(-1)) == null ? void 0 : _a.name) !== null && _currentArray$at$name !== void 0 ? _currentArray$at$name : null;
835
- };
836
- }
837
- function createDoingHook(hooks, storeKey) {
838
- return function doingHook(hookName) {
839
- const hooksStore = hooks[storeKey];
840
- if ("undefined" === typeof hookName) {
841
- return hooksStore.__current.size > 0;
842
- }
843
- return Array.from(hooksStore.__current).some((hook) => hook.name === hookName);
844
- };
845
- }
846
- function createDidHook(hooks, storeKey) {
847
- return function didHook(hookName) {
848
- const hooksStore = hooks[storeKey];
849
- if (!validateHookName(hookName)) {
850
- return;
851
- }
852
- return hooksStore[hookName] && hooksStore[hookName].runs ? hooksStore[hookName].runs : 0;
853
- };
854
- }
855
- class _Hooks {
856
- constructor() {
857
- this.actions = /* @__PURE__ */ Object.create(null);
858
- this.actions.__current = /* @__PURE__ */ new Set();
859
- this.filters = /* @__PURE__ */ Object.create(null);
860
- this.filters.__current = /* @__PURE__ */ new Set();
861
- this.addAction = createAddHook(this, "actions");
862
- this.addFilter = createAddHook(this, "filters");
863
- this.removeAction = createRemoveHook(this, "actions");
864
- this.removeFilter = createRemoveHook(this, "filters");
865
- this.hasAction = createHasHook(this, "actions");
866
- this.hasFilter = createHasHook(this, "filters");
867
- this.removeAllActions = createRemoveHook(this, "actions", true);
868
- this.removeAllFilters = createRemoveHook(this, "filters", true);
869
- this.doAction = createRunHook(this, "actions", false, false);
870
- this.doActionAsync = createRunHook(this, "actions", false, true);
871
- this.applyFilters = createRunHook(this, "filters", true, false);
872
- this.applyFiltersAsync = createRunHook(this, "filters", true, true);
873
- this.currentAction = createCurrentHook(this, "actions");
874
- this.currentFilter = createCurrentHook(this, "filters");
875
- this.doingAction = createDoingHook(this, "actions");
876
- this.doingFilter = createDoingHook(this, "filters");
877
- this.didAction = createDidHook(this, "actions");
878
- this.didFilter = createDidHook(this, "filters");
879
- }
880
- }
881
- function createHooks() {
882
- return new _Hooks();
883
- }
884
- const defaultHooks = createHooks();
885
- const {
886
- addAction,
887
- addFilter,
888
- removeAction,
889
- removeFilter,
890
- hasAction,
891
- hasFilter,
892
- removeAllActions,
893
- removeAllFilters,
894
- doAction,
895
- doActionAsync,
896
- applyFilters,
897
- applyFiltersAsync,
898
- currentAction,
899
- currentFilter,
900
- doingAction,
901
- doingFilter,
902
- didAction,
903
- didFilter,
904
- actions,
905
- filters
906
- } = defaultHooks;
907
- const i18n = createI18n(void 0, void 0, defaultHooks);
908
- i18n.getLocaleData.bind(i18n);
909
- i18n.setLocaleData.bind(i18n);
910
- i18n.resetLocaleData.bind(i18n);
911
- i18n.subscribe.bind(i18n);
912
- const __ = i18n.__.bind(i18n);
913
- i18n._x.bind(i18n);
914
- const _n = i18n._n.bind(i18n);
915
- i18n._nx.bind(i18n);
916
- i18n.isRTL.bind(i18n);
917
- i18n.hasTranslation.bind(i18n);
918
- export {
919
- __ as _,
920
- _n as a,
921
- sprintf as s
922
- };