@lynx-js/web-core-wasm 0.0.0 → 0.0.2

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 (192) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/{LICENSE → LICENSE.txt} +1 -1
  3. package/Notice.txt +1 -0
  4. package/README.md +1 -0
  5. package/binary/client/client.d.ts +272 -0
  6. package/binary/client/client.js +1297 -0
  7. package/binary/client/client_bg.wasm +0 -0
  8. package/binary/client/client_bg.wasm.d.ts +71 -0
  9. package/binary/client/client_debug.d.ts +272 -0
  10. package/binary/client/client_debug.js +1297 -0
  11. package/binary/client/client_debug_bg.wasm +0 -0
  12. package/binary/client/client_debug_bg.wasm.d.ts +71 -0
  13. package/binary/encode/encode.d.ts +118 -0
  14. package/binary/encode/encode.js +542 -0
  15. package/binary/encode/encode_bg.wasm +0 -0
  16. package/binary/encode/encode_bg.wasm.d.ts +30 -0
  17. package/binary/encode/encode_debug.d.ts +118 -0
  18. package/binary/encode/encode_debug.js +542 -0
  19. package/binary/encode/encode_debug_bg.wasm +0 -0
  20. package/binary/encode/encode_debug_bg.wasm.d.ts +30 -0
  21. package/binary/encode/package.json +4 -0
  22. package/css/in_shadow.css +10 -0
  23. package/css/index.css +119 -0
  24. package/dist/client/LynxCrossThreadContext.d.ts +22 -0
  25. package/dist/client/LynxCrossThreadContext.js +44 -0
  26. package/dist/client/background/background-apis/createBackgroundLynx.d.ts +25 -0
  27. package/dist/client/background/background-apis/createBackgroundLynx.js +41 -0
  28. package/dist/client/background/background-apis/createChunkLoading.d.ts +7 -0
  29. package/dist/client/background/background-apis/createChunkLoading.js +66 -0
  30. package/dist/client/background/background-apis/createElement.d.ts +5 -0
  31. package/dist/client/background/background-apis/createElement.js +18 -0
  32. package/dist/client/background/background-apis/createNapiLoader.d.ts +5 -0
  33. package/dist/client/background/background-apis/createNapiLoader.js +23 -0
  34. package/dist/client/background/background-apis/createNativeApp.d.ts +4 -0
  35. package/dist/client/background/background-apis/createNativeApp.js +98 -0
  36. package/dist/client/background/background-apis/createNativeModules.d.ts +3 -0
  37. package/dist/client/background/background-apis/createNativeModules.js +33 -0
  38. package/dist/client/background/background-apis/createPerformanceApis.d.ts +3 -0
  39. package/dist/client/background/background-apis/createPerformanceApis.js +47 -0
  40. package/dist/client/background/background-apis/createTimingSystem.d.ts +8 -0
  41. package/dist/client/background/background-apis/createTimingSystem.js +86 -0
  42. package/dist/client/background/background-apis/crossThreadHandlers/createGetCustomSection.d.ts +3 -0
  43. package/dist/client/background/background-apis/crossThreadHandlers/createGetCustomSection.js +14 -0
  44. package/dist/client/background/background-apis/crossThreadHandlers/createGetPathInfo.d.ts +3 -0
  45. package/dist/client/background/background-apis/crossThreadHandlers/createGetPathInfo.js +23 -0
  46. package/dist/client/background/background-apis/crossThreadHandlers/createInvokeUIMethod.d.ts +3 -0
  47. package/dist/client/background/background-apis/crossThreadHandlers/createInvokeUIMethod.js +24 -0
  48. package/dist/client/background/background-apis/crossThreadHandlers/createJSObjectDestructionObserver.d.ts +2 -0
  49. package/dist/client/background/background-apis/crossThreadHandlers/createJSObjectDestructionObserver.js +12 -0
  50. package/dist/client/background/background-apis/crossThreadHandlers/registerDisposeHandler.d.ts +3 -0
  51. package/dist/client/background/background-apis/crossThreadHandlers/registerDisposeHandler.js +9 -0
  52. package/dist/client/background/background-apis/crossThreadHandlers/registerPublicComponentEventHandler.d.ts +3 -0
  53. package/dist/client/background/background-apis/crossThreadHandlers/registerPublicComponentEventHandler.js +8 -0
  54. package/dist/client/background/background-apis/crossThreadHandlers/registerPublishEventHandler.d.ts +3 -0
  55. package/dist/client/background/background-apis/crossThreadHandlers/registerPublishEventHandler.js +8 -0
  56. package/dist/client/background/background-apis/crossThreadHandlers/registerSendGlobalEvent.d.ts +3 -0
  57. package/dist/client/background/background-apis/crossThreadHandlers/registerSendGlobalEvent.js +10 -0
  58. package/dist/client/background/background-apis/crossThreadHandlers/registerUpdateDataHandler.d.ts +3 -0
  59. package/dist/client/background/background-apis/crossThreadHandlers/registerUpdateDataHandler.js +5 -0
  60. package/dist/client/background/background-apis/crossThreadHandlers/registerUpdateGlobalPropsHandler.d.ts +3 -0
  61. package/dist/client/background/background-apis/crossThreadHandlers/registerUpdateGlobalPropsHandler.js +5 -0
  62. package/dist/client/background/background-apis/crossThreadHandlers/registerUpdateI18nResource.d.ts +3 -0
  63. package/dist/client/background/background-apis/crossThreadHandlers/registerUpdateI18nResource.js +9 -0
  64. package/dist/client/background/background-apis/startBackgroundThread.d.ts +2 -0
  65. package/dist/client/background/background-apis/startBackgroundThread.js +42 -0
  66. package/dist/client/background/index.d.ts +1 -0
  67. package/dist/client/background/index.js +15 -0
  68. package/dist/client/decodeWorker/cssLoader.d.ts +12 -0
  69. package/dist/client/decodeWorker/cssLoader.js +95 -0
  70. package/dist/client/decodeWorker/decode.worker.d.ts +1 -0
  71. package/dist/client/decodeWorker/decode.worker.js +339 -0
  72. package/dist/client/decodeWorker/types.d.ts +32 -0
  73. package/dist/client/decodeWorker/types.js +2 -0
  74. package/dist/client/endpoints.d.ts +54 -0
  75. package/dist/client/endpoints.js +38 -0
  76. package/dist/client/index.d.ts +3 -0
  77. package/dist/client/index.js +3 -0
  78. package/dist/client/mainthread/Background.d.ts +30 -0
  79. package/dist/client/mainthread/Background.js +209 -0
  80. package/dist/client/mainthread/ExposureServices.d.ts +11 -0
  81. package/dist/client/mainthread/ExposureServices.js +211 -0
  82. package/dist/client/mainthread/I18n.d.ts +9 -0
  83. package/dist/client/mainthread/I18n.js +44 -0
  84. package/dist/client/mainthread/LynxView.d.ts +170 -0
  85. package/dist/client/mainthread/LynxView.js +367 -0
  86. package/dist/client/mainthread/LynxViewInstance.d.ts +52 -0
  87. package/dist/client/mainthread/LynxViewInstance.js +188 -0
  88. package/dist/client/mainthread/TemplateManager.d.ts +10 -0
  89. package/dist/client/mainthread/TemplateManager.js +233 -0
  90. package/dist/client/mainthread/createIFrameRealm.d.ts +6 -0
  91. package/dist/client/mainthread/createIFrameRealm.js +68 -0
  92. package/dist/client/mainthread/createMainThreadGlobalAPIs.d.ts +3 -0
  93. package/dist/client/mainthread/createMainThreadGlobalAPIs.js +82 -0
  94. package/dist/client/mainthread/crossThreadHandlers/queryNodes.d.ts +3 -0
  95. package/dist/client/mainthread/crossThreadHandlers/queryNodes.js +74 -0
  96. package/dist/client/mainthread/crossThreadHandlers/registerGetPathInfoHandler.d.ts +3 -0
  97. package/dist/client/mainthread/crossThreadHandlers/registerGetPathInfoHandler.js +51 -0
  98. package/dist/client/mainthread/crossThreadHandlers/registerInvokeUIMethodHandler.d.ts +3 -0
  99. package/dist/client/mainthread/crossThreadHandlers/registerInvokeUIMethodHandler.js +49 -0
  100. package/dist/client/mainthread/crossThreadHandlers/registerNapiModulesCallHandler.d.ts +3 -0
  101. package/dist/client/mainthread/crossThreadHandlers/registerNapiModulesCallHandler.js +8 -0
  102. package/dist/client/mainthread/crossThreadHandlers/registerNativeModulesCallHandler.d.ts +3 -0
  103. package/dist/client/mainthread/crossThreadHandlers/registerNativeModulesCallHandler.js +7 -0
  104. package/dist/client/mainthread/crossThreadHandlers/registerReloadHandler.d.ts +3 -0
  105. package/dist/client/mainthread/crossThreadHandlers/registerReloadHandler.js +10 -0
  106. package/dist/client/mainthread/crossThreadHandlers/registerSelectComponentHandler.d.ts +3 -0
  107. package/dist/client/mainthread/crossThreadHandlers/registerSelectComponentHandler.js +20 -0
  108. package/dist/client/mainthread/crossThreadHandlers/registerSetNativePropsHandler.d.ts +3 -0
  109. package/dist/client/mainthread/crossThreadHandlers/registerSetNativePropsHandler.js +28 -0
  110. package/dist/client/mainthread/crossThreadHandlers/registerTriggerComponentEventHandler.d.ts +3 -0
  111. package/dist/client/mainthread/crossThreadHandlers/registerTriggerComponentEventHandler.js +12 -0
  112. package/dist/client/mainthread/crossThreadHandlers/registerTriggerElementMethodEndpointHandler.d.ts +3 -0
  113. package/dist/client/mainthread/crossThreadHandlers/registerTriggerElementMethodEndpointHandler.js +29 -0
  114. package/dist/client/mainthread/elementAPIs/WASMJSBinding.d.ts +32 -0
  115. package/dist/client/mainthread/elementAPIs/WASMJSBinding.js +117 -0
  116. package/dist/client/mainthread/elementAPIs/createCrossThreadEvent.d.ts +2 -0
  117. package/dist/client/mainthread/elementAPIs/createCrossThreadEvent.js +77 -0
  118. package/dist/client/mainthread/elementAPIs/createElementAPI.d.ts +3 -0
  119. package/dist/client/mainthread/elementAPIs/createElementAPI.js +322 -0
  120. package/dist/client/mainthread/elementAPIs/index.d.ts +2 -0
  121. package/dist/client/mainthread/elementAPIs/index.js +3 -0
  122. package/dist/client/mainthread/elementAPIs/pureElementPAPIs.d.ts +26 -0
  123. package/dist/client/mainthread/elementAPIs/pureElementPAPIs.js +85 -0
  124. package/dist/client/mainthread/utils/convertLengthToPx.d.ts +1 -0
  125. package/dist/client/mainthread/utils/convertLengthToPx.js +25 -0
  126. package/dist/client/wasm.d.ts +3 -0
  127. package/dist/client/wasm.js +38 -0
  128. package/dist/client/webElementsDynamicLoader.d.ts +1 -0
  129. package/dist/client/webElementsDynamicLoader.js +11 -0
  130. package/dist/client_prod/static/css/async/web-elements.css +1 -0
  131. package/dist/client_prod/static/css/client.css +1 -0
  132. package/dist/client_prod/static/js/async/lynx-core-chunk.js +3 -0
  133. package/dist/client_prod/static/js/async/web-core-main-chunk.js +1 -0
  134. package/dist/client_prod/static/js/async/web-core-template-loader-thread.js +8 -0
  135. package/dist/client_prod/static/js/async/web-core-worker-chunk.js +1 -0
  136. package/dist/client_prod/static/js/async/web-elements.js +309 -0
  137. package/dist/client_prod/static/js/client.js +2 -0
  138. package/dist/client_prod/static/wasm/a156b496.module.wasm +0 -0
  139. package/dist/constants.d.ts +58 -0
  140. package/dist/constants.js +114 -0
  141. package/dist/encode/encodeCSS.d.ts +3 -0
  142. package/dist/encode/encodeCSS.js +99 -0
  143. package/dist/encode/index.d.ts +1 -0
  144. package/dist/encode/index.js +7 -0
  145. package/dist/encode/webEncoder.d.ts +21 -0
  146. package/dist/encode/webEncoder.js +110 -0
  147. package/dist/types/BTSChunk.d.ts +3 -0
  148. package/dist/types/BTSChunk.js +5 -0
  149. package/dist/types/Cloneable.d.ts +2 -0
  150. package/dist/types/Cloneable.js +2 -0
  151. package/dist/types/DecodedTemplate.d.ts +7 -0
  152. package/dist/types/DecodedTemplate.js +7 -0
  153. package/dist/types/Element.d.ts +35 -0
  154. package/dist/types/Element.js +5 -0
  155. package/dist/types/ElementTemplateData.d.ts +15 -0
  156. package/dist/types/ElementTemplateData.js +7 -0
  157. package/dist/types/EventType.d.ts +56 -0
  158. package/dist/types/EventType.js +5 -0
  159. package/dist/types/I18nTypes.d.ts +21 -0
  160. package/dist/types/I18nTypes.js +2 -0
  161. package/dist/types/IElementPAPI.d.ts +182 -0
  162. package/dist/types/IElementPAPI.js +2 -0
  163. package/dist/types/IMtsBinding.d.ts +14 -0
  164. package/dist/types/IMtsBinding.js +7 -0
  165. package/dist/types/JSRealm.d.ts +5 -0
  166. package/dist/types/JSRealm.js +7 -0
  167. package/dist/types/LynxContextEventTarget.d.ts +12 -0
  168. package/dist/types/LynxContextEventTarget.js +5 -0
  169. package/dist/types/MainThreadLynx.d.ts +15 -0
  170. package/dist/types/MainThreadLynx.js +2 -0
  171. package/dist/types/NapiModules.d.ts +9 -0
  172. package/dist/types/NapiModules.js +5 -0
  173. package/dist/types/NativeApp.d.ts +120 -0
  174. package/dist/types/NativeApp.js +5 -0
  175. package/dist/types/NativeModules.d.ts +2 -0
  176. package/dist/types/NativeModules.js +5 -0
  177. package/dist/types/PageConfig.d.ts +9 -0
  178. package/dist/types/PageConfig.js +2 -0
  179. package/dist/types/ProcessDataCallback.d.ts +1 -0
  180. package/dist/types/ProcessDataCallback.js +2 -0
  181. package/dist/types/TimingAPIs.d.ts +32 -0
  182. package/dist/types/TimingAPIs.js +5 -0
  183. package/dist/types/UpdateDataOptions.d.ts +8 -0
  184. package/dist/types/UpdateDataOptions.js +6 -0
  185. package/dist/types/WorkerStartMessage.d.ts +14 -0
  186. package/dist/types/WorkerStartMessage.js +5 -0
  187. package/dist/types/index.d.ts +20 -0
  188. package/dist/types/index.js +7 -0
  189. package/eslint.config.js +34 -0
  190. package/package.json +86 -4
  191. package/index.js +0 -1
  192. package/selfIdentity.plist +0 -0
@@ -0,0 +1,12 @@
1
+ // Copyright 2023 The Lynx Authors. All rights reserved.
2
+ // Licensed under the Apache License Version 2.0 that can be found in the
3
+ // LICENSE file in the root directory of this source tree.
4
+ export function createJSObjectDestructionObserver() {
5
+ const registry = new FinalizationRegistry((callback) => callback());
6
+ return (cleanupCallback) => {
7
+ const observedObject = {};
8
+ registry.register(observedObject, cleanupCallback);
9
+ return observedObject;
10
+ };
11
+ }
12
+ //# sourceMappingURL=createJSObjectDestructionObserver.js.map
@@ -0,0 +1,3 @@
1
+ import type { NativeApp } from '../../../../types/index.js';
2
+ import type { Rpc } from '@lynx-js/web-worker-rpc';
3
+ export declare function registerDisposeHandler(rpc: Rpc, nativeApp: NativeApp, destroyCard: typeof import('@lynx-js/lynx-core/web')['destroyCard'], callDestroyLifetimeFun: typeof import('@lynx-js/lynx-core/web')['callDestroyLifetimeFun']): void;
@@ -0,0 +1,9 @@
1
+ import { disposeEndpoint } from '../../../endpoints.js';
2
+ export function registerDisposeHandler(rpc, nativeApp, destroyCard, callDestroyLifetimeFun) {
3
+ rpc.registerHandler(disposeEndpoint, () => {
4
+ const id = nativeApp.id;
5
+ callDestroyLifetimeFun(id);
6
+ destroyCard(id);
7
+ });
8
+ }
9
+ //# sourceMappingURL=registerDisposeHandler.js.map
@@ -0,0 +1,3 @@
1
+ import type { NativeTTObject } from '../../../../types/index.js';
2
+ import type { Rpc } from '@lynx-js/web-worker-rpc';
3
+ export declare function registerPublicComponentEventHandler(rpc: Rpc, tt: NativeTTObject): void;
@@ -0,0 +1,8 @@
1
+ // Copyright 2023 The Lynx Authors. All rights reserved.
2
+ // Licensed under the Apache License Version 2.0 that can be found in the
3
+ // LICENSE file in the root directory of this source tree.
4
+ import { publicComponentEventEndpoint } from '../../../endpoints.js';
5
+ export function registerPublicComponentEventHandler(rpc, tt) {
6
+ rpc.registerHandlerLazy(publicComponentEventEndpoint, tt, 'publicComponentEvent');
7
+ }
8
+ //# sourceMappingURL=registerPublicComponentEventHandler.js.map
@@ -0,0 +1,3 @@
1
+ import type { NativeTTObject } from '../../../../types/index.js';
2
+ import type { Rpc } from '@lynx-js/web-worker-rpc';
3
+ export declare function registerPublishEventHandler(rpc: Rpc, tt: NativeTTObject): void;
@@ -0,0 +1,8 @@
1
+ // Copyright 2023 The Lynx Authors. All rights reserved.
2
+ // Licensed under the Apache License Version 2.0 that can be found in the
3
+ // LICENSE file in the root directory of this source tree.
4
+ import { publishEventEndpoint } from '../../../endpoints.js';
5
+ export function registerPublishEventHandler(rpc, tt) {
6
+ rpc.registerHandlerLazy(publishEventEndpoint, tt, 'publishEvent');
7
+ }
8
+ //# sourceMappingURL=registerPublishEventHandler.js.map
@@ -0,0 +1,3 @@
1
+ import type { NativeTTObject } from '../../../../types/index.js';
2
+ import type { Rpc } from '@lynx-js/web-worker-rpc';
3
+ export declare function registerSendGlobalEventHandler(rpc: Rpc, tt: NativeTTObject): void;
@@ -0,0 +1,10 @@
1
+ // Copyright 2023 The Lynx Authors. All rights reserved.
2
+ // Licensed under the Apache License Version 2.0 that can be found in the
3
+ // LICENSE file in the root directory of this source tree.
4
+ import { sendGlobalEventEndpoint } from '../../../endpoints.js';
5
+ export function registerSendGlobalEventHandler(rpc, tt) {
6
+ rpc.registerHandler(sendGlobalEventEndpoint, (...args) => {
7
+ tt.GlobalEventEmitter.emit(...args);
8
+ });
9
+ }
10
+ //# sourceMappingURL=registerSendGlobalEvent.js.map
@@ -0,0 +1,3 @@
1
+ import type { NativeTTObject } from '../../../../types/index.js';
2
+ import type { Rpc } from '@lynx-js/web-worker-rpc';
3
+ export declare function registerUpdateDataHandler(rpc: Rpc, tt: NativeTTObject): void;
@@ -0,0 +1,5 @@
1
+ import { updateDataEndpoint } from '../../../endpoints.js';
2
+ export function registerUpdateDataHandler(rpc, tt) {
3
+ rpc.registerHandlerLazy(updateDataEndpoint, tt, 'updateCardData');
4
+ }
5
+ //# sourceMappingURL=registerUpdateDataHandler.js.map
@@ -0,0 +1,3 @@
1
+ import type { NativeTTObject } from '../../../../types/index.js';
2
+ import type { Rpc } from '@lynx-js/web-worker-rpc';
3
+ export declare function registerUpdateGlobalPropsHandler(rpc: Rpc, tt: NativeTTObject): void;
@@ -0,0 +1,5 @@
1
+ import { updateGlobalPropsEndpoint } from '../../../endpoints.js';
2
+ export function registerUpdateGlobalPropsHandler(rpc, tt) {
3
+ rpc.registerHandlerLazy(updateGlobalPropsEndpoint, tt, 'updateGlobalProps');
4
+ }
5
+ //# sourceMappingURL=registerUpdateGlobalPropsHandler.js.map
@@ -0,0 +1,3 @@
1
+ import type { II18nResource, NativeTTObject } from '../../../../types/index.js';
2
+ import type { Rpc } from '@lynx-js/web-worker-rpc';
3
+ export declare function registerUpdateI18nResource(mainThreadRpc: Rpc, i18nResource: II18nResource, tt: NativeTTObject): void;
@@ -0,0 +1,9 @@
1
+ import { dispatchI18nResourceEndpoint } from '../../../endpoints.js';
2
+ export function registerUpdateI18nResource(mainThreadRpc, i18nResource, tt) {
3
+ // dispatchI18nResource from mts
4
+ mainThreadRpc.registerHandler(dispatchI18nResourceEndpoint, (data) => {
5
+ i18nResource.setData(data);
6
+ tt.GlobalEventEmitter.emit('onI18nResourceReady', []);
7
+ });
8
+ }
9
+ //# sourceMappingURL=registerUpdateI18nResource.js.map
@@ -0,0 +1,2 @@
1
+ import type { WorkerStartMessage } from '../../../types/WorkerStartMessage.js';
2
+ export declare function startBackgroundThread(startMessage: WorkerStartMessage): void;
@@ -0,0 +1,42 @@
1
+ // Copyright 2023 The Lynx Authors. All rights reserved.
2
+ // Licensed under the Apache License Version 2.0 that can be found in the
3
+ // LICENSE file in the root directory of this source tree.
4
+ import { Rpc } from '@lynx-js/web-worker-rpc';
5
+ import { createBackgroundLynx } from './createBackgroundLynx.js';
6
+ import { createNativeApp } from './createNativeApp.js';
7
+ import { registerDisposeHandler } from './crossThreadHandlers/registerDisposeHandler.js';
8
+ import { BackgroundThreadStartEndpoint } from '../../endpoints.js';
9
+ import { createNapiLoader } from './createNapiLoader.js';
10
+ import { createTimingSystem } from './createTimingSystem.js';
11
+ export function startBackgroundThread(startMessage) {
12
+ const { mainThreadMessagePort, napiModulesMap, nativeModulesMap, initData, globalProps, customSections, cardType, entryTemplateUrl, } = startMessage;
13
+ const mainThreadPort = mainThreadMessagePort;
14
+ const mainThreadRpc = new Rpc(mainThreadPort, 'bg-to-main');
15
+ const timingSystem = createTimingSystem(mainThreadRpc, mainThreadRpc);
16
+ timingSystem.markTimingInternal('load_core_start');
17
+ const nativeApp = createNativeApp(mainThreadRpc, timingSystem, nativeModulesMap, entryTemplateUrl);
18
+ const lynxCore = import(
19
+ /* webpackChunkName: "lynx-core-chunk" */
20
+ '@lynx-js/lynx-core/web');
21
+ const napiLoader = createNapiLoader(mainThreadRpc, napiModulesMap);
22
+ Promise.all([lynxCore, nativeApp, napiLoader]).then(([lynxCore, nativeApp, napiLoader]) => {
23
+ timingSystem.markTimingInternal('load_core_end');
24
+ globalThis['napiLoaderOnRT' + nativeApp.id] = napiLoader;
25
+ const nativeLynx = createBackgroundLynx(globalProps, customSections, nativeApp, mainThreadRpc);
26
+ const { loadCard, destroyCard, callDestroyLifetimeFun, nativeGlobal, loadDynamicComponent, } = lynxCore;
27
+ // @lynx-js/lynx-core >= 0.1.3 will export nativeGlobal and loadDynamicComponent
28
+ if (nativeGlobal && loadDynamicComponent) {
29
+ nativeGlobal.loadDynamicComponent = loadDynamicComponent;
30
+ }
31
+ mainThreadRpc.registerHandler(BackgroundThreadStartEndpoint, () => {
32
+ loadCard(nativeApp, {
33
+ initData,
34
+ cardType,
35
+ // @ts-ignore
36
+ updateData: initData,
37
+ }, nativeLynx);
38
+ });
39
+ registerDisposeHandler(mainThreadRpc, nativeApp, destroyCard, callDestroyLifetimeFun);
40
+ });
41
+ }
42
+ //# sourceMappingURL=startBackgroundThread.js.map
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,15 @@
1
+ import { startBackgroundThread } from './background-apis/startBackgroundThread.js';
2
+ // @ts-expect-error
3
+ globalThis.nativeConsole = console;
4
+ globalThis.onmessage = async (ev) => {
5
+ const message = ev
6
+ .data;
7
+ if (!globalThis.SystemInfo) {
8
+ globalThis.SystemInfo = message.systemInfo;
9
+ }
10
+ startBackgroundThread(message);
11
+ };
12
+ Object.assign(globalThis, {
13
+ module: { exports: null },
14
+ });
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,12 @@
1
+ interface CSSRule {
2
+ sel: string[][][];
3
+ decl: [string, string][];
4
+ }
5
+ interface OneInfo {
6
+ content: string[];
7
+ rules: CSSRule[];
8
+ imports?: string[];
9
+ }
10
+ type StyleInfo = Record<string, OneInfo>;
11
+ export declare function loadStyleFromJSON(styleInfo: StyleInfo, configEnableCSSSelector: boolean, entryName?: string): Uint8Array;
12
+ export {};
@@ -0,0 +1,95 @@
1
+ import { wasmInstance } from '../wasm.js';
2
+ export function loadStyleFromJSON(styleInfo, configEnableCSSSelector, entryName) {
3
+ const rawStyleInfo = new wasmInstance.RawStyleInfo();
4
+ for (const [cssIdStr, info] of Object.entries(styleInfo)) {
5
+ const cssId = parseInt(cssIdStr, 10);
6
+ // Handle imports
7
+ if (info.imports) {
8
+ // imports in StyleInfo are filenames/hrefs, but RawStyleInfo expects cssIds.
9
+ // Wait, genStyleInfo output imports as string hrefs?
10
+ // RawStyleInfo: imports: Vec<i32>
11
+ // It seems genStyleInfo.ts produces imports array of strings, but RawStyleInfo needs integers.
12
+ // If the JSON only contains strings, we might have a problem mapping them back to IDs unless we have a map.
13
+ // However, WebEncodePlugin usually handles mapping.
14
+ // Let's check genStyleInfo again.
15
+ // node.type === 'ImportRule' => imports.push(node.href).
16
+ // If imports are paths, we can't easily convert to ID without extra info.
17
+ // BUT, current usage of imports in RawStyleInfo is strictly ID-based.
18
+ // If the input JSON has hrefs, we might skip imports or error.
19
+ // For now, I will omit imports if they are strings, or try to parse if they look like IDs.
20
+ // Actually, in the ecosystem, imports might not be fully supported in JSON mode yet or resolved differently.
21
+ // I will log or ignore for now, focusing on Rules.
22
+ }
23
+ // Handle rules
24
+ for (const rule of info.rules) {
25
+ const wasmRule = new wasmInstance.Rule('StyleRule');
26
+ // Declarations
27
+ for (const [prop, val] of rule.decl) {
28
+ wasmRule.push_declaration(prop, val);
29
+ }
30
+ // Selectors
31
+ const prelude = new wasmInstance.RulePrelude();
32
+ for (const selectorChain of rule.sel) {
33
+ const selector = new wasmInstance.Selector();
34
+ // Iterate in chunks of 4
35
+ for (let i = 0; i < selectorChain.length; i += 4) {
36
+ const plain = selectorChain[i] || [];
37
+ const pseudoClass = selectorChain[i + 1] || [];
38
+ const pseudoElement = selectorChain[i + 2] || [];
39
+ const combinator = selectorChain[i + 3] || [];
40
+ for (const s of plain) {
41
+ parseAndPushSelector(selector, s);
42
+ }
43
+ for (const s of pseudoClass) {
44
+ // Strip leading :
45
+ const val = s.startsWith(':') ? s.substring(1) : s;
46
+ selector.push_one_selector_section('PseudoClassSelector', val);
47
+ }
48
+ for (const s of pseudoElement) {
49
+ // Strip leading ::
50
+ const val = s.startsWith('::')
51
+ ? s.substring(2)
52
+ : s.startsWith(':')
53
+ ? s.substring(1)
54
+ : s;
55
+ selector.push_one_selector_section('PseudoElementSelector', val);
56
+ }
57
+ if (combinator.length > 0) {
58
+ selector.push_one_selector_section('Combinator', combinator[0]);
59
+ }
60
+ }
61
+ prelude.push_selector(selector);
62
+ }
63
+ wasmRule.set_prelude(prelude);
64
+ rawStyleInfo.push_rule(cssId, wasmRule);
65
+ }
66
+ }
67
+ return wasmInstance.encode_legacy_json_generated_raw_style_info(rawStyleInfo, configEnableCSSSelector, entryName);
68
+ }
69
+ function parseAndPushSelector(selector, s) {
70
+ if (s.startsWith('.')) {
71
+ selector.push_one_selector_section('ClassSelector', s.substring(1));
72
+ }
73
+ else if (s.startsWith('#')) {
74
+ selector.push_one_selector_section('IdSelector', s.substring(1));
75
+ }
76
+ else if (s.startsWith('[')) {
77
+ // Attribute: [attr=val]
78
+ // Remove enclosing []
79
+ const content = s.substring(1, s.length - 1);
80
+ selector.push_one_selector_section('AttributeSelector', content);
81
+ }
82
+ else if (s === '*') {
83
+ selector.push_one_selector_section('UniversalSelector', '*');
84
+ }
85
+ else {
86
+ // Type selector
87
+ // It comes as [lynx-tag="div"] usually.
88
+ let content = s;
89
+ if (s.startsWith('[') && s.endsWith(']')) {
90
+ content = s.substring(1, s.length - 1);
91
+ }
92
+ selector.push_one_selector_section('AttributeSelector', content);
93
+ }
94
+ }
95
+ //# sourceMappingURL=cssLoader.js.map
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,339 @@
1
+ import { TemplateSectionLabel, MagicHeader } from '../../constants.js';
2
+ import { wasmInstance } from '../wasm.js';
3
+ let wasmModuleLoadedResolve;
4
+ const wasmModuleLoadedPromise = new Promise((resolve) => {
5
+ wasmModuleLoadedResolve = resolve;
6
+ });
7
+ import { loadStyleFromJSON } from './cssLoader.js';
8
+ class StreamReader {
9
+ #reader;
10
+ #buffer = new Uint8Array(0);
11
+ constructor(reader) {
12
+ this.#reader = reader;
13
+ }
14
+ async read(size) {
15
+ if (this.#buffer.length >= size) {
16
+ const result = this.#buffer.slice(0, size);
17
+ this.#buffer = this.#buffer.slice(size);
18
+ return result;
19
+ }
20
+ while (this.#buffer.length < size) {
21
+ const { done, value } = await this.#reader.read();
22
+ if (value) {
23
+ const newBuffer = new Uint8Array(this.#buffer.length + value.length);
24
+ newBuffer.set(this.#buffer);
25
+ newBuffer.set(value, this.#buffer.length);
26
+ this.#buffer = newBuffer;
27
+ }
28
+ if (done) {
29
+ break;
30
+ }
31
+ }
32
+ if (this.#buffer.length < size) {
33
+ if (this.#buffer.length === 0) {
34
+ return null;
35
+ }
36
+ throw new Error(`Unexpected end of stream. Expected ${size} bytes, got ${this.#buffer.length}`);
37
+ }
38
+ const result = this.#buffer.slice(0, size);
39
+ this.#buffer = this.#buffer.slice(size);
40
+ return result;
41
+ }
42
+ async readRest() {
43
+ while (true) {
44
+ const { done, value } = await this.#reader.read();
45
+ if (value) {
46
+ const newBuffer = new Uint8Array(this.#buffer.length + value.length);
47
+ newBuffer.set(this.#buffer);
48
+ newBuffer.set(value, this.#buffer.length);
49
+ this.#buffer = newBuffer;
50
+ }
51
+ if (done) {
52
+ break;
53
+ }
54
+ }
55
+ const result = this.#buffer;
56
+ this.#buffer = new Uint8Array(0);
57
+ return result;
58
+ }
59
+ }
60
+ function decodeJSONMap(buffer) {
61
+ const utf16Array = new Uint16Array(buffer.buffer, buffer.byteOffset, buffer.byteLength / 2);
62
+ let jsonString = '';
63
+ const CHUNK_SIZE = 8192;
64
+ for (let i = 0; i < utf16Array.length; i += CHUNK_SIZE) {
65
+ jsonString += String.fromCharCode.apply(null, utf16Array.subarray(i, i + CHUNK_SIZE));
66
+ }
67
+ return JSON.parse(jsonString);
68
+ }
69
+ function decodeBinaryMap(buffer) {
70
+ const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
71
+ let offset = 0;
72
+ if (buffer.byteLength < 4) {
73
+ throw new Error('Buffer too short for count');
74
+ }
75
+ const count = view.getUint32(offset, true);
76
+ offset += 4;
77
+ const result = {};
78
+ const decoder = new TextDecoder();
79
+ for (let i = 0; i < count; i++) {
80
+ if (buffer.byteLength < offset + 4) {
81
+ throw new Error('Buffer too short for key length');
82
+ }
83
+ const keyLen = view.getUint32(offset, true);
84
+ offset += 4;
85
+ if (buffer.byteLength < offset + keyLen) {
86
+ throw new Error('Buffer too short for key');
87
+ }
88
+ const key = decoder.decode(buffer.subarray(offset, offset + keyLen));
89
+ offset += keyLen;
90
+ if (buffer.byteLength < offset + 4) {
91
+ throw new Error('Buffer too short for value length');
92
+ }
93
+ const valLen = view.getUint32(offset, true);
94
+ offset += 4;
95
+ if (buffer.byteLength < offset + valLen) {
96
+ throw new Error('Buffer too short for value');
97
+ }
98
+ const val = buffer.subarray(offset, offset + valLen);
99
+ offset += valLen;
100
+ result[key] = val;
101
+ }
102
+ return result;
103
+ }
104
+ self.onmessage = async (event) => {
105
+ const data = event.data;
106
+ if (data.type === 'init') {
107
+ const { wasmModule } = data;
108
+ wasmInstance.initSync({ module: wasmModule });
109
+ wasmModuleLoadedResolve();
110
+ }
111
+ else if (data.type === 'load') {
112
+ const { url, fetchUrl, overrideConfig } = data;
113
+ try {
114
+ const response = await fetch(fetchUrl, {
115
+ headers: {
116
+ 'Content-Type': 'octet-stream',
117
+ },
118
+ });
119
+ if (!response.body || response.status !== 200) {
120
+ throw new Error(`Failed to fetch template: ${response.statusText}`);
121
+ }
122
+ const reader = response.body.getReader();
123
+ await handleStream(url, reader, overrideConfig);
124
+ postMessage({ type: 'done', url });
125
+ }
126
+ catch (error) {
127
+ postMessage({ type: 'error', url, error: error.message });
128
+ }
129
+ }
130
+ };
131
+ async function handleStream(url, reader, overrideConfig) {
132
+ const streamReader = new StreamReader(reader);
133
+ let config = {};
134
+ // 1. Check MagicHeader
135
+ const headerBytes = await streamReader.read(8);
136
+ if (!headerBytes) {
137
+ throw new Error('Empty stream');
138
+ }
139
+ // Check if JSON (starts with {)
140
+ if (headerBytes[0] === 123) {
141
+ const rest = await streamReader.readRest();
142
+ const decoder = new TextDecoder();
143
+ const jsonStr = decoder.decode(headerBytes) + decoder.decode(rest);
144
+ const json = JSON.parse(jsonStr);
145
+ await handleJSON(json, url, overrideConfig);
146
+ return;
147
+ }
148
+ const view = new DataView(headerBytes.buffer, headerBytes.byteOffset, headerBytes.byteLength);
149
+ const magic = view.getBigUint64(0, true); // Little Endian
150
+ if (magic !== BigInt(MagicHeader)) {
151
+ throw new Error('Invalid Magic Header');
152
+ }
153
+ // 2. Check Version
154
+ const versionBytes = await streamReader.read(4);
155
+ if (!versionBytes) {
156
+ throw new Error('Unexpected EOF reading version');
157
+ }
158
+ const versionView = new DataView(versionBytes.buffer, versionBytes.byteOffset, versionBytes.byteLength);
159
+ const version = versionView.getUint32(0, true);
160
+ if (version > 1) {
161
+ throw new Error(`Unsupported version: ${version}`);
162
+ }
163
+ // 3. Read Sections
164
+ while (true) {
165
+ const labelBytes = await streamReader.read(4);
166
+ if (!labelBytes) {
167
+ break; // EOF
168
+ }
169
+ const labelView = new DataView(labelBytes.buffer, labelBytes.byteOffset, labelBytes.byteLength);
170
+ const label = labelView.getUint32(0, true);
171
+ const lengthBytes = await streamReader.read(4);
172
+ if (!lengthBytes) {
173
+ throw new Error('Unexpected EOF reading section length');
174
+ }
175
+ const lengthView = new DataView(lengthBytes.buffer, lengthBytes.byteOffset, lengthBytes.byteLength);
176
+ const length = lengthView.getUint32(0, true);
177
+ const content = await streamReader.read(length);
178
+ if (!content) {
179
+ throw new Error(`Unexpected EOF reading section content. Expected ${length} bytes.`);
180
+ }
181
+ switch (label) {
182
+ case TemplateSectionLabel.Configurations: {
183
+ config = overrideConfig
184
+ ? { ...decodeJSONMap(content), ...overrideConfig }
185
+ : decodeJSONMap(content);
186
+ postMessage({ type: 'section', label, url, data: config });
187
+ break;
188
+ }
189
+ case TemplateSectionLabel.StyleInfo: {
190
+ await wasmModuleLoadedPromise;
191
+ const buffer = wasmInstance.decode_style_info(content, config['isLazy'] === 'true' ? url : undefined, config['enableCSSSelector'] === 'true');
192
+ postMessage({
193
+ type: 'section',
194
+ label,
195
+ url,
196
+ data: buffer.buffer,
197
+ config,
198
+ }, {
199
+ transfer: [buffer.buffer],
200
+ });
201
+ break;
202
+ }
203
+ case TemplateSectionLabel.LepusCode: {
204
+ const codeMap = decodeBinaryMap(content);
205
+ const isLazy = config['isLazy'] === 'true';
206
+ const blobMap = {};
207
+ for (const [key, code] of Object.entries(codeMap)) {
208
+ const prefix = `(function(){ "use strict"; const navigator=void 0,postMessage=void 0,window=void 0; ${isLazy ? 'module.exports=' : ''} `;
209
+ const suffix = ` \n })()\n//# sourceURL=${url}\n`;
210
+ const blob = new Blob([prefix, code, suffix], {
211
+ type: 'text/javascript; charset=utf-8',
212
+ });
213
+ blobMap[key] = URL.createObjectURL(blob);
214
+ }
215
+ postMessage({ type: 'section', label, url, data: blobMap, config });
216
+ break;
217
+ }
218
+ case TemplateSectionLabel.ElementTemplates: {
219
+ postMessage({ type: 'section', label, url, data: content }, [content.buffer]);
220
+ break;
221
+ }
222
+ case TemplateSectionLabel.CustomSections: {
223
+ postMessage({ type: 'section', label, url, data: content.buffer }, {
224
+ transfer: [content.buffer],
225
+ });
226
+ break;
227
+ }
228
+ case TemplateSectionLabel.Manifest: {
229
+ const codeMap = decodeBinaryMap(content);
230
+ const blobMap = {};
231
+ for (const [key, code] of Object.entries(codeMap)) {
232
+ const suffix = `//# sourceURL=${url}/${key}`;
233
+ const blob = new Blob([code, suffix], {
234
+ type: 'text/javascript; charset=utf-8',
235
+ });
236
+ blobMap[key] = URL.createObjectURL(blob);
237
+ }
238
+ postMessage({ type: 'section', label, url, data: blobMap });
239
+ break;
240
+ }
241
+ default:
242
+ throw new Error(`Unknown section label: ${label}`);
243
+ }
244
+ }
245
+ }
246
+ async function handleJSON(json, url, overrideConfig) {
247
+ // Configurations
248
+ let config = {};
249
+ if (json.pageConfig) {
250
+ config = { ...json.pageConfig };
251
+ }
252
+ if (overrideConfig) {
253
+ config = { ...config, ...overrideConfig };
254
+ }
255
+ config = Object.fromEntries(Object.entries(config).map(([key, value]) => [key, value.toString()]));
256
+ postMessage({
257
+ type: 'section',
258
+ label: TemplateSectionLabel.Configurations,
259
+ url,
260
+ data: config,
261
+ });
262
+ // StyleInfo
263
+ if (json.styleInfo) {
264
+ await wasmModuleLoadedPromise;
265
+ const buffer = loadStyleFromJSON(json.styleInfo, config['enableCSSSelector'] === 'true', config['isLazy'] === 'true' ? url : undefined);
266
+ postMessage({
267
+ type: 'section',
268
+ label: TemplateSectionLabel.StyleInfo,
269
+ url,
270
+ data: buffer.buffer,
271
+ config,
272
+ }, {
273
+ transfer: [buffer.buffer],
274
+ });
275
+ }
276
+ // LepusCode
277
+ if (json.lepusCode) {
278
+ // Flattened structure in json: { root: "...", chunk1: "..." }
279
+ const isLazy = config['isLazy'] === 'true';
280
+ const blobMap = {};
281
+ for (const [key, code] of Object.entries(json.lepusCode)) {
282
+ if (typeof code !== 'string')
283
+ continue;
284
+ const prefix = `(function(){ "use strict"; const navigator=void 0,postMessage=void 0,window=void 0; ${isLazy ? 'module.exports=' : ''} `;
285
+ const suffix = ` \n })()\n//# sourceURL=${url}/${key}\n`;
286
+ const blob = new Blob([prefix, code, suffix], {
287
+ type: 'text/javascript;',
288
+ });
289
+ blobMap[key] = URL.createObjectURL(blob);
290
+ }
291
+ postMessage({
292
+ type: 'section',
293
+ label: TemplateSectionLabel.LepusCode,
294
+ url,
295
+ data: blobMap,
296
+ config,
297
+ });
298
+ }
299
+ // Manifest
300
+ if (json.manifest) {
301
+ const blobMap = {};
302
+ for (const [key, code] of Object.entries(json.manifest)) {
303
+ if (typeof code !== 'string')
304
+ continue;
305
+ const blob = new Blob([code], {
306
+ type: 'text/javascript;',
307
+ });
308
+ blobMap[key] = URL.createObjectURL(blob);
309
+ }
310
+ postMessage({
311
+ type: 'section',
312
+ label: TemplateSectionLabel.Manifest,
313
+ url,
314
+ data: blobMap,
315
+ });
316
+ }
317
+ // CustomSections
318
+ if (json.customSections) {
319
+ // Currently we don't have a way to encode custom sections here.
320
+ // If main thread accepts generic object, we send it.
321
+ // But TemplateManager expects buffer?
322
+ // TemplateManager: case CustomSections: #setCustomSection(url, data). data: any.
323
+ // So passing object is fine!
324
+ postMessage({
325
+ type: 'section',
326
+ label: TemplateSectionLabel.CustomSections,
327
+ url,
328
+ data: json.customSections,
329
+ });
330
+ }
331
+ // ElementTemplates
332
+ if (json.elementTemplates && Object.keys(json.elementTemplates).length > 0) {
333
+ // TemplateManager expects Uint8Array for ElementTemplates.
334
+ // We can't support this easily for JSON.
335
+ throw new Error('ElementTemplates in JSON artifacts are not supported yet.');
336
+ }
337
+ }
338
+ postMessage({ type: 'ready' });
339
+ //# sourceMappingURL=decode.worker.js.map