@shopify/klint 0.0.97 → 0.2.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.
@@ -1,658 +0,0 @@
1
- interface KlintColor {
2
- colors: readonly string[];
3
- coral: string;
4
- brown: string;
5
- mustard: string;
6
- crimson: string;
7
- navy: string;
8
- sky: string;
9
- olive: string;
10
- charcoal: string;
11
- peach: string;
12
- rose: string;
13
- plum: string;
14
- sage: string;
15
- drab: string;
16
- taupe: string;
17
- midnight: string;
18
- golden: string;
19
- orange: string;
20
- slate: string;
21
- hex(color: string): string;
22
- rgb(r: number, g: number, b: number): string;
23
- rgba(r: number, g: number, b: number, alpha: number): string;
24
- gray(value: number, alpha?: number): string;
25
- hsl(h: number, s: number, l: number): string;
26
- hsla(h: number, s: number, l: number, alpha: number): string;
27
- lch(l: number, c: number, h: number): string;
28
- lcha(l: number, c: number, h: number, alpha: number): string;
29
- lab(l: number, a: number, b: number): string;
30
- laba(l: number, a: number, b: number, alpha: number): string;
31
- oklch(l: number, c: number, h: number): string;
32
- oklcha(l: number, c: number, h: number, alpha: number): string;
33
- oklab(l: number, a: number, b: number): string;
34
- oklaba(l: number, a: number, b: number, alpha: number): string;
35
- blendColors(colorA: string, colorB: string, factor: number, colorMode?: string): string;
36
- createPalette(baseColor: string, steps?: number): string[];
37
- complementary(color: string): string;
38
- analogous(color: string, angle?: number): [string, string];
39
- triadic(color: string): [string, string];
40
- saturate(color: string, amount: number): string;
41
- lighten(color: string, amount: number): string;
42
- darken(color: string, amount: number): string;
43
- }
44
- declare class Color implements KlintColor {
45
- /**
46
- * Array of predefined colors in the Klint color palette
47
- */
48
- colors: readonly ["#E84D37", "#7F4C2F", "#EDBC2F", "#BF3034", "#18599D", "#45A7C6", "#8CB151", "#252120", "#ECA088", "#C9B1B8", "#8F3064", "#7B8870", "#C0C180", "#4B423D", "#1A2A65", "#EAA550", "#F17B04", "#404757"];
49
- get coral(): "#E84D37";
50
- get brown(): "#7F4C2F";
51
- get mustard(): "#EDBC2F";
52
- get crimson(): "#BF3034";
53
- get navy(): "#18599D";
54
- get sky(): "#45A7C6";
55
- get olive(): "#8CB151";
56
- get charcoal(): "#252120";
57
- get peach(): "#ECA088";
58
- get rose(): "#C9B1B8";
59
- get plum(): "#8F3064";
60
- get sage(): "#7B8870";
61
- get drab(): "#C0C180";
62
- get taupe(): "#4B423D";
63
- get midnight(): "#1A2A65";
64
- get golden(): "#EAA550";
65
- get orange(): "#F17B04";
66
- get slate(): "#404757";
67
- /**
68
- * Ensures a color string has a # prefix
69
- * @param color - Color string in hex format (with or without #)
70
- * @returns Hex color string with # prefix
71
- */
72
- hex(color: string): string;
73
- /**
74
- * Creates an RGB color string
75
- * @param r - Red component (0-255)
76
- * @param g - Green component (0-255)
77
- * @param b - Blue component (0-255)
78
- * @returns RGB color string
79
- */
80
- rgb(r: number, g: number, b: number): string;
81
- /**
82
- * Creates an RGBA color string
83
- * @param r - Red component (0-255)
84
- * @param g - Green component (0-255)
85
- * @param b - Blue component (0-255)
86
- * @param alpha - Alpha/opacity value (0-1)
87
- * @returns RGBA color string
88
- */
89
- rgba(r: number, g: number, b: number, alpha: number): string;
90
- /**
91
- * Creates a grayscale color
92
- * @param value - Gray value (0-255)
93
- * @param alpha - Optional alpha/opacity value (0-1)
94
- * @returns RGB or RGBA grayscale color string
95
- */
96
- gray(value: number, alpha?: number): string;
97
- /**
98
- * Creates an HSL color string
99
- * @param h - Hue (0-360)
100
- * @param s - Saturation percentage (0-100)
101
- * @param l - Lightness percentage (0-100)
102
- * @returns HSL color string
103
- */
104
- hsl(h: number, s: number, l: number): string;
105
- /**
106
- * Creates an HSLA color string
107
- * @param h - Hue (0-360)
108
- * @param s - Saturation percentage (0-100)
109
- * @param l - Lightness percentage (0-100)
110
- * @param alpha - Alpha/opacity value (0-1)
111
- * @returns HSLA color string
112
- */
113
- hsla(h: number, s: number, l: number, alpha: number): string;
114
- /**
115
- * Creates an LCH color string
116
- * @param l - Lightness percentage (0-100)
117
- * @param c - Chroma value
118
- * @param h - Hue (0-360)
119
- * @returns LCH color string
120
- */
121
- lch(l: number, c: number, h: number): string;
122
- /**
123
- * Creates an LCH color string with alpha
124
- * @param l - Lightness percentage (0-100)
125
- * @param c - Chroma value
126
- * @param h - Hue (0-360)
127
- * @param alpha - Alpha/opacity value (0-1)
128
- * @returns LCH color string with alpha
129
- */
130
- lcha(l: number, c: number, h: number, alpha: number): string;
131
- /**
132
- * Creates a LAB color string
133
- * @param l - Lightness percentage (0-100)
134
- * @param a - A-axis value (green to red)
135
- * @param b - B-axis value (blue to yellow)
136
- * @returns LAB color string
137
- */
138
- lab(l: number, a: number, b: number): string;
139
- /**
140
- * Creates a LAB color string with alpha
141
- * @param l - Lightness percentage (0-100)
142
- * @param a - A-axis value (green to red)
143
- * @param b - B-axis value (blue to yellow)
144
- * @param alpha - Alpha/opacity value (0-1)
145
- * @returns LAB color string with alpha
146
- */
147
- laba(l: number, a: number, b: number, alpha: number): string;
148
- /**
149
- * Creates an OKLCH color string
150
- * @param l - Lightness value (0-1)
151
- * @param c - Chroma value
152
- * @param h - Hue (0-360)
153
- * @returns OKLCH color string
154
- */
155
- oklch(l: number, c: number, h: number): string;
156
- /**
157
- * Creates an OKLCH color string with alpha
158
- * @param l - Lightness value (0-1)
159
- * @param c - Chroma value
160
- * @param h - Hue (0-360)
161
- * @param alpha - Alpha/opacity value (0-1)
162
- * @returns OKLCH color string with alpha
163
- */
164
- oklcha(l: number, c: number, h: number, alpha: number): string;
165
- /**
166
- * Creates an OKLAB color string
167
- * @param l - Lightness value (0-1)
168
- * @param a - A-axis value (green to red)
169
- * @param b - B-axis value (blue to yellow)
170
- * @returns OKLAB color string
171
- */
172
- oklab(l: number, a: number, b: number): string;
173
- /**
174
- * Creates an OKLAB color string with alpha
175
- * @param l - Lightness value (0-1)
176
- * @param a - A-axis value (green to red)
177
- * @param b - B-axis value (blue to yellow)
178
- * @param alpha - Alpha/opacity value (0-1)
179
- * @returns OKLAB color string with alpha
180
- */
181
- oklaba(l: number, a: number, b: number, alpha: number): string;
182
- /**
183
- * Blends two colors using CSS color-mix
184
- * @param colorA - First color
185
- * @param colorB - Second color
186
- * @param factor - Blend factor (0-1) where 0 is colorA and 1 is colorB
187
- * @param colorMode - Color space to blend in (e.g., "oklch", "hsl")
188
- * @returns Blended color string
189
- */
190
- blendColors(colorA: string, colorB: string, factor: number, colorMode?: string): string;
191
- /**
192
- * Creates a palette of colors based on a single base color
193
- * @param baseColor - The base color to create palette from
194
- * @param steps - Number of steps in each direction (lighter/darker)
195
- * @returns Array of color strings forming a palette
196
- */
197
- createPalette(baseColor: string, steps?: number): string[];
198
- /**
199
- * Creates a complementary color (opposite on the color wheel)
200
- * @param color - Base color
201
- * @returns Complementary color string
202
- */
203
- complementary(color: string): string;
204
- /**
205
- * Creates analogous colors (adjacent on the color wheel)
206
- * @param color - Base color
207
- * @param angle - Angle of separation in degrees
208
- * @returns Tuple of two analogous color strings
209
- */
210
- analogous(color: string, angle?: number): [string, string];
211
- /**
212
- * Creates a triadic color scheme (three colors evenly spaced on the color wheel)
213
- * @param color - Base color
214
- * @returns Tuple of two additional colors to form a triadic scheme
215
- */
216
- triadic(color: string): [string, string];
217
- /**
218
- * Increases the saturation of a color
219
- * @param color - Base color
220
- * @param amount - Amount to saturate (percentage)
221
- * @returns Saturated color string
222
- */
223
- saturate(color: string, amount: number): string;
224
- /**
225
- * Lightens a color by mixing with white
226
- * @param color - Base color
227
- * @param amount - Amount to lighten (percentage)
228
- * @returns Lightened color string
229
- */
230
- lighten(color: string, amount: number): string;
231
- /**
232
- * Darkens a color by mixing with black
233
- * @param color - Base color
234
- * @param amount - Amount to darken (percentage)
235
- * @returns Darkened color string
236
- */
237
- darken(color: string, amount: number): string;
238
- }
239
-
240
- type KlintCoreFunctionNames = keyof typeof KlintCoreFunctions;
241
- type KlintCoreFunctions = {
242
- [K in KlintCoreFunctionNames]: ReturnType<(typeof KlintCoreFunctions)[K]>;
243
- };
244
- declare const KlintCoreFunctions: {
245
- saveCanvas: (ctx: KlintContext) => () => void;
246
- fullscreen: (ctx: KlintContext) => () => void;
247
- play: (ctx: KlintContext) => () => void;
248
- pause: (ctx: KlintContext) => () => void;
249
- redraw: () => () => void;
250
- extend: (ctx: KlintContext) => (name: string, data: unknown, enforceReplace?: boolean) => void;
251
- passImage: () => (element: HTMLImageElement) => HTMLImageElement | null;
252
- passImages: () => (elements: HTMLImageElement[]) => (HTMLImageElement | null)[];
253
- saveConfig: (ctx: KlintContexts) => (from?: KlintContexts) => KlintConfig;
254
- restoreConfig: (ctx: KlintContext) => (config: KlintConfig) => void;
255
- describe: (ctx: KlintContext) => (description: string) => void;
256
- createOffscreen: (ctx: KlintContext) => (id: string, width: number, height: number, options?: KlintCanvasOptions, callback?: (ctx: KlintOffscreenContext) => void) => KlintOffscreenContext | HTMLImageElement;
257
- getOffscreen: (ctx: KlintContext) => (id: string) => KlintOffscreenContext | HTMLImageElement;
258
- };
259
- type KlintFunctionNames = keyof typeof KlintFunctions;
260
- type KlintFunctions = {
261
- [K in KlintFunctionNames]: ReturnType<(typeof KlintFunctions)[K]>;
262
- };
263
- declare const KlintFunctions: {
264
- readonly extend: (ctx: KlintContexts) => (name: string, data: unknown, enforceReplace?: boolean) => void;
265
- readonly background: (ctx: KlintContexts) => (color?: string) => void;
266
- readonly reset: (ctx: KlintContexts) => () => void;
267
- readonly clear: (ctx: KlintContexts) => () => void;
268
- readonly fillColor: (ctx: KlintContexts) => (color: string | CanvasGradient) => void;
269
- readonly strokeColor: (ctx: KlintContexts) => (color: string | CanvasGradient) => void;
270
- readonly noFill: (ctx: KlintContexts) => () => void;
271
- readonly noStroke: (ctx: KlintContexts) => () => void;
272
- readonly strokeWidth: (ctx: KlintContexts) => (width: number) => void;
273
- readonly strokeJoin: (ctx: KlintContexts) => (join: CanvasLineJoin) => void;
274
- readonly strokeCap: (ctx: KlintContexts) => (cap: CanvasLineCap) => void;
275
- readonly push: (ctx: KlintContexts) => () => void;
276
- readonly pop: (ctx: KlintContexts) => () => void;
277
- readonly point: (ctx: KlintContexts) => (x: number, y: number) => void;
278
- readonly checkTransparency: (ctx: KlintContexts) => (toCheck: string) => boolean;
279
- readonly drawIfVisible: (ctx: KlintContexts) => () => void;
280
- readonly line: (ctx: KlintContexts) => (x1: number, y1: number, x2: number, y2: number) => void;
281
- readonly circle: (ctx: KlintContexts) => (x: number, y: number, radius: number, radius2?: number) => void;
282
- readonly disk: (ctx: KlintContexts) => (x: number, y: number, radius: number, startAngle?: number, endAngle?: number, closed?: boolean) => void;
283
- readonly rectangle: (ctx: KlintContexts) => (x: number, y: number, width: number, height?: number) => void;
284
- readonly roundedRectangle: (ctx: KlintContexts) => (x: number, y: number, width: number, radius: number | number[], height?: number) => void;
285
- readonly polygon: (ctx: KlintContexts) => (x: number, y: number, radius: number, sides: number, radius2?: number, rotation?: number) => void;
286
- readonly beginShape: (ctx: KlintContexts) => () => void;
287
- readonly beginContour: (ctx: KlintContexts) => () => void;
288
- readonly vertex: (ctx: KlintContexts) => (x: number, y: number) => void;
289
- readonly endContour: (ctx: KlintContexts) => (forceRevert?: boolean) => void;
290
- readonly endShape: (ctx: KlintContexts) => (close?: boolean) => void;
291
- readonly gradient: (ctx: KlintContexts) => (x1?: number, y1?: number, x2?: number, y2?: number) => CanvasGradient;
292
- readonly radialGradient: (ctx: KlintContexts) => (x1?: number, y1?: number, r1?: number, x2?: number, y2?: number, r2?: number) => CanvasGradient;
293
- readonly conicGradient: (ctx: KlintContexts) => (angle?: number, x1?: number, y1?: number) => CanvasGradient;
294
- readonly addColorStop: () => (gradient: CanvasGradient, offset?: number, color?: string) => void;
295
- readonly constrain: () => (val: number, floor: number, ceil: number) => number;
296
- readonly lerp: (ctx: KlintContexts) => (A: number, B: number, mix: number, bounded?: boolean) => number;
297
- readonly fract: () => (n: number, mod: number, mode?: "precise" | "fast" | "faster") => number;
298
- readonly distance: (ctx: KlintContexts) => (x1: number, y1: number, x2: number, y2: number, mode?: "precise" | "fast" | "faster") => number;
299
- readonly squareDistance: () => (x1: number, y1: number, x2: number, y2: number) => number;
300
- readonly dot: () => (x1: number, y1: number, x2: number, y2: number) => number;
301
- readonly remap: (ctx: KlintContexts) => (n: number, A: number, B: number, C: number, D: number, bounded?: boolean) => number;
302
- readonly textFont: (ctx: KlintContexts) => (font: string) => void;
303
- readonly textSize: (ctx: KlintContexts) => (size: number) => void;
304
- readonly textStyle: (ctx: KlintContexts) => (style: string) => void;
305
- readonly textWeight: (ctx: KlintContexts) => (weight: string) => void;
306
- readonly textQuality: (ctx: KlintContexts) => (quality?: "speed" | "auto" | "legibility" | "precision") => void;
307
- readonly textSpacing: (ctx: KlintContexts) => (kind: "letter" | "word", value: number) => void;
308
- readonly computeTextStyle: (ctx: KlintContexts) => () => void;
309
- readonly alignText: (ctx: KlintContexts) => (horizontal: CanvasTextAlign, vertical?: CanvasTextBaseline) => void;
310
- readonly textLeading: (ctx: KlintContexts) => (spacing: number) => void;
311
- readonly computeFont: (ctx: KlintContexts) => () => void;
312
- readonly textWidth: (ctx: KlintContexts) => (text: string) => number;
313
- readonly text: (ctx: KlintContexts) => (text: string | number | undefined, x: number, y: number, maxWidth?: number | undefined) => void;
314
- readonly image: (ctx: KlintContexts) => (image: HTMLImageElement | HTMLCanvasElement | OffscreenCanvas | KlintContexts, x: number, y: number, arg3?: number, arg4?: number, arg5?: number, arg6?: number, arg7?: number, arg8?: number) => void;
315
- readonly loadPixels: (ctx: KlintContexts) => () => ImageData;
316
- readonly updatePixels: (ctx: KlintContexts) => (pixels: Uint8ClampedArray | number[]) => void;
317
- readonly readPixels: (ctx: KlintContexts) => (x: number, y: number, w?: number, h?: number) => number[];
318
- readonly scaleTo: () => (originWidth: number, originHeight: number, destinationWidth: number, destinationHeight: number, cover?: boolean) => number;
319
- readonly opacity: (ctx: KlintContexts) => (value: number) => void;
320
- readonly blend: (ctx: KlintContexts) => (blend: GlobalCompositeOperation) => void;
321
- readonly setCanvasOrigin: (ctx: KlintContexts) => (type: "center" | "corner") => void;
322
- readonly setImageOrigin: (ctx: KlintContexts) => (type: "center" | "corner") => void;
323
- readonly setRectOrigin: (ctx: KlintContexts) => (type: "center" | "corner") => void;
324
- readonly withConfig: (ctx: KlintContexts) => (config: KlintConfig) => void;
325
- readonly toBase64: (ctx: KlintContexts) => (type?: string, quality?: number) => string;
326
- readonly saveConfig: (ctx: KlintContexts) => (from?: KlintContexts) => KlintConfig;
327
- readonly restoreConfig: (ctx: KlintContexts) => (config: KlintConfig) => void;
328
- readonly resizeCanvas: (ctx: KlintContexts) => (width: number, height: number) => void;
329
- };
330
-
331
- type KlintContexts = KlintContext | KlintOffscreenContext;
332
- interface KlintOffscreenContext extends CanvasRenderingContext2D, KlintFunctions, KlintElements {
333
- width: number;
334
- height: number;
335
- __dpr: number;
336
- __startedShape: boolean;
337
- __currentShape: number[][] | null;
338
- __startedContour: boolean;
339
- __currentContours: number[][][] | null;
340
- __currentContour: number[][] | null;
341
- __isReadyToDraw: boolean;
342
- __isMainContext: boolean;
343
- __imageOrigin: "corner" | "center";
344
- __rectangleOrigin: "corner" | "center";
345
- __canvasOrigin: "corner" | "center";
346
- __computedTextFont: string;
347
- __textFont: string;
348
- __textSize: number;
349
- __textStyle: string;
350
- __textWeight: string;
351
- __textAlignment: {
352
- horizontal: CanvasTextAlign;
353
- vertical: CanvasTextBaseline;
354
- };
355
- createVector: (x: number, y: number) => Vector;
356
- [key: string]: any;
357
- }
358
- interface KlintContext extends KlintOffscreenContext, KlintCoreFunctions {
359
- frame: number;
360
- time: number;
361
- deltaTime: number;
362
- fps: number;
363
- __lastTargetTime: number;
364
- __lastRealTime: number;
365
- __isPlaying: boolean;
366
- __offscreens: Map<string, KlintOffscreenContext | HTMLImageElement>;
367
- }
368
- interface KlintCanvasOptions {
369
- alpha?: string;
370
- willreadfrequently?: string;
371
- autoplay?: string;
372
- ignoreResize?: string;
373
- noloop?: string;
374
- ignoreFunctions?: string;
375
- static?: string;
376
- nocanvas?: string;
377
- fps?: number;
378
- unsafemode?: string;
379
- dpr?: number | "default";
380
- origin?: "corner" | "center";
381
- }
382
- type KlintConfig = Partial<Pick<KlintContext, (typeof CONFIG_PROPS)[number]>>;
383
- declare const CONFIG_PROPS: readonly ["lineWidth", "strokeStyle", "lineJoin", "lineCap", "fillStyle", "font", "textAlign", "textBaseline", "textRendering", "wordSpacing", "letterSpacing", "globalAlpha", "globalCompositeOperation", "origin", "transform", "__imageOrigin", "__rectangleOrigin", "__textFont", "__textWeight", "__textStyle", "__textSize", "__textAlignment", "__isPlaying"];
384
-
385
- interface KlintEasing {
386
- context: KlintContexts;
387
- normalize: (val: number) => number;
388
- expand: (val: number) => number;
389
- inout: (val: number, power?: number) => number;
390
- in: (val: number, power?: number) => number;
391
- out: (val: number, power?: number) => number;
392
- overshootIn: (val: number) => number;
393
- overshootOut: (val: number) => number;
394
- overshootInOut: (val: number) => number;
395
- }
396
- declare class Easing implements KlintEasing {
397
- context: KlintContexts;
398
- constructor(ctx: KlintContexts);
399
- normalize: (val: number) => number;
400
- expand: (val: number) => number;
401
- inout: (val: number, power?: number) => number;
402
- in: (val: number, power?: number) => number;
403
- out: (val: number, power?: number) => number;
404
- overshootIn: (val: number) => number;
405
- overshootOut: (val: number) => number;
406
- overshootInOut: (val: number) => number;
407
- bounceOut: (val: number) => number;
408
- bounceIn: (val: number) => number;
409
- bounceInOut: (val: number) => number;
410
- elasticIn: (val: number) => number;
411
- elasticOut: (val: number) => number;
412
- elasticInOut: (val: number) => number;
413
- smoothstep: (val: number, x0?: number, x1?: number) => number;
414
- log: () => void;
415
- }
416
-
417
- type KlintStateValue = unknown;
418
- type KlintStateCallback = (key: string, value: KlintStateValue) => void;
419
- interface KlintState {
420
- set(key: string, value: KlintStateValue, callback?: KlintStateCallback): void;
421
- get(key: string, callback?: KlintStateCallback): KlintStateValue;
422
- has(key: string): boolean;
423
- delete(key: string, callback?: (key: string) => void): void;
424
- log(): Map<string, KlintStateValue>;
425
- }
426
- declare class State implements KlintState {
427
- private store;
428
- set(key: string, value: KlintStateValue, callback?: KlintStateCallback): void;
429
- get(key: string, callback?: KlintStateCallback): unknown;
430
- has(key: string): boolean;
431
- delete(key: string, callback?: (key: string) => void): void;
432
- log(): Map<string, unknown>;
433
- }
434
-
435
- /**
436
- * Interface defining a 2D vector with various vector operations
437
- */
438
- interface KlintVector {
439
- x: number;
440
- y: number;
441
- add: (v: KlintVector) => KlintVector;
442
- sub: (v: KlintVector) => KlintVector;
443
- mult: (n: number) => KlintVector;
444
- div: (n: number) => KlintVector;
445
- rotate: (angle: number) => KlintVector;
446
- mag: () => number;
447
- length: () => number;
448
- dot: (v: KlintVector) => number;
449
- dist: (v: KlintVector) => number;
450
- angle: () => number;
451
- copy: () => KlintVector;
452
- normalize: () => KlintVector;
453
- set: (x: number, y: number, z?: number, w?: number) => KlintVector;
454
- }
455
- /**
456
- * A 2D vector class with various vector operations
457
- */
458
- declare class Vector implements KlintVector {
459
- /** X-coordinate of the vector */
460
- x: number;
461
- /** Y-coordinate of the vector */
462
- y: number;
463
- /**
464
- * Creates a new Vector
465
- * @param x - X-coordinate (default: 0)
466
- * @param y - Y-coordinate (default: 0)
467
- */
468
- constructor(x?: number, y?: number);
469
- /**
470
- * Adds another vector to this vector
471
- * @param v - Vector to add
472
- * @returns This vector after addition
473
- */
474
- add(v: KlintVector): Vector;
475
- /**
476
- * Subtracts another vector from this vector
477
- * @param v - Vector to subtract
478
- * @returns This vector after subtraction
479
- */
480
- sub(v: KlintVector): Vector;
481
- /**
482
- * Multiplies this vector by a scalar
483
- * @param n - Scalar to multiply by
484
- * @returns This vector after multiplication
485
- */
486
- mult(n: number): Vector;
487
- /**
488
- * Divides this vector by a scalar
489
- * @param n - Scalar to divide by
490
- * @returns This vector after division
491
- */
492
- div(n: number): Vector;
493
- /**
494
- * Rotates this vector by an angle
495
- * @param angle - Angle in radians
496
- * @returns This vector after rotation
497
- */
498
- rotate(angle: number): Vector;
499
- /**
500
- * Calculates the magnitude (length) of this vector
501
- * @returns The magnitude of the vector
502
- */
503
- mag(): number;
504
- /**
505
- * Alias for mag() - calculates the length of this vector
506
- * @returns The length of the vector
507
- */
508
- length(): number;
509
- /**
510
- * Calculates the dot product of this vector with another vector
511
- * @param v - The other vector
512
- * @returns The dot product
513
- */
514
- dot(v: KlintVector): number;
515
- /**
516
- * Calculates the distance between this vector and another vector
517
- * @param v - The other vector
518
- * @returns The distance between the vectors
519
- */
520
- dist(v: KlintVector): number;
521
- /**
522
- * Calculates the angle of this vector
523
- * @returns The angle in radians
524
- */
525
- angle(): number;
526
- /**
527
- * Creates a copy of this vector
528
- * @returns A new Vector with the same coordinates
529
- */
530
- copy(): Vector;
531
- /**
532
- * Normalizes this vector (sets its magnitude to 1)
533
- * @returns This vector after normalization
534
- */
535
- normalize(): Vector;
536
- /**
537
- * Sets the coordinates of this vector
538
- * @param x - New X-coordinate
539
- * @param y - New Y-coordinate
540
- * @returns This vector after setting coordinates
541
- */
542
- set(x: number, y: number): Vector;
543
- /**
544
- * Creates a new vector at a specified angle and distance from a center point
545
- * @param center - The center point vector
546
- * @param a - The angle in radians
547
- * @param r - The radius (distance from center)
548
- * @returns A new Vector at the calculated position
549
- */
550
- static fromAngle(center: Vector, a: number, r: number): Vector;
551
- }
552
-
553
- interface KlintTime {
554
- context: KlintContexts;
555
- timeline(key: string): KlintTime;
556
- use(progress: number): KlintTime;
557
- for(duration: number): KlintTime;
558
- }
559
- declare class Time implements KlintTime {
560
- context: KlintContexts;
561
- private timelines;
562
- private currentTimeline;
563
- private readonly DEFAULT_DURATION;
564
- private staggers;
565
- constructor(ctx: KlintContexts);
566
- timeline(key: string): this;
567
- use(progress: number): this;
568
- for(duration: number): this;
569
- stagger(num: number, offset?: number, callback?: (progress: number, id: number, num: number) => void): this | {
570
- id: number;
571
- progress: number;
572
- }[];
573
- between(from: number | undefined, to: number | undefined, callback: (progress: number) => void): this;
574
- progress(): number;
575
- }
576
-
577
- type TextMetrics = {
578
- width: number;
579
- height: number;
580
- baseline: number;
581
- };
582
- interface KlintText {
583
- context: KlintContexts;
584
- findTextSize: (text: string, dist: number, estimate?: number, direction?: "x" | "y") => number;
585
- getTextMetrics: (text: string) => TextMetrics;
586
- splitTo: (text: string, kind: "letters" | "words" | "lines" | "all", options?: {
587
- maxWidth?: number;
588
- lineSpacing?: number;
589
- letterSpacing?: number;
590
- wordSpacing?: number;
591
- }) => Array<{
592
- char: string;
593
- x: number;
594
- y: number;
595
- metrics: TextMetrics;
596
- letterIndex?: number;
597
- wordIndex?: number;
598
- lineIndex?: number;
599
- }>;
600
- circularText: (text: string, radius?: number, fill?: "fill" | "kerned" | "words", offset?: number, arc?: number) => void;
601
- textBounds: (text: string) => {
602
- x: number;
603
- y: number;
604
- width: number;
605
- height: number;
606
- };
607
- log: () => void;
608
- }
609
- declare class Text implements KlintText {
610
- context: KlintContexts;
611
- constructor(ctx: KlintContexts);
612
- findTextSize: (text: string, dist: number, estimate?: number, direction?: "x" | "y") => number;
613
- getTextMetrics: (text: string) => TextMetrics;
614
- splitTo: (text: string, kind: "letters" | "words" | "lines" | "all", options?: {
615
- maxWidth?: number;
616
- lineSpacing?: number;
617
- letterSpacing?: number;
618
- wordSpacing?: number;
619
- }) => {
620
- letterIndex?: number | undefined;
621
- wordIndex?: number | undefined;
622
- lineIndex?: number | undefined;
623
- char: string;
624
- x: number;
625
- y: number;
626
- metrics: TextMetrics;
627
- }[];
628
- circularText: (text: string, radius?: number, fill?: "fill" | "kerned" | "words", offset?: number, arc?: number) => void;
629
- textBounds: (text: string) => {
630
- x: number;
631
- y: number;
632
- width: number;
633
- height: number;
634
- };
635
- log: () => void;
636
- }
637
-
638
- interface KlintThing {
639
- context: KlintContexts;
640
- log(): void;
641
- }
642
- declare class Thing implements KlintThing {
643
- context: KlintContexts;
644
- constructor(ctx: KlintContexts);
645
- log(): void;
646
- }
647
-
648
- interface KlintElements {
649
- Color: Color;
650
- Easing: Easing;
651
- State: State;
652
- Vector: Vector;
653
- Time: Time;
654
- Text: Text;
655
- Thing: Thing;
656
- }
657
-
658
- export { Color, Easing, type KlintElements, State, Text, Thing, Time, Vector };