@windwalker-io/unicorn-next 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. package/.editorconfig +18 -18
  2. package/.gulp.json +7 -7
  3. package/bin/release.mjs +47 -47
  4. package/dist/chunks/button-radio.js.map +1 -1
  5. package/dist/chunks/checkboxes-multi-select.js.map +1 -1
  6. package/dist/chunks/field-cascade-select.js.map +1 -1
  7. package/dist/chunks/field-file-drag.js.map +1 -1
  8. package/dist/chunks/field-flatpickr.js.map +1 -1
  9. package/dist/chunks/field-modal-select.js.map +1 -1
  10. package/dist/chunks/field-modal-tree.js +2 -2
  11. package/dist/chunks/field-modal-tree.js.map +1 -1
  12. package/dist/chunks/field-multi-uploader.js.map +1 -1
  13. package/dist/chunks/field-repeatable.js.map +1 -1
  14. package/dist/chunks/field-single-image-drag.js.map +1 -1
  15. package/dist/chunks/form.js +1 -1
  16. package/dist/chunks/form.js.map +1 -1
  17. package/dist/chunks/grid.js.map +1 -1
  18. package/dist/chunks/http-client.js.map +1 -1
  19. package/dist/chunks/iframe-modal.js.map +1 -1
  20. package/dist/chunks/keep-tab.js +1 -1
  21. package/dist/chunks/keep-tab.js.map +1 -1
  22. package/dist/chunks/legacy.js +3 -3
  23. package/dist/chunks/legacy.js.map +1 -1
  24. package/dist/chunks/list-dependent.js.map +1 -1
  25. package/dist/chunks/s3-multipart-uploader.js.map +1 -1
  26. package/dist/chunks/s3-uploader.js.map +1 -1
  27. package/dist/chunks/show-on.js.map +1 -1
  28. package/dist/chunks/tinymce.js +14 -4
  29. package/dist/chunks/tinymce.js.map +1 -1
  30. package/dist/chunks/ui-bootstrap5.js +9 -2
  31. package/dist/chunks/ui-bootstrap5.js.map +1 -1
  32. package/dist/chunks/unicorn.js +94 -46
  33. package/dist/chunks/unicorn.js.map +1 -1
  34. package/dist/chunks/validation.js.map +1 -1
  35. package/dist/editor.css +1 -1
  36. package/dist/index.d.ts +55 -36
  37. package/dist/multi-level-menu.css +1 -1
  38. package/dist/switcher.css +1 -1
  39. package/dist/unicorn.js +22 -22
  40. package/fusionfile.mjs +155 -155
  41. package/package.json +102 -102
  42. package/scss/bootstrap/multi-level-menu.scss +121 -121
  43. package/scss/editor.scss +116 -116
  44. package/scss/field/file-drag.scss +102 -102
  45. package/scss/field/single-image-drag.scss +88 -88
  46. package/scss/field/vue-drag-uploader.scss +160 -160
  47. package/scss/switcher.scss +156 -156
  48. package/src/app.ts +128 -128
  49. package/src/bootstrap/button-radio.ts +208 -208
  50. package/src/bootstrap/keep-tab.ts +155 -155
  51. package/src/composable/index.ts +21 -21
  52. package/src/composable/useCheckboxesMultiSelect.ts +22 -22
  53. package/src/composable/useFieldCascadeSelect.ts +9 -9
  54. package/src/composable/useFieldFileDrag.ts +9 -9
  55. package/src/composable/useFieldFlatpickr.ts +3 -3
  56. package/src/composable/useFieldModalSelect.ts +6 -6
  57. package/src/composable/useFieldModalTree.ts +3 -3
  58. package/src/composable/useFieldMultiUploader.ts +3 -3
  59. package/src/composable/useFieldRepeatable.ts +9 -9
  60. package/src/composable/useFieldSingleImageDrag.ts +5 -5
  61. package/src/composable/useForm.ts +43 -43
  62. package/src/composable/useGrid.ts +57 -57
  63. package/src/composable/useHttp.ts +9 -8
  64. package/src/composable/useIframeModal.ts +9 -9
  65. package/src/composable/useListDependent.ts +26 -26
  66. package/src/composable/useQueue.ts +13 -13
  67. package/src/composable/useS3Uploader.ts +32 -32
  68. package/src/composable/useShowOn.ts +9 -9
  69. package/src/composable/useStack.ts +13 -13
  70. package/src/composable/useTinymce.ts +29 -29
  71. package/src/composable/useTomSelect.ts +72 -72
  72. package/src/composable/useUIBootstrap5.ts +48 -48
  73. package/src/composable/useUniDirective.ts +32 -32
  74. package/src/composable/useValidation.ts +39 -39
  75. package/src/data.ts +34 -36
  76. package/src/events.ts +82 -73
  77. package/src/legacy/legacy.ts +186 -186
  78. package/src/legacy/loader.ts +125 -125
  79. package/src/module/checkboxes-multi-select.ts +54 -54
  80. package/src/module/field-cascade-select.ts +292 -292
  81. package/src/module/field-file-drag.ts +292 -292
  82. package/src/module/field-flatpickr.ts +127 -127
  83. package/src/module/field-modal-select.ts +174 -174
  84. package/src/module/field-modal-tree.ts +27 -27
  85. package/src/module/field-multi-uploader.ts +361 -361
  86. package/src/module/field-repeatable.ts +202 -202
  87. package/src/module/field-single-image-drag.ts +468 -468
  88. package/src/module/form.ts +223 -223
  89. package/src/module/grid.ts +465 -465
  90. package/src/module/http-client.ts +248 -243
  91. package/src/module/iframe-modal.ts +167 -167
  92. package/src/module/list-dependent.ts +321 -321
  93. package/src/module/s3-multipart-uploader.ts +300 -300
  94. package/src/module/s3-uploader.ts +234 -234
  95. package/src/module/show-on.ts +173 -173
  96. package/src/module/tinymce.ts +279 -263
  97. package/src/module/ui-bootstrap5.ts +116 -107
  98. package/src/module/validation.ts +1019 -1019
  99. package/src/plugin/index.ts +1 -1
  100. package/src/plugin/php-adapter.ts +65 -65
  101. package/src/polyfill/form-request-submit.ts +31 -31
  102. package/src/polyfill/index.ts +9 -9
  103. package/src/service/animate.ts +58 -58
  104. package/src/service/crypto.ts +27 -27
  105. package/src/service/dom-watcher.ts +62 -62
  106. package/src/service/dom.ts +265 -265
  107. package/src/service/helper.ts +48 -48
  108. package/src/service/index.ts +10 -10
  109. package/src/service/lang.ts +122 -122
  110. package/src/service/loader.ts +152 -152
  111. package/src/service/router.ts +118 -118
  112. package/src/service/ui.ts +525 -497
  113. package/src/service/uri.ts +106 -106
  114. package/src/types/base.ts +9 -9
  115. package/src/types/index.ts +4 -4
  116. package/src/types/modal-tree.ts +12 -12
  117. package/src/types/plugin.ts +6 -6
  118. package/src/types/shims.d.ts +18 -18
  119. package/src/types/ui.ts +6 -6
  120. package/src/unicorn.ts +79 -63
  121. package/src/utilities/arr.ts +25 -25
  122. package/src/utilities/base.ts +9 -9
  123. package/src/utilities/data.ts +48 -48
  124. package/src/utilities/index.ts +5 -5
  125. package/src/utilities/tree.ts +20 -20
  126. package/src/vue/components/ModalTree/ModalTreeApp.vue +175 -175
  127. package/src/vue/components/ModalTree/TreeItem.vue +262 -262
  128. package/src/vue/components/ModalTree/TreeModal.vue +225 -225
  129. package/tests/test.js +4 -4
  130. package/tsconfig.js.json +25 -25
  131. package/tsconfig.json +17 -17
  132. package/vite.assets.config.ts +61 -61
  133. package/vite.config.test.ts +36 -36
  134. package/vite.config.ts +112 -112
  135. package/dist/unicorn-next.css +0 -12
@@ -1,186 +1,186 @@
1
- import { numberFormat } from '@lyrasoft/ts-toolkit/generic';
2
- import { sprintf, vsprintf } from 'sprintf-js';
3
- import {
4
- addGlobalValidator,
5
- useBs5Tooltip,
6
- useCheckboxesMultiSelect,
7
- useFieldValidationSync,
8
- useForm,
9
- useFormAsync,
10
- useFormValidation,
11
- useFormValidationSync,
12
- useGrid,
13
- useGridAsync,
14
- useHttpClient,
15
- useQueue,
16
- useStack,
17
- useTomSelect,
18
- useUniDirective
19
- } from '../composable';
20
- import {
21
- __,
22
- animateTo,
23
- base64UrlDecode,
24
- base64UrlEncode,
25
- clearMessages,
26
- clearNotifies,
27
- debounce,
28
- delegate,
29
- domready,
30
- fadeIn,
31
- fadeOut,
32
- getBoundedInstance,
33
- getBoundedInstanceList,
34
- h,
35
- highlight,
36
- html,
37
- initAlpineComponent,
38
- isDebug,
39
- loadAlpine,
40
- mark,
41
- module,
42
- notify,
43
- prepareAlpine,
44
- renderMessage,
45
- route,
46
- selectAll,
47
- selectOne,
48
- serial,
49
- simpleAlert,
50
- simpleConfirm,
51
- slideDown,
52
- slideToggle,
53
- slideUp,
54
- throttle,
55
- tid,
56
- uid,
57
- useAssetUri,
58
- useColorPicker,
59
- useDisableIfStackNotEmpty,
60
- useDisableOnSubmit,
61
- useKeepAlive,
62
- useSystemUri
63
- } from '../service';
64
- import { LegacyLoader } from './loader';
65
-
66
- export async function useLegacyMethods(app: any) {
67
- const http = await useHttpClient();
68
-
69
- app.use(LegacyLoader);
70
-
71
- handleUri(app);
72
- handlerHelper(app);
73
- handleCrypto(app);
74
-
75
- app.__ = __;
76
- app.trans = __;
77
- app.route = route;
78
- app.$http = http;
79
- app.directive = useUniDirective;
80
-
81
- app.animate = animateTo;
82
- app.$animation = { to: animateTo };
83
-
84
- app.addMessage = renderMessage;
85
- app.clearMessages = clearMessages;
86
- app.notify = notify;
87
- app.clearNotifies = clearNotifies;
88
-
89
- app.loadAlpine = loadAlpine;
90
- app.initAlpine = initAlpineComponent;
91
- app.beforeAlpineInit = prepareAlpine;
92
- app.prepareAlpine = prepareAlpine;
93
-
94
- handleUI(app);
95
-
96
- await handleFormGrid(app);
97
-
98
- app.formValidation = useFormValidation;
99
- app.$validation = {
100
- get: useFormValidationSync,
101
- getField: useFieldValidationSync,
102
- addGlobalValidator: addGlobalValidator,
103
- import: () => useFormValidation()
104
- };
105
-
106
- app.stack = useStack;
107
- app.queue = useQueue;
108
- }
109
-
110
- function handleCrypto(app: any) {
111
- app.base64Encode = base64UrlEncode;
112
- app.base64Decode = base64UrlDecode;
113
- // app.uuid4 = uuid4;
114
- app.uid = uid;
115
- app.tid = tid;
116
- // app.md5 = md5;
117
- app.serial = serial;
118
- }
119
-
120
- function handleUri(app: any) {
121
- app.uri = useSystemUri;
122
- app.asset = useAssetUri;
123
- }
124
-
125
- function handlerHelper(app: any) {
126
- app.domready = domready;
127
- app.selectOne = selectOne;
128
- app.selectAll = selectAll;
129
- app.each = selectAll;
130
- app.getBoundedInstance = getBoundedInstance;
131
- app.getBoundedInstanceList = getBoundedInstanceList;
132
- app.module = module;
133
- app.h = h;
134
- app.html = html;
135
- // app.$get = get;
136
- // app.$set = set;
137
- app.delegate = delegate;
138
- app.debounce = debounce;
139
- app.throttle = throttle;
140
- app.isDebug = isDebug;
141
- app.confirm = simpleConfirm;
142
- app.alert = simpleAlert;
143
- app.numberFormat = numberFormat;
144
- app.sprintf = sprintf;
145
- app.vsprintf = vsprintf;
146
- // app.genRandomString = genRandomString;
147
- // app.defaultsDeep = defaultsDeep;
148
- }
149
-
150
- function handleUI(app: any) {
151
- app.$ui ??= {};
152
- app.$ui.addMessage = renderMessage;
153
- app.$ui.clearMessages = clearMessages;
154
- app.$ui.notify = notify;
155
- app.$ui.clearNotifies = clearNotifies;
156
-
157
- app.$ui.loadAlpine = loadAlpine;
158
- app.$ui.initAlpine = initAlpineComponent;
159
- app.$ui.beforeAlpineInit = prepareAlpine;
160
- app.$ui.prepareAlpine = prepareAlpine;
161
-
162
- app.$ui.mark = mark;
163
- app.$ui.tomSelect = useTomSelect;
164
- app.$ui.slideUp = slideUp;
165
- app.$ui.slideDown = slideDown;
166
- app.$ui.slideToggle = slideToggle;
167
- app.$ui.fadeOut = fadeOut;
168
- app.$ui.fadeIn = fadeIn;
169
- app.$ui.highlight = highlight;
170
- app.$ui.colorPicker = useColorPicker;
171
- app.$ui.disableOnSubmit = useDisableOnSubmit;
172
- app.$ui.disableIfStackNotEmpty = useDisableIfStackNotEmpty;
173
- app.$ui.checkboxesMultiSelect = useCheckboxesMultiSelect;
174
- app.$ui.keepAlive = useKeepAlive;
175
- app.$ui.bootstrap = {
176
- tooltip: useBs5Tooltip
177
- };
178
- }
179
-
180
- async function handleFormGrid(app: any) {
181
- await useFormAsync();
182
- await useGridAsync();
183
-
184
- app.form = useForm;
185
- app.grid = useGrid;
186
- }
1
+ import { numberFormat } from '@lyrasoft/ts-toolkit/generic';
2
+ import { sprintf, vsprintf } from 'sprintf-js';
3
+ import {
4
+ addGlobalValidator,
5
+ useBs5Tooltip,
6
+ useCheckboxesMultiSelect,
7
+ useFieldValidationSync,
8
+ useForm,
9
+ useFormAsync,
10
+ useFormValidation,
11
+ useFormValidationSync,
12
+ useGrid,
13
+ useGridAsync,
14
+ useHttpClient,
15
+ useQueue,
16
+ useStack,
17
+ useTomSelect,
18
+ useUniDirective
19
+ } from '../composable';
20
+ import {
21
+ __,
22
+ animateTo,
23
+ base64UrlDecode,
24
+ base64UrlEncode,
25
+ clearMessages,
26
+ clearNotifies,
27
+ debounce,
28
+ delegate,
29
+ domready,
30
+ fadeIn,
31
+ fadeOut,
32
+ getBoundedInstance,
33
+ getBoundedInstanceList,
34
+ h,
35
+ highlight,
36
+ html,
37
+ initAlpineComponent,
38
+ isDebug,
39
+ loadAlpine,
40
+ mark,
41
+ module,
42
+ simpleNotify,
43
+ prepareAlpine,
44
+ renderMessage,
45
+ route,
46
+ selectAll,
47
+ selectOne,
48
+ serial,
49
+ simpleAlert,
50
+ simpleConfirm,
51
+ slideDown,
52
+ slideToggle,
53
+ slideUp,
54
+ throttle,
55
+ tid,
56
+ uid,
57
+ useAssetUri,
58
+ useColorPicker,
59
+ useDisableIfStackNotEmpty,
60
+ useDisableOnSubmit,
61
+ useKeepAlive,
62
+ useSystemUri
63
+ } from '../service';
64
+ import { LegacyLoader } from './loader';
65
+
66
+ export async function useLegacyMethods(app: any) {
67
+ const http = await useHttpClient();
68
+
69
+ app.use(LegacyLoader);
70
+
71
+ handleUri(app);
72
+ handlerHelper(app);
73
+ handleCrypto(app);
74
+
75
+ app.__ = __;
76
+ app.trans = __;
77
+ app.route = route;
78
+ app.$http = http;
79
+ app.directive = useUniDirective;
80
+
81
+ app.animate = animateTo;
82
+ app.$animation = { to: animateTo };
83
+
84
+ app.addMessage = renderMessage;
85
+ app.clearMessages = clearMessages;
86
+ app.notify = simpleNotify;
87
+ app.clearNotifies = clearNotifies;
88
+
89
+ app.loadAlpine = loadAlpine;
90
+ app.initAlpine = initAlpineComponent;
91
+ app.beforeAlpineInit = prepareAlpine;
92
+ app.prepareAlpine = prepareAlpine;
93
+
94
+ handleUI(app);
95
+
96
+ await handleFormGrid(app);
97
+
98
+ app.formValidation = useFormValidation;
99
+ app.$validation = {
100
+ get: useFormValidationSync,
101
+ getField: useFieldValidationSync,
102
+ addGlobalValidator: addGlobalValidator,
103
+ import: () => useFormValidation()
104
+ };
105
+
106
+ app.stack = useStack;
107
+ app.queue = useQueue;
108
+ }
109
+
110
+ function handleCrypto(app: any) {
111
+ app.base64Encode = base64UrlEncode;
112
+ app.base64Decode = base64UrlDecode;
113
+ // app.uuid4 = uuid4;
114
+ app.uid = uid;
115
+ app.tid = tid;
116
+ // app.md5 = md5;
117
+ app.serial = serial;
118
+ }
119
+
120
+ function handleUri(app: any) {
121
+ app.uri = useSystemUri;
122
+ app.asset = useAssetUri;
123
+ }
124
+
125
+ function handlerHelper(app: any) {
126
+ app.domready = domready;
127
+ app.selectOne = selectOne;
128
+ app.selectAll = selectAll;
129
+ app.each = selectAll;
130
+ app.getBoundedInstance = getBoundedInstance;
131
+ app.getBoundedInstanceList = getBoundedInstanceList;
132
+ app.module = module;
133
+ app.h = h;
134
+ app.html = html;
135
+ // app.$get = get;
136
+ // app.$set = set;
137
+ app.delegate = delegate;
138
+ app.debounce = debounce;
139
+ app.throttle = throttle;
140
+ app.isDebug = isDebug;
141
+ app.confirm = simpleConfirm;
142
+ app.alert = simpleAlert;
143
+ app.numberFormat = numberFormat;
144
+ app.sprintf = sprintf;
145
+ app.vsprintf = vsprintf;
146
+ // app.genRandomString = genRandomString;
147
+ // app.defaultsDeep = defaultsDeep;
148
+ }
149
+
150
+ function handleUI(app: any) {
151
+ app.$ui ??= {};
152
+ app.$ui.addMessage = renderMessage;
153
+ app.$ui.clearMessages = clearMessages;
154
+ app.$ui.notify = simpleNotify;
155
+ app.$ui.clearNotifies = clearNotifies;
156
+
157
+ app.$ui.loadAlpine = loadAlpine;
158
+ app.$ui.initAlpine = initAlpineComponent;
159
+ app.$ui.beforeAlpineInit = prepareAlpine;
160
+ app.$ui.prepareAlpine = prepareAlpine;
161
+
162
+ app.$ui.mark = mark;
163
+ app.$ui.tomSelect = useTomSelect;
164
+ app.$ui.slideUp = slideUp;
165
+ app.$ui.slideDown = slideDown;
166
+ app.$ui.slideToggle = slideToggle;
167
+ app.$ui.fadeOut = fadeOut;
168
+ app.$ui.fadeIn = fadeIn;
169
+ app.$ui.highlight = highlight;
170
+ app.$ui.colorPicker = useColorPicker;
171
+ app.$ui.disableOnSubmit = useDisableOnSubmit;
172
+ app.$ui.disableIfStackNotEmpty = useDisableIfStackNotEmpty;
173
+ app.$ui.checkboxesMultiSelect = useCheckboxesMultiSelect;
174
+ app.$ui.keepAlive = useKeepAlive;
175
+ app.$ui.bootstrap = {
176
+ tooltip: useBs5Tooltip
177
+ };
178
+ }
179
+
180
+ async function handleFormGrid(app: any) {
181
+ await useFormAsync();
182
+ await useGridAsync();
183
+
184
+ app.form = useForm;
185
+ app.grid = useGrid;
186
+ }
@@ -1,125 +1,125 @@
1
- import { isDebug } from '../service';
2
-
3
- const imports: Record<string, { promise: Promise<any>; resolve?: Function; }> = {};
4
-
5
- export class LegacyLoader {
6
- static install(app: any) {
7
- const loader = app.$loader = new this(app);
8
-
9
- app.import = loader.import.bind(loader);
10
- app.importSync = loader.importSync.bind(loader);
11
- app.importCSS = loader.importCSS.bind(loader);
12
- app.minFileName = loader.minFileName.bind(loader);
13
- app.afterImported = loader.afterImported.bind(loader);
14
- }
15
-
16
- constructor(protected app: any) {
17
- //
18
- }
19
-
20
- doImport(src: string): Promise<any> {
21
- return S.import(src);
22
- }
23
-
24
- /**
25
- * Import modules or scripts.
26
- */
27
- import(...src: any[]): Promise<any|any[]> {
28
- if (src.length === 1) {
29
- return this.doImport(src[0]);
30
- }
31
-
32
- const promises: Promise<any>[] = [];
33
-
34
- src.forEach((link) => {
35
- promises.push(
36
- link instanceof Promise ? link : this.doImport(link)
37
- );
38
- });
39
-
40
- return Promise.all(promises);
41
- }
42
-
43
- /**
44
- * Import sync.
45
- */
46
- importSync(...src: any): Promise<any|any[]> {
47
- let promise: Promise<any> = Promise.resolve();
48
- let url: string[];
49
- const modules: any[] = [];
50
-
51
- while (url = src.shift()) {
52
- if (!Array.isArray(url)) {
53
- url = [ url ];
54
- }
55
-
56
- const target = url;
57
- promise = promise.then(
58
- () => this.import(...target).then((m) => {
59
- modules.push(m);
60
- return modules;
61
- })
62
- );
63
- }
64
-
65
- return promise;
66
- }
67
-
68
- /**
69
- * Import CSS files.
70
- */
71
- async importCSS(...src: any): Promise<any|any[]> {
72
- let modules: any = await this.import(...src);
73
-
74
- if (!Array.isArray(modules)) {
75
- modules = [modules];
76
- }
77
-
78
- const styles: CSSStyleSheet[] = (modules as any[]).map(module => module.default);
79
-
80
- document.adoptedStyleSheets = [...document.adoptedStyleSheets, ...styles];
81
- }
82
-
83
- minFileName(fileName: string): string {
84
- const segments = fileName.split('.');
85
- const ext = segments.pop();
86
-
87
- if (isDebug()) {
88
- return segments.join('.') + '.min.' + ext;
89
- }
90
-
91
- return fileName;
92
- }
93
-
94
- asImported(name: string) {
95
- if (!imports[name]) {
96
- imports[name] = {
97
- promise: Promise.resolve(),
98
- resolve: undefined
99
- };
100
- } else {
101
- imports[name]?.resolve?.();
102
- }
103
- }
104
-
105
- /**
106
- * Add after import hook for some url or id.
107
- */
108
- afterImported(name: string, callback: (resolve: Function, reject?: Function) => void): Promise<any> {
109
- if (!imports[name]) {
110
- let r;
111
- imports[name] = {
112
- promise: new Promise((resolve) => {
113
- r = resolve;
114
- }),
115
- };
116
-
117
- imports[name].resolve = r;
118
- }
119
-
120
- imports[name].promise.then(callback);
121
-
122
- return imports[name].promise;
123
- }
124
- }
125
-
1
+ import { isDebug } from '../service';
2
+
3
+ const imports: Record<string, { promise: Promise<any>; resolve?: Function; }> = {};
4
+
5
+ export class LegacyLoader {
6
+ static install(app: any) {
7
+ const loader = app.$loader = new this(app);
8
+
9
+ app.import = loader.import.bind(loader);
10
+ app.importSync = loader.importSync.bind(loader);
11
+ app.importCSS = loader.importCSS.bind(loader);
12
+ app.minFileName = loader.minFileName.bind(loader);
13
+ app.afterImported = loader.afterImported.bind(loader);
14
+ }
15
+
16
+ constructor(protected app: any) {
17
+ //
18
+ }
19
+
20
+ doImport(src: string): Promise<any> {
21
+ return S.import(src);
22
+ }
23
+
24
+ /**
25
+ * Import modules or scripts.
26
+ */
27
+ import(...src: any[]): Promise<any|any[]> {
28
+ if (src.length === 1) {
29
+ return this.doImport(src[0]);
30
+ }
31
+
32
+ const promises: Promise<any>[] = [];
33
+
34
+ src.forEach((link) => {
35
+ promises.push(
36
+ link instanceof Promise ? link : this.doImport(link)
37
+ );
38
+ });
39
+
40
+ return Promise.all(promises);
41
+ }
42
+
43
+ /**
44
+ * Import sync.
45
+ */
46
+ importSync(...src: any): Promise<any|any[]> {
47
+ let promise: Promise<any> = Promise.resolve();
48
+ let url: string[];
49
+ const modules: any[] = [];
50
+
51
+ while (url = src.shift()) {
52
+ if (!Array.isArray(url)) {
53
+ url = [ url ];
54
+ }
55
+
56
+ const target = url;
57
+ promise = promise.then(
58
+ () => this.import(...target).then((m) => {
59
+ modules.push(m);
60
+ return modules;
61
+ })
62
+ );
63
+ }
64
+
65
+ return promise;
66
+ }
67
+
68
+ /**
69
+ * Import CSS files.
70
+ */
71
+ async importCSS(...src: any): Promise<any|any[]> {
72
+ let modules: any = await this.import(...src);
73
+
74
+ if (!Array.isArray(modules)) {
75
+ modules = [modules];
76
+ }
77
+
78
+ const styles: CSSStyleSheet[] = (modules as any[]).map(module => module.default);
79
+
80
+ document.adoptedStyleSheets = [...document.adoptedStyleSheets, ...styles];
81
+ }
82
+
83
+ minFileName(fileName: string): string {
84
+ const segments = fileName.split('.');
85
+ const ext = segments.pop();
86
+
87
+ if (isDebug()) {
88
+ return segments.join('.') + '.min.' + ext;
89
+ }
90
+
91
+ return fileName;
92
+ }
93
+
94
+ asImported(name: string) {
95
+ if (!imports[name]) {
96
+ imports[name] = {
97
+ promise: Promise.resolve(),
98
+ resolve: undefined
99
+ };
100
+ } else {
101
+ imports[name]?.resolve?.();
102
+ }
103
+ }
104
+
105
+ /**
106
+ * Add after import hook for some url or id.
107
+ */
108
+ afterImported(name: string, callback: (resolve: Function, reject?: Function) => void): Promise<any> {
109
+ if (!imports[name]) {
110
+ let r;
111
+ imports[name] = {
112
+ promise: new Promise((resolve) => {
113
+ r = resolve;
114
+ }),
115
+ };
116
+
117
+ imports[name].resolve = r;
118
+ }
119
+
120
+ imports[name].promise.then(callback);
121
+
122
+ return imports[name].promise;
123
+ }
124
+ }
125
+