@variousjs/various 5.3.0 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1402 @@
1
+ import e, { Component, useCallback, useEffect, useLayoutEffect, useRef, useState } from "react";
2
+ //#region \0@oxc-project+runtime@0.142.0/helpers/esm/typeof.js
3
+ function _typeof(o) {
4
+ "@babel/helpers - typeof";
5
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
6
+ return typeof o;
7
+ } : function(o) {
8
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
9
+ }, _typeof(o);
10
+ }
11
+ //#endregion
12
+ //#region \0@oxc-project+runtime@0.142.0/helpers/esm/toPrimitive.js
13
+ function toPrimitive(t, r) {
14
+ if ("object" != _typeof(t) || !t) return t;
15
+ var e = t[Symbol.toPrimitive];
16
+ if (void 0 !== e) {
17
+ var i = e.call(t, r || "default");
18
+ if ("object" != _typeof(i)) return i;
19
+ throw new TypeError("@@toPrimitive must return a primitive value.");
20
+ }
21
+ return ("string" === r ? String : Number)(t);
22
+ }
23
+ //#endregion
24
+ //#region \0@oxc-project+runtime@0.142.0/helpers/esm/toPropertyKey.js
25
+ function toPropertyKey(t) {
26
+ var i = toPrimitive(t, "string");
27
+ return "symbol" == _typeof(i) ? i : i + "";
28
+ }
29
+ //#endregion
30
+ //#region \0@oxc-project+runtime@0.142.0/helpers/esm/defineProperty.js
31
+ function _defineProperty(e, r, t) {
32
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
33
+ value: t,
34
+ enumerable: !0,
35
+ configurable: !0,
36
+ writable: !0
37
+ }) : e[r] = t, e;
38
+ }
39
+ //#endregion
40
+ //#region \0@oxc-project+runtime@0.142.0/helpers/esm/objectSpread2.js
41
+ function ownKeys(e, r) {
42
+ var t = Object.keys(e);
43
+ if (Object.getOwnPropertySymbols) {
44
+ var o = Object.getOwnPropertySymbols(e);
45
+ r && (o = o.filter(function(r) {
46
+ return Object.getOwnPropertyDescriptor(e, r).enumerable;
47
+ })), t.push.apply(t, o);
48
+ }
49
+ return t;
50
+ }
51
+ function _objectSpread2(e) {
52
+ for (var r = 1; r < arguments.length; r++) {
53
+ var t = null != arguments[r] ? arguments[r] : {};
54
+ r % 2 ? ownKeys(Object(t), !0).forEach(function(r) {
55
+ _defineProperty(e, r, t[r]);
56
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r) {
57
+ Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
58
+ });
59
+ }
60
+ return e;
61
+ }
62
+ //#endregion
63
+ //#region node_modules/nycticorax/dist/esm/index.js
64
+ var o = {
65
+ 17(t) {
66
+ t.exports = function t(e, r) {
67
+ if (e === r) return !0;
68
+ if (e && r && "object" == typeof e && "object" == typeof r) {
69
+ if (e.constructor !== r.constructor) return !1;
70
+ var s, o, n;
71
+ if (Array.isArray(e)) {
72
+ if ((s = e.length) != r.length) return !1;
73
+ for (o = s; 0 !== o--;) if (!t(e[o], r[o])) return !1;
74
+ return !0;
75
+ }
76
+ if (e.constructor === RegExp) return e.source === r.source && e.flags === r.flags;
77
+ if (e.valueOf !== Object.prototype.valueOf) return e.valueOf() === r.valueOf();
78
+ if (e.toString !== Object.prototype.toString) return e.toString() === r.toString();
79
+ if ((s = (n = Object.keys(e)).length) !== Object.keys(r).length) return !1;
80
+ for (o = s; 0 !== o--;) if (!Object.prototype.hasOwnProperty.call(r, n[o])) return !1;
81
+ for (o = s; 0 !== o--;) {
82
+ var i = n[o];
83
+ if (!t(e[i], r[i])) return !1;
84
+ }
85
+ return !0;
86
+ }
87
+ return e != e && r != r;
88
+ };
89
+ },
90
+ 232(t, e, r) {
91
+ r.d(e, { A: () => u });
92
+ var s = r(705), o = r(17), n = r.n(o);
93
+ function i(t, e = /* @__PURE__ */ new WeakMap()) {
94
+ if ("object" != typeof t || null === t) return t;
95
+ if (e.has(t)) return e.get(t);
96
+ const r = Array.isArray(t) ? [] : {};
97
+ e.set(t, r);
98
+ const s = Reflect.ownKeys(t);
99
+ for (const o of s) r[o] = i(t[o], e);
100
+ return r;
101
+ }
102
+ class u {
103
+ constructor() {
104
+ var t;
105
+ (0, s.A)(this, "state", void 0), (0, s.A)(this, "listeners", void 0), (0, s.A)(this, "emits", void 0), (0, s.A)(this, "timer", void 0), (0, s.A)(this, "onStateChange", void 0), (0, s.A)(this, "getStore", void 0), (0, s.A)(this, "createStore", (t) => {
106
+ this.listeners = Reflect.ownKeys(t).reduce((e, r) => {
107
+ const s = r;
108
+ return this.state[s] = t[s], _objectSpread2(_objectSpread2({}, e), {}, { [r]: [] });
109
+ }, {});
110
+ }), (0, s.A)(this, "subscribe", (t) => {
111
+ const e = {};
112
+ return Reflect.ownKeys(t).forEach((r) => {
113
+ const s = r;
114
+ this.listeners[s] || (this.listeners[s] = []), this.listeners[s].push(t[s]), e[s] = t[s];
115
+ }), () => {
116
+ Reflect.ownKeys(e).forEach((t) => {
117
+ const r = t;
118
+ this.listeners[r] = this.listeners[r].filter((t) => t !== e[r]);
119
+ });
120
+ };
121
+ }), (0, s.A)(this, "emit", (t, e) => {
122
+ this.emits = _objectSpread2(_objectSpread2({}, this.emits), t), e ? this.trigger() : (clearTimeout(this.timer), this.timer = setTimeout(this.trigger));
123
+ }), (0, s.A)(this, "dispatch", (t, ...e) => t({
124
+ getStore: this.getStore,
125
+ emit: (t) => this.emit(t, !0)
126
+ }, ...e)), (0, s.A)(this, "trigger", () => {
127
+ const t = this.emits, e = [], r = Reflect.ownKeys(t);
128
+ for (let s = 0; s < r.length; s += 1) {
129
+ const o = r[s];
130
+ if (n()(this.state[o], t[o])) continue;
131
+ const u = t[o], c = this.state[o];
132
+ this.state[o] = i(t[o]), e.push({
133
+ key: o,
134
+ newValue: u,
135
+ oldValue: c
136
+ });
137
+ }
138
+ const s = {};
139
+ e.forEach((t) => {
140
+ s[t.key] = [t.newValue, t.oldValue], this.listeners[t.key] && this.listeners[t.key].forEach((e) => e(t.newValue, t.oldValue));
141
+ }), e.length && this.onStateChange(s), this.emits = {}, this.timer = void 0;
142
+ }), this.state = {}, this.listeners = {}, this.emits = {}, this.timer = void 0, this.onStateChange = () => null, this.getStore = (t = this.state, function(e) {
143
+ return e ? i(t[e]) : t;
144
+ });
145
+ }
146
+ set onChange(t) {
147
+ this.onStateChange = t;
148
+ }
149
+ }
150
+ },
151
+ 705(t, e, r) {
152
+ function s(t) {
153
+ return s = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(t) {
154
+ return typeof t;
155
+ } : function(t) {
156
+ return t && "function" == typeof Symbol && t.constructor === Symbol && t !== Symbol.prototype ? "symbol" : typeof t;
157
+ }, s(t);
158
+ }
159
+ function o(t, e, r) {
160
+ return (e = function(t) {
161
+ var e = function(t) {
162
+ if ("object" != s(t) || !t) return t;
163
+ var e = t[Symbol.toPrimitive];
164
+ if (void 0 !== e) {
165
+ var r = e.call(t, "string");
166
+ if ("object" != s(r)) return r;
167
+ throw new TypeError("@@toPrimitive must return a primitive value.");
168
+ }
169
+ return String(t);
170
+ }(t);
171
+ return "symbol" == s(e) ? e : e + "";
172
+ }(e)) in t ? Object.defineProperty(t, e, {
173
+ value: r,
174
+ enumerable: !0,
175
+ configurable: !0,
176
+ writable: !0
177
+ }) : t[e] = r, t;
178
+ }
179
+ r.d(e, { A: () => o });
180
+ }
181
+ };
182
+ var n = {};
183
+ function i(t) {
184
+ var e = n[t];
185
+ if (void 0 !== e) return e.exports;
186
+ var r = n[t] = { exports: {} };
187
+ return o[t](r, r.exports, i), r.exports;
188
+ }
189
+ i.n = (t) => {
190
+ var e = t && t.__esModule ? () => t.default : () => t;
191
+ return i.d(e, { a: e }), e;
192
+ }, i.d = (t, e) => {
193
+ for (var r in e) i.o(e, r) && !i.o(t, r) && Object.defineProperty(t, r, {
194
+ enumerable: !0,
195
+ get: e[r]
196
+ });
197
+ }, i.o = (t, e) => Object.prototype.hasOwnProperty.call(t, e);
198
+ var u = i(705);
199
+ var c = i(232);
200
+ var a = [
201
+ "name",
202
+ "prototype",
203
+ "length",
204
+ "getDerivedStateFromProps",
205
+ "getDerivedStateFromError"
206
+ ];
207
+ var f = class extends c.A {
208
+ constructor(...o) {
209
+ super(...o), (0, u.A)(this, "connect", function(r) {
210
+ const { getStore: s, subscribe: o } = r;
211
+ return function(...r) {
212
+ return function(n) {
213
+ class i extends Component {
214
+ constructor(t) {
215
+ super(t), (0, u.A)(this, "unsubscribe", void 0), (0, u.A)(this, "state", { props: s() }), this.unsubscribe = o(r.reduce((t, e) => _objectSpread2(_objectSpread2({}, t), {}, { [e]: () => {
216
+ this.setState({ props: s() });
217
+ } }), {}));
218
+ }
219
+ componentWillUnmount() {
220
+ this.unsubscribe();
221
+ }
222
+ render() {
223
+ const { props: t } = this.state, r = _objectSpread2(_objectSpread2({}, t), this.props);
224
+ return e.createElement(n, r);
225
+ }
226
+ }
227
+ return Reflect.ownKeys(n).forEach((t) => {
228
+ const e = String(t);
229
+ if (!a.includes(e)) {
230
+ const e = Object.getOwnPropertyDescriptor(n, t);
231
+ e && Object.defineProperty(i, t, e);
232
+ }
233
+ }), i;
234
+ };
235
+ };
236
+ }(this)), (0, u.A)(this, "useStore", function(t) {
237
+ const { getStore: e, subscribe: o } = t;
238
+ return function(...t) {
239
+ const [n, i] = useState(e());
240
+ return useLayoutEffect(() => o(t.reduce((t, r) => _objectSpread2(_objectSpread2({}, t), {}, { [r]: () => {
241
+ i((t) => _objectSpread2(_objectSpread2({}, t), {}, { [r]: e()[r] }));
242
+ } }), {}))), n;
243
+ };
244
+ }(this));
245
+ }
246
+ };
247
+ //#endregion
248
+ //#region src/core/store.ts
249
+ var { createStore, getStore, connect, emit, subscribe, dispatch, useStore } = new f();
250
+ function getUserStore() {
251
+ const globalStore = getStore();
252
+ const keys = Object.keys(globalStore);
253
+ const store = {};
254
+ keys.forEach((key) => {
255
+ store[key] = globalStore[key];
256
+ });
257
+ return store;
258
+ }
259
+ //#endregion
260
+ //#region src/core/default-component.tsx
261
+ var Fallback = (props) => {
262
+ const className = getClassNameWithModule(props.$self.module, "various-component-fallback");
263
+ return /* @__PURE__ */ e.createElement("div", { className }, "Loading");
264
+ };
265
+ var ErrorFallback = ({ $error, $reload, $self }) => {
266
+ const className = getClassNameWithModule($self.module, "various-component-error_fallback");
267
+ return /* @__PURE__ */ e.createElement("div", { className }, /* @__PURE__ */ e.createElement("h3", null, $error.type), /* @__PURE__ */ e.createElement("p", null, $error.message), /* @__PURE__ */ e.createElement("button", {
268
+ type: "button",
269
+ onClick: $reload
270
+ }, "Reload"));
271
+ };
272
+ //#endregion
273
+ //#region src/core/connector.ts
274
+ var Connector = class {
275
+ constructor() {
276
+ _defineProperty(this, "fallbackComponent", void 0);
277
+ _defineProperty(this, "errorFallbackComponent", void 0);
278
+ _defineProperty(this, "storeActions", void 0);
279
+ _defineProperty(this, "componentActions", void 0);
280
+ _defineProperty(this, "i18nConfigs", void 0);
281
+ _defineProperty(this, "globalI18nConfig", void 0);
282
+ _defineProperty(this, "middlewares", void 0);
283
+ this.fallbackComponent = Fallback;
284
+ this.errorFallbackComponent = ErrorFallback;
285
+ this.storeActions = {};
286
+ this.componentActions = {};
287
+ this.i18nConfigs = {};
288
+ this.middlewares = {};
289
+ }
290
+ setMiddlewares(m) {
291
+ this.middlewares = m;
292
+ }
293
+ getMiddlewares() {
294
+ return this.middlewares;
295
+ }
296
+ setI18nConfig(module, config) {
297
+ this.i18nConfigs[module] = _objectSpread2(_objectSpread2({}, this.i18nConfigs[module]), config);
298
+ }
299
+ getI18nConfig(module) {
300
+ return this.i18nConfigs[module];
301
+ }
302
+ setGlobalI18nConfig(config) {
303
+ this.globalI18nConfig = _objectSpread2(_objectSpread2({}, this.globalI18nConfig), config);
304
+ }
305
+ getGlobalI18nConfig() {
306
+ return this.globalI18nConfig;
307
+ }
308
+ setComponentActions(module, actions) {
309
+ this.componentActions[module] = actions;
310
+ }
311
+ deleteComponentActions(module) {
312
+ delete this.componentActions[module];
313
+ }
314
+ getComponentActions(module) {
315
+ return this.componentActions[module];
316
+ }
317
+ setStoreActions(actions) {
318
+ this.storeActions = actions;
319
+ }
320
+ getStoreActions() {
321
+ return this.storeActions;
322
+ }
323
+ setFallbackComponent(fallbackComponent) {
324
+ this.fallbackComponent = fallbackComponent;
325
+ }
326
+ getFallbackComponent() {
327
+ return this.fallbackComponent;
328
+ }
329
+ setErrorFallbackComponent(errorFallbackComponent) {
330
+ this.errorFallbackComponent = errorFallbackComponent;
331
+ }
332
+ getErrorFallbackComponent() {
333
+ return this.errorFallbackComponent;
334
+ }
335
+ };
336
+ var connector_default = new Connector();
337
+ //#endregion
338
+ //#region src/core/logger.ts
339
+ var logger = (args) => {
340
+ var _middlewares$onLog;
341
+ const middlewares = connector_default.getMiddlewares();
342
+ if ((middlewares === null || middlewares === void 0 || (_middlewares$onLog = middlewares.onLog) === null || _middlewares$onLog === void 0 ? void 0 : _middlewares$onLog.call(middlewares, args)) === false) return;
343
+ const color = {
344
+ info: "blue",
345
+ warn: "orange",
346
+ error: "red"
347
+ }[args.level];
348
+ const params = [`%c ${args.module} `, `background:${color};border:1px solid ${color};padding:1px;border-radius:2px 0 0 2px;color: #fff;`];
349
+ if (args.type) {
350
+ params[0] = `${params[0]}%c ${args.type} %c`;
351
+ params.push(`border:1px solid ${color};padding:1px;border-radius:0 2px 2px 0;color:${color};`, "background:transparent");
352
+ }
353
+ if (args.level !== "info") params[0] = ` ${params[0]}`;
354
+ window.console[args.level](...params, args.message);
355
+ };
356
+ var createLogger = (module) => ({
357
+ info(message, type) {
358
+ logger({
359
+ module,
360
+ level: "info",
361
+ type,
362
+ message
363
+ });
364
+ },
365
+ warn(message, type) {
366
+ logger({
367
+ module,
368
+ level: "warn",
369
+ type,
370
+ message
371
+ });
372
+ },
373
+ error(message, type) {
374
+ var _middlewares$onError;
375
+ const middlewares = connector_default.getMiddlewares();
376
+ const error = message instanceof VariousError ? message : new VariousError({
377
+ module,
378
+ type: type || "unknow",
379
+ originalError: message instanceof Error ? message : new Error(message)
380
+ });
381
+ middlewares === null || middlewares === void 0 || (_middlewares$onError = middlewares.onError) === null || _middlewares$onError === void 0 || _middlewares$onError.call(middlewares, error);
382
+ logger({
383
+ module,
384
+ level: "error",
385
+ type,
386
+ message
387
+ });
388
+ }
389
+ });
390
+ //#endregion
391
+ //#region src/core/config.ts
392
+ var MOUNTED_COMPONENTS_KEY = Symbol("MOUNTED_COMPONENTS");
393
+ var MESSAGE_KEY = Symbol("MESSAGE");
394
+ var CONFIG_KEY = Symbol("CONFIG");
395
+ var DEPENDENCIES_KEY = Symbol("DEPENDENCIES");
396
+ var LOCALE_KEY = Symbol("LOCALE");
397
+ var STANDALONE_CONFIG_READY = Symbol("STANDALONE_CONFIG_READY");
398
+ var I18NActions = /* @__PURE__ */ function(I18NActions) {
399
+ I18NActions["SetLocale"] = "setLocale";
400
+ I18NActions["GetLocale"] = "getLocale";
401
+ I18NActions["UpdateI18nConfig"] = "updateI18nConfig";
402
+ return I18NActions;
403
+ }({});
404
+ var VUE_FUNCTION_OPTIONS = [
405
+ "beforeCreate",
406
+ "created",
407
+ "beforeMount",
408
+ "mounted",
409
+ "beforeUpdate",
410
+ "updated",
411
+ "beforeUnmount",
412
+ "unmounted",
413
+ "errorCaptured",
414
+ "renderTracked",
415
+ "renderTriggered",
416
+ "activated",
417
+ "deactivated",
418
+ "setup",
419
+ "data",
420
+ "render"
421
+ ];
422
+ //#endregion
423
+ //#region src/core/message.ts
424
+ var createPostMessage = (module) => async ({ event, payload }) => {
425
+ const middlewares = connector_default.getMiddlewares();
426
+ const logger = createLogger(module);
427
+ let next = {
428
+ trigger: module,
429
+ event,
430
+ payload
431
+ };
432
+ if (middlewares === null || middlewares === void 0 ? void 0 : middlewares.onMessage) {
433
+ const check = await middlewares.onMessage(next);
434
+ if (check === false) {
435
+ logger.warn("blocked by middleware", "POST_MESSAGE");
436
+ return;
437
+ }
438
+ if (check !== true) next = _objectSpread2(_objectSpread2({}, next), check);
439
+ }
440
+ emit({ [MESSAGE_KEY]: {
441
+ timestamp: +/* @__PURE__ */ new Date(),
442
+ event: next.event,
443
+ trigger: module,
444
+ payload: next.payload
445
+ } });
446
+ };
447
+ var createOnMessage = (module, onMessage) => subscribe({ [MESSAGE_KEY](v) {
448
+ const { trigger, payload, event } = v;
449
+ if (module !== trigger) onMessage({
450
+ event,
451
+ payload,
452
+ trigger
453
+ });
454
+ } });
455
+ //#endregion
456
+ //#region src/core/i18n.ts
457
+ function createI18nConfig(method, module, callback) {
458
+ if (!method) return;
459
+ const i18nConfig = method();
460
+ if (!isPromiseLike(i18nConfig)) {
461
+ if (module) connector_default.setI18nConfig(module, i18nConfig);
462
+ else connector_default.setGlobalI18nConfig(i18nConfig);
463
+ return;
464
+ }
465
+ if (module) connector_default.setI18nConfig(module, {
466
+ loading: true,
467
+ resources: {}
468
+ });
469
+ else connector_default.setGlobalI18nConfig({
470
+ loading: true,
471
+ resources: {}
472
+ });
473
+ i18nConfig.then((res) => {
474
+ if (module) {
475
+ connector_default.setI18nConfig(module, _objectSpread2(_objectSpread2({}, res), {}, { loading: false }));
476
+ callback === null || callback === void 0 || callback();
477
+ return;
478
+ }
479
+ const locale = getStore(LOCALE_KEY);
480
+ emit({ [LOCALE_KEY]: void 0 }, true);
481
+ emit({ [LOCALE_KEY]: locale }, true);
482
+ connector_default.setGlobalI18nConfig(_objectSpread2(_objectSpread2({}, res), {}, { loading: false }));
483
+ }).catch((e) => {
484
+ onError(new VariousError({
485
+ module: module || "app",
486
+ type: "I18N",
487
+ originalError: e
488
+ }));
489
+ });
490
+ }
491
+ function createI18n(module, updater) {
492
+ const ctx = (key, params, defaultString) => {
493
+ const i18nConfig = connector_default.getI18nConfig(module) || connector_default.getGlobalI18nConfig();
494
+ let defaultText = defaultString;
495
+ if (defaultText === void 0) defaultText = typeof params === "string" ? params : key;
496
+ if (!i18nConfig) {
497
+ onError(new VariousError({
498
+ module,
499
+ type: "I18N",
500
+ originalError: /* @__PURE__ */ new Error("config not exist")
501
+ }));
502
+ return defaultText;
503
+ }
504
+ if (i18nConfig.loading) return defaultText;
505
+ const { resources } = i18nConfig;
506
+ const locale = getStore(LOCALE_KEY);
507
+ const resource = resources === null || resources === void 0 ? void 0 : resources[locale];
508
+ if (!resource) {
509
+ onError(new VariousError({
510
+ module,
511
+ type: "I18N",
512
+ originalError: /* @__PURE__ */ new Error(`locale resource \`${locale}\` not exist`)
513
+ }));
514
+ return defaultText;
515
+ }
516
+ if (!resource[key]) {
517
+ onError(new VariousError({
518
+ module,
519
+ type: "I18N",
520
+ originalError: /* @__PURE__ */ new Error(`locale key \`${key}\` not exist`)
521
+ }));
522
+ return defaultText;
523
+ }
524
+ const text = resource[key];
525
+ if (!params || typeof params === "string" || Object.prototype.toString.call(params) !== "[object Object]") return text;
526
+ const args = Object.keys(params);
527
+ if (!args.length) return text;
528
+ return args.reduce((next, arg) => {
529
+ const regex = new RegExp(`{\\s*${arg}\\s*}`, "g");
530
+ return next.replace(regex, params[arg].toString());
531
+ }, text);
532
+ };
533
+ ctx.update = (config) => {
534
+ const next = _objectSpread2(_objectSpread2({}, connector_default.getI18nConfig(module)), config);
535
+ connector_default.setI18nConfig(module, next);
536
+ updater();
537
+ };
538
+ return ctx;
539
+ }
540
+ //#endregion
541
+ //#region \0vite/preload-helper.js
542
+ var scriptRel = "modulepreload";
543
+ var assetsURL = function(dep) {
544
+ return "/" + dep;
545
+ };
546
+ var seen = {};
547
+ var __vitePreload = function preload(baseModule, deps, importerUrl) {
548
+ let promise = Promise.resolve();
549
+ if (deps && deps.length > 0) {
550
+ const links = document.getElementsByTagName("link");
551
+ const cspNonceMeta = document.querySelector("meta[property=csp-nonce]");
552
+ const cspNonce = (cspNonceMeta === null || cspNonceMeta === void 0 ? void 0 : cspNonceMeta.nonce) || (cspNonceMeta === null || cspNonceMeta === void 0 ? void 0 : cspNonceMeta.getAttribute("nonce"));
553
+ function allSettled(promises) {
554
+ return Promise.all(promises.map((p) => Promise.resolve(p).then((value) => ({
555
+ status: "fulfilled",
556
+ value
557
+ }), (reason) => ({
558
+ status: "rejected",
559
+ reason
560
+ }))));
561
+ }
562
+ function importMetaResolve(specifier) {
563
+ if (import.meta.resolve) return import.meta.resolve(specifier);
564
+ return new URL(
565
+ specifier,
566
+ /** #__KEEP__ */
567
+ import.meta.url
568
+ ).href;
569
+ }
570
+ promise = allSettled(deps.map((dep) => {
571
+ dep = assetsURL(dep, importerUrl);
572
+ dep = importMetaResolve(dep);
573
+ if (dep in seen) return;
574
+ seen[dep] = true;
575
+ const isCss = dep.endsWith(".css");
576
+ for (let i = links.length - 1; i >= 0; i--) {
577
+ const link = links[i];
578
+ if (link.href === dep && (!isCss || link.rel === "stylesheet")) return;
579
+ }
580
+ const link = document.createElement("link");
581
+ link.rel = isCss ? "stylesheet" : scriptRel;
582
+ if (!isCss) link.as = "script";
583
+ link.crossOrigin = "";
584
+ link.href = dep;
585
+ if (cspNonce) link.setAttribute("nonce", cspNonce);
586
+ document.head.appendChild(link);
587
+ if (isCss) return new Promise((res, rej) => {
588
+ link.addEventListener("load", res);
589
+ link.addEventListener("error", () => rej(/* @__PURE__ */ new Error(`Unable to preload CSS for ${dep}`)));
590
+ });
591
+ }));
592
+ }
593
+ function handlePreloadError(err) {
594
+ const e = new Event("vite:preloadError", { cancelable: true });
595
+ e.payload = err;
596
+ window.dispatchEvent(e);
597
+ if (!e.defaultPrevented) throw err;
598
+ }
599
+ return promise.then((res) => {
600
+ for (const item of res || []) {
601
+ if (item.status !== "rejected") continue;
602
+ handlePreloadError(item.reason);
603
+ }
604
+ return baseModule().catch(handlePreloadError);
605
+ });
606
+ };
607
+ //#endregion
608
+ //#region src/core/system.ts
609
+ function getRegistry() {
610
+ if (!window.__various) window.__various = {
611
+ modules: /* @__PURE__ */ new Map(),
612
+ urls: /* @__PURE__ */ new Map(),
613
+ loaded: /* @__PURE__ */ new Map()
614
+ };
615
+ return window.__various;
616
+ }
617
+ var { modules: moduleRegistry, urls: moduleUrls, loaded: loadedModules } = getRegistry();
618
+ function resolveUrl(url) {
619
+ if (url.startsWith("http") || url.startsWith("/") || url.startsWith("blob:")) return url;
620
+ return new URL(url, document.baseURI).href;
621
+ }
622
+ function setModuleUrl(name, url) {
623
+ moduleUrls.set(name, url);
624
+ }
625
+ function getModuleUrl(name) {
626
+ return moduleUrls.get(name);
627
+ }
628
+ function getAllModuleUrls() {
629
+ const result = {};
630
+ moduleUrls.forEach((url, name) => {
631
+ result[name] = url;
632
+ });
633
+ return result;
634
+ }
635
+ function getInjectedModuleNames() {
636
+ const result = [];
637
+ moduleRegistry.forEach((_, name) => {
638
+ if (!moduleUrls.has(name)) result.push(name);
639
+ });
640
+ return result;
641
+ }
642
+ async function importModule(name) {
643
+ const url = moduleUrls.get(name);
644
+ if (url) {
645
+ const absoluteUrl = resolveUrl(url);
646
+ if (loadedModules.has(absoluteUrl)) return loadedModules.get(absoluteUrl);
647
+ const mod = await __vitePreload(() => import(
648
+ /* @vite-ignore */
649
+ absoluteUrl
650
+ ), []);
651
+ loadedModules.set(absoluteUrl, mod);
652
+ return mod;
653
+ }
654
+ if (moduleRegistry.has(name)) return moduleRegistry.get(name);
655
+ throw new Error(`module "${name}" not defined`);
656
+ }
657
+ function isModuleDefined(name) {
658
+ if (moduleRegistry.has(name)) return true;
659
+ const url = moduleUrls.get(name);
660
+ if (url && loadedModules.has(resolveUrl(url))) return true;
661
+ return false;
662
+ }
663
+ function isModuleSpecified$1(name) {
664
+ return moduleUrls.has(name) || isModuleDefined(name);
665
+ }
666
+ function deleteModule(name) {
667
+ moduleRegistry.delete(name);
668
+ const url = moduleUrls.get(name);
669
+ if (url) loadedModules.delete(resolveUrl(url));
670
+ }
671
+ function setModule(name, mod) {
672
+ if (mod && typeof mod === "object" && !("default" in mod)) moduleRegistry.set(name, _objectSpread2({ default: mod }, mod));
673
+ else moduleRegistry.set(name, mod);
674
+ }
675
+ function createModuleBlobUrl(name) {
676
+ const mod = moduleRegistry.get(name);
677
+ if (!mod) return null;
678
+ const realMod = typeof mod === "object" && "default" in mod ? mod : { default: mod };
679
+ const keys = Object.keys(realMod).filter((k) => k !== "default" && /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(k));
680
+ const lines = [
681
+ `const m = window.__various.modules.get(${JSON.stringify(name)});`,
682
+ "export default m.default || m;",
683
+ ...keys.map((k) => `export const ${k} = m[${JSON.stringify(k)}];`)
684
+ ];
685
+ const blob = new Blob([lines.join("\n")], { type: "application/javascript" });
686
+ return URL.createObjectURL(blob);
687
+ }
688
+ //#endregion
689
+ //#region src/core/helper.ts
690
+ var getUrlHash = (url) => `${url}?${+/* @__PURE__ */ new Date()}`;
691
+ var getModuleInfo = (module) => {
692
+ const [name, entry] = module.split(".");
693
+ return {
694
+ name,
695
+ entry
696
+ };
697
+ };
698
+ var isModuleLoaded = (module) => {
699
+ const { name } = getModuleInfo(module);
700
+ return isModuleDefined(name);
701
+ };
702
+ var isModuleSpecified = (module) => {
703
+ const { name } = getModuleInfo(module);
704
+ return isModuleSpecified$1(name);
705
+ };
706
+ var getMountedComponents = () => getStore(MOUNTED_COMPONENTS_KEY);
707
+ var resetDependencyConfig = (module, url) => {
708
+ const { name } = getModuleInfo(module);
709
+ const dependencies = getStore(DEPENDENCIES_KEY);
710
+ if (url && isModuleDefined(name)) return;
711
+ if (!dependencies[name] && url) {
712
+ setModuleUrl(name, url);
713
+ return;
714
+ }
715
+ let moduleUrl = getUrlHash(dependencies[name]);
716
+ if (url) moduleUrl = getUrlHash(url);
717
+ deleteModule(name);
718
+ setModuleUrl(name, moduleUrl);
719
+ };
720
+ var onError = (e) => {
721
+ const { module, type } = e;
722
+ createLogger(module).error(e, type);
723
+ };
724
+ var VariousError = class extends Error {
725
+ constructor(data) {
726
+ super(data.originalError.message);
727
+ _defineProperty(this, "type", void 0);
728
+ _defineProperty(this, "originalError", void 0);
729
+ _defineProperty(this, "module", void 0);
730
+ this.type = data.type;
731
+ this.originalError = data.originalError;
732
+ this.module = data.module;
733
+ }
734
+ };
735
+ function checkReactComponent(component, module) {
736
+ return new Promise((reslove, reject) => {
737
+ var _component$prototype;
738
+ if (component.$$typeof || ((_component$prototype = component.prototype) === null || _component$prototype === void 0 ? void 0 : _component$prototype.isReactComponent) || typeof component === "function") {
739
+ reslove();
740
+ return;
741
+ }
742
+ reject(new VariousError({
743
+ module,
744
+ originalError: /* @__PURE__ */ new Error("not a valid React component"),
745
+ type: "INVALID_COMPONENT"
746
+ }));
747
+ });
748
+ }
749
+ function isPromiseLike(value) {
750
+ return value != null && typeof value.then === "function";
751
+ }
752
+ function checkVueComponent(component, module) {
753
+ const versionRegex = new RegExp(`^3\\.`);
754
+ return new Promise((resolve, reject) => {
755
+ importModule("vue").then((Vue) => {
756
+ const vueObj = Vue.default || Vue;
757
+ if (!versionRegex.test(vueObj.version)) {
758
+ reject(/* @__PURE__ */ new Error(`Vue 3+ required, detected an incompatible version`));
759
+ return;
760
+ }
761
+ if (typeof (component === null || component === void 0 ? void 0 : component.render) === "function" || typeof (component === null || component === void 0 ? void 0 : component.setup) === "function") {
762
+ resolve();
763
+ return;
764
+ }
765
+ reject(new VariousError({
766
+ module,
767
+ originalError: /* @__PURE__ */ new Error("not a valid Vue component"),
768
+ type: "INVALID_COMPONENT"
769
+ }));
770
+ }).catch(reject);
771
+ });
772
+ }
773
+ function parseComponentActions(params) {
774
+ const { componentNode, module, type, i18nUpdate } = params;
775
+ const actions = {};
776
+ let onMessageAction;
777
+ let i18nAction;
778
+ Object.getOwnPropertyNames(componentNode).forEach((method) => {
779
+ if (typeof componentNode[method] !== "function") return;
780
+ if (method === "$onMessage") {
781
+ onMessageAction = componentNode[method];
782
+ return;
783
+ }
784
+ if (method === "$i18n") {
785
+ i18nAction = componentNode[method];
786
+ return;
787
+ }
788
+ if (type === "vue3" && VUE_FUNCTION_OPTIONS.includes(method)) return;
789
+ actions[method] = componentNode[method];
790
+ });
791
+ if (i18nAction) createI18nConfig(i18nAction, module, i18nUpdate);
792
+ connector_default.setComponentActions(module, actions);
793
+ if (onMessageAction) return createOnMessage(module, onMessageAction);
794
+ return () => null;
795
+ }
796
+ function updateMountedComponent(module) {
797
+ const mountedComponents = getMountedComponents();
798
+ if (!mountedComponents.includes(module)) mountedComponents.push(module);
799
+ emit({ [MOUNTED_COMPONENTS_KEY]: mountedComponents }, true);
800
+ }
801
+ function updateUnMountComponent(module) {
802
+ let mountedComponents = getMountedComponents();
803
+ mountedComponents = mountedComponents.filter((item) => item !== module);
804
+ emit({ [MOUNTED_COMPONENTS_KEY]: mountedComponents }, true);
805
+ connector_default.deleteComponentActions(module);
806
+ }
807
+ function getSelfInfo(params) {
808
+ const { module, url } = params;
809
+ const dependencies = getStore(DEPENDENCIES_KEY);
810
+ const { name } = getModuleInfo(module);
811
+ return {
812
+ module,
813
+ url: url || dependencies[name] || getModuleUrl(name) || ""
814
+ };
815
+ }
816
+ function getClassNameWithModule(module, prefix) {
817
+ const { name, entry } = getModuleInfo(module);
818
+ return `${prefix} ${[name, entry].filter(Boolean).join("-")}`;
819
+ }
820
+ //#endregion
821
+ //#region src/core/dispatch.ts
822
+ var createDispatch = (module) => async function(params) {
823
+ const middlewares = connector_default.getMiddlewares();
824
+ const logger = createLogger(module);
825
+ let { action, payload, target } = params;
826
+ if (middlewares === null || middlewares === void 0 ? void 0 : middlewares.onDispatch) {
827
+ const check = await middlewares.onDispatch({
828
+ target,
829
+ action,
830
+ payload,
831
+ trigger: module
832
+ });
833
+ if (check === false) {
834
+ logger.warn("blocked by middleware", "DISPATCH");
835
+ return Promise.resolve();
836
+ }
837
+ if (check !== true) {
838
+ target = check.target;
839
+ action = check.action;
840
+ payload = check.payload;
841
+ }
842
+ }
843
+ if (target === "app") {
844
+ const storeAction = connector_default.getStoreActions()[action];
845
+ if (action === I18NActions.SetLocale) {
846
+ emit({ [LOCALE_KEY]: payload }, true);
847
+ return payload;
848
+ }
849
+ if (action === I18NActions.GetLocale) return getStore(LOCALE_KEY);
850
+ if (action === I18NActions.UpdateI18nConfig) {
851
+ const locale = getStore(LOCALE_KEY);
852
+ connector_default.setGlobalI18nConfig(payload);
853
+ emit({ [LOCALE_KEY]: void 0 }, true);
854
+ emit({ [LOCALE_KEY]: locale }, true);
855
+ return locale;
856
+ }
857
+ if (!storeAction) {
858
+ const errorMessage = `action "${action}" is not present`;
859
+ const error = new VariousError({
860
+ module,
861
+ type: "DISPATCH",
862
+ originalError: new Error(errorMessage)
863
+ });
864
+ onError(error);
865
+ throw error;
866
+ }
867
+ return dispatch(storeAction, payload, module);
868
+ }
869
+ const componentActions = connector_default.getComponentActions(target);
870
+ if (!componentActions) {
871
+ const error = new VariousError({
872
+ module,
873
+ type: "DISPATCH",
874
+ originalError: /* @__PURE__ */ new Error("component is not ready")
875
+ });
876
+ onError(error);
877
+ throw error;
878
+ }
879
+ const componentAction = componentActions[action];
880
+ if (!componentAction) {
881
+ const errorMessage = `action "${action}" is not present`;
882
+ const error = new VariousError({
883
+ module,
884
+ type: "DISPATCH",
885
+ originalError: new Error(errorMessage)
886
+ });
887
+ onError(error);
888
+ throw error;
889
+ }
890
+ return Promise.resolve(componentAction({
891
+ payload,
892
+ trigger: module
893
+ }));
894
+ };
895
+ //#endregion
896
+ //#region src/core/create-module.ts
897
+ var createModule = (config, logError = true) => {
898
+ const dependencies = getStore(DEPENDENCIES_KEY);
899
+ const middlewares = connector_default.getMiddlewares();
900
+ const { url, module } = config;
901
+ const { name, entry } = getModuleInfo(module);
902
+ const loadStart = +/* @__PURE__ */ new Date();
903
+ const logOnError = (e) => {
904
+ if (logError) onError(e);
905
+ };
906
+ if (url) resetDependencyConfig(module, url);
907
+ return new Promise((resolve, reject) => {
908
+ if (!url && !dependencies[name] && !isModuleSpecified(module)) {
909
+ const error = new VariousError({
910
+ module,
911
+ type: "NOT_DEFINED",
912
+ originalError: /* @__PURE__ */ new Error(`module "${name}" not defined`)
913
+ });
914
+ logOnError(error);
915
+ reject(error);
916
+ return;
917
+ }
918
+ importModule(name).then((C) => {
919
+ var _middlewares$onLoad;
920
+ const loadEnd = +/* @__PURE__ */ new Date();
921
+ middlewares === null || middlewares === void 0 || (_middlewares$onLoad = middlewares.onLoad) === null || _middlewares$onLoad === void 0 || _middlewares$onLoad.call(middlewares, {
922
+ module,
923
+ loadStart,
924
+ loadEnd,
925
+ beenLoaded: isModuleLoaded(module)
926
+ });
927
+ if (!C || typeof C === "object" && Object.keys(C).length === 0) {
928
+ const error = new VariousError({
929
+ module,
930
+ type: "INVALID_MODULE",
931
+ originalError: /* @__PURE__ */ new Error(`module "${name}" invalid`)
932
+ });
933
+ resetDependencyConfig(module);
934
+ logOnError(error);
935
+ reject(error);
936
+ return;
937
+ }
938
+ const defaultModule = "default" in C ? C.default : C;
939
+ const actualModule = !entry ? defaultModule : C[entry];
940
+ if (actualModule === void 0 && entry) {
941
+ const error = new VariousError({
942
+ module,
943
+ type: "SUBMODULE_NOT_DEFINED",
944
+ originalError: /* @__PURE__ */ new Error(`submodule "${entry}" not defined`)
945
+ });
946
+ resetDependencyConfig(module);
947
+ logOnError(error);
948
+ reject(error);
949
+ return;
950
+ }
951
+ resolve(actualModule);
952
+ }).catch((e) => {
953
+ resetDependencyConfig(module, url);
954
+ let errorType = "LOADING_ERROR";
955
+ if (!url && e.message && !e.message.includes(name)) errorType = "SUBMODULE_LOADING_ERROR";
956
+ const error = new VariousError({
957
+ module: name,
958
+ type: errorType,
959
+ originalError: e
960
+ });
961
+ logOnError(error);
962
+ reject(error);
963
+ });
964
+ });
965
+ };
966
+ //#endregion
967
+ //#region src/core/react-component.tsx
968
+ function reactComponent(config) {
969
+ const { module, url, watchKeys, onMounted } = config;
970
+ const storeKeys = watchKeys || Object.keys(getStore());
971
+ class R extends Component {
972
+ constructor(..._args) {
973
+ var _this;
974
+ super(..._args);
975
+ _this = this;
976
+ _defineProperty(this, "state", {
977
+ componentReady: false,
978
+ isError: false
979
+ });
980
+ _defineProperty(this, "error", void 0);
981
+ _defineProperty(this, "ComponentNode", void 0);
982
+ _defineProperty(this, "isUnMounted", void 0);
983
+ _defineProperty(this, "unSubscribeMessage", () => null);
984
+ _defineProperty(this, "mountComponent", async () => {
985
+ try {
986
+ const componentNode = await createModule({
987
+ module,
988
+ url
989
+ }, false);
990
+ if (_this.isUnMounted) return;
991
+ await checkReactComponent(componentNode, module);
992
+ componentNode.displayName = module;
993
+ updateMountedComponent(module);
994
+ _this.unSubscribeMessage = parseComponentActions({
995
+ componentNode,
996
+ module,
997
+ i18nUpdate: () => _this.forceUpdate()
998
+ });
999
+ _this.ComponentNode = componentNode;
1000
+ _this.setState({ componentReady: true });
1001
+ onMounted === null || onMounted === void 0 || onMounted();
1002
+ } catch (e) {
1003
+ if (_this.isUnMounted) return;
1004
+ _this.error = e;
1005
+ _this.setState({
1006
+ componentReady: true,
1007
+ isError: true
1008
+ });
1009
+ }
1010
+ });
1011
+ _defineProperty(this, "$postMessage", createPostMessage(module));
1012
+ _defineProperty(this, "$dispatch", createDispatch(module));
1013
+ _defineProperty(this, "$t", createI18n(module, () => this.forceUpdate()));
1014
+ _defineProperty(this, "$logger", createLogger(module));
1015
+ _defineProperty(this, "$self", getSelfInfo({
1016
+ module,
1017
+ url
1018
+ }));
1019
+ }
1020
+ componentDidMount() {
1021
+ this.isUnMounted = false;
1022
+ this.mountComponent();
1023
+ }
1024
+ componentWillUnmount() {
1025
+ this.error = void 0;
1026
+ this.ComponentNode = null;
1027
+ this.isUnMounted = true;
1028
+ this.unSubscribeMessage();
1029
+ updateUnMountComponent(module);
1030
+ }
1031
+ render() {
1032
+ const Fallback = connector_default.getFallbackComponent();
1033
+ const { $silent, $componentProps, $ref } = this.props;
1034
+ const { componentReady, isError } = this.state;
1035
+ const store = getUserStore();
1036
+ const locale = getStore(LOCALE_KEY);
1037
+ const ComponentNode = this.ComponentNode;
1038
+ if (isError) throw this.error;
1039
+ if (!componentReady) {
1040
+ if ($silent || isModuleLoaded(module)) return null;
1041
+ return /* @__PURE__ */ e.createElement(Fallback, {
1042
+ $self: this.$self,
1043
+ $store: store,
1044
+ $locale: locale
1045
+ });
1046
+ }
1047
+ return /* @__PURE__ */ e.createElement(ComponentNode, _objectSpread2(_objectSpread2({}, $componentProps), {}, {
1048
+ $self: this.$self,
1049
+ $dispatch: this.$dispatch,
1050
+ $store: store,
1051
+ $postMessage: this.$postMessage,
1052
+ $t: this.$t,
1053
+ $logger: this.$logger,
1054
+ ref: $ref,
1055
+ $locale: locale
1056
+ }));
1057
+ }
1058
+ }
1059
+ _defineProperty(R, "displayName", "various-react-component");
1060
+ const Connected = connect(...storeKeys, LOCALE_KEY)(R);
1061
+ Connected.displayName = "various-connector";
1062
+ return Connected;
1063
+ }
1064
+ //#endregion
1065
+ //#region src/core/vue-component.tsx
1066
+ function vueComponent(config) {
1067
+ const { module, url, watchKeys, onMounted } = config;
1068
+ const storeKeys = watchKeys || Object.keys(getStore());
1069
+ const V = (props) => {
1070
+ const store = useStore(...storeKeys, LOCALE_KEY);
1071
+ const locale = store[LOCALE_KEY];
1072
+ const vueRef = useRef();
1073
+ const vmRef = useRef();
1074
+ const isVueMounted = useRef(false);
1075
+ const errorRef = useRef();
1076
+ const isUnMountedRef = useRef(false);
1077
+ const ComponentNodeRef = useRef();
1078
+ const selfRef = useRef(getSelfInfo({
1079
+ module,
1080
+ url
1081
+ }));
1082
+ const containerDivRef = useRef(null);
1083
+ const propsReactiveRef = useRef();
1084
+ const storeReactiveRef = useRef();
1085
+ const localeReactiveRef = useRef();
1086
+ const unMountVue = useRef();
1087
+ const unSubscribeMessageRef = useRef();
1088
+ const updateVueComponentRef = useRef();
1089
+ const [componentReady, setComponentReady] = useState(false);
1090
+ const [isError, setIsError] = useState(false);
1091
+ const Fallback = connector_default.getFallbackComponent();
1092
+ const { $silent, $componentProps } = props;
1093
+ const mountVue = useCallback(() => {
1094
+ const $logger = createLogger(module);
1095
+ const $dispatch = createDispatch(module);
1096
+ const $postMessage = createPostMessage(module);
1097
+ const $t = createI18n(module, () => {
1098
+ var _updateVueComponentRe;
1099
+ (_updateVueComponentRe = updateVueComponentRef.current) === null || _updateVueComponentRe === void 0 || _updateVueComponentRe.call(updateVueComponentRef);
1100
+ });
1101
+ propsReactiveRef.current = vueRef.current.ref(_objectSpread2({}, $componentProps));
1102
+ storeReactiveRef.current = vueRef.current.ref(_objectSpread2({}, store));
1103
+ localeReactiveRef.current = vueRef.current.ref(locale);
1104
+ const vueApp = vueRef.current.createApp({
1105
+ setup() {
1106
+ const renderKey = vueRef.current.ref(0);
1107
+ updateVueComponentRef.current = () => {
1108
+ renderKey.value += 1;
1109
+ };
1110
+ return { key: renderKey };
1111
+ },
1112
+ errorCaptured(e) {
1113
+ var _error$message;
1114
+ const error = e;
1115
+ errorRef.current = ((_error$message = error.message) === null || _error$message === void 0 ? void 0 : _error$message.includes("https://react")) ? new VariousError({
1116
+ originalError: /* @__PURE__ */ new Error("not a valid Vue component"),
1117
+ module,
1118
+ type: "INVALID_COMPONENT"
1119
+ }) : error;
1120
+ setIsError(true);
1121
+ },
1122
+ render() {
1123
+ return vueRef.current.h(ComponentNodeRef.current, _objectSpread2(_objectSpread2({}, propsReactiveRef.current.value), {}, {
1124
+ various: {
1125
+ $dispatch,
1126
+ $logger,
1127
+ $postMessage,
1128
+ $t,
1129
+ $store: storeReactiveRef.current.value,
1130
+ $self: selfRef.current,
1131
+ $locale: localeReactiveRef.current.value
1132
+ },
1133
+ key: this.key
1134
+ }));
1135
+ }
1136
+ });
1137
+ if (!vmRef.current) vmRef.current = vueApp.mount(containerDivRef.current);
1138
+ isVueMounted.current = true;
1139
+ unMountVue.current = () => vueApp.unmount();
1140
+ }, [
1141
+ $componentProps,
1142
+ store,
1143
+ locale
1144
+ ]);
1145
+ const mountComponent = useCallback(async () => {
1146
+ try {
1147
+ const vue = await createModule({ module: "vue" });
1148
+ vueRef.current = vue;
1149
+ const componentNode = await createModule({
1150
+ module,
1151
+ url
1152
+ }, false);
1153
+ if (isUnMountedRef.current) return;
1154
+ await checkVueComponent(componentNode, module);
1155
+ updateMountedComponent(module);
1156
+ unSubscribeMessageRef.current = parseComponentActions({
1157
+ componentNode,
1158
+ module,
1159
+ type: "vue3",
1160
+ i18nUpdate() {
1161
+ var _updateVueComponentRe2;
1162
+ (_updateVueComponentRe2 = updateVueComponentRef.current) === null || _updateVueComponentRe2 === void 0 || _updateVueComponentRe2.call(updateVueComponentRef);
1163
+ }
1164
+ });
1165
+ ComponentNodeRef.current = componentNode;
1166
+ setTimeout(mountVue);
1167
+ setComponentReady(true);
1168
+ onMounted === null || onMounted === void 0 || onMounted();
1169
+ } catch (e) {
1170
+ if (isUnMountedRef.current) return;
1171
+ errorRef.current = e;
1172
+ setComponentReady(true);
1173
+ setIsError(true);
1174
+ }
1175
+ }, [mountVue]);
1176
+ useEffect(() => {
1177
+ isUnMountedRef.current = false;
1178
+ return () => {
1179
+ var _unMountVue$current, _unSubscribeMessageRe;
1180
+ errorRef.current = void 0;
1181
+ ComponentNodeRef.current = void 0;
1182
+ isUnMountedRef.current = true;
1183
+ updateUnMountComponent(module);
1184
+ (_unMountVue$current = unMountVue.current) === null || _unMountVue$current === void 0 || _unMountVue$current.call(unMountVue);
1185
+ (_unSubscribeMessageRe = unSubscribeMessageRef.current) === null || _unSubscribeMessageRe === void 0 || _unSubscribeMessageRe.call(unSubscribeMessageRef);
1186
+ isVueMounted.current = false;
1187
+ };
1188
+ }, []);
1189
+ useEffect(() => {
1190
+ if (isVueMounted.current) return;
1191
+ mountComponent();
1192
+ }, [mountComponent]);
1193
+ useEffect(() => {
1194
+ if (propsReactiveRef.current) propsReactiveRef.current.value = _objectSpread2({}, $componentProps);
1195
+ }, [$componentProps]);
1196
+ useEffect(() => {
1197
+ if (storeReactiveRef.current) storeReactiveRef.current.value = _objectSpread2({}, store);
1198
+ }, [store]);
1199
+ useEffect(() => {
1200
+ if (localeReactiveRef.current) localeReactiveRef.current.value = locale;
1201
+ }, [locale]);
1202
+ if (isError) throw errorRef.current;
1203
+ return /* @__PURE__ */ e.createElement(e.Fragment, null, !componentReady && !$silent && !isModuleLoaded(module) ? /* @__PURE__ */ e.createElement(Fallback, {
1204
+ $self: selfRef.current,
1205
+ $store: store,
1206
+ $locale: locale
1207
+ }) : null, /* @__PURE__ */ e.createElement("div", {
1208
+ className: getClassNameWithModule(module, "various-vue-component"),
1209
+ ref: containerDivRef
1210
+ }));
1211
+ };
1212
+ V.displayName = module;
1213
+ const VueComponent = (props) => /* @__PURE__ */ e.createElement(V, props);
1214
+ VueComponent.displayName = "various-vue-component";
1215
+ return VueComponent;
1216
+ }
1217
+ //#endregion
1218
+ //#region src/core/error-boundary.tsx
1219
+ var ErrorBoundary = class extends Component {
1220
+ constructor(..._args) {
1221
+ super(..._args);
1222
+ _defineProperty(this, "state", { hasError: false });
1223
+ _defineProperty(this, "error", void 0);
1224
+ _defineProperty(this, "$self", getSelfInfo(this.props));
1225
+ _defineProperty(this, "reload", () => {
1226
+ this.error = void 0;
1227
+ this.setState({ hasError: false });
1228
+ });
1229
+ }
1230
+ componentDidCatch(e) {
1231
+ const { module } = this.props;
1232
+ const error = e instanceof VariousError ? e : new VariousError({
1233
+ module,
1234
+ type: module === "app" ? "APP_ERROR" : "SCRIPT_ERROR",
1235
+ originalError: e
1236
+ });
1237
+ this.setState({ hasError: true });
1238
+ this.error = error;
1239
+ onError(error);
1240
+ resetDependencyConfig(module);
1241
+ updateUnMountComponent(module);
1242
+ }
1243
+ render() {
1244
+ const ErrorFallbackNode = connector_default.getErrorFallbackComponent();
1245
+ const store = getUserStore();
1246
+ const locale = getStore(LOCALE_KEY);
1247
+ if (this.state.hasError) return /* @__PURE__ */ e.createElement(ErrorFallbackNode, {
1248
+ $self: this.$self,
1249
+ $reload: this.reload,
1250
+ $store: store,
1251
+ $error: this.error,
1252
+ $locale: locale
1253
+ });
1254
+ return this.props.children;
1255
+ }
1256
+ };
1257
+ _defineProperty(ErrorBoundary, "displayName", "various-error-boundary");
1258
+ //#endregion
1259
+ //#region \0@oxc-project+runtime@0.142.0/helpers/esm/objectWithoutPropertiesLoose.js
1260
+ function _objectWithoutPropertiesLoose(r, e) {
1261
+ if (null == r) return {};
1262
+ var t = {};
1263
+ for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
1264
+ if (e.includes(n)) continue;
1265
+ t[n] = r[n];
1266
+ }
1267
+ return t;
1268
+ }
1269
+ //#endregion
1270
+ //#region \0@oxc-project+runtime@0.142.0/helpers/esm/objectWithoutProperties.js
1271
+ function _objectWithoutProperties(e, t) {
1272
+ if (null == e) return {};
1273
+ var o, r, i = _objectWithoutPropertiesLoose(e, t);
1274
+ if (Object.getOwnPropertySymbols) {
1275
+ var s = Object.getOwnPropertySymbols(e);
1276
+ for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
1277
+ }
1278
+ return i;
1279
+ }
1280
+ //#endregion
1281
+ //#region src/core/create-component.tsx
1282
+ var _excluded = ["$silent", "$ref"];
1283
+ var createComponent = (config, storeKeys) => {
1284
+ const { module, url, type = "react" } = config;
1285
+ const C = (type === "vue3" ? vueComponent : reactComponent)({
1286
+ module,
1287
+ url,
1288
+ watchKeys: storeKeys
1289
+ });
1290
+ const component = (props) => {
1291
+ const _ref = props || {}, { $silent, $ref } = _ref;
1292
+ const nextProps = {
1293
+ $componentProps: _objectWithoutProperties(_ref, _excluded),
1294
+ $silent,
1295
+ $ref
1296
+ };
1297
+ return /* @__PURE__ */ e.createElement(ErrorBoundary, {
1298
+ module,
1299
+ url
1300
+ }, /* @__PURE__ */ e.createElement(C, nextProps));
1301
+ };
1302
+ component.displayName = "various-creator";
1303
+ return component;
1304
+ };
1305
+ //#endregion
1306
+ //#region src/standalone/helper.ts
1307
+ var defineAsync = (name, dep) => {
1308
+ if (typeof dep === "string") return importModule(name).then((mod) => {
1309
+ setModule(name, mod.default || mod);
1310
+ });
1311
+ return Promise.resolve();
1312
+ };
1313
+ var importMapCreated = false;
1314
+ function ensureImportMap(defines) {
1315
+ if (importMapCreated) return;
1316
+ const imports = {};
1317
+ Object.entries(getAllModuleUrls()).forEach(([name, url]) => {
1318
+ imports[name] = url;
1319
+ });
1320
+ defines.forEach(({ key, value }) => {
1321
+ if (typeof value !== "string") {
1322
+ const blobUrl = createModuleBlobUrl(key);
1323
+ if (blobUrl) imports[key] = blobUrl;
1324
+ }
1325
+ });
1326
+ getInjectedModuleNames().forEach((name) => {
1327
+ if (!imports[name]) {
1328
+ const blobUrl = createModuleBlobUrl(name);
1329
+ if (blobUrl) imports[name] = blobUrl;
1330
+ }
1331
+ });
1332
+ if (Object.keys(imports).length === 0) return;
1333
+ const script = document.createElement("script");
1334
+ script.type = "importmap";
1335
+ script.textContent = JSON.stringify({ imports });
1336
+ document.head.appendChild(script);
1337
+ importMapCreated = true;
1338
+ }
1339
+ function defineModules(deps) {
1340
+ const defines = [];
1341
+ Object.entries(deps).forEach(([key, value]) => {
1342
+ if (isModuleSpecified(key) || value === void 0) return;
1343
+ if (typeof value === "string") setModuleUrl(key, value);
1344
+ else setModule(key, value);
1345
+ defines.push({
1346
+ key,
1347
+ value
1348
+ });
1349
+ });
1350
+ ensureImportMap(defines);
1351
+ return Promise.all(defines.map((item) => defineAsync(item.key, item.value)));
1352
+ }
1353
+ //#endregion
1354
+ //#region src/standalone/index.tsx
1355
+ createStore({
1356
+ [MOUNTED_COMPONENTS_KEY]: [],
1357
+ [MESSAGE_KEY]: null,
1358
+ [CONFIG_KEY]: {},
1359
+ [DEPENDENCIES_KEY]: {},
1360
+ [STANDALONE_CONFIG_READY]: void 0,
1361
+ [LOCALE_KEY]: "en"
1362
+ });
1363
+ setModule("react", e);
1364
+ var Standalone = (props) => {
1365
+ const { dependencies, url, module, type, $componentProps, $ref, storeKeys } = props;
1366
+ const store = useStore(STANDALONE_CONFIG_READY);
1367
+ const [componentReady, setComponentReady] = useState(false);
1368
+ const componentNode = useRef();
1369
+ useEffect(() => {
1370
+ defineModules(dependencies || {}).then(() => {
1371
+ componentNode.current = createComponent({
1372
+ module,
1373
+ url,
1374
+ type
1375
+ }, storeKeys);
1376
+ setComponentReady(true);
1377
+ });
1378
+ }, [
1379
+ url,
1380
+ module,
1381
+ dependencies,
1382
+ type,
1383
+ storeKeys
1384
+ ]);
1385
+ if (!componentReady || store[STANDALONE_CONFIG_READY] === false) {
1386
+ const FallBack = connector_default.getFallbackComponent();
1387
+ return /* @__PURE__ */ e.createElement(FallBack, {
1388
+ $self: {
1389
+ module,
1390
+ url: url || ""
1391
+ },
1392
+ $store: getUserStore(),
1393
+ $locale: store[LOCALE_KEY]
1394
+ });
1395
+ }
1396
+ const C = componentNode.current;
1397
+ return /* @__PURE__ */ e.createElement(C, _objectSpread2(_objectSpread2({}, $componentProps), {}, { ref: $ref }));
1398
+ };
1399
+ Standalone.displayName = "various-standalone";
1400
+ //#endregion
1401
+
1402
+ //# sourceMappingURL=standalone.mjs.map