@lynx-js/web-core-server 0.15.6 → 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,21 @@
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
+
17
+ ## 0.15.7
18
+
3
19
  ## 0.15.6
4
20
 
5
21
  ### Patch Changes
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'
@@ -469,12 +466,12 @@ class Rpc {
469
466
  };
470
467
  }
471
468
  #onMessage = async (message)=>{
472
- const handler1 = this.#handlerMap.get(message.name);
473
- if (handler1) {
469
+ const handler = this.#handlerMap.get(message.name);
470
+ if (handler) {
474
471
  const lockViewer = message.sync ? new Int32Array(message.lock) : void 0;
475
472
  const replyTempEndpoint = !message.sync && message.retId ? Rpc.createRetEndpoint(message.retId) : void 0;
476
473
  try {
477
- const result = await handler1(...message.data);
474
+ const result = await handler(...message.data);
478
475
  let retData, transfer = [];
479
476
  if (message.sync) retData = result;
480
477
  else if (message.hasTransfer) ({ data: retData, transfer } = result || {});
@@ -517,8 +514,8 @@ class Rpc {
517
514
  createCall(endpoint) {
518
515
  return (...args)=>this.invoke(endpoint, args);
519
516
  }
520
- registerHandler(endpoint, handler1) {
521
- this.#handlerMap.set(endpoint.name, handler1);
517
+ registerHandler(endpoint, handler) {
518
+ this.#handlerMap.set(endpoint.name, handler);
522
519
  const currentCache = this.#messageCache[endpoint.name];
523
520
  if (currentCache?.length) {
524
521
  this.#messageCache[endpoint.name] = void 0;
@@ -737,114 +734,49 @@ class LynxCrossThreadContext extends EventTarget {
737
734
  });
738
735
  }
739
736
  }
740
- const mainThreadInjectVars = [
741
- 'lynx',
742
- 'globalThis',
743
- '_ReportError',
744
- '_SetSourceMapRelease',
745
- '__AddConfig',
746
- '__AddDataset',
747
- '__GetAttributes',
748
- '__GetComponentID',
749
- '__GetDataByKey',
750
- '__GetDataset',
751
- '__GetElementConfig',
752
- '__GetElementUniqueID',
753
- '__GetID',
754
- '__GetTag',
755
- '__SetAttribute',
756
- '__SetConfig',
757
- '__SetDataset',
758
- '__SetID',
759
- '__UpdateComponentID',
760
- '__UpdateComponentInfo',
761
- '__GetConfig',
762
- '__GetAttributeByName',
763
- '__UpdateListCallbacks',
764
- '__AppendElement',
765
- '__ElementIsEqual',
766
- '__FirstElement',
767
- '__GetChildren',
768
- '__GetParent',
769
- '__InsertElementBefore',
770
- '__LastElement',
771
- '__NextElement',
772
- '__RemoveElement',
773
- '__ReplaceElement',
774
- '__ReplaceElements',
775
- '__SwapElement',
776
- '__CreateComponent',
777
- '__CreateElement',
778
- '__CreatePage',
779
- '__CreateView',
780
- '__CreateText',
781
- '__CreateRawText',
782
- '__CreateImage',
783
- '__CreateScrollView',
784
- '__CreateWrapperElement',
785
- '__CreateList',
786
- '__AddEvent',
787
- '__GetEvent',
788
- '__GetEvents',
789
- '__SetEvents',
790
- '__AddClass',
791
- '__SetClasses',
792
- '__GetClasses',
793
- '__AddInlineStyle',
794
- '__SetInlineStyles',
795
- '__SetCSSId',
796
- '__OnLifecycleEvent',
797
- '__FlushElementTree',
798
- '__LoadLepusChunk',
799
- 'SystemInfo',
800
- '_I18nResourceTranslation',
801
- '_AddEventListener',
802
- '__GetTemplateParts',
803
- '__MarkPartElement',
804
- '__MarkTemplateElement',
805
- '__GetPageElement',
806
- '__ElementFromBinary'
807
- ];
808
- const backgroundInjectVars = [
809
- 'NativeModules',
810
- 'globalThis',
811
- 'lynx',
812
- 'lynxCoreInject',
813
- 'SystemInfo'
737
+ const currentSupportedTemplateVersion = 2;
738
+ const globalDisallowedVars = [
739
+ 'navigator',
740
+ 'postMessage'
814
741
  ];
815
- const backgroundInjectWithBind = [
816
- 'Card',
817
- '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
+ }
818
756
  ];
819
- const generateModuleContent = (content, injectVars, injectWithBind, muteableVars, isESM)=>[
757
+ const generateModuleContent = (content)=>[
820
758
  '//# allFunctionsCalledOnLoad\n',
821
- isESM ? 'export default ' : 'globalThis.module.exports =',
822
- 'function(lynx_runtime) {',
823
- 'const module= {exports:{}};let exports = module.exports;',
824
- 'var {',
825
- injectVars.join(','),
826
- '} = lynx_runtime;',
827
- ...injectWithBind.map((nm)=>`const ${nm} = lynx_runtime.${nm}?.bind(lynx_runtime);`),
828
- ';var globDynamicComponentEntry = \'__Card__\';',
829
- 'var {__globalProps} = lynx;',
830
- 'lynx_runtime._updateVars=()=>{',
831
- ...muteableVars.map((nm)=>`${nm} = lynx_runtime.__lynxGlobalBindingValues.${nm};`),
832
- '};\n',
759
+ '"use strict";\n',
760
+ `(() => {const ${globalDisallowedVars.join('=void 0,')}=void 0;module.exports = `,
833
761
  content,
834
- '\n return module.exports;}'
762
+ '\n})()'
835
763
  ].join('');
836
- async function generateJavascriptUrl(obj, injectVars, injectWithBind, muteableVars, createJsModuleUrl, isESM, templateName) {
764
+ async function generateJavascriptUrl(obj, createJsModuleUrl, templateName) {
837
765
  const processEntry = async ([name, content])=>[
838
766
  name,
839
- await createJsModuleUrl(generateModuleContent(content, injectVars.concat(muteableVars), injectWithBind, muteableVars, isESM), `${templateName}-${name.replaceAll('/', '')}.js`)
767
+ await createJsModuleUrl(generateModuleContent(content), `${templateName}-${name.replaceAll('/', '')}.js`)
840
768
  ];
841
769
  return Promise.all(Object.entries(obj).filter(([_, content])=>'string' == typeof content).map(processEntry)).then(Object.fromEntries);
842
770
  }
843
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);
844
776
  return {
845
777
  ...template,
846
- lepusCode: await generateJavascriptUrl(template.lepusCode, mainThreadInjectVars, [], globalMuteableVars, createJsModuleUrl, true, templateName),
847
- manifest: await generateJavascriptUrl(template.manifest, backgroundInjectVars, backgroundInjectWithBind, [], createJsModuleUrl, false, templateName)
778
+ lepusCode: await generateJavascriptUrl(template.lepusCode, createJsModuleUrl, templateName),
779
+ manifest: await generateJavascriptUrl(template.manifest, createJsModuleUrl, templateName)
848
780
  };
849
781
  }
850
782
  function registerCallLepusMethodHandler(rpc, runtime) {
@@ -856,163 +788,34 @@ function registerGetCustomSectionHandler(rpc, customSections) {
856
788
  rpc.registerHandler(getCustomSectionsEndpoint, (key)=>customSections[key]?.content);
857
789
  }
858
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;
859
797
  return {
860
798
  getJSContext () {
861
799
  return config.jsContext;
862
800
  },
863
801
  requestAnimationFrame (cb) {
864
- return requestAnimationFrame(cb);
802
+ return requestAnimationFrameBrowserImpl(cb);
865
803
  },
866
- cancelAnimationFrame (handler1) {
867
- return cancelAnimationFrame(handler1);
804
+ cancelAnimationFrame (handler) {
805
+ return cancelAnimationFrameBrowserImpl(handler);
868
806
  },
869
807
  __globalProps: config.globalProps,
870
808
  getCustomSectionSync (key) {
871
- return config.customSections[key]?.content;
809
+ return config.lynxTemplate.customSections[key]?.content;
872
810
  },
873
811
  markPipelineTiming: config.callbacks.markTiming,
874
- SystemInfo
875
- };
876
- }
877
- const referenceTypes = async ()=>WebAssembly.validate(new Uint8Array([
878
- 0,
879
- 97,
880
- 115,
881
- 109,
882
- 1,
883
- 0,
884
- 0,
885
- 0,
886
- 1,
887
- 4,
888
- 1,
889
- 96,
890
- 0,
891
- 0,
892
- 3,
893
- 2,
894
- 1,
895
- 0,
896
- 10,
897
- 7,
898
- 1,
899
- 5,
900
- 0,
901
- 208,
902
- 112,
903
- 26,
904
- 11
905
- ]));
906
- let wasm;
907
- async function initWasm() {
908
- const supportsReferenceTypes = await referenceTypes();
909
- 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"));
910
- }
911
- function transformInlineStyleString(str) {
912
- return wasm.transform_raw_u16_inline_style_ptr(str) ?? str;
913
- }
914
- function transformParsedStyles(styles) {
915
- let childStyle = [];
916
- let transformedStyle = [];
917
- for (const [property, value] of styles){
918
- const transformedResult = wasm.transform_raw_u16_inline_style_ptr_parsed(property, value);
919
- if (transformedResult) {
920
- const [transformedStyleForCurrent, childStyleForCurrent] = transformedResult;
921
- transformedStyle = transformedStyle.concat(transformedStyleForCurrent);
922
- if (childStyleForCurrent) childStyle = childStyle.concat(childStyleForCurrent);
923
- } else transformedStyle.push([
924
- property,
925
- value
926
- ]);
927
- }
928
- return {
929
- childStyle,
930
- transformedStyle
812
+ SystemInfo,
813
+ setTimeout: setTimeoutBrowserImpl,
814
+ clearTimeout: clearTimeoutBrowserImpl,
815
+ setInterval: setIntervalBrowserImpl,
816
+ clearInterval: clearIntervalBrowserImpl
931
817
  };
932
818
  }
933
- function flattenStyleInfo(styleInfo, enableCSSSelector) {
934
- function flattenOneStyleInfo(cssId) {
935
- const oneInfo = styleInfo[cssId];
936
- const imports = oneInfo?.imports;
937
- if (oneInfo && imports?.length) {
938
- for (const im of imports){
939
- const flatInfo = flattenOneStyleInfo(im);
940
- if (flatInfo) {
941
- oneInfo.content.push(...flatInfo.content);
942
- oneInfo.rules.push(...enableCSSSelector ? flatInfo.rules : flatInfo.rules.map((i)=>({
943
- ...i
944
- })));
945
- }
946
- }
947
- oneInfo.imports = void 0;
948
- }
949
- return oneInfo;
950
- }
951
- Object.keys(styleInfo).map((cssId)=>{
952
- flattenOneStyleInfo(cssId);
953
- });
954
- }
955
- function transformToWebCss(styleInfo) {
956
- for (const cssInfos of Object.values(styleInfo))for (const rule of cssInfos.rules){
957
- const { sel: selectors, decl: declarations } = rule;
958
- const { transformedStyle, childStyle } = transformParsedStyles(declarations);
959
- rule.decl = transformedStyle;
960
- if (childStyle.length > 0) cssInfos.rules.push({
961
- sel: selectors.map((selector)=>selector.toSpliced(-2, 1, [
962
- '>'
963
- ], [
964
- '*'
965
- ], [], [], [])),
966
- decl: childStyle
967
- });
968
- }
969
- }
970
- function genCssContent(styleInfo, pageConfig) {
971
- function getExtraSelectors(cssId) {
972
- let suffix = '';
973
- if (pageConfig.enableRemoveCSSScope) suffix += `[${lynxTagAttribute}]`;
974
- else if (void 0 !== cssId) suffix += `[${cssIdAttribute}="${cssId}"]`;
975
- else suffix += `[${lynxTagAttribute}]`;
976
- return suffix;
977
- }
978
- const finalCssContent = [];
979
- for (const [cssId, cssInfos] of Object.entries(styleInfo)){
980
- const suffix = getExtraSelectors(cssId);
981
- const declarationContent = cssInfos.rules.map((rule)=>{
982
- const { sel: selectorList, decl: declarations } = rule;
983
- const selectorString = selectorList.map((selectors)=>selectors.toSpliced(-4, 0, [
984
- suffix
985
- ]).flat().join('')).join(',');
986
- const declarationString = declarations.map(([k, v])=>`${k}:${v};`).join('');
987
- return `${selectorString}{${declarationString}}`;
988
- }).join('');
989
- finalCssContent.push(...cssInfos.content, declarationContent);
990
- }
991
- return finalCssContent.join('\n');
992
- }
993
- function genCssOGInfo(styleInfo) {
994
- return Object.fromEntries(Object.entries(styleInfo).map(([cssId, cssInfos])=>{
995
- const oneCssOGInfo = {};
996
- cssInfos.rules = cssInfos.rules.filter((oneCssInfo)=>{
997
- oneCssInfo.sel = oneCssInfo.sel.filter((selectorList)=>{
998
- const [classSelectors, pseudoClassSelectors, pseudoElementSelectors, combinator] = selectorList;
999
- if (1 === classSelectors.length && '.' === classSelectors[0][0] && 0 === pseudoClassSelectors.length && 0 === pseudoElementSelectors.length && 0 === combinator.length) {
1000
- const selectorName = classSelectors[0].substring(1);
1001
- const currentDeclarations = oneCssOGInfo[selectorName];
1002
- if (currentDeclarations) currentDeclarations.push(...oneCssInfo.decl);
1003
- else oneCssOGInfo[selectorName] = oneCssInfo.decl;
1004
- return false;
1005
- }
1006
- return true;
1007
- });
1008
- return oneCssInfo.sel.length > 0;
1009
- });
1010
- return [
1011
- cssId,
1012
- oneCssOGInfo
1013
- ];
1014
- }));
1015
- }
1016
819
  const cacheForCamelize = {};
1017
820
  function camelize(str) {
1018
821
  if (cacheForCamelize[str]) return cacheForCamelize[str];
@@ -1253,6 +1056,62 @@ V('offset-distance');
1253
1056
  function queryCSSProperty(index) {
1254
1057
  return cssPropertyMap[index];
1255
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
+ }
1256
1115
  var uppercasePattern = /[A-Z]/g;
1257
1116
  var msPattern = /^ms-/;
1258
1117
  var hyphenate_style_name_cache = {};
@@ -1462,17 +1321,6 @@ function createCrossThreadEvent(domEvent, eventName) {
1462
1321
  ...otherProperties
1463
1322
  };
1464
1323
  }
1465
- function decodeCssOG(classes, styleInfo, cssId) {
1466
- const classList = classes.split(' ').filter((e)=>e);
1467
- let declarations = [];
1468
- const currentStyleInfo = styleInfo[cssId ?? '0'];
1469
- if (currentStyleInfo) for (const oneClassName of classList){
1470
- const oneRule = currentStyleInfo[oneClassName];
1471
- if (oneRule) declarations.push(...oneRule);
1472
- }
1473
- else console.warn(`[lynx-web] cannot find styleinfo for cssid ${cssId}`);
1474
- return declarations.map(([property, value])=>`${property}:${value};`).join('');
1475
- }
1476
1324
  const exposureRelatedAttributes = new Set([
1477
1325
  'exposure-id',
1478
1326
  'exposure-area',
@@ -1487,36 +1335,13 @@ const exposureRelatedAttributes = new Set([
1487
1335
  ]);
1488
1336
  function createMainThreadGlobalThis(config) {
1489
1337
  let timingFlags = [];
1490
- let renderPage;
1491
- 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;
1492
1340
  const lynxUniqueIdToElement = ssrHydrateInfo?.lynxUniqueIdToElement ?? [];
1493
- const lynxUniqueIdToStyleRulesIndex = ssrHydrateInfo?.lynxUniqueIdToStyleRulesIndex ?? [];
1494
1341
  const elementToRuntimeInfoMap = new WeakMap();
1495
1342
  let pageElement = lynxUniqueIdToElement[1]?.deref();
1496
1343
  let uniqueIdInc = lynxUniqueIdToElement.length || 1;
1497
- const varsUpdateHandlers = [];
1498
- const lynxGlobalBindingValues = {};
1499
1344
  const exposureChangedElements = new Set();
1500
- flattenStyleInfo(styleInfo, pageConfig.enableCSSSelector);
1501
- transformToWebCss(styleInfo);
1502
- const cssOGInfo = pageConfig.enableCSSSelector ? {} : genCssOGInfo(styleInfo);
1503
- let cardStyleElement;
1504
- if (ssrHydrateInfo?.cardStyleElement) cardStyleElement = ssrHydrateInfo.cardStyleElement;
1505
- else {
1506
- cardStyleElement = callbacks.createElement('style');
1507
- cardStyleElement.innerHTML = genCssContent(styleInfo, pageConfig);
1508
- rootDom.append(cardStyleElement);
1509
- }
1510
- const cardStyleElementSheet = cardStyleElement.sheet;
1511
- const updateCssOGStyle = (uniqueId, newStyles)=>{
1512
- if (void 0 !== lynxUniqueIdToStyleRulesIndex[uniqueId]) {
1513
- const rule = cardStyleElementSheet.cssRules[lynxUniqueIdToStyleRulesIndex[uniqueId]];
1514
- rule.style.cssText = newStyles;
1515
- } else {
1516
- const index = cardStyleElementSheet.insertRule(`[${lynxUniqueIdAttribute}="${uniqueId}"]{${newStyles}}`, cardStyleElementSheet.cssRules.length);
1517
- lynxUniqueIdToStyleRulesIndex[uniqueId] = index;
1518
- }
1519
- };
1520
1345
  const commonHandler = (event)=>{
1521
1346
  if (!event.currentTarget) return;
1522
1347
  const currentTarget = event.currentTarget;
@@ -1537,7 +1362,7 @@ function createMainThreadGlobalThis(config) {
1537
1362
  if (hname) {
1538
1363
  crossThreadEvent.target.elementRefptr = event.target;
1539
1364
  if (crossThreadEvent.currentTarget) crossThreadEvent.currentTarget.elementRefptr = event.currentTarget;
1540
- mtsGlobalThis.runWorklet?.(hname.value, [
1365
+ mtsRealm.globalWindow.runWorklet?.(hname.value, [
1541
1366
  crossThreadEvent
1542
1367
  ]);
1543
1368
  }
@@ -1595,8 +1420,8 @@ function createMainThreadGlobalThis(config) {
1595
1420
  {
1596
1421
  eventName = eventName.toLowerCase();
1597
1422
  const isCapture = eventType.startsWith('capture');
1598
- const handler1 = isCapture ? runtimeInfo.eventHandlerMap[eventName]?.capture : runtimeInfo.eventHandlerMap[eventName]?.bind;
1599
- return handler1?.handler;
1423
+ const handler = isCapture ? runtimeInfo.eventHandlerMap[eventName]?.capture : runtimeInfo.eventHandlerMap[eventName]?.bind;
1424
+ return handler?.handler;
1600
1425
  }
1601
1426
  };
1602
1427
  const __GetEvents = (element)=>{
@@ -1606,11 +1431,11 @@ function createMainThreadGlobalThis(config) {
1606
1431
  info.bind,
1607
1432
  info.capture
1608
1433
  ])if (atomInfo) {
1609
- const { type, handler: handler1 } = atomInfo;
1610
- if (handler1) eventInfos.push({
1434
+ const { type, handler } = atomInfo;
1435
+ if (handler) eventInfos.push({
1611
1436
  type: type,
1612
1437
  name: lynxEventName,
1613
- function: handler1
1438
+ function: handler
1614
1439
  });
1615
1440
  }
1616
1441
  return eventInfos;
@@ -1621,7 +1446,7 @@ function createMainThreadGlobalThis(config) {
1621
1446
  const __CreateElement = (tag, parentComponentUniqueId)=>{
1622
1447
  const uniqueId = uniqueIdInc++;
1623
1448
  const htmlTag = tagMap[tag] ?? tag;
1624
- const element = callbacks.createElement(htmlTag);
1449
+ const element = document.createElement(htmlTag);
1625
1450
  lynxUniqueIdToElement[uniqueId] = new WeakRef(element);
1626
1451
  const parentComponentCssID = lynxUniqueIdToElement[parentComponentUniqueId]?.deref()?.getAttribute(cssIdAttribute);
1627
1452
  parentComponentCssID && '0' !== parentComponentCssID && element.setAttribute(cssIdAttribute, parentComponentCssID);
@@ -1702,7 +1527,7 @@ function createMainThreadGlobalThis(config) {
1702
1527
  elementToRuntimeInfoMap.set(element, runtimeInfo);
1703
1528
  };
1704
1529
  const __SwapElement = (childA, childB)=>{
1705
- const temp = callbacks.createElement('div');
1530
+ const temp = document.createElement('div');
1706
1531
  childA.replaceWith(temp);
1707
1532
  childB.replaceWith(childA);
1708
1533
  temp.replaceWith(childB);
@@ -1717,21 +1542,24 @@ function createMainThreadGlobalThis(config) {
1717
1542
  const __AddClassForCSSOG = (element, className)=>{
1718
1543
  const newClassName = ((element.getAttribute('class') ?? '') + ' ' + className).trim();
1719
1544
  element.setAttribute('class', newClassName);
1720
- const newStyleStr = decodeCssOG(newClassName, cssOGInfo, element.getAttribute(cssIdAttribute));
1721
- 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);
1722
1548
  };
1723
1549
  const __SetClassesForCSSOG = (element, classNames)=>{
1724
1550
  __SetClasses(element, classNames);
1725
- const newStyleStr = decodeCssOG(classNames ?? '', cssOGInfo, element.getAttribute(cssIdAttribute));
1726
- 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);
1727
1554
  };
1728
1555
  const __LoadLepusChunk = (path)=>{
1729
- const lepusModule = lepusCode[`${path}`];
1730
- if (!lepusModule) return false;
1731
- {
1732
- const entry = lepusModule.exports;
1733
- entry?.(mtsGlobalThis);
1556
+ try {
1557
+ path = lepusCode?.[path] ?? path;
1558
+ mtsRealm.loadScriptSync(path);
1734
1559
  return true;
1560
+ } catch (e) {
1561
+ console.error(`failed to load lepus chunk ${path}`, e);
1562
+ return false;
1735
1563
  }
1736
1564
  };
1737
1565
  const __FlushElementTree = (_subTree, options)=>{
@@ -1771,14 +1599,14 @@ function createMainThreadGlobalThis(config) {
1771
1599
  }
1772
1600
  };
1773
1601
  const __ElementFromBinary = (templateId, parentComponentUniId)=>{
1774
- const elementTemplateData = config.elementTemplate[templateId];
1602
+ const elementTemplateData = elementTemplate[templateId];
1775
1603
  if (elementTemplateData) {
1776
1604
  let clonedElements;
1777
1605
  if (templateIdToTemplate[templateId]) clonedElements = Array.from(templateIdToTemplate[templateId].content.cloneNode(true).children);
1778
1606
  else {
1779
1607
  clonedElements = elementTemplateData.map((data)=>createElementForElementTemplateData(data, parentComponentUniId));
1780
1608
  if (rootDom.cloneNode) {
1781
- const template = callbacks.createElement('template');
1609
+ const template = document.createElement('template');
1782
1610
  template.content.append(...clonedElements);
1783
1611
  templateIdToTemplate[templateId] = template;
1784
1612
  rootDom.append(template);
@@ -1866,41 +1694,23 @@ function createMainThreadGlobalThis(config) {
1866
1694
  _SetSourceMapRelease: (errInfo)=>release = errInfo?.release,
1867
1695
  __OnLifecycleEvent: callbacks.__OnLifecycleEvent,
1868
1696
  __FlushElementTree,
1869
- __lynxGlobalBindingValues: lynxGlobalBindingValues,
1870
1697
  _I18nResourceTranslation: callbacks._I18nResourceTranslation,
1871
1698
  _AddEventListener: ()=>{},
1872
- set _updateVars (handler){
1873
- varsUpdateHandlers.push(handler);
1874
- },
1875
- set renderPage (foo){
1876
- renderPage = foo;
1877
- queueMicrotask(callbacks.mainChunkReady);
1878
- },
1879
- get renderPage () {
1880
- return renderPage;
1881
- }
1699
+ renderPage: void 0
1882
1700
  };
1883
- mtsGlobalThis.globalThis = new Proxy(mtsGlobalThis, {
1884
- get: (target, prop)=>{
1885
- if ('globalThis' === prop) return target;
1886
- return target[prop] ?? globalThis[prop];
1701
+ Object.assign(mtsRealm.globalWindow, mtsGlobalThis);
1702
+ Object.defineProperty(mtsRealm.globalWindow, 'renderPage', {
1703
+ get () {
1704
+ return mtsGlobalThis.renderPage;
1887
1705
  },
1888
- set: (target, prop, value)=>{
1889
- target[prop] = value;
1890
- return true;
1706
+ set (v) {
1707
+ mtsGlobalThis.renderPage = v;
1708
+ queueMicrotask(callbacks.mainChunkReady);
1891
1709
  },
1892
- ownKeys (target) {
1893
- return Reflect.ownKeys(target).filter((key)=>'globalThis' !== key);
1894
- }
1895
- });
1896
- for (const nm of globalMuteableVars)Object.defineProperty(mtsGlobalThis, nm, {
1897
- get: ()=>lynxGlobalBindingValues[nm],
1898
- set: (v)=>{
1899
- lynxGlobalBindingValues[nm] = v;
1900
- for (const handler1 of varsUpdateHandlers)handler1();
1901
- }
1710
+ configurable: true,
1711
+ enumerable: true
1902
1712
  });
1903
- return mtsGlobalThis;
1713
+ return mtsRealm.globalWindow;
1904
1714
  }
1905
1715
  function createExposureService(rootDom, postExposure) {
1906
1716
  let working = true;
@@ -1960,9 +1770,128 @@ function createExposureService(rootDom, postExposure) {
1960
1770
  switchExposureService
1961
1771
  };
1962
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
+ }
1963
1893
  const initWasmPromise = initWasm();
1964
- const moduleCache = {};
1965
- 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) {
1966
1895
  const postTimingFlags = backgroundThreadRpc.createCall(postTimingFlagsEndpoint);
1967
1896
  const backgroundStart = backgroundThreadRpc.createCall(BackgroundThreadStartEndpoint);
1968
1897
  const publishEvent = backgroundThreadRpc.createCall(publishEventEndpoint);
@@ -1973,49 +1902,30 @@ function prepareMainThreadAPIs(backgroundThreadRpc, rootDom, createElement, comm
1973
1902
  async function startMainThread(config, ssrHydrateInfo) {
1974
1903
  let isFp = true;
1975
1904
  const { globalProps, template, browserConfig, nativeModulesMap, napiModulesMap, tagMap, initI18nResources } = config;
1976
- const { styleInfo, pageConfig, customSections, cardType, lepusCode, elementTemplate } = template;
1905
+ const { styleInfo, pageConfig, customSections, cardType } = template;
1977
1906
  markTimingInternal('decode_start');
1978
1907
  await initWasmPromise;
1979
- const lepusCodeEntries = await Promise.all(Object.entries(lepusCode).map(async ([name, url])=>{
1980
- const cachedModule = moduleCache[url];
1981
- if (cachedModule) return [
1982
- name,
1983
- cachedModule
1984
- ];
1985
- {
1986
- const { default: evaluateModule } = await import(url);
1987
- const module = {
1988
- exports: evaluateModule
1989
- };
1990
- moduleCache[url] = module;
1991
- return [
1992
- name,
1993
- module
1994
- ];
1995
- }
1996
- }));
1997
- const lepusCodeLoaded = Object.fromEntries(lepusCodeEntries);
1998
- const entry = lepusCodeLoaded['root'].exports;
1999
1908
  const jsContext = new LynxCrossThreadContext({
2000
1909
  rpc: backgroundThreadRpc,
2001
1910
  receiveEventEndpoint: dispatchJSContextOnMainThreadEndpoint,
2002
1911
  sendEventEndpoint: dispatchCoreContextOnBackgroundEndpoint
2003
1912
  });
2004
1913
  const i18nResources = initialI18nResources(initI18nResources);
1914
+ const { updateCssOGStyle } = appendStyleElement(styleInfo, pageConfig, rootDom, document, void 0, ssrHydrateInfo);
2005
1915
  const mtsGlobalThis = createMainThreadGlobalThis({
1916
+ lynxTemplate: template,
1917
+ mtsRealm,
2006
1918
  jsContext,
2007
1919
  tagMap,
2008
1920
  browserConfig,
2009
- customSections,
2010
- elementTemplate,
2011
1921
  globalProps,
2012
1922
  pageConfig,
2013
- styleInfo,
2014
- lepusCode: lepusCodeLoaded,
2015
1923
  rootDom,
2016
1924
  ssrHydrateInfo,
2017
1925
  ssrHooks,
1926
+ document,
2018
1927
  callbacks: {
1928
+ updateCssOGStyle,
2019
1929
  mainChunkReady: ()=>{
2020
1930
  markTimingInternal('data_processor_start');
2021
1931
  let initData = config.initData;
@@ -2035,8 +1945,7 @@ function prepareMainThreadAPIs(backgroundThreadRpc, rootDom, createElement, comm
2035
1945
  v.content
2036
1946
  ])),
2037
1947
  nativeModulesMap,
2038
- napiModulesMap,
2039
- browserConfig
1948
+ napiModulesMap
2040
1949
  });
2041
1950
  if (ssrHydrateInfo) {
2042
1951
  for (const event of ssrHydrateInfo.events){
@@ -2081,7 +1990,6 @@ function prepareMainThreadAPIs(backgroundThreadRpc, rootDom, createElement, comm
2081
1990
  markTiming: (a, b)=>markTimingInternal(b, a),
2082
1991
  publishEvent,
2083
1992
  publicComponentEvent,
2084
- createElement,
2085
1993
  _I18nResourceTranslation: (options)=>{
2086
1994
  const matchedInitI18nResources = i18nResources.data?.find((i)=>getCacheI18nResourcesKey(i.options) === getCacheI18nResourcesKey(options));
2087
1995
  dispatchI18nResource(matchedInitI18nResources?.resource);
@@ -2091,9 +1999,8 @@ function prepareMainThreadAPIs(backgroundThreadRpc, rootDom, createElement, comm
2091
1999
  }
2092
2000
  });
2093
2001
  markTimingInternal('decode_end');
2094
- entry(mtsGlobalThis);
2002
+ await mtsRealm.loadScript(template.lepusCode.root);
2095
2003
  jsContext.__start();
2096
- return mtsGlobalThis;
2097
2004
  }
2098
2005
  return {
2099
2006
  startMainThread
@@ -2129,7 +2036,7 @@ const OperationType = {
2129
2036
  RemoveChild: 9,
2130
2037
  StyleDeclarationSetProperty: 10,
2131
2038
  StyleDeclarationRemoveProperty: 11,
2132
- SetInnerHTML: 12,
2039
+ SetTextContent: 12,
2133
2040
  sheetInsertRule: 13,
2134
2041
  sheetRuleUpdateCssText: 14
2135
2042
  };
@@ -2152,12 +2059,12 @@ class OffscreenCSSStyleDeclaration {
2152
2059
  const ancestorDocument = Symbol('ancestorDocument');
2153
2060
  const _attributes = Symbol('_attributes');
2154
2061
  const _children = Symbol('_children');
2155
- const innerHTML = Symbol('innerHTML');
2062
+ const textContent = Symbol('textContent');
2156
2063
  const _cssRuleContents = Symbol('_cssRuleContents');
2157
2064
  const OffscreenElement_uniqueId = Symbol('uniqueId');
2158
2065
  const _style = Symbol('_style');
2159
2066
  class OffscreenElement extends EventTarget {
2160
- [innerHTML] = '';
2067
+ [textContent] = '';
2161
2068
  [_style];
2162
2069
  [_attributes] = new Map();
2163
2070
  _parentElement = null;
@@ -2304,10 +2211,10 @@ class OffscreenElement extends EventTarget {
2304
2211
  this[ancestorDocument][enableEvent](type, this[OffscreenElement_uniqueId]);
2305
2212
  super.addEventListener(type, callback, options);
2306
2213
  }
2307
- set innerHTML(text1) {
2308
- 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);
2309
2216
  for (const child of this.children)child.remove();
2310
- this[innerHTML] = text1;
2217
+ this[textContent] = text1;
2311
2218
  if (this[_cssRuleContents]) this[_cssRuleContents] = [];
2312
2219
  }
2313
2220
  }
@@ -2734,7 +2641,7 @@ function escapeHtml(string) {
2734
2641
  }
2735
2642
  return lastIndex !== index ? html + str.substring(lastIndex, index) : html;
2736
2643
  }
2737
- function getInnerHTMLImpl(buffer, element, shadowrootTemplates) {
2644
+ function getTextContentImpl(buffer, element, shadowrootTemplates) {
2738
2645
  const localName = element.localName;
2739
2646
  buffer.push('<');
2740
2647
  buffer.push(localName);
@@ -2756,14 +2663,14 @@ function getInnerHTMLImpl(buffer, element, shadowrootTemplates) {
2756
2663
  buffer.push('<template shadowrootmode="open">', template, '</template>');
2757
2664
  }
2758
2665
  if (element[_cssRuleContents]?.length) buffer.push(...element[_cssRuleContents]);
2759
- if (element[innerHTML]) buffer.push(element[innerHTML]);
2760
- 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);
2761
2668
  buffer.push('</');
2762
2669
  buffer.push(localName);
2763
2670
  buffer.push('>');
2764
2671
  }
2765
2672
  function dumpHTMLString(buffer, element, shadowrootTemplates) {
2766
- for (const child of element[_children])getInnerHTMLImpl(buffer, child, shadowrootTemplates);
2673
+ for (const child of element[_children])getTextContentImpl(buffer, child, shadowrootTemplates);
2767
2674
  }
2768
2675
  const builtinElementTemplates = {
2769
2676
  'scroll-view': templateScrollView,
@@ -2804,7 +2711,39 @@ async function createLynxView(config) {
2804
2711
  });
2805
2712
  const i18nResources = new I18nResources();
2806
2713
  const events = [];
2807
- 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
+ }, ()=>{
2808
2747
  firstPaintReady();
2809
2748
  }, ()=>{}, ()=>{}, ()=>{}, ()=>{}, (initI18nResources)=>{
2810
2749
  i18nResources.setData(initI18nResources);
@@ -2819,7 +2758,7 @@ async function createLynxView(config) {
2819
2758
  ]);
2820
2759
  }
2821
2760
  });
2822
- const runtime = await startMainThread({
2761
+ await startMainThread({
2823
2762
  template,
2824
2763
  initData,
2825
2764
  globalProps,
@@ -2838,7 +2777,7 @@ async function createLynxView(config) {
2838
2777
  };
2839
2778
  async function renderToString() {
2840
2779
  await firstPaintReadyPromise;
2841
- const ssrEncodeData = runtime?.ssrEncode?.();
2780
+ const ssrEncodeData = mtsVMContext?.ssrEncode?.();
2842
2781
  const ssrDumpInfo = {
2843
2782
  ssrEncodeData,
2844
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.6",
3
+ "version": "0.16.0",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "keywords": [],
@@ -23,11 +23,13 @@
23
23
  "README.md"
24
24
  ],
25
25
  "devDependencies": {
26
- "@lynx-js/offscreen-document": "0.1.3",
27
- "@lynx-js/web-constants": "0.15.6",
26
+ "rsbuild-plugin-arethetypeswrong": "0.1.1",
27
+ "rsbuild-plugin-publint": "0.3.3",
28
+ "@lynx-js/offscreen-document": "0.1.4",
29
+ "@lynx-js/web-constants": "0.16.0",
28
30
  "@lynx-js/web-elements-template": "0.8.4",
29
- "@lynx-js/web-mainthread-apis": "0.15.6",
30
- "@lynx-js/web-worker-rpc": "0.15.6"
31
+ "@lynx-js/web-mainthread-apis": "0.16.0",
32
+ "@lynx-js/web-worker-rpc": "0.16.0"
31
33
  },
32
34
  "scripts": {
33
35
  "build": "rslib build",