Loading…
위로 스크롤

' + escapeHtml(t.diagram) + '

' + escapeHtml(pattern || '') + '
' + (html || '
' + escapeHtml(t.diagramEmpty) + '
') + '
'; const blob = new Blob([fullHtml], { type: 'text/html' }); const url = URL.createObjectURL(blob); window.open(url, '_blank'); setTimeout(() => URL.revokeObjectURL(url), 5000); } catch (e) { console.warn('Pattern Studio addon popout error', e); } }); } // Initial render if user already on diagram/explain (rare). // Important: do this only once per root to avoid resetting token selections // when the add-on is re-ensured by DOM mutations. try { if (root.dataset && root.dataset.psAddonInitRender !== '1') { root.dataset.psAddonInitRender = '1'; setTimeout(onUpdate, 0); } } catch (e) {} } catch (e) { console.warn('Pattern Studio addon ensureViews error', e); } } function mountAddon() { qa('.ps-root').forEach(root => ensureViews(root)); } function inViewbar(node) { try { let el = (node && node.nodeType === 1) ? node : (node && node.parentNode ? node.parentNode : null); while (el && el !== document.documentElement) { if (el.matches && el.matches('[data-viewbar]')) return true; el = el.parentNode; } } catch (e) {} return false; } function needsMount(mutations) { try { for (const m of mutations || []) { // If the mutation happens inside the viewbar, core likely re-rendered tabs. if (inViewbar(m.target)) return true; const nodes = []; if (m.addedNodes && m.addedNodes.length) nodes.push(...m.addedNodes); if (m.removedNodes && m.removedNodes.length) nodes.push(...m.removedNodes); for (const n of nodes) { if (!n || n.nodeType !== 1) continue; const el = n; // New app root inserted if (el.matches && el.matches('.ps-root')) return true; // Viewbar inserted/replaced if (el.matches && el.matches('[data-viewbar]')) return true; // Or contains either if (el.querySelector && (el.querySelector('.ps-root') || el.querySelector('[data-viewbar]'))) return true; } } } catch (e) {} return false; } function boot() { try { mountAddon(); const obs = new MutationObserver((mutations) => { if (needsMount(mutations)) { mountAddon(); } }); obs.observe(document.documentElement, { childList: true, subtree: true }); // Keep the observer for a while to survive Elementor/SPA-ish DOM swaps, // but avoid reacting to internal diagram/explain DOM updates. setTimeout(() => { try { obs.disconnect(); } catch (e) {} }, 60000); } catch (e) { console.warn('Pattern Studio addon boot error', e); } } if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', boot); } else { boot(); } })();