@lynx-js/web-core-server-canary 0.15.8-canary-20250828-86da1623 → 0.16.0-canary-20250828-c1f8715a
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 +13 -1
- package/dist/index.js +123 -197
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
# @lynx-js/web-core-server
|
|
2
2
|
|
|
3
|
-
## 0.
|
|
3
|
+
## 0.16.0-canary-20250828064127-c1f8715a81b2e69ff46fc363013626db4468c209
|
|
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.
|
|
4
16
|
|
|
5
17
|
## 0.15.7
|
|
6
18
|
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
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__) {
|
|
@@ -399,12 +401,6 @@ const lynxElementTemplateMarkerAttribute = 'l-template';
|
|
|
399
401
|
const lynxPartIdAttribute = 'l-part';
|
|
400
402
|
const lynxDefaultDisplayLinearAttribute = 'lynx-default-display-linear';
|
|
401
403
|
const __lynx_timing_flag = '__lynx_timing_flag';
|
|
402
|
-
const globalMuteableVars = [
|
|
403
|
-
'registerDataProcessor',
|
|
404
|
-
'registerWorkletInternal',
|
|
405
|
-
'lynxWorkletImpl',
|
|
406
|
-
'runWorklet'
|
|
407
|
-
];
|
|
408
404
|
const systemInfo = {
|
|
409
405
|
platform: 'web',
|
|
410
406
|
lynxSdkVersion: '3.0'
|
|
@@ -418,10 +414,6 @@ const inShadowRootStyles = [
|
|
|
418
414
|
overflow: visible;
|
|
419
415
|
}`
|
|
420
416
|
];
|
|
421
|
-
const constants_globalDisallowedVars = [
|
|
422
|
-
'navigator',
|
|
423
|
-
'postMessage'
|
|
424
|
-
];
|
|
425
417
|
const W3cEventNameToLynx = {
|
|
426
418
|
click: 'tap',
|
|
427
419
|
lynxscroll: 'scroll',
|
|
@@ -473,12 +465,12 @@ class Rpc {
|
|
|
473
465
|
};
|
|
474
466
|
}
|
|
475
467
|
#onMessage = async (message)=>{
|
|
476
|
-
const
|
|
477
|
-
if (
|
|
468
|
+
const handler = this.#handlerMap.get(message.name);
|
|
469
|
+
if (handler) {
|
|
478
470
|
const lockViewer = message.sync ? new Int32Array(message.lock) : void 0;
|
|
479
471
|
const replyTempEndpoint = !message.sync && message.retId ? Rpc.createRetEndpoint(message.retId) : void 0;
|
|
480
472
|
try {
|
|
481
|
-
const result = await
|
|
473
|
+
const result = await handler(...message.data);
|
|
482
474
|
let retData, transfer = [];
|
|
483
475
|
if (message.sync) retData = result;
|
|
484
476
|
else if (message.hasTransfer) ({ data: retData, transfer } = result || {});
|
|
@@ -521,8 +513,8 @@ class Rpc {
|
|
|
521
513
|
createCall(endpoint) {
|
|
522
514
|
return (...args)=>this.invoke(endpoint, args);
|
|
523
515
|
}
|
|
524
|
-
registerHandler(endpoint,
|
|
525
|
-
this.#handlerMap.set(endpoint.name,
|
|
516
|
+
registerHandler(endpoint, handler) {
|
|
517
|
+
this.#handlerMap.set(endpoint.name, handler);
|
|
526
518
|
const currentCache = this.#messageCache[endpoint.name];
|
|
527
519
|
if (currentCache?.length) {
|
|
528
520
|
this.#messageCache[endpoint.name] = void 0;
|
|
@@ -741,114 +733,49 @@ class LynxCrossThreadContext extends EventTarget {
|
|
|
741
733
|
});
|
|
742
734
|
}
|
|
743
735
|
}
|
|
744
|
-
const
|
|
745
|
-
|
|
746
|
-
'
|
|
747
|
-
'
|
|
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'
|
|
736
|
+
const currentSupportedTemplateVersion = 2;
|
|
737
|
+
const globalDisallowedVars = [
|
|
738
|
+
'navigator',
|
|
739
|
+
'postMessage'
|
|
817
740
|
];
|
|
818
|
-
const
|
|
819
|
-
|
|
820
|
-
|
|
741
|
+
const templateUpgraders = [
|
|
742
|
+
(template)=>{
|
|
743
|
+
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";
|
|
744
|
+
template.manifest = Object.fromEntries(Object.entries(template.manifest).map(([key, value])=>[
|
|
745
|
+
key,
|
|
746
|
+
`{init: (lynxCoreInject) => { var {${defaultInjectStr}} = lynxCoreInject.tt; var module = {exports:null}; ${value}\n return module.exports; } }`
|
|
747
|
+
]));
|
|
748
|
+
template.lepusCode = Object.fromEntries(Object.entries(template.lepusCode).map(([key, value])=>[
|
|
749
|
+
key,
|
|
750
|
+
`(()=>{${value}\n})();`
|
|
751
|
+
]));
|
|
752
|
+
template.version = 2;
|
|
753
|
+
return template;
|
|
754
|
+
}
|
|
821
755
|
];
|
|
822
|
-
const generateModuleContent = (content
|
|
756
|
+
const generateModuleContent = (content)=>[
|
|
823
757
|
'//# allFunctionsCalledOnLoad\n',
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
'const module= {exports:{}};let exports = module.exports;',
|
|
827
|
-
'var {',
|
|
828
|
-
injectVars.join(','),
|
|
829
|
-
'} = lynx_runtime;',
|
|
830
|
-
...injectWithBind.map((nm)=>`const ${nm} = lynx_runtime.${nm}?.bind(lynx_runtime);`),
|
|
831
|
-
';var globDynamicComponentEntry = \'__Card__\';',
|
|
832
|
-
0 !== globalDisallowedVars.length ? `var ${globalDisallowedVars.join('=')}=undefined;` : '',
|
|
833
|
-
'var {__globalProps} = lynx;',
|
|
834
|
-
'lynx_runtime._updateVars=()=>{',
|
|
835
|
-
...muteableVars.map((nm)=>`${nm} = lynx_runtime.__lynxGlobalBindingValues.${nm};`),
|
|
836
|
-
'};\n',
|
|
758
|
+
'"use strict";\n',
|
|
759
|
+
`(() => {const ${globalDisallowedVars.join('=void 0,')}=void 0;module.exports = `,
|
|
837
760
|
content,
|
|
838
|
-
'\n
|
|
761
|
+
'\n})()'
|
|
839
762
|
].join('');
|
|
840
|
-
async function generateJavascriptUrl(obj,
|
|
763
|
+
async function generateJavascriptUrl(obj, createJsModuleUrl, templateName) {
|
|
841
764
|
const processEntry = async ([name, content])=>[
|
|
842
765
|
name,
|
|
843
|
-
await createJsModuleUrl(generateModuleContent(content
|
|
766
|
+
await createJsModuleUrl(generateModuleContent(content), `${templateName}-${name.replaceAll('/', '')}.js`)
|
|
844
767
|
];
|
|
845
768
|
return Promise.all(Object.entries(obj).filter(([_, content])=>'string' == typeof content).map(processEntry)).then(Object.fromEntries);
|
|
846
769
|
}
|
|
847
770
|
async function generateTemplate(template, createJsModuleUrl, templateName) {
|
|
771
|
+
template.version = template.version ?? 1;
|
|
772
|
+
if (template.version > currentSupportedTemplateVersion) throw new Error("Unsupported template, please upgrade your web-platform dependencies");
|
|
773
|
+
let upgrader;
|
|
774
|
+
while(template.version < currentSupportedTemplateVersion && (upgrader = templateUpgraders[template.version - 1]))template = upgrader(template);
|
|
848
775
|
return {
|
|
849
776
|
...template,
|
|
850
|
-
lepusCode: await generateJavascriptUrl(template.lepusCode,
|
|
851
|
-
manifest: await generateJavascriptUrl(template.manifest,
|
|
777
|
+
lepusCode: await generateJavascriptUrl(template.lepusCode, createJsModuleUrl, templateName),
|
|
778
|
+
manifest: await generateJavascriptUrl(template.manifest, createJsModuleUrl, templateName)
|
|
852
779
|
};
|
|
853
780
|
}
|
|
854
781
|
function registerCallLepusMethodHandler(rpc, runtime) {
|
|
@@ -860,22 +787,32 @@ function registerGetCustomSectionHandler(rpc, customSections) {
|
|
|
860
787
|
rpc.registerHandler(getCustomSectionsEndpoint, (key)=>customSections[key]?.content);
|
|
861
788
|
}
|
|
862
789
|
function createMainThreadLynx(config, SystemInfo) {
|
|
790
|
+
const requestAnimationFrameBrowserImpl = requestAnimationFrame;
|
|
791
|
+
const cancelAnimationFrameBrowserImpl = cancelAnimationFrame;
|
|
792
|
+
const setTimeoutBrowserImpl = setTimeout;
|
|
793
|
+
const clearTimeoutBrowserImpl = clearTimeout;
|
|
794
|
+
const setIntervalBrowserImpl = setInterval;
|
|
795
|
+
const clearIntervalBrowserImpl = clearInterval;
|
|
863
796
|
return {
|
|
864
797
|
getJSContext () {
|
|
865
798
|
return config.jsContext;
|
|
866
799
|
},
|
|
867
800
|
requestAnimationFrame (cb) {
|
|
868
|
-
return
|
|
801
|
+
return requestAnimationFrameBrowserImpl(cb);
|
|
869
802
|
},
|
|
870
|
-
cancelAnimationFrame (
|
|
871
|
-
return
|
|
803
|
+
cancelAnimationFrame (handler) {
|
|
804
|
+
return cancelAnimationFrameBrowserImpl(handler);
|
|
872
805
|
},
|
|
873
806
|
__globalProps: config.globalProps,
|
|
874
807
|
getCustomSectionSync (key) {
|
|
875
|
-
return config.customSections[key]?.content;
|
|
808
|
+
return config.lynxTemplate.customSections[key]?.content;
|
|
876
809
|
},
|
|
877
810
|
markPipelineTiming: config.callbacks.markTiming,
|
|
878
|
-
SystemInfo
|
|
811
|
+
SystemInfo,
|
|
812
|
+
setTimeout: setTimeoutBrowserImpl,
|
|
813
|
+
clearTimeout: clearTimeoutBrowserImpl,
|
|
814
|
+
setInterval: setIntervalBrowserImpl,
|
|
815
|
+
clearInterval: clearIntervalBrowserImpl
|
|
879
816
|
};
|
|
880
817
|
}
|
|
881
818
|
const referenceTypes = async ()=>WebAssembly.validate(new Uint8Array([
|
|
@@ -1491,15 +1428,13 @@ const exposureRelatedAttributes = new Set([
|
|
|
1491
1428
|
]);
|
|
1492
1429
|
function createMainThreadGlobalThis(config) {
|
|
1493
1430
|
let timingFlags = [];
|
|
1494
|
-
|
|
1495
|
-
const {
|
|
1431
|
+
const { callbacks, tagMap, pageConfig, lynxTemplate, rootDom, globalProps, styleInfo, ssrHydrateInfo, ssrHooks, mtsRealm, document } = config;
|
|
1432
|
+
const { elementTemplate, lepusCode } = lynxTemplate;
|
|
1496
1433
|
const lynxUniqueIdToElement = ssrHydrateInfo?.lynxUniqueIdToElement ?? [];
|
|
1497
1434
|
const lynxUniqueIdToStyleRulesIndex = ssrHydrateInfo?.lynxUniqueIdToStyleRulesIndex ?? [];
|
|
1498
1435
|
const elementToRuntimeInfoMap = new WeakMap();
|
|
1499
1436
|
let pageElement = lynxUniqueIdToElement[1]?.deref();
|
|
1500
1437
|
let uniqueIdInc = lynxUniqueIdToElement.length || 1;
|
|
1501
|
-
const varsUpdateHandlers = [];
|
|
1502
|
-
const lynxGlobalBindingValues = {};
|
|
1503
1438
|
const exposureChangedElements = new Set();
|
|
1504
1439
|
flattenStyleInfo(styleInfo, pageConfig.enableCSSSelector);
|
|
1505
1440
|
transformToWebCss(styleInfo);
|
|
@@ -1507,7 +1442,7 @@ function createMainThreadGlobalThis(config) {
|
|
|
1507
1442
|
let cardStyleElement;
|
|
1508
1443
|
if (ssrHydrateInfo?.cardStyleElement) cardStyleElement = ssrHydrateInfo.cardStyleElement;
|
|
1509
1444
|
else {
|
|
1510
|
-
cardStyleElement =
|
|
1445
|
+
cardStyleElement = document.createElement('style');
|
|
1511
1446
|
cardStyleElement.innerHTML = genCssContent(styleInfo, pageConfig);
|
|
1512
1447
|
rootDom.append(cardStyleElement);
|
|
1513
1448
|
}
|
|
@@ -1541,7 +1476,7 @@ function createMainThreadGlobalThis(config) {
|
|
|
1541
1476
|
if (hname) {
|
|
1542
1477
|
crossThreadEvent.target.elementRefptr = event.target;
|
|
1543
1478
|
if (crossThreadEvent.currentTarget) crossThreadEvent.currentTarget.elementRefptr = event.currentTarget;
|
|
1544
|
-
|
|
1479
|
+
mtsRealm.globalWindow.runWorklet?.(hname.value, [
|
|
1545
1480
|
crossThreadEvent
|
|
1546
1481
|
]);
|
|
1547
1482
|
}
|
|
@@ -1599,8 +1534,8 @@ function createMainThreadGlobalThis(config) {
|
|
|
1599
1534
|
{
|
|
1600
1535
|
eventName = eventName.toLowerCase();
|
|
1601
1536
|
const isCapture = eventType.startsWith('capture');
|
|
1602
|
-
const
|
|
1603
|
-
return
|
|
1537
|
+
const handler = isCapture ? runtimeInfo.eventHandlerMap[eventName]?.capture : runtimeInfo.eventHandlerMap[eventName]?.bind;
|
|
1538
|
+
return handler?.handler;
|
|
1604
1539
|
}
|
|
1605
1540
|
};
|
|
1606
1541
|
const __GetEvents = (element)=>{
|
|
@@ -1610,11 +1545,11 @@ function createMainThreadGlobalThis(config) {
|
|
|
1610
1545
|
info.bind,
|
|
1611
1546
|
info.capture
|
|
1612
1547
|
])if (atomInfo) {
|
|
1613
|
-
const { type, handler
|
|
1614
|
-
if (
|
|
1548
|
+
const { type, handler } = atomInfo;
|
|
1549
|
+
if (handler) eventInfos.push({
|
|
1615
1550
|
type: type,
|
|
1616
1551
|
name: lynxEventName,
|
|
1617
|
-
function:
|
|
1552
|
+
function: handler
|
|
1618
1553
|
});
|
|
1619
1554
|
}
|
|
1620
1555
|
return eventInfos;
|
|
@@ -1625,7 +1560,7 @@ function createMainThreadGlobalThis(config) {
|
|
|
1625
1560
|
const __CreateElement = (tag, parentComponentUniqueId)=>{
|
|
1626
1561
|
const uniqueId = uniqueIdInc++;
|
|
1627
1562
|
const htmlTag = tagMap[tag] ?? tag;
|
|
1628
|
-
const element =
|
|
1563
|
+
const element = document.createElement(htmlTag);
|
|
1629
1564
|
lynxUniqueIdToElement[uniqueId] = new WeakRef(element);
|
|
1630
1565
|
const parentComponentCssID = lynxUniqueIdToElement[parentComponentUniqueId]?.deref()?.getAttribute(cssIdAttribute);
|
|
1631
1566
|
parentComponentCssID && '0' !== parentComponentCssID && element.setAttribute(cssIdAttribute, parentComponentCssID);
|
|
@@ -1706,7 +1641,7 @@ function createMainThreadGlobalThis(config) {
|
|
|
1706
1641
|
elementToRuntimeInfoMap.set(element, runtimeInfo);
|
|
1707
1642
|
};
|
|
1708
1643
|
const __SwapElement = (childA, childB)=>{
|
|
1709
|
-
const temp =
|
|
1644
|
+
const temp = document.createElement('div');
|
|
1710
1645
|
childA.replaceWith(temp);
|
|
1711
1646
|
childB.replaceWith(childA);
|
|
1712
1647
|
temp.replaceWith(childB);
|
|
@@ -1730,12 +1665,13 @@ function createMainThreadGlobalThis(config) {
|
|
|
1730
1665
|
updateCssOGStyle(Number(element.getAttribute(lynxUniqueIdAttribute)), newStyleStr ?? '');
|
|
1731
1666
|
};
|
|
1732
1667
|
const __LoadLepusChunk = (path)=>{
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
const entry = lepusModule.exports;
|
|
1737
|
-
entry?.(mtsGlobalThis);
|
|
1668
|
+
try {
|
|
1669
|
+
path = lepusCode?.[path] ?? path;
|
|
1670
|
+
mtsRealm.loadScriptSync(path);
|
|
1738
1671
|
return true;
|
|
1672
|
+
} catch (e) {
|
|
1673
|
+
console.error(`failed to load lepus chunk ${path}`, e);
|
|
1674
|
+
return false;
|
|
1739
1675
|
}
|
|
1740
1676
|
};
|
|
1741
1677
|
const __FlushElementTree = (_subTree, options)=>{
|
|
@@ -1775,14 +1711,14 @@ function createMainThreadGlobalThis(config) {
|
|
|
1775
1711
|
}
|
|
1776
1712
|
};
|
|
1777
1713
|
const __ElementFromBinary = (templateId, parentComponentUniId)=>{
|
|
1778
|
-
const elementTemplateData =
|
|
1714
|
+
const elementTemplateData = elementTemplate[templateId];
|
|
1779
1715
|
if (elementTemplateData) {
|
|
1780
1716
|
let clonedElements;
|
|
1781
1717
|
if (templateIdToTemplate[templateId]) clonedElements = Array.from(templateIdToTemplate[templateId].content.cloneNode(true).children);
|
|
1782
1718
|
else {
|
|
1783
1719
|
clonedElements = elementTemplateData.map((data)=>createElementForElementTemplateData(data, parentComponentUniId));
|
|
1784
1720
|
if (rootDom.cloneNode) {
|
|
1785
|
-
const template =
|
|
1721
|
+
const template = document.createElement('template');
|
|
1786
1722
|
template.content.append(...clonedElements);
|
|
1787
1723
|
templateIdToTemplate[templateId] = template;
|
|
1788
1724
|
rootDom.append(template);
|
|
@@ -1870,42 +1806,23 @@ function createMainThreadGlobalThis(config) {
|
|
|
1870
1806
|
_SetSourceMapRelease: (errInfo)=>release = errInfo?.release,
|
|
1871
1807
|
__OnLifecycleEvent: callbacks.__OnLifecycleEvent,
|
|
1872
1808
|
__FlushElementTree,
|
|
1873
|
-
__lynxGlobalBindingValues: lynxGlobalBindingValues,
|
|
1874
1809
|
_I18nResourceTranslation: callbacks._I18nResourceTranslation,
|
|
1875
1810
|
_AddEventListener: ()=>{},
|
|
1876
|
-
|
|
1877
|
-
varsUpdateHandlers.push(handler);
|
|
1878
|
-
},
|
|
1879
|
-
set renderPage (foo){
|
|
1880
|
-
renderPage = foo;
|
|
1881
|
-
queueMicrotask(callbacks.mainChunkReady);
|
|
1882
|
-
},
|
|
1883
|
-
get renderPage () {
|
|
1884
|
-
return renderPage;
|
|
1885
|
-
}
|
|
1811
|
+
renderPage: void 0
|
|
1886
1812
|
};
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
return target[prop] ?? globalThis[prop];
|
|
1813
|
+
Object.assign(mtsRealm.globalWindow, mtsGlobalThis);
|
|
1814
|
+
Object.defineProperty(mtsRealm.globalWindow, 'renderPage', {
|
|
1815
|
+
get () {
|
|
1816
|
+
return mtsGlobalThis.renderPage;
|
|
1892
1817
|
},
|
|
1893
|
-
set
|
|
1894
|
-
|
|
1895
|
-
|
|
1818
|
+
set (v) {
|
|
1819
|
+
mtsGlobalThis.renderPage = v;
|
|
1820
|
+
queueMicrotask(callbacks.mainChunkReady);
|
|
1896
1821
|
},
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
}
|
|
1822
|
+
configurable: true,
|
|
1823
|
+
enumerable: true
|
|
1900
1824
|
});
|
|
1901
|
-
|
|
1902
|
-
get: ()=>lynxGlobalBindingValues[nm],
|
|
1903
|
-
set: (v)=>{
|
|
1904
|
-
lynxGlobalBindingValues[nm] = v;
|
|
1905
|
-
for (const handler1 of varsUpdateHandlers)handler1();
|
|
1906
|
-
}
|
|
1907
|
-
});
|
|
1908
|
-
return mtsGlobalThis;
|
|
1825
|
+
return mtsRealm.globalWindow;
|
|
1909
1826
|
}
|
|
1910
1827
|
function createExposureService(rootDom, postExposure) {
|
|
1911
1828
|
let working = true;
|
|
@@ -1966,8 +1883,7 @@ function createExposureService(rootDom, postExposure) {
|
|
|
1966
1883
|
};
|
|
1967
1884
|
}
|
|
1968
1885
|
const initWasmPromise = initWasm();
|
|
1969
|
-
|
|
1970
|
-
function prepareMainThreadAPIs(backgroundThreadRpc, rootDom, createElement, commitDocument, markTimingInternal, flushMarkTimingInternal, reportError, triggerI18nResourceFallback, initialI18nResources, ssrHooks) {
|
|
1886
|
+
function prepareMainThreadAPIs(backgroundThreadRpc, rootDom, document, mtsRealm, commitDocument, markTimingInternal, flushMarkTimingInternal, reportError, triggerI18nResourceFallback, initialI18nResources, ssrHooks) {
|
|
1971
1887
|
const postTimingFlags = backgroundThreadRpc.createCall(postTimingFlagsEndpoint);
|
|
1972
1888
|
const backgroundStart = backgroundThreadRpc.createCall(BackgroundThreadStartEndpoint);
|
|
1973
1889
|
const publishEvent = backgroundThreadRpc.createCall(publishEventEndpoint);
|
|
@@ -1978,29 +1894,9 @@ function prepareMainThreadAPIs(backgroundThreadRpc, rootDom, createElement, comm
|
|
|
1978
1894
|
async function startMainThread(config, ssrHydrateInfo) {
|
|
1979
1895
|
let isFp = true;
|
|
1980
1896
|
const { globalProps, template, browserConfig, nativeModulesMap, napiModulesMap, tagMap, initI18nResources } = config;
|
|
1981
|
-
const { styleInfo, pageConfig, customSections, cardType
|
|
1897
|
+
const { styleInfo, pageConfig, customSections, cardType } = template;
|
|
1982
1898
|
markTimingInternal('decode_start');
|
|
1983
1899
|
await initWasmPromise;
|
|
1984
|
-
const lepusCodeEntries = await Promise.all(Object.entries(lepusCode).map(async ([name, url])=>{
|
|
1985
|
-
const cachedModule = moduleCache[url];
|
|
1986
|
-
if (cachedModule) return [
|
|
1987
|
-
name,
|
|
1988
|
-
cachedModule
|
|
1989
|
-
];
|
|
1990
|
-
{
|
|
1991
|
-
const { default: evaluateModule } = await import(url);
|
|
1992
|
-
const module = {
|
|
1993
|
-
exports: evaluateModule
|
|
1994
|
-
};
|
|
1995
|
-
moduleCache[url] = module;
|
|
1996
|
-
return [
|
|
1997
|
-
name,
|
|
1998
|
-
module
|
|
1999
|
-
];
|
|
2000
|
-
}
|
|
2001
|
-
}));
|
|
2002
|
-
const lepusCodeLoaded = Object.fromEntries(lepusCodeEntries);
|
|
2003
|
-
const entry = lepusCodeLoaded['root'].exports;
|
|
2004
1900
|
const jsContext = new LynxCrossThreadContext({
|
|
2005
1901
|
rpc: backgroundThreadRpc,
|
|
2006
1902
|
receiveEventEndpoint: dispatchJSContextOnMainThreadEndpoint,
|
|
@@ -2008,18 +1904,18 @@ function prepareMainThreadAPIs(backgroundThreadRpc, rootDom, createElement, comm
|
|
|
2008
1904
|
});
|
|
2009
1905
|
const i18nResources = initialI18nResources(initI18nResources);
|
|
2010
1906
|
const mtsGlobalThis = createMainThreadGlobalThis({
|
|
1907
|
+
lynxTemplate: template,
|
|
1908
|
+
mtsRealm,
|
|
2011
1909
|
jsContext,
|
|
2012
1910
|
tagMap,
|
|
2013
1911
|
browserConfig,
|
|
2014
|
-
customSections,
|
|
2015
|
-
elementTemplate,
|
|
2016
1912
|
globalProps,
|
|
2017
1913
|
pageConfig,
|
|
2018
1914
|
styleInfo,
|
|
2019
|
-
lepusCode: lepusCodeLoaded,
|
|
2020
1915
|
rootDom,
|
|
2021
1916
|
ssrHydrateInfo,
|
|
2022
1917
|
ssrHooks,
|
|
1918
|
+
document,
|
|
2023
1919
|
callbacks: {
|
|
2024
1920
|
mainChunkReady: ()=>{
|
|
2025
1921
|
markTimingInternal('data_processor_start');
|
|
@@ -2085,7 +1981,6 @@ function prepareMainThreadAPIs(backgroundThreadRpc, rootDom, createElement, comm
|
|
|
2085
1981
|
markTiming: (a, b)=>markTimingInternal(b, a),
|
|
2086
1982
|
publishEvent,
|
|
2087
1983
|
publicComponentEvent,
|
|
2088
|
-
createElement,
|
|
2089
1984
|
_I18nResourceTranslation: (options)=>{
|
|
2090
1985
|
const matchedInitI18nResources = i18nResources.data?.find((i)=>getCacheI18nResourcesKey(i.options) === getCacheI18nResourcesKey(options));
|
|
2091
1986
|
dispatchI18nResource(matchedInitI18nResources?.resource);
|
|
@@ -2095,9 +1990,8 @@ function prepareMainThreadAPIs(backgroundThreadRpc, rootDom, createElement, comm
|
|
|
2095
1990
|
}
|
|
2096
1991
|
});
|
|
2097
1992
|
markTimingInternal('decode_end');
|
|
2098
|
-
|
|
1993
|
+
await mtsRealm.loadScript(template.lepusCode.root);
|
|
2099
1994
|
jsContext.__start();
|
|
2100
|
-
return mtsGlobalThis;
|
|
2101
1995
|
}
|
|
2102
1996
|
return {
|
|
2103
1997
|
startMainThread
|
|
@@ -2808,7 +2702,39 @@ async function createLynxView(config) {
|
|
|
2808
2702
|
});
|
|
2809
2703
|
const i18nResources = new I18nResources();
|
|
2810
2704
|
const events = [];
|
|
2811
|
-
const
|
|
2705
|
+
const mtsVMContext = node_vm.createContext(node_vm.constants.DONT_CONTEXTIFY);
|
|
2706
|
+
Object.assign(mtsVMContext, {
|
|
2707
|
+
document: offscreenDocument,
|
|
2708
|
+
module: {
|
|
2709
|
+
exports: null
|
|
2710
|
+
}
|
|
2711
|
+
});
|
|
2712
|
+
const loadScriptSync = (url)=>{
|
|
2713
|
+
const scriptContent = node_fs.readFileSync(url);
|
|
2714
|
+
const script = new node_vm.Script(scriptContent.toString(), {
|
|
2715
|
+
filename: url
|
|
2716
|
+
});
|
|
2717
|
+
return script.runInContext(mtsVMContext);
|
|
2718
|
+
};
|
|
2719
|
+
const loadScript = async (url)=>new Promise((resolve, reject)=>{
|
|
2720
|
+
node_fs.readFile(url, (err, data)=>{
|
|
2721
|
+
if (err) return void reject(err);
|
|
2722
|
+
try {
|
|
2723
|
+
const script = new node_vm.Script(data.toString(), {
|
|
2724
|
+
filename: url
|
|
2725
|
+
});
|
|
2726
|
+
const result = script.runInContext(mtsVMContext);
|
|
2727
|
+
resolve(result);
|
|
2728
|
+
} catch (e) {
|
|
2729
|
+
reject(e);
|
|
2730
|
+
}
|
|
2731
|
+
});
|
|
2732
|
+
});
|
|
2733
|
+
const { startMainThread } = prepareMainThreadAPIs(backgroundThreadRpc, offscreenDocument, offscreenDocument, {
|
|
2734
|
+
globalWindow: mtsVMContext,
|
|
2735
|
+
loadScript,
|
|
2736
|
+
loadScriptSync
|
|
2737
|
+
}, ()=>{
|
|
2812
2738
|
firstPaintReady();
|
|
2813
2739
|
}, ()=>{}, ()=>{}, ()=>{}, ()=>{}, (initI18nResources)=>{
|
|
2814
2740
|
i18nResources.setData(initI18nResources);
|
|
@@ -2823,7 +2749,7 @@ async function createLynxView(config) {
|
|
|
2823
2749
|
]);
|
|
2824
2750
|
}
|
|
2825
2751
|
});
|
|
2826
|
-
|
|
2752
|
+
await startMainThread({
|
|
2827
2753
|
template,
|
|
2828
2754
|
initData,
|
|
2829
2755
|
globalProps,
|
|
@@ -2842,7 +2768,7 @@ async function createLynxView(config) {
|
|
|
2842
2768
|
};
|
|
2843
2769
|
async function renderToString() {
|
|
2844
2770
|
await firstPaintReadyPromise;
|
|
2845
|
-
const ssrEncodeData =
|
|
2771
|
+
const ssrEncodeData = mtsVMContext?.ssrEncode?.();
|
|
2846
2772
|
const ssrDumpInfo = {
|
|
2847
2773
|
ssrEncodeData,
|
|
2848
2774
|
events
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lynx-js/web-core-server-canary",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0-canary-20250828-c1f8715a",
|
|
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/web-constants": "npm:@lynx-js/web-constants-canary@0.15.8-canary-20250828-86da1623",
|
|
29
28
|
"@lynx-js/offscreen-document": "npm:@lynx-js/offscreen-document-canary@0.1.3",
|
|
29
|
+
"@lynx-js/web-constants": "npm:@lynx-js/web-constants-canary@0.16.0-canary-20250828-c1f8715a",
|
|
30
30
|
"@lynx-js/web-elements-template": "npm:@lynx-js/web-elements-template-canary@0.8.4",
|
|
31
|
-
"@lynx-js/web-
|
|
32
|
-
"@lynx-js/web-
|
|
31
|
+
"@lynx-js/web-worker-rpc": "npm:@lynx-js/web-worker-rpc-canary@0.16.0-canary-20250828-c1f8715a",
|
|
32
|
+
"@lynx-js/web-mainthread-apis": "npm:@lynx-js/web-mainthread-apis-canary@0.16.0-canary-20250828-c1f8715a"
|
|
33
33
|
},
|
|
34
34
|
"scripts": {
|
|
35
35
|
"build": "rslib build",
|