@lynx-js/web-core 0.7.1 → 0.9.0

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,198 @@
1
1
  # @lynx-js/web-core
2
2
 
3
+ ## 0.9.0
4
+
5
+ ### Minor Changes
6
+
7
+ - feat: `nativeModulesUrl` of lynx-view is changed to `nativeModulesMap`, and the usage is completely aligned with `napiModulesMap`. ([#220](https://github.com/lynx-family/lynx-stack/pull/220))
8
+
9
+ "warning: This is a breaking change."
10
+
11
+ `nativeModulesMap` will be a map: key is module-name, value should be a esm url which export default a
12
+ function with two parameters(you never need to use `this`):
13
+
14
+ - `NativeModules`: oriented `NativeModules`, which you can use to call
15
+ other Native-Modules.
16
+
17
+ - `NativeModulesCall`: trigger `onNativeModulesCall`, same as the deprecated `this.nativeModulesCall`.
18
+
19
+ example:
20
+
21
+ ```js
22
+ const nativeModulesMap = {
23
+ CustomModule: URL.createObjectURL(
24
+ new Blob(
25
+ [
26
+ `export default function(NativeModules, NativeModulesCall) {
27
+ return {
28
+ async getColor(data, callback) {
29
+ const color = await NativeModulesCall('getColor', data);
30
+ callback(color);
31
+ },
32
+ }
33
+ };`,
34
+ ],
35
+ { type: 'text/javascript' },
36
+ ),
37
+ ),
38
+ };
39
+ lynxView.nativeModulesMap = nativeModulesMap;
40
+ ```
41
+
42
+ In addition, we will use Promise.all to load `nativeModules`, which will optimize performance in the case of multiple modules.
43
+
44
+ - refractor: remove entryId concept ([#217](https://github.com/lynx-family/lynx-stack/pull/217))
45
+
46
+ After the PR #198
47
+ All contents are isolated by a shadowroot.
48
+ Therefore we don't need to add the entryId selector to avoid the lynx-view's style taking effect on the whole page.
49
+
50
+ ### Patch Changes
51
+
52
+ - refactor: code clean ([#266](https://github.com/lynx-family/lynx-stack/pull/266))
53
+
54
+ - refactor: clean the decodeOperations implementation ([#261](https://github.com/lynx-family/lynx-stack/pull/261))
55
+
56
+ - fix: When the width and height of lynx-view are not auto, the width and height of the `lynx-tag="page"` need to be correctly set to 100%. ([#228](https://github.com/lynx-family/lynx-stack/pull/228))
57
+
58
+ - refactor: remove customelement defined detecting logic ([#247](https://github.com/lynx-family/lynx-stack/pull/247))
59
+
60
+ Before this commit, for those element with tag without `-`, we always try to detect if the `x-${tagName}` is defined.
61
+
62
+ After this commit, we pre-define a map(could be override by the `overrideLynxTagToHTMLTagMap`) to make that transformation for tag name.
63
+
64
+ This change is a path to SSR and the MTS support.
65
+
66
+ - fix: 'error' event for main-thread \_reportError ([#283](https://github.com/lynx-family/lynx-stack/pull/283))
67
+
68
+ - Updated dependencies [[`5b5e090`](https://github.com/lynx-family/lynx-stack/commit/5b5e090fdf0e896f1c38a49bf3ed9889117c4fb8), [`b844e75`](https://github.com/lynx-family/lynx-stack/commit/b844e751f566d924256365d37aec4c86c520ec00), [`53230f0`](https://github.com/lynx-family/lynx-stack/commit/53230f012216f3a627853e11d544e4be175c5b9b), [`6f16827`](https://github.com/lynx-family/lynx-stack/commit/6f16827d1f4d7364870d354fc805a8868c110f1e), [`d2d55ef`](https://github.com/lynx-family/lynx-stack/commit/d2d55ef9fe438c35921d9db0daa40d5228822ecc)]:
69
+ - @lynx-js/web-worker-runtime@0.9.0
70
+ - @lynx-js/web-constants@0.9.0
71
+ - @lynx-js/web-worker-rpc@0.9.0
72
+
73
+ ## 0.8.0
74
+
75
+ ### Minor Changes
76
+
77
+ - refactor: remove web-elements/lazy and loadNewTag ([#123](https://github.com/lynx-family/lynx-stack/pull/123))
78
+
79
+ - remove @lynx-js/web-elements/lazy
80
+ - remove loadElement
81
+ - remove loadNewTag callback
82
+
83
+ **This is a breaking change**
84
+
85
+ Now we removed the default lazy loading preinstalled in web-core
86
+
87
+ Please add the following statement in your web project
88
+
89
+ ```
90
+ import "@lynx-js/web-elements/all";
91
+ ```
92
+
93
+ - feat: use shadowroot to isolate one lynx-view ([#198](https://github.com/lynx-family/lynx-stack/pull/198))
94
+
95
+ Before this commit, we have been detecting if current browser supports the `@scope` rule.
96
+ This allows us to scope one lynx-view's styles.
97
+
98
+ After this commit we always create a shadowroot to scope then.
99
+
100
+ Also for the new shadowroot pattern, we add a new **attribute** `inject-head-links`.
101
+ By default, we will iterate all `<link rel="stylesheet">` in the `<head>`, and use `@import url()` to import them inside the shadowroot.
102
+ Developers could add a `inject-head-links="false"` to disable this behavior.
103
+
104
+ - feat: never add the x-enable-xx-event attributes ([#157](https://github.com/lynx-family/lynx-stack/pull/157))
105
+
106
+ After this commit, we update the reqirement of the version of `@lynx-js/web-elements` to `>=0.3.1`
107
+
108
+ ### Patch Changes
109
+
110
+ - feat: add pixelRatio of SystemInfo, now you can use `SystemInfo.pixelRatio`. ([#150](https://github.com/lynx-family/lynx-stack/pull/150))
111
+
112
+ - Improve LynxView resize observer cleanup ([#124](https://github.com/lynx-family/lynx-stack/pull/124))
113
+
114
+ - feat: add two prop of lynx-view about `napiLoader`: ([#173](https://github.com/lynx-family/lynx-stack/pull/173))
115
+
116
+ - `napiModulesMap`: [optional] the napiModule which is called in lynx-core. key is module-name, value is esm url.
117
+
118
+ - `onNapiModulesCall`: [optional] the NapiModule value handler.
119
+
120
+ **Warning:** This is the internal implementation of `@lynx-js/lynx-core`. In most cases, this API is not required for projects.
121
+
122
+ 1. The `napiModulesMap` value should be a esm url which export default a function with two parameters:
123
+
124
+ - `NapiModules`: oriented `napiModulesMap`, which you can use to call other Napi-Modules
125
+
126
+ - `NapiModulesCall`: trigger `onNapiModulesCall`
127
+
128
+ example:
129
+
130
+ ```js
131
+ const color_environment = URL.createObjectURL(
132
+ new Blob(
133
+ [
134
+ `export default function(NapiModules, NapiModulesCall) {
135
+ return {
136
+ getColor() {
137
+ NapiModules.color_methods.getColor({ color: 'green' }, color => {
138
+ console.log(color);
139
+ });
140
+ },
141
+ ColorEngine: class ColorEngine {
142
+ getColor(name) {
143
+ NapiModules.color_methods.getColor({ color: 'green' }, color => {
144
+ console.log(color);
145
+ });
146
+ }
147
+ },
148
+ };
149
+ };`,
150
+ ],
151
+ { type: 'text/javascript' },
152
+ ),
153
+ );
154
+
155
+ const color_methods = URL.createObjectURL(
156
+ new Blob(
157
+ [
158
+ `export default function(NapiModules, NapiModulesCall) {
159
+ return {
160
+ async getColor(data, callback) {
161
+ const color = await NapiModulesCall('getColor', data);
162
+ callback(color);
163
+ },
164
+ };
165
+ };`,
166
+ ],
167
+ { type: 'text/javascript' },
168
+ ),
169
+ );
170
+
171
+ lynxView.napiModuleMap = {
172
+ color_environment: color_environment,
173
+ color_methods: color_methods,
174
+ };
175
+ ```
176
+
177
+ 2. The `onNapiModulesCall` function has three parameters:
178
+
179
+ - `name`: the first parameter of `NapiModulesCall`, the function name
180
+ - `data`: the second parameter of `NapiModulesCall`, data
181
+ - `moduleName`: the module-name of the called napi-module
182
+
183
+ ```js
184
+ lynxView.onNapiModulesCall = (name, data, moduleName) => {
185
+ if (name === 'getColor' && moduleName === 'color_methods') {
186
+ return data.color;
187
+ }
188
+ };
189
+ ```
190
+
191
+ - Updated dependencies [[`eab1328`](https://github.com/lynx-family/lynx-stack/commit/eab1328a83797fc903255c984d9f39537b9138b9), [`e9e8370`](https://github.com/lynx-family/lynx-stack/commit/e9e8370e070a50cbf65a4ebc46c2e37ea1e0be40), [`ec4e1ce`](https://github.com/lynx-family/lynx-stack/commit/ec4e1ce0d7612d6c0701792a46c78cd52130bad4), [`f0a717c`](https://github.com/lynx-family/lynx-stack/commit/f0a717c630700e16ab0af7f1fe370fd60ac75b30)]:
192
+ - @lynx-js/web-worker-runtime@0.8.0
193
+ - @lynx-js/web-constants@0.8.0
194
+ - @lynx-js/web-worker-rpc@0.8.0
195
+
3
196
  ## 0.7.1
4
197
 
5
198
  ### Patch Changes
@@ -1,15 +1,19 @@
1
- import { type Cloneable, type NativeModulesCall, type UpdateDataType } from '@lynx-js/web-constants';
1
+ import { type Cloneable, type NapiModulesCall, type NapiModulesMap, type NativeModulesCall, type NativeModulesMap, type UpdateDataType } from '@lynx-js/web-constants';
2
+ /**
3
+ * Based on our experiences, these elements are almost used in all lynx cards.
4
+ */
2
5
  /**
3
6
  * @param {string} url [required] The url of the entry of your Lynx card
4
7
  * @param {Cloneable} globalProps [optional] The globalProps value of this Lynx card
5
8
  * @param {Cloneable} initData [oprional] The initial data of this Lynx card
6
9
  * @param {Record<string,string>} overrideLynxTagToHTMLTagMap [optional] use this property/attribute to override the lynx tag -> html tag map
7
- * @param {string} nativeModulesUrl [optional] It is a esm url, use to customize NativeModules.
8
- * @param {INativeModulesCall} onNativeModulesCall [optional] the NativeModules value handler. Arguments will be cached before this property is assigned.
10
+ * @param {NativeModulesMap} nativeModulesMap [optional] use to customize NativeModules. key is module-name, value is esm url.
11
+ * @param {NativeModulesCall} onNativeModulesCall [optional] the NativeModules value handler. Arguments will be cached before this property is assigned.
9
12
  * @param {"auto" | null} height [optional] set it to "auto" for height auto-sizing
10
13
  * @param {"auto" | null} width [optional] set it to "auto" for width auto-sizing
11
- *
12
- * @property entryId the currently Lynx view entryId.
14
+ * @param {NapiModulesMap} napiModulesMap [optional] the napiModule which is called in lynx-core. key is module-name, value is esm url.
15
+ * @param {NapiModulesCall} onNapiModulesCall [optional] the NapiModule value handler.
16
+ * @param {"false" | "true" | null} injectHeadLinks [optional] @default true set it to "false" to disable injecting the <link href="" ref="stylesheet"> styles into shadowroot
13
17
  *
14
18
  * @event error lynx card fired an error
15
19
  *
@@ -59,13 +63,6 @@ export declare class LynxView extends HTMLElement {
59
63
  */
60
64
  get initData(): Cloneable;
61
65
  set initData(val: string | Cloneable);
62
- /**
63
- * @public
64
- * @readonly
65
- * @property
66
- * The random generated entryId of current lynxview
67
- */
68
- get entryId(): string | undefined;
69
66
  /**
70
67
  * @public
71
68
  * @property
@@ -81,10 +78,24 @@ export declare class LynxView extends HTMLElement {
81
78
  set onNativeModulesCall(handler: NativeModulesCall);
82
79
  /**
83
80
  * @public
84
- * @property nativeModules
81
+ * @property nativeModulesMap
82
+ * @default {}
83
+ */
84
+ get nativeModulesMap(): NativeModulesMap | undefined;
85
+ set nativeModulesMap(map: NativeModulesMap);
86
+ /**
87
+ * @param
88
+ * @property napiModulesMap
89
+ * @default {}
90
+ */
91
+ get napiModulesMap(): NapiModulesMap | undefined;
92
+ set napiModulesMap(map: NapiModulesMap);
93
+ /**
94
+ * @param
95
+ * @property
85
96
  */
86
- get nativeModulesUrl(): string | undefined;
87
- set nativeModulesUrl(val: string);
97
+ get onNapiModulesCall(): NapiModulesCall | undefined;
98
+ set onNapiModulesCall(handler: NapiModulesCall);
88
99
  /**
89
100
  * @public
90
101
  * "auto" for auto calculated height
@@ -134,4 +145,5 @@ export declare class LynxView extends HTMLElement {
134
145
  * @private
135
146
  */
136
147
  connectedCallback(): void;
148
+ private cleanupResizeObserver;
137
149
  }
@@ -2,27 +2,23 @@
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
4
  import { createLynxView, } from './createLynxView.js';
5
- import { cardIdAttribute, lynxViewEntryIdPrefix, lynxViewRootDomId, } from '@lynx-js/web-constants';
6
- import { loadElement } from '@lynx-js/web-elements/lazy';
5
+ import { lynxViewRootDomId, } from '@lynx-js/web-constants';
6
+ import { inShadowRootStyles } from './inShadowRootStyles.js';
7
7
  /**
8
8
  * Based on our experiences, these elements are almost used in all lynx cards.
9
9
  */
10
- loadElement('lynx-wrapper');
11
- loadElement('x-view');
12
- loadElement('x-text');
13
- loadElement('x-image');
14
- loadElement('scroll-view');
15
10
  /**
16
11
  * @param {string} url [required] The url of the entry of your Lynx card
17
12
  * @param {Cloneable} globalProps [optional] The globalProps value of this Lynx card
18
13
  * @param {Cloneable} initData [oprional] The initial data of this Lynx card
19
14
  * @param {Record<string,string>} overrideLynxTagToHTMLTagMap [optional] use this property/attribute to override the lynx tag -> html tag map
20
- * @param {string} nativeModulesUrl [optional] It is a esm url, use to customize NativeModules.
21
- * @param {INativeModulesCall} onNativeModulesCall [optional] the NativeModules value handler. Arguments will be cached before this property is assigned.
15
+ * @param {NativeModulesMap} nativeModulesMap [optional] use to customize NativeModules. key is module-name, value is esm url.
16
+ * @param {NativeModulesCall} onNativeModulesCall [optional] the NativeModules value handler. Arguments will be cached before this property is assigned.
22
17
  * @param {"auto" | null} height [optional] set it to "auto" for height auto-sizing
23
18
  * @param {"auto" | null} width [optional] set it to "auto" for width auto-sizing
24
- *
25
- * @property entryId the currently Lynx view entryId.
19
+ * @param {NapiModulesMap} napiModulesMap [optional] the napiModule which is called in lynx-core. key is module-name, value is esm url.
20
+ * @param {NapiModulesCall} onNapiModulesCall [optional] the NapiModule value handler.
21
+ * @param {"false" | "true" | null} injectHeadLinks [optional] @default true set it to "false" to disable injecting the <link href="" ref="stylesheet"> styles into shadowroot
26
22
  *
27
23
  * @event error lynx card fired an error
28
24
  *
@@ -50,7 +46,7 @@ export class LynxView extends HTMLElement {
50
46
  'globalProps',
51
47
  'initData',
52
48
  'overrideLynxTagToHTMLTagMap',
53
- 'nativeModulesUrl',
49
+ 'nativeModulesMap',
54
50
  ];
55
51
  static attributeCamelCaseMap = Object.fromEntries(this.observedAttributeAsProperties.map((nm) => [nm.toLocaleLowerCase(), nm]));
56
52
  /**
@@ -104,16 +100,6 @@ export class LynxView extends HTMLElement {
104
100
  this.#initData = val;
105
101
  }
106
102
  }
107
- #entryId;
108
- /**
109
- * @public
110
- * @readonly
111
- * @property
112
- * The random generated entryId of current lynxview
113
- */
114
- get entryId() {
115
- return this.#entryId;
116
- }
117
103
  #overrideLynxTagToHTMLTagMap = { 'page': 'div' };
118
104
  /**
119
105
  * @public
@@ -148,16 +134,40 @@ export class LynxView extends HTMLElement {
148
134
  }
149
135
  }
150
136
  }
151
- #nativeModulesUrl;
137
+ #nativeModulesMap = {};
152
138
  /**
153
139
  * @public
154
- * @property nativeModules
140
+ * @property nativeModulesMap
141
+ * @default {}
142
+ */
143
+ get nativeModulesMap() {
144
+ return this.#nativeModulesMap;
145
+ }
146
+ set nativeModulesMap(map) {
147
+ this.#nativeModulesMap = map;
148
+ }
149
+ #napiModulesMap = {};
150
+ /**
151
+ * @param
152
+ * @property napiModulesMap
153
+ * @default {}
155
154
  */
156
- get nativeModulesUrl() {
157
- return this.#nativeModulesUrl;
155
+ get napiModulesMap() {
156
+ return this.#napiModulesMap;
158
157
  }
159
- set nativeModulesUrl(val) {
160
- this.#nativeModulesUrl = val;
158
+ set napiModulesMap(map) {
159
+ this.#napiModulesMap = map;
160
+ }
161
+ #onNapiModulesCall;
162
+ /**
163
+ * @param
164
+ * @property
165
+ */
166
+ get onNapiModulesCall() {
167
+ return this.#onNapiModulesCall;
168
+ }
169
+ set onNapiModulesCall(handler) {
170
+ this.#onNapiModulesCall = handler;
161
171
  }
162
172
  #autoHeight = false;
163
173
  #autoWidth = false;
@@ -281,12 +291,15 @@ export class LynxView extends HTMLElement {
281
291
  * @private
282
292
  */
283
293
  disconnectedCallback() {
294
+ this.cleanupResizeObserver();
284
295
  if (this.#instance) {
285
- this.#instance.resizeObserver?.disconnect();
286
296
  this.#instance.lynxView.dispose();
287
297
  this.#instance.rootDom.remove();
288
298
  }
289
299
  this.#instance = undefined;
300
+ if (this.shadowRoot) {
301
+ this.shadowRoot.innerHTML = '';
302
+ }
290
303
  }
291
304
  /**
292
305
  * @private the flag to group all changes into one render operation
@@ -306,24 +319,25 @@ export class LynxView extends HTMLElement {
306
319
  if (this.#url) {
307
320
  const rootDom = document.createElement('div');
308
321
  rootDom.id = lynxViewRootDomId;
309
- const entryId = `${lynxViewEntryIdPrefix}-${LynxView
310
- .lynxViewCount++}`;
311
- this.#entryId = entryId;
312
- rootDom.setAttribute(cardIdAttribute, entryId);
313
322
  rootDom.setAttribute('part', lynxViewRootDomId);
314
- const commonEventDetail = {
315
- entryId,
323
+ const tagMap = {
324
+ 'page': 'div',
325
+ 'view': 'x-view',
326
+ 'text': 'x-text',
327
+ 'image': 'x-image',
328
+ 'list': 'x-list',
329
+ 'svg': 'x-svg',
330
+ ...this.overrideLynxTagToHTMLTagMap,
316
331
  };
317
332
  const lynxView = createLynxView({
318
- entryId,
333
+ tagMap,
319
334
  rootDom,
320
335
  templateUrl: this.#url,
321
336
  globalProps: this.#globalProps,
322
337
  initData: this.#initData,
323
- overrideLynxTagToHTMLTagMap: this.#overrideLynxTagToHTMLTagMap,
324
- nativeModulesUrl: this.#nativeModulesUrl,
338
+ nativeModulesMap: this.#nativeModulesMap,
339
+ napiModulesMap: this.#napiModulesMap,
325
340
  callbacks: {
326
- loadNewTag: loadElement,
327
341
  nativeModulesCall: (...args) => {
328
342
  if (this.#onNativeModulesCall) {
329
343
  return this.#onNativeModulesCall(...args);
@@ -335,10 +349,11 @@ export class LynxView extends HTMLElement {
335
349
  this.#cachedNativeModulesCall = [args];
336
350
  }
337
351
  },
352
+ napiModulesCall: (...args) => {
353
+ return this.#onNapiModulesCall?.(...args);
354
+ },
338
355
  onError: () => {
339
- this.dispatchEvent(new CustomEvent('error', {
340
- detail: commonEventDetail,
341
- }));
356
+ this.dispatchEvent(new CustomEvent('error', {}));
342
357
  },
343
358
  },
344
359
  });
@@ -347,7 +362,21 @@ export class LynxView extends HTMLElement {
347
362
  rootDom,
348
363
  };
349
364
  this.#handleAutoSize();
350
- this.append(rootDom);
365
+ if (!this.shadowRoot) {
366
+ this.attachShadow({ mode: 'open' });
367
+ }
368
+ const styleElement = document.createElement('style');
369
+ this.shadowRoot.append(styleElement);
370
+ const styleSheet = styleElement.sheet;
371
+ styleSheet.insertRule(inShadowRootStyles);
372
+ const injectHeadLinks = this.getAttribute('inject-head-links') !== 'false';
373
+ if (injectHeadLinks) {
374
+ document.head.querySelectorAll('link[rel="stylesheet"]').forEach((linkElement) => {
375
+ const href = linkElement.href;
376
+ styleSheet.insertRule(`@import url("${href}");`);
377
+ });
378
+ }
379
+ this.shadowRoot.append(rootDom);
351
380
  }
352
381
  });
353
382
  }
@@ -358,6 +387,12 @@ export class LynxView extends HTMLElement {
358
387
  connectedCallback() {
359
388
  this.#render();
360
389
  }
390
+ cleanupResizeObserver() {
391
+ if (this.#instance?.resizeObserver) {
392
+ this.#instance.resizeObserver.disconnect();
393
+ this.#instance.resizeObserver = undefined;
394
+ }
395
+ }
361
396
  }
362
397
  if (customElements.get(LynxView.tag)) {
363
398
  console.warn(`[${LynxView.tag}] has already been defined`);
@@ -1,18 +1,19 @@
1
- import type { Cloneable, UpdateDataType } from '@lynx-js/web-constants';
1
+ import type { Cloneable, NapiModulesMap, NativeModulesMap, sendGlobalEventEndpoint, UpdateDataType } from '@lynx-js/web-constants';
2
2
  import { startUIThread } from '../uiThread/startUIThread.js';
3
+ import type { RpcCallType } from '@lynx-js/web-worker-rpc';
3
4
  export interface LynxViewConfigs {
4
5
  templateUrl: string;
5
6
  initData: Cloneable;
6
7
  globalProps: Cloneable;
7
- entryId: string;
8
8
  rootDom: HTMLElement;
9
9
  callbacks: Parameters<typeof startUIThread>[3];
10
- overrideLynxTagToHTMLTagMap?: Record<string, string>;
11
- nativeModulesUrl: string | undefined;
10
+ nativeModulesMap: NativeModulesMap;
11
+ napiModulesMap: NapiModulesMap;
12
+ tagMap: Record<string, string>;
12
13
  }
13
14
  export interface LynxView {
14
15
  updateData(data: Cloneable, updateDataType: UpdateDataType, callback?: () => void): void;
15
16
  dispose(): Promise<void>;
16
- sendGlobalEvent(name: string, params?: Cloneable[]): void;
17
+ sendGlobalEvent: RpcCallType<typeof sendGlobalEventEndpoint>;
17
18
  }
18
19
  export declare function createLynxView(configs: LynxViewConfigs): LynxView;
@@ -2,16 +2,15 @@
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
4
  import { startUIThread } from '../uiThread/startUIThread.js';
5
- import { supportAtScope } from '../utils/browser.js';
6
5
  export function createLynxView(configs) {
7
- const { rootDom, callbacks, templateUrl, globalProps, entryId, initData, overrideLynxTagToHTMLTagMap, nativeModulesUrl, } = configs;
6
+ const { rootDom, callbacks, templateUrl, globalProps, initData, nativeModulesMap, napiModulesMap, tagMap, } = configs;
8
7
  return startUIThread(templateUrl, {
8
+ tagMap,
9
9
  initData,
10
10
  globalProps,
11
- entryId,
12
- browserConfig: {
13
- supportAtScope,
14
- },
15
- }, rootDom, callbacks, overrideLynxTagToHTMLTagMap, nativeModulesUrl);
11
+ nativeModulesMap,
12
+ napiModulesMap,
13
+ browserConfig: {},
14
+ }, rootDom, callbacks);
16
15
  }
17
16
  //# sourceMappingURL=createLynxView.js.map
@@ -0,0 +1 @@
1
+ export declare const inShadowRootStyles = "\n[lynx-default-display-linear=\"false\"] * {\n --lynx-display: flex;\n --lynx-display-toggle: var(--lynx-display-flex);\n}\n";
@@ -0,0 +1,7 @@
1
+ export const inShadowRootStyles = `
2
+ [lynx-default-display-linear="false"] * {
3
+ --lynx-display: flex;
4
+ --lynx-display-toggle: var(--lynx-display-flex);
5
+ }
6
+ `;
7
+ //# sourceMappingURL=inShadowRootStyles.js.map
@@ -27,6 +27,7 @@ function createMainWorker() {
27
27
  mode: 'main',
28
28
  toUIThread: channelToMainThread.port2,
29
29
  toPeerThread: channelMainThreadWithBackground.port1,
30
+ pixelRatio: window.devicePixelRatio,
30
31
  };
31
32
  mainThreadWorker.postMessage(mainThreadMessage, [
32
33
  channelToMainThread.port2,
@@ -49,6 +50,7 @@ function createBackgroundWorker(channelMainThreadWithBackground) {
49
50
  mode: 'background',
50
51
  toUIThread: channelToBackground.port2,
51
52
  toPeerThread: channelMainThreadWithBackground.port2,
53
+ pixelRatio: window.devicePixelRatio,
52
54
  };
53
55
  backgroundThreadWorker.postMessage(backgroundThreadMessage, [
54
56
  channelToBackground.port2,
@@ -35,6 +35,7 @@ export function bootTimingSystem(mainThreadRpc, backgroundThreadRpc, rootDom) {
35
35
  detail: isFp ? setupTiming : timingInfo,
36
36
  bubbles: true,
37
37
  cancelable: true,
38
+ composed: true,
38
39
  }));
39
40
  if (pipelineId) {
40
41
  pipelineIdToTiming.delete(pipelineId);
@@ -3,11 +3,8 @@ import type { Rpc } from '@lynx-js/web-worker-rpc';
3
3
  import type { RuntimePropertyOnElement } from '../../types/RuntimePropertyOnElement.js';
4
4
  export declare function registerFlushElementTreeHandler(mainThreadRpc: Rpc, endpoint: typeof flushElementTreeEndpoint, options: {
5
5
  pageConfig: PageConfig;
6
- overrideTagMap: Record<string, string>;
7
6
  backgroundRpc: Rpc;
8
7
  rootDom: HTMLElement;
9
- entryId: string;
10
- currentLoadingTags: Promise<void>[];
11
8
  }, onCommit: (info: {
12
9
  pipelineId: string | undefined;
13
10
  timingFlags: string[];
@@ -1,33 +1,24 @@
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 { cardIdAttribute, componentIdAttribute, lynxDefaultDisplayLinearAttribute, lynxRuntimeValue, lynxTagAttribute, lynxUniqueIdAttribute, parentComponentUniqueIdAttribute, postMainThreadEvent, publicComponentEventEndpoint, publishEventEndpoint, } from '@lynx-js/web-constants';
4
+ import { componentIdAttribute, lynxDefaultDisplayLinearAttribute, lynxRuntimeValue, lynxTagAttribute, lynxUniqueIdAttribute, parentComponentUniqueIdAttribute, postMainThreadEvent, publicComponentEventEndpoint, publishEventEndpoint, } from '@lynx-js/web-constants';
5
5
  import { decodeElementOperation } from '../decodeElementOperation.js';
6
- import { getElementTag } from '../getElementTag.js';
7
6
  import { createCrossThreadEvent } from '../../utils/createCrossThreadEvent.js';
8
- import { isWebkit, supportAtScope } from '../../utils/browser.js';
9
- function applyPageAttributes(page, pageConfig, entryId) {
10
- page.setAttribute(cardIdAttribute, entryId);
7
+ function applyPageAttributes(page, pageConfig) {
11
8
  if (pageConfig.defaultDisplayLinear === false) {
12
9
  page.setAttribute(lynxDefaultDisplayLinearAttribute, 'false');
13
10
  }
14
11
  }
15
12
  export function registerFlushElementTreeHandler(mainThreadRpc, endpoint, options, onCommit, markTimingInternal) {
16
- const { pageConfig, overrideTagMap, backgroundRpc, rootDom, entryId, currentLoadingTags, } = options;
13
+ const { pageConfig, backgroundRpc, rootDom, } = options;
17
14
  const uniqueIdToElement = [];
18
15
  const uniqueIdToCssInJsRule = [];
19
16
  const rootStyleElementForCssInJs = document.createElement('style');
20
17
  if (!pageConfig.enableCSSSelector) {
21
- rootStyleElementForCssInJs.innerHTML = `/* enableCSSSelector: false */ ${supportAtScope && !isWebkit ? '@scope { :scope{} }' : ''}`;
22
- // safari testing needs this :scope{} see: https://github.com/microsoft/playwright/issues/33647
23
- // for 18.2 the :scope{} placeholder dose not work neither. we fired an issue for this https://bugs.webkit.org/show_bug.cgi?id=285130
24
18
  rootDom.append(rootStyleElementForCssInJs);
25
19
  }
26
- // dom must connected to get the sheet property
27
- const rootScopeRule = rootStyleElementForCssInJs?.sheet?.cssRules[0];
28
20
  const createElementImpl = (tag) => {
29
- const htmlTag = getElementTag(tag, overrideTagMap);
30
- const element = document.createElement(htmlTag);
21
+ const element = document.createElement(tag);
31
22
  element[lynxRuntimeValue] = {
32
23
  dataset: {},
33
24
  eventHandler: {},
@@ -36,14 +27,8 @@ export function registerFlushElementTreeHandler(mainThreadRpc, endpoint, options
36
27
  };
37
28
  const createStyleRuleImpl = (uniqueId, initialStyle) => {
38
29
  const commonStyleSheetText = `[${lynxUniqueIdAttribute}="${uniqueId.toString()}"]{${initialStyle}}`;
39
- if (rootScopeRule) {
40
- const idx = rootScopeRule.insertRule(commonStyleSheetText);
41
- return rootScopeRule.cssRules[idx];
42
- }
43
- else {
44
- const idx = rootStyleElementForCssInJs.sheet.insertRule(`[${cardIdAttribute}="${entryId}"] ${commonStyleSheetText}`);
45
- return rootStyleElementForCssInJs.sheet.cssRules[idx];
46
- }
30
+ const idx = rootStyleElementForCssInJs.sheet.insertRule(commonStyleSheetText);
31
+ return rootStyleElementForCssInJs.sheet.cssRules[idx];
47
32
  };
48
33
  const mtsHandler = (event) => {
49
34
  const crossThreadEvent = createCrossThreadEvent(event);
@@ -73,42 +58,38 @@ export function registerFlushElementTreeHandler(mainThreadRpc, endpoint, options
73
58
  ]);
74
59
  }
75
60
  };
76
- mainThreadRpc.registerHandler(endpoint, (operations, options, cardCss) => {
61
+ mainThreadRpc.registerHandler(endpoint, (operations, options, cardCss, timingFlags) => {
77
62
  const { pipelineOptions } = options;
78
63
  const pipelineId = pipelineOptions?.pipelineID;
79
- const timingFlags = [];
80
64
  markTimingInternal('dispatch_start', pipelineId);
81
- Promise.all(currentLoadingTags).then(() => {
82
- markTimingInternal('layout_start', pipelineId);
83
- markTimingInternal('ui_operation_flush_start', pipelineId);
84
- const page = decodeElementOperation(operations, {
85
- timingFlags,
86
- uniqueIdToElement,
87
- uniqueIdToCssInJsRule,
88
- createElementImpl,
89
- createStyleRuleImpl,
90
- eventHandler: {
91
- mtsHandler,
92
- btsHandler,
93
- },
94
- });
95
- markTimingInternal('ui_operation_flush_end', pipelineId);
96
- const isFP = !!page;
97
- if (isFP) {
98
- // on FP
99
- const styleElement = document.createElement('style');
100
- styleElement.innerHTML = cardCss;
101
- rootDom.append(styleElement);
102
- rootDom.append(page);
103
- applyPageAttributes(page, pageConfig, entryId);
104
- }
105
- markTimingInternal('layout_end', pipelineId);
106
- markTimingInternal('dispatch_end', pipelineId);
107
- onCommit({
108
- pipelineId,
109
- timingFlags,
110
- isFP,
111
- });
65
+ markTimingInternal('layout_start', pipelineId);
66
+ markTimingInternal('ui_operation_flush_start', pipelineId);
67
+ const page = decodeElementOperation(operations, {
68
+ uniqueIdToElement,
69
+ uniqueIdToCssInJsRule,
70
+ createElementImpl,
71
+ createStyleRuleImpl,
72
+ eventHandler: {
73
+ mtsHandler,
74
+ btsHandler,
75
+ },
76
+ });
77
+ markTimingInternal('ui_operation_flush_end', pipelineId);
78
+ const isFP = !!page;
79
+ if (isFP) {
80
+ // on FP
81
+ const styleElement = document.createElement('style');
82
+ styleElement.innerHTML = cardCss;
83
+ rootDom.append(styleElement);
84
+ rootDom.append(page);
85
+ applyPageAttributes(page, pageConfig);
86
+ }
87
+ markTimingInternal('layout_end', pipelineId);
88
+ markTimingInternal('dispatch_end', pipelineId);
89
+ onCommit({
90
+ pipelineId,
91
+ timingFlags,
92
+ isFP,
112
93
  });
113
94
  });
114
95
  return { uniqueIdToElement, uniqueIdToCssInJsRule };
@@ -0,0 +1,3 @@
1
+ import type { Rpc } from '@lynx-js/web-worker-rpc';
2
+ import { type NapiModulesCall } from '@lynx-js/web-constants';
3
+ export declare function registerNapiModulesCallHandler(rpc: Rpc, napiModulesCall: NapiModulesCall): void;
@@ -0,0 +1,5 @@
1
+ import { napiModulesCallEndpoint, } from '@lynx-js/web-constants';
2
+ export function registerNapiModulesCallHandler(rpc, napiModulesCall) {
3
+ rpc.registerHandler(napiModulesCallEndpoint, napiModulesCall);
4
+ }
5
+ //# sourceMappingURL=registerNapiModulesCallHandler.js.map
@@ -1,7 +1,6 @@
1
1
  import type { ElementOperation } from '@lynx-js/web-constants';
2
2
  import type { RuntimePropertyOnElement } from '../types/RuntimePropertyOnElement.js';
3
3
  export declare function decodeElementOperation<T extends HTMLElement & RuntimePropertyOnElement>(operations: ElementOperation[], options: {
4
- timingFlags: string[];
5
4
  uniqueIdToElement: (WeakRef<T> | undefined)[];
6
5
  uniqueIdToCssInJsRule: (WeakRef<CSSStyleRule> | undefined)[];
7
6
  createElementImpl: (tag: string) => T;
@@ -1,7 +1,7 @@
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 { cssIdAttribute, lynxTagAttribute, lynxUniqueIdAttribute, OperationType, lynxRuntimeValue, LynxEventNameToW3cByTagName, LynxEventNameToW3cCommon, W3cEventNameToLynx, __lynx_timing_flag, } from '@lynx-js/web-constants';
4
+ import { cssIdAttribute, lynxUniqueIdAttribute, OperationType, lynxRuntimeValue, LynxEventNameToW3cByTagName, LynxEventNameToW3cCommon, W3cEventNameToLynx, __lynx_timing_flag, lynxTagAttribute, } from '@lynx-js/web-constants';
5
5
  function getElement(uniqueId, uniqueIdToElement) {
6
6
  const element = uniqueIdToElement[uniqueId]?.deref();
7
7
  if (element) {
@@ -18,7 +18,6 @@ function createElement(tag, uniqueId, uniqueIdToElement, createElementImpl) {
18
18
  }
19
19
  const element = createElementImpl(tag);
20
20
  element.setAttribute(lynxUniqueIdAttribute, uniqueId.toString());
21
- element.setAttribute(lynxTagAttribute, tag);
22
21
  uniqueIdToElement[uniqueId] = new WeakRef(element);
23
22
  return element;
24
23
  }
@@ -39,7 +38,7 @@ function handleHtmlEvent(event) {
39
38
  }
40
39
  }
41
40
  export function decodeElementOperation(operations, options) {
42
- const { uniqueIdToElement, uniqueIdToCssInJsRule, createElementImpl, createStyleRuleImpl, eventHandler, timingFlags, } = options;
41
+ const { uniqueIdToElement, uniqueIdToCssInJsRule, createElementImpl, createStyleRuleImpl, eventHandler, } = options;
43
42
  let pageElement;
44
43
  for (const op of operations) {
45
44
  if (op.type === OperationType.Create) {
@@ -47,8 +46,6 @@ export function decodeElementOperation(operations, options) {
47
46
  if (typeof op.cssId === 'number') {
48
47
  element.setAttribute(cssIdAttribute, op.cssId.toString());
49
48
  }
50
- if (op.tag === 'page')
51
- pageElement = element;
52
49
  }
53
50
  else {
54
51
  const target = getElement(op.uid, uniqueIdToElement);
@@ -87,8 +84,8 @@ export function decodeElementOperation(operations, options) {
87
84
  }
88
85
  else {
89
86
  target.setAttribute(op.key, op.value);
90
- if (op.value && op.key === __lynx_timing_flag) {
91
- timingFlags.push(op.value);
87
+ if (op.key === lynxTagAttribute && op.value === 'page') {
88
+ pageElement = target;
92
89
  }
93
90
  }
94
91
  }
@@ -141,11 +138,9 @@ export function decodeElementOperation(operations, options) {
141
138
  const isCaptureEvent = op.eventType === 'capture-bind'
142
139
  || op.eventType === 'capture-catch';
143
140
  if (op.hname === undefined) {
144
- target.removeAttribute(`x-enable-${lynxEventName}-event`);
145
141
  target[lynxRuntimeValue].eventHandler[lynxEventName] = undefined;
146
142
  }
147
143
  else {
148
- target.setAttribute(`x-enable-${lynxEventName}-event`, '');
149
144
  target.addEventListener(htmlEventName, handleHtmlEvent, {
150
145
  passive: true,
151
146
  capture: isCaptureEvent,
@@ -1,7 +1,7 @@
1
1
  import type { LynxView } from '../apis/createLynxView.js';
2
- import { type MainThreadStartConfigs, type NativeModulesCall } from '@lynx-js/web-constants';
2
+ import { type MainThreadStartConfigs, type NapiModulesCall, type NativeModulesCall } from '@lynx-js/web-constants';
3
3
  export declare function startUIThread(templateUrl: string, configs: Omit<MainThreadStartConfigs, 'template'>, rootDom: HTMLElement, callbacks: {
4
- loadNewTag?: (tag: string) => void;
5
4
  nativeModulesCall: NativeModulesCall;
5
+ napiModulesCall: NapiModulesCall;
6
6
  onError?: () => void;
7
- }, overrideTagMap: Record<string, string> | undefined, nativeModulesUrl: string | undefined): LynxView;
7
+ }): LynxView;
@@ -1,7 +1,6 @@
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 { registerLoadNewTagHandler } from './crossThreadHandlers/registerLoadNewTagHandler.js';
5
4
  import { createExposureService } from './crossThreadHandlers/createExposureService.js';
6
5
  import { registerInvokeUIMethodHandler } from './crossThreadHandlers/registerInvokeUIMethodHandler.js';
7
6
  import { registerNativePropsHandler } from './crossThreadHandlers/registerSetNativePropsHandler.js';
@@ -13,13 +12,13 @@ import { createDispose } from './crossThreadHandlers/createDispose.js';
13
12
  import { bootTimingSystem } from './crossThreadHandlers/bootTimingSystem.js';
14
13
  import { registerTriggerComponentEventHandler } from './crossThreadHandlers/registerTriggerComponentEventHandler.js';
15
14
  import { registerSelectComponentHandler } from './crossThreadHandlers/registerSelectComponentHandler.js';
16
- import { flushElementTreeEndpoint, loadNewTagEndpoint, mainThreadChunkReadyEndpoint, mainThreadStartEndpoint, sendGlobalEventEndpoint, uiThreadFpReadyEndpoint, } from '@lynx-js/web-constants';
15
+ import { flushElementTreeEndpoint, mainThreadChunkReadyEndpoint, mainThreadStartEndpoint, sendGlobalEventEndpoint, uiThreadFpReadyEndpoint, } from '@lynx-js/web-constants';
17
16
  import { loadTemplate } from '../utils/loadTemplate.js';
18
17
  import { createUpdateData } from './crossThreadHandlers/createUpdateData.js';
19
- export function startUIThread(templateUrl, configs, rootDom, callbacks, overrideTagMap = {}, nativeModulesUrl) {
18
+ import { registerNapiModulesCallHandler } from './crossThreadHandlers/registerNapiModulesCallHandler.js';
19
+ export function startUIThread(templateUrl, configs, rootDom, callbacks) {
20
20
  const createLynxStartTiming = performance.now() + performance.timeOrigin;
21
- const { entryId } = configs;
22
- const currentLoadingTags = [];
21
+ const { nativeModulesMap, napiModulesMap } = configs;
23
22
  const { mainThreadRpc, backgroundRpc, terminateWorkers, } = bootWorkers();
24
23
  const sendGlobalEvent = backgroundRpc.createCall(sendGlobalEventEndpoint);
25
24
  const uiThreadFpReady = backgroundRpc.createCall(uiThreadFpReadyEndpoint);
@@ -32,29 +31,17 @@ export function startUIThread(templateUrl, configs, rootDom, callbacks, override
32
31
  mainThreadStart({
33
32
  ...configs,
34
33
  template,
35
- nativeModulesUrl,
34
+ nativeModulesMap,
35
+ napiModulesMap,
36
36
  });
37
37
  });
38
- registerLoadNewTagHandler(mainThreadRpc, loadNewTagEndpoint, (tag) => {
39
- if (callbacks.loadNewTag) {
40
- callbacks.loadNewTag(tag);
41
- }
42
- else {
43
- if (!customElements.get(tag) && tag.includes('-')) {
44
- throw new Error(`[lynx-web] cannot find custom element ${tag}`);
45
- }
46
- }
47
- }, overrideTagMap, currentLoadingTags);
48
38
  registerReportErrorHandler(mainThreadRpc, callbacks.onError);
49
39
  mainThreadRpc.registerHandler(mainThreadChunkReadyEndpoint, (mainChunkInfo) => {
50
40
  const { pageConfig } = mainChunkInfo;
51
41
  registerFlushElementTreeHandler(mainThreadRpc, flushElementTreeEndpoint, {
52
42
  pageConfig,
53
- overrideTagMap,
54
43
  backgroundRpc,
55
44
  rootDom,
56
- entryId,
57
- currentLoadingTags,
58
45
  }, (info) => {
59
46
  const { pipelineId, timingFlags, isFP } = info;
60
47
  if (isFP) {
@@ -69,6 +56,7 @@ export function startUIThread(templateUrl, configs, rootDom, callbacks, override
69
56
  }, markTimingInternal);
70
57
  });
71
58
  registerNativeModulesCallHandler(backgroundRpc, callbacks.nativeModulesCall);
59
+ registerNapiModulesCallHandler(backgroundRpc, callbacks.napiModulesCall);
72
60
  return {
73
61
  updateData: createUpdateData(mainThreadRpc, backgroundRpc),
74
62
  dispose: createDispose(backgroundRpc, terminateWorkers),
@@ -1,3 +1,2 @@
1
1
  export declare const isChromium: boolean;
2
2
  export declare const isWebkit: boolean;
3
- export declare const supportAtScope = true;
@@ -5,5 +5,4 @@ export const isWebkit = /\b(iPad|iPhone|iPod|OS X)\b/.test(UA)
5
5
  && /WebKit/.test(UA)
6
6
  // @ts-expect-error
7
7
  && !window.MSStream;
8
- export const supportAtScope = !!globalThis.CSSScopeRule;
9
8
  //# sourceMappingURL=browser.js.map
@@ -29,6 +29,7 @@ function generateJavascriptUrl(obj, injectVars, injectWithBind, muteableVars) {
29
29
  const mainThreadInjectVars = [
30
30
  'lynx',
31
31
  'globalThis',
32
+ '_ReportError',
32
33
  '__AddConfig',
33
34
  '__AddDataset',
34
35
  '__GetAttributes',
package/index.css CHANGED
@@ -3,17 +3,13 @@
3
3
  // Licensed under the Apache License Version 2.0 that can be found in the
4
4
  // LICENSE file in the root directory of this source tree.
5
5
  */
6
- [lynx-default-display-linear="false"] * {
7
- --lynx-display: flex;
8
- --lynx-display-toggle: var(--lynx-display-flex);
9
- }
10
6
 
11
7
  lynx-view {
12
8
  contain: strict;
13
9
  display: flex;
14
10
  }
15
11
 
16
- lynx-view > #lynx-view-root {
12
+ lynx-view::part(lynx-view-root) {
17
13
  display: contents;
18
14
  width: 100%;
19
15
  height: 100%;
@@ -24,7 +20,7 @@ lynx-view[height="auto"] {
24
20
  height: var(--lynx-view-height);
25
21
  block-size: var(--lynx-view-height);
26
22
  }
27
- lynx-view[height="auto"] > #lynx-view-root {
23
+ lynx-view[height="auto"]::part(lynx-view-root) {
28
24
  height: unset;
29
25
  }
30
26
 
@@ -33,15 +29,15 @@ lynx-view[width="auto"] {
33
29
  width: var(--lynx-view-width);
34
30
  inline-size: var(--lynx-view-width);
35
31
  }
36
- lynx-view[width="auto"] > #lynx-view-root {
32
+ lynx-view[width="auto"]::part(lynx-view-root) {
37
33
  width: unset;
38
34
  }
39
35
 
40
36
  lynx-view[height="auto"], lynx-view[width="auto"] {
41
37
  contain-intrinsic-size: var(--lynx-view-width) var(--lynx-view-height);
42
38
  }
43
- lynx-view[height="auto"] > #lynx-view-root,
44
- lynx-view[width="auto"] > #lynx-view-root {
39
+ lynx-view[height="auto"]::part(lynx-view-root),
40
+ lynx-view[width="auto"]::part(lynx-view-root) {
45
41
  display: unset;
46
42
  position: fixed;
47
43
  top: 0;
@@ -60,7 +56,7 @@ lynx-view[width="auto"] > #lynx-view-root {
60
56
  initial-value: 100%;
61
57
  }
62
58
 
63
- lynx-view:not([width="auto"]):not([height="auto"]) [lynx-tag="page"] {
59
+ lynx-view:not([width="auto"]):not([height="auto"])::part(page) {
64
60
  height: 100%;
65
61
  width: 100%;
66
62
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/web-core",
3
- "version": "0.7.1",
3
+ "version": "0.9.0",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "keywords": [],
@@ -24,16 +24,16 @@
24
24
  "**/*.css"
25
25
  ],
26
26
  "dependencies": {
27
- "@lynx-js/web-constants": "0.7.1",
28
- "@lynx-js/web-worker-rpc": "0.7.1",
29
- "@lynx-js/web-worker-runtime": "0.7.1"
27
+ "@lynx-js/web-constants": "0.9.0",
28
+ "@lynx-js/web-worker-rpc": "0.9.0",
29
+ "@lynx-js/web-worker-runtime": "0.9.0"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@lynx-js/lynx-core": "0.1.0",
33
- "@lynx-js/web-elements": "0.3.0"
33
+ "@lynx-js/web-elements": "0.5.0"
34
34
  },
35
35
  "peerDependencies": {
36
36
  "@lynx-js/lynx-core": "0.1.0",
37
- "@lynx-js/web-elements": ">=0.1.0"
37
+ "@lynx-js/web-elements": ">=0.3.1"
38
38
  }
39
39
  }
@@ -1,3 +0,0 @@
1
- import type { Rpc } from '@lynx-js/web-worker-rpc';
2
- import type { loadNewTagEndpoint } from '@lynx-js/web-constants';
3
- export declare function registerLoadNewTagHandler(rpc: Rpc, endpoint: typeof loadNewTagEndpoint, loadTag: (tag: string) => void, tagMap: Record<string, string>, currentLoadingTags: Promise<any>[]): void;
@@ -1,7 +0,0 @@
1
- import { getElementTag } from '../getElementTag.js';
2
- export function registerLoadNewTagHandler(rpc, endpoint, loadTag, tagMap, currentLoadingTags) {
3
- rpc.registerHandler(endpoint, (tag) => {
4
- loadTag(getElementTag(tag, tagMap, currentLoadingTags));
5
- });
6
- }
7
- //# sourceMappingURL=registerLoadNewTagHandler.js.map
@@ -1 +0,0 @@
1
- export declare function getElementTag(tag: string, tagMap: Record<string, string>, currentLoadingTags?: Promise<any>[]): string;
@@ -1,20 +0,0 @@
1
- // Copyright 2023 The Lynx Authors. All rights reserved.
2
- // Licensed under the Apache License Version 2.0 that can be found in the
3
- // LICENSE file in the root directory of this source tree.
4
- export function getElementTag(tag, tagMap, currentLoadingTags) {
5
- if (tagMap[tag]) {
6
- return tagMap[tag];
7
- }
8
- if (customElements.get(tag)) {
9
- tagMap[tag] = tag;
10
- return tag;
11
- }
12
- const normizedTag = tag.includes('-') ? tag : `x-${tag}`;
13
- if (customElements.get(normizedTag)) {
14
- tagMap[tag] = normizedTag;
15
- return normizedTag;
16
- }
17
- currentLoadingTags?.push(customElements.whenDefined(normizedTag));
18
- return normizedTag;
19
- }
20
- //# sourceMappingURL=getElementTag.js.map