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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # @motionscript/code
2
2
 
3
+ ## 0.1.0-alpha.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 4b23387: A `code` node draws the listing its props describe until its first command starts.
8
+
9
+ - The structure, highlight and in-flight transitions the listing commands own live outside the props, and only a command that had started wrote them, so before the first one a frame showed whatever the last evaluation left: the end of every command. A listing appended to at 1 s drew the new rows from 0 s, and a `highlight` at 0.8 s, as in the README's own example, dimmed the listing from 0 s, jumped to full brightness when it started, then faded back. A seek back past an edit or a highlight also left it drawn mid-transition. Until a command applies, all three are now derived from the props, so a frame is the same however the playhead reached it, and a highlight still selects the tokens it was built against when a later edit returns the source to the same text.
10
+ - The README says what the host supplies: a monospaced face under `fontFamily` (`Fira Mono` by default) in the engine's asset manifest, without which the listing draws no text or falls back to another registered face.
11
+
12
+ ## 0.1.0-alpha.2
13
+
14
+ ### Patch Changes
15
+
16
+ - 0227e28: A document's `remove` command on a `code` node erases its `target` range. It used to reach `Node.remove` instead of `Code.erase` and leave the listing as it was.
17
+
18
+ ## 0.1.0-alpha.1
19
+
20
+ ### Minor Changes
21
+
22
+ - 59cecba: Build on `@motionscript/sdk` instead of `@motionscript/core`. The peer dependency is now `@motionscript/sdk`, every import goes through it (and `@motionscript/sdk/component` for the component machinery), and the browser build leaves `@motionscript/sdk` an import, so an import map names it once. A component copied with `ms add` imports the SDK too, and its registry item depends on `@motionscript/sdk` rather than `@motionscript/core`. `@motionscript/charts/kit` re-exports `@motionscript/sdk/component` where it re-exported `@motionscript/core/component`.
23
+
3
24
  ## 0.1.0-alpha.0
4
25
 
5
26
  Initial release.
package/README.md CHANGED
@@ -1,70 +1,101 @@
1
1
  # @motionscript/code
2
2
 
3
- Animated, syntax-highlighted code blocks for [Motion Script](https://motionscript.dev).
4
- The `Code` node tokenizes source with [Shiki](https://shiki.style) and animates
5
- edits at the token level, so appending, inserting, removing, replacing, and
6
- highlighting code all morph smoothly instead of snapping.
7
-
8
- ```tsx
9
- import { createScene, createRef } from '@motionscript/core';
10
- import { Code, lines, word } from '@motionscript/code';
11
-
12
- export default createScene(function* (stage) {
13
- const code = createRef<Code>();
14
-
15
- stage.add(
16
- <Code
17
- ref={code}
18
- language="typescript"
19
- theme="github-dark"
20
- fontSize={28}
21
- code={`function greet(name) {\n return "hi";\n}`}
22
- />,
23
- );
24
-
25
- yield* code().append('\ngreet("world");', 0.6);
26
- yield* code().highlight(lines(2), 0.4);
27
- yield* code().replace(word(2, 10, 4), '`hi, ${name}`', 0.6);
28
- });
3
+ Animated, syntax-highlighted code listings for [Motion Script](https://motionscript.dev).
4
+ The `Code` node highlights source with [Lezer](https://lezer.codemirror.net)
5
+ grammars and animates edits at the token level: each edit is diffed against the
6
+ listing it becomes, so tokens that survive travel to their new columns, removed
7
+ ones fade out and new ones fade in, rather than the listing snapping.
8
+
9
+ Hand `Code` to the engine through your project entry's `nodes`, and any
10
+ document that engine opens can name it as `code`:
11
+
12
+ ```ts
13
+ // src/project.ts
14
+ import { Code } from '@motionscript/code';
15
+
16
+ export const nodes = [Code];
17
+ ```
18
+
19
+ ```ts
20
+ import type { CompositionDocument } from '@motionscript/sdk';
21
+ import { lines } from '@motionscript/code';
22
+
23
+ export default {
24
+ kind: 'composition',
25
+ nodes: [
26
+ { id: 'listing', type: 'code', parentId: null, layerOrder: 0,
27
+ props: { code: 'function greet(name) {\n return "hi";\n}', language: 'typescript',
28
+ theme: 'github-dark', fontSize: 28 } },
29
+ ],
30
+ commands: [
31
+ { id: 'call', type: 'append', targetId: 'listing', at: 0, duration: 0.6,
32
+ args: { code: '\ngreet("world");' } },
33
+ { id: 'focus', type: 'highlight', targetId: 'listing', at: 0.8, duration: 0.4,
34
+ args: { target: lines(2) } },
35
+ ],
36
+ } satisfies CompositionDocument;
29
37
  ```
30
38
 
31
39
  ## What's in here
32
40
 
33
- - **`Code`** node, a hugging block of syntax-highlighted source. Set `code`,
34
- `language`, and `theme` to switch what is shown; tune `fontSize`,
41
+ - **`Code`** node, a hugging block of highlighted source. Set `code`,
42
+ `language` and `theme` to choose what is shown; tune `fontSize`,
35
43
  `fontFamily`, `lineHeight`, `letterSpacing`, `showLineNumbers`,
36
- `lineNumberGap`, and `padding` for layout.
37
- - **Token-level transitions**, generator methods you `yield*` from a scene:
38
- - `append(code, duration)` / `prepend(code, duration)`, fade in lines at the
39
- end or start.
40
- - `insert([line, col], code, duration)`, splice code into a line or grow new
41
- lines mid-document.
42
- - `remove(range, duration)`, collapse tokens (and whole lines) so surrounding
43
- text reflows.
44
- - `replace(range, next, duration)`, cross-fade old tokens out and new ones in.
45
- - `highlight(range, duration)` / `resetHighlight(duration)`, dim everything
46
- outside the range, then restore it.
47
- - **Range helpers**, `word(line, col, length)`, `lines(from, to)`, and
48
- `range(startLine, startCol, endLine, endCol)` build the `CodeRange` values the
49
- transitions take. `findFirstRange`, `findRangeAt`, and `findAllRanges` locate
50
- ranges by matching literal text.
51
- - **`initSyntaxHighlighter(themes, langs)`**, optional preloading of Shiki
52
- themes and languages so the first frame renders fully highlighted.
44
+ `lineNumberGap` and `padding` for layout.
45
+ - **Token-level commands**: `append`/`prepend` (lines at the end or start),
46
+ `insert` (at a `[line, col]` position), `remove`, `replace`, and
47
+ `highlight`/`resetHighlight` (dim everything outside a range, then restore
48
+ it). A `to` command on `code` diffs the whole listing the same way.
49
+ - **Range helpers**: `word(line, col, length)`, `lines(from, to)` and the
50
+ chainable `CodeRanges` build the ranges those commands take.
51
+ - **Themes**: `github-dark`, `github-light`, `vscode-dark`, `vscode-light`
52
+ and a default, plus `registerCodeTheme` for your own.
53
+ `initSyntaxHighlighter(themes, langs)` preloads grammars so the first frame
54
+ renders fully highlighted.
53
55
 
54
56
  Every token keeps a stable identity across edits, so concurrent animations at
55
57
  different positions do not clobber each other while one is mid-flight.
56
58
 
57
- This package builds on [`@motionscript/core`](../../core) (the scene graph and
58
- animation runtime) and renders through whatever backend draws the scene, such as
59
- [`@motionscript/browser`](../../browser).
59
+ This package is written against [`@motionscript/sdk`](../../sdk), which it
60
+ takes as a peer dependency, and renders through whatever backend draws the
61
+ scene, such as [`@motionscript/browser`](../../browser).
62
+
63
+ ## The monospaced face is yours to supply
64
+
65
+ `Code` measures and draws every token in its `fontFamily`, `Fira Mono` by
66
+ default, and lines its columns up on that face's advances. The package ships no
67
+ font file and names no URL: list a monospaced face under that family in the
68
+ engine's asset manifest, alongside the node itself.
69
+
70
+ ```ts
71
+ const engine = await createBrowserEngine({
72
+ wasmUrl,
73
+ nodes: [Code],
74
+ manifest: {
75
+ image: {}, video: {}, audio: {},
76
+ font: {
77
+ 'Fira Mono@400': {
78
+ fontFamily: 'Fira Mono', fontWeight: 400,
79
+ src: '/fonts/FiraMono-Regular.ttf', sizeBytes: 0,
80
+ },
81
+ },
82
+ },
83
+ });
84
+ ```
85
+
86
+ A family the manifest does not list is never loaded. The loader warns once, and
87
+ the listing draws no text, or shapes in whichever other face is registered. To
88
+ use another face, set `fontFamily` on the node and list that family instead.
60
89
 
61
90
  ## Usage
62
91
 
63
92
  ```bash
64
- npm install @motionscript/code
93
+ npm install @motionscript/code @motionscript/sdk
65
94
  ```
66
95
 
67
- See the [docs](https://motionscript.dev/docs) for the full feature set and API
96
+ Or copy the node's source into your project with `ms add code`
97
+ (see [`@motionscript/cli`](../../cli)). See the
98
+ [docs](https://motionscript.dev/docs) for the full feature set and API
68
99
  reference.
69
100
 
70
101
  ## Development
@@ -1,8 +1,7 @@
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 ct,k as lt,l as e}from"./chunks/chunk-SYZUZB3M.js";import{node as oe,Clip as ie,Node2D as re,property as _,insetsProperty as se,lerpNumber as Ht,command as O,driveCommand as F}from"@motionscript/sdk";function Ft(n,t,i){if(i<=n[0])return t[0];if(i>=n[n.length-1])return t[t.length-1];for(let o=0;o<n.length-1;o++)if(i<=n[o+1]){let s=n[o+1]-n[o],a=s===0?0:(i-n[o])/s;return t[o]+(t[o+1]-t[o])*a}return t[t.length-1]}function G(n,t){if(!n)return 1;let[i,o]=n;return t<=i?0:t>=o||o===i?1:(t-i)/(o-i)}function Ot(n){return n*n*(3-2*n)}function X(n,t){return{id:n,opacity:t.values,opacityKeys:t.keys}}function At(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 ht=At;function P(n){return n?Ot(G(n.phases.move,n.progress)):1}function dt(n,t,i,o){let s=new Map;if(i!==null){let a=i;for(let r of n)for(let c of r.tokens)s.set(c.id,{opacity:o.has(c.id)?1:a})}for(let a of t)if(a.kind==="dim")for(let r of a.tokens)s.set(r.id,{opacity:Ft(r.opacityKeys,r.opacity,a.progress)});return s}function K(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 Et(n,t,i){return i.advance(n," ",t.fontSize,t.fontFamily,0)*t.lineNumberGap}function zt(n,t,i,o,s){if(!t.showLineNumbers)return 0;let a=String(Math.max(1,o));return i.advance(n,a,t.fontSize,t.fontFamily,0)+s}function W(n,t,i,o){let s=t.fontSize*t.lineHeight,a=t.showLineNumbers?Et(o,t,i):0,r=zt(o,t,i,n.length,a),c=new Array(n.length),l=0;for(let b=0;b<n.length;b++){let m=0;for(let x of n[b].tokens)m+=i.advance(o,x.content,t.fontSize,t.fontFamily,t.letterSpacing);c[b]=m,m>l&&(l=m)}let h=l+r,d=n.length*s,f=h+t.padding.left+t.padding.right,u=d+t.padding.top+t.padding.bottom,g=-f/2+t.padding.left+r,k=u/2-t.padding.top,S=new Map,p=new Array(n.length),v=new Map;for(let b=0;b<n.length;b++){let m=k-b*s-s/2;p[b]=m,v.set(n[b].id,b);let x=g;for(let C of n[b].tokens)S.set(C.id,{x,y:m}),x+=i.advance(o,C.content,t.fontSize,t.fontFamily,t.letterSpacing)}return{tokens:S,lineY:p,lineW:c,lineIndex:v,gutter:r,gutterGap:a,innerW:h,innerH:d,blockW:f,blockH:u,startX:g}}import{Graphics2D as ft,parseColor as Dt,lerpNumber as A}from"@motionscript/sdk";var jt=[.82,.84,.86,1],Rt=[.45,.5,.55,1],ut=new Map;function J(n){if(!n)return jt;let t=ut.get(n);return t||(t=Dt(n),ut.set(n,t)),t}function Gt(n,t,i){return i<=0?n:i>=1?t:[n[0]+(t[0]-n[0])*i,n[1]+(t[1]-n[1])*i,n[2]+(t[2]-n[2])*i,n[3]+(t[3]-n[3])*i]}function Pt(n,t,i){if(!i)return 1;let o=1;for(let s of n.tokens){if(s.content.length===0)continue;let a=t.get(s.id)?.opacity??1;a<o&&(o=a)}return o}function Q(n,t){let{tokenLines:i,metrics:o,advanceCache:s,from:a,to:r,edit:c,tokenStates:l}=t,h=c?c.progress:1,d=c?G(c.phases.out,h):1,f=P(c),u=c?G(c.phases.in,h):1,g=c?A(a.blockW,r.blockW,f):r.blockW,k=c?A(a.gutter,r.gutter,f):r.gutter,S=r.gutterGap||a.gutterGap,p=-g/2+o.padding.left+k-S,v=(m,x,C)=>{if(C<=0)return;let N=s.advance(n,m,o.fontSize,o.fontFamily,0);n.draw(new ft().text({text:m,fontSize:o.fontSize,fontFamily:o.fontFamily,lineHeight:o.lineHeight,x:p-N/2,y:x,textAlign:"left"}).fill([{type:"solid",color:Rt,opacity:C}]))},b=(m,x,C,N,M)=>{if(M<=0||m.length===0)return;let I=s.advance(n,m,o.fontSize,o.fontFamily,o.letterSpacing);n.draw(new ft().text({text:m,fontSize:o.fontSize,fontFamily:o.fontFamily,lineHeight:o.lineHeight,letterSpacing:o.letterSpacing,x:x+I/2,y:C,textAlign:"left"}).fill([{type:"solid",color:N,opacity:M}]))};for(let m=0;m<i.length;m++){let x=i[m],C=r.lineIndex.get(x.id);if(C===void 0)continue;let N=r.lineY[C],M=c?.enteringLineIds.has(x.id)??!1,I=N,z=1;if(c&&M)z=u;else if(c){let L=a.lineIndex.get(x.id);L!==void 0&&(I=A(a.lineY[L],N,f))}for(let L of x.tokens){let V=r.tokens.get(L.id);if(!V)continue;let rt=V.x,st=z,q=J(L.color);if(c&&!M)if(c.addedIds.has(L.id))st=u;else{let at=a.tokens.get(L.id);at&&(rt=A(at.x,V.x,f)),c.fromColorById.has(L.id)&&(q=Gt(J(c.fromColorById.get(L.id)),q,f))}b(L.content,rt,I,q,st*(l.get(L.id)?.opacity??1))}}if(c&&d<1)for(let m=0;m<c.from.length;m++){let x=c.from[m],C=a.lineIndex.get(x.id);if(C===void 0)continue;let N=r.lineIndex.get(x.id),M=N===void 0?a.lineY[C]:A(a.lineY[C],r.lineY[N],f);for(let I of x.tokens){if(!c.removedIds.has(I.id))continue;let z=a.tokens.get(I.id);z&&b(I.content,z.x,M,J(I.color),1-d)}}o.showLineNumbers&&Kt(t,v,f,u,d)}function Kt(n,t,i,o,s){let{tokenLines:a,from:r,to:c,edit:l,tokenStates:h,highlightActive:d}=n,f=a.length,u=l?l.from.length:f;for(let g=0;g<Math.max(u,f);g++){let k=g<u,S=g<f,p=S?a[g]:l?.from[g],v=p?Pt(p,h,d):1;l?k&&S?t(String(g+1),A(r.lineY[g],c.lineY[g],i),v):S?t(String(g+1),c.lineY[g],o*v):t(String(g+1),r.lineY[g],(1-s)*v):t(String(g+1),c.lineY[g],v)}}function B(n){return n.content.trim().length}function gt(n){let t=0;for(let i of n.tokens)t+=B(i);return t}function Wt(n,t){let i=gt(n),o=gt(t);if(i===0&&o===0)return 1;if(i===0||o===0)return 0;let s=new Map;for(let r of n.tokens)B(r)!==0&&s.set(r.content,(s.get(r.content)??0)+1);let a=0;for(let r of t.tokens){let c=B(r);if(c===0)continue;let l=s.get(r.content)??0;l>0&&(s.set(r.content,l-1),a+=c)}return 2*a/(i+o)}function pt(n,t,i){let o=t+1,s=new Float64Array((n+1)*o),a=new Float64Array(n*t);for(let h=1;h<=n;h++)for(let d=1;d<=t;d++){let f=i(h-1,d-1);a[(h-1)*t+(d-1)]=f;let u=s[(h-1)*o+d],g=s[h*o+(d-1)],k=u>g?u:g;if(f>0){let S=s[(h-1)*o+(d-1)]+f;S>k&&(k=S)}s[h*o+d]=k}let r=[],c=n,l=t;for(;c>0&&l>0;){let h=a[(c-1)*t+(l-1)];h>0&&s[c*o+l]===s[(c-1)*o+(l-1)]+h?(r.push([c-1,l-1]),c--,l--):s[(c-1)*o+l]>=s[c*o+(l-1)]?c--:l--}return r.reverse(),r}function Bt(n,t){return pt(n.length,t.length,(i,o)=>n[i].content!==t[o].content?0:B(t[o])||.25)}function Z(n,t){let i=new Set,o=new Set,s=new Set,a=new Map,r=pt(n.length,t.length,(h,d)=>Wt(n[h],t[d])-.45),c=new Set,l=new Set;for(let[h,d]of r){l.add(h),c.add(d);let f=n[h],u=t[d];u.id=f.id;let g=Bt(f.tokens,u.tokens),k=new Set,S=new Set;for(let[p,v]of g){k.add(p),S.add(v);let b=f.tokens[p],m=u.tokens[v];m.id=b.id,b.color!==m.color&&a.set(b.id,b.color)}for(let p=0;p<f.tokens.length;p++)k.has(p)||i.add(f.tokens[p].id);for(let p=0;p<u.tokens.length;p++)S.has(p)||o.add(u.tokens[p].id)}for(let h=0;h<n.length;h++)if(!l.has(h))for(let d of n[h].tokens)i.add(d.id);for(let h=0;h<t.length;h++)if(!c.has(h)){s.add(t[h].id);for(let d of t[h].tokens)o.add(d.id)}return{lines:t,removedIds:i,addedIds:o,newLineIds:s,fromColorById:a}}var T={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"}]},St={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":T,"github-dark":yt,"github-light":kt,"vscode-dark":bt,"vscode-light":St},mt=new Map;function et(n){let t=mt.get(n.name);if(t)return t;let i=ct(n.rules.map(o=>({tag:o.tag,class:o.color})));return mt.set(n.name,i),i}var Yt={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},$t={ts:"typescript",js:"javascript",py:"python","c++":"cpp",md:"markdown",yml:"yaml",shell:"javascript"};function Y(n){let t=n.toLowerCase();return $t[t]??t}var D=new Map,nt=new Map,ot=[T.name],wt=["typescript","javascript","json","python"],xt=new Map(Object.entries(tt));function Ut(n){xt.set(n.name,n)}function vt(n){return typeof n!="string"?n:xt.get(n)??T}function Vt(n){return D.has(Y(n))}function E(n=ot,t=wt){let i=[];for(let o of t){let s=Y(o);if(D.has(s))continue;let a=Yt[s];if(!a)continue;let r=nt.get(s);r||(r=a().then(c=>(D.set(s,c),c)).catch(()=>null).finally(()=>nt.delete(s)),nt.set(s,r)),i.push(r)}return i.length===0?Promise.resolve():Promise.all(i).then(()=>{})}async function qt(n,t){await E(ot,[n])}async function Xt(n=ot,t=wt){await E(n,t)}function H(n,t){return Vt(n)}function Ct(n,t){return`${n}:${t}`}function Jt(n,t,i){let o=D.get(Y(t));if(!o)return null;let s=o.parse(n),a=et(i),r=new Map;return lt(s,a,(c,l,h)=>{let d=h;if(!d)return;let f=s.cursorAt(c,1);do r.set(Ct(f.from,f.to),d);while(f.next()&&f.to<=l)}),{tree:s,code:n,colorLookup:r}}function Qt(n,t){let i=t.tree.resolveInner(n,1),o=t.colorLookup.get(Ct(i.from,i.to));return o?{color:o,skipAhead:i.to-n}:{color:null,skipAhead:i.firstChild?0:i.to-n}}function Zt(n,t){let i=D.get(Y(t));if(!i)return[n];let s=i.parse(n).cursor(),a=[],r=0;do s.node.firstChild||(s.from>r&&a.push(n.slice(r,s.from)),s.from<s.to&&a.push(n.slice(s.from,s.to)),r=s.to);while(s.next());return r<n.length&&a.push(n.slice(r)),a}function Lt(n,t,i=T){let o=vt(i),s=Jt(n,t,o),a=[[]],r=()=>a.push([]);if(!s)return n.split(`
2
+ `).map(l=>[{content:l,color:o.defaultColor}]);let c=0;for(let l of Zt(n,t)){let h=0;for(;h<l.length;){let{color:d,skipAhead:f}=Qt(c+h,s),u=h+Math.max(f,1);u>l.length&&(u=l.length);let g=l.indexOf(`
3
+ `,h);g!==-1&&g<u&&(u=g);let k=l.slice(h,u);k.length>0&&a[a.length-1].push({content:k,color:d??o.defaultColor}),g===u&&(r(),u+=1),h=u}c+=l.length}return a}var te=1,ee=1;function Nt(n,t){return{id:te++,content:n,color:t}}function It(n){return{id:ee++,tokens:n}}function $(n,t,i){return H(t,i)?Lt(n,t,i).map(o=>It(o.map(s=>Nt(s.content,s.color)))):n.split(`
4
+ `).map(o=>It([Nt(o,"#d1d5db")]))}var j=class{cache=new Map;sig="";signature(t,i){return`${t}|${i}`}sync(t){t!==this.sig&&(this.cache.clear(),this.sig=t)}advance(t,i,o,s,a){if(i.length===0)return 0;let r=`${i}\0${a}`,c=this.cache.get(r);if(c!==void 0)return c;let{width:l}=t.measureText(i,o,s,void 0,a);return this.cache.set(r,l),l}};function _t(n,t,i){return{startLine:n,startCol:t,endLine:n,endCol:i===void 0?1/0:t+i}}function Tt(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,i){return new n([...this.list,Tt(t,i)])}word(t,i,o){return new n([...this.list,_t(t,i,o)])}*[Symbol.iterator](){yield*this.list}},ne=new U;function R(n,t){if(t.length===0)return{start:0,end:0};let i=new Array(t.length),o=0;for(let p=0;p<t.length;p++)i[p]=o,o+=t[p]+1;let s=o>0?o-1:0,a=p=>Math.max(0,Math.min(t.length-1,p-1)),r=n.endLine??1/0,c=n.endCol??1/0,l=a(n.startLine),h=a(r),d=t[l],f=t[h],u=Math.max(0,Math.min(d,n.startCol-1)),g=c===1/0?f:Math.max(0,Math.min(f,c-1)),k=Math.min(s,i[l]+u),S=Math.min(s,i[h]+g);return{start:Math.min(k,S),end:Math.max(k,S)}}function it(n,t,i){let o=0,s=1,a=1,r=1,c=1,l=!1;for(let h=0;h<i.length;h++){let d=o,f=o+i[h];if(!l&&n>=d&&n<=f&&(s=h+1,a=n-d+1,l=!0),t>=d&&t<=f){r=h+1,c=t-d+1;break}o=f+1}return{startLine:s,startCol:a,endLine:r,endCol:c}}var w=function(n,t,i,o){var s=arguments.length,a=s<3?t:o===null?o=Object.getOwnPropertyDescriptor(t,i):o,r;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")a=Reflect.decorate(n,t,i,o);else for(var c=n.length-1;c>=0;c--)(r=n[c])&&(a=(s<3?r(a):s>3?r(t,i,a):r(t,i))||a);return s>3&&a&&Object.defineProperty(t,i,a),a},y=class extends re{tokenLines=[];tokenized=!1;_linesSource="";transitions=[];advanceCache=new j;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??ht,this.applyProp("width",t.width??"hug"),this.applyProp("height",t.height??"hug"),this.applyProp("_driven",!1),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._structureFor(this.code),this.code),this.tokenized=H(this.language,this.theme)}setLines(t,i){this.tokenLines!==t&&(this.tokenLines=t,this._linesSource=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 i=this.transitions[t];if(i.kind==="structural")return i}return null}settledLayout(t,i){let o=`${this.structureVersion}|${K(t)}|${this.advanceCache.signature(t.fontSize,t.fontFamily)}`;if(this.layoutCache&&this.layoutCacheKey===o)return this.layoutCache;let s=W(this.tokenLines,t,this.advanceCache,i);return this.layoutCache=s,this.layoutCacheKey=o,s}frameLayout(t){let i=this.metrics(),o=this.activeEdit();if(!o){let a=this.settledLayout(i,t);return{from:a,to:a,edit:null}}let s=`${K(i)}|${this.advanceCache.signature(i.fontSize,i.fontFamily)}`;return(o.layoutKey!==s||!o.fromLayout||!o.toLayout)&&(o.fromLayout=W(o.from,i,this.advanceCache,t),o.toLayout=W(o.to,i,this.advanceCache,t),o.layoutKey=s),{from:o.fromLayout,to:o.toLayout,edit:o}}measure(t,i){this._sync(),this.advanceCache.sync(this.advanceCache.signature(this.fontSize,this.fontFamily));let o=this.width,s=this.height,{from:a,to:r,edit:c}=this.frameLayout(i),l=P(c),h=c?Ht(a.innerW,r.innerW,l):r.innerW,d=c?Ht(a.innerH,r.innerH,l):r.innerH,f=typeof o=="number"?o:o==="hug"?h+this.padding.left+this.padding.right:t.maxWidth??0,u=typeof s=="number"?s:s==="hug"?d+this.padding.top+this.padding.bottom:t.maxHeight??0;return{width:f,height:u}}renderContent(t){t.pushTextStyle(null);try{this._sync(),!this.tokenized&&!this.activeEdit()&&H(this.language,this.theme)&&this.tokenize(),super.renderContent(t)}finally{t.popTextStyle()}}renderSelf(t){this.drawSelf(t)}acceptsChild(t){return!1}clipSelf(){return new ie().rect({width:this.layoutBounds.width,height:this.layoutBounds.height})}hitTestSelf(t,i){this._sync();let o=this.hitLayout();if(!o)return super.hitTestSelf(t,i);if(!super.hitTestSelf(t,i))return!1;let s=this.fontSize*this.lineHeight/2,a=this.showLineNumbers?o.gutter:0,r=o.startX-a-i;for(let c=0;c<o.lineY.length;c++)if(!((o.lineW[c]??0)+a<=0)&&!(Math.abs(t.y-o.lineY[c])>s+i)&&t.x>=r&&t.x<=o.startX+(o.lineW[c]??0)+i)return!0;return!1}hitLayout(){if(!this.layoutCache||this.activeEdit())return null;let t=this.metrics(),i=`${this.structureVersion}|${K(t)}|${this.advanceCache.signature(t.fontSize,t.fontFamily)}`;return this.layoutCacheKey===i?this.layoutCache:null}append(t){this._sync();let{code:i}=t.data;return this.editTo(this.joinedSource()+i,t.duration,t.easing)}prepend(t){this._sync();let{code:i}=t.data;return this.editTo(i+this.joinedSource(),t.duration,t.easing)}insert(t){this._sync();let{position:i,code:o}=t.data,s=this.joinedSource(),a=this.offsetAt(i);return this.editTo(s.slice(0,a)+o+s.slice(a),t.duration,t.easing)}erase(t){this._sync();let{target:i}=t.data,{duration:o,easing:s}=t,a=this.joinedSource(),{start:r,end:c}=R(i,this.lineLengths()),l=r===0||a[r-1]===`
5
+ `,h=c===a.length||a[c]===`
6
+ `;if(l&&h)c<a.length?c+=1:r>0&&(r-=1);else if(c<=r)return F(o,()=>{});return c<=r?F(o,()=>{}):this.editTo(a.slice(0,r)+a.slice(c),o,s)}replace(t){this._sync();let{target:i,replacement:o}=t.data,s=this.joinedSource(),{start:a,end:r}=R(i,this.lineLengths());return this.editTo(s.slice(0,a)+o+s.slice(r),t.duration,t.easing)}highlight(t){this._sync();let{target:i,dim:o}=t.data,{duration:s,easing:a}=t,r=o??.4,c=this.tokenIdsInRanges(ce(i));if(c.size===0)return F(s,()=>{});let l=this.highlightDimOpacity??1,h=this.highlightedIds.size>0,d=this.highlightedIds,f=[];for(let u of this.tokenLines)for(let g of u.tokens){let k=!h||d.has(g.id),S=c.has(g.id),p=k?1:l,v=S?1:r;p!==v&&f.push(X(g.id,{keys:[0,1],values:[p,v]}))}return this.runDim(f,s,a,u=>{this.highlightDimOpacity=u?r:h?l:null,this.highlightedIds=u?c:d})}resetHighlight(t){this._sync();let{duration:i,easing:o}=t;if(this.highlightDimOpacity===null)return F(i,()=>{});let s=this.highlightDimOpacity,a=this.highlightedIds,r=[];for(let c of this.tokenLines)for(let l of c.tokens){let h=a.has(l.id)?1:s;h!==1&&r.push(X(l.id,{keys:[0,1],values:[h,1]}))}return this.runDim(r,i,o,c=>{this.highlightDimOpacity=c?null:s,this.highlightedIds=c?new Set:a})}editTo(t,i,o){let s=this.tokenLines,a=this.joinedSource();if(t===a)return F(i,()=>{});let r=this.diffStrategy(s,$(t,this.language,this.theme)),c={kind:"structural",from:s,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=H(this.language,this.theme),F(i,l=>{this._drive();let h=l>0&&l<1,d=this.transitions.indexOf(c);h&&d<0?this.transitions.push(c):!h&&d>=0&&this.transitions.splice(d,1),c.progress=o?o(l):l,l<=0?(this.setLines(s,a),this._writeProp("code",a)):(this.setLines(r.lines,t),this._writeProp("code",t))})}runDim(t,i,o,s){let a={kind:"dim",tokens:t,progress:0};return F(i,r=>{this._drive();let c=r>0&&r<1,l=this.transitions.indexOf(a);c&&l<0?this.transitions.push(a):!c&&l>=0&&this.transitions.splice(l,1),a.progress=o?o(r):r,s?.(r>=1)})}_prepareStep(t,i,o){this._sync();let s=t.code;if(typeof s!="string"||s===this.joinedSource())return super._prepareStep(t,i,o);let a={...t};delete a.code;let r=super._prepareStep(a,i,o),c=this.editTo(s,i,o)._stepper();return{seek:l=>{r.seek(l),c.seek(l)},advance:l=>{let h=r.advance(l),d=c.advance(l);return h&&d}}}findAllRanges(t){let i=[];if(!t)return i;this._sync();let o=this.joinedSource(),s=this.lineLengths(),a=0;for(;;){let r=o.indexOf(t,a);if(r===-1)break;i.push(it(r,r+t.length,s)),a=r+Math.max(1,t.length)}return i}findRangeAt(t,i){return this.findAllRanges(t)[i]??null}findFirstRange(t){return this.findRangeAt(t,0)}joinedSource(){return this._linesSource}lineLengths(){return this.tokenLines.map(t=>t.tokens.reduce((i,o)=>i+o.content.length,0))}offsetAt(t){let i=this.lineLengths();if(i.length===0)return 0;let[o,s]=t,a=Math.max(0,Math.min(i.length-1,o-1)),r=0;for(let c=0;c<a;c++)r+=i[c]+1;return r+Math.max(0,Math.min(i[a],s-1))}tokenIdsInRanges(t){let i=new Set,o=this.lineLengths();if(o.length===0)return i;let s=t.map(r=>R(r,o)).filter(({start:r,end:c})=>c>r);if(s.length===0)return i;let a=0;for(let r=0;r<this.tokenLines.length;r++){let c=this.tokenLines[r];for(let l of c.tokens){let h=a,d=a+l.content.length;s.some(({start:f,end:u})=>d>f&&h<u)&&i.add(l.id),a=d}r<this.tokenLines.length-1&&(a+=1)}return i}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:dt(this.tokenLines,this.transitions,this.highlightDimOpacity,this.highlightedIds),highlightActive:this.highlightDimOpacity!==null||this.transitions.some(i=>i.kind==="dim")})}_derived=new Map;_drive(){this._sync(),this._writeProp("_driven",!0)}_sync(){this._driven?this._linesSource!==this.code&&!this.activeEdit()&&this.setLines(this._structureFor(this.code),this.code):(this.transitions.length=0,this.highlightDimOpacity=null,this.highlightedIds.size>0&&(this.highlightedIds=new Set),this.setLines(this._structureFor(this.code),this.code))}_structureFor(t){let i=H(this.language,this.theme),o=this._derived.get(t);return(!o||o.language!==this.language||o.theme!==this.theme||o.highlighted!==i)&&(o={language:this.language,theme:this.theme,highlighted:i,lines:$(t,this.language,this.theme)},this._derived.delete(t),this._derived.set(t,o),this._derived.size>ae&&this._derived.delete(this._derived.keys().next().value)),o.lines}};w([_({default:""})],y.prototype,"code",void 0);w([_({default:"typescript"})],y.prototype,"language",void 0);w([_({default:"Fira Mono"})],y.prototype,"fontFamily",void 0);w([_({default:T.name})],y.prototype,"theme",void 0);w([_({default:16})],y.prototype,"fontSize",void 0);w([_({default:1.6})],y.prototype,"lineHeight",void 0);w([_({default:1.1})],y.prototype,"letterSpacing",void 0);w([_({default:!1})],y.prototype,"showLineNumbers",void 0);w([_({default:2})],y.prototype,"lineNumberGap",void 0);w([se()],y.prototype,"padding",void 0);w([O({args:[{key:"code",kind:"text",multiline:!0}]})],y.prototype,"append",null);w([O({args:[{key:"code",kind:"text",multiline:!0}]})],y.prototype,"prepend",null);w([O({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);w([O({key:"remove",args:[{key:"target",kind:"selector"}]})],y.prototype,"erase",null);w([O({args:[{key:"target",kind:"selector"},{key:"replacement",kind:"text",default:"",multiline:!0}]})],y.prototype,"replace",null);w([O({args:[{key:"target",kind:"selector"},{key:"dim",kind:"number",default:.4,min:0,max:1,step:.01,scale:100,unit:"%"}]})],y.prototype,"highlight",null);w([O()],y.prototype,"resetHighlight",null);y=w([oe({key:"code",parentKey:"node",forkable:!0,layout:{defaultWidthMode:"hug",defaultHeightMode:"hug",acceptsChildren:!1}})],y);var ae=16;function ce(n){return typeof n[Symbol.iterator]=="function"?[...n]:[n]}var Mt=new Map;function le(n){let t=Mt.get(n);return t===void 0&&(t=()=>E(void 0,[n]),Mt.set(n,t)),t}var he=[y];export{tt as BUILTIN_THEMES,y as Code,U as CodeRangeChain,ne as CodeRanges,T as DefaultHighlightStyle,yt as GithubDarkStyle,kt as GithubLightStyle,he as NODES,j as TokenAdvanceCache,bt as VscodeDarkStyle,St as VscodeLightStyle,H as canHighlight,it as charOffsetsToRange,et as compileStyle,Z as defaultCodeDiff,ht as defaultCodePhases,Q as drawCode,E as ensureHighlighter,Xt as initSyntaxHighlighter,W as layoutCode,Tt as lines,qt as loadCodeLanguage,X as makeAnim,K as metricsSignature,P as moveProgress,At as phasesFor,R as rangeToCharOffsets,Ut as registerCodeTheme,vt as resolveTheme,dt as resolveTokenStates,Ft as sampleCurve,Ot as smoothstep,$ as tokenizeCodeToIdLines,G as windowProgress,_t as word};
8
7
  //# sourceMappingURL=index.js.map