@lynx-js/web-core-server 0.16.1 → 0.17.1

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,9 @@
1
1
  # @lynx-js/web-core-server
2
2
 
3
+ ## 0.17.1
4
+
5
+ ## 0.17.0
6
+
3
7
  ## 0.16.1
4
8
 
5
9
  ### Patch Changes
package/dist/index.js CHANGED
@@ -387,14 +387,17 @@ __webpack_require__.m = __webpack_modules__;
387
387
  }
388
388
  };
389
389
  })();
390
+ const lynxUniqueIdAttribute = 'l-uid';
390
391
  const cssIdAttribute = 'l-css-id';
391
392
  const componentIdAttribute = 'l-comp-id';
392
393
  const parentComponentUniqueIdAttribute = 'l-p-comp-uid';
393
394
  const lynxEntryNameAttribute = 'l-e-name';
394
395
  const lynxTagAttribute = 'lynx-tag';
396
+ const lynxDatasetAttribute = 'l-dset';
395
397
  const lynxComponentConfigAttribute = 'l-comp-cfg';
396
398
  const lynxDisposedAttribute = 'l-disposed';
397
399
  const lynxElementTemplateMarkerAttribute = 'l-template';
400
+ const lynxPartIdAttribute = 'l-part';
398
401
  const lynxDefaultDisplayLinearAttribute = 'lynx-default-display-linear';
399
402
  const __lynx_timing_flag = '__lynx_timing_flag';
400
403
  const systemInfo = {
@@ -740,7 +743,7 @@ const globalDisallowedVars = [
740
743
  const templateUpgraders = [
741
744
  (template)=>{
742
745
  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";
743
- template.appType = template.lepusCode.root.startsWith('(function (globDynamicComponentEntry') ? 'lazy' : 'card';
746
+ template.appType = template.appType ?? (template.lepusCode.root.startsWith('(function (globDynamicComponentEntry') ? 'lazy' : 'card');
744
747
  template.manifest = Object.fromEntries(Object.entries(template.manifest).map(([key, value])=>[
745
748
  key,
746
749
  `module.exports={init: (lynxCoreInject) => { var {${defaultInjectStr}} = lynxCoreInject.tt; var module = {exports:{}}; var exports=module.exports; ${value}\n return module.exports; } }`
@@ -754,7 +757,7 @@ const generateModuleContent = (content, eager, appType)=>[
754
757
  '\n(function() { "use strict"; const ',
755
758
  globalDisallowedVars.join('=void 0,'),
756
759
  '=void 0;\n',
757
- 'lazy' === appType ? 'module.exports=\n' : '',
760
+ 'card' !== appType ? 'module.exports=\n' : '',
758
761
  content,
759
762
  '\n})()'
760
763
  ].join('');
@@ -1156,11 +1159,11 @@ const __AddConfig = /*#__PURE__*/ (element, type, value)=>{
1156
1159
  const __AddDataset = /*#__PURE__*/ (element, key, value)=>{
1157
1160
  const currentDataset = __GetDataset(element);
1158
1161
  currentDataset[key] = value;
1159
- element.setAttribute("l-dset", encodeURIComponent(JSON.stringify(currentDataset)));
1162
+ element.setAttribute(lynxDatasetAttribute, encodeURIComponent(JSON.stringify(currentDataset)));
1160
1163
  value ? element.setAttribute('data-' + key, value.toString()) : element.removeAttribute('data-' + key);
1161
1164
  };
1162
1165
  const __GetDataset = /*#__PURE__*/ (element)=>{
1163
- const datasetString = element.getAttribute("l-dset");
1166
+ const datasetString = element.getAttribute(lynxDatasetAttribute);
1164
1167
  const currentDataset = datasetString ? JSON.parse(decodeURIComponent(datasetString)) : {};
1165
1168
  return currentDataset;
1166
1169
  };
@@ -1178,7 +1181,7 @@ const __GetElementConfig = /*#__PURE__*/ (element)=>{
1178
1181
  return currentComponentConfigString ? JSON.parse(decodeURIComponent(currentComponentConfigString)) : {};
1179
1182
  };
1180
1183
  const __GetAttributeByName = /*#__PURE__*/ (element, name)=>element.getAttribute(name);
1181
- const __GetElementUniqueID = /*#__PURE__*/ (element)=>element && element.getAttribute ? Number(element.getAttribute("l-uid")) : -1;
1184
+ const __GetElementUniqueID = /*#__PURE__*/ (element)=>element && element.getAttribute ? Number(element.getAttribute(lynxUniqueIdAttribute)) : -1;
1182
1185
  const __GetID = /*#__PURE__*/ (element)=>element.getAttribute('id');
1183
1186
  const __SetID = /*#__PURE__*/ (element, id)=>id ? element.setAttribute('id', id) : element.removeAttribute('id');
1184
1187
  const __GetTag = /*#__PURE__*/ (element)=>element.getAttribute(lynxTagAttribute);
@@ -1186,7 +1189,7 @@ const __SetConfig = /*#__PURE__*/ (element, config)=>{
1186
1189
  element.setAttribute(lynxComponentConfigAttribute, encodeURIComponent(JSON.stringify(config)));
1187
1190
  };
1188
1191
  const __SetDataset = /*#__PURE__*/ (element, dataset)=>{
1189
- element.setAttribute("l-dset", encodeURIComponent(JSON.stringify(dataset)));
1192
+ element.setAttribute(lynxDatasetAttribute, encodeURIComponent(JSON.stringify(dataset)));
1190
1193
  for (const [key, value] of Object.entries(dataset))element.setAttribute('data-' + key, value.toString());
1191
1194
  };
1192
1195
  const __UpdateComponentID = /*#__PURE__*/ (element, componentID)=>element.setAttribute(componentIdAttribute, componentID);
@@ -1244,9 +1247,9 @@ const __GetTemplateParts = (templateElement)=>{
1244
1247
  if (!isTemplate) return {};
1245
1248
  const templateUniqueId = __GetElementUniqueID(templateElement);
1246
1249
  const parts = {};
1247
- const partElements = templateElement.querySelectorAll(`[l-uid="${templateUniqueId}"] [l-part]:not([l-uid="${templateUniqueId}"] [${lynxElementTemplateMarkerAttribute}] [l-part])`);
1250
+ const partElements = templateElement.querySelectorAll(`[${lynxUniqueIdAttribute}="${templateUniqueId}"] [${lynxPartIdAttribute}]:not([${lynxUniqueIdAttribute}="${templateUniqueId}"] [${lynxElementTemplateMarkerAttribute}] [${lynxPartIdAttribute}])`);
1248
1251
  for (const partElement of partElements){
1249
- const partId = partElement.getAttribute("l-part");
1252
+ const partId = partElement.getAttribute(lynxPartIdAttribute);
1250
1253
  if (partId) parts[partId] = partElement;
1251
1254
  }
1252
1255
  return parts;
@@ -1255,7 +1258,7 @@ const __MarkTemplateElement = (element)=>{
1255
1258
  element.setAttribute(lynxElementTemplateMarkerAttribute, '');
1256
1259
  };
1257
1260
  const __MarkPartElement = (element, partId)=>{
1258
- element.setAttribute("l-part", partId);
1261
+ element.setAttribute(lynxPartIdAttribute, partId);
1259
1262
  };
1260
1263
  function toCloneableObject(obj) {
1261
1264
  const cloneableObj = {};
@@ -1299,9 +1302,9 @@ function createCrossThreadEvent(domEvent, eventName) {
1299
1302
  changedTouches: isTrusted ? changedTouches.map(toCloneableObject) : changedTouches
1300
1303
  });
1301
1304
  }
1302
- const currentTargetDatasetString = currentTargetElement?.getAttribute("l-dset");
1305
+ const currentTargetDatasetString = currentTargetElement?.getAttribute(lynxDatasetAttribute);
1303
1306
  const currentTargetDataset = currentTargetDatasetString ? JSON.parse(decodeURIComponent(currentTargetDatasetString)) : {};
1304
- const targetDatasetString = targetElement.getAttribute("l-dset");
1307
+ const targetDatasetString = targetElement.getAttribute(lynxDatasetAttribute);
1305
1308
  const targetDataset = targetDatasetString ? JSON.parse(decodeURIComponent(targetDatasetString)) : {};
1306
1309
  return {
1307
1310
  type: eventName,
@@ -1309,12 +1312,12 @@ function createCrossThreadEvent(domEvent, eventName) {
1309
1312
  target: {
1310
1313
  id: targetElement.getAttribute('id'),
1311
1314
  dataset: targetDataset,
1312
- uniqueId: Number(targetElement.getAttribute("l-uid"))
1315
+ uniqueId: Number(targetElement.getAttribute(lynxUniqueIdAttribute))
1313
1316
  },
1314
1317
  currentTarget: currentTargetElement ? {
1315
1318
  id: currentTargetElement.getAttribute('id'),
1316
1319
  dataset: currentTargetDataset,
1317
- uniqueId: Number(currentTargetElement.getAttribute("l-uid"))
1320
+ uniqueId: Number(currentTargetElement.getAttribute(lynxUniqueIdAttribute))
1318
1321
  } : null,
1319
1322
  detail: domEvent.detail ?? {},
1320
1323
  params,
@@ -1451,7 +1454,7 @@ function createMainThreadGlobalThis(config) {
1451
1454
  const parentComponentCssID = lynxUniqueIdToElement[parentComponentUniqueId]?.deref()?.getAttribute(cssIdAttribute);
1452
1455
  parentComponentCssID && '0' !== parentComponentCssID && element.setAttribute(cssIdAttribute, parentComponentCssID);
1453
1456
  element.setAttribute(lynxTagAttribute, tag);
1454
- element.setAttribute("l-uid", uniqueId + '');
1457
+ element.setAttribute(lynxUniqueIdAttribute, uniqueId + '');
1455
1458
  element.setAttribute(parentComponentUniqueIdAttribute, parentComponentUniqueId + '');
1456
1459
  return element;
1457
1460
  };
@@ -1532,9 +1535,10 @@ function createMainThreadGlobalThis(config) {
1532
1535
  childB.replaceWith(childA);
1533
1536
  temp.replaceWith(childB);
1534
1537
  };
1535
- const __SetCSSIdForCSSOG = (elements, cssId)=>{
1538
+ const __SetCSSIdForCSSOG = (elements, cssId, entryName)=>{
1536
1539
  for (const element of elements){
1537
1540
  element.setAttribute(cssIdAttribute, cssId + '');
1541
+ entryName && element.setAttribute(lynxEntryNameAttribute, entryName);
1538
1542
  const cls = element.getAttribute('class');
1539
1543
  cls && __SetClassesForCSSOG(element, cls);
1540
1544
  }
@@ -1543,14 +1547,16 @@ function createMainThreadGlobalThis(config) {
1543
1547
  const newClassName = ((element.getAttribute('class') ?? '') + ' ' + className).trim();
1544
1548
  element.setAttribute('class', newClassName);
1545
1549
  const cssId = element.getAttribute(cssIdAttribute);
1546
- const uniqueId = Number(element.getAttribute("l-uid"));
1547
- callbacks.updateCssOGStyle(uniqueId, newClassName, cssId);
1550
+ const uniqueId = Number(element.getAttribute(lynxUniqueIdAttribute));
1551
+ const entryName = element.getAttribute(lynxEntryNameAttribute);
1552
+ callbacks.updateCssOGStyle(uniqueId, newClassName, cssId, entryName);
1548
1553
  };
1549
1554
  const __SetClassesForCSSOG = (element, classNames)=>{
1550
1555
  __SetClasses(element, classNames);
1551
1556
  const cssId = element.getAttribute(cssIdAttribute);
1552
- const uniqueId = Number(element.getAttribute("l-uid"));
1553
- callbacks.updateCssOGStyle(uniqueId, classNames ?? '', cssId);
1557
+ const uniqueId = Number(element.getAttribute(lynxUniqueIdAttribute));
1558
+ const entryName = element.getAttribute(lynxEntryNameAttribute);
1559
+ callbacks.updateCssOGStyle(uniqueId, classNames ?? '', cssId, entryName);
1554
1560
  };
1555
1561
  const __LoadLepusChunk = (path)=>{
1556
1562
  try {
@@ -1587,7 +1593,7 @@ function createMainThreadGlobalThis(config) {
1587
1593
  };
1588
1594
  const applyEventsForElementTemplate = (data, element)=>{
1589
1595
  const uniqueId = uniqueIdInc++;
1590
- element.setAttribute("l-uid", uniqueId + '');
1596
+ element.setAttribute(lynxUniqueIdAttribute, uniqueId + '');
1591
1597
  for (const event of data.events || []){
1592
1598
  const { type, name, value } = event;
1593
1599
  __AddEvent(element, type, name, value);
@@ -1721,7 +1727,7 @@ function createExposureService(rootDom, postExposure) {
1721
1727
  const onScreen = new Map();
1722
1728
  function exposureEventHandler(ev) {
1723
1729
  const exposureEvent = createCrossThreadEvent(ev, ev.type);
1724
- exposureEvent.detail['unique-id'] = parseFloat(ev.target.getAttribute("l-uid"));
1730
+ exposureEvent.detail['unique-id'] = parseFloat(ev.target.getAttribute(lynxUniqueIdAttribute));
1725
1731
  const exposureID = exposureEvent.detail.exposureID;
1726
1732
  if ('exposure' === ev.type) {
1727
1733
  exposureCache.push(exposureEvent);
@@ -1782,30 +1788,74 @@ function decodeCssOG(classes, styleInfo, cssId) {
1782
1788
  else console.warn(`[lynx-web] cannot find styleinfo for cssid ${cssId}`);
1783
1789
  return declarations.map(([property, value])=>`${property}:${value};`).join('');
1784
1790
  }
1785
- function flattenStyleInfo(styleInfo, enableCSSSelector) {
1786
- function flattenOneStyleInfo(cssId) {
1787
- const oneInfo = styleInfo[cssId];
1788
- const imports = oneInfo?.imports;
1789
- if (oneInfo && imports?.length) {
1790
- for (const im of imports){
1791
- const flatInfo = flattenOneStyleInfo(im);
1792
- if (flatInfo) {
1793
- oneInfo.content.push(...flatInfo.content);
1794
- oneInfo.rules.push(...enableCSSSelector ? flatInfo.rules : flatInfo.rules.map((i)=>({
1795
- ...i
1796
- })));
1797
- }
1791
+ function topologicalSort(styleInfo) {
1792
+ const queue = [];
1793
+ const inDegreeMap = new Map();
1794
+ for (const [cssId, oneStyleInfo] of Object.entries(styleInfo)){
1795
+ inDegreeMap.has(cssId) || inDegreeMap.set(cssId, 0);
1796
+ for (const importCssId of oneStyleInfo.imports ?? []){
1797
+ const currentInDegree = inDegreeMap.get(importCssId) ?? 0;
1798
+ inDegreeMap.set(importCssId, currentInDegree + 1);
1799
+ }
1800
+ }
1801
+ for (const [cssId, inDegree] of inDegreeMap.entries())if (0 === inDegree) queue.push(cssId);
1802
+ const sortedCssIds = [];
1803
+ while(queue.length > 0){
1804
+ const currentCssId = queue.shift();
1805
+ sortedCssIds.push(currentCssId);
1806
+ const currentAdjunction = styleInfo[currentCssId]?.imports;
1807
+ if (currentAdjunction) for (const importCssId of currentAdjunction){
1808
+ const importInDegree = inDegreeMap.get(importCssId) - 1;
1809
+ inDegreeMap.set(importCssId, importInDegree);
1810
+ if (0 === importInDegree) queue.push(importCssId);
1811
+ }
1812
+ }
1813
+ return sortedCssIds;
1814
+ }
1815
+ function generateImportByMap(styleInfo, sortedCssIds) {
1816
+ const cssIdToImportBy = new Map();
1817
+ for (const cssId of sortedCssIds){
1818
+ const currentAdjunction = styleInfo[cssId]?.imports;
1819
+ if (currentAdjunction) {
1820
+ const currentImportBy = cssIdToImportBy.get(cssId) ?? new Set([
1821
+ cssId
1822
+ ]);
1823
+ for (const importCssId of currentAdjunction){
1824
+ const importDeps = cssIdToImportBy.get(importCssId) ?? new Set([
1825
+ importCssId
1826
+ ]);
1827
+ importDeps.add(cssId);
1828
+ cssIdToImportBy.set(importCssId, currentImportBy.union(importDeps));
1798
1829
  }
1799
- oneInfo.imports = void 0;
1830
+ cssIdToImportBy.set(cssId, currentImportBy);
1800
1831
  }
1801
- return oneInfo;
1802
1832
  }
1803
- Object.keys(styleInfo).map((cssId)=>{
1804
- flattenOneStyleInfo(cssId);
1833
+ return cssIdToImportBy;
1834
+ }
1835
+ function flattenStyleInfo(styleInfo) {
1836
+ const sortedCssIds = topologicalSort(styleInfo);
1837
+ const cssIdToImportBy = generateImportByMap(styleInfo, sortedCssIds);
1838
+ sortedCssIds.reverse();
1839
+ return sortedCssIds.map((cssId)=>{
1840
+ const oneInfo = styleInfo[cssId];
1841
+ const flattenedInfo = oneInfo ? {
1842
+ content: oneInfo.content,
1843
+ rules: oneInfo.rules,
1844
+ importBy: Array.from(cssIdToImportBy.get(cssId) ?? [
1845
+ cssId
1846
+ ])
1847
+ } : {
1848
+ content: [],
1849
+ rules: [],
1850
+ importBy: [
1851
+ cssId
1852
+ ]
1853
+ };
1854
+ return flattenedInfo;
1805
1855
  });
1806
1856
  }
1807
1857
  function transformToWebCss(styleInfo) {
1808
- for (const cssInfos of Object.values(styleInfo))for (const rule of cssInfos.rules){
1858
+ for (const cssInfos of styleInfo)for (const rule of cssInfos.rules){
1809
1859
  const { sel: selectors, decl: declarations } = rule;
1810
1860
  const { transformedStyle, childStyle } = transformParsedStyles(declarations);
1811
1861
  rule.decl = transformedStyle;
@@ -1822,18 +1872,20 @@ function transformToWebCss(styleInfo) {
1822
1872
  function genCssContent(styleInfo, pageConfig, entryName) {
1823
1873
  function getExtraSelectors(cssId) {
1824
1874
  let suffix;
1825
- suffix = pageConfig.enableRemoveCSSScope ? `[${lynxTagAttribute}]` : void 0 !== cssId ? `[${cssIdAttribute}="${cssId}"]` : `[${lynxTagAttribute}]`;
1875
+ suffix = pageConfig.enableRemoveCSSScope ? `[${lynxTagAttribute}]` : `[${cssIdAttribute}="${cssId}"]`;
1826
1876
  suffix = entryName ? `${suffix}[${lynxEntryNameAttribute}=${JSON.stringify(entryName)}]` : `${suffix}:not([${lynxEntryNameAttribute}])`;
1827
1877
  return suffix;
1828
1878
  }
1829
1879
  const finalCssContent = [];
1830
- for (const [cssId, cssInfos] of Object.entries(styleInfo)){
1831
- const suffix = getExtraSelectors(cssId);
1880
+ for (const cssInfos of styleInfo){
1832
1881
  const declarationContent = cssInfos.rules.map((rule)=>{
1833
1882
  const { sel: selectorList, decl: declarations } = rule;
1834
- const selectorString = selectorList.map((selectors)=>selectors.toSpliced(-4, 0, [
1835
- suffix
1836
- ]).flat().join('')).join(',');
1883
+ const selectorString = cssInfos.importBy.map((cssId)=>{
1884
+ const suffix = getExtraSelectors(cssId);
1885
+ return selectorList.map((selectors)=>selectors.toSpliced(-4, 0, [
1886
+ suffix
1887
+ ]).flat().join('')).join(',');
1888
+ }).join(',');
1837
1889
  const declarationString = declarations.map(([k, v])=>`${k}:${v};`).join('');
1838
1890
  return `${selectorString}{${declarationString}}`;
1839
1891
  }).join('');
@@ -1842,55 +1894,56 @@ function genCssContent(styleInfo, pageConfig, entryName) {
1842
1894
  return finalCssContent.join('\n');
1843
1895
  }
1844
1896
  function genCssOGInfo(styleInfo) {
1845
- return Object.fromEntries(Object.entries(styleInfo).map(([cssId, cssInfos])=>{
1846
- const oneCssOGInfo = {};
1847
- cssInfos.rules = cssInfos.rules.filter((oneCssInfo)=>{
1848
- oneCssInfo.sel = oneCssInfo.sel.filter((selectorList)=>{
1849
- const [classSelectors, pseudoClassSelectors, pseudoElementSelectors, combinator] = selectorList;
1850
- if (1 === classSelectors.length && '.' === classSelectors[0][0] && 0 === pseudoClassSelectors.length && 0 === pseudoElementSelectors.length && 0 === combinator.length) {
1851
- const selectorName = classSelectors[0].substring(1);
1852
- const currentDeclarations = oneCssOGInfo[selectorName];
1853
- if (currentDeclarations) currentDeclarations.push(...oneCssInfo.decl);
1854
- else oneCssOGInfo[selectorName] = oneCssInfo.decl;
1855
- return false;
1897
+ const cssOGInfo = {};
1898
+ for (const oneInfo of styleInfo)oneInfo.rules = oneInfo.rules.filter((oneRule)=>{
1899
+ oneRule.sel = oneRule.sel.filter((selectorList)=>{
1900
+ const [classSelectors, pseudoClassSelectors, pseudoElementSelectors, combinator] = selectorList;
1901
+ if (1 === classSelectors.length && '.' === classSelectors[0][0] && 0 === pseudoClassSelectors.length && 0 === pseudoElementSelectors.length && 0 === combinator.length) {
1902
+ const selectorName = classSelectors[0].substring(1);
1903
+ for (const cssId of oneInfo.importBy){
1904
+ if (!cssOGInfo[cssId]) cssOGInfo[cssId] = {};
1905
+ const currentDeclarations = cssOGInfo[cssId][selectorName];
1906
+ if (currentDeclarations) currentDeclarations.push(...oneRule.decl);
1907
+ else cssOGInfo[cssId][selectorName] = oneRule.decl;
1856
1908
  }
1857
- return true;
1858
- });
1859
- return oneCssInfo.sel.length > 0;
1909
+ return false;
1910
+ }
1911
+ return true;
1860
1912
  });
1861
- return [
1862
- cssId,
1863
- oneCssOGInfo
1864
- ];
1865
- }));
1913
+ return oneRule.sel.length > 0;
1914
+ });
1915
+ return cssOGInfo;
1866
1916
  }
1867
- function appendStyleElement(styleInfo, pageConfig, rootDom, document, entryName, ssrHydrateInfo) {
1917
+ function appendStyleElement(styleInfo, pageConfig, rootDom, document, ssrHydrateInfo) {
1868
1918
  const lynxUniqueIdToStyleRulesIndex = ssrHydrateInfo?.lynxUniqueIdToStyleRulesIndex ?? [];
1869
- flattenStyleInfo(styleInfo, pageConfig.enableCSSSelector);
1870
- transformToWebCss(styleInfo);
1871
- const cssOGInfo = pageConfig.enableCSSSelector ? {} : genCssOGInfo(styleInfo);
1919
+ const flattenedStyleInfo = flattenStyleInfo(styleInfo);
1920
+ transformToWebCss(flattenedStyleInfo);
1921
+ const cssOGInfo = pageConfig.enableCSSSelector ? {} : genCssOGInfo(flattenedStyleInfo);
1922
+ const lazyCSSOGInfo = {};
1872
1923
  let cardStyleElement;
1873
1924
  if (ssrHydrateInfo?.cardStyleElement) cardStyleElement = ssrHydrateInfo.cardStyleElement;
1874
1925
  else {
1875
1926
  cardStyleElement = document.createElement('style');
1876
- cardStyleElement.textContent = genCssContent(styleInfo, pageConfig, entryName);
1927
+ cardStyleElement.textContent = genCssContent(flattenedStyleInfo, pageConfig, void 0);
1877
1928
  rootDom.appendChild(cardStyleElement);
1878
1929
  }
1879
- const cardStyleElementSheet = cardStyleElement.sheet;
1880
- const updateCssOGStyle = (uniqueId, newClassName, cssID)=>{
1881
- const newStyles = decodeCssOG(newClassName, cssOGInfo, cssID);
1930
+ const updateCssOGStyle = (uniqueId, newClassName, cssID, entryName)=>{
1931
+ const cardStyleElementSheet = cardStyleElement.sheet;
1932
+ const styleMap = entryName && lazyCSSOGInfo[entryName] ? lazyCSSOGInfo[entryName] : cssOGInfo;
1933
+ const newStyles = decodeCssOG(newClassName, styleMap, cssID);
1882
1934
  if (void 0 !== lynxUniqueIdToStyleRulesIndex[uniqueId]) {
1883
1935
  const rule = cardStyleElementSheet.cssRules[lynxUniqueIdToStyleRulesIndex[uniqueId]];
1884
1936
  rule.style.cssText = newStyles;
1885
1937
  } else {
1886
- const index = cardStyleElementSheet.insertRule(`[l-uid="${uniqueId}"]{${newStyles}}`, cardStyleElementSheet.cssRules.length);
1938
+ const index = cardStyleElementSheet.insertRule(`[${lynxUniqueIdAttribute}="${uniqueId}"]{${newStyles}}`, cardStyleElementSheet.cssRules.length);
1887
1939
  lynxUniqueIdToStyleRulesIndex[uniqueId] = index;
1888
1940
  }
1889
1941
  };
1890
1942
  const updateLazyComponentStyle = (styleInfo, entryName)=>{
1891
- flattenStyleInfo(styleInfo, pageConfig.enableCSSSelector);
1892
- transformToWebCss(styleInfo);
1893
- const newStyleSheet = genCssContent(styleInfo, pageConfig, entryName);
1943
+ const flattenedStyleInfo = flattenStyleInfo(styleInfo);
1944
+ transformToWebCss(flattenedStyleInfo);
1945
+ if (!pageConfig.enableCSSSelector) lazyCSSOGInfo[entryName] = genCssOGInfo(flattenedStyleInfo);
1946
+ const newStyleSheet = genCssContent(flattenedStyleInfo, pageConfig, entryName);
1894
1947
  cardStyleElement.textContent += newStyleSheet;
1895
1948
  };
1896
1949
  return {
@@ -1900,8 +1953,10 @@ function appendStyleElement(styleInfo, pageConfig, rootDom, document, entryName,
1900
1953
  }
1901
1954
  function createQueryComponent(loadTemplate, updateLazyComponentStyle, backgroundThreadRpc, mtsGlobalThisRef, jsContext, mtsRealm) {
1902
1955
  const updateBTSTemplateCache = backgroundThreadRpc.createCall(updateBTSTemplateCacheEndpoint);
1956
+ const lazyCache = new Map();
1903
1957
  const __QueryComponentImpl = (url, callback)=>{
1904
- loadTemplate(url).then(async (template)=>{
1958
+ const cacheLazy = lazyCache.get(url);
1959
+ const loadPromise = cacheLazy ?? loadTemplate(url).then(async (template)=>{
1905
1960
  const updateBTSCachePromise = updateBTSTemplateCache(url, template);
1906
1961
  let lepusRootChunkExport = await mtsRealm.loadScript(template.lepusCode.root);
1907
1962
  if (mtsGlobalThisRef.mtsGlobalThis.processEvalResult) lepusRootChunkExport = mtsGlobalThisRef.mtsGlobalThis.processEvalResult(lepusRootChunkExport, url);
@@ -1911,6 +1966,10 @@ function createQueryComponent(loadTemplate, updateLazyComponentStyle, background
1911
1966
  type: '__OnDynamicJSSourcePrepared',
1912
1967
  data: url
1913
1968
  });
1969
+ return lepusRootChunkExport;
1970
+ });
1971
+ cacheLazy || lazyCache.set(url, loadPromise);
1972
+ loadPromise.then((lepusRootChunkExport)=>{
1914
1973
  callback?.({
1915
1974
  code: 0,
1916
1975
  data: {
@@ -1920,6 +1979,7 @@ function createQueryComponent(loadTemplate, updateLazyComponentStyle, background
1920
1979
  });
1921
1980
  }).catch((error)=>{
1922
1981
  console.error("lynx web: lazy bundle load failed:", error);
1982
+ lazyCache.delete(url);
1923
1983
  callback?.({
1924
1984
  code: -1,
1925
1985
  data: void 0
@@ -1963,7 +2023,7 @@ function prepareMainThreadAPIs(backgroundThreadRpc, rootDom, document, mtsRealm,
1963
2023
  sendEventEndpoint: dispatchCoreContextOnBackgroundEndpoint
1964
2024
  });
1965
2025
  const i18nResources = initialI18nResources(initI18nResources);
1966
- const { updateCssOGStyle, updateLazyComponentStyle } = appendStyleElement(styleInfo, pageConfig, rootDom, document, void 0, ssrHydrateInfo);
2026
+ const { updateCssOGStyle, updateLazyComponentStyle } = appendStyleElement(styleInfo, pageConfig, rootDom, document, ssrHydrateInfo);
1967
2027
  const mtsGlobalThisRef = {
1968
2028
  mtsGlobalThis: void 0
1969
2029
  };
@@ -2737,8 +2797,8 @@ function getTextContentImpl(buffer, element, shadowrootTemplates) {
2737
2797
  buffer.push('"');
2738
2798
  }
2739
2799
  }
2740
- const partId = element[_attributes].get("l-part") ?? element[_attributes].get("l-uid");
2741
- buffer.push(' ', "l-part", '="', partId, '"');
2800
+ const partId = element[_attributes].get(lynxPartIdAttribute) ?? element[_attributes].get(lynxUniqueIdAttribute);
2801
+ buffer.push(' ', lynxPartIdAttribute, '="', partId, '"');
2742
2802
  buffer.push('>');
2743
2803
  const templateImpl = shadowrootTemplates[localName];
2744
2804
  if (templateImpl) {
@@ -2780,7 +2840,7 @@ const builtinTagTransformMap = {
2780
2840
  };
2781
2841
  OffscreenElement.prototype.toJSON = function() {
2782
2842
  return {
2783
- ssrID: this[_attributes].get("l-part") ?? this[_attributes].get("l-uid")
2843
+ ssrID: this[_attributes].get(lynxPartIdAttribute) ?? this[_attributes].get(lynxUniqueIdAttribute)
2784
2844
  };
2785
2845
  };
2786
2846
  async function createLynxView(config) {
@@ -2849,7 +2909,7 @@ async function createLynxView(config) {
2849
2909
  }, ()=>{}, {
2850
2910
  __AddEvent (element, eventName, eventData, eventOptions) {
2851
2911
  events.push([
2852
- Number(element.getAttribute("l-uid")),
2912
+ Number(element.getAttribute(lynxUniqueIdAttribute)),
2853
2913
  eventName,
2854
2914
  eventData,
2855
2915
  eventOptions
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/web-core-server",
3
- "version": "0.16.1",
3
+ "version": "0.17.1",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "keywords": [],
@@ -26,10 +26,10 @@
26
26
  "rsbuild-plugin-arethetypeswrong": "0.1.1",
27
27
  "rsbuild-plugin-publint": "0.3.3",
28
28
  "@lynx-js/offscreen-document": "0.1.4",
29
- "@lynx-js/web-constants": "0.16.1",
30
- "@lynx-js/web-elements-template": "0.8.6",
31
- "@lynx-js/web-mainthread-apis": "0.16.1",
32
- "@lynx-js/web-worker-rpc": "0.16.1"
29
+ "@lynx-js/web-constants": "0.17.1",
30
+ "@lynx-js/web-elements-template": "0.8.7",
31
+ "@lynx-js/web-mainthread-apis": "0.17.1",
32
+ "@lynx-js/web-worker-rpc": "0.17.1"
33
33
  },
34
34
  "scripts": {
35
35
  "build": "rslib build",