diff --git a/CHANGELOG.md b/CHANGELOG.md index fc02a31..6590be1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 2025-12-29: v2.7.0 + +- Added event `embedSize` + ## 2025-10-22: v2.6.0 - Added support for new locales: Danish (`da`), Finnish (`fi`), Filipino (`fil`), French Canadian (`fr-CA`), Hindi (`hi`), Indonesian (`id`), Malay (`ms`), Norwegian Bokmål (`nb`), Traditional Chinese Hong Kong (`zh-HK`), and Traditional Chinese Taiwan (`zh-TW`) diff --git a/karma.conf.js b/karma.conf.js index ab6642f..f3b4cb0 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -22,6 +22,7 @@ module.exports = config => { FLAT_EMBED_QUARTET_SCORE: process.env.FLAT_EMBED_QUARTET_SCORE, FLAT_EMBED_PRIVATE_LINK_SCORE: process.env.FLAT_EMBED_PRIVATE_LINK_SCORE, FLAT_EMBED_PRIVATE_LINK_SHARING_KEY: process.env.FLAT_EMBED_PRIVATE_LINK_SHARING_KEY, + FLAT_EMBED_NEW_DISPLAY: process.env.FLAT_EMBED_NEW_DISPLAY, }, }, reporters: ['mocha'], diff --git a/package.json b/package.json index 4950518..3a11f68 100644 --- a/package.json +++ b/package.json @@ -42,10 +42,13 @@ "scripts": { "clean": "rm build/*", "build": "tsc && vite build", - "test": "tsc && pnpm run biome:check && npm run test:karma", + "test": "tsc && pnpm run biome:check && npm run test:karma:all-displays", "biome:check": "biome check .", "biome:fix": "biome check --write .", "test:karma": "karma start --single-run", + "test:karma:old-display": "karma start --single-run", + "test:karma:new-display": "FLAT_EMBED_NEW_DISPLAY=true karma start --single-run", + "test:karma:all-displays": "npm run test:karma:old-display && npm run test:karma:new-display", "test:karma-watch": "karma start --single-run=false --auto-watch", "prepare": "husky", "generate:docs": "npx tsx scripts/update-version-in-docs.ts && npx tsx scripts/generate-api-docs.ts" diff --git a/src/types/embedSize.ts b/src/types/embedSize.ts new file mode 100644 index 0000000..588cc24 --- /dev/null +++ b/src/types/embedSize.ts @@ -0,0 +1,9 @@ +/** + * Embed size information + */ +export interface EmbedSize { + /** Total embed height in pixels */ + height: number; + /** Total embed width in pixels */ + width: number; +} diff --git a/src/types/events.ts b/src/types/events.ts index f2acb35..c928d6b 100644 --- a/src/types/events.ts +++ b/src/types/events.ts @@ -15,6 +15,7 @@ export const EVENTS_NAMES = [ 'stop', 'playbackPosition', 'restrictedFeatureAttempt', + 'embedSize', ] as const; /** diff --git a/src/types/index.ts b/src/types/index.ts index 8051534..91166a0 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -3,6 +3,7 @@ export * from './cursorPosition'; export * from './embedMessage'; export * from './embedParameters'; +export * from './embedSize'; export * from './events'; export * from './measure'; export * from './metronome'; diff --git a/test/integration/embed-integration.js b/test/integration/embed-integration.js index b59d23b..e241c7c 100644 --- a/test/integration/embed-integration.js +++ b/test/integration/embed-integration.js @@ -24,6 +24,9 @@ describe('Integration - Embed', () => { } }); + const USE_NEW_DISPLAY = window.__karma__.config.env.FLAT_EMBED_NEW_DISPLAY === 'true'; + console.log('[embed-integration] USE_NEW_DISPLAY:', USE_NEW_DISPLAY); + function createEmbedForScoreId(score, embedParams = {}) { const container = document.createElement('div'); document.body.appendChild(container); @@ -38,6 +41,7 @@ describe('Integration - Embed', () => { embedParams: { ...embedParams, appId: APP_ID, + ...(USE_NEW_DISPLAY && { newDisplay: true }), }, }); @@ -733,6 +737,74 @@ describe('Integration - Embed', () => { }); }); + describe('Events - embedSize', () => { + // Note: New display (adagio-display) currently reports viewport dimensions via contentRect, + // not actual content dimensions. Height assertions are skipped for new display until + // adagio-display is updated to report actual content height. + it('should receive embedSize event with reasonable dimensions', done => { + const { embed, container } = createEmbedForScoreId(PUBLIC_SCORE); + container.style.width = '800px'; + + // Wait for score to be loaded before subscribing to embedSize + // This ensures the score has fully rendered before we check dimensions + embed.on('scoreLoaded', () => { + // Add a small delay to allow layout to stabilize (especially for new display) + setTimeout(() => { + let eventCount = 0; + embed.on('embedSize', data => { + eventCount++; + console.log(`[embedSize test] event #${eventCount}: height=${data.height}px, width=${data.width}px`); + + assert.ok(typeof data.height === 'number', 'height is number'); + assert.ok(typeof data.width === 'number', 'width is number'); + // Height should be meaningful for a real score (not just iframe chrome) + // Skip height check for new display - it returns viewport height, not content height + if (!USE_NEW_DISPLAY) { + assert.ok(data.height > 500, `height should be > 500px, got ${data.height}px`); + } + assert.ok(data.width > 0, 'width > 0'); + done(); + }); + }, 500); + }); + }); + + // Skip resize test for new display - contentRect doesn't update on container resize + (USE_NEW_DISPLAY ? it.skip : it)('should emit new embedSize event on container resize', done => { + const { embed, container } = createEmbedForScoreId(PUBLIC_SCORE); + container.style.width = '800px'; + + // Wait for score to be loaded before subscribing to embedSize + embed.on('scoreLoaded', () => { + // Add a small delay to allow layout to stabilize (especially for new display) + setTimeout(() => { + let eventCount = 0; + let firstWidth = 0; + + embed.on('embedSize', data => { + eventCount++; + console.log(`[embedSize resize test] event #${eventCount}: height=${data.height}px, width=${data.width}px`); + + if (eventCount === 1) { + // First event after load + firstWidth = data.width; + assert.ok(data.height > 500, `initial height > 500px, got ${data.height}px`); + // Trigger resize after first event + setTimeout(() => { + console.log('[embedSize resize test] triggering resize to 500px'); + container.style.width = '500px'; + }, 200); + } else if (eventCount === 2) { + // Second event after resize + assert.ok(data.width < firstWidth, `width should decrease after resize: ${data.width} < ${firstWidth}`); + done(); + } + }); + }, 500); + }); + }); + }); + describe('Parts display', () => { it('should get all the parts by default', async () => { const { embed } = createEmbedForScoreId(QUARTET_SCORE); diff --git a/test/manual/test-embedSize.html b/test/manual/test-embedSize.html new file mode 100644 index 0000000..0c6201e --- /dev/null +++ b/test/manual/test-embedSize.html @@ -0,0 +1,203 @@ + + + + + + Test embedSize Event + + + +

embedSize Event Test

+ +
+
+ + + +
+
+ + + + +
+
+ + + + +
+
+ + + +
+
+ +
+ Mode: loading... +
+ +
+ Iframe size: waiting for embedSize event... +
+ +
+ +

Event Log:

+
+ + + + +