@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.mjs CHANGED
@@ -868,7 +868,7 @@ function unitArgument(parser, name) {
868
868
  const node = parser.create(
869
869
  "token",
870
870
  "mtext",
871
- { class: "butex-unit-text", "data-butex-unit": text },
871
+ { class: "butex-unit-text", "data-butex-unit": text, "data-butex-svg-text": text },
872
872
  text
873
873
  );
874
874
  parser.Push(node);
@@ -7795,6 +7795,15 @@ var BOLD_LAYOUT = {
7795
7795
  baselineShift: 0,
7796
7796
  fontWeight: 700
7797
7797
  };
7798
+ var UNIT_LAYOUT = {
7799
+ key: "unit",
7800
+ stack: BOLD_LAYOUT.stack,
7801
+ height: 0.75,
7802
+ depth: 0.25,
7803
+ drawScale: 1,
7804
+ baselineShift: 0,
7805
+ fontWeight: 400
7806
+ };
7798
7807
  var FONT_LAYOUTS = Object.fromEntries(
7799
7808
  NON_DEFAULT_CHARACTER_FONT_SPECS.filter((font) => font.svgLayoutKey && font.browserFontStack).map((font) => {
7800
7809
  const key = font.svgLayoutKey;
@@ -7818,6 +7827,9 @@ function fontLayoutForClass(className) {
7818
7827
  if (classes.includes("butex-bold-text")) {
7819
7828
  return BOLD_LAYOUT;
7820
7829
  }
7830
+ if (classes.includes("butex-unit-text")) {
7831
+ return UNIT_LAYOUT;
7832
+ }
7821
7833
  for (const font of NON_DEFAULT_CHARACTER_FONT_SPECS) {
7822
7834
  if (font.mathJaxClass && font.svgLayoutKey && classes.includes(font.mathJaxClass)) {
7823
7835
  return FONT_LAYOUTS[font.svgLayoutKey] ?? null;
@@ -7856,7 +7868,7 @@ function getSvgGraphicsBox(node) {
7856
7868
  function formatSvgNumber(value) {
7857
7869
  return Number.isFinite(value) ? value.toFixed(3).replace(/\.?0+$/, "") : "0";
7858
7870
  }
7859
- function measureAdvance(wrapper, text, fontStack) {
7871
+ function measureAdvance(wrapper, text, font) {
7860
7872
  const jax = wrapper.jax;
7861
7873
  const adaptor = jax.adaptor;
7862
7874
  const body = adaptor.document == null ? null : adaptor.body(adaptor.document);
@@ -7868,16 +7880,16 @@ function measureAdvance(wrapper, text, fontStack) {
7868
7880
  {
7869
7881
  x: 0,
7870
7882
  y: 0,
7871
- "font-family": fontStack,
7883
+ "font-family": font.stack,
7872
7884
  "font-size": EM,
7873
- "font-weight": fontStack === BOLD_LAYOUT.stack ? BOLD_LAYOUT.fontWeight : void 0,
7885
+ "font-weight": font.fontWeight,
7874
7886
  "text-anchor": "end",
7875
7887
  direction: "rtl",
7876
7888
  "unicode-bidi": "isolate",
7877
7889
  "dominant-baseline": "alphabetic",
7878
7890
  style: {
7879
- "font-family": fontStack,
7880
- "font-weight": fontStack === BOLD_LAYOUT.stack ? BOLD_LAYOUT.fontWeight : void 0,
7891
+ "font-family": font.stack,
7892
+ "font-weight": font.fontWeight,
7881
7893
  direction: "rtl",
7882
7894
  "unicode-bidi": "isolate"
7883
7895
  }
@@ -7920,7 +7932,7 @@ function metricsFor(wrapper) {
7920
7932
  if (!text || !font) {
7921
7933
  return null;
7922
7934
  }
7923
- const measured = measureAdvance(wrapper, text, font.stack);
7935
+ const measured = measureAdvance(wrapper, text, font);
7924
7936
  const charCount = Math.max(1, Array.from(text).length);
7925
7937
  const anchorUnits = measured ? measured.anchorUnits : charCount * FALLBACK_CHAR_WIDTH * EM;
7926
7938
  const widthUnits = measured ? measured.widthUnits : charCount * FALLBACK_CHAR_WIDTH * EM;