@chronocide/hyper 1.0.1 → 1.1.1
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/dist/hyper.d.ts +5 -2
- package/dist/hyper.js +6 -4
- package/package.json +1 -1
package/dist/hyper.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
type CellOptions<T> = {
|
|
2
2
|
/** If empty, equal to container width */
|
|
3
|
-
width?: number | ((data: T, i: number, arr: T[]) => number | null);
|
|
3
|
+
width?: number | ((data: T, i: number, arr: T[]) => number | null) | null;
|
|
4
4
|
/** If true, cells do not fill container width */
|
|
5
5
|
gap?: boolean;
|
|
6
6
|
height: number | ((data: T, i: number, arr: T[]) => number);
|
|
@@ -34,7 +34,10 @@ declare const svg: <T extends keyof SVGElementTagNameMap>(tag: T) => <P extends
|
|
|
34
34
|
declare const mathml: <T extends keyof MathMLElementEventMap>(tag: T) => <P extends Attributes>(attributes?: P) => (...children: Child[]) => MathMLElement;
|
|
35
35
|
declare const xml: (tag: string) => <P extends Attributes>(attributes?: P) => (...children: Child[]) => HTMLElement;
|
|
36
36
|
declare const list: <T extends Json>(render: (x: T, i: number, arr: T[]) => Element) => (root: Element) => (next: T[]) => void;
|
|
37
|
-
declare const virtual: <T>(cell: CellOptions<T>) => (render: (
|
|
37
|
+
declare const virtual: <T>(cell: CellOptions<T>) => (render: (x: T, i: {
|
|
38
|
+
real: number;
|
|
39
|
+
virtual: number;
|
|
40
|
+
}, arr: T[]) => HTMLElement) => (root: HTMLElement) => {
|
|
38
41
|
update: (next: T[]) => void;
|
|
39
42
|
scrollTo: (i: number) => void;
|
|
40
43
|
};
|
package/dist/hyper.js
CHANGED
|
@@ -73,7 +73,9 @@ const bisectRight = (arr) => (n) => {
|
|
|
73
73
|
const cells = (cell) => (container) => (data) => fill(data.length)((i, arr) => {
|
|
74
74
|
const prev = get(arr)(i - 1);
|
|
75
75
|
const height2 = typeof cell.height === "number" ? cell.height : cell.height(data[i], i, data);
|
|
76
|
-
let width =
|
|
76
|
+
let width = container.width;
|
|
77
|
+
if (typeof cell.width === "number") width = cell.width;
|
|
78
|
+
if (typeof cell.width === "function") width = cell.width(data[i], i, data) ?? container.width;
|
|
77
79
|
if (!cell.gap) {
|
|
78
80
|
const rows = Math.max(1, Math.floor(container.width / width));
|
|
79
81
|
width = Math.floor(container.width / rows);
|
|
@@ -190,8 +192,8 @@ const virtual$1 = (env) => (cell) => (render) => (root) => {
|
|
|
190
192
|
"z-index": "-1"
|
|
191
193
|
}
|
|
192
194
|
})();
|
|
193
|
-
root.replaceChildren(...cache.slice(min, max + 1).map((cell2) => {
|
|
194
|
-
const child = render(cell2.i);
|
|
195
|
+
root.replaceChildren(...cache.slice(min, max + 1).map((cell2, j) => {
|
|
196
|
+
const child = render(state[cell2.i], { real: cell2.i, virtual: j }, state);
|
|
195
197
|
style(child)({
|
|
196
198
|
position: "absolute",
|
|
197
199
|
transform: `translate(${cell2.x}px, ${cell2.y}px)`,
|
|
@@ -202,7 +204,7 @@ const virtual$1 = (env) => (cell) => (render) => (root) => {
|
|
|
202
204
|
}), spacer);
|
|
203
205
|
});
|
|
204
206
|
root.addEventListener("scroll", () => update(false), { passive: true });
|
|
205
|
-
|
|
207
|
+
env.window.addEventListener("resize", () => update(true), { passive: true });
|
|
206
208
|
return {
|
|
207
209
|
update: (next) => {
|
|
208
210
|
state = next;
|