@shopify/klint 0.3.1 → 0.4.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.
@@ -10,11 +10,6 @@ declare const KlintCoreFunctions: {
10
10
  play: (ctx: KlintContext) => () => void;
11
11
  pause: (ctx: KlintContext) => () => void;
12
12
  redraw: () => () => void;
13
- extend: (ctx: KlintContext) => (name: string, data: unknown, enforceReplace?: boolean) => void;
14
- passImage: () => (element: HTMLImageElement) => HTMLImageElement | null;
15
- passImages: () => (elements: HTMLImageElement[]) => (HTMLImageElement | null)[];
16
- saveConfig: (ctx: KlintContexts) => (from?: KlintContexts) => KlintConfig;
17
- restoreConfig: (ctx: KlintContext) => (config: KlintConfig) => void;
18
13
  describe: (ctx: KlintContext) => (description: string) => void;
19
14
  createOffscreen: (ctx: KlintContext) => (id: string, width: number, height: number, options?: KlintCanvasOptions, callback?: (ctx: KlintOffscreenContext) => void) => KlintOffscreenContext | HTMLImageElement;
20
15
  getOffscreen: (ctx: KlintContext) => (id: string) => KlintOffscreenContext | HTMLImageElement;
@@ -89,12 +84,11 @@ declare const KlintFunctions: {
89
84
  break?: "words" | "letters";
90
85
  }) => void;
91
86
  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;
92
- readonly loadPixels: (ctx: KlintContexts) => () => ImageData;
93
- readonly updatePixels: (ctx: KlintContexts) => (pixels: Uint8ClampedArray | number[]) => void;
94
- readonly readPixels: (ctx: KlintContexts) => (x: number, y: number, w?: number, h?: number) => number[];
95
87
  readonly scaleTo: () => (originWidth: number, originHeight: number, destinationWidth: number, destinationHeight: number, cover?: boolean) => number;
96
88
  readonly opacity: (ctx: KlintContexts) => (value: number) => void;
97
89
  readonly blend: (ctx: KlintContexts) => (blend: GlobalCompositeOperation | "default") => void;
90
+ readonly smooth: (ctx: KlintContexts) => () => void;
91
+ readonly noSmooth: (ctx: KlintContexts) => () => void;
98
92
  readonly setCanvasOrigin: (ctx: KlintContexts) => (type: "center" | "corner") => void;
99
93
  readonly setImageOrigin: (ctx: KlintContexts) => (type: "center" | "corner") => void;
100
94
  readonly setRectOrigin: (ctx: KlintContexts) => (type: "center" | "corner") => void;
@@ -104,6 +98,22 @@ declare const KlintFunctions: {
104
98
  readonly restoreConfig: (ctx: KlintContexts) => (config: KlintConfig) => void;
105
99
  readonly resizeCanvas: (ctx: KlintContexts) => (width: number, height: number) => void;
106
100
  readonly clipTo: (ctx: KlintContexts) => (callback: (K: KlintContexts | KlintContext) => void, fillRule?: CanvasFillRule) => void;
101
+ readonly screenToWorld: (ctx: KlintContexts) => (screenX: number, screenY: number) => {
102
+ x: number;
103
+ y: number;
104
+ };
105
+ readonly worldToScreen: (ctx: KlintContexts) => (worldX: number, worldY: number) => {
106
+ x: number;
107
+ y: number;
108
+ };
109
+ readonly getVisibleBounds: (ctx: KlintContexts) => () => {
110
+ left: number;
111
+ top: number;
112
+ right: number;
113
+ bottom: number;
114
+ width: number;
115
+ height: number;
116
+ };
107
117
  readonly canIuseFilter: (ctx: KlintContexts) => () => boolean;
108
118
  readonly blur: (ctx: KlintContexts) => (radius: number) => void;
109
119
  readonly SVGfilter: (ctx: KlintContexts) => (url: string) => void;
@@ -362,6 +372,18 @@ interface KlintEasing {
362
372
  overshootIn: (val: number) => number;
363
373
  overshootOut: (val: number) => number;
364
374
  overshootInOut: (val: number) => number;
375
+ bounceIn: (val: number) => number;
376
+ bounceOut: (val: number) => number;
377
+ bounceInOut: (val: number) => number;
378
+ elasticIn: (val: number) => number;
379
+ elasticOut: (val: number) => number;
380
+ elasticInOut: (val: number) => number;
381
+ smoothstep: (val: number, x0?: number, x1?: number) => number;
382
+ spring: (val: number, tension?: number, friction?: number) => number;
383
+ steps: (val: number, n?: number) => number;
384
+ damp: (current: number, target: number, smoothing: number, deltaTime: number) => number;
385
+ impulse: (val: number, k?: number) => number;
386
+ parabola: (val: number, k?: number) => number;
365
387
  }
366
388
  declare class Easing implements KlintEasing {
367
389
  private zeroOut;
@@ -380,6 +402,40 @@ declare class Easing implements KlintEasing {
380
402
  elasticOut: (val: number) => number;
381
403
  elasticInOut: (val: number) => number;
382
404
  smoothstep: (val: number, x0?: number, x1?: number) => number;
405
+ /**
406
+ * Damped spring easing. Physically expressive oscillation.
407
+ * @param val - Progress value (0 to 1)
408
+ * @param tension - Spring tension (0 to 1, default 0.5). Higher = faster oscillation.
409
+ * @param friction - Spring friction (0 to 1, default 0.5). Higher = less damping (more bouncy).
410
+ */
411
+ spring: (val: number, tension?: number, friction?: number) => number;
412
+ /**
413
+ * Staircase easing. Quantizes to N discrete steps.
414
+ * @param val - Progress value (0 to 1)
415
+ * @param n - Number of steps (default 4)
416
+ */
417
+ steps: (val: number, n?: number) => number;
418
+ /**
419
+ * Frame-rate independent exponential smoothing.
420
+ * Use instead of naive `lerp(a, b, 0.1)` which breaks at different FPS.
421
+ * @param current - Current value
422
+ * @param target - Target value
423
+ * @param smoothing - Smoothing factor (higher = faster convergence)
424
+ * @param deltaTime - Time since last frame in seconds
425
+ */
426
+ damp: (current: number, target: number, smoothing: number, deltaTime: number) => number;
427
+ /**
428
+ * Quick rise then decay. Great for hit effects, flashes.
429
+ * @param val - Progress value (0 to 1)
430
+ * @param k - Sharpness (default 6). Higher = sharper peak.
431
+ */
432
+ impulse: (val: number, k?: number) => number;
433
+ /**
434
+ * Symmetric arc. Useful for jumps, throw curves.
435
+ * @param val - Progress value (0 to 1)
436
+ * @param k - Steepness (default 1)
437
+ */
438
+ parabola: (val: number, k?: number) => number;
383
439
  log: () => void;
384
440
  }
385
441
 
@@ -543,7 +599,7 @@ declare class Vector implements KlintVector {
543
599
  static fromAngle(center: Vector, a: number, r: number): Vector;
544
600
  }
545
601
 
546
- type TextMetrics$1 = {
602
+ type TextMetrics = {
547
603
  width: number;
548
604
  height: number;
549
605
  baseline: number;
@@ -551,7 +607,7 @@ type TextMetrics$1 = {
551
607
  interface KlintText {
552
608
  context: KlintContexts;
553
609
  findTextSize: (text: string, dist: number, estimate?: number, direction?: "x" | "y") => number;
554
- getTextMetrics: (text: string) => TextMetrics$1;
610
+ getTextMetrics: (text: string) => TextMetrics;
555
611
  splitTo: (text: string, kind: "letters" | "words" | "lines" | "all", options?: {
556
612
  maxWidth?: number;
557
613
  lineSpacing?: number;
@@ -561,7 +617,7 @@ interface KlintText {
561
617
  char: string;
562
618
  x: number;
563
619
  y: number;
564
- metrics: TextMetrics$1;
620
+ metrics: TextMetrics;
565
621
  letterIndex?: number;
566
622
  wordIndex?: number;
567
623
  lineIndex?: number;
@@ -579,7 +635,7 @@ declare class Text implements KlintText {
579
635
  context: KlintContexts;
580
636
  constructor(ctx: KlintContexts);
581
637
  findTextSize: (text: string, dist: number, estimate?: number, direction?: "x" | "y") => number;
582
- getTextMetrics: (text: string) => TextMetrics$1;
638
+ getTextMetrics: (text: string) => TextMetrics;
583
639
  splitTo: (text: string, kind: "letters" | "words" | "lines" | "all", options?: {
584
640
  maxWidth?: number;
585
641
  lineSpacing?: number;
@@ -592,7 +648,7 @@ declare class Text implements KlintText {
592
648
  char: string;
593
649
  x: number;
594
650
  y: number;
595
- metrics: TextMetrics$1;
651
+ metrics: TextMetrics;
596
652
  }[];
597
653
  circularText: (text: string, radius?: number, fill?: "fill" | "kerned" | "words", offset?: number, arc?: number) => void;
598
654
  textBounds: (text: string) => {
@@ -604,16 +660,6 @@ declare class Text implements KlintText {
604
660
  log: () => void;
605
661
  }
606
662
 
607
- interface KlintThing {
608
- context: KlintContexts;
609
- log(): void;
610
- }
611
- declare class Thing implements KlintThing {
612
- context: KlintContexts;
613
- constructor(ctx: KlintContexts);
614
- log(): void;
615
- }
616
-
617
663
  /**
618
664
  * Grid point interface
619
665
  */
@@ -868,204 +914,56 @@ declare class Strip {
868
914
  }) => string | void): void;
869
915
  }
870
916
 
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
917
  /**
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
918
+ * Noise Perlin (1-4D), Simplex (1-4D), Hash (1-4D), Gaussian random
896
919
  *
897
920
  * @example
898
921
  * ```tsx
899
922
  * 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
- * }
923
+ * K.Noise.seed(42);
924
+ * const n = K.Noise.perlin(x * 0.01, y * 0.01);
911
925
  * };
912
926
  * ```
913
927
  */
914
928
  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
- */
929
+ private p;
930
+ private _seed;
931
+ private static readonly F2;
932
+ private static readonly G2;
933
+ private static readonly F3;
934
+ private static readonly G3;
935
+ private static readonly F4;
936
+ private static readonly G4;
937
+ constructor(_ctx: KlintContext);
938
+ private rng;
939
+ private buildPerm;
940
+ /** Set seed for reproducible noise */
941
+ seed(s?: number): void;
942
+ private static fade;
943
+ private static lerp;
944
+ /** Improved Perlin gradient — maps 4-bit hash to one of 12 gradient directions */
945
+ private static grad3;
958
946
  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
947
  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
948
  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
949
  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
- */
950
+ private perlin1;
951
+ private perlin2;
952
+ private perlin3;
953
+ private perlin4;
988
954
  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
955
  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
956
  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
957
  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
- */
958
+ private simplex2;
959
+ private simplex3;
960
+ private simplex4;
1026
961
  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
962
  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
963
  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
964
  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;
965
+ /** Box-Muller transform — returns normally distributed random number (seeded) */
966
+ gaussianRandom(mean?: number, stddev?: number): number;
1069
967
  }
1070
968
 
1071
969
  /**
@@ -1153,136 +1051,121 @@ declare class Hotspot {
1153
1051
  }
1154
1052
 
1155
1053
  /**
1156
- * Performance monitoring and optimization utilities for Klint
1054
+ * Point with at least x, y — can carry any extra data.
1157
1055
  */
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;
1056
+ interface QuadtreePoint {
1057
+ x: number;
1058
+ y: number;
1059
+ [key: string]: any;
1172
1060
  }
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;
1061
+ /**
1062
+ * Center-based rectangular bounds (x, y = center, w, h = half-extents).
1063
+ */
1064
+ declare class Rectangle {
1065
+ x: number;
1066
+ y: number;
1067
+ w: number;
1068
+ h: number;
1069
+ constructor(x: number, y: number, w: number, h: number);
1070
+ contains(point: QuadtreePoint): boolean;
1071
+ intersects(range: Rectangle): boolean;
1072
+ intersectsCircle(cx: number, cy: number, r: number): boolean;
1185
1073
  }
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;
1074
+ /**
1075
+ * Quadtree — spatial partitioning for efficient neighbor queries.
1076
+ *
1077
+ * Uses center-based bounds. Create with `Quadtree.create()`.
1078
+ *
1079
+ * @example
1080
+ * ```tsx
1081
+ * const qt = K.Quadtree.create(0, 0, K.width, K.height);
1082
+ * particles.forEach(p => qt.insert(p));
1083
+ * const nearby = qt.queryRadius(mouseX, mouseY, 100);
1084
+ * ```
1085
+ */
1086
+ declare class Quadtree<T extends QuadtreePoint = QuadtreePoint> {
1087
+ private boundary;
1088
+ private capacity;
1089
+ private maxDepth;
1090
+ private depth;
1091
+ private points;
1092
+ private divided;
1093
+ private ne;
1094
+ private nw;
1095
+ private se;
1096
+ private sw;
1097
+ constructor(boundary: Rectangle, capacity?: number, maxDepth?: number, depth?: number);
1098
+ /**
1099
+ * Create a Quadtree from corner-based bounds (top-left + size).
1100
+ * Internally converts to center-based representation.
1101
+ */
1102
+ static create<T extends QuadtreePoint = QuadtreePoint>(x: number, y: number, width: number, height: number, options?: {
1103
+ capacity?: number;
1104
+ maxDepth?: number;
1105
+ }): Quadtree<T>;
1106
+ insert(point: T): boolean;
1107
+ private subdivide;
1108
+ query(range: Rectangle, found?: T[]): T[];
1109
+ queryRadius(cx: number, cy: number, radius: number, found?: T[]): T[];
1110
+ clear(): void;
1111
+ get size(): number;
1231
1112
  }
1232
1113
 
1233
1114
  /**
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.
1115
+ * Pixels Element for Klint
1116
+ *
1117
+ * Provides pixel-level read/write access to the canvas.
1118
+ *
1119
+ * @example
1120
+ * ```tsx
1121
+ * const draw = (K) => {
1122
+ * // Read all pixels
1123
+ * const imageData = K.Pixels.load();
1124
+ *
1125
+ * // Read a single pixel
1126
+ * const [r, g, b, a] = K.Pixels.read(100, 100);
1127
+ *
1128
+ * // Modify and write back
1129
+ * K.Pixels.update(imageData.data);
1130
+ * };
1131
+ * ```
1237
1132
  */
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 {
1133
+ declare class Pixels {
1134
+ private ctx;
1135
+ constructor(ctx: KlintContexts);
1247
1136
  /**
1248
- * Render a Klint sketch to a static image (base64 data URL)
1249
- * Useful for Server Components, static site generation, or previews
1137
+ * Read all pixels from the canvas as ImageData.
1250
1138
  */
1251
- renderToImage: (draw: (ctx: KlintContext) => void, options: KlintServerRenderOptions) => Promise<string>;
1139
+ load(): ImageData;
1252
1140
  /**
1253
- * Generate a static image URL for a Klint sketch
1254
- * This can be used in Server Components to generate images at build time
1141
+ * Write pixel data back to the canvas.
1142
+ * Accepts a Uint8ClampedArray or a plain number array of RGBA values.
1255
1143
  */
1256
- generateImageUrl: (draw: (ctx: KlintContext) => void, options: KlintServerRenderOptions) => Promise<string>;
1144
+ update(pixels: Uint8ClampedArray | number[]): void;
1257
1145
  /**
1258
- * Check if Klint can run in the current environment
1146
+ * Read pixel values at a position.
1147
+ * Returns an array of [r, g, b, a] values (0-255).
1148
+ *
1149
+ * @param x - X coordinate
1150
+ * @param y - Y coordinate
1151
+ * @param w - Width of region (default: 1)
1152
+ * @param h - Height of region (default: 1)
1259
1153
  */
1260
- canRender: () => boolean;
1154
+ read(x: number, y: number, w?: number, h?: number): number[];
1261
1155
  }
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;
1156
+
1157
+ declare class Timeline {
1158
+ private callbacks;
1159
+ constructor();
1160
+ onStart(fn: () => void): void;
1161
+ onEnd(fn: () => void): void;
1162
+ onLoop(fn: () => void): void;
1163
+ create<T extends Record<string, any>>(setup: (timeline: any) => T, options?: {
1164
+ defaultEasing?: (t: number) => number;
1165
+ defaultLoop?: number;
1166
+ }): T & {
1167
+ update: (progress: number) => void;
1168
+ };
1286
1169
  }
1287
1170
 
1288
1171
  interface KlintElements {
@@ -1290,13 +1173,13 @@ interface KlintElements {
1290
1173
  Easing: Easing;
1291
1174
  Vector: Vector;
1292
1175
  Text: Text;
1293
- Thing: Thing;
1294
1176
  Grid: Grid;
1295
1177
  Strip: Strip;
1296
1178
  Noise: Noise;
1297
1179
  Hotspot: Hotspot;
1298
- Performance: Performance;
1299
- SSR: SSR;
1180
+ Quadtree: typeof Quadtree;
1181
+ Pixels: Pixels;
1182
+ Timeline: Timeline;
1300
1183
  }
1301
1184
 
1302
1185
  declare const EPSILON = 0.0001;
@@ -1355,15 +1238,6 @@ interface KlintOffscreenContext extends CanvasRenderingContext2D, KlintFunctions
1355
1238
  createVector: (x: number, y: number) => Vector;
1356
1239
  [key: string]: any;
1357
1240
  }
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
- }
1367
1241
  interface KlintContext extends KlintOffscreenContext, KlintCoreFunctions {
1368
1242
  frame: number;
1369
1243
  time: number;
@@ -1373,7 +1247,6 @@ interface KlintContext extends KlintOffscreenContext, KlintCoreFunctions {
1373
1247
  __lastRealTime: number;
1374
1248
  __isPlaying: boolean;
1375
1249
  __offscreens: Map<string, KlintOffscreenContext | HTMLImageElement>;
1376
- __performance?: KlintPerformanceMetrics;
1377
1250
  }
1378
1251
  interface KlintCanvasOptions {
1379
1252
  alpha?: string;
@@ -1403,8 +1276,7 @@ interface KlintProps {
1403
1276
  options?: KlintCanvasOptions;
1404
1277
  onResize?: (ctx: KlintContext) => void;
1405
1278
  onVisible?: (ctx: KlintContext) => void;
1406
- enablePerformanceTracking?: boolean;
1407
1279
  }
1408
- declare function Klint({ context, setup, draw, options, preload, onVisible, enablePerformanceTracking, }: KlintProps): React.JSX.Element;
1280
+ declare function Klint({ context, setup, draw, options, preload, onVisible, }: KlintProps): React.JSX.Element;
1409
1281
 
1410
- export { CONFIG_PROPS as C, EPSILON as E, Grid as G, Hotspot as H, type KlintContext as K, Noise as N, Performance as P, SSR as S, Text as T, Vector as V, type KlintCanvasOptions as a, type KlintPerformanceMetrics as b, Color as c, type CurveVertex as d, Easing as e, Klint as f, type KlintConfig as g, type KlintContextWrapper as h, type KlintContexts as i, KlintCoreFunctions as j, type KlintElements as k, KlintFunctions as l, type KlintOffscreenContext as m, type KlintProps as n, type KlintServerRenderOptions as o, type PerformanceWidgetOptions as p, Strip as q, Thing as r };
1282
+ export { CONFIG_PROPS as C, EPSILON as E, Grid as G, Hotspot as H, type KlintContext as K, Noise as N, Pixels as P, Quadtree as Q, Rectangle as R, Strip as S, Text as T, Vector as V, type KlintCanvasOptions as a, Color as b, type CurveVertex as c, Easing as d, Klint as e, type KlintConfig as f, type KlintContextWrapper as g, type KlintContexts as h, KlintCoreFunctions as i, type KlintElements as j, KlintFunctions as k, type KlintOffscreenContext as l, type KlintProps as m, type QuadtreePoint as n, Timeline as o };