@dtducas/wh-forge-viewer 3.0.0-beta.6 → 3.0.0-beta.8
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.esm.js +104 -26
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +104 -26
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -70648,6 +70648,7 @@ var SvgToPdfConverter = /*#__PURE__*/function () {
|
|
|
70648
70648
|
}, {
|
|
70649
70649
|
key: "drawEllipse",
|
|
70650
70650
|
value: function drawEllipse(element, pdfPage, options, transform) {
|
|
70651
|
+
var _options$pageRotation;
|
|
70651
70652
|
var cx = parseFloat(element.getAttribute('cx') || '0');
|
|
70652
70653
|
var cy = parseFloat(element.getAttribute('cy') || '0');
|
|
70653
70654
|
var rx = parseFloat(element.getAttribute('rx') || '0');
|
|
@@ -70659,16 +70660,24 @@ var SvgToPdfConverter = /*#__PURE__*/function () {
|
|
|
70659
70660
|
_this$transformPoint34 = _slicedToArray(_this$transformPoint33, 2),
|
|
70660
70661
|
pdfCx = _this$transformPoint34[0],
|
|
70661
70662
|
pdfCy = _this$transformPoint34[1];
|
|
70662
|
-
// Scale radii (apply SVG transform scale if present)
|
|
70663
|
-
|
|
70664
|
-
|
|
70663
|
+
// Scale radii (apply SVG transform scale if present). Use the *displayed*
|
|
70664
|
+
// page dims (swapped for 90/270) so radii are not stretched on rotated pages,
|
|
70665
|
+
// and swap rx/ry under a quarter rotation since the axes swap in user space.
|
|
70666
|
+
var svgScaleX = Math.abs(transform ? transform.scaleX : 1);
|
|
70667
|
+
var svgScaleY = Math.abs(transform ? transform.scaleY : 1);
|
|
70665
70668
|
var mbE = options.modelBounds;
|
|
70666
70669
|
var mapWE = mbE ? mbE.maxX - mbE.minX : options.svgViewBox.width;
|
|
70667
70670
|
var mapHE = mbE ? mbE.maxY - mbE.minY : options.svgViewBox.height;
|
|
70668
|
-
var
|
|
70669
|
-
var
|
|
70670
|
-
var
|
|
70671
|
-
var
|
|
70671
|
+
var rotE = (((_options$pageRotation = options.pageRotation) !== null && _options$pageRotation !== void 0 ? _options$pageRotation : 0) % 360 + 360) % 360;
|
|
70672
|
+
var quarterE = rotE === 90 || rotE === 270;
|
|
70673
|
+
var dispWE = quarterE ? options.pageHeight : options.pageWidth;
|
|
70674
|
+
var dispHE = quarterE ? options.pageWidth : options.pageHeight;
|
|
70675
|
+
var scaleX = dispWE / mapWE;
|
|
70676
|
+
var scaleY = dispHE / mapHE;
|
|
70677
|
+
var rdx = rx * svgScaleX * scaleX;
|
|
70678
|
+
var rdy = ry * svgScaleY * scaleY;
|
|
70679
|
+
var pdfRx = quarterE ? rdy : rdx;
|
|
70680
|
+
var pdfRy = quarterE ? rdx : rdy;
|
|
70672
70681
|
// Draw fill
|
|
70673
70682
|
if (style.fillColor && style.fillOpacity > 0) {
|
|
70674
70683
|
pdfPage.drawEllipse({
|
|
@@ -70700,6 +70709,7 @@ var SvgToPdfConverter = /*#__PURE__*/function () {
|
|
|
70700
70709
|
}, {
|
|
70701
70710
|
key: "drawCircle",
|
|
70702
70711
|
value: function drawCircle(element, pdfPage, options, transform) {
|
|
70712
|
+
var _options$pageRotation2;
|
|
70703
70713
|
var cx = parseFloat(element.getAttribute('cx') || '0');
|
|
70704
70714
|
var cy = parseFloat(element.getAttribute('cy') || '0');
|
|
70705
70715
|
var r = parseFloat(element.getAttribute('r') || '0');
|
|
@@ -70710,12 +70720,18 @@ var SvgToPdfConverter = /*#__PURE__*/function () {
|
|
|
70710
70720
|
_this$transformPoint36 = _slicedToArray(_this$transformPoint35, 2),
|
|
70711
70721
|
pdfCx = _this$transformPoint36[0],
|
|
70712
70722
|
pdfCy = _this$transformPoint36[1];
|
|
70713
|
-
// Scale radius (apply SVG transform scale if present)
|
|
70714
|
-
|
|
70723
|
+
// Scale radius (apply SVG transform scale if present). Use displayed page
|
|
70724
|
+
// dims (swapped for 90/270) and absolute scale (the SVG Y-flip makes scaleY
|
|
70725
|
+
// negative, which must not flip the radius sign).
|
|
70726
|
+
var svgScale = transform ? Math.min(Math.abs(transform.scaleX), Math.abs(transform.scaleY)) : 1;
|
|
70715
70727
|
var mbC = options.modelBounds;
|
|
70716
70728
|
var mapWC = mbC ? mbC.maxX - mbC.minX : options.svgViewBox.width;
|
|
70717
70729
|
var mapHC = mbC ? mbC.maxY - mbC.minY : options.svgViewBox.height;
|
|
70718
|
-
var
|
|
70730
|
+
var rotC = (((_options$pageRotation2 = options.pageRotation) !== null && _options$pageRotation2 !== void 0 ? _options$pageRotation2 : 0) % 360 + 360) % 360;
|
|
70731
|
+
var quarterC = rotC === 90 || rotC === 270;
|
|
70732
|
+
var dispWC = quarterC ? options.pageHeight : options.pageWidth;
|
|
70733
|
+
var dispHC = quarterC ? options.pageWidth : options.pageHeight;
|
|
70734
|
+
var scale = svgScale * Math.min(dispWC / mapWC, dispHC / mapHC);
|
|
70719
70735
|
var pdfR = r * scale;
|
|
70720
70736
|
// Draw fill
|
|
70721
70737
|
if (style.fillColor && style.fillOpacity > 0) {
|
|
@@ -70907,8 +70923,9 @@ var SvgToPdfConverter = /*#__PURE__*/function () {
|
|
|
70907
70923
|
var _element$textContent,
|
|
70908
70924
|
_element$getAttribute,
|
|
70909
70925
|
_element$getAttribute2,
|
|
70910
|
-
_this = this
|
|
70911
|
-
|
|
70926
|
+
_this = this,
|
|
70927
|
+
_options$pageRotation3;
|
|
70928
|
+
var text, style, inlineStyles, x, y, fontSizeStr, fontSize, _this$transformPoint43, _this$transformPoint44, pdfX, pdfY, svgFontScale, fontScale, pdfFontSize, rawBoxH, pdfBoxH, maxPdfFs, textColor, opacity, mb, mapW, mapH, textAnchor, anchorOffsetX, pageRot, rotateOffset, drawLine, tspans, linesDrawn, lineYWorld, _iterator4, _step4, _tspan$textContent$tr, _tspan$textContent, tspan, lineText, tspanXAttr, lineXWorld, tspanYAttr, dyAttr, _this$transformPoint45, _this$transformPoint46, linePdfX, linePdfY, _element$getAttribute3, _t3;
|
|
70912
70929
|
return _regenerator().w(function (_context3) {
|
|
70913
70930
|
while (1) switch (_context3.p = _context3.n) {
|
|
70914
70931
|
case 0:
|
|
@@ -70962,9 +70979,25 @@ var SvgToPdfConverter = /*#__PURE__*/function () {
|
|
|
70962
70979
|
} catch (_unused) {
|
|
70963
70980
|
return 0;
|
|
70964
70981
|
}
|
|
70982
|
+
}; // Page /Rotate: glyphs must be rotated to read upright on the displayed page,
|
|
70983
|
+
// and the anchor (text-anchor X) + baseline (down) offsets — which are in the
|
|
70984
|
+
// displayed/text frame — must be rotated into the unrotated mediabox space.
|
|
70985
|
+
pageRot = (((_options$pageRotation3 = options.pageRotation) !== null && _options$pageRotation3 !== void 0 ? _options$pageRotation3 : 0) % 360 + 360) % 360; // Rotate a displayed-frame offset vector into mediabox space (same linear part
|
|
70986
|
+
// as the point mapping in transformPoint).
|
|
70987
|
+
rotateOffset = function rotateOffset(ox, oy) {
|
|
70988
|
+
switch (pageRot) {
|
|
70989
|
+
case 90:
|
|
70990
|
+
return [-oy, ox];
|
|
70991
|
+
case 180:
|
|
70992
|
+
return [-ox, -oy];
|
|
70993
|
+
case 270:
|
|
70994
|
+
return [oy, -ox];
|
|
70995
|
+
default:
|
|
70996
|
+
return [ox, oy];
|
|
70997
|
+
}
|
|
70965
70998
|
}; // ── Helper: draw one text line with fallback ──────────────────────────────
|
|
70999
|
+
// drawX/drawY is the line anchor already mapped into mediabox space.
|
|
70966
71000
|
drawLine = function drawLine(lineText, drawX, drawY) {
|
|
70967
|
-
var baselinePdfY = drawY - pdfFontSize * 0.8;
|
|
70968
71001
|
// Try primary font, then Helvetica per-line so export never stops.
|
|
70969
71002
|
for (var _i3 = 0, _arr = [[_this.currentFont, false], [_this.helveticaFont, true]]; _i3 < _arr.length; _i3++) {
|
|
70970
71003
|
var _arr$_i = _slicedToArray(_arr[_i3], 2),
|
|
@@ -70972,14 +71005,20 @@ var SvgToPdfConverter = /*#__PURE__*/function () {
|
|
|
70972
71005
|
isHelvetica = _arr$_i[1];
|
|
70973
71006
|
var safe = isHelvetica ? _this.safeText(lineText).replace(/[^\x20-\x7E]/g, '?') : _this.safeText(lineText);
|
|
70974
71007
|
var xOff = anchorOffsetX(safe, font);
|
|
71008
|
+
// Offset in the displayed/text frame: along text (xOff), baseline down (-0.8em).
|
|
71009
|
+
var _rotateOffset = rotateOffset(xOff, -pdfFontSize * 0.8),
|
|
71010
|
+
_rotateOffset2 = _slicedToArray(_rotateOffset, 2),
|
|
71011
|
+
offX = _rotateOffset2[0],
|
|
71012
|
+
offY = _rotateOffset2[1];
|
|
70975
71013
|
try {
|
|
70976
71014
|
pdfPage.drawText(safe, {
|
|
70977
|
-
x: drawX +
|
|
70978
|
-
y:
|
|
71015
|
+
x: drawX + offX,
|
|
71016
|
+
y: drawY + offY,
|
|
70979
71017
|
size: pdfFontSize,
|
|
70980
71018
|
font: font,
|
|
70981
71019
|
color: rgb(textColor.r, textColor.g, textColor.b),
|
|
70982
|
-
opacity: opacity
|
|
71020
|
+
opacity: opacity,
|
|
71021
|
+
rotate: degrees(pageRot)
|
|
70983
71022
|
});
|
|
70984
71023
|
if (isHelvetica) console.warn('[SvgToPdfConverter] drawText: used Helvetica fallback for line:', lineText);
|
|
70985
71024
|
return true;
|
|
@@ -71546,6 +71585,7 @@ var SvgToPdfConverter = /*#__PURE__*/function () {
|
|
|
71546
71585
|
}, {
|
|
71547
71586
|
key: "transformPoint",
|
|
71548
71587
|
value: function transformPoint(x, y, options, svgTransform) {
|
|
71588
|
+
var _options$pageRotation4;
|
|
71549
71589
|
// Apply SVG transform (translate, rotate, scale) first
|
|
71550
71590
|
var svgX = x;
|
|
71551
71591
|
var svgY = y;
|
|
@@ -71575,12 +71615,44 @@ var SvgToPdfConverter = /*#__PURE__*/function () {
|
|
|
71575
71615
|
var mapY = mb ? mb.minY : options.svgViewBox.y;
|
|
71576
71616
|
var mapW = mb ? mb.maxX - mb.minX : options.svgViewBox.width;
|
|
71577
71617
|
var mapH = mb ? mb.maxY - mb.minY : options.svgViewBox.height;
|
|
71578
|
-
|
|
71579
|
-
var
|
|
71580
|
-
var
|
|
71618
|
+
// Raw (unrotated) mediabox dims — pdf-lib draws into this space.
|
|
71619
|
+
var rawW = options.pageWidth;
|
|
71620
|
+
var rawH = options.pageHeight;
|
|
71621
|
+
var rot = (((_options$pageRotation4 = options.pageRotation) !== null && _options$pageRotation4 !== void 0 ? _options$pageRotation4 : 0) % 360 + 360) % 360;
|
|
71622
|
+
var quarter = rot === 90 || rot === 270;
|
|
71623
|
+
// Displayed page dims = the orientation the markup was authored in. For a
|
|
71624
|
+
// 90/270 rotation the visible page is the mediabox with width/height swapped,
|
|
71625
|
+
// so we must scale into the swapped dims (otherwise X/Y scale differ → stretch).
|
|
71626
|
+
var dispW = quarter ? rawH : rawW;
|
|
71627
|
+
var dispH = quarter ? rawW : rawH;
|
|
71628
|
+
var scaleX = dispW / mapW;
|
|
71629
|
+
var scaleY = dispH / mapH;
|
|
71630
|
+
// Displayed-space coords (origin bottom-left of the *visible* page, Y-up).
|
|
71631
|
+
var dx = (svgX - mapX) * scaleX;
|
|
71581
71632
|
// When SVG has CSS scale(1,-1), coordinates are already Y-up (like PDF)
|
|
71582
71633
|
// so we map directly. Otherwise flip Y (SVG Y-down → PDF Y-up).
|
|
71583
|
-
var
|
|
71634
|
+
var dy = this.isYFlipped ? (svgY - mapY) * scaleY : dispH - (svgY - mapY) * scaleY;
|
|
71635
|
+
// Map displayed coords → unrotated mediabox space by inverting the page
|
|
71636
|
+
// /Rotate, so markup lines up with the rotated page content.
|
|
71637
|
+
var pdfX;
|
|
71638
|
+
var pdfY;
|
|
71639
|
+
switch (rot) {
|
|
71640
|
+
case 90:
|
|
71641
|
+
pdfX = rawW - dy;
|
|
71642
|
+
pdfY = dx;
|
|
71643
|
+
break;
|
|
71644
|
+
case 180:
|
|
71645
|
+
pdfX = rawW - dx;
|
|
71646
|
+
pdfY = rawH - dy;
|
|
71647
|
+
break;
|
|
71648
|
+
case 270:
|
|
71649
|
+
pdfX = dy;
|
|
71650
|
+
pdfY = rawH - dx;
|
|
71651
|
+
break;
|
|
71652
|
+
default:
|
|
71653
|
+
pdfX = dx;
|
|
71654
|
+
pdfY = dy;
|
|
71655
|
+
}
|
|
71584
71656
|
return [pdfX, pdfY];
|
|
71585
71657
|
}
|
|
71586
71658
|
/**
|
|
@@ -72106,7 +72178,8 @@ var MarkupExportService = /*#__PURE__*/function () {
|
|
|
72106
72178
|
pageWidth: width,
|
|
72107
72179
|
pageHeight: height,
|
|
72108
72180
|
svgViewBox: svgViewBox,
|
|
72109
|
-
modelBounds: modelBounds
|
|
72181
|
+
modelBounds: modelBounds,
|
|
72182
|
+
pageRotation: page.getRotation().angle
|
|
72110
72183
|
}; // Draw markup on page
|
|
72111
72184
|
_context.n = 8;
|
|
72112
72185
|
return this.converter.drawSvgOnPdfPage(svgString, page, converterOptions);
|
|
@@ -93865,9 +93938,9 @@ var CanvasExportService = /*#__PURE__*/function () {
|
|
|
93865
93938
|
scene,
|
|
93866
93939
|
_msg,
|
|
93867
93940
|
_error,
|
|
93868
|
-
svgString,
|
|
93869
93941
|
sceneBounds,
|
|
93870
93942
|
svgViewBox,
|
|
93943
|
+
svgString,
|
|
93871
93944
|
modelBounds,
|
|
93872
93945
|
pb,
|
|
93873
93946
|
avgStrokePt,
|
|
@@ -93987,7 +94060,14 @@ var CanvasExportService = /*#__PURE__*/function () {
|
|
|
93987
94060
|
_error.code = 'MISSING_PAGE_BOUNDS';
|
|
93988
94061
|
throw _error;
|
|
93989
94062
|
case 13:
|
|
93990
|
-
|
|
94063
|
+
sceneBounds = SceneToSvg.computeBounds(scene); // SVG viewBox: use full page bounds if available, else shape bounding box.
|
|
94064
|
+
// The viewBox must cover all shapes so nothing is clipped.
|
|
94065
|
+
svgViewBox = (_ref = (_scene$pageBounds = scene.pageBounds) !== null && _scene$pageBounds !== void 0 ? _scene$pageBounds : scene.viewportBounds) !== null && _ref !== void 0 ? _ref : sceneBounds; // Build the SVG with the SAME viewBox used for PDF coordinate mapping below.
|
|
94066
|
+
// SceneToSvg derives its viewBox attribute AND the Y-flip (translate/scale(1,-1))
|
|
94067
|
+
// from this rect; if it defaulted to viewportBounds while the converter maps via
|
|
94068
|
+
// modelBounds (=pageBounds), the flip origin and the mapping disagree → markup is
|
|
94069
|
+
// mispositioned. Passing svgViewBox keeps both consistent.
|
|
94070
|
+
svgString = SceneToSvg.convert(scene, svgViewBox);
|
|
93991
94071
|
if (svgString) {
|
|
93992
94072
|
_context2.n = 14;
|
|
93993
94073
|
break;
|
|
@@ -93995,9 +94075,7 @@ var CanvasExportService = /*#__PURE__*/function () {
|
|
|
93995
94075
|
console.debug("[CanvasExportService] page ".concat(pageIndex, ": SceneToSvg returned empty"));
|
|
93996
94076
|
return _context2.a(3, 15);
|
|
93997
94077
|
case 14:
|
|
93998
|
-
|
|
93999
|
-
// The viewBox must cover all shapes so nothing is clipped.
|
|
94000
|
-
svgViewBox = (_ref = (_scene$pageBounds = scene.pageBounds) !== null && _scene$pageBounds !== void 0 ? _scene$pageBounds : scene.viewportBounds) !== null && _ref !== void 0 ? _ref : sceneBounds; // modelBounds: the full page extent in world coordinates.
|
|
94078
|
+
// modelBounds: the full page extent in world coordinates.
|
|
94001
94079
|
// CRITICAL: must be the full PDF page, not just the shape bounding box.
|
|
94002
94080
|
// Using the shape bounding box stretches markup to fill the page (wrong scale/position).
|
|
94003
94081
|
// pageBounds is captured from viewer.model.getBoundingBox() at save time.
|