morphico 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +71 -1
- package/dist/morphico.js +1373 -5
- package/dist/morphico.mjs +1373 -5
- package/dist/types/geometry.d.ts +10 -0
- package/dist/types/icon.d.ts +28 -0
- package/dist/types/iconSets.d.ts +11 -0
- package/dist/types/index.d.ts +11 -1
- package/dist/types/morph.d.ts +27 -0
- package/dist/types/sets/condensed.d.ts +2 -0
- package/dist/types/sets/handwritten.d.ts +2 -0
- package/dist/types/sets/round.d.ts +2 -0
- package/dist/types/sets/slim.d.ts +2 -0
- package/dist/types/sets/square.d.ts +2 -0
- package/dist/types/svg.d.ts +4 -0
- package/dist/types/text.d.ts +39 -0
- package/dist/types/types.d.ts +16 -0
- package/package.json +1 -1
- package/dist/types/sets/v1.d.ts +0 -3
- package/dist/types/sets/v2.d.ts +0 -3
- package/dist/types/sets/v3.d.ts +0 -3
package/dist/types/geometry.d.ts
CHANGED
|
@@ -4,6 +4,14 @@ export declare const line: (fromX: number, fromY: number, toX: number, toY: numb
|
|
|
4
4
|
export declare const arc: (centerX: number, centerY: number, radius: number, startAngle: number, endAngle: number) => Stroke;
|
|
5
5
|
export declare const cubic: (startX: number, startY: number, control1X: number, control1Y: number, control2X: number, control2Y: number, endX: number, endY: number) => Stroke;
|
|
6
6
|
export declare const pointOnCircle: (centerX: number, centerY: number, radius: number, angle: number) => Point;
|
|
7
|
+
/** A full ellipse as four cubic quarters, drawn counter-clockwise on screen, starting at the top. */
|
|
8
|
+
export declare const ellipse: (centerX: number, centerY: number, radiusX: number, radiusY: number) => Stroke[];
|
|
9
|
+
/**
|
|
10
|
+
* A polyline whose corners are rounded: straight lines joined by tangent circle arcs.
|
|
11
|
+
* `radii[index]` rounds the corner at `points[index]` (a single number rounds every corner; 0 = sharp corner).
|
|
12
|
+
* Straight-through points and reversals (going back along the same line) always stay sharp.
|
|
13
|
+
*/
|
|
14
|
+
export declare const roundedPolyline: (points: Point[], radii: number | number[]) => Stroke[];
|
|
7
15
|
export declare const segmentCountOf: (path: PathNumbers) => number;
|
|
8
16
|
export declare const toSegments: (path: PathNumbers) => CubicSegment[];
|
|
9
17
|
export declare const fromSegments: (segments: CubicSegment[]) => PathNumbers;
|
|
@@ -12,6 +20,8 @@ export declare const reorderSegments: (path: PathNumbers, { startSegment, revers
|
|
|
12
20
|
export declare const interpolate: (from: PathNumbers, to: PathNumbers, progress: number) => PathNumbers;
|
|
13
21
|
/** SVG `d` attribute: `M x y` followed by one `C` per segment. */
|
|
14
22
|
export declare const toPathData: (path: PathNumbers) => string;
|
|
23
|
+
/** Shrinks (factor < 1) or grows the whole shape around the icon center (12, 12). */
|
|
24
|
+
export declare const scaleAroundCenter: (path: PathNumbers, factor: number) => PathNumbers;
|
|
15
25
|
/** Rotates the whole shape around the icon center (12, 12). */
|
|
16
26
|
export declare const rotateAroundCenter: (path: PathNumbers, angle: number) => PathNumbers;
|
|
17
27
|
/**
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { IconSetName } from './iconSets.js';
|
|
2
|
+
import type { MorphOptions, MorphResult } from './morph.js';
|
|
3
|
+
import type { IconSet } from './types.js';
|
|
4
|
+
export interface IconOptions extends MorphOptions {
|
|
5
|
+
/** A built-in set by name (default `'round'`) or a set object. */
|
|
6
|
+
set?: IconSetName | IconSet;
|
|
7
|
+
/** The state shown first (default: empty, `' '`). */
|
|
8
|
+
state?: string;
|
|
9
|
+
/** CSS width and height of the icon (default `'1em'`: it follows the font size). */
|
|
10
|
+
size?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface ChangeOptions extends MorphOptions {
|
|
13
|
+
/** Called when the morph ends, with the same result the promise resolves to. */
|
|
14
|
+
onEnd?: (result: MorphResult) => void;
|
|
15
|
+
}
|
|
16
|
+
export interface Icon {
|
|
17
|
+
/** The state shown, or being morphed to. */
|
|
18
|
+
readonly state: string;
|
|
19
|
+
/**
|
|
20
|
+
* Morphs to `state` (`'0'`…`'9'`, `'-'`, or `' '` for empty). The promise resolves when the morph ends;
|
|
21
|
+
* an interrupted morph resolves with `interrupted: true`. Without animation when the user prefers reduced motion.
|
|
22
|
+
*/
|
|
23
|
+
to(state: string, options?: ChangeOptions): Promise<MorphResult>;
|
|
24
|
+
/** Stops any morph and removes the icon from the page. */
|
|
25
|
+
destroy(): void;
|
|
26
|
+
}
|
|
27
|
+
/** Adds a morphing icon (an <svg>) to `element`. */
|
|
28
|
+
export declare const icon: (element: Element, options?: IconOptions) => Icon;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { IconSet } from './types.js';
|
|
2
|
+
export declare const iconSets: {
|
|
3
|
+
round: IconSet;
|
|
4
|
+
square: IconSet;
|
|
5
|
+
condensed: IconSet;
|
|
6
|
+
slim: IconSet;
|
|
7
|
+
handwritten: IconSet;
|
|
8
|
+
};
|
|
9
|
+
export type IconSetName = keyof typeof iconSets;
|
|
10
|
+
/** A set given by name or as a set object. */
|
|
11
|
+
export declare const resolveIconSet: (set?: IconSetName | IconSet) => IconSet;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,2 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
export { easings } from './engine.js';
|
|
2
|
+
export { icon } from './icon.js';
|
|
3
|
+
export { iconSets } from './iconSets.js';
|
|
4
|
+
export { text } from './text.js';
|
|
5
|
+
export type { Easing } from './engine.js';
|
|
6
|
+
export type { ChangeOptions, Icon, IconOptions } from './icon.js';
|
|
7
|
+
export type { IconSetName } from './iconSets.js';
|
|
8
|
+
export type { EasingName, MorphOptions, MorphResult } from './morph.js';
|
|
9
|
+
export type { SetOptions, Text, TextOptions, TextResult } from './text.js';
|
|
10
|
+
export type { IconSet, TextLayout } from './types.js';
|
|
11
|
+
/** Package version, e.g. "0.1.0" (tools/build.ts replaces 'dev'). */
|
|
2
12
|
export declare const version: string;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { easings } from './engine.js';
|
|
2
|
+
import type { Easing } from './engine.js';
|
|
3
|
+
import type { IconSet } from './types.js';
|
|
4
|
+
export type EasingName = keyof typeof easings;
|
|
5
|
+
export interface MorphOptions {
|
|
6
|
+
/** Length of a morph in milliseconds (default 400). */
|
|
7
|
+
duration?: number;
|
|
8
|
+
/** An easing name or your own function `(progress) => easedProgress` (default `'easeInOutCubic'`). */
|
|
9
|
+
easing?: EasingName | Easing;
|
|
10
|
+
}
|
|
11
|
+
export interface MorphResult {
|
|
12
|
+
/** The state the morph was heading to. */
|
|
13
|
+
state: string;
|
|
14
|
+
/** `true` when a newer morph (or `destroy()`) took over before this one finished. */
|
|
15
|
+
interrupted: boolean;
|
|
16
|
+
}
|
|
17
|
+
/** The empty state: nothing is drawn. Shapes grow out of it and shrink into it while fading. */
|
|
18
|
+
export declare const EMPTY_STATE = " ";
|
|
19
|
+
export declare const hasState: (iconSet: IconSet, state: string) => boolean;
|
|
20
|
+
export interface MorphingPath {
|
|
21
|
+
/** The state shown, or being morphed to. */
|
|
22
|
+
readonly state: string;
|
|
23
|
+
morphTo(state: string, options?: MorphOptions): Promise<MorphResult>;
|
|
24
|
+
/** Stops a running morph where it is; its promise resolves as interrupted. */
|
|
25
|
+
stop(): void;
|
|
26
|
+
}
|
|
27
|
+
export declare const createMorphingPath: (pathElement: SVGPathElement, iconSet: IconSet, initialState: string) => MorphingPath;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { IconSet } from './types.js';
|
|
2
|
+
export declare const createSvgElement: <TagName extends keyof SVGElementTagNameMap>(tagName: TagName, attributes?: Record<string, string | number>) => SVGElementTagNameMap[TagName];
|
|
3
|
+
/** An <svg> drawn in the set's stroke style, coloured by the CSS `color` (currentColor). */
|
|
4
|
+
export declare const createIconSvg: (iconSet: IconSet, viewBox: string) => SVGSVGElement;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { IconSetName } from './iconSets.js';
|
|
2
|
+
import type { MorphOptions } from './morph.js';
|
|
3
|
+
import type { IconSet } from './types.js';
|
|
4
|
+
export interface TextOptions extends MorphOptions {
|
|
5
|
+
/** A built-in set by name (default `'round'`) or a set object. */
|
|
6
|
+
set?: IconSetName | IconSet;
|
|
7
|
+
/** The text shown first (default: empty). */
|
|
8
|
+
value?: string;
|
|
9
|
+
/** CSS height of the line (default `'1em'`: it follows the font size). */
|
|
10
|
+
size?: string;
|
|
11
|
+
/** Width of a digit cell in grid units, where a digit is 16 high (default: the set's own). */
|
|
12
|
+
cellWidth?: number;
|
|
13
|
+
/** Gap between cells in grid units (default: the set's own). The CSS variable `--morphico-spacing` overrides it. */
|
|
14
|
+
spacing?: number;
|
|
15
|
+
}
|
|
16
|
+
export interface TextResult {
|
|
17
|
+
/** The text the change was heading to. */
|
|
18
|
+
value: string;
|
|
19
|
+
/** `true` when a newer `set()` (or `destroy()`) took over before every digit finished. */
|
|
20
|
+
interrupted: boolean;
|
|
21
|
+
}
|
|
22
|
+
export interface SetOptions extends MorphOptions {
|
|
23
|
+
/** Called when every changed digit has finished, with the same result the promise resolves to. */
|
|
24
|
+
onEnd?: (result: TextResult) => void;
|
|
25
|
+
}
|
|
26
|
+
export interface Text {
|
|
27
|
+
/** The text shown, or being morphed to (after unsupported characters were removed). */
|
|
28
|
+
readonly value: string;
|
|
29
|
+
/**
|
|
30
|
+
* Shows `value`. Unsupported characters are removed first. If the length and the places of `:` `.` `,` `/`
|
|
31
|
+
* stay the same, only the changed digits morph; otherwise the line is rebuilt without animation
|
|
32
|
+
* (pad with spaces, e.g. `String(count).padStart(3, ' ')`, to keep counters morphing).
|
|
33
|
+
*/
|
|
34
|
+
set(value: string, options?: SetOptions): Promise<TextResult>;
|
|
35
|
+
/** Stops all morphs and removes the line from the page. */
|
|
36
|
+
destroy(): void;
|
|
37
|
+
}
|
|
38
|
+
/** Adds a line of morphing characters (a <span> of <svg> cells) to `element`. */
|
|
39
|
+
export declare const text: (element: Element, options?: TextOptions) => Text;
|
package/dist/types/types.d.ts
CHANGED
|
@@ -48,10 +48,25 @@ export interface PairLayout {
|
|
|
48
48
|
/** Rotate by this many degrees around the icon center (only for shapes that look the same turned). */
|
|
49
49
|
rotation?: number;
|
|
50
50
|
}
|
|
51
|
+
/** How a set's characters sit in the narrow cells of `text()`. Numbers are in grid units (digits are 16 high). */
|
|
52
|
+
export interface TextLayout {
|
|
53
|
+
/** Default width of a digit cell. */
|
|
54
|
+
cellWidth: number;
|
|
55
|
+
/** Default gap between two cells. */
|
|
56
|
+
spacing: number;
|
|
57
|
+
/** y of the line the digits stand on (stroke centre); `.` and `,` sit there and `/` spans to `24 - baselineY`. */
|
|
58
|
+
baselineY: number;
|
|
59
|
+
/** y of the two dots of `:` (the centres of the 8's loops). */
|
|
60
|
+
colonDotsY: [top: number, bottom: number];
|
|
61
|
+
}
|
|
51
62
|
export interface IconSet {
|
|
52
63
|
/** Cubic segments per shape. The state that needs the most segments decides it. */
|
|
53
64
|
segmentCount: number;
|
|
54
65
|
strokeWidth: number;
|
|
66
|
+
/** SVG `stroke-linecap`: flat (`butt`) or rounded line ends. */
|
|
67
|
+
lineCap: 'butt' | 'round' | 'square';
|
|
68
|
+
/** SVG `stroke-linejoin`: sharp (`miter`) or rounded corners. */
|
|
69
|
+
lineJoin: 'miter' | 'round' | 'bevel';
|
|
55
70
|
/** The strokes of each state, as one continuous line in drawing order. */
|
|
56
71
|
strokes: Record<string, Stroke[]>;
|
|
57
72
|
/** Alternative tracings: the same picture (with round joins) drawn in a different order. */
|
|
@@ -60,4 +75,5 @@ export interface IconSet {
|
|
|
60
75
|
pairLayouts: Record<string, Record<string, PairLayout>>;
|
|
61
76
|
/** `spins[fromState][toState]`: degrees to rotate around the icon center while morphing. */
|
|
62
77
|
spins: Record<string, Record<string, number>>;
|
|
78
|
+
textLayout: TextLayout;
|
|
63
79
|
}
|
package/package.json
CHANGED
package/dist/types/sets/v1.d.ts
DELETED
package/dist/types/sets/v2.d.ts
DELETED
package/dist/types/sets/v3.d.ts
DELETED