@cadit-app/script-params 0.5.2 → 0.5.4
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/dist/exporters.d.ts +107 -0
- package/dist/exporters.d.ts.map +1 -0
- package/dist/exporters.js +29 -0
- package/dist/exporters.js.map +1 -0
- package/dist/index.d.ts +11 -555
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -326
- package/dist/index.js.map +1 -1
- package/dist/params/geometry.d.ts +313 -0
- package/dist/params/geometry.d.ts.map +1 -0
- package/dist/params/geometry.js +207 -0
- package/dist/params/geometry.js.map +1 -0
- package/dist/params/index.d.ts +10 -0
- package/dist/params/index.d.ts.map +1 -0
- package/dist/params/index.js +8 -0
- package/dist/params/index.js.map +1 -0
- package/dist/params/schema.d.ts +95 -0
- package/dist/params/schema.d.ts.map +1 -0
- package/dist/params/schema.js +8 -0
- package/dist/params/schema.js.map +1 -0
- package/dist/params/types.d.ts +239 -0
- package/dist/params/types.d.ts.map +1 -0
- package/dist/params/types.js +8 -0
- package/dist/params/types.js.map +1 -0
- package/dist/sceneOutput.d.ts +424 -0
- package/dist/sceneOutput.d.ts.map +1 -0
- package/dist/sceneOutput.js +92 -0
- package/dist/sceneOutput.js.map +1 -0
- package/dist/script.d.ts +132 -0
- package/dist/script.d.ts.map +1 -0
- package/dist/script.js +117 -0
- package/dist/script.js.map +1 -0
- package/dist/utils.d.ts +115 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +224 -0
- package/dist/utils.js.map +1 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -19,559 +19,15 @@
|
|
|
19
19
|
* });
|
|
20
20
|
* ```
|
|
21
21
|
*/
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
export
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Exporter definition.
|
|
36
|
-
* Provides a function to export the current state to a downloadable format.
|
|
37
|
-
*
|
|
38
|
-
* @template P - The params type. Use `InferParams<typeof myScript>` to derive
|
|
39
|
-
* from a script, or define inline when used with defineParams.
|
|
40
|
-
*
|
|
41
|
-
* @example Inline with defineParams (type is inferred automatically)
|
|
42
|
-
* ```typescript
|
|
43
|
-
* export default defineParams({
|
|
44
|
-
* params: { size: { type: 'number', default: 10 } },
|
|
45
|
-
* exporters: {
|
|
46
|
-
* svg: {
|
|
47
|
-
* name: 'SVG',
|
|
48
|
-
* export: (p) => ({ ... }), // p.size is typed as number
|
|
49
|
-
* },
|
|
50
|
-
* },
|
|
51
|
-
* });
|
|
52
|
-
* ```
|
|
53
|
-
*
|
|
54
|
-
* @example Separate file using InferParams
|
|
55
|
-
* ```typescript
|
|
56
|
-
* import type { Exporter, InferParams } from '@cadit-app/script-params';
|
|
57
|
-
* import type script from './main';
|
|
58
|
-
*
|
|
59
|
-
* type Params = InferParams<typeof script>;
|
|
60
|
-
*
|
|
61
|
-
* export const pngExporter: Exporter<Params> = {
|
|
62
|
-
* name: 'PNG',
|
|
63
|
-
* export: (params) => { ... }, // params is fully typed
|
|
64
|
-
* };
|
|
65
|
-
* ```
|
|
66
|
-
*/
|
|
67
|
-
export interface Exporter<P = unknown> {
|
|
68
|
-
/** Short name for the exporter (e.g., 'SVG', 'PNG', '3MF'). */
|
|
69
|
-
name: string;
|
|
70
|
-
/** Label shown on the download button (e.g., 'Download SVG'). */
|
|
71
|
-
label?: string;
|
|
72
|
-
/** Description or tooltip for the exporter. */
|
|
73
|
-
description?: string;
|
|
74
|
-
/**
|
|
75
|
-
* Optional async initialization function.
|
|
76
|
-
* Called once before the first export.
|
|
77
|
-
* Use for WASM initialization or other one-time setup.
|
|
78
|
-
*
|
|
79
|
-
* @example
|
|
80
|
-
* ```typescript
|
|
81
|
-
* init: async () => {
|
|
82
|
-
* const wasm = await __cadit_loadWasm('@resvg/resvg-wasm', 'index_bg.wasm');
|
|
83
|
-
* await resvg.initWasm(wasm);
|
|
84
|
-
* }
|
|
85
|
-
* ```
|
|
86
|
-
*/
|
|
87
|
-
init?: () => Promise<void>;
|
|
88
|
-
/** Export function that receives the current parameter values. */
|
|
89
|
-
export: (params: P) => Promise<ExportResult> | ExportResult;
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Serializable exporter metadata for passing to UI.
|
|
93
|
-
* Contains only the display information, not the actual export function.
|
|
94
|
-
*/
|
|
95
|
-
export interface ExporterMetadata {
|
|
96
|
-
/** The key used to identify this exporter in the exporters record. */
|
|
97
|
-
key: string;
|
|
98
|
-
/** Short name for the exporter (e.g., 'SVG', 'PNG', '3MF'). */
|
|
99
|
-
name: string;
|
|
100
|
-
/** Label shown on the download button (e.g., 'Download SVG'). */
|
|
101
|
-
label?: string;
|
|
102
|
-
/** Description or tooltip for the exporter. */
|
|
103
|
-
description?: string;
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Extract metadata from an Exporter (strips non-serializable functions).
|
|
107
|
-
* @param key - The key in the exporters record
|
|
108
|
-
* @param exporter - The exporter definition
|
|
109
|
-
*/
|
|
110
|
-
export declare function getExporterMetadata<P>(key: string, exporter: Exporter<P>): ExporterMetadata;
|
|
111
|
-
/**
|
|
112
|
-
* Extract metadata array from Exporters record.
|
|
113
|
-
* Preserves the key for each exporter so it can be looked up later.
|
|
114
|
-
*/
|
|
115
|
-
export declare function getExportersMetadata<P>(exporters: Exporters<P>): ExporterMetadata[];
|
|
116
|
-
/**
|
|
117
|
-
* Map of exporters keyed by identifier.
|
|
118
|
-
* The key is used to identify the exporter, the value contains the definition.
|
|
119
|
-
*
|
|
120
|
-
* @template P - The params type for all exporters in the map.
|
|
121
|
-
*/
|
|
122
|
-
export type Exporters<P = unknown> = Record<string, Exporter<P>>;
|
|
123
|
-
/**
|
|
124
|
-
* Base properties shared by all parameter types.
|
|
125
|
-
*/
|
|
126
|
-
interface ParamDefBase {
|
|
127
|
-
/** Human-readable label for the parameter. If omitted, the key is used. */
|
|
128
|
-
label?: string;
|
|
129
|
-
/** Description shown as tooltip or help text. */
|
|
130
|
-
description?: string;
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Number parameter - floating point values.
|
|
134
|
-
*/
|
|
135
|
-
export interface NumberParamDef extends ParamDefBase {
|
|
136
|
-
type: 'number';
|
|
137
|
-
default: number;
|
|
138
|
-
min?: number;
|
|
139
|
-
max?: number;
|
|
140
|
-
step?: number;
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Integer parameter - whole number values.
|
|
144
|
-
*/
|
|
145
|
-
export interface IntParamDef extends ParamDefBase {
|
|
146
|
-
type: 'int';
|
|
147
|
-
default: number;
|
|
148
|
-
min?: number;
|
|
149
|
-
max?: number;
|
|
150
|
-
step?: number;
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* Text parameter - string values.
|
|
154
|
-
*/
|
|
155
|
-
export interface TextParamDef extends ParamDefBase {
|
|
156
|
-
type: 'text';
|
|
157
|
-
default: string;
|
|
158
|
-
maxLength?: number;
|
|
159
|
-
placeholder?: string;
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* Boolean parameter - true/false toggle.
|
|
163
|
-
*/
|
|
164
|
-
export interface BooleanParamDef extends ParamDefBase {
|
|
165
|
-
type: 'boolean';
|
|
166
|
-
default: boolean;
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Option for choice parameter.
|
|
170
|
-
* Can be a simple string or an object with value and optional label.
|
|
171
|
-
*/
|
|
172
|
-
export type ChoiceOption = string | {
|
|
173
|
-
value: string;
|
|
174
|
-
label?: string;
|
|
175
|
-
};
|
|
176
|
-
/**
|
|
177
|
-
* Choice parameter - select from predefined options.
|
|
178
|
-
* Options can be simple strings or objects with value/label pairs.
|
|
179
|
-
*
|
|
180
|
-
* @example
|
|
181
|
-
* ```typescript
|
|
182
|
-
* // Simple options
|
|
183
|
-
* color: { type: 'choice', default: 'red', options: ['red', 'green', 'blue'] }
|
|
184
|
-
*
|
|
185
|
-
* // Options with labels
|
|
186
|
-
* errorLevel: {
|
|
187
|
-
* type: 'choice',
|
|
188
|
-
* default: 'M',
|
|
189
|
-
* options: [
|
|
190
|
-
* { value: 'L', label: 'L - ~7% recovery' },
|
|
191
|
-
* { value: 'M', label: 'M - ~15% recovery' },
|
|
192
|
-
* { value: 'Q', label: 'Q - ~25% recovery' },
|
|
193
|
-
* { value: 'H', label: 'H - ~30% recovery' },
|
|
194
|
-
* ]
|
|
195
|
-
* }
|
|
196
|
-
* ```
|
|
197
|
-
*/
|
|
198
|
-
export interface ChoiceParamDef extends ParamDefBase {
|
|
199
|
-
type: 'choice';
|
|
200
|
-
default: string;
|
|
201
|
-
options: readonly ChoiceOption[];
|
|
202
|
-
}
|
|
203
|
-
/**
|
|
204
|
-
* Slider parameter - number with visual slider control.
|
|
205
|
-
*/
|
|
206
|
-
export interface SliderParamDef extends ParamDefBase {
|
|
207
|
-
type: 'slider';
|
|
208
|
-
default: number;
|
|
209
|
-
min: number;
|
|
210
|
-
max: number;
|
|
211
|
-
step?: number;
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* Value type for image parameters.
|
|
215
|
-
* Represents an image file that can be loaded via URL or embedded as a data URL.
|
|
216
|
-
*/
|
|
217
|
-
export interface ImageFileValue {
|
|
218
|
-
/** Remote URL to fetch the image from (e.g., HTTP URL or relative path). */
|
|
219
|
-
imageUrl?: string;
|
|
220
|
-
/** Base64-encoded data URL of the image content. */
|
|
221
|
-
dataUrl?: string;
|
|
222
|
-
/** MIME type of the image (e.g., 'image/svg+xml', 'image/png'). */
|
|
223
|
-
fileType?: string;
|
|
224
|
-
/** Original filename of the image. */
|
|
225
|
-
fileName?: string;
|
|
226
|
-
}
|
|
227
|
-
/**
|
|
228
|
-
* Image parameter - for image file uploads with URL or data URL.
|
|
229
|
-
*/
|
|
230
|
-
export interface ImageParamDef extends ParamDefBase {
|
|
231
|
-
type: 'image';
|
|
232
|
-
default: ImageFileValue | null;
|
|
233
|
-
}
|
|
234
|
-
/**
|
|
235
|
-
* Option for buttonGrid parameter.
|
|
236
|
-
* Each option can have an image, caption, or both.
|
|
237
|
-
*/
|
|
238
|
-
export interface ButtonGridOption {
|
|
239
|
-
/** The value returned when this option is selected. */
|
|
240
|
-
value: string;
|
|
241
|
-
/** Optional image URL (absolute or relative to script location). */
|
|
242
|
-
image?: string;
|
|
243
|
-
/** Optional caption/label for the button. Used as alt text if image is present. */
|
|
244
|
-
caption?: string;
|
|
245
|
-
}
|
|
246
|
-
/**
|
|
247
|
-
* ButtonGrid parameter - visual grid of buttons with images/captions.
|
|
248
|
-
* Useful for pattern selection, style options, etc.
|
|
249
|
-
*
|
|
250
|
-
* @example
|
|
251
|
-
* ```typescript
|
|
252
|
-
* pattern: {
|
|
253
|
-
* type: 'buttonGrid',
|
|
254
|
-
* default: 'style1',
|
|
255
|
-
* options: [
|
|
256
|
-
* { value: 'style1', image: './images/style1.svg', caption: 'Style 1' },
|
|
257
|
-
* { value: 'style2', image: './images/style2.svg', caption: 'Style 2' },
|
|
258
|
-
* ]
|
|
259
|
-
* }
|
|
260
|
-
* ```
|
|
261
|
-
*/
|
|
262
|
-
export interface ButtonGridParamDef extends ParamDefBase {
|
|
263
|
-
type: 'buttonGrid';
|
|
264
|
-
default: string;
|
|
265
|
-
options: readonly ButtonGridOption[];
|
|
266
|
-
}
|
|
267
|
-
/**
|
|
268
|
-
* Embedded parameter - nests another script's parameters.
|
|
269
|
-
* The embedded params can be enabled/disabled and expanded/collapsed.
|
|
270
|
-
*
|
|
271
|
-
* @example
|
|
272
|
-
* ```typescript
|
|
273
|
-
* import qrCodeScript from './qr-code';
|
|
274
|
-
*
|
|
275
|
-
* export default defineParams({
|
|
276
|
-
* size: { type: 'number', default: 10 },
|
|
277
|
-
* qrCode: {
|
|
278
|
-
* type: 'embedded',
|
|
279
|
-
* label: 'QR Code (Optional)',
|
|
280
|
-
* params: qrCodeScript.params,
|
|
281
|
-
* enabled: false,
|
|
282
|
-
* showSettings: false
|
|
283
|
-
* }
|
|
284
|
-
* }, (p) => {
|
|
285
|
-
* if (p.qrCode.enabled) {
|
|
286
|
-
* const qrMesh = qrCodeScript(p.qrCode.params);
|
|
287
|
-
* // combine meshes...
|
|
288
|
-
* }
|
|
289
|
-
* });
|
|
290
|
-
* ```
|
|
291
|
-
*/
|
|
292
|
-
export interface EmbeddedParamDef extends ParamDefBase {
|
|
293
|
-
type: 'embedded';
|
|
294
|
-
/** The nested parameter schema. */
|
|
295
|
-
params: ParamSchema;
|
|
296
|
-
/** Whether the embedded feature is initially enabled. */
|
|
297
|
-
enabled?: boolean;
|
|
298
|
-
/** Whether the settings panel is initially expanded. */
|
|
299
|
-
showSettings?: boolean;
|
|
300
|
-
/**
|
|
301
|
-
* NPM package name for resolving relative asset paths (like buttonGrid images).
|
|
302
|
-
* This is automatically set when using the `embedParams()` helper.
|
|
303
|
-
*
|
|
304
|
-
* @example '@cadit-app/qr-code'
|
|
305
|
-
*/
|
|
306
|
-
npmPackage?: string;
|
|
307
|
-
}
|
|
308
|
-
/**
|
|
309
|
-
* Value type for embedded parameters.
|
|
310
|
-
* Contains the enabled state, showSettings state, and the resolved param values.
|
|
311
|
-
*/
|
|
312
|
-
export interface EmbeddedParamValue<S extends ParamSchema = ParamSchema> {
|
|
313
|
-
enabled: boolean;
|
|
314
|
-
showSettings: boolean;
|
|
315
|
-
params: Params<S>;
|
|
316
|
-
}
|
|
317
|
-
/**
|
|
318
|
-
* Union of all parameter definition types.
|
|
319
|
-
*/
|
|
320
|
-
export type ParamDef = NumberParamDef | IntParamDef | TextParamDef | BooleanParamDef | ChoiceParamDef | SliderParamDef | ImageParamDef | ButtonGridParamDef | EmbeddedParamDef;
|
|
321
|
-
/**
|
|
322
|
-
* A schema defining all parameters for a script.
|
|
323
|
-
* Keys are parameter names, values are parameter definitions.
|
|
324
|
-
*/
|
|
325
|
-
export type ParamSchema = Record<string, ParamDef>;
|
|
326
|
-
/**
|
|
327
|
-
* Infer the runtime value type from a parameter definition.
|
|
328
|
-
*
|
|
329
|
-
* @example
|
|
330
|
-
* ```typescript
|
|
331
|
-
* type T = ParamValue<{ type: 'number'; default: 10 }>; // number
|
|
332
|
-
* type S = ParamValue<{ type: 'text'; default: 'hi' }>; // string
|
|
333
|
-
* ```
|
|
334
|
-
*/
|
|
335
|
-
export type ParamValue<P extends ParamDef> = P['type'] extends 'number' | 'int' | 'slider' ? number : P['type'] extends 'text' | 'choice' | 'buttonGrid' ? string : P['type'] extends 'boolean' ? boolean : P['type'] extends 'image' ? ImageFileValue | null : P['type'] extends 'embedded' ? P extends EmbeddedParamDef ? EmbeddedParamValue<P['params']> : EmbeddedParamValue : never;
|
|
336
|
-
/**
|
|
337
|
-
* Infer the full params object type from a schema.
|
|
338
|
-
*
|
|
339
|
-
* @example
|
|
340
|
-
* ```typescript
|
|
341
|
-
* const schema = {
|
|
342
|
-
* size: { type: 'number', default: 10 },
|
|
343
|
-
* label: { type: 'text', default: 'Hi' },
|
|
344
|
-
* } as const;
|
|
345
|
-
*
|
|
346
|
-
* type P = Params<typeof schema>;
|
|
347
|
-
* // { size: number; label: string }
|
|
348
|
-
* ```
|
|
349
|
-
*/
|
|
350
|
-
export type Params<S extends ParamSchema> = {
|
|
351
|
-
[K in keyof S]: ParamValue<S[K]>;
|
|
352
|
-
};
|
|
353
|
-
/**
|
|
354
|
-
* Infer the params type from a ScriptModule.
|
|
355
|
-
* Use this to get the typed params for use in exporters defined in separate files.
|
|
356
|
-
*
|
|
357
|
-
* @example
|
|
358
|
-
* ```typescript
|
|
359
|
-
* // In main.ts
|
|
360
|
-
* const script = defineParams({
|
|
361
|
-
* params: {
|
|
362
|
-
* size: { type: 'number', default: 10 },
|
|
363
|
-
* label: { type: 'text', default: 'Hello' },
|
|
364
|
-
* },
|
|
365
|
-
* main: (p) => { ... },
|
|
366
|
-
* });
|
|
367
|
-
* export default script;
|
|
368
|
-
*
|
|
369
|
-
* // In pngExport.ts
|
|
370
|
-
* import type { Exporter, InferParams } from '@cadit-app/script-params';
|
|
371
|
-
* import type script from './main';
|
|
372
|
-
*
|
|
373
|
-
* type QrCodeParams = InferParams<typeof script>;
|
|
374
|
-
* // { size: number; label: string }
|
|
375
|
-
*
|
|
376
|
-
* export const pngExporter: Exporter<QrCodeParams> = {
|
|
377
|
-
* name: 'PNG',
|
|
378
|
-
* export: (params) => { ... }, // params.size is number, params.label is string
|
|
379
|
-
* };
|
|
380
|
-
* ```
|
|
381
|
-
*/
|
|
382
|
-
export type InferParams<T> = T extends ScriptModule<infer S, unknown> ? Params<S> : T extends {
|
|
383
|
-
params: infer S extends ParamSchema;
|
|
384
|
-
} ? Params<S> : never;
|
|
385
|
-
/**
|
|
386
|
-
* Configuration object for defineParams when using named properties.
|
|
387
|
-
* All options are named for clarity and extensibility.
|
|
388
|
-
*/
|
|
389
|
-
export interface ScriptConfig<S extends ParamSchema, R = unknown> {
|
|
390
|
-
/** The parameter schema defining all inputs. */
|
|
391
|
-
params: S;
|
|
392
|
-
/** Optional main function that generates geometry. */
|
|
393
|
-
main?: (params: Params<S>) => R;
|
|
394
|
-
/** Optional exporters for custom download formats (SVG, PNG, etc.). */
|
|
395
|
-
exporters?: Exporters<Params<S>>;
|
|
396
|
-
}
|
|
397
|
-
/**
|
|
398
|
-
* The result returned by defineParams.
|
|
399
|
-
* Contains the schema (for UI), optional exporters, and is optionally callable.
|
|
400
|
-
*/
|
|
401
|
-
export interface ScriptModule<S extends ParamSchema, R = unknown> {
|
|
402
|
-
/** The parameter schema for UI generation. */
|
|
403
|
-
params: S;
|
|
404
|
-
/** Optional exporters for custom download formats. */
|
|
405
|
-
exporters?: Exporters<Params<S>>;
|
|
406
|
-
/**
|
|
407
|
-
* Execute the script with optional parameter overrides.
|
|
408
|
-
* Missing parameters use their default values.
|
|
409
|
-
* Only available if a main function was provided.
|
|
410
|
-
*/
|
|
411
|
-
(inputParams?: Partial<Params<S>>): R;
|
|
412
|
-
}
|
|
413
|
-
/**
|
|
414
|
-
* Define parameters for a parametric script.
|
|
415
|
-
*
|
|
416
|
-
* Pass a config object with `params` (required), and optionally `main` and `exporters`.
|
|
417
|
-
*
|
|
418
|
-
* @example Basic usage
|
|
419
|
-
* ```typescript
|
|
420
|
-
* export default defineParams({
|
|
421
|
-
* params: {
|
|
422
|
-
* size: { type: 'number', default: 10 },
|
|
423
|
-
* },
|
|
424
|
-
* main: (params) => Manifold.cube([params.size, params.size, params.size]),
|
|
425
|
-
* });
|
|
426
|
-
* ```
|
|
427
|
-
*
|
|
428
|
-
* @example With exporters
|
|
429
|
-
* ```typescript
|
|
430
|
-
* export default defineParams({
|
|
431
|
-
* params: {
|
|
432
|
-
* size: { type: 'number', default: 10 },
|
|
433
|
-
* },
|
|
434
|
-
* exporters: {
|
|
435
|
-
* svg: { name: 'SVG', export: (p) => svgExport(p) },
|
|
436
|
-
* png: { name: 'PNG', export: (p) => pngExport(p) },
|
|
437
|
-
* },
|
|
438
|
-
* main: (params) => Manifold.cube([params.size, params.size, params.size]),
|
|
439
|
-
* });
|
|
440
|
-
* ```
|
|
441
|
-
*
|
|
442
|
-
* @example Without main (add main separately with createMain)
|
|
443
|
-
* ```typescript
|
|
444
|
-
* const script = defineParams({
|
|
445
|
-
* params: { size: { type: 'number', default: 10 } },
|
|
446
|
-
* exporters: { svg: svgExporter },
|
|
447
|
-
* });
|
|
448
|
-
* export default createMain(script, myMainFunction);
|
|
449
|
-
* ```
|
|
450
|
-
*/
|
|
451
|
-
export declare function defineParams<const S extends ParamSchema, R = unknown>(config: ScriptConfig<S, R>): ScriptModule<S, R>;
|
|
452
|
-
/**
|
|
453
|
-
* Create an executable script module by adding a main function.
|
|
454
|
-
*
|
|
455
|
-
* Use this when you want to define your main function separately from the params,
|
|
456
|
-
* for example when the main is complex or needs to be tested independently.
|
|
457
|
-
*
|
|
458
|
-
* Preserves any exporters defined on the original ScriptModule.
|
|
459
|
-
*
|
|
460
|
-
* @example
|
|
461
|
-
* ```typescript
|
|
462
|
-
* const script = defineParams({
|
|
463
|
-
* params: { size: { type: 'number', default: 10 } },
|
|
464
|
-
* exporters: { svg: svgExporter },
|
|
465
|
-
* });
|
|
466
|
-
*
|
|
467
|
-
* export default createMain(script, (p) => Manifold.cube([p.size, ...]));
|
|
468
|
-
* ```
|
|
469
|
-
*/
|
|
470
|
-
export declare function createMain<S extends ParamSchema, R>(scriptModule: ScriptModule<S, unknown>, main: (params: Params<S>) => R): ScriptModule<S, R>;
|
|
471
|
-
/**
|
|
472
|
-
* Convert an object-based schema to array format for legacy UI compatibility.
|
|
473
|
-
*
|
|
474
|
-
* This function transforms the script-params schema format into the
|
|
475
|
-
* ObjectMakerParam[] format expected by the Core UI.
|
|
476
|
-
*
|
|
477
|
-
* @example
|
|
478
|
-
* ```typescript
|
|
479
|
-
* const schema = { size: { type: 'number', default: 10 } };
|
|
480
|
-
* const array = schemaToArray(schema);
|
|
481
|
-
* // [{ name: 'size', type: 'number', initial: 10, caption: 'size' }]
|
|
482
|
-
* ```
|
|
483
|
-
*/
|
|
484
|
-
export declare function schemaToArray<S extends ParamSchema>(schema: S): Array<Record<string, unknown>>;
|
|
485
|
-
/**
|
|
486
|
-
* Extract defaults from a schema as a plain object.
|
|
487
|
-
*
|
|
488
|
-
* @example
|
|
489
|
-
* ```typescript
|
|
490
|
-
* const schema = {
|
|
491
|
-
* size: { type: 'number', default: 10 },
|
|
492
|
-
* label: { type: 'text', default: 'Hi' },
|
|
493
|
-
* };
|
|
494
|
-
* const defaults = getDefaults(schema);
|
|
495
|
-
* // { size: 10, label: 'Hi' }
|
|
496
|
-
* ```
|
|
497
|
-
*/
|
|
498
|
-
export declare function getDefaults<S extends ParamSchema>(schema: S): Params<S>;
|
|
499
|
-
/**
|
|
500
|
-
* Check if a module export uses the defineParams format.
|
|
501
|
-
*
|
|
502
|
-
* @example
|
|
503
|
-
* ```typescript
|
|
504
|
-
* const mod = await import('./script.ts');
|
|
505
|
-
* if (isScriptModule(mod.default)) {
|
|
506
|
-
* const result = mod.default({ size: 20 });
|
|
507
|
-
* }
|
|
508
|
-
* ```
|
|
509
|
-
*/
|
|
510
|
-
export declare function isScriptModule(value: unknown): value is ScriptModule<ParamSchema, unknown>;
|
|
511
|
-
/**
|
|
512
|
-
* Extract the parameter schema from a ScriptModule.
|
|
513
|
-
* Useful for embedding another script's parameters.
|
|
514
|
-
*
|
|
515
|
-
* @example
|
|
516
|
-
* ```typescript
|
|
517
|
-
* import qrCodeScript from './qr-code';
|
|
518
|
-
*
|
|
519
|
-
* const qrParams = getParams(qrCodeScript);
|
|
520
|
-
*
|
|
521
|
-
* // Use in embedded param definition
|
|
522
|
-
* export default defineParams({
|
|
523
|
-
* params: {
|
|
524
|
-
* qrCode: {
|
|
525
|
-
* type: 'embedded',
|
|
526
|
-
* params: getParams(qrCodeScript),
|
|
527
|
-
* enabled: false,
|
|
528
|
-
* },
|
|
529
|
-
* },
|
|
530
|
-
* });
|
|
531
|
-
* ```
|
|
532
|
-
*/
|
|
533
|
-
export declare function getParams<S extends ParamSchema>(source: ScriptModule<S, unknown>): S;
|
|
534
|
-
/**
|
|
535
|
-
* Extract exporters from a ScriptModule.
|
|
536
|
-
* Returns an empty object if the module has no exporters.
|
|
537
|
-
*
|
|
538
|
-
* @example
|
|
539
|
-
* ```typescript
|
|
540
|
-
* import qrCodeScript from './qr-code';
|
|
541
|
-
*
|
|
542
|
-
* const exporters = getExporters(qrCodeScript);
|
|
543
|
-
* // { svg: { name: 'SVG', ... }, png: { name: 'PNG', ... } }
|
|
544
|
-
* ```
|
|
545
|
-
*/
|
|
546
|
-
export declare function getExporters<S extends ParamSchema>(source: ScriptModule<S, unknown>): Exporters<Params<S>>;
|
|
547
|
-
/**
|
|
548
|
-
* Helper to create an embedded param definition with npm package metadata.
|
|
549
|
-
* This enables relative asset paths (like buttonGrid images) to be resolved
|
|
550
|
-
* correctly when embedding another npm package's parameters.
|
|
551
|
-
*
|
|
552
|
-
* @param npmPackage - The npm package name (e.g., '@cadit-app/qr-code')
|
|
553
|
-
* @param embeddedDef - The embedded param definition
|
|
554
|
-
* @returns The embedded definition with npmPackage attached
|
|
555
|
-
*
|
|
556
|
-
* @example
|
|
557
|
-
* ```typescript
|
|
558
|
-
* import qrCodeModule from '@cadit-app/qr-code';
|
|
559
|
-
* import { defineParams, embedParams } from '@cadit-app/script-params';
|
|
560
|
-
*
|
|
561
|
-
* export default defineParams({
|
|
562
|
-
* params: {
|
|
563
|
-
* qrCodeSettings: embedParams('@cadit-app/qr-code', {
|
|
564
|
-
* type: 'embedded',
|
|
565
|
-
* label: 'QR Code (Optional)',
|
|
566
|
-
* params: qrCodeModule.params,
|
|
567
|
-
* enabled: false,
|
|
568
|
-
* showSettings: false,
|
|
569
|
-
* }),
|
|
570
|
-
* },
|
|
571
|
-
* main: (params) => { ... },
|
|
572
|
-
* });
|
|
573
|
-
* ```
|
|
574
|
-
*/
|
|
575
|
-
export declare function embedParams(npmPackage: string, embeddedDef: Omit<EmbeddedParamDef, 'npmPackage'>): EmbeddedParamDef;
|
|
576
|
-
export {};
|
|
22
|
+
export type { ParamDefBase, NumberParamDef, FloatParamDef, IntParamDef, SliderParamDef, TextParamDef, FontParamDef, BooleanParamDef, SwitchParamDef, CheckboxParamDef, ChoiceOption, ChoiceParamDef, RadioParamDef, ImageFileValue, ImageParamDef, ButtonGridOption, ButtonGridParamDef, PresetOption, PresetParamDef, } from './params';
|
|
23
|
+
export type { Point2D, Point3D, PathSegment, PathPoint, DoodlePath, SerializedShapeData, Shape2dValue, Shape2dParamDef, Triangle, SerializedMeshData, Shape3dValue, Shape3dParamDef, MeshOptions, } from './params';
|
|
24
|
+
export type { EmbeddedParamDef, EmbeddedParamValue, ParamDef, ParamSchema, ParamValue, Params, } from './params';
|
|
25
|
+
export { isPathSegment, getPathPointXY, samplePathTo2D, hasShape3dMesh, getShape3dMeshOptions, toManifold, } from './params';
|
|
26
|
+
export type { ExportResult, Exporter, ExporterMetadata, Exporters, } from './exporters';
|
|
27
|
+
export { getExporterMetadata, getExportersMetadata, } from './exporters';
|
|
28
|
+
export type { ScriptConfig, ScriptModule, InferParams, } from './script';
|
|
29
|
+
export { defineParams, createMain, } from './script';
|
|
30
|
+
export { schemaToArray, getDefaults, isScriptModule, getParams, getExporters, embedParams, } from './utils';
|
|
31
|
+
export type { BezierPoint2D, PathPoint2D, SculptPoint, Color, ShapeBase, RectInput, TriangleInput, StarInput, CircleInput, PolyPointsInput, HeartInput, PolygonInput, CompoundPathInput, TextInput, ShapeInput, ShapeDefinition, SceneObject2DPolygon, SceneObject2DRect, SceneObject2DCircle, SceneObject2DEllipse, SceneObject2D, SceneObject3DBox, SceneObject3DCylinder, SceneObject3DSphere, SceneObject3DExtrusion, SceneObject3D, SceneObject, AnyShape, SceneOutput, } from './sceneOutput';
|
|
32
|
+
export { rect, circle, star, triangle, regularPolygon, heart, polygon, text, createSceneOutput, isSceneOutput, } from './sceneOutput';
|
|
577
33
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAOH,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,UAAU,CAAC;AAGlB,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,UAAU,CAAC;AAGlB,YAAY,EACV,gBAAgB,EAChB,kBAAkB,EAClB,QAAQ,EACR,WAAW,EACX,UAAU,EACV,MAAM,GACP,MAAM,UAAU,CAAC;AAGlB,OAAO,EACL,aAAa,EACb,cAAc,EACd,cAAc,EACd,cAAc,EACd,qBAAqB,EACrB,UAAU,GACX,MAAM,UAAU,CAAC;AAMlB,YAAY,EACV,YAAY,EACZ,QAAQ,EACR,gBAAgB,EAChB,SAAS,GACV,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,aAAa,CAAC;AAMrB,YAAY,EACV,YAAY,EACZ,YAAY,EACZ,WAAW,GACZ,MAAM,UAAU,CAAC;AAElB,OAAO,EACL,YAAY,EACZ,UAAU,GACX,MAAM,UAAU,CAAC;AAMlB,OAAO,EACL,aAAa,EACb,WAAW,EACX,cAAc,EACd,SAAS,EACT,YAAY,EACZ,WAAW,GACZ,MAAM,SAAS,CAAC;AAMjB,YAAY,EAEV,aAAa,EACb,WAAW,EACX,WAAW,EACX,KAAK,EAGL,SAAS,EAGT,SAAS,EACT,aAAa,EACb,SAAS,EACT,WAAW,EACX,eAAe,EACf,UAAU,EACV,YAAY,EACZ,iBAAiB,EACjB,SAAS,EACT,UAAU,EACV,eAAe,EAGf,oBAAoB,EACpB,iBAAiB,EACjB,mBAAmB,EACnB,oBAAoB,EACpB,aAAa,EAGb,gBAAgB,EAChB,qBAAqB,EACrB,mBAAmB,EACnB,sBAAsB,EACtB,aAAa,EAGb,WAAW,EACX,QAAQ,EAGR,WAAW,GACZ,MAAM,eAAe,CAAC;AAGvB,OAAO,EACL,IAAI,EACJ,MAAM,EACN,IAAI,EACJ,QAAQ,EACR,cAAc,EACd,KAAK,EACL,OAAO,EACP,IAAI,EACJ,iBAAiB,EACjB,aAAa,GACd,MAAM,eAAe,CAAC"}
|