camox 0.74.1 → 0.75.0

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.
@@ -23,7 +23,9 @@
23
23
  * document's `height` whenever it changes.
24
24
  * - runtime → page: `navigate` with an `href`. The host acts only with transient user activation.
25
25
  * - host → frame: `capture`, from the look document's hosts only: the runtime enters capture mode,
26
- * where real time never advances and the Timeline only moves when seeked. Only in capture mode
26
+ * where real time never advances and the Timeline only moves when seeked. Until the first seek it
27
+ * shows its poster's frame, as under reduced motion, so a capture of the page around it shows the
28
+ * frame that stands for the artifact. Only in capture mode
27
29
  * does it answer `timeline` (→ `timeline` with the same `id` and the declared `timeline`, or
28
30
  * `null` without one) and `seek` with `t` in ms (→ `seeked` with the same `id`, once the frame at
29
31
  * that time painted, and an `error` when `render` threw) and `guardrail` (→ `guardrail` with the
@@ -51,7 +53,7 @@
51
53
  * `plugins/minifyArtifactRuntime.ts`), so it must stay one template literal without
52
54
  * interpolations or backslashes.
53
55
  */
54
- const ARTIFACT_RUNTIME = "(()=>{\"use strict\";let e=window.parent,t=null,n=null,r,i,a=new Set,o=location.hash.slice(1),s=()=>{if(i!==void 0)return r;let e=document.querySelector(`script[data-camox-data]`);try{r=JSON.parse(e?e.textContent:decodeURIComponent(o)),(!r||typeof r!=`object`||Array.isArray(r))&&(r={})}catch{r={}}return i=JSON.stringify(r),r},c=(()=>{let e={setTimeout:window.setTimeout.bind(window),setInterval:window.setInterval.bind(window),clearTimeout:window.clearTimeout.bind(window)},t=new Map;window.setTimeout=function(n,r,...i){if(typeof n!=`function`)return e.setTimeout(n,r,...i);let a=e.setTimeout(function(){return t.delete(a),n.apply(this,arguments)},r,...i);return t.set(a,{kind:`setTimeout`,delay:Number(r)||0}),a},window.setInterval=function(n,r,...i){let a=e.setInterval(n,r,...i);return typeof n==`function`&&t.set(a,{kind:`setInterval`,delay:Number(r)||0}),a};let n=function(n){t.delete(n),e.clearTimeout(n)};return window.clearTimeout=n,window.clearInterval=n,{later:e.setTimeout,get live(){return[...t.values()]}}})(),l=(()=>{let e=new Set,t=[],n=Object.freeze({tokens:Object.freeze({}),colors:Object.freeze({})}),r=document.createElement(`style`);r.textContent=`body { visibility: hidden !important; }`,document.head.append(r);let i=()=>r.remove();c.later(i,300);let a=e=>Number.isFinite(e)?Math.min(255,Math.max(0,Math.round(e))):0;return{get current(){return n},receive(r){let o={},s={},c=r.colors||{};for(let[e,t]of Object.entries(r.tokens||{})){if(!e.startsWith(`--`)||typeof t!=`string`)continue;o[e]=t;let n=Object.hasOwn(c,e)?c[e]:null;n&&typeof n==`object`&&(s[e]=Object.freeze({r:a(n.r),g:a(n.g),b:a(n.b)}))}let l=document.documentElement.style;for(let e of t)Object.hasOwn(o,e)||l.removeProperty(e);for(let[e,t]of Object.entries(o))l.setProperty(e,t);t=Object.keys(o),i(),n=Object.freeze({tokens:Object.freeze(o),colors:Object.freeze(s)});for(let t of[...e])t(n)},subscribe(t){return e.add(t),()=>{e.delete(t)}}}})(),u=new Set,d=null,f=null,p=null,m=()=>{let e=Math.ceil(document.documentElement.getBoundingClientRect().height);e!==p&&(p=e,h(`height`,{height:p}))},h=(n,r)=>{t&&e.postMessage({...r,camox:n,channel:t},`*`)},g=()=>h(`observe-viewport`,{observe:u.size>0}),_=(e,t,n,r)=>{let i=(e,t,n)=>3*(1-n)*(1-n)*n*e+3*(1-n)*n*n*t+n*n*n,a=(e,t,n)=>3*(1-n)*(1-n)*e+6*(1-n)*n*(t-e)+3*n*n*(1-t);return o=>{if(o<=0)return 0;if(o>=1)return 1;let s=o;for(let c=0;c<8;c++){let c=i(e,n,s)-o;if(Math.abs(c)<1e-7)return i(t,r,s);let l=a(e,n,s);if(Math.abs(l)<1e-6)break;s-=c/l}let c=0,l=1;s=o;for(let t=0;t<40;t++){let t=i(e,n,s);if(Math.abs(t-o)<1e-7)break;t<o?c=s:l=s,s=(c+l)/2}return i(t,r,s)}},v=Object.freeze({travel:[.45,0,.1,1],arrive:[.25,.8,.25,1]}),y=Object.freeze({linear:e=>Math.min(1,Math.max(0,e)),travel:_(...v.travel),arrive:_(...v.arrive)}),b=e=>typeof e==`string`&&Object.hasOwn(y,e),x=e=>{if(e===void 0)return y.linear;if(typeof e==`function`)return e;if(b(e))return y[e];throw TypeError(`Unknown easing `+String(e)+`: use travel, arrive, linear or a function`)},S=(()=>{let e=[`transform`,`opacity`],t=e=>e===`linear`?`linear`:`cubic-bezier(`+v[e].join(`, `)+`)`,n=()=>Object.freeze({width:window.innerWidth,height:window.innerHeight}),r=(e,t)=>({index:e.index,text:e.name+` is skipped, so nothing it animates moves: `+t+`.`}),i=(e,t)=>{if(!e||typeof e!=`object`)return`a Track is an object`;let{el:n,at:r,keyframes:i}=e;if(!n||typeof n.animate!=`function`)return`it needs an el, the element it moves`;if(typeof r!=`number`||!(r>=0))return`it needs an at, when it starts in ms`;let a=e.duration;if(typeof a!=`number`||!(a>=0)||!(r+a<=t))return`it needs a duration in ms, and must end by the Timeline's duration (`+t+` ms)`;if(e.ease!==void 0&&!b(e.ease))return`it has an unknown easing `+String(e.ease)+`: use travel, arrive or linear`;if(typeof i!=`function`&&(!i||typeof i!=`object`))return`it needs keyframes, or a function of the artifact's size giving them`},a=(e,t)=>{if(e===void 0)return{tracks:[],skipped:[]};if(!Array.isArray(e))throw TypeError(`A Timeline's tracks must be an array of Tracks`);let n=[],a=[];return e.forEach((e,o)=>{let s=`Track `+o,c=i(e,t);if(c){a.push(r({index:o,name:s},c));return}let{el:l,at:u,keyframes:d}=e,f=e.ease===void 0?`linear`:e.ease;n.push({name:s,index:o,el:l,at:u,end:u+e.duration,ease:f,keyframes:d})}),{tracks:n,skipped:a}},o=(t,n)=>{let r=typeof t.keyframes==`function`?t.keyframes(n):t.keyframes;if(!r||typeof r!=`object`)return{problem:`its keyframes must be an object`};let i={};for(let[t,n]of Object.entries(r)){if(!e.includes(t))return{problem:`Tracks animate transform and opacity only, not `+t+`: draw it from render(t)`};if(!Array.isArray(n)||n.length!==2)return{problem:`its `+t+` needs two values, [from, to]`};i[t]=n}return{frames:i}},s=(e,i,a)=>{let s=new Map,c=[],l=n();for(let t of[...e].sort((e,t)=>e.at-t.at||e.index-t.index)){let{frames:e,problem:n}=o(t,l);if(n)c.push(r(t,n));else for(let[n,[r,i]]of Object.entries(e)){s.has(t.el)||s.set(t.el,new Map);let e=s.get(t.el);e.has(n)||e.set(n,[]),e.get(n).push({track:t,from:r,to:i})}}let u=[],d=[];for(let[e,n]of s)for(let[r,o]of n){let n=(e,n,a)=>({offset:e/i,[r]:n,easing:t(a)}),s=[n(0,o[0].from,`linear`)],c=0,l=null,f=null;for(let{track:t,from:i,to:a}of o){if(f&&t.at<f.end){let n=Math.min(f.end,t.end);d.push({el:e,property:r,tracks:[f.index,t.index],from:t.at,to:n})}(!f||t.end>f.end)&&(f=t);let o=Math.max(t.at,c),u=Math.max(t.end,o);l&&s.push(n(o,l.to,`linear`)),s.push(n(o,i,t.ease),n(u,a,`linear`)),c=u,l={track:t,to:a}}s.push(n(i,l.to,`linear`)),u.push(e.animate(s,{duration:i,iterations:a?1/0:1,fill:`both`}))}return{animations:u,overlaps:d,skipped:c}};return(e,t,n)=>{let{tracks:r,skipped:i}=a(e,t),o=s(r,t,n),c=null,l=0,u=()=>{for(let e of o.animations)c===null?(e.pause(),e.currentTime=Math.min(t,Math.max(0,l))):e.startTime=c};return r.some(e=>typeof e.keyframes==`function`)&&window.addEventListener(`resize`,()=>{for(let e of o.animations)e.cancel();o=s(r,t,n),u()}),{get animations(){return o.animations},get overlaps(){return o.overlaps},get skipped(){return[...i,...o.skipped].sort((e,t)=>e.index-t.index)},play(e){c=e,u()},seek(e){c=null,l=e,u()}}}})(),C=(()=>{let e=null,t=null,n=!1,r=0,i=null,a=0,o=null,s=!1,l=t=>{let{duration:n,loop:r}=e;return r?(t%n+n)%n:Math.min(n,Math.max(0,t))},d=[],f=0,p=t=>{f=t;for(let e of d)e(t);e.render&&e.render(t)},m=e=>{t.seek(e),p(e)},_=()=>{let e=document.timeline?document.timeline.currentTime:null;return typeof e==`number`?e:performance.now()},v=()=>{r&&cancelAnimationFrame(r),r=0},y=t=>{r=0;let n=l(t-i);p(n),e.loop||n<e.duration?r=requestAnimationFrame(y):(a=e.duration,i=null)},b=()=>{v(),i=_()-a,t.play(i),r=requestAnimationFrame(y)},x=()=>{i!==null&&(a=_()-i,i=null,v(),m(l(a)))},C=()=>{if(n||s)return;let{loop:t,duration:r}=e;(o===null?t:o)&&(t||a<r)?i===null&&b():x()},w=e=>{o=e.visibleRatio>0,C()},T=()=>{let{poster:t,marks:n,loop:r,duration:i}=e;return t===null?r?0:i:n[t]},E=e=>{let t=!1,n=()=>{t||(t=!0,e())};requestAnimationFrame(()=>requestAnimationFrame(n)),c.later(n,200)};return{inspect(n){if(!e)return{animations:[],skipped:[],overlaps:[],ends:null};let{animations:r,skipped:i,overlaps:a}=t;if(!e.loop||!n)return{animations:r,skipped:i,overlaps:a,ends:null};let o=f,s=e.duration-1;try{m(0);let e=n();return m(s),{animations:r,skipped:i,overlaps:a,ends:{first:e,last:n(),at:s}}}finally{m(o)}},register(t,n){if(!e)throw Error(`camox.`+t+` needs a Timeline: call camox.timeline first`);d.push(n),n(f)},declare(r){if(e)throw Error(`camox.timeline can be called once per artifact`);if(!r||typeof r!=`object`)throw TypeError(`camox.timeline needs its options: duration, marks, render`);let{duration:i}=r;if(typeof i!=`number`||!Number.isFinite(i)||i<=0)throw TypeError(`camox.timeline needs a duration: a positive number of milliseconds`);let a={};for(let[e,t]of Object.entries(r.marks||{})){if(typeof t!=`number`||!(t>=0&&t<=i))throw RangeError(`The Mark `+e+` must be a time from 0 to the duration`);a[e]=t}let o=r.poster===void 0?null:String(r.poster);if(o!==null&&!Object.hasOwn(a,o))throw RangeError(`The poster `+o+` must name a Mark`);let{render:c}=r;if(c!==void 0&&typeof c!=`function`)throw TypeError(`A Timeline's render must be a function of the time`);let l=r.loop===!0;t=S(r.tracks,i,l),e=Object.freeze({duration:i,loop:l,marks:Object.freeze(a),poster:o,render:c}),s=!n&&typeof matchMedia==`function`&&matchMedia(`(prefers-reduced-motion: reduce)`).matches,m(s?T():0),!(n||s)&&(u.add(w),u.size===1&&g(),C())},capture(){n=!0,e&&(v(),i=null,u.delete(w)&&u.size===0&&g(),m(0))},describe(t){if(!n)return;let{duration:r,loop:i,marks:a,poster:o}=e||{};h(`timeline`,{id:t.id,timeline:e?{duration:r,loop:i,marks:a,poster:o}:null})},seek(t){if(!n)return;let r=Number(t.t),i;if(e&&Number.isFinite(r))try{m(l(r))}catch(e){i=`render(`+r+`) threw: `+String(e&&e.message?e.message:e)}E(()=>h(`seeked`,i===void 0?{id:t.id}:{id:t.id,error:i}))}}})(),w=(()=>{let e=(e,t)=>{if(!(t instanceof Element))throw TypeError(`camox.`+e+` needs an element to write in`);return t},t=(e,t,n,r,i)=>{if(n===void 0&&r!==void 0)return r;if(typeof n!=`number`||!Number.isFinite(n)||n<0||i&&n===0)throw TypeError(`camox.`+e+`'s `+t+` must be a `+(i?`positive `:``)+`number`);return n},n=e=>{let[,t=``]=String(e).split(`.`);return/^[0-9]+$/.test(t)?Math.min(20,t.length):0};return{type(n,r,i={}){let a=e(`type`,n),o=t(`type`,`at`,i.at,0),s=t(`type`,`cps`,i.cps,20,!0),c=typeof Intl.Segmenter==`function`?Array.from(new Intl.Segmenter().segment(String(r)),e=>e.segment):Array.from(String(r)),l=o+c.length*1e3/s,u=document.createElement(`span`),d=document.createTextNode(``),f=document.createElement(`span`);f.setAttribute(`aria-hidden`,`true`),f.setAttribute(`data-camox-caret`,``),f.style.cssText=`border-left: max(1px, 0.07em) solid currentColor; margin-right: calc(-1 * max(1px, 0.07em));`,u.append(d,f),a.replaceChildren(u);let p=!0;C.register(`type`,e=>{let t=e<o?0:Math.min(c.length,Math.floor((e-o)*s/1e3)+1),n=c.slice(0,t).join(``);d.data!==n&&(d.data=n);let r=e<o?o-e:e-l,i=r<0||Math.floor(r/530)%2==0;i!==p&&(p=i,f.style.visibility=i?``:`hidden`)})},count(r,i){let a=e(`count`,r);if(!i||typeof i.to!=`number`||!Number.isFinite(i.to))throw TypeError(`camox.count needs the number to count to`);let{to:o}=i,s=i.from===void 0?0:i.from;if(typeof s!=`number`||!Number.isFinite(s))throw TypeError(`camox.count's from must be a number`);let c=t(`count`,`at`,i.at,0),l=t(`count`,`duration`,i.duration,1e3,!0),u=x(i.ease===void 0?`arrive`:i.ease),d=i.format;if(d===void 0){let e=Math.max(n(s),n(o)),t=new Intl.NumberFormat(void 0,{minimumFractionDigits:e,maximumFractionDigits:e});d=e=>t.format(e)}else if(typeof d!=`function`)throw TypeError(`camox.count's format must be a function of the value`);let f=null;C.register(`count`,e=>{let t=e>=c+l?o:s+(o-s)*u(Math.max(0,e-c)/l),n=String(d(t));n!==f&&(f=n,a.textContent=n)})}}})(),T=(()=>{let e=!1,t=new Set,n=/-?(?:[0-9]+[.]?[0-9]*|[.][0-9]+)(?:e[-+]?[0-9]+)?/g,r=e=>{if(!e||!e.tagName)return`an element`;let t=e.tagName.toLowerCase();if(e.id)return t+`#`+e.id;let n=Array.from(e.classList).slice(0,2);if(n.length)return t+`.`+n.join(`.`);let i=e.parentElement;return!i||i===document.documentElement?t:r(i)+` > `+t+`:nth-child(`+(Array.from(i.children).indexOf(e)+1)+`)`},i=e=>{let t=e.effect,n=t&&t.target,i=(n?r(n):`no element`)+(t&&t.pseudoElement||``);return typeof CSSAnimation==`function`&&e instanceof CSSAnimation?`The CSS animation `+e.animationName+` on `+i+` plays on its own, outside the Timeline, so captures can't seek it: make it a Track, or draw it from render(t).`:typeof CSSTransition==`function`&&e instanceof CSSTransition?`A CSS transition of `+e.transitionProperty+` on `+i+` ran without a visitor's hover or press: motion that plays on its own goes through the Timeline, as a Track or from render(t).`:`A Web Animation on `+i+` was made by the source and plays outside the Timeline: declare it as a Track, or pause it and set its currentTime from render(t).`},a=()=>{if(!e||typeof document.getAnimations!=`function`)return;let n=new Set(C.inspect().animations);for(let e of document.getAnimations())n.has(e)||e.playState===`paused`||e.playState===`idle`||t.add(i(e))},o=()=>{let e=new Map;for(let{kind:t,delay:n}of c.live){let r=t+` `+n;e.has(r)||e.set(r,{kind:t,delay:n,count:0}),e.get(r).count++}return[...e.values()].map(({kind:e,delay:t,count:n})=>({kind:`timer`,text:(e===`setInterval`?`A setInterval every `+t+` ms is still running`:`A setTimeout of `+t+` ms is still pending`)+(n>1?` (`+n+` of them)`:``)+`: time stands still in captures, so what timers move never shows there, and they don't follow the Timeline's loop. Draw it from render(t) instead.`}))},s=e=>{let t=new Map,n=(r,i,a)=>{let o=getComputedStyle(r),s=a&&o.display!==`none`,c=i*Number(o.opacity),l=s&&o.visibility!==`hidden`&&c>.01;if(!r.hasAttribute(`data-camox-caret`)){let n={};for(let e of r.attributes)n[e.name+` attribute`]=e.value;let i=``;for(let e of r.childNodes)e.nodeType===Node.TEXT_NODE&&(i+=e.data);if(i&&(n.text=i),e.has(r)&&(n.transform=new DOMMatrix(o.transform).toString(),n.opacity=o.opacity),r instanceof HTMLCanvasElement)try{n[`canvas drawing`]=r.toDataURL()}catch{}t.set(r,{visible:l,values:n})}for(let e of r.children)n(e,c,s)};return n(document.documentElement,1,!0),t},l=(e,t)=>{if(e===t)return!0;if(typeof e!=`string`||typeof t!=`string`||e.replace(n,`0`)!==t.replace(n,`0`))return!1;let r=t.match(n)||[];return(e.match(n)||[]).every((e,t)=>{let n=Number(e),i=Number(r[t]);return Math.abs(n-i)<=.01*Math.max(1,Math.abs(n),Math.abs(i))})},u=e=>JSON.stringify(e.length>40?e.slice(0,39)+`…`:e),d=()=>{let e=new Set(C.inspect().animations.map(e=>e.effect&&e.effect.target)),t;try{t=C.inspect(()=>s(e)).ends}catch{return null}if(!t)return null;let{first:n,last:i,at:a}=t,o=[];for(let e of new Set([...n.keys(),...i.keys()])){let t=n.get(e),s=i.get(e);if(!t||!s)(t||s).visible&&o.push(r(e)+` is there at only one end`);else if(t.visible||s.visible)for(let n of new Set([...Object.keys(t.values),...Object.keys(s.values)])){let i=t.values[n],c=s.values[n];l(i,c)||o.push(n===`canvas drawing`?r(e)+`'s canvas drawing`:r(e)+`'s `+n+` (`+(i===void 0?`none`:u(i))+` at 0 ms, `+(c===void 0?`none`:u(c))+` at `+a+` ms)`)}}if(!o.length)return null;let c=o.slice(0,4).join(`; `)+(o.length>4?`; and `+(o.length-4)+` more`:``);return{kind:`loop-cut`,text:`Loop cut: the last frame (`+a+` ms) differs from the first (0 ms), so the loop jumps at its restart: `+c+`. Bring them back to how they start before the end, or hide them while they reset.`}};return{get watching(){return e},watch(){e=!0,a()},sample:a,report(){let e=d();a();let n=[...t].map(e=>({kind:`animation`,text:e}));n.push(...o());let{skipped:i,overlaps:s}=C.inspect();for(let{text:e}of i)n.push({kind:`track`,text:e});for(let{el:e,property:t,tracks:i,from:a,to:o}of s)n.push({kind:`overlap`,text:`Tracks `+i[0]+` and `+i[1]+` both animate the `+t+` of `+r(e)+`, from `+a+` to `+o+` ms: the later one waits for the earlier to end, so it jumps. Start it once the earlier one ends.`});return e&&n.push(e),n}}})(),E={studio(e){let t=e.studio;n=t?Object.freeze({editing:!!t.editing,canvas:!!t.canvas}):null},data(e){s();let t=JSON.stringify(e.data??{});if(t!==i){r=JSON.parse(t),i=t;for(let e of[...a])e(r)}},theme:l.receive,measure(){p=null,f||(f=new ResizeObserver(m),f.observe(document.documentElement)),m()},viewport(e){let{progress:t,visibleRatio:n}=e;if(typeof t==`number`&&typeof n==`number`){d=Object.freeze({progress:t,visibleRatio:n}),document.documentElement.style.setProperty(`--camox-progress`,String(t));for(let e of u)e(d)}},capture(e){C.capture(e),T.watch()},timeline:C.describe,seek(e){C.seek(e),T.sample()},guardrail(e){T.watching&&h(`guardrail`,{id:e.id,findings:T.report()})}};window.addEventListener(`message`,e=>{let n=e.data;if(n&&typeof n.camox==`string`){if(n.camox===`connect`){if(typeof n.channel!=`string`||n.channel===t)return;t=n.channel,h(`ready`),u.size>0&&g()}else t&&n.channel===t&&Object.hasOwn(E,n.camox)&&E[n.camox](n)}});let D=Object.freeze({get studio(){return n},get data(){return s()},onData(e){return a.add(e),()=>{a.delete(e)}},get theme(){return l.current},onTheme:l.subscribe,navigate(e){h(`navigate`,{href:String(e)})},onViewport(e){if(typeof e!=`function`)throw TypeError(`camox.onViewport needs a callback`);let t=t=>e(t);return u.add(t),u.size===1?g():d&&queueMicrotask(()=>u.has(t)&&e(d)),()=>{u.delete(t)&&u.size===0&&g()}},timeline:C.declare,interpolate(e,t,n,r){let[i,a]=t,[o,s]=n,c=x(r&&r.ease),l=a===i?e<i?0:1:(e-i)/(a-i);return o+(s-o)*c(Math.min(1,Math.max(0,l)))},random(e){let t=String(e),n=2166136261;for(let e=0;e<t.length;e++)n=Math.imul(n^t.charCodeAt(e),16777619);return n=Math.imul(n^n>>>16,2246822507),n=Math.imul(n^n>>>13,3266489909),((n^n>>>16)>>>0)/4294967296},type:w.type,count:w.count});Object.defineProperty(window,\"camox\",{value:D,enumerable:!0}),e!==window&&e.postMessage({camox:`hello`},`*`)})();";
56
+ const ARTIFACT_RUNTIME = "(()=>{\"use strict\";let e=window.parent,t=null,n=null,r,i,a=new Set,o=location.hash.slice(1),s=()=>{if(i!==void 0)return r;let e=document.querySelector(`script[data-camox-data]`);try{r=JSON.parse(e?e.textContent:decodeURIComponent(o)),(!r||typeof r!=`object`||Array.isArray(r))&&(r={})}catch{r={}}return i=JSON.stringify(r),r},c=(()=>{let e={setTimeout:window.setTimeout.bind(window),setInterval:window.setInterval.bind(window),clearTimeout:window.clearTimeout.bind(window)},t=new Map;window.setTimeout=function(n,r,...i){if(typeof n!=`function`)return e.setTimeout(n,r,...i);let a=e.setTimeout(function(){return t.delete(a),n.apply(this,arguments)},r,...i);return t.set(a,{kind:`setTimeout`,delay:Number(r)||0}),a},window.setInterval=function(n,r,...i){let a=e.setInterval(n,r,...i);return typeof n==`function`&&t.set(a,{kind:`setInterval`,delay:Number(r)||0}),a};let n=function(n){t.delete(n),e.clearTimeout(n)};return window.clearTimeout=n,window.clearInterval=n,{later:e.setTimeout,get live(){return[...t.values()]}}})(),l=(()=>{let e=new Set,t=[],n=Object.freeze({tokens:Object.freeze({}),colors:Object.freeze({})}),r=document.createElement(`style`);r.textContent=`body { visibility: hidden !important; }`,document.head.append(r);let i=()=>r.remove();c.later(i,300);let a=e=>Number.isFinite(e)?Math.min(255,Math.max(0,Math.round(e))):0;return{get current(){return n},receive(r){let o={},s={},c=r.colors||{};for(let[e,t]of Object.entries(r.tokens||{})){if(!e.startsWith(`--`)||typeof t!=`string`)continue;o[e]=t;let n=Object.hasOwn(c,e)?c[e]:null;n&&typeof n==`object`&&(s[e]=Object.freeze({r:a(n.r),g:a(n.g),b:a(n.b)}))}let l=document.documentElement.style;for(let e of t)Object.hasOwn(o,e)||l.removeProperty(e);for(let[e,t]of Object.entries(o))l.setProperty(e,t);t=Object.keys(o),i(),n=Object.freeze({tokens:Object.freeze(o),colors:Object.freeze(s)});for(let t of[...e])t(n)},subscribe(t){return e.add(t),()=>{e.delete(t)}}}})(),u=new Set,d=null,f=null,p=null,m=()=>{let e=Math.ceil(document.documentElement.getBoundingClientRect().height);e!==p&&(p=e,h(`height`,{height:p}))},h=(n,r)=>{t&&e.postMessage({...r,camox:n,channel:t},`*`)},g=()=>h(`observe-viewport`,{observe:u.size>0}),_=(e,t,n,r)=>{let i=(e,t,n)=>3*(1-n)*(1-n)*n*e+3*(1-n)*n*n*t+n*n*n,a=(e,t,n)=>3*(1-n)*(1-n)*e+6*(1-n)*n*(t-e)+3*n*n*(1-t);return o=>{if(o<=0)return 0;if(o>=1)return 1;let s=o;for(let c=0;c<8;c++){let c=i(e,n,s)-o;if(Math.abs(c)<1e-7)return i(t,r,s);let l=a(e,n,s);if(Math.abs(l)<1e-6)break;s-=c/l}let c=0,l=1;s=o;for(let t=0;t<40;t++){let t=i(e,n,s);if(Math.abs(t-o)<1e-7)break;t<o?c=s:l=s,s=(c+l)/2}return i(t,r,s)}},v=Object.freeze({travel:[.45,0,.1,1],arrive:[.25,.8,.25,1]}),y=Object.freeze({linear:e=>Math.min(1,Math.max(0,e)),travel:_(...v.travel),arrive:_(...v.arrive)}),b=e=>typeof e==`string`&&Object.hasOwn(y,e),x=e=>{if(e===void 0)return y.linear;if(typeof e==`function`)return e;if(b(e))return y[e];throw TypeError(`Unknown easing `+String(e)+`: use travel, arrive, linear or a function`)},S=(()=>{let e=[`transform`,`opacity`],t=e=>e===`linear`?`linear`:`cubic-bezier(`+v[e].join(`, `)+`)`,n=()=>Object.freeze({width:window.innerWidth,height:window.innerHeight}),r=(e,t)=>({index:e.index,text:e.name+` is skipped, so nothing it animates moves: `+t+`.`}),i=(e,t)=>{if(!e||typeof e!=`object`)return`a Track is an object`;let{el:n,at:r,keyframes:i}=e;if(!n||typeof n.animate!=`function`)return`it needs an el, the element it moves`;if(typeof r!=`number`||!(r>=0))return`it needs an at, when it starts in ms`;let a=e.duration;if(typeof a!=`number`||!(a>=0)||!(r+a<=t))return`it needs a duration in ms, and must end by the Timeline's duration (`+t+` ms)`;if(e.ease!==void 0&&!b(e.ease))return`it has an unknown easing `+String(e.ease)+`: use travel, arrive or linear`;if(typeof i!=`function`&&(!i||typeof i!=`object`))return`it needs keyframes, or a function of the artifact's size giving them`},a=(e,t)=>{if(e===void 0)return{tracks:[],skipped:[]};if(!Array.isArray(e))throw TypeError(`A Timeline's tracks must be an array of Tracks`);let n=[],a=[];return e.forEach((e,o)=>{let s=`Track `+o,c=i(e,t);if(c){a.push(r({index:o,name:s},c));return}let{el:l,at:u,keyframes:d}=e,f=e.ease===void 0?`linear`:e.ease;n.push({name:s,index:o,el:l,at:u,end:u+e.duration,ease:f,keyframes:d})}),{tracks:n,skipped:a}},o=(t,n)=>{let r=typeof t.keyframes==`function`?t.keyframes(n):t.keyframes;if(!r||typeof r!=`object`)return{problem:`its keyframes must be an object`};let i={};for(let[t,n]of Object.entries(r)){if(!e.includes(t))return{problem:`Tracks animate transform and opacity only, not `+t+`: draw it from render(t)`};if(!Array.isArray(n)||n.length!==2)return{problem:`its `+t+` needs two values, [from, to]`};i[t]=n}return{frames:i}},s=(e,i,a)=>{let s=new Map,c=[],l=n();for(let t of[...e].sort((e,t)=>e.at-t.at||e.index-t.index)){let{frames:e,problem:n}=o(t,l);if(n)c.push(r(t,n));else for(let[n,[r,i]]of Object.entries(e)){s.has(t.el)||s.set(t.el,new Map);let e=s.get(t.el);e.has(n)||e.set(n,[]),e.get(n).push({track:t,from:r,to:i})}}let u=[],d=[];for(let[e,n]of s)for(let[r,o]of n){let n=(e,n,a)=>({offset:e/i,[r]:n,easing:t(a)}),s=[n(0,o[0].from,`linear`)],c=0,l=null,f=null;for(let{track:t,from:i,to:a}of o){if(f&&t.at<f.end){let n=Math.min(f.end,t.end);d.push({el:e,property:r,tracks:[f.index,t.index],from:t.at,to:n})}(!f||t.end>f.end)&&(f=t);let o=Math.max(t.at,c),u=Math.max(t.end,o);l&&s.push(n(o,l.to,`linear`)),s.push(n(o,i,t.ease),n(u,a,`linear`)),c=u,l={track:t,to:a}}s.push(n(i,l.to,`linear`)),u.push(e.animate(s,{duration:i,iterations:a?1/0:1,fill:`both`}))}return{animations:u,overlaps:d,skipped:c}};return(e,t,n)=>{let{tracks:r,skipped:i}=a(e,t),o=s(r,t,n),c=null,l=0,u=()=>{for(let e of o.animations)c===null?(e.pause(),e.currentTime=Math.min(t,Math.max(0,l))):e.startTime=c};return r.some(e=>typeof e.keyframes==`function`)&&window.addEventListener(`resize`,()=>{for(let e of o.animations)e.cancel();o=s(r,t,n),u()}),{get animations(){return o.animations},get overlaps(){return o.overlaps},get skipped(){return[...i,...o.skipped].sort((e,t)=>e.index-t.index)},play(e){c=e,u()},seek(e){c=null,l=e,u()}}}})(),C=(()=>{let e=null,t=null,n=!1,r=0,i=null,a=0,o=null,s=!1,l=t=>{let{duration:n,loop:r}=e;return r?(t%n+n)%n:Math.min(n,Math.max(0,t))},d=[],f=0,p=t=>{f=t;for(let e of d)e(t);e.render&&e.render(t)},m=e=>{t.seek(e),p(e)},_=()=>{let e=document.timeline?document.timeline.currentTime:null;return typeof e==`number`?e:performance.now()},v=()=>{r&&cancelAnimationFrame(r),r=0},y=t=>{r=0;let n=l(t-i);p(n),e.loop||n<e.duration?r=requestAnimationFrame(y):(a=e.duration,i=null)},b=()=>{v(),i=_()-a,t.play(i),r=requestAnimationFrame(y)},x=()=>{i!==null&&(a=_()-i,i=null,v(),m(l(a)))},C=()=>{if(n||s)return;let{loop:t,duration:r}=e;(o===null?t:o)&&(t||a<r)?i===null&&b():x()},w=e=>{o=e.visibleRatio>0,C()},T=()=>{let{poster:t,marks:n,loop:r,duration:i}=e;return t===null?r?0:i:n[t]},E=e=>{let t=!1,n=()=>{t||(t=!0,e())};requestAnimationFrame(()=>requestAnimationFrame(n)),c.later(n,200)};return{inspect(n){if(!e)return{animations:[],skipped:[],overlaps:[],ends:null};let{animations:r,skipped:i,overlaps:a}=t;if(!e.loop||!n)return{animations:r,skipped:i,overlaps:a,ends:null};let o=f,s=e.duration-1;try{m(0);let e=n();return m(s),{animations:r,skipped:i,overlaps:a,ends:{first:e,last:n(),at:s}}}finally{m(o)}},register(t,n){if(!e)throw Error(`camox.`+t+` needs a Timeline: call camox.timeline first`);d.push(n),n(f)},declare(r){if(e)throw Error(`camox.timeline can be called once per artifact`);if(!r||typeof r!=`object`)throw TypeError(`camox.timeline needs its options: duration, marks, render`);let{duration:i}=r;if(typeof i!=`number`||!Number.isFinite(i)||i<=0)throw TypeError(`camox.timeline needs a duration: a positive number of milliseconds`);let a={};for(let[e,t]of Object.entries(r.marks||{})){if(typeof t!=`number`||!(t>=0&&t<=i))throw RangeError(`The Mark `+e+` must be a time from 0 to the duration`);a[e]=t}let o=r.poster===void 0?null:String(r.poster);if(o!==null&&!Object.hasOwn(a,o))throw RangeError(`The poster `+o+` must name a Mark`);let{render:c}=r;if(c!==void 0&&typeof c!=`function`)throw TypeError(`A Timeline's render must be a function of the time`);let l=r.loop===!0;t=S(r.tracks,i,l),e=Object.freeze({duration:i,loop:l,marks:Object.freeze(a),poster:o,render:c}),s=!n&&typeof matchMedia==`function`&&matchMedia(`(prefers-reduced-motion: reduce)`).matches,m(n||s?T():0),!(n||s)&&(u.add(w),u.size===1&&g(),C())},capture(){n=!0,e&&(v(),i=null,u.delete(w)&&u.size===0&&g(),m(T()))},describe(t){if(!n)return;let{duration:r,loop:i,marks:a,poster:o}=e||{};h(`timeline`,{id:t.id,timeline:e?{duration:r,loop:i,marks:a,poster:o}:null})},seek(t){if(!n)return;let r=Number(t.t),i;if(e&&Number.isFinite(r))try{m(l(r))}catch(e){i=`render(`+r+`) threw: `+String(e&&e.message?e.message:e)}E(()=>h(`seeked`,i===void 0?{id:t.id}:{id:t.id,error:i}))}}})(),w=(()=>{let e=(e,t)=>{if(!(t instanceof Element))throw TypeError(`camox.`+e+` needs an element to write in`);return t},t=(e,t,n,r,i)=>{if(n===void 0&&r!==void 0)return r;if(typeof n!=`number`||!Number.isFinite(n)||n<0||i&&n===0)throw TypeError(`camox.`+e+`'s `+t+` must be a `+(i?`positive `:``)+`number`);return n},n=e=>{let[,t=``]=String(e).split(`.`);return/^[0-9]+$/.test(t)?Math.min(20,t.length):0};return{type(n,r,i={}){let a=e(`type`,n),o=t(`type`,`at`,i.at,0),s=t(`type`,`cps`,i.cps,20,!0),c=typeof Intl.Segmenter==`function`?Array.from(new Intl.Segmenter().segment(String(r)),e=>e.segment):Array.from(String(r)),l=o+c.length*1e3/s,u=document.createElement(`span`),d=document.createTextNode(``),f=document.createElement(`span`);f.setAttribute(`aria-hidden`,`true`),f.setAttribute(`data-camox-caret`,``),f.style.cssText=`border-left: max(1px, 0.07em) solid currentColor; margin-right: calc(-1 * max(1px, 0.07em));`,u.append(d,f),a.replaceChildren(u);let p=!0;C.register(`type`,e=>{let t=e<o?0:Math.min(c.length,Math.floor((e-o)*s/1e3)+1),n=c.slice(0,t).join(``);d.data!==n&&(d.data=n);let r=e<o?o-e:e-l,i=r<0||Math.floor(r/530)%2==0;i!==p&&(p=i,f.style.visibility=i?``:`hidden`)})},count(r,i){let a=e(`count`,r);if(!i||typeof i.to!=`number`||!Number.isFinite(i.to))throw TypeError(`camox.count needs the number to count to`);let{to:o}=i,s=i.from===void 0?0:i.from;if(typeof s!=`number`||!Number.isFinite(s))throw TypeError(`camox.count's from must be a number`);let c=t(`count`,`at`,i.at,0),l=t(`count`,`duration`,i.duration,1e3,!0),u=x(i.ease===void 0?`arrive`:i.ease),d=i.format;if(d===void 0){let e=Math.max(n(s),n(o)),t=new Intl.NumberFormat(void 0,{minimumFractionDigits:e,maximumFractionDigits:e});d=e=>t.format(e)}else if(typeof d!=`function`)throw TypeError(`camox.count's format must be a function of the value`);let f=null;C.register(`count`,e=>{let t=e>=c+l?o:s+(o-s)*u(Math.max(0,e-c)/l),n=String(d(t));n!==f&&(f=n,a.textContent=n)})}}})(),T=(()=>{let e=!1,t=new Set,n=/-?(?:[0-9]+[.]?[0-9]*|[.][0-9]+)(?:e[-+]?[0-9]+)?/g,r=e=>{if(!e||!e.tagName)return`an element`;let t=e.tagName.toLowerCase();if(e.id)return t+`#`+e.id;let n=Array.from(e.classList).slice(0,2);if(n.length)return t+`.`+n.join(`.`);let i=e.parentElement;return!i||i===document.documentElement?t:r(i)+` > `+t+`:nth-child(`+(Array.from(i.children).indexOf(e)+1)+`)`},i=e=>{let t=e.effect,n=t&&t.target,i=(n?r(n):`no element`)+(t&&t.pseudoElement||``);return typeof CSSAnimation==`function`&&e instanceof CSSAnimation?`The CSS animation `+e.animationName+` on `+i+` plays on its own, outside the Timeline, so captures can't seek it: make it a Track, or draw it from render(t).`:typeof CSSTransition==`function`&&e instanceof CSSTransition?`A CSS transition of `+e.transitionProperty+` on `+i+` ran without a visitor's hover or press: motion that plays on its own goes through the Timeline, as a Track or from render(t).`:`A Web Animation on `+i+` was made by the source and plays outside the Timeline: declare it as a Track, or pause it and set its currentTime from render(t).`},a=()=>{if(!e||typeof document.getAnimations!=`function`)return;let n=new Set(C.inspect().animations);for(let e of document.getAnimations())n.has(e)||e.playState===`paused`||e.playState===`idle`||t.add(i(e))},o=()=>{let e=new Map;for(let{kind:t,delay:n}of c.live){let r=t+` `+n;e.has(r)||e.set(r,{kind:t,delay:n,count:0}),e.get(r).count++}return[...e.values()].map(({kind:e,delay:t,count:n})=>({kind:`timer`,text:(e===`setInterval`?`A setInterval every `+t+` ms is still running`:`A setTimeout of `+t+` ms is still pending`)+(n>1?` (`+n+` of them)`:``)+`: time stands still in captures, so what timers move never shows there, and they don't follow the Timeline's loop. Draw it from render(t) instead.`}))},s=e=>{let t=new Map,n=(r,i,a)=>{let o=getComputedStyle(r),s=a&&o.display!==`none`,c=i*Number(o.opacity),l=s&&o.visibility!==`hidden`&&c>.01;if(!r.hasAttribute(`data-camox-caret`)){let n={};for(let e of r.attributes)n[e.name+` attribute`]=e.value;let i=``;for(let e of r.childNodes)e.nodeType===Node.TEXT_NODE&&(i+=e.data);if(i&&(n.text=i),e.has(r)&&(n.transform=new DOMMatrix(o.transform).toString(),n.opacity=o.opacity),r instanceof HTMLCanvasElement)try{n[`canvas drawing`]=r.toDataURL()}catch{}t.set(r,{visible:l,values:n})}for(let e of r.children)n(e,c,s)};return n(document.documentElement,1,!0),t},l=(e,t)=>{if(e===t)return!0;if(typeof e!=`string`||typeof t!=`string`||e.replace(n,`0`)!==t.replace(n,`0`))return!1;let r=t.match(n)||[];return(e.match(n)||[]).every((e,t)=>{let n=Number(e),i=Number(r[t]);return Math.abs(n-i)<=.01*Math.max(1,Math.abs(n),Math.abs(i))})},u=e=>JSON.stringify(e.length>40?e.slice(0,39)+`…`:e),d=()=>{let e=new Set(C.inspect().animations.map(e=>e.effect&&e.effect.target)),t;try{t=C.inspect(()=>s(e)).ends}catch{return null}if(!t)return null;let{first:n,last:i,at:a}=t,o=[];for(let e of new Set([...n.keys(),...i.keys()])){let t=n.get(e),s=i.get(e);if(!t||!s)(t||s).visible&&o.push(r(e)+` is there at only one end`);else if(t.visible||s.visible)for(let n of new Set([...Object.keys(t.values),...Object.keys(s.values)])){let i=t.values[n],c=s.values[n];l(i,c)||o.push(n===`canvas drawing`?r(e)+`'s canvas drawing`:r(e)+`'s `+n+` (`+(i===void 0?`none`:u(i))+` at 0 ms, `+(c===void 0?`none`:u(c))+` at `+a+` ms)`)}}if(!o.length)return null;let c=o.slice(0,4).join(`; `)+(o.length>4?`; and `+(o.length-4)+` more`:``);return{kind:`loop-cut`,text:`Loop cut: the last frame (`+a+` ms) differs from the first (0 ms), so the loop jumps at its restart: `+c+`. Bring them back to how they start before the end, or hide them while they reset.`}};return{get watching(){return e},watch(){e=!0,a()},sample:a,report(){let e=d();a();let n=[...t].map(e=>({kind:`animation`,text:e}));n.push(...o());let{skipped:i,overlaps:s}=C.inspect();for(let{text:e}of i)n.push({kind:`track`,text:e});for(let{el:e,property:t,tracks:i,from:a,to:o}of s)n.push({kind:`overlap`,text:`Tracks `+i[0]+` and `+i[1]+` both animate the `+t+` of `+r(e)+`, from `+a+` to `+o+` ms: the later one waits for the earlier to end, so it jumps. Start it once the earlier one ends.`});return e&&n.push(e),n}}})(),E={studio(e){let t=e.studio;n=t?Object.freeze({editing:!!t.editing,canvas:!!t.canvas}):null},data(e){s();let t=JSON.stringify(e.data??{});if(t!==i){r=JSON.parse(t),i=t;for(let e of[...a])e(r)}},theme:l.receive,measure(){p=null,f||(f=new ResizeObserver(m),f.observe(document.documentElement)),m()},viewport(e){let{progress:t,visibleRatio:n}=e;if(typeof t==`number`&&typeof n==`number`){d=Object.freeze({progress:t,visibleRatio:n}),document.documentElement.style.setProperty(`--camox-progress`,String(t));for(let e of u)e(d)}},capture(e){C.capture(e),T.watch()},timeline:C.describe,seek(e){C.seek(e),T.sample()},guardrail(e){T.watching&&h(`guardrail`,{id:e.id,findings:T.report()})}};window.addEventListener(`message`,e=>{let n=e.data;if(n&&typeof n.camox==`string`){if(n.camox===`connect`){if(typeof n.channel!=`string`||n.channel===t)return;t=n.channel,h(`ready`),u.size>0&&g()}else t&&n.channel===t&&Object.hasOwn(E,n.camox)&&E[n.camox](n)}});let D=Object.freeze({get studio(){return n},get data(){return s()},onData(e){return a.add(e),()=>{a.delete(e)}},get theme(){return l.current},onTheme:l.subscribe,navigate(e){h(`navigate`,{href:String(e)})},onViewport(e){if(typeof e!=`function`)throw TypeError(`camox.onViewport needs a callback`);let t=t=>e(t);return u.add(t),u.size===1?g():d&&queueMicrotask(()=>u.has(t)&&e(d)),()=>{u.delete(t)&&u.size===0&&g()}},timeline:C.declare,interpolate(e,t,n,r){let[i,a]=t,[o,s]=n,c=x(r&&r.ease),l=a===i?e<i?0:1:(e-i)/(a-i);return o+(s-o)*c(Math.min(1,Math.max(0,l)))},random(e){let t=String(e),n=2166136261;for(let e=0;e<t.length;e++)n=Math.imul(n^t.charCodeAt(e),16777619);return n=Math.imul(n^n>>>16,2246822507),n=Math.imul(n^n>>>13,3266489909),((n^n>>>16)>>>0)/4294967296},type:w.type,count:w.count});Object.defineProperty(window,\"camox\",{value:D,enumerable:!0}),e!==window&&e.postMessage({camox:`hello`},`*`)})();";
55
57
 
56
58
  //#endregion
57
59
  export { ARTIFACT_RUNTIME };
@@ -103,7 +103,7 @@ function _temp() {}
103
103
  * the studio keeps the Canvas position and selection, and tells the new renderer.
104
104
  */
105
105
  function RendererFramesProvider(t0) {
106
- const $ = c(33);
106
+ const $ = c(34);
107
107
  const { runtimeBasePath, children } = t0;
108
108
  const queryClient = useQueryClient();
109
109
  const studioCache = useStudioCache();
@@ -147,6 +147,7 @@ function RendererFramesProvider(t0) {
147
147
  const documentUrl = t3;
148
148
  const [source, setSource] = React.useState(documentUrl);
149
149
  const loaded = React.useRef(source);
150
+ const [loads, setLoads] = React.useState(0);
150
151
  let t4;
151
152
  if ($[8] !== documentUrl || $[9] !== host) {
152
153
  t4 = (t5) => {
@@ -156,6 +157,7 @@ function RendererFramesProvider(t0) {
156
157
  loaded.current = next;
157
158
  host?.replacing();
158
159
  setSource(next);
160
+ setLoads(_temp2);
159
161
  };
160
162
  $[8] = documentUrl;
161
163
  $[9] = host;
@@ -164,23 +166,29 @@ function RendererFramesProvider(t0) {
164
166
  const reload = t4;
165
167
  let t5;
166
168
  let t6;
167
- if ($[11] !== draftScope || $[12] !== reload) {
169
+ if ($[11] !== documentUrl || $[12] !== draftScope || $[13] !== reload) {
168
170
  t5 = () => draftScope.subscribe((t7) => {
169
171
  const { move } = t7;
170
- if (move !== "started") reload();
172
+ if (move === "started") loaded.current = documentUrl();
173
+ else reload();
171
174
  });
172
- t6 = [draftScope, reload];
173
- $[11] = draftScope;
174
- $[12] = reload;
175
- $[13] = t5;
176
- $[14] = t6;
175
+ t6 = [
176
+ draftScope,
177
+ documentUrl,
178
+ reload
179
+ ];
180
+ $[11] = documentUrl;
181
+ $[12] = draftScope;
182
+ $[13] = reload;
183
+ $[14] = t5;
184
+ $[15] = t6;
177
185
  } else {
178
- t5 = $[13];
179
- t6 = $[14];
186
+ t5 = $[14];
187
+ t6 = $[15];
180
188
  }
181
189
  React.useEffect(t5, t6);
182
190
  let t7;
183
- if ($[15] !== host) {
191
+ if ($[16] !== host) {
184
192
  t7 = (next_0) => {
185
193
  if (!host) return Promise.resolve();
186
194
  return host.ask({
@@ -190,47 +198,45 @@ function RendererFramesProvider(t0) {
190
198
  locale: next_0.locale
191
199
  });
192
200
  };
193
- $[15] = host;
194
- $[16] = t7;
195
- } else t7 = $[16];
201
+ $[16] = host;
202
+ $[17] = t7;
203
+ } else t7 = $[17];
196
204
  useViewPreparer(t7);
197
- const [loads, setLoads] = React.useState(0);
198
205
  const revisions = React.use(RevisionsContext);
199
206
  let t8;
200
207
  let t9;
201
- if ($[17] !== draftScope || $[18] !== reload || $[19] !== revisions) {
208
+ if ($[18] !== draftScope || $[19] !== reload || $[20] !== revisions) {
202
209
  t8 = () => revisions?.subscribe((t10) => {
203
210
  const { draftId } = t10;
204
211
  if (draftId !== draftScope.current()) return;
205
212
  reload(true);
206
- setLoads(_temp2);
207
213
  });
208
214
  t9 = [
209
215
  revisions,
210
216
  draftScope,
211
217
  reload
212
218
  ];
213
- $[17] = draftScope;
214
- $[18] = reload;
215
- $[19] = revisions;
216
- $[20] = t8;
217
- $[21] = t9;
219
+ $[18] = draftScope;
220
+ $[19] = reload;
221
+ $[20] = revisions;
222
+ $[21] = t8;
223
+ $[22] = t9;
218
224
  } else {
219
- t8 = $[20];
220
- t9 = $[21];
225
+ t8 = $[21];
226
+ t9 = $[22];
221
227
  }
222
228
  React.useEffect(t8, t9);
223
229
  let t10;
224
- if ($[22] !== host) {
230
+ if ($[23] !== host) {
225
231
  t10 = (frame) => {
226
232
  if (frame && host) frame[STUDIO_HANDLE_KEY] = host.handle;
227
233
  };
228
- $[22] = host;
229
- $[23] = t10;
230
- } else t10 = $[23];
234
+ $[23] = host;
235
+ $[24] = t10;
236
+ } else t10 = $[24];
231
237
  const connect = t10;
232
238
  let t11;
233
- if ($[24] !== connect || $[25] !== host || $[26] !== loads || $[27] !== source) {
239
+ if ($[25] !== connect || $[26] !== host || $[27] !== loads || $[28] !== source) {
234
240
  t11 = host && /* @__PURE__ */ jsx("iframe", {
235
241
  ref: connect,
236
242
  src: source,
@@ -238,23 +244,23 @@ function RendererFramesProvider(t0) {
238
244
  title: "Website renderer",
239
245
  "data-camox-renderer": true
240
246
  }, `${source}#${loads}`);
241
- $[24] = connect;
242
- $[25] = host;
243
- $[26] = loads;
244
- $[27] = source;
245
- $[28] = t11;
246
- } else t11 = $[28];
247
+ $[25] = connect;
248
+ $[26] = host;
249
+ $[27] = loads;
250
+ $[28] = source;
251
+ $[29] = t11;
252
+ } else t11 = $[29];
247
253
  let t12;
248
- if ($[29] !== children || $[30] !== host || $[31] !== t11) {
254
+ if ($[30] !== children || $[31] !== host || $[32] !== t11) {
249
255
  t12 = /* @__PURE__ */ jsxs(RendererHostContext, {
250
256
  value: host,
251
257
  children: [children, t11]
252
258
  });
253
- $[29] = children;
254
- $[30] = host;
255
- $[31] = t11;
256
- $[32] = t12;
257
- } else t12 = $[32];
259
+ $[30] = children;
260
+ $[31] = host;
261
+ $[32] = t11;
262
+ $[33] = t12;
263
+ } else t12 = $[33];
258
264
  return t12;
259
265
  }
260
266
  function _temp2(count) {
@@ -4,6 +4,9 @@ import { ThreadMarkdown } from "./ThreadMarkdown.js";
4
4
  import { c } from "react/compiler-runtime";
5
5
  import * as React from "react";
6
6
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
7
+ import { Button } from "@camox/ui/button";
8
+ import { X } from "lucide-react";
9
+ import { Dialog, DialogContent, DialogTitle } from "@camox/ui/dialog";
7
10
  import { Avatar, AvatarFallback, AvatarImage } from "@camox/ui/avatar";
8
11
  import { Bubble, BubbleContent } from "@camox/ui/bubble";
9
12
  import { Message, MessageAvatar, MessageContent, MessageHeader } from "@camox/ui/message";
@@ -298,7 +301,7 @@ const PUSH_OUTCOMES = {
298
301
  notPreviewed: "Built, but the preview can’t show it."
299
302
  };
300
303
  function ThreadMessageRow(t0) {
301
- const $ = c(50);
304
+ const $ = c(56);
302
305
  const { message, onOpenDraft } = t0;
303
306
  if (message.from === "draft") {
304
307
  let t1;
@@ -412,112 +415,131 @@ function ThreadMessageRow(t0) {
412
415
  const t1 = `${sender} added context`;
413
416
  const t2 = client.verified ? void 0 : client.name;
414
417
  let t3;
415
- if ($[26] !== message.text || $[27] !== t1 || $[28] !== t2) {
416
- t3 = /* @__PURE__ */ jsx(Message, { children: /* @__PURE__ */ jsx(MessageContent, { children: /* @__PURE__ */ jsx(CollapsedNote, {
418
+ if ($[26] !== message.attachments) {
419
+ t3 = message.attachments && /* @__PURE__ */ jsx(AttachmentThumbnails, { attachments: message.attachments });
420
+ $[26] = message.attachments;
421
+ $[27] = t3;
422
+ } else t3 = $[27];
423
+ let t4;
424
+ if ($[28] !== message.text || $[29] !== t1 || $[30] !== t2 || $[31] !== t3) {
425
+ t4 = /* @__PURE__ */ jsx(Message, { children: /* @__PURE__ */ jsx(MessageContent, { children: /* @__PURE__ */ jsx(CollapsedNote, {
417
426
  label: t1,
418
427
  hideLabel: "Hide the context",
419
428
  title: t2,
420
- text: message.text
429
+ text: message.text,
430
+ children: t3
421
431
  }) }) });
422
- $[26] = message.text;
423
- $[27] = t1;
424
- $[28] = t2;
425
- $[29] = t3;
426
- } else t3 = $[29];
427
- return t3;
432
+ $[28] = message.text;
433
+ $[29] = t1;
434
+ $[30] = t2;
435
+ $[31] = t3;
436
+ $[32] = t4;
437
+ } else t4 = $[32];
438
+ return t4;
428
439
  }
429
440
  const t1 = client.verified ? void 0 : client.name;
430
441
  let t2;
431
- if ($[30] !== sender || $[31] !== t1) {
442
+ if ($[33] !== sender || $[34] !== t1) {
432
443
  t2 = /* @__PURE__ */ jsx(MessageHeader, {
433
444
  className: "text-muted-foreground text-xs",
434
445
  title: t1,
435
446
  children: sender
436
447
  });
437
- $[30] = sender;
438
- $[31] = t1;
439
- $[32] = t2;
440
- } else t2 = $[32];
448
+ $[33] = sender;
449
+ $[34] = t1;
450
+ $[35] = t2;
451
+ } else t2 = $[35];
441
452
  let t3;
442
- if ($[33] !== message.text) {
453
+ if ($[36] !== message.text) {
443
454
  t3 = /* @__PURE__ */ jsx(Bubble, {
444
455
  variant: "muted",
445
456
  className: "max-w-full",
446
457
  children: /* @__PURE__ */ jsx(BubbleContent, { children: /* @__PURE__ */ jsx(CroppedText, { text: message.text }) })
447
458
  });
448
- $[33] = message.text;
449
- $[34] = t3;
450
- } else t3 = $[34];
459
+ $[36] = message.text;
460
+ $[37] = t3;
461
+ } else t3 = $[37];
451
462
  let t4;
452
- if ($[35] !== t2 || $[36] !== t3) {
453
- t4 = /* @__PURE__ */ jsx(Message, { children: /* @__PURE__ */ jsxs(MessageContent, { children: [t2, t3] }) });
454
- $[35] = t2;
455
- $[36] = t3;
456
- $[37] = t4;
457
- } else t4 = $[37];
458
- return t4;
463
+ if ($[38] !== message.attachments) {
464
+ t4 = message.attachments && /* @__PURE__ */ jsx(AttachmentThumbnails, { attachments: message.attachments });
465
+ $[38] = message.attachments;
466
+ $[39] = t4;
467
+ } else t4 = $[39];
468
+ let t5;
469
+ if ($[40] !== t2 || $[41] !== t3 || $[42] !== t4) {
470
+ t5 = /* @__PURE__ */ jsx(Message, { children: /* @__PURE__ */ jsxs(MessageContent, { children: [
471
+ t2,
472
+ t3,
473
+ t4
474
+ ] }) });
475
+ $[40] = t2;
476
+ $[41] = t3;
477
+ $[42] = t4;
478
+ $[43] = t5;
479
+ } else t5 = $[43];
480
+ return t5;
459
481
  }
460
482
  if (message.from === "brief") {
461
483
  let t1;
462
- if ($[38] !== message.text) {
484
+ if ($[44] !== message.text) {
463
485
  t1 = /* @__PURE__ */ jsx(Message, { children: /* @__PURE__ */ jsx(MessageContent, { children: /* @__PURE__ */ jsx(CollapsedNote, {
464
486
  label: "Camox briefed the agent",
465
487
  hideLabel: "Hide the brief",
466
488
  text: message.text
467
489
  }) }) });
468
- $[38] = message.text;
469
- $[39] = t1;
470
- } else t1 = $[39];
490
+ $[44] = message.text;
491
+ $[45] = t1;
492
+ } else t1 = $[45];
471
493
  return t1;
472
494
  }
473
495
  if (message.from === "camox") {
474
496
  let t1;
475
- if ($[40] === Symbol.for("react.memo_cache_sentinel")) {
497
+ if ($[46] === Symbol.for("react.memo_cache_sentinel")) {
476
498
  t1 = /* @__PURE__ */ jsx(MessageHeader, {
477
499
  className: "text-muted-foreground text-xs",
478
500
  children: "Camox"
479
501
  });
480
- $[40] = t1;
481
- } else t1 = $[40];
502
+ $[46] = t1;
503
+ } else t1 = $[46];
482
504
  let t2;
483
- if ($[41] !== message.text) {
505
+ if ($[47] !== message.text) {
484
506
  t2 = /* @__PURE__ */ jsx(Message, { children: /* @__PURE__ */ jsxs(MessageContent, { children: [t1, /* @__PURE__ */ jsx(Bubble, {
485
507
  variant: "muted",
486
508
  className: "max-w-full",
487
509
  children: /* @__PURE__ */ jsx(BubbleContent, { children: /* @__PURE__ */ jsx(CroppedText, { text: message.text }) })
488
510
  })] }) });
489
- $[41] = message.text;
490
- $[42] = t2;
491
- } else t2 = $[42];
511
+ $[47] = message.text;
512
+ $[48] = t2;
513
+ } else t2 = $[48];
492
514
  return t2;
493
515
  }
494
516
  let t1;
495
- if ($[43] !== message.sender) {
517
+ if ($[49] !== message.sender) {
496
518
  t1 = /* @__PURE__ */ jsx(MessageAvatar, { children: /* @__PURE__ */ jsx(SenderAvatar, { sender: message.sender }) });
497
- $[43] = message.sender;
498
- $[44] = t1;
499
- } else t1 = $[44];
519
+ $[49] = message.sender;
520
+ $[50] = t1;
521
+ } else t1 = $[50];
500
522
  let t2;
501
- if ($[45] !== message.text) {
523
+ if ($[51] !== message.text) {
502
524
  t2 = /* @__PURE__ */ jsx(MessageContent, { children: /* @__PURE__ */ jsx(Bubble, {
503
525
  align: "end",
504
526
  variant: "muted",
505
527
  className: "max-w-full",
506
528
  children: /* @__PURE__ */ jsx(BubbleContent, { children: /* @__PURE__ */ jsx(CroppedText, { text: message.text }) })
507
529
  }) });
508
- $[45] = message.text;
509
- $[46] = t2;
510
- } else t2 = $[46];
530
+ $[51] = message.text;
531
+ $[52] = t2;
532
+ } else t2 = $[52];
511
533
  let t3;
512
- if ($[47] !== t1 || $[48] !== t2) {
534
+ if ($[53] !== t1 || $[54] !== t2) {
513
535
  t3 = /* @__PURE__ */ jsxs(Message, {
514
536
  align: "end",
515
537
  children: [t1, t2]
516
538
  });
517
- $[47] = t1;
518
- $[48] = t2;
519
- $[49] = t3;
520
- } else t3 = $[49];
539
+ $[53] = t1;
540
+ $[54] = t2;
541
+ $[55] = t3;
542
+ } else t3 = $[55];
521
543
  return t3;
522
544
  }
523
545
  function _temp(subject, index) {
@@ -608,13 +630,135 @@ function CroppedText(t0) {
608
630
  return t9;
609
631
  }
610
632
  /**
633
+ * The Attachments a Connected Agent's message carries, the images Camox's agent saw with it
634
+ * (ADR 0044): a thumbnail of each, which opens it at full size.
635
+ */
636
+ function AttachmentThumbnails(t0) {
637
+ const $ = c(20);
638
+ const { attachments } = t0;
639
+ const [opened, setOpened] = React.useState();
640
+ let t1;
641
+ if ($[0] !== attachments) {
642
+ let t2;
643
+ if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
644
+ t2 = (attachment) => /* @__PURE__ */ jsx("button", {
645
+ type: "button",
646
+ title: attachment.filename,
647
+ onClick: () => setOpened(attachment),
648
+ className: "checkered focus-visible:ring-ring size-16 overflow-hidden rounded-md border focus-visible:ring-2 focus-visible:outline-none",
649
+ children: /* @__PURE__ */ jsx("img", {
650
+ src: attachment.url,
651
+ alt: attachment.filename,
652
+ className: "size-full object-cover",
653
+ draggable: false
654
+ })
655
+ }, attachment.id);
656
+ $[2] = t2;
657
+ } else t2 = $[2];
658
+ t1 = attachments.map(t2);
659
+ $[0] = attachments;
660
+ $[1] = t1;
661
+ } else t1 = $[1];
662
+ let t2;
663
+ if ($[3] !== t1) {
664
+ t2 = /* @__PURE__ */ jsx("div", {
665
+ "data-thread-attachments": true,
666
+ className: "flex flex-wrap gap-1.5",
667
+ children: t1
668
+ });
669
+ $[3] = t1;
670
+ $[4] = t2;
671
+ } else t2 = $[4];
672
+ const t3 = !!opened;
673
+ let t4;
674
+ if ($[5] === Symbol.for("react.memo_cache_sentinel")) {
675
+ t4 = (open) => !open && setOpened(void 0);
676
+ $[5] = t4;
677
+ } else t4 = $[5];
678
+ const t5 = opened?.filename;
679
+ let t6;
680
+ if ($[6] !== t5) {
681
+ t6 = /* @__PURE__ */ jsx(DialogTitle, {
682
+ className: "sr-only",
683
+ children: t5
684
+ });
685
+ $[6] = t5;
686
+ $[7] = t6;
687
+ } else t6 = $[7];
688
+ let t7;
689
+ if ($[8] === Symbol.for("react.memo_cache_sentinel")) {
690
+ t7 = /* @__PURE__ */ jsxs(Button, {
691
+ type: "button",
692
+ variant: "ghost",
693
+ size: "icon",
694
+ className: "absolute top-2 right-2 z-10",
695
+ onClick: () => setOpened(void 0),
696
+ children: [/* @__PURE__ */ jsx(X, {}), /* @__PURE__ */ jsx("span", {
697
+ className: "sr-only",
698
+ children: "Close"
699
+ })]
700
+ });
701
+ $[8] = t7;
702
+ } else t7 = $[8];
703
+ let t8;
704
+ if ($[9] !== opened) {
705
+ t8 = opened && /* @__PURE__ */ jsx("div", {
706
+ className: "checkered absolute inset-0 flex items-center justify-center overflow-hidden p-6",
707
+ children: /* @__PURE__ */ jsx("img", {
708
+ src: opened.url,
709
+ alt: opened.filename,
710
+ className: "max-h-full max-w-full object-contain shadow-lg",
711
+ draggable: false
712
+ })
713
+ });
714
+ $[9] = opened;
715
+ $[10] = t8;
716
+ } else t8 = $[10];
717
+ let t9;
718
+ if ($[11] !== t6 || $[12] !== t8) {
719
+ t9 = /* @__PURE__ */ jsxs(DialogContent, {
720
+ className: "h-[90vh] max-h-[90vh] w-[90vw] max-w-[90vw] gap-0 overflow-hidden p-0 sm:max-w-[90vw]",
721
+ showCloseButton: false,
722
+ forceOverlay: true,
723
+ children: [
724
+ t6,
725
+ t7,
726
+ t8
727
+ ]
728
+ });
729
+ $[11] = t6;
730
+ $[12] = t8;
731
+ $[13] = t9;
732
+ } else t9 = $[13];
733
+ let t10;
734
+ if ($[14] !== t3 || $[15] !== t9) {
735
+ t10 = /* @__PURE__ */ jsx(Dialog, {
736
+ open: t3,
737
+ onOpenChange: t4,
738
+ children: t9
739
+ });
740
+ $[14] = t3;
741
+ $[15] = t9;
742
+ $[16] = t10;
743
+ } else t10 = $[16];
744
+ let t11;
745
+ if ($[17] !== t10 || $[18] !== t2) {
746
+ t11 = /* @__PURE__ */ jsxs(Fragment, { children: [t2, t10] });
747
+ $[17] = t10;
748
+ $[18] = t2;
749
+ $[19] = t11;
750
+ } else t11 = $[19];
751
+ return t11;
752
+ }
753
+ /**
611
754
  * Context the agent was given beside the editors' requests, such as the Brief the agent on Live
612
755
  * handed the request off with, or a Connected Agent's answers to its questions: a quiet line,
613
- * `label`, so the requests read on as they were sent, which shows `text` once clicked.
756
+ * `label`, so the requests read on as they were sent, which shows `text`, then `children`, once
757
+ * clicked.
614
758
  */
615
759
  function CollapsedNote(t0) {
616
- const $ = c(11);
617
- const { label, hideLabel, title, text } = t0;
760
+ const $ = c(12);
761
+ const { label, hideLabel, title, text, children } = t0;
618
762
  const [open, setOpen] = React.useState(false);
619
763
  let t1;
620
764
  if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
@@ -651,18 +795,24 @@ function CollapsedNote(t0) {
651
795
  $[6] = text;
652
796
  $[7] = t4;
653
797
  } else t4 = $[7];
654
- let t5;
655
- if ($[8] !== t3 || $[9] !== t4) {
656
- t5 = /* @__PURE__ */ jsxs("div", {
798
+ const t5 = open && children;
799
+ let t6;
800
+ if ($[8] !== t3 || $[9] !== t4 || $[10] !== t5) {
801
+ t6 = /* @__PURE__ */ jsxs("div", {
657
802
  "data-thread-collapsed": true,
658
803
  className: "text-muted-foreground flex flex-col gap-2 text-xs",
659
- children: [t3, t4]
804
+ children: [
805
+ t3,
806
+ t4,
807
+ t5
808
+ ]
660
809
  });
661
810
  $[8] = t3;
662
811
  $[9] = t4;
663
812
  $[10] = t5;
664
- } else t5 = $[10];
665
- return t5;
813
+ $[11] = t6;
814
+ } else t6 = $[11];
815
+ return t6;
666
816
  }
667
817
  function _temp2(current) {
668
818
  return !current;
package/dist/package.js CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "0.74.1";
2
+ var version = "0.75.0";
3
3
 
4
4
  //#endregion
5
5
  export { version };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "camox",
3
- "version": "0.74.1",
3
+ "version": "0.75.0",
4
4
  "license": "MIT",
5
5
  "bin": {
6
6
  "camox": "./bin/camox.mjs"
@@ -148,9 +148,9 @@
148
148
  "unhead": "^3.4.3",
149
149
  "yaml": "^2.9.0",
150
150
  "zod": "^4.6.7",
151
- "@camox/api-contract": "0.74.1",
152
- "@camox/cli": "0.74.1",
153
- "@camox/ui": "0.74.1"
151
+ "@camox/api-contract": "0.75.0",
152
+ "@camox/cli": "0.75.0",
153
+ "@camox/ui": "0.75.0"
154
154
  },
155
155
  "devDependencies": {
156
156
  "@earendil-works/pi-ai": "1.3.0",