@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
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Exporter types for CADit parametric scripts.
|
|
3
|
+
*
|
|
4
|
+
* Exporters allow scripts to provide custom download formats (SVG, PNG, 3MF, etc.).
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Result returned by an exporter function.
|
|
8
|
+
* Contains the file data, MIME type, and suggested filename.
|
|
9
|
+
*/
|
|
10
|
+
export interface ExportResult {
|
|
11
|
+
/** MIME type of the exported data (e.g., 'image/svg+xml', 'image/png'). */
|
|
12
|
+
mimeType: string;
|
|
13
|
+
/** Suggested filename for download (e.g., 'model.svg'). */
|
|
14
|
+
fileName: string;
|
|
15
|
+
/** The exported data - string for text formats, ArrayBuffer for binary. */
|
|
16
|
+
data: ArrayBuffer | string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Exporter definition.
|
|
20
|
+
* Provides a function to export the current state to a downloadable format.
|
|
21
|
+
*
|
|
22
|
+
* @template P - The params type. Use `InferParams<typeof myScript>` to derive
|
|
23
|
+
* from a script, or define inline when used with defineParams.
|
|
24
|
+
*
|
|
25
|
+
* @example Inline with defineParams (type is inferred automatically)
|
|
26
|
+
* ```typescript
|
|
27
|
+
* export default defineParams({
|
|
28
|
+
* params: { size: { type: 'number', default: 10 } },
|
|
29
|
+
* exporters: {
|
|
30
|
+
* svg: {
|
|
31
|
+
* name: 'SVG',
|
|
32
|
+
* export: (p) => ({ ... }), // p.size is typed as number
|
|
33
|
+
* },
|
|
34
|
+
* },
|
|
35
|
+
* });
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* @example Separate file using InferParams
|
|
39
|
+
* ```typescript
|
|
40
|
+
* import type { Exporter, InferParams } from '@cadit-app/script-params';
|
|
41
|
+
* import type script from './main';
|
|
42
|
+
*
|
|
43
|
+
* type Params = InferParams<typeof script>;
|
|
44
|
+
*
|
|
45
|
+
* export const pngExporter: Exporter<Params> = {
|
|
46
|
+
* name: 'PNG',
|
|
47
|
+
* export: (params) => { ... }, // params is fully typed
|
|
48
|
+
* };
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export interface Exporter<P = unknown> {
|
|
52
|
+
/** Short name for the exporter (e.g., 'SVG', 'PNG', '3MF'). */
|
|
53
|
+
name: string;
|
|
54
|
+
/** Label shown on the download button (e.g., 'Download SVG'). */
|
|
55
|
+
label?: string;
|
|
56
|
+
/** Description or tooltip for the exporter. */
|
|
57
|
+
description?: string;
|
|
58
|
+
/**
|
|
59
|
+
* Optional async initialization function.
|
|
60
|
+
* Called once before the first export.
|
|
61
|
+
* Use for WASM initialization or other one-time setup.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* init: async () => {
|
|
66
|
+
* const wasm = await __cadit_loadWasm('@resvg/resvg-wasm', 'index_bg.wasm');
|
|
67
|
+
* await resvg.initWasm(wasm);
|
|
68
|
+
* }
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
init?: () => Promise<void>;
|
|
72
|
+
/** Export function that receives the current parameter values. */
|
|
73
|
+
export: (params: P) => Promise<ExportResult> | ExportResult;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Serializable exporter metadata for passing to UI.
|
|
77
|
+
* Contains only the display information, not the actual export function.
|
|
78
|
+
*/
|
|
79
|
+
export interface ExporterMetadata {
|
|
80
|
+
/** The key used to identify this exporter in the exporters record. */
|
|
81
|
+
key: string;
|
|
82
|
+
/** Short name for the exporter (e.g., 'SVG', 'PNG', '3MF'). */
|
|
83
|
+
name: string;
|
|
84
|
+
/** Label shown on the download button (e.g., 'Download SVG'). */
|
|
85
|
+
label?: string;
|
|
86
|
+
/** Description or tooltip for the exporter. */
|
|
87
|
+
description?: string;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Map of exporters keyed by identifier.
|
|
91
|
+
* The key is used to identify the exporter, the value contains the definition.
|
|
92
|
+
*
|
|
93
|
+
* @template P - The params type for all exporters in the map.
|
|
94
|
+
*/
|
|
95
|
+
export type Exporters<P = unknown> = Record<string, Exporter<P>>;
|
|
96
|
+
/**
|
|
97
|
+
* Extract metadata from an Exporter (strips non-serializable functions).
|
|
98
|
+
* @param key - The key in the exporters record
|
|
99
|
+
* @param exporter - The exporter definition
|
|
100
|
+
*/
|
|
101
|
+
export declare function getExporterMetadata<P>(key: string, exporter: Exporter<P>): ExporterMetadata;
|
|
102
|
+
/**
|
|
103
|
+
* Extract metadata array from Exporters record.
|
|
104
|
+
* Preserves the key for each exporter so it can be looked up later.
|
|
105
|
+
*/
|
|
106
|
+
export declare function getExportersMetadata<P>(exporters: Exporters<P>): ExporterMetadata[];
|
|
107
|
+
//# sourceMappingURL=exporters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exporters.d.ts","sourceRoot":"","sources":["../src/exporters.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,2EAA2E;IAC3E,QAAQ,EAAE,MAAM,CAAC;IACjB,2DAA2D;IAC3D,QAAQ,EAAE,MAAM,CAAC;IACjB,2EAA2E;IAC3E,IAAI,EAAE,WAAW,GAAG,MAAM,CAAC;CAC5B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,WAAW,QAAQ,CAAC,CAAC,GAAG,OAAO;IACnC,+DAA+D;IAC/D,IAAI,EAAE,MAAM,CAAC;IACb,iEAAiE;IACjE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,+CAA+C;IAC/C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;;;;;;;;;OAYG;IACH,IAAI,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3B,kEAAkE;IAClE,MAAM,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,OAAO,CAAC,YAAY,CAAC,GAAG,YAAY,CAAC;CAC7D;AAED;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,sEAAsE;IACtE,GAAG,EAAE,MAAM,CAAC;IACZ,+DAA+D;IAC/D,IAAI,EAAE,MAAM,CAAC;IACb,iEAAiE;IACjE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,+CAA+C;IAC/C,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;;;GAKG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,GAAG,OAAO,IAAI,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;AAMjE;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,gBAAgB,CAO3F;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,gBAAgB,EAAE,CAEnF"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Exporter types for CADit parametric scripts.
|
|
3
|
+
*
|
|
4
|
+
* Exporters allow scripts to provide custom download formats (SVG, PNG, 3MF, etc.).
|
|
5
|
+
*/
|
|
6
|
+
// =============================================================================
|
|
7
|
+
// Exporter Utility Functions
|
|
8
|
+
// =============================================================================
|
|
9
|
+
/**
|
|
10
|
+
* Extract metadata from an Exporter (strips non-serializable functions).
|
|
11
|
+
* @param key - The key in the exporters record
|
|
12
|
+
* @param exporter - The exporter definition
|
|
13
|
+
*/
|
|
14
|
+
export function getExporterMetadata(key, exporter) {
|
|
15
|
+
return {
|
|
16
|
+
key,
|
|
17
|
+
name: exporter.name,
|
|
18
|
+
label: exporter.label,
|
|
19
|
+
description: exporter.description,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Extract metadata array from Exporters record.
|
|
24
|
+
* Preserves the key for each exporter so it can be looked up later.
|
|
25
|
+
*/
|
|
26
|
+
export function getExportersMetadata(exporters) {
|
|
27
|
+
return Object.entries(exporters).map(([key, exporter]) => getExporterMetadata(key, exporter));
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=exporters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exporters.js","sourceRoot":"","sources":["../src/exporters.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAoGH,gFAAgF;AAChF,6BAA6B;AAC7B,gFAAgF;AAEhF;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAI,GAAW,EAAE,QAAqB;IACvE,OAAO;QACL,GAAG;QACH,IAAI,EAAE,QAAQ,CAAC,IAAI;QACnB,KAAK,EAAE,QAAQ,CAAC,KAAK;QACrB,WAAW,EAAE,QAAQ,CAAC,WAAW;KAClC,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAAI,SAAuB;IAC7D,OAAO,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,QAAQ,CAAC,EAAE,EAAE,CAAC,mBAAmB,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC;AAChG,CAAC"}
|