@alegendstale/holly-components 2.0.9 → 2.0.10
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/custom-elements.json +1926 -927
- package/dist/components/responsive-svg/responsive-svg.d.ts +4 -4
- package/dist/components/responsive-svg/responsive-svg.d.ts.map +1 -1
- package/dist/components/responsive-svg/responsive-svg.js +68 -67
- package/dist/controllers/ResponsiveController.d.ts.map +1 -0
- package/dist/controllers/StyleController.d.ts +12 -0
- package/dist/controllers/StyleController.d.ts.map +1 -0
- package/dist/controllers/StyleController.js +20 -0
- package/dist/decorators/ExposeParts.d.ts +6 -0
- package/dist/decorators/ExposeParts.d.ts.map +1 -0
- package/dist/decorators/ExposeParts.js +39 -0
- package/dist/node_modules/style-observer/src/element-style-observer.js +214 -0
- package/dist/node_modules/style-observer/src/rendered-observer.js +46 -0
- package/dist/node_modules/style-observer/src/style-observer.js +98 -0
- package/dist/node_modules/style-observer/src/util/Bug.js +36 -0
- package/dist/node_modules/style-observer/src/util/MultiWeakMap.js +20 -0
- package/dist/node_modules/style-observer/src/util/adopt-css.js +15 -0
- package/dist/node_modules/style-observer/src/util/bugs/adopted-style-sheet.js +28 -0
- package/dist/node_modules/style-observer/src/util/bugs/transitionrun-loop.js +15 -0
- package/dist/node_modules/style-observer/src/util/bugs/unregistered-transition.js +14 -0
- package/dist/node_modules/style-observer/src/util/gentle-register-property.js +41 -0
- package/dist/node_modules/style-observer/src/util/is-registered-property.js +15 -0
- package/dist/node_modules/style-observer/src/util.js +61 -0
- package/package.json +15 -5
- package/dist/utils/ResponsiveController.d.ts.map +0 -1
- /package/dist/{utils → controllers}/ResponsiveController.d.ts +0 -0
- /package/dist/{utils → controllers}/ResponsiveController.js +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LitElement, TemplateResult
|
|
1
|
+
import { LitElement, TemplateResult } from 'lit';
|
|
2
2
|
type ViewBox = {
|
|
3
3
|
x: number;
|
|
4
4
|
y: number;
|
|
@@ -51,10 +51,10 @@ export declare class ResponsiveSvg extends LitElement {
|
|
|
51
51
|
/** The viewBox dimensions the SVG will use. */
|
|
52
52
|
protected viewBox: ViewBox;
|
|
53
53
|
protected svgClasses(): {};
|
|
54
|
-
|
|
54
|
+
private _widthController;
|
|
55
|
+
private _heightController;
|
|
56
|
+
connectedCallback(): void;
|
|
55
57
|
render(): TemplateResult<1> | undefined;
|
|
56
|
-
/** Applies a part name to all paths in the given element. */
|
|
57
|
-
private applyPartToPaths;
|
|
58
58
|
/**
|
|
59
59
|
* Gets the viewBox dimensions from an SVG element.
|
|
60
60
|
* @param svg The SVG to get the attribute from.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"responsive-svg.d.ts","sourceRoot":"","sources":["../../../src/components/responsive-svg/responsive-svg.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAQ,cAAc,EAAE,
|
|
1
|
+
{"version":3,"file":"responsive-svg.d.ts","sourceRoot":"","sources":["../../../src/components/responsive-svg/responsive-svg.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAQ,cAAc,EAAE,MAAM,KAAK,CAAC;AAUvD,KAAK,OAAO,GAAG;IACd,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAA;CACd,CAAA;AAED,eAAO,MAAM,+BAA+B,+HAKlC,CAAC;AAEX,eAAO,MAAM,iCAAiC,4BAA6B,CAAC;AAE5E,eAAO,MAAM,0BAA0B,+eAG7B,CAAC;AAEX,MAAM,MAAM,wBAAwB,GAAG,OAAO,+BAA+B,CAAC,MAAM,CAAC,CAAC;AACtF,MAAM,MAAM,0BAA0B,GAAG,OAAO,iCAAiC,CAAC,MAAM,CAAC,CAAC;AAC1F,MAAM,MAAM,mBAAmB,GAAG,OAAO,0BAA0B,CAAC,MAAM,CAAC,CAAC;AAC5E,MAAM,MAAM,oBAAoB,GAAG,GAAG,wBAAwB,IAAI,0BAA0B,EAAE,CAAC;AAQ/F;;;;;;;;;;;GAWG;AACH,qBACa,aAAc,SAAQ,UAAU;IAC5C,MAAM,CAAC,MAAM,4BAAY;IAEzB,kDAAkD;IAElD,OAAO,EAAE,OAAO,CAAS;IAEzB,yCAAyC;IAEzC,SAAS,EAAE,OAAO,CAAS;IAE3B,gBAAgB;IAChB,OAAO,CAAC,IAAI,CAAC,CAAiC;IAC9C;;;;OAIG;IACH,IAEI,GAAG,CAAC,GAAG,EAAE,UAAU,GAAG,cAAc,CAAC,CAAC,CAAC,GAAG,MAAM,EASnD;IACD,IAAI,GAAG,IAVM,UAAU,GAAG,cAAc,CAAC,CAAC,CAAC,GAAG,MAAM,CAYnD;IAED,gBAAgB;IAChB,OAAO,CAAC,oBAAoB,CAAkC;IAC9D;;;;OAIG;IACH,IACI,mBAAmB,CAAC,GAAG,EAAE,mBAAmB,GAAG,SAAS,EAE3D;IACD,IAAI,mBAAmB,IAHM,mBAAmB,GAAG,SAAS,CAW3D;IAED,+CAA+C;IAC/C,SAAS,CAAC,OAAO,EAAE,OAAO,CAAuC;IAGjE,SAAS,CAAC,UAAU;IAIpB,OAAO,CAAC,gBAAgB,CAEtB;IAEF,OAAO,CAAC,iBAAiB,CAEvB;IAEF,iBAAiB,IAAI,IAAI;IAoBzB,MAAM;IAuCN;;;;OAIG;IACI,cAAc,CAAC,GAAG,EAAE,UAAU,GAAG,OAAO,GAAG,IAAI;CAMtD;AAED,OAAO,CAAC,MAAM,CAAC;IACd,UAAU,qBAAqB;QAC9B,gBAAgB,EAAE,aAAa,CAAC;KAChC;CACD"}
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
import { LitElement as g, html as
|
|
2
|
-
import { property as
|
|
3
|
-
import { styleMap as
|
|
4
|
-
import { parseSVG as
|
|
5
|
-
import { classMap as
|
|
6
|
-
import { isTemplateResult as
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import { LitElement as g, html as l } from "lit";
|
|
2
|
+
import { property as h, customElement as f } from "lit/decorators.js";
|
|
3
|
+
import { styleMap as m } from "lit/directives/style-map.js";
|
|
4
|
+
import { parseSVG as x } from "../../utils/basicUtils.js";
|
|
5
|
+
import { classMap as u } from "lit/directives/class-map.js";
|
|
6
|
+
import { isTemplateResult as w } from "lit/directive-helpers.js";
|
|
7
|
+
import d from "./responsive-svg.styles.js";
|
|
8
|
+
import { StyleController as c } from "../../controllers/StyleController.js";
|
|
9
|
+
import { exposeParts as y } from "../../decorators/ExposeParts.js";
|
|
10
|
+
var M = Object.defineProperty, A = Object.getOwnPropertyDescriptor, p = (t, e, r, o) => {
|
|
11
|
+
for (var s = o > 1 ? void 0 : o ? A(e, r) : e, i = t.length - 1, a; i >= 0; i--)
|
|
12
|
+
(a = t[i]) && (s = (o ? a(e, r, s) : a(s)) || s);
|
|
13
|
+
return o && s && M(e, r, s), s;
|
|
12
14
|
};
|
|
13
|
-
const
|
|
15
|
+
const v = [
|
|
14
16
|
"none",
|
|
15
17
|
"xMinYMin",
|
|
16
18
|
"xMidYMin",
|
|
@@ -21,19 +23,23 @@ const l = [
|
|
|
21
23
|
"xMinYMax",
|
|
22
24
|
"xMidYMax",
|
|
23
25
|
"xMaxYMax"
|
|
24
|
-
],
|
|
25
|
-
...
|
|
26
|
-
...
|
|
27
|
-
], _ = new Set(
|
|
28
|
-
function
|
|
26
|
+
], S = ["meet", "slice"], R = [
|
|
27
|
+
...v,
|
|
28
|
+
...v.flatMap((t) => S.map((e) => `${t} ${e}`))
|
|
29
|
+
], _ = new Set(R);
|
|
30
|
+
function B(t) {
|
|
29
31
|
return _.has(t);
|
|
30
32
|
}
|
|
31
|
-
let
|
|
33
|
+
let n = class extends g {
|
|
32
34
|
constructor() {
|
|
33
|
-
super(...arguments), this.autofit = !1, this.svgColors = !1, this.viewBox = { x: 0, y: 0, width: 0, height: 0 }
|
|
35
|
+
super(...arguments), this.autofit = !1, this.svgColors = !1, this.viewBox = { x: 0, y: 0, width: 0, height: 0 }, this._widthController = new c(this, "--svg-width", (t) => {
|
|
36
|
+
this.viewBox = { ...this.viewBox, width: parseFloat(t) || 0 };
|
|
37
|
+
}), this._heightController = new c(this, "--svg-height", (t) => {
|
|
38
|
+
this.viewBox = { ...this.viewBox, height: parseFloat(t) || 0 };
|
|
39
|
+
});
|
|
34
40
|
}
|
|
35
41
|
set svg(t) {
|
|
36
|
-
const e = t instanceof SVGElement ||
|
|
42
|
+
const e = t instanceof SVGElement || w(t) ? t : x(t);
|
|
37
43
|
e instanceof Element && !(e instanceof SVGElement) || (this._svg = e);
|
|
38
44
|
}
|
|
39
45
|
get svg() {
|
|
@@ -45,7 +51,7 @@ let p = class extends g {
|
|
|
45
51
|
get preserveAspectRatio() {
|
|
46
52
|
if (this._preserveAspectRatio == null && this.svg instanceof SVGElement) {
|
|
47
53
|
const t = this.svg.getAttribute("preserveAspectRatio") || "";
|
|
48
|
-
if (
|
|
54
|
+
if (B(t)) return t;
|
|
49
55
|
}
|
|
50
56
|
return this._preserveAspectRatio || "xMidYMid meet";
|
|
51
57
|
}
|
|
@@ -53,33 +59,35 @@ let p = class extends g {
|
|
|
53
59
|
svgClasses() {
|
|
54
60
|
return {};
|
|
55
61
|
}
|
|
56
|
-
|
|
57
|
-
if (super.
|
|
58
|
-
const
|
|
59
|
-
this.viewBox =
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
62
|
+
connectedCallback() {
|
|
63
|
+
if (super.connectedCallback(), this.svg instanceof SVGElement) {
|
|
64
|
+
const t = this.getViewBoxSize(this.svg), e = parseFloat(this.svg.getAttribute("width") || "0"), r = parseFloat(this.svg.getAttribute("height") || "0");
|
|
65
|
+
this.viewBox = {
|
|
66
|
+
x: t?.x ?? 0,
|
|
67
|
+
y: t?.y ?? 0,
|
|
68
|
+
width: this.viewBox.width || (t?.width ?? e),
|
|
69
|
+
height: this.viewBox.height || (t?.height ?? r)
|
|
70
|
+
};
|
|
63
71
|
}
|
|
64
72
|
}
|
|
65
73
|
render() {
|
|
66
|
-
const t = this.viewBox, e = this.preserveAspectRatio,
|
|
67
|
-
if (
|
|
74
|
+
const t = this.viewBox, e = this.preserveAspectRatio, r = this.svgClasses();
|
|
75
|
+
if (t.height === 0 || t.width === 0) return l`<p style="font-size: initial;">⚠️ SVG ViewBox</p>`;
|
|
76
|
+
if (typeof this.svg == "string") return l`<p style="font-size: initial;">⚠️ SVG Error</p>`;
|
|
68
77
|
if (this.svg instanceof SVGElement) {
|
|
69
78
|
const s = this.svg.cloneNode(!0);
|
|
70
|
-
return
|
|
79
|
+
return o(Array.from(s.children), t);
|
|
71
80
|
} else return o(this.svg, t);
|
|
72
|
-
function o(s,
|
|
81
|
+
function o(s, i) {
|
|
73
82
|
if (s)
|
|
74
|
-
return
|
|
83
|
+
return l`
|
|
75
84
|
<svg
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
"--svg-
|
|
80
|
-
"--svg-height-fallback": `${r.height}em`
|
|
85
|
+
class=${u(r)}
|
|
86
|
+
style=${m({
|
|
87
|
+
"--svg-width-fallback": `${i.width}em`,
|
|
88
|
+
"--svg-height-fallback": `${i.height}em`
|
|
81
89
|
})}
|
|
82
|
-
viewBox="${
|
|
90
|
+
viewBox="${i.x} ${i.y} ${i.width} ${i.height}"
|
|
83
91
|
preserveAspectRatio=${e}
|
|
84
92
|
xmlns="http://www.w3.org/2000/svg"
|
|
85
93
|
>
|
|
@@ -88,14 +96,6 @@ let p = class extends g {
|
|
|
88
96
|
`;
|
|
89
97
|
}
|
|
90
98
|
}
|
|
91
|
-
/** Applies a part name to all paths in the given element. */
|
|
92
|
-
applyPartToPaths(t, e) {
|
|
93
|
-
if (t instanceof Element) {
|
|
94
|
-
t.tagName.toLowerCase() === "path" && t.setAttribute("part", e);
|
|
95
|
-
for (const i of Array.from(t.children))
|
|
96
|
-
this.applyPartToPaths(i, e);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
99
|
/**
|
|
100
100
|
* Gets the viewBox dimensions from an SVG element.
|
|
101
101
|
* @param svg The SVG to get the attribute from.
|
|
@@ -106,25 +106,26 @@ let p = class extends g {
|
|
|
106
106
|
return e ? { x: +e[0], y: +e[1], width: +e[2], height: +e[3] } : null;
|
|
107
107
|
}
|
|
108
108
|
};
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
],
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
],
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
n
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
109
|
+
n.styles = [d];
|
|
110
|
+
p([
|
|
111
|
+
h({ type: Boolean, reflect: !0 })
|
|
112
|
+
], n.prototype, "autofit", 2);
|
|
113
|
+
p([
|
|
114
|
+
h({ type: Boolean, reflect: !0 })
|
|
115
|
+
], n.prototype, "svgColors", 2);
|
|
116
|
+
p([
|
|
117
|
+
y(["svg", "path"]),
|
|
118
|
+
h({ type: Object })
|
|
119
|
+
], n.prototype, "svg", 1);
|
|
120
|
+
p([
|
|
121
|
+
h({ type: String, reflect: !0 })
|
|
122
|
+
], n.prototype, "preserveAspectRatio", 1);
|
|
123
|
+
n = p([
|
|
124
|
+
f("responsive-svg")
|
|
125
|
+
], n);
|
|
125
126
|
export {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
127
|
+
n as ResponsiveSvg,
|
|
128
|
+
v as preserveAspectRatioAlignOptions,
|
|
129
|
+
R as preserveAspectRatioOptions,
|
|
130
|
+
S as preserveAspectRatioSpacingOptions
|
|
130
131
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ResponsiveController.d.ts","sourceRoot":"","sources":["../../src/controllers/ResponsiveController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,KAAK,CAAC;AAEjE,qBAAa,oBAAqB,YAAW,kBAAkB;IAC9D,QAAQ,EAAE,OAAO,CAAS;IAC1B,OAAO,CAAC,IAAI,CAAyB;IACrC,OAAO,CAAC,cAAc,CAAiB;IACvC,OAAO,CAAC,sBAAsB,CAAuC;gBAEzD,IAAI,EAAE,sBAAsB,EAAE,gBAAgB,GAAE,MAAgB;IAS5E,aAAa,IAAI,IAAI;IAMrB,gBAAgB,IAAI,IAAI;CAGxB"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ReactiveController, ReactiveControllerHost } from 'lit';
|
|
2
|
+
export declare class StyleController implements ReactiveController {
|
|
3
|
+
private host;
|
|
4
|
+
private property;
|
|
5
|
+
private callback?;
|
|
6
|
+
private observer?;
|
|
7
|
+
value: string;
|
|
8
|
+
constructor(host: ReactiveControllerHost & HTMLElement, property: string, callback?: ((val: string) => void) | undefined);
|
|
9
|
+
hostConnected(): void;
|
|
10
|
+
hostDisconnected(): void;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=StyleController.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StyleController.d.ts","sourceRoot":"","sources":["../../src/controllers/StyleController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,KAAK,CAAC;AAGjE,qBAAa,eAAgB,YAAW,kBAAkB;IAKxD,OAAO,CAAC,IAAI;IACZ,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,QAAQ,CAAC;IANlB,OAAO,CAAC,QAAQ,CAAC,CAAgB;IAC1B,KAAK,EAAE,MAAM,CAAM;gBAGjB,IAAI,EAAE,sBAAsB,GAAG,WAAW,EAC1C,QAAQ,EAAE,MAAM,EAChB,QAAQ,CAAC,GAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,aAAA;IAKzC,aAAa;IAkBb,gBAAgB;CAGhB"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import i from "../node_modules/style-observer/src/style-observer.js";
|
|
2
|
+
import "../node_modules/style-observer/src/element-style-observer.js";
|
|
3
|
+
class l {
|
|
4
|
+
constructor(s, t, e) {
|
|
5
|
+
this.host = s, this.property = t, this.callback = e, this.value = "", this.host.addController(this);
|
|
6
|
+
}
|
|
7
|
+
hostConnected() {
|
|
8
|
+
const s = window.getComputedStyle(this.host).getPropertyValue(this.property);
|
|
9
|
+
this.value = s.trim(), this.callback?.(this.value), this.observer = new i((t) => {
|
|
10
|
+
const e = t[t.length - 1].value.trim();
|
|
11
|
+
e !== this.value && (this.value = e, this.callback?.(this.value), this.host.requestUpdate());
|
|
12
|
+
}), this.observer.observe(this.host, this.property);
|
|
13
|
+
}
|
|
14
|
+
hostDisconnected() {
|
|
15
|
+
this.observer?.unobserve();
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export {
|
|
19
|
+
l as StyleController
|
|
20
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ReactiveElement } from 'lit';
|
|
2
|
+
type PartMap = string | Record<string, string>;
|
|
3
|
+
/** Property decorator that exposes parts and updates them when the property changes. */
|
|
4
|
+
export declare function exposeParts<T extends ReactiveElement>(partMap: PartMap[]): (proto: T, key: string & keyof T) => void;
|
|
5
|
+
export {};
|
|
6
|
+
//# sourceMappingURL=ExposeParts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExposeParts.d.ts","sourceRoot":"","sources":["../../src/decorators/ExposeParts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAA8C,MAAM,KAAK,CAAC;AAOlF,KAAK,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAgD/C,wFAAwF;AACxF,wBAAgB,WAAW,CAAC,CAAC,SAAS,eAAe,EAAE,OAAO,EAAE,OAAO,EAAE,IAChE,OAAO,CAAC,EAAE,KAAK,MAAM,GAAG,MAAM,CAAC,UAWvC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
class n {
|
|
2
|
+
constructor(t, r, s) {
|
|
3
|
+
this.host = t, this.getValue = r, this.normalizedMap = {}, t.addController(this);
|
|
4
|
+
for (const e of s)
|
|
5
|
+
typeof e == "string" ? this.normalizedMap[e] = e : Object.assign(this.normalizedMap, e);
|
|
6
|
+
}
|
|
7
|
+
hostUpdated() {
|
|
8
|
+
const t = this.getValue();
|
|
9
|
+
t !== this.lastValue && (this.lastValue = t, this._apply());
|
|
10
|
+
}
|
|
11
|
+
/** Applies the parts in the map to the relevant elements. */
|
|
12
|
+
_apply() {
|
|
13
|
+
const t = this.host.shadowRoot;
|
|
14
|
+
if (t)
|
|
15
|
+
for (const [r, s] of Object.entries(this.normalizedMap)) {
|
|
16
|
+
const e = t.querySelectorAll(r), i = this._prefix(s);
|
|
17
|
+
for (const a of e)
|
|
18
|
+
a.getAttribute("part") !== i && a.setAttribute("part", i);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/** Sanitizes name (removes CSS selectors), and prefixes partName */
|
|
22
|
+
_prefix(t) {
|
|
23
|
+
return `__${t.replace(/[.#]/g, "")}`;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function l(o) {
|
|
27
|
+
return (t, r) => {
|
|
28
|
+
t.constructor.addInitializer((e) => {
|
|
29
|
+
new n(
|
|
30
|
+
e,
|
|
31
|
+
() => e[r],
|
|
32
|
+
o
|
|
33
|
+
);
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export {
|
|
38
|
+
l as exposeParts
|
|
39
|
+
};
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import a from "./util/Bug.js";
|
|
2
|
+
import "./util/bugs/transitionrun-loop.js";
|
|
3
|
+
import "./util/bugs/unregistered-transition.js";
|
|
4
|
+
import "./util/bugs/adopted-style-sheet.js";
|
|
5
|
+
import p from "./util/gentle-register-property.js";
|
|
6
|
+
import d from "./util/MultiWeakMap.js";
|
|
7
|
+
import { toArray as h, getTimesFor as y, wait as u } from "./util.js";
|
|
8
|
+
import g from "./rendered-observer.js";
|
|
9
|
+
const f = globalThis.CSS?.supports?.("transition-behavior", "allow-discrete") ? " allow-discrete" : "";
|
|
10
|
+
globalThis.document && (p("--style-observer-transition", { inherits: !1 }), a.detectAll());
|
|
11
|
+
class O {
|
|
12
|
+
/**
|
|
13
|
+
* Observed properties to their old values.
|
|
14
|
+
* @type {Map<string, string>}
|
|
15
|
+
*/
|
|
16
|
+
properties;
|
|
17
|
+
/**
|
|
18
|
+
* Get the names of all properties currently being observed.
|
|
19
|
+
* @type { string[] }
|
|
20
|
+
*/
|
|
21
|
+
get propertyNames() {
|
|
22
|
+
return [...this.properties.keys()];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The element being observed.
|
|
26
|
+
* @type {Element}
|
|
27
|
+
*/
|
|
28
|
+
target;
|
|
29
|
+
/**
|
|
30
|
+
* The callback to call when the element's style changes.
|
|
31
|
+
* @type {StyleObserverCallback}
|
|
32
|
+
*/
|
|
33
|
+
callback;
|
|
34
|
+
/**
|
|
35
|
+
* The observer options.
|
|
36
|
+
* @type {StyleObserverOptions}
|
|
37
|
+
*/
|
|
38
|
+
options;
|
|
39
|
+
/**
|
|
40
|
+
* Whether the observer has been initialized.
|
|
41
|
+
* @type {boolean}
|
|
42
|
+
*/
|
|
43
|
+
#t = !1;
|
|
44
|
+
/**
|
|
45
|
+
* @param {Element} target
|
|
46
|
+
* @param {StyleObserverCallback} callback
|
|
47
|
+
* @param {StyleObserverOptions} [options]
|
|
48
|
+
*/
|
|
49
|
+
constructor(t, r, s = {}) {
|
|
50
|
+
this.constructor.all.add(t, this), this.properties = /* @__PURE__ */ new Map(), this.target = t, this.callback = r, this.options = { properties: [], ...s };
|
|
51
|
+
let e = h(s.properties);
|
|
52
|
+
this.renderedObserver = new g((i) => {
|
|
53
|
+
this.propertyNames.length > 0 && this.handleEvent();
|
|
54
|
+
}), e.length > 0 && this.observe(e);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Called the first time observe() is called to initialize the target.
|
|
58
|
+
*/
|
|
59
|
+
#s() {
|
|
60
|
+
if (this.#t)
|
|
61
|
+
return;
|
|
62
|
+
let t = this.constructor.all.get(this.target).size === 1;
|
|
63
|
+
this.updateTransition({ firstTime: t }), this.#t = !0;
|
|
64
|
+
}
|
|
65
|
+
resolveOptions(t) {
|
|
66
|
+
return Object.assign(c(t), this.options);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Handle a potential property change
|
|
70
|
+
* @private
|
|
71
|
+
* @param {TransitionEvent} [event]
|
|
72
|
+
*/
|
|
73
|
+
async handleEvent(t) {
|
|
74
|
+
if (t && !this.properties.has(t.propertyName))
|
|
75
|
+
return;
|
|
76
|
+
if (a.TRANSITIONRUN_EVENT_LOOP && t?.type === "transitionrun" || this.options.throttle > 0) {
|
|
77
|
+
let e = a.TRANSITIONRUN_EVENT_LOOP ? "transitionrun" : "transitionstart", i = Math.max(this.options.throttle, 50);
|
|
78
|
+
if (a.TRANSITIONRUN_EVENT_LOOP) {
|
|
79
|
+
let n = y(
|
|
80
|
+
t.propertyName,
|
|
81
|
+
getComputedStyle(this.target).transition
|
|
82
|
+
);
|
|
83
|
+
i = Math.max(i, n.duration + n.delay + 16);
|
|
84
|
+
}
|
|
85
|
+
this.target.removeEventListener(e, this), await u(i), this.target.addEventListener(e, this);
|
|
86
|
+
}
|
|
87
|
+
let r = getComputedStyle(this.target), s = [];
|
|
88
|
+
for (let e of this.propertyNames) {
|
|
89
|
+
let i = r.getPropertyValue(e), n = this.properties.get(e);
|
|
90
|
+
i !== n && (s.push({ target: this.target, property: e, value: i, oldValue: n }), this.properties.set(e, i));
|
|
91
|
+
}
|
|
92
|
+
s.length > 0 && this.callback(s);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Observe the target for changes to one or more CSS properties.
|
|
96
|
+
* @param {string | string[]} properties
|
|
97
|
+
* @return {void}
|
|
98
|
+
*/
|
|
99
|
+
observe(t) {
|
|
100
|
+
if (t = h(t), t = t.filter((s) => !this.properties.has(s)), t.length === 0)
|
|
101
|
+
return;
|
|
102
|
+
this.#s();
|
|
103
|
+
let r = getComputedStyle(this.target);
|
|
104
|
+
for (let s of t) {
|
|
105
|
+
a.UNREGISTERED_TRANSITION && !this.constructor.properties.has(s) && (p(s, void 0, this.target.ownerDocument), this.constructor.properties.add(s));
|
|
106
|
+
let e = r.getPropertyValue(s);
|
|
107
|
+
this.properties.set(s, e);
|
|
108
|
+
}
|
|
109
|
+
a.TRANSITIONRUN_EVENT_LOOP && (this.target.addEventListener("transitionrun", this), a.all.TRANSITIONRUN_EVENT_LOOP.valuePending?.then((s) => {
|
|
110
|
+
s || this.target.removeEventListener("transitionrun", this);
|
|
111
|
+
})), this.target.addEventListener("transitionstart", this), this.target.addEventListener("transitionend", this), this.updateTransitionProperties(), this.renderedObserver.observe(this.target);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Update the `--style-observer-transition` property to include all observed properties.
|
|
115
|
+
*/
|
|
116
|
+
updateTransitionProperties() {
|
|
117
|
+
this.setProperty("--style-observer-transition", "");
|
|
118
|
+
let t = new Set(
|
|
119
|
+
getComputedStyle(this.target).transitionProperty.split(", ")
|
|
120
|
+
), r = [];
|
|
121
|
+
for (let e of this.constructor.all.get(this.target))
|
|
122
|
+
r.push(...e.propertyNames);
|
|
123
|
+
r = [...new Set(r)];
|
|
124
|
+
let s = r.filter((e) => !t.has(e)).map((e) => `${e} 1ms step-start${f}`).join(", ");
|
|
125
|
+
this.setProperty("--style-observer-transition", s);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* @type { string | undefined }
|
|
129
|
+
*/
|
|
130
|
+
#e;
|
|
131
|
+
/**
|
|
132
|
+
* Update the target's transition property or refresh it if it was overwritten.
|
|
133
|
+
* @param {object} options
|
|
134
|
+
* @param {boolean} [options.firstTime] - Whether this is the first time the transition is being set.
|
|
135
|
+
*/
|
|
136
|
+
updateTransition({ firstTime: t } = {}) {
|
|
137
|
+
const r = "var(--style-observer-transition, --style-observer-noop)", s = this.getProperty("transition");
|
|
138
|
+
let e;
|
|
139
|
+
(t ? s : !s.includes(r)) && (e = this.#e = s), e === void 0 && (t || !this.#e) && (s.includes(r) && this.setProperty("transition", ""), e = getComputedStyle(this.target).transition), e === "all" ? e = "" : e = e.replace(/^none\b/, "");
|
|
140
|
+
const i = e ? e + ", " : "";
|
|
141
|
+
this.setProperty("transition", i + r), this.updateTransitionProperties();
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Whether the target has an open shadow root (and the modern adoptedStyleSheets API is supported).
|
|
145
|
+
* @type { boolean }
|
|
146
|
+
* @private
|
|
147
|
+
*/
|
|
148
|
+
get _isHost() {
|
|
149
|
+
return this.target.shadowRoot && !a.ADOPTED_STYLE_SHEET && !Object.isFrozen(this.target.shadowRoot.adoptedStyleSheets);
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Shadow style sheet. Only used if _isHost is true.
|
|
153
|
+
* @type { CSSStyleSheet | undefined }
|
|
154
|
+
* @private
|
|
155
|
+
*/
|
|
156
|
+
_shadowSheet;
|
|
157
|
+
/**
|
|
158
|
+
* Any styles we've set on the target, for any reason.
|
|
159
|
+
* @type { Record<string, string> }
|
|
160
|
+
* @private
|
|
161
|
+
*/
|
|
162
|
+
_styles = {};
|
|
163
|
+
/**
|
|
164
|
+
* Set a CSS property on the target.
|
|
165
|
+
* @param {string} property
|
|
166
|
+
* @param {string} value
|
|
167
|
+
* @param {string} [priority]
|
|
168
|
+
* @return {void}
|
|
169
|
+
*/
|
|
170
|
+
setProperty(t, r, s) {
|
|
171
|
+
let e = this.target.style, i = e;
|
|
172
|
+
if (this._isHost) {
|
|
173
|
+
if (!this._shadowSheet && (this._shadowSheet = new CSSStyleSheet(), this._shadowSheet.insertRule(":host { }"), this.target.shadowRoot.adoptedStyleSheets.push(this._shadowSheet), Object.keys(this._styles).length > 0))
|
|
174
|
+
for (let n in this._styles) {
|
|
175
|
+
let l = this._styles[n];
|
|
176
|
+
this.setProperty(n, l), e.getPropertyValue(n) === l && e.removeProperty(n);
|
|
177
|
+
}
|
|
178
|
+
i = this._shadowSheet.cssRules[0].style;
|
|
179
|
+
}
|
|
180
|
+
i.setProperty(t, r, s), this._styles[t] = this.getProperty(t);
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Get a CSS property from the target.
|
|
184
|
+
* @param {string} property
|
|
185
|
+
* @return {string}
|
|
186
|
+
*/
|
|
187
|
+
getProperty(t) {
|
|
188
|
+
return (this._shadowSheet?.cssRules[0]?.style ?? this.target.style).getPropertyValue(t);
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Stop observing a target for changes to one or more CSS properties.
|
|
192
|
+
* @param { string | string[] } [properties] Properties to stop observing. Defaults to all observed properties.
|
|
193
|
+
* @return {void}
|
|
194
|
+
*/
|
|
195
|
+
unobserve(t) {
|
|
196
|
+
t = h(t), t = t.filter((r) => this.properties.has(r));
|
|
197
|
+
for (let r of t)
|
|
198
|
+
this.properties.delete(r);
|
|
199
|
+
this.properties.size === 0 && (this.target.removeEventListener("transitionrun", this), this.target.removeEventListener("transitionstart", this), this.target.removeEventListener("transitionend", this), this.renderedObserver.unobserve(this.target)), this.updateTransitionProperties();
|
|
200
|
+
}
|
|
201
|
+
/** All properties ever observed by this class. */
|
|
202
|
+
static properties = /* @__PURE__ */ new Set();
|
|
203
|
+
/**
|
|
204
|
+
* All instances ever observed by this class.
|
|
205
|
+
*/
|
|
206
|
+
static all = new d();
|
|
207
|
+
}
|
|
208
|
+
function c(o) {
|
|
209
|
+
return o ? (typeof o == "string" || Array.isArray(o) ? o = { properties: h(o) } : typeof o == "object" && (o = { properties: [], ...o }), o) : {};
|
|
210
|
+
}
|
|
211
|
+
export {
|
|
212
|
+
O as default,
|
|
213
|
+
c as resolveOptions
|
|
214
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
class c {
|
|
2
|
+
/**
|
|
3
|
+
* All currently observed targets
|
|
4
|
+
* @type {WeakSet<Element>}
|
|
5
|
+
*/
|
|
6
|
+
#e = /* @__PURE__ */ new Set();
|
|
7
|
+
/**
|
|
8
|
+
* Documents to IntersectionObserver instances
|
|
9
|
+
* @type {WeakMap<Document, IntersectionObserver>}
|
|
10
|
+
*/
|
|
11
|
+
#t = /* @__PURE__ */ new WeakMap();
|
|
12
|
+
constructor(e) {
|
|
13
|
+
this.callback = e;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Begin observing the presence of an element.
|
|
17
|
+
* @param {Element} element - The element to observe.
|
|
18
|
+
*/
|
|
19
|
+
observe(e) {
|
|
20
|
+
if (this.#e.has(e))
|
|
21
|
+
return;
|
|
22
|
+
let t = e.ownerDocument, s = this.#t.get(t);
|
|
23
|
+
s || (s = new IntersectionObserver(
|
|
24
|
+
(r) => {
|
|
25
|
+
this.callback(r.map(({ target: o }) => ({ target: o })));
|
|
26
|
+
},
|
|
27
|
+
{ root: t.documentElement }
|
|
28
|
+
), this.#t.set(t, s)), this.#e.add(e), s.observe(e);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Stop observing the presence of an element.
|
|
32
|
+
* @param {Element} [element] - The element to stop observing. If not provided, all targets will be unobserved.
|
|
33
|
+
*/
|
|
34
|
+
unobserve(e) {
|
|
35
|
+
if (!e) {
|
|
36
|
+
for (const r of this.#e)
|
|
37
|
+
this.unobserve(r);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
let t = e.ownerDocument;
|
|
41
|
+
this.#t.get(t)?.unobserve(e), this.#e.delete(e);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export {
|
|
45
|
+
c as default
|
|
46
|
+
};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import h, { resolveOptions as g } from "./element-style-observer.js";
|
|
2
|
+
import { toArray as n } from "./util.js";
|
|
3
|
+
class p {
|
|
4
|
+
/**
|
|
5
|
+
* @type { WeakMap<Element, ElementStyleObserver> }
|
|
6
|
+
*/
|
|
7
|
+
elementObservers = /* @__PURE__ */ new WeakMap();
|
|
8
|
+
/**
|
|
9
|
+
* @param {StyleObserverCallback} callback
|
|
10
|
+
* @param {StyleObserverOptions | string | string[]} [options]
|
|
11
|
+
*/
|
|
12
|
+
constructor(t, e) {
|
|
13
|
+
this.callback = t, e = g(e), e.targets ??= [], e.target && e.targets.push(e.target), this.options = e, this.options.targets.length > 0 && this.options.properties.length > 0 && this.observe(this.options.targets, this.options.properties);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* @type {StyleObserverCallback}
|
|
17
|
+
*/
|
|
18
|
+
changed(t) {
|
|
19
|
+
this.callback(t);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Observe one or more targets for changes to one or more CSS properties.
|
|
23
|
+
*
|
|
24
|
+
* @overload
|
|
25
|
+
* @param {Element | Element[]} targets
|
|
26
|
+
* @param {string | string[]} properties
|
|
27
|
+
* @returns {void}
|
|
28
|
+
*
|
|
29
|
+
* @overload
|
|
30
|
+
* @param {string | string[]} properties
|
|
31
|
+
* @param {Element | Element[]} targets
|
|
32
|
+
* @returns {void}
|
|
33
|
+
*
|
|
34
|
+
* @overload
|
|
35
|
+
* @param {...(string | Element | (string | Element)[]) } propertiesOrTargets
|
|
36
|
+
* @returns {void}
|
|
37
|
+
*/
|
|
38
|
+
observe(...t) {
|
|
39
|
+
let { targets: e, properties: r } = l(...t);
|
|
40
|
+
if (e.length === 0 && (e = this.options.targets), e.length !== 0)
|
|
41
|
+
for (let i of e) {
|
|
42
|
+
let s = this.elementObservers.get(i);
|
|
43
|
+
s || (s = new h(
|
|
44
|
+
i,
|
|
45
|
+
(a) => this.changed(a),
|
|
46
|
+
this.options
|
|
47
|
+
), this.elementObservers.set(i, s)), s.observe(r);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Stop observing one or more targets for changes to one or more CSS properties.
|
|
52
|
+
*
|
|
53
|
+
* @overload
|
|
54
|
+
* @param {Element | Element[]} targets
|
|
55
|
+
* @param {string | string[]} properties
|
|
56
|
+
* @returns {void}
|
|
57
|
+
*
|
|
58
|
+
* @overload
|
|
59
|
+
* @param {string | string[]} properties
|
|
60
|
+
* @param {Element | Element[]} targets
|
|
61
|
+
* @returns {void}
|
|
62
|
+
*
|
|
63
|
+
* @overload
|
|
64
|
+
* @param {...(string | Element | (string | Element)[]) } propertiesOrTargets
|
|
65
|
+
* @returns {void}
|
|
66
|
+
*/
|
|
67
|
+
unobserve(...t) {
|
|
68
|
+
let { targets: e, properties: r } = l(...t);
|
|
69
|
+
if (e.length === 0 && (e = this.options.targets), e.length !== 0) {
|
|
70
|
+
r.length === 0 && (r = this.options.properties);
|
|
71
|
+
for (let i of e) {
|
|
72
|
+
let s = this.elementObservers.get(i);
|
|
73
|
+
s && s.unobserve(r);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Update the transition for one or more targets.
|
|
79
|
+
* @param {Element | Element[]} targets
|
|
80
|
+
* @returns {void}
|
|
81
|
+
*/
|
|
82
|
+
updateTransition(t) {
|
|
83
|
+
for (let e of n(t)) {
|
|
84
|
+
let r = this.elementObservers.get(e);
|
|
85
|
+
r && r.updateTransition();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function l(o, t) {
|
|
90
|
+
let e = [...n(o), ...n(t)];
|
|
91
|
+
o = [], t = [];
|
|
92
|
+
for (let r of e)
|
|
93
|
+
(typeof r == "string" || r instanceof String ? t : o).push(r);
|
|
94
|
+
return { targets: o, properties: t };
|
|
95
|
+
}
|
|
96
|
+
export {
|
|
97
|
+
p as default
|
|
98
|
+
};
|