@faicad/faijs-fcstd 0.17.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 (87) hide show
  1. package/LICENSE +29 -0
  2. package/NOTICE +20 -0
  3. package/dist/attachment.d.ts +72 -0
  4. package/dist/attachment.d.ts.map +1 -0
  5. package/dist/attachment.js +93 -0
  6. package/dist/attachment.js.map +1 -0
  7. package/dist/bspline.d.ts +58 -0
  8. package/dist/bspline.d.ts.map +1 -0
  9. package/dist/bspline.js +93 -0
  10. package/dist/bspline.js.map +1 -0
  11. package/dist/build-fai-zip.d.ts +40 -0
  12. package/dist/build-fai-zip.d.ts.map +1 -0
  13. package/dist/build-fai-zip.js +111 -0
  14. package/dist/build-fai-zip.js.map +1 -0
  15. package/dist/cli.d.ts +3 -0
  16. package/dist/cli.d.ts.map +1 -0
  17. package/dist/cli.js +37 -0
  18. package/dist/cli.js.map +1 -0
  19. package/dist/codegen.d.ts +83 -0
  20. package/dist/codegen.d.ts.map +1 -0
  21. package/dist/codegen.js +618 -0
  22. package/dist/codegen.js.map +1 -0
  23. package/dist/container.d.ts +75 -0
  24. package/dist/container.d.ts.map +1 -0
  25. package/dist/container.js +36 -0
  26. package/dist/container.js.map +1 -0
  27. package/dist/contour.d.ts +43 -0
  28. package/dist/contour.d.ts.map +1 -0
  29. package/dist/contour.js +132 -0
  30. package/dist/contour.js.map +1 -0
  31. package/dist/convert.d.ts +69 -0
  32. package/dist/convert.d.ts.map +1 -0
  33. package/dist/convert.js +303 -0
  34. package/dist/convert.js.map +1 -0
  35. package/dist/document.d.ts +48 -0
  36. package/dist/document.d.ts.map +1 -0
  37. package/dist/document.js +140 -0
  38. package/dist/document.js.map +1 -0
  39. package/dist/expressions.d.ts +79 -0
  40. package/dist/expressions.d.ts.map +1 -0
  41. package/dist/expressions.js +162 -0
  42. package/dist/expressions.js.map +1 -0
  43. package/dist/external-geo.d.ts +49 -0
  44. package/dist/external-geo.d.ts.map +1 -0
  45. package/dist/external-geo.js +140 -0
  46. package/dist/external-geo.js.map +1 -0
  47. package/dist/feature-translate.d.ts +193 -0
  48. package/dist/feature-translate.d.ts.map +1 -0
  49. package/dist/feature-translate.js +1441 -0
  50. package/dist/feature-translate.js.map +1 -0
  51. package/dist/fillet-edges.d.ts +26 -0
  52. package/dist/fillet-edges.d.ts.map +1 -0
  53. package/dist/fillet-edges.js +36 -0
  54. package/dist/fillet-edges.js.map +1 -0
  55. package/dist/index.d.ts +23 -0
  56. package/dist/index.d.ts.map +1 -0
  57. package/dist/index.js +19 -0
  58. package/dist/index.js.map +1 -0
  59. package/dist/placement.d.ts +93 -0
  60. package/dist/placement.d.ts.map +1 -0
  61. package/dist/placement.js +117 -0
  62. package/dist/placement.js.map +1 -0
  63. package/dist/planegcs-backend.d.ts +34 -0
  64. package/dist/planegcs-backend.d.ts.map +1 -0
  65. package/dist/planegcs-backend.js +665 -0
  66. package/dist/planegcs-backend.js.map +1 -0
  67. package/dist/sketch-parse.d.ts +199 -0
  68. package/dist/sketch-parse.d.ts.map +1 -0
  69. package/dist/sketch-parse.js +263 -0
  70. package/dist/sketch-parse.js.map +1 -0
  71. package/dist/sketch-solver.d.ts +63 -0
  72. package/dist/sketch-solver.d.ts.map +1 -0
  73. package/dist/sketch-solver.js +28 -0
  74. package/dist/sketch-solver.js.map +1 -0
  75. package/dist/sketch-verify.d.ts +53 -0
  76. package/dist/sketch-verify.d.ts.map +1 -0
  77. package/dist/sketch-verify.js +71 -0
  78. package/dist/sketch-verify.js.map +1 -0
  79. package/dist/structural-types.d.ts +96 -0
  80. package/dist/structural-types.d.ts.map +1 -0
  81. package/dist/structural-types.js +155 -0
  82. package/dist/structural-types.js.map +1 -0
  83. package/dist/unpack.d.ts +44 -0
  84. package/dist/unpack.d.ts.map +1 -0
  85. package/dist/unpack.js +64 -0
  86. package/dist/unpack.js.map +1 -0
  87. package/package.json +65 -0
@@ -0,0 +1,193 @@
1
+ /**
2
+ * M4 — whitelisted feature translation: FCStd objects → cad-op call plan.
3
+ *
4
+ * M4.1 whitelist: anything not listed → baked (S3, no silent loss).
5
+ * M4.2 primitives → cad.box/cylinder/cone/sphere
6
+ * M4.3 booleans → cad.union/subtract/intersect
7
+ * M4.6 Pad/Pocket → cad.extrude/cad.subtract over the M3 sketch contour (M6: sketch is a cad.sketch face)
8
+ *
9
+ * The call plan is an intermediate representation: M5 lowers it to .fai.js
10
+ * (statements sN, variables partN). Geometry values are already mm (D7).
11
+ */
12
+ import type { FcstdObject } from './document.js';
13
+ import { type ExpressionBinding } from './expressions.js';
14
+ import type { FilletEdgeEntry } from './fillet-edges.js';
15
+ /**
16
+ * One cad-op call in the M4 call plan (lowered to .fai.js by M5).
17
+ */
18
+ export interface CadCall {
19
+ /** target variable name (partN, assigned by M5) */
20
+ out: string;
21
+ /** cad-op name, e.g. "cad.box" */
22
+ op: string;
23
+ /** positional + named params, JSON-serializable */
24
+ params: Record<string, unknown>;
25
+ /** variable names this call consumes (rendered positionally before literals) */
26
+ inputs: string[];
27
+ /** positional literal values appended after `inputs` (e.g. a direction Vec3) */
28
+ literals?: unknown[];
29
+ /** FCStd object this call came from */
30
+ source: string;
31
+ /**
32
+ * When true, `inputs` is bookkeeping-only (dependency tracking / variable
33
+ * remapping / consumed-set) and must NOT be rendered as positional args —
34
+ * the real args come from `params`. Used by params-only ops like
35
+ * `cad.compound` whose members live in `params.members` (rendering `inputs`
36
+ * positionally would shadow `params`).
37
+ */
38
+ noPositionalArgs?: boolean;
39
+ }
40
+ /**
41
+ * A raw JS expression argument that M5 renders verbatim instead of JSON-encoding.
42
+ *
43
+ * Needed when a call argument is itself a function call against a variable that
44
+ * only exists at run time — e.g. `cad.edgeRef(part3, 17)` for the edge selection
45
+ * of a Fillet/Chamfer (the EdgeTopoRef must be resolved against the live base
46
+ * shape, so it cannot be baked into the IR as a literal).
47
+ */
48
+ export interface JsExpr {
49
+ /** the JS source to emit in the argument position */
50
+ readonly __jsExpr: string;
51
+ }
52
+ /**
53
+ * Wrap raw JS source as a verbatim argument (`JsExpr`).
54
+ *
55
+ * @param code - the JS expression source to emit in the argument position.
56
+ * @returns the `JsExpr` marker carrying that source.
57
+ */
58
+ export declare function jsExpr(code: string): JsExpr;
59
+ /**
60
+ * True for a `JsExpr` marker (used by M5 to render verbatim).
61
+ *
62
+ * @param v - the value to test.
63
+ * @returns true when `v` is a `JsExpr` marker.
64
+ */
65
+ export declare function isJsExpr(v: unknown): v is JsExpr;
66
+ /**
67
+ * Outcome of translating one FCStd object: a cad-op call plan, an explicit
68
+ * bake with reason, or preserved-only (no geometry emitted).
69
+ */
70
+ export type TranslateVerdict = {
71
+ kind: 'translated';
72
+ calls: CadCall[];
73
+ reason?: string;
74
+ } | {
75
+ kind: 'baked';
76
+ reason: string;
77
+ } | {
78
+ kind: 'preserved-only';
79
+ reason: string;
80
+ };
81
+ /**
82
+ * H7 (hole_puzzle corpus, 2026-09-20): marker input for a subtract whose base
83
+ * is implied by the Body's feature order (no explicit BaseFeature property).
84
+ * Codegen retargets this at the chain head when folding the feature into its
85
+ * Body chain. Never a legal variable name (contains `::`), so it cannot be
86
+ * confused with a real input.
87
+ */
88
+ export declare const BODY_CHAIN_BASE = "::body-chain-base::";
89
+ /**
90
+ * True when the object type is on the M4.1 translation whitelist.
91
+ *
92
+ * @param type - the FCStd object type, e.g. "Part::Box".
93
+ * @returns true when the type is whitelisted for translation.
94
+ */
95
+ export declare function isWhitelisted(type: string): boolean;
96
+ /**
97
+ * H10 (plan §3.1/§3.5): C4's Python exception, decided by PROPERTY presence —
98
+ * NOT by the `Python` type-name suffix. Matches the library profile's
99
+ * pythonObjects口径 (profile.mjs: type contains "Python" or carries
100
+ * Python/Proxy properties); here only the property evidence qualifies, so a
101
+ * Python-suffixed type without the property stays a plain translation gap.
102
+ * @param obj - the FCStd object to inspect.
103
+ * @returns true when the object is a Python-scripted feature whose serialized
104
+ * shape is opaque (legitimate `python-baked` under C4).
105
+ */
106
+ export declare function isPythonOpaque(obj: FcstdObject): boolean;
107
+ /**
108
+ * M11.1/M11.2: the ExpressionEngine binding for `name`, if any. `value` is
109
+ * undefined for non-constant expressions (references/arithmetic) — the caller
110
+ * must bake with an explicit reason instead of estimating.
111
+ *
112
+ * @param obj - the FCStd object whose ExpressionEngine to inspect.
113
+ * @param name - the property name to look up.
114
+ * @returns the binding for `name`, or undefined when the object has no
115
+ * ExpressionEngine binding for it.
116
+ */
117
+ export declare function expressionBindingOf(obj: FcstdObject, name: string): ExpressionBinding | undefined;
118
+ /**
119
+ * M11.2: detect a non-constant expression binding on a property.
120
+ *
121
+ * @param obj - the FCStd object whose ExpressionEngine to inspect.
122
+ * @param name - the property name to look up.
123
+ * @returns true when `name` has a binding that is NOT a constant expression.
124
+ */
125
+ export declare function hasNonConstantBinding(obj: FcstdObject, name: string): boolean;
126
+ /**
127
+ * M9.1 — Pad/Pocket `Type` enumeration (App::PropertyEnumeration, stored as
128
+ * the string enum label OR its integer index — both seen in the corpus).
129
+ * FreeCAD sources: Pad.h / Pocket.h TypeEnum lists (differs between the two):
130
+ * Pad: 0=Length 1=UpToLast 2=UpToFirst 3=UpToFace 4=TwoLengths
131
+ * Pocket: 0=Length 1=ThroughAll 2=UpToFirst 3=UpToFace 4=TwoLengths
132
+ * A missing Type property means Length (0) — the FreeCAD default.
133
+ */
134
+ export type FeatureType = 'Length' | 'ThroughAll' | 'UpToLast' | 'UpToFirst' | 'UpToFace' | 'TwoLengths' | 'unknown';
135
+ /**
136
+ * Read the Pad/Pocket `Type` enumeration of an object (M9.1).
137
+ *
138
+ * @param obj - the FCStd Pad or Pocket object.
139
+ * @param kind - which type-enum table to apply (Pad vs Pocket labels differ).
140
+ * @returns the parsed feature type; 'Length' when Type is missing, 'unknown'
141
+ * when the stored label/index is not recognized.
142
+ */
143
+ export declare function featureTypeOf(obj: FcstdObject, kind: 'pad' | 'pocket'): FeatureType;
144
+ /**
145
+ * Parse a PartDesign ReferenceAxis reference into a 3D axis + pivot point.
146
+ *
147
+ * FreeCAD stores this as an `App::PropertyLinkSub` string that either names a
148
+ * standard body axis (`V_Axis` / `H_Axis` / `N_Axis`, or the generic `Axis`
149
+ * that PartDesign revolves around = +Z) or an edge/vertex of another feature.
150
+ * Edge/vertex axes require resolving referenced geometry, which the port does
151
+ * not yet do (explicit downgrade, no silent loss).
152
+ *
153
+ * @param ref - the ReferenceAxis (or Direction) LinkSub string, may be undefined.
154
+ * @returns a unit axis and pivot point, or undefined when the reference names
155
+ * edge/vertex geometry (unsupported).
156
+ */
157
+ export declare function parseReferenceAxis(ref: string | undefined): {
158
+ axis: [number, number, number];
159
+ at: [number, number, number];
160
+ } | undefined;
161
+ /**
162
+ * Placement position (translation) of an object.
163
+ *
164
+ * @param obj - the FCStd object to read.
165
+ * @returns the (Px, Py, Pz) translation from its Placement, or (0,0,0) when absent.
166
+ */
167
+ export declare function placementPos(obj: FcstdObject): [number, number, number];
168
+ /**
169
+ * M4 translate one object. `inputVar` maps a dependency object name to the
170
+ * variable holding its geometry (sketch contours or prior solid).
171
+ *
172
+ * `docObjects` (optional) is the full document object list — needed by the
173
+ * UpToFace datum-plane path to read the target plane's Placement (plan
174
+ * extrude-upto-face §4.3-C1). When absent, UpToFace keeps the explicit bake.
175
+ *
176
+ * @param obj - the FCStd object to translate.
177
+ * @param inputVar - resolves a dependency object name to the variable holding
178
+ * its geometry (sketch contours or prior solid).
179
+ * @param docObjects - the full document object list, needed by the UpToFace
180
+ * datum-plane path; optional.
181
+ * @param shapeCarriers - objects whose Shape is stored as a .brp member; optional.
182
+ * @param brokenShapeAssets - objects whose Shape `file` attribute points at a missing/empty member (explicit gap); optional.
183
+ * @param filletEdgesData - parsed PropertyFilletEdges binaries keyed by object name (Part::Chamfer/Fillet); optional.
184
+ * @returns the cad-op call plan, or an explicit bake/preserve verdict with reason.
185
+ */
186
+ export declare function translateObject(obj: FcstdObject, inputVar: (depName: string) => string | undefined, docObjects?: readonly FcstdObject[],
187
+ /** H7: names of objects whose Shape is stored as a .brp member (probed from the ZIP). */
188
+ shapeCarriers?: ReadonlySet<string>,
189
+ /** E4: objects whose Shape `file` attribute points at a missing/empty member. */
190
+ brokenShapeAssets?: ReadonlySet<string>,
191
+ /** P8: parsed PropertyFilletEdges binaries keyed by object name (Part::Chamfer/Fillet). */
192
+ filletEdgesData?: ReadonlyMap<string, FilletEdgeEntry[]>): TranslateVerdict;
193
+ //# sourceMappingURL=feature-translate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"feature-translate.d.ts","sourceRoot":"","sources":["../src/feature-translate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAsC,KAAK,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAG9F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEzD;;GAEG;AACH,MAAM,WAAW,OAAO;IACtB,mDAAmD;IACnD,GAAG,EAAE,MAAM,CAAC;IACZ,kCAAkC;IAClC,EAAE,EAAE,MAAM,CAAC;IACX,mDAAmD;IACnD,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,gFAAgF;IAChF,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,gFAAgF;IAChF,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAC;IACrB,uCAAuC;IACvC,MAAM,EAAE,MAAM,CAAC;IACf;;;;;;OAMG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,MAAM;IACrB,qDAAqD;IACrD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B;AAED;;;;;GAKG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE3C;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,MAAM,CAE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