lbrnts 0.0.8 → 0.0.10

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
@@ -92,6 +92,8 @@ interface CutSettingInit {
92
92
  overScanning?: number;
93
93
  lineAngle?: number;
94
94
  crossHatch?: boolean;
95
+ frequency?: number;
96
+ pulseWidth?: number;
95
97
  }
96
98
  declare class CutSetting extends LightBurnBaseElement {
97
99
  private _type;
@@ -117,6 +119,8 @@ declare class CutSetting extends LightBurnBaseElement {
117
119
  private _overScanning?;
118
120
  private _lineAngle?;
119
121
  private _crossHatch?;
122
+ private _frequency?;
123
+ private _pulseWidth?;
120
124
  constructor(init?: CutSettingInit);
121
125
  get type(): string;
122
126
  set type(value: string);
@@ -164,6 +168,10 @@ declare class CutSetting extends LightBurnBaseElement {
164
168
  set lineAngle(value: number | undefined);
165
169
  get crossHatch(): boolean | undefined;
166
170
  set crossHatch(value: boolean | undefined);
171
+ get frequency(): number | undefined;
172
+ set frequency(value: number | undefined);
173
+ get pulseWidth(): number | undefined;
174
+ set pulseWidth(value: number | undefined);
167
175
  getXmlAttributes(): Record<string, string | number | boolean | undefined>;
168
176
  getChildren(): LightBurnBaseElement[];
169
177
  static fromXmlJson(node: XmlJsonElement): CutSetting;
@@ -353,6 +361,10 @@ declare class ShapeBitmap extends ShapeBase {
353
361
 
354
362
  interface GenerateSvgOptions {
355
363
  margin?: number;
364
+ /** Target width for the SVG. When provided with height, scales the output. */
365
+ width?: number;
366
+ /** Target height for the SVG. When provided with width, scales the output. */
367
+ height?: number;
356
368
  }
357
369
 
358
370
  declare function generateLightBurnSvg(root: LightBurnBaseElement | LightBurnBaseElement[], options?: GenerateSvgOptions): string;
package/dist/index.js CHANGED
@@ -104,7 +104,7 @@ ${this.toXml()}`;
104
104
  get [Symbol.toStringTag]() {
105
105
  return this.getString();
106
106
  }
107
- [Symbol.for("nodejs.util.inspect.custom")]() {
107
+ [/* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom")]() {
108
108
  return this.getString();
109
109
  }
110
110
  // =========================== STATIC METHODS ===========================
@@ -294,6 +294,8 @@ var CutSetting = class _CutSetting extends LightBurnBaseElement {
294
294
  _overScanning;
295
295
  _lineAngle;
296
296
  _crossHatch;
297
+ _frequency;
298
+ _pulseWidth;
297
299
  constructor(init) {
298
300
  super();
299
301
  this.token = "CutSetting";
@@ -323,6 +325,8 @@ var CutSetting = class _CutSetting extends LightBurnBaseElement {
323
325
  this._overScanning = init.overScanning;
324
326
  if (init.lineAngle !== void 0) this._lineAngle = init.lineAngle;
325
327
  if (init.crossHatch !== void 0) this._crossHatch = init.crossHatch;
328
+ if (init.frequency !== void 0) this._frequency = init.frequency;
329
+ if (init.pulseWidth !== void 0) this._pulseWidth = init.pulseWidth;
326
330
  }
327
331
  }
328
332
  get type() {
@@ -463,6 +467,18 @@ var CutSetting = class _CutSetting extends LightBurnBaseElement {
463
467
  set crossHatch(value) {
464
468
  this._crossHatch = value;
465
469
  }
470
+ get frequency() {
471
+ return this._frequency;
472
+ }
473
+ set frequency(value) {
474
+ this._frequency = value;
475
+ }
476
+ get pulseWidth() {
477
+ return this._pulseWidth;
478
+ }
479
+ set pulseWidth(value) {
480
+ this._pulseWidth = value;
481
+ }
466
482
  getXmlAttributes() {
467
483
  return {
468
484
  type: this._type
@@ -492,7 +508,9 @@ var CutSetting = class _CutSetting extends LightBurnBaseElement {
492
508
  "angle",
493
509
  "overScanning",
494
510
  "lineAngle",
495
- "crossHatch"
511
+ "crossHatch",
512
+ "frequency",
513
+ "pulseWidth"
496
514
  ];
497
515
  for (const prop of props) {
498
516
  const value = this[`_${prop}`];
@@ -533,6 +551,8 @@ var CutSetting = class _CutSetting extends LightBurnBaseElement {
533
551
  cs.overScanning = num(getChildValue("overScanning"), void 0);
534
552
  cs.lineAngle = num(getChildValue("lineAngle"), void 0);
535
553
  cs.crossHatch = boolish(getChildValue("crossHatch"), void 0);
554
+ cs.frequency = num(getChildValue("frequency"), void 0);
555
+ cs.pulseWidth = num(getChildValue("pulseWidth"), void 0);
536
556
  return cs;
537
557
  }
538
558
  };
@@ -545,9 +565,18 @@ var CutSettingPropertyElement = class extends LightBurnBaseElement {
545
565
  this.propName = propName;
546
566
  this.propValue = propValue;
547
567
  }
568
+ formatValue(value) {
569
+ if (typeof value === "number") {
570
+ if (value !== 0 && Math.abs(value) < 1e-3) {
571
+ return value.toFixed(9).replace(/\.?0+$/, "");
572
+ }
573
+ return value.toString();
574
+ }
575
+ return String(value);
576
+ }
548
577
  toXml(indent = 0) {
549
578
  const indentStr = " ".repeat(indent);
550
- return `${indentStr}<${this.propName} Value="${this.propValue}"/>`;
579
+ return `${indentStr}<${this.propName} Value="${this.formatValue(this.propValue)}"/>`;
551
580
  }
552
581
  };
553
582
  LightBurnBaseElement.register("CutSetting", CutSetting);
@@ -1286,16 +1315,18 @@ function computeLayout(bbox, options) {
1286
1315
  const minY = Math.min(0, bbox.minY) - margin;
1287
1316
  const maxX = Math.max(0, bbox.maxX) + margin;
1288
1317
  const maxY = Math.max(0, bbox.maxY) + margin;
1289
- const width = maxX - minX;
1290
- const height = maxY - minY;
1291
- const viewBox = `${minX} ${minY} ${width} ${height}`;
1318
+ const contentWidth = maxX - minX;
1319
+ const contentHeight = maxY - minY;
1320
+ const viewBox = `${minX} ${minY} ${contentWidth} ${contentHeight}`;
1292
1321
  const flipY = maxY + minY;
1322
+ const width = options?.width ?? contentWidth;
1323
+ const height = options?.height ?? contentHeight;
1293
1324
  return {
1294
1325
  viewBox,
1295
1326
  width,
1296
1327
  height,
1297
1328
  flipY,
1298
- bg: { x: minX, y: minY, width, height }
1329
+ bg: { x: minX, y: minY, width: contentWidth, height: contentHeight }
1299
1330
  };
1300
1331
  }
1301
1332
 
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.8",
5
+ "version": "0.0.10",
6
6
  "files": [
7
7
  "dist"
8
8
  ],