@mcp-b/wc-support 0.2.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/LICENSE +21 -0
- package/dist/base/sigvelo-element.d.ts +80 -0
- package/dist/base/sigvelo-element.d.ts.map +1 -0
- package/dist/base/sigvelo-element.js +147 -0
- package/dist/base/sigvelo-element.js.map +1 -0
- package/dist/cem-plugins/type-references.d.ts +64 -0
- package/dist/cem-plugins/type-references.d.ts.map +1 -0
- package/dist/cem-plugins/type-references.js +242 -0
- package/dist/cem-plugins/type-references.js.map +1 -0
- package/dist/events/activate.d.ts +25 -0
- package/dist/events/activate.d.ts.map +1 -0
- package/dist/events/activate.js +25 -0
- package/dist/events/activate.js.map +1 -0
- package/dist/events/animation.d.ts +10 -0
- package/dist/events/animation.d.ts.map +1 -0
- package/dist/events/animation.js +7 -0
- package/dist/events/animation.js.map +1 -0
- package/dist/events/content.d.ts +15 -0
- package/dist/events/content.d.ts.map +1 -0
- package/dist/events/content.js +8 -0
- package/dist/events/content.js.map +1 -0
- package/dist/events/copy.d.ts +25 -0
- package/dist/events/copy.d.ts.map +1 -0
- package/dist/events/copy.js +15 -0
- package/dist/events/copy.js.map +1 -0
- package/dist/events/expand-collapse.d.ts +38 -0
- package/dist/events/expand-collapse.d.ts.map +1 -0
- package/dist/events/expand-collapse.js +37 -0
- package/dist/events/expand-collapse.js.map +1 -0
- package/dist/events/filter.d.ts +13 -0
- package/dist/events/filter.d.ts.map +1 -0
- package/dist/events/filter.js +12 -0
- package/dist/events/filter.js.map +1 -0
- package/dist/events/flip.d.ts +15 -0
- package/dist/events/flip.d.ts.map +1 -0
- package/dist/events/flip.js +13 -0
- package/dist/events/flip.js.map +1 -0
- package/dist/events/form.d.ts +29 -0
- package/dist/events/form.d.ts.map +1 -0
- package/dist/events/form.js +31 -0
- package/dist/events/form.js.map +1 -0
- package/dist/events/include.d.ts +28 -0
- package/dist/events/include.d.ts.map +1 -0
- package/dist/events/include.js +15 -0
- package/dist/events/include.js.map +1 -0
- package/dist/events/index.d.ts +23 -0
- package/dist/events/index.d.ts.map +1 -0
- package/dist/events/index.js +23 -0
- package/dist/events/index.js.map +1 -0
- package/dist/events/intersect.d.ts +15 -0
- package/dist/events/intersect.d.ts.map +1 -0
- package/dist/events/intersect.js +8 -0
- package/dist/events/intersect.js.map +1 -0
- package/dist/events/item.d.ts +18 -0
- package/dist/events/item.d.ts.map +1 -0
- package/dist/events/item.js +13 -0
- package/dist/events/item.js.map +1 -0
- package/dist/events/load.d.ts +25 -0
- package/dist/events/load.d.ts.map +1 -0
- package/dist/events/load.js +24 -0
- package/dist/events/load.js.map +1 -0
- package/dist/events/mutation.d.ts +15 -0
- package/dist/events/mutation.d.ts.map +1 -0
- package/dist/events/mutation.js +8 -0
- package/dist/events/mutation.js.map +1 -0
- package/dist/events/open-close.d.ts +38 -0
- package/dist/events/open-close.d.ts.map +1 -0
- package/dist/events/open-close.js +33 -0
- package/dist/events/open-close.js.map +1 -0
- package/dist/events/page.d.ts +24 -0
- package/dist/events/page.d.ts.map +1 -0
- package/dist/events/page.js +17 -0
- package/dist/events/page.js.map +1 -0
- package/dist/events/progress.d.ts +15 -0
- package/dist/events/progress.d.ts.map +1 -0
- package/dist/events/progress.js +8 -0
- package/dist/events/progress.js.map +1 -0
- package/dist/events/resize.d.ts +15 -0
- package/dist/events/resize.d.ts.map +1 -0
- package/dist/events/resize.js +8 -0
- package/dist/events/resize.js.map +1 -0
- package/dist/events/row.d.ts +19 -0
- package/dist/events/row.d.ts.map +1 -0
- package/dist/events/row.js +8 -0
- package/dist/events/row.js.map +1 -0
- package/dist/events/select.d.ts +16 -0
- package/dist/events/select.d.ts.map +1 -0
- package/dist/events/select.js +8 -0
- package/dist/events/select.js.map +1 -0
- package/dist/events/tabs.d.ts +32 -0
- package/dist/events/tabs.d.ts.map +1 -0
- package/dist/events/tabs.js +21 -0
- package/dist/events/tabs.js.map +1 -0
- package/dist/events/time.d.ts +15 -0
- package/dist/events/time.d.ts.map +1 -0
- package/dist/events/time.js +13 -0
- package/dist/events/time.js.map +1 -0
- package/dist/events/transition.d.ts +10 -0
- package/dist/events/transition.d.ts.map +1 -0
- package/dist/events/transition.js +7 -0
- package/dist/events/transition.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/prefix.d.ts +16 -0
- package/dist/prefix.d.ts.map +1 -0
- package/dist/prefix.js +22 -0
- package/dist/prefix.js.map +1 -0
- package/dist/styles/form-control.styles.d.ts +9 -0
- package/dist/styles/form-control.styles.d.ts.map +1 -0
- package/dist/styles/form-control.styles.js +337 -0
- package/dist/styles/form-control.styles.js.map +1 -0
- package/dist/styles/host.styles.d.ts +4 -0
- package/dist/styles/host.styles.d.ts.map +1 -0
- package/dist/styles/host.styles.js +33 -0
- package/dist/styles/host.styles.js.map +1 -0
- package/dist/utilities/active-element.d.ts +7 -0
- package/dist/utilities/active-element.d.ts.map +1 -0
- package/dist/utilities/active-element.js +16 -0
- package/dist/utilities/active-element.js.map +1 -0
- package/dist/utilities/animate.d.ts +25 -0
- package/dist/utilities/animate.d.ts.map +1 -0
- package/dist/utilities/animate.js +58 -0
- package/dist/utilities/animate.js.map +1 -0
- package/dist/utilities/defined.d.ts +37 -0
- package/dist/utilities/defined.d.ts.map +1 -0
- package/dist/utilities/defined.js +42 -0
- package/dist/utilities/defined.js.map +1 -0
- package/dist/utilities/drag.d.ts +45 -0
- package/dist/utilities/drag.d.ts.map +1 -0
- package/dist/utilities/drag.js +106 -0
- package/dist/utilities/drag.js.map +1 -0
- package/dist/utilities/html.d.ts +5 -0
- package/dist/utilities/html.d.ts.map +1 -0
- package/dist/utilities/html.js +41 -0
- package/dist/utilities/html.js.map +1 -0
- package/dist/utilities/icon-library.d.ts +28 -0
- package/dist/utilities/icon-library.d.ts.map +1 -0
- package/dist/utilities/icon-library.js +36 -0
- package/dist/utilities/icon-library.js.map +1 -0
- package/dist/utilities/index.d.ts +16 -0
- package/dist/utilities/index.d.ts.map +1 -0
- package/dist/utilities/index.js +16 -0
- package/dist/utilities/index.js.map +1 -0
- package/dist/utilities/library.d.ts +19 -0
- package/dist/utilities/library.d.ts.map +1 -0
- package/dist/utilities/library.js +45 -0
- package/dist/utilities/library.js.map +1 -0
- package/dist/utilities/loader.d.ts +36 -0
- package/dist/utilities/loader.d.ts.map +1 -0
- package/dist/utilities/loader.js +139 -0
- package/dist/utilities/loader.js.map +1 -0
- package/dist/utilities/localize.d.ts +62 -0
- package/dist/utilities/localize.d.ts.map +1 -0
- package/dist/utilities/localize.js +128 -0
- package/dist/utilities/localize.js.map +1 -0
- package/dist/utilities/long-press.d.ts +67 -0
- package/dist/utilities/long-press.d.ts.map +1 -0
- package/dist/utilities/long-press.js +125 -0
- package/dist/utilities/long-press.js.map +1 -0
- package/dist/utilities/math.d.ts +9 -0
- package/dist/utilities/math.d.ts.map +1 -0
- package/dist/utilities/math.js +25 -0
- package/dist/utilities/math.js.map +1 -0
- package/dist/utilities/parse.d.ts +5 -0
- package/dist/utilities/parse.d.ts.map +1 -0
- package/dist/utilities/parse.js +10 -0
- package/dist/utilities/parse.js.map +1 -0
- package/dist/utilities/platform.d.ts +10 -0
- package/dist/utilities/platform.d.ts.map +1 -0
- package/dist/utilities/platform.js +30 -0
- package/dist/utilities/platform.js.map +1 -0
- package/dist/utilities/scroll.d.ts +8 -0
- package/dist/utilities/scroll.d.ts.map +1 -0
- package/dist/utilities/scroll.js +33 -0
- package/dist/utilities/scroll.js.map +1 -0
- package/dist/utilities/search.d.ts +20 -0
- package/dist/utilities/search.d.ts.map +1 -0
- package/dist/utilities/search.js +110 -0
- package/dist/utilities/search.js.map +1 -0
- package/package.json +77 -0
- package/src/themes/sigvelo.css +28 -0
- package/src/themes/utilities.css +115 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
const supportsTouch = typeof window !== "undefined" && "ontouchstart" in window;
|
|
2
|
+
/**
|
|
3
|
+
* Attaches the necessary events to make an element draggable.
|
|
4
|
+
*
|
|
5
|
+
* This by itself will not make the element draggable, but it provides the events and callbacks necessary to facilitate
|
|
6
|
+
* dragging. Use the `clientX` and `clientY` arguments of each callback to update the UI as desired when dragging.
|
|
7
|
+
*
|
|
8
|
+
* Drag functionality will be enabled as soon as the constructor is called. A `start()` and `stop()` method can be used
|
|
9
|
+
* to start and stop it, if needed.
|
|
10
|
+
*
|
|
11
|
+
* Note: to prevent undesired scrolling while dragging on touch devices, use `touch-action: none` in the component's
|
|
12
|
+
* styles instead of preventing the `pointerdown` event.
|
|
13
|
+
*
|
|
14
|
+
* @usage
|
|
15
|
+
*
|
|
16
|
+
* const draggable = new DraggableElement(element, {
|
|
17
|
+
* start: (clientX, clientY) => { ... },
|
|
18
|
+
* move: (clientX, clientY) => { ... },
|
|
19
|
+
* stop: (clientX, clientY) => { ... }
|
|
20
|
+
* });
|
|
21
|
+
*/
|
|
22
|
+
export class DraggableElement {
|
|
23
|
+
constructor(el, options) {
|
|
24
|
+
this.isActive = false;
|
|
25
|
+
this.isDragging = false;
|
|
26
|
+
this.handleDragStart = (event) => {
|
|
27
|
+
const clientX = "touches" in event ? event.touches[0].clientX : event.clientX;
|
|
28
|
+
const clientY = "touches" in event ? event.touches[0].clientY : event.clientY;
|
|
29
|
+
if (this.isDragging ||
|
|
30
|
+
// Prevent right-clicks from triggering drags
|
|
31
|
+
(!supportsTouch && event.buttons > 1)) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
this.isDragging = true;
|
|
35
|
+
// Capture pointer to prevent iframes from stealing events during drag
|
|
36
|
+
if ("pointerId" in event) {
|
|
37
|
+
event.target.setPointerCapture(event.pointerId);
|
|
38
|
+
}
|
|
39
|
+
document.addEventListener("pointerup", this.handleDragStop);
|
|
40
|
+
document.addEventListener("pointermove", this.handleDragMove);
|
|
41
|
+
document.addEventListener("touchend", this.handleDragStop);
|
|
42
|
+
document.addEventListener("touchmove", this.handleDragMove);
|
|
43
|
+
this.options.start(clientX, clientY);
|
|
44
|
+
};
|
|
45
|
+
this.handleDragStop = (event) => {
|
|
46
|
+
// touchend has an empty `touches` list — use changedTouches instead
|
|
47
|
+
const clientX = "changedTouches" in event ? event.changedTouches[0].clientX : event.clientX;
|
|
48
|
+
const clientY = "changedTouches" in event ? event.changedTouches[0].clientY : event.clientY;
|
|
49
|
+
this.isDragging = false;
|
|
50
|
+
document.removeEventListener("pointerup", this.handleDragStop);
|
|
51
|
+
document.removeEventListener("pointermove", this.handleDragMove);
|
|
52
|
+
document.removeEventListener("touchend", this.handleDragStop);
|
|
53
|
+
document.removeEventListener("touchmove", this.handleDragMove);
|
|
54
|
+
this.options.stop(clientX, clientY);
|
|
55
|
+
};
|
|
56
|
+
this.handleDragMove = (event) => {
|
|
57
|
+
const clientX = "touches" in event ? event.touches[0].clientX : event.clientX;
|
|
58
|
+
const clientY = "touches" in event ? event.touches[0].clientY : event.clientY;
|
|
59
|
+
// Prevent text selection while dragging
|
|
60
|
+
window.getSelection()?.removeAllRanges();
|
|
61
|
+
this.options.move(clientX, clientY);
|
|
62
|
+
};
|
|
63
|
+
this.element = el;
|
|
64
|
+
this.options = {
|
|
65
|
+
start: () => undefined,
|
|
66
|
+
stop: () => undefined,
|
|
67
|
+
move: () => undefined,
|
|
68
|
+
...options,
|
|
69
|
+
};
|
|
70
|
+
this.start();
|
|
71
|
+
}
|
|
72
|
+
/** Start listening to drags. */
|
|
73
|
+
start() {
|
|
74
|
+
if (!this.isActive) {
|
|
75
|
+
this.element.addEventListener("pointerdown", this.handleDragStart);
|
|
76
|
+
if (supportsTouch) {
|
|
77
|
+
this.element.addEventListener("touchstart", this.handleDragStart);
|
|
78
|
+
}
|
|
79
|
+
this.isActive = true;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/** Stop listening to drags. */
|
|
83
|
+
stop() {
|
|
84
|
+
document.removeEventListener("pointerup", this.handleDragStop);
|
|
85
|
+
document.removeEventListener("pointermove", this.handleDragMove);
|
|
86
|
+
document.removeEventListener("touchend", this.handleDragStop);
|
|
87
|
+
document.removeEventListener("touchmove", this.handleDragMove);
|
|
88
|
+
this.element.removeEventListener("pointerdown", this.handleDragStart);
|
|
89
|
+
if (supportsTouch) {
|
|
90
|
+
this.element.removeEventListener("touchstart", this.handleDragStart);
|
|
91
|
+
}
|
|
92
|
+
this.isActive = false;
|
|
93
|
+
this.isDragging = false;
|
|
94
|
+
}
|
|
95
|
+
/** Starts or stops the drag listeners. */
|
|
96
|
+
toggle(isActive) {
|
|
97
|
+
const isGoingToBeActive = isActive !== undefined ? isActive : !this.isActive;
|
|
98
|
+
if (isGoingToBeActive) {
|
|
99
|
+
this.start();
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
this.stop();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=drag.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drag.js","sourceRoot":"","sources":["../../src/utilities/drag.ts"],"names":[],"mappings":"AAAA,MAAM,aAAa,GAAG,OAAO,MAAM,KAAK,WAAW,IAAI,cAAc,IAAI,MAAM,CAAC;AAEhF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,OAAO,gBAAgB;IAM3B,YAAY,EAAW,EAAE,OAAyC;QAJ1D,aAAQ,GAAG,KAAK,CAAC;QACjB,eAAU,GAAG,KAAK,CAAC;QAenB,oBAAe,GAAG,CAAC,KAAgC,EAAE,EAAE;YAC7D,MAAM,OAAO,GAAG,SAAS,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAE,KAAsB,CAAC,OAAO,CAAC;YAChG,MAAM,OAAO,GAAG,SAAS,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAE,KAAsB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|
+
/** Returns the "inner HTML" of a slot element. */
|
|
2
|
+
export declare function getSlotHtml(slot: HTMLSlotElement): string;
|
|
3
|
+
/** Returns the "text content" of a slot element. */
|
|
4
|
+
export declare function getSlotText(slot: HTMLSlotElement | undefined | null): string;
|
|
5
|
+
//# sourceMappingURL=html.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"html.d.ts","sourceRoot":"","sources":["../../src/utilities/html.ts"],"names":[],"mappings":"AAAA,kDAAkD;AAClD,wBAAgB,WAAW,CAAC,IAAI,EAAE,eAAe,GAAG,MAAM,CAezD;AAoBD,oDAAoD;AACpD,wBAAgB,WAAW,CAAC,IAAI,EAAE,eAAe,GAAG,SAAS,GAAG,IAAI,GAAG,MAAM,CAO5E"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/** Returns the "inner HTML" of a slot element. */
|
|
2
|
+
export function getSlotHtml(slot) {
|
|
3
|
+
const nodes = slot.assignedNodes({ flatten: true });
|
|
4
|
+
let innerHtml = "";
|
|
5
|
+
[...nodes].forEach((node) => {
|
|
6
|
+
if (node.nodeType === Node.ELEMENT_NODE) {
|
|
7
|
+
innerHtml += node.outerHTML;
|
|
8
|
+
}
|
|
9
|
+
if (node.nodeType === Node.TEXT_NODE) {
|
|
10
|
+
innerHtml += node.textContent;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
return innerHtml;
|
|
14
|
+
}
|
|
15
|
+
function extractText(nodesArray) {
|
|
16
|
+
let text = "";
|
|
17
|
+
nodesArray.forEach((node) => {
|
|
18
|
+
if (node.nodeType === Node.TEXT_NODE) {
|
|
19
|
+
// If it's a text node, add its content
|
|
20
|
+
text += node.textContent || "";
|
|
21
|
+
}
|
|
22
|
+
else if (node.nodeType === Node.ELEMENT_NODE && node.hasChildNodes()) {
|
|
23
|
+
// If it's an element node, check for child text nodes
|
|
24
|
+
text += extractText(Array.from(node.childNodes));
|
|
25
|
+
}
|
|
26
|
+
else if (node.nodeType === Node.ELEMENT_NODE) {
|
|
27
|
+
// For elements without children, get their textContent
|
|
28
|
+
text += node.textContent || "";
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
return text;
|
|
32
|
+
}
|
|
33
|
+
/** Returns the "text content" of a slot element. */
|
|
34
|
+
export function getSlotText(slot) {
|
|
35
|
+
if (!slot) {
|
|
36
|
+
return "";
|
|
37
|
+
}
|
|
38
|
+
const nodes = slot.assignedNodes({ flatten: true });
|
|
39
|
+
return extractText(nodes).trim();
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=html.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"html.js","sourceRoot":"","sources":["../../src/utilities/html.ts"],"names":[],"mappings":"AAAA,kDAAkD;AAClD,MAAM,UAAU,WAAW,CAAC,IAAqB;IAC/C,MAAM,KAAK,GAAG,IAAI,CAAC,aAAa,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;IACpD,IAAI,SAAS,GAAG,EAAE,CAAC;IAEnB,CAAC,GAAG,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QAC1B,IAAI,IAAI,CAAC,QAAQ,KAAK,IAAI,CAAC,YAAY,EAAE,CAAC;YACxC,SAAS,IAAK,IAAoB,CAAC,SAAS,CAAC;QAC/C,CAAC;QAED,IAAI,IAAI,CAAC,QAAQ,KAAK,IAAI,CAAC,SAAS,EAAE,CAAC;YACrC,SAAS,IAAI,IAAI,CAAC,WAAW,CAAC;QAChC,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,SAAS,WAAW,CAAC,UAAkB;IACrC,IAAI,IAAI,GAAG,EAAE,CAAC;IACd,UAAU,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QAC1B,IAAI,IAAI,CAAC,QAAQ,KAAK,IAAI,CAAC,SAAS,EAAE,CAAC;YACrC,uCAAuC;YACvC,IAAI,IAAI,IAAI,CAAC,WAAW,IAAI,EAAE,CAAC;QACjC,CAAC;aAAM,IAAI,IAAI,CAAC,QAAQ,KAAK,IAAI,CAAC,YAAY,IAAK,IAAoB,CAAC,aAAa,EAAE,EAAE,CAAC;YACxF,sDAAsD;YACtD,IAAI,IAAI,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;QACnD,CAAC;aAAM,IAAI,IAAI,CAAC,QAAQ,KAAK,IAAI,CAAC,YAAY,EAAE,CAAC;YAC/C,uDAAuD;YACvD,IAAI,IAAK,IAAoB,CAAC,WAAW,IAAI,EAAE,CAAC;QAClD,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,IAAI,CAAC;AACd,CAAC;AAED,oDAAoD;AACpD,MAAM,UAAU,WAAW,CAAC,IAAwC;IAClE,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,KAAK,GAAG,IAAI,CAAC,aAAa,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;IACpD,OAAO,WAAW,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC;AACnC,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export type ResolveFunction = (name: string, family: string) => string;
|
|
2
|
+
export type MutateFunction = (svg: SVGElement) => void;
|
|
3
|
+
export interface Library {
|
|
4
|
+
resolve: ResolveFunction;
|
|
5
|
+
mutate?: MutateFunction;
|
|
6
|
+
}
|
|
7
|
+
/** Any element that can be tracked by the icon library system. */
|
|
8
|
+
export interface IconElement extends HTMLElement {
|
|
9
|
+
load(): Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
/** Registers a new icon library. */
|
|
12
|
+
export declare function registerIconLibrary(name: string, library: Library): void;
|
|
13
|
+
/** Removes a previously registered icon library. */
|
|
14
|
+
export declare function unregisterIconLibrary(name: string): void;
|
|
15
|
+
/** Gets a registered icon library. */
|
|
16
|
+
export declare function getLibrary(name: string): Library | undefined;
|
|
17
|
+
/** Call this when an icon is connected to make it reactive to changes to icon libraries. */
|
|
18
|
+
export declare function connectIcon(el: IconElement): void;
|
|
19
|
+
/** Call this when an icon is disconnected and no longer needs to be reactive. */
|
|
20
|
+
export declare function disconnectIcon(el: IconElement): void;
|
|
21
|
+
/** Gets an array of all icons that are currently connected. */
|
|
22
|
+
export declare function getObservedIcons(): IconElement[];
|
|
23
|
+
/**
|
|
24
|
+
* Updates all connected icons from the specified library. Call this after registering, unregistering, or making changes
|
|
25
|
+
* to an icon library to make sure icons refresh.
|
|
26
|
+
*/
|
|
27
|
+
export declare function updateConnectedIcons(): Promise<void[]>;
|
|
28
|
+
//# sourceMappingURL=icon-library.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"icon-library.d.ts","sourceRoot":"","sources":["../../src/utilities/icon-library.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,eAAe,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,MAAM,CAAC;AACvE,MAAM,MAAM,cAAc,GAAG,CAAC,GAAG,EAAE,UAAU,KAAK,IAAI,CAAC;AAEvD,MAAM,WAAW,OAAO;IACtB,OAAO,EAAE,eAAe,CAAC;IACzB,MAAM,CAAC,EAAE,cAAc,CAAC;CACzB;AAED,kEAAkE;AAClE,MAAM,WAAW,WAAY,SAAQ,WAAW;IAC9C,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACvB;AAKD,oCAAoC;AACpC,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,QAGjE;AAED,oDAAoD;AACpD,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,QAGjD;AAED,sCAAsC;AACtC,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,uBAEtC;AAED,4FAA4F;AAC5F,wBAAgB,WAAW,CAAC,EAAE,EAAE,WAAW,QAE1C;AAED,iFAAiF;AACjF,wBAAgB,cAAc,CAAC,EAAE,EAAE,WAAW,QAE7C;AAED,+DAA+D;AAC/D,wBAAgB,gBAAgB,kBAE/B;AAED;;;GAGG;AACH,wBAAsB,oBAAoB,oBAEzC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const libraries = new Map();
|
|
2
|
+
const connectedIcons = new Set();
|
|
3
|
+
/** Registers a new icon library. */
|
|
4
|
+
export function registerIconLibrary(name, library) {
|
|
5
|
+
libraries.set(name, library);
|
|
6
|
+
updateConnectedIcons();
|
|
7
|
+
}
|
|
8
|
+
/** Removes a previously registered icon library. */
|
|
9
|
+
export function unregisterIconLibrary(name) {
|
|
10
|
+
libraries.delete(name);
|
|
11
|
+
updateConnectedIcons();
|
|
12
|
+
}
|
|
13
|
+
/** Gets a registered icon library. */
|
|
14
|
+
export function getLibrary(name) {
|
|
15
|
+
return libraries.get(name);
|
|
16
|
+
}
|
|
17
|
+
/** Call this when an icon is connected to make it reactive to changes to icon libraries. */
|
|
18
|
+
export function connectIcon(el) {
|
|
19
|
+
connectedIcons.add(el);
|
|
20
|
+
}
|
|
21
|
+
/** Call this when an icon is disconnected and no longer needs to be reactive. */
|
|
22
|
+
export function disconnectIcon(el) {
|
|
23
|
+
connectedIcons.delete(el);
|
|
24
|
+
}
|
|
25
|
+
/** Gets an array of all icons that are currently connected. */
|
|
26
|
+
export function getObservedIcons() {
|
|
27
|
+
return [...connectedIcons];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Updates all connected icons from the specified library. Call this after registering, unregistering, or making changes
|
|
31
|
+
* to an icon library to make sure icons refresh.
|
|
32
|
+
*/
|
|
33
|
+
export async function updateConnectedIcons() {
|
|
34
|
+
return Promise.all([...connectedIcons].map((icon) => icon.load()));
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=icon-library.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"icon-library.js","sourceRoot":"","sources":["../../src/utilities/icon-library.ts"],"names":[],"mappings":"AAaA,MAAM,SAAS,GAAG,IAAI,GAAG,EAAmB,CAAC;AAC7C,MAAM,cAAc,GAAG,IAAI,GAAG,EAAe,CAAC;AAE9C,oCAAoC;AACpC,MAAM,UAAU,mBAAmB,CAAC,IAAY,EAAE,OAAgB;IAChE,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAC7B,oBAAoB,EAAE,CAAC;AACzB,CAAC;AAED,oDAAoD;AACpD,MAAM,UAAU,qBAAqB,CAAC,IAAY;IAChD,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACvB,oBAAoB,EAAE,CAAC;AACzB,CAAC;AAED,sCAAsC;AACtC,MAAM,UAAU,UAAU,CAAC,IAAY;IACrC,OAAO,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AAC7B,CAAC;AAED,4FAA4F;AAC5F,MAAM,UAAU,WAAW,CAAC,EAAe;IACzC,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;AACzB,CAAC;AAED,iFAAiF;AACjF,MAAM,UAAU,cAAc,CAAC,EAAe;IAC5C,cAAc,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AAC5B,CAAC;AAED,+DAA+D;AAC/D,MAAM,UAAU,gBAAgB;IAC9B,OAAO,CAAC,GAAG,cAAc,CAAC,CAAC;AAC7B,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB;IACxC,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,cAAc,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;AACrE,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export * from "./active-element.js";
|
|
2
|
+
export * from "./localize.js";
|
|
3
|
+
export * from "./animate.js";
|
|
4
|
+
export * from "./defined.js";
|
|
5
|
+
export * from "./drag.js";
|
|
6
|
+
export * from "./html.js";
|
|
7
|
+
export * from "./icon-library.js";
|
|
8
|
+
export * from "./library.js";
|
|
9
|
+
export * from "./loader.js";
|
|
10
|
+
export * from "./long-press.js";
|
|
11
|
+
export * from "./math.js";
|
|
12
|
+
export * from "./parse.js";
|
|
13
|
+
export * from "./platform.js";
|
|
14
|
+
export * from "./scroll.js";
|
|
15
|
+
export * from "./search.js";
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utilities/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export * from "./active-element.js";
|
|
2
|
+
export * from "./localize.js";
|
|
3
|
+
export * from "./animate.js";
|
|
4
|
+
export * from "./defined.js";
|
|
5
|
+
export * from "./drag.js";
|
|
6
|
+
export * from "./html.js";
|
|
7
|
+
export * from "./icon-library.js";
|
|
8
|
+
export * from "./library.js";
|
|
9
|
+
export * from "./loader.js";
|
|
10
|
+
export * from "./long-press.js";
|
|
11
|
+
export * from "./math.js";
|
|
12
|
+
export * from "./parse.js";
|
|
13
|
+
export * from "./platform.js";
|
|
14
|
+
export * from "./scroll.js";
|
|
15
|
+
export * from "./search.js";
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utilities/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** Sets the library's asset path to the specified directory or URL. */
|
|
2
|
+
export declare function setLibraryPath(path: string): void;
|
|
3
|
+
/**
|
|
4
|
+
* Gets the library's assets path.
|
|
5
|
+
*
|
|
6
|
+
* The asset path is used to load assets such as icons and images. By default, Sigvelo will look for a script ending in
|
|
7
|
+
* "sigvelo.js" and guess the asset path relative to the script's location. This "just works" for most users but, if
|
|
8
|
+
* you're bundling the library, you'll need to copy the `assets` folder into your app and point this to that location.
|
|
9
|
+
*
|
|
10
|
+
* The easiest way is to provide a `data-sigvelo` attribute on any element in the DOM.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
*
|
|
14
|
+
* <html data-sigvelo="/path/to/assets">
|
|
15
|
+
*
|
|
16
|
+
* @param subpath - An optional path to append to the base path.
|
|
17
|
+
*/
|
|
18
|
+
export declare function getLibraryPath(subpath?: string): string;
|
|
19
|
+
//# sourceMappingURL=library.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"library.d.ts","sourceRoot":"","sources":["../../src/utilities/library.ts"],"names":[],"mappings":"AAEA,uEAAuE;AACvE,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,QAE1C;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,cAAc,CAAC,OAAO,SAAK,UA4B1C"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
let libraryPath = "";
|
|
2
|
+
/** Sets the library's asset path to the specified directory or URL. */
|
|
3
|
+
export function setLibraryPath(path) {
|
|
4
|
+
libraryPath = path;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Gets the library's assets path.
|
|
8
|
+
*
|
|
9
|
+
* The asset path is used to load assets such as icons and images. By default, Sigvelo will look for a script ending in
|
|
10
|
+
* "sigvelo.js" and guess the asset path relative to the script's location. This "just works" for most users but, if
|
|
11
|
+
* you're bundling the library, you'll need to copy the `assets` folder into your app and point this to that location.
|
|
12
|
+
*
|
|
13
|
+
* The easiest way is to provide a `data-sigvelo` attribute on any element in the DOM.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
*
|
|
17
|
+
* <html data-sigvelo="/path/to/assets">
|
|
18
|
+
*
|
|
19
|
+
* @param subpath - An optional path to append to the base path.
|
|
20
|
+
*/
|
|
21
|
+
export function getLibraryPath(subpath = "") {
|
|
22
|
+
if (!libraryPath) {
|
|
23
|
+
const sigveloEl = document.querySelector("[data-sigvelo]");
|
|
24
|
+
if (sigveloEl?.hasAttribute("data-sigvelo")) {
|
|
25
|
+
// Use data-sigvelo to get the root-relative URL
|
|
26
|
+
const rootRelativeUrl = new URL(sigveloEl.getAttribute("data-sigvelo") ?? "", window.location.href).pathname;
|
|
27
|
+
setLibraryPath(rootRelativeUrl);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
// Use the path to sigvelo.js or sigvelo.loader.js
|
|
31
|
+
const scripts = [...document.getElementsByTagName("script")];
|
|
32
|
+
const sigveloScript = scripts.find((script) => {
|
|
33
|
+
const src = script.src.split("?")[0];
|
|
34
|
+
return src.endsWith("sigvelo.js") || src.endsWith("sigvelo.loader.js");
|
|
35
|
+
});
|
|
36
|
+
if (sigveloScript) {
|
|
37
|
+
const path = String(sigveloScript.getAttribute("src"));
|
|
38
|
+
setLibraryPath(path.split("/").slice(0, -1).join("/"));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
// Return the asset path without a trailing slash and append the subpath
|
|
43
|
+
return libraryPath.replace(/\/$/, "") + (subpath ? `/${subpath.replace(/^\//, "")}` : ``);
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=library.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"library.js","sourceRoot":"","sources":["../../src/utilities/library.ts"],"names":[],"mappings":"AAAA,IAAI,WAAW,GAAG,EAAE,CAAC;AAErB,uEAAuE;AACvE,MAAM,UAAU,cAAc,CAAC,IAAY;IACzC,WAAW,GAAG,IAAI,CAAC;AACrB,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,cAAc,CAAC,OAAO,GAAG,EAAE;IACzC,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,MAAM,SAAS,GAAG,QAAQ,CAAC,aAAa,CAAC,gBAAgB,CAAC,CAAC;QAE3D,IAAI,SAAS,EAAE,YAAY,CAAC,cAAc,CAAC,EAAE,CAAC;YAC5C,gDAAgD;YAChD,MAAM,eAAe,GAAG,IAAI,GAAG,CAC7B,SAAS,CAAC,YAAY,CAAC,cAAc,CAAC,IAAI,EAAE,EAC5C,MAAM,CAAC,QAAQ,CAAC,IAAI,CACrB,CAAC,QAAQ,CAAC;YACX,cAAc,CAAC,eAAe,CAAC,CAAC;QAClC,CAAC;aAAM,CAAC;YACN,kDAAkD;YAClD,MAAM,OAAO,GAAG,CAAC,GAAG,QAAQ,CAAC,oBAAoB,CAAC,QAAQ,CAAC,CAAwB,CAAC;YACpF,MAAM,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;gBAC5C,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;gBACrC,OAAO,GAAG,CAAC,QAAQ,CAAC,YAAY,CAAC,IAAI,GAAG,CAAC,QAAQ,CAAC,mBAAmB,CAAC,CAAC;YACzE,CAAC,CAAC,CAAC;YAEH,IAAI,aAAa,EAAE,CAAC;gBAClB,MAAM,IAAI,GAAG,MAAM,CAAC,aAAa,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC;gBACvD,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;YACzD,CAAC;QACH,CAAC;IACH,CAAC;IAED,wEAAwE;IACxE,OAAO,WAAW,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AAC5F,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export type ComponentModuleMap = Record<string, () => Promise<unknown>>;
|
|
2
|
+
export interface LoaderOptions {
|
|
3
|
+
/** A map of component names (without prefix) to lazy import functions. */
|
|
4
|
+
modules?: ComponentModuleMap;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Starts the autoloader and registers new Sigvelo elements as they appear in the DOM.
|
|
8
|
+
*
|
|
9
|
+
* When `modules` is provided, the loader uses it to resolve components (Vite-friendly).
|
|
10
|
+
* Otherwise, it falls back to constructing file paths via `getLibraryPath`.
|
|
11
|
+
*/
|
|
12
|
+
export declare function startLoader(options?: LoaderOptions): void;
|
|
13
|
+
/**
|
|
14
|
+
* Stops the autoloader. Elements that have already been loaded will remain loaded.
|
|
15
|
+
*/
|
|
16
|
+
export declare function stopLoader(): void;
|
|
17
|
+
/**
|
|
18
|
+
* Checks a node for undefined elements and attempts to register them.
|
|
19
|
+
*/
|
|
20
|
+
export declare function discoverElements(root: Element | ShadowRoot): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Many multi-page applications (MPAs) use Hotwire: Turbo to provide a SPA-like experience for users. When visiting
|
|
23
|
+
* links, Turbo intercepts the click, fetches the new page, and updates metadata and content without redirecting,
|
|
24
|
+
* resulting in a buttery smooth transition when going from one page to another.
|
|
25
|
+
*
|
|
26
|
+
* However, when you use Turbo with Sigvelo's autoloader, you may see FOUCE when visiting new pages for the first time.
|
|
27
|
+
* This is because Turbo renders the new page and _then_ the autoloader fetches unregistered components.
|
|
28
|
+
*
|
|
29
|
+
* To solve that, this function adds a listener that hooks into Turbo's `turbo:before-render` event and registers all
|
|
30
|
+
* components before the new page is rendered, effectively eliminating FOUCE for page-to-page navigation.
|
|
31
|
+
*
|
|
32
|
+
* The function comes with a configurable timeout to prevent issues with errors or slow networks. For most use cases,
|
|
33
|
+
* the default value of 2000ms is optimal.
|
|
34
|
+
*/
|
|
35
|
+
export declare function preventTurboFouce(timeout?: number): void;
|
|
36
|
+
//# sourceMappingURL=loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../src/utilities/loader.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,kBAAkB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;AA6CxE,MAAM,WAAW,aAAa;IAC5B,0EAA0E;IAC1E,OAAO,CAAC,EAAE,kBAAkB,CAAC;CAC9B;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,OAAO,CAAC,EAAE,aAAa,QAUlD;AAED;;GAEG;AACH,wBAAgB,UAAU,SAEzB;AAED;;GAEG;AACH,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,OAAO,GAAG,UAAU,iBAsDhE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,SAAO,QAgB/C"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { isDesignSystemTag, stripElementPrefix } from "../prefix.js";
|
|
2
|
+
import { getLibraryPath } from "./library.js";
|
|
3
|
+
let moduleMap;
|
|
4
|
+
const observer = new MutationObserver((mutations) => {
|
|
5
|
+
for (const { addedNodes } of mutations) {
|
|
6
|
+
for (const node of addedNodes) {
|
|
7
|
+
if (node.nodeType === Node.ELEMENT_NODE) {
|
|
8
|
+
discoverElements(node);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
/**
|
|
14
|
+
* Registers an element by tag name.
|
|
15
|
+
*/
|
|
16
|
+
function register(tagName) {
|
|
17
|
+
// If the element is already defined, there's nothing more to do
|
|
18
|
+
if (customElements.get(tagName)) {
|
|
19
|
+
return Promise.resolve();
|
|
20
|
+
}
|
|
21
|
+
const tagWithoutPrefix = stripElementPrefix(tagName);
|
|
22
|
+
// Use the module map if provided, otherwise fall back to path-based dynamic import
|
|
23
|
+
if (moduleMap) {
|
|
24
|
+
const loader = moduleMap[tagWithoutPrefix];
|
|
25
|
+
if (loader) {
|
|
26
|
+
return loader().then(() => { });
|
|
27
|
+
}
|
|
28
|
+
return Promise.reject(new Error(`Unknown component <${tagName}>`));
|
|
29
|
+
}
|
|
30
|
+
const path = getLibraryPath(`components/${tagWithoutPrefix}/${tagWithoutPrefix}.js`);
|
|
31
|
+
return new Promise((resolve, reject) => {
|
|
32
|
+
import(/* @vite-ignore */ path)
|
|
33
|
+
.then(() => resolve())
|
|
34
|
+
.catch(() => {
|
|
35
|
+
reject(new Error(`Failed to load <${tagName}> from "${path}"`));
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Starts the autoloader and registers new Sigvelo elements as they appear in the DOM.
|
|
41
|
+
*
|
|
42
|
+
* When `modules` is provided, the loader uses it to resolve components (Vite-friendly).
|
|
43
|
+
* Otherwise, it falls back to constructing file paths via `getLibraryPath`.
|
|
44
|
+
*/
|
|
45
|
+
export function startLoader(options) {
|
|
46
|
+
if (options?.modules) {
|
|
47
|
+
moduleMap = options.modules;
|
|
48
|
+
}
|
|
49
|
+
// Initial discovery
|
|
50
|
+
discoverElements(document.body);
|
|
51
|
+
// Listen for new undefined elements
|
|
52
|
+
observer.observe(document.documentElement, { subtree: true, childList: true });
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Stops the autoloader. Elements that have already been loaded will remain loaded.
|
|
56
|
+
*/
|
|
57
|
+
export function stopLoader() {
|
|
58
|
+
observer.disconnect();
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Checks a node for undefined elements and attempts to register them.
|
|
62
|
+
*/
|
|
63
|
+
export async function discoverElements(root) {
|
|
64
|
+
const rootTagName = root instanceof Element ? root.tagName.toLowerCase() : "";
|
|
65
|
+
const rootIsSigveloElement = isDesignSystemTag(rootTagName);
|
|
66
|
+
// Get a list of elements to preload from all `data-sigvelo-preload` attributes on the page
|
|
67
|
+
const tagsToPreload = [...document.querySelectorAll("[data-sigvelo-preload]")]
|
|
68
|
+
.map((el) => el.getAttribute("data-sigvelo-preload") || "")
|
|
69
|
+
.flatMap((attr) => attr.split(" "))
|
|
70
|
+
.filter((tag) => tag.length > 0);
|
|
71
|
+
const tagsOnPage = [...root.querySelectorAll(":not(:defined)")]
|
|
72
|
+
.map((el) => el.tagName.toLowerCase())
|
|
73
|
+
.filter((tag) => isDesignSystemTag(tag));
|
|
74
|
+
// If the root element is an undefined Sigvelo element, add it to the list
|
|
75
|
+
if (rootIsSigveloElement && !customElements.get(rootTagName)) {
|
|
76
|
+
tagsOnPage.push(rootTagName);
|
|
77
|
+
}
|
|
78
|
+
// Get a unique list of all tags to register
|
|
79
|
+
const tagsToRegister = [...new Set(tagsOnPage.concat(tagsToPreload))];
|
|
80
|
+
const registered = [];
|
|
81
|
+
const unknown = [];
|
|
82
|
+
if (tagsToRegister.length === 0) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
// Registration is sequential on purpose; the inner await is what orders it,
|
|
86
|
+
// so a plain for-of is correct here (the array is not async iterable).
|
|
87
|
+
for (const tagName of tagsToRegister) {
|
|
88
|
+
try {
|
|
89
|
+
await register(tagName);
|
|
90
|
+
registered.push(tagName);
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
unknown.push(tagName);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
// Wait a cycle for initial component updates to complete
|
|
97
|
+
await new Promise(requestAnimationFrame);
|
|
98
|
+
//
|
|
99
|
+
// Emit the 'sigvelo-discovery-complete' event for this batch of elements. The detail payload will include an object
|
|
100
|
+
// with an array of elements that were registered and an array of unknown elements (i.e. not found).
|
|
101
|
+
//
|
|
102
|
+
root.dispatchEvent(new CustomEvent("sigvelo-discovery-complete", {
|
|
103
|
+
bubbles: false,
|
|
104
|
+
cancelable: false,
|
|
105
|
+
composed: true,
|
|
106
|
+
detail: { registered, unknown },
|
|
107
|
+
}));
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Many multi-page applications (MPAs) use Hotwire: Turbo to provide a SPA-like experience for users. When visiting
|
|
111
|
+
* links, Turbo intercepts the click, fetches the new page, and updates metadata and content without redirecting,
|
|
112
|
+
* resulting in a buttery smooth transition when going from one page to another.
|
|
113
|
+
*
|
|
114
|
+
* However, when you use Turbo with Sigvelo's autoloader, you may see FOUCE when visiting new pages for the first time.
|
|
115
|
+
* This is because Turbo renders the new page and _then_ the autoloader fetches unregistered components.
|
|
116
|
+
*
|
|
117
|
+
* To solve that, this function adds a listener that hooks into Turbo's `turbo:before-render` event and registers all
|
|
118
|
+
* components before the new page is rendered, effectively eliminating FOUCE for page-to-page navigation.
|
|
119
|
+
*
|
|
120
|
+
* The function comes with a configurable timeout to prevent issues with errors or slow networks. For most use cases,
|
|
121
|
+
* the default value of 2000ms is optimal.
|
|
122
|
+
*/
|
|
123
|
+
export function preventTurboFouce(timeout = 2000) {
|
|
124
|
+
document.addEventListener("turbo:before-render", async (event) => {
|
|
125
|
+
const newBody = event.detail.newBody;
|
|
126
|
+
event.preventDefault();
|
|
127
|
+
try {
|
|
128
|
+
// Wait until all elements are registered or two seconds, whichever comes first
|
|
129
|
+
await Promise.race([
|
|
130
|
+
discoverElements(newBody),
|
|
131
|
+
new Promise((resolve) => setTimeout(resolve, timeout)),
|
|
132
|
+
]);
|
|
133
|
+
}
|
|
134
|
+
finally {
|
|
135
|
+
event.detail.resume();
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../../src/utilities/loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAI9C,IAAI,SAAyC,CAAC;AAE9C,MAAM,QAAQ,GAAG,IAAI,gBAAgB,CAAC,CAAC,SAAS,EAAE,EAAE;IAClD,KAAK,MAAM,EAAE,UAAU,EAAE,IAAI,SAAS,EAAE,CAAC;QACvC,KAAK,MAAM,IAAI,IAAI,UAAU,EAAE,CAAC;YAC9B,IAAI,IAAI,CAAC,QAAQ,KAAK,IAAI,CAAC,YAAY,EAAE,CAAC;gBACxC,gBAAgB,CAAC,IAAe,CAAC,CAAC;YACpC,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC,CAAC,CAAC;AAEH;;GAEG;AACH,SAAS,QAAQ,CAAC,OAAe;IAC/B,gEAAgE;IAChE,IAAI,cAAc,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;QAChC,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;IAED,MAAM,gBAAgB,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AC,MAAM,CAAC,MAAM,EAAE,CAAC;QACxB,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { ReactiveController, ReactiveControllerHost } from "lit";
|
|
2
|
+
/** Extracts parameter types from a translation value that is a function. */
|
|
3
|
+
type FunctionParams<T> = T extends (...args: infer P) => string ? P : [];
|
|
4
|
+
/** Minimum shape every translation must satisfy. */
|
|
5
|
+
export interface BaseTranslation {
|
|
6
|
+
/** BCP 47 language code, e.g. `en`, `en-GB`. */
|
|
7
|
+
$code: string;
|
|
8
|
+
/** Human-readable language name, e.g. `English`, `Espanol`. */
|
|
9
|
+
$name: string;
|
|
10
|
+
/** Text directionality. */
|
|
11
|
+
$dir: "ltr" | "rtl";
|
|
12
|
+
}
|
|
13
|
+
/** Registers the fallback translation used when no better match is found. */
|
|
14
|
+
export declare function registerDefaultTranslation(translation: BaseTranslation): void;
|
|
15
|
+
/**
|
|
16
|
+
* Registers one or more translations. If a translation with the same language
|
|
17
|
+
* code already exists, the new keys are merged into it.
|
|
18
|
+
*/
|
|
19
|
+
export declare function registerTranslation(...items: BaseTranslation[]): void;
|
|
20
|
+
/** Re-reads `<html>` attributes and requests an update on every connected element. */
|
|
21
|
+
export declare function update(): void;
|
|
22
|
+
/**
|
|
23
|
+
* Reactive Controller that localizes terms, dates, numbers, and currency for
|
|
24
|
+
* Lit-based custom elements.
|
|
25
|
+
*
|
|
26
|
+
* Instantiate in a component constructor:
|
|
27
|
+
* ```ts
|
|
28
|
+
* private localize = new LocalizeController(this)
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* The controller automatically re-renders its host when `<html dir>` or
|
|
32
|
+
* `<html lang>` change. To also react to per-element overrides, declare
|
|
33
|
+
* `dir` / `lang` as reactive properties on the host.
|
|
34
|
+
*/
|
|
35
|
+
export declare class LocalizeController<T extends BaseTranslation = BaseTranslation> implements ReactiveController {
|
|
36
|
+
private host;
|
|
37
|
+
constructor(host: ReactiveControllerHost & HTMLElement);
|
|
38
|
+
hostConnected(): void;
|
|
39
|
+
hostDisconnected(): void;
|
|
40
|
+
/** Returns the host's resolved text direction (`ltr` or `rtl`). */
|
|
41
|
+
dir(): string;
|
|
42
|
+
/** Returns the host's resolved BCP 47 language tag. */
|
|
43
|
+
lang(): string;
|
|
44
|
+
/** Checks whether a translation key exists for the given (or current) language. */
|
|
45
|
+
exists<K extends keyof T>(key: K, options?: {
|
|
46
|
+
lang?: string;
|
|
47
|
+
includeDefault?: boolean;
|
|
48
|
+
}): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Returns a translated string for the given key. If the value is a function,
|
|
51
|
+
* it is called with the supplied arguments.
|
|
52
|
+
*/
|
|
53
|
+
term<K extends keyof T>(key: K, ...args: FunctionParams<T[K]>): string;
|
|
54
|
+
/** Formats a date using `Intl.DateTimeFormat` in the host's locale. */
|
|
55
|
+
date(value: Date | string, options?: Intl.DateTimeFormatOptions): string;
|
|
56
|
+
/** Formats a number using `Intl.NumberFormat` in the host's locale. */
|
|
57
|
+
number(value: number | string, options?: Intl.NumberFormatOptions): string;
|
|
58
|
+
/** Formats a relative time value (e.g. "3 days ago") in the host's locale. */
|
|
59
|
+
relativeTime(value: number, unit: Intl.RelativeTimeFormatUnit, options?: Intl.RelativeTimeFormatOptions): string;
|
|
60
|
+
}
|
|
61
|
+
export {};
|
|
62
|
+
//# sourceMappingURL=localize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localize.d.ts","sourceRoot":"","sources":["../../src/utilities/localize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,KAAK,CAAC;AAGtE,4EAA4E;AAC5E,KAAK,cAAc,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,MAAM,CAAC,KAAK,MAAM,GAAG,CAAC,GAAG,EAAE,CAAC;AAEzE,oDAAoD;AACpD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