guidex 0.2.4 → 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.
- package/dist/lib/{core-dx503oih.js → core-CmzGmufM.js} +76 -5
- package/dist/lib/embed/index.js +1 -1
- package/dist/lib/embed/manual.js +1 -1
- package/dist/lib/guidex.css +6 -0
- package/dist/lib/guidoStyles.d.ts +11 -5
- package/dist/lib/react/index.js +1 -1
- package/dist-embed/guidex-embed.min.css +1 -1
- package/dist-embed/guidex-embed.min.js +1 -1
- package/package.json +1 -1
|
@@ -70,6 +70,62 @@ function escape(text) {
|
|
|
70
70
|
}
|
|
71
71
|
//#endregion
|
|
72
72
|
//#region src/guidoScriptTransforms.ts
|
|
73
|
+
/**
|
|
74
|
+
* Source-level transformations for GuidoScript: named rewrites applied
|
|
75
|
+
* to a script's raw source before parsing (see the `transforms` option
|
|
76
|
+
* on the GuidoScript constructor). Each one receives the source and
|
|
77
|
+
* returns the rewritten source — or the source unchanged when the
|
|
78
|
+
* feature does not apply. They compose in registration order, and the
|
|
79
|
+
* parsed script never sees which ones ran. New script-level features
|
|
80
|
+
* are added here, and only here: as entries of SCRIPT_TRANSFORMS, or —
|
|
81
|
+
* when the feature takes parameters — as factories returning a
|
|
82
|
+
* ScriptTransform (see `transposeBy`).
|
|
83
|
+
*/
|
|
84
|
+
/** The first character unit of a text run: a backslash escape pair or a
|
|
85
|
+
* single character, skipping leading whitespace. Returns null when the
|
|
86
|
+
* run has no characters to mark. */
|
|
87
|
+
function firstCharUnit(text) {
|
|
88
|
+
const chars = [...text];
|
|
89
|
+
for (let i = 0; i < chars.length; i++) {
|
|
90
|
+
const ch = chars[i];
|
|
91
|
+
if (/\s/.test(ch)) continue;
|
|
92
|
+
return {
|
|
93
|
+
unit: ch === "\\" && chars[i + 1] !== void 0 ? ch + chars[i + 1] : ch,
|
|
94
|
+
index: i
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
/** The `startWithInitial` transform: finds the first syllable group with
|
|
100
|
+
* actual notes (the clef and no-notes groups don't count) and wraps the
|
|
101
|
+
* syllable's first character in the `*…*` initial marker. Already-marked
|
|
102
|
+
* text (leading `*`) and syllables without text are left alone. */
|
|
103
|
+
function startWithInitial(source) {
|
|
104
|
+
const clefMatch = source.match(/^\s*\(([^)]*)\)/);
|
|
105
|
+
const offset = clefMatch ? clefMatch[0].length : 0;
|
|
106
|
+
const rest = source.slice(offset);
|
|
107
|
+
for (const match of rest.matchAll(/((?:[^()\\]|\\.)*)\(((?:[^)\\]|\\.)*)\)/g)) {
|
|
108
|
+
const [, text, notes] = match;
|
|
109
|
+
if (unescape(notes).trim().length === 0) continue;
|
|
110
|
+
const unit = firstCharUnit(text);
|
|
111
|
+
if (!unit || text.trimStart().startsWith("*")) return source;
|
|
112
|
+
const unitStart = offset + match.index + unit.index;
|
|
113
|
+
const unitEnd = unitStart + unit.unit.length;
|
|
114
|
+
return `${source.slice(0, unitStart)}*${source.slice(unitStart, unitEnd)}*${source.slice(unitEnd)}`;
|
|
115
|
+
}
|
|
116
|
+
return source;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* The built-in transformations, keyed by name; pass the ones a feature
|
|
120
|
+
* needs to the GuidoScript constructor.
|
|
121
|
+
*/
|
|
122
|
+
var SCRIPT_TRANSFORMS = {
|
|
123
|
+
/** Wraps the first letter of the first syllable that has notes in
|
|
124
|
+
* `*…*`, the initial marker of the style marking system. */
|
|
125
|
+
startWithInitial: {
|
|
126
|
+
name: "startWithInitial",
|
|
127
|
+
apply: startWithInitial
|
|
128
|
+
} };
|
|
73
129
|
/** The pitch rows of the chant font: every character carrying pitch
|
|
74
130
|
* information, grouped into rows of neighbouring pitches from low to
|
|
75
131
|
* high. A transpose shift moves a character this many positions along
|
|
@@ -144,6 +200,11 @@ function transposeBy(shift, options = {}) {
|
|
|
144
200
|
}
|
|
145
201
|
//#endregion
|
|
146
202
|
//#region src/guidoStyles.ts
|
|
203
|
+
/**
|
|
204
|
+
* Style sets for the renderer: named appearance rules (fonts, colors, and
|
|
205
|
+
* the special syllable decorations) kept in one constant registry, so a
|
|
206
|
+
* new style is a data entry here rather than a renderer fork.
|
|
207
|
+
*/
|
|
147
208
|
/** Text characters (* and †) rendered in Times New Roman. */
|
|
148
209
|
var TIMES_MARKER_GLYPHS = {
|
|
149
210
|
chars: /* @__PURE__ */ new Set(["*", "†"]),
|
|
@@ -206,7 +267,8 @@ var STYLE_SETS = {
|
|
|
206
267
|
raise: .1,
|
|
207
268
|
color: "var(--red)"
|
|
208
269
|
},
|
|
209
|
-
padding: 12
|
|
270
|
+
padding: 12,
|
|
271
|
+
scriptTransforms: [SCRIPT_TRANSFORMS.startWithInitial]
|
|
210
272
|
},
|
|
211
273
|
/** Times New Roman text, strictly black and white. */
|
|
212
274
|
Vesperale: {
|
|
@@ -251,7 +313,8 @@ var STYLE_SETS = {
|
|
|
251
313
|
measureScale: .95,
|
|
252
314
|
raise: .2
|
|
253
315
|
},
|
|
254
|
-
padding: 12
|
|
316
|
+
padding: 12,
|
|
317
|
+
scriptTransforms: []
|
|
255
318
|
}
|
|
256
319
|
};
|
|
257
320
|
/**
|
|
@@ -864,7 +927,7 @@ var GuidoRender = class GuidoRender {
|
|
|
864
927
|
//#region src/embed/core.ts
|
|
865
928
|
var version = {
|
|
866
929
|
name: "guidex",
|
|
867
|
-
version: "0.2.
|
|
930
|
+
version: "0.2.5",
|
|
868
931
|
description: "Guidex — render plainchant scores from a compact GuidoScript notation, as a web app and an embeddable runtime",
|
|
869
932
|
type: "module",
|
|
870
933
|
workspaces: ["examples/*"],
|
|
@@ -1032,6 +1095,14 @@ function renderError(wrapper, message) {
|
|
|
1032
1095
|
note.textContent = message;
|
|
1033
1096
|
wrapper.replaceChildren(note);
|
|
1034
1097
|
}
|
|
1098
|
+
/** The transforms a score renders with: the style set's defaults (BNS
|
|
1099
|
+
* marks the first initial) plus the user-requested transpose. An unknown
|
|
1100
|
+
* style name yields no defaults here — the render itself reports it. */
|
|
1101
|
+
function scriptTransforms(style, transpose) {
|
|
1102
|
+
const transforms = [...STYLE_SETS[style]?.scriptTransforms ?? []];
|
|
1103
|
+
if (transpose !== 0) transforms.push(transposeBy(transpose));
|
|
1104
|
+
return transforms;
|
|
1105
|
+
}
|
|
1035
1106
|
/** Renders one target element. The score is built into a detached
|
|
1036
1107
|
* scratch wrapper and swapped into the live one only when this run is
|
|
1037
1108
|
* still the latest — a stale render that finished late leaves no
|
|
@@ -1046,7 +1117,7 @@ async function renderElement(el) {
|
|
|
1046
1117
|
const widthPx = resolveWidthPx(el, options.maxWidth, options.style);
|
|
1047
1118
|
lastWidths.set(el, widthPx);
|
|
1048
1119
|
const scratch = document.createElement("div");
|
|
1049
|
-
const script = new GuidoScript(source, { transforms: options.
|
|
1120
|
+
const script = new GuidoScript(source, { transforms: scriptTransforms(options.style, options.transpose) });
|
|
1050
1121
|
try {
|
|
1051
1122
|
await new GuidoRender(script).render(scratch, {
|
|
1052
1123
|
style: options.style,
|
|
@@ -1119,7 +1190,7 @@ async function renderScore(el, source, options = {}) {
|
|
|
1119
1190
|
lastWidths.set(el, widthPx);
|
|
1120
1191
|
attachResizeListener(el);
|
|
1121
1192
|
const scratch = document.createElement("div");
|
|
1122
|
-
const script = new GuidoScript(source, { transforms: resolved.
|
|
1193
|
+
const script = new GuidoScript(source, { transforms: scriptTransforms(resolved.style, resolved.transpose) });
|
|
1123
1194
|
try {
|
|
1124
1195
|
await new GuidoRender(script).render(scratch, {
|
|
1125
1196
|
style: resolved.style,
|
package/dist/lib/embed/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as version, i as renderScore, n as init, r as renderAll, t as dispose } from "../core-
|
|
1
|
+
import { a as version, i as renderScore, n as init, r as renderAll, t as dispose } from "../core-CmzGmufM.js";
|
|
2
2
|
//#region src/embed/index.ts
|
|
3
3
|
if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", () => init(), { once: true });
|
|
4
4
|
else init();
|
package/dist/lib/embed/manual.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as version, i as renderScore, n as init, r as renderAll, t as dispose } from "../core-
|
|
1
|
+
import { a as version, i as renderScore, n as init, r as renderAll, t as dispose } from "../core-CmzGmufM.js";
|
|
2
2
|
export { dispose, init, renderAll, renderScore, version };
|
package/dist/lib/guidex.css
CHANGED
|
@@ -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) {
|
|
@@ -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;
|
package/dist/lib/react/index.js
CHANGED
|
@@ -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-
|
|
2
|
+
import { a as version, i as renderScore, n as init, r as renderAll, t as dispose } from "../core-CmzGmufM.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.5`,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})({});
|