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AAC,CAAC,CAAC,CAAC,CAAC;AAEpE;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,OAAgC,EAAE,EAAE;AAC7D,wEAAwE;AACxE,4EAA4E;AAC5E,YAAY;AACZ,2EAA2E;AAC3E,aAAa;AACb,CAAC,CAAC,iBAAsC,EAAE,IAAa,EAAE,EAAE,CACtD,CAAC,IAAI,KAAK,SAAS,CAAC;IAChB,CAAC,CAAC,kBAAkB,CAAC,OAAO,EAAE,iBAA2B,EAAE,IAAI,CAAC;IAChE,CAAC,CAAC,oBAAoB,CAAC,OAAO,EACP,iBAAiC,CAAC,CAAQ,CAAC","sourcesContent":["\n/**\n * @license\n * Copyright (c) 2017 The Polymer Project Authors. All rights reserved.\n * This code may only be used under the BSD style license found at\n * http://polymer.github.io/LICENSE.txt\n * The complete set of authors may be found at\n * http://polymer.github.io/AUTHORS.txt\n * The complete set of contributors may be found at\n * http://polymer.github.io/CONTRIBUTORS.txt\n * Code distributed by Google as part of the polymer project is also\n * subject to an additional IP rights grant found at\n * http://polymer.github.io/PATENTS.txt\n */\n\nimport {LitElement} from '../lit-element.js';\n\nimport {PropertyDeclaration, UpdatingElement} from './updating-element.js';\n\nexport type Constructor<T> = {\n new (...args: any[]): T\n};\n\n// From the TC39 Decorators proposal\ninterface ClassDescriptor {\n kind: 'class';\n elements: ClassElement[];\n finisher?: <T>(clazz: Constructor<T>) => undefined | Constructor<T>;\n}\n\n// From the TC39 Decorators proposal\ninterface ClassElement {\n kind: 'field'|'method';\n key: PropertyKey;\n placement: 'static'|'prototype'|'own';\n initializer?: Function;\n extras?: ClassElement[];\n finisher?: <T>(clazz: Constructor<T>) => undefined | Constructor<T>;\n descriptor?: PropertyDescriptor;\n}\n\nconst legacyCustomElement =\n (tagName: string, clazz: Constructor<HTMLElement>) => {\n window.customElements.define(tagName, clazz);\n // Cast as any because TS doesn't recognize the return type as being a\n // subtype of the decorated class when clazz is typed as\n // `Constructor<HTMLElement>` for some reason.\n // `Constructor<HTMLElement>` is helpful to make sure the decorator is\n // applied to elements however.\n return clazz as any;\n };\n\nconst standardCustomElement =\n (tagName: string, descriptor: ClassDescriptor) => {\n const {kind, elements} = descriptor;\n return {\n kind,\n elements,\n // This callback is called once the class is otherwise fully defined\n finisher(clazz: Constructor<HTMLElement>) {\n window.customElements.define(tagName, clazz);\n }\n };\n };\n\n/**\n * Class decorator factory that defines the decorated class as a custom element.\n *\n * @param tagName the name of the custom element to define\n *\n * In TypeScript, the `tagName` passed to `customElement` should be a key of the\n * `HTMLElementTagNameMap` interface. To add your element to the interface,\n * declare the interface in this module:\n *\n * @customElement('my-element')\n * export class MyElement extends LitElement {}\n *\n * declare global {\n * interface HTMLElementTagNameMap {\n * 'my-element': MyElement;\n * }\n * }\n *\n */\nexport const customElement = (tagName: string) => (\n classOrDescriptor: Constructor<HTMLElement>|ClassDescriptor) =>\n (typeof classOrDescriptor === 'function')\n ? legacyCustomElement(tagName,\n classOrDescriptor as Constructor<HTMLElement>)\n : standardCustomElement(tagName, classOrDescriptor as ClassDescriptor);\n\nconst standardProperty =\n (options: PropertyDeclaration, element: ClassElement) => {\n // createProperty() takes care of defining the property, but we still must\n // return some kind of descriptor, so return a descriptor for an unused\n // prototype field. The finisher calls createProperty().\n return {\n kind : 'field',\n key : Symbol(),\n placement : 'own',\n descriptor : {},\n // When @babel/plugin-proposal-decorators implements initializers,\n // do this instead of the initializer below. See:\n // https://github.com/babel/babel/issues/9260 extras: [\n // {\n // kind: 'initializer',\n // placement: 'own',\n // initializer: descriptor.initializer,\n // }\n // ],\n initializer(this: any) {\n if (typeof element.initializer === 'function') {\n this[element.key] = element.initializer!.call(this);\n }\n },\n finisher(clazz: typeof UpdatingElement) {\n clazz.createProperty(element.key, options);\n }\n };\n };\n\nconst legacyProperty = (options: PropertyDeclaration, proto: Object,\n name: PropertyKey) => {\n (proto.constructor as typeof UpdatingElement).createProperty(name!, options);\n};\n\n/**\n * A property decorator which creates a LitElement property which reflects a\n * corresponding attribute value. A `PropertyDeclaration` may optionally be\n * supplied to configure property features.\n */\nexport const property = (options?: PropertyDeclaration) =>\n (protoOrDescriptor: Object|ClassElement, name?: PropertyKey): any =>\n (name !== undefined)\n ? legacyProperty(options!, protoOrDescriptor as Object, name)\n : standardProperty(options!, protoOrDescriptor as ClassElement);\n\n/**\n * A property decorator that converts a class property into a getter that\n * executes a querySelector on the element's renderRoot.\n */\nexport const query = _query((target: NodeSelector, selector: string) =>\n target.querySelector(selector));\n\n/**\n * A property decorator that converts a class property into a getter\n * that executes a querySelectorAll on the element's renderRoot.\n */\nexport const queryAll = _query((target: NodeSelector, selector: string) =>\n target.querySelectorAll(selector));\n\nconst legacyQuery =\n (descriptor: PropertyDescriptor, proto: Object,\n name: PropertyKey) => { Object.defineProperty(proto, name, descriptor); };\n\nconst standardQuery = (descriptor: PropertyDescriptor, element: ClassElement) =>\n ({\n kind : 'method',\n placement : 'prototype',\n key : element.key,\n descriptor,\n });\n\n/**\n * Base-implementation of `@query` and `@queryAll` decorators.\n *\n * @param queryFn exectute a `selector` (ie, querySelector or querySelectorAll)\n * against `target`.\n */\nfunction _query<T>(queryFn: (target: NodeSelector, selector: string) => T) {\n return (selector: string) => (protoOrDescriptor: Object|ClassElement,\n name?: PropertyKey): any => {\n const descriptor = {\n get(this: LitElement) { return queryFn(this.renderRoot!, selector); },\n enumerable : true,\n configurable : true,\n };\n return (name !== undefined)\n ? legacyQuery(descriptor, protoOrDescriptor as Object, name)\n : standardQuery(descriptor, protoOrDescriptor as ClassElement);\n };\n}\n\nconst standardEventOptions =\n (options: AddEventListenerOptions, element: ClassElement) => {\n return {\n ...element,\n finisher(clazz: typeof UpdatingElement) {\n Object.assign(clazz.prototype[element.key as keyof UpdatingElement],\n options);\n }\n };\n };\n\nconst legacyEventOptions =\n (options: AddEventListenerOptions, proto: any,\n name: PropertyKey) => { Object.assign(proto[name], options); };\n\n/**\n * Adds event listener options to a method used as an event listener in a\n * lit-html template.\n *\n * @param options An object that specifis event listener options as accepted by\n * `EventTarget#addEventListener` and `EventTarget#removeEventListener`.\n *\n * Current browsers support the `capture`, `passive`, and `once` options. See:\n * https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#Parameters\n *\n * @example\n *\n * class MyElement {\n *\n * clicked = false;\n *\n * render() {\n * return html`<div @click=${this._onClick}`><button></button></div>`;\n * }\n *\n * @eventOptions({capture: true})\n * _onClick(e) {\n * this.clicked = true;\n * }\n * }\n */\nexport const eventOptions = (options: AddEventListenerOptions) =>\n // Return value typed as any to prevent TypeScript from complaining that\n // standard decorator function signature does not match TypeScript decorator\n // signature\n // TODO(kschaaf): unclear why it was only failing on this decorator and not\n // the others\n ((protoOrDescriptor: Object|ClassElement, name?: string) =>\n (name !== undefined)\n ? legacyEventOptions(options, protoOrDescriptor as Object, name)\n : standardEventOptions(options,\n protoOrDescriptor as ClassElement)) as any;\n"]}
\No newline at end of file