satoru-render 1.0.2 → 1.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.
@@ -439,7 +439,10 @@ var SatoruBase = class {
439
439
  cropX: options.crop?.x ?? 0,
440
440
  cropY: options.crop?.y ?? 0,
441
441
  cropWidth: options.crop?.width ?? 0,
442
- cropHeight: options.crop?.height ?? 0
442
+ cropHeight: options.crop?.height ?? 0,
443
+ fitPositionX: options.fitPosition?.x ?? .5,
444
+ fitPositionY: options.fitPosition?.y ?? .5,
445
+ backgroundColor: this.parseColor(options.backgroundColor)
443
446
  });
444
447
  if (!result) {
445
448
  if (options.format === "svg") return "";
@@ -460,6 +463,29 @@ var SatoruBase = class {
460
463
  mod.destroy_instance(inst);
461
464
  }
462
465
  }
466
+ parseColor(color) {
467
+ if (!color) return 0;
468
+ if (color.startsWith("#")) {
469
+ let hex = color.slice(1);
470
+ if (hex.length === 3) hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
471
+ if (hex.length === 6) return (4278190080 | parseInt(hex, 16)) >>> 0;
472
+ if (hex.length === 8) {
473
+ const r = hex.slice(0, 2);
474
+ const g = hex.slice(2, 4);
475
+ const b = hex.slice(4, 6);
476
+ const a = hex.slice(6, 8);
477
+ return parseInt(a + r + g + b, 16) >>> 0;
478
+ }
479
+ }
480
+ const m = color.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)/);
481
+ if (m) {
482
+ const r = parseInt(m[1]);
483
+ const g = parseInt(m[2]);
484
+ const b = parseInt(m[3]);
485
+ return ((m[4] ? Math.round(parseFloat(m[4]) * 255) : 255) << 24 | r << 16 | g << 8 | b) >>> 0;
486
+ }
487
+ return 0;
488
+ }
463
489
  async render(options) {
464
490
  let { format = "svg", value, url, baseUrl } = options;
465
491
  if (format === "pdf" && Array.isArray(value) && value.length > 1) {
@@ -566,7 +592,7 @@ var SatoruBase = class {
566
592
  if (!data) return;
567
593
  if (typeof data === "object" && "css" in data && "fonts" in data) {
568
594
  const fontResult = data;
569
- mod.add_resource(instancePtr, r.url, 1, fontResult.css);
595
+ mod.add_resource(instancePtr, r.url, 3, fontResult.css);
570
596
  for (const font of fontResult.fonts) {
571
597
  const fontKey = `font:${font.url}:`;
572
598
  resolvedResources.add(fontKey);
@@ -605,7 +631,10 @@ var SatoruBase = class {
605
631
  cropX: options.crop?.x ?? 0,
606
632
  cropY: options.crop?.y ?? 0,
607
633
  cropWidth: options.crop?.width ?? 0,
608
- cropHeight: options.crop?.height ?? 0
634
+ cropHeight: options.crop?.height ?? 0,
635
+ fitPositionX: options.fitPosition?.x ?? .5,
636
+ fitPositionY: options.fitPosition?.y ?? .5,
637
+ backgroundColor: this.parseColor(options.backgroundColor)
609
638
  });
610
639
  if (!result) {
611
640
  if (format === "svg") return "";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "satoru-render",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "High-fidelity HTML/CSS to SVG/PNG/PDF converter running in WebAssembly",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",