skatejs-named-slots
Advanced tools
Comparing version 0.3.3 to 1.0.0
@@ -65,43 +65,49 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
var _canPatchNativeAccessors = __webpack_require__(2); | ||
var _support = __webpack_require__(2); | ||
var _canPatchNativeAccessors = __webpack_require__(3); | ||
var _canPatchNativeAccessors2 = _interopRequireDefault(_canPatchNativeAccessors); | ||
var _getPropertyDescriptor = __webpack_require__(3); | ||
var _getPropertyDescriptor = __webpack_require__(4); | ||
var _getPropertyDescriptor2 = _interopRequireDefault(_getPropertyDescriptor); | ||
var _debounce = __webpack_require__(4); | ||
var _debounce = __webpack_require__(5); | ||
var _debounce2 = _interopRequireDefault(_debounce); | ||
var _getEscapedTextContent = __webpack_require__(6); | ||
var _getEscapedTextContent = __webpack_require__(7); | ||
var _getEscapedTextContent2 = _interopRequireDefault(_getEscapedTextContent); | ||
var _getCommentNodeOuterHtml = __webpack_require__(7); | ||
var _getCommentNodeOuterHtml = __webpack_require__(8); | ||
var _getCommentNodeOuterHtml2 = _interopRequireDefault(_getCommentNodeOuterHtml); | ||
var _findSlots = __webpack_require__(8); | ||
var _findSlots = __webpack_require__(9); | ||
var _findSlots2 = _interopRequireDefault(_findSlots); | ||
var _isRootNode = __webpack_require__(10); | ||
var _isRootNode = __webpack_require__(11); | ||
var _isRootNode2 = _interopRequireDefault(_isRootNode); | ||
var _isSlotNode = __webpack_require__(9); | ||
var _isSlotNode = __webpack_require__(10); | ||
var _isSlotNode2 = _interopRequireDefault(_isSlotNode); | ||
var _pseudoArrayToArray = __webpack_require__(11); | ||
var _pseudoArrayToArray = __webpack_require__(12); | ||
var _pseudoArrayToArray2 = _interopRequireDefault(_pseudoArrayToArray); | ||
var _version = __webpack_require__(12); | ||
var _v = __webpack_require__(13); | ||
var _v2 = _interopRequireDefault(_v); | ||
var _version = __webpack_require__(15); | ||
var _version2 = _interopRequireDefault(_version); | ||
__webpack_require__(13); | ||
__webpack_require__(16); | ||
@@ -238,22 +244,3 @@ __webpack_require__(14); | ||
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; | ||
} | ||
// only Text and Element nodes should be slotted | ||
// Only Text and Element nodes should be slotted. | ||
if (slottedNodeTypes.indexOf(node.nodeType) === -1) { | ||
@@ -953,58 +940,62 @@ return; | ||
if (!('attachShadow' in document.createElement('div'))) { | ||
(function () { | ||
var commProto = Comment.prototype; | ||
var elementProto = HTMLElement.prototype; | ||
var svgProto = SVGElement.prototype; | ||
var textProto = Text.prototype; | ||
var textNode = document.createTextNode(''); | ||
var commNode = document.createComment(''); | ||
if (_support.shadowDomV1) { | ||
// then we should probably not be loading this | ||
} else if (_support.shadowDomV0) { | ||
(0, _v2.default)(); | ||
} else { | ||
(function () { | ||
var commProto = Comment.prototype; | ||
var elementProto = HTMLElement.prototype; | ||
var svgProto = SVGElement.prototype; | ||
var textProto = Text.prototype; | ||
var textNode = document.createTextNode(''); | ||
var commNode = document.createComment(''); | ||
Object.keys(members).forEach(function (memberName) { | ||
var memberProperty = members[memberName]; | ||
Object.keys(members).forEach(function (memberName) { | ||
var memberProperty = members[memberName]; | ||
// All properties should be configurable. | ||
memberProperty.configurable = true; | ||
// All properties should be configurable. | ||
memberProperty.configurable = true; | ||
// Applying to the data properties only since we can't have writable accessor properties. | ||
if (memberProperty.hasOwnProperty('value')) { | ||
memberProperty.writable = true; | ||
} | ||
// Applying to the data properties only since we can't have writable accessor properties. | ||
if (memberProperty.hasOwnProperty('value')) { | ||
memberProperty.writable = true; | ||
} | ||
// Polyfill as much as we can and work around WebKit in other areas. | ||
if (_canPatchNativeAccessors2.default || polyfillAtRuntime.indexOf(memberName) === -1) { | ||
var nativeDescriptor = (0, _getPropertyDescriptor2.default)(elementProto, memberName); | ||
var nativeTextDescriptor = (0, _getPropertyDescriptor2.default)(textProto, memberName); | ||
var nativeCommDescriptor = (0, _getPropertyDescriptor2.default)(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; | ||
// Polyfill as much as we can and work around WebKit in other areas. | ||
if (_canPatchNativeAccessors2.default || polyfillAtRuntime.indexOf(memberName) === -1) { | ||
var nativeDescriptor = (0, _getPropertyDescriptor2.default)(elementProto, memberName); | ||
var nativeTextDescriptor = (0, _getPropertyDescriptor2.default)(textProto, memberName); | ||
var nativeCommDescriptor = (0, _getPropertyDescriptor2.default)(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; | ||
Object.defineProperty(elementProto, memberName, memberProperty); | ||
Object.defineProperty(svgProto, memberName, memberProperty); | ||
Object.defineProperty(elementProto, memberName, memberProperty); | ||
Object.defineProperty(svgProto, memberName, memberProperty); | ||
if (nativeDescriptor) { | ||
Object.defineProperty(elementProto, nativeMemberName, nativeDescriptor); | ||
Object.defineProperty(svgProto, nativeMemberName, nativeDescriptor); | ||
} | ||
if (nativeDescriptor) { | ||
Object.defineProperty(elementProto, nativeMemberName, nativeDescriptor); | ||
Object.defineProperty(svgProto, nativeMemberName, nativeDescriptor); | ||
} | ||
if (shouldOverrideInTextNode) { | ||
Object.defineProperty(textProto, memberName, memberProperty); | ||
} | ||
if (shouldOverrideInTextNode) { | ||
Object.defineProperty(textProto, memberName, memberProperty); | ||
} | ||
if (shouldOverrideInTextNode && nativeTextDescriptor) { | ||
Object.defineProperty(textProto, nativeMemberName, nativeTextDescriptor); | ||
} | ||
if (shouldOverrideInTextNode && nativeTextDescriptor) { | ||
Object.defineProperty(textProto, nativeMemberName, nativeTextDescriptor); | ||
} | ||
if (shouldOverrideInCommentNode) { | ||
Object.defineProperty(commProto, memberName, memberProperty); | ||
} | ||
if (shouldOverrideInCommentNode) { | ||
Object.defineProperty(commProto, memberName, memberProperty); | ||
} | ||
if (shouldOverrideInCommentNode && nativeCommDescriptor) { | ||
Object.defineProperty(commProto, nativeMemberName, nativeCommDescriptor); | ||
if (shouldOverrideInCommentNode && nativeCommDescriptor) { | ||
Object.defineProperty(commProto, nativeMemberName, nativeCommDescriptor); | ||
} | ||
} | ||
} | ||
}); | ||
})(); | ||
} | ||
}); | ||
})(); | ||
} | ||
@@ -1071,2 +1062,15 @@ exports.default = _version2.default; | ||
/* 2 */ | ||
/***/ function(module, exports) { | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var div = document.createElement('div'); | ||
var shadowDomV0 = exports.shadowDomV0 = !!div.createShadowRoot; | ||
var shadowDomV1 = exports.shadowDomV1 = !!div.attachShadow; | ||
/***/ }, | ||
/* 3 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
@@ -1080,3 +1084,3 @@ | ||
var _getPropertyDescriptor = __webpack_require__(3); | ||
var _getPropertyDescriptor = __webpack_require__(4); | ||
@@ -1093,3 +1097,3 @@ var _getPropertyDescriptor2 = _interopRequireDefault(_getPropertyDescriptor); | ||
/***/ }, | ||
/* 3 */ | ||
/* 4 */ | ||
/***/ function(module, exports) { | ||
@@ -1146,3 +1150,3 @@ | ||
/***/ }, | ||
/* 4 */ | ||
/* 5 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
@@ -1156,3 +1160,3 @@ | ||
var now = __webpack_require__(5); | ||
var now = __webpack_require__(6); | ||
@@ -1207,3 +1211,3 @@ /** | ||
/***/ }, | ||
/* 5 */ | ||
/* 6 */ | ||
/***/ function(module, exports) { | ||
@@ -1220,3 +1224,3 @@ | ||
/***/ }, | ||
/* 6 */ | ||
/* 7 */ | ||
/***/ function(module, exports) { | ||
@@ -1240,3 +1244,3 @@ | ||
/***/ }, | ||
/* 7 */ | ||
/* 8 */ | ||
/***/ function(module, exports) { | ||
@@ -1259,3 +1263,3 @@ | ||
/***/ }, | ||
/* 8 */ | ||
/* 9 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
@@ -1270,4 +1274,6 @@ | ||
var _isSlotNode = __webpack_require__(9); | ||
var _support = __webpack_require__(2); | ||
var _isSlotNode = __webpack_require__(10); | ||
var _isSlotNode2 = _interopRequireDefault(_isSlotNode); | ||
@@ -1277,2 +1283,4 @@ | ||
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } | ||
function findSlots(root) { | ||
@@ -1283,2 +1291,6 @@ var slots = arguments.length <= 1 || arguments[1] === undefined ? [] : arguments[1]; | ||
if (_support.shadowDomV0) { | ||
return [].concat(_toConsumableArray(root.querySelectorAll('content'))); | ||
} | ||
if (!childNodes || root.nodeType !== Node.ELEMENT_NODE) { | ||
@@ -1304,3 +1316,3 @@ return slots; | ||
/***/ }, | ||
/* 9 */ | ||
/* 10 */ | ||
/***/ function(module, exports) { | ||
@@ -1319,3 +1331,3 @@ | ||
/***/ }, | ||
/* 10 */ | ||
/* 11 */ | ||
/***/ function(module, exports) { | ||
@@ -1334,3 +1346,3 @@ | ||
/***/ }, | ||
/* 11 */ | ||
/* 12 */ | ||
/***/ function(module, exports) { | ||
@@ -1349,4 +1361,4 @@ | ||
/***/ }, | ||
/* 12 */ | ||
/***/ function(module, exports) { | ||
/* 13 */ | ||
/***/ function(module, exports, __webpack_require__) { | ||
@@ -1358,55 +1370,269 @@ 'use strict'; | ||
}); | ||
exports.default = '0.0.1'; | ||
/***/ }, | ||
/* 13 */ | ||
/***/ function(module, exports) { | ||
'use strict'; | ||
/** | ||
* @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 | ||
*/ | ||
__webpack_require__(14); | ||
if (typeof WeakMap === 'undefined') { | ||
(function () { | ||
var defineProperty = Object.defineProperty; | ||
var counter = Date.now() % 1e9; | ||
var $shadowRoot = '__shadowRoot'; | ||
var WeakMap = function WeakMap() { | ||
this.name = '__st' + (Math.random() * 1e9 >>> 0) + (counter++ + '__'); | ||
}; | ||
exports.default = function () { | ||
// Returns the assigned nodes (unflattened) for a <content> node. | ||
var getAssignedNodes = function getAssignedNodes(node) { | ||
var slot = node.getAttribute('name'); | ||
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 host = node; | ||
while (host) { | ||
var sr = host[$shadowRoot]; | ||
if (sr && sr.contains(node)) { | ||
break; | ||
} | ||
}; | ||
host = host.parentNode; | ||
} | ||
window.WeakMap = WeakMap; | ||
})(); | ||
} | ||
if (!host) { | ||
return []; | ||
} | ||
var chs = host.childNodes; | ||
var chsLen = chs.length; | ||
var filtered = []; | ||
for (var a = 0; a < chsLen; a++) { | ||
var ch = chs[a]; | ||
var chSlot = ch.getAttribute ? ch.getAttribute('slot') : null; | ||
if (slot === chSlot) { | ||
filtered.push(ch); | ||
} | ||
} | ||
return filtered; | ||
}; | ||
var _HTMLElement$prototyp = HTMLElement.prototype; | ||
var getAttribute = _HTMLElement$prototyp.getAttribute; | ||
var setAttribute = _HTMLElement$prototyp.setAttribute; | ||
var elementInnerHTML = Object.getOwnPropertyDescriptor(Element.prototype, 'innerHTML'); | ||
var shadowRootInnerHTML = Object.getOwnPropertyDescriptor(ShadowRoot.prototype, 'innerHTML'); | ||
// We do this so creating a <slot> actually creates a <content>. | ||
var filterTagName = function filterTagName(name) { | ||
return name === 'slot' ? 'content' : name; | ||
}; | ||
var createElement = document.createElement.bind(document); | ||
var createElementNS = document.createElementNS.bind(document); | ||
document.createElement = function (name) { | ||
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
args[_key - 1] = arguments[_key]; | ||
} | ||
return createElement.apply(undefined, [filterTagName(name)].concat(args)); | ||
}; | ||
document.createElementNS = function (name) { | ||
for (var _len2 = arguments.length, args = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { | ||
args[_key2 - 1] = arguments[_key2]; | ||
} | ||
return createElementNS.apply(undefined, [filterTagName(name)].concat(args)); | ||
}; | ||
// Override innerHTML to turn slot nodes into content nodes. | ||
function replaceSlotsWithContents(node) { | ||
var tree = document.createTreeWalker(node, NodeFilter.SHOW_ELEMENT); | ||
var repl = []; | ||
// Walk the tree and record nodes that need replacing. | ||
while (tree.nextNode()) { | ||
var currentNode = tree.currentNode; | ||
if (currentNode.tagName === 'SLOT') { | ||
repl.push(currentNode); | ||
} | ||
} | ||
repl.forEach(function (fake) { | ||
var name = fake.getAttribute('name'); | ||
var real = document.createElement('slot'); | ||
if (name) { | ||
real.setAttribute('name', name); | ||
} | ||
fake.parentNode.replaceChild(real, fake); | ||
while (fake.hasChildNodes()) { | ||
real.appendChild(fake.firstChild); | ||
} | ||
}); | ||
} | ||
Object.defineProperty(Element.prototype, 'innerHTML', { | ||
configurable: true, | ||
get: elementInnerHTML.get, | ||
set: function set(html) { | ||
elementInnerHTML.set.call(this, html); | ||
replaceSlotsWithContents(this); | ||
} | ||
}); | ||
Object.defineProperty(ShadowRoot.prototype, 'innerHTML', { | ||
configurable: true, | ||
get: shadowRootInnerHTML.get, | ||
set: function set(html) { | ||
shadowRootInnerHTML.set.call(this, html); | ||
replaceSlotsWithContents(this); | ||
} | ||
}); | ||
// Node | ||
// ---- | ||
Object.defineProperty(Node.prototype, 'assignedSlot', { | ||
get: function get() { | ||
var parentNode = this.parentNode; | ||
if (parentNode) { | ||
var shadowRoot = parentNode.shadowRoot; | ||
// If { mode } is "closed", always return `null`. | ||
if (!shadowRoot) { | ||
return null; | ||
} | ||
var contents = shadowRoot.querySelectorAll('content'); | ||
for (var a = 0; a < contents.length; a++) { | ||
var content = contents[a]; | ||
if (content.assignedNodes().indexOf(this) > -1) { | ||
return content; | ||
} | ||
} | ||
} | ||
return null; | ||
} | ||
}); | ||
// Just proxy createShadowRoot() because there's no such thing as closed | ||
// shadow trees in v0. | ||
HTMLElement.prototype.attachShadow = function attachShadow() { | ||
var _this = this; | ||
var _ref = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
var mode = _ref.mode; | ||
// In v1 you must specify a mode. | ||
if (mode !== 'closed' && mode !== 'open') { | ||
throw new Error('You must specify { mode } as "open" or "closed" to attachShadow().'); | ||
} | ||
// Proxy native v0. | ||
var sr = this.createShadowRoot(); | ||
// In v0 it always defines the shadowRoot property so we must undefine it. | ||
if (mode === 'closed') { | ||
Object.defineProperty(this, 'shadowRoot', { | ||
configurable: true, | ||
get: function get() { | ||
return null; | ||
} | ||
}); | ||
} | ||
// For some reason this wasn't being reported as set, but it seems to work | ||
// in dev tools. | ||
Object.defineProperty(sr, 'parentNode', { | ||
get: function get() { | ||
return _this; | ||
} | ||
}); | ||
// Add a MutationObserver to trigger slot change events when the element | ||
// is mutated. We only need to listen to the childList because we only care | ||
// about light DOM. | ||
var mo = new MutationObserver(function (muts) { | ||
var root = _this[$shadowRoot]; | ||
muts.forEach(function (mut) { | ||
var addedNodes = mut.addedNodes; | ||
var removedNodes = mut.removedNodes; | ||
var slots = {}; | ||
var recordSlots = function recordSlots(node) { | ||
return slots[node.getAttribute && node.getAttribute('slot') || '__default'] = true; | ||
}; | ||
if (addedNodes) { | ||
var addedNodesLen = addedNodes.length; | ||
for (var a = 0; a < addedNodesLen; a++) { | ||
recordSlots(addedNodes[a]); | ||
} | ||
} | ||
if (removedNodes) { | ||
var removedNodesLen = removedNodes.length; | ||
for (var _a = 0; _a < removedNodesLen; _a++) { | ||
recordSlots(removedNodes[_a]); | ||
} | ||
} | ||
Object.keys(slots).forEach(function (slot) { | ||
var node = slot === '__default' ? root.querySelector('content:not([name])') || root.querySelector('content[name=""]') : root.querySelector('content[name="' + slot + '"]'); | ||
if (node) { | ||
node.dispatchEvent(new CustomEvent('slotchange', { | ||
bubbles: false, | ||
cancelable: false | ||
})); | ||
} | ||
}); | ||
}); | ||
}); | ||
mo.observe(this, { childList: true }); | ||
return this[$shadowRoot] = sr; | ||
}; | ||
// Make like the <slot> name property. | ||
Object.defineProperty(HTMLContentElement.prototype, 'name', { | ||
get: function get() { | ||
return this.getAttribute('name'); | ||
}, | ||
set: function set(name) { | ||
return this.setAttribute('name', name); | ||
} | ||
}); | ||
// By default, getDistributedNodes() returns a flattened tree (no <slot> | ||
// nodes). That means we get native { deep } but we have to manually do the | ||
// opposite. | ||
HTMLContentElement.prototype.assignedNodes = function assignedNodes() { | ||
var _ref2 = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
var deep = _ref2.deep; | ||
var cnodes = []; | ||
var dnodes = deep ? this.getDistributedNodes() : getAssignedNodes(this); | ||
// Regardless of how we get the nodes, we must ensure we're only given text | ||
// nodes or element nodes. | ||
for (var a = 0; a < dnodes.length; a++) { | ||
var dnode = dnodes[a]; | ||
var dtype = dnode.nodeType; | ||
if (dtype === Node.ELEMENT_NODE || dtype === Node.TEXT_NODE) { | ||
cnodes.push(dnode); | ||
} | ||
} | ||
return cnodes; | ||
}; | ||
HTMLContentElement.prototype.getAttribute = function overriddenGetAttribute(name) { | ||
if (name === 'name') { | ||
var select = getAttribute.call(this, 'select'); | ||
return select ? select.match(/\[slot=['"]?(.*?)['"]?\]/)[1] : null; | ||
} | ||
return getAttribute.call(this, name); | ||
}; | ||
HTMLContentElement.prototype.setAttribute = function overriddenSetAttribute(name, value) { | ||
if (name === 'name') { | ||
name = 'select'; | ||
value = '[slot=\'' + value + '\']'; | ||
} | ||
return setAttribute.call(this, name, value); | ||
}; | ||
}; | ||
@@ -1470,2 +1696,65 @@ /***/ }, | ||
/***/ }, | ||
/* 15 */ | ||
/***/ function(module, exports) { | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = '0.0.1'; | ||
/***/ }, | ||
/* 16 */ | ||
/***/ function(module, exports) { | ||
'use strict'; | ||
/** | ||
* @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 | ||
*/ | ||
if (typeof WeakMap === 'undefined') { | ||
(function () { | ||
var defineProperty = Object.defineProperty; | ||
var counter = Date.now() % 1e9; | ||
var WeakMap = function WeakMap() { | ||
this.name = '__st' + (Math.random() * 1e9 >>> 0) + (counter++ + '__'); | ||
}; | ||
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; | ||
} | ||
}; | ||
window.WeakMap = WeakMap; | ||
})(); | ||
} | ||
/***/ } | ||
@@ -1472,0 +1761,0 @@ /******/ ]) |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.skatejsNamedSlots=t():e.skatejsNamedSlots=t()}(this,function(){return function(e){function t(r){if(n[r])return n[r].exports;var i=n[r]={exports:{},id:r,loaded:!1};return e[r].call(i.exports,i,i.exports,t),i.loaded=!0,i.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function i(e){var t=document.createElement("div");if(k["default"])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 o(e,t,n){Object.defineProperty(e,t,{configurable:!0,get:function(){return n}})}function u(e){return this[e]}function a(e){return e.item=u,e}function s(e){return!!de.get(e)}function d(e){return s(e)?"host":(0,z["default"])(e)?"slot":(0,Y["default"])(e)?"root":"node"}function l(e,t){for(;e&&e!==document;){if(t(e))return e;e=e.parentNode}}function f(e){return e.getAttribute&&e.getAttribute("name")||"default"}function c(e){return e.getAttribute&&e.getAttribute("slot")||"default"}function h(e,t,n){if((3!==t.nodeType||!t.textContent||0!==t.textContent.trim().length)&&ue.indexOf(t.nodeType)!==-1){var r=e.assignedNodes(),i=0===r.length,o=r.indexOf(n);ce.set(t,e),i&&$.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 _(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),ce.set(e,null),t.__removeChild(e),i&&$.call(t.childNodes,function(e){return t.__appendChild(e)}),t.____triggerSlotChangeEvent()}}}function p(e,t){for(var n=e.childNodes,r=n.length,i=0;i<r;i++)if(n[i]===t)return i;return-1}function v(e,t,n,r){var i=p(e,n);(0,L.eachNodeOrFragmentNodes)(t,function(t,n){r(t,n),k["default"]?fe.set(t,e):o(t,"parentNode",e),i>-1?Z.splice.call(e.childNodes,i+n,0,t):Z.push.call(e.childNodes,t)})}function g(e,t,n){var r=p(e,t);r>-1&&(n(t,0),k["default"]?fe.set(t,null):o(t,"parentNode",null),Z.splice.call(e.childNodes,r,1))}function N(e,t,n){v(e,t,n,function(t){e.__insertBefore(t,void 0!==n?n:null)})}function m(e,t,n){v(e,t,n,function(t){var r=de.get(e),i=_e.get(r),o=i[c(t)];o&&h(o,t,n)})}function C(e,t){var n=f(t);k["default"]||Array.isArray(t.childNodes)||o(t,"childNodes",(0,K["default"])(t.childNodes)),_e.get(e)[n]=t,pe.has(t)||pe.set(t,e),(0,L.eachChildNode)(he.get(e),function(e){e.assignedSlot||n!==c(e)||h(t,e)})}function y(e,t,n){(0,L.eachNodeOrFragmentNodes)(t,function(t){if((0,z["default"])(t))C(e,t);else{var n=(0,V["default"])(t);if(n)for(var r=n.length,i=0;i<r;i++)C(e,n[i])}}),N(e,t,n)}function b(e,t,n){var r=0===e.assignedNodes().length;v(e,t,n,function(t){r&&e.__insertBefore(t,void 0!==n?n:null)})}function O(e,t){var n=0===e.assignedNodes().length;g(e,t,function(){n&&e.__removeChild(t)})}function E(e,t){g(e,t,function(){e.__removeChild(t)})}function w(e,t){g(e,t,function(){_(t)})}function M(e,t){t.assignedNodes().forEach(_),delete _e.get(e)[f(t)],pe["delete"](t)}function x(e,t){g(e,t,function(){if((0,z["default"])(t))M(e,t);else{var n=(0,V["default"])(t);if(n)for(var r=0;r<n.length;r++)M(e,n[r])}e.__removeChild(t)})}function T(e){if((0,Y["default"])(e))return e;if(e.parentNode)return T(e.parentNode)}function j(e,t,n){var r=d(e),i=t.parentNode,u=T(e);return k["default"]||Array.isArray(e.childNodes)||o(e,"childNodes",(0,K["default"])(e.childNodes)),u&&"slot"===d(t)&&C(u,t),i&&"host"===d(i)&&(k["default"]?fe.set(t,null):o(t,"parentNode",null)),"node"===r?k["default"]?(fe.set(t,e),e.__insertBefore(t,void 0!==n?n:null)):N(e,t,n):"slot"===r?b(e,t,n):"host"===r?m(e,t,n):"root"===r?y(e,t,n):void 0}function P(e){if(k["default"]&&"slot"===d(e)&&e.__childNodes.length!==e.childNodes.length){for(;e.hasChildNodes();)e.removeChild(e.firstChild);$.call(e.__childNodes,function(t){return e.appendChild(t)})}}Object.defineProperty(t,"__esModule",{value:!0});var L=n(1),S=n(2),k=r(S),D=n(3),A=r(D),W=n(4),H=r(W),F=n(6),B=r(F),R=n(7),G=r(R),I=n(8),V=r(I),X=n(10),Y=r(X),q=n(9),z=r(q),J=n(11),K=r(J),Q=n(12),U=r(Q);n(13),n(14);var Z=Array.prototype,$=Z.forEach,ee="_shadow_root_",te=["childNodes","parentNode"],ne=["textContent"],re=["assignedSlot"],ie=["textContent"],oe=[],ue=[Node.ELEMENT_NODE,Node.TEXT_NODE],ae=new WeakMap,se=new WeakMap,de=new WeakMap,le=new WeakMap,fe=new WeakMap,ce=new WeakMap,he=new WeakMap,_e=new WeakMap,pe=new WeakMap,ve=new DOMParser,ge={____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:(0,H["default"])(function(){this.____slotChangeListeners&&this.dispatchEvent(new CustomEvent("slotchange",{bubbles:!1,cancelable:!1}))})},addEventListener:{value:function(e,t,n){return"slotchange"===e&&(0,z["default"])(this)&&this.____slotChangeListeners++,this.__addEventListener(e,t,n)}},appendChild:{value:function(e){return j(this,e),e}},assignedSlot:{get:function(){var e=ce.get(this);if(!e)return null;var t=pe.get(e),n=he.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=de.get(this);if(r)return r;var i=a([].slice.call(this.childNodes)),u=document.createElement(e.polyfillShadowRootTagName||ee);return se.set(this,n),de.set(this,u),he.set(u,this),_e.set(u,{}),k["default"]?le.set(this,i):o(this,"childNodes",i),i.forEach(function(e){t.__removeChild(e),k["default"]?fe.set(e,t):o(e,"parentNode",t)}),this.__appendChild(u)}},childElementCount:{get:function(){return this.children.length}},childNodes:{get:function(){if(k["default"]&&"node"===d(this))return this.__childNodes;var e=le.get(this);return e||le.set(this,e=a([])),e}},children:{get:function(){var e=[];return(0,L.eachChildNode)(this,function(t){1===t.nodeType&&e.push(t)}),a(e)}},firstChild:{get:function(){return this.childNodes[0]||null}},firstElementChild:{get:function(){return this.children[0]||null}},assignedNodes:{value:function(){if((0,z["default"])(this)){var e=ae.get(this);return e||ae.set(this,e=[]),e}}},hasChildNodes:{value:function(){return this.childNodes.length>0}},innerHTML:{get:function(){var e="",t=function(e){return e.outerHTML},n={1:t,3:B["default"],8:G["default"]};return(0,L.eachChildNode)(this,function(r){var i=n[r.nodeType]||t;e+=i(r)}),e},set:function(e){for(var t=i(e);this.hasChildNodes();)this.removeChild(this.firstChild);var n=(0,V["default"])(t);for($.call(n,function(e){return P(e)});t.hasChildNodes();){var r=t.firstChild;t.removeChild(r),this.appendChild(r)}}},insertBefore:{value:function(e,t){return j(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(0,L.eachChildNode)(this.parentNode,function(t,n,r){if(e===t)return r[n+1]||null})}},nextElementSibling:{get:function(){var e=this,t=void 0;return(0,L.eachChildNode)(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=i(e);this.parentNode.replaceChild(t.firstChild,this)}else{if(!k["default"])throw new Error("Failed to set the 'outerHTML' property on 'Element': This element has no parent node.");this.__outerHTML=e}}},parentElement:{get:function(){return l(this.parentNode,function(e){return 1===e.nodeType})}},parentNode:{get:function(){return fe.get(this)||this.__parentNode||null}},previousSibling:{get:function(){var e=this;return(0,L.eachChildNode)(this.parentNode,function(t,n,r){if(e===t)return r[n-1]||null})}},previousElementSibling:{get:function(){var e=this,t=void 0;return(0,L.eachChildNode)(this.parentNode,function(n){return t&&e===n?t:void(1===n.nodeType&&(t=n))})}},removeChild:{value:function(e){var t=d(this);switch(t){case"node":if(k["default"])return fe.set(e,null),this.__removeChild(e);E(this,e);break;case"slot":O(this,e);break;case"host":w(this,e);break;case"root":x(this,e)}return e}},removeEventListener:{value:function(e,t,n){return"slotchange"===e&&this.____slotChangeListeners&&(0,z["default"])(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)?de.get(this):null}},textContent:{get:function(){var e="";return(0,L.eachChildNode)(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=Comment.prototype,t=HTMLElement.prototype,n=SVGElement.prototype,r=Text.prototype,i=document.createTextNode(""),o=document.createComment("");Object.keys(ge).forEach(function(u){var a=ge[u];if(a.configurable=!0,a.hasOwnProperty("value")&&(a.writable=!0),k["default"]||te.indexOf(u)===-1){var s=(0,A["default"])(t,u),d=(0,A["default"])(r,u),l=(0,A["default"])(e,u),f=u in i&&ne.indexOf(u)===-1||~re.indexOf(u),c=u in o&&ie.indexOf(u)===-1||~oe.indexOf(u),h="__"+u;Object.defineProperty(t,u,a),Object.defineProperty(n,u,a),s&&(Object.defineProperty(t,h,s),Object.defineProperty(n,h,s)),f&&Object.defineProperty(r,u,a),f&&d&&Object.defineProperty(r,h,d),c&&Object.defineProperty(e,u,a),c&&l&&Object.defineProperty(e,h,l)}})}(),t["default"]=U["default"]},function(e,t){"use strict";function n(e,t){if(e)for(var n=e.childNodes,r=n.length,i=0;i<r;i++){var o=t(n[i],i,n);if("undefined"!=typeof o)return o}}function r(e){for(var t=[],n=e.length-1;n>=0;n--)t.push(e[n]);return t}function i(e,t){if(e instanceof DocumentFragment)for(var n=e.childNodes,i=n.length,o=i-1;o>=0;o--){var u=r(e.childNodes)[o];t(u,o)}else t(e,0)}Object.defineProperty(t,"__esModule",{value:!0}),t.eachChildNode=n,t.eachNodeOrFragmentNodes=i},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var i=n(3),o=r(i),u=(0,o["default"])(Element.prototype,"innerHTML");t["default"]=!!u},function(e,t){"use strict";function n(e,t){for(var n=void 0;e&&!(n=Object.getOwnPropertyDescriptor(e,t));)e=Object.getPrototypeOf(e);return n}Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=function(e,t){e instanceof Node&&(e=r);var i=n(e,t);if(i){var o=i.get,u=i.set,a={configurable:!0,enumerable:!0};if(o)return a.get=o,a.set=u,a;if("function"==typeof e[t])return a.value=e[t],a}var s=Object.getOwnPropertyDescriptor(e,t);if(s&&s.get)return s};var r=document.createElement("div")},function(e,t,n){"use strict";var r=n(5);e.exports=function(e,t,n){function i(){var l=r()-s;l<t&&l>0?o=setTimeout(i,t-l):(o=null,n||(d=e.apply(a,u),o||(a=u=null)))}var o,u,a,s,d;return null==t&&(t=100),function(){a=this,u=arguments,s=r();var l=n&&!o;return o||(o=setTimeout(i,t)),l&&(d=e.apply(a,u),a=u=null),d}}},function(e,t){"use strict";function n(){return(new Date).getTime()}e.exports=Date.now||n},function(e,t){"use strict";function n(e){return e.textContent.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=n},function(e,t){"use strict";function n(e){return e.text||"<!--"+e.textContent+"-->"}Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=n},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function i(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 r=n.length,o=0;o<r;o++){var a=n[o];(0,u["default"])(a)&&t.push(a),i(a,t)}return t}Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=i;var o=n(9),u=r(o)},function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=function(e){return"SLOT"===e.tagName}},function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=function(e){return"_SHADOW_ROOT_"===e.tagName}},function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=function(e){return Array.prototype.slice.call(e)}},function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t["default"]="0.0.1"},function(e,t){"use strict";/** | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.skatejsNamedSlots=t():e.skatejsNamedSlots=t()}(this,function(){return function(e){function t(r){if(n[r])return n[r].exports;var o=n[r]={exports:{},id:r,loaded:!1};return e[r].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function o(e){var t=document.createElement("div");if(D["default"])return t.__innerHTML=e,t;for(var n=Ne.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 i(e,t,n){Object.defineProperty(e,t,{configurable:!0,get:function(){return n}})}function u(e){return this[e]}function a(e){return e.item=u,e}function s(e){return!!fe.get(e)}function l(e){return s(e)?"host":(0,J["default"])(e)?"slot":(0,I["default"])(e)?"root":"node"}function d(e,t){for(;e&&e!==document;){if(t(e))return e;e=e.parentNode}}function c(e){return e.getAttribute&&e.getAttribute("name")||"default"}function f(e){return e.getAttribute&&e.getAttribute("slot")||"default"}function h(e,t,n){if(le.indexOf(t.nodeType)!==-1){var r=e.assignedNodes(),o=0===r.length,i=r.indexOf(n);ve.set(t,e),o&&ne.call(e.childNodes,function(t){return e.__removeChild(t)}),i>-1?(e.__insertBefore(t,void 0!==n?n:null),r.splice(i,0,t)):(e.__appendChild(t),r.push(t)),e.____triggerSlotChangeEvent()}}function p(e){var t=e.assignedSlot;if(t){var n=t.assignedNodes(),r=n.indexOf(e);if(r>-1){var o=1===n.length;n.splice(r,1),ve.set(e,null),t.__removeChild(e),o&&ne.call(t.childNodes,function(e){return t.__appendChild(e)}),t.____triggerSlotChangeEvent()}}}function v(e,t){for(var n=e.childNodes,r=n.length,o=0;o<r;o++)if(n[o]===t)return o;return-1}function _(e,t,n,r){var o=v(e,n);(0,S.eachNodeOrFragmentNodes)(t,function(t,n){r(t,n),D["default"]?pe.set(t,e):i(t,"parentNode",e),o>-1?te.splice.call(e.childNodes,o+n,0,t):te.push.call(e.childNodes,t)})}function g(e,t,n){var r=v(e,t);r>-1&&(n(t,0),D["default"]?pe.set(t,null):i(t,"parentNode",null),te.splice.call(e.childNodes,r,1))}function m(e,t,n){_(e,t,n,function(t){e.__insertBefore(t,void 0!==n?n:null)})}function N(e,t,n){_(e,t,n,function(t){var r=fe.get(e),o=ge.get(r),i=o[f(t)];i&&h(i,t,n)})}function y(e,t){var n=c(t);D["default"]||Array.isArray(t.childNodes)||i(t,"childNodes",(0,Q["default"])(t.childNodes)),ge.get(e)[n]=t,me.has(t)||me.set(t,e),(0,S.eachChildNode)(_e.get(e),function(e){e.assignedSlot||n!==f(e)||h(t,e)})}function b(e,t,n){(0,S.eachNodeOrFragmentNodes)(t,function(t){if((0,J["default"])(t))y(e,t);else{var n=(0,Y["default"])(t);if(n)for(var r=n.length,o=0;o<r;o++)y(e,n[o])}}),m(e,t,n)}function C(e,t,n){var r=0===e.assignedNodes().length;_(e,t,n,function(t){r&&e.__insertBefore(t,void 0!==n?n:null)})}function E(e,t){var n=0===e.assignedNodes().length;g(e,t,function(){n&&e.__removeChild(t)})}function O(e,t){g(e,t,function(){e.__removeChild(t)})}function w(e,t){g(e,t,function(){p(t)})}function M(e,t){t.assignedNodes().forEach(p),delete ge.get(e)[c(t)],me["delete"](t)}function T(e,t){g(e,t,function(){if((0,J["default"])(t))M(e,t);else{var n=(0,Y["default"])(t);if(n)for(var r=0;r<n.length;r++)M(e,n[r])}e.__removeChild(t)})}function j(e){if((0,I["default"])(e))return e;if(e.parentNode)return j(e.parentNode)}function L(e,t,n){var r=l(e),o=t.parentNode,u=j(e);return D["default"]||Array.isArray(e.childNodes)||i(e,"childNodes",(0,Q["default"])(e.childNodes)),u&&"slot"===l(t)&&y(u,t),o&&"host"===l(o)&&(D["default"]?pe.set(t,null):i(t,"parentNode",null)),"node"===r?D["default"]?(pe.set(t,e),e.__insertBefore(t,void 0!==n?n:null)):m(e,t,n):"slot"===r?C(e,t,n):"host"===r?N(e,t,n):"root"===r?b(e,t,n):void 0}function P(e){if(D["default"]&&"slot"===l(e)&&e.__childNodes.length!==e.childNodes.length){for(;e.hasChildNodes();)e.removeChild(e.firstChild);ne.call(e.__childNodes,function(t){return e.appendChild(t)})}}Object.defineProperty(t,"__esModule",{value:!0});var S=n(1),x=n(2),A=n(3),D=r(A),k=n(4),H=r(k),W=n(5),R=r(W),F=n(7),B=r(F),V=n(8),q=r(V),X=n(9),Y=r(X),G=n(11),I=r(G),z=n(10),J=r(z),K=n(12),Q=r(K),U=n(13),Z=r(U),$=n(15),ee=r($);n(16),n(14);var te=Array.prototype,ne=te.forEach,re="_shadow_root_",oe=["childNodes","parentNode"],ie=["textContent"],ue=["assignedSlot"],ae=["textContent"],se=[],le=[Node.ELEMENT_NODE,Node.TEXT_NODE],de=new WeakMap,ce=new WeakMap,fe=new WeakMap,he=new WeakMap,pe=new WeakMap,ve=new WeakMap,_e=new WeakMap,ge=new WeakMap,me=new WeakMap,Ne=new DOMParser,ye={____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:(0,R["default"])(function(){this.____slotChangeListeners&&this.dispatchEvent(new CustomEvent("slotchange",{bubbles:!1,cancelable:!1}))})},addEventListener:{value:function(e,t,n){return"slotchange"===e&&(0,J["default"])(this)&&this.____slotChangeListeners++,this.__addEventListener(e,t,n)}},appendChild:{value:function(e){return L(this,e),e}},assignedSlot:{get:function(){var e=ve.get(this);if(!e)return null;var t=me.get(e),n=_e.get(t),r=ce.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=fe.get(this);if(r)return r;var o=a([].slice.call(this.childNodes)),u=document.createElement(e.polyfillShadowRootTagName||re);return ce.set(this,n),fe.set(this,u),_e.set(u,this),ge.set(u,{}),D["default"]?he.set(this,o):i(this,"childNodes",o),o.forEach(function(e){t.__removeChild(e),D["default"]?pe.set(e,t):i(e,"parentNode",t)}),this.__appendChild(u)}},childElementCount:{get:function(){return this.children.length}},childNodes:{get:function(){if(D["default"]&&"node"===l(this))return this.__childNodes;var e=he.get(this);return e||he.set(this,e=a([])),e}},children:{get:function(){var e=[];return(0,S.eachChildNode)(this,function(t){1===t.nodeType&&e.push(t)}),a(e)}},firstChild:{get:function(){return this.childNodes[0]||null}},firstElementChild:{get:function(){return this.children[0]||null}},assignedNodes:{value:function(){if((0,J["default"])(this)){var e=de.get(this);return e||de.set(this,e=[]),e}}},hasChildNodes:{value:function(){return this.childNodes.length>0}},innerHTML:{get:function(){var e="",t=function(e){return e.outerHTML},n={1:t,3:B["default"],8:q["default"]};return(0,S.eachChildNode)(this,function(r){var o=n[r.nodeType]||t;e+=o(r)}),e},set:function(e){for(var t=o(e);this.hasChildNodes();)this.removeChild(this.firstChild);var n=(0,Y["default"])(t);for(ne.call(n,function(e){return P(e)});t.hasChildNodes();){var r=t.firstChild;t.removeChild(r),this.appendChild(r)}}},insertBefore:{value:function(e,t){return L(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(0,S.eachChildNode)(this.parentNode,function(t,n,r){if(e===t)return r[n+1]||null})}},nextElementSibling:{get:function(){var e=this,t=void 0;return(0,S.eachChildNode)(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=o(e);this.parentNode.replaceChild(t.firstChild,this)}else{if(!D["default"])throw new Error("Failed to set the 'outerHTML' property on 'Element': This element has no parent node.");this.__outerHTML=e}}},parentElement:{get:function(){return d(this.parentNode,function(e){return 1===e.nodeType})}},parentNode:{get:function(){return pe.get(this)||this.__parentNode||null}},previousSibling:{get:function(){var e=this;return(0,S.eachChildNode)(this.parentNode,function(t,n,r){if(e===t)return r[n-1]||null})}},previousElementSibling:{get:function(){var e=this,t=void 0;return(0,S.eachChildNode)(this.parentNode,function(n){return t&&e===n?t:void(1===n.nodeType&&(t=n))})}},removeChild:{value:function(e){var t=l(this);switch(t){case"node":if(D["default"])return pe.set(e,null),this.__removeChild(e);O(this,e);break;case"slot":E(this,e);break;case"host":w(this,e);break;case"root":T(this,e)}return e}},removeEventListener:{value:function(e,t,n){return"slotchange"===e&&this.____slotChangeListeners&&(0,J["default"])(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"===ce.get(this)?fe.get(this):null}},textContent:{get:function(){var e="";return(0,S.eachChildNode)(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))}}};x.shadowDomV1||(x.shadowDomV0?(0,Z["default"])():!function(){var e=Comment.prototype,t=HTMLElement.prototype,n=SVGElement.prototype,r=Text.prototype,o=document.createTextNode(""),i=document.createComment("");Object.keys(ye).forEach(function(u){var a=ye[u];if(a.configurable=!0,a.hasOwnProperty("value")&&(a.writable=!0),D["default"]||oe.indexOf(u)===-1){var s=(0,H["default"])(t,u),l=(0,H["default"])(r,u),d=(0,H["default"])(e,u),c=u in o&&ie.indexOf(u)===-1||~ue.indexOf(u),f=u in i&&ae.indexOf(u)===-1||~se.indexOf(u),h="__"+u;Object.defineProperty(t,u,a),Object.defineProperty(n,u,a),s&&(Object.defineProperty(t,h,s),Object.defineProperty(n,h,s)),c&&Object.defineProperty(r,u,a),c&&l&&Object.defineProperty(r,h,l),f&&Object.defineProperty(e,u,a),f&&d&&Object.defineProperty(e,h,d)}})}()),t["default"]=ee["default"]},function(e,t){"use strict";function n(e,t){if(e)for(var n=e.childNodes,r=n.length,o=0;o<r;o++){var i=t(n[o],o,n);if("undefined"!=typeof i)return i}}function r(e){for(var t=[],n=e.length-1;n>=0;n--)t.push(e[n]);return t}function o(e,t){if(e instanceof DocumentFragment)for(var n=e.childNodes,o=n.length,i=o-1;i>=0;i--){var u=r(e.childNodes)[i];t(u,i)}else t(e,0)}Object.defineProperty(t,"__esModule",{value:!0}),t.eachChildNode=n,t.eachNodeOrFragmentNodes=o},function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=document.createElement("div");t.shadowDomV0=!!n.createShadowRoot,t.shadowDomV1=!!n.attachShadow},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var o=n(4),i=r(o),u=(0,i["default"])(Element.prototype,"innerHTML");t["default"]=!!u},function(e,t){"use strict";function n(e,t){for(var n=void 0;e&&!(n=Object.getOwnPropertyDescriptor(e,t));)e=Object.getPrototypeOf(e);return n}Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=function(e,t){e instanceof Node&&(e=r);var o=n(e,t);if(o){var i=o.get,u=o.set,a={configurable:!0,enumerable:!0};if(i)return a.get=i,a.set=u,a;if("function"==typeof e[t])return a.value=e[t],a}var s=Object.getOwnPropertyDescriptor(e,t);if(s&&s.get)return s};var r=document.createElement("div")},function(e,t,n){"use strict";var r=n(6);e.exports=function(e,t,n){function o(){var d=r()-s;d<t&&d>0?i=setTimeout(o,t-d):(i=null,n||(l=e.apply(a,u),i||(a=u=null)))}var i,u,a,s,l;return null==t&&(t=100),function(){a=this,u=arguments,s=r();var d=n&&!i;return i||(i=setTimeout(o,t)),d&&(l=e.apply(a,u),a=u=null),l}}},function(e,t){"use strict";function n(){return(new Date).getTime()}e.exports=Date.now||n},function(e,t){"use strict";function n(e){return e.textContent.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=n},function(e,t){"use strict";function n(e){return e.text||"<!--"+e.textContent+"-->"}Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=n},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function o(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)}function i(e){var t=arguments.length<=1||void 0===arguments[1]?[]:arguments[1],n=e.childNodes;if(u.shadowDomV0)return[].concat(o(e.querySelectorAll("content")));if(!n||e.nodeType!==Node.ELEMENT_NODE)return t;for(var r=n.length,a=0;a<r;a++){var l=n[a];(0,s["default"])(l)&&t.push(l),i(l,t)}return t}Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=i;var u=n(2),a=n(10),s=r(a)},function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=function(e){return"SLOT"===e.tagName}},function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=function(e){return"_SHADOW_ROOT_"===e.tagName}},function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=function(e){return Array.prototype.slice.call(e)}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),n(14);var r="__shadowRoot";t["default"]=function(){function e(e){for(var t=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT),n=[];t.nextNode();){var r=t.currentNode;"SLOT"===r.tagName&&n.push(r)}n.forEach(function(e){var t=e.getAttribute("name"),n=document.createElement("slot");for(t&&n.setAttribute("name",t),e.parentNode.replaceChild(n,e);e.hasChildNodes();)n.appendChild(e.firstChild)})}var t=function(e){for(var t=e.getAttribute("name"),n=e;n;){var o=n[r];if(o&&o.contains(e))break;n=n.parentNode}if(!n)return[];for(var i=n.childNodes,u=i.length,a=[],s=0;s<u;s++){var l=i[s],d=l.getAttribute?l.getAttribute("slot"):null;t===d&&a.push(l)}return a},n=HTMLElement.prototype,o=n.getAttribute,i=n.setAttribute,u=Object.getOwnPropertyDescriptor(Element.prototype,"innerHTML"),a=Object.getOwnPropertyDescriptor(ShadowRoot.prototype,"innerHTML"),s=function(e){return"slot"===e?"content":e},l=document.createElement.bind(document),d=document.createElementNS.bind(document);document.createElement=function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];return l.apply(void 0,[s(e)].concat(n))},document.createElementNS=function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];return d.apply(void 0,[s(e)].concat(n))},Object.defineProperty(Element.prototype,"innerHTML",{configurable:!0,get:u.get,set:function(t){u.set.call(this,t),e(this)}}),Object.defineProperty(ShadowRoot.prototype,"innerHTML",{configurable:!0,get:a.get,set:function(t){a.set.call(this,t),e(this)}}),Object.defineProperty(Node.prototype,"assignedSlot",{get:function(){var e=this.parentNode;if(e){var t=e.shadowRoot;if(!t)return null;for(var n=t.querySelectorAll("content"),r=0;r<n.length;r++){var o=n[r];if(o.assignedNodes().indexOf(this)>-1)return o}}return null}}),HTMLElement.prototype.attachShadow=function(){var e=this,t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],n=t.mode;if("closed"!==n&&"open"!==n)throw new Error('You must specify { mode } as "open" or "closed" to attachShadow().');var o=this.createShadowRoot();"closed"===n&&Object.defineProperty(this,"shadowRoot",{configurable:!0,get:function(){return null}}),Object.defineProperty(o,"parentNode",{get:function(){return e}});var i=new MutationObserver(function(t){var n=e[r];t.forEach(function(e){var t=e.addedNodes,r=e.removedNodes,o={},i=function(e){return o[e.getAttribute&&e.getAttribute("slot")||"__default"]=!0};if(t)for(var u=t.length,a=0;a<u;a++)i(t[a]);if(r)for(var s=r.length,l=0;l<s;l++)i(r[l]);Object.keys(o).forEach(function(e){var t="__default"===e?n.querySelector("content:not([name])")||n.querySelector('content[name=""]'):n.querySelector('content[name="'+e+'"]');t&&t.dispatchEvent(new CustomEvent("slotchange",{bubbles:!1,cancelable:!1}))})})});return i.observe(this,{childList:!0}),this[r]=o},Object.defineProperty(HTMLContentElement.prototype,"name",{get:function(){return this.getAttribute("name")},set:function(e){return this.setAttribute("name",e)}}),HTMLContentElement.prototype.assignedNodes=function(){for(var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],n=e.deep,r=[],o=n?this.getDistributedNodes():t(this),i=0;i<o.length;i++){var u=o[i],a=u.nodeType;a!==Node.ELEMENT_NODE&&a!==Node.TEXT_NODE||r.push(u)}return r},HTMLContentElement.prototype.getAttribute=function(e){if("name"===e){var t=o.call(this,"select");return t?t.match(/\[slot=['"]?(.*?)['"]?\]/)[1]:null}return o.call(this,e)},HTMLContentElement.prototype.setAttribute=function(e,t){return"name"===e&&(e="select",t="[slot='"+t+"']"),i.call(this,e,t)}}},function(e,t){"use strict";try{var n=new window.CustomEvent("test",{bubbles:!1,cancelable:!0,detail:{x:"y"}});if(n.preventDefault(),n.defaultPrevented!==!0)throw new Error("Could not prevent default")}catch(r){var o=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};o.prototype=window.Event.prototype,window.CustomEvent=o}},function(e,t){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t["default"]="0.0.1"},function(e,t){"use strict";/** | ||
* @license | ||
@@ -10,3 +10,3 @@ * Copyright (c) 2014 The Polymer Project Authors. All rights reserved. | ||
*/ | ||
"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)},has:function(e){var t=e[this.name];return!!t&&t[0]===e}},window.WeakMap=n}()},function(e,t){"use strict";try{var n=new window.CustomEvent("test",{bubbles:!1,cancelable:!0,detail:{x:"y"}});if(n.preventDefault(),n.defaultPrevented!==!0)throw new Error("Could not prevent default")}catch(r){var i=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};i.prototype=window.Event.prototype,window.CustomEvent=i}}])}); | ||
"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)},has:function(e){var t=e[this.name];return!!t&&t[0]===e}},window.WeakMap=n}()}])}); | ||
//# sourceMappingURL=index-with-deps.min.js.map |
@@ -55,3 +55,7 @@ (function (global, factory) { | ||
var div = document.createElement('div'); | ||
var shadowDomV0 = !!div.createShadowRoot; | ||
var shadowDomV1 = !!div.attachShadow; | ||
var div$1 = document.createElement('div'); | ||
function getPrototype(obj, key) { | ||
@@ -68,3 +72,3 @@ var descriptor = void 0; | ||
if (obj instanceof Node) { | ||
obj = div; | ||
obj = div$1; | ||
} | ||
@@ -122,2 +126,12 @@ var proto = getPrototype(obj, key); | ||
var toConsumableArray = function (arr) { | ||
if (Array.isArray(arr)) { | ||
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} else { | ||
return Array.from(arr); | ||
} | ||
}; | ||
function findSlots(root) { | ||
@@ -128,2 +142,6 @@ var slots = arguments.length <= 1 || arguments[1] === undefined ? [] : arguments[1]; | ||
if (shadowDomV0) { | ||
return [].concat(toConsumableArray(root.querySelectorAll('content'))); | ||
} | ||
if (!childNodes || root.nodeType !== Node.ELEMENT_NODE) { | ||
@@ -156,2 +174,267 @@ return slots; | ||
var $shadowRoot = '__shadowRoot'; | ||
var v0 = (function () { | ||
// Returns the assigned nodes (unflattened) for a <content> node. | ||
var getAssignedNodes = function getAssignedNodes(node) { | ||
var slot = node.getAttribute('name'); | ||
var host = node; | ||
while (host) { | ||
var sr = host[$shadowRoot]; | ||
if (sr && sr.contains(node)) { | ||
break; | ||
} | ||
host = host.parentNode; | ||
} | ||
if (!host) { | ||
return []; | ||
} | ||
var chs = host.childNodes; | ||
var chsLen = chs.length; | ||
var filtered = []; | ||
for (var a = 0; a < chsLen; a++) { | ||
var ch = chs[a]; | ||
var chSlot = ch.getAttribute ? ch.getAttribute('slot') : null; | ||
if (slot === chSlot) { | ||
filtered.push(ch); | ||
} | ||
} | ||
return filtered; | ||
}; | ||
var _HTMLElement$prototyp = HTMLElement.prototype; | ||
var getAttribute = _HTMLElement$prototyp.getAttribute; | ||
var setAttribute = _HTMLElement$prototyp.setAttribute; | ||
var elementInnerHTML = Object.getOwnPropertyDescriptor(Element.prototype, 'innerHTML'); | ||
var shadowRootInnerHTML = Object.getOwnPropertyDescriptor(ShadowRoot.prototype, 'innerHTML'); | ||
// We do this so creating a <slot> actually creates a <content>. | ||
var filterTagName = function filterTagName(name) { | ||
return name === 'slot' ? 'content' : name; | ||
}; | ||
var createElement = document.createElement.bind(document); | ||
var createElementNS = document.createElementNS.bind(document); | ||
document.createElement = function (name) { | ||
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
args[_key - 1] = arguments[_key]; | ||
} | ||
return createElement.apply(undefined, [filterTagName(name)].concat(args)); | ||
}; | ||
document.createElementNS = function (name) { | ||
for (var _len2 = arguments.length, args = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { | ||
args[_key2 - 1] = arguments[_key2]; | ||
} | ||
return createElementNS.apply(undefined, [filterTagName(name)].concat(args)); | ||
}; | ||
// Override innerHTML to turn slot nodes into content nodes. | ||
function replaceSlotsWithContents(node) { | ||
var tree = document.createTreeWalker(node, NodeFilter.SHOW_ELEMENT); | ||
var repl = []; | ||
// Walk the tree and record nodes that need replacing. | ||
while (tree.nextNode()) { | ||
var currentNode = tree.currentNode; | ||
if (currentNode.tagName === 'SLOT') { | ||
repl.push(currentNode); | ||
} | ||
} | ||
repl.forEach(function (fake) { | ||
var name = fake.getAttribute('name'); | ||
var real = document.createElement('slot'); | ||
if (name) { | ||
real.setAttribute('name', name); | ||
} | ||
fake.parentNode.replaceChild(real, fake); | ||
while (fake.hasChildNodes()) { | ||
real.appendChild(fake.firstChild); | ||
} | ||
}); | ||
} | ||
Object.defineProperty(Element.prototype, 'innerHTML', { | ||
configurable: true, | ||
get: elementInnerHTML.get, | ||
set: function set(html) { | ||
elementInnerHTML.set.call(this, html); | ||
replaceSlotsWithContents(this); | ||
} | ||
}); | ||
Object.defineProperty(ShadowRoot.prototype, 'innerHTML', { | ||
configurable: true, | ||
get: shadowRootInnerHTML.get, | ||
set: function set(html) { | ||
shadowRootInnerHTML.set.call(this, html); | ||
replaceSlotsWithContents(this); | ||
} | ||
}); | ||
// Node | ||
// ---- | ||
Object.defineProperty(Node.prototype, 'assignedSlot', { | ||
get: function get() { | ||
var parentNode = this.parentNode; | ||
if (parentNode) { | ||
var shadowRoot = parentNode.shadowRoot; | ||
// If { mode } is "closed", always return `null`. | ||
if (!shadowRoot) { | ||
return null; | ||
} | ||
var contents = shadowRoot.querySelectorAll('content'); | ||
for (var a = 0; a < contents.length; a++) { | ||
var content = contents[a]; | ||
if (content.assignedNodes().indexOf(this) > -1) { | ||
return content; | ||
} | ||
} | ||
} | ||
return null; | ||
} | ||
}); | ||
// Just proxy createShadowRoot() because there's no such thing as closed | ||
// shadow trees in v0. | ||
HTMLElement.prototype.attachShadow = function attachShadow() { | ||
var _this = this; | ||
var _ref = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
var mode = _ref.mode; | ||
// In v1 you must specify a mode. | ||
if (mode !== 'closed' && mode !== 'open') { | ||
throw new Error('You must specify { mode } as "open" or "closed" to attachShadow().'); | ||
} | ||
// Proxy native v0. | ||
var sr = this.createShadowRoot(); | ||
// In v0 it always defines the shadowRoot property so we must undefine it. | ||
if (mode === 'closed') { | ||
Object.defineProperty(this, 'shadowRoot', { | ||
configurable: true, | ||
get: function get() { | ||
return null; | ||
} | ||
}); | ||
} | ||
// For some reason this wasn't being reported as set, but it seems to work | ||
// in dev tools. | ||
Object.defineProperty(sr, 'parentNode', { | ||
get: function get() { | ||
return _this; | ||
} | ||
}); | ||
// Add a MutationObserver to trigger slot change events when the element | ||
// is mutated. We only need to listen to the childList because we only care | ||
// about light DOM. | ||
var mo = new MutationObserver(function (muts) { | ||
var root = _this[$shadowRoot]; | ||
muts.forEach(function (mut) { | ||
var addedNodes = mut.addedNodes; | ||
var removedNodes = mut.removedNodes; | ||
var slots = {}; | ||
var recordSlots = function recordSlots(node) { | ||
return slots[node.getAttribute && node.getAttribute('slot') || '__default'] = true; | ||
}; | ||
if (addedNodes) { | ||
var addedNodesLen = addedNodes.length; | ||
for (var a = 0; a < addedNodesLen; a++) { | ||
recordSlots(addedNodes[a]); | ||
} | ||
} | ||
if (removedNodes) { | ||
var removedNodesLen = removedNodes.length; | ||
for (var _a = 0; _a < removedNodesLen; _a++) { | ||
recordSlots(removedNodes[_a]); | ||
} | ||
} | ||
Object.keys(slots).forEach(function (slot) { | ||
var node = slot === '__default' ? root.querySelector('content:not([name])') || root.querySelector('content[name=""]') : root.querySelector('content[name="' + slot + '"]'); | ||
if (node) { | ||
node.dispatchEvent(new CustomEvent('slotchange', { | ||
bubbles: false, | ||
cancelable: false | ||
})); | ||
} | ||
}); | ||
}); | ||
}); | ||
mo.observe(this, { childList: true }); | ||
return this[$shadowRoot] = sr; | ||
}; | ||
// Make like the <slot> name property. | ||
Object.defineProperty(HTMLContentElement.prototype, 'name', { | ||
get: function get() { | ||
return this.getAttribute('name'); | ||
}, | ||
set: function set(name) { | ||
return this.setAttribute('name', name); | ||
} | ||
}); | ||
// By default, getDistributedNodes() returns a flattened tree (no <slot> | ||
// nodes). That means we get native { deep } but we have to manually do the | ||
// opposite. | ||
HTMLContentElement.prototype.assignedNodes = function assignedNodes() { | ||
var _ref2 = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
var deep = _ref2.deep; | ||
var cnodes = []; | ||
var dnodes = deep ? this.getDistributedNodes() : getAssignedNodes(this); | ||
// Regardless of how we get the nodes, we must ensure we're only given text | ||
// nodes or element nodes. | ||
for (var a = 0; a < dnodes.length; a++) { | ||
var dnode = dnodes[a]; | ||
var dtype = dnode.nodeType; | ||
if (dtype === Node.ELEMENT_NODE || dtype === Node.TEXT_NODE) { | ||
cnodes.push(dnode); | ||
} | ||
} | ||
return cnodes; | ||
}; | ||
HTMLContentElement.prototype.getAttribute = function overriddenGetAttribute(name) { | ||
if (name === 'name') { | ||
var select = getAttribute.call(this, 'select'); | ||
return select ? select.match(/\[slot=['"]?(.*?)['"]?\]/)[1] : null; | ||
} | ||
return getAttribute.call(this, name); | ||
}; | ||
HTMLContentElement.prototype.setAttribute = function overriddenSetAttribute(name, value) { | ||
if (name === 'name') { | ||
name = 'select'; | ||
value = '[slot=\'' + value + '\']'; | ||
} | ||
return setAttribute.call(this, name, value); | ||
}; | ||
}) | ||
var version = '0.0.1'; | ||
@@ -331,22 +614,3 @@ | ||
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; | ||
} | ||
// only Text and Element nodes should be slotted | ||
// Only Text and Element nodes should be slotted. | ||
if (slottedNodeTypes.indexOf(node.nodeType) === -1) { | ||
@@ -1046,58 +1310,62 @@ return; | ||
if (!('attachShadow' in document.createElement('div'))) { | ||
(function () { | ||
var commProto = Comment.prototype; | ||
var elementProto = HTMLElement.prototype; | ||
var svgProto = SVGElement.prototype; | ||
var textProto = Text.prototype; | ||
var textNode = document.createTextNode(''); | ||
var commNode = document.createComment(''); | ||
if (shadowDomV1) { | ||
// then we should probably not be loading this | ||
} else if (shadowDomV0) { | ||
v0(); | ||
} else { | ||
(function () { | ||
var commProto = Comment.prototype; | ||
var elementProto = HTMLElement.prototype; | ||
var svgProto = SVGElement.prototype; | ||
var textProto = Text.prototype; | ||
var textNode = document.createTextNode(''); | ||
var commNode = document.createComment(''); | ||
Object.keys(members).forEach(function (memberName) { | ||
var memberProperty = members[memberName]; | ||
Object.keys(members).forEach(function (memberName) { | ||
var memberProperty = members[memberName]; | ||
// All properties should be configurable. | ||
memberProperty.configurable = true; | ||
// All properties should be configurable. | ||
memberProperty.configurable = true; | ||
// Applying to the data properties only since we can't have writable accessor properties. | ||
if (memberProperty.hasOwnProperty('value')) { | ||
memberProperty.writable = true; | ||
} | ||
// Applying to the data properties only since we can't have writable accessor properties. | ||
if (memberProperty.hasOwnProperty('value')) { | ||
memberProperty.writable = true; | ||
} | ||
// 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; | ||
// 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; | ||
Object.defineProperty(elementProto, memberName, memberProperty); | ||
Object.defineProperty(svgProto, memberName, memberProperty); | ||
Object.defineProperty(elementProto, memberName, memberProperty); | ||
Object.defineProperty(svgProto, memberName, memberProperty); | ||
if (nativeDescriptor) { | ||
Object.defineProperty(elementProto, nativeMemberName, nativeDescriptor); | ||
Object.defineProperty(svgProto, nativeMemberName, nativeDescriptor); | ||
} | ||
if (nativeDescriptor) { | ||
Object.defineProperty(elementProto, nativeMemberName, nativeDescriptor); | ||
Object.defineProperty(svgProto, nativeMemberName, nativeDescriptor); | ||
} | ||
if (shouldOverrideInTextNode) { | ||
Object.defineProperty(textProto, memberName, memberProperty); | ||
} | ||
if (shouldOverrideInTextNode) { | ||
Object.defineProperty(textProto, memberName, memberProperty); | ||
} | ||
if (shouldOverrideInTextNode && nativeTextDescriptor) { | ||
Object.defineProperty(textProto, nativeMemberName, nativeTextDescriptor); | ||
} | ||
if (shouldOverrideInTextNode && nativeTextDescriptor) { | ||
Object.defineProperty(textProto, nativeMemberName, nativeTextDescriptor); | ||
} | ||
if (shouldOverrideInCommentNode) { | ||
Object.defineProperty(commProto, memberName, memberProperty); | ||
} | ||
if (shouldOverrideInCommentNode) { | ||
Object.defineProperty(commProto, memberName, memberProperty); | ||
} | ||
if (shouldOverrideInCommentNode && nativeCommDescriptor) { | ||
Object.defineProperty(commProto, nativeMemberName, nativeCommDescriptor); | ||
if (shouldOverrideInCommentNode && nativeCommDescriptor) { | ||
Object.defineProperty(commProto, nativeMemberName, nativeCommDescriptor); | ||
} | ||
} | ||
} | ||
}); | ||
})(); | ||
} | ||
}); | ||
})(); | ||
} | ||
@@ -1104,0 +1372,0 @@ exports['default'] = version; |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("debounce"),require("custom-event-polyfill")):"function"==typeof define&&define.amd?define(["exports","debounce","custom-event-polyfill"],t):t(e.skatejsNamedSlots=e.skatejsNamedSlots||{},e.debounce,e.customEventPolyfill)}(this,function(e,t,n){function i(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 r(e){for(var t=[],n=e.length-1;n>=0;n--)t.push(e[n]);return t}function o(e,t){if(e instanceof DocumentFragment)for(var n=e.childNodes,i=n.length,o=i-1;o>=0;o--){var s=r(e.childNodes)[o];t(s,o)}else t(e,0)}function s(e,t){for(var n=void 0;e&&!(n=Object.getOwnPropertyDescriptor(e,t));)e=Object.getPrototypeOf(e);return n}function u(e,t){e instanceof Node&&(e=R);var n=s(e,t);if(n){var i=n.get,r=n.set,o={configurable:!0,enumerable:!0};if(i)return o.get=i,o.set=r,o;if("function"==typeof e[t])return o.value=e[t],o}var u=Object.getOwnPropertyDescriptor(e,t);if(u&&u.get)return u}function a(e){return e.textContent.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function d(e){return e.text||"<!--"+e.textContent+"-->"}function l(e){return"SLOT"===e.tagName}function h(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];l(o)&&t.push(o),h(o,t)}return t}function c(e){return"_SHADOW_ROOT_"===e.tagName}function f(e){var t=document.createElement("div");if(G)return t.__innerHTML=e,t;for(var n=de.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 _(e,t,n){Object.defineProperty(e,t,{configurable:!0,get:function(){return n}})}function p(e){return this[e]}function v(e){return e.item=p,e}function g(e){return!!ne.get(e)}function N(e){return g(e)?"host":l(e)?"slot":c(e)?"root":"node"}function m(e,t){for(;e&&e!==document;){if(t(e))return e;e=e.parentNode}}function C(e){return e.getAttribute&&e.getAttribute("name")||"default"}function y(e){return e.getAttribute&&e.getAttribute("slot")||"default"}function b(e,t,n){if((3!==t.nodeType||!t.textContent||0!==t.textContent.trim().length)&&$.indexOf(t.nodeType)!==-1){var i=e.assignedNodes(),r=0===i.length,o=i.indexOf(n);oe.set(t,e),r&&Y.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 E(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),oe.set(e,null),t.__removeChild(e),r&&Y.call(t.childNodes,function(e){return t.__appendChild(e)}),t.____triggerSlotChangeEvent()}}}function O(e,t){for(var n=e.childNodes,i=n.length,r=0;r<i;r++)if(n[r]===t)return r;return-1}function w(e,t,n,i){var r=O(e,n);o(t,function(t,n){i(t,n),G?re.set(t,e):_(t,"parentNode",e),r>-1?X.splice.call(e.childNodes,r+n,0,t):X.push.call(e.childNodes,t)})}function T(e,t,n){var i=O(e,t);i>-1&&(n(t,0),G?re.set(t,null):_(t,"parentNode",null),X.splice.call(e.childNodes,i,1))}function M(e,t,n){w(e,t,n,function(t){e.__insertBefore(t,void 0!==n?n:null)})}function x(e,t,n){w(e,t,n,function(t){var i=ne.get(e),r=ue.get(i),o=r[y(t)];o&&b(o,t,n)})}function L(e,t){var n=C(t);G||Array.isArray(t.childNodes)||_(t,"childNodes",I(t.childNodes)),ue.get(e)[n]=t,ae.has(t)||ae.set(t,e),i(se.get(e),function(e){e.assignedSlot||n!==y(e)||b(t,e)})}function S(e,t,n){o(t,function(t){if(l(t))L(e,t);else{var n=h(t);if(n)for(var i=n.length,r=0;r<i;r++)L(e,n[r])}}),M(e,t,n)}function j(e,t,n){var i=0===e.assignedNodes().length;w(e,t,n,function(t){i&&e.__insertBefore(t,void 0!==n?n:null)})}function k(e,t){var n=0===e.assignedNodes().length;T(e,t,function(){n&&e.__removeChild(t)})}function P(e,t){T(e,t,function(){e.__removeChild(t)})}function A(e,t){T(e,t,function(){E(t)})}function W(e,t){t.assignedNodes().forEach(E),delete ue.get(e)[C(t)],ae.delete(t)}function D(e,t){T(e,t,function(){if(l(t))W(e,t);else{var n=h(t);if(n)for(var i=0;i<n.length;i++)W(e,n[i])}e.__removeChild(t)})}function H(e){if(c(e))return e;if(e.parentNode)return H(e.parentNode)}function B(e,t,n){var i=N(e),r=t.parentNode,o=H(e);return G||Array.isArray(e.childNodes)||_(e,"childNodes",I(e.childNodes)),o&&"slot"===N(t)&&L(o,t),r&&"host"===N(r)&&(G?re.set(t,null):_(t,"parentNode",null)),"node"===i?G?(re.set(t,e),e.__insertBefore(t,void 0!==n?n:null)):M(e,t,n):"slot"===i?j(e,t,n):"host"===i?x(e,t,n):"root"===i?S(e,t,n):void 0}function F(e){if(G&&"slot"===N(e)&&e.__childNodes.length!==e.childNodes.length){for(;e.hasChildNodes();)e.removeChild(e.firstChild);Y.call(e.__childNodes,function(t){return e.appendChild(t)})}}t="default"in t?t.default:t;var R=document.createElement("div"),q=u(Element.prototype,"innerHTML"),G=!!q,I=function(e){return Array.prototype.slice.call(e)},V="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}();var X=Array.prototype,Y=X.forEach,z="_shadow_root_",J=["childNodes","parentNode"],K=["textContent"],Q=["assignedSlot"],U=["textContent"],Z=[],$=[Node.ELEMENT_NODE,Node.TEXT_NODE],ee=new WeakMap,te=new WeakMap,ne=new WeakMap,ie=new WeakMap,re=new WeakMap,oe=new WeakMap,se=new WeakMap,ue=new WeakMap,ae=new WeakMap,de=new DOMParser,le={____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:t(function(){this.____slotChangeListeners&&this.dispatchEvent(new CustomEvent("slotchange",{bubbles:!1,cancelable:!1}))})},addEventListener:{value:function(e,t,n){return"slotchange"===e&&l(this)&&this.____slotChangeListeners++,this.__addEventListener(e,t,n)}},appendChild:{value:function(e){return B(this,e),e}},assignedSlot:{get:function(){var e=oe.get(this);if(!e)return null;var t=ae.get(e),n=se.get(t),i=te.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=ne.get(this);if(i)return i;var r=v([].slice.call(this.childNodes)),o=document.createElement(e.polyfillShadowRootTagName||z);return te.set(this,n),ne.set(this,o),se.set(o,this),ue.set(o,{}),G?ie.set(this,r):_(this,"childNodes",r),r.forEach(function(e){t.__removeChild(e),G?re.set(e,t):_(e,"parentNode",t)}),this.__appendChild(o)}},childElementCount:{get:function(){return this.children.length}},childNodes:{get:function(){if(G&&"node"===N(this))return this.__childNodes;var e=ie.get(this);return e||ie.set(this,e=v([])),e}},children:{get:function(){var e=[];return i(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(l(this)){var e=ee.get(this);return e||ee.set(this,e=[]),e}}},hasChildNodes:{value:function(){return this.childNodes.length>0}},innerHTML:{get:function(){var e="",t=function(e){return e.outerHTML},n={1:t,3:a,8:d};return i(this,function(i){var r=n[i.nodeType]||t;e+=r(i)}),e},set:function(e){for(var t=f(e);this.hasChildNodes();)this.removeChild(this.firstChild);var n=h(t);for(Y.call(n,function(e){return F(e)});t.hasChildNodes();){var i=t.firstChild;t.removeChild(i),this.appendChild(i)}}},insertBefore:{value:function(e,t){return B(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 i(this.parentNode,function(t,n,i){if(e===t)return i[n+1]||null})}},nextElementSibling:{get:function(){var e=this,t=void 0;return i(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=f(e);this.parentNode.replaceChild(t.firstChild,this)}else{if(!G)throw new Error("Failed to set the 'outerHTML' property on 'Element': This element has no parent node.");this.__outerHTML=e}}},parentElement:{get:function(){return m(this.parentNode,function(e){return 1===e.nodeType})}},parentNode:{get:function(){return re.get(this)||this.__parentNode||null}},previousSibling:{get:function(){var e=this;return i(this.parentNode,function(t,n,i){if(e===t)return i[n-1]||null})}},previousElementSibling:{get:function(){var e=this,t=void 0;return i(this.parentNode,function(n){return t&&e===n?t:void(1===n.nodeType&&(t=n))})}},removeChild:{value:function(e){var t=N(this);switch(t){case"node":if(G)return re.set(e,null),this.__removeChild(e);P(this,e);break;case"slot":k(this,e);break;case"host":A(this,e);break;case"root":D(this,e)}return e}},removeEventListener:{value:function(e,t,n){return"slotchange"===e&&this.____slotChangeListeners&&l(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"===te.get(this)?ne.get(this):null}},textContent:{get:function(){var e="";return i(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=Comment.prototype,t=HTMLElement.prototype,n=SVGElement.prototype,i=Text.prototype,r=document.createTextNode(""),o=document.createComment("");Object.keys(le).forEach(function(s){var a=le[s];if(a.configurable=!0,a.hasOwnProperty("value")&&(a.writable=!0),G||J.indexOf(s)===-1){var d=u(t,s),l=u(i,s),h=u(e,s),c=s in r&&K.indexOf(s)===-1||~Q.indexOf(s),f=s in o&&U.indexOf(s)===-1||~Z.indexOf(s),_="__"+s;Object.defineProperty(t,s,a),Object.defineProperty(n,s,a),d&&(Object.defineProperty(t,_,d),Object.defineProperty(n,_,d)),c&&Object.defineProperty(i,s,a),c&&l&&Object.defineProperty(i,_,l),f&&Object.defineProperty(e,s,a),f&&h&&Object.defineProperty(e,_,h)}})}(),e.default=V,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("debounce"),require("custom-event-polyfill")):"function"==typeof define&&define.amd?define(["exports","debounce","custom-event-polyfill"],t):t(e.skatejsNamedSlots=e.skatejsNamedSlots||{},e.debounce,e.customEventPolyfill)}(this,function(e,t,n){function r(e,t){if(e)for(var n=e.childNodes,r=n.length,o=0;o<r;o++){var i=t(n[o],o,n);if("undefined"!=typeof i)return i}}function o(e){for(var t=[],n=e.length-1;n>=0;n--)t.push(e[n]);return t}function i(e,t){if(e instanceof DocumentFragment)for(var n=e.childNodes,r=n.length,i=r-1;i>=0;i--){var s=o(e.childNodes)[i];t(s,i)}else t(e,0)}function s(e,t){for(var n=void 0;e&&!(n=Object.getOwnPropertyDescriptor(e,t));)e=Object.getPrototypeOf(e);return n}function a(e,t){e instanceof Node&&(e=Y);var n=s(e,t);if(n){var r=n.get,o=n.set,i={configurable:!0,enumerable:!0};if(r)return i.get=r,i.set=o,i;if("function"==typeof e[t])return i.value=e[t],i}var a=Object.getOwnPropertyDescriptor(e,t);if(a&&a.get)return a}function u(e){return e.textContent.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function l(e){return e.text||"<!--"+e.textContent+"-->"}function d(e){return"SLOT"===e.tagName}function c(e){var t=arguments.length<=1||void 0===arguments[1]?[]:arguments[1],n=e.childNodes;if(F)return[].concat(V(e.querySelectorAll("content")));if(!n||e.nodeType!==Node.ELEMENT_NODE)return t;for(var r=n.length,o=0;o<r;o++){var i=n[o];d(i)&&t.push(i),c(i,t)}return t}function h(e){return"_SHADOW_ROOT_"===e.tagName}function f(e){var t=document.createElement("div");if(I)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 p(e,t,n){Object.defineProperty(e,t,{configurable:!0,get:function(){return n}})}function v(e){return this[e]}function g(e){return e.item=v,e}function _(e){return!!ue.get(e)}function m(e){return _(e)?"host":d(e)?"slot":h(e)?"root":"node"}function N(e,t){for(;e&&e!==document;){if(t(e))return e;e=e.parentNode}}function y(e){return e.getAttribute&&e.getAttribute("name")||"default"}function b(e){return e.getAttribute&&e.getAttribute("slot")||"default"}function C(e,t,n){if(ie.indexOf(t.nodeType)!==-1){var r=e.assignedNodes(),o=0===r.length,i=r.indexOf(n);ce.set(t,e),o&&Z.call(e.childNodes,function(t){return e.__removeChild(t)}),i>-1?(e.__insertBefore(t,void 0!==n?n:null),r.splice(i,0,t)):(e.__appendChild(t),r.push(t)),e.____triggerSlotChangeEvent()}}function E(e){var t=e.assignedSlot;if(t){var n=t.assignedNodes(),r=n.indexOf(e);if(r>-1){var o=1===n.length;n.splice(r,1),ce.set(e,null),t.__removeChild(e),o&&Z.call(t.childNodes,function(e){return t.__appendChild(e)}),t.____triggerSlotChangeEvent()}}}function O(e,t){for(var n=e.childNodes,r=n.length,o=0;o<r;o++)if(n[o]===t)return o;return-1}function w(e,t,n,r){var o=O(e,n);i(t,function(t,n){r(t,n),I?de.set(t,e):p(t,"parentNode",e),o>-1?U.splice.call(e.childNodes,o+n,0,t):U.push.call(e.childNodes,t)})}function T(e,t,n){var r=O(e,t);r>-1&&(n(t,0),I?de.set(t,null):p(t,"parentNode",null),U.splice.call(e.childNodes,r,1))}function M(e,t,n){w(e,t,n,function(t){e.__insertBefore(t,void 0!==n?n:null)})}function L(e,t,n){w(e,t,n,function(t){var r=ue.get(e),o=fe.get(r),i=o[b(t)];i&&C(i,t,n)})}function S(e,t){var n=y(t);I||Array.isArray(t.childNodes)||p(t,"childNodes",z(t.childNodes)),fe.get(e)[n]=t,pe.has(t)||pe.set(t,e),r(he.get(e),function(e){e.assignedSlot||n!==b(e)||C(t,e)})}function A(e,t,n){i(t,function(t){if(d(t))S(e,t);else{var n=c(t);if(n)for(var r=n.length,o=0;o<r;o++)S(e,n[o])}}),M(e,t,n)}function j(e,t,n){var r=0===e.assignedNodes().length;w(e,t,n,function(t){r&&e.__insertBefore(t,void 0!==n?n:null)})}function x(e,t){var n=0===e.assignedNodes().length;T(e,t,function(){n&&e.__removeChild(t)})}function P(e,t){T(e,t,function(){e.__removeChild(t)})}function k(e,t){T(e,t,function(){E(t)})}function H(e,t){t.assignedNodes().forEach(E),delete fe.get(e)[y(t)],pe.delete(t)}function D(e,t){T(e,t,function(){if(d(t))H(e,t);else{var n=c(t);if(n)for(var r=0;r<n.length;r++)H(e,n[r])}e.__removeChild(t)})}function W(e){if(h(e))return e;if(e.parentNode)return W(e.parentNode)}function R(e,t,n){var r=m(e),o=t.parentNode,i=W(e);return I||Array.isArray(e.childNodes)||p(e,"childNodes",z(e.childNodes)),i&&"slot"===m(t)&&S(i,t),o&&"host"===m(o)&&(I?de.set(t,null):p(t,"parentNode",null)),"node"===r?I?(de.set(t,e),e.__insertBefore(t,void 0!==n?n:null)):M(e,t,n):"slot"===r?j(e,t,n):"host"===r?L(e,t,n):"root"===r?A(e,t,n):void 0}function q(e){if(I&&"slot"===m(e)&&e.__childNodes.length!==e.childNodes.length){for(;e.hasChildNodes();)e.removeChild(e.firstChild);Z.call(e.__childNodes,function(t){return e.appendChild(t)})}}t="default"in t?t.default:t;var B=document.createElement("div"),F=!!B.createShadowRoot,X=!!B.attachShadow,Y=document.createElement("div"),G=a(Element.prototype,"innerHTML"),I=!!G,V=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)},z=function(e){return Array.prototype.slice.call(e)},J="__shadowRoot",K=function(){function e(e){for(var t=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT),n=[];t.nextNode();){var r=t.currentNode;"SLOT"===r.tagName&&n.push(r)}n.forEach(function(e){var t=e.getAttribute("name"),n=document.createElement("slot");for(t&&n.setAttribute("name",t),e.parentNode.replaceChild(n,e);e.hasChildNodes();)n.appendChild(e.firstChild)})}var t=function(e){for(var t=e.getAttribute("name"),n=e;n;){var r=n[J];if(r&&r.contains(e))break;n=n.parentNode}if(!n)return[];for(var o=n.childNodes,i=o.length,s=[],a=0;a<i;a++){var u=o[a],l=u.getAttribute?u.getAttribute("slot"):null;t===l&&s.push(u)}return s},n=HTMLElement.prototype,r=n.getAttribute,o=n.setAttribute,i=Object.getOwnPropertyDescriptor(Element.prototype,"innerHTML"),s=Object.getOwnPropertyDescriptor(ShadowRoot.prototype,"innerHTML"),a=function(e){return"slot"===e?"content":e},u=document.createElement.bind(document),l=document.createElementNS.bind(document);document.createElement=function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];return u.apply(void 0,[a(e)].concat(n))},document.createElementNS=function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];return l.apply(void 0,[a(e)].concat(n))},Object.defineProperty(Element.prototype,"innerHTML",{configurable:!0,get:i.get,set:function(t){i.set.call(this,t),e(this)}}),Object.defineProperty(ShadowRoot.prototype,"innerHTML",{configurable:!0,get:s.get,set:function(t){s.set.call(this,t),e(this)}}),Object.defineProperty(Node.prototype,"assignedSlot",{get:function(){var e=this.parentNode;if(e){var t=e.shadowRoot;if(!t)return null;for(var n=t.querySelectorAll("content"),r=0;r<n.length;r++){var o=n[r];if(o.assignedNodes().indexOf(this)>-1)return o}}return null}}),HTMLElement.prototype.attachShadow=function(){var e=this,t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],n=t.mode;if("closed"!==n&&"open"!==n)throw new Error('You must specify { mode } as "open" or "closed" to attachShadow().');var r=this.createShadowRoot();"closed"===n&&Object.defineProperty(this,"shadowRoot",{configurable:!0,get:function(){return null}}),Object.defineProperty(r,"parentNode",{get:function(){return e}});var o=new MutationObserver(function(t){var n=e[J];t.forEach(function(e){var t=e.addedNodes,r=e.removedNodes,o={},i=function(e){return o[e.getAttribute&&e.getAttribute("slot")||"__default"]=!0};if(t)for(var s=t.length,a=0;a<s;a++)i(t[a]);if(r)for(var u=r.length,l=0;l<u;l++)i(r[l]);Object.keys(o).forEach(function(e){var t="__default"===e?n.querySelector("content:not([name])")||n.querySelector('content[name=""]'):n.querySelector('content[name="'+e+'"]');t&&t.dispatchEvent(new CustomEvent("slotchange",{bubbles:!1,cancelable:!1}))})})});return o.observe(this,{childList:!0}),this[J]=r},Object.defineProperty(HTMLContentElement.prototype,"name",{get:function(){return this.getAttribute("name")},set:function(e){return this.setAttribute("name",e)}}),HTMLContentElement.prototype.assignedNodes=function(){for(var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],n=e.deep,r=[],o=n?this.getDistributedNodes():t(this),i=0;i<o.length;i++){var s=o[i],a=s.nodeType;a!==Node.ELEMENT_NODE&&a!==Node.TEXT_NODE||r.push(s)}return r},HTMLContentElement.prototype.getAttribute=function(e){if("name"===e){var t=r.call(this,"select");return t?t.match(/\[slot=['"]?(.*?)['"]?\]/)[1]:null}return r.call(this,e)},HTMLContentElement.prototype.setAttribute=function(e,t){return"name"===e&&(e="select",t="[slot='"+t+"']"),o.call(this,e,t)}},Q="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)},has:function(e){var t=e[this.name];return!!t&&t[0]===e}},window.WeakMap=n}();var U=Array.prototype,Z=U.forEach,$="_shadow_root_",ee=["childNodes","parentNode"],te=["textContent"],ne=["assignedSlot"],re=["textContent"],oe=[],ie=[Node.ELEMENT_NODE,Node.TEXT_NODE],se=new WeakMap,ae=new WeakMap,ue=new WeakMap,le=new WeakMap,de=new WeakMap,ce=new WeakMap,he=new WeakMap,fe=new WeakMap,pe=new WeakMap,ve=new DOMParser,ge={____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:t(function(){this.____slotChangeListeners&&this.dispatchEvent(new CustomEvent("slotchange",{bubbles:!1,cancelable:!1}))})},addEventListener:{value:function(e,t,n){return"slotchange"===e&&d(this)&&this.____slotChangeListeners++,this.__addEventListener(e,t,n)}},appendChild:{value:function(e){return R(this,e),e}},assignedSlot:{get:function(){var e=ce.get(this);if(!e)return null;var t=pe.get(e),n=he.get(t),r=ae.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 o=g([].slice.call(this.childNodes)),i=document.createElement(e.polyfillShadowRootTagName||$);return ae.set(this,n),ue.set(this,i),he.set(i,this),fe.set(i,{}),I?le.set(this,o):p(this,"childNodes",o),o.forEach(function(e){t.__removeChild(e),I?de.set(e,t):p(e,"parentNode",t)}),this.__appendChild(i)}},childElementCount:{get:function(){return this.children.length}},childNodes:{get:function(){if(I&&"node"===m(this))return this.__childNodes;var e=le.get(this);return e||le.set(this,e=g([])),e}},children:{get:function(){var e=[];return r(this,function(t){1===t.nodeType&&e.push(t)}),g(e)}},firstChild:{get:function(){return this.childNodes[0]||null}},firstElementChild:{get:function(){return this.children[0]||null}},assignedNodes:{value:function(){if(d(this)){var e=se.get(this);return e||se.set(this,e=[]),e}}},hasChildNodes:{value:function(){return this.childNodes.length>0}},innerHTML:{get:function(){var e="",t=function(e){return e.outerHTML},n={1:t,3:u,8:l};return r(this,function(r){var o=n[r.nodeType]||t;e+=o(r)}),e},set:function(e){for(var t=f(e);this.hasChildNodes();)this.removeChild(this.firstChild);var n=c(t);for(Z.call(n,function(e){return q(e)});t.hasChildNodes();){var r=t.firstChild;t.removeChild(r),this.appendChild(r)}}},insertBefore:{value:function(e,t){return R(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 r(this.parentNode,function(t,n,r){if(e===t)return r[n+1]||null})}},nextElementSibling:{get:function(){var e=this,t=void 0;return r(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=f(e);this.parentNode.replaceChild(t.firstChild,this)}else{if(!I)throw new Error("Failed to set the 'outerHTML' property on 'Element': This element has no parent node.");this.__outerHTML=e}}},parentElement:{get:function(){return N(this.parentNode,function(e){return 1===e.nodeType})}},parentNode:{get:function(){return de.get(this)||this.__parentNode||null}},previousSibling:{get:function(){var e=this;return r(this.parentNode,function(t,n,r){if(e===t)return r[n-1]||null})}},previousElementSibling:{get:function(){var e=this,t=void 0;return r(this.parentNode,function(n){return t&&e===n?t:void(1===n.nodeType&&(t=n))})}},removeChild:{value:function(e){var t=m(this);switch(t){case"node":if(I)return de.set(e,null),this.__removeChild(e);P(this,e);break;case"slot":x(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&&d(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"===ae.get(this)?ue.get(this):null}},textContent:{get:function(){var e="";return r(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))}}};X||(F?K():!function(){var e=Comment.prototype,t=HTMLElement.prototype,n=SVGElement.prototype,r=Text.prototype,o=document.createTextNode(""),i=document.createComment("");Object.keys(ge).forEach(function(s){var u=ge[s];if(u.configurable=!0,u.hasOwnProperty("value")&&(u.writable=!0),I||ee.indexOf(s)===-1){var l=a(t,s),d=a(r,s),c=a(e,s),h=s in o&&te.indexOf(s)===-1||~ne.indexOf(s),f=s in i&&re.indexOf(s)===-1||~oe.indexOf(s),p="__"+s;Object.defineProperty(t,s,u),Object.defineProperty(n,s,u),l&&(Object.defineProperty(t,p,l),Object.defineProperty(n,p,l)),h&&Object.defineProperty(r,s,u),h&&d&&Object.defineProperty(r,p,d),f&&Object.defineProperty(e,s,u),f&&c&&Object.defineProperty(e,p,c)}})}()),e.default=Q,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=index.min.js.map |
@@ -51,3 +51,3 @@ { | ||
}, | ||
"version": "0.3.3" | ||
"version": "1.0.0" | ||
} |
# named-slots [![Build Status](https://travis-ci.org/skatejs/named-slots.svg?branch=master)](https://travis-ci.org/skatejs/named-slots) | ||
A polygap (partial polyfill) for the Shadow DOM Named Slot API. | ||
A polygap (partial polyfill) for the Shadow DOM Named Slot API. Also polyfills native v0 to behave like v1 with minimal overrides. | ||
@@ -12,2 +12,3 @@ | ||
- You don't want to wait for browser adoption | ||
- Uses native v0 where it can | ||
- You don't need allthethings in the [Shadow DOM spec](http://w3c.github.io/webcomponents/spec/shadow/) | ||
@@ -110,2 +111,8 @@ - You want interopaberability with React, jQuery and other libraries that don't care about your implementation details | ||
### Known Issues | ||
If possible, you should try and load this polyfill before anything else. If anything copies built-in prototypes before it has a chance to patch the built-in prototypes, you could get buggy behaviour. | ||
### Polyfilled | ||
@@ -217,2 +224,17 @@ | ||
### V0 overrides | ||
There are minimal overrides for the native Shadow DOM implementations so that they behave like v1. | ||
- `Element.innerHTML` | ||
- `HTMLContentElement.name` | ||
- `HTMLContentElement.assignedNodes()` | ||
- `HTMLContentElement.getAttribute()` | ||
- `HTMLContentElement.setAttribute()` | ||
- `HTMLElement.attachShadow()` | ||
- `Node.assignedSlot` | ||
- `ShadowRoot.innerHTML` | ||
## Performance | ||
@@ -219,0 +241,0 @@ |
import { eachChildNode, eachNodeOrFragmentNodes } from './util/each'; | ||
import { shadowDomV0, shadowDomV1 } from './util/support'; | ||
import canPatchNativeAccessors from './util/can-patch-native-accessors'; | ||
@@ -11,2 +12,3 @@ import getPropertyDescriptor from './util/get-property-descriptor'; | ||
import pseudoArrayToArray from './util/pseudo-array-to-array'; | ||
import v0 from './v0'; | ||
import version from './version'; | ||
@@ -141,22 +143,3 @@ import 'webcomponents.js/src/WeakMap/WeakMap.js'; | ||
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; | ||
} | ||
// only Text and Element nodes should be slotted | ||
// Only Text and Element nodes should be slotted. | ||
if (slottedNodeTypes.indexOf(node.nodeType) === -1) { | ||
@@ -576,3 +559,3 @@ return; | ||
let childNodes = nodeToChildNodesMap.get(this); | ||
if (!childNodes) { | ||
@@ -844,3 +827,7 @@ nodeToChildNodesMap.set(this, childNodes = makeLikeNodeList([])); | ||
if (!('attachShadow' in document.createElement('div'))) { | ||
if (shadowDomV1) { | ||
// then we should probably not be loading this | ||
} else if (shadowDomV0) { | ||
v0(); | ||
} else { | ||
const commProto = Comment.prototype; | ||
@@ -869,4 +856,10 @@ const elementProto = HTMLElement.prototype; | ||
const nativeCommDescriptor = getPropertyDescriptor(commProto, memberName); | ||
const shouldOverrideInTextNode = (memberName in textNode && doNotOverridePropertiesInTextNodes.indexOf(memberName) === -1) || ~defineInTextNodes.indexOf(memberName); | ||
const shouldOverrideInCommentNode = (memberName in commNode && doNotOverridePropertiesInCommNodes.indexOf(memberName) === -1) || ~defineInCommNodes.indexOf(memberName); | ||
const shouldOverrideInTextNode = ( | ||
memberName in textNode && | ||
doNotOverridePropertiesInTextNodes.indexOf(memberName) === -1 | ||
) || ~defineInTextNodes.indexOf(memberName); | ||
const shouldOverrideInCommentNode = ( | ||
memberName in commNode && | ||
doNotOverridePropertiesInCommNodes.indexOf(memberName) === -1 | ||
) || ~defineInCommNodes.indexOf(memberName); | ||
const nativeMemberName = `__${memberName}`; | ||
@@ -873,0 +866,0 @@ |
@@ -0,1 +1,2 @@ | ||
import { shadowDomV0 } from './support'; | ||
import isSlotNode from './is-slot-node'; | ||
@@ -6,2 +7,6 @@ | ||
if (shadowDomV0) { | ||
return [...root.querySelectorAll('content')]; | ||
} | ||
if (!childNodes || root.nodeType !== Node.ELEMENT_NODE) { | ||
@@ -8,0 +13,0 @@ return slots; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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 v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
499070
24
3863
2
248