limmat 0.0.0-stage → 0.1.0

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.
@@ -0,0 +1,15 @@
1
+ // limmat, MIT, Copyright (c) 2026 Daan Rosendal
2
+ var Ve=/^ {0,3}(#{1,6})(?:[ \t]([^\n]*))?$/,V=/^( *)([-*+]|\d{1,9}[.)])(?:( +)([^\n]*)|$)/,Ye=/^( {0,3})(`{3,}|~{3,})([^\n]*)$/,je=/^ {0,3}\*[ \t]+\*{2,}$/,et=/^ {0,3}(?:[-*+]|\d{1,9}[.)])$/,me=/^ {0,3}([-*_])(?:[ \t]*\1){2,}[ \t]*$/,be=/^ {0,3}>/,De=/^ {0,3}\|/,Ue=/^ {0,3}\|?[ \t]*:?-+:?[ \t]*(?:\|[ \t]*:?-+:?[ \t]*)*(?:\|[ \t]*)?$/,He=/^[ \t|:-]*$/,tt=/^ {0,3}<details( open)?>(?:<summary>((?:(?!<\/summary>)[^\n])*)<\/summary>)?[ \t]*$/i,ge=/^ {0,3}<\/details>[ \t]*$/i,nt=/^ {0,3}<summary>((?:(?!<\/summary>)[^\n])*)<\/summary>[ \t]*$/i,st=["<details>","<details open>","</details>"],lt=/^ {0,3}(?:`+|~+)$/,ne=e=>e.length-e.trimStart().length;function Y(e){let l=Ve.exec(e);if(!l)return null;let i=(l[2]??"").trim(),n=i.length;for(;n>0&&i[n-1]==="#";)n--;return n<i.length&&(n===0||i[n-1]===" "||i[n-1]===" ")&&(i=i.slice(0,n).trimEnd()),[l[1].length,i]}function Z(e){e=e.trim(),e[0]==="|"&&(e=e.slice(1)),e.endsWith("|")&&!e.endsWith("\\|")&&(e=e.slice(0,-1));let l=[],i="";for(let n=0;n<e.length;n++)e[n]==="\\"&&e[n+1]==="|"?(i+="|",n++):e[n]==="|"?(l.push(i.trim()),i=""):i+=e[n];return l.push(i.trim()),l}var ot=e=>Z(e).map(l=>l[0]===":"?l.endsWith(":")?"center":"left":l.endsWith(":")?"right":null),le=e=>{let l=Ye.exec(e);return l&&!(l[2][0]==="`"&&l[3].includes("`"))?l:null},ke=(e,l)=>new RegExp(`^${l}${e[2][0]}{${e[2].length},}[ \\t]*$`);function _e(e){let l=tt.exec(e);return l&&(l[2]===void 0||l[2].trim())?l:null}function te(e,l){let i=0;for(;i<4&&e[i]===" ";)i++;if(i>3)return!1;let n=e.slice(i).toLowerCase(),d=n.length;for(;d>0&&(n[d-1]===" "||n[d-1]===" ");)d--;let m=n.slice(0,d);if(st.some(t=>t.startsWith(n)||m.length<n.length&&t===m))return!0;let r=/^<details( open)?>/.exec(n);if(r){let t=n.slice(r[0].length);return!!t&&("<summary>".startsWith(t)||t.startsWith("<summary>")&&!t.includes("</summary>"))}if(l&&(n.length<9?"<summary>".startsWith(n):n.startsWith("<summary>"))){let t=n.slice(9),g=t.indexOf("</summary>");return g<0||!t.slice(g+10).trim()}return!1}function se(e,l,i=!1){if(i&&(_e(e)||ge.test(e))||le(e)||Y(e)||me.test(e)||be.test(e)||!l&&De.test(e))return!0;let n=V.exec(e);return!!n&&!!n[4]&&n[1].length<4&&n[2].length<4}function it(e,l,i,n,d){let m=e.length,r=ke(i," {0,3}"),t=l+1,g=!1;for(;t<m;){if(r.test(e[t])){g=!0,t++;break}t++}let a=!g&&!d&&n&&t===m&&t-1>l&&lt.test(e[m-1]);return{k:"f",a:l,e:a?t-1:t,b:t,lang:i[3].trim().split(/\s+/)[0],closed:g,ind:i[1].length}}function rt(e,l,i){let n=e.length,d=l,m=!1,r=null;for(;d<n&&e[d].trim();d++){if(!be.test(e[d])){if(!m||se(e[d],!1,i))break;continue}let t=e[d].replace(/^ {0,3}> ?/,""),g=r?null:le(t);r?(r.test(t)&&(r=null),m=!1):g?(r=ke(g," {0,3}"),m=!1):m=!!t.trim()&&!Y(t)&&!me.test(t)}return d}function ct(e,l,i,n,d){let m=e.length,r=l+1,t=null,g=!1,a=l+1;for(;r<m;r++){let f=e[r];if(t){if(f.trim()&&ne(f)<2)break;t.test(f)&&(t=null,n=!1),a=r+1;continue}if(!f.trim()){g=!0;continue}let c=ne(f);if(c>=2){let w=le(f.slice(Math.min(c,i)));w&&(t=ke(w," *"))}else if(V.test(f)||se(f,!1,d)||g||!n)break;g=!1,n=!t,a=r+1}return{last:a,j:r}}function xe(e,l,i,n,d=0,m=!1){var f;let r=[],t=e.length,g=[],a=0;for(;a<t;){let c=e[a];if(!c.trim()){r.length>(g.length?g[g.length-1].u:0)&&(r[r.length-1].b=a+1),l=null,a++;continue}if(d){let o=_e(c);if(m&&a===t-1&&(o||ge.test(c)||te(c,!!g.length&&a===g[g.length-1].a+1))){a++;continue}if(o){g.push({a,u:r.length,open:!!o[1],sum:o[2]===void 0?null:o[2].trim()}),l=null,a++;continue}if(g.length&&ge.test(c)){let b=g.pop();if(l=null,!g.length){r.length=b.u;let h=Pe(e,b,a,!1);r.push({k:"d",a:b.a,e:a+1,b:a+1,open:b.open,closed:!0,sum:h[0],bs:h[1]})}a++;continue}}if(l){if(!se(c,!0,!!d)){r.push({k:"tr",a,e:a+1,b:a+1,al:l}),a++;continue}l=null}let w,y;if(w=le(c)){let o=it(e,a,w,i,n);r.push(o),a=o.b}else if(y=Y(c))r.push({k:"h",a,e:a+1,b:a+1,lv:y[0]}),a++;else if(me.test(c)){if(!n&&i&&a===t-1&&je.test(c)){a++;continue}r.push({k:"hr",a,e:a+1,b:a+1}),a++}else if(be.test(c)){let o=rt(e,a,!!d);r.push({k:"q",a,e:o,b:o}),a=o}else if(w=V.exec(c)){if(w[4]===void 0&&!n&&i&&a===t-1){a++;continue}let o=w[1].length,b=/\d/.test(w[2]),h=((f=w[3])==null?void 0:f.length)??1,U=o+w[2].length+(w[4]===void 0||h>4?1:h),{last:I,j:$}=ct(e,a,U,!!w[4],!!d);r.push({k:"li",a,e:I,b:$,ord:b,num:b?parseInt(w[2],10):0,off:U}),a=$}else{let o=e[a+1],b=De.test(c);if(c.includes("|")&&(b||o!==void 0&&Ue.test(o)&&Z(c).length===Z(o).length)){if(o!==void 0&&Ue.test(o)){let $=ot(o);r.push({k:"th",a,e:a+2,b:a+2,al:$}),l=$,a+=2;continue}if(b&&!n&&(o===void 0||i&&a+1===t-1&&He.test(o))){r.push({k:"th",a,e:t,b:t,pend:!0,al:Z(c).map(()=>null)});break}}if(!b&&!n&&i&&o!==void 0&&a+1===t-1&&c.includes("|")&&He.test(o)){let $=o.split("-").length-1;if($>0&&($>1||/[|:]/.test(o))&&Z(o).length<=Z(c).length){r.push({k:"th",a,e:t,b:t,pend:!0,al:Z(c).map(()=>null)});break}}let h=a+1;for(;h<t&&e[h].trim()&&!se(e[h],!1,!!d);)h++;let U=!n&&i&&h===t&&h-1>a&&et.test(e[t-1]),I=!!d&&m&&h===t&&h-1>a&&te(e[t-1],!1);r.push({k:"p",a,e:U||I?h-1:h,b:h}),a=h}}if(g.length){let c=g[0];r.length=c.u;let w=Pe(e,c,t,m),y=w[0]!==null;for(let o=w[1];!y&&o<t;o++)y=!!e[o].trim()&&!(m&&o===t-1&&te(e[o],!1));y?r.push({k:"d",a:c.a,e:t,b:t,open:c.open,closed:!1,sum:w[0],bs:w[1]}):d===2&&r.push({k:"p",a:c.a,e:c.a+1,b:t})}return r}function Pe(e,l,i,n){if(l.sum!==null)return[l.sum,l.a+1];let d=l.a+1;if(d>=i)return[null,d];if(n&&d===e.length-1&&te(e[d],!0))return[null,d+1];let m=nt.exec(e[d]);return m!=null&&m[1].trim()?[m[1].trim(),d+1]:[null,d]}var re=["b","strong","i","em","u","s","del","ins","mark","small","kbd","sub","sup"],at=new Set(re),We=/[\p{P}\p{S}]/u,ze=/\s/,ut=/[!-/:-@[-`{-~]/,ft=/[A-Za-z0-9_]/,ye=/<br\s*\/?>/iy,Oe=/<(\/?)([A-Za-z]+)>/y,Be=/<([A-Za-z][A-Za-z0-9+.-]*:[^\s<>]*|[\w.+-]+@[\w-]+(?:\.[\w-]+)+)>/y,Ze=/<(?:[A-Za-z][\w.+-]*:[^\s<>]*|[\w.+-]+@[\w.-]*)$/y,Fe=/(?:https?:\/\/|www\.)[^\s<\]]+/iy,qe=/[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)+/y,Ge=8192,ie=30,dt=(e,l)=>{let i=e.charCodeAt(l-1);return l>1&&i>=56320&&i<=57343?e.slice(l-2,l):e[l-1]},ht=(e,l)=>String.fromCodePoint(e.codePointAt(l));function Xe(e){let l=[];for(let i of e){let n=l[l.length-1];i.k==="t"&&n&&n.k==="t"?n.s=n.s+i.s:l.push(i)}return l}function pt(e,l,i){let n=e.length;if(i.n<=0)return null;for(l++;e[l]===" "||e[l]===" ";)l++;if(l>=n)return"p";let d;if(e[l]==="<"){let g=l+1;for(;g<n&&e[g]!==">"&&e[g]!==`
3
+ `&&e[g]!=="<"&&g-l<Ge;)g++;if(i.n-=g-l,g>=n)return"p";if(e[g]!==">")return null;d=e.slice(l+1,g),l=g+1}else{let g=0,a=l;for(;a<n;){let f=e.charCodeAt(a);if(f<=32||f===127)break;if(f===92&&a+1<n){a+=2;continue}if(f===40)g++;else if(f===41&&!g--)break;if(++a-l>Ge)return i.n-=a-l,null}if(i.n-=a-l,a>=n)return"p";d=e.slice(l,a),l=a}let m=()=>{for(;e[l]===" "||e[l]===" "||e[l]===`
4
+ `;)l++},r=()=>d.replace(/\\([!-/:-@[-`{-~])/g,"$1");if(m(),l>=n)return"p";if(e[l]===")")return{end:l+1,href:r()};let t=e[l];if(t==='"'||t==="'"||t==="("){let g=t==="("?")":t,a=Math.min(n,l+501),f=l+1;for(;f<a&&e[f]!==g;)f++;if(i.n-=f-l,f>=a)return f>=n?"p":null;if(l=f+1,m(),l>=n)return"p";if(e[l]===")")return{end:l+1,href:r()}}return null}function gt(e){let l=0,i=0;for(let n of e)n==="("?l++:n===")"&&i++;for(;;){let n=e[e.length-1];if(/[?!.,:;*_~'"]/.test(n))e=e.slice(0,-1);else if(n===")"&&i>l)e=e.slice(0,-1),i--;else return e}}function mt(e,l){if(!e.some(r=>r.k==="g"))return e;let i=[],n=[],d=r=>({k:"t",s:r.s}),m=(r,t)=>{let g=oe(i.slice(r+1),t),a=0;for(let c of g)a=Math.max(a,c.d??0);let f=i[r].tag;i.length=r,i.push({k:"e",tag:f,kids:g,d:a+1})};for(let r of e)if(r.k!=="g")i.push(r);else if(r.o)n.length<ie?(n.push(i.length),i.push(r)):i.push(d(r));else{let t=n.length-1;for(;t>=0&&i[n[t]].tag!==r.tag;)t--;if(t<0)i.push(d(r));else{let g=n[t];n.length=t,m(g,!1)}}if(l)for(;n.length;)m(n.pop(),!0);return i.map(r=>r.k==="g"?d(r):r)}function oe(e,l){if(e=mt(e,l),!e.some(f=>f.k==="d"))return Xe(e);let i={k:"h",x:null},n=i;for(let f of e)n.x=f,f.p=n,f.x=null,n=f;let d=[],m={},r=f=>({k:"t",s:f.ch.repeat(f.n)}),t=(f,c)=>{let w=[],y=0;for(let o=f;o&&o!==c;o=o.x)w.push(o.k==="d"?r(o):o),y=Math.max(y,o.d??0);return{kids:w,md:y}},g=(f,c,w,y)=>({k:"e",tag:c===2?f==="~"?"del":"strong":"em",kids:w,d:y+1});for(let f=i.x;f;){if(f.k!=="d"){f=f.x;continue}let c=f;if(c.c){let w=c.ch+(c.o?1:0)+c.orig%3;for(;c.n>0;){let y=-1;for(let $=d.length-1,_=Math.min(m[w]??0,d.length);$>=_;$--){let W=d[$];if(!(W.ch!==c.ch||c.ch==="~"&&(W.n<2||c.n<2))&&!((W.c||c.o)&&(W.orig+c.orig)%3===0&&!(W.orig%3===0&&c.orig%3===0))){y=$;break}}if(y<0){m[w]=d.length;break}let o=d[y],{kids:b,md:h}=t(o.x,c);if(h>=ie){m[w]=d.length;break}let U=o.n>=2&&c.n>=2?2:1,I=g(c.ch,U,b,h);d.length=y+1,o.n-=U,c.n-=U,I.p=o,I.x=c,o.x=I,c.p=I,o.n===0&&(o.p.x=I,I.p=o.p,d.pop()),c.n===0&&(I.x=c.x,c.x&&(c.x.p=I));for(let $ in m)m[$]=Math.min(m[$],d.length)}c.n>0&&c.o&&d.push(c)}else d.push(c);f=c.x}if(l){let f=i;for(;f.x;)f=f.x;for(;f.k==="d"&&f!==i;)f=f.p,f.x=null;e:for(let c=d.length-1;c>=0;c--){let w=d[c];for(;w.n>0&&w.x&&!(w.ch==="~"&&w.n<2);){let{kids:y,md:o}=t(w.x,null);if(o>=ie)break e;let b=w.n>=2?2:1,h=g(w.ch,b,y,o);h.p=w,h.x=null,w.x=h,w.n-=b}}}let a=[];for(let f=i.x;f;f=f.x)f.k!=="d"?a.push(f):f.n>0&&a.push(r(f));return Xe(a)}function bt(e,l){e=e.toLowerCase();let i=["<br>","<br/>","<br />","<http:","<https:","<mailto:"];for(let n of l)i.push(`<${n}>`,`</${n}>`);return i.some(n=>n.length>e.length&&n.startsWith(e))}function kt(e,l){return Ze.lastIndex=l,Ze.test(e)}function Le(e,l,i=at){let n=[],d=[],m=e.length,r=0,t=0,g,a=new Map,f={n:8*m+8192},c=y=>{y>r&&n.push({k:"t",s:e.slice(r,y)})};for(;t<m;){let y=e[t];if(y==="\\"){let o=e[t+1];if(o===`
5
+ `){c(t),n.push({k:"br"}),t+=2,r=t;continue}if(o&&ut.test(o)){c(t),n.push({k:"t",s:o}),t+=2,r=t;continue}if(l&&o===void 0){c(t),t++,r=t;continue}t++}else if(y==="`"){let o=t;for(;e[o]==="`";)o++;let b=o-t;if(!g){g=new Map;for(let $ of e.matchAll(/`+/g)){let _=g.get($[0].length);_?_.push($.index):g.set($[0].length,[$.index])}}let h=g.get(b)??[],U=a.get(b)??0;for(;U<h.length&&h[U]<=t;)U++;a.set(b,U);let I=U<h.length?h[U]:l?m:-1;if(I>=0){c(t);let $=e.slice(o,I).replace(/\n/g," ");$.length>1&&$[0]===" "&&$[$.length-1]===" "&&$.trim()&&($=$.slice(1,-1)),n.push({k:"c",s:$}),t=I<m?I+b:m,r=t}else t=o}else if(y==="*"||y==="_"||y==="~"){let o=t;for(;e[o]===y;)o++;let b=o-t;if(y==="~"&&b<2){l&&o===m&&(c(t),r=o),t=o;continue}let h=t?dt(e,t):" ",U=o<m?ht(e,o):" ",I=ze.test(h),$=ze.test(U),_=We.test(h),W=We.test(U),B=!$&&(!W||I||_),L=!I&&(!_||$||W),G=y==="_"?B&&(!L||_):B,Q=y==="_"?L&&(!B||W):L;G||Q?(c(t),n.push({k:"d",ch:y,n:b,orig:b,o:G,c:Q}),r=o):l&&o===m&&(c(t),r=o),t=o}else if(y==="["||y==="!"&&e[t+1]==="[")c(t),d.push(n.length),n.push({k:"[",img:y==="!"}),t+=y==="!"?2:1,r=t;else if(y==="]"){let o=d.pop();if(o===void 0){t++;continue}let b=n[o],h=e[t+1]==="("?pt(e,t+1,f):null;if(h&&h!=="p"){c(t);let U=oe(n.splice(o+1),!1);n.length=o;let I=0;for(let $ of U)I=Math.max(I,$.d??0);if(I>=ie)for(let $ of U)n.push($);else n.push({k:"l",href:h.href,img:b.img,kids:U,d:I+1});t=h.end,r=t}else if(l&&(h==="p"||t+1===m)){c(t);let U=oe(n.splice(o+1),l);n.length=o;for(let I of U)n.push(I);t=m,r=m}else b.k="t",b.s=b.img?"![":"[",t++}else if(y==="<"){ye.lastIndex=t,Be.lastIndex=t;let o;if(ye.test(e))c(t),n.push({k:"br"}),t=ye.lastIndex,r=t;else if(o=Be.exec(e)){c(t);let b=o[1];n.push({k:"a",s:b,href:b.includes(":")?b:"mailto:"+b,ang:!0}),t+=o[0].length,r=t}else i.size&&(Oe.lastIndex=t)>=0&&(o=Oe.exec(e))&&i.has(o[2].toLowerCase())?(c(t),n.push({k:"g",tag:o[2].toLowerCase(),o:!o[1],s:o[0]}),t+=o[0].length,r=t):l&&(m-t<=9&&bt(e.slice(t),i)||kt(e,t))?(c(t),t=m,r=m):t++}else if(y===`
6
+ `){if(e[t-1]===" "&&e[t-2]===" "){let o=t;for(;o>r&&e[o-1]===" ";)o--;c(o),n.push({k:"br"}),r=t+1}t++}else if((y==="h"||y==="H"||y==="w"||y==="W")&&(t===0||!ft.test(e[t-1]))){Fe.lastIndex=t;let o=Fe.exec(e),b=o?gt(o[0]):"";b.replace(/^(?:https?:\/\/|www\.)/i,"")?(c(t),n.push({k:"a",s:b,href:/^www\./i.test(b)?"https://"+b:b}),t+=b.length,r=t):t++}else if(y==="@"){let o=/[A-Za-z0-9._+-]+$/.exec(e.slice(Math.max(r,t-64),t));qe.lastIndex=t+1;let b=qe.exec(e);if(o&&b){let h=b[0].replace(/[-_.]+$/,"");c(t-o[0].length),n.push({k:"a",s:o[0]+"@"+h,href:"mailto:"+o[0]+"@"+h}),t+=1+h.length,r=t}else t++}else t++}c(m);let w=[];for(let y of n)y.k!=="["?w.push(y):l||w.push({k:"t",s:y.img?"![":"["});return oe(w,l)}var xt=/[\\\u0000-\u0020\u007f-\u00a0\u00ad\u061c\u180e\u2000-\u200f\u2028-\u202f\u205f-\u206f\u3000\ufeff]/,yt=/^([a-z][a-z0-9+.-]*):/i;function Ee(e,l,i){if(!e||xt.test(e))return null;let n=yt.exec(e);if(n){let d=n[1].toLowerCase()+":";if(!l.includes(d)||e.length===n[0].length||/^(?:javascript|data|vbscript):$/.test(d)||d[0]==="h"&&!/^https?:\/\/[^/?#]/i.test(e))return null;try{new URL(e)}catch{return null}return e}return e[0]==="/"&&e[1]!=="/"&&i(e)?e:null}var Qe=12;function Nt(e,l={}){if(!e||typeof e.addEventListener!="function")throw new TypeError("limmat: container must be an element");e.replaceChildren();let i=l,n=(i.allowedProtocols??["https","http","mailto"]).map(s=>`${s}`.toLowerCase().replace(/:?$/,":")),d=i.isInternalPath?s=>{try{return!!i.isInternalPath(s)}catch{return!1}}:()=>!0,m=s=>{try{let u=new URL(s);return u.protocol==="https:"||u.protocol==="http:"?u.origin:""}catch{return""}},r=n.filter(s=>s==="https:"||s==="http:"),t=Array.isArray(i.images)?new Set(i.images.map(s=>m(`${s}`)).filter(Boolean)):null,g=s=>{if(i.images===!1)return null;let u=Ee(s,r,d);return u&&(!t||u[0]==="/"||t.has(m(u)))?u:null},a=i.externalLinksNewTab!==!1,f=new Set(i.html===!1?[]:Array.isArray(i.html)?i.html.map(s=>`${s}`.toLowerCase()).filter(s=>re.includes(s)):re),c=i.html===void 0||i.html===!0||Array.isArray(i.html)&&i.html.some(s=>`${s}`.toLowerCase()==="details"),w=Number.isFinite(i.throttleMs)?i.throttleMs:50,y=i.classPrefix??"limmat",o=i.labels??{},b={copy:o.copy??"Copy",copied:o.copied??"Copied",table:o.table??"Table",done:o.done??"Completed",todo:o.todo??"Not completed"},h=s=>`${y}-${s}`,U=new Set,I=new WeakSet,$="",_="",W=!1,B=!1,L=0,G,Q=-1/0,v=(s,u,p)=>{let E=document.createElement(s);return u&&(E.className=u),p&&(E.textContent=p),E},Ae=s=>s.map(u=>u.k==="t"||u.k==="c"||u.k==="a"?u.s:u.k==="br"?" ":Ae(u.kids)).join("");function J(s,u,p){let E=[{nodes:Le(u,p,f),i:0,el:s,il:!1}];for(;E.length;){let A=E[E.length-1];if(A.i>=A.nodes.length){E.pop();continue}let T=A.nodes[A.i++];if(T.k==="t")A.el.append(T.s);else if(T.k==="c")A.el.append(v("code",h("inline-code"),T.s));else if(T.k==="br")A.el.append(v("br"));else if(T.k==="e"){let P=v(T.tag,T.tag==="kbd"?h("kbd"):void 0);A.el.append(P),E.push({nodes:T.kids,i:0,el:P,il:A.il})}else{let P=T.k==="l"&&T.img,k=T.k==="l"&&P?g(T.href):null;if(T.k==="l"&&k){let M=v("img",h("image"));for(let[H,N]of[["alt",Ae(T.kids)],["loading","lazy"],["decoding","async"],["referrerpolicy","no-referrer"],["src",k]])M.setAttribute(H,N);A.el.append(M);continue}let C=P?null:Ee(T.href,n,d);if(!C||A.il)T.k==="a"?A.el.append(T.ang&&!C?`<${T.s}>`:T.s):E.push({nodes:T.kids,i:0,el:A.el,il:!0});else{let M=v("a",h("link"));M.setAttribute("href",C),a&&/^https?:/i.test(C)&&(M.setAttribute("target","_blank"),M.setAttribute("rel","noopener noreferrer")),A.el.append(M),T.k==="a"?M.append(T.s):E.push({nodes:T.kids,i:0,el:M,il:!0})}}}}function ce(s,u,p){if(i.highlight)try{let E=i.highlight(s,u,p);E&&typeof E.catch=="function"&&E.catch(()=>{})}catch{}}let we=(s,u)=>s.slice(Math.min(ne(s),u)),ae=s=>s.map(u=>u.trimStart()).join(`
7
+ `).trimEnd();function Te(s,u){return u.slice(s.a+1,s.closed?s.e-1:s.e).map(p=>we(p,s.ind)).join(`
8
+ `)}function ue(s,u,p,E,A,T,P=!1){switch(s.k){case"p":{let k=v("p");return J(k,ae(u.slice(s.a,s.e)),p),{n:k}}case"h":{let k=v("h"+s.lv);return J(k,Y(u[s.a])[1],p),{n:k}}case"hr":return{n:v("hr")};case"f":{let k=s.lang,C=Te(s,u),M=v("div",h("code")),H=v("div",h("code-head"));if(k){let K=v("span",h("lang"),k);K.setAttribute("aria-hidden","true"),H.append(K)}let N=v("button",h("copy"),b.copy);N.setAttribute("type","button"),N.setAttribute("aria-label",`${b.copy} ${k||"code"}`);let S=v("span",h("status"));S.setAttribute("role","status"),H.append(N,S);let D=v("pre");D.setAttribute("tabindex","0");let z=v("code",/^[\w+#-]{1,20}$/.test(k)?h("lang-"+k.toLowerCase()):"");return z.append(document.createTextNode(C)),D.append(z),M.append(H,D),E>0?T==null||T.push([z,C,k]):(s.closed||A)&&ce(z,C,k),{n:M,code:z}}case"q":{let k=v("blockquote");return fe(u.slice(s.a,s.e).map(C=>C.replace(/^ {0,3}> ?/,"")),k,E+1,p,!1,T,P),{n:k}}case"d":{let k=v("details",h("details"));if((s.open||!s.closed&&!p)&&(k.setAttribute("open",""),I.add(k)),s.sum!==null){let C=v("summary",h("summary"));J(C,s.sum,!1),k.append(C)}return fe(u.slice(s.bs,s.closed?s.e-1:s.e),k,E+1,p&&!s.closed,!1,T,P),{n:k}}case"li":{let C=[V.exec(u[s.a])[4]??"",...u.slice(s.a+1,s.e).map(N=>we(N,s.off))],M=v("li"),H=/^\[([ xX])\](?:[ \t]+|$)/.exec(C[0]);if(H){M.className=h("task");let N=v("input");N.type="checkbox",N.disabled=!0,N.defaultChecked=H[1]!==" ",N.setAttribute("aria-label",H[1]===" "?b.todo:b.done),M.append(N),C[0]=C[0].slice(H[0].length)}return fe(C,M,E+1,p,!0,T,P),{n:M}}case"th":{let k=v("div",h("table-wrap"));k.setAttribute("tabindex","0"),k.setAttribute("role","group"),k.setAttribute("aria-label",b.table);let C=v("table"),M=v("tr");Z(u[s.a]).forEach((S,D)=>{let z=v("th");s.al[D]&&(z.style.textAlign=s.al[D]),J(z,S,!!s.pend),M.append(z)});let H=v("thead"),N=v("tbody");return H.append(M),C.append(H,N),k.append(C),{n:k,body:N}}case"tr":{let k=v("tr"),C=Z(u[s.a]);return s.al.forEach((M,H)=>{let N=v("td");M&&(N.style.textAlign=M),J(N,C[H]??"",p),k.append(N)}),{n:k}}}}function Ce(s,u,p,E){if(p.k==="li"){if(u&&u.k==="l"&&u.ord===p.ord)return u.el.append(E.n),{ctx:u};let A=v(p.ord?"ol":"ul",h("list"));return p.ord&&p.num!==1&&A.setAttribute("start",String(p.num)),A.append(E.n),s.append(A),{ctx:{k:"l",el:A,ord:p.ord},made:A}}return p.k==="tr"?(u.el.append(E.n),{ctx:u}):(s.append(E.n),{ctx:p.k==="th"?{k:"t",el:E.body,al:p.al}:null})}function fe(s,u,p,E,A,T,P=!1){if(p>Qe){let M=v("p");J(M,ae(s),E),u.append(M);return}let k=null,C=xe(s,null,P,!P,c?E?1:2:0,P);C.forEach((M,H)=>{let N=E&&H===C.length-1;if(A&&H===0&&M.k==="p")return J(u,ae(s.slice(M.a,M.e)),N);k=Ce(u,k,M,ue(M,s,N,p,!0,T,P&&M.b===s.length)).ctx})}function $e(s){for(let[u,p,E]of s.hl??[])ce(u,p,E);s.hl=void 0}let de=()=>({tail:[],fctx:null,fl:0}),Ne=de(),Me=(s,u)=>`${u[s.a]}
9
+ ${s.sum}
10
+ ${s.bs-s.a}`;function he(s,u,p,E,A,T,P){var Re;let k=s.tail,C=xe(p,s.fctx&&s.fctx.k==="t"?s.fctx.al:null,E,A,c?A?2:1:0,E&&!A),M=(x,R,O)=>P?P.push([x,R,O]):ce(x,R,O),H=C.map((x,R)=>{let O=!A&&R===C.length-1,q=p.slice(x.a,x.e).join(`
11
+ `),X=E&&!A&&x.b===p.length&&(x.k==="q"||x.k==="li"||x.k==="d");return x.k==="f"?`f${x.closed?1:0}${q}`:`${x.k}${x.k==="d"&&x.closed?1:""}${O?"*":""}${X?"~":""}${x.k==="th"&&x.pend?"?":""}${q}`}),N=0;for(;N<k.length&&N<C.length&&k[N].key===H[N];)N++;let S=k[N],D=C[N];if(S!=null&&S.open&&S.code&&N<C.length&&D.k==="f"&&S.u.k==="f"&&D.lang===S.u.lang){let x=Te(D,p),R=S.code.firstChild;x.startsWith(R.data)?R.appendData(x.slice(R.data.length)):R.data=x,S.key=H[N],S.u=D,(D.closed||A)&&(S.open=!1,M(S.code,x,D.lang)),N++}else if(S!=null&&S.sub&&N===C.length-1&&D.k==="d"&&!D.closed&&S.u.k==="d"&&Me(D,p)===S.hk){let x=p.slice(D.bs,D.e);S.sub.fl+=he(S.sub,S.node,x.slice(S.sub.fl),E,A,T+1,S.hl),A&&!S.node.hasAttribute("open")&&!I.has(S.node)&&(S.node.setAttribute("open",""),I.add(S.node)),S.key=H[N],S.u=D,N++}let z=N>0?k[N-1].ctx:s.fctx,K=[];for(let x of k.splice(N)){for(let R of x.node.tagName==="DETAILS"?[x.node]:Array.from(x.node.querySelectorAll("details")))K.push(R.open!==I.has(R)?R.open:null);x.node.remove(),(Re=x.made)==null||Re.remove()}for(let x=N;x<C.length;x++){let R=C[x],O=[],q=!A&&x===C.length-1,X,ee;R.k==="d"&&!R.closed&&T<Qe?(X=ue({...R,bs:R.e},p,q,T,A,O),ee=de(),ee.fl+=he(ee,X.n,p.slice(R.bs,R.e),E,A,T+1,O)):X=ue(R,p,q,T,A,O,E&&!A&&R.b===p.length);let ve=Ce(u,z,R,X);z=ve.ctx,k.push({key:H[x],u:R,node:X.n,made:ve.made,ctx:z,code:X.code,open:R.k==="f"&&!R.closed&&!A,hl:O,sub:ee,hk:R.k==="d"?Me(R,p):void 0})}if(K.some(x=>x!==null)){let x=0;for(let R of k.slice(N))for(let O of R.node.tagName==="DETAILS"?[R.node]:Array.from(R.node.querySelectorAll("details"))){let q=K[x++];q!=null&&(O.open=q)}}if(A)for(let x of k)x.open&&x.code&&x.u.k==="f"&&(x.open=!1,M(x.code,x.code.textContent??"",x.u.lang)),P?P.push(...x.hl??[]):$e(x);let F=Math.max(C.length-1,0);if(E&&F>0&&C[F].a===p.length-1&&F--,!A&&F>0){s.fctx=k[F-1].ctx,s.fctx&&s.fctx.k==="t"&&C[F-1].b>C[F-1].e&&(s.fctx=null);for(let x of k.splice(0,F))P?P.push(...x.hl??[]):$e(x);return C[F-1].b}return 0}function j(s){let u=!$.endsWith(`
12
+ `),p=$.split(`
13
+ `);u||p.pop();let E=he(Ne,e,p,u,s,0,null),A=0;for(let T=0;T<E;T++)A+=p[T].length+1;$=$.slice(A)}function Je(){if(w<=0)return j(!1);if(G!==void 0)return;let s=Q+w-Date.now();s<=0?(Q=Date.now(),j(!1)):G=setTimeout(()=>{G=void 0,Q=Date.now(),j(!1)},s)}let pe=()=>{clearTimeout(G),G=void 0},Ie=()=>{U.forEach(clearTimeout),U.clear()};async function Ke(s){var u;try{return await navigator.clipboard.writeText(s),!0}catch{let p=v("textarea");p.value=s,p.style.cssText="position:fixed;opacity:0";let E=document.activeElement;e.append(p),p.select();let A=!1;try{A=document.execCommand("copy")}catch{}return p.remove(),(u=E==null?void 0:E.focus)==null||u.call(E),A}}function Se(s){var p,E,A,T,P;let u=(E=(p=s.target)==null?void 0:p.closest)==null?void 0:E.call(p,"a,button");if(!(!u||!e.contains(u))){if(u.tagName==="A")((A=i.onLinkClick)==null?void 0:A.call(i,u.getAttribute("href")??"",s))===!0&&s.preventDefault();else if(u.classList.contains(h("copy"))){let k=(T=u.closest("."+h("code")))==null?void 0:T.querySelector("code"),C=(P=u.parentElement)==null?void 0:P.querySelector("."+h("status")),M=L;Ke((k==null?void 0:k.textContent)??"").then(H=>{if(!H||B||M!==L)return;u.textContent=b.copied,C&&(C.textContent=b.copied);let N=setTimeout(()=>{U.delete(N),u.textContent=b.copy,C&&(C.textContent="")},2e3);U.add(N)})}}}return e.addEventListener("click",Se),{write(s){if(B||W||!s)return;s=_+s,_="";let u=s.charCodeAt(s.length-1);(u===13||u>=55296&&u<56320)&&(_=s[s.length-1],s=s.slice(0,-1)),s=s.replace(/\r\n?/g,`
14
+ `),s&&($+=s,Je())},end(){B||W||(W=!0,pe(),_&&($+=_==="\r"?`
15
+ `:_),_="",j(!0))},reset(){B||(pe(),Ie(),L++,e.replaceChildren(),$="",_="",Ne=de(),W=!1,Q=-1/0)},destroy(){B||(pe(),Ie(),B=!0,e.removeEventListener("click",Se))}}}export{Nt as createRenderer};
package/dist/style.css ADDED
@@ -0,0 +1,214 @@
1
+ /* Optional styles for limmat. Override the variables, or ignore this file and style the classes yourself.
2
+ It follows prefers-color-scheme and supports forced colors. The variables are --limmat-link, --limmat-border,
3
+ --limmat-code-bg, --limmat-radius, --limmat-font-mono, --limmat-muted, and --limmat-focus.
4
+ The generated structure (classes may be added, never removed or renamed):
5
+ p, h1-h6, hr, blockquote, ul.limmat-list, ol.limmat-list, li, li.limmat-task (task items)
6
+ div.limmat-code
7
+ div.limmat-code-head > span.limmat-lang[aria-hidden], button.limmat-copy, span.limmat-status[role=status]
8
+ pre[tabindex=0] > code.limmat-lang-ts
9
+ div.limmat-table-wrap[tabindex=0][role=group] > table
10
+ a.limmat-link
11
+ details.limmat-details[open] > summary.limmat-summary, then the content blocks
12
+ kbd.limmat-kbd, b, strong, i, em, u, s, del, ins, mark, small, sub, sup (from the HTML tags, no attributes)
13
+ img.limmat-image[loading=lazy][decoding=async][referrerpolicy=no-referrer]
14
+ code.limmat-inline-code (inline code)
15
+ */
16
+ :root,
17
+ :host {
18
+ --limmat-code-bg: rgba(128, 128, 128, 0.1);
19
+ --limmat-border: rgba(128, 128, 128, 0.4);
20
+ --limmat-muted: #595959;
21
+ --limmat-link: #1d4ed8;
22
+ --limmat-radius: 0.5rem;
23
+ --limmat-font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
24
+ --limmat-focus: #2563eb;
25
+ }
26
+ @supports (color: color-mix(in srgb, red, blue)) {
27
+ :root,
28
+ :host {
29
+ --limmat-code-bg: color-mix(in srgb, currentColor 7%, transparent);
30
+ --limmat-border: color-mix(in srgb, currentColor 22%, transparent);
31
+ --limmat-muted: color-mix(in srgb, currentColor 65%, transparent);
32
+ }
33
+ }
34
+ @media (prefers-color-scheme: dark) {
35
+ :root,
36
+ :host {
37
+ --limmat-link: #93c5fd;
38
+ --limmat-focus: #93c5fd;
39
+ }
40
+ }
41
+ @supports not (color: color-mix(in srgb, red, blue)) {
42
+ @media (prefers-color-scheme: dark) {
43
+ :root,
44
+ :host {
45
+ --limmat-muted: #a3a3a3;
46
+ }
47
+ }
48
+ }
49
+ .limmat-link {
50
+ overflow-wrap: anywhere;
51
+ color: var(--limmat-link);
52
+ text-decoration: underline;
53
+ text-underline-offset: 0.15em;
54
+ }
55
+ .limmat-kbd {
56
+ padding: 0.1em 0.4em;
57
+ border: 1px solid var(--limmat-border);
58
+ border-bottom-width: 2px;
59
+ border-radius: 0.35em;
60
+ background: var(--limmat-code-bg);
61
+ font-family: var(--limmat-font-mono);
62
+ font-size: 0.875em;
63
+ white-space: nowrap;
64
+ }
65
+ .limmat-details {
66
+ margin: 0.5em 0;
67
+ padding: 0.35em 0.75em;
68
+ border: 1px solid var(--limmat-border);
69
+ border-radius: var(--limmat-radius);
70
+ }
71
+ .limmat-summary {
72
+ cursor: pointer;
73
+ font-weight: 600;
74
+ }
75
+ .limmat-details[open] > .limmat-summary {
76
+ margin-bottom: 0.4em;
77
+ }
78
+ .limmat-image {
79
+ max-width: 100%;
80
+ height: auto;
81
+ }
82
+ .limmat-inline-code {
83
+ padding: 0.12em 0.4em;
84
+ border-radius: 0.35em;
85
+ background: var(--limmat-code-bg);
86
+ font-family: var(--limmat-font-mono);
87
+ font-size: 0.875em;
88
+ overflow-wrap: anywhere;
89
+ }
90
+ .limmat-code {
91
+ margin: 0.75em 0;
92
+ border: 1px solid var(--limmat-border);
93
+ border-radius: var(--limmat-radius);
94
+ background: var(--limmat-code-bg);
95
+ overflow: hidden;
96
+ }
97
+ .limmat-code-head {
98
+ display: flex;
99
+ align-items: center;
100
+ gap: 0.5rem;
101
+ padding: 0.25rem 0.5rem;
102
+ border-bottom: 1px solid var(--limmat-border);
103
+ font-size: 0.8em;
104
+ color: var(--limmat-muted);
105
+ }
106
+ .limmat-lang {
107
+ margin-inline-end: auto;
108
+ font-family: var(--limmat-font-mono);
109
+ }
110
+ .limmat-code-head > .limmat-copy:first-child {
111
+ margin-inline-start: auto;
112
+ }
113
+ .limmat-copy {
114
+ font: inherit;
115
+ color: inherit;
116
+ background: none;
117
+ border: 1px solid var(--limmat-border);
118
+ border-radius: 0.3rem;
119
+ padding: 0.1rem 0.5rem;
120
+ cursor: pointer;
121
+ }
122
+ .limmat-copy:hover {
123
+ background: var(--limmat-code-bg);
124
+ }
125
+ .limmat-status {
126
+ position: absolute;
127
+ width: 1px;
128
+ height: 1px;
129
+ overflow: hidden;
130
+ clip-path: inset(50%);
131
+ white-space: nowrap;
132
+ }
133
+ .limmat-code pre {
134
+ direction: ltr;
135
+ text-align: left;
136
+ margin: 0;
137
+ padding: 0.75rem;
138
+ overflow-x: auto;
139
+ font-family: var(--limmat-font-mono);
140
+ font-size: 0.9em;
141
+ line-height: 1.5;
142
+ }
143
+ .limmat-code code {
144
+ font: inherit;
145
+ }
146
+ /* A @speed-highlight/core theme styles <code> as a standalone block. Keep limmat's frame and let the theme set colors only. */
147
+ .limmat-code code[class*="shj-lang-"] {
148
+ margin: 0;
149
+ padding: 0;
150
+ border: 0;
151
+ border-radius: 0;
152
+ background: none;
153
+ max-width: none;
154
+ font: inherit;
155
+ }
156
+ .limmat-table-wrap {
157
+ margin: 0.75em 0;
158
+ overflow-x: auto;
159
+ }
160
+ .limmat-table-wrap table {
161
+ border-collapse: collapse;
162
+ min-width: 100%;
163
+ }
164
+ .limmat-table-wrap th,
165
+ .limmat-table-wrap td {
166
+ border: 1px solid var(--limmat-border);
167
+ padding: 0.3rem 0.6rem;
168
+ text-align: start;
169
+ }
170
+ .limmat-table-wrap th {
171
+ background: var(--limmat-code-bg);
172
+ }
173
+ .limmat-list {
174
+ padding-inline-start: 1.5em;
175
+ }
176
+ .limmat-task {
177
+ list-style: none;
178
+ margin-inline-start: -1.25em;
179
+ }
180
+ .limmat-task > input[type="checkbox"]:first-child {
181
+ margin-inline-end: 0.5em;
182
+ }
183
+ .limmat-code pre:focus-visible,
184
+ .limmat-table-wrap:focus-visible,
185
+ .limmat-copy:focus-visible,
186
+ .limmat-summary:focus-visible,
187
+ .limmat-link:focus-visible {
188
+ outline: 2px solid var(--limmat-focus);
189
+ outline-offset: 2px;
190
+ }
191
+ @media (forced-colors: active) {
192
+ .limmat-code,
193
+ .limmat-code-head,
194
+ .limmat-copy,
195
+ .limmat-table-wrap th,
196
+ .limmat-table-wrap td {
197
+ border-color: CanvasText;
198
+ }
199
+ .limmat-inline-code {
200
+ border: 1px solid CanvasText;
201
+ }
202
+ .limmat-kbd,
203
+ .limmat-details {
204
+ border-color: CanvasText;
205
+ }
206
+ .limmat-link {
207
+ color: LinkText;
208
+ }
209
+ }
210
+ @media (prefers-reduced-motion: no-preference) {
211
+ .limmat-copy {
212
+ transition: background-color 0.15s;
213
+ }
214
+ }
package/package.json CHANGED
@@ -1,6 +1,93 @@
1
1
  {
2
2
  "name": "limmat",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "A tiny, safe markdown renderer for streaming LLM output. Builds DOM nodes as text arrives, never HTML strings, with no framework and no dependencies.",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "author": "Daan Rosendal",
8
+ "sideEffects": [
9
+ "*.css"
10
+ ],
11
+ "main": "./dist/index.js",
12
+ "module": "./dist/index.js",
13
+ "types": "./dist/index.d.ts",
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "exports": {
18
+ ".": {
19
+ "types": "./dist/index.d.ts",
20
+ "default": "./dist/index.js"
21
+ },
22
+ "./highlight": {
23
+ "types": "./dist/highlight.d.ts",
24
+ "default": "./dist/highlight.js"
25
+ },
26
+ "./style.css": "./dist/style.css",
27
+ "./limmat.min.js": "./dist/limmat.min.js",
28
+ "./package.json": "./package.json"
29
+ },
30
+ "peerDependencies": {
31
+ "@speed-highlight/core": "^2.1.0"
32
+ },
33
+ "peerDependenciesMeta": {
34
+ "@speed-highlight/core": {
35
+ "optional": true
36
+ }
37
+ },
38
+ "scripts": {
39
+ "build": "node scripts/build.mjs",
40
+ "typecheck": "tsc --noEmit",
41
+ "test": "vitest run",
42
+ "size": "node scripts/size.mjs",
43
+ "lint": "biome check .",
44
+ "format": "biome format --write .",
45
+ "test:browser": "playwright test",
46
+ "check": "npm run typecheck && npm run lint && npm run check:style && npm test && npm run build && npm run build:demo && npm run check:package && npm run check:support && npm run size && npm run test:browser",
47
+ "test:browser:chromium": "playwright test --project=chromium",
48
+ "check:package": "node scripts/check-package.mjs",
49
+ "support": "node scripts/gen-support.mjs",
50
+ "check:support": "node scripts/gen-support.mjs --check",
51
+ "check:style": "node scripts/check-style.mjs",
52
+ "prepublishOnly": "npm run build && npm run check:package",
53
+ "build:demo": "node scripts/build-demo.mjs",
54
+ "record": "node scripts/record-demo.mjs",
55
+ "deploy:demo": "npm run build && npm run build:demo && npm ci --ignore-scripts --prefix deploy && WRANGLER_SEND_METRICS=false deploy/node_modules/.bin/wrangler deploy",
56
+ "demo": "npm run build && npm run build:demo && node scripts/serve-demo.mjs"
57
+ },
58
+ "devDependencies": {
59
+ "@axe-core/playwright": "^4.14.0",
60
+ "@biomejs/biome": "2.6.8",
61
+ "@playwright/test": "^1.65.1",
62
+ "@speed-highlight/core": "^2.1.0",
63
+ "@types/node": "^26.6.6",
64
+ "esbuild": "^0.28.2",
65
+ "jsdom": "^31.0.1",
66
+ "typescript": "^7.0.2",
67
+ "vitest": "^5.1.1"
68
+ },
69
+ "repository": {
70
+ "type": "git",
71
+ "url": "git+https://github.com/DaanRosendal/limmat.git"
72
+ },
73
+ "homepage": "https://github.com/DaanRosendal/limmat#readme",
74
+ "bugs": {
75
+ "url": "https://github.com/DaanRosendal/limmat/issues"
76
+ },
77
+ "keywords": [
78
+ "markdown",
79
+ "streaming",
80
+ "llm",
81
+ "chat",
82
+ "dom",
83
+ "xss",
84
+ "safe",
85
+ "markdown-renderer",
86
+ "streaming-markdown",
87
+ "ai",
88
+ "chatgpt",
89
+ "typescript",
90
+ "sanitize",
91
+ "zero-dependency"
92
+ ]
93
+ }