-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: copy style-loader runtime files
- Loading branch information
Showing
13 changed files
with
401 additions
and
0 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
packages/shared/compiled/style-loader/runtime/injectStylesIntoLinkTag.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
"use strict"; | ||
|
||
module.exports = function (url, options) { | ||
if (typeof document === "undefined") { | ||
return function () {}; | ||
} | ||
options = options || {}; | ||
options.attributes = typeof options.attributes === "object" ? options.attributes : {}; | ||
if (typeof options.attributes.nonce === "undefined") { | ||
var nonce = typeof __webpack_nonce__ !== "undefined" ? __webpack_nonce__ : null; | ||
if (nonce) { | ||
options.attributes.nonce = nonce; | ||
} | ||
} | ||
var linkElement = document.createElement("link"); | ||
linkElement.rel = "stylesheet"; | ||
linkElement.href = url; | ||
Object.keys(options.attributes).forEach(function (key) { | ||
linkElement.setAttribute(key, options.attributes[key]); | ||
}); | ||
options.insert(linkElement); | ||
return function (newUrl) { | ||
if (typeof newUrl === "string") { | ||
linkElement.href = newUrl; | ||
} else { | ||
linkElement.parentNode.removeChild(linkElement); | ||
} | ||
}; | ||
}; |
84 changes: 84 additions & 0 deletions
84
packages/shared/compiled/style-loader/runtime/injectStylesIntoStyleTag.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
"use strict"; | ||
|
||
var stylesInDOM = []; | ||
function getIndexByIdentifier(identifier) { | ||
var result = -1; | ||
for (var i = 0; i < stylesInDOM.length; i++) { | ||
if (stylesInDOM[i].identifier === identifier) { | ||
result = i; | ||
break; | ||
} | ||
} | ||
return result; | ||
} | ||
function modulesToDom(list, options) { | ||
var idCountMap = {}; | ||
var identifiers = []; | ||
for (var i = 0; i < list.length; i++) { | ||
var item = list[i]; | ||
var id = options.base ? item[0] + options.base : item[0]; | ||
var count = idCountMap[id] || 0; | ||
var identifier = "".concat(id, " ").concat(count); | ||
idCountMap[id] = count + 1; | ||
var indexByIdentifier = getIndexByIdentifier(identifier); | ||
var obj = { | ||
css: item[1], | ||
media: item[2], | ||
sourceMap: item[3], | ||
supports: item[4], | ||
layer: item[5] | ||
}; | ||
if (indexByIdentifier !== -1) { | ||
stylesInDOM[indexByIdentifier].references++; | ||
stylesInDOM[indexByIdentifier].updater(obj); | ||
} else { | ||
var updater = addElementStyle(obj, options); | ||
options.byIndex = i; | ||
stylesInDOM.splice(i, 0, { | ||
identifier: identifier, | ||
updater: updater, | ||
references: 1 | ||
}); | ||
} | ||
identifiers.push(identifier); | ||
} | ||
return identifiers; | ||
} | ||
function addElementStyle(obj, options) { | ||
var api = options.domAPI(options); | ||
api.update(obj); | ||
var updater = function updater(newObj) { | ||
if (newObj) { | ||
if (newObj.css === obj.css && newObj.media === obj.media && newObj.sourceMap === obj.sourceMap && newObj.supports === obj.supports && newObj.layer === obj.layer) { | ||
return; | ||
} | ||
api.update(obj = newObj); | ||
} else { | ||
api.remove(); | ||
} | ||
}; | ||
return updater; | ||
} | ||
module.exports = function (list, options) { | ||
options = options || {}; | ||
list = list || []; | ||
var lastIdentifiers = modulesToDom(list, options); | ||
return function update(newList) { | ||
newList = newList || []; | ||
for (var i = 0; i < lastIdentifiers.length; i++) { | ||
var identifier = lastIdentifiers[i]; | ||
var index = getIndexByIdentifier(identifier); | ||
stylesInDOM[index].references--; | ||
} | ||
var newLastIdentifiers = modulesToDom(newList, options); | ||
for (var _i = 0; _i < lastIdentifiers.length; _i++) { | ||
var _identifier = lastIdentifiers[_i]; | ||
var _index = getIndexByIdentifier(_identifier); | ||
if (stylesInDOM[_index].references === 0) { | ||
stylesInDOM[_index].updater(); | ||
stylesInDOM.splice(_index, 1); | ||
} | ||
} | ||
lastIdentifiers = newLastIdentifiers; | ||
}; | ||
}; |
34 changes: 34 additions & 0 deletions
34
packages/shared/compiled/style-loader/runtime/insertBySelector.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
"use strict"; | ||
|
||
var memo = {}; | ||
|
||
/* istanbul ignore next */ | ||
function getTarget(target) { | ||
if (typeof memo[target] === "undefined") { | ||
var styleTarget = document.querySelector(target); | ||
|
||
// Special case to return head of iframe instead of iframe itself | ||
if (window.HTMLIFrameElement && styleTarget instanceof window.HTMLIFrameElement) { | ||
try { | ||
// This will throw an exception if access to iframe is blocked | ||
// due to cross-origin restrictions | ||
styleTarget = styleTarget.contentDocument.head; | ||
} catch (e) { | ||
// istanbul ignore next | ||
styleTarget = null; | ||
} | ||
} | ||
memo[target] = styleTarget; | ||
} | ||
return memo[target]; | ||
} | ||
|
||
/* istanbul ignore next */ | ||
function insertBySelector(insert, style) { | ||
var target = getTarget(insert); | ||
if (!target) { | ||
throw new Error("Couldn't find a style target. This probably means that the value for the 'insert' parameter is invalid."); | ||
} | ||
target.appendChild(style); | ||
} | ||
module.exports = insertBySelector; |
10 changes: 10 additions & 0 deletions
10
packages/shared/compiled/style-loader/runtime/insertStyleElement.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
"use strict"; | ||
|
||
/* istanbul ignore next */ | ||
function insertStyleElement(options) { | ||
var element = document.createElement("style"); | ||
options.setAttributes(element, options.attributes); | ||
options.insert(element, options.options); | ||
return element; | ||
} | ||
module.exports = insertStyleElement; |
28 changes: 28 additions & 0 deletions
28
packages/shared/compiled/style-loader/runtime/isEqualLocals.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
"use strict"; | ||
|
||
function isEqualLocals(a, b, isNamedExport) { | ||
if (!a && b || a && !b) { | ||
return false; | ||
} | ||
var p; | ||
for (p in a) { | ||
if (isNamedExport && p === "default") { | ||
// eslint-disable-next-line no-continue | ||
continue; | ||
} | ||
if (a[p] !== b[p]) { | ||
return false; | ||
} | ||
} | ||
for (p in b) { | ||
if (isNamedExport && p === "default") { | ||
// eslint-disable-next-line no-continue | ||
continue; | ||
} | ||
if (!a[p]) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
module.exports = isEqualLocals; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
"use strict"; | ||
|
||
var memo; | ||
|
||
/* istanbul ignore next */ | ||
function isOldIE() { | ||
if (typeof memo === "undefined") { | ||
// Test for IE <= 9 as proposed by Browserhacks | ||
// @see http://browserhacks.com/#hack-e71d8692f65334173fee715c222cb805 | ||
// Tests for existence of standard globals is to allow style-loader | ||
// to operate correctly into non-standard environments | ||
// @see https://github.com/webpack-contrib/style-loader/issues/177 | ||
memo = Boolean(typeof window !== "undefined" && typeof document !== "undefined" && document.all && !window.atob); | ||
} | ||
return memo; | ||
} | ||
module.exports = isOldIE; |
13 changes: 13 additions & 0 deletions
13
packages/shared/compiled/style-loader/runtime/setAttributesWithAttributes.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
"use strict"; | ||
|
||
/* istanbul ignore next */ | ||
function setAttributesWithoutAttributes(styleElement, attributes) { | ||
var nonce = typeof __webpack_nonce__ !== "undefined" ? __webpack_nonce__ : null; | ||
if (nonce) { | ||
attributes.nonce = nonce; | ||
} | ||
Object.keys(attributes).forEach(function (key) { | ||
styleElement.setAttribute(key, attributes[key]); | ||
}); | ||
} | ||
module.exports = setAttributesWithoutAttributes; |
9 changes: 9 additions & 0 deletions
9
packages/shared/compiled/style-loader/runtime/setAttributesWithAttributesAndNonce.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
"use strict"; | ||
|
||
/* istanbul ignore next */ | ||
function setAttributesWithoutAttributes(styleElement, attributes) { | ||
Object.keys(attributes).forEach(function (key) { | ||
styleElement.setAttribute(key, attributes[key]); | ||
}); | ||
} | ||
module.exports = setAttributesWithoutAttributes; |
10 changes: 10 additions & 0 deletions
10
packages/shared/compiled/style-loader/runtime/setAttributesWithoutAttributes.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
"use strict"; | ||
|
||
/* istanbul ignore next */ | ||
function setAttributesWithoutAttributes(styleElement) { | ||
var nonce = typeof __webpack_nonce__ !== "undefined" ? __webpack_nonce__ : null; | ||
if (nonce) { | ||
styleElement.setAttribute("nonce", nonce); | ||
} | ||
} | ||
module.exports = setAttributesWithoutAttributes; |
86 changes: 86 additions & 0 deletions
86
packages/shared/compiled/style-loader/runtime/singletonStyleDomAPI.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
"use strict"; | ||
|
||
/* istanbul ignore next */ | ||
var replaceText = function replaceText() { | ||
var textStore = []; | ||
return function replace(index, replacement) { | ||
textStore[index] = replacement; | ||
return textStore.filter(Boolean).join("\n"); | ||
}; | ||
}(); | ||
|
||
/* istanbul ignore next */ | ||
function apply(styleElement, index, remove, obj) { | ||
var css; | ||
if (remove) { | ||
css = ""; | ||
} else { | ||
css = ""; | ||
if (obj.supports) { | ||
css += "@supports (".concat(obj.supports, ") {"); | ||
} | ||
if (obj.media) { | ||
css += "@media ".concat(obj.media, " {"); | ||
} | ||
var needLayer = typeof obj.layer !== "undefined"; | ||
if (needLayer) { | ||
css += "@layer".concat(obj.layer.length > 0 ? " ".concat(obj.layer) : "", " {"); | ||
} | ||
css += obj.css; | ||
if (needLayer) { | ||
css += "}"; | ||
} | ||
if (obj.media) { | ||
css += "}"; | ||
} | ||
if (obj.supports) { | ||
css += "}"; | ||
} | ||
} | ||
|
||
// For old IE | ||
/* istanbul ignore if */ | ||
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); | ||
} | ||
} | ||
} | ||
var singletonData = { | ||
singleton: null, | ||
singletonCounter: 0 | ||
}; | ||
|
||
/* istanbul ignore next */ | ||
function domAPI(options) { | ||
if (typeof document === "undefined") return { | ||
update: function update() {}, | ||
remove: function remove() {} | ||
}; | ||
|
||
// eslint-disable-next-line no-undef,no-use-before-define | ||
var styleIndex = singletonData.singletonCounter++; | ||
var styleElement = | ||
// eslint-disable-next-line no-undef,no-use-before-define | ||
singletonData.singleton || ( | ||
// eslint-disable-next-line no-undef,no-use-before-define | ||
singletonData.singleton = options.insertStyleElement(options)); | ||
return { | ||
update: function update(obj) { | ||
apply(styleElement, styleIndex, false, obj); | ||
}, | ||
remove: function remove(obj) { | ||
apply(styleElement, styleIndex, true, obj); | ||
} | ||
}; | ||
} | ||
module.exports = domAPI; |
Oops, something went wrong.