morphico 0.3.0 → 0.4.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 +43 -3
- package/dist/morphico.js +669 -30
- package/dist/morphico.mjs +669 -30
- package/dist/types/clip.d.ts +2 -0
- package/dist/types/face.d.ts +31 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/sets/faces.d.ts +25 -0
- package/package.json +1 -1
package/dist/types/clip.d.ts
CHANGED
|
@@ -23,6 +23,8 @@ export interface ClipChanges {
|
|
|
23
23
|
roundness?: number;
|
|
24
24
|
/** `false` (default) = the whole shape shows; an outline = only a band along its edge (not animated). */
|
|
25
25
|
outline?: false | ClipOutline;
|
|
26
|
+
/** `true` = the other way round: the shape (or band) is a hole, the rest of the element shows (not animated). */
|
|
27
|
+
inverted?: boolean;
|
|
26
28
|
}
|
|
27
29
|
export interface ClipOptions extends ClipChanges, MorphOptions {
|
|
28
30
|
/** The shape set (default: the built-in shapes, based on Lucide). */
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { MorphOptions, MorphResult } from './morph.js';
|
|
2
|
+
import type { FaceExpression } from './sets/faces.js';
|
|
3
|
+
export interface FaceOptions extends MorphOptions {
|
|
4
|
+
/** The expression shown first (default `'normal'`). */
|
|
5
|
+
state?: FaceExpression;
|
|
6
|
+
/** Color of the pupils (default `'white'`). Brows, eyes and mouth take the CSS `color`. */
|
|
7
|
+
pupilColor?: string;
|
|
8
|
+
/** Blink by itself every few seconds (default `true`). Off when the user prefers reduced motion. */
|
|
9
|
+
blink?: boolean;
|
|
10
|
+
/** CSS width and height of the face (default `'100%'`: it fills the element). */
|
|
11
|
+
size?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface FaceChangeOptions extends MorphOptions {
|
|
14
|
+
/** Called when the morph ends, with the same result the promise resolves to. */
|
|
15
|
+
onEnd?: (result: MorphResult) => void;
|
|
16
|
+
}
|
|
17
|
+
export interface Face {
|
|
18
|
+
/** The expression shown, or being morphed to. */
|
|
19
|
+
readonly state: FaceExpression;
|
|
20
|
+
/**
|
|
21
|
+
* Morphs to another expression. The promise resolves when the morph ends; an interrupted morph resolves with
|
|
22
|
+
* `interrupted: true`. Without animation when the user prefers reduced motion.
|
|
23
|
+
*/
|
|
24
|
+
to(state: FaceExpression, options?: FaceChangeOptions): Promise<MorphResult>;
|
|
25
|
+
/** Closes the eyes and opens them again, on top of the expression (none while asleep or with reduced motion). */
|
|
26
|
+
blink(): Promise<void>;
|
|
27
|
+
/** Stops everything and removes the face from the page. */
|
|
28
|
+
destroy(): void;
|
|
29
|
+
}
|
|
30
|
+
/** Adds a morphing face (an <svg>) to `element`. */
|
|
31
|
+
export declare const face: (element: Element, options?: FaceOptions) => Face;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
export { clip } from './clip.js';
|
|
2
2
|
export { easings } from './engine.js';
|
|
3
|
+
export { face } from './face.js';
|
|
3
4
|
export { icon } from './icon.js';
|
|
4
5
|
export { iconSets } from './iconSets.js';
|
|
6
|
+
export { faceExpressionNames } from './sets/faces.js';
|
|
5
7
|
export { text } from './text.js';
|
|
6
8
|
export type { Clip, ClipChangeOptions, ClipChanges, ClipOptions, ClipOutline, Length } from './clip.js';
|
|
7
9
|
export type { Easing } from './engine.js';
|
|
10
|
+
export type { Face, FaceChangeOptions, FaceOptions } from './face.js';
|
|
8
11
|
export type { ChangeOptions, Icon, IconOptions } from './icon.js';
|
|
9
12
|
export type { IconSetName } from './iconSets.js';
|
|
10
13
|
export type { EasingName, MorphOptions, MorphResult } from './morph.js';
|
|
14
|
+
export type { FaceExpression } from './sets/faces.js';
|
|
11
15
|
export type { StyleOptions } from './svg.js';
|
|
12
16
|
export type { SetOptions, Text, TextOptions, TextResult } from './text.js';
|
|
13
17
|
export type { IconSet, TextLayout } from './types.js';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Point } from '../types.js';
|
|
2
|
+
export declare const OUTLINE_POINTS = 24;
|
|
3
|
+
export declare const PIECE_NAMES: readonly ['leftBrow', 'rightBrow', 'leftEye', 'rightEye', 'leftPupil', 'rightPupil', 'mouth'];
|
|
4
|
+
type PieceName = typeof PIECE_NAMES[number];
|
|
5
|
+
/** One expression: the outline points of every piece. */
|
|
6
|
+
export type FacePieces = Record<PieceName, Point[]>;
|
|
7
|
+
export declare const faceExpressionNames: readonly ['normal', 'smiling', 'pleading', 'wonder', 'focused', 'fright', 'angry', 'asleep', 'sad', 'surprised', 'laughing', 'tired', 'wink-left', 'wink-right', 'suspicious', 'confused', 'smug', 'irritated', 'bored', 'curious', 'empathetic', 'guilty', 'worried', 'disappointed', 'ashamed', 'embarrassed', 'yearning', 'triumphant', 'proud', 'excited', 'scornful', 'disgusted'];
|
|
8
|
+
export type FaceExpression = typeof faceExpressionNames[number];
|
|
9
|
+
/** Every expression's pieces, built on first use (nothing runs at import). */
|
|
10
|
+
export declare const faceExpressionPieces: () => Record<FaceExpression, FacePieces>;
|
|
11
|
+
export declare const interpolateFace: (from: FacePieces, to: FacePieces, progress: number) => FacePieces;
|
|
12
|
+
/** The face with its eyes partly closed: openness 1 = as drawn, 0 = shut to a flat slit (pupils gone). */
|
|
13
|
+
export declare const blinked: (face: FacePieces, openness: number) => FacePieces;
|
|
14
|
+
/** A smooth closed curve through the points: each handle points along the neighbours' chord and is a third of its own
|
|
15
|
+
* segment long (no loops where points sit close together, as at a band's round end). Empty for a hidden piece. */
|
|
16
|
+
export declare const smoothClosedPath: (points: Point[]) => string;
|
|
17
|
+
export interface FacePaths {
|
|
18
|
+
/** Brows, eyes and mouth (one colour). */
|
|
19
|
+
features: string;
|
|
20
|
+
/** Both eyes, to clip the pupils with. */
|
|
21
|
+
eyes: string;
|
|
22
|
+
pupils: string;
|
|
23
|
+
}
|
|
24
|
+
export declare const facePaths: (face: FacePieces) => FacePaths;
|
|
25
|
+
export {};
|
package/package.json
CHANGED