@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 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: (i: number) => HTMLElement) => (root: HTMLElement) => {
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 = typeof cell.width === "number" ? cell.width : cell.width?.(data[i], i, data) ?? container.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
- root.addEventListener("resize", () => update(true), { passive: true });
207
+ env.window.addEventListener("resize", () => update(true), { passive: true });
206
208
  return {
207
209
  update: (next) => {
208
210
  state = next;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chronocide/hyper",
3
- "version": "1.0.1",
3
+ "version": "1.1.1",
4
4
  "type": "module",
5
5
  "types": "dist/hyper.d.ts",
6
6
  "exports": {