@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.
- package/bin/create-editor +423 -0
- package/bin/create-sandbox +232 -0
- package/bin/klint +146 -0
- package/dist/index.cjs +2369 -317
- package/dist/index.d.cts +847 -66
- package/dist/index.d.ts +847 -66
- package/dist/index.js +2362 -316
- package/package.json +11 -17
- package/dist/elements/index.cjs +0 -946
- package/dist/elements/index.d.cts +0 -658
- package/dist/elements/index.d.ts +0 -658
- package/dist/elements/index.js +0 -913
- package/dist/plugins/index.cjs +0 -1174
- package/dist/plugins/index.d.ts +0 -731
- package/dist/plugins/index.js +0 -1140
package/dist/index.d.cts
CHANGED
|
@@ -40,6 +40,7 @@ declare const KlintFunctions: {
|
|
|
40
40
|
readonly point: (ctx: KlintContexts) => (x: number, y: number) => void;
|
|
41
41
|
readonly checkTransparency: (ctx: KlintContexts) => (toCheck: string) => boolean;
|
|
42
42
|
readonly drawIfVisible: (ctx: KlintContexts) => () => void;
|
|
43
|
+
readonly fillRule: (ctx: KlintContexts) => (rule: CanvasFillRule) => void;
|
|
43
44
|
readonly line: (ctx: KlintContexts) => (x1: number, y1: number, x2: number, y2: number) => void;
|
|
44
45
|
readonly circle: (ctx: KlintContexts) => (x: number, y: number, radius: number, radius2?: number) => void;
|
|
45
46
|
readonly disk: (ctx: KlintContexts) => (x: number, y: number, radius: number, startAngle?: number, endAngle?: number, closed?: boolean) => void;
|
|
@@ -49,12 +50,18 @@ declare const KlintFunctions: {
|
|
|
49
50
|
readonly beginShape: (ctx: KlintContexts) => () => void;
|
|
50
51
|
readonly beginContour: (ctx: KlintContexts) => () => void;
|
|
51
52
|
readonly vertex: (ctx: KlintContexts) => (x: number, y: number) => void;
|
|
53
|
+
readonly bezierVertex: (ctx: KlintContexts) => (cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, y: number) => void;
|
|
54
|
+
readonly quadraticVertex: (ctx: KlintContexts) => (cpx: number, cpy: number, x: number, y: number) => void;
|
|
55
|
+
readonly arcVertex: (ctx: KlintContexts) => (x1: number, y1: number, x2: number, y2: number, radius: number) => void;
|
|
52
56
|
readonly endContour: (ctx: KlintContexts) => (forceRevert?: boolean) => void;
|
|
53
57
|
readonly endShape: (ctx: KlintContexts) => (close?: boolean) => void;
|
|
54
58
|
readonly gradient: (ctx: KlintContexts) => (x1?: number, y1?: number, x2?: number, y2?: number) => CanvasGradient;
|
|
55
59
|
readonly radialGradient: (ctx: KlintContexts) => (x1?: number, y1?: number, r1?: number, x2?: number, y2?: number, r2?: number) => CanvasGradient;
|
|
56
60
|
readonly conicGradient: (ctx: KlintContexts) => (angle?: number, x1?: number, y1?: number) => CanvasGradient;
|
|
57
61
|
readonly addColorStop: () => (gradient: CanvasGradient, offset?: number, color?: string) => void;
|
|
62
|
+
readonly PI: () => number;
|
|
63
|
+
readonly TWO_PI: () => number;
|
|
64
|
+
readonly TAU: () => number;
|
|
58
65
|
readonly constrain: () => (val: number, floor: number, ceil: number) => number;
|
|
59
66
|
readonly lerp: (ctx: KlintContexts) => (A: number, B: number, mix: number, bounded?: boolean) => number;
|
|
60
67
|
readonly fract: () => (n: number, mod: number, mode?: "precise" | "fast" | "faster") => number;
|
|
@@ -62,6 +69,8 @@ declare const KlintFunctions: {
|
|
|
62
69
|
readonly squareDistance: () => (x1: number, y1: number, x2: number, y2: number) => number;
|
|
63
70
|
readonly dot: () => (x1: number, y1: number, x2: number, y2: number) => number;
|
|
64
71
|
readonly remap: (ctx: KlintContexts) => (n: number, A: number, B: number, C: number, D: number, bounded?: boolean) => number;
|
|
72
|
+
readonly bezierLerp: () => (a: number, b: number, c: number, d: number, t: number) => number;
|
|
73
|
+
readonly bezierTangent: () => (a: number, b: number, c: number, d: number, t: number) => number;
|
|
65
74
|
readonly textFont: (ctx: KlintContexts) => (font: string) => void;
|
|
66
75
|
readonly textSize: (ctx: KlintContexts) => (size: number) => void;
|
|
67
76
|
readonly textStyle: (ctx: KlintContexts) => (style: string) => void;
|
|
@@ -70,17 +79,22 @@ declare const KlintFunctions: {
|
|
|
70
79
|
readonly textSpacing: (ctx: KlintContexts) => (kind: "letter" | "word", value: number) => void;
|
|
71
80
|
readonly computeTextStyle: (ctx: KlintContexts) => () => void;
|
|
72
81
|
readonly alignText: (ctx: KlintContexts) => (horizontal: CanvasTextAlign, vertical?: CanvasTextBaseline) => void;
|
|
73
|
-
readonly textLeading: (ctx: KlintContexts) => (spacing: number) =>
|
|
82
|
+
readonly textLeading: (ctx: KlintContexts) => (spacing: number) => number;
|
|
74
83
|
readonly computeFont: (ctx: KlintContexts) => () => void;
|
|
75
84
|
readonly textWidth: (ctx: KlintContexts) => (text: string) => number;
|
|
76
85
|
readonly text: (ctx: KlintContexts) => (text: string | number | undefined, x: number, y: number, maxWidth?: number | undefined) => void;
|
|
86
|
+
readonly paragraph: (ctx: KlintContexts) => (text: string | number | undefined, x: number, y: number, width: number, options?: {
|
|
87
|
+
justification?: "left" | "center" | "right" | "justified";
|
|
88
|
+
overflow?: number;
|
|
89
|
+
break?: "words" | "letters";
|
|
90
|
+
}) => void;
|
|
77
91
|
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;
|
|
78
92
|
readonly loadPixels: (ctx: KlintContexts) => () => ImageData;
|
|
79
93
|
readonly updatePixels: (ctx: KlintContexts) => (pixels: Uint8ClampedArray | number[]) => void;
|
|
80
94
|
readonly readPixels: (ctx: KlintContexts) => (x: number, y: number, w?: number, h?: number) => number[];
|
|
81
95
|
readonly scaleTo: () => (originWidth: number, originHeight: number, destinationWidth: number, destinationHeight: number, cover?: boolean) => number;
|
|
82
96
|
readonly opacity: (ctx: KlintContexts) => (value: number) => void;
|
|
83
|
-
readonly blend: (ctx: KlintContexts) => (blend: GlobalCompositeOperation) => void;
|
|
97
|
+
readonly blend: (ctx: KlintContexts) => (blend: GlobalCompositeOperation | "default") => void;
|
|
84
98
|
readonly setCanvasOrigin: (ctx: KlintContexts) => (type: "center" | "corner") => void;
|
|
85
99
|
readonly setImageOrigin: (ctx: KlintContexts) => (type: "center" | "corner") => void;
|
|
86
100
|
readonly setRectOrigin: (ctx: KlintContexts) => (type: "center" | "corner") => void;
|
|
@@ -89,6 +103,15 @@ declare const KlintFunctions: {
|
|
|
89
103
|
readonly saveConfig: (ctx: KlintContexts) => (from?: KlintContexts) => KlintConfig;
|
|
90
104
|
readonly restoreConfig: (ctx: KlintContexts) => (config: KlintConfig) => void;
|
|
91
105
|
readonly resizeCanvas: (ctx: KlintContexts) => (width: number, height: number) => void;
|
|
106
|
+
readonly clipTo: (ctx: KlintContexts) => (callback: (K: KlintContexts | KlintContext) => void, fillRule?: CanvasFillRule) => void;
|
|
107
|
+
readonly canIuseFilter: (ctx: KlintContexts) => () => boolean;
|
|
108
|
+
readonly blur: (ctx: KlintContexts) => (radius: number) => void;
|
|
109
|
+
readonly SVGfilter: (ctx: KlintContexts) => (url: string) => void;
|
|
110
|
+
readonly dropShadow: (ctx: KlintContexts) => (offsetX: number, offsetY: number, blurRadius: number, color: string) => void;
|
|
111
|
+
readonly grayscale: (ctx: KlintContexts) => (amount: number) => void;
|
|
112
|
+
readonly hue: (ctx: KlintContexts) => (angle: number) => void;
|
|
113
|
+
readonly invert: (ctx: KlintContexts) => (amount: number) => void;
|
|
114
|
+
readonly filterOpacity: (ctx: KlintContexts) => (value: number) => void;
|
|
92
115
|
};
|
|
93
116
|
|
|
94
117
|
interface KlintColor {
|
|
@@ -331,7 +354,6 @@ declare class Color implements KlintColor {
|
|
|
331
354
|
}
|
|
332
355
|
|
|
333
356
|
interface KlintEasing {
|
|
334
|
-
context: KlintContexts;
|
|
335
357
|
normalize: (val: number) => number;
|
|
336
358
|
expand: (val: number) => number;
|
|
337
359
|
inout: (val: number, power?: number) => number;
|
|
@@ -342,8 +364,7 @@ interface KlintEasing {
|
|
|
342
364
|
overshootInOut: (val: number) => number;
|
|
343
365
|
}
|
|
344
366
|
declare class Easing implements KlintEasing {
|
|
345
|
-
|
|
346
|
-
constructor(ctx: KlintContexts);
|
|
367
|
+
private zeroOut;
|
|
347
368
|
normalize: (val: number) => number;
|
|
348
369
|
expand: (val: number) => number;
|
|
349
370
|
inout: (val: number, power?: number) => number;
|
|
@@ -362,30 +383,13 @@ declare class Easing implements KlintEasing {
|
|
|
362
383
|
log: () => void;
|
|
363
384
|
}
|
|
364
385
|
|
|
365
|
-
type KlintStateValue = unknown;
|
|
366
|
-
type KlintStateCallback = (key: string, value: KlintStateValue) => void;
|
|
367
|
-
interface KlintState {
|
|
368
|
-
set(key: string, value: KlintStateValue, callback?: KlintStateCallback): void;
|
|
369
|
-
get(key: string, callback?: KlintStateCallback): KlintStateValue;
|
|
370
|
-
has(key: string): boolean;
|
|
371
|
-
delete(key: string, callback?: (key: string) => void): void;
|
|
372
|
-
log(): Map<string, KlintStateValue>;
|
|
373
|
-
}
|
|
374
|
-
declare class State implements KlintState {
|
|
375
|
-
private store;
|
|
376
|
-
set(key: string, value: KlintStateValue, callback?: KlintStateCallback): void;
|
|
377
|
-
get(key: string, callback?: KlintStateCallback): unknown;
|
|
378
|
-
has(key: string): boolean;
|
|
379
|
-
delete(key: string, callback?: (key: string) => void): void;
|
|
380
|
-
log(): Map<string, unknown>;
|
|
381
|
-
}
|
|
382
|
-
|
|
383
386
|
/**
|
|
384
|
-
* Interface defining a
|
|
387
|
+
* Interface defining a 3D vector with various vector operations
|
|
385
388
|
*/
|
|
386
389
|
interface KlintVector {
|
|
387
390
|
x: number;
|
|
388
391
|
y: number;
|
|
392
|
+
z: number;
|
|
389
393
|
add: (v: KlintVector) => KlintVector;
|
|
390
394
|
sub: (v: KlintVector) => KlintVector;
|
|
391
395
|
mult: (n: number) => KlintVector;
|
|
@@ -399,21 +403,29 @@ interface KlintVector {
|
|
|
399
403
|
copy: () => KlintVector;
|
|
400
404
|
normalize: () => KlintVector;
|
|
401
405
|
set: (x: number, y: number, z?: number, w?: number) => KlintVector;
|
|
406
|
+
cross: (v: KlintVector) => KlintVector;
|
|
407
|
+
relativeTo: (v: KlintVector) => KlintVector;
|
|
408
|
+
lookAt: (target: KlintVector) => KlintVector;
|
|
409
|
+
toScreen: (width: number, height: number) => KlintVector;
|
|
410
|
+
slerp: (v: KlintVector, amt: number) => KlintVector;
|
|
402
411
|
}
|
|
403
412
|
/**
|
|
404
|
-
* A
|
|
413
|
+
* A 3D vector class with various vector operations (z=0 by default for 2D use)
|
|
405
414
|
*/
|
|
406
415
|
declare class Vector implements KlintVector {
|
|
407
416
|
/** X-coordinate of the vector */
|
|
408
417
|
x: number;
|
|
409
418
|
/** Y-coordinate of the vector */
|
|
410
419
|
y: number;
|
|
420
|
+
/** Z-coordinate of the vector */
|
|
421
|
+
z: number;
|
|
411
422
|
/**
|
|
412
423
|
* Creates a new Vector
|
|
413
424
|
* @param x - X-coordinate (default: 0)
|
|
414
425
|
* @param y - Y-coordinate (default: 0)
|
|
426
|
+
* @param z - Z-coordinate (default: 0)
|
|
415
427
|
*/
|
|
416
|
-
constructor(x?: number, y?: number);
|
|
428
|
+
constructor(x?: number, y?: number, z?: number);
|
|
417
429
|
/**
|
|
418
430
|
* Adds another vector to this vector
|
|
419
431
|
* @param v - Vector to add
|
|
@@ -439,7 +451,7 @@ declare class Vector implements KlintVector {
|
|
|
439
451
|
*/
|
|
440
452
|
div(n: number): Vector;
|
|
441
453
|
/**
|
|
442
|
-
* Rotates this vector by an angle
|
|
454
|
+
* Rotates this vector by an angle (around z-axis for 2D rotation)
|
|
443
455
|
* @param angle - Angle in radians
|
|
444
456
|
* @returns This vector after rotation
|
|
445
457
|
*/
|
|
@@ -467,7 +479,7 @@ declare class Vector implements KlintVector {
|
|
|
467
479
|
*/
|
|
468
480
|
dist(v: KlintVector): number;
|
|
469
481
|
/**
|
|
470
|
-
* Calculates the angle of this vector
|
|
482
|
+
* Calculates the angle of this vector (in 2D, ignoring z)
|
|
471
483
|
* @returns The angle in radians
|
|
472
484
|
*/
|
|
473
485
|
angle(): number;
|
|
@@ -485,9 +497,42 @@ declare class Vector implements KlintVector {
|
|
|
485
497
|
* Sets the coordinates of this vector
|
|
486
498
|
* @param x - New X-coordinate
|
|
487
499
|
* @param y - New Y-coordinate
|
|
500
|
+
* @param z - New Z-coordinate (default: 0)
|
|
488
501
|
* @returns This vector after setting coordinates
|
|
489
502
|
*/
|
|
490
|
-
set(x: number, y: number): Vector;
|
|
503
|
+
set(x: number, y: number, z?: number): Vector;
|
|
504
|
+
/**
|
|
505
|
+
* Calculates the cross product of this vector with another vector
|
|
506
|
+
* @param v - The other vector
|
|
507
|
+
* @returns A new Vector representing the cross product
|
|
508
|
+
*/
|
|
509
|
+
cross(v: KlintVector): Vector;
|
|
510
|
+
/**
|
|
511
|
+
* Calculates this vector's position relative to another vector
|
|
512
|
+
* @param v - The reference vector
|
|
513
|
+
* @returns This vector after making it relative to v
|
|
514
|
+
*/
|
|
515
|
+
relativeTo(v: KlintVector): Vector;
|
|
516
|
+
/**
|
|
517
|
+
* Makes this vector point towards a target vector
|
|
518
|
+
* @param target - The target vector to look at
|
|
519
|
+
* @returns This vector after pointing towards target
|
|
520
|
+
*/
|
|
521
|
+
lookAt(target: KlintVector): Vector;
|
|
522
|
+
/**
|
|
523
|
+
* Converts this vector from world space to screen space
|
|
524
|
+
* @param width - Screen width
|
|
525
|
+
* @param height - Screen height
|
|
526
|
+
* @returns This vector after screen space conversion
|
|
527
|
+
*/
|
|
528
|
+
toScreen(width: number, height: number): Vector;
|
|
529
|
+
/**
|
|
530
|
+
* Spherical linear interpolation between this vector and another vector
|
|
531
|
+
* @param v - The target vector
|
|
532
|
+
* @param amt - Interpolation amount (0-1)
|
|
533
|
+
* @returns This vector after interpolation
|
|
534
|
+
*/
|
|
535
|
+
slerp(v: KlintVector, amt: number): Vector;
|
|
491
536
|
/**
|
|
492
537
|
* Creates a new vector at a specified angle and distance from a center point
|
|
493
538
|
* @param center - The center point vector
|
|
@@ -498,31 +543,7 @@ declare class Vector implements KlintVector {
|
|
|
498
543
|
static fromAngle(center: Vector, a: number, r: number): Vector;
|
|
499
544
|
}
|
|
500
545
|
|
|
501
|
-
|
|
502
|
-
context: KlintContexts;
|
|
503
|
-
timeline(key: string): KlintTime;
|
|
504
|
-
use(progress: number): KlintTime;
|
|
505
|
-
for(duration: number): KlintTime;
|
|
506
|
-
}
|
|
507
|
-
declare class Time implements KlintTime {
|
|
508
|
-
context: KlintContexts;
|
|
509
|
-
private timelines;
|
|
510
|
-
private currentTimeline;
|
|
511
|
-
private readonly DEFAULT_DURATION;
|
|
512
|
-
private staggers;
|
|
513
|
-
constructor(ctx: KlintContexts);
|
|
514
|
-
timeline(key: string): this;
|
|
515
|
-
use(progress: number): this;
|
|
516
|
-
for(duration: number): this;
|
|
517
|
-
stagger(num: number, offset?: number, callback?: (progress: number, id: number, num: number) => void): this | {
|
|
518
|
-
id: number;
|
|
519
|
-
progress: number;
|
|
520
|
-
}[];
|
|
521
|
-
between(from: number | undefined, to: number | undefined, callback: (progress: number) => void): this;
|
|
522
|
-
progress(): number;
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
type TextMetrics = {
|
|
546
|
+
type TextMetrics$1 = {
|
|
526
547
|
width: number;
|
|
527
548
|
height: number;
|
|
528
549
|
baseline: number;
|
|
@@ -530,7 +551,7 @@ type TextMetrics = {
|
|
|
530
551
|
interface KlintText {
|
|
531
552
|
context: KlintContexts;
|
|
532
553
|
findTextSize: (text: string, dist: number, estimate?: number, direction?: "x" | "y") => number;
|
|
533
|
-
getTextMetrics: (text: string) => TextMetrics;
|
|
554
|
+
getTextMetrics: (text: string) => TextMetrics$1;
|
|
534
555
|
splitTo: (text: string, kind: "letters" | "words" | "lines" | "all", options?: {
|
|
535
556
|
maxWidth?: number;
|
|
536
557
|
lineSpacing?: number;
|
|
@@ -540,7 +561,7 @@ interface KlintText {
|
|
|
540
561
|
char: string;
|
|
541
562
|
x: number;
|
|
542
563
|
y: number;
|
|
543
|
-
metrics: TextMetrics;
|
|
564
|
+
metrics: TextMetrics$1;
|
|
544
565
|
letterIndex?: number;
|
|
545
566
|
wordIndex?: number;
|
|
546
567
|
lineIndex?: number;
|
|
@@ -558,7 +579,7 @@ declare class Text implements KlintText {
|
|
|
558
579
|
context: KlintContexts;
|
|
559
580
|
constructor(ctx: KlintContexts);
|
|
560
581
|
findTextSize: (text: string, dist: number, estimate?: number, direction?: "x" | "y") => number;
|
|
561
|
-
getTextMetrics: (text: string) => TextMetrics;
|
|
582
|
+
getTextMetrics: (text: string) => TextMetrics$1;
|
|
562
583
|
splitTo: (text: string, kind: "letters" | "words" | "lines" | "all", options?: {
|
|
563
584
|
maxWidth?: number;
|
|
564
585
|
lineSpacing?: number;
|
|
@@ -571,7 +592,7 @@ declare class Text implements KlintText {
|
|
|
571
592
|
char: string;
|
|
572
593
|
x: number;
|
|
573
594
|
y: number;
|
|
574
|
-
metrics: TextMetrics;
|
|
595
|
+
metrics: TextMetrics$1;
|
|
575
596
|
}[];
|
|
576
597
|
circularText: (text: string, radius?: number, fill?: "fill" | "kerned" | "words", offset?: number, arc?: number) => void;
|
|
577
598
|
textBounds: (text: string) => {
|
|
@@ -593,27 +614,728 @@ declare class Thing implements KlintThing {
|
|
|
593
614
|
log(): void;
|
|
594
615
|
}
|
|
595
616
|
|
|
617
|
+
/**
|
|
618
|
+
* Grid point interface
|
|
619
|
+
*/
|
|
620
|
+
interface GridPoint {
|
|
621
|
+
x: number;
|
|
622
|
+
y: number;
|
|
623
|
+
i: number;
|
|
624
|
+
j: number;
|
|
625
|
+
id: number;
|
|
626
|
+
}
|
|
627
|
+
/**
|
|
628
|
+
* Grid Element for Klint
|
|
629
|
+
*
|
|
630
|
+
* Provides utilities for creating rectangular and radial grids
|
|
631
|
+
*
|
|
632
|
+
* @example
|
|
633
|
+
* ```tsx
|
|
634
|
+
* const draw = (K) => {
|
|
635
|
+
* // Rectangular grid
|
|
636
|
+
* const rectGrid = K.Grid.rect(100, 100, 400, 300, 5, 4);
|
|
637
|
+
* rectGrid.forEach(point => {
|
|
638
|
+
* K.circle(point.x, point.y, 5);
|
|
639
|
+
* });
|
|
640
|
+
*
|
|
641
|
+
* // Radial grid
|
|
642
|
+
* const radialGrid = K.Grid.radial(400, 300, 100, 12, 3, 50);
|
|
643
|
+
* radialGrid.forEach(point => {
|
|
644
|
+
* K.circle(point.x, point.y, 3);
|
|
645
|
+
* });
|
|
646
|
+
* };
|
|
647
|
+
* ```
|
|
648
|
+
*/
|
|
649
|
+
declare class Grid {
|
|
650
|
+
private context;
|
|
651
|
+
/**
|
|
652
|
+
* Creates a new Grid instance
|
|
653
|
+
* @param ctx - The Klint context
|
|
654
|
+
*/
|
|
655
|
+
constructor(ctx: KlintContext);
|
|
656
|
+
/**
|
|
657
|
+
* Create a rectangular grid of points
|
|
658
|
+
* @param x - X position of the grid
|
|
659
|
+
* @param y - Y position of the grid
|
|
660
|
+
* @param width - Width of the grid
|
|
661
|
+
* @param height - Height of the grid
|
|
662
|
+
* @param countX - Number of points horizontally
|
|
663
|
+
* @param countY - Number of points vertically
|
|
664
|
+
* @param options - Grid options
|
|
665
|
+
* @returns Array of grid points
|
|
666
|
+
*/
|
|
667
|
+
rect(x: number, y: number, width: number, height: number, countX: number, countY: number, options?: {
|
|
668
|
+
origin?: 'corner' | 'center';
|
|
669
|
+
}): GridPoint[];
|
|
670
|
+
/**
|
|
671
|
+
* Create a radial grid of points
|
|
672
|
+
* @param x - Center X position
|
|
673
|
+
* @param y - Center Y position
|
|
674
|
+
* @param radius - Maximum radius
|
|
675
|
+
* @param count - Number of points per ring
|
|
676
|
+
* @param ringCount - Number of rings
|
|
677
|
+
* @param ringSpace - Space between rings
|
|
678
|
+
* @param options - Grid options
|
|
679
|
+
* @returns Array of grid points
|
|
680
|
+
*/
|
|
681
|
+
radial(x: number, y: number, radius: number, count: number, ringCount: number, ringSpace: number, options?: {
|
|
682
|
+
perStepCount?: number;
|
|
683
|
+
}): GridPoint[];
|
|
684
|
+
/**
|
|
685
|
+
* Create a hexagonal grid of points
|
|
686
|
+
* @param x - X position of the grid
|
|
687
|
+
* @param y - Y position of the grid
|
|
688
|
+
* @param width - Width of the grid area
|
|
689
|
+
* @param height - Height of the grid area
|
|
690
|
+
* @param size - Size of each hexagon
|
|
691
|
+
* @param options - Grid options
|
|
692
|
+
* @returns Array of grid points
|
|
693
|
+
*/
|
|
694
|
+
hex(x: number, y: number, width: number, height: number, size: number, options?: {
|
|
695
|
+
origin?: 'corner' | 'center';
|
|
696
|
+
pointy?: boolean;
|
|
697
|
+
}): GridPoint[];
|
|
698
|
+
/**
|
|
699
|
+
* Create a triangular grid of points
|
|
700
|
+
* @param x - X position of the grid
|
|
701
|
+
* @param y - Y position of the grid
|
|
702
|
+
* @param width - Width of the grid
|
|
703
|
+
* @param height - Height of the grid
|
|
704
|
+
* @param size - Size of each triangle
|
|
705
|
+
* @param options - Grid options
|
|
706
|
+
* @returns Array of grid points
|
|
707
|
+
*/
|
|
708
|
+
triangle(x: number, y: number, width: number, height: number, size: number, options?: {
|
|
709
|
+
origin?: 'corner' | 'center';
|
|
710
|
+
}): GridPoint[];
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
/**
|
|
714
|
+
* Triangle structure for Strip
|
|
715
|
+
*/
|
|
716
|
+
interface StripTriangle {
|
|
717
|
+
id: number;
|
|
718
|
+
center: {
|
|
719
|
+
x: number;
|
|
720
|
+
y: number;
|
|
721
|
+
};
|
|
722
|
+
points: [
|
|
723
|
+
{
|
|
724
|
+
x: number;
|
|
725
|
+
y: number;
|
|
726
|
+
},
|
|
727
|
+
{
|
|
728
|
+
x: number;
|
|
729
|
+
y: number;
|
|
730
|
+
},
|
|
731
|
+
{
|
|
732
|
+
x: number;
|
|
733
|
+
y: number;
|
|
734
|
+
}
|
|
735
|
+
];
|
|
736
|
+
}
|
|
737
|
+
/**
|
|
738
|
+
* Quad structure for Strip
|
|
739
|
+
*/
|
|
740
|
+
interface StripQuad {
|
|
741
|
+
id: number;
|
|
742
|
+
center: {
|
|
743
|
+
x: number;
|
|
744
|
+
y: number;
|
|
745
|
+
};
|
|
746
|
+
points: [
|
|
747
|
+
{
|
|
748
|
+
x: number;
|
|
749
|
+
y: number;
|
|
750
|
+
},
|
|
751
|
+
{
|
|
752
|
+
x: number;
|
|
753
|
+
y: number;
|
|
754
|
+
},
|
|
755
|
+
{
|
|
756
|
+
x: number;
|
|
757
|
+
y: number;
|
|
758
|
+
},
|
|
759
|
+
{
|
|
760
|
+
x: number;
|
|
761
|
+
y: number;
|
|
762
|
+
}
|
|
763
|
+
];
|
|
764
|
+
}
|
|
765
|
+
/**
|
|
766
|
+
* Hull structure for Strip
|
|
767
|
+
*/
|
|
768
|
+
interface StripHull {
|
|
769
|
+
id: number;
|
|
770
|
+
center: {
|
|
771
|
+
x: number;
|
|
772
|
+
y: number;
|
|
773
|
+
};
|
|
774
|
+
}
|
|
775
|
+
/**
|
|
776
|
+
* Strip Element for Klint
|
|
777
|
+
*
|
|
778
|
+
* Creates strips of triangles, quads, or hulls from a set of points
|
|
779
|
+
*
|
|
780
|
+
* @example
|
|
781
|
+
* ```tsx
|
|
782
|
+
* const draw = (K) => {
|
|
783
|
+
* const points = [];
|
|
784
|
+
* for (let i = 0; i < 20; i++) {
|
|
785
|
+
* points.push({
|
|
786
|
+
* x: 100 + i * 30,
|
|
787
|
+
* y: 300 + Math.sin(i * 0.5) * 50
|
|
788
|
+
* });
|
|
789
|
+
* }
|
|
790
|
+
*
|
|
791
|
+
* // Draw triangles
|
|
792
|
+
* K.Strip.triangles(points, (triangle) => {
|
|
793
|
+
* const { id, center } = triangle;
|
|
794
|
+
* K.circle(center.x, center.y, 3);
|
|
795
|
+
* return `hsl(${id * 30}, 70%, 50%)`;
|
|
796
|
+
* });
|
|
797
|
+
* };
|
|
798
|
+
* ```
|
|
799
|
+
*/
|
|
800
|
+
declare class Strip {
|
|
801
|
+
private context;
|
|
802
|
+
/**
|
|
803
|
+
* Creates a new Strip instance
|
|
804
|
+
* @param ctx - The Klint context
|
|
805
|
+
*/
|
|
806
|
+
constructor(ctx: KlintContext);
|
|
807
|
+
/**
|
|
808
|
+
* Create a strip of triangles from points
|
|
809
|
+
* Points are connected in a zigzag pattern:
|
|
810
|
+
* 0 - 2 - 4 ...
|
|
811
|
+
* | / | / |
|
|
812
|
+
* 1 - 3 - 5 ...
|
|
813
|
+
*
|
|
814
|
+
* @param points - Array of points (must be even number for complete triangles)
|
|
815
|
+
* @param draw - Optional callback to customize each triangle's appearance
|
|
816
|
+
*/
|
|
817
|
+
triangles(points: Array<{
|
|
818
|
+
x: number;
|
|
819
|
+
y: number;
|
|
820
|
+
}>, draw?: (triangle: StripTriangle) => string | void): void;
|
|
821
|
+
/**
|
|
822
|
+
* Create a strip of quads from points
|
|
823
|
+
* Points are connected in a grid pattern:
|
|
824
|
+
* 0 - 2 - 4 ...
|
|
825
|
+
* | | |
|
|
826
|
+
* 1 - 3 - 5 ...
|
|
827
|
+
*
|
|
828
|
+
* @param points - Array of points (must be even number for complete quads)
|
|
829
|
+
* @param draw - Optional callback to customize each quad's appearance
|
|
830
|
+
*/
|
|
831
|
+
quads(points: Array<{
|
|
832
|
+
x: number;
|
|
833
|
+
y: number;
|
|
834
|
+
}>, draw?: (quad: StripQuad) => string | void): void;
|
|
835
|
+
/**
|
|
836
|
+
* Create a single hull shape from points
|
|
837
|
+
* Points are connected following the winding order:
|
|
838
|
+
* 0 - 2 - 4 - ... n-1
|
|
839
|
+
* | |
|
|
840
|
+
* 1 - 3 - 5 - ... n
|
|
841
|
+
*
|
|
842
|
+
* Final order: 0 - 2 - 4 ... n-1, n, ... 5 - 3 - 1
|
|
843
|
+
*
|
|
844
|
+
* @param points - Array of points
|
|
845
|
+
* @param draw - Optional callback to add elements along the hull
|
|
846
|
+
*/
|
|
847
|
+
hull(points: Array<{
|
|
848
|
+
x: number;
|
|
849
|
+
y: number;
|
|
850
|
+
}>, draw?: (hull: StripHull) => void): void;
|
|
851
|
+
/**
|
|
852
|
+
* Create a ribbon/tape effect from points
|
|
853
|
+
* Similar to hull but with configurable width
|
|
854
|
+
*
|
|
855
|
+
* @param points - Array of center points
|
|
856
|
+
* @param width - Width of the ribbon
|
|
857
|
+
* @param draw - Optional callback
|
|
858
|
+
*/
|
|
859
|
+
ribbon(points: Array<{
|
|
860
|
+
x: number;
|
|
861
|
+
y: number;
|
|
862
|
+
}>, width: number, draw?: (segment: {
|
|
863
|
+
id: number;
|
|
864
|
+
center: {
|
|
865
|
+
x: number;
|
|
866
|
+
y: number;
|
|
867
|
+
};
|
|
868
|
+
}) => string | void): void;
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
type FbmOptions = {
|
|
872
|
+
octaves?: number;
|
|
873
|
+
lacunarity?: number;
|
|
874
|
+
gain?: number;
|
|
875
|
+
amplitude?: number;
|
|
876
|
+
frequency?: number;
|
|
877
|
+
};
|
|
878
|
+
type TurbulenceOptions = {
|
|
879
|
+
octaves?: number;
|
|
880
|
+
};
|
|
881
|
+
type RidgeOptions = {
|
|
882
|
+
octaves?: number;
|
|
883
|
+
amplitude?: number;
|
|
884
|
+
frequency?: number;
|
|
885
|
+
lacunarity?: number;
|
|
886
|
+
gain?: number;
|
|
887
|
+
};
|
|
888
|
+
type CellularOptions = {
|
|
889
|
+
distance?: "euclidean" | "manhattan";
|
|
890
|
+
};
|
|
891
|
+
/**
|
|
892
|
+
* Noise Element for Klint
|
|
893
|
+
*
|
|
894
|
+
* Provides Perlin noise, Simplex noise, and hash functions for procedural generation
|
|
895
|
+
* Based on implementations by Stefan Gustavson and others
|
|
896
|
+
*
|
|
897
|
+
* @example
|
|
898
|
+
* ```tsx
|
|
899
|
+
* const draw = (K) => {
|
|
900
|
+
* K.Noise.seed(42); // Optional: set seed for reproducibility
|
|
901
|
+
*
|
|
902
|
+
* // Generate terrain
|
|
903
|
+
* for (let x = 0; x < K.width; x += 5) {
|
|
904
|
+
* for (let y = 0; y < K.height; y += 5) {
|
|
905
|
+
* const n = K.Noise.perlin(x * 0.01, y * 0.01);
|
|
906
|
+
* const brightness = (n + 1) * 127;
|
|
907
|
+
* K.fillColor(`rgb(${brightness}, ${brightness}, ${brightness})`);
|
|
908
|
+
* K.rectangle(x, y, 5, 5);
|
|
909
|
+
* }
|
|
910
|
+
* }
|
|
911
|
+
* };
|
|
912
|
+
* ```
|
|
913
|
+
*/
|
|
914
|
+
declare class Noise {
|
|
915
|
+
private context;
|
|
916
|
+
private perm;
|
|
917
|
+
private permMod12;
|
|
918
|
+
private grad3;
|
|
919
|
+
private grad4;
|
|
920
|
+
private currentSeed;
|
|
921
|
+
private F2;
|
|
922
|
+
private G2;
|
|
923
|
+
private F3;
|
|
924
|
+
private G3;
|
|
925
|
+
private F4;
|
|
926
|
+
private G4;
|
|
927
|
+
/**
|
|
928
|
+
* Creates a new Noise instance
|
|
929
|
+
* @param ctx - The Klint context
|
|
930
|
+
*/
|
|
931
|
+
constructor(ctx: KlintContext);
|
|
932
|
+
/**
|
|
933
|
+
* Build permutation table for noise generation
|
|
934
|
+
*/
|
|
935
|
+
private buildPermutationTable;
|
|
936
|
+
/**
|
|
937
|
+
* Seeded random number generator
|
|
938
|
+
*/
|
|
939
|
+
private random;
|
|
940
|
+
/**
|
|
941
|
+
* Set seed for noise generation
|
|
942
|
+
* @param seed - Seed value for reproducible noise
|
|
943
|
+
*/
|
|
944
|
+
seed(seed?: number): void;
|
|
945
|
+
/**
|
|
946
|
+
* Fade function for Perlin noise
|
|
947
|
+
*/
|
|
948
|
+
private fade;
|
|
949
|
+
/**
|
|
950
|
+
* Linear interpolation
|
|
951
|
+
*/
|
|
952
|
+
private lerp;
|
|
953
|
+
/**
|
|
954
|
+
* 1D Perlin noise
|
|
955
|
+
* @param x - X coordinate
|
|
956
|
+
* @returns Noise value between -1 and 1
|
|
957
|
+
*/
|
|
958
|
+
perlin(x: number): number;
|
|
959
|
+
/**
|
|
960
|
+
* 2D Perlin noise
|
|
961
|
+
* @param x - X coordinate
|
|
962
|
+
* @param y - Y coordinate
|
|
963
|
+
* @returns Noise value between -1 and 1
|
|
964
|
+
*/
|
|
965
|
+
perlin(x: number, y: number): number;
|
|
966
|
+
/**
|
|
967
|
+
* 3D Perlin noise
|
|
968
|
+
* @param x - X coordinate
|
|
969
|
+
* @param y - Y coordinate
|
|
970
|
+
* @param z - Z coordinate
|
|
971
|
+
* @returns Noise value between -1 and 1
|
|
972
|
+
*/
|
|
973
|
+
perlin(x: number, y: number, z: number): number;
|
|
974
|
+
/**
|
|
975
|
+
* 4D Perlin noise
|
|
976
|
+
* @param x - X coordinate
|
|
977
|
+
* @param y - Y coordinate
|
|
978
|
+
* @param z - Z coordinate
|
|
979
|
+
* @param w - W coordinate
|
|
980
|
+
* @returns Noise value between -1 and 1
|
|
981
|
+
*/
|
|
982
|
+
perlin(x: number, y: number, z: number, w: number): number;
|
|
983
|
+
/**
|
|
984
|
+
* 1D Simplex noise
|
|
985
|
+
* @param x - X coordinate
|
|
986
|
+
* @returns Noise value between -1 and 1
|
|
987
|
+
*/
|
|
988
|
+
simplex(x: number): number;
|
|
989
|
+
/**
|
|
990
|
+
* 2D Simplex noise
|
|
991
|
+
* @param x - X coordinate
|
|
992
|
+
* @param y - Y coordinate
|
|
993
|
+
* @returns Noise value between -1 and 1
|
|
994
|
+
*/
|
|
995
|
+
simplex(x: number, y: number): number;
|
|
996
|
+
/**
|
|
997
|
+
* 3D Simplex noise
|
|
998
|
+
* @param x - X coordinate
|
|
999
|
+
* @param y - Y coordinate
|
|
1000
|
+
* @param z - Z coordinate
|
|
1001
|
+
* @returns Noise value between -1 and 1
|
|
1002
|
+
*/
|
|
1003
|
+
simplex(x: number, y: number, z: number): number;
|
|
1004
|
+
/**
|
|
1005
|
+
* 4D Simplex noise
|
|
1006
|
+
* @param x - X coordinate
|
|
1007
|
+
* @param y - Y coordinate
|
|
1008
|
+
* @param z - Z coordinate
|
|
1009
|
+
* @param w - W coordinate
|
|
1010
|
+
* @returns Noise value between -1 and 1
|
|
1011
|
+
*/
|
|
1012
|
+
simplex(x: number, y: number, z: number, w: number): number;
|
|
1013
|
+
/**
|
|
1014
|
+
* Dot product for 2D
|
|
1015
|
+
*/
|
|
1016
|
+
private dot2;
|
|
1017
|
+
/**
|
|
1018
|
+
* Dot product for 3D
|
|
1019
|
+
*/
|
|
1020
|
+
private dot3;
|
|
1021
|
+
/**
|
|
1022
|
+
* 1D hash function
|
|
1023
|
+
* @param x - X coordinate
|
|
1024
|
+
* @returns Hash value between 0 and 1
|
|
1025
|
+
*/
|
|
1026
|
+
hash(x: number): number;
|
|
1027
|
+
/**
|
|
1028
|
+
* 2D hash function
|
|
1029
|
+
* @param x - X coordinate
|
|
1030
|
+
* @param y - Y coordinate
|
|
1031
|
+
* @returns Hash value between 0 and 1
|
|
1032
|
+
*/
|
|
1033
|
+
hash(x: number, y: number): number;
|
|
1034
|
+
/**
|
|
1035
|
+
* 3D hash function
|
|
1036
|
+
* @param x - X coordinate
|
|
1037
|
+
* @param y - Y coordinate
|
|
1038
|
+
* @param z - Z coordinate
|
|
1039
|
+
* @returns Hash value between 0 and 1
|
|
1040
|
+
*/
|
|
1041
|
+
hash(x: number, y: number, z: number): number;
|
|
1042
|
+
/**
|
|
1043
|
+
* 4D hash function
|
|
1044
|
+
* @param x - X coordinate
|
|
1045
|
+
* @param y - Y coordinate
|
|
1046
|
+
* @param z - Z coordinate
|
|
1047
|
+
* @param w - W coordinate
|
|
1048
|
+
* @returns Hash value between 0 and 1
|
|
1049
|
+
*/
|
|
1050
|
+
hash(x: number, y: number, z: number, w: number): number;
|
|
1051
|
+
/**
|
|
1052
|
+
* Fractal Brownian Motion (fBm) noise
|
|
1053
|
+
* Supports options object for amplitude/frequency/lacunarity/gain/octaves.
|
|
1054
|
+
*/
|
|
1055
|
+
fbm(x: number, y?: number | FbmOptions, z?: number | FbmOptions, options?: FbmOptions): number;
|
|
1056
|
+
/**
|
|
1057
|
+
* Turbulence noise (absolute value of noise)
|
|
1058
|
+
* Supports options object for octaves.
|
|
1059
|
+
*/
|
|
1060
|
+
turbulence(x: number, y?: number | TurbulenceOptions, z?: number | TurbulenceOptions, options?: TurbulenceOptions): number;
|
|
1061
|
+
/**
|
|
1062
|
+
* Ridged multifractal noise (simple implementation)
|
|
1063
|
+
*/
|
|
1064
|
+
ridge(x: number, y?: number | RidgeOptions, options?: RidgeOptions): number;
|
|
1065
|
+
/**
|
|
1066
|
+
* Cellular / Worley noise (2D simple implementation)
|
|
1067
|
+
*/
|
|
1068
|
+
cellular(x: number, y?: number | CellularOptions, options?: CellularOptions): number;
|
|
1069
|
+
}
|
|
1070
|
+
|
|
1071
|
+
/**
|
|
1072
|
+
* Point interface for hotspot detection
|
|
1073
|
+
*/
|
|
1074
|
+
interface HotspotPoint {
|
|
1075
|
+
x: number;
|
|
1076
|
+
y: number;
|
|
1077
|
+
}
|
|
1078
|
+
/**
|
|
1079
|
+
* Hotspot Element for Klint
|
|
1080
|
+
*
|
|
1081
|
+
* Provides simple hit detection for various shapes
|
|
1082
|
+
*
|
|
1083
|
+
* @example
|
|
1084
|
+
* ```tsx
|
|
1085
|
+
* const draw = (K) => {
|
|
1086
|
+
* // Check if mouse is inside a circle
|
|
1087
|
+
* const isHovering = K.Hotspot.circle(K.mouse, 200, 200, 50);
|
|
1088
|
+
*
|
|
1089
|
+
* // Draw circle with hover effect
|
|
1090
|
+
* K.fillColor(isHovering ? '#ff0066' : '#333');
|
|
1091
|
+
* K.circle(200, 200, 50);
|
|
1092
|
+
*
|
|
1093
|
+
* // Rectangle hotspot
|
|
1094
|
+
* if (K.Hotspot.rect(K.mouse, 100, 100, 80, 60)) {
|
|
1095
|
+
* K.canvas.style.cursor = 'pointer';
|
|
1096
|
+
* } else {
|
|
1097
|
+
* K.canvas.style.cursor = 'default';
|
|
1098
|
+
* }
|
|
1099
|
+
* };
|
|
1100
|
+
* ```
|
|
1101
|
+
*/
|
|
1102
|
+
declare class Hotspot {
|
|
1103
|
+
private context;
|
|
1104
|
+
/**
|
|
1105
|
+
* Creates a new Hotspot instance
|
|
1106
|
+
* @param ctx - The Klint context
|
|
1107
|
+
*/
|
|
1108
|
+
constructor(ctx: KlintContext);
|
|
1109
|
+
/**
|
|
1110
|
+
* Check if point is inside a circle
|
|
1111
|
+
* @param point - Point to check (usually mouse position)
|
|
1112
|
+
* @param x - Circle center X
|
|
1113
|
+
* @param y - Circle center Y
|
|
1114
|
+
* @param radius - Circle radius
|
|
1115
|
+
* @returns True if point is inside the circle
|
|
1116
|
+
*/
|
|
1117
|
+
circle(point: HotspotPoint, x: number, y: number, radius: number): boolean;
|
|
1118
|
+
/**
|
|
1119
|
+
* Check if point is inside a rectangle
|
|
1120
|
+
* @param point - Point to check (usually mouse position)
|
|
1121
|
+
* @param x - Rectangle X position
|
|
1122
|
+
* @param y - Rectangle Y position
|
|
1123
|
+
* @param width - Rectangle width
|
|
1124
|
+
* @param height - Rectangle height
|
|
1125
|
+
* @returns True if point is inside the rectangle
|
|
1126
|
+
*/
|
|
1127
|
+
rect(point: HotspotPoint, x: number, y: number, width: number, height: number): boolean;
|
|
1128
|
+
/**
|
|
1129
|
+
* Check if point is inside an ellipse
|
|
1130
|
+
* @param point - Point to check
|
|
1131
|
+
* @param x - Ellipse center X
|
|
1132
|
+
* @param y - Ellipse center Y
|
|
1133
|
+
* @param radiusX - Horizontal radius
|
|
1134
|
+
* @param radiusY - Vertical radius
|
|
1135
|
+
* @param rotation - Rotation angle in radians
|
|
1136
|
+
* @returns True if point is inside the ellipse
|
|
1137
|
+
*/
|
|
1138
|
+
ellipse(point: HotspotPoint, x: number, y: number, radiusX: number, radiusY: number, rotation?: number): boolean;
|
|
1139
|
+
/**
|
|
1140
|
+
* Check if point is inside a polygon
|
|
1141
|
+
* @param point - Point to check
|
|
1142
|
+
* @param vertices - Array of polygon vertices
|
|
1143
|
+
* @returns True if point is inside the polygon
|
|
1144
|
+
*/
|
|
1145
|
+
polygon(point: HotspotPoint, vertices: HotspotPoint[]): boolean;
|
|
1146
|
+
/**
|
|
1147
|
+
* Check if point is inside a Path2D
|
|
1148
|
+
* @param point - Point to check
|
|
1149
|
+
* @param path - Path2D object
|
|
1150
|
+
* @returns True if point is inside the path
|
|
1151
|
+
*/
|
|
1152
|
+
path(point: HotspotPoint, path: Path2D): boolean;
|
|
1153
|
+
}
|
|
1154
|
+
|
|
1155
|
+
/**
|
|
1156
|
+
* Performance monitoring and optimization utilities for Klint
|
|
1157
|
+
*/
|
|
1158
|
+
|
|
1159
|
+
interface KlintPerformance {
|
|
1160
|
+
batchDraw: (drawFn: () => void) => void;
|
|
1161
|
+
useOffscreenCache: (id: string, width: number, height: number, renderFn: (offscreenCtx: KlintContext) => void) => void;
|
|
1162
|
+
throttleFrame: <T>(interval: number, fn: () => T) => T;
|
|
1163
|
+
useLeakDetection: () => {
|
|
1164
|
+
track: (type: string) => void;
|
|
1165
|
+
check: () => void;
|
|
1166
|
+
};
|
|
1167
|
+
getCachedTextMetrics: (text: string, font: string) => TextMetrics;
|
|
1168
|
+
clearCaches: () => void;
|
|
1169
|
+
render: (options?: PerformanceWidgetOptions) => void;
|
|
1170
|
+
show: (options?: PerformanceWidgetOptions) => void;
|
|
1171
|
+
getMetrics: () => KlintPerformanceMetrics | null;
|
|
1172
|
+
}
|
|
1173
|
+
interface PerformanceWidgetOptions {
|
|
1174
|
+
x?: number;
|
|
1175
|
+
y?: number;
|
|
1176
|
+
width?: number;
|
|
1177
|
+
height?: number;
|
|
1178
|
+
backgroundColor?: string;
|
|
1179
|
+
textColor?: string;
|
|
1180
|
+
accentColor?: string;
|
|
1181
|
+
showGraph?: boolean;
|
|
1182
|
+
graphHeight?: number;
|
|
1183
|
+
fontSize?: number;
|
|
1184
|
+
showMemory?: boolean;
|
|
1185
|
+
}
|
|
1186
|
+
declare class Performance implements KlintPerformance {
|
|
1187
|
+
private context;
|
|
1188
|
+
private textMetricsCache;
|
|
1189
|
+
private frameTimeHistory;
|
|
1190
|
+
private readonly MAX_HISTORY;
|
|
1191
|
+
constructor(ctx: KlintContext);
|
|
1192
|
+
/**
|
|
1193
|
+
* Batch multiple canvas operations together for better performance
|
|
1194
|
+
*/
|
|
1195
|
+
batchDraw(drawFn: () => void): void;
|
|
1196
|
+
/**
|
|
1197
|
+
* Optimize drawing by using offscreen canvas for static elements
|
|
1198
|
+
*/
|
|
1199
|
+
useOffscreenCache(id: string, width: number, height: number, renderFn: (offscreenCtx: KlintContext) => void): void;
|
|
1200
|
+
/**
|
|
1201
|
+
* Throttle expensive operations to run less frequently
|
|
1202
|
+
*/
|
|
1203
|
+
throttleFrame<T>(interval: number, fn: () => T): T;
|
|
1204
|
+
/**
|
|
1205
|
+
* Detect potential memory leaks by tracking object creation
|
|
1206
|
+
*/
|
|
1207
|
+
useLeakDetection(): {
|
|
1208
|
+
track: (type: string) => void;
|
|
1209
|
+
check: () => void;
|
|
1210
|
+
};
|
|
1211
|
+
/**
|
|
1212
|
+
* Optimize text rendering by caching text measurements
|
|
1213
|
+
*/
|
|
1214
|
+
getCachedTextMetrics(text: string, font: string): TextMetrics;
|
|
1215
|
+
/**
|
|
1216
|
+
* Clear all performance caches
|
|
1217
|
+
*/
|
|
1218
|
+
clearCaches(): void;
|
|
1219
|
+
/**
|
|
1220
|
+
* Get current performance metrics
|
|
1221
|
+
*/
|
|
1222
|
+
getMetrics(): KlintPerformanceMetrics | null;
|
|
1223
|
+
/**
|
|
1224
|
+
* Render performance widget on canvas
|
|
1225
|
+
*/
|
|
1226
|
+
render(options?: PerformanceWidgetOptions): void;
|
|
1227
|
+
/**
|
|
1228
|
+
* Alias for render() - shows performance widget
|
|
1229
|
+
*/
|
|
1230
|
+
show(options?: PerformanceWidgetOptions): void;
|
|
1231
|
+
}
|
|
1232
|
+
|
|
1233
|
+
/**
|
|
1234
|
+
* Server-Side Rendering (SSR) utilities for Klint
|
|
1235
|
+
* Provides utilities for rendering Klint sketches on the server
|
|
1236
|
+
* or generating static images without requiring a browser environment.
|
|
1237
|
+
*/
|
|
1238
|
+
|
|
1239
|
+
interface KlintServerRenderOptions {
|
|
1240
|
+
width: number;
|
|
1241
|
+
height: number;
|
|
1242
|
+
dpr?: number;
|
|
1243
|
+
format?: "png" | "jpeg" | "webp";
|
|
1244
|
+
quality?: number;
|
|
1245
|
+
}
|
|
1246
|
+
interface KlintSSR {
|
|
1247
|
+
/**
|
|
1248
|
+
* Render a Klint sketch to a static image (base64 data URL)
|
|
1249
|
+
* Useful for Server Components, static site generation, or previews
|
|
1250
|
+
*/
|
|
1251
|
+
renderToImage: (draw: (ctx: KlintContext) => void, options: KlintServerRenderOptions) => Promise<string>;
|
|
1252
|
+
/**
|
|
1253
|
+
* Generate a static image URL for a Klint sketch
|
|
1254
|
+
* This can be used in Server Components to generate images at build time
|
|
1255
|
+
*/
|
|
1256
|
+
generateImageUrl: (draw: (ctx: KlintContext) => void, options: KlintServerRenderOptions) => Promise<string>;
|
|
1257
|
+
/**
|
|
1258
|
+
* Check if Klint can run in the current environment
|
|
1259
|
+
*/
|
|
1260
|
+
canRender: () => boolean;
|
|
1261
|
+
}
|
|
1262
|
+
declare class SSR implements KlintSSR {
|
|
1263
|
+
private context;
|
|
1264
|
+
constructor(ctx?: KlintContext);
|
|
1265
|
+
/**
|
|
1266
|
+
* Render a Klint sketch to a static image (base64 data URL)
|
|
1267
|
+
*/
|
|
1268
|
+
renderToImage(draw: (ctx: KlintContext) => void, options: KlintServerRenderOptions): Promise<string>;
|
|
1269
|
+
/**
|
|
1270
|
+
* Generate a static image URL for a Klint sketch
|
|
1271
|
+
*/
|
|
1272
|
+
generateImageUrl(draw: (ctx: KlintContext) => void, options: KlintServerRenderOptions): Promise<string>;
|
|
1273
|
+
/**
|
|
1274
|
+
* Check if Klint can run in the current environment
|
|
1275
|
+
*/
|
|
1276
|
+
canRender(): boolean;
|
|
1277
|
+
/**
|
|
1278
|
+
* Render in browser environment (client-side)
|
|
1279
|
+
*/
|
|
1280
|
+
private renderInBrowser;
|
|
1281
|
+
/**
|
|
1282
|
+
* Create a minimal KlintContext for server rendering
|
|
1283
|
+
* This provides basic functionality without full Klint features
|
|
1284
|
+
*/
|
|
1285
|
+
private createMinimalContext;
|
|
1286
|
+
}
|
|
1287
|
+
|
|
596
1288
|
interface KlintElements {
|
|
597
1289
|
Color: Color;
|
|
598
1290
|
Easing: Easing;
|
|
599
|
-
State: State;
|
|
600
1291
|
Vector: Vector;
|
|
601
|
-
Time: Time;
|
|
602
1292
|
Text: Text;
|
|
603
1293
|
Thing: Thing;
|
|
1294
|
+
Grid: Grid;
|
|
1295
|
+
Strip: Strip;
|
|
1296
|
+
Noise: Noise;
|
|
1297
|
+
Hotspot: Hotspot;
|
|
1298
|
+
Performance: Performance;
|
|
1299
|
+
SSR: SSR;
|
|
604
1300
|
}
|
|
605
1301
|
|
|
606
1302
|
declare const EPSILON = 0.0001;
|
|
607
1303
|
type KlintContexts = KlintContext | KlintOffscreenContext;
|
|
1304
|
+
type CurveVertex = {
|
|
1305
|
+
type: "line";
|
|
1306
|
+
x: number;
|
|
1307
|
+
y: number;
|
|
1308
|
+
} | {
|
|
1309
|
+
type: "bezier";
|
|
1310
|
+
cp1x: number;
|
|
1311
|
+
cp1y: number;
|
|
1312
|
+
cp2x: number;
|
|
1313
|
+
cp2y: number;
|
|
1314
|
+
x: number;
|
|
1315
|
+
y: number;
|
|
1316
|
+
} | {
|
|
1317
|
+
type: "quadratic";
|
|
1318
|
+
cpx: number;
|
|
1319
|
+
cpy: number;
|
|
1320
|
+
x: number;
|
|
1321
|
+
y: number;
|
|
1322
|
+
} | {
|
|
1323
|
+
type: "arc";
|
|
1324
|
+
x1: number;
|
|
1325
|
+
y1: number;
|
|
1326
|
+
x2: number;
|
|
1327
|
+
y2: number;
|
|
1328
|
+
radius: number;
|
|
1329
|
+
};
|
|
608
1330
|
interface KlintOffscreenContext extends CanvasRenderingContext2D, KlintFunctions, KlintElements {
|
|
609
1331
|
width: number;
|
|
610
1332
|
height: number;
|
|
611
1333
|
__dpr: number;
|
|
612
1334
|
__startedShape: boolean;
|
|
613
|
-
__currentShape:
|
|
1335
|
+
__currentShape: CurveVertex[] | null;
|
|
614
1336
|
__startedContour: boolean;
|
|
615
|
-
__currentContours:
|
|
616
|
-
__currentContour:
|
|
1337
|
+
__currentContours: CurveVertex[][] | null;
|
|
1338
|
+
__currentContour: CurveVertex[] | null;
|
|
617
1339
|
__isReadyToDraw: boolean;
|
|
618
1340
|
__isMainContext: boolean;
|
|
619
1341
|
__imageOrigin: "corner" | "center";
|
|
@@ -622,15 +1344,26 @@ interface KlintOffscreenContext extends CanvasRenderingContext2D, KlintFunctions
|
|
|
622
1344
|
__computedTextFont: string;
|
|
623
1345
|
__textFont: string;
|
|
624
1346
|
__textSize: number;
|
|
1347
|
+
__textLeading: number | undefined;
|
|
625
1348
|
__textStyle: string;
|
|
626
1349
|
__textWeight: string;
|
|
627
1350
|
__textAlignment: {
|
|
628
1351
|
horizontal: CanvasTextAlign;
|
|
629
1352
|
vertical: CanvasTextBaseline;
|
|
630
1353
|
};
|
|
1354
|
+
__fillRule: CanvasFillRule;
|
|
631
1355
|
createVector: (x: number, y: number) => Vector;
|
|
632
1356
|
[key: string]: any;
|
|
633
1357
|
}
|
|
1358
|
+
interface KlintPerformanceMetrics {
|
|
1359
|
+
fps: number;
|
|
1360
|
+
frameTime: number;
|
|
1361
|
+
averageFrameTime: number;
|
|
1362
|
+
minFrameTime: number;
|
|
1363
|
+
maxFrameTime: number;
|
|
1364
|
+
droppedFrames: number;
|
|
1365
|
+
memoryUsage?: number;
|
|
1366
|
+
}
|
|
634
1367
|
interface KlintContext extends KlintOffscreenContext, KlintCoreFunctions {
|
|
635
1368
|
frame: number;
|
|
636
1369
|
time: number;
|
|
@@ -640,6 +1373,7 @@ interface KlintContext extends KlintOffscreenContext, KlintCoreFunctions {
|
|
|
640
1373
|
__lastRealTime: number;
|
|
641
1374
|
__isPlaying: boolean;
|
|
642
1375
|
__offscreens: Map<string, KlintOffscreenContext | HTMLImageElement>;
|
|
1376
|
+
__performance?: KlintPerformanceMetrics;
|
|
643
1377
|
}
|
|
644
1378
|
interface KlintCanvasOptions {
|
|
645
1379
|
alpha?: string;
|
|
@@ -660,7 +1394,7 @@ interface KlintContextWrapper {
|
|
|
660
1394
|
context: KlintContext | null;
|
|
661
1395
|
initCoreContext: (canvas: HTMLCanvasElement, options: KlintCanvasOptions) => KlintContext;
|
|
662
1396
|
}
|
|
663
|
-
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"];
|
|
1397
|
+
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", "__textLeading", "__textAlignment", "__fillRule", "__isPlaying"];
|
|
664
1398
|
interface KlintProps {
|
|
665
1399
|
context: KlintContextWrapper;
|
|
666
1400
|
draw: (ctx: KlintContext) => void;
|
|
@@ -669,8 +1403,9 @@ interface KlintProps {
|
|
|
669
1403
|
options?: KlintCanvasOptions;
|
|
670
1404
|
onResize?: (ctx: KlintContext) => void;
|
|
671
1405
|
onVisible?: (ctx: KlintContext) => void;
|
|
1406
|
+
enablePerformanceTracking?: boolean;
|
|
672
1407
|
}
|
|
673
|
-
declare function Klint({ context, setup, draw, options, preload, onVisible, }: KlintProps): React.JSX.Element;
|
|
1408
|
+
declare function Klint({ context, setup, draw, options, preload, onVisible, enablePerformanceTracking, }: KlintProps): React.JSX.Element;
|
|
674
1409
|
|
|
675
1410
|
interface KlintMouse {
|
|
676
1411
|
x: number;
|
|
@@ -705,6 +1440,17 @@ interface KlintGesture {
|
|
|
705
1440
|
lastX: number;
|
|
706
1441
|
lastY: number;
|
|
707
1442
|
}
|
|
1443
|
+
interface KlintKeyboard {
|
|
1444
|
+
pressedKeys: Set<string>;
|
|
1445
|
+
modifiers: {
|
|
1446
|
+
alt: boolean;
|
|
1447
|
+
shift: boolean;
|
|
1448
|
+
ctrl: boolean;
|
|
1449
|
+
meta: boolean;
|
|
1450
|
+
};
|
|
1451
|
+
lastKey: string | null;
|
|
1452
|
+
lastKeyTime: number;
|
|
1453
|
+
}
|
|
708
1454
|
declare function useKlint(): {
|
|
709
1455
|
context: {
|
|
710
1456
|
context: KlintContext | null;
|
|
@@ -732,6 +1478,15 @@ declare function useKlint(): {
|
|
|
732
1478
|
onTouchMove: (callback: (ctx: KlintContext, e: TouchEvent, gesture: KlintGesture) => void) => (ctx: KlintContext, e: TouchEvent, gesture: KlintGesture) => void;
|
|
733
1479
|
onTouchEnd: (callback: (ctx: KlintContext, e: TouchEvent, gesture: KlintGesture) => void) => (ctx: KlintContext, e: TouchEvent, gesture: KlintGesture) => void;
|
|
734
1480
|
};
|
|
1481
|
+
KlintKeyboard: () => {
|
|
1482
|
+
keyboard: KlintKeyboard;
|
|
1483
|
+
keyPressed: (key: string, callback: (ctx: KlintContext, e: KeyboardEvent) => void) => void;
|
|
1484
|
+
keyReleased: (key: string, callback: (ctx: KlintContext, e: KeyboardEvent) => void) => void;
|
|
1485
|
+
keyCombo: (keys: string[], callback: (ctx: KlintContext, e: KeyboardEvent) => void) => void;
|
|
1486
|
+
isPressed: (key: string) => boolean;
|
|
1487
|
+
arePressed: (keys: string[]) => boolean;
|
|
1488
|
+
clearCallbacks: () => void;
|
|
1489
|
+
};
|
|
735
1490
|
KlintWindow: () => {
|
|
736
1491
|
onResize: (callback: (ctx: KlintContext) => void) => (ctx: KlintContext) => void;
|
|
737
1492
|
onBlur: (callback: (ctx: KlintContext) => void) => (ctx: KlintContext) => void;
|
|
@@ -750,6 +1505,32 @@ declare function useKlint(): {
|
|
|
750
1505
|
hasImage: (key: string) => boolean;
|
|
751
1506
|
clearImages: () => void;
|
|
752
1507
|
};
|
|
1508
|
+
KlintTimeline: () => {
|
|
1509
|
+
Timeline: {
|
|
1510
|
+
create: <T extends Record<string, any>>(setup: (timeline: any) => T, options?: {
|
|
1511
|
+
defaultEasing?: (t: number) => number;
|
|
1512
|
+
defaultLoop?: number;
|
|
1513
|
+
}) => T & {
|
|
1514
|
+
update: (progress: number) => void;
|
|
1515
|
+
};
|
|
1516
|
+
};
|
|
1517
|
+
onStart: (fn: () => void) => number;
|
|
1518
|
+
onEnd: (fn: () => void) => number;
|
|
1519
|
+
onLoop: (fn: () => void) => number;
|
|
1520
|
+
};
|
|
1521
|
+
KlintPerformance: () => {
|
|
1522
|
+
metrics: {
|
|
1523
|
+
fps: number;
|
|
1524
|
+
frameTime: number;
|
|
1525
|
+
averageFrameTime: number;
|
|
1526
|
+
minFrameTime: number;
|
|
1527
|
+
maxFrameTime: number;
|
|
1528
|
+
droppedFrames: number;
|
|
1529
|
+
memoryUsage?: number;
|
|
1530
|
+
} | null;
|
|
1531
|
+
getMetrics: () => KlintPerformanceMetrics | null;
|
|
1532
|
+
reset: () => void;
|
|
1533
|
+
};
|
|
753
1534
|
togglePlay: (playing?: boolean) => void;
|
|
754
1535
|
useDev: () => void;
|
|
755
1536
|
};
|
|
@@ -766,4 +1547,4 @@ declare const useStorage: <T extends object = Record<string, unknown>>(initialPr
|
|
|
766
1547
|
store: T;
|
|
767
1548
|
};
|
|
768
1549
|
|
|
769
|
-
export { CONFIG_PROPS, EPSILON, Klint, type KlintCanvasOptions, type KlintConfig, type KlintContext, type KlintContextWrapper, type KlintContexts, KlintCoreFunctions, KlintFunctions, type KlintMouse, type KlintOffscreenContext, type KlintProps, type KlintScroll, useKlint, useProps, useStorage };
|
|
1550
|
+
export { CONFIG_PROPS, Color, type CurveVertex, EPSILON, Easing, Grid, Hotspot, Klint, type KlintCanvasOptions, type KlintConfig, type KlintContext, type KlintContextWrapper, type KlintContexts, KlintCoreFunctions, type KlintElements, KlintFunctions, type KlintMouse, type KlintOffscreenContext, type KlintPerformanceMetrics, type KlintProps, type KlintScroll, type KlintServerRenderOptions, Noise, Performance, type PerformanceWidgetOptions, SSR, Strip, Text, Thing, Vector, useKlint, useProps, useStorage };
|