@arraypress/covers 1.0.0 → 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 (213) hide show
  1. package/CHANGELOG.md +76 -0
  2. package/README.md +296 -11
  3. package/package.json +33 -5
  4. package/recipes/brand.json +1143 -0
  5. package/schema/recipe.schema.json +7300 -770
  6. package/src/animate/index.d.ts +19 -0
  7. package/src/animate/index.js +116 -0
  8. package/src/builtins.js +4 -0
  9. package/src/effects/ascii.d.ts +7 -0
  10. package/src/effects/ascii.js +93 -0
  11. package/src/effects/buffer.d.ts +60 -0
  12. package/src/effects/buffer.js +472 -0
  13. package/src/effects/detail.d.ts +12 -0
  14. package/src/effects/detail.js +124 -0
  15. package/src/effects/digital.d.ts +14 -0
  16. package/src/effects/digital.js +216 -0
  17. package/src/effects/distort.d.ts +20 -0
  18. package/src/effects/distort.js +314 -0
  19. package/src/effects/dither.d.ts +8 -0
  20. package/src/effects/dither.js +147 -0
  21. package/src/effects/drop-shadow.d.ts +4 -0
  22. package/src/effects/drop-shadow.js +45 -0
  23. package/src/effects/extrude.d.ts +5 -0
  24. package/src/effects/extrude.js +55 -0
  25. package/src/effects/film.d.ts +11 -0
  26. package/src/effects/film.js +204 -0
  27. package/src/effects/glow.d.ts +8 -0
  28. package/src/effects/glow.js +56 -0
  29. package/src/effects/grade.d.ts +30 -0
  30. package/src/effects/grade.js +274 -0
  31. package/src/effects/halftone.d.ts +8 -0
  32. package/src/effects/halftone.js +95 -0
  33. package/src/effects/index.d.ts +125 -0
  34. package/src/effects/index.js +277 -0
  35. package/src/effects/ink.d.ts +12 -0
  36. package/src/effects/ink.js +70 -0
  37. package/src/effects/lens.d.ts +14 -0
  38. package/src/effects/lens.js +277 -0
  39. package/src/effects/light.d.ts +10 -0
  40. package/src/effects/light.js +59 -0
  41. package/src/effects/looks.d.ts +9 -0
  42. package/src/effects/looks.js +74 -0
  43. package/src/effects/mask.d.ts +52 -0
  44. package/src/effects/mask.js +314 -0
  45. package/src/effects/motion.d.ts +6 -0
  46. package/src/effects/motion.js +60 -0
  47. package/src/effects/newsprint.d.ts +6 -0
  48. package/src/effects/newsprint.js +89 -0
  49. package/src/effects/optics.d.ts +10 -0
  50. package/src/effects/optics.js +213 -0
  51. package/src/effects/options.d.ts +6 -0
  52. package/src/effects/options.js +106 -0
  53. package/src/effects/paint-presets.d.ts +10 -0
  54. package/src/effects/paint-presets.js +47 -0
  55. package/src/effects/paint.d.ts +49 -0
  56. package/src/effects/paint.js +66 -0
  57. package/src/effects/pixels.d.ts +24 -0
  58. package/src/effects/pixels.js +138 -0
  59. package/src/effects/polar.d.ts +10 -0
  60. package/src/effects/polar.js +265 -0
  61. package/src/effects/region.d.ts +8 -0
  62. package/src/effects/region.js +136 -0
  63. package/src/effects/round-border.d.ts +5 -0
  64. package/src/effects/round-border.js +62 -0
  65. package/src/effects/screen.d.ts +14 -0
  66. package/src/effects/screen.js +212 -0
  67. package/src/effects/sort.d.ts +8 -0
  68. package/src/effects/sort.js +125 -0
  69. package/src/effects/symmetry.d.ts +6 -0
  70. package/src/effects/symmetry.js +74 -0
  71. package/src/effects/tile.d.ts +7 -0
  72. package/src/effects/tile.js +55 -0
  73. package/src/effects/tone.d.ts +16 -0
  74. package/src/effects/tone.js +117 -0
  75. package/src/effects/transform.d.ts +35 -0
  76. package/src/effects/transform.js +127 -0
  77. package/src/effects/util.d.ts +16 -0
  78. package/src/effects/util.js +85 -0
  79. package/src/extract.js +4 -3
  80. package/src/fonts.d.ts +55 -0
  81. package/src/fonts.js +246 -53
  82. package/src/formats/cut.d.ts +10 -0
  83. package/src/formats/cut.js +77 -0
  84. package/src/formats/index.d.ts +6 -0
  85. package/src/formats/index.js +9 -0
  86. package/src/formats/presets.d.ts +41 -0
  87. package/src/formats/presets.js +89 -0
  88. package/src/formats/print.d.ts +25 -0
  89. package/src/formats/print.js +117 -0
  90. package/src/formats/zones.d.ts +10 -0
  91. package/src/formats/zones.js +64 -0
  92. package/src/geometry.js +1 -1
  93. package/src/icons.js +43 -9
  94. package/src/index.d.ts +205 -19
  95. package/src/index.js +12 -4
  96. package/src/inter-data.js +27 -0
  97. package/src/json-recipe.js +181 -23
  98. package/src/kit/index.d.ts +20 -0
  99. package/src/kit/index.js +58 -0
  100. package/src/layer-options.js +23 -4
  101. package/src/layers/barcode.d.ts +19 -0
  102. package/src/layers/barcode.js +63 -0
  103. package/src/layers/code128.d.ts +4 -0
  104. package/src/layers/code128.js +28 -0
  105. package/src/layers/expr.d.ts +6 -0
  106. package/src/layers/expr.js +121 -0
  107. package/src/layers/geometry.d.ts +6 -0
  108. package/src/layers/geometry.js +238 -0
  109. package/src/layers/index.d.ts +18 -0
  110. package/src/layers/index.js +15 -0
  111. package/src/layers/perforation.d.ts +14 -0
  112. package/src/layers/perforation.js +47 -0
  113. package/src/layers/repeat.d.ts +29 -0
  114. package/src/layers/repeat.js +90 -0
  115. package/src/layers/shape.d.ts +46 -0
  116. package/src/layers/shape.js +115 -0
  117. package/src/layers/soft.d.ts +5 -0
  118. package/src/layers/soft.js +43 -0
  119. package/src/layers/svg.d.ts +23 -0
  120. package/src/layers/svg.js +109 -0
  121. package/src/layers/table.d.ts +25 -0
  122. package/src/layers/table.js +80 -0
  123. package/src/layers/tear.d.ts +21 -0
  124. package/src/layers/tear.js +74 -0
  125. package/src/layers/texture.d.ts +17 -0
  126. package/src/layers/texture.js +106 -0
  127. package/src/layers/util.d.ts +8 -0
  128. package/src/layers/util.js +48 -0
  129. package/src/layers.js +125 -41
  130. package/src/lint/image-size.d.ts +4 -0
  131. package/src/lint/image-size.js +34 -0
  132. package/src/lint/index.d.ts +16 -0
  133. package/src/lint/index.js +127 -0
  134. package/src/lint/rules.d.ts +5 -0
  135. package/src/lint/rules.js +19 -0
  136. package/src/node.d.ts +2 -0
  137. package/src/node.js +20 -0
  138. package/src/platform/bytes.d.ts +22 -0
  139. package/src/platform/bytes.js +103 -0
  140. package/src/platform/compress.d.ts +12 -0
  141. package/src/platform/compress.js +81 -0
  142. package/src/platform/harfbuzz.d.ts +9 -0
  143. package/src/platform/harfbuzz.js +80 -0
  144. package/src/platform/index.d.ts +8 -0
  145. package/src/platform/index.js +13 -0
  146. package/src/platform/load.d.ts +6 -0
  147. package/src/platform/load.js +72 -0
  148. package/src/platform/no-harfbuzz.d.ts +2 -0
  149. package/src/platform/no-harfbuzz.js +11 -0
  150. package/src/platform/node.d.ts +26 -0
  151. package/src/platform/node.js +86 -0
  152. package/src/platform/settings.d.ts +28 -0
  153. package/src/platform/settings.js +51 -0
  154. package/src/png.js +77 -28
  155. package/src/print.js +8 -7
  156. package/src/raster/index.d.ts +24 -0
  157. package/src/raster/index.js +171 -0
  158. package/src/recipes.js +4 -3
  159. package/src/render/backdrop.d.ts +6 -0
  160. package/src/render/backdrop.js +55 -0
  161. package/src/render/content.d.ts +5 -0
  162. package/src/render/content.js +58 -0
  163. package/src/render/context.d.ts +82 -0
  164. package/src/render/grain.d.ts +7 -0
  165. package/src/render/grain.js +113 -0
  166. package/src/render/group.d.ts +23 -0
  167. package/src/render/group.js +67 -0
  168. package/src/render/key.d.ts +5 -0
  169. package/src/render/key.js +91 -0
  170. package/src/render/report.d.ts +5 -0
  171. package/src/render/report.js +19 -0
  172. package/src/render/tiles.d.ts +6 -0
  173. package/src/render/tiles.js +77 -0
  174. package/src/render/use.d.ts +27 -0
  175. package/src/render/use.js +73 -0
  176. package/src/render/wrap.d.ts +14 -0
  177. package/src/render/wrap.js +199 -0
  178. package/src/render.js +303 -212
  179. package/src/text.d.ts +29 -0
  180. package/src/text.js +22 -15
  181. package/src/type/auto-color.d.ts +9 -0
  182. package/src/type/auto-color.js +44 -0
  183. package/src/type/fallback.d.ts +11 -0
  184. package/src/type/fallback.js +92 -0
  185. package/src/type/glyphs.d.ts +24 -0
  186. package/src/type/glyphs.js +87 -0
  187. package/src/type/index.d.ts +5 -0
  188. package/src/type/index.js +10 -0
  189. package/src/type/kern.d.ts +4 -0
  190. package/src/type/kern.js +144 -0
  191. package/src/type/layout-ref.d.ts +10 -0
  192. package/src/type/layout-ref.js +74 -0
  193. package/src/type/line.d.ts +11 -0
  194. package/src/type/line.js +105 -0
  195. package/src/type/live.d.ts +6 -0
  196. package/src/type/live.js +39 -0
  197. package/src/type/name.d.ts +4 -0
  198. package/src/type/name.js +32 -0
  199. package/src/type/path.d.ts +18 -0
  200. package/src/type/path.js +89 -0
  201. package/src/type/pixel.d.ts +9 -0
  202. package/src/type/pixel.js +115 -0
  203. package/src/type/sfnt.d.ts +20 -0
  204. package/src/type/sfnt.js +258 -0
  205. package/src/type/spans.d.ts +33 -0
  206. package/src/type/spans.js +138 -0
  207. package/src/type/symbols.d.ts +7 -0
  208. package/src/type/symbols.js +89 -0
  209. package/src/type/typeset.d.ts +10 -0
  210. package/src/type/typeset.js +352 -0
  211. package/src/type/woff2.d.ts +6 -0
  212. package/src/type/woff2.js +301 -0
  213. package/src/version.js +4 -0
@@ -0,0 +1,127 @@
1
+ /**
2
+ * A layer's `transform` option as an SVG transform.
3
+ *
4
+ * @module effects/transform
5
+ */
6
+
7
+ import { num } from '../svg.js';
8
+ import { pos } from '../layers/util.js';
9
+
10
+ /**
11
+ * A layer's `transform` as an SVG transform string.
12
+ *
13
+ * Object form: `translate` (`[x, y]` or `{ x, y }`, lengths), `rotate`
14
+ * (degrees), `scale` (a number or `[sx, sy]`), `skewX`, `skewY`, `mirror`
15
+ * (`'x'` flips left–right, `'y'` top–bottom), all about `origin` (`[x, y]`
16
+ * px or `'center'`, the default). A string is used as written.
17
+ *
18
+ * @param {any} t
19
+ * @param {{ width: number, height: number }} canvas
20
+ * @returns {string | undefined}
21
+ */
22
+ export function transformAttr(t, canvas) {
23
+ if (!t) return undefined;
24
+ if (typeof t === 'string') return t;
25
+ const parts = [];
26
+ const tr = Array.isArray(t.translate) ? { x: t.translate[0], y: t.translate[1] } : t.translate;
27
+ if (tr) parts.push(`translate(${num(pos(tr.x ?? 0, 'x', canvas))} ${num(pos(tr.y ?? 0, 'y', canvas))})`);
28
+ const o = t.origin === undefined || t.origin === 'center'
29
+ ? [canvas.width / 2, canvas.height / 2]
30
+ : Array.isArray(t.origin) ? [pos(t.origin[0], 'x', canvas), pos(t.origin[1], 'y', canvas)] : [pos(t.origin.x, 'x', canvas), pos(t.origin.y, 'y', canvas)];
31
+ const inner = [];
32
+ if (t.rotate) inner.push(`rotate(${num(t.rotate, 3)})`);
33
+ let [sx, sy] = t.scale == null ? [1, 1] : Array.isArray(t.scale) ? t.scale : [t.scale, t.scale];
34
+ if (t.mirror === 'x' || t.mirror === 'both') sx = -sx;
35
+ if (t.mirror === 'y' || t.mirror === 'both') sy = -sy;
36
+ if (sx !== 1 || sy !== 1) inner.push(`scale(${num(sx, 4)} ${num(sy, 4)})`);
37
+ if (t.skewX) inner.push(`skewX(${num(t.skewX, 3)})`);
38
+ if (t.skewY) inner.push(`skewY(${num(t.skewY, 3)})`);
39
+ if (inner.length) parts.push(`translate(${num(o[0])} ${num(o[1])}) ${inner.join(' ')} translate(${num(-o[0])} ${num(-o[1])})`);
40
+ return parts.length ? parts.join(' ') : undefined;
41
+ }
42
+
43
+ /** @typedef {[number, number, number, number, number, number]} Affine - `[a, b, c, d, e, f]`, as SVG's `matrix()`. */
44
+
45
+ /** @param {Affine} m @param {Affine} n @returns {Affine} `m × n`. */
46
+ const multiply = (m, n) => [
47
+ m[0] * n[0] + m[2] * n[1], m[1] * n[0] + m[3] * n[1],
48
+ m[0] * n[2] + m[2] * n[3], m[1] * n[2] + m[3] * n[3],
49
+ m[0] * n[4] + m[2] * n[5] + m[4], m[1] * n[4] + m[3] * n[5] + m[5],
50
+ ];
51
+
52
+ /** @param {string} name @param {number[]} v @returns {Affine} One SVG transform function as a matrix. */
53
+ function fn(name, v) {
54
+ const r = ((v[0] ?? 0) * Math.PI) / 180;
55
+ switch (name) {
56
+ case 'translate': return [1, 0, 0, 1, v[0] ?? 0, v[1] ?? 0];
57
+ case 'scale': return [v[0] ?? 1, 0, 0, v[1] ?? v[0] ?? 1, 0, 0];
58
+ case 'rotate': {
59
+ const m = /** @type {Affine} */ ([Math.cos(r), Math.sin(r), -Math.sin(r), Math.cos(r), 0, 0]);
60
+ if (v.length < 3) return m;
61
+ return multiply(multiply([1, 0, 0, 1, v[1], v[2]], m), [1, 0, 0, 1, -v[1], -v[2]]);
62
+ }
63
+ case 'skewX': return [1, 0, Math.tan(r), 1, 0, 0];
64
+ case 'skewY': return [1, Math.tan(r), 0, 1, 0, 0];
65
+ case 'matrix': return /** @type {Affine} */ (v.slice(0, 6));
66
+ default: return [1, 0, 0, 1, 0, 0];
67
+ }
68
+ }
69
+
70
+ /**
71
+ * A transform (an SVG transform string, or the object form) as one matrix.
72
+ *
73
+ * @param {any} t
74
+ * @param {{ width: number, height: number }} canvas
75
+ * @returns {Affine}
76
+ */
77
+ export function transformMatrix(t, canvas) {
78
+ const s = transformAttr(t, canvas);
79
+ /** @type {Affine} */
80
+ let m = [1, 0, 0, 1, 0, 0];
81
+ if (!s) return m;
82
+ for (const [, name, args] of s.matchAll(/(\w+)\s*\(([^)]*)\)/g)) m = multiply(m, fn(name, args.split(/[\s,]+/).filter(Boolean).map(Number)));
83
+ return m;
84
+ }
85
+
86
+ /**
87
+ * How much a matrix enlarges what it draws: its smallest and largest
88
+ * stretch (singular values), and their geometric mean.
89
+ *
90
+ * @param {Affine} m
91
+ * @returns {{ min: number, max: number, mean: number }}
92
+ */
93
+ export function stretchOf(m) {
94
+ const [a, b, c, d] = m;
95
+ const sum = a * a + b * b + c * c + d * d;
96
+ const det = Math.abs(a * d - b * c);
97
+ const root = Math.sqrt(Math.max(0, sum * sum - 4 * det * det));
98
+ return { min: Math.sqrt((sum - root) / 2), max: Math.sqrt((sum + root) / 2), mean: Math.sqrt(det) };
99
+ }
100
+
101
+ /**
102
+ * The inverse of an affine matrix.
103
+ *
104
+ * @param {Affine} m
105
+ * @returns {Affine}
106
+ */
107
+ export function invert(m) {
108
+ const [a, b, c, d, e, f] = m;
109
+ const det = a * d - b * c || 1e-12;
110
+ return [d / det, -b / det, -c / det, a / det, (c * f - d * e) / det, (b * e - a * f) / det];
111
+ }
112
+
113
+ /**
114
+ * A point through an affine matrix.
115
+ *
116
+ * @param {Affine} m @param {number} x @param {number} y
117
+ * @returns {[number, number]}
118
+ */
119
+ export function apply(m, x, y) {
120
+ return [m[0] * x + m[2] * y + m[4], m[1] * x + m[3] * y + m[5]];
121
+ }
122
+
123
+ /** The identity matrix. @type {Affine} */
124
+ export const IDENTITY = Object.freeze(/** @type {Affine} */ ([1, 0, 0, 1, 0, 0]));
125
+
126
+ /** @param {Affine} m @param {Affine} n @returns {Affine} `m` then `n` (n applied first, in m's space). */
127
+ export const compose = (m, n) => multiply(m, n);
@@ -0,0 +1,16 @@
1
+ // Helpers for writing filter primitives.
2
+
3
+ /** Rec. 709 luma weights. */
4
+ export const LUMA: [number, number, number];
5
+ /** A colour as 0–1 channels. */
6
+ export function rgb(c: string): [number, number, number];
7
+ /** A colour-matrix value list from 20 numbers. */
8
+ export function mat(m: number[]): string;
9
+ /** A matrix flooding RGB with a colour, alpha from a 5-number row (default the source alpha). */
10
+ export function flood(color: string, alpha?: number[]): string;
11
+ /** The effect's `seed`, else a seeded one. */
12
+ export function seedOf(ctx: { rng: { int: (a: number, b: number) => number } }, fx: { seed?: number }): number;
13
+ /** A `<filter>` over the canvas, padded by `pad` (a fraction) on each side, in user space. */
14
+ export function filterElement(id: string, ctx: { width: number; height: number }, pad: number, body: string, colorSpace?: 'sRGB' | 'linearRGB', region?: { x: number; y: number; width: number; height: number }): string;
15
+ /** Turbulence fed to a displacement map. */
16
+ export function displace(frequency: number | number[], octaves: number, seed: number, scale: number, result?: string): string;
@@ -0,0 +1,85 @@
1
+ /**
2
+ * Helpers for writing filter primitives.
3
+ *
4
+ * @module effects/util
5
+ */
6
+
7
+ import { attrs, num } from '../svg.js';
8
+ import { toHex } from '../color.js';
9
+
10
+ /** Rec. 709 luma weights. */
11
+ export const LUMA = [0.2126, 0.7152, 0.0722];
12
+
13
+ /**
14
+ * A colour as 0–1 channels.
15
+ *
16
+ * @param {string} c
17
+ * @returns {[number, number, number]}
18
+ */
19
+ export function rgb(c) {
20
+ const h = toHex(c);
21
+ return /** @type {[number, number, number]} */ ([1, 3, 5].map((i) => parseInt(h.slice(i, i + 2), 16) / 255));
22
+ }
23
+
24
+ /**
25
+ * A colour-matrix value list.
26
+ *
27
+ * @param {number[]} m - 20 numbers.
28
+ * @returns {string}
29
+ */
30
+ export const mat = (m) => m.map((x) => num(x, 4)).join(' ');
31
+
32
+ /**
33
+ * A matrix that floods RGB with a colour and takes alpha from `alpha` (a
34
+ * 5-number row; default the source alpha).
35
+ *
36
+ * @param {string} color
37
+ * @param {number[]} [alpha]
38
+ * @returns {string}
39
+ */
40
+ export function flood(color, alpha = [0, 0, 0, 1, 0]) {
41
+ const [r, g, b] = rgb(color);
42
+ return mat([0, 0, 0, 0, r, 0, 0, 0, 0, g, 0, 0, 0, 0, b, ...alpha]);
43
+ }
44
+
45
+ /**
46
+ * A layer's seeded turbulence seed (or the effect's own `seed`).
47
+ *
48
+ * @param {{ rng: { int: (a: number, b: number) => number } }} ctx
49
+ * @param {{ seed?: number }} fx
50
+ * @returns {number}
51
+ */
52
+ export const seedOf = (ctx, fx) => fx.seed ?? ctx.rng.int(1, 9999);
53
+
54
+ /**
55
+ * A `<filter>` over the canvas, padded, in user space.
56
+ *
57
+ * @param {string} id
58
+ * @param {{ width: number, height: number }} ctx
59
+ * @param {number} pad - Fraction of the canvas on each side.
60
+ * @param {string} body - Primitives.
61
+ * @param {'sRGB' | 'linearRGB'} [colorSpace='sRGB'] - Where the primitives do their arithmetic.
62
+ * @param {{ x: number, y: number, width: number, height: number }} [region] - A smaller region (the content's box plus padding).
63
+ * @returns {string}
64
+ */
65
+ export function filterElement(id, ctx, pad, body, colorSpace = 'sRGB', region) {
66
+ const px = ctx.width * pad;
67
+ const py = ctx.height * pad;
68
+ if (colorSpace !== 'sRGB' && colorSpace !== 'linearRGB') throw new TypeError(`Unknown colorSpace "${colorSpace}" (sRGB, linearRGB)`);
69
+ const r = region ?? { x: -px, y: -py, width: ctx.width + 2 * px, height: ctx.height + 2 * py };
70
+ return `<filter${attrs({ id, filterUnits: 'userSpaceOnUse', primitiveUnits: 'userSpaceOnUse', ...r, 'color-interpolation-filters': colorSpace })}>${body}</filter>`;
71
+ }
72
+
73
+ /**
74
+ * Noise turned into displacement: the shared start of rough, warp and wear.
75
+ *
76
+ * @param {number | number[]} frequency
77
+ * @param {number} octaves
78
+ * @param {number} seed
79
+ * @param {number} scale - Displacement, px.
80
+ * @param {string} [result]
81
+ * @returns {string}
82
+ */
83
+ export function displace(frequency, octaves, seed, scale, result) {
84
+ return `<feTurbulence type="fractalNoise" baseFrequency="${[].concat(/** @type {any} */ (frequency)).map((f) => num(f, 4)).join(' ')}" numOctaves="${octaves}" seed="${seed}" result="n"/><feDisplacementMap in="SourceGraphic" in2="n" scale="${num(scale)}" xChannelSelector="R" yChannelSelector="G"${result ? ` result="${result}"` : ''}/>`;
85
+ }
package/src/extract.js CHANGED
@@ -4,7 +4,7 @@
4
4
  * @module extract
5
5
  */
6
6
 
7
- import { readFile } from 'node:fs/promises';
7
+ import { loadBytes } from './platform/index.js';
8
8
  import { toOklch, fromOklch, toHex } from './color.js';
9
9
  import { createRng } from './rng.js';
10
10
 
@@ -35,11 +35,12 @@ export function extractPalette(src, options = {}) {
35
35
  const job = (async () => {
36
36
  let sharp;
37
37
  try {
38
- sharp = (await import('sharp')).default;
38
+ const name = 'sharp';
39
+ sharp = (await import(/* @vite-ignore */ name)).default;
39
40
  } catch {
40
41
  throw new Error('Extracting a palette from a photo needs sharp: npm install sharp');
41
42
  }
42
- const bytes = typeof src === 'string' ? await readFile(src) : src;
43
+ const bytes = await loadBytes(src, 'image');
43
44
  const { data } = await sharp(bytes).rotate().resize(64, 64, { fit: 'cover' }).removeAlpha().raw().toBuffer({ resolveWithObject: true });
44
45
  /** @type {[number, number, number][]} */
45
46
  const pts = [];
package/src/fonts.d.ts ADDED
@@ -0,0 +1,55 @@
1
+ // Fonts: loading, decoding and picking a face.
2
+ import type { FontSource } from './index.js';
3
+ import type { HarfBuzzModule } from './platform/harfbuzz.js';
4
+
5
+ /** A shaped glyph, font units. */
6
+ export interface RunGlyph {
7
+ gid: number;
8
+ cluster: number;
9
+ xAdvance: number;
10
+ xOffset: number;
11
+ yOffset: number;
12
+ }
13
+
14
+ /** A loaded face, ready to shape with (HarfBuzz, or the JavaScript reader in Workers). */
15
+ export interface LoadedFont {
16
+ name: string;
17
+ weight: number;
18
+ style: string;
19
+ /** The harfbuzzjs Font, or the JavaScript face. */
20
+ font: object;
21
+ upem: number;
22
+ ascender: number;
23
+ descender: number;
24
+ capHeight: number;
25
+ /** Parsed outline commands by glyph id. */
26
+ paths: Map<number, (string | number)[]>;
27
+ /** Shape one line. */
28
+ shapeRun: (text: string) => RunGlyph[];
29
+ /** A glyph's outline, font units, y up. */
30
+ glyphToPath: (gid: number) => string;
31
+ axes: Record<string, { min: number; default: number; max: number }>;
32
+ variations: Record<string, number>;
33
+ source: FontSource;
34
+ }
35
+
36
+ /** HarfBuzz, or undefined where it can't run (Workers) or is switched off. */
37
+ export function harfbuzz(): Promise<HarfBuzzModule | undefined>;
38
+ /** The bundled Inter faces (bytes from disk in Node, else loaded on first use). */
39
+ export function bundledFonts(): FontSource[];
40
+ /** A cover's fonts, then the registered ones, then Inter. */
41
+ export function fontPool(own: FontSource[]): FontSource[];
42
+ /** Register a font for every cover. */
43
+ export function registerFont(font: FontSource): void;
44
+ /** A font source's bytes. */
45
+ export function fontBytes(source: FontSource): Promise<Uint8Array>;
46
+ /** WOFF or sfnt bytes as sfnt, synchronously (Node). */
47
+ export function decodeFont(input: Uint8Array | ArrayBuffer): Uint8Array;
48
+ /** WOFF or sfnt bytes as sfnt, on any platform. */
49
+ export function decodeFontAsync(input: Uint8Array | ArrayBuffer): Promise<Uint8Array>;
50
+ /** Load a face, optionally at a variation (`{ wght: 650, wdth: 80 }`). */
51
+ export function loadFont(source: FontSource, variations?: Record<string, number>): Promise<LoadedFont>;
52
+ /** The closest face for a family, weight and style (a variable range matches inside it). */
53
+ export function pickFont(sources: FontSource[], family: string, weight: number, style?: string): FontSource;
54
+ /** A layer's variation settings (`wght` follows the weight on a variable font). */
55
+ export function variationsFor(source: FontSource, weight: number, axes: Record<string, number> | undefined): Record<string, number> | undefined;