lbrnts 0.0.1 → 0.0.3
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 +24 -2
- package/dist/index.js +229 -13
- package/package.json +1 -1
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
|
|
|
@@ -188,11 +205,13 @@ type Mat = [
|
|
|
188
205
|
declare abstract class ShapeBase extends LightBurnBaseElement {
|
|
189
206
|
cutIndex?: number;
|
|
190
207
|
locked?: boolean;
|
|
191
|
-
xform
|
|
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;
|
|
195
|
-
xform
|
|
214
|
+
xform: Mat;
|
|
196
215
|
};
|
|
197
216
|
}
|
|
198
217
|
|
|
@@ -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
|
-
|
|
49
|
-
|
|
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
|
-
|
|
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
|
|
85
|
+
return `${indentStr}<${tag}${attrStr}/>`;
|
|
55
86
|
}
|
|
56
|
-
const lines = [
|
|
57
|
-
for (const
|
|
58
|
-
lines.push(
|
|
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
|
|
@@ -535,9 +637,25 @@ LightBurnBaseElement.register("Thumbnail", Thumbnail);
|
|
|
535
637
|
var ShapeBase = class extends LightBurnBaseElement {
|
|
536
638
|
cutIndex;
|
|
537
639
|
locked;
|
|
538
|
-
xform;
|
|
640
|
+
xform = [1, 0, 0, 1, 0, 0];
|
|
641
|
+
// Default identity matrix
|
|
642
|
+
getShapeXmlAttributes() {
|
|
643
|
+
return {
|
|
644
|
+
CutIndex: this.cutIndex,
|
|
645
|
+
Locked: this.locked
|
|
646
|
+
};
|
|
647
|
+
}
|
|
648
|
+
getChildren() {
|
|
649
|
+
const children = [];
|
|
650
|
+
const xformElement = new XFormElement(this.xform);
|
|
651
|
+
children.push(xformElement);
|
|
652
|
+
return children;
|
|
653
|
+
}
|
|
539
654
|
static readCommon(node) {
|
|
540
|
-
const common = {
|
|
655
|
+
const common = {
|
|
656
|
+
xform: [1, 0, 0, 1, 0, 0]
|
|
657
|
+
// Default identity matrix
|
|
658
|
+
};
|
|
541
659
|
if (node.$) {
|
|
542
660
|
if (node.$.CutIndex !== void 0) {
|
|
543
661
|
common.cutIndex = num(node.$.CutIndex, void 0);
|
|
@@ -559,6 +677,19 @@ var ShapeBase = class extends LightBurnBaseElement {
|
|
|
559
677
|
return common;
|
|
560
678
|
}
|
|
561
679
|
};
|
|
680
|
+
var XFormElement = class extends LightBurnBaseElement {
|
|
681
|
+
mat;
|
|
682
|
+
constructor(mat) {
|
|
683
|
+
super();
|
|
684
|
+
this.token = "XForm";
|
|
685
|
+
this.mat = mat;
|
|
686
|
+
}
|
|
687
|
+
toXml(indent = 0) {
|
|
688
|
+
const indentStr = " ".repeat(indent);
|
|
689
|
+
const value = this.mat.join(" ");
|
|
690
|
+
return `${indentStr}<XForm>${value}</XForm>`;
|
|
691
|
+
}
|
|
692
|
+
};
|
|
562
693
|
|
|
563
694
|
// lib/classes/elements/shapes/ShapeEllipse.ts
|
|
564
695
|
var ShapeEllipse = class _ShapeEllipse extends ShapeBase {
|
|
@@ -590,6 +721,15 @@ var ShapeRect = class _ShapeRect extends ShapeBase {
|
|
|
590
721
|
super();
|
|
591
722
|
this.token = "Shape.Rect";
|
|
592
723
|
}
|
|
724
|
+
getXmlAttributes() {
|
|
725
|
+
return {
|
|
726
|
+
Type: "Rect",
|
|
727
|
+
...this.getShapeXmlAttributes(),
|
|
728
|
+
W: this.w,
|
|
729
|
+
H: this.h,
|
|
730
|
+
Cr: this.cr
|
|
731
|
+
};
|
|
732
|
+
}
|
|
593
733
|
static fromXmlJson(node) {
|
|
594
734
|
const rect = new _ShapeRect();
|
|
595
735
|
const common = ShapeBase.readCommon(node);
|
|
@@ -627,6 +767,22 @@ var ShapePath = class _ShapePath extends ShapeBase {
|
|
|
627
767
|
static clearTemplateRegistry() {
|
|
628
768
|
_ShapePath.templateRegistry.clear();
|
|
629
769
|
}
|
|
770
|
+
getXmlAttributes() {
|
|
771
|
+
return {
|
|
772
|
+
Type: "Path",
|
|
773
|
+
...this.getShapeXmlAttributes()
|
|
774
|
+
};
|
|
775
|
+
}
|
|
776
|
+
getChildren() {
|
|
777
|
+
const children = super.getChildren();
|
|
778
|
+
if (this.verts.length > 0) {
|
|
779
|
+
children.push(new VertListElement(this.verts));
|
|
780
|
+
}
|
|
781
|
+
if (this.prims.length > 0) {
|
|
782
|
+
children.push(new PrimListElement(this.prims, this.isClosed));
|
|
783
|
+
}
|
|
784
|
+
return children;
|
|
785
|
+
}
|
|
630
786
|
static fromXmlJson(node) {
|
|
631
787
|
const path = new _ShapePath();
|
|
632
788
|
const common = ShapeBase.readCommon(node);
|
|
@@ -642,11 +798,16 @@ var ShapePath = class _ShapePath extends ShapeBase {
|
|
|
642
798
|
const verts = Array.isArray(vertList.Vert) ? vertList.Vert : [vertList.Vert];
|
|
643
799
|
for (const v of verts) {
|
|
644
800
|
if (v.$) {
|
|
645
|
-
|
|
801
|
+
const vert = {
|
|
646
802
|
x: num(v.$.x, 0),
|
|
647
803
|
y: num(v.$.y, 0),
|
|
648
804
|
c: num(v.$.c, void 0)
|
|
649
|
-
}
|
|
805
|
+
};
|
|
806
|
+
if (v.$.c0x !== void 0) vert.c0x = num(v.$.c0x, void 0);
|
|
807
|
+
if (v.$.c0y !== void 0) vert.c0y = num(v.$.c0y, void 0);
|
|
808
|
+
if (v.$.c1x !== void 0) vert.c1x = num(v.$.c1x, void 0);
|
|
809
|
+
if (v.$.c1y !== void 0) vert.c1y = num(v.$.c1y, void 0);
|
|
810
|
+
path.verts.push(vert);
|
|
650
811
|
}
|
|
651
812
|
}
|
|
652
813
|
}
|
|
@@ -771,6 +932,60 @@ var ShapePath = class _ShapePath extends ShapeBase {
|
|
|
771
932
|
return prims;
|
|
772
933
|
}
|
|
773
934
|
};
|
|
935
|
+
var VertListElement = class extends LightBurnBaseElement {
|
|
936
|
+
verts;
|
|
937
|
+
constructor(verts) {
|
|
938
|
+
super();
|
|
939
|
+
this.token = "VertList";
|
|
940
|
+
this.verts = verts;
|
|
941
|
+
}
|
|
942
|
+
toXml(indent = 0) {
|
|
943
|
+
const indentStr = " ".repeat(indent);
|
|
944
|
+
const innerIndent = " ".repeat(indent + 1);
|
|
945
|
+
const lines = [`${indentStr}<VertList>`];
|
|
946
|
+
for (const vert of this.verts) {
|
|
947
|
+
let attrs = `x="${vert.x}" y="${vert.y}"`;
|
|
948
|
+
if (vert.c !== void 0) {
|
|
949
|
+
attrs += ` c="${vert.c}"`;
|
|
950
|
+
}
|
|
951
|
+
if (vert.c0x !== void 0) {
|
|
952
|
+
attrs += ` c0x="${vert.c0x}"`;
|
|
953
|
+
}
|
|
954
|
+
if (vert.c0y !== void 0) {
|
|
955
|
+
attrs += ` c0y="${vert.c0y}"`;
|
|
956
|
+
}
|
|
957
|
+
if (vert.c1x !== void 0) {
|
|
958
|
+
attrs += ` c1x="${vert.c1x}"`;
|
|
959
|
+
}
|
|
960
|
+
if (vert.c1y !== void 0) {
|
|
961
|
+
attrs += ` c1y="${vert.c1y}"`;
|
|
962
|
+
}
|
|
963
|
+
lines.push(`${innerIndent}<Vert ${attrs}/>`);
|
|
964
|
+
}
|
|
965
|
+
lines.push(`${indentStr}</VertList>`);
|
|
966
|
+
return lines.join("\n");
|
|
967
|
+
}
|
|
968
|
+
};
|
|
969
|
+
var PrimListElement = class extends LightBurnBaseElement {
|
|
970
|
+
prims;
|
|
971
|
+
isClosed;
|
|
972
|
+
constructor(prims, isClosed) {
|
|
973
|
+
super();
|
|
974
|
+
this.token = "PrimList";
|
|
975
|
+
this.prims = prims;
|
|
976
|
+
this.isClosed = isClosed;
|
|
977
|
+
}
|
|
978
|
+
toXml(indent = 0) {
|
|
979
|
+
const indentStr = " ".repeat(indent);
|
|
980
|
+
const innerIndent = " ".repeat(indent + 1);
|
|
981
|
+
const lines = [`${indentStr}<PrimList>`];
|
|
982
|
+
for (const prim of this.prims) {
|
|
983
|
+
lines.push(`${innerIndent}<Prim type="${prim.type}"/>`);
|
|
984
|
+
}
|
|
985
|
+
lines.push(`${indentStr}</PrimList>`);
|
|
986
|
+
return lines.join("\n");
|
|
987
|
+
}
|
|
988
|
+
};
|
|
774
989
|
LightBurnBaseElement.register("Shape.Path", ShapePath);
|
|
775
990
|
|
|
776
991
|
// lib/classes/elements/shapes/ShapeText.ts
|
|
@@ -827,7 +1042,8 @@ var ShapeGroup = class _ShapeGroup extends ShapeBase {
|
|
|
827
1042
|
return group;
|
|
828
1043
|
}
|
|
829
1044
|
getChildren() {
|
|
830
|
-
|
|
1045
|
+
const baseChildren = super.getChildren();
|
|
1046
|
+
return [...baseChildren, ...this.children];
|
|
831
1047
|
}
|
|
832
1048
|
};
|
|
833
1049
|
LightBurnBaseElement.register("Shape.Group", ShapeGroup);
|