@lynx-js/web-core-server 0.15.7 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @lynx-js/web-core-server
2
2
 
3
+ ## 0.16.0
4
+
5
+ ### Minor Changes
6
+
7
+ - refactor: provide the mts a real globalThis ([#1589](https://github.com/lynx-family/lynx-stack/pull/1589))
8
+
9
+ Before this change, We create a function wrapper and a fake globalThis for Javascript code.
10
+
11
+ This caused some issues.
12
+
13
+ After this change, we will create an iframe for createing an isolated Javascript context.
14
+
15
+ This means the globalThis will be the real one.
16
+
3
17
  ## 0.15.7
4
18
 
5
19
  ## 0.15.6
package/dist/index.js CHANGED
@@ -1,19 +1,21 @@
1
1
  import node_os from "node:os";
2
2
  import promises from "node:fs/promises";
3
3
  import node_path from "node:path";
4
+ import node_vm from "node:vm";
5
+ import node_fs from "node:fs";
4
6
  var __webpack_modules__ = {
5
7
  "../web-style-transformer/dist/standard.js": function(module, __webpack_exports__, __webpack_require__) {
6
8
  __webpack_require__.a(module, async function(__webpack_handle_async_dependencies__, __webpack_async_result__) {
7
9
  try {
8
10
  __webpack_require__.d(__webpack_exports__, {
9
- C2: ()=>_standard_bg_js__WEBPACK_IMPORTED_MODULE_0__.C2,
10
- Or: ()=>_standard_bg_js__WEBPACK_IMPORTED_MODULE_0__.Or,
11
- a9: ()=>_standard_bg_js__WEBPACK_IMPORTED_MODULE_0__.a9,
12
- h4: ()=>_standard_bg_js__WEBPACK_IMPORTED_MODULE_0__.h4,
13
- oT: ()=>_standard_bg_js__WEBPACK_IMPORTED_MODULE_0__.oT,
14
- pE: ()=>_standard_bg_js__WEBPACK_IMPORTED_MODULE_0__.pE,
15
- xJ: ()=>_standard_bg_js__WEBPACK_IMPORTED_MODULE_0__.xJ,
16
- xQ: ()=>_standard_bg_js__WEBPACK_IMPORTED_MODULE_0__.xQ
11
+ M2: ()=>_standard_bg_js__WEBPACK_IMPORTED_MODULE_0__.M2,
12
+ Qn: ()=>_standard_bg_js__WEBPACK_IMPORTED_MODULE_0__.Qn,
13
+ aC: ()=>_standard_bg_js__WEBPACK_IMPORTED_MODULE_0__.aC,
14
+ bL: ()=>_standard_bg_js__WEBPACK_IMPORTED_MODULE_0__.bL,
15
+ iG: ()=>_standard_bg_js__WEBPACK_IMPORTED_MODULE_0__.iG,
16
+ lI: ()=>_standard_bg_js__WEBPACK_IMPORTED_MODULE_0__.lI,
17
+ tZ: ()=>_standard_bg_js__WEBPACK_IMPORTED_MODULE_0__.tZ,
18
+ yc: ()=>_standard_bg_js__WEBPACK_IMPORTED_MODULE_0__.yc
17
19
  });
18
20
  var _standard_bg_wasm__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("../web-style-transformer/dist/standard_bg.wasm");
19
21
  var _standard_bg_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("../web-style-transformer/dist/standard_bg.js");
@@ -21,7 +23,7 @@ var __webpack_modules__ = {
21
23
  _standard_bg_wasm__WEBPACK_IMPORTED_MODULE_1__
22
24
  ]);
23
25
  _standard_bg_wasm__WEBPACK_IMPORTED_MODULE_1__ = (__webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__)[0];
24
- (0, _standard_bg_js__WEBPACK_IMPORTED_MODULE_0__.oT)(_standard_bg_wasm__WEBPACK_IMPORTED_MODULE_1__);
26
+ (0, _standard_bg_js__WEBPACK_IMPORTED_MODULE_0__.lI)(_standard_bg_wasm__WEBPACK_IMPORTED_MODULE_1__);
25
27
  _standard_bg_wasm__WEBPACK_IMPORTED_MODULE_1__.__wbindgen_start();
26
28
  __webpack_async_result__();
27
29
  } catch (e) {
@@ -31,14 +33,14 @@ var __webpack_modules__ = {
31
33
  },
32
34
  "../web-style-transformer/dist/standard_bg.js": function(module, __webpack_exports__, __webpack_require__) {
33
35
  __webpack_require__.d(__webpack_exports__, {
34
- C2: ()=>__wbg_push_737cfc8c1432c2c6,
35
- Or: ()=>__wbindgen_throw,
36
- a9: ()=>__wbg_new_78feb108b6472713,
37
- h4: ()=>__wbindgen_string_new,
38
- oT: ()=>__wbg_set_wasm,
39
- pE: ()=>transform_raw_u16_inline_style_ptr_parsed,
40
- xJ: ()=>transform_raw_u16_inline_style_ptr,
41
- xQ: ()=>__wbindgen_init_externref_table
36
+ M2: ()=>__wbg_new_78feb108b6472713,
37
+ Qn: ()=>__wbindgen_throw,
38
+ aC: ()=>transform_raw_u16_inline_style_ptr,
39
+ bL: ()=>__wbindgen_init_externref_table,
40
+ iG: ()=>transform_raw_u16_inline_style_ptr_parsed,
41
+ lI: ()=>__wbg_set_wasm,
42
+ tZ: ()=>__wbg_push_737cfc8c1432c2c6,
43
+ yc: ()=>__wbindgen_string_new
42
44
  });
43
45
  module = __webpack_require__.hmd(module);
44
46
  let wasm;
@@ -150,14 +152,14 @@ var __webpack_modules__ = {
150
152
  try {
151
153
  __webpack_require__.r(__webpack_exports__);
152
154
  __webpack_require__.d(__webpack_exports__, {
153
- __wbg_new_78feb108b6472713: ()=>_dist_standard_js__WEBPACK_IMPORTED_MODULE_0__.a9,
154
- __wbg_push_737cfc8c1432c2c6: ()=>_dist_standard_js__WEBPACK_IMPORTED_MODULE_0__.C2,
155
- __wbg_set_wasm: ()=>_dist_standard_js__WEBPACK_IMPORTED_MODULE_0__.oT,
156
- __wbindgen_init_externref_table: ()=>_dist_standard_js__WEBPACK_IMPORTED_MODULE_0__.xQ,
157
- __wbindgen_string_new: ()=>_dist_standard_js__WEBPACK_IMPORTED_MODULE_0__.h4,
158
- __wbindgen_throw: ()=>_dist_standard_js__WEBPACK_IMPORTED_MODULE_0__.Or,
159
- transform_raw_u16_inline_style_ptr: ()=>_dist_standard_js__WEBPACK_IMPORTED_MODULE_0__.xJ,
160
- transform_raw_u16_inline_style_ptr_parsed: ()=>_dist_standard_js__WEBPACK_IMPORTED_MODULE_0__.pE
155
+ __wbg_new_78feb108b6472713: ()=>_dist_standard_js__WEBPACK_IMPORTED_MODULE_0__.M2,
156
+ __wbg_push_737cfc8c1432c2c6: ()=>_dist_standard_js__WEBPACK_IMPORTED_MODULE_0__.tZ,
157
+ __wbg_set_wasm: ()=>_dist_standard_js__WEBPACK_IMPORTED_MODULE_0__.lI,
158
+ __wbindgen_init_externref_table: ()=>_dist_standard_js__WEBPACK_IMPORTED_MODULE_0__.bL,
159
+ __wbindgen_string_new: ()=>_dist_standard_js__WEBPACK_IMPORTED_MODULE_0__.yc,
160
+ __wbindgen_throw: ()=>_dist_standard_js__WEBPACK_IMPORTED_MODULE_0__.Qn,
161
+ transform_raw_u16_inline_style_ptr: ()=>_dist_standard_js__WEBPACK_IMPORTED_MODULE_0__.aC,
162
+ transform_raw_u16_inline_style_ptr_parsed: ()=>_dist_standard_js__WEBPACK_IMPORTED_MODULE_0__.iG
161
163
  });
162
164
  var _dist_standard_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("../web-style-transformer/dist/standard.js");
163
165
  var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([
@@ -174,11 +176,11 @@ var __webpack_modules__ = {
174
176
  var WEBPACK_IMPORTED_MODULE_0 = __webpack_require__("../web-style-transformer/dist/standard_bg.js");
175
177
  module.exports = __webpack_require__.v(exports, module.id, "431436911960378f", {
176
178
  "./standard_bg.js": {
177
- __wbg_new_78feb108b6472713: WEBPACK_IMPORTED_MODULE_0.a9,
178
- __wbindgen_string_new: WEBPACK_IMPORTED_MODULE_0.h4,
179
- __wbg_push_737cfc8c1432c2c6: WEBPACK_IMPORTED_MODULE_0.C2,
180
- __wbindgen_throw: WEBPACK_IMPORTED_MODULE_0.Or,
181
- __wbindgen_init_externref_table: WEBPACK_IMPORTED_MODULE_0.xQ
179
+ __wbg_new_78feb108b6472713: WEBPACK_IMPORTED_MODULE_0.M2,
180
+ __wbindgen_string_new: WEBPACK_IMPORTED_MODULE_0.yc,
181
+ __wbg_push_737cfc8c1432c2c6: WEBPACK_IMPORTED_MODULE_0.tZ,
182
+ __wbindgen_throw: WEBPACK_IMPORTED_MODULE_0.Qn,
183
+ __wbindgen_init_externref_table: WEBPACK_IMPORTED_MODULE_0.bL
182
184
  }
183
185
  });
184
186
  }
@@ -352,7 +354,7 @@ __webpack_require__.m = __webpack_modules__;
352
354
  })();
353
355
  (()=>{
354
356
  var installedChunks = {
355
- 980: 0
357
+ 410: 0
356
358
  };
357
359
  var installChunk = (data)=>{
358
360
  var __webpack_ids__ = data.__webpack_ids__;
@@ -391,6 +393,7 @@ const lynxUniqueIdAttribute = 'l-uid';
391
393
  const cssIdAttribute = 'l-css-id';
392
394
  const componentIdAttribute = 'l-comp-id';
393
395
  const parentComponentUniqueIdAttribute = 'l-p-comp-uid';
396
+ const lynxEntryNameAttribute = 'l-e-name';
394
397
  const lynxTagAttribute = 'lynx-tag';
395
398
  const lynxDatasetAttribute = 'l-dset';
396
399
  const lynxComponentConfigAttribute = 'l-comp-cfg';
@@ -399,12 +402,6 @@ const lynxElementTemplateMarkerAttribute = 'l-template';
399
402
  const lynxPartIdAttribute = 'l-part';
400
403
  const lynxDefaultDisplayLinearAttribute = 'lynx-default-display-linear';
401
404
  const __lynx_timing_flag = '__lynx_timing_flag';
402
- const globalMuteableVars = [
403
- 'registerDataProcessor',
404
- 'registerWorkletInternal',
405
- 'lynxWorkletImpl',
406
- 'runWorklet'
407
- ];
408
405
  const systemInfo = {
409
406
  platform: 'web',
410
407
  lynxSdkVersion: '3.0'
@@ -418,10 +415,6 @@ const inShadowRootStyles = [
418
415
  overflow: visible;
419
416
  }`
420
417
  ];
421
- const constants_globalDisallowedVars = [
422
- 'navigator',
423
- 'postMessage'
424
- ];
425
418
  const W3cEventNameToLynx = {
426
419
  click: 'tap',
427
420
  lynxscroll: 'scroll',
@@ -473,12 +466,12 @@ class Rpc {
473
466
  };
474
467
  }
475
468
  #onMessage = async (message)=>{
476
- const handler1 = this.#handlerMap.get(message.name);
477
- if (handler1) {
469
+ const handler = this.#handlerMap.get(message.name);
470
+ if (handler) {
478
471
  const lockViewer = message.sync ? new Int32Array(message.lock) : void 0;
479
472
  const replyTempEndpoint = !message.sync && message.retId ? Rpc.createRetEndpoint(message.retId) : void 0;
480
473
  try {
481
- const result = await handler1(...message.data);
474
+ const result = await handler(...message.data);
482
475
  let retData, transfer = [];
483
476
  if (message.sync) retData = result;
484
477
  else if (message.hasTransfer) ({ data: retData, transfer } = result || {});
@@ -521,8 +514,8 @@ class Rpc {
521
514
  createCall(endpoint) {
522
515
  return (...args)=>this.invoke(endpoint, args);
523
516
  }
524
- registerHandler(endpoint, handler1) {
525
- this.#handlerMap.set(endpoint.name, handler1);
517
+ registerHandler(endpoint, handler) {
518
+ this.#handlerMap.set(endpoint.name, handler);
526
519
  const currentCache = this.#messageCache[endpoint.name];
527
520
  if (currentCache?.length) {
528
521
  this.#messageCache[endpoint.name] = void 0;
@@ -741,115 +734,49 @@ class LynxCrossThreadContext extends EventTarget {
741
734
  });
742
735
  }
743
736
  }
744
- const mainThreadInjectVars = [
745
- 'lynx',
746
- 'globalThis',
747
- '_ReportError',
748
- '_SetSourceMapRelease',
749
- '__AddConfig',
750
- '__AddDataset',
751
- '__GetAttributes',
752
- '__GetComponentID',
753
- '__GetDataByKey',
754
- '__GetDataset',
755
- '__GetElementConfig',
756
- '__GetElementUniqueID',
757
- '__GetID',
758
- '__GetTag',
759
- '__SetAttribute',
760
- '__SetConfig',
761
- '__SetDataset',
762
- '__SetID',
763
- '__UpdateComponentID',
764
- '__UpdateComponentInfo',
765
- '__GetConfig',
766
- '__GetAttributeByName',
767
- '__UpdateListCallbacks',
768
- '__AppendElement',
769
- '__ElementIsEqual',
770
- '__FirstElement',
771
- '__GetChildren',
772
- '__GetParent',
773
- '__InsertElementBefore',
774
- '__LastElement',
775
- '__NextElement',
776
- '__RemoveElement',
777
- '__ReplaceElement',
778
- '__ReplaceElements',
779
- '__SwapElement',
780
- '__CreateComponent',
781
- '__CreateElement',
782
- '__CreatePage',
783
- '__CreateView',
784
- '__CreateText',
785
- '__CreateRawText',
786
- '__CreateImage',
787
- '__CreateScrollView',
788
- '__CreateWrapperElement',
789
- '__CreateList',
790
- '__AddEvent',
791
- '__GetEvent',
792
- '__GetEvents',
793
- '__SetEvents',
794
- '__AddClass',
795
- '__SetClasses',
796
- '__GetClasses',
797
- '__AddInlineStyle',
798
- '__SetInlineStyles',
799
- '__SetCSSId',
800
- '__OnLifecycleEvent',
801
- '__FlushElementTree',
802
- '__LoadLepusChunk',
803
- 'SystemInfo',
804
- '_I18nResourceTranslation',
805
- '_AddEventListener',
806
- '__GetTemplateParts',
807
- '__MarkPartElement',
808
- '__MarkTemplateElement',
809
- '__GetPageElement',
810
- '__ElementFromBinary'
811
- ];
812
- const backgroundInjectVars = [
813
- 'NativeModules',
814
- 'globalThis',
815
- 'lynx',
816
- 'lynxCoreInject',
817
- 'SystemInfo'
737
+ const currentSupportedTemplateVersion = 2;
738
+ const globalDisallowedVars = [
739
+ 'navigator',
740
+ 'postMessage'
818
741
  ];
819
- const backgroundInjectWithBind = [
820
- 'Card',
821
- 'Component'
742
+ const templateUpgraders = [
743
+ (template)=>{
744
+ const defaultInjectStr = "Card,setTimeout,setInterval,clearInterval,clearTimeout,NativeModules,Component,ReactLynx,nativeAppId,Behavior,LynxJSBI,lynx,window,document,frames,location,navigator,localStorage,history,Caches,screen,alert,confirm,prompt,fetch,XMLHttpRequest,__WebSocket__,webkit,Reporter,print,global,requestAnimationFrame,cancelAnimationFrame";
745
+ template.manifest = Object.fromEntries(Object.entries(template.manifest).map(([key, value])=>[
746
+ key,
747
+ `{init: (lynxCoreInject) => { var {${defaultInjectStr}} = lynxCoreInject.tt; var module = {exports:null}; ${value}\n return module.exports; } }`
748
+ ]));
749
+ template.lepusCode = Object.fromEntries(Object.entries(template.lepusCode).map(([key, value])=>[
750
+ key,
751
+ `(()=>{${value}\n})();`
752
+ ]));
753
+ template.version = 2;
754
+ return template;
755
+ }
822
756
  ];
823
- const generateModuleContent = (content, injectVars, injectWithBind, muteableVars, globalDisallowedVars, isESM)=>[
757
+ const generateModuleContent = (content)=>[
824
758
  '//# allFunctionsCalledOnLoad\n',
825
- isESM ? 'export default ' : 'globalThis.module.exports =',
826
- 'function(lynx_runtime) {',
827
- 'const module= {exports:{}};let exports = module.exports;',
828
- 'var {',
829
- injectVars.join(','),
830
- '} = lynx_runtime;',
831
- ...injectWithBind.map((nm)=>`const ${nm} = lynx_runtime.${nm}?.bind(lynx_runtime);`),
832
- ';var globDynamicComponentEntry = \'__Card__\';',
833
- 0 !== globalDisallowedVars.length ? `var ${globalDisallowedVars.join('=')}=undefined;` : '',
834
- 'var {__globalProps} = lynx;',
835
- 'lynx_runtime._updateVars=()=>{',
836
- ...muteableVars.map((nm)=>`${nm} = lynx_runtime.__lynxGlobalBindingValues.${nm};`),
837
- '};\n',
759
+ '"use strict";\n',
760
+ `(() => {const ${globalDisallowedVars.join('=void 0,')}=void 0;module.exports = `,
838
761
  content,
839
- '\n return module.exports;}'
762
+ '\n})()'
840
763
  ].join('');
841
- async function generateJavascriptUrl(obj, injectVars, injectWithBind, muteableVars, globalDisallowedVars, createJsModuleUrl, isESM, templateName) {
764
+ async function generateJavascriptUrl(obj, createJsModuleUrl, templateName) {
842
765
  const processEntry = async ([name, content])=>[
843
766
  name,
844
- await createJsModuleUrl(generateModuleContent(content, injectVars.concat(muteableVars), injectWithBind, muteableVars, globalDisallowedVars, isESM), `${templateName}-${name.replaceAll('/', '')}.js`)
767
+ await createJsModuleUrl(generateModuleContent(content), `${templateName}-${name.replaceAll('/', '')}.js`)
845
768
  ];
846
769
  return Promise.all(Object.entries(obj).filter(([_, content])=>'string' == typeof content).map(processEntry)).then(Object.fromEntries);
847
770
  }
848
771
  async function generateTemplate(template, createJsModuleUrl, templateName) {
772
+ template.version = template.version ?? 1;
773
+ if (template.version > currentSupportedTemplateVersion) throw new Error("Unsupported template, please upgrade your web-platform dependencies");
774
+ let upgrader;
775
+ while(template.version < currentSupportedTemplateVersion && (upgrader = templateUpgraders[template.version - 1]))template = upgrader(template);
849
776
  return {
850
777
  ...template,
851
- lepusCode: await generateJavascriptUrl(template.lepusCode, mainThreadInjectVars, [], globalMuteableVars, templateName ? [] : constants_globalDisallowedVars, createJsModuleUrl, true, templateName),
852
- manifest: await generateJavascriptUrl(template.manifest, backgroundInjectVars, backgroundInjectWithBind, [], templateName ? [] : constants_globalDisallowedVars, createJsModuleUrl, false, templateName)
778
+ lepusCode: await generateJavascriptUrl(template.lepusCode, createJsModuleUrl, templateName),
779
+ manifest: await generateJavascriptUrl(template.manifest, createJsModuleUrl, templateName)
853
780
  };
854
781
  }
855
782
  function registerCallLepusMethodHandler(rpc, runtime) {
@@ -861,163 +788,34 @@ function registerGetCustomSectionHandler(rpc, customSections) {
861
788
  rpc.registerHandler(getCustomSectionsEndpoint, (key)=>customSections[key]?.content);
862
789
  }
863
790
  function createMainThreadLynx(config, SystemInfo) {
791
+ const requestAnimationFrameBrowserImpl = requestAnimationFrame;
792
+ const cancelAnimationFrameBrowserImpl = cancelAnimationFrame;
793
+ const setTimeoutBrowserImpl = setTimeout;
794
+ const clearTimeoutBrowserImpl = clearTimeout;
795
+ const setIntervalBrowserImpl = setInterval;
796
+ const clearIntervalBrowserImpl = clearInterval;
864
797
  return {
865
798
  getJSContext () {
866
799
  return config.jsContext;
867
800
  },
868
801
  requestAnimationFrame (cb) {
869
- return requestAnimationFrame(cb);
802
+ return requestAnimationFrameBrowserImpl(cb);
870
803
  },
871
- cancelAnimationFrame (handler1) {
872
- return cancelAnimationFrame(handler1);
804
+ cancelAnimationFrame (handler) {
805
+ return cancelAnimationFrameBrowserImpl(handler);
873
806
  },
874
807
  __globalProps: config.globalProps,
875
808
  getCustomSectionSync (key) {
876
- return config.customSections[key]?.content;
809
+ return config.lynxTemplate.customSections[key]?.content;
877
810
  },
878
811
  markPipelineTiming: config.callbacks.markTiming,
879
- SystemInfo
880
- };
881
- }
882
- const referenceTypes = async ()=>WebAssembly.validate(new Uint8Array([
883
- 0,
884
- 97,
885
- 115,
886
- 109,
887
- 1,
888
- 0,
889
- 0,
890
- 0,
891
- 1,
892
- 4,
893
- 1,
894
- 96,
895
- 0,
896
- 0,
897
- 3,
898
- 2,
899
- 1,
900
- 0,
901
- 10,
902
- 7,
903
- 1,
904
- 5,
905
- 0,
906
- 208,
907
- 112,
908
- 26,
909
- 11
910
- ]));
911
- let wasm;
912
- async function initWasm() {
913
- const supportsReferenceTypes = await referenceTypes();
914
- wasm = supportsReferenceTypes ? await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "../web-style-transformer/standard.js")) : await __webpack_require__.e("501").then(__webpack_require__.bind(__webpack_require__, "../web-style-transformer/legacy.js"));
915
- }
916
- function transformInlineStyleString(str) {
917
- return wasm.transform_raw_u16_inline_style_ptr(str) ?? str;
918
- }
919
- function transformParsedStyles(styles) {
920
- let childStyle = [];
921
- let transformedStyle = [];
922
- for (const [property, value] of styles){
923
- const transformedResult = wasm.transform_raw_u16_inline_style_ptr_parsed(property, value);
924
- if (transformedResult) {
925
- const [transformedStyleForCurrent, childStyleForCurrent] = transformedResult;
926
- transformedStyle = transformedStyle.concat(transformedStyleForCurrent);
927
- if (childStyleForCurrent) childStyle = childStyle.concat(childStyleForCurrent);
928
- } else transformedStyle.push([
929
- property,
930
- value
931
- ]);
932
- }
933
- return {
934
- childStyle,
935
- transformedStyle
812
+ SystemInfo,
813
+ setTimeout: setTimeoutBrowserImpl,
814
+ clearTimeout: clearTimeoutBrowserImpl,
815
+ setInterval: setIntervalBrowserImpl,
816
+ clearInterval: clearIntervalBrowserImpl
936
817
  };
937
818
  }
938
- function flattenStyleInfo(styleInfo, enableCSSSelector) {
939
- function flattenOneStyleInfo(cssId) {
940
- const oneInfo = styleInfo[cssId];
941
- const imports = oneInfo?.imports;
942
- if (oneInfo && imports?.length) {
943
- for (const im of imports){
944
- const flatInfo = flattenOneStyleInfo(im);
945
- if (flatInfo) {
946
- oneInfo.content.push(...flatInfo.content);
947
- oneInfo.rules.push(...enableCSSSelector ? flatInfo.rules : flatInfo.rules.map((i)=>({
948
- ...i
949
- })));
950
- }
951
- }
952
- oneInfo.imports = void 0;
953
- }
954
- return oneInfo;
955
- }
956
- Object.keys(styleInfo).map((cssId)=>{
957
- flattenOneStyleInfo(cssId);
958
- });
959
- }
960
- function transformToWebCss(styleInfo) {
961
- for (const cssInfos of Object.values(styleInfo))for (const rule of cssInfos.rules){
962
- const { sel: selectors, decl: declarations } = rule;
963
- const { transformedStyle, childStyle } = transformParsedStyles(declarations);
964
- rule.decl = transformedStyle;
965
- if (childStyle.length > 0) cssInfos.rules.push({
966
- sel: selectors.map((selector)=>selector.toSpliced(-2, 1, [
967
- '>'
968
- ], [
969
- '*'
970
- ], [], [], [])),
971
- decl: childStyle
972
- });
973
- }
974
- }
975
- function genCssContent(styleInfo, pageConfig) {
976
- function getExtraSelectors(cssId) {
977
- let suffix = '';
978
- if (pageConfig.enableRemoveCSSScope) suffix += `[${lynxTagAttribute}]`;
979
- else if (void 0 !== cssId) suffix += `[${cssIdAttribute}="${cssId}"]`;
980
- else suffix += `[${lynxTagAttribute}]`;
981
- return suffix;
982
- }
983
- const finalCssContent = [];
984
- for (const [cssId, cssInfos] of Object.entries(styleInfo)){
985
- const suffix = getExtraSelectors(cssId);
986
- const declarationContent = cssInfos.rules.map((rule)=>{
987
- const { sel: selectorList, decl: declarations } = rule;
988
- const selectorString = selectorList.map((selectors)=>selectors.toSpliced(-4, 0, [
989
- suffix
990
- ]).flat().join('')).join(',');
991
- const declarationString = declarations.map(([k, v])=>`${k}:${v};`).join('');
992
- return `${selectorString}{${declarationString}}`;
993
- }).join('');
994
- finalCssContent.push(...cssInfos.content, declarationContent);
995
- }
996
- return finalCssContent.join('\n');
997
- }
998
- function genCssOGInfo(styleInfo) {
999
- return Object.fromEntries(Object.entries(styleInfo).map(([cssId, cssInfos])=>{
1000
- const oneCssOGInfo = {};
1001
- cssInfos.rules = cssInfos.rules.filter((oneCssInfo)=>{
1002
- oneCssInfo.sel = oneCssInfo.sel.filter((selectorList)=>{
1003
- const [classSelectors, pseudoClassSelectors, pseudoElementSelectors, combinator] = selectorList;
1004
- if (1 === classSelectors.length && '.' === classSelectors[0][0] && 0 === pseudoClassSelectors.length && 0 === pseudoElementSelectors.length && 0 === combinator.length) {
1005
- const selectorName = classSelectors[0].substring(1);
1006
- const currentDeclarations = oneCssOGInfo[selectorName];
1007
- if (currentDeclarations) currentDeclarations.push(...oneCssInfo.decl);
1008
- else oneCssOGInfo[selectorName] = oneCssInfo.decl;
1009
- return false;
1010
- }
1011
- return true;
1012
- });
1013
- return oneCssInfo.sel.length > 0;
1014
- });
1015
- return [
1016
- cssId,
1017
- oneCssOGInfo
1018
- ];
1019
- }));
1020
- }
1021
819
  const cacheForCamelize = {};
1022
820
  function camelize(str) {
1023
821
  if (cacheForCamelize[str]) return cacheForCamelize[str];
@@ -1258,6 +1056,62 @@ V('offset-distance');
1258
1056
  function queryCSSProperty(index) {
1259
1057
  return cssPropertyMap[index];
1260
1058
  }
1059
+ const referenceTypes = async ()=>WebAssembly.validate(new Uint8Array([
1060
+ 0,
1061
+ 97,
1062
+ 115,
1063
+ 109,
1064
+ 1,
1065
+ 0,
1066
+ 0,
1067
+ 0,
1068
+ 1,
1069
+ 4,
1070
+ 1,
1071
+ 96,
1072
+ 0,
1073
+ 0,
1074
+ 3,
1075
+ 2,
1076
+ 1,
1077
+ 0,
1078
+ 10,
1079
+ 7,
1080
+ 1,
1081
+ 5,
1082
+ 0,
1083
+ 208,
1084
+ 112,
1085
+ 26,
1086
+ 11
1087
+ ]));
1088
+ let wasm;
1089
+ async function initWasm() {
1090
+ const supportsReferenceTypes = await referenceTypes();
1091
+ wasm = supportsReferenceTypes ? await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "../web-style-transformer/standard.js")) : await __webpack_require__.e("8").then(__webpack_require__.bind(__webpack_require__, "../web-style-transformer/legacy.js"));
1092
+ }
1093
+ function transformInlineStyleString(str) {
1094
+ return wasm.transform_raw_u16_inline_style_ptr(str) ?? str;
1095
+ }
1096
+ function transformParsedStyles(styles) {
1097
+ let childStyle = [];
1098
+ let transformedStyle = [];
1099
+ for (const [property, value] of styles){
1100
+ const transformedResult = wasm.transform_raw_u16_inline_style_ptr_parsed(property, value);
1101
+ if (transformedResult) {
1102
+ const [transformedStyleForCurrent, childStyleForCurrent] = transformedResult;
1103
+ transformedStyle = transformedStyle.concat(transformedStyleForCurrent);
1104
+ if (childStyleForCurrent) childStyle = childStyle.concat(childStyleForCurrent);
1105
+ } else transformedStyle.push([
1106
+ property,
1107
+ value
1108
+ ]);
1109
+ }
1110
+ return {
1111
+ childStyle,
1112
+ transformedStyle
1113
+ };
1114
+ }
1261
1115
  var uppercasePattern = /[A-Z]/g;
1262
1116
  var msPattern = /^ms-/;
1263
1117
  var hyphenate_style_name_cache = {};
@@ -1467,17 +1321,6 @@ function createCrossThreadEvent(domEvent, eventName) {
1467
1321
  ...otherProperties
1468
1322
  };
1469
1323
  }
1470
- function decodeCssOG(classes, styleInfo, cssId) {
1471
- const classList = classes.split(' ').filter((e)=>e);
1472
- let declarations = [];
1473
- const currentStyleInfo = styleInfo[cssId ?? '0'];
1474
- if (currentStyleInfo) for (const oneClassName of classList){
1475
- const oneRule = currentStyleInfo[oneClassName];
1476
- if (oneRule) declarations.push(...oneRule);
1477
- }
1478
- else console.warn(`[lynx-web] cannot find styleinfo for cssid ${cssId}`);
1479
- return declarations.map(([property, value])=>`${property}:${value};`).join('');
1480
- }
1481
1324
  const exposureRelatedAttributes = new Set([
1482
1325
  'exposure-id',
1483
1326
  'exposure-area',
@@ -1492,36 +1335,13 @@ const exposureRelatedAttributes = new Set([
1492
1335
  ]);
1493
1336
  function createMainThreadGlobalThis(config) {
1494
1337
  let timingFlags = [];
1495
- let renderPage;
1496
- const { callbacks, tagMap, pageConfig, lepusCode, rootDom, globalProps, styleInfo, ssrHydrateInfo, ssrHooks } = config;
1338
+ const { callbacks, tagMap, pageConfig, lynxTemplate, rootDom, globalProps, ssrHydrateInfo, ssrHooks, mtsRealm, document } = config;
1339
+ const { elementTemplate, lepusCode } = lynxTemplate;
1497
1340
  const lynxUniqueIdToElement = ssrHydrateInfo?.lynxUniqueIdToElement ?? [];
1498
- const lynxUniqueIdToStyleRulesIndex = ssrHydrateInfo?.lynxUniqueIdToStyleRulesIndex ?? [];
1499
1341
  const elementToRuntimeInfoMap = new WeakMap();
1500
1342
  let pageElement = lynxUniqueIdToElement[1]?.deref();
1501
1343
  let uniqueIdInc = lynxUniqueIdToElement.length || 1;
1502
- const varsUpdateHandlers = [];
1503
- const lynxGlobalBindingValues = {};
1504
1344
  const exposureChangedElements = new Set();
1505
- flattenStyleInfo(styleInfo, pageConfig.enableCSSSelector);
1506
- transformToWebCss(styleInfo);
1507
- const cssOGInfo = pageConfig.enableCSSSelector ? {} : genCssOGInfo(styleInfo);
1508
- let cardStyleElement;
1509
- if (ssrHydrateInfo?.cardStyleElement) cardStyleElement = ssrHydrateInfo.cardStyleElement;
1510
- else {
1511
- cardStyleElement = callbacks.createElement('style');
1512
- cardStyleElement.innerHTML = genCssContent(styleInfo, pageConfig);
1513
- rootDom.append(cardStyleElement);
1514
- }
1515
- const cardStyleElementSheet = cardStyleElement.sheet;
1516
- const updateCssOGStyle = (uniqueId, newStyles)=>{
1517
- if (void 0 !== lynxUniqueIdToStyleRulesIndex[uniqueId]) {
1518
- const rule = cardStyleElementSheet.cssRules[lynxUniqueIdToStyleRulesIndex[uniqueId]];
1519
- rule.style.cssText = newStyles;
1520
- } else {
1521
- const index = cardStyleElementSheet.insertRule(`[${lynxUniqueIdAttribute}="${uniqueId}"]{${newStyles}}`, cardStyleElementSheet.cssRules.length);
1522
- lynxUniqueIdToStyleRulesIndex[uniqueId] = index;
1523
- }
1524
- };
1525
1345
  const commonHandler = (event)=>{
1526
1346
  if (!event.currentTarget) return;
1527
1347
  const currentTarget = event.currentTarget;
@@ -1542,7 +1362,7 @@ function createMainThreadGlobalThis(config) {
1542
1362
  if (hname) {
1543
1363
  crossThreadEvent.target.elementRefptr = event.target;
1544
1364
  if (crossThreadEvent.currentTarget) crossThreadEvent.currentTarget.elementRefptr = event.currentTarget;
1545
- mtsGlobalThis.runWorklet?.(hname.value, [
1365
+ mtsRealm.globalWindow.runWorklet?.(hname.value, [
1546
1366
  crossThreadEvent
1547
1367
  ]);
1548
1368
  }
@@ -1600,8 +1420,8 @@ function createMainThreadGlobalThis(config) {
1600
1420
  {
1601
1421
  eventName = eventName.toLowerCase();
1602
1422
  const isCapture = eventType.startsWith('capture');
1603
- const handler1 = isCapture ? runtimeInfo.eventHandlerMap[eventName]?.capture : runtimeInfo.eventHandlerMap[eventName]?.bind;
1604
- return handler1?.handler;
1423
+ const handler = isCapture ? runtimeInfo.eventHandlerMap[eventName]?.capture : runtimeInfo.eventHandlerMap[eventName]?.bind;
1424
+ return handler?.handler;
1605
1425
  }
1606
1426
  };
1607
1427
  const __GetEvents = (element)=>{
@@ -1611,11 +1431,11 @@ function createMainThreadGlobalThis(config) {
1611
1431
  info.bind,
1612
1432
  info.capture
1613
1433
  ])if (atomInfo) {
1614
- const { type, handler: handler1 } = atomInfo;
1615
- if (handler1) eventInfos.push({
1434
+ const { type, handler } = atomInfo;
1435
+ if (handler) eventInfos.push({
1616
1436
  type: type,
1617
1437
  name: lynxEventName,
1618
- function: handler1
1438
+ function: handler
1619
1439
  });
1620
1440
  }
1621
1441
  return eventInfos;
@@ -1626,7 +1446,7 @@ function createMainThreadGlobalThis(config) {
1626
1446
  const __CreateElement = (tag, parentComponentUniqueId)=>{
1627
1447
  const uniqueId = uniqueIdInc++;
1628
1448
  const htmlTag = tagMap[tag] ?? tag;
1629
- const element = callbacks.createElement(htmlTag);
1449
+ const element = document.createElement(htmlTag);
1630
1450
  lynxUniqueIdToElement[uniqueId] = new WeakRef(element);
1631
1451
  const parentComponentCssID = lynxUniqueIdToElement[parentComponentUniqueId]?.deref()?.getAttribute(cssIdAttribute);
1632
1452
  parentComponentCssID && '0' !== parentComponentCssID && element.setAttribute(cssIdAttribute, parentComponentCssID);
@@ -1707,7 +1527,7 @@ function createMainThreadGlobalThis(config) {
1707
1527
  elementToRuntimeInfoMap.set(element, runtimeInfo);
1708
1528
  };
1709
1529
  const __SwapElement = (childA, childB)=>{
1710
- const temp = callbacks.createElement('div');
1530
+ const temp = document.createElement('div');
1711
1531
  childA.replaceWith(temp);
1712
1532
  childB.replaceWith(childA);
1713
1533
  temp.replaceWith(childB);
@@ -1722,21 +1542,24 @@ function createMainThreadGlobalThis(config) {
1722
1542
  const __AddClassForCSSOG = (element, className)=>{
1723
1543
  const newClassName = ((element.getAttribute('class') ?? '') + ' ' + className).trim();
1724
1544
  element.setAttribute('class', newClassName);
1725
- const newStyleStr = decodeCssOG(newClassName, cssOGInfo, element.getAttribute(cssIdAttribute));
1726
- updateCssOGStyle(Number(element.getAttribute(lynxUniqueIdAttribute)), newStyleStr);
1545
+ const cssId = element.getAttribute(cssIdAttribute);
1546
+ const uniqueId = Number(element.getAttribute(lynxUniqueIdAttribute));
1547
+ callbacks.updateCssOGStyle(uniqueId, newClassName, cssId);
1727
1548
  };
1728
1549
  const __SetClassesForCSSOG = (element, classNames)=>{
1729
1550
  __SetClasses(element, classNames);
1730
- const newStyleStr = decodeCssOG(classNames ?? '', cssOGInfo, element.getAttribute(cssIdAttribute));
1731
- updateCssOGStyle(Number(element.getAttribute(lynxUniqueIdAttribute)), newStyleStr ?? '');
1551
+ const cssId = element.getAttribute(cssIdAttribute);
1552
+ const uniqueId = Number(element.getAttribute(lynxUniqueIdAttribute));
1553
+ callbacks.updateCssOGStyle(uniqueId, classNames ?? '', cssId);
1732
1554
  };
1733
1555
  const __LoadLepusChunk = (path)=>{
1734
- const lepusModule = lepusCode[`${path}`];
1735
- if (!lepusModule) return false;
1736
- {
1737
- const entry = lepusModule.exports;
1738
- entry?.(mtsGlobalThis);
1556
+ try {
1557
+ path = lepusCode?.[path] ?? path;
1558
+ mtsRealm.loadScriptSync(path);
1739
1559
  return true;
1560
+ } catch (e) {
1561
+ console.error(`failed to load lepus chunk ${path}`, e);
1562
+ return false;
1740
1563
  }
1741
1564
  };
1742
1565
  const __FlushElementTree = (_subTree, options)=>{
@@ -1776,14 +1599,14 @@ function createMainThreadGlobalThis(config) {
1776
1599
  }
1777
1600
  };
1778
1601
  const __ElementFromBinary = (templateId, parentComponentUniId)=>{
1779
- const elementTemplateData = config.elementTemplate[templateId];
1602
+ const elementTemplateData = elementTemplate[templateId];
1780
1603
  if (elementTemplateData) {
1781
1604
  let clonedElements;
1782
1605
  if (templateIdToTemplate[templateId]) clonedElements = Array.from(templateIdToTemplate[templateId].content.cloneNode(true).children);
1783
1606
  else {
1784
1607
  clonedElements = elementTemplateData.map((data)=>createElementForElementTemplateData(data, parentComponentUniId));
1785
1608
  if (rootDom.cloneNode) {
1786
- const template = callbacks.createElement('template');
1609
+ const template = document.createElement('template');
1787
1610
  template.content.append(...clonedElements);
1788
1611
  templateIdToTemplate[templateId] = template;
1789
1612
  rootDom.append(template);
@@ -1871,42 +1694,23 @@ function createMainThreadGlobalThis(config) {
1871
1694
  _SetSourceMapRelease: (errInfo)=>release = errInfo?.release,
1872
1695
  __OnLifecycleEvent: callbacks.__OnLifecycleEvent,
1873
1696
  __FlushElementTree,
1874
- __lynxGlobalBindingValues: lynxGlobalBindingValues,
1875
1697
  _I18nResourceTranslation: callbacks._I18nResourceTranslation,
1876
1698
  _AddEventListener: ()=>{},
1877
- set _updateVars (handler){
1878
- varsUpdateHandlers.push(handler);
1879
- },
1880
- set renderPage (foo){
1881
- renderPage = foo;
1882
- queueMicrotask(callbacks.mainChunkReady);
1883
- },
1884
- get renderPage () {
1885
- return renderPage;
1886
- }
1699
+ renderPage: void 0
1887
1700
  };
1888
- mtsGlobalThis.globalThis = new Proxy(mtsGlobalThis, {
1889
- get: (target, prop)=>{
1890
- if ('string' == typeof prop && constants_globalDisallowedVars.includes(prop)) return;
1891
- if ('globalThis' === prop) return target;
1892
- return target[prop] ?? globalThis[prop];
1701
+ Object.assign(mtsRealm.globalWindow, mtsGlobalThis);
1702
+ Object.defineProperty(mtsRealm.globalWindow, 'renderPage', {
1703
+ get () {
1704
+ return mtsGlobalThis.renderPage;
1893
1705
  },
1894
- set: (target, prop, value)=>{
1895
- target[prop] = value;
1896
- return true;
1706
+ set (v) {
1707
+ mtsGlobalThis.renderPage = v;
1708
+ queueMicrotask(callbacks.mainChunkReady);
1897
1709
  },
1898
- ownKeys (target) {
1899
- return Reflect.ownKeys(target).filter((key)=>'globalThis' !== key);
1900
- }
1710
+ configurable: true,
1711
+ enumerable: true
1901
1712
  });
1902
- for (const nm of globalMuteableVars)Object.defineProperty(mtsGlobalThis, nm, {
1903
- get: ()=>lynxGlobalBindingValues[nm],
1904
- set: (v)=>{
1905
- lynxGlobalBindingValues[nm] = v;
1906
- for (const handler1 of varsUpdateHandlers)handler1();
1907
- }
1908
- });
1909
- return mtsGlobalThis;
1713
+ return mtsRealm.globalWindow;
1910
1714
  }
1911
1715
  function createExposureService(rootDom, postExposure) {
1912
1716
  let working = true;
@@ -1966,9 +1770,128 @@ function createExposureService(rootDom, postExposure) {
1966
1770
  switchExposureService
1967
1771
  };
1968
1772
  }
1773
+ function decodeCssOG(classes, styleInfo, cssId) {
1774
+ const classList = classes.split(' ').filter((e)=>e);
1775
+ let declarations = [];
1776
+ const currentStyleInfo = styleInfo[cssId ?? '0'];
1777
+ if (currentStyleInfo) for (const oneClassName of classList){
1778
+ const oneRule = currentStyleInfo[oneClassName];
1779
+ if (oneRule) declarations.push(...oneRule);
1780
+ }
1781
+ else console.warn(`[lynx-web] cannot find styleinfo for cssid ${cssId}`);
1782
+ return declarations.map(([property, value])=>`${property}:${value};`).join('');
1783
+ }
1784
+ function flattenStyleInfo(styleInfo, enableCSSSelector) {
1785
+ function flattenOneStyleInfo(cssId) {
1786
+ const oneInfo = styleInfo[cssId];
1787
+ const imports = oneInfo?.imports;
1788
+ if (oneInfo && imports?.length) {
1789
+ for (const im of imports){
1790
+ const flatInfo = flattenOneStyleInfo(im);
1791
+ if (flatInfo) {
1792
+ oneInfo.content.push(...flatInfo.content);
1793
+ oneInfo.rules.push(...enableCSSSelector ? flatInfo.rules : flatInfo.rules.map((i)=>({
1794
+ ...i
1795
+ })));
1796
+ }
1797
+ }
1798
+ oneInfo.imports = void 0;
1799
+ }
1800
+ return oneInfo;
1801
+ }
1802
+ Object.keys(styleInfo).map((cssId)=>{
1803
+ flattenOneStyleInfo(cssId);
1804
+ });
1805
+ }
1806
+ function transformToWebCss(styleInfo) {
1807
+ for (const cssInfos of Object.values(styleInfo))for (const rule of cssInfos.rules){
1808
+ const { sel: selectors, decl: declarations } = rule;
1809
+ const { transformedStyle, childStyle } = transformParsedStyles(declarations);
1810
+ rule.decl = transformedStyle;
1811
+ if (childStyle.length > 0) cssInfos.rules.push({
1812
+ sel: selectors.map((selector)=>selector.toSpliced(-2, 1, [
1813
+ '>'
1814
+ ], [
1815
+ '*'
1816
+ ], [], [], [])),
1817
+ decl: childStyle
1818
+ });
1819
+ }
1820
+ }
1821
+ function genCssContent(styleInfo, pageConfig, entryName) {
1822
+ function getExtraSelectors(cssId) {
1823
+ let suffix;
1824
+ suffix = pageConfig.enableRemoveCSSScope ? `[${lynxTagAttribute}]` : void 0 !== cssId ? `[${cssIdAttribute}="${cssId}"]` : `[${lynxTagAttribute}]`;
1825
+ suffix = entryName ? `${suffix}[${lynxEntryNameAttribute}="${entryName}"]` : `${suffix}:not([${lynxEntryNameAttribute}])`;
1826
+ return suffix;
1827
+ }
1828
+ const finalCssContent = [];
1829
+ for (const [cssId, cssInfos] of Object.entries(styleInfo)){
1830
+ const suffix = getExtraSelectors(cssId);
1831
+ const declarationContent = cssInfos.rules.map((rule)=>{
1832
+ const { sel: selectorList, decl: declarations } = rule;
1833
+ const selectorString = selectorList.map((selectors)=>selectors.toSpliced(-4, 0, [
1834
+ suffix
1835
+ ]).flat().join('')).join(',');
1836
+ const declarationString = declarations.map(([k, v])=>`${k}:${v};`).join('');
1837
+ return `${selectorString}{${declarationString}}`;
1838
+ }).join('');
1839
+ finalCssContent.push(...cssInfos.content, declarationContent);
1840
+ }
1841
+ return finalCssContent.join('\n');
1842
+ }
1843
+ function genCssOGInfo(styleInfo) {
1844
+ return Object.fromEntries(Object.entries(styleInfo).map(([cssId, cssInfos])=>{
1845
+ const oneCssOGInfo = {};
1846
+ cssInfos.rules = cssInfos.rules.filter((oneCssInfo)=>{
1847
+ oneCssInfo.sel = oneCssInfo.sel.filter((selectorList)=>{
1848
+ const [classSelectors, pseudoClassSelectors, pseudoElementSelectors, combinator] = selectorList;
1849
+ if (1 === classSelectors.length && '.' === classSelectors[0][0] && 0 === pseudoClassSelectors.length && 0 === pseudoElementSelectors.length && 0 === combinator.length) {
1850
+ const selectorName = classSelectors[0].substring(1);
1851
+ const currentDeclarations = oneCssOGInfo[selectorName];
1852
+ if (currentDeclarations) currentDeclarations.push(...oneCssInfo.decl);
1853
+ else oneCssOGInfo[selectorName] = oneCssInfo.decl;
1854
+ return false;
1855
+ }
1856
+ return true;
1857
+ });
1858
+ return oneCssInfo.sel.length > 0;
1859
+ });
1860
+ return [
1861
+ cssId,
1862
+ oneCssOGInfo
1863
+ ];
1864
+ }));
1865
+ }
1866
+ function appendStyleElement(styleInfo, pageConfig, rootDom, document, entryName, ssrHydrateInfo) {
1867
+ const lynxUniqueIdToStyleRulesIndex = ssrHydrateInfo?.lynxUniqueIdToStyleRulesIndex ?? [];
1868
+ flattenStyleInfo(styleInfo, pageConfig.enableCSSSelector);
1869
+ transformToWebCss(styleInfo);
1870
+ const cssOGInfo = pageConfig.enableCSSSelector ? {} : genCssOGInfo(styleInfo);
1871
+ let cardStyleElement;
1872
+ if (ssrHydrateInfo?.cardStyleElement) cardStyleElement = ssrHydrateInfo.cardStyleElement;
1873
+ else {
1874
+ cardStyleElement = document.createElement('style');
1875
+ cardStyleElement.textContent = genCssContent(styleInfo, pageConfig, entryName);
1876
+ rootDom.appendChild(cardStyleElement);
1877
+ }
1878
+ const cardStyleElementSheet = cardStyleElement.sheet;
1879
+ const updateCssOGStyle = (uniqueId, newClassName, cssID)=>{
1880
+ const newStyles = decodeCssOG(newClassName, cssOGInfo, cssID);
1881
+ if (void 0 !== lynxUniqueIdToStyleRulesIndex[uniqueId]) {
1882
+ const rule = cardStyleElementSheet.cssRules[lynxUniqueIdToStyleRulesIndex[uniqueId]];
1883
+ rule.style.cssText = newStyles;
1884
+ } else {
1885
+ const index = cardStyleElementSheet.insertRule(`[${lynxUniqueIdAttribute}="${uniqueId}"]{${newStyles}}`, cardStyleElementSheet.cssRules.length);
1886
+ lynxUniqueIdToStyleRulesIndex[uniqueId] = index;
1887
+ }
1888
+ };
1889
+ return {
1890
+ updateCssOGStyle
1891
+ };
1892
+ }
1969
1893
  const initWasmPromise = initWasm();
1970
- const moduleCache = {};
1971
- function prepareMainThreadAPIs(backgroundThreadRpc, rootDom, createElement, commitDocument, markTimingInternal, flushMarkTimingInternal, reportError, triggerI18nResourceFallback, initialI18nResources, ssrHooks) {
1894
+ function prepareMainThreadAPIs(backgroundThreadRpc, rootDom, document, mtsRealm, commitDocument, markTimingInternal, flushMarkTimingInternal, reportError, triggerI18nResourceFallback, initialI18nResources, ssrHooks) {
1972
1895
  const postTimingFlags = backgroundThreadRpc.createCall(postTimingFlagsEndpoint);
1973
1896
  const backgroundStart = backgroundThreadRpc.createCall(BackgroundThreadStartEndpoint);
1974
1897
  const publishEvent = backgroundThreadRpc.createCall(publishEventEndpoint);
@@ -1979,49 +1902,30 @@ function prepareMainThreadAPIs(backgroundThreadRpc, rootDom, createElement, comm
1979
1902
  async function startMainThread(config, ssrHydrateInfo) {
1980
1903
  let isFp = true;
1981
1904
  const { globalProps, template, browserConfig, nativeModulesMap, napiModulesMap, tagMap, initI18nResources } = config;
1982
- const { styleInfo, pageConfig, customSections, cardType, lepusCode, elementTemplate } = template;
1905
+ const { styleInfo, pageConfig, customSections, cardType } = template;
1983
1906
  markTimingInternal('decode_start');
1984
1907
  await initWasmPromise;
1985
- const lepusCodeEntries = await Promise.all(Object.entries(lepusCode).map(async ([name, url])=>{
1986
- const cachedModule = moduleCache[url];
1987
- if (cachedModule) return [
1988
- name,
1989
- cachedModule
1990
- ];
1991
- {
1992
- const { default: evaluateModule } = await import(url);
1993
- const module = {
1994
- exports: evaluateModule
1995
- };
1996
- moduleCache[url] = module;
1997
- return [
1998
- name,
1999
- module
2000
- ];
2001
- }
2002
- }));
2003
- const lepusCodeLoaded = Object.fromEntries(lepusCodeEntries);
2004
- const entry = lepusCodeLoaded['root'].exports;
2005
1908
  const jsContext = new LynxCrossThreadContext({
2006
1909
  rpc: backgroundThreadRpc,
2007
1910
  receiveEventEndpoint: dispatchJSContextOnMainThreadEndpoint,
2008
1911
  sendEventEndpoint: dispatchCoreContextOnBackgroundEndpoint
2009
1912
  });
2010
1913
  const i18nResources = initialI18nResources(initI18nResources);
1914
+ const { updateCssOGStyle } = appendStyleElement(styleInfo, pageConfig, rootDom, document, void 0, ssrHydrateInfo);
2011
1915
  const mtsGlobalThis = createMainThreadGlobalThis({
1916
+ lynxTemplate: template,
1917
+ mtsRealm,
2012
1918
  jsContext,
2013
1919
  tagMap,
2014
1920
  browserConfig,
2015
- customSections,
2016
- elementTemplate,
2017
1921
  globalProps,
2018
1922
  pageConfig,
2019
- styleInfo,
2020
- lepusCode: lepusCodeLoaded,
2021
1923
  rootDom,
2022
1924
  ssrHydrateInfo,
2023
1925
  ssrHooks,
1926
+ document,
2024
1927
  callbacks: {
1928
+ updateCssOGStyle,
2025
1929
  mainChunkReady: ()=>{
2026
1930
  markTimingInternal('data_processor_start');
2027
1931
  let initData = config.initData;
@@ -2041,8 +1945,7 @@ function prepareMainThreadAPIs(backgroundThreadRpc, rootDom, createElement, comm
2041
1945
  v.content
2042
1946
  ])),
2043
1947
  nativeModulesMap,
2044
- napiModulesMap,
2045
- browserConfig
1948
+ napiModulesMap
2046
1949
  });
2047
1950
  if (ssrHydrateInfo) {
2048
1951
  for (const event of ssrHydrateInfo.events){
@@ -2087,7 +1990,6 @@ function prepareMainThreadAPIs(backgroundThreadRpc, rootDom, createElement, comm
2087
1990
  markTiming: (a, b)=>markTimingInternal(b, a),
2088
1991
  publishEvent,
2089
1992
  publicComponentEvent,
2090
- createElement,
2091
1993
  _I18nResourceTranslation: (options)=>{
2092
1994
  const matchedInitI18nResources = i18nResources.data?.find((i)=>getCacheI18nResourcesKey(i.options) === getCacheI18nResourcesKey(options));
2093
1995
  dispatchI18nResource(matchedInitI18nResources?.resource);
@@ -2097,9 +1999,8 @@ function prepareMainThreadAPIs(backgroundThreadRpc, rootDom, createElement, comm
2097
1999
  }
2098
2000
  });
2099
2001
  markTimingInternal('decode_end');
2100
- entry(mtsGlobalThis);
2002
+ await mtsRealm.loadScript(template.lepusCode.root);
2101
2003
  jsContext.__start();
2102
- return mtsGlobalThis;
2103
2004
  }
2104
2005
  return {
2105
2006
  startMainThread
@@ -2135,7 +2036,7 @@ const OperationType = {
2135
2036
  RemoveChild: 9,
2136
2037
  StyleDeclarationSetProperty: 10,
2137
2038
  StyleDeclarationRemoveProperty: 11,
2138
- SetInnerHTML: 12,
2039
+ SetTextContent: 12,
2139
2040
  sheetInsertRule: 13,
2140
2041
  sheetRuleUpdateCssText: 14
2141
2042
  };
@@ -2158,12 +2059,12 @@ class OffscreenCSSStyleDeclaration {
2158
2059
  const ancestorDocument = Symbol('ancestorDocument');
2159
2060
  const _attributes = Symbol('_attributes');
2160
2061
  const _children = Symbol('_children');
2161
- const innerHTML = Symbol('innerHTML');
2062
+ const textContent = Symbol('textContent');
2162
2063
  const _cssRuleContents = Symbol('_cssRuleContents');
2163
2064
  const OffscreenElement_uniqueId = Symbol('uniqueId');
2164
2065
  const _style = Symbol('_style');
2165
2066
  class OffscreenElement extends EventTarget {
2166
- [innerHTML] = '';
2067
+ [textContent] = '';
2167
2068
  [_style];
2168
2069
  [_attributes] = new Map();
2169
2070
  _parentElement = null;
@@ -2310,10 +2211,10 @@ class OffscreenElement extends EventTarget {
2310
2211
  this[ancestorDocument][enableEvent](type, this[OffscreenElement_uniqueId]);
2311
2212
  super.addEventListener(type, callback, options);
2312
2213
  }
2313
- set innerHTML(text1) {
2314
- this[ancestorDocument][operations].push(OperationType.SetInnerHTML, this[OffscreenElement_uniqueId], text1);
2214
+ set textContent(text1) {
2215
+ this[ancestorDocument][operations].push(OperationType.SetTextContent, this[OffscreenElement_uniqueId], text1);
2315
2216
  for (const child of this.children)child.remove();
2316
- this[innerHTML] = text1;
2217
+ this[textContent] = text1;
2317
2218
  if (this[_cssRuleContents]) this[_cssRuleContents] = [];
2318
2219
  }
2319
2220
  }
@@ -2740,7 +2641,7 @@ function escapeHtml(string) {
2740
2641
  }
2741
2642
  return lastIndex !== index ? html + str.substring(lastIndex, index) : html;
2742
2643
  }
2743
- function getInnerHTMLImpl(buffer, element, shadowrootTemplates) {
2644
+ function getTextContentImpl(buffer, element, shadowrootTemplates) {
2744
2645
  const localName = element.localName;
2745
2646
  buffer.push('<');
2746
2647
  buffer.push(localName);
@@ -2762,14 +2663,14 @@ function getInnerHTMLImpl(buffer, element, shadowrootTemplates) {
2762
2663
  buffer.push('<template shadowrootmode="open">', template, '</template>');
2763
2664
  }
2764
2665
  if (element[_cssRuleContents]?.length) buffer.push(...element[_cssRuleContents]);
2765
- if (element[innerHTML]) buffer.push(element[innerHTML]);
2766
- else for (const child of element[_children])getInnerHTMLImpl(buffer, child, shadowrootTemplates);
2666
+ if (element[textContent]) buffer.push(element[textContent]);
2667
+ else for (const child of element[_children])getTextContentImpl(buffer, child, shadowrootTemplates);
2767
2668
  buffer.push('</');
2768
2669
  buffer.push(localName);
2769
2670
  buffer.push('>');
2770
2671
  }
2771
2672
  function dumpHTMLString(buffer, element, shadowrootTemplates) {
2772
- for (const child of element[_children])getInnerHTMLImpl(buffer, child, shadowrootTemplates);
2673
+ for (const child of element[_children])getTextContentImpl(buffer, child, shadowrootTemplates);
2773
2674
  }
2774
2675
  const builtinElementTemplates = {
2775
2676
  'scroll-view': templateScrollView,
@@ -2810,7 +2711,39 @@ async function createLynxView(config) {
2810
2711
  });
2811
2712
  const i18nResources = new I18nResources();
2812
2713
  const events = [];
2813
- const { startMainThread } = prepareMainThreadAPIs(backgroundThreadRpc, offscreenDocument, offscreenDocument.createElement.bind(offscreenDocument), ()=>{
2714
+ const mtsVMContext = node_vm.createContext(node_vm.constants.DONT_CONTEXTIFY);
2715
+ Object.assign(mtsVMContext, {
2716
+ document: offscreenDocument,
2717
+ module: {
2718
+ exports: null
2719
+ }
2720
+ });
2721
+ const loadScriptSync = (url)=>{
2722
+ const scriptContent = node_fs.readFileSync(url);
2723
+ const script = new node_vm.Script(scriptContent.toString(), {
2724
+ filename: url
2725
+ });
2726
+ return script.runInContext(mtsVMContext);
2727
+ };
2728
+ const loadScript = async (url)=>new Promise((resolve, reject)=>{
2729
+ node_fs.readFile(url, (err, data)=>{
2730
+ if (err) return void reject(err);
2731
+ try {
2732
+ const script = new node_vm.Script(data.toString(), {
2733
+ filename: url
2734
+ });
2735
+ const result = script.runInContext(mtsVMContext);
2736
+ resolve(result);
2737
+ } catch (e) {
2738
+ reject(e);
2739
+ }
2740
+ });
2741
+ });
2742
+ const { startMainThread } = prepareMainThreadAPIs(backgroundThreadRpc, offscreenDocument, offscreenDocument, {
2743
+ globalWindow: mtsVMContext,
2744
+ loadScript,
2745
+ loadScriptSync
2746
+ }, ()=>{
2814
2747
  firstPaintReady();
2815
2748
  }, ()=>{}, ()=>{}, ()=>{}, ()=>{}, (initI18nResources)=>{
2816
2749
  i18nResources.setData(initI18nResources);
@@ -2825,7 +2758,7 @@ async function createLynxView(config) {
2825
2758
  ]);
2826
2759
  }
2827
2760
  });
2828
- const runtime = await startMainThread({
2761
+ await startMainThread({
2829
2762
  template,
2830
2763
  initData,
2831
2764
  globalProps,
@@ -2844,7 +2777,7 @@ async function createLynxView(config) {
2844
2777
  };
2845
2778
  async function renderToString() {
2846
2779
  await firstPaintReadyPromise;
2847
- const ssrEncodeData = runtime?.ssrEncode?.();
2780
+ const ssrEncodeData = mtsVMContext?.ssrEncode?.();
2848
2781
  const ssrDumpInfo = {
2849
2782
  ssrEncodeData,
2850
2783
  events
@@ -1,19 +1,20 @@
1
+ export const __webpack_id__ = "8";
1
2
  export const __webpack_ids__ = [
2
- "501"
3
+ "8"
3
4
  ];
4
5
  export const __webpack_modules__ = {
5
6
  "../web-style-transformer/dist/legacy.js": function(module, __webpack_exports__, __webpack_require__) {
6
7
  __webpack_require__.a(module, async function(__webpack_handle_async_dependencies__, __webpack_async_result__) {
7
8
  try {
8
9
  __webpack_require__.d(__webpack_exports__, {
9
- C2: ()=>_legacy_bg_js__WEBPACK_IMPORTED_MODULE_0__.C2,
10
- Or: ()=>_legacy_bg_js__WEBPACK_IMPORTED_MODULE_0__.Or,
11
- a9: ()=>_legacy_bg_js__WEBPACK_IMPORTED_MODULE_0__.a9,
12
- h4: ()=>_legacy_bg_js__WEBPACK_IMPORTED_MODULE_0__.h4,
13
- oT: ()=>_legacy_bg_js__WEBPACK_IMPORTED_MODULE_0__.oT,
14
- pE: ()=>_legacy_bg_js__WEBPACK_IMPORTED_MODULE_0__.pE,
15
- ug: ()=>_legacy_bg_js__WEBPACK_IMPORTED_MODULE_0__.ug,
16
- xJ: ()=>_legacy_bg_js__WEBPACK_IMPORTED_MODULE_0__.xJ
10
+ M2: ()=>_legacy_bg_js__WEBPACK_IMPORTED_MODULE_0__.M2,
11
+ Qn: ()=>_legacy_bg_js__WEBPACK_IMPORTED_MODULE_0__.Qn,
12
+ aC: ()=>_legacy_bg_js__WEBPACK_IMPORTED_MODULE_0__.aC,
13
+ bk: ()=>_legacy_bg_js__WEBPACK_IMPORTED_MODULE_0__.bk,
14
+ iG: ()=>_legacy_bg_js__WEBPACK_IMPORTED_MODULE_0__.iG,
15
+ lI: ()=>_legacy_bg_js__WEBPACK_IMPORTED_MODULE_0__.lI,
16
+ tZ: ()=>_legacy_bg_js__WEBPACK_IMPORTED_MODULE_0__.tZ,
17
+ yc: ()=>_legacy_bg_js__WEBPACK_IMPORTED_MODULE_0__.yc
17
18
  });
18
19
  var _legacy_bg_wasm__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("../web-style-transformer/dist/legacy_bg.wasm");
19
20
  var _legacy_bg_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("../web-style-transformer/dist/legacy_bg.js");
@@ -21,7 +22,7 @@ export const __webpack_modules__ = {
21
22
  _legacy_bg_wasm__WEBPACK_IMPORTED_MODULE_1__
22
23
  ]);
23
24
  _legacy_bg_wasm__WEBPACK_IMPORTED_MODULE_1__ = (__webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__)[0];
24
- (0, _legacy_bg_js__WEBPACK_IMPORTED_MODULE_0__.oT)(_legacy_bg_wasm__WEBPACK_IMPORTED_MODULE_1__);
25
+ (0, _legacy_bg_js__WEBPACK_IMPORTED_MODULE_0__.lI)(_legacy_bg_wasm__WEBPACK_IMPORTED_MODULE_1__);
25
26
  __webpack_async_result__();
26
27
  } catch (e) {
27
28
  __webpack_async_result__(e);
@@ -30,14 +31,14 @@ export const __webpack_modules__ = {
30
31
  },
31
32
  "../web-style-transformer/dist/legacy_bg.js": function(module, __webpack_exports__, __webpack_require__) {
32
33
  __webpack_require__.d(__webpack_exports__, {
33
- C2: ()=>__wbg_push_737cfc8c1432c2c6,
34
- Or: ()=>__wbindgen_throw,
35
- a9: ()=>__wbg_new_78feb108b6472713,
36
- h4: ()=>__wbindgen_string_new,
37
- oT: ()=>__wbg_set_wasm,
38
- pE: ()=>transform_raw_u16_inline_style_ptr_parsed,
39
- ug: ()=>__wbindgen_object_drop_ref,
40
- xJ: ()=>transform_raw_u16_inline_style_ptr
34
+ M2: ()=>__wbg_new_78feb108b6472713,
35
+ Qn: ()=>__wbindgen_throw,
36
+ aC: ()=>transform_raw_u16_inline_style_ptr,
37
+ bk: ()=>__wbindgen_object_drop_ref,
38
+ iG: ()=>transform_raw_u16_inline_style_ptr_parsed,
39
+ lI: ()=>__wbg_set_wasm,
40
+ tZ: ()=>__wbg_push_737cfc8c1432c2c6,
41
+ yc: ()=>__wbindgen_string_new
41
42
  });
42
43
  module = __webpack_require__.hmd(module);
43
44
  let wasm;
@@ -178,15 +179,15 @@ export const __webpack_modules__ = {
178
179
  try {
179
180
  __webpack_require__.r(__webpack_exports__);
180
181
  __webpack_require__.d(__webpack_exports__, {
181
- __wbg_new_78feb108b6472713: ()=>_dist_legacy_js__WEBPACK_IMPORTED_MODULE_0__.a9,
182
- __wbg_push_737cfc8c1432c2c6: ()=>_dist_legacy_js__WEBPACK_IMPORTED_MODULE_0__.C2,
183
- __wbg_set_wasm: ()=>_dist_legacy_js__WEBPACK_IMPORTED_MODULE_0__.oT,
184
- __wbindgen_object_drop_ref: ()=>_dist_legacy_js__WEBPACK_IMPORTED_MODULE_0__.ug,
185
- __wbindgen_string_new: ()=>_dist_legacy_js__WEBPACK_IMPORTED_MODULE_0__.h4,
186
- __wbindgen_throw: ()=>_dist_legacy_js__WEBPACK_IMPORTED_MODULE_0__.Or,
182
+ __wbg_new_78feb108b6472713: ()=>_dist_legacy_js__WEBPACK_IMPORTED_MODULE_0__.M2,
183
+ __wbg_push_737cfc8c1432c2c6: ()=>_dist_legacy_js__WEBPACK_IMPORTED_MODULE_0__.tZ,
184
+ __wbg_set_wasm: ()=>_dist_legacy_js__WEBPACK_IMPORTED_MODULE_0__.lI,
185
+ __wbindgen_object_drop_ref: ()=>_dist_legacy_js__WEBPACK_IMPORTED_MODULE_0__.bk,
186
+ __wbindgen_string_new: ()=>_dist_legacy_js__WEBPACK_IMPORTED_MODULE_0__.yc,
187
+ __wbindgen_throw: ()=>_dist_legacy_js__WEBPACK_IMPORTED_MODULE_0__.Qn,
187
188
  memory: ()=>_dist_legacy_bg_wasm__WEBPACK_IMPORTED_MODULE_1__.memory,
188
- transform_raw_u16_inline_style_ptr: ()=>_dist_legacy_js__WEBPACK_IMPORTED_MODULE_0__.xJ,
189
- transform_raw_u16_inline_style_ptr_parsed: ()=>_dist_legacy_js__WEBPACK_IMPORTED_MODULE_0__.pE
189
+ transform_raw_u16_inline_style_ptr: ()=>_dist_legacy_js__WEBPACK_IMPORTED_MODULE_0__.aC,
190
+ transform_raw_u16_inline_style_ptr_parsed: ()=>_dist_legacy_js__WEBPACK_IMPORTED_MODULE_0__.iG
190
191
  });
191
192
  var _dist_legacy_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("../web-style-transformer/dist/legacy.js");
192
193
  var _dist_legacy_bg_wasm__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("../web-style-transformer/dist/legacy_bg.wasm");
@@ -205,11 +206,11 @@ export const __webpack_modules__ = {
205
206
  var WEBPACK_IMPORTED_MODULE_0 = __webpack_require__("../web-style-transformer/dist/legacy_bg.js");
206
207
  module.exports = __webpack_require__.v(exports, module.id, "578076972e1e5ffd", {
207
208
  "./legacy_bg.js": {
208
- __wbg_new_78feb108b6472713: WEBPACK_IMPORTED_MODULE_0.a9,
209
- __wbindgen_string_new: WEBPACK_IMPORTED_MODULE_0.h4,
210
- __wbg_push_737cfc8c1432c2c6: WEBPACK_IMPORTED_MODULE_0.C2,
211
- __wbindgen_object_drop_ref: WEBPACK_IMPORTED_MODULE_0.ug,
212
- __wbindgen_throw: WEBPACK_IMPORTED_MODULE_0.Or
209
+ __wbg_new_78feb108b6472713: WEBPACK_IMPORTED_MODULE_0.M2,
210
+ __wbindgen_string_new: WEBPACK_IMPORTED_MODULE_0.yc,
211
+ __wbg_push_737cfc8c1432c2c6: WEBPACK_IMPORTED_MODULE_0.tZ,
212
+ __wbindgen_object_drop_ref: WEBPACK_IMPORTED_MODULE_0.bk,
213
+ __wbindgen_throw: WEBPACK_IMPORTED_MODULE_0.Qn
213
214
  }
214
215
  });
215
216
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/web-core-server",
3
- "version": "0.15.7",
3
+ "version": "0.16.0",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "keywords": [],
@@ -25,11 +25,11 @@
25
25
  "devDependencies": {
26
26
  "rsbuild-plugin-arethetypeswrong": "0.1.1",
27
27
  "rsbuild-plugin-publint": "0.3.3",
28
- "@lynx-js/offscreen-document": "0.1.3",
28
+ "@lynx-js/offscreen-document": "0.1.4",
29
+ "@lynx-js/web-constants": "0.16.0",
29
30
  "@lynx-js/web-elements-template": "0.8.4",
30
- "@lynx-js/web-mainthread-apis": "0.15.7",
31
- "@lynx-js/web-worker-rpc": "0.15.7",
32
- "@lynx-js/web-constants": "0.15.7"
31
+ "@lynx-js/web-mainthread-apis": "0.16.0",
32
+ "@lynx-js/web-worker-rpc": "0.16.0"
33
33
  },
34
34
  "scripts": {
35
35
  "build": "rslib build",