@pooder/kit 5.3.1 → 5.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.
Files changed (90) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/index.d.mts +243 -36
  3. package/dist/index.d.ts +243 -36
  4. package/dist/index.js +2278 -1041
  5. package/dist/index.mjs +2278 -1041
  6. package/package.json +1 -1
  7. package/src/coordinate.ts +106 -106
  8. package/src/extensions/background.ts +323 -230
  9. package/src/extensions/bridgeSelection.ts +17 -17
  10. package/src/extensions/constraints.ts +322 -322
  11. package/src/extensions/dieline.ts +1149 -1076
  12. package/src/extensions/dielineShape.ts +109 -0
  13. package/src/extensions/edgeScale.ts +19 -19
  14. package/src/extensions/feature.ts +1137 -1021
  15. package/src/extensions/featureComplete.ts +46 -46
  16. package/src/extensions/film.ts +266 -194
  17. package/src/extensions/geometry.ts +885 -752
  18. package/src/extensions/image.ts +2054 -1926
  19. package/src/extensions/index.ts +11 -11
  20. package/src/extensions/maskOps.ts +283 -283
  21. package/src/extensions/mirror.ts +128 -128
  22. package/src/extensions/ruler.ts +654 -451
  23. package/src/extensions/sceneLayout.ts +140 -140
  24. package/src/extensions/sceneLayoutModel.ts +364 -352
  25. package/src/extensions/sceneVisibility.ts +64 -71
  26. package/src/extensions/size.ts +389 -389
  27. package/src/extensions/tracer.ts +1019 -1019
  28. package/src/extensions/white-ink.ts +1567 -1514
  29. package/src/extensions/wrappedOffsets.ts +33 -33
  30. package/src/index.ts +2 -2
  31. package/src/services/CanvasService.ts +832 -300
  32. package/src/services/ViewportSystem.ts +95 -95
  33. package/src/services/index.ts +3 -3
  34. package/src/services/renderSpec.ts +53 -18
  35. package/src/units.ts +27 -27
  36. package/tests/run.ts +118 -118
  37. package/tsconfig.test.json +15 -15
  38. package/.test-dist/src/CanvasService.js +0 -249
  39. package/.test-dist/src/ViewportSystem.js +0 -75
  40. package/.test-dist/src/background.js +0 -203
  41. package/.test-dist/src/bridgeSelection.js +0 -20
  42. package/.test-dist/src/constraints.js +0 -237
  43. package/.test-dist/src/coordinate.js +0 -74
  44. package/.test-dist/src/dieline.js +0 -818
  45. package/.test-dist/src/edgeScale.js +0 -12
  46. package/.test-dist/src/extensions/background.js +0 -203
  47. package/.test-dist/src/extensions/bridgeSelection.js +0 -20
  48. package/.test-dist/src/extensions/constraints.js +0 -237
  49. package/.test-dist/src/extensions/dieline.js +0 -828
  50. package/.test-dist/src/extensions/edgeScale.js +0 -12
  51. package/.test-dist/src/extensions/feature.js +0 -825
  52. package/.test-dist/src/extensions/featureComplete.js +0 -32
  53. package/.test-dist/src/extensions/film.js +0 -167
  54. package/.test-dist/src/extensions/geometry.js +0 -545
  55. package/.test-dist/src/extensions/image.js +0 -1529
  56. package/.test-dist/src/extensions/index.js +0 -30
  57. package/.test-dist/src/extensions/maskOps.js +0 -279
  58. package/.test-dist/src/extensions/mirror.js +0 -104
  59. package/.test-dist/src/extensions/ruler.js +0 -345
  60. package/.test-dist/src/extensions/sceneLayout.js +0 -96
  61. package/.test-dist/src/extensions/sceneLayoutModel.js +0 -196
  62. package/.test-dist/src/extensions/sceneVisibility.js +0 -62
  63. package/.test-dist/src/extensions/size.js +0 -331
  64. package/.test-dist/src/extensions/tracer.js +0 -538
  65. package/.test-dist/src/extensions/white-ink.js +0 -1190
  66. package/.test-dist/src/extensions/wrappedOffsets.js +0 -33
  67. package/.test-dist/src/feature.js +0 -826
  68. package/.test-dist/src/featureComplete.js +0 -32
  69. package/.test-dist/src/film.js +0 -167
  70. package/.test-dist/src/geometry.js +0 -506
  71. package/.test-dist/src/image.js +0 -1250
  72. package/.test-dist/src/index.js +0 -18
  73. package/.test-dist/src/maskOps.js +0 -270
  74. package/.test-dist/src/mirror.js +0 -104
  75. package/.test-dist/src/renderSpec.js +0 -2
  76. package/.test-dist/src/ruler.js +0 -343
  77. package/.test-dist/src/sceneLayout.js +0 -99
  78. package/.test-dist/src/sceneLayoutModel.js +0 -196
  79. package/.test-dist/src/sceneView.js +0 -40
  80. package/.test-dist/src/sceneVisibility.js +0 -42
  81. package/.test-dist/src/services/CanvasService.js +0 -249
  82. package/.test-dist/src/services/ViewportSystem.js +0 -76
  83. package/.test-dist/src/services/index.js +0 -24
  84. package/.test-dist/src/services/renderSpec.js +0 -2
  85. package/.test-dist/src/size.js +0 -332
  86. package/.test-dist/src/tracer.js +0 -544
  87. package/.test-dist/src/units.js +0 -30
  88. package/.test-dist/src/white-ink.js +0 -829
  89. package/.test-dist/src/wrappedOffsets.js +0 -33
  90. package/.test-dist/tests/run.js +0 -94
@@ -1,95 +1,95 @@
1
- import { Coordinate, Layout, Point, Size } from "../coordinate";
2
-
3
- export class ViewportSystem {
4
- private _containerSize: Size = { width: 0, height: 0 };
5
- private _physicalSize: Size = { width: 0, height: 0 };
6
- private _padding: number = 0;
7
- private _layout: Layout = {
8
- scale: 1,
9
- offsetX: 0,
10
- offsetY: 0,
11
- width: 0,
12
- height: 0,
13
- };
14
-
15
- constructor(
16
- containerSize: Size = { width: 0, height: 0 },
17
- physicalSize: Size = { width: 0, height: 0 },
18
- padding: number = 40,
19
- ) {
20
- this._containerSize = containerSize;
21
- this._physicalSize = physicalSize;
22
- this._padding = padding;
23
- this.updateLayout();
24
- }
25
-
26
- get layout(): Layout {
27
- return this._layout;
28
- }
29
-
30
- get scale(): number {
31
- return this._layout.scale;
32
- }
33
-
34
- get offset(): Point {
35
- return { x: this._layout.offsetX, y: this._layout.offsetY };
36
- }
37
-
38
- updateContainer(width: number, height: number) {
39
- if (
40
- this._containerSize.width === width &&
41
- this._containerSize.height === height
42
- )
43
- return;
44
- this._containerSize = { width, height };
45
- this.updateLayout();
46
- }
47
-
48
- updatePhysical(width: number, height: number) {
49
- if (
50
- this._physicalSize.width === width &&
51
- this._physicalSize.height === height
52
- )
53
- return;
54
- this._physicalSize = { width, height };
55
- this.updateLayout();
56
- }
57
-
58
- setPadding(padding: number) {
59
- if (this._padding === padding) return;
60
- this._padding = padding;
61
- this.updateLayout();
62
- }
63
-
64
- private updateLayout() {
65
- this._layout = Coordinate.calculateLayout(
66
- this._containerSize,
67
- this._physicalSize,
68
- this._padding,
69
- );
70
- }
71
-
72
- toPixel(value: number): number {
73
- return value * this._layout.scale;
74
- }
75
-
76
- toPhysical(value: number): number {
77
- return this._layout.scale === 0 ? 0 : value / this._layout.scale;
78
- }
79
-
80
- toPixelPoint(point: Point): Point {
81
- return {
82
- x: point.x * this._layout.scale + this._layout.offsetX,
83
- y: point.y * this._layout.scale + this._layout.offsetY,
84
- };
85
- }
86
-
87
- // Convert screen coordinate (e.g. mouse event) to physical coordinate (relative to content origin)
88
- toPhysicalPoint(point: Point): Point {
89
- if (this._layout.scale === 0) return { x: 0, y: 0 };
90
- return {
91
- x: (point.x - this._layout.offsetX) / this._layout.scale,
92
- y: (point.y - this._layout.offsetY) / this._layout.scale,
93
- };
94
- }
95
- }
1
+ import { Coordinate, Layout, Point, Size } from "../coordinate";
2
+
3
+ export class ViewportSystem {
4
+ private _containerSize: Size = { width: 0, height: 0 };
5
+ private _physicalSize: Size = { width: 0, height: 0 };
6
+ private _padding: number = 0;
7
+ private _layout: Layout = {
8
+ scale: 1,
9
+ offsetX: 0,
10
+ offsetY: 0,
11
+ width: 0,
12
+ height: 0,
13
+ };
14
+
15
+ constructor(
16
+ containerSize: Size = { width: 0, height: 0 },
17
+ physicalSize: Size = { width: 0, height: 0 },
18
+ padding: number = 40,
19
+ ) {
20
+ this._containerSize = containerSize;
21
+ this._physicalSize = physicalSize;
22
+ this._padding = padding;
23
+ this.updateLayout();
24
+ }
25
+
26
+ get layout(): Layout {
27
+ return this._layout;
28
+ }
29
+
30
+ get scale(): number {
31
+ return this._layout.scale;
32
+ }
33
+
34
+ get offset(): Point {
35
+ return { x: this._layout.offsetX, y: this._layout.offsetY };
36
+ }
37
+
38
+ updateContainer(width: number, height: number) {
39
+ if (
40
+ this._containerSize.width === width &&
41
+ this._containerSize.height === height
42
+ )
43
+ return;
44
+ this._containerSize = { width, height };
45
+ this.updateLayout();
46
+ }
47
+
48
+ updatePhysical(width: number, height: number) {
49
+ if (
50
+ this._physicalSize.width === width &&
51
+ this._physicalSize.height === height
52
+ )
53
+ return;
54
+ this._physicalSize = { width, height };
55
+ this.updateLayout();
56
+ }
57
+
58
+ setPadding(padding: number) {
59
+ if (this._padding === padding) return;
60
+ this._padding = padding;
61
+ this.updateLayout();
62
+ }
63
+
64
+ private updateLayout() {
65
+ this._layout = Coordinate.calculateLayout(
66
+ this._containerSize,
67
+ this._physicalSize,
68
+ this._padding,
69
+ );
70
+ }
71
+
72
+ toPixel(value: number): number {
73
+ return value * this._layout.scale;
74
+ }
75
+
76
+ toPhysical(value: number): number {
77
+ return this._layout.scale === 0 ? 0 : value / this._layout.scale;
78
+ }
79
+
80
+ toPixelPoint(point: Point): Point {
81
+ return {
82
+ x: point.x * this._layout.scale + this._layout.offsetX,
83
+ y: point.y * this._layout.scale + this._layout.offsetY,
84
+ };
85
+ }
86
+
87
+ // Convert screen coordinate (e.g. mouse event) to physical coordinate (relative to content origin)
88
+ toPhysicalPoint(point: Point): Point {
89
+ if (this._layout.scale === 0) return { x: 0, y: 0 };
90
+ return {
91
+ x: (point.x - this._layout.offsetX) / this._layout.scale,
92
+ y: (point.y - this._layout.offsetY) / this._layout.scale,
93
+ };
94
+ }
95
+ }
@@ -1,3 +1,3 @@
1
- export { default as CanvasService } from "./CanvasService";
2
- export * from "./renderSpec";
3
- export * from "./ViewportSystem";
1
+ export { default as CanvasService } from "./CanvasService";
2
+ export * from "./renderSpec";
3
+ export * from "./ViewportSystem";
@@ -1,18 +1,53 @@
1
- export type RenderObjectType = "rect" | "image" | "path";
2
-
3
- export type RenderProps = Record<string, any>;
4
-
5
- export interface RenderObjectSpec {
6
- id: string;
7
- type: RenderObjectType;
8
- props: RenderProps;
9
- data?: Record<string, any>;
10
- src?: string;
11
- }
12
-
13
- export interface RenderLayerSpec {
14
- id: string;
15
- objects: RenderObjectSpec[];
16
- props?: RenderProps;
17
- }
18
-
1
+ export type RenderObjectType = "rect" | "image" | "path" | "text";
2
+
3
+ export type RenderProps = Record<string, any>;
4
+ export type RenderCoordinateSpace = "scene" | "screen";
5
+ export type RenderLayoutLength = number | string;
6
+ export type RenderLayoutAlign = "start" | "center" | "end";
7
+ export type RenderLayoutReference =
8
+ | "sceneViewport"
9
+ | "screenViewport"
10
+ | "custom";
11
+
12
+ export interface RenderLayoutInsets {
13
+ top?: RenderLayoutLength;
14
+ right?: RenderLayoutLength;
15
+ bottom?: RenderLayoutLength;
16
+ left?: RenderLayoutLength;
17
+ }
18
+
19
+ export interface RenderLayoutRect {
20
+ left: number;
21
+ top: number;
22
+ width: number;
23
+ height: number;
24
+ space?: RenderCoordinateSpace;
25
+ }
26
+
27
+ export interface RenderObjectLayoutSpec {
28
+ reference?: RenderLayoutReference;
29
+ referenceRect?: RenderLayoutRect;
30
+ inset?: RenderLayoutLength | RenderLayoutInsets;
31
+ alignX?: RenderLayoutAlign;
32
+ alignY?: RenderLayoutAlign;
33
+ offsetX?: RenderLayoutLength;
34
+ offsetY?: RenderLayoutLength;
35
+ width?: RenderLayoutLength;
36
+ height?: RenderLayoutLength;
37
+ }
38
+
39
+ export interface RenderObjectSpec {
40
+ id: string;
41
+ type: RenderObjectType;
42
+ props: RenderProps;
43
+ data?: Record<string, any>;
44
+ src?: string;
45
+ space?: RenderCoordinateSpace;
46
+ layout?: RenderObjectLayoutSpec;
47
+ }
48
+
49
+ export interface RenderLayerSpec {
50
+ id: string;
51
+ objects: RenderObjectSpec[];
52
+ props?: RenderProps;
53
+ }
package/src/units.ts CHANGED
@@ -1,27 +1,27 @@
1
- import { Coordinate, Unit } from "./coordinate";
2
-
3
- export function parseLengthToMm(input: number | string, defaultUnit: Unit): number {
4
- if (typeof input === "number") {
5
- if (!Number.isFinite(input)) return 0;
6
- return Coordinate.convertUnit(input, defaultUnit, "mm");
7
- }
8
-
9
- const raw = input.trim();
10
- if (!raw) return 0;
11
-
12
- const match = raw.match(/^([+-]?\d+(?:\.\d+)?)\s*(px|mm|cm|in)?$/i);
13
- if (!match) return 0;
14
-
15
- const value = Number(match[1]);
16
- if (!Number.isFinite(value)) return 0;
17
-
18
- const unit = (match[2]?.toLowerCase() as Unit | undefined) ?? defaultUnit;
19
- return Coordinate.convertUnit(value, unit, "mm");
20
- }
21
-
22
- export function formatMm(valueMm: number, displayUnit: Unit, fractionDigits: number = 2): string {
23
- if (!Number.isFinite(valueMm)) return "0";
24
- const value = Coordinate.convertUnit(valueMm, "mm", displayUnit);
25
- const rounded = Number(value.toFixed(fractionDigits));
26
- return rounded.toString();
27
- }
1
+ import { Coordinate, Unit } from "./coordinate";
2
+
3
+ export function parseLengthToMm(input: number | string, defaultUnit: Unit): number {
4
+ if (typeof input === "number") {
5
+ if (!Number.isFinite(input)) return 0;
6
+ return Coordinate.convertUnit(input, defaultUnit, "mm");
7
+ }
8
+
9
+ const raw = input.trim();
10
+ if (!raw) return 0;
11
+
12
+ const match = raw.match(/^([+-]?\d+(?:\.\d+)?)\s*(px|mm|cm|in)?$/i);
13
+ if (!match) return 0;
14
+
15
+ const value = Number(match[1]);
16
+ if (!Number.isFinite(value)) return 0;
17
+
18
+ const unit = (match[2]?.toLowerCase() as Unit | undefined) ?? defaultUnit;
19
+ return Coordinate.convertUnit(value, unit, "mm");
20
+ }
21
+
22
+ export function formatMm(valueMm: number, displayUnit: Unit, fractionDigits: number = 2): string {
23
+ if (!Number.isFinite(valueMm)) return "0";
24
+ const value = Coordinate.convertUnit(valueMm, "mm", displayUnit);
25
+ const rounded = Number(value.toFixed(fractionDigits));
26
+ return rounded.toString();
27
+ }
package/tests/run.ts CHANGED
@@ -1,118 +1,118 @@
1
- import { pickExitIndex, scoreOutsideAbove } from "../src/bridgeSelection";
2
- import { sampleWrappedOffsets, wrappedDistance } from "../src/wrappedOffsets";
3
- import {
4
- circularMorphology,
5
- createMask,
6
- fillHoles,
7
- findMinimalConnectRadius,
8
- isMaskConnected8,
9
- } from "../src/maskOps";
10
- import { computeDetectEdgeSize } from "../src/edgeScale";
11
-
12
- function assert(condition: unknown, message: string) {
13
- if (!condition) throw new Error(message);
14
- }
15
-
16
- function testWrappedOffsets() {
17
- assert(wrappedDistance(100, 10, 30) === 20, "distance 10->30 should be 20");
18
- assert(wrappedDistance(100, 90, 10) === 20, "distance 90->10 should wrap to 20");
19
-
20
- const a = sampleWrappedOffsets(100, 10, 30, 5);
21
- assert(
22
- JSON.stringify(a) === JSON.stringify([10, 15, 20, 25, 30]),
23
- `unexpected sample: ${JSON.stringify(a)}`,
24
- );
25
-
26
- const b = sampleWrappedOffsets(100, 90, 10, 3);
27
- assert(
28
- JSON.stringify(b) === JSON.stringify([90, 0, 10]),
29
- `unexpected wrap sample: ${JSON.stringify(b)}`,
30
- );
31
- }
32
-
33
- function testBridgeSelection() {
34
- const idx = pickExitIndex([
35
- { insideAbove: true, insideBelow: true },
36
- { insideAbove: false, insideBelow: true },
37
- { insideAbove: false, insideBelow: false },
38
- ]);
39
- assert(idx === 1, `expected exit index 1, got ${idx}`);
40
-
41
- const none = pickExitIndex([{ insideAbove: true, insideBelow: true }]);
42
- assert(none === -1, `expected -1, got ${none}`);
43
-
44
- const score = scoreOutsideAbove([
45
- { outsideAbove: true },
46
- { outsideAbove: false },
47
- { outsideAbove: true },
48
- ]);
49
- assert(score === 2, `expected score 2, got ${score}`);
50
- }
51
-
52
- function testMaskOps() {
53
- const width = 50;
54
- const height = 50;
55
- const mask = new Uint8Array(width * height);
56
- mask[10 * width + 10] = 1;
57
- mask[10 * width + 20] = 1;
58
-
59
- const r = findMinimalConnectRadius(mask, width, height, 20);
60
- const closed = circularMorphology(mask, width, height, r, "closing");
61
- assert(isMaskConnected8(closed, width, height), `closed mask should be connected (r=${r})`);
62
- if (r > 0) {
63
- const closedPrev = circularMorphology(mask, width, height, r - 1, "closing");
64
- assert(
65
- !isMaskConnected8(closedPrev, width, height),
66
- `r should be minimal (r=${r})`,
67
- );
68
- }
69
-
70
- const donut = new Uint8Array(9 * 9);
71
- for (let y = 1; y <= 7; y++) {
72
- for (let x = 1; x <= 7; x++) donut[y * 9 + x] = 1;
73
- }
74
- for (let y = 3; y <= 5; y++) {
75
- for (let x = 3; x <= 5; x++) donut[y * 9 + x] = 0;
76
- }
77
- const filled = fillHoles(donut, 9, 9);
78
- assert(filled[4 * 9 + 4] === 1, "hole should be filled");
79
-
80
- const imgW = 2;
81
- const imgH = 1;
82
- const rgba = new Uint8ClampedArray([
83
- 255, 255, 255, 255, 10, 10, 10, 254,
84
- ]);
85
- const imageData = { width: imgW, height: imgH, data: rgba } as unknown as ImageData;
86
- const paddedWidth = imgW + 4;
87
- const paddedHeight = imgH + 4;
88
- const created = createMask(imageData, {
89
- threshold: 10,
90
- padding: 2,
91
- paddedWidth,
92
- paddedHeight,
93
- maskMode: "auto",
94
- alphaOpaqueCutoff: 250,
95
- });
96
- assert(created[2 * paddedWidth + 2] === 0, "white pixel should be background");
97
- assert(created[2 * paddedWidth + 3] === 1, "non-white pixel should be foreground");
98
- }
99
-
100
- function testEdgeScale() {
101
- const currentMax = 100;
102
- const baseBounds = { width: 50, height: 20 };
103
- const expandedBounds = { width: 70, height: 40 };
104
- const { width, height, scale } = computeDetectEdgeSize(currentMax, baseBounds, expandedBounds);
105
- assert(scale === 2, `expected scale 2, got ${scale}`);
106
- assert(width === 140, `expected width 140, got ${width}`);
107
- assert(height === 80, `expected height 80, got ${height}`);
108
- }
109
-
110
- function main() {
111
- testWrappedOffsets();
112
- testBridgeSelection();
113
- testMaskOps();
114
- testEdgeScale();
115
- console.log("ok");
116
- }
117
-
118
- main();
1
+ import { pickExitIndex, scoreOutsideAbove } from "../src/bridgeSelection";
2
+ import { sampleWrappedOffsets, wrappedDistance } from "../src/wrappedOffsets";
3
+ import {
4
+ circularMorphology,
5
+ createMask,
6
+ fillHoles,
7
+ findMinimalConnectRadius,
8
+ isMaskConnected8,
9
+ } from "../src/maskOps";
10
+ import { computeDetectEdgeSize } from "../src/edgeScale";
11
+
12
+ function assert(condition: unknown, message: string) {
13
+ if (!condition) throw new Error(message);
14
+ }
15
+
16
+ function testWrappedOffsets() {
17
+ assert(wrappedDistance(100, 10, 30) === 20, "distance 10->30 should be 20");
18
+ assert(wrappedDistance(100, 90, 10) === 20, "distance 90->10 should wrap to 20");
19
+
20
+ const a = sampleWrappedOffsets(100, 10, 30, 5);
21
+ assert(
22
+ JSON.stringify(a) === JSON.stringify([10, 15, 20, 25, 30]),
23
+ `unexpected sample: ${JSON.stringify(a)}`,
24
+ );
25
+
26
+ const b = sampleWrappedOffsets(100, 90, 10, 3);
27
+ assert(
28
+ JSON.stringify(b) === JSON.stringify([90, 0, 10]),
29
+ `unexpected wrap sample: ${JSON.stringify(b)}`,
30
+ );
31
+ }
32
+
33
+ function testBridgeSelection() {
34
+ const idx = pickExitIndex([
35
+ { insideAbove: true, insideBelow: true },
36
+ { insideAbove: false, insideBelow: true },
37
+ { insideAbove: false, insideBelow: false },
38
+ ]);
39
+ assert(idx === 1, `expected exit index 1, got ${idx}`);
40
+
41
+ const none = pickExitIndex([{ insideAbove: true, insideBelow: true }]);
42
+ assert(none === -1, `expected -1, got ${none}`);
43
+
44
+ const score = scoreOutsideAbove([
45
+ { outsideAbove: true },
46
+ { outsideAbove: false },
47
+ { outsideAbove: true },
48
+ ]);
49
+ assert(score === 2, `expected score 2, got ${score}`);
50
+ }
51
+
52
+ function testMaskOps() {
53
+ const width = 50;
54
+ const height = 50;
55
+ const mask = new Uint8Array(width * height);
56
+ mask[10 * width + 10] = 1;
57
+ mask[10 * width + 20] = 1;
58
+
59
+ const r = findMinimalConnectRadius(mask, width, height, 20);
60
+ const closed = circularMorphology(mask, width, height, r, "closing");
61
+ assert(isMaskConnected8(closed, width, height), `closed mask should be connected (r=${r})`);
62
+ if (r > 0) {
63
+ const closedPrev = circularMorphology(mask, width, height, r - 1, "closing");
64
+ assert(
65
+ !isMaskConnected8(closedPrev, width, height),
66
+ `r should be minimal (r=${r})`,
67
+ );
68
+ }
69
+
70
+ const donut = new Uint8Array(9 * 9);
71
+ for (let y = 1; y <= 7; y++) {
72
+ for (let x = 1; x <= 7; x++) donut[y * 9 + x] = 1;
73
+ }
74
+ for (let y = 3; y <= 5; y++) {
75
+ for (let x = 3; x <= 5; x++) donut[y * 9 + x] = 0;
76
+ }
77
+ const filled = fillHoles(donut, 9, 9);
78
+ assert(filled[4 * 9 + 4] === 1, "hole should be filled");
79
+
80
+ const imgW = 2;
81
+ const imgH = 1;
82
+ const rgba = new Uint8ClampedArray([
83
+ 255, 255, 255, 255, 10, 10, 10, 254,
84
+ ]);
85
+ const imageData = { width: imgW, height: imgH, data: rgba } as unknown as ImageData;
86
+ const paddedWidth = imgW + 4;
87
+ const paddedHeight = imgH + 4;
88
+ const created = createMask(imageData, {
89
+ threshold: 10,
90
+ padding: 2,
91
+ paddedWidth,
92
+ paddedHeight,
93
+ maskMode: "auto",
94
+ alphaOpaqueCutoff: 250,
95
+ });
96
+ assert(created[2 * paddedWidth + 2] === 0, "white pixel should be background");
97
+ assert(created[2 * paddedWidth + 3] === 1, "non-white pixel should be foreground");
98
+ }
99
+
100
+ function testEdgeScale() {
101
+ const currentMax = 100;
102
+ const baseBounds = { width: 50, height: 20 };
103
+ const expandedBounds = { width: 70, height: 40 };
104
+ const { width, height, scale } = computeDetectEdgeSize(currentMax, baseBounds, expandedBounds);
105
+ assert(scale === 2, `expected scale 2, got ${scale}`);
106
+ assert(width === 140, `expected width 140, got ${width}`);
107
+ assert(height === 80, `expected height 80, got ${height}`);
108
+ }
109
+
110
+ function main() {
111
+ testWrappedOffsets();
112
+ testBridgeSelection();
113
+ testMaskOps();
114
+ testEdgeScale();
115
+ console.log("ok");
116
+ }
117
+
118
+ main();
@@ -1,15 +1,15 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2020",
4
- "module": "CommonJS",
5
- "lib": ["ES2020", "DOM"],
6
- "moduleResolution": "Node",
7
- "esModuleInterop": true,
8
- "skipLibCheck": true,
9
- "strict": true,
10
- "outDir": ".test-dist",
11
- "rootDir": "."
12
- },
13
- "include": ["tests/**/*.ts", "src/**/*.ts"]
14
- }
15
-
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "CommonJS",
5
+ "lib": ["ES2020", "DOM"],
6
+ "moduleResolution": "Node",
7
+ "esModuleInterop": true,
8
+ "skipLibCheck": true,
9
+ "strict": true,
10
+ "outDir": ".test-dist",
11
+ "rootDir": "."
12
+ },
13
+ "include": ["tests/**/*.ts", "src/**/*.ts"]
14
+ }
15
+