PATH:
home
/
nappmpmd
/
bestyment.online
/
wp-content
/
themes
/
wvc-theme
/
assets
/
js
/** * Gutenberg void block comment compiler * Hydrates server-rendered compiled placeholders into real DOM near block comments. * * Contract (matches PHP WVCBlocks): full token = "<!--" + comment.data + "-->"; * wrapper id = fullToken with double quotes replaced by single quotes (then PHP esc_attr in HTML). */ function wvcBlockWrapperIdFromFullToken(fullToken) { return fullToken.replace(/"/g, "'"); } function wvcBlockFullTokenFromCommentData(data) { return "<!--" + data + "-->"; } function wvcBlockIsWpBlockCommentData(data) { return /^\s*\/?wp:\s*\S/.test(data || ""); } function wvcBlockParseCommentMeta(data) { const raw = (data || "").trim(); const isClosing = /^\/wp:\s*/.test(raw); const openingMatch = raw.match(/^wp:\s*([^\s/][^\s]*)/); const closingMatch = raw.match(/^\/wp:\s*([^\s/][^\s]*)/); const blockName = openingMatch ? openingMatch[1] : closingMatch ? closingMatch[1] : ""; const isOpening = !isClosing && /^wp:\s*/.test(raw); const isVoid = isOpening && /\/\s*$/.test(raw); return { raw, blockName, isOpening, isClosing, isVoid, }; } function wvcBlockShouldSkipForAncestors(node) { let parent = node.parentNode; while (parent) { const tag = parent.tagName; if (tag === "SCRIPT" || tag === "STYLE" || tag === "WRAPPER") { return true; } parent = parent.parentNode; } return false; } function wvcBlockFindUnusedStoreNode(wrapperId) { return document.querySelector( `wrapper[id="${CSS.escape(wrapperId)}"]:not([data-processed])` ); } function wvcBlockMaterializeNode(storeNode) { if (!storeNode) { return null; } if (storeNode.innerHTML.trim()) { const fragment = document.createDocumentFragment(); while (storeNode.firstChild) { fragment.appendChild(storeNode.firstChild); } return fragment; } return null; } function wvcBlockTryFindWrapper(commentNode) { const raw = commentNode.data; const variants = []; if (raw != null && raw !== "") { variants.push(raw); } const trimmed = typeof raw === "string" ? raw.trim() : ""; if (trimmed !== "" && trimmed !== raw) { variants.push(trimmed); } for (const d of variants) { const full = wvcBlockFullTokenFromCommentData(d); const wid = wvcBlockWrapperIdFromFullToken(full); const store = wvcBlockFindUnusedStoreNode(wid); if (store) { return store; } } return null; } function wvcBlockFindMatchingClosingComment(openCommentNode) { const openMeta = wvcBlockParseCommentMeta(openCommentNode.data); if (!openMeta.isOpening || openMeta.isVoid || !openMeta.blockName) { return null; } const walker = document.createTreeWalker( document.body, NodeFilter.SHOW_COMMENT, null, false ); walker.currentNode = openCommentNode; let depth = 1; let node; while ((node = walker.nextNode())) { if (wvcBlockShouldSkipForAncestors(node)) { continue; } if (!wvcBlockIsWpBlockCommentData(node.data)) { continue; } const meta = wvcBlockParseCommentMeta(node.data); if (meta.blockName !== openMeta.blockName) { continue; } if (meta.isOpening && !meta.isVoid) { depth += 1; continue; } if (meta.isClosing) { depth -= 1; if (depth === 0) { return node; } } } return null; } function wvcBlockReplacePairedRange(openCommentNode, closeCommentNode, renderedNode) { if (!openCommentNode.parentNode || !closeCommentNode.parentNode) { return false; } const parent = openCommentNode.parentNode; if (parent !== closeCommentNode.parentNode) { return false; } parent.insertBefore(renderedNode, openCommentNode); let node = openCommentNode; while (node) { const next = node.nextSibling; parent.removeChild(node); if (node === closeCommentNode) { break; } node = next; } return true; } function wvcBlockProcessOneComment(commentNode) { if (!commentNode.parentNode) { return false; } if (!wvcBlockIsWpBlockCommentData(commentNode.data)) { return false; } const meta = wvcBlockParseCommentMeta(commentNode.data); if (!meta.isOpening) { return false; } const storeNode = wvcBlockTryFindWrapper(commentNode); if (!storeNode) { return false; } const renderedNode = wvcBlockMaterializeNode(storeNode); if (!renderedNode) { return false; } storeNode.setAttribute("data-processed", "true"); if (storeNode.parentNode) { storeNode.parentNode.removeChild(storeNode); } if (!meta.isVoid) { const closeCommentNode = wvcBlockFindMatchingClosingComment(commentNode); if (closeCommentNode) { return wvcBlockReplacePairedRange(commentNode, closeCommentNode, renderedNode); } } const parent = commentNode.parentNode; parent.insertBefore(renderedNode, commentNode); parent.removeChild(commentNode); return true; } function wvcBlockProcessCommentsAfterRender() { setTimeout(() => { const walker = document.createTreeWalker( document.body, NodeFilter.SHOW_COMMENT, null, false ); const comments = []; let node; while ((node = walker.nextNode())) { if (!wvcBlockIsWpBlockCommentData(node.data)) { continue; } if (wvcBlockShouldSkipForAncestors(node)) { continue; } const meta = wvcBlockParseCommentMeta(node.data); if (!meta.isOpening) { continue; } comments.push(node); } let processedCount = 0; comments.forEach((c) => { if (wvcBlockProcessOneComment(c)) { processedCount += 1; } }); // Do not poll forever; subsequent runs are driven by MutationObserver. }, 100); } if (document.readyState === "loading") { document.addEventListener("DOMContentLoaded", wvcBlockProcessCommentsAfterRender); } else { wvcBlockProcessCommentsAfterRender(); } const wvcBlockMutationObserver = new MutationObserver((mutations) => { let shouldProcess = false; mutations.forEach((mutation) => { if (mutation.type !== "childList" || mutation.addedNodes.length === 0) { return; } mutation.addedNodes.forEach((added) => { if (added.nodeType === Node.COMMENT_NODE) { if (wvcBlockIsWpBlockCommentData(added.data)) { shouldProcess = true; } } else if (added.nodeType === Node.ELEMENT_NODE) { if (added.tagName === "WRAPPER") { shouldProcess = true; return; } const innerWalker = document.createTreeWalker( added, NodeFilter.SHOW_COMMENT, null, false ); let c; while ((c = innerWalker.nextNode())) { if (wvcBlockIsWpBlockCommentData(c.data)) { shouldProcess = true; break; } } if (!shouldProcess) { const hasWrapperStore = added.querySelector("wrapper"); if (hasWrapperStore) { shouldProcess = true; } } } }); }); if (shouldProcess) { setTimeout(wvcBlockProcessCommentsAfterRender, 100); } }); wvcBlockMutationObserver.observe(document.body, { childList: true, subtree: true, });
[+]
..
[-] short-code.compiler.js
[edit]
[-] wvc.js
[edit]
[-] index.umd.js
[edit]
[-] wvc-editor.js
[edit]
[-] block.compiler.js
[edit]
[-] content.compiler.js
[edit]