@visactor/vrender 1.1.0-alpha.24 → 1.1.0-alpha.26
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.
- package/cjs/entries/bootstrap-browser-lite.d.ts +2 -0
- package/cjs/entries/bootstrap-browser-lite.js +27 -0
- package/cjs/entries/bootstrap-browser-lite.js.map +1 -0
- package/cjs/entries/bootstrap-browser.d.ts +2 -0
- package/cjs/entries/bootstrap-browser.js +19 -0
- package/cjs/entries/bootstrap-browser.js.map +1 -0
- package/cjs/entries/bootstrap-common.d.ts +3 -0
- package/cjs/entries/bootstrap-common.js +44 -0
- package/cjs/entries/bootstrap-common.js.map +1 -0
- package/cjs/entries/bootstrap-utils.d.ts +7 -0
- package/cjs/entries/bootstrap-utils.js +44 -0
- package/cjs/entries/bootstrap-utils.js.map +1 -0
- package/cjs/entries/bootstrap.js +11 -39
- package/cjs/entries/bootstrap.js.map +1 -1
- package/cjs/entries/browser.js +3 -26
- package/cjs/entries/browser.js.map +1 -1
- package/cjs/entries/shared-browser-lite.d.ts +12 -0
- package/cjs/entries/shared-browser-lite.js +31 -0
- package/cjs/entries/shared-browser-lite.js.map +1 -0
- package/cjs/entries/shared-browser.d.ts +12 -0
- package/cjs/entries/shared-browser.js +30 -0
- package/cjs/entries/shared-browser.js.map +1 -0
- package/cjs/entries/shared-registry.d.ts +16 -0
- package/cjs/entries/shared-registry.js +87 -0
- package/cjs/entries/shared-registry.js.map +1 -0
- package/cjs/entries/shared.d.ts +3 -7
- package/cjs/entries/shared.js +6 -69
- package/cjs/entries/shared.js.map +1 -1
- package/cjs/index.d.ts +1 -1
- package/cjs/index.js +1 -1
- package/cjs/index.js.map +1 -1
- package/dist/index.es.js +3099 -3933
- package/dist/index.js +3100 -3934
- package/dist/index.min.js +1 -1
- package/es/entries/bootstrap-browser-lite.d.ts +2 -0
- package/es/entries/bootstrap-browser-lite.js +51 -0
- package/es/entries/bootstrap-browser-lite.js.map +1 -0
- package/es/entries/bootstrap-browser.d.ts +2 -0
- package/es/entries/bootstrap-browser.js +15 -0
- package/es/entries/bootstrap-browser.js.map +1 -0
- package/es/entries/bootstrap-common.d.ts +3 -0
- package/es/entries/bootstrap-common.js +58 -0
- package/es/entries/bootstrap-common.js.map +1 -0
- package/es/entries/bootstrap-utils.d.ts +7 -0
- package/es/entries/bootstrap-utils.js +38 -0
- package/es/entries/bootstrap-utils.js.map +1 -0
- package/es/entries/bootstrap.js +4 -34
- package/es/entries/bootstrap.js.map +1 -1
- package/es/entries/browser.js +1 -3
- package/es/entries/browser.js.map +1 -1
- package/es/entries/shared-browser-lite.d.ts +12 -0
- package/es/entries/shared-browser-lite.js +28 -0
- package/es/entries/shared-browser-lite.js.map +1 -0
- package/es/entries/shared-browser.d.ts +12 -0
- package/es/entries/shared-browser.js +28 -0
- package/es/entries/shared-browser.js.map +1 -0
- package/es/entries/shared-registry.d.ts +16 -0
- package/es/entries/shared-registry.js +79 -0
- package/es/entries/shared-registry.js.map +1 -0
- package/es/entries/shared.d.ts +3 -7
- package/es/entries/shared.js +6 -69
- package/es/entries/shared.js.map +1 -1
- package/es/index.d.ts +1 -1
- package/es/index.js +1 -1
- package/es/index.js.map +1 -1
- package/package.json +19 -5
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: !0
|
|
5
|
+
}), exports.releaseSharedApp = exports.getSharedApp = exports.acquireSharedApp = exports.DEFAULT_SHARED_APP_KEY = void 0,
|
|
6
|
+
exports.DEFAULT_SHARED_APP_KEY = "default";
|
|
7
|
+
|
|
8
|
+
const SHARED_APP_REGISTRY_KEY = Symbol.for("visactor.vrender.sharedAppRegistry");
|
|
9
|
+
|
|
10
|
+
function getSharedAppRegistry() {
|
|
11
|
+
var _a;
|
|
12
|
+
const target = globalThis, registry = null !== (_a = target[SHARED_APP_REGISTRY_KEY]) && void 0 !== _a ? _a : new Map;
|
|
13
|
+
return target[SHARED_APP_REGISTRY_KEY] = registry, registry;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function getSharedAppEnvRegistry(env, create) {
|
|
17
|
+
const registry = getSharedAppRegistry(), envRegistry = registry.get(env);
|
|
18
|
+
if (envRegistry || !create) return envRegistry;
|
|
19
|
+
const nextEnvRegistry = new Map;
|
|
20
|
+
return registry.set(env, nextEnvRegistry), nextEnvRegistry;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function getOrCreateSharedAppEnvRegistry(env) {
|
|
24
|
+
return getSharedAppEnvRegistry(env, !0);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function removeSharedAppRecord(env, key, record) {
|
|
28
|
+
const registry = getSharedAppRegistry(), envRegistry = registry.get(env);
|
|
29
|
+
(null == envRegistry ? void 0 : envRegistry.get(key)) === record && (envRegistry.delete(key),
|
|
30
|
+
envRegistry.size || registry.delete(env));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function releaseSharedAppRecord(env, key, record) {
|
|
34
|
+
record.released || (record.released = !0, record.refCount = 0, removeSharedAppRecord(env, key, record),
|
|
35
|
+
record.releaseApp());
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function createSharedAppRecord(env, key, options, createApp) {
|
|
39
|
+
const app = createApp(options), originalRelease = app.release.bind(app), record = {
|
|
40
|
+
app: app,
|
|
41
|
+
refCount: 0,
|
|
42
|
+
released: !1,
|
|
43
|
+
releaseApp: originalRelease
|
|
44
|
+
};
|
|
45
|
+
return app.release = () => releaseSharedAppRecord(env, key, record), record;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function createSharedAppHandle(registryEnv, handleEnv, key, record) {
|
|
49
|
+
let released = !1;
|
|
50
|
+
return {
|
|
51
|
+
app: record.app,
|
|
52
|
+
env: handleEnv,
|
|
53
|
+
key: key,
|
|
54
|
+
release() {
|
|
55
|
+
if (released) return;
|
|
56
|
+
released = !0;
|
|
57
|
+
const envRegistry = getSharedAppEnvRegistry(registryEnv, !1);
|
|
58
|
+
(null == envRegistry ? void 0 : envRegistry.get(key)) !== record || record.released || (record.refCount -= 1,
|
|
59
|
+
record.refCount <= 0 && releaseSharedAppRecord(registryEnv, key, record));
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function acquireSharedApp(registryEnv, options, createApp, handleEnv = registryEnv) {
|
|
65
|
+
var _a;
|
|
66
|
+
const key = null !== (_a = options.key) && void 0 !== _a ? _a : exports.DEFAULT_SHARED_APP_KEY, envRegistry = getOrCreateSharedAppEnvRegistry(registryEnv);
|
|
67
|
+
let record = envRegistry.get(key);
|
|
68
|
+
return (null == record ? void 0 : record.app.released) && (releaseSharedAppRecord(registryEnv, key, record),
|
|
69
|
+
record = void 0), record || (record = createSharedAppRecord(registryEnv, key, options, createApp),
|
|
70
|
+
envRegistry.set(key, record)), record.refCount += 1, createSharedAppHandle(registryEnv, handleEnv, key, record);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function getSharedApp(env, key = exports.DEFAULT_SHARED_APP_KEY) {
|
|
74
|
+
var _a;
|
|
75
|
+
const record = null === (_a = getSharedAppEnvRegistry(env, !1)) || void 0 === _a ? void 0 : _a.get(key);
|
|
76
|
+
return !record || record.released || record.app.released ? null : record.app;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function releaseSharedApp(env, key = exports.DEFAULT_SHARED_APP_KEY) {
|
|
80
|
+
var _a;
|
|
81
|
+
const record = null === (_a = getSharedAppEnvRegistry(env, !1)) || void 0 === _a ? void 0 : _a.get(key);
|
|
82
|
+
record && releaseSharedAppRecord(env, key, record);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
exports.acquireSharedApp = acquireSharedApp, exports.getSharedApp = getSharedApp,
|
|
86
|
+
exports.releaseSharedApp = releaseSharedApp;
|
|
87
|
+
//# sourceMappingURL=shared-registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{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AAC,GAAG,CAAC,CAAC;IAC7D,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,QAAQ,IAAI,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE;QACrD,OAAO,IAAI,CAAC;KACb;IACD,OAAO,MAAM,CAAC,GAAG,CAAC;AACpB,CAAC;AATD,oCASC;AAED,SAAgB,gBAAgB,CAC9B,GAAS,EACT,MAA4B,8BAAsB;;IAElD,MAAM,MAAM,GAAG,MAAA,uBAAuB,CAAC,GAAG,EAAE,KAAK,CAAC,0CAAE,GAAG,CAAC,GAAG,CAAC,CAAC;IAC7D,IAAI,MAAM,EAAE;QACV,sBAAsB,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;KAC1C;AACH,CAAC;AARD,4CAQC","file":"shared-registry.js","sourcesContent":["import type { IApp } from '@visactor/vrender-core';\n\nexport type TVRenderSharedAppKey = string | symbol;\n\nexport type TVRenderSharedAppHandle<TEnv extends string = string> = {\n readonly app: IApp;\n readonly env: TEnv;\n readonly key: TVRenderSharedAppKey;\n release: () => void;\n};\n\ntype TSharedAppRecord = {\n app: IApp;\n refCount: number;\n released: boolean;\n releaseApp: () => void;\n};\n\ntype TSharedAppRegistry<TEnv extends string = string> = Map<TEnv, Map<TVRenderSharedAppKey, TSharedAppRecord>>;\ntype TGlobalSharedAppRegistry = typeof globalThis & Record<symbol, TSharedAppRegistry | undefined>;\n\nexport const DEFAULT_SHARED_APP_KEY = 'default';\n\nconst SHARED_APP_REGISTRY_KEY = Symbol.for('visactor.vrender.sharedAppRegistry');\n\nfunction getSharedAppRegistry<TEnv extends string>(): TSharedAppRegistry<TEnv> {\n const target = globalThis as TGlobalSharedAppRegistry;\n const registry = target[SHARED_APP_REGISTRY_KEY] ?? new Map();\n target[SHARED_APP_REGISTRY_KEY] = registry;\n return registry as TSharedAppRegistry<TEnv>;\n}\n\nfunction getSharedAppEnvRegistry<TEnv extends string>(\n env: TEnv,\n create: boolean\n): Map<TVRenderSharedAppKey, TSharedAppRecord> | undefined {\n const registry = getSharedAppRegistry<TEnv>();\n const envRegistry = registry.get(env);\n\n if (envRegistry || !create) {\n return envRegistry;\n }\n\n const nextEnvRegistry = new Map<TVRenderSharedAppKey, TSharedAppRecord>();\n registry.set(env, nextEnvRegistry);\n return nextEnvRegistry;\n}\n\nfunction getOrCreateSharedAppEnvRegistry<TEnv extends string>(env: TEnv): Map<TVRenderSharedAppKey, TSharedAppRecord> {\n return getSharedAppEnvRegistry(env, true) as Map<TVRenderSharedAppKey, TSharedAppRecord>;\n}\n\nfunction removeSharedAppRecord<TEnv extends string>(env: TEnv, key: TVRenderSharedAppKey, record: TSharedAppRecord) {\n const registry = getSharedAppRegistry<TEnv>();\n const envRegistry = registry.get(env);\n\n if (envRegistry?.get(key) === record) {\n envRegistry.delete(key);\n if (!envRegistry.size) {\n registry.delete(env);\n }\n }\n}\n\nfunction releaseSharedAppRecord<TEnv extends string>(env: TEnv, key: TVRenderSharedAppKey, record: TSharedAppRecord) {\n if (record.released) {\n return;\n }\n\n record.released = true;\n record.refCount = 0;\n removeSharedAppRecord(env, key, record);\n record.releaseApp();\n}\n\nfunction createSharedAppRecord<TEnv extends string, TOptions>(\n env: TEnv,\n key: TVRenderSharedAppKey,\n options: TOptions,\n createApp: (options: TOptions) => IApp\n): TSharedAppRecord {\n const app = createApp(options);\n const originalRelease = app.release.bind(app);\n const record: TSharedAppRecord = {\n app,\n refCount: 0,\n released: false,\n releaseApp: originalRelease\n };\n\n app.release = () => releaseSharedAppRecord(env, key, record);\n return record;\n}\n\nfunction createSharedAppHandle<TEnv extends string>(\n registryEnv: string,\n handleEnv: TEnv,\n key: TVRenderSharedAppKey,\n record: TSharedAppRecord\n): TVRenderSharedAppHandle<TEnv> {\n let released = false;\n\n return {\n app: record.app,\n env: handleEnv,\n key,\n release() {\n if (released) {\n return;\n }\n released = true;\n\n const envRegistry = getSharedAppEnvRegistry(registryEnv, false);\n if (envRegistry?.get(key) !== record || record.released) {\n return;\n }\n\n record.refCount -= 1;\n if (record.refCount <= 0) {\n releaseSharedAppRecord(registryEnv, key, record);\n }\n }\n };\n}\n\nexport function acquireSharedApp<\n TRegistryEnv extends string,\n THandleEnv extends string = TRegistryEnv,\n TOptions extends { key?: TVRenderSharedAppKey } = { key?: TVRenderSharedAppKey }\n>(\n registryEnv: TRegistryEnv,\n options: TOptions,\n createApp: (options: TOptions) => IApp,\n handleEnv: THandleEnv = registryEnv as unknown as THandleEnv\n): TVRenderSharedAppHandle<THandleEnv> {\n const key = options.key ?? DEFAULT_SHARED_APP_KEY;\n const envRegistry = getOrCreateSharedAppEnvRegistry(registryEnv);\n let record = envRegistry.get(key);\n\n if (record?.app.released) {\n releaseSharedAppRecord(registryEnv, key, record);\n record = undefined;\n }\n\n if (!record) {\n record = createSharedAppRecord(registryEnv, key, options, createApp);\n envRegistry.set(key, record);\n }\n\n record.refCount += 1;\n return createSharedAppHandle(registryEnv, handleEnv, key, record);\n}\n\nexport function getSharedApp<TEnv extends string>(\n env: TEnv,\n key: TVRenderSharedAppKey = DEFAULT_SHARED_APP_KEY\n): IApp | null {\n const record = getSharedAppEnvRegistry(env, false)?.get(key);\n if (!record || record.released || record.app.released) {\n return null;\n }\n return record.app;\n}\n\nexport function releaseSharedApp<TEnv extends string>(\n env: TEnv,\n key: TVRenderSharedAppKey = DEFAULT_SHARED_APP_KEY\n): void {\n const record = getSharedAppEnvRegistry(env, false)?.get(key);\n if (record) {\n releaseSharedAppRecord(env, key, record);\n }\n}\n"]}
|
package/cjs/entries/shared.d.ts
CHANGED
|
@@ -2,8 +2,9 @@ import type { IApp } from '@visactor/vrender-core';
|
|
|
2
2
|
import { type TVRenderBrowserAppEntryOptions } from './browser';
|
|
3
3
|
import { type TVRenderMiniAppEntryOptions } from './miniapp';
|
|
4
4
|
import { type TVRenderNodeAppEntryOptions } from './node';
|
|
5
|
+
import { type TVRenderSharedAppHandle as TSharedAppHandle, type TVRenderSharedAppKey as TSharedAppKey } from './shared-registry';
|
|
5
6
|
export type TVRenderSharedAppEnv = 'browser' | 'node' | 'taro' | 'feishu' | 'tt' | 'wx' | 'lynx' | 'harmony';
|
|
6
|
-
export type TVRenderSharedAppKey =
|
|
7
|
+
export type TVRenderSharedAppKey = TSharedAppKey;
|
|
7
8
|
type TVRenderSharedAppEntryOptionsMap = {
|
|
8
9
|
browser: TVRenderBrowserAppEntryOptions;
|
|
9
10
|
node: TVRenderNodeAppEntryOptions;
|
|
@@ -18,12 +19,7 @@ export type TVRenderSharedAppOptions<TEnv extends TVRenderSharedAppEnv = TVRende
|
|
|
18
19
|
env: TEnv;
|
|
19
20
|
key?: TVRenderSharedAppKey;
|
|
20
21
|
};
|
|
21
|
-
export type TVRenderSharedAppHandle<TEnv extends TVRenderSharedAppEnv = TVRenderSharedAppEnv> =
|
|
22
|
-
readonly app: IApp;
|
|
23
|
-
readonly env: TEnv;
|
|
24
|
-
readonly key: TVRenderSharedAppKey;
|
|
25
|
-
release: () => void;
|
|
26
|
-
};
|
|
22
|
+
export type TVRenderSharedAppHandle<TEnv extends TVRenderSharedAppEnv = TVRenderSharedAppEnv> = TSharedAppHandle<TEnv>;
|
|
27
23
|
export declare function acquireSharedVRenderApp<TEnv extends TVRenderSharedAppEnv>(options: TVRenderSharedAppOptions<TEnv>): TVRenderSharedAppHandle<TEnv>;
|
|
28
24
|
export declare function getSharedVRenderApp<TEnv extends TVRenderSharedAppEnv>(env: TEnv, key?: TVRenderSharedAppKey): IApp | null;
|
|
29
25
|
export declare function releaseSharedVRenderApp<TEnv extends TVRenderSharedAppEnv>(env: TEnv, key?: TVRenderSharedAppKey): void;
|
package/cjs/entries/shared.js
CHANGED
|
@@ -4,35 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: !0
|
|
5
5
|
}), exports.releaseSharedVRenderApp = exports.getSharedVRenderApp = exports.acquireSharedVRenderApp = void 0;
|
|
6
6
|
|
|
7
|
-
const browser_1 = require("./browser"), miniapp_1 = require("./miniapp"), node_1 = require("./node"),
|
|
8
|
-
|
|
9
|
-
function getSharedAppRegistry() {
|
|
10
|
-
var _a;
|
|
11
|
-
const target = globalThis, registry = null !== (_a = target[SHARED_APP_REGISTRY_KEY]) && void 0 !== _a ? _a : new Map;
|
|
12
|
-
return target[SHARED_APP_REGISTRY_KEY] = registry, registry;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function getSharedAppEnvRegistry(env, create) {
|
|
16
|
-
const registry = getSharedAppRegistry(), envRegistry = registry.get(env);
|
|
17
|
-
if (envRegistry || !create) return envRegistry;
|
|
18
|
-
const nextEnvRegistry = new Map;
|
|
19
|
-
return registry.set(env, nextEnvRegistry), nextEnvRegistry;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function getOrCreateSharedAppEnvRegistry(env) {
|
|
23
|
-
return getSharedAppEnvRegistry(env, !0);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function removeSharedAppRecord(env, key, record) {
|
|
27
|
-
const registry = getSharedAppRegistry(), envRegistry = registry.get(env);
|
|
28
|
-
(null == envRegistry ? void 0 : envRegistry.get(key)) === record && (envRegistry.delete(key),
|
|
29
|
-
envRegistry.size || registry.delete(env));
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function releaseSharedAppRecord(env, key, record) {
|
|
33
|
-
record.released || (record.released = !0, record.refCount = 0, removeSharedAppRecord(env, key, record),
|
|
34
|
-
record.releaseApp());
|
|
35
|
-
}
|
|
7
|
+
const browser_1 = require("./browser"), miniapp_1 = require("./miniapp"), node_1 = require("./node"), shared_registry_1 = require("./shared-registry");
|
|
36
8
|
|
|
37
9
|
function createAppForSharedEnv(options) {
|
|
38
10
|
const {env: env} = options, entryOptions = Object.assign({}, options);
|
|
@@ -43,51 +15,16 @@ function createAppForSharedEnv(options) {
|
|
|
43
15
|
miniapp_1.createLynxVRenderApp)(entryOptions) : (0, miniapp_1.createHarmonyVRenderApp)(entryOptions);
|
|
44
16
|
}
|
|
45
17
|
|
|
46
|
-
function createSharedAppRecord(env, key, options) {
|
|
47
|
-
const app = createAppForSharedEnv(options), originalRelease = app.release.bind(app), record = {
|
|
48
|
-
app: app,
|
|
49
|
-
refCount: 0,
|
|
50
|
-
released: !1,
|
|
51
|
-
releaseApp: originalRelease
|
|
52
|
-
};
|
|
53
|
-
return app.release = () => releaseSharedAppRecord(env, key, record), record;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function createSharedAppHandle(env, key, record) {
|
|
57
|
-
let released = !1;
|
|
58
|
-
return {
|
|
59
|
-
app: record.app,
|
|
60
|
-
env: env,
|
|
61
|
-
key: key,
|
|
62
|
-
release() {
|
|
63
|
-
if (released) return;
|
|
64
|
-
released = !0;
|
|
65
|
-
const envRegistry = getSharedAppEnvRegistry(env, !1);
|
|
66
|
-
(null == envRegistry ? void 0 : envRegistry.get(key)) !== record || record.released || (record.refCount -= 1,
|
|
67
|
-
record.refCount <= 0 && releaseSharedAppRecord(env, key, record));
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
|
|
72
18
|
function acquireSharedVRenderApp(options) {
|
|
73
|
-
|
|
74
|
-
const key = null !== (_a = options.key) && void 0 !== _a ? _a : DEFAULT_SHARED_APP_KEY, envRegistry = getOrCreateSharedAppEnvRegistry(options.env);
|
|
75
|
-
let record = envRegistry.get(key);
|
|
76
|
-
return (null == record ? void 0 : record.app.released) && (releaseSharedAppRecord(options.env, key, record),
|
|
77
|
-
record = void 0), record || (record = createSharedAppRecord(options.env, key, options),
|
|
78
|
-
envRegistry.set(key, record)), record.refCount += 1, createSharedAppHandle(options.env, key, record);
|
|
19
|
+
return (0, shared_registry_1.acquireSharedApp)(options.env, options, createAppForSharedEnv, options.env);
|
|
79
20
|
}
|
|
80
21
|
|
|
81
|
-
function getSharedVRenderApp(env, key = DEFAULT_SHARED_APP_KEY) {
|
|
82
|
-
|
|
83
|
-
const record = null === (_a = getSharedAppEnvRegistry(env, !1)) || void 0 === _a ? void 0 : _a.get(key);
|
|
84
|
-
return !record || record.released || record.app.released ? null : record.app;
|
|
22
|
+
function getSharedVRenderApp(env, key = shared_registry_1.DEFAULT_SHARED_APP_KEY) {
|
|
23
|
+
return (0, shared_registry_1.getSharedApp)(env, key);
|
|
85
24
|
}
|
|
86
25
|
|
|
87
|
-
function releaseSharedVRenderApp(env, key = DEFAULT_SHARED_APP_KEY) {
|
|
88
|
-
|
|
89
|
-
const record = null === (_a = getSharedAppEnvRegistry(env, !1)) || void 0 === _a ? void 0 : _a.get(key);
|
|
90
|
-
record && releaseSharedAppRecord(env, key, record);
|
|
26
|
+
function releaseSharedVRenderApp(env, key = shared_registry_1.DEFAULT_SHARED_APP_KEY) {
|
|
27
|
+
(0, shared_registry_1.releaseSharedApp)(env, key);
|
|
91
28
|
}
|
|
92
29
|
|
|
93
30
|
exports.acquireSharedVRenderApp = acquireSharedVRenderApp, exports.getSharedVRenderApp = getSharedVRenderApp,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/entries/shared.ts"],"names":[],"mappings":";;;AACA,uCAAyF;AACzF,uCAQmB;AACnB,iCAAgF;AA2ChF,MAAM,uBAAuB,GAAG,MAAM,CAAC,GAAG,CAAC,oCAAoC,CAAC,CAAC;AACjF,MAAM,sBAAsB,GAAG,SAAS,CAAC;AAEzC,SAAS,oBAAoB;;IAC3B,MAAM,MAAM,GAAG,UAAsC,CAAC;IACtD,MAAM,QAAQ,GAAG,MAAA,MAAM,CAAC,uBAAuB,CAAC,mCAAI,IAAI,GAAG,EAAE,CAAC;IAC9D,MAAM,CAAC,uBAAuB,CAAC,GAAG,QAAQ,CAAC;IAC3C,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,SAAS,uBAAuB,CAC9B,GAAS,EACT,MAAe;IAEf,MAAM,QAAQ,GAAG,oBAAoB,EAAE,CAAC;IACxC,MAAM,WAAW,GAAG,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAEtC,IAAI,WAAW,IAAI,CAAC,MA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,IAAI,CAAC,CAAC;IACrB,OAAO,qBAAqB,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;AACzD,CAAC;AAnBD,0DAmBC;AAED,SAAgB,mBAAmB,CACjC,GAAS,EACT,MAA4B,sBAAsB;;IAElD,MAAM,MAAM,GAAG,MAAA,uBAAuB,CAAC,GAAG,EAAE,KAAK,CAAC,0CAAE,GAAG,CAAC,GAAG,CAAC,CAAC;IAC7D,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,QAAQ,IAAI,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE;QACrD,OAAO,IAAI,CAAC;KACb;IACD,OAAO,MAAM,CAAC,GAAG,CAAC;AACpB,CAAC;AATD,kDASC;AAED,SAAgB,uBAAuB,CACrC,GAAS,EACT,MAA4B,sBAAsB;;IAElD,MAAM,MAAM,GAAG,MAAA,uBAAuB,CAAC,GAAG,EAAE,KAAK,CAAC,0CAAE,GAAG,CAAC,GAAG,CAAC,CAAC;IAC7D,IAAI,MAAM,EAAE;QACV,sBAAsB,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;KAC1C;AACH,CAAC;AARD,0DAQC","file":"shared.js","sourcesContent":["import type { IApp } from '@visactor/vrender-core';\nimport { createBrowserVRenderApp, type TVRenderBrowserAppEntryOptions } from './browser';\nimport {\n createFeishuVRenderApp,\n createHarmonyVRenderApp,\n createLynxVRenderApp,\n createTaroVRenderApp,\n createTTVRenderApp,\n createWxVRenderApp,\n type TVRenderMiniAppEntryOptions\n} from './miniapp';\nimport { createNodeVRenderApp, type TVRenderNodeAppEntryOptions } from './node';\n\nexport type TVRenderSharedAppEnv = 'browser' | 'node' | 'taro' | 'feishu' | 'tt' | 'wx' | 'lynx' | 'harmony';\nexport type TVRenderSharedAppKey = string | symbol;\n\ntype TVRenderSharedAppEntryOptionsMap = {\n browser: TVRenderBrowserAppEntryOptions;\n node: TVRenderNodeAppEntryOptions;\n taro: TVRenderMiniAppEntryOptions<'taro'>;\n feishu: TVRenderMiniAppEntryOptions<'feishu'>;\n tt: TVRenderMiniAppEntryOptions<'tt'>;\n wx: TVRenderMiniAppEntryOptions<'wx'>;\n lynx: TVRenderMiniAppEntryOptions<'lynx'>;\n harmony: TVRenderMiniAppEntryOptions<'harmony'>;\n};\n\nexport type TVRenderSharedAppOptions<TEnv extends TVRenderSharedAppEnv = TVRenderSharedAppEnv> =\n TVRenderSharedAppEntryOptionsMap[TEnv] & {\n env: TEnv;\n /**\n * Shared identity inside the current JS runtime. Use a stable app/page/container key\n * when multiple products, such as VChart and VTable, should share one VRender app.\n */\n key?: TVRenderSharedAppKey;\n };\n\nexport type TVRenderSharedAppHandle<TEnv extends TVRenderSharedAppEnv = TVRenderSharedAppEnv> = {\n readonly app: IApp;\n readonly env: TEnv;\n readonly key: TVRenderSharedAppKey;\n release: () => void;\n};\n\ntype TSharedAppRecord = {\n app: IApp;\n refCount: number;\n released: boolean;\n releaseApp: () => void;\n};\n\ntype TSharedAppRegistry = Map<TVRenderSharedAppEnv, Map<TVRenderSharedAppKey, TSharedAppRecord>>;\ntype TGlobalSharedAppRegistry = typeof globalThis & Record<symbol, TSharedAppRegistry | undefined>;\n\nconst SHARED_APP_REGISTRY_KEY = Symbol.for('visactor.vrender.sharedAppRegistry');\nconst DEFAULT_SHARED_APP_KEY = 'default';\n\nfunction getSharedAppRegistry(): TSharedAppRegistry {\n const target = globalThis as TGlobalSharedAppRegistry;\n const registry = target[SHARED_APP_REGISTRY_KEY] ?? new Map();\n target[SHARED_APP_REGISTRY_KEY] = registry;\n return registry;\n}\n\nfunction getSharedAppEnvRegistry<TEnv extends TVRenderSharedAppEnv>(\n env: TEnv,\n create: boolean\n): Map<TVRenderSharedAppKey, TSharedAppRecord> | undefined {\n const registry = getSharedAppRegistry();\n const envRegistry = registry.get(env);\n\n if (envRegistry || !create) {\n return envRegistry;\n }\n\n const nextEnvRegistry = new Map<TVRenderSharedAppKey, TSharedAppRecord>();\n registry.set(env, nextEnvRegistry);\n return nextEnvRegistry;\n}\n\nfunction getOrCreateSharedAppEnvRegistry<TEnv extends TVRenderSharedAppEnv>(\n env: TEnv\n): Map<TVRenderSharedAppKey, TSharedAppRecord> {\n return getSharedAppEnvRegistry(env, true) as Map<TVRenderSharedAppKey, TSharedAppRecord>;\n}\n\nfunction removeSharedAppRecord<TEnv extends TVRenderSharedAppEnv>(\n env: TEnv,\n key: TVRenderSharedAppKey,\n record: TSharedAppRecord\n) {\n const registry = getSharedAppRegistry();\n const envRegistry = registry.get(env);\n\n if (envRegistry?.get(key) === record) {\n envRegistry.delete(key);\n if (!envRegistry.size) {\n registry.delete(env);\n }\n }\n}\n\nfunction releaseSharedAppRecord<TEnv extends TVRenderSharedAppEnv>(\n env: TEnv,\n key: TVRenderSharedAppKey,\n record: TSharedAppRecord\n) {\n if (record.released) {\n return;\n }\n\n record.released = true;\n record.refCount = 0;\n removeSharedAppRecord(env, key, record);\n record.releaseApp();\n}\n\nfunction createAppForSharedEnv<TEnv extends TVRenderSharedAppEnv>(options: TVRenderSharedAppOptions<TEnv>): IApp {\n const { env } = options;\n const entryOptions = { ...options } as Record<string, unknown>;\n delete entryOptions.env;\n delete entryOptions.key;\n\n if (env === 'browser') {\n return createBrowserVRenderApp(entryOptions as TVRenderBrowserAppEntryOptions);\n }\n if (env === 'node') {\n return createNodeVRenderApp(entryOptions as TVRenderNodeAppEntryOptions);\n }\n if (env === 'taro') {\n return createTaroVRenderApp(entryOptions as TVRenderMiniAppEntryOptions<'taro'>);\n }\n if (env === 'feishu') {\n return createFeishuVRenderApp(entryOptions as TVRenderMiniAppEntryOptions<'feishu'>);\n }\n if (env === 'tt') {\n return createTTVRenderApp(entryOptions as TVRenderMiniAppEntryOptions<'tt'>);\n }\n if (env === 'wx') {\n return createWxVRenderApp(entryOptions as TVRenderMiniAppEntryOptions<'wx'>);\n }\n if (env === 'lynx') {\n return createLynxVRenderApp(entryOptions as TVRenderMiniAppEntryOptions<'lynx'>);\n }\n return createHarmonyVRenderApp(entryOptions as TVRenderMiniAppEntryOptions<'harmony'>);\n}\n\nfunction createSharedAppRecord<TEnv extends TVRenderSharedAppEnv>(\n env: TEnv,\n key: TVRenderSharedAppKey,\n options: TVRenderSharedAppOptions<TEnv>\n): TSharedAppRecord {\n const app = createAppForSharedEnv(options);\n const originalRelease = app.release.bind(app);\n const record: TSharedAppRecord = {\n app,\n refCount: 0,\n released: false,\n releaseApp: originalRelease\n };\n\n app.release = () => releaseSharedAppRecord(env, key, record);\n return record;\n}\n\nfunction createSharedAppHandle<TEnv extends TVRenderSharedAppEnv>(\n env: TEnv,\n key: TVRenderSharedAppKey,\n record: TSharedAppRecord\n): TVRenderSharedAppHandle<TEnv> {\n let released = false;\n\n return {\n app: record.app,\n env,\n key,\n release() {\n if (released) {\n return;\n }\n released = true;\n\n const envRegistry = getSharedAppEnvRegistry(env, false);\n if (envRegistry?.get(key) !== record || record.released) {\n return;\n }\n\n record.refCount -= 1;\n if (record.refCount <= 0) {\n releaseSharedAppRecord(env, key, record);\n }\n }\n };\n}\n\nexport function acquireSharedVRenderApp<TEnv extends TVRenderSharedAppEnv>(\n options: TVRenderSharedAppOptions<TEnv>\n): TVRenderSharedAppHandle<TEnv> {\n const key = options.key ?? DEFAULT_SHARED_APP_KEY;\n const envRegistry = getOrCreateSharedAppEnvRegistry(options.env);\n let record = envRegistry.get(key);\n\n if (record?.app.released) {\n releaseSharedAppRecord(options.env, key, record);\n record = undefined;\n }\n\n if (!record) {\n record = createSharedAppRecord(options.env, key, options);\n envRegistry.set(key, record);\n }\n\n record.refCount += 1;\n return createSharedAppHandle(options.env, key, record);\n}\n\nexport function getSharedVRenderApp<TEnv extends TVRenderSharedAppEnv>(\n env: TEnv,\n key: TVRenderSharedAppKey = DEFAULT_SHARED_APP_KEY\n): IApp | null {\n const record = getSharedAppEnvRegistry(env, false)?.get(key);\n if (!record || record.released || record.app.released) {\n return null;\n }\n return record.app;\n}\n\nexport function releaseSharedVRenderApp<TEnv extends TVRenderSharedAppEnv>(\n env: TEnv,\n key: TVRenderSharedAppKey = DEFAULT_SHARED_APP_KEY\n): void {\n const record = getSharedAppEnvRegistry(env, false)?.get(key);\n if (record) {\n releaseSharedAppRecord(env, key, record);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/entries/shared.ts"],"names":[],"mappings":";;;AACA,uCAAyF;AACzF,uCAQmB;AACnB,iCAAgF;AAChF,uDAO2B;AA4B3B,SAAS,qBAAqB,CAAoC,OAAuC;IACvG,MAAM,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC;IACxB,MAAM,YAAY,GAAG,kBAAK,OAAO,CAA6B,CAAC;IAC/D,OAAO,YAAY,CAAC,GAAG,CAAC;IACxB,OAAO,YAAY,CAAC,GAAG,CAAC;IAExB,IAAI,GAAG,KAAK,SAAS,EAAE;QACrB,OAAO,IAAA,iCAAuB,EAAC,YAA8C,CAAC,CAAC;KAChF;IACD,IAAI,GAAG,KAAK,MAAM,EAAE;QAClB,OAAO,IAAA,2BAAoB,EAAC,YAA2C,CAAC,CAAC;KAC1E;IACD,IAAI,GAAG,KAAK,MAAM,EAAE;QAClB,OAAO,IAAA,8BAAoB,EAAC,YAAmD,CAAC,CAAC;KAClF;IACD,IAAI,GAAG,KAAK,QAAQ,EAAE;QACpB,OAAO,IAAA,gCAAsB,EAAC,YAAqD,CAAC,CAAC;KACtF;IACD,IAAI,GAAG,KAAK,IAAI,EAAE;QAChB,OAAO,IAAA,4BAAkB,EAAC,YAAiD,CAAC,CAAC;KAC9E;IACD,IAAI,GAAG,KAAK,IAAI,EAAE;QAChB,OAAO,IAAA,4BAAkB,EAAC,YAAiD,CAAC,CAAC;KAC9E;IACD,IAAI,GAAG,KAAK,MAAM,EAAE;QAClB,OAAO,IAAA,8BAAoB,EAAC,YAAmD,CAAC,CAAC;KAClF;IACD,OAAO,IAAA,iCAAuB,EAAC,YAAsD,CAAC,CAAC;AACzF,CAAC;AAED,SAAgB,uBAAuB,CACrC,OAAuC;IAEvC,OAAO,IAAA,kCAAgB,EAAC,OAAO,CAAC,GAAG,EAAE,OAAO,EAAE,qBAAqB,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;AACpF,CAAC;AAJD,0DAIC;AAED,SAAgB,mBAAmB,CACjC,GAAS,EACT,MAA4B,wCAAsB;IAElD,OAAO,IAAA,8BAAY,EAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AAChC,CAAC;AALD,kDAKC;AAED,SAAgB,uBAAuB,CACrC,GAAS,EACT,MAA4B,wCAAsB;IAElD,IAAA,kCAAgB,EAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AAC7B,CAAC;AALD,0DAKC","file":"shared.js","sourcesContent":["import type { IApp } from '@visactor/vrender-core';\nimport { createBrowserVRenderApp, type TVRenderBrowserAppEntryOptions } from './browser';\nimport {\n createFeishuVRenderApp,\n createHarmonyVRenderApp,\n createLynxVRenderApp,\n createTaroVRenderApp,\n createTTVRenderApp,\n createWxVRenderApp,\n type TVRenderMiniAppEntryOptions\n} from './miniapp';\nimport { createNodeVRenderApp, type TVRenderNodeAppEntryOptions } from './node';\nimport {\n acquireSharedApp,\n DEFAULT_SHARED_APP_KEY,\n getSharedApp,\n releaseSharedApp,\n type TVRenderSharedAppHandle as TSharedAppHandle,\n type TVRenderSharedAppKey as TSharedAppKey\n} from './shared-registry';\n\nexport type TVRenderSharedAppEnv = 'browser' | 'node' | 'taro' | 'feishu' | 'tt' | 'wx' | 'lynx' | 'harmony';\nexport type TVRenderSharedAppKey = TSharedAppKey;\n\ntype TVRenderSharedAppEntryOptionsMap = {\n browser: TVRenderBrowserAppEntryOptions;\n node: TVRenderNodeAppEntryOptions;\n taro: TVRenderMiniAppEntryOptions<'taro'>;\n feishu: TVRenderMiniAppEntryOptions<'feishu'>;\n tt: TVRenderMiniAppEntryOptions<'tt'>;\n wx: TVRenderMiniAppEntryOptions<'wx'>;\n lynx: TVRenderMiniAppEntryOptions<'lynx'>;\n harmony: TVRenderMiniAppEntryOptions<'harmony'>;\n};\n\nexport type TVRenderSharedAppOptions<TEnv extends TVRenderSharedAppEnv = TVRenderSharedAppEnv> =\n TVRenderSharedAppEntryOptionsMap[TEnv] & {\n env: TEnv;\n /**\n * Shared identity inside the current JS runtime. Use a stable app/page/container key\n * when multiple products, such as VChart and VTable, should share one VRender app.\n */\n key?: TVRenderSharedAppKey;\n };\n\nexport type TVRenderSharedAppHandle<TEnv extends TVRenderSharedAppEnv = TVRenderSharedAppEnv> = TSharedAppHandle<TEnv>;\n\nfunction createAppForSharedEnv<TEnv extends TVRenderSharedAppEnv>(options: TVRenderSharedAppOptions<TEnv>): IApp {\n const { env } = options;\n const entryOptions = { ...options } as Record<string, unknown>;\n delete entryOptions.env;\n delete entryOptions.key;\n\n if (env === 'browser') {\n return createBrowserVRenderApp(entryOptions as TVRenderBrowserAppEntryOptions);\n }\n if (env === 'node') {\n return createNodeVRenderApp(entryOptions as TVRenderNodeAppEntryOptions);\n }\n if (env === 'taro') {\n return createTaroVRenderApp(entryOptions as TVRenderMiniAppEntryOptions<'taro'>);\n }\n if (env === 'feishu') {\n return createFeishuVRenderApp(entryOptions as TVRenderMiniAppEntryOptions<'feishu'>);\n }\n if (env === 'tt') {\n return createTTVRenderApp(entryOptions as TVRenderMiniAppEntryOptions<'tt'>);\n }\n if (env === 'wx') {\n return createWxVRenderApp(entryOptions as TVRenderMiniAppEntryOptions<'wx'>);\n }\n if (env === 'lynx') {\n return createLynxVRenderApp(entryOptions as TVRenderMiniAppEntryOptions<'lynx'>);\n }\n return createHarmonyVRenderApp(entryOptions as TVRenderMiniAppEntryOptions<'harmony'>);\n}\n\nexport function acquireSharedVRenderApp<TEnv extends TVRenderSharedAppEnv>(\n options: TVRenderSharedAppOptions<TEnv>\n): TVRenderSharedAppHandle<TEnv> {\n return acquireSharedApp(options.env, options, createAppForSharedEnv, options.env);\n}\n\nexport function getSharedVRenderApp<TEnv extends TVRenderSharedAppEnv>(\n env: TEnv,\n key: TVRenderSharedAppKey = DEFAULT_SHARED_APP_KEY\n): IApp | null {\n return getSharedApp(env, key);\n}\n\nexport function releaseSharedVRenderApp<TEnv extends TVRenderSharedAppEnv>(\n env: TEnv,\n key: TVRenderSharedAppKey = DEFAULT_SHARED_APP_KEY\n): void {\n releaseSharedApp(env, key);\n}\n"]}
|
package/cjs/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Direction } from '@visactor/vrender-core';
|
|
2
|
-
export declare const version = "1.1.0-alpha.
|
|
2
|
+
export declare const version = "1.1.0-alpha.26";
|
|
3
3
|
export * from '@visactor/vrender-core';
|
|
4
4
|
export * from '@visactor/vrender-kits';
|
|
5
5
|
export * from '@visactor/vrender-animate';
|
package/cjs/index.js
CHANGED
|
@@ -26,7 +26,7 @@ Object.defineProperty(exports, "Direction", {
|
|
|
26
26
|
get: function() {
|
|
27
27
|
return vrender_core_1.Direction;
|
|
28
28
|
}
|
|
29
|
-
}), exports.version = "1.1.0-alpha.
|
|
29
|
+
}), exports.version = "1.1.0-alpha.26", __exportStar(require("@visactor/vrender-core"), exports),
|
|
30
30
|
__exportStar(require("@visactor/vrender-kits"), exports), __exportStar(require("@visactor/vrender-animate"), exports),
|
|
31
31
|
__exportStar(require("@visactor/vrender-components"), exports), __exportStar(require("./entries"), exports);
|
|
32
32
|
|
package/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,yDAAmD;AAa1C,0FAbA,wBAAS,OAaA;AAXL,QAAA,OAAO,GAAG,gBAAgB,CAAC;AAExC,yDAAuC;AACvC,yDAAuC;AACvC,4DAA0C;AAC1C,+DAA6C;AAC7C,4CAA0B;AAC1B,mCAAuC;AAA9B,qGAAA,WAAW,OAAA;AAGpB,6DAAkD;AAAzC,wGAAA,KAAK,OAAA","file":"index.js","sourcesContent":["import { Direction } from '@visactor/vrender-core';\n// 导出版本号\nexport const version = \"1.1.0-alpha.
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,yDAAmD;AAa1C,0FAbA,wBAAS,OAaA;AAXL,QAAA,OAAO,GAAG,gBAAgB,CAAC;AAExC,yDAAuC;AACvC,yDAAuC;AACvC,4DAA0C;AAC1C,+DAA6C;AAC7C,4CAA0B;AAC1B,mCAAuC;AAA9B,qGAAA,WAAW,OAAA;AAGpB,6DAAkD;AAAzC,wGAAA,KAAK,OAAA","file":"index.js","sourcesContent":["import { Direction } from '@visactor/vrender-core';\n// 导出版本号\nexport const version = \"1.1.0-alpha.26\";\n\nexport * from '@visactor/vrender-core';\nexport * from '@visactor/vrender-kits';\nexport * from '@visactor/vrender-animate';\nexport * from '@visactor/vrender-components';\nexport * from './entries';\nexport { createStage } from './legacy';\n\n// avoid naming conflicts with 'State' & 'Direction' in '@visactor/vrender-components'\nexport { State } from '@visactor/vrender-animate';\nexport { Direction };\n"]}
|