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,MAAM,CAAC","sourcesContent":["/**\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 */\nimport {TemplateResult} from 'lit-html';\nimport {render} from 'lit-html/lib/shady-render.js';\n\nimport {PropertyValues, UpdatingElement} from './lib/updating-element.js';\n\nexport * from './lib/updating-element.js';\nexport * from './lib/decorators.js';\nexport {html, svg, TemplateResult, SVGTemplateResult} from 'lit-html/lit-html.js';\nimport {supportsAdoptingStyleSheets, CSSResult} from './lib/css-tag.js';\nexport * from './lib/css-tag.js';\n\ndeclare global {\n interface Window {\n litElementVersions: string[];\n }\n}\n\n// IMPORTANT: do not change the property name or the assignment expression.\n// This line will be used in regexes to search for LitElement usage.\n// TODO(justinfagnani): inject version number at build time\n(window['litElementVersions'] || (window['litElementVersions'] = []))\n .push('2.2.1');\n\nexport interface CSSResultArray extends Array<CSSResult|CSSResultArray> {}\n\n/**\n * Minimal implementation of Array.prototype.flat\n * @param arr the array to flatten\n * @param result the accumlated result\n */\nfunction arrayFlat(\n styles: CSSResultArray, result: CSSResult[] = []): CSSResult[] {\n for (let i = 0, length = styles.length; i < length; i++) {\n const value = styles[i];\n if (Array.isArray(value)) {\n arrayFlat(value, result);\n } else {\n result.push(value);\n }\n }\n return result;\n}\n\n/** Deeply flattens styles array. Uses native flat if available. */\nconst flattenStyles = (styles: CSSResultArray): CSSResult[] =>\n styles.flat ? styles.flat(Infinity) : arrayFlat(styles);\n\nexport class LitElement extends UpdatingElement {\n\n /**\n * Ensure this class is marked as `finalized` as an optimization ensuring\n * it will not needlessly try to `finalize`.\n *\n * Note this property name is a string to prevent breaking Closure JS Compiler\n * optimizations. See updating-element.ts for more information.\n */\n protected static['finalized'] = true;\n /**\n * Render method used to render the lit-html TemplateResult to the element's\n * DOM.\n * @param {TemplateResult} Template to render.\n * @param {Element|DocumentFragment} Node into which to render.\n * @param {String} Element name.\n * @nocollapse\n */\n static render = render;\n\n /**\n * Array of styles to apply to the element. The styles should be defined\n * using the `css` tag function.\n */\n static styles?: CSSResult|CSSResultArray;\n\n private static _styles: CSSResult[]|undefined;\n\n /** @nocollapse */\n protected static finalize() {\n // The Closure JS Compiler does not always preserve the correct \"this\"\n // when calling static super methods (b/137460243), so explicitly bind.\n super.finalize.call(this);\n // Prepare styling that is stamped at first render time. Styling\n // is built from user provided `styles` or is inherited from the superclass.\n this._styles =\n this.hasOwnProperty(JSCompiler_renameProperty('styles', this)) ?\n this._getUniqueStyles() :\n this._styles || [];\n }\n\n /** @nocollapse */\n private static _getUniqueStyles(): CSSResult[] {\n // Take care not to call `this.styles` multiple times since this generates\n // new CSSResults each time.\n // TODO(sorvell): Since we do not cache CSSResults by input, any\n // shared styles will generate new stylesheet objects, which is wasteful.\n // This should be addressed when a browser ships constructable\n // stylesheets.\n const userStyles = this.styles;\n const styles: CSSResult[] = [];\n if (Array.isArray(userStyles)) {\n const flatStyles = flattenStyles(userStyles);\n // As a performance optimization to avoid duplicated styling that can\n // occur especially when composing via subclassing, de-duplicate styles\n // preserving the last item in the list. The last item is kept to\n // try to preserve cascade order with the assumption that it's most\n // important that last added styles override previous styles.\n const styleSet = flatStyles.reduceRight((set, s) => {\n set.add(s);\n // on IE set.add does not return the set.\n return set;\n }, new Set<CSSResult>());\n // Array.from does not work on Set in IE\n styleSet.forEach((v) => styles.unshift(v));\n } else if (userStyles) {\n styles.push(userStyles);\n }\n return styles;\n }\n\n private _needsShimAdoptedStyleSheets?: boolean;\n\n /**\n * Node or ShadowRoot into which element DOM should be rendered. Defaults\n * to an open shadowRoot.\n */\n readonly renderRoot!: Element|DocumentFragment;\n\n /**\n * Performs element initialization. By default this calls `createRenderRoot`\n * to create the element `renderRoot` node and captures any pre-set values for\n * registered properties.\n */\n protected initialize() {\n super.initialize();\n (this as {renderRoot: Element | DocumentFragment}).renderRoot =\n this.createRenderRoot();\n // Note, if renderRoot is not a shadowRoot, styles would/could apply to the\n // element's getRootNode(). While this could be done, we're choosing not to\n // support this now since it would require different logic around de-duping.\n if (window.ShadowRoot && this.renderRoot instanceof window.ShadowRoot) {\n this.adoptStyles();\n }\n }\n\n /**\n * Returns the node into which the element should render and by default\n * creates and returns an open shadowRoot. Implement to customize where the\n * element's DOM is rendered. For example, to render into the element's\n * childNodes, return `this`.\n * @returns {Element|DocumentFragment} Returns a node into which to render.\n */\n protected createRenderRoot(): Element|ShadowRoot {\n return this.attachShadow({mode: 'open'});\n }\n\n /**\n * Applies styling to the element shadowRoot using the `static get styles`\n * property. Styling will apply using `shadowRoot.adoptedStyleSheets` where\n * available and will fallback otherwise. When Shadow DOM is polyfilled,\n * ShadyCSS scopes styles and adds them to the document. When Shadow DOM\n * is available but `adoptedStyleSheets` is not, styles are appended to the\n * end of the `shadowRoot` to [mimic spec\n * behavior](https://wicg.github.io/construct-stylesheets/#using-constructed-stylesheets).\n */\n protected adoptStyles() {\n const styles = (this.constructor as typeof LitElement)._styles!;\n if (styles.length === 0) {\n return;\n }\n // There are three separate cases here based on Shadow DOM support.\n // (1) shadowRoot polyfilled: use ShadyCSS\n // (2) shadowRoot.adoptedStyleSheets available: use it.\n // (3) shadowRoot.adoptedStyleSheets polyfilled: append styles after\n // rendering\n if (window.ShadyCSS !== undefined && !window.ShadyCSS.nativeShadow) {\n window.ShadyCSS.ScopingShim!.prepareAdoptedCssText(\n styles.map((s) => s.cssText), this.localName);\n } else if (supportsAdoptingStyleSheets) {\n (this.renderRoot as ShadowRoot).adoptedStyleSheets =\n styles.map((s) => s.styleSheet!);\n } else {\n // This must be done after rendering so the actual style insertion is done\n // in `update`.\n this._needsShimAdoptedStyleSheets = true;\n }\n }\n\n connectedCallback() {\n super.connectedCallback();\n // Note, first update/render handles styleElement so we only call this if\n // connected after first update.\n if (this.hasUpdated && window.ShadyCSS !== undefined) {\n window.ShadyCSS.styleElement(this);\n }\n }\n\n /**\n * Updates the element. This method reflects property values to attributes\n * and calls `render` to render DOM via lit-html. Setting properties inside\n * this method will *not* trigger another update.\n * * @param _changedProperties Map of changed properties with old values\n */\n protected update(changedProperties: PropertyValues) {\n super.update(changedProperties);\n const templateResult = this.render() as unknown;\n if (templateResult instanceof TemplateResult) {\n (this.constructor as typeof LitElement)\n .render(\n templateResult,\n this.renderRoot,\n {scopeName: this.localName, eventContext: this});\n }\n // When native Shadow DOM is used but adoptedStyles are not supported,\n // insert styling after rendering to ensure adoptedStyles have highest\n // priority.\n if (this._needsShimAdoptedStyleSheets) {\n this._needsShimAdoptedStyleSheets = false;\n (this.constructor as typeof LitElement)._styles!.forEach((s) => {\n const style = document.createElement('style');\n style.textContent = s.cssText;\n this.renderRoot.appendChild(style);\n });\n }\n }\n\n /**\n * Invoked on each update to perform rendering tasks. This method must return\n * a lit-html TemplateResult. Setting properties inside this method will *not*\n * trigger the element to update.\n */\n protected render(): TemplateResult|void {\n }\n}\n"]}
\No newline at end of file