@andamento/dom 0.1.0 → 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.
@@ -0,0 +1,169 @@
1
+ import { Cell, Layout, ContentCells, ContentPlacement, Rect, Focus, LayoutOptions } from '@andamento/core';
2
+ import { ReliefPath, FillSource, ReliefOptions } from '@andamento/svg';
3
+
4
+ /**
5
+ * The parts of an HTML tile layout that don't depend on a framework: what each tile's
6
+ * element looks like, what keys do, what's in view. `mountTileLayout`, the
7
+ * `<andamento-layout>` element and the Vue components all render from these.
8
+ */
9
+ /** How a layout's `fit` option sizes its tiles. */
10
+ type FitProp = boolean | "atLeast" | "nearest";
11
+ /** What a per-cell option function is told about the cell besides its geometry. */
12
+ interface CellState {
13
+ /** The cell has no content. */
14
+ empty: boolean;
15
+ /** Position among the cells that hold content, in reading order (the item index), or -1. */
16
+ slot: number;
17
+ }
18
+ /**
19
+ * Put each tile's content in its safe area: `true` or "tile" fits the whole tile (for a tile
20
+ * an `edges: "window"` layout cuts, content near the edge is then partly hidden like the
21
+ * tile), "visible" fits the part that shows. See `SafeAreaOptions.within`.
22
+ */
23
+ type SafeAreaProp = boolean | "tile" | "visible";
24
+ /** A value, or a function giving it per cell. */
25
+ type PerCell<T> = T | ((cell: Cell, state: CellState) => T);
26
+ declare const resolvePerCell: <T>(v: PerCell<T> | undefined, cell: Cell, state: CellState) => T | undefined;
27
+ /** Style as property → value, camelCase (`clipPath`) or custom (`--x`). */
28
+ type StyleMap = Record<string, string | number | undefined>;
29
+ /** Clip paths get this many points when animating, so any two tile shapes can morph. */
30
+ declare const MORPH_POINTS = 72;
31
+ /**
32
+ * A key for options that changes when they change: compared by value, with any function in
33
+ * them (`sizeAt`, say) by identity, which JSON alone would leave out.
34
+ */
35
+ declare function optionsKey(value: unknown): string;
36
+ /** What a layout's items need from it: how many there are, and how they're sized and placed. */
37
+ interface LayoutNeeds {
38
+ fit?: FitProp;
39
+ count: number;
40
+ cells?: ContentCells;
41
+ /** Tiles each item spans (see `weightedLayout`); heavier items get featured tiles. */
42
+ weights?: readonly number[];
43
+ placement?: ContentPlacement;
44
+ }
45
+ /**
46
+ * A layout from options, worked out again only when they change (compared by value; a
47
+ * `cells` function by identity). Returns `layout` itself when given.
48
+ */
49
+ declare function layoutResolver(component: string): (options: LayoutOptions | undefined, layout: Layout | undefined, fit?: LayoutNeeds) => Layout;
50
+ interface FrameOptions {
51
+ /** How many items there are to place (Infinity when every allowed cell gets content). */
52
+ count: number;
53
+ aspects?: readonly number[];
54
+ contentCells?: ContentCells;
55
+ placement?: ContentPlacement;
56
+ choose?: "placement" | "shape";
57
+ fill?: FillSource;
58
+ relief?: boolean | ReliefOptions;
59
+ animate?: boolean | {
60
+ duration?: number;
61
+ easing?: string;
62
+ };
63
+ }
64
+ /** Everything about a layout's tiles shared between them. */
65
+ interface Frame {
66
+ layout: Layout;
67
+ /** Item index per cell, or -1. */
68
+ slots: number[];
69
+ /** Empty-tile color per cell. */
70
+ fills: string[];
71
+ /** Bevel paths for a cell (worked out on first use), or undefined without relief. */
72
+ bevel(index: number): ReliefPath[] | undefined;
73
+ shadow?: {
74
+ dx: number;
75
+ dy: number;
76
+ blur: number;
77
+ opacity: number;
78
+ };
79
+ anim?: {
80
+ duration: number;
81
+ easing: string;
82
+ };
83
+ /** `left, top, width, height` transitions, when animating. */
84
+ boxTransition?: string;
85
+ tileTransition?: string;
86
+ }
87
+ /** Builds frames, reusing the slots, fills and bevels of the last one where nothing they depend on changed. */
88
+ declare function frameBuilder(): (layout: Layout, o: FrameOptions) => Frame;
89
+ /** Style of the element holding the layout. */
90
+ declare const containerStyle: (layout: Layout) => StyleMap;
91
+ /** Style of the element painting `background` across the region (seen through the gaps). */
92
+ declare const backgroundStyle: (frame: Frame, background: string) => StyleMap;
93
+ /**
94
+ * A tile's element: placed over its cell's bounding box and clipped to its shape. Empty
95
+ * tiles (and every tile with `safeArea`) show their fill unless there's a backdrop.
96
+ */
97
+ declare function tileStyle(frame: Frame, cell: Cell, o: {
98
+ empty: boolean;
99
+ safeArea?: SafeAreaProp;
100
+ backdrop?: boolean;
101
+ clickable?: boolean;
102
+ focus?: Focus;
103
+ aspect?: number;
104
+ }): StyleMap;
105
+ /**
106
+ * The `--andamento-object-position` a tile sets for its content's focal point, which
107
+ * `coverStyle` uses as its `object-position`. Exact with the image's `aspect` (given, or the focus's own; see
108
+ * `objectPosition`); without, the focus as a percentage, which CSS keeps at the same place
109
+ * in the tile's box rather than in the middle of what shows.
110
+ */
111
+ declare function focusStyle(frame: Frame, cell: Cell, focus: Focus, aspect?: number): StyleMap;
112
+ /** A backdrop copy inside a tile: behind its content, covering the whole layout. */
113
+ declare const backdropStyle: (frame: Frame, cell: Cell) => StyleMap;
114
+ /** The box holding a tile's content with `safeArea`. */
115
+ declare const safeBoxStyle: (frame: Frame, cell: Cell, aspect?: number, safe?: SafeAreaProp) => StyleMap;
116
+ /** Style of an <svg> drawn over a tile (bevel, focus ring), with `viewBox` set to `tileViewBox`. */
117
+ declare const overlayStyle: StyleMap;
118
+ declare const tileViewBox: (cell: Cell) => string;
119
+ /** The focus ring's two strokes: white under the color, so it shows on any content. */
120
+ declare const ringStrokes: (frame: Frame, cell: Cell, color: string) => {
121
+ d: string;
122
+ stroke: string;
123
+ width: number;
124
+ }[];
125
+ /** The shadow tiles cast into the grout (with relief's `shadow`), for an <svg> over the region. */
126
+ declare function shadowShape(frame: Frame, cells: readonly Cell[]): {
127
+ viewBox: string;
128
+ style: StyleMap;
129
+ blur: number;
130
+ d: string;
131
+ transform: string;
132
+ opacity: number;
133
+ } | undefined;
134
+ /**
135
+ * What a key does on a focused tile: move focus to another tile, activate it, or just stop
136
+ * the page scrolling (arrows at the edge). Undefined for keys that aren't ours.
137
+ */
138
+ declare function keyAction(layout: Layout, from: Cell, key: string, accept: (cell: Cell) => boolean, canActivate: boolean): {
139
+ move: Cell;
140
+ } | {
141
+ activate: true;
142
+ } | {
143
+ prevent: true;
144
+ } | undefined;
145
+ /** Style sheet text for focus rings and animation (empty when neither is on). */
146
+ declare function tileSheet(o: {
147
+ focusRing: boolean;
148
+ anim?: {
149
+ duration: number;
150
+ easing: string;
151
+ };
152
+ }): string;
153
+ /** "Nothing in view": `view` before the layout has been measured, or when it's off screen. */
154
+ declare const NOTHING_IN_VIEW: Rect;
155
+ /**
156
+ * The part of the layout in view (in layout units), widened by `overscan` pixels and
157
+ * snapped outwards to a coarse grid so small scrolls give the same rectangle.
158
+ */
159
+ declare function viewRect(el: Element, layout: Layout, overscan: number): Rect;
160
+ declare const sameRect: (a: Rect | undefined, b: Rect | undefined) => boolean;
161
+ /**
162
+ * Call `measure` now and again (at most once a frame) whenever the page or any scrolling
163
+ * container scrolls, the window resizes or `el` does. Returns a function that stops it.
164
+ */
165
+ declare function watchView(el: Element, measure: () => void): () => void;
166
+ /** Style that makes an <img> or <video> cover its tile, like `object-fit: cover`. */
167
+ declare const coverStyle: StyleMap;
168
+
169
+ export { type CellState as C, type FitProp as F, type LayoutNeeds as L, MORPH_POINTS as M, NOTHING_IN_VIEW as N, type PerCell as P, type SafeAreaProp as S, type StyleMap as a, type Frame as b, coverStyle as c, type FrameOptions as d, backdropStyle as e, backgroundStyle as f, containerStyle as g, focusStyle as h, frameBuilder as i, overlayStyle as j, keyAction as k, layoutResolver as l, ringStrokes as m, sameRect as n, optionsKey as o, shadowShape as p, tileStyle as q, resolvePerCell as r, safeBoxStyle as s, tileSheet as t, tileViewBox as u, viewRect as v, watchView as w };
@@ -0,0 +1,47 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+ var _chunk276TFSAGcjs = require('./chunk-276TFSAG.cjs');
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+ exports.MORPH_POINTS = _chunk276TFSAGcjs.MORPH_POINTS; exports.NOTHING_IN_VIEW = _chunk276TFSAGcjs.NOTHING_IN_VIEW; exports.backdropStyle = _chunk276TFSAGcjs.backdropStyle; exports.backgroundStyle = _chunk276TFSAGcjs.backgroundStyle; exports.containerStyle = _chunk276TFSAGcjs.containerStyle; exports.focusStyle = _chunk276TFSAGcjs.focusStyle; exports.frameBuilder = _chunk276TFSAGcjs.frameBuilder; exports.keyAction = _chunk276TFSAGcjs.keyAction; exports.layoutResolver = _chunk276TFSAGcjs.layoutResolver; exports.optionsKey = _chunk276TFSAGcjs.optionsKey; exports.overlayStyle = _chunk276TFSAGcjs.overlayStyle; exports.resolvePerCell = _chunk276TFSAGcjs.resolvePerCell; exports.ringStrokes = _chunk276TFSAGcjs.ringStrokes; exports.safeBoxStyle = _chunk276TFSAGcjs.safeBoxStyle; exports.sameRect = _chunk276TFSAGcjs.sameRect; exports.shadowShape = _chunk276TFSAGcjs.shadowShape; exports.tileSheet = _chunk276TFSAGcjs.tileSheet; exports.tileStyle = _chunk276TFSAGcjs.tileStyle; exports.tileViewBox = _chunk276TFSAGcjs.tileViewBox; exports.viewRect = _chunk276TFSAGcjs.viewRect; exports.watchView = _chunk276TFSAGcjs.watchView;
47
+ //# sourceMappingURL=internal.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/matthewputnam/code/andamento/packages/dom/dist/internal.cjs"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,smCAAC","file":"/Users/matthewputnam/code/andamento/packages/dom/dist/internal.cjs"}
@@ -0,0 +1,3 @@
1
+ export { b as Frame, d as FrameOptions, L as LayoutNeeds, M as MORPH_POINTS, N as NOTHING_IN_VIEW, e as backdropStyle, f as backgroundStyle, g as containerStyle, h as focusStyle, i as frameBuilder, k as keyAction, l as layoutResolver, o as optionsKey, j as overlayStyle, r as resolvePerCell, m as ringStrokes, s as safeBoxStyle, n as sameRect, p as shadowShape, t as tileSheet, q as tileStyle, u as tileViewBox, v as viewRect, w as watchView } from './internal-NveCwJWd.cjs';
2
+ import '@andamento/core';
3
+ import '@andamento/svg';
@@ -0,0 +1,3 @@
1
+ export { b as Frame, d as FrameOptions, L as LayoutNeeds, M as MORPH_POINTS, N as NOTHING_IN_VIEW, e as backdropStyle, f as backgroundStyle, g as containerStyle, h as focusStyle, i as frameBuilder, k as keyAction, l as layoutResolver, o as optionsKey, j as overlayStyle, r as resolvePerCell, m as ringStrokes, s as safeBoxStyle, n as sameRect, p as shadowShape, t as tileSheet, q as tileStyle, u as tileViewBox, v as viewRect, w as watchView } from './internal-NveCwJWd.js';
2
+ import '@andamento/core';
3
+ import '@andamento/svg';
@@ -0,0 +1,47 @@
1
+ import {
2
+ MORPH_POINTS,
3
+ NOTHING_IN_VIEW,
4
+ backdropStyle,
5
+ backgroundStyle,
6
+ containerStyle,
7
+ focusStyle,
8
+ frameBuilder,
9
+ keyAction,
10
+ layoutResolver,
11
+ optionsKey,
12
+ overlayStyle,
13
+ resolvePerCell,
14
+ ringStrokes,
15
+ safeBoxStyle,
16
+ sameRect,
17
+ shadowShape,
18
+ tileSheet,
19
+ tileStyle,
20
+ tileViewBox,
21
+ viewRect,
22
+ watchView
23
+ } from "./chunk-RCXEXYRF.js";
24
+ export {
25
+ MORPH_POINTS,
26
+ NOTHING_IN_VIEW,
27
+ backdropStyle,
28
+ backgroundStyle,
29
+ containerStyle,
30
+ focusStyle,
31
+ frameBuilder,
32
+ keyAction,
33
+ layoutResolver,
34
+ optionsKey,
35
+ overlayStyle,
36
+ resolvePerCell,
37
+ ringStrokes,
38
+ safeBoxStyle,
39
+ sameRect,
40
+ shadowShape,
41
+ tileSheet,
42
+ tileStyle,
43
+ tileViewBox,
44
+ viewRect,
45
+ watchView
46
+ };
47
+ //# sourceMappingURL=internal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@andamento/dom",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Framework-free @andamento tiling layouts: mount one into any element, or use the <andamento-layout> web component.",
5
5
  "keywords": [
6
6
  "tiling",
@@ -43,6 +43,16 @@
43
43
  "types": "./dist/index.d.cts",
44
44
  "default": "./dist/index.cjs"
45
45
  }
46
+ },
47
+ "./internal": {
48
+ "import": {
49
+ "types": "./dist/internal.d.ts",
50
+ "default": "./dist/internal.js"
51
+ },
52
+ "require": {
53
+ "types": "./dist/internal.d.cts",
54
+ "default": "./dist/internal.cjs"
55
+ }
46
56
  }
47
57
  },
48
58
  "files": [
@@ -56,8 +66,8 @@
56
66
  "typecheck": "tsc --noEmit -p ."
57
67
  },
58
68
  "dependencies": {
59
- "@andamento/core": "0.1.0",
60
- "@andamento/svg": "0.1.0"
69
+ "@andamento/core": "0.2.0",
70
+ "@andamento/svg": "0.2.0"
61
71
  },
62
72
  "publishConfig": {
63
73
  "access": "public"