@@ -31,11 +31,13 @@ function normalizeRuntimeExtensionEntry(entry) {
3131 const panelHeightRaw = Number ( entry . panelHeight ) ;
3232 const panelWidth = Number . isFinite ( panelWidthRaw ) && panelWidthRaw > 0 ? panelWidthRaw : 260 ;
3333 const panelHeight = Number . isFinite ( panelHeightRaw ) && panelHeightRaw > 0 ? panelHeightRaw : 96 ;
34+ const resolvePanelSize = typeof entry . resolvePanelSize === 'function' ? entry . resolvePanelSize : null ;
3435
3536 return Object . freeze ( {
3637 overlayId,
3738 onStep,
3839 onRender,
40+ resolvePanelSize,
3941 compose,
4042 layerOrder,
4143 visualPriority,
@@ -255,7 +257,37 @@ function applyCompositionReadabilityLimits(frames, renderer) {
255257 return frames . filter ( ( frame ) => selectedSet . has ( frame ) ) ;
256258}
257259
258- function attachCompositionSlots ( frames , renderer , safeZones = [ ] ) {
260+ function normalizePanelDimension ( value , fallback , minimum ) {
261+ const numeric = Number ( value ) ;
262+ if ( ! Number . isFinite ( numeric ) || numeric <= 0 ) {
263+ return Math . max ( minimum , fallback ) ;
264+ }
265+ return Math . max ( minimum , numeric ) ;
266+ }
267+
268+ function resolveDynamicPanelSize ( extension , layoutContext , fallbackWidth , fallbackHeight ) {
269+ if ( ! extension || typeof extension . resolvePanelSize !== 'function' ) {
270+ return {
271+ width : fallbackWidth ,
272+ height : fallbackHeight ,
273+ } ;
274+ }
275+
276+ try {
277+ const computed = extension . resolvePanelSize ( layoutContext || { } ) ;
278+ return {
279+ width : normalizePanelDimension ( computed ?. width , fallbackWidth , 120 ) ,
280+ height : normalizePanelDimension ( computed ?. height , fallbackHeight , 32 ) ,
281+ } ;
282+ } catch {
283+ return {
284+ width : fallbackWidth ,
285+ height : fallbackHeight ,
286+ } ;
287+ }
288+ }
289+
290+ function attachCompositionSlots ( frames , renderer , safeZones = [ ] , layoutContext = { } ) {
259291 if ( ! Array . isArray ( frames ) || frames . length === 0 ) {
260292 return frames || [ ] ;
261293 }
@@ -330,8 +362,20 @@ function attachCompositionSlots(frames, renderer, safeZones = []) {
330362
331363 for ( let i = 0 ; i < frames . length ; i += 1 ) {
332364 const frame = frames [ i ] ;
333- const slotWidth = Math . max ( 120 , Number ( frame . extension . panelWidth ) || 260 ) ;
334- const slotHeight = Math . max ( 32 , Number ( frame . extension . panelHeight ) || 96 ) ;
365+ const fallbackWidth = Math . max ( 120 , Number ( frame . extension . panelWidth ) || 260 ) ;
366+ const fallbackHeight = Math . max ( 32 , Number ( frame . extension . panelHeight ) || 96 ) ;
367+ const dynamicPanelSize = resolveDynamicPanelSize ( frame . extension , {
368+ ...layoutContext ,
369+ renderer,
370+ canvasSize : { width, height } ,
371+ frameIndex : i ,
372+ frameCount : frames . length ,
373+ safeZones,
374+ } , fallbackWidth , fallbackHeight ) ;
375+ const maxPanelWidth = Math . max ( 120 , width - margin * 2 ) ;
376+ const maxPanelHeight = Math . max ( 32 , height - margin * 2 ) ;
377+ const slotWidth = Math . min ( maxPanelWidth , Math . max ( 120 , Number ( dynamicPanelSize . width ) || fallbackWidth ) ) ;
378+ const slotHeight = Math . min ( maxPanelHeight , Math . max ( 32 , Number ( dynamicPanelSize . height ) || fallbackHeight ) ) ;
335379 const anchorOrder = [ 'bottom-right' , 'top-right' , 'bottom-left' , 'top-left' ] ;
336380
337381 let slot = null ;
@@ -457,7 +501,8 @@ export function getOverlayGameplayRuntimeCompositionSnapshot(runtime, context =
457501 const frames = deriveRenderHierarchy ( attachCompositionSlots (
458502 getComposedRuntimeFrames ( runtime , activeOverlayId ) ,
459503 context ?. renderer ,
460- safeZones
504+ safeZones ,
505+ context
461506 ) ) ;
462507 const visibleFrames = applyCompositionReadabilityLimits ( frames , context ?. renderer ) ;
463508 const visibleSet = new Set ( visibleFrames ) ;
@@ -618,7 +663,8 @@ export function renderOverlayGameplayRuntime(runtime, context = {}) {
618663 attachCompositionSlots (
619664 getComposedRuntimeFrames ( runtime , activeOverlayId ) ,
620665 context . renderer ,
621- safeZones
666+ safeZones ,
667+ context
622668 )
623669 ) ,
624670 context . renderer
0 commit comments