@livx.cc/bare-v3 0.1.0-alpha.159 → 0.1.0-alpha.160

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.
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.1.0-alpha.159",
2
+ "version": "0.1.0-alpha.160",
3
3
  "cssSha256": "87ac01d3a41ddd908697ea8c41eb589c54125e9130c4522aaa5b2d2417493c07",
4
4
  "classes": [
5
5
  "b3-accordion",
@@ -112,8 +112,11 @@ export declare class MarkdownStream {
112
112
  /**
113
113
  * Keep a scroller pinned to the bottom while content grows, unless the reader scrolled up;
114
114
  * scrolling back near the bottom re-pins. `stick(true)` forces a pin (e.g. on send).
115
+ * Inner scrollers (`inner`, default: an open b3-message-disclosure's body — streaming Thinking) follow
116
+ * their own tail the same way: pinned until the reader scrolls one up, re-pinned near its bottom.
115
117
  */
116
- export declare function stickToBottom(scroller?: Element, { threshold }?: {
118
+ export declare function stickToBottom(scroller?: Element, { threshold, inner }?: {
119
+ inner?: string | undefined;
117
120
  threshold?: number | undefined;
118
121
  }): {
119
122
  readonly pinned: boolean;
@@ -1,12 +1,12 @@
1
- var q=Symbol.for("bare-v3.styles");function O(e,n,a){if(!e?.head||e.getElementById(n))return;let t=e[q]??=new Set;if(t.has(n))return;let r=e.defaultView;if(r&&"adoptedStyleSheets"in e&&"replaceSync"in r.CSSStyleSheet.prototype){let i=new r.CSSStyleSheet;i.replaceSync(a),e.adoptedStyleSheets=[...e.adoptedStyleSheets,i],t.add(n);return}let s=e.createElement("style");s.id=n,s.textContent=a,e.head.append(s)}var b=(e)=>String(e).replace(/[&<>"]/g,(n)=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;"})[n]),P=(e)=>Object.fromEntries([...(e||"").matchAll(/(\w+)=(?:"([^"]*)"|(\S+))/g)].map((n)=>[n[1],n[2]??n[3]])),B=(e)=>/^[-+$€£]?[\d,.]+%?$/.test(String(e).trim()),R=(e)=>e?` data-b3-tone="${b(e)}"`:"",T={callout(e,n){let a=e.attrs.title?`<strong>${b(e.attrs.title)}</strong>`:"";return`<div class="b3-alert"${R(e.attrs.tone)}><div>${a}${n.parse(e.tokens)}</div></div>`},stats(e,n){let a=n?.inline??b;return`<div class="b3-md-stats">${e.body.split(`
2
- `).filter((r)=>r.trim()).map((r)=>{let[s="",i,o=""]=r.replace(/^\s*\|/,"").replace(/\|\s*$/,"").split("|").map((c)=>c.trim()),l=/^[↑+]/.test(o)?"success":/^[↓-]/.test(o)?"danger":"";return`<div class="b3-stat b3-surface"><span class="b3-label">${a(s)}</span><strong class="b3-stat-value">${i?a(i.replace(/^\*\*(.*)\*\*$/,"$1")):"…"}</strong>${o?`<span class="b3-badge"${R(l)}>${a(o)}</span>`:""}</div>`}).join("")}</div>`}},S={chart(e){let n=e.split(`
3
- `).map((t)=>t.split(":")).filter((t)=>t.length>1&&!isNaN(parseFloat(t[1]))),a=Math.max(...n.map((t)=>parseFloat(t[1])),1);return`<figure class="b3-md-bars b3-surface">${n.map(([t="",r=""])=>`<div class="b3-md-bar"><span>${b(t.trim())}</span><i style="inline-size:${Math.max(parseFloat(r),0)/a*100}%"></i><b>${b(r.trim())}</b></div>`).join("")}</figure>`}},U=(e,n)=>{let a=e.trim();if(!/^[[{]/.test(a))return S.chart(e,n);let t;try{t=JSON.parse(a)}catch{return(a.match(/[[{]/g)?.length??0)>(a.match(/[\]}]/g)?.length??0)?'<figure class="b3-md-chart b3-surface b3-md-pending"><div class="b3-skeleton"></div></figure>':j(e,"json")}let r=_(t);return r?Y(r):j(e,"json")};U.doc='```chart fence with JSON — `{"type":"bar|line|pie","title":"…","data":[{"label":"Jan","sales":120,"costs":80}]}` (numbers, not strings; every numeric field is a series; type is optional) — for trends over time (line), comparing groups/series (bar) or shares of a whole (pie). For a few single values, one `Label: number` per line gives simple bars.';var M=(e)=>typeof e==="number"&&Number.isFinite(e);function _(e){let n=Array.isArray(e)?{data:e}:e&&typeof e==="object"?e:null;if(!n)return null;let a=n.data??n.rows,t=n.series??n.values;if(!a&&t&&typeof t==="object"&&!Array.isArray(t)){let c=Object.keys(t);a=[...new Set(c.flatMap((m)=>Object.keys(t[m]||{})))].map((m)=>({label:m,...Object.fromEntries(c.map((g)=>[g,Number(t[g]?.[m]??0)]))}))}if(!Array.isArray(a)||!a.length||!a.every((c)=>c&&typeof c==="object"&&!Array.isArray(c)))return null;let r=[...new Set(a.flatMap((c)=>Object.keys(c)))],s=typeof n.x==="string"?n.x:r.find((c)=>a.some((d)=>d[c]!=null&&!M(d[c])))??"",i=n.y?[n.y].flat().map(String):r.filter((c)=>c!==s&&a.some((d)=>M(d[c])));if(!i.length)return null;let o=a.some((c)=>/^\d{4}-\d{2}/.test(String(c[s]??""))),l=["bar","line","pie"].includes(n.type)?n.type:o||a.length>12?"line":"bar";return{type:l,title:String(n.title??""),x:s,ys:l==="pie"?i.slice(0,1):i.slice(0,8),rows:a.slice(0,500)}}var A=(e)=>{try{return new Intl.NumberFormat(void 0,{notation:"compact",maximumFractionDigits:1}).format(e)}catch{return String(e)}};function Y({type:e,title:n,x:a,ys:t,rows:r}){let s=(p,u)=>M(p[u])?p[u]:0,i=(p,u)=>String(a?p[a]??"":u+1),o=(p,u,h)=>`<title>${b(i(p,u))} · ${b(h)}: ${b(p[h]??"")}</title>`,l=n?`<figcaption>${b(n)}</figcaption>`:"",c=(p)=>`<div class="b3-md-legend">${p.map((u,h)=>`<span><i class="b3-md-c${h%8}"></i>${b(u)}</span>`).join("")}</div>`;if(e==="pie"){let p=t[0],u=r.map((k)=>Math.max(s(k,p),0)),h=u.reduce((k,y)=>k+y,0)||1,f=0,E=r.map((k,y)=>{let x=f+u[y]/h*Math.PI*2,C=(z)=>`${(16+15*Math.sin(z)).toFixed(3)} ${(16-15*Math.cos(z)).toFixed(3)}`,N=u[y]>=h?"M16 1a15 15 0 1 1 0 30a15 15 0 1 1 0-30Z":`M16 16L${C(f)}A15 15 0 ${x-f>Math.PI?1:0} 1 ${C(x)}Z`;return f=x,`<path class="b3-md-c${y%8}" d="${N}">${o(k,y,p)}</path>`});return`<figure class="b3-md-chart b3-surface">${l}<div class="b3-md-pie"><svg viewBox="0 0 32 32" role="img" aria-label="${b(n||p)}">${E.join("")}</svg>${c(r.map(i))}</div></figure>`}let d=r.flatMap((p)=>t.map((u)=>s(p,u))),m=Math.min(0,...d),g=Math.max(0,...d),H=g-m||1,v=(p)=>(100-(p-m)/H*100).toFixed(2),w=r.length,I=e==="line"?t.map((p,u)=>`<polyline class="b3-md-c${u%8}" vector-effect="non-scaling-stroke" points="${r.map((h,f)=>`${(w>1?f/(w-1)*100:50).toFixed(2)},${v(s(h,p))}`).join(" ")}"><title>${b(p)}</title></polyline>`).join(""):r.map((p,u)=>t.map((h,f)=>{let E=100/w*0.8/t.length,k=100/w*(u+0.1)+E*f,y=s(p,h),x=Math.min(+v(y),+v(0));return`<rect class="b3-md-c${f%8}" x="${k.toFixed(2)}" y="${x.toFixed(2)}" width="${E.toFixed(2)}" height="${Math.max(Math.abs(+v(y)-+v(0)),0.4).toFixed(2)}">${o(p,u,h)}</rect>`}).join("")).join(""),D=w>2?[0,Math.floor((w-1)/2),w-1]:[...Array(w).keys()];return`<figure class="b3-md-chart b3-surface">${l}<div class="b3-md-plot"><div class="b3-md-y"><span>${A(g)}</span><span>${A(m)}</span></div><svg viewBox="0 0 100 100" preserveAspectRatio="none" role="img" aria-label="${b(n||t.join(", "))}">${I}</svg><div class="b3-md-x">${D.map((p)=>`<span>${b(i(r[p],p))}</span>`).join("")}</div></div>${t.length>1?c(t):""}</figure>`}T.callout.doc='`:::callout{tone=info|success|warning|danger title="Short title"}` newline, markdown body, newline `:::` — a highlighted note, tip, warning or recommendation.';T.stats.doc="`:::stats` newline, one card per line `Label | Value | note`, newline `:::` — headline numbers; a note starting with ↑ or + shows as good, ↓ or - as bad.";S.chart.doc="```chart fence, one bar per line `Label: number` (plain number, no units) — a horizontal bar chart for comparing a few values.";function X(e={}){let n={...T,...e.directives,...S,...e.fences},a=Object.entries(e.tones??new L().tones).reduce((t,[r,s])=>((t[s]??=[]).push(r),t),{});return["Your replies are Markdown rendered live into UI components. Use GitHub-flavoured Markdown (headings, **bold**, lists, links, `inline code`, fenced code with a language, > quotes) plus:",`- Tables: GFM pipe tables with a header row and a \`| --- |\` delimiter row. Never add a Status column the data does not already have. Only when a row really has one of these states (e.g. an invoice that is paid), write the plain word alone in the cell and it is shown as a coloured badge automatically (no images, emoji or badge URLs): ${Object.entries(a).map(([t,r])=>`${r.join(", ")} (${t})`).join("; ")}. Numeric columns align right.`,"- Task lists: `- [x] done` and `- [ ] to do`.",...Object.values(n).filter((t)=>t?.doc).map((t)=>`- ${t.doc}`),"Use a component only when it makes the answer clearer; plain prose is fine. Put every block on its own lines with a blank line around it, always close ::: and ``` blocks, and never write raw HTML."].join(`
4
- `)}var j=(e,n)=>`<div class="b3-md-code"><header><span class="b3-muted">${b(n||"text")}</span><button type="button" class="b3-button" data-b3-emphasis="quiet" data-b3-md-copy>Copy</button></header><pre><code>${b(e)}</code></pre></div>`;function V(e){let n=e,a=n.split(`
5
- `),t=[];while(a.length&&/^\s*\|/.test(a.at(-1)))t.unshift(a.pop());let r=e.endsWith(`
6
- `)?t:t.slice(0,-1),s=!1;if(t.length&&!r.some((c)=>/^\s*\|?\s*:?-{2,}/.test(c)))s=!0,n=a.join(`
7
- `);if(n=n.replace(/(^|\n) {0,3}(`{3}[^\n]*|~{3}[^\n]*|:{3}[^\n]*|`{1,2}|~{1,2}|:{1,2})$/,"$1"),(n.match(/^ {0,3}(`{3}|~{3})/gm)||[]).length%2)return{src:n,pendingTable:s};n=n.replace(/\[([^\]\n]*)\]?\([^)\n]*$/,"$1").replace(/\[([^\]\n]*)$/,"$1").replace(/(\*{1,3}|_{1,3}|~{1,2}|`)$/,"");let i=[...n.matchAll(/^ {0,3}(`{3}|~{3})[^\n]*\n?/gm)].at(-1),o=n.slice(Math.max(n.lastIndexOf(`
1
+ var q=Symbol.for("bare-v3.styles");function F(e,n,a){if(!e?.head||e.getElementById(n))return;let t=e[q]??=new Set;if(t.has(n))return;let i=e.defaultView;if(i&&"adoptedStyleSheets"in e&&"replaceSync"in i.CSSStyleSheet.prototype){let r=new i.CSSStyleSheet;r.replaceSync(a),e.adoptedStyleSheets=[...e.adoptedStyleSheets,r],t.add(n);return}let s=e.createElement("style");s.id=n,s.textContent=a,e.head.append(s)}var u=(e)=>String(e).replace(/[&<>"]/g,(n)=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;"})[n]),P=(e)=>Object.fromEntries([...(e||"").matchAll(/(\w+)=(?:"([^"]*)"|(\S+))/g)].map((n)=>[n[1],n[2]??n[3]])),B=(e)=>/^[-+$€£]?[\d,.]+%?$/.test(String(e).trim()),H=(e)=>e?` data-b3-tone="${u(e)}"`:"",S={callout(e,n){let a=e.attrs.title?`<strong>${u(e.attrs.title)}</strong>`:"";return`<div class="b3-alert"${H(e.attrs.tone)}><div>${a}${n.parse(e.tokens)}</div></div>`},stats(e,n){let a=n?.inline??u;return`<div class="b3-md-stats">${e.body.split(`
2
+ `).filter((i)=>i.trim()).map((i)=>{let[s="",r,o=""]=i.replace(/^\s*\|/,"").replace(/\|\s*$/,"").split("|").map((c)=>c.trim()),l=/^[↑+]/.test(o)?"success":/^[↓-]/.test(o)?"danger":"";return`<div class="b3-stat b3-surface"><span class="b3-label">${a(s)}</span><strong class="b3-stat-value">${r?a(r.replace(/^\*\*(.*)\*\*$/,"$1")):"…"}</strong>${o?`<span class="b3-badge"${H(l)}>${a(o)}</span>`:""}</div>`}).join("")}</div>`}},E={chart(e){let n=e.split(`
3
+ `).map((t)=>t.split(":")).filter((t)=>t.length>1&&!isNaN(parseFloat(t[1]))),a=Math.max(...n.map((t)=>parseFloat(t[1])),1);return`<figure class="b3-md-bars b3-surface">${n.map(([t="",i=""])=>`<div class="b3-md-bar"><span>${u(t.trim())}</span><i style="inline-size:${Math.max(parseFloat(i),0)/a*100}%"></i><b>${u(i.trim())}</b></div>`).join("")}</figure>`}},U=(e,n)=>{let a=e.trim();if(!/^[[{]/.test(a))return E.chart(e,n);let t;try{t=JSON.parse(a)}catch{return(a.match(/[[{]/g)?.length??0)>(a.match(/[\]}]/g)?.length??0)?'<figure class="b3-md-chart b3-surface b3-md-pending"><div class="b3-skeleton"></div></figure>':z(e,"json")}let i=_(t);return i?Y(i):z(e,"json")};U.doc='```chart fence with JSON — `{"type":"bar|line|pie","title":"…","data":[{"label":"Jan","sales":120,"costs":80}]}` (numbers, not strings; every numeric field is a series; type is optional) — for trends over time (line), comparing groups/series (bar) or shares of a whole (pie). For a few single values, one `Label: number` per line gives simple bars.';var C=(e)=>typeof e==="number"&&Number.isFinite(e);function _(e){let n=Array.isArray(e)?{data:e}:e&&typeof e==="object"?e:null;if(!n)return null;let a=n.data??n.rows,t=n.series??n.values;if(!a&&t&&typeof t==="object"&&!Array.isArray(t)){let c=Object.keys(t);a=[...new Set(c.flatMap((p)=>Object.keys(t[p]||{})))].map((p)=>({label:p,...Object.fromEntries(c.map((f)=>[f,Number(t[f]?.[p]??0)]))}))}if(!Array.isArray(a)||!a.length||!a.every((c)=>c&&typeof c==="object"&&!Array.isArray(c)))return null;let i=[...new Set(a.flatMap((c)=>Object.keys(c)))],s=typeof n.x==="string"?n.x:i.find((c)=>a.some((h)=>h[c]!=null&&!C(h[c])))??"",r=n.y?[n.y].flat().map(String):i.filter((c)=>c!==s&&a.some((h)=>C(h[c])));if(!r.length)return null;let o=a.some((c)=>/^\d{4}-\d{2}/.test(String(c[s]??""))),l=["bar","line","pie"].includes(n.type)?n.type:o||a.length>12?"line":"bar";return{type:l,title:String(n.title??""),x:s,ys:l==="pie"?r.slice(0,1):r.slice(0,8),rows:a.slice(0,500)}}var I=(e)=>{try{return new Intl.NumberFormat(void 0,{notation:"compact",maximumFractionDigits:1}).format(e)}catch{return String(e)}};function Y({type:e,title:n,x:a,ys:t,rows:i}){let s=(m,b)=>C(m[b])?m[b]:0,r=(m,b)=>String(a?m[a]??"":b+1),o=(m,b,w)=>`<title>${u(r(m,b))} · ${u(w)}: ${u(m[w]??"")}</title>`,l=n?`<figcaption>${u(n)}</figcaption>`:"",c=(m)=>`<div class="b3-md-legend">${m.map((b,w)=>`<span><i class="b3-md-c${w%8}"></i>${u(b)}</span>`).join("")}</div>`;if(e==="pie"){let m=t[0],b=i.map((x)=>Math.max(s(x,m),0)),w=b.reduce((x,v)=>x+v,0)||1,k=0,L=i.map((x,v)=>{let T=k+b[v]/w*Math.PI*2,R=(A)=>`${(16+15*Math.sin(A)).toFixed(3)} ${(16-15*Math.cos(A)).toFixed(3)}`,N=b[v]>=w?"M16 1a15 15 0 1 1 0 30a15 15 0 1 1 0-30Z":`M16 16L${R(k)}A15 15 0 ${T-k>Math.PI?1:0} 1 ${R(T)}Z`;return k=T,`<path class="b3-md-c${v%8}" d="${N}">${o(x,v,m)}</path>`});return`<figure class="b3-md-chart b3-surface">${l}<div class="b3-md-pie"><svg viewBox="0 0 32 32" role="img" aria-label="${u(n||m)}">${L.join("")}</svg>${c(i.map(r))}</div></figure>`}let h=i.flatMap((m)=>t.map((b)=>s(m,b))),p=Math.min(0,...h),f=Math.max(0,...h),M=f-p||1,g=(m)=>(100-(m-p)/M*100).toFixed(2),d=i.length,y=e==="line"?t.map((m,b)=>`<polyline class="b3-md-c${b%8}" vector-effect="non-scaling-stroke" points="${i.map((w,k)=>`${(d>1?k/(d-1)*100:50).toFixed(2)},${g(s(w,m))}`).join(" ")}"><title>${u(m)}</title></polyline>`).join(""):i.map((m,b)=>t.map((w,k)=>{let L=100/d*0.8/t.length,x=100/d*(b+0.1)+L*k,v=s(m,w),T=Math.min(+g(v),+g(0));return`<rect class="b3-md-c${k%8}" x="${x.toFixed(2)}" y="${T.toFixed(2)}" width="${L.toFixed(2)}" height="${Math.max(Math.abs(+g(v)-+g(0)),0.4).toFixed(2)}">${o(m,b,w)}</rect>`}).join("")).join(""),j=d>2?[0,Math.floor((d-1)/2),d-1]:[...Array(d).keys()];return`<figure class="b3-md-chart b3-surface">${l}<div class="b3-md-plot"><div class="b3-md-y"><span>${I(f)}</span><span>${I(p)}</span></div><svg viewBox="0 0 100 100" preserveAspectRatio="none" role="img" aria-label="${u(n||t.join(", "))}">${y}</svg><div class="b3-md-x">${j.map((m)=>`<span>${u(r(i[m],m))}</span>`).join("")}</div></div>${t.length>1?c(t):""}</figure>`}S.callout.doc='`:::callout{tone=info|success|warning|danger title="Short title"}` newline, markdown body, newline `:::` — a highlighted note, tip, warning or recommendation.';S.stats.doc="`:::stats` newline, one card per line `Label | Value | note`, newline `:::` — headline numbers; a note starting with ↑ or + shows as good, ↓ or - as bad.";E.chart.doc="```chart fence, one bar per line `Label: number` (plain number, no units) — a horizontal bar chart for comparing a few values.";function X(e={}){let n={...S,...e.directives,...E,...e.fences},a=Object.entries(e.tones??new O().tones).reduce((t,[i,s])=>((t[s]??=[]).push(i),t),{});return["Your replies are Markdown rendered live into UI components. Use GitHub-flavoured Markdown (headings, **bold**, lists, links, `inline code`, fenced code with a language, > quotes) plus:",`- Tables: GFM pipe tables with a header row and a \`| --- |\` delimiter row. Never add a Status column the data does not already have. Only when a row really has one of these states (e.g. an invoice that is paid), write the plain word alone in the cell and it is shown as a coloured badge automatically (no images, emoji or badge URLs): ${Object.entries(a).map(([t,i])=>`${i.join(", ")} (${t})`).join("; ")}. Numeric columns align right.`,"- Task lists: `- [x] done` and `- [ ] to do`.",...Object.values(n).filter((t)=>t?.doc).map((t)=>`- ${t.doc}`),"Use a component only when it makes the answer clearer; plain prose is fine. Put every block on its own lines with a blank line around it, always close ::: and ``` blocks, and never write raw HTML."].join(`
4
+ `)}var z=(e,n)=>`<div class="b3-md-code"><header><span class="b3-muted">${u(n||"text")}</span><button type="button" class="b3-button" data-b3-emphasis="quiet" data-b3-md-copy>Copy</button></header><pre><code>${u(e)}</code></pre></div>`;function V(e){let n=e,a=n.split(`
5
+ `),t=[];while(a.length&&/^\s*\|/.test(a.at(-1)))t.unshift(a.pop());let i=e.endsWith(`
6
+ `)?t:t.slice(0,-1),s=!1;if(t.length&&!i.some((c)=>/^\s*\|?\s*:?-{2,}/.test(c)))s=!0,n=a.join(`
7
+ `);if(n=n.replace(/(^|\n) {0,3}(`{3}[^\n]*|~{3}[^\n]*|:{3}[^\n]*|`{1,2}|~{1,2}|:{1,2})$/,"$1"),(n.match(/^ {0,3}(`{3}|~{3})/gm)||[]).length%2)return{src:n,pendingTable:s};n=n.replace(/\[([^\]\n]*)\]?\([^)\n]*$/,"$1").replace(/\[([^\]\n]*)$/,"$1").replace(/(\*{1,3}|_{1,3}|~{1,2}|`)$/,"");let r=[...n.matchAll(/^ {0,3}(`{3}|~{3})[^\n]*\n?/gm)].at(-1),o=n.slice(Math.max(n.lastIndexOf(`
8
8
 
9
- `)+1,i?i.index+i[0].length:0)),l="";for(let c of["`","~~"])if(o.split(c).length%2===0)l=c+l;return l+=G(o),{src:l?n.trimEnd()+l:n,pendingTable:s}}function G(e){let n=e.replace(/`[^`\n]*`?/g,"").replace(/\\[*_]/g,"").replace(/\]\([^)\n]*\)?|https?:\/\/\S*/g,"]"),a=[];for(let{0:t,index:r}of n.matchAll(/\*+|_+/g)){let s=n[r-1]??" ",i=n[r+t.length]??" ",o=t.length;if(/\S/.test(s)&&(t[0]==="*"||!/\w/.test(i)))while(o&&a.at(-1)?.[0]===t[0]){let c=a.pop(),d=Math.min(o,c.length);if(o-=d,c.length>d)a.push(c.slice(d))}let l=/[\p{L}\p{N}]/u.test(i)||t.length>1&&/\s/.test(s)&&/^[^\s\w*_-]\S*$/.test(n.slice(r+t.length));if(o&&l&&!(/\w/.test(s)&&(t[0]==="_"||o===1)))a.push(t.slice(0,o))}return a.reverse().join("")}var F={note:"info",info:"info",tip:"success",important:"info",warning:"warning",caution:"danger",danger:"danger"},J="b3-markdown-stream-style",W=`
9
+ `)+1,r?r.index+r[0].length:0)),l="";for(let c of["`","~~"])if(o.split(c).length%2===0)l=c+l;return l+=W(o),{src:l?n.trimEnd()+l:n,pendingTable:s}}function W(e){let n=e.replace(/`[^`\n]*`?/g,"").replace(/\\[*_]/g,"").replace(/\]\([^)\n]*\)?|https?:\/\/\S*/g,"]"),a=[];for(let{0:t,index:i}of n.matchAll(/\*+|_+/g)){let s=n[i-1]??" ",r=n[i+t.length]??" ",o=t.length;if(/\S/.test(s)&&(t[0]==="*"||!/\w/.test(r)))while(o&&a.at(-1)?.[0]===t[0]){let c=a.pop(),h=Math.min(o,c.length);if(o-=h,c.length>h)a.push(c.slice(h))}let l=/[\p{L}\p{N}]/u.test(r)||t.length>1&&/\s/.test(s)&&/^[^\s\w*_-]\S*$/.test(n.slice(i+t.length));if(o&&l&&!(/\w/.test(s)&&(t[0]==="_"||o===1)))a.push(t.slice(0,o))}return a.reverse().join("")}var D={note:"info",info:"info",tip:"success",important:"info",warning:"warning",caution:"danger",danger:"danger"},G="b3-markdown-stream-style",J=`
10
10
  .b3-prose > :is(.b3-md-stats,.b3-table-wrap,.b3-alert,.b3-md-code,.b3-md-bars){margin-block:1rem;}
11
11
  .b3-prose > :first-child{margin-block-start:0;}
12
12
  .b3-md-appear{animation:b3-md-in var(--b3-duration,.2s) ease-out;}
@@ -56,8 +56,8 @@ var q=Symbol.for("bare-v3.styles");function O(e,n,a){if(!e?.head||e.getElementBy
56
56
  .b3-md-pending>.b3-skeleton{block-size:1.5rem;}
57
57
  .b3-md-pending>.b3-skeleton+.b3-skeleton{inline-size:80%;}
58
58
  @media (prefers-reduced-motion:reduce){.b3-md-appear,.b3-md-caret{animation:none;}}
59
- `;class L{Marked=null;sanitize=null;directives=T;fences=S;code=j;tones={paid:"success",done:"success",ok:"success",active:"success",pending:"warning",overdue:"danger",failed:"danger",blocked:"danger",draft:"info"};html="escape";images="alt";markedOptions={}}class Z{el=null;buf="";nodes=[];ended=!1;options;#e;#t=(e)=>this.#n(e);constructor(e){this.options={...new L,...e},this.options.directives={...T,...e?.directives},this.options.fences={...S,...e?.fences};let{Marked:n,sanitize:a}=this.options;if(typeof n!=="function")throw TypeError('MarkdownStream: options.Marked (from "marked") is required');if(typeof a!=="function")throw TypeError("MarkdownStream: options.sanitize is required (e.g. html => DOMPurify.sanitize(html))");this.#e=this.#s()}attach(e){return this.detach(),this.el=e,e.replaceChildren(),this.buf="",this.nodes=[],this.ended=!1,O(e.ownerDocument,J,W),e.addEventListener("click",this.#t),this}detach(){this.el?.removeEventListener("click",this.#t),this.el=null}push(e){if(this.ended){console.warn("MarkdownStream: push() after end() ignored; call attach(el) to start a new stream");return}this.buf+=e,this.render(!0)}end(e){if(e!==void 0)this.buf=String(e);this.ended=!0,this.render(!1)}toHtml(e){return this.options.sanitize(this.#e.parse(e))}render(e){let{el:n}=this;if(!n)throw Error("MarkdownStream: call attach(el) before push()");let a=n.ownerDocument,{src:t,pendingTable:r}=e?V(this.buf):{src:this.buf,pendingTable:!1},s=this.#e.lexer(t).filter((i)=>i.type!=="space");if(s.forEach((i,o)=>{let l=this.nodes[o];if(l&&l.raw===i.raw)return;let c=a.createElement("div");c.innerHTML=this.options.sanitize(this.#e.parser([i]));let m=(c.childElementCount===1&&[...c.childNodes].every((g)=>g.nodeType===1||!g.textContent.trim())?c.firstElementChild:null)??c;if(!l)m.classList.add("b3-md-appear");l?l.el.replaceWith(m):n.append(m),this.nodes[o]={raw:i.raw,el:m}}),this.nodes.splice(s.length).forEach((i)=>i.el.remove()),n.querySelector(":scope .b3-md-caret, :scope > .b3-md-pending")?.remove(),r)n.insertAdjacentHTML("beforeend",'<div class="b3-md-pending" aria-hidden="true"><div class="b3-skeleton"></div><div class="b3-skeleton"></div></div>');else if(e){let i=this.nodes.at(-1)?.el;((i?.matches("p, li, td, th, pre"))?i:i?.querySelector("p:last-of-type, li:last-child, td:last-child")||i||n).insertAdjacentHTML("beforeend",'<span class="b3-md-caret" aria-hidden="true"></span>')}}#n(e){let n=e.target.closest?.("[data-b3-md-copy]");if(!n||!this.el?.contains(n))return;let a=n.closest(".b3-md-code")?.querySelector("code")?.textContent??"",t=(i)=>{n.textContent=i,setTimeout(()=>{n.textContent="Copy"},1200)},r=(i)=>{console.warn("MarkdownStream: copy failed",i),t("Copy failed")},s=this.el.ownerDocument.defaultView?.navigator?.clipboard;if(s?.writeText)s.writeText(a).then(()=>t("Copied"),r);else r(Error("navigator.clipboard is unavailable (insecure context?)"))}#s(){let e=this.options,n={name:"directive",level:"block",start:(t)=>t.match(/^:::/m)?.index,tokenizer(t){let r=/^:::(\w+)(?:\{([^}\n]*)\})?[^\n]*(?:\n|$)/.exec(t);if(!r)return;let s=t.slice(r[0].length).split(`
60
- `),i=null,o=s.length;for(let m=0;m<s.length;m++){let g=/^ {0,3}(`{3,}|~{3,})/.exec(s[m])?.[1];if(i){if(g&&g[0]===i[0]&&g.length>=i.length&&!s[m].trim().slice(g.length))i=null}else if(g)i=g;else if(/^:::[^\S\n]*$/.test(s[m])){o=m;break}}let l=s.slice(0,o).join(`
61
- `).replace(/\n$/,""),c=o<s.length;return{type:"directive",raw:r[0]+s.slice(0,c?o+1:o).join(`
59
+ `;class O{Marked=null;sanitize=null;directives=S;fences=E;code=z;tones={paid:"success",done:"success",ok:"success",active:"success",pending:"warning",overdue:"danger",failed:"danger",blocked:"danger",draft:"info"};html="escape";images="alt";markedOptions={}}class Z{el=null;buf="";nodes=[];ended=!1;options;#e;#t=(e)=>this.#n(e);constructor(e){this.options={...new O,...e},this.options.directives={...S,...e?.directives},this.options.fences={...E,...e?.fences};let{Marked:n,sanitize:a}=this.options;if(typeof n!=="function")throw TypeError('MarkdownStream: options.Marked (from "marked") is required');if(typeof a!=="function")throw TypeError("MarkdownStream: options.sanitize is required (e.g. html => DOMPurify.sanitize(html))");this.#e=this.#s()}attach(e){return this.detach(),this.el=e,e.replaceChildren(),this.buf="",this.nodes=[],this.ended=!1,F(e.ownerDocument,G,J),e.addEventListener("click",this.#t),this}detach(){this.el?.removeEventListener("click",this.#t),this.el=null}push(e){if(this.ended){console.warn("MarkdownStream: push() after end() ignored; call attach(el) to start a new stream");return}this.buf+=e,this.render(!0)}end(e){if(e!==void 0)this.buf=String(e);this.ended=!0,this.render(!1)}toHtml(e){return this.options.sanitize(this.#e.parse(e))}render(e){let{el:n}=this;if(!n)throw Error("MarkdownStream: call attach(el) before push()");let a=n.ownerDocument,{src:t,pendingTable:i}=e?V(this.buf):{src:this.buf,pendingTable:!1},s=this.#e.lexer(t).filter((r)=>r.type!=="space");if(s.forEach((r,o)=>{let l=this.nodes[o];if(l&&l.raw===r.raw)return;let c=a.createElement("div");c.innerHTML=this.options.sanitize(this.#e.parser([r]));let p=(c.childElementCount===1&&[...c.childNodes].every((f)=>f.nodeType===1||!f.textContent.trim())?c.firstElementChild:null)??c;if(!l)p.classList.add("b3-md-appear");l?l.el.replaceWith(p):n.append(p),this.nodes[o]={raw:r.raw,el:p}}),this.nodes.splice(s.length).forEach((r)=>r.el.remove()),n.querySelector(":scope .b3-md-caret, :scope > .b3-md-pending")?.remove(),i)n.insertAdjacentHTML("beforeend",'<div class="b3-md-pending" aria-hidden="true"><div class="b3-skeleton"></div><div class="b3-skeleton"></div></div>');else if(e){let r=this.nodes.at(-1)?.el;((r?.matches("p, li, td, th, pre"))?r:r?.querySelector("p:last-of-type, li:last-child, td:last-child")||r||n).insertAdjacentHTML("beforeend",'<span class="b3-md-caret" aria-hidden="true"></span>')}}#n(e){let n=e.target.closest?.("[data-b3-md-copy]");if(!n||!this.el?.contains(n))return;let a=n.closest(".b3-md-code")?.querySelector("code")?.textContent??"",t=(r)=>{n.textContent=r,setTimeout(()=>{n.textContent="Copy"},1200)},i=(r)=>{console.warn("MarkdownStream: copy failed",r),t("Copy failed")},s=this.el.ownerDocument.defaultView?.navigator?.clipboard;if(s?.writeText)s.writeText(a).then(()=>t("Copied"),i);else i(Error("navigator.clipboard is unavailable (insecure context?)"))}#s(){let e=this.options,n={name:"directive",level:"block",start:(t)=>t.match(/^:::/m)?.index,tokenizer(t){let i=/^:::(\w+)(?:\{([^}\n]*)\})?[^\n]*(?:\n|$)/.exec(t);if(!i)return;let s=t.slice(i[0].length).split(`
60
+ `),r=null,o=s.length;for(let p=0;p<s.length;p++){let f=/^ {0,3}(`{3,}|~{3,})/.exec(s[p])?.[1];if(r){if(f&&f[0]===r[0]&&f.length>=r.length&&!s[p].trim().slice(f.length))r=null}else if(f)r=f;else if(/^:::[^\S\n]*$/.test(s[p])){o=p;break}}let l=s.slice(0,o).join(`
61
+ `).replace(/\n$/,""),c=o<s.length;return{type:"directive",raw:i[0]+s.slice(0,c?o+1:o).join(`
62
62
  `)+(c&&o+1<s.length?`
63
- `:""),name:r[1],attrs:P(r[2]),body:l,tokens:this.lexer.blockTokens(l,[])}},renderer(t){return(e.directives[t.name]??e.directives.callout)(t,{parse:(s)=>this.parser.parse(s),parseInline:(s)=>this.parser.parseInline(s),inline:(s)=>a.parseInline(s),esc:b})}},a=new e.Marked({gfm:!0,extensions:[n]});if(a.use({renderer:{blockquote(t){let r=/^\s*(?:\[!(\w+)\][^\S\n]*\n?|\*\*(\w+):?\*\*:?[^\S\n]*)/.exec(t.text),s=(r?.[1]??r?.[2])?.toLowerCase();if(!s||!r||!Object.hasOwn(F,s))return!1;let i=s[0].toUpperCase()+s.slice(1);return e.directives.callout({attrs:{tone:F[s],title:i},tokens:a.lexer(t.text.slice(r[0].length))},{parse:(o)=>this.parser.parse(o),parseInline:(o)=>this.parser.parseInline(o),inline:(o)=>a.parseInline(o),esc:b})},table(t){let r=t.header.map((i,o)=>t.rows.length>0&&t.rows.every((l)=>B(l[o]?.text||"0"))),s=(i,o,l)=>{let c=this.parser.parseInline(i.tokens),d=l==="td"&&e.tones[i.text.trim().toLowerCase()],m=d?`<span class="b3-badge" data-b3-tone="${b(d)}">${c}</span>`:c;return`<${l}${l==="th"?' scope="col"':""}${r[o]?' class="b3-md-num"':""}>${m}</${l}>`};return`<div class="b3-table-wrap" tabindex="0" role="region" aria-label="Table"><table class="b3-table b3-md-table"><thead><tr>${t.header.map((i,o)=>s(i,o,"th")).join("")}</tr></thead><tbody>${t.rows.map((i)=>`<tr>${i.map((o,l)=>s(o,l,"td")).join("")}</tr>`).join("")}</tbody></table></div>`},code({text:t,lang:r}){let s=(r||"").trim().split(/\s/)[0],i=Object.hasOwn(e.fences,s)?e.fences[s]:null;return i?i(t,{esc:b,lang:s}):e.code(t,s)},html(t){return e.html==="render"?!1:t.block?`<p>${b(t.text.trim())}</p>`:b(t.text)},image({href:t,text:r}){return e.images==="render"||typeof e.images==="function"&&e.images(t??"")?!1:b(r)},list(t){if(!t.items.some((r)=>r.task))return!1;return`<ul class="b3-md-tasks">${t.items.map((r)=>{let s=r.tokens.filter((l)=>l.type!=="checkbox"),i=s.find((l)=>l.type==="text"||l.type==="paragraph");if(i?.tokens)i.tokens=i.tokens.filter((l)=>l.type!=="checkbox");let o=s.map((l)=>l.type==="text"&&!r.loose?this.parser.parseInline(l.tokens??[l]):this.parser.parse([l])).join("");return`<li><input type="checkbox" disabled${r.checked?" checked":""}>${o}</li>`}).join("")}</ul>`}}}),e.markedOptions&&Object.keys(e.markedOptions).length)a.use(e.markedOptions);return a}}function ee(e=document.scrollingElement,{threshold:n=80}={}){let a=e.ownerDocument,t=a.defaultView,r=e===a.scrollingElement?t:e,s=!0,i=e.scrollTop,o=()=>{let d=e.scrollTop;if(e.scrollHeight-d-e.clientHeight>=n)s=!1;else if(d>=i)s=!0;i=d},l=(d)=>{if(d.target?.closest?.('input, textarea, select, [contenteditable]:not([contenteditable="false"])'))return;if(e.scrollTop>0&&((d.deltaY??0)<0||/^(ArrowUp|PageUp|Home)$/.test(d.key??"")))s=!1},c=[["scroll",o],["wheel",l],["keydown",l]];return c.forEach(([d,m])=>r.addEventListener(d,m,{passive:!0})),{get pinned(){return s},stick(d=!1){if(d||s)e.scrollTop=e.scrollHeight,s=!0},destroy(){c.forEach(([d,m])=>r.removeEventListener(d,m))}}}export{Z as MarkdownStream,L as MarkdownStreamOptions,j as codeBlock,T as directives,b as esc,S as fences,B as isNum,U as jsonChart,P as parseAttrs,X as promptGuide,V as settle,ee as stickToBottom};
63
+ `:""),name:i[1],attrs:P(i[2]),body:l,tokens:this.lexer.blockTokens(l,[])}},renderer(t){return(e.directives[t.name]??e.directives.callout)(t,{parse:(s)=>this.parser.parse(s),parseInline:(s)=>this.parser.parseInline(s),inline:(s)=>a.parseInline(s),esc:u})}},a=new e.Marked({gfm:!0,extensions:[n]});if(a.use({renderer:{blockquote(t){let i=/^\s*(?:\[!(\w+)\][^\S\n]*\n?|\*\*(\w+):?\*\*:?[^\S\n]*)/.exec(t.text),s=(i?.[1]??i?.[2])?.toLowerCase();if(!s||!i||!Object.hasOwn(D,s))return!1;let r=s[0].toUpperCase()+s.slice(1);return e.directives.callout({attrs:{tone:D[s],title:r},tokens:a.lexer(t.text.slice(i[0].length))},{parse:(o)=>this.parser.parse(o),parseInline:(o)=>this.parser.parseInline(o),inline:(o)=>a.parseInline(o),esc:u})},table(t){let i=t.header.map((r,o)=>t.rows.length>0&&t.rows.every((l)=>B(l[o]?.text||"0"))),s=(r,o,l)=>{let c=this.parser.parseInline(r.tokens),h=l==="td"&&e.tones[r.text.trim().toLowerCase()],p=h?`<span class="b3-badge" data-b3-tone="${u(h)}">${c}</span>`:c;return`<${l}${l==="th"?' scope="col"':""}${i[o]?' class="b3-md-num"':""}>${p}</${l}>`};return`<div class="b3-table-wrap" tabindex="0" role="region" aria-label="Table"><table class="b3-table b3-md-table"><thead><tr>${t.header.map((r,o)=>s(r,o,"th")).join("")}</tr></thead><tbody>${t.rows.map((r)=>`<tr>${r.map((o,l)=>s(o,l,"td")).join("")}</tr>`).join("")}</tbody></table></div>`},code({text:t,lang:i}){let s=(i||"").trim().split(/\s/)[0],r=Object.hasOwn(e.fences,s)?e.fences[s]:null;return r?r(t,{esc:u,lang:s}):e.code(t,s)},html(t){return e.html==="render"?!1:t.block?`<p>${u(t.text.trim())}</p>`:u(t.text)},image({href:t,text:i}){return e.images==="render"||typeof e.images==="function"&&e.images(t??"")?!1:u(i)},list(t){if(!t.items.some((i)=>i.task))return!1;return`<ul class="b3-md-tasks">${t.items.map((i)=>{let s=i.tokens.filter((l)=>l.type!=="checkbox"),r=s.find((l)=>l.type==="text"||l.type==="paragraph");if(r?.tokens)r.tokens=r.tokens.filter((l)=>l.type!=="checkbox");let o=s.map((l)=>l.type==="text"&&!i.loose?this.parser.parseInline(l.tokens??[l]):this.parser.parse([l])).join("");return`<li><input type="checkbox" disabled${i.checked?" checked":""}>${o}</li>`}).join("")}</ul>`}}}),e.markedOptions&&Object.keys(e.markedOptions).length)a.use(e.markedOptions);return a}}function ee(e=document.scrollingElement,{threshold:n=80,inner:a=".b3-message-disclosure[open] > :not(summary)"}={}){let t=e.ownerDocument,i=t.defaultView,s=e===t.scrollingElement?i:e,r=!0,o=e.scrollTop,l=new WeakSet,c=new WeakMap,h=(g)=>g.scrollHeight-g.scrollTop-g.clientHeight,p=(g)=>{let d=g.target===t?t.scrollingElement:g.target;if(d&&d!==e){if(!d.matches?.(a))return;let m=c.get(d)??0,b=d.scrollTop;if(h(d)<2||b>=m&&h(d)<n)l.delete(d);else if(b<m)l.add(d);c.set(d,b);return}let y=e.scrollTop,j=h(e);if(y<o&&j>1)r=!1;else if(j<n)r=!0;o=y},f=(g)=>{let d=g.target;if(d?.closest?.('input, textarea, select, [contenteditable]:not([contenteditable="false"])'))return;if(!((g.deltaY??0)<0||/^(ArrowUp|PageUp|Home)$/.test(g.key??"")))return;let y=d?.closest?.(a);if(y&&e.contains(y)&&y.scrollTop>0)l.add(y);else if(e.scrollTop>0)r=!1},M=[["scroll",p,!0],["wheel",f,!1],["keydown",f,!1]];return M.forEach(([g,d,y])=>s.addEventListener(g,d,{passive:!0,capture:y})),{get pinned(){return r},stick(g=!1){for(let d of e.querySelectorAll(a))if(!l.has(d))d.scrollTop=d.scrollHeight,c.set(d,d.scrollTop);if(g||r)e.scrollTop=e.scrollHeight,o=e.scrollTop,r=!0},destroy(){M.forEach(([g,d,y])=>s.removeEventListener(g,d,{capture:y}))}}}export{Z as MarkdownStream,O as MarkdownStreamOptions,z as codeBlock,S as directives,u as esc,E as fences,B as isNum,U as jsonChart,P as parseAttrs,X as promptGuide,V as settle,ee as stickToBottom};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@livx.cc/bare-v3",
3
- "version": "0.1.0-alpha.159",
3
+ "version": "0.1.0-alpha.160",
4
4
  "type": "module",
5
5
  "thirdPartyNotices": "./dist/third-party.json",
6
6
  "files": [