@marktiderman/genesis-core 2.13.0 → 2.14.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/dist/gallery/index.d.ts
CHANGED
|
@@ -24,6 +24,11 @@ interface GalleryItem {
|
|
|
24
24
|
width?: number;
|
|
25
25
|
height?: number;
|
|
26
26
|
caption?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Native only: caches the picture under this key instead of `src` (`NativeImage`'s
|
|
29
|
+
* `cacheKey`), for signed URLs that rotate. The web grid ignores it.
|
|
30
|
+
*/
|
|
31
|
+
cacheKey?: string;
|
|
27
32
|
}
|
|
28
33
|
/**
|
|
29
34
|
* The gallery's defaults, the same on web and native: a target row height and the space between
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/gallery/index.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"sources":["../../src/gallery/index.ts"],"names":[],"mappings":";AAwCO,IAAM,mBAAmB,EAAE,SAAA,EAAW,KAAK,GAAA,EAAK,CAAA,EAAG,SAAS,CAAA;AAW5D,IAAM,wBAAwB,CAAA,GAAI;AAiBlC,SAAS,iBAAiB,IAAA,EAA2B;AAC1D,EAAA,MAAM,EAAE,KAAA,EAAO,MAAA,EAAO,GAAI,IAAA;AAC1B,EAAA,IACE,OAAO,KAAA,KAAU,QAAA,IACjB,OAAO,MAAA,KAAW,YAClB,MAAA,CAAO,QAAA,CAAS,KAAK,CAAA,IACrB,OAAO,QAAA,CAAS,MAAM,KACtB,KAAA,GAAQ,CAAA,IACR,SAAS,CAAA,EACT;AACA,IAAA,OAAO,KAAA,GAAQ,MAAA;AAAA,EACjB;AACA,EAAA,OAAO,qBAAA;AACT;AAiBO,SAAS,WAAA,CACd,KAAA,EACA,cAAA,EACA,SAAA,EACA,GAAA,EACgB;AAChB,EAAA,IAAI,EAAE,cAAA,GAAiB,CAAA,CAAA,IAAM,EAAE,SAAA,GAAY,MAAM,KAAA,CAAM,M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B,IAAI,CAAA,GAAI,SAAA;AAAA,MAChC,MAAA,EAAQ;AAAA,KACV;AACA,IAAA,MAAM,QAAA,GAAW,CAAC,GAAG,OAAA,EAAS,IAAI,CAAA;AAClC,IAAA,MAAM,aAAA,GAAgB,gBAAA,CAAiB,QAAA,EAAU,YAAA,GAAe,KAAK,KAAK,CAAA;AAE1E,IAAA,IAAI,gBAAgB,cAAA,EAAgB;AAClC,MAAA,OAAA,GAAU,QAAA;AACV,MAAA,YAAA,IAAgB,IAAA,CAAK,KAAA;AACrB,MAAA;AAAA,IACF;AAIA,IAAA,MAAM,YAAA,GAAe,gBAAA,CAAiB,OAAA,EAAS,YAAY,CAAA;AAC3D,IAAA,MAAM,IAAA,GACJ,OAAA,CAAQ,MAAA,KAAW,CAAA,IACnB,IAAA,CAAK,GAAA,CAAI,aAAA,GAAgB,cAAc,CAAA,IAAK,IAAA,CAAK,GAAA,CAAI,cAAA,GAAiB,YAAY,CAAA;AAEpF,IAAA,IAAI,IAAA,EAAM;AACR,MAAA,KAAA,CAAM,QAAA,EAAU,YAAA,GAAe,IAAA,CAAK,KAAA,EAAO,KAAK,CAAA;AAChD,MAAA,OAAA,GAAU,EAAC;AACX,MAAA,YAAA,GAAe,CAAA;AAAA,IACjB,CAAA,MAAO;AACL,MAAA,KAAA,CAAM,OAAA,EAAS,cAAc,KAAK,CAAA;AAClC,MAAA,OAAA,GAAU,CAAC,IAAI,CAAA;AACf,MAAA,YAAA,GAAe,IAAA,CAAK,KAAA;AAAA,IACtB;AAAA,EACF,CAAC,CAAA;AAED,EAAA,KAAA,CAAM,OAAA,EAAS,cAAc,IAAI,CAAA;AACjC,EAAA,OAAO,IAAA;AACT","file":"index.js","sourcesContent":["/**\n * The gallery's data and layout, the same on every platform: one image's shape, the defaults, and\n * the justified-rows packing. genesis-ui's `GalleryGrid` and genesis-ui-native's\n * `NativeGalleryGrid` both lay out with `justifyRows` from here, as does ResourceView's\n * `mode=\"grid\"` over a view's `gallery` block, so the same items pack into the same rows anywhere.\n *\n * Pure: no React, no DOM.\n *\n * @stability Beta\n */\n\n/**\n * One image in a gallery. Shared by `GalleryGrid`, `Lightbox` and their native twins, so a\n * consumer passes the same array to the grid and to the viewer it opens.\n *\n * `width`/`height` are the image's intrinsic pixel size when known; the justified layout uses\n * their ratio to pack rows and falls back to 4:3 when they are absent.\n *\n * @stability Beta\n */\nexport interface GalleryItem {\n id: string;\n src: string;\n alt?: string;\n width?: number;\n height?: number;\n caption?: string;\n /**\n * Native only: caches the picture under this key instead of `src` (`NativeImage`'s\n * `cacheKey`), for signed URLs that rotate. The web grid ignores it.\n */\n cacheKey?: string;\n}\n\n/**\n * The gallery's defaults, the same on web and native: a target row height and the space between\n * tiles (px on web, points on native), and the columns of `layout=\"grid\"`.\n *\n * @stability Beta\n */\nexport const GALLERY_DEFAULTS = { rowHeight: 180, gap: 4, columns: 3 } as const;\n\n/**\n * A `layout=\"grid\"` tile's shape: a ratio (width / height; 1 is square, the default), or `\"item\"`\n * for each item's own (its `width`/`height`, 4:3 when unknown).\n *\n * @stability Beta\n */\nexport type GalleryTileAspect = number | \"item\";\n\n/** Used when an item has no `width`/`height` (or a degenerate one). */\nexport const DEFAULT_GALLERY_RATIO = 4 / 3;\n\nexport interface JustifiedTile {\n item: GalleryItem;\n /** Index of `item` in the input array. */\n index: number;\n width: number;\n height: number;\n}\n\nexport interface JustifiedRow {\n tiles: JustifiedTile[];\n /** The row's height after scaling to fill the container. */\n height: number;\n}\n\n/** Width ÷ height of an item, falling back to 4:3. */\nexport function galleryItemRatio(item: GalleryItem): number {\n const { width, height } = item;\n if (\n typeof width === \"number\" &&\n typeof height === \"number\" &&\n Number.isFinite(width) &&\n Number.isFinite(height) &&\n width > 0 &&\n height > 0\n ) {\n return width / height;\n }\n return DEFAULT_GALLERY_RATIO;\n}\n\n/**\n * Pack `items` into rows of a target `rowHeight`, then scale each row so its\n * tiles exactly fill `containerWidth` (minus `gap` between tiles). Pure: same\n * input, same rows.\n *\n * Greedy, as in the classic justified-gallery algorithm: tiles are added at\n * the target height until the row would overflow; the row is then closed at\n * whichever of \"with\" / \"without\" the overflowing tile is nearer the target\n * width, and scaled to fit. The last row is scaled too, but never above the\n * target height (a single landscape photo in the last row should not fill\n * the width as a banner); it is left-aligned at the target height instead.\n *\n * `containerWidth <= 0` (not measured yet) yields no rows, so callers render\n * nothing rather than divide by zero.\n */\nexport function justifyRows(\n items: readonly GalleryItem[],\n containerWidth: number,\n rowHeight: number,\n gap: number,\n): JustifiedRow[] {\n if (!(containerWidth > 0) || !(rowHeight > 0) || items.length === 0) return [];\n const spacing = Math.max(0, gap);\n\n const rows: JustifiedRow[] = [];\n let pending: JustifiedTile[] = [];\n let pendingWidth = 0; // tile widths only, no gaps\n\n const rowWidthWithGaps = (tiles: JustifiedTile[], widthSum: number) =>\n widthSum + spacing * Math.max(0, tiles.length - 1);\n\n const close = (tiles: JustifiedTile[], widthSum: number, capAtTarget: boolean) => {\n if (tiles.length === 0) return;\n const available = containerWidth - spacing * (tiles.length - 1);\n let scale = available > 0 ? available / widthSum : 1;\n if (capAtTarget && scale > 1) scale = 1;\n rows.push({\n height: rowHeight * scale,\n tiles: tiles.map((t) => ({\n ...t,\n width: t.width * scale,\n height: t.height * scale,\n })),\n });\n };\n\n items.forEach((item, index) => {\n const tile: JustifiedTile = {\n item,\n index,\n width: galleryItemRatio(item) * rowHeight,\n height: rowHeight,\n };\n const withTile = [...pending, tile];\n const withTileWidth = rowWidthWithGaps(withTile, pendingWidth + tile.width);\n\n if (withTileWidth < containerWidth) {\n pending = withTile;\n pendingWidth += tile.width;\n return;\n }\n\n // Overflow. Close the row with or without this tile, whichever is closer\n // to the container width; a row must hold at least one tile.\n const withoutWidth = rowWidthWithGaps(pending, pendingWidth);\n const keep =\n pending.length === 0 ||\n Math.abs(withTileWidth - containerWidth) <= Math.abs(containerWidth - withoutWidth);\n\n if (keep) {\n close(withTile, pendingWidth + tile.width, false);\n pending = [];\n pendingWidth = 0;\n } else {\n close(pending, pendingWidth, false);\n pending = [tile];\n pendingWidth = tile.width;\n }\n });\n\n close(pending, pendingWidth, true);\n return rows;\n}\n"]}
|