{
  "version": 3,
  "sources": ["../index.ts", "../src/ComponentProvider.ts"],
  "sourcesContent": ["export * from './src'\n", "import { tagNameLower, objectMap } from '@tko/utils'\n\nimport registry from '@tko/utils.component'\n\nimport { unwrap, isWriteableObservable } from '@tko/observable'\n\nimport { computed } from '@tko/computed'\n\nimport { Provider } from '@tko/provider'\n\nimport { Parser } from '@tko/utils.parser'\n\nexport default class ComponentProvider extends Provider {\n  override get FOR_NODE_TYPES() {\n    return [Node.ELEMENT_NODE]\n  }\n\n  /**\n   * Convert <slot name='X'> to <!-- ko slot: 'X' --><!-- /ko -->\n   * @param {Node} node\n   */\n  override preprocessNode(node: Node): Node[] | null {\n    if (node instanceof Element && node.tagName === 'SLOT') {\n      const parent = node.parentNode\n      const slotName = node.getAttribute('name') || ''\n      const openNode = document.createComment(`ko slot: \"${slotName}\"`)\n      const closeNode = document.createComment('/ko')\n\n      if (!parent) {\n        throw Error('Missing parent node')\n      }\n\n      parent.insertBefore(openNode, node)\n      parent.insertBefore(closeNode, node)\n      parent.removeChild(node)\n\n      return [openNode, closeNode]\n    }\n    return null\n  }\n\n  override nodeHasBindings(node: Node): boolean {\n    return Boolean(this.getComponentNameForNode(node))\n  }\n\n  override getBindingAccessors(node: Node, context) {\n    const componentName = this.getComponentNameForNode(node)\n    if (!componentName) {\n      return Object.create(null)\n    }\n    const component = () => ({ name: componentName, params: this.getComponentParams(node, context) })\n    return { component }\n  }\n\n  getComponentNameForNode(node: Node): string | null {\n    if (!(node instanceof Element) || node.nodeType !== Node.ELEMENT_NODE) {\n      return null\n    }\n    const tagName = tagNameLower(node)\n    if (registry.isRegistered(tagName)) {\n      const hasDash = tagName.includes('-')\n      const isUnknownEntity = Object.prototype.toString.call(node) === '[object HTMLUnknownElement]'\n      if (hasDash || isUnknownEntity) {\n        return tagName\n      }\n    }\n    return null\n  }\n\n  getComponentParams(node: Node, context) {\n    if (!(node instanceof Element)) {\n      return { $raw: {} }\n    }\n\n    const parser = new (Parser as any)(node, context, this.globals) as Parser\n    const paramsString = (node.getAttribute('params') || '').trim()\n    const accessors = parser.parse(paramsString, context, undefined, node)\n    if (!accessors || Object.keys(accessors).length === 0) {\n      return { $raw: {} }\n    }\n    const $raw = objectMap(accessors, value => computed(value, null, { disposeWhenNodeIsRemoved: node }))\n    const params = objectMap($raw, v => this.makeParamValue(node, v))\n    return Object.assign({ $raw }, params)\n  }\n\n  makeParamValue(node: Element, paramValueComputed) {\n    const paramValue = paramValueComputed.peek()\n    // Does the evaluation of the parameter value unwrap any observables?\n    if (!paramValueComputed.isActive()) {\n      // No it doesn't, so there's no need for any computed wrapper. Just pass through the supplied value directly.\n      // Example: \"someVal: firstName, age: 123\" (whether or not firstName is an observable/computed)\n      return paramValue\n    }\n    // Yes it does. Supply a computed property that unwraps both the outer (binding expression)\n    // level of observability, and any inner (resulting model value) level of observability.\n    // This means the component doesn't have to worry about multiple unwrapping. If the value is a\n    // writable observable, the computed will also be writable and pass the value on to the observable.\n    const isWriteable = isWriteableObservable(paramValue)\n\n    return computed({\n      read: () => unwrap(paramValueComputed()),\n      write: isWriteable ? v => paramValueComputed()(v) : undefined,\n      disposeWhenNodeIsRemoved: node\n    })\n  }\n}\n"],
  "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAwC;AAExC,IAAAA,gBAAqB;AAErB,wBAA8C;AAE9C,sBAAyB;AAEzB,sBAAyB;AAEzB,IAAAA,gBAAuB;AAEvB,IAAqB,oBAArB,cAA+C,yBAAS;AAAA,EACtD,IAAa,iBAAiB;AAC5B,WAAO,CAAC,KAAK,YAAY;AAAA,EAC3B;AAAA;AAAA;AAAA;AAAA;AAAA,EAMS,eAAe,MAA2B;AACjD,QAAI,gBAAgB,WAAW,KAAK,YAAY,QAAQ;AACtD,YAAM,SAAS,KAAK;AACpB,YAAM,WAAW,KAAK,aAAa,MAAM,KAAK;AAC9C,YAAM,WAAW,SAAS,cAAc,aAAa,QAAQ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