@lynx-js/lynx-runtime 0.0.0 → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +354 -2
  3. package/dist/bts/data.d.ts +1 -0
  4. package/dist/bts/data.js +28 -0
  5. package/dist/bts/events.d.ts +1 -0
  6. package/dist/bts/events.js +57 -0
  7. package/dist/bts/scope.d.ts +1 -0
  8. package/dist/bts/scope.js +129 -0
  9. package/dist/bts/services.d.ts +1 -0
  10. package/dist/bts/services.js +34 -0
  11. package/dist/bts.d.ts +14 -0
  12. package/dist/bts.js +30 -0
  13. package/dist/common/host-types.d.ts +1 -0
  14. package/dist/common/host-types.js +1 -0
  15. package/dist/common/messages.d.ts +1 -0
  16. package/dist/common/messages.js +69 -0
  17. package/dist/common/performance.d.ts +1 -0
  18. package/dist/common/performance.js +26 -0
  19. package/dist/common/protocol.d.ts +20 -0
  20. package/dist/common/protocol.js +53 -0
  21. package/dist/common/types.d.ts +203 -0
  22. package/dist/common/types.js +1 -0
  23. package/dist/iife/bts.js +1 -0
  24. package/dist/iife/mts.js +1 -0
  25. package/dist/index.d.ts +16 -0
  26. package/dist/index.js +1 -0
  27. package/dist/mts/data.d.ts +71 -0
  28. package/dist/mts/data.js +46 -0
  29. package/dist/mts/flush.d.ts +11 -0
  30. package/dist/mts/flush.js +16 -0
  31. package/dist/mts/host.d.ts +35 -0
  32. package/dist/mts/host.js +124 -0
  33. package/dist/mts/services.d.ts +21 -0
  34. package/dist/mts/services.js +46 -0
  35. package/dist/mts.d.ts +5 -0
  36. package/dist/mts.js +4 -0
  37. package/package.json +54 -7
  38. package/skills/lynx-runtime/SKILL.md +67 -0
  39. package/src/bts/data.ts +94 -0
  40. package/src/bts/events.ts +100 -0
  41. package/src/bts/scope.ts +279 -0
  42. package/src/bts/services.ts +88 -0
  43. package/src/bts.ts +110 -0
  44. package/src/common/host-types.ts +161 -0
  45. package/src/common/messages.ts +129 -0
  46. package/src/common/performance.ts +65 -0
  47. package/src/common/protocol.ts +98 -0
  48. package/src/common/types.ts +259 -0
  49. package/src/index.ts +35 -0
  50. package/src/mts/data.ts +200 -0
  51. package/src/mts/flush.ts +50 -0
  52. package/src/mts/host.ts +297 -0
  53. package/src/mts/services.ts +102 -0
  54. package/src/mts.ts +36 -0
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,129 @@
1
+ import { clearMultiplexed } from "../common/messages.js";
2
+ import { copyHostData, invokeAll, subscribeListener } from "../common/protocol.js";
3
+ const btsScopeMap = new WeakMap();
4
+ function assertScopeAlive(scope) {
5
+ if (scope.destroyed) throw new Error('[@lynx-js/lynx-runtime/bts] Cannot register or activate a capability on a destroying or destroyed page. Check page.isDestroyed() before registering in async callbacks.');
6
+ }
7
+ function resolveHostLynx(app, host) {
8
+ const hostLynx = host.lynx;
9
+ if (hostLynx && (hostLynx.getApp?.() === app || !hostLynx.getApp && !host.multiApps && host.tt === app)) return hostLynx;
10
+ }
11
+ function getScopeLynx(scope) {
12
+ return scope.app.lynx ?? scope.lynx ?? resolveHostLynx(scope.app, globalThis);
13
+ }
14
+ function mergeBTSInitData(rawInitData, dynamicData) {
15
+ return {
16
+ ...rawInitData,
17
+ ...dynamicData ? copyHostData(dynamicData) : void 0
18
+ };
19
+ }
20
+ function ensureBTSSlot(scope, key, before) {
21
+ let listeners = scope.slots.get(key);
22
+ if (listeners) return listeners;
23
+ const appRecord = scope.app;
24
+ const prev = appRecord[key];
25
+ listeners = new Map();
26
+ const currentListeners = listeners;
27
+ appRecord[key] = function(...args) {
28
+ if (!scope.destroyed) before?.(...args);
29
+ prev?.apply(this, args);
30
+ if (scope.destroyed) return;
31
+ for (const [identity, reg] of [
32
+ ...currentListeners
33
+ ])if (currentListeners.get(identity) === reg) reg.invoke(...args);
34
+ };
35
+ scope.slots.set(key, listeners);
36
+ return listeners;
37
+ }
38
+ function subscribeBTSSlot(scope, key, invoke, identity = invoke) {
39
+ assertScopeAlive(scope);
40
+ const listeners = ensureBTSSlot(scope, key);
41
+ const existing = listeners.get(identity);
42
+ if (existing) return existing.dispose;
43
+ const dispose = ()=>{
44
+ if (listeners.get(identity)?.dispose === dispose) listeners.delete(identity);
45
+ };
46
+ listeners.set(identity, {
47
+ invoke: invoke,
48
+ dispose
49
+ });
50
+ return dispose;
51
+ }
52
+ function scopeOnDestroy(scope, listener) {
53
+ assertScopeAlive(scope);
54
+ return subscribeListener(scope.destroyListeners, listener);
55
+ }
56
+ function createBTSPageScope(targetApp, host, lexicalLynx) {
57
+ const existing = btsScopeMap.get(targetApp);
58
+ if (existing) return existing;
59
+ let boundLynx = targetApp.lynx;
60
+ if (!boundLynx && lexicalLynx && (!lexicalLynx.getApp || lexicalLynx.getApp() === targetApp)) boundLynx = lexicalLynx;
61
+ boundLynx ??= resolveHostLynx(targetApp, host);
62
+ const params = targetApp._params;
63
+ const rawInitData = params?.initData ? copyHostData(params.initData) : void 0;
64
+ const initData = mergeBTSInitData(rawInitData, params?.updateData);
65
+ const scope = {
66
+ appId: params?.appGUID ?? targetApp.nativeAppId ?? '',
67
+ app: targetApp,
68
+ lynx: boundLynx,
69
+ rawInitData,
70
+ initData,
71
+ globalProps: boundLynx?.__globalProps ?? {},
72
+ destroyed: false,
73
+ slots: new Map(),
74
+ destroyListeners: new Map()
75
+ };
76
+ ensureBTSSlot(scope, 'onAppReload', (newData)=>{
77
+ scope.initData = mergeBTSInitData(scope.rawInitData, newData);
78
+ });
79
+ ensureBTSSlot(scope, 'updateGlobalProps', (newData)=>{
80
+ scope.globalProps = newData ?? {};
81
+ });
82
+ const prevDestroy = targetApp.callDestroyLifetimeFun;
83
+ targetApp.callDestroyLifetimeFun = function() {
84
+ if (scope.destroyed) return void prevDestroy?.call(this);
85
+ scope.destroyed = true;
86
+ if (scope.globalEvents) {
87
+ clearMultiplexed(scope.globalEvents);
88
+ scope.globalEvents = void 0;
89
+ }
90
+ if (scope.messages) {
91
+ clearMultiplexed(scope.messages);
92
+ scope.messages = void 0;
93
+ }
94
+ if (scope.eventEntry) {
95
+ scope.eventEntry.current = void 0;
96
+ scope.eventEntry = void 0;
97
+ }
98
+ try {
99
+ invokeAll([
100
+ ...prevDestroy ? [
101
+ ()=>prevDestroy.call(this)
102
+ ] : [],
103
+ ...[
104
+ ...scope.destroyListeners
105
+ ].map(([listener, reg])=>()=>{
106
+ if (scope.destroyListeners.get(listener) === reg) listener();
107
+ })
108
+ ]);
109
+ } finally{
110
+ scope.destroyListeners.clear();
111
+ for (const listeners of scope.slots.values())listeners.clear();
112
+ scope.slots.clear();
113
+ }
114
+ };
115
+ btsScopeMap.set(targetApp, scope);
116
+ return scope;
117
+ }
118
+ function resolveOptionalHostApp(host, lexicalLynx) {
119
+ const currentMultiApp = host.currentAppId && host.multiApps ? host.multiApps[host.currentAppId] : void 0;
120
+ return lexicalLynx?.getApp?.() ?? host.lynx?.getApp?.() ?? currentMultiApp ?? host.tt;
121
+ }
122
+ function resolveCurrentHostScope() {
123
+ const host = globalThis;
124
+ const lexicalLynx = "u" < typeof lynx ? void 0 : lynx;
125
+ const resolved = resolveOptionalHostApp(host, lexicalLynx);
126
+ if (!resolved) throw new Error('[@lynx-js/lynx-runtime/bts] Unable to resolve BTS App instance (`tt`). Call bindPage() synchronously during BTS page bootstrap and retain the returned handle.');
127
+ return createBTSPageScope(resolved, host, lexicalLynx);
128
+ }
129
+ export { assertScopeAlive, ensureBTSSlot, getScopeLynx, resolveCurrentHostScope, resolveHostLynx, scopeOnDestroy, subscribeBTSSlot };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,34 @@
1
+ import { assertScopeAlive, getScopeLynx } from "./scope.js";
2
+ import { subscribeMessage } from "../common/messages.js";
3
+ import { createHostPipeline, markHostTiming } from "../common/performance.js";
4
+ function scopeGetSystemInfo(scope) {
5
+ const host = globalThis;
6
+ return getScopeLynx(scope)?.SystemInfo ?? host.SystemInfo ?? host.lynx?.SystemInfo ?? {};
7
+ }
8
+ function scopeCreatePipeline(scope, options) {
9
+ if (scope.destroyed) return;
10
+ return createHostPipeline(getScopeLynx(scope)?.performance, options, 'bts', scopeGetSystemInfo(scope).lynxSdkVersion);
11
+ }
12
+ function scopeMarkTiming(scope, pipeline, timingKey) {
13
+ if (scope.destroyed) return;
14
+ markHostTiming(getScopeLynx(scope)?.performance, pipeline, timingKey);
15
+ }
16
+ function getCoreContext(scope) {
17
+ const proxy = getScopeLynx(scope)?.getCoreContext?.();
18
+ if (!proxy) throw new Error('[@lynx-js/lynx-runtime/bts] Message communication requires lynx.getCoreContext(). Ensure the BTS host context is initialized before calling sendMessage() or onMessage().');
19
+ return proxy;
20
+ }
21
+ function scopeSendMessage(scope, type, data) {
22
+ assertScopeAlive(scope);
23
+ getCoreContext(scope).dispatchEvent({
24
+ type,
25
+ data
26
+ });
27
+ }
28
+ function scopeOnMessage(scope, type, listener) {
29
+ assertScopeAlive(scope);
30
+ const proxy = getCoreContext(scope);
31
+ scope.messages ??= new Map();
32
+ return subscribeMessage(scope.messages, proxy, type, listener);
33
+ }
34
+ export { scopeCreatePipeline, scopeGetSystemInfo, scopeMarkTiming, scopeOnMessage, scopeSendMessage };
package/dist/bts.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ import type { BTSEventHandler, BTSPageRuntime, BTSReloadOptions, BTSUpdateOptions, CreatePipelineOptions, CreatedPipelineOptions, LynxSystemInfo, PipelineOptions, Unsubscribe } from './common/types.js';
2
+ export type { BTSEventHandler, BTSPageRuntime, BTSReloadOptions, BTSUpdateOptions, CreatedPipelineOptions, CreatePipelineOptions, LynxSystemInfo, PipelineOptions, Unsubscribe, };
3
+ /**
4
+ * Bind the BTS runtime to the page currently bootstrapping in the host environment
5
+ * and return a page-scoped runtime handle isolated from subsequent `LynxGroup` page loads.
6
+ * Call `bindPage()` synchronously during page bootstrap and retain the returned
7
+ * `BTSPageRuntime` handle for all subsequent asynchronous work on that page.
8
+ * Repeated binding to the same App returns the same handle, including its destruction
9
+ * state. Binding captures the initial baseline and `GlobalProps`, and tracks
10
+ * reload, `GlobalProps` updates, and destruction; other channels attach lazily on use.
11
+ * Binding alone does not claim the raw event handler.
12
+ * Throws when the host provides no BTS App; it does not create a page.
13
+ */
14
+ export declare function bindPage(): BTSPageRuntime;
package/dist/bts.js ADDED
@@ -0,0 +1,30 @@
1
+ import { scopeOnConfigChanged, scopeOnGlobalPropsChanged, scopeOnReload, scopeOnUpdateData } from "./bts/data.js";
2
+ import { scopeOnGlobalEvent, scopeSetEventHandler } from "./bts/events.js";
3
+ import { resolveCurrentHostScope, scopeOnDestroy, subscribeBTSSlot } from "./bts/scope.js";
4
+ import { scopeCreatePipeline, scopeGetSystemInfo, scopeMarkTiming, scopeOnMessage, scopeSendMessage } from "./bts/services.js";
5
+ import { copyHostData } from "./common/protocol.js";
6
+ function bindPage() {
7
+ const scope = resolveCurrentHostScope();
8
+ scope.runtime ??= {
9
+ isDestroyed: ()=>scope.destroyed,
10
+ getSystemInfo: ()=>scopeGetSystemInfo(scope),
11
+ createPipeline: (options)=>scopeCreatePipeline(scope, options),
12
+ markTiming: (pipeline, timingKey)=>scopeMarkTiming(scope, pipeline, timingKey),
13
+ getId: ()=>scope.appId,
14
+ getInitData: ()=>copyHostData(scope.initData),
15
+ getGlobalProps: ()=>scope.globalProps,
16
+ onGlobalPropsChanged: (listener)=>scopeOnGlobalPropsChanged(scope, listener),
17
+ onUpdateData: (listener)=>scopeOnUpdateData(scope, listener),
18
+ onReload: (listener)=>scopeOnReload(scope, listener),
19
+ onConfigChanged: (listener)=>scopeOnConfigChanged(scope, listener),
20
+ onEnterForeground: (listener)=>subscribeBTSSlot(scope, 'onAppEnterForeground', listener),
21
+ onEnterBackground: (listener)=>subscribeBTSSlot(scope, 'onAppEnterBackground', listener),
22
+ onGlobalEvent: (name, listener)=>scopeOnGlobalEvent(scope, name, listener),
23
+ setEventHandler: (handler)=>scopeSetEventHandler(scope, handler),
24
+ sendMessage: (type, data)=>scopeSendMessage(scope, type, data),
25
+ onMessage: (type, listener)=>scopeOnMessage(scope, type, listener),
26
+ onDestroy: (listener)=>scopeOnDestroy(scope, listener)
27
+ };
28
+ return scope.runtime;
29
+ }
30
+ export { bindPage };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,69 @@
1
+ import { dispatchListeners } from "./protocol.js";
2
+ function subscribeMultiplexed(subscriptions, key, callback, attachHost) {
3
+ let entry = subscriptions.get(key);
4
+ if (!entry) {
5
+ const listeners = new Map();
6
+ let dispatching = 0;
7
+ let detachScheduled = false;
8
+ const unsubscribeHost = attachHost((invoke)=>{
9
+ dispatching++;
10
+ try {
11
+ dispatchListeners(listeners, invoke);
12
+ } finally{
13
+ dispatching--;
14
+ }
15
+ });
16
+ const detachIfEmpty = ()=>{
17
+ if (0 === listeners.size && subscriptions.get(key) === created) {
18
+ subscriptions.delete(key);
19
+ unsubscribeHost();
20
+ }
21
+ };
22
+ const created = {
23
+ listeners,
24
+ unsubscribeHost,
25
+ releaseIfEmpty: ()=>{
26
+ if (0 === dispatching) return void detachIfEmpty();
27
+ if (detachScheduled) return;
28
+ detachScheduled = true;
29
+ Promise.resolve().then(()=>{
30
+ detachScheduled = false;
31
+ detachIfEmpty();
32
+ });
33
+ }
34
+ };
35
+ entry = created;
36
+ subscriptions.set(key, created);
37
+ }
38
+ const current = entry;
39
+ const existing = current.listeners.get(callback);
40
+ if (existing) return existing;
41
+ const dispose = ()=>{
42
+ if (current.listeners.get(callback) !== dispose) return;
43
+ current.listeners.delete(callback);
44
+ if (0 === current.listeners.size) current.releaseIfEmpty();
45
+ };
46
+ current.listeners.set(callback, dispose);
47
+ return dispose;
48
+ }
49
+ function clearMultiplexed(subscriptions) {
50
+ for (const entry of subscriptions.values()){
51
+ entry.listeners.clear();
52
+ entry.unsubscribeHost();
53
+ }
54
+ subscriptions.clear();
55
+ }
56
+ function subscribeMessage(subscriptions, proxy, type, listener) {
57
+ return subscribeMultiplexed(subscriptions, type, listener, (dispatch)=>{
58
+ const onEvent = (event)=>{
59
+ dispatch((fn)=>{
60
+ fn(event.data);
61
+ });
62
+ };
63
+ proxy.addEventListener(type, onEvent);
64
+ return ()=>{
65
+ proxy.removeEventListener(type, onEvent);
66
+ };
67
+ });
68
+ }
69
+ export { clearMultiplexed, subscribeMessage, subscribeMultiplexed };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,26 @@
1
+ function createHostPipeline(perf, options, side, sdkVersion) {
2
+ const pipeline = perf?._generatePipelineOptions?.();
3
+ const id = pipeline?.pipelineID;
4
+ if (!pipeline || !id) return;
5
+ if (options?.needTimestamps !== void 0) pipeline.needTimestamps = options.needTimestamps;
6
+ if (options?.pipelineOrigin !== void 0) pipeline.pipelineOrigin = options.pipelineOrigin;
7
+ if (options?.dsl !== void 0) pipeline.dsl = options.dsl;
8
+ if (options?.stage !== void 0) pipeline.stage = options.stage;
9
+ if ('mts' === side) if (pipeline.pipelineOrigin) perf?._onPipelineStart?.(id, pipeline.pipelineOrigin);
10
+ else perf?._onPipelineStart?.(id);
11
+ else {
12
+ const [major = 0, minor = 0] = (sdkVersion ?? '1.0').split('.').map(Number);
13
+ if (major > 3 || 3 === major && minor > 0) perf?._onPipelineStart?.(id, pipeline);
14
+ else perf?._onPipelineStart?.(id);
15
+ }
16
+ const flag = options?.timingFlag;
17
+ if (flag) if ('mts' === side) perf?._bindPipelineIDWithTimingFlag?.(id, flag);
18
+ else perf?._bindPipelineIdWithTimingFlag?.(id, flag);
19
+ return pipeline;
20
+ }
21
+ function markHostTiming(perf, pipeline, timingKey) {
22
+ const id = 'string' == typeof pipeline ? pipeline : pipeline?.pipelineID;
23
+ if (!id || !timingKey) return;
24
+ perf?._markTiming?.(id, timingKey);
25
+ }
26
+ export { createHostPipeline, markHostTiming };
@@ -0,0 +1,20 @@
1
+ import type { Unsubscribe } from './types.js';
2
+ /**
3
+ * Native Engine / Native ContextProxy event names (Lynx SDK 3.4+).
4
+ */
5
+ export declare const NATIVE_EVENT_RENDER_PAGE = "__RenderPage";
6
+ export declare const NATIVE_EVENT_UPDATE_PAGE = "__UpdatePage";
7
+ export declare const NATIVE_EVENT_UPDATE_GLOBAL_PROPS = "__UpdateGlobalProps";
8
+ export declare const NATIVE_EVENT_DESTROY_LIFETIME = "__DestroyLifetime";
9
+ export declare function isPlainRecord(value: unknown): value is Record<string, unknown>;
10
+ /**
11
+ * Run teardown/cleanup callbacks so an earlier failure never skips remaining
12
+ * destruction hooks or host listener cleanup, then rethrow the first error.
13
+ */
14
+ export declare function invokeAll(callbacks: Iterable<() => void>): void;
15
+ /** Each effective subscription has an identity that outlives its callback key. */
16
+ export declare function subscribeListener<T>(listeners: Map<T, Unsubscribe>, listener: T): Unsubscribe;
17
+ /** Additions wait until the next dispatch; cancellations take effect immediately. */
18
+ export declare function dispatchListeners<T>(listeners: Map<T, Unsubscribe>, invoke: (listener: T) => void): void;
19
+ /** Copy plain records and arrays at an ownership boundary; retain opaque values by reference. */
20
+ export declare function copyHostData<T>(value: T): T;
@@ -0,0 +1,53 @@
1
+ const NATIVE_EVENT_RENDER_PAGE = '__RenderPage';
2
+ const NATIVE_EVENT_UPDATE_PAGE = '__UpdatePage';
3
+ const NATIVE_EVENT_UPDATE_GLOBAL_PROPS = '__UpdateGlobalProps';
4
+ const NATIVE_EVENT_DESTROY_LIFETIME = '__DestroyLifetime';
5
+ function isPlainRecord(value) {
6
+ if (!value || 'object' != typeof value || Array.isArray(value)) return false;
7
+ const prototype = Object.getPrototypeOf(value);
8
+ return null === prototype || prototype === Object.prototype;
9
+ }
10
+ function invokeAll(callbacks) {
11
+ let firstError;
12
+ let hasError = false;
13
+ for (const fn of callbacks)try {
14
+ fn();
15
+ } catch (err) {
16
+ if (!hasError) {
17
+ hasError = true;
18
+ firstError = err;
19
+ }
20
+ }
21
+ if (hasError) throw firstError;
22
+ }
23
+ function subscribeListener(listeners, listener) {
24
+ const existing = listeners.get(listener);
25
+ if (existing) return existing;
26
+ const dispose = ()=>{
27
+ if (listeners.get(listener) === dispose) listeners.delete(listener);
28
+ };
29
+ listeners.set(listener, dispose);
30
+ return dispose;
31
+ }
32
+ function dispatchListeners(listeners, invoke) {
33
+ for (const [listener, registration] of [
34
+ ...listeners
35
+ ])if (listeners.get(listener) === registration) invoke(listener);
36
+ }
37
+ function copyHostData(value) {
38
+ if (Array.isArray(value)) return value.map((item)=>copyHostData(item));
39
+ if (!isPlainRecord(value)) return value;
40
+ const copy = null === Object.getPrototypeOf(value) ? Object.create(null) : {};
41
+ for (const key of Object.keys(value)){
42
+ const copiedValue = copyHostData(value[key]);
43
+ if ('__proto__' === key) Object.defineProperty(copy, key, {
44
+ value: copiedValue,
45
+ enumerable: true,
46
+ writable: true,
47
+ configurable: true
48
+ });
49
+ else copy[key] = copiedValue;
50
+ }
51
+ return copy;
52
+ }
53
+ export { NATIVE_EVENT_DESTROY_LIFETIME, NATIVE_EVENT_RENDER_PAGE, NATIVE_EVENT_UPDATE_GLOBAL_PROPS, NATIVE_EVENT_UPDATE_PAGE, copyHostData, dispatchListeners, invokeAll, isPlainRecord, subscribeListener };
@@ -0,0 +1,203 @@
1
+ /** Idempotently remove this registration; does not destroy its page or restore a previous owner. */
2
+ export type Unsubscribe = () => void;
3
+ export interface LynxSystemInfo {
4
+ platform?: string | undefined;
5
+ pixelRatio?: number | undefined;
6
+ pixelWidth?: number | undefined;
7
+ pixelHeight?: number | undefined;
8
+ lynxSdkVersion?: string | undefined;
9
+ engineVersion?: string | undefined;
10
+ osVersion?: string | undefined;
11
+ runtimeType?: string | undefined;
12
+ theme?: Record<string, unknown> | undefined;
13
+ [key: string]: unknown;
14
+ }
15
+ export interface CreatePipelineOptions {
16
+ pipelineOrigin?: string | undefined;
17
+ needTimestamps?: boolean | undefined;
18
+ timingFlag?: string | undefined;
19
+ dsl?: string | undefined;
20
+ stage?: string | undefined;
21
+ }
22
+ export interface PipelineOptions {
23
+ pipelineID?: string | undefined;
24
+ pipelineOrigin?: string | undefined;
25
+ needTimestamps?: boolean | undefined;
26
+ dsl?: string | undefined;
27
+ stage?: string | undefined;
28
+ [key: string]: unknown;
29
+ }
30
+ /** A successfully created host pipeline, with a usable identifier. */
31
+ export interface CreatedPipelineOptions extends PipelineOptions {
32
+ pipelineID: string;
33
+ }
34
+ export interface MTSRenderOptions {
35
+ processorName?: string | undefined;
36
+ preLoadTemplate?: boolean | undefined;
37
+ pipelineOptions?: PipelineOptions | undefined;
38
+ initPage?: unknown;
39
+ }
40
+ /**
41
+ * Host pass-through context carried from MTS lifecycle callbacks into `flushElementTree`.
42
+ * Keep this context with its work, including when submission is deferred.
43
+ */
44
+ export interface MTSFlushContext {
45
+ /** Preserve the originating host reload context when submitting its changes. */
46
+ reloadTemplate?: boolean | undefined;
47
+ /** Preserve the host update sequence when forwarding or deferring a flush. */
48
+ nativeUpdateDataOrder?: number | undefined;
49
+ pipelineOptions?: PipelineOptions | undefined;
50
+ }
51
+ /**
52
+ * Context for one host page data update or reset. Keep this context with its work
53
+ * and pass it to `flushElementTree`, including when submission is deferred.
54
+ */
55
+ export interface MTSUpdateOptions extends MTSFlushContext {
56
+ /** Replace current page data rather than merging an incremental update. */
57
+ resetPageData?: boolean | undefined;
58
+ processorName?: string | undefined;
59
+ triggerLifeCycle?: boolean | undefined;
60
+ }
61
+ /**
62
+ * Context for one host template reload on MTS. Keep this context with its work
63
+ * and pass it to `flushElementTree`, including when submission is deferred.
64
+ */
65
+ export interface MTSReloadOptions extends MTSUpdateOptions {
66
+ /** Reload the template and replace the initial-input baseline. */
67
+ reloadTemplate?: boolean | undefined;
68
+ /** The host reload originated from JS. */
69
+ reloadFromJS?: boolean | undefined;
70
+ }
71
+ export interface MTSFlushOptions extends MTSFlushContext {
72
+ /** Timing flag associated with the active performance pipeline. */
73
+ timingFlag?: string | undefined;
74
+ /** Request layout (Native default: true). */
75
+ triggerLayout?: boolean | undefined;
76
+ /** Request the client OnDataUpdated callback (Native default: false). */
77
+ triggerDataUpdated?: boolean | undefined;
78
+ /** Allow the unified pixel pipeline to skip resolving an empty patch. */
79
+ emptyPatch?: boolean | undefined;
80
+ }
81
+ export interface BTSUpdateOptions {
82
+ /** Replace current page data rather than merging an incremental update. */
83
+ resetPageData?: boolean | undefined;
84
+ processorName?: string | undefined;
85
+ }
86
+ export interface BTSReloadOptions {
87
+ processorName?: string | undefined;
88
+ }
89
+ export type BTSEventHandler<T = unknown> = (this: void, handlerName: string, data: T, componentId?: string) => unknown;
90
+ /** Capabilities bound to one host App instance; retain this handle across asynchronous work. */
91
+ export interface BTSPageRuntime {
92
+ /**
93
+ * True from the start of BTS page destruction, including inside teardown callbacks.
94
+ *
95
+ * @since Lynx 2.14
96
+ */
97
+ isDestroyed(this: void): boolean;
98
+ getSystemInfo(this: void): Readonly<LynxSystemInfo>;
99
+ createPipeline(this: void, options?: CreatePipelineOptions): CreatedPipelineOptions | undefined;
100
+ markTiming(this: void, pipeline: string | PipelineOptions | undefined, timingKey: string): void;
101
+ /** Host ID captured at binding; empty when the host provides no ID. */
102
+ getId(this: void): string;
103
+ /**
104
+ * Detached records and arrays for mutable DSL state; opaque values remain shared.
105
+ * Overlays the current round's processed initial or `onReload` `TemplateData`
106
+ * onto the template's static `_params.initData` (`encoded_data`), replacing
107
+ * previous dynamic keys across reloads while preserving static template keys.
108
+ * Incremental updates do not change this baseline. Remains readable after destruction.
109
+ */
110
+ getInitData<T = Record<string, unknown>>(this: void): T;
111
+ /**
112
+ * Borrow the bound page's current host GlobalProps without copying
113
+ * (defaults to `{}` when the host has not injected GlobalProps).
114
+ * Treat the entire value as read-only, including nested objects; Readonly is
115
+ * shallow and no freeze is applied. If a DSL mutates its own root GlobalProps
116
+ * object in place (e.g. via `Object.assign`), shallow-copy
117
+ * `{ ...page.getGlobalProps() }` during bootstrap.
118
+ * Tracked automatically from `bindPage()` and remains readable after destruction.
119
+ */
120
+ getGlobalProps<T = Record<string, unknown>>(this: void): Readonly<T>;
121
+ /** Subscribe to host GlobalProps updates without replaying earlier notifications. */
122
+ onGlobalPropsChanged<T = Record<string, unknown>>(this: void, listener: (globalProps: Readonly<T>) => void): Unsubscribe;
123
+ /**
124
+ * Subscribe to host incremental data updates and `resetPageData` replacements on BTS.
125
+ *
126
+ * @remarks
127
+ * Subscribes directly to the page's `tt.updateCardData` callback without an
128
+ * MTS-to-BTS forwarding bridge (requires `REACT_NODIFF` bundle DSL on Native,
129
+ * used by standard Rspeedy/ReactLynx, `@lynx-js/rspeedy` Vanilla, and `.lynxml`
130
+ * on hosts that build LynxML bundles as `REACT_NODIFF`; legacy
131
+ * `PackageInstanceDSL::REACT` bundles skip BTS `updateCardData`).
132
+ * Payloads are read-only. The DSL owns merge/reset state and rendering;
133
+ * registering a listener does not replay earlier updates.
134
+ */
135
+ onUpdateData<T = Record<string, unknown>>(this: void, listener: (data: Readonly<T>, options: Readonly<BTSUpdateOptions>) => void): Unsubscribe;
136
+ /**
137
+ * Subscribe to host template reloads on BTS (`tt.onAppReload`).
138
+ * Runtime refreshes `getInitData()` by overlaying the reload payload onto
139
+ * template static `_params.initData` before invoking listeners.
140
+ * A reload notification alone does not destroy the bound App or retire DSL resources.
141
+ */
142
+ onReload<T = Record<string, unknown>>(this: void, listener: (data: Readonly<T>, options: Readonly<BTSReloadOptions>) => void): Unsubscribe;
143
+ onConfigChanged<T = Record<string, unknown>>(this: void, listener: (config: Readonly<T>) => void): Unsubscribe;
144
+ onEnterForeground(this: void, listener: () => void): Unsubscribe;
145
+ onEnterBackground(this: void, listener: () => void): Unsubscribe;
146
+ /**
147
+ * Subscribe to host global events delivered to this page's `GlobalEventEmitter`
148
+ * (such as client `sendGlobalEvent`, `exposure` / `disexposure`, and
149
+ * `keyboardstatuschanged`) while the page and emitter are available.
150
+ *
151
+ * @remarks
152
+ * Resolves `GlobalEventEmitter` from the bound page so asynchronous subscriptions
153
+ * in a shared `LynxGroup` context remain isolated from peer pages. Shares one host
154
+ * listener per event `name` on this page, deduplicates identical `(name, listener)`
155
+ * callbacks, forwards all positional arguments with `undefined` `this`, and removes
156
+ * all listeners before DSL `onDestroy` callbacks run. Does not replay earlier events
157
+ * or validate `Args` at runtime; dispose when an owning entry retires across in-place
158
+ * reloads (`onReload`).
159
+ */
160
+ onGlobalEvent<Args extends unknown[] = unknown[]>(this: void, name: string, listener: (this: void, ...args: Args) => void): Unsubscribe;
161
+ /**
162
+ * Claim both raw page and component event slots with one synchronous handler.
163
+ * Latest registration wins; disposal clears the current handler without restoring
164
+ * an earlier owner. Page events have no componentId; component events retain it.
165
+ * Return values and exceptions pass through to the host (synchronous return values
166
+ * are consumed on Native; Web event RPC is one-way); Promises are not awaited
167
+ * and false is ordinary data, not cancellation. Register only while the page is alive.
168
+ */
169
+ setEventHandler<T = unknown>(this: void, handler: BTSEventHandler<T>): Unsubscribe;
170
+ /**
171
+ * Send to this bound page's MTS; returns no receipt and does not wait for execution.
172
+ * Requires a live page and its host peer proxy. Install the receiver before sending:
173
+ * there is no startup queue, retry, RPC, or cross-type ordering guarantee.
174
+ * T constrains the caller only; it does not validate the peer's payload.
175
+ */
176
+ sendMessage<T = undefined>(this: void, type: string, ...args: undefined extends T ? [data?: T] : [data: T]): void;
177
+ /**
178
+ * Subscribe to raw payloads from this page's MTS while the page and proxy are available.
179
+ * Identical callbacks for a type share a registration. Dispose when the owning entry
180
+ * retires; page destruction also removes listeners. No replay or payload validation.
181
+ */
182
+ onMessage<T = unknown>(this: void, type: string, listener: (this: void, data: T) => void): Unsubscribe;
183
+ /**
184
+ * Subscribe to BTS page destruction.
185
+ *
186
+ * @remarks
187
+ * Supported across **Lynx SDK 2.14+** on Native (`tt.callDestroyLifetimeFun`)
188
+ * and on Web. Do not also register a `lynx.getNative()` `__DestroyLifetime`
189
+ * listener on BTS, as Native skips `tt.callDestroyLifetimeFun` when one is present.
190
+ * Use this hook to deterministically release page-scoped timers, subscriptions,
191
+ * and shared `LynxGroup` background resources when a page instance is destroyed.
192
+ *
193
+ * Host template reload (`onReload`) does **not** trigger host destruction unless
194
+ * the DSL explicitly invokes `callDestroyLifetimeFun()` before `reloadCard()`.
195
+ * Runtime objects recreated across in-place reloads must invoke the returned
196
+ * `Unsubscribe` disposer when retiring so listeners do not accumulate.
197
+ *
198
+ * @param listener - Callback invoked synchronously when BTS page destruction begins.
199
+ * @returns An idempotent disposer that unsubscribes `listener`.
200
+ * @since Lynx 2.14
201
+ */
202
+ onDestroy(this: void, listener: () => void): Unsubscribe;
203
+ }
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1 @@
1
+ var LynxRuntime;(()=>{"use strict";var e={};e.d=(t,n,l)=>{var r=(n,l)=>{for(var r in n)e.o(n,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,[l]:n[r]})};r(n,"get"),r(l,"value")},e.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),e.r=e=>{"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var t={};function n(e){if(Array.isArray(e))return e.map(e=>n(e));if(!function(e){if(!e||"object"!=typeof e||Array.isArray(e))return!1;let t=Object.getPrototypeOf(e);return null===t||t===Object.prototype}(e))return e;let t=null===Object.getPrototypeOf(e)?Object.create(null):{};for(let l of Object.keys(e)){let r=n(e[l]);"__proto__"===l?Object.defineProperty(t,l,{value:r,enumerable:!0,writable:!0,configurable:!0}):t[l]=r}return t}function l(e,t,n,l){let r=e.get(t);if(!r){let n=new Map,o=0,i=!1,a=l(e=>{o++;try{for(let[t,l]of[...n])n.get(t)===l&&e(t)}finally{o--}}),s=()=>{0===n.size&&e.get(t)===u&&(e.delete(t),a())},u={listeners:n,unsubscribeHost:a,releaseIfEmpty:()=>{0===o?s():i||(i=!0,Promise.resolve().then(()=>{i=!1,s()}))}};r=u,e.set(t,u)}let o=r,i=o.listeners.get(n);if(i)return i;let a=()=>{o.listeners.get(n)===a&&(o.listeners.delete(n),0===o.listeners.size&&o.releaseIfEmpty())};return o.listeners.set(n,a),a}function r(e){for(let t of e.values())t.listeners.clear(),t.unsubscribeHost();e.clear()}e.r(t),e.d(t,{bindPage:()=>f});let o=new WeakMap;function i(e){if(e.destroyed)throw Error("[@lynx-js/lynx-runtime/bts] Cannot register or activate a capability on a destroying or destroyed page. Check page.isDestroyed() before registering in async callbacks.")}function a(e,t){var n;let l=t.lynx;if(l&&((null==(n=l.getApp)?void 0:n.call(l))===e||!l.getApp&&!t.multiApps&&t.tt===e))return l}function s(e){var t,n;return null!=(t=null!=(n=e.app.lynx)?n:e.lynx)?t:a(e.app,globalThis)}function u(e,t){return function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},l=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(l=l.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),l.forEach(function(t){var l;l=n[t],t in e?Object.defineProperty(e,t,{value:l,enumerable:!0,configurable:!0,writable:!0}):e[t]=l})}return e}({},e,t?n(t):void 0)}function p(e,t,n){let l=e.slots.get(t);if(l)return l;let r=e.app,o=r[t],i=l=new Map;return r[t]=function(...t){if(e.destroyed||null==n||n(...t),null==o||o.apply(this,t),!e.destroyed)for(let[e,n]of[...i])i.get(e)===n&&n.invoke(...t)},e.slots.set(t,l),l}function c(e,t,n,l=n){i(e);let r=p(e,t),o=r.get(l);if(o)return o.dispose;let a=()=>{var e;(null==(e=r.get(l))?void 0:e.dispose)===a&&r.delete(l)};return r.set(l,{invoke:n,dispose:a}),a}function d(e){var t,n,l,r,o;let i=globalThis;return null!=(t=null!=(n=null!=(l=null==(r=s(e))?void 0:r.SystemInfo)?l:i.SystemInfo)?n:null==(o=i.lynx)?void 0:o.SystemInfo)?t:{}}function v(e){var t,n;let l=null==(n=s(e))||null==(t=n.getCoreContext)?void 0:t.call(n);if(!l)throw Error("[@lynx-js/lynx-runtime/bts] Message communication requires lynx.getCoreContext(). Ensure the BTS host context is initialized before calling sendMessage() or onMessage().");return l}function f(){let e=function(){var e,t,l,i,s,c;let d,v=globalThis,f="u"<typeof lynx?void 0:lynx,g=(d=v.currentAppId&&v.multiApps?v.multiApps[v.currentAppId]:void 0,null!=(e=null!=(t=null!=(l=null==f||null==(i=f.getApp)?void 0:i.call(f))?l:null==(c=v.lynx)||null==(s=c.getApp)?void 0:s.call(c))?t:d)?e:v.tt);if(!g)throw Error("[@lynx-js/lynx-runtime/bts] Unable to resolve BTS App instance (`tt`). Call bindPage() synchronously during BTS page bootstrap and retain the returned handle.");return function(e,t,l){var i,s,c;let d=o.get(e);if(d)return d;let v=e.lynx;v||!l||l.getApp&&l.getApp()!==e||(v=l),null!=v||(v=a(e,t));let f=e._params,g=(null==f?void 0:f.initData)?n(f.initData):void 0,y=u(g,null==f?void 0:f.updateData),b={appId:null!=(i=null!=(s=null==f?void 0:f.appGUID)?s:e.nativeAppId)?i:"",app:e,lynx:v,rawInitData:g,initData:y,globalProps:null!=(c=null==v?void 0:v.__globalProps)?c:{},destroyed:!1,slots:new Map,destroyListeners:new Map};p(b,"onAppReload",e=>{b.initData=u(b.rawInitData,e)}),p(b,"updateGlobalProps",e=>{b.globalProps=null!=e?e:{}});let m=e.callDestroyLifetimeFun;return e.callDestroyLifetimeFun=function(){if(b.destroyed){null==m||m.call(this);return}b.destroyed=!0,b.globalEvents&&(r(b.globalEvents),b.globalEvents=void 0),b.messages&&(r(b.messages),b.messages=void 0),b.eventEntry&&(b.eventEntry.current=void 0,b.eventEntry=void 0);try{var e=[...m?[()=>m.call(this)]:[],...[...b.destroyListeners].map(([e,t])=>()=>{b.destroyListeners.get(e)===t&&e()})];let t,n=!1;for(let l of e)try{l()}catch(e){n||(n=!0,t=e)}if(n)throw t}finally{for(let e of(b.destroyListeners.clear(),b.slots.values()))e.clear();b.slots.clear()}},o.set(e,b),b}(g,v,f)}();return null!=e.runtime||(e.runtime={isDestroyed:()=>e.destroyed,getSystemInfo:()=>d(e),createPipeline:t=>(function(e,t){var n;if(!e.destroyed)return function(e,t,n){var l,r,o,i;let a=null==e||null==(l=e._generatePipelineOptions)?void 0:l.call(e),s=null==a?void 0:a.pipelineID;if(!a||!s)return;(null==t?void 0:t.needTimestamps)!==void 0&&(a.needTimestamps=t.needTimestamps),(null==t?void 0:t.pipelineOrigin)!==void 0&&(a.pipelineOrigin=t.pipelineOrigin),(null==t?void 0:t.dsl)!==void 0&&(a.dsl=t.dsl),(null==t?void 0:t.stage)!==void 0&&(a.stage=t.stage);{let[t=0,l=0]=(null!=n?n:"1.0").split(".").map(Number);t>3||3===t&&l>0?null==e||null==(r=e._onPipelineStart)||r.call(e,s,a):null==e||null==(o=e._onPipelineStart)||o.call(e,s)}let u=null==t?void 0:t.timingFlag;return u&&(null==e||null==(i=e._bindPipelineIdWithTimingFlag)||i.call(e,s,u)),a}(null==(n=s(e))?void 0:n.performance,t,d(e).lynxSdkVersion)})(e,t),markTiming:(t,n)=>(function(e,t,n){var l,r,o;if(!e.destroyed){let i;r=null==(l=s(e))?void 0:l.performance,(i="string"==typeof t?t:null==t?void 0:t.pipelineID)&&n&&(null==r||null==(o=r._markTiming)||o.call(r,i,n))}})(e,t,n),getId:()=>e.appId,getInitData:()=>n(e.initData),getGlobalProps:()=>e.globalProps,onGlobalPropsChanged:t=>{var n;return c(e,"updateGlobalProps",()=>{n(e.globalProps)},n=t)},onUpdateData:t=>{var n;return c(e,"updateCardData",(e,t)=>{n(null!=e?e:{},{resetPageData:(null==t?void 0:t.type)===1,processorName:(null==t?void 0:t.processorName)===""||null==t?void 0:t.processorName})},n=t)},onReload:t=>{var n;return c(e,"onAppReload",(e,t)=>{var l,r;n(null!=e?e:{},t?(l=function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},l=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(l=l.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),l.forEach(function(t){var l;l=n[t],t in e?Object.defineProperty(e,t,{value:l,enumerable:!0,configurable:!0,writable:!0}):e[t]=l})}return e}({},t),r=r={processorName:""===t.processorName?void 0:t.processorName},Object.getOwnPropertyDescriptors?Object.defineProperties(l,Object.getOwnPropertyDescriptors(r)):(function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t.push.apply(t,n)}return t})(Object(r)).forEach(function(e){Object.defineProperty(l,e,Object.getOwnPropertyDescriptor(r,e))}),l):{})},n=t)},onConfigChanged:t=>{var n;return c(e,"processCardConfig",e=>{n(null!=e?e:{})},n=t)},onEnterForeground:t=>c(e,"onAppEnterForeground",t),onEnterBackground:t=>c(e,"onAppEnterBackground",t),onGlobalEvent:(t,n)=>(i(e),null!=e.globalEvents||(e.globalEvents=new Map),l(e.globalEvents,t,n,n=>{let l=function(e){var t,n,l,r;let o=null!=(t=null==(n=(l=e.app).getJSModule)?void 0:n.call(l,"GlobalEventEmitter"))?t:e.app.GlobalEventEmitter;if(!o){let t=s(e);t&&(!t.getApp||t.getApp()===e.app)&&(o=null==(r=t.getJSModule)?void 0:r.call(t,"GlobalEventEmitter"))}if(!o)throw Error("[@lynx-js/lynx-runtime/bts] Global event subscription requires GlobalEventEmitter. Ensure the BTS host environment is initialized before calling onGlobalEvent().");return o}(e),r=(...e)=>{n(t=>{t(...e)})};return l.addListener(t,r),()=>{l.removeListener(t,r)}})),setEventHandler:t=>(function(e,t){i(e);let n=e.eventEntry;if(!n){let t,l;t=(e,t,n)=>{var r;let o=null==(r=l.current)?void 0:r.handler;return null==o?void 0:o(e,t,n)},n=e.eventEntry=l={current:void 0,publishEvent:(e,n)=>t(e,n),publicComponentEvent:(e,n,l)=>t(n,l,e)},e.app.publishEvent=n.publishEvent,e.app.publicComponentEvent=n.publicComponentEvent}let l={handler:t};n.current=l;let r=n;return()=>{r.current===l&&(r.current=void 0)}})(e,t),sendMessage:(t,n)=>{i(e),v(e).dispatchEvent({type:t,data:n})},onMessage:(t,n)=>{var r;let o;return i(e),o=v(e),null!=e.messages||(e.messages=new Map),r=e.messages,l(r,t,n,e=>{let n=t=>{e(e=>{e(t.data)})};return o.addEventListener(t,n),()=>{o.removeEventListener(t,n)}})},onDestroy:t=>(function(e,t){i(e);var n=e.destroyListeners;let l=n.get(t);if(l)return l;let r=()=>{n.get(t)===r&&n.delete(t)};return n.set(t,r),r})(e,t)}),e.runtime}LynxRuntime=t})();
@@ -0,0 +1 @@
1
+ var LynxRuntime;(()=>{"use strict";var e={};e.d=(t,n,l)=>{var r=(n,l)=>{for(var r in n)e.o(n,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,[l]:n[r]})};r(n,"get"),r(l,"value")},e.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),e.r=e=>{"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var t={};e.r(t),e.d(t,{createPipeline:()=>S,flushElementTree:()=>j,getGlobalProps:()=>v,getInitData:()=>m,getSystemInfo:()=>L,isDestroyed:()=>f,markTiming:()=>w,onDestroy:()=>y,onGlobalPropsChanged:()=>D,onMessage:()=>I,onReload:()=>O,onRenderPage:()=>P,onUpdateData:()=>h,sendMessage:()=>E,setDataProcessor:()=>_,setPageDataGetter:()=>x});let n="__DestroyLifetime";function l(e){if(!e||"object"!=typeof e||Array.isArray(e))return!1;let t=Object.getPrototypeOf(e);return null===t||t===Object.prototype}function r(e,t){let n=e.get(t);if(n)return n;let l=()=>{e.get(t)===l&&e.delete(t)};return e.set(t,l),l}function o(e,t){for(let[n,l]of[...e])e.get(n)===l&&t(n)}function s(e){if(Array.isArray(e))return e.map(e=>s(e));if(!l(e))return e;let t=null===Object.getPrototypeOf(e)?Object.create(null):{};for(let n of Object.keys(e)){let l=s(e[n]);"__proto__"===n?Object.defineProperty(t,n,{value:l,enumerable:!0,writable:!0,configurable:!0}):t[n]=l}return t}let i=new WeakMap,a=e=>e,u=()=>null,d=()=>{};function g(e){var t,n;return(null==(n=i.get(null!=(t=e.lynx)?t:e))?void 0:n.destroyed)===!0}function c(e){var t,l,r,g,c,p;let f=null!=(t=e.lynx)?t:e,y=i.get(f);if(y)return y;let b=null==(r=e.lynx)||null==(l=r.getNative)?void 0:l.call(r),m={destroyed:!1,hasDestroyProxy:void 0!==b,destroyListeners:new Map,globalProps:{},initData:{},renderListeners:new Map,updateListeners:new Map,reloadListeners:new Map,globalPropsListeners:new Map,slots:{}};i.set(f,m);let v=(e,t)=>{if(m.destroyed)return;let n=null!=e?e:{};m.initData=s(n);let l=null!=t?t:{};o(m.renderListeners,e=>{e(n,l)})},P=(e,t)=>{if(m.destroyed)return;let n=null!=e?e:{},l=null!=t?t:{};l.reloadTemplate?(m.initData=s(n),o(m.reloadListeners,e=>{e(n,l)})):o(m.updateListeners,e=>{e(n,l)})},h=(e,t)=>{if(m.destroyed)return;let n=null!=e?e:{};o(m.globalPropsListeners,e=>{e(n,t)})};e.renderPage=v,e.updatePage=P,e.updateGlobalProps=h,null!=e.processData||(e.processData=a),null!=e.removeComponents||(e.removeComponents=d),null!=e.getPageData||(e.getPageData=u),(null==(g=e.lynx)?void 0:g.SystemInfo)&&!e.SystemInfo&&(e.SystemInfo=e.lynx.SystemInfo);let O=null==(p=e.lynx)||null==(c=p.getEngine)?void 0:c.call(p);if(O&&(O.addEventListener("__RenderPage",e=>{let[t,n]=e.data;v(t,n)}),O.addEventListener("__UpdatePage",e=>{let[t,n]=e.data;P(t,n)}),O.addEventListener("__UpdateGlobalProps",e=>{let[t,n]=e.data;h(t,n)})),b){let t=()=>{var l,r;if(!m.destroyed){m.globalProps=null!=(l=null==(r=e.lynx)?void 0:r.__globalProps)?l:m.globalProps,m.destroyed=!0;try{if(m.messages){var o=m.messages;for(let e of o.values())e.listeners.clear(),e.unsubscribeHost();o.clear(),m.messages=void 0}var s=[...m.destroyListeners].map(([e,t])=>()=>{m.destroyListeners.get(e)===t&&e()});let e,t=!1;for(let n of s)try{n()}catch(n){t||(t=!0,e=n)}if(t)throw e}finally{m.renderListeners.clear(),m.updateListeners.clear(),m.reloadListeners.clear(),m.globalPropsListeners.clear(),m.destroyListeners.clear(),m.slots.processData&&e.processData===m.slots.processData&&(e.processData=a),m.slots.processData=void 0,m.slots.getPageData&&e.getPageData===m.slots.getPageData&&(e.getPageData=u),m.slots.getPageData=void 0,b.removeEventListener(n,t)}}};b.addEventListener(n,t)}return m}function p(e){let t=c(e);if(t.destroyed)throw Error("[@lynx-js/lynx-runtime/mts] Cannot register or activate a capability on a destroying or destroyed host. Check isDestroyed() before registering in async callbacks.");return t}function f(){return g(globalThis)}function y(e){let t=p(globalThis);return t.hasDestroyProxy?r(t.destroyListeners,e):d}function b(e,t,n){let l=globalThis,r=p(l);return r.slots[e]=n,l[e]=n,()=>{r.slots[e]===n&&(r.slots[e]=void 0,l[e]===n&&(l[e]=t))}}function m(){return s(c(globalThis).initData)}function v(){var e,t;let n=globalThis,l=c(n);return l.destroyed?l.globalProps:null!=(e=null==(t=n.lynx)?void 0:t.__globalProps)?e:l.globalProps}function P(e){return r(p(globalThis).renderListeners,e)}function h(e){return r(p(globalThis).updateListeners,e)}function O(e){return r(p(globalThis).reloadListeners,e)}function D(e){return r(p(globalThis).globalPropsListeners,e)}function _(e){return b("processData",a,(t,n)=>e(null!=t?t:{},""===n?void 0:n))}function x(e){return b("getPageData",u,t=>e(t))}function j(e){var t,n;let r=globalThis;p(r);let o=r.__FlushElementTree;if(!o)throw Error("[@lynx-js/lynx-runtime/mts] Page flush requires __FlushElementTree(). Ensure flushElementTree() is called on the main thread (MTS).");if(void 0===e)return void o();if(!l(e))throw TypeError("[@lynx-js/lynx-runtime/mts] Flush options must be a plain object (flushElementTree(options) flushes the page root and does not take an element target).");o(void 0,void 0!==e.timingFlag&&void 0===e.__lynx_timing_flag?(t=function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},l=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(l=l.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),l.forEach(function(t){var l;l=n[t],t in e?Object.defineProperty(e,t,{value:l,enumerable:!0,configurable:!0,writable:!0}):e[t]=l})}return e}({},e),n=n={__lynx_timing_flag:e.timingFlag},Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):(function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t.push.apply(t,n)}return t})(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}),t):e)}function T(e,t){let n=t.jsContext;if(!n){var l,r;if(!(n=null==(r=e.lynx)||null==(l=r.getJSContext)?void 0:l.call(r)))throw Error("[@lynx-js/lynx-runtime/mts] Message communication requires lynx.getJSContext(). Ensure the MTS host context is initialized before calling sendMessage() or onMessage().");t.jsContext=n}return n}function L(){var e,t,n,l;let r=globalThis;return!g(r)&&(null==(e=r.lynx)?void 0:e.SystemInfo)&&!r.SystemInfo&&(r.SystemInfo=r.lynx.SystemInfo),null!=(t=null!=(n=null==(l=r.lynx)?void 0:l.SystemInfo)?n:r.SystemInfo)?t:{}}function S(e){var t;let n=globalThis;if(!g(n))return function(e,t){var n,l,r,o;let s=null==e||null==(n=e._generatePipelineOptions)?void 0:n.call(e),i=null==s?void 0:s.pipelineID;if(!s||!i)return;(null==t?void 0:t.needTimestamps)!==void 0&&(s.needTimestamps=t.needTimestamps),(null==t?void 0:t.pipelineOrigin)!==void 0&&(s.pipelineOrigin=t.pipelineOrigin),(null==t?void 0:t.dsl)!==void 0&&(s.dsl=t.dsl),(null==t?void 0:t.stage)!==void 0&&(s.stage=t.stage),s.pipelineOrigin?null==e||null==(l=e._onPipelineStart)||l.call(e,i,s.pipelineOrigin):null==e||null==(r=e._onPipelineStart)||r.call(e,i);let a=null==t?void 0:t.timingFlag;return a&&(null==e||null==(o=e._bindPipelineIDWithTimingFlag)||o.call(e,i,a)),s}(null==(t=n.lynx)?void 0:t.performance,e)}function w(e,t){var n,l,r;let o=globalThis;if(!g(o)){let s;l=null==(n=o.lynx)?void 0:n.performance,(s="string"==typeof e?e:null==e?void 0:e.pipelineID)&&t&&(null==l||null==(r=l._markTiming)||r.call(l,s,t))}}function E(e,t){let n=globalThis,l=p(n);T(n,l).dispatchEvent({type:e,data:t})}function I(e,t){var n;let l=globalThis,r=p(l),s=T(l,r);return null!=r.messages||(r.messages=new Map),n=r.messages,function(e,t,n,l){let r=e.get(t);if(!r){let n=new Map,s=0,i=!1,a=l(e=>{s++;try{o(n,e)}finally{s--}}),u=()=>{0===n.size&&e.get(t)===d&&(e.delete(t),a())},d={listeners:n,unsubscribeHost:a,releaseIfEmpty:()=>{0===s?u():i||(i=!0,Promise.resolve().then(()=>{i=!1,u()}))}};r=d,e.set(t,d)}let s=r,i=s.listeners.get(n);if(i)return i;let a=()=>{s.listeners.get(n)===a&&(s.listeners.delete(n),0===s.listeners.size&&s.releaseIfEmpty())};return s.listeners.set(n,a),a}(n,e,t,t=>{let n=e=>{t(t=>{t(e.data)})};return s.addEventListener(e,n),()=>{s.removeEventListener(e,n)}})}LynxRuntime=t})();