aboutsummaryrefslogtreecommitdiff
path: root/node_modules/vue-style-loader/lib
diff options
context:
space:
mode:
authorruki <waruqi@gmail.com>2018-11-08 00:38:48 +0800
committerruki <waruqi@gmail.com>2018-11-07 21:53:09 +0800
commit26105034da4fcce7ac883c899d781f016559310d (patch)
treec459a5dc4e3aa0972d9919033ece511ce76dd129 /node_modules/vue-style-loader/lib
parent2c77f00f1a7ecb6c8192f9c16d3b2001b254a107 (diff)
downloadxmake-docs-26105034da4fcce7ac883c899d781f016559310d.tar.gz
xmake-docs-26105034da4fcce7ac883c899d781f016559310d.zip
switch to vuepress
Diffstat (limited to 'node_modules/vue-style-loader/lib')
-rw-r--r--node_modules/vue-style-loader/lib/addStylesClient.js222
-rw-r--r--node_modules/vue-style-loader/lib/addStylesServer.js80
-rw-r--r--node_modules/vue-style-loader/lib/addStylesShadow.js70
-rw-r--r--node_modules/vue-style-loader/lib/listToStyles.js27
4 files changed, 399 insertions, 0 deletions
diff --git a/node_modules/vue-style-loader/lib/addStylesClient.js b/node_modules/vue-style-loader/lib/addStylesClient.js
new file mode 100644
index 00000000..920b00bb
--- /dev/null
+++ b/node_modules/vue-style-loader/lib/addStylesClient.js
@@ -0,0 +1,222 @@
+/*
+ MIT License http://www.opensource.org/licenses/mit-license.php
+ Author Tobias Koppers @sokra
+ Modified by Evan You @yyx990803
+*/
+
+import listToStyles from './listToStyles'
+
+var hasDocument = typeof document !== 'undefined'
+
+if (typeof DEBUG !== 'undefined' && DEBUG) {
+ if (!hasDocument) {
+ throw new Error(
+ 'vue-style-loader cannot be used in a non-browser environment. ' +
+ "Use { target: 'node' } in your Webpack config to indicate a server-rendering environment."
+ ) }
+}
+
+/*
+type StyleObject = {
+ id: number;
+ parts: Array<StyleObjectPart>
+}
+
+type StyleObjectPart = {
+ css: string;
+ media: string;
+ sourceMap: ?string
+}
+*/
+
+var stylesInDom = {/*
+ [id: number]: {
+ id: number,
+ refs: number,
+ parts: Array<(obj?: StyleObjectPart) => void>
+ }
+*/}
+
+var head = hasDocument && (document.head || document.getElementsByTagName('head')[0])
+var singletonElement = null
+var singletonCounter = 0
+var isProduction = false
+var noop = function () {}
+var options = null
+var ssrIdKey = 'data-vue-ssr-id'
+
+// Force single-tag solution on IE6-9, which has a hard limit on the # of <style>
+// tags it will allow on a page
+var isOldIE = typeof navigator !== 'undefined' && /msie [6-9]\b/.test(navigator.userAgent.toLowerCase())
+
+export default function addStylesClient (parentId, list, _isProduction, _options) {
+ isProduction = _isProduction
+
+ options = _options || {}
+
+ var styles = listToStyles(parentId, list)
+ addStylesToDom(styles)
+
+ return function update (newList) {
+ var mayRemove = []
+ for (var i = 0; i < styles.length; i++) {
+ var item = styles[i]
+ var domStyle = stylesInDom[item.id]
+ domStyle.refs--
+ mayRemove.push(domStyle)
+ }
+ if (newList) {
+ styles = listToStyles(parentId, newList)
+ addStylesToDom(styles)
+ } else {
+ styles = []
+ }
+ for (var i = 0; i < mayRemove.length; i++) {
+ var domStyle = mayRemove[i]
+ if (domStyle.refs === 0) {
+ for (var j = 0; j < domStyle.parts.length; j++) {
+ domStyle.parts[j]()
+ }
+ delete stylesInDom[domStyle.id]
+ }
+ }
+ }
+}
+
+function addStylesToDom (styles /* Array<StyleObject> */) {
+ for (var i = 0; i < styles.length; i++) {
+ var item = styles[i]
+ var domStyle = stylesInDom[item.id]
+ if (domStyle) {
+ domStyle.refs++
+ for (var j = 0; j < domStyle.parts.length; j++) {
+ domStyle.parts[j](item.parts[j])
+ }
+ for (; j < item.parts.length; j++) {
+ domStyle.parts.push(addStyle(item.parts[j]))
+ }
+ if (domStyle.parts.length > item.parts.length) {
+ domStyle.parts.length = item.parts.length
+ }
+ } else {
+ var parts = []
+ for (var j = 0; j < item.parts.length; j++) {
+ parts.push(addStyle(item.parts[j]))
+ }
+ stylesInDom[item.id] = { id: item.id, refs: 1, parts: parts }
+ }
+ }
+}
+
+function createStyleElement () {
+ var styleElement = document.createElement('style')
+ styleElement.type = 'text/css'
+ head.appendChild(styleElement)
+ return styleElement
+}
+
+function addStyle (obj /* StyleObjectPart */) {
+ var update, remove
+ var styleElement = document.querySelector('style[' + ssrIdKey + '~="' + obj.id + '"]')
+
+ if (styleElement) {
+ if (isProduction) {
+ // has SSR styles and in production mode.
+ // simply do nothing.
+ return noop
+ } else {
+ // has SSR styles but in dev mode.
+ // for some reason Chrome can't handle source map in server-rendered
+ // style tags - source maps in <style> only works if the style tag is
+ // created and inserted dynamically. So we remove the server rendered
+ // styles and inject new ones.
+ styleElement.parentNode.removeChild(styleElement)
+ }
+ }
+
+ if (isOldIE) {
+ // use singleton mode for IE9.
+ var styleIndex = singletonCounter++
+ styleElement = singletonElement || (singletonElement = createStyleElement())
+ update = applyToSingletonTag.bind(null, styleElement, styleIndex, false)
+ remove = applyToSingletonTag.bind(null, styleElement, styleIndex, true)
+ } else {
+ // use multi-style-tag mode in all other cases
+ styleElement = createStyleElement()
+ update = applyToTag.bind(null, styleElement)
+ remove = function () {
+ styleElement.parentNode.removeChild(styleElement)
+ }
+ }
+
+ update(obj)
+
+ return function updateStyle (newObj /* StyleObjectPart */) {
+ if (newObj) {
+ if (newObj.css === obj.css &&
+ newObj.media === obj.media &&
+ newObj.sourceMap === obj.sourceMap) {
+ return
+ }
+ update(obj = newObj)
+ } else {
+ remove()
+ }
+ }
+}
+
+var replaceText = (function () {
+ var textStore = []
+
+ return function (index, replacement) {
+ textStore[index] = replacement
+ return textStore.filter(Boolean).join('\n')
+ }
+})()
+
+function applyToSingletonTag (styleElement, index, remove, obj) {
+ var css = remove ? '' : obj.css
+
+ if (styleElement.styleSheet) {
+ styleElement.styleSheet.cssText = replaceText(index, css)
+ } else {
+ var cssNode = document.createTextNode(css)
+ var childNodes = styleElement.childNodes
+ if (childNodes[index]) styleElement.removeChild(childNodes[index])
+ if (childNodes.length) {
+ styleElement.insertBefore(cssNode, childNodes[index])
+ } else {
+ styleElement.appendChild(cssNode)
+ }
+ }
+}
+
+function applyToTag (styleElement, obj) {
+ var css = obj.css
+ var media = obj.media
+ var sourceMap = obj.sourceMap
+
+ if (media) {
+ styleElement.setAttribute('media', media)
+ }
+ if (options.ssrId) {
+ styleElement.setAttribute(ssrIdKey, obj.id)
+ }
+
+ if (sourceMap) {
+ // https://developer.chrome.com/devtools/docs/javascript-debugging
+ // this makes source maps inside style tags work properly in Chrome
+ css += '\n/*# sourceURL=' + sourceMap.sources[0] + ' */'
+ // http://stackoverflow.com/a/26603875
+ css += '\n/*# sourceMappingURL=data:application/json;base64,' + btoa(unescape(encodeURIComponent(JSON.stringify(sourceMap)))) + ' */'
+ }
+
+ if (styleElement.styleSheet) {
+ styleElement.styleSheet.cssText = css
+ } else {
+ while (styleElement.firstChild) {
+ styleElement.removeChild(styleElement.firstChild)
+ }
+ styleElement.appendChild(document.createTextNode(css))
+ }
+}
diff --git a/node_modules/vue-style-loader/lib/addStylesServer.js b/node_modules/vue-style-loader/lib/addStylesServer.js
new file mode 100644
index 00000000..e80492fb
--- /dev/null
+++ b/node_modules/vue-style-loader/lib/addStylesServer.js
@@ -0,0 +1,80 @@
+import listToStyles from './listToStyles'
+
+export default function addStylesServer (parentId, list, isProduction, context) {
+ if (!context && typeof __VUE_SSR_CONTEXT__ !== 'undefined') {
+ context = __VUE_SSR_CONTEXT__
+ }
+ if (context) {
+ if (!context.hasOwnProperty('styles')) {
+ Object.defineProperty(context, 'styles', {
+ enumerable: true,
+ get: function() {
+ return renderStyles(context._styles)
+ }
+ })
+ // expose renderStyles for vue-server-renderer (vuejs/#6353)
+ context._renderStyles = renderStyles
+ }
+
+ var styles = context._styles || (context._styles = {})
+ list = listToStyles(parentId, list)
+ if (isProduction) {
+ addStyleProd(styles, list)
+ } else {
+ addStyleDev(styles, list)
+ }
+ }
+}
+
+// In production, render as few style tags as possible.
+// (mostly because IE9 has a limit on number of style tags)
+function addStyleProd (styles, list) {
+ for (var i = 0; i < list.length; i++) {
+ var parts = list[i].parts
+ for (var j = 0; j < parts.length; j++) {
+ var part = parts[j]
+ // group style tags by media types.
+ var id = part.media || 'default'
+ var style = styles[id]
+ if (style) {
+ if (style.ids.indexOf(part.id) < 0) {
+ style.ids.push(part.id)
+ style.css += '\n' + part.css
+ }
+ } else {
+ styles[id] = {
+ ids: [part.id],
+ css: part.css,
+ media: part.media
+ }
+ }
+ }
+ }
+}
+
+// In dev we use individual style tag for each module for hot-reload
+// and source maps.
+function addStyleDev (styles, list) {
+ for (var i = 0; i < list.length; i++) {
+ var parts = list[i].parts
+ for (var j = 0; j < parts.length; j++) {
+ var part = parts[j]
+ styles[part.id] = {
+ ids: [part.id],
+ css: part.css,
+ media: part.media
+ }
+ }
+ }
+}
+
+function renderStyles (styles) {
+ var css = ''
+ for (var key in styles) {
+ var style = styles[key]
+ css += '<style data-vue-ssr-id="' + style.ids.join(' ') + '"' +
+ (style.media ? ( ' media="' + style.media + '"' ) : '') + '>' +
+ style.css + '</style>'
+ }
+ return css
+}
diff --git a/node_modules/vue-style-loader/lib/addStylesShadow.js b/node_modules/vue-style-loader/lib/addStylesShadow.js
new file mode 100644
index 00000000..72947108
--- /dev/null
+++ b/node_modules/vue-style-loader/lib/addStylesShadow.js
@@ -0,0 +1,70 @@
+import listToStyles from './listToStyles'
+
+export default function addStylesToShadowDOM (parentId, list, shadowRoot) {
+ var styles = listToStyles(parentId, list)
+ addStyles(styles, shadowRoot)
+}
+
+/*
+type StyleObject = {
+ id: number;
+ parts: Array<StyleObjectPart>
+}
+
+type StyleObjectPart = {
+ css: string;
+ media: string;
+ sourceMap: ?string
+}
+*/
+
+function addStyles (styles /* Array<StyleObject> */, shadowRoot) {
+ const injectedStyles =
+ shadowRoot._injectedStyles ||
+ (shadowRoot._injectedStyles = {})
+ for (var i = 0; i < styles.length; i++) {
+ var item = styles[i]
+ var style = injectedStyles[item.id]
+ if (!style) {
+ for (var j = 0; j < item.parts.length; j++) {
+ addStyle(item.parts[j], shadowRoot)
+ }
+ injectedStyles[item.id] = true
+ }
+ }
+}
+
+function createStyleElement (shadowRoot) {
+ var styleElement = document.createElement('style')
+ styleElement.type = 'text/css'
+ shadowRoot.appendChild(styleElement)
+ return styleElement
+}
+
+function addStyle (obj /* StyleObjectPart */, shadowRoot) {
+ var styleElement = createStyleElement(shadowRoot)
+ var css = obj.css
+ var media = obj.media
+ var sourceMap = obj.sourceMap
+
+ if (media) {
+ styleElement.setAttribute('media', media)
+ }
+
+ if (sourceMap) {
+ // https://developer.chrome.com/devtools/docs/javascript-debugging
+ // this makes source maps inside style tags work properly in Chrome
+ css += '\n/*# sourceURL=' + sourceMap.sources[0] + ' */'
+ // http://stackoverflow.com/a/26603875
+ css += '\n/*# sourceMappingURL=data:application/json;base64,' + btoa(unescape(encodeURIComponent(JSON.stringify(sourceMap)))) + ' */'
+ }
+
+ if (styleElement.styleSheet) {
+ styleElement.styleSheet.cssText = css
+ } else {
+ while (styleElement.firstChild) {
+ styleElement.removeChild(styleElement.firstChild)
+ }
+ styleElement.appendChild(document.createTextNode(css))
+ }
+}
diff --git a/node_modules/vue-style-loader/lib/listToStyles.js b/node_modules/vue-style-loader/lib/listToStyles.js
new file mode 100644
index 00000000..bc86bb40
--- /dev/null
+++ b/node_modules/vue-style-loader/lib/listToStyles.js
@@ -0,0 +1,27 @@
+/**
+ * Translates the list format produced by css-loader into something
+ * easier to manipulate.
+ */
+export default function listToStyles (parentId, list) {
+ var styles = []
+ var newStyles = {}
+ for (var i = 0; i < list.length; i++) {
+ var item = list[i]
+ var id = item[0]
+ var css = item[1]
+ var media = item[2]
+ var sourceMap = item[3]
+ var part = {
+ id: parentId + ':' + i,
+ css: css,
+ media: media,
+ sourceMap: sourceMap
+ }
+ if (!newStyles[id]) {
+ styles.push(newStyles[id] = { id: id, parts: [part] })
+ } else {
+ newStyles[id].parts.push(part)
+ }
+ }
+ return styles
+}