@slithy/prim-lib 0.8.2 → 0.9.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/LICENSE-COMMERCIAL.md +2 -2
- package/dist/index.d.ts +41 -22
- package/dist/index.js +274 -335
- package/package.json +5 -5
package/LICENSE-COMMERCIAL.md
CHANGED
|
@@ -4,11 +4,11 @@ Copyright Matthew Campagna
|
|
|
4
4
|
|
|
5
5
|
1. Grant
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
The individual copyright owner of `@slithy/prim-lib`, currently Matthew Campagna, is granted a personal, non-transferable, non-sublicensable license to use, reproduce, modify, distribute, and commercially exploit `@slithy/prim-lib` as part of software products and related internal development activities.
|
|
8
8
|
|
|
9
9
|
2. Scope
|
|
10
10
|
|
|
11
|
-
This commercial license applies only to
|
|
11
|
+
This commercial license applies only to the natural person who is the individual copyright owner of `@slithy/prim-lib` at the time of use, in that person's personal capacity. It does not extend to any employer, client, contractor, affiliate, assignee, or other third party.
|
|
12
12
|
|
|
13
13
|
3. Public License Unchanged
|
|
14
14
|
|
package/dist/index.d.ts
CHANGED
|
@@ -30,8 +30,7 @@ interface ShapeInterface {
|
|
|
30
30
|
hueCenter?: number;
|
|
31
31
|
hueTolerance?: number;
|
|
32
32
|
invertHue?: boolean;
|
|
33
|
-
|
|
34
|
-
mutate(cfg?: Partial<Cfg>): ShapeInterface;
|
|
33
|
+
mutate(): ShapeInterface;
|
|
35
34
|
toSVG(): SVGElement | undefined;
|
|
36
35
|
toData(alpha: number, color: RGB): StepData;
|
|
37
36
|
rasterize(alpha: number): {
|
|
@@ -46,10 +45,14 @@ interface Cfg {
|
|
|
46
45
|
mutateAlpha: boolean;
|
|
47
46
|
shapeTypes: Array<new (w: number, h: number) => ShapeInterface>;
|
|
48
47
|
shapeWeights?: number[];
|
|
48
|
+
/** Number of candidate shapes to generate and score per step. Also reused as the
|
|
49
|
+
* rejection-streak retry limit in Optimizer._addShape() — how many consecutive
|
|
50
|
+
* fully-rejected candidates (e.g. from tonal/hue/saturation constraints) to
|
|
51
|
+
* tolerate before consuming a step from the budget anyway. */
|
|
49
52
|
shapes: number;
|
|
50
53
|
mutations: number;
|
|
51
54
|
steps: number;
|
|
52
|
-
fill: 'auto' | string;
|
|
55
|
+
fill: 'auto' | (string & {});
|
|
53
56
|
outputFill?: string;
|
|
54
57
|
computeSize: number;
|
|
55
58
|
viewSize: number;
|
|
@@ -119,6 +122,7 @@ type StepData = {
|
|
|
119
122
|
cy: number;
|
|
120
123
|
fs: number;
|
|
121
124
|
text: string;
|
|
125
|
+
fontFamily?: string;
|
|
122
126
|
} | {
|
|
123
127
|
t: 'rc';
|
|
124
128
|
a: number;
|
|
@@ -141,9 +145,7 @@ interface SerializedOutput {
|
|
|
141
145
|
interface DrawableStep {
|
|
142
146
|
alpha: number;
|
|
143
147
|
color: string;
|
|
144
|
-
shape:
|
|
145
|
-
render(ctx: Ctx2D): void;
|
|
146
|
-
};
|
|
148
|
+
shape: Pick<ShapeInterface, 'bbox' | 'rasterize' | 'render'>;
|
|
147
149
|
}
|
|
148
150
|
declare class Canvas {
|
|
149
151
|
node: HTMLCanvasElement | OffscreenCanvas;
|
|
@@ -161,6 +163,7 @@ declare class Canvas {
|
|
|
161
163
|
getImageData(): ImageDataLike;
|
|
162
164
|
difference(otherCanvas: Canvas): number;
|
|
163
165
|
distance(otherCanvas: Canvas): number;
|
|
166
|
+
private patchImageData;
|
|
164
167
|
drawStep(step: DrawableStep): this;
|
|
165
168
|
}
|
|
166
169
|
|
|
@@ -196,6 +199,7 @@ declare class Optimizer {
|
|
|
196
199
|
cfg: Cfg;
|
|
197
200
|
state: State;
|
|
198
201
|
onStep: (step: Step | null) => void;
|
|
202
|
+
onError: (error: unknown) => void;
|
|
199
203
|
_steps: number;
|
|
200
204
|
_stopped: boolean;
|
|
201
205
|
_paused: boolean;
|
|
@@ -218,21 +222,22 @@ declare class Shape implements ShapeInterface {
|
|
|
218
222
|
static randomPoint(width: number, height: number): Point;
|
|
219
223
|
static create(cfg: Cfg): ShapeInterface;
|
|
220
224
|
constructor(_w: number, _h: number);
|
|
221
|
-
mutate(
|
|
225
|
+
mutate(): ShapeInterface;
|
|
222
226
|
toSVG(): SVGElement | undefined;
|
|
223
227
|
toData(_alpha: number, _color: RGB): StepData;
|
|
224
228
|
rasterize(alpha: number): {
|
|
225
229
|
getImageData(): ImageDataLike;
|
|
226
230
|
};
|
|
231
|
+
protected setBbox(tight: Bbox): this;
|
|
227
232
|
render(_ctx: Ctx2D): void;
|
|
228
233
|
}
|
|
229
234
|
declare class Polygon extends Shape {
|
|
230
235
|
points: Point[];
|
|
231
236
|
constructor(w: number, h: number, count?: number);
|
|
232
237
|
protected _cloneEmpty(): Polygon;
|
|
233
|
-
render(ctx:
|
|
238
|
+
render(ctx: Ctx2D): void;
|
|
234
239
|
toSVG(): SVGElement;
|
|
235
|
-
mutate(
|
|
240
|
+
mutate(): ShapeInterface;
|
|
236
241
|
computeBbox(): this;
|
|
237
242
|
_createPoints(w: number, h: number, count: number): Point[];
|
|
238
243
|
}
|
|
@@ -245,7 +250,7 @@ declare class Rectangle extends Polygon {
|
|
|
245
250
|
constructor(w: number, h: number);
|
|
246
251
|
protected _cloneEmpty(): Rectangle;
|
|
247
252
|
toData(a: number, c: RGB): StepData;
|
|
248
|
-
mutate(
|
|
253
|
+
mutate(): ShapeInterface;
|
|
249
254
|
_createPoints(w: number, h: number, _count: number): Point[];
|
|
250
255
|
}
|
|
251
256
|
declare class Ellipse extends Shape {
|
|
@@ -253,10 +258,10 @@ declare class Ellipse extends Shape {
|
|
|
253
258
|
rx: number;
|
|
254
259
|
ry: number;
|
|
255
260
|
constructor(w: number, h: number);
|
|
256
|
-
render(ctx:
|
|
261
|
+
render(ctx: Ctx2D): void;
|
|
257
262
|
toSVG(): SVGElement;
|
|
258
263
|
toData(a: number, c: RGB): StepData;
|
|
259
|
-
mutate(
|
|
264
|
+
mutate(): ShapeInterface;
|
|
260
265
|
computeBbox(): this;
|
|
261
266
|
}
|
|
262
267
|
declare class Circle extends Shape {
|
|
@@ -264,10 +269,10 @@ declare class Circle extends Shape {
|
|
|
264
269
|
r: number;
|
|
265
270
|
constructor(w: number, h: number);
|
|
266
271
|
computeBbox(): this;
|
|
267
|
-
render(ctx:
|
|
272
|
+
render(ctx: Ctx2D): void;
|
|
268
273
|
toSVG(): SVGElement;
|
|
269
274
|
toData(a: number, c: RGB): StepData;
|
|
270
|
-
mutate(
|
|
275
|
+
mutate(): ShapeInterface;
|
|
271
276
|
}
|
|
272
277
|
declare class Glyph extends Shape {
|
|
273
278
|
center: Point;
|
|
@@ -275,8 +280,8 @@ declare class Glyph extends Shape {
|
|
|
275
280
|
fontSize: number;
|
|
276
281
|
constructor(w: number, h: number, text?: string);
|
|
277
282
|
computeBbox(): this;
|
|
278
|
-
render(ctx:
|
|
279
|
-
mutate(
|
|
283
|
+
render(ctx: Ctx2D): void;
|
|
284
|
+
mutate(): Glyph;
|
|
280
285
|
toSVG(): SVGElement;
|
|
281
286
|
toData(a: number, c: RGB): StepData;
|
|
282
287
|
}
|
|
@@ -285,10 +290,10 @@ declare class Square extends Shape {
|
|
|
285
290
|
r: number;
|
|
286
291
|
constructor(w: number, h: number);
|
|
287
292
|
computeBbox(): this;
|
|
288
|
-
render(ctx:
|
|
293
|
+
render(ctx: Ctx2D): void;
|
|
289
294
|
toSVG(): SVGElement;
|
|
290
295
|
toData(a: number, c: RGB): StepData;
|
|
291
|
-
mutate(
|
|
296
|
+
mutate(): ShapeInterface;
|
|
292
297
|
}
|
|
293
298
|
declare class Hexagon extends Shape {
|
|
294
299
|
center: Point;
|
|
@@ -298,10 +303,10 @@ declare class Hexagon extends Shape {
|
|
|
298
303
|
constructor(w: number, h: number);
|
|
299
304
|
_points(): Point[];
|
|
300
305
|
computeBbox(): this;
|
|
301
|
-
render(ctx:
|
|
306
|
+
render(ctx: Ctx2D): void;
|
|
302
307
|
toSVG(): SVGElement;
|
|
303
308
|
toData(a: number, c: RGB): StepData;
|
|
304
|
-
mutate(
|
|
309
|
+
mutate(): ShapeInterface;
|
|
305
310
|
}
|
|
306
311
|
interface NGonOptions {
|
|
307
312
|
sides: number;
|
|
@@ -378,7 +383,7 @@ interface GlyphOptions {
|
|
|
378
383
|
declare function makeGlyph(opts?: Partial<GlyphOptions>): new (w: number, h: number) => ShapeInterface;
|
|
379
384
|
declare class Debug extends Shape {
|
|
380
385
|
constructor(w: number, h: number);
|
|
381
|
-
render(ctx:
|
|
386
|
+
render(ctx: Ctx2D): void;
|
|
382
387
|
}
|
|
383
388
|
|
|
384
389
|
declare const SVGNS = "http://www.w3.org/2000/svg";
|
|
@@ -386,6 +391,20 @@ declare function rgbToHsl(r: number, g: number, b: number): [number, number, num
|
|
|
386
391
|
declare function parseColor(color: string): [number, number, number];
|
|
387
392
|
|
|
388
393
|
declare function clamp(x: number, min: number, max: number): number;
|
|
394
|
+
/** The four corners of a rotated rectangle centred at (cx, cy) with half-extents
|
|
395
|
+
* (hw, hh) rotated by `angle` radians. Raw floats — no truncation. */
|
|
396
|
+
declare function rectCorners(cx: number, cy: number, hw: number, hh: number, angle: number): [Point, Point, Point, Point];
|
|
397
|
+
/** The `sides` vertices of a regular polygon centred at (cx, cy), the first at
|
|
398
|
+
* `angle`. `radius` may be a constant or a per-index function (for noise).
|
|
399
|
+
* Raw floats — no truncation. */
|
|
400
|
+
declare function regularPolygonPoints(cx: number, cy: number, sides: number, angle: number, radius: number | ((i: number) => number)): Point[];
|
|
401
|
+
/** Axis-aligned bounding box of a set of points. Degenerate zero-extent
|
|
402
|
+
* width/height fall back to 1 (matching the per-shape computeBbox behaviour). */
|
|
403
|
+
declare function bboxOfPoints(points: Point[]): Bbox;
|
|
404
|
+
/** A random offset within a disc of radius `scale`, truncated to integers.
|
|
405
|
+
* Used by shape mutations to nudge a point by a random angle + magnitude.
|
|
406
|
+
* The `~~` truncation is intentional and behaviour-defining — do not remove. */
|
|
407
|
+
declare function randomPolarOffset(scale: number): [number, number];
|
|
389
408
|
declare function clampColor(x: number): number;
|
|
390
409
|
declare function distanceToDifference(distance: number, pixels: number): number;
|
|
391
410
|
declare function differenceToDistance(difference: number, pixels: number): number;
|
|
@@ -405,4 +424,4 @@ interface ReplayResult {
|
|
|
405
424
|
}
|
|
406
425
|
declare function replayOutput(data: SerializedOutput): ReplayResult;
|
|
407
426
|
|
|
408
|
-
export { type Bbox, Canvas, type Cfg, Circle, type CircleOptions, type Ctx2D, Debug, Ellipse, type EllipseOptions, Glyph, type GlyphOptions, Hexagon, type ImageDataLike, type NGonOptions, Optimizer, type Point, type PreCfg, type RGB, type RectOptions, Rectangle, type ReplayResult, SVGNS, type SerializedOutput, Shape, type ShapeImageData, type ShapeInterface, Square, State, Step, type StepData, Triangle, clamp, clampColor, computeColorAndDifferenceChange, difference, differenceToDistance, distanceToDifference, getFill, makeCircle, makeEllipse, makeGlyph, makeNGon, makeRect, parseColor, renderStepToCtx, replayOutput, rgbToHsl, stepDataToSVGElement, stepPerf };
|
|
427
|
+
export { type Bbox, Canvas, type Cfg, Circle, type CircleOptions, type Ctx2D, Debug, Ellipse, type EllipseOptions, Glyph, type GlyphOptions, Hexagon, type ImageDataLike, type NGonOptions, Optimizer, type Point, type PreCfg, type RGB, type RectOptions, Rectangle, type ReplayResult, SVGNS, type SerializedOutput, Shape, type ShapeImageData, type ShapeInterface, Square, State, Step, type StepData, Triangle, bboxOfPoints, clamp, clampColor, computeColorAndDifferenceChange, difference, differenceToDistance, distanceToDifference, getFill, makeCircle, makeEllipse, makeGlyph, makeNGon, makeRect, parseColor, randomPolarOffset, rectCorners, regularPolygonPoints, renderStepToCtx, replayOutput, rgbToHsl, stepDataToSVGElement, stepPerf };
|