@altnovatrail/picture-kit 0.0.0-stage → 0.1.1

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 (122) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +7 -0
  3. package/README.md +28 -2
  4. package/lib/emoji.d.ts +16 -0
  5. package/lib/emoji.js +64 -0
  6. package/lib/index.d.ts +9 -0
  7. package/lib/index.js +10 -0
  8. package/lib/kind.d.ts +22 -0
  9. package/lib/kind.js +2 -0
  10. package/lib/kinds/balance.d.ts +34 -0
  11. package/lib/kinds/balance.js +217 -0
  12. package/lib/kinds/branches.d.ts +33 -0
  13. package/lib/kinds/branches.js +473 -0
  14. package/lib/kinds/calendar.d.ts +55 -0
  15. package/lib/kinds/calendar.js +532 -0
  16. package/lib/kinds/chart.d.ts +48 -0
  17. package/lib/kinds/chart.js +645 -0
  18. package/lib/kinds/choices.d.ts +14 -0
  19. package/lib/kinds/choices.js +53 -0
  20. package/lib/kinds/clock.d.ts +36 -0
  21. package/lib/kinds/clock.js +219 -0
  22. package/lib/kinds/coins.d.ts +37 -0
  23. package/lib/kinds/coins.js +550 -0
  24. package/lib/kinds/column.d.ts +37 -0
  25. package/lib/kinds/column.js +410 -0
  26. package/lib/kinds/commands-parts.d.ts +12 -0
  27. package/lib/kinds/commands-parts.js +24 -0
  28. package/lib/kinds/commands.d.ts +66 -0
  29. package/lib/kinds/commands.js +789 -0
  30. package/lib/kinds/containers.d.ts +52 -0
  31. package/lib/kinds/containers.js +758 -0
  32. package/lib/kinds/countfig.d.ts +41 -0
  33. package/lib/kinds/countfig.js +372 -0
  34. package/lib/kinds/cubes.d.ts +70 -0
  35. package/lib/kinds/cubes.js +371 -0
  36. package/lib/kinds/die.d.ts +32 -0
  37. package/lib/kinds/die.js +301 -0
  38. package/lib/kinds/domino.d.ts +37 -0
  39. package/lib/kinds/domino.js +450 -0
  40. package/lib/kinds/dotgrid.d.ts +38 -0
  41. package/lib/kinds/dotgrid.js +411 -0
  42. package/lib/kinds/figure.d.ts +62 -0
  43. package/lib/kinds/figure.js +687 -0
  44. package/lib/kinds/fold-parts.d.ts +73 -0
  45. package/lib/kinds/fold-parts.js +315 -0
  46. package/lib/kinds/fold.d.ts +52 -0
  47. package/lib/kinds/fold.js +650 -0
  48. package/lib/kinds/fraction.d.ts +50 -0
  49. package/lib/kinds/fraction.js +568 -0
  50. package/lib/kinds/gauges.d.ts +53 -0
  51. package/lib/kinds/gauges.js +880 -0
  52. package/lib/kinds/gears.d.ts +40 -0
  53. package/lib/kinds/gears.js +787 -0
  54. package/lib/kinds/grid.d.ts +45 -0
  55. package/lib/kinds/grid.js +591 -0
  56. package/lib/kinds/groups.d.ts +23 -0
  57. package/lib/kinds/groups.js +335 -0
  58. package/lib/kinds/index.d.ts +3 -0
  59. package/lib/kinds/index.js +87 -0
  60. package/lib/kinds/lanes.d.ts +36 -0
  61. package/lib/kinds/lanes.js +220 -0
  62. package/lib/kinds/layers.d.ts +31 -0
  63. package/lib/kinds/layers.js +419 -0
  64. package/lib/kinds/line.d.ts +38 -0
  65. package/lib/kinds/line.js +739 -0
  66. package/lib/kinds/magic-parts.d.ts +72 -0
  67. package/lib/kinds/magic-parts.js +186 -0
  68. package/lib/kinds/magic.d.ts +66 -0
  69. package/lib/kinds/magic.js +664 -0
  70. package/lib/kinds/map.d.ts +32 -0
  71. package/lib/kinds/map.js +370 -0
  72. package/lib/kinds/matchsticks.d.ts +26 -0
  73. package/lib/kinds/matchsticks.js +434 -0
  74. package/lib/kinds/necklace.d.ts +27 -0
  75. package/lib/kinds/necklace.js +342 -0
  76. package/lib/kinds/net.d.ts +47 -0
  77. package/lib/kinds/net.js +241 -0
  78. package/lib/kinds/overlay.d.ts +50 -0
  79. package/lib/kinds/overlay.js +519 -0
  80. package/lib/kinds/pieces.d.ts +41 -0
  81. package/lib/kinds/pieces.js +420 -0
  82. package/lib/kinds/pipes.d.ts +46 -0
  83. package/lib/kinds/pipes.js +657 -0
  84. package/lib/kinds/plane-parts.d.ts +105 -0
  85. package/lib/kinds/plane-parts.js +372 -0
  86. package/lib/kinds/plane.d.ts +35 -0
  87. package/lib/kinds/plane.js +755 -0
  88. package/lib/kinds/pyramid.d.ts +26 -0
  89. package/lib/kinds/pyramid.js +228 -0
  90. package/lib/kinds/ropes.d.ts +30 -0
  91. package/lib/kinds/ropes.js +571 -0
  92. package/lib/kinds/shapes.d.ts +59 -0
  93. package/lib/kinds/shapes.js +490 -0
  94. package/lib/kinds/solids.d.ts +78 -0
  95. package/lib/kinds/solids.js +1058 -0
  96. package/lib/kinds/tangram.d.ts +52 -0
  97. package/lib/kinds/tangram.js +713 -0
  98. package/lib/kinds/target.d.ts +39 -0
  99. package/lib/kinds/target.js +761 -0
  100. package/lib/kinds/tiles.d.ts +55 -0
  101. package/lib/kinds/tiles.js +606 -0
  102. package/lib/kinds/venn.d.ts +38 -0
  103. package/lib/kinds/venn.js +710 -0
  104. package/lib/noto.d.ts +2 -0
  105. package/lib/noto.js +212 -0
  106. package/lib/objects.d.ts +7 -0
  107. package/lib/objects.js +226 -0
  108. package/lib/pen.d.ts +32 -0
  109. package/lib/pen.js +60 -0
  110. package/lib/read.d.ts +9 -0
  111. package/lib/read.js +49 -0
  112. package/lib/render.d.ts +24 -0
  113. package/lib/render.js +68 -0
  114. package/lib/solve/balance.d.ts +46 -0
  115. package/lib/solve/balance.js +118 -0
  116. package/lib/style.d.ts +70 -0
  117. package/lib/style.js +39 -0
  118. package/lib/svg.d.ts +22 -0
  119. package/lib/svg.js +48 -0
  120. package/lib/things.d.ts +40 -0
  121. package/lib/things.js +269 -0
  122. package/package.json +28 -4
@@ -0,0 +1,73 @@
1
+ import type { P } from "../svg.ts";
2
+ /**
3
+ * The atoms of a sheet of squares: each square cut by its two diagonals into
4
+ * four quarters, the triangles between its sides and its centre. A fold along
5
+ * a line of the squares or along their diagonals, a quarter turn and a flip
6
+ * all take quarters onto quarters, so whatever is folded, punched, cut,
7
+ * turned or laid together stays exact, quarter by quarter.
8
+ */
9
+ export declare const quarters: readonly ["top", "right", "bottom", "left"];
10
+ export type Quarter = (typeof quarters)[number];
11
+ /** An atom is the quarter q (an index of quarters) of the square at row r, column c, from 0. */
12
+ export type Atom = {
13
+ r: number;
14
+ c: number;
15
+ q: number;
16
+ };
17
+ /** The parts of a square: whole, the half at a corner, or a quarter. */
18
+ export declare const parts: readonly ["whole", "nw", "ne", "se", "sw", "top", "right", "bottom", "left"];
19
+ export type Part = (typeof parts)[number];
20
+ export declare const partQuarters: Record<Part, readonly number[]>;
21
+ /** A map of the plane, x' = a x + c y + e and y' = b x + d y + f, as SVG writes a matrix. */
22
+ export type Mat = readonly [number, number, number, number, number, number];
23
+ export declare const identity: Mat;
24
+ /** andThen is the map that does m first and k after it. */
25
+ export declare function andThen(m: Mat, k: Mat): Mat;
26
+ export declare function apply(m: Mat, p: P): P;
27
+ export declare function key(a: Atom): number;
28
+ export declare function centreOf(a: Atom): P;
29
+ /** mapAtom takes an atom where a map of the squares takes it. */
30
+ export declare function mapAtom(a: Atom, m: Mat): Atom;
31
+ export declare function sortAtoms(atoms: Atom[]): Atom[];
32
+ export declare function atomsOf(r: number, c: number, part: Part): Atom[];
33
+ /** sheetAtoms are every atom of a sheet of rows by cols squares. */
34
+ export declare function sheetAtoms(rows: number, cols: number): Atom[];
35
+ export type Box = {
36
+ x0: number;
37
+ y0: number;
38
+ x1: number;
39
+ y1: number;
40
+ };
41
+ /** boxOf is the box round some atoms, in squares. */
42
+ export declare function boxOf(atoms: readonly Atom[]): Box;
43
+ /**
44
+ * loopsOf chains the outer sides of some atoms into closed loops, in squares,
45
+ * dropping the corners that lie on a straight side; filled with the even-odd
46
+ * rule they draw the atoms, holes and all.
47
+ */
48
+ export declare function loopsOf(atoms: readonly Atom[]): P[][];
49
+ /**
50
+ * innerLines lists the sides between two of the atoms that pass a test, joined
51
+ * into the longest straight lines, in squares: the lines of the squares on a
52
+ * sheet, or the crease of a fold.
53
+ */
54
+ export declare function innerLines(atoms: readonly Atom[], keep: (a: P, b: P) => boolean): [P, P][];
55
+ /** pieceCount counts the pieces some atoms fall into, atoms joined side to side. */
56
+ export declare function pieceCount(atoms: readonly Atom[]): number;
57
+ /**
58
+ * cellWords says which part of a square some of its quarters make: "the
59
+ * square", "the top-left half", "the top quarter", "the top and left quarters".
60
+ */
61
+ export declare function cellWords(qs: readonly number[]): string;
62
+ /** partWords says a part of a square at its place: "the top-left half of the square at row 1, column 2". */
63
+ export declare function partWords(part: Part, r: number, c: number): string;
64
+ /** The four ways a mark can point, clockwise from up, as vectors on the screen. */
65
+ export declare const ways: readonly ["up", "right", "down", "left"];
66
+ /** turnOf is the quarter turn, clockwise in degrees, that takes the way `from` to where a map sends it. */
67
+ export declare function turnOf(m: Mat, from: number): number;
68
+ /** turnMat is the turn clockwise by a multiple of 90 degrees, about the origin. */
69
+ export declare function turnMat(turn: number): Mat;
70
+ /** linear is a map without its shift; transposed, an orthogonal one is undone. */
71
+ export declare function transposed(m: Mat): Mat;
72
+ /** article puts "a" or "an" before words. */
73
+ export declare function article(words: string): string;
@@ -0,0 +1,315 @@
1
+ /**
2
+ * The atoms of a sheet of squares: each square cut by its two diagonals into
3
+ * four quarters, the triangles between its sides and its centre. A fold along
4
+ * a line of the squares or along their diagonals, a quarter turn and a flip
5
+ * all take quarters onto quarters, so whatever is folded, punched, cut,
6
+ * turned or laid together stays exact, quarter by quarter.
7
+ */
8
+ export const quarters = ["top", "right", "bottom", "left"];
9
+ /** The parts of a square: whole, the half at a corner, or a quarter. */
10
+ export const parts = ["whole", "nw", "ne", "se", "sw", "top", "right", "bottom", "left"];
11
+ export const partQuarters = {
12
+ whole: [0, 1, 2, 3],
13
+ nw: [0, 3],
14
+ ne: [0, 1],
15
+ se: [1, 2],
16
+ sw: [2, 3],
17
+ top: [0],
18
+ right: [1],
19
+ bottom: [2],
20
+ left: [3],
21
+ };
22
+ const halfWords = {
23
+ nw: "top-left",
24
+ ne: "top-right",
25
+ se: "bottom-right",
26
+ sw: "bottom-left",
27
+ };
28
+ export const identity = [1, 0, 0, 1, 0, 0];
29
+ /** andThen is the map that does m first and k after it. */
30
+ export function andThen(m, k) {
31
+ return [
32
+ k[0] * m[0] + k[2] * m[1],
33
+ k[1] * m[0] + k[3] * m[1],
34
+ k[0] * m[2] + k[2] * m[3],
35
+ k[1] * m[2] + k[3] * m[3],
36
+ k[0] * m[4] + k[2] * m[5] + k[4],
37
+ k[1] * m[4] + k[3] * m[5] + k[5],
38
+ ];
39
+ }
40
+ export function apply(m, p) {
41
+ return { x: m[0] * p.x + m[2] * p.y + m[4], y: m[1] * p.x + m[3] * p.y + m[5] };
42
+ }
43
+ /** The corners of each quarter, in doubled units: square corners even, the centre odd. */
44
+ const corners = [
45
+ [
46
+ [0, 0],
47
+ [2, 0],
48
+ [1, 1],
49
+ ],
50
+ [
51
+ [2, 0],
52
+ [2, 2],
53
+ [1, 1],
54
+ ],
55
+ [
56
+ [2, 2],
57
+ [0, 2],
58
+ [1, 1],
59
+ ],
60
+ [
61
+ [0, 2],
62
+ [0, 0],
63
+ [1, 1],
64
+ ],
65
+ ];
66
+ const centres = [
67
+ { x: 0.5, y: 1 / 6 },
68
+ { x: 5 / 6, y: 0.5 },
69
+ { x: 0.5, y: 5 / 6 },
70
+ { x: 1 / 6, y: 0.5 },
71
+ ];
72
+ export function key(a) {
73
+ return (a.r * 64 + a.c) * 4 + a.q;
74
+ }
75
+ export function centreOf(a) {
76
+ const local = centres[a.q];
77
+ return { x: a.c + local.x, y: a.r + local.y };
78
+ }
79
+ /** atomAt finds the atom whose centre is at p. */
80
+ function atomAt(p) {
81
+ const r = Math.floor(p.y);
82
+ const c = Math.floor(p.x);
83
+ const dx = p.x - c - 0.5;
84
+ const dy = p.y - r - 0.5;
85
+ const q = Math.abs(dy) > Math.abs(dx) ? (dy < 0 ? 0 : 2) : dx > 0 ? 1 : 3;
86
+ return { r, c, q };
87
+ }
88
+ /** mapAtom takes an atom where a map of the squares takes it. */
89
+ export function mapAtom(a, m) {
90
+ return atomAt(apply(m, centreOf(a)));
91
+ }
92
+ export function sortAtoms(atoms) {
93
+ return atoms.sort((a, b) => key(a) - key(b));
94
+ }
95
+ export function atomsOf(r, c, part) {
96
+ return partQuarters[part].map((q) => ({ r, c, q }));
97
+ }
98
+ /** sheetAtoms are every atom of a sheet of rows by cols squares. */
99
+ export function sheetAtoms(rows, cols) {
100
+ const out = [];
101
+ for (let r = 0; r < rows; r++)
102
+ for (let c = 0; c < cols; c++)
103
+ for (let q = 0; q < 4; q++)
104
+ out.push({ r, c, q });
105
+ return out;
106
+ }
107
+ /** boxOf is the box round some atoms, in squares. */
108
+ export function boxOf(atoms) {
109
+ const box = { x0: Infinity, y0: Infinity, x1: -Infinity, y1: -Infinity };
110
+ for (const a of atoms)
111
+ for (const [x, y] of corners[a.q]) {
112
+ box.x0 = Math.min(box.x0, a.c + x / 2);
113
+ box.x1 = Math.max(box.x1, a.c + x / 2);
114
+ box.y0 = Math.min(box.y0, a.r + y / 2);
115
+ box.y1 = Math.max(box.y1, a.r + y / 2);
116
+ }
117
+ return box;
118
+ }
119
+ /** edgesOf lists each side of the atoms once, with how many of the atoms it bounds. */
120
+ function edgesOf(atoms) {
121
+ const out = new Map();
122
+ for (const at of atoms) {
123
+ const v = corners[at.q].map(([x, y]) => [2 * at.c + x, 2 * at.r + y]);
124
+ for (let i = 0; i < 3; i++) {
125
+ const a = v[i];
126
+ const b = v[(i + 1) % 3];
127
+ const name = a[0] < b[0] || (a[0] === b[0] && a[1] < b[1]) ? `${a},${b}` : `${b},${a}`;
128
+ const seen = out.get(name);
129
+ if (seen)
130
+ seen.count++;
131
+ else
132
+ out.set(name, { a, b, count: 1 });
133
+ }
134
+ }
135
+ return [...out.values()];
136
+ }
137
+ /**
138
+ * loopsOf chains the outer sides of some atoms into closed loops, in squares,
139
+ * dropping the corners that lie on a straight side; filled with the even-odd
140
+ * rule they draw the atoms, holes and all.
141
+ */
142
+ export function loopsOf(atoms) {
143
+ const edges = edgesOf(atoms).filter((e) => e.count === 1);
144
+ const at = new Map();
145
+ edges.forEach((e, i) => {
146
+ for (const p of [e.a, e.b]) {
147
+ const name = `${p}`;
148
+ const list = at.get(name);
149
+ if (list)
150
+ list.push(i);
151
+ else
152
+ at.set(name, [i]);
153
+ }
154
+ });
155
+ const used = new Set();
156
+ const loops = [];
157
+ for (let first = 0; first < edges.length; first++) {
158
+ if (used.has(first))
159
+ continue;
160
+ used.add(first);
161
+ const start = edges[first].a;
162
+ const points = [start, edges[first].b];
163
+ for (;;) {
164
+ const end = points[points.length - 1];
165
+ if (end[0] === start[0] && end[1] === start[1])
166
+ break;
167
+ const next = at.get(`${end}`).find((i) => !used.has(i));
168
+ if (next === undefined)
169
+ break;
170
+ used.add(next);
171
+ const e = edges[next];
172
+ points.push(e.a[0] === end[0] && e.a[1] === end[1] ? e.b : e.a);
173
+ }
174
+ points.pop();
175
+ const kept = points.filter((p, i) => {
176
+ const a = points[(i + points.length - 1) % points.length];
177
+ const b = points[(i + 1) % points.length];
178
+ return (p[0] - a[0]) * (b[1] - p[1]) - (p[1] - a[1]) * (b[0] - p[0]) !== 0;
179
+ });
180
+ loops.push(kept.map(([x, y]) => ({ x: x / 2, y: y / 2 })));
181
+ }
182
+ return loops;
183
+ }
184
+ /**
185
+ * innerLines lists the sides between two of the atoms that pass a test, joined
186
+ * into the longest straight lines, in squares: the lines of the squares on a
187
+ * sheet, or the crease of a fold.
188
+ */
189
+ export function innerLines(atoms, keep) {
190
+ const pieces = edgesOf(atoms)
191
+ .filter((e) => e.count === 2)
192
+ .map((e) => [
193
+ { x: e.a[0] / 2, y: e.a[1] / 2 },
194
+ { x: e.b[0] / 2, y: e.b[1] / 2 },
195
+ ])
196
+ .filter(([a, b]) => keep(a, b));
197
+ // Group the pieces by the line they lie on, then join those that meet.
198
+ const lines = new Map();
199
+ for (const [a, b] of pieces) {
200
+ const dx = Math.sign(b.x - a.x);
201
+ const dy = Math.sign(b.y - a.y);
202
+ const [u, v] = dx < 0 || (dx === 0 && dy < 0) ? [b, a] : [a, b];
203
+ const d = { x: Math.sign(v.x - u.x), y: Math.sign(v.y - u.y) };
204
+ const name = `${d.x},${d.y},${d.y * u.x - d.x * u.y}`;
205
+ const list = lines.get(name);
206
+ if (list)
207
+ list.push([u, v]);
208
+ else
209
+ lines.set(name, [[u, v]]);
210
+ }
211
+ const out = [];
212
+ for (const list of lines.values()) {
213
+ list.sort((p, q) => p[0].x - q[0].x || p[0].y - q[0].y);
214
+ let cur = list[0];
215
+ for (const seg of list.slice(1)) {
216
+ if (seg[0].x === cur[1].x && seg[0].y === cur[1].y)
217
+ cur = [cur[0], seg[1]];
218
+ else {
219
+ out.push(cur);
220
+ cur = seg;
221
+ }
222
+ }
223
+ out.push(cur);
224
+ }
225
+ return out;
226
+ }
227
+ /** pieceCount counts the pieces some atoms fall into, atoms joined side to side. */
228
+ export function pieceCount(atoms) {
229
+ const index = new Map(atoms.map((a, i) => [key(a), i]));
230
+ const seen = new Set();
231
+ let pieces = 0;
232
+ const neighbours = (a) => {
233
+ const inCell = [(a.q + 1) % 4, (a.q + 3) % 4].map((q) => ({ r: a.r, c: a.c, q }));
234
+ const across = [
235
+ { r: a.r - 1, c: a.c, q: 2 },
236
+ { r: a.r, c: a.c + 1, q: 3 },
237
+ { r: a.r + 1, c: a.c, q: 0 },
238
+ { r: a.r, c: a.c - 1, q: 1 },
239
+ ][a.q];
240
+ return [...inCell, across];
241
+ };
242
+ atoms.forEach((first, i) => {
243
+ if (seen.has(i))
244
+ return;
245
+ pieces++;
246
+ seen.add(i);
247
+ const todo = [first];
248
+ while (todo.length > 0) {
249
+ const a = todo.pop();
250
+ for (const b of neighbours(a)) {
251
+ if (b.r < 0 || b.c < 0)
252
+ continue;
253
+ const j = index.get(key(b));
254
+ if (j !== undefined && !seen.has(j)) {
255
+ seen.add(j);
256
+ todo.push(b);
257
+ }
258
+ }
259
+ }
260
+ });
261
+ return pieces;
262
+ }
263
+ /**
264
+ * cellWords says which part of a square some of its quarters make: "the
265
+ * square", "the top-left half", "the top quarter", "the top and left quarters".
266
+ */
267
+ export function cellWords(qs) {
268
+ const set = [...new Set(qs)].sort((a, b) => a - b);
269
+ if (set.length === 4)
270
+ return "the whole square";
271
+ if (set.length === 2) {
272
+ const half = Object.keys(halfWords).find((p) => partQuarters[p].length === 2 && partQuarters[p].every((q) => set.includes(q)));
273
+ if (half)
274
+ return `the ${halfWords[half]} half`;
275
+ }
276
+ const names = set.map((q) => quarters[q]);
277
+ if (names.length === 1)
278
+ return `the ${names[0]} quarter`;
279
+ return `the ${names.slice(0, -1).join(", ")} and ${names[names.length - 1]} quarters`;
280
+ }
281
+ /** partWords says a part of a square at its place: "the top-left half of the square at row 1, column 2". */
282
+ export function partWords(part, r, c) {
283
+ const where = `the square at row ${r}, column ${c}`;
284
+ if (part === "whole")
285
+ return where;
286
+ return `${cellWords(partQuarters[part])} of ${where}`;
287
+ }
288
+ /** The four ways a mark can point, clockwise from up, as vectors on the screen. */
289
+ export const ways = ["up", "right", "down", "left"];
290
+ const wayVectors = [
291
+ { x: 0, y: -1 },
292
+ { x: 1, y: 0 },
293
+ { x: 0, y: 1 },
294
+ { x: -1, y: 0 },
295
+ ];
296
+ /** turnOf is the quarter turn, clockwise in degrees, that takes the way `from` to where a map sends it. */
297
+ export function turnOf(m, from) {
298
+ const v = wayVectors[from];
299
+ const w = { x: m[0] * v.x + m[2] * v.y, y: m[1] * v.x + m[3] * v.y };
300
+ const to = wayVectors.findIndex((u) => u.x === w.x && u.y === w.y);
301
+ return ((((to - from) % 4) + 4) % 4) * 90;
302
+ }
303
+ /** turnMat is the turn clockwise by a multiple of 90 degrees, about the origin. */
304
+ export function turnMat(turn) {
305
+ const k = (((turn / 90) % 4) + 4) % 4;
306
+ return [identity, [0, 1, -1, 0, 0, 0], [-1, 0, 0, -1, 0, 0], [0, -1, 1, 0, 0, 0]][k];
307
+ }
308
+ /** linear is a map without its shift; transposed, an orthogonal one is undone. */
309
+ export function transposed(m) {
310
+ return [m[0], m[2], m[1], m[3], 0, 0];
311
+ }
312
+ /** article puts "a" or "an" before words. */
313
+ export function article(words) {
314
+ return `${/^[aeiou]/.test(words) ? "an" : "a"} ${words}`;
315
+ }
@@ -0,0 +1,52 @@
1
+ import type { Kind } from "../kind.ts";
2
+ import { type ColorName } from "../style.ts";
3
+ import { type Part } from "./fold-parts.ts";
4
+ /**
5
+ * Fold: a sheet of paper, a rectangle of squares, folded in half one to three
6
+ * times, then punched with holes or cut, drawn as steps in a row: the sheet
7
+ * with the dashed line of its first fold and a curved arrow from the half that
8
+ * moves to the half it lies on, the folded sheet with its next fold, and so on
9
+ * to the folded sheet with its holes and its cuts, the parts cut off dashed.
10
+ * After an arrow the picture may end with the sheet unfolded again, or with a
11
+ * "?" in its place; or it may show the unfolded sheet alone, as an option of a
12
+ * choice. The program unfolds the sheet itself, quarter of a square by
13
+ * quarter, so the unfolded sheet is exactly what the folds, holes and cuts
14
+ * make, every hole turned or mirrored as the folds turn it.
15
+ *
16
+ * A fold is named by the half that moves and the half it lies on — "left
17
+ * onto right", "top-right onto bottom-left" — and folds the sheet as folded so
18
+ * far along its middle line of that direction. A place on the folded sheet is
19
+ * [row, column], counted from 1 at the top left of the folded sheet. A hole is
20
+ * punched in the middle of a whole square of it; a cut takes off a square or a
21
+ * part of one: "nw", "ne", "se", "sw", the half at that corner of a square cut
22
+ * along a diagonal, or "top", "right", "bottom", "left", the quarter between
23
+ * that side and the centre.
24
+ */
25
+ export declare const foldNames: readonly ["left onto right", "right onto left", "top onto bottom", "bottom onto top", "top-right onto bottom-left", "bottom-left onto top-right", "top-left onto bottom-right", "bottom-right onto top-left"];
26
+ export type FoldName = (typeof foldNames)[number];
27
+ export declare const holeShapes: readonly ["circle", "square", "triangle", "diamond", "star", "heart", "moon", "cross"];
28
+ export type HoleShape = (typeof holeShapes)[number];
29
+ export declare const shows: readonly ["steps", "result", "ask", "unfolded"];
30
+ export type Show = (typeof shows)[number];
31
+ export declare const holeTurns: readonly [0, 90, 180, 270];
32
+ export type Hole = {
33
+ at: [number, number];
34
+ shape: HoleShape;
35
+ turn?: number;
36
+ };
37
+ export type Cut = [number, number] | [number, number, Part];
38
+ export type Sheet = {
39
+ rows: number;
40
+ cols: number;
41
+ color?: ColorName;
42
+ grid?: boolean;
43
+ };
44
+ export type FoldScene = {
45
+ kind: "fold";
46
+ sheet: Sheet;
47
+ folds?: FoldName[];
48
+ holes?: Hole[];
49
+ cuts?: Cut[];
50
+ show?: Show;
51
+ };
52
+ export declare const fold: Kind;