morphico 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/README.md +37 -3
- package/dist/morphico.js +711 -5
- package/dist/morphico.mjs +711 -5
- package/dist/types/clip.d.ts +55 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/morph.d.ts +5 -1
- package/dist/types/sets/shapes.d.ts +5 -0
- package/package.json +1 -1
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { MorphOptions, MorphResult } from './morph.js';
|
|
2
|
+
import type { IconSet } from './types.js';
|
|
3
|
+
/** A length: a number = % (of the element's width for x and size, of its height for y), or `'40%'` / `'120px'`. */
|
|
4
|
+
export type Length = number | string;
|
|
5
|
+
/** Only a band along the shape's edge shows. */
|
|
6
|
+
export interface ClipOutline {
|
|
7
|
+
/** Width of the band in px. */
|
|
8
|
+
width: number;
|
|
9
|
+
/** Where the band sits: inside the edge (default), on it (`'centre'`) or outside it. */
|
|
10
|
+
band?: 'inside' | 'centre' | 'outside';
|
|
11
|
+
}
|
|
12
|
+
/** What can change, in `clip()` and in every `to()` / `set()`. */
|
|
13
|
+
export interface ClipChanges {
|
|
14
|
+
/** Centre of the shape, from the element's left edge (default 50 = the middle). */
|
|
15
|
+
x?: Length;
|
|
16
|
+
/** Centre of the shape, from the element's top edge (default 50 = the middle). */
|
|
17
|
+
y?: Length;
|
|
18
|
+
/** Side of the shape's square (default: the largest square that fits the element). */
|
|
19
|
+
size?: Length;
|
|
20
|
+
/** Turn in degrees, clockwise; absolute (`rotation: 360` ends one full turn from 0). */
|
|
21
|
+
rotation?: number;
|
|
22
|
+
/** Corners: 1 = the shape's own (default, the roundest) … 0 = sharp. */
|
|
23
|
+
roundness?: number;
|
|
24
|
+
/** `false` (default) = the whole shape shows; an outline = only a band along its edge (not animated). */
|
|
25
|
+
outline?: false | ClipOutline;
|
|
26
|
+
}
|
|
27
|
+
export interface ClipOptions extends ClipChanges, MorphOptions {
|
|
28
|
+
/** The shape set (default: the built-in shapes, based on Lucide). */
|
|
29
|
+
set?: IconSet;
|
|
30
|
+
/** The shape shown first (default `'circle'`). */
|
|
31
|
+
state?: string;
|
|
32
|
+
}
|
|
33
|
+
export interface ClipChangeOptions extends ClipChanges, MorphOptions {
|
|
34
|
+
/** Called when the change ends, with the same result the promise resolves to. */
|
|
35
|
+
onEnd?: (result: MorphResult) => void;
|
|
36
|
+
}
|
|
37
|
+
export interface Clip {
|
|
38
|
+
/** The shape shown, or being morphed to. */
|
|
39
|
+
readonly state: string;
|
|
40
|
+
/**
|
|
41
|
+
* Morphs to the shape `state` and animates the given changes along (move, resize, turn, roundness), or — called with
|
|
42
|
+
* only an object — animates those changes and keeps the shape. The promise resolves when it ends; an interrupted
|
|
43
|
+
* change resolves with `interrupted: true`. Without animation when the user prefers reduced motion.
|
|
44
|
+
*/
|
|
45
|
+
to(state: string, options?: ClipChangeOptions): Promise<MorphResult>;
|
|
46
|
+
to(changes: ClipChangeOptions): Promise<MorphResult>;
|
|
47
|
+
/** Jumps (no animation), e.g. while a slider is dragged. Stops a running change (it resolves as interrupted). */
|
|
48
|
+
set(changes: ClipChanges & {
|
|
49
|
+
state?: string;
|
|
50
|
+
}): void;
|
|
51
|
+
/** Stops, removes the hidden <svg> and gives the element back its own clip-path / mask. */
|
|
52
|
+
destroy(): void;
|
|
53
|
+
}
|
|
54
|
+
/** Cuts `element` out by a morphing shape. */
|
|
55
|
+
export declare const clip: (element: HTMLElement | SVGElement, options?: ClipOptions) => Clip;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
export { clip } from './clip.js';
|
|
1
2
|
export { easings } from './engine.js';
|
|
2
3
|
export { icon } from './icon.js';
|
|
3
4
|
export { iconSets } from './iconSets.js';
|
|
4
5
|
export { text } from './text.js';
|
|
6
|
+
export type { Clip, ClipChangeOptions, ClipChanges, ClipOptions, ClipOutline, Length } from './clip.js';
|
|
5
7
|
export type { Easing } from './engine.js';
|
|
6
8
|
export type { ChangeOptions, Icon, IconOptions } from './icon.js';
|
|
7
9
|
export type { IconSetName } from './iconSets.js';
|
package/dist/types/morph.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { easings } from './engine.js';
|
|
2
2
|
import type { Easing } from './engine.js';
|
|
3
|
-
import type { IconSet } from './types.js';
|
|
3
|
+
import type { IconSet, PathNumbers } from './types.js';
|
|
4
4
|
export type EasingName = keyof typeof easings;
|
|
5
5
|
export interface MorphOptions {
|
|
6
6
|
/** Length of a morph in milliseconds (default 400). */
|
|
@@ -16,7 +16,11 @@ export interface MorphResult {
|
|
|
16
16
|
}
|
|
17
17
|
/** The empty state: nothing is drawn. Shapes grow out of it and shrink into it while fading. */
|
|
18
18
|
export declare const EMPTY_STATE = " ";
|
|
19
|
+
export declare const DEFAULT_DURATION = 400;
|
|
20
|
+
export declare const shapesOf: (iconSet: IconSet) => Record<string, PathNumbers>;
|
|
19
21
|
export declare const hasState: (iconSet: IconSet, state: string) => boolean;
|
|
22
|
+
export declare const prefersReducedMotion: () => boolean;
|
|
23
|
+
export declare const clampToUnit: (value: number) => number;
|
|
20
24
|
export interface MorphingPath {
|
|
21
25
|
/** The state shown, or being morphed to. */
|
|
22
26
|
readonly state: string;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { IconSet, Stroke } from '../types.js';
|
|
2
|
+
/** The shapes as Lucide draws them (Lucide coordinates); the set's states are made from these. */
|
|
3
|
+
export declare const lucideShapeOutlines: Record<string, Stroke[]>;
|
|
4
|
+
/** The shape set of clip(): states `circle`, `ellipse`, `heart` … `puzzle` (see `lucideShapeOutlines`). */
|
|
5
|
+
export declare const clipShapes: IconSet;
|
package/package.json
CHANGED