wordinweb 0.2.3 → 0.2.5

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.
@@ -5448,6 +5448,7 @@ function parseVmlPict(pict, ctx) {
5448
5448
  const strokeColor = el16.attrs["strokecolor"];
5449
5449
  const stroked = el16.attrs["stroked"] !== "f" && strokeColor !== void 0;
5450
5450
  const ta = style.get("v-text-anchor");
5451
+ const rotation = parseFloat(style.get("rotation") ?? "0") || 0;
5451
5452
  const vmlInsets = parseVmlInset(findDescendant(el16, "textbox")?.attrs["inset"]);
5452
5453
  out.push({
5453
5454
  kind: "anchor",
@@ -5471,6 +5472,7 @@ function parseVmlPict(pict, ctx) {
5471
5472
  pctWidthRel: relOf(style.get("mso-width-relative")),
5472
5473
  pctHeightRel: relOf(style.get("mso-height-relative")),
5473
5474
  textAnchor: ta === "middle" ? "middle" : ta === "bottom" ? "bottom" : void 0,
5475
+ ...rotation ? { rotation } : {},
5474
5476
  ...vmlInsets ? { insets: vmlInsets } : {},
5475
5477
  srcDrawing: el16,
5476
5478
  ...ctx.independentTextboxStories ? { textboxStory: true } : {}
@@ -22774,6 +22776,12 @@ function insertWordArtAt(doc, caretT, text, preset = "plain") {
22774
22776
  }[preset];
22775
22777
  const docPr = descendant3(drawing, "docPr");
22776
22778
  if (docPr) docPr.attrs.name = `WordArt ${docPr.attrs.id}`;
22779
+ const anchor = descendant3(drawing, "anchor");
22780
+ if (anchor) {
22781
+ const wrap = anchor.children.findIndex((child4) => localName(child4.name).startsWith("wrap"));
22782
+ if (wrap !== -1) anchor.children[wrap] = el6("wp:wrapNone");
22783
+ anchor.attrs.behindDoc = "0";
22784
+ }
22777
22785
  if (preset === "plain") {
22778
22786
  const height = String(Math.round(40 * EMU_PER_PX4));
22779
22787
  const extent = descendant3(drawing, "extent");
@@ -22794,8 +22802,39 @@ function insertWordArtAt(doc, caretT, text, preset = "plain") {
22794
22802
  if (color) color.attrs[Object.keys(color.attrs).find((key) => localName(key) === "val") ?? `${prefixOf8(color)}val`] = "2E74B5";
22795
22803
  if (size) size.attrs[Object.keys(size.attrs).find((key) => localName(key) === "val") ?? `${prefixOf8(size)}val`] = "40";
22796
22804
  }
22805
+ const paragraphProperties = descendant3(drawing, "pPr");
22806
+ const justification = paragraphProperties ? descendant3(paragraphProperties, "jc") : void 0;
22807
+ if (justification) {
22808
+ const valueKey = Object.keys(justification.attrs).find((key) => localName(key) === "val") ?? `${prefixOf8(justification)}val`;
22809
+ justification.attrs[valueKey] = "center";
22810
+ }
22797
22811
  const bodyPr = descendant3(drawing, "bodyPr");
22798
- if (bodyPr) bodyPr.children.unshift(el6("a:prstTxWarp", { prst: warp }, [el6("a:avLst")]));
22812
+ if (bodyPr) {
22813
+ bodyPr.attrs = {
22814
+ rot: "0",
22815
+ spcFirstLastPara: "1",
22816
+ vertOverflow: "overflow",
22817
+ horzOverflow: "overflow",
22818
+ vert: "horz",
22819
+ wrap: "none",
22820
+ lIns: "91440",
22821
+ tIns: "45720",
22822
+ rIns: "91440",
22823
+ bIns: "45720",
22824
+ numCol: "1",
22825
+ spcCol: "0",
22826
+ rtlCol: "0",
22827
+ fromWordArt: "0",
22828
+ anchor: "t",
22829
+ anchorCtr: "0",
22830
+ forceAA: "0",
22831
+ compatLnSpc: "1"
22832
+ };
22833
+ bodyPr.children = [
22834
+ el6("a:prstTxWarp", { prst: warp }, [el6("a:avLst")]),
22835
+ el6("a:noAutofit")
22836
+ ];
22837
+ }
22799
22838
  doc.refresh();
22800
22839
  return drawing;
22801
22840
  }
@@ -22953,8 +22992,39 @@ var NS_WP4 = "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDra
22953
22992
  function el7(name, attrs = {}, children2 = [], text = "") {
22954
22993
  return { name, attrs, children: children2, text };
22955
22994
  }
22995
+ function isVmlShape(el16) {
22996
+ return ["shape", "rect"].includes(localName(el16.name));
22997
+ }
22998
+ function vmlStyle(el16) {
22999
+ const style = /* @__PURE__ */ new Map();
23000
+ for (const declaration of (el16.attrs.style ?? "").split(";")) {
23001
+ const colon = declaration.indexOf(":");
23002
+ if (colon > 0) style.set(declaration.slice(0, colon).trim(), declaration.slice(colon + 1).trim());
23003
+ }
23004
+ return style;
23005
+ }
23006
+ function setVmlStyle(el16, patch) {
23007
+ const style = vmlStyle(el16);
23008
+ for (const [key, value] of Object.entries(patch)) {
23009
+ if (value === null) style.delete(key);
23010
+ else style.set(key, value);
23011
+ }
23012
+ el16.attrs.style = [...style].map(([key, value]) => `${key}:${value}`).join(";");
23013
+ }
23014
+ function vmlLengthPx(raw) {
23015
+ if (!raw) return 0;
23016
+ const match = /^(-?[\d.]+)\s*(pt|in|px)?$/.exec(raw.trim());
23017
+ if (!match) return 0;
23018
+ const value = parseFloat(match[1]);
23019
+ if (match[2] === "pt") return value * 4 / 3;
23020
+ if (match[2] === "in") return value * 96;
23021
+ return value;
23022
+ }
23023
+ function pxToVmlPt(px) {
23024
+ return `${Math.round(px * 75) / 100}pt`;
23025
+ }
22956
23026
  function isFloatingDrawing(drawingEl) {
22957
- return !!child(drawingEl, "anchor");
23027
+ return !!child(drawingEl, "anchor") || isVmlShape(drawingEl) && vmlStyle(drawingEl).get("position") === "absolute";
22958
23028
  }
22959
23029
  function imageAltText(drawingEl) {
22960
23030
  const holder = child(drawingEl, "inline") ?? child(drawingEl, "anchor");
@@ -23069,7 +23139,20 @@ function setFloatingPosition(doc, drawingEl, xPx, yPx) {
23069
23139
  }
23070
23140
  function setFloatingPagePosition(doc, drawingEl, xPx, yPx) {
23071
23141
  const anchor = child(drawingEl, "anchor");
23072
- if (!anchor) return false;
23142
+ if (!anchor) {
23143
+ if (!isVmlShape(drawingEl)) return false;
23144
+ setVmlStyle(drawingEl, {
23145
+ position: "absolute",
23146
+ "margin-left": pxToVmlPt(xPx),
23147
+ "margin-top": pxToVmlPt(yPx),
23148
+ "mso-position-horizontal": "absolute",
23149
+ "mso-position-horizontal-relative": "page",
23150
+ "mso-position-vertical": "absolute",
23151
+ "mso-position-vertical-relative": "page"
23152
+ });
23153
+ doc.refresh();
23154
+ return true;
23155
+ }
23073
23156
  const set = (posName, px) => {
23074
23157
  let posEl = child(anchor, posName);
23075
23158
  if (!posEl) {
@@ -23088,7 +23171,16 @@ function setFloatingPagePosition(doc, drawingEl, xPx, yPx) {
23088
23171
  }
23089
23172
  function adjustFloatingPosition(doc, drawingEl, dxPx, dyPx) {
23090
23173
  const anchor = child(drawingEl, "anchor");
23091
- if (!anchor) return false;
23174
+ if (!anchor) {
23175
+ if (!isVmlShape(drawingEl) || !isFloatingDrawing(drawingEl)) return false;
23176
+ const style = vmlStyle(drawingEl);
23177
+ setVmlStyle(drawingEl, {
23178
+ "margin-left": pxToVmlPt(vmlLengthPx(style.get("margin-left")) + dxPx),
23179
+ "margin-top": pxToVmlPt(vmlLengthPx(style.get("margin-top")) + dyPx)
23180
+ });
23181
+ doc.refresh();
23182
+ return true;
23183
+ }
23092
23184
  const bump = (posName, deltaPx) => {
23093
23185
  const posEl = child(anchor, posName);
23094
23186
  if (!posEl) return;
@@ -23118,13 +23210,19 @@ function drawingTransform(drawingEl) {
23118
23210
  }
23119
23211
  function drawingRotation(drawingEl) {
23120
23212
  const xfrm = drawingTransform(drawingEl);
23121
- if (!xfrm) return 0;
23213
+ if (!xfrm) return isVmlShape(drawingEl) ? parseFloat(vmlStyle(drawingEl).get("rotation") ?? "0") || 0 : 0;
23122
23214
  const key = Object.keys(xfrm.attrs).find((k) => localName(k) === "rot");
23123
23215
  return key ? (parseInt(xfrm.attrs[key], 10) || 0) / 6e4 : 0;
23124
23216
  }
23125
23217
  function setDrawingRotation(doc, drawingEl, degrees) {
23126
23218
  const xfrm = drawingTransform(drawingEl);
23127
- if (!xfrm) return false;
23219
+ if (!xfrm) {
23220
+ if (!isVmlShape(drawingEl)) return false;
23221
+ const normalized2 = (degrees % 360 + 360) % 360;
23222
+ setVmlStyle(drawingEl, { rotation: normalized2 === 0 ? null : String(Math.round(normalized2 * 100) / 100) });
23223
+ doc.refresh();
23224
+ return true;
23225
+ }
23128
23226
  const key = Object.keys(xfrm.attrs).find((k) => localName(k) === "rot") ?? "rot";
23129
23227
  const normalized = (degrees % 360 + 360) % 360;
23130
23228
  if (normalized === 0) delete xfrm.attrs[key];
@@ -38342,4 +38440,4 @@ export {
38342
38440
  cfb/cfb.js:
38343
38441
  (*! crc32.js (C) 2014-present SheetJS -- http://sheetjs.com *)
38344
38442
  */
38345
- //# sourceMappingURL=chunk-OIN65MGS.js.map
38443
+ //# sourceMappingURL=chunk-ALLQ5KWP.js.map