@lalalic/markcut 3.2.63 → 3.2.65

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lalalic/markcut",
3
- "version": "3.2.63",
3
+ "version": "3.2.65",
4
4
  "description": "Markdown-to-video engine. Describe scenes in markdown, get a rendered video.",
5
5
  "bin": {
6
6
  "markcut": "bin/markcut"
@@ -84,21 +84,63 @@ function mediaSrc(videoPath,edit){
84
84
  if(candidates.length!==1)throw Error('EDL source_id '+JSON.stringify(id)+' does not uniquely resolve; specify source_src');
85
85
  return confinedMediaSrc(videoPath,'input/media/'+candidates[0]);
86
86
  }
87
- const html=s=>String(s??'').replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;').replace(/'/g,'&#39;').replace(/[\r\n]+/g,' ');
88
- const short=(s,n=140)=>{const text=String(s??'').trim();return text.length>n?text.slice(0,n-1)+'…':text;};
89
- function overlay(edit,index,src){
90
- const fields=[edit.shot_purpose||edit.beat||edit.story_beat_id,edit.editor_reason||edit.cut_reason,edit.visual_relationship,edit.sound_decision||edit.audioIntent,edit.revision_note].filter(nonEmpty).map(s=>short(s));
91
- const lines=['SOURCE: '+src+' ['+edit.in_seconds.toFixed(2)+'–'+edit.out_seconds.toFixed(2)+'s]',...fields].slice(0,5);
92
- const body=lines.map((line,i)=>'<div style={{fontSize:'+(i===0?18:24)+',opacity:'+(i===0?0.7:1)+",marginTop:10,overflowWrap:'anywhere'}}>"+html(line)+'</div>').join('');
93
- return "<div style={{boxSizing:'border-box',width:'100%',height:'100%',display:'flex',flexDirection:'column',justifyContent:'flex-end',padding:'5%',color:'white',fontFamily:'Arial,sans-serif',background:'linear-gradient(0deg,rgba(0,0,0,.94),rgba(0,0,0,.6) 45%,transparent 90%)'}}><div style={{fontSize:33,fontWeight:700}}>SHOT "+(index+1)+' · '+html(edit.shot_id)+'</div>'+body+'</div>';
87
+ // Escape JSX expression delimiters as well as HTML, since EDL strings are
88
+ // inserted into JSX children, not into an ordinary inert HTML document.
89
+ const html=s=>String(s??'').replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;').replace(/'/g,'&#39;').replace(/{/g,'&#123;').replace(/}/g,'&#125;').replace(/[\r\n]+/g,' ');
90
+ // Keep complete Editorial Decision text in the playable overlay: EDL is the
91
+ // source of truth and should never be silently ellipsized or drop fields.
92
+ // Prefer the large 1080x1920 typography, then decrease type only when the
93
+ // FULL caption needs the space. Unlike a scroll region, these sizes are
94
+ // deterministic Remotion frames and remain visible in exported video.
95
+ function shotTypography(edit,src,sections,width,height){
96
+ const canvasScale=Math.min(width/1080,height/1920);
97
+ // CSS percentage padding uses the container WIDTH on all four sides.
98
+ const usableWidth=width*0.90,usableHeight=height-width*0.10;
99
+ const glyphWidth=text=>[...String(text)].reduce((sum,ch)=>sum+(
100
+ /[\u2E80-\u9FFF\uAC00-\uD7AF\uFF01-\uFF60]/u.test(ch)?1:
101
+ /\s/.test(ch)?.36:/[iIl.,:;!|'`]/.test(ch)?.34:/[MW@#%&]/.test(ch)?.83:.61),0);
102
+ const estimateLines=(text,font)=>Math.max(1,Math.ceil(glyphWidth(text)*font*1.18/usableWidth));
103
+ const source=`SOURCE: ${src} [${edit.in_seconds.toFixed(2)}–${edit.out_seconds.toFixed(2)}s]`;
104
+ const desc=sections.map(([label,text])=>`${label}: ${text}`);
105
+ for(let n=20;n>=9;n--){
106
+ const shrink=n/20*canvasScale;
107
+ const title=68*shrink,sourceFont=38*shrink,body=46*shrink,gap=23*shrink;
108
+ const needed=estimateLines(`SHOT ${edit.shot_id}`,title)*title*1.14+
109
+ estimateLines(source,sourceFont)*sourceFont*1.3+
110
+ desc.reduce((sum,text)=>sum+estimateLines(text,body)*body*1.28,0)+
111
+ (desc.length+1)*gap;
112
+ if(needed<=usableHeight*0.95)
113
+ return {title:Math.round(title*100)/100,source:Math.round(sourceFont*100)/100,body:Math.round(body*100)/100,label:Math.round(34*shrink*100)/100,gap:Math.round(gap*100)/100};
114
+ }
115
+ throw Error('EDL Shot '+edit.shot_id+' has too much decision text to fit on one frame; split the decision into separate shots instead of clipping it');
116
+ }
117
+ function overlay(edit,index,src,width,height){
118
+ const sections=[
119
+ ['BEAT',edit.shot_purpose],
120
+ ['STORY',edit.beat],
121
+ ['STORY BEAT ID',edit.story_beat_id],
122
+ ['EDITOR REASON',edit.editor_reason],
123
+ ['CUT REASON',edit.cut_reason],
124
+ ['VISUAL RELATIONSHIP',edit.visual_relationship],
125
+ ['SOUND DECISION',edit.sound_decision],
126
+ ['AUDIO INTENT',edit.audioIntent],
127
+ ['TRANSITION',edit.transition],
128
+ ['REVISION NOTE',edit.revision_note],
129
+ ].filter(([,value])=>nonEmpty(value));
130
+ const size=shotTypography(edit,src,sections,width,height);
131
+ const heading=`<div style={{fontSize:${size.title},fontWeight:800,lineHeight:1.14,overflowWrap:'anywhere'}}>SHOT ${index+1} · ${html(edit.shot_id)}</div>`;
132
+ const source=`<div style={{fontSize:${size.source},fontWeight:600,lineHeight:1.3,opacity:.9,overflowWrap:'anywhere'}}>SOURCE: ${html(src)} [${edit.in_seconds.toFixed(2)}–${edit.out_seconds.toFixed(2)}s]</div>`;
133
+ const descriptions=sections.map(([label,value])=>`<div style={{fontSize:${size.body},lineHeight:1.28,overflowWrap:'anywhere',whiteSpace:'pre-wrap'}}><span style={{fontSize:${size.label},fontWeight:700,letterSpacing:1,color:'#a5d8ff'}}>${label}:</span> ${html(value)}</div>`).join('');
134
+ return `<div style={{boxSizing:'border-box',width:'100%',height:'100%',display:'flex',flexDirection:'column',justifyContent:'flex-start',alignItems:'stretch',gap:${size.gap},overflowY:'hidden',padding:'5%',color:'white',fontFamily:'Arial,sans-serif',textShadow:'0 2px 5px rgba(0,0,0,.85)',background:'linear-gradient(180deg,rgba(0,0,0,.94),rgba(0,0,0,.78) 62%,rgba(0,0,0,.34))'}}>${heading}${source}${descriptions}</div>`;
94
135
  }
136
+
95
137
  export function editorDecisionToMarkdown(videoPath,edl,markdown=readFileSync(videoPath,'utf8')){
96
138
  validateEditorDecision(edl);
97
139
  const width=Number(/\bwidth:(\d+)/.exec(markdown)?.[1]||1080),height=Number(/\bheight:(\d+)/.exec(markdown)?.[1]||1920);
98
140
  const fps=Number(/\bfps:(\d+)/.exec(markdown)?.[1]||30);
99
141
  const out=['# video','width:'+width+' height:'+height+' fps:'+fps+' layout:series'];
100
142
  if(nonEmpty(edl.editorial_intent)){
101
- const jsx="<div style={{boxSizing:'border-box',width:'100%',height:'100%',background:'#111827',color:'white',display:'flex',alignItems:'center',justifyContent:'center',padding:'10%',fontSize:46,textAlign:'center'}}>"+html(short(edl.editorial_intent,320))+'</div>';
143
+ const jsx="<div style={{boxSizing:'border-box',width:'100%',height:'100%',background:'#111827',color:'white',display:'flex',alignItems:'center',justifyContent:'center',padding:'10%',fontSize:46,textAlign:'center'}}>"+html(edl.editorial_intent)+'</div>';
102
144
  out.push('','## EditorialIntent','layout:parallel','- component duration:3 jsx:'+JSON.stringify(jsx));
103
145
  }
104
146
  for(const [i,e] of edl.edits.entries()){
@@ -109,7 +151,7 @@ export function editorDecisionToMarkdown(videoPath,edl,markdown=readFileSync(vid
109
151
  if(imageExts.has(ext))out.push('- image src:'+src+' duration:'+duration.toFixed(4)+' fit:cover');
110
152
  else if(videoExts.has(ext))out.push('- video src:'+src+' startFrom:'+e.in_seconds+' endAt:'+e.out_seconds+' duration:'+duration.toFixed(4)+' playbackRate:'+speed+' volume:1 fit:cover');
111
153
  else throw Error('Unsupported EDL media format: '+src);
112
- out.push('- component duration:'+duration.toFixed(4)+' jsx:'+JSON.stringify(overlay(e,i,src)));
154
+ out.push('- component duration:'+duration.toFixed(4)+' jsx:'+JSON.stringify(overlay(e,i,src,width,height)));
113
155
  }
114
156
  return out.join('\n')+'\n';
115
157
  }
@@ -49,6 +49,73 @@ test('converts decisions into playable Markcut Markdown with original source and
49
49
  }finally{f.cleanup();}
50
50
  });
51
51
 
52
+ test('Editor Decisions shot overlay begins at top with larger type and never truncates EDL text',()=>{
53
+ const f=setup();
54
+ try{
55
+ const marker='FULL_REASON_END_987654321';
56
+ const reason='Narrative continuity, source-grounded editorial intention. '.repeat(8)+marker;
57
+ const decision={...EDL,edits:[{
58
+ ...EDL.edits[0],shot_purpose:'Purpose should not replace story beat',
59
+ editor_reason:reason,
60
+ visual_relationship:'wide shot to detailed close-up',
61
+ sound_decision:'preserve natural source audio',audioIntent:'do not duck the recording',
62
+ revision_note:'keep the original observation',story_beat_id:'story-beat-abc',
63
+ transition:'match cut from {shot} to <scene>',cut_reason:'Independent cut reason {not_an_expression}'
64
+ }]};
65
+ const md=editorDecisionToMarkdown(f.video,decision,'# video\nwidth:1080 height:1920 fps:30 layout:series');
66
+ const component=md.split('- component duration:1.0000 jsx:')[1];
67
+ const jsx=JSON.parse(component.trim());
68
+ assert.match(jsx,/justifyContent:'flex-start'/);
69
+ assert.doesNotMatch(jsx,/justifyContent:'flex-end'/);
70
+ const title=Number(jsx.match(/fontSize:([\d.]+)/)[1]);
71
+ const body=Number(jsx.match(/<div style=\{\{fontSize:([\d.]+),lineHeight:1\.28/)[1]);
72
+ assert.ok(title>33&&title<=68,`shot title must remain larger than prior 33px, got ${title}`);
73
+ assert.ok(body>24&&body<=46,`shot body must remain larger than prior 24px, got ${body}`);
74
+ assert.match(jsx,/overflowY:'hidden'/);
75
+ assert.match(jsx,/FULL_REASON_END_987654321/);
76
+ assert.match(jsx,/Independent cut reason/);
77
+ assert.match(jsx,/Purpose should not replace story beat/);
78
+ assert.match(jsx,/story-beat-abc/);
79
+ assert.match(jsx,/wide shot to detailed close-up/);
80
+ assert.match(jsx,/preserve natural source audio/);
81
+ assert.match(jsx,/do not duck the recording/);
82
+ assert.match(jsx,/keep the original observation/);
83
+ assert.match(jsx,/TRANSITION:/);
84
+ assert.match(jsx,/match cut from &#123;shot&#125; to &lt;scene&gt;/);
85
+ assert.match(jsx,/Independent cut reason &#123;not_an_expression&#125;/);
86
+ assert.doesNotMatch(jsx,/\{not_an_expression\}/);
87
+ assert.doesNotMatch(jsx,/…/);
88
+ assert.ok(jsx.indexOf('SHOT 1')<jsx.indexOf('SOURCE:')&&jsx.indexOf('SOURCE:')<jsx.indexOf('EDITOR REASON:'));
89
+ }finally{f.cleanup();}
90
+ });
91
+
92
+ test('shot typography scales down if necessary and rejects impossible single-frame content',()=>{
93
+ const f=setup();
94
+ try{
95
+ const run=reason=>editorDecisionToMarkdown(f.video,{...EDL,edits:[{...EDL.edits[0],editor_reason:reason}]},'# video\nwidth:1080 height:1920 fps:30 layout:series');
96
+ const moderate='Long source-grounded explanation about the observed moments. '.repeat(22);
97
+ const md=run(moderate),jsx=JSON.parse(md.split('- component duration:1.0000 jsx:')[1].trim());
98
+ const size=Number(jsx.match(/fontSize:([\d.]+)/)[1]);
99
+ assert.ok(size<68&&size>=30,`expected fitted title, got ${size}`);
100
+ assert.ok(jsx.includes(moderate));
101
+ assert.match(jsx,/overflowY:'hidden'/);
102
+ assert.throws(()=>run('Very long reason. '.repeat(1500)),/too much decision text to fit on one frame/);
103
+ }finally{f.cleanup();}
104
+ });
105
+
106
+ test('editorial intent text is safely escaped as inert JSX content',()=>{
107
+ const f=setup();
108
+ try{
109
+ const md=editorDecisionToMarkdown(f.video,{...EDL,editorial_intent:'Observe {globalThis.alert(1)} <picture> & keep it real'});
110
+ const first=md.match(/- component duration:3 jsx:([^\n]+)/);
111
+ assert.ok(first);
112
+ const jsx=JSON.parse(first[1]);
113
+ assert.match(jsx,/&#123;globalThis\.alert\(1\)&#125;/);
114
+ assert.match(jsx,/&lt;picture&gt; &amp; keep it real/);
115
+ assert.doesNotMatch(jsx,/\{globalThis\.alert\(1\)\}/);
116
+ }finally{f.cleanup();}
117
+ });
118
+
52
119
  test('refuses malformed timing, duplicate shots and path traversal rather than rendering invented footage',()=>{
53
120
  const f=setup();
54
121
  try{
@@ -231,16 +231,31 @@ export function externalizePreviewMedia(compiled,revisionId,origin=publicOrigin(
231
231
  return {compiled:replace(compiled),assets};
232
232
  }
233
233
 
234
- // Fallback for hosts that deliver tool-input but omit tool-result notifications.
235
- export function publishPreviewRevision(requestedPath,payload) {
236
- const key=createHash("sha256").update(requestedPath).digest("hex");
237
- const dir=join(EXPORT_ROOT,"revisions");
234
+ // The MCP iframe identifies a preview by the requested path. The standalone
235
+ // NeoY viewer identifies the *same* video by its mounted /files/... path.
236
+ // Publish both pointers with identical content, preserving old callers.
237
+ export function publishPreviewRevision(requestedPath,payload,{
238
+ root=EXPORT_ROOT,origin=publicOrigin(),mount=resolveMountedFile,
239
+ }={}) {
240
+ const dir=join(root,"revisions");
238
241
  mkdirSync(dir,{recursive:true});
239
- const target=join(dir,key+".json");
240
- const temp=join(dir,key+"."+process.pid+".tmp");
241
- writeFileSync(temp,JSON.stringify(payload),{mode:0o644});
242
- renameSync(temp,target);
243
- return publicOrigin()+"/files/_neoy/markcut/revisions/"+key+".json";
242
+ function writePointer(identity,data){
243
+ const key=createHash("sha256").update(identity).digest("hex");
244
+ const target=join(dir,key+".json");
245
+ const temp=join(dir,key+"."+process.pid+".tmp");
246
+ writeFileSync(temp,JSON.stringify(data),{mode:0o644});
247
+ renameSync(temp,target);
248
+ return origin+"/files/_neoy/markcut/revisions/"+key+".json";
249
+ }
250
+ const url=writePointer(requestedPath,payload);
251
+ if(typeof payload?.path==="string"){
252
+ const mounted=mount(payload.path,origin);
253
+ if(mounted){
254
+ const canonical=new URL(mounted).pathname;
255
+ if(canonical!==requestedPath)writePointer(canonical,{...payload,requestedPath:canonical});
256
+ }
257
+ }
258
+ return url;
244
259
  }
245
260
 
246
261
 
@@ -4,7 +4,8 @@ import {tmpdir} from 'node:os';
4
4
  import {join} from 'node:path';
5
5
  import {readFileSync} from 'node:fs';
6
6
  import vm from 'node:vm';
7
- import {webcrypto} from 'node:crypto';
7
+ import {webcrypto,createHash} from 'node:crypto';
8
+ import {publishPreviewRevision} from '../src/mcp/remote-assets.mjs';
8
9
  import {designViewerUrl,publishDesignViewer} from '../src/mcp/design-viewer.mjs';
9
10
  import {buildPreviewBridgeScript} from '../src/mcp/bridge.mjs';
10
11
 
@@ -22,6 +23,22 @@ describe('NeoY standalone Markcut design mode',()=>{
22
23
  expect(()=>designViewerUrl(file,origin,()=>origin+'/files/_neoy/markcut/cache/evil.md')).toThrow();
23
24
  expect(()=>designViewerUrl(file,origin,()=>origin+'/files/vlog/../secret.md')).toThrow();
24
25
  });
26
+ it('publishes the same revision by both caller path and canonical mounted video.md identity',async()=>{
27
+ const root=await mkdtemp(join(tmpdir(),'markcut-design-revisions-'));
28
+ const caller='/home/source/video.md',canonical='/files/vlog/video.md';
29
+ const payload={requestedPath:caller,path:caller,contentHash:hash,compiledUrl:'https://neoy.example.test/files/_neoy/markcut/cache/'+hash+'.json'};
30
+ const key=value=>createHash('sha256').update(value).digest('hex');
31
+ try {
32
+ const url=publishPreviewRevision(caller,payload,{root,origin:'https://neoy.example.test',
33
+ mount:()=> 'https://neoy.example.test'+canonical});
34
+ expect(url).toContain('/revisions/'+key(caller)+'.json');
35
+ const local=JSON.parse(await readFile(join(root,'revisions',key(caller)+'.json'),'utf8'));
36
+ const mounted=JSON.parse(await readFile(join(root,'revisions',key(canonical)+'.json'),'utf8'));
37
+ expect(local.requestedPath).toBe(caller);
38
+ expect(mounted.requestedPath).toBe(canonical);
39
+ expect(mounted.compiledUrl).toBe(local.compiledUrl);
40
+ }finally{await rm(root,{recursive:true,force:true});}
41
+ });
25
42
  it('publishes the same player without creating a second viewer',async()=>{
26
43
  const root=await mkdtemp(join(tmpdir(),'markcut-design-ui-'));
27
44
  try{