@monowind/ascii 0.2.10 → 0.2.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -75,6 +75,9 @@ below.
75
75
  the attribute.
76
76
  - `effect` attribute: `rainbow` or `metal` — per-cell color mapped to
77
77
  the `--mw-ansi-*` theme tokens, so effects follow your theme.
78
+ - `trim` attribute: drops the blank rows and columns around the art —
79
+ a FIGlet glyph keeps its font's leading space column and descender
80
+ row, so a drop cap floated beside text (`float-left`) sits tight.
78
81
  - `registerAsciiFont(name, data)`: register raw `.flf`/`.tlf` text —
79
82
  the bring-your-own-file path for fonts this package doesn't
80
83
  redistribute (zipped fonts must be extracted first). SGR color
package/dist/cdn.js CHANGED
@@ -30155,13 +30155,13 @@ of new full-width/kern/smush alternatives, but default output is NOT changed.
30155
30155
  ███▀▄██@
30156
30156
  ▀█▀▄███@
30157
30157
  @@
30158
- `);function h(e,t){let n=Array.from({length:t.height},()=>({chars:[],paints:[]})),r={lines:Array.from({length:t.height},()=>` `),width:1},i=!0;for(let a of e){let e=t.glyphs.get(a===`\xA0`?32:a.codePointAt(0))??r;_(n,e,i?0:g(n,e,t),t),i=!1}return{lines:n.map(e=>e.chars.map(e=>e===t.hardblank?` `:e).join(``)),runs:y(n)}}function g(e,t,n){if(n.layout===`full`)return 0;let r=1/0;for(let i=0;i<e.length;i++){let a=e[i].chars,o=t.lines[i]??``,s=0;for(;s<a.length&&a[a.length-1-s]===` `;)s++;let c=0;for(;c<o.length&&o.charAt(c)===` `;)c++;let l=s+c;if(n.layout!==`kerning`){let e=a[a.length-1-s],t=o.charAt(c);e!==void 0&&t!==``&&v(e,t,n)!==null&&l++}r=Math.min(r,l)}return Number.isFinite(r)?r:0}function _(e,t,n,r){for(let i=0;i<e.length;i++){let a=e[i],o=t.lines[i]??``,s=t.colors?.[i],c=Math.min(n,a.chars.length,o.length),l=a.chars.length-c;for(let e=0;e<c;e++){let t=a.chars[l+e],n=o.charAt(e),i=a.paints[l+e],c=s?.[e];if(t===` `)a.chars[l+e]=n,a.paints[l+e]=n===` `?i:c;else if(n!==` `){let o=v(t,n,r);a.chars[l+e]=o??n,a.paints[l+e]=o===t?i:c}}for(let e=c;e<o.length;e++)a.chars.push(o.charAt(e)),a.paints.push(s?.[e])}}function v(e,t,n){if(e===` `)return t;if(t===` `)return e;let{hardblank:r}=n;if(n.layout===`smush-universal`)return e===r||t===r?null:t;let i=n.rules;if(e===r||t===r)return i&32&&e===r&&t===r?r:null;if(i&1&&e===t)return e;if(i&2){if(e===`_`&&`|/\\[]{}()<>`.includes(t))return t;if(t===`_`&&`|/\\[]{}()<>`.includes(e))return e}if(i&4){let n=e=>e===`|`?1:`/\\`.includes(e)?2:`[]`.includes(e)?3:`{}`.includes(e)?4:`()`.includes(e)?5:`<>`.includes(e)?6:0,r=n(e),i=n(t);if(r&&i&&r!==i)return r>i?e:t}if(i&8&&[`[]`,`][`,`{}`,`}{`,`()`,`)(`].includes(e+t))return`|`;if(i&16){if(e===`/`&&t===`\\`)return`|`;if(e===`\\`&&t===`/`)return`Y`;if(e===`>`&&t===`<`)return`X`}return null}function y(e){let t=[];return e.forEach((e,n)=>{let r=-1,i,a=e=>{r>=0&&i&&t.push({line:n,start:r,end:e,paint:b(i)}),r=-1,i=void 0};e.paints.forEach((e,t)=>{x(e,i)||(a(t),e&&(r=t,i=e))}),a(e.paints.length)}),t}function b(e){let t={};return e.color&&(t.color=e.color),e.backgroundColor&&(t.backgroundColor=e.backgroundColor),e.bold&&(t.fontWeight=`bold`),t}function x(e,t){return e===t?!0:!e||!t?!1:e.color===t.color&&e.backgroundColor===t.backgroundColor&&e.bold===t.bold}var S={rainbow:[`red`,`yellow`,`green`,`cyan`,`blue`,`magenta`],metal:[`bright-white`,`white`,`bright-cyan`,`bright-blue`,`blue`]};function C(e){return e in S}function w(e,t){let n=S[e],r=e=>`var(--mw-ansi-${n[e%n.length]})`,i=[];return e===`metal`?(t.forEach((e,a)=>{e.length>0&&i.push({line:a,start:0,end:e.length,paint:{color:r(Math.floor(a*n.length/Math.max(1,t.length)))}})}),i):(t.forEach((e,t)=>{for(let n=0;n<e.length;n+=2)i.push({line:t,start:n,end:Math.min(e.length,n+2),paint:{color:r(Math.floor(n/2))}})}),i)}var T=new Set,E=new WeakSet,D=null;function O(e){D=e}var k=typeof HTMLElement>`u`?class{}:HTMLElement,A=`<style>
30158
+ `);function h(e,t){let n=Array.from({length:t.height},()=>({chars:[],paints:[]})),r={lines:Array.from({length:t.height},()=>` `),width:1},i=!0;for(let a of e){let e=t.glyphs.get(a===`\xA0`?32:a.codePointAt(0))??r;v(n,e,i?0:_(n,e,t),t),i=!1}return{lines:n.map(e=>e.chars.map(e=>e===t.hardblank?` `:e).join(``)),runs:b(n)}}function g(e){let t=e.lines.map(e=>e.trim()!==``),n=t.indexOf(!0);if(n<0)return{lines:[],runs:[]};let r=t.lastIndexOf(!0)+1,i=e.lines.slice(n,r),a=Math.min(...i.map(e=>e.search(/\S/)).filter(e=>e>=0)),o=Math.max(...i.map(e=>e.trimEnd().length));return{lines:i.map(e=>e.slice(a,o)),runs:e.runs.filter(e=>e.line>=n&&e.line<r).map(e=>({...e,line:e.line-n,start:Math.max(e.start,a)-a,end:Math.min(e.end,o)-a})).filter(e=>e.end>e.start)}}function _(e,t,n){if(n.layout===`full`)return 0;let r=1/0;for(let i=0;i<e.length;i++){let a=e[i].chars,o=t.lines[i]??``,s=0;for(;s<a.length&&a[a.length-1-s]===` `;)s++;let c=0;for(;c<o.length&&o.charAt(c)===` `;)c++;let l=s+c;if(n.layout!==`kerning`){let e=a[a.length-1-s],t=o.charAt(c);e!==void 0&&t!==``&&y(e,t,n)!==null&&l++}r=Math.min(r,l)}return Number.isFinite(r)?r:0}function v(e,t,n,r){for(let i=0;i<e.length;i++){let a=e[i],o=t.lines[i]??``,s=t.colors?.[i],c=Math.min(n,a.chars.length,o.length),l=a.chars.length-c;for(let e=0;e<c;e++){let t=a.chars[l+e],n=o.charAt(e),i=a.paints[l+e],c=s?.[e];if(t===` `)a.chars[l+e]=n,a.paints[l+e]=n===` `?i:c;else if(n!==` `){let o=y(t,n,r);a.chars[l+e]=o??n,a.paints[l+e]=o===t?i:c}}for(let e=c;e<o.length;e++)a.chars.push(o.charAt(e)),a.paints.push(s?.[e])}}function y(e,t,n){if(e===` `)return t;if(t===` `)return e;let{hardblank:r}=n;if(n.layout===`smush-universal`)return e===r||t===r?null:t;let i=n.rules;if(e===r||t===r)return i&32&&e===r&&t===r?r:null;if(i&1&&e===t)return e;if(i&2){if(e===`_`&&`|/\\[]{}()<>`.includes(t))return t;if(t===`_`&&`|/\\[]{}()<>`.includes(e))return e}if(i&4){let n=e=>e===`|`?1:`/\\`.includes(e)?2:`[]`.includes(e)?3:`{}`.includes(e)?4:`()`.includes(e)?5:`<>`.includes(e)?6:0,r=n(e),i=n(t);if(r&&i&&r!==i)return r>i?e:t}if(i&8&&[`[]`,`][`,`{}`,`}{`,`()`,`)(`].includes(e+t))return`|`;if(i&16){if(e===`/`&&t===`\\`)return`|`;if(e===`\\`&&t===`/`)return`Y`;if(e===`>`&&t===`<`)return`X`}return null}function b(e){let t=[];return e.forEach((e,n)=>{let r=-1,i,a=e=>{r>=0&&i&&t.push({line:n,start:r,end:e,paint:x(i)}),r=-1,i=void 0};e.paints.forEach((e,t)=>{S(e,i)||(a(t),e&&(r=t,i=e))}),a(e.paints.length)}),t}function x(e){let t={};return e.color&&(t.color=e.color),e.backgroundColor&&(t.backgroundColor=e.backgroundColor),e.bold&&(t.fontWeight=`bold`),t}function S(e,t){return e===t?!0:!e||!t?!1:e.color===t.color&&e.backgroundColor===t.backgroundColor&&e.bold===t.bold}var C={rainbow:[`red`,`yellow`,`green`,`cyan`,`blue`,`magenta`],metal:[`bright-white`,`white`,`bright-cyan`,`bright-blue`,`blue`]};function w(e){return e in C}function T(e,t){let n=C[e],r=e=>`var(--mw-ansi-${n[e%n.length]})`,i=[];return e===`metal`?(t.forEach((e,a)=>{e.length>0&&i.push({line:a,start:0,end:e.length,paint:{color:r(Math.floor(a*n.length/Math.max(1,t.length)))}})}),i):(t.forEach((e,t)=>{for(let n=0;n<e.length;n+=2)i.push({line:t,start:n,end:Math.min(e.length,n+2),paint:{color:r(Math.floor(n/2))}})}),i)}var E=new Set,D=new WeakSet,O=null;function k(e){O=e}var A=typeof HTMLElement>`u`?class{}:HTMLElement,j=`<style>
30159
30159
  :host { display: block; }
30160
30160
  #mirror { margin: 0; font: inherit; line-height: inherit; letter-spacing: inherit; white-space: pre; color: transparent; }
30161
30161
  /* The engine paints a selection on its grid (specs/wide-characters.md);
30162
30162
  * the transcript's own highlight stays invisible, like the light DOM's. */
30163
30163
  #mirror::selection { color: transparent; text-shadow: none; background: transparent; }
30164
30164
  .alt { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; user-select: none; -webkit-user-select: none; }
30165
- </style><pre id="mirror" aria-hidden="true"></pre><span class="alt"><slot></slot></span>`,j=class extends k{#e=null;#t=null;constructor(){super();let e=this.attachShadow({mode:`open`});e.innerHTML=A,this.#t=e.getElementById(`mirror`)}get font(){return this.#e}set font(t){this.#e=t,(0,e.invalidateLeaves)()}syncMirror(e){let t=e.join(`
30166
- `);this.#t&&this.#t.textContent!==t&&(this.#t.textContent=t)}};function M(e){let t=N(e);return e.syncMirror?.(t.lines),t}function N(e){let t=(e.textContent??``).replace(/[ \t\r\n\f]+/g,` `).replace(/^ | $/g,``);e.children.length>0&&!E.has(e)&&(E.add(e),console.warn(`[monowind] <mono-ascii> takes text only; element children are ignored.`,e));let n=e.getAttribute(`font`)??`standard`,r=e.font??m(n);if(!r)return T.has(`font:${n}`)||(T.add(`font:${n}`),D?D(n):console.warn(`[monowind] <mono-ascii>: no registered font "${n}"; rendering plain text.`,e)),{lines:t?[t]:[]};if(!t)return{lines:[]};let i=h(t,r),a=e.getAttribute(`effect`);return a&&C(a)?{lines:i.lines,runs:w(a,i.lines)}:{lines:i.lines,runs:i.runs}}function P(){typeof customElements>`u`||customElements.get(`mono-ascii`)||(customElements.define(`mono-ascii`,j),(0,e.registerLeafRenderer)({tag:`mono-ascii`,observedAttributes:[`font`,`effect`],render:M,selectionTarget:e=>e.shadowRoot?.getElementById(`mirror`)??null}))}P();var F=`@layer base{mono-ascii{display:block}}`,I=document.createElement(`style`);I.setAttribute(`data-monowind-ascii`,``),I.textContent=F,document.head.appendChild(I);var L=new Map;function R(e){let t=e.toLowerCase().replace(/\.(flf|tlf)$/,``),n=L.get(t);if(n)return n;let r=z(t).finally(()=>L.delete(t));return L.set(t,r),r}async function z(e){let t=m(e);if(t)return t;for(let t of[`fonts/`,`https://cdn.jsdelivr.net/npm/@monowind/ascii@0.2.10/fonts/`])for(let n of[`flf`,`tlf`])try{let r=await fetch(`${t}${e}.${n}`);if(r.ok)return p(e,await r.text())}catch{}return console.warn(`[monowind] loadFont("${e}"): no such bundled font.`),null}O(e=>void R(e));var B=globalThis.monowind;Object.assign(globalThis,{monowind:{...B,ascii:{...B?.ascii,asciiFont:m,loadFont:R,registerAsciiFont:p,version:`0.2.10`}}})})(monowind);
30165
+ </style><pre id="mirror" aria-hidden="true"></pre><span class="alt"><slot></slot></span>`,M=class extends A{#e=null;#t=null;constructor(){super();let e=this.attachShadow({mode:`open`});e.innerHTML=j,this.#t=e.getElementById(`mirror`)}get font(){return this.#e}set font(t){this.#e=t,(0,e.invalidateLeaves)()}syncMirror(e){let t=e.join(`
30166
+ `);this.#t&&this.#t.textContent!==t&&(this.#t.textContent=t)}};function N(e){let t=P(e);return e.syncMirror?.(t.lines),t}function P(e){let t=(e.textContent??``).replace(/[ \t\r\n\f]+/g,` `).replace(/^ | $/g,``);e.children.length>0&&!D.has(e)&&(D.add(e),console.warn(`[monowind] <mono-ascii> takes text only; element children are ignored.`,e));let n=e.getAttribute(`font`)??`standard`,r=e.font??m(n);if(!r)return E.has(`font:${n}`)||(E.add(`font:${n}`),O?O(n):console.warn(`[monowind] <mono-ascii>: no registered font "${n}"; rendering plain text.`,e)),{lines:t?[t]:[]};if(!t)return{lines:[]};let i=h(t,r),a=e.hasAttribute(`trim`)?g(i):i,o=e.getAttribute(`effect`);return o&&w(o)?{lines:a.lines,runs:T(o,a.lines)}:a}function F(){typeof customElements>`u`||customElements.get(`mono-ascii`)||(customElements.define(`mono-ascii`,M),(0,e.registerLeafRenderer)({tag:`mono-ascii`,observedAttributes:[`font`,`effect`,`trim`],render:N,selectionTarget:e=>e.shadowRoot?.getElementById(`mirror`)??null}))}F();var I=`@layer base{mono-ascii{display:block}}`,L=document.createElement(`style`);L.setAttribute(`data-monowind-ascii`,``),L.textContent=I,document.head.appendChild(L);var R=new Map;function z(e){let t=e.toLowerCase().replace(/\.(flf|tlf)$/,``),n=R.get(t);if(n)return n;let r=B(t).finally(()=>R.delete(t));return R.set(t,r),r}async function B(e){let t=m(e);if(t)return t;for(let t of[`fonts/`,`https://cdn.jsdelivr.net/npm/@monowind/ascii@0.2.12/fonts/`])for(let n of[`flf`,`tlf`])try{let r=await fetch(`${t}${e}.${n}`);if(r.ok)return p(e,await r.text())}catch{}return console.warn(`[monowind] loadFont("${e}"): no such bundled font.`),null}k(e=>void z(e));var V=globalThis.monowind;Object.assign(globalThis,{monowind:{...V,ascii:{...V?.ascii,asciiFont:m,loadFont:z,registerAsciiFont:p,version:`0.2.12`}}})})(monowind);
30167
30167
  //# sourceMappingURL=cdn.js.map