smbls 3.1.2 → 3.2.7

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.
@@ -0,0 +1,740 @@
1
+ "use strict";
2
+ var Smbls = (() => {
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
10
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
11
+ }) : x)(function(x) {
12
+ if (typeof require !== "undefined") return require.apply(this, arguments);
13
+ throw Error('Dynamic require of "' + x + '" is not supported');
14
+ });
15
+ var __export = (target, all) => {
16
+ for (var name in all)
17
+ __defProp(target, name, { get: all[name], enumerable: true });
18
+ };
19
+ var __copyProps = (to, from, except, desc) => {
20
+ if (from && typeof from === "object" || typeof from === "function") {
21
+ for (let key of __getOwnPropNames(from))
22
+ if (!__hasOwnProp.call(to, key) && key !== except)
23
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
24
+ }
25
+ return to;
26
+ };
27
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
28
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
29
+ // If the importer is in node compatibility mode or this is not an ESM
30
+ // file that has been converted to a CommonJS file using a Babel-
31
+ // compatible transform (i.e. "__esModule" has not been set), then set
32
+ // "default" to the CommonJS "module.exports" for node compatibility.
33
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
34
+ mod
35
+ ));
36
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
37
+
38
+ // index.js
39
+ var index_exports = {};
40
+ __export(index_exports, {
41
+ DEFAULT_CONTEXT: () => DEFAULT_CONTEXT,
42
+ DESIGN_SYSTEM_OPTIONS: () => DESIGN_SYSTEM_OPTIONS,
43
+ DYNAMIC_JSON: () => import_dynamic.default,
44
+ ROUTER_OPTIONS: () => ROUTER_OPTIONS,
45
+ applyCSS: () => applyCSS,
46
+ create: () => create,
47
+ createAsync: () => createAsync,
48
+ createSkeleton: () => createSkeleton,
49
+ createSync: () => createSync,
50
+ init: () => init,
51
+ reinit: () => reinit,
52
+ setClass: () => setClass,
53
+ updateVars: () => updateVars
54
+ });
55
+ __reExport(index_exports, __require("@domql/utils"));
56
+ __reExport(index_exports, __require("attrs-in-props"));
57
+ __reExport(index_exports, __require("css-in-props"));
58
+ __reExport(index_exports, __require("@symbo.ls/default-config"));
59
+ __reExport(index_exports, __require("@symbo.ls/emotion"));
60
+ __reExport(index_exports, __require("@symbo.ls/scratch"));
61
+ __reExport(index_exports, __require("@symbo.ls/uikit"));
62
+ __reExport(index_exports, __require("@symbo.ls/smbls-utils"));
63
+
64
+ // src/index.js
65
+ var import_utils7 = __require("@domql/utils");
66
+
67
+ // src/utilImports.js
68
+ var utilImports_exports = {};
69
+ __export(utilImports_exports, {
70
+ applyCSS: () => applyCSS,
71
+ init: () => init,
72
+ reinit: () => reinit,
73
+ scratchSystem: () => import_scratch2.scratchSystem,
74
+ scratchUtils: () => import_scratch2.scratchUtils,
75
+ set: () => import_scratch2.set
76
+ });
77
+ var import_scratch2 = __require("@symbo.ls/scratch");
78
+ __reExport(utilImports_exports, __require("@domql/utils"));
79
+ __reExport(utilImports_exports, __require("@symbo.ls/smbls-utils"));
80
+
81
+ // src/init.js
82
+ var import_scratch = __require("@symbo.ls/scratch");
83
+ var import_utils = __require("@domql/utils");
84
+ var import_emotion = __require("@symbo.ls/emotion");
85
+ var import_dynamic = __toESM(__require("../dynamic.json"), 1);
86
+ var CONFIG = (0, import_scratch.getActiveConfig)();
87
+ var mergeWithLocalFile = (config = CONFIG, options) => {
88
+ const rcfile = (0, import_utils.isObject)(options.localFile) ? options.localFile : import_dynamic.default || {};
89
+ const clonedFile = (0, import_utils.deepClone)(rcfile.designSystem || {});
90
+ return (0, import_utils.deepMerge)(config, clonedFile);
91
+ };
92
+ var SET_OPTIONS = {
93
+ emotion: import_emotion.emotion,
94
+ useVariable: true,
95
+ useReset: true,
96
+ useFontImport: true,
97
+ useIconSprite: true,
98
+ useDocumentTheme: true,
99
+ useSvgSprite: true
100
+ };
101
+ var init = (config, options = SET_OPTIONS) => {
102
+ const emotion = options.emotion || import_emotion.emotion;
103
+ const resultConfig = mergeWithLocalFile(config || {}, options);
104
+ const conf = (0, import_scratch.set)(
105
+ {
106
+ verbose: options.verbose,
107
+ useReset: options.useReset,
108
+ useFontImport: options.useFontImport,
109
+ useVariable: options.useVariable,
110
+ useSvgSprite: options.useSvgSprite,
111
+ useDocumentTheme: options.useDocumentTheme,
112
+ useIconSprite: options.useIconSprite,
113
+ useDefaultConfig: options.useDefaultConfig,
114
+ globalTheme: options.globalTheme,
115
+ ...resultConfig
116
+ },
117
+ { newConfig: options.newConfig }
118
+ );
119
+ const FontFace = (0, import_scratch.getFontFaceString)(conf.FONT);
120
+ const useReset = conf.useReset;
121
+ const useVariable = conf.useVariable;
122
+ const useFontImport = conf.useFontImport;
123
+ const useSvgSprite = conf.useSvgSprite;
124
+ const hasSvgs = config.svg || config.SVG;
125
+ const useIconSprite = conf.useIconSprite;
126
+ const hasIcons = config.icons || config.ICONS;
127
+ if (useFontImport) emotion.injectGlobal(FontFace);
128
+ if (useVariable) emotion.injectGlobal({ ":root": conf.CSS_VARS });
129
+ if (useReset) emotion.injectGlobal(conf.RESET);
130
+ if (conf.ANIMATION) {
131
+ const keyframesCSS = {};
132
+ for (const name in conf.ANIMATION) {
133
+ keyframesCSS[`@keyframes ${name}`] = conf.ANIMATION[name];
134
+ }
135
+ emotion.injectGlobal(keyframesCSS);
136
+ }
137
+ if (hasSvgs) (0, import_scratch.appendSVGSprite)(hasSvgs, { document: options.document });
138
+ else if (useSvgSprite)
139
+ (0, import_scratch.appendSVGSprite)(conf.SVG, { document: options.document });
140
+ if (hasIcons) (0, import_scratch.appendSvgIconsSprite)(hasIcons, { document: options.document });
141
+ else if (useIconSprite)
142
+ (0, import_scratch.appendSvgIconsSprite)(conf.ICONS, { document: options.document });
143
+ return conf;
144
+ };
145
+ var UPDATE_OPTIONS = {
146
+ emotion: import_emotion.emotion
147
+ };
148
+ var reinit = (config, options = UPDATE_OPTIONS) => {
149
+ const emotion = options.emotion || import_emotion.emotion;
150
+ const resultConfig = mergeWithLocalFile(config || {}, options);
151
+ const conf = (0, import_scratch.set)({
152
+ verbose: false,
153
+ ...resultConfig
154
+ });
155
+ if (!options.preventInject) {
156
+ emotion.injectGlobal({ ":root": conf.CSS_VARS });
157
+ emotion.injectGlobal(conf.RESET);
158
+ }
159
+ return conf;
160
+ };
161
+ var applyCSS = (styles, options = UPDATE_OPTIONS) => {
162
+ const emotion = options.emotion || import_emotion.emotion;
163
+ emotion.injectGlobal(styles);
164
+ };
165
+ var updateVars = (config, options = UPDATE_OPTIONS) => {
166
+ const emotion = options.emotion || import_emotion.emotion;
167
+ emotion.injectGlobal({ ":root": config.CSS_VARS });
168
+ };
169
+ var setClass = (props, options = UPDATE_OPTIONS) => {
170
+ };
171
+
172
+ // src/utilImports.js
173
+ __reExport(utilImports_exports, __require("@domql/report"));
174
+ __reExport(utilImports_exports, __require("@domql/router"));
175
+
176
+ // src/router.js
177
+ var import_utils2 = __require("@domql/utils");
178
+ var import_router = __require("@domql/router");
179
+ var DEFAULT_ROUTING_OPTIONS = {
180
+ initRouter: true,
181
+ injectRouterInLinkComponent: true,
182
+ popState: true
183
+ };
184
+ var initRouter = (element, context) => {
185
+ if (context.router === false) return;
186
+ else if (context.router === true) context.router = DEFAULT_ROUTING_OPTIONS;
187
+ else context.router = (0, import_utils2.merge)(context.router || {}, DEFAULT_ROUTING_OPTIONS);
188
+ const routerOptions = context.router;
189
+ const onRouterRenderDefault = async (el, s) => {
190
+ const { pathname, search, hash } = import_utils2.window.location;
191
+ const url = pathname + search + hash;
192
+ if (el.routes) await (0, import_router.router)(url, el, {}, { initialRender: true });
193
+ };
194
+ const hasRenderRouter = element.on && !(0, import_utils2.isUndefined)(element.on.renderRouter) || !(0, import_utils2.isUndefined)(element.onRenderRouter);
195
+ if (routerOptions && routerOptions.initRouter && !hasRenderRouter) {
196
+ if (element.on) {
197
+ element.on.renderRouter = onRouterRenderDefault;
198
+ } else {
199
+ element.on = {
200
+ renderRouter: onRouterRenderDefault
201
+ };
202
+ }
203
+ }
204
+ injectRouterInLinkComponent(context, routerOptions);
205
+ return routerOptions;
206
+ };
207
+ var popStateFired;
208
+ var onpopstateRouter = (element, context) => {
209
+ if (popStateFired) return;
210
+ popStateFired = true;
211
+ const routerOptions = context.router || DEFAULT_ROUTING_OPTIONS;
212
+ if (!routerOptions.popState) return;
213
+ const router = context.utils && context.utils.router ? context.utils.router : import_router.router;
214
+ import_utils2.window.onpopstate = async (e) => {
215
+ const { pathname, search, hash } = import_utils2.window.location;
216
+ const url = pathname + search + hash;
217
+ await element.call(
218
+ "router",
219
+ url,
220
+ element,
221
+ {},
222
+ { pushState: false, scrollToTop: false, level: 0, event: e }
223
+ );
224
+ };
225
+ };
226
+ var injectRouterInLinkComponent = (context, routerOptions) => {
227
+ const { components } = context;
228
+ if (routerOptions && routerOptions.injectRouterInLinkComponent) {
229
+ return (0, import_utils2.deepMerge)(
230
+ components["Link"] || components["smbls.Link"],
231
+ components["RouterLink"] || components["smbls.RouterLink"]
232
+ );
233
+ }
234
+ };
235
+
236
+ // src/fetchOnCreate.js
237
+ var import_utils3 = __require("@domql/utils");
238
+ var import_fetch = __require("@symbo.ls/fetch");
239
+ var fetchSync = async (key, options) => {
240
+ if (key && options.editor) {
241
+ try {
242
+ if (!options.editor.async) await (0, import_fetch.fetchProject)(key, options);
243
+ } catch (e) {
244
+ console.error(e);
245
+ }
246
+ }
247
+ };
248
+ var fetchAsync = (app, key, options, callback) => {
249
+ if (key && options.editor) {
250
+ try {
251
+ if (options.editor.async) {
252
+ (0, import_fetch.fetchProjectAsync)(key, options, callback || ((data) => {
253
+ const designSystem = data.designSystem;
254
+ if ((0, import_utils3.isObject)(designSystem)) {
255
+ options.utils.init(designSystem);
256
+ }
257
+ if ((0, import_utils3.isObject)(data.state)) {
258
+ app.state.set(data.state);
259
+ }
260
+ }));
261
+ }
262
+ } catch (e) {
263
+ console.error(e);
264
+ }
265
+ }
266
+ };
267
+
268
+ // src/define.js
269
+ var defaultDefine = {
270
+ routes: (param) => param,
271
+ // deps: (param, el) => param || el.parent.deps,
272
+ $router: async (param, el) => {
273
+ if (!param) return;
274
+ const obj = { tag: "fragment", ...param };
275
+ const set3 = async () => {
276
+ await el.set(obj, { preventDefineUpdate: "$router" });
277
+ };
278
+ if (el.props && el.props.lazyLoad) {
279
+ window.requestAnimationFrame(set3);
280
+ } else await set3();
281
+ return obj;
282
+ }
283
+ };
284
+
285
+ // src/options.js
286
+ var import_package = __require("../package.json");
287
+ var DESIGN_SYSTEM_OPTIONS = {
288
+ useReset: true,
289
+ useVariable: true,
290
+ useIconSprite: true,
291
+ useSvgSprite: true,
292
+ useDocumentTheme: true,
293
+ useDefaultIcons: true,
294
+ useFontImport: true,
295
+ useDefaultConfig: true
296
+ };
297
+ var ROUTER_OPTIONS = {
298
+ initRouter: true,
299
+ popState: true,
300
+ injectRouterInLinkComponent: true
301
+ };
302
+ var DEFAULT_CONTEXT = {
303
+ ...DESIGN_SYSTEM_OPTIONS,
304
+ router: ROUTER_OPTIONS,
305
+ version: import_package.version
306
+ };
307
+ var CREATE_OPTIONS = {
308
+ state: {},
309
+ pages: {},
310
+ components: {},
311
+ router: ROUTER_OPTIONS,
312
+ define: defaultDefine
313
+ };
314
+ var options_default = CREATE_OPTIONS;
315
+
316
+ // src/index.js
317
+ var import_dynamic2 = __toESM(__require("../dynamic.json"), 1);
318
+
319
+ // src/createDomql.js
320
+ var import_domql = __toESM(__require("domql"), 1);
321
+ var uikit2 = __toESM(__require("@symbo.ls/uikit"), 1);
322
+ var import_css_in_props = __require("css-in-props");
323
+ var import_utils6 = __require("@domql/utils");
324
+ var import_element = __require("@domql/element");
325
+
326
+ // src/syncExtend.js
327
+ var import_utils4 = __require("@domql/utils");
328
+ var import_sync = __require("@symbo.ls/sync");
329
+ var initializeExtend = (app, ctx) => {
330
+ return (0, import_utils4.isObjectLike)(app.extends) ? app.extends : [];
331
+ };
332
+ var initializeSync = (app, ctx) => {
333
+ const { editor } = ctx;
334
+ if (!editor) return;
335
+ const liveSync = (0, import_utils4.isUndefined)(editor.liveSync) ? (0, import_utils4.isDevelopment)() : editor.liveSync;
336
+ if (liveSync) {
337
+ if ((0, import_utils4.isArray)(app.extends)) app.extends.push(import_sync.SyncComponent);
338
+ else if (app.extends) {
339
+ app.extends = [app.extends, import_sync.SyncComponent];
340
+ } else {
341
+ app.extends = [import_sync.SyncComponent];
342
+ }
343
+ }
344
+ };
345
+ var initializeNotifications = (app, ctx) => {
346
+ const { editor } = ctx;
347
+ if (!editor) return;
348
+ const verbose = (0, import_utils4.isUndefined)(editor.verbose) ? (0, import_utils4.isDevelopment)() || ctx.verbose : editor.verbose;
349
+ if (verbose) {
350
+ if ((0, import_utils4.isArray)(app.extends)) app.extends.push(import_sync.Notifications);
351
+ else if (app.extends) {
352
+ app.extends = [app.extends, import_sync.Notifications];
353
+ } else {
354
+ app.extends = [import_sync.Notifications];
355
+ }
356
+ }
357
+ };
358
+
359
+ // src/prepare.js
360
+ var import_utils5 = __require("@domql/utils");
361
+ var import_emotion2 = __require("@symbo.ls/emotion");
362
+ var uikit = __toESM(__require("@symbo.ls/uikit"), 1);
363
+ var routerUtils = __toESM(__require("@domql/router"), 1);
364
+ var prepareWindow = (context) => {
365
+ if (typeof window === "undefined") window = globalThis || {};
366
+ if (typeof document === "undefined") {
367
+ if (!window.document) window.document = globalThis.document || { body: {} };
368
+ document = window.document;
369
+ }
370
+ context.document = context.document || document;
371
+ context.window = context.window || window;
372
+ return context.window;
373
+ };
374
+ function onlyDotsAndNumbers(str) {
375
+ return /^[0-9.]+$/.test(str) && str !== "";
376
+ }
377
+ var CDN_PROVIDERS = {
378
+ skypack: {
379
+ url: "https://cdn.skypack.dev",
380
+ formatUrl: (pkg, version2) => `${CDN_PROVIDERS.skypack.url}/${pkg}${version2 !== "latest" ? `@${version2}` : ""}`
381
+ },
382
+ esmsh: {
383
+ url: "https://esm.sh",
384
+ formatUrl: (pkg, version2) => `${CDN_PROVIDERS.esmsh.url}/${pkg}${version2 !== "latest" ? `@${version2}` : ""}`
385
+ },
386
+ unpkg: {
387
+ url: "https://unpkg.com",
388
+ formatUrl: (pkg, version2) => `${CDN_PROVIDERS.unpkg.url}/${pkg}${version2 !== "latest" ? `@${version2}` : ""}?module`
389
+ },
390
+ jsdelivr: {
391
+ url: "https://cdn.jsdelivr.net/npm",
392
+ formatUrl: (pkg, version2) => `${CDN_PROVIDERS.jsdelivr.url}/${pkg}${version2 !== "latest" ? `@${version2}` : ""}/+esm`
393
+ },
394
+ symbols: {
395
+ url: "https://pkg.symbo.ls",
396
+ formatUrl: (pkg, version2) => {
397
+ if (pkg.split("/").length > 2 || !onlyDotsAndNumbers(version2)) {
398
+ return `${CDN_PROVIDERS.symbols.url}/${pkg}`;
399
+ }
400
+ return `${CDN_PROVIDERS.symbols.url}/${pkg}/${version2}.js`;
401
+ }
402
+ }
403
+ };
404
+ var PACKAGE_MANAGER_TO_CDN = {
405
+ "esm.sh": "esmsh",
406
+ "unpkg": "unpkg",
407
+ "skypack": "skypack",
408
+ "jsdelivr": "jsdelivr",
409
+ "pkg.symbo.ls": "symbols"
410
+ };
411
+ var getCdnProviderFromConfig = (symbolsConfig = {}) => {
412
+ const { packageManager } = symbolsConfig;
413
+ return PACKAGE_MANAGER_TO_CDN[packageManager] || null;
414
+ };
415
+ var getCDNUrl = (packageName, version2 = "latest", provider = "esmsh") => {
416
+ const cdnConfig = CDN_PROVIDERS[provider] || CDN_PROVIDERS.esmsh;
417
+ return cdnConfig.formatUrl(packageName, version2);
418
+ };
419
+ var UIkitWithPrefix = (prefix = "smbls") => {
420
+ const newObj = {};
421
+ for (const key in uikit) {
422
+ if (Object.prototype.hasOwnProperty.call(uikit, key)) {
423
+ if ((0, import_utils5.matchesComponentNaming)(key)) {
424
+ newObj[`smbls.${key}`] = uikit[key];
425
+ } else {
426
+ newObj[key] = uikit[key];
427
+ }
428
+ }
429
+ }
430
+ return newObj;
431
+ };
432
+ var prepareComponents = (context) => {
433
+ return context.components ? { ...UIkitWithPrefix(), ...context.components } : UIkitWithPrefix();
434
+ };
435
+ var prepareUtils = (context) => {
436
+ return {
437
+ ...utilImports_exports,
438
+ ...routerUtils,
439
+ ...import_scratch2.scratchUtils,
440
+ ...context.utils,
441
+ ...context.snippets,
442
+ ...context.functions
443
+ };
444
+ };
445
+ var prepareMethods = (context) => {
446
+ return {
447
+ ...context.methods || {},
448
+ require: context.utils.require,
449
+ requireOnDemand: context.utils.requireOnDemand,
450
+ router: context.utils.router
451
+ };
452
+ };
453
+ var cachedDeps = {};
454
+ var prepareDependencies = async ({
455
+ dependencies,
456
+ dependenciesOnDemand,
457
+ document: document2,
458
+ preventCaching = false,
459
+ cdnProvider,
460
+ packageManager,
461
+ symbolsConfig
462
+ }) => {
463
+ if (!cdnProvider) {
464
+ cdnProvider = PACKAGE_MANAGER_TO_CDN[packageManager] || getCdnProviderFromConfig(symbolsConfig) || "esmsh";
465
+ }
466
+ if (!dependencies) return null;
467
+ let hasAny = false;
468
+ for (const _k in dependencies) {
469
+ hasAny = true;
470
+ break;
471
+ }
472
+ if (!hasAny) return null;
473
+ for (const dependency in dependencies) {
474
+ const version2 = dependencies[dependency];
475
+ if (dependenciesOnDemand && dependenciesOnDemand[dependency]) {
476
+ continue;
477
+ }
478
+ const random = (0, import_utils5.isDevelopment)() && preventCaching ? `?${Math.random()}` : "";
479
+ const url = getCDNUrl(dependency, version2, cdnProvider) + random;
480
+ try {
481
+ if (cachedDeps[dependency]) return;
482
+ cachedDeps[dependency] = true;
483
+ await utilImports_exports.loadRemoteScript(url, { document: document2, type: "module" });
484
+ } catch (e) {
485
+ console.error(`Failed to load ${dependency} from ${cdnProvider}:`, e);
486
+ if (cdnProvider !== "symbols") {
487
+ try {
488
+ const fallbackUrl = getCDNUrl(dependency, version2, "symbols") + random;
489
+ await utilImports_exports.loadRemoteScript(fallbackUrl, { document: document2 });
490
+ console.log(
491
+ `Successfully loaded ${dependency} from fallback (symbols.ls)`
492
+ );
493
+ } catch (fallbackError) {
494
+ console.error(
495
+ `Failed to load ${dependency} from fallback:`,
496
+ fallbackError
497
+ );
498
+ }
499
+ }
500
+ }
501
+ }
502
+ return dependencies;
503
+ };
504
+ var prepareRequire = async (packages, ctx) => {
505
+ const windowOpts = ctx.window || window;
506
+ const defaultProvider = ctx.cdnProvider || getCdnProviderFromConfig(ctx.symbolsConfig) || "esmsh";
507
+ const initRequire = async (ctx2) => async (key, provider) => {
508
+ const windowOpts2 = ctx2.window || window;
509
+ const pkg = windowOpts2.packages[key];
510
+ if (typeof pkg === "function") return pkg();
511
+ return pkg;
512
+ };
513
+ const initRequireOnDemand = async (ctx2) => async (key, provider = defaultProvider) => {
514
+ const { dependenciesOnDemand } = ctx2;
515
+ const documentOpts = ctx2.document || document;
516
+ const windowOpts2 = ctx2.window || window;
517
+ if (!windowOpts2.packages[key]) {
518
+ const random = (0, import_utils5.isDevelopment)() ? `?${Math.random()}` : "";
519
+ if (dependenciesOnDemand && dependenciesOnDemand[key]) {
520
+ const version2 = dependenciesOnDemand[key];
521
+ const url = getCDNUrl(key, version2, provider) + random;
522
+ try {
523
+ await ctx2.utils.loadRemoteScript(url, {
524
+ window: windowOpts2,
525
+ document: documentOpts
526
+ });
527
+ } catch (e) {
528
+ console.error(`Failed to load ${key} from ${provider}:`, e);
529
+ if (provider !== "symbols") {
530
+ const fallbackUrl = getCDNUrl(key, version2, "symbols") + random;
531
+ await ctx2.utils.loadRemoteScript(fallbackUrl, {
532
+ window: windowOpts2,
533
+ document: documentOpts
534
+ });
535
+ }
536
+ }
537
+ } else {
538
+ const url = getCDNUrl(key, "latest", provider) + random;
539
+ try {
540
+ await ctx2.utils.loadRemoteScript(url, {
541
+ window: windowOpts2,
542
+ document: documentOpts
543
+ });
544
+ } catch (e) {
545
+ console.error(`Failed to load ${key} from ${provider}:`, e);
546
+ if (provider !== "symbols") {
547
+ const fallbackUrl = getCDNUrl(key, "latest", "symbols") + random;
548
+ await ctx2.utils.loadRemoteScript(fallbackUrl, {
549
+ window: windowOpts2,
550
+ document: documentOpts
551
+ });
552
+ }
553
+ }
554
+ windowOpts2.packages[key] = "loadedOnDeman";
555
+ }
556
+ }
557
+ return await windowOpts2.require(key, provider);
558
+ };
559
+ if (windowOpts.packages) {
560
+ windowOpts.packages = (0, import_utils5.merge)(windowOpts.packages, packages);
561
+ } else {
562
+ windowOpts.packages = packages;
563
+ }
564
+ if (!windowOpts.require) {
565
+ ctx.utils.require = await initRequire(ctx);
566
+ windowOpts.require = ctx.utils.require;
567
+ }
568
+ if (!windowOpts.requireOnDemand) {
569
+ ctx.utils.requireOnDemand = await initRequireOnDemand(ctx);
570
+ windowOpts.requireOnDemand = ctx.utils.requireOnDemand;
571
+ }
572
+ };
573
+ var prepareDesignSystem = (key, context) => {
574
+ const [scratcDesignhSystem, emotion, registry] = (0, import_emotion2.initEmotion)(key, context);
575
+ return [scratcDesignhSystem, emotion, registry];
576
+ };
577
+ var prepareState = (app, context) => {
578
+ const state = {};
579
+ if (context.state) utilImports_exports.deepMerge(state, context.state);
580
+ if (app && app.state) (0, import_utils5.deepMerge)(state, app.state);
581
+ state.isRootState = true;
582
+ return (0, import_utils5.deepClone)(state);
583
+ };
584
+ var preparePages = (app, context) => {
585
+ if ((0, import_utils5.isObject)(app.routes) && (0, import_utils5.isObject)(context.pages)) {
586
+ (0, import_utils5.merge)(app.routes, context.pages);
587
+ }
588
+ const pages = app.routes || context.pages || {};
589
+ for (const v in pages) {
590
+ if (v.charCodeAt(0) === 47) continue;
591
+ const index = v === "index" ? "" : v;
592
+ pages["/" + index] = pages[v];
593
+ delete pages[v];
594
+ }
595
+ return pages;
596
+ };
597
+ var prepareSharedLibs = (context) => {
598
+ const sharedLibraries = context.sharedLibraries;
599
+ for (let i = 0; i < sharedLibraries.length; i++) {
600
+ const sharedLib = sharedLibraries[i];
601
+ if (context.type === "template") {
602
+ overwriteShallow(context.designSystem, sharedLib.designSystem);
603
+ (0, import_utils5.deepMerge)(context, sharedLib, ["designSystem"], 1);
604
+ } else {
605
+ (0, import_utils5.deepMerge)(context, sharedLib, [], 1);
606
+ }
607
+ }
608
+ };
609
+
610
+ // src/createDomql.js
611
+ var prepareContext = async (app, context = {}) => {
612
+ const key = context.key = context.key || ((0, import_utils6.isString)(app) ? app : "smblsapp");
613
+ context.define = context.define || defaultDefine;
614
+ context.cssPropsRegistry = import_css_in_props.CSS_PROPS_REGISTRY;
615
+ context.window = prepareWindow(context);
616
+ if (context.sharedLibraries && context.sharedLibraries.length) {
617
+ prepareSharedLibs(context);
618
+ }
619
+ const [scratcDesignSystem, emotion, registry] = prepareDesignSystem(
620
+ key,
621
+ context
622
+ );
623
+ context.designSystem = scratcDesignSystem;
624
+ context.registry = registry;
625
+ context.emotion = emotion;
626
+ const state = prepareState(app, context);
627
+ context.state = state;
628
+ context.pages = preparePages(app, context);
629
+ context.components = prepareComponents(context);
630
+ context.utils = prepareUtils(context);
631
+ if (PACKAGE_MANAGER_TO_CDN[context.packageManager]) {
632
+ context.dependencies = await prepareDependencies(context);
633
+ }
634
+ context.methods = prepareMethods(context);
635
+ context.routerOptions = initRouter(app, context);
636
+ context.defaultExtends = [uikit2.Box];
637
+ context.snippets = context.snippets || {};
638
+ context.functions = context.functions || {};
639
+ return context;
640
+ };
641
+ var createDomqlElement = async (app, ctx) => {
642
+ if (!(0, import_utils6.isObject)(ctx)) ctx = {};
643
+ if ((0, import_utils6.isNode)(app)) {
644
+ app = {};
645
+ ctx.parent = app;
646
+ } else if ((0, import_utils6.isString)(app)) {
647
+ app = {};
648
+ ctx.key = app;
649
+ } else if (!(0, import_utils6.isObject)(app)) {
650
+ app = {};
651
+ }
652
+ await prepareContext(app, ctx);
653
+ app.extends = initializeExtend(app, ctx);
654
+ app.routes = ctx.pages;
655
+ app.state = ctx.state;
656
+ app.context = ctx;
657
+ app.data = app.data || {};
658
+ app.data.frameListeners = (0, import_element.initAnimationFrame)(ctx);
659
+ await prepareRequire(
660
+ {
661
+ functions: ctx.functions,
662
+ utils: ctx.utils,
663
+ snippets: ctx.snippets,
664
+ ...ctx.files
665
+ },
666
+ ctx
667
+ );
668
+ initializeSync(app, ctx);
669
+ initializeNotifications(app, ctx);
670
+ const parentNode = ctx.parent || ctx.document.body;
671
+ const domqlCreate = import_domql.default.default && import_domql.default.default.create || import_domql.default.create;
672
+ const smblsApp = await domqlCreate(app, parentNode, ctx.key, {
673
+ verbose: ctx.verbose,
674
+ ...ctx.domqlOptions
675
+ });
676
+ return smblsApp;
677
+ };
678
+
679
+ // src/index.js
680
+ var mergeWithLocalFile2 = (options, optionsExternalFile) => (0, import_utils7.deepMerge)(
681
+ options,
682
+ (0, import_utils7.isObject)(optionsExternalFile) ? optionsExternalFile : import_dynamic2.default || {}
683
+ );
684
+ var create = (App, options = options_default, optionsExternalFile) => {
685
+ const redefinedOptions = {
686
+ ...options_default,
687
+ ...mergeWithLocalFile2(options, optionsExternalFile)
688
+ };
689
+ const domqlApp = createDomqlElement(App, redefinedOptions).then((App2) => {
690
+ onpopstateRouter(App2, redefinedOptions);
691
+ if (redefinedOptions.on && redefinedOptions.on.create)
692
+ redefinedOptions.on.create(
693
+ domqlApp,
694
+ domqlApp.state,
695
+ domqlApp.context,
696
+ redefinedOptions
697
+ );
698
+ });
699
+ return domqlApp;
700
+ };
701
+ var createAsync = (App, options = options_default, optionsExternalFile) => {
702
+ const domqlApp = create(App, options, optionsExternalFile);
703
+ const redefinedOptions = {
704
+ ...options_default,
705
+ ...mergeWithLocalFile2(options, optionsExternalFile)
706
+ };
707
+ const key = redefinedOptions.key;
708
+ fetchAsync(domqlApp, key, { utils: utilImports_exports, ...redefinedOptions });
709
+ return domqlApp;
710
+ };
711
+ var createSync = async (App, options = options_default, optionsExternalFile) => {
712
+ const redefinedOptions = {
713
+ ...options_default,
714
+ ...mergeWithLocalFile2(options, optionsExternalFile)
715
+ };
716
+ const key = options.key;
717
+ await fetchSync(key, redefinedOptions);
718
+ const domqlApp = await createDomqlElement(App, redefinedOptions);
719
+ if (redefinedOptions.on && redefinedOptions.on.create)
720
+ await redefinedOptions.on.create(
721
+ domqlApp,
722
+ domqlApp.state,
723
+ domqlApp.context,
724
+ redefinedOptions
725
+ );
726
+ return domqlApp;
727
+ };
728
+ var createSkeleton = (App = {}, options = options_default, optionsExternalFile) => {
729
+ return create(
730
+ {
731
+ deps: { isUndefined: import_utils7.isUndefined },
732
+ ...App
733
+ },
734
+ (0, import_utils7.deepMerge)({ domqlOptions: { onlyResolveExtends: true } }, options),
735
+ optionsExternalFile
736
+ );
737
+ };
738
+ return __toCommonJS(index_exports);
739
+ })();
740
+ // @preserve-env