{ "version": 3, "sources": ["node_modules/imba/src/imba/dom/core.web.imba"], "sourcesContent": ["import {Flags} from './flags'\nimport {getDeepPropertyDescriptor} from '../utils'\n\nexport const {\n\tEvent,\n\tUIEvent,\n\tMouseEvent,\n\tPointerEvent,\n\tKeyboardEvent,\n\tCustomEvent,\n\tNode,\n\tComment,\n\tText,\n\tElement,\n\tHTMLElement,\n\tHTMLHtmlElement,\n\tHTMLSelectElement,\n\tHTMLInputElement,\n\tHTMLTextAreaElement,\n\tHTMLButtonElement,\n\tHTMLOptionElement,\n\tHTMLScriptElement,\n\tSVGElement,\n\tDocumentFragment,\n\tShadowRoot,\n\tDocument,\n\tWindow,\n\tcustomElements\n} = global.window\n\n\nconst descriptorCache = {}\ndef getDescriptor item,key,cache\n\tif !item\n\t\treturn cache[key] = null\n\n\tif cache[key] !== undefined\n\t\treturn cache[key]\n\t\n\tlet desc = Object.getOwnPropertyDescriptor(item,key)\n\n\tif desc !== undefined or item == SVGElement\n\t\treturn cache[key] = desc or null\n\n\tgetDescriptor(Reflect.getPrototypeOf(item),key,cache)\n\n# export const document = global.window.document\nconst CustomTagConstructors = {}\nconst CustomTagToElementNames = {}\nexport const TYPES = {}\nexport const CUSTOM_TYPES = {}\nexport def get_document\n\tglobal.document\n\nexport def use_window\n\tyes\n\n\n\n# Basic node extensions\n\nconst contextHandler =\n\tdef get target, name\n\t\tlet ctx = target\n\t\tlet val = undefined\n\t\twhile ctx and val == undefined\n\t\t\tif ctx = ctx.#parent\n\t\t\t\tval = ctx[name]\n\t\treturn val\n\n\tdef set target, name, value\n\t\tlet ctx = target\n\t\tlet val = undefined\n\t\twhile ctx and val == undefined\n\t\t\tlet desc = getDeepPropertyDescriptor(ctx,name,Element)\n\t\t\tif desc\n\t\t\t\tctx[name] = value\n\t\t\t\treturn yes\n\t\t\telse \n\t\t\t\tctx = ctx.#parent\n\t\treturn yes\n\nextend class Document\n\tget flags\n\t\tself.documentElement.flags\n\nextend class Node\n\tget #parent\n\t\t##parent or this.parentNode or ##up # FIX\n\n\tget #context\n\t\t##context ||= new Proxy(self,contextHandler)\n\n\tdef #__init__\n\t\tself\n\t\n\tdef #insertChild newnode, refnode\n\t\tnewnode.#insertInto(self,refnode)\n\t\n\tdef #appendChild newnode\n\t\tnewnode.#insertInto(self,null)\n\t\t\n\tdef #replaceChild newnode, oldnode\n\t\tlet res = #insertChild(newnode,oldnode)\n\t\t#removeChild(oldnode)\n\t\treturn res\n\t\t\n\tdef #removeChild node\n\t\tnode.#removeFrom(self)\n\n\t# can override if the element itself wants ot deal with this\n\tdef #insertInto parent, before = null\n\t\tif before\n\t\t\tparent.insertBefore(self,before)\n\t\telse\n\t\t\tparent.appendChild(self)\n\t\treturn self\n\t\t\n\tdef #insertIntoDeopt parent, before\n\t\t# log '#insertIntoDeopt',parent,before\n\t\tif before\n\t\t\tparent.insertBefore(#domNode or self,before)\n\t\telse\n\t\t\tparent.appendChild(#domNode or self)\n\t\treturn self\n\n\tdef #removeFrom parent\n\t\tparent.removeChild(self)\n\t\t\n\tdef #removeFromDeopt parent\n\t\tparent.removeChild(#domNode or self)\n\t\t\n\tdef #replaceWith other, parent\n\t\tparent.#replaceChild(other,self)\n\t\t\n\tdef #replaceWithDeopt other, parent\n\t\tparent.#replaceChild(other,#domNode or self)\n\n\tget #placeholderNode\n\t\t##placeholderNode ||= global.document.createComment(\"placeholder\")\n\n\tset #placeholderNode value\n\t\tlet prev = ##placeholderNode\n\t\t##placeholderNode = value\n\t\tif prev and prev != value and prev.parentNode\n\t\t\tprev.#replaceWith(value)\n\n\tdef #attachToParent\n\t\tlet ph = #domNode\n\t\tlet par = ph and ph.parentNode\n\t\tif ph and par and ph != self\n\t\t\t#domNode = null\n\t\t\t#insertInto(par,ph)\n\t\t\tph.#removeFrom(par)\n\t\tself\n\n\tdef #detachFromParent\n\t\tif #domDeopt =? yes\n\t\t\t#replaceWith = #replaceWithDeopt\n\t\t\t#removeFrom = #removeFromDeopt\n\t\t\t#insertInto = #insertIntoDeopt\n\n\t\tlet ph = #placeholderNode\n\t\tif parentNode and ph != self\n\t\t\tph.#insertInto(parentNode,self)\n\t\t\t#removeFrom(parentNode)\n\n\t\t#domNode = ph\n\t\t# self.#replaceWith(ph,parentNode)\n\t\tself\n\t\t\n\tdef #placeChild item, f, prev\n\t\t\n\t\tlet type = typeof item\n\t\t# console.log '#inserting!',item,f,prev,type\n\n\t\tif type === 'undefined' or item === null\n\t\t\t# what if the prev value was the same?\n\t\t\tif prev and prev isa Comment # check perf\n\t\t\t\treturn prev\n\n\t\t\tlet el = document.createComment('')\n\t\t\treturn prev ? prev.#replaceWith(el,self) : el.#insertInto(this,null)\n\n\t\t# dont reinsert again\n\t\tif item === prev\n\t\t\treturn item\n\n\t\t# what if this is null or undefined -- add comment and return? Or blank text node?\n\t\telif type !== 'object'\n\t\t\tlet res\n\t\t\tlet txt = item\n\t\t\t\n\t\t\tif (f & $TAG_FIRST_CHILD$) && (f & $TAG_LAST_CHILD$) and false\n\t\t\t\t# FIXME what if the previous one was not text? Possibly dangerous\n\t\t\t\t# when we set this on a fragment - it essentially replaces the whole\n\t\t\t\t# fragment?\n\t\t\t\t# log 'set textcontent raw',txt,prev\n\t\t\t\tself.textContent = txt\n\t\t\t\treturn\n\n\t\t\tif prev\n\t\t\t\tif prev isa Text # check perf\n\t\t\t\t\tprev.textContent = txt\n\t\t\t\t\treturn prev\n\t\t\t\telse\n\t\t\t\t\tres = document.createTextNode(txt)\n\t\t\t\t\tprev.#replaceWith(res,self)\n\t\t\t\t\treturn res\n\t\t\telse\n\t\t\t\tself.appendChild(res = document.createTextNode(txt))\n\t\t\t\treturn res\t\n\n\t\telse\n\t\t\treturn prev ? prev.#replaceWith(item,this) : item.#insertInto(this,null)\n\t\treturn\n\n# Basic element extensions\nextend class Element\n\t\n\tdef log ...params\n\t\tconsole.log(...params)\n\t\tself\n\n\tdef emit name, detail, o = {bubbles: true, cancelable: true}\n\t\to.detail = detail if detail != undefined\n\t\tlet event = new CustomEvent(name, o)\n\t\tlet res = self.dispatchEvent(event)\n\t\treturn event\n\n\tdef slot$ name, ctx\n\t\treturn self\n\n\t# inline in files or remove all together?\n\tdef text$ item\n\t\tself.textContent = item\n\t\tself\n\t\n\tdef #beforeReconcile\n\t\tself\n\t\t\n\tdef #afterReconcile\n\t\tself\n\t\t\n\tdef #afterVisit\n\t\tself.render! if self.render\n\t\treturn\n\n\tget flags\n\t\tunless $flags\n\t\t\t# unless deopted - we want to first cache the extflags\n\t\t\t$flags = new Flags(self)\n\t\t\tif flag$ == Element.prototype.flag$\n\t\t\t\tflags$ext = self.className\n\t\t\tflagDeopt$()\n\t\treturn $flags\n\n\tdef flag$ str\n\t\t# Potentially slow\n\t\tlet ns = flags$ns\n\t\tself.className = ns ? (ns + (flags$ext = str)) : (flags$ext = str)\n\t\treturn\n\t\t\n\tdef flagDeopt$\n\t\tself.flag$ = self.flagExt$ # do(str) self.flagSync$(flags$ext = str)\n\t\tself.flagSelf$ = do(str) self.flagSync$(flags$own = str)\n\t\treturn\n\t\t\n\tdef flagExt$ str\n\t\tself.flagSync$(flags$ext = str)\n\n\tdef flagSelf$ str\n\t\t# if a tag receives flags from inside we need to\n\t\t# redefine the flag-methods to later use both\n\t\tflagDeopt$()\n\t\treturn flagSelf$(str)\n\n\tdef flagSync$\n\t\tself.className = ((flags$ns or '') + (flags$ext or '') + ' ' + (flags$own || '') + ' ' + ($flags or ''))\n\t\t\n\tdef set$ key,value\n\t\t# FIXME relatively slow\n\t\tlet desc = getDeepPropertyDescriptor(this,key,Element)\n\t\tif !desc or !desc.set\n\t\t\tsetAttribute(key,value)\n\t\telse\n\t\t\tself[key] = value\n\t\treturn\n\t\t\n\tget richValue\n\t\tvalue\n\n\tset richValue value\n\t\tself.value = value\n\n# Element.prototype.set$ = Element.prototype.setAttribute\nElement.prototype.setns$ = Element.prototype.setAttributeNS\n\nexport def createElement name, parent, flags, text\n\tlet el = document.createElement(name)\n\t\t\n\tel.className = flags if flags\n\n\tif text !== null\n\t\tel.text$(text)\n\n\tif parent and parent.#appendChild\n\t\tparent.#appendChild(el)\n\t\t# el.#insertInto(parent)\n\n\treturn el\n\n\n\n\nextend class SVGElement\n\n\tdef set$ key,value\n\t\tlet cache = descriptorCache[nodeName] ||= {}\n\t\tlet desc = getDescriptor(this,key,cache)\n\n\t\tif !desc or !desc.set\n\t\t\tsetAttribute(key,value)\n\t\telse\n\t\t\tself[key] = value\n\t\treturn\n\n\tdef flag$ str\n\t\tlet ns = flags$ns\n\t\tself.setAttribute('class',ns ? (ns + (flags$ext = str)) : (flags$ext = str))\n\t\treturn\n\n\tdef flagSelf$ str\n\t\t# if a tag receives flags from inside we need to\n\t\t# redefine the flag-methods to later use both\n\t\tself.flag$ = do(str) self.flagSync$(flags$ext = str)\n\t\tself.flagSelf$ = do(str) self.flagSync$(flags$own = str)\n\t\treturn flagSelf$(str)\n\n\tdef flagSync$\n\t\tself.setAttribute('class',(flags$ns or '') + (flags$ext or '') + ' ' + (flags$own || '') + ' ' + ($flags or ''))\n\n\nextend class SVGSVGElement\n\n\tset src value\n\t\tif #src =? value\n\t\t\tif value\n\t\t\t\tif value.adoptNode\n\t\t\t\t\tvalue.adoptNode(self)\n\t\t\t\telif value.content\n\t\t\t\t\tfor own k,v of value.attributes\n\t\t\t\t\t\tsetAttribute(k,v)\n\t\t\t\t\tinnerHTML = value.content\n\t\treturn\n\n\t\t\n\nexport def createSVGElement name, parent, flags, text, ctx\n\tlet el = document.createElementNS(\"http://www.w3.org/2000/svg\",name)\n\n\tif flags\n\t\tel.className.baseVal = flags\n\n\tif parent and parent.#appendChild\n\t\tparent.#appendChild(el) # .#appendChild(parent)\n\n\tif text\n\t\tel.textContent = text\n\n\treturn el\n\nexport def createComment text\n\tdocument.createComment(text)\n\nexport def createTextNode text\n\tdocument.createTextNode(text)\n\t\nexport def createFragment\n\tdocument.createDocumentFragment!\n\n\nconst navigator = global.navigator\nconst vendor = navigator and navigator.vendor or ''\nconst ua = navigator and navigator.userAgent or ''\n\nconst isSafari = vendor.indexOf('Apple') > -1 || ua.indexOf('CriOS') >= 0 || ua.indexOf('FxiOS') >= 0\nconst supportsCustomizedBuiltInElements = !isSafari\nconst CustomDescriptorCache = new Map\n\nclass CustomHook < HTMLElement\n\tdef connectedCallback\n\t\tif supportsCustomizedBuiltInElements\n\t\t\tparentNode.removeChild(self)\n\t\telse\n\t\t\tparentNode.connectedCallback!\n\n\tdef disconnectedCallback\n\t\tif !supportsCustomizedBuiltInElements\n\t\t\tparentNode.disconnectedCallback!\n\nwindow.customElements.define('i-hook',CustomHook)\n\ndef getCustomDescriptors el, klass\n\tlet props = CustomDescriptorCache.get(klass)\n\n\tunless props\n\t\tprops = {}\n\t\tlet proto = klass.prototype\n\t\tlet protos = [proto]\n\t\twhile proto = (proto and Object.getPrototypeOf(proto))\n\t\t\tbreak if proto.constructor == el.constructor\n\t\t\tprotos.unshift(proto)\n\n\t\tfor item in protos\n\t\t\tlet desc = Object.getOwnPropertyDescriptors(item)\n\t\t\tObject.assign(props,desc)\n\t\tCustomDescriptorCache.set(klass,props)\n\n\treturn props\n\n# Registry\nexport def createComponent name, parent, flags, text, ctx\n\t# the component could have a different web-components name?\n\tlet el\n\t\n\tif typeof name != 'string'\n\t\tif name and name.nodeName\n\t\t\tname = name.nodeName\n\n\tlet cmpname = CustomTagToElementNames[name] or name\n\n\tif CustomTagConstructors[name]\n\t\tlet cls = CustomTagConstructors[name]\n\t\tlet typ = cls.prototype.#htmlNodeName\n\t\tif typ and supportsCustomizedBuiltInElements\n\t\t\tel = document.createElement(typ,is: name)\n\t\telif cls.create$ and typ\n\t\t\tel = document.createElement(typ)\n\t\t\tel.setAttribute('is',cmpname)\n\t\t\tlet props = getCustomDescriptors(el,cls)\n\t\t\tObject.defineProperties(el,props)\n\t\t\tel.__slots = {}\n\t\t\t# check if we need a hook though?\n\t\t\tel.appendChild(document.createElement('i-hook'))\n\t\telif cls.create$\n\t\t\tel = cls.create$(el)\n\t\t\tel.__slots = {}\n\t\telse\n\t\t\tconsole.warn \"could not create tag {name}\"\n\telse\n\t\tel = document.createElement(CustomTagToElementNames[name] or name)\n\n\tel.##parent = parent\n\tel.#__init__!\n\n\tif text !== null\n\t\tel.slot$('__').text$(text)\n\t\t\n\tif flags or el.flags$ns # or nsflag\n\t\tel.flag$(flags or '')\n\treturn el\n\nexport def getTagType name, klass\n\t# TODO follow same structure as ssr TYPES\n\tif TYPES[name]\n\t\treturn TYPES[name]\n\n\tif window[klass]\n\t\treturn window[klass]\n\n\tif window[name]\n\t\treturn window[name]\n\nexport def getSuperTagType name, klass, cmp\n\tlet typ = getTagType(name,klass)\n\tlet custom = typ == cmp or typ.prototype isa cmp or typ.prototype.#htmlNodeName\n\t\n\tif !custom\n\t\tlet cls = typ.prototype.#ImbaElement\n\n\t\tif !cls\n\t\t\tcls = class CustomBuiltInElement < typ\n\t\t\t\tdef constructor\n\t\t\t\t\tsuper\n\t\t\t\t\t__slots = {}\n\t\t\t\t\t__F = 0\n\n\t\t\ttyp.prototype.#ImbaElement = cls\n\t\t\tlet descriptors = Object.getOwnPropertyDescriptors(cmp.prototype)\n\t\t\tObject.defineProperties(cls.prototype,descriptors)\n\t\t\tcls.prototype.#htmlNodeName = name\n\n\t\treturn cls\n\n\treturn typ\n\nexport def defineTag name, klass, options = {}\n\tTYPES[name] = CUSTOM_TYPES[name] = klass\n\n\tklass.nodeName = name\n\n\tlet componentName = name\n\tlet proto = klass.prototype\n\n\tif name.indexOf('-') == -1\n\t\tcomponentName = \"{name}-tag\"\n\t\tCustomTagToElementNames[name] = componentName\n\n\tlet basens = proto._ns_\n\tif options.ns\n\t\tlet ns = options.ns\n\t\tlet flags = ns + ' ' + ns + '_ '\n\t\tif basens\n\t\t\tflags += proto.flags$ns \n\t\t\tns += ' ' + basens\n\t\tproto._ns_ = ns\n\t\tproto.flags$ns = flags\n\n\tif proto.#htmlNodeName and !options.extends\n\t\toptions.extends = proto.#htmlNodeName\n\n\tif options.extends\n\t\tproto.#htmlNodeName = options.extends\n\t\tCustomTagConstructors[name] = klass\n\n\t\tif supportsCustomizedBuiltInElements\n\t\t\twindow.customElements.define(componentName,klass,extends: options.extends)\n\telse\n\t\twindow.customElements.define(componentName,klass)\n\n\treturn klass\n\t\nlet instance = global.imba ||= {}\ninstance.document = global.document\n"], "mappings": ";2KAmZA,WAAyB,EAAI,EAAK,CAC7B,GAAA,GAAQ,EAAsB,IAAI,GAEtC,GAAO,CAAA,EAAK,CACX,EAAQ,GACJ,GAAA,GAAQ,EAAM,UACd,EAAS,CAAC,QACR,GAAS,GAAU,OAAO,eAAe,KACrC,EAAM,aAAe,EAAG,aACjC,EAAO,QAAQ,GAEhB,OAAG,GAAA,EAAA,EAAA,EAAS,GAAM,EAAA,EAAA,OAAA,EAAA,EAAA,IAAA,IAAd,GAAI,EAAA,GACH,EAAO,OAAO,0BAA0B,GAC5C,OAAO,OAAO,EAAM,GACrB,EAAsB,IAAI,EAAM,GAEjC,MAAO,GAGD,WAAoB,EAAM,EAAQ,EAAO,EAAM,EAAG,CAEpD,GAAA,GAEJ,AAAU,MAAA,IAAQ,UACd,GAAS,EAAK,UAChB,GAAO,EAAK,UAEV,GAAA,GAAU,EAAwB,IAAS,EAE/C,GAAG,EAAsB,GAAK,CACzB,GAAA,GAAM,EAAsB,GAC5B,EAAM,EAAI,UAAS,GACvB,GAAG,GAAQ,EACV,EAAK,WAAA,SAAS,cAAc,EAAG,CAAC,GAAI,YAChC,EAAI,SAAY,EAAG,CACvB,EAAK,WAAA,SAAS,cAAc,GAC5B,EAAG,aAAa,KAAK,GACjB,GAAA,GAAQ,EAAqB,EAAG,GACpC,OAAO,iBAAiB,EAAG,GAC3B,EAAG,QAAU,GAEb,EAAG,YAAY,WAAA,SAAS,cAAc,eACvC,AAAK,GAAI,QACR,GAAK,EAAI,QAAQ,GACjB,EAAG,QAAU,IAEb,QAAQ,KAAI,wBAAwB,OAErC,GAAK,WAAA,SAAS,cAAc,EAAwB,IAAS,GAE9D,SAAE,GAAY,EACd,EAAE,KAEC,IAAS,MACX,EAAG,MAAM,MAAM,MAAM,GAEnB,IAAS,EAAG,WACd,EAAG,MAAM,GAAS,IACZ", "names": [] }