@shopify/klint 0.0.4 → 0.0.6

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.
@@ -0,0 +1,731 @@
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, KlintPlugins {
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
+ [key: string]: any;
356
+ }
357
+ interface KlintContext extends KlintOffscreenContext, KlintCoreFunctions {
358
+ frame: number;
359
+ time: number;
360
+ deltaTime: number;
361
+ fps: number;
362
+ __lastTargetTime: number;
363
+ __lastRealTime: number;
364
+ __isPlaying: boolean;
365
+ __offscreens: Map<string, KlintOffscreenContext | HTMLImageElement>;
366
+ }
367
+ interface KlintCanvasOptions {
368
+ alpha?: string;
369
+ willreadfrequently?: string;
370
+ autoplay?: string;
371
+ ignoreResize?: string;
372
+ noloop?: string;
373
+ ignoreFunctions?: string;
374
+ static?: string;
375
+ nocanvas?: string;
376
+ fps?: number;
377
+ unsafemode?: string;
378
+ origin?: "corner" | "center";
379
+ }
380
+ type KlintConfig = Partial<Pick<KlintContext, (typeof CONFIG_PROPS)[number]>>;
381
+ 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"];
382
+
383
+ interface KlintEasing {
384
+ context: KlintContexts;
385
+ normalize: (val: number) => number;
386
+ expand: (val: number) => number;
387
+ inout: (val: number, power?: number) => number;
388
+ in: (val: number, power?: number) => number;
389
+ out: (val: number, power?: number) => number;
390
+ overshootIn: (val: number) => number;
391
+ overshootOut: (val: number) => number;
392
+ overshootInOut: (val: number) => number;
393
+ }
394
+ declare class Easing implements KlintEasing {
395
+ context: KlintContexts;
396
+ constructor(ctx: KlintContexts);
397
+ normalize: (val: number) => number;
398
+ expand: (val: number) => number;
399
+ inout: (val: number, power?: number) => number;
400
+ in: (val: number, power?: number) => number;
401
+ out: (val: number, power?: number) => number;
402
+ overshootIn: (val: number) => number;
403
+ overshootOut: (val: number) => number;
404
+ overshootInOut: (val: number) => number;
405
+ bounceOut: (val: number) => number;
406
+ bounceIn: (val: number) => number;
407
+ bounceInOut: (val: number) => number;
408
+ elasticIn: (val: number) => number;
409
+ elasticOut: (val: number) => number;
410
+ elasticInOut: (val: number) => number;
411
+ smoothstep: (val: number, x0?: number, x1?: number) => number;
412
+ log: () => void;
413
+ }
414
+
415
+ type SVGFontPaths = Array<Array<Array<{
416
+ x: number;
417
+ y: number;
418
+ }>>>;
419
+ interface FontMetrics {
420
+ fontFamily: string;
421
+ fontWeight: string;
422
+ unitsPerEm: number;
423
+ ascent: number;
424
+ descent: number;
425
+ xHeight: number;
426
+ capHeight: number;
427
+ }
428
+ interface GlyphMetrics {
429
+ name: string;
430
+ unicode: string;
431
+ horizAdvX: number;
432
+ d?: string;
433
+ }
434
+ interface KlintSVGfont {
435
+ context: KlintContexts;
436
+ metrics: FontMetrics;
437
+ glyphs: Map<string, GlyphMetrics>;
438
+ parse(font: string): void;
439
+ }
440
+ interface PointOptions {
441
+ factor: number;
442
+ align?: "center" | "left" | "right";
443
+ center?: "alphabetic" | "middle" | "top";
444
+ letterSpacing?: number;
445
+ treshold?: number;
446
+ }
447
+ interface DisplacementParams {
448
+ point: {
449
+ x: number;
450
+ y: number;
451
+ };
452
+ position: {
453
+ x: number;
454
+ y: number;
455
+ };
456
+ groupIndex: number;
457
+ letterSpacing: number;
458
+ }
459
+ interface DisplacementCallback {
460
+ (params: DisplacementParams): {
461
+ x: number;
462
+ y: number;
463
+ };
464
+ }
465
+ declare class SVGfont implements KlintSVGfont {
466
+ readonly context: KlintContexts;
467
+ readonly metrics: FontMetrics;
468
+ readonly glyphs: Map<string, GlyphMetrics>;
469
+ private font;
470
+ private SCALE;
471
+ private targetXHeight;
472
+ constructor(context: KlintContexts);
473
+ parse(font: string, desiredXHeight?: number): void;
474
+ toJSON(): {
475
+ metrics: FontMetrics;
476
+ glyphs: Record<string, GlyphMetrics>;
477
+ };
478
+ getPoints(text: string, options: PointOptions): Array<Array<Array<{
479
+ x: number;
480
+ y: number;
481
+ }>>>;
482
+ flatten(points: SVGFontPaths, displacement?: DisplacementCallback): Array<{
483
+ x: number;
484
+ y: number;
485
+ }>;
486
+ draw(points: SVGFontPaths, displacement?: DisplacementCallback): void;
487
+ }
488
+
489
+ type KlintStateValue = unknown;
490
+ type KlintStateCallback = (key: string, value: KlintStateValue) => void;
491
+ interface KlintState {
492
+ set(key: string, value: KlintStateValue, callback?: KlintStateCallback): void;
493
+ get(key: string, callback?: KlintStateCallback): KlintStateValue;
494
+ has(key: string): boolean;
495
+ delete(key: string, callback?: (key: string) => void): void;
496
+ log(): Map<string, KlintStateValue>;
497
+ }
498
+ declare class State implements KlintState {
499
+ private store;
500
+ set(key: string, value: KlintStateValue, callback?: KlintStateCallback): void;
501
+ get(key: string, callback?: KlintStateCallback): unknown;
502
+ has(key: string): boolean;
503
+ delete(key: string, callback?: (key: string) => void): void;
504
+ log(): Map<string, unknown>;
505
+ }
506
+
507
+ /**
508
+ * Interface defining a 2D vector with various vector operations
509
+ */
510
+ interface KlintVector {
511
+ x: number;
512
+ y: number;
513
+ add: (v: KlintVector) => KlintVector;
514
+ sub: (v: KlintVector) => KlintVector;
515
+ mult: (n: number) => KlintVector;
516
+ div: (n: number) => KlintVector;
517
+ rotate: (angle: number) => KlintVector;
518
+ mag: () => number;
519
+ length: () => number;
520
+ dot: (v: KlintVector) => number;
521
+ dist: (v: KlintVector) => number;
522
+ angle: () => number;
523
+ copy: () => KlintVector;
524
+ normalize: () => KlintVector;
525
+ set: (x: number, y: number, z?: number, w?: number) => KlintVector;
526
+ }
527
+ /**
528
+ * A 2D vector class with various vector operations
529
+ */
530
+ declare class Vector implements KlintVector {
531
+ /** X-coordinate of the vector */
532
+ x: number;
533
+ /** Y-coordinate of the vector */
534
+ y: number;
535
+ /**
536
+ * Creates a new Vector
537
+ * @param x - X-coordinate (default: 0)
538
+ * @param y - Y-coordinate (default: 0)
539
+ */
540
+ constructor(x?: number, y?: number);
541
+ /**
542
+ * Adds another vector to this vector
543
+ * @param v - Vector to add
544
+ * @returns This vector after addition
545
+ */
546
+ add(v: KlintVector): Vector;
547
+ /**
548
+ * Subtracts another vector from this vector
549
+ * @param v - Vector to subtract
550
+ * @returns This vector after subtraction
551
+ */
552
+ sub(v: KlintVector): Vector;
553
+ /**
554
+ * Multiplies this vector by a scalar
555
+ * @param n - Scalar to multiply by
556
+ * @returns This vector after multiplication
557
+ */
558
+ mult(n: number): Vector;
559
+ /**
560
+ * Divides this vector by a scalar
561
+ * @param n - Scalar to divide by
562
+ * @returns This vector after division
563
+ */
564
+ div(n: number): Vector;
565
+ /**
566
+ * Rotates this vector by an angle
567
+ * @param angle - Angle in radians
568
+ * @returns This vector after rotation
569
+ */
570
+ rotate(angle: number): Vector;
571
+ /**
572
+ * Calculates the magnitude (length) of this vector
573
+ * @returns The magnitude of the vector
574
+ */
575
+ mag(): number;
576
+ /**
577
+ * Alias for mag() - calculates the length of this vector
578
+ * @returns The length of the vector
579
+ */
580
+ length(): number;
581
+ /**
582
+ * Calculates the dot product of this vector with another vector
583
+ * @param v - The other vector
584
+ * @returns The dot product
585
+ */
586
+ dot(v: KlintVector): number;
587
+ /**
588
+ * Calculates the distance between this vector and another vector
589
+ * @param v - The other vector
590
+ * @returns The distance between the vectors
591
+ */
592
+ dist(v: KlintVector): number;
593
+ /**
594
+ * Calculates the angle of this vector
595
+ * @returns The angle in radians
596
+ */
597
+ angle(): number;
598
+ /**
599
+ * Creates a copy of this vector
600
+ * @returns A new Vector with the same coordinates
601
+ */
602
+ copy(): Vector;
603
+ /**
604
+ * Normalizes this vector (sets its magnitude to 1)
605
+ * @returns This vector after normalization
606
+ */
607
+ normalize(): Vector;
608
+ /**
609
+ * Sets the coordinates of this vector
610
+ * @param x - New X-coordinate
611
+ * @param y - New Y-coordinate
612
+ * @returns This vector after setting coordinates
613
+ */
614
+ set(x: number, y: number): Vector;
615
+ /**
616
+ * Creates a new vector at a specified angle and distance from a center point
617
+ * @param center - The center point vector
618
+ * @param a - The angle in radians
619
+ * @param r - The radius (distance from center)
620
+ * @returns A new Vector at the calculated position
621
+ */
622
+ static fromAngle(center: Vector, a: number, r: number): Vector;
623
+ }
624
+
625
+ interface KlintTime {
626
+ context: KlintContexts;
627
+ timeline(key: string): KlintTime;
628
+ use(progress: number): KlintTime;
629
+ for(duration: number): KlintTime;
630
+ }
631
+ declare class Time implements KlintTime {
632
+ context: KlintContexts;
633
+ private timelines;
634
+ private currentTimeline;
635
+ private readonly DEFAULT_DURATION;
636
+ private staggers;
637
+ constructor(ctx: KlintContexts);
638
+ timeline(key: string): this;
639
+ use(progress: number): this;
640
+ for(duration: number): this;
641
+ stagger(num: number, offset?: number, callback?: (progress: number, id: number, num: number) => void): this | {
642
+ id: number;
643
+ progress: number;
644
+ }[];
645
+ between(from: number | undefined, to: number | undefined, callback: (progress: number) => void): this;
646
+ progress(): number;
647
+ }
648
+
649
+ type TextMetrics = {
650
+ width: number;
651
+ height: number;
652
+ baseline: number;
653
+ };
654
+ interface KlintText {
655
+ context: KlintContexts;
656
+ findTextSize: (text: string, dist: number, estimate?: number, direction?: "x" | "y") => number;
657
+ getTextMetrics: (text: string) => TextMetrics;
658
+ splitTo: (text: string, kind: "letters" | "words" | "lines" | "all", options?: {
659
+ maxWidth?: number;
660
+ lineSpacing?: number;
661
+ letterSpacing?: number;
662
+ wordSpacing?: number;
663
+ }) => Array<{
664
+ char: string;
665
+ x: number;
666
+ y: number;
667
+ metrics: TextMetrics;
668
+ letterIndex?: number;
669
+ wordIndex?: number;
670
+ lineIndex?: number;
671
+ }>;
672
+ circularText: (text: string, radius?: number, fill?: "fill" | "kerned" | "words", offset?: number, arc?: number) => void;
673
+ textBounds: (text: string) => {
674
+ x: number;
675
+ y: number;
676
+ width: number;
677
+ height: number;
678
+ };
679
+ log: () => void;
680
+ }
681
+ declare class Text implements KlintText {
682
+ context: KlintContexts;
683
+ constructor(ctx: KlintContexts);
684
+ findTextSize: (text: string, dist: number, estimate?: number, direction?: "x" | "y") => number;
685
+ getTextMetrics: (text: string) => TextMetrics;
686
+ splitTo: (text: string, kind: "letters" | "words" | "lines" | "all", options?: {
687
+ maxWidth?: number;
688
+ lineSpacing?: number;
689
+ letterSpacing?: number;
690
+ wordSpacing?: number;
691
+ }) => {
692
+ letterIndex?: number | undefined;
693
+ wordIndex?: number | undefined;
694
+ lineIndex?: number | undefined;
695
+ char: string;
696
+ x: number;
697
+ y: number;
698
+ metrics: TextMetrics;
699
+ }[];
700
+ circularText: (text: string, radius?: number, fill?: "fill" | "kerned" | "words", offset?: number, arc?: number) => void;
701
+ textBounds: (text: string) => {
702
+ x: number;
703
+ y: number;
704
+ width: number;
705
+ height: number;
706
+ };
707
+ log: () => void;
708
+ }
709
+
710
+ interface KlintThing {
711
+ context: KlintContexts;
712
+ log(): void;
713
+ }
714
+ declare class Thing implements KlintThing {
715
+ context: KlintContexts;
716
+ constructor(ctx: KlintContexts);
717
+ log(): void;
718
+ }
719
+
720
+ interface KlintPlugins {
721
+ Color: Color;
722
+ Easing: Easing;
723
+ SVGfont: SVGfont;
724
+ State: State;
725
+ Vector: Vector;
726
+ Time: Time;
727
+ Text: Text;
728
+ Thing: Thing;
729
+ }
730
+
731
+ export { Color, Easing, type KlintPlugins, SVGfont, State, Text, Thing, Time, Vector };