@drghaliasri/butex 7.4.1 → 7.4.2

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
@@ -910,7 +910,7 @@ function unitArgument(parser, name) {
910
910
  const node = parser.create(
911
911
  "token",
912
912
  "mtext",
913
- { class: "butex-unit-text", "data-butex-unit": text },
913
+ { class: "butex-unit-text", "data-butex-unit": text, "data-butex-svg-text": text },
914
914
  text
915
915
  );
916
916
  parser.Push(node);
@@ -7837,6 +7837,15 @@ var BOLD_LAYOUT = {
7837
7837
  baselineShift: 0,
7838
7838
  fontWeight: 700
7839
7839
  };
7840
+ var UNIT_LAYOUT = {
7841
+ key: "unit",
7842
+ stack: BOLD_LAYOUT.stack,
7843
+ height: 0.75,
7844
+ depth: 0.25,
7845
+ drawScale: 1,
7846
+ baselineShift: 0,
7847
+ fontWeight: 400
7848
+ };
7840
7849
  var FONT_LAYOUTS = Object.fromEntries(
7841
7850
  NON_DEFAULT_CHARACTER_FONT_SPECS.filter((font) => font.svgLayoutKey && font.browserFontStack).map((font) => {
7842
7851
  const key = font.svgLayoutKey;
@@ -7860,6 +7869,9 @@ function fontLayoutForClass(className) {
7860
7869
  if (classes.includes("butex-bold-text")) {
7861
7870
  return BOLD_LAYOUT;
7862
7871
  }
7872
+ if (classes.includes("butex-unit-text")) {
7873
+ return UNIT_LAYOUT;
7874
+ }
7863
7875
  for (const font of NON_DEFAULT_CHARACTER_FONT_SPECS) {
7864
7876
  if (font.mathJaxClass && font.svgLayoutKey && classes.includes(font.mathJaxClass)) {
7865
7877
  return FONT_LAYOUTS[font.svgLayoutKey] ?? null;
@@ -7898,7 +7910,7 @@ function getSvgGraphicsBox(node) {
7898
7910
  function formatSvgNumber(value) {
7899
7911
  return Number.isFinite(value) ? value.toFixed(3).replace(/\.?0+$/, "") : "0";
7900
7912
  }
7901
- function measureAdvance(wrapper, text, fontStack) {
7913
+ function measureAdvance(wrapper, text, font) {
7902
7914
  const jax = wrapper.jax;
7903
7915
  const adaptor = jax.adaptor;
7904
7916
  const body = adaptor.document == null ? null : adaptor.body(adaptor.document);
@@ -7910,16 +7922,16 @@ function measureAdvance(wrapper, text, fontStack) {
7910
7922
  {
7911
7923
  x: 0,
7912
7924
  y: 0,
7913
- "font-family": fontStack,
7925
+ "font-family": font.stack,
7914
7926
  "font-size": EM,
7915
- "font-weight": fontStack === BOLD_LAYOUT.stack ? BOLD_LAYOUT.fontWeight : void 0,
7927
+ "font-weight": font.fontWeight,
7916
7928
  "text-anchor": "end",
7917
7929
  direction: "rtl",
7918
7930
  "unicode-bidi": "isolate",
7919
7931
  "dominant-baseline": "alphabetic",
7920
7932
  style: {
7921
- "font-family": fontStack,
7922
- "font-weight": fontStack === BOLD_LAYOUT.stack ? BOLD_LAYOUT.fontWeight : void 0,
7933
+ "font-family": font.stack,
7934
+ "font-weight": font.fontWeight,
7923
7935
  direction: "rtl",
7924
7936
  "unicode-bidi": "isolate"
7925
7937
  }
@@ -7962,7 +7974,7 @@ function metricsFor(wrapper) {
7962
7974
  if (!text || !font) {
7963
7975
  return null;
7964
7976
  }
7965
- const measured = measureAdvance(wrapper, text, font.stack);
7977
+ const measured = measureAdvance(wrapper, text, font);
7966
7978
  const charCount = Math.max(1, Array.from(text).length);
7967
7979
  const anchorUnits = measured ? measured.anchorUnits : charCount * FALLBACK_CHAR_WIDTH * EM;
7968
7980
  const widthUnits = measured ? measured.widthUnits : charCount * FALLBACK_CHAR_WIDTH * EM;