guidex 0.2.5 → 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 +20 -3
- package/dist/lib/{core-CmzGmufM.js → core-hF6L1EtS.js} +8 -2
- package/dist/lib/embed/index.js +1 -1
- package/dist/lib/embed/manual.d.ts +8 -1
- package/dist/lib/embed/manual.js +2 -2
- package/dist/lib/guidoScript.d.ts +3 -0
- package/dist/lib/react/GuidexScore.d.ts +1 -1
- package/dist/lib/react/index.js +1 -1
- package/dist-embed/guidex-embed.min.js +1 -1
- package/package.json +1 -1
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
|
|
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'), '(
|
|
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="(
|
|
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) {
|
|
@@ -317,6 +322,7 @@ var STYLE_SETS = {
|
|
|
317
322
|
scriptTransforms: []
|
|
318
323
|
}
|
|
319
324
|
};
|
|
325
|
+
var DEFAULT_STYLE_SET = "BNS";
|
|
320
326
|
/**
|
|
321
327
|
* Resolves a syllable's raw text into the runs it renders as: the whole-
|
|
322
328
|
* syllable `**` star renders as the bold ∗ operator, a `__…__` or `_…_`
|
|
@@ -927,7 +933,7 @@ var GuidoRender = class GuidoRender {
|
|
|
927
933
|
//#region src/embed/core.ts
|
|
928
934
|
var version = {
|
|
929
935
|
name: "guidex",
|
|
930
|
-
version: "0.2.
|
|
936
|
+
version: "0.2.6",
|
|
931
937
|
description: "Guidex — render plainchant scores from a compact GuidoScript notation, as a web app and an embeddable runtime",
|
|
932
938
|
type: "module",
|
|
933
939
|
workspaces: ["examples/*"],
|
|
@@ -1259,4 +1265,4 @@ function init(options = {}) {
|
|
|
1259
1265
|
renderAll();
|
|
1260
1266
|
}
|
|
1261
1267
|
//#endregion
|
|
1262
|
-
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 };
|
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-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';
|
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-
|
|
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 };
|
|
@@ -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,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. `'(
|
|
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;
|
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-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 +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}`)}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})({});
|
|
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})({});
|