@lynx-js/web-mainthread-apis 0.15.2 → 0.15.4
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,38 @@
|
|
|
1
1
|
# @lynx-js/web-mainthread-apis
|
|
2
2
|
|
|
3
|
+
## 0.15.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- feat: support `__ElementFromBinary` ([#1391](https://github.com/lynx-family/lynx-stack/pull/1391))
|
|
8
|
+
|
|
9
|
+
- fix: crash on chrome<96 ([#1361](https://github.com/lynx-family/lynx-stack/pull/1361))
|
|
10
|
+
|
|
11
|
+
https://github.com/wasm-bindgen/wasm-bindgen/issues/4211#issuecomment-2505965903
|
|
12
|
+
|
|
13
|
+
https://github.com/WebAssembly/binaryen/issues/7358
|
|
14
|
+
|
|
15
|
+
The rust toolchain enables WASM feature `reference types` by default.
|
|
16
|
+
|
|
17
|
+
However this feature is not supported by chromium lower than version 96
|
|
18
|
+
|
|
19
|
+
Therefore we found a workaround for it.
|
|
20
|
+
|
|
21
|
+
In this implementation we detect if browser supports `reference types` first.
|
|
22
|
+
|
|
23
|
+
If user's browser supported it, we load the wasm file with `reference types` on, otherwise we load the wasm file with `reference types` off.
|
|
24
|
+
|
|
25
|
+
- Updated dependencies [[`22ca433`](https://github.com/lynx-family/lynx-stack/commit/22ca433eb96b39724c6eb47ce0a938d291bbdef2)]:
|
|
26
|
+
- @lynx-js/web-constants@0.15.4
|
|
27
|
+
- @lynx-js/web-style-transformer@0.15.4
|
|
28
|
+
|
|
29
|
+
## 0.15.3
|
|
30
|
+
|
|
31
|
+
### Patch Changes
|
|
32
|
+
|
|
33
|
+
- Updated dependencies [[`0da5ef0`](https://github.com/lynx-family/lynx-stack/commit/0da5ef03e41f20e9f8019c6dc03cb4a38ab18854)]:
|
|
34
|
+
- @lynx-js/web-constants@0.15.3
|
|
35
|
+
|
|
3
36
|
## 0.15.2
|
|
4
37
|
|
|
5
38
|
### Patch Changes
|
|
@@ -16,10 +16,11 @@ export interface MainThreadRuntimeConfig {
|
|
|
16
16
|
callbacks: MainThreadRuntimeCallbacks;
|
|
17
17
|
styleInfo: StyleInfo;
|
|
18
18
|
customSections: LynxTemplate['customSections'];
|
|
19
|
+
elementTemplate: LynxTemplate['elementTemplate'];
|
|
19
20
|
lepusCode: Record<string, LynxJSModule>;
|
|
20
21
|
browserConfig: BrowserConfig;
|
|
21
22
|
tagMap: Record<string, string>;
|
|
22
|
-
rootDom: Pick<Element, 'append' | 'addEventListener'> & Partial<Pick<
|
|
23
|
+
rootDom: Pick<Element, 'append' | 'addEventListener'> & Partial<Pick<ShadowRoot, 'querySelectorAll' | 'cloneNode'>>;
|
|
23
24
|
jsContext: LynxContextEventTarget;
|
|
24
25
|
ssrHydrateInfo?: SSRHydrateInfo;
|
|
25
26
|
ssrHooks?: SSRDehydrateHooks;
|
|
@@ -376,9 +376,69 @@ export function createMainThreadGlobalThis(config) {
|
|
|
376
376
|
const __GetPageElement = () => {
|
|
377
377
|
return pageElement;
|
|
378
378
|
};
|
|
379
|
+
const templateIdToTemplate = {};
|
|
380
|
+
const createElementForElementTemplateData = (data, parentComponentUniId) => {
|
|
381
|
+
const element = __CreateElement(data.type, parentComponentUniId);
|
|
382
|
+
__SetID(element, data.id);
|
|
383
|
+
__SetClasses(element, data.class.join(' '));
|
|
384
|
+
for (const [key, value] of Object.entries(data.attributes)) {
|
|
385
|
+
__SetAttribute(element, key, value);
|
|
386
|
+
}
|
|
387
|
+
for (const [key, value] of Object.entries(data.builtinAttributes)) {
|
|
388
|
+
__SetAttribute(element, key, value);
|
|
389
|
+
}
|
|
390
|
+
for (const childData of data.children) {
|
|
391
|
+
__AppendElement(element, createElementForElementTemplateData(childData, parentComponentUniId));
|
|
392
|
+
}
|
|
393
|
+
return element;
|
|
394
|
+
};
|
|
395
|
+
const applyEventsForElementTemplate = (data, element) => {
|
|
396
|
+
const uniqueId = uniqueIdInc++;
|
|
397
|
+
element.setAttribute(lynxUniqueIdAttribute, uniqueId + '');
|
|
398
|
+
for (const event of data.events) {
|
|
399
|
+
const { type, name, value } = event;
|
|
400
|
+
__AddEvent(element, type, name, value);
|
|
401
|
+
}
|
|
402
|
+
for (let ii = 0; ii < data.children.length; ii++) {
|
|
403
|
+
const childData = data.children[ii];
|
|
404
|
+
const childElement = element.children[ii];
|
|
405
|
+
if (childData && childElement) {
|
|
406
|
+
applyEventsForElementTemplate(childData, childElement);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
};
|
|
410
|
+
const __ElementFromBinary = (templateId, parentComponentUniId) => {
|
|
411
|
+
const elementTemplateData = config.elementTemplate[templateId];
|
|
412
|
+
if (elementTemplateData) {
|
|
413
|
+
let clonedElements;
|
|
414
|
+
if (templateIdToTemplate[templateId]) {
|
|
415
|
+
clonedElements = Array.from(templateIdToTemplate[templateId].content.cloneNode(true).children);
|
|
416
|
+
}
|
|
417
|
+
else {
|
|
418
|
+
clonedElements = elementTemplateData.map(data => createElementForElementTemplateData(data, parentComponentUniId));
|
|
419
|
+
if (rootDom.cloneNode) {
|
|
420
|
+
const template = callbacks.createElement('template');
|
|
421
|
+
template.content.append(...clonedElements);
|
|
422
|
+
templateIdToTemplate[templateId] = template;
|
|
423
|
+
rootDom.append(template);
|
|
424
|
+
return __ElementFromBinary(templateId, parentComponentUniId);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
for (let ii = 0; ii < clonedElements.length; ii++) {
|
|
428
|
+
const data = elementTemplateData[ii];
|
|
429
|
+
const element = clonedElements[ii];
|
|
430
|
+
if (data && element) {
|
|
431
|
+
applyEventsForElementTemplate(data, element);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
return clonedElements;
|
|
435
|
+
}
|
|
436
|
+
return [];
|
|
437
|
+
};
|
|
379
438
|
let release = '';
|
|
380
439
|
const isCSSOG = !pageConfig.enableCSSSelector;
|
|
381
440
|
const mtsGlobalThis = {
|
|
441
|
+
__ElementFromBinary,
|
|
382
442
|
__GetTemplateParts: rootDom.querySelectorAll
|
|
383
443
|
? __GetTemplateParts
|
|
384
444
|
: undefined,
|
|
@@ -6,8 +6,8 @@ import { registerCallLepusMethodHandler } from './crossThreadHandlers/registerCa
|
|
|
6
6
|
import { registerGetCustomSectionHandler } from './crossThreadHandlers/registerGetCustomSectionHandler.js';
|
|
7
7
|
import { createMainThreadGlobalThis } from './createMainThreadGlobalThis.js';
|
|
8
8
|
import { createExposureService } from './utils/createExposureService.js';
|
|
9
|
-
import {
|
|
10
|
-
const
|
|
9
|
+
import { initWasm } from '@lynx-js/web-style-transformer';
|
|
10
|
+
const initWasmPromise = initWasm();
|
|
11
11
|
const moduleCache = {};
|
|
12
12
|
export function prepareMainThreadAPIs(backgroundThreadRpc, rootDom, createElement, commitDocument, markTimingInternal, flushMarkTimingInternal, reportError, triggerI18nResourceFallback, initialI18nResources, ssrHooks) {
|
|
13
13
|
const postTimingFlags = backgroundThreadRpc.createCall(postTimingFlagsEndpoint);
|
|
@@ -20,9 +20,9 @@ export function prepareMainThreadAPIs(backgroundThreadRpc, rootDom, createElemen
|
|
|
20
20
|
async function startMainThread(config, ssrHydrateInfo) {
|
|
21
21
|
let isFp = true;
|
|
22
22
|
const { globalProps, template, browserConfig, nativeModulesMap, napiModulesMap, tagMap, initI18nResources, } = config;
|
|
23
|
-
const { styleInfo, pageConfig, customSections, cardType, lepusCode } = template;
|
|
23
|
+
const { styleInfo, pageConfig, customSections, cardType, lepusCode, elementTemplate, } = template;
|
|
24
24
|
markTimingInternal('decode_start');
|
|
25
|
-
await
|
|
25
|
+
await initWasmPromise;
|
|
26
26
|
const lepusCodeEntries = await Promise.all(Object.entries(lepusCode).map(async ([name, url]) => {
|
|
27
27
|
const cachedModule = moduleCache[url];
|
|
28
28
|
if (cachedModule) {
|
|
@@ -50,6 +50,7 @@ export function prepareMainThreadAPIs(backgroundThreadRpc, rootDom, createElemen
|
|
|
50
50
|
tagMap,
|
|
51
51
|
browserConfig,
|
|
52
52
|
customSections,
|
|
53
|
+
elementTemplate,
|
|
53
54
|
globalProps,
|
|
54
55
|
pageConfig,
|
|
55
56
|
styleInfo,
|
package/dist/utils/tokenizer.js
CHANGED
|
@@ -1,22 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
import init from '@lynx-js/web-style-transformer';
|
|
3
|
-
let wasm;
|
|
1
|
+
import { wasm } from '@lynx-js/web-style-transformer';
|
|
4
2
|
let HEAPU16;
|
|
5
|
-
var ENVIRONMENT_IS_NODE = typeof process == 'object'
|
|
6
|
-
&& typeof process.versions == 'object'
|
|
7
|
-
&& typeof process.versions.node == 'string';
|
|
8
|
-
export const initTokenizer = async () => {
|
|
9
|
-
// initialize wasm module in node.js environment
|
|
10
|
-
if (ENVIRONMENT_IS_NODE) {
|
|
11
|
-
const path = await import(/* webpackIgnore:true */ 'node:path');
|
|
12
|
-
const fs = await import(/* webpackIgnore:true */ 'node:fs/promises');
|
|
13
|
-
const wasmModuleBuffer = await fs.readFile(path.join(import.meta.dirname, '..', '..', 'node_modules', '@lynx-js', 'web-style-transformer', 'dist', 'index_bg.wasm'));
|
|
14
|
-
wasm = await init(wasmModuleBuffer);
|
|
15
|
-
}
|
|
16
|
-
else {
|
|
17
|
-
wasm = await init();
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
3
|
const stringToUTF16 = (str) => {
|
|
21
4
|
const len = str.length;
|
|
22
5
|
const ptr = wasm.malloc(len << 1);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lynx-js/web-mainthread-apis",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.4",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"keywords": [],
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"hyphenate-style-name": "^1.1.0",
|
|
28
|
-
"@lynx-js/web-constants": "0.15.
|
|
29
|
-
"@lynx-js/web-style-transformer": "0.
|
|
28
|
+
"@lynx-js/web-constants": "0.15.4",
|
|
29
|
+
"@lynx-js/web-style-transformer": "0.15.4"
|
|
30
30
|
}
|
|
31
31
|
}
|