export const SvgNamespace = "http://www.w3.org/2000/svg" ; export const XlinkNamespace = "http://www.w3.org/1999/xlink" ; export const XmlNamespace = "http://www.w3.org/XML/1998/namespace" ; declare global { interface Element { closest ( selector ) : Element | null ; } } const ElementPrototype = Element . prototype ; /**
 * Matches polyfill.
 *
 * Edge14, Android 4.4
 */ if ( ElementPrototype . matches === undefined ) { ElementPrototype . matches = ElementPrototype . webkitMatchesSelector || ElementPrototype . msMatchesSelector ; } /**
 * Flags shared between ElementDescriptor, VNode, ComponentDescriptor and Component objects.
 *
 * They can be easily copied with a binary or operator from object with one type to another with different type. For
 * example, when creating VNode from ElementDesciptor, we are marking flags like `ElementDesciptor` directly on a
 * VNode object.
 *
 * 16-24 bits are reserved for shared flags.
 */ const enum SharedFlags { Svg = 1 << 15 , Canvas2D = 1 << 16 , ElementDescriptor = 1 << 17 , ElementDescriptorUpdateHandler = 1 << 18 , EnabledRecycling = 1 << 19 } /**
 * Element Descriptor flags.
 */ export const enum ElementDescriptorFlags { EnabledCloning = 1 , Svg = SharedFlags . Svg } /**
 * VNode flags.
 */ export const enum VNodeFlags { Text = 1 , Element = 1 << 1 , Component = 1 << 2 , Root = 1 << 3 , ArrayChildren = 1 << 4 , TrackByKeyChildren = 1 << 5 , DynamicShapeAttrs = 1 << 6 , TextInputElement = 1 << 7 , CheckedInputElement = 1 << 8 , InputElement = TextInputElement | CheckedInputElement , KeepAlive = 1 << 9 , BindOnce = 1 << 10 , ImmutableProps = 1 << 11 , UnsafeHTML = 1 << 12 , Svg = SharedFlags . Svg , ElementDescriptor = SharedFlags . ElementDescriptor , ElementDescriptorUpdateHandler = SharedFlags . ElementDescriptorUpdateHandler } /**
 * VNode flags used when DEBUG mode is enabled.
 */ export const enum VNodeDebugFlags { Rendered = 1 , Mounted = 1 << 1 , Attached = 1 << 2 , Detached = 1 << 3 , Disposed = 1 << 4 , DisabledChildrenShapeError = 1 << 5 , DisabledFreeze = 1 << 6 } /**
 * ComponentDescriptor flags.
 */ export const enum ComponentDescriptorFlags { EnabledBackRef = 1 , Svg = SharedFlags . Svg , Canvas2D = SharedFlags . Canvas2D , ElementDescriptor = SharedFlags . ElementDescriptor , EnabledRecycling = SharedFlags . EnabledRecycling } /**
 * Component flags.
 */ export const enum ComponentFlags { Disposed = 1 , Attached = 1 << 1 , Dirty = 1 << 2 , DirtyView = 1 << 3 , UpdateEachFrame = 1 << 4 , InUpdateEachFrameQueue = 1 << 5 , Recycled = 1 << 6 , InUpdateQueue = 1 << 7 , HighPriorityUpdate = 1 << 8 , ImmutableProps = 1 << 9 , Svg = SharedFlags . Svg , Canvas2D = SharedFlags . Canvas2D , ElementDescriptor = SharedFlags . ElementDescriptor , EnabledRecycling = SharedFlags . EnabledRecycling } /**
 * Set HTML attribute.
 */ export function setAttr ( node , key , value ) { if ( key . charCodeAt ( 0 ) !== 120 ) { node . setAttribute ( key , value ) ; } else { if ( "<@KIVI_DEBUG@>" as string !== "DEBUG_DISABLED" ) { if ( key . length <= 3 ) { throw new Error ( `Failed to set attr: invalid attribute "${ key }", attributes starting with letter "x" should` + ` have length 4 or more.` ) ; } } if ( key . charCodeAt ( 1 ) === 109 && key . charCodeAt ( 2 ) === 108 ) { if ( "<@KIVI_DEBUG@>" as string !== "DEBUG_DISABLED" ) { if ( key . charCodeAt ( 3 ) !== 58 ) { throw new Error ( `Failed to set attr: invalid attribute "${ key }", attributes with "xml" prefix should be in` + ` the form "xml:attr".` ) ; } } node . setAttributeNS ( XmlNamespace , key , value ) ; } else if ( key . charCodeAt ( 1 ) === 108 && key . charCodeAt ( 2 ) === 105 ) { if ( "<@KIVI_DEBUG@>" as string !== "DEBUG_DISABLED" ) { if ( key . charCodeAt ( 3 ) !== 110 || key . charCodeAt ( 4 ) !== 107 || key . charCodeAt ( 5 ) !== 58 ) { throw new Error ( `Failed to set attr: invalid attribute "${ key }", attributes with "xli" prefix should be in` + ` the form "xlink:attr".` ) ; } } node . setAttributeNS ( XlinkNamespace , key , value ) ; } else { node . setAttribute ( key , value ) ; } } } /**
 * Find closest element that matches [selector].
 */ export function matchesWithAncestors ( element , selector , sentinel = null ) { while ( element !== sentinel ) { if ( element . matches ( selector ) ) { return element ; } element = element . parentNode as Element ; } return null ; }