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B,EAAI,OAAS,UAAY;;;2CAGlD,KAAK;;uCAET,EAAI,KAAO;;;;;SAO9C,GAxRS,EAqKF,OAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAnKhB,EAAA,CADC,EAAS,CAAE,KAAM,UADT,EAET,UAAA,eAGA,EAAA,CADC,EAAS,CAAE,KAAM,UAJT,EAKT,UAAA,WAEiB,EAAA,CAAhB,KAPQ,EAOQ,UAAA,kBACA,EAAA,CAAhB,KARQ,EAQQ,UAAA,qBACA,EAAA,CAAhB,KATQ,EASQ,UAAA,wBACA,EAAA,CAAhB,KAVQ,EAUQ,UAAA,qBACA,EAAA,CAAhB,KAXQ,EAWQ,UAAA,iBACA,EAAA,CAAhB,KAZQ,EAYQ,UAAA,kBACA,EAAA,CAAhB,KAbQ,EAaQ,UAAA,mBAEU,EAAA,CAA1B,EAAM,aAfE,EAekB,UAAA,aAflB,EAAN,EAAA,CADN,EAAc,uBACF,U","file":"/npm/@record-evolution/widget-embed@1.0.7/dist/widget-embed.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@record-evolution/widget-embed@1.0.7/dist/widget-embed.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","import { html, css, LitElement, PropertyValueMap, nothing } from 'lit'\nimport { repeat } from 'lit/directives/repeat.js'\nimport { customElement, property, query, state } from 'lit/decorators.js'\nimport { InputData } from './definition-schema.js'\n\ntype Theme = {\n    theme_name: string\n    theme_object: any\n}\n\n@customElement('widget-embed-versionplaceholder')\nexport class WidgetValue extends LitElement {\n    @property({ type: Object })\n    inputData?: InputData\n\n    @property({ type: Object })\n    theme?: Theme\n\n    @state() private themeBgColor?: string\n    @state() private themeTitleColor?: string\n    @state() private themeSubtitleColor?: string\n    @state() private showFailMessage: boolean = false\n    @state() private gridColumns: number = 1\n    @state() private elementWidth: number = 0\n    @state() private elementHeight: number = 0\n\n    @query('.wrapper') private wrapper?: HTMLDivElement\n\n    version: string = 'versionplaceholder'\n    private resizeObserver?: ResizeObserver\n\n    disconnectedCallback() {\n        super.disconnectedCallback()\n        if (this.resizeObserver) {\n            this.resizeObserver.disconnect()\n        }\n    }\n\n    protected firstUpdated(_changedProperties: PropertyValueMap<any> | Map<PropertyKey, unknown>) {\n        this.registerTheme(this.theme)\n\n        // Set up ResizeObserver for the wrapper\n        if (this.wrapper) {\n            this.resizeObserver = new ResizeObserver(() => {\n                this.updateGridLayout()\n            })\n            this.resizeObserver.observe(this.wrapper)\n            // Initial layout calculation\n            this.updateGridLayout()\n        }\n    }\n\n    update(changedProperties: Map<string, any>) {\n        if (changedProperties.has('inputData')) {\n            this.updateGridLayout()\n        }\n\n        if (changedProperties.has('theme')) {\n            this.registerTheme(this.theme)\n        }\n\n        super.update(changedProperties)\n    }\n\n    registerTheme(theme?: Theme) {\n        const cssTextColor = getComputedStyle(this).getPropertyValue('--re-text-color').trim()\n        const cssBgColor = getComputedStyle(this).getPropertyValue('--re-tile-background-color').trim()\n        this.themeBgColor = cssBgColor || this.theme?.theme_object?.backgroundColor\n        this.themeTitleColor = cssTextColor || this.theme?.theme_object?.title?.textStyle?.color\n        this.themeSubtitleColor =\n            cssTextColor || this.theme?.theme_object?.title?.subtextStyle?.color || this.themeTitleColor\n    }\n\n    /**\n     * Update grid layout based on container size and number of elements\n     */\n    updateGridLayout() {\n        if (!this.wrapper) return\n\n        const urls = this.inputData?.multiEmbed\n            ? (this.inputData?.data?.map((item) => item.webUrl) ?? [])\n            : [this.inputData?.webUrl ?? '']\n\n        const numElements = urls.length\n        if (numElements === 0) return\n\n        const rect = this.wrapper.getBoundingClientRect()\n        const containerWidth = rect.width\n        const containerHeight = rect.height\n\n        if (containerWidth === 0 || containerHeight === 0) return\n\n        // Maximize total area (negative because optimizeLayout minimizes error)\n        const layout = this.optimizeLayout(\n            containerWidth,\n            containerHeight,\n            numElements,\n            (w, h) => Math.abs(w / h - 16 / 10),\n            this.inputData?.gap ?? 12\n        )\n\n        // Update grid columns and element dimensions\n        this.elementWidth = layout.elementWidth\n        this.elementHeight = layout.elementHeight\n        console.log('Optimized layout:', layout)\n        // Apply width and height to each child iframe\n        const iframes = this.wrapper.querySelectorAll('.iframe-container') as NodeListOf<HTMLDivElement>\n        iframes.forEach((iframe) => {\n            iframe.style.width = `${layout.elementWidth}px`\n            iframe.style.height = `${layout.elementHeight}px`\n        })\n    }\n\n    /**\n     * Optimize grid layout by minimizing an error function\n     * @param containerWidth - Available width for the grid\n     * @param containerHeight - Available height for the grid\n     * @param numElements - Number of elements to arrange\n     * @param errorFn - Error function that takes (element_width, element_height) and returns error value\n     * @param gap - Gap between elements (default: 12)\n     * @returns Optimal layout configuration\n     */\n    optimizeLayout(\n        containerWidth: number,\n        containerHeight: number,\n        numElements: number,\n        errorFn: (w: number, h: number) => number,\n        gap: number = 12\n    ): {\n        elementWidth: number\n        elementHeight: number\n        numCols: number\n        numRows: number\n        error: number\n    } {\n        let bestLayout = {\n            elementWidth: 0,\n            elementHeight: 0,\n            numCols: 1,\n            numRows: numElements,\n            error: Infinity\n        }\n\n        // Try all possible column configurations from 1 to numElements\n        for (let cols = 1; cols <= numElements; cols++) {\n            const rows = Math.ceil(numElements / cols)\n\n            // Calculate element dimensions accounting for gaps\n            const totalGapWidth = gap * (cols - 1)\n            const totalGapHeight = gap * (rows - 1)\n            const availableWidth = containerWidth - totalGapWidth\n            const availableHeight = containerHeight - totalGapHeight\n\n            if (availableWidth <= 0 || availableHeight <= 0) continue\n\n            const elementWidth = availableWidth / cols\n            const elementHeight = availableHeight / rows\n\n            // Calculate error for this configuration\n            const error = errorFn(elementWidth, elementHeight)\n\n            // Update best layout if this is better\n            if (error < bestLayout.error) {\n                bestLayout = {\n                    elementWidth,\n                    elementHeight,\n                    numCols: cols,\n                    numRows: rows,\n                    error\n                }\n            }\n        }\n\n        return bestLayout\n    }\n\n    static styles = css`\n        :host {\n            display: block;\n            font-family: sans-serif;\n            box-sizing: border-box;\n            position: relative;\n            margin: auto;\n        }\n\n        .paging:not([active]) {\n            display: none !important;\n        }\n\n        .wrapper {\n            display: flex;\n            flex-wrap: wrap;\n            height: 100%;\n            width: 100%;\n            box-sizing: border-box;\n            gap: 12px;\n            align-content: flex-start;\n        }\n\n        .wrapper > * {\n            flex-shrink: 1;\n            min-width: 0;\n            min-height: 0;\n        }\n\n        .title {\n            height: 24px;\n            font-size: 18px;\n            margin: 0;\n            padding: 0 4px;\n            overflow: hidden;\n            text-overflow: ellipsis;\n            text-align: center;\n            flex: 0 0 auto;\n            white-space: nowrap;\n        }\n\n        .no-data {\n            font-size: 20px;\n            display: flex;\n            flex-direction: column;\n            height: 100%;\n            width: 100%;\n            text-align: center;\n            align-items: center;\n            justify-content: center;\n        }\n\n        .iframe-container {\n            display: flex;\n            flex-direction: column;\n            box-sizing: border-box;\n            max-width: 100%;\n            max-height: 100%;\n            overflow: hidden;\n        }\n\n        iframe {\n            border: none;\n            flex: 1;\n            min-width: 0;\n            min-height: 0;\n            width: 100%;\n            height: 100%;\n        }\n    `\n\n    render() {\n        const urls = this.inputData?.multiEmbed\n            ? (this.inputData?.data ?? [])\n            : [{ url: this.inputData?.webUrl ?? '', title: this.inputData?.title ?? '' }]\n        const hasMultipleItems = urls.length > 1\n        const showTitles = urls.filter((u) => u.title).length > 0\n\n        return html`\n            <div\n                class=\"wrapper\"\n                style=\"background-color: ${this.themeBgColor}; color: ${this\n                    .themeTitleColor}; gap: ${hasMultipleItems ? `${this.inputData?.gap ?? 12}px` : '0px'};\"\n            >\n                <div class=\"no-data paging\" ?active=${this.showFailMessage}>\n                    Unable to display the content. The site may have restrictions preventing it from being\n                    embedded.\n                    <a\n                        href=\"${this.inputData?.webUrl ?? ''}\"\n                        target=\"_blank\"\n                        style=\"color: ${this.themeTitleColor};\"\n                        >${this.inputData?.webUrl}</a\n                    >\n                </div>\n                ${repeat(\n                    urls,\n                    (url) => url.url,\n                    (url) => html`\n                        <div\n                            class=\"iframe-container\"\n                            style=\"border: none; width: ${this.elementWidth}px; height: ${this\n                                .elementHeight}px;\"\n                        >\n                            ${showTitles ? html`<h2 class=\"title\">${url.title ?? ''}</h2>` : nothing}\n                            <iframe\n                                class=\"paging\"\n                                ?active=${!this.showFailMessage}\n                                allowfullscreen\n                                src=\"${url.url ?? ''}\"\n                            ></iframe>\n                        </div>\n                    `\n                )}\n            </div>\n        `\n    }\n}\n"]}