web-to-print 0.1.2 → 0.1.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.
@@ -637,13 +637,17 @@ function upscaleSvgDataUrl(svgDataUrl, maxSize = 4000) {
637
637
  if (svgText === null) {
638
638
  return { dataUrl: svgDataUrl, scaleApplied: 1 };
639
639
  }
640
- // Parse SVG document
640
+ // Parse SVG document. Real browsers return the SVG as documentElement when
641
+ // parsing image/svg+xml; some environments (mock-doc, fallback parsers) wrap
642
+ // it in <html><body>, so probe both.
641
643
  const doc = new DOMParser().parseFromString(svgText, 'image/svg+xml');
642
- const svgEl = doc.documentElement;
643
- if (svgEl.tagName !== 'svg')
644
+ const svgEl = doc.documentElement.tagName.toLowerCase() === 'svg'
645
+ ? doc.documentElement
646
+ : doc.querySelector('svg');
647
+ if (svgEl === null)
644
648
  return { dataUrl: svgDataUrl, scaleApplied: 1 };
645
649
  // Determine intrinsic dimensions from viewBox or width/height attributes
646
- const viewBox = svgEl.getAttribute('viewBox');
650
+ const viewBox = svgEl.getAttribute('viewBox') ?? svgEl.getAttribute('viewbox');
647
651
  let intrinsicW;
648
652
  let intrinsicH;
649
653
  if (viewBox !== null) {
@@ -671,6 +675,10 @@ function upscaleSvgDataUrl(svgDataUrl, maxSize = 4000) {
671
675
  if (viewBox === null) {
672
676
  svgEl.setAttribute('viewBox', `0 0 ${intrinsicW} ${intrinsicH}`);
673
677
  }
678
+ else if (svgEl.getAttribute('viewBox') === null) {
679
+ // mock-doc lowercases attribute names; re-set with canonical case for serialization
680
+ svgEl.setAttribute('viewBox', viewBox);
681
+ }
674
682
  // Serialize and re-encode as base64 data URL
675
683
  const newSvgText = new XMLSerializer().serializeToString(doc);
676
684
  const bytes = new TextEncoder().encode(newSvgText);
@@ -690,10 +698,13 @@ async function trimSvgWhitespace(svgDataUrl, padding = 1) {
690
698
  if (svgText === null) {
691
699
  return svgDataUrl;
692
700
  }
693
- // Parse SVG document
701
+ // Parse SVG document. See upscaleSvgDataUrl for the documentElement vs
702
+ // querySelector('svg') rationale.
694
703
  const doc = new DOMParser().parseFromString(svgText, 'image/svg+xml');
695
- const svgEl = doc.documentElement;
696
- if (svgEl.tagName !== 'svg')
704
+ const svgEl = doc.documentElement.tagName.toLowerCase() === 'svg'
705
+ ? doc.documentElement
706
+ : doc.querySelector('svg');
707
+ if (svgEl === null)
697
708
  return svgDataUrl;
698
709
  // Insert SVG offscreen to enable getBBox()
699
710
  const container = document.createElement('div');
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var logo = require('./logo-BUX-b45R.js');
4
- var canvasHelpers = require('./canvas-helpers-A6rp5rPD.js');
4
+ var canvasHelpers = require('./canvas-helpers-CVJyl28T.js');
5
5
 
6
6
  const DEFAULT_PDF_CONFIG = {
7
7
  pageFormat: 'a4',
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var index = require('./index-IFGFRm-i.js');
4
- var canvasHelpers = require('./canvas-helpers-A6rp5rPD.js');
4
+ var canvasHelpers = require('./canvas-helpers-CVJyl28T.js');
5
5
  var logo = require('./logo-BUX-b45R.js');
6
6
 
7
7
  // User-facing strings for components, overridable via the `labels` prop.
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var index = require('./index-IFGFRm-i.js');
4
- var canvasHelpers = require('./canvas-helpers-A6rp5rPD.js');
4
+ var canvasHelpers = require('./canvas-helpers-CVJyl28T.js');
5
5
 
6
6
  /** Utility functions for the HTML/CSS-based logo renderer and Canvas 2D export. */
7
7
  /** Load an image from a URL/data-URL and return the HTMLImageElement once loaded. */
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var index = require('./index-IFGFRm-i.js');
4
- var canvasHelpers = require('./canvas-helpers-A6rp5rPD.js');
4
+ var canvasHelpers = require('./canvas-helpers-CVJyl28T.js');
5
5
 
6
6
  const wtpPrintAreaEditorCss = () => `*.sc-wtp-print-area-editor,*.sc-wtp-print-area-editor::before,*.sc-wtp-print-area-editor::after{box-sizing:border-box}.sc-wtp-print-area-editor-h{font-family:var(--wtp-font-family, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif);color:var(--wtp-color-text, #1e293b);line-height:1.5}.wtp-print-area-editor.sc-wtp-print-area-editor{display:inline-block;line-height:0;border:1px solid var(--wtp-color-border, #e2e8f0);border-radius:8px;overflow:hidden;background:repeating-conic-gradient(#e5e7eb 0% 25%, transparent 0% 50%) 50%/20px 20px}`;
7
7
 
@@ -250,13 +250,17 @@ export function upscaleSvgDataUrl(svgDataUrl, maxSize = 4000) {
250
250
  if (svgText === null) {
251
251
  return { dataUrl: svgDataUrl, scaleApplied: 1 };
252
252
  }
253
- // Parse SVG document
253
+ // Parse SVG document. Real browsers return the SVG as documentElement when
254
+ // parsing image/svg+xml; some environments (mock-doc, fallback parsers) wrap
255
+ // it in <html><body>, so probe both.
254
256
  const doc = new DOMParser().parseFromString(svgText, 'image/svg+xml');
255
- const svgEl = doc.documentElement;
256
- if (svgEl.tagName !== 'svg')
257
+ const svgEl = doc.documentElement.tagName.toLowerCase() === 'svg'
258
+ ? doc.documentElement
259
+ : doc.querySelector('svg');
260
+ if (svgEl === null)
257
261
  return { dataUrl: svgDataUrl, scaleApplied: 1 };
258
262
  // Determine intrinsic dimensions from viewBox or width/height attributes
259
- const viewBox = svgEl.getAttribute('viewBox');
263
+ const viewBox = svgEl.getAttribute('viewBox') ?? svgEl.getAttribute('viewbox');
260
264
  let intrinsicW;
261
265
  let intrinsicH;
262
266
  if (viewBox !== null) {
@@ -284,6 +288,10 @@ export function upscaleSvgDataUrl(svgDataUrl, maxSize = 4000) {
284
288
  if (viewBox === null) {
285
289
  svgEl.setAttribute('viewBox', `0 0 ${intrinsicW} ${intrinsicH}`);
286
290
  }
291
+ else if (svgEl.getAttribute('viewBox') === null) {
292
+ // mock-doc lowercases attribute names; re-set with canonical case for serialization
293
+ svgEl.setAttribute('viewBox', viewBox);
294
+ }
287
295
  // Serialize and re-encode as base64 data URL
288
296
  const newSvgText = new XMLSerializer().serializeToString(doc);
289
297
  const bytes = new TextEncoder().encode(newSvgText);
@@ -303,10 +311,13 @@ export async function trimSvgWhitespace(svgDataUrl, padding = 1) {
303
311
  if (svgText === null) {
304
312
  return svgDataUrl;
305
313
  }
306
- // Parse SVG document
314
+ // Parse SVG document. See upscaleSvgDataUrl for the documentElement vs
315
+ // querySelector('svg') rationale.
307
316
  const doc = new DOMParser().parseFromString(svgText, 'image/svg+xml');
308
- const svgEl = doc.documentElement;
309
- if (svgEl.tagName !== 'svg')
317
+ const svgEl = doc.documentElement.tagName.toLowerCase() === 'svg'
318
+ ? doc.documentElement
319
+ : doc.querySelector('svg');
320
+ if (svgEl === null)
310
321
  return svgDataUrl;
311
322
  // Insert SVG offscreen to enable getBBox()
312
323
  const container = document.createElement('div');
@@ -1 +1 @@
1
- import{u as t,p as n}from"./p-5qCsRzlt.js";export{g as getAssetPath,r as render,s as setAssetPath,a as setNonce,b as setPlatformOptions}from"./p-5qCsRzlt.js";export{a as DEFAULT_BG_REMOVAL_CONFIG,D as DEFAULT_VALIDATION_CONFIG}from"./p-D8pVJRuX.js";const o={pageFormat:"a4",orientation:"portrait",marginMm:15,showPrintAreaGuides:!0,title:"Logo Print Specification"};function e(t){return t.startsWith("data:image/jpeg")||t.startsWith("data:image/jpg")?"JPEG":"PNG"}function i(t){return t<1024?t+" B":t<1048576?(t/1024).toFixed(1)+" KB":(t/1048576).toFixed(1)+" MB"}async function c(r,a,s,c,l,m,u){const d=function(t){return{...o,...t}}(u),f=function(){const t="undefined"!=typeof window?window:void 0,n=t?.jspdf;if(null!=n?.jsPDF)return n.jsPDF;throw Error('jsPDF is required for PDF export. Load it via: <script src="https://unpkg.com/jspdf@4.1.0/dist/jspdf.umd.min.js"><\/script>')}(),p=await function(n,o=4e3){if(!function(t){return t.startsWith("data:image/svg+xml")}(n))return Promise.resolve(n);const{dataUrl:e}=t(n,o);return new Promise(((t,n)=>{const r=new Image;r.onload=()=>{const e=r.naturalWidth||o,a=r.naturalHeight||o,i=document.createElement("canvas");i.width=e,i.height=a;const s=i.getContext("2d");null!=s?(s.drawImage(r,0,0,e,a),t(i.toDataURL("image/png"))):n(Error("Failed to get 2D context for SVG rasterization"))},r.onerror=()=>n(Error("Failed to load image for rasterization")),r.src=e}))}(r.dataUrl),g=new f({orientation:d.orientation,unit:"mm",format:d.pageFormat});!function(t,n,o,r){const a=t.internal.pageSize.getWidth(),s=t.internal.pageSize.getHeight(),c=r.marginMm,l=a-2*c;t.setFontSize(18),t.setFont("helvetica","bold"),t.text(r.title,a/2,c+8,{align:"center"});const m=e(o),u=c+16,d=.5*s,f=n.metadata.width/Math.max(n.metadata.height,1);let p=l,g=p/f;g>d&&(g=d,p=g*f),t.addImage(o,m,(a-p)/2,u,p,g);const P=u+g+10,h=n.metadata,F=[["Format",h.format.toUpperCase()],["Dimensions",`${h.width} x ${h.height} px`],["DPI",null!==h.dpiX?`${h.dpiX} x ${h.dpiY??h.dpiX}`:"Not available"],["File Size",i(h.fileSize)],["Transparency",h.hasTransparency?"Yes":"No"],["File Name",h.fileName]];t.setFontSize(10),F.forEach(((n,o)=>{const e=P+7*o;t.setFont("helvetica","bold"),t.text(n[0],c,e),t.setFont("helvetica","normal"),t.text(n[1],c+30,e)})),t.setDrawColor(200,200,200),t.setLineWidth(.3),t.line(c,P-4,c+l,P-4)}(g,r,p,d),g.addPage(),function(t,o,r,a,i,s,c){const l=t.internal.pageSize.getWidth(),m=t.internal.pageSize.getHeight(),u=c.marginMm,d=l-2*u;t.setFontSize(16),t.setFont("helvetica","bold"),t.text(o.name,l/2,u+8,{align:"center"});const f=o.views[r],p=[["Article ID",o.id]];f?.impMethod&&p.push(["Print Method",f.impMethod]),f?.impLocation&&p.push(["Print Location",f.impLocation]),f?.impDiameterMm&&f.impDiameterMm>0?p.push(["Print Area",`Ø ${f.impDiameterMm} mm`]):f?.impWidthMm&&f?.impHeightMm&&p.push(["Print Area",`${f.impWidthMm} × ${f.impHeightMm} mm`]),f?.maxColours&&p.push(["Max Colors",""+f.maxColours]);const g=u+16;t.setFontSize(9),p.forEach(((n,o)=>{const e=g+6*o;t.setFont("helvetica","bold"),t.text(n[0],u,e),t.setFont("helvetica","normal"),t.text(n[1],u+30,e)})),t.setDrawColor(200,200,200),t.setLineWidth(.3),t.line(u,g+6*p.length+2,u+d,g+6*p.length+2);const P=e(a),h=g+6*p.length+6,F=m-h-u,v=i/Math.max(s,1);let x=d,A=x/v;A>F&&(A=F,x=A*v);const D=(l-x)/2;t.addImage(a,P,D,h,x,A),c.showPrintAreaGuides&&null!=f?.printArea&&function(t,o,e,r,a,i,s,c){const l=n(o,s,c),m=a/s,u=i/c,d=l.map((t=>({x:e+t.x*m,y:r+t.y*u})));t.setDrawColor(37,99,235),t.setLineWidth(.4),t.setLineDashPattern([2,1.5],0);for(let n=0;n<4;n++){const o=d[n],e=d[(n+1)%4];t.line(o.x,o.y,e.x,e.y)}t.setLineDashPattern([],0)}(t,f.printArea,D,h,x,A,i,s)}(g,a,s,c,l,m,d),g.save(a.id+".pdf")}export{c as exportProductPdf}
1
+ import{u as t,p as n}from"./p-7iz1Mktq.js";export{g as getAssetPath,r as render,s as setAssetPath,a as setNonce,b as setPlatformOptions}from"./p-7iz1Mktq.js";export{a as DEFAULT_BG_REMOVAL_CONFIG,D as DEFAULT_VALIDATION_CONFIG}from"./p-D8pVJRuX.js";const o={pageFormat:"a4",orientation:"portrait",marginMm:15,showPrintAreaGuides:!0,title:"Logo Print Specification"};function e(t){return t.startsWith("data:image/jpeg")||t.startsWith("data:image/jpg")?"JPEG":"PNG"}function i(t){return t<1024?t+" B":t<1048576?(t/1024).toFixed(1)+" KB":(t/1048576).toFixed(1)+" MB"}async function c(r,a,s,c,l,m,u){const d=function(t){return{...o,...t}}(u),f=function(){const t="undefined"!=typeof window?window:void 0,n=t?.jspdf;if(null!=n?.jsPDF)return n.jsPDF;throw Error('jsPDF is required for PDF export. Load it via: <script src="https://unpkg.com/jspdf@4.1.0/dist/jspdf.umd.min.js"><\/script>')}(),p=await function(n,o=4e3){if(!function(t){return t.startsWith("data:image/svg+xml")}(n))return Promise.resolve(n);const{dataUrl:e}=t(n,o);return new Promise(((t,n)=>{const r=new Image;r.onload=()=>{const e=r.naturalWidth||o,i=r.naturalHeight||o,a=document.createElement("canvas");a.width=e,a.height=i;const s=a.getContext("2d");null!=s?(s.drawImage(r,0,0,e,i),t(a.toDataURL("image/png"))):n(Error("Failed to get 2D context for SVG rasterization"))},r.onerror=()=>n(Error("Failed to load image for rasterization")),r.src=e}))}(r.dataUrl),g=new f({orientation:d.orientation,unit:"mm",format:d.pageFormat});!function(t,n,o,r){const a=t.internal.pageSize.getWidth(),s=t.internal.pageSize.getHeight(),c=r.marginMm,l=a-2*c;t.setFontSize(18),t.setFont("helvetica","bold"),t.text(r.title,a/2,c+8,{align:"center"});const m=e(o),u=c+16,d=.5*s,f=n.metadata.width/Math.max(n.metadata.height,1);let p=l,g=p/f;g>d&&(g=d,p=g*f),t.addImage(o,m,(a-p)/2,u,p,g);const P=u+g+10,h=n.metadata,F=[["Format",h.format.toUpperCase()],["Dimensions",`${h.width} x ${h.height} px`],["DPI",null!==h.dpiX?`${h.dpiX} x ${h.dpiY??h.dpiX}`:"Not available"],["File Size",i(h.fileSize)],["Transparency",h.hasTransparency?"Yes":"No"],["File Name",h.fileName]];t.setFontSize(10),F.forEach(((n,o)=>{const e=P+7*o;t.setFont("helvetica","bold"),t.text(n[0],c,e),t.setFont("helvetica","normal"),t.text(n[1],c+30,e)})),t.setDrawColor(200,200,200),t.setLineWidth(.3),t.line(c,P-4,c+l,P-4)}(g,r,p,d),g.addPage(),function(t,o,r,i,a,s,c){const l=t.internal.pageSize.getWidth(),m=t.internal.pageSize.getHeight(),u=c.marginMm,d=l-2*u;t.setFontSize(16),t.setFont("helvetica","bold"),t.text(o.name,l/2,u+8,{align:"center"});const f=o.views[r],p=[["Article ID",o.id]];f?.impMethod&&p.push(["Print Method",f.impMethod]),f?.impLocation&&p.push(["Print Location",f.impLocation]),f?.impDiameterMm&&f.impDiameterMm>0?p.push(["Print Area",`Ø ${f.impDiameterMm} mm`]):f?.impWidthMm&&f?.impHeightMm&&p.push(["Print Area",`${f.impWidthMm} × ${f.impHeightMm} mm`]),f?.maxColours&&p.push(["Max Colors",""+f.maxColours]);const g=u+16;t.setFontSize(9),p.forEach(((n,o)=>{const e=g+6*o;t.setFont("helvetica","bold"),t.text(n[0],u,e),t.setFont("helvetica","normal"),t.text(n[1],u+30,e)})),t.setDrawColor(200,200,200),t.setLineWidth(.3),t.line(u,g+6*p.length+2,u+d,g+6*p.length+2);const P=e(i),h=g+6*p.length+6,F=m-h-u,v=a/Math.max(s,1);let x=d,A=x/v;A>F&&(A=F,x=A*v);const D=(l-x)/2;t.addImage(i,P,D,h,x,A),c.showPrintAreaGuides&&null!=f?.printArea&&function(t,o,e,r,i,a,s,c){const l=n(o,s,c),m=i/s,u=a/c,d=l.map((t=>({x:e+t.x*m,y:r+t.y*u})));t.setDrawColor(37,99,235),t.setLineWidth(.4),t.setLineDashPattern([2,1.5],0);for(let n=0;n<4;n++){const o=d[n],e=d[(n+1)%4];t.line(o.x,o.y,e.x,e.y)}t.setLineDashPattern([],0)}(t,f.printArea,D,h,x,A,a,s)}(g,a,s,c,l,m,d),g.save(a.id+".pdf")}export{c as exportProductPdf}