@lynx-js/web-mainthread-apis 0.15.5 → 0.15.7

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,37 @@
1
1
  # @lynx-js/web-mainthread-apis
2
2
 
3
+ ## 0.15.7
4
+
5
+ ### Patch Changes
6
+
7
+ - fix: globalThis is never accessible in MTS ([#1531](https://github.com/lynx-family/lynx-stack/pull/1531))
8
+
9
+ - Updated dependencies [[`70863fb`](https://github.com/lynx-family/lynx-stack/commit/70863fbc311d8885ebda40855668097b0631f521)]:
10
+ - @lynx-js/web-constants@0.15.7
11
+ - @lynx-js/web-style-transformer@0.15.7
12
+
13
+ ## 0.15.6
14
+
15
+ ### Patch Changes
16
+
17
+ - fix: systeminfo in mts function ([#1537](https://github.com/lynx-family/lynx-stack/pull/1537))
18
+
19
+ - refactor: use utf-8 string ([#1473](https://github.com/lynx-family/lynx-stack/pull/1473))
20
+
21
+ - feat: add MTS API: \_\_UpdateComponentInfo ([#1485](https://github.com/lynx-family/lynx-stack/pull/1485))
22
+
23
+ - fix: \_\_ElementFromBinary should mark all elements actively ([#1484](https://github.com/lynx-family/lynx-stack/pull/1484))
24
+
25
+ - fix: `__ElementFromBinary` needs to correctly apply the dataset in elementTemplate to the Element ([#1487](https://github.com/lynx-family/lynx-stack/pull/1487))
26
+
27
+ - fix: all attributes except `id` and `type` under ElementTemplateData are optional. ([#1483](https://github.com/lynx-family/lynx-stack/pull/1483))
28
+
29
+ - feat: add MTS API \_\_GetAttributeByName ([#1486](https://github.com/lynx-family/lynx-stack/pull/1486))
30
+
31
+ - Updated dependencies [[`405a917`](https://github.com/lynx-family/lynx-stack/commit/405a9170442ae32603b7687549b49ab4b34aff92), [`b8f89e2`](https://github.com/lynx-family/lynx-stack/commit/b8f89e25f106a15ba9d70f2df06dfb684cbb6633), [`f76aae9`](https://github.com/lynx-family/lynx-stack/commit/f76aae9ea06abdc7022ba508d22f9f4eb00864e8), [`d8381a5`](https://github.com/lynx-family/lynx-stack/commit/d8381a58d12af6424cab4955617251e798bdc9f1), [`214898b`](https://github.com/lynx-family/lynx-stack/commit/214898bb9c74fc9b44e68cb220a4c02485102ce2), [`ab8cee4`](https://github.com/lynx-family/lynx-stack/commit/ab8cee4bab384fa905c045c4b4b93e5d4a95d57f)]:
32
+ - @lynx-js/web-constants@0.15.6
33
+ - @lynx-js/web-style-transformer@0.15.6
34
+
3
35
  ## 0.15.5
4
36
 
5
37
  ### Patch Changes
@@ -1,11 +1,11 @@
1
1
  // Copyright 2023 The Lynx Authors. All rights reserved.
2
2
  // Licensed under the Apache License Version 2.0 that can be found in the
3
3
  // LICENSE file in the root directory of this source tree.
4
- import { lynxUniqueIdAttribute, systemInfo, parentComponentUniqueIdAttribute, componentIdAttribute, LynxEventNameToW3cByTagName, LynxEventNameToW3cCommon, lynxTagAttribute, W3cEventNameToLynx, cssIdAttribute, lynxDefaultDisplayLinearAttribute, __lynx_timing_flag, lynxDisposedAttribute, } from '@lynx-js/web-constants';
4
+ import { lynxUniqueIdAttribute, systemInfo, parentComponentUniqueIdAttribute, componentIdAttribute, LynxEventNameToW3cByTagName, LynxEventNameToW3cCommon, lynxTagAttribute, W3cEventNameToLynx, cssIdAttribute, lynxDefaultDisplayLinearAttribute, __lynx_timing_flag, lynxDisposedAttribute, globalDisallowedVars, } from '@lynx-js/web-constants';
5
5
  import { globalMuteableVars } from '@lynx-js/web-constants';
6
6
  import { createMainThreadLynx } from './createMainThreadLynx.js';
7
7
  import { flattenStyleInfo, genCssContent, genCssOGInfo, transformToWebCss, } from './utils/processStyleInfo.js';
8
- import { __AddClass, __AddConfig, __AddDataset, __AddInlineStyle, __AppendElement, __ElementIsEqual, __FirstElement, __GetAttributes, __GetChildren, __GetClasses, __GetComponentID, __GetDataByKey, __GetDataset, __GetElementConfig, __GetElementUniqueID, __GetID, __GetParent, __GetTag, __GetTemplateParts, __InsertElementBefore, __LastElement, __MarkPartElement, __MarkTemplateElement, __NextElement, __RemoveElement, __ReplaceElement, __ReplaceElements, __SetClasses, __SetConfig, __SetCSSId, __SetDataset, __SetID, __SetInlineStyles, __UpdateComponentID, } from './pureElementPAPIs.js';
8
+ import { __AddClass, __AddConfig, __AddDataset, __AddInlineStyle, __AppendElement, __ElementIsEqual, __FirstElement, __GetAttributes, __GetChildren, __GetClasses, __GetComponentID, __GetDataByKey, __GetDataset, __GetElementConfig, __GetElementUniqueID, __GetID, __GetParent, __GetTag, __GetTemplateParts, __InsertElementBefore, __LastElement, __MarkPartElement, __MarkTemplateElement, __NextElement, __RemoveElement, __ReplaceElement, __ReplaceElements, __SetClasses, __SetConfig, __SetCSSId, __SetDataset, __SetID, __SetInlineStyles, __UpdateComponentID, __UpdateComponentInfo, __GetAttributeByName, } from './pureElementPAPIs.js';
9
9
  import { createCrossThreadEvent } from './utils/createCrossThreadEvent.js';
10
10
  import { decodeCssOG } from './utils/decodeCssOG.js';
11
11
  const exposureRelatedAttributes = new Set([
@@ -380,27 +380,31 @@ export function createMainThreadGlobalThis(config) {
380
380
  const createElementForElementTemplateData = (data, parentComponentUniId) => {
381
381
  const element = __CreateElement(data.type, parentComponentUniId);
382
382
  __SetID(element, data.id);
383
- __SetClasses(element, data.class.join(' '));
384
- for (const [key, value] of Object.entries(data.attributes)) {
383
+ data.class && __SetClasses(element, data.class.join(' '));
384
+ for (const [key, value] of Object.entries(data.attributes || {})) {
385
385
  __SetAttribute(element, key, value);
386
386
  }
387
- for (const [key, value] of Object.entries(data.builtinAttributes)) {
387
+ for (const [key, value] of Object.entries(data.builtinAttributes || {})) {
388
+ if (key === 'dirtyID' && value === data.id) {
389
+ __MarkPartElement(element, value);
390
+ }
388
391
  __SetAttribute(element, key, value);
389
392
  }
390
- for (const childData of data.children) {
393
+ for (const childData of data.children || []) {
391
394
  __AppendElement(element, createElementForElementTemplateData(childData, parentComponentUniId));
392
395
  }
396
+ data.dataset !== undefined && __SetDataset(element, data.dataset);
393
397
  return element;
394
398
  };
395
399
  const applyEventsForElementTemplate = (data, element) => {
396
400
  const uniqueId = uniqueIdInc++;
397
401
  element.setAttribute(lynxUniqueIdAttribute, uniqueId + '');
398
- for (const event of data.events) {
402
+ for (const event of data.events || []) {
399
403
  const { type, name, value } = event;
400
404
  __AddEvent(element, type, name, value);
401
405
  }
402
- for (let ii = 0; ii < data.children.length; ii++) {
403
- const childData = data.children[ii];
406
+ for (let ii = 0; ii < (data.children || []).length; ii++) {
407
+ const childData = (data.children || [])[ii];
404
408
  const childElement = element.children[ii];
405
409
  if (childData && childElement) {
406
410
  applyEventsForElementTemplate(childData, childElement);
@@ -431,12 +435,17 @@ export function createMainThreadGlobalThis(config) {
431
435
  applyEventsForElementTemplate(data, element);
432
436
  }
433
437
  }
438
+ clonedElements.forEach(__MarkTemplateElement);
434
439
  return clonedElements;
435
440
  }
436
441
  return [];
437
442
  };
438
443
  let release = '';
439
444
  const isCSSOG = !pageConfig.enableCSSSelector;
445
+ const SystemInfo = {
446
+ ...systemInfo,
447
+ ...config.browserConfig,
448
+ };
440
449
  const mtsGlobalThis = {
441
450
  __ElementFromBinary,
442
451
  __GetTemplateParts: rootDom.querySelectorAll
@@ -473,6 +482,7 @@ export function createMainThreadGlobalThis(config) {
473
482
  __SetDataset,
474
483
  __SetID,
475
484
  __UpdateComponentID,
485
+ __UpdateComponentInfo,
476
486
  __CreateElement,
477
487
  __CreateView,
478
488
  __CreateText,
@@ -487,6 +497,7 @@ export function createMainThreadGlobalThis(config) {
487
497
  __SwapElement,
488
498
  __UpdateListCallbacks,
489
499
  __GetConfig: __GetElementConfig,
500
+ __GetAttributeByName,
490
501
  __GetClasses,
491
502
  __AddClass: isCSSOG ? __AddClassForCSSOG : __AddClass,
492
503
  __SetClasses: isCSSOG ? __SetClassesForCSSOG : __SetClasses,
@@ -496,11 +507,8 @@ export function createMainThreadGlobalThis(config) {
496
507
  __LoadLepusChunk,
497
508
  __GetPageElement,
498
509
  __globalProps: globalProps,
499
- SystemInfo: {
500
- ...systemInfo,
501
- ...config.browserConfig,
502
- },
503
- lynx: createMainThreadLynx(config),
510
+ SystemInfo,
511
+ lynx: createMainThreadLynx(config, SystemInfo),
504
512
  _ReportError: (err, _) => callbacks._ReportError(err, _, release),
505
513
  _SetSourceMapRelease: (errInfo) => release = errInfo?.release,
506
514
  __OnLifecycleEvent: callbacks.__OnLifecycleEvent,
@@ -521,6 +529,9 @@ export function createMainThreadGlobalThis(config) {
521
529
  };
522
530
  mtsGlobalThis.globalThis = new Proxy(mtsGlobalThis, {
523
531
  get: (target, prop) => {
532
+ if (typeof prop === 'string' && globalDisallowedVars.includes(prop)) {
533
+ return undefined;
534
+ }
524
535
  if (prop === 'globalThis') {
525
536
  return target;
526
537
  }
@@ -1,3 +1,3 @@
1
1
  import type { MainThreadLynx } from '@lynx-js/web-constants';
2
2
  import { type MainThreadRuntimeConfig } from './createMainThreadGlobalThis.js';
3
- export declare function createMainThreadLynx(config: MainThreadRuntimeConfig): MainThreadLynx;
3
+ export declare function createMainThreadLynx(config: MainThreadRuntimeConfig, SystemInfo: Record<string, any>): MainThreadLynx;
@@ -1,5 +1,5 @@
1
1
  import {} from './createMainThreadGlobalThis.js';
2
- export function createMainThreadLynx(config) {
2
+ export function createMainThreadLynx(config, SystemInfo) {
3
3
  return {
4
4
  getJSContext() {
5
5
  return config.jsContext;
@@ -15,6 +15,7 @@ export function createMainThreadLynx(config) {
15
15
  return config.customSections[key]?.content;
16
16
  },
17
17
  markPipelineTiming: config.callbacks.markTiming,
18
+ SystemInfo,
18
19
  };
19
20
  }
20
21
  //# sourceMappingURL=createMainThreadLynx.js.map
@@ -1,4 +1,4 @@
1
- import { type AddClassPAPI, type AddConfigPAPI, type AddDatasetPAPI, type AddInlineStylePAPI, type AppendElementPAPI, type ElementIsEqualPAPI, type FirstElementPAPI, type GetAttributesPAPI, type GetChildrenPAPI, type GetClassesPAPI, type GetComponentIdPAPI, type GetDataByKeyPAPI, type GetDatasetPAPI, type GetElementConfigPAPI, type GetElementUniqueIDPAPI, type GetIDPAPI, type GetParentPAPI, type GetTagPAPI, type GetTemplatePartsPAPI, type InsertElementBeforePAPI, type LastElementPAPI, type MarkPartElementPAPI, type MarkTemplateElementPAPI, type NextElementPAPI, type RemoveElementPAPI, type ReplaceElementPAPI, type ReplaceElementsPAPI, type SetClassesPAPI, type SetConfigPAPI, type SetCSSIdPAPI, type SetDatasetPAPI, type SetIDPAPI, type SetInlineStylesPAPI, type UpdateComponentIDPAPI } from '@lynx-js/web-constants';
1
+ import { type AddClassPAPI, type AddConfigPAPI, type AddDatasetPAPI, type AddInlineStylePAPI, type AppendElementPAPI, type ElementIsEqualPAPI, type FirstElementPAPI, type GetAttributeByNamePAPI, type GetAttributesPAPI, type GetChildrenPAPI, type GetClassesPAPI, type GetComponentIdPAPI, type GetDataByKeyPAPI, type GetDatasetPAPI, type GetElementConfigPAPI, type GetElementUniqueIDPAPI, type GetIDPAPI, type GetParentPAPI, type GetTagPAPI, type GetTemplatePartsPAPI, type InsertElementBeforePAPI, type LastElementPAPI, type MarkPartElementPAPI, type MarkTemplateElementPAPI, type NextElementPAPI, type RemoveElementPAPI, type ReplaceElementPAPI, type ReplaceElementsPAPI, type SetClassesPAPI, type SetConfigPAPI, type SetCSSIdPAPI, type SetDatasetPAPI, type SetIDPAPI, type SetInlineStylesPAPI, type UpdateComponentIDPAPI, type UpdateComponentInfoPAPI } from '@lynx-js/web-constants';
2
2
  export declare const __AppendElement: AppendElementPAPI;
3
3
  export declare const __ElementIsEqual: ElementIsEqualPAPI;
4
4
  export declare const __FirstElement: FirstElementPAPI;
@@ -17,6 +17,7 @@ export declare const __GetDataByKey: GetDataByKeyPAPI;
17
17
  export declare const __GetAttributes: GetAttributesPAPI;
18
18
  export declare const __GetComponentID: GetComponentIdPAPI;
19
19
  export declare const __GetElementConfig: GetElementConfigPAPI;
20
+ export declare const __GetAttributeByName: GetAttributeByNamePAPI;
20
21
  export declare const __GetElementUniqueID: GetElementUniqueIDPAPI;
21
22
  export declare const __GetID: GetIDPAPI;
22
23
  export declare const __SetID: SetIDPAPI;
@@ -25,6 +26,7 @@ export declare const __SetConfig: SetConfigPAPI;
25
26
  export declare const __SetDataset: SetDatasetPAPI;
26
27
  export declare const __UpdateComponentID: UpdateComponentIDPAPI;
27
28
  export declare const __GetClasses: GetClassesPAPI;
29
+ export declare const __UpdateComponentInfo: UpdateComponentInfoPAPI;
28
30
  export declare const __SetCSSId: SetCSSIdPAPI;
29
31
  export declare const __SetClasses: SetClassesPAPI;
30
32
  export declare const __AddInlineStyle: AddInlineStylePAPI;
@@ -67,6 +67,7 @@ export const __GetElementConfig = /*#__PURE__*/ (element) => {
67
67
  ? JSON.parse(decodeURIComponent(currentComponentConfigString))
68
68
  : {};
69
69
  };
70
+ export const __GetAttributeByName = /*#__PURE__*/ (element, name) => element.getAttribute(name);
70
71
  export const __GetElementUniqueID = /*#__PURE__*/ (element) => (element && element.getAttribute
71
72
  ? Number(element.getAttribute(lynxUniqueIdAttribute))
72
73
  : -1);
@@ -84,6 +85,13 @@ export const __SetDataset = /*#__PURE__*/ (element, dataset) => {
84
85
  };
85
86
  export const __UpdateComponentID = /*#__PURE__*/ (element, componentID) => element.setAttribute(componentIdAttribute, componentID);
86
87
  export const __GetClasses = /*#__PURE__*/ (element) => ((element.getAttribute('class') ?? '').split(' ').filter(e => e));
88
+ export const __UpdateComponentInfo = /*#__PURE__*/ (element, params) => {
89
+ params.componentID !== undefined
90
+ && __UpdateComponentID(element, params.componentID);
91
+ params.cssID !== undefined
92
+ && element.setAttribute(cssIdAttribute, params.cssID + '');
93
+ params.name !== undefined && element.setAttribute('name', params.name);
94
+ };
87
95
  export const __SetCSSId = /*#__PURE__*/ (elements, cssId) => {
88
96
  for (const element of elements) {
89
97
  element.setAttribute(cssIdAttribute, cssId + '');
@@ -1,56 +1,23 @@
1
1
  import { wasm } from '@lynx-js/web-style-transformer';
2
- let HEAPU16;
3
- const stringToUTF16 = (str) => {
4
- const len = str.length;
5
- const ptr = wasm.malloc(len << 1);
6
- if (!HEAPU16 || HEAPU16.byteLength == 0) {
7
- HEAPU16 = new Uint16Array(wasm.memory.buffer);
8
- }
9
- for (let i = 0; i < len; i++) {
10
- HEAPU16[(ptr >> 1) + i] = str.charCodeAt(i);
11
- }
12
- return { ptr, len };
13
- };
14
2
  export function transformInlineStyleString(str) {
15
- const { ptr, len } = stringToUTF16(str);
16
- try {
17
- const transformedStyle = wasm.transform_raw_u16_inline_style_ptr(ptr, len)
18
- ?? str;
19
- wasm.free(ptr, len << 1);
20
- return transformedStyle;
21
- }
22
- catch (e) {
23
- wasm.free(ptr, len << 1);
24
- throw e;
25
- }
3
+ return wasm.transform_raw_u16_inline_style_ptr(str) ?? str;
26
4
  }
27
5
  export function transformParsedStyles(styles) {
28
6
  let childStyle = [];
29
7
  let transformedStyle = [];
30
8
  for (const [property, value] of styles) {
31
- const { ptr: propertyPtr, len: propertyLen } = stringToUTF16(property);
32
- const { ptr: valuePtr, len: valueLen } = stringToUTF16(value);
33
- try {
34
- const transformedResult = wasm
35
- .transform_raw_u16_inline_style_ptr_parsed(propertyPtr, propertyLen, valuePtr, valueLen);
36
- wasm.free(propertyPtr, propertyLen << 1);
37
- wasm.free(valuePtr, valueLen << 1);
38
- if (transformedResult) {
39
- const [transformedStyleForCurrent, childStyleForCurrent] = transformedResult;
40
- transformedStyle = transformedStyle.concat(transformedStyleForCurrent);
41
- if (childStyleForCurrent) {
42
- childStyle = childStyle.concat(childStyleForCurrent);
43
- }
44
- }
45
- else {
46
- // If the transformation fails, we keep the original style
47
- transformedStyle.push([property, value]);
9
+ const transformedResult = wasm
10
+ .transform_raw_u16_inline_style_ptr_parsed(property, value);
11
+ if (transformedResult) {
12
+ const [transformedStyleForCurrent, childStyleForCurrent] = transformedResult;
13
+ transformedStyle = transformedStyle.concat(transformedStyleForCurrent);
14
+ if (childStyleForCurrent) {
15
+ childStyle = childStyle.concat(childStyleForCurrent);
48
16
  }
49
17
  }
50
- catch (e) {
51
- wasm.free(propertyPtr, propertyLen << 1);
52
- wasm.free(valuePtr, valueLen << 1);
53
- throw e;
18
+ else {
19
+ // If the transformation fails, we keep the original style
20
+ transformedStyle.push([property, value]);
54
21
  }
55
22
  }
56
23
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/web-mainthread-apis",
3
- "version": "0.15.5",
3
+ "version": "0.15.7",
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.5",
29
- "@lynx-js/web-style-transformer": "0.15.5"
28
+ "@lynx-js/web-constants": "0.15.7",
29
+ "@lynx-js/web-style-transformer": "0.15.7"
30
30
  }
31
31
  }