// scene-places.mjs — where a slide's scene blocks are, as the frame // layer needs them (scene-layer.mjs): which state each is at, what // counts as the same place on the next slide, whether anything is drawn // over it, and whether it can run at all. // // A block runs only once it and every box holding it have arrived (no // data-waiting from it up), and only outside a phone view. A block that // something above it on the slide covers (a canvas box with a higher z, // or the same z later in the slide, over its box; image-full's heading // over its media) runs inside its own block, where the slide's stacking // holds, and so never carries on to another slide. /** * The scene blocks under container that can run: [{el, block, scene, * state, key, inside, slot}]. slot is the block's scene and the number * of that scene's blocks before it on the slide, " ", counted * over every one of them, arrived or not: two blocks of one scene are * two placements, each with a frame of its own, the next slide's are * paired with these by slot (scene-layer.mjs), and a block arriving * never renumbers one already running. */ export function scenePositions (container) { const out = [] if (!container) return out const seen = new Map() for (const el of container.querySelectorAll('[slides-block][data-block="scene"][data-scene]')) { const scene = el.getAttribute('data-scene') const n = seen.get(scene) || 0 seen.set(scene, n + 1) if (waiting(el)) continue const states = el.children ? [...el.children].filter(c => c.hasAttribute('data-scene-state')) : [] const shown = states.filter(c => !c.hasAttribute('data-waiting')) const at = shown[shown.length - 1] const state = at ? at.getAttribute('data-scene-state') : '' if (!state) continue const block = el.getAttribute('data-id') const inside = covered(el) out.push({ el, block, scene, state, key: inside ? 'inside:' + block : placeKey(el), inside, slot: `${scene} ${n}` }) } return out } /** Whether a block, or a box holding it, is still to arrive. */ function waiting (el) { for (let n = el; n && n.getAttribute; n = n.parentNode) { if (n.hasAttribute('data-waiting')) return true if (n.hasAttribute('slides-slide')) return false } return false } /** What "the same box" means: the box on a canvas, the region in a flow. */ export function placeKey (el) { const section = el.closest && el.closest('[slides-slide]') if (section && section.getAttribute('data-layout') === 'canvas') { const s = el.style || {} return 'box:' + [s.left, s.top, s.width, s.height].join(',') } const region = el.closest && el.closest('[slides-region]') return 'region:' + ((region && region.getAttribute('data-region')) || 'body') } /** Whether a block shows its stills only: a phone view, rendered for one or laid out as one. */ export function stillsOnly (el) { const section = el.closest && el.closest('[slides-slide]') if (!section) return true if (section.getAttribute('data-vp') === 'phone') return true const w = section.offsetWidth || 0 return w > 0 && w <= 600 } const pct = v => parseFloat(v) || 0 function boxOf (el) { const s = el.style || {} return { x: pct(s.left), y: pct(s.top), w: pct(s.width), h: pct(s.height) } } /** Whether anything on the slide is drawn over the block. */ export function covered (el) { const section = el.closest && el.closest('[slides-slide]') if (!section) return false if (section.getAttribute('data-layout') === 'canvas') { const z = Number(el.getAttribute('data-z')) || 0 const a = boxOf(el) const kids = [...section.children] const at = kids.indexOf(el) return kids.some((o, i) => { if (o === el || !o.hasAttribute('slides-block')) return false const oz = Number(o.getAttribute('data-z')) || 0 if (oz < z || (oz === z && i < at)) return false const b = boxOf(o) return a.x < b.x + b.w && b.x < a.x + a.w && a.y < b.y + b.h && b.y < a.y + a.h }) } if (section.getAttribute('data-template') === 'image-full') { const region = el.closest('[slides-region]') return !!region && region.getAttribute('data-region') === 'media' && !!section.querySelector('[slides-region][data-region="heading"]') } return false }