le-kit 0.1.12 → 0.1.13
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 +1268 -1268
- package/dist/collection/assets/custom-elements.json +750 -750
- package/dist/components/index.d.ts +33 -0
- package/dist/components/index.js +113 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/le-box.d.ts +11 -0
- package/dist/components/le-box.js +257 -0
- package/dist/components/le-box.js.map +1 -0
- package/dist/components/le-button.d.ts +11 -0
- package/dist/components/le-button.js +9 -0
- package/dist/components/le-button.js.map +1 -0
- package/dist/components/le-button2.js +1149 -0
- package/dist/components/le-button2.js.map +1 -0
- package/dist/components/le-card.d.ts +11 -0
- package/dist/components/le-card.js +84 -0
- package/dist/components/le-card.js.map +1 -0
- package/dist/components/le-checkbox.d.ts +11 -0
- package/dist/components/le-checkbox.js +9 -0
- package/dist/components/le-checkbox.js.map +1 -0
- package/dist/components/le-component.d.ts +11 -0
- package/dist/components/le-component.js +9 -0
- package/dist/components/le-component.js.map +1 -0
- package/dist/components/le-number-input.d.ts +11 -0
- package/dist/components/le-number-input.js +272 -0
- package/dist/components/le-number-input.js.map +1 -0
- package/dist/components/le-popover.d.ts +11 -0
- package/dist/components/le-popover.js +9 -0
- package/dist/components/le-popover.js.map +1 -0
- package/dist/components/le-popover2.js +382 -0
- package/dist/components/le-popover2.js.map +1 -0
- package/dist/components/le-popup.d.ts +11 -0
- package/dist/components/le-popup.js +279 -0
- package/dist/components/le-popup.js.map +1 -0
- package/dist/components/le-round-progress.d.ts +11 -0
- package/dist/components/le-round-progress.js +135 -0
- package/dist/components/le-round-progress.js.map +1 -0
- package/dist/components/le-slot.d.ts +11 -0
- package/dist/components/le-slot.js +9 -0
- package/dist/components/le-slot.js.map +1 -0
- package/dist/components/le-stack.d.ts +11 -0
- package/dist/components/le-stack.js +199 -0
- package/dist/components/le-stack.js.map +1 -0
- package/dist/components/le-string-input.d.ts +11 -0
- package/dist/components/le-string-input.js +9 -0
- package/dist/components/le-string-input.js.map +1 -0
- package/dist/components/le-text.d.ts +11 -0
- package/dist/components/le-text.js +399 -0
- package/dist/components/le-text.js.map +1 -0
- package/dist/components/le-turntable.d.ts +11 -0
- package/dist/components/le-turntable.js +164 -0
- package/dist/components/le-turntable.js.map +1 -0
- package/dist/components/utils.js +310 -0
- package/dist/components/utils.js.map +1 -0
- package/dist/core/collection/assets/custom-elements.json +4305 -0
- package/dist/core/collection/themes/base.css +89 -0
- package/dist/core/collection/themes/dark.css +100 -0
- package/dist/core/collection/themes/default.css +108 -0
- package/dist/core/collection/themes/gradient.css +100 -0
- package/dist/core/collection/themes/index.css +413 -0
- package/dist/core/collection/themes/minimal.css +100 -0
- package/dist/core/collection/themes/warm.css +100 -0
- package/dist/core/components/index.d.ts +33 -0
- package/dist/core/components/index.js +113 -0
- package/dist/core/components/index.js.map +1 -0
- package/dist/core/components/le-box.d.ts +11 -0
- package/dist/core/components/le-box.js +225 -0
- package/dist/core/components/le-box.js.map +1 -0
- package/dist/core/components/le-button.d.ts +11 -0
- package/dist/core/components/le-button.js +9 -0
- package/dist/core/components/le-button.js.map +1 -0
- package/dist/core/components/le-button2.js +121 -0
- package/dist/core/components/le-button2.js.map +1 -0
- package/dist/core/components/le-card.d.ts +11 -0
- package/dist/core/components/le-card.js +52 -0
- package/dist/core/components/le-card.js.map +1 -0
- package/dist/core/components/le-checkbox.d.ts +11 -0
- package/dist/core/components/le-checkbox.js +87 -0
- package/dist/core/components/le-checkbox.js.map +1 -0
- package/dist/core/components/le-number-input.d.ts +11 -0
- package/dist/core/components/le-number-input.js +246 -0
- package/dist/core/components/le-number-input.js.map +1 -0
- package/dist/core/components/le-popover.d.ts +11 -0
- package/dist/core/components/le-popover.js +385 -0
- package/dist/core/components/le-popover.js.map +1 -0
- package/dist/core/components/le-popup.d.ts +11 -0
- package/dist/core/components/le-popup.js +253 -0
- package/dist/core/components/le-popup.js.map +1 -0
- package/dist/core/components/le-round-progress.d.ts +11 -0
- package/dist/core/components/le-round-progress.js +135 -0
- package/dist/core/components/le-round-progress.js.map +1 -0
- package/dist/core/components/le-stack.d.ts +11 -0
- package/dist/core/components/le-stack.js +167 -0
- package/dist/core/components/le-stack.js.map +1 -0
- package/dist/core/components/le-string-input.d.ts +11 -0
- package/dist/core/components/le-string-input.js +127 -0
- package/dist/core/components/le-string-input.js.map +1 -0
- package/dist/core/components/le-text.d.ts +11 -0
- package/dist/core/components/le-text.js +367 -0
- package/dist/core/components/le-text.js.map +1 -0
- package/dist/core/components/le-turntable.d.ts +11 -0
- package/dist/core/components/le-turntable.js +164 -0
- package/dist/core/components/le-turntable.js.map +1 -0
- package/dist/core/components/utils.js +310 -0
- package/dist/core/components/utils.js.map +1 -0
- package/dist/docs.json +1 -1
- package/dist/le-kit/assets/custom-elements.json +750 -750
- package/dist/le-kit/dist/collection/themes/base.css +89 -0
- package/dist/le-kit/dist/collection/themes/dark.css +100 -0
- package/dist/le-kit/dist/collection/themes/default.css +108 -0
- package/dist/le-kit/dist/collection/themes/gradient.css +100 -0
- package/dist/le-kit/dist/collection/themes/index.css +413 -0
- package/dist/le-kit/dist/collection/themes/minimal.css +100 -0
- package/dist/le-kit/dist/collection/themes/warm.css +100 -0
- package/package.json +2 -2
- /package/dist/{le-kit → collection/dist/collection}/themes/base.css +0 -0
- /package/dist/{le-kit → collection/dist/collection}/themes/dark.css +0 -0
- /package/dist/{le-kit → collection/dist/collection}/themes/default.css +0 -0
- /package/dist/{le-kit → collection/dist/collection}/themes/gradient.css +0 -0
- /package/dist/{le-kit → collection/dist/collection}/themes/index.css +0 -0
- /package/dist/{le-kit → collection/dist/collection}/themes/minimal.css +0 -0
- /package/dist/{le-kit → collection/dist/collection}/themes/warm.css +0 -0
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { proxyCustomElement, HTMLElement, h } from '@stencil/core/internal/client';
|
|
2
|
+
|
|
3
|
+
const leTurntableCss = ":host{display:block;cursor:grab}div.turntable{width:100%;height:100%;padding:1px}";
|
|
4
|
+
|
|
5
|
+
const LeTurntable$1 = /*@__PURE__*/ proxyCustomElement(class LeTurntable extends HTMLElement {
|
|
6
|
+
constructor(registerHost) {
|
|
7
|
+
super();
|
|
8
|
+
if (registerHost !== false) {
|
|
9
|
+
this.__registerHost();
|
|
10
|
+
}
|
|
11
|
+
this.__attachShadow();
|
|
12
|
+
}
|
|
13
|
+
get el() { return this; }
|
|
14
|
+
// transform origin
|
|
15
|
+
// gets the same values as transform-origin css property
|
|
16
|
+
center = 'center';
|
|
17
|
+
// transform rotate
|
|
18
|
+
value = 0;
|
|
19
|
+
updateValue(newValue) {
|
|
20
|
+
if (!this.rotating) {
|
|
21
|
+
this.currentAngle = parseFloat(newValue);
|
|
22
|
+
this.setAngle(this.currentAngle);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Internal state
|
|
27
|
+
*
|
|
28
|
+
* using properties instead of @State decoratorm
|
|
29
|
+
* because we are only changing styles of the element and don't
|
|
30
|
+
* need the element to be rerendered
|
|
31
|
+
*/
|
|
32
|
+
// indicates is the element being manually rotated right now
|
|
33
|
+
rotating = false;
|
|
34
|
+
// coordinates of the transform origin in pixels
|
|
35
|
+
centerX;
|
|
36
|
+
centerY;
|
|
37
|
+
// element page (body?) offset in pixels
|
|
38
|
+
pageX;
|
|
39
|
+
pageY;
|
|
40
|
+
currentAngle = 0;
|
|
41
|
+
// angle at the start of the drag
|
|
42
|
+
startAngle;
|
|
43
|
+
/**
|
|
44
|
+
* Event listeners
|
|
45
|
+
*/
|
|
46
|
+
handleMouseDown(evt) {
|
|
47
|
+
// set rotating mode on
|
|
48
|
+
this.rotating = true;
|
|
49
|
+
// get start angle
|
|
50
|
+
// getting pageX/Y, because when the element is transformed
|
|
51
|
+
// relative values are useless
|
|
52
|
+
this.startAngle = this.getAngle(evt.pageX, evt.pageY);
|
|
53
|
+
// cancel the event to prevent text selection
|
|
54
|
+
evt.preventDefault();
|
|
55
|
+
evt.stopPropagation();
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Fires when the mouse moves
|
|
60
|
+
* checks is the element rotating right now and if it is
|
|
61
|
+
* then calc the current angle and rotate the element
|
|
62
|
+
*
|
|
63
|
+
* TODO: attach events only after the dragStart?
|
|
64
|
+
*/
|
|
65
|
+
handleMouseMove(evt) {
|
|
66
|
+
if (this.rotating) {
|
|
67
|
+
// calc angle update and rotate element
|
|
68
|
+
this.setAngle(this.currentAngle + (this.getAngle(evt.pageX, evt.pageY) - this.startAngle));
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
handleMouseUp(evt) {
|
|
73
|
+
if (this.rotating) {
|
|
74
|
+
const angle = this.currentAngle + (this.getAngle(evt.pageX, evt.pageY) - this.startAngle);
|
|
75
|
+
this.setAngle(angle);
|
|
76
|
+
this.currentAngle = angle;
|
|
77
|
+
this.rotating = false;
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
// on window resize the center should be recalculated
|
|
82
|
+
handleWindowResize() {
|
|
83
|
+
this.getTransformOrigin();
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Component lifecycles
|
|
87
|
+
*/
|
|
88
|
+
componentDidLoad() {
|
|
89
|
+
this.el.style.transformOrigin = this.center;
|
|
90
|
+
this.currentAngle = this.value;
|
|
91
|
+
this.getTransformOrigin();
|
|
92
|
+
this.setAngle(this.currentAngle);
|
|
93
|
+
}
|
|
94
|
+
componentDidUpdate() {
|
|
95
|
+
this.getTransformOrigin();
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Calculates the transform origin of the component
|
|
99
|
+
* and the page offset in pixels
|
|
100
|
+
*
|
|
101
|
+
* We'll need these values to calculate the angle of pointer event
|
|
102
|
+
*/
|
|
103
|
+
getTransformOrigin() {
|
|
104
|
+
// transform origin
|
|
105
|
+
[this.centerX, this.centerY] = window
|
|
106
|
+
.getComputedStyle(this.el, null)
|
|
107
|
+
.transformOrigin.split(' ')
|
|
108
|
+
.map(val => Math.round(parseFloat(val)));
|
|
109
|
+
// page offset
|
|
110
|
+
let t = null;
|
|
111
|
+
const scrollContainer = ((t = document.documentElement) || (t = document.body.parentNode)) && typeof t.scrollLeft === 'number' ? t : document.body;
|
|
112
|
+
const clientRects = this.el.getBoundingClientRect();
|
|
113
|
+
this.pageX = Math.round(clientRects.left + scrollContainer.scrollLeft);
|
|
114
|
+
this.pageY = Math.round(clientRects.top + scrollContainer.scrollTop);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Calculates current angle
|
|
118
|
+
*
|
|
119
|
+
* @param {number} posX horizontal mouse position
|
|
120
|
+
* @param {number} posY vertical mouse position
|
|
121
|
+
*/
|
|
122
|
+
getAngle(posX, posY) {
|
|
123
|
+
const x = posX - this.pageX - this.centerX;
|
|
124
|
+
const y = posY - this.pageY - this.centerY;
|
|
125
|
+
const angle = Math.round(((Math.atan2(y, x) * 180) / Math.PI) * 100) / 100;
|
|
126
|
+
return angle;
|
|
127
|
+
}
|
|
128
|
+
setAngle(angle) {
|
|
129
|
+
this.el.style.transform = `rotate(${angle}deg)`;
|
|
130
|
+
}
|
|
131
|
+
render() {
|
|
132
|
+
return (h("div", { key: '6ac04c3dfb7d2cd26000d1497122fc8c9ba775d3', class: "turntable", onMouseDown: this.handleMouseDown.bind(this) }, h("slot", { key: '18bb701a32e9b3be8e3522351bec99b74d29335d' })));
|
|
133
|
+
}
|
|
134
|
+
static get watchers() { return {
|
|
135
|
+
"value": ["updateValue"]
|
|
136
|
+
}; }
|
|
137
|
+
static get style() { return leTurntableCss; }
|
|
138
|
+
}, [769, "le-turntable", {
|
|
139
|
+
"center": [1],
|
|
140
|
+
"value": [2]
|
|
141
|
+
}, [[9, "mousemove", "handleMouseMove"], [9, "mouseup", "handleMouseUp"], [9, "resize", "handleWindowResize"]], {
|
|
142
|
+
"value": ["updateValue"]
|
|
143
|
+
}]);
|
|
144
|
+
function defineCustomElement$1() {
|
|
145
|
+
if (typeof customElements === "undefined") {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
const components = ["le-turntable"];
|
|
149
|
+
components.forEach(tagName => { switch (tagName) {
|
|
150
|
+
case "le-turntable":
|
|
151
|
+
if (!customElements.get(tagName)) {
|
|
152
|
+
customElements.define(tagName, LeTurntable$1);
|
|
153
|
+
}
|
|
154
|
+
break;
|
|
155
|
+
} });
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const LeTurntable = LeTurntable$1;
|
|
159
|
+
const defineCustomElement = defineCustomElement$1;
|
|
160
|
+
|
|
161
|
+
export { LeTurntable, defineCustomElement };
|
|
162
|
+
//# sourceMappingURL=le-turntable.js.map
|
|
163
|
+
|
|
164
|
+
//# sourceMappingURL=le-turntable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"file":"le-turntable.js","mappings":";;AAAA,MAAM,cAAc,GAAG,mFAAmF;;MCO7FA,aAAW,iBAAAC,kBAAA,CAAA,MAAA,WAAA,SAAA,WAAA,CAAA;;;;;;;;;;;IAMd,MAAM,GAAW,QAAQ;;IAGzB,KAAK,GAAW,CAAC;AAGzB,IAAA,WAAW,CAAC,QAAQ,EAAA;AAClB,QAAA,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;AAClB,YAAA,IAAI,CAAC,YAAY,GAAG,UAAU,CAAC,QAAQ,CAAC;AACxC,YAAA,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC;;;AAIpC;;;;;;AAMG;;IAGH,QAAQ,GAAG,KAAK;;AAGhB,IAAA,OAAO;AACP,IAAA,OAAO;;AAGP,IAAA,KAAK;AACL,IAAA,KAAK;IAEL,YAAY,GAAW,CAAC;;AAExB,IAAA,UAAU;AAEV;;AAEG;AACH,IAAA,eAAe,CAAC,GAAe,EAAA;;AAE7B,QAAA,IAAI,CAAC,QAAQ,GAAG,IAAI;;;;AAKpB,QAAA,IA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;AAC1E,QAAA,OAAO,KAAK;;AAGd,IAAA,QAAQ,CAAC,KAAK,EAAA;QACZ,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,SAAS,GAAG,CAAA,OAAA,EAAU,KAAK,CAAA,IAAA,CAAM;;IAGjD,MAAM,GAAA;AACJ,QAAA,QACE,CAAA,CAAA,KAAA,EAAA,EAAA,GAAA,EAAA,0CAAA,EAAK,KAAK,EAAC,WAAW,EAAC,WAAW,EAAE,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,EAAA,EACjE,CAAQ,CAAA,MAAA,EAAA,EAAA,GAAA,EAAA,0CAAA,EAAA,CAAA,CACJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","names":["LeTurntable","__stencil_proxyCustomElement"],"sources":["src-core/components/le-turntable/le-turntable.css?tag=le-turntable&encapsulation=shadow","src-core/components/le-turntable/le-turntable.tsx"],"sourcesContent":[":host {\n display: block;\n cursor: grab;\n}\n\ndiv.turntable {\n width: 100%;\n height: 100%;\n padding: 1px;\n}\n","import { Component, Element, Prop, Listen, h, Watch } from '@stencil/core';\n\n@Component({\n tag: 'le-turntable',\n styleUrl: 'le-turntable.css',\n shadow: true,\n})\nexport class LeTurntable {\n // host element\n @Element() el: HTMLElement;\n\n // transform origin\n // gets the same values as transform-origin css property\n @Prop() center: string = 'center';\n\n // transform rotate\n @Prop() value: number = 0;\n\n @Watch('value')\n updateValue(newValue) {\n if (!this.rotating) {\n this.currentAngle = parseFloat(newValue);\n this.setAngle(this.currentAngle);\n }\n }\n\n /**\n * Internal state\n *\n * using properties instead of @State decoratorm\n * because we are only changing styles of the element and don't\n * need the element to be rerendered\n */\n\n // indicates is the element being manually rotated right now\n rotating = false;\n\n // coordinates of the transform origin in pixels\n centerX: number;\n centerY: number;\n\n // element page (body?) offset in pixels\n pageX: number;\n pageY: number;\n\n currentAngle: number = 0;\n // angle at the start of the drag\n startAngle: number;\n\n /**\n * Event listeners\n */\n handleMouseDown(evt: MouseEvent) {\n // set rotating mode on\n this.rotating = true;\n\n // get start angle\n // getting pageX/Y, because when the element is transformed\n // relative values are useless\n this.startAngle = this.getAngle(evt.pageX, evt.pageY);\n\n // cancel the event to prevent text selection\n evt.preventDefault();\n evt.stopPropagation();\n return false;\n }\n\n /**\n * Fires when the mouse moves\n * checks is the element rotating right now and if it is\n * then calc the current angle and rotate the element\n *\n * TODO: attach events only after the dragStart?\n */\n @Listen('mousemove', { target: 'window' })\n handleMouseMove(evt: MouseEvent) {\n if (this.rotating) {\n // calc angle update and rotate element\n this.setAngle(this.currentAngle + (this.getAngle(evt.pageX, evt.pageY) - this.startAngle));\n return false;\n }\n }\n\n @Listen('mouseup', { target: 'window' })\n handleMouseUp(evt: MouseEvent) {\n if (this.rotating) {\n const angle = this.currentAngle + (this.getAngle(evt.pageX, evt.pageY) - this.startAngle);\n this.setAngle(angle);\n this.currentAngle = angle;\n this.rotating = false;\n return false;\n }\n }\n\n // on window resize the center should be recalculated\n @Listen('resize', { target: 'window' })\n handleWindowResize() {\n this.getTransformOrigin();\n }\n\n /**\n * Component lifecycles\n */\n componentDidLoad() {\n this.el.style.transformOrigin = this.center;\n this.currentAngle = this.value;\n\n this.getTransformOrigin();\n this.setAngle(this.currentAngle);\n }\n\n componentDidUpdate() {\n this.getTransformOrigin();\n }\n\n /**\n * Calculates the transform origin of the component\n * and the page offset in pixels\n *\n * We'll need these values to calculate the angle of pointer event\n */\n getTransformOrigin() {\n // transform origin\n [this.centerX, this.centerY] = window\n .getComputedStyle(this.el, null)\n .transformOrigin.split(' ')\n .map(val => Math.round(parseFloat(val)));\n // page offset\n let t = null;\n const scrollContainer = ((t = document.documentElement) || (t = document.body.parentNode)) && typeof t.scrollLeft === 'number' ? t : document.body;\n const clientRects = this.el.getBoundingClientRect();\n this.pageX = Math.round(clientRects.left + scrollContainer.scrollLeft);\n this.pageY = Math.round(clientRects.top + scrollContainer.scrollTop);\n }\n\n /**\n * Calculates current angle\n *\n * @param {number} posX horizontal mouse position\n * @param {number} posY vertical mouse position\n */\n getAngle(posX: number, posY: number) {\n const x = posX - this.pageX - this.centerX;\n const y = posY - this.pageY - this.centerY;\n const angle = Math.round(((Math.atan2(y, x) * 180) / Math.PI) * 100) / 100;\n return angle;\n }\n\n setAngle(angle) {\n this.el.style.transform = `rotate(${angle}deg)`;\n }\n\n render() {\n return (\n <div class=\"turntable\" onMouseDown={this.handleMouseDown.bind(this)}>\n <slot />\n </div>\n );\n }\n}\n"],"version":3}
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
import { setMode } from '@stencil/core/internal/client';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Global mode initialization for le-kit components.
|
|
5
|
+
*
|
|
6
|
+
* Mode inheritance works as follows:
|
|
7
|
+
* 1. Check the element's own `mode` attribute
|
|
8
|
+
* 2. Traverse up the DOM to find a parent with `mode` attribute
|
|
9
|
+
* 3. Check the document root element (html) for `mode` attribute
|
|
10
|
+
* 4. Fall back to 'default'
|
|
11
|
+
*
|
|
12
|
+
* This allows setting mode at any level:
|
|
13
|
+
* - `<html mode="admin">` - all components in admin mode
|
|
14
|
+
* - `<le-card mode="admin">` - this card and its children in admin mode
|
|
15
|
+
*/
|
|
16
|
+
function initializeMode() {
|
|
17
|
+
setMode((el) => {
|
|
18
|
+
// 1. Check element's own mode attribute
|
|
19
|
+
const ownMode = el.getAttribute('mode');
|
|
20
|
+
if (ownMode) {
|
|
21
|
+
return ownMode;
|
|
22
|
+
}
|
|
23
|
+
// 2. Traverse up the DOM tree to find inherited mode
|
|
24
|
+
let parent = el.parentElement;
|
|
25
|
+
while (parent) {
|
|
26
|
+
const parentMode = parent.getAttribute('mode');
|
|
27
|
+
if (parentMode) {
|
|
28
|
+
return parentMode;
|
|
29
|
+
}
|
|
30
|
+
parent = parent.parentElement;
|
|
31
|
+
}
|
|
32
|
+
// 3. Check document root element
|
|
33
|
+
const rootMode = document.documentElement.getAttribute('mode');
|
|
34
|
+
if (rootMode) {
|
|
35
|
+
return rootMode;
|
|
36
|
+
}
|
|
37
|
+
// 4. Default mode
|
|
38
|
+
return 'default';
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Helper function to get the current mode for an element.
|
|
43
|
+
* Can be used programmatically in components.
|
|
44
|
+
*
|
|
45
|
+
* This function traverses both regular DOM and shadow DOM boundaries
|
|
46
|
+
* to find the nearest mode attribute.
|
|
47
|
+
*/
|
|
48
|
+
function getMode(el) {
|
|
49
|
+
// Check element's own mode
|
|
50
|
+
const ownMode = el.getAttribute('mode');
|
|
51
|
+
if (ownMode) {
|
|
52
|
+
return ownMode;
|
|
53
|
+
}
|
|
54
|
+
// Traverse up DOM, crossing shadow boundaries
|
|
55
|
+
let current = el;
|
|
56
|
+
while (current) {
|
|
57
|
+
// Try parent element first
|
|
58
|
+
if (current instanceof Element && current.parentElement) {
|
|
59
|
+
current = current.parentElement;
|
|
60
|
+
const mode = current.getAttribute?.('mode');
|
|
61
|
+
if (mode) {
|
|
62
|
+
return mode;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
// No parent element - check if we're in a shadow root
|
|
67
|
+
const root = current.getRootNode();
|
|
68
|
+
if (root instanceof ShadowRoot) {
|
|
69
|
+
// Cross the shadow boundary to the host element
|
|
70
|
+
current = root.host;
|
|
71
|
+
const mode = current.getAttribute?.('mode');
|
|
72
|
+
if (mode) {
|
|
73
|
+
return mode;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
// We've reached the document root
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
// Check document root
|
|
83
|
+
const rootMode = document.documentElement.getAttribute('mode');
|
|
84
|
+
if (rootMode) {
|
|
85
|
+
return rootMode;
|
|
86
|
+
}
|
|
87
|
+
return 'default';
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Helper function to get the current theme for an element.
|
|
91
|
+
* Theme inheritance works the same as mode - cascades through DOM.
|
|
92
|
+
*/
|
|
93
|
+
function getTheme(el) {
|
|
94
|
+
// Check element's own theme
|
|
95
|
+
const ownTheme = el.getAttribute('theme');
|
|
96
|
+
if (ownTheme) {
|
|
97
|
+
return ownTheme;
|
|
98
|
+
}
|
|
99
|
+
// Traverse up DOM
|
|
100
|
+
let parent = el.parentElement;
|
|
101
|
+
while (parent) {
|
|
102
|
+
const parentTheme = parent.getAttribute('theme');
|
|
103
|
+
if (parentTheme) {
|
|
104
|
+
return parentTheme;
|
|
105
|
+
}
|
|
106
|
+
parent = parent.parentElement;
|
|
107
|
+
}
|
|
108
|
+
// Check root
|
|
109
|
+
const rootTheme = document.documentElement.getAttribute('theme');
|
|
110
|
+
if (rootTheme) {
|
|
111
|
+
return rootTheme;
|
|
112
|
+
}
|
|
113
|
+
return 'default';
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Helper function to set mode on the document root.
|
|
117
|
+
* Useful for switching all components to admin mode.
|
|
118
|
+
*/
|
|
119
|
+
function setGlobalMode(mode) {
|
|
120
|
+
document.documentElement.setAttribute('mode', mode);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Helper function to set theme on the document root.
|
|
124
|
+
* Useful for switching all components to a different theme.
|
|
125
|
+
*/
|
|
126
|
+
function setGlobalTheme(theme) {
|
|
127
|
+
document.documentElement.setAttribute('theme', theme);
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Global configuration for le-kit
|
|
131
|
+
*/
|
|
132
|
+
let leKitConfig = {
|
|
133
|
+
/**
|
|
134
|
+
* URL to the custom-elements.json manifest.
|
|
135
|
+
* Used by admin components (le-component, le-slot) to load component metadata.
|
|
136
|
+
*
|
|
137
|
+
* Default: '/custom-elements.json' (served from app root)
|
|
138
|
+
*
|
|
139
|
+
* For apps using le-kit, you may need to:
|
|
140
|
+
* 1. Copy the manifest from node_modules/le-kit/custom-elements.json to your public folder
|
|
141
|
+
* 2. Or set this to point to where the manifest is served
|
|
142
|
+
*/
|
|
143
|
+
manifestUrl: '/custom-elements.json',
|
|
144
|
+
};
|
|
145
|
+
/**
|
|
146
|
+
* Configure le-kit global settings.
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```ts
|
|
150
|
+
* import { configureLeki } from 'le-kit';
|
|
151
|
+
*
|
|
152
|
+
* configureLeki({
|
|
153
|
+
* manifestUrl: '/assets/custom-elements.json'
|
|
154
|
+
* });
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
function configureLeKit(config) {
|
|
158
|
+
leKitConfig = { ...leKitConfig, ...config };
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Get the current le-kit configuration.
|
|
162
|
+
*/
|
|
163
|
+
function getLeKitConfig() {
|
|
164
|
+
return leKitConfig;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Utility functions for le-kit components
|
|
169
|
+
*/
|
|
170
|
+
/**
|
|
171
|
+
* Generates a unique ID for component instances
|
|
172
|
+
*/
|
|
173
|
+
function generateId(prefix = 'le') {
|
|
174
|
+
return `${prefix}-${Math.random().toString(36).substring(2, 9)}`;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Parses a comma-separated string into an array
|
|
178
|
+
*/
|
|
179
|
+
function parseCommaSeparated(value) {
|
|
180
|
+
if (!value)
|
|
181
|
+
return [];
|
|
182
|
+
return value
|
|
183
|
+
.split(',')
|
|
184
|
+
.map(s => s.trim())
|
|
185
|
+
.filter(Boolean);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Checks if a slot has content
|
|
189
|
+
*/
|
|
190
|
+
function slotHasContent(el, slotName = '') {
|
|
191
|
+
const selector = slotName ? `[slot="${slotName}"]` : ':not([slot])';
|
|
192
|
+
return el.querySelector(selector) !== null;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Sets up a MutationObserver to track mode changes on ancestor elements.
|
|
196
|
+
* Returns a cleanup function to disconnect the observer.
|
|
197
|
+
*
|
|
198
|
+
* If the element or any ancestor has an explicit `mode` attribute, that creates
|
|
199
|
+
* a "mode boundary" - the mode is determined from that point, not from further up.
|
|
200
|
+
* This allows components like le-popover to force default mode for their children.
|
|
201
|
+
*
|
|
202
|
+
* @param el - The component's host element
|
|
203
|
+
* @param callback - Function to call when mode changes, receives the new mode
|
|
204
|
+
* @returns Cleanup function to disconnect the observer
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* ```tsx
|
|
208
|
+
* export class MyComponent {
|
|
209
|
+
* @Element() el: HTMLElement;
|
|
210
|
+
* @State() adminMode: boolean = false;
|
|
211
|
+
* private disconnectModeObserver?: () => void;
|
|
212
|
+
*
|
|
213
|
+
* connectedCallback() {
|
|
214
|
+
* this.disconnectModeObserver = observeModeChanges(this.el, (mode) => {
|
|
215
|
+
* this.adminMode = mode === 'admin';
|
|
216
|
+
* });
|
|
217
|
+
* }
|
|
218
|
+
*
|
|
219
|
+
* disconnectedCallback() {
|
|
220
|
+
* this.disconnectModeObserver?.();
|
|
221
|
+
* }
|
|
222
|
+
* }
|
|
223
|
+
* ```
|
|
224
|
+
*/
|
|
225
|
+
function observeModeChanges(el, callback) {
|
|
226
|
+
// Call immediately with current mode
|
|
227
|
+
callback(getMode(el));
|
|
228
|
+
// Set up observer for mode attribute changes
|
|
229
|
+
const observer = new MutationObserver(() => {
|
|
230
|
+
callback(getMode(el));
|
|
231
|
+
});
|
|
232
|
+
// Observe the element itself (for mode boundary changes)
|
|
233
|
+
observer.observe(el, {
|
|
234
|
+
attributes: true,
|
|
235
|
+
attributeFilter: ['mode'],
|
|
236
|
+
});
|
|
237
|
+
// Observe document root
|
|
238
|
+
observer.observe(document.documentElement, {
|
|
239
|
+
attributes: true,
|
|
240
|
+
attributeFilter: ['mode'],
|
|
241
|
+
});
|
|
242
|
+
// Traverse up, crossing shadow boundaries, and observe each element
|
|
243
|
+
let current = el;
|
|
244
|
+
while (current) {
|
|
245
|
+
if (current instanceof Element && current.parentElement) {
|
|
246
|
+
current = current.parentElement;
|
|
247
|
+
observer.observe(current, {
|
|
248
|
+
attributes: true,
|
|
249
|
+
attributeFilter: ['mode'],
|
|
250
|
+
});
|
|
251
|
+
// If this element has an explicit mode, it's a boundary
|
|
252
|
+
if (current.hasAttribute('mode')) {
|
|
253
|
+
break;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
// Check if we're in a shadow root
|
|
258
|
+
const root = current.getRootNode();
|
|
259
|
+
if (root instanceof ShadowRoot) {
|
|
260
|
+
// Cross the shadow boundary and observe the host
|
|
261
|
+
current = root.host;
|
|
262
|
+
observer.observe(current, {
|
|
263
|
+
attributes: true,
|
|
264
|
+
attributeFilter: ['mode'],
|
|
265
|
+
});
|
|
266
|
+
// If the host has an explicit mode, it's a boundary
|
|
267
|
+
if (current.hasAttribute('mode')) {
|
|
268
|
+
break;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
272
|
+
break;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
// Return cleanup function
|
|
277
|
+
return () => observer.disconnect();
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Combines multiple class names into a single string, filtering out falsy values.
|
|
281
|
+
*
|
|
282
|
+
* @param classes - arguments of class names, undefined, arrays, objects with boolean values and nested combinations of these
|
|
283
|
+
* @returns Combined class names string
|
|
284
|
+
*/
|
|
285
|
+
function classnames(...classes) {
|
|
286
|
+
const result = [];
|
|
287
|
+
classes.forEach(cls => {
|
|
288
|
+
if (!cls)
|
|
289
|
+
return;
|
|
290
|
+
if (typeof cls === 'string') {
|
|
291
|
+
result.push(cls);
|
|
292
|
+
}
|
|
293
|
+
else if (Array.isArray(cls)) {
|
|
294
|
+
result.push(classnames(...cls));
|
|
295
|
+
}
|
|
296
|
+
else if (typeof cls === 'object') {
|
|
297
|
+
Object.entries(cls).forEach(([key, value]) => {
|
|
298
|
+
if (value) {
|
|
299
|
+
result.push(key);
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
});
|
|
304
|
+
return result.join(' ');
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
export { getMode as a, setGlobalMode as b, getTheme as c, setGlobalTheme as d, configureLeKit as e, getLeKitConfig as f, generateId as g, classnames as h, initializeMode as i, observeModeChanges as o, parseCommaSeparated as p, slotHasContent as s };
|
|
308
|
+
//# sourceMappingURL=utils.js.map
|
|
309
|
+
|
|
310
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"file":"utils.js","mappings":";;AAKA;;;;;;;;;;;;AAYG;AACH,SAAS,cAAc,GAAA;AACrB,IAAA,OAAO,CAAC,CAAC,EAAe,KAAe;;QAErC,MAAM,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,MAAM,CAAC;QACvC,IAAI,OAAO,EAAE;AACX,YAAA,OAAO,OAAoB;;;AAI7B,QAAA,IAAI,MAAM,GAAG,EAAE,CAAC,aAAa;QAC7B,OAAO,MAAM,EAAE;YACb,MAAM,UAAU,GAAG,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC;YAC9C,IAAI,UAAU,EAAE;AACd,gBAAA,OAAO,UAAuB;;AAEhC,YAAA,MAAM,GAAG,MAAM,CAAC,aAAa;;;QAI/B,MAAM,QAAQ,GAAG,QAAQ,CAAC,eAAe,CAAC,YAAY,CAAC,MAAM,CAAC;QAC9D,IAAI,QAAQ,EAAE;AACZ,YAAA,OAAO,QAAqB;;;AAI9B,QAAA,OAAO,SAAS;AAClB,KAAC,CAAC;AACJ;AAKA;;;;;;AAMG;AACG,SAAU,OAAO,CAAC,EAAe,EAAA;;IAErC,MAAM,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,MAAM,CAAC;IACvC,IAAI,OAAO,EAAE;AACX,QAAA,OAAO,OAAoB;;;IAI7B,I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C,MAAM,CAAC;AAC1B,iBAAA,CAAC;;AAEF,gBAAA,IAAK,OAAmB,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE;oBAC7C;;;iBAEG;gBACL;;;;;AAMN,IAAA,OAAO,MAAM,QAAQ,CAAC,UAAU,EAAE;AACpC;AAEA;;;;;AAKG;AACa,SAAA,UAAU,CAAC,GAAG,OAAc,EAAA;IAC1C,MAAM,MAAM,GAAa,EAAE;AAE3B,IAAA,OAAO,CAAC,OAAO,CAAC,GAAG,IAAG;AACpB,QAAA,IAAI,CAAC,GAAG;YAAE;AAEV,QAAA,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;AAC3B,YAAA,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC;;AACX,aAAA,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;YAC7B,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,GAAG,CAAC,CAAC;;AAC1B,aAAA,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;AAClC,YAAA,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,KAAI;gBAC3C,IAAI,KAAK,EAAE;AACT,oBAAA,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC;;AAEpB,aAAC,CAAC;;AAEN,KAAC,CAAC;AAEF,IAAA,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC;AACzB;;;;","names":[],"sources":["src-core/global/app.ts","src-core/utils/utils.ts"],"sourcesContent":["import { setMode } from '@stencil/core';\n\nexport type LeKitMode = 'default' | 'admin' | string;\nexport type LeKitTheme = 'default' | 'dark' | string;\n\n/**\n * Global mode initialization for le-kit components.\n *\n * Mode inheritance works as follows:\n * 1. Check the element's own `mode` attribute\n * 2. Traverse up the DOM to find a parent with `mode` attribute\n * 3. Check the document root element (html) for `mode` attribute\n * 4. Fall back to 'default'\n *\n * This allows setting mode at any level:\n * - `<html mode=\"admin\">` - all components in admin mode\n * - `<le-card mode=\"admin\">` - this card and its children in admin mode\n */\nfunction initializeMode() {\n setMode((el: HTMLElement): LeKitMode => {\n // 1. Check element's own mode attribute\n const ownMode = el.getAttribute('mode');\n if (ownMode) {\n return ownMode as LeKitMode;\n }\n\n // 2. Traverse up the DOM tree to find inherited mode\n let parent = el.parentElement;\n while (parent) {\n const parentMode = parent.getAttribute('mode');\n if (parentMode) {\n return parentMode as LeKitMode;\n }\n parent = parent.parentElement;\n }\n\n // 3. Check document root element\n const rootMode = document.documentElement.getAttribute('mode');\n if (rootMode) {\n return rootMode as LeKitMode;\n }\n\n // 4. Default mode\n return 'default';\n });\n}\n\n// Default export for Stencil global script\nexport default initializeMode;\n\n/**\n * Helper function to get the current mode for an element.\n * Can be used programmatically in components.\n * \n * This function traverses both regular DOM and shadow DOM boundaries\n * to find the nearest mode attribute.\n */\nexport function getMode(el: HTMLElement): LeKitMode {\n // Check element's own mode\n const ownMode = el.getAttribute('mode');\n if (ownMode) {\n return ownMode as LeKitMode;\n }\n\n // Traverse up DOM, crossing shadow boundaries\n let current: Node | null = el;\n while (current) {\n // Try parent element first\n if (current instanceof Element && current.parentElement) {\n current = current.parentElement;\n const mode = (current as HTMLElement).getAttribute?.('mode');\n if (mode) {\n return mode as LeKitMode;\n }\n } else {\n // No parent element - check if we're in a shadow root\n const root = current.getRootNode();\n if (root instanceof ShadowRoot) {\n // Cross the shadow boundary to the host element\n current = root.host;\n const mode = (current as HTMLElement).getAttribute?.('mode');\n if (mode) {\n return mode as LeKitMode;\n }\n } else {\n // We've reached the document root\n break;\n }\n }\n }\n\n // Check document root\n const rootMode = document.documentElement.getAttribute('mode');\n if (rootMode) {\n return rootMode as LeKitMode;\n }\n\n return 'default';\n}\n\n/**\n * Helper function to get the current theme for an element.\n * Theme inheritance works the same as mode - cascades through DOM.\n */\nexport function getTheme(el: HTMLElement): LeKitTheme {\n // Check element's own theme\n const ownTheme = el.getAttribute('theme');\n if (ownTheme) {\n return ownTheme as LeKitTheme;\n }\n\n // Traverse up DOM\n let parent = el.parentElement;\n while (parent) {\n const parentTheme = parent.getAttribute('theme');\n if (parentTheme) {\n return parentTheme as LeKitTheme;\n }\n parent = parent.parentElement;\n }\n\n // Check root\n const rootTheme = document.documentElement.getAttribute('theme');\n if (rootTheme) {\n return rootTheme as LeKitTheme;\n }\n\n return 'default';\n}\n\n/**\n * Helper function to set mode on the document root.\n * Useful for switching all components to admin mode.\n */\nexport function setGlobalMode(mode: LeKitMode): void {\n document.documentElement.setAttribute('mode', mode);\n}\n\n/**\n * Helper function to set theme on the document root.\n * Useful for switching all components to a different theme.\n */\nexport function setGlobalTheme(theme: LeKitTheme): void {\n document.documentElement.setAttribute('theme', theme);\n}\n\n/**\n * Global configuration for le-kit\n */\nlet leKitConfig = {\n /**\n * URL to the custom-elements.json manifest.\n * Used by admin components (le-component, le-slot) to load component metadata.\n * \n * Default: '/custom-elements.json' (served from app root)\n * \n * For apps using le-kit, you may need to:\n * 1. Copy the manifest from node_modules/le-kit/custom-elements.json to your public folder\n * 2. Or set this to point to where the manifest is served\n */\n manifestUrl: '/custom-elements.json',\n};\n\n/**\n * Configure le-kit global settings.\n * \n * @example\n * ```ts\n * import { configureLeki } from 'le-kit';\n * \n * configureLeki({\n * manifestUrl: '/assets/custom-elements.json'\n * });\n * ```\n */\nexport function configureLeKit(config: Partial<typeof leKitConfig>): void {\n leKitConfig = { ...leKitConfig, ...config };\n}\n\n/**\n * Get the current le-kit configuration.\n */\nexport function getLeKitConfig(): typeof leKitConfig {\n return leKitConfig;\n}\n","/**\n * Utility functions for le-kit components\n */\n\nimport { getMode } from '../global/app';\n\n/**\n * Generates a unique ID for component instances\n */\nexport function generateId(prefix: string = 'le'): string {\n return `${prefix}-${Math.random().toString(36).substring(2, 9)}`;\n}\n\n/**\n * Parses a comma-separated string into an array\n */\nexport function parseCommaSeparated(value: string | undefined): string[] {\n if (!value) return [];\n return value\n .split(',')\n .map(s => s.trim())\n .filter(Boolean);\n}\n\n/**\n * Checks if a slot has content\n */\nexport function slotHasContent(el: HTMLElement, slotName: string = ''): boolean {\n const selector = slotName ? `[slot=\"${slotName}\"]` : ':not([slot])';\n return el.querySelector(selector) !== null;\n}\n\n/**\n * Sets up a MutationObserver to track mode changes on ancestor elements.\n * Returns a cleanup function to disconnect the observer.\n * \n * If the element or any ancestor has an explicit `mode` attribute, that creates\n * a \"mode boundary\" - the mode is determined from that point, not from further up.\n * This allows components like le-popover to force default mode for their children.\n * \n * @param el - The component's host element\n * @param callback - Function to call when mode changes, receives the new mode\n * @returns Cleanup function to disconnect the observer\n * \n * @example\n * ```tsx\n * export class MyComponent {\n * @Element() el: HTMLElement;\n * @State() adminMode: boolean = false;\n * private disconnectModeObserver?: () => void;\n * \n * connectedCallback() {\n * this.disconnectModeObserver = observeModeChanges(this.el, (mode) => {\n * this.adminMode = mode === 'admin';\n * });\n * }\n * \n * disconnectedCallback() {\n * this.disconnectModeObserver?.();\n * }\n * }\n * ```\n */\nexport function observeModeChanges(\n el: HTMLElement,\n callback: (mode: string) => void\n): () => void {\n // Call immediately with current mode\n callback(getMode(el));\n\n // Set up observer for mode attribute changes\n const observer = new MutationObserver(() => {\n callback(getMode(el));\n });\n\n // Observe the element itself (for mode boundary changes)\n observer.observe(el, {\n attributes: true,\n attributeFilter: ['mode'],\n });\n\n // Observe document root\n observer.observe(document.documentElement, {\n attributes: true,\n attributeFilter: ['mode'],\n });\n\n // Traverse up, crossing shadow boundaries, and observe each element\n let current: Node | null = el;\n while (current) {\n if (current instanceof Element && current.parentElement) {\n current = current.parentElement;\n observer.observe(current, {\n attributes: true,\n attributeFilter: ['mode'],\n });\n // If this element has an explicit mode, it's a boundary\n if ((current as Element).hasAttribute('mode')) {\n break;\n }\n } else {\n // Check if we're in a shadow root\n const root = current.getRootNode();\n if (root instanceof ShadowRoot) {\n // Cross the shadow boundary and observe the host\n current = root.host;\n observer.observe(current, {\n attributes: true,\n attributeFilter: ['mode'],\n });\n // If the host has an explicit mode, it's a boundary\n if ((current as Element).hasAttribute('mode')) {\n break;\n }\n } else {\n break;\n }\n }\n }\n\n // Return cleanup function\n return () => observer.disconnect();\n}\n\n/**\n * Combines multiple class names into a single string, filtering out falsy values.\n * \n * @param classes - arguments of class names, undefined, arrays, objects with boolean values and nested combinations of these\n * @returns Combined class names string\n */\nexport function classnames(...classes: any[]): string {\n const result: string[] = [];\n\n classes.forEach(cls => {\n if (!cls) return;\n\n if (typeof cls === 'string') {\n result.push(cls);\n } else if (Array.isArray(cls)) {\n result.push(classnames(...cls));\n } else if (typeof cls === 'object') {\n Object.entries(cls).forEach(([key, value]) => {\n if (value) {\n result.push(key);\n }\n });\n }\n });\n\n return result.join(' ');\n}\n"],"version":3}
|
package/dist/docs.json
CHANGED