{"version":3,"file":"vbQ7zBOk.mjs","sources":["../../../../../../node_modules/svelte/src/internal/client/dom/blocks/snippet.js"],"sourcesContent":["/** @import { Snippet } from 'svelte' */\n/** @import { Effect, TemplateNode } from '#client' */\n/** @import { Getters } from '#shared' */\nimport { EFFECT_TRANSPARENT, ELEMENT_NODE } from '#client/constants';\nimport { branch, block, destroy_effect, teardown } from '../../reactivity/effects.js';\nimport {\n\tdev_current_component_function,\n\tset_dev_current_component_function\n} from '../../context.js';\nimport { hydrate_next, hydrate_node, hydrating } from '../hydration.js';\nimport { create_fragment_from_html } from '../reconciler.js';\nimport { assign_nodes } from '../template.js';\nimport * as w from '../../warnings.js';\nimport * as e from '../../errors.js';\nimport { DEV } from 'esm-env';\nimport { get_first_child, get_next_sibling } from '../operations.js';\nimport { noop } from '../../../shared/utils.js';\nimport { prevent_snippet_stringification } from '../../../shared/validate.js';\n\n/**\n * @template {(node: TemplateNode, ...args: any[]) => void} SnippetFn\n * @param {TemplateNode} node\n * @param {() => SnippetFn | null | undefined} get_snippet\n * @param {(() => any)[]} args\n * @returns {void}\n */\nexport function snippet(node, get_snippet, ...args) {\n\tvar anchor = node;\n\n\t/** @type {SnippetFn | null | undefined} */\n\t// @ts-ignore\n\tvar snippet = noop;\n\n\t/** @type {Effect | null} */\n\tvar snippet_effect;\n\n\tblock(() => {\n\t\tif (snippet === (snippet = get_snippet())) return;\n\n\t\tif (snippet_effect) {\n\t\t\tdestroy_effect(snippet_effect);\n\t\t\tsnippet_effect = null;\n\t\t}\n\n\t\tif (DEV && snippet == null) {\n\t\t\te.invalid_snippet();\n\t\t}\n\n\t\tsnippet_effect = branch(() => /** @type {SnippetFn} */ (snippet)(anchor, ...args));\n\t}, EFFECT_TRANSPARENT);\n\n\tif (hydrating) {\n\t\tanchor = hydrate_node;\n\t}\n}\n\n/**\n * In development, wrap the snippet function so that it passes validation, and so that the\n * correct component context is set for ownership checks\n * @param {any} component\n * @param {(node: TemplateNode, ...args: any[]) => void} fn\n */\nexport function wrap_snippet(component, fn) {\n\tconst snippet = (/** @type {TemplateNode} */ node, /** @type {any[]} */ ...args) => {\n\t\tvar previous_component_function = dev_current_component_function;\n\t\tset_dev_current_component_function(component);\n\n\t\ttry {\n\t\t\treturn fn(node, ...args);\n\t\t} finally {\n\t\t\tset_dev_current_component_function(previous_component_function);\n\t\t}\n\t};\n\n\tprevent_snippet_stringification(snippet);\n\n\treturn snippet;\n}\n\n/**\n * Create a snippet programmatically\n * @template {unknown[]} Params\n * @param {(...params: Getters<Params>) => {\n *   render: () => string\n *   setup?: (element: Element) => void | (() => void)\n * }} fn\n * @returns {Snippet<Params>}\n */\nexport function createRawSnippet(fn) {\n\t// @ts-expect-error the types are a lie\n\treturn (/** @type {TemplateNode} */ anchor, /** @type {Getters<Params>} */ ...params) => {\n\t\tvar snippet = fn(...params);\n\n\t\t/** @type {Element} */\n\t\tvar element;\n\n\t\tif (hydrating) {\n\t\t\telement = /** @type {Element} */ (hydrate_node);\n\t\t\thydrate_next();\n\t\t} else {\n\t\t\tvar html = snippet.render().trim();\n\t\t\tvar fragment = create_fragment_from_html(html);\n\t\t\telement = /** @type {Element} */ (get_first_child(fragment));\n\n\t\t\tif (DEV && (get_next_sibling(element) !== null || element.nodeType !== ELEMENT_NODE)) {\n\t\t\t\tw.invalid_raw_snippet_render();\n\t\t\t}\n\n\t\t\tanchor.before(element);\n\t\t}\n\n\t\tconst result = snippet.setup?.(element);\n\t\tassign_nodes(element, element);\n\n\t\tif (typeof result === 'function') {\n\t\t\tteardown(result);\n\t\t}\n\t};\n}\n"],"names":["snippet","node","get_snippet","args","anchor","noop","snippet_effect","block","destroy_effect","branch","EFFECT_TRANSPARENT","hydrating","hydrate_node","createRawSnippet","fn","params","element","hydrate_next","html","fragment","create_fragment_from_html","get_first_child","result","assign_nodes","teardown"],"mappings":"gHA0BO,SAASA,EAAQC,EAAMC,KAAgBC,EAAM,CACnD,IAAIC,EAASH,EAITD,EAAUK,EAGVC,EAEJC,EAAM,IAAM,CACPP,KAAaA,EAAUE,EAAW,KAElCI,IACHE,EAAeF,CAAc,EAC7BA,EAAiB,MAOlBA,EAAiBG,EAAO,IAAgCT,EAASI,EAAQ,GAAGD,CAAI,CAAC,EAClF,EAAGO,CAAkB,EAEjBC,IACHP,EAASQ,EAEX,CAkCO,SAASC,EAAiBC,EAAI,CAEpC,MAAO,CAA6BV,KAA0CW,IAAW,CACxF,IAAIf,EAAUc,EAAG,GAAGC,CAAM,EAGtBC,EAEJ,GAAIL,EACHK,EAAkCJ,EAClCK,EAAY,MACN,CACN,IAAIC,EAAOlB,EAAQ,OAAM,EAAG,KAAI,EAC5BmB,EAAWC,EAA0BF,CAAI,EAC7CF,EAAkCK,EAAgBF,CAAQ,EAM1Df,EAAO,OAAOY,CAAO,CACtB,CAEA,MAAMM,EAAStB,EAAQ,QAAQgB,CAAO,EACtCO,EAAaP,EAASA,CAAO,EAEzB,OAAOM,GAAW,YACrBE,EAASF,CAAM,CAEjB,CACD","x_google_ignoreList":[0]}