skatejs-named-slots
Advanced tools
Comparing version 0.2.5 to 0.2.6
2057
dist/index.js
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(factory((global.skatejsNamedSlots = global.skatejsNamedSlots || {}))); | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(factory((global.skatejsNamedSlots = global.skatejsNamedSlots || {}))); | ||
}(this, function (exports) { | ||
var babelHelpers = {}; | ||
function eachChildNode(node, func) { | ||
if (!node) { | ||
return; | ||
} | ||
babelHelpers.toConsumableArray = function (arr) { | ||
if (Array.isArray(arr)) { | ||
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; | ||
var chs = node.childNodes; | ||
var chsLen = chs.length; | ||
for (var a = 0; a < chsLen; a++) { | ||
var ret = func(chs[a], a, chs); | ||
if (typeof ret !== 'undefined') { | ||
return ret; // eslint-disable-line consistent-return | ||
} | ||
} | ||
} | ||
return arr2; | ||
} else { | ||
return Array.from(arr); | ||
} | ||
}; | ||
function eachNodeOrFragmentNodes(node, func) { | ||
if (node instanceof DocumentFragment) { | ||
var chs = node.childNodes; | ||
var chsLen = chs.length; | ||
for (var a = 0; a < chsLen; a++) { | ||
func(chs[a], a); | ||
} | ||
} else { | ||
func(node, 0); | ||
} | ||
} | ||
babelHelpers; | ||
var div = document.createElement('div'); | ||
function getPrototype(obj, key) { | ||
var descriptor = void 0; | ||
function __commonjs(fn, module) { return module = { exports: {} }, fn(module, module.exports), module.exports; } | ||
while (obj && !(descriptor = Object.getOwnPropertyDescriptor(obj, key))) { | ||
// eslint-disable-line no-cond-assign | ||
obj = Object.getPrototypeOf(obj); | ||
} | ||
return descriptor; | ||
} | ||
function getPropertyDescriptor (obj, key) { | ||
if (obj instanceof Node) { | ||
obj = div; | ||
} | ||
var proto = getPrototype(obj, key); | ||
function eachChildNode(node, func) { | ||
if (!node) { | ||
return; | ||
} | ||
if (proto) { | ||
var getter = proto.get; | ||
var setter = proto.set; | ||
var _descriptor = { | ||
configurable: true, | ||
enumerable: true | ||
}; | ||
var chs = node.childNodes; | ||
var chsLen = chs.length; | ||
for (var a = 0; a < chsLen; a++) { | ||
var ret = func(chs[a], a, chs); | ||
if (typeof ret !== 'undefined') { | ||
return ret; // eslint-disable-line consistent-return | ||
} | ||
} | ||
} | ||
if (getter) { | ||
_descriptor.get = getter; | ||
_descriptor.set = setter; | ||
return _descriptor; | ||
} else if (typeof obj[key] === 'function') { | ||
_descriptor.value = obj[key]; | ||
return _descriptor; | ||
} | ||
} | ||
function eachNodeOrFragmentNodes(node, func) { | ||
if (node instanceof DocumentFragment) { | ||
var chs = node.childNodes; | ||
var chsLen = chs.length; | ||
for (var a = 0; a < chsLen; a++) { | ||
func(chs[a], a); | ||
} | ||
} else { | ||
func(node, 0); | ||
} | ||
} | ||
var descriptor = Object.getOwnPropertyDescriptor(obj, key); | ||
if (descriptor && descriptor.get) { | ||
return descriptor; | ||
} | ||
} | ||
var div = document.createElement('div'); | ||
var nativeParentNode = getPropertyDescriptor(Element.prototype, 'innerHTML'); | ||
function getPrototype(obj, key) { | ||
var descriptor = void 0; | ||
var canPatchNativeAccessors = !!nativeParentNode; | ||
while (obj && !(descriptor = Object.getOwnPropertyDescriptor(obj, key))) { | ||
// eslint-disable-line no-cond-assign | ||
obj = Object.getPrototypeOf(obj); | ||
} | ||
return descriptor; | ||
} | ||
function getPropertyDescriptor (obj, key) { | ||
if (obj instanceof Node) { | ||
obj = div; | ||
} | ||
var proto = getPrototype(obj, key); | ||
function createCommonjsModule(fn, module) { | ||
return module = { exports: {} }, fn(module, module.exports), module.exports; | ||
} | ||
if (proto) { | ||
var getter = proto.get; | ||
var setter = proto.set; | ||
var _descriptor = { | ||
configurable: true, | ||
enumerable: true | ||
}; | ||
var index$1 = createCommonjsModule(function (module) { | ||
module.exports = Date.now || now; | ||
if (getter) { | ||
_descriptor.get = getter; | ||
_descriptor.set = setter; | ||
return _descriptor; | ||
} else if (typeof obj[key] === 'function') { | ||
_descriptor.value = obj[key]; | ||
return _descriptor; | ||
} | ||
} | ||
function now() { | ||
return new Date().getTime(); | ||
} | ||
}); | ||
var descriptor = Object.getOwnPropertyDescriptor(obj, key); | ||
if (descriptor && descriptor.get) { | ||
return descriptor; | ||
} | ||
} | ||
var require$$0 = (index$1 && typeof index$1 === 'object' && 'default' in index$1 ? index$1['default'] : index$1); | ||
var nativeParentNode = getPropertyDescriptor(Element.prototype, 'innerHTML'); | ||
var index = createCommonjsModule(function (module) { | ||
/** | ||
* Module dependencies. | ||
*/ | ||
var canPatchNativeAccessors = !!nativeParentNode; | ||
var now = require$$0; | ||
var index$1 = __commonjs(function (module) { | ||
module.exports = Date.now || now; | ||
/** | ||
* Returns a function, that, as long as it continues to be invoked, will not | ||
* be triggered. The function will be called after it stops being called for | ||
* N milliseconds. If `immediate` is passed, trigger the function on the | ||
* leading edge, instead of the trailing. | ||
* | ||
* @source underscore.js | ||
* @see http://unscriptable.com/2009/03/20/debouncing-javascript-methods/ | ||
* @param {Function} function to wrap | ||
* @param {Number} timeout in ms (`100`) | ||
* @param {Boolean} whether to execute at the beginning (`false`) | ||
* @api public | ||
*/ | ||
function now() { | ||
return new Date().getTime(); | ||
} | ||
}); | ||
module.exports = function debounce(func, wait, immediate) { | ||
var timeout, args, context, timestamp, result; | ||
if (null == wait) wait = 100; | ||
var require$$0 = (index$1 && typeof index$1 === 'object' && 'default' in index$1 ? index$1['default'] : index$1); | ||
function later() { | ||
var last = now() - timestamp; | ||
var index = __commonjs(function (module) { | ||
/** | ||
* Module dependencies. | ||
*/ | ||
if (last < wait && last > 0) { | ||
timeout = setTimeout(later, wait - last); | ||
} else { | ||
timeout = null; | ||
if (!immediate) { | ||
result = func.apply(context, args); | ||
if (!timeout) context = args = null; | ||
} | ||
} | ||
}; | ||
var now = require$$0; | ||
return function debounced() { | ||
context = this; | ||
args = arguments; | ||
timestamp = now(); | ||
var callNow = immediate && !timeout; | ||
if (!timeout) timeout = setTimeout(later, wait); | ||
if (callNow) { | ||
result = func.apply(context, args); | ||
context = args = null; | ||
} | ||
/** | ||
* Returns a function, that, as long as it continues to be invoked, will not | ||
* be triggered. The function will be called after it stops being called for | ||
* N milliseconds. If `immediate` is passed, trigger the function on the | ||
* leading edge, instead of the trailing. | ||
* | ||
* @source underscore.js | ||
* @see http://unscriptable.com/2009/03/20/debouncing-javascript-methods/ | ||
* @param {Function} function to wrap | ||
* @param {Number} timeout in ms (`100`) | ||
* @param {Boolean} whether to execute at the beginning (`false`) | ||
* @api public | ||
*/ | ||
return result; | ||
}; | ||
}; | ||
}); | ||
module.exports = function debounce(func, wait, immediate) { | ||
var timeout, args, context, timestamp, result; | ||
if (null == wait) wait = 100; | ||
var debounce = (index && typeof index === 'object' && 'default' in index ? index['default'] : index); | ||
function later() { | ||
var last = now() - timestamp; | ||
/** | ||
* See https://w3c.github.io/DOM-Parsing/#serializing | ||
* @param {TextNode} | ||
* @returns {string} | ||
*/ | ||
function getEscapedTextContent(textNode) { | ||
return textNode.textContent.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>'); | ||
} | ||
if (last < wait && last > 0) { | ||
timeout = setTimeout(later, wait - last); | ||
} else { | ||
timeout = null; | ||
if (!immediate) { | ||
result = func.apply(context, args); | ||
if (!timeout) context = args = null; | ||
} | ||
} | ||
}; | ||
/** | ||
* @returns {string} | ||
* @param {commentNode} | ||
*/ | ||
function getCommentNodeOuterHtml(commentNode) { | ||
return commentNode.text || "<!--" + commentNode.textContent + "-->"; | ||
} | ||
return function debounced() { | ||
context = this; | ||
args = arguments; | ||
timestamp = now(); | ||
var callNow = immediate && !timeout; | ||
if (!timeout) timeout = setTimeout(later, wait); | ||
if (callNow) { | ||
result = func.apply(context, args); | ||
context = args = null; | ||
} | ||
function isSlotNode (node) { | ||
return node.tagName === 'SLOT'; | ||
} | ||
return result; | ||
}; | ||
}; | ||
}); | ||
function findSlots(root) { | ||
var slots = arguments.length <= 1 || arguments[1] === undefined ? [] : arguments[1]; | ||
var childNodes = root.childNodes; | ||
var debounce = (index && typeof index === 'object' && 'default' in index ? index['default'] : index); | ||
/** | ||
* See https://w3c.github.io/DOM-Parsing/#serializing | ||
* @param {TextNode} | ||
* @returns {string} | ||
*/ | ||
function getEscapedTextContent(textNode) { | ||
return textNode.textContent.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>'); | ||
} | ||
if (!childNodes || root.nodeType !== Node.ELEMENT_NODE) { | ||
return slots; | ||
} | ||
/** | ||
* @returns {string} | ||
* @param {commentNode} | ||
*/ | ||
function getCommentNodeOuterHtml(commentNode) { | ||
return commentNode.text || "<!--" + commentNode.textContent + "-->"; | ||
} | ||
var length = childNodes.length; | ||
var version = '0.0.1'; | ||
/** | ||
* @license | ||
* Copyright (c) 2014 The Polymer Project Authors. All rights reserved. | ||
* This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt | ||
* The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt | ||
* The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt | ||
* Code distributed by Google as part of the polymer project is also | ||
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt | ||
*/ | ||
for (var a = 0; a < length; a++) { | ||
var childNode = childNodes[a]; | ||
if (typeof WeakMap === 'undefined') { | ||
(function () { | ||
var defineProperty = Object.defineProperty; | ||
var counter = Date.now() % 1e9; | ||
if (isSlotNode(childNode)) { | ||
slots.push(childNode); | ||
} | ||
var WeakMap = function WeakMap() { | ||
this.name = '__st' + (Math.random() * 1e9 >>> 0) + (counter++ + '__'); | ||
}; | ||
findSlots(childNode, slots); | ||
} | ||
WeakMap.prototype = { | ||
set: function set(key, value) { | ||
var entry = key[this.name]; | ||
if (entry && entry[0] === key) entry[1] = value;else defineProperty(key, this.name, { value: [key, value], writable: true }); | ||
return this; | ||
}, | ||
get: function get(key) { | ||
var entry; | ||
return (entry = key[this.name]) && entry[0] === key ? entry[1] : undefined; | ||
}, | ||
delete: function _delete(key) { | ||
var entry = key[this.name]; | ||
if (!entry || entry[0] !== key) return false; | ||
entry[0] = entry[1] = undefined; | ||
return true; | ||
}, | ||
has: function has(key) { | ||
var entry = key[this.name]; | ||
if (!entry) return false; | ||
return entry[0] === key; | ||
} | ||
}; | ||
return slots; | ||
} | ||
window.WeakMap = WeakMap; | ||
})(); | ||
} | ||
function isRootNode (node) { | ||
return node.tagName === '_SHADOW_ROOT_'; | ||
} | ||
// Polyfill for creating CustomEvents on IE9/10/11 | ||
var version = '0.0.1'; | ||
// code pulled from: | ||
// https://github.com/d4tocchini/customevent-polyfill | ||
// https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent#Polyfill | ||
/** | ||
* @license | ||
* Copyright (c) 2014 The Polymer Project Authors. All rights reserved. | ||
* This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt | ||
* The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt | ||
* The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt | ||
* Code distributed by Google as part of the polymer project is also | ||
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt | ||
*/ | ||
try { | ||
var ce = new window.CustomEvent('test', { | ||
bubbles: false, | ||
cancelable: true, | ||
detail: { | ||
x: 'y' | ||
} | ||
}); | ||
ce.preventDefault(); | ||
if (ce.defaultPrevented !== true) { | ||
// IE has problems with .preventDefault() on custom events | ||
// http://stackoverflow.com/questions/23349191 | ||
throw new Error('Could not prevent default'); | ||
} | ||
} catch (e) { | ||
var CustomEvent$1 = function CustomEvent(event, params) { | ||
var evt; | ||
params = params || { | ||
bubbles: false, | ||
cancelable: false, | ||
detail: undefined | ||
}; | ||
if (typeof WeakMap === 'undefined') { | ||
(function () { | ||
var defineProperty = Object.defineProperty; | ||
var counter = Date.now() % 1e9; | ||
evt = document.createEvent("CustomEvent"); | ||
evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail); | ||
var origPrevent = evt.preventDefault; | ||
evt.preventDefault = function () { | ||
origPrevent.call(this); | ||
try { | ||
Object.defineProperty(this, 'defaultPrevented', { | ||
get: function get() { | ||
return true; | ||
} | ||
}); | ||
} catch (e) { | ||
this.defaultPrevented = true; | ||
} | ||
}; | ||
return evt; | ||
}; | ||
var WeakMap = function WeakMap() { | ||
this.name = '__st' + (Math.random() * 1e9 >>> 0) + (counter++ + '__'); | ||
}; | ||
CustomEvent$1.prototype = window.Event.prototype; | ||
window.CustomEvent = CustomEvent$1; // expose definition to window | ||
} | ||
WeakMap.prototype = { | ||
set: function set(key, value) { | ||
var entry = key[this.name]; | ||
if (entry && entry[0] === key) entry[1] = value;else defineProperty(key, this.name, { value: [key, value], writable: true }); | ||
return this; | ||
}, | ||
get: function get(key) { | ||
var entry; | ||
return (entry = key[this.name]) && entry[0] === key ? entry[1] : undefined; | ||
}, | ||
delete: function _delete(key) { | ||
var entry = key[this.name]; | ||
if (!entry || entry[0] !== key) return false; | ||
entry[0] = entry[1] = undefined; | ||
return true; | ||
}, | ||
has: function has(key) { | ||
var entry = key[this.name]; | ||
if (!entry) return false; | ||
return entry[0] === key; | ||
} | ||
}; | ||
var arrProto = Array.prototype; | ||
var forEach = arrProto.forEach; | ||
window.WeakMap = WeakMap; | ||
})(); | ||
} | ||
// We use a real DOM node for a shadow root. This is because the host node | ||
// basically becomes a virtual entry point for your element leaving the shadow | ||
// root the only thing that can receive instructions on how the host should | ||
// render to the browser. | ||
// Polyfill for creating CustomEvents on IE9/10/11 | ||
var defaultShadowRootTagName = '_shadow_root_'; | ||
var defaultShadowRootTagNameUc = defaultShadowRootTagName.toUpperCase(); | ||
// code pulled from: | ||
// https://github.com/d4tocchini/customevent-polyfill | ||
// https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent#Polyfill | ||
// * WebKit only * | ||
// | ||
// These members we need cannot override as we require native access to their | ||
// original values at some point. | ||
var polyfillAtRuntime = ['childNodes', 'parentNode']; | ||
try { | ||
var ce = new window.CustomEvent('test', { | ||
bubbles: false, | ||
cancelable: true, | ||
detail: { | ||
x: 'y' | ||
} | ||
}); | ||
ce.preventDefault(); | ||
if (ce.defaultPrevented !== true) { | ||
// IE has problems with .preventDefault() on custom events | ||
// http://stackoverflow.com/questions/23349191 | ||
throw new Error('Could not prevent default'); | ||
} | ||
} catch (e) { | ||
var CustomEvent$1 = function CustomEvent(event, params) { | ||
var evt; | ||
params = params || { | ||
bubbles: false, | ||
cancelable: false, | ||
detail: undefined | ||
}; | ||
// Some properties that should not be overridden in the Text prototype. | ||
var doNotOverridePropertiesInTextNodes = ['textContent']; | ||
evt = document.createEvent("CustomEvent"); | ||
evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail); | ||
var origPrevent = evt.preventDefault; | ||
evt.preventDefault = function () { | ||
origPrevent.call(this); | ||
try { | ||
Object.defineProperty(this, 'defaultPrevented', { | ||
get: function get() { | ||
return true; | ||
} | ||
}); | ||
} catch (e) { | ||
this.defaultPrevented = true; | ||
} | ||
}; | ||
return evt; | ||
}; | ||
// Some new properties that should be defined in the Text prototype. | ||
var defineInTextNodes = ['assignedSlot']; | ||
CustomEvent$1.prototype = window.Event.prototype; | ||
window.CustomEvent = CustomEvent$1; // expose definition to window | ||
} | ||
// Some properties that should not be overridden in the Comment prototype. | ||
var doNotOverridePropertiesInCommNodes = ['textContent']; | ||
var toConsumableArray = function (arr) { | ||
if (Array.isArray(arr)) { | ||
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; | ||
// Some new properties that should be defined in the Comment prototype. | ||
var defineInCommNodes = []; | ||
return arr2; | ||
} else { | ||
return Array.from(arr); | ||
} | ||
}; | ||
// Nodes that should be slotted | ||
var slottedNodeTypes = [Node.ELEMENT_NODE, Node.TEXT_NODE]; | ||
var arrProto = Array.prototype; | ||
var forEach = arrProto.forEach; | ||
// Private data stores. | ||
var assignedToSlotMap = new WeakMap(); | ||
var hostToModeMap = new WeakMap(); | ||
var hostToRootMap = new WeakMap(); | ||
var nodeToChildNodesMap = new WeakMap(); | ||
var nodeToParentNodeMap = new WeakMap(); | ||
var nodeToSlotMap = new WeakMap(); | ||
var rootToHostMap = new WeakMap(); | ||
var rootToSlotMap = new WeakMap(); | ||
var slotToRootMap = new WeakMap(); | ||
// We use a real DOM node for a shadow root. This is because the host node | ||
// basically becomes a virtual entry point for your element leaving the shadow | ||
// root the only thing that can receive instructions on how the host should | ||
// render to the browser. | ||
// Unfortunately manual DOM parsing is because of WebKit. | ||
var parser = new DOMParser(); | ||
function parse(html) { | ||
var tree = document.createElement('div'); | ||
var defaultShadowRootTagName = '_shadow_root_'; | ||
// Everything not WebKit can do this easily. | ||
if (canPatchNativeAccessors) { | ||
tree.__innerHTML = html; | ||
return tree; | ||
} | ||
// * WebKit only * | ||
// | ||
// These members we need cannot override as we require native access to their | ||
// original values at some point. | ||
var polyfillAtRuntime = ['childNodes', 'parentNode']; | ||
var parsed = parser.parseFromString('<div>' + html + '</div>', 'text/html').body.firstChild; | ||
// Some properties that should not be overridden in the Text prototype. | ||
var doNotOverridePropertiesInTextNodes = ['textContent']; | ||
while (parsed.hasChildNodes()) { | ||
var firstChild = parsed.firstChild; | ||
parsed.removeChild(firstChild); | ||
tree.appendChild(firstChild); | ||
} | ||
// Some new properties that should be defined in the Text prototype. | ||
var defineInTextNodes = ['assignedSlot']; | ||
// Need to import the node to initialise the custom elements from the parser. | ||
return document.importNode(tree, true); | ||
} | ||
// Some properties that should not be overridden in the Comment prototype. | ||
var doNotOverridePropertiesInCommNodes = ['textContent']; | ||
function staticProp(obj, name, value) { | ||
Object.defineProperty(obj, name, { | ||
configurable: true, | ||
get: function get() { | ||
return value; | ||
} | ||
}); | ||
} | ||
// Some new properties that should be defined in the Comment prototype. | ||
var defineInCommNodes = []; | ||
// Slotting helpers. | ||
// Nodes that should be slotted | ||
var slottedNodeTypes = [Node.ELEMENT_NODE, Node.TEXT_NODE]; | ||
function arrayItem(idx) { | ||
return this[idx]; | ||
} | ||
// Private data stores. | ||
var assignedToSlotMap = new WeakMap(); | ||
var hostToModeMap = new WeakMap(); | ||
var hostToRootMap = new WeakMap(); | ||
var nodeToChildNodesMap = new WeakMap(); | ||
var nodeToParentNodeMap = new WeakMap(); | ||
var nodeToSlotMap = new WeakMap(); | ||
var rootToHostMap = new WeakMap(); | ||
var rootToSlotMap = new WeakMap(); | ||
var slotToRootMap = new WeakMap(); | ||
function makeLikeNodeList(arr) { | ||
arr.item = arrayItem; | ||
return arr; | ||
} | ||
// Unfortunately manual DOM parsing is because of WebKit. | ||
var parser = new DOMParser(); | ||
function parse(html) { | ||
var tree = document.createElement('div'); | ||
function isHostNode(node) { | ||
return !!hostToRootMap.get(node); | ||
} | ||
// Everything not WebKit can do this easily. | ||
if (canPatchNativeAccessors) { | ||
tree.__innerHTML = html; | ||
return tree; | ||
} | ||
function isSlotNode(node) { | ||
return node.tagName === 'SLOT'; | ||
} | ||
var parsed = parser.parseFromString('<div>' + html + '</div>', 'text/html').body.firstChild; | ||
function isRootNode(node) { | ||
return node.tagName === defaultShadowRootTagNameUc; | ||
} | ||
while (parsed.hasChildNodes()) { | ||
var firstChild = parsed.firstChild; | ||
parsed.removeChild(firstChild); | ||
tree.appendChild(firstChild); | ||
} | ||
function getNodeType(node) { | ||
if (isHostNode(node)) { | ||
return 'host'; | ||
} | ||
// Need to import the node to initialise the custom elements from the parser. | ||
return document.importNode(tree, true); | ||
} | ||
if (isSlotNode(node)) { | ||
return 'slot'; | ||
} | ||
function staticProp(obj, name, value) { | ||
Object.defineProperty(obj, name, { | ||
configurable: true, | ||
get: function get() { | ||
return value; | ||
} | ||
}); | ||
} | ||
if (isRootNode(node)) { | ||
return 'root'; | ||
} | ||
// Slotting helpers. | ||
return 'node'; | ||
} | ||
function arrayItem(idx) { | ||
return this[idx]; | ||
} | ||
function findClosest(node, func) { | ||
while (node) { | ||
if (node === document) { | ||
break; | ||
} | ||
if (func(node)) { | ||
return node; | ||
} | ||
node = node.parentNode; | ||
} | ||
} | ||
function makeLikeNodeList(arr) { | ||
arr.item = arrayItem; | ||
return arr; | ||
} | ||
function getSlotNameFromSlot(node) { | ||
return node.getAttribute && node.getAttribute('name') || 'default'; | ||
} | ||
function isHostNode(node) { | ||
return !!hostToRootMap.get(node); | ||
} | ||
function getSlotNameFromNode(node) { | ||
return node.getAttribute && node.getAttribute('slot') || 'default'; | ||
} | ||
function getNodeType(node) { | ||
if (isHostNode(node)) { | ||
return 'host'; | ||
} | ||
function slotNodeIntoSlot(slot, node, insertBefore) { | ||
// Don't slot nodes that have content but are only whitespace. This is an | ||
// anomaly that I don't think the spec deals with. | ||
// | ||
// The problem is: | ||
// | ||
// - If you insert HTML with indentation into the page, there will be | ||
// whitespace and if that's inserted it messes with fallback content | ||
// calculation where there is formatting, but no meaningful content, so in | ||
// theory it should fallback. Since you can attach a shadow root after we | ||
// mean to insert an empty text node and have it "count", we can't really | ||
// discard nodes that are considered formatting at the time of attachment. | ||
// - You can insert a text node and modify its text content later. | ||
// Incremental DOM seems to do this. Every way I look at it, it seems | ||
// problematic that we should have to screen for content, but I don't seems | ||
// much of a way around it at the moment. | ||
if (node.nodeType === 3 && node.textContent && node.textContent.trim().length === 0) { | ||
return; | ||
} | ||
if (isSlotNode(node)) { | ||
return 'slot'; | ||
} | ||
// only Text and Element nodes should be slotted | ||
if (slottedNodeTypes.indexOf(node.nodeType) === -1) { | ||
return; | ||
} | ||
if (isRootNode(node)) { | ||
return 'root'; | ||
} | ||
var assignedNodes = slot.assignedNodes(); | ||
var shouldGoIntoContentMode = assignedNodes.length === 0; | ||
var slotInsertBeforeIndex = assignedNodes.indexOf(insertBefore); | ||
return 'node'; | ||
} | ||
// Assign the slot to the node internally. | ||
nodeToSlotMap.set(node, slot); | ||
function findClosest(node, func) { | ||
while (node) { | ||
if (node === document) { | ||
break; | ||
} | ||
if (func(node)) { | ||
return node; | ||
} | ||
node = node.parentNode; | ||
} | ||
} | ||
// Remove the fallback content and state if we're going into content mode. | ||
if (shouldGoIntoContentMode) { | ||
forEach.call(slot.childNodes, function (child) { | ||
return slot.__removeChild(child); | ||
}); | ||
} | ||
function getSlotNameFromSlot(node) { | ||
return node.getAttribute && node.getAttribute('name') || 'default'; | ||
} | ||
if (slotInsertBeforeIndex > -1) { | ||
slot.__insertBefore(node, insertBefore !== undefined ? insertBefore : null); | ||
assignedNodes.splice(slotInsertBeforeIndex, 0, node); | ||
} else { | ||
slot.__appendChild(node); | ||
assignedNodes.push(node); | ||
} | ||
function getSlotNameFromNode(node) { | ||
return node.getAttribute && node.getAttribute('slot') || 'default'; | ||
} | ||
slot.____triggerSlotChangeEvent(); | ||
} | ||
function slotNodeIntoSlot(slot, node, insertBefore) { | ||
// Don't slot nodes that have content but are only whitespace. This is an | ||
// anomaly that I don't think the spec deals with. | ||
// | ||
// The problem is: | ||
// | ||
// - If you insert HTML with indentation into the page, there will be | ||
// whitespace and if that's inserted it messes with fallback content | ||
// calculation where there is formatting, but no meaningful content, so in | ||
// theory it should fallback. Since you can attach a shadow root after we | ||
// mean to insert an empty text node and have it "count", we can't really | ||
// discard nodes that are considered formatting at the time of attachment. | ||
// - You can insert a text node and modify its text content later. | ||
// Incremental DOM seems to do this. Every way I look at it, it seems | ||
// problematic that we should have to screen for content, but I don't seems | ||
// much of a way around it at the moment. | ||
if (node.nodeType === 3 && node.textContent && node.textContent.trim().length === 0) { | ||
return; | ||
} | ||
function slotNodeFromSlot(node) { | ||
var slot = node.assignedSlot; | ||
// only Text and Element nodes should be slotted | ||
if (slottedNodeTypes.indexOf(node.nodeType) === -1) { | ||
return; | ||
} | ||
if (slot) { | ||
var assignedNodes = slot.assignedNodes(); | ||
var index = assignedNodes.indexOf(node); | ||
var assignedNodes = slot.assignedNodes(); | ||
var shouldGoIntoContentMode = assignedNodes.length === 0; | ||
var slotInsertBeforeIndex = assignedNodes.indexOf(insertBefore); | ||
if (index > -1) { | ||
var shouldGoIntoDefaultMode = assignedNodes.length === 1; | ||
// Assign the slot to the node internally. | ||
nodeToSlotMap.set(node, slot); | ||
assignedNodes.splice(index, 1); | ||
nodeToSlotMap.set(node, null); | ||
// Remove the fallback content and state if we're going into content mode. | ||
if (shouldGoIntoContentMode) { | ||
forEach.call(slot.childNodes, function (child) { | ||
return slot.__removeChild(child); | ||
}); | ||
} | ||
// Actually remove the child. | ||
slot.__removeChild(node); | ||
if (slotInsertBeforeIndex > -1) { | ||
slot.__insertBefore(node, insertBefore !== undefined ? insertBefore : null); | ||
assignedNodes.splice(slotInsertBeforeIndex, 0, node); | ||
} else { | ||
slot.__appendChild(node); | ||
assignedNodes.push(node); | ||
} | ||
// If this was the last slotted node, then insert fallback content. | ||
if (shouldGoIntoDefaultMode) { | ||
forEach.call(slot.childNodes, function (child) { | ||
return slot.__appendChild(child); | ||
}); | ||
} | ||
slot.____triggerSlotChangeEvent(); | ||
} | ||
slot.____triggerSlotChangeEvent(); | ||
} | ||
} | ||
} | ||
function slotNodeFromSlot(node) { | ||
var slot = node.assignedSlot; | ||
// Returns the index of the node in the host's childNodes. | ||
function indexOfNode(host, node) { | ||
var chs = host.childNodes; | ||
var chsLen = chs.length; | ||
for (var a = 0; a < chsLen; a++) { | ||
if (chs[a] === node) { | ||
return a; | ||
} | ||
} | ||
return -1; | ||
} | ||
if (slot) { | ||
var assignedNodes = slot.assignedNodes(); | ||
var index = assignedNodes.indexOf(node); | ||
// Adds the node to the list of childNodes on the host and fakes any necessary | ||
// information such as parentNode. | ||
function registerNode(host, node, insertBefore, func) { | ||
var index = indexOfNode(host, insertBefore); | ||
eachNodeOrFragmentNodes(node, function (eachNode, eachIndex) { | ||
func(eachNode, eachIndex); | ||
if (index > -1) { | ||
var shouldGoIntoDefaultMode = assignedNodes.length === 1; | ||
if (canPatchNativeAccessors) { | ||
nodeToParentNodeMap.set(eachNode, host); | ||
} else { | ||
staticProp(eachNode, 'parentNode', host); | ||
} | ||
assignedNodes.splice(index, 1); | ||
nodeToSlotMap.set(node, null); | ||
if (index > -1) { | ||
arrProto.splice.call(host.childNodes, index + eachIndex, 0, eachNode); | ||
} else { | ||
arrProto.push.call(host.childNodes, eachNode); | ||
} | ||
}); | ||
} | ||
// Actually remove the child. | ||
slot.__removeChild(node); | ||
// Cleans up registerNode(). | ||
function unregisterNode(host, node, func) { | ||
var index = indexOfNode(host, node); | ||
// If this was the last slotted node, then insert fallback content. | ||
if (shouldGoIntoDefaultMode) { | ||
forEach.call(slot.childNodes, function (child) { | ||
return slot.__appendChild(child); | ||
}); | ||
} | ||
if (index > -1) { | ||
func(node, 0); | ||
slot.____triggerSlotChangeEvent(); | ||
} | ||
} | ||
} | ||
if (canPatchNativeAccessors) { | ||
nodeToParentNodeMap.set(node, null); | ||
} else { | ||
staticProp(node, 'parentNode', null); | ||
} | ||
// Returns the index of the node in the host's childNodes. | ||
function indexOfNode(host, node) { | ||
var chs = host.childNodes; | ||
var chsLen = chs.length; | ||
for (var a = 0; a < chsLen; a++) { | ||
if (chs[a] === node) { | ||
return a; | ||
} | ||
} | ||
return -1; | ||
} | ||
arrProto.splice.call(host.childNodes, index, 1); | ||
} | ||
} | ||
// Adds the node to the list of childNodes on the host and fakes any necessary | ||
// information such as parentNode. | ||
function registerNode(host, node, insertBefore, func) { | ||
var index = indexOfNode(host, insertBefore); | ||
eachNodeOrFragmentNodes(node, function (eachNode, eachIndex) { | ||
func(eachNode, eachIndex); | ||
function addNodeToNode(host, node, insertBefore) { | ||
registerNode(host, node, insertBefore, function (eachNode) { | ||
host.__insertBefore(eachNode, insertBefore !== undefined ? insertBefore : null); | ||
}); | ||
} | ||
if (canPatchNativeAccessors) { | ||
nodeToParentNodeMap.set(eachNode, host); | ||
} else { | ||
staticProp(eachNode, 'parentNode', host); | ||
} | ||
function addNodeToHost(host, node, insertBefore) { | ||
registerNode(host, node, insertBefore, function (eachNode) { | ||
var rootNode = hostToRootMap.get(host); | ||
var slotNodes = rootToSlotMap.get(rootNode); | ||
var slotNode = slotNodes[getSlotNameFromNode(eachNode)]; | ||
if (slotNode) { | ||
slotNodeIntoSlot(slotNode, eachNode, insertBefore); | ||
} | ||
}); | ||
} | ||
if (index > -1) { | ||
arrProto.splice.call(host.childNodes, index + eachIndex, 0, eachNode); | ||
} else { | ||
arrProto.push.call(host.childNodes, eachNode); | ||
} | ||
}); | ||
} | ||
function addSlotToRoot(root, slot) { | ||
var slotName = getSlotNameFromSlot(slot); | ||
// Cleans up registerNode(). | ||
function unregisterNode(host, node, func) { | ||
var index = indexOfNode(host, node); | ||
// Ensure a slot node's childNodes are overridden at the earliest point | ||
// possible for WebKit. | ||
if (!canPatchNativeAccessors && !slot.childNodes.push) { | ||
staticProp(slot, 'childNodes', [].concat(babelHelpers.toConsumableArray(slot.childNodes))); | ||
} | ||
if (index > -1) { | ||
func(node, 0); | ||
rootToSlotMap.get(root)[slotName] = slot; | ||
if (canPatchNativeAccessors) { | ||
nodeToParentNodeMap.set(node, null); | ||
} else { | ||
staticProp(node, 'parentNode', null); | ||
} | ||
if (!slotToRootMap.has(slot)) { | ||
slotToRootMap.set(slot, root); | ||
} | ||
arrProto.splice.call(host.childNodes, index, 1); | ||
} | ||
} | ||
eachChildNode(rootToHostMap.get(root), function (eachNode) { | ||
if (!eachNode.assignedSlot && slotName === getSlotNameFromNode(eachNode)) { | ||
slotNodeIntoSlot(slot, eachNode); | ||
} | ||
}); | ||
} | ||
function addNodeToNode(host, node, insertBefore) { | ||
registerNode(host, node, insertBefore, function (eachNode) { | ||
host.__insertBefore(eachNode, insertBefore !== undefined ? insertBefore : null); | ||
}); | ||
} | ||
function addNodeToRoot(root, node, insertBefore) { | ||
eachNodeOrFragmentNodes(node, function (child) { | ||
if (isSlotNode(child)) { | ||
addSlotToRoot(root, child); | ||
} else { | ||
var slotNodes = child.querySelectorAll && child.querySelectorAll('slot'); | ||
if (slotNodes) { | ||
var slotNodesLen = slotNodes.length; | ||
for (var a = 0; a < slotNodesLen; a++) { | ||
addSlotToRoot(root, slotNodes[a]); | ||
} | ||
} | ||
} | ||
}); | ||
addNodeToNode(root, node, insertBefore); | ||
} | ||
function addNodeToHost(host, node, insertBefore) { | ||
registerNode(host, node, insertBefore, function (eachNode) { | ||
var rootNode = hostToRootMap.get(host); | ||
var slotNodes = rootToSlotMap.get(rootNode); | ||
var slotNode = slotNodes[getSlotNameFromNode(eachNode)]; | ||
if (slotNode) { | ||
slotNodeIntoSlot(slotNode, eachNode, insertBefore); | ||
} | ||
}); | ||
} | ||
// Adds a node to a slot. In other words, adds default content to a slot. It | ||
// ensures that if the slot doesn't have any assigned nodes yet, that the node | ||
// is actually displayed, otherwise it's just registered as child content. | ||
function addNodeToSlot(slot, node, insertBefore) { | ||
var isInDefaultMode = slot.assignedNodes().length === 0; | ||
registerNode(slot, node, insertBefore, function (eachNode) { | ||
if (isInDefaultMode) { | ||
slot.__insertBefore(eachNode, insertBefore !== undefined ? insertBefore : null); | ||
} | ||
}); | ||
} | ||
function addSlotToRoot(root, slot) { | ||
var slotName = getSlotNameFromSlot(slot); | ||
// Removes a node from a slot (default content). It ensures that if the slot | ||
// doesn't have any assigned nodes yet, that the node is actually removed, | ||
// otherwise it's just unregistered. | ||
function removeNodeFromSlot(slot, node) { | ||
var isInDefaultMode = slot.assignedNodes().length === 0; | ||
unregisterNode(slot, node, function () { | ||
if (isInDefaultMode) { | ||
slot.__removeChild(node); | ||
} | ||
}); | ||
} | ||
// Ensure a slot node's childNodes are overridden at the earliest point | ||
// possible for WebKit. | ||
if (!canPatchNativeAccessors && !slot.childNodes.push) { | ||
staticProp(slot, 'childNodes', [].concat(toConsumableArray(slot.childNodes))); | ||
} | ||
function removeNodeFromNode(host, node) { | ||
unregisterNode(host, node, function () { | ||
host.__removeChild(node); | ||
}); | ||
} | ||
rootToSlotMap.get(root)[slotName] = slot; | ||
function removeNodeFromHost(host, node) { | ||
unregisterNode(host, node, function () { | ||
slotNodeFromSlot(node); | ||
}); | ||
} | ||
if (!slotToRootMap.has(slot)) { | ||
slotToRootMap.set(slot, root); | ||
} | ||
function removeSlotFromRoot(root, node) { | ||
node.assignedNodes().forEach(slotNodeFromSlot); | ||
delete rootToSlotMap.get(root)[getSlotNameFromSlot(node)]; | ||
slotToRootMap.delete(node); | ||
} | ||
eachChildNode(rootToHostMap.get(root), function (eachNode) { | ||
if (!eachNode.assignedSlot && slotName === getSlotNameFromNode(eachNode)) { | ||
slotNodeIntoSlot(slot, eachNode); | ||
} | ||
}); | ||
} | ||
function removeNodeFromRoot(root, node) { | ||
unregisterNode(root, node, function () { | ||
if (isSlotNode(node)) { | ||
removeSlotFromRoot(root, node); | ||
} else { | ||
var nodes = node.querySelectorAll && node.querySelectorAll('slot'); | ||
if (nodes) { | ||
for (var a = 0; a < nodes.length; a++) { | ||
removeSlotFromRoot(root, nodes[a]); | ||
} | ||
} | ||
} | ||
root.__removeChild(node); | ||
}); | ||
} | ||
function addNodeToRoot(root, node, insertBefore) { | ||
eachNodeOrFragmentNodes(node, function (child) { | ||
if (isSlotNode(child)) { | ||
addSlotToRoot(root, child); | ||
} else { | ||
var slotNodes = findSlots(child); | ||
if (slotNodes) { | ||
var slotNodesLen = slotNodes.length; | ||
for (var a = 0; a < slotNodesLen; a++) { | ||
addSlotToRoot(root, slotNodes[a]); | ||
} | ||
} | ||
} | ||
}); | ||
addNodeToNode(root, node, insertBefore); | ||
} | ||
// TODO terribly inefficient | ||
function getRootNode(host) { | ||
if (isRootNode(host)) { | ||
return host; | ||
} | ||
// Adds a node to a slot. In other words, adds default content to a slot. It | ||
// ensures that if the slot doesn't have any assigned nodes yet, that the node | ||
// is actually displayed, otherwise it's just registered as child content. | ||
function addNodeToSlot(slot, node, insertBefore) { | ||
var isInDefaultMode = slot.assignedNodes().length === 0; | ||
registerNode(slot, node, insertBefore, function (eachNode) { | ||
if (isInDefaultMode) { | ||
slot.__insertBefore(eachNode, insertBefore !== undefined ? insertBefore : null); | ||
} | ||
}); | ||
} | ||
if (!host.parentNode) { | ||
return; | ||
} | ||
// Removes a node from a slot (default content). It ensures that if the slot | ||
// doesn't have any assigned nodes yet, that the node is actually removed, | ||
// otherwise it's just unregistered. | ||
function removeNodeFromSlot(slot, node) { | ||
var isInDefaultMode = slot.assignedNodes().length === 0; | ||
unregisterNode(slot, node, function () { | ||
if (isInDefaultMode) { | ||
slot.__removeChild(node); | ||
} | ||
}); | ||
} | ||
return getRootNode(host.parentNode); | ||
} | ||
function removeNodeFromNode(host, node) { | ||
unregisterNode(host, node, function () { | ||
host.__removeChild(node); | ||
}); | ||
} | ||
function appendChildOrInsertBefore(host, newNode, refNode) { | ||
var nodeType = getNodeType(host); | ||
var parentNode = newNode.parentNode; | ||
var rootNode = getRootNode(host); | ||
function removeNodeFromHost(host, node) { | ||
unregisterNode(host, node, function () { | ||
slotNodeFromSlot(node); | ||
}); | ||
} | ||
// Ensure childNodes is patched so we can manually update it for WebKit. | ||
if (!canPatchNativeAccessors && !host.childNodes.push) { | ||
staticProp(host, 'childNodes', [].concat(babelHelpers.toConsumableArray(host.childNodes))); | ||
} | ||
function removeSlotFromRoot(root, node) { | ||
node.assignedNodes().forEach(slotNodeFromSlot); | ||
delete rootToSlotMap.get(root)[getSlotNameFromSlot(node)]; | ||
slotToRootMap.delete(node); | ||
} | ||
if (rootNode && getNodeType(newNode) === 'slot') { | ||
addSlotToRoot(rootNode, newNode); | ||
} | ||
function removeNodeFromRoot(root, node) { | ||
unregisterNode(root, node, function () { | ||
if (isSlotNode(node)) { | ||
removeSlotFromRoot(root, node); | ||
} else { | ||
var nodes = findSlots(node); | ||
if (nodes) { | ||
for (var a = 0; a < nodes.length; a++) { | ||
removeSlotFromRoot(root, nodes[a]); | ||
} | ||
} | ||
} | ||
root.__removeChild(node); | ||
}); | ||
} | ||
// If we append a child to a host, the host tells the shadow root to distribute | ||
// it. If the root decides it doesn't need to be distributed, it is never | ||
// removed from the old parent because in polyfill land we store a reference | ||
// to the node but we don't move it. Due to that, we must explicitly remove the | ||
// node from its old parent. | ||
if (parentNode && getNodeType(parentNode) === 'host') { | ||
if (canPatchNativeAccessors) { | ||
nodeToParentNodeMap.set(newNode, null); | ||
} else { | ||
staticProp(newNode, 'parentNode', null); | ||
} | ||
} | ||
// TODO terribly inefficient | ||
function getRootNode(host) { | ||
if (isRootNode(host)) { | ||
return host; | ||
} | ||
if (nodeType === 'node') { | ||
if (canPatchNativeAccessors) { | ||
nodeToParentNodeMap.set(newNode, host); | ||
return host.__insertBefore(newNode, refNode !== undefined ? refNode : null); | ||
} | ||
if (!host.parentNode) { | ||
return; | ||
} | ||
return addNodeToNode(host, newNode, refNode); | ||
} | ||
return getRootNode(host.parentNode); | ||
} | ||
if (nodeType === 'slot') { | ||
return addNodeToSlot(host, newNode, refNode); | ||
} | ||
function appendChildOrInsertBefore(host, newNode, refNode) { | ||
var nodeType = getNodeType(host); | ||
var parentNode = newNode.parentNode; | ||
var rootNode = getRootNode(host); | ||
if (nodeType === 'host') { | ||
return addNodeToHost(host, newNode, refNode); | ||
} | ||
// Ensure childNodes is patched so we can manually update it for WebKit. | ||
if (!canPatchNativeAccessors && !host.childNodes.push) { | ||
staticProp(host, 'childNodes', [].concat(toConsumableArray(host.childNodes))); | ||
} | ||
if (nodeType === 'root') { | ||
return addNodeToRoot(host, newNode, refNode); | ||
} | ||
} | ||
if (rootNode && getNodeType(newNode) === 'slot') { | ||
addSlotToRoot(rootNode, newNode); | ||
} | ||
function syncSlotChildNodes(node) { | ||
if (canPatchNativeAccessors && getNodeType(node) === 'slot' && node.__childNodes.length !== node.childNodes.length) { | ||
while (node.hasChildNodes()) { | ||
node.removeChild(node.firstChild); | ||
} | ||
// If we append a child to a host, the host tells the shadow root to distribute | ||
// it. If the root decides it doesn't need to be distributed, it is never | ||
// removed from the old parent because in polyfill land we store a reference | ||
// to the node but we don't move it. Due to that, we must explicitly remove the | ||
// node from its old parent. | ||
if (parentNode && getNodeType(parentNode) === 'host') { | ||
if (canPatchNativeAccessors) { | ||
nodeToParentNodeMap.set(newNode, null); | ||
} else { | ||
staticProp(newNode, 'parentNode', null); | ||
} | ||
} | ||
forEach.call(node.__childNodes, function (child) { | ||
return node.appendChild(child); | ||
}); | ||
} | ||
} | ||
if (nodeType === 'node') { | ||
if (canPatchNativeAccessors) { | ||
nodeToParentNodeMap.set(newNode, host); | ||
return host.__insertBefore(newNode, refNode !== undefined ? refNode : null); | ||
} | ||
var members = { | ||
// For testing purposes. | ||
____assignedNodes: { | ||
get: function get() { | ||
return this.______assignedNodes || (this.______assignedNodes = []); | ||
} | ||
}, | ||
return addNodeToNode(host, newNode, refNode); | ||
} | ||
// For testing purposes. | ||
____isInFallbackMode: { | ||
get: function get() { | ||
return this.assignedNodes().length === 0; | ||
} | ||
}, | ||
if (nodeType === 'slot') { | ||
return addNodeToSlot(host, newNode, refNode); | ||
} | ||
____slotChangeListeners: { | ||
get: function get() { | ||
if (typeof this.______slotChangeListeners === 'undefined') { | ||
this.______slotChangeListeners = 0; | ||
} | ||
return this.______slotChangeListeners; | ||
}, | ||
set: function set(value) { | ||
this.______slotChangeListeners = value; | ||
} | ||
}, | ||
____triggerSlotChangeEvent: { | ||
value: debounce(function callback() { | ||
if (this.____slotChangeListeners) { | ||
this.dispatchEvent(new CustomEvent('slotchange', { | ||
bubbles: false, | ||
cancelable: false | ||
})); | ||
} | ||
}) | ||
}, | ||
addEventListener: { | ||
value: function value(name, func, opts) { | ||
if (name === 'slotchange' && isSlotNode(this)) { | ||
this.____slotChangeListeners++; | ||
} | ||
return this.__addEventListener(name, func, opts); | ||
} | ||
}, | ||
appendChild: { | ||
value: function value(newNode) { | ||
appendChildOrInsertBefore(this, newNode); | ||
return newNode; | ||
} | ||
}, | ||
assignedSlot: { | ||
get: function get() { | ||
var slot = nodeToSlotMap.get(this); | ||
if (nodeType === 'host') { | ||
return addNodeToHost(host, newNode, refNode); | ||
} | ||
if (!slot) { | ||
return null; | ||
} | ||
if (nodeType === 'root') { | ||
return addNodeToRoot(host, newNode, refNode); | ||
} | ||
} | ||
var root = slotToRootMap.get(slot); | ||
var host = rootToHostMap.get(root); | ||
var mode = hostToModeMap.get(host); | ||
function syncSlotChildNodes(node) { | ||
if (canPatchNativeAccessors && getNodeType(node) === 'slot' && node.__childNodes.length !== node.childNodes.length) { | ||
while (node.hasChildNodes()) { | ||
node.removeChild(node.firstChild); | ||
} | ||
return mode === 'open' ? slot : null; | ||
} | ||
}, | ||
attachShadow: { | ||
value: function value(opts) { | ||
var _this = this; | ||
forEach.call(node.__childNodes, function (child) { | ||
return node.appendChild(child); | ||
}); | ||
} | ||
} | ||
var mode = opts && opts.mode; | ||
if (mode !== 'closed' && mode !== 'open') { | ||
throw new Error('You must specify { mode } as "open" or "closed" to attachShadow().'); | ||
} | ||
var members = { | ||
// For testing purposes. | ||
____assignedNodes: { | ||
get: function get() { | ||
return this.______assignedNodes || (this.______assignedNodes = []); | ||
} | ||
}, | ||
// Return the existing shadow root if it exists. | ||
var existingShadowRoot = hostToRootMap.get(this); | ||
if (existingShadowRoot) { | ||
return existingShadowRoot; | ||
} | ||
// For testing purposes. | ||
____isInFallbackMode: { | ||
get: function get() { | ||
return this.assignedNodes().length === 0; | ||
} | ||
}, | ||
var lightNodes = makeLikeNodeList([].slice.call(this.childNodes)); | ||
var shadowRoot = document.createElement(opts.polyfillShadowRootTagName || defaultShadowRootTagName); | ||
____slotChangeListeners: { | ||
get: function get() { | ||
if (typeof this.______slotChangeListeners === 'undefined') { | ||
this.______slotChangeListeners = 0; | ||
} | ||
return this.______slotChangeListeners; | ||
}, | ||
set: function set(value) { | ||
this.______slotChangeListeners = value; | ||
} | ||
}, | ||
____triggerSlotChangeEvent: { | ||
value: debounce(function callback() { | ||
if (this.____slotChangeListeners) { | ||
this.dispatchEvent(new CustomEvent('slotchange', { | ||
bubbles: false, | ||
cancelable: false | ||
})); | ||
} | ||
}) | ||
}, | ||
addEventListener: { | ||
value: function value(name, func, opts) { | ||
if (name === 'slotchange' && isSlotNode(this)) { | ||
this.____slotChangeListeners++; | ||
} | ||
return this.__addEventListener(name, func, opts); | ||
} | ||
}, | ||
appendChild: { | ||
value: function value(newNode) { | ||
appendChildOrInsertBefore(this, newNode); | ||
return newNode; | ||
} | ||
}, | ||
assignedSlot: { | ||
get: function get() { | ||
var slot = nodeToSlotMap.get(this); | ||
// Host and shadow root data. | ||
hostToModeMap.set(this, mode); | ||
hostToRootMap.set(this, shadowRoot); | ||
rootToHostMap.set(shadowRoot, this); | ||
rootToSlotMap.set(shadowRoot, {}); | ||
if (!slot) { | ||
return null; | ||
} | ||
if (canPatchNativeAccessors) { | ||
nodeToChildNodesMap.set(this, lightNodes); | ||
} else { | ||
staticProp(this, 'childNodes', lightNodes); | ||
} | ||
var root = slotToRootMap.get(slot); | ||
var host = rootToHostMap.get(root); | ||
var mode = hostToModeMap.get(host); | ||
// Process light DOM. | ||
lightNodes.forEach(function (node) { | ||
// Existing children should be removed from being displayed, but still | ||
// appear to be child nodes. This is how light DOM works; they're still | ||
// child nodes but not in the composed DOM yet as there won't be any | ||
// slots for them to go into. | ||
_this.__removeChild(node); | ||
return mode === 'open' ? slot : null; | ||
} | ||
}, | ||
attachShadow: { | ||
value: function value(opts) { | ||
var _this = this; | ||
// We must register the parentNode here as this has the potential to | ||
// become out of sync if the node is moved before being slotted. | ||
if (canPatchNativeAccessors) { | ||
nodeToParentNodeMap.set(node, _this); | ||
} else { | ||
staticProp(node, 'parentNode', _this); | ||
} | ||
}); | ||
var mode = opts && opts.mode; | ||
if (mode !== 'closed' && mode !== 'open') { | ||
throw new Error('You must specify { mode } as "open" or "closed" to attachShadow().'); | ||
} | ||
// The shadow root is actually the only child of the host. | ||
return this.__appendChild(shadowRoot); | ||
} | ||
}, | ||
childElementCount: { | ||
get: function get() { | ||
return this.children.length; | ||
} | ||
}, | ||
childNodes: { | ||
get: function get() { | ||
if (canPatchNativeAccessors && getNodeType(this) === 'node') { | ||
return this.__childNodes; | ||
} | ||
var childNodes = nodeToChildNodesMap.get(this); | ||
// Return the existing shadow root if it exists. | ||
var existingShadowRoot = hostToRootMap.get(this); | ||
if (existingShadowRoot) { | ||
return existingShadowRoot; | ||
} | ||
if (!childNodes) { | ||
nodeToChildNodesMap.set(this, childNodes = makeLikeNodeList([])); | ||
} | ||
var lightNodes = makeLikeNodeList([].slice.call(this.childNodes)); | ||
var shadowRoot = document.createElement(opts.polyfillShadowRootTagName || defaultShadowRootTagName); | ||
return childNodes; | ||
} | ||
}, | ||
children: { | ||
get: function get() { | ||
var chs = []; | ||
eachChildNode(this, function (node) { | ||
if (node.nodeType === 1) { | ||
chs.push(node); | ||
} | ||
}); | ||
return makeLikeNodeList(chs); | ||
} | ||
}, | ||
firstChild: { | ||
get: function get() { | ||
return this.childNodes[0] || null; | ||
} | ||
}, | ||
firstElementChild: { | ||
get: function get() { | ||
return this.children[0] || null; | ||
} | ||
}, | ||
assignedNodes: { | ||
value: function value() { | ||
if (isSlotNode(this)) { | ||
var assigned = assignedToSlotMap.get(this); | ||
// Host and shadow root data. | ||
hostToModeMap.set(this, mode); | ||
hostToRootMap.set(this, shadowRoot); | ||
rootToHostMap.set(shadowRoot, this); | ||
rootToSlotMap.set(shadowRoot, {}); | ||
if (!assigned) { | ||
assignedToSlotMap.set(this, assigned = []); | ||
} | ||
if (canPatchNativeAccessors) { | ||
nodeToChildNodesMap.set(this, lightNodes); | ||
} else { | ||
staticProp(this, 'childNodes', lightNodes); | ||
} | ||
return assigned; | ||
} | ||
} | ||
}, | ||
hasChildNodes: { | ||
value: function value() { | ||
return this.childNodes.length > 0; | ||
} | ||
}, | ||
innerHTML: { | ||
get: function get() { | ||
var innerHTML = ''; | ||
// Process light DOM. | ||
lightNodes.forEach(function (node) { | ||
// Existing children should be removed from being displayed, but still | ||
// appear to be child nodes. This is how light DOM works; they're still | ||
// child nodes but not in the composed DOM yet as there won't be any | ||
// slots for them to go into. | ||
_this.__removeChild(node); | ||
var getHtmlNodeOuterHtml = function getHtmlNodeOuterHtml(node) { | ||
return node.outerHTML; | ||
}; | ||
var getOuterHtmlByNodeType = { | ||
1: getHtmlNodeOuterHtml, | ||
3: getEscapedTextContent, | ||
8: getCommentNodeOuterHtml | ||
}; | ||
// We must register the parentNode here as this has the potential to | ||
// become out of sync if the node is moved before being slotted. | ||
if (canPatchNativeAccessors) { | ||
nodeToParentNodeMap.set(node, _this); | ||
} else { | ||
staticProp(node, 'parentNode', _this); | ||
} | ||
}); | ||
eachChildNode(this, function (node) { | ||
var getOuterHtml = getOuterHtmlByNodeType[node.nodeType] || getHtmlNodeOuterHtml; | ||
innerHTML += getOuterHtml(node); | ||
}); | ||
return innerHTML; | ||
}, | ||
set: function set(innerHTML) { | ||
var parsed = parse(innerHTML); | ||
// The shadow root is actually the only child of the host. | ||
return this.__appendChild(shadowRoot); | ||
} | ||
}, | ||
childElementCount: { | ||
get: function get() { | ||
return this.children.length; | ||
} | ||
}, | ||
childNodes: { | ||
get: function get() { | ||
if (canPatchNativeAccessors && getNodeType(this) === 'node') { | ||
return this.__childNodes; | ||
} | ||
var childNodes = nodeToChildNodesMap.get(this); | ||
while (this.hasChildNodes()) { | ||
this.removeChild(this.firstChild); | ||
} | ||
if (!childNodes) { | ||
nodeToChildNodesMap.set(this, childNodes = makeLikeNodeList([])); | ||
} | ||
// when we are doing this: root.innerHTML = "<slot><div></div></slot>"; | ||
// slot.__childNodes is out of sync with slot.childNodes. | ||
// to fix it we have to manually remove and insert them | ||
var slots = parsed.querySelectorAll('slot'); | ||
forEach.call(slots, function (slot) { | ||
return syncSlotChildNodes(slot); | ||
}); | ||
return childNodes; | ||
} | ||
}, | ||
children: { | ||
get: function get() { | ||
var chs = []; | ||
eachChildNode(this, function (node) { | ||
if (node.nodeType === 1) { | ||
chs.push(node); | ||
} | ||
}); | ||
return makeLikeNodeList(chs); | ||
} | ||
}, | ||
firstChild: { | ||
get: function get() { | ||
return this.childNodes[0] || null; | ||
} | ||
}, | ||
firstElementChild: { | ||
get: function get() { | ||
return this.children[0] || null; | ||
} | ||
}, | ||
assignedNodes: { | ||
value: function value() { | ||
if (isSlotNode(this)) { | ||
var assigned = assignedToSlotMap.get(this); | ||
while (parsed.hasChildNodes()) { | ||
var firstChild = parsed.firstChild; | ||
if (!assigned) { | ||
assignedToSlotMap.set(this, assigned = []); | ||
} | ||
// When we polyfill everything on HTMLElement.prototype, we overwrite | ||
// properties. This makes it so that parentNode reports null even though | ||
// it's actually a parent of the HTML parser. For this reason, | ||
// cleanNode() won't work and we must manually remove it from the | ||
// parser before it is moved to the host just in case it's added as a | ||
// light node but not assigned to a slot. | ||
parsed.removeChild(firstChild); | ||
return assigned; | ||
} | ||
} | ||
}, | ||
hasChildNodes: { | ||
value: function value() { | ||
return this.childNodes.length > 0; | ||
} | ||
}, | ||
innerHTML: { | ||
get: function get() { | ||
var innerHTML = ''; | ||
this.appendChild(firstChild); | ||
} | ||
} | ||
}, | ||
insertBefore: { | ||
value: function value(newNode, refNode) { | ||
appendChildOrInsertBefore(this, newNode, refNode); | ||
var getHtmlNodeOuterHtml = function getHtmlNodeOuterHtml(node) { | ||
return node.outerHTML; | ||
}; | ||
var getOuterHtmlByNodeType = { | ||
1: getHtmlNodeOuterHtml, | ||
3: getEscapedTextContent, | ||
8: getCommentNodeOuterHtml | ||
}; | ||
return newNode; | ||
} | ||
}, | ||
lastChild: { | ||
get: function get() { | ||
var ch = this.childNodes; | ||
return ch[ch.length - 1] || null; | ||
} | ||
}, | ||
lastElementChild: { | ||
get: function get() { | ||
var ch = this.children; | ||
return ch[ch.length - 1] || null; | ||
} | ||
}, | ||
name: { | ||
get: function get() { | ||
return this.getAttribute('name'); | ||
}, | ||
set: function set(name) { | ||
return this.setAttribute('name', name); | ||
} | ||
}, | ||
nextSibling: { | ||
get: function get() { | ||
var host = this; | ||
return eachChildNode(this.parentNode, function (child, index, nodes) { | ||
if (host === child) { | ||
return nodes[index + 1] || null; | ||
} | ||
}); | ||
} | ||
}, | ||
nextElementSibling: { | ||
get: function get() { | ||
var host = this; | ||
var found = void 0; | ||
return eachChildNode(this.parentNode, function (child) { | ||
if (found && child.nodeType === 1) { | ||
return child; | ||
} | ||
if (host === child) { | ||
found = true; | ||
} | ||
}); | ||
} | ||
}, | ||
outerHTML: { | ||
get: function get() { | ||
var name = this.tagName.toLowerCase(); | ||
var attributes = Array.prototype.slice.call(this.attributes).map(function (attr) { | ||
return ' ' + attr.name + (attr.value ? '="' + attr.value + '"' : ''); | ||
}).join(''); | ||
return '<' + name + attributes + '>' + this.innerHTML + '</' + name + '>'; | ||
}, | ||
set: function set(outerHTML) { | ||
if (this.parentNode) { | ||
var parsed = parse(outerHTML); | ||
this.parentNode.replaceChild(parsed.firstChild, this); | ||
} else { | ||
if (canPatchNativeAccessors) { | ||
this.__outerHTML = outerHTML; // this will throw a native error; | ||
} else { | ||
throw new Error('Failed to set the \'outerHTML\' property on \'Element\': This element has no parent node.'); | ||
} | ||
} | ||
} | ||
}, | ||
parentElement: { | ||
get: function get() { | ||
return findClosest(this.parentNode, function (node) { | ||
return node.nodeType === 1; | ||
}); | ||
} | ||
}, | ||
parentNode: { | ||
get: function get() { | ||
return nodeToParentNodeMap.get(this) || this.__parentNode || null; | ||
} | ||
}, | ||
previousSibling: { | ||
get: function get() { | ||
var host = this; | ||
return eachChildNode(this.parentNode, function (child, index, nodes) { | ||
if (host === child) { | ||
return nodes[index - 1] || null; | ||
} | ||
}); | ||
} | ||
}, | ||
previousElementSibling: { | ||
get: function get() { | ||
var host = this; | ||
var found = void 0; | ||
return eachChildNode(this.parentNode, function (child) { | ||
if (found && host === child) { | ||
return found; | ||
} | ||
if (child.nodeType === 1) { | ||
found = child; | ||
} | ||
}); | ||
} | ||
}, | ||
removeChild: { | ||
value: function value(refNode) { | ||
var nodeType = getNodeType(this); | ||
eachChildNode(this, function (node) { | ||
var getOuterHtml = getOuterHtmlByNodeType[node.nodeType] || getHtmlNodeOuterHtml; | ||
innerHTML += getOuterHtml(node); | ||
}); | ||
return innerHTML; | ||
}, | ||
set: function set(innerHTML) { | ||
var parsed = parse(innerHTML); | ||
switch (nodeType) { | ||
case 'node': | ||
if (canPatchNativeAccessors) { | ||
return this.__removeChild(refNode); | ||
} | ||
removeNodeFromNode(this, refNode); | ||
break; | ||
case 'slot': | ||
removeNodeFromSlot(this, refNode); | ||
break; | ||
case 'host': | ||
removeNodeFromHost(this, refNode); | ||
break; | ||
case 'root': | ||
removeNodeFromRoot(this, refNode); | ||
break; | ||
} | ||
return refNode; | ||
} | ||
}, | ||
removeEventListener: { | ||
value: function value(name, func, opts) { | ||
if (name === 'slotchange' && this.____slotChangeListeners && isSlotNode(this)) { | ||
this.____slotChangeListeners--; | ||
} | ||
return this.__removeEventListener(name, func, opts); | ||
} | ||
}, | ||
replaceChild: { | ||
value: function value(newNode, refNode) { | ||
this.insertBefore(newNode, refNode); | ||
return this.removeChild(refNode); | ||
} | ||
}, | ||
shadowRoot: { | ||
get: function get() { | ||
return hostToModeMap.get(this) === 'open' ? hostToRootMap.get(this) : null; | ||
} | ||
}, | ||
textContent: { | ||
get: function get() { | ||
var textContent = ''; | ||
eachChildNode(this, function (node) { | ||
if (node.nodeType !== Node.COMMENT_NODE) { | ||
textContent += node.textContent; | ||
} | ||
}); | ||
return textContent; | ||
}, | ||
set: function set(textContent) { | ||
while (this.hasChildNodes()) { | ||
this.removeChild(this.firstChild); | ||
} | ||
if (!textContent) { | ||
return; | ||
} | ||
this.appendChild(document.createTextNode(textContent)); | ||
} | ||
} | ||
}; | ||
while (this.hasChildNodes()) { | ||
this.removeChild(this.firstChild); | ||
} | ||
if (!('attachShadow' in document.createElement('div'))) { | ||
(function () { | ||
var elementProto = HTMLElement.prototype; | ||
var textProto = Text.prototype; | ||
var commProto = Comment.prototype; | ||
var textNode = document.createTextNode(''); | ||
var commNode = document.createComment(''); | ||
// when we are doing this: root.innerHTML = "<slot><div></div></slot>"; | ||
// slot.__childNodes is out of sync with slot.childNodes. | ||
// to fix it we have to manually remove and insert them | ||
var slots = findSlots(parsed); | ||
forEach.call(slots, function (slot) { | ||
return syncSlotChildNodes(slot); | ||
}); | ||
Object.keys(members).forEach(function (memberName) { | ||
var memberProperty = members[memberName]; | ||
while (parsed.hasChildNodes()) { | ||
var firstChild = parsed.firstChild; | ||
// All properties should be configurable. | ||
memberProperty.configurable = true; | ||
// When we polyfill everything on HTMLElement.prototype, we overwrite | ||
// properties. This makes it so that parentNode reports null even though | ||
// it's actually a parent of the HTML parser. For this reason, | ||
// cleanNode() won't work and we must manually remove it from the | ||
// parser before it is moved to the host just in case it's added as a | ||
// light node but not assigned to a slot. | ||
parsed.removeChild(firstChild); | ||
// Applying to the data properties only since we can't have writable accessor properties. | ||
if (memberProperty.hasOwnProperty('value')) { | ||
memberProperty.writable = true; | ||
} | ||
this.appendChild(firstChild); | ||
} | ||
} | ||
}, | ||
insertBefore: { | ||
value: function value(newNode, refNode) { | ||
appendChildOrInsertBefore(this, newNode, refNode); | ||
// Polyfill as much as we can and work around WebKit in other areas. | ||
if (canPatchNativeAccessors || polyfillAtRuntime.indexOf(memberName) === -1) { | ||
var nativeDescriptor = getPropertyDescriptor(elementProto, memberName); | ||
var nativeTextDescriptor = getPropertyDescriptor(textProto, memberName); | ||
var nativeCommDescriptor = getPropertyDescriptor(commProto, memberName); | ||
var shouldOverrideInTextNode = memberName in textNode && doNotOverridePropertiesInTextNodes.indexOf(memberName) === -1 || ~defineInTextNodes.indexOf(memberName); | ||
var shouldOverrideInCommentNode = memberName in commNode && doNotOverridePropertiesInCommNodes.indexOf(memberName) === -1 || ~defineInCommNodes.indexOf(memberName); | ||
var nativeMemberName = '__' + memberName; | ||
return newNode; | ||
} | ||
}, | ||
lastChild: { | ||
get: function get() { | ||
var ch = this.childNodes; | ||
return ch[ch.length - 1] || null; | ||
} | ||
}, | ||
lastElementChild: { | ||
get: function get() { | ||
var ch = this.children; | ||
return ch[ch.length - 1] || null; | ||
} | ||
}, | ||
name: { | ||
get: function get() { | ||
return this.getAttribute('name'); | ||
}, | ||
set: function set(name) { | ||
return this.setAttribute('name', name); | ||
} | ||
}, | ||
nextSibling: { | ||
get: function get() { | ||
var host = this; | ||
return eachChildNode(this.parentNode, function (child, index, nodes) { | ||
if (host === child) { | ||
return nodes[index + 1] || null; | ||
} | ||
}); | ||
} | ||
}, | ||
nextElementSibling: { | ||
get: function get() { | ||
var host = this; | ||
var found = void 0; | ||
return eachChildNode(this.parentNode, function (child) { | ||
if (found && child.nodeType === 1) { | ||
return child; | ||
} | ||
if (host === child) { | ||
found = true; | ||
} | ||
}); | ||
} | ||
}, | ||
outerHTML: { | ||
get: function get() { | ||
var name = this.tagName.toLowerCase(); | ||
var attributes = Array.prototype.slice.call(this.attributes).map(function (attr) { | ||
return ' ' + attr.name + (attr.value ? '="' + attr.value + '"' : ''); | ||
}).join(''); | ||
return '<' + name + attributes + '>' + this.innerHTML + '</' + name + '>'; | ||
}, | ||
set: function set(outerHTML) { | ||
if (this.parentNode) { | ||
var parsed = parse(outerHTML); | ||
this.parentNode.replaceChild(parsed.firstChild, this); | ||
} else { | ||
if (canPatchNativeAccessors) { | ||
this.__outerHTML = outerHTML; // this will throw a native error; | ||
} else { | ||
throw new Error('Failed to set the \'outerHTML\' property on \'Element\': This element has no parent node.'); | ||
} | ||
} | ||
} | ||
}, | ||
parentElement: { | ||
get: function get() { | ||
return findClosest(this.parentNode, function (node) { | ||
return node.nodeType === 1; | ||
}); | ||
} | ||
}, | ||
parentNode: { | ||
get: function get() { | ||
return nodeToParentNodeMap.get(this) || this.__parentNode || null; | ||
} | ||
}, | ||
previousSibling: { | ||
get: function get() { | ||
var host = this; | ||
return eachChildNode(this.parentNode, function (child, index, nodes) { | ||
if (host === child) { | ||
return nodes[index - 1] || null; | ||
} | ||
}); | ||
} | ||
}, | ||
previousElementSibling: { | ||
get: function get() { | ||
var host = this; | ||
var found = void 0; | ||
return eachChildNode(this.parentNode, function (child) { | ||
if (found && host === child) { | ||
return found; | ||
} | ||
if (child.nodeType === 1) { | ||
found = child; | ||
} | ||
}); | ||
} | ||
}, | ||
removeChild: { | ||
value: function value(refNode) { | ||
var nodeType = getNodeType(this); | ||
Object.defineProperty(elementProto, memberName, memberProperty); | ||
switch (nodeType) { | ||
case 'node': | ||
if (canPatchNativeAccessors) { | ||
return this.__removeChild(refNode); | ||
} | ||
removeNodeFromNode(this, refNode); | ||
break; | ||
case 'slot': | ||
removeNodeFromSlot(this, refNode); | ||
break; | ||
case 'host': | ||
removeNodeFromHost(this, refNode); | ||
break; | ||
case 'root': | ||
removeNodeFromRoot(this, refNode); | ||
break; | ||
} | ||
return refNode; | ||
} | ||
}, | ||
removeEventListener: { | ||
value: function value(name, func, opts) { | ||
if (name === 'slotchange' && this.____slotChangeListeners && isSlotNode(this)) { | ||
this.____slotChangeListeners--; | ||
} | ||
return this.__removeEventListener(name, func, opts); | ||
} | ||
}, | ||
replaceChild: { | ||
value: function value(newNode, refNode) { | ||
this.insertBefore(newNode, refNode); | ||
return this.removeChild(refNode); | ||
} | ||
}, | ||
shadowRoot: { | ||
get: function get() { | ||
return hostToModeMap.get(this) === 'open' ? hostToRootMap.get(this) : null; | ||
} | ||
}, | ||
textContent: { | ||
get: function get() { | ||
var textContent = ''; | ||
eachChildNode(this, function (node) { | ||
if (node.nodeType !== Node.COMMENT_NODE) { | ||
textContent += node.textContent; | ||
} | ||
}); | ||
return textContent; | ||
}, | ||
set: function set(textContent) { | ||
while (this.hasChildNodes()) { | ||
this.removeChild(this.firstChild); | ||
} | ||
if (!textContent) { | ||
return; | ||
} | ||
this.appendChild(document.createTextNode(textContent)); | ||
} | ||
} | ||
}; | ||
if (nativeDescriptor) { | ||
Object.defineProperty(elementProto, nativeMemberName, nativeDescriptor); | ||
} | ||
if (!('attachShadow' in document.createElement('div'))) { | ||
(function () { | ||
var elementProto = HTMLElement.prototype; | ||
var textProto = Text.prototype; | ||
var commProto = Comment.prototype; | ||
var textNode = document.createTextNode(''); | ||
var commNode = document.createComment(''); | ||
if (shouldOverrideInTextNode) { | ||
Object.defineProperty(textProto, memberName, memberProperty); | ||
} | ||
Object.keys(members).forEach(function (memberName) { | ||
var memberProperty = members[memberName]; | ||
if (shouldOverrideInTextNode && nativeTextDescriptor) { | ||
Object.defineProperty(textProto, nativeMemberName, nativeTextDescriptor); | ||
} | ||
// All properties should be configurable. | ||
memberProperty.configurable = true; | ||
if (shouldOverrideInCommentNode) { | ||
Object.defineProperty(commProto, memberName, memberProperty); | ||
} | ||
// Applying to the data properties only since we can't have writable accessor properties. | ||
if (memberProperty.hasOwnProperty('value')) { | ||
memberProperty.writable = true; | ||
} | ||
if (shouldOverrideInCommentNode && nativeCommDescriptor) { | ||
Object.defineProperty(commProto, nativeMemberName, nativeCommDescriptor); | ||
} | ||
} | ||
}); | ||
})(); | ||
} | ||
// Polyfill as much as we can and work around WebKit in other areas. | ||
if (canPatchNativeAccessors || polyfillAtRuntime.indexOf(memberName) === -1) { | ||
var nativeDescriptor = getPropertyDescriptor(elementProto, memberName); | ||
var nativeTextDescriptor = getPropertyDescriptor(textProto, memberName); | ||
var nativeCommDescriptor = getPropertyDescriptor(commProto, memberName); | ||
var shouldOverrideInTextNode = memberName in textNode && doNotOverridePropertiesInTextNodes.indexOf(memberName) === -1 || ~defineInTextNodes.indexOf(memberName); | ||
var shouldOverrideInCommentNode = memberName in commNode && doNotOverridePropertiesInCommNodes.indexOf(memberName) === -1 || ~defineInCommNodes.indexOf(memberName); | ||
var nativeMemberName = '__' + memberName; | ||
exports['default'] = version; | ||
Object.defineProperty(elementProto, memberName, memberProperty); | ||
if (nativeDescriptor) { | ||
Object.defineProperty(elementProto, nativeMemberName, nativeDescriptor); | ||
} | ||
if (shouldOverrideInTextNode) { | ||
Object.defineProperty(textProto, memberName, memberProperty); | ||
} | ||
if (shouldOverrideInTextNode && nativeTextDescriptor) { | ||
Object.defineProperty(textProto, nativeMemberName, nativeTextDescriptor); | ||
} | ||
if (shouldOverrideInCommentNode) { | ||
Object.defineProperty(commProto, memberName, memberProperty); | ||
} | ||
if (shouldOverrideInCommentNode && nativeCommDescriptor) { | ||
Object.defineProperty(commProto, nativeMemberName, nativeCommDescriptor); | ||
} | ||
} | ||
}); | ||
})(); | ||
} | ||
exports['default'] = version; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
})); | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.skatejsNamedSlots=e.skatejsNamedSlots||{})}(this,function(e){function t(e,t){return t={exports:{}},e(t,t.exports),t.exports}function n(e,t){if(e)for(var n=e.childNodes,r=n.length,i=0;r>i;i++){var o=t(n[i],i,n);if("undefined"!=typeof o)return o}}function r(e,t){if(e instanceof DocumentFragment)for(var n=e.childNodes,r=n.length,i=0;r>i;i++)t(n[i],i);else t(e,0)}function i(e,t){for(var n=void 0;e&&!(n=Object.getOwnPropertyDescriptor(e,t));)e=Object.getPrototypeOf(e);return n}function o(e,t){e instanceof Node&&(e=B);var n=i(e,t);if(n){var r=n.get,o=n.set,s={configurable:!0,enumerable:!0};if(r)return s.get=r,s.set=o,s;if("function"==typeof e[t])return s.value=e[t],s}var u=Object.getOwnPropertyDescriptor(e,t);return u&&u.get?u:void 0}function s(e){return e.textContent.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function u(e){return e.text||"<!--"+e.textContent+"-->"}function a(e){var t=document.createElement("div");if(F)return t.__innerHTML=e,t;for(var n=ve.parseFromString("<div>"+e+"</div>","text/html").body.firstChild;n.hasChildNodes();){var r=n.firstChild;n.removeChild(r),t.appendChild(r)}return document.importNode(t,!0)}function l(e,t,n){Object.defineProperty(e,t,{configurable:!0,get:function(){return n}})}function d(e){return this[e]}function c(e){return e.item=d,e}function h(e){return!!ue.get(e)}function f(e){return"SLOT"===e.tagName}function v(e){return e.tagName===Z}function p(e){return h(e)?"host":f(e)?"slot":v(e)?"root":"node"}function _(e,t){for(;e&&e!==document;){if(t(e))return e;e=e.parentNode}}function g(e){return e.getAttribute&&e.getAttribute("name")||"default"}function m(e){return e.getAttribute&&e.getAttribute("slot")||"default"}function N(e,t,n){if((3!==t.nodeType||!t.textContent||0!==t.textContent.trim().length)&&-1!==ie.indexOf(t.nodeType)){var r=e.assignedNodes(),i=0===r.length,o=r.indexOf(n);de.set(t,e),i&&Q.call(e.childNodes,function(t){return e.__removeChild(t)}),o>-1?(e.__insertBefore(t,void 0!==n?n:null),r.splice(o,0,t)):(e.__appendChild(t),r.push(t)),e.____triggerSlotChangeEvent()}}function C(e){var t=e.assignedSlot;if(t){var n=t.assignedNodes(),r=n.indexOf(e);if(r>-1){var i=1===n.length;n.splice(r,1),de.set(e,null),t.__removeChild(e),i&&Q.call(t.childNodes,function(e){return t.__appendChild(e)}),t.____triggerSlotChangeEvent()}}}function y(e,t){for(var n=e.childNodes,r=n.length,i=0;r>i;i++)if(n[i]===t)return i;return-1}function b(e,t,n,i){var o=y(e,n);r(t,function(t,n){i(t,n),F?le.set(t,e):l(t,"parentNode",e),o>-1?K.splice.call(e.childNodes,o+n,0,t):K.push.call(e.childNodes,t)})}function E(e,t,n){var r=y(e,t);r>-1&&(n(t,0),F?le.set(t,null):l(t,"parentNode",null),K.splice.call(e.childNodes,r,1))}function w(e,t,n){b(e,t,n,function(t){e.__insertBefore(t,void 0!==n?n:null)})}function x(e,t,n){b(e,t,n,function(t){var r=ue.get(e),i=he.get(r),o=i[m(t)];o&&N(o,t,n)})}function O(e,t){var r=g(t);F||t.childNodes.push||l(t,"childNodes",[].concat(H.toConsumableArray(t.childNodes))),he.get(e)[r]=t,fe.has(t)||fe.set(t,e),n(ce.get(e),function(e){e.assignedSlot||r!==m(e)||N(t,e)})}function T(e,t,n){r(t,function(t){if(f(t))O(e,t);else{var n=t.querySelectorAll&&t.querySelectorAll("slot");if(n)for(var r=n.length,i=0;r>i;i++)O(e,n[i])}}),w(e,t,n)}function M(e,t,n){var r=0===e.assignedNodes().length;b(e,t,n,function(t){r&&e.__insertBefore(t,void 0!==n?n:null)})}function L(e,t){var n=0===e.assignedNodes().length;E(e,t,function(){n&&e.__removeChild(t)})}function S(e,t){E(e,t,function(){e.__removeChild(t)})}function A(e,t){E(e,t,function(){C(t)})}function j(e,t){t.assignedNodes().forEach(C),delete he.get(e)[g(t)],fe["delete"](t)}function k(e,t){E(e,t,function(){if(f(t))j(e,t);else{var n=t.querySelectorAll&&t.querySelectorAll("slot");if(n)for(var r=0;r<n.length;r++)j(e,n[r])}e.__removeChild(t)})}function P(e){if(v(e))return e;if(e.parentNode)return P(e.parentNode)}function D(e,t,n){var r=p(e),i=t.parentNode,o=P(e);return F||e.childNodes.push||l(e,"childNodes",[].concat(H.toConsumableArray(e.childNodes))),o&&"slot"===p(t)&&O(o,t),i&&"host"===p(i)&&(F?le.set(t,null):l(t,"parentNode",null)),"node"===r?F?(le.set(t,e),e.__insertBefore(t,void 0!==n?n:null)):w(e,t,n):"slot"===r?M(e,t,n):"host"===r?x(e,t,n):"root"===r?T(e,t,n):void 0}function W(e){if(F&&"slot"===p(e)&&e.__childNodes.length!==e.childNodes.length){for(;e.hasChildNodes();)e.removeChild(e.firstChild);Q.call(e.__childNodes,function(t){return e.appendChild(t)})}}var H={};H.toConsumableArray=function(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t<e.length;t++)n[t]=e[t];return n}return Array.from(e)};var B=document.createElement("div"),q=o(Element.prototype,"innerHTML"),F=!!q,R=t(function(e){function t(){return(new Date).getTime()}e.exports=Date.now||t}),I=R&&"object"==typeof R&&"default"in R?R["default"]:R,U=t(function(e){var t=I;e.exports=function(e,n,r){function i(){var d=t()-a;n>d&&d>0?o=setTimeout(i,n-d):(o=null,r||(l=e.apply(u,s),o||(u=s=null)))}var o,s,u,a,l;return null==n&&(n=100),function(){u=this,s=arguments,a=t();var d=r&&!o;return o||(o=setTimeout(i,n)),d&&(l=e.apply(u,s),u=s=null),l}}}),X=U&&"object"==typeof U&&"default"in U?U["default"]:U,Y="0.0.1";"undefined"==typeof WeakMap&&!function(){var e=Object.defineProperty,t=Date.now()%1e9,n=function(){this.name="__st"+(1e9*Math.random()>>>0)+(t++ +"__")};n.prototype={set:function(t,n){var r=t[this.name];return r&&r[0]===t?r[1]=n:e(t,this.name,{value:[t,n],writable:!0}),this},get:function(e){var t;return(t=e[this.name])&&t[0]===e?t[1]:void 0},"delete":function(e){var t=e[this.name];return t&&t[0]===e?(t[0]=t[1]=void 0,!0):!1},has:function(e){var t=e[this.name];return t?t[0]===e:!1}},window.WeakMap=n}();try{var z=new window.CustomEvent("test",{bubbles:!1,cancelable:!0,detail:{x:"y"}});if(z.preventDefault(),z.defaultPrevented!==!0)throw new Error("Could not prevent default")}catch(G){var J=function(e,t){var n;t=t||{bubbles:!1,cancelable:!1,detail:void 0},n=document.createEvent("CustomEvent"),n.initCustomEvent(e,t.bubbles,t.cancelable,t.detail);var r=n.preventDefault;return n.preventDefault=function(){r.call(this);try{Object.defineProperty(this,"defaultPrevented",{get:function(){return!0}})}catch(e){this.defaultPrevented=!0}},n};J.prototype=window.Event.prototype,window.CustomEvent=J}var K=Array.prototype,Q=K.forEach,V="_shadow_root_",Z=V.toUpperCase(),$=["childNodes","parentNode"],ee=["textContent"],te=["assignedSlot"],ne=["textContent"],re=[],ie=[Node.ELEMENT_NODE,Node.TEXT_NODE],oe=new WeakMap,se=new WeakMap,ue=new WeakMap,ae=new WeakMap,le=new WeakMap,de=new WeakMap,ce=new WeakMap,he=new WeakMap,fe=new WeakMap,ve=new DOMParser,pe={____assignedNodes:{get:function(){return this.______assignedNodes||(this.______assignedNodes=[])}},____isInFallbackMode:{get:function(){return 0===this.assignedNodes().length}},____slotChangeListeners:{get:function(){return"undefined"==typeof this.______slotChangeListeners&&(this.______slotChangeListeners=0),this.______slotChangeListeners},set:function(e){this.______slotChangeListeners=e}},____triggerSlotChangeEvent:{value:X(function(){this.____slotChangeListeners&&this.dispatchEvent(new CustomEvent("slotchange",{bubbles:!1,cancelable:!1}))})},addEventListener:{value:function(e,t,n){return"slotchange"===e&&f(this)&&this.____slotChangeListeners++,this.__addEventListener(e,t,n)}},appendChild:{value:function(e){return D(this,e),e}},assignedSlot:{get:function(){var e=de.get(this);if(!e)return null;var t=fe.get(e),n=ce.get(t),r=se.get(n);return"open"===r?e:null}},attachShadow:{value:function(e){var t=this,n=e&&e.mode;if("closed"!==n&&"open"!==n)throw new Error('You must specify { mode } as "open" or "closed" to attachShadow().');var r=ue.get(this);if(r)return r;var i=c([].slice.call(this.childNodes)),o=document.createElement(e.polyfillShadowRootTagName||V);return se.set(this,n),ue.set(this,o),ce.set(o,this),he.set(o,{}),F?ae.set(this,i):l(this,"childNodes",i),i.forEach(function(e){t.__removeChild(e),F?le.set(e,t):l(e,"parentNode",t)}),this.__appendChild(o)}},childElementCount:{get:function(){return this.children.length}},childNodes:{get:function(){if(F&&"node"===p(this))return this.__childNodes;var e=ae.get(this);return e||ae.set(this,e=c([])),e}},children:{get:function(){var e=[];return n(this,function(t){1===t.nodeType&&e.push(t)}),c(e)}},firstChild:{get:function(){return this.childNodes[0]||null}},firstElementChild:{get:function(){return this.children[0]||null}},assignedNodes:{value:function(){if(f(this)){var e=oe.get(this);return e||oe.set(this,e=[]),e}}},hasChildNodes:{value:function(){return this.childNodes.length>0}},innerHTML:{get:function(){var e="",t=function(e){return e.outerHTML},r={1:t,3:s,8:u};return n(this,function(n){var i=r[n.nodeType]||t;e+=i(n)}),e},set:function(e){for(var t=a(e);this.hasChildNodes();)this.removeChild(this.firstChild);var n=t.querySelectorAll("slot");for(Q.call(n,function(e){return W(e)});t.hasChildNodes();){var r=t.firstChild;t.removeChild(r),this.appendChild(r)}}},insertBefore:{value:function(e,t){return D(this,e,t),e}},lastChild:{get:function(){var e=this.childNodes;return e[e.length-1]||null}},lastElementChild:{get:function(){var e=this.children;return e[e.length-1]||null}},name:{get:function(){return this.getAttribute("name")},set:function(e){return this.setAttribute("name",e)}},nextSibling:{get:function(){var e=this;return n(this.parentNode,function(t,n,r){return e===t?r[n+1]||null:void 0})}},nextElementSibling:{get:function(){var e=this,t=void 0;return n(this.parentNode,function(n){return t&&1===n.nodeType?n:void(e===n&&(t=!0))})}},outerHTML:{get:function(){var e=this.tagName.toLowerCase(),t=Array.prototype.slice.call(this.attributes).map(function(e){return" "+e.name+(e.value?'="'+e.value+'"':"")}).join("");return"<"+e+t+">"+this.innerHTML+"</"+e+">"},set:function(e){if(this.parentNode){var t=a(e);this.parentNode.replaceChild(t.firstChild,this)}else{if(!F)throw new Error("Failed to set the 'outerHTML' property on 'Element': This element has no parent node.");this.__outerHTML=e}}},parentElement:{get:function(){return _(this.parentNode,function(e){return 1===e.nodeType})}},parentNode:{get:function(){return le.get(this)||this.__parentNode||null}},previousSibling:{get:function(){var e=this;return n(this.parentNode,function(t,n,r){return e===t?r[n-1]||null:void 0})}},previousElementSibling:{get:function(){var e=this,t=void 0;return n(this.parentNode,function(n){return t&&e===n?t:void(1===n.nodeType&&(t=n))})}},removeChild:{value:function(e){var t=p(this);switch(t){case"node":if(F)return this.__removeChild(e);S(this,e);break;case"slot":L(this,e);break;case"host":A(this,e);break;case"root":k(this,e)}return e}},removeEventListener:{value:function(e,t,n){return"slotchange"===e&&this.____slotChangeListeners&&f(this)&&this.____slotChangeListeners--,this.__removeEventListener(e,t,n)}},replaceChild:{value:function(e,t){return this.insertBefore(e,t),this.removeChild(t)}},shadowRoot:{get:function(){return"open"===se.get(this)?ue.get(this):null}},textContent:{get:function(){var e="";return n(this,function(t){t.nodeType!==Node.COMMENT_NODE&&(e+=t.textContent)}),e},set:function(e){for(;this.hasChildNodes();)this.removeChild(this.firstChild);e&&this.appendChild(document.createTextNode(e))}}};"attachShadow"in document.createElement("div")||!function(){var e=HTMLElement.prototype,t=Text.prototype,n=Comment.prototype,r=document.createTextNode(""),i=document.createComment("");Object.keys(pe).forEach(function(s){var u=pe[s];if(u.configurable=!0,u.hasOwnProperty("value")&&(u.writable=!0),F||-1===$.indexOf(s)){var a=o(e,s),l=o(t,s),d=o(n,s),c=s in r&&-1===ee.indexOf(s)||~te.indexOf(s),h=s in i&&-1===ne.indexOf(s)||~re.indexOf(s),f="__"+s;Object.defineProperty(e,s,u),a&&Object.defineProperty(e,f,a),c&&Object.defineProperty(t,s,u),c&&l&&Object.defineProperty(t,f,l),h&&Object.defineProperty(n,s,u),h&&d&&Object.defineProperty(n,f,d)}})}(),e["default"]=Y}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.skatejsNamedSlots=e.skatejsNamedSlots||{})}(this,function(e){function t(e,t){if(e)for(var n=e.childNodes,i=n.length,r=0;r<i;r++){var o=t(n[r],r,n);if("undefined"!=typeof o)return o}}function n(e,t){if(e instanceof DocumentFragment)for(var n=e.childNodes,i=n.length,r=0;r<i;r++)t(n[r],r);else t(e,0)}function i(e,t){for(var n=void 0;e&&!(n=Object.getOwnPropertyDescriptor(e,t));)e=Object.getPrototypeOf(e);return n}function r(e,t){e instanceof Node&&(e=B);var n=i(e,t);if(n){var r=n.get,o=n.set,s={configurable:!0,enumerable:!0};if(r)return s.get=r,s.set=o,s;if("function"==typeof e[t])return s.value=e[t],s}var u=Object.getOwnPropertyDescriptor(e,t);if(u&&u.get)return u}function o(e,t){return t={exports:{}},e(t,t.exports),t.exports}function s(e){return e.textContent.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function u(e){return e.text||"<!--"+e.textContent+"-->"}function a(e){return"SLOT"===e.tagName}function l(e){var t=arguments.length<=1||void 0===arguments[1]?[]:arguments[1],n=e.childNodes;if(!n||e.nodeType!==Node.ELEMENT_NODE)return t;for(var i=n.length,r=0;r<i;r++){var o=n[r];a(o)&&t.push(o),l(o,t)}return t}function d(e){return"_SHADOW_ROOT_"===e.tagName}function c(e){var t=document.createElement("div");if(R)return t.__innerHTML=e,t;for(var n=ve.parseFromString("<div>"+e+"</div>","text/html").body.firstChild;n.hasChildNodes();){var i=n.firstChild;n.removeChild(i),t.appendChild(i)}return document.importNode(t,!0)}function h(e,t,n){Object.defineProperty(e,t,{configurable:!0,get:function(){return n}})}function f(e){return this[e]}function v(e){return e.item=f,e}function p(e){return!!ue.get(e)}function _(e){return p(e)?"host":a(e)?"slot":d(e)?"root":"node"}function g(e,t){for(;e&&e!==document;){if(t(e))return e;e=e.parentNode}}function m(e){return e.getAttribute&&e.getAttribute("name")||"default"}function N(e){return e.getAttribute&&e.getAttribute("slot")||"default"}function C(e,t,n){if((3!==t.nodeType||!t.textContent||0!==t.textContent.trim().length)&&re.indexOf(t.nodeType)!==-1){var i=e.assignedNodes(),r=0===i.length,o=i.indexOf(n);de.set(t,e),r&&V.call(e.childNodes,function(t){return e.__removeChild(t)}),o>-1?(e.__insertBefore(t,void 0!==n?n:null),i.splice(o,0,t)):(e.__appendChild(t),i.push(t)),e.____triggerSlotChangeEvent()}}function y(e){var t=e.assignedSlot;if(t){var n=t.assignedNodes(),i=n.indexOf(e);if(i>-1){var r=1===n.length;n.splice(i,1),de.set(e,null),t.__removeChild(e),r&&V.call(t.childNodes,function(e){return t.__appendChild(e)}),t.____triggerSlotChangeEvent()}}}function b(e,t){for(var n=e.childNodes,i=n.length,r=0;r<i;r++)if(n[r]===t)return r;return-1}function E(e,t,i,r){var o=b(e,i);n(t,function(t,n){r(t,n),R?le.set(t,e):h(t,"parentNode",e),o>-1?U.splice.call(e.childNodes,o+n,0,t):U.push.call(e.childNodes,t)})}function w(e,t,n){var i=b(e,t);i>-1&&(n(t,0),R?le.set(t,null):h(t,"parentNode",null),U.splice.call(e.childNodes,i,1))}function O(e,t,n){E(e,t,n,function(t){e.__insertBefore(t,void 0!==n?n:null)})}function T(e,t,n){E(e,t,n,function(t){var i=ue.get(e),r=he.get(i),o=r[N(t)];o&&C(o,t,n)})}function x(e,n){var i=m(n);R||n.childNodes.push||h(n,"childNodes",[].concat(Q(n.childNodes))),he.get(e)[i]=n,fe.has(n)||fe.set(n,e),t(ce.get(e),function(e){e.assignedSlot||i!==N(e)||C(n,e)})}function M(e,t,i){n(t,function(t){if(a(t))x(e,t);else{var n=l(t);if(n)for(var i=n.length,r=0;r<i;r++)x(e,n[r])}}),O(e,t,i)}function L(e,t,n){var i=0===e.assignedNodes().length;E(e,t,n,function(t){i&&e.__insertBefore(t,void 0!==n?n:null)})}function j(e,t){var n=0===e.assignedNodes().length;w(e,t,function(){n&&e.__removeChild(t)})}function S(e,t){w(e,t,function(){e.__removeChild(t)})}function k(e,t){w(e,t,function(){y(t)})}function P(e,t){t.assignedNodes().forEach(y),delete he.get(e)[m(t)],fe["delete"](t)}function D(e,t){w(e,t,function(){if(a(t))P(e,t);else{var n=l(t);if(n)for(var i=0;i<n.length;i++)P(e,n[i])}e.__removeChild(t)})}function A(e){if(d(e))return e;if(e.parentNode)return A(e.parentNode)}function W(e,t,n){var i=_(e),r=t.parentNode,o=A(e);return R||e.childNodes.push||h(e,"childNodes",[].concat(Q(e.childNodes))),o&&"slot"===_(t)&&x(o,t),r&&"host"===_(r)&&(R?le.set(t,null):h(t,"parentNode",null)),"node"===i?R?(le.set(t,e),e.__insertBefore(t,void 0!==n?n:null)):O(e,t,n):"slot"===i?L(e,t,n):"host"===i?T(e,t,n):"root"===i?M(e,t,n):void 0}function H(e){if(R&&"slot"===_(e)&&e.__childNodes.length!==e.childNodes.length){for(;e.hasChildNodes();)e.removeChild(e.firstChild);V.call(e.__childNodes,function(t){return e.appendChild(t)})}}var B=document.createElement("div"),F=r(Element.prototype,"innerHTML"),R=!!F,I=o(function(e){function t(){return(new Date).getTime()}e.exports=Date.now||t}),X=I&&"object"==typeof I&&"default"in I?I["default"]:I,Y=o(function(e){var t=X;e.exports=function(e,n,i){function r(){var d=t()-a;d<n&&d>0?o=setTimeout(r,n-d):(o=null,i||(l=e.apply(u,s),o||(u=s=null)))}var o,s,u,a,l;return null==n&&(n=100),function(){u=this,s=arguments,a=t();var d=i&&!o;return o||(o=setTimeout(r,n)),d&&(l=e.apply(u,s),u=s=null),l}}}),q=Y&&"object"==typeof Y&&"default"in Y?Y["default"]:Y,z="0.0.1";"undefined"==typeof WeakMap&&!function(){var e=Object.defineProperty,t=Date.now()%1e9,n=function(){this.name="__st"+(1e9*Math.random()>>>0)+(t++ +"__")};n.prototype={set:function(t,n){var i=t[this.name];return i&&i[0]===t?i[1]=n:e(t,this.name,{value:[t,n],writable:!0}),this},get:function(e){var t;return(t=e[this.name])&&t[0]===e?t[1]:void 0},"delete":function(e){var t=e[this.name];return!(!t||t[0]!==e)&&(t[0]=t[1]=void 0,!0)},has:function(e){var t=e[this.name];return!!t&&t[0]===e}},window.WeakMap=n}();try{var G=new window.CustomEvent("test",{bubbles:!1,cancelable:!0,detail:{x:"y"}});if(G.preventDefault(),G.defaultPrevented!==!0)throw new Error("Could not prevent default")}catch(J){var K=function(e,t){var n;t=t||{bubbles:!1,cancelable:!1,detail:void 0},n=document.createEvent("CustomEvent"),n.initCustomEvent(e,t.bubbles,t.cancelable,t.detail);var i=n.preventDefault;return n.preventDefault=function(){i.call(this);try{Object.defineProperty(this,"defaultPrevented",{get:function(){return!0}})}catch(e){this.defaultPrevented=!0}},n};K.prototype=window.Event.prototype,window.CustomEvent=K}var Q=function(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t<e.length;t++)n[t]=e[t];return n}return Array.from(e)},U=Array.prototype,V=U.forEach,Z="_shadow_root_",$=["childNodes","parentNode"],ee=["textContent"],te=["assignedSlot"],ne=["textContent"],ie=[],re=[Node.ELEMENT_NODE,Node.TEXT_NODE],oe=new WeakMap,se=new WeakMap,ue=new WeakMap,ae=new WeakMap,le=new WeakMap,de=new WeakMap,ce=new WeakMap,he=new WeakMap,fe=new WeakMap,ve=new DOMParser,pe={____assignedNodes:{get:function(){return this.______assignedNodes||(this.______assignedNodes=[])}},____isInFallbackMode:{get:function(){return 0===this.assignedNodes().length}},____slotChangeListeners:{get:function(){return"undefined"==typeof this.______slotChangeListeners&&(this.______slotChangeListeners=0),this.______slotChangeListeners},set:function(e){this.______slotChangeListeners=e}},____triggerSlotChangeEvent:{value:q(function(){this.____slotChangeListeners&&this.dispatchEvent(new CustomEvent("slotchange",{bubbles:!1,cancelable:!1}))})},addEventListener:{value:function(e,t,n){return"slotchange"===e&&a(this)&&this.____slotChangeListeners++,this.__addEventListener(e,t,n)}},appendChild:{value:function(e){return W(this,e),e}},assignedSlot:{get:function(){var e=de.get(this);if(!e)return null;var t=fe.get(e),n=ce.get(t),i=se.get(n);return"open"===i?e:null}},attachShadow:{value:function(e){var t=this,n=e&&e.mode;if("closed"!==n&&"open"!==n)throw new Error('You must specify { mode } as "open" or "closed" to attachShadow().');var i=ue.get(this);if(i)return i;var r=v([].slice.call(this.childNodes)),o=document.createElement(e.polyfillShadowRootTagName||Z);return se.set(this,n),ue.set(this,o),ce.set(o,this),he.set(o,{}),R?ae.set(this,r):h(this,"childNodes",r),r.forEach(function(e){t.__removeChild(e),R?le.set(e,t):h(e,"parentNode",t)}),this.__appendChild(o)}},childElementCount:{get:function(){return this.children.length}},childNodes:{get:function(){if(R&&"node"===_(this))return this.__childNodes;var e=ae.get(this);return e||ae.set(this,e=v([])),e}},children:{get:function(){var e=[];return t(this,function(t){1===t.nodeType&&e.push(t)}),v(e)}},firstChild:{get:function(){return this.childNodes[0]||null}},firstElementChild:{get:function(){return this.children[0]||null}},assignedNodes:{value:function(){if(a(this)){var e=oe.get(this);return e||oe.set(this,e=[]),e}}},hasChildNodes:{value:function(){return this.childNodes.length>0}},innerHTML:{get:function(){var e="",n=function(e){return e.outerHTML},i={1:n,3:s,8:u};return t(this,function(t){var r=i[t.nodeType]||n;e+=r(t)}),e},set:function(e){for(var t=c(e);this.hasChildNodes();)this.removeChild(this.firstChild);var n=l(t);for(V.call(n,function(e){return H(e)});t.hasChildNodes();){var i=t.firstChild;t.removeChild(i),this.appendChild(i)}}},insertBefore:{value:function(e,t){return W(this,e,t),e}},lastChild:{get:function(){var e=this.childNodes;return e[e.length-1]||null}},lastElementChild:{get:function(){var e=this.children;return e[e.length-1]||null}},name:{get:function(){return this.getAttribute("name")},set:function(e){return this.setAttribute("name",e)}},nextSibling:{get:function(){var e=this;return t(this.parentNode,function(t,n,i){if(e===t)return i[n+1]||null})}},nextElementSibling:{get:function(){var e=this,n=void 0;return t(this.parentNode,function(t){return n&&1===t.nodeType?t:void(e===t&&(n=!0))})}},outerHTML:{get:function(){var e=this.tagName.toLowerCase(),t=Array.prototype.slice.call(this.attributes).map(function(e){return" "+e.name+(e.value?'="'+e.value+'"':"")}).join("");return"<"+e+t+">"+this.innerHTML+"</"+e+">"},set:function(e){if(this.parentNode){var t=c(e);this.parentNode.replaceChild(t.firstChild,this)}else{if(!R)throw new Error("Failed to set the 'outerHTML' property on 'Element': This element has no parent node.");this.__outerHTML=e}}},parentElement:{get:function(){return g(this.parentNode,function(e){return 1===e.nodeType})}},parentNode:{get:function(){return le.get(this)||this.__parentNode||null}},previousSibling:{get:function(){var e=this;return t(this.parentNode,function(t,n,i){if(e===t)return i[n-1]||null})}},previousElementSibling:{get:function(){var e=this,n=void 0;return t(this.parentNode,function(t){return n&&e===t?n:void(1===t.nodeType&&(n=t))})}},removeChild:{value:function(e){var t=_(this);switch(t){case"node":if(R)return this.__removeChild(e);S(this,e);break;case"slot":j(this,e);break;case"host":k(this,e);break;case"root":D(this,e)}return e}},removeEventListener:{value:function(e,t,n){return"slotchange"===e&&this.____slotChangeListeners&&a(this)&&this.____slotChangeListeners--,this.__removeEventListener(e,t,n)}},replaceChild:{value:function(e,t){return this.insertBefore(e,t),this.removeChild(t)}},shadowRoot:{get:function(){return"open"===se.get(this)?ue.get(this):null}},textContent:{get:function(){var e="";return t(this,function(t){t.nodeType!==Node.COMMENT_NODE&&(e+=t.textContent)}),e},set:function(e){for(;this.hasChildNodes();)this.removeChild(this.firstChild);e&&this.appendChild(document.createTextNode(e))}}};"attachShadow"in document.createElement("div")||!function(){var e=HTMLElement.prototype,t=Text.prototype,n=Comment.prototype,i=document.createTextNode(""),o=document.createComment("");Object.keys(pe).forEach(function(s){var u=pe[s];if(u.configurable=!0,u.hasOwnProperty("value")&&(u.writable=!0),R||$.indexOf(s)===-1){var a=r(e,s),l=r(t,s),d=r(n,s),c=s in i&&ee.indexOf(s)===-1||~te.indexOf(s),h=s in o&&ne.indexOf(s)===-1||~ie.indexOf(s),f="__"+s;Object.defineProperty(e,s,u),a&&Object.defineProperty(e,f,a),c&&Object.defineProperty(t,s,u),c&&l&&Object.defineProperty(t,f,l),h&&Object.defineProperty(n,s,u),h&&d&&Object.defineProperty(n,f,d)}})}(),e["default"]=z,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=index.min.js.map |
@@ -36,5 +36,5 @@ { | ||
"devDependencies": { | ||
"eslint": "2.11.0", | ||
"eslint": "^2.11.0", | ||
"eslint-plugin-react": "^3.16.1", | ||
"skatejs-build": "2.1.1" | ||
"skatejs-build": "^4.2.2" | ||
}, | ||
@@ -51,3 +51,3 @@ "dependencies": { | ||
}, | ||
"version": "0.2.5" | ||
"version": "0.2.6" | ||
} |
@@ -7,2 +7,5 @@ import { eachChildNode, eachNodeOrFragmentNodes } from './util/each'; | ||
import getCommentNodeOuterHtml from './util/get-comment-node-outer-html'; | ||
import findSlots from './util/find-slots'; | ||
import isRootNode from './util/is-root-node'; | ||
import isSlotNode from './util/is-slot-node'; | ||
import version from './version'; | ||
@@ -20,3 +23,2 @@ import 'webcomponents.js/src/WeakMap/WeakMap.js'; | ||
const defaultShadowRootTagName = '_shadow_root_'; | ||
const defaultShadowRootTagNameUc = defaultShadowRootTagName.toUpperCase(); | ||
@@ -102,10 +104,2 @@ // * WebKit only * | ||
function isSlotNode(node) { | ||
return node.tagName === 'SLOT'; | ||
} | ||
function isRootNode(node) { | ||
return node.tagName === defaultShadowRootTagNameUc; | ||
} | ||
function getNodeType(node) { | ||
@@ -315,3 +309,3 @@ if (isHostNode(node)) { | ||
} else { | ||
const slotNodes = child.querySelectorAll && child.querySelectorAll('slot'); | ||
const slotNodes = findSlots(child); | ||
if (slotNodes) { | ||
@@ -375,3 +369,3 @@ const slotNodesLen = slotNodes.length; | ||
} else { | ||
const nodes = node.querySelectorAll && node.querySelectorAll('slot'); | ||
const nodes = findSlots(node); | ||
if (nodes) { | ||
@@ -658,3 +652,3 @@ for (let a = 0; a < nodes.length; a++) { | ||
// to fix it we have to manually remove and insert them | ||
const slots = parsed.querySelectorAll('slot'); | ||
const slots = findSlots(parsed); | ||
forEach.call(slots, slot => syncSlotChildNodes(slot)); | ||
@@ -789,17 +783,17 @@ | ||
switch (nodeType) { | ||
case 'node': | ||
if (canPatchNativeAccessors) { | ||
return this.__removeChild(refNode); | ||
} | ||
removeNodeFromNode(this, refNode); | ||
break; | ||
case 'slot': | ||
removeNodeFromSlot(this, refNode); | ||
break; | ||
case 'host': | ||
removeNodeFromHost(this, refNode); | ||
break; | ||
case 'root': | ||
removeNodeFromRoot(this, refNode); | ||
break; | ||
case 'node': | ||
if (canPatchNativeAccessors) { | ||
return this.__removeChild(refNode); | ||
} | ||
removeNodeFromNode(this, refNode); | ||
break; | ||
case 'slot': | ||
removeNodeFromSlot(this, refNode); | ||
break; | ||
case 'host': | ||
removeNodeFromHost(this, refNode); | ||
break; | ||
case 'root': | ||
removeNodeFromRoot(this, refNode); | ||
break; | ||
} | ||
@@ -806,0 +800,0 @@ return refNode; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
209416
16
1958
1
1