@lynx-js/web-elements-canary 0.8.5-canary-20250905-877d1535 → 0.8.6-canary-20250911-1d97fce6

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,13 +1,33 @@
1
1
  # @lynx-js/web-elements
2
2
 
3
- ## 0.8.5-canary-20250905120148-877d15356c059640bfb350eea2675af63376c8e4
3
+ ## 0.8.6-canary-20250911061409-1d97fce68178418f6af8d50e54ab24a5567452b7
4
+
5
+ ### Patch Changes
6
+
7
+ - fix: 1. svg use image tag to render, to differentiate background-image styles ([#1668](https://github.com/lynx-family/lynx-stack/pull/1668))
8
+
9
+ 1. use blob instead of raw data-uri
10
+
11
+ > Not using data-uri(data:image/svg+xml;utf8,${props.content})
12
+ > since it has follow limitations:
13
+ >
14
+ > < and > must be encoded to %3C and %3E.
15
+ > Double quotes must be converted to single quotes.
16
+ > Colors must use a non-hex format because # will not work inside data-uri.
17
+ > See: https://codepen.io/zvuc/pen/BWNLJL
18
+ > Instead, we use modern Blob API to create SVG URL that have the same support
19
+
20
+ - Updated dependencies [[`1d97fce`](https://github.com/lynx-family/lynx-stack/commit/1d97fce68178418f6af8d50e54ab24a5567452b7)]:
21
+ - @lynx-js/web-elements-template@0.8.6-canary-20250911061409-1d97fce68178418f6af8d50e54ab24a5567452b7
22
+
23
+ ## 0.8.5
4
24
 
5
25
  ### Patch Changes
6
26
 
7
27
  - fix: register attr of width is set to height incorrectly ([#1649](https://github.com/lynx-family/lynx-stack/pull/1649))
8
28
 
9
29
  - Updated dependencies []:
10
- - @lynx-js/web-elements-template@0.8.5-canary-20250905120148-877d15356c059640bfb350eea2675af63376c8e4
30
+ - @lynx-js/web-elements-template@0.8.5
11
31
 
12
32
  ## 0.8.4
13
33
 
package/dist/XSvg/XSvg.js CHANGED
@@ -1,63 +1,84 @@
1
- import { __esDecorate, __runInitializers } from "tslib";
1
+ import { __esDecorate, __runInitializers, __setFunctionName } from "tslib";
2
2
  /*
3
3
  // Copyright 2024 The Lynx Authors. All rights reserved.
4
4
  // Licensed under the Apache License Version 2.0 that can be found in the
5
5
  // LICENSE file in the root directory of this source tree.
6
6
  */
7
- import { Component, bindToStyle, registerAttributeHandler, } from '@lynx-js/web-elements-reactive';
7
+ import { Component, bindToStyle, genDomGetter, registerAttributeHandler, registerEventEnableStatusChangeHandler, } from '@lynx-js/web-elements-reactive';
8
8
  import { CommonEventsAndMethods } from '../common/CommonEventsAndMethods.js';
9
9
  import { commonComponentEventSetting } from '../common/commonEventInitConfiguration.js';
10
+ import { templateXSvg } from '@lynx-js/web-elements-template';
10
11
  let XSvgFeatures = (() => {
12
+ let _instanceExtraInitializers = [];
11
13
  let _private_handleSrc_decorators;
12
- let _private_handleSrc_initializers = [];
13
- let _private_handleSrc_extraInitializers = [];
14
+ let _private_handleSrc_descriptor;
14
15
  let _private_handleContent_decorators;
15
- let _private_handleContent_initializers = [];
16
- let _private_handleContent_extraInitializers = [];
16
+ let _private_handleContent_descriptor;
17
+ let _private_enableLoadEvent_decorators;
18
+ let _private_enableLoadEvent_descriptor;
17
19
  return class XSvgFeatures {
18
20
  static {
19
21
  const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
20
22
  _private_handleSrc_decorators = [registerAttributeHandler('src', true)];
21
23
  _private_handleContent_decorators = [registerAttributeHandler('content', true)];
22
- __esDecorate(null, null, _private_handleSrc_decorators, { kind: "field", name: "#handleSrc", static: false, private: true, access: { has: obj => #handleSrc in obj, get: obj => obj.#handleSrc, set: (obj, value) => { obj.#handleSrc = value; } }, metadata: _metadata }, _private_handleSrc_initializers, _private_handleSrc_extraInitializers);
23
- __esDecorate(null, null, _private_handleContent_decorators, { kind: "field", name: "#handleContent", static: false, private: true, access: { has: obj => #handleContent in obj, get: obj => obj.#handleContent, set: (obj, value) => { obj.#handleContent = value; } }, metadata: _metadata }, _private_handleContent_initializers, _private_handleContent_extraInitializers);
24
+ _private_enableLoadEvent_decorators = [registerEventEnableStatusChangeHandler('load')];
25
+ __esDecorate(this, _private_handleSrc_descriptor = { value: __setFunctionName(function (newVal) {
26
+ if (!newVal) {
27
+ this.#getImg().src = '';
28
+ }
29
+ else {
30
+ this.#getImg().src = newVal;
31
+ }
32
+ }, "#handleSrc") }, _private_handleSrc_decorators, { kind: "method", name: "#handleSrc", static: false, private: true, access: { has: obj => #handleSrc in obj, get: obj => obj.#handleSrc }, metadata: _metadata }, null, _instanceExtraInitializers);
33
+ __esDecorate(this, _private_handleContent_descriptor = { value: __setFunctionName(function (content) {
34
+ this.#url && URL.revokeObjectURL(this.#url);
35
+ if (!content) {
36
+ this.#url = '';
37
+ return;
38
+ }
39
+ const blob = new Blob([content], {
40
+ type: 'image/svg+xml;charset=UTF-8',
41
+ });
42
+ const src = URL.createObjectURL(blob);
43
+ this.#url = src;
44
+ this.#getImg().src = src;
45
+ }, "#handleContent") }, _private_handleContent_decorators, { kind: "method", name: "#handleContent", static: false, private: true, access: { has: obj => #handleContent in obj, get: obj => obj.#handleContent }, metadata: _metadata }, null, _instanceExtraInitializers);
46
+ __esDecorate(this, _private_enableLoadEvent_descriptor = { value: __setFunctionName(function (status) {
47
+ if (status) {
48
+ this.#getImg().addEventListener('load', this.#teleportLoadEvent, {
49
+ passive: true,
50
+ });
51
+ }
52
+ else {
53
+ this.#getImg().removeEventListener('load', this.#teleportLoadEvent);
54
+ }
55
+ }, "#enableLoadEvent") }, _private_enableLoadEvent_decorators, { kind: "method", name: "#enableLoadEvent", static: false, private: true, access: { has: obj => #enableLoadEvent in obj, get: obj => obj.#enableLoadEvent }, metadata: _metadata }, null, _instanceExtraInitializers);
24
56
  if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
25
57
  }
26
58
  static observedAttributes = ['src', 'content'];
27
- #dom;
28
- #loadEventInvoker = new Image();
29
- #handleSrc = __runInitializers(this, _private_handleSrc_initializers, bindToStyle(() => this.#dom, 'background-image', (src) => {
30
- this.#loadEventInvoker.src = src;
31
- return `url(${src})`;
32
- }));
33
- #handleContent = (__runInitializers(this, _private_handleSrc_extraInitializers), __runInitializers(this, _private_handleContent_initializers, bindToStyle(() => this.#dom, 'background-image', (content) => {
34
- if (!content)
35
- return '';
36
- // https://stackoverflow.com/questions/23223718/failed-to-execute-btoa-on-window-the-string-to-be-encoded-contains-characte
37
- const src = 'data:image/svg+xml;base64,'
38
- + btoa(unescape(encodeURIComponent(content)));
39
- this.#loadEventInvoker.src = src;
40
- return `url("${src}")`;
41
- })));
42
- #fireLoadEvent = (__runInitializers(this, _private_handleContent_extraInitializers), () => {
43
- const { width, height } = this.#loadEventInvoker;
59
+ #dom = __runInitializers(this, _instanceExtraInitializers);
60
+ #url = null;
61
+ #getImg = genDomGetter(() => this.#dom.shadowRoot, '#img');
62
+ get #handleSrc() { return _private_handleSrc_descriptor.value; }
63
+ get #handleContent() { return _private_handleContent_descriptor.value; }
64
+ get #enableLoadEvent() { return _private_enableLoadEvent_descriptor.value; }
65
+ #teleportLoadEvent = () => {
44
66
  this.#dom.dispatchEvent(new CustomEvent('load', {
45
67
  ...commonComponentEventSetting,
46
68
  detail: {
47
- width,
48
- height,
69
+ width: this.#getImg().naturalWidth,
70
+ height: this.#getImg().naturalHeight,
49
71
  },
50
72
  }));
51
- });
73
+ };
52
74
  constructor(dom) {
53
75
  this.#dom = dom;
54
- this.#loadEventInvoker.addEventListener('load', this.#fireLoadEvent);
55
76
  }
56
77
  };
57
78
  })();
58
79
  export { XSvgFeatures };
59
80
  let XSvg = (() => {
60
- let _classDecorators = [Component('x-svg', [CommonEventsAndMethods, XSvgFeatures])];
81
+ let _classDecorators = [Component('x-svg', [CommonEventsAndMethods, XSvgFeatures], templateXSvg())];
61
82
  let _classDescriptor;
62
83
  let _classExtraInitializers = [];
63
84
  let _classThis;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/web-elements-canary",
3
- "version": "0.8.5-canary-20250905-877d1535",
3
+ "version": "0.8.6-canary-20250911-1d97fce6",
4
4
  "private": false,
5
5
  "repository": {
6
6
  "type": "git",
@@ -101,7 +101,7 @@
101
101
  ],
102
102
  "dependencies": {
103
103
  "@lynx-js/web-elements-reactive": "npm:@lynx-js/web-elements-reactive-canary@0.2.2",
104
- "@lynx-js/web-elements-template": "npm:@lynx-js/web-elements-template-canary@0.8.5-canary-20250905-877d1535"
104
+ "@lynx-js/web-elements-template": "npm:@lynx-js/web-elements-template-canary@0.8.6-canary-20250911-1d97fce6"
105
105
  },
106
106
  "devDependencies": {
107
107
  "tslib": "^2.8.1"
@@ -56,7 +56,7 @@ x-image[auto-size] {
56
56
  display: contents;
57
57
  }
58
58
 
59
- x-image[auto-size]::part(img) {
59
+ x-image[auto-size]::part(img), x-svg::part(img) {
60
60
  margin: inherit;
61
61
  padding: inherit;
62
62
  width: inherit;
@@ -4,7 +4,12 @@
4
4
  // LICENSE file in the root directory of this source tree.
5
5
  */
6
6
  x-svg {
7
- contain: strict;
8
- background: no-repeat center;
9
- background-size: 100% 100%;
7
+ contain: content;
8
+ display: flex;
9
+ }
10
+
11
+ x-svg::part(img) {
12
+ width: 100%;
13
+ height: 100%;
14
+ flex: 0 0 100%;
10
15
  }