@lynx-js/web-core-server-canary 0.16.1 → 0.17.0-canary-20250918-b17b7cb2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/CHANGELOG.md +11 -9
  2. package/dist/index.js +102 -51
  3. package/package.json +4 -4
package/CHANGELOG.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # @lynx-js/web-core-server
2
2
 
3
+ ## 0.17.0-canary-20250918080343-b17b7cb2bb92d1539e76276f136806eefa788258
4
+
3
5
  ## 0.16.1
4
6
 
5
7
  ### Patch Changes
@@ -103,25 +105,25 @@
103
105
  lynxView.initI18nResources = [
104
106
  {
105
107
  options: {
106
- locale: 'en',
107
- channel: '1',
108
- fallback_url: '',
108
+ locale: "en",
109
+ channel: "1",
110
+ fallback_url: "",
109
111
  },
110
112
  resource: {
111
- hello: 'hello',
112
- lynx: 'lynx web platform1',
113
+ hello: "hello",
114
+ lynx: "lynx web platform1",
113
115
  },
114
116
  },
115
117
  ];
116
- lynxView.addEventListener('i18nResourceMissed', (e) => {
118
+ lynxView.addEventListener("i18nResourceMissed", (e) => {
117
119
  console.log(e);
118
120
  });
119
121
 
120
122
  // mts
121
123
  _I18nResourceTranslation({
122
- locale: 'en',
123
- channel: '1',
124
- fallback_url: '',
124
+ locale: "en",
125
+ channel: "1",
126
+ fallback_url: "",
125
127
  });
126
128
  ```
127
129
 
package/dist/index.js CHANGED
@@ -1782,30 +1782,74 @@ function decodeCssOG(classes, styleInfo, cssId) {
1782
1782
  else console.warn(`[lynx-web] cannot find styleinfo for cssid ${cssId}`);
1783
1783
  return declarations.map(([property, value])=>`${property}:${value};`).join('');
1784
1784
  }
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
- }
1785
+ function topologicalSort(styleInfo) {
1786
+ const queue = [];
1787
+ const inDegreeMap = new Map();
1788
+ for (const [cssId, oneStyleInfo] of Object.entries(styleInfo)){
1789
+ inDegreeMap.has(cssId) || inDegreeMap.set(cssId, 0);
1790
+ for (const importCssId of oneStyleInfo.imports ?? []){
1791
+ const currentInDegree = inDegreeMap.get(importCssId) ?? 0;
1792
+ inDegreeMap.set(importCssId, currentInDegree + 1);
1793
+ }
1794
+ }
1795
+ for (const [cssId, inDegree] of inDegreeMap.entries())if (0 === inDegree) queue.push(cssId);
1796
+ const sortedCssIds = [];
1797
+ while(queue.length > 0){
1798
+ const currentCssId = queue.shift();
1799
+ sortedCssIds.push(currentCssId);
1800
+ const currentAdjunction = styleInfo[currentCssId]?.imports;
1801
+ if (currentAdjunction) for (const importCssId of currentAdjunction){
1802
+ const importInDegree = inDegreeMap.get(importCssId) - 1;
1803
+ inDegreeMap.set(importCssId, importInDegree);
1804
+ if (0 === importInDegree) queue.push(importCssId);
1805
+ }
1806
+ }
1807
+ return sortedCssIds;
1808
+ }
1809
+ function generateImportByMap(styleInfo, sortedCssIds) {
1810
+ const cssIdToImportBy = new Map();
1811
+ for (const cssId of sortedCssIds){
1812
+ const currentAdjunction = styleInfo[cssId]?.imports;
1813
+ if (currentAdjunction) {
1814
+ const currentImportBy = cssIdToImportBy.get(cssId) ?? new Set([
1815
+ cssId
1816
+ ]);
1817
+ for (const importCssId of currentAdjunction){
1818
+ const importDeps = cssIdToImportBy.get(importCssId) ?? new Set([
1819
+ importCssId
1820
+ ]);
1821
+ importDeps.add(cssId);
1822
+ cssIdToImportBy.set(importCssId, currentImportBy.union(importDeps));
1798
1823
  }
1799
- oneInfo.imports = void 0;
1824
+ cssIdToImportBy.set(cssId, currentImportBy);
1800
1825
  }
1801
- return oneInfo;
1802
1826
  }
1803
- Object.keys(styleInfo).map((cssId)=>{
1804
- flattenOneStyleInfo(cssId);
1827
+ return cssIdToImportBy;
1828
+ }
1829
+ function flattenStyleInfo(styleInfo) {
1830
+ const sortedCssIds = topologicalSort(styleInfo);
1831
+ const cssIdToImportBy = generateImportByMap(styleInfo, sortedCssIds);
1832
+ sortedCssIds.reverse();
1833
+ return sortedCssIds.map((cssId)=>{
1834
+ const oneInfo = styleInfo[cssId];
1835
+ const flattenedInfo = oneInfo ? {
1836
+ content: oneInfo.content,
1837
+ rules: oneInfo.rules,
1838
+ importBy: Array.from(cssIdToImportBy.get(cssId) ?? [
1839
+ cssId
1840
+ ])
1841
+ } : {
1842
+ content: [],
1843
+ rules: [],
1844
+ importBy: [
1845
+ cssId
1846
+ ]
1847
+ };
1848
+ return flattenedInfo;
1805
1849
  });
1806
1850
  }
1807
1851
  function transformToWebCss(styleInfo) {
1808
- for (const cssInfos of Object.values(styleInfo))for (const rule of cssInfos.rules){
1852
+ for (const cssInfos of styleInfo)for (const rule of cssInfos.rules){
1809
1853
  const { sel: selectors, decl: declarations } = rule;
1810
1854
  const { transformedStyle, childStyle } = transformParsedStyles(declarations);
1811
1855
  rule.decl = transformedStyle;
@@ -1822,18 +1866,20 @@ function transformToWebCss(styleInfo) {
1822
1866
  function genCssContent(styleInfo, pageConfig, entryName) {
1823
1867
  function getExtraSelectors(cssId) {
1824
1868
  let suffix;
1825
- suffix = pageConfig.enableRemoveCSSScope ? `[${lynxTagAttribute}]` : void 0 !== cssId ? `[${cssIdAttribute}="${cssId}"]` : `[${lynxTagAttribute}]`;
1869
+ suffix = pageConfig.enableRemoveCSSScope ? `[${lynxTagAttribute}]` : `[${cssIdAttribute}="${cssId}"]`;
1826
1870
  suffix = entryName ? `${suffix}[${lynxEntryNameAttribute}=${JSON.stringify(entryName)}]` : `${suffix}:not([${lynxEntryNameAttribute}])`;
1827
1871
  return suffix;
1828
1872
  }
1829
1873
  const finalCssContent = [];
1830
- for (const [cssId, cssInfos] of Object.entries(styleInfo)){
1831
- const suffix = getExtraSelectors(cssId);
1874
+ for (const cssInfos of styleInfo){
1832
1875
  const declarationContent = cssInfos.rules.map((rule)=>{
1833
1876
  const { sel: selectorList, decl: declarations } = rule;
1834
- const selectorString = selectorList.map((selectors)=>selectors.toSpliced(-4, 0, [
1835
- suffix
1836
- ]).flat().join('')).join(',');
1877
+ const selectorString = cssInfos.importBy.map((cssId)=>{
1878
+ const suffix = getExtraSelectors(cssId);
1879
+ return selectorList.map((selectors)=>selectors.toSpliced(-4, 0, [
1880
+ suffix
1881
+ ]).flat().join('')).join(',');
1882
+ }).join(',');
1837
1883
  const declarationString = declarations.map(([k, v])=>`${k}:${v};`).join('');
1838
1884
  return `${selectorString}{${declarationString}}`;
1839
1885
  }).join('');
@@ -1842,38 +1888,36 @@ function genCssContent(styleInfo, pageConfig, entryName) {
1842
1888
  return finalCssContent.join('\n');
1843
1889
  }
1844
1890
  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;
1891
+ const cssOGInfo = {};
1892
+ for (const oneInfo of styleInfo)oneInfo.rules = oneInfo.rules.filter((oneRule)=>{
1893
+ oneRule.sel = oneRule.sel.filter((selectorList)=>{
1894
+ const [classSelectors, pseudoClassSelectors, pseudoElementSelectors, combinator] = selectorList;
1895
+ if (1 === classSelectors.length && '.' === classSelectors[0][0] && 0 === pseudoClassSelectors.length && 0 === pseudoElementSelectors.length && 0 === combinator.length) {
1896
+ const selectorName = classSelectors[0].substring(1);
1897
+ for (const cssId of oneInfo.importBy){
1898
+ if (!cssOGInfo[cssId]) cssOGInfo[cssId] = {};
1899
+ const currentDeclarations = cssOGInfo[cssId][selectorName];
1900
+ if (currentDeclarations) currentDeclarations.push(...oneRule.decl);
1901
+ else cssOGInfo[cssId][selectorName] = oneRule.decl;
1856
1902
  }
1857
- return true;
1858
- });
1859
- return oneCssInfo.sel.length > 0;
1903
+ return false;
1904
+ }
1905
+ return true;
1860
1906
  });
1861
- return [
1862
- cssId,
1863
- oneCssOGInfo
1864
- ];
1865
- }));
1907
+ return oneRule.sel.length > 0;
1908
+ });
1909
+ return cssOGInfo;
1866
1910
  }
1867
1911
  function appendStyleElement(styleInfo, pageConfig, rootDom, document, entryName, ssrHydrateInfo) {
1868
1912
  const lynxUniqueIdToStyleRulesIndex = ssrHydrateInfo?.lynxUniqueIdToStyleRulesIndex ?? [];
1869
- flattenStyleInfo(styleInfo, pageConfig.enableCSSSelector);
1870
- transformToWebCss(styleInfo);
1871
- const cssOGInfo = pageConfig.enableCSSSelector ? {} : genCssOGInfo(styleInfo);
1913
+ const flattenedStyleInfo = flattenStyleInfo(styleInfo);
1914
+ transformToWebCss(flattenedStyleInfo);
1915
+ const cssOGInfo = pageConfig.enableCSSSelector ? {} : genCssOGInfo(flattenedStyleInfo);
1872
1916
  let cardStyleElement;
1873
1917
  if (ssrHydrateInfo?.cardStyleElement) cardStyleElement = ssrHydrateInfo.cardStyleElement;
1874
1918
  else {
1875
1919
  cardStyleElement = document.createElement('style');
1876
- cardStyleElement.textContent = genCssContent(styleInfo, pageConfig, entryName);
1920
+ cardStyleElement.textContent = genCssContent(flattenedStyleInfo, pageConfig, entryName);
1877
1921
  rootDom.appendChild(cardStyleElement);
1878
1922
  }
1879
1923
  const cardStyleElementSheet = cardStyleElement.sheet;
@@ -1888,9 +1932,9 @@ function appendStyleElement(styleInfo, pageConfig, rootDom, document, entryName,
1888
1932
  }
1889
1933
  };
1890
1934
  const updateLazyComponentStyle = (styleInfo, entryName)=>{
1891
- flattenStyleInfo(styleInfo, pageConfig.enableCSSSelector);
1892
- transformToWebCss(styleInfo);
1893
- const newStyleSheet = genCssContent(styleInfo, pageConfig, entryName);
1935
+ const flattenedStyleInfo = flattenStyleInfo(styleInfo);
1936
+ transformToWebCss(flattenedStyleInfo);
1937
+ const newStyleSheet = genCssContent(flattenedStyleInfo, pageConfig, entryName);
1894
1938
  cardStyleElement.textContent += newStyleSheet;
1895
1939
  };
1896
1940
  return {
@@ -1900,8 +1944,10 @@ function appendStyleElement(styleInfo, pageConfig, rootDom, document, entryName,
1900
1944
  }
1901
1945
  function createQueryComponent(loadTemplate, updateLazyComponentStyle, backgroundThreadRpc, mtsGlobalThisRef, jsContext, mtsRealm) {
1902
1946
  const updateBTSTemplateCache = backgroundThreadRpc.createCall(updateBTSTemplateCacheEndpoint);
1947
+ const lazyCache = new Map();
1903
1948
  const __QueryComponentImpl = (url, callback)=>{
1904
- loadTemplate(url).then(async (template)=>{
1949
+ const cacheLazy = lazyCache.get(url);
1950
+ const loadPromise = cacheLazy ?? loadTemplate(url).then(async (template)=>{
1905
1951
  const updateBTSCachePromise = updateBTSTemplateCache(url, template);
1906
1952
  let lepusRootChunkExport = await mtsRealm.loadScript(template.lepusCode.root);
1907
1953
  if (mtsGlobalThisRef.mtsGlobalThis.processEvalResult) lepusRootChunkExport = mtsGlobalThisRef.mtsGlobalThis.processEvalResult(lepusRootChunkExport, url);
@@ -1911,6 +1957,10 @@ function createQueryComponent(loadTemplate, updateLazyComponentStyle, background
1911
1957
  type: '__OnDynamicJSSourcePrepared',
1912
1958
  data: url
1913
1959
  });
1960
+ return lepusRootChunkExport;
1961
+ });
1962
+ cacheLazy || lazyCache.set(url, loadPromise);
1963
+ loadPromise.then((lepusRootChunkExport)=>{
1914
1964
  callback?.({
1915
1965
  code: 0,
1916
1966
  data: {
@@ -1920,6 +1970,7 @@ function createQueryComponent(loadTemplate, updateLazyComponentStyle, background
1920
1970
  });
1921
1971
  }).catch((error)=>{
1922
1972
  console.error("lynx web: lazy bundle load failed:", error);
1973
+ lazyCache.delete(url);
1923
1974
  callback?.({
1924
1975
  code: -1,
1925
1976
  data: void 0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/web-core-server-canary",
3
- "version": "0.16.1",
3
+ "version": "0.17.0-canary-20250918-b17b7cb2",
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.16.1",
28
+ "@lynx-js/web-constants": "npm:@lynx-js/web-constants-canary@0.17.0-canary-20250918-b17b7cb2",
29
29
  "@lynx-js/web-elements-template": "npm:@lynx-js/web-elements-template-canary@0.8.6",
30
- "@lynx-js/web-worker-rpc": "npm:@lynx-js/web-worker-rpc-canary@0.16.1",
30
+ "@lynx-js/web-mainthread-apis": "npm:@lynx-js/web-mainthread-apis-canary@0.17.0-canary-20250918-b17b7cb2",
31
31
  "@lynx-js/offscreen-document": "npm:@lynx-js/offscreen-document-canary@0.1.4",
32
- "@lynx-js/web-mainthread-apis": "npm:@lynx-js/web-mainthread-apis-canary@0.16.1"
32
+ "@lynx-js/web-worker-rpc": "npm:@lynx-js/web-worker-rpc-canary@0.17.0-canary-20250918-b17b7cb2"
33
33
  },
34
34
  "scripts": {
35
35
  "build": "rslib build",