export const streamingIifeCode = "var __unhead_iife__ = (function (exports) { 'use strict'; const DupeableTags = new Set([\"link\", \"style\", \"script\", \"noscript\"]); const TagsWithInnerContent = new Set([\"title\", \"titleTemplate\", \"script\", \"style\", \"noscript\"]); const HasElementTags = new Set([\"base\", \"meta\", \"link\", \"style\", \"script\", \"noscript\"]); const ValidHeadTags = new Set([\"title\", \"base\", \"htmlAttrs\", \"bodyAttrs\", \"meta\", \"link\", \"style\", \"script\", \"noscript\"]); const UniqueTags = new Set([\"base\", \"title\", \"titleTemplate\", \"bodyAttrs\", \"htmlAttrs\", \"templateParams\"]); const TagConfigKeys = new Set([\"key\", \"tagPosition\", \"tagPriority\", \"tagDuplicateStrategy\", \"innerHTML\", \"textContent\", \"\u0070rocessTemplateParams\"]); const UsesMergeStrategy = new Set([\"templateParams\", \"htmlAttrs\", \"bodyAttrs\"]); const MetaTagsArrayable = new Set([ \"theme-color\", \"google-site-verification\", \"author\", \"og:locale:alternate\", \"og:image\", \"og:video\", \"og:audio\", \"article:author\", \"article:tag\", \"book:author\", \"book:tag\", \"twitter:image\" ]); const hasContent = (value) => typeof value === \"number\" ? Number.isFinite(value) : value; function isUnsafeKey(key) { return key === \"__proto__\" || key === \"constructor\" || key === \"prototype\"; } function callHook(head, hook, ctx) { const hooks = head.hooks?._hooks?.[hook]; if (!hooks?.length) return; return head.hooks?.callHook(hook, ctx); } const META_NOREWRITE_RE = /^(?:viewport|description|keywords|robots)$/; const META_KEY_ATTRS = [\"name\", \"property\", \"http-equiv\"]; function isMetaArrayDupeKey(v) { const i = v.indexOf(\":\"); if (i === -1) return false; const key = v.slice(i + 1); return MetaTagsArrayable.has(key) || key.startsWith(\"og:image:\") || key.startsWith(\"og:video:\") || key.startsWith(\"og:audio:\") || key.startsWith(\"twitter:image:\"); } function dedupeKey(tag) { const { props, tag: t, key } = tag; if (UniqueTags.has(t)) return t; if (t === \"link\") { if (props.rel === \"canonical\") return \"canonical\"; if (props.rel === \"alternate\" && props.hreflang) return `alternate:${props.hreflang}`; } if (props.charset) return \"charset\"; if (t === \"meta\") { for (const n of META_KEY_ATTRS) { const v = props[n]; if (v !== void 0) return `meta:${v}${(typeof v !== \"string\" || !v.includes(\":\")) && !META_NOREWRITE_RE.test(v) && key ? `:key:${key}` : \"\"}`; } } if (key) return `${t}:key:${key}`; if (props.id) return `${t}:id:${props.id}`; if (t === \"link\" && props.rel && props.href) return `link:${props.rel}:${props.href}`; return TagsWithInnerContent.has(t) && (tag.textContent || tag.innerHTML) ? `${t}:content:${tag.textContent || tag.innerHTML}` : void 0; } function hashTag(tag) { const identity = tag._h || tag._d || tag.textContent || tag.innerHTML; if (identity) return String(identity); const keys = Object.keys(tag.props).sort(); let hash = `${tag.tag}:`; let separator = \"\"; for (const key of keys) { hash += `${separator}${key}:${String(tag.props[key])}`; separator = \",\"; } return hash; } function walkResolver(val, resolve, key) { if (key === \"_resolver\") return val; if (typeof val === \"function\" && (!key || key !== \"titleTemplate\" && !key.startsWith(\"on\"))) val = val(); const v = resolve ? resolve(key, val) : val; if (Array.isArray(v)) { let out; for (let i = 0; i < v.length; i++) { const r = walkResolver(v[i], resolve); if (out) { out[i] = r; } else if (r !== v[i]) { out = v.slice(0, i); out[i] = r; } } return out || v; } if (v?.constructor === Object) { let next; for (const k in v) { const unsafe = isUnsafeKey(k); const r = unsafe ? void 0 : walkResolver(v[k], resolve, k); if (!next && (unsafe || r !== v[k])) { next = {}; for (const pk in v) { if (pk === k) break; next[pk] = v[pk]; } } if (next && !unsafe) next[k] = r; } return next || v; } return v; } const INVALID_ATTR_NAME_RE = /[\\s\"'<>/=\\x00-\\x1F\\x7F]/; function normalizeStyleClassProps(key, value) { const isStyle = key === \"style\"; const store = isStyle ? new Map() : new Set(); const add = (v) => { if (!v) return; if (isStyle) { const i = v.indexOf(\":\"); i > 0 && store.set(v.slice(0, i).trim(), v.slice(i + 1).trim()); } else { v.split(\" \").forEach((c) => c && store.add(c)); } }; if (typeof value === \"string\") { (isStyle ? value.split(\";\") : [value]).forEach(add); } else if (Array.isArray(value)) { value.forEach(add); } else if (value && typeof value === \"object\") { for (const k in value) { const v = value[k]; v && v !== \"false\" && (isStyle ? store.set(k.trim(), String(v)) : add(k)); } } return store; } function normalizeProps(tag, input) { tag.props = tag.props || {}; if (!input) return tag; if (tag.tag === \"templateParams\") { tag.props = input; return tag; } const isHtmlTag = HasElementTags.has(tag.tag) || tag.tag === \"htmlAttrs\" || tag.tag === \"bodyAttrs\"; for (const prop in input) { if (isUnsafeKey(prop)) continue; const isData = prop.startsWith(\"data-\"); const isHtmlAttr = isHtmlTag && !TagConfigKeys.has(prop); const key = isHtmlAttr && !isData ? prop.toLowerCase() : prop; if (isHtmlAttr && (!key || INVALID_ATTR_NAME_RE.test(key))) continue; const value = input[prop]; if (value === null) { tag.props[key] = null; } else if (prop === \"class\" || prop === \"style\") { tag.props[prop] = normalizeStyleClassProps(prop, value); } else if (TagConfigKeys.has(prop)) { if ((prop === \"textContent\" || prop === \"innerHTML\") && typeof value === \"object\") { const type = input.type || \"application/json\"; if (type.endsWith(\"json\") || type === \"speculationrules\" || type === \"importmap\") { tag.props.type = type; tag[prop] = JSON.stringify(value); } } else { tag[prop] = value; } } else if (value !== void 0) { const str = String(value); const isMeta = tag.tag === \"meta\" && key === \"content\"; tag.props[key] = str === \"true\" || str === \"\" ? isData || isMeta ? str : true : !value && isData && str === \"false\" ? \"false\" : value; } } return tag; } function resolveHeadInput(input, propResolvers) { let resolve; if (propResolvers.length) { resolve = (key, val) => { for (let i = 0; i < propResolvers.length; i++) val = propResolvers[i](key, val); return val; }; input = resolve(void 0, input); } return walkResolver(input, resolve); } function normalizeTag(tagName, _input) { const input = typeof _input === \"object\" && typeof _input !== \"function\" ? _input : { [tagName === \"script\" || tagName === \"noscript\" || tagName === \"style\" ? \"innerHTML\" : \"textContent\"]: _input }; const tag = normalizeProps({ tag: tagName, props: {} }, input); if (tag.key && DupeableTags.has(tag.tag)) tag.props[\"data-hid\"] = tag._h = tag.key; if (tag.tag === \"script\" && typeof tag.innerHTML === \"object\") { tag.innerHTML = JSON.stringify(tag.innerHTML); tag.props.type = tag.props.type || \"application/json\"; } if (Array.isArray(tag.props.content)) { const tags = []; for (const content of tag.props.content) { tags.push({ ...tag, props: { ...tag.props, content } }); } return tags; } return tag; } function pushNormalizedTag(tags, tag) { if (Array.isArray(tag)) { for (const t of tag) tags.push(t); } else { tags.push(tag); } } function normalizeEntryToTags(input, propResolvers) { if (!input) return []; if (typeof input === \"function\") input = input(); input = resolveHeadInput(input, propResolvers); const tags = []; for (const key in input) { const value = input[key]; if (value !== void 0) { if (Array.isArray(value)) { for (const v of value) pushNormalizedTag(tags, normalizeTag(key, v)); } else { pushNormalizedTag(tags, normalizeTag(key, value)); } } } return tags; } const LT_RE = / a._w === b._w ? a._p - b._p : a._w - b._w; const DEFAULT_TAG_WEIGHT = () => 100; function isEmptyProps(props) { for (const _ in props) return false; return true; } const TAG_MUTATING_HOOK_RE = /^tags:|:render/; function syncEntryHookCache(head, hooks) { const count = (hooks[\"entries:resolve\"]?.length || 0) + (hooks[\"entries:normalize\"]?.length || 0); if (head._h !== count) { head._h = count; for (const entry of head.entries.values()) delete entry._tags; } } function cloneTagsInPlace(tags) { for (let i = 0; i < tags.length; i++) { const t = tags[i]; const props = { ...t.props }; if (props.class instanceof Set) props.class = new Set(props.class); if (props.style instanceof Map) props.style = new Map(props.style); tags[i] = { ...t, props }; } } function valuesToTags(ctx, sortFlatMeta) { const tags = ctx.tags; let w = 0; for (const value of ctx.tagMap.values()) { if (Array.isArray(value)) { for (const tag of value) tags[w++] = tag; } else { tags[w++] = value; } } tags.length = w; if (sortFlatMeta) tags.sort(sortTags); } function dedupeTags(ctx) { let hasFlatMeta = false; for (const next of ctx.tags.sort(sortTags)) { const k = next._d || hashTag(next); if (!k) continue; const prev = ctx.tagMap.get(k); if (!prev) { ctx.tagMap.set(k, next); continue; } const strategy = next.tagDuplicateStrategy || (UsesMergeStrategy.has(next.tag) ? \"merge\" : null) || (next.key && next.key === prev.key ? \"merge\" : null); if (strategy === \"merge\") { const props = { ...prev.props }; for (const p in next.props) { props[p] = p === \"style\" ? new Map([...prev.props.style || new Map(), ...next.props[p]]) : p === \"class\" ? new Set([...prev.props.class || [], ...next.props[p]]) : next.props[p]; } ctx.tagMap.set(k, { ...next, props }); } else if (next._p >> 10 === prev._p >> 10 && next.tag === \"meta\" && isMetaArrayDupeKey(k)) { ctx.tagMap.set(k, Object.assign([...Array.isArray(prev) ? prev : [prev], next], next)); hasFlatMeta = true; } else if (next._w === prev._w ? next._p > prev._p : next._w < prev._w) { ctx.tagMap.set(k, next); } } return hasFlatMeta; } function resolveTitleTemplate(ctx, head) { const title = ctx.tagMap.get(\"title\"); const tpl = ctx.tagMap.get(\"titleTemplate\"); head._title = title?.textContent; if (!tpl) return; const fn = tpl.textContent; head._titleTemplate = fn; if (!fn) return; let v = typeof fn === \"function\" ? fn(title?.textContent) : fn; if (typeof v === \"string\" && !head.plugins.has(\"template-params\")) v = v.replace(\"%s\", title?.textContent || \"\"); if (title) { v === null ? ctx.tagMap.delete(\"title\") : ctx.tagMap.set(\"title\", { ...title, textContent: v }); } else { ctx.tagMap.set(\"titleTemplate\", { ...tpl, tag: \"title\", textContent: v }); } } function sanitizeTagsInPlace(tags) { let w = 0; for (let t of tags) { const { innerHTML, tag, props } = t; if (!ValidHeadTags.has(tag) || isEmptyProps(props) && !hasContent(innerHTML) && !hasContent(t.textContent)) continue; if (tag === \"meta\") { if (!hasContent(props.content) && !props[\"http-equiv\"] && !props.charset) continue; } if (tag === \"script\" && (innerHTML || t.textContent)) { const type = String(props.type); const isJsonLike = type.endsWith(\"json\") || type === \"importmap\" || type === \"speculationrules\"; const escape = (content) => isJsonLike ? (typeof content === \"string\" ? content : JSON.stringify(content)).replace(LT_RE, \"\\\\u003C\") : typeof content === \"string\" ? content.replace(SCRIPT_END_RE, \"<\\\\/script\") : content; t = { ...t }; if (innerHTML) t.innerHTML = escape(innerHTML); if (t.textContent) t.textContent = escape(t.textContent); t._d = dedupeKey(t); } tags[w++] = t; } tags.length = w; return tags; } function resolveTags(head, options) { const weightFn = options?.tagWeight ?? head.resolvedOptions._tagWeight ?? DEFAULT_TAG_WEIGHT; const ctx = { tagMap: new Map(), tags: [] }; const hooks = head.hooks?._hooks || {}; syncEntryHookCache(head, hooks); for (const e of head.entries.values()) { if (e._pending !== void 0) { e.input = e._pending; delete e._pending; delete e._tags; delete e._precomputedTags; } } let entries; if (hooks[\"entries:resolve\"]?.length || hooks[\"entries:normalize\"]?.length) { entries = [...head.entries.values()]; if (hooks[\"entries:resolve\"]?.length) callHook(head, \"entries:resolve\", { entries, ...ctx }); } syncEntryHookCache(head, hooks); for (const e of entries || head.entries.values()) { let tags = e._tags; if (!tags) { if (e._precomputedTags && weightFn === head.resolvedOptions._tagWeight && !hooks[\"entries:normalize\"]?.length && !hooks[\"entries:resolve\"]?.length && (!e.options || isEmptyProps(e.options))) { tags = e._precomputedTags; } else { tags = normalizeEntryToTags(e.input, head.resolvedOptions.propResolvers || []); if (e.options && !isEmptyProps(e.options)) { for (const t of tags) Object.assign(t, e.options); } if (hooks[\"entries:normalize\"]?.length) { const normalizeCtx = { tags, entry: e }; callHook(head, \"entries:normalize\", normalizeCtx); tags = normalizeCtx.tags; } for (let i = 0; i < tags.length; i++) { const t = tags[i]; t._w = weightFn(t); t._p = (e._i << 10) + i; t._d = dedupeKey(t); if (!t._d) t._h = hashTag(t); } e._tags = tags; } } ctx.tags.push(...tags); } for (const name in hooks) { if (hooks[name]?.length && TAG_MUTATING_HOOK_RE.test(name)) { cloneTagsInPlace(ctx.tags); break; } } const hasFlatMeta = dedupeTags(ctx); resolveTitleTemplate(ctx, head); valuesToTags(ctx, hasFlatMeta); callHook(head, \"tags:beforeResolve\", ctx); callHook(head, \"tags:resolve\", ctx); callHook(head, \"tags:afterResolve\", ctx); return sanitizeTagsInPlace(ctx.tags); } const WHITESPACE_RE = /\\s+/; function createDomRenderer(options = {}) { return (head) => _renderDOMHead(head, options); } function hasPendingEntries(head) { for (const entry of head.entries.values()) { if (entry._pending !== void 0) return true; } return false; } function createDomState(head, dom) { const state = { _d: dom, _t: dom.title, _e: new Map([[\"htmlAttrs\", dom.documentElement], [\"bodyAttrs\", dom.body]]), _p: {}, _s: {}, _l: new Map() }; for (const entry of head.entries.values()) { if (entry._o !== void 0) { const orig = entry._o; for (const t of [\"bodyAttrs\", \"htmlAttrs\"]) { const cls = orig[t]?.class; if (typeof cls === \"string\") { const $el = state._e.get(t); for (const c of cls.split(WHITESPACE_RE)) { if (c) state._p[`${t}:attr:class:${c}`] = () => $el.classList.remove(c); } } } } } return state; } function _renderDOMHead(head, options = {}) { const dom = options.document || head.resolvedOptions.document; const activeState = head._dom; if (!dom || head._du || activeState && activeState._d === dom && !head.dirty && !hasPendingEntries(head)) return false; const defaultView = dom.defaultView; head._du = true; let didRender = false; try { let track = function(key, fn, fresh) { renderState._s[key] = !fresh && previous[key] || fn; delete previous[key]; }, trackEvent = function(id, k, ev, source, $el, target) { const key = `${id}:event:${k}`; const prev = renderState._l.get(key); if (prev && prev[0] === target && prev[1] === ev && prev[2] === source) { track(key, prev[4]); return; } prev?.[4](); const dk = `data-${k}`; const handler = ((e) => source.call($el, e)); const cleanup = () => { target.removeEventListener(ev, handler); if ($el.getAttribute(dk) === \"\") $el.removeAttribute(dk); if (renderState._l.get(key)?.[3] === handler) renderState._l.delete(key); }; target.addEventListener(ev, handler); renderState._l.set(key, [target, ev, source, handler, cleanup]); $el.setAttribute(dk, \"\"); track(key, cleanup, true); }, trackCtx = function({ id, $el, tag }) { renderState._e.set(id, $el); if (!tag.tag.endsWith(\"Attrs\")) { const text = tag.textContent; if (text != null && text !== \"\") { if (text !== $el.textContent) $el.textContent = text; track(`${id}:text`, () => { if ($el.textContent === text) $el.textContent = \"\"; }, true); } const html = tag.innerHTML; if (html != null && html !== \"\") { if (html !== $el.innerHTML) $el.innerHTML = html; track(`${id}:html`, () => { if ($el.innerHTML === html) $el.innerHTML = \"\"; }, true); } const elKey = `${id}:el`; track(elKey, previous[elKey] || (() => { $el?.remove(); renderState._e.delete(id); })); } for (const k in tag.props) { const v = tag.props[k]; if (k[0] === \"o\" && k[1] === \"n\" && typeof v === \"function\") { const ev = k.slice(2); if ($el?.dataset?.[`${k}fired`]) v.call($el, new (defaultView?.Event || Event)(ev)); trackEvent(id, k, ev, v, $el, tag.tag === \"bodyAttrs\" && defaultView ? defaultView : $el); continue; } const ck = `${id}:attr:${k}`; if (k === \"class\" && v) { for (const c of v) { const key = `${ck}:${c}`; track(key, previous[key] || (() => $el.classList.remove(c))); if (!$el.classList.contains(c)) $el.classList.add(c); } } else if (k === \"style\" && v) { for (const [sk, sv] of v) { const key = `${ck}:${sk}`; track(key, previous[key] || (() => $el.style.removeProperty(sk))); $el.style.setProperty(sk, sv); } } else if (v !== false && v !== null) { if ($el.getAttribute(k) !== v) $el.setAttribute(k, v === true ? \"\" : String(v)); track(ck, previous[ck] || (() => $el.removeAttribute(k))); } } }; const beforeRenderCtx = { shouldRender: true, tags: [] }; callHook(head, \"dom:beforeRender\", beforeRenderCtx); if (!beforeRenderCtx.shouldRender) return false; let state = activeState; if (state?._d !== dom) { if (state) { for (const k in state._s) state._s[k](); for (const k in state._p) state._p[k](); state._s = state._p = {}; state._e.clear(); state._l.clear(); } state = void 0; } if (!state) { state = createDomState(head, dom); } else { state._p = state._s; } state._s = {}; const renderState = state; const previous = renderState._p; const pending = []; const frag = {}; head.dirty = false; const rawTags = resolveTags(head, options.tagWeight ? { tagWeight: options.tagWeight } : void 0); const tags = []; const dupeKeyCounter = {}; for (const tag of rawTags) { const count = dupeKeyCounter[tag._d] || 0; const id = (count ? `${tag._d}:${count}` : tag._d) || tag._h; const ctx = { tag, id, shouldRender: true }; if (tag.tag === \"meta\" && tag._d && isMetaArrayDupeKey(tag._d)) dupeKeyCounter[tag._d] = count + 1; tags.push(ctx); if (tag.tag === \"title\") { dom.title = tag.textContent; track(\"title:\", () => dom.title = renderState._t); continue; } ctx.$el = renderState._e.get(id); if (ctx.$el) trackCtx(ctx); else if (HasElementTags.has(tag.tag)) pending.push(ctx); } if (pending.length) { const tracked = new Set(renderState._e.values()); for (const el of [...dom.body.children, ...dom.head.children]) { const elTag = el.tagName.toLowerCase(); if (!HasElementTags.has(elTag) || tracked.has(el)) continue; const props = { innerHTML: el.innerHTML }; for (const n of el.getAttributeNames()) props[n] = el.getAttribute(n); const next = normalizeProps({ tag: elTag, props: {} }, props); next.key = el.getAttribute(\"data-hid\") || void 0; const dedupe = dedupeKey(next) || hashTag(next); let k = dedupe; let c = 1; while (renderState._e.has(k)) k = `${dedupe}:${c++}`; renderState._e.set(k, el); } } for (const ctx of pending) { const found = renderState._e.get(ctx.id); ctx.$el = found || dom.createElement(ctx.tag.tag); trackCtx(ctx); if (!found) (frag[ctx.tag.tagPosition || \"head\"] ??= dom.createDocumentFragment()).appendChild(ctx.$el); } if (frag.head) dom.head.appendChild(frag.head); if (frag.bodyOpen) dom.body.insertBefore(frag.bodyOpen, dom.body.firstChild); if (frag.bodyClose) dom.body.appendChild(frag.bodyClose); for (const k in previous) previous[k](); head._dom = renderState; didRender = true; callHook(head, \"dom:rendered\", { renders: tags }); } catch (e) { head.dirty = true; throw e; } finally { head._du = false; } if (didRender && (head.dirty || hasPendingEntries(head))) _renderDOMHead(head, options); return didRender; } function registerPlugin(head, p) { if (typeof p === \"function\" && p.key && head.plugins.has(p.key)) return; const plugin = typeof p === \"function\" ? p(head) : p; const key = plugin.key || String(head.plugins.size + 1); if (!head.plugins.get(key)) { head.plugins.set(key, plugin); for (const k in plugin.hooks || {}) head.hooks?.hook(k, plugin.hooks[k]); } } function createUnhead(renderer, resolvedOptions = {}) { const ssr = !resolvedOptions.document; const entries = new Map(); const plugins = new Map(); const head = { _entryCount: 1, _h: 0, plugins, resolvedOptions, ssr, entries, hooks: void 0, render: () => renderer(head), use: (p) => registerPlugin(head, p), push(input, _options) { const _i = _options?._index ?? head._entryCount++; const options = _options ? { ..._options } : {}; delete options.head; delete options.onRendered; delete options._index; const entry = { _i, input, options }; entries.set(_i, entry); const active = { _i, dispose() { entries.delete(_i); }, patch(input2) { if (ssr) { entry.input = input2; delete entry._tags; } else { entry._pending = input2; } if (!entries.has(_i)) entries.set(_i, entry); } }; return active; } }; resolvedOptions.init?.forEach((e) => e && head.push(e)); return head; } const DEFAULT_STREAM_KEY = \"__unhead__\"; function init(options = {}) { const { streamKey = DEFAULT_STREAM_KEY } = options; const win = \u0074ypeof window !== \"undefined\" ? window : void 0; if (!win) return; const queue = win[streamKey]; if (queue?._head) return queue._head; const doc = typeof document !== \"undefined\" ? document : void 0; const head = createUnhead(createDomRenderer(), { document: doc }); function pushStreamed(entry) { const active = head.push(entry); const stored = head.entries.get(active._i); if (stored) stored._streamed = true; } function pushBatch(entries) { const nested = head._b; head._b = true; try { for (const entry of entries) { pushStreamed(entry); } } finally { head._b = nested; if (!nested) { head.dirty = true; head.render(); } } } if (queue?._q?.length) { pushBatch(queue._q.flat()); } win[streamKey] = { _q: [], _head: head, push: pushBatch }; return head; } exports.init = init; return exports; })({});__unhead_iife__.init();"; export const streamingIifeSize = 21331;