@logomarks/typemarks 0.1.0 → 0.2.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # Changelog
2
2
 
3
+
4
+ ## 0.2.1 (2026-11-27)
5
+
6
+ - No monogram join or link in a script face (tagged `script`): its capitals are joined strokes already, and JO in
7
+ Caveat joined into a p.
8
+
9
+ ## 0.2.0 (2026-11-27)
10
+
11
+ - **Short names** (`src/edits/short.js`, `isShort`, `SHORT_EDITS`): nine moves for names of one to three letters, which
12
+ a quiet edit can't carry (a page for JO was 27 filled counters, one for X 27 full stops): `monoJoin` (two capitals
13
+ sharing a stroke), `inset` (one letter inside the other's counter or open side), `stack` (two capitals one above the
14
+ other, or three with the first big), `knock` and `frame` (a single letter cut out of, or framed by, a square, rounded
15
+ square or disc), `link` (two capitals passing over and under), `split` (a single letter cut through and slid),
16
+ `echo` (a solid block shadow, capitals in a heavy face only: stroke a fifth of the cap height or more) and `lines` (two or three level gaps). A stack takes
17
+ letters of like widths (within 1.25 to 1) that make a lockup near square; stacks and shadows rank below the rest, and a
18
+ page holds at most two stacks and three shadows. Each keeps its banned reads out by letter
19
+ (`docs/edits.md`). They find nothing for a longer name: the pages for LUCIA, TRAVIS and NORTHWIND COFFEE are
20
+ byte-identical to 0.1.0's.
21
+ - `suggest()`: on a short name no move takes more than eight of a page of forty (moves on a page of 40 in the test
22
+ fonts, before → after: JO 4 → 8, OX 3 → 5, X 2 → 5, Q 2 → 7, AI 6 → 8, KAI 8 → 9; the most of one move, before →
23
+ after: JO 27 → 8, OX 28 → 8, X 27 → 8, Q 24 → 8; a single X or OX fills 35 of 40, every move at its cap), and a short name's lowercase q, b or d is never given a filled
24
+ counter.
25
+ - `ops.bolder` and `ops.counterOf` are exported.
26
+
3
27
  ## 0.1.0 (2026-11-26)
4
28
 
5
29
  - `suggest()` sets like a designer: one case through the word (capitals or lowercase, never as typed unless `lock.case`
package/README.md CHANGED
@@ -13,6 +13,10 @@ through its spine… Each is made of general operations (stretch, shorten, detac
13
13
  tuck letters under a bar) on the strokes measured from the outline: bars with free or held ends, stems, slanted legs,
14
14
  forks.
15
15
 
16
+ A name of one to three letters gets monogram moves instead: two capitals set into each other or linked, one letter
17
+ inside the other's counter, stacked, a single letter knocked out of a square or disc or framed by one, split, echoed by
18
+ a block shadow, or cut by lines (`docs/edits.md`, "Short names").
19
+
16
20
  ## Install
17
21
 
18
22
  ```sh
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logomarks/typemarks",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
4
  "description": "Wordmarks from any font, no AI: a name set in a font and cut by design rules (a crossbar dropped, a shared stroke, a stencil break, one slice across the word, a bar extended, a letter swapped…), each edit found from the font's own outlines, ranked into a page of diverse results. Runs in the browser and in Node; reads TTF, OTF and WOFF (TrueType or CFF outlines) with opentype.js.",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -14,9 +14,11 @@ import counter from './counter.js';
14
14
  import round from './round.js';
15
15
  import accent from './accent.js';
16
16
  import { PIXEL_EDITS } from './pixel.js';
17
+ import { SHORT_EDITS } from './short.js';
17
18
  import { RULES } from './rules.js';
18
19
 
19
- export const EDITS = Object.fromEntries([drop, cut, stencil, slice, ligature, overlap, bar, underline, swap, counter, round, accent, ...PIXEL_EDITS, ...RULES].map((e) => [e.id, e]));
20
+ export const EDITS = Object.fromEntries([drop, cut, stencil, slice, ligature, overlap, bar, underline, swap, counter, round, accent, ...PIXEL_EDITS, ...SHORT_EDITS, ...RULES].map((e) => [e.id, e]));
20
21
 
21
22
  export { RULES, fits } from './rules.js';
22
23
  export { pixelOf } from './pixel.js';
24
+ export { isShort, SHORT_EDITS } from './short.js';
@@ -0,0 +1,447 @@
1
+ /**
2
+ * Moves for short names: one to three letters (JO, OX, AI, KAI, a single Q). A long name has room for a quiet edit to
3
+ * carry it; a short one has too few letters for that, so these treat the letters as a monogram: two set into each other
4
+ * until they share a stroke, one set inside the other's counter or open side, stacked one above the other, linked with
5
+ * an over and under, echoed by a shadow, cut by lines, a single letter split or knocked out of a solid shape. Each finds
6
+ * nothing for a name of four letters or more, so a long name's page is as it was.
7
+ *
8
+ * Banned reads are kept out by letter: two holed letters side by side (a face, glasses), a round letter inside a round
9
+ * one (a target), an X or a stem inside a ring (a cancel or power sign), straight letters crossed (a cross), and the
10
+ * letters that read as a sign or a known logo in a frame (® © ⓘ ⓧ, H for a hospital or a helipad, P for parking, f, t,
11
+ * N, M, Y, W, K and U as app icons and certification marks, A in a ring).
12
+ */
13
+ import { U, D, I, mapPts, rect, rr, circle, poly } from '@logomarks/core/geometry';
14
+ import { grown } from '@logomarks/core/geometry';
15
+ import { moved, ink } from '../geo.js';
16
+ import { boxOf, featuresOf, runsAt } from '../features.js';
17
+ import { fill } from '../raster.js';
18
+ import { CAP, shiftFrom, strokeOf } from '../word.js';
19
+ import { roomBetween, bolder, counterOf } from '../ops.js';
20
+
21
+ /** The letters with ink. */
22
+ const inked = (word) => word.letters.filter((l) => l.shape.length);
23
+ /** A name of one to three letters, one word. */
24
+ export const isShort = (word) => { const n = inked(word).length; return n >= 1 && n <= 3 && !word.letters.some((l) => /\s/.test(l.char)); };
25
+ /** A script face (tagged `script`): its capitals are joined strokes already, so a join or link turns JO into a p. */
26
+ const script = (word) => !!word.font?.tags?.includes('script');
27
+ const stemOf = (word) => word.stem || strokeOf(word);
28
+
29
+ const STRAIGHT = 'IiLlTtJj1|';
30
+ /** Two letters whose crossing reads as a cross (IT, TL, XI …). */
31
+ const crossy = (a, b) => (STRAIGHT.includes(a) && STRAIGHT.includes(b)) || ('Xx+'.includes(a) && STRAIGHT.includes(b)) || ('Xx+'.includes(b) && STRAIGHT.includes(a));
32
+ const holed = (l) => (l.f?.holes?.length ?? 0) > 0;
33
+ /** A letter more than its stem (an I or an l set into another vanishes). */
34
+ const wide = (l) => l.f && l.f.w > l.f.stem * 1.8;
35
+ /**
36
+ * A pair that can be set into each other: capitals (a lowercase stem set into a bowl makes another letter: j and o
37
+ * become a p), neither narrow (condensed letters overlapped are a smudge), never a cross, never two holes side by side.
38
+ */
39
+ const capital = (c) => c !== c.toLowerCase() && c === c.toUpperCase();
40
+ const ROUND = 'OQ0CGD';
41
+ /** A round letter set into an X is a fish (and an alpha). */
42
+ const fishy = (a, b) => (a === 'X' && ROUND.includes(b)) || (b === 'X' && ROUND.includes(a));
43
+ const pairable = (a, b) => wide(a) && wide(b) && capital(a.char) && capital(b.char) && Math.min(a.f.w, b.f.w) > CAP * 0.6 && !crossy(a.char, b.char) && !fishy(a.char, b.char) && !(holed(a) && holed(b));
44
+
45
+ /** Consecutive pairs of inked letters, as letter indices. */
46
+ function pairsOf(word) {
47
+ const idx = word.letters.map((l, i) => (l.shape.length ? i : -1)).filter((i) => i >= 0), out = [];
48
+ for (let k = 1; k < idx.length; k++) out.push([idx[k - 1], idx[k]]);
49
+ return out;
50
+ }
51
+
52
+ /** A shape scaled by s from its box's top-left corner to (x0, y0). */
53
+ const placedAt = (shape, s, x0, y0) => { const b = boxOf(shape); return mapPts(shape, ([x, y]) => [x0 + (x - b[0]) * s, y0 + (y - b[1]) * s]); };
54
+ /** The weight a letter set at s loses, given back (no more than a fifth of a counter at its size). */
55
+ const thickenFor = (word, s) => { const stem = stemOf(word); return Math.min((stem * (1 - s)) / 2 * 0.85, 0.2 * counterOf(word, stem) * s); };
56
+ /** A letter's shape set at scale s, its top-left at (x0, y0), made a touch bolder for the size it lost. */
57
+ function smaller(word, l, s, x0, y0) {
58
+ let shape = placedAt(l.shape, s, x0, y0);
59
+ const t = s < 1 ? thickenFor(word, s) : 0;
60
+ if (t > stemOf(word) * 0.04) shape = bolder(shape, t);
61
+ return shape;
62
+ }
63
+ /** Puts a letter's new shape in, moving its x with it and measuring it again. */
64
+ function setShape(l, shape, flag = 'tucked') {
65
+ const dx = boxOf(shape)[0] - boxOf(l.shape)[0];
66
+ l.shape = shape; l.x += dx; l.f = featuresOf(shape, l.char);
67
+ l.edited = true; l[flag] = true;
68
+ }
69
+
70
+ /* ---------- Monogram: two letters set into each other until they share a stroke ---------- */
71
+
72
+ const joinable = (word, [i, j]) => pairable(word.letters[i], word.letters[j]);
73
+
74
+ export const monoJoin = {
75
+ id: 'monoJoin', name: 'Monogram', line: 'Two letters set into each other until they share a stroke.',
76
+ controls: [
77
+ { key: 'share', label: 'Share', type: 'choice', options: ['stroke', 'more'], value: 'stroke' },
78
+ { key: 'pair', label: 'Pair', type: 'choice', options: ['first', 'last'], value: 'first' },
79
+ ],
80
+ find: (word) => (isShort(word) && !script(word) ? pairsOf(word).filter((pr) => joinable(word, pr)).map(([i]) => i) : []),
81
+ apply(word, p) {
82
+ const prs = pairsOf(word).filter((pr) => joinable(word, pr));
83
+ if (!prs.length) return false;
84
+ const [i, j] = p.pair === 'last' ? prs.at(-1) : prs[0], a = word.letters[i], b = word.letters[j], stem = stemOf(word);
85
+ // closed until the nearest ink of the two overlaps by one stroke (or a stroke and a half): the stroke they share
86
+ const shift = roomBetween(a.shape, b.shape, 0) + stem * (p.share === 'more' ? 1.5 : 1);
87
+ shiftFrom(word, j, -shift);
88
+ b.shape = U(a.shape, b.shape);
89
+ a.shape = [];
90
+ b.edited = true; b.joined = true;
91
+ word.fused = true;
92
+ return true;
93
+ },
94
+ };
95
+
96
+ /* ---------- Inset: one letter set inside the other's counter or open side ---------- */
97
+
98
+ const ROUNDISH = 'OQ0CGDUocgdeaqbpu';
99
+ /** An inner letter that reads as a sign inside this outer one: a ring in a ring (a target), an X or a stem in a ring. */
100
+ function insetBanned(outer, inner) {
101
+ const o = outer.char, n = inner.char;
102
+ if ('OQ0o'.includes(n) && (holed(outer) || ROUNDISH.includes(o))) return true;
103
+ if ('Xx+'.includes(n) && ROUNDISH.includes(o)) return true;
104
+ if ('Ii1l|'.includes(n) && 'OQ0oC'.includes(o)) return true;
105
+ return false;
106
+ }
107
+
108
+ /**
109
+ * Where `inner` fits inside `outer`'s box, clear of its ink by `gap`: the biggest scale (down to `min`) at which a box of
110
+ * inner's shape fits in the white of outer's box, placed nearest the middle of all the places it fits. From a bitmap of
111
+ * outer, its ink grown by the gap, and a summed-area table, so each try is a lookup. The inner letter keeps the reading
112
+ * order: the second letter sits in the right half or the middle, the first in the left half or the middle.
113
+ */
114
+ function fitInside(outer, inner, gap, min, side = 0) {
115
+ const ob = boxOf(outer), ib = boxOf(inner), ow = ob[2] - ob[0], oh = ob[3] - ob[1], iw = ib[2] - ib[0], ih = ib[3] - ib[1];
116
+ const R = 120, u = Math.max(ow, oh) / R, W = Math.ceil(ow / u), H = Math.ceil(oh / u);
117
+ const bits = fill(outer, [ob[0], ob[1], ob[0] + W * u, ob[1] + H * u], W, H);
118
+ // the ink grown by the gap, cell by cell (a square reach: a little more than the gap on the diagonal)
119
+ const g = Math.ceil(gap / u), grownBits = new Uint8Array(W * H);
120
+ for (let r = 0; r < H; r++) for (let c = 0; c < W; c++) {
121
+ if (!bits[r * W + c]) continue;
122
+ for (let rr2 = Math.max(0, r - g); rr2 <= Math.min(H - 1, r + g); rr2++) for (let cc = Math.max(0, c - g); cc <= Math.min(W - 1, c + g); cc++) grownBits[rr2 * W + cc] = 1;
123
+ }
124
+ const S = new Int32Array((W + 1) * (H + 1));
125
+ for (let r = 0; r < H; r++) for (let c = 0; c < W; c++) S[(r + 1) * (W + 1) + c + 1] = grownBits[r * W + c] + S[r * (W + 1) + c + 1] + S[(r + 1) * (W + 1) + c] - S[r * (W + 1) + c];
126
+ const sum = (r0, c0, r1, c1) => S[r1 * (W + 1) + c1] - S[r0 * (W + 1) + c1] - S[r1 * (W + 1) + c0] + S[r0 * (W + 1) + c0];
127
+ for (let s = 0.8; s >= min; s -= 0.02) {
128
+ const w = Math.ceil((iw * s) / u), h = Math.ceil((ih * s) / u);
129
+ if (w >= W || h >= H) continue;
130
+ const spots = [];
131
+ // side: the inner letter's middle right of the outer's (it is the second letter) or left of it (the first)
132
+ for (let r = 0; r + h <= H; r++) for (let c = 0; c + w <= W; c++) if (!sum(r, c, r + h, c + w) && (side * (c + w / 2 - W / 2) >= -W * 0.04)) spots.push([r, c]);
133
+ if (!spots.length) continue;
134
+ // held: the outer letter's ink on three sides of the spot of four (a counter on all four, a C's mouth on three); a
135
+ // spot in a corner of the box, beside an A's apex or a J's hook, is outside the letter, not in it
136
+ const ink1 = (r, c) => bits[r * W + c] === 1;
137
+ const held = ([r, c]) => {
138
+ const rm = Math.min(H - 1, r + (h >> 1)), cm = Math.min(W - 1, c + (w >> 1));
139
+ let n = 0;
140
+ for (let k = c - 1; k >= 0; k--) if (ink1(rm, k)) { n++; break; }
141
+ for (let k = c + w; k < W; k++) if (ink1(rm, k)) { n++; break; }
142
+ for (let k = r - 1; k >= 0; k--) if (ink1(k, cm)) { n++; break; }
143
+ for (let k = r + h; k < H; k++) if (ink1(k, cm)) { n++; break; }
144
+ return n >= 3;
145
+ };
146
+ for (let k = spots.length - 1; k >= 0; k--) if (!held(spots[k])) spots.splice(k, 1);
147
+ if (!spots.length) continue;
148
+ const mr = spots.reduce((t, [r]) => t + r, 0) / spots.length, mc = spots.reduce((t, [, c]) => t + c, 0) / spots.length;
149
+ const [r, c] = spots.reduce((best, sp) => (Math.hypot(sp[0] - mr, sp[1] - mc) < Math.hypot(best[0] - mr, best[1] - mc) ? sp : best));
150
+ return { s, x0: ob[0] + c * u + (w * u - iw * s) / 2, y0: ob[1] + r * u + (h * u - ih * s) / 2 };
151
+ }
152
+ return null;
153
+ }
154
+
155
+ export const inset = {
156
+ id: 'inset', name: 'Inset', line: 'One letter set inside the other’s counter or open side.',
157
+ controls: [{ key: 'order', label: 'Inside', type: 'choice', options: ['auto', 'second', 'first'], value: 'auto' }],
158
+ find(word) {
159
+ if (!isShort(word) || inked(word).length !== 2) return [];
160
+ const [a, b] = inked(word);
161
+ return insetBanned(a, b) && insetBanned(b, a) ? [] : [0];
162
+ },
163
+ apply(word, p) {
164
+ const [a, b] = inked(word), gap = stemOf(word) * 0.75;
165
+ // 'second': the second letter goes inside the first; 'first': the first inside the second
166
+ const tries = p.order === 'second' ? [[a, b]] : p.order === 'first' ? [[b, a]] : [[a, b], [b, a]];
167
+ let best = null;
168
+ for (const [outer, inner] of tries) {
169
+ if (insetBanned(outer, inner)) continue;
170
+ const at = fitInside(outer.shape, inner.shape, gap, 0.34, inner === b ? 1 : -1);
171
+ if (at && (!best || at.s > best.at.s)) best = { outer, inner, at };
172
+ }
173
+ if (!best) return false;
174
+ const { outer, inner, at } = best;
175
+ let shape = smaller(word, inner, at.s, at.x0, at.y0);
176
+ // grown a touch for its weight: still clear of the outer letter, or back to its plain size
177
+ if (I(shape, outer.shape).length) shape = placedAt(inner.shape, at.s, at.x0, at.y0);
178
+ if (I(shape, outer.shape).length) return false;
179
+ setShape(inner, shape);
180
+ return true;
181
+ },
182
+ };
183
+
184
+ /* ---------- Stack: the letters one above the other ---------- */
185
+
186
+ export const stack = {
187
+ id: 'stack', name: 'Stacked', line: 'Two capitals one above the other, or three with the first big and two stacked beside it.',
188
+ controls: [
189
+ { key: 'mode', label: 'Stack', type: 'choice', options: ['rows', 'lead'], value: 'rows' },
190
+ { key: 'align', label: 'Align', type: 'choice', options: ['centre', 'left'], value: 'centre' },
191
+ ],
192
+ // capitals: lowercase letters stacked sit at three heights and read as a list
193
+ // …and each wider than its stem: an A over an I is an arrow, an I over an O a pin
194
+ // …and no round letter on top: a ring over a letter is a head over a body
195
+ find: (word) => (isShort(word) && inked(word).length >= 2 && inked(word).every((l) => capital(l.char) && wide(l)) && !'OQ0'.includes(inked(word)[0].char) ? [0] : []),
196
+ apply(word, p) {
197
+ const ls = inked(word), stem = stemOf(word), gap = Math.max(stem * 0.8, CAP * 0.07);
198
+ if (p.mode === 'rows' && ls.length !== 2) return false; // three rows are a tall thin column
199
+ // letters of like widths only, and a lockup near square (a J balanced on an O reads as a figure or a key)
200
+ const like = (x, y) => { const wx = boxOf(x.shape)[2] - boxOf(x.shape)[0], wy = boxOf(y.shape)[2] - boxOf(y.shape)[0]; return Math.max(wx, wy) / Math.min(wx, wy) <= 1.25; };
201
+ if (p.mode === 'rows') {
202
+ const [A, B] = ls, ba = boxOf(A.shape), bb = boxOf(B.shape);
203
+ const w = Math.max(ba[2] - ba[0], bb[2] - bb[0]), h = ba[3] - ba[1] + bb[3] - bb[1] + gap;
204
+ if (!like(A, B) || w / h < 0.6) return false;
205
+ } else if (ls.length === 3 && !like(ls[1], ls[2])) return false;
206
+ if (p.mode === 'lead') {
207
+ if (ls.length !== 3) return false;
208
+ const [A, B, C] = ls, ba = boxOf(A.shape), bb = boxOf(B.shape), bc = boxOf(C.shape);
209
+ const s = (ba[3] - ba[1] - gap) / (bb[3] - bb[1] + bc[3] - bc[1]);
210
+ if (s < 0.4) return false;
211
+ const x0 = ba[2] + gap;
212
+ const top = smaller(word, B, s, x0, ba[1]);
213
+ const foot = smaller(word, C, s, x0, ba[3] - (bc[3] - bc[1]) * s);
214
+ // the weight given back mustn't close the gap between the two small ones
215
+ if (I(top, foot).length || I(top, A.shape).length || I(foot, A.shape).length) return false;
216
+ setShape(B, top); setShape(C, foot);
217
+ return true;
218
+ }
219
+ // rows: each letter on its own row, the gap between
220
+ const boxes = ls.map((l) => boxOf(l.shape)), cx = (boxes[0][0] + boxes[0][2]) / 2, x0 = boxes[0][0];
221
+ let y = 0;
222
+ for (let k = ls.length - 1; k >= 0; k--) {
223
+ const b = boxes[k], h = b[3] - b[1], w = b[2] - b[0];
224
+ const left = p.align === 'left' ? x0 : cx - w / 2;
225
+ setShape(ls[k], moved(ls[k].shape, left - b[0], y - b[3]));
226
+ y -= h + gap;
227
+ }
228
+ return true;
229
+ },
230
+ };
231
+
232
+ /* ---------- Knock-out and frame: a single letter in a solid shape, or in an outline of one ---------- */
233
+
234
+ /** The letters a container turns into a sign or a known mark (by its upper case). */
235
+ const FRAME_BANNED = {
236
+ disc: 'ABCGHIKOPQRSUWX0E',
237
+ square: 'FHIMNOPUXY0',
238
+ round: 'EFHIMNOPQTUVXY0',
239
+ };
240
+ const banned = (shape, ch) => FRAME_BANNED[shape].includes(ch.toUpperCase());
241
+
242
+ /** The container round a single letter: a square, a rounded square or a disc, `pad` clear of its ink. */
243
+ function containerOf(l, kind, pad) {
244
+ const b = boxOf(l.shape), cx = (b[0] + b[2]) / 2, cy = (b[1] + b[3]) / 2;
245
+ if (kind === 'disc') {
246
+ let r = 0;
247
+ for (const pg of l.shape) for (const [x, y] of pg[0]) r = Math.max(r, Math.hypot(x - cx, y - cy));
248
+ return { make: (extra) => circle(cx, cy, r + pad + extra, 180), cx, cy };
249
+ }
250
+ const side = Math.max(b[2] - b[0], b[3] - b[1]) + 2 * pad;
251
+ return {
252
+ make: (extra) => { const sd = side + 2 * extra; return kind === 'round' ? rr(cx - sd / 2, cy - sd / 2, sd, sd, sd * 0.22) : rect(cx - sd / 2, cy - sd / 2, sd, sd); },
253
+ cx, cy,
254
+ };
255
+ }
256
+
257
+ const single = (word) => isShort(word) && inked(word).length === 1;
258
+
259
+ export const knock = {
260
+ id: 'knock', name: 'Knock-out', line: 'The letter cut out of a solid square, rounded square or disc.',
261
+ controls: [
262
+ { key: 'shape', label: 'Shape', type: 'choice', options: ['square', 'round', 'disc'], value: 'square' },
263
+ { key: 'pad', label: 'Margin', type: 'range', min: 0.9, max: 1.8, step: 0.05, value: 1.2 },
264
+ ],
265
+ find: (word) => (single(word) && Object.keys(FRAME_BANNED).some((k) => !banned(k, inked(word)[0].char)) ? [0] : []),
266
+ apply(word, p) {
267
+ const l = inked(word)[0];
268
+ if (banned(p.shape, l.char)) return false;
269
+ const box = containerOf(l, p.shape, stemOf(word) * p.pad).make(0);
270
+ word.extra.push(D(box, l.shape));
271
+ l.shape = []; l.edited = true;
272
+ word.fused = true;
273
+ return true;
274
+ },
275
+ };
276
+
277
+ export const frame = {
278
+ id: 'frame', name: 'Framed', line: 'The letter inside an outline of a square, rounded square or disc.',
279
+ controls: [
280
+ { key: 'shape', label: 'Shape', type: 'choice', options: ['round', 'disc', 'square'], value: 'round' },
281
+ { key: 'pad', label: 'Margin', type: 'range', min: 0.8, max: 1.6, step: 0.05, value: 1.05 },
282
+ ],
283
+ find: knock.find,
284
+ apply(word, p) {
285
+ const l = inked(word)[0];
286
+ if (banned(p.shape, l.char)) return false;
287
+ const stem = stemOf(word), c = containerOf(l, p.shape, stem * p.pad);
288
+ word.extra.push(D(c.make(stem * 0.85), c.make(0)));
289
+ l.edited = true;
290
+ word.fused = true;
291
+ return true;
292
+ },
293
+ };
294
+
295
+ /* ---------- Linked: two letters overlapping, passing over and under each other ---------- */
296
+
297
+ const linkable = (word, [i, j]) => pairable(word.letters[i], word.letters[j]);
298
+
299
+ export const link = {
300
+ id: 'link', name: 'Linked', line: 'Two letters overlapping, passing over and under each other where they cross.',
301
+ controls: [
302
+ { key: 'depth', label: 'Overlap', type: 'range', min: 0.2, max: 0.45, step: 0.01, value: 0.32 },
303
+ { key: 'gap', label: 'Gap', type: 'range', min: 0.3, max: 0.6, step: 0.02, value: 0.4 },
304
+ { key: 'front', label: 'In front', type: 'choice', options: ['alternate', 'right', 'left'], value: 'alternate' },
305
+ ],
306
+ find: (word) => (isShort(word) && !script(word) ? pairsOf(word).filter((pr) => linkable(word, pr)).map(([i]) => i) : []),
307
+ apply(word, p) {
308
+ const prs = pairsOf(word).filter((pr) => linkable(word, pr));
309
+ if (!prs.length) return false;
310
+ const stem = stemOf(word), g = stem * p.gap;
311
+ for (const [i, j] of prs) {
312
+ const a = word.letters[i], b = word.letters[j];
313
+ shiftFrom(word, j, -(roomBetween(a.shape, b.shape, 0) + p.depth * Math.min(a.f.w, b.f.w)));
314
+ const crossings = I(a.shape, b.shape).filter((pg) => ink([pg]) > stem * stem * 0.15);
315
+ if (!crossings.length) return false;
316
+ const A = a.shape, B = b.shape;
317
+ if (p.front === 'alternate' && crossings.length >= 2) {
318
+ // top to bottom, the crossings take turns: the second letter over the first, then under it
319
+ crossings.sort((p1, p2) => boxOf([p1])[1] - boxOf([p2])[1]);
320
+ let na = A, nb = B;
321
+ crossings.forEach((c, k) => {
322
+ const near = grown([c], g * 1.6), front = k % 2 ? A : B;
323
+ const cutter = I(grown(front, g), near);
324
+ if (k % 2) nb = D(nb, cutter); else na = D(na, cutter);
325
+ });
326
+ a.shape = na; b.shape = nb;
327
+ } else if (p.front === 'left') b.shape = D(B, grown(A, g));
328
+ else a.shape = D(A, grown(B, g));
329
+ a.edited = b.edited = true;
330
+ }
331
+ word.fused = true;
332
+ return true;
333
+ },
334
+ };
335
+
336
+ /** Whether (x, y) is in the shape's ink. */
337
+ const inkAt = (shape, x, y) => runsAt(shape, y).some(([a, b]) => x >= a && x <= b);
338
+
339
+ /* ---------- Split: a single letter cut in two, one half slid along the cut ---------- */
340
+
341
+ export const split = {
342
+ id: 'split', name: 'Split', line: 'A single letter cut through the middle, one half slid along the cut.',
343
+ controls: [
344
+ { key: 'mode', label: 'Cut', type: 'choice', options: ['level', 'upright', 'slant'], value: 'level' },
345
+ { key: 'shift', label: 'Slide', type: 'range', min: 0.4, max: 1.2, step: 0.05, value: 0.75 },
346
+ { key: 'gap', label: 'Gap', type: 'range', min: 0.25, max: 0.6, step: 0.02, value: 0.35 },
347
+ ],
348
+ find: (word) => (single(word) ? [0] : []),
349
+ apply(word, p) {
350
+ const l = inked(word)[0], stem = stemOf(word), b = boxOf(l.shape), g = stem * p.gap;
351
+ let cx = (b[0] + b[2]) / 2, cy = (b[1] + b[3]) / 2;
352
+ // a level cut never runs along a crossbar: it moves halfway to the top instead
353
+ if (p.mode === 'level' && l.f?.crossbar) { const c = l.f.crossbar; if (cy > c.y0 - g * 1.5 && cy < c.y1 + g * 1.5) cy = (b[1] + c.y0) / 2; }
354
+ const deg = p.mode === 'level' ? 0 : p.mode === 'upright' ? 90 : -62, t = (deg * Math.PI) / 180;
355
+ const ux = Math.cos(t), uy = Math.sin(t), nx = -uy, ny = ux, F = CAP * 4;
356
+ const side = (k) => poly([
357
+ [cx + nx * k * g / 2 - ux * F, cy + ny * k * g / 2 - uy * F], [cx + nx * k * g / 2 + ux * F, cy + ny * k * g / 2 + uy * F],
358
+ [cx + nx * k * F + ux * F, cy + ny * k * F + uy * F], [cx + nx * k * F - ux * F, cy + ny * k * F - uy * F],
359
+ ]);
360
+ // the cut must cross strokes, never a junction (an X cut through its crossing is two chevrons): where it crosses
361
+ // ink, a line beside it a stroke and a third off meets one stroke there, not two arms parting
362
+ const step = stem / 10, crossings = [];
363
+ let start = null;
364
+ for (let t = -CAP * 1.5; t <= CAP * 1.5; t += step) {
365
+ const inside = inkAt(l.shape, cx + ux * t, cy + uy * t);
366
+ if (inside && start === null) start = t;
367
+ if (!inside && start !== null) { crossings.push((start + t) / 2); start = null; }
368
+ }
369
+ // each crossing looks along its own stretch of the line, up to halfway to the next crossing (an O's two walls)
370
+ const runsBeside = (t, k, lo, hi) => {
371
+ let n = 0, was = false;
372
+ for (let q = lo; q <= hi; q += step) {
373
+ const x = cx + ux * (t + q) + nx * k * 1.3 * stem, y = cy + uy * (t + q) + ny * k * 1.3 * stem, now = inkAt(l.shape, x, y);
374
+ if (now && !was) n++;
375
+ was = now;
376
+ }
377
+ return n;
378
+ };
379
+ const reach = (i) => [i > 0 ? Math.max(-3 * stem, (crossings[i - 1] - crossings[i]) / 2) : -3 * stem, i < crossings.length - 1 ? Math.min(3 * stem, (crossings[i + 1] - crossings[i]) / 2) : 3 * stem];
380
+ if (!crossings.length || crossings.some((t, i) => runsBeside(t, 1, ...reach(i)) > 1 || runsBeside(t, -1, ...reach(i)) > 1)) return false;
381
+ const s = stem * p.shift, one = I(l.shape, side(1)), two = moved(I(l.shape, side(-1)), ux * s, uy * s);
382
+ const total = ink(l.shape), pieces = [...one, ...two];
383
+ // a cut that leaves a crumb (a serif's tip, an arm's end) isn't a split
384
+ if (!one.length || !two.length || pieces.some((pg) => ink([pg]) < total * 0.04)) return false;
385
+ l.shape = pieces; l.edited = true; l.sliced = true;
386
+ return true;
387
+ },
388
+ };
389
+
390
+ /* ---------- Echo: the letters and a shadow of them, cut free by a gap ---------- */
391
+
392
+ export const echo = {
393
+ id: 'echo', name: 'Echo', line: 'The letters with a solid block shadow behind, cut free by a gap.',
394
+ controls: [
395
+ { key: 'dir', label: 'Falls', type: 'choice', options: ['drop', 'rise'], value: 'drop' }, // a shadow rising reads as a fall: by hand only
396
+ { key: 'depth', label: 'Depth', type: 'range', min: 0.7, max: 1.6, step: 0.05, value: 1.1 },
397
+ { key: 'gap', label: 'Gap', type: 'range', min: 0.25, max: 0.5, step: 0.01, value: 0.32 },
398
+ ],
399
+ // capitals in a heavy face only: a shadow behind lowercase or a light face is a blur at 32 px
400
+ find: (word) => (isShort(word) && inked(word).every((l) => capital(l.char)) && stemOf(word) / CAP >= 0.21 ? [0] : []),
401
+ apply(word, p) {
402
+ if (!this.find(word).length) return false;
403
+ const front = U(...inked(word).map((l) => l.shape)), stem = stemOf(word), d = stem * p.depth, sy = p.dir === 'rise' ? -1 : 1;
404
+ // the letters swept back along the shadow's line, exactly (every edge drawn out into a parallelogram), so the
405
+ // shadow is one solid block with straight sides; kept outside the letters' outlines (a shadow in a counter is
406
+ // clutter), a gap clear of them
407
+ const vx = d, vy = sy * d, quads = [];
408
+ for (const pg of front) for (const ring of pg) for (let i = 0; i < ring.length; i++) {
409
+ const [ax, ay] = ring[i], [bx, by] = ring[(i + 1) % ring.length];
410
+ if (Math.hypot(bx - ax, by - ay) < 0.5) continue;
411
+ quads.push(poly([[ax, ay], [bx, by], [bx + vx, by + vy], [ax + vx, ay + vy]]));
412
+ }
413
+ const solid = U(front, moved(front, vx, vy), ...quads);
414
+ const outline = U(...front.map((pg) => [pg[0]]));
415
+ const total = ink(front);
416
+ const back = D(solid, grown(outline, stem * p.gap)).filter((pg) => ink([pg]) > total * 0.03);
417
+ if (!back.length || ink(back) < total * 0.15) return false;
418
+ word.extra.push(back);
419
+ word.fused = true;
420
+ return true;
421
+ },
422
+ };
423
+
424
+ /* ---------- Lines: two or three level gaps across the letters ---------- */
425
+
426
+ export const lines = {
427
+ id: 'lines', name: 'Lines', line: 'Two or three level gaps cut across the letters.',
428
+ controls: [
429
+ { key: 'lines', label: 'Lines', type: 'range', min: 2, max: 3, step: 1, value: 2 },
430
+ { key: 'gap', label: 'Gap', type: 'range', min: 0.22, max: 0.45, step: 0.01, value: 0.3 },
431
+ ],
432
+ // three heavy capitals in stripes are a known computing logo
433
+ find: (word) => (isShort(word) && inked(word).map((l) => l.char).join('').toUpperCase() !== 'IBM' ? [0] : []),
434
+ apply(word, p) {
435
+ const ls = inked(word), stem = stemOf(word), g = stem * p.gap, n = Math.round(p.lines);
436
+ const b = boxOf(U(...ls.map((l) => l.shape))), x0 = b[0] - CAP, x1 = b[2] + CAP, top = Math.max(b[1], -CAP), h = Math.min(b[3], 0) - top;
437
+ const cuts = U(...Array.from({ length: n }, (_, k) => rect(x0, top + (h * (k + 1)) / (n + 1) - g / 2, x1 - x0, g)));
438
+ for (const l of ls) {
439
+ const total = ink(l.shape), cut = D(l.shape, cuts);
440
+ if (cut.some((pg) => ink([pg]) < total * 0.025)) return false;
441
+ l.shape = cut; l.edited = true; l.sliced = true;
442
+ }
443
+ return true;
444
+ },
445
+ };
446
+
447
+ export const SHORT_EDITS = [monoJoin, inset, stack, knock, frame, link, split, echo, lines];
package/src/index.d.ts CHANGED
@@ -72,6 +72,11 @@ export function typemark(name: string, o: { font: TypeFont; edits?: EditCall[];
72
72
  export function suggest(name: string, o: { fonts: TypeFont[] | FontRegistry; count?: number; seed?: number | string; lock?: { fonts?: string[]; edits?: string[]; slant?: number; tracking?: number } }): Promise<Typemark[]>;
73
73
  /** Every edit, by id (the general edits and the rule book's rules alike). */
74
74
  export const EDITS: Record<string, Edit>;
75
+
76
+ /** Whether a set word is a short name: one to three letters, one word (the short-name moves act only on these). */
77
+ export function isShort(word: unknown): boolean;
78
+ /** The short-name moves: monoJoin, inset, stack, knock, frame, link, split, echo, lines (also in `EDITS`). */
79
+ export const SHORT_EDITS: Edit[];
75
80
  /** A rule of the letter rule book: an edit keyed on the letters a name has. */
76
81
  export interface Rule extends Edit {
77
82
  /** The letters any one of which makes the rule fit a name ('RKQ'), or the pairs a pair rule needs (['TT', 'TH', …]). */
package/src/index.js CHANGED
@@ -4,7 +4,7 @@
4
4
  export { loadFont, registry } from './font.js';
5
5
  export { typemark } from './typemark.js';
6
6
  export { suggest, WEIGHT } from './suggest.js';
7
- export { EDITS, RULES, fits } from './edits/index.js';
7
+ export { EDITS, RULES, fits, isShort, SHORT_EDITS } from './edits/index.js';
8
8
  export { strokesOf } from './strokes.js';
9
9
  export * as ops from './ops.js';
10
10
  export { setWord, strokeOf, CAP } from './word.js';
package/src/ops.js CHANGED
@@ -171,7 +171,7 @@ export function shortenStem(shape, f, x0, x1, edge, len) {
171
171
 
172
172
  /** The font's counter width, in word units: the white between an H's stems (or an n's), cached per font. */
173
173
  const counters = new WeakMap();
174
- function counterOf(word, stem) {
174
+ export function counterOf(word, stem) {
175
175
  const font = word.font;
176
176
  if (!counters.has(font)) {
177
177
  let gap = 0;
@@ -193,7 +193,7 @@ function counterOf(word, stem) {
193
193
  * counter or a C's mouth, so half is tried, then none.
194
194
  */
195
195
  const topology = (shape) => `${shape.length}:${shape.map((p) => p.length).join(',')}`;
196
- function bolder(shape, d) {
196
+ export function bolder(shape, d) {
197
197
  const key = topology(U(shape));
198
198
  for (const k of [1, 0.5]) {
199
199
  const b = grown(shape, d * k);
package/src/suggest.js CHANGED
@@ -20,6 +20,7 @@ export const WEIGHT = {
20
20
  crossbarDrop: 1, crossShift: 0.96, sharedBar: 0.95, ligature: 0.9, legRun: 0.92, eArms: 0.92, ringLink: 0.9, tRoof: 0.9, lFloor: 0.9,
21
21
  nestPair: 0.85, pointCut: 0.8, hBar: 0.78, counter: 0.72, tCut: 0.72, xCut: 0.7, yFork: 0.7, terminalCut: 0.68, crossbarCut: 0.66,
22
22
  pixelStep: 0.98, pixelCursor: 0.9, pixelBar: 0.86, pixelShift: 0.6,
23
+ monoJoin: 0.96, inset: 0.96, knock: 0.95, link: 0.93, stack: 0.6, echo: 0.7, split: 0.86, frame: 0.85, lines: 0.8,
23
24
  sSlice: 0.62, diagCut: 0.6, stemShort: 0.6, legFree: 0.6, stemCut: 0.58, swap: 0.55, slice: 0.55, stencil: 0.5, accent: 0.42,
24
25
  };
25
26
  /** Edits `suggest()` never picks on its own: loud, or decoration rather than an idea. They stay in `EDITS` for hand use. */
@@ -37,7 +38,20 @@ const HOUSE = {
37
38
  pixelShift: [{ row: 0.45, rows: 1, by: 1 }],
38
39
  pixelStep: [{ mode: 'alternate', by: 1 }, { mode: 'stairs', by: 1 }, { mode: 'arch', by: 1 }],
39
40
  pixelBar: [{ ends: 'steps', weight: 1 }, { ends: 'dots', weight: 1 }],
41
+ monoJoin: [{ share: 'stroke', pair: 'first' }, { share: 'stroke', pair: 'last' }],
42
+ inset: [{ order: 'auto' }],
43
+ stack: [{ mode: 'rows', align: 'centre' }, { mode: 'rows', align: 'left' }, { mode: 'lead' }],
44
+ knock: [{ shape: 'square', pad: 1.2 }, { shape: 'round', pad: 1.2 }, { shape: 'disc', pad: 1.1 }],
45
+ frame: [{ shape: 'round', pad: 1.05 }, { shape: 'disc', pad: 1 }, { shape: 'square', pad: 1.05 }],
46
+ link: [{ front: 'alternate' }, { front: 'right' }],
47
+ split: [{ mode: 'level' }, { mode: 'upright' }, { mode: 'slant' }],
48
+ echo: [{ dir: 'drop', depth: 1.1 }, { dir: 'drop', depth: 0.8, gap: 0.28 }],
49
+ lines: [{ lines: 2, gap: 0.3 }, { lines: 3, gap: 0.26 }],
40
50
  };
51
+ /** The short-name moves (./edits/short.js): a monogram resets the letters, so like a roof it is judged as a big move. */
52
+ /** Moves a page holds only a few of, however many pass: stacks render small, shadows are busy. */
53
+ const PAGE_CAP = { stack: 2, echo: 3 };
54
+ const SHORT_IDS = ['monoJoin', 'inset', 'stack', 'knock', 'frame', 'link', 'split', 'echo', 'lines'];
41
55
 
42
56
  /**
43
57
  * The tracking a setting wants, as a share of the cap height, from its case and its weight (stroke over cap height):
@@ -103,7 +117,7 @@ export async function suggest(name, { fonts, count = 48, seed = 1, lock = {} } =
103
117
  if (lock.fonts?.length) list = list.filter((f) => lock.fonts.includes(f.id));
104
118
  const ids = (lock.edits?.length ? lock.edits : Object.keys(EDITS).filter((id) => !EDITS[id].alias && !HAND_ONLY.includes(id))).filter((id) => EDITS[id]);
105
119
  const found = [];
106
- const started = Date.now(), long = [...name].length > 10;
120
+ const started = Date.now(), long = [...name].length > 10, short = [...name.trim()].length <= 3 && !/\s/.test(name.trim());
107
121
  let fontsDone = 0;
108
122
  for (const font of list) {
109
123
  // a long name is slow to set: past the time budget, the fonts already tried make the page
@@ -126,11 +140,12 @@ export async function suggest(name, { fonts, count = 48, seed = 1, lock = {} } =
126
140
  if ((id === 'tRoof' || id === 'lFloor') && (!carries(id, text) || font.tags?.includes('serif') || weight > 0.23)) continue; // a roof on serifs tangles, and in a very heavy face the tucked letters cramp
127
141
  if (id === 'crossbarCut' && !isUpper) continue; // a cut through a lowercase e's bar closes it into an o
128
142
  if (id === 'counter' && !/[oOqQ0]/.test(text)) continue; // a ring or slot belongs in a round letter: in an a or e it is a blob
143
+ if (id === 'counter' && short && !/[oOQ0]/.test(text)) continue; // a short name's lowercase q with its counter shut is a blob
129
144
  for (const params of long ? tries(EDITS[id]).slice(0, 1) : tries(EDITS[id])) {
130
145
  const tracking = lock.tracking ?? (pixel ? 0 : JOINED.includes(id) ? Math.min(0.02, opticalTracking(weight, isUpper)) : opticalTracking(weight, isUpper));
131
146
  const m = typemark(text, { font, edits: [{ id, params }], slant: lock.slant ?? 0, tracking });
132
147
  if (m.problems.length || !m.applied.length) continue;
133
- const main = m.applied[0], rule = RULE[main.id], big = main.id === 'tRoof' || main.id === 'lFloor' || main.id.startsWith('pixel');
148
+ const main = m.applied[0], rule = RULE[main.id], big = main.id === 'tRoof' || main.id === 'lFloor' || main.id.startsWith('pixel') || SHORT_IDS.includes(main.id);
134
149
  const score = 0.4 * visibleOf(m.change, big) + 0.5 * (WEIGHT[main.id] ?? 0.4) - (rule ? quiet(rule, main.params) : 0) + 0.06 * rand();
135
150
  found.push({ ...m, score, key: `${font.id}|${main.id}|${isUpper ? 'U' : 'l'}`, pair: `${font.id}|${main.id}` });
136
151
  }
@@ -143,7 +158,7 @@ export async function suggest(name, { fonts, count = 48, seed = 1, lock = {} } =
143
158
  for (const m of found) {
144
159
  if (picked.length >= count) break;
145
160
  const f = m.record.fontId, e = m.applied[0].id;
146
- if ((nFont.get(f) || 0) >= perFont || (nEdit.get(e) || 0) >= perEdit || (nKey.get(m.key) || 0) >= 1) continue;
161
+ if ((nFont.get(f) || 0) >= perFont || (nEdit.get(e) || 0) >= Math.min(perEdit, PAGE_CAP[e] ?? Infinity) || (nKey.get(m.key) || 0) >= 1) continue;
147
162
  nFont.set(f, (nFont.get(f) || 0) + 1); nEdit.set(e, (nEdit.get(e) || 0) + 1); nKey.set(m.key, (nKey.get(m.key) || 0) + 1);
148
163
  picked.push(m);
149
164
  }
@@ -151,7 +166,10 @@ export async function suggest(name, { fonts, count = 48, seed = 1, lock = {} } =
151
166
  for (const m of found) {
152
167
  if (picked.length >= count) break;
153
168
  if (picked.includes(m) || (nFont.get(m.record.fontId) || 0) >= perFont + 2 || (nKey.get(m.key) || 0) >= 2) continue;
169
+ // a short name has few moves: none may fill the page (a long name's pass is as it was)
170
+ if (short && (nEdit.get(m.applied[0].id) || 0) >= Math.min(perEdit + 2, PAGE_CAP[m.applied[0].id] ?? Infinity)) continue;
154
171
  nFont.set(m.record.fontId, (nFont.get(m.record.fontId) || 0) + 1); nKey.set(m.key, (nKey.get(m.key) || 0) + 1);
172
+ nEdit.set(m.applied[0].id, (nEdit.get(m.applied[0].id) || 0) + 1);
155
173
  picked.push(m);
156
174
  }
157
175
  // order the page: best first, but never the same edit twice running, nor the same font, where another is to be had