@andamento/svg 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,36 @@
1
+ // src/styles.ts
2
+ import { contentSlots, matchSlots, paletteFill } from "@andamento/core";
3
+ var defaultPalette = ["#e9d8a6", "#94d2bd", "#ee9b00", "#0a9396", "#ca6702", "#bb3e03", "#ae2012", "#005f73"];
4
+ function resolveFills(layout, fill) {
5
+ if (typeof fill === "string") return layout.cells.map(() => fill);
6
+ const f = typeof fill === "function" ? fill : paletteFill(fill.length ? fill : defaultPalette);
7
+ return layout.cells.map((c) => f(c, layout));
8
+ }
9
+ function resolveCellStyles(layout, opts = {}) {
10
+ const fills = resolveFills(layout, opts.fill ?? defaultPalette);
11
+ const images = opts.images;
12
+ let slots = layout.cells.map(() => -1);
13
+ if (Array.isArray(images) && images.length > 0) {
14
+ const count = opts.repeatImages ? Infinity : images.length;
15
+ const content = { cells: opts.contentCells, placement: opts.placement, choose: opts.choose };
16
+ slots = opts.imageAspects && !opts.repeatImages ? matchSlots(layout, images.map((_, i) => opts.imageAspects[i] ?? 1), content) : contentSlots(layout, count, content);
17
+ }
18
+ return layout.cells.map((c, i) => {
19
+ if (typeof images === "function") return { fill: fills[i], image: images(c), slot: -1 };
20
+ const slot = images && images.length > 0 && slots[i] >= 0 ? slots[i] % images.length : -1;
21
+ return { fill: fills[i], image: slot >= 0 ? images[slot] : void 0, slot };
22
+ });
23
+ }
24
+ function cellA11y(style, alts) {
25
+ if (!alts?.length) return {};
26
+ const alt = style.image && style.slot >= 0 ? alts[style.slot] : void 0;
27
+ return alt ? { role: "img", "aria-label": alt } : { "aria-hidden": "true" };
28
+ }
29
+
30
+ export {
31
+ defaultPalette,
32
+ resolveFills,
33
+ resolveCellStyles,
34
+ cellA11y
35
+ };
36
+ //# sourceMappingURL=chunk-GCRUDQEZ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/styles.ts"],"sourcesContent":["import { contentSlots, matchSlots, paletteFill, type CellFill, type Layout } from \"@andamento/core\";\nimport type { RenderOptions } from \"./index\";\n\nexport const defaultPalette = [\"#e9d8a6\", \"#94d2bd\", \"#ee9b00\", \"#0a9396\", \"#ca6702\", \"#bb3e03\", \"#ae2012\", \"#005f73\"];\n\n/** A color, a palette (neighboring cells get different entries), or a color per cell. */\nexport type FillSource = string | readonly string[] | CellFill;\n\nexport interface CellStyle {\n fill: string;\n image?: string;\n /** Which item of `images` the cell shows (-1 if none or if `images` is a function). */\n slot: number;\n}\n\n/**\n * Fill color per cell (by `cell.index`): a color, a palette (neighboring cells get\n * different entries), or a function.\n */\nexport function resolveFills(layout: Layout, fill: FillSource): string[] {\n if (typeof fill === \"string\") return layout.cells.map(() => fill);\n const f = typeof fill === \"function\" ? fill : paletteFill(fill.length ? fill : defaultPalette);\n return layout.cells.map((c) => f(c, layout));\n}\n\ntype StyleOptions = Pick<RenderOptions, \"images\" | \"repeatImages\" | \"fill\" | \"contentCells\" | \"placement\" | \"imageAspects\" | \"choose\">;\n\n/** Resolve the fill color and image for every cell (shared by the SVG and React renderers). */\nexport function resolveCellStyles(layout: Layout, opts: StyleOptions = {}): CellStyle[] {\n const fills = resolveFills(layout, opts.fill ?? defaultPalette);\n const images = opts.images;\n let slots: number[] = layout.cells.map(() => -1);\n if (Array.isArray(images) && images.length > 0) {\n const count = opts.repeatImages ? Infinity : images.length;\n const content = { cells: opts.contentCells, placement: opts.placement, choose: opts.choose };\n slots =\n opts.imageAspects && !opts.repeatImages\n ? matchSlots(layout, images.map((_, i) => opts.imageAspects![i] ?? 1), content)\n : contentSlots(layout, count, content);\n }\n return layout.cells.map((c, i) => {\n if (typeof images === \"function\") return { fill: fills[i]!, image: images(c), slot: -1 };\n // With repeatImages, slots run past the images: the image shown is the slot wrapped round.\n const slot = images && images.length > 0 && slots[i]! >= 0 ? slots[i]! % images.length : -1;\n return { fill: fills[i]!, image: slot >= 0 ? images![slot] : undefined, slot };\n });\n}\n\n/** With `imageAlts`: a cell showing a described image is an image; the rest is decoration. */\nexport function cellA11y(style: CellStyle, alts: readonly string[] | undefined): { role?: \"img\"; \"aria-label\"?: string; \"aria-hidden\"?: \"true\" } {\n if (!alts?.length) return {};\n const alt = style.image && style.slot >= 0 ? alts[style.slot] : undefined;\n return alt ? { role: \"img\", \"aria-label\": alt } : { \"aria-hidden\": \"true\" };\n}\n"],"mappings":";AAAA,SAAS,cAAc,YAAY,mBAA+C;AAG3E,IAAM,iBAAiB,CAAC,WAAW,WAAW,WAAW,WAAW,WAAW,WAAW,WAAW,SAAS;AAgB9G,SAAS,aAAa,QAAgB,MAA4B;AACvE,MAAI,OAAO,SAAS,SAAU,QAAO,OAAO,MAAM,IAAI,MAAM,IAAI;AAChE,QAAM,IAAI,OAAO,SAAS,aAAa,OAAO,YAAY,KAAK,SAAS,OAAO,cAAc;AAC7F,SAAO,OAAO,MAAM,IAAI,CAAC,MAAM,EAAE,GAAG,MAAM,CAAC;AAC7C;AAKO,SAAS,kBAAkB,QAAgB,OAAqB,CAAC,GAAgB;AACtF,QAAM,QAAQ,aAAa,QAAQ,KAAK,QAAQ,cAAc;AAC9D,QAAM,SAAS,KAAK;AACpB,MAAI,QAAkB,OAAO,MAAM,IAAI,MAAM,EAAE;AAC/C,MAAI,MAAM,QAAQ,MAAM,KAAK,OAAO,SAAS,GAAG;AAC9C,UAAM,QAAQ,KAAK,eAAe,WAAW,OAAO;AACpD,UAAM,UAAU,EAAE,OAAO,KAAK,cAAc,WAAW,KAAK,WAAW,QAAQ,KAAK,OAAO;AAC3F,YACE,KAAK,gBAAgB,CAAC,KAAK,eACvB,WAAW,QAAQ,OAAO,IAAI,CAAC,GAAG,MAAM,KAAK,aAAc,CAAC,KAAK,CAAC,GAAG,OAAO,IAC5E,aAAa,QAAQ,OAAO,OAAO;AAAA,EAC3C;AACA,SAAO,OAAO,MAAM,IAAI,CAAC,GAAG,MAAM;AAChC,QAAI,OAAO,WAAW,WAAY,QAAO,EAAE,MAAM,MAAM,CAAC,GAAI,OAAO,OAAO,CAAC,GAAG,MAAM,GAAG;AAEvF,UAAM,OAAO,UAAU,OAAO,SAAS,KAAK,MAAM,CAAC,KAAM,IAAI,MAAM,CAAC,IAAK,OAAO,SAAS;AACzF,WAAO,EAAE,MAAM,MAAM,CAAC,GAAI,OAAO,QAAQ,IAAI,OAAQ,IAAI,IAAI,QAAW,KAAK;AAAA,EAC/E,CAAC;AACH;AAGO,SAAS,SAAS,OAAkB,MAAsG;AAC/I,MAAI,CAAC,MAAM,OAAQ,QAAO,CAAC;AAC3B,QAAM,MAAM,MAAM,SAAS,MAAM,QAAQ,IAAI,KAAK,MAAM,IAAI,IAAI;AAChE,SAAO,MAAM,EAAE,MAAM,OAAO,cAAc,IAAI,IAAI,EAAE,eAAe,OAAO;AAC5E;","names":[]}
@@ -0,0 +1,36 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/styles.ts
2
+ var _core = require('@andamento/core');
3
+ var defaultPalette = ["#e9d8a6", "#94d2bd", "#ee9b00", "#0a9396", "#ca6702", "#bb3e03", "#ae2012", "#005f73"];
4
+ function resolveFills(layout, fill) {
5
+ if (typeof fill === "string") return layout.cells.map(() => fill);
6
+ const f = typeof fill === "function" ? fill : _core.paletteFill.call(void 0, fill.length ? fill : defaultPalette);
7
+ return layout.cells.map((c) => f(c, layout));
8
+ }
9
+ function resolveCellStyles(layout, opts = {}) {
10
+ const fills = resolveFills(layout, _nullishCoalesce(opts.fill, () => ( defaultPalette)));
11
+ const images = opts.images;
12
+ let slots = layout.cells.map(() => -1);
13
+ if (Array.isArray(images) && images.length > 0) {
14
+ const count = opts.repeatImages ? Infinity : images.length;
15
+ const content = { cells: opts.contentCells, placement: opts.placement, choose: opts.choose };
16
+ slots = opts.imageAspects && !opts.repeatImages ? _core.matchSlots.call(void 0, layout, images.map((_, i) => _nullishCoalesce(opts.imageAspects[i], () => ( 1))), content) : _core.contentSlots.call(void 0, layout, count, content);
17
+ }
18
+ return layout.cells.map((c, i) => {
19
+ if (typeof images === "function") return { fill: fills[i], image: images(c), slot: -1 };
20
+ const slot = images && images.length > 0 && slots[i] >= 0 ? slots[i] % images.length : -1;
21
+ return { fill: fills[i], image: slot >= 0 ? images[slot] : void 0, slot };
22
+ });
23
+ }
24
+ function cellA11y(style, alts) {
25
+ if (!_optionalChain([alts, 'optionalAccess', _2 => _2.length])) return {};
26
+ const alt = style.image && style.slot >= 0 ? alts[style.slot] : void 0;
27
+ return alt ? { role: "img", "aria-label": alt } : { "aria-hidden": "true" };
28
+ }
29
+
30
+
31
+
32
+
33
+
34
+
35
+ exports.defaultPalette = defaultPalette; exports.resolveFills = resolveFills; exports.resolveCellStyles = resolveCellStyles; exports.cellA11y = cellA11y;
36
+ //# sourceMappingURL=chunk-JSRCX7PI.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/matthewputnam/code/andamento/packages/svg/dist/chunk-JSRCX7PI.cjs","../src/styles.ts"],"names":[],"mappings":"AAAA;ACAA,uCAAkF;AAG3E,IAAM,eAAA,EAAiB,CAAC,SAAA,EAAW,SAAA,EAAW,SAAA,EAAW,SAAA,EAAW,SAAA,EAAW,SAAA,EAAW,SAAA,EAAW,SAAS,CAAA;AAgB9G,SAAS,YAAA,CAAa,MAAA,EAAgB,IAAA,EAA4B;AACvE,EAAA,GAAA,CAAI,OAAO,KAAA,IAAS,QAAA,EAAU,OAAO,MAAA,CAAO,KAA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out } from \"@andamento/core\";\nimport type { RenderOptions } from \"./index\";\n\nexport const defaultPalette = [\"#e9d8a6\", \"#94d2bd\", \"#ee9b00\", \"#0a9396\", \"#ca6702\", \"#bb3e03\", \"#ae2012\", \"#005f73\"];\n\n/** A color, a palette (neighboring cells get different entries), or a color per cell. */\nexport type FillSource = string | readonly string[] | CellFill;\n\nexport interface CellStyle {\n fill: string;\n image?: string;\n /** Which item of `images` the cell shows (-1 if none or if `images` is a function). */\n slot: number;\n}\n\n/**\n * Fill color per cell (by `cell.index`): a color, a palette (neighboring cells get\n * different entries), or a function.\n */\nexport function resolveFills(layout: Layout, fill: FillSource): string[] {\n if (typeof fill === \"string\") return layout.cells.map(() => fill);\n const f = typeof fill === \"function\" ? fill : paletteFill(fill.length ? fill : defaultPalette);\n return layout.cells.map((c) => f(c, layout));\n}\n\ntype StyleOptions = Pick<RenderOptions, \"images\" | \"repeatImages\" | \"fill\" | \"contentCells\" | \"placement\" | \"imageAspects\" | \"choose\">;\n\n/** Resolve the fill color and image for every cell (shared by the SVG and React renderers). */\nexport function resolveCellStyles(layout: Layout, opts: StyleOptions = {}): CellStyle[] {\n const fills = resolveFills(layout, opts.fill ?? defaultPalette);\n const images = opts.images;\n let slots: number[] = layout.cells.map(() => -1);\n if (Array.isArray(images) && images.length > 0) {\n const count = opts.repeatImages ? Infinity : images.length;\n const content = { cells: opts.contentCells, placement: opts.placement, choose: opts.choose };\n slots =\n opts.imageAspects && !opts.repeatImages\n ? matchSlots(layout, images.map((_, i) => opts.imageAspects![i] ?? 1), content)\n : contentSlots(layout, count, content);\n }\n return layout.cells.map((c, i) => {\n if (typeof images === \"function\") return { fill: fills[i]!, image: images(c), slot: -1 };\n // With repeatImages, slots run past the images: the image shown is the slot wrapped round.\n const slot = images && images.length > 0 && slots[i]! >= 0 ? slots[i]! % images.length : -1;\n return { fill: fills[i]!, image: slot >= 0 ? images![slot] : undefined, slot };\n });\n}\n\n/** With `imageAlts`: a cell showing a described image is an image; the rest is decoration. */\nexport function cellA11y(style: CellStyle, alts: readonly string[] | undefined): { role?: \"img\"; \"aria-label\"?: string; \"aria-hidden\"?: \"true\" } {\n if (!alts?.length) return {};\n const alt = style.image && style.slot >= 0 ? alts[style.slot] : undefined;\n return alt ? { role: \"img\", \"aria-label\": alt } : { \"aria-hidden\": \"true\" };\n}\n"]}
package/dist/index.cjs CHANGED
@@ -1,55 +1,14 @@
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);
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } async function _asyncNullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return await rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
+
3
+
4
+
5
+ var _chunkJSRCX7PIcjs = require('./chunk-JSRCX7PI.cjs');
19
6
 
20
7
  // src/index.ts
21
- var index_exports = {};
22
- __export(index_exports, {
23
- cellA11y: () => cellA11y,
24
- cellPath: () => cellPath,
25
- defaultBevel: () => defaultBevel,
26
- defaultPalette: () => defaultPalette,
27
- drawLayout: () => drawLayout,
28
- imagesUsed: () => imagesUsed,
29
- loadImages: () => loadImages,
30
- neutralPalette: () => neutralPalette,
31
- polygonToPath: () => polygonToPath,
32
- rasterSize: () => rasterSize,
33
- regionPath: () => regionPath,
34
- reliefLayers: () => reliefLayers,
35
- reliefPaths: () => reliefPaths,
36
- renderToCanvas: () => renderToCanvas,
37
- renderToElement: () => renderToElement,
38
- renderToPng: () => renderToPng,
39
- renderToString: () => renderToString,
40
- resolveCellStyles: () => resolveCellStyles,
41
- resolveFills: () => resolveFills,
42
- serialize: () => serialize,
43
- shadowOffset: () => shadowOffset,
44
- toSvgTree: () => toSvgTree,
45
- tracePolygon: () => tracePolygon,
46
- viewPath: () => viewPath
47
- });
48
- module.exports = __toCommonJS(index_exports);
49
- var import_core3 = require("@andamento/core");
8
+ var _core = require('@andamento/core');
50
9
 
51
10
  // src/relief.ts
52
- var import_core = require("@andamento/core");
11
+
53
12
  function defaultBevel(layout) {
54
13
  const n = layout.cells.length;
55
14
  if (n === 0) return 0;
@@ -58,9 +17,9 @@ function defaultBevel(layout) {
58
17
  }
59
18
  var LEVELS = 8;
60
19
  function reliefLayers(layout, cell, relief, bevel) {
61
- const strength = relief.strength ?? 0.4;
20
+ const strength = _nullishCoalesce(relief.strength, () => ( 0.4));
62
21
  const groups = /* @__PURE__ */ new Map();
63
- for (const facet of (0, import_core.bevelFacets)(cell, layout, { width: bevel, light: relief.light })) {
22
+ for (const facet of _core.bevelFacets.call(void 0, cell, layout, { width: bevel, light: relief.light })) {
64
23
  const level = Math.round(facet.shade * LEVELS);
65
24
  if (level === 0) continue;
66
25
  const list = groups.get(level);
@@ -82,28 +41,28 @@ function reliefPaths(layout, cell, relief, bevel, precision = 3) {
82
41
  }));
83
42
  }
84
43
  function shadowOffset(relief) {
85
- const s = relief.shadow ?? 0;
44
+ const s = _nullishCoalesce(relief.shadow, () => ( 0));
86
45
  if (!(s > 0)) return void 0;
87
- const l = (0, import_core.lightVector)(relief.light);
88
- return { dx: -l.x * s, dy: -l.y * s, blur: relief.shadowBlur ?? s, opacity: relief.shadowOpacity ?? 0.35 };
46
+ const l = _core.lightVector.call(void 0, relief.light);
47
+ return { dx: -l.x * s, dy: -l.y * s, blur: _nullishCoalesce(relief.shadowBlur, () => ( s)), opacity: _nullishCoalesce(relief.shadowOpacity, () => ( 0.35)) };
89
48
  }
90
49
 
91
50
  // src/canvas.ts
92
- var import_core2 = require("@andamento/core");
51
+
93
52
  function drawLayout(ctx, layout, options = {}) {
94
53
  const canvas = ctx.canvas;
95
- const width = options.width ?? canvas?.width ?? layout.bounds.width;
96
- const height = options.height ?? canvas?.height ?? layout.bounds.height;
54
+ const width = _nullishCoalesce(_nullishCoalesce(options.width, () => ( _optionalChain([canvas, 'optionalAccess', _ => _.width]))), () => ( layout.bounds.width));
55
+ const height = _nullishCoalesce(_nullishCoalesce(options.height, () => ( _optionalChain([canvas, 'optionalAccess', _2 => _2.height]))), () => ( layout.bounds.height));
97
56
  const b = layout.bounds;
98
57
  const scale = Math.min(width / (b.width || 1), height / (b.height || 1)) || 1;
99
58
  const ox = (width - b.width * scale) / 2 - b.x * scale;
100
59
  const oy = (height - b.height * scale) / 2 - b.y * scale;
101
60
  const toLayout = () => ctx.setTransform(scale, 0, 0, scale, ox, oy);
102
- const styles = resolveCellStyles(layout, options);
103
- const loaded = options.loaded ?? /* @__PURE__ */ new Map();
61
+ const styles = _chunkJSRCX7PIcjs.resolveCellStyles.call(void 0, layout, options);
62
+ const loaded = _nullishCoalesce(options.loaded, () => ( /* @__PURE__ */ new Map()));
104
63
  const radius = layout.cornerRadius;
105
64
  const cellLoops = (c) => {
106
- const s = (0, import_core2.cellShape)(c);
65
+ const s = _core.cellShape.call(void 0, c);
107
66
  return [s.outline, ...s.holes];
108
67
  };
109
68
  ctx.save();
@@ -148,7 +107,7 @@ function drawLayout(ctx, layout, options = {}) {
148
107
  drawCover(ctx, backdrop, b);
149
108
  ctx.restore();
150
109
  }
151
- const bevel = relief ? relief.bevel ?? defaultBevel(layout) : 0;
110
+ const bevel = relief ? _nullishCoalesce(relief.bevel, () => ( defaultBevel(layout))) : 0;
152
111
  layout.cells.forEach((cell, i) => {
153
112
  const style = styles[i];
154
113
  ctx.beginPath();
@@ -162,14 +121,14 @@ function drawLayout(ctx, layout, options = {}) {
162
121
  ctx.save();
163
122
  ctx.clip("evenodd");
164
123
  if (options.imageFit === "contain") {
165
- const aspect = options.imageAspects && style.slot >= 0 ? options.imageAspects[style.slot % options.imageAspects.length] : void 0;
166
- drawContain(ctx, img, (0, import_core2.safeArea)(cell, layout, { aspect, within: options.containWithin }));
124
+ const aspect = options.imageAspects && style.slot >= 0 ? options.imageAspects[style.slot] : void 0;
125
+ drawContain(ctx, img, _core.safeArea.call(void 0, cell, layout, { aspect, within: options.containWithin }));
167
126
  } else {
168
- const focus = style.slot >= 0 ? Array.isArray(options.images) ? options.imageFocus?.[style.slot % options.images.length] : void 0 : void 0;
127
+ const focus = style.slot >= 0 ? _optionalChain([options, 'access', _3 => _3.imageFocus, 'optionalAccess', _4 => _4[style.slot]]) : void 0;
169
128
  if (focus && img.width && img.height) {
170
- const r = (0, import_core2.coverRect)(cell, layout, { aspect: img.width / img.height, focus });
129
+ const r = _core.coverRect.call(void 0, cell, layout, { aspect: img.width / img.height, focus });
171
130
  ctx.drawImage(img, 0, 0, img.width, img.height, r.x, r.y, r.width, r.height);
172
- } else drawCover(ctx, img, (0, import_core2.cellShape)(cell).bbox);
131
+ } else drawCover(ctx, img, _core.cellShape.call(void 0, cell).bbox);
173
132
  }
174
133
  ctx.restore();
175
134
  }
@@ -187,7 +146,7 @@ function drawLayout(ctx, layout, options = {}) {
187
146
  ctx.beginPath();
188
147
  for (const p of cellLoops(cell)) tracePolygon(ctx, p, radius);
189
148
  ctx.strokeStyle = options.stroke;
190
- ctx.lineWidth = options.strokeWidth ?? 1;
149
+ ctx.lineWidth = _nullishCoalesce(options.strokeWidth, () => ( 1));
191
150
  ctx.stroke();
192
151
  }
193
152
  });
@@ -201,7 +160,7 @@ function tracePolygon(ctx, poly, radius) {
201
160
  ctx.closePath();
202
161
  return;
203
162
  }
204
- (0, import_core2.roundCorners)(poly, radius).forEach((c, i) => {
163
+ _core.roundCorners.call(void 0, poly, radius).forEach((c, i) => {
205
164
  if (i === 0) ctx.moveTo(c.start.x, c.start.y);
206
165
  else ctx.lineTo(c.start.x, c.start.y);
207
166
  if (c.radius > 0) {
@@ -225,7 +184,7 @@ function drawContain(ctx, img, box) {
225
184
  }
226
185
  function imagesUsed(layout, options = {}) {
227
186
  const urls = /* @__PURE__ */ new Set();
228
- for (const s of resolveCellStyles(layout, options)) if (s.image) urls.add(s.image);
187
+ for (const s of _chunkJSRCX7PIcjs.resolveCellStyles.call(void 0, layout, options)) if (s.image) urls.add(s.image);
229
188
  if (options.backdrop) urls.add(options.backdrop);
230
189
  return [...urls];
231
190
  }
@@ -235,7 +194,7 @@ async function loadImages(urls, load = browserImage) {
235
194
  urls.map(async (url) => {
236
195
  try {
237
196
  out.set(url, await load(url));
238
- } catch {
197
+ } catch (e) {
239
198
  }
240
199
  })
241
200
  );
@@ -258,22 +217,22 @@ async function renderToCanvas(layout, canvas, options = {}) {
258
217
  canvas.height = h;
259
218
  const ctx = canvas.getContext("2d");
260
219
  if (!ctx) throw new Error("Could not get a 2D context from the canvas");
261
- const loaded = options.loaded ?? await loadImages(imagesUsed(layout, options), options.loadImage);
220
+ const loaded = await _asyncNullishCoalesce(options.loaded, async () => ( await loadImages(imagesUsed(layout, options), options.loadImage)));
262
221
  ctx.clearRect(0, 0, w, h);
263
222
  drawLayout(ctx, layout, { ...options, loaded, width: w, height: h });
264
223
  return canvas;
265
224
  }
266
225
  function rasterSize(layout, options = {}) {
267
226
  const b = layout.bounds;
268
- const cssWidth = options.width ?? b.width;
269
- const ratio = options.pixelRatio ?? 1;
227
+ const cssWidth = _nullishCoalesce(options.width, () => ( b.width));
228
+ const ratio = _nullishCoalesce(options.pixelRatio, () => ( 1));
270
229
  return { w: Math.max(1, Math.round(cssWidth * ratio)), h: Math.max(1, Math.round(cssWidth * b.height / (b.width || 1) * ratio)) };
271
230
  }
272
231
  async function renderToPng(layout, options = {}) {
273
232
  const { w, h } = rasterSize(layout, options);
274
233
  const canvas = options.createCanvas ? options.createCanvas(w, h) : makeCanvas(w, h);
275
234
  await renderToCanvas(layout, canvas, options);
276
- const type = options.type ?? "image/png";
235
+ const type = _nullishCoalesce(options.type, () => ( "image/png"));
277
236
  const c = canvas;
278
237
  if (c.convertToBlob) return c.convertToBlob({ type, quality: options.quality });
279
238
  if (c.toBlob) {
@@ -296,7 +255,6 @@ function makeCanvas(w, h) {
296
255
  }
297
256
 
298
257
  // src/index.ts
299
- var defaultPalette = ["#e9d8a6", "#94d2bd", "#ee9b00", "#0a9396", "#ca6702", "#bb3e03", "#ae2012", "#005f73"];
300
258
  var neutralPalette = ["#e7e5e4", "#d6d3d1", "#f5f5f4", "#dedad6", "#ecebe9"];
301
259
  var formatter = (precision) => (n) => {
302
260
  const s = n.toFixed(precision);
@@ -308,7 +266,7 @@ function polygonToPath(p, precision = 3, radius = 0) {
308
266
  const f = formatter(precision);
309
267
  if (radius <= 0) return "M" + p.map((v) => `${f(v.x)} ${f(v.y)}`).join("L") + "Z";
310
268
  const parts = [];
311
- for (const c of (0, import_core3.roundCorners)(p, radius)) {
269
+ for (const c of _core.roundCorners.call(void 0, p, radius)) {
312
270
  parts.push(`${parts.length ? "L" : "M"}${f(c.start.x)} ${f(c.start.y)}`);
313
271
  if (c.radius > 0) {
314
272
  const r = f(c.radius);
@@ -318,7 +276,7 @@ function polygonToPath(p, precision = 3, radius = 0) {
318
276
  return parts.join("") + "Z";
319
277
  }
320
278
  function cellPath(layout, cell, precision = 3) {
321
- const s = (0, import_core3.cellShape)(cell);
279
+ const s = _core.cellShape.call(void 0, cell);
322
280
  return [s.outline, ...s.holes].map((p) => polygonToPath(p, precision, layout.cornerRadius)).join("");
323
281
  }
324
282
  function viewPath(layout, precision = 3) {
@@ -328,38 +286,16 @@ function viewPath(layout, precision = 3) {
328
286
  function regionPath(layout, precision = 3) {
329
287
  return [layout.region, ...layout.holes].map((p) => polygonToPath(p, precision)).join("");
330
288
  }
331
- function resolveFills(layout, fill) {
332
- if (typeof fill === "string") return layout.cells.map(() => fill);
333
- const f = typeof fill === "function" ? fill : (0, import_core3.paletteFill)(fill.length ? fill : defaultPalette);
334
- return layout.cells.map((c) => f(c, layout));
335
- }
336
- function resolveCellStyles(layout, opts = {}) {
337
- const fills = resolveFills(layout, opts.fill ?? defaultPalette);
338
- const images = opts.images;
339
- let slots = layout.cells.map(() => -1);
340
- if (Array.isArray(images) && images.length > 0) {
341
- const count = opts.repeatImages ? Infinity : images.length;
342
- const content = { cells: opts.contentCells, placement: opts.placement, choose: opts.choose };
343
- slots = opts.imageAspects && !opts.repeatImages ? (0, import_core3.matchSlots)(layout, images.map((_, i) => opts.imageAspects[i] ?? 1), content) : (0, import_core3.contentSlots)(layout, count, content);
344
- }
345
- return layout.cells.map((c, i) => {
346
- const slot = slots[i];
347
- let image;
348
- if (typeof images === "function") image = images(c);
349
- else if (images && slot >= 0) image = images[slot % images.length];
350
- return { fill: fills[i], image, slot };
351
- });
352
- }
353
289
  var el = (tag, attrs = {}, children = []) => ({
354
290
  tag,
355
291
  attrs,
356
292
  children
357
293
  });
358
294
  function toSvgTree(layout, opts = {}) {
359
- const precision = opts.precision ?? 3;
360
- const prefix = opts.idPrefix ?? "andamento";
295
+ const precision = _nullishCoalesce(opts.precision, () => ( 3));
296
+ const prefix = _nullishCoalesce(opts.idPrefix, () => ( "andamento"));
361
297
  const { x, y, width, height } = layout.bounds;
362
- const styles = resolveCellStyles(layout, opts);
298
+ const styles = _chunkJSRCX7PIcjs.resolveCellStyles.call(void 0, layout, opts);
363
299
  const r = (n) => Number(n.toFixed(precision));
364
300
  const children = [];
365
301
  if (opts.title) children.push(el("title", {}, [opts.title]));
@@ -385,7 +321,7 @@ function toSvgTree(layout, opts = {}) {
385
321
  );
386
322
  }
387
323
  const relief = opts.relief === true ? {} : opts.relief || void 0;
388
- const bevel = relief ? relief.bevel ?? defaultBevel(layout) : 0;
324
+ const bevel = relief ? _nullishCoalesce(relief.bevel, () => ( defaultBevel(layout))) : 0;
389
325
  const cast = relief && shadowOffset(relief);
390
326
  if (cast) {
391
327
  const regionId = `${prefix}-region`;
@@ -408,16 +344,16 @@ function toSvgTree(layout, opts = {}) {
408
344
  layout.cells.forEach((cell, i) => {
409
345
  const d = cellPath(layout, cell, precision);
410
346
  const style = styles[i];
411
- const holed = !!cell.holes?.length;
347
+ const holed = !!_optionalChain([cell, 'access', _5 => _5.holes, 'optionalAccess', _6 => _6.length]);
412
348
  const parts = opts.backdrop ? [] : [el("path", { d, fill: style.fill, "fill-rule": holed ? "evenodd" : void 0 })];
413
349
  if (style.image) {
414
350
  const clipId = `${prefix}-clip-${cell.index}`;
415
351
  parts.unshift(el("clipPath", { id: clipId }, [el("path", { d, "clip-rule": holed ? "evenodd" : void 0 })]));
416
352
  const contain = opts.imageFit === "contain";
417
- const aspect = contain && opts.imageAspects && style.slot >= 0 ? opts.imageAspects[style.slot % opts.imageAspects.length] : void 0;
418
- const focus = !contain && style.slot >= 0 ? Array.isArray(opts.images) ? opts.imageFocus?.[style.slot % opts.images.length] : void 0 : void 0;
419
- const shape = focus ? opts.imageAspects?.[style.slot % opts.imageAspects.length] ?? focus.aspect : void 0;
420
- const box = contain ? (0, import_core3.safeArea)(cell, layout, { aspect, within: opts.containWithin }) : focus && shape ? (0, import_core3.coverRect)(cell, layout, { aspect: shape, focus }) : (0, import_core3.cellShape)(cell).bbox;
353
+ const aspect = contain && opts.imageAspects && style.slot >= 0 ? opts.imageAspects[style.slot] : void 0;
354
+ const focus = !contain && style.slot >= 0 ? _optionalChain([opts, 'access', _7 => _7.imageFocus, 'optionalAccess', _8 => _8[style.slot]]) : void 0;
355
+ const shape = focus ? _nullishCoalesce(_optionalChain([opts, 'access', _9 => _9.imageAspects, 'optionalAccess', _10 => _10[style.slot]]), () => ( focus.aspect)) : void 0;
356
+ const box = contain ? _core.safeArea.call(void 0, cell, layout, { aspect, within: opts.containWithin }) : focus && shape ? _core.coverRect.call(void 0, cell, layout, { aspect: shape, focus }) : _core.cellShape.call(void 0, cell).bbox;
421
357
  parts.push(
422
358
  el("image", {
423
359
  href: style.image,
@@ -436,7 +372,7 @@ function toSvgTree(layout, opts = {}) {
436
372
  }
437
373
  }
438
374
  if (opts.stroke) {
439
- parts.push(el("path", { d, fill: "none", stroke: opts.stroke, "stroke-width": opts.strokeWidth ?? 1 }));
375
+ parts.push(el("path", { d, fill: "none", stroke: opts.stroke, "stroke-width": _nullishCoalesce(opts.strokeWidth, () => ( 1)) }));
440
376
  }
441
377
  children.push(
442
378
  el(
@@ -447,7 +383,7 @@ function toSvgTree(layout, opts = {}) {
447
383
  "data-index": cell.index,
448
384
  "data-empty": style.image ? void 0 : "",
449
385
  "data-boundary": cell.boundary ? "" : void 0,
450
- ...cellA11y(style, opts.imageAlts)
386
+ ..._chunkJSRCX7PIcjs.cellA11y.call(void 0, style, opts.imageAlts)
451
387
  },
452
388
  parts
453
389
  )
@@ -466,16 +402,11 @@ function toSvgTree(layout, opts = {}) {
466
402
  viewBox: `${r(x)} ${r(y)} ${r(width)} ${r(height)}`,
467
403
  width: opts.width,
468
404
  height: opts.height,
469
- role: opts.imageAlts?.length ? "group" : opts.title ? "img" : void 0
405
+ role: _optionalChain([opts, 'access', _11 => _11.imageAlts, 'optionalAccess', _12 => _12.length]) ? "group" : opts.title ? "img" : void 0
470
406
  },
471
407
  children
472
408
  );
473
409
  }
474
- function cellA11y(style, alts) {
475
- if (!alts?.length) return {};
476
- const alt = style.image && style.slot >= 0 ? alts[style.slot % alts.length] : void 0;
477
- return alt ? { role: "img", "aria-label": alt } : { "aria-hidden": "true" };
478
- }
479
410
  var escapeText = (s) => s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
480
411
  var escapeAttr = (s) => escapeText(s).replace(/"/g, "&quot;");
481
412
  function serialize(node) {
@@ -501,31 +432,27 @@ function renderToElement(layout, opts = {}, doc = globalThis.document) {
501
432
  if (!doc) throw new Error("renderToElement needs a DOM Document; pass one explicitly outside the browser");
502
433
  return build(toSvgTree(layout, opts), doc);
503
434
  }
504
- // Annotate the CommonJS export names for ESM import in node:
505
- 0 && (module.exports = {
506
- cellA11y,
507
- cellPath,
508
- defaultBevel,
509
- defaultPalette,
510
- drawLayout,
511
- imagesUsed,
512
- loadImages,
513
- neutralPalette,
514
- polygonToPath,
515
- rasterSize,
516
- regionPath,
517
- reliefLayers,
518
- reliefPaths,
519
- renderToCanvas,
520
- renderToElement,
521
- renderToPng,
522
- renderToString,
523
- resolveCellStyles,
524
- resolveFills,
525
- serialize,
526
- shadowOffset,
527
- toSvgTree,
528
- tracePolygon,
529
- viewPath
530
- });
435
+
436
+
437
+
438
+
439
+
440
+
441
+
442
+
443
+
444
+
445
+
446
+
447
+
448
+
449
+
450
+
451
+
452
+
453
+
454
+
455
+
456
+
457
+ exports.cellPath = cellPath; exports.defaultBevel = defaultBevel; exports.defaultPalette = _chunkJSRCX7PIcjs.defaultPalette; exports.drawLayout = drawLayout; exports.imagesUsed = imagesUsed; exports.loadImages = loadImages; exports.neutralPalette = neutralPalette; exports.polygonToPath = polygonToPath; exports.rasterSize = rasterSize; exports.regionPath = regionPath; exports.reliefLayers = reliefLayers; exports.reliefPaths = reliefPaths; exports.renderToCanvas = renderToCanvas; exports.renderToElement = renderToElement; exports.renderToPng = renderToPng; exports.renderToString = renderToString; exports.serialize = serialize; exports.shadowOffset = shadowOffset; exports.toSvgTree = toSvgTree; exports.tracePolygon = tracePolygon; exports.viewPath = viewPath;
531
458
  //# sourceMappingURL=index.cjs.map