morphico 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/README.md +99 -32
  2. package/dist/esm/all.js +1 -1
  3. package/dist/esm/clip.js +8 -6
  4. package/dist/esm/engine.js +1 -1
  5. package/dist/esm/face.js +2 -3
  6. package/dist/esm/geometry.js +1 -1
  7. package/dist/esm/icon.js +1 -1
  8. package/dist/esm/index.js +3 -2
  9. package/dist/esm/morph.js +2 -2
  10. package/dist/esm/roundness.js +1 -1
  11. package/dist/esm/sets/battery.js +1 -1
  12. package/dist/esm/sets/bell.js +1 -1
  13. package/dist/esm/sets/characters.js +42 -21
  14. package/dist/esm/sets/check-mark.js +1 -1
  15. package/dist/esm/sets/checkbox.js +1 -1
  16. package/dist/esm/sets/chevron.js +1 -1
  17. package/dist/esm/sets/condensed.js +4 -3
  18. package/dist/esm/sets/copy.js +1 -1
  19. package/dist/esm/sets/eye.js +1 -1
  20. package/dist/esm/sets/faces.js +1 -1
  21. package/dist/esm/sets/folder.js +1 -1
  22. package/dist/esm/sets/handwritten.js +4 -3
  23. package/dist/esm/sets/lock.js +1 -1
  24. package/dist/esm/sets/lucide.js +1 -1
  25. package/dist/esm/sets/media.js +1 -1
  26. package/dist/esm/sets/menu.js +1 -1
  27. package/dist/esm/sets/mic.js +1 -1
  28. package/dist/esm/sets/radio.js +1 -1
  29. package/dist/esm/sets/round.js +4 -3
  30. package/dist/esm/sets/shapes.js +7 -1
  31. package/dist/esm/sets/slim.js +4 -3
  32. package/dist/esm/sets/square.js +4 -3
  33. package/dist/esm/sets/symbols.js +154 -0
  34. package/dist/esm/sets/theme.js +1 -1
  35. package/dist/esm/sets/toggle.js +1 -1
  36. package/dist/esm/sets/volume.js +1 -1
  37. package/dist/esm/sets/weather.js +1 -1
  38. package/dist/esm/sets/wifi.js +1 -1
  39. package/dist/esm/svg.js +1 -1
  40. package/dist/esm/text.js +6 -5
  41. package/dist/esm/types.js +1 -1
  42. package/dist/morphico.js +236 -46
  43. package/dist/types/clip.d.ts +5 -8
  44. package/dist/types/icon.d.ts +2 -2
  45. package/dist/types/index.d.ts +4 -3
  46. package/dist/types/morph.d.ts +3 -3
  47. package/dist/types/sets/characters.d.ts +3 -2
  48. package/dist/types/sets/shapes.d.ts +4 -1
  49. package/dist/types/sets/symbols.d.ts +38 -0
  50. package/dist/types/text.d.ts +3 -9
  51. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- /*! morphico v0.5.0 | code: MIT License, Copyright (c) 2026 Raycho Ivanov (see LICENSE)
1
+ /*! morphico v0.6.0 | code: MIT License, Copyright (c) 2026 Raycho Ivanov (see LICENSE)
2
2
  * Icons based on Lucide (https://lucide.dev), some of them from Feather (https://feathericons.com):
3
3
  *
4
4
  * ISC License
@@ -50,6 +50,12 @@ const GRID_CENTER = 12;
50
50
  const SAMPLES_PER_STROKE = 48;
51
51
  /** Enough for the shape that needs the most (puzzle: 24 strokes, its knobs ≈ 40 segments); the rest spreads by length. */
52
52
  const SEGMENT_COUNT = 48;
53
+ /** The names of clip()'s shapes (TypeScript checks the outlines below have exactly these). */
54
+ export const clipShapeNames = [
55
+ 'circle', 'ellipse', 'heart', 'sparkle', 'astroid', 'bookmark', 'shield', 'moon', 'tag', 'square', 'badge', 'triangle',
56
+ 'droplet', 'pentagon', 'hexagon', 'octagon', 'squircle', 'star', 'rectangle-horizontal', 'message-circle',
57
+ 'message-square', 'cloud', 'puzzle', 'club',
58
+ ];
53
59
  /** The shapes as Lucide draws them (Lucide coordinates); the set's states are made from these. */
54
60
  export const lucideShapeOutlines = {
55
61
  circle: [arc(12, 12, 10, -90, 270)],
@@ -1,4 +1,4 @@
1
- /*! morphico v0.5.0 | MIT License, Copyright (c) 2026 Raycho Ivanov (see LICENSE) */
1
+ /*! morphico v0.6.0 | MIT License, Copyright (c) 2026 Raycho Ivanov (see LICENSE) */
2
2
  // Digit set "slim": thin, tall, round digits, drafted from the reference images in icons/slim/
3
3
  // (the set format is described in ../types.ts).
4
4
  //
@@ -35,7 +35,8 @@ const SIX = [
35
35
  topArc(SIX_HOOK_ANGLE, -180),
36
36
  ...roundedPolyline([[8, 8], [8, 20], [16, 20], [16, SIX_LOOP_TOP], [8, SIX_LOOP_TOP], [8, SIX_LOOP_TOP + RADIUS]], [0, RADIUS, RADIUS, RADIUS, RADIUS, 0]),
37
37
  ];
38
- // '-' '/' '.' ',' ':' are added by withTextCharacters (characters.ts)
38
+ // '-' '/' '.' ',' ':' and the symbols '+' '%' '$' '€' '£' (in this set's box and corners) are added by
39
+ // withTextCharacters (characters.ts, symbols.ts)
39
40
  export const digitsSlim = withTextCharacters({
40
41
  segmentCount: 16,
41
42
  strokeWidth: 6 / 5.5,
@@ -145,4 +146,4 @@ export const digitsSlim = withTextCharacters({
145
146
  // 9 is exactly 6 turned 180°; 2 → 6 also turns (it is 2 → 9 in the turning frame)
146
147
  spins: { 2: { 6: 180 }, 6: { 9: 180, 2: -180 }, 9: { 6: -180 } },
147
148
  textLayout: { cellWidth: 9.5, spacing: 4, baselineY: 20, colonDotsY: [8, 16] },
148
- });
149
+ }, { left: 8, right: 16, top: 4, bottom: 20, corners: 'round' });
@@ -1,4 +1,4 @@
1
- /*! morphico v0.5.0 | MIT License, Copyright (c) 2026 Raycho Ivanov (see LICENSE) */
1
+ /*! morphico v0.6.0 | MIT License, Copyright (c) 2026 Raycho Ivanov (see LICENSE) */
2
2
  // Digit set "square": rounded-square "techno" digits, drafted from the reference images in icons/square/
3
3
  // (the set format is described in ../types.ts).
4
4
  //
@@ -28,7 +28,8 @@ const EIGHT_RADIUS = 6;
28
28
  // the 6: hook from the top right, round the left side, then the closed bottom loop back to the left side
29
29
  const SIX_POINTS = [[15, 2], [2, 2], [2, 26], [19, 26], [19, 12], [2, 12]];
30
30
  const SIX_RADII = [0, SIX_RADIUS, SIX_RADIUS, SIX_RADIUS, SIX_RADIUS, 0];
31
- // '-' '/' '.' ',' ':' are added by withTextCharacters (characters.ts)
31
+ // '-' '/' '.' ',' ':' and the symbols '+' '%' '$' '€' '£' (in this set's box and corners) are added by
32
+ // withTextCharacters (characters.ts, symbols.ts)
32
33
  export const digitsSquare = withTextCharacters({
33
34
  segmentCount: 20,
34
35
  strokeWidth: STROKE_WIDTH,
@@ -146,4 +147,4 @@ export const digitsSquare = withTextCharacters({
146
147
  },
147
148
  spins: { 6: { 9: 180 }, 9: { 6: -180 } },
148
149
  textLayout: { cellWidth: 13.5, spacing: 4, baselineY: 20, colonDotsY: [8, 16] },
149
- });
150
+ }, { left: 6.33, right: 17.67, top: 4, bottom: 20, corners: 4 });
@@ -0,0 +1,154 @@
1
+ /*! morphico v0.6.0 | MIT License, Copyright (c) 2026 Raycho Ivanov (see LICENSE) */
2
+ // The symbols of the digit sets: `+` `%` `$` `€` `£` (for prices and discounts: `€39.99`, `-20%`). No reference
3
+ // images: drawn from each set's own box (where its digits stand) and corner style, so they match the digits — round
4
+ // sets (round, slim, handwritten) get elliptical bowls like their 0, 3 and 8; boxy sets (square, condensed) rounded
5
+ // corners with the set's radius. Every symbol is at most three pieces: one continuous line each (see characters.ts).
6
+ import { cubic, line, roundedPolyline } from '../geometry.js';
7
+ /**
8
+ * How symbol pairs lay out their pieces (first, second, third piece), from the user's ratings (2026-11-03; pairs rated
9
+ * good use the default and are left out):
10
+ * - `+` → `€` / `£`: the upright bar bends into the C / the £'s line, the cross bar becomes the bar (tracings swap
11
+ * which of the two pieces draws which bar).
12
+ * - `%` → `$` / `€` / `£`: the slash runs from the top right, where S, C and the £'s hook start; the rings are pressed
13
+ * flat onto the bars (`flatten`, as digits onto `-`); the lower ring, where `$` / `£` have no bar, is erased like a pen
14
+ * in the first 60 % (`draw`, as the weather's rays) instead of shrinking into a dot.
15
+ * - `£` ↔ `€`: the £'s base is drawn out to the left first, ending at the right like the C (with `$` it ends at the
16
+ * left like the S).
17
+ * - `£` / `+` → `€`: both bars of `€` come out of the one bar of `£` / `+` (the crossbar / the cross bar), which
18
+ * traces its third piece as a hidden copy of that bar (user: the two lines must merge into one; growing out of the
19
+ * resting point in the middle showed as a blob, drawing the lower bar in like a pen didn't merge).
20
+ */
21
+ export const symbolPairLayouts = [
22
+ {
23
+ '+': { '€': { tracing: 'plus-upright' }, '£': { tracing: 'plus-upright' } },
24
+ '%': { $: { reversed: true }, '€': { reversed: true }, '£': { reversed: true } },
25
+ '£': { '€': { tracing: 'pound-base-left-first' } },
26
+ },
27
+ {
28
+ '+': { '€': { tracing: 'plus-across' }, '£': { tracing: 'plus-across' } },
29
+ $: { '%': { flatten: true } },
30
+ '€': { '%': { flatten: true } },
31
+ '£': { '%': { flatten: true } },
32
+ },
33
+ {
34
+ '+': { '€': { tracing: 'plus-across' } },
35
+ $: { '%': { draw: 0.6 } },
36
+ '€': { '%': { flatten: true } },
37
+ '£': { '%': { draw: 0.6 }, '€': { tracing: 'pound-crossbar' } },
38
+ },
39
+ ];
40
+ const DEGREE = Math.PI / 180;
41
+ /**
42
+ * Part of an ellipse as cubics of at most 90° each. Angles in degrees (0 = right, 90 = down: y points down);
43
+ * `endAngle > startAngle` runs clockwise on screen. Each cubic matches the ellipse at both ends (an exact circle's
44
+ * quarter handles, stretched).
45
+ */
46
+ const ellipticArc = (centerX, centerY, radiusX, radiusY, startAngle, endAngle) => {
47
+ const count = Math.max(1, Math.ceil(Math.abs(endAngle - startAngle) / 90 - 1e-9));
48
+ const step = (endAngle - startAngle) / count;
49
+ const handle = (4 / 3) * Math.tan((step * DEGREE) / 4);
50
+ const pointAt = (angle) => [centerX + radiusX * Math.cos(angle * DEGREE), centerY + radiusY * Math.sin(angle * DEGREE)];
51
+ const directionAt = (angle) => [-radiusX * Math.sin(angle * DEGREE), radiusY * Math.cos(angle * DEGREE)];
52
+ return Array.from({ length: count }, (_, index) => {
53
+ const from = startAngle + step * index;
54
+ const to = from + step;
55
+ const [startX, startY] = pointAt(from);
56
+ const [endX, endY] = pointAt(to);
57
+ const [startDirectionX, startDirectionY] = directionAt(from);
58
+ const [endDirectionX, endDirectionY] = directionAt(to);
59
+ return cubic(startX, startY, startX + handle * startDirectionX, startY + handle * startDirectionY, endX - handle * endDirectionX, endY - handle * endDirectionY, endX, endY);
60
+ });
61
+ };
62
+ /** A small closed loop (the rings of `%`): a circle, or a rounded box for boxy sets — clockwise from the top. */
63
+ const ring = (style, centerX, centerY, radius) => {
64
+ if (style.corners === 'round')
65
+ return ellipticArc(centerX, centerY, radius, radius, -90, 270);
66
+ const corner = Math.min(style.corners, radius);
67
+ const [left, right, top, bottom] = [centerX - radius, centerX + radius, centerY - radius, centerY + radius];
68
+ return roundedPolyline([[centerX, top], [right, top], [right, bottom], [left, bottom], [left, top], [centerX, top]], [0, corner, corner, corner, corner, 0]);
69
+ };
70
+ /** `+` `%` `$` `€` `£` drawn in a set's style. */
71
+ export const symbolStrokes = (style) => {
72
+ const { left, right, top, bottom } = style;
73
+ const width = right - left;
74
+ const height = bottom - top;
75
+ const centerX = (left + right) / 2;
76
+ const middleY = (top + bottom) / 2;
77
+ const round = style.corners === 'round';
78
+ /** Corner radius of a boxy set, never more than a box of that size allows. */
79
+ const cornerFor = (boxWidth, boxHeight) => Math.min(round ? 0 : style.corners, boxWidth / 2, boxHeight / 2);
80
+ // + : the same bar as `-` (so `-` ↔ `+` only stands one bar up), crossed by an upright one of the same length
81
+ const plusAcross = line(9.5, 12, 14.5, 12);
82
+ const plusUpright = line(12, 9.5, 12, 14.5);
83
+ const plus = [[plusAcross], [plusUpright]];
84
+ // % : slash from the bottom left to the top right, a ring at the top left and one at the bottom right
85
+ const ringRadius = Math.min(width * 0.2, height * 0.13);
86
+ const percent = [
87
+ [line(left + width * 0.08, bottom, right - width * 0.08, top)],
88
+ ring(style, left + ringRadius, top + ringRadius + height * 0.04, ringRadius),
89
+ ring(style, right - ringRadius, bottom - ringRadius - height * 0.04, ringRadius),
90
+ ];
91
+ // $ : an S as tall as the digits, the bar through it a little longer
92
+ const sLeft = left + width * 0.06;
93
+ const sRight = right - width * 0.06;
94
+ const sWidth = sRight - sLeft;
95
+ let dollarS;
96
+ if (round) {
97
+ const quarterHeight = height / 4;
98
+ dollarS = [
99
+ ...ellipticArc(centerX, top + quarterHeight, sWidth / 2, quarterHeight, -30, -270),
100
+ ...ellipticArc(centerX, bottom - quarterHeight, sWidth / 2, quarterHeight, 270, 510),
101
+ ];
102
+ }
103
+ else {
104
+ const corner = cornerFor(sWidth, height / 2);
105
+ const hook = Math.max(corner, height * 0.15);
106
+ dollarS = roundedPolyline([[sRight, top + hook], [sRight, top], [sLeft, top], [sLeft, middleY], [sRight, middleY], [sRight, bottom], [sLeft, bottom], [sLeft, bottom - hook]], [0, corner, corner, corner, corner, corner, corner, 0]);
107
+ }
108
+ const dollar = [dollarS, [line(centerX, top - 1.2, centerX, bottom + 1.2)]];
109
+ // € : a C opened to the right (moved right a little), two bars sticking out of its left side
110
+ const cLeft = left + width * 0.14;
111
+ let euroC;
112
+ if (round) {
113
+ const radiusX = (right - cLeft) / 2;
114
+ euroC = ellipticArc(cLeft + radiusX, middleY, radiusX, height / 2, -48, -312);
115
+ }
116
+ else {
117
+ const corner = cornerFor(right - cLeft, height);
118
+ euroC = roundedPolyline([[right, top], [cLeft, top], [cLeft, bottom], [right, bottom]], [0, corner, corner, 0]);
119
+ }
120
+ const barGap = height * 0.12;
121
+ const barEnd = centerX + width * 0.12;
122
+ const euro = [
123
+ euroC,
124
+ [line(left - width * 0.06, middleY - barGap, barEnd, middleY - barGap)],
125
+ [line(left - width * 0.06, middleY + barGap, barEnd, middleY + barGap)],
126
+ ];
127
+ // £ : a hook at the top right running into the stem, a base line out to both sides (drawn out to the right and back,
128
+ // the way the S of $ ends, so they morph into each other without twisting; with € the other way round), a crossbar
129
+ const stemX = left + width * 0.3;
130
+ const hookRight = right - width * 0.08;
131
+ const poundLineWithBase = (firstSide, secondSide) => {
132
+ if (round) {
133
+ const hookRadius = (hookRight - stemX) / 2;
134
+ return [
135
+ ...ellipticArc(stemX + hookRadius, top + hookRadius, hookRadius, hookRadius, 20, -180),
136
+ line(stemX, top + hookRadius, stemX, bottom),
137
+ line(stemX, bottom, firstSide, bottom),
138
+ line(firstSide, bottom, secondSide, bottom),
139
+ ];
140
+ }
141
+ const corner = cornerFor(hookRight - stemX, height / 2);
142
+ const hook = Math.max(corner, height * 0.15);
143
+ return roundedPolyline([[hookRight, top + hook], [hookRight, top], [stemX, top], [stemX, bottom], [firstSide, bottom], [secondSide, bottom]], [0, corner, corner, 0, 0, 0]);
144
+ };
145
+ const poundLine = poundLineWithBase(right, left);
146
+ const poundCrossbar = line(left + width * 0.05, middleY + height * 0.04, stemX + width * 0.32, middleY + height * 0.04);
147
+ const pound = [poundLine, [poundCrossbar]];
148
+ return {
149
+ pieces: { '+': plus, '%': percent, $: dollar, '€': euro, '£': pound },
150
+ firstPieceTracings: { 'plus-upright': [plusUpright], 'pound-base-left-first': poundLineWithBase(left, right) },
151
+ secondPieceTracings: { 'plus-across': [plusAcross] },
152
+ thirdPieceTracings: { 'plus-across': [plusAcross], 'pound-crossbar': [poundCrossbar] },
153
+ };
154
+ };
@@ -1,4 +1,4 @@
1
- /*! morphico v0.5.0 | code: MIT License, Copyright (c) 2026 Raycho Ivanov (see LICENSE)
1
+ /*! morphico v0.6.0 | code: MIT License, Copyright (c) 2026 Raycho Ivanov (see LICENSE)
2
2
  * Icons based on Lucide (https://lucide.dev), some of them from Feather (https://feathericons.com):
3
3
  *
4
4
  * ISC License
@@ -1,4 +1,4 @@
1
- /*! morphico v0.5.0 | code: MIT License, Copyright (c) 2026 Raycho Ivanov (see LICENSE)
1
+ /*! morphico v0.6.0 | code: MIT License, Copyright (c) 2026 Raycho Ivanov (see LICENSE)
2
2
  * Icons based on Lucide (https://lucide.dev), some of them from Feather (https://feathericons.com):
3
3
  *
4
4
  * ISC License
@@ -1,4 +1,4 @@
1
- /*! morphico v0.5.0 | code: MIT License, Copyright (c) 2026 Raycho Ivanov (see LICENSE)
1
+ /*! morphico v0.6.0 | code: MIT License, Copyright (c) 2026 Raycho Ivanov (see LICENSE)
2
2
  * Icons based on Lucide (https://lucide.dev), some of them from Feather (https://feathericons.com):
3
3
  *
4
4
  * ISC License
@@ -1,4 +1,4 @@
1
- /*! morphico v0.5.0 | code: MIT License, Copyright (c) 2026 Raycho Ivanov (see LICENSE)
1
+ /*! morphico v0.6.0 | code: MIT License, Copyright (c) 2026 Raycho Ivanov (see LICENSE)
2
2
  * Icons based on Lucide (https://lucide.dev), some of them from Feather (https://feathericons.com):
3
3
  *
4
4
  * ISC License
@@ -1,4 +1,4 @@
1
- /*! morphico v0.5.0 | code: MIT License, Copyright (c) 2026 Raycho Ivanov (see LICENSE)
1
+ /*! morphico v0.6.0 | code: MIT License, Copyright (c) 2026 Raycho Ivanov (see LICENSE)
2
2
  * Icons based on Lucide (https://lucide.dev), some of them from Feather (https://feathericons.com):
3
3
  *
4
4
  * ISC License
package/dist/esm/svg.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! morphico v0.5.0 | MIT License, Copyright (c) 2026 Raycho Ivanov (see LICENSE) */
1
+ /*! morphico v0.6.0 | MIT License, Copyright (c) 2026 Raycho Ivanov (see LICENSE) */
2
2
  const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
3
3
  /** A CSS length as stroke width: drawn at that width on screen instead of scaling with the icon. */
4
4
  export const hasFixedStrokeWidth = (style) => typeof style.strokeWidth === 'string';
package/dist/esm/text.js CHANGED
@@ -1,11 +1,12 @@
1
- /*! morphico v0.5.0 | MIT License, Copyright (c) 2026 Raycho Ivanov (see LICENSE) */
1
+ /*! morphico v0.6.0 | MIT License, Copyright (c) 2026 Raycho Ivanov (see LICENSE) */
2
2
  // Layer 2: a line of characters (clock, counter, date) in narrow cells; changed digits morph.
3
3
  // Every character reuses the 24×24 icon drawing; only the viewBox is narrowed to its cell.
4
4
  import { createMorphingPath, hasState } from './morph.js';
5
5
  import { checkedIconSet, checkedInit } from './roundness.js';
6
6
  import { createIconSvg, createStrokedElement } from './svg.js';
7
- /** Characters `text()` can show: digits, space, `-` `:` `.` `,` `/` — all of them morph. Anything else is removed. */
8
- const UNSUPPORTED_CHARACTERS = /[^0-9 :.,\/-]/g;
7
+ /** Characters `text()` can show: digits, space, `-` `:` `.` `,` `/`, `+` `%` `$` `€` `£` — all of them morph. Anything
8
+ * else is removed. */
9
+ const UNSUPPORTED_CHARACTERS = /[^0-9 :.,\/+%$€£-]/g;
9
10
  /** Vertical part of the 24×24 grid shown in a cell: y 3…21 holds every digit including its stroke. */
10
11
  const CELL_TOP = 3;
11
12
  const CELL_HEIGHT = 18;
@@ -66,11 +67,11 @@ export const text = (element, init, options) => {
66
67
  if (sameLayout) {
67
68
  const morphs = cells.map((cell, index) => cell.morphingPath.morphTo(characters[index], { ...defaultMorphOptions, ...morphOptions }));
68
69
  const finishedValue = value;
69
- change = Promise.all(morphs).then((results) => ({ value: finishedValue, interrupted: results.some((result) => result.interrupted) }));
70
+ change = Promise.all(morphs).then((results) => ({ state: finishedValue, interrupted: results.some((result) => result.interrupted) }));
70
71
  }
71
72
  else {
72
73
  rebuild(characters);
73
- change = Promise.resolve({ value, interrupted: false });
74
+ change = Promise.resolve({ state: value, interrupted: false });
74
75
  }
75
76
  if (onEnd)
76
77
  change.then(onEnd);
package/dist/esm/types.js CHANGED
@@ -1,3 +1,3 @@
1
- /*! morphico v0.5.0 | MIT License, Copyright (c) 2026 Raycho Ivanov (see LICENSE) */
1
+ /*! morphico v0.6.0 | MIT License, Copyright (c) 2026 Raycho Ivanov (see LICENSE) */
2
2
  // Shared types. Coordinates live in the 24×24 icon grid; y points down.
3
3
  export {};