@mochabug/adapt-sdk 0.1.21 → 0.1.23
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/cjs/frontend.cjs
CHANGED
|
@@ -1,2 +1,9 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var f=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var U=Object.prototype.hasOwnProperty;var _=(e,t)=>{for(var n in t)f(e,n,{get:t[n],enumerable:!0})},N=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of P(t))!U.call(e,o)&&o!==n&&f(e,o,{get:()=>t[o],enumerable:!(i=I(t,o))||i.enumerable});return e};var j=e=>N(f({},"__esModule",{value:!0}),e);var ee={};_(ee,{getDarkMode:()=>Z,getToken:()=>V,listenDarkMode:()=>q});module.exports=j(ee);var a=null;function V(e=!1){if(e)return"dev-token";if(a!==null)return a;if(typeof window>"u"||typeof location>"u")throw new Error("getToken() is only available in browser environments");let t=location.hash.slice(1);if(!t)throw new Error("No token found in URL hash");let n=new URLSearchParams(t).get("mb_token");if(!n)throw new Error('Token "mb_token" not found in URL hash');return a=decodeURIComponent(n),a}var u=null,y=new Set;function Z(){return u}function q(e){if(y.add(e),u!==null)try{e(u)}catch{}return()=>{y.delete(e)}}function M(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function G(e){return M(e)&&e.type==="adapt-darkMode"&&typeof e.darkMode=="boolean"}function J(e){return M(e)&&e.type==="adapt-autoResizing"&&typeof e.autoResizing=="boolean"}function T(e){return Number.isFinite(e)&&e>=1}function K(e){return M(e)&&typeof e.postMessage=="function"}function c(){return typeof window<"u"&&typeof document<"u"&&typeof window.postMessage=="function"}function z(){if(!c())return!1;try{return window.self!==window.top}catch{return!0}}var l=-1,d=-1,m=-1,b=-1,p=null,Q=16,w=0,X=5;function L(){let{body:e,documentElement:t}=document;if(!e)return null;let n=getComputedStyle(e),i=parseFloat(n.marginTop)||0,o=parseFloat(n.marginBottom)||0,E=parseFloat(n.marginLeft)||0,B=parseFloat(n.marginRight)||0,r=getComputedStyle(t),F=parseFloat(r.paddingTop)||0,S=parseFloat(r.paddingBottom)||0,W=parseFloat(r.paddingLeft)||0,A=parseFloat(r.paddingRight)||0,x=parseFloat(r.borderTopWidth)||0,D=parseFloat(r.borderBottomWidth)||0,C=parseFloat(r.borderLeftWidth)||0,O=parseFloat(r.borderRightWidth)||0,h=Math.max(e.scrollHeight,e.offsetHeight),H=Math.max(e.scrollWidth,e.offsetWidth),k=h+i+o+F+S+x+D,R=H+E+B+W+A+C+O;return!T(R)||!T(k)||w>=X&&b>0&&Math.abs(h-d)<=2?null:(b=h,{width:R,height:k+1})}function s(){if(!c()||!z())return;let e=window.parent;if(!K(e))return;let t=document.body?Math.max(document.body.scrollWidth,document.body.offsetWidth):0;t!==m&&m!==-1&&(w=0,b=-1),m=t;let n=L();if(!n)return;let{width:i,height:o}=n;if(!(i===l&&o===d)){l=i,d=o,w++;try{e.postMessage({type:"adapt-resize",width:i,height:o},"*")}catch{}}}function g(){p===null&&(p=setTimeout(()=>{p=null,s()},Q))}function Y(){let e=L();if(!e){if(d>0)try{window.parent.postMessage({type:"adapt-resize",width:l,height:d},"*")}catch{}return}let{width:t,height:n}=e;l=t,d=n;try{window.parent.postMessage({type:"adapt-resize",width:t,height:n},"*")}catch{}}function $(e){let t;try{t=e.data}catch{return}if(G(t)){u=t.darkMode;for(let n of y)try{n(t.darkMode)}catch{}}J(t)&&t.autoResizing&&Y()}function v(){if(!c()||!z())return;let e=document.createElement("style");e.textContent=`
|
|
2
|
+
html, body {
|
|
3
|
+
box-sizing: border-box;
|
|
4
|
+
}
|
|
5
|
+
*, *::before, *::after {
|
|
6
|
+
box-sizing: inherit;
|
|
7
|
+
}
|
|
8
|
+
`,document.head.appendChild(e),window.addEventListener("message",$);let t=new ResizeObserver(g);document.body&&t.observe(document.body),document.documentElement&&t.observe(document.documentElement),document.body&&new MutationObserver(g).observe(document.body,{childList:!0,subtree:!0,attributes:!0,characterData:!0}),document.addEventListener("load",g,!0),document.fonts?.ready?.then(()=>{s()}),document.readyState==="complete"?s():window.addEventListener("load",()=>{s()}),setTimeout(s,50),setTimeout(s,150)}c()&&(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",v):v());0&&(module.exports={getDarkMode,getToken,listenDarkMode});
|
|
2
9
|
//# sourceMappingURL=frontend.cjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/frontend.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Frontend utilities for Adapt plugins running in browser/iframe contexts\n *\n * Iframe resizing is handled automatically - no initialization required.\n * Just import the functions you need and the resize communication starts automatically.\n */\n\n// =============================================================================\n// Token Management\n// =============================================================================\n\nlet cachedToken: string | null = null;\n\n/**\n * Get the authentication token from the URL hash.\n * @param isDevelopment If true, returns a dev token for local development\n */\nexport function getToken(isDevelopment = false): string {\n if (isDevelopment) return 'dev-token';\n if (cachedToken !== null) return cachedToken;\n\n if (typeof window === 'undefined' || typeof location === 'undefined') {\n throw new Error('getToken() is only available in browser environments');\n }\n\n const hash = location.hash.slice(1);\n if (!hash) throw new Error('No token found in URL hash');\n\n const token = new URLSearchParams(hash).get('mb_token');\n if (!token) throw new Error('Token \"mb_token\" not found in URL hash');\n\n cachedToken = decodeURIComponent(token);\n return cachedToken;\n}\n\n// =============================================================================\n// Dark Mode\n// =============================================================================\n\nlet currentDarkMode: boolean | null = null;\nconst darkModeListeners = new Set<(darkMode: boolean) => void>();\n\n/**\n * Get the current dark mode state.\n * Returns null if dark mode state hasn't been received from parent yet.\n */\nexport function getDarkMode(): boolean | null {\n return currentDarkMode;\n}\n\n/**\n * Listen for dark mode changes from the parent window.\n * Returns an unsubscribe function.\n * @param callback Called immediately with current state (if known) and on every change\n */\nexport function listenDarkMode(\n callback: (darkMode: boolean) => void\n): () => void {\n darkModeListeners.add(callback);\n\n // Call immediately with current value if we have one\n if (currentDarkMode !== null) {\n try {\n callback(currentDarkMode);\n } catch {}\n }\n\n return () => {\n darkModeListeners.delete(callback);\n };\n}\n\n// =============================================================================\n// Internal: Message Types and Type Guards\n// =============================================================================\n\ninterface AdaptResizeMessage {\n type: 'adapt-resize';\n width: number;\n height: number;\n}\n\ninterface AdaptDarkModeMessage {\n type: 'adapt-darkMode';\n darkMode: boolean;\n}\n\ninterface AdaptAutoResizingMessage {\n type: 'adapt-autoResizing';\n autoResizing: boolean;\n}\n\nfunction isObject(value: unknown): value is Record<string, unknown> {\n return value !== null && typeof value === 'object' && !Array.isArray(value);\n}\n\nfunction isDarkModeMessage(data: unknown): data is AdaptDarkModeMessage {\n return (\n isObject(data) &&\n data.type === 'adapt-darkMode' &&\n typeof data.darkMode === 'boolean'\n );\n}\n\nfunction isAutoResizingMessage(\n data: unknown\n): data is AdaptAutoResizingMessage {\n return (\n isObject(data) &&\n data.type === 'adapt-autoResizing' &&\n typeof data.autoResizing === 'boolean'\n );\n}\n\nfunction isValidDimension(value: number): boolean {\n return Number.isFinite(value) && value >= 1;\n}\n\nfunction hasPostMessage(\n obj: unknown\n): obj is { postMessage: typeof postMessage } {\n return isObject(obj) && typeof obj.postMessage === 'function';\n}\n\n// =============================================================================\n// Internal: Environment Detection\n// =============================================================================\n\nfunction isBrowser(): boolean {\n return (\n typeof window !== 'undefined' &&\n typeof document !== 'undefined' &&\n typeof window.postMessage === 'function'\n );\n}\n\nfunction isInIframe(): boolean {\n if (!isBrowser()) return false;\n try {\n return window.self !== window.top;\n } catch {\n return true;\n }\n}\n\n// =============================================================================\n// Internal: Resize Logic\n// =============================================================================\n\nlet lastSentWidth = -1;\nlet lastSentHeight = -1;\nlet lastBodyHeight = -1;\nlet throttleTimer: ReturnType<typeof setTimeout> | null = null;\nconst THROTTLE_MS = 16;\nlet resizeCount = 0;\nconst RESIZE_SETTLE_COUNT = 5;\n\nfunction getContentDimensions(): { width: number; height: number } | null {\n const { body, documentElement: html } = document;\n if (!body) return null;\n\n // Get computed styles for body margin\n // body.scrollHeight/offsetHeight include padding and border but NOT margin\n const bodyStyle = getComputedStyle(body);\n const bodyMarginTop = parseFloat(bodyStyle.marginTop) || 0;\n const bodyMarginBottom = parseFloat(bodyStyle.marginBottom) || 0;\n const bodyMarginLeft = parseFloat(bodyStyle.marginLeft) || 0;\n const bodyMarginRight = parseFloat(bodyStyle.marginRight) || 0;\n\n // Get computed styles for html element padding and border\n // html padding creates space around the body, html border adds to outer edge\n const htmlStyle = getComputedStyle(html);\n const htmlPaddingTop = parseFloat(htmlStyle.paddingTop) || 0;\n const htmlPaddingBottom = parseFloat(htmlStyle.paddingBottom) || 0;\n const htmlPaddingLeft = parseFloat(htmlStyle.paddingLeft) || 0;\n const htmlPaddingRight = parseFloat(htmlStyle.paddingRight) || 0;\n const htmlBorderTop = parseFloat(htmlStyle.borderTopWidth) || 0;\n const htmlBorderBottom = parseFloat(htmlStyle.borderBottomWidth) || 0;\n const htmlBorderLeft = parseFloat(htmlStyle.borderLeftWidth) || 0;\n const htmlBorderRight = parseFloat(htmlStyle.borderRightWidth) || 0;\n\n // Calculate total dimensions:\n // body content (scrollHeight/offsetHeight includes body padding + border)\n // + body margin (space between body and html's inner edge)\n // + html padding (space between html's inner edge and body)\n // + html border (html element's border)\n const bodyHeight = Math.max(body.scrollHeight, body.offsetHeight);\n const bodyWidth = Math.max(body.scrollWidth, body.offsetWidth);\n\n const height =\n bodyHeight +\n bodyMarginTop +\n bodyMarginBottom +\n htmlPaddingTop +\n htmlPaddingBottom +\n htmlBorderTop +\n htmlBorderBottom;\n\n const width =\n bodyWidth +\n bodyMarginLeft +\n bodyMarginRight +\n htmlPaddingLeft +\n htmlPaddingRight +\n htmlBorderLeft +\n htmlBorderRight;\n\n if (!isValidDimension(width) || !isValidDimension(height)) return null;\n\n // DEBUG: Log resize measurements\n console.log('[adapt-resize] measure:', {\n bodyHeight,\n height,\n lastSentHeight,\n lastBodyHeight,\n bodyTrackingViewport: Math.abs(bodyHeight - lastSentHeight),\n resizeCount\n });\n\n // Feedback loop detection: detect when body is tracking the viewport height\n // If bodyHeight \u2248 lastSentHeight, the body expanded to fill the new iframe\n // This happens with min-height: 100vh or similar viewport-relative CSS\n if (\n resizeCount >= RESIZE_SETTLE_COUNT &&\n lastBodyHeight > 0 &&\n Math.abs(bodyHeight - lastSentHeight) <= 2\n ) {\n console.log('[adapt-resize] STOPPED - body tracking viewport detected');\n return null;\n }\n\n lastBodyHeight = bodyHeight;\n\n return { width, height: height + 1 };\n}\n\nfunction sendResizeImmediate(): void {\n if (!isBrowser() || !isInIframe()) return;\n\n const parent = window.parent;\n if (!hasPostMessage(parent)) return;\n\n const dims = getContentDimensions();\n if (!dims) return;\n\n const { width, height } = dims;\n if (width === lastSentWidth && height === lastSentHeight) return;\n\n // Reset counters on width change (window resize) to allow content to re-settle\n if (width !== lastSentWidth && lastSentWidth !== -1) {\n resizeCount = 0;\n lastBodyHeight = -1;\n }\n\n lastSentWidth = width;\n lastSentHeight = height;\n resizeCount++;\n\n // DEBUG: Log resize send\n console.log('[adapt-resize] SEND:', { width, height, resizeCount });\n\n try {\n parent.postMessage(\n { type: 'adapt-resize', width, height } satisfies AdaptResizeMessage,\n '*'\n );\n } catch {}\n}\n\nfunction sendResizeThrottled(): void {\n if (throttleTimer !== null) return;\n\n throttleTimer = setTimeout(() => {\n throttleTimer = null;\n sendResizeImmediate();\n }, THROTTLE_MS);\n}\n\nfunction sendResizeForced(): void {\n // Reset all tracking values to force fresh measurement\n lastSentWidth = -1;\n lastSentHeight = -1;\n lastBodyHeight = -1;\n resizeCount = 0;\n sendResizeImmediate();\n}\n\n// =============================================================================\n// Internal: Message Handling\n// =============================================================================\n\nfunction handleMessage(event: MessageEvent): void {\n let data: unknown;\n try {\n data = event.data;\n } catch {\n return;\n }\n\n if (isDarkModeMessage(data)) {\n currentDarkMode = data.darkMode;\n for (const listener of darkModeListeners) {\n try {\n listener(data.darkMode);\n } catch {}\n }\n }\n\n if (isAutoResizingMessage(data) && data.autoResizing) {\n // Parent requested auto-resizing - immediately send current dimensions\n sendResizeForced();\n }\n}\n\n// =============================================================================\n// Internal: Auto-initialization\n// =============================================================================\n\nfunction autoInit(): void {\n if (!isBrowser() || !isInIframe()) return;\n\n // Listen for messages from parent\n window.addEventListener('message', handleMessage);\n\n // Set up resize observation\n const resizeObserver = new ResizeObserver(sendResizeThrottled);\n if (document.body) resizeObserver.observe(document.body);\n if (document.documentElement)\n resizeObserver.observe(document.documentElement);\n\n // Set up mutation observation for DOM changes\n if (document.body) {\n const mutationObserver = new MutationObserver(sendResizeThrottled);\n mutationObserver.observe(document.body, {\n childList: true,\n subtree: true,\n attributes: true,\n characterData: true\n });\n }\n\n // Capture load events on resources (images, iframes, etc.)\n document.addEventListener('load', sendResizeThrottled, true);\n\n // Wait for fonts to load\n document.fonts?.ready?.then(() => {\n sendResizeImmediate();\n });\n\n // Send initial size when fully loaded\n if (document.readyState === 'complete') {\n // Already loaded, send immediately\n sendResizeImmediate();\n } else {\n // Wait for full load\n window.addEventListener('load', () => {\n sendResizeImmediate();\n });\n }\n\n // Send again with delays to handle timing issues where parent sends\n // adapt-autoResizing before we're fully ready\n setTimeout(sendResizeImmediate, 50);\n setTimeout(sendResizeImmediate, 150);\n}\n\n// Run initialization when DOM is ready\nif (isBrowser()) {\n if (document.readyState === 'loading') {\n document.addEventListener('DOMContentLoaded', autoInit);\n } else {\n // DOM already ready, init now\n autoInit();\n }\n}\n"],
|
|
5
|
-
"mappings": "yaAAA,IAAAA,
|
|
6
|
-
"names": ["frontend_exports", "__export", "getDarkMode", "getToken", "listenDarkMode", "__toCommonJS", "cachedToken", "isDevelopment", "hash", "token", "currentDarkMode", "darkModeListeners", "callback", "isObject", "value", "isDarkModeMessage", "data", "isAutoResizingMessage", "isValidDimension", "hasPostMessage", "obj", "isBrowser", "isInIframe", "lastSentWidth", "lastSentHeight", "lastBodyHeight", "throttleTimer", "THROTTLE_MS", "resizeCount", "RESIZE_SETTLE_COUNT", "getContentDimensions", "body", "html", "bodyStyle", "bodyMarginTop", "bodyMarginBottom", "bodyMarginLeft", "bodyMarginRight", "htmlStyle", "htmlPaddingTop", "htmlPaddingBottom", "htmlPaddingLeft", "htmlPaddingRight", "htmlBorderTop", "htmlBorderBottom", "htmlBorderLeft", "htmlBorderRight", "bodyHeight", "bodyWidth", "height", "width", "sendResizeImmediate", "parent", "dims", "sendResizeThrottled", "sendResizeForced", "handleMessage", "event", "listener", "autoInit", "resizeObserver"]
|
|
4
|
+
"sourcesContent": ["/**\n * Frontend utilities for Adapt plugins running in browser/iframe contexts\n *\n * Iframe resizing is handled automatically - no initialization required.\n * Just import the functions you need and the resize communication starts automatically.\n */\n\n// =============================================================================\n// Token Management\n// =============================================================================\n\nlet cachedToken: string | null = null;\n\n/**\n * Get the authentication token from the URL hash.\n * @param isDevelopment If true, returns a dev token for local development\n */\nexport function getToken(isDevelopment = false): string {\n if (isDevelopment) return 'dev-token';\n if (cachedToken !== null) return cachedToken;\n\n if (typeof window === 'undefined' || typeof location === 'undefined') {\n throw new Error('getToken() is only available in browser environments');\n }\n\n const hash = location.hash.slice(1);\n if (!hash) throw new Error('No token found in URL hash');\n\n const token = new URLSearchParams(hash).get('mb_token');\n if (!token) throw new Error('Token \"mb_token\" not found in URL hash');\n\n cachedToken = decodeURIComponent(token);\n return cachedToken;\n}\n\n// =============================================================================\n// Dark Mode\n// =============================================================================\n\nlet currentDarkMode: boolean | null = null;\nconst darkModeListeners = new Set<(darkMode: boolean) => void>();\n\n/**\n * Get the current dark mode state.\n * Returns null if dark mode state hasn't been received from parent yet.\n */\nexport function getDarkMode(): boolean | null {\n return currentDarkMode;\n}\n\n/**\n * Listen for dark mode changes from the parent window.\n * Returns an unsubscribe function.\n * @param callback Called immediately with current state (if known) and on every change\n */\nexport function listenDarkMode(\n callback: (darkMode: boolean) => void\n): () => void {\n darkModeListeners.add(callback);\n\n // Call immediately with current value if we have one\n if (currentDarkMode !== null) {\n try {\n callback(currentDarkMode);\n } catch {}\n }\n\n return () => {\n darkModeListeners.delete(callback);\n };\n}\n\n// =============================================================================\n// Internal: Message Types and Type Guards\n// =============================================================================\n\ninterface AdaptResizeMessage {\n type: 'adapt-resize';\n width: number;\n height: number;\n}\n\ninterface AdaptDarkModeMessage {\n type: 'adapt-darkMode';\n darkMode: boolean;\n}\n\ninterface AdaptAutoResizingMessage {\n type: 'adapt-autoResizing';\n autoResizing: boolean;\n}\n\nfunction isObject(value: unknown): value is Record<string, unknown> {\n return value !== null && typeof value === 'object' && !Array.isArray(value);\n}\n\nfunction isDarkModeMessage(data: unknown): data is AdaptDarkModeMessage {\n return (\n isObject(data) &&\n data.type === 'adapt-darkMode' &&\n typeof data.darkMode === 'boolean'\n );\n}\n\nfunction isAutoResizingMessage(\n data: unknown\n): data is AdaptAutoResizingMessage {\n return (\n isObject(data) &&\n data.type === 'adapt-autoResizing' &&\n typeof data.autoResizing === 'boolean'\n );\n}\n\nfunction isValidDimension(value: number): boolean {\n return Number.isFinite(value) && value >= 1;\n}\n\nfunction hasPostMessage(\n obj: unknown\n): obj is { postMessage: typeof postMessage } {\n return isObject(obj) && typeof obj.postMessage === 'function';\n}\n\n// =============================================================================\n// Internal: Environment Detection\n// =============================================================================\n\nfunction isBrowser(): boolean {\n return (\n typeof window !== 'undefined' &&\n typeof document !== 'undefined' &&\n typeof window.postMessage === 'function'\n );\n}\n\nfunction isInIframe(): boolean {\n if (!isBrowser()) return false;\n try {\n return window.self !== window.top;\n } catch {\n return true;\n }\n}\n\n// =============================================================================\n// Internal: Resize Logic\n// =============================================================================\n\nlet lastSentWidth = -1;\nlet lastSentHeight = -1;\nlet lastBodyWidth = -1; // Track body width separately for change detection\nlet lastBodyHeight = -1;\nlet throttleTimer: ReturnType<typeof setTimeout> | null = null;\nconst THROTTLE_MS = 16;\nlet resizeCount = 0;\nconst RESIZE_SETTLE_COUNT = 5;\n\nfunction getContentDimensions(): { width: number; height: number } | null {\n const { body, documentElement: html } = document;\n if (!body) return null;\n\n // Get computed styles for body margin\n // body.scrollHeight/offsetHeight include padding and border but NOT margin\n const bodyStyle = getComputedStyle(body);\n const bodyMarginTop = parseFloat(bodyStyle.marginTop) || 0;\n const bodyMarginBottom = parseFloat(bodyStyle.marginBottom) || 0;\n const bodyMarginLeft = parseFloat(bodyStyle.marginLeft) || 0;\n const bodyMarginRight = parseFloat(bodyStyle.marginRight) || 0;\n\n // Get computed styles for html element padding and border\n // html padding creates space around the body, html border adds to outer edge\n const htmlStyle = getComputedStyle(html);\n const htmlPaddingTop = parseFloat(htmlStyle.paddingTop) || 0;\n const htmlPaddingBottom = parseFloat(htmlStyle.paddingBottom) || 0;\n const htmlPaddingLeft = parseFloat(htmlStyle.paddingLeft) || 0;\n const htmlPaddingRight = parseFloat(htmlStyle.paddingRight) || 0;\n const htmlBorderTop = parseFloat(htmlStyle.borderTopWidth) || 0;\n const htmlBorderBottom = parseFloat(htmlStyle.borderBottomWidth) || 0;\n const htmlBorderLeft = parseFloat(htmlStyle.borderLeftWidth) || 0;\n const htmlBorderRight = parseFloat(htmlStyle.borderRightWidth) || 0;\n\n // Calculate total dimensions:\n // body content (scrollHeight/offsetHeight includes body padding + border)\n // + body margin (space between body and html's inner edge)\n // + html padding (space between html's inner edge and body)\n // + html border (html element's border)\n const bodyHeight = Math.max(body.scrollHeight, body.offsetHeight);\n const bodyWidth = Math.max(body.scrollWidth, body.offsetWidth);\n\n const height =\n bodyHeight +\n bodyMarginTop +\n bodyMarginBottom +\n htmlPaddingTop +\n htmlPaddingBottom +\n htmlBorderTop +\n htmlBorderBottom;\n\n const width =\n bodyWidth +\n bodyMarginLeft +\n bodyMarginRight +\n htmlPaddingLeft +\n htmlPaddingRight +\n htmlBorderLeft +\n htmlBorderRight;\n\n if (!isValidDimension(width) || !isValidDimension(height)) return null;\n\n // Feedback loop detection: detect when body is tracking the viewport height\n // If bodyHeight \u2248 lastSentHeight, the body expanded to fill the new iframe\n // This happens with min-height: 100vh or similar viewport-relative CSS\n if (\n resizeCount >= RESIZE_SETTLE_COUNT &&\n lastBodyHeight > 0 &&\n Math.abs(bodyHeight - lastSentHeight) <= 2\n ) {\n return null;\n }\n\n lastBodyHeight = bodyHeight;\n\n return { width, height: height + 1 };\n}\n\nfunction sendResizeImmediate(): void {\n if (!isBrowser() || !isInIframe()) return;\n\n const parent = window.parent;\n if (!hasPostMessage(parent)) return;\n\n // Check for width change BEFORE getting dims (to reset counters)\n const currentBodyWidth = document.body\n ? Math.max(document.body.scrollWidth, document.body.offsetWidth)\n : 0;\n if (currentBodyWidth !== lastBodyWidth && lastBodyWidth !== -1) {\n // Width changed (window resize) - reset counters to allow re-settling\n resizeCount = 0;\n lastBodyHeight = -1;\n }\n lastBodyWidth = currentBodyWidth;\n\n const dims = getContentDimensions();\n if (!dims) return;\n\n const { width, height } = dims;\n if (width === lastSentWidth && height === lastSentHeight) return;\n\n lastSentWidth = width;\n lastSentHeight = height;\n resizeCount++;\n\n try {\n parent.postMessage(\n { type: 'adapt-resize', width, height } satisfies AdaptResizeMessage,\n '*'\n );\n } catch {}\n}\n\nfunction sendResizeThrottled(): void {\n if (throttleTimer !== null) return;\n\n throttleTimer = setTimeout(() => {\n throttleTimer = null;\n sendResizeImmediate();\n }, THROTTLE_MS);\n}\n\nfunction sendResizeForced(): void {\n // Force sending current dimensions (don't reset tracking)\n const dims = getContentDimensions();\n if (!dims) {\n // If detection stopped us, send the last known dimensions\n if (lastSentHeight > 0) {\n try {\n window.parent.postMessage(\n {\n type: 'adapt-resize',\n width: lastSentWidth,\n height: lastSentHeight\n },\n '*'\n );\n } catch {}\n }\n return;\n }\n\n const { width, height } = dims;\n lastSentWidth = width;\n lastSentHeight = height;\n\n try {\n window.parent.postMessage({ type: 'adapt-resize', width, height }, '*');\n } catch {}\n}\n\n// =============================================================================\n// Internal: Message Handling\n// =============================================================================\n\nfunction handleMessage(event: MessageEvent): void {\n let data: unknown;\n try {\n data = event.data;\n } catch {\n return;\n }\n\n if (isDarkModeMessage(data)) {\n currentDarkMode = data.darkMode;\n for (const listener of darkModeListeners) {\n try {\n listener(data.darkMode);\n } catch {}\n }\n }\n\n if (isAutoResizingMessage(data) && data.autoResizing) {\n // Parent requested auto-resizing - immediately send current dimensions\n sendResizeForced();\n }\n}\n\n// =============================================================================\n// Internal: Auto-initialization\n// =============================================================================\n\nfunction autoInit(): void {\n if (!isBrowser() || !isInIframe()) return;\n\n // Inject baseline CSS for consistent measurements\n // This ensures box-sizing is predictable regardless of plugin CSS\n const style = document.createElement('style');\n style.textContent = `\n html, body {\n box-sizing: border-box;\n }\n *, *::before, *::after {\n box-sizing: inherit;\n }\n `;\n document.head.appendChild(style);\n\n // Listen for messages from parent\n window.addEventListener('message', handleMessage);\n\n // Set up resize observation\n const resizeObserver = new ResizeObserver(sendResizeThrottled);\n if (document.body) resizeObserver.observe(document.body);\n if (document.documentElement)\n resizeObserver.observe(document.documentElement);\n\n // Set up mutation observation for DOM changes\n if (document.body) {\n const mutationObserver = new MutationObserver(sendResizeThrottled);\n mutationObserver.observe(document.body, {\n childList: true,\n subtree: true,\n attributes: true,\n characterData: true\n });\n }\n\n // Capture load events on resources (images, iframes, etc.)\n document.addEventListener('load', sendResizeThrottled, true);\n\n // Wait for fonts to load\n document.fonts?.ready?.then(() => {\n sendResizeImmediate();\n });\n\n // Send initial size when fully loaded\n if (document.readyState === 'complete') {\n // Already loaded, send immediately\n sendResizeImmediate();\n } else {\n // Wait for full load\n window.addEventListener('load', () => {\n sendResizeImmediate();\n });\n }\n\n // Send again with delays to handle timing issues where parent sends\n // adapt-autoResizing before we're fully ready\n setTimeout(sendResizeImmediate, 50);\n setTimeout(sendResizeImmediate, 150);\n}\n\n// Run initialization when DOM is ready\nif (isBrowser()) {\n if (document.readyState === 'loading') {\n document.addEventListener('DOMContentLoaded', autoInit);\n } else {\n // DOM already ready, init now\n autoInit();\n }\n}\n"],
|
|
5
|
+
"mappings": "yaAAA,IAAAA,GAAA,GAAAC,EAAAD,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AAoBwC,CAAQ,EAGtDA,EAAS",
|
|
6
|
+
"names": ["frontend_exports", "__export", "getDarkMode", "getToken", "listenDarkMode", "__toCommonJS", "cachedToken", "isDevelopment", "hash", "token", "currentDarkMode", "darkModeListeners", "callback", "isObject", "value", "isDarkModeMessage", "data", "isAutoResizingMessage", "isValidDimension", "hasPostMessage", "obj", "isBrowser", "isInIframe", "lastSentWidth", "lastSentHeight", "lastBodyWidth", "lastBodyHeight", "throttleTimer", "THROTTLE_MS", "resizeCount", "RESIZE_SETTLE_COUNT", "getContentDimensions", "body", "html", "bodyStyle", "bodyMarginTop", "bodyMarginBottom", "bodyMarginLeft", "bodyMarginRight", "htmlStyle", "htmlPaddingTop", "htmlPaddingBottom", "htmlPaddingLeft", "htmlPaddingRight", "htmlBorderTop", "htmlBorderBottom", "htmlBorderLeft", "htmlBorderRight", "bodyHeight", "bodyWidth", "height", "width", "sendResizeImmediate", "parent", "currentBodyWidth", "dims", "sendResizeThrottled", "sendResizeForced", "handleMessage", "event", "listener", "autoInit", "style", "resizeObserver"]
|
|
7
7
|
}
|
package/dist/esm/frontend.mjs
CHANGED
|
@@ -1,2 +1,9 @@
|
|
|
1
|
-
var
|
|
1
|
+
var a=null;function V(e=!1){if(e)return"dev-token";if(a!==null)return a;if(typeof window>"u"||typeof location>"u")throw new Error("getToken() is only available in browser environments");let t=location.hash.slice(1);if(!t)throw new Error("No token found in URL hash");let n=new URLSearchParams(t).get("mb_token");if(!n)throw new Error('Token "mb_token" not found in URL hash');return a=decodeURIComponent(n),a}var u=null,g=new Set;function Z(){return u}function q(e){if(g.add(e),u!==null)try{e(u)}catch{}return()=>{g.delete(e)}}function w(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function H(e){return w(e)&&e.type==="adapt-darkMode"&&typeof e.darkMode=="boolean"}function I(e){return w(e)&&e.type==="adapt-autoResizing"&&typeof e.autoResizing=="boolean"}function R(e){return Number.isFinite(e)&&e>=1}function P(e){return w(e)&&typeof e.postMessage=="function"}function c(){return typeof window<"u"&&typeof document<"u"&&typeof window.postMessage=="function"}function v(){if(!c())return!1;try{return window.self!==window.top}catch{return!0}}var l=-1,r=-1,f=-1,y=-1,m=null,U=16,b=0,_=5;function z(){let{body:e,documentElement:t}=document;if(!e)return null;let n=getComputedStyle(e),s=parseFloat(n.marginTop)||0,d=parseFloat(n.marginBottom)||0,L=parseFloat(n.marginLeft)||0,E=parseFloat(n.marginRight)||0,o=getComputedStyle(t),B=parseFloat(o.paddingTop)||0,F=parseFloat(o.paddingBottom)||0,S=parseFloat(o.paddingLeft)||0,W=parseFloat(o.paddingRight)||0,A=parseFloat(o.borderTopWidth)||0,x=parseFloat(o.borderBottomWidth)||0,D=parseFloat(o.borderLeftWidth)||0,C=parseFloat(o.borderRightWidth)||0,h=Math.max(e.scrollHeight,e.offsetHeight),O=Math.max(e.scrollWidth,e.offsetWidth),M=h+s+d+B+F+A+x,k=O+L+E+S+W+D+C;return!R(k)||!R(M)||b>=_&&y>0&&Math.abs(h-r)<=2?null:(y=h,{width:k,height:M+1})}function i(){if(!c()||!v())return;let e=window.parent;if(!P(e))return;let t=document.body?Math.max(document.body.scrollWidth,document.body.offsetWidth):0;t!==f&&f!==-1&&(b=0,y=-1),f=t;let n=z();if(!n)return;let{width:s,height:d}=n;if(!(s===l&&d===r)){l=s,r=d,b++;try{e.postMessage({type:"adapt-resize",width:s,height:d},"*")}catch{}}}function p(){m===null&&(m=setTimeout(()=>{m=null,i()},U))}function N(){let e=z();if(!e){if(r>0)try{window.parent.postMessage({type:"adapt-resize",width:l,height:r},"*")}catch{}return}let{width:t,height:n}=e;l=t,r=n;try{window.parent.postMessage({type:"adapt-resize",width:t,height:n},"*")}catch{}}function j(e){let t;try{t=e.data}catch{return}if(H(t)){u=t.darkMode;for(let n of g)try{n(t.darkMode)}catch{}}I(t)&&t.autoResizing&&N()}function T(){if(!c()||!v())return;let e=document.createElement("style");e.textContent=`
|
|
2
|
+
html, body {
|
|
3
|
+
box-sizing: border-box;
|
|
4
|
+
}
|
|
5
|
+
*, *::before, *::after {
|
|
6
|
+
box-sizing: inherit;
|
|
7
|
+
}
|
|
8
|
+
`,document.head.appendChild(e),window.addEventListener("message",j);let t=new ResizeObserver(p);document.body&&t.observe(document.body),document.documentElement&&t.observe(document.documentElement),document.body&&new MutationObserver(p).observe(document.body,{childList:!0,subtree:!0,attributes:!0,characterData:!0}),document.addEventListener("load",p,!0),document.fonts?.ready?.then(()=>{i()}),document.readyState==="complete"?i():window.addEventListener("load",()=>{i()}),setTimeout(i,50),setTimeout(i,150)}c()&&(document.readyState==="loading"?document.addEventListener("DOMContentLoaded",T):T());export{Z as getDarkMode,V as getToken,q as listenDarkMode};
|
|
2
9
|
//# sourceMappingURL=frontend.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/frontend.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Frontend utilities for Adapt plugins running in browser/iframe contexts\n *\n * Iframe resizing is handled automatically - no initialization required.\n * Just import the functions you need and the resize communication starts automatically.\n */\n\n// =============================================================================\n// Token Management\n// =============================================================================\n\nlet cachedToken: string | null = null;\n\n/**\n * Get the authentication token from the URL hash.\n * @param isDevelopment If true, returns a dev token for local development\n */\nexport function getToken(isDevelopment = false): string {\n if (isDevelopment) return 'dev-token';\n if (cachedToken !== null) return cachedToken;\n\n if (typeof window === 'undefined' || typeof location === 'undefined') {\n throw new Error('getToken() is only available in browser environments');\n }\n\n const hash = location.hash.slice(1);\n if (!hash) throw new Error('No token found in URL hash');\n\n const token = new URLSearchParams(hash).get('mb_token');\n if (!token) throw new Error('Token \"mb_token\" not found in URL hash');\n\n cachedToken = decodeURIComponent(token);\n return cachedToken;\n}\n\n// =============================================================================\n// Dark Mode\n// =============================================================================\n\nlet currentDarkMode: boolean | null = null;\nconst darkModeListeners = new Set<(darkMode: boolean) => void>();\n\n/**\n * Get the current dark mode state.\n * Returns null if dark mode state hasn't been received from parent yet.\n */\nexport function getDarkMode(): boolean | null {\n return currentDarkMode;\n}\n\n/**\n * Listen for dark mode changes from the parent window.\n * Returns an unsubscribe function.\n * @param callback Called immediately with current state (if known) and on every change\n */\nexport function listenDarkMode(\n callback: (darkMode: boolean) => void\n): () => void {\n darkModeListeners.add(callback);\n\n // Call immediately with current value if we have one\n if (currentDarkMode !== null) {\n try {\n callback(currentDarkMode);\n } catch {}\n }\n\n return () => {\n darkModeListeners.delete(callback);\n };\n}\n\n// =============================================================================\n// Internal: Message Types and Type Guards\n// =============================================================================\n\ninterface AdaptResizeMessage {\n type: 'adapt-resize';\n width: number;\n height: number;\n}\n\ninterface AdaptDarkModeMessage {\n type: 'adapt-darkMode';\n darkMode: boolean;\n}\n\ninterface AdaptAutoResizingMessage {\n type: 'adapt-autoResizing';\n autoResizing: boolean;\n}\n\nfunction isObject(value: unknown): value is Record<string, unknown> {\n return value !== null && typeof value === 'object' && !Array.isArray(value);\n}\n\nfunction isDarkModeMessage(data: unknown): data is AdaptDarkModeMessage {\n return (\n isObject(data) &&\n data.type === 'adapt-darkMode' &&\n typeof data.darkMode === 'boolean'\n );\n}\n\nfunction isAutoResizingMessage(\n data: unknown\n): data is AdaptAutoResizingMessage {\n return (\n isObject(data) &&\n data.type === 'adapt-autoResizing' &&\n typeof data.autoResizing === 'boolean'\n );\n}\n\nfunction isValidDimension(value: number): boolean {\n return Number.isFinite(value) && value >= 1;\n}\n\nfunction hasPostMessage(\n obj: unknown\n): obj is { postMessage: typeof postMessage } {\n return isObject(obj) && typeof obj.postMessage === 'function';\n}\n\n// =============================================================================\n// Internal: Environment Detection\n// =============================================================================\n\nfunction isBrowser(): boolean {\n return (\n typeof window !== 'undefined' &&\n typeof document !== 'undefined' &&\n typeof window.postMessage === 'function'\n );\n}\n\nfunction isInIframe(): boolean {\n if (!isBrowser()) return false;\n try {\n return window.self !== window.top;\n } catch {\n return true;\n }\n}\n\n// =============================================================================\n// Internal: Resize Logic\n// =============================================================================\n\nlet lastSentWidth = -1;\nlet lastSentHeight = -1;\nlet lastBodyHeight = -1;\nlet throttleTimer: ReturnType<typeof setTimeout> | null = null;\nconst THROTTLE_MS = 16;\nlet resizeCount = 0;\nconst RESIZE_SETTLE_COUNT = 5;\n\nfunction getContentDimensions(): { width: number; height: number } | null {\n const { body, documentElement: html } = document;\n if (!body) return null;\n\n // Get computed styles for body margin\n // body.scrollHeight/offsetHeight include padding and border but NOT margin\n const bodyStyle = getComputedStyle(body);\n const bodyMarginTop = parseFloat(bodyStyle.marginTop) || 0;\n const bodyMarginBottom = parseFloat(bodyStyle.marginBottom) || 0;\n const bodyMarginLeft = parseFloat(bodyStyle.marginLeft) || 0;\n const bodyMarginRight = parseFloat(bodyStyle.marginRight) || 0;\n\n // Get computed styles for html element padding and border\n // html padding creates space around the body, html border adds to outer edge\n const htmlStyle = getComputedStyle(html);\n const htmlPaddingTop = parseFloat(htmlStyle.paddingTop) || 0;\n const htmlPaddingBottom = parseFloat(htmlStyle.paddingBottom) || 0;\n const htmlPaddingLeft = parseFloat(htmlStyle.paddingLeft) || 0;\n const htmlPaddingRight = parseFloat(htmlStyle.paddingRight) || 0;\n const htmlBorderTop = parseFloat(htmlStyle.borderTopWidth) || 0;\n const htmlBorderBottom = parseFloat(htmlStyle.borderBottomWidth) || 0;\n const htmlBorderLeft = parseFloat(htmlStyle.borderLeftWidth) || 0;\n const htmlBorderRight = parseFloat(htmlStyle.borderRightWidth) || 0;\n\n // Calculate total dimensions:\n // body content (scrollHeight/offsetHeight includes body padding + border)\n // + body margin (space between body and html's inner edge)\n // + html padding (space between html's inner edge and body)\n // + html border (html element's border)\n const bodyHeight = Math.max(body.scrollHeight, body.offsetHeight);\n const bodyWidth = Math.max(body.scrollWidth, body.offsetWidth);\n\n const height =\n bodyHeight +\n bodyMarginTop +\n bodyMarginBottom +\n htmlPaddingTop +\n htmlPaddingBottom +\n htmlBorderTop +\n htmlBorderBottom;\n\n const width =\n bodyWidth +\n bodyMarginLeft +\n bodyMarginRight +\n htmlPaddingLeft +\n htmlPaddingRight +\n htmlBorderLeft +\n htmlBorderRight;\n\n if (!isValidDimension(width) || !isValidDimension(height)) return null;\n\n // DEBUG: Log resize measurements\n console.log('[adapt-resize] measure:', {\n bodyHeight,\n height,\n lastSentHeight,\n lastBodyHeight,\n bodyTrackingViewport: Math.abs(bodyHeight - lastSentHeight),\n resizeCount\n });\n\n // Feedback loop detection: detect when body is tracking the viewport height\n // If bodyHeight \u2248 lastSentHeight, the body expanded to fill the new iframe\n // This happens with min-height: 100vh or similar viewport-relative CSS\n if (\n resizeCount >= RESIZE_SETTLE_COUNT &&\n lastBodyHeight > 0 &&\n Math.abs(bodyHeight - lastSentHeight) <= 2\n ) {\n console.log('[adapt-resize] STOPPED - body tracking viewport detected');\n return null;\n }\n\n lastBodyHeight = bodyHeight;\n\n return { width, height: height + 1 };\n}\n\nfunction sendResizeImmediate(): void {\n if (!isBrowser() || !isInIframe()) return;\n\n const parent = window.parent;\n if (!hasPostMessage(parent)) return;\n\n const dims = getContentDimensions();\n if (!dims) return;\n\n const { width, height } = dims;\n if (width === lastSentWidth && height === lastSentHeight) return;\n\n // Reset counters on width change (window resize) to allow content to re-settle\n if (width !== lastSentWidth && lastSentWidth !== -1) {\n resizeCount = 0;\n lastBodyHeight = -1;\n }\n\n lastSentWidth = width;\n lastSentHeight = height;\n resizeCount++;\n\n // DEBUG: Log resize send\n console.log('[adapt-resize] SEND:', { width, height, resizeCount });\n\n try {\n parent.postMessage(\n { type: 'adapt-resize', width, height } satisfies AdaptResizeMessage,\n '*'\n );\n } catch {}\n}\n\nfunction sendResizeThrottled(): void {\n if (throttleTimer !== null) return;\n\n throttleTimer = setTimeout(() => {\n throttleTimer = null;\n sendResizeImmediate();\n }, THROTTLE_MS);\n}\n\nfunction sendResizeForced(): void {\n // Reset all tracking values to force fresh measurement\n lastSentWidth = -1;\n lastSentHeight = -1;\n lastBodyHeight = -1;\n resizeCount = 0;\n sendResizeImmediate();\n}\n\n// =============================================================================\n// Internal: Message Handling\n// =============================================================================\n\nfunction handleMessage(event: MessageEvent): void {\n let data: unknown;\n try {\n data = event.data;\n } catch {\n return;\n }\n\n if (isDarkModeMessage(data)) {\n currentDarkMode = data.darkMode;\n for (const listener of darkModeListeners) {\n try {\n listener(data.darkMode);\n } catch {}\n }\n }\n\n if (isAutoResizingMessage(data) && data.autoResizing) {\n // Parent requested auto-resizing - immediately send current dimensions\n sendResizeForced();\n }\n}\n\n// =============================================================================\n// Internal: Auto-initialization\n// =============================================================================\n\nfunction autoInit(): void {\n if (!isBrowser() || !isInIframe()) return;\n\n // Listen for messages from parent\n window.addEventListener('message', handleMessage);\n\n // Set up resize observation\n const resizeObserver = new ResizeObserver(sendResizeThrottled);\n if (document.body) resizeObserver.observe(document.body);\n if (document.documentElement)\n resizeObserver.observe(document.documentElement);\n\n // Set up mutation observation for DOM changes\n if (document.body) {\n const mutationObserver = new MutationObserver(sendResizeThrottled);\n mutationObserver.observe(document.body, {\n childList: true,\n subtree: true,\n attributes: true,\n characterData: true\n });\n }\n\n // Capture load events on resources (images, iframes, etc.)\n document.addEventListener('load', sendResizeThrottled, true);\n\n // Wait for fonts to load\n document.fonts?.ready?.then(() => {\n sendResizeImmediate();\n });\n\n // Send initial size when fully loaded\n if (document.readyState === 'complete') {\n // Already loaded, send immediately\n sendResizeImmediate();\n } else {\n // Wait for full load\n window.addEventListener('load', () => {\n sendResizeImmediate();\n });\n }\n\n // Send again with delays to handle timing issues where parent sends\n // adapt-autoResizing before we're fully ready\n setTimeout(sendResizeImmediate, 50);\n setTimeout(sendResizeImmediate, 150);\n}\n\n// Run initialization when DOM is ready\nif (isBrowser()) {\n if (document.readyState === 'loading') {\n document.addEventListener('DOMContentLoaded', autoInit);\n } else {\n // DOM already ready, init now\n autoInit();\n }\n}\n"],
|
|
5
|
-
"mappings": "AAWA,IAAIA,EAA6B,KAM1B,SAASC,EAASC,EAAgB,GAAe,CACtD,GAAIA,EAAe,MAAO,YAC1B,GAAIF,IA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AAO,GACzB,GAAI,CACF,OAAO,OAAO,OAAS,OAAO,GAChC,MAAQ,CACN,MAAO,EACT,CACF,CAMA,IAAIE,EAAgB,GAChBC,EAAiB,GACjBC,EAAiB,GACjBC,EAAsD,KACpDC,EAAc,GAChBC,EAAc,EACZC,EAAsB,EAE5B,SAASC,GAAiE,CACxE,GAAM,CAAE,KAAAC,EAAM,gBAAiBC,CAAK,EAAI,SACxC,GAAI,CAACD,EAAM,OAAO,KAIlB,IAAME,EAAY,iBAAiBF,CAAI,EACjCG,EAAgB,WAAWD,EAAU,SAAS,GAAK,EACnDE,EAAmB,WAAWF,EAAU,YAAY,GAAK,EACzDG,EAAiB,WAAWH,EAAU,UAAU,GAAK,EACrDI,EAAkB,WAAWJ,EAAU,WAAW,GAAK,EAIvDK,EAAY,iBAAiBN,CAAI,EACjCO,EAAiB,WAAWD,EAAU,UAAU,GAAK,EACrDE,EAAoB,WAAWF,EAAU,aAAa,GAAK,EAC3DG,EAAkB,WAAWH,EAAU,WAAW,GAAK,EACvDI,EAAmB,WAAWJ,EAAU,YAAY,GAAK,EACzDK,EAAgB,WAAWL,EAAU,cAAc,GAAK,EACxDM,EAAmB,WAAWN,EAAU,iBAAiB,GAAK,EAC9DO,EAAiB,WAAWP,EAAU,eAAe,GAAK,EAC1DQ,EAAkB,WAAWR,EAAU,gBAAgB,GAAK,EAO5DS,EAAa,KAAK,IAAIhB,EAAK,aAAcA,EAAK,YAAY,EAC1DiB,EAAY,KAAK,IAAIjB,EAAK,YAAaA,EAAK,WAAW,EAEvDkB,EACJF,EACAb,EACAC,EACAI,EACAC,EACAG,EACAC,EAEIM,EACJF,EACAZ,EACAC,EACAI,EACAC,EACAG,EACAC,
|
|
6
|
-
"names": ["cachedToken", "getToken", "isDevelopment", "hash", "token", "currentDarkMode", "darkModeListeners", "getDarkMode", "listenDarkMode", "callback", "isObject", "value", "isDarkModeMessage", "data", "isAutoResizingMessage", "isValidDimension", "hasPostMessage", "obj", "isBrowser", "isInIframe", "lastSentWidth", "lastSentHeight", "lastBodyHeight", "throttleTimer", "THROTTLE_MS", "resizeCount", "RESIZE_SETTLE_COUNT", "getContentDimensions", "body", "html", "bodyStyle", "bodyMarginTop", "bodyMarginBottom", "bodyMarginLeft", "bodyMarginRight", "htmlStyle", "htmlPaddingTop", "htmlPaddingBottom", "htmlPaddingLeft", "htmlPaddingRight", "htmlBorderTop", "htmlBorderBottom", "htmlBorderLeft", "htmlBorderRight", "bodyHeight", "bodyWidth", "height", "width", "sendResizeImmediate", "parent", "dims", "sendResizeThrottled", "sendResizeForced", "handleMessage", "event", "listener", "autoInit", "resizeObserver"]
|
|
4
|
+
"sourcesContent": ["/**\n * Frontend utilities for Adapt plugins running in browser/iframe contexts\n *\n * Iframe resizing is handled automatically - no initialization required.\n * Just import the functions you need and the resize communication starts automatically.\n */\n\n// =============================================================================\n// Token Management\n// =============================================================================\n\nlet cachedToken: string | null = null;\n\n/**\n * Get the authentication token from the URL hash.\n * @param isDevelopment If true, returns a dev token for local development\n */\nexport function getToken(isDevelopment = false): string {\n if (isDevelopment) return 'dev-token';\n if (cachedToken !== null) return cachedToken;\n\n if (typeof window === 'undefined' || typeof location === 'undefined') {\n throw new Error('getToken() is only available in browser environments');\n }\n\n const hash = location.hash.slice(1);\n if (!hash) throw new Error('No token found in URL hash');\n\n const token = new URLSearchParams(hash).get('mb_token');\n if (!token) throw new Error('Token \"mb_token\" not found in URL hash');\n\n cachedToken = decodeURIComponent(token);\n return cachedToken;\n}\n\n// =============================================================================\n// Dark Mode\n// =============================================================================\n\nlet currentDarkMode: boolean | null = null;\nconst darkModeListeners = new Set<(darkMode: boolean) => void>();\n\n/**\n * Get the current dark mode state.\n * Returns null if dark mode state hasn't been received from parent yet.\n */\nexport function getDarkMode(): boolean | null {\n return currentDarkMode;\n}\n\n/**\n * Listen for dark mode changes from the parent window.\n * Returns an unsubscribe function.\n * @param callback Called immediately with current state (if known) and on every change\n */\nexport function listenDarkMode(\n callback: (darkMode: boolean) => void\n): () => void {\n darkModeListeners.add(callback);\n\n // Call immediately with current value if we have one\n if (currentDarkMode !== null) {\n try {\n callback(currentDarkMode);\n } catch {}\n }\n\n return () => {\n darkModeListeners.delete(callback);\n };\n}\n\n// =============================================================================\n// Internal: Message Types and Type Guards\n// =============================================================================\n\ninterface AdaptResizeMessage {\n type: 'adapt-resize';\n width: number;\n height: number;\n}\n\ninterface AdaptDarkModeMessage {\n type: 'adapt-darkMode';\n darkMode: boolean;\n}\n\ninterface AdaptAutoResizingMessage {\n type: 'adapt-autoResizing';\n autoResizing: boolean;\n}\n\nfunction isObject(value: unknown): value is Record<string, unknown> {\n return value !== null && typeof value === 'object' && !Array.isArray(value);\n}\n\nfunction isDarkModeMessage(data: unknown): data is AdaptDarkModeMessage {\n return (\n isObject(data) &&\n data.type === 'adapt-darkMode' &&\n typeof data.darkMode === 'boolean'\n );\n}\n\nfunction isAutoResizingMessage(\n data: unknown\n): data is AdaptAutoResizingMessage {\n return (\n isObject(data) &&\n data.type === 'adapt-autoResizing' &&\n typeof data.autoResizing === 'boolean'\n );\n}\n\nfunction isValidDimension(value: number): boolean {\n return Number.isFinite(value) && value >= 1;\n}\n\nfunction hasPostMessage(\n obj: unknown\n): obj is { postMessage: typeof postMessage } {\n return isObject(obj) && typeof obj.postMessage === 'function';\n}\n\n// =============================================================================\n// Internal: Environment Detection\n// =============================================================================\n\nfunction isBrowser(): boolean {\n return (\n typeof window !== 'undefined' &&\n typeof document !== 'undefined' &&\n typeof window.postMessage === 'function'\n );\n}\n\nfunction isInIframe(): boolean {\n if (!isBrowser()) return false;\n try {\n return window.self !== window.top;\n } catch {\n return true;\n }\n}\n\n// =============================================================================\n// Internal: Resize Logic\n// =============================================================================\n\nlet lastSentWidth = -1;\nlet lastSentHeight = -1;\nlet lastBodyWidth = -1; // Track body width separately for change detection\nlet lastBodyHeight = -1;\nlet throttleTimer: ReturnType<typeof setTimeout> | null = null;\nconst THROTTLE_MS = 16;\nlet resizeCount = 0;\nconst RESIZE_SETTLE_COUNT = 5;\n\nfunction getContentDimensions(): { width: number; height: number } | null {\n const { body, documentElement: html } = document;\n if (!body) return null;\n\n // Get computed styles for body margin\n // body.scrollHeight/offsetHeight include padding and border but NOT margin\n const bodyStyle = getComputedStyle(body);\n const bodyMarginTop = parseFloat(bodyStyle.marginTop) || 0;\n const bodyMarginBottom = parseFloat(bodyStyle.marginBottom) || 0;\n const bodyMarginLeft = parseFloat(bodyStyle.marginLeft) || 0;\n const bodyMarginRight = parseFloat(bodyStyle.marginRight) || 0;\n\n // Get computed styles for html element padding and border\n // html padding creates space around the body, html border adds to outer edge\n const htmlStyle = getComputedStyle(html);\n const htmlPaddingTop = parseFloat(htmlStyle.paddingTop) || 0;\n const htmlPaddingBottom = parseFloat(htmlStyle.paddingBottom) || 0;\n const htmlPaddingLeft = parseFloat(htmlStyle.paddingLeft) || 0;\n const htmlPaddingRight = parseFloat(htmlStyle.paddingRight) || 0;\n const htmlBorderTop = parseFloat(htmlStyle.borderTopWidth) || 0;\n const htmlBorderBottom = parseFloat(htmlStyle.borderBottomWidth) || 0;\n const htmlBorderLeft = parseFloat(htmlStyle.borderLeftWidth) || 0;\n const htmlBorderRight = parseFloat(htmlStyle.borderRightWidth) || 0;\n\n // Calculate total dimensions:\n // body content (scrollHeight/offsetHeight includes body padding + border)\n // + body margin (space between body and html's inner edge)\n // + html padding (space between html's inner edge and body)\n // + html border (html element's border)\n const bodyHeight = Math.max(body.scrollHeight, body.offsetHeight);\n const bodyWidth = Math.max(body.scrollWidth, body.offsetWidth);\n\n const height =\n bodyHeight +\n bodyMarginTop +\n bodyMarginBottom +\n htmlPaddingTop +\n htmlPaddingBottom +\n htmlBorderTop +\n htmlBorderBottom;\n\n const width =\n bodyWidth +\n bodyMarginLeft +\n bodyMarginRight +\n htmlPaddingLeft +\n htmlPaddingRight +\n htmlBorderLeft +\n htmlBorderRight;\n\n if (!isValidDimension(width) || !isValidDimension(height)) return null;\n\n // Feedback loop detection: detect when body is tracking the viewport height\n // If bodyHeight \u2248 lastSentHeight, the body expanded to fill the new iframe\n // This happens with min-height: 100vh or similar viewport-relative CSS\n if (\n resizeCount >= RESIZE_SETTLE_COUNT &&\n lastBodyHeight > 0 &&\n Math.abs(bodyHeight - lastSentHeight) <= 2\n ) {\n return null;\n }\n\n lastBodyHeight = bodyHeight;\n\n return { width, height: height + 1 };\n}\n\nfunction sendResizeImmediate(): void {\n if (!isBrowser() || !isInIframe()) return;\n\n const parent = window.parent;\n if (!hasPostMessage(parent)) return;\n\n // Check for width change BEFORE getting dims (to reset counters)\n const currentBodyWidth = document.body\n ? Math.max(document.body.scrollWidth, document.body.offsetWidth)\n : 0;\n if (currentBodyWidth !== lastBodyWidth && lastBodyWidth !== -1) {\n // Width changed (window resize) - reset counters to allow re-settling\n resizeCount = 0;\n lastBodyHeight = -1;\n }\n lastBodyWidth = currentBodyWidth;\n\n const dims = getContentDimensions();\n if (!dims) return;\n\n const { width, height } = dims;\n if (width === lastSentWidth && height === lastSentHeight) return;\n\n lastSentWidth = width;\n lastSentHeight = height;\n resizeCount++;\n\n try {\n parent.postMessage(\n { type: 'adapt-resize', width, height } satisfies AdaptResizeMessage,\n '*'\n );\n } catch {}\n}\n\nfunction sendResizeThrottled(): void {\n if (throttleTimer !== null) return;\n\n throttleTimer = setTimeout(() => {\n throttleTimer = null;\n sendResizeImmediate();\n }, THROTTLE_MS);\n}\n\nfunction sendResizeForced(): void {\n // Force sending current dimensions (don't reset tracking)\n const dims = getContentDimensions();\n if (!dims) {\n // If detection stopped us, send the last known dimensions\n if (lastSentHeight > 0) {\n try {\n window.parent.postMessage(\n {\n type: 'adapt-resize',\n width: lastSentWidth,\n height: lastSentHeight\n },\n '*'\n );\n } catch {}\n }\n return;\n }\n\n const { width, height } = dims;\n lastSentWidth = width;\n lastSentHeight = height;\n\n try {\n window.parent.postMessage({ type: 'adapt-resize', width, height }, '*');\n } catch {}\n}\n\n// =============================================================================\n// Internal: Message Handling\n// =============================================================================\n\nfunction handleMessage(event: MessageEvent): void {\n let data: unknown;\n try {\n data = event.data;\n } catch {\n return;\n }\n\n if (isDarkModeMessage(data)) {\n currentDarkMode = data.darkMode;\n for (const listener of darkModeListeners) {\n try {\n listener(data.darkMode);\n } catch {}\n }\n }\n\n if (isAutoResizingMessage(data) && data.autoResizing) {\n // Parent requested auto-resizing - immediately send current dimensions\n sendResizeForced();\n }\n}\n\n// =============================================================================\n// Internal: Auto-initialization\n// =============================================================================\n\nfunction autoInit(): void {\n if (!isBrowser() || !isInIframe()) return;\n\n // Inject baseline CSS for consistent measurements\n // This ensures box-sizing is predictable regardless of plugin CSS\n const style = document.createElement('style');\n style.textContent = `\n html, body {\n box-sizing: border-box;\n }\n *, *::before, *::after {\n box-sizing: inherit;\n }\n `;\n document.head.appendChild(style);\n\n // Listen for messages from parent\n window.addEventListener('message', handleMessage);\n\n // Set up resize observation\n const resizeObserver = new ResizeObserver(sendResizeThrottled);\n if (document.body) resizeObserver.observe(document.body);\n if (document.documentElement)\n resizeObserver.observe(document.documentElement);\n\n // Set up mutation observation for DOM changes\n if (document.body) {\n const mutationObserver = new MutationObserver(sendResizeThrottled);\n mutationObserver.observe(document.body, {\n childList: true,\n subtree: true,\n attributes: true,\n characterData: true\n });\n }\n\n // Capture load events on resources (images, iframes, etc.)\n document.addEventListener('load', sendResizeThrottled, true);\n\n // Wait for fonts to load\n document.fonts?.ready?.then(() => {\n sendResizeImmediate();\n });\n\n // Send initial size when fully loaded\n if (document.readyState === 'complete') {\n // Already loaded, send immediately\n sendResizeImmediate();\n } else {\n // Wait for full load\n window.addEventListener('load', () => {\n sendResizeImmediate();\n });\n }\n\n // Send again with delays to handle timing issues where parent sends\n // adapt-autoResizing before we're fully ready\n setTimeout(sendResizeImmediate, 50);\n setTimeout(sendResizeImmediate, 150);\n}\n\n// Run initialization when DOM is ready\nif (isBrowser()) {\n if (document.readyState === 'loading') {\n document.addEventListener('DOMContentLoaded', autoInit);\n } else {\n // DOM already ready, init now\n autoInit();\n }\n}\n"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|
6
|
+
"names": ["cachedToken", "getToken", "isDevelopment", "hash", "token", "currentDarkMode", "darkModeListeners", "getDarkMode", "listenDarkMode", "callback", "isObject", "value", "isDarkModeMessage", "data", "isAutoResizingMessage", "isValidDimension", "hasPostMessage", "obj", "isBrowser", "isInIframe", "lastSentWidth", "lastSentHeight", "lastBodyWidth", "lastBodyHeight", "throttleTimer", "THROTTLE_MS", "resizeCount", "RESIZE_SETTLE_COUNT", "getContentDimensions", "body", "html", "bodyStyle", "bodyMarginTop", "bodyMarginBottom", "bodyMarginLeft", "bodyMarginRight", "htmlStyle", "htmlPaddingTop", "htmlPaddingBottom", "htmlPaddingLeft", "htmlPaddingRight", "htmlBorderTop", "htmlBorderBottom", "htmlBorderLeft", "htmlBorderRight", "bodyHeight", "bodyWidth", "height", "width", "sendResizeImmediate", "parent", "currentBodyWidth", "dims", "sendResizeThrottled", "sendResizeForced", "handleMessage", "event", "listener", "autoInit", "style", "resizeObserver"]
|
|
7
7
|
}
|