aboutsummaryrefslogtreecommitdiff
path: root/catapult/third_party/polymer/components/shadycss/custom-style-interface.min.js.map
blob: 722c51eefabd8357973e6fae15cb1c82c7ff98c9 (plain)
1
{"version":3,"sources":["src/document-wait.js","src/custom-style-interface.js","src/common-utils.js","src/style-settings.js","entrypoints/custom-style-interface.js"],"names":["readyPromise","whenReady","window","resolveFn","documentWait","callback","requestAnimationFrame","Promise","resolve","document","readyState","addEventListener","then","transformFn","validateFn","constructor","CustomStyleInterface","enqueueDocumentValidation","addCustomStyle","style","push","getStyleForCustomStyle","customStyle","processStyles","cs","i","length","styleToTransform","prototype","Object","defineProperties","get","set","fn","needsEnqueue","updateNativeProperties","element","properties","p","removeProperty","setProperty","nativeShadow","nativeCssVariables_","calcCssVariables","settings","navigator","userAgent","match","CSS","supports","cssBuild","ShadyCSS","undefined","nativeCss","nativeCssVariables","module$src$style_settings.cssBuild","customStyleInterface","prepareTemplate","prepareTemplateDom","prepareTemplateStyles","styleSubtree","styleElement","styleDocument","body","getComputedStyleValue","property","value","getComputedStyle","getPropertyValue","trim","flushCustomStyles"],"mappings":"A;;;;;;;;;aAaA,IAAIA,EAAe,IAAnB,CAGIC,EAAYC,MAAA,YAAZD,EAAqCC,MAAA,YAAA,UAArCD,EAA2E,IAH/E,CAMIE,CAKWC,SAASA,EAAY,CAACC,CAAD,CAAW,CAC7CC,qBAAA,CAAsB,QAAQ,EAAG,CAC3BL,CAAJ,CACEA,CAAA,CAAUI,CAAV,CADF,EAGOL,CAYL,GAXEA,CACA,CADe,IAAIO,OAAJ,CAAY,QAAA,CAACC,CAAD,CAAa,CAACL,CAAA,CAAYK,CAAb,CAAzB,CACf,CAA4B,UAA5B,GAAIC,QAAAC,WAAJ,CACEP,CAAA,EADF,CAGEM,QAAAE,iBAAA,CAA0B,kBAA1B,CAA8C,QAAA,EAAM,CACtB,UAA5B,GAAIF,QAAAC,WAAJ,EACEP,CAAA,EAFgD,CAApD,CAOJ,EAAAH,CAAAY,KAAA,CAAkB,Q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AvB,CAAsC1B,CAAtC,CAFwB,CAxCV,CAkDhB,sBAAA2B,QAAqB,CAAC5B,CAAD,CAAU6B,CAAV,CAAoB,CACvC,MF9BJ,CADMC,CACN,CADchE,MAAAiE,iBAAA,CE+BmB/B,CF/BnB,CAAAgC,iBAAA,CE+B4BH,CF/B5B,CACd,EAGSC,CAAAG,KAAA,EAHT,CACS,EE4BkC,CAlDzB,CAsDhB,kBAAAC,QAAiB,EAAG,EAtDJ,CAuDhBjB,UAAWC,CAvDK,CAwDhBb,aAAcA,CAxDE,CAyDhBS,SAAUK,CAzDM,CADpB,CA8DArD,OAAAiD,SAAAnC,qBAAA,CAAuCwC","file":"custom-style-interface.min.js","sourcesContent":["/**\n@license\nCopyright (c) 2017 The Polymer Project Authors. All rights reserved.\nThis code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt\nThe complete set of authors may be found at http://polymer.github.io/AUTHORS.txt\nThe complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt\nCode distributed by Google as part of the polymer project is also\nsubject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt\n*/\n\n'use strict';\n\n/** @type {Promise<void>} */\nlet readyPromise = null;\n\n/** @type {?function(?function())} */\nlet whenReady = window['HTMLImports'] && window['HTMLImports']['whenReady'] || null;\n\n/** @type {function()} */\nlet resolveFn;\n\n/**\n * @param {?function()} callback\n */\nexport default function documentWait(callback) {\n  requestAnimationFrame(function() {\n    if (whenReady) {\n      whenReady(callback)\n    } else {\n      if (!readyPromise) {\n        readyPromise = new Promise((resolve) => {resolveFn = resolve});\n        if (document.readyState === 'complete') {\n          resolveFn();\n        } else {\n          document.addEventListener('readystatechange', () => {\n            if (document.readyState === 'complete') {\n              resolveFn();\n            }\n          });\n        }\n      }\n      readyPromise.then(function(){ callback && callback(); });\n    }\n  });\n}\n","/**\n@license\nCopyright (c) 2017 The Polymer Project Authors. All rights reserved.\nThis code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt\nThe complete set of authors may be found at http://polymer.github.io/AUTHORS.txt\nThe complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt\nCode distributed by Google as part of the polymer project is also\nsubject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt\n*/\n\n'use strict';\n\nimport documentWait from './document-wait.js';\n\n/**\n * @typedef {HTMLStyleElement | {getStyle: function():HTMLStyleElement}}\n */\nexport let CustomStyleProvider;\n\nconst SEEN_MARKER = '__seenByShadyCSS';\nconst CACHED_STYLE = '__shadyCSSCachedStyle';\n\n/** @type {?function(!HTMLStyleElement)} */\nlet transformFn = null;\n\n/** @type {?function()} */\nlet validateFn = null;\n\n/**\nThis interface is provided to add document-level <style> elements to ShadyCSS for processing.\nThese styles must be processed by ShadyCSS to simulate ShadowRoot upper-bound encapsulation from outside styles\nIn addition, these styles may also need to be processed for @apply rules and CSS Custom Properties\n\nTo add document-level styles to ShadyCSS, one can call `ShadyCSS.addDocumentStyle(styleElement)` or `ShadyCSS.addDocumentStyle({getStyle: () => styleElement})`\n\nIn addition, if the process used to discover document-level styles can be synchronously flushed, one should set `ShadyCSS.documentStyleFlush`.\nThis function will be called when calculating styles.\n\nAn example usage of the document-level styling api can be found in `examples/document-style-lib.js`\n\n@unrestricted\n*/\nexport default class CustomStyleInterface {\n  constructor() {\n    /** @type {!Array<!CustomStyleProvider>} */\n    this['customStyles'] = [];\n    this['enqueued'] = false;\n    // NOTE(dfreedm): use quotes here to prevent closure inlining to `function(){}`;\n    documentWait(() => {\n      if (window['ShadyCSS']['flushCustomStyles']) {\n        window['ShadyCSS']['flushCustomStyles']();\n      }\n    })\n  }\n  /**\n   * Queue a validation for new custom styles to batch style recalculations\n   */\n  enqueueDocumentValidation() {\n    if (this['enqueued'] || !validateFn) {\n      return;\n    }\n    this['enqueued'] = true;\n    documentWait(validateFn);\n  }\n  /**\n   * @param {!HTMLStyleElement} style\n   */\n  addCustomStyle(style) {\n    if (!style[SEEN_MARKER]) {\n      style[SEEN_MARKER] = true;\n      this['customStyles'].push(style);\n      this.enqueueDocumentValidation();\n    }\n  }\n  /**\n   * @param {!CustomStyleProvider} customStyle\n   * @return {HTMLStyleElement}\n   */\n  getStyleForCustomStyle(customStyle) {\n    if (customStyle[CACHED_STYLE]) {\n      return customStyle[CACHED_STYLE];\n    }\n    let style;\n    if (customStyle['getStyle']) {\n      style = customStyle['getStyle']();\n    } else {\n      style = customStyle;\n    }\n    return style;\n  }\n  /**\n   * @return {!Array<!CustomStyleProvider>}\n   */\n  processStyles() {\n    const cs = this['customStyles'];\n    for (let i = 0; i < cs.length; i++) {\n      const customStyle = cs[i];\n      if (customStyle[CACHED_STYLE]) {\n        continue;\n      }\n      const style = this.getStyleForCustomStyle(customStyle);\n      if (style) {\n        // HTMLImports polyfill may have cloned the style into the main document,\n        // which is referenced with __appliedElement.\n        const styleToTransform = /** @type {!HTMLStyleElement} */(style['__appliedElement'] || style);\n        if (transformFn) {\n          transformFn(styleToTransform);\n        }\n        customStyle[CACHED_STYLE] = styleToTransform;\n      }\n    }\n    return cs;\n  }\n}\n\n/* eslint-disable no-self-assign */\nCustomStyleInterface.prototype['addCustomStyle'] = CustomStyleInterface.prototype.addCustomStyle;\nCustomStyleInterface.prototype['getStyleForCustomStyle'] = CustomStyleInterface.prototype.getStyleForCustomStyle;\nCustomStyleInterface.prototype['processStyles'] = CustomStyleInterface.prototype.processStyles;\n/* eslint-enable no-self-assign */\n\nObject.defineProperties(CustomStyleInterface.prototype, {\n  'transformCallback': {\n    /** @return {?function(!HTMLStyleElement)} */\n    get() {\n      return transformFn;\n    },\n    /** @param {?function(!HTMLStyleElement)} fn */\n    set(fn) {\n      transformFn = fn;\n    }\n  },\n  'validateCallback': {\n    /** @return {?function()} */\n    get() {\n      return validateFn;\n    },\n    /**\n     * @param {?function()} fn\n     * @this {CustomStyleInterface}\n     */\n    set(fn) {\n      let needsEnqueue = false;\n      if (!validateFn) {\n        needsEnqueue = true;\n      }\n      validateFn = fn;\n      if (needsEnqueue) {\n        this.enqueueDocumentValidation();\n      }\n    },\n  }\n})\n\n/** @typedef {{\n * customStyles: !Array<!CustomStyleProvider>,\n * addCustomStyle: function(!CustomStyleProvider),\n * getStyleForCustomStyle: function(!CustomStyleProvider): HTMLStyleElement,\n * findStyles: function(),\n * transformCallback: ?function(!HTMLStyleElement),\n * validateCallback: ?function()\n * }}\n */\nexport const CustomStyleInterfaceInterface = {};\n","/**\n@license\nCopyright (c) 2017 The Polymer Project Authors. All rights reserved.\nThis code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt\nThe complete set of authors may be found at http://polymer.github.io/AUTHORS.txt\nThe complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt\nCode distributed by Google as part of the polymer project is also\nsubject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt\n*/\n\n'use strict';\n\nimport { MIXIN_MATCH, VAR_ASSIGN } from './common-regex.js';\n\n/**\n * @param {Element} element\n * @param {Object=} properties\n */\nexport function updateNativeProperties(element, properties) {\n  // remove previous properties\n  for (let p in properties) {\n    // NOTE: for bc with shim, don't apply null values.\n    if (p === null) {\n      element.style.removeProperty(p);\n    } else {\n      element.style.setProperty(p, properties[p]);\n    }\n  }\n}\n\n/**\n * @param {Element} element\n * @param {string} property\n * @return {string}\n */\nexport function getComputedStyleValue(element, property) {\n  /**\n   * @const {string}\n   */\n  const value = window.getComputedStyle(element).getPropertyValue(property);\n  if (!value) {\n    return '';\n  } else {\n    return value.trim();\n  }\n}\n\n/**\n * return true if `cssText` contains a mixin definition or consumption\n * @param {string} cssText\n * @return {boolean}\n */\nexport function detectMixin(cssText) {\n  const has = MIXIN_MATCH.test(cssText) || VAR_ASSIGN.test(cssText);\n  // reset state of the regexes\n  MIXIN_MATCH.lastIndex = 0;\n  VAR_ASSIGN.lastIndex = 0;\n  return has;\n}\n","/**\n@license\nCopyright (c) 2017 The Polymer Project Authors. All rights reserved.\nThis code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt\nThe complete set of authors may be found at http://polymer.github.io/AUTHORS.txt\nThe complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt\nCode distributed by Google as part of the polymer project is also\nsubject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt\n*/\n\n'use strict';\n\nexport const nativeShadow = !(window['ShadyDOM'] && window['ShadyDOM']['inUse']);\nlet nativeCssVariables_;\n\n/**\n * @param {(ShadyCSSOptions | ShadyCSSInterface)=} settings\n */\nfunction calcCssVariables(settings) {\n  if (settings && settings['shimcssproperties']) {\n    nativeCssVariables_ = false;\n  } else {\n    // chrome 49 has semi-working css vars, check if box-shadow works\n    // safari 9.1 has a recalc bug: https://bugs.webkit.org/show_bug.cgi?id=155782\n    // However, shim css custom properties are only supported with ShadyDOM enabled,\n    // so fall back on native if we do not detect ShadyDOM\n    // Edge 15: custom properties used in ::before and ::after will also be used in the parent element\n    // https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/12414257/\n    nativeCssVariables_ = nativeShadow || Boolean(!navigator.userAgent.match(/AppleWebKit\\/601|Edge\\/15/) &&\n      window.CSS && CSS.supports && CSS.supports('box-shadow', '0 0 0 var(--foo)'));\n  }\n}\n\n/** @type {string | undefined} */\nexport let cssBuild;\nif (window.ShadyCSS && window.ShadyCSS.cssBuild !== undefined) {\n  cssBuild = window.ShadyCSS.cssBuild;\n}\n\nif (window.ShadyCSS && window.ShadyCSS.nativeCss !== undefined) {\n  nativeCssVariables_ = window.ShadyCSS.nativeCss;\n} else if (window.ShadyCSS) {\n  calcCssVariables(window.ShadyCSS);\n  // reset window variable to let ShadyCSS API take its place\n  window.ShadyCSS = undefined;\n} else {\n  calcCssVariables(window['WebComponents'] && window['WebComponents']['flags']);\n}\n\n// Hack for type error under new type inference which doesn't like that\n// nativeCssVariables is updated in a function and assigns the type\n// `function(): ?` instead of `boolean`.\nexport const nativeCssVariables = /** @type {boolean} */(nativeCssVariables_);","/**\n@license\nCopyright (c) 2017 The Polymer Project Authors. All rights reserved.\nThis code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt\nThe complete set of authors may be found at http://polymer.github.io/AUTHORS.txt\nThe complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt\nCode distributed by Google as part of the polymer project is also\nsubject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt\n*/\n\n'use strict';\n\nimport CustomStyleInterface from '../src/custom-style-interface.js';\nimport {getComputedStyleValue, updateNativeProperties} from '../src/common-utils.js';\nimport {nativeCssVariables, nativeShadow, cssBuild} from '../src/style-settings.js';\n\nconst customStyleInterface = new CustomStyleInterface();\n\nif (!window.ShadyCSS) {\n  window.ShadyCSS = {\n    /**\n     * @param {!HTMLTemplateElement} template\n     * @param {string} elementName\n     * @param {string=} elementExtends\n     */\n    prepareTemplate(template, elementName, elementExtends) {}, // eslint-disable-line no-unused-vars\n\n    /**\n     * @param {!HTMLTemplateElement} template\n     * @param {string} elementName\n     */\n    prepareTemplateDom(template, elementName) {}, // eslint-disable-line no-unused-vars\n\n    /**\n     * @param {!HTMLTemplateElement} template\n     * @param {string} elementName\n     * @param {string=} elementExtends\n     */\n    prepareTemplateStyles(template, elementName, elementExtends) {}, // eslint-disable-line no-unused-vars\n\n    /**\n     * @param {Element} element\n     * @param {Object=} properties\n     */\n    styleSubtree(element, properties) {\n      customStyleInterface.processStyles();\n      updateNativeProperties(element, properties);\n    },\n\n    /**\n     * @param {Element} element\n     */\n    styleElement(element) { // eslint-disable-line no-unused-vars\n      customStyleInterface.processStyles();\n    },\n\n    /**\n     * @param {Object=} properties\n     */\n    styleDocument(properties) {\n      customStyleInterface.processStyles();\n      updateNativeProperties(document.body, properties);\n    },\n\n    /**\n     * @param {Element} element\n     * @param {string} property\n     * @return {string}\n     */\n    getComputedStyleValue(element, property) {\n      return getComputedStyleValue(element, property);\n    },\n\n    flushCustomStyles() {},\n    nativeCss: nativeCssVariables,\n    nativeShadow: nativeShadow,\n    cssBuild: cssBuild\n  }\n}\n\nwindow.ShadyCSS.CustomStyleInterface = customStyleInterface;"]}