@arraypress/covers 0.0.0-stage → 1.1.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.
Files changed (245) hide show
  1. package/CHANGELOG.md +126 -0
  2. package/LICENSE +29 -0
  3. package/README.md +846 -2
  4. package/fonts/OFL.txt +93 -0
  5. package/fonts/inter-latin-400.woff +0 -0
  6. package/fonts/inter-latin-500.woff +0 -0
  7. package/fonts/inter-latin-600.woff +0 -0
  8. package/fonts/inter-latin-700.woff +0 -0
  9. package/package.json +124 -4
  10. package/recipes/aurora.json +132 -0
  11. package/recipes/bauhaus.json +113 -0
  12. package/recipes/bigType.json +103 -0
  13. package/recipes/brand.json +1143 -0
  14. package/recipes/contour.json +109 -0
  15. package/recipes/cutout.json +191 -0
  16. package/recipes/diagram.json +92 -0
  17. package/recipes/dither.json +170 -0
  18. package/recipes/duotone.json +75 -0
  19. package/recipes/gridTitle.json +136 -0
  20. package/recipes/iconTile.json +214 -0
  21. package/recipes/issue.json +221 -0
  22. package/recipes/mark.json +170 -0
  23. package/recipes/photo.json +156 -0
  24. package/recipes/riso.json +387 -0
  25. package/recipes/stripes.json +206 -0
  26. package/recipes/waveform.json +154 -0
  27. package/schema/recipe.schema.json +8822 -0
  28. package/src/animate/index.d.ts +19 -0
  29. package/src/animate/index.js +116 -0
  30. package/src/astro.d.ts +31 -0
  31. package/src/astro.js +86 -0
  32. package/src/builtins.js +4 -0
  33. package/src/color.js +246 -0
  34. package/src/diagram.js +248 -0
  35. package/src/effects/ascii.d.ts +7 -0
  36. package/src/effects/ascii.js +93 -0
  37. package/src/effects/buffer.d.ts +60 -0
  38. package/src/effects/buffer.js +472 -0
  39. package/src/effects/detail.d.ts +12 -0
  40. package/src/effects/detail.js +124 -0
  41. package/src/effects/digital.d.ts +14 -0
  42. package/src/effects/digital.js +216 -0
  43. package/src/effects/distort.d.ts +20 -0
  44. package/src/effects/distort.js +314 -0
  45. package/src/effects/dither.d.ts +8 -0
  46. package/src/effects/dither.js +147 -0
  47. package/src/effects/drop-shadow.d.ts +4 -0
  48. package/src/effects/drop-shadow.js +45 -0
  49. package/src/effects/extrude.d.ts +5 -0
  50. package/src/effects/extrude.js +55 -0
  51. package/src/effects/film.d.ts +11 -0
  52. package/src/effects/film.js +204 -0
  53. package/src/effects/glow.d.ts +8 -0
  54. package/src/effects/glow.js +56 -0
  55. package/src/effects/grade.d.ts +30 -0
  56. package/src/effects/grade.js +274 -0
  57. package/src/effects/halftone.d.ts +8 -0
  58. package/src/effects/halftone.js +95 -0
  59. package/src/effects/index.d.ts +125 -0
  60. package/src/effects/index.js +277 -0
  61. package/src/effects/ink.d.ts +12 -0
  62. package/src/effects/ink.js +70 -0
  63. package/src/effects/lens.d.ts +14 -0
  64. package/src/effects/lens.js +277 -0
  65. package/src/effects/light.d.ts +10 -0
  66. package/src/effects/light.js +59 -0
  67. package/src/effects/looks.d.ts +9 -0
  68. package/src/effects/looks.js +74 -0
  69. package/src/effects/mask.d.ts +52 -0
  70. package/src/effects/mask.js +314 -0
  71. package/src/effects/motion.d.ts +6 -0
  72. package/src/effects/motion.js +60 -0
  73. package/src/effects/newsprint.d.ts +6 -0
  74. package/src/effects/newsprint.js +89 -0
  75. package/src/effects/optics.d.ts +10 -0
  76. package/src/effects/optics.js +213 -0
  77. package/src/effects/options.d.ts +6 -0
  78. package/src/effects/options.js +106 -0
  79. package/src/effects/paint-presets.d.ts +10 -0
  80. package/src/effects/paint-presets.js +47 -0
  81. package/src/effects/paint.d.ts +49 -0
  82. package/src/effects/paint.js +66 -0
  83. package/src/effects/pixels.d.ts +24 -0
  84. package/src/effects/pixels.js +138 -0
  85. package/src/effects/polar.d.ts +10 -0
  86. package/src/effects/polar.js +265 -0
  87. package/src/effects/region.d.ts +8 -0
  88. package/src/effects/region.js +136 -0
  89. package/src/effects/round-border.d.ts +5 -0
  90. package/src/effects/round-border.js +62 -0
  91. package/src/effects/screen.d.ts +14 -0
  92. package/src/effects/screen.js +212 -0
  93. package/src/effects/sort.d.ts +8 -0
  94. package/src/effects/sort.js +125 -0
  95. package/src/effects/symmetry.d.ts +6 -0
  96. package/src/effects/symmetry.js +74 -0
  97. package/src/effects/tile.d.ts +7 -0
  98. package/src/effects/tile.js +55 -0
  99. package/src/effects/tone.d.ts +16 -0
  100. package/src/effects/tone.js +117 -0
  101. package/src/effects/transform.d.ts +35 -0
  102. package/src/effects/transform.js +127 -0
  103. package/src/effects/util.d.ts +16 -0
  104. package/src/effects/util.js +85 -0
  105. package/src/extract.js +91 -0
  106. package/src/flatten.js +234 -0
  107. package/src/fonts.d.ts +55 -0
  108. package/src/fonts.js +393 -0
  109. package/src/formats/cut.d.ts +10 -0
  110. package/src/formats/cut.js +77 -0
  111. package/src/formats/index.d.ts +6 -0
  112. package/src/formats/index.js +9 -0
  113. package/src/formats/presets.d.ts +41 -0
  114. package/src/formats/presets.js +89 -0
  115. package/src/formats/print.d.ts +25 -0
  116. package/src/formats/print.js +117 -0
  117. package/src/formats/zones.d.ts +10 -0
  118. package/src/formats/zones.js +64 -0
  119. package/src/geometry.js +187 -0
  120. package/src/grid.js +41 -0
  121. package/src/handmade.js +253 -0
  122. package/src/icons.js +191 -0
  123. package/src/index.d.ts +1083 -0
  124. package/src/index.js +27 -0
  125. package/src/inter-data.js +27 -0
  126. package/src/json-recipe.js +616 -0
  127. package/src/kit/index.d.ts +20 -0
  128. package/src/kit/index.js +58 -0
  129. package/src/layer-options.js +56 -0
  130. package/src/layers/barcode.d.ts +19 -0
  131. package/src/layers/barcode.js +63 -0
  132. package/src/layers/code128.d.ts +4 -0
  133. package/src/layers/code128.js +28 -0
  134. package/src/layers/expr.d.ts +6 -0
  135. package/src/layers/expr.js +121 -0
  136. package/src/layers/geometry.d.ts +6 -0
  137. package/src/layers/geometry.js +238 -0
  138. package/src/layers/index.d.ts +18 -0
  139. package/src/layers/index.js +15 -0
  140. package/src/layers/perforation.d.ts +14 -0
  141. package/src/layers/perforation.js +47 -0
  142. package/src/layers/repeat.d.ts +29 -0
  143. package/src/layers/repeat.js +90 -0
  144. package/src/layers/shape.d.ts +46 -0
  145. package/src/layers/shape.js +115 -0
  146. package/src/layers/soft.d.ts +5 -0
  147. package/src/layers/soft.js +43 -0
  148. package/src/layers/svg.d.ts +23 -0
  149. package/src/layers/svg.js +109 -0
  150. package/src/layers/table.d.ts +25 -0
  151. package/src/layers/table.js +80 -0
  152. package/src/layers/tear.d.ts +21 -0
  153. package/src/layers/tear.js +74 -0
  154. package/src/layers/texture.d.ts +17 -0
  155. package/src/layers/texture.js +106 -0
  156. package/src/layers/util.d.ts +8 -0
  157. package/src/layers/util.js +48 -0
  158. package/src/layers.js +1056 -0
  159. package/src/lint/image-size.d.ts +4 -0
  160. package/src/lint/image-size.js +34 -0
  161. package/src/lint/index.d.ts +16 -0
  162. package/src/lint/index.js +127 -0
  163. package/src/lint/rules.d.ts +5 -0
  164. package/src/lint/rules.js +19 -0
  165. package/src/node.d.ts +2 -0
  166. package/src/node.js +20 -0
  167. package/src/palette.js +185 -0
  168. package/src/platform/bytes.d.ts +22 -0
  169. package/src/platform/bytes.js +103 -0
  170. package/src/platform/compress.d.ts +12 -0
  171. package/src/platform/compress.js +81 -0
  172. package/src/platform/harfbuzz.d.ts +9 -0
  173. package/src/platform/harfbuzz.js +80 -0
  174. package/src/platform/index.d.ts +8 -0
  175. package/src/platform/index.js +13 -0
  176. package/src/platform/load.d.ts +6 -0
  177. package/src/platform/load.js +72 -0
  178. package/src/platform/no-harfbuzz.d.ts +2 -0
  179. package/src/platform/no-harfbuzz.js +11 -0
  180. package/src/platform/node.d.ts +26 -0
  181. package/src/platform/node.js +86 -0
  182. package/src/platform/settings.d.ts +28 -0
  183. package/src/platform/settings.js +51 -0
  184. package/src/png.js +126 -0
  185. package/src/print.js +659 -0
  186. package/src/raster/index.d.ts +24 -0
  187. package/src/raster/index.js +171 -0
  188. package/src/recipes.js +79 -0
  189. package/src/render/backdrop.d.ts +6 -0
  190. package/src/render/backdrop.js +55 -0
  191. package/src/render/content.d.ts +5 -0
  192. package/src/render/content.js +58 -0
  193. package/src/render/context.d.ts +82 -0
  194. package/src/render/grain.d.ts +7 -0
  195. package/src/render/grain.js +113 -0
  196. package/src/render/group.d.ts +23 -0
  197. package/src/render/group.js +67 -0
  198. package/src/render/key.d.ts +5 -0
  199. package/src/render/key.js +91 -0
  200. package/src/render/report.d.ts +5 -0
  201. package/src/render/report.js +19 -0
  202. package/src/render/tiles.d.ts +6 -0
  203. package/src/render/tiles.js +77 -0
  204. package/src/render/use.d.ts +27 -0
  205. package/src/render/use.js +73 -0
  206. package/src/render/wrap.d.ts +14 -0
  207. package/src/render/wrap.js +199 -0
  208. package/src/render.js +553 -0
  209. package/src/rng.js +95 -0
  210. package/src/svg.js +69 -0
  211. package/src/text.d.ts +29 -0
  212. package/src/text.js +237 -0
  213. package/src/type/auto-color.d.ts +9 -0
  214. package/src/type/auto-color.js +44 -0
  215. package/src/type/fallback.d.ts +11 -0
  216. package/src/type/fallback.js +92 -0
  217. package/src/type/glyphs.d.ts +24 -0
  218. package/src/type/glyphs.js +87 -0
  219. package/src/type/index.d.ts +5 -0
  220. package/src/type/index.js +10 -0
  221. package/src/type/kern.d.ts +4 -0
  222. package/src/type/kern.js +144 -0
  223. package/src/type/layout-ref.d.ts +10 -0
  224. package/src/type/layout-ref.js +74 -0
  225. package/src/type/line.d.ts +11 -0
  226. package/src/type/line.js +105 -0
  227. package/src/type/live.d.ts +6 -0
  228. package/src/type/live.js +39 -0
  229. package/src/type/name.d.ts +4 -0
  230. package/src/type/name.js +32 -0
  231. package/src/type/path.d.ts +18 -0
  232. package/src/type/path.js +89 -0
  233. package/src/type/pixel.d.ts +9 -0
  234. package/src/type/pixel.js +115 -0
  235. package/src/type/sfnt.d.ts +20 -0
  236. package/src/type/sfnt.js +258 -0
  237. package/src/type/spans.d.ts +33 -0
  238. package/src/type/spans.js +138 -0
  239. package/src/type/symbols.d.ts +7 -0
  240. package/src/type/symbols.js +89 -0
  241. package/src/type/typeset.d.ts +10 -0
  242. package/src/type/typeset.js +352 -0
  243. package/src/type/woff2.d.ts +6 -0
  244. package/src/type/woff2.js +301 -0
  245. package/src/version.js +4 -0
package/src/icons.js ADDED
@@ -0,0 +1,191 @@
1
+ /**
2
+ * Icons: Iconify sets by name, or raw SVG.
3
+ *
4
+ * `'lucide:feather'` and `'simple-icons:github'` resolve through the
5
+ * `@iconify-json/<prefix>` package when it's installed (optional peer
6
+ * dependencies; any Iconify JSON set works the same way). A set can also be
7
+ * handed over directly with {@link registerIcons}, which is how to use
8
+ * icons without installing the packages, or in a bundler that can't
9
+ * resolve them.
10
+ *
11
+ * Raw input works too: an SVG string (its `viewBox` is read) or a bare
12
+ * path `d` with a `viewBox`.
13
+ *
14
+ * @module icons
15
+ */
16
+
17
+ import { node, settings, loadBytes } from './platform/index.js';
18
+ import { utf8 } from './platform/bytes.js';
19
+
20
+ /** @type {Map<string, IconSet>} */
21
+ const sets = new Map();
22
+
23
+ /**
24
+ * An Iconify JSON icon set (the shape of `@iconify-json/<prefix>/icons.json`).
25
+ *
26
+ * @typedef {object} IconSet
27
+ * @property {string} prefix
28
+ * @property {Record<string, { body: string, width?: number, height?: number, left?: number, top?: number }>} icons
29
+ * @property {Record<string, { parent: string, width?: number, height?: number }>} [aliases]
30
+ * @property {number} [width]
31
+ * @property {number} [height]
32
+ * @property {number} [left]
33
+ * @property {number} [top]
34
+ */
35
+
36
+ /**
37
+ * A resolved icon.
38
+ *
39
+ * @typedef {object} IconData
40
+ * @property {string} body - Inner SVG markup.
41
+ * @property {[number, number, number, number]} viewBox - `[minX, minY, width, height]`.
42
+ */
43
+
44
+ /**
45
+ * Register an Iconify icon set (for example the parsed
46
+ * `@iconify-json/lucide/icons.json`). Replaces any set with that prefix.
47
+ *
48
+ * @param {IconSet} set - The set.
49
+ * @returns {void}
50
+ *
51
+ * @example
52
+ * import lucide from '@iconify-json/lucide/icons.json' with { type: 'json' };
53
+ * registerIcons(lucide);
54
+ */
55
+ export function registerIcons(set) {
56
+ if (!set?.prefix || typeof set.icons !== 'object') throw new TypeError('registerIcons() expects an Iconify JSON set ({ prefix, icons })');
57
+ sets.set(set.prefix, set);
58
+ }
59
+
60
+ /**
61
+ * Load a set by prefix: a registered one, else `@iconify-json/<prefix>`.
62
+ *
63
+ * @param {string} prefix - e.g. `'lucide'`.
64
+ * @returns {IconSet} The set.
65
+ * @throws {Error} When the set isn't registered or installed.
66
+ */
67
+ function loadSet(prefix) {
68
+ let set = sets.get(prefix);
69
+ if (set) return set;
70
+ const pkg = `@iconify-json/${prefix}`;
71
+ const mod = node('module');
72
+ const fs = node('fs');
73
+ const path = node('path');
74
+ const url = node('url');
75
+ let file;
76
+ try {
77
+ if (!mod || !fs) throw new Error('no node');
78
+ const require = mod.createRequire(import.meta.url);
79
+ const here = String(import.meta.url).startsWith('file:') ? [url.fileURLToPath(new URL('.', import.meta.url))] : [];
80
+ file = path.join(require.resolve(`${pkg}/package.json`, { paths: [/** @type {any} */ (globalThis).process.cwd(), ...here] }), '..', 'icons.json');
81
+ } catch {
82
+ throw new Error(`Icon set "${prefix}" is not available. Install ${pkg}, or pass the set to registerIcons()${mod ? '' : ' (or configure({ icons }) with a URL to load sets from)'}.`);
83
+ }
84
+ set = /** @type {IconSet} */ (JSON.parse(fs.readFileSync(file, 'utf8')));
85
+ sets.set(prefix, set);
86
+ return set;
87
+ }
88
+
89
+ /**
90
+ * Make sure the icon sets these names need are loaded: from Node's
91
+ * `node_modules`, or (in a browser or Worker) from `configure({ icons })`,
92
+ * a URL template like `'https://cdn.jsdelivr.net/npm/@iconify-json/{prefix}/icons.json'`
93
+ * or a function of the prefix. Names whose set can't be found are left for
94
+ * {@link resolveIcon} to report.
95
+ *
96
+ * @param {Iterable<string>} names - Candidate icon names (`prefix:name`).
97
+ * @returns {Promise<void>}
98
+ */
99
+ export async function preloadIcons(names) {
100
+ const prefixes = new Set();
101
+ for (const n of names) {
102
+ const m = /^([a-z0-9-]+):([a-z0-9-]+)$/i.exec(n);
103
+ if (m && !sets.has(m[1])) prefixes.add(m[1]);
104
+ }
105
+ for (const prefix of prefixes) {
106
+ if (node('module')) {
107
+ try { loadSet(prefix); } catch { /* reported when drawn */ }
108
+ continue;
109
+ }
110
+ const where = typeof settings.icons === 'function' ? settings.icons(prefix) : settings.icons?.replace('{prefix}', prefix);
111
+ if (!where) continue;
112
+ try {
113
+ registerIcons(JSON.parse(utf8(await loadBytes(where, 'icons'))));
114
+ } catch { /* reported when drawn */ }
115
+ }
116
+ }
117
+
118
+ /**
119
+ * Resolve an Iconify name (`'prefix:name'`) to its markup and viewBox.
120
+ *
121
+ * @param {string} name - e.g. `'lucide:feather'`.
122
+ * @returns {IconData} The icon.
123
+ * @throws {Error} On a malformed name, a missing set or a missing icon.
124
+ *
125
+ * @example
126
+ * resolveIcon('lucide:feather').viewBox; // [0, 0, 24, 24]
127
+ */
128
+ export function resolveIcon(name) {
129
+ const m = String(name).match(/^([a-z0-9-]+):([a-z0-9-]+)$/i);
130
+ if (!m) throw new Error(`Icon names look like "lucide:feather", got "${name}"`);
131
+ const set = loadSet(m[1]);
132
+ let key = m[2];
133
+ /** @type {{ width?: number, height?: number }} */
134
+ let size = {};
135
+ for (let hops = 0; !set.icons[key] && set.aliases?.[key] && hops < 8; hops++) {
136
+ const alias = set.aliases[key];
137
+ size = { width: size.width ?? alias.width, height: size.height ?? alias.height };
138
+ key = alias.parent;
139
+ }
140
+ const icon = set.icons[key];
141
+ if (!icon) throw new Error(`Icon "${name}" was not found in the ${m[1]} set`);
142
+ return {
143
+ body: icon.body,
144
+ viewBox: [
145
+ icon.left ?? set.left ?? 0,
146
+ icon.top ?? set.top ?? 0,
147
+ size.width ?? icon.width ?? set.width ?? 16,
148
+ size.height ?? icon.height ?? set.height ?? 16,
149
+ ],
150
+ };
151
+ }
152
+
153
+ /**
154
+ * Read a raw SVG string: its inner markup and viewBox. Scripts,
155
+ * `foreignObject` and event-handler attributes are dropped.
156
+ *
157
+ * @param {string} svg - An `<svg …>…</svg>` string.
158
+ * @returns {IconData} The icon.
159
+ * @throws {Error} When there's no `<svg>` element or no size.
160
+ */
161
+ export function parseSvgIcon(svg) {
162
+ const open = svg.match(/<svg\b[^>]*>/i);
163
+ // Bare markup (a mark's paths on a 512 grid): wrap it.
164
+ if (!open && /^\s*<(path|g|circle|rect|polygon|ellipse|line|polyline)\b/i.test(svg)) return parseSvgIcon(`<svg viewBox="0 0 512 512">${svg}</svg>`);
165
+ if (!open) throw new Error('Icon SVG must contain an <svg> element');
166
+ const tag = open[0];
167
+ const vb = tag.match(/viewBox\s*=\s*["']([^"']+)["']/i);
168
+ let viewBox;
169
+ if (vb) {
170
+ viewBox = vb[1].trim().split(/[\s,]+/).map(Number);
171
+ } else {
172
+ const w = parseFloat(tag.match(/\bwidth\s*=\s*["']([\d.]+)/i)?.[1] ?? '');
173
+ const h = parseFloat(tag.match(/\bheight\s*=\s*["']([\d.]+)/i)?.[1] ?? '');
174
+ if (!(w > 0 && h > 0)) throw new Error('Icon SVG needs a viewBox or width/height');
175
+ viewBox = [0, 0, w, h];
176
+ }
177
+ if (viewBox.length !== 4 || viewBox.some((n) => !Number.isFinite(n))) throw new Error('Icon SVG has an unreadable viewBox');
178
+
179
+ // Presentation attributes on the root (fill="none", stroke=…) apply to the body.
180
+ const inherited = [...tag.matchAll(/\b(fill|stroke|stroke-width|stroke-linecap|stroke-linejoin)\s*=\s*("[^"]*"|'[^']*')/gi)]
181
+ .map((m) => `${m[1]}=${m[2]}`)
182
+ .join(' ');
183
+ const start = svg.indexOf(tag) + tag.length;
184
+ const end = svg.lastIndexOf('</svg>');
185
+ let body = svg.slice(start, end > start ? end : undefined);
186
+ body = body
187
+ .replace(/<script\b[\s\S]*?<\/script>/gi, '')
188
+ .replace(/<foreignObject\b[\s\S]*?<\/foreignObject>/gi, '')
189
+ .replace(/\son[a-z]+\s*=\s*("[^"]*"|'[^']*')/gi, '');
190
+ return { body: inherited ? `<g ${inherited}>${body}</g>` : body, viewBox: /** @type {any} */ (viewBox) };
191
+ }