lbrnts 0.0.2 → 0.0.4
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 +13 -6
- package/dist/index.js +64 -41
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -205,13 +205,13 @@ type Mat = [
|
|
|
205
205
|
declare abstract class ShapeBase extends LightBurnBaseElement {
|
|
206
206
|
cutIndex?: number;
|
|
207
207
|
locked?: boolean;
|
|
208
|
-
xform
|
|
208
|
+
xform: Mat;
|
|
209
209
|
protected getShapeXmlAttributes(): Record<string, string | number | boolean | undefined>;
|
|
210
210
|
getChildren(): LightBurnBaseElement[];
|
|
211
211
|
static readCommon(node: XmlJsonElement): {
|
|
212
212
|
cutIndex?: number;
|
|
213
213
|
locked?: boolean;
|
|
214
|
-
xform
|
|
214
|
+
xform: Mat;
|
|
215
215
|
};
|
|
216
216
|
}
|
|
217
217
|
|
|
@@ -263,15 +263,22 @@ declare class ShapePath extends ShapeBase {
|
|
|
263
263
|
static fromXmlJson(node: XmlJsonElement): ShapePath;
|
|
264
264
|
/**
|
|
265
265
|
* Parse encoded VertList string format
|
|
266
|
-
* Format: V{x} {y}c{flag}
|
|
266
|
+
* Format: V{x} {y}c{flag}c0x{value}c0y{value}c1x{value}c1y{value}
|
|
267
267
|
* Example: V2.1156745 -12.3306c0x1c1x1.5871694c1y-12.3306
|
|
268
268
|
*
|
|
269
269
|
* Control points are encoded as:
|
|
270
|
-
* - c0x{value}c0y{value} = control point 0 (when
|
|
271
|
-
* - c1x{value}c1y{value} = control point 1 (when
|
|
272
|
-
* -
|
|
270
|
+
* - c0x{value}c0y{value} = control point 0 (outgoing handle when this vertex is START of Bezier)
|
|
271
|
+
* - c1x{value}c1y{value} = control point 1 (incoming handle when this vertex is END of Bezier)
|
|
272
|
+
* - c0x1 or c1x1 (value of exactly "1" without corresponding y) = "no handle" marker, not a coordinate
|
|
273
273
|
*/
|
|
274
274
|
static parseEncodedVertList(encoded: string): Vert[];
|
|
275
|
+
/**
|
|
276
|
+
* Parse encoded PrimList string format
|
|
277
|
+
* Format: {type}{fromIdx} {toIdx}{type}{fromIdx} {toIdx}...
|
|
278
|
+
* Example: L0 1B1 2L2 3B3 4
|
|
279
|
+
* where L = Line (type 0), B = Bezier (type 1)
|
|
280
|
+
*/
|
|
281
|
+
static parseEncodedPrimList(encoded: string): Prim[];
|
|
275
282
|
/**
|
|
276
283
|
* Parse encoded PrimPolyline string format
|
|
277
284
|
* This typically contains line-to commands, each prim is type 0 (LineTo)
|
package/dist/index.js
CHANGED
|
@@ -637,7 +637,8 @@ LightBurnBaseElement.register("Thumbnail", Thumbnail);
|
|
|
637
637
|
var ShapeBase = class extends LightBurnBaseElement {
|
|
638
638
|
cutIndex;
|
|
639
639
|
locked;
|
|
640
|
-
xform;
|
|
640
|
+
xform = [1, 0, 0, 1, 0, 0];
|
|
641
|
+
// Default identity matrix
|
|
641
642
|
getShapeXmlAttributes() {
|
|
642
643
|
return {
|
|
643
644
|
CutIndex: this.cutIndex,
|
|
@@ -646,14 +647,15 @@ var ShapeBase = class extends LightBurnBaseElement {
|
|
|
646
647
|
}
|
|
647
648
|
getChildren() {
|
|
648
649
|
const children = [];
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
children.push(xformElement);
|
|
652
|
-
}
|
|
650
|
+
const xformElement = new XFormElement(this.xform);
|
|
651
|
+
children.push(xformElement);
|
|
653
652
|
return children;
|
|
654
653
|
}
|
|
655
654
|
static readCommon(node) {
|
|
656
|
-
const common = {
|
|
655
|
+
const common = {
|
|
656
|
+
xform: [1, 0, 0, 1, 0, 0]
|
|
657
|
+
// Default identity matrix
|
|
658
|
+
};
|
|
657
659
|
if (node.$) {
|
|
658
660
|
if (node.$.CutIndex !== void 0) {
|
|
659
661
|
common.cutIndex = num(node.$.CutIndex, void 0);
|
|
@@ -777,7 +779,7 @@ var ShapePath = class _ShapePath extends ShapeBase {
|
|
|
777
779
|
children.push(new VertListElement(this.verts));
|
|
778
780
|
}
|
|
779
781
|
if (this.prims.length > 0) {
|
|
780
|
-
children.push(new PrimListElement(this.prims
|
|
782
|
+
children.push(new PrimListElement(this.prims));
|
|
781
783
|
}
|
|
782
784
|
return children;
|
|
783
785
|
}
|
|
@@ -813,11 +815,15 @@ var ShapePath = class _ShapePath extends ShapeBase {
|
|
|
813
815
|
const primList = node.PrimList;
|
|
814
816
|
if (primList) {
|
|
815
817
|
if (typeof primList === "string") {
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
path.
|
|
818
|
+
if (primList.match(/[LB]\d+\s+\d+/)) {
|
|
819
|
+
path.prims = _ShapePath.parseEncodedPrimList(primList);
|
|
820
|
+
} else if (primList.includes("Line")) {
|
|
821
|
+
const isOpen = primList.includes("Open");
|
|
822
|
+
path.isClosed = !isOpen;
|
|
823
|
+
const primCount = isOpen ? path.verts.length - 1 : path.verts.length;
|
|
824
|
+
for (let i = 0; i < primCount; i++) {
|
|
825
|
+
path.prims.push({ type: 0 });
|
|
826
|
+
}
|
|
821
827
|
}
|
|
822
828
|
} else if (primList.Prim) {
|
|
823
829
|
const prims = Array.isArray(primList.Prim) ? primList.Prim : [primList.Prim];
|
|
@@ -856,13 +862,13 @@ var ShapePath = class _ShapePath extends ShapeBase {
|
|
|
856
862
|
}
|
|
857
863
|
/**
|
|
858
864
|
* Parse encoded VertList string format
|
|
859
|
-
* Format: V{x} {y}c{flag}
|
|
865
|
+
* Format: V{x} {y}c{flag}c0x{value}c0y{value}c1x{value}c1y{value}
|
|
860
866
|
* Example: V2.1156745 -12.3306c0x1c1x1.5871694c1y-12.3306
|
|
861
867
|
*
|
|
862
868
|
* Control points are encoded as:
|
|
863
|
-
* - c0x{value}c0y{value} = control point 0 (when
|
|
864
|
-
* - c1x{value}c1y{value} = control point 1 (when
|
|
865
|
-
* -
|
|
869
|
+
* - c0x{value}c0y{value} = control point 0 (outgoing handle when this vertex is START of Bezier)
|
|
870
|
+
* - c1x{value}c1y{value} = control point 1 (incoming handle when this vertex is END of Bezier)
|
|
871
|
+
* - c0x1 or c1x1 (value of exactly "1" without corresponding y) = "no handle" marker, not a coordinate
|
|
866
872
|
*/
|
|
867
873
|
static parseEncodedVertList(encoded) {
|
|
868
874
|
const verts = [];
|
|
@@ -879,13 +885,13 @@ var ShapePath = class _ShapePath extends ShapeBase {
|
|
|
879
885
|
}
|
|
880
886
|
const c0xMatch = part.match(/c0x([-\d.]+)/);
|
|
881
887
|
const c0yMatch = part.match(/c0y([-\d.]+)/);
|
|
882
|
-
|
|
883
|
-
const c1yMatch = part.match(/c1y([-\d.]+)/);
|
|
884
|
-
if (c0xMatch && c0yMatch && (c0xMatch[1].includes(".") || c0xMatch[1].length > 1)) {
|
|
888
|
+
if (c0xMatch && c0yMatch) {
|
|
885
889
|
vert.c0x = parseFloat(c0xMatch[1]);
|
|
886
890
|
vert.c0y = parseFloat(c0yMatch[1]);
|
|
887
891
|
}
|
|
888
|
-
|
|
892
|
+
const c1xMatch = part.match(/c1x([-\d.]+)/);
|
|
893
|
+
const c1yMatch = part.match(/c1y([-\d.]+)/);
|
|
894
|
+
if (c1xMatch && c1yMatch) {
|
|
889
895
|
vert.c1x = parseFloat(c1xMatch[1]);
|
|
890
896
|
vert.c1y = parseFloat(c1yMatch[1]);
|
|
891
897
|
}
|
|
@@ -894,6 +900,25 @@ var ShapePath = class _ShapePath extends ShapeBase {
|
|
|
894
900
|
}
|
|
895
901
|
return verts;
|
|
896
902
|
}
|
|
903
|
+
/**
|
|
904
|
+
* Parse encoded PrimList string format
|
|
905
|
+
* Format: {type}{fromIdx} {toIdx}{type}{fromIdx} {toIdx}...
|
|
906
|
+
* Example: L0 1B1 2L2 3B3 4
|
|
907
|
+
* where L = Line (type 0), B = Bezier (type 1)
|
|
908
|
+
*/
|
|
909
|
+
static parseEncodedPrimList(encoded) {
|
|
910
|
+
const prims = [];
|
|
911
|
+
const primPattern = /([LB])(\d+)\s+(\d+)/g;
|
|
912
|
+
const matches = encoded.matchAll(primPattern);
|
|
913
|
+
for (const match of matches) {
|
|
914
|
+
const primType = match[1];
|
|
915
|
+
prims.push({
|
|
916
|
+
type: primType === "L" ? 0 : 1
|
|
917
|
+
// L=0 (Line), B=1 (Bezier)
|
|
918
|
+
});
|
|
919
|
+
}
|
|
920
|
+
return prims;
|
|
921
|
+
}
|
|
897
922
|
/**
|
|
898
923
|
* Parse encoded PrimPolyline string format
|
|
899
924
|
* This typically contains line-to commands, each prim is type 0 (LineTo)
|
|
@@ -939,49 +964,46 @@ var VertListElement = class extends LightBurnBaseElement {
|
|
|
939
964
|
}
|
|
940
965
|
toXml(indent = 0) {
|
|
941
966
|
const indentStr = " ".repeat(indent);
|
|
942
|
-
|
|
943
|
-
const lines = [`${indentStr}<VertList>`];
|
|
967
|
+
let encoded = "";
|
|
944
968
|
for (const vert of this.verts) {
|
|
945
|
-
|
|
969
|
+
encoded += `V${vert.x} ${vert.y}`;
|
|
946
970
|
if (vert.c !== void 0) {
|
|
947
|
-
|
|
971
|
+
encoded += `c${vert.c}`;
|
|
948
972
|
}
|
|
949
973
|
if (vert.c0x !== void 0) {
|
|
950
|
-
|
|
974
|
+
encoded += `c0x${vert.c0x}`;
|
|
951
975
|
}
|
|
952
976
|
if (vert.c0y !== void 0) {
|
|
953
|
-
|
|
977
|
+
encoded += `c0y${vert.c0y}`;
|
|
954
978
|
}
|
|
955
979
|
if (vert.c1x !== void 0) {
|
|
956
|
-
|
|
980
|
+
encoded += `c1x${vert.c1x}`;
|
|
957
981
|
}
|
|
958
982
|
if (vert.c1y !== void 0) {
|
|
959
|
-
|
|
983
|
+
encoded += `c1y${vert.c1y}`;
|
|
960
984
|
}
|
|
961
|
-
lines.push(`${innerIndent}<Vert ${attrs}/>`);
|
|
962
985
|
}
|
|
963
|
-
|
|
964
|
-
return lines.join("\n");
|
|
986
|
+
return `${indentStr}<VertList>${encoded}</VertList>`;
|
|
965
987
|
}
|
|
966
988
|
};
|
|
967
989
|
var PrimListElement = class extends LightBurnBaseElement {
|
|
968
990
|
prims;
|
|
969
|
-
|
|
970
|
-
constructor(prims, isClosed) {
|
|
991
|
+
constructor(prims) {
|
|
971
992
|
super();
|
|
972
993
|
this.token = "PrimList";
|
|
973
994
|
this.prims = prims;
|
|
974
|
-
this.isClosed = isClosed;
|
|
975
995
|
}
|
|
976
996
|
toXml(indent = 0) {
|
|
977
997
|
const indentStr = " ".repeat(indent);
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
998
|
+
let encoded = "";
|
|
999
|
+
for (let i = 0; i < this.prims.length; i++) {
|
|
1000
|
+
const prim = this.prims[i];
|
|
1001
|
+
const primType = prim.type === 0 ? "L" : "B";
|
|
1002
|
+
const fromIdx = i;
|
|
1003
|
+
const toIdx = (i + 1) % this.prims.length;
|
|
1004
|
+
encoded += `${primType}${fromIdx} ${toIdx}`;
|
|
982
1005
|
}
|
|
983
|
-
|
|
984
|
-
return lines.join("\n");
|
|
1006
|
+
return `${indentStr}<PrimList>${encoded}</PrimList>`;
|
|
985
1007
|
}
|
|
986
1008
|
};
|
|
987
1009
|
LightBurnBaseElement.register("Shape.Path", ShapePath);
|
|
@@ -1040,7 +1062,8 @@ var ShapeGroup = class _ShapeGroup extends ShapeBase {
|
|
|
1040
1062
|
return group;
|
|
1041
1063
|
}
|
|
1042
1064
|
getChildren() {
|
|
1043
|
-
|
|
1065
|
+
const baseChildren = super.getChildren();
|
|
1066
|
+
return [...baseChildren, ...this.children];
|
|
1044
1067
|
}
|
|
1045
1068
|
};
|
|
1046
1069
|
LightBurnBaseElement.register("Shape.Group", ShapeGroup);
|