@logomarks/typemarks 0.2.0 → 0.3.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.
- package/CHANGELOG.md +23 -0
- package/README.md +3 -1
- package/package.json +1 -1
- package/src/edits/duo.js +141 -0
- package/src/edits/index.js +4 -2
- package/src/edits/short.js +22 -12
- package/src/index.d.ts +7 -2
- package/src/index.js +1 -1
- package/src/suggest.js +29 -7
- package/src/typemark.js +5 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
|
|
4
|
+
## 0.3.0 (2026-11-28)
|
|
5
|
+
|
|
6
|
+
- **Contrast moves for two-letter names** (`src/edits/duo.js`, `DUO_EDITS`), after the owner's contrast monograms:
|
|
7
|
+
the two initials treated unlike on purpose. `duoBox` (one cut out of a solid square or rounded square, the other open
|
|
8
|
+
beside it), `duoRings` (each in a circle, or a rounded square where a circle would make a sign, one cut out of a solid
|
|
9
|
+
one, the other in an outline), `duoClash` (one initial in another face, a sans beside a serif, at the same cap height:
|
|
10
|
+
`typemark(name, { partner })` takes the face, and `record.partner` names it with its licence) and `duoScale` (one big,
|
|
11
|
+
the other half size at its foot or shoulder). Two capitals only; on such a name they lead `suggest()`'s page (five of
|
|
12
|
+
each at most, four of `duoScale`), and a clash is tried with the two faces of the page's fonts that contrast most
|
|
13
|
+
(another first tag: a serif for a sans, a sans or display for a serif).
|
|
14
|
+
- **Bans:** `BLOCKED` initials (other companies' monograms, LV, CC, GG, DG, YSL, VW, HP, GE, MK, CK, HM, DC, NY, LA, IBM,
|
|
15
|
+
BMW, KFC, and hate codes, SS, HH, KKK, 88) are never drawn as a contrast pair, a join or a link; a boxed or ringed
|
|
16
|
+
letter keeps the single-letter frame bans (® ©, H, P, app-icon letters); a small T, S or O at an M's or N's shoulder
|
|
17
|
+
(™ ℠ №) is skipped.
|
|
18
|
+
- Every other name's page is byte-identical to 0.2.1's (LUCIA, TRAVIS, NORTHWIND COFFEE: `tests/fixtures/long-names.json`).
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
## 0.2.1 (2026-11-27)
|
|
22
|
+
|
|
23
|
+
- No monogram join or link in a script face (tagged `script`): its capitals are joined strokes already, and JO in
|
|
24
|
+
Caveat joined into a p.
|
|
25
|
+
|
|
3
26
|
## 0.2.0 (2026-11-27)
|
|
4
27
|
|
|
5
28
|
- **Short names** (`src/edits/short.js`, `isShort`, `SHORT_EDITS`): nine moves for names of one to three letters, which
|
package/README.md
CHANGED
|
@@ -15,7 +15,9 @@ forks.
|
|
|
15
15
|
|
|
16
16
|
A name of one to three letters gets monogram moves instead: two capitals set into each other or linked, one letter
|
|
17
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").
|
|
18
|
+
a block shadow, or cut by lines (`docs/edits.md`, "Short names"). Two capitals also get contrast moves, the initials
|
|
19
|
+
treated unlike on purpose: one boxed and one open, each in a ring (one solid, one outlined), one in another face matched
|
|
20
|
+
to cap height (`typemark(name, { font, partner })`), or one big and one small (`docs/edits.md`, "Two-letter contrast").
|
|
19
21
|
|
|
20
22
|
## Install
|
|
21
23
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logomarks/typemarks",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
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",
|
package/src/edits/duo.js
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contrast moves for two-letter names (JM, AS, DK): the two initials treated unlike on purpose, after the owner's
|
|
3
|
+
* contrast monograms. One knocked out of a box, the other open beside it (`duoBox`); each in a circle or rounded square,
|
|
4
|
+
* one solid, one outlined (`duoRings`); the second (or first) set in another face from the registry, matched to cap
|
|
5
|
+
* height (`duoClash`: `typemark()` takes the face as `partner`); one big, the other small at its foot or shoulder
|
|
6
|
+
* (`duoScale`). Each finds nothing unless the name is two capitals, so every other name's page is as it was.
|
|
7
|
+
*
|
|
8
|
+
* Bans: the blocked initials (other companies' monograms, hate codes: `BLOCKED`); a boxed or ringed letter that reads as
|
|
9
|
+
* a sign in that container (the single-letter frame bans: ® © Ⓐ, H, P, app-icon letters); a small T, S or O at the
|
|
10
|
+
* shoulder of an M or N (™, ℠, №).
|
|
11
|
+
*/
|
|
12
|
+
import { D, rect, rr, circle } from '@logomarks/core/geometry';
|
|
13
|
+
import { moved } from '../geo.js';
|
|
14
|
+
import { boxOf } from '../features.js';
|
|
15
|
+
import { setWord, CAP } from '../word.js';
|
|
16
|
+
import { inked, isShort, capital, wide, smaller, setShape, banned, stemOf, blockedWord } from './short.js';
|
|
17
|
+
|
|
18
|
+
/** Two capitals, one word, not blocked. */
|
|
19
|
+
const two = (word) => isShort(word) && inked(word).length === 2 && inked(word).every((l) => capital(l.char) && l.f) && !blockedWord(word);
|
|
20
|
+
const middle = (s) => { const b = boxOf(s); return [(b[0] + b[2]) / 2, (b[1] + b[3]) / 2]; };
|
|
21
|
+
/** The space between two letters set side by side as a pair: wider than a word's tracking, so they read as two parts. */
|
|
22
|
+
const pairGap = (word) => Math.max(stemOf(word) * 1.1, CAP * 0.12);
|
|
23
|
+
|
|
24
|
+
/** A square or rounded square `side` wide round (cx, cy). */
|
|
25
|
+
const square = (kind, cx, cy, side) => (kind === 'round' ? rr(cx - side / 2, cy - side / 2, side, side, side * 0.22) : rect(cx - side / 2, cy - side / 2, side, side));
|
|
26
|
+
/** How far a letter's ink reaches from (cx, cy). */
|
|
27
|
+
const reach = (shape, cx, cy) => { let r = 0; for (const pg of shape) for (const [x, y] of pg[0]) r = Math.max(r, Math.hypot(x - cx, y - cy)); return r; };
|
|
28
|
+
|
|
29
|
+
/* ---------- Boxed: one letter knocked out of a box, the other open beside it ---------- */
|
|
30
|
+
|
|
31
|
+
export const duoBox = {
|
|
32
|
+
id: 'duoBox', name: 'Boxed pair', line: 'One initial cut out of a solid box, the other open beside it.',
|
|
33
|
+
controls: [
|
|
34
|
+
{ key: 'which', label: 'Boxed', type: 'choice', options: ['first', 'second'], value: 'first' },
|
|
35
|
+
{ key: 'shape', label: 'Box', type: 'choice', options: ['round', 'square'], value: 'round' },
|
|
36
|
+
{ key: 'pad', label: 'Margin', type: 'range', min: 0.8, max: 1.6, step: 0.05, value: 1.1 },
|
|
37
|
+
],
|
|
38
|
+
find: (word) => (two(word) && inked(word).some((l) => !banned('round', l.char) || !banned('square', l.char)) ? [0] : []),
|
|
39
|
+
apply(word, p) {
|
|
40
|
+
const [a, b] = inked(word), boxed = p.which === 'second' ? b : a, open = boxed === a ? b : a;
|
|
41
|
+
if (banned(p.shape, boxed.char)) return false;
|
|
42
|
+
const stem = stemOf(word), bb = boxOf(boxed.shape), side = Math.max(bb[2] - bb[0], bb[3] - bb[1]) + 2 * stem * p.pad, gap = pairGap(word);
|
|
43
|
+
const ob = boxOf(open.shape), [, cy] = middle(boxed.shape);
|
|
44
|
+
// the box keeps its letter's place; the open letter sits a pair's gap from it, centred on it (reading order kept)
|
|
45
|
+
const [bx] = middle(boxed.shape), boxLeft = bx - side / 2, boxRight = bx + side / 2;
|
|
46
|
+
const dx = boxed === a ? boxRight + gap - ob[0] : boxLeft - gap - ob[2];
|
|
47
|
+
setShape(open, moved(open.shape, dx, cy - (ob[1] + ob[3]) / 2));
|
|
48
|
+
word.extra.push(D(square(p.shape, bx, cy, side), boxed.shape));
|
|
49
|
+
boxed.shape = []; boxed.edited = true;
|
|
50
|
+
word.fused = true;
|
|
51
|
+
return true;
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/* ---------- Rings: each letter in a circle (or rounded square), one solid, one outlined ---------- */
|
|
56
|
+
|
|
57
|
+
/** The container both letters can take: a disc, else a rounded square, else none. */
|
|
58
|
+
const ringShape = (word, asked) => {
|
|
59
|
+
const ls = inked(word), ok = (k) => ls.every((l) => !banned(k, l.char));
|
|
60
|
+
return [asked, asked === 'disc' ? 'round' : 'disc'].find(ok) || null;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export const duoRings = {
|
|
64
|
+
id: 'duoRings', name: 'Two rings', line: 'Each initial in a circle, one cut out of a solid one, the other in an outline.',
|
|
65
|
+
controls: [
|
|
66
|
+
{ key: 'which', label: 'Solid', type: 'choice', options: ['first', 'second'], value: 'first' },
|
|
67
|
+
{ key: 'shape', label: 'Shape', type: 'choice', options: ['disc', 'round'], value: 'disc' },
|
|
68
|
+
{ key: 'pad', label: 'Margin', type: 'range', min: 0.7, max: 1.4, step: 0.05, value: 0.95 },
|
|
69
|
+
],
|
|
70
|
+
find: (word) => (two(word) && ringShape(word, 'disc') ? [0] : []),
|
|
71
|
+
apply(word, p) {
|
|
72
|
+
const kind = ringShape(word, p.shape);
|
|
73
|
+
if (!kind) return false;
|
|
74
|
+
const [a, b] = inked(word), stem = stemOf(word), t = stem * 0.85, pad = stem * p.pad, gap = Math.max(stem * 0.9, CAP * 0.1);
|
|
75
|
+
// one size for both: the bigger letter's reach (a disc) or side (a square), its margin, then the outline's width
|
|
76
|
+
const size = Math.max(...[a, b].map((l) => { const [cx, cy] = middle(l.shape), bx = boxOf(l.shape); return kind === 'disc' ? reach(l.shape, cx, cy) : Math.max(bx[2] - bx[0], bx[3] - bx[1]) / 2; })) + pad;
|
|
77
|
+
const outer = size + t, make = (cx, cy, r) => (kind === 'disc' ? circle(cx, cy, r, 180) : square('round', cx, cy, 2 * r));
|
|
78
|
+
const [ax, ay] = middle(a.shape), [bx0, by0] = middle(b.shape), cy = (ay + by0) / 2, bx = ax + 2 * outer + gap;
|
|
79
|
+
setShape(a, moved(a.shape, 0, cy - ay));
|
|
80
|
+
setShape(b, moved(b.shape, bx - bx0, cy - by0));
|
|
81
|
+
const solid = p.which === 'second' ? b : a, ring = solid === a ? b : a, sx = solid === a ? ax : bx, rx = ring === a ? ax : bx;
|
|
82
|
+
word.extra.push(D(make(sx, cy, outer), solid.shape));
|
|
83
|
+
word.extra.push(D(make(rx, cy, outer), make(rx, cy, size)));
|
|
84
|
+
solid.shape = []; solid.edited = true;
|
|
85
|
+
word.fused = true;
|
|
86
|
+
return true;
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
/* ---------- Clash: one letter in another face, matched to cap height ---------- */
|
|
91
|
+
|
|
92
|
+
export const duoClash = {
|
|
93
|
+
id: 'duoClash', name: 'Type clash', line: 'One initial in another face, a sans beside a serif, matched to cap height.',
|
|
94
|
+
controls: [
|
|
95
|
+
{ key: 'which', label: 'Other face', type: 'choice', options: ['second', 'first'], value: 'second' },
|
|
96
|
+
{ key: 'space', label: 'Space', type: 'range', min: 0.6, max: 1.6, step: 0.05, value: 1 },
|
|
97
|
+
],
|
|
98
|
+
// the other face comes from `typemark(name, { partner })`: without one there is nothing to clash with
|
|
99
|
+
find: (word) => (two(word) ? [0] : []),
|
|
100
|
+
apply(word, p) {
|
|
101
|
+
const partner = word.partner;
|
|
102
|
+
if (!partner || partner.id === word.font?.id) return false;
|
|
103
|
+
// a clash is two kinds of face (a sans and a serif, a wide and a condensed): two of a kind just look mis-set
|
|
104
|
+
if (partner.tags?.[0] && word.font?.tags?.[0] && partner.tags[0] === word.font.tags[0]) return false;
|
|
105
|
+
const [a, b] = inked(word), swap = p.which === 'first' ? a : b, keep = swap === a ? b : a;
|
|
106
|
+
const set = setWord(partner, swap.char).letters[0];
|
|
107
|
+
if (!set || set.missing || !set.shape.length) return false;
|
|
108
|
+
// set at the same cap height (every word is set to CAP); a pair's gap from the letter it stays beside
|
|
109
|
+
const kb = boxOf(keep.shape), sb = boxOf(set.shape), gap = pairGap(word) * 0.55 * p.space;
|
|
110
|
+
const dx = swap === b ? kb[2] + gap - sb[0] : kb[0] - gap - sb[2];
|
|
111
|
+
setShape(swap, moved(set.shape, dx, 0), 'swapped');
|
|
112
|
+
word.partnerUsed = true;
|
|
113
|
+
return true;
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
/* ---------- Scale: one letter big, the other small at its foot or shoulder ---------- */
|
|
118
|
+
|
|
119
|
+
/** A small letter at an M's or N's shoulder that reads as a sign: ™, ℠, №. */
|
|
120
|
+
const SIGNS = ['TM', 'SM', 'NO'];
|
|
121
|
+
|
|
122
|
+
export const duoScale = {
|
|
123
|
+
id: 'duoScale', name: 'Big and small', line: 'One initial big, the other small at its foot or its shoulder.',
|
|
124
|
+
controls: [
|
|
125
|
+
{ key: 'which', label: 'Small', type: 'choice', options: ['second', 'first'], value: 'second' },
|
|
126
|
+
{ key: 'align', label: 'Sits', type: 'choice', options: ['base', 'top'], value: 'base' },
|
|
127
|
+
{ key: 'size', label: 'Size', type: 'range', min: 0.4, max: 0.62, step: 0.01, value: 0.5 },
|
|
128
|
+
],
|
|
129
|
+
// both wider than a stem: a small I is a dot
|
|
130
|
+
find: (word) => (two(word) && inked(word).every((l) => wide(l)) ? [0] : []),
|
|
131
|
+
apply(word, p) {
|
|
132
|
+
const [a, b] = inked(word), small = p.which === 'first' ? a : b, big = small === a ? b : a;
|
|
133
|
+
if (p.align === 'top' && small === b && SIGNS.includes(a.char + b.char)) return false;
|
|
134
|
+
const gb = boxOf(big.shape), sb = boxOf(small.shape), s = p.size, w = (sb[2] - sb[0]) * s, h = (sb[3] - sb[1]) * s, gap = Math.max(stemOf(word) * 0.7, CAP * 0.08);
|
|
135
|
+
const x0 = small === b ? gb[2] + gap : gb[0] - gap - w, y0 = p.align === 'top' ? gb[1] : gb[3] - h;
|
|
136
|
+
setShape(small, smaller(word, small, s, x0, y0));
|
|
137
|
+
return true;
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
export const DUO_EDITS = [duoBox, duoRings, duoClash, duoScale];
|
package/src/edits/index.js
CHANGED
|
@@ -15,10 +15,12 @@ import round from './round.js';
|
|
|
15
15
|
import accent from './accent.js';
|
|
16
16
|
import { PIXEL_EDITS } from './pixel.js';
|
|
17
17
|
import { SHORT_EDITS } from './short.js';
|
|
18
|
+
import { DUO_EDITS } from './duo.js';
|
|
18
19
|
import { RULES } from './rules.js';
|
|
19
20
|
|
|
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]));
|
|
21
|
+
export const EDITS = Object.fromEntries([drop, cut, stencil, slice, ligature, overlap, bar, underline, swap, counter, round, accent, ...PIXEL_EDITS, ...SHORT_EDITS, ...DUO_EDITS, ...RULES].map((e) => [e.id, e]));
|
|
21
22
|
|
|
22
23
|
export { RULES, fits } from './rules.js';
|
|
23
24
|
export { pixelOf } from './pixel.js';
|
|
24
|
-
export { isShort, SHORT_EDITS } from './short.js';
|
|
25
|
+
export { isShort, SHORT_EDITS, BLOCKED } from './short.js';
|
|
26
|
+
export { DUO_EDITS } from './duo.js';
|
package/src/edits/short.js
CHANGED
|
@@ -18,23 +18,33 @@ import { fill } from '../raster.js';
|
|
|
18
18
|
import { CAP, shiftFrom, strokeOf } from '../word.js';
|
|
19
19
|
import { roomBetween, bolder, counterOf } from '../ops.js';
|
|
20
20
|
|
|
21
|
+
/**
|
|
22
|
+
* Initials never drawn as a monogram: other companies' monogram logos (LV, CC, GG, DG, YSL, VW, HP, GE, MK, CK, HM, DC,
|
|
23
|
+
* NY, LA, IBM, BMW, KFC) and hate codes (SS, HH, KKK, 88). The same list as @logomarks/generate's.
|
|
24
|
+
*/
|
|
25
|
+
export const BLOCKED = ['LV', 'CC', 'GG', 'DG', 'YSL', 'VW', 'HP', 'GE', 'MK', 'CK', 'HM', 'DC', 'NY', 'LA', 'IBM', 'BMW', 'KFC', 'SS', 'HH', 'KKK', '88'];
|
|
26
|
+
/** Whether a short word's letters are blocked initials. */
|
|
27
|
+
export const blockedWord = (word) => BLOCKED.includes(word.letters.filter((l) => l.shape.length).map((l) => l.char).join('').toUpperCase());
|
|
28
|
+
|
|
21
29
|
/** The letters with ink. */
|
|
22
|
-
const inked = (word) => word.letters.filter((l) => l.shape.length);
|
|
30
|
+
export const inked = (word) => word.letters.filter((l) => l.shape.length);
|
|
23
31
|
/** A name of one to three letters, one word. */
|
|
24
32
|
export const isShort = (word) => { const n = inked(word).length; return n >= 1 && n <= 3 && !word.letters.some((l) => /\s/.test(l.char)); };
|
|
25
|
-
|
|
33
|
+
/** A script face (tagged `script`): its capitals are joined strokes already, so a join or link turns JO into a p. */
|
|
34
|
+
export const script = (word) => !!word.font?.tags?.includes('script');
|
|
35
|
+
export const stemOf = (word) => word.stem || strokeOf(word);
|
|
26
36
|
|
|
27
37
|
const STRAIGHT = 'IiLlTtJj1|';
|
|
28
38
|
/** Two letters whose crossing reads as a cross (IT, TL, XI …). */
|
|
29
39
|
const crossy = (a, b) => (STRAIGHT.includes(a) && STRAIGHT.includes(b)) || ('Xx+'.includes(a) && STRAIGHT.includes(b)) || ('Xx+'.includes(b) && STRAIGHT.includes(a));
|
|
30
|
-
const holed = (l) => (l.f?.holes?.length ?? 0) > 0;
|
|
40
|
+
export const holed = (l) => (l.f?.holes?.length ?? 0) > 0;
|
|
31
41
|
/** A letter more than its stem (an I or an l set into another vanishes). */
|
|
32
|
-
const wide = (l) => l.f && l.f.w > l.f.stem * 1.8;
|
|
42
|
+
export const wide = (l) => l.f && l.f.w > l.f.stem * 1.8;
|
|
33
43
|
/**
|
|
34
44
|
* A pair that can be set into each other: capitals (a lowercase stem set into a bowl makes another letter: j and o
|
|
35
45
|
* become a p), neither narrow (condensed letters overlapped are a smudge), never a cross, never two holes side by side.
|
|
36
46
|
*/
|
|
37
|
-
const capital = (c) => c !== c.toLowerCase() && c === c.toUpperCase();
|
|
47
|
+
export const capital = (c) => c !== c.toLowerCase() && c === c.toUpperCase();
|
|
38
48
|
const ROUND = 'OQ0CGD';
|
|
39
49
|
/** A round letter set into an X is a fish (and an alpha). */
|
|
40
50
|
const fishy = (a, b) => (a === 'X' && ROUND.includes(b)) || (b === 'X' && ROUND.includes(a));
|
|
@@ -52,14 +62,14 @@ const placedAt = (shape, s, x0, y0) => { const b = boxOf(shape); return mapPts(s
|
|
|
52
62
|
/** The weight a letter set at s loses, given back (no more than a fifth of a counter at its size). */
|
|
53
63
|
const thickenFor = (word, s) => { const stem = stemOf(word); return Math.min((stem * (1 - s)) / 2 * 0.85, 0.2 * counterOf(word, stem) * s); };
|
|
54
64
|
/** A letter's shape set at scale s, its top-left at (x0, y0), made a touch bolder for the size it lost. */
|
|
55
|
-
function smaller(word, l, s, x0, y0) {
|
|
65
|
+
export function smaller(word, l, s, x0, y0) {
|
|
56
66
|
let shape = placedAt(l.shape, s, x0, y0);
|
|
57
67
|
const t = s < 1 ? thickenFor(word, s) : 0;
|
|
58
68
|
if (t > stemOf(word) * 0.04) shape = bolder(shape, t);
|
|
59
69
|
return shape;
|
|
60
70
|
}
|
|
61
71
|
/** Puts a letter's new shape in, moving its x with it and measuring it again. */
|
|
62
|
-
function setShape(l, shape, flag = 'tucked') {
|
|
72
|
+
export function setShape(l, shape, flag = 'tucked') {
|
|
63
73
|
const dx = boxOf(shape)[0] - boxOf(l.shape)[0];
|
|
64
74
|
l.shape = shape; l.x += dx; l.f = featuresOf(shape, l.char);
|
|
65
75
|
l.edited = true; l[flag] = true;
|
|
@@ -67,7 +77,7 @@ function setShape(l, shape, flag = 'tucked') {
|
|
|
67
77
|
|
|
68
78
|
/* ---------- Monogram: two letters set into each other until they share a stroke ---------- */
|
|
69
79
|
|
|
70
|
-
const joinable = (word, [i, j]) => pairable(word.letters[i], word.letters[j]);
|
|
80
|
+
const joinable = (word, [i, j]) => pairable(word.letters[i], word.letters[j]) && !blockedWord(word);
|
|
71
81
|
|
|
72
82
|
export const monoJoin = {
|
|
73
83
|
id: 'monoJoin', name: 'Monogram', line: 'Two letters set into each other until they share a stroke.',
|
|
@@ -75,7 +85,7 @@ export const monoJoin = {
|
|
|
75
85
|
{ key: 'share', label: 'Share', type: 'choice', options: ['stroke', 'more'], value: 'stroke' },
|
|
76
86
|
{ key: 'pair', label: 'Pair', type: 'choice', options: ['first', 'last'], value: 'first' },
|
|
77
87
|
],
|
|
78
|
-
find: (word) => (isShort(word) ? pairsOf(word).filter((pr) => joinable(word, pr)).map(([i]) => i) : []),
|
|
88
|
+
find: (word) => (isShort(word) && !script(word) ? pairsOf(word).filter((pr) => joinable(word, pr)).map(([i]) => i) : []),
|
|
79
89
|
apply(word, p) {
|
|
80
90
|
const prs = pairsOf(word).filter((pr) => joinable(word, pr));
|
|
81
91
|
if (!prs.length) return false;
|
|
@@ -235,7 +245,7 @@ const FRAME_BANNED = {
|
|
|
235
245
|
square: 'FHIMNOPUXY0',
|
|
236
246
|
round: 'EFHIMNOPQTUVXY0',
|
|
237
247
|
};
|
|
238
|
-
const banned = (shape, ch) => FRAME_BANNED[shape].includes(ch.toUpperCase());
|
|
248
|
+
export const banned = (shape, ch) => FRAME_BANNED[shape].includes(ch.toUpperCase());
|
|
239
249
|
|
|
240
250
|
/** The container round a single letter: a square, a rounded square or a disc, `pad` clear of its ink. */
|
|
241
251
|
function containerOf(l, kind, pad) {
|
|
@@ -292,7 +302,7 @@ export const frame = {
|
|
|
292
302
|
|
|
293
303
|
/* ---------- Linked: two letters overlapping, passing over and under each other ---------- */
|
|
294
304
|
|
|
295
|
-
const linkable = (word, [i, j]) => pairable(word.letters[i], word.letters[j]);
|
|
305
|
+
const linkable = (word, [i, j]) => pairable(word.letters[i], word.letters[j]) && !blockedWord(word);
|
|
296
306
|
|
|
297
307
|
export const link = {
|
|
298
308
|
id: 'link', name: 'Linked', line: 'Two letters overlapping, passing over and under each other where they cross.',
|
|
@@ -301,7 +311,7 @@ export const link = {
|
|
|
301
311
|
{ key: 'gap', label: 'Gap', type: 'range', min: 0.3, max: 0.6, step: 0.02, value: 0.4 },
|
|
302
312
|
{ key: 'front', label: 'In front', type: 'choice', options: ['alternate', 'right', 'left'], value: 'alternate' },
|
|
303
313
|
],
|
|
304
|
-
find: (word) => (isShort(word) ? pairsOf(word).filter((pr) => linkable(word, pr)).map(([i]) => i) : []),
|
|
314
|
+
find: (word) => (isShort(word) && !script(word) ? pairsOf(word).filter((pr) => linkable(word, pr)).map(([i]) => i) : []),
|
|
305
315
|
apply(word, p) {
|
|
306
316
|
const prs = pairsOf(word).filter((pr) => linkable(word, pr));
|
|
307
317
|
if (!prs.length) return false;
|
package/src/index.d.ts
CHANGED
|
@@ -57,7 +57,7 @@ export interface Typemark {
|
|
|
57
57
|
change: number;
|
|
58
58
|
/** The edits that applied (one whose feature isn't in this font or name is skipped). */
|
|
59
59
|
applied: { id: string; params: Params }[];
|
|
60
|
-
record: { name: string; font: string; fontId: string; licence: string; source: string; edits: { id: string; params: Params }[]; tracking: number; slant: number };
|
|
60
|
+
record: { name: string; font: string; fontId: string; licence: string; source: string; edits: { id: string; params: Params }[]; tracking: number; slant: number; partner?: { font: string; fontId: string; licence: string; source: string } };
|
|
61
61
|
/** From `suggest()` only. */
|
|
62
62
|
score?: number;
|
|
63
63
|
}
|
|
@@ -67,7 +67,8 @@ export function loadFont(bytes: ArrayBuffer | Uint8Array, meta?: Partial<Omit<Ty
|
|
|
67
67
|
/** A registry of fonts loaded on demand. */
|
|
68
68
|
export function registry(entries: FontEntry[]): FontRegistry;
|
|
69
69
|
/** A name set in a font with edits applied in order, tracking (share of the cap height) and slant (degrees). */
|
|
70
|
-
|
|
70
|
+
/** `partner`: a second loaded font, for `duoClash` (one initial in another face); the record then names it (`record.partner`). */
|
|
71
|
+
export function typemark(name: string, o: { font: TypeFont; edits?: EditCall[]; tracking?: number; slant?: number; partner?: TypeFont }): Typemark;
|
|
71
72
|
/** A ranked, diverse page of typemarks for a name, from loaded fonts or a registry; seeded. */
|
|
72
73
|
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
74
|
/** Every edit, by id (the general edits and the rule book's rules alike). */
|
|
@@ -77,6 +78,10 @@ export const EDITS: Record<string, Edit>;
|
|
|
77
78
|
export function isShort(word: unknown): boolean;
|
|
78
79
|
/** The short-name moves: monoJoin, inset, stack, knock, frame, link, split, echo, lines (also in `EDITS`). */
|
|
79
80
|
export const SHORT_EDITS: Edit[];
|
|
81
|
+
/** The contrast moves for two-capital names: duoBox, duoRings, duoClash, duoScale. */
|
|
82
|
+
export const DUO_EDITS: Edit[];
|
|
83
|
+
/** Initials never drawn as a monogram: other companies' monogram logos and hate codes. */
|
|
84
|
+
export const BLOCKED: string[];
|
|
80
85
|
/** A rule of the letter rule book: an edit keyed on the letters a name has. */
|
|
81
86
|
export interface Rule extends Edit {
|
|
82
87
|
/** 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, isShort, SHORT_EDITS } from './edits/index.js';
|
|
7
|
+
export { EDITS, RULES, fits, isShort, SHORT_EDITS, DUO_EDITS, BLOCKED } 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/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
|
+
duoBox: 0.97, duoRings: 0.96, duoClash: 0.95, duoScale: 0.9,
|
|
23
24
|
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,
|
|
24
25
|
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,
|
|
25
26
|
};
|
|
@@ -47,11 +48,28 @@ const HOUSE = {
|
|
|
47
48
|
split: [{ mode: 'level' }, { mode: 'upright' }, { mode: 'slant' }],
|
|
48
49
|
echo: [{ dir: 'drop', depth: 1.1 }, { dir: 'drop', depth: 0.8, gap: 0.28 }],
|
|
49
50
|
lines: [{ lines: 2, gap: 0.3 }, { lines: 3, gap: 0.26 }],
|
|
51
|
+
duoBox: [{ which: 'first', shape: 'round' }, { which: 'first', shape: 'square' }, { which: 'second', shape: 'round' }],
|
|
52
|
+
duoRings: [{ which: 'first', shape: 'disc' }, { which: 'second', shape: 'disc' }, { which: 'first', shape: 'round' }],
|
|
53
|
+
duoClash: [{ which: 'second' }, { which: 'first' }],
|
|
54
|
+
duoScale: [{ which: 'second', align: 'base' }, { which: 'second', align: 'top' }], // a small first letter reads as lowercase: by hand only
|
|
50
55
|
};
|
|
51
56
|
/** The short-name moves (./edits/short.js): a monogram resets the letters, so like a roof it is judged as a big move. */
|
|
52
57
|
/** 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
|
-
|
|
58
|
+
const PAGE_CAP = { stack: 2, echo: 3, duoBox: 5, duoRings: 5, duoClash: 5, duoScale: 4 };
|
|
59
|
+
/** The contrast moves for two-letter names (./edits/duo.js): on a two-capital name they lead the page. */
|
|
60
|
+
const DUO_IDS = ['duoBox', 'duoRings', 'duoClash', 'duoScale'];
|
|
61
|
+
const SHORT_IDS = ['monoJoin', 'inset', 'stack', 'knock', 'frame', 'link', 'split', 'echo', 'lines', ...DUO_IDS];
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* The faces a clash pairs with `font`: others of the page's fonts, of another kind (first tag), with the letters. Up to
|
|
65
|
+
* two, the kinds that contrast most first (a serif with a sans, a display with a serif), then by the seed.
|
|
66
|
+
*/
|
|
67
|
+
function partnersOf(font, list, text, rand) {
|
|
68
|
+
const kind = font.tags?.[0] || 'other', want = kind === 'serif' ? ['sans', 'display', 'condensed', 'wide'] : ['serif', 'display', 'sans', 'script'];
|
|
69
|
+
const ok = list.filter((f) => f.id !== font.id && (f.tags?.[0] || 'other') !== kind && !setWord(f, text).letters.some((l) => l.missing));
|
|
70
|
+
const rank = (f) => { const i = want.indexOf(f.tags?.[0]); return (i < 0 ? want.length : i) + rand() * 0.9; };
|
|
71
|
+
return ok.map((f) => [rank(f), f]).sort((x, y) => x[0] - y[0]).slice(0, 2).map(([, f]) => f);
|
|
72
|
+
}
|
|
55
73
|
|
|
56
74
|
/**
|
|
57
75
|
* The tracking a setting wants, as a share of the cap height, from its case and its weight (stroke over cap height):
|
|
@@ -117,7 +135,7 @@ export async function suggest(name, { fonts, count = 48, seed = 1, lock = {} } =
|
|
|
117
135
|
if (lock.fonts?.length) list = list.filter((f) => lock.fonts.includes(f.id));
|
|
118
136
|
const ids = (lock.edits?.length ? lock.edits : Object.keys(EDITS).filter((id) => !EDITS[id].alias && !HAND_ONLY.includes(id))).filter((id) => EDITS[id]);
|
|
119
137
|
const found = [];
|
|
120
|
-
const started = Date.now(), long = [...name].length > 10, short = [...name.trim()].length <= 3 && !/\s/.test(name.trim());
|
|
138
|
+
const started = Date.now(), long = [...name].length > 10, short = [...name.trim()].length <= 3 && !/\s/.test(name.trim()), pair = [...name.trim()].length === 2 && !/\s/.test(name.trim());
|
|
121
139
|
let fontsDone = 0;
|
|
122
140
|
for (const font of list) {
|
|
123
141
|
// a long name is slow to set: past the time budget, the fonts already tried make the page
|
|
@@ -141,13 +159,17 @@ export async function suggest(name, { fonts, count = 48, seed = 1, lock = {} } =
|
|
|
141
159
|
if (id === 'crossbarCut' && !isUpper) continue; // a cut through a lowercase e's bar closes it into an o
|
|
142
160
|
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
161
|
if (id === 'counter' && short && !/[oOQ0]/.test(text)) continue; // a short name's lowercase q with its counter shut is a blob
|
|
144
|
-
|
|
162
|
+
// a clash is tried with each face it pairs with; every other move with none
|
|
163
|
+
const partners = id === 'duoClash' ? partnersOf(font, list, text, rand) : [null];
|
|
164
|
+
for (const partner of partners) for (const params of long ? tries(EDITS[id]).slice(0, 1) : tries(EDITS[id])) {
|
|
145
165
|
const tracking = lock.tracking ?? (pixel ? 0 : JOINED.includes(id) ? Math.min(0.02, opticalTracking(weight, isUpper)) : opticalTracking(weight, isUpper));
|
|
146
|
-
const m = typemark(text, { font, edits: [{ id, params }], slant: lock.slant ?? 0, tracking });
|
|
166
|
+
const m = typemark(text, { font, edits: [{ id, params }], slant: lock.slant ?? 0, tracking, ...(partner ? { partner } : {}) });
|
|
147
167
|
if (m.problems.length || !m.applied.length) continue;
|
|
148
168
|
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);
|
|
149
|
-
|
|
150
|
-
|
|
169
|
+
// two capitals: the contrast moves lead, ahead of a monogram's join or inset
|
|
170
|
+
const lead = pair && DUO_IDS.includes(main.id) ? 0.12 : 0;
|
|
171
|
+
const score = 0.4 * visibleOf(m.change, big) + 0.5 * (WEIGHT[main.id] ?? 0.4) - (rule ? quiet(rule, main.params) : 0) + lead + 0.06 * rand();
|
|
172
|
+
found.push({ ...m, score, key: `${font.id}|${main.id}|${isUpper ? 'U' : 'l'}${partner ? `|${partner.id}` : ''}`, pair: `${font.id}|${main.id}` });
|
|
151
173
|
}
|
|
152
174
|
}
|
|
153
175
|
}
|
package/src/typemark.js
CHANGED
|
@@ -44,12 +44,14 @@ function baseOf(font, name, tracking) {
|
|
|
44
44
|
|
|
45
45
|
/**
|
|
46
46
|
* `name` set in `font` (from `loadFont`) with `edits` ([{ id, params }]) applied in order, `tracking` (share of the cap
|
|
47
|
-
* height) and `slant` (degrees).
|
|
47
|
+
* height) and `slant` (degrees). `partner` is a second loaded font, for `duoClash` (one initial in another face); the
|
|
48
|
+
* record then names it too (`record.partner`, with its licence). Returns `{ svg, d, pieces, box, problems, change, applied, record }`; an edit whose
|
|
48
49
|
* feature isn't in this font (or this name) is skipped and left out of `applied`.
|
|
49
50
|
*/
|
|
50
|
-
export function typemark(name, { font, edits = [], tracking = 0, slant = 0 } = {}) {
|
|
51
|
+
export function typemark(name, { font, edits = [], tracking = 0, slant = 0, partner = null } = {}) {
|
|
51
52
|
const base = baseOf(font, name, tracking);
|
|
52
53
|
const word = copy(base);
|
|
54
|
+
if (partner) word.partner = partner;
|
|
53
55
|
const applied = [];
|
|
54
56
|
for (const e of edits) {
|
|
55
57
|
const def = EDITS[e.id];
|
|
@@ -73,6 +75,6 @@ export function typemark(name, { font, edits = [], tracking = 0, slant = 0 } = {
|
|
|
73
75
|
return {
|
|
74
76
|
svg, d, box: b, problems, change, applied,
|
|
75
77
|
pieces: all.map((p) => toPath([p])),
|
|
76
|
-
record: { name, font: font.name, fontId: font.id, licence: font.licence, source: font.source, edits: applied, tracking, slant },
|
|
78
|
+
record: { name, font: font.name, fontId: font.id, licence: font.licence, source: font.source, edits: applied, tracking, slant, ...(word.partnerUsed ? { partner: { font: partner.name, fontId: partner.id, licence: partner.licence, source: partner.source } } : {}) },
|
|
77
79
|
};
|
|
78
80
|
}
|