Clone any viral video with AI agents. Not just a script, the whole workflow: swap the face, the words, the B-roll, ship 100 variants in one command, and get your 100M views.
TypeScript agentic-aiaiai-agentsai-videocompilerdslffmpeggenerative-aillmmarkup-languagemonorepoplugin-systemprogramming-languagetext-to-videotypescriptvideovideo-automationvideo-clonevideo-editingvideo-generation
feat(script)!: delimit semantic markers and preserve caption spacing
kashorinbd728d05b955
diff --git a/docs/quickstart/composition.md b/docs/quickstart/composition.mdindex 8780c07f..1a2a383f 100644--- a/docs/quickstart/composition.md+++ b/docs/quickstart/composition.md@@ -162,7 +162,7 @@ illustration. The complete runnable project is `examples/podcast/`; the commands<!-- 1. Script: the semantic truth --><script id="story">- <opening><HOST>Meaning @demo becomes the source @/demo.</opening>+ <opening><HOST>Meaning @{demo} becomes the source @{/demo}.</opening></script><!-- 2. Generation: Seedance talking head + standalone video -->diff --git a/docs/quickstart/script.md b/docs/quickstart/script.mdindex d9d0dbc6..3498d1fa 100644--- a/docs/quickstart/script.md+++ b/docs/quickstart/script.md@@ -122,20 +122,31 @@ valid without grouping, and `||` still chooses the Cue handoff. This works for pin other languages too, such as `<Git Hub|>`.Here the left side also supplies speech, so markers can be written and moved there:-`<组@beat!件化|>`. Markers and display attributes never become spoken text. An explicit spoken side+`<组@{beat!}件化|>`. Markers and display attributes never become spoken text. An explicit spoken sidestill owns its own markers. Both sides empty is invalid.`||` is the **Caption Cue Break** syntax. It records a boundary between complete Alignment Units;it cannot appear inside Dual Text or split an N:M unit. Cue timing is still obtained later byjoining the CaptionDocument to the Timeline.+### Spaces and spelling++Write the display spacing you want: `是的 就是这样`, `3개월`, `3 개월`, `3D` and `3 D` remain+distinct. Ordinary whitespace runs normalize to one space; Turn-edge whitespace and padding around+Dual Text sides are omitted. Source newlines do not create subtitle rows. Use `||` for Caption Cues+and the selected caption family's layout for line wrapping.++Semantic markers contribute no text or space. `是的@{part}就是这样@{/part}` stays joined;+`是的 @{part}就是这样@{/part}` keeps a space. Grouping with `<text|>` is optional and controls+caption behavior; it is not required to protect spelling.+### Flat token attributesA display word may carry one flat attribute block. The block is postfix, never nested, and has notiming meaning:```svml-<HOST> This is really{emphasis,keyword} important{brand}.</HOST>+<line><HOST>This is really{emphasis,keyword} important{brand}.</line>```An entry without `=` has the value `true`; scalar values may be written as `name=value`. Caption@@ -162,34 +173,39 @@ marker; the value is a pair of semantic anchors, not a frame span:```svml<script id="story">- @whole+ @{whole}<opening>- <HOST> @problem Current tools make agents operate a timeline. @/problem+ <HOST> @{problem} Current tools make agents operate a timeline. @{/problem}</opening><answer>- <HOST> @solution SVML removes that editing loop. @/solution+ <HOST> @{solution} SVML removes that editing loop. @{/solution}</answer>- @/whole~+ @{/whole~}</script>```### Syntax+Every marker begins with `@{` and ends with `}`; `/`, `!` and `~` are inside. Names match+`[a-z][a-z0-9_-]{0,63}`; whitespace and nesting inside a marker are invalid. `@{beat!}` is a Moment;+`@{part}!` opens a Selection followed by a prose exclamation mark. A marker cannot split a speech Token.++| Marker | Meaning ||---|---|-| `@id` | Open, right-absorbing (starts at the next word) |-| `~@id` | Open, left-absorbing (starts at the previous word's end) |-| `@/id` | Close, left-absorbing (ends at the previous word's end) |-| `@/id~` | Close, right-absorbing (ends at the next word's start) |+| `@{id}` | Open, right-absorbing (starts at the next word) |+| `@{~id}` | Open, left-absorbing (starts at the previous word's end) |+| `@{/id}` | Close, left-absorbing (ends at the previous word's end) |+| `@{/id~}` | Close, right-absorbing (ends at the next word's start) |The `~` suffix/prefix controls whether the boundary snaps to the left or right. Default open isright-absorbing; default close is left-absorbing.The complete Script has exactly `2M + 2N + 2` ordered semantic anchors: two for every Token, two forevery Segment, and the Program start/end. At the outer cuts, affinity keeps coincident meanings-distinct: `~@id` before the first Segment chooses Program start while `@id` chooses that Segment's-start; `@/id` after the final Segment chooses that Segment's end while `@/id~` chooses Program end.+distinct: `@{~id}` before the first Segment chooses Program start while `@{id}` chooses that Segment's+start; `@{/id}` after the final Segment chooses that Segment's end while `@{/id~}` chooses Program end.Their frames may coincide after alignment, but their author identities do not.### Multiple named Selections@@ -200,7 +216,7 @@ Selections are not required to nest like XML tags. They can cross each other:```svml<demo>- <HOST> @a One @b two @/a three @/b.+ <HOST> @{a} One @{b} two @{/a} three @{/b}.</demo>```@@ -217,15 +233,15 @@ Moments are named time **points** (not ranges):```svml<ecosystem>- <HOST> @ranking! Image generation, video generation, captions and B-roll+ <HOST> @{ranking!} Image generation, video generation, captions and B-rollall become reusable components.</ecosystem>```| Marker | Meaning ||---|---|-| `@id!` | Right-absorbing (point at the next word's start) |-| `~@id!` | Left-absorbing (point at the previous word's end) |+| `@{id!}` | Right-absorbing (point at the next word's start) |+| `@{~id!}` | Left-absorbing (point at the previous word's end) |Each Moment name occurs once and compiles into one `NarrativeMoment` with an `anchorId`. Selectionand Moment share the same name namespace — the same id cannot be used for both.@@ -260,26 +276,26 @@ A complete Script using all constructs together:```svml<script id="story">- @whole+ @{whole}<hook>- <HOST> @problem Girls, you need to hear this. Never let anyone take credit- for your work. @/problem+ <HOST> @{problem} Girls, you need to hear this. Never let anyone take credit+ for your work. @{/problem}</hook><meeting>- <HOST> @solution I started sending <BCC | B C C> recaps after every- meeting: timestamps, decisions, who said what. @ranking! After- the first recap, everything changed. @/solution+ <HOST> @{solution} I started sending <BCC | B C C> recaps after every+ meeting: timestamps, decisions, who said what. @{ranking!} After+ the first recap, everything changed. @{/solution}</meeting><evidence>- <HOST> That gave me @emphasis the courage I was missing @/emphasis.+ <HOST> That gave me @{emphasis} the courage I was missing @{/emphasis}.</evidence><payoff><HOST> And guess what? I'm sitting in my old boss's chair now.</payoff>- @/whole~+ @{/whole~}</script>```diff --git a/docs/zh/quickstart/composition.md b/docs/zh/quickstart/composition.mdindex 4c8e5afe..e4be498c 100644--- a/docs/zh/quickstart/composition.md+++ b/docs/zh/quickstart/composition.md@@ -156,7 +156,7 @@ Build Target,也可以直接接到媒体裁切、音频/帧提取或模型参<!-- 1. Script: the semantic truth --><script id="story">- <opening><HOST>Meaning @demo becomes the source @/demo.</opening>+ <opening><HOST>Meaning @{demo} becomes the source @{/demo}.</opening></script><!-- 2. Generation: Seedance talking head + standalone video -->diff --git a/docs/zh/quickstart/script.md b/docs/zh/quickstart/script.mdindex fda47df6..3d659aa3 100644--- a/docs/zh/quickstart/script.md+++ b/docs/zh/quickstart/script.md@@ -113,18 +113,28 @@ dialogue `Text` 包含 Role Cue 前缀,speech `Text` 和 CaptionDocument 会Cue 的切换。这同样适用于其他语言的短语或名字,例如 `<Git Hub|>`。这时左侧同时提供口播,因此标记也可以放在左侧,Studio 会回写到实际文字上:-`<组@beat!件化|>`。标记和显示属性不会成为口播内容。若明确写了右侧口播,标记仍然属于+`<组@{beat!}件化|>`。标记和显示属性不会成为口播内容。若明确写了右侧口播,标记仍然属于右侧。两侧都没有口播文字时无效。`||` 是 **Caption Cue Break** 语法,只能位于完整对齐单元之间,不能写进 Dual Text 或切开N:M 单元。字幕稍后才把 CaptionDocument 与 Timeline 汇合得到帧时间。+### 空格与拼写++按想显示的内容书写:`是的 就是这样`、`3개월`、`3 개월`、`3D` 和 `3 D` 会保留各自的+分隔。连续普通空白规范为一个空格;说话轮次首尾的排版空白和 Dual Text 两侧的边缘空白+不显示。源码换行不是字幕换行;用 `||` 分 Cue,用所选字幕样式控制视觉换行。++语义标记不贡献文字或空格。`是的@{part}就是这样@{/part}` 连续显示;+`是的 @{part}就是这样@{/part}` 保留空格。`<文字|>` 用来明确字幕分组,+不是保护拼写或空格所必需的写法。+### 扁平词属性显示词可以带一个扁平的属性块。属性写在词后面,不嵌套,也不表达时间:```svml-<HOST> This is really{emphasis,keyword} important{brand}.</HOST>+<line><HOST>This is really{emphasis,keyword} important{brand}.</line>```不写 `=` 的属性值默认为 `true`,也可以写成 `name=value`。Caption 包负责把属性名映射为@@ -150,33 +160,38 @@ Selection 是内联声明的具名语义**范围**。每个名字只能有一对```svml<script id="story">- @whole+ @{whole}<opening>- <HOST> @problem Current tools make agents operate a timeline. @/problem+ <HOST> @{problem} Current tools make agents operate a timeline. @{/problem}</opening><answer>- <HOST> @solution SVML removes that editing loop. @/solution+ <HOST> @{solution} SVML removes that editing loop. @{/solution}</answer>- @/whole~+ @{/whole~}</script>```### 语法+所有标记都以 `@{` 开始、以 `}` 结束;`/`、`!`、`~` 均在内部。名称以小写字母开头,+后续可用小写字母、数字、`_`、`-`,总长不超过 64;内部不允许空白或嵌套。+`@{beat!}` 是 Moment,`@{part}!` 则是区间首后跟正文感叹号。标记不能切开一个语音 Token。++| 标记 | 含义 ||---|---|-| `@id` | 打开,右吸附(从下一个单词开始) |-| `~@id` | 打开,左吸附(从前一个单词的末尾开始) |-| `@/id` | 关闭,左吸附(在前一个单词的末尾结束) |-| `@/id~` | 关闭,右吸附(在下一个单词的起始处结束) |+| `@{id}` | 打开,右吸附(从下一个单词开始) |+| `@{~id}` | 打开,左吸附(从前一个单词的末尾开始) |+| `@{/id}` | 关闭,左吸附(在前一个单词的末尾结束) |+| `@{/id~}` | 关闭,右吸附(在下一个单词的起始处结束) |`~` 后缀/前缀控制边界是吸附到左边还是右边。默认的打开标记为右吸附;默认的关闭标记为左吸附。完整 Script 严格拥有 `2M + 2N + 2` 个有序语义锚点:每个 Token 两个、每个 Segment 两个,-再加 Program 自己的首尾。最外侧切口仍用 affinity 区分语义:第一个 Segment 前的 `~@id`-选择 Program start,`@id` 选择首 Segment start;末 Segment 后的 `@/id` 选择末 Segment end,-`@/id~` 选择 Program end。对齐后它们可能落在同一帧,但作者身份并不相同。+再加 Program 自己的首尾。最外侧切口仍用 affinity 区分语义:第一个 Segment 前的 `@{~id}`+选择 Program start,`@{id}` 选择首 Segment start;末 Segment 后的 `@{/id}` 选择末 Segment end,+`@{/id~}` 选择 Program end。对齐后它们可能落在同一帧,但作者身份并不相同。### 多个具名 Selection@@ -186,7 +201,7 @@ Selection 不要求像 XML 标签那样嵌套,它们可以互相交叉:```svml<demo>- <HOST> @a One @b two @/a three @/b.+ <HOST> @{a} One @{b} two @{/a} three @{/b}.</demo>```@@ -202,15 +217,15 @@ Moment 是具名的时间**点**(不是范围):```svml<ecosystem>- <HOST> @ranking! Image generation, video generation, captions and B-roll+ <HOST> @{ranking!} Image generation, video generation, captions and B-rollall become reusable components.</ecosystem>```| 标记 | 含义 ||---|---|-| `@id!` | 右吸附(时间点位于下一个单词的起始处) |-| `~@id!` | 左吸附(时间点位于前一个单词的末尾) |+| `@{id!}` | 右吸附(时间点位于下一个单词的起始处) |+| `@{~id!}` | 左吸附(时间点位于前一个单词的末尾) |每个 Moment 名字只出现一次,编译为带有 `anchorId` 的 `NarrativeMoment`。Selection 和 Moment共享同一命名空间——同一个 id 不能同时用于两者。@@ -246,26 +261,26 @@ Moment 是具名的时间**点**(不是范围):```svml<script id="story">- @whole+ @{whole}<hook>- <HOST> @problem Girls, you need to hear this. Never let anyone take credit- for your work. @/problem+ <HOST> @{problem} Girls, you need to hear this. Never let anyone take credit+ for your work. @{/problem}</hook><meeting>- <HOST> @solution I started sending <BCC | B C C> recaps after every- meeting: timestamps, decisions, who said what. @ranking! After- the first recap, everything changed. @/solution+ <HOST> @{solution} I started sending <BCC | B C C> recaps after every+ meeting: timestamps, decisions, who said what. @{ranking!} After+ the first recap, everything changed. @{/solution}</meeting><evidence>- <HOST> That gave me @emphasis the courage I was missing @/emphasis.+ <HOST> That gave me @{emphasis} the courage I was missing @{/emphasis}.</evidence><payoff><HOST> And guess what? I'm sitting in my old boss's chair now.</payoff>- @/whole~+ @{/whole~}</script>```diff --git a/examples/complex-explainer/productions/explainer/authors/script.svml b/examples/complex-explainer/productions/explainer/authors/script.svmlindex f156839d..cb5ed157 100644--- a/examples/complex-explainer/productions/explainer/authors/script.svml+++ b/examples/complex-explainer/productions/explainer/authors/script.svml@@ -4,55 +4,55 @@<script id="story"><opening>- <HOST> 一分钟带你了解最近超火的 || 开源视频复刻项目 @opening-brand! high pit。 || @begin! 开始咯!+ <HOST> 一分钟带你了解最近超火的 || 开源视频复刻项目 @{opening-brand!} high pit。 || @{begin!} 开始咯!</opening><introduction>- <HOST> Hypit是一个开源视频复刻框架, || @intro-language! 自创了一套视频领域语言。 || @intro-install! 把hypit skill装进你的 || @intro-codex! codex或者@intro-claude! <claude|cloud>, || @intro-thirty! 只要半小时就能拿到 || @intro-examples! 你想复刻的任何爆款视频, || 并且还换@intro-face! 上了你自己的脸 || 和@intro-product! 产品。+ <HOST> Hypit是一个开源视频复刻框架, || @{intro-language!} 自创了一套视频领域语言。 || @{intro-install!} 把hypit skill装进你的 || @{intro-codex!} codex或者@{intro-claude!} <claude|cloud>, || @{intro-thirty!} 只要半小时就能拿到 || @{intro-examples!} 你想复刻的任何爆款视频, || 并且还换@{intro-face!} 上了你自己的脸 || 和@{intro-product!} 产品。</introduction><competitors>- <HOST> 隔壁的 Creatify和@competitor-other! Higgsfield, || 一个月要@competitor-monthly! 收你几十美元 || @competitor-templates! 但只能照着模板做, || @competitor-cases! 不仅复刻不了爆款, || @competitor-watermark! 还会给你打他们家的水印哦。+ <HOST> 隔壁的 Creatify和@{competitor-other!} Higgsfield, || 一个月要@{competitor-monthly!} 收你几十美元 || @{competitor-templates!} 但只能照着模板做, || @{competitor-cases!} 不仅复刻不了爆款, || @{competitor-watermark!} 还会给你打他们家的水印哦。</competitors><two-roads>- <HOST> 那接下来我给你拆解 || @road-half! Hypit 的底层逻辑。 || @road-overview! 说白了, || 现在用 AI 做视频就@roads! 两条路嘛。+ <HOST> 那接下来我给你拆解 || @{road-half!} Hypit 的底层逻辑。 || @{road-overview!} 说白了, || 现在用 AI 做视频就@{roads!} 两条路嘛。</two-roads><editor-road>- <HOST> @road-editor! 第一条路是 || @road-operate! 让 AI 操作剪辑软件。 || @road-capcut! 别看有@road-premiere! 那么@road-resolve! 多种, || @road-same! 但逻辑都是一样的: || @road-assets! AI 先帮你把素材生成好, || @road-drag! 再一个个去贴到 || 时间轴和画布上。+ <HOST> @{road-editor!} 第一条路是 || @{road-operate!} 让 AI 操作剪辑软件。 || @{road-capcut!} 别看有@{road-premiere!} 那么@{road-resolve!} 多种, || @{road-same!} 但逻辑都是一样的: || @{road-assets!} AI 先帮你把素材生成好, || @{road-drag!} 再一个个去贴到 || 时间轴和画布上。</editor-road><keyframe-cost>- <HOST> @road-place! 虽然贴的还可以, || @road-fail! 但做动效就不行咯。 || 想让@road-number! 一个数字弹出来、 || 或者@road-image! 一张图飞进来, || @road-keys! 要么让 AI 在时间轴上 || 标出二十几个时间点, || @road-tokens! 烧掉几十万的token, || @road-generated! 要么用seedance直出, || @road-unstable! 不仅效果不稳定, || @road-styles! 而且还改不了样式。+ <HOST> @{road-place!} 虽然贴的还可以, || @{road-fail!} 但做动效就不行咯。 || 想让@{road-number!} 一个数字弹出来、 || 或者@{road-image!} 一张图飞进来, || @{road-keys!} 要么让 AI 在时间轴上 || 标出二十几个时间点, || @{road-tokens!} 烧掉几十万的token, || @{road-generated!} 要么用seedance直出, || @{road-unstable!} 不仅效果不稳定, || @{road-styles!} 而且还改不了样式。</keyframe-cost><code-road>- <HOST> @code-start! 第二条路是让 AI 去写代码。 || @code-remotion! Remotion和@code-hyperframes! Hyperframes, || 本质都是写@code-html! html, || @code-play! 动效想怎么做怎么做。+ <HOST> @{code-start!} 第二条路是让 AI 去写代码。 || @{code-remotion!} Remotion和@{code-hyperframes!} Hyperframes, || 本质都是写@{code-html!} html, || @{code-play!} 动效想怎么做怎么做。</code-road><reuse-cost>- <HOST> @code-once! 但代价是每条视频只能用一次了! || @code-variant! 下次想做个差不多的, || @code-copy! 得让 AI 把几千行的html || @code-duplicate! 原封不动抄一遍, || @code-tokens! 又会烧掉几十万的token;+ <HOST> @{code-once!} 但代价是每条视频只能用一次了! || @{code-variant!} 下次想做个差不多的, || @{code-copy!} 得让 AI 把几千行的html || @{code-duplicate!} 原封不动抄一遍, || @{code-tokens!} 又会烧掉几十万的token;</reuse-cost><timing-cost>- <HOST> @code-time! 而且更要命的是, || @code-different! 每条素材的稿子和配音都不一样, || @code-match! 为了让动效对上口播的时间, || @code-retime! 每次 AI 都得重新抄一遍时间点。+ <HOST> @{code-time!} 而且更要命的是, || @{code-different!} 每条素材的稿子和配音都不一样, || @{code-match!} 为了让动效对上口播的时间, || @{code-retime!} 每次 AI 都得重新抄一遍时间点。</timing-cost><water-break>- <HOST> @resume! 我们继续。+ <HOST> @{resume!} 我们继续。</water-break><synthesis>- <HOST> @solution! 而 Hypit 是把 @solution-roads! 这两条路上 || @solution-keep! 最值钱的东西都留下了, || @solution-drop! 最烧钱的东西都扔掉了!+ <HOST> @{solution!} 而 Hypit 是把 @{solution-roads!} 这两条路上 || @{solution-keep!} 最值钱的东西都留下了, || @{solution-drop!} 最烧钱的东西都扔掉了!</synthesis><components>- <HOST> 画布上呢, || 它把动效给组件化了: || @parts-all! 所有值得变成组件的东西, || 无论是@component-list @part-caption! 字幕、@part-ranking! 榜单、@part-chart! 图表、@part-card! 卡片 @/component-list, || @parts-library! AI 都只需要写一次, || @parts-reuse! 之后每条视频都能拿来复用, || 你想@parts-word! 换文案、@parts-picture! 换图、@parts-color! 换颜色, || @parts-swap! 一行代码都不用重写了!+ <HOST> 画布上呢, || 它把动效给组件化了: || @{parts-all!} 所有值得变成组件的东西, || 无论是@{component-list} @{part-caption!} 字幕、@{part-ranking!} 榜单、@{part-chart!} 图表、@{part-card!} 卡片 @{/component-list}, || @{parts-library!} AI 都只需要写一次, || @{parts-reuse!} 之后每条视频都能拿来复用, || 你想@{parts-word!} 换文案、@{parts-picture!} 换图、@{parts-color!} 换颜色, || @{parts-swap!} 一行代码都不用重写了!</components><semantic-time>- <HOST> 时间上呢, || 它是把稿子当做时间线的: || @sem-bind! 动效不是绑定在秒上, || 而是绑定在说的话上。+ <HOST> 时间上呢, || 它是把稿子当做时间线的: || @{sem-bind!} 动效不是绑定在秒上, || 而是绑定在说的话上。</semantic-time><semantic-demo>- <HOST> @sem-examples! 比如榜单在“@rank-reveal! 第一名”这个词上翻开, || 产品图在说“@product-reveal! hypit”这时候飞进来。 || @sem-rewrite-scene! 就算是重写 @sem-rewrite! 稿子、@sem-voice! 换掉了配音, || @sem-adapt! 动效依然都会精准出现, || @sem-syntax! 一个时间点都不用改了!+ <HOST> @{sem-examples!} 比如榜单在“@{rank-reveal!} 第一名”这个词上翻开, || 产品图在说“@{product-reveal!} hypit”这时候飞进来。 || @{sem-rewrite-scene!} 就算是重写 @{sem-rewrite!} 稿子、@{sem-voice!} 换掉了配音, || @{sem-adapt!} 动效依然都会精准出现, || @{sem-syntax!} 一个时间点都不用改了!</semantic-demo><result>- <HOST> 所以用 Hypit 来做视频, || @result-assets! 素材生成完就能直接拿到成片, || @result-upload! 连一秒钟的剪辑都不需要, || @result-compare! 而且跟原来那条爆款的效果 || 完全一模一样!+ <HOST> 所以用 Hypit 来做视频, || @{result-assets!} 素材生成完就能直接拿到成片, || @{result-upload!} 连一秒钟的剪辑都不需要, || @{result-compare!} 而且跟原来那条爆款的效果 || 完全一模一样!</result><reference-reveal>- <HOST> @result-meta! 这条视频就是用 @result-brand! Hypit || 复刻的一条爆款, || @result-guess! 你们猜得出原博主是哪位吗?+ <HOST> @{result-meta!} 这条视频就是用 @{result-brand!} Hypit || 复刻的一条爆款, || @{result-guess!} 你们猜得出原博主是哪位吗?</reference-reveal><closing>- <HOST> 哎呀说好一分钟的 || @outro-overtime! 怎么超时这么久了。 || @outro-github! <Github|Git Hub> 搜索 Hypit, || @outro-copy! 一键复制skill || @outro-install! 装进你的 coding agent; || @outro-gift! 还能免费领取 || 一百个口播数字人哦! || @outro-bye! 我们下期见, || 拜拜~+ <HOST> 哎呀说好一分钟的 || @{outro-overtime!} 怎么超时这么久了。 || @{outro-github!} <Github|Git Hub> 搜索 Hypit, || @{outro-copy!} 一键复制skill || @{outro-install!} 装进你的 coding agent; || @{outro-gift!} 还能免费领取 || 一百个口播数字人哦! || @{outro-bye!} 我们下期见, || 拜拜~</closing></script></svml>diff --git a/examples/interview/reference.svml b/examples/interview/reference.svmlindex c71b1fe4..ca0d6799 100644--- a/examples/interview/reference.svml+++ b/examples/interview/reference.svml@@ -32,7 +32,7 @@<BOY>Hey yo! || Is this || Lamborghini || yours?<WIFE>Mmm hmm.<BOY>Give me || three rules || to make your || first million.- <WIFE>OK || the || first one || is || @manifest! Manifest.+ <WIFE>OK || the || first one || is || @{manifest!} Manifest.<BOY>You manifested || a Lamborghini?<WIFE>I || said it || to || myself || every || morning.</manifest-rule>@@ -41,14 +41,14 @@<BOY>Did it really || work?<WIFE>No. || But || rule two || did.<BOY>Say it.- <WIFE>@real-estate! Real estate. || Buy || the || building, || and || charge || everyone || rent.+ <WIFE>@{real-estate!} Real estate. || Buy || the || building, || and || charge || everyone || rent.<BOY>But how did you || buy the building?<WIFE>That's || rule three.</real-estate-rule><bitcoin-rule><BOY>Wait what?- <WIFE>@bitcoin! Bitcoin. || I || pressed || the || wrong || button || in <2012 | twenty twelve> || and || made || six figures.+ <WIFE>@{bitcoin!} Bitcoin. || I || pressed || the || wrong || button || in <2012 | twenty twelve> || and || made || six figures.<BOY>So you || accidentally || bought Bitcoin?!<WIFE>That's || manifesting, || baby.</bitcoin-rule>diff --git a/examples/interview/swap-host.svml b/examples/interview/swap-host.svmlindex 2d1187ca..e4ba8043 100644--- a/examples/interview/swap-host.svml+++ b/examples/interview/swap-host.svml@@ -31,7 +31,7 @@<CHAD>Hey yo! || Is this Lamborghini || yours?<WOJAK>Um, || yeah.<CHAD>Give me three rules || to make your || first million.- <WOJAK>OK || the || first one || is || @manifest! Manifest.+ <WOJAK>OK || the || first one || is || @{manifest!} Manifest.<CHAD>You manifested || a Lamborghini?<WOJAK>I || whispered || it || to || myself || in || the || shower.</manifest-rule>@@ -40,14 +40,14 @@<CHAD>Did it really || work?<WOJAK>No. || But || rule two || did.<CHAD>Say it.- <WOJAK>@real-estate! Real estate. || Buy || the || building, || and || charge || everyone || rent.+ <WOJAK>@{real-estate!} Real estate. || Buy || the || building, || and || charge || everyone || rent.<CHAD>But how did you || buy the building?<WOJAK>That's || rule three.</real-estate-rule><bitcoin-rule><CHAD>Wait what?- <WOJAK>@bitcoin! Bitcoin. || I || pressed || the || wrong || button || in <2012 | twenty twelve> || and || made || six figures.+ <WOJAK>@{bitcoin!} Bitcoin. || I || pressed || the || wrong || button || in <2012 | twenty twelve> || and || made || six figures.<CHAD>So you || accidentally || bought Bitcoin?!<WOJAK>That's || manifesting, || bro.</bitcoin-rule>diff --git a/examples/interview/swap-lang.svml b/examples/interview/swap-lang.svmlindex 734f5b3c..8779f507 100644--- a/examples/interview/swap-lang.svml+++ b/examples/interview/swap-lang.svml@@ -30,9 +30,9 @@<script id="story"><manifest-rule><BOY>Oye! || Este Ferrari || es tuyo?- <WIFE>@aja! Ajá.+ <WIFE>@{aja!} Ajá.<BOY>Dame tres reglas || para ganar || tu primer millón.- <WIFE>OK || la || primera || es || @manifest! Manifestar.+ <WIFE>OK || la || primera || es || @{manifest!} Manifestar.<BOY>Manifestaste || un Ferrari?<WIFE>Me lo || repetí || cada || mañana.</manifest-rule>@@ -41,14 +41,14 @@<BOY>Y funcionó?<WIFE>No. || Pero || la dos || sí.<BOY>Dime.- <WIFE>@real-estate! Bienes raíces. || Compra || el || edificio || y cóbrales || renta a || todos.+ <WIFE>@{real-estate!} Bienes raíces. || Compra || el || edificio || y cóbrales || renta a || todos.<BOY>Pero || cómo compraste || el edificio?<WIFE>Esa || es || la tres.</real-estate-rule><bitcoin-rule><BOY>Espera qué?- <WIFE>@bitcoin! Bitcoin. || Apreté || el || botón || equivocado || en <2012 | dos mil doce> || y gané || seis || cifras.+ <WIFE>@{bitcoin!} Bitcoin. || Apreté || el || botón || equivocado || en <2012 | dos mil doce> || y gané || seis || cifras.<BOY>Compraste Bitcoin || por accidente?!<WIFE>Eso || es || manifestar, || cariño.</bitcoin-rule>diff --git a/examples/interview/swap-ride.svml b/examples/interview/swap-ride.svmlindex 9a24116c..e21694fb 100644--- a/examples/interview/swap-ride.svml+++ b/examples/interview/swap-ride.svml@@ -31,7 +31,7 @@<LEON>Hey yo! || Is this <F1 | F One> car || yours?<ADA>Mmm hmm.<LEON>Give me three rules || to make your || first million.- <ADA>OK || the || first one || is || @uber! Uber.+ <ADA>OK || the || first one || is || @{uber!} Uber.<LEON>You drove || Uber?<ADA>Two || years. || Five || stars || for || every || single || ride.</uber-rule>@@ -40,7 +40,7 @@<LEON>Did that || make you || a million?<ADA>No. || But || rule two || did.<LEON>Say it.- <ADA>@shortcuts! Shortcuts. || Take || every || single || one.+ <ADA>@{shortcuts!} Shortcuts. || Take || every || single || one.<LEON>Like on the track?<ADA>Like on || Google || Maps. || I || missed || my || exit || and || ended up || on a || racetrack.<LEON>Wait like || during a race?@@ -49,7 +49,7 @@<first-place-rule><LEON>What?!- <ADA>I won || the || @first-place! First || place || so || they || gave me || the car.+ <ADA>I won || the || @{first-place!} First || place || so || they || gave me || the car.<LEON>So you won an || <F1 | F One> race || by accident?!<ADA>Five star || driver, || baby.</first-place-rule>diff --git a/examples/podcast/reference.svml b/examples/podcast/reference.svmlindex b9b24971..0e7ebda6 100644--- a/examples/podcast/reference.svml+++ b/examples/podcast/reference.svml@@ -32,8 +32,8 @@<GUY>OK Sarah || so what is || the one single thing || that you literally || can't live without?</opening-question><daily-creatine>- <GIRL>Creatine. Five grams || a day, every day. ~@lifestyle || I put it || in my coffee, || my smoothie, || and even my || pasta water.- <GUY>God I think || you're treating this @/lifestyle || as flour.+ <GIRL>Creatine. Five grams || a day, every day. @{~lifestyle} || I put it || in my coffee, || my smoothie, || and even my || pasta water.+ <GUY>God I think || you're treating this @{/lifestyle} || as flour.</daily-creatine><arms-are-asking><GIRL>But actually you || need this way || more than I do.diff --git a/examples/podcast/swap-app.svml b/examples/podcast/swap-app.svmlindex 6703ff1e..bcea63f3 100644--- a/examples/podcast/swap-app.svml+++ b/examples/podcast/swap-app.svml@@ -29,8 +29,8 @@<NERD>OK big guy || so what is || the one single thing || that you literally || can't live without?</opening-question><daily-cheatgpt>- <JOCK>CheatGPT. Every single day || since sophomore year. ~@lifestyle || For my essays, || my emails, || and even || my wedding vows.- <NERD>You used AI || on your @/lifestyle vows?+ <JOCK>CheatGPT. Every single day || since sophomore year. @{~lifestyle} || For my essays, || my emails, || and even || my wedding vows.+ <NERD>You used AI || on your @{/lifestyle} vows?</daily-cheatgpt><brain-is-asking><JOCK>And guess what? || She cried. || Sent you the link.diff --git a/examples/podcast/swap-host.svml b/examples/podcast/swap-host.svmlindex 4a40017f..df1aa3ef 100644--- a/examples/podcast/swap-host.svml+++ b/examples/podcast/swap-host.svml@@ -29,8 +29,8 @@<DOGE>OK <Pepe | PEP-ay> || so what is || the one single thing || that you literally || can't live without?</opening-question><daily-creatine>- <PEPE>Creatine. Ten grams || a day, every day. ~@lifestyle || Before my workout, || after my workout, || and honestly? || During my workout.- <DOGE>Bro that @/lifestyle sounds || like an addiction.+ <PEPE>Creatine. Ten grams || a day, every day. @{~lifestyle} || Before my workout, || after my workout, || and honestly? || During my workout.+ <DOGE>Bro that @{/lifestyle} sounds || like an addiction.</daily-creatine><arms-are-asking><PEPE>You know what's || an addiction? || Being skinny. || Take this.diff --git a/examples/podcast/swap-item.svml b/examples/podcast/swap-item.svmlindex 8b907cb1..7c3cd897 100644--- a/examples/podcast/swap-item.svml+++ b/examples/podcast/swap-item.svml@@ -29,8 +29,8 @@<TBOY>OK pretty boy || so what is || the one single thing || that you literally || can't live without?</opening-question><daily-retinol>- <IDOL>Retinol. || Every single night || for three years. ~@lifestyle || After my cleanser, || before my || moisturizer, || I literally set || an alarm for it.- <TBOY>You set @/lifestyle an alarm || for face cream?+ <IDOL>Retinol. || Every single night || for three years. @{~lifestyle} || After my cleanser, || before my || moisturizer, || I literally set || an alarm for it.+ <TBOY>You set @{/lifestyle} an alarm || for face cream?</daily-retinol><skin-is-asking><IDOL>You know what || needs an alarm? || That forehead. || Here.diff --git a/examples/ranking-football/reference-banana-from-swap/reference-banana-from-swap.svml b/examples/ranking-football/reference-banana-from-swap/reference-banana-from-swap.svmlindex bd4f6bbc..c3194a61 100644--- a/examples/ranking-football/reference-banana-from-swap/reference-banana-from-swap.svml+++ b/examples/ranking-football/reference-banana-from-swap/reference-banana-from-swap.svml@@ -29,10 +29,10 @@TierBoard consumes windows without finding frames. Cue breaks are author intent. --><script id="story"><ronaldo>- <HOST>Ronaldo is <D | Dee> tier. || Bro has @hair-gel more || hair gel than @trophy trophies || at this point@/trophy@/hair-gel. || Built like || @greek-god a Greek god, || plays like || @greek-tragedy a Greek tragedy@/greek-tragedy@/greek-god. || But hey, || at least @penaldo-social he's got || the most followers || on Instagram@/penaldo-social.+ <HOST>Ronaldo is <D | Dee> tier. || Bro has @{hair-gel} more || hair gel than @{trophy} trophies || at this point@{/trophy}@{/hair-gel}. || Built like || @{greek-god} a Greek god, || plays like || @{greek-tragedy} a Greek tragedy@{/greek-tragedy}@{/greek-god}. || But hey, || at least @{penaldo-social} he's got || the most followers || on Instagram@{/penaldo-social}.</ronaldo><messi>- <HOST>Messi? Man won || a World Cup || @tired-dad looking like || somebody's tired dad@/tired-dad. || Walks around || @walks-around for 89 minutes, || touches the ball || three times, || and somehow || @hat-trick you just watched || a hat trick@/hat-trick@/walks-around. || Definitely <S | Ess> tier.+ <HOST>Messi? Man won || a World Cup || @{tired-dad} looking like || somebody's tired dad@{/tired-dad}. || Walks around || @{walks-around} for 89 minutes, || touches the ball || three times, || and somehow || @{hat-trick} you just watched || a hat trick@{/hat-trick}@{/walks-around}. || Definitely <S | Ess> tier.</messi></script>diff --git a/examples/ranking-football/reference-banana/reference-banana.svml b/examples/ranking-football/reference-banana/reference-banana.svmlindex bd4f6bbc..c3194a61 100644--- a/examples/ranking-football/reference-banana/reference-banana.svml+++ b/examples/ranking-football/reference-banana/reference-banana.svml@@ -29,10 +29,10 @@TierBoard consumes windows without finding frames. Cue breaks are author intent. --><script id="story"><ronaldo>- <HOST>Ronaldo is <D | Dee> tier. || Bro has @hair-gel more || hair gel than @trophy trophies || at this point@/trophy@/hair-gel. || Built like || @greek-god a Greek god, || plays like || @greek-tragedy a Greek tragedy@/greek-tragedy@/greek-god. || But hey, || at least @penaldo-social he's got || the most followers || on Instagram@/penaldo-social.+ <HOST>Ronaldo is <D | Dee> tier. || Bro has @{hair-gel} more || hair gel than @{trophy} trophies || at this point@{/trophy}@{/hair-gel}. || Built like || @{greek-god} a Greek god, || plays like || @{greek-tragedy} a Greek tragedy@{/greek-tragedy}@{/greek-god}. || But hey, || at least @{penaldo-social} he's got || the most followers || on Instagram@{/penaldo-social}.</ronaldo><messi>- <HOST>Messi? Man won || a World Cup || @tired-dad looking like || somebody's tired dad@/tired-dad. || Walks around || @walks-around for 89 minutes, || touches the ball || three times, || and somehow || @hat-trick you just watched || a hat trick@/hat-trick@/walks-around. || Definitely <S | Ess> tier.+ <HOST>Messi? Man won || a World Cup || @{tired-dad} looking like || somebody's tired dad@{/tired-dad}. || Walks around || @{walks-around} for 89 minutes, || touches the ball || three times, || and somehow || @{hat-trick} you just watched || a hat trick@{/hat-trick}@{/walks-around}. || Definitely <S | Ess> tier.</messi></script>diff --git a/examples/ranking-football/reference-gpt.svml b/examples/ranking-football/reference-gpt.svmlindex e1da5295..b2b02842 100644--- a/examples/ranking-football/reference-gpt.svml+++ b/examples/ranking-football/reference-gpt.svml@@ -29,10 +29,10 @@TierBoard consumes windows without finding frames. Cue breaks are author intent. --><script id="story"><ronaldo>- <HOST>Ronaldo is <D | Dee> tier. || Bro has @hair-gel more || hair gel than @trophy trophies || at this point@/trophy@/hair-gel. || Built like || @greek-god a Greek god, || plays like || @greek-tragedy a Greek tragedy@/greek-tragedy@/greek-god. || But hey, || at least @penaldo-social he's got || the most followers || on Instagram@/penaldo-social.+ <HOST>Ronaldo is <D | Dee> tier. || Bro has @{hair-gel} more || hair gel than @{trophy} trophies || at this point@{/trophy}@{/hair-gel}. || Built like || @{greek-god} a Greek god, || plays like || @{greek-tragedy} a Greek tragedy@{/greek-tragedy}@{/greek-god}. || But hey, || at least @{penaldo-social} he's got || the most followers || on Instagram@{/penaldo-social}.</ronaldo><messi>- <HOST>Messi? Man won || a World Cup || @tired-dad looking like || somebody's tired dad@/tired-dad. || Walks around || @walks-around for 89 minutes, || touches the ball || three times, || and somehow || @hat-trick you just watched || a hat trick@/hat-trick@/walks-around. || Definitely <S | Ess> tier.+ <HOST>Messi? Man won || a World Cup || @{tired-dad} looking like || somebody's tired dad@{/tired-dad}. || Walks around || @{walks-around} for 89 minutes, || touches the ball || three times, || and somehow || @{hat-trick} you just watched || a hat trick@{/hat-trick}@{/walks-around}. || Definitely <S | Ess> tier.</messi></script>diff --git a/examples/ranking-football/reference.svml b/examples/ranking-football/reference.svmlindex 63464cdd..529df8fd 100644--- a/examples/ranking-football/reference.svml+++ b/examples/ranking-football/reference.svml@@ -31,10 +31,10 @@TierBoard consumes windows without finding frames. Cue breaks are author intent. --><script id="story"><ronaldo>- <HOST>Ronaldo is <D | Dee> tier. || Bro has @hair-gel more || hair gel than @trophy trophies || at this point@/trophy@/hair-gel. || Built like || @greek-god a Greek god, || plays like || @greek-tragedy a Greek tragedy@/greek-tragedy@/greek-god. || But hey, || at least @penaldo-social he's got || the most followers || on Instagram@/penaldo-social.+ <HOST>Ronaldo is <D | Dee> tier. || Bro has @{hair-gel} more || hair gel than @{trophy} trophies || at this point@{/trophy}@{/hair-gel}. || Built like || @{greek-god} a Greek god, || plays like || @{greek-tragedy} a Greek tragedy@{/greek-tragedy}@{/greek-god}. || But hey, || at least @{penaldo-social} he's got || the most followers || on Instagram@{/penaldo-social}.</ronaldo><messi>- <HOST>Messi? Man won || a World Cup || @tired-dad looking like || somebody's tired dad@/tired-dad. || Walks around || @walks-around for 89 minutes, || touches the ball || three times, || and somehow || @hat-trick you just watched || a hat trick@/hat-trick@/walks-around. || Definitely <S | Ess> tier.+ <HOST>Messi? Man won || a World Cup || @{tired-dad} looking like || somebody's tired dad@{/tired-dad}. || Walks around || @{walks-around} for 89 minutes, || touches the ball || three times, || and somehow || @{hat-trick} you just watched || a hat trick@{/hat-trick}@{/walks-around}. || Definitely <S | Ess> tier.</messi></script>diff --git a/examples/ranking-football/swap-effect-banana-reference-sync/swap-effect-banana-reference-sync.svml b/examples/ranking-football/swap-effect-banana-reference-sync/swap-effect-banana-reference-sync.svmlindex d73d4c8a..8de5a7e2 100644--- a/examples/ranking-football/swap-effect-banana-reference-sync/swap-effect-banana-reference-sync.svml+++ b/examples/ranking-football/swap-effect-banana-reference-sync/swap-effect-banana-reference-sync.svml@@ -29,10 +29,10 @@TierBoard consumes windows without finding frames. Cue breaks are author intent. --><script id="story"><ronaldo>- <HOST>Ronaldo is <D | Dee> tier. || Bro has @hair-gel more || hair gel than @trophy trophies || at this point@/trophy@/hair-gel. || Built like || @greek-god a Greek god, || plays like || @greek-tragedy a Greek tragedy@/greek-tragedy@/greek-god. || But hey, || at least @penaldo-social he's got || the most followers || on Instagram@/penaldo-social.+ <HOST>Ronaldo is <D | Dee> tier. || Bro has @{hair-gel} more || hair gel than @{trophy} trophies || at this point@{/trophy}@{/hair-gel}. || Built like || @{greek-god} a Greek god, || plays like || @{greek-tragedy} a Greek tragedy@{/greek-tragedy}@{/greek-god}. || But hey, || at least @{penaldo-social} he's got || the most followers || on Instagram@{/penaldo-social}.</ronaldo><messi>- <HOST>Messi? Man won || a World Cup || @tired-dad looking like || somebody's tired dad@/tired-dad. || Walks around || @walks-around for 89 minutes, || touches the ball || three times, || and somehow || @hat-trick you just watched || a hat trick@/hat-trick@/walks-around. || Definitely <S | Ess> tier.+ <HOST>Messi? Man won || a World Cup || @{tired-dad} looking like || somebody's tired dad@{/tired-dad}. || Walks around || @{walks-around} for 89 minutes, || touches the ball || three times, || and somehow || @{hat-trick} you just watched || a hat trick@{/hat-trick}@{/walks-around}. || Definitely <S | Ess> tier.</messi></script>diff --git a/examples/ranking-football/swap-effect-banana/swap-effect-banana.svml b/examples/ranking-football/swap-effect-banana/swap-effect-banana.svmlindex 929979eb..cc3a6cdb 100644--- a/examples/ranking-football/swap-effect-banana/swap-effect-banana.svml+++ b/examples/ranking-football/swap-effect-banana/swap-effect-banana.svml@@ -28,10 +28,10 @@Ronaldo Segments are also the two disjoint Column reveal windows. --><script id="story"><messi>- <HOST>Messi is the bottom. || Five foot seven, || no muscles, || no speed, || just vibes. || @pitch-pov Man walks around || the pitch like || @ikea-sign he's lost in <IKEA | eye KEE uh>@/ikea-sign@/pitch-pov. || @retirement-room Went to Miami || and turned the league || into a retirement home@/retirement-room.+ <HOST>Messi is the bottom. || Five foot seven, || no muscles, || no speed, || just vibes. || @{pitch-pov} Man walks around || the pitch like || @{ikea-sign} he's lost in <IKEA | eye KEE uh>@{/ikea-sign}@{/pitch-pov}. || @{retirement-room} Went to Miami || and turned the league || into a retirement home@{/retirement-room}.</messi><ronaldo>- <HOST>Ronaldo? Bro is || 39 years old || @rent-jump and still jumps || higher than your rent@/rent-jump. || @nine-hundred-goals Nine hundred goals, || @laboratory-body a body built || in a laboratory, || @museum-jawline and a jawline || that belongs || in a museum@/museum-jawline@/laboratory-body@/nine-hundred-goals. || Absolutely the top one.+ <HOST>Ronaldo? Bro is || 39 years old || @{rent-jump} and still jumps || higher than your rent@{/rent-jump}. || @{nine-hundred-goals} Nine hundred goals, || @{laboratory-body} a body built || in a laboratory, || @{museum-jawline} and a jawline || that belongs || in a museum@{/museum-jawline}@{/laboratory-body}@{/nine-hundred-goals}. || Absolutely the top one.</ronaldo></script>diff --git a/examples/ranking-football/swap-effect.svml b/examples/ranking-football/swap-effect.svmlindex e092fd63..5568c289 100644--- a/examples/ranking-football/swap-effect.svml+++ b/examples/ranking-football/swap-effect.svml@@ -28,10 +28,10 @@Ronaldo Segments are also the two disjoint Column reveal windows. --><script id="story"><messi>- <HOST>Messi is the bottom. || Five foot seven, || no muscles, || no speed, || just vibes. || @pitch-pov Man walks around || the pitch like || @ikea-sign he's lost in <IKEA | eye KEE uh>@/ikea-sign@/pitch-pov. || @retirement-room Went to Miami || and turned the league || into a retirement home@/retirement-room.+ <HOST>Messi is the bottom. || Five foot seven, || no muscles, || no speed, || just vibes. || @{pitch-pov} Man walks around || the pitch like || @{ikea-sign} he's lost in <IKEA | eye KEE uh>@{/ikea-sign}@{/pitch-pov}. || @{retirement-room} Went to Miami || and turned the league || into a retirement home@{/retirement-room}.</messi><ronaldo>- <HOST>Ronaldo? Bro is || 39 years old || @rent-jump and still jumps || higher than your rent@/rent-jump. || @nine-hundred-goals Nine hundred goals, || @laboratory-body a body built || in a laboratory, || @museum-jawline and a jawline || that belongs || in a museum@/museum-jawline@/laboratory-body@/nine-hundred-goals. || Absolutely the top one.+ <HOST>Ronaldo? Bro is || 39 years old || @{rent-jump} and still jumps || higher than your rent@{/rent-jump}. || @{nine-hundred-goals} Nine hundred goals, || @{laboratory-body} a body built || in a laboratory, || @{museum-jawline} and a jawline || that belongs || in a museum@{/museum-jawline}@{/laboratory-body}@{/nine-hundred-goals}. || Absolutely the top one.</ronaldo></script>diff --git a/examples/ranking-football/swap-host.svml b/examples/ranking-football/swap-host.svmlindex 0ea12add..5a907cbe 100644--- a/examples/ranking-football/swap-host.svml+++ b/examples/ranking-football/swap-host.svml@@ -29,10 +29,10 @@TierBoard consumes windows without finding frames. Cue breaks are author intent. --><script id="story"><ronaldo>- <HOST>Ronaldo is <D | Dee> tier. || Bro has @hair-gel more || hair gel than @trophy trophies || at this point@/trophy@/hair-gel. || Built like || @greek-god a Greek god, || plays like || @greek-tragedy a Greek tragedy@/greek-tragedy@/greek-god. || But hey, || at least @penaldo-social he's got || the most followers || on Instagram@/penaldo-social.+ <HOST>Ronaldo is <D | Dee> tier. || Bro has @{hair-gel} more || hair gel than @{trophy} trophies || at this point@{/trophy}@{/hair-gel}. || Built like || @{greek-god} a Greek god, || plays like || @{greek-tragedy} a Greek tragedy@{/greek-tragedy}@{/greek-god}. || But hey, || at least @{penaldo-social} he's got || the most followers || on Instagram@{/penaldo-social}.</ronaldo><messi>- <HOST>Messi? Man won || a World Cup || @tired-dad looking like || somebody's tired dad@/tired-dad. || Walks around || @walks-around for 89 minutes, || touches the ball || three times, || and somehow || @hat-trick you just watched || a hat trick@/hat-trick@/walks-around. || Definitely <S | Ess> tier.+ <HOST>Messi? Man won || a World Cup || @{tired-dad} looking like || somebody's tired dad@{/tired-dad}. || Walks around || @{walks-around} for 89 minutes, || touches the ball || three times, || and somehow || @{hat-trick} you just watched || a hat trick@{/hat-trick}@{/walks-around}. || Definitely <S | Ess> tier.</messi></script>diff --git a/examples/ranking-football/swap-topic.svml b/examples/ranking-football/swap-topic.svmlindex a0cc7abf..7f2eb3b9 100644--- a/examples/ranking-football/swap-topic.svml+++ b/examples/ranking-football/swap-topic.svml@@ -28,10 +28,10 @@Every B-roll insert consumes an authored semantic Selection. --><script id="story"><elon>- <HOST>Elon is <D | Dee> tier. || @money-rain Man bought Twitter || for 44 billion dollars || @twitter-x just to change || the name@/twitter-x@/money-rain. || @mars-rocket Sends rockets || to Mars, || but @market-crash can't send a tweet || without crashing || the stock market@/market-crash@/mars-rocket. || @richest-chair Richest guy || on Earth, || but somehow || @haircut-x still can't buy || a good haircut@/haircut-x@/richest-chair.+ <HOST>Elon is <D | Dee> tier. || @{money-rain} Man bought Twitter || for 44 billion dollars || @{twitter-x} just to change || the name@{/twitter-x}@{/money-rain}. || @{mars-rocket} Sends rockets || to Mars, || but @{market-crash} can't send a tweet || without crashing || the stock market@{/market-crash}@{/mars-rocket}. || @{richest-chair} Richest guy || on Earth, || but somehow || @{haircut-x} still can't buy || a good haircut@{/haircut-x}@{/richest-chair}.</elon><sam>- <HOST>Sam Altman? || @fired-friday Guy got fired || on a Friday, || @company-quit the entire company || threatened to quit, || and @back-monday he was back || in the chair || by Monday@/back-monday@/company-quit@/fired-friday. || @elon-lawsuit Elon sued him, || @google-fears Google fears him, || @congress-grilled Congress grilled him, || @still-here and he's still here@/still-here@/congress-grilled@/google-fears@/elon-lawsuit. || I have to || put him in || <S | Ess> tier.+ <HOST>Sam Altman? || @{fired-friday} Guy got fired || on a Friday, || @{company-quit} the entire company || threatened to quit, || and @{back-monday} he was back || in the chair || by Monday@{/back-monday}@{/company-quit}@{/fired-friday}. || @{elon-lawsuit} Elon sued him, || @{google-fears} Google fears him, || @{congress-grilled} Congress grilled him, || @{still-here} and he's still here@{/still-here}@{/congress-grilled}@{/google-fears}@{/elon-lawsuit}. || I have to || put him in || <S | Ess> tier.</sam></script>diff --git a/examples/semantic-composition/packages/responsive-explainer/README.md b/examples/semantic-composition/packages/responsive-explainer/README.mdindex c5146ca4..300d19f8 100644--- a/examples/semantic-composition/packages/responsive-explainer/README.md+++ b/examples/semantic-composition/packages/responsive-explainer/README.md@@ -30,7 +30,7 @@ With prepared Takes, a Canvas and an exact FontStack already available:````during` also accepts a Script Selection or Segment; the shared Window syntax supports other authored-intervals. `reveal` selects a Script Moment, such as `@demonstrate!` before the relevant word. Rewriting+intervals. `reveal` selects a Script Moment, such as `@{demonstrate!}` before the relevant word. Rewritingthe Script or using another delivery changes the projected frame while retaining the layout behavior.`transition-frames` is the duration of that change, separate from the scene's lifetime. `stack-order`places this scene among other contributions. The caller supplies its title and exact fonts.diff --git a/package.json b/package.jsonindex d6c452f8..8488c370 100644--- a/package.json+++ b/package.json@@ -1,6 +1,6 @@{"name": "@hypit/hypit",- "version": "0.1.14",+ "version": "0.2.0","homepage": "https://hypit.ai","repository": {"type": "git",diff --git a/packages/caption-fine-studio/test/adapter.test.ts b/packages/caption-fine-studio/test/adapter.test.tsindex 3cb1c4f3..f267e2a3 100644--- a/packages/caption-fine-studio/test/adapter.test.ts+++ b/packages/caption-fine-studio/test/adapter.test.ts@@ -38,8 +38,8 @@ test("Caption Companion projects Cue text and Style from public domain values",narrativeId: "story",units: [{ id: "unit-1", segmentId: "segment-1", turnId: "turn-1", wordIds: ["word-1", "word-2"], sourceTokenIds: ["token-1"] }],words: [- { id: "word-1", unitId: "unit-1", segmentId: "segment-1", turnId: "turn-1", text: "真实", attributes: [] },- { id: "word-2", unitId: "unit-1", segmentId: "segment-1", turnId: "turn-1", text: "字幕", attributes: [] },+ { id: "word-1", unitId: "unit-1", segmentId: "segment-1", turnId: "turn-1", text: "真实", separatorBefore: "", attributes: [] },+ { id: "word-2", unitId: "unit-1", segmentId: "segment-1", turnId: "turn-1", text: "字幕", separatorBefore: "", attributes: [] },],cueBreaks: [],};diff --git a/packages/caption-fine/README.md b/packages/caption-fine/README.mdindex 58feb8c0..1cfd3644 100644--- a/packages/caption-fine/README.md+++ b/packages/caption-fine/README.md@@ -82,8 +82,8 @@ caption.primary {## Language, spacing and line layout-The same Caption pipeline serves English and Chinese. Script emits English lexical words and-individual Han characters as Display Words; punctuation stays with its display word. Fine uses+The same Caption pipeline serves authored text across writing systems. Script emits lexical words+and individual Han characters as Display Words; punctuation stays with its display word. Fine usesthose units for timing and active Paint, while authored Cues remain complete reading phrases.Dual Text retains its complete alignment unit even when it displays or speaks several words.@@ -94,9 +94,11 @@ explicit authored group, not a renderer-selected segmentation, and does not intrThe underlying character anchors remain available to other Timeline consumers. `wipe` and`typewriter` still animate inside the complete unit over its interval when deliberately selected.-`word-gap` applies between Latin words and at Chinese/Latin boundaries. Adjacent Han characters and-full-width punctuation carry no extra word gap. `letter-spacing` controls glyph tracking. Exact-font fallbacks supply the required glyphs; the layout does not select a font by language.+`word-gap` sizes the separators authored in `CaptionDisplayWord.separatorBefore`. A numeric or+writing-system boundary does not create a space: `3D` and `3개월` stay joined, while `是的 就是这样`+keeps its space. Base text, active text, underlines and joined boxes consume the same boundaries.+`letter-spacing` controls glyph tracking. Exact font fallbacks supply the required glyphs; the layout+does not select a font by language.| Control | Behavior || --- | --- |diff --git a/packages/caption-fine/src/manifest.ts b/packages/caption-fine/src/manifest.tsindex 266ccc09..9c460d09 100644--- a/packages/caption-fine/src/manifest.ts+++ b/packages/caption-fine/src/manifest.ts@@ -75,7 +75,7 @@ export const captionFineMarkupSurfaces = [{ name: "letter-spacing", required: false, fallback: "0",summary: "Adds pixels of tracking between glyphs." },{ name: "word-gap", required: false, fallback: "a quarter of size",- summary: "Sets pixel spacing between Latin words and at Chinese/Latin boundaries. Adjacent Han characters and full-width punctuation have no extra word gap; use letter-spacing for tracking." },+ summary: "Sets the pixel width of authored display separators. Writing-system and numeric boundaries do not create spaces; use letter-spacing for glyph tracking." },{ name: "size", required: true,summary: "Sets the type size in pixels." },{ name: "kerning", required: false, values: ["auto", "normal", "none"], fallback: "auto",diff --git a/packages/caption-fine/src/render.ts b/packages/caption-fine/src/render.tsindex 02ce6f02..ae1540bc 100644--- a/packages/caption-fine/src/render.ts+++ b/packages/caption-fine/src/render.ts@@ -13,14 +13,14 @@ import type {VisualTextPaintLayer,VisualTrack,} from "@hypit/composition";-import type { CaptionAlignmentUnit, CaptionDocument } from "@hypit/narrative";+import type { CaptionAlignmentUnit, CaptionDocument, CaptionDisplayWord } from "@hypit/narrative";import { assertProgramSpaceIdentity, programSpaceFrameCount } from "@hypit/program-space";import { assertSpatialRegionTimeline } from "@hypit/spatial";import type { CanvasSpace, SpatialFrame, SpatialRegionTimeline } from "@hypit/spatial";import { assertFineCaptionParameters, FINE_CAPTION_FAMILY } from "./style.js";import { assertFineCaptionSchedule } from "./schedule.js";-import { joinSurfaces, uniformGap, wordGapBetween, wordGaps } from "./spacing.js";+import { uniformGap, wordGaps } from "./spacing.js";import type {FineCaptionActiveUnderline,FineCaptionGlyphPaint,@@ -621,20 +621,17 @@ function trackedPlacementAnimation(return { keyframes };}-function structuralRowCount(- atoms: readonly CaptionAlignmentUnit[],- maxWordsPerLine: number,-): number {- let rows = atoms.length === 0 ? 0 : 1;+function structuralRowStarts(atoms: readonly CaptionAlignmentUnit[], maxWordsPerLine?: number): ReadonlySet<number> {+ const starts = new Set<number>();let wordsOnRow = 0;- for (const atom of atoms) {- if (wordsOnRow > 0 && wordsOnRow + atom.wordIds.length > maxWordsPerLine) {- rows += 1;+ for (const [index, atom] of atoms.entries()) {+ if (index === 0 || (maxWordsPerLine !== undefined && wordsOnRow > 0 && wordsOnRow + atom.wordIds.length > maxWordsPerLine)) {+ starts.add(index);wordsOnRow = 0;}wordsOnRow += atom.wordIds.length;}- return rows;+ return starts;}/**@@ -665,7 +662,7 @@ function cueElements(atoms: readonly CaptionAlignmentUnit[],atomFrames: ReadonlyMap<string, { readonly start: number; readonly end: number }>,parameters: FineCaptionParameters,- wordText: ReadonlyMap<string, string>,+ wordText: ReadonlyMap<string, CaptionDisplayWord>,durationFrames: number,styleId: string,trackedPlacement?: {@@ -694,21 +691,21 @@ function cueElements(const cueLoop = parameters.motion.loopTarget === "cue" ? loopAnimation(parameters, durationFrames) : undefined;const activationFrames = exclusiveActivationFrames(atoms, atomFrames);const gapPx = `${compactNumber(parameters.layout.wordGapPx)}px`;- const atomSurfaces = atoms.map((atom) => atom.wordIds.map((wordId) => wordText.get(wordId) ?? ""));- // A Cue whose boundaries all agree carries one `column-gap`, which is also what keeps a row that- // wraps from opening on a margin. A Cue that mixes scripts spaces each element instead.- const atomGaps = atomSurfaces.map((surfaces, index) => {- const previous = atomSurfaces[index - 1];- return previous === undefined ? false : wordGapBetween(previous.at(-1) ?? "", surfaces[0] ?? "");- });- const cueGap = uniformGap(atomGaps);+ const atomWords = atoms.map(atom => atom.wordIds.map(wordId => {+ const word = wordText.get(wordId);+ if (!word) throw new Error(`Fine Caption Atom references unknown word ${wordId}`);+ return word;+ }));+ const atomSurfaces = atomWords.map(words => words.map(word => word.text));+ const atomGaps = atomWords.map((words, index) => index > 0 && words[0]!.separatorBefore === " ");// The Visual IR carries physical margins, so the leading edge follows the Cue's own direction.const marginStart = parameters.layout.direction === "rtl" ? "margin-right" : "margin-left";const spacedStyle = (spaced: boolean): readonly VisualStyleDeclaration[] =>spaced ? [{ name: marginStart, value: gapPx }] : [];const fonts = parameters.typography.exactFonts;+ const rowStarts = structuralRowStarts(atoms, parameters.layout.maxWordsPerLine);if (parameters.layout.maxLines !== undefined) {- const rows = structuralRowCount(atoms, parameters.layout.maxWordsPerLine!);+ const rows = rowStarts.size;if (rows > parameters.layout.maxLines) {throw new Error(`Fine Caption Style ${styleId} constructs ${rows} rows for a Cue whose maximum is ${parameters.layout.maxLines}`);}@@ -766,10 +763,10 @@ function cueElements({ name: "border-radius", value: `${compactNumber(parameters.cueBox.radiusPx)}px` },{ name: "border-style", value: "solid" },{ name: "border-width", value: `${compactNumber(parameters.cueBox.borderWidthPx)}px` },- ...(cueGap === true ? [{ name: "column-gap", value: gapPx }] as const : []),{ name: "direction", value: parameters.layout.direction },- { name: "display", value: "flex" },- { name: "flex-wrap", value: "wrap" },+ { name: "display", value: "block" },+ { name: "font-size", value: "0px" },+ { name: "line-height", value: "0" },{ name: "justify-content", value: parameters.layout.textAlign === "left" ? "flex-start": parameters.layout.textAlign === "right" ? "flex-end" : "center" },{ name: "max-width", value: "100%" },@@ -781,6 +778,17 @@ function cueElements(],});+ const pushSeparator = (id: string, parent: string): void => push({+ id, parent, kind: "text", text: " ", fonts,+ style: [+ { name: "display", value: "inline" },+ { name: "font-size", value: "0px" },+ { name: "letter-spacing", value: gapPx },+ { name: "line-height", value: "0" },+ { name: "white-space", value: "normal" },+ ],+ });+if (parameters.activeBox.mode === "trail" && parameters.activeBox.continuity === "joined") {for (const [prefixIndex, atom] of atoms.entries()) {const timing = atomFrames.get(atom.id);@@ -788,17 +796,6 @@ function cueElements(const next = atoms[prefixIndex + 1];const nextStart = next === undefined ? durationFrames : atomFrames.get(next.id)?.start;if (nextStart === undefined) throw new Error("Fine Caption is missing timing for the next Atom");- // A no-break space inside an atom keeps its words on one row; the boundaries between atoms- // take an ordinary space. Both are spaced only where the surfaces meeting there call for one.- const prefixText = joinSurfaces(- atoms.slice(0, prefixIndex + 1).map((prefixAtom, index) => {- for (const wordId of prefixAtom.wordIds) {- if (!wordText.has(wordId)) throw new Error(`Fine Caption Atom references unknown word ${wordId}`);- }- return joinSurfaces(atomSurfaces[index] ?? [], "\u00A0");- }),- " ",- );const layerId = `joined-box-${prefixIndex + 1}`;push({id: layerId,@@ -818,8 +815,7 @@ function cueElements(push({id: `${layerId}-text`,parent: layerId,- kind: "text",- text: prefixText,+ kind: "box",style: [...transparentGlyphStyle(parameters).filter(({ name }) => name !== "white-space"),{ name: "-webkit-box-decoration-break", value: "clone" },@@ -833,12 +829,24 @@ function cueElements({ name: "padding", value: `${compactNumber(parameters.activeBox.paddingYPx)}px ${compactNumber(parameters.activeBox.paddingXPx)}px` },{ name: "white-space", value: "normal" },],- fonts,});+ for (const [index, words] of atomWords.slice(0, prefixIndex + 1).entries()) {+ if (index > 0 && rowStarts.has(index)) push({ id: `${layerId}-break-${index}`, parent: `${layerId}-text`, kind: "box",+ style: [{ name: "display", value: "block" }, { name: "height", value: "0" }],+ });+ if (!rowStarts.has(index) && words[0]!.separatorBefore === " ") pushSeparator(`${layerId}-gap-${index}`, `${layerId}-text`);+ const groupId = `${layerId}-group-${index}`;+ push({ id: groupId, parent: `${layerId}-text`, kind: "box", style: [{ name: "display", value: "inline-flex" }] });+ for (const [wordIndex, word] of words.entries()) {+ push({ id: `${groupId}-word-${wordIndex}`, parent: groupId, kind: "text", text: word.text, fonts,+ style: [...transparentGlyphStyle(parameters),+ ...(wordIndex > 0 && word.separatorBefore === " " ? spacedStyle(true) : [])],+ });+ }+ }}}- let wordsOnLine = 0;for (const [atomIndex, atom] of atoms.entries()) {const timing = atomFrames.get(atom.id);if (timing === undefined) throw new Error(`Fine Caption is missing timing for Atom ${atom.id}`);@@ -848,22 +856,20 @@ function cueElements(const surfaces = atomSurfaces[atomIndex] ?? [];// The base glyphs and the activated copy stacked over them are laid out from this one list, so// the karaoke wipe keeps sitting on the letterforms it reveals.- const gaps = wordGaps(surfaces);+ const gaps = wordGaps(atomWords[atomIndex]!);const wordGap = uniformGap(gaps);const entryId = `${atomId}-entry`;const loopId = `${atomId}-loop`;const responseId = `${atomId}-response`;- if (parameters.layout.maxWordsPerLine !== undefined- && wordsOnLine > 0- && wordsOnLine + atom.wordIds.length > parameters.layout.maxWordsPerLine) {+ if (atomIndex > 0 && rowStarts.has(atomIndex)) {push({id: `line-break-${atomIndex}`,parent: "cue",kind: "box",- style: [{ name: "flex-basis", value: "100%" }, { name: "height", value: "0" }],+ style: [{ name: "display", value: "block" }, { name: "height", value: "0" }],});- wordsOnLine = 0;}+ if (!rowStarts.has(atomIndex) && atomGaps[atomIndex]) pushSeparator(`gap-${atomIndex}`, "cue");const entryAnimation = atomLifecycleAnimation(parameters, timing.start, timing.end, durationFrames);const atomLoop = parameters.motion.loopTarget === "active-atom"? loopAnimation(parameters, durationFrames, activationTiming) : undefined;@@ -880,8 +886,6 @@ function cueElements(style: [{ name: "display", value: "inline-flex" },{ name: "min-width", value: "0" },- // A row that wraps opens at its own edge, so an atom that starts one carries no margin.- ...(cueGap === undefined && wordsOnLine > 0 ? spacedStyle(atomGaps[atomIndex] ?? false) : []),{ name: "transform-origin", value: "center center" },],...(entryAnimation === undefined ? {} : { animation: entryAnimation }),@@ -996,7 +1000,7 @@ function cueElements(}};for (const [wordIndex, wordId] of atom.wordIds.entries()) {- const text = wordText.get(wordId);+ const text = wordText.get(wordId)?.text;if (text === undefined) throw new Error(`Fine Caption Atom references unknown word ${wordId}`);pushText({id: `${atomId}-base-${wordIndex + 1}`,@@ -1037,7 +1041,7 @@ function cueElements(attributes: [{ name: kind === "glyph" ? "data-caption-karaoke" : "data-caption-active-underline", value: mode }],});for (const [wordIndex, wordId] of atom.wordIds.entries()) {- const text = wordText.get(wordId)!;+ const text = wordText.get(wordId)!.text;pushText({id: `${activeId}-${wordIndex + 1}`,parent: activeId,@@ -1060,7 +1064,6 @@ function cueElements(if (parameters.activeUnderline.mode !== "off") {addActivatedTextLayer("underline", parameters.activeUnderline.mode, "underline");}- wordsOnLine += atom.wordIds.length;}return elements;}@@ -1081,7 +1084,7 @@ export function renderFineCaption(throw new Error("Fine Caption inputs belong to different Timelines or Narratives");}const styles = new Map(program.styles.map((style) => [style.id, style]));- const wordText = new Map(document.words.map((word) => [word.id, word.text]));+ const wordText = new Map(document.words.map((word) => [word.id, word]));const atomById = new Map(document.units.map((atom) => [atom.id, atom]));for (const style of styles.values()) {if (style.rendering === null) continue;diff --git a/packages/caption-fine/src/spacing.ts b/packages/caption-fine/src/spacing.tsindex e24d7864..98fe8c19 100644--- a/packages/caption-fine/src/spacing.ts+++ b/packages/caption-fine/src/spacing.ts@@ -1,69 +1,16 @@-/**- * Where a word gap belongs between two adjacent display surfaces.- *- * A Display Word is one lexical unit, and in Han, Hiragana and Katakana that unit is a single- * character. A gap applied to every boundary therefore sets Chinese and Japanese as though every- * character were a word, so each boundary decides its own gap from the two characters that meet- * across it.- *- * The classes follow pangu.js: a CJK character beside a half-width letter, digit, bracket or- * operator takes one space. The gap pangu inserts is an ordinary space, so a boundary either- * carries the Style's `word-gap` or carries nothing.- */+import type { CaptionDisplayWord } from "@hypit/narrative";-/** The three scripts the Script tokenizer treats as one character per lexical unit. */-const CJK = /[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}]/u;+type Surface = Pick<CaptionDisplayWord, "text" | "separatorBefore">;-/**- * Full-width punctuation, including the bracket, quotation and dash pairs.- *- * These glyphs are drawn inside a full-width em box with their own side bearing, so a gap beside- * one paints a second space over the one the font already carries. The ranges cover CJK- * punctuation, the full-width ASCII forms, the curly quotes and the ellipsis, and stop short of- * the full-width digits and letters at `0-9`, `A-Z` and `a-z`, which- * are ordinary word characters.- */-const FULL_WIDTH_PUNCTUATION =- /[、-〃〈-】〔-〟!-/:-@[-`{-・‘’“”—…]/u;--/**- * Half-width brackets and quotation marks take their space on the outside of the pair, which falls- * out of reading the boundary characters: `displayWordSurfaces` attaches an opener to the surface- * that follows it and a closer to the surface before it, so `中文(注)中文` meets `(` on the right- * of one boundary and `)` on the left of the next, and both take a gap.- *- * A boundary with no CJK character on either side keeps the gap it has today. Latin spacing is not- * what this decides.- */-export function wordGapBetween(previous: string, next: string): boolean {- const left = [...previous].at(-1);- const right = [...next].at(0);- if (left === undefined || right === undefined) return false;- if (FULL_WIDTH_PUNCTUATION.test(left) || FULL_WIDTH_PUNCTUATION.test(right)) return false;- return !(CJK.test(left) && CJK.test(right));-}--/** Every boundary in order. The first surface opens the run, so its entry is always `false`. */-export function wordGaps(surfaces: readonly string[]): readonly boolean[] {- return surfaces.map((surface, index) => {- const previous = surfaces[index - 1];- return previous === undefined ? false : wordGapBetween(previous, surface);- });+/** The first displayed word starts a line; all other gaps come from authored content. */+export function wordGaps(words: readonly Surface[]): readonly boolean[] {+ return words.map((word, index) => index > 0 && word.separatorBefore === " ");}-/**- * A run whose boundaries all agree carries one `column-gap` on its container. A mixed run cannot,- * because `column-gap` is uniform, and takes a margin per element instead.- */+/** A uniform run can use column-gap; a mixed run requires individual separators. */export function uniformGap(gaps: readonly boolean[]): boolean | undefined {const boundaries = gaps.slice(1);if (boundaries.length === 0) return false;- if (boundaries.every((gap) => gap)) return true;- return boundaries.some((gap) => gap) ? undefined : false;-}--/** Join surfaces back into prose, spacing only the boundaries that carry a gap. */-export function joinSurfaces(surfaces: readonly string[], separator: string): string {- const gaps = wordGaps(surfaces);- return surfaces.map((surface, index) => (gaps[index] ? `${separator}${surface}` : surface)).join("");+ if (boundaries.every(gap => gap)) return true;+ return boundaries.some(gap => gap) ? undefined : false;}diff --git a/packages/caption-fine/test/caption-fine.test.ts b/packages/caption-fine/test/caption-fine.test.tsindex 640dce2b..cde0c875 100644--- a/packages/caption-fine/test/caption-fine.test.ts+++ b/packages/caption-fine/test/caption-fine.test.ts@@ -467,7 +467,7 @@ test("Caption Surface wires one Timeline to both ordinary and tracked-region ren});test("a Use beginning inside a Cue changes presentation without changing words or animation time", () => {- const { document, program } = fixture("<line>test1 || test2 @select test3 || test4 @/select</line>");+ const { document, program } = fixture("<line>test1 || test2 @{select} test3 || test4 @{/select}</line>");const timeline = sealTimeline({ id: "test-space", durationSec: 3, frameRate: { numerator: 30, denominator: 1 }, items: [] });const unit = (index: number) => ({ unitId: document.units[index]!.id, startFrame: 10 + index * 10, endFrameExclusive: 20 + index * 10 });const projection: TimedCaptionProjection = { spaceId: timeline.id, narrativeId: "story", documentId: document.id, cues: [@@ -543,3 +543,37 @@ test("Caption Track Uses share the temporal author language and reject the removawait assert.rejects(()=>decode('', 'program={old}'),/requires id, document, timeline/);await assert.rejects(()=>decode('<fine:Use style={style} selection={selection}/>'),/requires exactly one/);});++test("Fine uses author separators in ordinary text, shared groups, active copies and joined boxes", () => {+ const { program, projection } = fixture();+ const { "max-lines": _lines, "max-words-per-line": _words, ...flow } = recipe.properties;+ const style = fineCaptionStyle("plain", { ...recipe, properties: { ...flow,+ karaoke: "trail", "active-underline": "trail", "active-box": "trail", "active-box-continuity": "joined",+ } }, [font]);+ const styled = { ...program, styles: [style] };+ const render = (source: string) => {+ const document = captionDocument(parseScript("spacing", `<line>${source}</line>`), "story.caption", "story");+ const timed: TimedCaptionProjection = { ...projection, cues: [{ ...projection.cues[0]!,+ startFrame: 10, endFrameExclusive: 70,+ units: document.units.map((unit, index) => ({ unitId: unit.id, startFrame: 10 + index * 5, endFrameExclusive: 15 + index * 5 })),+ }] };+ return renderFineCaption(scheduleFineCaption(timed, styled, document), styled, document,+ sealTimeline({ items: [], id: "test-space", durationSec: 3, frameRate: { numerator: 30, denominator: 1 } })).presents[0]!.elements;+ };+ const grouped = render("<3개월 만에|> 완료했습니다");+ for (const id of ["atom-1-base-2", "atom-1-active-2", "atom-1-underline-2"]) {+ assert.equal(grouped.find(element => element.id === id)!.style.some(style => style.name === "margin-left"), false);+ }+ for (const id of ["atom-1-base-3", "atom-1-active-3", "atom-1-underline-3"]) {+ assert.equal(grouped.find(element => element.id === id)!.style.find(style => style.name === "margin-left")?.value, "14px");+ }+ const backgroundWords = grouped.filter(element => element.id.startsWith("joined-box-2-group-") && element.kind === "text");+ assert.deepEqual(backgroundWords.map(element => element.kind === "text" && element.text), ["3", "개월", "만에", "완료했습니다"]);+ assert.equal(grouped.find(element => element.id === "joined-box-2-group-0-word-2")!.style.find(style => style.name === "margin-left")?.value, "14px");+ assert.equal(grouped.find(element => element.id === "joined-box-2-gap-1")!.kind, "text");+ const chinese = render("是的 就是这样");+ assert.equal(chinese.find(element => element.id === "gap-2")!.style.find(style => style.name === "letter-spacing")?.value, "14px");+ assert.equal(chinese.find(element => element.id === "atom-2-entry")!.style.some(style => style.name === "margin-left"), false);+ const joined = render("3D");+ assert.equal(joined.some(element => element.style.some(style => style.name === "column-gap" || style.name === "margin-left")), false);+});diff --git a/packages/caption/README.md b/packages/caption/README.mdindex b8649c05..6f47a526 100644--- a/packages/caption/README.md+++ b/packages/caption/README.md@@ -7,7 +7,7 @@ Caption has two independent structures: Script organizes displayed words into Cuchoose how those Cues appear. A Use may begin inside a Cue. It changes presentation without changingthat Cue's text or restarting its word timing.-`CaptionDocument` owns displayed words, display/pronunciation associations, word attributes and `||`+`CaptionDocument` owns displayed words with authored separators, display/pronunciation associations, word attributes and `||`breaks. `Timeline` owns placed Takes and measured word times. `temporalizeCaptionDocument(document,timeline)` joins their identities and returns `TimedCaptionProjection`: complete Cues with originalunit times. Segment, speaking-turn and explicit Cue boundaries organize this content. No Style isdiff --git a/packages/caption/src/display.ts b/packages/caption/src/display.tsindex 17ef1530..bd479a5c 100644--- a/packages/caption/src/display.ts+++ b/packages/caption/src/display.ts@@ -8,6 +8,7 @@ function assert(condition: unknown, message: string): asserts condition {export function assertCaptionDocument(value: CaptionDocument): void {assert(value.id.length > 0, "CaptionDocument identity is invalid");assert(value.units.length > 0 && value.words.length > 0, "CaptionDocument is empty");+ for (const word of value.words) assert(word.separatorBefore === "" || word.separatorBefore === " ", "Caption word must declare its authored separator");const words = new Map(value.words.map((word) => [word.id, word]));assert(words.size === value.words.length, "CaptionDocument word ids are repeated");const units = new Set<string>();diff --git a/packages/caption/test/caption.test.ts b/packages/caption/test/caption.test.tsindex 9228ebea..4a94fe1c 100644--- a/packages/caption/test/caption.test.ts+++ b/packages/caption/test/caption.test.ts@@ -12,7 +12,7 @@ import { captionDocument, narrativeValue, parseScript } from "@hypit/script";import type { Narrative } from "@hypit/narrative";test("Caption uses complete semantic selections and authored cue breaks", () => {- const parsed = parseScript("caption.svml", "<line>one @focus two three @/focus || four</line>");+ const parsed = parseScript("caption.svml", "<line>one @{focus} two three @{/focus} || four</line>");const narrative = narrativeValue(parsed, "story") as unknown as Narrative;const document = captionDocument(parsed, "story.caption", "story");const selection = narrative.selections[0]!;@@ -22,10 +22,10 @@ test("Caption uses complete semantic selections and authored cue breaks", () =>});test("Caption selects complete Segments and the program through structural anchors", () => {- const parsed = parseScript("caption-ranges.svml", `~@whole-@opening <intro><HOST>One idea.</intro> @/opening+ const parsed = parseScript("caption-ranges.svml", `@{~whole}+@{opening} <intro><HOST>One idea.</intro> @{/opening}<answer><GUEST>Another view.</answer>-@/whole~`);+@{/whole~}`);const narrative = narrativeValue(parsed, "story") as unknown as Narrative;const document = captionDocument(parsed, "story.caption", "story");const whole = narrative.selections.find((selection) => selection.id === "whole")!;diff --git a/packages/caption/test/chinese-pipeline.test.ts b/packages/caption/test/chinese-pipeline.test.tsindex d08fa371..4508e096 100644--- a/packages/caption/test/chinese-pipeline.test.ts+++ b/packages/caption/test/chinese-pipeline.test.ts@@ -10,7 +10,7 @@ import { temporalizeCaptionDocument } from "../src/index.js";import { fixtureResource } from "../../../test/fixture-resource.js";for (const grouped of [false, true]) test(`Chinese Script through WhisperX and Timeline preserves caption timing (shared groups: ${grouped})`, () => {- const parsed = parseScript("mixed-zh.svml", `<opening><HOST>用@brand ElevenLabs @/brand做${grouped ? '<视频|>' : '视频'},|| 真方便。</opening>+ const parsed = parseScript("mixed-zh.svml", `<opening><HOST>用@{brand} ElevenLabs @{/brand}做${grouped ? '<视频|>' : '视频'},|| 真方便。</opening><answer><GUEST>今年<2026|二零二六>年,這個很好。</answer>`);const narrative = narrativeValue(parsed, "story") as unknown as Narrative;const document = captionDocument(parsed, "story.caption", "story");diff --git a/packages/narrative/README.md b/packages/narrative/README.mdindex 2c362f6f..d520b3a8 100644--- a/packages/narrative/README.md+++ b/packages/narrative/README.md@@ -26,4 +26,6 @@ no Tokens. Authored order is independent of gaps, overlap or placement order inCaption uses this content query and the Narrative's display correspondence to select completesubtitle units. Timeline projection uses the same semantic references to locate events in physicaltime. Neither operation substitutes for the other. Token lookup returns Tokens, not reconstructed-source prose: whitespace, comments and source-preserving edits remain the author language's concern.+source prose: comments and source-preserving edits remain the author language's concern. Caption+Display Words separately carry `separatorBefore` (`""` or `" "`) so consumers can reconstruct the+authored display spelling without guessing from Token boundaries or importing an author parser.diff --git a/packages/narrative/src/schema.ts b/packages/narrative/src/schema.tsindex 03c56a02..32b80d4c 100644--- a/packages/narrative/src/schema.ts+++ b/packages/narrative/src/schema.ts@@ -29,6 +29,7 @@ export const narrativeExcerptSchema: ValueSchema = object({tokenStart: { schema: integer }, tokenEndExclusive: { schema: integer },});const captionDisplayWord = object({+ separatorBefore: { schema: { kind: "string", enum: ["", " "] } },id: { schema: string }, unitId: { schema: string }, segmentId: { schema: string },turnId: { schema: string }, role: { schema: string, optional: true }, text: { schema: string },attributes: { schema: { kind: "array", items: object({diff --git a/packages/narrative/src/types.ts b/packages/narrative/src/types.tsindex e45d3034..d0f40389 100644--- a/packages/narrative/src/types.ts+++ b/packages/narrative/src/types.ts@@ -50,6 +50,8 @@ export type NarrativeMomentRef = NarrativeMoment & {/** One author-visible word surface. Punctuation owned by the surface is preserved. */export type CaptionDisplayWord = {+ /** Authored display separator from the preceding word; ignored at a displayed line start. */+ readonly separatorBefore: "" | " ";readonly id: string;readonly unitId: string;readonly segmentId: string;diff --git a/packages/script/README.md b/packages/script/README.mdindex c0e52cdb..44db0f94 100644--- a/packages/script/README.md+++ b/packages/script/README.md@@ -10,7 +10,7 @@ know that Script, Segment or Narrative exist.```svml<script id="story">- @answer+ @{answer}<opening><ALICE> I will make the first point.@@ -18,7 +18,7 @@ know that Script, Segment or Narrative exist.</opening><pause/>- @/answer+ @{/answer}</script>```@@ -65,8 +65,8 @@ CaptionDocument contracts.Role Cue or the Segment close ends that turn.- **Dual Text**: one authored speech span with separate display and spoken projections, written`<display text | spoken text>`. In `<display text|>`, omitted speech inherits the displayed prose.-- **Selection marker**: a named semantic range, written `@name ... @/name`.-- **Moment marker**: a named semantic point, written `@name!`.+- **Selection marker**: a named semantic range, written `@{name} ... @{/name}`.+- **Moment marker**: a named semantic point, written `@{name!}`.- **CaptionDocument**: the Script-owned caption truth; it contains **Display Words**,**Alignment Units** and **Cue Breaks**. It contains no seconds or frames.- **Token attribute**: a flat postfix display-word annotation such as `really{emphasis}` or@@ -86,7 +86,7 @@ Caption Styles choose whether to highlight, reveal or keep the text steady.In a shared side, markers and display attributes do not enter either text projection. Its speechTokens retain offsets into the actually written left-hand text, so Studio can move an anchor inside-`<组@beat!件化|>` without expanding the shorthand. Attributes still annotate the preceding display+`<组@{beat!}件化|>` without expanding the shorthand. Attributes still annotate the preceding displayword, not the whole group. Whitespace-only speech is omitted; a group with no spoken text on eitherside is invalid. This adds no new public value type or protocol version.@@ -101,8 +101,8 @@ Units; it does not split the Segment, cut the picture or end a Selection.<script id="story"><exchange><HOST> I use it || every day, || since <2012 | twenty twelve>.- <GUEST> Even @proof on holiday @/proof?- <HOST> @answer! Especially then.+ <GUEST> Even @{proof} on holiday @{/proof}?+ <HOST> @{answer!} Especially then.</exchange></script>```@@ -117,19 +117,43 @@ following characters. Display punctuation attaches to neighboring words withoutThese units support precise timing and highlighting. A Caption Cue can hold a whole phrase of them;`||` chooses its handoff independently of character counts or visual line wrapping.+## Display spelling and separators++Script preserves the normalized display spelling independently of speech tokenization. Ordinary+whitespace runs become one space; leading/trailing whitespace in a Turn and padding at the edges+of a Dual Text side are omitted. No language-specific rule removes a Chinese space or inserts a+space between numeric and Korean/Latin tokens. `是的 就是这样`, `3개월`, `3 개월`, `3D` and `3 D`+therefore remain distinct as authored. Source newlines are prose formatting, not Caption Cue breaks.+Use `||` for Cues and a family's layout controls for visual rows.++Each `CaptionDisplayWord.separatorBefore` is `""` or `" "`, relative to the preceding displayed word+in its Turn. Together with `text`, it carries the display spelling to consumers; it is not a speech+Token and has no timing. A renderer suppresses the leading separator at a displayed line/Cue start.+Shared groups retain internal separators and individual speech anchors: `<New York|>` is one+Alignment Unit with a space inside, while `<3D|>` has none. Grouping is a creative choice, not a+workaround for preserving spelling.+## Selection and Moment affinity+Every marker starts with `@{` and ends with `}`. The complete marker is zero-width in speech and+display; surrounding prose whitespace remains prose. All control sigils belong inside the braces:+`@{beat!}` is a Moment, whereas `@{part}!` opens a Selection followed by a literal exclamation mark.+Names match `[a-z][a-z0-9_-]{0,63}`; whitespace and nesting inside a marker are invalid.+A marker cannot split a speech Token. `hello{emphasis}` is a postfix display attribute; `@{part}`+is consumed as one marker and cannot be mistaken for that attribute. Write a literal `@{part}` as+`\@\{part\}`.+A marker selects the adjacent semantic anchor; it does not write a timecode. Inside a spokenpassage, its affinity normally chooses a neighboring word boundary:| Marker | Boundary || --- | --- |-| `@name` | Selection opens at the next word's start: right affinity. |-| `~@name` | Selection opens at the previous word's end: left affinity. |-| `@/name` | Selection closes at the previous word's end: left affinity. |-| `@/name~` | Selection closes at the next word's start: right affinity. |-| `@name!` | Moment at the next word's start: right affinity. |-| `~@name!` | Moment at the previous word's end: left affinity. |+| `@{name}` | Selection opens at the next word's start: right affinity. |+| `@{~name}` | Selection opens at the previous word's end: left affinity. |+| `@{/name}` | Selection closes at the previous word's end: left affinity. |+| `@{/name~}` | Selection closes at the next word's start: right affinity. |+| `@{name!}` | Moment at the next word's start: right affinity. |+| `@{~name!}` | Moment at the previous word's end: left affinity. |At structural edges, the parser retains the corresponding Segment or program boundary rather thaninventing a neighboring word. Selection and Moment ids share one namespace. Selections can overlap,@@ -138,37 +162,47 @@ cross and span Segments; unlike tags, they do not need to nest.To join two visual Selections without exposing their inter-word pause, match affinity on both sides:```text-@coffee my coffee @/coffee ~@smoothie my smoothie @/smoothie-@coffee my coffee @/coffee~ @smoothie my smoothie @/smoothie+@{coffee} my coffee @{/coffee} @{~smoothie} my smoothie @{/smoothie}+@{coffee} my coffee @{/coffee~} @{smoothie} my smoothie @{/smoothie}```These are alternative spellings, not two occurrences to put in the same Script. In the first,“coffee” ends both the first Window and the gap's left boundary, so the smoothie Selection owns thepause. In the second, the next “my” starts both touching boundaries, so the coffee Selection owns it.-Plain `@/coffee @smoothie` leaves the gap between previous word end and next word start outside both.+Plain `@{/coffee} @{smoothie}` leaves the gap between previous word end and next word start outside both.The media consumer still decides playback and visual coverage inside those projected Windows.## Marker writeback`adjustScriptSelection` and `adjustScriptMoment` accept explicit anchor identities. A Selection's-two endpoints are written together. Script owns their legal source sites: token punctuation and-postfix attributes stay attached, Segment boundaries stay structural, and coincident markers are-ordered together. Writeback reads the current source, removes the markers, normalizes ordinary-same-line prose, and places the markers at their requested anchors. Repeated spaces and tabs in-prose become necessary separators; punctuation uses the same attachment rules as Script's text-projection. Newlines, blank lines and each line's leading spaces/tabs remain intact. A marker at-the start of a line is placed after its indentation; whitespace after that marker is prose, not-additional indentation. Marker-only lines remain blank when the marker leaves. Comments, tags,-Dual Text and display attributes retain their own syntax and are not passed through prose cleanup.--Normalization keeps lexical units unchanged and does not restore earlier whitespace spellings.-It has no persistent formatting state: the same text structure and anchor relationships produce-the same spelling on repeated edits. Empty self-closing Segments expand when needed to make their-distinct boundaries writable.--Writeback reparses the result to retain the intended identities and unchanged narrative/caption-content. These checks concern authored order, not frame order. A consumer's temporal projection-determines whether the resulting Instant or Window is usable.+two endpoints are moved together; unrelated markers and all source prose remain untouched. Names+terminate at `}`, so writeback never inserts a separating space or normalizes surrounding prose.+A no-op adjustment returns the original source. Script owns legal insertion sites: Tokens and+postfix attributes stay together, Dual Text markers follow the actual speech side, and coincident+markers written together have deterministic order. Empty self-closing Segments expand only when a+requested boundary needs an interior insertion site.++Writeback reparses the result to retain the requested bindings and unchanged speech, display and+Narrative/Caption content. Source offsets remain parser-private; no formatting history is stored.++## Explicit migration from 0.1++The 0.2 parser rejects bare `@name` markers. Preview migration from the repository or installed+Distribution root, then explicitly write the reviewed result:++```sh+node packages/script/bin/migrate-0.2.mjs /path/to/film.svml+node packages/script/bin/migrate-0.2.mjs /path/to/film.svml --write+```++Use `--body` for a file containing a raw Script body rather than outer SVML. The tool converts+markers only inside Script bodies, leaves comments and escapes intact, and does not touch provider+prompt references such as `@image1`. It neither installs anything nor runs during a build.++Review authored whitespace after migration: spaces previously discarded by Chinese/punctuation+normalization now appear. The tool preserves source spaces rather than guessing the author's intent.+Regenerate affected Narrative, caption and Build results with the new reader/writer together;+protocol identities remain `@1`. Existing rendered media is not modified by source migration.## Complete authored content and narrow exportsdiff --git a/packages/script/bin/migrate-0.2.mjs b/packages/script/bin/migrate-0.2.mjsnew file mode 100644index 00000000..65eb064f--- /dev/null+++ b/packages/script/bin/migrate-0.2.mjs@@ -0,0 +1,90 @@+#!/usr/bin/env node+/** Explicit, one-time marker migration. Never called by parsing, building, or Studio. */+import { readFile, writeFile } from "node:fs/promises";+import { resolve } from "node:path";+import { pathToFileURL } from "node:url";++export function migrateScriptBody(source) {+ let result = "";+ for (let cursor = 0; cursor < source.length;) {+ if (source[cursor] === "\\") {+ result += source.slice(cursor, cursor + 2);+ cursor += 2;+ continue;+ }+ if (source.startsWith("<!--", cursor)) {+ const close = source.indexOf("-->", cursor + 4);+ if (close < 0) throw new Error("Unclosed Script comment");+ result += source.slice(cursor, close + 3);+ cursor = close + 3;+ continue;+ }+ if (source.startsWith("@{", cursor)) {+ const close = source.indexOf("}", cursor + 2);+ if (close < 0) throw new Error("Unclosed delimited Script marker");+ result += source.slice(cursor, close + 1);+ cursor = close + 1;+ continue;+ }+ const rest = source.slice(cursor);+ const match = /^@\/([a-z][a-z0-9_-]{0,63})(~)/u.exec(rest)+ ?? /^@\/([a-z][a-z0-9_-]{0,63})(?![A-Za-z0-9_-])/u.exec(rest);+ const open = match ? undefined : /^(~)?@([a-z][a-z0-9_-]{0,63})(!)/u.exec(rest)+ ?? /^(~)?@([a-z][a-z0-9_-]{0,63})(?![A-Za-z0-9_-])/u.exec(rest);+ if (match) {+ result += `@{/${match[1]}${match[2] ?? ""}}`;+ cursor += match[0].length;+ } else if (open) {+ result += `@{${open[1] ?? ""}${open[2]}${open[3] ?? ""}}`;+ cursor += open[0].length;+ } else {+ result += source[cursor++];+ }+ }+ return result;+}++/** Change Script raw bodies only; package references and generation prompt tags stay untouched. */+export function migrateSvml(source) {+ let result = "";+ let cursor = 0;+ const token = /<!--[\s\S]*?-->|<(?:[A-Za-z_][\w.-]*:)?script(?=[\s/>])(?:"[^"]*"|'[^']*'|[^'">])*>/gu;+ for (let match = token.exec(source); match; match = token.exec(source)) {+ if (match[0].startsWith("<!--") || match[0].endsWith("/>")) continue;+ const name = /^<([^\s>]+)/u.exec(match[0])[1];+ const close = `</${name}>`;+ const start = match.index + match[0].length;+ let end = start;+ while (end < source.length) {+ if (source[end] === "\\") { end += 2; continue; }+ if (source.startsWith("<!--", end)) {+ const stop = source.indexOf("-->", end + 4);+ if (stop < 0) throw new Error("Unclosed Script comment");+ end = stop + 3;+ continue;+ }+ if (source.startsWith(close, end)) break;+ end++;+ }+ if (end >= source.length) throw new Error(`Missing ${close}`);+ result += source.slice(cursor, start) + migrateScriptBody(source.slice(start, end)) + close;+ cursor = end + close.length;+ token.lastIndex = cursor;+ }+ return result + source.slice(cursor);+}++if (process.argv[1] && import.meta.url === pathToFileURL(resolve(process.argv[1])).href) {+ const args = process.argv.slice(2);+ const flags = new Set(args.filter(arg => arg.startsWith("--")));+ const paths = args.filter(arg => !arg.startsWith("--"));+ if (paths.length !== 1 || [...flags].some(flag => !["--write", "--body"].includes(flag))) {+ console.error("Usage: node migrate-0.2.mjs <source.svml> [--body] [--write]\nDefault: print migrated SVML. --body: input is a raw Script body. --write: replace the named file.");+ process.exitCode = 2;+ } else {+ const source = await readFile(paths[0], "utf8");+ const migrated = flags.has("--body") ? migrateScriptBody(source) : migrateSvml(source);+ if (flags.has("--write")) await writeFile(paths[0], migrated);+ else process.stdout.write(migrated);+ }+}diff --git a/packages/script/src/edit.ts b/packages/script/src/edit.tsindex 7fb4842f..2bf1c90c 100644--- a/packages/script/src/edit.ts+++ b/packages/script/src/edit.ts@@ -3,7 +3,6 @@ import type { SourceRange } from "@hypit/protocol";import { canonicalStringify } from "@hypit/protocol";import { captionDocument, narrativeValue } from "./narrative.js";import { parseScript } from "./parser.js";-import { cleanHorizontalProse } from "./lexical.js";import type { Affinity, ParsedNarrative, SemanticAnchor } from "./types.js";export type ScriptAnchorEditSite = {@@ -75,8 +74,8 @@ export function scriptAnchorEditSites(parsed: ParsedNarrative): readonly ScriptA}function marker(id: string, edge: "open" | "close", affinity: Affinity): string {- if (edge === "open") return affinity === "left" ? `~@${id}` : `@${id}`;- return affinity === "left" ? `@/${id}` : `@/${id}~`;+ if (edge === "open") return `@{${affinity === "left" ? "~" : ""}${id}}`;+ return `@{/${id}${affinity === "right" ? "~" : ""}}`;}function applyEdits(source: string, edits: readonly Edit[]): string {@@ -100,61 +99,32 @@ type AdjustmentInput = {type NamedAnchor = { readonly id: string; readonly edge: "open" | "close" | "moment"; readonly anchorId: string };-/** Normalize only parser-owned prose. Indentation is read from this edit's input, never stored. */-function normalizedProse(source: string, parsed: ParsedNarrative, original: string): string {- const bodyStarts = new Set(parsed.segments.flatMap(segment => [segment.contentRange.start,- ...segment.atoms.filter(atom => atom.kind === "role").map(atom => atom.range.end)]));- const bodyEnds = new Set(parsed.segments.map(segment => segment.contentRange.end));- const indentation = original.split(/\r\n|\r|\n/u).map(line => /^[ \t]*/u.exec(line)![0].length);- const lines: Array<{ start: number; end: number; indentEnd: number }> = [];- let offset = 0;- const parts = source.split(/(\r\n|\r|\n)/u);- for (let index = 0; index < parts.length; index += 2) {- const text = parts[index]!;- lines.push({ start: offset, end: offset + text.length, indentEnd: offset + indentation[index / 2]! });- offset += text.length + (parts[index + 1]?.length ?? 0);- }- const edits: Edit[] = [];- for (const range of parsed.proseRanges) for (const line of lines) {- const start = Math.max(range.start, line.indentEnd);- const end = Math.min(range.end, line.end);- if (start >= end) continue;- let text = cleanHorizontalProse(source.slice(start, end));- const outside = !parsed.segments.some(segment => range.start >= segment.contentRange.start && range.end <= segment.contentRange.end);- if (start === line.indentEnd || bodyStarts.has(start) || outside) text = text.replace(/^[ \t]+/u, "");- if (end === line.end || bodyEnds.has(end) || outside) text = text.replace(/[ \t]+$/u, "");- edits.push({ range: { start, end }, replacement: text });- }- return applyEdits(source, edits);-}--/** One canonical boundary spelling, independent of the order of previous gestures. */+/** Move only the requested markers. Delimited names never require editing prose separators. */function rewrite(input: AdjustmentInput, markers: readonly NamedAnchor[]): string {- const ranges = [- ...input.parsed.moments.map((item) => item.range),- ...input.parsed.selections.flatMap((item) => [item.open.range, item.close.range]),- ].map((range) => ({ start: range.start - input.parsed.sourceRange.start, end: range.end - input.parsed.sourceRange.start }))- .sort((a, b) => a.start - b.start);- const edits: Edit[] = ranges.map(range => ({ range, replacement: "" }));+ const original = namedAnchors(input.parsed);+ const changedNames = new Set(markers.filter(value => original.find(item => item.id === value.id && item.edge === value.edge)?.anchorId !== value.anchorId).map(value => value.id));+ const moved = markers.filter(value => changedNames.has(value.id));+ if (moved.length === 0) return input.source;+ const origin = input.parsed.sourceRange.start;+ const edits: Edit[] = moved.map(value => {+ const range = value.edge === "moment"+ ? input.parsed.moments.find(item => item.id === value.id)!.range+ : input.parsed.selections.find(item => item.id === value.id)![value.edge].range;+ return { range: { start: range.start - origin, end: range.end - origin }, replacement: "" };+ });for (const segment of input.parsed.segments) {- if (segment.selfClosing) edits.push({ range: { start: segment.range.start - input.parsed.sourceRange.start, end: segment.range.end - input.parsed.sourceRange.start }, replacement: `<${segment.id}></${segment.id}>` });+ if (segment.selfClosing && moved.some(value => value.anchorId === segment.startAnchorId || value.anchorId === segment.endAnchorId)) {+ edits.push({ range: { start: segment.range.start - origin, end: segment.range.end - origin }, replacement: `<${segment.id}></${segment.id}>` });+ }}- const unmarked = applyEdits(input.source, edits);- const base = normalizedProse(unmarked, parseScript(input.sourceName, unmarked), input.source);- const parsed = parseScript(input.sourceName, base);+ const base = applyEdits(input.source, edits);+ const parsed = parseScript(input.sourceName, base, origin);const sites = new Map(scriptAnchorEditSites(parsed).map((site, order) => [site.anchorId, { ...site, order }]));const groups = new Map<number, Array<NamedAnchor & { affinity: Affinity; order: number }>>();- for (const value of markers) {+ for (const value of moved) {const site = sites.get(value.anchorId);if (!site) throw new Error(`Semantic Anchor ${value.anchorId} does not exist.`);- let offset = site.offset;- const lineStart = Math.max(base.lastIndexOf("\n", offset - 1), base.lastIndexOf("\r", offset - 1)) + 1;- const indentEnd = lineStart + /^[ \t]*/u.exec(base.slice(lineStart))![0].length;- if (offset < indentEnd) offset = indentEnd;- // Reuse horizontal separators without moving a word marker ahead of line indentation.- let gapStart = offset;- while (gapStart > 0 && /[ \t]/u.test(base[gapStart - 1]!)) gapStart -= 1;- if (gapStart > 0 && !/[\r\n]/u.test(base[gapStart - 1]!)) offset = gapStart;+ const offset = site.offset - origin;const group = groups.get(offset) ?? [];group.push({ ...value, affinity: site.affinity, order: site.order });groups.set(offset, group);@@ -163,18 +133,13 @@ function rewrite(input: AdjustmentInput, markers: readonly NamedAnchor[]): stringroup.sort((a, b) => a.order - b.order|| (a.edge === "open" ? 0 : a.edge === "moment" ? 1 : 2) - (b.edge === "open" ? 0 : b.edge === "moment" ? 1 : 2)|| a.id.localeCompare(b.id));- let replacement = group.map((item) => item.edge === "moment"- ? `${item.affinity === "left" ? "~" : ""}@${item.id}!`+ const replacement = group.map(item => item.edge === "moment"+ ? `@{${item.affinity === "left" ? "~" : ""}${item.id}!}`: marker(item.id, item.edge, item.affinity)).join("");- let end = offset;- while (end < base.length && /[ \t]/u.test(base[end]!)) end += 1;- if (end > offset) replacement += " ";- // Only undelimited names followed by an ASCII name character need a separator.- if (/[a-z0-9_-]$/u.test(replacement) && /[A-Za-z0-9_-]/u.test(base[offset] ?? "")) replacement += " ";- return { range: { start: offset, end }, replacement };+ return { range: { start: offset, end: offset }, replacement };});const next = applyEdits(base, insertions);- const reparsed = parseScript(input.sourceName, next);+ const reparsed = parseScript(input.sourceName, next, origin);const actual = namedAnchors(reparsed);if (canonicalStringify(actual) !== canonicalStringify(markers)) {throw new Error("Script marker adjustment did not preserve the requested semantic bindings.");@@ -183,6 +148,9 @@ function rewrite(input: AdjustmentInput, markers: readonly NamedAnchor[]): strinconst content = (value: ParsedNarrative) => ({...narrativeValue(value, "comparison") as Record<string, unknown>, selections: [], moments: [],caption: captionDocument(value, "caption", "comparison"),+ speech: value.serializations.speech,+ dialogue: value.serializations.dialogue,+ display: value.captionProjection.text,});if (canonicalStringify(content(input.parsed)) !== canonicalStringify(content(reparsed))) {throw new Error("Script marker adjustment changed authored content.");diff --git a/packages/script/src/lexical.ts b/packages/script/src/lexical.tsindex 8db9b99d..21514133 100644--- a/packages/script/src/lexical.ts+++ b/packages/script/src/lexical.ts@@ -71,30 +71,9 @@ export function lexicalEditRanges(value: string): readonly { start: number; end:});}-/** Canonical prose spacing; punctuation remains display/speech information, never a timing token. */-function attachProseSpacing(value: string): string {- return value- .replace(/ +([,.;:!?%…,。!?;:、%‰)】》」』〕〉}\]])/gu, "$1")- .replace(/([([{(【《「『〔〈“‘]) +/gu, "$1")- // Do not erase a cross-script space: `here 你好` must remain two semantic regions.- // Only collapse explicit spaces inside one CJK run; the lexical tokenizer already keeps- // adjacent Latin and CJK runs separate when no space was authored.- .replace(/([\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}]) +(?=[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}])/gu, "$1");-}-+/** Normalize source formatting without inventing or removing language-specific separators. */export function cleanProjection(value: string): string {- return attachProseSpacing(value.replace(/\s+/gu, " ")).trim();-}--/** Source formatting keeps line breaks and lexical boundaries, including spaced decimal-like prose. */-export function cleanHorizontalProse(value: string): string {- const collapsed = value.replace(/[ \t]+/gu, " ");- const attached = attachProseSpacing(collapsed);- const words = (text: string) => lexicalUnits(text).map(unit => unit.text);- // A separator in `3 .14` cannot be erased into the different token `3.14`.- const before = words(collapsed);- const after = words(attached);- return before.length === after.length && before.every((word, index) => word === after[index]) ? attached : collapsed;+ return value.replace(/\s+/gu, " ").trim();}/** Structural markers split atoms but must not invent prose whitespace when those atoms rejoin. */@@ -102,47 +81,55 @@ export function joinProjection(parts: readonly string[]): string {return cleanProjection(parts.join(""));}-/**- * Display units follow the same lexical boundaries as semantic speech tokens. Punctuation is kept- * for rendering: opening punctuation belongs to the next unit; all other inter-token punctuation- * belongs to the previous unit. Whitespace is layout, not a display word of its own.- */-export function displayWordSurfaces(value: string): readonly string[] {+export type DisplaySurface = {+ readonly text: string;+ readonly separatorBefore: "" | " ";+};++/** Keep the authored display spelling while assigning punctuation to lexical surfaces. */+export function displaySurfaces(value: string): readonly DisplaySurface[] {const prose = cleanProjection(value);const units = lexicalUnits(prose);- if (units.length === 0) return [];-- const surfaces: string[] = [];+ const surfaces: Array<{ text: string; separatorBefore: "" | " " }> = [];let cursor = 0;- let prefix = "";for (const unit of units) {const gap = prose.slice(cursor, unit.index);- const punctuation = [...gap]- .map((character, position) => ({ character, position }))- .filter(({ character }) => !/\s/u.test(character));- if (surfaces.length === 0) {- prefix += punctuation.map(({ character }) => character).join("");- } else {- const suffix = punctuation- .filter(({ character, position }) => !isOpeningPunctuation(character, gap, position, true))- .map(({ character }) => character)- .join("");- const opening = punctuation- .filter(({ character, position }) => isOpeningPunctuation(character, gap, position, true))- .map(({ character }) => character)- .join("");- if (suffix) surfaces[surfaces.length - 1] += suffix;- prefix += opening;+ let openingAt = gap.length;+ for (const match of gap.matchAll(/./gu)) {+ if (!/\s/u.test(match[0]) && isOpeningPunctuation(match[0], gap, match.index, surfaces.length > 0)) {+ openingAt = match.index;+ break;+ }}- surfaces.push(`${prefix}${unit.text}`);- prefix = "";+ const closing = gap.slice(0, openingAt);+ const previous = surfaces.at(-1);+ if (previous) previous.text += closing.trimEnd();+ const prefix = (previous ? "" : closing.trimStart()) + gap.slice(openingAt);+ surfaces.push({ text: prefix + unit.text, separatorBefore: previous && /\s$/u.test(closing) ? " " : "" });cursor = unit.index + unit.text.length;}- const trailing = prose.slice(cursor).replace(/\s+/gu, "");- if (trailing) surfaces[surfaces.length - 1] += trailing;+ const last = surfaces.at(-1);+ if (last) last.text += prose.slice(cursor);return surfaces;}+export function displayWordSurfaces(value: string): readonly string[] {+ return displaySurfaces(value).map(surface => surface.text);+}++/** Split punctuation before the first lexical unit, retaining every authored separator. */+export function splitDisplayPrefix(value: string): { previous: string; current: string } {+ const first = lexicalUnits(value)[0];+ if (!first) return { previous: value, current: "" };+ const leading = value.slice(0, first.index);+ for (const match of leading.matchAll(/./gu)) {+ if (!/\s/u.test(match[0]) && isOpeningPunctuation(match[0], leading, match.index, false)) {+ return { previous: leading.slice(0, match.index), current: value.slice(match.index) };+ }+ }+ return { previous: leading, current: value.slice(first.index) };+}+/** Closing punctuation before a lexical unit belongs to the previous display unit when one exists. */export function splitLeadingClosingPunctuation(value: string): {readonly previous: string;diff --git a/packages/script/src/manifest.ts b/packages/script/src/manifest.tsindex ec8a618c..45d41fa6 100644--- a/packages/script/src/manifest.ts+++ b/packages/script/src/manifest.ts@@ -48,15 +48,15 @@ export const scriptMarkupSurfaces = [],example: ['<script id="story">',- " @whole",+ " @{whole}"," <hook>",- " <HOST> @problem Never let anyone take credit for your work. @/problem",+ " <HOST> @{problem} Never let anyone take credit for your work. @{/problem}"," </hook>",""," <meeting>",- " <HOST> I started sending <BCC | B C C> recaps. @ranking! Everything changed.",+ " <HOST> I started sending <BCC | B C C> recaps. @{ranking!} Everything changed."," </meeting>",- " @/whole~",+ " @{/whole~}","</script>",].join("\n"),notes: [@@ -67,16 +67,16 @@ export const scriptMarkupSurfaces = ["Dual Text is written `<display | speech>`: the left side reaches Caption and the right side reaches dialogue and speech. `<display|>` inherits speech from the displayed prose and forms the same complete alignment unit; its word times remain individual. `<|speech>` speaks without displaying. Both sides empty is invalid.","Inside Dual Text, semantic markers belong to the source of spoken text: the explicit right side, or the shared left side when speech is omitted. Display attributes remain visual metadata and never enter spoken text.","A flat token attribute follows a complete display token as `{name}` or `{name=value}`; multiple attributes use one comma-separated block. Attributes do not nest, do not carry timing, and never split a Dual Alignment Unit.",- "Selection and Moment markers are zero-width, share one name namespace, and may not split a speech token:",+ "Selection and Moment markers are fully enclosed in `@{...}` with all sigils inside. They are zero-width, share one name namespace, and may not split a speech token. Surrounding prose spaces remain content; do not add spaces to delimit a name:",["| Marker | Meaning |","|---|---|",- "| `@id` | Opens a Selection at the next word's start |",- "| `~@id` | Opens a Selection at the previous word's end |",- "| `@/id` | Closes a Selection at the previous word's end |",- "| `@/id~` | Closes a Selection at the next word's start |",- "| `@id!` | A Moment at the next word's start |",- "| `~@id!` | A Moment at the previous word's end |",+ "| `@{id}` | Opens a Selection at the next word's start |",+ "| `@{~id}` | Opens a Selection at the previous word's end |",+ "| `@{/id}` | Closes a Selection at the previous word's end |",+ "| `@{/id~}` | Closes a Selection at the next word's start |",+ "| `@{id!}` | A Moment at the next word's start |",+ "| `@{~id!}` | A Moment at the previous word's end |",].join("\n"),"Each Selection name has one opening and one closing marker; use distinct names for distinct semantic ranges.","`<!-- -->` comments never enter any projection, and `\\@`, `\\<`, `\\\\`, `\\{` and `\\}` write those characters literally; inside Dual Text `\\|` and `\\>` do the same.",diff --git a/packages/script/src/narrative.ts b/packages/script/src/narrative.tsindex 4afecaec..39eab801 100644--- a/packages/script/src/narrative.ts+++ b/packages/script/src/narrative.ts@@ -4,7 +4,7 @@ import type { CaptionAlignmentUnit, CaptionDocument, CaptionDisplayWord } from "import { sealText } from "@hypit/text";import type { ParsedCaptionRegion, ParsedNarrative } from "./types.js";-import { cleanProjection, displayWordSurfaces, joinProjection, lexicalCount } from "./lexical.js";+import { cleanProjection, displaySurfaces, joinProjection, lexicalCount } from "./lexical.js";function turnForRegion(parsed: ParsedNarrative, region: ParsedCaptionRegion): ParsedNarrative["turns"][number] {const turn = parsed.turns.find((candidate) =>@@ -21,7 +21,8 @@ function projectCaption(parsed: ParsedNarrative, id: string, narrativeId: stringfor (const region of parsed.captionProjection.regions) {if (region.kind === "hidden") continue;const turn = turnForRegion(parsed, region);- const surfaces = displayWordSurfaces(region.display);+ const display = displaySurfaces(region.display);+ const surfaces = display.map(word => word.text);if (surfaces.length === 0) throw new Error(`Caption region ${region.id} contains no visible display surface`);// A Dual Text alias is one indivisible N:M correspondence unit. Ordinary prose gives one// unit per display surface so the author can place cue/style boundaries between words.@@ -46,6 +47,7 @@ function projectCaption(parsed: ParsedNarrative, id: string, narrativeId: stringturnId: turn.id,...(turn.role === undefined ? {} : { role: turn.role }),text: surface,+ separatorBefore: group.indices[groupIndex] === 0 ? region.separatorBefore : display[group.indices[groupIndex]!]!.separatorBefore,attributes,});return wordId;diff --git a/packages/script/src/parser.ts b/packages/script/src/parser.tsindex d7c2ab08..e3a6dbad 100644--- a/packages/script/src/parser.ts+++ b/packages/script/src/parser.ts@@ -7,6 +7,7 @@ import {lexicalUnits,lexicalEditRanges,splitLeadingClosingPunctuation,+ splitDisplayPrefix,} from "./lexical.js";import type {CaptionWordAttribute,@@ -65,33 +66,15 @@ function normalizeWord(value: string): string {}function parseMarker(source: string, offset: number): Marker | undefined {- const markerName = String.raw`[a-z][a-z0-9_-]{0,63}`;- const rest = source.slice(offset);- const closeRight = new RegExp(String.raw`^@\/(${markerName})~`, "u").exec(rest);- if (closeRight) {- return { id: closeRight[1]!, kind: "close", affinity: "right", length: closeRight[0].length };+ const match = /^@\{(~)?(\/)?([a-z][a-z0-9_-]{0,63})([!~])?\}/u.exec(source.slice(offset));+ if (!match) return undefined;+ const [, left, close, id, suffix] = match;+ if (close) {+ if (left || suffix === "!") return undefined;+ return { id: id!, kind: "close", affinity: suffix === "~" ? "right" : "left", length: match[0].length };}- const closeLeft = new RegExp(String.raw`^@\/(${markerName})(?![A-Za-z0-9_-])`, "u").exec(rest);- if (closeLeft) {- return { id: closeLeft[1]!, kind: "close", affinity: "left", length: closeLeft[0].length };- }- const moment = new RegExp(String.raw`^(~)?@(${markerName})!`, "u").exec(rest);- if (moment) {- return {- id: moment[2]!,- kind: "moment",- affinity: moment[1] === "~" ? "left" : "right",- length: moment[0].length,- };- }- const open = new RegExp(String.raw`^(~)?@(${markerName})(?![A-Za-z0-9_-])`, "u").exec(rest);- if (!open) return undefined;- return {- id: open[2]!,- kind: "open",- affinity: open[1] === "~" ? "left" : "right",- length: open[0].length,- };+ if (suffix === "~") return undefined;+ return { id: id!, kind: suffix === "!" ? "moment" : "open", affinity: left ? "left" : "right", length: match[0].length };}function segmentAnchorId(segmentId: string, edge: "start" | "end"): string {@@ -142,8 +125,9 @@ export function parseScript(const segments: ParsedSegment[] = [];const tokens: ParsedToken[] = [];- const proseRanges: Array<{ start: number; end: number }> = [];const captionRegions: ParsedCaptionRegion[] = [];+ let precedingCaptionRegion: number | undefined;+ let pendingCaptionSpace = false;const selections = new Map<string, RawSelection>();const moments = new Map<string, RawMoment>();const captionBreaks: Array<{ readonly tokenIndex: number; readonly range: { readonly start: number; readonly end: number } }> = [];@@ -261,6 +245,7 @@ export function parseScript(positions.push(absoluteStart + index);continue;}+ if (dual && raw[index] === "<") fail("SCRIPT_DUAL_NESTED", "Dual Text cannot nest; escape a literal < as \\<.", absoluteStart + index);buffer += raw[index];index += 1;positions.push(absoluteStart + index);@@ -365,6 +350,7 @@ export function parseScript(captionRegions.push({id: `caption-region:${captionRegions.length + 1}`,display: "",+ separatorBefore: "",segmentId,startToken: tokenStart,endTokenExclusive: tokenEndExclusive,@@ -375,21 +361,24 @@ export function parseScript(}return;}- const split = splitLeadingClosingPunctuation(displayValue);- const previous = captionRegions.at(-1);- const canAttachPrevious = previous !== undefined && previous.segmentId === segmentId;- if (split.previous && canAttachPrevious) {- captionRegions[captionRegions.length - 1] = {+ // Dual Text edge whitespace is syntax padding; ordinary prose whitespace is content.+ const raw = kind === "alias" ? cleanProjection(displayValue) : displayValue;+ const value = ((pendingCaptionSpace ? " " : "") + raw).replace(/\s+/gu, " ");+ const split = splitDisplayPrefix(value);+ const previous = precedingCaptionRegion === undefined ? undefined : captionRegions[precedingCaptionRegion];+ if (previous && split.previous.trim()) {+ captionRegions[precedingCaptionRegion!] = {...previous,- display: cleanProjection(`${previous.display}${split.previous}`),- range: { start: previous.range.start, end: range.end },+ display: previous.display + split.previous.trimEnd(),};}- const display = canAttachPrevious ? split.current : `${split.previous}${split.current}`;+ pendingCaptionSpace = /\s$/u.test(value);+ const display = (previous ? split.current : split.previous + split.current).trim();if (!display || tokenEndExclusive <= tokenStart) return;captionRegions.push({id: `caption-region:${captionRegions.length + 1}`,display,+ separatorBefore: previous && /\s$/u.test(split.previous) ? " " : "",segmentId,startToken: tokenStart,endTokenExclusive: tokenEndExclusive,@@ -397,6 +386,7 @@ export function parseScript(marks,range,});+ precedingCaptionRegion = captionRegions.length - 1;};const markLastCaptionSurface = (@@ -484,7 +474,7 @@ export function parseScript(tokenEndExclusive: tokens.length,range: { start: sourceOffset + start, end: sourceOffset + end },});- if (captureCaptionRegion && cleanProjection(caption)) {+ if (captureCaptionRegion) {addCaptionRegion(caption,current.id,@@ -502,6 +492,10 @@ export function parseScript(caption: string | undefined,marks: ParsedCaptionRegion["marks"] = [],): void => {+ const leading = /^\s*/u.exec(raw)![0].length;+ raw = raw.trim();+ absoluteStart += leading;+ if (caption !== undefined) caption = caption.trim();const startToken = tokens.length;// An omitted speech side shares the written display source. Keep its original offsets:// marker edits target these words, not a synthetic copy beyond the pipe.@@ -526,6 +520,7 @@ export function parseScript(if (raw.startsWith("||", index)) {fail("SCRIPT_CAPTION_BREAK_DUAL", "Caption Cue break cannot occur inside Dual Text; split the Dual Text into separate units.", absoluteStart + index);}+ if (!shared && raw[index] === "{") fail("SCRIPT_DUAL_SPEECH_ATTRIBUTE", "Display attributes belong to the display side; escape literal braces in speech.", absoluteStart + index);if (shared && raw[index] === "{") {const before = raw.slice(partStart, index);if (!before || /\s$/u.test(before)) {@@ -551,7 +546,7 @@ export function parseScript(}const marker = parseMarker(raw, index);if (!marker) {- if (raw[index] === "@") fail("SCRIPT_MARKER", "Unescaped @ must begin a valid marker.", absoluteStart + index);+ if (raw[index] === "@") fail("SCRIPT_MARKER", "Unescaped @ must begin a delimited @{...} marker; migrate bare markers from 0.1 explicitly.", absoluteStart + index);index += 1;continue;}@@ -619,6 +614,8 @@ export function parseScript(fail("SCRIPT_SEGMENT_DUPLICATE", `Duplicate Segment id "${id}".`, offset);}const contentStart = offset + open[0].length;+ precedingCaptionRegion = undefined;+ pendingCaptionSpace = false;current = {id,index: segments.length,@@ -660,7 +657,7 @@ export function parseScript(offset += marker.length;continue;}- if (source[offset] === "@") fail("SCRIPT_MARKER", "Unescaped @ must begin a valid marker.", offset);+ if (source[offset] === "@") fail("SCRIPT_MARKER", "Unescaped @ must begin a delimited @{...} marker; migrate bare markers from 0.1 explicitly.", offset);if (source[offset] === "<" && current) {const end = findUnescaped(source, ">", offset + 1);@@ -679,7 +676,7 @@ export function parseScript(assertDualDisplayLiteral(inside.slice(0, pipe), offset + 1);const markedDisplay = parseMarkedDisplay(inside.slice(0, pipe), offset + 1);const display = markedDisplay.display;- if (!speech.replace(/~?@\/?[A-Za-z_][A-Za-z0-9_.-]*!?~?/gu, "").trim()) {+ if (!speech.replace(/@\{[^{}]*\}/gu, "").trim()) {fail("SCRIPT_DUAL_EMPTY", "Dual Text speech side must not be empty.", offset);}consumeSpeechSide(speech, offset + pipe + 2, display, markedDisplay.marks);@@ -689,6 +686,8 @@ export function parseScript(}if (!ROLE_LABEL.test(inside)) fail("SCRIPT_ANGLE", `Unknown Script construct <${inside}>.`, offset);finishLexicalRun();+ precedingCaptionRegion = undefined;+ pendingCaptionSpace = false;current.atoms.push({kind: "role",label: inside,@@ -715,7 +714,6 @@ export function parseScript(offset += 1;}const raw = source.slice(textStart, offset);- if (raw) proseRanges.push({ start: sourceOffset + textStart, end: sourceOffset + offset });for (const piece of literalPieces(raw, textStart)) addText(piece.value, piece.value, piece.start, piece.end, true, piece.positions);if (source[offset] === "{") {const block = parseAttributeBlock(source.slice(offset), offset);@@ -881,7 +879,6 @@ export function parseScript(return {sourceRange: { start: sourceOffset, end: sourceOffset + source.length },- proseRanges,segments,tokens,turns,diff --git a/packages/script/src/types.ts b/packages/script/src/types.tsindex 4fa948d4..79268788 100644--- a/packages/script/src/types.ts+++ b/packages/script/src/types.ts@@ -61,6 +61,7 @@ export type ParsedMoment = Omit<NarrativeMoment, "narrativeId"> & {};export type ParsedCaptionRegion = {+ readonly separatorBefore: "" | " ";readonly id: string;readonly display: string;readonly segmentId: string;@@ -81,8 +82,6 @@ export type ParsedNarrative = Omit<> & {/** Exact Script body range, used only for source-preserving Program-boundary edits. */readonly sourceRange: SourceRange;- /** Ordinary source prose/whitespace; excludes tags, Dual Text, attributes and comments. */- readonly proseRanges: readonly SourceRange[];readonly segments: readonly ParsedSegment[];readonly tokens: readonly ParsedToken[];readonly turns: readonly ParsedTurn[];diff --git a/packages/script/test/display-spacing.test.ts b/packages/script/test/display-spacing.test.tsnew file mode 100644index 00000000..ed0fd629--- /dev/null+++ b/packages/script/test/display-spacing.test.ts@@ -0,0 +1,100 @@+import assert from "node:assert/strict";+import test from "node:test";+import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";+import { tmpdir } from "node:os";+import { join } from "node:path";+import { execFileSync } from "node:child_process";+import { fileURLToPath } from "node:url";+import { adjustScriptSelection, captionDocument, parseScript, serializeCaption, serializeSpeech } from "@hypit/script";++function displayed(body: string) {+ const parsed = parseScript("display", `<line>${body}</line>`);+ const document = captionDocument(parsed, "caption", "story");+ return { parsed, document, text: document.words.map(word => word.separatorBefore + word.text).join("") };+}++for (const text of [+ "是的 就是这样", "是的就是这样", "hello world", "3D", "3 D", "할 수 있습니다",+ "3개월 만에 완성했습니다", "3 개월 만에 완성했습니다", "2026년 9월 17일", "韓國어 표기",+ "韓國 어 표기", "안녕,세계", "안녕, 세계", 'He said "hello world".', "a ( b ) c",+]) test(`display projection preserves authored separation: ${text}`, () => {+ const { parsed, text: actual } = displayed(text);+ assert.equal(actual, text);+ assert.equal(serializeCaption(parsed), text);+});++test("markers, properties and Dual Text boundaries never invent or discard a separator", () => {+ for (const [source, expected] of [+ ["是的@{part}就是这样@{/part}", "是的就是这样"],+ ["是的 @{part}就是这样@{/part}", "是的 就是这样"],+ ["<是的 就是这样|>", "是的 就是这样"],+ ["<안녕|>하세요", "안녕하세요"],+ ["<안녕|> 하세요", "안녕 하세요"],+ ["< 안녕 | 안녕 >하세요", "안녕하세요"],+ ["是的{emphasis} 就是这样", "是的 就是这样"],+ ["<3D{emphasis}|three @{letter!}D> animation", "3D animation"],+ ["是的 <|别显示> 就是这样", "是的 就是这样"],+ ["是的<|别显示>就是这样", "是的就是这样"],+ ["hello{emphasis} . world", "hello . world"],+ ["<hello|> . world", "hello . world"],+ ["할\t수\n있습니다", "할 수 있습니다"],+ ]) {+ const { parsed, text } = displayed(source!);+ assert.equal(text, expected, source);+ assert.equal(serializeCaption(parsed), expected, source);+ }+});++test("shared groups keep punctuation, properties, internal anchors and speech correspondence", () => {+ const { parsed, document, text } = displayed("<组@{beat!}件{emphasis}化|>");+ assert.equal(text, "组件化");+ assert.equal(serializeSpeech(parsed), "组件化");+ assert.equal(document.units.length, 1);+ assert.equal(document.units[0]!.sourceTokenIds.length, 3);+ assert.equal(parsed.moments[0]!.anchorId, parsed.tokens[1]!.startAnchorId);+ assert.deepEqual(document.words[1]!.attributes, [{ name: "emphasis", value: true }]);+});++test("all marker control sigils are delimited and cannot absorb text or punctuation", () => {+ const parsed = displayed("@{a}one@{/a} @{~b}two@{/b~} @{right!}@{~left!}three").parsed;+ assert.equal(parsed.selections[0]!.startAnchorId, parsed.tokens[0]!.startAnchorId);+ assert.equal(parsed.selections[0]!.endAnchorId, parsed.tokens[0]!.endAnchorId);+ assert.equal(parsed.selections[1]!.startAnchorId, parsed.tokens[0]!.endAnchorId);+ assert.equal(parsed.selections[1]!.endAnchorId, parsed.tokens[2]!.startAnchorId);+ assert.equal(parsed.moments.find(m => m.id === "right")!.anchorId, parsed.tokens[2]!.startAnchorId);+ assert.equal(parsed.moments.find(m => m.id === "left")!.anchorId, parsed.tokens[1]!.endAnchorId);+ assert.equal(displayed("@{a}!yes@{/a}").text, "!yes");+ assert.equal(displayed(String.raw`\@\{part\}`).text, "@{part}");+ for (const source of ["@old hi", "@{old", "@{ name}hi", "@{~ /a}", "@{/a!}", "@{a~}", "hel@{beat!}lo", "<x|a{emphasis}>", "<x|<y|z>>"]) {+ assert.throws(() => displayed(source), /SCRIPT_/u, source);+ }+});++test("moving a Selection inside shared text preserves spelling, properties and unrelated markers", () => {+ const source = '<line>@{part}<3D{emphasis}|>@{/part} 是的 就是这样@{end!}</line>';+ const parsed = parseScript("edit", source);+ const next = adjustScriptSelection({ sourceName: "edit", source, parsed, adjustment: {+ id: "part", startAnchorId: parsed.tokens[1]!.startAnchorId, endAnchorId: parsed.tokens[1]!.endAnchorId,+ } });+ assert.equal(next, '<line><3@{part}D{emphasis}@{/part}|> 是的 就是这样@{end!}</line>');+ const after = parseScript("edit", next);+ assert.equal(serializeCaption(after), serializeCaption(parsed));+ assert.equal(serializeSpeech(after), serializeSpeech(parsed));+ assert.deepEqual(captionDocument(after, "c", "s"), captionDocument(parsed, "c", "s"));+});++test("explicit migration changes only Script markers and leaves the original file untouched by default", async () => {+ const directory = await mkdtemp(join(tmpdir(), "hypit-script-migrate-"));+ try {+ const path = join(directory, "film.svml");+ const source = '<prompt>@image1 stays</prompt>\n<script id="s">@whole<line>是的 @part <3D|>@/part @beat!好</line>@/whole~</script>';+ const expected = '<prompt>@image1 stays</prompt>\n<script id="s">@{whole}<line>是的 @{part} <3D|>@{/part} @{beat!}好</line>@{/whole~}</script>';+ await writeFile(path, source);+ const tool = fileURLToPath(new URL("../bin/migrate-0.2.mjs", import.meta.url));+ assert.equal(execFileSync(process.execPath, [tool, path], { encoding: "utf8" }), expected);+ assert.equal(await readFile(path, "utf8"), source);+ execFileSync(process.execPath, [tool, path, "--write"]);+ assert.equal(await readFile(path, "utf8"), expected);+ assert.equal(execFileSync(process.execPath, [tool, path], { encoding: "utf8" }), expected);+ } finally { await rm(directory, { recursive: true, force: true }); }+});diff --git a/packages/script/test/edit.test.ts b/packages/script/test/edit.test.tsindex efe600ef..fa80d190 100644--- a/packages/script/test/edit.test.ts+++ b/packages/script/test/edit.test.ts@@ -1,30 +1,24 @@import assert from "node:assert/strict";import test from "node:test";import { adjustScriptMoment, adjustScriptSelection, captionDocument, narrativeValue, parseScript } from "@hypit/script";-import { cleanHorizontalProse } from "../src/lexical.js";const fixtures = [- '<one><HOST>“Hello,” world{emphasis}! @beat!</one>',- '<one><HOST>你好,世界!@beat!</one>',- '<one><HOST>用<Hypit|Hai Pit>做视频 || 很好。@beat!</one>',- '<one/>\r\n<two><HOST>Hello. @beat!</two>',- '<one> <HOST>first @beat! second.\n <GUEST>Third.</one><two></two>',- '<one>A\n\t ~@beat! B .</one>',- '\t <one>\r\n\t <HOST>We are\r\n\t @beat! talking about Instagram .\r\n\t </one>\r\n',- '<one>\n @beat! \n <HOST>你 好 ,世 界 !\n</one>',- '<one><!-- keep this\n\t comment --> <HOST>用<Hypit|Hai Pit> 做 视频{emphasis} 。@beat!</one>',- '<one>Find \\@hypit now. @beat!</one>',- '<one>Use \\{braces\\} here. @beat!</one>',- '<one><Hypit|Hai \\@ Pit> works. @beat!</one>',- '<one><HOST>把<动效|><组件化|>。@beat!</one>',- '<one><HOST><Git Hub|> <图{emphasis}像|> <\\@Hypit|>。@beat!</one>',+ '<one><HOST>“Hello,” world{emphasis}! @{beat!}</one>',+ '<one><HOST>你好,世界!@{beat!}</one>',+ '<one><HOST>用<Hypit|Hai Pit>做视频 || 很好。@{beat!}</one>',+ '<one/>\r\n<two><HOST>Hello. @{beat!}</two>',+ '<one> <HOST>first @{beat!} second.\n <GUEST>Third.</one><two></two>',+ '<one>A\n\t @{~beat!} B .</one>',+ '\t <one>\r\n\t <HOST>We are\r\n\t @{beat!} talking about Instagram .\r\n\t </one>\r\n',+ '<one>\n @{beat!} \n <HOST>你 好 ,世 界 !\n</one>',+ '<one><!-- keep this\n\t comment --> <HOST>用<Hypit|Hai Pit> 做 视频{emphasis} 。@{beat!}</one>',+ '<one>Find \\@hypit now. @{beat!}</one>',+ '<one>Use \\{braces\\} here. @{beat!}</one>',+ '<one><Hypit|Hai \\@ Pit> works. @{beat!}</one>',+ '<one><HOST>把<动效|><组件化|>。@{beat!}</one>',+ '<one><HOST><Git Hub|> <图{emphasis}像|> <\\@Hypit|>。@{beat!}</one>',];-test("horizontal formatting preserves lexical distinctions and line breaks", () => {- assert.equal(cleanHorizontalProse("3 .14"), "3 .14");- assert.equal(cleanHorizontalProse("Instagram .\n你 好 ,"), "Instagram.\n你好,");-});-for (const source of fixtures) test(`Moment round trips through structural and lexical anchors: ${source}`, () => {const original = parseScript("edit", source);const move = (text: string, anchorId: string) => adjustScriptMoment({@@ -40,8 +34,8 @@ for (const source of fixtures) test(`Moment round trips through structural and l}});-test("normalization retains line indentation and removes marker residue without remembering its origin", () => {- const source = '<one>\r\n\t <HOST>We are\r\n\t @beat! on Instagram . \r\n\t </one>';+test("moving a marker preserves every source whitespace character without accumulating residue", () => {+ const source = '<one>\r\n\t <HOST>We are\r\n\t @{beat!} on Instagram . \r\n\t </one>';const original = parseScript("edit", source);const originalAnchor = original.moments[0]!.anchorId;const end = original.tokens.at(-1)!.endAnchorId;@@ -49,7 +43,7 @@ test("normalization retains line indentation and removes marker residue withoutsourceName: "edit", source: text, parsed: parseScript("edit", text), adjustment: { id: "beat", anchorId },});const atEnd = move(source, end);- assert.equal(atEnd, '<one>\r\n\t <HOST>We are\r\n\t on Instagram.~@beat!\r\n\t </one>');+ assert.equal(atEnd, '<one>\r\n\t <HOST>We are\r\n\t on Instagram@{~beat!} . \r\n\t </one>');let current = atEnd;for (let index = 0; index < 30; index++) {current = move(move(current, originalAnchor), end);@@ -58,22 +52,21 @@ test("normalization retains line indentation and removes marker residue withoutassert.equal(move(atEnd, end), atEnd);});-test("equivalent inline whitespace converges to the same marker spelling", () => {+test("an unchanged Selection leaves its source formatting untouched", () => {const sources = [- '<one><HOST>@social on Instagram @/social .</one>',- '<one><HOST>@social on Instagram.@/social</one>',+ '<one><HOST>@{social} on Instagram @{/social} .</one>',+ '<one><HOST>@{social} on Instagram.@{/social}</one>',];const normalized = sources.map(source => {const parsed = parseScript("edit", source);const selection = parsed.selections[0]!;return adjustScriptSelection({ sourceName: "edit", source, parsed, adjustment: selection });});- assert.equal(normalized[0], normalized[1]);- assert.match(normalized[0]!, /on Instagram\.@\/social/u);+ assert.deepEqual(normalized, sources);});test("Selection endpoints sharing a source position are written together in semantic order", () => {- const source = '<one><HOST>@range hello @/range world.</one><empty/>';+ const source = '<one><HOST>@{range} hello @{/range} world.</one><empty/>';const original = parseScript("edit", source);const anchors = original.semanticIndex.anchors;for (let start = 0; start < anchors.length; start++) for (let end = start; end < anchors.length; end++) {@@ -86,11 +79,11 @@ test("Selection endpoints sharing a source position are written together in sema});for (const source of [- '<one>A @s B . @/s</one>',- '<one>A ~@s B . @/s</one>',- '<one>@s A @/s B .</one>',- '<one>@s A @/s~ B .</one>',- '<one><HOST>@s <动效|><组件化|> @/s</one>',+ '<one>A @{s} B . @{/s}</one>',+ '<one>A @{~s} B . @{/s}</one>',+ '<one>@{s} A @{/s} B .</one>',+ '<one>@{s} A @{/s~} B .</one>',+ '<one><HOST>@{s} <动效|><组件化|> @{/s}</one>',]) test(`Selection affinity survives every structural round trip: ${source}`, () => {const original = parseScript("edit", source);const selection = original.selections[0]!;@@ -105,12 +98,14 @@ for (const source of [const actual = parseScript("edit", moved).selections[0]!;assert.equal(actual.startAnchorId, anchors[start]!.id);assert.equal(actual.endAnchorId, anchors[end]!.id);- assert.equal(move(moved, selection.startAnchorId, selection.endAnchorId), expected);+ const back = move(moved, selection.startAnchorId, selection.endAnchorId);+ assert.deepEqual(narrativeValue(parseScript("edit", back), "story"), narrativeValue(original, "story"));+ assert.equal(back.replace(/@\{[^{}]+\}/gu, ""), expected.replace(/@\{[^{}]+\}/gu, ""));}});test("Moving one relationship preserves crossing selections, cues and other moments", () => {- const source = '<one><HOST>@a One @b two @/a || three @/b. @beat! ~@other!</one>';+ const source = '<one><HOST>@{a} One @{b} two @{/a} || three @{/b}. @{beat!} @{~other!}</one>';const parsed = parseScript("edit", source);const next = adjustScriptMoment({ sourceName: "edit", source, parsed,adjustment: { id: "beat", anchorId: parsed.tokens[0]!.endAnchorId } });diff --git a/packages/script/test/narrative-views.test.ts b/packages/script/test/narrative-views.test.tsindex 30d69a16..60620874 100644--- a/packages/script/test/narrative-views.test.ts+++ b/packages/script/test/narrative-views.test.ts@@ -12,9 +12,9 @@ import type { SurfaceResolvedReference } from "@hypit/markup";import { countSpeechEstimateUnits } from "@hypit/estimate";import type { Text } from "@hypit/text";-const body = `<intro><HOST>Try @brand <hypit|Hai-Pit> @/brand today. ||</intro>+const body = `<intro><HOST>Try @{brand} <hypit|Hai-Pit> @{/brand} today. ||</intro><gap/>-<closing><HOST>现在 @name <声工坊|voice workshop> @/name 好用。<|indeed></closing>`;+<closing><HOST>现在 @{name} <声工坊|voice workshop> @{/name} 好用。<|indeed></closing>`;function authored() {return narrativeValue(parseScript("views.svml", body), "story") as unknown as Narrative;@@ -44,16 +44,16 @@ test("omitted speech shares display prose while retaining ordinary Narrative and});test("shared text permits semantic markers without changing display; empty groups still fail", () => {- const parsed = parseScript("shared", '<intro><HOST><组@part 件@/part化|></intro>');+ const parsed = parseScript("shared", '<intro><HOST><组@{part}件@{/part}化|></intro>');assert.equal(parsed.serializations.speech, "组件化");assert.equal(parsed.captionProjection.text, "组件化");assert.equal(parsed.selections[0]!.startAnchorId, parsed.tokens[1]!.startAnchorId);assert.equal(captionDocument(parsed, "caption", "story").units[0]!.sourceTokenIds.length, 3);- for (const body of ['<|>', '< | >', '<@beat!|>', '<...|>']) {+ for (const body of ['<|>', '< | >', '<@{beat!}|>', '<...|>']) {assert.throws(() => parseScript("empty", `<intro>${body}</intro>`), /omitted speech must contain spoken text/u);}assert.throws(() => parseScript("cue", '<intro><动效|动||效></intro>'), /Cue break cannot occur inside/u);- assert.throws(() => parseScript("explicit", '<intro><@bad 字|word></intro>'), /spoken text, not the Dual display side/u);+ assert.throws(() => parseScript("explicit", '<intro><@{bad} 字|word></intro>'), /spoken text, not the Dual display side/u);});test("Script exports complete author content and a caption view from that same value", () => {diff --git a/packages/script/test/script.test.ts b/packages/script/test/script.test.tsindex 0a4c1a74..ee3d65fb 100644--- a/packages/script/test/script.test.ts+++ b/packages/script/test/script.test.ts@@ -14,7 +14,7 @@ import {} from "@hypit/script";test("Selection source edits relocate markers by 2M + 2N + 2 Anchor identity", () => {- const source = "<one><HOST>@focus alpha beta @/focus gamma</one>\r\n<two><HOST>delta epsilon</two>";+ const source = "<one><HOST>@{focus} alpha beta @{/focus} gamma</one>\r\n<two><HOST>delta epsilon</two>";const parsed = parseScript("selection-adjust.svml", source);const movedWords = adjustScriptSelection({sourceName: "selection-adjust.svml",@@ -52,30 +52,30 @@ test("Program boundaries are distinct writable semantic Anchors", () => {const source = "<one>alpha</one>\n<two>beta</two>";const withSelection = adjustScriptSelection({sourceName: "program-boundaries.svml",- source: "@focus <one>alpha</one>\n<two>beta @/focus</two>",- parsed: parseScript("program-boundaries.svml", "@focus <one>alpha</one>\n<two>beta @/focus</two>"),+ source: "@{focus} <one>alpha</one>\n<two>beta @{/focus}</two>",+ parsed: parseScript("program-boundaries.svml", "@{focus} <one>alpha</one>\n<two>beta @{/focus}</two>"),adjustment: { id: "focus", startAnchorId: "program:start", endAnchorId: "program:end" },});const selection = parseScript("program-boundaries.svml", withSelection).selections[0]!;assert.deepEqual([selection.startAnchorId, selection.endAnchorId], ["program:start", "program:end"]);- assert.match(withSelection, /^~@focus(?=[ <])/u);- assert.match(withSelection, /@\/focus~$/u);+ assert.match(withSelection, /^@\{~focus\}(?=[ <])/u);+ assert.match(withSelection, /@\{\/focus~\}$/u);const withMoment = adjustScriptMoment({sourceName: "program-boundaries.svml",- source: `${source.slice(0, source.indexOf("beta"))}@cue! ${source.slice(source.indexOf("beta"))}`,+ source: `${source.slice(0, source.indexOf("beta"))}@{cue!} ${source.slice(source.indexOf("beta"))}`,parsed: parseScript("program-boundaries.svml",- `${source.slice(0, source.indexOf("beta"))}@cue! ${source.slice(source.indexOf("beta"))}`,+ `${source.slice(0, source.indexOf("beta"))}@{cue!} ${source.slice(source.indexOf("beta"))}`,),adjustment: { id: "cue", anchorId: "program:end" },});assert.equal(parseScript("program-boundaries.svml", withMoment).moments[0]!.anchorId, "program:end");- assert.match(withMoment, /@cue!$/u);+ assert.match(withMoment, /@\{cue!\}$/u);});test("Moment source edits relocate one marker to an exact semantic Anchor", () => {- const source = "<one><HOST>alpha @cue! beta</one><two><HOST>gamma</two>";+ const source = "<one><HOST>alpha @{cue!} beta</one><two><HOST>gamma</two>";const moved = adjustScriptMoment({sourceName: "moment-adjust.svml",source,@@ -161,16 +161,16 @@ test("A single pipe is literal and a double pipe is an authored Cue Break", () =const document = captionDocument(parsed, "story.caption", "story");assert.equal(document.cueBreaks.length, 1);assert.equal(serializeCaption(parsed), "one | two three || four");- assert.deepEqual(document.words.map((word) => word.text), ["one|", "two", "three||", "four"]);+ assert.deepEqual(document.words.map((word) => word.text), ["one |", "two", "three ||", "four"]);});test("Dual display text cannot contain semantic markers", () => {assert.throws(- () => parseScript("dual-marker.svml", "<line><@bad | spoken></line>"),+ () => parseScript("dual-marker.svml", "<line><@{bad} | spoken></line>"),(error: unknown) => error instanceof ScriptSyntaxError && error.code === "SCRIPT_DUAL_DISPLAY_MARKER",);- const parsed = parseScript("dual-spoken-selection.svml", "<line><shown | @start spoken words @/start></line>");+ const parsed = parseScript("dual-spoken-selection.svml", "<line><shown | @{start} spoken words @{/start}></line>");assert.equal(parsed.selections.length, 1);});diff --git a/packages/studio/src/ui/code.ts b/packages/studio/src/ui/code.tsindex cf0af920..d0959e95 100644--- a/packages/studio/src/ui/code.ts+++ b/packages/studio/src/ui/code.ts@@ -354,7 +354,7 @@ export function createCodePane(): CodePane {else {const span = document.createElement("span");// A marker pair shares a tone with the clip it binds, so the two- // ends of `@claim … @/claim` read as one thing.+ // ends of `@{claim} … @{/claim}` read as one thing.const tone = token.id === undefined ? undefined : tones.get(token.id);span.className = `tok tok-${token.kind}${tone === undefined ? "" : ` tone-${tone}`}`;if (token.id !== undefined) span.dataset.marker = token.id;diff --git a/packages/studio/src/ui/main.ts b/packages/studio/src/ui/main.tsindex c971efa5..a6ea3efa 100644--- a/packages/studio/src/ui/main.ts+++ b/packages/studio/src/ui/main.ts@@ -1034,8 +1034,8 @@ code.element.addEventListener("click", (event) => {const clip = clipAtOffset(state.snapshot, offset);// A click inside marked prose lands inside the innermost marker written there,- // not at the start of whatever encloses it. `@amount` places nothing, so- // resolving through clips alone would throw the playhead out to `@fee`.+ // not at the start of whatever encloses it. `@{amount}` places nothing, so+ // resolving through clips alone would throw the playhead out to `@{fee}`.const span = spanAtOffset(state.snapshot, offset);// Prose is anywhere a marker was written; whether a clip also covers that// offset only decides which clip to select, not whether the click counts.diff --git a/packages/studio/src/ui/markers.ts b/packages/studio/src/ui/markers.tsindex bbdd5683..bed4ef4c 100644--- a/packages/studio/src/ui/markers.ts+++ b/packages/studio/src/ui/markers.ts@@ -55,12 +55,12 @@ export function intentTones(snapshot: StudioSnapshot): ReadonlyMap<string, numbe* The Script ranges whose speech the playhead is inside, outermost first.** Segments and Selections alike, because a Segment is a level too: `<price>`- * encloses `@bags`, so drawing only the Selection would show a nesting with its+ * encloses `@{bags}`, so drawing only the Selection would show a nesting with its* outermost level missing.** Derived from the Script tokens each range encloses rather than from the clips* bound to it, because a range is a claim about speech whether or not anything- * was placed on it. `@amount` inside `@fee` is still inside `@fee` even when+ * was placed on it. `@{amount}` inside `@{fee}` is still inside `@{fee}` even when* only the outer one drives a Media Item.*/export type ScriptSpan = {@@ -110,7 +110,7 @@ export function liveRanges(snapshot: StudioSnapshot, frame: number): readonly Sc** Clicking marked prose should land inside the thing that was clicked, and the* innermost intent is the most specific claim there. Resolving to a clip alone- * would send a click on `@amount` to whatever encloses it, because a marker that+ * would send a click on `@{amount}` to whatever encloses it, because a marker that* places nothing still means something.*/export function spanAtOffset(snapshot: StudioSnapshot, offset: number): ScriptSpan | undefined {diff --git a/packages/studio/src/ui/selection.ts b/packages/studio/src/ui/selection.tsindex e5a924eb..673e48b7 100644--- a/packages/studio/src/ui/selection.ts+++ b/packages/studio/src/ui/selection.ts@@ -53,7 +53,7 @@ export type Store = {/*** The clip an author is pointing at in the source text.*- * A Script intent wins over the element that binds it: `@claim … @/claim` sits+ * A Script intent wins over the element that binds it: `@{claim} … @{/claim}` sits* inside the `<script>` element, so without that preference every click in the* prose would select the Speech Take instead of the B-roll. Ties break toward* the tightest range, which is the most specific thing under the cursor.diff --git a/packages/studio/src/ui/syntax.ts b/packages/studio/src/ui/syntax.tsindex 624e4d9f..b83fa392 100644--- a/packages/studio/src/ui/syntax.ts+++ b/packages/studio/src/ui/syntax.ts@@ -4,7 +4,7 @@* SVML has a small, closed grammar — tags, quoted strings, whole-value* references, and Script prose with markers — so it is tokenized directly rather* than through a general highlighter that has no grammar for it. The Script- * markers are the point: `@claim … @/claim` is what a Media Item binds to, so it+ * markers are the point: `@{claim} … @{/claim}` is what a Media Item binds to, so it* has to read as a distinct thing from an ordinary attribute.** Tokens are non-overlapping and in source order. Gaps between them are plain@@ -33,12 +33,30 @@ export type Token = {const NAME = /^[A-Za-z_][A-Za-z0-9_.:-]*/u;const ATTRIBUTE = /^[A-Za-z_][A-Za-z0-9_.:-]*/u;-/**- * The Script's own marker grammar: `@id` opens a Selection, `@/id` closes one,- * `@id!` marks a Moment, and a leading `~` or trailing `~` chooses which side of- * the neighbouring word the marker binds to.- */-const MARKER = /^~?@\/?[a-z][a-z0-9_-]*[!~]?/u;+/** All control sigils belong inside a delimited Script marker. */+const MARKER = /^@\{(?:(~)?([a-z][a-z0-9_-]{0,63})(!)?|\/([a-z][a-z0-9_-]{0,63})(~)?)\}/u;++function unescapedIndex(source: string, character: string, from: number, to = source.length): number {+ for (let index = from; index < to; index++) {+ if (source[index] === "\\") { index++; continue; }+ if (source[index] === character) return index;+ }+ return -1;+}++function scriptDecoration(source: string, cursor: number, push: Push, markers = true, attributes = true): number {+ if (source[cursor] === "\\") return cursor + 2;+ const marker = markers ? MARKER.exec(source.slice(cursor)) : null;+ if (marker) {+ push(cursor, cursor + marker[0].length, "marker", marker[2] ?? marker[4]);+ return cursor + marker[0].length;+ }+ if (attributes && source[cursor] === "{") {+ const end = unescapedIndex(source, "}", cursor + 1);+ if (end >= 0) { push(cursor, end + 1, "attr"); return end + 1; }+ }+ return cursor + 1;+}function localName(tag: string): string {const colon = tag.indexOf(":");@@ -145,11 +163,12 @@ function tokenizeAttributes(source: string, from: number, push: Push): number {return cursor;}-/** Script prose: Segment and Role Cue tags stay tags; `@id` markers stand out. */+/** Script prose: Segment and Role Cue tags stay tags; `@{id}` markers stand out. */function tokenizeScriptBody(source: string, from: number, tag: string, push: Push): number {const close = `</${tag}>`;let cursor = from;while (cursor < source.length) {+ if (source[cursor] === "\\") { cursor += 2; continue; }if (source.startsWith(close, cursor)) {push(cursor, cursor + 2, "punct");push(cursor + 2, cursor + 2 + tag.length, "tag");@@ -164,6 +183,20 @@ function tokenizeScriptBody(source: string, from: number, tag: string, push: Puscontinue;}if (source[cursor] === "<") {+ const endDual = unescapedIndex(source, ">", cursor + 1);+ const pipe = endDual < 0 ? -1 : unescapedIndex(source, "|", cursor + 1, endDual);+ if (pipe >= 0) {+ const shared = !source.slice(pipe + 1, endDual).trim();+ push(cursor, cursor + 1, "punct");+ cursor++;+ while (cursor < pipe) cursor = scriptDecoration(source, cursor, push, shared, true);+ push(pipe, pipe + 1, "punct");+ cursor = pipe + 1;+ while (cursor < endDual) cursor = scriptDecoration(source, cursor, push, true, false);+ push(endDual, endDual + 1, "punct");+ cursor = endDual + 1;+ continue;+ }const closing = source[cursor + 1] === "/";const nameStart = cursor + (closing ? 2 : 1);const name = NAME.exec(source.slice(nameStart));@@ -177,19 +210,7 @@ function tokenizeScriptBody(source: string, from: number, tag: string, push: Puscursor = stop;continue;}- // A leading `~` binds the marker to the word on its left, and is part of it.- if (source[cursor] === "@" || (source[cursor] === "~" && source[cursor + 1] === "@")) {- const marker = MARKER.exec(source.slice(cursor));- if (marker !== null) {- // Strip the affinity sigils, the `@` and the closing `/` so an opening- // marker, its closing marker and a Moment all report the same name.- const id = marker[0].replace(/^~?@\/?/u, "").replace(/[!~]$/u, "");- push(cursor, cursor + marker[0].length, "marker", id);- cursor += marker[0].length;- continue;- }- }- cursor += 1;+ cursor = scriptDecoration(source, cursor, push);}return cursor;}diff --git a/packages/studio/test/script-syntax.test.ts b/packages/studio/test/script-syntax.test.tsnew file mode 100644index 00000000..d0a036a1--- /dev/null+++ b/packages/studio/test/script-syntax.test.ts@@ -0,0 +1,13 @@+import assert from "node:assert/strict";+import test from "node:test";+import { tokenizeSvml } from "../src/ui/syntax.js";++test("Studio distinguishes delimited Script markers from properties, escapes and generation references", () => {+ const source = '<script id="s"><line>@{a}hello{emphasis}@{/a} <New @{beat!}York|> <3D|three @{d!}D> \\@\\{literal\\}</line></script><prompt>@image1</prompt>';+ const tokens = tokenizeSvml(source);+ assert.deepEqual(tokens.filter(token => token.kind === "marker").map(token => [token.id, source.slice(token.start, token.end)]), [+ ["a", "@{a}"], ["a", "@{/a}"], ["beat", "@{beat!}"], ["d", "@{d!}"],+ ]);+ assert.equal(tokens.filter(token => token.kind === "attr").some(token => source.slice(token.start, token.end) === "{emphasis}"), true);+ for (let index = 1; index < tokens.length; index++) assert.ok(tokens[index]!.start >= tokens[index - 1]!.end);+});diff --git a/packages/studio/test/semantic-gesture.test.ts b/packages/studio/test/semantic-gesture.test.tsindex 45fbe017..a4e3b0ad8 100644--- a/packages/studio/test/semantic-gesture.test.ts+++ b/packages/studio/test/semantic-gesture.test.ts@@ -6,7 +6,7 @@ import { projectProgramInstant } from "@hypit/temporal";import { parseTemporalInstant } from "@hypit/temporal-markup";import { chooseSemanticGesture, formatTemporalPointEdit, semanticGestureSpan } from "../src/temporal-edit.js";-const source = '<one><HOST>@proof One two @/proof three.</one>';+const source = '<one><HOST>@{proof} One two @{/proof} three.</one>';const narrative = parseScript("gesture", source);// Duplicate word/Segment boundaries count as one stop, not additional movement steps.const frames = [0, 0, 0, 5, 10, 20, 40, 55, 55, 55];diff --git a/packages/temporal-markup/README.md b/packages/temporal-markup/README.mdindex fd6e8794..3dd8d171 100644--- a/packages/temporal-markup/README.md+++ b/packages/temporal-markup/README.md@@ -75,7 +75,7 @@ time and implements its own schedule or state, while the shared temporal protocotime came from. An outer lifetime and child activations are separate inputs when a component persistsbetween events.-Script's `@`, `~@`, close markers and Moment syntax belong to `@hypit/script`; media playback belongs+Script's delimited `@{...}` Selection and Moment syntax belong to `@hypit/script`; media playback belongsto `@hypit/media-track`; a graphic component's reveal or preset semantics belong to that component.## Independently bound endpointsdiff --git a/skills/hypit/references/creation/script-and-time.md b/skills/hypit/references/creation/script-and-time.mdindex 5f9f529e..b9caaf83 100644--- a/skills/hypit/references/creation/script-and-time.md+++ b/skills/hypit/references/creation/script-and-time.md@@ -36,7 +36,7 @@ Choose Script structure from the thought being expressed and the performance car```svml<script id="story"><hook>- <HOST> @claim! I made the @proof <API | A P I> || work overnight @/proof.+ <HOST> @{claim!} I made the @{proof} <API | A P I> || work overnight @{/proof}.</hook></script>```@@ -66,8 +66,8 @@ The author-facing forms are:| `||` | A Caption Cue handoff between complete Alignment Units. || `word{emphasis,keyword}` | Boolean attributes on one complete display word for a Caption family to interpret. || `word{importance=2,tone=warm}` | Named string, number or boolean attribute values on that display word. |-| `@proof ... @/proof` | A Selection: one named semantic range. |-| `@claim!` | A Moment: one named semantic point. |+| `@{proof} ... @{/proof}` | A Selection: one named semantic range. |+| `@{claim!}` | A Moment: one named semantic point. |A Script contains one or more uniquely named lower-case Segments. A paired Segment can carry proseor be wordless; the self-closing form also carries a wordless passage. A Role Cue is a bare turn marker rather than a@@ -90,7 +90,7 @@ Chinese prose does not require word-by-word markup. The group's Style determines`||` still controls which reading phrases appear as separate Cues.With speech omitted, the left side supplies both projections, so semantic markers can be placed-there and Studio writes back there: `<组@beat!件化|>`. Display attributes and markers are metadata,+there and Studio writes back there: `<组@{beat!}件化|>`. Display attributes and markers are metadata,not spoken words. Attributes still apply to the preceding display word rather than the whole group.With an explicit spoken side, markers continue to belong on that right-hand side.@@ -292,32 +292,38 @@ For a picture, Caption treatment, MG state, sound, or effect that belongs to spoSelection or Moment and use the consuming component's Surface to project it through the Timeline.Use explicit seconds for genuinely clock-based or speechless design.+Every semantic marker is enclosed in `@{...}`, with `/`, `!` and `~` inside. The marker contributes+no text or whitespace. `是的@{part}就是这样@{/part}` stays joined; `是的 @{part}就是这样@{/part}`+keeps its authored space. Do not add spaces to make a marker parse. Markers cannot split a speech+Token. Attributes stay attached to their display word: `word{emphasis}@{beat!}`. Write literal+`@{part}` as `\@\{part\}`. Bare 0.1 markers require explicit migration before use with 0.2.+Selections may overlap, cross, or span Segments; they are named semantic ranges rather than nestedmarkup. Selection and Moment names share one namespace. Inside spoken text, each marker chooses anadjacent semantic boundary:| Marker | Boundary || --- | --- |-| `@name` | Open a Selection at the next word's start. |-| `~@name` | Open a Selection at the previous word's end. |-| `@/name` | Close a Selection at the previous word's end. |-| `@/name~` | Close a Selection at the next word's start. |-| `@name!` | Place a Moment at the next word's start. |-| `~@name!` | Place a Moment at the previous word's end. |+| `@{name}` | Open a Selection at the next word's start. |+| `@{~name}` | Open a Selection at the previous word's end. |+| `@{/name}` | Close a Selection at the previous word's end. |+| `@{/name~}` | Close a Selection at the next word's start. |+| `@{name!}` | Place a Moment at the next word's start. |+| `@{~name!}` | Place a Moment at the previous word's end. |Markers may sit between or outside Segments when the meaning crosses structural passages. Forexample, this Selection owns the complete Script program rather than borrowing the first and lastword boundaries:```svml-~@whole+@{~whole}<opening><HOST>First thought.</opening><answer><HOST>Final answer.</answer>-@/whole~+@{/whole~}```At a Script or Segment edge, the corresponding structural boundary remains available even when-there is no neighboring word. Thus `@videos videos @/videos` covers exactly that word. For adjacent+there is no neighboring word. Thus `@{videos} videos @{/videos}` covers exactly that word. For adjacentB-roll windows that should also own the pause between words, choose which neighboring Selectionowns that gap through the explicit affinities; [B-roll craft](../playbooks/craft/b-roll.md) shows theshared-boundary forms.diff --git a/skills/hypit/references/playbooks/craft/b-roll.md b/skills/hypit/references/playbooks/craft/b-roll.mdindex f4946501..f3f81b29 100644--- a/skills/hypit/references/playbooks/craft/b-roll.md+++ b/skills/hypit/references/playbooks/craft/b-roll.md@@ -82,13 +82,13 @@ each shared boundary must select the same instant. Default markers close on theand open on the next word's start, leaving their intervening pause uncovered.```text-@coffee my coffee @/coffee ~@smoothie my smoothie @/smoothie+@{coffee} my coffee @{/coffee} @{~smoothie} my smoothie @{/smoothie}```Here both sides meet at the end of “coffee”; the smoothie picture owns the pause. Alternatively:```text-@coffee my coffee @/coffee~ @smoothie my smoothie @/smoothie+@{coffee} my coffee @{/coffee~} @{smoothie} my smoothie @{/smoothie}```Both sides now meet at the start of the next “my”; the coffee picture owns the pause. Keep bothdiff --git a/skills/hypit/references/playbooks/craft/captions.md b/skills/hypit/references/playbooks/craft/captions.mdindex 0fec5fd6..7b880117 100644--- a/skills/hypit/references/playbooks/craft/captions.md+++ b/skills/hypit/references/playbooks/craft/captions.md@@ -125,8 +125,11 @@ or character count cannot make that choice. Count the display side of Dual Text| Chinese | Keep compounds, names, modifiers and their objects together. Let a complete short clause share a Cue when it fits; repeated tiny character groups fragment both meaning and the screen. || Mixed Chinese and English | Read the phrase as a whole. A Latin brand name or number can occupy several Han characters' width; its lexical unit count does not predict that width. |-Fine already leaves adjacent Han characters together without English word gaps. Its `word-gap`-controls spaced boundaries, including Chinese/Latin transitions; `letter-spacing` adjusts tracking.+Fine preserves authored display separators in every writing system. Its `word-gap` sizes those+separators; a Chinese/Latin or number/letter boundary does not create one. Write `是的 就是这样`+when that space is intended, and `3D` or `3개월` when the text should stay joined. `letter-spacing`+adjusts glyph tracking. `<expression|>` groups an expression for caption behavior; it is not needed+to preserve spelling or spaces.The same timing supports a stable complete Cue, current-character color or a trail. For flowingChinese speech, a readable phrase with restrained emphasis often works better than a separate bounceor reveal on every character. Choose the response for the performance's energy.diff --git a/skills/hypit/references/production/caption-authoring.md b/skills/hypit/references/production/caption-authoring.mdindex cce9d200..bfe7b41d 100644--- a/skills/hypit/references/production/caption-authoring.md+++ b/skills/hypit/references/production/caption-authoring.md@@ -51,6 +51,11 @@ Track Uses → resolved time windows, Styles and optional speaker filterscomplete Cues + Uses + family parameters → family schedule → VisualTrack```+Consume each display word's `separatorBefore` with its `text`; never rebuild wording by joining+speech Tokens with spaces or guessing from a writing system. Suppress a separator at the start of+a displayed Cue/line. Use the same authored boundaries in base glyphs, active layers and backgrounds.+Separators are display content, not timed Tokens.+Use `@hypit/hypit/caption` for content timing and Use coverage, and `@hypit/hypit/narrative` forScript document types. A family Track accepts `document`, `timeline` and ordered `Use` children:diff --git a/skills/hypit/references/production/caption-presentation.md b/skills/hypit/references/production/caption-presentation.mdindex d21f4f35..bfe8e9fe 100644--- a/skills/hypit/references/production/caption-presentation.md+++ b/skills/hypit/references/production/caption-presentation.md@@ -48,7 +48,7 @@ to draw. Independent Caption Tracks can intentionally show multiple presentation## A style change can happen inside a Cue```text-test1 || test2 @select test3 || test4 @/select+test1 || test2 @{select} test3 || test4 @{/select}```This contains three Cues: `test1`, `test2 test3`, and `test4`. The Selection starts before `test3`;diff --git a/skills/hypit/references/production/examples/production.svml b/skills/hypit/references/production/examples/production.svmlindex b7fb76b5..bd7a3ed3 100644--- a/skills/hypit/references/production/examples/production.svml+++ b/skills/hypit/references/production/examples/production.svml@@ -18,7 +18,7 @@<import as="look" source="./look.svs"/><script id="story">- <opening><HOST>Here is @proof the useful part @/proof.</opening>+ <opening><HOST>Here is @{proof} the useful part @{/proof}.</opening></script><space:Canvas id="canvas" width="720" height="1280"/><program:Clock id="clock" frame-rate="30"/>diff --git a/skills/hypit/references/production/source-syntax.md b/skills/hypit/references/production/source-syntax.mdindex 0a6e2ba6..5a97b9f7 100644--- a/skills/hypit/references/production/source-syntax.md+++ b/skills/hypit/references/production/source-syntax.md@@ -21,7 +21,7 @@ This small Author Source produces Text and Script values; it makes no media requ<import as="kit" source="./direction.svs"/><script id="story">- <opening><HOST>Here is @proof the useful part @/proof.</opening>+ <opening><HOST>Here is @{proof} the useful part @{/proof}.</opening></script><copy:Value id="direction">She leans in slightly, amused by her own observation.</copy:Value><copy:Render id="prompt" template={kit.performance}>