@dtducas/wh-forge-viewer 3.0.0-beta.7 → 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.js CHANGED
@@ -70923,8 +70923,9 @@ var SvgToPdfConverter = /*#__PURE__*/function () {
70923
70923
  var _element$textContent,
70924
70924
  _element$getAttribute,
70925
70925
  _element$getAttribute2,
70926
- _this = this;
70927
- 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, 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;
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;
70928
70929
  return _regenerator().w(function (_context3) {
70929
70930
  while (1) switch (_context3.p = _context3.n) {
70930
70931
  case 0:
@@ -70978,9 +70979,25 @@ var SvgToPdfConverter = /*#__PURE__*/function () {
70978
70979
  } catch (_unused) {
70979
70980
  return 0;
70980
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
+ }
70981
70998
  }; // ── Helper: draw one text line with fallback ──────────────────────────────
70999
+ // drawX/drawY is the line anchor already mapped into mediabox space.
70982
71000
  drawLine = function drawLine(lineText, drawX, drawY) {
70983
- var baselinePdfY = drawY - pdfFontSize * 0.8;
70984
71001
  // Try primary font, then Helvetica per-line so export never stops.
70985
71002
  for (var _i3 = 0, _arr = [[_this.currentFont, false], [_this.helveticaFont, true]]; _i3 < _arr.length; _i3++) {
70986
71003
  var _arr$_i = _slicedToArray(_arr[_i3], 2),
@@ -70988,14 +71005,20 @@ var SvgToPdfConverter = /*#__PURE__*/function () {
70988
71005
  isHelvetica = _arr$_i[1];
70989
71006
  var safe = isHelvetica ? _this.safeText(lineText).replace(/[^\x20-\x7E]/g, '?') : _this.safeText(lineText);
70990
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];
70991
71013
  try {
70992
71014
  pdfPage.drawText(safe, {
70993
- x: drawX + xOff,
70994
- y: baselinePdfY,
71015
+ x: drawX + offX,
71016
+ y: drawY + offY,
70995
71017
  size: pdfFontSize,
70996
71018
  font: font,
70997
71019
  color: rgb(textColor.r, textColor.g, textColor.b),
70998
- opacity: opacity
71020
+ opacity: opacity,
71021
+ rotate: degrees(pageRot)
70999
71022
  });
71000
71023
  if (isHelvetica) console.warn('[SvgToPdfConverter] drawText: used Helvetica fallback for line:', lineText);
71001
71024
  return true;
@@ -71562,7 +71585,7 @@ var SvgToPdfConverter = /*#__PURE__*/function () {
71562
71585
  }, {
71563
71586
  key: "transformPoint",
71564
71587
  value: function transformPoint(x, y, options, svgTransform) {
71565
- var _options$pageRotation3;
71588
+ var _options$pageRotation4;
71566
71589
  // Apply SVG transform (translate, rotate, scale) first
71567
71590
  var svgX = x;
71568
71591
  var svgY = y;
@@ -71595,7 +71618,7 @@ var SvgToPdfConverter = /*#__PURE__*/function () {
71595
71618
  // Raw (unrotated) mediabox dims — pdf-lib draws into this space.
71596
71619
  var rawW = options.pageWidth;
71597
71620
  var rawH = options.pageHeight;
71598
- var rot = (((_options$pageRotation3 = options.pageRotation) !== null && _options$pageRotation3 !== void 0 ? _options$pageRotation3 : 0) % 360 + 360) % 360;
71621
+ var rot = (((_options$pageRotation4 = options.pageRotation) !== null && _options$pageRotation4 !== void 0 ? _options$pageRotation4 : 0) % 360 + 360) % 360;
71599
71622
  var quarter = rot === 90 || rot === 270;
71600
71623
  // Displayed page dims = the orientation the markup was authored in. For a
71601
71624
  // 90/270 rotation the visible page is the mediabox with width/height swapped,