@cadit-app/script-params 0.5.2 → 0.5.3

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.
@@ -0,0 +1,207 @@
1
+ /**
2
+ * Geometry-related parameter types for CADit parametric scripts.
3
+ *
4
+ * This module defines the shape2d and shape3d parameter types and their
5
+ * associated value types, as well as utility functions for working with
6
+ * path geometry (bezier curves, point extraction, etc.).
7
+ */
8
+ // =============================================================================
9
+ // Geometry Utility Functions
10
+ // =============================================================================
11
+ /**
12
+ * Type guard to check if a path point is a bezier segment with handles.
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * for (const point of path.points) {
17
+ * if (isPathSegment(point)) {
18
+ * // point is PathSegment with handleIn/handleOut
19
+ * console.log('Bezier point:', point.point, point.handleIn, point.handleOut);
20
+ * } else {
21
+ * // point is Point3D (simple point)
22
+ * console.log('Simple point:', point.x, point.y);
23
+ * }
24
+ * }
25
+ * ```
26
+ */
27
+ export function isPathSegment(point) {
28
+ return point !== null && typeof point === 'object' && 'point' in point;
29
+ }
30
+ /**
31
+ * Get the x, y coordinates from a path point.
32
+ * Works for both simple Point3D and PathSegment.
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * const points2D = path.points.map(p => {
37
+ * const { x, y } = getPathPointXY(p);
38
+ * return [x, y];
39
+ * });
40
+ * ```
41
+ */
42
+ export function getPathPointXY(point) {
43
+ if (isPathSegment(point)) {
44
+ return { x: point.point.x, y: point.point.y };
45
+ }
46
+ return { x: point.x, y: point.y };
47
+ }
48
+ /**
49
+ * Evaluate a cubic bezier curve at parameter t.
50
+ * @internal
51
+ */
52
+ function cubicBezier(p0, p1, p2, p3, t) {
53
+ const oneMinusT = 1 - t;
54
+ return (oneMinusT * oneMinusT * oneMinusT * p0 +
55
+ 3 * oneMinusT * oneMinusT * t * p1 +
56
+ 3 * oneMinusT * t * t * p2 +
57
+ t * t * t * p3);
58
+ }
59
+ /**
60
+ * Convert a path with bezier segments to simple 2D points.
61
+ * This samples the bezier curves at regular intervals.
62
+ *
63
+ * @param points - Array of path points (can include bezier segments)
64
+ * @param samplesPerSegment - Number of samples per bezier segment (default: 8)
65
+ * @returns Array of [x, y] tuples suitable for CrossSection
66
+ *
67
+ * @example
68
+ * ```typescript
69
+ * const path = inputShape.shapeData.doodlePaths[0];
70
+ * const points2D = samplePathTo2D(path.points);
71
+ * const crossSection = Module.CrossSection(points2D);
72
+ * ```
73
+ */
74
+ export function samplePathTo2D(points, samplesPerSegment = 8) {
75
+ const result = [];
76
+ for (let i = 0; i < points.length; i++) {
77
+ const current = points[i];
78
+ const next = points[(i + 1) % points.length];
79
+ // Get current point position
80
+ const currentXY = getPathPointXY(current);
81
+ // Check if we have bezier handles
82
+ const currentSegment = isPathSegment(current) ? current : null;
83
+ const nextSegment = isPathSegment(next) ? next : null;
84
+ // If no handles, just add the point
85
+ if (!currentSegment?.handleOut && !nextSegment?.handleIn) {
86
+ result.push([currentXY.x, currentXY.y]);
87
+ continue;
88
+ }
89
+ // Sample the bezier curve
90
+ const nextXY = getPathPointXY(next);
91
+ // Control point 1: current point + handleOut (or just current point)
92
+ const cp1x = currentSegment?.handleOut
93
+ ? currentXY.x + currentSegment.handleOut.x
94
+ : currentXY.x;
95
+ const cp1y = currentSegment?.handleOut
96
+ ? currentXY.y + currentSegment.handleOut.y
97
+ : currentXY.y;
98
+ // Control point 2: next point + handleIn (or just next point)
99
+ const cp2x = nextSegment?.handleIn
100
+ ? nextXY.x + nextSegment.handleIn.x
101
+ : nextXY.x;
102
+ const cp2y = nextSegment?.handleIn
103
+ ? nextXY.y + nextSegment.handleIn.y
104
+ : nextXY.y;
105
+ // Sample cubic bezier curve
106
+ for (let t = 0; t < 1; t += 1 / samplesPerSegment) {
107
+ const x = cubicBezier(currentXY.x, cp1x, cp2x, nextXY.x, t);
108
+ const y = cubicBezier(currentXY.y, cp1y, cp2y, nextXY.y, t);
109
+ result.push([x, y]);
110
+ }
111
+ }
112
+ return result;
113
+ }
114
+ /**
115
+ * Type guard to check if a Shape3dValue has valid mesh data.
116
+ * Use this to narrow the type before accessing meshData properties.
117
+ *
118
+ * @param shape3d - The Shape3dValue to check (may be null/undefined)
119
+ * @returns True if the shape has valid mesh data with vertices and triangles
120
+ *
121
+ * @example
122
+ * ```typescript
123
+ * import { Manifold, Mesh } from '@cadit-app/manifold-3d/manifoldCAD';
124
+ * import { hasShape3dMesh, getShape3dMeshOptions } from '@cadit-app/script-params';
125
+ *
126
+ * if (hasShape3dMesh(params.inputMesh)) {
127
+ * const manifold = new Manifold(new Mesh(getShape3dMeshOptions(params.inputMesh)));
128
+ * // use manifold...
129
+ * }
130
+ * ```
131
+ */
132
+ export function hasShape3dMesh(shape3d) {
133
+ if (!shape3d?.meshData)
134
+ return false;
135
+ const { vertices, triangles } = shape3d.meshData;
136
+ // Need at least 1 triangle (3 vertices = 9 coords, 3 indices)
137
+ return !!(vertices && vertices.length >= 9 && triangles && triangles.length >= 3);
138
+ }
139
+ /**
140
+ * Get mesh options from a Shape3dValue for use with Manifold's Mesh constructor.
141
+ *
142
+ * IMPORTANT: Always call hasShape3dMesh() first to validate the shape,
143
+ * or use toManifold() for a simpler one-liner.
144
+ *
145
+ * @param shape3d - A Shape3dValue that has valid meshData (use hasShape3dMesh to check)
146
+ * @returns MeshOptions ready to pass to `new Mesh(options)`
147
+ *
148
+ * @example
149
+ * ```typescript
150
+ * import { Manifold, Mesh } from '@cadit-app/manifold-3d/manifoldCAD';
151
+ * import { hasShape3dMesh, getShape3dMeshOptions } from '@cadit-app/script-params';
152
+ *
153
+ * if (hasShape3dMesh(baseShape)) {
154
+ * const opts = getShape3dMeshOptions(baseShape);
155
+ * const manifold = new Manifold(new Mesh(opts));
156
+ * }
157
+ * ```
158
+ */
159
+ export function getShape3dMeshOptions(shape3d) {
160
+ const { vertices, triangles } = shape3d.meshData;
161
+ return {
162
+ numProp: 3,
163
+ vertProperties: new Float32Array(vertices),
164
+ triVerts: new Uint32Array(triangles),
165
+ };
166
+ }
167
+ /**
168
+ * Convert a Shape3dValue to a Manifold in a single expression.
169
+ *
170
+ * This is a convenience function that combines hasShape3dMesh check and
171
+ * Manifold construction. Pass your Mesh and Manifold constructors.
172
+ *
173
+ * Note: We can't import Manifold/Mesh directly in script-params because
174
+ * manifold-3d requires async WASM initialization. The worker pre-initializes
175
+ * it and exposes the classes, which you import in your script.
176
+ *
177
+ * @param shape3d - The Shape3dValue from a shape3d parameter (may be null)
178
+ * @param Mesh - The Mesh constructor from manifold-3d
179
+ * @param Manifold - The Manifold constructor from manifold-3d
180
+ * @returns A Manifold object, or null if the shape3d is invalid
181
+ *
182
+ * @example
183
+ * ```typescript
184
+ * import { Manifold, Mesh } from '@cadit-app/manifold-3d/manifoldCAD';
185
+ * import { toManifold } from '@cadit-app/script-params';
186
+ *
187
+ * const manifoldA = toManifold(params.baseShape, Mesh, Manifold);
188
+ * const manifoldB = toManifold(params.sweepShape, Mesh, Manifold);
189
+ *
190
+ * if (manifoldA && manifoldB) {
191
+ * return manifoldA.add(manifoldB);
192
+ * }
193
+ * ```
194
+ */
195
+ export function toManifold(shape3d, Mesh, Manifold) {
196
+ if (!hasShape3dMesh(shape3d))
197
+ return null;
198
+ try {
199
+ const mesh = new Mesh(getShape3dMeshOptions(shape3d));
200
+ return new Manifold(mesh);
201
+ }
202
+ catch (error) {
203
+ console.error('[toManifold] Error creating manifold:', error);
204
+ return null;
205
+ }
206
+ }
207
+ //# sourceMappingURL=geometry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"geometry.js","sourceRoot":"","sources":["../../src/params/geometry.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAyMH,gFAAgF;AAChF,6BAA6B;AAC7B,gFAAgF;AAEhF;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,aAAa,CAAC,KAAgB;IAC5C,OAAO,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,IAAI,KAAK,CAAC;AACzE,CAAC;AA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OAAO,IAAI,CAAC;IAE1C,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAAC,CAAC,CAAC;QACtD,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,uCAAuC,EAAE,KAAK,CAAC,CAAC;QAC9D,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Parameter types and schema for CADit parametric scripts.
3
+ *
4
+ * Re-exports all parameter-related types from the params submodule.
5
+ */
6
+ export type { ParamDefBase, NumberParamDef, FloatParamDef, IntParamDef, SliderParamDef, TextParamDef, FontParamDef, BooleanParamDef, SwitchParamDef, CheckboxParamDef, ChoiceOption, ChoiceParamDef, RadioParamDef, ImageFileValue, ImageParamDef, ButtonGridOption, ButtonGridParamDef, PresetOption, PresetParamDef, } from './types';
7
+ export type { Point2D, Point3D, PathSegment, PathPoint, DoodlePath, SerializedShapeData, Shape2dValue, Shape2dParamDef, Triangle, SerializedMeshData, Shape3dValue, Shape3dParamDef, MeshOptions, } from './geometry';
8
+ export { isPathSegment, getPathPointXY, samplePathTo2D, hasShape3dMesh, getShape3dMeshOptions, toManifold, } from './geometry';
9
+ export type { EmbeddedParamDef, EmbeddedParamValue, ParamDef, ParamSchema, ParamValue, Params, } from './schema';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/params/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,YAAY,EACV,YAAY,EAEZ,cAAc,EACd,aAAa,EACb,WAAW,EACX,cAAc,EAEd,YAAY,EACZ,YAAY,EAEZ,eAAe,EACf,cAAc,EACd,gBAAgB,EAEhB,YAAY,EACZ,cAAc,EACd,aAAa,EAEb,cAAc,EACd,aAAa,EAEb,gBAAgB,EAChB,kBAAkB,EAElB,YAAY,EACZ,cAAc,GACf,MAAM,SAAS,CAAC;AAGjB,YAAY,EACV,OAAO,EACP,OAAO,EACP,WAAW,EACX,SAAS,EACT,UAAU,EACV,mBAAmB,EACnB,YAAY,EACZ,eAAe,EACf,QAAQ,EACR,kBAAkB,EAClB,YAAY,EACZ,eAAe,EACf,WAAW,GACZ,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,aAAa,EACb,cAAc,EACd,cAAc,EACd,cAAc,EACd,qBAAqB,EACrB,UAAU,GACX,MAAM,YAAY,CAAC;AAGpB,YAAY,EACV,gBAAgB,EAChB,kBAAkB,EAClB,QAAQ,EACR,WAAW,EACX,UAAU,EACV,MAAM,GACP,MAAM,UAAU,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Parameter types and schema for CADit parametric scripts.
3
+ *
4
+ * Re-exports all parameter-related types from the params submodule.
5
+ */
6
+ // Geometry utility functions
7
+ export { isPathSegment, getPathPointXY, samplePathTo2D, hasShape3dMesh, getShape3dMeshOptions, toManifold, } from './geometry';
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/params/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAiDH,6BAA6B;AAC7B,OAAO,EACL,aAAa,EACb,cAAc,EACd,cAAc,EACd,cAAc,EACd,qBAAqB,EACrB,UAAU,GACX,MAAM,YAAY,CAAC"}
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Parameter schema and embedded parameter types.
3
+ *
4
+ * This module defines the EmbeddedParamDef for nesting parameters,
5
+ * the ParamDef union type, ParamSchema, and type inference utilities.
6
+ */
7
+ import type { NumberParamDef, FloatParamDef, IntParamDef, SliderParamDef, TextParamDef, FontParamDef, BooleanParamDef, SwitchParamDef, CheckboxParamDef, ChoiceParamDef, RadioParamDef, ImageParamDef, ImageFileValue, ButtonGridParamDef, PresetParamDef, ParamDefBase } from './types';
8
+ import type { Shape2dParamDef, Shape2dValue, Shape3dParamDef, Shape3dValue } from './geometry';
9
+ /**
10
+ * Embedded parameter - nests another script's parameters.
11
+ * The embedded params can be enabled/disabled and expanded/collapsed.
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * import qrCodeScript from './qr-code';
16
+ *
17
+ * export default defineParams({
18
+ * size: { type: 'number', default: 10 },
19
+ * qrCode: {
20
+ * type: 'embedded',
21
+ * label: 'QR Code (Optional)',
22
+ * params: qrCodeScript.params,
23
+ * enabled: false,
24
+ * showSettings: false
25
+ * }
26
+ * }, (p) => {
27
+ * if (p.qrCode.enabled) {
28
+ * const qrMesh = qrCodeScript(p.qrCode.params);
29
+ * // combine meshes...
30
+ * }
31
+ * });
32
+ * ```
33
+ */
34
+ export interface EmbeddedParamDef extends ParamDefBase {
35
+ type: 'embedded';
36
+ /** The nested parameter schema. */
37
+ params: ParamSchema;
38
+ /** Whether the embedded feature is initially enabled. */
39
+ enabled?: boolean;
40
+ /** Whether the settings panel is initially expanded. */
41
+ showSettings?: boolean;
42
+ /**
43
+ * NPM package name for resolving relative asset paths (like buttonGrid images).
44
+ * This is automatically set when using the `embedParams()` helper.
45
+ *
46
+ * @example '@cadit-app/qr-code'
47
+ */
48
+ npmPackage?: string;
49
+ }
50
+ /**
51
+ * Value type for embedded parameters.
52
+ * Contains the enabled state, showSettings state, and the resolved param values.
53
+ */
54
+ export interface EmbeddedParamValue<S extends ParamSchema = ParamSchema> {
55
+ enabled: boolean;
56
+ showSettings: boolean;
57
+ params: Params<S>;
58
+ }
59
+ /**
60
+ * Union of all parameter definition types.
61
+ */
62
+ export type ParamDef = NumberParamDef | FloatParamDef | IntParamDef | SliderParamDef | TextParamDef | FontParamDef | BooleanParamDef | SwitchParamDef | CheckboxParamDef | ChoiceParamDef | RadioParamDef | ImageParamDef | ButtonGridParamDef | PresetParamDef | Shape2dParamDef | Shape3dParamDef | EmbeddedParamDef;
63
+ /**
64
+ * A schema defining all parameters for a script.
65
+ * Keys are parameter names, values are parameter definitions.
66
+ */
67
+ export type ParamSchema = Record<string, ParamDef>;
68
+ /**
69
+ * Infer the runtime value type from a parameter definition.
70
+ *
71
+ * @example
72
+ * ```typescript
73
+ * type T = ParamValue<{ type: 'number'; default: 10 }>; // number
74
+ * type S = ParamValue<{ type: 'text'; default: 'hi' }>; // string
75
+ * ```
76
+ */
77
+ export type ParamValue<P extends ParamDef> = P['type'] extends 'number' | 'float' | 'int' | 'slider' ? number : P['type'] extends 'text' | 'choice' | 'radio' | 'buttonGrid' | 'font' | 'preset' ? string : P['type'] extends 'boolean' | 'switch' | 'checkbox' ? boolean : P['type'] extends 'image' ? ImageFileValue | null : P['type'] extends 'shape2d' ? Shape2dValue | null : P['type'] extends 'shape3d' ? Shape3dValue | null : P['type'] extends 'embedded' ? P extends EmbeddedParamDef ? EmbeddedParamValue<P['params']> : EmbeddedParamValue : never;
78
+ /**
79
+ * Infer the full params object type from a schema.
80
+ *
81
+ * @example
82
+ * ```typescript
83
+ * const schema = {
84
+ * size: { type: 'number', default: 10 },
85
+ * label: { type: 'text', default: 'Hi' },
86
+ * } as const;
87
+ *
88
+ * type P = Params<typeof schema>;
89
+ * // { size: number; label: string }
90
+ * ```
91
+ */
92
+ export type Params<S extends ParamSchema> = {
93
+ [K in keyof S]: ParamValue<S[K]>;
94
+ };
95
+ //# sourceMappingURL=schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/params/schema.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EACb,WAAW,EACX,cAAc,EACd,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,cAAc,EACd,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,aAAa,EACb,cAAc,EACd,kBAAkB,EAClB,cAAc,EACd,YAAY,EACb,MAAM,SAAS,CAAC;AAEjB,OAAO,KAAK,EACV,eAAe,EACf,YAAY,EACZ,e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AO,GAET,CAAC,CAAC,MAAM,CAAC,SAAS,OAAO,GACvB,cAAc,GAAG,IAAI,GAEvB,CAAC,CAAC,MAAM,CAAC,SAAS,SAAS,GACzB,YAAY,GAAG,IAAI,GACrB,CAAC,CAAC,MAAM,CAAC,SAAS,SAAS,GACzB,YAAY,GAAG,IAAI,GAErB,CAAC,CAAC,MAAM,CAAC,SAAS,UAAU,GAC1B,CAAC,SAAS,gBAAgB,GACxB,kBAAkB,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,GAC/B,kBAAkB,GACtB,KAAK,CAAC;AAEV;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,SAAS,WAAW,IAAI;KACzC,CAAC,IAAI,MAAM,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CACjC,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Parameter schema and embedded parameter types.
3
+ *
4
+ * This module defines the EmbeddedParamDef for nesting parameters,
5
+ * the ParamDef union type, ParamSchema, and type inference utilities.
6
+ */
7
+ export {};
8
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/params/schema.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
@@ -0,0 +1,239 @@
1
+ /**
2
+ * Parameter definition types for CADit parametric scripts.
3
+ *
4
+ * This module defines all the parameter types that can be used in script definitions.
5
+ * Each parameter type maps to a corresponding UI input component in Core.
6
+ */
7
+ /**
8
+ * Base properties shared by all parameter types.
9
+ */
10
+ export interface ParamDefBase {
11
+ /** Human-readable label for the parameter. If omitted, the key is used. */
12
+ label?: string;
13
+ /** Description shown as tooltip or help text. */
14
+ description?: string;
15
+ }
16
+ /**
17
+ * Number parameter - floating point values.
18
+ */
19
+ export interface NumberParamDef extends ParamDefBase {
20
+ type: 'number';
21
+ default: number;
22
+ min?: number;
23
+ max?: number;
24
+ step?: number;
25
+ }
26
+ /**
27
+ * Float parameter - alias for number (floating point values).
28
+ * This is provided for compatibility with Core's float type.
29
+ */
30
+ export interface FloatParamDef extends ParamDefBase {
31
+ type: 'float';
32
+ default: number;
33
+ min?: number;
34
+ max?: number;
35
+ step?: number;
36
+ }
37
+ /**
38
+ * Integer parameter - whole number values.
39
+ */
40
+ export interface IntParamDef extends ParamDefBase {
41
+ type: 'int';
42
+ default: number;
43
+ min?: number;
44
+ max?: number;
45
+ step?: number;
46
+ }
47
+ /**
48
+ * Slider parameter - number with visual slider control.
49
+ */
50
+ export interface SliderParamDef extends ParamDefBase {
51
+ type: 'slider';
52
+ default: number;
53
+ min: number;
54
+ max: number;
55
+ step?: number;
56
+ }
57
+ /**
58
+ * Text parameter - string values.
59
+ */
60
+ export interface TextParamDef extends ParamDefBase {
61
+ type: 'text';
62
+ default: string;
63
+ maxLength?: number;
64
+ placeholder?: string;
65
+ }
66
+ /**
67
+ * Font parameter - font selector.
68
+ * Allows selecting from available fonts in the CADit system.
69
+ */
70
+ export interface FontParamDef extends ParamDefBase {
71
+ type: 'font';
72
+ default: string;
73
+ }
74
+ /**
75
+ * Boolean parameter - true/false toggle.
76
+ */
77
+ export interface BooleanParamDef extends ParamDefBase {
78
+ type: 'boolean';
79
+ default: boolean;
80
+ }
81
+ /**
82
+ * Switch parameter - true/false toggle (alias for boolean).
83
+ * Renders as a toggle switch in the UI.
84
+ */
85
+ export interface SwitchParamDef extends ParamDefBase {
86
+ type: 'switch';
87
+ default: boolean;
88
+ }
89
+ /**
90
+ * Checkbox parameter - true/false toggle (alias for boolean).
91
+ * Renders as a checkbox in the UI.
92
+ */
93
+ export interface CheckboxParamDef extends ParamDefBase {
94
+ type: 'checkbox';
95
+ default: boolean;
96
+ }
97
+ /**
98
+ * Option for choice/radio parameter.
99
+ * Can be a simple string or an object with value and optional label.
100
+ */
101
+ export type ChoiceOption = string | {
102
+ value: string;
103
+ label?: string;
104
+ };
105
+ /**
106
+ * Choice parameter - select from predefined options (dropdown).
107
+ * Options can be simple strings or objects with value/label pairs.
108
+ *
109
+ * @example
110
+ * ```typescript
111
+ * // Simple options
112
+ * color: { type: 'choice', default: 'red', options: ['red', 'green', 'blue'] }
113
+ *
114
+ * // Options with labels
115
+ * errorLevel: {
116
+ * type: 'choice',
117
+ * default: 'M',
118
+ * options: [
119
+ * { value: 'L', label: 'L - ~7% recovery' },
120
+ * { value: 'M', label: 'M - ~15% recovery' },
121
+ * { value: 'Q', label: 'Q - ~25% recovery' },
122
+ * { value: 'H', label: 'H - ~30% recovery' },
123
+ * ]
124
+ * }
125
+ * ```
126
+ */
127
+ export interface ChoiceParamDef extends ParamDefBase {
128
+ type: 'choice';
129
+ default: string;
130
+ options: readonly ChoiceOption[];
131
+ }
132
+ /**
133
+ * Radio parameter - select from predefined options (radio buttons).
134
+ * Similar to choice but renders as radio buttons instead of a dropdown.
135
+ * Options can be simple strings or objects with value/label pairs.
136
+ *
137
+ * @example
138
+ * ```typescript
139
+ * alignment: {
140
+ * type: 'radio',
141
+ * default: 'center',
142
+ * options: ['left', 'center', 'right']
143
+ * }
144
+ * ```
145
+ */
146
+ export interface RadioParamDef extends ParamDefBase {
147
+ type: 'radio';
148
+ default: string;
149
+ options: readonly ChoiceOption[];
150
+ }
151
+ /**
152
+ * Value type for image parameters.
153
+ * Represents an image file that can be loaded via URL or embedded as a data URL.
154
+ */
155
+ export interface ImageFileValue {
156
+ /** Remote URL to fetch the image from (e.g., HTTP URL or relative path). */
157
+ imageUrl?: string;
158
+ /** Base64-encoded data URL of the image content. */
159
+ dataUrl?: string;
160
+ /** MIME type of the image (e.g., 'image/svg+xml', 'image/png'). */
161
+ fileType?: string;
162
+ /** Original filename of the image. */
163
+ fileName?: string;
164
+ }
165
+ /**
166
+ * Image parameter - for image file uploads with URL or data URL.
167
+ */
168
+ export interface ImageParamDef extends ParamDefBase {
169
+ type: 'image';
170
+ default: ImageFileValue | null;
171
+ }
172
+ /**
173
+ * Option for buttonGrid parameter.
174
+ * Each option can have an image, caption, or both.
175
+ */
176
+ export interface ButtonGridOption {
177
+ /** The value returned when this option is selected. */
178
+ value: string;
179
+ /** Optional image URL (absolute or relative to script location). */
180
+ image?: string;
181
+ /** Optional caption/label for the button. Used as alt text if image is present. */
182
+ caption?: string;
183
+ }
184
+ /**
185
+ * ButtonGrid parameter - visual grid of buttons with images/captions.
186
+ * Useful for pattern selection, style options, etc.
187
+ *
188
+ * @example
189
+ * ```typescript
190
+ * pattern: {
191
+ * type: 'buttonGrid',
192
+ * default: 'style1',
193
+ * options: [
194
+ * { value: 'style1', image: './images/style1.svg', caption: 'Style 1' },
195
+ * { value: 'style2', image: './images/style2.svg', caption: 'Style 2' },
196
+ * ]
197
+ * }
198
+ * ```
199
+ */
200
+ export interface ButtonGridParamDef extends ParamDefBase {
201
+ type: 'buttonGrid';
202
+ default: string;
203
+ options: readonly ButtonGridOption[];
204
+ }
205
+ /**
206
+ * A preset option that contains predefined parameter values.
207
+ * @template T - The type of the preset values object.
208
+ */
209
+ export interface PresetOption<T = Record<string, unknown>> {
210
+ /** The value/identifier for this preset. */
211
+ value: string;
212
+ /** Human-readable label for the preset. */
213
+ label: string;
214
+ /** Partial parameter values to apply when this preset is selected. */
215
+ presetValues: Partial<T>;
216
+ }
217
+ /**
218
+ * Preset parameter - allows selecting from predefined parameter configurations.
219
+ * When a preset is selected, it overrides multiple other parameter values.
220
+ *
221
+ * @example
222
+ * ```typescript
223
+ * preset: {
224
+ * type: 'preset',
225
+ * default: 'small',
226
+ * presets: [
227
+ * { value: 'small', label: 'Small', presetValues: { width: 10, height: 10 } },
228
+ * { value: 'medium', label: 'Medium', presetValues: { width: 20, height: 20 } },
229
+ * { value: 'large', label: 'Large', presetValues: { width: 40, height: 40 } },
230
+ * ]
231
+ * }
232
+ * ```
233
+ */
234
+ export interface PresetParamDef<T = Record<string, unknown>> extends ParamDefBase {
235
+ type: 'preset';
236
+ default: string;
237
+ presets: readonly PresetOption<T>[];
238
+ }
239
+ //# sourceMappingURL=types.d.ts.map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C,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,aAAc,SAAQ,YAAY;IACjD,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,EAAE,cAAc,GAAG,IAAI,CAAC;CAChC;AAMD;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,uDAAuD;IACvD,KAAK,EAAE,MAAM,CAAC;IACd,oEAAoE;IACpE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,mFAAmF;IACnF,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,WAAW,kBAAmB,SAAQ,YAAY;IACtD,IAAI,EAAE,YAAY,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,SAAS,gBAAgB,EAAE,CAAC;CACtC;AAMD;;;GAGG;AACH,MAAM,WAAW,YAAY,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACvD,4CAA4C;IAC5C,KAAK,EAAE,MAAM,CAAC;IACd,2CAA2C;IAC3C,KAAK,EAAE,MAAM,CAAC;IACd,sEAAsE;IACtE,YAAY,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;CAC1B;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,WAAW,cAAc,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAE,SAAQ,YAAY;IAC/E,IAAI,EAAE,QAAQ,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,SAAS,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC;CACrC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Parameter definition types for CADit parametric scripts.
3
+ *
4
+ * This module defines all the parameter types that can be used in script definitions.
5
+ * Each parameter type maps to a corresponding UI input component in Core.
6
+ */
7
+ export {};
8
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/params/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}