@windwalker-io/unicorn-next 0.1.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 (175) hide show
  1. package/.editorconfig +18 -0
  2. package/.gulp.json +7 -0
  3. package/bin/release.mjs +47 -0
  4. package/dist/chunks/_arrayPush.js +168 -0
  5. package/dist/chunks/_arrayPush.js.map +1 -0
  6. package/dist/chunks/_baseRest.js +73 -0
  7. package/dist/chunks/_baseRest.js.map +1 -0
  8. package/dist/chunks/_commonjsHelpers.js +7 -0
  9. package/dist/chunks/_commonjsHelpers.js.map +1 -0
  10. package/dist/chunks/_getPrototype.js +130 -0
  11. package/dist/chunks/_getPrototype.js.map +1 -0
  12. package/dist/chunks/button-radio.js +147 -0
  13. package/dist/chunks/button-radio.js.map +1 -0
  14. package/dist/chunks/checkboxes-multi-select.js +44 -0
  15. package/dist/chunks/checkboxes-multi-select.js.map +1 -0
  16. package/dist/chunks/cloneDeep.js +287 -0
  17. package/dist/chunks/cloneDeep.js.map +1 -0
  18. package/dist/chunks/cropper.min.js +5 -0
  19. package/dist/chunks/cropper.min.js.map +1 -0
  20. package/dist/chunks/field-cascade-select.js +256 -0
  21. package/dist/chunks/field-cascade-select.js.map +1 -0
  22. package/dist/chunks/field-file-drag.js +218 -0
  23. package/dist/chunks/field-file-drag.js.map +1 -0
  24. package/dist/chunks/field-flatpickr.js +893 -0
  25. package/dist/chunks/field-flatpickr.js.map +1 -0
  26. package/dist/chunks/field-modal-select.js +403 -0
  27. package/dist/chunks/field-modal-select.js.map +1 -0
  28. package/dist/chunks/field-modal-tree.js +790 -0
  29. package/dist/chunks/field-modal-tree.js.map +1 -0
  30. package/dist/chunks/field-multi-uploader.js +256 -0
  31. package/dist/chunks/field-multi-uploader.js.map +1 -0
  32. package/dist/chunks/field-repeatable.js +132 -0
  33. package/dist/chunks/field-repeatable.js.map +1 -0
  34. package/dist/chunks/field-single-image-drag.js +338 -0
  35. package/dist/chunks/field-single-image-drag.js.map +1 -0
  36. package/dist/chunks/form.js +154 -0
  37. package/dist/chunks/form.js.map +1 -0
  38. package/dist/chunks/grid.js +345 -0
  39. package/dist/chunks/grid.js.map +1 -0
  40. package/dist/chunks/http-client.js +229 -0
  41. package/dist/chunks/http-client.js.map +1 -0
  42. package/dist/chunks/iframe-modal.js +124 -0
  43. package/dist/chunks/iframe-modal.js.map +1 -0
  44. package/dist/chunks/index.js +309 -0
  45. package/dist/chunks/index.js.map +1 -0
  46. package/dist/chunks/isArguments.js +146 -0
  47. package/dist/chunks/isArguments.js.map +1 -0
  48. package/dist/chunks/keep-tab.js +101 -0
  49. package/dist/chunks/keep-tab.js.map +1 -0
  50. package/dist/chunks/legacy.js +210 -0
  51. package/dist/chunks/legacy.js.map +1 -0
  52. package/dist/chunks/list-dependent.js +231 -0
  53. package/dist/chunks/list-dependent.js.map +1 -0
  54. package/dist/chunks/s3-multipart-uploader.js +172 -0
  55. package/dist/chunks/s3-multipart-uploader.js.map +1 -0
  56. package/dist/chunks/s3-uploader.js +136 -0
  57. package/dist/chunks/s3-uploader.js.map +1 -0
  58. package/dist/chunks/show-on.js +237 -0
  59. package/dist/chunks/show-on.js.map +1 -0
  60. package/dist/chunks/tinymce.js +196 -0
  61. package/dist/chunks/tinymce.js.map +1 -0
  62. package/dist/chunks/ui-bootstrap5.js +71 -0
  63. package/dist/chunks/ui-bootstrap5.js.map +1 -0
  64. package/dist/chunks/unicorn.js +2202 -0
  65. package/dist/chunks/unicorn.js.map +1 -0
  66. package/dist/chunks/validation.js +854 -0
  67. package/dist/chunks/validation.js.map +1 -0
  68. package/dist/editor.css +1 -0
  69. package/dist/index.d.ts +1427 -0
  70. package/dist/multi-level-menu.css +1 -0
  71. package/dist/switcher.css +1 -0
  72. package/dist/unicorn-next.css +12 -0
  73. package/dist/unicorn.js +125 -0
  74. package/dist/unicorn.js.map +1 -0
  75. package/fusionfile.mjs +155 -0
  76. package/images/ajax-loader.gif +0 -0
  77. package/images/placeholder/avatar.png +0 -0
  78. package/images/placeholder/image-16x10.png +0 -0
  79. package/images/placeholder/image-16x9.png +0 -0
  80. package/images/placeholder/image-1x1.png +0 -0
  81. package/images/placeholder/image-4x3.png +0 -0
  82. package/package.json +102 -0
  83. package/scss/bootstrap/multi-level-menu.scss +121 -0
  84. package/scss/editor.scss +116 -0
  85. package/scss/field/file-drag.scss +102 -0
  86. package/scss/field/single-image-drag.scss +88 -0
  87. package/scss/field/vue-drag-uploader.scss +160 -0
  88. package/scss/switcher.scss +156 -0
  89. package/src/app.ts +128 -0
  90. package/src/bootstrap/button-radio.ts +208 -0
  91. package/src/bootstrap/keep-tab.ts +155 -0
  92. package/src/composable/index.ts +21 -0
  93. package/src/composable/useCheckboxesMultiSelect.ts +22 -0
  94. package/src/composable/useFieldCascadeSelect.ts +9 -0
  95. package/src/composable/useFieldFileDrag.ts +9 -0
  96. package/src/composable/useFieldFlatpickr.ts +3 -0
  97. package/src/composable/useFieldModalSelect.ts +6 -0
  98. package/src/composable/useFieldModalTree.ts +3 -0
  99. package/src/composable/useFieldMultiUploader.ts +3 -0
  100. package/src/composable/useFieldRepeatable.ts +9 -0
  101. package/src/composable/useFieldSingleImageDrag.ts +5 -0
  102. package/src/composable/useForm.ts +43 -0
  103. package/src/composable/useGrid.ts +57 -0
  104. package/src/composable/useHttp.ts +8 -0
  105. package/src/composable/useIframeModal.ts +9 -0
  106. package/src/composable/useListDependent.ts +26 -0
  107. package/src/composable/useQueue.ts +13 -0
  108. package/src/composable/useS3Uploader.ts +32 -0
  109. package/src/composable/useShowOn.ts +9 -0
  110. package/src/composable/useStack.ts +13 -0
  111. package/src/composable/useTinymce.ts +29 -0
  112. package/src/composable/useTomSelect.ts +72 -0
  113. package/src/composable/useUIBootstrap5.ts +48 -0
  114. package/src/composable/useUniDirective.ts +32 -0
  115. package/src/composable/useValidation.ts +39 -0
  116. package/src/data.ts +36 -0
  117. package/src/events.ts +73 -0
  118. package/src/legacy/legacy.ts +186 -0
  119. package/src/legacy/loader.ts +125 -0
  120. package/src/module/checkboxes-multi-select.ts +54 -0
  121. package/src/module/field-cascade-select.ts +292 -0
  122. package/src/module/field-file-drag.ts +292 -0
  123. package/src/module/field-flatpickr.ts +127 -0
  124. package/src/module/field-modal-select.ts +174 -0
  125. package/src/module/field-modal-tree.ts +27 -0
  126. package/src/module/field-multi-uploader.ts +361 -0
  127. package/src/module/field-repeatable.ts +202 -0
  128. package/src/module/field-single-image-drag.ts +468 -0
  129. package/src/module/form.ts +223 -0
  130. package/src/module/grid.ts +465 -0
  131. package/src/module/http-client.ts +243 -0
  132. package/src/module/iframe-modal.ts +167 -0
  133. package/src/module/list-dependent.ts +321 -0
  134. package/src/module/s3-multipart-uploader.ts +300 -0
  135. package/src/module/s3-uploader.ts +234 -0
  136. package/src/module/show-on.ts +173 -0
  137. package/src/module/tinymce.ts +263 -0
  138. package/src/module/ui-bootstrap5.ts +107 -0
  139. package/src/module/validation.ts +1019 -0
  140. package/src/plugin/index.ts +1 -0
  141. package/src/plugin/php-adapter.ts +65 -0
  142. package/src/polyfill/form-request-submit.ts +31 -0
  143. package/src/polyfill/index.ts +9 -0
  144. package/src/service/animate.ts +58 -0
  145. package/src/service/crypto.ts +27 -0
  146. package/src/service/dom-watcher.ts +62 -0
  147. package/src/service/dom.ts +265 -0
  148. package/src/service/helper.ts +48 -0
  149. package/src/service/index.ts +10 -0
  150. package/src/service/lang.ts +122 -0
  151. package/src/service/loader.ts +152 -0
  152. package/src/service/router.ts +118 -0
  153. package/src/service/ui.ts +497 -0
  154. package/src/service/uri.ts +106 -0
  155. package/src/types/base.ts +9 -0
  156. package/src/types/index.ts +4 -0
  157. package/src/types/modal-tree.ts +12 -0
  158. package/src/types/plugin.ts +6 -0
  159. package/src/types/shims.d.ts +18 -0
  160. package/src/types/ui.ts +6 -0
  161. package/src/unicorn.ts +63 -0
  162. package/src/utilities/arr.ts +25 -0
  163. package/src/utilities/base.ts +9 -0
  164. package/src/utilities/data.ts +48 -0
  165. package/src/utilities/index.ts +5 -0
  166. package/src/utilities/tree.ts +20 -0
  167. package/src/vue/components/ModalTree/ModalTreeApp.vue +175 -0
  168. package/src/vue/components/ModalTree/TreeItem.vue +262 -0
  169. package/src/vue/components/ModalTree/TreeModal.vue +225 -0
  170. package/tests/test.js +4 -0
  171. package/tsconfig.js.json +25 -0
  172. package/tsconfig.json +17 -0
  173. package/vite.assets.config.ts +61 -0
  174. package/vite.config.test.ts +36 -0
  175. package/vite.config.ts +112 -0
@@ -0,0 +1,2202 @@
1
+ const copyProps = (dest, src, exclude = []) => {
2
+ const props = Object.getOwnPropertyDescriptors(src);
3
+ for (let prop of exclude)
4
+ delete props[prop];
5
+ Object.defineProperties(dest, props);
6
+ };
7
+ const protoChain = (obj, currentChain = [obj]) => {
8
+ const proto = Object.getPrototypeOf(obj);
9
+ if (proto === null)
10
+ return currentChain;
11
+ return protoChain(proto, [...currentChain, proto]);
12
+ };
13
+ const nearestCommonProto = (...objs) => {
14
+ if (objs.length === 0)
15
+ return void 0;
16
+ let commonProto = void 0;
17
+ const protoChains = objs.map((obj) => protoChain(obj));
18
+ while (protoChains.every((protoChain2) => protoChain2.length > 0)) {
19
+ const protos = protoChains.map((protoChain2) => protoChain2.pop());
20
+ const potentialCommonProto = protos[0];
21
+ if (protos.every((proto) => proto === potentialCommonProto))
22
+ commonProto = potentialCommonProto;
23
+ else
24
+ break;
25
+ }
26
+ return commonProto;
27
+ };
28
+ const hardMixProtos = (ingredients, constructor, exclude = []) => {
29
+ var _a;
30
+ const base = (_a = nearestCommonProto(...ingredients)) !== null && _a !== void 0 ? _a : Object.prototype;
31
+ const mixedProto = Object.create(base);
32
+ const visitedProtos = protoChain(base);
33
+ for (let prototype of ingredients) {
34
+ let protos = protoChain(prototype);
35
+ for (let i = protos.length - 1; i >= 0; i--) {
36
+ let newProto = protos[i];
37
+ if (visitedProtos.indexOf(newProto) === -1) {
38
+ copyProps(mixedProto, newProto, ["constructor", ...exclude]);
39
+ visitedProtos.push(newProto);
40
+ }
41
+ }
42
+ }
43
+ mixedProto.constructor = constructor;
44
+ return mixedProto;
45
+ };
46
+ const unique = (arr) => arr.filter((e, i) => arr.indexOf(e) == i);
47
+ const mixins = /* @__PURE__ */ new WeakMap();
48
+ const getMixinsForClass = (clazz) => mixins.get(clazz);
49
+ const registerMixins = (mixedClass, constituents) => mixins.set(mixedClass, constituents);
50
+ const mergeObjectsOfDecorators = (o1, o2) => {
51
+ var _a, _b;
52
+ const allKeys = unique([...Object.getOwnPropertyNames(o1), ...Object.getOwnPropertyNames(o2)]);
53
+ const mergedObject = {};
54
+ for (let key of allKeys)
55
+ mergedObject[key] = unique([...(_a = o1 === null || o1 === void 0 ? void 0 : o1[key]) !== null && _a !== void 0 ? _a : [], ...(_b = o2 === null || o2 === void 0 ? void 0 : o2[key]) !== null && _b !== void 0 ? _b : []]);
56
+ return mergedObject;
57
+ };
58
+ const mergePropertyAndMethodDecorators = (d1, d2) => {
59
+ var _a, _b, _c, _d;
60
+ return {
61
+ property: mergeObjectsOfDecorators((_a = d1 === null || d1 === void 0 ? void 0 : d1.property) !== null && _a !== void 0 ? _a : {}, (_b = d2 === null || d2 === void 0 ? void 0 : d2.property) !== null && _b !== void 0 ? _b : {}),
62
+ method: mergeObjectsOfDecorators((_c = d1 === null || d1 === void 0 ? void 0 : d1.method) !== null && _c !== void 0 ? _c : {}, (_d = d2 === null || d2 === void 0 ? void 0 : d2.method) !== null && _d !== void 0 ? _d : {})
63
+ };
64
+ };
65
+ const mergeDecorators = (d1, d2) => {
66
+ var _a, _b, _c, _d, _e, _f;
67
+ return {
68
+ class: unique([...(_a = d1 === null || d1 === void 0 ? void 0 : d1.class) !== null && _a !== void 0 ? _a : [], ...(_b = d2 === null || d2 === void 0 ? void 0 : d2.class) !== null && _b !== void 0 ? _b : []]),
69
+ static: mergePropertyAndMethodDecorators((_c = d1 === null || d1 === void 0 ? void 0 : d1.static) !== null && _c !== void 0 ? _c : {}, (_d = d2 === null || d2 === void 0 ? void 0 : d2.static) !== null && _d !== void 0 ? _d : {}),
70
+ instance: mergePropertyAndMethodDecorators((_e = d1 === null || d1 === void 0 ? void 0 : d1.instance) !== null && _e !== void 0 ? _e : {}, (_f = d2 === null || d2 === void 0 ? void 0 : d2.instance) !== null && _f !== void 0 ? _f : {})
71
+ };
72
+ };
73
+ const decorators = /* @__PURE__ */ new Map();
74
+ const findAllConstituentClasses = (...classes) => {
75
+ var _a;
76
+ const allClasses = /* @__PURE__ */ new Set();
77
+ const frontier = /* @__PURE__ */ new Set([...classes]);
78
+ while (frontier.size > 0) {
79
+ for (let clazz of frontier) {
80
+ const protoChainClasses = protoChain(clazz.prototype).map((proto) => proto.constructor);
81
+ const mixinClasses = (_a = getMixinsForClass(clazz)) !== null && _a !== void 0 ? _a : [];
82
+ const potentiallyNewClasses = [...protoChainClasses, ...mixinClasses];
83
+ const newClasses = potentiallyNewClasses.filter((c) => !allClasses.has(c));
84
+ for (let newClass of newClasses)
85
+ frontier.add(newClass);
86
+ allClasses.add(clazz);
87
+ frontier.delete(clazz);
88
+ }
89
+ }
90
+ return [...allClasses];
91
+ };
92
+ const deepDecoratorSearch = (...classes) => {
93
+ const decoratorsForClassChain = findAllConstituentClasses(...classes).map((clazz) => decorators.get(clazz)).filter((decorators2) => !!decorators2);
94
+ if (decoratorsForClassChain.length == 0)
95
+ return {};
96
+ if (decoratorsForClassChain.length == 1)
97
+ return decoratorsForClassChain[0];
98
+ return decoratorsForClassChain.reduce((d1, d2) => mergeDecorators(d1, d2));
99
+ };
100
+ function Mixin(...constructors) {
101
+ var _a, _b, _c;
102
+ const prototypes = constructors.map((constructor) => constructor.prototype);
103
+ function MixedClass(...args) {
104
+ for (const constructor of constructors)
105
+ copyProps(this, new constructor(...args));
106
+ }
107
+ MixedClass.prototype = hardMixProtos(prototypes, MixedClass);
108
+ Object.setPrototypeOf(
109
+ MixedClass,
110
+ hardMixProtos(constructors, null, ["prototype"])
111
+ );
112
+ let DecoratedMixedClass = MixedClass;
113
+ {
114
+ const classDecorators = deepDecoratorSearch(...constructors);
115
+ for (let decorator of (_a = classDecorators === null || classDecorators === void 0 ? void 0 : classDecorators.class) !== null && _a !== void 0 ? _a : []) {
116
+ const result = decorator(DecoratedMixedClass);
117
+ if (result) {
118
+ DecoratedMixedClass = result;
119
+ }
120
+ }
121
+ applyPropAndMethodDecorators((_b = classDecorators === null || classDecorators === void 0 ? void 0 : classDecorators.static) !== null && _b !== void 0 ? _b : {}, DecoratedMixedClass);
122
+ applyPropAndMethodDecorators((_c = classDecorators === null || classDecorators === void 0 ? void 0 : classDecorators.instance) !== null && _c !== void 0 ? _c : {}, DecoratedMixedClass.prototype);
123
+ }
124
+ registerMixins(DecoratedMixedClass, constructors);
125
+ return DecoratedMixedClass;
126
+ }
127
+ const applyPropAndMethodDecorators = (propAndMethodDecorators, target) => {
128
+ const propDecorators = propAndMethodDecorators.property;
129
+ const methodDecorators = propAndMethodDecorators.method;
130
+ if (propDecorators)
131
+ for (let key in propDecorators)
132
+ for (let decorator of propDecorators[key])
133
+ decorator(target, key);
134
+ if (methodDecorators)
135
+ for (let key in methodDecorators)
136
+ for (let decorator of methodDecorators[key])
137
+ decorator(target, key, Object.getOwnPropertyDescriptor(target, key));
138
+ };
139
+ function isPlainObject(val) {
140
+ return val && typeof val === "object" && !Array.isArray(val);
141
+ }
142
+ function mergeDeep(target, ...sources) {
143
+ let out = isPlainObject(target) ? { ...target } : target;
144
+ for (const source of sources) {
145
+ if (Array.isArray(source)) {
146
+ out = Array.isArray(out) ? out.concat(source) : source;
147
+ continue;
148
+ }
149
+ if (isPlainObject(source)) {
150
+ out = { ...isPlainObject(out) ? out : {} };
151
+ for (const key of Object.keys(source)) {
152
+ out[key] = key in out ? mergeDeep(out[key], source[key]) : source[key];
153
+ }
154
+ continue;
155
+ }
156
+ out = source;
157
+ }
158
+ return out;
159
+ }
160
+ function getData(element, name = void 0) {
161
+ prepareData(element);
162
+ if (name === void 0) {
163
+ return element.__unicorn;
164
+ }
165
+ return element.__unicorn[name];
166
+ }
167
+ function setData(element, name, value) {
168
+ prepareData(element);
169
+ element.__unicorn[name] = value;
170
+ }
171
+ function defData(element, name, defCallback) {
172
+ prepareData(element);
173
+ element.__unicorn[name] = element.__unicorn[name] || defCallback(element);
174
+ return element.__unicorn[name];
175
+ }
176
+ function removeData$1(element, name) {
177
+ prepareData(element);
178
+ const v = element.__unicorn[name];
179
+ delete element.__unicorn[name];
180
+ return v;
181
+ }
182
+ function prepareData(element) {
183
+ if (!element) {
184
+ return element;
185
+ }
186
+ element.__unicorn = element.__unicorn || {};
187
+ return element;
188
+ }
189
+ function domready(callback) {
190
+ let promise = new Promise((resolve) => {
191
+ if (document.readyState === "complete" || document.readyState === "interactive") {
192
+ setTimeout(resolve, 0);
193
+ } else {
194
+ document.addEventListener("DOMContentLoaded", () => resolve());
195
+ }
196
+ });
197
+ if (callback) {
198
+ promise = promise.then(callback);
199
+ }
200
+ return promise;
201
+ }
202
+ function selectOne(ele) {
203
+ let r;
204
+ if (typeof ele === "string") {
205
+ r = document.querySelector(ele);
206
+ } else {
207
+ r = ele;
208
+ }
209
+ if (!r) {
210
+ return r;
211
+ }
212
+ return r;
213
+ }
214
+ function selectAll(ele, callback = void 0) {
215
+ if (typeof ele === "string") {
216
+ ele = document.querySelectorAll(ele);
217
+ }
218
+ const resultSet = [].slice.call(ele);
219
+ if (callback) {
220
+ return resultSet.map((el) => callback(el) || el);
221
+ }
222
+ return resultSet;
223
+ }
224
+ function getBoundedInstance(selector, name, callback = () => null) {
225
+ const element = typeof selector === "string" ? document.querySelector(selector) : selector;
226
+ if (!element) {
227
+ return null;
228
+ }
229
+ return defData(element, name, callback);
230
+ }
231
+ function getBoundedInstanceList(selector, name, callback = () => null) {
232
+ const items = typeof selector === "string" ? document.querySelectorAll(selector) : selector;
233
+ return Array.from(items).map((ele) => getBoundedInstance(ele, name, callback));
234
+ }
235
+ function module(ele, name, callback = () => null) {
236
+ if (typeof ele === "string") {
237
+ return getBoundedInstanceList(ele, name, callback);
238
+ }
239
+ if (ele instanceof HTMLElement) {
240
+ return getBoundedInstance(ele, name, callback);
241
+ }
242
+ return getBoundedInstanceList(ele, name, callback);
243
+ }
244
+ function h(element, attrs = {}, content = void 0) {
245
+ const ele = document.createElement(element);
246
+ for (let i in attrs) {
247
+ const v = attrs[i];
248
+ ele.setAttribute(i, v);
249
+ }
250
+ if (content !== null) {
251
+ ele.innerHTML = content;
252
+ }
253
+ return ele;
254
+ }
255
+ function html(html2) {
256
+ const div = document.createElement("div");
257
+ div.innerHTML = html2;
258
+ return div.children[0];
259
+ }
260
+ function delegate(wrapper, selector, eventName, callback) {
261
+ if (typeof selector === "undefined" || selector === "") {
262
+ throw new Error("The provided selector is empty.");
263
+ }
264
+ if (typeof callback === "undefined" || typeof callback !== "function") {
265
+ throw new Error("Please specify an callback.");
266
+ }
267
+ const delegationSelectorsMap = {};
268
+ const wrapperElement = selectOne(wrapper);
269
+ wrapperElement?.addEventListener(eventName, function(event) {
270
+ let element = event.target;
271
+ let forceBreak = false;
272
+ while (element && element !== wrapperElement) {
273
+ for (const selector2 in delegationSelectorsMap) {
274
+ if (element.matches(selector2)) {
275
+ event.stopPropagation = function() {
276
+ forceBreak = true;
277
+ };
278
+ Object.defineProperty(
279
+ event,
280
+ "currentTarget",
281
+ {
282
+ get() {
283
+ return element;
284
+ }
285
+ }
286
+ );
287
+ const callbackList = delegationSelectorsMap[selector2];
288
+ callbackList.forEach(function(callback2) {
289
+ callback2(event);
290
+ });
291
+ }
292
+ }
293
+ if (forceBreak) {
294
+ break;
295
+ }
296
+ element = element.parentElement;
297
+ }
298
+ });
299
+ if (!delegationSelectorsMap[selector]) {
300
+ delegationSelectorsMap[selector] = [callback];
301
+ } else {
302
+ delegationSelectorsMap[selector].push(callback);
303
+ }
304
+ return function unsubscribe() {
305
+ if (!delegationSelectorsMap[selector]) {
306
+ return;
307
+ }
308
+ if (delegationSelectorsMap[selector].length >= 2) {
309
+ delegationSelectorsMap[selector] = delegationSelectorsMap[selector].filter((cb) => cb !== callback);
310
+ } else {
311
+ delete delegationSelectorsMap[selector];
312
+ }
313
+ };
314
+ }
315
+ function injectCssToDocument(doc, ...css) {
316
+ if (!(doc instanceof Document)) {
317
+ css.push(doc);
318
+ doc = document;
319
+ }
320
+ const styles = css.map((css2) => {
321
+ if (typeof css2 === "string") {
322
+ const style = new CSSStyleSheet();
323
+ style.replaceSync(css2);
324
+ return style;
325
+ }
326
+ return css2;
327
+ });
328
+ doc.adoptedStyleSheets = [...doc.adoptedStyleSheets, ...styles];
329
+ return styles;
330
+ }
331
+ function animateTo(element, styles, options = {}) {
332
+ element = selectOne(element);
333
+ const currentStyles = window.getComputedStyle(element);
334
+ const transitions = {};
335
+ for (const name in styles) {
336
+ const value = styles[name];
337
+ transitions[name] = Array.isArray(value) ? value : [
338
+ currentStyles.getPropertyValue(name),
339
+ value
340
+ ];
341
+ }
342
+ if (typeof options === "number") {
343
+ options = { duration: options };
344
+ }
345
+ options = Object.assign(
346
+ {
347
+ duration: 400,
348
+ easing: "linear",
349
+ fill: "both"
350
+ },
351
+ options
352
+ );
353
+ const animation = element.animate(
354
+ transitions,
355
+ options
356
+ );
357
+ animation.addEventListener("finish", () => {
358
+ for (const name in styles) {
359
+ const value = styles[name];
360
+ element.style.setProperty(
361
+ name,
362
+ Array.isArray(value) ? value[value.length - 1] : value
363
+ );
364
+ }
365
+ animation.cancel();
366
+ });
367
+ return animation;
368
+ }
369
+ const _AlertAdapter = class _AlertAdapter {
370
+ };
371
+ _AlertAdapter.alert = async (title) => window.alert(title);
372
+ _AlertAdapter.confirm = async (title) => {
373
+ return new Promise((resolve) => {
374
+ const v = confirm(title);
375
+ resolve(v);
376
+ });
377
+ };
378
+ _AlertAdapter.deleteConfirm = async (title) => _AlertAdapter.confirm(title);
379
+ _AlertAdapter.confirmText = () => "確認";
380
+ _AlertAdapter.cancelText = () => "取消";
381
+ _AlertAdapter.deleteText = () => "刪除";
382
+ let AlertAdapter = _AlertAdapter;
383
+ async function simpleAlert(title, text = "", icon = "info", extra) {
384
+ return AlertAdapter.alert(title, text, icon, extra);
385
+ }
386
+ async function simpleConfirm(title, text = "", icon = "info", extra) {
387
+ return AlertAdapter.confirm(title, text, icon, extra);
388
+ }
389
+ async function deleteConfirm(title, text = "", icon = "info", extra) {
390
+ return AlertAdapter.deleteConfirm(title, text, icon, extra);
391
+ }
392
+ function isNode() {
393
+ return typeof window === "undefined";
394
+ }
395
+ function uid(prefix = "", timebase = false) {
396
+ if (timebase) {
397
+ const start = performance?.timeOrigin ? Math.round(performance.timeOrigin) : performance.timing.navigationStart;
398
+ const time = start * 1e5 + performance.now() * 100;
399
+ return prefix + time.toString(12) + randomBytesString(4);
400
+ }
401
+ return prefix + randomBytesString(12);
402
+ }
403
+ function tid(prefix = "") {
404
+ return uid(prefix, true);
405
+ }
406
+ function randomBytesString(size = 12) {
407
+ if (!isNode() && !globalThis.crypto) {
408
+ return String(Math.floor(Math.random() * size ** 10));
409
+ }
410
+ return Array.from(randomBytes(size)).map((x) => x.toString(16).padStart(2, "0")).join("");
411
+ }
412
+ function randomBytes(size = 12) {
413
+ const arr = new Uint8Array(size);
414
+ globalThis.crypto.getRandomValues(arr);
415
+ return arr;
416
+ }
417
+ class TaskQueue {
418
+ constructor(maxRunning = 1) {
419
+ this.maxRunning = maxRunning;
420
+ this.items = [];
421
+ this.currentRunning = 0;
422
+ this.running = false;
423
+ this.observers = [];
424
+ }
425
+ push(callback) {
426
+ const p = new Promise((resolve, reject) => {
427
+ this.items.push(() => {
428
+ return Promise.resolve(callback()).then(resolve);
429
+ });
430
+ });
431
+ this.run();
432
+ return p;
433
+ }
434
+ run() {
435
+ if (!this.running) {
436
+ this.running = true;
437
+ }
438
+ this.pop();
439
+ }
440
+ async pop() {
441
+ const callback = this.items.shift();
442
+ if (!callback) {
443
+ this.running = false;
444
+ return Promise.resolve();
445
+ }
446
+ if (this.currentRunning >= this.maxRunning) {
447
+ this.items.unshift(callback);
448
+ return Promise.resolve();
449
+ }
450
+ this.currentRunning++;
451
+ this.notice();
452
+ try {
453
+ return await callback();
454
+ } catch (e) {
455
+ throw e;
456
+ } finally {
457
+ this.endPop();
458
+ }
459
+ }
460
+ endPop() {
461
+ this.currentRunning--;
462
+ this.notice();
463
+ this.pop();
464
+ }
465
+ clear() {
466
+ this.items = [];
467
+ this.notice();
468
+ return this;
469
+ }
470
+ isEmpty() {
471
+ return this.items.length === 0;
472
+ }
473
+ get length() {
474
+ return this.items.length;
475
+ }
476
+ peek() {
477
+ return this.items;
478
+ }
479
+ observe(handler, options = {}) {
480
+ this.observers.push({
481
+ handler,
482
+ once: options.once || false
483
+ });
484
+ return () => {
485
+ this.off(handler);
486
+ };
487
+ }
488
+ once(handler, options = {}) {
489
+ options.once = true;
490
+ return this.observe(handler, options);
491
+ }
492
+ onEnd(callback, options = {}) {
493
+ return this.observe((queue2, length, running) => {
494
+ if (length === 0 && running === 0) {
495
+ callback(queue2, length, running);
496
+ }
497
+ }, options);
498
+ }
499
+ notice() {
500
+ this.observers.forEach((observer) => {
501
+ observer.handler(this, this.length, this.currentRunning);
502
+ });
503
+ this.observers = this.observers.filter((observer) => !observer.once);
504
+ return this;
505
+ }
506
+ off(callback) {
507
+ if (callback == null) {
508
+ this.observers = [];
509
+ return this;
510
+ }
511
+ this.observers = this.observers.filter((observer) => observer.handler !== callback);
512
+ return this;
513
+ }
514
+ }
515
+ function queue(maxRunning = 1) {
516
+ return new TaskQueue(maxRunning);
517
+ }
518
+ class Stack {
519
+ constructor(store = []) {
520
+ this.store = store;
521
+ this.observers = [];
522
+ }
523
+ push(value) {
524
+ const r = this.store.push(value ?? true);
525
+ this.notice();
526
+ return r;
527
+ }
528
+ pop() {
529
+ const r = this.store.pop();
530
+ this.notice();
531
+ return r;
532
+ }
533
+ clear() {
534
+ this.store = [];
535
+ this.notice();
536
+ return this;
537
+ }
538
+ isEmpty() {
539
+ return this.store.length === 0;
540
+ }
541
+ get length() {
542
+ return this.store.length;
543
+ }
544
+ peek() {
545
+ return this.store;
546
+ }
547
+ observe(handler) {
548
+ this.observers.push({
549
+ handler,
550
+ once: false
551
+ });
552
+ return () => {
553
+ this.off(handler);
554
+ };
555
+ }
556
+ once(handler) {
557
+ this.observers.push({
558
+ handler,
559
+ once: true
560
+ });
561
+ return () => {
562
+ this.off(handler);
563
+ };
564
+ }
565
+ notice() {
566
+ this.observers.forEach((observer) => {
567
+ observer.handler(this, this.length);
568
+ });
569
+ this.observers = this.observers.filter((observer) => observer.once !== true);
570
+ return this;
571
+ }
572
+ off(callback) {
573
+ this.observers = this.observers.filter((observer) => observer.handler !== callback);
574
+ return this;
575
+ }
576
+ }
577
+ function stack(store = []) {
578
+ return new Stack(store);
579
+ }
580
+ function sleep(time) {
581
+ return new Promise((resolve) => {
582
+ setTimeout(resolve, time);
583
+ });
584
+ }
585
+ function base64UrlEncode(string) {
586
+ return btoa(String(string)).replace(/\+/, "-").replace(new RegExp("\\/"), "_").replace(/=+$/, "");
587
+ }
588
+ function base64UrlDecode(string) {
589
+ return atob(
590
+ String(string).replace(/-/, "+").replace(/_/, "/")
591
+ );
592
+ }
593
+ let globalSerial = 1;
594
+ function serial() {
595
+ return globalSerial++;
596
+ }
597
+ function watchAttributes(el, callback) {
598
+ return new AttributeMutationObserver(el, callback);
599
+ }
600
+ class AttributeMutationObserver {
601
+ constructor(element, callback) {
602
+ this.element = element;
603
+ this.callback = callback;
604
+ this.element = element;
605
+ this.observer = new MutationObserver((mutations) => {
606
+ for (const mutation of mutations) {
607
+ if (mutation.type === "attributes") {
608
+ const attrName = mutation.attributeName;
609
+ const target = mutation.target;
610
+ const value = target.getAttribute(attrName);
611
+ this.callback?.(
612
+ target,
613
+ attrName,
614
+ value,
615
+ mutation.oldValue
616
+ );
617
+ if (this.watches[attrName]) {
618
+ for (const watch of this.watches[attrName]) {
619
+ watch(target, value, mutation.oldValue);
620
+ }
621
+ }
622
+ }
623
+ }
624
+ });
625
+ this.observe();
626
+ }
627
+ observer;
628
+ watches = {};
629
+ watch(name, callback) {
630
+ this.watches[name] ??= [];
631
+ this.watches[name].push(callback);
632
+ return () => {
633
+ this.watches[name] = this.watches[name].filter((fn) => fn !== callback);
634
+ };
635
+ }
636
+ observe() {
637
+ this.observer.observe(this.element, {
638
+ attributes: true,
639
+ attributeOldValue: true
640
+ });
641
+ }
642
+ disconnect() {
643
+ this.observer.disconnect();
644
+ }
645
+ }
646
+ function forceArray(item) {
647
+ if (Array.isArray(item)) {
648
+ return item;
649
+ } else {
650
+ return [item];
651
+ }
652
+ }
653
+ function debounce(handler, wait2 = 1) {
654
+ let timer, result;
655
+ return function(...args) {
656
+ clearTimeout(timer);
657
+ timer = setTimeout(() => result = handler.call(this, ...args), wait2);
658
+ return result;
659
+ };
660
+ }
661
+ function throttle(handler, wait2 = 1) {
662
+ return function(...args) {
663
+ {
664
+ return handler.call(this, ...args);
665
+ }
666
+ };
667
+ }
668
+ function isDebug() {
669
+ return Boolean(data("windwalker.debug"));
670
+ }
671
+ function nextTick(callback) {
672
+ return Promise.resolve().then(callback ?? (() => null));
673
+ }
674
+ function wait(...promisee) {
675
+ return Promise.all(promisee);
676
+ }
677
+ var sprintf = {};
678
+ var hasRequiredSprintf;
679
+ function requireSprintf() {
680
+ if (hasRequiredSprintf) return sprintf;
681
+ hasRequiredSprintf = 1;
682
+ (function(exports) {
683
+ !(function() {
684
+ var re = {
685
+ not_type: /[^T]/,
686
+ not_primitive: /[^v]/,
687
+ number: /[diefg]/,
688
+ numeric_arg: /[bcdiefguxX]/,
689
+ json: /[j]/,
690
+ text: /^[^\x25]+/,
691
+ modulo: /^\x25{2}/,
692
+ placeholder: /^\x25(?:([1-9]\d*)\$|\(([^)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-gijostTuvxX])/,
693
+ key: /^([a-z_][a-z_\d]*)/i,
694
+ key_access: /^\.([a-z_][a-z_\d]*)/i,
695
+ index_access: /^\[(\d+)\]/,
696
+ sign: /^[+-]/
697
+ };
698
+ function sprintf2(key) {
699
+ return sprintf_format(sprintf_parse(key), arguments);
700
+ }
701
+ function vsprintf(fmt, argv) {
702
+ return sprintf2.apply(null, [fmt].concat(argv || []));
703
+ }
704
+ function sprintf_format(parse_tree, argv) {
705
+ var cursor = 1, tree_length = parse_tree.length, arg, output = "", i, k, ph, pad, pad_character, pad_length, is_positive, sign;
706
+ for (i = 0; i < tree_length; i++) {
707
+ if (typeof parse_tree[i] === "string") {
708
+ output += parse_tree[i];
709
+ } else if (typeof parse_tree[i] === "object") {
710
+ ph = parse_tree[i];
711
+ if (ph.keys) {
712
+ arg = argv[cursor];
713
+ for (k = 0; k < ph.keys.length; k++) {
714
+ if (arg == void 0) {
715
+ throw new Error(sprintf2('[sprintf] Cannot access property "%s" of undefined value "%s"', ph.keys[k], ph.keys[k - 1]));
716
+ }
717
+ arg = arg[ph.keys[k]];
718
+ }
719
+ } else if (ph.param_no) {
720
+ arg = argv[ph.param_no];
721
+ } else {
722
+ arg = argv[cursor++];
723
+ }
724
+ if (re.not_type.test(ph.type) && re.not_primitive.test(ph.type) && arg instanceof Function) {
725
+ arg = arg();
726
+ }
727
+ if (re.numeric_arg.test(ph.type) && (typeof arg !== "number" && isNaN(arg))) {
728
+ throw new TypeError(sprintf2("[sprintf] expecting number but found %T", arg));
729
+ }
730
+ if (re.number.test(ph.type)) {
731
+ is_positive = arg >= 0;
732
+ }
733
+ switch (ph.type) {
734
+ case "b":
735
+ arg = parseInt(arg, 10).toString(2);
736
+ break;
737
+ case "c":
738
+ arg = String.fromCharCode(parseInt(arg, 10));
739
+ break;
740
+ case "d":
741
+ case "i":
742
+ arg = parseInt(arg, 10);
743
+ break;
744
+ case "j":
745
+ arg = JSON.stringify(arg, null, ph.width ? parseInt(ph.width) : 0);
746
+ break;
747
+ case "e":
748
+ arg = ph.precision ? parseFloat(arg).toExponential(ph.precision) : parseFloat(arg).toExponential();
749
+ break;
750
+ case "f":
751
+ arg = ph.precision ? parseFloat(arg).toFixed(ph.precision) : parseFloat(arg);
752
+ break;
753
+ case "g":
754
+ arg = ph.precision ? String(Number(arg.toPrecision(ph.precision))) : parseFloat(arg);
755
+ break;
756
+ case "o":
757
+ arg = (parseInt(arg, 10) >>> 0).toString(8);
758
+ break;
759
+ case "s":
760
+ arg = String(arg);
761
+ arg = ph.precision ? arg.substring(0, ph.precision) : arg;
762
+ break;
763
+ case "t":
764
+ arg = String(!!arg);
765
+ arg = ph.precision ? arg.substring(0, ph.precision) : arg;
766
+ break;
767
+ case "T":
768
+ arg = Object.prototype.toString.call(arg).slice(8, -1).toLowerCase();
769
+ arg = ph.precision ? arg.substring(0, ph.precision) : arg;
770
+ break;
771
+ case "u":
772
+ arg = parseInt(arg, 10) >>> 0;
773
+ break;
774
+ case "v":
775
+ arg = arg.valueOf();
776
+ arg = ph.precision ? arg.substring(0, ph.precision) : arg;
777
+ break;
778
+ case "x":
779
+ arg = (parseInt(arg, 10) >>> 0).toString(16);
780
+ break;
781
+ case "X":
782
+ arg = (parseInt(arg, 10) >>> 0).toString(16).toUpperCase();
783
+ break;
784
+ }
785
+ if (re.json.test(ph.type)) {
786
+ output += arg;
787
+ } else {
788
+ if (re.number.test(ph.type) && (!is_positive || ph.sign)) {
789
+ sign = is_positive ? "+" : "-";
790
+ arg = arg.toString().replace(re.sign, "");
791
+ } else {
792
+ sign = "";
793
+ }
794
+ pad_character = ph.pad_char ? ph.pad_char === "0" ? "0" : ph.pad_char.charAt(1) : " ";
795
+ pad_length = ph.width - (sign + arg).length;
796
+ pad = ph.width ? pad_length > 0 ? pad_character.repeat(pad_length) : "" : "";
797
+ output += ph.align ? sign + arg + pad : pad_character === "0" ? sign + pad + arg : pad + sign + arg;
798
+ }
799
+ }
800
+ }
801
+ return output;
802
+ }
803
+ var sprintf_cache = /* @__PURE__ */ Object.create(null);
804
+ function sprintf_parse(fmt) {
805
+ if (sprintf_cache[fmt]) {
806
+ return sprintf_cache[fmt];
807
+ }
808
+ var _fmt = fmt, match, parse_tree = [], arg_names = 0;
809
+ while (_fmt) {
810
+ if ((match = re.text.exec(_fmt)) !== null) {
811
+ parse_tree.push(match[0]);
812
+ } else if ((match = re.modulo.exec(_fmt)) !== null) {
813
+ parse_tree.push("%");
814
+ } else if ((match = re.placeholder.exec(_fmt)) !== null) {
815
+ if (match[2]) {
816
+ arg_names |= 1;
817
+ var field_list = [], replacement_field = match[2], field_match = [];
818
+ if ((field_match = re.key.exec(replacement_field)) !== null) {
819
+ field_list.push(field_match[1]);
820
+ while ((replacement_field = replacement_field.substring(field_match[0].length)) !== "") {
821
+ if ((field_match = re.key_access.exec(replacement_field)) !== null) {
822
+ field_list.push(field_match[1]);
823
+ } else if ((field_match = re.index_access.exec(replacement_field)) !== null) {
824
+ field_list.push(field_match[1]);
825
+ } else {
826
+ throw new SyntaxError("[sprintf] failed to parse named argument key");
827
+ }
828
+ }
829
+ } else {
830
+ throw new SyntaxError("[sprintf] failed to parse named argument key");
831
+ }
832
+ match[2] = field_list;
833
+ } else {
834
+ arg_names |= 2;
835
+ }
836
+ if (arg_names === 3) {
837
+ throw new Error("[sprintf] mixing positional and named placeholders is not (yet) supported");
838
+ }
839
+ parse_tree.push(
840
+ {
841
+ placeholder: match[0],
842
+ param_no: match[1],
843
+ keys: match[2],
844
+ sign: match[3],
845
+ pad_char: match[4],
846
+ align: match[5],
847
+ width: match[6],
848
+ precision: match[7],
849
+ type: match[8]
850
+ }
851
+ );
852
+ } else {
853
+ throw new SyntaxError("[sprintf] unexpected placeholder");
854
+ }
855
+ _fmt = _fmt.substring(match[0].length);
856
+ }
857
+ return sprintf_cache[fmt] = parse_tree;
858
+ }
859
+ {
860
+ exports["sprintf"] = sprintf2;
861
+ exports["vsprintf"] = vsprintf;
862
+ }
863
+ if (typeof window !== "undefined") {
864
+ window["sprintf"] = sprintf2;
865
+ window["vsprintf"] = vsprintf;
866
+ }
867
+ })();
868
+ })(sprintf);
869
+ return sprintf;
870
+ }
871
+ var sprintfExports = /* @__PURE__ */ requireSprintf();
872
+ let lang;
873
+ function useLang() {
874
+ return lang ??= new UnicornLang();
875
+ }
876
+ function trans(id, ...args) {
877
+ return useLang().trans(id, ...args);
878
+ }
879
+ function __(id, ...args) {
880
+ return trans(id, ...args);
881
+ }
882
+ class UnicornLang {
883
+ /**
884
+ * Translate a string.
885
+ */
886
+ trans(id, ...args) {
887
+ const key = this.normalize(id);
888
+ let translated = this.get(key) || "";
889
+ translated = this.replace(translated, args);
890
+ return translated !== "" ? translated : this.wrapDebug(id, false);
891
+ }
892
+ replace(str, args) {
893
+ let replacements = {};
894
+ let values = [];
895
+ for (const arg of args) {
896
+ if (typeof arg === "object") {
897
+ replacements = { ...replacements, ...arg };
898
+ } else {
899
+ values.push(arg);
900
+ }
901
+ }
902
+ if (values.length) {
903
+ str = sprintfExports.vsprintf(str, values);
904
+ }
905
+ if (Object.values(replacements).length) {
906
+ for (const key in replacements) {
907
+ let value = replacements[key];
908
+ if (typeof value === "function") {
909
+ value = value();
910
+ }
911
+ str = str.replace(new RegExp(":" + key, "g"), String(value));
912
+ }
913
+ }
914
+ return str;
915
+ }
916
+ /**
917
+ * Find text.
918
+ */
919
+ get(id) {
920
+ const strings = this.getStrings();
921
+ if (strings[id]) {
922
+ return strings[id];
923
+ }
924
+ return null;
925
+ }
926
+ /**
927
+ * Has language key.
928
+ */
929
+ has(key) {
930
+ const strings = this.getStrings();
931
+ return strings[key] !== void 0;
932
+ }
933
+ /**
934
+ * Add language key.
935
+ */
936
+ add(key, value) {
937
+ const strings = this.getStrings();
938
+ strings[this.normalize(key)] = value;
939
+ data("unicorn.languages", strings);
940
+ return this;
941
+ }
942
+ /**
943
+ * Replace all symbols to dot(.).
944
+ */
945
+ normalize(text) {
946
+ return text.replace(/[^A-Z0-9]+/ig, ".");
947
+ }
948
+ wrapDebug(text, success) {
949
+ if (isDebug()) {
950
+ if (success) {
951
+ return "**" + text + "**";
952
+ }
953
+ return "??" + text + "??";
954
+ }
955
+ return text;
956
+ }
957
+ getStrings() {
958
+ return data("unicorn.languages") || {};
959
+ }
960
+ }
961
+ function useScriptImport(src, attrs = {}) {
962
+ const script = document.createElement("script");
963
+ script.src = src;
964
+ for (const key in attrs) {
965
+ script.setAttribute(key, attrs[key]);
966
+ }
967
+ return new Promise((resolve, reject) => {
968
+ script.onload = () => {
969
+ resolve();
970
+ document.body.removeChild(script);
971
+ };
972
+ script.onerror = (e) => {
973
+ reject(e);
974
+ document.body.removeChild(script);
975
+ };
976
+ document.body.appendChild(script);
977
+ });
978
+ }
979
+ function doImport(src) {
980
+ return import(
981
+ /* @vite-ignore */
982
+ src
983
+ );
984
+ }
985
+ async function useImport(...src) {
986
+ if (src.length === 1) {
987
+ return doImport(src[0]);
988
+ }
989
+ const promises = [];
990
+ src.forEach((link) => {
991
+ promises.push(
992
+ link instanceof Promise ? link : doImport(link)
993
+ );
994
+ });
995
+ return Promise.all(promises);
996
+ }
997
+ async function useSeriesImport(...src) {
998
+ const modules = [];
999
+ for (const source of src) {
1000
+ if (Array.isArray(source)) {
1001
+ const m2 = await useImport(...source);
1002
+ modules.push(m2);
1003
+ continue;
1004
+ }
1005
+ const m = await useImport(source);
1006
+ modules.push(m);
1007
+ }
1008
+ return modules;
1009
+ }
1010
+ async function useCssIncludes(...hrefs) {
1011
+ const promises = hrefs.map((href) => {
1012
+ href = resolveUrl(href);
1013
+ return new Promise((resolve, reject) => {
1014
+ const link = document.createElement("link");
1015
+ link.rel = "stylesheet";
1016
+ link.href = href;
1017
+ link.onload = () => resolve();
1018
+ link.onerror = (e) => reject(e);
1019
+ document.head.appendChild(link);
1020
+ });
1021
+ });
1022
+ return Promise.all(promises);
1023
+ }
1024
+ const importedSheets = {};
1025
+ async function useCssImport(...hrefs) {
1026
+ const modules = await Promise.all(
1027
+ hrefs.map((href) => {
1028
+ if (!importedSheets[href]) {
1029
+ importedSheets[href] = simulateCssImport(href);
1030
+ }
1031
+ return importedSheets[href];
1032
+ })
1033
+ );
1034
+ const styles = modules.map((module2) => module2.default);
1035
+ return injectCssToDocument(...styles);
1036
+ }
1037
+ async function simulateCssImport(href) {
1038
+ href = resolveUrl(href);
1039
+ const response = await fetch(href);
1040
+ if (!response.ok) {
1041
+ throw new Error(`Failed to load CSS: ${href}`);
1042
+ }
1043
+ const cssText = await response.text();
1044
+ const sheet = new CSSStyleSheet();
1045
+ await sheet.replace(cssText);
1046
+ return { default: sheet };
1047
+ }
1048
+ let importMap;
1049
+ function parseImportMap() {
1050
+ const importMapScript = document.querySelector('script[type="importmap"]');
1051
+ if (importMapScript) {
1052
+ try {
1053
+ return JSON.parse(importMapScript.textContent || "{}").imports || {};
1054
+ } catch (e) {
1055
+ console.error("Failed to parse import map:", e);
1056
+ }
1057
+ }
1058
+ return {};
1059
+ }
1060
+ function resolveUrl(specifier) {
1061
+ importMap ??= parseImportMap();
1062
+ for (const [prefix, target] of Object.entries(importMap)) {
1063
+ if (specifier === prefix) {
1064
+ return target;
1065
+ }
1066
+ }
1067
+ for (const [prefix, target] of Object.entries(importMap)) {
1068
+ if (specifier.startsWith(prefix)) {
1069
+ return specifier.replace(prefix, target);
1070
+ }
1071
+ }
1072
+ return specifier;
1073
+ }
1074
+ async function useCheckboxesMultiSelect(selector, options = {}) {
1075
+ const m = await import("./checkboxes-multi-select.js");
1076
+ if (selector) {
1077
+ m.CheckboxesMultiSelect.handle(selector, options);
1078
+ }
1079
+ return m;
1080
+ }
1081
+ async function useFieldCascadeSelect() {
1082
+ const module2 = await import("./field-cascade-select.js");
1083
+ await module2.ready;
1084
+ return module2;
1085
+ }
1086
+ async function useFieldFileDrag() {
1087
+ const module2 = await import("./field-file-drag.js");
1088
+ await module2.ready;
1089
+ return module2;
1090
+ }
1091
+ function useFieldFlatpickr() {
1092
+ return import("./field-flatpickr.js");
1093
+ }
1094
+ function useFieldModalSelect() {
1095
+ return import("./field-modal-select.js");
1096
+ }
1097
+ function useFieldModalTree() {
1098
+ import("./field-modal-tree.js");
1099
+ }
1100
+ async function useFieldRepeatable() {
1101
+ const module2 = await import("./field-repeatable.js");
1102
+ await module2.ready;
1103
+ return module2;
1104
+ }
1105
+ function useFieldSingleImageDrag() {
1106
+ return import("./field-single-image-drag.js");
1107
+ }
1108
+ let formElement;
1109
+ async function useFormAsync(ele, options = {}) {
1110
+ const { UnicornFormElement } = await import("./form.js");
1111
+ formElement ??= UnicornFormElement;
1112
+ return useForm(ele, options);
1113
+ }
1114
+ function useForm(ele, options = {}) {
1115
+ if (ele == null) {
1116
+ return new formElement(void 0, void 0, options);
1117
+ }
1118
+ const selector = typeof ele === "string" ? ele : void 0;
1119
+ const el = selectOne(ele);
1120
+ if (!el) {
1121
+ throw new Error(`Form element of: ${selector} not found.`);
1122
+ }
1123
+ return module(
1124
+ el,
1125
+ "unicorn.form",
1126
+ () => new formElement(selector, el, options)
1127
+ );
1128
+ }
1129
+ async function useFormComponent(ele, options = {}) {
1130
+ const form = await useFormAsync(ele, options);
1131
+ await form?.initComponent();
1132
+ return form;
1133
+ }
1134
+ let gridElement;
1135
+ async function useGridAsync(ele, options = {}) {
1136
+ await useFormAsync();
1137
+ const { UnicornGridElement } = await import("./grid.js");
1138
+ gridElement ??= UnicornGridElement;
1139
+ if (!ele) {
1140
+ return null;
1141
+ }
1142
+ return useGrid(ele, options);
1143
+ }
1144
+ function useGrid(ele, options = {}) {
1145
+ const selector = typeof ele === "string" ? ele : "";
1146
+ const element = selectOne(ele);
1147
+ if (!element) {
1148
+ throw new Error("Element is empty");
1149
+ }
1150
+ const form = useForm(selector || element);
1151
+ if (!form) {
1152
+ throw new Error("UnicornGrid is depends on UnicornForm");
1153
+ }
1154
+ return module(
1155
+ element,
1156
+ "grid.plugin",
1157
+ () => new gridElement(selector, element, form, options)
1158
+ );
1159
+ }
1160
+ async function useGridComponent(ele, options = {}) {
1161
+ const grid = await useGridAsync(ele, options);
1162
+ await grid?.initComponent();
1163
+ return grid;
1164
+ }
1165
+ async function useHttpClient(config) {
1166
+ const { createHttpClient } = await import("./http-client.js");
1167
+ return createHttpClient(config);
1168
+ }
1169
+ async function useIframeModal() {
1170
+ const module2 = await import("./iframe-modal.js");
1171
+ await module2.ready;
1172
+ return module2;
1173
+ }
1174
+ async function useListDependent(element, dependent, options = {}) {
1175
+ const module2 = await import("./list-dependent.js");
1176
+ await module2.ready;
1177
+ if (element) {
1178
+ const { ListDependent } = module2;
1179
+ return ListDependent.handle(element, dependent ?? void 0, options);
1180
+ }
1181
+ return module2;
1182
+ }
1183
+ const queues = {};
1184
+ function useQueue(name = "default", maxRunning = 1) {
1185
+ return queues[name] ??= createQueue(maxRunning);
1186
+ }
1187
+ function createQueue(maxRunning = 1) {
1188
+ return queue(maxRunning);
1189
+ }
1190
+ async function useS3Uploader(name, options = {}) {
1191
+ const module2 = await import("./s3-uploader.js");
1192
+ if (!name) {
1193
+ return module2;
1194
+ }
1195
+ const { get } = module2;
1196
+ return get(name, options);
1197
+ }
1198
+ async function useS3MultipartUploader(options) {
1199
+ const module2 = await import("./s3-multipart-uploader.js");
1200
+ if (options != null) {
1201
+ return new module2.S3MultipartUploader(options);
1202
+ }
1203
+ return module2;
1204
+ }
1205
+ async function useShowOn() {
1206
+ const module2 = await import("./show-on.js");
1207
+ await module2.ready;
1208
+ return module2;
1209
+ }
1210
+ const stacks = {};
1211
+ function useStack(name = "default", store = []) {
1212
+ return stacks[name] ??= createStack(store);
1213
+ }
1214
+ function createStack(store = []) {
1215
+ return stack(store);
1216
+ }
1217
+ async function useTomSelect(selector, options = {}, theme = "bootstrap5") {
1218
+ const [m] = await wait(
1219
+ useImport("@vendor/tom-select/dist/js/tom-select.complete.min.js"),
1220
+ useCssImport(`@vendor/tom-select/dist/css/tom-select.${theme}.min.css`)
1221
+ );
1222
+ if (selector) {
1223
+ module(
1224
+ selector,
1225
+ "tom.select",
1226
+ (ele) => {
1227
+ options = mergeDeep({
1228
+ allowEmptyOption: true,
1229
+ maxOptions: null,
1230
+ plugins: {
1231
+ caret_position: {},
1232
+ clear_button: {}
1233
+ }
1234
+ }, options);
1235
+ if (ele.multiple) {
1236
+ options.plugins.remove_button = {};
1237
+ } else {
1238
+ options.plugins.dropdown_input = {};
1239
+ }
1240
+ class UnicornTomSelect extends TomSelect {
1241
+ syncOptionsWithoutKeepSelected() {
1242
+ const oldValue = ele.value;
1243
+ this.clear();
1244
+ this.clearOptions();
1245
+ this.sync();
1246
+ if (ele.value !== oldValue) {
1247
+ this.setValue(
1248
+ ele.querySelector(`option[value="${oldValue}"]`)?.value ?? ele.querySelector("option")?.value ?? "",
1249
+ true
1250
+ );
1251
+ }
1252
+ }
1253
+ }
1254
+ const t = new UnicornTomSelect(ele, options);
1255
+ ele.addEventListener("list:updated", () => {
1256
+ t.syncOptionsWithoutKeepSelected();
1257
+ });
1258
+ return t;
1259
+ }
1260
+ );
1261
+ }
1262
+ return m;
1263
+ }
1264
+ async function useUIBootstrap5(install = false, pushToGlobal = false) {
1265
+ const { UIBootstrap5 } = await import("./ui-bootstrap5.js");
1266
+ const theme = UIBootstrap5.get();
1267
+ if (install) {
1268
+ useUITheme(theme);
1269
+ if (pushToGlobal) {
1270
+ theme.pushBootstrapToGlobal();
1271
+ }
1272
+ }
1273
+ return theme;
1274
+ }
1275
+ async function useBs5Tooltip(selector = '[data-bs-toggle="tooltip"]', config = {}) {
1276
+ const bs5 = await useUIBootstrap5();
1277
+ return bs5.tooltip(selector, config);
1278
+ }
1279
+ const useBs5KeepTab = async (selector, options = {}) => {
1280
+ const bs5 = await useUIBootstrap5();
1281
+ return bs5.keepTab(selector, options);
1282
+ };
1283
+ const useBs5ButtonRadio = async (selector, options = {}) => {
1284
+ const bs5 = await useUIBootstrap5();
1285
+ return bs5.buttonRadio(selector, options);
1286
+ };
1287
+ let instances = {};
1288
+ async function useWebDirective(name = "unicorn", options = {}) {
1289
+ return instances[name] ??= await createWebDirective(Object.assign({}, options, { prefix: "uni-" }));
1290
+ }
1291
+ async function useUniDirective(name, handler, wdInstance = "unicorn") {
1292
+ const wd = typeof wdInstance === "string" ? await useWebDirective(wdInstance) : wdInstance;
1293
+ wd.register(name, handler);
1294
+ }
1295
+ async function createWebDirective(options = {}) {
1296
+ const WebDirective = (await import("web-directive")).default;
1297
+ const wd = new WebDirective(options);
1298
+ wd.listen();
1299
+ return wd;
1300
+ }
1301
+ async function useFormValidation(selector) {
1302
+ const module2 = await import("./validation.js");
1303
+ await module2.ready;
1304
+ if (!selector) {
1305
+ return module2;
1306
+ }
1307
+ return useFormValidationSync(selector);
1308
+ }
1309
+ function useFormValidationSync(selector) {
1310
+ return getBoundedInstance(selector, "form.validation");
1311
+ }
1312
+ function useFieldValidationSync(selector) {
1313
+ return getBoundedInstance(selector, "field.validation");
1314
+ }
1315
+ async function addGlobalValidator(name, validator, options = {}) {
1316
+ const { UnicornFormValidation } = await useFormValidation();
1317
+ UnicornFormValidation.addGlobalValidator(name, validator, options);
1318
+ }
1319
+ let ui;
1320
+ AlertAdapter.alert = (title, text = "", type = "info") => {
1321
+ if (text) {
1322
+ title += " | " + text;
1323
+ }
1324
+ window.alert(title);
1325
+ return Promise.resolve();
1326
+ };
1327
+ AlertAdapter.confirm = (message) => {
1328
+ message = message || "Are you sure?";
1329
+ return new Promise((resolve) => {
1330
+ resolve(window.confirm(message));
1331
+ });
1332
+ };
1333
+ AlertAdapter.confirmText = () => "OK";
1334
+ AlertAdapter.cancelText = () => "Cancel";
1335
+ AlertAdapter.deleteText = () => "Delete";
1336
+ function useUI(instance) {
1337
+ if (instance) {
1338
+ ui = instance;
1339
+ }
1340
+ return ui ??= new UnicornUI();
1341
+ }
1342
+ function useUITheme(theme) {
1343
+ const ui2 = useUI();
1344
+ if (ui2.theme && !theme) {
1345
+ return ui2.theme;
1346
+ }
1347
+ if (typeof theme === "function") {
1348
+ theme = new theme();
1349
+ }
1350
+ ui2.installTheme(theme);
1351
+ return ui2.theme;
1352
+ }
1353
+ class UnicornUI {
1354
+ theme;
1355
+ aliveHandle;
1356
+ static get defaultOptions() {
1357
+ return {
1358
+ messageSelector: ".message-wrap"
1359
+ };
1360
+ }
1361
+ installTheme(theme) {
1362
+ this.theme = theme;
1363
+ }
1364
+ // confirm(message: string): Promise<boolean> {
1365
+ // message = message || 'Are you sure?';
1366
+ //
1367
+ // return new Promise((resolve) => {
1368
+ // resolve(window.confirm(message));
1369
+ // });
1370
+ // }
1371
+ //
1372
+ // alert(title: string, text = '', type = 'info'): Promise<boolean> {
1373
+ // if (text) {
1374
+ // title += ' | ' + text;
1375
+ // }
1376
+ //
1377
+ // window.alert(title);
1378
+ //
1379
+ // return Promise.resolve(true);
1380
+ // }
1381
+ }
1382
+ const prepares = [];
1383
+ const { promise: alpineLoaded, resolve: alpineResolve } = /* @__PURE__ */ Promise.withResolvers();
1384
+ async function loadAlpine(callback) {
1385
+ if (callback && !window.Alpine) {
1386
+ prepares.push(callback);
1387
+ }
1388
+ const { default: Alpine } = await useImport("@alpinejs");
1389
+ if (!window.Alpine) {
1390
+ await Promise.all(prepares.map((callback2) => Promise.resolve(callback2(Alpine))));
1391
+ Alpine.start();
1392
+ window.Alpine = Alpine;
1393
+ alpineResolve(Alpine);
1394
+ } else if (callback) {
1395
+ await callback(Alpine);
1396
+ }
1397
+ return Alpine;
1398
+ }
1399
+ async function initAlpineComponent(directive) {
1400
+ const Alpine = await alpineLoaded;
1401
+ await nextTick();
1402
+ selectAll(`[${directive}]`, (el) => {
1403
+ const code = el.getAttribute(directive) || "";
1404
+ el.removeAttribute(directive);
1405
+ Alpine.mutateDom(() => {
1406
+ el.setAttribute("x-data", code);
1407
+ });
1408
+ Alpine.initTree(el);
1409
+ });
1410
+ }
1411
+ async function prepareAlpine(callback) {
1412
+ if (window.Alpine) {
1413
+ await callback(window.Alpine);
1414
+ } else {
1415
+ prepares.push(callback);
1416
+ }
1417
+ }
1418
+ async function prepareAlpineDefer(callback) {
1419
+ await alpineLoaded;
1420
+ await callback(window.Alpine);
1421
+ }
1422
+ function renderMessage(messages, type = "info") {
1423
+ ui.theme.renderMessage(messages, type);
1424
+ }
1425
+ function clearMessages() {
1426
+ ui.theme.clearMessages();
1427
+ }
1428
+ function notify(messages, type = "info") {
1429
+ ui.theme.renderMessage(messages, type);
1430
+ }
1431
+ function clearNotifies() {
1432
+ ui.theme.clearMessages();
1433
+ }
1434
+ async function mark(selector, keyword = "", options = {}) {
1435
+ const modules = await useImport("@vendor/mark.js/dist/mark.min.js");
1436
+ if (selector != null) {
1437
+ const instance = new Mark(selector);
1438
+ instance.mark(keyword, options);
1439
+ }
1440
+ return modules;
1441
+ }
1442
+ async function slideUp(target, duration = 300) {
1443
+ const ele = selectOne(target);
1444
+ if (!ele) {
1445
+ return Promise.resolve();
1446
+ }
1447
+ ele.style.overflow = "hidden";
1448
+ const animation = animateTo(
1449
+ ele,
1450
+ { height: 0, paddingTop: 0, paddingBottom: 0 },
1451
+ { duration, easing: "ease-out" }
1452
+ );
1453
+ data(ele, "animation.sliding.up", true);
1454
+ const r = await animation.finished;
1455
+ if (!data(ele, "animation.sliding.down")) {
1456
+ ele.style.display = "none";
1457
+ }
1458
+ removeData(ele, "animation.sliding.up");
1459
+ return r;
1460
+ }
1461
+ function slideDown(target, duration = 300, display = "block") {
1462
+ const ele = selectOne(target);
1463
+ if (!ele) {
1464
+ return Promise.resolve();
1465
+ }
1466
+ data(ele, "animation.sliding.down", true);
1467
+ ele.style.display = display;
1468
+ let maxHeight = 0;
1469
+ for (const child of Array.from(ele.children)) {
1470
+ maxHeight = Math.max(child.offsetHeight, maxHeight);
1471
+ }
1472
+ const animation = animateTo(
1473
+ ele,
1474
+ {
1475
+ height: [
1476
+ 0,
1477
+ maxHeight + "px"
1478
+ ]
1479
+ },
1480
+ { duration, easing: "ease-out" }
1481
+ );
1482
+ animation.addEventListener("finish", () => {
1483
+ ele.style.height = "";
1484
+ if (!data(ele, "animation.sliding.up")) {
1485
+ ele.style.overflow = "visible";
1486
+ }
1487
+ removeData(ele, "animation.sliding.down");
1488
+ });
1489
+ return animation.finished;
1490
+ }
1491
+ function slideToggle(target, duration = 500, display = "block") {
1492
+ const ele = selectOne(target);
1493
+ if (!ele) {
1494
+ return Promise.resolve();
1495
+ }
1496
+ if (window.getComputedStyle(ele).display === "none") {
1497
+ return slideDown(ele, duration, display);
1498
+ } else {
1499
+ return slideUp(ele, duration);
1500
+ }
1501
+ }
1502
+ async function fadeOut(selector, duration = 500) {
1503
+ const el = selectOne(selector);
1504
+ if (!el) {
1505
+ return;
1506
+ }
1507
+ const animation = animateTo(el, { opacity: 0 }, { duration, easing: "ease-out" });
1508
+ const p = await animation.finished;
1509
+ el.style.display = "none";
1510
+ return p;
1511
+ }
1512
+ async function fadeIn(selector, duration = 500, display = "block") {
1513
+ const el = selectOne(selector);
1514
+ if (!el) {
1515
+ return;
1516
+ }
1517
+ el.style.display = "";
1518
+ if (window.getComputedStyle(el).display !== display) {
1519
+ el.style.display = display;
1520
+ }
1521
+ const animation = animateTo(el, { opacity: 1 }, { duration, easing: "ease-out" });
1522
+ return animation.finished;
1523
+ }
1524
+ async function highlight(selector, color = "#ffff99", duration = 600) {
1525
+ const ele = selectOne(selector);
1526
+ if (!ele) {
1527
+ return;
1528
+ }
1529
+ duration /= 2;
1530
+ const bg = window.getComputedStyle(ele).backgroundColor;
1531
+ const animation = animateTo(ele, { backgroundColor: color }, { duration });
1532
+ await animation.finished;
1533
+ return animateTo(ele, { backgroundColor: bg }, { duration });
1534
+ }
1535
+ async function useColorPicker(selector, options = {}) {
1536
+ if (options?.theme === "dark") {
1537
+ useCssImport("@spectrum/spectrum-dark.min.css");
1538
+ } else if (!options?.theme) {
1539
+ useCssImport("@spectrum/spectrum.min.css");
1540
+ }
1541
+ const m = await useImport("@spectrum");
1542
+ if (typeof options.locale === "string") {
1543
+ let ls = options.locale.split("-").map((l) => l.toLowerCase());
1544
+ if (ls[0] === ls[1]) {
1545
+ ls = [ls];
1546
+ }
1547
+ ls = ls.join("-");
1548
+ try {
1549
+ await useImport(`@spectrum/i18n/${ls}.js`);
1550
+ } catch (e) {
1551
+ console.warn(`Unable to load Spectrum locale "${ls}" (${options.locale})`);
1552
+ }
1553
+ }
1554
+ if (selector) {
1555
+ module(selector, "spectrum", (ele) => Spectrum.getInstance(ele, options));
1556
+ }
1557
+ return m;
1558
+ }
1559
+ function useDisableOnSubmit(formSelector = "#admin-form", buttonSelector = "", options = {}) {
1560
+ buttonSelector = buttonSelector || [
1561
+ "#admin-toolbar button",
1562
+ "#admin-toolbar a",
1563
+ formSelector + " .disable-on-submit",
1564
+ formSelector + " .js-dos",
1565
+ formSelector + " [data-dos]"
1566
+ ].join(",");
1567
+ const iconSelector = options.iconSelector || [
1568
+ '[class*="fa-"]',
1569
+ "[data-spin]",
1570
+ "[data-spinner]"
1571
+ ].join(",");
1572
+ const event = options.event || "submit";
1573
+ const spinnerClass = options.spinnerClass || "spinner-border spinner-border-sm";
1574
+ selectAll(buttonSelector, (button) => {
1575
+ button.addEventListener("click", (e) => {
1576
+ button.dataset.clicked = "1";
1577
+ setTimeout(() => {
1578
+ delete button.dataset.clicked;
1579
+ }, 1500);
1580
+ });
1581
+ });
1582
+ const form = selectOne(formSelector);
1583
+ form?.addEventListener(event, (e) => {
1584
+ setTimeout(() => {
1585
+ if (!form.checkValidity()) {
1586
+ return;
1587
+ }
1588
+ selectAll(buttonSelector, (button) => {
1589
+ button.style.pointerEvents = "none";
1590
+ button.setAttribute("disabled", "disabled");
1591
+ button.classList.add("disabled");
1592
+ if (button.dataset.clicked) {
1593
+ let icon = button.querySelector(iconSelector);
1594
+ if (icon) {
1595
+ const i = html("<i></i>");
1596
+ icon.parentNode.replaceChild(i, icon);
1597
+ i.setAttribute("class", spinnerClass);
1598
+ }
1599
+ }
1600
+ });
1601
+ }, 0);
1602
+ });
1603
+ }
1604
+ function useDisableIfStackNotEmpty(buttonSelector = "[data-task=save]", stackName = "uploading") {
1605
+ const stack2 = useStack(stackName);
1606
+ stack2.observe((stack22, length) => {
1607
+ for (const button of selectAll(buttonSelector)) {
1608
+ if (length > 0) {
1609
+ button.setAttribute("disabled", "disabled");
1610
+ button.classList.add("disabled");
1611
+ } else {
1612
+ button.removeAttribute("disabled");
1613
+ button.classList.remove("disabled");
1614
+ }
1615
+ }
1616
+ });
1617
+ }
1618
+ function useKeepAlive(url, time = 6e4) {
1619
+ const aliveHandle = window.setInterval(() => fetch(url), time);
1620
+ return () => {
1621
+ clearInterval(aliveHandle);
1622
+ };
1623
+ }
1624
+ async function useVueComponentField(selector, value, options = {}) {
1625
+ const m = await useImport("@unicorn/field/vue-component-field.js");
1626
+ if (selector) {
1627
+ m.VueComponentField.init(selector, value, options);
1628
+ }
1629
+ return m;
1630
+ }
1631
+ function useSystemUri(type, path) {
1632
+ const uri2 = UnicornSystemUri.get();
1633
+ if (type) {
1634
+ return uri2[type](path);
1635
+ }
1636
+ return uri2;
1637
+ }
1638
+ function useAssetUri(type, path) {
1639
+ const asset2 = UnicornAssetUri.get();
1640
+ if (type) {
1641
+ return asset2[type](path);
1642
+ }
1643
+ return asset2;
1644
+ }
1645
+ function uri(type) {
1646
+ return data("unicorn.uri")[type];
1647
+ }
1648
+ function asset(type) {
1649
+ return uri("asset")[type];
1650
+ }
1651
+ function addUriBase(uri2, type = "path") {
1652
+ if (uri2.substring(0, 2) === "//" || uri2.substring(0, 4) === "http") {
1653
+ return uri2;
1654
+ }
1655
+ return asset(type) + "/" + uri2;
1656
+ }
1657
+ class UnicornSystemUri extends URL {
1658
+ static instance;
1659
+ static get() {
1660
+ return this.instance ??= new this(uri("full"));
1661
+ }
1662
+ path(path = "") {
1663
+ return uri("path") + path;
1664
+ }
1665
+ root(path = "") {
1666
+ return uri("root") + path;
1667
+ }
1668
+ current() {
1669
+ return uri("current") || "";
1670
+ }
1671
+ full() {
1672
+ return uri("full") || "";
1673
+ }
1674
+ route() {
1675
+ return uri("route") || "";
1676
+ }
1677
+ script() {
1678
+ return uri("script") || "";
1679
+ }
1680
+ routeWithQuery() {
1681
+ const route2 = this.route();
1682
+ const query = this.searchParams.toString();
1683
+ return query ? `${route2}?${query}` : route2;
1684
+ }
1685
+ routeAndQuery() {
1686
+ const route2 = this.route();
1687
+ const query = this.searchParams.toString();
1688
+ return [route2, query];
1689
+ }
1690
+ }
1691
+ class UnicornAssetUri {
1692
+ static instance;
1693
+ static get() {
1694
+ return this.instance ??= new this();
1695
+ }
1696
+ path(path = "") {
1697
+ return asset("path") + path;
1698
+ }
1699
+ root(path = "") {
1700
+ return asset("root") + path;
1701
+ }
1702
+ }
1703
+ function encode(obj, pfx) {
1704
+ var k, i, tmp, str = "";
1705
+ for (k in obj) {
1706
+ if ((tmp = obj[k]) !== void 0) {
1707
+ if (Array.isArray(tmp)) {
1708
+ for (i = 0; i < tmp.length; i++) {
1709
+ str && (str += "&");
1710
+ str += encodeURIComponent(k) + "=" + encodeURIComponent(tmp[i]);
1711
+ }
1712
+ } else {
1713
+ str && (str += "&");
1714
+ str += encodeURIComponent(k) + "=" + encodeURIComponent(tmp);
1715
+ }
1716
+ }
1717
+ }
1718
+ return "" + str;
1719
+ }
1720
+ function toValue(mix) {
1721
+ if (!mix) return "";
1722
+ var str = decodeURIComponent(mix);
1723
+ if (str === "false") return false;
1724
+ if (str === "true") return true;
1725
+ return +str * 0 === 0 ? +str : str;
1726
+ }
1727
+ function decode(str) {
1728
+ var tmp, k, out = {}, arr = str.split("&");
1729
+ while (tmp = arr.shift()) {
1730
+ tmp = tmp.split("=");
1731
+ k = tmp.shift();
1732
+ if (out[k] !== void 0) {
1733
+ out[k] = [].concat(out[k], toValue(tmp.shift()));
1734
+ } else {
1735
+ out[k] = toValue(tmp.shift());
1736
+ }
1737
+ }
1738
+ return out;
1739
+ }
1740
+ function addRoute(route2, url) {
1741
+ const routes = data("unicorn.routes") || {};
1742
+ routes[route2] = url;
1743
+ data("unicorn.routes", routes);
1744
+ }
1745
+ function route(route2, query) {
1746
+ const source = route2;
1747
+ const extract = extractRoute(source);
1748
+ route2 = extract.route;
1749
+ let path = extract.path;
1750
+ const routes = data("unicorn.routes") || {};
1751
+ let url = routes[route2];
1752
+ if (url == null) {
1753
+ if (!route2.startsWith("@")) {
1754
+ route2 = "@" + route2;
1755
+ } else {
1756
+ route2 = route2.substring(1);
1757
+ }
1758
+ }
1759
+ url = routes[route2];
1760
+ if (url == null) {
1761
+ throw new Error(`Route: "${source}" not found`);
1762
+ }
1763
+ if (path) {
1764
+ const { route: u1, path: u1q } = extractRoute(url, "?");
1765
+ const { route: u2, path: u2q } = extractRoute(path, "?");
1766
+ url = u1 + "/" + u2;
1767
+ if (u1q || u2q) {
1768
+ const q = [u1q, u2q].filter((u) => u).join("&");
1769
+ url += "?" + q;
1770
+ }
1771
+ }
1772
+ return addQuery(url, query);
1773
+ }
1774
+ function extractRoute(route2, sep = "/") {
1775
+ if (route2.indexOf(sep) === -1) {
1776
+ return { route: route2, path: "" };
1777
+ }
1778
+ const segments = route2.split(sep);
1779
+ route2 = segments.shift() || "";
1780
+ const path = segments.join(sep);
1781
+ return { route: route2, path };
1782
+ }
1783
+ function hasRoute(route2) {
1784
+ return void 0 !== data("unicorn.routes")[route2];
1785
+ }
1786
+ function addQuery(url, query) {
1787
+ if (query == null) {
1788
+ return url;
1789
+ }
1790
+ for (let k in query) {
1791
+ const v = query[k];
1792
+ const placeholder = `{${k}}`;
1793
+ if (url.indexOf(placeholder) !== -1) {
1794
+ url = url.replace(
1795
+ new RegExp(`${placeholder}`, "g"),
1796
+ v
1797
+ );
1798
+ delete query[k];
1799
+ }
1800
+ const encodedPlaceholder = encodeURIComponent(`{${k}}`);
1801
+ if (url.indexOf(encodedPlaceholder) !== -1) {
1802
+ url = url.replace(
1803
+ new RegExp(`${encodedPlaceholder}`, "g"),
1804
+ v
1805
+ );
1806
+ delete query[k];
1807
+ }
1808
+ }
1809
+ if (Object.keys(query).length === 0) {
1810
+ return url;
1811
+ }
1812
+ const queryString = encode(query);
1813
+ return url + (/\?/.test(url) ? `&${queryString}` : `?${queryString}`);
1814
+ }
1815
+ function parseQuery(queryString) {
1816
+ return decode(queryString);
1817
+ }
1818
+ function buildQuery(query) {
1819
+ return encode(query);
1820
+ }
1821
+ function removeCloak() {
1822
+ if (globalThis.document == null) {
1823
+ return;
1824
+ }
1825
+ selectAll("[uni-cloak]", (el) => el.removeAttribute("uni-cloak"));
1826
+ }
1827
+ function data(ele, name = void 0, value = void 0) {
1828
+ if (!(ele instanceof HTMLElement)) {
1829
+ value = name;
1830
+ name = ele;
1831
+ ele = document;
1832
+ }
1833
+ if (name === void 0) {
1834
+ return getData(ele);
1835
+ }
1836
+ if (value === void 0) {
1837
+ const res = getData(ele, name);
1838
+ return res;
1839
+ }
1840
+ setData(ele, name, value);
1841
+ }
1842
+ function removeData(ele, name = void 0) {
1843
+ if (!(ele instanceof HTMLElement)) {
1844
+ name = ele;
1845
+ ele = document;
1846
+ }
1847
+ removeData$1(ele, name);
1848
+ }
1849
+ class EventMixin {
1850
+ _listeners = {};
1851
+ on(event, handler) {
1852
+ if (Array.isArray(event)) {
1853
+ for (const e of event) {
1854
+ this.on(e, handler);
1855
+ }
1856
+ return this;
1857
+ }
1858
+ this._listeners[event] ??= [];
1859
+ this._listeners[event].push(handler);
1860
+ return this;
1861
+ }
1862
+ once(event, handler) {
1863
+ handler.once = true;
1864
+ return this.on(event, handler);
1865
+ }
1866
+ off(event, handler) {
1867
+ if (handler) {
1868
+ this._listeners[event] = this.listeners(event).filter((listener) => listener !== handler);
1869
+ return this;
1870
+ }
1871
+ delete this._listeners[event];
1872
+ return this;
1873
+ }
1874
+ trigger(event, ...args) {
1875
+ if (Array.isArray(event)) {
1876
+ for (const e of event) {
1877
+ this.trigger(e);
1878
+ }
1879
+ return this;
1880
+ }
1881
+ for (const listener of this.listeners(event)) {
1882
+ listener(...args);
1883
+ }
1884
+ this._listeners[event] = this.listeners(event).filter((listener) => listener?.once !== true);
1885
+ return this;
1886
+ }
1887
+ listeners(event) {
1888
+ return this._listeners[event] === void 0 ? [] : this._listeners[event];
1889
+ }
1890
+ }
1891
+ class UnicornApp extends (/* @__PURE__ */ Mixin(EventMixin)) {
1892
+ registry = /* @__PURE__ */ new Map();
1893
+ plugins = /* @__PURE__ */ new Map();
1894
+ // _listeners = {};
1895
+ waits = [];
1896
+ options;
1897
+ defaultOptions = {};
1898
+ domready = domready;
1899
+ data = data;
1900
+ constructor(options = {}) {
1901
+ super();
1902
+ this.options = Object.assign({}, this.defaultOptions, options);
1903
+ if (typeof document !== "undefined") {
1904
+ this.wait((resolve) => {
1905
+ document.addEventListener("DOMContentLoaded", () => resolve());
1906
+ });
1907
+ document.addEventListener("DOMContentLoaded", () => {
1908
+ this.completed().then(() => this.trigger("loaded"));
1909
+ });
1910
+ }
1911
+ }
1912
+ use(plugin, options = {}) {
1913
+ if (Array.isArray(plugin)) {
1914
+ plugin.forEach((p) => this.use(p));
1915
+ return this;
1916
+ }
1917
+ plugin?.install?.(this, options);
1918
+ this.trigger("plugin.installed", plugin);
1919
+ this.plugins.set(plugin, plugin);
1920
+ return this;
1921
+ }
1922
+ detach(plugin) {
1923
+ if (plugin.uninstall) {
1924
+ plugin.uninstall(this);
1925
+ }
1926
+ this.trigger("plugin.uninstalled", plugin);
1927
+ return this;
1928
+ }
1929
+ inject(id, def) {
1930
+ if (!typeof this.registry.has(id)) {
1931
+ if (def !== void 0) {
1932
+ return def;
1933
+ }
1934
+ throw new Error(`Injectable: ${id.name} not found.`);
1935
+ }
1936
+ return this.registry.get(id);
1937
+ }
1938
+ provide(id, value) {
1939
+ this.registry.set(id, value);
1940
+ return this;
1941
+ }
1942
+ // trigger(event, ...args) {
1943
+ // return this.tap(super.trigger(event, ...args), () => {
1944
+ // if (this.data('windwalker.debug')) {
1945
+ // console.debug(`[Unicorn Event] ${event}`, args, this.listeners(event));
1946
+ // }
1947
+ // });
1948
+ // }
1949
+ wait(callback) {
1950
+ const p = new Promise((resolve, reject) => {
1951
+ const promise = callback(resolve, reject);
1952
+ if (promise && "then" in promise) {
1953
+ promise.then(resolve).catch(reject);
1954
+ }
1955
+ });
1956
+ this.waits.push(p);
1957
+ return p;
1958
+ }
1959
+ completed() {
1960
+ const promise = Promise.all(this.waits);
1961
+ this.waits = [];
1962
+ return promise;
1963
+ }
1964
+ macro(name, callback) {
1965
+ if (this[name]) {
1966
+ throw new Error(`Macro: ${name} already exists.`);
1967
+ }
1968
+ this[name] = callback;
1969
+ return this;
1970
+ }
1971
+ }
1972
+ function formRequestSubmit(prototype) {
1973
+ if (typeof prototype.requestSubmit == "function") {
1974
+ return;
1975
+ }
1976
+ prototype.requestSubmit = function(submitter) {
1977
+ if (submitter) {
1978
+ validateSubmitter(submitter, this);
1979
+ submitter.click();
1980
+ } else {
1981
+ submitter = document.createElement("input");
1982
+ submitter.type = "submit";
1983
+ submitter.hidden = true;
1984
+ this.appendChild(submitter);
1985
+ submitter.click();
1986
+ this.removeChild(submitter);
1987
+ }
1988
+ };
1989
+ function validateSubmitter(submitter, form) {
1990
+ submitter instanceof HTMLElement || raise(TypeError, "parameter 1 is not of type 'HTMLElement'");
1991
+ submitter.type == "submit" || raise(TypeError, "The specified element is not a submit button");
1992
+ submitter.form == form || raise(DOMException, "The specified element is not owned by this form element", "NotFoundError");
1993
+ }
1994
+ function raise(errorConstructor, message, name) {
1995
+ throw new errorConstructor("Failed to execute 'requestSubmit' on 'HTMLFormElement': " + message + ".", name);
1996
+ }
1997
+ }
1998
+ function polyfill() {
1999
+ if (typeof window !== "undefined") {
2000
+ formRequestSubmit(HTMLFormElement.prototype);
2001
+ }
2002
+ }
2003
+ async function useFieldMultiUploader() {
2004
+ await import("./field-multi-uploader.js");
2005
+ }
2006
+ async function useTinymce(selector, options = {}) {
2007
+ const module2 = await import("./tinymce.js");
2008
+ if (selector) {
2009
+ return module2.get(selector, options);
2010
+ }
2011
+ return module2;
2012
+ }
2013
+ function useUnicornPhpAdapter(app2) {
2014
+ app2 ??= useUnicorn();
2015
+ app2.use(UnicornPhpAdapter);
2016
+ return app2.$ui;
2017
+ }
2018
+ const methods = {
2019
+ repeatable: useFieldRepeatable,
2020
+ flatpickr: useFieldFlatpickr,
2021
+ fileDrag: useFieldFileDrag,
2022
+ modalField: useFieldModalSelect,
2023
+ cascadeSelect: useFieldCascadeSelect,
2024
+ sid: useFieldSingleImageDrag,
2025
+ tinymce: {
2026
+ init: useTinymce
2027
+ },
2028
+ s3Uploader: useS3Uploader,
2029
+ iframeModal: useIframeModal,
2030
+ initShowOn: useShowOn,
2031
+ modalTree: useFieldModalTree,
2032
+ multiUploader: useFieldMultiUploader,
2033
+ tomSelect: useTomSelect
2034
+ };
2035
+ class UnicornPhpAdapter {
2036
+ static install(app2) {
2037
+ if (app2.$ui) {
2038
+ app2.$ui = { ...app2.$ui, ...methods };
2039
+ } else {
2040
+ app2.$ui = methods;
2041
+ }
2042
+ }
2043
+ }
2044
+ let app;
2045
+ function createUnicorn() {
2046
+ polyfill();
2047
+ removeCloak();
2048
+ return app = new UnicornApp();
2049
+ }
2050
+ function createUnicornWithPlugins() {
2051
+ const app2 = createUnicorn();
2052
+ return app2;
2053
+ }
2054
+ function useUnicorn(instance) {
2055
+ if (instance) {
2056
+ app = instance;
2057
+ }
2058
+ return app ??= createUnicorn();
2059
+ }
2060
+ const useInject = (id, def) => {
2061
+ return useUnicorn().inject(id, def);
2062
+ };
2063
+ function pushUnicornToGlobal(app2) {
2064
+ window.u = app2 ?? useUnicorn();
2065
+ }
2066
+ function useMacro(name, handler) {
2067
+ useUnicorn().macro(name, handler);
2068
+ }
2069
+ async function useLegacy(app2) {
2070
+ app2 ??= useUnicorn();
2071
+ pushUnicornToGlobal(app2);
2072
+ const { useLegacyMethods } = await import("./legacy.js");
2073
+ await useLegacyMethods(app2);
2074
+ return app2;
2075
+ }
2076
+ export {
2077
+ useBs5Tooltip as $,
2078
+ h as A,
2079
+ html as B,
2080
+ delegate as C,
2081
+ debounce as D,
2082
+ throttle as E,
2083
+ simpleConfirm as F,
2084
+ simpleAlert as G,
2085
+ sprintfExports as H,
2086
+ base64UrlEncode as I,
2087
+ base64UrlDecode as J,
2088
+ uid as K,
2089
+ tid as L,
2090
+ serial as M,
2091
+ mark as N,
2092
+ useTomSelect as O,
2093
+ slideUp as P,
2094
+ slideDown as Q,
2095
+ slideToggle as R,
2096
+ fadeOut as S,
2097
+ fadeIn as T,
2098
+ highlight as U,
2099
+ useColorPicker as V,
2100
+ useDisableOnSubmit as W,
2101
+ useDisableIfStackNotEmpty as X,
2102
+ useCheckboxesMultiSelect as Y,
2103
+ useKeepAlive as Z,
2104
+ __ as _,
2105
+ useUniDirective as a,
2106
+ createStack as a$,
2107
+ useFormAsync as a0,
2108
+ useGridAsync as a1,
2109
+ useForm as a2,
2110
+ useGrid as a3,
2111
+ prepareAlpineDefer as a4,
2112
+ mergeDeep as a5,
2113
+ watchAttributes as a6,
2114
+ injectCssToDocument as a7,
2115
+ useImport as a8,
2116
+ useCssImport as a9,
2117
+ useCssIncludes as aA,
2118
+ AlertAdapter as aB,
2119
+ useUI as aC,
2120
+ UnicornUI as aD,
2121
+ useVueComponentField as aE,
2122
+ addUriBase as aF,
2123
+ UnicornSystemUri as aG,
2124
+ UnicornAssetUri as aH,
2125
+ addRoute as aI,
2126
+ hasRoute as aJ,
2127
+ addQuery as aK,
2128
+ parseQuery as aL,
2129
+ buildQuery as aM,
2130
+ useFieldCascadeSelect as aN,
2131
+ useFieldFileDrag as aO,
2132
+ useFieldFlatpickr as aP,
2133
+ useFieldModalSelect as aQ,
2134
+ useFieldModalTree as aR,
2135
+ useFieldRepeatable as aS,
2136
+ useFieldSingleImageDrag as aT,
2137
+ useFormComponent as aU,
2138
+ useGridComponent as aV,
2139
+ useIframeModal as aW,
2140
+ useListDependent as aX,
2141
+ useS3Uploader as aY,
2142
+ useS3MultipartUploader as aZ,
2143
+ useShowOn as a_,
2144
+ data as aa,
2145
+ forceArray as ab,
2146
+ deleteConfirm as ac,
2147
+ Mixin as ad,
2148
+ EventMixin as ae,
2149
+ createQueue as af,
2150
+ trans as ag,
2151
+ useUITheme as ah,
2152
+ sleep as ai,
2153
+ createUnicorn as aj,
2154
+ createUnicornWithPlugins as ak,
2155
+ useUnicorn as al,
2156
+ useInject as am,
2157
+ pushUnicornToGlobal as an,
2158
+ useMacro as ao,
2159
+ useLegacy as ap,
2160
+ removeData as aq,
2161
+ randomBytes as ar,
2162
+ randomBytesString as as,
2163
+ AttributeMutationObserver as at,
2164
+ nextTick as au,
2165
+ wait as av,
2166
+ useLang as aw,
2167
+ useScriptImport as ax,
2168
+ doImport as ay,
2169
+ useSeriesImport as az,
2170
+ animateTo as b,
2171
+ useUIBootstrap5 as b0,
2172
+ useBs5KeepTab as b1,
2173
+ useBs5ButtonRadio as b2,
2174
+ useWebDirective as b3,
2175
+ useUnicornPhpAdapter as b4,
2176
+ UnicornPhpAdapter as b5,
2177
+ renderMessage as c,
2178
+ clearMessages as d,
2179
+ clearNotifies as e,
2180
+ initAlpineComponent as f,
2181
+ useFormValidation as g,
2182
+ addGlobalValidator as h,
2183
+ isDebug as i,
2184
+ useFieldValidationSync as j,
2185
+ useFormValidationSync as k,
2186
+ loadAlpine as l,
2187
+ useStack as m,
2188
+ notify as n,
2189
+ useQueue as o,
2190
+ prepareAlpine as p,
2191
+ useSystemUri as q,
2192
+ route as r,
2193
+ useAssetUri as s,
2194
+ domready as t,
2195
+ useHttpClient as u,
2196
+ selectOne as v,
2197
+ selectAll as w,
2198
+ getBoundedInstance as x,
2199
+ getBoundedInstanceList as y,
2200
+ module as z
2201
+ };
2202
+ //# sourceMappingURL=unicorn.js.map