overflowed 0.0.0-experimental-20230103160007 → 0.0.0-experimental-005
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/README.md +11 -45
- package/box-mirror/HTMLBoxMirror.css +15 -0
- package/box-mirror/HTMLBoxMirror.ts +99 -0
- package/content-mirror/HTMLContentMirror.css +3 -0
- package/content-mirror/HTMLContentMirror.ts +43 -0
- package/dist/mod.d.ts +54 -0
- package/dist/mod.d.ts.map +1 -0
- package/dist/mod.js +189 -0
- package/dist/mod.js.map +1 -0
- package/mod.ts +2 -0
- package/overflow-container/HTMLOverflowContainerElement.css +42 -0
- package/overflow-container/HTMLOverflowContainerElement.ts +171 -0
- package/overflow-container/HTMLOverflowContainerEvent.ts +11 -0
- package/package.json +18 -48
- package/LICENSE.md +0 -21
- package/Overflowed-4d9a04ab.d.ts +0 -30
- package/chunk-DZKPYTOC.mjs +0 -163
- package/chunk-TXQIKLPR.mjs +0 -0
- package/core/index.d.ts +0 -1
- package/core/index.js +0 -189
- package/core/index.mjs +0 -7
- package/index.d.ts +0 -4
- package/index.js +0 -31
- package/index.mjs +0 -8
- package/react/index.d.ts +0 -17
- package/react/index.js +0 -291
- package/react/index.mjs +0 -108
- package/svelte/index.d.ts +0 -9
- package/svelte/index.js +0 -216
- package/svelte/index.mjs +0 -34
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import "../box-mirror/HTMLBoxMirror.ts";
|
|
2
|
+
import { HTMLBoxMirror } from "../box-mirror/HTMLBoxMirror.ts";
|
|
3
|
+
|
|
4
|
+
import styles from "./HTMLOverflowContainerElement.css?raw" with { type: "text" };
|
|
5
|
+
|
|
6
|
+
export class HTMLOverflowContainerElement extends HTMLElement {
|
|
7
|
+
private readonly rootStyleSheet = new CSSStyleSheet();
|
|
8
|
+
private readonly variableStyleSheet = new CSSStyleSheet();
|
|
9
|
+
private readonly overflowStyleSheet = new CSSStyleSheet();
|
|
10
|
+
|
|
11
|
+
private readonly childrenSlot = this.ownerDocument.createElement("slot");
|
|
12
|
+
private readonly overflowSlot = this.ownerDocument.createElement("slot");
|
|
13
|
+
|
|
14
|
+
private readonly containerMirror = this.ownerDocument.createElement("box-mirror");
|
|
15
|
+
|
|
16
|
+
private readonly overflowResizeObserver = new ResizeObserver(this.handleResize.bind(this));
|
|
17
|
+
|
|
18
|
+
private readonly elementIsIntersectingMap = new WeakMap<Element, boolean>();
|
|
19
|
+
private readonly intersectionObserver = new IntersectionObserver(this.handleIntersection.bind(this), {
|
|
20
|
+
root: this.containerMirror,
|
|
21
|
+
threshold: 1,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
constructor() {
|
|
25
|
+
super();
|
|
26
|
+
|
|
27
|
+
this.overflowSlot.name = "overflow";
|
|
28
|
+
|
|
29
|
+
this.containerMirror.id = "container-mirror";
|
|
30
|
+
this.containerMirror.boxSizing = "content-box";
|
|
31
|
+
this.containerMirror.target = this;
|
|
32
|
+
|
|
33
|
+
const shadowRoot = this.attachShadow({ mode: "open" });
|
|
34
|
+
shadowRoot.adoptedStyleSheets = [this.rootStyleSheet, this.variableStyleSheet, this.overflowStyleSheet];
|
|
35
|
+
|
|
36
|
+
shadowRoot.appendChild(this.childrenSlot);
|
|
37
|
+
shadowRoot.appendChild(this.overflowSlot);
|
|
38
|
+
|
|
39
|
+
shadowRoot.appendChild(this.containerMirror);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
connectedCallback() {
|
|
43
|
+
this.rootStyleSheet.replaceSync(styles);
|
|
44
|
+
this.updateInlineGap();
|
|
45
|
+
|
|
46
|
+
for (const overflowElement of this.getOverflowElements()) {
|
|
47
|
+
this.registerOverflowElement(overflowElement);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
for (const itemElement of this.getItemElements()) {
|
|
51
|
+
this.registerItemElement(itemElement);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
public disconnectedCallback() {
|
|
56
|
+
this.intersectionObserver.disconnect();
|
|
57
|
+
this.overflowResizeObserver.disconnect();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
private registerItemElement(element: HTMLElement) {
|
|
61
|
+
if (!this.contains(element)) throw new Error("Container must contain item element", { cause: element });
|
|
62
|
+
|
|
63
|
+
const mirrorElement = globalThis.document.createElement("box-mirror");
|
|
64
|
+
mirrorElement.boxSizing = "border-box";
|
|
65
|
+
mirrorElement.behavior = "ignore-hidden";
|
|
66
|
+
|
|
67
|
+
this.containerMirror.appendChild(mirrorElement);
|
|
68
|
+
|
|
69
|
+
this.intersectionObserver.observe(mirrorElement);
|
|
70
|
+
mirrorElement.target = element;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
private registerOverflowElement(element: HTMLElement) {
|
|
74
|
+
this.overflowResizeObserver.observe(element);
|
|
75
|
+
|
|
76
|
+
const mirrorElement = globalThis.document.createElement("box-mirror");
|
|
77
|
+
mirrorElement.boxSizing = "border-box";
|
|
78
|
+
|
|
79
|
+
this.containerMirror.appendChild(mirrorElement);
|
|
80
|
+
|
|
81
|
+
this.intersectionObserver.observe(mirrorElement);
|
|
82
|
+
mirrorElement.target = element;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
private handleIntersection(entries: IntersectionObserverEntry[]) {
|
|
86
|
+
this.updateInlineGap();
|
|
87
|
+
|
|
88
|
+
for (const entry of entries) {
|
|
89
|
+
if (!HTMLBoxMirror.isHTMLBoxMirror(entry.target)) throw 78324;
|
|
90
|
+
|
|
91
|
+
const mirrorElement = entry.target.target;
|
|
92
|
+
if (!mirrorElement) throw 1129342;
|
|
93
|
+
|
|
94
|
+
this.elementIsIntersectingMap.set(mirrorElement, entry.isIntersecting);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const itemElements = this.getItemElements();
|
|
98
|
+
const lastItemElement = itemElements.at(-1);
|
|
99
|
+
|
|
100
|
+
const isOverflowing = lastItemElement ? !this.elementIsIntersectingMap.get(lastItemElement) : true;
|
|
101
|
+
|
|
102
|
+
for (const overflowElement of this.getOverflowElements()) {
|
|
103
|
+
overflowElement.hidden = !isOverflowing;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
for (const itemElement of itemElements) {
|
|
107
|
+
if (isOverflowing) {
|
|
108
|
+
itemElement.hidden = !this.elementIsIntersectingMap.get(itemElement);
|
|
109
|
+
} else {
|
|
110
|
+
itemElement.hidden = false;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
this.setAttribute("overflowing", String(isOverflowing));
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
private updateInlineGap() {
|
|
118
|
+
const blockGap = globalThis.getComputedStyle(this).rowGap;
|
|
119
|
+
const inlineGap = globalThis.getComputedStyle(this).columnGap;
|
|
120
|
+
|
|
121
|
+
this.variableStyleSheet.replaceSync(`
|
|
122
|
+
:host {
|
|
123
|
+
--block-gap: ${isNaN(parseFloat(blockGap)) ? "0px" : blockGap};
|
|
124
|
+
--inline-gap: ${isNaN(parseFloat(inlineGap)) ? "0px" : inlineGap};
|
|
125
|
+
}
|
|
126
|
+
`);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
private handleResize(entries: ResizeObserverEntry[]) {
|
|
130
|
+
for (const entry of entries) {
|
|
131
|
+
const [borderBoxSize, ...rest] = entry.borderBoxSize;
|
|
132
|
+
if (!borderBoxSize) throw 1;
|
|
133
|
+
if (rest.length > 0) throw 1;
|
|
134
|
+
|
|
135
|
+
if (entry.target.slot === "overflow") {
|
|
136
|
+
if (borderBoxSize.blockSize === 0 || borderBoxSize.inlineSize === 0) continue;
|
|
137
|
+
|
|
138
|
+
this.overflowStyleSheet.replaceSync(`
|
|
139
|
+
:host {
|
|
140
|
+
--overflow-inline-size: ${borderBoxSize.inlineSize}px;
|
|
141
|
+
--overflow-block-size: ${borderBoxSize.blockSize}px;
|
|
142
|
+
}
|
|
143
|
+
`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
private getItemElements() {
|
|
149
|
+
return this.childrenSlot
|
|
150
|
+
.assignedElements()
|
|
151
|
+
.filter(HTMLOverflowContainerElement.isHTMLElement);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
private getOverflowElements() {
|
|
155
|
+
return this.overflowSlot
|
|
156
|
+
.assignedElements()
|
|
157
|
+
.filter(HTMLOverflowContainerElement.isHTMLElement);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
private static isHTMLElement(element: unknown) {
|
|
161
|
+
return element instanceof HTMLElement;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
declare global {
|
|
166
|
+
interface HTMLElementTagNameMap {
|
|
167
|
+
"overflow-container": HTMLOverflowContainerElement;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
globalThis.customElements.define("overflow-container", HTMLOverflowContainerElement);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export class HTMLOverflowContainerEvent<Type extends string, Detail> extends CustomEvent<Detail> {
|
|
2
|
+
constructor(type: Type, eventInitDict: CustomEventInit<Detail>) {
|
|
3
|
+
super(type, eventInitDict);
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export class HTMLOverflowContainerStateEvent extends HTMLOverflowContainerEvent<"state", { overflowingAt?: number }> {
|
|
8
|
+
private constructor(overflowingAt?: number) {
|
|
9
|
+
super("state", { detail: { overflowingAt } });
|
|
10
|
+
}
|
|
11
|
+
}
|
package/package.json
CHANGED
|
@@ -1,49 +1,19 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
"rome": "11.0.0",
|
|
21
|
-
"svelte": "3.55.0",
|
|
22
|
-
"tsup": "6.5.0",
|
|
23
|
-
"typescript": "4.9.4"
|
|
24
|
-
},
|
|
25
|
-
"peerDependencies": {
|
|
26
|
-
"@types/react": "^17.0.0 || ^18.0.0",
|
|
27
|
-
"preact": "^10.0.0",
|
|
28
|
-
"react": "^17.0.0 || ^18.0.0",
|
|
29
|
-
"svelte": "^3.0.0"
|
|
30
|
-
},
|
|
31
|
-
"peerDependenciesMeta": {
|
|
32
|
-
"@types/react": {
|
|
33
|
-
"optional": true
|
|
34
|
-
},
|
|
35
|
-
"preact": {
|
|
36
|
-
"optional": true
|
|
37
|
-
},
|
|
38
|
-
"react": {
|
|
39
|
-
"optional": true
|
|
40
|
-
},
|
|
41
|
-
"svelte": {
|
|
42
|
-
"optional": true
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
"scripts": {
|
|
46
|
-
"build": "tsup",
|
|
47
|
-
"dev": "pnpm --recursive dev"
|
|
48
|
-
}
|
|
49
|
-
}
|
|
2
|
+
"type": "module",
|
|
3
|
+
"name": "overflowed",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"homepage": "https://overflowed.aht.cx",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/ahtcx/overflow-container.git",
|
|
9
|
+
"directory": "packages/core"
|
|
10
|
+
},
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/ahtcx/overflowed"
|
|
13
|
+
},
|
|
14
|
+
"exports": {
|
|
15
|
+
".": "./dist/mod.js",
|
|
16
|
+
"./package.json": "./package.json"
|
|
17
|
+
},
|
|
18
|
+
"version": "v0.0.0-experimental-005"
|
|
19
|
+
}
|
package/LICENSE.md
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2033 Alexandre Hitchcox
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
package/Overflowed-4d9a04ab.d.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
interface OverflowedOptions {
|
|
2
|
-
axis?: "horizontal" | "vertical";
|
|
3
|
-
onUpdate: (visibleItemCount: number, indicatorElementOffset: number) => void;
|
|
4
|
-
disableIndicatorResizeProtection?: boolean;
|
|
5
|
-
ResizeObserver?: typeof ResizeObserver;
|
|
6
|
-
}
|
|
7
|
-
type Breakpoint = [lowerBound: number, upperBound: number];
|
|
8
|
-
declare class Overflowed {
|
|
9
|
-
readonly axis: "horizontal" | "vertical";
|
|
10
|
-
private onUpdate;
|
|
11
|
-
private resizeObserver;
|
|
12
|
-
private containerElement;
|
|
13
|
-
private indicatorElement;
|
|
14
|
-
private indicatorSize?;
|
|
15
|
-
constructor({ ResizeObserver, axis, onUpdate, }: OverflowedOptions);
|
|
16
|
-
registerContainerElement(containerElement: HTMLElement): void;
|
|
17
|
-
registerIndicatorElement(indicatorElement: HTMLElement): void;
|
|
18
|
-
registerItemElement(itemElement: HTMLElement): void;
|
|
19
|
-
/** Should be called before the container element is unmounted. */
|
|
20
|
-
onContainerElementWillUnmount(): void;
|
|
21
|
-
private getElementSize;
|
|
22
|
-
private getElementOffsetFromRight;
|
|
23
|
-
private getElementOffsetFromLeft;
|
|
24
|
-
private getElementComputedValues;
|
|
25
|
-
private update;
|
|
26
|
-
private requestedUpdate;
|
|
27
|
-
requestUpdate(): void;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export { Breakpoint as B, OverflowedOptions as O, Overflowed as a };
|
package/chunk-DZKPYTOC.mjs
DELETED
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
// modules/core/Overflowed.ts
|
|
2
|
-
var Overflowed = class {
|
|
3
|
-
axis;
|
|
4
|
-
onUpdate;
|
|
5
|
-
resizeObserver;
|
|
6
|
-
containerElement = null;
|
|
7
|
-
indicatorElement = null;
|
|
8
|
-
indicatorSize;
|
|
9
|
-
constructor({
|
|
10
|
-
ResizeObserver = typeof window === "undefined" ? void 0 : window.ResizeObserver,
|
|
11
|
-
axis = "horizontal",
|
|
12
|
-
onUpdate
|
|
13
|
-
}) {
|
|
14
|
-
this.resizeObserver = ResizeObserver && new ResizeObserver((entries) => {
|
|
15
|
-
for (const entry of entries) {
|
|
16
|
-
if (entry.target === this.indicatorElement) {
|
|
17
|
-
if (entry.target.clientWidth > 0 && entry.target.clientWidth !== this.indicatorSize) {
|
|
18
|
-
console.warn("width doesn't match", this.indicatorSize, entry.target.clientWidth);
|
|
19
|
-
}
|
|
20
|
-
this.indicatorSize = entry.target.clientWidth;
|
|
21
|
-
} else if (entry.target.parentNode === this.containerElement) {
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
this.requestUpdate();
|
|
25
|
-
});
|
|
26
|
-
this.axis = axis;
|
|
27
|
-
this.onUpdate = onUpdate;
|
|
28
|
-
}
|
|
29
|
-
registerContainerElement(containerElement) {
|
|
30
|
-
this.containerElement = containerElement;
|
|
31
|
-
this.resizeObserver?.observe(containerElement);
|
|
32
|
-
this.requestUpdate();
|
|
33
|
-
}
|
|
34
|
-
registerIndicatorElement(indicatorElement) {
|
|
35
|
-
this.indicatorElement = indicatorElement;
|
|
36
|
-
this.indicatorSize = indicatorElement.clientWidth;
|
|
37
|
-
this.resizeObserver?.observe(indicatorElement);
|
|
38
|
-
this.requestUpdate();
|
|
39
|
-
}
|
|
40
|
-
registerItemElement(itemElement) {
|
|
41
|
-
this.resizeObserver?.observe(itemElement);
|
|
42
|
-
this.requestUpdate();
|
|
43
|
-
}
|
|
44
|
-
onContainerElementWillUnmount() {
|
|
45
|
-
this.resizeObserver?.disconnect();
|
|
46
|
-
this.containerElement = null;
|
|
47
|
-
this.indicatorElement = null;
|
|
48
|
-
}
|
|
49
|
-
getElementSize(element) {
|
|
50
|
-
if (!element) {
|
|
51
|
-
return 0;
|
|
52
|
-
}
|
|
53
|
-
if (this.axis === "horizontal") {
|
|
54
|
-
return element.offsetWidth;
|
|
55
|
-
}
|
|
56
|
-
return element.offsetHeight;
|
|
57
|
-
}
|
|
58
|
-
getElementOffsetFromRight(element) {
|
|
59
|
-
if (!element) {
|
|
60
|
-
return 0;
|
|
61
|
-
}
|
|
62
|
-
if (this.axis === "horizontal") {
|
|
63
|
-
return this.getElementSize(element.parentElement) - this.getElementSize(element) - element.offsetLeft;
|
|
64
|
-
}
|
|
65
|
-
return this.getElementSize(element.parentElement) - this.getElementSize(element) - element.offsetTop;
|
|
66
|
-
}
|
|
67
|
-
getElementOffsetFromLeft(element) {
|
|
68
|
-
if (!element) {
|
|
69
|
-
return 0;
|
|
70
|
-
}
|
|
71
|
-
if (this.axis === "horizontal") {
|
|
72
|
-
return element.offsetLeft;
|
|
73
|
-
}
|
|
74
|
-
return element.offsetTop;
|
|
75
|
-
}
|
|
76
|
-
getElementComputedValues(element) {
|
|
77
|
-
const {
|
|
78
|
-
direction,
|
|
79
|
-
marginBlockStart,
|
|
80
|
-
marginBlockEnd,
|
|
81
|
-
marginInlineStart,
|
|
82
|
-
marginInlineEnd,
|
|
83
|
-
paddingBlockStart,
|
|
84
|
-
paddingBlockEnd,
|
|
85
|
-
paddingInlineStart,
|
|
86
|
-
paddingInlineEnd
|
|
87
|
-
} = window.getComputedStyle(element);
|
|
88
|
-
const marginStartAsString = this.axis === "horizontal" ? marginInlineStart : marginBlockStart;
|
|
89
|
-
const marginEndAsString = this.axis === "horizontal" ? marginInlineEnd : marginBlockEnd;
|
|
90
|
-
const paddingStartAsString = this.axis === "horizontal" ? paddingInlineStart : paddingBlockStart;
|
|
91
|
-
const paddingEndAsString = this.axis === "horizontal" ? paddingInlineEnd : paddingBlockEnd;
|
|
92
|
-
if (marginStartAsString && !marginStartAsString.endsWith("px"))
|
|
93
|
-
throw new Error("ok1");
|
|
94
|
-
if (marginEndAsString && !marginEndAsString.endsWith("px"))
|
|
95
|
-
throw new Error("ok2");
|
|
96
|
-
if (paddingStartAsString && !paddingStartAsString.endsWith("px"))
|
|
97
|
-
throw new Error("ok3");
|
|
98
|
-
if (paddingEndAsString && !paddingEndAsString.endsWith("px"))
|
|
99
|
-
throw new Error("ok4");
|
|
100
|
-
const marginStart = parseInt(marginStartAsString || "0", 10);
|
|
101
|
-
const marginEnd = parseInt(marginEndAsString || "0", 10);
|
|
102
|
-
const paddingStart = parseInt(paddingStartAsString || "0", 10);
|
|
103
|
-
const paddingEnd = parseInt(paddingEndAsString || "0", 10);
|
|
104
|
-
const isRtl = direction === "rtl";
|
|
105
|
-
return { isRtl, marginStart, marginEnd, paddingStart, paddingEnd };
|
|
106
|
-
}
|
|
107
|
-
update() {
|
|
108
|
-
if (!this.containerElement) {
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
const {
|
|
112
|
-
isRtl,
|
|
113
|
-
paddingStart: containerPaddingStart,
|
|
114
|
-
paddingEnd: containerPaddingEnd
|
|
115
|
-
} = this.getElementComputedValues(this.containerElement);
|
|
116
|
-
const indicatorMarginEnd = this.indicatorElement ? this.getElementComputedValues(this.indicatorElement).marginEnd : 0;
|
|
117
|
-
const containerElementSize = this.getElementSize(this.containerElement) - containerPaddingStart - containerPaddingEnd;
|
|
118
|
-
const indicatorElementSize = this.getElementSize(this.indicatorElement) + indicatorMarginEnd;
|
|
119
|
-
const childrenArray = Array.from(this.containerElement.children).filter((element) => element !== this.indicatorElement).filter(isHtmlElement);
|
|
120
|
-
const getOffset = isRtl ? this.getElementOffsetFromRight.bind(this) : this.getElementOffsetFromLeft.bind(this);
|
|
121
|
-
const breakpoints = [];
|
|
122
|
-
for (const childElement of childrenArray.values()) {
|
|
123
|
-
const childOffset = getOffset(childElement);
|
|
124
|
-
const childSize = this.getElementSize(childElement);
|
|
125
|
-
breakpoints.push([childOffset - containerPaddingStart, childOffset + childSize + containerPaddingEnd]);
|
|
126
|
-
}
|
|
127
|
-
if (breakpoints.length === 0) {
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
const containerIntersectingChildIndex = breakpoints.findIndex(([_start, end]) => end > containerElementSize);
|
|
131
|
-
if (containerIntersectingChildIndex !== -1) {
|
|
132
|
-
const intersectingChildIndex = breakpoints.findIndex(
|
|
133
|
-
([start, end]) => (this.indicatorElement ? start : end) > containerElementSize - indicatorElementSize
|
|
134
|
-
);
|
|
135
|
-
const newVisibleItemCount = Math.max(intersectingChildIndex - (this.indicatorElement ? 1 : 0), 0);
|
|
136
|
-
const newIndicatorElementOffset = breakpoints[newVisibleItemCount]?.[0] + containerPaddingStart;
|
|
137
|
-
this.onUpdate(newVisibleItemCount, newIndicatorElementOffset);
|
|
138
|
-
} else {
|
|
139
|
-
this.onUpdate(breakpoints.length, 0);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
requestedUpdate = false;
|
|
143
|
-
requestUpdate() {
|
|
144
|
-
if (this.requestedUpdate) {
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
this.requestedUpdate = true;
|
|
148
|
-
this.update();
|
|
149
|
-
window.requestAnimationFrame(() => {
|
|
150
|
-
this.requestedUpdate = false;
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
};
|
|
154
|
-
var isHtmlElement = (element) => {
|
|
155
|
-
if (element instanceof HTMLElement) {
|
|
156
|
-
return true;
|
|
157
|
-
}
|
|
158
|
-
throw new Error("Element provided is not a HTMLElement.");
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
export {
|
|
162
|
-
Overflowed
|
|
163
|
-
};
|
package/chunk-TXQIKLPR.mjs
DELETED
|
File without changes
|
package/core/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { B as Breakpoint, a as Overflowed, O as OverflowedOptions } from '../Overflowed-4d9a04ab.js';
|
package/core/index.js
DELETED
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// modules/core/index.ts
|
|
21
|
-
var core_exports = {};
|
|
22
|
-
__export(core_exports, {
|
|
23
|
-
Overflowed: () => Overflowed
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(core_exports);
|
|
26
|
-
|
|
27
|
-
// modules/core/Overflowed.ts
|
|
28
|
-
var Overflowed = class {
|
|
29
|
-
axis;
|
|
30
|
-
onUpdate;
|
|
31
|
-
resizeObserver;
|
|
32
|
-
containerElement = null;
|
|
33
|
-
indicatorElement = null;
|
|
34
|
-
indicatorSize;
|
|
35
|
-
constructor({
|
|
36
|
-
ResizeObserver = typeof window === "undefined" ? void 0 : window.ResizeObserver,
|
|
37
|
-
axis = "horizontal",
|
|
38
|
-
onUpdate
|
|
39
|
-
}) {
|
|
40
|
-
this.resizeObserver = ResizeObserver && new ResizeObserver((entries) => {
|
|
41
|
-
for (const entry of entries) {
|
|
42
|
-
if (entry.target === this.indicatorElement) {
|
|
43
|
-
if (entry.target.clientWidth > 0 && entry.target.clientWidth !== this.indicatorSize) {
|
|
44
|
-
console.warn("width doesn't match", this.indicatorSize, entry.target.clientWidth);
|
|
45
|
-
}
|
|
46
|
-
this.indicatorSize = entry.target.clientWidth;
|
|
47
|
-
} else if (entry.target.parentNode === this.containerElement) {
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
this.requestUpdate();
|
|
51
|
-
});
|
|
52
|
-
this.axis = axis;
|
|
53
|
-
this.onUpdate = onUpdate;
|
|
54
|
-
}
|
|
55
|
-
registerContainerElement(containerElement) {
|
|
56
|
-
this.containerElement = containerElement;
|
|
57
|
-
this.resizeObserver?.observe(containerElement);
|
|
58
|
-
this.requestUpdate();
|
|
59
|
-
}
|
|
60
|
-
registerIndicatorElement(indicatorElement) {
|
|
61
|
-
this.indicatorElement = indicatorElement;
|
|
62
|
-
this.indicatorSize = indicatorElement.clientWidth;
|
|
63
|
-
this.resizeObserver?.observe(indicatorElement);
|
|
64
|
-
this.requestUpdate();
|
|
65
|
-
}
|
|
66
|
-
registerItemElement(itemElement) {
|
|
67
|
-
this.resizeObserver?.observe(itemElement);
|
|
68
|
-
this.requestUpdate();
|
|
69
|
-
}
|
|
70
|
-
onContainerElementWillUnmount() {
|
|
71
|
-
this.resizeObserver?.disconnect();
|
|
72
|
-
this.containerElement = null;
|
|
73
|
-
this.indicatorElement = null;
|
|
74
|
-
}
|
|
75
|
-
getElementSize(element) {
|
|
76
|
-
if (!element) {
|
|
77
|
-
return 0;
|
|
78
|
-
}
|
|
79
|
-
if (this.axis === "horizontal") {
|
|
80
|
-
return element.offsetWidth;
|
|
81
|
-
}
|
|
82
|
-
return element.offsetHeight;
|
|
83
|
-
}
|
|
84
|
-
getElementOffsetFromRight(element) {
|
|
85
|
-
if (!element) {
|
|
86
|
-
return 0;
|
|
87
|
-
}
|
|
88
|
-
if (this.axis === "horizontal") {
|
|
89
|
-
return this.getElementSize(element.parentElement) - this.getElementSize(element) - element.offsetLeft;
|
|
90
|
-
}
|
|
91
|
-
return this.getElementSize(element.parentElement) - this.getElementSize(element) - element.offsetTop;
|
|
92
|
-
}
|
|
93
|
-
getElementOffsetFromLeft(element) {
|
|
94
|
-
if (!element) {
|
|
95
|
-
return 0;
|
|
96
|
-
}
|
|
97
|
-
if (this.axis === "horizontal") {
|
|
98
|
-
return element.offsetLeft;
|
|
99
|
-
}
|
|
100
|
-
return element.offsetTop;
|
|
101
|
-
}
|
|
102
|
-
getElementComputedValues(element) {
|
|
103
|
-
const {
|
|
104
|
-
direction,
|
|
105
|
-
marginBlockStart,
|
|
106
|
-
marginBlockEnd,
|
|
107
|
-
marginInlineStart,
|
|
108
|
-
marginInlineEnd,
|
|
109
|
-
paddingBlockStart,
|
|
110
|
-
paddingBlockEnd,
|
|
111
|
-
paddingInlineStart,
|
|
112
|
-
paddingInlineEnd
|
|
113
|
-
} = window.getComputedStyle(element);
|
|
114
|
-
const marginStartAsString = this.axis === "horizontal" ? marginInlineStart : marginBlockStart;
|
|
115
|
-
const marginEndAsString = this.axis === "horizontal" ? marginInlineEnd : marginBlockEnd;
|
|
116
|
-
const paddingStartAsString = this.axis === "horizontal" ? paddingInlineStart : paddingBlockStart;
|
|
117
|
-
const paddingEndAsString = this.axis === "horizontal" ? paddingInlineEnd : paddingBlockEnd;
|
|
118
|
-
if (marginStartAsString && !marginStartAsString.endsWith("px"))
|
|
119
|
-
throw new Error("ok1");
|
|
120
|
-
if (marginEndAsString && !marginEndAsString.endsWith("px"))
|
|
121
|
-
throw new Error("ok2");
|
|
122
|
-
if (paddingStartAsString && !paddingStartAsString.endsWith("px"))
|
|
123
|
-
throw new Error("ok3");
|
|
124
|
-
if (paddingEndAsString && !paddingEndAsString.endsWith("px"))
|
|
125
|
-
throw new Error("ok4");
|
|
126
|
-
const marginStart = parseInt(marginStartAsString || "0", 10);
|
|
127
|
-
const marginEnd = parseInt(marginEndAsString || "0", 10);
|
|
128
|
-
const paddingStart = parseInt(paddingStartAsString || "0", 10);
|
|
129
|
-
const paddingEnd = parseInt(paddingEndAsString || "0", 10);
|
|
130
|
-
const isRtl = direction === "rtl";
|
|
131
|
-
return { isRtl, marginStart, marginEnd, paddingStart, paddingEnd };
|
|
132
|
-
}
|
|
133
|
-
update() {
|
|
134
|
-
if (!this.containerElement) {
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
const {
|
|
138
|
-
isRtl,
|
|
139
|
-
paddingStart: containerPaddingStart,
|
|
140
|
-
paddingEnd: containerPaddingEnd
|
|
141
|
-
} = this.getElementComputedValues(this.containerElement);
|
|
142
|
-
const indicatorMarginEnd = this.indicatorElement ? this.getElementComputedValues(this.indicatorElement).marginEnd : 0;
|
|
143
|
-
const containerElementSize = this.getElementSize(this.containerElement) - containerPaddingStart - containerPaddingEnd;
|
|
144
|
-
const indicatorElementSize = this.getElementSize(this.indicatorElement) + indicatorMarginEnd;
|
|
145
|
-
const childrenArray = Array.from(this.containerElement.children).filter((element) => element !== this.indicatorElement).filter(isHtmlElement);
|
|
146
|
-
const getOffset = isRtl ? this.getElementOffsetFromRight.bind(this) : this.getElementOffsetFromLeft.bind(this);
|
|
147
|
-
const breakpoints = [];
|
|
148
|
-
for (const childElement of childrenArray.values()) {
|
|
149
|
-
const childOffset = getOffset(childElement);
|
|
150
|
-
const childSize = this.getElementSize(childElement);
|
|
151
|
-
breakpoints.push([childOffset - containerPaddingStart, childOffset + childSize + containerPaddingEnd]);
|
|
152
|
-
}
|
|
153
|
-
if (breakpoints.length === 0) {
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
const containerIntersectingChildIndex = breakpoints.findIndex(([_start, end]) => end > containerElementSize);
|
|
157
|
-
if (containerIntersectingChildIndex !== -1) {
|
|
158
|
-
const intersectingChildIndex = breakpoints.findIndex(
|
|
159
|
-
([start, end]) => (this.indicatorElement ? start : end) > containerElementSize - indicatorElementSize
|
|
160
|
-
);
|
|
161
|
-
const newVisibleItemCount = Math.max(intersectingChildIndex - (this.indicatorElement ? 1 : 0), 0);
|
|
162
|
-
const newIndicatorElementOffset = breakpoints[newVisibleItemCount]?.[0] + containerPaddingStart;
|
|
163
|
-
this.onUpdate(newVisibleItemCount, newIndicatorElementOffset);
|
|
164
|
-
} else {
|
|
165
|
-
this.onUpdate(breakpoints.length, 0);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
requestedUpdate = false;
|
|
169
|
-
requestUpdate() {
|
|
170
|
-
if (this.requestedUpdate) {
|
|
171
|
-
return;
|
|
172
|
-
}
|
|
173
|
-
this.requestedUpdate = true;
|
|
174
|
-
this.update();
|
|
175
|
-
window.requestAnimationFrame(() => {
|
|
176
|
-
this.requestedUpdate = false;
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
};
|
|
180
|
-
var isHtmlElement = (element) => {
|
|
181
|
-
if (element instanceof HTMLElement) {
|
|
182
|
-
return true;
|
|
183
|
-
}
|
|
184
|
-
throw new Error("Element provided is not a HTMLElement.");
|
|
185
|
-
};
|
|
186
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
187
|
-
0 && (module.exports = {
|
|
188
|
-
Overflowed
|
|
189
|
-
});
|
package/core/index.mjs
DELETED
package/index.d.ts
DELETED