@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.
- package/LICENSE +29 -0
- package/NOTICE +20 -0
- package/dist/attachment.d.ts +72 -0
- package/dist/attachment.d.ts.map +1 -0
- package/dist/attachment.js +93 -0
- package/dist/attachment.js.map +1 -0
- package/dist/bspline.d.ts +58 -0
- package/dist/bspline.d.ts.map +1 -0
- package/dist/bspline.js +93 -0
- package/dist/bspline.js.map +1 -0
- package/dist/build-fai-zip.d.ts +40 -0
- package/dist/build-fai-zip.d.ts.map +1 -0
- package/dist/build-fai-zip.js +111 -0
- package/dist/build-fai-zip.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +37 -0
- package/dist/cli.js.map +1 -0
- package/dist/codegen.d.ts +83 -0
- package/dist/codegen.d.ts.map +1 -0
- package/dist/codegen.js +618 -0
- package/dist/codegen.js.map +1 -0
- package/dist/container.d.ts +75 -0
- package/dist/container.d.ts.map +1 -0
- package/dist/container.js +36 -0
- package/dist/container.js.map +1 -0
- package/dist/contour.d.ts +43 -0
- package/dist/contour.d.ts.map +1 -0
- package/dist/contour.js +132 -0
- package/dist/contour.js.map +1 -0
- package/dist/convert.d.ts +69 -0
- package/dist/convert.d.ts.map +1 -0
- package/dist/convert.js +303 -0
- package/dist/convert.js.map +1 -0
- package/dist/document.d.ts +48 -0
- package/dist/document.d.ts.map +1 -0
- package/dist/document.js +140 -0
- package/dist/document.js.map +1 -0
- package/dist/expressions.d.ts +79 -0
- package/dist/expressions.d.ts.map +1 -0
- package/dist/expressions.js +162 -0
- package/dist/expressions.js.map +1 -0
- package/dist/external-geo.d.ts +49 -0
- package/dist/external-geo.d.ts.map +1 -0
- package/dist/external-geo.js +140 -0
- package/dist/external-geo.js.map +1 -0
- package/dist/feature-translate.d.ts +193 -0
- package/dist/feature-translate.d.ts.map +1 -0
- package/dist/feature-translate.js +1441 -0
- package/dist/feature-translate.js.map +1 -0
- package/dist/fillet-edges.d.ts +26 -0
- package/dist/fillet-edges.d.ts.map +1 -0
- package/dist/fillet-edges.js +36 -0
- package/dist/fillet-edges.js.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/placement.d.ts +93 -0
- package/dist/placement.d.ts.map +1 -0
- package/dist/placement.js +117 -0
- package/dist/placement.js.map +1 -0
- package/dist/planegcs-backend.d.ts +34 -0
- package/dist/planegcs-backend.d.ts.map +1 -0
- package/dist/planegcs-backend.js +665 -0
- package/dist/planegcs-backend.js.map +1 -0
- package/dist/sketch-parse.d.ts +199 -0
- package/dist/sketch-parse.d.ts.map +1 -0
- package/dist/sketch-parse.js +263 -0
- package/dist/sketch-parse.js.map +1 -0
- package/dist/sketch-solver.d.ts +63 -0
- package/dist/sketch-solver.d.ts.map +1 -0
- package/dist/sketch-solver.js +28 -0
- package/dist/sketch-solver.js.map +1 -0
- package/dist/sketch-verify.d.ts +53 -0
- package/dist/sketch-verify.d.ts.map +1 -0
- package/dist/sketch-verify.js +71 -0
- package/dist/sketch-verify.js.map +1 -0
- package/dist/structural-types.d.ts +96 -0
- package/dist/structural-types.d.ts.map +1 -0
- package/dist/structural-types.js +155 -0
- package/dist/structural-types.js.map +1 -0
- package/dist/unpack.d.ts +44 -0
- package/dist/unpack.d.ts.map +1 -0
- package/dist/unpack.js +64 -0
- package/dist/unpack.js.map +1 -0
- package/package.json +65 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unpack.d.ts","sourceRoot":"","sources":["../src/unpack.ts"],"names":[],"mappings":"AAUA,OAAO,EAAW,KAAK,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAEhE;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,gEAAgE;IAChE,IAAI,EAAE,MAAM,CAAC;IACb,6BAA6B;IAC7B,KAAK,EAAE,UAAU,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IACjC,4EAA4E;IAC5E,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,MAAM,WAAW,GACnB;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GACpC;IAAE,IAAI,EAAE,iBAAiB,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAEjD;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,CAAC,YAAY,EAAE,WAAW,CAAC,CAkB/E;AAiBD;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAIlF"}
|
package/dist/unpack.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* M1.1 — FCStd container unpacking.
|
|
3
|
+
*
|
|
4
|
+
* Validation rules per plan §5.5.6 (corrected): a file is an FCStd iff it opens
|
|
5
|
+
* as a ZIP and contains `Document.xml` at its root. The ZIP comment is advisory
|
|
6
|
+
* only and must never cause rejection.
|
|
7
|
+
*
|
|
8
|
+
* faijs contract: unit mm, errors via Result (ok/err).
|
|
9
|
+
*/
|
|
10
|
+
import { unzipSync } from 'fflate';
|
|
11
|
+
import { err, ok } from '@faicad/faijs/api/result';
|
|
12
|
+
/**
|
|
13
|
+
* Unpack an FCStd file. Only requirement: valid ZIP + root `Document.xml`.
|
|
14
|
+
*
|
|
15
|
+
* @param data - the raw FCStd file bytes.
|
|
16
|
+
* @returns the unpacked archive, or a structured UnpackError.
|
|
17
|
+
*/
|
|
18
|
+
export function unpackFcstd(data) {
|
|
19
|
+
let entries;
|
|
20
|
+
try {
|
|
21
|
+
entries = unzipSync(data);
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
return err({
|
|
25
|
+
kind: 'not-zip',
|
|
26
|
+
message: `cannot open as ZIP: ${e instanceof Error ? e.message : String(e)}`,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
if (!('Document.xml' in entries)) {
|
|
30
|
+
return err({ kind: 'no-document-xml', message: 'root Document.xml not found in ZIP' });
|
|
31
|
+
}
|
|
32
|
+
// fflate does not expose the raw ZIP comment through unzipSync; read it
|
|
33
|
+
// directly from the EOCD record (22 bytes from end when comment is empty,
|
|
34
|
+
// else longer). Advisory only — never used for validation.
|
|
35
|
+
const comment = readZipComment(data) ?? '';
|
|
36
|
+
return ok({ members: new Map(Object.entries(entries)), zipComment: comment });
|
|
37
|
+
}
|
|
38
|
+
function readZipComment(data) {
|
|
39
|
+
// scan for EOCD signature 0x06054b50 from the end
|
|
40
|
+
for (let i = data.length - 22; i >= Math.max(0, data.length - 22 - 65535); i--) {
|
|
41
|
+
if (data[i] === 0x50 && data[i + 1] === 0x4b && data[i + 2] === 0x05 && data[i + 3] === 0x06) {
|
|
42
|
+
const len = data[i + 20] | (data[i + 21] << 8);
|
|
43
|
+
const start = i + 22;
|
|
44
|
+
if (start + len > data.length)
|
|
45
|
+
return null;
|
|
46
|
+
return new TextDecoder('latin1').decode(data.subarray(start, start + len));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* UTF-8 text decode helper for XML members.
|
|
53
|
+
*
|
|
54
|
+
* @param archive - the unpacked FCStd container.
|
|
55
|
+
* @param path - member path inside the ZIP, e.g. "Document.xml".
|
|
56
|
+
* @returns the member decoded as UTF-8 text, or undefined when absent.
|
|
57
|
+
*/
|
|
58
|
+
export function memberText(archive, path) {
|
|
59
|
+
const bytes = archive.members.get(path);
|
|
60
|
+
if (!bytes)
|
|
61
|
+
return undefined;
|
|
62
|
+
return new TextDecoder('utf-8').decode(b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,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,GAAG,EAAE,GAAG,KAAK,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC/E,IACE,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,IAAI,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,IAAI,IAAI,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,IAAI,IAAI,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,IAAI,EACxF,CAAC;YACD,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,GAAG,EAAE,CAAE,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,CAAE,IAAI,CAAC,CAAC,CAAC;YACjD,MAAM,KAAK,GAAG,CAAC,GAAG,EAAE,CAAC;YACrB,IAAI,KAAK,GAAG,GAAG,GAAG,IAAI,CAAC,MAAM;gBAAE,OAAO,IAAI,CAAC;YAC3C,OAAO,IAAI,WAAW,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,GAAG,CAAC,CAAC,CAAC;QAC7E,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CAAC,OAAqB,EAAE,IAAY;IAC5D,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACxC,IAAI,CAAC,KAAK;QAAE,OAAO,SAAS,CAAC;IAC7B,OAAO,IAAI,WAAW,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAChD,CAAC","sourcesContent":["/**\n * M1.1 — FCStd container unpacking.\n *\n * Validation rules per plan §5.5.6 (corrected): a file is an FCStd iff it opens\n * as a ZIP and contains `Document.xml` at its root. The ZIP comment is advisory\n * only and must never cause rejection.\n *\n * faijs contract: unit mm, errors via Result (ok/err).\n */\nimport { unzipSync } from 'fflate';\nimport { err, ok, type Result } from '@faicad/faijs/api/result';\n\n/**\n * One raw file inside the FCStd ZIP container.\n */\nexport interface FcstdMember {\n /** path inside the ZIP, e.g. \"Document.xml\", \"PartShape.brp\" */\n path: string;\n /** the member's raw bytes */\n bytes: Uint8Array;\n}\n\n/**\n * The unpacked FCStd container: all ZIP members plus the advisory comment.\n */\nexport interface FcstdArchive {\n members: Map<string, Uint8Array>;\n /** advisory ZIP comment; may be empty (2/56 samples have empty comments) */\n zipComment: string;\n}\n\n/**\n * Structured unpack failure: not a valid ZIP, or missing root `Document.xml`.\n */\nexport type UnpackError =\n | { kind: 'not-zip'; message: string }\n | { kind: 'no-document-xml'; message: string };\n\n/**\n * Unpack an FCStd file. Only requirement: valid ZIP + root `Document.xml`.\n *\n * @param data - the raw FCStd file bytes.\n * @returns the unpacked archive, or a structured UnpackError.\n */\nexport function unpackFcstd(data: Uint8Array): Result<FcstdArchive, UnpackError> {\n let entries: Record<string, Uint8Array>;\n try {\n entries = unzipSync(data);\n } catch (e) {\n return err({\n kind: 'not-zip',\n message: `cannot open as ZIP: ${e instanceof Error ? e.message : String(e)}`,\n });\n }\n if (!('Document.xml' in entries)) {\n return err({ kind: 'no-document-xml', message: 'root Document.xml not found in ZIP' });\n }\n // fflate does not expose the raw ZIP comment through unzipSync; read it\n // directly from the EOCD record (22 bytes from end when comment is empty,\n // else longer). Advisory only — never used for validation.\n const comment = readZipComment(data) ?? '';\n return ok({ members: new Map(Object.entries(entries)), zipComment: comment });\n}\n\nfunction readZipComment(data: Uint8Array): string | null {\n // scan for EOCD signature 0x06054b50 from the end\n for (let i = data.length - 22; i >= Math.max(0, data.length - 22 - 65535); i--) {\n if (\n data[i] === 0x50 && data[i + 1] === 0x4b && data[i + 2] === 0x05 && data[i + 3] === 0x06\n ) {\n const len = data[i + 20]! | (data[i + 21]! << 8);\n const start = i + 22;\n if (start + len > data.length) return null;\n return new TextDecoder('latin1').decode(data.subarray(start, start + len));\n }\n }\n return null;\n}\n\n/**\n * UTF-8 text decode helper for XML members.\n *\n * @param archive - the unpacked FCStd container.\n * @param path - member path inside the ZIP, e.g. \"Document.xml\".\n * @returns the member decoded as UTF-8 text, or undefined when absent.\n */\nexport function memberText(archive: FcstdArchive, path: string): string | undefined {\n const bytes = archive.members.get(path);\n if (!bytes) return undefined;\n return new TextDecoder('utf-8').decode(bytes);\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@faicad/faijs-fcstd",
|
|
3
|
+
"version": "0.17.0",
|
|
4
|
+
"description": "FCStd reader and .fai.js conversion pipeline for faijs — unpack, sketch parse/solve, feature translate, batch CLI",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"faijs",
|
|
7
|
+
"cad",
|
|
8
|
+
"fcstd",
|
|
9
|
+
"freecad",
|
|
10
|
+
"converter"
|
|
11
|
+
],
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://gitcode.com/Faicad/faijs.git"
|
|
16
|
+
},
|
|
17
|
+
"type": "module",
|
|
18
|
+
"sideEffects": false,
|
|
19
|
+
"main": "./dist/index.js",
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"bin": {
|
|
22
|
+
"faijs-fcstd-convert": "./dist/cli.js"
|
|
23
|
+
},
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"default": "./dist/index.js"
|
|
28
|
+
},
|
|
29
|
+
"./convert": {
|
|
30
|
+
"types": "./dist/convert.d.ts",
|
|
31
|
+
"default": "./dist/convert.js"
|
|
32
|
+
},
|
|
33
|
+
"./*": {
|
|
34
|
+
"types": "./dist/*.d.ts",
|
|
35
|
+
"default": "./dist/*.js"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"files": [
|
|
39
|
+
"dist",
|
|
40
|
+
"NOTICE",
|
|
41
|
+
"LICENSE"
|
|
42
|
+
],
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@salusoft89/planegcs": "1.2.0",
|
|
45
|
+
"@xmldom/xmldom": "^0.9.8",
|
|
46
|
+
"fflate": "^0.8.2"
|
|
47
|
+
},
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"@faicad/faijs": "^0.17.0",
|
|
50
|
+
"occt-wasm": "^3.8.4"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"typescript": "*",
|
|
54
|
+
"vitest": "*",
|
|
55
|
+
"occt-wasm": "^3.8.4",
|
|
56
|
+
"three": "^0.184.0",
|
|
57
|
+
"@types/three": "^0.184.1"
|
|
58
|
+
},
|
|
59
|
+
"scripts": {
|
|
60
|
+
"build": "tsc -p tsconfig.build.json && node ../../scripts/fix-import-extensions.mjs dist",
|
|
61
|
+
"typecheck": "tsc --noEmit",
|
|
62
|
+
"test": "vitest run",
|
|
63
|
+
"lint": "eslint src"
|
|
64
|
+
}
|
|
65
|
+
}
|