@pooder/kit 5.1.0 → 5.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.
Files changed (86) hide show
  1. package/.test-dist/src/CanvasService.js +249 -249
  2. package/.test-dist/src/ViewportSystem.js +75 -75
  3. package/.test-dist/src/background.js +203 -203
  4. package/.test-dist/src/bridgeSelection.js +20 -20
  5. package/.test-dist/src/constraints.js +237 -237
  6. package/.test-dist/src/dieline.js +818 -818
  7. package/.test-dist/src/edgeScale.js +12 -12
  8. package/.test-dist/src/extensions/background.js +203 -0
  9. package/.test-dist/src/extensions/bridgeSelection.js +20 -0
  10. package/.test-dist/src/extensions/constraints.js +237 -0
  11. package/.test-dist/src/extensions/dieline.js +828 -0
  12. package/.test-dist/src/extensions/edgeScale.js +12 -0
  13. package/.test-dist/src/extensions/feature.js +825 -0
  14. package/.test-dist/src/extensions/featureComplete.js +32 -0
  15. package/.test-dist/src/extensions/film.js +167 -0
  16. package/.test-dist/src/extensions/geometry.js +545 -0
  17. package/.test-dist/src/extensions/image.js +1529 -0
  18. package/.test-dist/src/extensions/index.js +30 -0
  19. package/.test-dist/src/extensions/maskOps.js +279 -0
  20. package/.test-dist/src/extensions/mirror.js +104 -0
  21. package/.test-dist/src/extensions/ruler.js +345 -0
  22. package/.test-dist/src/extensions/sceneLayout.js +96 -0
  23. package/.test-dist/src/extensions/sceneLayoutModel.js +196 -0
  24. package/.test-dist/src/extensions/sceneVisibility.js +62 -0
  25. package/.test-dist/src/extensions/size.js +331 -0
  26. package/.test-dist/src/extensions/tracer.js +538 -0
  27. package/.test-dist/src/extensions/white-ink.js +1190 -0
  28. package/.test-dist/src/extensions/wrappedOffsets.js +33 -0
  29. package/.test-dist/src/feature.js +826 -826
  30. package/.test-dist/src/featureComplete.js +32 -32
  31. package/.test-dist/src/film.js +167 -167
  32. package/.test-dist/src/geometry.js +506 -506
  33. package/.test-dist/src/image.js +1250 -1250
  34. package/.test-dist/src/index.js +2 -19
  35. package/.test-dist/src/maskOps.js +270 -270
  36. package/.test-dist/src/mirror.js +104 -104
  37. package/.test-dist/src/renderSpec.js +2 -2
  38. package/.test-dist/src/ruler.js +343 -343
  39. package/.test-dist/src/sceneLayout.js +99 -99
  40. package/.test-dist/src/sceneLayoutModel.js +196 -196
  41. package/.test-dist/src/sceneView.js +40 -40
  42. package/.test-dist/src/sceneVisibility.js +42 -42
  43. package/.test-dist/src/services/CanvasService.js +249 -0
  44. package/.test-dist/src/services/ViewportSystem.js +76 -0
  45. package/.test-dist/src/services/index.js +24 -0
  46. package/.test-dist/src/services/renderSpec.js +2 -0
  47. package/.test-dist/src/size.js +332 -332
  48. package/.test-dist/src/tracer.js +544 -544
  49. package/.test-dist/src/white-ink.js +829 -829
  50. package/.test-dist/src/wrappedOffsets.js +33 -33
  51. package/CHANGELOG.md +12 -0
  52. package/dist/index.d.mts +14 -0
  53. package/dist/index.d.ts +14 -0
  54. package/dist/index.js +3521 -3220
  55. package/dist/index.mjs +3532 -3226
  56. package/package.json +1 -1
  57. package/src/coordinate.ts +106 -106
  58. package/src/extensions/background.ts +230 -230
  59. package/src/extensions/bridgeSelection.ts +17 -17
  60. package/src/extensions/constraints.ts +322 -322
  61. package/src/extensions/dieline.ts +20 -17
  62. package/src/extensions/edgeScale.ts +19 -19
  63. package/src/extensions/feature.ts +1021 -1021
  64. package/src/extensions/featureComplete.ts +46 -46
  65. package/src/extensions/film.ts +194 -194
  66. package/src/extensions/geometry.ts +719 -719
  67. package/src/extensions/image.ts +1924 -1594
  68. package/src/extensions/index.ts +11 -11
  69. package/src/extensions/maskOps.ts +365 -299
  70. package/src/extensions/mirror.ts +128 -128
  71. package/src/extensions/ruler.ts +451 -451
  72. package/src/extensions/sceneLayout.ts +140 -140
  73. package/src/extensions/sceneLayoutModel.ts +342 -342
  74. package/src/extensions/sceneVisibility.ts +71 -71
  75. package/src/extensions/size.ts +389 -389
  76. package/src/extensions/tracer.ts +302 -370
  77. package/src/extensions/white-ink.ts +1489 -1366
  78. package/src/extensions/wrappedOffsets.ts +33 -33
  79. package/src/index.ts +2 -2
  80. package/src/services/CanvasService.ts +300 -300
  81. package/src/services/ViewportSystem.ts +95 -95
  82. package/src/services/index.ts +3 -3
  83. package/src/services/renderSpec.ts +18 -18
  84. package/src/units.ts +27 -27
  85. package/tests/run.ts +118 -118
  86. package/tsconfig.test.json +15 -15
@@ -1,46 +1,46 @@
1
- import { ConstraintContext, ConstraintFeature, ConstraintRegistry } from "./constraints";
2
-
3
- export type FeatureCompleteIssue = {
4
- featureId: string;
5
- groupId?: string;
6
- reason: string;
7
- };
8
-
9
- export function validateFeaturesStrict(
10
- features: ConstraintFeature[],
11
- context: ConstraintContext,
12
- ): { ok: boolean; issues?: FeatureCompleteIssue[] } {
13
- const eps = 1e-6;
14
- const issues: FeatureCompleteIssue[] = [];
15
-
16
- for (const f of features) {
17
- if (!f.constraints || f.constraints.length === 0) continue;
18
- // Pass ALL constraints (including validateOnly) for strict validation check
19
- const constrained = ConstraintRegistry.apply(f.x, f.y, f, context, f.constraints);
20
- if (
21
- Math.abs(constrained.x - f.x) > eps ||
22
- Math.abs(constrained.y - f.y) > eps
23
- ) {
24
- issues.push({
25
- featureId: f.id,
26
- groupId: f.groupId,
27
- reason: "Position violates constraint strategy",
28
- });
29
- }
30
- }
31
-
32
- return { ok: issues.length === 0, issues: issues.length ? issues : undefined };
33
- }
34
-
35
- export function completeFeaturesStrict(
36
- features: ConstraintFeature[],
37
- context: ConstraintContext,
38
- update: (nextFeatures: ConstraintFeature[]) => void,
39
- ): { ok: boolean; issues?: FeatureCompleteIssue[] } {
40
- const validation = validateFeaturesStrict(features, context);
41
- if (!validation.ok) return validation;
42
- const next = JSON.parse(JSON.stringify(features || [])) as ConstraintFeature[];
43
- update(next);
44
- return { ok: true };
45
- }
46
-
1
+ import { ConstraintContext, ConstraintFeature, ConstraintRegistry } from "./constraints";
2
+
3
+ export type FeatureCompleteIssue = {
4
+ featureId: string;
5
+ groupId?: string;
6
+ reason: string;
7
+ };
8
+
9
+ export function validateFeaturesStrict(
10
+ features: ConstraintFeature[],
11
+ context: ConstraintContext,
12
+ ): { ok: boolean; issues?: FeatureCompleteIssue[] } {
13
+ const eps = 1e-6;
14
+ const issues: FeatureCompleteIssue[] = [];
15
+
16
+ for (const f of features) {
17
+ if (!f.constraints || f.constraints.length === 0) continue;
18
+ // Pass ALL constraints (including validateOnly) for strict validation check
19
+ const constrained = ConstraintRegistry.apply(f.x, f.y, f, context, f.constraints);
20
+ if (
21
+ Math.abs(constrained.x - f.x) > eps ||
22
+ Math.abs(constrained.y - f.y) > eps
23
+ ) {
24
+ issues.push({
25
+ featureId: f.id,
26
+ groupId: f.groupId,
27
+ reason: "Position violates constraint strategy",
28
+ });
29
+ }
30
+ }
31
+
32
+ return { ok: issues.length === 0, issues: issues.length ? issues : undefined };
33
+ }
34
+
35
+ export function completeFeaturesStrict(
36
+ features: ConstraintFeature[],
37
+ context: ConstraintContext,
38
+ update: (nextFeatures: ConstraintFeature[]) => void,
39
+ ): { ok: boolean; issues?: FeatureCompleteIssue[] } {
40
+ const validation = validateFeaturesStrict(features, context);
41
+ if (!validation.ok) return validation;
42
+ const next = JSON.parse(JSON.stringify(features || [])) as ConstraintFeature[];
43
+ update(next);
44
+ return { ok: true };
45
+ }
46
+
@@ -1,194 +1,194 @@
1
- import {
2
- Extension,
3
- ExtensionContext,
4
- ContributionPointIds,
5
- CommandContribution,
6
- ConfigurationContribution,
7
- } from "@pooder/core";
8
- import { FabricImage as Image } from "fabric";
9
- import { CanvasService } from "../services";
10
-
11
- export class FilmTool implements Extension {
12
- id = "pooder.kit.film";
13
-
14
- public metadata = {
15
- name: "FilmTool",
16
- };
17
-
18
- private url: string = "";
19
- private opacity: number = 0.5;
20
-
21
- private canvasService?: CanvasService;
22
-
23
- constructor(
24
- options?: Partial<{
25
- url: string;
26
- opacity: number;
27
- }>,
28
- ) {
29
- if (options) {
30
- Object.assign(this, options);
31
- }
32
- }
33
-
34
- activate(context: ExtensionContext) {
35
- this.canvasService = context.services.get<CanvasService>("CanvasService");
36
- if (!this.canvasService) {
37
- console.warn("CanvasService not found for FilmTool");
38
- return;
39
- }
40
-
41
- const configService = context.services.get<any>("ConfigurationService");
42
- if (configService) {
43
- // Load initial config
44
- this.url = configService.get("film.url", this.url);
45
- this.opacity = configService.get("film.opacity", this.opacity);
46
-
47
- // Listen for changes
48
- configService.onAnyChange((e: { key: string; value: any }) => {
49
- if (e.key.startsWith("film.")) {
50
- const prop = e.key.split(".")[1];
51
- console.log(
52
- `[FilmTool] Config change detected: ${e.key} -> ${e.value}`,
53
- );
54
- if (prop && prop in this) {
55
- (this as any)[prop] = e.value;
56
- this.updateFilm();
57
- }
58
- }
59
- });
60
- }
61
-
62
- this.initLayer();
63
- this.updateFilm();
64
- }
65
-
66
- deactivate(context: ExtensionContext) {
67
- if (this.canvasService) {
68
- const layer = this.canvasService.getLayer("overlay");
69
- if (layer) {
70
- const img = this.canvasService.getObject("film-image", "overlay");
71
- if (img) {
72
- layer.remove(img);
73
- this.canvasService.requestRenderAll();
74
- }
75
- }
76
- this.canvasService = undefined;
77
- }
78
- }
79
-
80
- contribute() {
81
- return {
82
- [ContributionPointIds.CONFIGURATIONS]: [
83
- {
84
- id: "film.url",
85
- type: "string",
86
- label: "Film Image URL",
87
- default: "",
88
- },
89
- {
90
- id: "film.opacity",
91
- type: "number",
92
- label: "Opacity",
93
- min: 0,
94
- max: 1,
95
- step: 0.1,
96
- default: 0.5,
97
- },
98
- ] as ConfigurationContribution[],
99
- [ContributionPointIds.COMMANDS]: [
100
- {
101
- command: "setFilmImage",
102
- title: "Set Film Image",
103
- handler: (url: string, opacity: number) => {
104
- if (this.url === url && this.opacity === opacity) return true;
105
-
106
- this.url = url;
107
- this.opacity = opacity;
108
-
109
- this.updateFilm();
110
-
111
- return true;
112
- },
113
- },
114
- ] as CommandContribution[],
115
- };
116
- }
117
-
118
- private initLayer() {
119
- if (!this.canvasService) return;
120
- let overlayLayer = this.canvasService.getLayer("overlay");
121
- if (!overlayLayer) {
122
- const width = this.canvasService.canvas.width || 800;
123
- const height = this.canvasService.canvas.height || 600;
124
-
125
- const layer = this.canvasService.createLayer("overlay", {
126
- width,
127
- height,
128
- left: 0,
129
- top: 0,
130
- originX: "left",
131
- originY: "top",
132
- selectable: false,
133
- evented: false,
134
- subTargetCheck: false,
135
- interactive: false,
136
- });
137
-
138
- this.canvasService.canvas.bringObjectToFront(layer);
139
- }
140
- }
141
-
142
- private async updateFilm() {
143
- if (!this.canvasService) return;
144
- const layer = this.canvasService.getLayer("overlay");
145
- if (!layer) {
146
- console.warn("[FilmTool] Overlay layer not found");
147
- return;
148
- }
149
-
150
- const { url, opacity } = this;
151
-
152
- if (!url) {
153
- const img = this.canvasService.getObject("film-image", "overlay");
154
- if (img) {
155
- layer.remove(img);
156
- this.canvasService.requestRenderAll();
157
- }
158
- return;
159
- }
160
-
161
- const width = this.canvasService.canvas.width || 800;
162
- const height = this.canvasService.canvas.height || 600;
163
-
164
- let img = this.canvasService.getObject("film-image", "overlay") as Image;
165
- try {
166
- if (img) {
167
- if (img.getSrc() !== url) {
168
- await img.setSrc(url);
169
- }
170
- img.set({ opacity });
171
- } else {
172
- img = await Image.fromURL(url, { crossOrigin: "anonymous" });
173
- img.scaleToWidth(width);
174
- if (img.getScaledHeight() < height) img.scaleToHeight(height);
175
- img.set({
176
- originX: "left",
177
- originY: "top",
178
- left: 0,
179
- top: 0,
180
- opacity,
181
- selectable: false,
182
- evented: false,
183
- data: { id: "film-image" },
184
- });
185
- layer.add(img);
186
- }
187
- this.canvasService.requestRenderAll();
188
- } catch (error) {
189
- console.error("[FilmTool] Failed to load film image", url, error);
190
- }
191
- layer.dirty = true;
192
- this.canvasService.requestRenderAll();
193
- }
194
- }
1
+ import {
2
+ Extension,
3
+ ExtensionContext,
4
+ ContributionPointIds,
5
+ CommandContribution,
6
+ ConfigurationContribution,
7
+ } from "@pooder/core";
8
+ import { FabricImage as Image } from "fabric";
9
+ import { CanvasService } from "../services";
10
+
11
+ export class FilmTool implements Extension {
12
+ id = "pooder.kit.film";
13
+
14
+ public metadata = {
15
+ name: "FilmTool",
16
+ };
17
+
18
+ private url: string = "";
19
+ private opacity: number = 0.5;
20
+
21
+ private canvasService?: CanvasService;
22
+
23
+ constructor(
24
+ options?: Partial<{
25
+ url: string;
26
+ opacity: number;
27
+ }>,
28
+ ) {
29
+ if (options) {
30
+ Object.assign(this, options);
31
+ }
32
+ }
33
+
34
+ activate(context: ExtensionContext) {
35
+ this.canvasService = context.services.get<CanvasService>("CanvasService");
36
+ if (!this.canvasService) {
37
+ console.warn("CanvasService not found for FilmTool");
38
+ return;
39
+ }
40
+
41
+ const configService = context.services.get<any>("ConfigurationService");
42
+ if (configService) {
43
+ // Load initial config
44
+ this.url = configService.get("film.url", this.url);
45
+ this.opacity = configService.get("film.opacity", this.opacity);
46
+
47
+ // Listen for changes
48
+ configService.onAnyChange((e: { key: string; value: any }) => {
49
+ if (e.key.startsWith("film.")) {
50
+ const prop = e.key.split(".")[1];
51
+ console.log(
52
+ `[FilmTool] Config change detected: ${e.key} -> ${e.value}`,
53
+ );
54
+ if (prop && prop in this) {
55
+ (this as any)[prop] = e.value;
56
+ this.updateFilm();
57
+ }
58
+ }
59
+ });
60
+ }
61
+
62
+ this.initLayer();
63
+ this.updateFilm();
64
+ }
65
+
66
+ deactivate(context: ExtensionContext) {
67
+ if (this.canvasService) {
68
+ const layer = this.canvasService.getLayer("overlay");
69
+ if (layer) {
70
+ const img = this.canvasService.getObject("film-image", "overlay");
71
+ if (img) {
72
+ layer.remove(img);
73
+ this.canvasService.requestRenderAll();
74
+ }
75
+ }
76
+ this.canvasService = undefined;
77
+ }
78
+ }
79
+
80
+ contribute() {
81
+ return {
82
+ [ContributionPointIds.CONFIGURATIONS]: [
83
+ {
84
+ id: "film.url",
85
+ type: "string",
86
+ label: "Film Image URL",
87
+ default: "",
88
+ },
89
+ {
90
+ id: "film.opacity",
91
+ type: "number",
92
+ label: "Opacity",
93
+ min: 0,
94
+ max: 1,
95
+ step: 0.1,
96
+ default: 0.5,
97
+ },
98
+ ] as ConfigurationContribution[],
99
+ [ContributionPointIds.COMMANDS]: [
100
+ {
101
+ command: "setFilmImage",
102
+ title: "Set Film Image",
103
+ handler: (url: string, opacity: number) => {
104
+ if (this.url === url && this.opacity === opacity) return true;
105
+
106
+ this.url = url;
107
+ this.opacity = opacity;
108
+
109
+ this.updateFilm();
110
+
111
+ return true;
112
+ },
113
+ },
114
+ ] as CommandContribution[],
115
+ };
116
+ }
117
+
118
+ private initLayer() {
119
+ if (!this.canvasService) return;
120
+ let overlayLayer = this.canvasService.getLayer("overlay");
121
+ if (!overlayLayer) {
122
+ const width = this.canvasService.canvas.width || 800;
123
+ const height = this.canvasService.canvas.height || 600;
124
+
125
+ const layer = this.canvasService.createLayer("overlay", {
126
+ width,
127
+ height,
128
+ left: 0,
129
+ top: 0,
130
+ originX: "left",
131
+ originY: "top",
132
+ selectable: false,
133
+ evented: false,
134
+ subTargetCheck: false,
135
+ interactive: false,
136
+ });
137
+
138
+ this.canvasService.canvas.bringObjectToFront(layer);
139
+ }
140
+ }
141
+
142
+ private async updateFilm() {
143
+ if (!this.canvasService) return;
144
+ const layer = this.canvasService.getLayer("overlay");
145
+ if (!layer) {
146
+ console.warn("[FilmTool] Overlay layer not found");
147
+ return;
148
+ }
149
+
150
+ const { url, opacity } = this;
151
+
152
+ if (!url) {
153
+ const img = this.canvasService.getObject("film-image", "overlay");
154
+ if (img) {
155
+ layer.remove(img);
156
+ this.canvasService.requestRenderAll();
157
+ }
158
+ return;
159
+ }
160
+
161
+ const width = this.canvasService.canvas.width || 800;
162
+ const height = this.canvasService.canvas.height || 600;
163
+
164
+ let img = this.canvasService.getObject("film-image", "overlay") as Image;
165
+ try {
166
+ if (img) {
167
+ if (img.getSrc() !== url) {
168
+ await img.setSrc(url);
169
+ }
170
+ img.set({ opacity });
171
+ } else {
172
+ img = await Image.fromURL(url, { crossOrigin: "anonymous" });
173
+ img.scaleToWidth(width);
174
+ if (img.getScaledHeight() < height) img.scaleToHeight(height);
175
+ img.set({
176
+ originX: "left",
177
+ originY: "top",
178
+ left: 0,
179
+ top: 0,
180
+ opacity,
181
+ selectable: false,
182
+ evented: false,
183
+ data: { id: "film-image" },
184
+ });
185
+ layer.add(img);
186
+ }
187
+ this.canvasService.requestRenderAll();
188
+ } catch (error) {
189
+ console.error("[FilmTool] Failed to load film image", url, error);
190
+ }
191
+ layer.dirty = true;
192
+ this.canvasService.requestRenderAll();
193
+ }
194
+ }