lbrnts 0.0.1 → 0.0.2

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/index.d.ts CHANGED
@@ -15,6 +15,20 @@ declare class LightBurnBaseElement {
15
15
  token: string;
16
16
  static token: string;
17
17
  getChildren(): LightBurnBaseElement[];
18
+ /**
19
+ * Get XML attributes for this element
20
+ * Subclasses should override this to provide their specific attributes
21
+ */
22
+ getXmlAttributes(): Record<string, string | number | boolean | undefined>;
23
+ /**
24
+ * Get the XML tag name for this element
25
+ * By default, uses the token, but can be overridden
26
+ */
27
+ getXmlTag(): string;
28
+ /**
29
+ * Convert this element to XML string
30
+ */
31
+ toXml(indent?: number): string;
18
32
  getStringIndented(): string;
19
33
  getString(): string;
20
34
  get [Symbol.toStringTag](): string;
@@ -51,6 +65,7 @@ declare class LightBurnProject extends LightBurnBaseElement {
51
65
  constructor(init?: LightBurnProjectInit);
52
66
  static fromXmlJson(node: XmlJsonElement): LightBurnProject;
53
67
  getChildren(): LightBurnBaseElement[];
68
+ getXmlAttributes(): Record<string, string | number | boolean | undefined>;
54
69
  }
55
70
 
56
71
  interface CutSettingInit {
@@ -145,6 +160,8 @@ declare class CutSetting extends LightBurnBaseElement {
145
160
  set overScanning(value: number | undefined);
146
161
  get lineAngle(): number | undefined;
147
162
  set lineAngle(value: number | undefined);
163
+ getXmlAttributes(): Record<string, string | number | boolean | undefined>;
164
+ getChildren(): LightBurnBaseElement[];
148
165
  static fromXmlJson(node: XmlJsonElement): CutSetting;
149
166
  }
150
167
 
@@ -189,6 +206,8 @@ declare abstract class ShapeBase extends LightBurnBaseElement {
189
206
  cutIndex?: number;
190
207
  locked?: boolean;
191
208
  xform?: Mat;
209
+ protected getShapeXmlAttributes(): Record<string, string | number | boolean | undefined>;
210
+ getChildren(): LightBurnBaseElement[];
192
211
  static readCommon(node: XmlJsonElement): {
193
212
  cutIndex?: number;
194
213
  locked?: boolean;
@@ -208,6 +227,7 @@ declare class ShapeRect extends ShapeBase {
208
227
  h?: number;
209
228
  cr?: number;
210
229
  constructor();
230
+ getXmlAttributes(): Record<string, string | number | boolean | undefined>;
211
231
  static fromXmlJson(node: XmlJsonElement): ShapeRect;
212
232
  }
213
233
 
@@ -238,6 +258,8 @@ declare class ShapePath extends ShapeBase {
238
258
  private static templateRegistry;
239
259
  constructor(init?: ShapePathInit);
240
260
  static clearTemplateRegistry(): void;
261
+ getXmlAttributes(): Record<string, string | number | boolean | undefined>;
262
+ getChildren(): LightBurnBaseElement[];
241
263
  static fromXmlJson(node: XmlJsonElement): ShapePath;
242
264
  /**
243
265
  * Parse encoded VertList string format
package/dist/index.js CHANGED
@@ -45,21 +45,62 @@ var LightBurnBaseElement = class _LightBurnBaseElement {
45
45
  getChildren() {
46
46
  return [];
47
47
  }
48
- getStringIndented() {
49
- return this.getString().split("\n").map((line) => ` ${line}`).join("\n");
48
+ /**
49
+ * Get XML attributes for this element
50
+ * Subclasses should override this to provide their specific attributes
51
+ */
52
+ getXmlAttributes() {
53
+ return {};
50
54
  }
51
- getString() {
55
+ /**
56
+ * Get the XML tag name for this element
57
+ * By default, uses the token, but can be overridden
58
+ */
59
+ getXmlTag() {
60
+ if (this.token.startsWith("Shape.")) {
61
+ return "Shape";
62
+ }
63
+ return this.token;
64
+ }
65
+ /**
66
+ * Convert this element to XML string
67
+ */
68
+ toXml(indent = 0) {
69
+ const indentStr = " ".repeat(indent);
70
+ const tag = this.getXmlTag();
71
+ const attrs = this.getXmlAttributes();
72
+ const attrPairs = [];
73
+ for (const [key, value] of Object.entries(attrs)) {
74
+ if (value !== void 0 && value !== null) {
75
+ if (typeof value === "boolean") {
76
+ attrPairs.push(`${key}="${value ? "True" : "False"}"`);
77
+ } else {
78
+ attrPairs.push(`${key}="${value}"`);
79
+ }
80
+ }
81
+ }
82
+ const attrStr = attrPairs.length > 0 ? " " + attrPairs.join(" ") : "";
52
83
  const children = this.getChildren();
53
84
  if (children.length === 0) {
54
- return `(${this.token})`;
85
+ return `${indentStr}<${tag}${attrStr}/>`;
55
86
  }
56
- const lines = [`(${this.token}`];
57
- for (const p of children) {
58
- lines.push(p.getStringIndented());
87
+ const lines = [`${indentStr}<${tag}${attrStr}>`];
88
+ for (const child of children) {
89
+ lines.push(child.toXml(indent + 1));
59
90
  }
60
- lines.push(")");
91
+ lines.push(`${indentStr}</${tag}>`);
61
92
  return lines.join("\n");
62
93
  }
94
+ getStringIndented() {
95
+ return this.getString().split("\n").map((line) => ` ${line}`).join("\n");
96
+ }
97
+ getString() {
98
+ if (this.token === "LightBurnProject") {
99
+ return `<?xml version="1.0" encoding="UTF-8"?>
100
+ ${this.toXml()}`;
101
+ }
102
+ return this.toXml();
103
+ }
63
104
  get [Symbol.toStringTag]() {
64
105
  return this.getString();
65
106
  }
@@ -216,6 +257,15 @@ var LightBurnProject = class _LightBurnProject extends LightBurnBaseElement {
216
257
  getChildren() {
217
258
  return this.children;
218
259
  }
260
+ getXmlAttributes() {
261
+ return {
262
+ AppVersion: this.appVersion,
263
+ FormatVersion: this.formatVersion,
264
+ MaterialHeight: this.materialHeight,
265
+ MirrorX: this.mirrorX,
266
+ MirrorY: this.mirrorY
267
+ };
268
+ }
219
269
  };
220
270
  LightBurnBaseElement.register("LightBurnProject", LightBurnProject);
221
271
 
@@ -405,6 +455,44 @@ var CutSetting = class _CutSetting extends LightBurnBaseElement {
405
455
  set lineAngle(value) {
406
456
  this._lineAngle = value;
407
457
  }
458
+ getXmlAttributes() {
459
+ return {
460
+ type: this._type
461
+ };
462
+ }
463
+ getChildren() {
464
+ const children = [];
465
+ const props = [
466
+ "index",
467
+ "name",
468
+ "priority",
469
+ "minPower",
470
+ "maxPower",
471
+ "minPower2",
472
+ "maxPower2",
473
+ "speed",
474
+ "kerf",
475
+ "zOffset",
476
+ "enablePowerRamp",
477
+ "rampLength",
478
+ "numPasses",
479
+ "zPerPass",
480
+ "perforate",
481
+ "dotMode",
482
+ "scanOpt",
483
+ "interval",
484
+ "angle",
485
+ "overScanning",
486
+ "lineAngle"
487
+ ];
488
+ for (const prop of props) {
489
+ const value = this[`_${prop}`];
490
+ if (value !== void 0) {
491
+ children.push(new CutSettingPropertyElement(prop, value));
492
+ }
493
+ }
494
+ return children;
495
+ }
408
496
  static fromXmlJson(node) {
409
497
  const cs = new _CutSetting();
410
498
  if (node.$) {
@@ -438,6 +526,20 @@ var CutSetting = class _CutSetting extends LightBurnBaseElement {
438
526
  return cs;
439
527
  }
440
528
  };
529
+ var CutSettingPropertyElement = class extends LightBurnBaseElement {
530
+ propName;
531
+ propValue;
532
+ constructor(propName, propValue) {
533
+ super();
534
+ this.token = propName;
535
+ this.propName = propName;
536
+ this.propValue = propValue;
537
+ }
538
+ toXml(indent = 0) {
539
+ const indentStr = " ".repeat(indent);
540
+ return `${indentStr}<${this.propName} Value="${this.propValue}"/>`;
541
+ }
542
+ };
441
543
  LightBurnBaseElement.register("CutSetting", CutSetting);
442
544
 
443
545
  // lib/classes/elements/Notes.ts
@@ -536,6 +638,20 @@ var ShapeBase = class extends LightBurnBaseElement {
536
638
  cutIndex;
537
639
  locked;
538
640
  xform;
641
+ getShapeXmlAttributes() {
642
+ return {
643
+ CutIndex: this.cutIndex,
644
+ Locked: this.locked
645
+ };
646
+ }
647
+ getChildren() {
648
+ const children = [];
649
+ if (this.xform) {
650
+ const xformElement = new XFormElement(this.xform);
651
+ children.push(xformElement);
652
+ }
653
+ return children;
654
+ }
539
655
  static readCommon(node) {
540
656
  const common = {};
541
657
  if (node.$) {
@@ -559,6 +675,19 @@ var ShapeBase = class extends LightBurnBaseElement {
559
675
  return common;
560
676
  }
561
677
  };
678
+ var XFormElement = class extends LightBurnBaseElement {
679
+ mat;
680
+ constructor(mat) {
681
+ super();
682
+ this.token = "XForm";
683
+ this.mat = mat;
684
+ }
685
+ toXml(indent = 0) {
686
+ const indentStr = " ".repeat(indent);
687
+ const value = this.mat.join(" ");
688
+ return `${indentStr}<XForm>${value}</XForm>`;
689
+ }
690
+ };
562
691
 
563
692
  // lib/classes/elements/shapes/ShapeEllipse.ts
564
693
  var ShapeEllipse = class _ShapeEllipse extends ShapeBase {
@@ -590,6 +719,15 @@ var ShapeRect = class _ShapeRect extends ShapeBase {
590
719
  super();
591
720
  this.token = "Shape.Rect";
592
721
  }
722
+ getXmlAttributes() {
723
+ return {
724
+ Type: "Rect",
725
+ ...this.getShapeXmlAttributes(),
726
+ W: this.w,
727
+ H: this.h,
728
+ Cr: this.cr
729
+ };
730
+ }
593
731
  static fromXmlJson(node) {
594
732
  const rect = new _ShapeRect();
595
733
  const common = ShapeBase.readCommon(node);
@@ -627,6 +765,22 @@ var ShapePath = class _ShapePath extends ShapeBase {
627
765
  static clearTemplateRegistry() {
628
766
  _ShapePath.templateRegistry.clear();
629
767
  }
768
+ getXmlAttributes() {
769
+ return {
770
+ Type: "Path",
771
+ ...this.getShapeXmlAttributes()
772
+ };
773
+ }
774
+ getChildren() {
775
+ const children = super.getChildren();
776
+ if (this.verts.length > 0) {
777
+ children.push(new VertListElement(this.verts));
778
+ }
779
+ if (this.prims.length > 0) {
780
+ children.push(new PrimListElement(this.prims, this.isClosed));
781
+ }
782
+ return children;
783
+ }
630
784
  static fromXmlJson(node) {
631
785
  const path = new _ShapePath();
632
786
  const common = ShapeBase.readCommon(node);
@@ -642,11 +796,16 @@ var ShapePath = class _ShapePath extends ShapeBase {
642
796
  const verts = Array.isArray(vertList.Vert) ? vertList.Vert : [vertList.Vert];
643
797
  for (const v of verts) {
644
798
  if (v.$) {
645
- path.verts.push({
799
+ const vert = {
646
800
  x: num(v.$.x, 0),
647
801
  y: num(v.$.y, 0),
648
802
  c: num(v.$.c, void 0)
649
- });
803
+ };
804
+ if (v.$.c0x !== void 0) vert.c0x = num(v.$.c0x, void 0);
805
+ if (v.$.c0y !== void 0) vert.c0y = num(v.$.c0y, void 0);
806
+ if (v.$.c1x !== void 0) vert.c1x = num(v.$.c1x, void 0);
807
+ if (v.$.c1y !== void 0) vert.c1y = num(v.$.c1y, void 0);
808
+ path.verts.push(vert);
650
809
  }
651
810
  }
652
811
  }
@@ -771,6 +930,60 @@ var ShapePath = class _ShapePath extends ShapeBase {
771
930
  return prims;
772
931
  }
773
932
  };
933
+ var VertListElement = class extends LightBurnBaseElement {
934
+ verts;
935
+ constructor(verts) {
936
+ super();
937
+ this.token = "VertList";
938
+ this.verts = verts;
939
+ }
940
+ toXml(indent = 0) {
941
+ const indentStr = " ".repeat(indent);
942
+ const innerIndent = " ".repeat(indent + 1);
943
+ const lines = [`${indentStr}<VertList>`];
944
+ for (const vert of this.verts) {
945
+ let attrs = `x="${vert.x}" y="${vert.y}"`;
946
+ if (vert.c !== void 0) {
947
+ attrs += ` c="${vert.c}"`;
948
+ }
949
+ if (vert.c0x !== void 0) {
950
+ attrs += ` c0x="${vert.c0x}"`;
951
+ }
952
+ if (vert.c0y !== void 0) {
953
+ attrs += ` c0y="${vert.c0y}"`;
954
+ }
955
+ if (vert.c1x !== void 0) {
956
+ attrs += ` c1x="${vert.c1x}"`;
957
+ }
958
+ if (vert.c1y !== void 0) {
959
+ attrs += ` c1y="${vert.c1y}"`;
960
+ }
961
+ lines.push(`${innerIndent}<Vert ${attrs}/>`);
962
+ }
963
+ lines.push(`${indentStr}</VertList>`);
964
+ return lines.join("\n");
965
+ }
966
+ };
967
+ var PrimListElement = class extends LightBurnBaseElement {
968
+ prims;
969
+ isClosed;
970
+ constructor(prims, isClosed) {
971
+ super();
972
+ this.token = "PrimList";
973
+ this.prims = prims;
974
+ this.isClosed = isClosed;
975
+ }
976
+ toXml(indent = 0) {
977
+ const indentStr = " ".repeat(indent);
978
+ const innerIndent = " ".repeat(indent + 1);
979
+ const lines = [`${indentStr}<PrimList>`];
980
+ for (const prim of this.prims) {
981
+ lines.push(`${innerIndent}<Prim type="${prim.type}"/>`);
982
+ }
983
+ lines.push(`${indentStr}</PrimList>`);
984
+ return lines.join("\n");
985
+ }
986
+ };
774
987
  LightBurnBaseElement.register("Shape.Path", ShapePath);
775
988
 
776
989
  // lib/classes/elements/shapes/ShapeText.ts
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "lbrnts",
3
3
  "main": "dist/index.js",
4
4
  "type": "module",
5
- "version": "0.0.1",
5
+ "version": "0.0.2",
6
6
  "files": [
7
7
  "dist"
8
8
  ],