@ -15,10 +15,14 @@ import {
} from '../../runtime.js' ;
import { clsx } from '../../../shared/attributes.js' ;
import { set _class } from './class.js' ;
import { NAMESPACE _HTML } from '../../../../constants.js' ;
export const CLASS = Symbol ( 'class' ) ;
export const STYLE = Symbol ( 'style' ) ;
const IS _CUSTOM _ELEMENT = Symbol ( 'is custom element' ) ;
const IS _HTML = Symbol ( 'is html' ) ;
/ * *
* The value / checked attribute in the template actually corresponds to the defaultValue property , so we need
* to remove it upon hydration to avoid a bug when someone resets the form value .
@ -63,8 +67,7 @@ export function remove_input_defaults(input) {
* @ param { any } value
* /
export function set _value ( element , value ) {
// @ts-expect-error
var attributes = ( element . _ _attributes ? ? = { } ) ;
var attributes = get _attributes ( element ) ;
if (
attributes . value ===
@ -87,8 +90,7 @@ export function set_value(element, value) {
* @ param { boolean } checked
* /
export function set _checked ( element , checked ) {
// @ts-expect-error
var attributes = ( element . _ _attributes ? ? = { } ) ;
var attributes = get _attributes ( element ) ;
if (
attributes . checked ===
@ -151,8 +153,7 @@ export function set_default_value(element, value) {
* @ param { boolean } [ skip _warning ]
* /
export function set _attribute ( element , attribute , value , skip _warning ) {
// @ts-expect-error
var attributes = ( element . _ _attributes ? ? = { } ) ;
var attributes = get _attributes ( element ) ;
if ( hydrating ) {
attributes [ attribute ] = element . getAttribute ( attribute ) ;
@ -261,20 +262,15 @@ export function set_custom_element_data(node, prop, value) {
* @ param { Record < string | symbol , any > | undefined } prev
* @ param { Record < string | symbol , any > } next New attributes - this function mutates this object
* @ param { string } [ css _hash ]
* @ param { boolean } [ preserve _attribute _case ]
* @ param { boolean } [ is _custom _element ]
* @ param { boolean } [ skip _warning ]
* @ returns { Record < string , any > }
* /
export function set _attributes (
element ,
prev ,
next ,
css _hash ,
preserve _attribute _case = false ,
is _custom _element = false ,
skip _warning = false
) {
export function set _attributes ( element , prev , next , css _hash , skip _warning = false ) {
var attributes = get _attributes ( element ) ;
var is _custom _element = attributes [ IS _CUSTOM _ELEMENT ] ;
var preserve _attribute _case = ! attributes [ IS _HTML ] ;
// If we're hydrating but the custom element is from Svelte, and it already scaffolded,
// then it might run block logic in hydration mode, which we have to prevent.
let is _hydrating _custom _element = hydrating && is _custom _element ;
@ -299,9 +295,6 @@ export function set_attributes(
var setters = get _setters ( element ) ;
// @ts-expect-error
var attributes = /** @type {Record<string, unknown>} **/ ( element . _ _attributes ? ? = { } ) ;
// since key is captured we use const
for ( const key in next ) {
// let instead of var because referenced in a closure
@ -432,7 +425,7 @@ export function set_attributes(
// @ts-ignore
element [ name ] = value ;
} else if ( typeof value !== 'function' ) {
set _attribute ( element , name , value );
set _attribute ( element , name , value , skip _warning );
}
}
if ( key === 'style' && '__styles' in element ) {
@ -448,6 +441,20 @@ export function set_attributes(
return current ;
}
/ * *
*
* @ param { Element } element
* /
function get _attributes ( element ) {
return /** @type {Record<string | symbol, unknown>} **/ (
// @ts-expect-error
element . _ _attributes ? ? = {
[ IS _CUSTOM _ELEMENT ] : element . nodeName . includes ( '-' ) ,
[ IS _HTML ] : element . namespaceURI === NAMESPACE _HTML
}
) ;
}
/** @type {Map<string, string[]>} */
var setters _cache = new Map ( ) ;