tegaki 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.
package/dist/index.d.mts CHANGED
@@ -1,288 +1,3 @@
1
- import { ComponentProps, Ref } from "react";
2
- import * as _$react_jsx_runtime0 from "react/jsx-runtime";
3
-
4
- //#region src/types.d.ts
5
- type LineCap = 'round' | 'butt' | 'square';
6
- interface Point {
7
- x: number;
8
- y: number;
9
- }
10
- interface TimedPoint extends Point {
11
- t: number;
12
- width: number;
13
- }
14
- interface BBox {
15
- x1: number;
16
- y1: number;
17
- x2: number;
18
- y2: number;
19
- }
20
- interface Stroke {
21
- points: TimedPoint[];
22
- order: number;
23
- length: number;
24
- animationDuration: number;
25
- delay: number;
26
- }
27
- interface GlyphData {
28
- char: string;
29
- unicode: number;
30
- advanceWidth: number;
31
- boundingBox: BBox;
32
- path: string;
33
- skeleton: Point[][];
34
- strokes: Stroke[];
35
- totalLength: number;
36
- totalAnimationDuration: number;
37
- }
38
- interface FontOutput {
39
- font: {
40
- family: string;
41
- style: string;
42
- unitsPerEm: number;
43
- ascender: number;
44
- descender: number;
45
- lineCap: LineCap;
46
- };
47
- glyphs: Record<string, GlyphData>;
48
- }
49
- interface PathCommand {
50
- type: 'M' | 'L' | 'Q' | 'C' | 'Z';
51
- x: number;
52
- y: number;
53
- x1?: number;
54
- y1?: number;
55
- x2?: number;
56
- y2?: number;
57
- }
58
- /**
59
- * Compact glyph data for rendering.
60
- * - `w`: advance width
61
- * - `t`: total animation duration
62
- * - `s`: strokes, each with `p` (points as `[x, y, width]` tuples), `d` (delay), `a` (animation duration)
63
- */
64
- interface TegakiGlyphData {
65
- w: number;
66
- t: number;
67
- s: {
68
- p: ([x: number, y: number, width: number] | number[])[];
69
- d: number;
70
- a: number;
71
- }[];
72
- }
73
- type BaseEffectConfig = {
74
- enabled?: boolean;
75
- };
76
- /** A length value: plain number is pixels, string `"${number}em"` is relative to font size. */
77
- type CSSLength = number | `${number}em`;
78
- type TegakiEffectConfigs = {
79
- glow: BaseEffectConfig & {
80
- radius?: CSSLength;
81
- color?: string;
82
- offsetX?: number;
83
- offsetY?: number;
84
- };
85
- wobble: BaseEffectConfig & {
86
- amplitude?: number;
87
- frequency?: number;
88
- mode?: 'sine' | 'noise';
89
- };
90
- pressureWidth: BaseEffectConfig & {
91
- strength?: number;
92
- };
93
- taper: BaseEffectConfig & {
94
- startLength?: number;
95
- endLength?: number;
96
- };
97
- gradient: BaseEffectConfig & {
98
- colors?: string[] | 'rainbow';
99
- saturation?: number;
100
- lightness?: number;
101
- };
102
- };
103
- type TegakiEffectName = keyof TegakiEffectConfigs;
104
- /** Effects that can only appear once (cannot be used with custom keys). */
105
- type TegakiSingletonEffectName = 'pressureWidth' | 'wobble' | 'taper' | 'gradient';
106
- /** Effects that can be duplicated with custom keys. */
107
- type TegakiMultiEffectName = Exclude<TegakiEffectName, TegakiSingletonEffectName>;
108
- type TegakiCustomEffect = { [K in TegakiMultiEffectName]: TegakiEffectConfigs[K] & {
109
- effect: K;
110
- order?: number;
111
- } }[TegakiMultiEffectName];
112
- /** Validates an effects object: known keys infer `effect`, unknown keys require it (singleton effects excluded). */
113
- type TegakiEffects<T> = { [K in keyof T]: K extends TegakiEffectName ? (TegakiEffectConfigs[K] & {
114
- effect?: K;
115
- order?: number;
116
- }) | boolean : TegakiCustomEffect | boolean };
117
- interface TegakiBundle {
118
- family: string;
119
- lineCap: LineCap;
120
- fontUrl: string;
121
- fontFaceCSS: string;
122
- unitsPerEm: number;
123
- ascender: number;
124
- descender: number;
125
- glyphData: Record<string, TegakiGlyphData>;
126
- }
127
- //#endregion
128
- //#region src/lib/effects.d.ts
129
- interface ResolvedEffect<K extends TegakiEffectName = TegakiEffectName> {
130
- effect: K;
131
- order: number;
132
- config: TegakiEffectConfigs[K];
133
- }
134
- //#endregion
135
- //#region src/lib/drawGlyph.d.ts
136
- interface GlyphPosition {
137
- /** X offset in CSS pixels */
138
- x: number;
139
- /** Y offset in CSS pixels (top of em square) */
140
- y: number;
141
- /** Font size in CSS pixels */
142
- fontSize: number;
143
- /** Units per em from the font */
144
- unitsPerEm: number;
145
- /** Font ascender in font units */
146
- ascender: number;
147
- /** Font descender in font units (negative) */
148
- descender: number;
149
- }
150
- /**
151
- * Draw a single glyph's strokes onto a canvas context, animated up to `localTime`.
152
- * `localTime` is seconds relative to this glyph's start (0 = glyph begins).
153
- */
154
- declare function drawGlyph(ctx: CanvasRenderingContext2D, glyph: TegakiGlyphData, pos: GlyphPosition, localTime: number, lineCap: LineCap, color: string, effects?: ResolvedEffect[], seed?: number, segmentSize?: number): void;
155
- //#endregion
156
- //#region src/lib/timeline.d.ts
157
- interface TimelineConfig {
158
- /** Pause between glyphs (seconds). Default: `0.1` */
159
- glyphGap?: number;
160
- /** Pause after a space character (seconds). Default: `0.15` */
161
- wordGap?: number;
162
- /** Pause after a newline / line break (seconds). Default: `0.3` */
163
- lineGap?: number;
164
- /** Duration for characters without glyph data (seconds). Default: `0.2` */
165
- unknownDuration?: number;
166
- }
167
- interface TimelineEntry {
168
- char: string;
169
- offset: number;
170
- duration: number;
171
- hasGlyph: boolean;
172
- }
173
- interface Timeline {
174
- entries: TimelineEntry[];
175
- totalDuration: number;
176
- }
177
- declare function computeTimeline(text: string, font: TegakiBundle, config?: TimelineConfig): Timeline;
178
- //#endregion
179
- //#region src/lib/utils.d.ts
180
- type Coercible = string | number | boolean | null | undefined | readonly Coercible[];
181
- //#endregion
182
- //#region src/lib/TegakiRenderer.d.ts
183
- /**
184
- * Returns a promise that resolves when the font is ready for text measurement.
185
- * - Already loaded (by us or externally): resolves immediately.
186
- * - Currently loading externally: waits for `document.fonts.ready`.
187
- * - Not registered at all: loads it via the FontFace API.
188
- * Returns `null` if the font is already loaded synchronously.
189
- */
190
- /**
191
- * Ensures the bundle's font face is loaded and available for rendering.
192
- * Resolves immediately if the font is already loaded.
193
- */
194
- declare function ensureFontFace(bundle: TegakiBundle): Promise<void>;
195
- type TimeControlMode = {
196
- controlled: {
197
- mode: 'controlled'; /** Current time in seconds. */
198
- value: number;
199
- };
200
- uncontrolled: {
201
- mode: 'uncontrolled'; /** Initial time in seconds. Default: `0` */
202
- initialTime?: number; /** Playback speed multiplier. Default: `1` */
203
- speed?: number; /** Whether animation is playing. Default: `true` */
204
- playing?: boolean; /** Loop animation when it reaches the end. Default: `false` */
205
- loop?: boolean;
206
- /**
207
- * Catch-up strength. When positive, playback speeds up when there is a
208
- * large amount of remaining animation and decays back to normal gradually.
209
- * `0` disables catch-up (default). Higher values ramp up more aggressively.
210
- * Typical range: `0.2` – `2`.
211
- */
212
- catchUp?: number; /** Called on every frame with the current time. */
213
- onTimeChange?: (time: number) => void;
214
- };
215
- css: {
216
- mode: 'css';
217
- };
218
- };
219
- /**
220
- * A plain number is shorthand for `{ mode: 'controlled', value: number }`.
221
- * `'css'` is shorthand for `{ mode: 'css' }`.
222
- * Omit for uncontrolled mode with default settings.
223
- */
224
- type TimeControlProp = null | undefined | number | 'css' | TimeControlMode[keyof TimeControlMode];
225
- /** Imperative handle exposed via the `ref` prop. */
226
- interface TegakiRendererHandle {
227
- /** The root DOM element. */
228
- getElement(): HTMLDivElement | null;
229
- /** Current animation time in seconds. */
230
- getCurrentTime(): number;
231
- /** Total timeline duration in seconds. */
232
- getDuration(): number;
233
- /** Whether the animation is currently playing (uncontrolled mode only). */
234
- getIsPlaying(): boolean;
235
- /** Whether the animation has reached the end. */
236
- getIsComplete(): boolean;
237
- /** Resume playback (uncontrolled mode only). No-op in controlled/css mode. */
238
- play(): void;
239
- /** Pause playback (uncontrolled mode only). No-op in controlled/css mode. */
240
- pause(): void;
241
- /** Jump to a specific time in seconds (uncontrolled mode only). No-op in controlled/css mode. */
242
- seek(time: number): void;
243
- /** Seek to 0 and play (uncontrolled mode only). No-op in controlled/css mode. */
244
- restart(): void;
245
- }
246
- interface TegakiRendererProps<E extends TegakiEffects<E> = Record<string, never>> extends Omit<ComponentProps<'div'>, 'children' | 'ref'> {
247
- /** Imperative handle ref for playback controls and DOM access. */
248
- ref?: Ref<TegakiRendererHandle>;
249
- /** TegakiBundle with font data and animated glyph SVGs. */
250
- font?: TegakiBundle;
251
- /** Text to animate. Takes precedence over children. */
252
- text?: string;
253
- /** Children coerced to string. Strings and numbers are kept; everything else is ignored. */
254
- children?: Coercible;
255
- /**
256
- * Time control. Accepts a number (controlled shorthand), or an object
257
- * specifying the mode (`'controlled'`, `'uncontrolled'`, or `'css'`).
258
- * Omit for uncontrolled playback with default settings.
259
- */
260
- time?: TimeControlProp;
261
- /** Called once when the animation reaches the end of the timeline. */
262
- onComplete?: () => void;
263
- /** Visual effects applied during canvas rendering. */
264
- effects?: E;
265
- /** Maximum segment size in pixels for effect subdivision. Lower values produce
266
- * smoother effects but cost more to render. Default: `2` */
267
- segmentSize?: number;
268
- /** Timeline timing configuration (gap between glyphs, words, lines, etc.). */
269
- timing?: TimelineConfig;
270
- /** Show debug text overlay. */
271
- showOverlay?: boolean;
272
- }
273
- declare function TegakiRenderer<const E extends TegakiEffects<E> = Record<string, never>>({
274
- ref,
275
- font,
276
- text,
277
- children,
278
- time: timeProp,
279
- onComplete,
280
- effects,
281
- segmentSize,
282
- timing,
283
- showOverlay,
284
- ...props
285
- }: TegakiRendererProps<E>): _$react_jsx_runtime0.JSX.Element;
286
- //#endregion
287
- export { BBox, CSSLength, FontOutput, GlyphData, LineCap, PathCommand, Point, Stroke, TegakiBundle, type TegakiEffectConfigs, TegakiEffectName, type TegakiEffects, TegakiGlyphData, TegakiMultiEffectName, TegakiRenderer, type TegakiRendererHandle, type TegakiRendererProps, TegakiSingletonEffectName, type TimeControlMode, type TimeControlProp, TimedPoint, type Timeline, type TimelineConfig, computeTimeline, drawGlyph, ensureFontFace };
288
- //# sourceMappingURL=index.d.mts.map
1
+ import { A as TegakiSingletonEffectName, C as Stroke, D as TegakiEffects, E as TegakiEffectName, O as TegakiGlyphData, S as Point, T as TegakiEffectConfigs, _ as CSSLength, a as TimeControlProp, b as LineCap, c as TimelineEntry, d as computeTextLayout, f as ensureFontFace, g as BBox, h as resolveEffects, i as TimeControlMode, j as TimedPoint, k as TegakiMultiEffectName, l as computeTimeline, m as ResolvedEffect, n as TegakiEngine, o as Timeline, p as drawGlyph, r as TegakiEngineOptions, s as TimelineConfig, t as CreateElementFn, u as TextLayout, v as FontOutput, w as TegakiBundle, x as PathCommand, y as GlyphData } from "./index-Bzxy01Zq.mjs";
2
+ import { n as TegakiRendererHandle, r as TegakiRendererProps, t as TegakiRenderer } from "./index-BUNd9bnS.mjs";
3
+ export { BBox, CSSLength, CreateElementFn, FontOutput, GlyphData, LineCap, PathCommand, Point, ResolvedEffect, Stroke, TegakiBundle, TegakiEffectConfigs, TegakiEffectName, TegakiEffects, TegakiEngine, TegakiEngineOptions, TegakiGlyphData, TegakiMultiEffectName, TegakiRenderer, TegakiRendererHandle, TegakiRendererProps, TegakiSingletonEffectName, TextLayout, TimeControlMode, TimeControlProp, TimedPoint, Timeline, TimelineConfig, TimelineEntry, computeTextLayout, computeTimeline, drawGlyph, ensureFontFace, resolveEffects };