@lynx-js/web-core-server 0.13.2 → 0.13.3

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,26 @@
1
1
  # @lynx-js/web-core-server
2
2
 
3
+ ## 0.13.3
4
+
5
+ ### Patch Changes
6
+
7
+ - refactor: code clean ([#897](https://github.com/lynx-family/lynx-stack/pull/897))
8
+
9
+ rename many internal apis to make logic be clear:
10
+
11
+ multi-thread: startMainWorker -> prepareMainThreadAPIs -> startMainThread -> createMainThreadContext(new MainThreadRuntime)
12
+ all-on-ui: prepareMainThreadAPIs -> startMainThread -> createMainThreadContext(new MainThreadRuntime)
13
+
14
+ - feat: support to dump ssrEncode string ([#876](https://github.com/lynx-family/lynx-stack/pull/876))
15
+
16
+ - perf: improve dom operation performance ([#881](https://github.com/lynx-family/lynx-stack/pull/881))
17
+
18
+ - code clean for offscreen-document, cut down inheritance levels
19
+ - add `appendChild` method for OffscreenElement, improve performance for append one node
20
+ - bypass some JS getter for dumping SSR string
21
+
22
+ - feat: dump dehydrate string with shadow root template ([#838](https://github.com/lynx-family/lynx-stack/pull/838))
23
+
3
24
  ## 0.13.2
4
25
 
5
26
  ### Patch Changes
@@ -1,6 +1,11 @@
1
- import { type MainThreadStartConfigs } from '@lynx-js/web-constants';
2
- interface LynxViewConfig extends Pick<MainThreadStartConfigs, 'browserConfig' | 'tagMap' | 'initData' | 'globalProps' | 'template'> {
1
+ import { type StartMainThreadContextConfig } from '@lynx-js/web-constants';
2
+ interface LynxViewConfig extends Pick<StartMainThreadContextConfig, 'browserConfig' | 'tagMap' | 'initData' | 'globalProps' | 'template'> {
3
3
  templateName?: string;
4
+ hydrateUrl: string;
5
+ injectStyles: string;
6
+ overrideElemenTemplates?: Record<string, ((attributes: Record<string, string>) => string) | string>;
7
+ autoSize?: boolean;
8
+ lynxViewStyle?: string;
4
9
  }
5
10
  export declare function createLynxView(config: LynxViewConfig): Promise<{
6
11
  renderToString: () => Promise<string>;
@@ -1,33 +1,78 @@
1
- import { flushElementTreeEndpoint, mainThreadStartEndpoint, } from '@lynx-js/web-constants';
1
+ import { inShadowRootStyles, } from '@lynx-js/web-constants';
2
2
  import { Rpc } from '@lynx-js/web-worker-rpc';
3
- import { startMainThread } from '@lynx-js/web-worker-runtime';
3
+ import { prepareMainThreadAPIs } from '@lynx-js/web-mainthread-apis';
4
4
  import { loadTemplate } from './utils/loadTemplate.js';
5
+ import { dumpHTMLString, OffscreenDocument, } from '@lynx-js/offscreen-document/webworker';
6
+ import { templateScrollView, templateXAudioTT, templateXImage, templateFilterImage, templateXInput, templateXList, templateXOverlayNg, templateXRefreshView, templateXSwiper, templateXText, templateInlineImage, templateXTextarea, templateXViewpageNg, } from '@lynx-js/web-elements-template';
7
+ const builtinElementTemplates = {
8
+ 'scroll-view': templateScrollView,
9
+ 'x-audio-tt': templateXAudioTT,
10
+ 'x-image': templateXImage,
11
+ 'filter-image': templateFilterImage,
12
+ 'x-input': templateXInput,
13
+ 'x-list': templateXList,
14
+ 'x-overlay-ng': templateXOverlayNg,
15
+ 'x-refresh-view': templateXRefreshView,
16
+ 'x-swiper': templateXSwiper,
17
+ 'x-text': templateXText,
18
+ 'inline-image': templateInlineImage,
19
+ 'x-textarea': templateXTextarea,
20
+ 'x-viewpage-ng': templateXViewpageNg,
21
+ };
22
+ const builtinTagTransformMap = {
23
+ 'page': 'div',
24
+ 'view': 'x-view',
25
+ 'text': 'x-text',
26
+ 'image': 'x-image',
27
+ 'list': 'x-list',
28
+ 'svg': 'x-svg',
29
+ };
5
30
  export async function createLynxView(config) {
6
- const { template: rawTemplate, browserConfig, tagMap, initData, globalProps, } = config;
7
- const mainToUIChannel = new MessageChannel();
8
- const mainWithBackgroundChannel = new MessageChannel();
9
- const mainToUIMessagePort = mainToUIChannel.port2;
10
- const uiToMainRpc = new Rpc(mainToUIChannel.port1, 'main-to-ui');
11
- const { docu: offscreenDocument } = startMainThread(mainToUIMessagePort, mainWithBackgroundChannel.port2);
31
+ const { template: rawTemplate, browserConfig, tagMap, initData, globalProps, overrideElemenTemplates = {}, hydrateUrl, autoSize, injectStyles, lynxViewStyle, } = config;
32
+ const template = await loadTemplate(rawTemplate, config.templateName);
12
33
  const { promise: firstPaintReadyPromise, resolve: firstPaintReady } = Promise
13
34
  .withResolvers();
14
- const template = await loadTemplate(rawTemplate, config.templateName);
15
- const mainThreadStart = uiToMainRpc.createCall(mainThreadStartEndpoint);
16
- mainThreadStart({
35
+ const mainWithBackgroundChannel = new MessageChannel();
36
+ const backgroundThreadRpc = new Rpc(mainWithBackgroundChannel.port1, 'background-thread');
37
+ const offscreenDocument = new OffscreenDocument({
38
+ onCommit: () => {
39
+ },
40
+ });
41
+ const { startMainThread } = prepareMainThreadAPIs(backgroundThreadRpc, offscreenDocument, offscreenDocument.createElement.bind(offscreenDocument), () => {
42
+ firstPaintReady();
43
+ }, () => {
44
+ // mark timing
45
+ }, () => {
46
+ // report error
47
+ });
48
+ const runtime = await startMainThread({
17
49
  template,
18
50
  initData,
19
51
  globalProps,
20
52
  browserConfig,
21
53
  nativeModulesMap: {}, // the bts won't start
22
54
  napiModulesMap: {}, // the bts won't start
23
- tagMap,
24
- });
25
- uiToMainRpc.registerHandler(flushElementTreeEndpoint, () => {
26
- firstPaintReady();
55
+ tagMap: {
56
+ ...builtinTagTransformMap,
57
+ ...tagMap,
58
+ },
27
59
  });
60
+ const elementTemplates = {
61
+ ...builtinElementTemplates,
62
+ ...overrideElemenTemplates,
63
+ };
28
64
  async function renderToString() {
29
65
  await firstPaintReadyPromise;
30
- return offscreenDocument.innerHTML;
66
+ const innerShadowRootHTML = dumpHTMLString(offscreenDocument, elementTemplates);
67
+ const ssrEncodeData = runtime?.ssrEncode?.();
68
+ const encodeDataEncoded = ssrEncodeData ? encodeURI(ssrEncodeData) : ''; // to avoid XSS
69
+ return `
70
+ <lynx-view url="${hydrateUrl}" ssr ${autoSize ? 'height="auto" width="auto"' : ''} ${lynxViewStyle ? `style="${lynxViewStyle}"` : ''} ${encodeDataEncoded ? `ssr-encode-data="${encodeDataEncoded}"` : ''}>
71
+ <template shadowrootmode="open">
72
+ <style>${injectStyles}\n${inShadowRootStyles.join('\n')}</style>
73
+ ${innerShadowRootHTML}
74
+ </template>
75
+ </lynx-view>`;
31
76
  }
32
77
  return {
33
78
  renderToString,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/web-core-server",
3
- "version": "0.13.2",
3
+ "version": "0.13.3",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "keywords": [],
@@ -22,8 +22,10 @@
22
22
  "README.md"
23
23
  ],
24
24
  "devDependencies": {
25
- "@lynx-js/web-constants": "0.13.2",
26
- "@lynx-js/web-worker-rpc": "0.13.2",
27
- "@lynx-js/web-worker-runtime": "0.13.2"
25
+ "@lynx-js/offscreen-document": "0.0.4",
26
+ "@lynx-js/web-constants": "0.13.3",
27
+ "@lynx-js/web-elements-template": "0.7.3",
28
+ "@lynx-js/web-mainthread-apis": "0.13.3",
29
+ "@lynx-js/web-worker-rpc": "0.13.3"
28
30
  }
29
31
  }