@office-kit/pptx-dev 0.9.1 → 0.11.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.
package/dist/index.d.mts CHANGED
@@ -1,12 +1,47 @@
1
- import { validatePresentation } from "@office-kit/pptx";
1
+ import { JsxSource } from "@office-kit/pptx-dsl";
2
+ import { MediaPlayback, ShapeBounds, ShapeMedia, getSlideAnimations, getSlideShowProperties, getSlideTransition, getSlides, validatePresentation } from "@office-kit/pptx";
2
3
 
4
+ //#region src/media-manifest.d.ts
5
+ /** Media information exposed to the dev preview for a single slide shape. */
6
+ interface PreviewMedia {
7
+ readonly slideIndex: number;
8
+ readonly shapeId: number;
9
+ readonly kind: ShapeMedia['kind'];
10
+ /** A data URL for embedded media, or the external URL for online media. */
11
+ readonly src: string;
12
+ /** Present for embedded media and suitable for an HTML media element. */
13
+ readonly contentType?: string;
14
+ /** Original shape geometry in EMUs. */
15
+ readonly bounds: ShapeBounds;
16
+ readonly playback: MediaPlayback | null;
17
+ }
18
+ //#endregion
3
19
  //#region src/build.d.ts
4
20
  interface BuildResult {
5
21
  bytes: Uint8Array;
6
22
  slides: string[];
7
23
  slideTexts: string[];
24
+ notes: (string | null)[];
25
+ hiddenSlides: boolean[];
26
+ transitions: ReturnType<typeof getSlideTransition>[];
27
+ /** What each slide animates, in click order — the preview's player reads this. */
28
+ animations: ReturnType<typeof getSlideAnimations>[];
29
+ showProperties: ReturnType<typeof getSlideShowProperties>;
30
+ customShows: {
31
+ id: number;
32
+ name: string;
33
+ slideIndices: number[];
34
+ }[];
35
+ /** Media clips keyed by slide and shape id for HTML playback in preview mode. */
36
+ media: PreviewMedia[];
8
37
  aspectRatio: number;
9
38
  dependencies: string[];
39
+ /**
40
+ * Slide index → shape id → the JSX elements being evaluated when the shape
41
+ * was made, outermost first. Only decks built from TSX have it; a saved
42
+ * editor deck has no source to point at.
43
+ */
44
+ shapeSources?: Record<number, Record<number, readonly JsxSource[]>>;
10
45
  diagnostics: ReturnType<typeof validatePresentation>;
11
46
  }
12
47
  //#endregion
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { i as initProject, n as exportDeck, r as inspectTemplate, t as buildDeck } from "./src-YH6kAXbA.mjs";
1
+ import { i as initProject, n as exportDeck, r as inspectTemplate, t as buildDeck } from "./src-CI73YbYS.mjs";
2
2
  export { buildDeck, exportDeck, initProject, inspectTemplate };
@@ -0,0 +1 @@
1
+ var X="http://www.w3.org/2000/svg",K="http://www.w3.org/1999/xhtml";function Y(p){let d=p.onCommand!==void 0,y=[],M=!1,I=p.locale==="ja"?"\u518D\u751F\u3067\u304D\u307E\u305B\u3093\u3067\u3057\u305F \xB7 \u518D\u8A66\u884C":"Unable to play media \xB7 Retry",T=p.locale==="ja"?"\u30E1\u30C7\u30A3\u30A2\u3092\u518D\u751F":"Play media",G=p.locale==="ja"?"\u30E1\u30C7\u30A3\u30A2\u3092\u4E00\u6642\u505C\u6B62":"Pause media";for(let t of p.clips){if(t.kind==="online")continue;let a=p.root.querySelector(`[data-pptx-shape-id="${t.shapeId}"]`)?.querySelector("image");if(!(a instanceof SVGImageElement))continue;let r=document.createElementNS(X,"foreignObject");for(let n of["x","y","width","height","transform","clip-path","filter","opacity"]){let o=a.getAttribute(n);o!==null&&r.setAttribute(n,o)}r.dataset.pptxMedia=String(t.shapeId);let f=t.kind==="audio"&&t.playback?.hideWhenStopped;f&&(r.style.visibility="hidden");let h=document.createElementNS(K,"div");h.style.cssText="position:relative;width:100%;height:100%;";let s=t.kind==="video"&&t.playback?.fullScreen?document.createElement("div"):void 0,l;s&&(s.dataset.pptxMediaFullscreen=String(t.shapeId),s.style.cssText=`position:${d?"absolute":"fixed"};inset:0;background:black;z-index:5;`,s.hidden=!0,p.overlayRoot.append(s));let b=!1,e=document.createElement(t.kind),c=Math.max(0,t.playback?.trim?.startMs??0)/1e3,k=Math.max(0,t.playback?.trim?.endMs??0)/1e3,P=c>0||k>0,H=Math.max(0,t.playback?.fade?.inMs??0)/1e3,V=Math.max(0,t.playback?.fade?.outMs??0)/1e3,$=t.playback?.volume??.5,g=!1,F=!1,R,v;e.src=t.src,e.preload="metadata",e.controls=!d,e.loop=(t.playback?.loop??!1)&&c===0&&k===0,e.volume=$,e.muted=d||(t.playback?.muted??!1),e.setAttribute("aria-label",t.kind==="video"?"Video":"Audio"),e.style.cssText="display:block;width:100%;height:100%;object-fit:fill;",s&&(e.style.objectFit="contain"),e instanceof HTMLVideoElement?(e.playsInline=!0,e.poster=a.href.baseVal):h.style.background=`center / contain no-repeat url("${a.href.baseVal}")`;let u=document.createElement("button");u.type="button",u.hidden=!0,u.style.cssText="position:absolute;inset:0;margin:auto;max-width:100%;height:fit-content;";let O,W,N=()=>{clearTimeout(W),W=void 0},_=()=>{clearTimeout(R),R=void 0},A=()=>{let n=e.duration;return!Number.isFinite(n)||n<=0?Number.POSITIVE_INFINITY:Math.max(c,n-k)},j=n=>Math.min(Math.max(n,c),A()),S=()=>{let n=A(),o=Number.isFinite(e.currentTime)?e.currentTime:c,m=1;H>0&&(m=Math.min(m,Math.max(0,(o-c)/H))),V>0&&Number.isFinite(n)&&(m=Math.min(m,Math.max(0,(n-o)/V))),e.volume=Math.max(0,Math.min(1,$*m))},w=()=>{g=!1;let n=Number.isFinite(e.duration)?j(c):c;Math.abs(e.currentTime-n)>.001&&(e.currentTime=n),S()},U=()=>{if(g||b)return;g=!0,e.pause();let n=A();if(Number.isFinite(n)&&Math.abs(e.currentTime-n)>.001&&(e.currentTime=n),S(),t.playback?.hideWhenStopped&&(r.style.visibility="hidden"),s){let o=s.contains(document.activeElement);s.hidden=!0,l&&(l.hidden=!1),o&&!d&&(t.playback?.hideWhenStopped?p.overlayRoot.focus():l?.focus())}if(t.playback?.loop){w(),r.style.visibility=f?"hidden":"",s&&(s.hidden=!1,l&&(l.hidden=!0)),e.play().catch(o=>{M||b||o instanceof DOMException&&o.name==="AbortError"||(u.textContent=I,u.hidden=!1)});return}t.playback?.rewindAfterPlaying&&(w(),g=!0)},B=()=>{if(F){if(!P){S();return}e.currentTime<c-.001?e.currentTime=c:e.currentTime>=A()-.001&&!e.paused&&(d?e.pause():U()),S()}},q=()=>{_(),!(M||b||e.paused||!P&&H===0&&V===0)&&(R=setTimeout(()=>{B(),q()},50))},D=async()=>{N(),u.hidden=!0,(g||F&&e.currentTime<c-.001)&&w(),B(),r.style.visibility=f?"hidden":"",s&&(s.hidden=!1,l&&(l.hidden=!0),d||e.focus());try{await e.play()}catch(n){if(M||b||n instanceof DOMException&&n.name==="AbortError")return;u.textContent=n instanceof DOMException&&n.name==="NotAllowedError"?T:I,r.style.visibility="",u.hidden=!1}},C=()=>{if(d){p.onCommand?.({shapeId:t.shapeId,action:"play"});return}D()};if(d){let n=document.createElement("button");n.type="button",n.textContent=T,n.setAttribute("aria-label",T);let o=document.createElement("input");o.type="range",o.min="0",o.max="100",o.step="0.1",o.value="0",o.setAttribute("aria-label",p.locale==="ja"?"\u30E1\u30C7\u30A3\u30A2\u4F4D\u7F6E":"Media position");let m=document.createElement("div");m.style.cssText="position:absolute;left:4px;right:4px;bottom:4px;z-index:2;display:flex;align-items:center;gap:4px;padding:3px;background:rgb(0 0 0 / 65%);",o.style.cssText="min-width:0;flex:1;",n.onclick=()=>{let x=v;(x?!x.paused&&!x.ended:!e.paused)?p.onCommand?.({shapeId:t.shapeId,action:"pause"}):C()},o.oninput=()=>{let x=v?.duration||e.duration,z=Number(o.value);Number.isFinite(x)&&x>0&&Number.isFinite(z)&&p.onCommand?.({shapeId:t.shapeId,action:"seek",time:x*z/100})},m.append(n,o),O={toggle:n,position:o},(s??h).append(m)}u.onclick=()=>{d&&(u.hidden=!0),e.error&&e.load(),C()};for(let n of["click","dblclick","pointerdown","keydown"]){let o=m=>{(!(m instanceof KeyboardEvent)||m.key!=="Escape")&&m.stopPropagation()};h.addEventListener(n,o),s?.addEventListener(n,o)}e.addEventListener("error",()=>{M||b||(u.textContent=I,u.hidden=!1)}),e.addEventListener("loadedmetadata",()=>{if(F=!0,!d&&e.currentTime<c-.001&&w(),S(),!d||!v)return;let n=j(Math.max(0,v.currentTime));Math.abs(e.currentTime-n)>.3&&(e.currentTime=n),!v.paused&&!v.ended&&e.play().catch(()=>{M||b||(u.textContent=I,u.hidden=!1)})}),e.addEventListener("timeupdate",B),e.addEventListener("seeking",()=>{if(!F)return;let n=j(e.currentTime);Math.abs(e.currentTime-n)>.001&&(e.currentTime=n),S()});for(let n of["play","ended"])e.addEventListener(n,()=>{if(!(M||b)){if(n==="play"&&N(),n==="play"&&q(),!d&&n==="ended"&&P){U();return}if(!d&&n==="ended"&&t.playback?.rewindAfterPlaying&&!g&&(e.pause(),w()),!d&&n==="ended"&&t.playback?.hideWhenStopped&&(r.style.visibility="hidden"),!d&&n==="play"&&(r.style.visibility=f?"hidden":""),s){let o=n==="ended"&&s.contains(document.activeElement);d||(s.hidden=n==="ended"),l&&n==="ended"&&(l.hidden=!1),o&&!d&&(t.playback?.hideWhenStopped?p.overlayRoot.focus():l?.focus())}}});if(e.addEventListener("pause",_),s?(h.style.background=`center / contain no-repeat url("${a.href.baseVal}")`,l=document.createElement("button"),l.type="button",l.setAttribute("aria-label",T),l.title=T,l.style.cssText="position:absolute;inset:0;width:100%;height:100%;padding:0;border:0;background:transparent;cursor:pointer;",l.onclick=()=>{C()},h.append(l),s.append(e,u)):h.append(e,u),r.append(h),a.replaceWith(r),y.push({clip:t,release:()=>{b=!0,N(),_(),!d&&s?.contains(document.activeElement)&&p.overlayRoot.focus(),e.pause(),e.removeAttribute("src"),e.load(),r.replaceWith(a),s?.remove(),e.remove()},retain:n=>{N(),e.parentNode!==n&&(n.append(e),r.replaceWith(a),D())},element:e,image:a,host:r,shapeId:t.shapeId,play:C,cancelStart:N,isTrimEnded:()=>g,status:u,...l?{start:l}:{},...O?{controls:O}:{},setTarget:n=>{v=n},...s?{overlay:s}:{}}),!d&&t.playback?.autoplay){let n=performance.now()+(t.playback.delayMs??0),o=()=>{if(M||b)return;let m=n-performance.now();m>0?W=setTimeout(o,Math.min(m,2147483647)):D()};o()}}let L=new Map(y.map(t=>[t.shapeId,t]));return{get progress(){return y.map(t=>{let{element:i,host:a,shapeId:r,overlay:f}=t;return{shapeId:r,currentTime:Number.isFinite(i.currentTime)?i.currentTime:0,duration:Number.isFinite(i.duration)?i.duration:0,paused:i.paused,ended:i.ended||t.isTrimEnded(),visible:a.style.visibility!=="hidden",fullScreen:!!(f&&!f.hidden)}})},command(t){let i=L.get(t.shapeId);if(i){if(d){if(t.action==="seek"&&(!Number.isFinite(t.time)||(t.time??0)<0))return;p.onCommand?.(t);return}if(t.action==="play")i.play();else if(t.action==="pause")i.cancelStart(),i.element.pause();else if(t.action==="seek"&&Number.isFinite(t.time)&&(t.time??0)>=0){let a=i.element.duration,r=i.clip.playback?.trim,f=Math.max(0,r?.startMs??0)/1e3,h=Math.max(0,r?.endMs??0)/1e3,E=Number.isFinite(a)?Math.max(f,a-h):a;i.element.currentTime=Number.isFinite(E)?Math.min(Math.max(t.time??0,f),E):Math.max(t.time??0,f)}}},sync(t){if(d)for(let i of t){let a=L.get(i.shapeId);if(!a)continue;let{element:r,host:f,overlay:h}=a;if(a.setTarget(i),a.start&&(a.start.hidden=i.fullScreen),a.controls){let c=!i.paused&&!i.ended;a.controls.toggle.textContent=c?G:T,a.controls.toggle.setAttribute("aria-label",c?G:T);let k=i.duration;a.controls.position.value=k>0?String(Math.max(0,Math.min(100,i.currentTime/k*100))):"0"}let E=a.clip.playback?.trim,s=Math.max(0,E?.startMs??0)/1e3,l=Math.max(0,E?.endMs??0)/1e3,b=Number.isFinite(i.duration)?Math.max(s,i.duration-l):i.duration,e=Number.isFinite(b)?Math.min(Math.max(s,i.currentTime),b):Math.max(s,i.currentTime);Math.abs(r.currentTime-e)>.3&&(r.currentTime=e),i.ended&&r.pause(),f.style.visibility=i.visible?"":"hidden",h&&(h.hidden=!i.fullScreen),i.paused||i.ended?r.pause():r.paused&&a.status.hidden&&r.play().catch(c=>{M||(a.status.textContent=c instanceof DOMException&&c.name==="NotAllowedError"?T:I,a.status.hidden=!1)})}},retainAcrossSlides(t,i){for(let a=y.length-1;a>=0;a--){let r=y[a],f=r.clip.playback?.slideCount??1;!d&&r.clip.kind==="audio"&&t>0&&t<f&&!r.element.paused&&!r.element.ended?r.retain(i):(r.release(),L.delete(r.shapeId),y.splice(a,1))}return y.length>0},dispose(){M=!0;for(let t of y)t.release();y.length=0,L.clear()}}}export{Y as createMediaPlayer};