@motionscript/code 0.1.0-alpha.0 → 0.1.0-alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/CHANGELOG.md +66 -0
  2. package/LICENSE +201 -201
  3. package/NOTICE +48 -0
  4. package/README.md +161 -77
  5. package/dist/browser/THIRD_PARTY_LICENSES.txt +431 -0
  6. package/dist/browser/index.js +7 -7
  7. package/dist/browser/index.js.map +3 -3
  8. package/dist/browser/manifest.json +85 -3
  9. package/dist/code-range.d.ts +7 -1
  10. package/dist/code-range.d.ts.map +1 -1
  11. package/dist/code-range.js +9 -1
  12. package/dist/code-range.js.map +1 -1
  13. package/dist/diff.d.ts +14 -0
  14. package/dist/diff.d.ts.map +1 -1
  15. package/dist/diff.js +134 -2
  16. package/dist/diff.js.map +1 -1
  17. package/dist/engine.d.ts +1 -1
  18. package/dist/engine.d.ts.map +1 -1
  19. package/dist/engine.js +1 -1
  20. package/dist/engine.js.map +1 -1
  21. package/dist/highlight.d.ts +10 -2
  22. package/dist/highlight.d.ts.map +1 -1
  23. package/dist/highlight.js +40 -6
  24. package/dist/highlight.js.map +1 -1
  25. package/dist/index.js.map +1 -1
  26. package/dist/layout.d.ts +1 -1
  27. package/dist/layout.d.ts.map +1 -1
  28. package/dist/layout.js.map +1 -1
  29. package/dist/measure-cache.d.ts +1 -1
  30. package/dist/measure-cache.d.ts.map +1 -1
  31. package/dist/measure-cache.js.map +1 -1
  32. package/dist/node.d.ts +62 -7
  33. package/dist/node.d.ts.map +1 -1
  34. package/dist/node.js +224 -42
  35. package/dist/node.js.map +1 -1
  36. package/dist/nodes.js.map +1 -1
  37. package/dist/render.d.ts +7 -2
  38. package/dist/render.d.ts.map +1 -1
  39. package/dist/render.js +60 -1
  40. package/dist/render.js.map +1 -1
  41. package/dist/style.d.ts +3 -3
  42. package/dist/style.d.ts.map +1 -1
  43. package/dist/style.js +10 -6
  44. package/dist/style.js.map +1 -1
  45. package/dist/tokens.d.ts.map +1 -1
  46. package/dist/tokens.js +5 -1
  47. package/dist/tokens.js.map +1 -1
  48. package/dist/transitions.d.ts +19 -1
  49. package/dist/transitions.d.ts.map +1 -1
  50. package/dist/transitions.js.map +1 -1
  51. package/package.json +7 -4
  52. package/registry.json +6 -6
  53. package/src/code-range.ts +165 -156
  54. package/src/diff.ts +351 -216
  55. package/src/engine.ts +21 -21
  56. package/src/highlight.ts +340 -291
  57. package/src/index.ts +3 -3
  58. package/src/layout.ts +157 -157
  59. package/src/measure-cache.ts +0 -0
  60. package/src/node.ts +1038 -834
  61. package/src/nodes.ts +18 -18
  62. package/src/render.ts +312 -247
  63. package/src/style.ts +255 -251
  64. package/src/tokens.ts +79 -75
  65. package/src/transitions.ts +204 -184
@@ -1,8 +1,8 @@
1
- import{j as ct,k as lt,l as e}from"./chunks/chunk-SYZUZB3M.js";import{node as ie,Clip as re,Node2D as ae,property as N,insetsOps as Mt,lerpNumber as Ot,command as F,driveCommand as A}from"@motionscript/core";function Ft(n,t,o){if(o<=n[0])return t[0];if(o>=n[n.length-1])return t[t.length-1];for(let i=0;i<n.length-1;i++)if(o<=n[i+1]){let a=n[i+1]-n[i],s=a===0?0:(o-n[i])/a;return t[i]+(t[i+1]-t[i])*s}return t[t.length-1]}function G(n,t){if(!n)return 1;let[o,i]=n;return t<=o?0:t>=i||i===o?1:(t-o)/(i-o)}function zt(n){return n*n*(3-2*n)}function X(n,t){return{id:n,opacity:t.values,opacityKeys:t.keys}}function Et(n,t){return n&&t?{out:[0,.38],move:[.1,.68],in:[.52,1]}:n?{out:[0,.45],move:[.22,1],in:null}:t?{out:null,move:[0,.55],in:[.38,1]}:{out:null,move:[0,1],in:null}}var dt=Et;function K(n){return n?zt(G(n.phases.move,n.progress)):1}function ht(n,t,o,i){let a=new Map;if(o!==null){let s=o;for(let r of n)for(let c of r.tokens)a.set(c.id,{opacity:i.has(c.id)?1:s})}for(let s of t)if(s.kind==="dim")for(let r of s.tokens)a.set(r.id,{opacity:Ft(r.opacityKeys,r.opacity,s.progress)});return a}function W(n){let t=n.padding;return[n.fontSize,n.fontFamily,n.lineHeight,n.letterSpacing,t.left,t.right,t.top,t.bottom,n.showLineNumbers?1:0,n.lineNumberGap].join("|")}function Dt(n,t,o){return o.advance(n," ",t.fontSize,t.fontFamily,0)*t.lineNumberGap}function jt(n,t,o,i,a){if(!t.showLineNumbers)return 0;let s=String(Math.max(1,i));return o.advance(n,s,t.fontSize,t.fontFamily,0)+a}function B(n,t,o,i){let a=t.fontSize*t.lineHeight,s=t.showLineNumbers?Dt(i,t,o):0,r=jt(i,t,o,n.length,s),c=new Array(n.length),l=0;for(let b=0;b<n.length;b++){let m=0;for(let S of n[b].tokens)m+=o.advance(i,S.content,t.fontSize,t.fontFamily,t.letterSpacing);c[b]=m,m>l&&(l=m)}let d=l+r,h=n.length*a,f=d+t.padding.left+t.padding.right,u=h+t.padding.top+t.padding.bottom,g=-f/2+t.padding.left+r,k=u/2-t.padding.top,w=new Map,p=new Array(n.length),C=new Map;for(let b=0;b<n.length;b++){let m=k-b*a-a/2;p[b]=m,C.set(n[b].id,b);let S=g;for(let L of n[b].tokens)w.set(L.id,{x:S,y:m}),S+=o.advance(i,L.content,t.fontSize,t.fontFamily,t.letterSpacing)}return{tokens:w,lineY:p,lineW:c,lineIndex:C,gutter:r,gutterGap:s,innerW:d,innerH:h,blockW:f,blockH:u,startX:g}}import{Graphics2D as ft,parseColor as _t,lerpNumber as z}from"@motionscript/core";var Rt=[.82,.84,.86,1],Gt=[.45,.5,.55,1],ut=new Map;function J(n){if(!n)return Rt;let t=ut.get(n);return t||(t=_t(n),ut.set(n,t)),t}function Kt(n,t,o){return o<=0?n:o>=1?t:[n[0]+(t[0]-n[0])*o,n[1]+(t[1]-n[1])*o,n[2]+(t[2]-n[2])*o,n[3]+(t[3]-n[3])*o]}function Wt(n,t,o){if(!o)return 1;let i=1;for(let a of n.tokens){if(a.content.length===0)continue;let s=t.get(a.id)?.opacity??1;s<i&&(i=s)}return i}function Q(n,t){let{tokenLines:o,metrics:i,advanceCache:a,from:s,to:r,edit:c,tokenStates:l}=t,d=c?c.progress:1,h=c?G(c.phases.out,d):1,f=K(c),u=c?G(c.phases.in,d):1,g=c?z(s.blockW,r.blockW,f):r.blockW,k=c?z(s.gutter,r.gutter,f):r.gutter,w=r.gutterGap||s.gutterGap,p=-g/2+i.padding.left+k-w,C=(m,S,L)=>{if(L<=0)return;let I=a.advance(n,m,i.fontSize,i.fontFamily,0);n.draw(new ft().text({text:m,fontSize:i.fontSize,fontFamily:i.fontFamily,lineHeight:i.lineHeight,x:p-I/2,y:S,textAlign:"left"}).fill([{type:"solid",color:Gt,opacity:L}]))},b=(m,S,L,I,M)=>{if(M<=0||m.length===0)return;let T=a.advance(n,m,i.fontSize,i.fontFamily,i.letterSpacing);n.draw(new ft().text({text:m,fontSize:i.fontSize,fontFamily:i.fontFamily,lineHeight:i.lineHeight,letterSpacing:i.letterSpacing,x:S+T/2,y:L,textAlign:"left"}).fill([{type:"solid",color:I,opacity:M}]))};for(let m=0;m<o.length;m++){let S=o[m],L=r.lineIndex.get(S.id);if(L===void 0)continue;let I=r.lineY[L],M=c?.enteringLineIds.has(S.id)??!1,T=I,D=1;if(c&&M)D=u;else if(c){let v=s.lineIndex.get(S.id);v!==void 0&&(T=z(s.lineY[v],I,f))}for(let v of S.tokens){let V=r.tokens.get(v.id);if(!V)continue;let rt=V.x,at=D,q=J(v.color);if(c&&!M)if(c.addedIds.has(v.id))at=u;else{let st=s.tokens.get(v.id);st&&(rt=z(st.x,V.x,f)),c.fromColorById.has(v.id)&&(q=Kt(J(c.fromColorById.get(v.id)),q,f))}b(v.content,rt,T,q,at*(l.get(v.id)?.opacity??1))}}if(c&&h<1)for(let m=0;m<c.from.length;m++){let S=c.from[m],L=s.lineIndex.get(S.id);if(L===void 0)continue;let I=r.lineIndex.get(S.id),M=I===void 0?s.lineY[L]:z(s.lineY[L],r.lineY[I],f);for(let T of S.tokens){if(!c.removedIds.has(T.id))continue;let D=s.tokens.get(T.id);D&&b(T.content,D.x,M,J(T.color),1-h)}}i.showLineNumbers&&Bt(t,C,f,u,h)}function Bt(n,t,o,i,a){let{tokenLines:s,from:r,to:c,edit:l,tokenStates:d,highlightActive:h}=n,f=s.length,u=l?l.from.length:f;for(let g=0;g<Math.max(u,f);g++){let k=g<u,w=g<f,p=w?s[g]:l?.from[g],C=p?Wt(p,d,h):1;l?k&&w?t(String(g+1),z(r.lineY[g],c.lineY[g],o),C):w?t(String(g+1),c.lineY[g],i*C):t(String(g+1),r.lineY[g],(1-a)*C):t(String(g+1),c.lineY[g],C)}}function P(n){return n.content.trim().length}function gt(n){let t=0;for(let o of n.tokens)t+=P(o);return t}function Pt(n,t){let o=gt(n),i=gt(t);if(o===0&&i===0)return 1;if(o===0||i===0)return 0;let a=new Map;for(let r of n.tokens)P(r)!==0&&a.set(r.content,(a.get(r.content)??0)+1);let s=0;for(let r of t.tokens){let c=P(r);if(c===0)continue;let l=a.get(r.content)??0;l>0&&(a.set(r.content,l-1),s+=c)}return 2*s/(o+i)}function pt(n,t,o){let i=t+1,a=new Float64Array((n+1)*i),s=new Float64Array(n*t);for(let d=1;d<=n;d++)for(let h=1;h<=t;h++){let f=o(d-1,h-1);s[(d-1)*t+(h-1)]=f;let u=a[(d-1)*i+h],g=a[d*i+(h-1)],k=u>g?u:g;if(f>0){let w=a[(d-1)*i+(h-1)]+f;w>k&&(k=w)}a[d*i+h]=k}let r=[],c=n,l=t;for(;c>0&&l>0;){let d=s[(c-1)*t+(l-1)];d>0&&a[c*i+l]===a[(c-1)*i+(l-1)]+d?(r.push([c-1,l-1]),c--,l--):a[(c-1)*i+l]>=a[c*i+(l-1)]?c--:l--}return r.reverse(),r}function Yt(n,t){return pt(n.length,t.length,(o,i)=>n[o].content!==t[i].content?0:P(t[i])||.25)}function Z(n,t){let o=new Set,i=new Set,a=new Set,s=new Map,r=pt(n.length,t.length,(d,h)=>Pt(n[d],t[h])-.45),c=new Set,l=new Set;for(let[d,h]of r){l.add(d),c.add(h);let f=n[d],u=t[h];u.id=f.id;let g=Yt(f.tokens,u.tokens),k=new Set,w=new Set;for(let[p,C]of g){k.add(p),w.add(C);let b=f.tokens[p],m=u.tokens[C];m.id=b.id,b.color!==m.color&&s.set(b.id,b.color)}for(let p=0;p<f.tokens.length;p++)k.has(p)||o.add(f.tokens[p].id);for(let p=0;p<u.tokens.length;p++)w.has(p)||i.add(u.tokens[p].id)}for(let d=0;d<n.length;d++)if(!l.has(d))for(let h of n[d].tokens)o.add(h.id);for(let d=0;d<t.length;d++)if(!c.has(d)){a.add(t[d].id);for(let h of t[d].tokens)i.add(h.id)}return{lines:t,removedIds:o,addedIds:i,newLineIds:a,fromColorById:s}}var H={name:"motion-canvas-default",defaultColor:"#d8dee9",rules:[{tag:e.keyword,color:"#5e81ac"},{tag:[e.name,e.deleted,e.character,e.propertyName,e.macroName],color:"#88c0d0"},{tag:[e.variableName],color:"#8fbcbb"},{tag:[e.function(e.variableName)],color:"#8fbcbb"},{tag:[e.labelName],color:"#81a1c1"},{tag:[e.color,e.constant(e.name),e.standard(e.name)],color:"#5e81ac"},{tag:[e.definition(e.name),e.separator],color:"#a3be8c"},{tag:[e.brace],color:"#8fbcbb"},{tag:[e.annotation],color:"#d30102"},{tag:[e.number,e.changed,e.annotation,e.modifier,e.self,e.namespace],color:"#b48ead"},{tag:[e.typeName,e.className],color:"#ECEFF4"},{tag:[e.operator,e.operatorKeyword],color:"#a3be8c"},{tag:[e.tagName],color:"#b48ead"},{tag:[e.squareBracket],color:"#ECEFF4"},{tag:[e.angleBracket],color:"#ECEFF4"},{tag:[e.attributeName],color:"#eceff4"},{tag:[e.regexp],color:"#5e81ac"},{tag:[e.quote],color:"#b48ead"},{tag:[e.string],color:"#a3be8c"},{tag:e.link,color:"#a3be8c"},{tag:[e.url,e.escape,e.special(e.string)],color:"#8fbcbb"},{tag:[e.meta],color:"#88c0d0"},{tag:[e.monospace],color:"#d8dee9"},{tag:[e.comment],color:"#4c566a"},{tag:e.strong,color:"#5e81ac"},{tag:e.emphasis,color:"#5e81ac"},{tag:e.heading,color:"#5e81ac"},{tag:e.special(e.heading1),color:"#5e81ac"},{tag:e.heading1,color:"#5e81ac"},{tag:[e.heading2,e.heading3,e.heading4],color:"#5e81ac"},{tag:[e.heading5,e.heading6],color:"#5e81ac"},{tag:[e.atom,e.bool,e.special(e.variableName)],color:"#d08770"},{tag:[e.processingInstruction,e.inserted],color:"#8fbcbb"},{tag:[e.contentSeparator],color:"#ebcb8b"},{tag:e.invalid,color:"#434c5e"}]},yt={name:"github-dark",defaultColor:"#c9d1d9",rules:[{tag:[e.standard(e.tagName),e.tagName],color:"#7ee787"},{tag:[e.comment,e.bracket],color:"#8b949e"},{tag:[e.className,e.propertyName],color:"#d2a8ff"},{tag:[e.variableName,e.attributeName,e.number,e.operator],color:"#79c0ff"},{tag:[e.keyword,e.typeName,e.typeOperator],color:"#ff7b72"},{tag:[e.string,e.meta,e.regexp],color:"#a5d6ff"},{tag:[e.name,e.quote],color:"#7ee787"},{tag:[e.heading,e.strong],color:"#d2a8ff"},{tag:[e.emphasis],color:"#d2a8ff"},{tag:[e.deleted],color:"#ffdcd7"},{tag:[e.atom,e.bool,e.special(e.variableName)],color:"#ffab70"},{tag:e.invalid,color:"#f97583"}]},kt={name:"github-light",defaultColor:"#24292e",rules:[{tag:[e.standard(e.tagName),e.tagName],color:"#116329"},{tag:[e.comment,e.bracket],color:"#6a737d"},{tag:[e.className,e.propertyName],color:"#6f42c1"},{tag:[e.variableName,e.attributeName,e.number,e.operator],color:"#005cc5"},{tag:[e.keyword,e.typeName,e.typeOperator],color:"#d73a49"},{tag:[e.string,e.meta,e.regexp],color:"#032f62"},{tag:[e.name,e.quote],color:"#22863a"},{tag:[e.heading,e.strong],color:"#24292e"},{tag:[e.emphasis],color:"#24292e"},{tag:[e.deleted],color:"#b31d28"},{tag:[e.atom,e.bool,e.special(e.variableName)],color:"#e36209"},{tag:[e.url,e.escape,e.regexp,e.link],color:"#032f62"},{tag:e.invalid,color:"#cb2431"}]},bt={name:"vscode-dark",defaultColor:"#9cdcfe",rules:[{tag:[e.keyword,e.operatorKeyword,e.modifier,e.color,e.constant(e.name),e.standard(e.name),e.standard(e.tagName),e.special(e.brace),e.atom,e.bool,e.special(e.variableName)],color:"#569cd6"},{tag:[e.controlKeyword,e.moduleKeyword],color:"#c586c0"},{tag:[e.name,e.deleted,e.character,e.macroName,e.propertyName,e.variableName,e.labelName,e.definition(e.name)],color:"#9cdcfe"},{tag:e.heading,color:"#9cdcfe"},{tag:[e.typeName,e.className,e.tagName,e.changed,e.annotation,e.self,e.namespace],color:"#4ec9b0"},{tag:[e.function(e.variableName),e.function(e.propertyName)],color:"#dcdcaa"},{tag:[e.number],color:"#b5cea8"},{tag:[e.operator,e.punctuation,e.separator,e.url,e.escape],color:"#d4d4d4"},{tag:[e.regexp],color:"#d16969"},{tag:[e.special(e.string),e.processingInstruction,e.string,e.inserted],color:"#ce9178"},{tag:[e.angleBracket],color:"#808080"},{tag:[e.meta,e.comment],color:"#6a9955"},{tag:e.link,color:"#6a9955"},{tag:e.invalid,color:"#ff0000"}]},wt={name:"vscode-light",defaultColor:"#383a42",rules:[{tag:[e.keyword,e.operatorKeyword,e.modifier,e.color,e.constant(e.name),e.standard(e.name),e.standard(e.tagName),e.special(e.brace),e.atom,e.bool,e.special(e.variableName)],color:"#0000ff"},{tag:[e.moduleKeyword,e.controlKeyword],color:"#af00db"},{tag:[e.name,e.deleted,e.character,e.macroName,e.propertyName,e.variableName,e.labelName,e.definition(e.name)],color:"#0070c1"},{tag:e.heading,color:"#0070c1"},{tag:[e.typeName,e.className,e.tagName,e.changed,e.annotation,e.self,e.namespace],color:"#267f99"},{tag:[e.function(e.variableName),e.function(e.propertyName)],color:"#795e26"},{tag:[e.number],color:"#098658"},{tag:[e.operator,e.punctuation,e.separator,e.url,e.escape],color:"#383a42"},{tag:[e.regexp],color:"#af00db"},{tag:[e.special(e.string),e.processingInstruction,e.string,e.inserted],color:"#a31515"},{tag:[e.angleBracket],color:"#383a42"},{tag:[e.meta,e.comment],color:"#008000"},{tag:e.link,color:"#4078f2"},{tag:e.invalid,color:"#e45649"}]},tt={"motion-canvas-default":H,"github-dark":yt,"github-light":kt,"vscode-dark":bt,"vscode-light":wt},mt=new Map;function et(n){let t=mt.get(n.name);if(t)return t;let o=ct(n.rules.map(i=>({tag:i.tag,class:i.color})));return mt.set(n.name,o),o}var $t={typescript:async()=>(await import("./chunks/dist-B46VH2YP.js")).parser.configure({dialect:"ts"}),tsx:async()=>(await import("./chunks/dist-B46VH2YP.js")).parser.configure({dialect:"ts jsx"}),javascript:async()=>(await import("./chunks/dist-B46VH2YP.js")).parser,jsx:async()=>(await import("./chunks/dist-B46VH2YP.js")).parser.configure({dialect:"jsx"}),python:async()=>(await import("./chunks/dist-W5ZXIMV7.js")).parser,json:async()=>(await import("./chunks/dist-3F5TQHM6.js")).parser,html:async()=>(await import("./chunks/dist-OXJDTPQ6.js")).parser,css:async()=>(await import("./chunks/dist-N4CNBNHL.js")).parser,rust:async()=>(await import("./chunks/dist-GPNEVCJI.js")).parser,go:async()=>(await import("./chunks/dist-FQDUBZKU.js")).parser,java:async()=>(await import("./chunks/dist-AQRNACF3.js")).parser,cpp:async()=>(await import("./chunks/dist-3SIR23P4.js")).parser,php:async()=>(await import("./chunks/dist-LRSXSDHT.js")).parser,markdown:async()=>(await import("./chunks/dist-FH6BHJ6A.js")).parser,xml:async()=>(await import("./chunks/dist-SH7H4MRK.js")).parser,yaml:async()=>(await import("./chunks/dist-UG3NTKWL.js")).parser},Ut={ts:"typescript",js:"javascript",py:"python","c++":"cpp",md:"markdown",yml:"yaml",shell:"javascript"};function Y(n){let t=n.toLowerCase();return Ut[t]??t}var j=new Map,nt=new Map,ot=[H.name],xt=["typescript","javascript","json","python"],St=new Map(Object.entries(tt));function Vt(n){St.set(n.name,n)}function Ct(n){return typeof n!="string"?n:St.get(n)??H}function qt(n){return j.has(Y(n))}function E(n=ot,t=xt){let o=[];for(let i of t){let a=Y(i);if(j.has(a))continue;let s=$t[a];if(!s)continue;let r=nt.get(a);r||(r=s().then(c=>(j.set(a,c),c)).catch(()=>null).finally(()=>nt.delete(a)),nt.set(a,r)),o.push(r)}return o.length===0?Promise.resolve():Promise.all(o).then(()=>{})}async function Xt(n,t){await E(ot,[n])}async function Jt(n=ot,t=xt){await E(n,t)}function O(n,t){return qt(n)}function Lt(n,t){return`${n}:${t}`}function Qt(n,t,o){let i=j.get(Y(t));if(!i)return null;let a=i.parse(n),s=et(o),r=new Map;return lt(a,s,(c,l,d)=>{let h=d;if(!h)return;let f=a.cursorAt(c,1);do r.set(Lt(f.from,f.to),h);while(f.next()&&f.to<=l)}),{tree:a,code:n,colorLookup:r}}function Zt(n,t){let o=t.tree.resolveInner(n,1),i=t.colorLookup.get(Lt(o.from,o.to));return i?{color:i,skipAhead:o.to-n}:{color:null,skipAhead:o.firstChild?0:o.to-n}}function te(n,t){let o=j.get(Y(t));if(!o)return[n];let a=o.parse(n).cursor(),s=[],r=0;do a.node.firstChild||(a.from>r&&s.push(n.slice(r,a.from)),a.from<a.to&&s.push(n.slice(a.from,a.to)),r=a.to);while(a.next());return r<n.length&&s.push(n.slice(r)),s}function vt(n,t,o=H){let i=Ct(o),a=Qt(n,t,i),s=[[]],r=()=>s.push([]);if(!a)return n.split(`
2
- `).map(l=>[{content:l,color:i.defaultColor}]);let c=0;for(let l of te(n,t)){let d=0;for(;d<l.length;){let{color:h,skipAhead:f}=Zt(c+d,a),u=d+Math.max(f,1);u>l.length&&(u=l.length);let g=l.indexOf(`
3
- `,d);g!==-1&&g<u&&(u=g);let k=l.slice(d,u);k.length>0&&s[s.length-1].push({content:k,color:h??i.defaultColor}),g===u&&(r(),u+=1),d=u}c+=l.length}return s}var ee=1,ne=1;function Nt(n,t){return{id:ee++,content:n,color:t}}function It(n){return{id:ne++,tokens:n}}function $(n,t,o){return O(t,o)?vt(n,t,o).map(i=>It(i.map(a=>Nt(a.content,a.color)))):n.split(`
4
- `).map(i=>It([Nt(i,"#d1d5db")]))}var _=class{cache=new Map;sig="";signature(t,o){return`${t}|${o}`}sync(t){t!==this.sig&&(this.cache.clear(),this.sig=t)}advance(t,o,i,a,s){if(o.length===0)return 0;let r=`${o}\0${s}`,c=this.cache.get(r);if(c!==void 0)return c;let{width:l}=t.measureText(o,i,a,void 0,s);return this.cache.set(r,l),l}};function Tt(n,t,o){return{startLine:n,startCol:t,endLine:n,endCol:o===void 0?1/0:t+o}}function Ht(n,t){return{startLine:n,startCol:1,endLine:t??n,endCol:1/0}}var U=class n{list;constructor(t=[]){this.list=t}lines(t,o){return new n([...this.list,Ht(t,o)])}word(t,o,i){return new n([...this.list,Tt(t,o,i)])}*[Symbol.iterator](){yield*this.list}},oe=new U;function R(n,t){if(t.length===0)return{start:0,end:0};let o=new Array(t.length),i=0;for(let p=0;p<t.length;p++)o[p]=i,i+=t[p]+1;let a=i>0?i-1:0,s=p=>Math.max(0,Math.min(t.length-1,p-1)),r=n.endLine??1/0,c=n.endCol??1/0,l=s(n.startLine),d=s(r),h=t[l],f=t[d],u=Math.max(0,Math.min(h,n.startCol-1)),g=c===1/0?f:Math.max(0,Math.min(f,c-1)),k=Math.min(a,o[l]+u),w=Math.min(a,o[d]+g);return{start:Math.min(k,w),end:Math.max(k,w)}}function it(n,t,o){let i=0,a=1,s=1,r=1,c=1,l=!1;for(let d=0;d<o.length;d++){let h=i,f=i+o[d];if(!l&&n>=h&&n<=f&&(a=d+1,s=n-h+1,l=!0),t>=h&&t<=f){r=d+1,c=t-h+1;break}i=f+1}return{startLine:a,startCol:s,endLine:r,endCol:c}}var x=function(n,t,o,i){var a=arguments.length,s=a<3?t:i===null?i=Object.getOwnPropertyDescriptor(t,o):i,r;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(n,t,o,i);else for(var c=n.length-1;c>=0;c--)(r=n[c])&&(s=(a<3?r(s):a>3?r(t,o,s):r(t,o))||s);return a>3&&s&&Object.defineProperty(t,o,s),s},y=class extends ae{tokenLines=[];tokenized=!1;transitions=[];advanceCache=new _;structureVersion=0;layoutCacheKey=null;layoutCache=null;highlightDimOpacity=null;highlightedIds=new Set;diffStrategy;phaseStrategy;constructor(t){super(t),this.diffStrategy=t.diffStrategy??Z,this.phaseStrategy=t.phaseStrategy??dt,this.applyProp("width",t.width??"hug"),this.applyProp("height",t.height??"hug"),E(void 0,[this.language]).catch(()=>{}),this.tokenize()}set(t){super.set(t),(t.code!==void 0||t.language!==void 0||t.theme!==void 0)&&(this.tokenized=!1)}tokenize(){this.setLines($(this.code,this.language,this.theme)),this.tokenized=O(this.language,this.theme)}setLines(t){this.tokenLines!==t&&(this.tokenLines=t,this.structureVersion++,this.layoutCache=null,this.layoutCacheKey=null)}declareAssets(t){super.declareAssets(t),t.font(this.fontFamily),t.loader(`shiki:lang:${this.language}`,ce(this.language),{gate:"layout"})}metrics(){return{fontSize:this.fontSize,fontFamily:this.fontFamily,lineHeight:this.lineHeight,letterSpacing:this.letterSpacing,padding:this.padding,showLineNumbers:this.showLineNumbers,lineNumberGap:this.lineNumberGap}}activeEdit(){for(let t=this.transitions.length-1;t>=0;t--){let o=this.transitions[t];if(o.kind==="structural")return o}return null}settledLayout(t,o){let i=`${this.structureVersion}|${W(t)}|${this.advanceCache.signature(t.fontSize,t.fontFamily)}`;if(this.layoutCache&&this.layoutCacheKey===i)return this.layoutCache;let a=B(this.tokenLines,t,this.advanceCache,o);return this.layoutCache=a,this.layoutCacheKey=i,a}frameLayout(t){let o=this.metrics(),i=this.activeEdit();if(!i){let s=this.settledLayout(o,t);return{from:s,to:s,edit:null}}let a=`${W(o)}|${this.advanceCache.signature(o.fontSize,o.fontFamily)}`;return(i.layoutKey!==a||!i.fromLayout||!i.toLayout)&&(i.fromLayout=B(i.from,o,this.advanceCache,t),i.toLayout=B(i.to,o,this.advanceCache,t),i.layoutKey=a),{from:i.fromLayout,to:i.toLayout,edit:i}}measure(t,o){this.advanceCache.sync(this.advanceCache.signature(this.fontSize,this.fontFamily));let i=this.width,a=this.height,{from:s,to:r,edit:c}=this.frameLayout(o),l=K(c),d=c?Ot(s.innerW,r.innerW,l):r.innerW,h=c?Ot(s.innerH,r.innerH,l):r.innerH,f=typeof i=="number"?i:i==="hug"?d+this.padding.left+this.padding.right:t.maxWidth??0,u=typeof a=="number"?a:a==="hug"?h+this.padding.top+this.padding.bottom:t.maxHeight??0;return{width:f,height:u}}renderContent(t){t.pushTextStyle(null);try{!this.tokenized&&!this.activeEdit()&&O(this.language,this.theme)&&this.tokenize(),super.renderContent(t)}finally{t.popTextStyle()}}renderSelf(t){this.drawSelf(t)}acceptsChild(t){return!1}clipSelf(){return new re().rect({width:this.layoutBounds.width,height:this.layoutBounds.height})}hitTestSelf(t,o){let i=this.hitLayout();if(!i)return super.hitTestSelf(t,o);if(!super.hitTestSelf(t,o))return!1;let a=this.fontSize*this.lineHeight/2,s=this.showLineNumbers?i.gutter:0,r=i.startX-s-o;for(let c=0;c<i.lineY.length;c++)if(!((i.lineW[c]??0)+s<=0)&&!(Math.abs(t.y-i.lineY[c])>a+o)&&t.x>=r&&t.x<=i.startX+(i.lineW[c]??0)+o)return!0;return!1}hitLayout(){if(!this.layoutCache||this.activeEdit())return null;let t=this.metrics(),o=`${this.structureVersion}|${W(t)}|${this.advanceCache.signature(t.fontSize,t.fontFamily)}`;return this.layoutCacheKey===o?this.layoutCache:null}append(t){let{code:o}=t.data;return this.editTo(this.joinedSource()+o,t.duration,t.easing)}prepend(t){let{code:o}=t.data;return this.editTo(o+this.joinedSource(),t.duration,t.easing)}insert(t){let{position:o,code:i}=t.data,a=this.joinedSource(),s=this.offsetAt(o);return this.editTo(a.slice(0,s)+i+a.slice(s),t.duration,t.easing)}erase(t){let{target:o}=t.data,{duration:i,easing:a}=t,s=this.joinedSource(),{start:r,end:c}=R(o,this.lineLengths()),l=r===0||s[r-1]===`
5
- `,d=c===s.length||s[c]===`
6
- `;if(l&&d)c<s.length?c+=1:r>0&&(r-=1);else if(c<=r)return A(i,()=>{});return c<=r?A(i,()=>{}):this.editTo(s.slice(0,r)+s.slice(c),i,a)}replace(t){let{target:o,replacement:i}=t.data,a=this.joinedSource(),{start:s,end:r}=R(o,this.lineLengths());return this.editTo(a.slice(0,s)+i+a.slice(r),t.duration,t.easing)}highlight(t){let{target:o,dim:i}=t.data,{duration:a,easing:s}=t,r=i??.4,c=this.tokenIdsInRanges(se(o));if(c.size===0)return A(a,()=>{});let l=this.highlightDimOpacity??1,d=this.highlightedIds.size>0,h=this.highlightedIds,f=[];for(let u of this.tokenLines)for(let g of u.tokens){let k=!d||h.has(g.id),w=c.has(g.id),p=k?1:l,C=w?1:r;p!==C&&f.push(X(g.id,{keys:[0,1],values:[p,C]}))}return this.runDim(f,a,s,u=>{this.highlightDimOpacity=u?r:d?l:null,this.highlightedIds=u?c:h})}resetHighlight(t){let{duration:o,easing:i}=t;if(this.highlightDimOpacity===null)return A(o,()=>{});let a=this.highlightDimOpacity,s=this.highlightedIds,r=[];for(let c of this.tokenLines)for(let l of c.tokens){let d=s.has(l.id)?1:a;d!==1&&r.push(X(l.id,{keys:[0,1],values:[d,1]}))}return this.runDim(r,o,i,c=>{this.highlightDimOpacity=c?null:a,this.highlightedIds=c?new Set:s})}editTo(t,o,i){let a=this.tokenLines,s=this.joinedSource();if(t===s)return A(o,()=>{});let r=this.diffStrategy(a,$(t,this.language,this.theme)),c={kind:"structural",from:a,to:r.lines,removedIds:r.removedIds,addedIds:r.addedIds,enteringLineIds:r.newLineIds,fromColorById:r.fromColorById,phases:this.phaseStrategy(r.removedIds.size>0,r.addedIds.size>0),progress:0,layoutKey:null,fromLayout:null,toLayout:null};return this.tokenized=O(this.language,this.theme),A(o,l=>{let d=l>0&&l<1,h=this.transitions.indexOf(c);d&&h<0?this.transitions.push(c):!d&&h>=0&&this.transitions.splice(h,1),c.progress=i?i(l):l,l<=0?(this.setLines(a),this._writeProp("code",s)):(this.setLines(r.lines),this._writeProp("code",t))})}runDim(t,o,i,a){let s={kind:"dim",tokens:t,progress:0};return A(o,r=>{let c=r>0&&r<1,l=this.transitions.indexOf(s);c&&l<0?this.transitions.push(s):!c&&l>=0&&this.transitions.splice(l,1),s.progress=i?i(r):r,a?.(r>=1)})}_prepareStep(t,o,i){let a=t.code;if(typeof a!="string"||a===this.joinedSource())return super._prepareStep(t,o,i);let s={...t};delete s.code;let r=super._prepareStep(s,o,i),c=this.editTo(a,o,i)._stepper();return{seek:l=>{r.seek(l),c.seek(l)},advance:l=>{let d=r.advance(l),h=c.advance(l);return d&&h}}}findAllRanges(t){let o=[];if(!t)return o;let i=this.joinedSource(),a=this.lineLengths(),s=0;for(;;){let r=i.indexOf(t,s);if(r===-1)break;o.push(it(r,r+t.length,a)),s=r+Math.max(1,t.length)}return o}findRangeAt(t,o){return this.findAllRanges(t)[o]??null}findFirstRange(t){return this.findRangeAt(t,0)}joinedSource(){return this.tokenLines.map(t=>t.tokens.map(o=>o.content).join("")).join(`
7
- `)}lineLengths(){return this.tokenLines.map(t=>t.tokens.reduce((o,i)=>o+i.content.length,0))}offsetAt(t){let o=this.lineLengths();if(o.length===0)return 0;let[i,a]=t,s=Math.max(0,Math.min(o.length-1,i-1)),r=0;for(let c=0;c<s;c++)r+=o[c]+1;return r+Math.max(0,Math.min(o[s],a-1))}tokenIdsInRanges(t){let o=new Set,i=this.lineLengths();if(i.length===0)return o;let a=t.map(r=>R(r,i)).filter(({start:r,end:c})=>c>r);if(a.length===0)return o;let s=0;for(let r=0;r<this.tokenLines.length;r++){let c=this.tokenLines[r];for(let l of c.tokens){let d=s,h=s+l.content.length;a.some(({start:f,end:u})=>h>f&&d<u)&&o.add(l.id),s=h}r<this.tokenLines.length-1&&(s+=1)}return o}drawSelf(t){this.advanceCache.sync(this.advanceCache.signature(this.fontSize,this.fontFamily)),Q(t,{tokenLines:this.tokenLines,metrics:this.metrics(),advanceCache:this.advanceCache,...this.frameLayout(t),tokenStates:ht(this.tokenLines,this.transitions,this.highlightDimOpacity,this.highlightedIds),highlightActive:this.highlightDimOpacity!==null||this.transitions.some(o=>o.kind==="dim")})}};x([N({default:""})],y.prototype,"code",void 0);x([N({default:"typescript"})],y.prototype,"language",void 0);x([N({default:"Fira Mono"})],y.prototype,"fontFamily",void 0);x([N({default:H.name})],y.prototype,"theme",void 0);x([N({default:16})],y.prototype,"fontSize",void 0);x([N({default:1.6})],y.prototype,"lineHeight",void 0);x([N({default:1.1})],y.prototype,"letterSpacing",void 0);x([N({default:!1})],y.prototype,"showLineNumbers",void 0);x([N({default:2})],y.prototype,"lineNumberGap",void 0);x([N({default:0,mapper:Mt.resolve,tween:Mt.lerp})],y.prototype,"padding",void 0);x([F({args:[{key:"code",kind:"text",multiline:!0}]})],y.prototype,"append",null);x([F({args:[{key:"code",kind:"text",multiline:!0}]})],y.prototype,"prepend",null);x([F({args:[{key:"position",kind:"point",properties:{line:{kind:"number",default:1,min:1,step:1},col:{kind:"number",default:1,min:1,step:1}}},{key:"code",kind:"text",default:"",multiline:!0}]})],y.prototype,"insert",null);x([F({key:"remove",args:[{key:"target",kind:"selector"}]})],y.prototype,"erase",null);x([F({args:[{key:"target",kind:"selector"},{key:"replacement",kind:"text",default:"",multiline:!0}]})],y.prototype,"replace",null);x([F({args:[{key:"target",kind:"selector"},{key:"dim",kind:"number",default:.4,min:0,max:1,step:.01,scale:100,unit:"%"}]})],y.prototype,"highlight",null);x([F()],y.prototype,"resetHighlight",null);y=x([ie({key:"code",parentKey:"node",forkable:!0,layout:{defaultWidthMode:"hug",defaultHeightMode:"hug",acceptsChildren:!1}})],y);function se(n){return typeof n[Symbol.iterator]=="function"?[...n]:[n]}var At=new Map;function ce(n){let t=At.get(n);return t===void 0&&(t=()=>E(void 0,[n]),At.set(n,t)),t}var le=[y];export{tt as BUILTIN_THEMES,y as Code,U as CodeRangeChain,oe as CodeRanges,H as DefaultHighlightStyle,yt as GithubDarkStyle,kt as GithubLightStyle,le as NODES,_ as TokenAdvanceCache,bt as VscodeDarkStyle,wt as VscodeLightStyle,O as canHighlight,it as charOffsetsToRange,et as compileStyle,Z as defaultCodeDiff,dt as defaultCodePhases,Q as drawCode,E as ensureHighlighter,Jt as initSyntaxHighlighter,B as layoutCode,Ht as lines,Xt as loadCodeLanguage,X as makeAnim,W as metricsSignature,K as moveProgress,Et as phasesFor,R as rangeToCharOffsets,Vt as registerCodeTheme,Ct as resolveTheme,ht as resolveTokenStates,Ft as sampleCurve,zt as smoothstep,$ as tokenizeCodeToIdLines,G as windowProgress,Tt as word};
1
+ import{j as ft,k as gt,l as e}from"./chunks/chunk-SYZUZB3M.js";import{node as me,Clip as ye,Node2D as ke,property as O,insetsProperty as we,lerpNumber as Bt,colorOps as be,command as E,driveCommand as _}from"@motionscript/sdk";function Wt(o,t,n){if(n<=o[0])return t[0];if(n>=o[o.length-1])return t[t.length-1];for(let i=0;i<o.length-1;i++)if(n<=o[i+1]){let s=o[i+1]-o[i],r=s===0?0:(n-o[i])/s;return t[i]+(t[i+1]-t[i])*r}return t[t.length-1]}function G(o,t){if(!o)return 1;let[n,i]=o;return t<=n?0:t>=i||i===n?1:(t-n)/(i-n)}function Pt(o){return o*o*(3-2*o)}function Z(o,t){return{id:o,opacity:t.values,opacityKeys:t.keys}}function Yt(o,t){return o&&t?{out:[0,.38],move:[.1,.68],in:[.52,1]}:o?{out:[0,.45],move:[.22,1],in:null}:t?{out:null,move:[0,.55],in:[.38,1]}:{out:null,move:[0,1],in:null}}var pt=Yt;function $(o){return o?Pt(G(o.phases.move,o.progress)):1}function mt(o,t,n,i){let s=new Map;if(n!==null){let r=n;for(let a of o)for(let l of a.tokens)s.set(l.id,{opacity:i.has(l.id)?1:r})}for(let r of t)if(r.kind==="dim")for(let a of r.tokens)s.set(a.id,{opacity:Wt(a.opacityKeys,a.opacity,r.progress)});return s}function W(o){let t=o.padding;return[o.fontSize,o.fontFamily,o.lineHeight,o.letterSpacing,t.left,t.right,t.top,t.bottom,o.showLineNumbers?1:0,o.lineNumberGap].join("|")}function Kt(o,t,n){return n.advance(o," ",t.fontSize,t.fontFamily,0)*t.lineNumberGap}function Ut(o,t,n,i,s){if(!t.showLineNumbers)return 0;let r=String(Math.max(1,i));return n.advance(o,r,t.fontSize,t.fontFamily,0)+s}function P(o,t,n,i){let s=t.fontSize*t.lineHeight,r=t.showLineNumbers?Kt(i,t,n):0,a=Ut(i,t,n,o.length,r),l=new Array(o.length),c=0;for(let S=0;S<o.length;S++){let k=0;for(let L of o[S].tokens)k+=n.advance(i,L.content,t.fontSize,t.fontFamily,t.letterSpacing);l[S]=k,k>c&&(c=k)}let h=c+a,u=o.length*s,d=h+t.padding.left+t.padding.right,f=u+t.padding.top+t.padding.bottom,m=-d/2+t.padding.left+a,g=f/2-t.padding.top,p=new Map,y=new Array(o.length),w=new Map;for(let S=0;S<o.length;S++){let k=g-S*s-s/2;y[S]=k,w.set(o[S].id,S);let L=m;for(let C of o[S].tokens)p.set(C.id,{x:L,y:k}),L+=n.advance(i,C.content,t.fontSize,t.fontFamily,t.letterSpacing)}return{tokens:p,lineY:y,lineW:l,lineIndex:w,gutter:a,gutterGap:r,innerW:h,innerH:u,blockW:d,blockH:f,startX:m}}import{Graphics2D as nt,parseColor as Vt,lerpNumber as I}from"@motionscript/sdk";var qt=[.82,.84,.86,1],Xt=[.45,.5,.55,1],yt=new Map;function tt(o){if(!o)return qt;let t=yt.get(o);return t||(t=Vt(o),yt.set(o,t)),t}function kt(o,t,n){return n<=0?o:n>=1?t:[o[0]+(t[0]-o[0])*n,o[1]+(t[1]-o[1])*n,o[2]+(t[2]-o[2])*n,o[3]+(t[3]-o[3])*n]}function Jt(o,t,n){if(!n)return 1;let i=1;for(let s of o.tokens){if(s.content.length===0)continue;let r=t.get(s.id)?.opacity??1;r<i&&(i=r)}return i}function ot(o,t){let{tokenLines:n,metrics:i,advanceCache:s,from:r,to:a,edit:l,tokenStates:c}=t,h=l?l.progress:1,u=l?G(l.phases.out,h):1,d=$(l),f=l?G(l.phases.in,h):1,m=l?I(r.blockW,a.blockW,d):a.blockW,g=l?I(r.gutter,a.gutter,d):a.gutter,p=a.gutterGap||r.gutterGap,y=-m/2+i.padding.left+g-p;Qt(o,t,Math.max(m,t.boxW??0),d);let w=(k,L,C)=>{if(C<=0)return;let N=s.advance(o,k,i.fontSize,i.fontFamily,0);o.draw(new nt().text({text:k,fontSize:i.fontSize,fontFamily:i.fontFamily,lineHeight:i.lineHeight,x:y-N/2,y:L,textAlign:"left"}).fill([{type:"solid",color:Xt,opacity:C}]))},S=(k,L,C,N,H)=>{if(H<=0||k.length===0)return;let T=s.advance(o,k,i.fontSize,i.fontFamily,i.letterSpacing);o.draw(new nt().text({text:k,fontSize:i.fontSize,fontFamily:i.fontFamily,lineHeight:i.lineHeight,letterSpacing:i.letterSpacing,x:L+T/2,y:C,textAlign:"left"}).fill([{type:"solid",color:N,opacity:H}]))};for(let k=0;k<n.length;k++){let L=n[k],C=a.lineIndex.get(L.id);if(C===void 0)continue;let N=a.lineY[C],H=l?.enteringLineIds.has(L.id)??!1,T=N,D=1;if(l&&H)D=f;else if(l){let v=r.lineIndex.get(L.id);v!==void 0&&(T=I(r.lineY[v],N,d))}for(let v of L.tokens){let J=a.tokens.get(v.id);if(!J)continue;let ht=J.x,dt=D,Q=tt(v.color);if(l&&!H)if(l.addedIds.has(v.id))dt=f;else{let ut=r.tokens.get(v.id);ut&&(ht=I(ut.x,J.x,d)),l.fromColorById.has(v.id)&&(Q=kt(tt(l.fromColorById.get(v.id)),Q,d))}S(v.content,ht,T,Q,dt*(c.get(v.id)?.opacity??1))}}if(l&&u<1)for(let k=0;k<l.from.length;k++){let L=l.from[k],C=r.lineIndex.get(L.id);if(C===void 0)continue;let N=a.lineIndex.get(L.id),H=N===void 0?r.lineY[C]:I(r.lineY[C],a.lineY[N],d);for(let T of L.tokens){if(!l.removedIds.has(T.id))continue;let D=r.tokens.get(T.id);D&&S(T.content,D.x,H,tt(T.color),1-u)}}i.showLineNumbers&&Zt(t,w,d,f,u)}function et(o,t,n){let{from:i,to:s,metrics:r}=t,a=r.fontSize*r.lineHeight/2,l=u=>{let d=s.lineIndex.get(u),f=i.lineIndex.get(u);return d!==void 0&&f!==void 0?I(i.lineY[f],s.lineY[d],n):d!==void 0?s.lineY[d]:f===void 0?null:i.lineY[f]},c=l(o.startId),h=l(o.endId);return c===null&&h===null?null:{top:(c??h)+a,bottom:(h??c)-a}}function Qt(o,t,n,i){let{rowBands:s=[],rowsEdit:r=null}=t,a=(c,h,u,d,f)=>{f<=0||c<=h||o.draw(new nt().rect({x:0,y:(c+h)/2,width:n,height:c-h,cornerRadius:d}).fill([{type:"solid",color:u,opacity:f}]))};if(!r){for(let c of s){let h=et(c,t,i);h&&a(h.top,h.bottom,c.color,c.radius,1)}return}let l=r.progress;for(let c=0;c<Math.max(r.from.length,r.to.length);c++){let h=r.from[c],u=r.to[c],d=h?et(h,t,i):null,f=u?et(u,t,i):null;d&&f?a(I(d.top,f.top,l),I(d.bottom,f.bottom,l),kt(h.color,u.color,l),I(h.radius,u.radius,l),1):d?a(d.top,d.bottom,h.color,h.radius,1-l):f&&a(f.top,f.bottom,u.color,u.radius,l)}}function Zt(o,t,n,i,s){let{tokenLines:r,from:a,to:l,edit:c,tokenStates:h,highlightActive:u}=o,d=r.length,f=c?c.from.length:d;for(let m=0;m<Math.max(f,d);m++){let g=m<f,p=m<d,y=p?r[m]:c?.from[m],w=y?Jt(y,h,u):1;c?g&&p?t(String(m+1),I(a.lineY[m],l.lineY[m],n),w):p?t(String(m+1),l.lineY[m],i*w):t(String(m+1),a.lineY[m],(1-s)*w):t(String(m+1),l.lineY[m],w)}}function Y(o){return o.content.trim().length}function wt(o){let t=0;for(let n of o.tokens)t+=Y(n);return t}function te(o,t){let n=wt(o),i=wt(t);if(n===0&&i===0)return 1;if(n===0||i===0)return 0;let s=new Map;for(let a of o.tokens)Y(a)!==0&&s.set(a.content,(s.get(a.content)??0)+1);let r=0;for(let a of t.tokens){let l=Y(a);if(l===0)continue;let c=s.get(a.content)??0;c>0&&(s.set(a.content,c-1),r+=l)}return 2*r/(n+i)}function St(o,t,n){let i=t+1,s=new Float64Array((o+1)*i),r=new Float64Array(o*t);for(let h=1;h<=o;h++)for(let u=1;u<=t;u++){let d=n(h-1,u-1);r[(h-1)*t+(u-1)]=d;let f=s[(h-1)*i+u],m=s[h*i+(u-1)],g=f>m?f:m;if(d>0){let p=s[(h-1)*i+(u-1)]+d;p>g&&(g=p)}s[h*i+u]=g}let a=[],l=o,c=t;for(;l>0&&c>0;){let h=r[(l-1)*t+(c-1)];h>0&&s[l*i+c]===s[(l-1)*i+(c-1)]+h?(a.push([l-1,c-1]),l--,c--):s[(l-1)*i+c]>=s[l*i+(c-1)]?l--:c--}return a.reverse(),a}function ee(o,t){return St(o.length,t.length,(n,i)=>o[n].content!==t[i].content?0:Y(t[i])||.25)}function ne(o,t){if(o.tokens.length!==t.tokens.length)return!1;for(let n=0;n<o.tokens.length;n++)if(o.tokens[n].content!==t.tokens[n].content)return!1;return!0}function bt(o){let t="";for(let n of o.tokens)t+=n.content+"";return t}function oe(o,t){let n=o.map(bt),i=t.map(bt),s=[],r=0;for(;r<o.length&&r<t.length&&n[r]===i[r];)s.push([r,r]),r++;let a=0;for(;a<o.length-r&&a<t.length-r&&n[o.length-1-a]===i[t.length-1-a];)a++;let l=ie(n,i,r,o.length-a,r,t.length-a),c=16e4,h=r,u=r;for(let[d,f]of[...l,[o.length-a,t.length-a]]){let m=d-h,g=f-u,p=m*g;if(p>0&&p<=4e4&&p<=c){c-=p;for(let[y,w]of St(m,g,(S,k)=>te(o[h+S],t[u+k])-.45))s.push([h+y,u+w])}d<o.length-a&&s.push([d,f]),h=d+1,u=f+1}for(let d=a;d>0;d--)s.push([o.length-d,t.length-d]);return s}function ie(o,t,n,i,s,r){let a=new Map,l=new Set;for(let g=n;g<i;g++){let p=o[g];l.has(p)?a.delete(p):a.set(p,g),l.add(p)}let c=new Map,h=new Set;for(let g=s;g<r;g++){let p=t[g];h.has(p)?c.delete(p):c.set(p,g),h.add(p)}let u=[];for(let g=s;g<r;g++){let p=a.get(t[g]);p!==void 0&&c.get(t[g])===g&&t[g].replaceAll("","").trim()!==""&&u.push([p,g])}let d=[],f=new Array(u.length).fill(-1);for(let g=0;g<u.length;g++){let p=0,y=d.length;for(;p<y;){let w=p+y>>1;u[d[w]][0]<u[g][0]?p=w+1:y=w}p>0&&(f[g]=d[p-1]),d[p]=g}let m=[];for(let g=d.length>0?d[d.length-1]:-1;g>=0;g=f[g])m.push(u[g]);return m.reverse()}function it(o,t){let n=new Set,i=new Set,s=new Set,r=new Map,a=oe(o,t),l=new Set,c=new Set;for(let[h,u]of a){c.add(h),l.add(u);let d=o[h],f=t[u];f.id=d.id;let m=ne(d,f)?d.tokens.map((y,w)=>[w,w]):ee(d.tokens,f.tokens),g=new Set,p=new Set;for(let[y,w]of m){g.add(y),p.add(w);let S=d.tokens[y],k=f.tokens[w];k.id=S.id,S.color!==k.color&&r.set(S.id,S.color)}for(let y=0;y<d.tokens.length;y++)g.has(y)||n.add(d.tokens[y].id);for(let y=0;y<f.tokens.length;y++)p.has(y)||i.add(f.tokens[y].id)}for(let h=0;h<o.length;h++)if(!c.has(h))for(let u of o[h].tokens)n.add(u.id);for(let h=0;h<t.length;h++)if(!l.has(h)){s.add(t[h].id);for(let u of t[h].tokens)i.add(u.id)}return{lines:t,removedIds:n,addedIds:i,newLineIds:s,fromColorById:r}}var A={name:"motion-canvas-default",defaultColor:"#d8dee9",rules:[{tag:e.keyword,color:"#5e81ac"},{tag:[e.name,e.deleted,e.character,e.propertyName,e.macroName],color:"#88c0d0"},{tag:[e.variableName],color:"#8fbcbb"},{tag:[e.function(e.variableName)],color:"#8fbcbb"},{tag:[e.labelName],color:"#81a1c1"},{tag:[e.color,e.constant(e.name),e.standard(e.name)],color:"#5e81ac"},{tag:[e.definition(e.name),e.separator],color:"#a3be8c"},{tag:[e.brace],color:"#8fbcbb"},{tag:[e.annotation],color:"#d30102"},{tag:[e.number,e.changed,e.annotation,e.modifier,e.self,e.namespace],color:"#b48ead"},{tag:[e.typeName,e.className],color:"#ECEFF4"},{tag:[e.operator,e.operatorKeyword],color:"#a3be8c"},{tag:[e.tagName],color:"#b48ead"},{tag:[e.squareBracket],color:"#ECEFF4"},{tag:[e.angleBracket],color:"#ECEFF4"},{tag:[e.attributeName],color:"#eceff4"},{tag:[e.regexp],color:"#5e81ac"},{tag:[e.quote],color:"#b48ead"},{tag:[e.string],color:"#a3be8c"},{tag:e.link,color:"#a3be8c"},{tag:[e.url,e.escape,e.special(e.string)],color:"#8fbcbb"},{tag:[e.meta],color:"#88c0d0"},{tag:[e.monospace],color:"#d8dee9"},{tag:[e.comment],color:"#4c566a"},{tag:e.strong,color:"#5e81ac"},{tag:e.emphasis,color:"#5e81ac"},{tag:e.heading,color:"#5e81ac"},{tag:e.special(e.heading1),color:"#5e81ac"},{tag:e.heading1,color:"#5e81ac"},{tag:[e.heading2,e.heading3,e.heading4],color:"#5e81ac"},{tag:[e.heading5,e.heading6],color:"#5e81ac"},{tag:[e.atom,e.bool,e.special(e.variableName)],color:"#d08770"},{tag:[e.processingInstruction,e.inserted],color:"#8fbcbb"},{tag:[e.contentSeparator],color:"#ebcb8b"},{tag:e.invalid,color:"#434c5e"}]},Lt={name:"github-dark",defaultColor:"#c9d1d9",rules:[{tag:[e.standard(e.tagName),e.tagName],color:"#7ee787"},{tag:[e.comment,e.bracket],color:"#8b949e"},{tag:[e.className,e.propertyName],color:"#d2a8ff"},{tag:[e.variableName,e.attributeName,e.number,e.operator],color:"#79c0ff"},{tag:[e.keyword,e.typeName,e.typeOperator],color:"#ff7b72"},{tag:[e.string,e.meta,e.regexp],color:"#a5d6ff"},{tag:[e.name,e.quote],color:"#7ee787"},{tag:[e.heading,e.strong],color:"#d2a8ff"},{tag:[e.emphasis],color:"#d2a8ff"},{tag:[e.deleted],color:"#ffdcd7"},{tag:[e.atom,e.bool,e.special(e.variableName)],color:"#ffab70"},{tag:e.invalid,color:"#f97583"}]},Ct={name:"github-light",defaultColor:"#24292e",rules:[{tag:[e.standard(e.tagName),e.tagName],color:"#116329"},{tag:[e.comment,e.bracket],color:"#6a737d"},{tag:[e.className,e.propertyName],color:"#6f42c1"},{tag:[e.variableName,e.attributeName,e.number,e.operator],color:"#005cc5"},{tag:[e.keyword,e.typeName,e.typeOperator],color:"#d73a49"},{tag:[e.string,e.meta,e.regexp],color:"#032f62"},{tag:[e.name,e.quote],color:"#22863a"},{tag:[e.heading,e.strong],color:"#24292e"},{tag:[e.emphasis],color:"#24292e"},{tag:[e.deleted],color:"#b31d28"},{tag:[e.atom,e.bool,e.special(e.variableName)],color:"#e36209"},{tag:[e.url,e.escape,e.regexp,e.link],color:"#032f62"},{tag:e.invalid,color:"#cb2431"}]},vt={name:"vscode-dark",defaultColor:"#9cdcfe",rules:[{tag:[e.keyword,e.operatorKeyword,e.modifier,e.color,e.constant(e.name),e.standard(e.name),e.standard(e.tagName),e.special(e.brace),e.atom,e.bool,e.special(e.variableName)],color:"#569cd6"},{tag:[e.controlKeyword,e.moduleKeyword],color:"#c586c0"},{tag:[e.name,e.deleted,e.character,e.macroName,e.propertyName,e.variableName,e.labelName,e.definition(e.name)],color:"#9cdcfe"},{tag:e.heading,color:"#9cdcfe"},{tag:[e.typeName,e.className,e.tagName,e.changed,e.annotation,e.self,e.namespace],color:"#4ec9b0"},{tag:[e.function(e.variableName),e.function(e.propertyName)],color:"#dcdcaa"},{tag:[e.number],color:"#b5cea8"},{tag:[e.operator,e.punctuation,e.separator,e.url,e.escape],color:"#d4d4d4"},{tag:[e.regexp],color:"#d16969"},{tag:[e.special(e.string),e.processingInstruction,e.string,e.inserted],color:"#ce9178"},{tag:[e.angleBracket],color:"#808080"},{tag:[e.meta,e.comment],color:"#6a9955"},{tag:e.link,color:"#6a9955"},{tag:e.invalid,color:"#ff0000"}]},_t={name:"vscode-light",defaultColor:"#383a42",rules:[{tag:[e.keyword,e.operatorKeyword,e.modifier,e.color,e.constant(e.name),e.standard(e.name),e.standard(e.tagName),e.special(e.brace),e.atom,e.bool,e.special(e.variableName)],color:"#0000ff"},{tag:[e.moduleKeyword,e.controlKeyword],color:"#af00db"},{tag:[e.name,e.deleted,e.character,e.macroName,e.propertyName,e.variableName,e.labelName,e.definition(e.name)],color:"#0070c1"},{tag:e.heading,color:"#0070c1"},{tag:[e.typeName,e.className,e.tagName,e.changed,e.annotation,e.self,e.namespace],color:"#267f99"},{tag:[e.function(e.variableName),e.function(e.propertyName)],color:"#795e26"},{tag:[e.number],color:"#098658"},{tag:[e.operator,e.punctuation,e.separator,e.url,e.escape],color:"#383a42"},{tag:[e.regexp],color:"#af00db"},{tag:[e.special(e.string),e.processingInstruction,e.string,e.inserted],color:"#a31515"},{tag:[e.angleBracket],color:"#383a42"},{tag:[e.meta,e.comment],color:"#008000"},{tag:e.link,color:"#4078f2"},{tag:e.invalid,color:"#e45649"}]},K={"motion-canvas-default":A,"github-dark":Lt,"github-light":Ct,"vscode-dark":vt,"vscode-light":_t},xt=new WeakMap;function rt(o){let t=xt.get(o);if(t)return t;let n=ft(o.rules.map(i=>({tag:i.tag,class:i.color})));return xt.set(o,n),n}var It={typescript:async()=>(await import("./chunks/dist-B46VH2YP.js")).parser.configure({dialect:"ts"}),tsx:async()=>(await import("./chunks/dist-B46VH2YP.js")).parser.configure({dialect:"ts jsx"}),javascript:async()=>(await import("./chunks/dist-B46VH2YP.js")).parser,jsx:async()=>(await import("./chunks/dist-B46VH2YP.js")).parser.configure({dialect:"jsx"}),python:async()=>(await import("./chunks/dist-W5ZXIMV7.js")).parser,json:async()=>(await import("./chunks/dist-3F5TQHM6.js")).parser,html:async()=>(await import("./chunks/dist-OXJDTPQ6.js")).parser,css:async()=>(await import("./chunks/dist-N4CNBNHL.js")).parser,rust:async()=>(await import("./chunks/dist-GPNEVCJI.js")).parser,go:async()=>(await import("./chunks/dist-FQDUBZKU.js")).parser,java:async()=>(await import("./chunks/dist-AQRNACF3.js")).parser,cpp:async()=>(await import("./chunks/dist-3SIR23P4.js")).parser,php:async()=>(await import("./chunks/dist-LRSXSDHT.js")).parser,markdown:async()=>(await import("./chunks/dist-FH6BHJ6A.js")).parser,xml:async()=>(await import("./chunks/dist-SH7H4MRK.js")).parser,yaml:async()=>(await import("./chunks/dist-UG3NTKWL.js")).parser},Tt={ts:"typescript",js:"javascript",py:"python","c++":"cpp",md:"markdown",yml:"yaml",shell:"javascript"},re=new Set(["","text","plaintext"]),Nt=new Set;function at(o,t,n){let i=`${o}:${t}`;Nt.has(i)||(Nt.add(i),console.warn(`[Code] ${n}`))}function M(o){return o.indexOf("\r")===-1?o:o.replace(/\r\n?/g,`
2
+ `)}function U(o){let t=o.toLowerCase();return Tt[t]??t}var j=new Map,st=new Map,lt=[A.name],At=["typescript","javascript","json","python"],Ot=new Map(Object.entries(K));function se(o){Ot.set(o.name,o)}function V(o){if(typeof o!="string")return o;let t=Ot.get(o);return t||(at("theme",o,`unknown theme "${o}"; using "${A.name}". Built-in themes: ${Object.keys(K).join(", ")}; register others with registerCodeTheme.`),A)}function ae(o){return j.has(U(o))}function F(o=lt,t=At){let n=[];for(let i of t){let s=U(i);if(j.has(s))continue;let r=It[s];if(!r){re.has(s)||at("language",s,`no grammar for language "${i}"; drawing it as plain text. Supported: ${Object.keys(It).join(", ")} (aliases: ${Object.keys(Tt).join(", ")}).`);continue}let a=st.get(s);a||(a=r().then(l=>(j.set(s,l),l)).catch(l=>(at("load",s,`could not load the "${i}" grammar; drawing it as plain text: ${l instanceof Error?l.message:String(l)}`),null)).finally(()=>st.delete(s)),st.set(s,a)),n.push(a)}return n.length===0?Promise.resolve():Promise.all(n).then(()=>{})}async function le(o,t){await F(lt,[o])}async function ce(o=lt,t=At){await F(o,t)}function B(o,t){return ae(o)}function Et(o,t){return`${o}:${t}`}function he(o,t,n){let i=j.get(U(t));if(!i)return null;let s=i.parse(o),r=rt(n),a=new Map;return gt(s,r,(l,c,h)=>{let u=h;if(!u)return;let d=s.cursorAt(l,1);do a.set(Et(d.from,d.to),u);while(d.next()&&d.to<=c)}),{tree:s,code:o,colorLookup:a}}function de(o,t){let n=t.tree.resolveInner(o,1),i=t.colorLookup.get(Et(n.from,n.to));return i?{color:i,skipAhead:n.to-o}:{color:null,skipAhead:n.firstChild?0:n.to-o}}function ue(o,t){let n=j.get(U(t));if(!n)return[o];let s=n.parse(o).cursor(),r=[],a=0;do s.node.firstChild||(s.from>a&&r.push(o.slice(a,s.from)),s.from<s.to&&r.push(o.slice(s.from,s.to)),a=s.to);while(s.next());return a<o.length&&r.push(o.slice(a)),r}function Mt(o,t,n=A){o=M(o);let i=V(n),s=he(o,t,i),r=[[]],a=()=>r.push([]);if(!s)return o.split(`
3
+ `).map(c=>[{content:c,color:i.defaultColor}]);let l=0;for(let c of ue(o,t)){let h=0;for(;h<c.length;){let{color:u,skipAhead:d}=de(l+h,s),f=h+Math.max(d,1);f>c.length&&(f=c.length);let m=c.indexOf(`
4
+ `,h);m!==-1&&m<f&&(f=m);let g=c.slice(h,f);g.length>0&&r[r.length-1].push({content:g,color:u??i.defaultColor}),m===f&&(a(),f+=1),h=f}l+=c.length}return r}var fe=1,ge=1;function Ht(o,t){return{id:fe++,content:o,color:t}}function Ft(o){return{id:ge++,tokens:o}}function q(o,t,n){return o=M(o),B(t,n)?Mt(o,t,n).map(i=>Ft(i.map(s=>Ht(s.content,s.color)))):(V(n),o.split(`
5
+ `).map(i=>Ft([Ht(i,"#d1d5db")])))}var R=class{cache=new Map;sig="";signature(t,n){return`${t}|${n}`}sync(t){t!==this.sig&&(this.cache.clear(),this.sig=t)}advance(t,n,i,s,r){if(n.length===0)return 0;let a=`${n}\0${r}`,l=this.cache.get(a);if(l!==void 0)return l;let{width:c}=t.measureText(n,i,s,void 0,r);return this.cache.set(a,c),c}};function Dt(o,t,n){return{startLine:o,startCol:t,endLine:o,endCol:n===void 0?1/0:t+n}}function jt(o,t){return{startLine:o,startCol:1,endLine:t??o,endCol:1/0}}var X=class o{list;constructor(t=[]){this.list=t}lines(t,n){return new o([...this.list,jt(t,n)])}word(t,n,i){return new o([...this.list,Dt(t,n,i)])}*[Symbol.iterator](){yield*this.list}toJSON(){return this.list}},pe=new X;function z(o,t){if(t.length===0)return{start:0,end:0};let n=new Array(t.length),i=0;for(let y=0;y<t.length;y++)n[y]=i,i+=t[y]+1;let s=i>0?i-1:0,r=y=>Math.max(0,Math.min(t.length-1,y-1)),a=o.endLine??1/0,l=o.endCol??1/0,c=r(o.startLine),h=r(a),u=t[c],d=t[h],f=Math.max(0,Math.min(u,o.startCol-1)),m=l===1/0?d:Math.max(0,Math.min(d,l-1)),g=Math.min(s,n[c]+f),p=Math.min(s,n[h]+m);return{start:Math.min(g,p),end:Math.max(g,p)}}function ct(o,t,n){let i=0,s=1,r=1,a=1,l=1,c=!1;for(let h=0;h<n.length;h++){let u=i,d=i+n[h];if(!c&&o>=u&&o<=d&&(s=h+1,r=o-u+1,c=!0),t>=u&&t<=d){a=h+1,l=t-u+1;break}i=d+1}return{startLine:s,startCol:r,endLine:a,endCol:l}}var x=function(o,t,n,i){var s=arguments.length,r=s<3?t:i===null?i=Object.getOwnPropertyDescriptor(t,n):i,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")r=Reflect.decorate(o,t,n,i);else for(var l=o.length-1;l>=0;l--)(a=o[l])&&(r=(s<3?a(r):s>3?a(t,n,r):a(t,n))||r);return s>3&&r&&Object.defineProperty(t,n,r),r},Gt="rgba(255, 255, 255, 0.12)",$t=6,b=class extends ke{tokenLines=[];_linesSource="";_linesBasis={language:"",theme:"",highlighted:!1};_rawCode=null;_normalCode="";transitions=[];advanceCache=new R;structureVersion=0;layoutCacheKey=null;layoutCache=null;highlightDimOpacity=null;highlightedIds=new Set;rowBands=[];diffStrategy;phaseStrategy;constructor(t){super(t),this.diffStrategy=t?.diffStrategy??it,this.phaseStrategy=t?.phaseStrategy??pt,this.applyProp("width",t?.width??"hug"),this.applyProp("height",t?.height??"hug"),this.applyProp("_driven",!1),F(void 0,[this.language]).catch(()=>{}),this._sync()}setLines(t,n,i=this._basis()){this.tokenLines!==t&&(this.tokenLines=t,this._linesSource=n,this._linesBasis=i,this.structureVersion++,this.layoutCache=null,this.layoutCacheKey=null)}declareAssets(t){super.declareAssets(t),t.font(this.fontFamily),t.loader(`shiki:lang:${this.language}`,Le(this.language),{gate:"layout"})}metrics(){return{fontSize:this.fontSize,fontFamily:this.fontFamily,lineHeight:this.lineHeight,letterSpacing:this.letterSpacing,padding:this.padding,showLineNumbers:this.showLineNumbers,lineNumberGap:this.lineNumberGap}}activeEdit(){for(let t=this.transitions.length-1;t>=0;t--){let n=this.transitions[t];if(n.kind==="structural")return n}return null}activeRows(){for(let t=this.transitions.length-1;t>=0;t--){let n=this.transitions[t];if(n.kind==="rows")return n}return null}settledLayout(t,n){let i=`${this.structureVersion}|${W(t)}|${this.advanceCache.signature(t.fontSize,t.fontFamily)}`;if(this.layoutCache&&this.layoutCacheKey===i)return this.layoutCache;let s=P(this.tokenLines,t,this.advanceCache,n);return this.layoutCache=s,this.layoutCacheKey=i,s}frameLayout(t){let n=this.metrics(),i=this.activeEdit();if(!i){let r=this.settledLayout(n,t);return{from:r,to:r,edit:null}}let s=`${W(n)}|${this.advanceCache.signature(n.fontSize,n.fontFamily)}`;return(i.layoutKey!==s||!i.fromLayout||!i.toLayout)&&(i.fromLayout=P(i.from,n,this.advanceCache,t),i.toLayout=P(i.to,n,this.advanceCache,t),i.layoutKey=s),{from:i.fromLayout,to:i.toLayout,edit:i}}measure(t,n){this._sync(),this.advanceCache.sync(this.advanceCache.signature(this.fontSize,this.fontFamily));let i=this.width,s=this.height,{from:r,to:a,edit:l}=this.frameLayout(n),c=$(l),h=l?Bt(r.innerW,a.innerW,c):a.innerW,u=l?Bt(r.innerH,a.innerH,c):a.innerH,d=typeof i=="number"?i:i==="hug"?h+this.padding.left+this.padding.right:t.maxWidth??0,f=typeof s=="number"?s:s==="hug"?u+this.padding.top+this.padding.bottom:t.maxHeight??0;return{width:d,height:f}}renderContent(t){t.pushTextStyle(null);try{this._sync(),super.renderContent(t)}finally{t.popTextStyle()}}renderSelf(t){this.drawSelf(t)}acceptsChild(t){return!1}clipSelf(){return new ye().rect({width:this.layoutBounds.width,height:this.layoutBounds.height})}hitTestSelf(t,n){this._sync();let i=this.hitLayout();if(!i)return super.hitTestSelf(t,n);if(!super.hitTestSelf(t,n))return!1;let s=this.fontSize*this.lineHeight/2,r=this.showLineNumbers?i.gutter:0,a=i.startX-r-n;for(let l=0;l<i.lineY.length;l++)if(!((i.lineW[l]??0)+r<=0)&&!(Math.abs(t.y-i.lineY[l])>s+n)&&t.x>=a&&t.x<=i.startX+(i.lineW[l]??0)+n)return!0;return!1}hitLayout(){if(!this.layoutCache||this.activeEdit())return null;let t=this.metrics(),n=`${this.structureVersion}|${W(t)}|${this.advanceCache.signature(t.fontSize,t.fontFamily)}`;return this.layoutCacheKey===n?this.layoutCache:null}append(t){this._sync();let{code:n}=t.data;return this.editTo(this.joinedSource()+n,t.duration,t.easing)}prepend(t){this._sync();let{code:n}=t.data;return this.editTo(n+this.joinedSource(),t.duration,t.easing)}insert(t){this._sync();let{position:n,code:i}=t.data,s=this.joinedSource(),r=this.offsetAt(n);return this.editTo(s.slice(0,r)+i+s.slice(r),t.duration,t.easing)}erase(t){this._sync();let{target:n}=t.data,{duration:i,easing:s}=t,r=this.joinedSource(),{start:a,end:l}=z(n,this.lineLengths()),c=a===0||r[a-1]===`
6
+ `,h=l===r.length||r[l]===`
7
+ `;if(c&&h)l<r.length?l+=1:a>0&&(a-=1);else if(l<=a)return _(i,()=>{});return l<=a?_(i,()=>{}):this.editTo(r.slice(0,a)+r.slice(l),i,s)}replace(t){this._sync();let{target:n,replacement:i}=t.data,s=this.joinedSource(),{start:r,end:a}=z(n,this.lineLengths());return this.editTo(s.slice(0,r)+i+s.slice(a),t.duration,t.easing)}highlight(t){this._sync();let{target:n,dim:i}=t.data,{duration:s,easing:r}=t,a=i??.4,l=this.tokenIdsInRanges(Rt(n));if(l.size===0)return _(s,()=>{});let c=this.highlightDimOpacity??1,h=this.highlightedIds.size>0,u=this.highlightedIds,d=[];for(let f of this.tokenLines)for(let m of f.tokens){let g=!h||u.has(m.id),p=l.has(m.id),y=g?1:c,w=p?1:a;y!==w&&d.push(Z(m.id,{keys:[0,1],values:[y,w]}))}return this.runDim(d,s,r,f=>{this.highlightDimOpacity=f?a:h?c:null,this.highlightedIds=f?l:u})}resetHighlight(t){this._sync();let{duration:n,easing:i}=t;if(this.highlightDimOpacity===null)return _(n,()=>{});let s=this.highlightDimOpacity,r=this.highlightedIds,a=[];for(let l of this.tokenLines)for(let c of l.tokens){let h=r.has(c.id)?1:s;h!==1&&a.push(Z(c.id,{keys:[0,1],values:[h,1]}))}return this.runDim(a,n,i,l=>{this.highlightDimOpacity=l?null:s,this.highlightedIds=l?new Set:r})}highlightRows(t){this._sync();let{target:n,color:i,radius:s}=t.data,r=be.resolve(i??Gt),a=this.rowBandsIn(Rt(n),r,Math.max(0,s??$t));return this.runRows(this.rowBands,a,t.duration,t.easing)}resetRowHighlight(t){return this._sync(),this.runRows(this.rowBands,[],t.duration,t.easing)}editTo(t,n,i){if(!this.mounted)return _(n,()=>{});t=M(t);let s=this.tokenLines,r=this.joinedSource();if(t===r)return _(n,()=>{});let a=this._linesBasis,l=this._basis(),c=this.diffStrategy(s,q(t,this.language,this.theme)),h={kind:"structural",from:s,to:c.lines,removedIds:c.removedIds,addedIds:c.addedIds,enteringLineIds:c.newLineIds,fromColorById:c.fromColorById,phases:this.phaseStrategy(c.removedIds.size>0,c.addedIds.size>0),progress:0,layoutKey:null,fromLayout:null,toLayout:null};return _(n,u=>{this._drive();let d=u>0&&u<1,f=this.transitions.indexOf(h);d&&f<0?this.transitions.push(h):!d&&f>=0&&this.transitions.splice(f,1),h.progress=i?i(u):u,u<=0?(this.setLines(s,r,a),this._writeProp("code",r)):(this.setLines(c.lines,t,l),this._writeProp("code",t))})}runDim(t,n,i,s){if(!this.mounted)return _(n,()=>{});let r={kind:"dim",tokens:t,progress:0};return _(n,a=>{this._drive();let l=a>0&&a<1,c=this.transitions.indexOf(r);l&&c<0?this.transitions.push(r):!l&&c>=0&&this.transitions.splice(c,1),r.progress=i?i(a):a,s?.(a>=1)})}runRows(t,n,i,s){if(!this.mounted||t.length===0&&n.length===0)return _(i,()=>{});let r={kind:"rows",from:t,to:n,progress:0};return _(i,a=>{this._drive();let l=a>0&&a<1,c=this.transitions.indexOf(r);l&&c<0?this.transitions.push(r):!l&&c>=0&&this.transitions.splice(c,1),r.progress=s?s(a):a,this.rowBands=a>=1?n:t})}_prepareStep(t,n,i){if(!this.mounted)return super._prepareStep(t,n,i);this._sync();let s=typeof t.code=="string"?M(t.code):void 0;if(s===void 0||s===this.joinedSource())return super._prepareStep(t,n,i);let r={...t};delete r.code;let a=super._prepareStep(r,n,i),l=this.editTo(s,n,i)._stepper();return{seek:c=>{a.seek(c),l.seek(c)},advance:c=>{let h=a.advance(c),u=l.advance(c);return h&&u}}}findAllRanges(t){let n=[];if(!t)return n;this._sync();let i=this.joinedSource(),s=this.lineLengths(),r=0;for(;;){let a=i.indexOf(t,r);if(a===-1)break;n.push(ct(a,a+t.length,s)),r=a+Math.max(1,t.length)}return n}findRangeAt(t,n){return this.findAllRanges(t)[n]??null}findFirstRange(t){return this.findRangeAt(t,0)}joinedSource(){return this._linesSource}lineLengths(){return this.tokenLines.map(t=>t.tokens.reduce((n,i)=>n+i.content.length,0))}offsetAt(t){let n=this.lineLengths();if(n.length===0)return 0;let[i,s]=t,r=Math.max(0,Math.min(n.length-1,i-1)),a=0;for(let l=0;l<r;l++)a+=n[l]+1;return a+Math.max(0,Math.min(n[r],s-1))}tokenIdsInRanges(t){let n=new Set,i=this.lineLengths();if(i.length===0)return n;let s=t.map(a=>z(a,i)).filter(({start:a,end:l})=>l>a);if(s.length===0)return n;let r=0;for(let a=0;a<this.tokenLines.length;a++){let l=this.tokenLines[a];for(let c of l.tokens){let h=r,u=r+c.content.length;s.some(({start:d,end:f})=>u>d&&h<f)&&n.add(c.id),r=u}a<this.tokenLines.length-1&&(r+=1)}return n}rowBandsIn(t,n,i){let s=this.tokenLines.length,r=[];for(let a of t){let l=Math.max(1,Math.round(a.startLine??1)),c=Math.min(s,a.endLine==null||a.endLine===1/0?s:Math.round(a.endLine));l>c||r.push({startId:this.tokenLines[l-1].id,endId:this.tokenLines[c-1].id,color:n,radius:i})}return r}drawSelf(t){this.advanceCache.sync(this.advanceCache.signature(this.fontSize,this.fontFamily)),ot(t,{tokenLines:this.tokenLines,metrics:this.metrics(),advanceCache:this.advanceCache,...this.frameLayout(t),tokenStates:mt(this.tokenLines,this.transitions,this.highlightDimOpacity,this.highlightedIds),highlightActive:this.highlightDimOpacity!==null||this.transitions.some(n=>n.kind==="dim"),rowBands:this.rowBands,rowsEdit:this.activeRows(),boxW:this.layoutBounds.width})}_derived=new Map;_drive(){this._sync(),this._writeProp("_driven",!0)}_sync(){let t=this._normalised();if(!this._driven)this.transitions.length=0,this.highlightDimOpacity=null,this.highlightedIds.size>0&&(this.highlightedIds=new Set),this.rowBands.length>0&&(this.rowBands=[]),this.setLines(this._structureFor(t),t);else if(!this.activeEdit()){let n=this._basis(),i=this._linesBasis;if(this._linesSource===t&&i.language===n.language&&i.theme===n.theme&&i.highlighted===n.highlighted)return;let s=this._structureFor(t);this._linesSource===t&&i.language===n.language&&i.highlighted===n.highlighted&&Se(this.tokenLines,s),this.setLines(s,t,n)}}_normalised(){let t=this.code;return t!==this._rawCode&&(this._rawCode=t,this._normalCode=M(t)),this._normalCode}_basis(){return{language:this.language,theme:this.theme,highlighted:B(this.language,this.theme)}}_structureFor(t){let{language:n,theme:i,highlighted:s}=this._basis(),r=this._derived.get(t);return(!r||r.language!==n||r.theme!==i||r.highlighted!==s)&&(r={language:n,theme:i,highlighted:s,lines:q(t,n,i)},this._derived.delete(t),this._derived.set(t,r),this._derived.size>xe&&this._derived.delete(this._derived.keys().next().value)),r.lines}};x([O({default:""})],b.prototype,"code",void 0);x([O({default:"typescript"})],b.prototype,"language",void 0);x([O({default:"Fira Mono"})],b.prototype,"fontFamily",void 0);x([O({default:A.name})],b.prototype,"theme",void 0);x([O({default:16})],b.prototype,"fontSize",void 0);x([O({default:1.6})],b.prototype,"lineHeight",void 0);x([O({default:1.1})],b.prototype,"letterSpacing",void 0);x([O({default:!1})],b.prototype,"showLineNumbers",void 0);x([O({default:2})],b.prototype,"lineNumberGap",void 0);x([we()],b.prototype,"padding",void 0);x([E({args:[{key:"code",kind:"text",multiline:!0}]})],b.prototype,"append",null);x([E({args:[{key:"code",kind:"text",multiline:!0}]})],b.prototype,"prepend",null);x([E({args:[{key:"position",kind:"point",properties:{line:{kind:"number",default:1,min:1,step:1},col:{kind:"number",default:1,min:1,step:1}}},{key:"code",kind:"text",default:"",multiline:!0}]})],b.prototype,"insert",null);x([E({key:"remove",args:[{key:"target",kind:"selector"}]})],b.prototype,"erase",null);x([E({args:[{key:"target",kind:"selector"},{key:"replacement",kind:"text",default:"",multiline:!0}]})],b.prototype,"replace",null);x([E({args:[{key:"target",kind:"selector"},{key:"dim",kind:"number",default:.4,min:0,max:1,step:.01,scale:100,unit:"%"}]})],b.prototype,"highlight",null);x([E()],b.prototype,"resetHighlight",null);x([E({args:[{key:"target",kind:"selector"},{key:"color",kind:"color",default:Gt},{key:"radius",kind:"number",default:$t,min:0,step:1}]})],b.prototype,"highlightRows",null);x([E()],b.prototype,"resetRowHighlight",null);b=x([me({key:"code",parentKey:"node",forkable:!0,layout:{defaultWidthMode:"hug",defaultHeightMode:"hug",acceptsChildren:!1}})],b);function Se(o,t){if(o.length===t.length){for(let n=0;n<o.length;n++){let i=o[n].tokens,s=t[n].tokens;if(i.length!==s.length)return;for(let r=0;r<i.length;r++)if(i[r].content!==s[r].content)return}for(let n=0;n<o.length;n++){t[n].id=o[n].id;for(let i=0;i<o[n].tokens.length;i++)t[n].tokens[i].id=o[n].tokens[i].id}}}var xe=16;function Rt(o){if(typeof o[Symbol.iterator]=="function")return[...o];let n=o.list;return Array.isArray(n)?[...n]:[o]}var zt=new Map;function Le(o){let t=zt.get(o);return t===void 0&&(t=()=>F(void 0,[o]),zt.set(o,t)),t}var Ce=[b];export{K as BUILTIN_THEMES,b as Code,X as CodeRangeChain,pe as CodeRanges,A as DefaultHighlightStyle,Lt as GithubDarkStyle,Ct as GithubLightStyle,Ce as NODES,R as TokenAdvanceCache,vt as VscodeDarkStyle,_t as VscodeLightStyle,B as canHighlight,ct as charOffsetsToRange,rt as compileStyle,it as defaultCodeDiff,pt as defaultCodePhases,ot as drawCode,F as ensureHighlighter,ce as initSyntaxHighlighter,P as layoutCode,jt as lines,le as loadCodeLanguage,Z as makeAnim,W as metricsSignature,$ as moveProgress,M as normalizeSource,Yt as phasesFor,z as rangeToCharOffsets,se as registerCodeTheme,V as resolveTheme,mt as resolveTokenStates,Wt as sampleCurve,Pt as smoothstep,q as tokenizeCodeToIdLines,G as windowProgress,Dt as word};
8
8
  //# sourceMappingURL=index.js.map