@ -1,46 +1,109 @@
import { current _hydration _fragment , get _hydration _fragment } from './hydration.js' ;
import { get _descriptor } from './utils.js' ;
/** This file is also loaded in server environments, so we need guard against eagerly accessing browser globals */
const has _browser _globals = typeof window !== 'undefined' ;
// We cache the Node and Element prototype methods, so that subsequent calls-sites are monomorphic rather
// than megamorphic.
const node _prototype = /** @type {Node} */ ( has _browser _globals ? Node . prototype : { } ) ;
const element _prototype = /** @type {Element} */ ( has _browser _globals ? Element . prototype : { } ) ;
const text _prototype = /** @type {Text} */ ( has _browser _globals ? Text . prototype : { } ) ;
const map _prototype = Map . prototype ;
const append _child _method = node _prototype . appendChild ;
const clone _node _method = node _prototype . cloneNode ;
const map _set _method = map _prototype . set ;
const map _get _method = map _prototype . get ;
const map _delete _method = map _prototype . delete ;
// @ts-expect-error improve perf of expando on DOM events
element _prototype . _ _click = undefined ;
// @ts-expect-error improve perf of expando on DOM text updates
text _prototype . _ _nodeValue = ' ' ;
// @ts-expect-error improve perf of expando on DOM className updates
element _prototype . _ _className = '' ;
const first _child _get = /** @type {(this: Node) => ChildNode | null} */ (
// We cache the Node and Element prototype methods, so that we can avoid doing
// expensive prototype chain lookups.
/** @type {Node} */
var node _prototype ;
/** @type {Element} */
var element _prototype ;
/** @type {Text} */
var text _prototype ;
/** @type {Map<any, any>} */
var map _prototype ;
/** @type {typeof Node.prototype.appendChild} */
var append _child _method ;
/** @type {typeof Node.prototype.cloneNode} */
var clone _node _method ;
/** @type {typeof Map.prototype.set} */
var map _set _method ;
/** @type {typeof Map.prototype.get} */
var map _get _method ;
/** @type {typeof Map.prototype.delete} */
var map _delete _method ;
/** @type {(this: Node) => ChildNode | null} */
var first _child _get ;
/** @type {(this: Node) => ChildNode | null} */
var next _sibling _get ;
/** @type {(this: Node, text: string ) => void} */
var text _content _set ;
/** @type {(this: Element, class_name: string) => void} */
var class _name _set ;
// export these for reference in the compiled code, making global name deduplication unnecessary
/ * *
* @ type { Window }
* /
export var $window ;
/ * *
* @ type { Document }
* /
export var $document ;
/ * *
* Initialize these lazily to avoid issues when using the runtime in a server context
* where these globals are not available while avoiding a separate server entry point
* /
export function init _operations ( ) {
if ( node _prototype !== undefined ) {
return ;
}
node _prototype = Node . prototype ;
element _prototype = Element . prototype ;
text _prototype = Text . prototype ;
map _prototype = Map . prototype ;
append _child _method = node _prototype . appendChild ;
clone _node _method = node _prototype . cloneNode ;
map _set _method = map _prototype . set ;
map _get _method = map _prototype . get ;
map _delete _method = map _prototype . delete ;
$window = window ;
$document = document ;
// the following assignments improve perf of lookups on DOM nodes
// @ts-expect-error
element _prototype . _ _click = undefined ;
// @ts-expect-error
text _prototype . _ _nodeValue = ' ' ;
// @ts-expect-error
element _prototype . _ _className = '' ;
first _child _get = /** @type {(this: Node) => ChildNode | null} */ (
// @ts-ignore
has _browser _globals ? get _descriptor ( node _prototype , 'firstChild' ) . get : null
) ;
get _descriptor ( node _prototype , 'firstChild' ) . get
) ;
const next _sibling _get = /** @type {(this: Node) => ChildNode | null} */ (
next _sibling _get = /** @type {(this: Node) => ChildNode | null} */ (
// @ts-ignore
has _browser _globals ? get _descriptor ( node _prototype , 'nextSibling' ) . get : null
) ;
get _descriptor ( node _prototype , 'nextSibling' ) . get
) ;
const text _content _set = /** @type {(this: Node, text: string ) => void} */ (
text _content _set = /** @type {(this: Node, text: string ) => void} */ (
// @ts-ignore
has _browser _globals ? get _descriptor ( node _prototype , 'textContent' ) . set : null
) ;
get _descriptor ( node _prototype , 'textContent' ) . set
) ;
const class _name _set = /** @type {(this: Element, class_name: string) => void} */ (
class _name _set = /** @type {(this: Element, class_name: string) => void} */ (
// @ts-ignore
has _browser _globals ? get _descriptor ( element _prototype , 'className' ) . set : null
) ;
get _descriptor ( element _prototype , 'className' ) . set
) ;
}
/ * *
* @ template { Element } E
@ -191,7 +254,3 @@ function capture_fragment_from_node(node) {
}
return node ;
}
// export these for reference in the compiled code, making global name deduplication unnecessary
export const $window = has _browser _globals ? window : undefined ;
export const $document = has _browser _globals ? document : undefined ;