lbrnts 0.0.3 → 0.0.5

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
@@ -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}x{flag}c{flag}x{c1x}c{flag}y{c1y}...
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 both present)
271
- * - c1x{value}c1y{value} = control point 1 (when both present)
272
- * - c{num}x{num} alone (like c0x1) = flag, not a coordinate
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
@@ -779,7 +779,7 @@ var ShapePath = class _ShapePath extends ShapeBase {
779
779
  children.push(new VertListElement(this.verts));
780
780
  }
781
781
  if (this.prims.length > 0) {
782
- children.push(new PrimListElement(this.prims, this.isClosed));
782
+ children.push(new PrimListElement(this.prims));
783
783
  }
784
784
  return children;
785
785
  }
@@ -815,11 +815,15 @@ var ShapePath = class _ShapePath extends ShapeBase {
815
815
  const primList = node.PrimList;
816
816
  if (primList) {
817
817
  if (typeof primList === "string") {
818
- const isOpen = primList.includes("Open");
819
- path.isClosed = !isOpen;
820
- const primCount = isOpen ? path.verts.length - 1 : path.verts.length;
821
- for (let i = 0; i < primCount; i++) {
822
- path.prims.push({ type: 0 });
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
+ }
823
827
  }
824
828
  } else if (primList.Prim) {
825
829
  const prims = Array.isArray(primList.Prim) ? primList.Prim : [primList.Prim];
@@ -858,13 +862,13 @@ var ShapePath = class _ShapePath extends ShapeBase {
858
862
  }
859
863
  /**
860
864
  * Parse encoded VertList string format
861
- * Format: V{x} {y}c{flag}x{flag}c{flag}x{c1x}c{flag}y{c1y}...
865
+ * Format: V{x} {y}c{flag}c0x{value}c0y{value}c1x{value}c1y{value}
862
866
  * Example: V2.1156745 -12.3306c0x1c1x1.5871694c1y-12.3306
863
867
  *
864
868
  * Control points are encoded as:
865
- * - c0x{value}c0y{value} = control point 0 (when both present)
866
- * - c1x{value}c1y{value} = control point 1 (when both present)
867
- * - c{num}x{num} alone (like c0x1) = flag, not a coordinate
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
868
872
  */
869
873
  static parseEncodedVertList(encoded) {
870
874
  const verts = [];
@@ -881,13 +885,13 @@ var ShapePath = class _ShapePath extends ShapeBase {
881
885
  }
882
886
  const c0xMatch = part.match(/c0x([-\d.]+)/);
883
887
  const c0yMatch = part.match(/c0y([-\d.]+)/);
884
- const c1xMatch = part.match(/c1x([-\d.]+)/);
885
- const c1yMatch = part.match(/c1y([-\d.]+)/);
886
- if (c0xMatch && c0yMatch && (c0xMatch[1].includes(".") || c0xMatch[1].length > 1)) {
888
+ if (c0xMatch && c0yMatch) {
887
889
  vert.c0x = parseFloat(c0xMatch[1]);
888
890
  vert.c0y = parseFloat(c0yMatch[1]);
889
891
  }
890
- if (c1xMatch && c1yMatch && (c1xMatch[1].includes(".") || c1xMatch[1].length > 1)) {
892
+ const c1xMatch = part.match(/c1x([-\d.]+)/);
893
+ const c1yMatch = part.match(/c1y([-\d.]+)/);
894
+ if (c1xMatch && c1yMatch) {
891
895
  vert.c1x = parseFloat(c1xMatch[1]);
892
896
  vert.c1y = parseFloat(c1yMatch[1]);
893
897
  }
@@ -896,6 +900,25 @@ var ShapePath = class _ShapePath extends ShapeBase {
896
900
  }
897
901
  return verts;
898
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
+ }
899
922
  /**
900
923
  * Parse encoded PrimPolyline string format
901
924
  * This typically contains line-to commands, each prim is type 0 (LineTo)
@@ -941,49 +964,46 @@ var VertListElement = class extends LightBurnBaseElement {
941
964
  }
942
965
  toXml(indent = 0) {
943
966
  const indentStr = " ".repeat(indent);
944
- const innerIndent = " ".repeat(indent + 1);
945
- const lines = [`${indentStr}<VertList>`];
967
+ let encoded = "";
946
968
  for (const vert of this.verts) {
947
- let attrs = `x="${vert.x}" y="${vert.y}"`;
969
+ encoded += `V${vert.x} ${vert.y}`;
948
970
  if (vert.c !== void 0) {
949
- attrs += ` c="${vert.c}"`;
971
+ encoded += `c${vert.c}`;
950
972
  }
951
973
  if (vert.c0x !== void 0) {
952
- attrs += ` c0x="${vert.c0x}"`;
974
+ encoded += `c0x${vert.c0x}`;
953
975
  }
954
976
  if (vert.c0y !== void 0) {
955
- attrs += ` c0y="${vert.c0y}"`;
977
+ encoded += `c0y${vert.c0y}`;
956
978
  }
957
979
  if (vert.c1x !== void 0) {
958
- attrs += ` c1x="${vert.c1x}"`;
980
+ encoded += `c1x${vert.c1x}`;
959
981
  }
960
982
  if (vert.c1y !== void 0) {
961
- attrs += ` c1y="${vert.c1y}"`;
983
+ encoded += `c1y${vert.c1y}`;
962
984
  }
963
- lines.push(`${innerIndent}<Vert ${attrs}/>`);
964
985
  }
965
- lines.push(`${indentStr}</VertList>`);
966
- return lines.join("\n");
986
+ return `${indentStr}<VertList>${encoded}</VertList>`;
967
987
  }
968
988
  };
969
989
  var PrimListElement = class extends LightBurnBaseElement {
970
990
  prims;
971
- isClosed;
972
- constructor(prims, isClosed) {
991
+ constructor(prims) {
973
992
  super();
974
993
  this.token = "PrimList";
975
994
  this.prims = prims;
976
- this.isClosed = isClosed;
977
995
  }
978
996
  toXml(indent = 0) {
979
997
  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}"/>`);
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}`;
984
1005
  }
985
- lines.push(`${indentStr}</PrimList>`);
986
- return lines.join("\n");
1006
+ return `${indentStr}<PrimList>${encoded}</PrimList>`;
987
1007
  }
988
1008
  };
989
1009
  LightBurnBaseElement.register("Shape.Path", ShapePath);
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.3",
5
+ "version": "0.0.5",
6
6
  "files": [
7
7
  "dist"
8
8
  ],