@onerjs/serializers 8.41.5 → 8.41.7

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 (67) hide show
  1. package/3MF/3mfSerializer.configuration.d.ts +9 -0
  2. package/3MF/3mfSerializer.configuration.js +11 -0
  3. package/3MF/3mfSerializer.configuration.js.map +1 -0
  4. package/3MF/3mfSerializer.d.ts +132 -0
  5. package/3MF/3mfSerializer.js +328 -0
  6. package/3MF/3mfSerializer.js.map +1 -0
  7. package/3MF/core/index.d.ts +2 -0
  8. package/3MF/core/index.js +4 -0
  9. package/3MF/core/index.js.map +1 -0
  10. package/3MF/core/model/3mf.builder.d.ts +231 -0
  11. package/3MF/core/model/3mf.builder.js +403 -0
  12. package/3MF/core/model/3mf.builder.js.map +1 -0
  13. package/3MF/core/model/3mf.d.ts +329 -0
  14. package/3MF/core/model/3mf.interfaces.d.ts +321 -0
  15. package/3MF/core/model/3mf.interfaces.js +39 -0
  16. package/3MF/core/model/3mf.interfaces.js.map +1 -0
  17. package/3MF/core/model/3mf.js +377 -0
  18. package/3MF/core/model/3mf.js.map +1 -0
  19. package/3MF/core/model/3mf.opc.d.ts +66 -0
  20. package/3MF/core/model/3mf.opc.interfaces.d.ts +126 -0
  21. package/3MF/core/model/3mf.opc.interfaces.js +75 -0
  22. package/3MF/core/model/3mf.opc.interfaces.js.map +1 -0
  23. package/3MF/core/model/3mf.opc.js +91 -0
  24. package/3MF/core/model/3mf.opc.js.map +1 -0
  25. package/3MF/core/model/3mf.serializer.d.ts +118 -0
  26. package/3MF/core/model/3mf.serializer.js +171 -0
  27. package/3MF/core/model/3mf.serializer.js.map +1 -0
  28. package/3MF/core/model/3mf.types.d.ts +46 -0
  29. package/3MF/core/model/3mf.types.js +2 -0
  30. package/3MF/core/model/3mf.types.js.map +1 -0
  31. package/3MF/core/model/index.d.ts +7 -0
  32. package/3MF/core/model/index.js +8 -0
  33. package/3MF/core/model/index.js.map +1 -0
  34. package/3MF/core/xml/index.d.ts +6 -0
  35. package/3MF/core/xml/index.js +7 -0
  36. package/3MF/core/xml/index.js.map +1 -0
  37. package/3MF/core/xml/xml.builder.bytes.d.ts +33 -0
  38. package/3MF/core/xml/xml.builder.bytes.js +60 -0
  39. package/3MF/core/xml/xml.builder.bytes.js.map +1 -0
  40. package/3MF/core/xml/xml.builder.d.ts +94 -0
  41. package/3MF/core/xml/xml.builder.js +286 -0
  42. package/3MF/core/xml/xml.builder.js.map +1 -0
  43. package/3MF/core/xml/xml.builder.string.d.ts +19 -0
  44. package/3MF/core/xml/xml.builder.string.js +35 -0
  45. package/3MF/core/xml/xml.builder.string.js.map +1 -0
  46. package/3MF/core/xml/xml.interfaces.d.ts +91 -0
  47. package/3MF/core/xml/xml.interfaces.js +110 -0
  48. package/3MF/core/xml/xml.interfaces.js.map +1 -0
  49. package/3MF/core/xml/xml.serializer.d.ts +39 -0
  50. package/3MF/core/xml/xml.serializer.format.d.ts +92 -0
  51. package/3MF/core/xml/xml.serializer.format.js +122 -0
  52. package/3MF/core/xml/xml.serializer.format.js.map +1 -0
  53. package/3MF/core/xml/xml.serializer.js +261 -0
  54. package/3MF/core/xml/xml.serializer.js.map +1 -0
  55. package/3MF/index.d.ts +3 -0
  56. package/3MF/index.js +5 -0
  57. package/3MF/index.js.map +1 -0
  58. package/index.d.ts +1 -0
  59. package/index.js +1 -0
  60. package/index.js.map +1 -1
  61. package/legacy/legacy-3mfSerializer.d.ts +1 -0
  62. package/legacy/legacy-3mfSerializer.js +20 -0
  63. package/legacy/legacy-3mfSerializer.js.map +1 -0
  64. package/legacy/legacy.d.ts +1 -0
  65. package/legacy/legacy.js +1 -0
  66. package/legacy/legacy.js.map +1 -1
  67. package/package.json +3 -3
@@ -0,0 +1,75 @@
1
+ export const OpenXmlContentTypesNamespace = "http://schemas.openxmlformats.org/package/2006/content-types";
2
+ export const OpenXmlRelationshipsNamespace = "http://schemas.openxmlformats.org/package/2006/relationships";
3
+ export var KnownI3mfContentType;
4
+ (function (KnownI3mfContentType) {
5
+ // OPC core
6
+ KnownI3mfContentType["Relationships"] = "application/vnd.openxmlformats-package.relationships+xml";
7
+ // 3MF core
8
+ KnownI3mfContentType["Model"] = "application/vnd.ms-package.3dmanufacturing-3dmodel+xml";
9
+ // Extensions officielles
10
+ KnownI3mfContentType["Materials"] = "application/vnd.ms-package.3dmanufacturing-material+xml";
11
+ KnownI3mfContentType["Colors"] = "application/vnd.ms-package.3dmanufacturing-colors+xml";
12
+ KnownI3mfContentType["Texture"] = "application/vnd.ms-package.3dmanufacturing-texture+xml";
13
+ KnownI3mfContentType["Texture2D"] = "application/vnd.ms-package.3dmanufacturing-texture2d+xml";
14
+ KnownI3mfContentType["Production"] = "application/vnd.ms-package.3dmanufacturing-production+xml";
15
+ KnownI3mfContentType["Slice"] = "application/vnd.ms-package.3dmanufacturing-slice+xml";
16
+ KnownI3mfContentType["BeamLattice"] = "application/vnd.ms-package.3dmanufacturing-beamlattice+xml";
17
+ KnownI3mfContentType["SecureContent"] = "application/vnd.ms-package.3dmanufacturing-securecontent+xml";
18
+ // Assets
19
+ KnownI3mfContentType["Png"] = "image/png";
20
+ KnownI3mfContentType["Jpeg"] = "image/jpeg";
21
+ KnownI3mfContentType["Tiff"] = "image/tiff";
22
+ KnownI3mfContentType["Xml"] = "application/xml";
23
+ })(KnownI3mfContentType || (KnownI3mfContentType = {}));
24
+ export const RelationshipDirName = "_rels/";
25
+ export const Object3dDirName = "3D/";
26
+ export const ModelFileName = `3dmodel.model`;
27
+ export const RelationshipFileName = `.rels`;
28
+ export const ContentTypeFileName = "[Content_Types].xml";
29
+ /**
30
+ * Common OPC and 3MF relationship Type URIs.
31
+ */
32
+ export class Known3mfRelationshipTypes {
33
+ /**
34
+ * Test if the relationship Type is one of the common known URIs above
35
+ * @param type
36
+ * @returns true if the relationship Type is one of the common known URIs above
37
+ */
38
+ static IsKnown(type) {
39
+ return Known3mfRelationshipTypes.Known.has(type);
40
+ }
41
+ /**
42
+ * test if the relationship Type is the main 3MF model entry point
43
+ * @param type
44
+ * @returns true if the relationship Type is the main 3MF model entry point
45
+ */
46
+ static IsThreeDimModel(type) {
47
+ return type === Known3mfRelationshipTypes.ThreeDimModel;
48
+ }
49
+ }
50
+ /**
51
+ * 3MF core: points to the main .model part of the package
52
+ */
53
+ Known3mfRelationshipTypes.ThreeDimModel = "http://schemas.microsoft.com/3dmanufacturing/2013/01/3dmodel";
54
+ /**
55
+ * OPC core: points to a package thumbnail (often used by 3MF packages)
56
+ */
57
+ Known3mfRelationshipTypes.Thumbnail = "http://schemas.openxmlformats.org/package/2006/relationships/metadata/thumbnail";
58
+ /**
59
+ * 3MF (print ticket): optional printing settings part (rarely used by slicers)
60
+ */
61
+ Known3mfRelationshipTypes.PrintTicket = "http://schemas.microsoft.com/3dmanufacturing/2013/01/printticket";
62
+ /**
63
+ * OPC core: indicates parts that must be preserved when editing the package
64
+ */
65
+ Known3mfRelationshipTypes.MustPreserve = "http://schemas.openxmlformats.org/package/2006/relationships/mustpreserve";
66
+ /**
67
+ * Convenience set for quick checks
68
+ */
69
+ Known3mfRelationshipTypes.Known = new Set([
70
+ Known3mfRelationshipTypes.ThreeDimModel,
71
+ Known3mfRelationshipTypes.Thumbnail,
72
+ Known3mfRelationshipTypes.PrintTicket,
73
+ Known3mfRelationshipTypes.MustPreserve,
74
+ ]);
75
+ //# sourceMappingURL=3mf.opc.interfaces.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"3mf.opc.interfaces.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/3MF/core/model/3mf.opc.interfaces.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,4BAA4B,GAAG,8DAA8D,CAAC;AAC3G,MAAM,CAAC,MAAM,6BAA6B,GAAG,8DAA8D,CAAC;AAE5G,MAAM,CAAN,IAAY,oBAsBX;AAtBD,WAAY,oBAAoB;IAC5B,WAAW;IACX,kGAA0E,CAAA;IAE1E,WAAW;IACX,wFAAgE,CAAA;I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C","sourcesContent":["import type { I3mfModel } from \"./3mf.interfaces\";\n\nexport const OpenXmlContentTypesNamespace = \"http://schemas.openxmlformats.org/package/2006/content-types\";\nexport const OpenXmlRelationshipsNamespace = \"http://schemas.openxmlformats.org/package/2006/relationships\";\n\nexport enum KnownI3mfContentType {\n // OPC core\n Relationships = \"application/vnd.openxmlformats-package.relationships+xml\",\n\n // 3MF core\n Model = \"application/vnd.ms-package.3dmanufacturing-3dmodel+xml\",\n\n // Extensions officielles\n Materials = \"application/vnd.ms-package.3dmanufacturing-material+xml\",\n Colors = \"application/vnd.ms-package.3dmanufacturing-colors+xml\",\n Texture = \"application/vnd.ms-package.3dmanufacturing-texture+xml\",\n Texture2D = \"application/vnd.ms-package.3dmanufacturing-texture2d+xml\",\n Production = \"application/vnd.ms-package.3dmanufacturing-production+xml\",\n Slice = \"application/vnd.ms-package.3dmanufacturing-slice+xml\",\n BeamLattice = \"application/vnd.ms-package.3dmanufacturing-beamlattice+xml\",\n SecureContent = \"application/vnd.ms-package.3dmanufacturing-securecontent+xml\",\n\n // Assets\n Png = \"image/png\",\n Jpeg = \"image/jpeg\",\n Tiff = \"image/tiff\",\n Xml = \"application/xml\",\n}\n\nexport const RelationshipDirName = \"_rels/\";\nexport const Object3dDirName = \"3D/\";\nexport const ModelFileName = `3dmodel.model`;\nexport const RelationshipFileName = `.rels`;\nexport const ContentTypeFileName = \"[Content_Types].xml\";\n\n/**\n * Common OPC and 3MF relationship Type URIs.\n */\nexport class Known3mfRelationshipTypes {\n /**\n * 3MF core: points to the main .model part of the package\n */\n public static readonly ThreeDimModel = \"http://schemas.microsoft.com/3dmanufacturing/2013/01/3dmodel\";\n\n /**\n * OPC core: points to a package thumbnail (often used by 3MF packages)\n */\n public static readonly Thumbnail = \"http://schemas.openxmlformats.org/package/2006/relationships/metadata/thumbnail\";\n\n /**\n * 3MF (print ticket): optional printing settings part (rarely used by slicers)\n */\n public static readonly PrintTicket = \"http://schemas.microsoft.com/3dmanufacturing/2013/01/printticket\";\n\n /**\n * OPC core: indicates parts that must be preserved when editing the package\n */\n public static readonly MustPreserve = \"http://schemas.openxmlformats.org/package/2006/relationships/mustpreserve\";\n\n /**\n * Convenience set for quick checks\n */\n public static readonly Known: ReadonlySet<string> = new Set<string>([\n Known3mfRelationshipTypes.ThreeDimModel,\n Known3mfRelationshipTypes.Thumbnail,\n Known3mfRelationshipTypes.PrintTicket,\n Known3mfRelationshipTypes.MustPreserve,\n ]);\n\n /**\n * Test if the relationship Type is one of the common known URIs above\n * @param type\n * @returns true if the relationship Type is one of the common known URIs above\n */\n public static IsKnown(type: string): boolean {\n return Known3mfRelationshipTypes.Known.has(type);\n }\n\n /**\n * test if the relationship Type is the main 3MF model entry point\n * @param type\n * @returns true if the relationship Type is the main 3MF model entry point\n */\n public static IsThreeDimModel(type: string): boolean {\n return type === Known3mfRelationshipTypes.ThreeDimModel;\n }\n}\n\n/**\n *\n */\nexport interface I3mfContentTypes {\n /**\n *\n */\n items: I3mfContentType[];\n}\n\n/**\n *\n */\nexport interface I3mfContentType {\n /**\n *\n */\n ext: string;\n /**\n *\n */\n ct: string;\n}\n\n/**\n *\n */\nexport interface I3mfRelationships {\n /**\n *\n */\n items: I3mfRelationship[];\n}\n\n/**\n *\n */\nexport interface I3mfRelationship {\n /**\n *\n */\n id: string;\n\n /**\n *\n */\n type?: string;\n\n /**\n *\n */\n target?: string;\n}\n\n/**\n *\n */\nexport interface I3mfDocument {\n /**\n *\n */\n contentTypes: I3mfContentTypes;\n /**\n *\n */\n relationships: I3mfRelationships;\n /**\n *\n */\n model: I3mfModel;\n}\n"]}
@@ -0,0 +1,91 @@
1
+ import { __decorate } from "@onerjs/core/tslib.es6.js";
2
+ import { XmlAttr, XmlName } from "../xml/xml.interfaces.js";
3
+ import { OpenXmlContentTypesNamespace, OpenXmlRelationshipsNamespace } from "./3mf.opc.interfaces.js";
4
+ /**
5
+ *
6
+ */
7
+ let ThreeMfContentTypes = class ThreeMfContentTypes {
8
+ constructor() {
9
+ /**
10
+ *
11
+ */
12
+ this.items = [];
13
+ }
14
+ };
15
+ ThreeMfContentTypes = __decorate([
16
+ XmlName({ ns: OpenXmlContentTypesNamespace, name: "Types" })
17
+ ], ThreeMfContentTypes);
18
+ export { ThreeMfContentTypes };
19
+ /**
20
+ *
21
+ */
22
+ let ThreeMfContentType = class ThreeMfContentType {
23
+ /**
24
+ *
25
+ * @param ext
26
+ * @param ct
27
+ */
28
+ constructor(ext, ct) {
29
+ this.ext = ext;
30
+ this.ct = ct;
31
+ }
32
+ };
33
+ __decorate([
34
+ XmlAttr({ name: { ns: OpenXmlContentTypesNamespace, name: "Extension" } })
35
+ ], ThreeMfContentType.prototype, "ext", void 0);
36
+ __decorate([
37
+ XmlAttr({ name: { ns: OpenXmlContentTypesNamespace, name: "ContentType" } })
38
+ ], ThreeMfContentType.prototype, "ct", void 0);
39
+ ThreeMfContentType = __decorate([
40
+ XmlName({ ns: OpenXmlContentTypesNamespace, name: "Default" })
41
+ ], ThreeMfContentType);
42
+ export { ThreeMfContentType };
43
+ /**
44
+ *
45
+ */
46
+ let ThreeMfRelationships = class ThreeMfRelationships {
47
+ constructor() {
48
+ /**
49
+ *
50
+ */
51
+ this.items = [];
52
+ }
53
+ };
54
+ ThreeMfRelationships = __decorate([
55
+ XmlName({ ns: OpenXmlRelationshipsNamespace, name: "Relationships" })
56
+ ], ThreeMfRelationships);
57
+ export { ThreeMfRelationships };
58
+ /**
59
+ *
60
+ */
61
+ let ThreeMfRelationship = class ThreeMfRelationship {
62
+ constructor(id, type, target) {
63
+ this.id = id;
64
+ this.type = type;
65
+ this.target = target;
66
+ }
67
+ };
68
+ __decorate([
69
+ XmlAttr({ name: "Id" })
70
+ ], ThreeMfRelationship.prototype, "id", void 0);
71
+ __decorate([
72
+ XmlAttr({ name: "Type" })
73
+ ], ThreeMfRelationship.prototype, "type", void 0);
74
+ __decorate([
75
+ XmlAttr({ name: "Target" })
76
+ ], ThreeMfRelationship.prototype, "target", void 0);
77
+ ThreeMfRelationship = __decorate([
78
+ XmlName({ ns: OpenXmlRelationshipsNamespace, name: "Relationship" })
79
+ ], ThreeMfRelationship);
80
+ export { ThreeMfRelationship };
81
+ /**
82
+ *
83
+ */
84
+ export class ThreeMfDocument {
85
+ constructor(contentTypes, relationships, model) {
86
+ this.contentTypes = contentTypes;
87
+ this.relationships = relationships;
88
+ this.model = model;
89
+ }
90
+ }
91
+ //# sourceMappingURL=3mf.opc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"3mf.opc.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/3MF/core/model/3mf.opc.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAEzD,OAAO,EAAE,4BAA4B,EAAE,6BAA6B,EAAE,MAAM,sBAAsB,CAAC;AAGnG;;GAEG;AAEI,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IAAzB;QACH;;WAEG;QACH,UAAK,GAAyB,EAAE,CAAC;IACrC,CAAC;CAAA,CAAA;AALY,mBAAmB;IAD/B,OAAO,CAAC,EAAE,EAAE,EAAE,4BAA4B,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;GAChD,mBAAmB,CAK/B;;AAED;;GAEG;AAEI,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAY3B;;;;OAIG;IACH,YAAmB,GAAW,EAAE,EAAU;QACtC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;IACjB,CAAC;CACJ,CAAA;AAhBG;IADC,OAAO,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,4BAA4B,EAAE,IAAI,EAAE,WAAW,EAAE,EAAE,CAAC;+CAC/D;AAKZ;IADC,OAAO,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,4BAA4B,EAAE,IAAI,EAAE,aAAa,EAAE,EAAE,CAAC;8CAClE;AAVF,kBAAkB;IAD9B,OAAO,CAAC,EAAE,EAAE,EAAE,4BAA4B,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;GAClD,kBAAkB,CAqB9B;;AAED;;GAEG;AAEI,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IAA1B;QACH;;WAEG;QACH,UAAK,GAA0B,EAAE,CAAC;IACtC,CAAC;CAAA,CAAA;AALY,oBAAoB;IADhC,OAAO,CAAC,EAAE,EAAE,EAAE,6BAA6B,EAAE,IAAI,EAAE,eAAe,EAAE,CAAC;GACzD,oBAAoB,CAKhC;;AAED;;GAEG;AAEI,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IAmB5B,YAAY,EAAU,EAAE,IAAY,EAAE,MAAc;QAChD,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;CACJ,CAAA;AAnBG;IADC,OAAO,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;+CACb;AAMX;IADC,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;iDACZ;AAMd;IADC,OAAO,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;mDACZ;AAjBP,mBAAmB;IAD/B,OAAO,CAAC,EAAE,EAAE,EAAE,6BAA6B,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC;GACxD,mBAAmB,CAwB/B;;AAED;;GAEG;AACH,MAAM,OAAO,eAAe;IACxB,YACW,YAA8B,EAC9B,aAAgC,EAChC,KAAgB;QAFhB,iBAAY,GAAZ,YAAY,CAAkB;QAC9B,kBAAa,GAAb,aAAa,CAAmB;QAChC,UAAK,GAAL,KAAK,CAAW;IACxB,CAAC;CACP","sourcesContent":["import { XmlAttr, XmlName } from \"../xml/xml.interfaces\";\nimport type { I3mfModel } from \"./3mf.interfaces\";\nimport { OpenXmlContentTypesNamespace, OpenXmlRelationshipsNamespace } from \"./3mf.opc.interfaces\";\nimport type { I3mfContentTypes, I3mfContentType, I3mfRelationships, I3mfRelationship, I3mfDocument } from \"./3mf.opc.interfaces\";\n\n/**\n *\n */\n@XmlName({ ns: OpenXmlContentTypesNamespace, name: \"Types\" })\nexport class ThreeMfContentTypes implements I3mfContentTypes {\n /**\n *\n */\n items: ThreeMfContentType[] = [];\n}\n\n/**\n *\n */\n@XmlName({ ns: OpenXmlContentTypesNamespace, name: \"Default\" })\nexport class ThreeMfContentType implements I3mfContentType {\n /**\n *\n */\n @XmlAttr({ name: { ns: OpenXmlContentTypesNamespace, name: \"Extension\" } })\n ext: string;\n /**\n *\n */\n @XmlAttr({ name: { ns: OpenXmlContentTypesNamespace, name: \"ContentType\" } })\n ct: string;\n\n /**\n *\n * @param ext\n * @param ct\n */\n public constructor(ext: string, ct: string) {\n this.ext = ext;\n this.ct = ct;\n }\n}\n\n/**\n *\n */\n@XmlName({ ns: OpenXmlRelationshipsNamespace, name: \"Relationships\" })\nexport class ThreeMfRelationships implements I3mfRelationships {\n /**\n *\n */\n items: ThreeMfRelationship[] = [];\n}\n\n/**\n *\n */\n@XmlName({ ns: OpenXmlRelationshipsNamespace, name: \"Relationship\" })\nexport class ThreeMfRelationship implements I3mfRelationship {\n /**\n *\n */\n @XmlAttr({ name: \"Id\" })\n id: string;\n\n /**\n *\n */\n @XmlAttr({ name: \"Type\" })\n type?: string;\n\n /**\n *\n */\n @XmlAttr({ name: \"Target\" })\n target?: string;\n\n constructor(id: string, type: string, target: string) {\n this.id = id;\n this.type = type;\n this.target = target;\n }\n}\n\n/**\n *\n */\nexport class ThreeMfDocument implements I3mfDocument {\n public constructor(\n public contentTypes: I3mfContentTypes,\n public relationships: I3mfRelationships,\n public model: I3mfModel\n ) {}\n}\n"]}
@@ -0,0 +1,118 @@
1
+ import { ThreeMfModelBuilder } from "./3mf.builder.js";
2
+ import { type I3mfDocument } from "./3mf.opc.interfaces.js";
3
+ import type { I3mfModel } from "./3mf.interfaces.js";
4
+ import { ST_Unit } from "./3mf.interfaces.js";
5
+ /**
6
+ * Options controlling how meshes are exported into the 3MF model.
7
+ *
8
+ * Notes:
9
+ * - These flags are kept generic here and are expected to be interpreted by the concrete serializer/model builder.
10
+ * - Defaults are set in AbstractThreeMfSerializer.DEFAULT_3MF_EXPORTER_OPTIONS.
11
+ */
12
+ export interface IThreeMfSerializerOptions {
13
+ /**
14
+ * define the unit. Default is millimeter
15
+ */
16
+ unit?: ST_Unit;
17
+ /**
18
+ *
19
+ */
20
+ metadata?: Record<string, string>;
21
+ }
22
+ /**
23
+ * Minimal contract for a 3MF serializer that can stream its output through a sink callback.
24
+ *
25
+ * The sink callback receives:
26
+ * - err: any error produced by the serialization pipeline (if any)
27
+ * - chunk: a chunk of bytes to append to the destination
28
+ * - final: true when this is the last chunk
29
+ *
30
+ * Important:
31
+ * - Implementations should call sink with final=true exactly once, or rely on the underlying zip lib to do so.
32
+ * - Consumers may ignore final if they just buffer everything.
33
+ */
34
+ export interface I3mfSerializer<T> {
35
+ serializeAsync(sink: (err: any, chunk: Uint8Array, final: boolean) => void, ...meshes: Array<T>): Promise<void>;
36
+ }
37
+ /**
38
+ * Base class for 3MF serialization.
39
+ *
40
+ * Responsibilities:
41
+ * - Convert user meshes to a 3MF model (toModel).
42
+ * - Wrap the 3MF document parts into an OPC container (zip) and stream bytes through the sink.
43
+ *
44
+ * Non-responsibilities:
45
+ * - Providing/initializing the zip implementation (ensureZipLibReadyAsync is abstract).
46
+ * - Defining how meshes map to 3MF objects (toModel is abstract).
47
+ */
48
+ export declare abstract class AbstractThreeMfSerializer<T, O extends IThreeMfSerializerOptions> implements I3mfSerializer<T> {
49
+ private _o;
50
+ /**
51
+ * @param opts user-provided options overriding defaults.
52
+ */
53
+ constructor(opts: O);
54
+ /**
55
+ * Expose the resolved options (defaults + overrides) as readonly.
56
+ */
57
+ get options(): Readonly<O>;
58
+ /**
59
+ * Generic 3MF binary serializer.
60
+ * Pipeline overview:
61
+ * 1. ensureZipLibReadyAsync provides a zip implementation (host-dependent).
62
+ * 2. Convert meshes into an I3mfDocument (OPC parts + model).
63
+ * 3. Create a zip target that streams through the provided sink.
64
+ * 4. Serialize XML parts into zip entries.
65
+ * 5. End the zip stream.
66
+ * @param sink a callback receiving byte chunks; enables streaming without buffering the full archive in memory.
67
+ * @param meshes the meshes to serialize.
68
+ * @returns
69
+ */
70
+ serializeAsync(sink: (err: any, chunk: Uint8Array, final: boolean) => void, ...meshes: Array<T>): Promise<void>;
71
+ /**
72
+ * Build a full 3MF OPC document from meshes.
73
+ *
74
+ * The default behavior uses ThreeMfDocumentBuilder with the model produced by toModel().
75
+ * Override if you need custom parts (textures, thumbnails, print ticket, etc.).
76
+ * @param meshes
77
+ * @returns
78
+ */
79
+ toDocument(...meshes: Array<T>): I3mfDocument | undefined;
80
+ /**
81
+ * Convert input meshes into a 3MF model.
82
+ *
83
+ * Implementations typically:
84
+ * - Create resources and objects.
85
+ * - Define build items (instances) when exportInstances is enabled.
86
+ * - Encode geometry and properties required by your pipeline.
87
+ */
88
+ abstract toModel(builder: ThreeMfModelBuilder, ...meshes: Array<T>): I3mfModel;
89
+ /**
90
+ * Provide a zip implementation for the current host/runtime.
91
+ *
92
+ * This might be provided by the framework implementation, but it could differ depending on the host
93
+ * (native, Node.js, browser, etc.).
94
+ *
95
+ * Expected shape (fflate-like):
96
+ * - return [ Zip, ZipDeflate ] at minimum.
97
+ *
98
+ * Notes:
99
+ * - In a browser, this might require bundler configuration or dynamic import.
100
+ * - In Node.js, this might be a direct import of "fflate" or another compatible implementation.
101
+ */
102
+ abstract ensureZipLibReadyAsync(): Promise<any>;
103
+ }
104
+ /**
105
+ * Convenience helpers around serializers.
106
+ */
107
+ export declare class ThreeMf {
108
+ /**
109
+ * Serialize to a single in-memory buffer.
110
+ *
111
+ * This is a helper that buffers all chunks produced by serializeAsync, then concatenates them.
112
+ * Use serializeAsync directly if you want true streaming to a file/response.
113
+ * @param s
114
+ * @param meshes
115
+ * @returns
116
+ */
117
+ static SerializeToMemoryAsync<A>(s: I3mfSerializer<A>, ...meshes: Array<A>): Promise<Uint8Array | undefined>;
118
+ }
@@ -0,0 +1,171 @@
1
+ // 3MF
2
+ import { ThreeMfDocumentBuilder, ThreeMfModelBuilder } from "./3mf.builder.js";
3
+ import { ContentTypeFileName, ModelFileName, Object3dDirName, RelationshipDirName, RelationshipFileName } from "./3mf.opc.interfaces.js";
4
+ import { ST_Unit } from "./3mf.interfaces.js";
5
+ // XML
6
+ import { XmlBuilder } from "../xml/xml.builder.js";
7
+ import { XmlSerializer } from "../xml/xml.serializer.js";
8
+ import { Utf8XmlWriterToBytes } from "../xml/xml.builder.bytes.js";
9
+ /**
10
+ * Base class for 3MF serialization.
11
+ *
12
+ * Responsibilities:
13
+ * - Convert user meshes to a 3MF model (toModel).
14
+ * - Wrap the 3MF document parts into an OPC container (zip) and stream bytes through the sink.
15
+ *
16
+ * Non-responsibilities:
17
+ * - Providing/initializing the zip implementation (ensureZipLibReadyAsync is abstract).
18
+ * - Defining how meshes map to 3MF objects (toModel is abstract).
19
+ */
20
+ export class AbstractThreeMfSerializer {
21
+ /**
22
+ * @param opts user-provided options overriding defaults.
23
+ */
24
+ constructor(opts) {
25
+ this._o = opts;
26
+ }
27
+ /**
28
+ * Expose the resolved options (defaults + overrides) as readonly.
29
+ */
30
+ get options() {
31
+ return this._o;
32
+ }
33
+ /**
34
+ * Generic 3MF binary serializer.
35
+ * Pipeline overview:
36
+ * 1. ensureZipLibReadyAsync provides a zip implementation (host-dependent).
37
+ * 2. Convert meshes into an I3mfDocument (OPC parts + model).
38
+ * 3. Create a zip target that streams through the provided sink.
39
+ * 4. Serialize XML parts into zip entries.
40
+ * 5. End the zip stream.
41
+ * @param sink a callback receiving byte chunks; enables streaming without buffering the full archive in memory.
42
+ * @param meshes the meshes to serialize.
43
+ * @returns
44
+ */
45
+ async serializeAsync(sink, ...meshes) {
46
+ // The zip library (e.g. fflate) may need dynamic import / polyfills depending on host.
47
+ // This is delegated to the concrete serializer implementation.
48
+ const lib = await this.ensureZipLibReadyAsync();
49
+ // If no lib is available, we silently do nothing today.
50
+ // Consider: throwing could be better to fail fast. Kept as-is to preserve current behavior.
51
+ if (!lib) {
52
+ return;
53
+ }
54
+ const zip = lib.Zip;
55
+ const zipDeflate = lib.ZipDeflate;
56
+ // We expect a "fflate-like" API. If it is missing, fail with an explicit error.
57
+ if (!zip || !zipDeflate) {
58
+ throw new Error("fflate Zip / ZipDeflate not available");
59
+ }
60
+ /**
61
+ * Adapt a fflate entry to our ByteSink interface used by Utf8XmlWriterToBytes.
62
+ *
63
+ * fflate entry.push(chunk, final) is the writer endpoint for compressed bytes.
64
+ * @param entry
65
+ * @returns
66
+ */
67
+ const makeByteSinkFromFflateEntry = function (entry) {
68
+ return { push: (chunk, final) => entry.push(chunk, final) };
69
+ };
70
+ /**
71
+ * Serialize an in-memory XML object into a compressed zip entry.
72
+ *
73
+ * Notes:
74
+ * - "object" here is expected to be a structure understood by XmlSerializer.
75
+ * - Compression level 6 is a reasonable default for speed/size tradeoff.
76
+ * @param target
77
+ * @param name
78
+ * @param object
79
+ */
80
+ const serializeEntry = function (target, name, object) {
81
+ const entry = new zipDeflate(name, { level: 6 });
82
+ target.add(entry);
83
+ // Convert XmlSerializer output into UTF-8 bytes and push to the zip entry.
84
+ const sink = makeByteSinkFromFflateEntry(entry);
85
+ const w = new Utf8XmlWriterToBytes(sink);
86
+ // Build XML declaration and serialize.
87
+ const b = new XmlBuilder(w).dec("1.0", "UTF-8");
88
+ const s = new XmlSerializer(b);
89
+ s.serialize(object);
90
+ // Ensure the writer flushes any pending bytes and closes the stream for this entry.
91
+ w.finish();
92
+ };
93
+ // Convert meshes into a 3MF document (content types + relationships + model part).
94
+ const doc = this.toDocument(...meshes);
95
+ if (!doc) {
96
+ // Nothing to write. Current behavior: no zip output.
97
+ return;
98
+ }
99
+ // Create the zip container. It will forward produced bytes to the provided sink.
100
+ const target = new zip(sink);
101
+ // Save the root content types part.
102
+ // In OPC, [Content_Types].xml defines the MIME/content types for the package parts.
103
+ serializeEntry(target, ContentTypeFileName, doc.contentTypes);
104
+ // Save relationships.
105
+ // In OPC, relationships live under _rels and map parts to each other.
106
+ serializeEntry(target, `${RelationshipDirName}${RelationshipFileName}`, doc.relationships);
107
+ // Save the 3D model part.
108
+ // In 3MF, the main model is typically under /3D/3dmodel.model.
109
+ serializeEntry(target, `${Object3dDirName}${ModelFileName}`, doc.model);
110
+ // Finalize the archive stream.
111
+ // This should trigger the zip implementation to call sink(..., final=true) when done.
112
+ target.end();
113
+ }
114
+ /**
115
+ * Build a full 3MF OPC document from meshes.
116
+ *
117
+ * The default behavior uses ThreeMfDocumentBuilder with the model produced by toModel().
118
+ * Override if you need custom parts (textures, thumbnails, print ticket, etc.).
119
+ * @param meshes
120
+ * @returns
121
+ */
122
+ toDocument(...meshes) {
123
+ const b = new ThreeMfModelBuilder().withUnit(this._o?.unit ?? ST_Unit.millimeter);
124
+ if (this.options.metadata) {
125
+ for (const m in this.options.metadata) {
126
+ b.withMetaData(m, this.options.metadata[m]);
127
+ }
128
+ }
129
+ return new ThreeMfDocumentBuilder().withModel(this.toModel(b, ...meshes)).build();
130
+ }
131
+ }
132
+ /**
133
+ * Convenience helpers around serializers.
134
+ */
135
+ export class ThreeMf {
136
+ /**
137
+ * Serialize to a single in-memory buffer.
138
+ *
139
+ * This is a helper that buffers all chunks produced by serializeAsync, then concatenates them.
140
+ * Use serializeAsync directly if you want true streaming to a file/response.
141
+ * @param s
142
+ * @param meshes
143
+ * @returns
144
+ */
145
+ static async SerializeToMemoryAsync(s, ...meshes) {
146
+ const chunks = new Array();
147
+ let size = 0;
148
+ // Sink used by the zip stream. We ignore `final` because we buffer everything anyway.
149
+ // If `err` is used by the underlying zip lib, callers may want to detect/throw here.
150
+ const sink = function (err, chunk, _final) {
151
+ // Current behavior: ignore err and keep accumulating.
152
+ // Consider: if err is non-null, you might want to throw or record it.
153
+ chunks.push(chunk);
154
+ size += chunk.length;
155
+ };
156
+ await s.serializeAsync(sink, ...meshes);
157
+ // If nothing was written, return undefined (matches current behavior).
158
+ if (!size) {
159
+ return undefined;
160
+ }
161
+ // Concatenate chunks into a single Uint8Array.
162
+ const buffer = new Uint8Array(size);
163
+ let off = 0;
164
+ for (const c of chunks) {
165
+ buffer.set(c, off);
166
+ off += c.length;
167
+ }
168
+ return buffer;
169
+ }
170
+ }
171
+ //# sourceMappingURL=3mf.serializer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"3mf.serializer.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/3MF/core/model/3mf.serializer.ts"],"names":[],"mappings":"AAAA,MAAM;AACN,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAC5E,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,eAAe,EAAE,mBAAmB,EAAE,oBAAoB,EAAqB,MAAM,sBAAsB,CAAC;AAEzJ,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,MAAM;AACN,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAiB,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAqC/E;;;;;;;;;;GAUG;AACH,MAAM,OAAgB,yBAAyB;IAG3C;;OAEG;IACH,YAAmB,IAAO;QACtB,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC;IACnB,CAAC;IAED;;OAEG;IACH,IAAW,OAAO;QACd,OAAO,IAAI,CAAC,EAAE,CAAC;IACnB,CAAC;IAED;;;;;;;;;;;OAWG;IACI,KAAK,CAAC,cAAc,CAAC,IAA2D,EAAE,GAAG,MAAgB;QACxG,uFAAuF;QACvF,+DAA+D;QAC/D,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,sBAAsB,EAAE,CAAC;QAEhD,wDAAwD;QACxD,4FAA4F;QAC5F,IAAI,CA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C,KAAK,CAAC,sBAAsB,CAAI,CAAoB,EAAE,GAAG,MAAgB;QACnF,MAAM,MAAM,GAAG,IAAI,KAAK,EAAc,CAAC;QACvC,IAAI,IAAI,GAAG,CAAC,CAAC;QAEb,sFAAsF;QACtF,qFAAqF;QACrF,MAAM,IAAI,GAAG,UAAU,GAAQ,EAAE,KAAiB,EAAE,MAAe;YAC/D,sDAAsD;YACtD,sEAAsE;YACtE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACnB,IAAI,IAAI,KAAK,CAAC,MAAM,CAAC;QACzB,CAAC,CAAC;QAEF,MAAM,CAAC,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,MAAM,CAAC,CAAC;QAExC,uEAAuE;QACvE,IAAI,CAAC,IAAI,EAAE,CAAC;YACR,OAAO,SAAS,CAAC;QACrB,CAAC;QAED,+CAA+C;QAC/C,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC;QACpC,IAAI,GAAG,GAAG,CAAC,CAAC;QACZ,KAAK,MAAM,CAAC,IAAI,MAAM,EAAE,CAAC;YACrB,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;YACnB,GAAG,IAAI,CAAC,CAAC,MAAM,CAAC;QACpB,CAAC;QACD,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ","sourcesContent":["// 3MF\r\nimport { ThreeMfDocumentBuilder, ThreeMfModelBuilder } from \"./3mf.builder\";\r\nimport { ContentTypeFileName, ModelFileName, Object3dDirName, RelationshipDirName, RelationshipFileName, type I3mfDocument } from \"./3mf.opc.interfaces\";\r\nimport type { I3mfModel } from \"./3mf.interfaces\";\r\nimport { ST_Unit } from \"./3mf.interfaces\";\r\n\r\n// XML\r\nimport { XmlBuilder } from \"../xml/xml.builder\";\r\nimport { XmlSerializer } from \"../xml/xml.serializer\";\r\nimport { type ByteSink, Utf8XmlWriterToBytes } from \"../xml/xml.builder.bytes\";\r\n\r\n/**\r\n * Options controlling how meshes are exported into the 3MF model.\r\n *\r\n * Notes:\r\n * - These flags are kept generic here and are expected to be interpreted by the concrete serializer/model builder.\r\n * - Defaults are set in AbstractThreeMfSerializer.DEFAULT_3MF_EXPORTER_OPTIONS.\r\n */\r\nexport interface IThreeMfSerializerOptions {\r\n /**\r\n * define the unit. Default is millimeter\r\n */\r\n unit?: ST_Unit;\r\n\r\n /**\r\n *\r\n */\r\n metadata?: Record<string, string>;\r\n}\r\n\r\n/**\r\n * Minimal contract for a 3MF serializer that can stream its output through a sink callback.\r\n *\r\n * The sink callback receives:\r\n * - err: any error produced by the serialization pipeline (if any)\r\n * - chunk: a chunk of bytes to append to the destination\r\n * - final: true when this is the last chunk\r\n *\r\n * Important:\r\n * - Implementations should call sink with final=true exactly once, or rely on the underlying zip lib to do so.\r\n * - Consumers may ignore final if they just buffer everything.\r\n */\r\nexport interface I3mfSerializer<T> {\r\n serializeAsync(sink: (err: any, chunk: Uint8Array, final: boolean) => void, ...meshes: Array<T>): Promise<void>;\r\n}\r\n\r\n/**\r\n * Base class for 3MF serialization.\r\n *\r\n * Responsibilities:\r\n * - Convert user meshes to a 3MF model (toModel).\r\n * - Wrap the 3MF document parts into an OPC container (zip) and stream bytes through the sink.\r\n *\r\n * Non-responsibilities:\r\n * - Providing/initializing the zip implementation (ensureZipLibReadyAsync is abstract).\r\n * - Defining how meshes map to 3MF objects (toModel is abstract).\r\n */\r\nexport abstract class AbstractThreeMfSerializer<T, O extends IThreeMfSerializerOptions> implements I3mfSerializer<T> {\r\n private _o: O;\r\n\r\n /**\r\n * @param opts user-provided options overriding defaults.\r\n */\r\n public constructor(opts: O) {\r\n this._o = opts;\r\n }\r\n\r\n /**\r\n * Expose the resolved options (defaults + overrides) as readonly.\r\n */\r\n public get options(): Readonly<O> {\r\n return this._o;\r\n }\r\n\r\n /**\r\n * Generic 3MF binary serializer.\r\n * Pipeline overview:\r\n * 1. ensureZipLibReadyAsync provides a zip implementation (host-dependent).\r\n * 2. Convert meshes into an I3mfDocument (OPC parts + model).\r\n * 3. Create a zip target that streams through the provided sink.\r\n * 4. Serialize XML parts into zip entries.\r\n * 5. End the zip stream.\r\n * @param sink a callback receiving byte chunks; enables streaming without buffering the full archive in memory.\r\n * @param meshes the meshes to serialize.\r\n * @returns\r\n */\r\n public async serializeAsync(sink: (err: any, chunk: Uint8Array, final: boolean) => void, ...meshes: Array<T>): Promise<void> {\r\n // The zip library (e.g. fflate) may need dynamic import / polyfills depending on host.\r\n // This is delegated to the concrete serializer implementation.\r\n const lib = await this.ensureZipLibReadyAsync();\r\n\r\n // If no lib is available, we silently do nothing today.\r\n // Consider: throwing could be better to fail fast. Kept as-is to preserve current behavior.\r\n if (!lib) {\r\n return;\r\n }\r\n\r\n const zip = lib.Zip;\r\n const zipDeflate = lib.ZipDeflate;\r\n\r\n // We expect a \"fflate-like\" API. If it is missing, fail with an explicit error.\r\n if (!zip || !zipDeflate) {\r\n throw new Error(\"fflate Zip / ZipDeflate not available\");\r\n }\r\n\r\n /**\r\n * Adapt a fflate entry to our ByteSink interface used by Utf8XmlWriterToBytes.\r\n *\r\n * fflate entry.push(chunk, final) is the writer endpoint for compressed bytes.\r\n * @param entry\r\n * @returns\r\n */\r\n const makeByteSinkFromFflateEntry = function (entry: any): ByteSink {\r\n return { push: (chunk: any, final: any) => entry.push(chunk, final) };\r\n };\r\n\r\n /**\r\n * Serialize an in-memory XML object into a compressed zip entry.\r\n *\r\n * Notes:\r\n * - \"object\" here is expected to be a structure understood by XmlSerializer.\r\n * - Compression level 6 is a reasonable default for speed/size tradeoff.\r\n * @param target\r\n * @param name\r\n * @param object\r\n */\r\n const serializeEntry = function (target: any, name: string, object: any): void {\r\n const entry = new zipDeflate(name, { level: 6 });\r\n target.add(entry);\r\n\r\n // Convert XmlSerializer output into UTF-8 bytes and push to the zip entry.\r\n const sink = makeByteSinkFromFflateEntry(entry);\r\n const w = new Utf8XmlWriterToBytes(sink);\r\n\r\n // Build XML declaration and serialize.\r\n const b = new XmlBuilder(w).dec(\"1.0\", \"UTF-8\");\r\n const s = new XmlSerializer(b);\r\n s.serialize(object);\r\n\r\n // Ensure the writer flushes any pending bytes and closes the stream for this entry.\r\n w.finish();\r\n };\r\n\r\n // Convert meshes into a 3MF document (content types + relationships + model part).\r\n const doc = this.toDocument(...meshes);\r\n if (!doc) {\r\n // Nothing to write. Current behavior: no zip output.\r\n return;\r\n }\r\n\r\n // Create the zip container. It will forward produced bytes to the provided sink.\r\n const target = new zip(sink);\r\n\r\n // Save the root content types part.\r\n // In OPC, [Content_Types].xml defines the MIME/content types for the package parts.\r\n serializeEntry(target, ContentTypeFileName, doc.contentTypes);\r\n\r\n // Save relationships.\r\n // In OPC, relationships live under _rels and map parts to each other.\r\n serializeEntry(target, `${RelationshipDirName}${RelationshipFileName}`, doc.relationships);\r\n\r\n // Save the 3D model part.\r\n // In 3MF, the main model is typically under /3D/3dmodel.model.\r\n serializeEntry(target, `${Object3dDirName}${ModelFileName}`, doc.model);\r\n\r\n // Finalize the archive stream.\r\n // This should trigger the zip implementation to call sink(..., final=true) when done.\r\n target.end();\r\n }\r\n\r\n /**\r\n * Build a full 3MF OPC document from meshes.\r\n *\r\n * The default behavior uses ThreeMfDocumentBuilder with the model produced by toModel().\r\n * Override if you need custom parts (textures, thumbnails, print ticket, etc.).\r\n * @param meshes\r\n * @returns\r\n */\r\n public toDocument(...meshes: Array<T>): I3mfDocument | undefined {\r\n const b = new ThreeMfModelBuilder().withUnit(this._o?.unit ?? ST_Unit.millimeter);\r\n if (this.options.metadata) {\r\n for (const m in this.options.metadata) {\r\n b.withMetaData(m, this.options.metadata[m]);\r\n }\r\n }\r\n return new ThreeMfDocumentBuilder().withModel(this.toModel(b, ...meshes)).build();\r\n }\r\n\r\n /**\r\n * Convert input meshes into a 3MF model.\r\n *\r\n * Implementations typically:\r\n * - Create resources and objects.\r\n * - Define build items (instances) when exportInstances is enabled.\r\n * - Encode geometry and properties required by your pipeline.\r\n */\r\n public abstract toModel(builder: ThreeMfModelBuilder, ...meshes: Array<T>): I3mfModel;\r\n\r\n /**\r\n * Provide a zip implementation for the current host/runtime.\r\n *\r\n * This might be provided by the framework implementation, but it could differ depending on the host\r\n * (native, Node.js, browser, etc.).\r\n *\r\n * Expected shape (fflate-like):\r\n * - return [ Zip, ZipDeflate ] at minimum.\r\n *\r\n * Notes:\r\n * - In a browser, this might require bundler configuration or dynamic import.\r\n * - In Node.js, this might be a direct import of \"fflate\" or another compatible implementation.\r\n */\r\n public abstract ensureZipLibReadyAsync(): Promise<any>;\r\n}\r\n\r\n/**\r\n * Convenience helpers around serializers.\r\n */\r\nexport class ThreeMf {\r\n /**\r\n * Serialize to a single in-memory buffer.\r\n *\r\n * This is a helper that buffers all chunks produced by serializeAsync, then concatenates them.\r\n * Use serializeAsync directly if you want true streaming to a file/response.\r\n * @param s\r\n * @param meshes\r\n * @returns\r\n */\r\n public static async SerializeToMemoryAsync<A>(s: I3mfSerializer<A>, ...meshes: Array<A>): Promise<Uint8Array | undefined> {\r\n const chunks = new Array<Uint8Array>();\r\n let size = 0;\r\n\r\n // Sink used by the zip stream. We ignore `final` because we buffer everything anyway.\r\n // If `err` is used by the underlying zip lib, callers may want to detect/throw here.\r\n const sink = function (err: any, chunk: Uint8Array, _final: boolean) {\r\n // Current behavior: ignore err and keep accumulating.\r\n // Consider: if err is non-null, you might want to throw or record it.\r\n chunks.push(chunk);\r\n size += chunk.length;\r\n };\r\n\r\n await s.serializeAsync(sink, ...meshes);\r\n\r\n // If nothing was written, return undefined (matches current behavior).\r\n if (!size) {\r\n return undefined;\r\n }\r\n\r\n // Concatenate chunks into a single Uint8Array.\r\n const buffer = new Uint8Array(size);\r\n let off = 0;\r\n for (const c of chunks) {\r\n buffer.set(c, off);\r\n off += c.length;\r\n }\r\n return buffer;\r\n }\r\n}\r\n"]}
@@ -0,0 +1,46 @@
1
+ /** Alias type for number array or Float32Array */
2
+ export type ThreeMfFloatArray = number[] | Float32Array;
3
+ /** Alias type for number array or Float32Array or Int32Array or Uint32Array or Uint16Array */
4
+ export type ThreeMfIndicesArray = number[] | Int32Array | Uint32Array | Uint16Array;
5
+ /**
6
+ * Interface used to define object data independaly of framework
7
+ */
8
+ export interface I3mfVertexData {
9
+ /**
10
+ * An array of the x, y, z position of each vertex [...., x, y, z, .....]
11
+ */
12
+ positions: ThreeMfFloatArray | null;
13
+ /**
14
+ * An array of i, j, k the three vertex indices required for each triangular facet [...., i, j, k .....]
15
+ */
16
+ indices: ThreeMfIndicesArray | null;
17
+ /**
18
+ * An array of the x, y, z normal vector of each vertex [...., x, y, z, .....]
19
+ */
20
+ normals?: ThreeMfFloatArray | null;
21
+ /**
22
+ * An array of the r, g, b, a, color of each vertex [...., r, g, b, a, .....]
23
+ */
24
+ colors?: ThreeMfFloatArray | null;
25
+ }
26
+ /**
27
+ * interface used to abstact rgb colors from any framework.
28
+ */
29
+ export interface I3mfRGBAColor {
30
+ /**
31
+ *
32
+ */
33
+ r: number;
34
+ /**
35
+ *
36
+ */
37
+ g: number;
38
+ /**
39
+ *
40
+ */
41
+ b: number;
42
+ /**
43
+ *
44
+ */
45
+ a?: number;
46
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=3mf.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"3mf.types.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/3MF/core/model/3mf.types.ts"],"names":[],"mappings":"","sourcesContent":["/** Alias type for number array or Float32Array */\r\nexport type ThreeMfFloatArray = number[] | Float32Array;\r\n/** Alias type for number array or Float32Array or Int32Array or Uint32Array or Uint16Array */\r\nexport type ThreeMfIndicesArray = number[] | Int32Array | Uint32Array | Uint16Array;\r\n\r\n/**\r\n * Interface used to define object data independaly of framework\r\n */\r\nexport interface I3mfVertexData {\r\n /**\r\n * An array of the x, y, z position of each vertex [...., x, y, z, .....]\r\n */\r\n positions: ThreeMfFloatArray | null;\r\n /**\r\n * An array of i, j, k the three vertex indices required for each triangular facet [...., i, j, k .....]\r\n */\r\n indices: ThreeMfIndicesArray | null;\r\n /**\r\n * An array of the x, y, z normal vector of each vertex [...., x, y, z, .....]\r\n */\r\n normals?: ThreeMfFloatArray | null;\r\n /**\r\n * An array of the r, g, b, a, color of each vertex [...., r, g, b, a, .....]\r\n */\r\n colors?: ThreeMfFloatArray | null;\r\n}\r\n\r\n/**\r\n * interface used to abstact rgb colors from any framework.\r\n */\r\nexport interface I3mfRGBAColor {\r\n /**\r\n *\r\n */\r\n r: number;\r\n /**\r\n *\r\n */\r\n g: number;\r\n /**\r\n *\r\n */\r\n b: number;\r\n /**\r\n *\r\n */\r\n a?: number;\r\n}\r\n"]}
@@ -0,0 +1,7 @@
1
+ export * from "./3mf.interfaces.js";
2
+ export * from "./3mf.opc.interfaces.js";
3
+ export * from "./3mf.opc.js";
4
+ export * from "./3mf.js";
5
+ export * from "./3mf.builder.js";
6
+ export * from "./3mf.types.js";
7
+ export * from "./3mf.serializer.js";
@@ -0,0 +1,8 @@
1
+ export * from "./3mf.interfaces.js";
2
+ export * from "./3mf.opc.interfaces.js";
3
+ export * from "./3mf.opc.js";
4
+ export * from "./3mf.js";
5
+ export * from "./3mf.builder.js";
6
+ export * from "./3mf.types.js";
7
+ export * from "./3mf.serializer.js";
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/3MF/core/model/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,WAAW,CAAC;AAC1B,cAAc,OAAO,CAAC;AACtB,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC","sourcesContent":["export * from \"./3mf.interfaces\";\r\nexport * from \"./3mf.opc.interfaces\";\r\nexport * from \"./3mf.opc\";\r\nexport * from \"./3mf\";\r\nexport * from \"./3mf.builder\";\r\nexport * from \"./3mf.types\";\r\nexport * from \"./3mf.serializer\";\r\n"]}
@@ -0,0 +1,6 @@
1
+ export * from "./xml.interfaces.js";
2
+ export * from "./xml.serializer.js";
3
+ export * from "./xml.serializer.format.js";
4
+ export * from "./xml.builder.js";
5
+ export * from "./xml.builder.string.js";
6
+ export * from "./xml.builder.bytes.js";
@@ -0,0 +1,7 @@
1
+ export * from "./xml.interfaces.js";
2
+ export * from "./xml.serializer.js";
3
+ export * from "./xml.serializer.format.js";
4
+ export * from "./xml.builder.js";
5
+ export * from "./xml.builder.string.js";
6
+ export * from "./xml.builder.bytes.js";
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/3MF/core/xml/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,yBAAyB,CAAC;AACxC,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC","sourcesContent":["export * from \"./xml.interfaces\";\r\nexport * from \"./xml.serializer\";\r\nexport * from \"./xml.serializer.format\";\r\nexport * from \"./xml.builder\";\r\nexport * from \"./xml.builder.string\";\r\nexport * from \"./xml.builder.bytes\";\r\n"]}
@@ -0,0 +1,33 @@
1
+ import type { IXmlWriter } from "./xml.builder.js";
2
+ /** */
3
+ export type ByteSink = {
4
+ push(chunk: Uint8Array, final?: boolean): void;
5
+ };
6
+ /** */
7
+ export declare class Utf8XmlWriterToBytes implements IXmlWriter {
8
+ private readonly _sink;
9
+ private readonly _opts;
10
+ /** */
11
+ count: number;
12
+ private _encoder;
13
+ private _pending;
14
+ private _pendingChars;
15
+ constructor(_sink: ByteSink, _opts?: {
16
+ flushChars?: number;
17
+ });
18
+ /**
19
+ * @param data
20
+ * @returns
21
+ */
22
+ write(...data: string[]): IXmlWriter;
23
+ /**
24
+ * @returns
25
+ */
26
+ flush(): this;
27
+ /**
28
+ */
29
+ finish(): void;
30
+ /**
31
+ */
32
+ clear(): void;
33
+ }