@motionhub/oms 0.0.0-stage → 0.1.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.
@@ -0,0 +1 @@
1
+ (()=>{function w(e,t){let o=i=>i.trim().replace(/^["']|["']$/g,"").toLowerCase(),s=o(e.split(",")[0]??""),c=new Set;for(let i of t){if(o(i.family)!==s)continue;let[r,l=r]=i.weight.split(/\s+/).map(n=>n==="bold"?700:n==="normal"?400:Number(n));if(!(!Number.isFinite(r)||!Number.isFinite(l))){for(let n=Math.ceil(r/100)*100;n<=l;n+=100)c.add(n);c.add(r)}}return c.size?[...c].sort((i,r)=>i-r).map(String):void 0}var x=["font-size","font-weight","color","background-color","opacity"];function E(){let e=window.__omsFrame??{width:innerWidth,height:innerHeight},t=Math.min(innerWidth/e.width,innerHeight/e.height),o=e.width*t,s=e.height*t;return new DOMRect((innerWidth-o)/2,(innerHeight-s)/2,o,s)}function k(e){for(let o=e;o&&o!==document.documentElement;o=o.parentElement){let s=getComputedStyle(o);if(s.visibility==="hidden"||s.display==="none"||Number(s.opacity)===0)return!1}let t=e.getBoundingClientRect();return t.width>0&&t.height>0}function M(e){let t=e.id?`#${e.id}`:"",o=[...e.classList].slice(0,2).map(s=>`.${s}`).join("");return`${e.tagName.toLowerCase()}${t}${o}`}var T=["font-family","font-size","font-weight","color","background-color","opacity","transform"],L={"background-color":"rgba(0, 0, 0, 0)",opacity:"1",transform:"none"};function F(e,t){let o=[];for(let a=e;a&&a!==document.body&&o.length<5;a=a.parentElement)o.unshift(M(a));let s=Object.fromEntries([...e.attributes].filter(a=>a.name.startsWith("data-")||["src","href","alt","aria-label"].includes(a.name)).slice(0,8).map(a=>[a.name,a.value.slice(0,120)])),c=(e.textContent??"").replace(/\s+/g," ").trim().slice(0,120),i=e.getBoundingClientRect(),r=getComputedStyle(e),l=Object.fromEntries(T.map(a=>[a,r.getPropertyValue(a).trim()]).filter(([a,b])=>b&&b!==L[a])),n=Math.max(0,Math.min(1,(i.left-t.left)/t.width)),h=Math.max(0,Math.min(1,(i.top-t.top)/t.height)),S={x:n,y:h,w:Math.max(0,Math.min(1,(i.right-t.left)/t.width)-n),h:Math.max(0,Math.min(1,(i.bottom-t.top)/t.height)-h)},f=e.closest("[data-scene]")?.getAttribute("data-scene"),p=e.closest("[data-layer]")?.getAttribute("data-layer"),g=e.childElementCount===0&&e.textContent?.trim()?e.textContent.slice(0,500):void 0,y=c?w(r.fontFamily,document.fonts):void 0;return{path:o.join(" > "),text:c,attributes:s,styles:l,...f?{scene:f}:{},...p?{layer:p}:{},...g!==void 0?{ownText:g}:{},...y?{weights:y}:{},box:S}}var v=null,d=null;function C(){d&&(d.rule.remove(),d.element.removeAttribute("data-oms-tweak"),d.words!==null&&d.element.isConnected&&(d.element.textContent=d.words),d=null)}var P=e=>typeof e=="string"&&e.length<=60&&!/[;{}<>\\]/.test(e)?e.trim():null;addEventListener("message",e=>{if(e.source!==parent||e.data?.type!=="oms:tweak")return;C();let t=v;if(!t?.isConnected)return;let{styles:o,text:s}=e.data,c=x.map(l=>[l,P(o?.[l])]).filter(([,l])=>l).map(([l,n])=>`${l}: ${n} !important;`),i=typeof s=="string"&&t.childElementCount===0?s.slice(0,500):null;if(!c.length&&i===null)return;let r=document.createElement("style");r.textContent=`[data-oms-tweak] { ${c.join(" ")} }`,document.head.appendChild(r),t.setAttribute("data-oms-tweak",""),d={element:t,rule:r,words:i===null?null:t.textContent??""},i!==null&&(t.textContent=i)});var u=null;addEventListener("message",e=>{if(e.source!==parent||e.data?.type!=="oms:solo")return;u?.remove(),u=null;let t=e.data.layer;typeof t=="string"&&(u=document.createElement("style"),u.textContent=`[data-layer]:not([data-layer="${CSS.escape(t)}"]) { visibility: hidden !important; }`,document.head.appendChild(u))});addEventListener("message",e=>{if(e.source!==parent||e.data?.type!=="oms:pick")return;let t=E(),o=t.left+e.data.x*t.width,s=t.top+e.data.y*t.height,c=document.elementsFromPoint(o,s).find(n=>n!==document.body&&n!==document.documentElement&&!n.hasAttribute("data-oms-mark")&&k(n)),i=[];for(let n=c??null;n&&n!==document.body&&n.id!=="root";n=n.parentElement)k(n)&&i.push(n);let r=i[Math.max(0,Math.min(i.length-1,Math.floor(e.data.depth??0)))];C(),v=r??null;let l;if(r){let{box:n,...h}=F(r,t);l={type:"oms:picked",element:h,box:n,levels:i.length}}else l={type:"oms:picked",element:null,box:null,levels:0};parent.postMessage(l,"*")});var m=null;window.__omsMark=e=>{if(m?.remove(),m=null,!e)return;let t=E();m=document.createElement("div"),m.setAttribute("data-oms-mark",""),Object.assign(m.style,{position:"fixed",left:`${t.left+e.x*t.width}px`,top:`${t.top+e.y*t.height}px`,width:`${e.w*t.width}px`,height:`${e.h*t.height}px`,border:`${Math.max(4,Math.round(t.width/320))}px solid #ff1744`,boxSizing:"border-box",zIndex:"2147483647",pointerEvents:"none"}),document.documentElement.appendChild(m)};})();
@@ -0,0 +1,35 @@
1
+ import {Film, Layer, Line, Scene, interpolate, useTime} from '@motionhub/runtime';
2
+
3
+ /** The film's size and rate; its scenes decide its length. */
4
+ export const film = {width: 1920, height: 1080, fps: 30};
5
+
6
+ function Title({children}: {children: string}) {
7
+ const t = useTime();
8
+ const opacity = interpolate(t, [0.3, 1.2], [0, 1], {clamp: true});
9
+ return (
10
+ <h1 style={{margin: 0, height: '100%', display: 'grid', placeItems: 'center', fontFamily: 'system-ui, sans-serif', fontSize: 120, color: '#fafafa', opacity}}>
11
+ {children}
12
+ </h1>
13
+ );
14
+ }
15
+
16
+ export default function Main() {
17
+ return (
18
+ <Film>
19
+ <Layer id="ground">
20
+ <div style={{width: '100%', height: '100%', background: '#111'}} />
21
+ </Layer>
22
+ <Scene id="opening" duration={3}>
23
+ <Line id="opening-line">A new film.</Line>
24
+ <Layer id="title" y={340} h={400}>
25
+ <Title>A new film</Title>
26
+ </Layer>
27
+ </Scene>
28
+ <Scene id="next" duration={3}>
29
+ <Layer id="title" y={340} h={400}>
30
+ <Title>Ask the agent for the rest</Title>
31
+ </Layer>
32
+ </Scene>
33
+ </Film>
34
+ );
35
+ }