guidex 0.2.4 → 0.2.6

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/README.md CHANGED
@@ -18,7 +18,9 @@ The package ships a typed ESM build with an exports map:
18
18
 
19
19
  - **`guidex`** — imperative API, no side effects:
20
20
  `renderScore(el, source, options?)`, `renderAll(root?)`,
21
- `init(options?)`, `dispose(el)`, plus the parser and style sets.
21
+ `init(options?)`, `dispose(el)`, plus the sung-text helpers
22
+ (`chantText(script)`, the `GuidoScript` parser, `unescape`) and the
23
+ style sets (`STYLE_SETS`, `DEFAULT_STYLE_SET`, `StyleSetName`).
22
24
  - **`guidex/react`** — the `GuidexScore` client component (`'use client'`
23
25
  marked, works in Next.js App Router Server Components). React ≥ 18 is
24
26
  an optional peer dependency; only React users install it.
@@ -36,7 +38,22 @@ relative `./fonts/…` URLs, so bundlers must see the package's
36
38
  import { renderScore } from 'guidex'
37
39
  import 'guidex/guidex.css'
38
40
 
39
- renderScore(document.querySelector('#score'), '(c4) Fat(2)ue(2)', { textPx: 22 })
41
+ renderScore(document.querySelector('#score'), '(M)A(0) di(0q)e(qQ0)bus(1) an(3)ti(1e)quis(qQ0-:)', { textPx: 22 })
42
+ ```
43
+
44
+ ### Sung text
45
+
46
+ The parser is exported too, so you can pull the sung text out of a
47
+ script — for a lyrics column, a search index, and the like:
48
+
49
+ ```js
50
+ import { chantText, GuidoScript } from 'guidex'
51
+
52
+ chantText('(M)A(0) di(0q)e(qQ0)bus(1) an(3)ti(1e)quis(qQ0-:)') // 'A diebus antiquis'
53
+ new GuidoScript('(M)A(0) di(0q)e(qQ0)bus(1) an(3)ti(1e)quis(qQ0-:)').words
54
+ // [{ text: 'A', syllables: [{ text: 'A', notes: '0' }] },
55
+ // { text: 'diebus', syllables: [{ text: 'di', notes: '0q' }, { text: 'e', notes: 'qQ0' }, { text: 'bus', notes: '1' }] },
56
+ // { text: 'antiquis', syllables: [{ text: 'an', notes: '3' }, { text: 'ti', notes: '1e' }, { text: 'quis', notes: 'qQ0-:' }] }]
40
57
  ```
41
58
 
42
59
  ### React / Next.js
@@ -45,7 +62,7 @@ renderScore(document.querySelector('#score'), '(c4) Fat(2)ue(2)', { textPx: 22 }
45
62
  import { GuidexScore } from 'guidex/react'
46
63
  import 'guidex/guidex.css'
47
64
 
48
- <GuidexScore script="(c4) Fat(2)ue(2)" textPx={22} />
65
+ <GuidexScore script="(M)A(0) di(0q)e(qQ0)bus(1) an(3)ti(1e)quis(qQ0-:)" textPx={22} />
49
66
  ```
50
67
 
51
68
  `GuidexScore` renders into a div on mount, re-renders on resize, and
@@ -59,6 +59,11 @@ var GuidoScript = class {
59
59
  return `${this.clef !== void 0 ? `(${this.clef})` : ""}${parts.join("")}`;
60
60
  }
61
61
  };
62
+ /** The sung text of the script: the clef stripped, syllables joined
63
+ * into words, and the words joined with single spaces. */
64
+ function chantText(script) {
65
+ return new GuidoScript(script).words.map((word) => word.text).join(" ");
66
+ }
62
67
  /** Folds backslash escapes into the characters they stand for. Shared
63
68
  * with the transforms module (guidoScriptTransforms.ts). */
64
69
  function unescape(text) {
@@ -70,6 +75,62 @@ function escape(text) {
70
75
  }
71
76
  //#endregion
72
77
  //#region src/guidoScriptTransforms.ts
78
+ /**
79
+ * Source-level transformations for GuidoScript: named rewrites applied
80
+ * to a script's raw source before parsing (see the `transforms` option
81
+ * on the GuidoScript constructor). Each one receives the source and
82
+ * returns the rewritten source — or the source unchanged when the
83
+ * feature does not apply. They compose in registration order, and the
84
+ * parsed script never sees which ones ran. New script-level features
85
+ * are added here, and only here: as entries of SCRIPT_TRANSFORMS, or —
86
+ * when the feature takes parameters — as factories returning a
87
+ * ScriptTransform (see `transposeBy`).
88
+ */
89
+ /** The first character unit of a text run: a backslash escape pair or a
90
+ * single character, skipping leading whitespace. Returns null when the
91
+ * run has no characters to mark. */
92
+ function firstCharUnit(text) {
93
+ const chars = [...text];
94
+ for (let i = 0; i < chars.length; i++) {
95
+ const ch = chars[i];
96
+ if (/\s/.test(ch)) continue;
97
+ return {
98
+ unit: ch === "\\" && chars[i + 1] !== void 0 ? ch + chars[i + 1] : ch,
99
+ index: i
100
+ };
101
+ }
102
+ return null;
103
+ }
104
+ /** The `startWithInitial` transform: finds the first syllable group with
105
+ * actual notes (the clef and no-notes groups don't count) and wraps the
106
+ * syllable's first character in the `*…*` initial marker. Already-marked
107
+ * text (leading `*`) and syllables without text are left alone. */
108
+ function startWithInitial(source) {
109
+ const clefMatch = source.match(/^\s*\(([^)]*)\)/);
110
+ const offset = clefMatch ? clefMatch[0].length : 0;
111
+ const rest = source.slice(offset);
112
+ for (const match of rest.matchAll(/((?:[^()\\]|\\.)*)\(((?:[^)\\]|\\.)*)\)/g)) {
113
+ const [, text, notes] = match;
114
+ if (unescape(notes).trim().length === 0) continue;
115
+ const unit = firstCharUnit(text);
116
+ if (!unit || text.trimStart().startsWith("*")) return source;
117
+ const unitStart = offset + match.index + unit.index;
118
+ const unitEnd = unitStart + unit.unit.length;
119
+ return `${source.slice(0, unitStart)}*${source.slice(unitStart, unitEnd)}*${source.slice(unitEnd)}`;
120
+ }
121
+ return source;
122
+ }
123
+ /**
124
+ * The built-in transformations, keyed by name; pass the ones a feature
125
+ * needs to the GuidoScript constructor.
126
+ */
127
+ var SCRIPT_TRANSFORMS = {
128
+ /** Wraps the first letter of the first syllable that has notes in
129
+ * `*…*`, the initial marker of the style marking system. */
130
+ startWithInitial: {
131
+ name: "startWithInitial",
132
+ apply: startWithInitial
133
+ } };
73
134
  /** The pitch rows of the chant font: every character carrying pitch
74
135
  * information, grouped into rows of neighbouring pitches from low to
75
136
  * high. A transpose shift moves a character this many positions along
@@ -144,6 +205,11 @@ function transposeBy(shift, options = {}) {
144
205
  }
145
206
  //#endregion
146
207
  //#region src/guidoStyles.ts
208
+ /**
209
+ * Style sets for the renderer: named appearance rules (fonts, colors, and
210
+ * the special syllable decorations) kept in one constant registry, so a
211
+ * new style is a data entry here rather than a renderer fork.
212
+ */
147
213
  /** Text characters (* and †) rendered in Times New Roman. */
148
214
  var TIMES_MARKER_GLYPHS = {
149
215
  chars: /* @__PURE__ */ new Set(["*", "†"]),
@@ -206,7 +272,8 @@ var STYLE_SETS = {
206
272
  raise: .1,
207
273
  color: "var(--red)"
208
274
  },
209
- padding: 12
275
+ padding: 12,
276
+ scriptTransforms: [SCRIPT_TRANSFORMS.startWithInitial]
210
277
  },
211
278
  /** Times New Roman text, strictly black and white. */
212
279
  Vesperale: {
@@ -251,9 +318,11 @@ var STYLE_SETS = {
251
318
  measureScale: .95,
252
319
  raise: .2
253
320
  },
254
- padding: 12
321
+ padding: 12,
322
+ scriptTransforms: []
255
323
  }
256
324
  };
325
+ var DEFAULT_STYLE_SET = "BNS";
257
326
  /**
258
327
  * Resolves a syllable's raw text into the runs it renders as: the whole-
259
328
  * syllable `**` star renders as the bold ∗ operator, a `__…__` or `_…_`
@@ -864,7 +933,7 @@ var GuidoRender = class GuidoRender {
864
933
  //#region src/embed/core.ts
865
934
  var version = {
866
935
  name: "guidex",
867
- version: "0.2.4",
936
+ version: "0.2.6",
868
937
  description: "Guidex — render plainchant scores from a compact GuidoScript notation, as a web app and an embeddable runtime",
869
938
  type: "module",
870
939
  workspaces: ["examples/*"],
@@ -1032,6 +1101,14 @@ function renderError(wrapper, message) {
1032
1101
  note.textContent = message;
1033
1102
  wrapper.replaceChildren(note);
1034
1103
  }
1104
+ /** The transforms a score renders with: the style set's defaults (BNS
1105
+ * marks the first initial) plus the user-requested transpose. An unknown
1106
+ * style name yields no defaults here — the render itself reports it. */
1107
+ function scriptTransforms(style, transpose) {
1108
+ const transforms = [...STYLE_SETS[style]?.scriptTransforms ?? []];
1109
+ if (transpose !== 0) transforms.push(transposeBy(transpose));
1110
+ return transforms;
1111
+ }
1035
1112
  /** Renders one target element. The score is built into a detached
1036
1113
  * scratch wrapper and swapped into the live one only when this run is
1037
1114
  * still the latest — a stale render that finished late leaves no
@@ -1046,7 +1123,7 @@ async function renderElement(el) {
1046
1123
  const widthPx = resolveWidthPx(el, options.maxWidth, options.style);
1047
1124
  lastWidths.set(el, widthPx);
1048
1125
  const scratch = document.createElement("div");
1049
- const script = new GuidoScript(source, { transforms: options.transpose !== 0 ? [transposeBy(options.transpose)] : [] });
1126
+ const script = new GuidoScript(source, { transforms: scriptTransforms(options.style, options.transpose) });
1050
1127
  try {
1051
1128
  await new GuidoRender(script).render(scratch, {
1052
1129
  style: options.style,
@@ -1119,7 +1196,7 @@ async function renderScore(el, source, options = {}) {
1119
1196
  lastWidths.set(el, widthPx);
1120
1197
  attachResizeListener(el);
1121
1198
  const scratch = document.createElement("div");
1122
- const script = new GuidoScript(source, { transforms: resolved.transpose !== 0 ? [transposeBy(resolved.transpose)] : [] });
1199
+ const script = new GuidoScript(source, { transforms: scriptTransforms(resolved.style, resolved.transpose) });
1123
1200
  try {
1124
1201
  await new GuidoRender(script).render(scratch, {
1125
1202
  style: resolved.style,
@@ -1188,4 +1265,4 @@ function init(options = {}) {
1188
1265
  renderAll();
1189
1266
  }
1190
1267
  //#endregion
1191
- export { version as a, renderScore as i, init as n, renderAll as r, dispose as t };
1268
+ export { version as a, GuidoScript as c, renderScore as i, chantText as l, init as n, DEFAULT_STYLE_SET as o, renderAll as r, STYLE_SETS as s, dispose as t, unescape as u };
@@ -1,4 +1,4 @@
1
- import { a as version, i as renderScore, n as init, r as renderAll, t as dispose } from "../core-dx503oih.js";
1
+ import { a as version, i as renderScore, n as init, r as renderAll, t as dispose } from "../core-hF6L1EtS.js";
2
2
  //#region src/embed/index.ts
3
3
  if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", () => init(), { once: true });
4
4
  else init();
@@ -1,6 +1,13 @@
1
1
  /**
2
2
  * Side-effect-free ESM entry (`guidex`, the package root): the embed
3
3
  * runtime's imperative API without any auto-rendering. Nothing happens
4
- * until you call `renderScore`, `renderAll`, or `init`.
4
+ * until you call `renderScore`, `renderAll`, or `init`. Also re-exports
5
+ * the script parser and text extraction (`GuidoScript`, `chantText`,
6
+ * `unescape`) and the style-set registry (`STYLE_SETS`,
7
+ * `DEFAULT_STYLE_SET`).
5
8
  */
6
9
  export * from './core';
10
+ export { GuidoScript, unescape, chantText } from '../guidoScript';
11
+ export { STYLE_SETS, DEFAULT_STYLE_SET } from '../guidoStyles';
12
+ export type { ScriptTransform } from '../guidoScriptTransforms';
13
+ export type { StyleSetName } from '../guidoStyles';
@@ -1,2 +1,2 @@
1
- import { a as version, i as renderScore, n as init, r as renderAll, t as dispose } from "../core-dx503oih.js";
2
- export { dispose, init, renderAll, renderScore, version };
1
+ import { a as version, c as GuidoScript, i as renderScore, l as chantText, n as init, o as DEFAULT_STYLE_SET, r as renderAll, s as STYLE_SETS, t as dispose, u as unescape } from "../core-hF6L1EtS.js";
2
+ export { DEFAULT_STYLE_SET, GuidoScript, STYLE_SETS, chantText, dispose, init, renderAll, renderScore, unescape, version };
@@ -62,6 +62,12 @@
62
62
  --text-h: #1a1a1a;
63
63
 
64
64
  color: var(--text);
65
+
66
+ /* Score alignment is precomputed in px; Safari's text inflation on
67
+ rotation would resize the text but not the baked-in spacers. Host
68
+ pages don't necessarily set this, so do it here. */
69
+ -webkit-text-size-adjust: 100%;
70
+ text-size-adjust: 100%;
65
71
  }
66
72
 
67
73
  @media (prefers-color-scheme: dark) {
@@ -33,6 +33,9 @@ export declare class GuidoScript {
33
33
  /** The script rebuilt from the parsed pieces — a round-trip of the source. */
34
34
  toString(): string;
35
35
  }
36
+ /** The sung text of the script: the clef stripped, syllables joined
37
+ * into words, and the words joined with single spaces. */
38
+ export declare function chantText(script: string): string;
36
39
  /** Folds backslash escapes into the characters they stand for. Shared
37
40
  * with the transforms module (guidoScriptTransforms.ts). */
38
41
  export declare function unescape(text: string): string;
@@ -1,8 +1,4 @@
1
- /**
2
- * Style sets for the renderer: named appearance rules (fonts, colors, and
3
- * the special syllable decorations) kept in one constant registry, so a
4
- * new style is a data entry here rather than a renderer fork.
5
- */
1
+ import { ScriptTransform } from './guidoScriptTransforms';
6
2
  /** How one run of syllable text is drawn. Unset fields inherit from the
7
3
  * surrounding text line: the style set's text font stack, its base weight,
8
4
  * and the theme's text color. */
@@ -61,6 +57,11 @@ export interface StyleSet {
61
57
  /** Line-end padding in px: the break marker `*` lands this far past
62
58
  * the max-width position. Defaults to 0 (the star sits on the edge). */
63
59
  padding?: number;
60
+ /** Script transforms applied by default when a score renders in this
61
+ * style: whoever parses the score's source (embed runtime, editor)
62
+ * starts from this list and layers user-requested transforms (e.g.
63
+ * transpose) on top. Defaults to no transforms. */
64
+ scriptTransforms?: ScriptTransform[];
64
65
  }
65
66
  export declare const STYLE_SETS: {
66
67
  /** Book Antiqua text with red accents. */
@@ -104,6 +105,10 @@ export declare const STYLE_SETS: {
104
105
  color: string;
105
106
  };
106
107
  padding: number;
108
+ scriptTransforms: {
109
+ name: string;
110
+ apply: (source: string) => string;
111
+ }[];
107
112
  };
108
113
  /** Times New Roman text, strictly black and white. */
109
114
  Vesperale: {
@@ -138,6 +143,7 @@ export declare const STYLE_SETS: {
138
143
  raise: number;
139
144
  };
140
145
  padding: number;
146
+ scriptTransforms: never[];
141
147
  };
142
148
  };
143
149
  export type StyleSetName = keyof typeof STYLE_SETS;
@@ -1,7 +1,7 @@
1
1
  import { MaxWidth } from '../embed/core';
2
2
  import { StyleSetName } from '../guidoStyles';
3
3
  export interface GuidexScoreProps {
4
- /** The score source in GuidoScript notation, e.g. `'(c4) fat(2)ue(2)'`. */
4
+ /** The score source in GuidoScript notation, e.g. `'(M)A(0) di(0q)e(qQ0)bus(1) an(3)ti(1e)quis(qQ0-:)'`. */
5
5
  script: string;
6
6
  /** Line-breaking budget in px, or 'auto' to fit the container (default). */
7
7
  maxWidth?: MaxWidth;
@@ -1,5 +1,5 @@
1
1
  "use client";
2
- import { a as version, i as renderScore, n as init, r as renderAll, t as dispose } from "../core-dx503oih.js";
2
+ import { a as version, i as renderScore, n as init, r as renderAll, t as dispose } from "../core-hF6L1EtS.js";
3
3
  import { useEffect, useRef } from "react";
4
4
  import { jsx } from "react/jsx-runtime";
5
5
  //#region src/react/GuidexScore.tsx
@@ -1,2 +1,2 @@
1
- @font-face{font-family:Book Antiqua;src:url(./fonts/bkant.ttf)format("truetype");font-weight:400;font-style:normal;font-display:swap}@font-face{font-family:Book Antiqua;src:url(./fonts/antquai.ttf)format("truetype");font-weight:400;font-style:italic;font-display:swap}@font-face{font-family:Book Antiqua;src:url(./fonts/antquab.ttf)format("truetype");font-weight:700;font-style:normal;font-display:swap}@font-face{font-family:Book Antiqua;src:url(./fonts/antquabi.ttf)format("truetype");font-weight:700;font-style:italic;font-display:swap}@font-face{font-family:Guidohu;src:url(./fonts/guidohu.ttf)format("truetype");font-display:swap}@font-face{font-family:Liturgy;src:url(./fonts/liturgy.ttf)format("truetype");font-weight:400;font-display:swap}.guidex-render{--red:#d40000;--text:#2b2b2b;--text-h:#1a1a1a;color:var(--text)}@media (prefers-color-scheme:dark){.guidex-render{--red:#ff4d4d;--text:#d4cdc7;--text-h:#f5f0ea}}.guidex-render .guido{color:var(--text-h);padding-block:.3em;font-family:Guidohu,Book Antiqua,Palatino Linotype,Palatino,Georgia,serif;font-size:200%;line-height:120%;position:relative}.guidex-render p{margin:0;line-height:normal}.guidex-render p:first-letter{color:inherit;font-weight:inherit;float:none}.guidex-render .syl,.guidex-render .guido-break{position:relative}.guidex-render .guidex-error{color:var(--red);margin:0;font:14px/1.4 Book Antiqua,Palatino Linotype,Palatino,Georgia,serif}
1
+ @font-face{font-family:Book Antiqua;src:url(./fonts/bkant.ttf)format("truetype");font-weight:400;font-style:normal;font-display:swap}@font-face{font-family:Book Antiqua;src:url(./fonts/antquai.ttf)format("truetype");font-weight:400;font-style:italic;font-display:swap}@font-face{font-family:Book Antiqua;src:url(./fonts/antquab.ttf)format("truetype");font-weight:700;font-style:normal;font-display:swap}@font-face{font-family:Book Antiqua;src:url(./fonts/antquabi.ttf)format("truetype");font-weight:700;font-style:italic;font-display:swap}@font-face{font-family:Guidohu;src:url(./fonts/guidohu.ttf)format("truetype");font-display:swap}@font-face{font-family:Liturgy;src:url(./fonts/liturgy.ttf)format("truetype");font-weight:400;font-display:swap}.guidex-render{--red:#d40000;--text:#2b2b2b;--text-h:#1a1a1a;color:var(--text);-webkit-text-size-adjust:100%;-moz-text-size-adjust:100%;text-size-adjust:100%}@media (prefers-color-scheme:dark){.guidex-render{--red:#ff4d4d;--text:#d4cdc7;--text-h:#f5f0ea}}.guidex-render .guido{color:var(--text-h);padding-block:.3em;font-family:Guidohu,Book Antiqua,Palatino Linotype,Palatino,Georgia,serif;font-size:200%;line-height:120%;position:relative}.guidex-render p{margin:0;line-height:normal}.guidex-render p:first-letter{color:inherit;font-weight:inherit;float:none}.guidex-render .syl,.guidex-render .guido-break{position:relative}.guidex-render .guidex-error{color:var(--red);margin:0;font:14px/1.4 Book Antiqua,Palatino Linotype,Palatino,Georgia,serif}
2
2
  /*$vite$:1*/
@@ -1 +1 @@
1
- var GuidexEmbed=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=class{source;constructor(e,t={}){this.source=(t.transforms??[]).reduce((e,t)=>t.apply(e),e)}get clef(){return this.normalized.match(/^\s*\(([^)]*)\)/)?.[1]}get syllables(){let e=[...this.normalized.replace(/^\s*\([^)]*\)/,``).matchAll(/((?:[^()\\]|\\.)*)\(((?:[^)\\]|\\.)*)\)/g)];return e.map(([,t,r],i)=>({text:n(t.trim()),notes:n(r),wordEnd:i===e.length-1||/^\s/.test(e[i+1][1])}))}get normalized(){let e=this.source;return(e.match(/(^|[^\\])\(/g)??[]).length>(e.match(/(^|[^\\])\)/g)??[]).length&&(e+=`)`),/(^|[^\\])\)$/.test(e)||(e+=`()`),e}get words(){let e=[],t;for(let n of this.syllables)t??={text:``,syllables:[]},t.syllables.push({text:n.text,notes:n.notes}),t.text=t.syllables.map(e=>e.text).join(``),n.wordEnd&&(e.push(t),t=void 0);return e}toString(){let e=this.syllables.map((e,t)=>`${t>0&&this.syllables[t-1].wordEnd?` `:``}${r(e.text)}(${r(e.notes)})`);return`${this.clef===void 0?``:`(${this.clef})`}${e.join(``)}`}};function n(e){return e.replace(/\\(.)/g,`$1`)}function r(e){return e.replace(/\\/g,`\\\\`).replace(/[()]/g,e=>`\\${e}`)}var i=[`ðñ0123456789öüó`,`^]qwertzuiopõú`,`ÝÞQWERTZUIOPÕÚ`,`×sdfghjkléáû`,`ØÙDFGHJKLÉÁÛ`,`÷øaASÍYXCVBN$m`,`ÈÊËÌÎÏÐÑÒþ¬ßòôùý`,`“”•–—˜™š›œº»`,`®−§ÿ"+!%/=()ÖÜÓ`,`Ÿ¡¢£[¥¦©ª«¬`,`~¯‚ƒ„…†‡ˆ‰Š‹Œ‘’`,`àâãäåæçèêëìîï`,`½°±²³´μ·¾¸¹`];function a(e,t,n){for(let r of i){let i=r.indexOf(e);if(i===-1)continue;let a=i+t;return a<0||a>=r.length?n===`null`?`\0`:r[Math.max(0,Math.min(r.length-1,a))]:r[a]}}function o(e,t,n){let r=``;for(let i=0;i<e.length;i++){let o=e[i],s=o===`\\`&&e[i+1]!==void 0,c=a(s?e[i+1]:o,t,n);if(c===void 0){r+=s?o+e[i+1]:o,s&&i++;continue}r+=`\\()`.includes(c)?`\\${c}`:c,s&&i++}return r}function s(e,t={}){let n=t.overflow??`clamp`;return{name:`transpose`,apply:t=>{if(e===0)return t;let r=t.match(/^\s*\(([^)]*)\)/),i=r?r[0].length:0;return t.slice(0,i)+t.slice(i).replace(/((?:[^()\\]|\\.)*)\(((?:[^)\\]|\\.)*)\)/g,(t,r,i)=>`${r}(${o(i,e,n)})`)}}}var c={chars:new Set([`*`,`†`]),fontFamily:`'Times New Roman', Times, serif`},l={weight:`400`,scale:.7,raise:.2},u={BNS:{textFontStack:`'Book Antiqua', Georgia, serif`,notesFontStack:`'Guidohu'`,markerGlyphs:c,verifiedFonts:[{family:`'Book Antiqua'`,weight:`400`},{family:`'Book Antiqua'`,weight:`700`},{family:`'Guidohu'`,weight:`400`},{family:`'Liturgy'`,weight:`700`}],decorations:{__:{fontFamily:`'Liturgy', serif`,weight:`700`,color:`var(--red)`},_:{uppercase:!0,scale:.7,color:`var(--red)`},"*":{weight:`700`,color:`var(--red)`,initial:!0}},specialStarStyle:{fontFamily:c.fontFamily,weight:`700`,scale:1,measureScale:.95,raise:.1,color:`var(--red)`},padding:12},Vesperale:{textFontStack:`'Times New Roman', Times, serif`,notesFontStack:`'Guidohu'`,verifiedFonts:[{family:`'Times New Roman', Times, serif`,weight:`400`},{family:`'Times New Roman', Times, serif`,weight:`700`},{family:`'Guidohu'`,weight:`400`},{family:`'Liturgy'`,weight:`700`}],decorations:{__:{fontFamily:`'Liturgy', serif`,weight:`700`},_:{scale:.8,italic:!0},"*":{weight:`700`,initial:!0}},specialStarStyle:{fontFamily:c.fontFamily,weight:`700`,scale:1,measureScale:.95,raise:.2},padding:12}};function d(e,t,n){if(e.length===0)return[];if(e===`**`)return[{text:`∗`,style:{...t.specialStarStyle}}];let r=e,i={};for(let n of[`__`,`_`]){let a=t.decorations[n];if(a&&e.length>=n.length*2+1&&e.startsWith(n)&&e.endsWith(n)){r=e.slice(n.length,-n.length),i={...a};break}}let a=t.decorations[`*`],o=[],s=r,c=``;for(let e=/\*([^*]+)\*/.exec(s);e;e=/\*([^*]+)\*/.exec(s))c+=s.slice(0,e.index),c&&=(o.push({text:c,marked:!1}),``),o.push({text:e[1],marked:!0}),s=s.slice(e.index+e[0].length);c+=s,c&&o.push({text:c,marked:!1});let u=o.map(({text:e,marked:t})=>({text:e,style:t?{...i,...a,initial:!0}:{...i}})),d=t.markerGlyphs,f=[];for(let e of u){e.style.uppercase&&(e.text=e.text.toUpperCase()),n&&(e.style={...e.style,weight:`700`});let t=[...e.text],r=e.style.fontFamily?.includes(`Liturgy`)??!1,i=e=>d&&d.chars.has(e)?`marker`:r&&e===`+`?`plus`:`text`;if(t.every(e=>i(e)===`text`)){f.push({text:e.text,style:{...e.style}});continue}let a=``,o=null,s=()=>{if(!a)return;let t={...e.style};o===`marker`&&d?t={...t,fontFamily:d.fontFamily}:o===`plus`&&(t={...t,...l}),f.push({text:a,style:t}),a=``};for(let e of t){let t=i(e);t!==o&&s(),o=t,a+=e}s()}return f}function f(e,t,n){return[e.italic?`italic`:`normal`,`normal`,e.weight??`400`,`${t*(e.measureScale??e.scale??1)}px`,e.fontFamily??n].join(` `)}function p(e,t){let n={};return e.fontFamily&&(n[`font-family`]=e.fontFamily),e.weight&&(n[`font-weight`]=e.weight),e.italic&&(n[`font-style`]=`italic`),e.scale!==void 0&&(n[`font-size`]=`${t*e.scale}px`),e.color&&(n.color=e.color),e.raise&&(n.position=`relative`,n.top=`${-t*e.raise}px`),n}function m(e,t){return e.verifiedFonts.map(e=>`${e.weight} ${t}px ${e.family}`)}var h=new Set(`,.:?'"+!%/=()ÖÜÓ;`.split(``)),ee=new Set(`Ÿ¡¢£[¥¦©ª«¬`.split(``)),g=[`-`,`¨`];function _(e){let t=0;for(;t<e.length&&h.has(e[t]);)t++;t>0&&t<e.length&&e[t]===`-`&&t++;let n=e.length;for(;n>t&&h.has(e[n-1]);)n--;return n<e.length&&n>t&&e[n-1]===`-`&&n--,{leading:e.slice(0,t),core:e.slice(t,n),trailing:e.slice(n)}}var v=class e{script;constructor(e){this.script=typeof e==`string`?new t(e):e}static ctx=null;static measure(t,n){return e.ctx||=document.createElement(`canvas`).getContext(`2d`),e.ctx.font=n,e.ctx.measureText(t).width}static ink(t,n){e.ctx||=document.createElement(`canvas`).getContext(`2d`),e.ctx.font=n;let r=e.ctx.measureText(t);return{left:r.actualBoundingBoxLeft,right:r.actualBoundingBoxRight}}async render(t,n={}){let{style:r=`BNS`,bold:i=!1,textPx:a=18,notesPx:o=a*2,debug:s=!1,maxWidthPx:c=1/0}=n,l=u[r];if(!l)throw Error(`Unknown style set: "${r}"`);for(let e of m(l,a)){try{await document.fonts.load(e)}catch{}if(!document.fonts.check(e))throw Error(`Font could not be loaded: ${e} (style "${r}")`)}let p=`400 ${o}px ${l.notesFontStack}`,v=l.textFontStack,y=f({weight:i?`700`:`400`},a,v),b=e=>d(e,l,i),x=e=>e.reduce((e,t)=>e+S(t.text,f(t.style,a,v)),0),S=(t,n)=>e.measure(t,n),C=S(`-`,p),w=S(`-`,y);t.style.fontSize=`${a}px`,t.style.fontFamily=v,t.dataset.style=r;let T=this.script.clef===void 0?``:`${this.script.clef}-`,E=[],D,O,k,A,j=!1,M=[],N=()=>{D&&(D.textCursor=k,D.notesEnd=D.notesParts.length?S(T+D.notesParts.join(``),p):0);let e=document.createElement(`div`);e.className=`guido`,e.style.fontSize=`${o}px`;let t=document.createElement(`p`);i&&(t.style.fontWeight=`700`),D={notesEl:e,textEl:t,notesParts:[],textCursor:0,notesEnd:0,lastWordEnd:null},E.push(D),O=T,k=0,A=!1,j=!1};N();let P=this.script.syllables,F=P.map((e,t)=>({syl:e,i:t,text:e.text,notes:e.notes,first:!0,lastSeg:!0})),I=(e,t,n)=>{for(let r=e.length-1;r>0;r--){if(!g.includes(e[r]))continue;let i=r+1;for(;i<e.length&&h.has(e[i]);)i++;if(!(i>=e.length)&&n(e.slice(0,i))<=t)return r}return-1},L=(e,t)=>{let n=e.notes,r=t+1;for(;r<n.length&&h.has(n[r]);)r++;return e.notes=n.slice(0,t)+n.slice(t+1,r),n.slice(r)},R=(e,t,n)=>{e.lastSeg=!1,F.splice(t+1,0,{syl:e.syl,i:e.i,text:``,notes:n,first:!1,lastSeg:!0}),z=!0},z=!1,B=0;for(;B<F.length;){let t=F[B],n=t.syl,r=t.i;z&&=(N(),!1);let i=t.lastSeg&&r===P.length-1,o=t.text,l=b(o),u=x(l),d=!i&&n.wordEnd?S(` `,y):0,f=M.reduce((e,t)=>e+t.textWidth+t.spaceWidth,0),m=n.notes.length===1&&ee.has(n.notes),g=k===0||k+f+u+(n.wordEnd?0:w)<=c;if(n.notes.length===0){M.push({sylParts:l,textWidth:u,spaceWidth:d,wordEnd:n.wordEnd}),B++;continue}if(t.first&&t.lastSeg&&n.text.trim()===``&&_(n.notes).core===``){let e=O[O.length-1],t=e&&e!==`-`&&!h.has(e)&&!n.notes.startsWith(`-`)?`-`:``;D.notesParts.push(t+n.notes),O+=t+n.notes,A=!0,j=!1,B++;continue}let v=P[r-1]?.notes!==n.notes;if(m&&!v&&D.notesParts.length>0&&!g&&N(),!t.first){for(;!(S(O+t.notes,p)<=c);){let e=I(t.notes,c,e=>S(O+e,p));if(e<0||e+1>=t.notes.length)break;let n=L(t,e);R(t,B,n)}let e=_(t.notes);D.notesParts.push(t.notes),O+=t.notes,t.lastSeg&&(A=e.trailing.length>0),D.lastWordEnd=!0,t.lastSeg||(z=!0),B++;continue}let T=D.notesParts.length===0||j?``:A?`--`:`---`,E=_(t.notes),V=(t=0)=>{let n=S(E.core,p),r=S(O+T+`-`.repeat(t)+E.leading,p),i=e.ink(E.core,p),a=-i.left,o=(i.right-i.left)/2;return{contentWidth:n,contentStart:r,textStart:n>=u||m?r+a:r+o-u/2}},{contentWidth:H,contentStart:U,textStart:W}=V();for(;;){let e=S(O+T+t.notes,p)>c,r=W+u+(n.wordEnd?0:w)>c;if(!e&&!r)break;if(e){let e=I(t.notes,c,e=>S(O+T+e,p));if(e>=0&&e+1<t.notes.length){let n=L(t,e);R(t,B,n),E=_(t.notes),{contentWidth:H,contentStart:U,textStart:W}=V();break}}if(D.notesParts.length===0&&k===0){if(e){let e=I(t.notes,c,e=>S(O+e,p));if(e>=0&&e+1<t.notes.length){let n=L(t,e);t.notes=t.notes.slice(0,e),R(t,B,n),E=_(t.notes),{contentWidth:H,contentStart:U,textStart:W}=V()}}break}N(),T=``,{contentWidth:H,contentStart:U,textStart:W}=V()}let G=D.notesParts.length>0&&!F[B-1].syl.wordEnd&&f===0,te=k+w,K=k+f+(j&&G?w:0),q=T+t.notes,J=0,Y=!1,X=e=>{J=e,q=T+`-`.repeat(e)+t.notes,{contentWidth:H,contentStart:U,textStart:W}=V(e)},Z=m&&!v&&D.notesParts.length>0;if(Z){T=``,W=k+f;let e=W+u+d-S(O,p),n=c-S(O+T,p),r=e>0?Math.min(Math.ceil(e/C),Math.max(0,Math.floor(n/C))):0;t.notes=`-`.repeat(r),E=_(t.notes),q=T+t.notes,Y=G}if(!Z){if(!j&&G&&W<te&&(u>H||W<k)){Y=!0,W=k;let e=H>=u?W:W+(u-H)/2;e>U&&(J=Math.round((e-U)/C),q=T+`-`.repeat(J)+t.notes)}else if(W<K){let e=H>=u?K:K+(u-H)/2;if(e>U){let n=Math.max(0,Math.floor((e-U)/C));for(X(n);W<K;)n++,X(n);if(D.notesParts.length>0&&S(O+q,p)>c&&(N(),T=``,q=T+t.notes,J=0,{contentWidth:H,contentStart:U,textStart:W}=V(),W<k+f)){let e=H>=u?k+f:k+f+(u-H)/2;if(e>U){let t=Math.max(0,Math.floor((e-U)/C));for(X(t);W<k+f;)t++,X(t)}}}}}f>0&&W<k+f&&(W=k+f);let Q=Math.max(0,W-f-k),$=e.sylSpan(l,a);if(D.notesParts.length===0){let t=e.spacer(Q);s&&(t.title=`lead-in ${Q.toFixed(1)}px → text ${W.toFixed(1)}`),D.textEl.appendChild(t)}else if(F[B-1].syl.wordEnd){let t=e.spacer(Q);s&&(t.title=`word gap ${Q.toFixed(1)}px → text ${W.toFixed(1)}`),D.textEl.appendChild(t)}else if(f===0&&Y)s&&($.title+=` | tight pair`);else if(f===0){let t=Math.max(0,(Q-w)/2),n=e.spacer(t),r=document.createElement(`span`);r.className=`dash`,r.textContent=`-`;let i=e.spacer(t);s&&(n.title=`lead pad ${t.toFixed(1)}px (gap ${Q.toFixed(1)} − dash ${w.toFixed(1)}, halved)`,r.title=`dash ${w.toFixed(1)}px`,i.title=`trail pad ${t.toFixed(1)}px`),D.textEl.append(n,r,i)}if(s){let e=(u-H)/2,t=W-U;$.title=[`text w ${u.toFixed(1)}`,`notes w ${H.toFixed(1)}`,J?`+${J} pad dash(es)`:null,`text start ${W.toFixed(1)}`,`notes start ${U.toFixed(1)}`,`theoDiff: ${e.toFixed(1)}`,`cursDiff: ${t.toFixed(1)}`].filter(Boolean).join(`, `)}for(let t of M){let n=e.sylSpan(t.sylParts,a);if(s&&(n.title=`no notes, text w ${t.textWidth.toFixed(1)}, before the next syllable with notes`),D.textEl.appendChild(n),t.spaceWidth>0){let e=document.createElement(`span`);e.className=`word-space`,e.textContent=` `,s&&(e.title=`word space ${t.spaceWidth.toFixed(1)}px`),D.textEl.appendChild(e)}}if(M=[],D.textEl.appendChild($),d>0){let e=document.createElement(`span`);e.className=`word-space`,e.textContent=` `,s&&(e.title=`word space ${d.toFixed(1)}px`),D.textEl.appendChild(e)}k=W+u+d,O+=q,D.notesParts.push(q),D.lastWordEnd=n.wordEnd,t.lastSeg&&(A=E.trailing.length>0,j=m),t.lastSeg||(z=!0),B++}if(M.length>0){for(let t of M){let n=e.sylSpan(t.sylParts,a);if(s&&(n.title=`no notes, text w ${t.textWidth.toFixed(1)}, end of score`),D.textEl.appendChild(n),t.spaceWidth>0){let e=document.createElement(`span`);e.className=`word-space`,e.textContent=` `,s&&(e.title=`word space ${t.spaceWidth.toFixed(1)}px`),D.textEl.appendChild(e)}k+=t.textWidth+t.spaceWidth}D.lastWordEnd=M[M.length-1].wordEnd,D.textCursor=k}E.forEach((t,n)=>{if(n===E.length-1||t.lastWordEnd!==!1)return;let r=t.notesEnd>t.textCursor?Math.max(0,(t.notesEnd-t.textCursor-w)/2):0,i=e.spacer(r),a=document.createElement(`span`);a.className=`dash`,a.textContent=`-`;let o=e.spacer(r);s&&(i.title=`lead pad ${r.toFixed(1)}px → line-end dash (text end ${t.textCursor.toFixed(1)}, notes end ${t.notesEnd.toFixed(1)})`,a.title=`dash ${w.toFixed(1)}px (line end)`,o.title=`trail pad ${r.toFixed(1)}px`),t.textEl.append(i,a,o)});let V=c+(l.padding??0),H=S(`*`,p);E.forEach((e,t)=>{if(t===E.length-1)return;let n=S(T+e.notesParts.join(``),p);for(;n+C<=V-H&&n+C<c;)e.notesParts.push(`-`),n+=C;e.breakMarkerLeftPx=V-n-H}),E.forEach(e=>{e.notesEl.textContent=T+e.notesParts.join(``)}),E.forEach((e,t)=>{if(t===E.length-1)return;let n=document.createElement(`span`);n.className=`guido-break`,n.textContent=`*`,n.style.position=`relative`,n.style.left=`${e.breakMarkerLeftPx}px`,s&&(n.title=`line break at ${V.toFixed(1)}px (staff filled to ${(V-e.breakMarkerLeftPx-H).toFixed(1)}px)`),e.notesEl.appendChild(n)}),t.replaceChildren(...E.flatMap(e=>[e.notesEl,e.textEl]))}static sylSpan(e,t){let n=document.createElement(`span`);return n.className=`syl`,e.forEach(e=>{let r=document.createElement(`span`);r.textContent=e.text;for(let[n,i]of Object.entries(p(e.style,t)))r.style.setProperty(n,i);e.style.initial&&(r.className=`initial`),n.appendChild(r)}),n}static spacer(e){let t=document.createElement(`span`);return t.className=`spacer`,t.style.display=`inline-block`,t.style.width=`${e}px`,t}},y={name:`guidex`,version:`0.2.4`,description:`Guidex — render plainchant scores from a compact GuidoScript notation, as a web app and an embeddable runtime`,type:`module`,workspaces:[`examples/*`],main:`./dist/lib/embed/manual.js`,types:`./dist/lib/embed/manual.d.ts`,exports:{".":{types:`./dist/lib/embed/manual.d.ts`,default:`./dist/lib/embed/manual.js`},"./embed":{types:`./dist/lib/embed/index.d.ts`,default:`./dist/lib/embed/index.js`},"./guidex.css":{types:`./dist/lib/guidex.css.d.ts`,default:`./dist/lib/guidex.css`},"./fonts/*":`./dist/lib/fonts/*`,"./react":{types:`./dist/lib/react/index.d.ts`,default:`./dist/lib/react/index.js`}},files:[`dist-embed`,`dist/lib`],peerDependencies:{react:`>=18`},peerDependenciesMeta:{react:{optional:!0}},publishConfig:{access:`public`},scripts:{dev:`vite --host`,build:`tsc && vite build`,"build:embed":`vite build --config vite.embed.config.ts`,"build:lib":`vite build --config vite.lib.config.ts`,preview:`vite preview`,test:`vitest run`,lint:`eslint .`},keywords:[`plainchant`,`gregorian`,`guido`,`score`,`notation`,`liturgy`],repository:{type:`git`,url:`git+https://github.com/BrownieMaar/guidex.git`},bugs:{url:`https://github.com/BrownieMaar/guidex/issues`},homepage:`https://github.com/BrownieMaar/guidex#readme`,devDependencies:{"@eslint/js":`^10.0.1`,"@types/react":`^19.3.0`,"@types/react-dom":`^19.3.0`,"@vitejs/plugin-react":`^6.1.1`,eslint:`^10.10.0`,jsdom:`^29.1.1`,react:`^19.3.0`,"react-dom":`^19.3.0`,typescript:`~6.0.2`,"typescript-eslint":`^8.70.0`,vite:`^8.2.2`,"vite-plugin-dts":`^5.1.1`,vitest:`^4.1.11`}}.version,b=`.guidex-script, .guido-script`,x={maxWidth:`auto`,style:`BNS`,bold:!1,textPx:18,transpose:0,debug:!1},S={},C=new WeakMap,w=new WeakMap,T=new WeakMap;function E(e){if(e!==void 0){if(e===``||e===`true`)return!0;if(e===`false`)return!1}}function D(e){if(e===void 0)return;let t=Number(e);return Number.isFinite(t)?t:void 0}function O(e,t){if(/^auto$/i.test(e.trim()))return`auto`;let n=Number(e);return Number.isFinite(n)&&n>0?n:(console.warn(`[guidex] ignoring invalid data-max-width "${e}"`),t)}var k=new WeakMap;function A(e){let t=e.dataset,n=k.get(e)??{};return{maxWidth:t.maxWidth===void 0?n.maxWidth??S.maxWidth??x.maxWidth:O(t.maxWidth,n.maxWidth??S.maxWidth??x.maxWidth),style:t.style??n.style??S.style??x.style,bold:E(t.bold)??n.bold??S.bold??x.bold,textPx:D(t.textPx)??n.textPx??S.textPx??x.textPx,transpose:D(t.transpose)??n.transpose??S.transpose??x.transpose,debug:E(t.debug)??n.debug??S.debug??x.debug}}function j(e){return e.querySelector(`:scope > .guidex-render`)?.clientWidth||e.clientWidth||e.parentElement?.clientWidth||0}function M(e,t,n){if(typeof t==`number`)return t;let r=j(e);if(r<=0)return 1/0;let i=r-(u[n]?.padding??0);return i>0?i:r}function N(e){for(let t of e.childNodes)if(t.nodeType===Node.TEXT_NODE&&t.nodeValue?.trim())return t.nodeValue.trim();return C.get(e)??``}function P(e){let t=e.querySelector(`:scope > .guidex-render`);if(t)return t;let n=document.createElement(`div`);return n.className=`guidex-render`,e.replaceChildren(n),n}function F(e,t){let n=document.createElement(`p`);n.className=`guidex-error`,n.textContent=t,e.replaceChildren(n)}async function I(e){let n=(w.get(e)??0)+1;w.set(e,n);let r=A(e),i=N(e);C.set(e,i);let a=P(e),o=M(e,r.maxWidth,r.style);T.set(e,o);let c=document.createElement(`div`),l=new t(i,{transforms:r.transpose===0?[]:[s(r.transpose)]});try{if(await new v(l).render(c,{style:r.style,bold:r.bold,textPx:r.textPx,debug:r.debug,maxWidthPx:o}),w.get(e)!==n)return;a.replaceChildren(...c.childNodes),a.style.cssText=c.style.cssText,c.dataset.style&&(a.dataset.style=c.dataset.style)}catch(t){if(w.get(e)!==n)return;console.error(`[guidex]`,t),F(a,t instanceof Error?t.message:String(t))}}var L=new WeakMap;function R(e){let t=A(e),n=M(e,t.maxWidth,t.style);return Math.abs(n-(T.get(e)??NaN))>1}function z(e){if(L.has(e))return;let t;if(typeof ResizeObserver<`u`){let n=new ResizeObserver(()=>{R(e)&&I(e)});n.observe(e),t=()=>n.disconnect()}else{let n=()=>{R(e)&&I(e)};window.addEventListener(`resize`,n),t=()=>window.removeEventListener(`resize`,n)}L.set(e,t)}function B(e){L.get(e)?.(),L.delete(e),C.delete(e),k.delete(e),w.delete(e),T.delete(e)}async function V(e,n,r={}){k.set(e,r);let i=(w.get(e)??0)+1;w.set(e,i),C.set(e,n);let a=A(e),o=P(e),c=M(e,a.maxWidth,a.style);T.set(e,c),z(e);let l=document.createElement(`div`),u=new t(n,{transforms:a.transpose===0?[]:[s(a.transpose)]});try{if(await new v(u).render(l,{style:a.style,bold:a.bold,textPx:a.textPx,debug:a.debug,maxWidthPx:c}),w.get(e)!==i)return;o.replaceChildren(...l.childNodes),o.style.cssText=l.style.cssText,l.dataset.style&&(o.dataset.style=l.dataset.style)}catch(t){if(w.get(e)!==i)return;console.error(`[guidex]`,t),F(o,t instanceof Error?t.message:String(t))}}async function H(e=document){let t=S.selector??b,n=[];return e instanceof Element&&e.matches(t)&&n.push(e),n.push(...e.querySelectorAll(t)),Promise.all(n.map(e=>(z(e),I(e)))).then(()=>void 0)}var U=!1;function W(){if(U||typeof MutationObserver>`u`)return;U=!0;let e=S.selector??b;new MutationObserver(t=>{let n=new Set;for(let r of t)for(let t of r.addedNodes)if(t instanceof Element&&!t.closest(`.guidex-render`)){t.matches(e)&&n.add(t);for(let r of t.querySelectorAll(e))n.add(r)}for(let e of n)z(e),I(e)}).observe(document.documentElement,{childList:!0,subtree:!0})}function G(e={}){S={...S,...e},W(),H()}return document.readyState===`loading`?document.addEventListener(`DOMContentLoaded`,()=>G(),{once:!0}):G(),e.dispose=B,e.init=G,e.renderAll=H,e.renderScore=V,e.version=y,e})({});
1
+ var GuidexEmbed=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=class{source;constructor(e,t={}){this.source=(t.transforms??[]).reduce((e,t)=>t.apply(e),e)}get clef(){return this.normalized.match(/^\s*\(([^)]*)\)/)?.[1]}get syllables(){let e=[...this.normalized.replace(/^\s*\([^)]*\)/,``).matchAll(/((?:[^()\\]|\\.)*)\(((?:[^)\\]|\\.)*)\)/g)];return e.map(([,t,r],i)=>({text:n(t.trim()),notes:n(r),wordEnd:i===e.length-1||/^\s/.test(e[i+1][1])}))}get normalized(){let e=this.source;return(e.match(/(^|[^\\])\(/g)??[]).length>(e.match(/(^|[^\\])\)/g)??[]).length&&(e+=`)`),/(^|[^\\])\)$/.test(e)||(e+=`()`),e}get words(){let e=[],t;for(let n of this.syllables)t??={text:``,syllables:[]},t.syllables.push({text:n.text,notes:n.notes}),t.text=t.syllables.map(e=>e.text).join(``),n.wordEnd&&(e.push(t),t=void 0);return e}toString(){let e=this.syllables.map((e,t)=>`${t>0&&this.syllables[t-1].wordEnd?` `:``}${r(e.text)}(${r(e.notes)})`);return`${this.clef===void 0?``:`(${this.clef})`}${e.join(``)}`}};function n(e){return e.replace(/\\(.)/g,`$1`)}function r(e){return e.replace(/\\/g,`\\\\`).replace(/[()]/g,e=>`\\${e}`)}function i(e){let t=[...e];for(let e=0;e<t.length;e++){let n=t[e];if(!/\s/.test(n))return{unit:n===`\\`&&t[e+1]!==void 0?n+t[e+1]:n,index:e}}return null}function a(e){let t=e.match(/^\s*\(([^)]*)\)/),r=t?t[0].length:0,a=e.slice(r);for(let t of a.matchAll(/((?:[^()\\]|\\.)*)\(((?:[^)\\]|\\.)*)\)/g)){let[,a,o]=t;if(n(o).trim().length===0)continue;let s=i(a);if(!s||a.trimStart().startsWith(`*`))return e;let c=r+t.index+s.index,l=c+s.unit.length;return`${e.slice(0,c)}*${e.slice(c,l)}*${e.slice(l)}`}return e}var o={startWithInitial:{name:`startWithInitial`,apply:a}},s=[`ðñ0123456789öüó`,`^]qwertzuiopõú`,`ÝÞQWERTZUIOPÕÚ`,`×sdfghjkléáû`,`ØÙDFGHJKLÉÁÛ`,`÷øaASÍYXCVBN$m`,`ÈÊËÌÎÏÐÑÒþ¬ßòôùý`,`“”•–—˜™š›œº»`,`®−§ÿ"+!%/=()ÖÜÓ`,`Ÿ¡¢£[¥¦©ª«¬`,`~¯‚ƒ„…†‡ˆ‰Š‹Œ‘’`,`àâãäåæçèêëìîï`,`½°±²³´μ·¾¸¹`];function c(e,t,n){for(let r of s){let i=r.indexOf(e);if(i===-1)continue;let a=i+t;return a<0||a>=r.length?n===`null`?`\0`:r[Math.max(0,Math.min(r.length-1,a))]:r[a]}}function l(e,t,n){let r=``;for(let i=0;i<e.length;i++){let a=e[i],o=a===`\\`&&e[i+1]!==void 0,s=c(o?e[i+1]:a,t,n);if(s===void 0){r+=o?a+e[i+1]:a,o&&i++;continue}r+=`\\()`.includes(s)?`\\${s}`:s,o&&i++}return r}function u(e,t={}){let n=t.overflow??`clamp`;return{name:`transpose`,apply:t=>{if(e===0)return t;let r=t.match(/^\s*\(([^)]*)\)/),i=r?r[0].length:0;return t.slice(0,i)+t.slice(i).replace(/((?:[^()\\]|\\.)*)\(((?:[^)\\]|\\.)*)\)/g,(t,r,i)=>`${r}(${l(i,e,n)})`)}}}var d={chars:new Set([`*`,`†`]),fontFamily:`'Times New Roman', Times, serif`},f={weight:`400`,scale:.7,raise:.2},p={BNS:{textFontStack:`'Book Antiqua', Georgia, serif`,notesFontStack:`'Guidohu'`,markerGlyphs:d,verifiedFonts:[{family:`'Book Antiqua'`,weight:`400`},{family:`'Book Antiqua'`,weight:`700`},{family:`'Guidohu'`,weight:`400`},{family:`'Liturgy'`,weight:`700`}],decorations:{__:{fontFamily:`'Liturgy', serif`,weight:`700`,color:`var(--red)`},_:{uppercase:!0,scale:.7,color:`var(--red)`},"*":{weight:`700`,color:`var(--red)`,initial:!0}},specialStarStyle:{fontFamily:d.fontFamily,weight:`700`,scale:1,measureScale:.95,raise:.1,color:`var(--red)`},padding:12,scriptTransforms:[o.startWithInitial]},Vesperale:{textFontStack:`'Times New Roman', Times, serif`,notesFontStack:`'Guidohu'`,verifiedFonts:[{family:`'Times New Roman', Times, serif`,weight:`400`},{family:`'Times New Roman', Times, serif`,weight:`700`},{family:`'Guidohu'`,weight:`400`},{family:`'Liturgy'`,weight:`700`}],decorations:{__:{fontFamily:`'Liturgy', serif`,weight:`700`},_:{scale:.8,italic:!0},"*":{weight:`700`,initial:!0}},specialStarStyle:{fontFamily:d.fontFamily,weight:`700`,scale:1,measureScale:.95,raise:.2},padding:12,scriptTransforms:[]}};function m(e,t,n){if(e.length===0)return[];if(e===`**`)return[{text:`∗`,style:{...t.specialStarStyle}}];let r=e,i={};for(let n of[`__`,`_`]){let a=t.decorations[n];if(a&&e.length>=n.length*2+1&&e.startsWith(n)&&e.endsWith(n)){r=e.slice(n.length,-n.length),i={...a};break}}let a=t.decorations[`*`],o=[],s=r,c=``;for(let e=/\*([^*]+)\*/.exec(s);e;e=/\*([^*]+)\*/.exec(s))c+=s.slice(0,e.index),c&&=(o.push({text:c,marked:!1}),``),o.push({text:e[1],marked:!0}),s=s.slice(e.index+e[0].length);c+=s,c&&o.push({text:c,marked:!1});let l=o.map(({text:e,marked:t})=>({text:e,style:t?{...i,...a,initial:!0}:{...i}})),u=t.markerGlyphs,d=[];for(let e of l){e.style.uppercase&&(e.text=e.text.toUpperCase()),n&&(e.style={...e.style,weight:`700`});let t=[...e.text],r=e.style.fontFamily?.includes(`Liturgy`)??!1,i=e=>u&&u.chars.has(e)?`marker`:r&&e===`+`?`plus`:`text`;if(t.every(e=>i(e)===`text`)){d.push({text:e.text,style:{...e.style}});continue}let a=``,o=null,s=()=>{if(!a)return;let t={...e.style};o===`marker`&&u?t={...t,fontFamily:u.fontFamily}:o===`plus`&&(t={...t,...f}),d.push({text:a,style:t}),a=``};for(let e of t){let t=i(e);t!==o&&s(),o=t,a+=e}s()}return d}function h(e,t,n){return[e.italic?`italic`:`normal`,`normal`,e.weight??`400`,`${t*(e.measureScale??e.scale??1)}px`,e.fontFamily??n].join(` `)}function g(e,t){let n={};return e.fontFamily&&(n[`font-family`]=e.fontFamily),e.weight&&(n[`font-weight`]=e.weight),e.italic&&(n[`font-style`]=`italic`),e.scale!==void 0&&(n[`font-size`]=`${t*e.scale}px`),e.color&&(n.color=e.color),e.raise&&(n.position=`relative`,n.top=`${-t*e.raise}px`),n}function _(e,t){return e.verifiedFonts.map(e=>`${e.weight} ${t}px ${e.family}`)}var v=new Set(`,.:?'"+!%/=()ÖÜÓ;`.split(``)),ee=new Set(`Ÿ¡¢£[¥¦©ª«¬`.split(``)),y=[`-`,`¨`];function b(e){let t=0;for(;t<e.length&&v.has(e[t]);)t++;t>0&&t<e.length&&e[t]===`-`&&t++;let n=e.length;for(;n>t&&v.has(e[n-1]);)n--;return n<e.length&&n>t&&e[n-1]===`-`&&n--,{leading:e.slice(0,t),core:e.slice(t,n),trailing:e.slice(n)}}var x=class e{script;constructor(e){this.script=typeof e==`string`?new t(e):e}static ctx=null;static measure(t,n){return e.ctx||=document.createElement(`canvas`).getContext(`2d`),e.ctx.font=n,e.ctx.measureText(t).width}static ink(t,n){e.ctx||=document.createElement(`canvas`).getContext(`2d`),e.ctx.font=n;let r=e.ctx.measureText(t);return{left:r.actualBoundingBoxLeft,right:r.actualBoundingBoxRight}}async render(t,n={}){let{style:r=`BNS`,bold:i=!1,textPx:a=18,notesPx:o=a*2,debug:s=!1,maxWidthPx:c=1/0}=n,l=p[r];if(!l)throw Error(`Unknown style set: "${r}"`);for(let e of _(l,a)){try{await document.fonts.load(e)}catch{}if(!document.fonts.check(e))throw Error(`Font could not be loaded: ${e} (style "${r}")`)}let u=`400 ${o}px ${l.notesFontStack}`,d=l.textFontStack,f=h({weight:i?`700`:`400`},a,d),g=e=>m(e,l,i),x=e=>e.reduce((e,t)=>e+S(t.text,h(t.style,a,d)),0),S=(t,n)=>e.measure(t,n),C=S(`-`,u),w=S(`-`,f);t.style.fontSize=`${a}px`,t.style.fontFamily=d,t.dataset.style=r;let T=this.script.clef===void 0?``:`${this.script.clef}-`,E=[],D,O,k,A,j=!1,M=[],N=()=>{D&&(D.textCursor=k,D.notesEnd=D.notesParts.length?S(T+D.notesParts.join(``),u):0);let e=document.createElement(`div`);e.className=`guido`,e.style.fontSize=`${o}px`;let t=document.createElement(`p`);i&&(t.style.fontWeight=`700`),D={notesEl:e,textEl:t,notesParts:[],textCursor:0,notesEnd:0,lastWordEnd:null},E.push(D),O=T,k=0,A=!1,j=!1};N();let P=this.script.syllables,F=P.map((e,t)=>({syl:e,i:t,text:e.text,notes:e.notes,first:!0,lastSeg:!0})),I=(e,t,n)=>{for(let r=e.length-1;r>0;r--){if(!y.includes(e[r]))continue;let i=r+1;for(;i<e.length&&v.has(e[i]);)i++;if(!(i>=e.length)&&n(e.slice(0,i))<=t)return r}return-1},L=(e,t)=>{let n=e.notes,r=t+1;for(;r<n.length&&v.has(n[r]);)r++;return e.notes=n.slice(0,t)+n.slice(t+1,r),n.slice(r)},R=(e,t,n)=>{e.lastSeg=!1,F.splice(t+1,0,{syl:e.syl,i:e.i,text:``,notes:n,first:!1,lastSeg:!0}),z=!0},z=!1,B=0;for(;B<F.length;){let t=F[B],n=t.syl,r=t.i;z&&=(N(),!1);let i=t.lastSeg&&r===P.length-1,o=t.text,l=g(o),d=x(l),p=!i&&n.wordEnd?S(` `,f):0,m=M.reduce((e,t)=>e+t.textWidth+t.spaceWidth,0),h=n.notes.length===1&&ee.has(n.notes),_=k===0||k+m+d+(n.wordEnd?0:w)<=c;if(n.notes.length===0){M.push({sylParts:l,textWidth:d,spaceWidth:p,wordEnd:n.wordEnd}),B++;continue}if(t.first&&t.lastSeg&&n.text.trim()===``&&b(n.notes).core===``){let e=O[O.length-1],t=e&&e!==`-`&&!v.has(e)&&!n.notes.startsWith(`-`)?`-`:``;D.notesParts.push(t+n.notes),O+=t+n.notes,A=!0,j=!1,B++;continue}let y=P[r-1]?.notes!==n.notes;if(h&&!y&&D.notesParts.length>0&&!_&&N(),!t.first){for(;!(S(O+t.notes,u)<=c);){let e=I(t.notes,c,e=>S(O+e,u));if(e<0||e+1>=t.notes.length)break;let n=L(t,e);R(t,B,n)}let e=b(t.notes);D.notesParts.push(t.notes),O+=t.notes,t.lastSeg&&(A=e.trailing.length>0),D.lastWordEnd=!0,t.lastSeg||(z=!0),B++;continue}let T=D.notesParts.length===0||j?``:A?`--`:`---`,E=b(t.notes),V=(t=0)=>{let n=S(E.core,u),r=S(O+T+`-`.repeat(t)+E.leading,u),i=e.ink(E.core,u),a=-i.left,o=(i.right-i.left)/2;return{contentWidth:n,contentStart:r,textStart:n>=d||h?r+a:r+o-d/2}},{contentWidth:H,contentStart:U,textStart:W}=V();for(;;){let e=S(O+T+t.notes,u)>c,r=W+d+(n.wordEnd?0:w)>c;if(!e&&!r)break;if(e){let e=I(t.notes,c,e=>S(O+T+e,u));if(e>=0&&e+1<t.notes.length){let n=L(t,e);R(t,B,n),E=b(t.notes),{contentWidth:H,contentStart:U,textStart:W}=V();break}}if(D.notesParts.length===0&&k===0){if(e){let e=I(t.notes,c,e=>S(O+e,u));if(e>=0&&e+1<t.notes.length){let n=L(t,e);t.notes=t.notes.slice(0,e),R(t,B,n),E=b(t.notes),{contentWidth:H,contentStart:U,textStart:W}=V()}}break}N(),T=``,{contentWidth:H,contentStart:U,textStart:W}=V()}let G=D.notesParts.length>0&&!F[B-1].syl.wordEnd&&m===0,K=k+w,q=k+m+(j&&G?w:0),J=T+t.notes,Y=0,X=!1,Z=e=>{Y=e,J=T+`-`.repeat(e)+t.notes,{contentWidth:H,contentStart:U,textStart:W}=V(e)},te=h&&!y&&D.notesParts.length>0;if(te){T=``,W=k+m;let e=W+d+p-S(O,u),n=c-S(O+T,u),r=e>0?Math.min(Math.ceil(e/C),Math.max(0,Math.floor(n/C))):0;t.notes=`-`.repeat(r),E=b(t.notes),J=T+t.notes,X=G}if(!te){if(!j&&G&&W<K&&(d>H||W<k)){X=!0,W=k;let e=H>=d?W:W+(d-H)/2;e>U&&(Y=Math.round((e-U)/C),J=T+`-`.repeat(Y)+t.notes)}else if(W<q){let e=H>=d?q:q+(d-H)/2;if(e>U){let n=Math.max(0,Math.floor((e-U)/C));for(Z(n);W<q;)n++,Z(n);if(D.notesParts.length>0&&S(O+J,u)>c&&(N(),T=``,J=T+t.notes,Y=0,{contentWidth:H,contentStart:U,textStart:W}=V(),W<k+m)){let e=H>=d?k+m:k+m+(d-H)/2;if(e>U){let t=Math.max(0,Math.floor((e-U)/C));for(Z(t);W<k+m;)t++,Z(t)}}}}}m>0&&W<k+m&&(W=k+m);let Q=Math.max(0,W-m-k),$=e.sylSpan(l,a);if(D.notesParts.length===0){let t=e.spacer(Q);s&&(t.title=`lead-in ${Q.toFixed(1)}px → text ${W.toFixed(1)}`),D.textEl.appendChild(t)}else if(F[B-1].syl.wordEnd){let t=e.spacer(Q);s&&(t.title=`word gap ${Q.toFixed(1)}px → text ${W.toFixed(1)}`),D.textEl.appendChild(t)}else if(m===0&&X)s&&($.title+=` | tight pair`);else if(m===0){let t=Math.max(0,(Q-w)/2),n=e.spacer(t),r=document.createElement(`span`);r.className=`dash`,r.textContent=`-`;let i=e.spacer(t);s&&(n.title=`lead pad ${t.toFixed(1)}px (gap ${Q.toFixed(1)} − dash ${w.toFixed(1)}, halved)`,r.title=`dash ${w.toFixed(1)}px`,i.title=`trail pad ${t.toFixed(1)}px`),D.textEl.append(n,r,i)}if(s){let e=(d-H)/2,t=W-U;$.title=[`text w ${d.toFixed(1)}`,`notes w ${H.toFixed(1)}`,Y?`+${Y} pad dash(es)`:null,`text start ${W.toFixed(1)}`,`notes start ${U.toFixed(1)}`,`theoDiff: ${e.toFixed(1)}`,`cursDiff: ${t.toFixed(1)}`].filter(Boolean).join(`, `)}for(let t of M){let n=e.sylSpan(t.sylParts,a);if(s&&(n.title=`no notes, text w ${t.textWidth.toFixed(1)}, before the next syllable with notes`),D.textEl.appendChild(n),t.spaceWidth>0){let e=document.createElement(`span`);e.className=`word-space`,e.textContent=` `,s&&(e.title=`word space ${t.spaceWidth.toFixed(1)}px`),D.textEl.appendChild(e)}}if(M=[],D.textEl.appendChild($),p>0){let e=document.createElement(`span`);e.className=`word-space`,e.textContent=` `,s&&(e.title=`word space ${p.toFixed(1)}px`),D.textEl.appendChild(e)}k=W+d+p,O+=J,D.notesParts.push(J),D.lastWordEnd=n.wordEnd,t.lastSeg&&(A=E.trailing.length>0,j=h),t.lastSeg||(z=!0),B++}if(M.length>0){for(let t of M){let n=e.sylSpan(t.sylParts,a);if(s&&(n.title=`no notes, text w ${t.textWidth.toFixed(1)}, end of score`),D.textEl.appendChild(n),t.spaceWidth>0){let e=document.createElement(`span`);e.className=`word-space`,e.textContent=` `,s&&(e.title=`word space ${t.spaceWidth.toFixed(1)}px`),D.textEl.appendChild(e)}k+=t.textWidth+t.spaceWidth}D.lastWordEnd=M[M.length-1].wordEnd,D.textCursor=k}E.forEach((t,n)=>{if(n===E.length-1||t.lastWordEnd!==!1)return;let r=t.notesEnd>t.textCursor?Math.max(0,(t.notesEnd-t.textCursor-w)/2):0,i=e.spacer(r),a=document.createElement(`span`);a.className=`dash`,a.textContent=`-`;let o=e.spacer(r);s&&(i.title=`lead pad ${r.toFixed(1)}px → line-end dash (text end ${t.textCursor.toFixed(1)}, notes end ${t.notesEnd.toFixed(1)})`,a.title=`dash ${w.toFixed(1)}px (line end)`,o.title=`trail pad ${r.toFixed(1)}px`),t.textEl.append(i,a,o)});let V=c+(l.padding??0),H=S(`*`,u);E.forEach((e,t)=>{if(t===E.length-1)return;let n=S(T+e.notesParts.join(``),u);for(;n+C<=V-H&&n+C<c;)e.notesParts.push(`-`),n+=C;e.breakMarkerLeftPx=V-n-H}),E.forEach(e=>{e.notesEl.textContent=T+e.notesParts.join(``)}),E.forEach((e,t)=>{if(t===E.length-1)return;let n=document.createElement(`span`);n.className=`guido-break`,n.textContent=`*`,n.style.position=`relative`,n.style.left=`${e.breakMarkerLeftPx}px`,s&&(n.title=`line break at ${V.toFixed(1)}px (staff filled to ${(V-e.breakMarkerLeftPx-H).toFixed(1)}px)`),e.notesEl.appendChild(n)}),t.replaceChildren(...E.flatMap(e=>[e.notesEl,e.textEl]))}static sylSpan(e,t){let n=document.createElement(`span`);return n.className=`syl`,e.forEach(e=>{let r=document.createElement(`span`);r.textContent=e.text;for(let[n,i]of Object.entries(g(e.style,t)))r.style.setProperty(n,i);e.style.initial&&(r.className=`initial`),n.appendChild(r)}),n}static spacer(e){let t=document.createElement(`span`);return t.className=`spacer`,t.style.display=`inline-block`,t.style.width=`${e}px`,t}},S={name:`guidex`,version:`0.2.6`,description:`Guidex — render plainchant scores from a compact GuidoScript notation, as a web app and an embeddable runtime`,type:`module`,workspaces:[`examples/*`],main:`./dist/lib/embed/manual.js`,types:`./dist/lib/embed/manual.d.ts`,exports:{".":{types:`./dist/lib/embed/manual.d.ts`,default:`./dist/lib/embed/manual.js`},"./embed":{types:`./dist/lib/embed/index.d.ts`,default:`./dist/lib/embed/index.js`},"./guidex.css":{types:`./dist/lib/guidex.css.d.ts`,default:`./dist/lib/guidex.css`},"./fonts/*":`./dist/lib/fonts/*`,"./react":{types:`./dist/lib/react/index.d.ts`,default:`./dist/lib/react/index.js`}},files:[`dist-embed`,`dist/lib`],peerDependencies:{react:`>=18`},peerDependenciesMeta:{react:{optional:!0}},publishConfig:{access:`public`},scripts:{dev:`vite --host`,build:`tsc && vite build`,"build:embed":`vite build --config vite.embed.config.ts`,"build:lib":`vite build --config vite.lib.config.ts`,preview:`vite preview`,test:`vitest run`,lint:`eslint .`},keywords:[`plainchant`,`gregorian`,`guido`,`score`,`notation`,`liturgy`],repository:{type:`git`,url:`git+https://github.com/BrownieMaar/guidex.git`},bugs:{url:`https://github.com/BrownieMaar/guidex/issues`},homepage:`https://github.com/BrownieMaar/guidex#readme`,devDependencies:{"@eslint/js":`^10.0.1`,"@types/react":`^19.3.0`,"@types/react-dom":`^19.3.0`,"@vitejs/plugin-react":`^6.1.1`,eslint:`^10.10.0`,jsdom:`^29.1.1`,react:`^19.3.0`,"react-dom":`^19.3.0`,typescript:`~6.0.2`,"typescript-eslint":`^8.70.0`,vite:`^8.2.2`,"vite-plugin-dts":`^5.1.1`,vitest:`^4.1.11`}}.version,C=`.guidex-script, .guido-script`,w={maxWidth:`auto`,style:`BNS`,bold:!1,textPx:18,transpose:0,debug:!1},T={},E=new WeakMap,D=new WeakMap,O=new WeakMap;function k(e){if(e!==void 0){if(e===``||e===`true`)return!0;if(e===`false`)return!1}}function A(e){if(e===void 0)return;let t=Number(e);return Number.isFinite(t)?t:void 0}function j(e,t){if(/^auto$/i.test(e.trim()))return`auto`;let n=Number(e);return Number.isFinite(n)&&n>0?n:(console.warn(`[guidex] ignoring invalid data-max-width "${e}"`),t)}var M=new WeakMap;function N(e){let t=e.dataset,n=M.get(e)??{};return{maxWidth:t.maxWidth===void 0?n.maxWidth??T.maxWidth??w.maxWidth:j(t.maxWidth,n.maxWidth??T.maxWidth??w.maxWidth),style:t.style??n.style??T.style??w.style,bold:k(t.bold)??n.bold??T.bold??w.bold,textPx:A(t.textPx)??n.textPx??T.textPx??w.textPx,transpose:A(t.transpose)??n.transpose??T.transpose??w.transpose,debug:k(t.debug)??n.debug??T.debug??w.debug}}function P(e){return e.querySelector(`:scope > .guidex-render`)?.clientWidth||e.clientWidth||e.parentElement?.clientWidth||0}function F(e,t,n){if(typeof t==`number`)return t;let r=P(e);if(r<=0)return 1/0;let i=r-(p[n]?.padding??0);return i>0?i:r}function I(e){for(let t of e.childNodes)if(t.nodeType===Node.TEXT_NODE&&t.nodeValue?.trim())return t.nodeValue.trim();return E.get(e)??``}function L(e){let t=e.querySelector(`:scope > .guidex-render`);if(t)return t;let n=document.createElement(`div`);return n.className=`guidex-render`,e.replaceChildren(n),n}function R(e,t){let n=document.createElement(`p`);n.className=`guidex-error`,n.textContent=t,e.replaceChildren(n)}function z(e,t){let n=[...p[e]?.scriptTransforms??[]];return t!==0&&n.push(u(t)),n}async function B(e){let n=(D.get(e)??0)+1;D.set(e,n);let r=N(e),i=I(e);E.set(e,i);let a=L(e),o=F(e,r.maxWidth,r.style);O.set(e,o);let s=document.createElement(`div`),c=new t(i,{transforms:z(r.style,r.transpose)});try{if(await new x(c).render(s,{style:r.style,bold:r.bold,textPx:r.textPx,debug:r.debug,maxWidthPx:o}),D.get(e)!==n)return;a.replaceChildren(...s.childNodes),a.style.cssText=s.style.cssText,s.dataset.style&&(a.dataset.style=s.dataset.style)}catch(t){if(D.get(e)!==n)return;console.error(`[guidex]`,t),R(a,t instanceof Error?t.message:String(t))}}var V=new WeakMap;function H(e){let t=N(e),n=F(e,t.maxWidth,t.style);return Math.abs(n-(O.get(e)??NaN))>1}function U(e){if(V.has(e))return;let t;if(typeof ResizeObserver<`u`){let n=new ResizeObserver(()=>{H(e)&&B(e)});n.observe(e),t=()=>n.disconnect()}else{let n=()=>{H(e)&&B(e)};window.addEventListener(`resize`,n),t=()=>window.removeEventListener(`resize`,n)}V.set(e,t)}function W(e){V.get(e)?.(),V.delete(e),E.delete(e),M.delete(e),D.delete(e),O.delete(e)}async function G(e,n,r={}){M.set(e,r);let i=(D.get(e)??0)+1;D.set(e,i),E.set(e,n);let a=N(e),o=L(e),s=F(e,a.maxWidth,a.style);O.set(e,s),U(e);let c=document.createElement(`div`),l=new t(n,{transforms:z(a.style,a.transpose)});try{if(await new x(l).render(c,{style:a.style,bold:a.bold,textPx:a.textPx,debug:a.debug,maxWidthPx:s}),D.get(e)!==i)return;o.replaceChildren(...c.childNodes),o.style.cssText=c.style.cssText,c.dataset.style&&(o.dataset.style=c.dataset.style)}catch(t){if(D.get(e)!==i)return;console.error(`[guidex]`,t),R(o,t instanceof Error?t.message:String(t))}}async function K(e=document){let t=T.selector??C,n=[];return e instanceof Element&&e.matches(t)&&n.push(e),n.push(...e.querySelectorAll(t)),Promise.all(n.map(e=>(U(e),B(e)))).then(()=>void 0)}var q=!1;function J(){if(q||typeof MutationObserver>`u`)return;q=!0;let e=T.selector??C;new MutationObserver(t=>{let n=new Set;for(let r of t)for(let t of r.addedNodes)if(t instanceof Element&&!t.closest(`.guidex-render`)){t.matches(e)&&n.add(t);for(let r of t.querySelectorAll(e))n.add(r)}for(let e of n)U(e),B(e)}).observe(document.documentElement,{childList:!0,subtree:!0})}function Y(e={}){T={...T,...e},J(),K()}return document.readyState===`loading`?document.addEventListener(`DOMContentLoaded`,()=>Y(),{once:!0}):Y(),e.dispose=W,e.init=Y,e.renderAll=K,e.renderScore=G,e.version=S,e})({});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "guidex",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
4
4
  "description": "Guidex — render plainchant scores from a compact GuidoScript notation, as a web app and an embeddable runtime",
5
5
  "type": "module",
6
6
  "workspaces": [