@lynx-js/web-core-wasm-canary 0.0.0 → 0.0.1-canary-20260116-ff5a5b09

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 (204) hide show
  1. package/CHANGELOG.md +8 -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 +263 -0
  6. package/binary/client/client.js +1339 -0
  7. package/binary/client/client_bg.wasm +0 -0
  8. package/binary/client/client_bg.wasm.d.ts +70 -0
  9. package/binary/client/client_debug.d.ts +263 -0
  10. package/binary/client/client_debug.js +1339 -0
  11. package/binary/client/client_debug_bg.wasm +0 -0
  12. package/binary/client/client_debug_bg.wasm.d.ts +70 -0
  13. package/binary/encode/encode.d.ts +157 -0
  14. package/binary/encode/encode.js +17 -0
  15. package/binary/encode/encode_bg.js +749 -0
  16. package/binary/encode/encode_bg.wasm +0 -0
  17. package/binary/encode/encode_bg.wasm.d.ts +50 -0
  18. package/binary/encode/encode_debug.d.ts +157 -0
  19. package/binary/encode/encode_debug.js +17 -0
  20. package/binary/encode/encode_debug_bg.js +822 -0
  21. package/binary/encode/encode_debug_bg.wasm +0 -0
  22. package/binary/encode/encode_debug_bg.wasm.d.ts +50 -0
  23. package/binary/encode/package.json +4 -0
  24. package/css/in_shadow.css +10 -0
  25. package/css/index.css +119 -0
  26. package/dist/client/LynxCrossThreadContext.d.ts +22 -0
  27. package/dist/client/LynxCrossThreadContext.js +44 -0
  28. package/dist/client/background/background-apis/createBackgroundLynx.d.ts +24 -0
  29. package/dist/client/background/background-apis/createBackgroundLynx.js +38 -0
  30. package/dist/client/background/background-apis/createChunkLoading.d.ts +7 -0
  31. package/dist/client/background/background-apis/createChunkLoading.js +66 -0
  32. package/dist/client/background/background-apis/createElement.d.ts +5 -0
  33. package/dist/client/background/background-apis/createElement.js +18 -0
  34. package/dist/client/background/background-apis/createNapiLoader.d.ts +5 -0
  35. package/dist/client/background/background-apis/createNapiLoader.js +23 -0
  36. package/dist/client/background/background-apis/createNativeApp.d.ts +4 -0
  37. package/dist/client/background/background-apis/createNativeApp.js +98 -0
  38. package/dist/client/background/background-apis/createNativeModules.d.ts +3 -0
  39. package/dist/client/background/background-apis/createNativeModules.js +33 -0
  40. package/dist/client/background/background-apis/createPerformanceApis.d.ts +3 -0
  41. package/dist/client/background/background-apis/createPerformanceApis.js +47 -0
  42. package/dist/client/background/background-apis/createTimingSystem.d.ts +8 -0
  43. package/dist/client/background/background-apis/createTimingSystem.js +86 -0
  44. package/dist/client/background/background-apis/crossThreadHandlers/createGetCustomSection.d.ts +3 -0
  45. package/dist/client/background/background-apis/crossThreadHandlers/createGetCustomSection.js +14 -0
  46. package/dist/client/background/background-apis/crossThreadHandlers/createGetPathInfo.d.ts +3 -0
  47. package/dist/client/background/background-apis/crossThreadHandlers/createGetPathInfo.js +23 -0
  48. package/dist/client/background/background-apis/crossThreadHandlers/createInvokeUIMethod.d.ts +3 -0
  49. package/dist/client/background/background-apis/crossThreadHandlers/createInvokeUIMethod.js +24 -0
  50. package/dist/client/background/background-apis/crossThreadHandlers/createJSObjectDestructionObserver.d.ts +2 -0
  51. package/dist/client/background/background-apis/crossThreadHandlers/createJSObjectDestructionObserver.js +12 -0
  52. package/dist/client/background/background-apis/crossThreadHandlers/registerDisposeHandler.d.ts +3 -0
  53. package/dist/client/background/background-apis/crossThreadHandlers/registerDisposeHandler.js +9 -0
  54. package/dist/client/background/background-apis/crossThreadHandlers/registerPublicComponentEventHandler.d.ts +3 -0
  55. package/dist/client/background/background-apis/crossThreadHandlers/registerPublicComponentEventHandler.js +8 -0
  56. package/dist/client/background/background-apis/crossThreadHandlers/registerPublishEventHandler.d.ts +3 -0
  57. package/dist/client/background/background-apis/crossThreadHandlers/registerPublishEventHandler.js +8 -0
  58. package/dist/client/background/background-apis/crossThreadHandlers/registerSendGlobalEvent.d.ts +3 -0
  59. package/dist/client/background/background-apis/crossThreadHandlers/registerSendGlobalEvent.js +10 -0
  60. package/dist/client/background/background-apis/crossThreadHandlers/registerUpdateDataHandler.d.ts +3 -0
  61. package/dist/client/background/background-apis/crossThreadHandlers/registerUpdateDataHandler.js +5 -0
  62. package/dist/client/background/background-apis/crossThreadHandlers/registerUpdateGlobalPropsHandler.d.ts +3 -0
  63. package/dist/client/background/background-apis/crossThreadHandlers/registerUpdateGlobalPropsHandler.js +5 -0
  64. package/dist/client/background/background-apis/crossThreadHandlers/registerUpdateI18nResource.d.ts +3 -0
  65. package/dist/client/background/background-apis/crossThreadHandlers/registerUpdateI18nResource.js +9 -0
  66. package/dist/client/background/background-apis/startBackgroundThread.d.ts +2 -0
  67. package/dist/client/background/background-apis/startBackgroundThread.js +42 -0
  68. package/dist/client/background/index.d.ts +1 -0
  69. package/dist/client/background/index.js +15 -0
  70. package/dist/client/decodeWorker/cssLoader.d.ts +12 -0
  71. package/dist/client/decodeWorker/cssLoader.js +96 -0
  72. package/dist/client/decodeWorker/decode.worker.d.ts +1 -0
  73. package/dist/client/decodeWorker/decode.worker.js +338 -0
  74. package/dist/client/decodeWorker/types.d.ts +32 -0
  75. package/dist/client/decodeWorker/types.js +2 -0
  76. package/dist/client/endpoints.d.ts +53 -0
  77. package/dist/client/endpoints.js +37 -0
  78. package/dist/client/index.d.ts +3 -0
  79. package/dist/client/index.js +3 -0
  80. package/dist/client/mainthread/Background.d.ts +30 -0
  81. package/dist/client/mainthread/Background.js +207 -0
  82. package/dist/client/mainthread/ExposureServices.d.ts +11 -0
  83. package/dist/client/mainthread/ExposureServices.js +211 -0
  84. package/dist/client/mainthread/I18n.d.ts +9 -0
  85. package/dist/client/mainthread/I18n.js +44 -0
  86. package/dist/client/mainthread/LynxView.d.ts +170 -0
  87. package/dist/client/mainthread/LynxView.js +367 -0
  88. package/dist/client/mainthread/LynxViewInstance.d.ts +56 -0
  89. package/dist/client/mainthread/LynxViewInstance.js +196 -0
  90. package/dist/client/mainthread/StyleManager.d.ts +15 -0
  91. package/dist/client/mainthread/StyleManager.js +72 -0
  92. package/dist/client/mainthread/TemplateManager.d.ts +11 -0
  93. package/dist/client/mainthread/TemplateManager.js +257 -0
  94. package/dist/client/mainthread/createIFrameRealm.d.ts +6 -0
  95. package/dist/client/mainthread/createIFrameRealm.js +68 -0
  96. package/dist/client/mainthread/createMainThreadGlobalAPIs.d.ts +3 -0
  97. package/dist/client/mainthread/createMainThreadGlobalAPIs.js +82 -0
  98. package/dist/client/mainthread/crossThreadHandlers/queryNodes.d.ts +3 -0
  99. package/dist/client/mainthread/crossThreadHandlers/queryNodes.js +74 -0
  100. package/dist/client/mainthread/crossThreadHandlers/registerGetPathInfoHandler.d.ts +3 -0
  101. package/dist/client/mainthread/crossThreadHandlers/registerGetPathInfoHandler.js +51 -0
  102. package/dist/client/mainthread/crossThreadHandlers/registerInvokeUIMethodHandler.d.ts +3 -0
  103. package/dist/client/mainthread/crossThreadHandlers/registerInvokeUIMethodHandler.js +49 -0
  104. package/dist/client/mainthread/crossThreadHandlers/registerNapiModulesCallHandler.d.ts +3 -0
  105. package/dist/client/mainthread/crossThreadHandlers/registerNapiModulesCallHandler.js +8 -0
  106. package/dist/client/mainthread/crossThreadHandlers/registerNativeModulesCallHandler.d.ts +3 -0
  107. package/dist/client/mainthread/crossThreadHandlers/registerNativeModulesCallHandler.js +7 -0
  108. package/dist/client/mainthread/crossThreadHandlers/registerSelectComponentHandler.d.ts +3 -0
  109. package/dist/client/mainthread/crossThreadHandlers/registerSelectComponentHandler.js +20 -0
  110. package/dist/client/mainthread/crossThreadHandlers/registerSetNativePropsHandler.d.ts +3 -0
  111. package/dist/client/mainthread/crossThreadHandlers/registerSetNativePropsHandler.js +28 -0
  112. package/dist/client/mainthread/crossThreadHandlers/registerTriggerComponentEventHandler.d.ts +3 -0
  113. package/dist/client/mainthread/crossThreadHandlers/registerTriggerComponentEventHandler.js +12 -0
  114. package/dist/client/mainthread/crossThreadHandlers/registerTriggerElementMethodEndpointHandler.d.ts +3 -0
  115. package/dist/client/mainthread/crossThreadHandlers/registerTriggerElementMethodEndpointHandler.js +29 -0
  116. package/dist/client/mainthread/elementAPIs/WASMJSBinding.d.ts +38 -0
  117. package/dist/client/mainthread/elementAPIs/WASMJSBinding.js +122 -0
  118. package/dist/client/mainthread/elementAPIs/createCrossThreadEvent.d.ts +2 -0
  119. package/dist/client/mainthread/elementAPIs/createCrossThreadEvent.js +77 -0
  120. package/dist/client/mainthread/elementAPIs/createElementAPI.d.ts +3 -0
  121. package/dist/client/mainthread/elementAPIs/createElementAPI.js +346 -0
  122. package/dist/client/mainthread/elementAPIs/index.d.ts +2 -0
  123. package/dist/client/mainthread/elementAPIs/index.js +3 -0
  124. package/dist/client/mainthread/elementAPIs/pureElementPAPIs.d.ts +26 -0
  125. package/dist/client/mainthread/elementAPIs/pureElementPAPIs.js +85 -0
  126. package/dist/client/mainthread/utils/convertLengthToPx.d.ts +1 -0
  127. package/dist/client/mainthread/utils/convertLengthToPx.js +25 -0
  128. package/dist/client/wasm.d.ts +11 -0
  129. package/dist/client/wasm.js +52 -0
  130. package/dist/client/webElementsDynamicLoader.d.ts +8 -0
  131. package/dist/client/webElementsDynamicLoader.js +80 -0
  132. package/dist/client_prod/static/css/async/web-core-main-chunk.css +1 -0
  133. package/dist/client_prod/static/css/client.css +1 -0
  134. package/dist/client_prod/static/js/async/lynx-core-chunk.js +3 -0
  135. package/dist/client_prod/static/js/async/web-core-main-chunk.js +303 -0
  136. package/dist/client_prod/static/js/async/web-core-template-loader-thread.js +8 -0
  137. package/dist/client_prod/static/js/async/web-core-worker-chunk.js +1 -0
  138. package/dist/client_prod/static/js/async/web-elements-audio.js +1 -0
  139. package/dist/client_prod/static/js/async/web-elements-foldview.js +1 -0
  140. package/dist/client_prod/static/js/async/web-elements-input.js +1 -0
  141. package/dist/client_prod/static/js/async/web-elements-list.js +1 -0
  142. package/dist/client_prod/static/js/async/web-elements-overlay.js +1 -0
  143. package/dist/client_prod/static/js/async/web-elements-refrshview.js +1 -0
  144. package/dist/client_prod/static/js/async/web-elements-swiper.js +1 -0
  145. package/dist/client_prod/static/js/async/web-elements-textarea.js +1 -0
  146. package/dist/client_prod/static/js/async/web-elements-viewpager.js +1 -0
  147. package/dist/client_prod/static/js/client.js +2 -0
  148. package/dist/client_prod/static/wasm/e7da3f5d.module.wasm +0 -0
  149. package/dist/constants.d.ts +58 -0
  150. package/dist/constants.js +114 -0
  151. package/dist/encode/encodeCSS.d.ts +3 -0
  152. package/dist/encode/encodeCSS.js +99 -0
  153. package/dist/encode/encodeElementTemplate.d.ts +2 -0
  154. package/dist/encode/encodeElementTemplate.js +52 -0
  155. package/dist/encode/index.d.ts +1 -0
  156. package/dist/encode/index.js +7 -0
  157. package/dist/encode/webEncoder.d.ts +21 -0
  158. package/dist/encode/webEncoder.js +125 -0
  159. package/dist/types/BTSChunk.d.ts +3 -0
  160. package/dist/types/BTSChunk.js +5 -0
  161. package/dist/types/Cloneable.d.ts +2 -0
  162. package/dist/types/Cloneable.js +2 -0
  163. package/dist/types/DecodedTemplate.d.ts +10 -0
  164. package/dist/types/DecodedTemplate.js +7 -0
  165. package/dist/types/Element.d.ts +35 -0
  166. package/dist/types/Element.js +5 -0
  167. package/dist/types/ElementTemplateData.d.ts +15 -0
  168. package/dist/types/ElementTemplateData.js +7 -0
  169. package/dist/types/EventType.d.ts +56 -0
  170. package/dist/types/EventType.js +5 -0
  171. package/dist/types/I18nTypes.d.ts +21 -0
  172. package/dist/types/I18nTypes.js +2 -0
  173. package/dist/types/IElementPAPI.d.ts +184 -0
  174. package/dist/types/IElementPAPI.js +2 -0
  175. package/dist/types/IMtsBinding.d.ts +11 -0
  176. package/dist/types/IMtsBinding.js +7 -0
  177. package/dist/types/JSRealm.d.ts +5 -0
  178. package/dist/types/JSRealm.js +7 -0
  179. package/dist/types/LynxContextEventTarget.d.ts +12 -0
  180. package/dist/types/LynxContextEventTarget.js +5 -0
  181. package/dist/types/MainThreadLynx.d.ts +15 -0
  182. package/dist/types/MainThreadLynx.js +2 -0
  183. package/dist/types/NapiModules.d.ts +9 -0
  184. package/dist/types/NapiModules.js +5 -0
  185. package/dist/types/NativeApp.d.ts +120 -0
  186. package/dist/types/NativeApp.js +5 -0
  187. package/dist/types/NativeModules.d.ts +2 -0
  188. package/dist/types/NativeModules.js +5 -0
  189. package/dist/types/PageConfig.d.ts +9 -0
  190. package/dist/types/PageConfig.js +2 -0
  191. package/dist/types/ProcessDataCallback.d.ts +1 -0
  192. package/dist/types/ProcessDataCallback.js +2 -0
  193. package/dist/types/TimingAPIs.d.ts +32 -0
  194. package/dist/types/TimingAPIs.js +5 -0
  195. package/dist/types/UpdateDataOptions.d.ts +8 -0
  196. package/dist/types/UpdateDataOptions.js +6 -0
  197. package/dist/types/WorkerStartMessage.d.ts +14 -0
  198. package/dist/types/WorkerStartMessage.js +5 -0
  199. package/dist/types/index.d.ts +20 -0
  200. package/dist/types/index.js +7 -0
  201. package/eslint.config.js +34 -0
  202. package/package.json +87 -4
  203. package/index.js +0 -1
  204. package/selfIdentity.plist +0 -0
@@ -0,0 +1,367 @@
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 { lynxDisposedAttribute } from '../../constants.js';
5
+ import { createIFrameRealm } from './createIFrameRealm.js';
6
+ import { templateManager } from './TemplateManager.js';
7
+ import(
8
+ /* webpackChunkName: "web-core-main-chunk" */
9
+ /* webpackFetchPriority: "high" */
10
+ './LynxViewInstance.js');
11
+ /**
12
+ * Based on our experiences, these elements are almost used in all lynx cards.
13
+ */
14
+ /**
15
+ * @property {string} url [required] (attribute: "url") The url of the entry of your Lynx card
16
+ * @property {Cloneable} globalProps [optional] (attribute: "global-props") The globalProps value of this Lynx card
17
+ * @property {Cloneable} initData [optional] (attribute: "init-data") The initial data of this Lynx card
18
+ * @property {Record<string,string>} overrideLynxTagToHTMLTagMap [optional] use this property/attribute to override the lynx tag -> html tag map
19
+ * @property {NativeModulesMap} nativeModulesMap [optional] use to customize NativeModules. key is module-name, value is esm url.
20
+ * @property {NativeModulesCall} onNativeModulesCall [optional] the NativeModules value handler. Arguments will be cached before this property is assigned.
21
+ * @property {"auto" | null} height [optional] (attribute: "height") set it to "auto" for height auto-sizing
22
+ * @property {"auto" | null} width [optional] (attribute: "width") set it to "auto" for width auto-sizing
23
+ * @property {NapiModulesMap} napiModulesMap [optional] the napiModule which is called in lynx-core. key is module-name, value is esm url.
24
+ * @property {INapiModulesCall} onNapiModulesCall [optional] the NapiModule value handler.
25
+ * @property {string[]} injectStyleRules [optional] the css rules which will be injected into shadowroot. Each items will be inserted by `insertRule` method. @see https://developer.mozilla.org/docs/Web/API/CSSStyleSheet/insertRule
26
+ * @property {number} lynxGroupId [optional] (attribute: "lynx-group-id") the background shared context id, which is used to share webworker between different lynx cards
27
+ * @property {(string)=>Promise<LynxTemplate>} customTemplateLoader [optional] the custom template loader, which is used to load the template
28
+ * @property {InitI18nResources} initI18nResources [optional] (attribute: "init-i18n-resources") the complete set of i18nResources that on the container side, which can be obtained synchronously by _I18nResourceTranslation
29
+ *
30
+ * @event error lynx card fired an error
31
+ * @event i18nResourceMissed i18n resource cache miss
32
+ *
33
+ * @example
34
+ * HTML Example
35
+ *
36
+ * Note that you should declarae the size of lynx-view
37
+ *
38
+ * ```html
39
+ * <lynx-view url="https://path/to/main-thread.js" raw-data="{}" global-props="{}" style="height:300px;width:300px">
40
+ * </lynx-view>
41
+ * ```
42
+ *
43
+ * React 19 Example
44
+ * ```jsx
45
+ * <lynx-view url={myLynxCardUrl} rawData={{}} globalProps={{}} style={{height:'300px', width:'300px'}}>
46
+ * </lynx-view>
47
+ * ```
48
+ */
49
+ export class LynxViewElement extends HTMLElement {
50
+ static lynxViewCount = 0;
51
+ static tag = 'lynx-view';
52
+ static observedAttributeAsProperties = [
53
+ 'url',
54
+ 'global-props',
55
+ 'init-data',
56
+ ];
57
+ /**
58
+ * @private
59
+ */
60
+ static observedAttributes = LynxViewElement.observedAttributeAsProperties.map(nm => nm.toLowerCase());
61
+ #instance;
62
+ #connected = false;
63
+ #url;
64
+ /**
65
+ * @public
66
+ * @property nativeModulesMap
67
+ * @default {}
68
+ */
69
+ nativeModulesMap;
70
+ /**
71
+ * @param
72
+ * @property napiModulesMap
73
+ * @default {}
74
+ */
75
+ napiModulesMap;
76
+ /**
77
+ * @param
78
+ * @property
79
+ */
80
+ onNapiModulesCall;
81
+ constructor() {
82
+ super();
83
+ if (!this.onNativeModulesCall) {
84
+ this.onNativeModulesCall = (name, data, moduleName) => {
85
+ return new Promise((resolve) => {
86
+ this.#cachedNativeModulesCall.push({
87
+ args: [name, data, moduleName],
88
+ resolve,
89
+ });
90
+ });
91
+ };
92
+ }
93
+ }
94
+ /**
95
+ * @public
96
+ * @property the url of lynx view output entry file
97
+ */
98
+ get url() {
99
+ return this.#url;
100
+ }
101
+ set url(val) {
102
+ this.#url = val;
103
+ this.#render();
104
+ }
105
+ #globalProps = {};
106
+ /**
107
+ * @public
108
+ * @property globalProps
109
+ * @default {}
110
+ */
111
+ get globalProps() {
112
+ return this.#globalProps;
113
+ }
114
+ set globalProps(val) {
115
+ if (typeof val === 'string') {
116
+ this.#globalProps = JSON.parse(val);
117
+ }
118
+ else {
119
+ this.#globalProps = val;
120
+ }
121
+ }
122
+ #initData = {};
123
+ /**
124
+ * @public
125
+ * @property initData
126
+ * @default {}
127
+ */
128
+ get initData() {
129
+ return this.#initData;
130
+ }
131
+ set initData(val) {
132
+ if (typeof val === 'string') {
133
+ this.#initData = JSON.parse(val);
134
+ }
135
+ else {
136
+ this.#initData = val;
137
+ }
138
+ }
139
+ #initI18nResources = [];
140
+ /**
141
+ * @public
142
+ * @property initI18nResources
143
+ * @default {}
144
+ */
145
+ get initI18nResources() {
146
+ return this.#initI18nResources;
147
+ }
148
+ set initI18nResources(val) {
149
+ if (typeof val === 'string') {
150
+ this.#initI18nResources = JSON.parse(val);
151
+ }
152
+ else {
153
+ this.#initI18nResources = val;
154
+ }
155
+ }
156
+ /**
157
+ * @public
158
+ * @method
159
+ * update the `__initData` and trigger essential flow
160
+ */
161
+ updateI18nResources(data, options) {
162
+ this.#instance?.i18nManager.updateData(data, options);
163
+ }
164
+ #overrideLynxTagToHTMLTagMap = {
165
+ 'page': 'div',
166
+ };
167
+ /**
168
+ * @public
169
+ * @property
170
+ * @default {page: 'div'}
171
+ */
172
+ get overrideLynxTagToHTMLTagMap() {
173
+ return this.#overrideLynxTagToHTMLTagMap;
174
+ }
175
+ set overrideLynxTagToHTMLTagMap(val) {
176
+ if (typeof val === 'string') {
177
+ this.#overrideLynxTagToHTMLTagMap = JSON.parse(val);
178
+ }
179
+ else {
180
+ this.#overrideLynxTagToHTMLTagMap = val;
181
+ }
182
+ }
183
+ #cachedNativeModulesCall = [];
184
+ #onNativeModulesCall;
185
+ /**
186
+ * @param
187
+ * @property
188
+ */
189
+ get onNativeModulesCall() {
190
+ return this.#onNativeModulesCall;
191
+ }
192
+ set onNativeModulesCall(handler) {
193
+ this.#onNativeModulesCall = handler;
194
+ for (const callInfo of this.#cachedNativeModulesCall) {
195
+ callInfo.resolve(handler.apply(undefined, callInfo.args));
196
+ }
197
+ this.#cachedNativeModulesCall = [];
198
+ }
199
+ /**
200
+ * @param
201
+ * @property
202
+ */
203
+ get lynxGroupId() {
204
+ return this.getAttribute('lynx-group-id')
205
+ ? Number(this.getAttribute('lynx-group-id'))
206
+ : undefined;
207
+ }
208
+ set lynxGroupId(val) {
209
+ if (val) {
210
+ this.setAttribute('lynx-group-id', val.toString());
211
+ }
212
+ else {
213
+ this.removeAttribute('lynx-group-id');
214
+ }
215
+ }
216
+ /**
217
+ * @public
218
+ * @method
219
+ * update the `__initData` and trigger essential flow
220
+ */
221
+ updateData(data, processorName, callback) {
222
+ this.#instance?.updateData(data, processorName).then(() => {
223
+ callback?.();
224
+ });
225
+ }
226
+ /**
227
+ * @public
228
+ * @method
229
+ * update the `__globalProps`
230
+ */
231
+ updateGlobalProps(data) {
232
+ this.#instance?.updateGlobalProps(data);
233
+ this.globalProps = data;
234
+ }
235
+ /**
236
+ * @public
237
+ * @method
238
+ * send global events, which can be listened to using the GlobalEventEmitter
239
+ */
240
+ sendGlobalEvent(eventName, params) {
241
+ this.#instance?.backgroundThread.sendGlobalEvent(eventName, params);
242
+ }
243
+ /**
244
+ * @public
245
+ * @method
246
+ * reload the current page
247
+ */
248
+ reload() {
249
+ this.removeAttribute('ssr');
250
+ this.#render();
251
+ }
252
+ /**
253
+ * @override
254
+ * "false" value will be omitted
255
+ *
256
+ * {@inheritdoc HTMLElement.setAttribute}
257
+ */
258
+ setAttribute(qualifiedName, value) {
259
+ if (value === 'false') {
260
+ this.removeAttribute(qualifiedName);
261
+ }
262
+ else {
263
+ super.setAttribute(qualifiedName, value);
264
+ }
265
+ }
266
+ /**
267
+ * @private
268
+ */
269
+ attributeChangedCallback(name, oldValue, newValue) {
270
+ if (oldValue !== newValue) {
271
+ switch (name) {
272
+ case 'url':
273
+ this.#url = newValue;
274
+ break;
275
+ case 'global-props':
276
+ this.#globalProps = JSON.parse(newValue);
277
+ break;
278
+ case 'init-data':
279
+ this.#initData = JSON.parse(newValue);
280
+ break;
281
+ }
282
+ }
283
+ }
284
+ injectStyleRules;
285
+ /**
286
+ * @private
287
+ */
288
+ disconnectedCallback() {
289
+ /* TODO:
290
+ * Await async disposal before re-rendering to prevent concurrent instance mutations.
291
+
292
+ Currently disconnectedCallback() triggers asyncDispose() without awaiting, allowing #render() to immediately create a new instance while the old one is still cleaning up on the background thread. This causes both instances to render into the shadowRoot concurrently, producing multiple page elements.
293
+
294
+ The basic-reload-page-only-one test confirms this issue by checking that exactly one page element exists after reload. The disposal must complete before the new instance begins rendering.
295
+
296
+ Extract an async #disposeInstance() method that marks the old page as disposed, awaits the instance cleanup, clears the shadowRoot, and resets adoptedStyleSheets to prevent stylesheet accumulation. Then await this in the microtask before instantiating the new LynxViewInstance.
297
+
298
+ This also fixes a secondary bug where lynxGroupId is referenced before declaration.
299
+ */
300
+ this.shadowRoot?.querySelector('[part="page"]')
301
+ ?.setAttribute(lynxDisposedAttribute, '');
302
+ this.#instance?.[Symbol.asyncDispose]();
303
+ if (this.shadowRoot) {
304
+ this.shadowRoot.innerHTML = '';
305
+ }
306
+ this.#instance = undefined;
307
+ }
308
+ /**
309
+ * @#the flag to group all changes into one render operation
310
+ */
311
+ #rendering = false;
312
+ /**
313
+ * @private
314
+ */
315
+ #render() {
316
+ if (!this.#rendering && this.#connected) {
317
+ this.#rendering = true;
318
+ if (!this.shadowRoot) {
319
+ this.attachShadow({ mode: 'open' });
320
+ }
321
+ if (this.#instance) {
322
+ this.disconnectedCallback();
323
+ }
324
+ const mtsRealmPromise = createIFrameRealm(this.shadowRoot);
325
+ queueMicrotask(async () => {
326
+ if (this.injectStyleRules && this.injectStyleRules.length > 0) {
327
+ const styleSheet = new CSSStyleSheet();
328
+ for (const rule of this.injectStyleRules) {
329
+ styleSheet.insertRule(rule);
330
+ }
331
+ this.shadowRoot.adoptedStyleSheets = this.shadowRoot
332
+ .adoptedStyleSheets.concat(styleSheet);
333
+ }
334
+ const mtsRealm = await mtsRealmPromise;
335
+ if (this.#url) {
336
+ const lynxViewInstance = import(
337
+ /* webpackChunkName: "web-core-main-chunk" */
338
+ /* webpackFetchPriority: "high" */
339
+ './LynxViewInstance.js').then(({ LynxViewInstance }) => {
340
+ return new LynxViewInstance(this, this.initData, this.globalProps, this.#url, this.shadowRoot, mtsRealm, lynxGroupId, this.nativeModulesMap, this.napiModulesMap, this.#initI18nResources);
341
+ });
342
+ templateManager.fetchBundle(this.#url, lynxViewInstance);
343
+ const lynxGroupId = this.lynxGroupId;
344
+ this.#instance = await lynxViewInstance;
345
+ this.#rendering = false;
346
+ }
347
+ });
348
+ }
349
+ }
350
+ /**
351
+ * @private
352
+ */
353
+ connectedCallback() {
354
+ if (this.url) {
355
+ this.#url = this.url;
356
+ }
357
+ this.#connected = true;
358
+ this.#render();
359
+ }
360
+ }
361
+ if (customElements.get(LynxViewElement.tag)) {
362
+ console.error(`[${LynxViewElement.tag}] has already been defined`);
363
+ }
364
+ else {
365
+ customElements.define(LynxViewElement.tag, LynxViewElement);
366
+ }
367
+ //# sourceMappingURL=LynxView.js.map
@@ -0,0 +1,56 @@
1
+ import type { Cloneable, InitI18nResources, JSRealm, MainThreadGlobalThis, NapiModulesMap, NativeModulesMap, PageConfig } from '../../types/index.js';
2
+ import type { DecodedStyle } from '../wasm.js';
3
+ import { BackgroundThread } from './Background.js';
4
+ import { I18nManager } from './I18n.js';
5
+ import { WASMJSBinding } from './elementAPIs/WASMJSBinding.js';
6
+ import { ExposureServices } from './ExposureServices.js';
7
+ import type { LynxViewElement } from './LynxView.js';
8
+ import { StyleManager } from './StyleManager.js';
9
+ export declare const systemInfo: Readonly<{
10
+ pixelRatio: number;
11
+ pixelWidth: number;
12
+ pixelHeight: number;
13
+ }>;
14
+ export interface LynxViewConfigs {
15
+ templateUrl: string;
16
+ initData: Cloneable;
17
+ globalProps: Cloneable;
18
+ shadowRoot: ShadowRoot;
19
+ nativeModulesMap: NativeModulesMap;
20
+ napiModulesMap: NapiModulesMap;
21
+ tagMap: Record<string, string>;
22
+ lynxGroupId: number | undefined;
23
+ initI18nResources: InitI18nResources;
24
+ }
25
+ export declare class LynxViewInstance implements AsyncDisposable {
26
+ #private;
27
+ readonly parentDom: LynxViewElement;
28
+ readonly initData: Cloneable;
29
+ readonly globalprops: Cloneable;
30
+ readonly templateUrl: string;
31
+ readonly rootDom: ShadowRoot;
32
+ readonly mtsRealm: JSRealm;
33
+ readonly mainThreadGlobalThis: MainThreadGlobalThis;
34
+ readonly mtsWasmBinding: WASMJSBinding;
35
+ readonly backgroundThread: BackgroundThread;
36
+ readonly i18nManager: I18nManager;
37
+ readonly exposureServices: ExposureServices;
38
+ readonly webElementsLoadingPromises: Promise<void>[];
39
+ readonly styleReadyPromise: Promise<void>;
40
+ readonly styleReadyResolve: () => void;
41
+ styleManager?: StyleManager;
42
+ lepusCodeUrls: Map<string, Record<string, string>>;
43
+ constructor(parentDom: LynxViewElement, initData: Cloneable, globalprops: Cloneable, templateUrl: string, rootDom: ShadowRoot, mtsRealm: JSRealm, lynxGroupId: number | undefined, nativeModulesMap?: NativeModulesMap, napiModulesMap?: NapiModulesMap, initI18nResources?: InitI18nResources);
44
+ onPageConfigReady(config: PageConfig): void;
45
+ onStyleInfoReady(styleInfo: DecodedStyle, currentUrl: string): void;
46
+ onMTSScriptsLoaded(currentUrl: string, isLazy: boolean): void;
47
+ onMTSScriptsExecuted(): Promise<void>;
48
+ onBTSScriptsLoaded(url: string): Promise<void>;
49
+ loadWebElement(id: number): void;
50
+ loadUnknownElement(tagName: string): void;
51
+ queryComponent(url: string): Promise<unknown>;
52
+ updateData(data: Cloneable, processorName?: string): Promise<void>;
53
+ updateGlobalProps(data: Cloneable): Promise<void>;
54
+ reportError(error: Error, release: string, fileName: string): void;
55
+ [Symbol.asyncDispose](): Promise<void>;
56
+ }
@@ -0,0 +1,196 @@
1
+ import { loadUnknownElementEventName, systemInfoBase, } from '../../constants.js';
2
+ import { BackgroundThread } from './Background.js';
3
+ import { I18nManager } from './I18n.js';
4
+ import { WASMJSBinding } from './elementAPIs/WASMJSBinding.js';
5
+ import { ExposureServices } from './ExposureServices.js';
6
+ import { createElementAPI } from './elementAPIs/createElementAPI.js';
7
+ import { createMainThreadGlobalAPIs } from './createMainThreadGlobalAPIs.js';
8
+ import { templateManager } from './TemplateManager.js';
9
+ import { loadAllWebElements, loadWebElement, } from '../webElementsDynamicLoader.js';
10
+ import { StyleManager } from './StyleManager.js';
11
+ const pixelRatio = window.devicePixelRatio;
12
+ const screenWidth = window.screen.availWidth * pixelRatio;
13
+ const screenHeight = window.screen.availHeight * pixelRatio;
14
+ export const systemInfo = Object.freeze({
15
+ ...systemInfoBase,
16
+ // some information only available on main thread, we should read and pass to worker
17
+ pixelRatio,
18
+ pixelWidth: screenWidth,
19
+ pixelHeight: screenHeight,
20
+ });
21
+ export class LynxViewInstance {
22
+ parentDom;
23
+ initData;
24
+ globalprops;
25
+ templateUrl;
26
+ rootDom;
27
+ mtsRealm;
28
+ mainThreadGlobalThis;
29
+ mtsWasmBinding;
30
+ backgroundThread;
31
+ i18nManager;
32
+ exposureServices;
33
+ webElementsLoadingPromises = [];
34
+ styleReadyPromise;
35
+ styleReadyResolve;
36
+ styleManager;
37
+ #renderPageFunction = null;
38
+ #queryComponentCache = new Map();
39
+ #pageConfig;
40
+ #nativeModulesMap;
41
+ #napiModulesMap;
42
+ lepusCodeUrls = new Map();
43
+ constructor(parentDom, initData, globalprops, templateUrl, rootDom, mtsRealm, lynxGroupId, nativeModulesMap = {}, napiModulesMap = {}, initI18nResources) {
44
+ this.parentDom = parentDom;
45
+ this.initData = initData;
46
+ this.globalprops = globalprops;
47
+ this.templateUrl = templateUrl;
48
+ this.rootDom = rootDom;
49
+ this.mtsRealm = mtsRealm;
50
+ this.#nativeModulesMap = nativeModulesMap;
51
+ this.#napiModulesMap = napiModulesMap;
52
+ let resolve;
53
+ const promise = new Promise((res) => {
54
+ resolve = res;
55
+ });
56
+ this.styleReadyPromise = promise;
57
+ this.styleReadyResolve = resolve;
58
+ this.parentDom.style.display = 'none';
59
+ this.mainThreadGlobalThis = mtsRealm.globalWindow;
60
+ this.backgroundThread = new BackgroundThread(lynxGroupId, this);
61
+ this.i18nManager = new I18nManager(this.backgroundThread, this.rootDom, initI18nResources);
62
+ this.mtsWasmBinding = new WASMJSBinding(this);
63
+ this.exposureServices = new ExposureServices(this);
64
+ this.backgroundThread.markTiming('create_lynx_start');
65
+ }
66
+ onPageConfigReady(config) {
67
+ if (this.#pageConfig) {
68
+ return;
69
+ }
70
+ // create element APIs
71
+ this.#pageConfig = config;
72
+ const enableCSSSelector = config['enableCSSSelector'] == 'true';
73
+ const defaultDisplayLinear = config['defaultDisplayLinear'] == 'true';
74
+ const defaultOverflowVisible = config['defaultOverflowVisible'] == 'true';
75
+ this.styleManager = new StyleManager(this.rootDom);
76
+ Object.assign(this.mtsRealm.globalWindow, createElementAPI(this.templateUrl, this.rootDom, this.mtsWasmBinding, enableCSSSelector, defaultDisplayLinear, defaultOverflowVisible), createMainThreadGlobalAPIs(this));
77
+ Object.defineProperty(this.mainThreadGlobalThis, 'renderPage', {
78
+ get: () => {
79
+ return this.#renderPageFunction;
80
+ },
81
+ set: (v) => {
82
+ this.#renderPageFunction = v;
83
+ this.onMTSScriptsExecuted();
84
+ },
85
+ configurable: true,
86
+ enumerable: true,
87
+ });
88
+ }
89
+ onStyleInfoReady(styleInfo, currentUrl) {
90
+ this.styleManager?.pushStyleSheet(styleInfo, currentUrl === this.templateUrl ? undefined : currentUrl);
91
+ this.parentDom.style.display = 'flex';
92
+ this.styleReadyResolve();
93
+ }
94
+ onMTSScriptsLoaded(currentUrl, isLazy) {
95
+ this.backgroundThread.markTiming('lepus_execute_start');
96
+ const urlMap = templateManager.getTemplate(currentUrl)
97
+ ?.lepusCode;
98
+ this.lepusCodeUrls.set(currentUrl, urlMap);
99
+ if (!isLazy) {
100
+ this.mtsRealm.loadScript(urlMap['root']);
101
+ }
102
+ }
103
+ async onMTSScriptsExecuted() {
104
+ this.backgroundThread.markTiming('lepus_execute_end');
105
+ if (!templateManager.getTemplate(this.templateUrl)?.elementTemplates) {
106
+ this.webElementsLoadingPromises.push(loadAllWebElements());
107
+ }
108
+ await Promise.all([
109
+ ...this.webElementsLoadingPromises,
110
+ this.styleReadyPromise,
111
+ ]);
112
+ this.webElementsLoadingPromises.length = 0;
113
+ this.backgroundThread.markTiming('data_processor_start');
114
+ const processedData = this.mainThreadGlobalThis.processData
115
+ ? this.mainThreadGlobalThis.processData?.(this.initData)
116
+ : this.initData;
117
+ this.backgroundThread.markTiming('data_processor_end');
118
+ this.backgroundThread.startWebWorker(processedData, this.globalprops, templateManager.getTemplate(this.templateUrl).config.cardType, templateManager.getTemplate(this.templateUrl)?.customSections, this.#nativeModulesMap, this.#napiModulesMap);
119
+ this.#renderPageFunction?.(processedData);
120
+ this.mainThreadGlobalThis.__FlushElementTree();
121
+ }
122
+ async onBTSScriptsLoaded(url) {
123
+ const btsUrls = templateManager.getTemplate(url)
124
+ ?.backgroundCode;
125
+ await this.backgroundThread.updateBTSChunk(url, btsUrls);
126
+ this.backgroundThread.startBTS();
127
+ }
128
+ loadWebElement(id) {
129
+ const loadPromise = loadWebElement(id);
130
+ if (loadPromise) {
131
+ this.webElementsLoadingPromises.push(loadPromise);
132
+ }
133
+ }
134
+ loadUnknownElement(tagName) {
135
+ if (tagName.includes('-') && !customElements.get(tagName)) {
136
+ this.rootDom.dispatchEvent(new CustomEvent(loadUnknownElementEventName, {
137
+ detail: {
138
+ tagName,
139
+ },
140
+ }));
141
+ this.webElementsLoadingPromises.push(customElements.whenDefined(tagName).then(() => { }));
142
+ }
143
+ }
144
+ queryComponent(url) {
145
+ if (this.#queryComponentCache.has(url)) {
146
+ return this.#queryComponentCache.get(url);
147
+ }
148
+ const promise = templateManager.fetchBundle(url, Promise.resolve(this), {
149
+ enableCSSSelector: this.#pageConfig['enableCSSSelector'],
150
+ })
151
+ .then(async () => {
152
+ const urlMap = this.lepusCodeUrls.get(url);
153
+ const rootUrl = urlMap?.['root'];
154
+ if (!rootUrl) {
155
+ throw new Error(`[lynx-web] Missing root URL for component: ${url}`);
156
+ }
157
+ let lepusRootChunkExport = await this.mtsRealm.loadScript(rootUrl);
158
+ lepusRootChunkExport = this.mainThreadGlobalThis.processEvalResult?.(lepusRootChunkExport, url);
159
+ return lepusRootChunkExport;
160
+ });
161
+ this.#queryComponentCache.set(url, promise);
162
+ return promise;
163
+ }
164
+ async updateData(data, processorName) {
165
+ const processedData = this.mainThreadGlobalThis.processData
166
+ ? this.mainThreadGlobalThis.processData(data, processorName)
167
+ : data;
168
+ this.mainThreadGlobalThis.updatePage?.(processedData, { processorName });
169
+ await this.backgroundThread.updateData(processedData, { processorName });
170
+ }
171
+ async updateGlobalProps(data) {
172
+ await this.backgroundThread.updateGlobalProps(data);
173
+ }
174
+ reportError(error, release, fileName) {
175
+ this.rootDom.dispatchEvent(new CustomEvent('error', {
176
+ detail: {
177
+ sourceMap: {
178
+ offset: {
179
+ line: 2,
180
+ col: 0,
181
+ },
182
+ },
183
+ error,
184
+ release,
185
+ fileName,
186
+ },
187
+ bubbles: true,
188
+ cancelable: true,
189
+ composed: true,
190
+ }));
191
+ }
192
+ async [Symbol.asyncDispose]() {
193
+ await this.backgroundThread[Symbol.asyncDispose]();
194
+ }
195
+ }
196
+ //# sourceMappingURL=LynxViewInstance.js.map
@@ -0,0 +1,15 @@
1
+ import type { DecodedStyle } from '../wasm.js';
2
+ /**
3
+ * There are two modes to manage styles:
4
+ * 1. CSS Selector mode: styles are injected into a <style>, the style manager won't keep track of which styles are applied to which elements.
5
+ * The browser's native CSS selector engine will handle the style application.
6
+ * 2. Non-CSS Selector mode: styles are managed by the style manager, which keeps track of which styles are applied to which elements.
7
+ * The style manager will inject styles into the style sheet of a <style> element. All classes is calculated
8
+ * based on entry_name, css_id, class_name, and applied by using [unique-id="x"] selectors.
9
+ */
10
+ export declare class StyleManager {
11
+ #private;
12
+ constructor(rootNode: Node);
13
+ updateCssOgStyle(uniqueId: number, cssId: number, classNames: DOMTokenList, entryName?: string): void;
14
+ pushStyleSheet(decodedStyle: DecodedStyle, entryName?: string): void;
15
+ }