@ -1,21 +1,27 @@
/** @import { Effect, TemplateNode } from '#client' */
/** @import { Effect, TemplateNode } from '#client' */
import { FILENAME , HYDRATION _ERROR } from '../../../../constants.js' ;
/** @import {} from 'trusted-types' */
import {
FILENAME ,
HYDRATION _ERROR ,
NAMESPACE _SVG ,
NAMESPACE _MATHML
} from '../../../../constants.js' ;
import { remove _effect _dom , template _effect } from '../../reactivity/effects.js' ;
import { remove _effect _dom , template _effect } from '../../reactivity/effects.js' ;
import { hydrate _next , hydrate _node , hydrating , set _hydrate _node } from '../hydration.js' ;
import { hydrate _next , hydrate _node , hydrating , set _hydrate _node } from '../hydration.js' ;
import { create _fragment _from _html } from '../reconciler.js' ;
import { assign _nodes } from '../template.js' ;
import { assign _nodes } from '../template.js' ;
import * as w from '../../warnings.js' ;
import * as w from '../../warnings.js' ;
import { hash , sanitize _location } from '../../../../utils.js' ;
import { hash , sanitize _location } from '../../../../utils.js' ;
import { DEV } from 'esm-env' ;
import { DEV } from 'esm-env' ;
import { dev _current _component _function } from '../../context.js' ;
import { dev _current _component _function } from '../../context.js' ;
import { get_first _child , get _next _sibling } from '../operations.js' ;
import { create_element , get_first _child , get _next _sibling } from '../operations.js' ;
import { active _effect } from '../../runtime.js' ;
import { active _effect } from '../../runtime.js' ;
import { COMMENT _NODE } from '#client/constants' ;
import { COMMENT _NODE } from '#client/constants' ;
/ * *
/ * *
* @ param { Element } element
* @ param { Element } element
* @ param { string | null } server _hash
* @ param { string | null } server _hash
* @ param { string } value
* @ param { string | TrustedHTML } value
* /
* /
function check _hash ( element , server _hash , value ) {
function check _hash ( element , server _hash , value ) {
if ( ! server _hash || server _hash === hash ( String ( value ? ? '' ) ) ) return ;
if ( ! server _hash || server _hash === hash ( String ( value ? ? '' ) ) ) return ;
@ -35,7 +41,7 @@ function check_hash(element, server_hash, value) {
/ * *
/ * *
* @ param { Element | Text | Comment } node
* @ param { Element | Text | Comment } node
* @ param { ( ) => string } get _value
* @ param { ( ) => string | TrustedHTML } get _value
* @ param { boolean } [ svg ]
* @ param { boolean } [ svg ]
* @ param { boolean } [ mathml ]
* @ param { boolean } [ mathml ]
* @ param { boolean } [ skip _warning ]
* @ param { boolean } [ skip _warning ]
@ -44,6 +50,7 @@ function check_hash(element, server_hash, value) {
export function html ( node , get _value , svg = false , mathml = false , skip _warning = false ) {
export function html ( node , get _value , svg = false , mathml = false , skip _warning = false ) {
var anchor = node ;
var anchor = node ;
/** @type {string | TrustedHTML} */
var value = '' ;
var value = '' ;
template _effect ( ( ) => {
template _effect ( ( ) => {
@ -92,18 +99,18 @@ export function html(node, get_value, svg = false, mathml = false, skip_warning
return ;
return ;
}
}
var html = value + '' ;
if ( svg ) html = ` <svg> ${ html } </svg> ` ;
else if ( mathml ) html = ` <math> ${ html } </math> ` ;
// Don't use create_fragment_with_script_from_html here because that would mean script tags are executed.
// Don't use create_fragment_with_script_from_html here because that would mean script tags are executed.
// @html is basically `.innerHTML = ...` and that doesn't execute scripts either due to security reasons.
// @html is basically `.innerHTML = ...` and that doesn't execute scripts either due to security reasons.
/** @type {DocumentFragment | Element} */
// Use a <template>, <svg>, or <math> wrapper depending on context. If value is a TrustedHTML object,
var node = create _fragment _from _html ( html ) ;
// it will be assigned directly to innerHTML without coercion — this allows {@html policy.createHTML(...)} to work.
var ns = svg ? NAMESPACE _SVG : mathml ? NAMESPACE _MATHML : undefined ;
var wrapper = /** @type {HTMLTemplateElement | SVGElement | MathMLElement} */ (
create _element ( svg ? 'svg' : mathml ? 'math' : 'template' , ns )
) ;
wrapper . innerHTML = /** @type {any} */ ( value ) ;
if ( svg || mathml ) {
/** @type {DocumentFragment | Element} */
node = /** @type {Element} */ ( get _first _child ( node ) ) ;
var node = svg || mathml ? wrapper : /** @type {HTMLTemplateElement} */ ( wrapper ) . content ;
}
assign _nodes (
assign _nodes (
/** @type {TemplateNode} */ ( get _first _child ( node ) ) ,
/** @type {TemplateNode} */ ( get _first _child ( node ) ) ,