smbls 3.2.3 → 3.2.8

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,296 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var prepare_exports = {};
30
+ __export(prepare_exports, {
31
+ PACKAGE_MANAGER_TO_CDN: () => PACKAGE_MANAGER_TO_CDN,
32
+ getCDNUrl: () => getCDNUrl,
33
+ getCdnProviderFromConfig: () => getCdnProviderFromConfig,
34
+ prepareComponents: () => prepareComponents,
35
+ prepareDependencies: () => prepareDependencies,
36
+ prepareDesignSystem: () => prepareDesignSystem,
37
+ prepareMethods: () => prepareMethods,
38
+ preparePages: () => preparePages,
39
+ prepareRequire: () => prepareRequire,
40
+ prepareSharedLibs: () => prepareSharedLibs,
41
+ prepareState: () => prepareState,
42
+ prepareUtils: () => prepareUtils,
43
+ prepareWindow: () => prepareWindow
44
+ });
45
+ module.exports = __toCommonJS(prepare_exports);
46
+ var import_utils = require("@domql/utils");
47
+ var import_emotion = require("@symbo.ls/emotion");
48
+ var uikit = __toESM(require("@symbo.ls/uikit"), 1);
49
+ var utils = __toESM(require("./utilImports.js"), 1);
50
+ var routerUtils = __toESM(require("@domql/router"), 1);
51
+ // @preserve-env
52
+ const prepareWindow = (context) => {
53
+ if (typeof window === "undefined") window = globalThis || {};
54
+ if (typeof document === "undefined") {
55
+ if (!window.document) window.document = globalThis.document || { body: {} };
56
+ document = window.document;
57
+ }
58
+ context.document = context.document || document;
59
+ context.window = context.window || window;
60
+ return context.window;
61
+ };
62
+ function onlyDotsAndNumbers(str) {
63
+ return /^[0-9.]+$/.test(str) && str !== "";
64
+ }
65
+ const CDN_PROVIDERS = {
66
+ skypack: {
67
+ url: "https://cdn.skypack.dev",
68
+ formatUrl: (pkg, version) => `${CDN_PROVIDERS.skypack.url}/${pkg}${version !== "latest" ? `@${version}` : ""}`
69
+ },
70
+ esmsh: {
71
+ url: "https://esm.sh",
72
+ formatUrl: (pkg, version) => `${CDN_PROVIDERS.esmsh.url}/${pkg}${version !== "latest" ? `@${version}` : ""}`
73
+ },
74
+ unpkg: {
75
+ url: "https://unpkg.com",
76
+ formatUrl: (pkg, version) => `${CDN_PROVIDERS.unpkg.url}/${pkg}${version !== "latest" ? `@${version}` : ""}?module`
77
+ },
78
+ jsdelivr: {
79
+ url: "https://cdn.jsdelivr.net/npm",
80
+ formatUrl: (pkg, version) => `${CDN_PROVIDERS.jsdelivr.url}/${pkg}${version !== "latest" ? `@${version}` : ""}/+esm`
81
+ },
82
+ symbols: {
83
+ url: "https://pkg.symbo.ls",
84
+ formatUrl: (pkg, version) => {
85
+ if (pkg.split("/").length > 2 || !onlyDotsAndNumbers(version)) {
86
+ return `${CDN_PROVIDERS.symbols.url}/${pkg}`;
87
+ }
88
+ return `${CDN_PROVIDERS.symbols.url}/${pkg}/${version}.js`;
89
+ }
90
+ }
91
+ };
92
+ const PACKAGE_MANAGER_TO_CDN = {
93
+ "esm.sh": "esmsh",
94
+ "unpkg": "unpkg",
95
+ "skypack": "skypack",
96
+ "jsdelivr": "jsdelivr",
97
+ "pkg.symbo.ls": "symbols"
98
+ };
99
+ const getCdnProviderFromConfig = (symbolsConfig = {}) => {
100
+ const { packageManager } = symbolsConfig;
101
+ return PACKAGE_MANAGER_TO_CDN[packageManager] || null;
102
+ };
103
+ const getCDNUrl = (packageName, version = "latest", provider = "esmsh") => {
104
+ const cdnConfig = CDN_PROVIDERS[provider] || CDN_PROVIDERS.esmsh;
105
+ return cdnConfig.formatUrl(packageName, version);
106
+ };
107
+ const UIkitWithPrefix = (prefix = "smbls") => {
108
+ const newObj = {};
109
+ for (const key in uikit) {
110
+ if (Object.prototype.hasOwnProperty.call(uikit, key)) {
111
+ if ((0, import_utils.matchesComponentNaming)(key)) {
112
+ newObj[`smbls.${key}`] = uikit[key];
113
+ } else {
114
+ newObj[key] = uikit[key];
115
+ }
116
+ }
117
+ }
118
+ return newObj;
119
+ };
120
+ const prepareComponents = (context) => {
121
+ return context.components ? { ...UIkitWithPrefix(), ...context.components } : UIkitWithPrefix();
122
+ };
123
+ const prepareUtils = (context) => {
124
+ return {
125
+ ...utils,
126
+ ...routerUtils,
127
+ ...utils.scratchUtils,
128
+ ...context.utils,
129
+ ...context.snippets,
130
+ ...context.functions
131
+ };
132
+ };
133
+ const prepareMethods = (context) => {
134
+ return {
135
+ ...context.methods || {},
136
+ require: context.utils.require,
137
+ requireOnDemand: context.utils.requireOnDemand,
138
+ router: context.utils.router
139
+ };
140
+ };
141
+ const cachedDeps = {};
142
+ const prepareDependencies = async ({
143
+ dependencies,
144
+ dependenciesOnDemand,
145
+ document: document2,
146
+ preventCaching = false,
147
+ cdnProvider,
148
+ packageManager,
149
+ symbolsConfig
150
+ }) => {
151
+ if (!cdnProvider) {
152
+ cdnProvider = PACKAGE_MANAGER_TO_CDN[packageManager] || getCdnProviderFromConfig(symbolsConfig) || "esmsh";
153
+ }
154
+ if (!dependencies) return null;
155
+ let hasAny = false;
156
+ for (const _k in dependencies) {
157
+ hasAny = true;
158
+ break;
159
+ }
160
+ if (!hasAny) return null;
161
+ for (const dependency in dependencies) {
162
+ const version = dependencies[dependency];
163
+ if (dependenciesOnDemand && dependenciesOnDemand[dependency]) {
164
+ continue;
165
+ }
166
+ const random = (0, import_utils.isDevelopment)() && preventCaching ? `?${Math.random()}` : "";
167
+ const url = getCDNUrl(dependency, version, cdnProvider) + random;
168
+ try {
169
+ if (cachedDeps[dependency]) return;
170
+ cachedDeps[dependency] = true;
171
+ await utils.loadRemoteScript(url, { document: document2, type: "module" });
172
+ } catch (e) {
173
+ console.error(`Failed to load ${dependency} from ${cdnProvider}:`, e);
174
+ if (cdnProvider !== "symbols") {
175
+ try {
176
+ const fallbackUrl = getCDNUrl(dependency, version, "symbols") + random;
177
+ await utils.loadRemoteScript(fallbackUrl, { document: document2 });
178
+ console.log(
179
+ `Successfully loaded ${dependency} from fallback (symbols.ls)`
180
+ );
181
+ } catch (fallbackError) {
182
+ console.error(
183
+ `Failed to load ${dependency} from fallback:`,
184
+ fallbackError
185
+ );
186
+ }
187
+ }
188
+ }
189
+ }
190
+ return dependencies;
191
+ };
192
+ const prepareRequire = async (packages, ctx) => {
193
+ const windowOpts = ctx.window || window;
194
+ const defaultProvider = ctx.cdnProvider || getCdnProviderFromConfig(ctx.symbolsConfig) || "esmsh";
195
+ const initRequire = async (ctx2) => async (key, provider) => {
196
+ const windowOpts2 = ctx2.window || window;
197
+ const pkg = windowOpts2.packages[key];
198
+ if (typeof pkg === "function") return pkg();
199
+ return pkg;
200
+ };
201
+ const initRequireOnDemand = async (ctx2) => async (key, provider = defaultProvider) => {
202
+ const { dependenciesOnDemand } = ctx2;
203
+ const documentOpts = ctx2.document || document;
204
+ const windowOpts2 = ctx2.window || window;
205
+ if (!windowOpts2.packages[key]) {
206
+ const random = (0, import_utils.isDevelopment)() ? `?${Math.random()}` : "";
207
+ if (dependenciesOnDemand && dependenciesOnDemand[key]) {
208
+ const version = dependenciesOnDemand[key];
209
+ const url = getCDNUrl(key, version, provider) + random;
210
+ try {
211
+ await ctx2.utils.loadRemoteScript(url, {
212
+ window: windowOpts2,
213
+ document: documentOpts
214
+ });
215
+ } catch (e) {
216
+ console.error(`Failed to load ${key} from ${provider}:`, e);
217
+ if (provider !== "symbols") {
218
+ const fallbackUrl = getCDNUrl(key, version, "symbols") + random;
219
+ await ctx2.utils.loadRemoteScript(fallbackUrl, {
220
+ window: windowOpts2,
221
+ document: documentOpts
222
+ });
223
+ }
224
+ }
225
+ } else {
226
+ const url = getCDNUrl(key, "latest", provider) + random;
227
+ try {
228
+ await ctx2.utils.loadRemoteScript(url, {
229
+ window: windowOpts2,
230
+ document: documentOpts
231
+ });
232
+ } catch (e) {
233
+ console.error(`Failed to load ${key} from ${provider}:`, e);
234
+ if (provider !== "symbols") {
235
+ const fallbackUrl = getCDNUrl(key, "latest", "symbols") + random;
236
+ await ctx2.utils.loadRemoteScript(fallbackUrl, {
237
+ window: windowOpts2,
238
+ document: documentOpts
239
+ });
240
+ }
241
+ }
242
+ windowOpts2.packages[key] = "loadedOnDeman";
243
+ }
244
+ }
245
+ return await windowOpts2.require(key, provider);
246
+ };
247
+ if (windowOpts.packages) {
248
+ windowOpts.packages = (0, import_utils.merge)(windowOpts.packages, packages);
249
+ } else {
250
+ windowOpts.packages = packages;
251
+ }
252
+ if (!windowOpts.require) {
253
+ ctx.utils.require = await initRequire(ctx);
254
+ windowOpts.require = ctx.utils.require;
255
+ }
256
+ if (!windowOpts.requireOnDemand) {
257
+ ctx.utils.requireOnDemand = await initRequireOnDemand(ctx);
258
+ windowOpts.requireOnDemand = ctx.utils.requireOnDemand;
259
+ }
260
+ };
261
+ const prepareDesignSystem = (key, context) => {
262
+ const [scratcDesignhSystem, emotion, registry] = (0, import_emotion.initEmotion)(key, context);
263
+ return [scratcDesignhSystem, emotion, registry];
264
+ };
265
+ const prepareState = (app, context) => {
266
+ const state = {};
267
+ if (context.state) utils.deepMerge(state, context.state);
268
+ if (app && app.state) (0, import_utils.deepMerge)(state, app.state);
269
+ state.isRootState = true;
270
+ return (0, import_utils.deepClone)(state);
271
+ };
272
+ const preparePages = (app, context) => {
273
+ if ((0, import_utils.isObject)(app.routes) && (0, import_utils.isObject)(context.pages)) {
274
+ (0, import_utils.merge)(app.routes, context.pages);
275
+ }
276
+ const pages = app.routes || context.pages || {};
277
+ for (const v in pages) {
278
+ if (v.charCodeAt(0) === 47) continue;
279
+ const index = v === "index" ? "" : v;
280
+ pages["/" + index] = pages[v];
281
+ delete pages[v];
282
+ }
283
+ return pages;
284
+ };
285
+ const prepareSharedLibs = (context) => {
286
+ const sharedLibraries = context.sharedLibraries;
287
+ for (let i = 0; i < sharedLibraries.length; i++) {
288
+ const sharedLib = sharedLibraries[i];
289
+ if (context.type === "template") {
290
+ overwriteShallow(context.designSystem, sharedLib.designSystem);
291
+ (0, import_utils.deepMerge)(context, sharedLib, ["designSystem"], 1);
292
+ } else {
293
+ (0, import_utils.deepMerge)(context, sharedLib, [], 1);
294
+ }
295
+ }
296
+ };
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var router_exports = {};
20
+ __export(router_exports, {
21
+ initRouter: () => initRouter,
22
+ injectRouterInLinkComponent: () => injectRouterInLinkComponent,
23
+ onpopstateRouter: () => onpopstateRouter
24
+ });
25
+ module.exports = __toCommonJS(router_exports);
26
+ var import_utils = require("@domql/utils");
27
+ var import_router = require("@domql/router");
28
+ var import_smbls = require("smbls");
29
+ const DEFAULT_ROUTING_OPTIONS = {
30
+ initRouter: true,
31
+ injectRouterInLinkComponent: true,
32
+ popState: true
33
+ };
34
+ const initRouter = (element, context) => {
35
+ if (context.router === false) return;
36
+ else if (context.router === true) context.router = DEFAULT_ROUTING_OPTIONS;
37
+ else context.router = (0, import_utils.merge)(context.router || {}, DEFAULT_ROUTING_OPTIONS);
38
+ const routerOptions = context.router;
39
+ const onRouterRenderDefault = async (el, s) => {
40
+ const { pathname, search, hash } = import_utils.window.location;
41
+ const url = pathname + search + hash;
42
+ if (el.routes) await (0, import_router.router)(url, el, {}, { initialRender: true });
43
+ };
44
+ const hasRenderRouter = element.on && !(0, import_utils.isUndefined)(element.on.renderRouter) || !(0, import_utils.isUndefined)(element.onRenderRouter);
45
+ if (routerOptions && routerOptions.initRouter && !hasRenderRouter) {
46
+ if (element.on) {
47
+ element.on.renderRouter = onRouterRenderDefault;
48
+ } else {
49
+ element.on = {
50
+ renderRouter: onRouterRenderDefault
51
+ };
52
+ }
53
+ }
54
+ injectRouterInLinkComponent(context, routerOptions);
55
+ return routerOptions;
56
+ };
57
+ let popStateFired;
58
+ const onpopstateRouter = (element, context) => {
59
+ if (popStateFired) return;
60
+ popStateFired = true;
61
+ const routerOptions = context.router || DEFAULT_ROUTING_OPTIONS;
62
+ if (!routerOptions.popState) return;
63
+ const router = context.utils && context.utils.router ? context.utils.router : import_router.router;
64
+ import_utils.window.onpopstate = async (e) => {
65
+ const { pathname, search, hash } = import_utils.window.location;
66
+ const url = pathname + search + hash;
67
+ await element.call(
68
+ "router",
69
+ url,
70
+ element,
71
+ {},
72
+ { pushState: false, scrollToTop: false, level: 0, event: e }
73
+ );
74
+ };
75
+ };
76
+ const injectRouterInLinkComponent = (context, routerOptions) => {
77
+ const { components } = context;
78
+ if (routerOptions && routerOptions.injectRouterInLinkComponent) {
79
+ return (0, import_utils.deepMerge)(
80
+ components["Link"] || components["smbls.Link"],
81
+ components["RouterLink"] || components["smbls.RouterLink"]
82
+ );
83
+ }
84
+ };
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var syncExtend_exports = {};
20
+ __export(syncExtend_exports, {
21
+ initializeExtend: () => initializeExtend,
22
+ initializeInspect: () => initializeInspect,
23
+ initializeNotifications: () => initializeNotifications,
24
+ initializeSync: () => initializeSync
25
+ });
26
+ module.exports = __toCommonJS(syncExtend_exports);
27
+ var import_utils = require("@domql/utils");
28
+ var import_sync = require("@symbo.ls/sync");
29
+ const initializeExtend = (app, ctx) => {
30
+ return (0, import_utils.isObjectLike)(app.extends) ? app.extends : [];
31
+ };
32
+ const initializeSync = (app, ctx) => {
33
+ const { editor } = ctx;
34
+ if (!editor) return;
35
+ const liveSync = (0, import_utils.isUndefined)(editor.liveSync) ? (0, import_utils.isDevelopment)() : editor.liveSync;
36
+ if (liveSync) {
37
+ if ((0, import_utils.isArray)(app.extends)) app.extends.push(import_sync.SyncComponent);
38
+ else if (app.extends) {
39
+ app.extends = [app.extends, import_sync.SyncComponent];
40
+ } else {
41
+ app.extends = [import_sync.SyncComponent];
42
+ }
43
+ }
44
+ };
45
+ const initializeInspect = (app, ctx) => {
46
+ const { editor } = ctx;
47
+ if (!editor) return;
48
+ const inspect = (0, import_utils.isUndefined)(editor.inspect) ? (0, import_utils.isDevelopment)() : editor.inspect;
49
+ if (inspect) {
50
+ if ((0, import_utils.isArray)(app.extends)) app.extends.push(import_sync.Inspect);
51
+ else if (app.extends) {
52
+ app.extends = [app.extends, import_sync.Inspect];
53
+ } else {
54
+ app.extends = [import_sync.Inspect];
55
+ }
56
+ }
57
+ };
58
+ const initializeNotifications = (app, ctx) => {
59
+ const { editor } = ctx;
60
+ if (!editor) return;
61
+ const verbose = (0, import_utils.isUndefined)(editor.verbose) ? (0, import_utils.isDevelopment)() || ctx.verbose : editor.verbose;
62
+ if (verbose) {
63
+ if ((0, import_utils.isArray)(app.extends)) app.extends.push(import_sync.Notifications);
64
+ else if (app.extends) {
65
+ app.extends = [app.extends, import_sync.Notifications];
66
+ } else {
67
+ app.extends = [import_sync.Notifications];
68
+ }
69
+ }
70
+ };
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var utilImports_exports = {};
21
+ __export(utilImports_exports, {
22
+ applyCSS: () => import_init.applyCSS,
23
+ init: () => import_init.init,
24
+ reinit: () => import_init.reinit,
25
+ scratchSystem: () => import_scratch.scratchSystem,
26
+ scratchUtils: () => import_scratch.scratchUtils,
27
+ set: () => import_scratch.set
28
+ });
29
+ module.exports = __toCommonJS(utilImports_exports);
30
+ var import_scratch = require("@symbo.ls/scratch");
31
+ __reExport(utilImports_exports, require("@domql/utils"), module.exports);
32
+ __reExport(utilImports_exports, require("@symbo.ls/smbls-utils"), module.exports);
33
+ var import_init = require("./init.js");
34
+ __reExport(utilImports_exports, require("@domql/report"), module.exports);
35
+ __reExport(utilImports_exports, require("@domql/router"), module.exports);
package/dist/esm/index.js CHANGED
@@ -1,10 +1,9 @@
1
1
  export * from "@domql/utils";
2
2
  export * from "attrs-in-props";
3
- export * from "@symbo.ls/create";
4
3
  export * from "css-in-props";
5
4
  export * from "@symbo.ls/default-config";
6
5
  export * from "@symbo.ls/emotion";
7
- export * from "@symbo.ls/init";
8
6
  export * from "@symbo.ls/scratch";
9
7
  export * from "@symbo.ls/uikit";
10
- export * from "@symbo.ls/utils";
8
+ export * from "@symbo.ls/smbls-utils";
9
+ export * from "./src/index.js";
@@ -0,0 +1,96 @@
1
+ import DOM from "domql";
2
+ import * as uikit from "@symbo.ls/uikit";
3
+ import { CSS_PROPS_REGISTRY } from "css-in-props";
4
+ import { isString, isNode, isObject } from "@domql/utils";
5
+ import { initAnimationFrame } from "@domql/element";
6
+ import { defaultDefine } from "./define.js";
7
+ import { initRouter } from "./router.js";
8
+ import {
9
+ initializeExtend,
10
+ initializeNotifications,
11
+ initializeSync
12
+ } from "./syncExtend.js";
13
+ import {
14
+ prepareComponents,
15
+ prepareDependencies,
16
+ prepareDesignSystem,
17
+ prepareWindow,
18
+ prepareRequire,
19
+ preparePages,
20
+ prepareState,
21
+ prepareUtils,
22
+ prepareMethods,
23
+ prepareSharedLibs,
24
+ PACKAGE_MANAGER_TO_CDN
25
+ } from "./prepare.js";
26
+ const prepareContext = async (app, context = {}) => {
27
+ const key = context.key = context.key || (isString(app) ? app : "smblsapp");
28
+ context.define = context.define || defaultDefine;
29
+ context.cssPropsRegistry = CSS_PROPS_REGISTRY;
30
+ context.window = prepareWindow(context);
31
+ if (context.sharedLibraries && context.sharedLibraries.length) {
32
+ prepareSharedLibs(context);
33
+ }
34
+ const [scratcDesignSystem, emotion, registry] = prepareDesignSystem(
35
+ key,
36
+ context
37
+ );
38
+ context.designSystem = scratcDesignSystem;
39
+ context.registry = registry;
40
+ context.emotion = emotion;
41
+ const state = prepareState(app, context);
42
+ context.state = state;
43
+ context.pages = preparePages(app, context);
44
+ context.components = prepareComponents(context);
45
+ context.utils = prepareUtils(context);
46
+ if (PACKAGE_MANAGER_TO_CDN[context.packageManager]) {
47
+ context.dependencies = await prepareDependencies(context);
48
+ }
49
+ context.methods = prepareMethods(context);
50
+ context.routerOptions = initRouter(app, context);
51
+ context.defaultExtends = [uikit.Box];
52
+ context.snippets = context.snippets || {};
53
+ context.functions = context.functions || {};
54
+ return context;
55
+ };
56
+ const createDomqlElement = async (app, ctx) => {
57
+ if (!isObject(ctx)) ctx = {};
58
+ if (isNode(app)) {
59
+ app = {};
60
+ ctx.parent = app;
61
+ } else if (isString(app)) {
62
+ app = {};
63
+ ctx.key = app;
64
+ } else if (!isObject(app)) {
65
+ app = {};
66
+ }
67
+ await prepareContext(app, ctx);
68
+ app.extends = initializeExtend(app, ctx);
69
+ app.routes = ctx.pages;
70
+ app.state = ctx.state;
71
+ app.context = ctx;
72
+ app.data = app.data || {};
73
+ app.data.frameListeners = initAnimationFrame(ctx);
74
+ await prepareRequire(
75
+ {
76
+ functions: ctx.functions,
77
+ utils: ctx.utils,
78
+ snippets: ctx.snippets,
79
+ ...ctx.files
80
+ },
81
+ ctx
82
+ );
83
+ initializeSync(app, ctx);
84
+ initializeNotifications(app, ctx);
85
+ const parentNode = ctx.parent || ctx.document.body;
86
+ const domqlCreate = DOM.default && DOM.default.create || DOM.create;
87
+ const smblsApp = await domqlCreate(app, parentNode, ctx.key, {
88
+ verbose: ctx.verbose,
89
+ ...ctx.domqlOptions
90
+ });
91
+ return smblsApp;
92
+ };
93
+ export {
94
+ createDomqlElement,
95
+ prepareContext
96
+ };
@@ -0,0 +1,18 @@
1
+ const defaultDefine = {
2
+ routes: (param) => param,
3
+ // deps: (param, el) => param || el.parent.deps,
4
+ $router: async (param, el) => {
5
+ if (!param) return;
6
+ const obj = { tag: "fragment", ...param };
7
+ const set = async () => {
8
+ await el.set(obj, { preventDefineUpdate: "$router" });
9
+ };
10
+ if (el.props && el.props.lazyLoad) {
11
+ window.requestAnimationFrame(set);
12
+ } else await set();
13
+ return obj;
14
+ }
15
+ };
16
+ export {
17
+ defaultDefine
18
+ };
@@ -0,0 +1,34 @@
1
+ import { isObject } from "@domql/utils";
2
+ import { fetchProject, fetchProjectAsync } from "@symbo.ls/fetch";
3
+ const fetchSync = async (key, options) => {
4
+ if (key && options.editor) {
5
+ try {
6
+ if (!options.editor.async) await fetchProject(key, options);
7
+ } catch (e) {
8
+ console.error(e);
9
+ }
10
+ }
11
+ };
12
+ const fetchAsync = (app, key, options, callback) => {
13
+ if (key && options.editor) {
14
+ try {
15
+ if (options.editor.async) {
16
+ fetchProjectAsync(key, options, callback || ((data) => {
17
+ const designSystem = data.designSystem;
18
+ if (isObject(designSystem)) {
19
+ options.utils.init(designSystem);
20
+ }
21
+ if (isObject(data.state)) {
22
+ app.state.set(data.state);
23
+ }
24
+ }));
25
+ }
26
+ } catch (e) {
27
+ console.error(e);
28
+ }
29
+ }
30
+ };
31
+ export {
32
+ fetchAsync,
33
+ fetchSync
34
+ };