@shopify/klint 0.2.0 → 0.3.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-sandbox +3 -3
- package/dist/Klint-CsVzll4n.d.cts +1410 -0
- package/dist/Klint-CsVzll4n.d.ts +1410 -0
- package/dist/chunk-3RG5ZIWI.js +10 -0
- package/dist/index.d.cts +4 -1409
- package/dist/index.d.ts +4 -1409
- package/dist/index.js +3 -6
- package/dist/plugins/index.cjs +2518 -0
- package/dist/plugins/index.d.cts +560 -0
- package/dist/plugins/index.d.ts +560 -0
- package/dist/plugins/index.js +2489 -0
- package/package.json +11 -7
|
@@ -0,0 +1,1410 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
type KlintCoreFunctionNames = keyof typeof KlintCoreFunctions;
|
|
4
|
+
type KlintCoreFunctions = {
|
|
5
|
+
[K in KlintCoreFunctionNames]: ReturnType<(typeof KlintCoreFunctions)[K]>;
|
|
6
|
+
};
|
|
7
|
+
declare const KlintCoreFunctions: {
|
|
8
|
+
saveCanvas: (ctx: KlintContext) => () => void;
|
|
9
|
+
fullscreen: (ctx: KlintContext) => () => void;
|
|
10
|
+
play: (ctx: KlintContext) => () => void;
|
|
11
|
+
pause: (ctx: KlintContext) => () => void;
|
|
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
|
+
describe: (ctx: KlintContext) => (description: string) => void;
|
|
19
|
+
createOffscreen: (ctx: KlintContext) => (id: string, width: number, height: number, options?: KlintCanvasOptions, callback?: (ctx: KlintOffscreenContext) => void) => KlintOffscreenContext | HTMLImageElement;
|
|
20
|
+
getOffscreen: (ctx: KlintContext) => (id: string) => KlintOffscreenContext | HTMLImageElement;
|
|
21
|
+
};
|
|
22
|
+
type KlintFunctionNames = keyof typeof KlintFunctions;
|
|
23
|
+
type KlintFunctions = {
|
|
24
|
+
[K in KlintFunctionNames]: ReturnType<(typeof KlintFunctions)[K]>;
|
|
25
|
+
};
|
|
26
|
+
declare const KlintFunctions: {
|
|
27
|
+
readonly extend: (ctx: KlintContexts) => (name: string, data: unknown, enforceReplace?: boolean) => void;
|
|
28
|
+
readonly background: (ctx: KlintContexts) => (color?: string) => void;
|
|
29
|
+
readonly reset: (ctx: KlintContexts) => () => void;
|
|
30
|
+
readonly clear: (ctx: KlintContexts) => () => void;
|
|
31
|
+
readonly fillColor: (ctx: KlintContexts) => (color: string | CanvasGradient) => void;
|
|
32
|
+
readonly strokeColor: (ctx: KlintContexts) => (color: string | CanvasGradient) => void;
|
|
33
|
+
readonly noFill: (ctx: KlintContexts) => () => void;
|
|
34
|
+
readonly noStroke: (ctx: KlintContexts) => () => void;
|
|
35
|
+
readonly strokeWidth: (ctx: KlintContexts) => (width: number) => void;
|
|
36
|
+
readonly strokeJoin: (ctx: KlintContexts) => (join: CanvasLineJoin) => void;
|
|
37
|
+
readonly strokeCap: (ctx: KlintContexts) => (cap: CanvasLineCap) => void;
|
|
38
|
+
readonly push: (ctx: KlintContexts) => () => void;
|
|
39
|
+
readonly pop: (ctx: KlintContexts) => () => void;
|
|
40
|
+
readonly point: (ctx: KlintContexts) => (x: number, y: number) => void;
|
|
41
|
+
readonly checkTransparency: (ctx: KlintContexts) => (toCheck: string) => boolean;
|
|
42
|
+
readonly drawIfVisible: (ctx: KlintContexts) => () => void;
|
|
43
|
+
readonly fillRule: (ctx: KlintContexts) => (rule: CanvasFillRule) => void;
|
|
44
|
+
readonly line: (ctx: KlintContexts) => (x1: number, y1: number, x2: number, y2: number) => void;
|
|
45
|
+
readonly circle: (ctx: KlintContexts) => (x: number, y: number, radius: number, radius2?: number) => void;
|
|
46
|
+
readonly disk: (ctx: KlintContexts) => (x: number, y: number, radius: number, startAngle?: number, endAngle?: number, closed?: boolean) => void;
|
|
47
|
+
readonly rectangle: (ctx: KlintContexts) => (x: number, y: number, width: number, height?: number) => void;
|
|
48
|
+
readonly roundedRectangle: (ctx: KlintContexts) => (x: number, y: number, width: number, radius: number | number[], height?: number) => void;
|
|
49
|
+
readonly polygon: (ctx: KlintContexts) => (x: number, y: number, radius: number, sides: number, radius2?: number, rotation?: number) => void;
|
|
50
|
+
readonly beginShape: (ctx: KlintContexts) => () => void;
|
|
51
|
+
readonly beginContour: (ctx: KlintContexts) => () => void;
|
|
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;
|
|
56
|
+
readonly endContour: (ctx: KlintContexts) => (forceRevert?: boolean) => void;
|
|
57
|
+
readonly endShape: (ctx: KlintContexts) => (close?: boolean) => void;
|
|
58
|
+
readonly gradient: (ctx: KlintContexts) => (x1?: number, y1?: number, x2?: number, y2?: number) => CanvasGradient;
|
|
59
|
+
readonly radialGradient: (ctx: KlintContexts) => (x1?: number, y1?: number, r1?: number, x2?: number, y2?: number, r2?: number) => CanvasGradient;
|
|
60
|
+
readonly conicGradient: (ctx: KlintContexts) => (angle?: number, x1?: number, y1?: number) => CanvasGradient;
|
|
61
|
+
readonly addColorStop: () => (gradient: CanvasGradient, offset?: number, color?: string) => void;
|
|
62
|
+
readonly PI: () => number;
|
|
63
|
+
readonly TWO_PI: () => number;
|
|
64
|
+
readonly TAU: () => number;
|
|
65
|
+
readonly constrain: () => (val: number, floor: number, ceil: number) => number;
|
|
66
|
+
readonly lerp: (ctx: KlintContexts) => (A: number, B: number, mix: number, bounded?: boolean) => number;
|
|
67
|
+
readonly fract: () => (n: number, mod: number, mode?: "precise" | "fast" | "faster") => number;
|
|
68
|
+
readonly distance: (ctx: KlintContexts) => (x1: number, y1: number, x2: number, y2: number, mode?: "precise" | "fast" | "faster") => number;
|
|
69
|
+
readonly squareDistance: () => (x1: number, y1: number, x2: number, y2: number) => number;
|
|
70
|
+
readonly dot: () => (x1: number, y1: number, x2: number, y2: number) => number;
|
|
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;
|
|
74
|
+
readonly textFont: (ctx: KlintContexts) => (font: string) => void;
|
|
75
|
+
readonly textSize: (ctx: KlintContexts) => (size: number) => void;
|
|
76
|
+
readonly textStyle: (ctx: KlintContexts) => (style: string) => void;
|
|
77
|
+
readonly textWeight: (ctx: KlintContexts) => (weight: string) => void;
|
|
78
|
+
readonly textQuality: (ctx: KlintContexts) => (quality?: "speed" | "auto" | "legibility" | "precision") => void;
|
|
79
|
+
readonly textSpacing: (ctx: KlintContexts) => (kind: "letter" | "word", value: number) => void;
|
|
80
|
+
readonly computeTextStyle: (ctx: KlintContexts) => () => void;
|
|
81
|
+
readonly alignText: (ctx: KlintContexts) => (horizontal: CanvasTextAlign, vertical?: CanvasTextBaseline) => void;
|
|
82
|
+
readonly textLeading: (ctx: KlintContexts) => (spacing: number) => number;
|
|
83
|
+
readonly computeFont: (ctx: KlintContexts) => () => void;
|
|
84
|
+
readonly textWidth: (ctx: KlintContexts) => (text: string) => number;
|
|
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;
|
|
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;
|
|
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
|
+
readonly scaleTo: () => (originWidth: number, originHeight: number, destinationWidth: number, destinationHeight: number, cover?: boolean) => number;
|
|
96
|
+
readonly opacity: (ctx: KlintContexts) => (value: number) => void;
|
|
97
|
+
readonly blend: (ctx: KlintContexts) => (blend: GlobalCompositeOperation | "default") => void;
|
|
98
|
+
readonly setCanvasOrigin: (ctx: KlintContexts) => (type: "center" | "corner") => void;
|
|
99
|
+
readonly setImageOrigin: (ctx: KlintContexts) => (type: "center" | "corner") => void;
|
|
100
|
+
readonly setRectOrigin: (ctx: KlintContexts) => (type: "center" | "corner") => void;
|
|
101
|
+
readonly withConfig: (ctx: KlintContexts) => (config: KlintConfig) => void;
|
|
102
|
+
readonly toBase64: (ctx: KlintContexts) => (type?: string, quality?: number) => string;
|
|
103
|
+
readonly saveConfig: (ctx: KlintContexts) => (from?: KlintContexts) => KlintConfig;
|
|
104
|
+
readonly restoreConfig: (ctx: KlintContexts) => (config: KlintConfig) => void;
|
|
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;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
interface KlintColor {
|
|
118
|
+
colors: readonly string[];
|
|
119
|
+
coral: string;
|
|
120
|
+
brown: string;
|
|
121
|
+
mustard: string;
|
|
122
|
+
crimson: string;
|
|
123
|
+
navy: string;
|
|
124
|
+
sky: string;
|
|
125
|
+
olive: string;
|
|
126
|
+
charcoal: string;
|
|
127
|
+
peach: string;
|
|
128
|
+
rose: string;
|
|
129
|
+
plum: string;
|
|
130
|
+
sage: string;
|
|
131
|
+
drab: string;
|
|
132
|
+
taupe: string;
|
|
133
|
+
midnight: string;
|
|
134
|
+
golden: string;
|
|
135
|
+
orange: string;
|
|
136
|
+
slate: string;
|
|
137
|
+
hex(color: string): string;
|
|
138
|
+
rgb(r: number, g: number, b: number): string;
|
|
139
|
+
rgba(r: number, g: number, b: number, alpha: number): string;
|
|
140
|
+
gray(value: number, alpha?: number): string;
|
|
141
|
+
hsl(h: number, s: number, l: number): string;
|
|
142
|
+
hsla(h: number, s: number, l: number, alpha: number): string;
|
|
143
|
+
lch(l: number, c: number, h: number): string;
|
|
144
|
+
lcha(l: number, c: number, h: number, alpha: number): string;
|
|
145
|
+
lab(l: number, a: number, b: number): string;
|
|
146
|
+
laba(l: number, a: number, b: number, alpha: number): string;
|
|
147
|
+
oklch(l: number, c: number, h: number): string;
|
|
148
|
+
oklcha(l: number, c: number, h: number, alpha: number): string;
|
|
149
|
+
oklab(l: number, a: number, b: number): string;
|
|
150
|
+
oklaba(l: number, a: number, b: number, alpha: number): string;
|
|
151
|
+
blendColors(colorA: string, colorB: string, factor: number, colorMode?: string): string;
|
|
152
|
+
createPalette(baseColor: string, steps?: number): string[];
|
|
153
|
+
complementary(color: string): string;
|
|
154
|
+
analogous(color: string, angle?: number): [string, string];
|
|
155
|
+
triadic(color: string): [string, string];
|
|
156
|
+
saturate(color: string, amount: number): string;
|
|
157
|
+
lighten(color: string, amount: number): string;
|
|
158
|
+
darken(color: string, amount: number): string;
|
|
159
|
+
}
|
|
160
|
+
declare class Color implements KlintColor {
|
|
161
|
+
/**
|
|
162
|
+
* Array of predefined colors in the Klint color palette
|
|
163
|
+
*/
|
|
164
|
+
colors: readonly ["#E84D37", "#7F4C2F", "#EDBC2F", "#BF3034", "#18599D", "#45A7C6", "#8CB151", "#252120", "#ECA088", "#C9B1B8", "#8F3064", "#7B8870", "#C0C180", "#4B423D", "#1A2A65", "#EAA550", "#F17B04", "#404757"];
|
|
165
|
+
get coral(): "#E84D37";
|
|
166
|
+
get brown(): "#7F4C2F";
|
|
167
|
+
get mustard(): "#EDBC2F";
|
|
168
|
+
get crimson(): "#BF3034";
|
|
169
|
+
get navy(): "#18599D";
|
|
170
|
+
get sky(): "#45A7C6";
|
|
171
|
+
get olive(): "#8CB151";
|
|
172
|
+
get charcoal(): "#252120";
|
|
173
|
+
get peach(): "#ECA088";
|
|
174
|
+
get rose(): "#C9B1B8";
|
|
175
|
+
get plum(): "#8F3064";
|
|
176
|
+
get sage(): "#7B8870";
|
|
177
|
+
get drab(): "#C0C180";
|
|
178
|
+
get taupe(): "#4B423D";
|
|
179
|
+
get midnight(): "#1A2A65";
|
|
180
|
+
get golden(): "#EAA550";
|
|
181
|
+
get orange(): "#F17B04";
|
|
182
|
+
get slate(): "#404757";
|
|
183
|
+
/**
|
|
184
|
+
* Ensures a color string has a # prefix
|
|
185
|
+
* @param color - Color string in hex format (with or without #)
|
|
186
|
+
* @returns Hex color string with # prefix
|
|
187
|
+
*/
|
|
188
|
+
hex(color: string): string;
|
|
189
|
+
/**
|
|
190
|
+
* Creates an RGB color string
|
|
191
|
+
* @param r - Red component (0-255)
|
|
192
|
+
* @param g - Green component (0-255)
|
|
193
|
+
* @param b - Blue component (0-255)
|
|
194
|
+
* @returns RGB color string
|
|
195
|
+
*/
|
|
196
|
+
rgb(r: number, g: number, b: number): string;
|
|
197
|
+
/**
|
|
198
|
+
* Creates an RGBA color string
|
|
199
|
+
* @param r - Red component (0-255)
|
|
200
|
+
* @param g - Green component (0-255)
|
|
201
|
+
* @param b - Blue component (0-255)
|
|
202
|
+
* @param alpha - Alpha/opacity value (0-1)
|
|
203
|
+
* @returns RGBA color string
|
|
204
|
+
*/
|
|
205
|
+
rgba(r: number, g: number, b: number, alpha: number): string;
|
|
206
|
+
/**
|
|
207
|
+
* Creates a grayscale color
|
|
208
|
+
* @param value - Gray value (0-255)
|
|
209
|
+
* @param alpha - Optional alpha/opacity value (0-1)
|
|
210
|
+
* @returns RGB or RGBA grayscale color string
|
|
211
|
+
*/
|
|
212
|
+
gray(value: number, alpha?: number): string;
|
|
213
|
+
/**
|
|
214
|
+
* Creates an HSL color string
|
|
215
|
+
* @param h - Hue (0-360)
|
|
216
|
+
* @param s - Saturation percentage (0-100)
|
|
217
|
+
* @param l - Lightness percentage (0-100)
|
|
218
|
+
* @returns HSL color string
|
|
219
|
+
*/
|
|
220
|
+
hsl(h: number, s: number, l: number): string;
|
|
221
|
+
/**
|
|
222
|
+
* Creates an HSLA color string
|
|
223
|
+
* @param h - Hue (0-360)
|
|
224
|
+
* @param s - Saturation percentage (0-100)
|
|
225
|
+
* @param l - Lightness percentage (0-100)
|
|
226
|
+
* @param alpha - Alpha/opacity value (0-1)
|
|
227
|
+
* @returns HSLA color string
|
|
228
|
+
*/
|
|
229
|
+
hsla(h: number, s: number, l: number, alpha: number): string;
|
|
230
|
+
/**
|
|
231
|
+
* Creates an LCH color string
|
|
232
|
+
* @param l - Lightness percentage (0-100)
|
|
233
|
+
* @param c - Chroma value
|
|
234
|
+
* @param h - Hue (0-360)
|
|
235
|
+
* @returns LCH color string
|
|
236
|
+
*/
|
|
237
|
+
lch(l: number, c: number, h: number): string;
|
|
238
|
+
/**
|
|
239
|
+
* Creates an LCH color string with alpha
|
|
240
|
+
* @param l - Lightness percentage (0-100)
|
|
241
|
+
* @param c - Chroma value
|
|
242
|
+
* @param h - Hue (0-360)
|
|
243
|
+
* @param alpha - Alpha/opacity value (0-1)
|
|
244
|
+
* @returns LCH color string with alpha
|
|
245
|
+
*/
|
|
246
|
+
lcha(l: number, c: number, h: number, alpha: number): string;
|
|
247
|
+
/**
|
|
248
|
+
* Creates a LAB color string
|
|
249
|
+
* @param l - Lightness percentage (0-100)
|
|
250
|
+
* @param a - A-axis value (green to red)
|
|
251
|
+
* @param b - B-axis value (blue to yellow)
|
|
252
|
+
* @returns LAB color string
|
|
253
|
+
*/
|
|
254
|
+
lab(l: number, a: number, b: number): string;
|
|
255
|
+
/**
|
|
256
|
+
* Creates a LAB color string with alpha
|
|
257
|
+
* @param l - Lightness percentage (0-100)
|
|
258
|
+
* @param a - A-axis value (green to red)
|
|
259
|
+
* @param b - B-axis value (blue to yellow)
|
|
260
|
+
* @param alpha - Alpha/opacity value (0-1)
|
|
261
|
+
* @returns LAB color string with alpha
|
|
262
|
+
*/
|
|
263
|
+
laba(l: number, a: number, b: number, alpha: number): string;
|
|
264
|
+
/**
|
|
265
|
+
* Creates an OKLCH color string
|
|
266
|
+
* @param l - Lightness value (0-1)
|
|
267
|
+
* @param c - Chroma value
|
|
268
|
+
* @param h - Hue (0-360)
|
|
269
|
+
* @returns OKLCH color string
|
|
270
|
+
*/
|
|
271
|
+
oklch(l: number, c: number, h: number): string;
|
|
272
|
+
/**
|
|
273
|
+
* Creates an OKLCH color string with alpha
|
|
274
|
+
* @param l - Lightness value (0-1)
|
|
275
|
+
* @param c - Chroma value
|
|
276
|
+
* @param h - Hue (0-360)
|
|
277
|
+
* @param alpha - Alpha/opacity value (0-1)
|
|
278
|
+
* @returns OKLCH color string with alpha
|
|
279
|
+
*/
|
|
280
|
+
oklcha(l: number, c: number, h: number, alpha: number): string;
|
|
281
|
+
/**
|
|
282
|
+
* Creates an OKLAB color string
|
|
283
|
+
* @param l - Lightness value (0-1)
|
|
284
|
+
* @param a - A-axis value (green to red)
|
|
285
|
+
* @param b - B-axis value (blue to yellow)
|
|
286
|
+
* @returns OKLAB color string
|
|
287
|
+
*/
|
|
288
|
+
oklab(l: number, a: number, b: number): string;
|
|
289
|
+
/**
|
|
290
|
+
* Creates an OKLAB color string with alpha
|
|
291
|
+
* @param l - Lightness value (0-1)
|
|
292
|
+
* @param a - A-axis value (green to red)
|
|
293
|
+
* @param b - B-axis value (blue to yellow)
|
|
294
|
+
* @param alpha - Alpha/opacity value (0-1)
|
|
295
|
+
* @returns OKLAB color string with alpha
|
|
296
|
+
*/
|
|
297
|
+
oklaba(l: number, a: number, b: number, alpha: number): string;
|
|
298
|
+
/**
|
|
299
|
+
* Blends two colors using CSS color-mix
|
|
300
|
+
* @param colorA - First color
|
|
301
|
+
* @param colorB - Second color
|
|
302
|
+
* @param factor - Blend factor (0-1) where 0 is colorA and 1 is colorB
|
|
303
|
+
* @param colorMode - Color space to blend in (e.g., "oklch", "hsl")
|
|
304
|
+
* @returns Blended color string
|
|
305
|
+
*/
|
|
306
|
+
blendColors(colorA: string, colorB: string, factor: number, colorMode?: string): string;
|
|
307
|
+
/**
|
|
308
|
+
* Creates a palette of colors based on a single base color
|
|
309
|
+
* @param baseColor - The base color to create palette from
|
|
310
|
+
* @param steps - Number of steps in each direction (lighter/darker)
|
|
311
|
+
* @returns Array of color strings forming a palette
|
|
312
|
+
*/
|
|
313
|
+
createPalette(baseColor: string, steps?: number): string[];
|
|
314
|
+
/**
|
|
315
|
+
* Creates a complementary color (opposite on the color wheel)
|
|
316
|
+
* @param color - Base color
|
|
317
|
+
* @returns Complementary color string
|
|
318
|
+
*/
|
|
319
|
+
complementary(color: string): string;
|
|
320
|
+
/**
|
|
321
|
+
* Creates analogous colors (adjacent on the color wheel)
|
|
322
|
+
* @param color - Base color
|
|
323
|
+
* @param angle - Angle of separation in degrees
|
|
324
|
+
* @returns Tuple of two analogous color strings
|
|
325
|
+
*/
|
|
326
|
+
analogous(color: string, angle?: number): [string, string];
|
|
327
|
+
/**
|
|
328
|
+
* Creates a triadic color scheme (three colors evenly spaced on the color wheel)
|
|
329
|
+
* @param color - Base color
|
|
330
|
+
* @returns Tuple of two additional colors to form a triadic scheme
|
|
331
|
+
*/
|
|
332
|
+
triadic(color: string): [string, string];
|
|
333
|
+
/**
|
|
334
|
+
* Increases the saturation of a color
|
|
335
|
+
* @param color - Base color
|
|
336
|
+
* @param amount - Amount to saturate (percentage)
|
|
337
|
+
* @returns Saturated color string
|
|
338
|
+
*/
|
|
339
|
+
saturate(color: string, amount: number): string;
|
|
340
|
+
/**
|
|
341
|
+
* Lightens a color by mixing with white
|
|
342
|
+
* @param color - Base color
|
|
343
|
+
* @param amount - Amount to lighten (percentage)
|
|
344
|
+
* @returns Lightened color string
|
|
345
|
+
*/
|
|
346
|
+
lighten(color: string, amount: number): string;
|
|
347
|
+
/**
|
|
348
|
+
* Darkens a color by mixing with black
|
|
349
|
+
* @param color - Base color
|
|
350
|
+
* @param amount - Amount to darken (percentage)
|
|
351
|
+
* @returns Darkened color string
|
|
352
|
+
*/
|
|
353
|
+
darken(color: string, amount: number): string;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
interface KlintEasing {
|
|
357
|
+
normalize: (val: number) => number;
|
|
358
|
+
expand: (val: number) => number;
|
|
359
|
+
inout: (val: number, power?: number) => number;
|
|
360
|
+
in: (val: number, power?: number) => number;
|
|
361
|
+
out: (val: number, power?: number) => number;
|
|
362
|
+
overshootIn: (val: number) => number;
|
|
363
|
+
overshootOut: (val: number) => number;
|
|
364
|
+
overshootInOut: (val: number) => number;
|
|
365
|
+
}
|
|
366
|
+
declare class Easing implements KlintEasing {
|
|
367
|
+
private zeroOut;
|
|
368
|
+
normalize: (val: number) => number;
|
|
369
|
+
expand: (val: number) => number;
|
|
370
|
+
inout: (val: number, power?: number) => number;
|
|
371
|
+
in: (val: number, power?: number) => number;
|
|
372
|
+
out: (val: number, power?: number) => number;
|
|
373
|
+
overshootIn: (val: number) => number;
|
|
374
|
+
overshootOut: (val: number) => number;
|
|
375
|
+
overshootInOut: (val: number) => number;
|
|
376
|
+
bounceOut: (val: number) => number;
|
|
377
|
+
bounceIn: (val: number) => number;
|
|
378
|
+
bounceInOut: (val: number) => number;
|
|
379
|
+
elasticIn: (val: number) => number;
|
|
380
|
+
elasticOut: (val: number) => number;
|
|
381
|
+
elasticInOut: (val: number) => number;
|
|
382
|
+
smoothstep: (val: number, x0?: number, x1?: number) => number;
|
|
383
|
+
log: () => void;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* Interface defining a 3D vector with various vector operations
|
|
388
|
+
*/
|
|
389
|
+
interface KlintVector {
|
|
390
|
+
x: number;
|
|
391
|
+
y: number;
|
|
392
|
+
z: number;
|
|
393
|
+
add: (v: KlintVector) => KlintVector;
|
|
394
|
+
sub: (v: KlintVector) => KlintVector;
|
|
395
|
+
mult: (n: number) => KlintVector;
|
|
396
|
+
div: (n: number) => KlintVector;
|
|
397
|
+
rotate: (angle: number) => KlintVector;
|
|
398
|
+
mag: () => number;
|
|
399
|
+
length: () => number;
|
|
400
|
+
dot: (v: KlintVector) => number;
|
|
401
|
+
dist: (v: KlintVector) => number;
|
|
402
|
+
angle: () => number;
|
|
403
|
+
copy: () => KlintVector;
|
|
404
|
+
normalize: () => KlintVector;
|
|
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;
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* A 3D vector class with various vector operations (z=0 by default for 2D use)
|
|
414
|
+
*/
|
|
415
|
+
declare class Vector implements KlintVector {
|
|
416
|
+
/** X-coordinate of the vector */
|
|
417
|
+
x: number;
|
|
418
|
+
/** Y-coordinate of the vector */
|
|
419
|
+
y: number;
|
|
420
|
+
/** Z-coordinate of the vector */
|
|
421
|
+
z: number;
|
|
422
|
+
/**
|
|
423
|
+
* Creates a new Vector
|
|
424
|
+
* @param x - X-coordinate (default: 0)
|
|
425
|
+
* @param y - Y-coordinate (default: 0)
|
|
426
|
+
* @param z - Z-coordinate (default: 0)
|
|
427
|
+
*/
|
|
428
|
+
constructor(x?: number, y?: number, z?: number);
|
|
429
|
+
/**
|
|
430
|
+
* Adds another vector to this vector
|
|
431
|
+
* @param v - Vector to add
|
|
432
|
+
* @returns This vector after addition
|
|
433
|
+
*/
|
|
434
|
+
add(v: KlintVector): Vector;
|
|
435
|
+
/**
|
|
436
|
+
* Subtracts another vector from this vector
|
|
437
|
+
* @param v - Vector to subtract
|
|
438
|
+
* @returns This vector after subtraction
|
|
439
|
+
*/
|
|
440
|
+
sub(v: KlintVector): Vector;
|
|
441
|
+
/**
|
|
442
|
+
* Multiplies this vector by a scalar
|
|
443
|
+
* @param n - Scalar to multiply by
|
|
444
|
+
* @returns This vector after multiplication
|
|
445
|
+
*/
|
|
446
|
+
mult(n: number): Vector;
|
|
447
|
+
/**
|
|
448
|
+
* Divides this vector by a scalar
|
|
449
|
+
* @param n - Scalar to divide by
|
|
450
|
+
* @returns This vector after division
|
|
451
|
+
*/
|
|
452
|
+
div(n: number): Vector;
|
|
453
|
+
/**
|
|
454
|
+
* Rotates this vector by an angle (around z-axis for 2D rotation)
|
|
455
|
+
* @param angle - Angle in radians
|
|
456
|
+
* @returns This vector after rotation
|
|
457
|
+
*/
|
|
458
|
+
rotate(angle: number): Vector;
|
|
459
|
+
/**
|
|
460
|
+
* Calculates the magnitude (length) of this vector
|
|
461
|
+
* @returns The magnitude of the vector
|
|
462
|
+
*/
|
|
463
|
+
mag(): number;
|
|
464
|
+
/**
|
|
465
|
+
* Alias for mag() - calculates the length of this vector
|
|
466
|
+
* @returns The length of the vector
|
|
467
|
+
*/
|
|
468
|
+
length(): number;
|
|
469
|
+
/**
|
|
470
|
+
* Calculates the dot product of this vector with another vector
|
|
471
|
+
* @param v - The other vector
|
|
472
|
+
* @returns The dot product
|
|
473
|
+
*/
|
|
474
|
+
dot(v: KlintVector): number;
|
|
475
|
+
/**
|
|
476
|
+
* Calculates the distance between this vector and another vector
|
|
477
|
+
* @param v - The other vector
|
|
478
|
+
* @returns The distance between the vectors
|
|
479
|
+
*/
|
|
480
|
+
dist(v: KlintVector): number;
|
|
481
|
+
/**
|
|
482
|
+
* Calculates the angle of this vector (in 2D, ignoring z)
|
|
483
|
+
* @returns The angle in radians
|
|
484
|
+
*/
|
|
485
|
+
angle(): number;
|
|
486
|
+
/**
|
|
487
|
+
* Creates a copy of this vector
|
|
488
|
+
* @returns A new Vector with the same coordinates
|
|
489
|
+
*/
|
|
490
|
+
copy(): Vector;
|
|
491
|
+
/**
|
|
492
|
+
* Normalizes this vector (sets its magnitude to 1)
|
|
493
|
+
* @returns This vector after normalization
|
|
494
|
+
*/
|
|
495
|
+
normalize(): Vector;
|
|
496
|
+
/**
|
|
497
|
+
* Sets the coordinates of this vector
|
|
498
|
+
* @param x - New X-coordinate
|
|
499
|
+
* @param y - New Y-coordinate
|
|
500
|
+
* @param z - New Z-coordinate (default: 0)
|
|
501
|
+
* @returns This vector after setting coordinates
|
|
502
|
+
*/
|
|
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;
|
|
536
|
+
/**
|
|
537
|
+
* Creates a new vector at a specified angle and distance from a center point
|
|
538
|
+
* @param center - The center point vector
|
|
539
|
+
* @param a - The angle in radians
|
|
540
|
+
* @param r - The radius (distance from center)
|
|
541
|
+
* @returns A new Vector at the calculated position
|
|
542
|
+
*/
|
|
543
|
+
static fromAngle(center: Vector, a: number, r: number): Vector;
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
type TextMetrics$1 = {
|
|
547
|
+
width: number;
|
|
548
|
+
height: number;
|
|
549
|
+
baseline: number;
|
|
550
|
+
};
|
|
551
|
+
interface KlintText {
|
|
552
|
+
context: KlintContexts;
|
|
553
|
+
findTextSize: (text: string, dist: number, estimate?: number, direction?: "x" | "y") => number;
|
|
554
|
+
getTextMetrics: (text: string) => TextMetrics$1;
|
|
555
|
+
splitTo: (text: string, kind: "letters" | "words" | "lines" | "all", options?: {
|
|
556
|
+
maxWidth?: number;
|
|
557
|
+
lineSpacing?: number;
|
|
558
|
+
letterSpacing?: number;
|
|
559
|
+
wordSpacing?: number;
|
|
560
|
+
}) => Array<{
|
|
561
|
+
char: string;
|
|
562
|
+
x: number;
|
|
563
|
+
y: number;
|
|
564
|
+
metrics: TextMetrics$1;
|
|
565
|
+
letterIndex?: number;
|
|
566
|
+
wordIndex?: number;
|
|
567
|
+
lineIndex?: number;
|
|
568
|
+
}>;
|
|
569
|
+
circularText: (text: string, radius?: number, fill?: "fill" | "kerned" | "words", offset?: number, arc?: number) => void;
|
|
570
|
+
textBounds: (text: string) => {
|
|
571
|
+
x: number;
|
|
572
|
+
y: number;
|
|
573
|
+
width: number;
|
|
574
|
+
height: number;
|
|
575
|
+
};
|
|
576
|
+
log: () => void;
|
|
577
|
+
}
|
|
578
|
+
declare class Text implements KlintText {
|
|
579
|
+
context: KlintContexts;
|
|
580
|
+
constructor(ctx: KlintContexts);
|
|
581
|
+
findTextSize: (text: string, dist: number, estimate?: number, direction?: "x" | "y") => number;
|
|
582
|
+
getTextMetrics: (text: string) => TextMetrics$1;
|
|
583
|
+
splitTo: (text: string, kind: "letters" | "words" | "lines" | "all", options?: {
|
|
584
|
+
maxWidth?: number;
|
|
585
|
+
lineSpacing?: number;
|
|
586
|
+
letterSpacing?: number;
|
|
587
|
+
wordSpacing?: number;
|
|
588
|
+
}) => {
|
|
589
|
+
letterIndex?: number | undefined;
|
|
590
|
+
wordIndex?: number | undefined;
|
|
591
|
+
lineIndex?: number | undefined;
|
|
592
|
+
char: string;
|
|
593
|
+
x: number;
|
|
594
|
+
y: number;
|
|
595
|
+
metrics: TextMetrics$1;
|
|
596
|
+
}[];
|
|
597
|
+
circularText: (text: string, radius?: number, fill?: "fill" | "kerned" | "words", offset?: number, arc?: number) => void;
|
|
598
|
+
textBounds: (text: string) => {
|
|
599
|
+
x: number;
|
|
600
|
+
y: number;
|
|
601
|
+
width: number;
|
|
602
|
+
height: number;
|
|
603
|
+
};
|
|
604
|
+
log: () => void;
|
|
605
|
+
}
|
|
606
|
+
|
|
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
|
+
/**
|
|
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
|
+
|
|
1288
|
+
interface KlintElements {
|
|
1289
|
+
Color: Color;
|
|
1290
|
+
Easing: Easing;
|
|
1291
|
+
Vector: Vector;
|
|
1292
|
+
Text: Text;
|
|
1293
|
+
Thing: Thing;
|
|
1294
|
+
Grid: Grid;
|
|
1295
|
+
Strip: Strip;
|
|
1296
|
+
Noise: Noise;
|
|
1297
|
+
Hotspot: Hotspot;
|
|
1298
|
+
Performance: Performance;
|
|
1299
|
+
SSR: SSR;
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1302
|
+
declare const EPSILON = 0.0001;
|
|
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
|
+
};
|
|
1330
|
+
interface KlintOffscreenContext extends CanvasRenderingContext2D, KlintFunctions, KlintElements {
|
|
1331
|
+
width: number;
|
|
1332
|
+
height: number;
|
|
1333
|
+
__dpr: number;
|
|
1334
|
+
__startedShape: boolean;
|
|
1335
|
+
__currentShape: CurveVertex[] | null;
|
|
1336
|
+
__startedContour: boolean;
|
|
1337
|
+
__currentContours: CurveVertex[][] | null;
|
|
1338
|
+
__currentContour: CurveVertex[] | null;
|
|
1339
|
+
__isReadyToDraw: boolean;
|
|
1340
|
+
__isMainContext: boolean;
|
|
1341
|
+
__imageOrigin: "corner" | "center";
|
|
1342
|
+
__rectangleOrigin: "corner" | "center";
|
|
1343
|
+
__canvasOrigin: "corner" | "center";
|
|
1344
|
+
__computedTextFont: string;
|
|
1345
|
+
__textFont: string;
|
|
1346
|
+
__textSize: number;
|
|
1347
|
+
__textLeading: number | undefined;
|
|
1348
|
+
__textStyle: string;
|
|
1349
|
+
__textWeight: string;
|
|
1350
|
+
__textAlignment: {
|
|
1351
|
+
horizontal: CanvasTextAlign;
|
|
1352
|
+
vertical: CanvasTextBaseline;
|
|
1353
|
+
};
|
|
1354
|
+
__fillRule: CanvasFillRule;
|
|
1355
|
+
createVector: (x: number, y: number) => Vector;
|
|
1356
|
+
[key: string]: any;
|
|
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
|
+
}
|
|
1367
|
+
interface KlintContext extends KlintOffscreenContext, KlintCoreFunctions {
|
|
1368
|
+
frame: number;
|
|
1369
|
+
time: number;
|
|
1370
|
+
deltaTime: number;
|
|
1371
|
+
fps: number;
|
|
1372
|
+
__lastTargetTime: number;
|
|
1373
|
+
__lastRealTime: number;
|
|
1374
|
+
__isPlaying: boolean;
|
|
1375
|
+
__offscreens: Map<string, KlintOffscreenContext | HTMLImageElement>;
|
|
1376
|
+
__performance?: KlintPerformanceMetrics;
|
|
1377
|
+
}
|
|
1378
|
+
interface KlintCanvasOptions {
|
|
1379
|
+
alpha?: string;
|
|
1380
|
+
willreadfrequently?: string;
|
|
1381
|
+
autoplay?: string;
|
|
1382
|
+
ignoreResize?: string;
|
|
1383
|
+
noloop?: string;
|
|
1384
|
+
ignoreFunctions?: string;
|
|
1385
|
+
static?: string;
|
|
1386
|
+
nocanvas?: string;
|
|
1387
|
+
fps?: number;
|
|
1388
|
+
unsafemode?: string;
|
|
1389
|
+
dpr?: number | "default";
|
|
1390
|
+
origin?: "corner" | "center";
|
|
1391
|
+
}
|
|
1392
|
+
type KlintConfig = Partial<Pick<KlintContext, (typeof CONFIG_PROPS)[number]>>;
|
|
1393
|
+
interface KlintContextWrapper {
|
|
1394
|
+
context: KlintContext | null;
|
|
1395
|
+
initCoreContext: (canvas: HTMLCanvasElement, options: KlintCanvasOptions) => KlintContext;
|
|
1396
|
+
}
|
|
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"];
|
|
1398
|
+
interface KlintProps {
|
|
1399
|
+
context: KlintContextWrapper;
|
|
1400
|
+
draw: (ctx: KlintContext) => void;
|
|
1401
|
+
setup?: (ctx: KlintContext) => void;
|
|
1402
|
+
preload?: (ctx: KlintContext) => Promise<void>;
|
|
1403
|
+
options?: KlintCanvasOptions;
|
|
1404
|
+
onResize?: (ctx: KlintContext) => void;
|
|
1405
|
+
onVisible?: (ctx: KlintContext) => void;
|
|
1406
|
+
enablePerformanceTracking?: boolean;
|
|
1407
|
+
}
|
|
1408
|
+
declare function Klint({ context, setup, draw, options, preload, onVisible, enablePerformanceTracking, }: KlintProps): React.JSX.Element;
|
|
1409
|
+
|
|
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 };
|