UNPKG

@lobehub/ui

Version:

Lobe UI is an open-source UI component library for building AIGC web apps

1 lines 1.24 kB
{"version":3,"file":"injectAutoHeightScript.mjs","names":[],"sources":["../../src/HtmlPreview/injectAutoHeightScript.ts"],"sourcesContent":["export const AUTO_HEIGHT_MESSAGE_TYPE = 'lobe-html-resize';\n\nexport const buildAutoHeightScript = (frameId: string) => `\n(function () {\n var frameId = ${JSON.stringify(frameId)};\n function post() {\n try {\n var h = Math.max(\n document.documentElement.scrollHeight,\n document.body ? document.body.scrollHeight : 0,\n );\n parent.postMessage({ type: ${JSON.stringify(AUTO_HEIGHT_MESSAGE_TYPE)}, frameId: frameId, height: h }, '*');\n } catch (_) {}\n }\n\n function attach() {\n post();\n try {\n var ro = new ResizeObserver(post);\n if (document.body) ro.observe(document.body);\n if (document.documentElement) ro.observe(document.documentElement);\n } catch (_) {}\n window.addEventListener('load', post);\n window.addEventListener('resize', post);\n }\n\n if (document.readyState === 'loading') {\n document.addEventListener('DOMContentLoaded', attach);\n } else {\n attach();\n }\n})();\n`;\n"],"mappings":";AAAA,MAAa,2BAA2B;AAExC,MAAa,yBAAyB,YAAoB;;kBAExC,KAAK,UAAU,QAAQ,CAAC;;;;;;;mCAOP,KAAK,UAAU,yBAAyB,CAAC"}