Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

skatejs-named-slots

Package Overview
Dependencies
Maintainers
4
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

skatejs-named-slots - npm Package Compare versions

Comparing version 0.1.5 to 0.2.0

karma.conf.js

823

dist/index.js
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global.skatejsNamedSlots = factory());
}(this, function () {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory((global.skatejsNamedSlots = global.skatejsNamedSlots || {})));
}(this, function (exports) {
var babelHelpers = {};
babelHelpers.typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
return typeof obj;
} : function (obj) {
return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj;
};
babelHelpers.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);
}
};
babelHelpers;
function __commonjs(fn, module) { return module = { exports: {} }, fn(module, module.exports), module.exports; }

@@ -19,3 +39,3 @@

if (typeof ret !== 'undefined') {
return ret;
return ret; // eslint-disable-line consistent-return
}

@@ -37,6 +57,47 @@ }

// Any code referring to this is because it has to work around this bug in
// WebKit: https://bugs.webkit.org/show_bug.cgi?id=49739
var canPatchNativeAccessors = !!Object.getOwnPropertyDescriptor(window.Node.prototype, 'parentNode').get;
var div = document.createElement('div');
function getPrototype(obj, key) {
var descriptor = void 0;
while (obj && !(descriptor = Object.getOwnPropertyDescriptor(obj, key))) {
// eslint-disable-line no-cond-assign
obj = Object.getPrototypeOf(obj);
}
return descriptor;
}
function getPropertyDescriptor (obj, key) {
if (obj instanceof Node) {
obj = div;
}
var proto = getPrototype(obj, key);
if (proto) {
var getter = proto.get;
var setter = proto.set;
var _descriptor = {
configurable: true,
enumerable: true
};
if (getter) {
_descriptor.get = getter;
_descriptor.set = setter;
return _descriptor;
} else if (typeof obj[key] === 'function') {
_descriptor.value = obj[key];
return _descriptor;
}
}
var descriptor = Object.getOwnPropertyDescriptor(obj, key);
if (descriptor && descriptor.get) {
return descriptor;
}
}
var nativeParentNode = getPropertyDescriptor(Element.prototype, 'innerHTML');
var canPatchNativeAccessors = !!nativeParentNode;
var index$1 = __commonjs(function (module) {

@@ -109,39 +170,309 @@ module.exports = Date.now || now;

/**
* See https://w3c.github.io/DOM-Parsing/#serializing
* @param {TextNode}
* @returns {string}
*/
function getEscapedTextContent(textNode) {
return textNode.textContent.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
}
/**
* @returns {string}
* @param {commentNode}
*/
function getCommentNodeOuterHtml(commentNode) {
return commentNode.text || "<!--" + commentNode.textContent + "-->";
}
var version = '0.0.1';
var WeakMap = window.WeakMap || function () {
var index = 0;
function Wm() {
this.key = '____weak_map_' + index++;
var weakmap = __commonjs(function (module, exports) {
/* (The MIT License)
*
* Copyright (c) 2012 Brandon Benvie <http://bbenvie.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the 'Software'), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included with all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
// Original WeakMap implementation by Gozala @ https://gist.github.com/1269991
// Updated and bugfixed by Raynos @ https://gist.github.com/1638059
// Expanded by Benvie @ https://github.com/Benvie/harmony-collections
void function (global, undefined_, undefined) {
var getProps = Object.getOwnPropertyNames,
defProp = Object.defineProperty,
toSource = Function.prototype.toString,
create = Object.create,
hasOwn = Object.prototype.hasOwnProperty,
funcName = /^\n?function\s?(\w*)?_?\(/;
function define(object, key, value) {
if (typeof key === 'function') {
value = key;
key = nameOf(value).replace(/_$/, '');
}
return defProp(object, key, { configurable: true, writable: true, value: value });
}
Wm.prototype = {
delete: function _delete(obj) {
if (obj) {
delete obj[this.key];
}
function nameOf(func) {
return typeof func !== 'function' ? '' : 'name' in func ? func.name : toSource.call(func).match(funcName)[1];
}
// ############
// ### Data ###
// ############
var Data = function () {
var dataDesc = { value: { writable: true, value: undefined } },
datalock = 'return function(k){if(k===s)return l}',
uids = create(null),
createUID = function createUID() {
var key = Math.random().toString(36).slice(2);
return key in uids ? createUID() : uids[key] = key;
},
get: function get(obj) {
return obj ? obj[this.key] : null;
},
has: function has(obj) {
return obj ? typeof obj[this.key] !== 'undefined' : false;
},
set: function set(obj, val) {
if (obj) {
var key = this.key;
if (typeof obj[key] === 'undefined') {
Object.defineProperty(obj, key, {
configurable: true,
enumerable: false,
value: val
});
} else {
obj[key] = val;
}
globalID = createUID(),
storage = function storage(obj) {
if (hasOwn.call(obj, globalID)) return obj[globalID];
if (!Object.isExtensible(obj)) throw new TypeError("Object must be extensible");
var store = create(null);
defProp(obj, globalID, { value: store });
return store;
};
// common per-object storage area made visible by patching getOwnPropertyNames'
define(Object, function getOwnPropertyNames(obj) {
var props = getProps(obj);
if (hasOwn.call(obj, globalID)) props.splice(props.indexOf(globalID), 1);
return props;
});
function Data() {
var puid = createUID(),
secret = {};
this.unlock = function (obj) {
var store = storage(obj);
if (hasOwn.call(store, puid)) return store[puid](secret);
var data = create(null, dataDesc);
defProp(store, puid, {
value: new Function('s', 'l', datalock)(secret, data)
});
return data;
};
}
define(Data.prototype, function get(o) {
return this.unlock(o).value;
});
define(Data.prototype, function set(o, v) {
this.unlock(o).value = v;
});
return Data;
}();
var WM = function (data) {
var validate = function validate(key) {
if (key == null || (typeof key === 'undefined' ? 'undefined' : babelHelpers.typeof(key)) !== 'object' && typeof key !== 'function') throw new TypeError("Invalid WeakMap key");
};
var wrap = function wrap(collection, value) {
var store = data.unlock(collection);
if (store.value) throw new TypeError("Object is already a WeakMap");
store.value = value;
};
var unwrap = function unwrap(collection) {
var storage = data.unlock(collection).value;
if (!storage) throw new TypeError("WeakMap is not generic");
return storage;
};
var initialize = function initialize(weakmap, iterable) {
if (iterable !== null && (typeof iterable === 'undefined' ? 'undefined' : babelHelpers.typeof(iterable)) === 'object' && typeof iterable.forEach === 'function') {
iterable.forEach(function (item, i) {
if (item instanceof Array && item.length === 2) set.call(weakmap, iterable[i][0], iterable[i][1]);
});
}
};
function WeakMap(iterable) {
if (this === global || this == null || this === WeakMap.prototype) return new WeakMap(iterable);
wrap(this, new Data());
initialize(this, iterable);
}
function get(key) {
validate(key);
var value = unwrap(this).get(key);
return value === undefined_ ? undefined : value;
}
function set(key, value) {
validate(key);
// store a token for explicit undefined so that "has" works correctly
unwrap(this).set(key, value === undefined ? undefined_ : value);
}
function has(key) {
validate(key);
return unwrap(this).get(key) !== undefined;
}
function delete_(key) {
validate(key);
var data = unwrap(this),
had = data.get(key) !== undefined;
data.set(key, undefined);
return had;
}
function toString() {
unwrap(this);
return '[object WeakMap]';
}
try {
var src = ('return ' + delete_).replace('e_', '\\u0065'),
del = new Function('unwrap', 'validate', src)(unwrap, validate);
} catch (e) {
var del = delete_;
}
var src = ('' + Object).split('Object');
var stringifier = function toString() {
return src[0] + nameOf(this) + src[1];
};
define(stringifier, stringifier);
var prep = { __proto__: [] } instanceof Array ? function (f) {
f.__proto__ = stringifier;
} : function (f) {
define(f, stringifier);
};
prep(WeakMap);
[toString, get, set, has, del].forEach(function (method) {
define(WeakMap.prototype, method);
prep(method);
});
return WeakMap;
}(new Data());
var defaultCreator = Object.create ? function () {
return Object.create(null);
} : function () {
return {};
};
return Wm;
}();
function createStorage(creator) {
var weakmap = new WM();
creator || (creator = defaultCreator);
function storage(object, value) {
if (value || arguments.length === 2) {
weakmap.set(object, value);
} else {
value = weakmap.get(object);
if (value === undefined) {
value = creator(object);
weakmap.set(object, value);
}
}
return value;
}
return storage;
}
if (typeof module !== 'undefined') {
module.exports = WM;
} else if (typeof exports !== 'undefined') {
exports.WeakMap = WM;
} else if (!('WeakMap' in global)) {
global.WeakMap = WM;
}
WM.createStorage = createStorage;
if (global.WeakMap) global.WeakMap.createStorage = createStorage;
}((0, eval)('this'));
});
var WeakMap = (weakmap && typeof weakmap === 'object' && 'default' in weakmap ? weakmap['default'] : weakmap);
// Polyfill for creating CustomEvents on IE9/10/11
// code pulled from:
// https://github.com/d4tocchini/customevent-polyfill
// https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent#Polyfill
try {
var ce = new window.CustomEvent('test', {
bubbles: false,
cancelable: true,
detail: {
x: 'y'
}
});
ce.preventDefault();
if (ce.defaultPrevented !== true) {
// IE has problems with .preventDefault() on custom events
// http://stackoverflow.com/questions/23349191
throw new Error('Could not prevent default');
}
} catch (e) {
var CustomEvent$1 = function CustomEvent(event, params) {
var evt;
params = params || {
bubbles: false,
cancelable: false,
detail: undefined
};
evt = document.createEvent("CustomEvent");
evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
var origPrevent = evt.preventDefault;
evt.preventDefault = function () {
origPrevent.call(this);
try {
Object.defineProperty(this, 'defaultPrevented', {
get: function get() {
return true;
}
});
} catch (e) {
this.defaultPrevented = true;
}
};
return evt;
};
CustomEvent$1.prototype = window.Event.prototype;
window.CustomEvent = CustomEvent$1; // expose definition to window
}
var arrProto = Array.prototype;
var forEach = arrProto.forEach;
// We use a real DOM node for a shadow root. This is because the host node

@@ -151,2 +482,3 @@ // basically becomes a virtual entry point for your element leaving the shadow

// render to the browser.
var defaultShadowRootTagName = '_shadow_root_';

@@ -159,7 +491,19 @@ var defaultShadowRootTagNameUc = defaultShadowRootTagName.toUpperCase();

// original values at some point.
var polyfilAtRuntime = ['childNodes', 'parentNode'];
var polyfillAtRuntime = ['childNodes', 'parentNode'];
// These are the protos that we need to search for native descriptors on.
var protos = ['Node', 'Element', 'EventTarget'];
// Some properties that should not be overridden in the Text prototype.
var doNotOverridePropertiesInTextNodes = ['textContent'];
// Some new properties that should be defined in the Text prototype.
var defineInTextNodes = ['assignedSlot'];
// Some properties that should not be overridden in the Comment prototype.
var doNotOverridePropertiesInCommNodes = ['textContent'];
// Some new properties that should be defined in the Comment prototype.
var defineInCommNodes = [];
// Nodes that should be slotted
var slottedNodeTypes = [Node.ELEMENT_NODE, Node.TEXT_NODE];
// Private data stores.

@@ -174,42 +518,25 @@ var assignedToSlotMap = new WeakMap();

var rootToSlotMap = new WeakMap();
var slotToModeMap = new WeakMap();
var slotToRootMap = new WeakMap();
// * WebKit only *
//
// We require some way to parse HTML natively because we can't use the native
// accessors. To do this we parse as XML and conver each node in the tree to
// HTML nodes.
//
// This works because we polyfill at the HTMLElement level and XML nodes are
// considered Element nodes and we don't polyfill at that level.
// Unfortunately manual DOM parsing is because of WebKit.
var parser = new DOMParser();
function parse(html) {
var tree = document.createElement('div');
function convertXmlToHtml(node) {
var nodeType = node.nodeType;
if (nodeType === 1) {
var copy = document.createElement(node.tagName);
for (var a = 0; a < node.attributes.length; a++) {
var attr = node.attributes[a];
copy.setAttribute(attr.name, attr.value);
}
for (var a = 0; a < node.childNodes.length; a++) {
var childNode = node.childNodes[a];
copy.appendChild(convertXmlToHtml(childNode));
}
return copy;
// Everything not WebKit can do this easily.
if (canPatchNativeAccessors) {
tree.__innerHTML = html;
return tree;
}
return node;
}
function parse(html) {
var tree = document.createElement('div');
var parsed = parser.parseFromString(html, 'text/xml');
var parsed = parser.parseFromString('<div>' + html + '</div>', 'text/html').body.firstChild;
while (parsed.hasChildNodes()) {
var firstChild = parsed.firstChild;
parsed.removeChild(firstChild);
tree.appendChild(convertXmlToHtml(firstChild));
tree.appendChild(firstChild);
}
return tree;
// Need to import the node to initialise the custom elements from the parser.
return document.importNode(tree, true);
}

@@ -237,2 +564,14 @@

function isHostNode(node) {
return !!hostToRootMap.get(node);
}
function isSlotNode(node) {
return node.tagName === 'SLOT';
}
function isRootNode(node) {
return node.tagName === defaultShadowRootTagNameUc;
}
function getNodeType(node) {

@@ -254,14 +593,2 @@ if (isHostNode(node)) {

function isHostNode(node) {
return !!hostToRootMap.get(node);
}
function isSlotNode(node) {
return node.tagName === 'SLOT';
}
function isRootNode(node) {
return node.tagName === defaultShadowRootTagNameUc;
}
function findClosest(node, func) {

@@ -288,5 +615,2 @@ while (node) {

function slotNodeIntoSlot(slot, node, insertBefore) {
var assignedNodes = slot.getAssignedNodes();
var slotInsertBeforeIndex = assignedNodes.indexOf(insertBefore);
// Don't slot nodes that have content but are only whitespace. This is an

@@ -311,25 +635,26 @@ // anomaly that I don't think the spec deals with.

// only Text and Element nodes should be slotted
if (slottedNodeTypes.indexOf(node.nodeType) === -1) {
return;
}
var assignedNodes = slot.assignedNodes();
var shouldGoIntoContentMode = assignedNodes.length === 0;
var slotInsertBeforeIndex = assignedNodes.indexOf(insertBefore);
// Assign the slot to the node internally.
nodeToSlotMap.set(node, slot);
// If there's currently no assigned nodes, there will be, so remove all fallback content.
if (!assignedNodes.length) {
slotToModeMap.set(slot, false);
[].slice.call(slot.childNodes).forEach(function (fallbackNode) {
return slot.__removeChild(fallbackNode);
// Remove the fallback content and state if we're going into content mode.
if (shouldGoIntoContentMode) {
forEach.call(slot.childNodes, function (child) {
return slot.__removeChild(child);
});
}
var shouldAffectSlot = !slotToModeMap.get(slot);
if (slotInsertBeforeIndex > -1) {
if (shouldAffectSlot) {
slot.__insertBefore(node, insertBefore);
}
slot.__insertBefore(node, insertBefore !== undefined ? insertBefore : null);
assignedNodes.splice(slotInsertBeforeIndex, 0, node);
} else {
if (shouldAffectSlot) {
slot.__appendChild(node);
}
slot.__appendChild(node);
assignedNodes.push(node);

@@ -345,22 +670,18 @@ }

if (slot) {
var assignedNodes = slot.getAssignedNodes();
var assignedNodes = slot.assignedNodes();
var index = assignedNodes.indexOf(node);
if (index > -1) {
var shouldGoIntoDefaultMode = assignedNodes.length === 1;
assignedNodes.splice(index, 1);
nodeToSlotMap.set(node, null);
var shouldAffectSlot = !slotToModeMap.get(slot);
// Actually remove the child.
slot.__removeChild(node);
// We only update the actual DOM representation if we're displaying
// slotted nodes.
if (shouldAffectSlot) {
slot.__removeChild(node);
}
// If this was the last slotted node, then insert fallback content.
if (!assignedNodes.length) {
slotToModeMap.set(slot, true);
eachChildNode(slot, function (node) {
slot.__appendChild(node);
if (shouldGoIntoDefaultMode) {
forEach.call(slot.childNodes, function (child) {
return slot.__appendChild(child);
});

@@ -374,2 +695,3 @@ }

// Returns the index of the node in the host's childNodes.
function indexOfNode(host, node) {

@@ -400,5 +722,5 @@ var chs = host.childNodes;

if (index > -1) {
host.childNodes.splice(index + eachIndex, 0, eachNode);
arrProto.splice.call(host.childNodes, index + eachIndex, 0, eachNode);
} else {
host.childNodes.push(eachNode);
arrProto.push.call(host.childNodes, eachNode);
}

@@ -411,2 +733,3 @@ });

var index = indexOfNode(host, node);
if (index > -1) {

@@ -421,3 +744,3 @@ func(node, 0);

host.childNodes.splice(index, 1);
arrProto.splice.call(host.childNodes, index, 1);
}

@@ -428,3 +751,3 @@ }

registerNode(host, node, insertBefore, function (eachNode) {
host.__insertBefore(eachNode, insertBefore);
host.__insertBefore(eachNode, insertBefore !== undefined ? insertBefore : null);
});

@@ -444,8 +767,30 @@ }

function addSlotToRoot(root, slot) {
var slotName = getSlotNameFromSlot(slot);
// Ensure a slot node's childNodes are overridden at the earliest point
// possible for WebKit.
if (!canPatchNativeAccessors && !slot.childNodes.push) {
staticProp(slot, 'childNodes', []);
}
rootToSlotMap.get(root)[slotName] = slot;
if (!slotToRootMap.has(slot)) {
slotToRootMap.set(slot, root);
}
eachChildNode(rootToHostMap.get(root), function (eachNode) {
if (!eachNode.assignedSlot && slotName === getSlotNameFromNode(eachNode)) {
slotNodeIntoSlot(slot, eachNode);
}
});
}
function addNodeToRoot(root, node, insertBefore) {
eachNodeOrFragmentNodes(node, function (node) {
if (isSlotNode(node)) {
addSlotToRoot(root, node);
eachNodeOrFragmentNodes(node, function (child) {
if (isSlotNode(child)) {
addSlotToRoot(root, child);
} else {
var slotNodes = node.querySelectorAll && node.querySelectorAll('slot');
var slotNodes = child.querySelectorAll && child.querySelectorAll('slot');
if (slotNodes) {

@@ -462,9 +807,10 @@ var slotNodesLen = slotNodes.length;

function addSlotToRoot(root, node) {
var slotName = getSlotNameFromSlot(node);
slotToModeMap.set(node, true);
rootToSlotMap.get(root)[slotName] = node;
eachChildNode(rootToHostMap.get(root), function (eachNode) {
if (!eachNode.assignedSlot && slotName === getSlotNameFromNode(eachNode)) {
slotNodeIntoSlot(node, eachNode);
// Adds a node to a slot. In other words, adds default content to a slot. It
// ensures that if the slot doesn't have any assigned nodes yet, that the node
// is actually displayed, otherwise it's just registered as child content.
function addNodeToSlot(slot, node, insertBefore) {
var isInDefaultMode = slot.assignedNodes().length === 0;
registerNode(slot, node, insertBefore, function (eachNode) {
if (isInDefaultMode) {
slot.__insertBefore(eachNode, insertBefore !== undefined ? insertBefore : null);
}

@@ -474,2 +820,14 @@ });

// Removes a node from a slot (default content). It ensures that if the slot
// doesn't have any assigned nodes yet, that the node is actually removed,
// otherwise it's just unregistered.
function removeNodeFromSlot(slot, node) {
var isInDefaultMode = slot.assignedNodes().length === 0;
unregisterNode(slot, node, function () {
if (isInDefaultMode) {
slot.__removeChild(node);
}
});
}
function removeNodeFromNode(host, node) {

@@ -487,2 +845,8 @@ unregisterNode(host, node, function () {

function removeSlotFromRoot(root, node) {
node.assignedNodes().forEach(slotNodeFromSlot);
delete rootToSlotMap.get(root)[getSlotNameFromSlot(node)];
slotToRootMap.delete(node);
}
function removeNodeFromRoot(root, node) {

@@ -494,12 +858,23 @@ unregisterNode(root, node, function () {

var nodes = node.querySelectorAll && node.querySelectorAll('slot');
for (var a = 0; a < nodes.length; a++) {
removeSlotFromRoot(root, nodes[a]);
if (nodes) {
for (var a = 0; a < nodes.length; a++) {
removeSlotFromRoot(root, nodes[a]);
}
}
}
root.__removeChild(node);
});
}
function removeSlotFromRoot(root, node) {
node.getAssignedNodes().forEach(slotNodeFromSlot);
delete rootToSlotMap.get(root)[getSlotNameFromSlot(node)];
// TODO terribly inefficient
function getRootNode(host) {
if (isRootNode(host)) {
return host;
}
if (!host.parentNode) {
return;
}
return getRootNode(host.parentNode);
}

@@ -510,7 +885,13 @@

var parentNode = newNode.parentNode;
var rootNode = getRootNode(host);
// Ensure childNodes is patched so we can manually update it for WebKit.
if (!canPatchNativeAccessors && !host.childNodes.push) {
staticProp(host, 'childNodes', []);
staticProp(host, 'childNodes', [].concat(babelHelpers.toConsumableArray(host.childNodes)));
}
if (rootNode && getNodeType(newNode) === 'slot') {
addSlotToRoot(rootNode, newNode);
}
// If we append a child to a host, the host tells the shadow root to distribute

@@ -531,10 +912,11 @@ // it. If the root decides it doesn't need to be distributed, it is never

if (canPatchNativeAccessors) {
return host.__insertBefore(newNode, refNode);
} else {
return addNodeToNode(host, newNode, refNode);
nodeToParentNodeMap.set(newNode, host);
return host.__insertBefore(newNode, refNode !== undefined ? refNode : null);
}
return addNodeToNode(host, newNode, refNode);
}
if (nodeType === 'slot') {
return addNodeToNode(host, newNode, refNode);
return addNodeToSlot(host, newNode, refNode);
}

@@ -562,3 +944,3 @@

get: function get() {
return slotToModeMap.get(this);
return this.assignedNodes().length === 0;
}

@@ -579,3 +961,3 @@ },

____triggerSlotChangeEvent: {
value: debounce(function () {
value: debounce(function callback() {
if (this.____slotChangeListeners) {

@@ -604,3 +986,13 @@ this.dispatchEvent(new CustomEvent('slotchange', {

get: function get() {
return nodeToSlotMap.get(this) || null;
var slot = nodeToSlotMap.get(this);
if (!slot) {
return null;
}
var root = slotToRootMap.get(slot);
var host = rootToHostMap.get(root);
var mode = hostToModeMap.get(host);
return mode === 'open' ? slot : null;
}

@@ -638,8 +1030,17 @@ },

// Existing children should be removed from being displayed, but still
// appear to be child nodes. This is how light DOM works; they're still
// child nodes but not in the composed DOM yet as there won't be any
// slots for them to go into.
eachChildNode(this, function (node) {
return _this.__removeChild(node);
// Process light DOM.
lightNodes.forEach(function (node) {
// Existing children should be removed from being displayed, but still
// appear to be child nodes. This is how light DOM works; they're still
// child nodes but not in the composed DOM yet as there won't be any
// slots for them to go into.
_this.__removeChild(node);
// We must register the parentNode here as this has the potential to
// become out of sync if the node is moved before being slotted.
if (canPatchNativeAccessors) {
nodeToParentNodeMap.set(node, _this);
} else {
staticProp(node, 'parentNode', _this);
}
});

@@ -662,3 +1063,7 @@

var childNodes = nodeToChildNodesMap.get(this);
childNodes || nodeToChildNodesMap.set(this, childNodes = makeLikeNodeList([]));
if (!childNodes) {
nodeToChildNodesMap.set(this, childNodes = makeLikeNodeList([]));
}
return childNodes;

@@ -688,7 +1093,11 @@ }

},
getAssignedNodes: {
assignedNodes: {
value: function value() {
if (isSlotNode(this)) {
var assigned = assignedToSlotMap.get(this);
assigned || assignedToSlotMap.set(this, assigned = []);
if (!assigned) {
assignedToSlotMap.set(this, assigned = []);
}
return assigned;

@@ -706,4 +1115,15 @@ }

var innerHTML = '';
var getHtmlNodeOuterHtml = function getHtmlNodeOuterHtml(node) {
return node.outerHTML;
};
var getOuterHtmlByNodeType = {
1: getHtmlNodeOuterHtml,
3: getEscapedTextContent,
8: getCommentNodeOuterHtml
};
eachChildNode(this, function (node) {
innerHTML += node.nodeType === 1 ? node.outerHTML : node.textContent;
var getOuterHtml = getOuterHtmlByNodeType[node.nodeType] || getHtmlNodeOuterHtml;
innerHTML += getOuterHtml(node);
});

@@ -772,3 +1192,3 @@ return innerHTML;

var host = this;
var found = undefined;
var found = void 0;
return eachChildNode(this.parentNode, function (child) {

@@ -791,2 +1211,14 @@ if (found && child.nodeType === 1) {

return '<' + name + attributes + '>' + this.innerHTML + '</' + name + '>';
},
set: function set(outerHTML) {
if (this.parentNode) {
var parsed = parse(outerHTML);
this.parentNode.replaceChild(parsed.firstChild, this);
} else {
if (canPatchNativeAccessors) {
this.__outerHTML = outerHTML; // this will throw a native error;
} else {
throw new Error('Failed to set the \'outerHTML\' property on \'Element\': This element has no parent node.');
}
}
}

@@ -819,3 +1251,3 @@ },

var host = this;
var found = undefined;
var found = void 0;
return eachChildNode(this.parentNode, function (child) {

@@ -838,9 +1270,9 @@ if (found && host === child) {

return this.__removeChild(refNode);
} else {
return removeNodeFromNode(this, refNode);
}
return removeNodeFromNode(this, refNode);
}
if (nodeType === 'slot') {
return removeNodeFromNode(this, refNode);
return removeNodeFromSlot(this, refNode);
}

@@ -880,3 +1312,5 @@

eachChildNode(this, function (node) {
textContent += node.textContent;
if (node.nodeType !== Node.COMMENT_NODE) {
textContent += node.textContent;
}
});

@@ -889,2 +1323,5 @@ return textContent;

}
if (!textContent) {
return;
}
this.appendChild(document.createTextNode(textContent));

@@ -895,18 +1332,10 @@ }

function findDescriptorFor(name) {
for (var a = 0; a < protos.length; a++) {
var ctor = window[protos[a]];
if (!ctor) {
continue;
}
var proto = ctor.prototype;
if (proto.hasOwnProperty(name)) {
return Object.getOwnPropertyDescriptor(proto, name);
}
}
}
if (!('attachShadow' in document.createElement('div'))) {
(function () {
var elementProto = HTMLElement.prototype;
var textProto = Text.prototype;
var commProto = Comment.prototype;
var textNode = document.createTextNode('');
var commNode = document.createComment('');
Object.keys(members).forEach(function (memberName) {

@@ -918,9 +1347,37 @@ var memberProperty = members[memberName];

// 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 || polyfilAtRuntime.indexOf(memberName) === -1) {
var nativeDescriptor = findDescriptorFor(memberName);
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);
if (nativeDescriptor && nativeDescriptor.configurable) {
Object.defineProperty(elementProto, '__' + memberName, nativeDescriptor);
if (nativeDescriptor) {
Object.defineProperty(elementProto, nativeMemberName, nativeDescriptor);
}
if (shouldOverrideInTextNode) {
Object.defineProperty(textProto, memberName, memberProperty);
}
if (shouldOverrideInTextNode && nativeTextDescriptor) {
Object.defineProperty(textProto, nativeMemberName, nativeTextDescriptor);
}
if (shouldOverrideInCommentNode) {
Object.defineProperty(commProto, memberName, memberProperty);
}
if (shouldOverrideInCommentNode && nativeCommDescriptor) {
Object.defineProperty(commProto, nativeMemberName, nativeCommDescriptor);
}
}

@@ -931,22 +1388,14 @@ });

var api = Object.freeze({
default: version
});
var previousGlobal = window.skatejsNamedSlots;
version.noConflict = function noConflict() {
exports.noConflict = function () {
window.skatejsNamedSlots = previousGlobal;
return this;
};
window.skatejsNamedSlots = version;
for (var name in api) {
version[name] = api[name];
}
version.version = '0.1.5';
exports.version = 'undefined';
return version;
exports['default'] = version;
Object.defineProperty(exports, '__esModule', { value: true });
}));
//# sourceMappingURL=index.js.map

@@ -1,2 +0,2 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.skatejsNamedSlots=t()}(this,function(){function e(e,t){return t={exports:{}},e(t,t.exports),t.exports}function t(e,t){if(e)for(var n=e.childNodes,i=n.length,r=0;i>r;r++){var o=t(n[r],r,n);if("undefined"!=typeof o)return o}}function n(e,t){if(e instanceof DocumentFragment)for(var n=e.childNodes,i=n.length,r=0;i>r;r++)t(n[r],r);else t(e,0)}function i(e){var t=e.nodeType;if(1===t){for(var n=document.createElement(e.tagName),r=0;r<e.attributes.length;r++){var o=e.attributes[r];n.setAttribute(o.name,o.value)}for(var r=0;r<e.childNodes.length;r++){var s=e.childNodes[r];n.appendChild(i(s))}return n}return e}function r(e){for(var t=document.createElement("div"),n=V.parseFromString(e,"text/xml");n.hasChildNodes();){var r=n.firstChild;n.removeChild(r),t.appendChild(i(r))}return t}function o(e,t,n){Object.defineProperty(e,t,{configurable:!0,get:function(){return n}})}function s(e){return this[e]}function u(e){return e.item=s,e}function l(e){return a(e)?"host":d(e)?"slot":h(e)?"root":"node"}function a(e){return!!U.get(e)}function d(e){return"SLOT"===e.tagName}function h(e){return e.tagName===q}function f(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 _(e){return e.getAttribute&&e.getAttribute("slot")||"default"}function g(e,t,n){var i=e.getAssignedNodes(),r=i.indexOf(n);if(3!==t.nodeType||!t.textContent||0!==t.textContent.trim().length){G.set(t,e),i.length||(Q.set(e,!1),[].slice.call(e.childNodes).forEach(function(t){return e.__removeChild(t)}));var o=!Q.get(e);r>-1?(o&&e.__insertBefore(t,n),i.splice(r,0,t)):(o&&e.__appendChild(t),i.push(t)),e.____triggerSlotChangeEvent()}}function v(e){var n=e.assignedSlot;if(n){var i=n.getAssignedNodes(),r=i.indexOf(e);if(r>-1){i.splice(r,1),G.set(e,null);var o=!Q.get(n);o&&n.__removeChild(e),i.length||(Q.set(n,!0),t(n,function(e){n.__appendChild(e)})),n.____triggerSlotChangeEvent()}}}function p(e,t){for(var n=e.childNodes,i=n.length,r=0;i>r;r++)if(n[r]===t)return r;return-1}function m(e,t,i,r){var s=p(e,i);n(t,function(t,n){r(t,n),A?Y.set(t,e):o(t,"parentNode",e),s>-1?e.childNodes.splice(s+n,0,t):e.childNodes.push(t)})}function N(e,t,n){var i=p(e,t);i>-1&&(n(t,0),A?Y.set(t,null):o(t,"parentNode",null),e.childNodes.splice(i,1))}function C(e,t,n){m(e,t,n,function(t){e.__insertBefore(t,n)})}function y(e,t,n){m(e,t,n,function(t){var i=U.get(e),r=K.get(i),o=r[_(t)];o&&g(o,t,n)})}function w(e,t,i){n(t,function(t){if(d(t))b(e,t);else{var n=t.querySelectorAll&&t.querySelectorAll("slot");if(n)for(var i=n.length,r=0;i>r;r++)b(e,n[r])}}),C(e,t,i)}function b(e,n){var i=c(n);Q.set(n,!0),K.get(e)[i]=n,t(J.get(e),function(e){e.assignedSlot||i!==_(e)||g(n,e)})}function E(e,t){N(e,t,function(){e.__removeChild(t)})}function S(e,t){N(e,t,function(){v(t)})}function x(e,t){N(e,t,function(){if(d(t))L(e,t);else for(var n=t.querySelectorAll&&t.querySelectorAll("slot"),i=0;i<n.length;i++)L(e,n[i])})}function L(e,t){t.getAssignedNodes().forEach(v),delete K.get(e)[c(t)]}function T(e,t,n){var i=l(e),r=t.parentNode;return A||e.childNodes.push||o(e,"childNodes",[]),r&&"host"===l(r)&&(A?Y.set(t,null):o(t,"parentNode",null)),"node"===i?A?e.__insertBefore(t,n):C(e,t,n):"slot"===i?C(e,t,n):"host"===i?y(e,t,n):"root"===i?w(e,t,n):void 0}function j(e){for(var t=0;t<R.length;t++){var n=window[R[t]];if(n){var i=n.prototype;if(i.hasOwnProperty(e))return Object.getOwnPropertyDescriptor(i,e)}}}var A=!!Object.getOwnPropertyDescriptor(window.Node.prototype,"parentNode").get,O=e(function(e){function t(){return(new Date).getTime()}e.exports=Date.now||t}),k=O&&"object"==typeof O&&"default"in O?O["default"]:O,M=e(function(e){var t=k;e.exports=function(e,n,i){function r(){var d=t()-l;n>d&&d>0?o=setTimeout(r,n-d):(o=null,i||(a=e.apply(u,s),o||(u=s=null)))}var o,s,u,l,a;return null==n&&(n=100),function(){u=this,s=arguments,l=t();var d=i&&!o;return o||(o=setTimeout(r,n)),d&&(a=e.apply(u,s),u=s=null),a}}}),P=M&&"object"==typeof M&&"default"in M?M["default"]:M,D="0.0.1",B=window.WeakMap||function(){function e(){this.key="____weak_map_"+t++}var t=0;return e.prototype={"delete":function(e){e&&delete e[this.key]},get:function(e){return e?e[this.key]:null},has:function(e){return e?"undefined"!=typeof e[this.key]:!1},set:function(e,t){if(e){var n=this.key;"undefined"==typeof e[n]?Object.defineProperty(e,n,{configurable:!0,enumerable:!1,value:t}):e[n]=t}}},e}(),H="_shadow_root_",q=H.toUpperCase(),F=["childNodes","parentNode"],R=["Node","Element","EventTarget"],z=new B,I=new B,U=new B,W=new B,Y=new B,G=new B,J=new B,K=new B,Q=new B,V=new DOMParser,X={____assignedNodes:{get:function(){return this.______assignedNodes||(this.______assignedNodes=[])}},____isInFallbackMode:{get:function(){return Q.get(this)}},____slotChangeListeners:{get:function(){return"undefined"==typeof this.______slotChangeListeners&&(this.______slotChangeListeners=0),this.______slotChangeListeners},set:function(e){this.______slotChangeListeners=e}},____triggerSlotChangeEvent:{value:P(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 T(this,e)}},assignedSlot:{get:function(){return G.get(this)||null}},attachShadow:{value:function(e){var n=this,i=e&&e.mode;if("closed"!==i&&"open"!==i)throw new Error('You must specify { mode } as "open" or "closed" to attachShadow().');var r=U.get(this);if(r)return r;var s=u([].slice.call(this.childNodes)),l=document.createElement(e.polyfillShadowRootTagName||H);return I.set(this,i),U.set(this,l),J.set(l,this),K.set(l,{}),A?W.set(this,s):o(this,"childNodes",s),t(this,function(e){return n.__removeChild(e)}),this.__appendChild(l)}},childElementCount:{get:function(){return this.children.length}},childNodes:{get:function(){if(A&&"node"===l(this))return this.__childNodes;var e=W.get(this);return e||W.set(this,e=u([])),e}},children:{get:function(){var e=[];return t(this,function(t){1===t.nodeType&&e.push(t)}),u(e)}},firstChild:{get:function(){return this.childNodes[0]||null}},firstElementChild:{get:function(){return this.children[0]||null}},getAssignedNodes:{value:function(){if(d(this)){var e=z.get(this);return e||z.set(this,e=[]),e}}},hasChildNodes:{value:function(){return this.childNodes.length>0}},innerHTML:{get:function(){var e="";return t(this,function(t){e+=1===t.nodeType?t.outerHTML:t.textContent}),e},set:function(e){for(var t=r(e);this.hasChildNodes();)this.removeChild(this.firstChild);for(;t.hasChildNodes();){var n=t.firstChild;t.removeChild(n),this.appendChild(n)}}},insertBefore:{value:function(e,t){return T(this,e,t)}},lastChild:{get:function(){var e=this.childNodes;return e[e.length-1]||null}},lastElementChild:{get:function(){var e=this.children;return e[e.length-1]||null}},name:{get:function(){return this.getAttribute("name")},set:function(e){return this.setAttribute("name",e)}},nextSibling:{get:function(){var e=this;return t(this.parentNode,function(t,n,i){return e===t?i[n+1]||null:void 0})}},nextElementSibling:{get:function(){var e=this,n=void 0;return t(this.parentNode,function(t){return n&&1===t.nodeType?t:void(e===t&&(n=!0))})}},outerHTML:{get:function(){var e=this.tagName.toLowerCase(),t=Array.prototype.slice.call(this.attributes).map(function(e){return" "+e.name+(e.value?'="'+e.value+'"':"")}).join("");return"<"+e+t+">"+this.innerHTML+"</"+e+">"}},parentElement:{get:function(){return f(this.parentNode,function(e){return 1===e.nodeType})}},parentNode:{get:function(){return Y.get(this)||this.__parentNode||null}},previousSibling:{get:function(){var e=this;return t(this.parentNode,function(t,n,i){return e===t?i[n-1]||null:void 0})}},previousElementSibling:{get:function(){var e=this,n=void 0;return t(this.parentNode,function(t){return n&&e===t?n:void(1===t.nodeType&&(n=t))})}},removeChild:{value:function(e){var t=l(this);return"node"===t?A?this.__removeChild(e):E(this,e):"slot"===t?E(this,e):"host"===t?S(this,e):"root"===t?x(this,e):void 0}},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"===I.get(this)?U.get(this):null}},textContent:{get:function(){var e="";return t(this,function(t){e+=t.textContent}),e},set:function(e){for(;this.hasChildNodes();)this.removeChild(this.firstChild);this.appendChild(document.createTextNode(e))}}};"attachShadow"in document.createElement("div")||!function(){var e=HTMLElement.prototype;Object.keys(X).forEach(function(t){var n=X[t];if(n.configurable=!0,A||-1===F.indexOf(t)){var i=j(t);Object.defineProperty(e,t,n),i&&i.configurable&&Object.defineProperty(e,"__"+t,i)}})}();var Z=Object.freeze({"default":D}),$=window.skatejsNamedSlots;D.noConflict=function(){return window.skatejsNamedSlots=$,this},window.skatejsNamedSlots=D;for(var ee in Z)D[ee]=Z[ee];return D.version="0.1.5",D});
//# sourceMappingURL=index.min.js.map
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.skatejsNamedSlots=e.skatejsNamedSlots||{})}(this,function(e){function t(e,t){return t={exports:{}},e(t,t.exports),t.exports}function n(e,t){if(e)for(var n=e.childNodes,r=n.length,o=0;r>o;o++){var i=t(n[o],o,n);if("undefined"!=typeof i)return i}}function r(e,t){if(e instanceof DocumentFragment)for(var n=e.childNodes,r=n.length,o=0;r>o;o++)t(n[o],o);else t(e,0)}function o(e,t){for(var n=void 0;e&&!(n=Object.getOwnPropertyDescriptor(e,t));)e=Object.getPrototypeOf(e);return n}function i(e,t){e instanceof Node&&(e=W);var n=o(e,t);if(n){var r=n.get,i=n.set,u={configurable:!0,enumerable:!0};if(r)return u.get=r,u.set=i,u;if("function"==typeof e[t])return u.value=e[t],u}var s=Object.getOwnPropertyDescriptor(e,t);return s&&s.get?s:void 0}function u(e){return e.textContent.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function s(e){return e.text||"<!--"+e.textContent+"-->"}function a(e){var t=document.createElement("div");if(B)return t.__innerHTML=e,t;for(var n=ve.parseFromString("<div>"+e+"</div>","text/html").body.firstChild;n.hasChildNodes();){var r=n.firstChild;n.removeChild(r),t.appendChild(r)}return document.importNode(t,!0)}function l(e,t,n){Object.defineProperty(e,t,{configurable:!0,get:function(){return n}})}function c(e){return this[e]}function f(e){return e.item=c,e}function d(e){return!!ae.get(e)}function h(e){return"SLOT"===e.tagName}function p(e){return e.tagName===Z}function v(e){return d(e)?"host":h(e)?"slot":p(e)?"root":"node"}function _(e,t){for(;e&&e!==document;){if(t(e))return e;e=e.parentNode}}function g(e){return e.getAttribute&&e.getAttribute("name")||"default"}function y(e){return e.getAttribute&&e.getAttribute("slot")||"default"}function m(e,t,n){if((3!==t.nodeType||!t.textContent||0!==t.textContent.trim().length)&&-1!==ie.indexOf(t.nodeType)){var r=e.assignedNodes(),o=0===r.length,i=r.indexOf(n);fe.set(t,e),o&&Q.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 b(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),fe.set(e,null),t.__removeChild(e),o&&Q.call(t.childNodes,function(e){return t.__appendChild(e)}),t.____triggerSlotChangeEvent()}}}function N(e,t){for(var n=e.childNodes,r=n.length,o=0;r>o;o++)if(n[o]===t)return o;return-1}function C(e,t,n,o){var i=N(e,n);r(t,function(t,n){o(t,n),B?ce.set(t,e):l(t,"parentNode",e),i>-1?K.splice.call(e.childNodes,i+n,0,t):K.push.call(e.childNodes,t)})}function w(e,t,n){var r=N(e,t);r>-1&&(n(t,0),B?ce.set(t,null):l(t,"parentNode",null),K.splice.call(e.childNodes,r,1))}function E(e,t,n){C(e,t,n,function(t){e.__insertBefore(t,void 0!==n?n:null)})}function O(e,t,n){C(e,t,n,function(t){var r=ae.get(e),o=he.get(r),i=o[y(t)];i&&m(i,t,n)})}function j(e,t){var r=g(t);B||t.childNodes.push||l(t,"childNodes",[]),he.get(e)[r]=t,pe.has(t)||pe.set(t,e),n(de.get(e),function(e){e.assignedSlot||r!==y(e)||m(t,e)})}function x(e,t,n){r(t,function(t){if(h(t))j(e,t);else{var n=t.querySelectorAll&&t.querySelectorAll("slot");if(n)for(var r=n.length,o=0;r>o;o++)j(e,n[o])}}),E(e,t,n)}function T(e,t,n){var r=0===e.assignedNodes().length;C(e,t,n,function(t){r&&e.__insertBefore(t,void 0!==n?n:null)})}function S(e,t){var n=0===e.assignedNodes().length;w(e,t,function(){n&&e.__removeChild(t)})}function L(e,t){w(e,t,function(){e.__removeChild(t)})}function M(e,t){w(e,t,function(){b(t)})}function k(e,t){t.assignedNodes().forEach(b),delete he.get(e)[g(t)],pe["delete"](t)}function A(e,t){w(e,t,function(){if(h(t))k(e,t);else{var n=t.querySelectorAll&&t.querySelectorAll("slot");if(n)for(var r=0;r<n.length;r++)k(e,n[r])}e.__removeChild(t)})}function P(e){if(p(e))return e;if(e.parentNode)return P(e.parentNode)}function D(e,t,n){var r=v(e),o=t.parentNode,i=P(e);return B||e.childNodes.push||l(e,"childNodes",[].concat(H.toConsumableArray(e.childNodes))),i&&"slot"===v(t)&&j(i,t),o&&"host"===v(o)&&(B?ce.set(t,null):l(t,"parentNode",null)),"node"===r?B?(ce.set(t,e),e.__insertBefore(t,void 0!==n?n:null)):E(e,t,n):"slot"===r?T(e,t,n):"host"===r?O(e,t,n):"root"===r?x(e,t,n):void 0}var H={};H["typeof"]="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e},H.toConsumableArray=function(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t<e.length;t++)n[t]=e[t];return n}return Array.from(e)};var W=document.createElement("div"),F=i(Element.prototype,"innerHTML"),B=!!F,q=t(function(e){function t(){return(new Date).getTime()}e.exports=Date.now||t}),I=q&&"object"==typeof q&&"default"in q?q["default"]:q,R=t(function(e){var t=I;e.exports=function(e,n,r){function o(){var c=t()-a;n>c&&c>0?i=setTimeout(o,n-c):(i=null,r||(l=e.apply(s,u),i||(s=u=null)))}var i,u,s,a,l;return null==n&&(n=100),function(){s=this,u=arguments,a=t();var c=r&&!i;return i||(i=setTimeout(o,n)),c&&(l=e.apply(s,u),s=u=null),l}}}),U=R&&"object"==typeof R&&"default"in R?R["default"]:R,X="0.0.1",Y=t(function(e,t){void function(n,r,o){function i(e,t,n){return"function"==typeof t&&(n=t,t=u(n).replace(/_$/,"")),l(e,t,{configurable:!0,writable:!0,value:n})}function u(e){return"function"!=typeof e?"":"name"in e?e.name:c.call(e).match(h)[1]}function s(e){function t(t,r){return r||2===arguments.length?n.set(t,r):(r=n.get(t),r===o&&(r=e(t),n.set(t,r))),r}var n=new v;return e||(e=_),t}var a=Object.getOwnPropertyNames,l=Object.defineProperty,c=Function.prototype.toString,f=Object.create,d=Object.prototype.hasOwnProperty,h=/^\n?function\s?(\w*)?_?\(/,p=function(){function e(){var e=u(),r={};this.unlock=function(o){var i=c(o);if(d.call(i,e))return i[e](r);var u=f(null,t);return l(i,e,{value:new Function("s","l",n)(r,u)}),u}}var t={value:{writable:!0,value:o}},n="return function(k){if(k===s)return l}",r=f(null),u=function h(){var e=Math.random().toString(36).slice(2);return e in r?h():r[e]=e},s=u(),c=function(e){if(d.call(e,s))return e[s];if(!Object.isExtensible(e))throw new TypeError("Object must be extensible");var t=f(null);return l(e,s,{value:t}),t};return i(Object,function(e){var t=a(e);return d.call(e,s)&&t.splice(t.indexOf(s),1),t}),i(e.prototype,function(e){return this.unlock(e).value}),i(e.prototype,function(e,t){this.unlock(e).value=t}),e}(),v=function(e){function t(e){return this===n||null==this||this===t.prototype?new t(e):(h(this,new p),void _(this,e))}function s(e){d(e);var t=v(this).get(e);return t===r?o:t}function a(e,t){d(e),v(this).set(e,t===o?r:t)}function l(e){return d(e),v(this).get(e)!==o}function c(e){d(e);var t=v(this),n=t.get(e)!==o;return t.set(e,o),n}function f(){return v(this),"[object WeakMap]"}var d=function(e){if(null==e||"object"!==("undefined"==typeof e?"undefined":H["typeof"](e))&&"function"!=typeof e)throw new TypeError("Invalid WeakMap key")},h=function(t,n){var r=e.unlock(t);if(r.value)throw new TypeError("Object is already a WeakMap");r.value=n},v=function(t){var n=e.unlock(t).value;if(!n)throw new TypeError("WeakMap is not generic");return n},_=function(e,t){null!==t&&"object"===("undefined"==typeof t?"undefined":H["typeof"](t))&&"function"==typeof t.forEach&&t.forEach(function(n,r){n instanceof Array&&2===n.length&&a.call(e,t[r][0],t[r][1])})};try{var g=("return "+c).replace("e_","\\u0065"),y=new Function("unwrap","validate",g)(v,d)}catch(m){var y=c}var g=(""+Object).split("Object"),b=function(){return g[0]+u(this)+g[1]};i(b,b);var N={__proto__:[]}instanceof Array?function(e){e.__proto__=b}:function(e){i(e,b)};return N(t),[f,s,a,l,y].forEach(function(e){i(t.prototype,e),N(e)}),t}(new p),_=Object.create?function(){return Object.create(null)}:function(){return{}};"undefined"!=typeof e?e.exports=v:"undefined"!=typeof t?t.WeakMap=v:"WeakMap"in n||(n.WeakMap=v),v.createStorage=s,n.WeakMap&&(n.WeakMap.createStorage=s)}((0,eval)("this"))}),$=Y&&"object"==typeof Y&&"default"in Y?Y["default"]:Y;try{var z=new window.CustomEvent("test",{bubbles:!1,cancelable:!0,detail:{x:"y"}});if(z.preventDefault(),z.defaultPrevented!==!0)throw new Error("Could not prevent default")}catch(G){var J=function(e,t){var n;t=t||{bubbles:!1,cancelable:!1,detail:void 0},n=document.createEvent("CustomEvent"),n.initCustomEvent(e,t.bubbles,t.cancelable,t.detail);var r=n.preventDefault;return n.preventDefault=function(){r.call(this);try{Object.defineProperty(this,"defaultPrevented",{get:function(){return!0}})}catch(e){this.defaultPrevented=!0}},n};J.prototype=window.Event.prototype,window.CustomEvent=J}var K=Array.prototype,Q=K.forEach,V="_shadow_root_",Z=V.toUpperCase(),ee=["childNodes","parentNode"],te=["textContent"],ne=["assignedSlot"],re=["textContent"],oe=[],ie=[Node.ELEMENT_NODE,Node.TEXT_NODE],ue=new $,se=new $,ae=new $,le=new $,ce=new $,fe=new $,de=new $,he=new $,pe=new $,ve=new DOMParser,_e={____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:U(function(){this.____slotChangeListeners&&this.dispatchEvent(new CustomEvent("slotchange",{bubbles:!1,cancelable:!1}))})},addEventListener:{value:function(e,t,n){return"slotchange"===e&&h(this)&&this.____slotChangeListeners++,this.__addEventListener(e,t,n)}},appendChild:{value:function(e){return D(this,e)}},assignedSlot:{get:function(){var e=fe.get(this);if(!e)return null;var t=pe.get(e),n=de.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=ae.get(this);if(r)return r;var o=f([].slice.call(this.childNodes)),i=document.createElement(e.polyfillShadowRootTagName||V);return se.set(this,n),ae.set(this,i),de.set(i,this),he.set(i,{}),B?le.set(this,o):l(this,"childNodes",o),o.forEach(function(e){t.__removeChild(e),B?ce.set(e,t):l(e,"parentNode",t)}),this.__appendChild(i)}},childElementCount:{get:function(){return this.children.length}},childNodes:{get:function(){if(B&&"node"===v(this))return this.__childNodes;var e=le.get(this);return e||le.set(this,e=f([])),e}},children:{get:function(){var e=[];return n(this,function(t){1===t.nodeType&&e.push(t)}),f(e)}},firstChild:{get:function(){return this.childNodes[0]||null}},firstElementChild:{get:function(){return this.children[0]||null}},assignedNodes:{value:function(){if(h(this)){var e=ue.get(this);return e||ue.set(this,e=[]),e}}},hasChildNodes:{value:function(){return this.childNodes.length>0}},innerHTML:{get:function(){var e="",t=function(e){return e.outerHTML},r={1:t,3:u,8:s};return n(this,function(n){var o=r[n.nodeType]||t;e+=o(n)}),e},set:function(e){for(var t=a(e);this.hasChildNodes();)this.removeChild(this.firstChild);for(;t.hasChildNodes();){var n=t.firstChild;t.removeChild(n),this.appendChild(n)}}},insertBefore:{value:function(e,t){return D(this,e,t)}},lastChild:{get:function(){var e=this.childNodes;return e[e.length-1]||null}},lastElementChild:{get:function(){var e=this.children;return e[e.length-1]||null}},name:{get:function(){return this.getAttribute("name")},set:function(e){return this.setAttribute("name",e)}},nextSibling:{get:function(){var e=this;return n(this.parentNode,function(t,n,r){return e===t?r[n+1]||null:void 0})}},nextElementSibling:{get:function(){var e=this,t=void 0;return n(this.parentNode,function(n){return t&&1===n.nodeType?n:void(e===n&&(t=!0))})}},outerHTML:{get:function(){var e=this.tagName.toLowerCase(),t=Array.prototype.slice.call(this.attributes).map(function(e){return" "+e.name+(e.value?'="'+e.value+'"':"")}).join("");return"<"+e+t+">"+this.innerHTML+"</"+e+">"},set:function(e){if(this.parentNode){var t=a(e);this.parentNode.replaceChild(t.firstChild,this)}else{if(!B)throw new Error("Failed to set the 'outerHTML' property on 'Element': This element has no parent node.");this.__outerHTML=e}}},parentElement:{get:function(){return _(this.parentNode,function(e){return 1===e.nodeType})}},parentNode:{get:function(){return ce.get(this)||this.__parentNode||null}},previousSibling:{get:function(){var e=this;return n(this.parentNode,function(t,n,r){return e===t?r[n-1]||null:void 0})}},previousElementSibling:{get:function(){var e=this,t=void 0;return n(this.parentNode,function(n){return t&&e===n?t:void(1===n.nodeType&&(t=n))})}},removeChild:{value:function(e){var t=v(this);return"node"===t?B?this.__removeChild(e):L(this,e):"slot"===t?S(this,e):"host"===t?M(this,e):"root"===t?A(this,e):void 0}},removeEventListener:{value:function(e,t,n){return"slotchange"===e&&this.____slotChangeListeners&&h(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)?ae.get(this):null}},textContent:{get:function(){var e="";return n(this,function(t){t.nodeType!==Node.COMMENT_NODE&&(e+=t.textContent)}),e},set:function(e){for(;this.hasChildNodes();)this.removeChild(this.firstChild);e&&this.appendChild(document.createTextNode(e))}}};"attachShadow"in document.createElement("div")||!function(){var e=HTMLElement.prototype,t=Text.prototype,n=Comment.prototype,r=document.createTextNode(""),o=document.createComment("");Object.keys(_e).forEach(function(u){var s=_e[u];if(s.configurable=!0,s.hasOwnProperty("value")&&(s.writable=!0),B||-1===ee.indexOf(u)){var a=i(e,u),l=i(t,u),c=i(n,u),f=u in r&&-1===te.indexOf(u)||~ne.indexOf(u),d=u in o&&-1===re.indexOf(u)||~oe.indexOf(u),h="__"+u;Object.defineProperty(e,u,s),a&&Object.defineProperty(e,h,a),f&&Object.defineProperty(t,u,s),f&&l&&Object.defineProperty(t,h,l),d&&Object.defineProperty(n,u,s),d&&c&&Object.defineProperty(n,h,c)}})}();var ge=window.skatejsNamedSlots;e.noConflict=function(){return window.skatejsNamedSlots=ge,this},e.version="undefined",e["default"]=X,Object.defineProperty(e,"__esModule",{value:!0})});
//# sourceMappingURL=index.min.js.map
{
"name": "skatejs-named-slots",
"version": "0.1.5",
"build:global": "skatejsNamedSlots",
"description": "A polygap (partial polyfill) for the Shadow DOM Named Slot API.",
"main": "lib/index.js",
"main": "dist/index.js",
"jsnext:main": "src/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "gulp build"
"test": "karma start --single-run",
"test/watch": "karma start",
"test/perf": "karma start --single-run --perf",
"build": "rollup --config && rollup --config --min",
"lint": "eslint -c node_modules/skatejs-build/.eslintrc src",
"prerelease": "npm test && eslint -c node_modules/skatejs-build/.eslintrc src && npm run build",
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
},

@@ -29,10 +34,18 @@ "repository": {

"devDependencies": {
"eslint": "1.10.3",
"eslint": "2.11.0",
"eslint-plugin-react": "^3.16.1",
"gulp": "gulpjs/gulp#73eced0",
"skatejs-build": "skatejs/build#6c4bf30"
"skatejs-build": "1.1.0",
"semantic-release": "^4.3.5"
},
"dependencies": {
"debounce": "^1.0.0"
}
}
"custom-event-polyfill": "joscha/custom-event-polyfill#de24bd9",
"debounce": "^1.0.0",
"weakmap": "0.0.6"
},
"config": {
"commitizen": {
"path": "cz-conventional-changelog"
}
},
"version": "0.2.0"
}

@@ -1,3 +0,5 @@

# named-slots
# named-slots [![Build Status](https://travis-ci.org/skatejs/named-slots.svg?branch=master)](https://travis-ci.org/skatejs/named-slots)
[![Sauce Test Status](https://saucelabs.com/browser-matrix/skatejs-named-slots.svg)](https://saucelabs.com/u/skatejs-named-slots)
A polygap (partial polyfill) for the Shadow DOM Named Slot API.

@@ -136,3 +138,3 @@

- `Element.attachShadow()`
- `HTMLSlotElement.getAssignedNodes()` - Only available after being added to a shadow root.
- `HTMLSlotElement.assignedNodes()` - Only available after being added to a shadow root.
- `Node.appendChild()`

@@ -224,4 +226,4 @@ - `Node.hasChildNodes()`

2. `npm install`
3. `gulp perf`
3. `npm run test/perf`
For most purposes, the performance should be acceptable. That said, we're always looking at ways to imporove.
import { eachChildNode, eachNodeOrFragmentNodes } from './util/each';
import canPatchNativeAccessors from './util/can-patch-native-accessors';
import getPropertyDescriptor from './util/get-property-descriptor';
import debounce from 'debounce';
import getEscapedTextContent from './util/get-escaped-text-content';
import getCommentNodeOuterHtml from './util/get-comment-node-outer-html';
import version from './version';
import WeakMap from './util/weak-map';
import WeakMap from 'weakmap';
import 'custom-event-polyfill';
const arrProto = Array.prototype;
const { forEach } = arrProto;
// We use a real DOM node for a shadow root. This is because the host node

@@ -18,7 +25,19 @@ // basically becomes a virtual entry point for your element leaving the shadow

// original values at some point.
const polyfilAtRuntime = ['childNodes', 'parentNode'];
const polyfillAtRuntime = ['childNodes', 'parentNode'];
// These are the protos that we need to search for native descriptors on.
const protos = ['Node', 'Element', 'EventTarget'];
// Some properties that should not be overridden in the Text prototype.
const doNotOverridePropertiesInTextNodes = ['textContent'];
// Some new properties that should be defined in the Text prototype.
const defineInTextNodes = ['assignedSlot'];
// Some properties that should not be overridden in the Comment prototype.
const doNotOverridePropertiesInCommNodes = ['textContent'];
// Some new properties that should be defined in the Comment prototype.
const defineInCommNodes = [];
// Nodes that should be slotted
const slottedNodeTypes = [Node.ELEMENT_NODE, Node.TEXT_NODE];
// Private data stores.

@@ -33,49 +52,32 @@ const assignedToSlotMap = new WeakMap();

const rootToSlotMap = new WeakMap();
const slotToModeMap = new WeakMap();
const slotToRootMap = new WeakMap();
// * WebKit only *
//
// We require some way to parse HTML natively because we can't use the native
// accessors. To do this we parse as XML and conver each node in the tree to
// HTML nodes.
//
// This works because we polyfill at the HTMLElement level and XML nodes are
// considered Element nodes and we don't polyfill at that level.
// Unfortunately manual DOM parsing is because of WebKit.
const parser = new DOMParser();
function parse(html) {
const tree = document.createElement('div');
function convertXmlToHtml (node) {
const { nodeType } = node;
if (nodeType === 1) {
const copy = document.createElement(node.tagName);
for (let a = 0; a < node.attributes.length; a++) {
const attr = node.attributes[a];
copy.setAttribute(attr.name, attr.value);
}
for (let a = 0; a < node.childNodes.length; a++) {
const childNode = node.childNodes[a];
copy.appendChild(convertXmlToHtml(childNode));
}
return copy;
// Everything not WebKit can do this easily.
if (canPatchNativeAccessors) {
tree.__innerHTML = html;
return tree;
}
return node;
}
function parse (html) {
const tree = document.createElement('div');
const parsed = parser.parseFromString(html, 'text/xml');
const parsed = parser.parseFromString(`<div>${html}</div>`, 'text/html').body.firstChild;
while (parsed.hasChildNodes()) {
const firstChild = parsed.firstChild;
parsed.removeChild(firstChild);
tree.appendChild(convertXmlToHtml(firstChild));
tree.appendChild(firstChild);
}
return tree;
// Need to import the node to initialise the custom elements from the parser.
return document.importNode(tree, true);
}
function staticProp (obj, name, value) {
function staticProp(obj, name, value) {
Object.defineProperty(obj, name, {
configurable: true,
get () { return value; }
get() { return value; },
});

@@ -87,7 +89,7 @@ }

function arrayItem (idx) {
function arrayItem(idx) {
return this[idx];
}
function makeLikeNodeList (arr) {
function makeLikeNodeList(arr) {
arr.item = arrayItem;

@@ -97,3 +99,15 @@ return arr;

function getNodeType (node) {
function isHostNode(node) {
return !!hostToRootMap.get(node);
}
function isSlotNode(node) {
return node.tagName === 'SLOT';
}
function isRootNode(node) {
return node.tagName === defaultShadowRootTagNameUc;
}
function getNodeType(node) {
if (isHostNode(node)) {

@@ -114,15 +128,3 @@ return 'host';

function isHostNode (node) {
return !!hostToRootMap.get(node);
}
function isSlotNode (node) {
return node.tagName === 'SLOT';
}
function isRootNode (node) {
return node.tagName === defaultShadowRootTagNameUc;
}
function findClosest (node, func) {
function findClosest(node, func) {
while (node) {

@@ -139,14 +141,11 @@ if (node === document) {

function getSlotNameFromSlot (node) {
function getSlotNameFromSlot(node) {
return node.getAttribute && node.getAttribute('name') || 'default';
}
function getSlotNameFromNode (node) {
function getSlotNameFromNode(node) {
return node.getAttribute && node.getAttribute('slot') || 'default';
}
function slotNodeIntoSlot (slot, node, insertBefore) {
const assignedNodes = slot.getAssignedNodes();
const slotInsertBeforeIndex = assignedNodes.indexOf(insertBefore);
function slotNodeIntoSlot(slot, node, insertBefore) {
// Don't slot nodes that have content but are only whitespace. This is an

@@ -171,23 +170,24 @@ // anomaly that I don't think the spec deals with.

// only Text and Element nodes should be slotted
if (slottedNodeTypes.indexOf(node.nodeType) === -1) {
return;
}
const assignedNodes = slot.assignedNodes();
const shouldGoIntoContentMode = assignedNodes.length === 0;
const slotInsertBeforeIndex = assignedNodes.indexOf(insertBefore);
// Assign the slot to the node internally.
nodeToSlotMap.set(node, slot);
// If there's currently no assigned nodes, there will be, so remove all fallback content.
if (!assignedNodes.length) {
slotToModeMap.set(slot, false);
[].slice.call(slot.childNodes).forEach(fallbackNode => slot.__removeChild(fallbackNode));
// Remove the fallback content and state if we're going into content mode.
if (shouldGoIntoContentMode) {
forEach.call(slot.childNodes, child => slot.__removeChild(child));
}
const shouldAffectSlot = !slotToModeMap.get(slot);
if (slotInsertBeforeIndex > -1) {
if (shouldAffectSlot) {
slot.__insertBefore(node, insertBefore);
}
slot.__insertBefore(node, insertBefore !== undefined ? insertBefore : null);
assignedNodes.splice(slotInsertBeforeIndex, 0, node);
} else {
if (shouldAffectSlot) {
slot.__appendChild(node);
}
slot.__appendChild(node);
assignedNodes.push(node);

@@ -199,27 +199,21 @@ }

function slotNodeFromSlot (node) {
function slotNodeFromSlot(node) {
const slot = node.assignedSlot;
if (slot) {
const assignedNodes = slot.getAssignedNodes();
const assignedNodes = slot.assignedNodes();
const index = assignedNodes.indexOf(node);
if (index > -1) {
const shouldGoIntoDefaultMode = assignedNodes.length === 1;
assignedNodes.splice(index, 1);
nodeToSlotMap.set(node, null);
const shouldAffectSlot = !slotToModeMap.get(slot);
// Actually remove the child.
slot.__removeChild(node);
// We only update the actual DOM representation if we're displaying
// slotted nodes.
if (shouldAffectSlot) {
slot.__removeChild(node);
}
// If this was the last slotted node, then insert fallback content.
if (!assignedNodes.length) {
slotToModeMap.set(slot, true);
eachChildNode(slot, function (node) {
slot.__appendChild(node);
});
if (shouldGoIntoDefaultMode) {
forEach.call(slot.childNodes, child => slot.__appendChild(child));
}

@@ -232,3 +226,4 @@

function indexOfNode (host, node) {
// Returns the index of the node in the host's childNodes.
function indexOfNode(host, node) {
const chs = host.childNodes;

@@ -246,5 +241,5 @@ const chsLen = chs.length;

// information such as parentNode.
function registerNode (host, node, insertBefore, func) {
function registerNode(host, node, insertBefore, func) {
const index = indexOfNode(host, insertBefore);
eachNodeOrFragmentNodes(node, function (eachNode, eachIndex) {
eachNodeOrFragmentNodes(node, (eachNode, eachIndex) => {
func(eachNode, eachIndex);

@@ -259,5 +254,5 @@

if (index > -1) {
host.childNodes.splice(index + eachIndex, 0, eachNode);
arrProto.splice.call(host.childNodes, index + eachIndex, 0, eachNode);
} else {
host.childNodes.push(eachNode);
arrProto.push.call(host.childNodes, eachNode);
}

@@ -268,4 +263,5 @@ });

// Cleans up registerNode().
function unregisterNode (host, node, func) {
function unregisterNode(host, node, func) {
const index = indexOfNode(host, node);
if (index > -1) {

@@ -280,14 +276,14 @@ func(node, 0);

host.childNodes.splice(index, 1);
arrProto.splice.call(host.childNodes, index, 1);
}
}
function addNodeToNode (host, node, insertBefore) {
registerNode(host, node, insertBefore, function (eachNode) {
host.__insertBefore(eachNode, insertBefore);
function addNodeToNode(host, node, insertBefore) {
registerNode(host, node, insertBefore, eachNode => {
host.__insertBefore(eachNode, insertBefore !== undefined ? insertBefore : null);
});
}
function addNodeToHost (host, node, insertBefore) {
registerNode(host, node, insertBefore, function (eachNode) {
function addNodeToHost(host, node, insertBefore) {
registerNode(host, node, insertBefore, eachNode => {
const rootNode = hostToRootMap.get(host);

@@ -302,8 +298,30 @@ const slotNodes = rootToSlotMap.get(rootNode);

function addNodeToRoot (root, node, insertBefore) {
eachNodeOrFragmentNodes(node, function (node) {
if (isSlotNode(node)) {
addSlotToRoot(root, node);
function addSlotToRoot(root, slot) {
const slotName = getSlotNameFromSlot(slot);
// Ensure a slot node's childNodes are overridden at the earliest point
// possible for WebKit.
if (!canPatchNativeAccessors && !slot.childNodes.push) {
staticProp(slot, 'childNodes', []);
}
rootToSlotMap.get(root)[slotName] = slot;
if (!slotToRootMap.has(slot)) {
slotToRootMap.set(slot, root);
}
eachChildNode(rootToHostMap.get(root), eachNode => {
if (!eachNode.assignedSlot && slotName === getSlotNameFromNode(eachNode)) {
slotNodeIntoSlot(slot, eachNode);
}
});
}
function addNodeToRoot(root, node, insertBefore) {
eachNodeOrFragmentNodes(node, child => {
if (isSlotNode(child)) {
addSlotToRoot(root, child);
} else {
const slotNodes = node.querySelectorAll && node.querySelectorAll('slot');
const slotNodes = child.querySelectorAll && child.querySelectorAll('slot');
if (slotNodes) {

@@ -320,9 +338,10 @@ const slotNodesLen = slotNodes.length;

function addSlotToRoot (root, node) {
const slotName = getSlotNameFromSlot(node);
slotToModeMap.set(node, true);
rootToSlotMap.get(root)[slotName] = node;
eachChildNode(rootToHostMap.get(root), function (eachNode) {
if (!eachNode.assignedSlot && slotName === getSlotNameFromNode(eachNode)) {
slotNodeIntoSlot(node, eachNode);
// Adds a node to a slot. In other words, adds default content to a slot. It
// ensures that if the slot doesn't have any assigned nodes yet, that the node
// is actually displayed, otherwise it's just registered as child content.
function addNodeToSlot(slot, node, insertBefore) {
const isInDefaultMode = slot.assignedNodes().length === 0;
registerNode(slot, node, insertBefore, eachNode => {
if (isInDefaultMode) {
slot.__insertBefore(eachNode, insertBefore !== undefined ? insertBefore : null);
}

@@ -332,4 +351,16 @@ });

function removeNodeFromNode (host, node) {
unregisterNode(host, node, function () {
// Removes a node from a slot (default content). It ensures that if the slot
// doesn't have any assigned nodes yet, that the node is actually removed,
// otherwise it's just unregistered.
function removeNodeFromSlot(slot, node) {
const isInDefaultMode = slot.assignedNodes().length === 0;
unregisterNode(slot, node, () => {
if (isInDefaultMode) {
slot.__removeChild(node);
}
});
}
function removeNodeFromNode(host, node) {
unregisterNode(host, node, () => {
host.__removeChild(node);

@@ -339,4 +370,4 @@ });

function removeNodeFromHost (host, node) {
unregisterNode(host, node, function () {
function removeNodeFromHost(host, node) {
unregisterNode(host, node, () => {
slotNodeFromSlot(node);

@@ -346,4 +377,10 @@ });

function removeNodeFromRoot (root, node) {
unregisterNode(root, node, function () {
function removeSlotFromRoot(root, node) {
node.assignedNodes().forEach(slotNodeFromSlot);
delete rootToSlotMap.get(root)[getSlotNameFromSlot(node)];
slotToRootMap.delete(node);
}
function removeNodeFromRoot(root, node) {
unregisterNode(root, node, () => {
if (isSlotNode(node)) {

@@ -353,22 +390,39 @@ removeSlotFromRoot(root, node);

const nodes = node.querySelectorAll && node.querySelectorAll('slot');
for (let a = 0; a < nodes.length; a++) {
removeSlotFromRoot(root, nodes[a]);
if (nodes) {
for (let a = 0; a < nodes.length; a++) {
removeSlotFromRoot(root, nodes[a]);
}
}
}
root.__removeChild(node);
});
}
function removeSlotFromRoot (root, node) {
node.getAssignedNodes().forEach(slotNodeFromSlot);
delete rootToSlotMap.get(root)[getSlotNameFromSlot(node)];
// TODO terribly inefficient
function getRootNode(host) {
if (isRootNode(host)) {
return host;
}
if (!host.parentNode) {
return;
}
return getRootNode(host.parentNode);
}
function appendChildOrInsertBefore (host, newNode, refNode) {
function appendChildOrInsertBefore(host, newNode, refNode) {
const nodeType = getNodeType(host);
const parentNode = newNode.parentNode;
const rootNode = getRootNode(host);
// Ensure childNodes is patched so we can manually update it for WebKit.
if (!canPatchNativeAccessors && !host.childNodes.push) {
staticProp(host, 'childNodes', []);
staticProp(host, 'childNodes', [...host.childNodes]);
}
if (rootNode && getNodeType(newNode) === 'slot') {
addSlotToRoot(rootNode, newNode);
}
// If we append a child to a host, the host tells the shadow root to distribute

@@ -389,10 +443,11 @@ // it. If the root decides it doesn't need to be distributed, it is never

if (canPatchNativeAccessors) {
return host.__insertBefore(newNode, refNode);
} else {
return addNodeToNode(host, newNode, refNode);
nodeToParentNodeMap.set(newNode, host);
return host.__insertBefore(newNode, refNode !== undefined ? refNode : null);
}
return addNodeToNode(host, newNode, refNode);
}
if (nodeType === 'slot') {
return addNodeToNode(host, newNode, refNode);
return addNodeToSlot(host, newNode, refNode);
}

@@ -412,5 +467,5 @@

____assignedNodes: {
get () {
get() {
return this.______assignedNodes || (this.______assignedNodes = []);
}
},
},

@@ -420,9 +475,9 @@

____isInFallbackMode: {
get () {
return slotToModeMap.get(this);
}
get() {
return this.assignedNodes().length === 0;
},
},
____slotChangeListeners: {
get () {
get() {
if (typeof this.______slotChangeListeners === 'undefined') {

@@ -433,18 +488,18 @@ this.______slotChangeListeners = 0;

},
set (value) {
set(value) {
this.______slotChangeListeners = value;
}
},
},
____triggerSlotChangeEvent: {
value: debounce(function () {
value: debounce(function callback() {
if (this.____slotChangeListeners) {
this.dispatchEvent(new CustomEvent('slotchange', {
bubbles: false,
cancelable: false
cancelable: false,
}));
}
})
}),
},
addEventListener: {
value (name, func, opts) {
value(name, func, opts) {
if (name === 'slotchange' && isSlotNode(this)) {

@@ -454,16 +509,26 @@ this.____slotChangeListeners++;

return this.__addEventListener(name, func, opts);
}
},
},
appendChild: {
value (newNode) {
value(newNode) {
return appendChildOrInsertBefore(this, newNode);
}
},
},
assignedSlot: {
get () {
return nodeToSlotMap.get(this) || null;
}
get() {
const slot = nodeToSlotMap.get(this);
if (!slot) {
return null;
}
const root = slotToRootMap.get(slot);
const host = rootToHostMap.get(root);
const mode = hostToModeMap.get(host);
return mode === 'open' ? slot : null;
},
},
attachShadow: {
value (opts) {
value(opts) {
const mode = opts && opts.mode;

@@ -495,19 +560,30 @@ if (mode !== 'closed' && mode !== 'open') {

// Existing children should be removed from being displayed, but still
// appear to be child nodes. This is how light DOM works; they're still
// child nodes but not in the composed DOM yet as there won't be any
// slots for them to go into.
eachChildNode(this, node => this.__removeChild(node));
// Process light DOM.
lightNodes.forEach(node => {
// Existing children should be removed from being displayed, but still
// appear to be child nodes. This is how light DOM works; they're still
// child nodes but not in the composed DOM yet as there won't be any
// slots for them to go into.
this.__removeChild(node);
// We must register the parentNode here as this has the potential to
// become out of sync if the node is moved before being slotted.
if (canPatchNativeAccessors) {
nodeToParentNodeMap.set(node, this);
} else {
staticProp(node, 'parentNode', this);
}
});
// The shadow root is actually the only child of the host.
return this.__appendChild(shadowRoot);
}
},
},
childElementCount: {
get () {
get() {
return this.children.length;
}
},
},
childNodes: {
get () {
get() {
if (canPatchNativeAccessors && getNodeType(this) === 'node') {

@@ -517,10 +593,14 @@ return this.__childNodes;

let childNodes = nodeToChildNodesMap.get(this);
childNodes || nodeToChildNodesMap.set(this, childNodes = makeLikeNodeList([]));
if (!childNodes) {
nodeToChildNodesMap.set(this, childNodes = makeLikeNodeList([]));
}
return childNodes;
}
},
},
children: {
get () {
get() {
const chs = [];
eachChildNode(this, function (node) {
eachChildNode(this, node => {
if (node.nodeType === 1) {

@@ -531,37 +611,50 @@ chs.push(node);

return makeLikeNodeList(chs);
}
},
},
firstChild: {
get () {
get() {
return this.childNodes[0] || null;
}
},
},
firstElementChild: {
get () {
get() {
return this.children[0] || null;
}
},
},
getAssignedNodes: {
value () {
assignedNodes: {
value() {
if (isSlotNode(this)) {
let assigned = assignedToSlotMap.get(this);
assigned || assignedToSlotMap.set(this, assigned = []);
if (!assigned) {
assignedToSlotMap.set(this, assigned = []);
}
return assigned;
}
}
},
},
hasChildNodes: {
value () {
value() {
return this.childNodes.length > 0;
}
},
},
innerHTML: {
get () {
get() {
let innerHTML = '';
eachChildNode(this, function (node) {
innerHTML += node.nodeType === 1 ? node.outerHTML : node.textContent;
const getHtmlNodeOuterHtml = (node) => node.outerHTML;
const getOuterHtmlByNodeType = {
1: getHtmlNodeOuterHtml,
3: getEscapedTextContent,
8: getCommentNodeOuterHtml,
};
eachChildNode(this, node => {
const getOuterHtml = getOuterHtmlByNodeType[node.nodeType] || getHtmlNodeOuterHtml;
innerHTML += getOuterHtml(node);
});
return innerHTML;
},
set (innerHTML) {
set(innerHTML) {
const parsed = parse(innerHTML);

@@ -586,33 +679,33 @@

}
}
},
},
insertBefore: {
value (newNode, refNode) {
value(newNode, refNode) {
return appendChildOrInsertBefore(this, newNode, refNode);
}
},
},
lastChild: {
get () {
get() {
const ch = this.childNodes;
return ch[ch.length - 1] || null;
}
},
},
lastElementChild: {
get () {
get() {
const ch = this.children;
return ch[ch.length - 1] || null;
}
},
},
name: {
get () {
get() {
return this.getAttribute('name');
},
set (name) {
set(name) {
return this.setAttribute('name', name);
}
},
},
nextSibling: {
get () {
get() {
const host = this;
return eachChildNode(this.parentNode, function (child, index, nodes) {
return eachChildNode(this.parentNode, (child, index, nodes) => {
if (host === child) {

@@ -622,9 +715,9 @@ return nodes[index + 1] || null;

});
}
},
},
nextElementSibling: {
get () {
get() {
const host = this;
let found;
return eachChildNode(this.parentNode, function (child) {
return eachChildNode(this.parentNode, child => {
if (found && child.nodeType === 1) {

@@ -637,29 +730,40 @@ return child;

});
}
},
},
outerHTML: {
get () {
get() {
const name = this.tagName.toLowerCase();
const attributes = Array.prototype.slice.call(this.attributes).map(function (attr) {
return ` ${attr.name}${attr.value ? `="${attr.value}"` : ''}`;
}).join('');
const attributes = Array.prototype.slice.call(this.attributes).map((attr) =>
(` ${attr.name}${attr.value ? `="${attr.value}"` : ''}`)
).join('');
return `<${name}${attributes}>${this.innerHTML}</${name}>`;
}
},
set(outerHTML) {
if (this.parentNode) {
const parsed = parse(outerHTML);
this.parentNode.replaceChild(parsed.firstChild, this);
} else {
if (canPatchNativeAccessors) {
this.__outerHTML = outerHTML; // this will throw a native error;
} else {
throw new Error('Failed to set the \'outerHTML\' property on \'Element\': This element has no parent node.');
}
}
},
},
parentElement: {
get () {
return findClosest(this.parentNode, function (node) {
return node.nodeType === 1;
});
}
get() {
return findClosest(this.parentNode, (node) => node.nodeType === 1);
},
},
parentNode: {
get () {
get() {
return nodeToParentNodeMap.get(this) || this.__parentNode || null;
}
},
},
previousSibling: {
get () {
get() {
const host = this;
return eachChildNode(this.parentNode, function (child, index, nodes) {
return eachChildNode(this.parentNode, (child, index, nodes) => {
if (host === child) {

@@ -669,9 +773,9 @@ return nodes[index - 1] || null;

});
}
},
},
previousElementSibling: {
get () {
get() {
const host = this;
let found;
return eachChildNode(this.parentNode, function (child) {
return eachChildNode(this.parentNode, child => {
if (found && host === child) {

@@ -684,6 +788,6 @@ return found;

});
}
},
},
removeChild: {
value (refNode) {
value(refNode) {
const nodeType = getNodeType(this);

@@ -694,9 +798,9 @@

return this.__removeChild(refNode);
} else {
return removeNodeFromNode(this, refNode);
}
return removeNodeFromNode(this, refNode);
}
if (nodeType === 'slot') {
return removeNodeFromNode(this, refNode);
return removeNodeFromSlot(this, refNode);
}

@@ -711,6 +815,6 @@

}
}
},
},
removeEventListener: {
value (name, func, opts) {
value(name, func, opts) {
if (name === 'slotchange' && this.____slotChangeListeners && isSlotNode(this)) {

@@ -720,48 +824,45 @@ this.____slotChangeListeners--;

return this.__removeEventListener(name, func, opts);
}
},
},
replaceChild: {
value (newNode, refNode) {
value(newNode, refNode) {
this.insertBefore(newNode, refNode);
return this.removeChild(refNode);
}
},
},
shadowRoot: {
get () {
get() {
return hostToModeMap.get(this) === 'open' ? hostToRootMap.get(this) : null;
}
},
},
textContent: {
get () {
get() {
let textContent = '';
eachChildNode(this, function (node) {
textContent += node.textContent;
eachChildNode(this, node => {
if (node.nodeType !== Node.COMMENT_NODE) {
textContent += node.textContent;
}
});
return textContent;
},
set (textContent) {
set(textContent) {
while (this.hasChildNodes()) {
this.removeChild(this.firstChild);
}
if (!textContent) {
return;
}
this.appendChild(document.createTextNode(textContent));
}
}
},
},
};
function findDescriptorFor (name) {
for (let a = 0; a < protos.length; a++) {
const ctor = window[protos[a]];
if (!ctor) {
continue;
}
const proto = ctor.prototype;
if (proto.hasOwnProperty(name)) {
return Object.getOwnPropertyDescriptor(proto, name);
}
}
}
if (!('attachShadow' in document.createElement('div'))) {
const elementProto = HTMLElement.prototype;
Object.keys(members).forEach(function (memberName) {
const textProto = Text.prototype;
const commProto = Comment.prototype;
const textNode = document.createTextNode('');
const commNode = document.createComment('');
Object.keys(members).forEach(memberName => {
const memberProperty = members[memberName];

@@ -772,9 +873,37 @@

// 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 || polyfilAtRuntime.indexOf(memberName) === -1) {
const nativeDescriptor = findDescriptorFor(memberName);
if (canPatchNativeAccessors || polyfillAtRuntime.indexOf(memberName) === -1) {
const nativeDescriptor = getPropertyDescriptor(elementProto, memberName);
const nativeTextDescriptor = getPropertyDescriptor(textProto, memberName);
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 nativeMemberName = `__${memberName}`;
Object.defineProperty(elementProto, memberName, memberProperty);
if (nativeDescriptor && nativeDescriptor.configurable) {
Object.defineProperty(elementProto, '__' + memberName, nativeDescriptor);
if (nativeDescriptor) {
Object.defineProperty(elementProto, nativeMemberName, nativeDescriptor);
}
if (shouldOverrideInTextNode) {
Object.defineProperty(textProto, memberName, memberProperty);
}
if (shouldOverrideInTextNode && nativeTextDescriptor) {
Object.defineProperty(textProto, nativeMemberName, nativeTextDescriptor);
}
if (shouldOverrideInCommentNode) {
Object.defineProperty(commProto, memberName, memberProperty);
}
if (shouldOverrideInCommentNode && nativeCommDescriptor) {
Object.defineProperty(commProto, nativeMemberName, nativeCommDescriptor);
}
}

@@ -781,0 +910,0 @@ });

// Any code referring to this is because it has to work around this bug in
// WebKit: https://bugs.webkit.org/show_bug.cgi?id=49739
export default !!Object.getOwnPropertyDescriptor(window.Node.prototype, 'parentNode').get;
import getPropertyDescriptor from './get-property-descriptor';
const nativeParentNode = getPropertyDescriptor(Element.prototype, 'innerHTML');
export default !!nativeParentNode;

@@ -1,2 +0,2 @@

export function eachChildNode (node, func) {
export function eachChildNode(node, func) {
if (!node) {

@@ -11,3 +11,3 @@ return;

if (typeof ret !== 'undefined') {
return ret;
return ret; // eslint-disable-line consistent-return
}

@@ -17,3 +17,3 @@ }

export function eachNodeOrFragmentNodes (node, func) {
export function eachNodeOrFragmentNodes(node, func) {
if (node instanceof DocumentFragment) {

@@ -20,0 +20,0 @@ const chs = node.childNodes;

@@ -1,3 +0,3 @@

import '../../src/index';
import bench from '../lib/bench';
import '../src/index';
import bench from './lib/bench';

@@ -4,0 +4,0 @@ describe('add / remove', function () {

@@ -1,10 +0,3 @@

import create from './lib/create';
import version from '../src/version';
import './unit/light/polyfill';
import './unit/shadow/polyfill';
import './unit/slot/polyfill';
import './unit/slot/fallback-content';
import './unit/slot/change-event.js';
describe('skatejs-named-slots', function () {

@@ -16,250 +9,9 @@ it('version', function () {

describe('skatejs-named-slots', function () {
let host, root, slot;
function add () {
host.appendChild(document.createElement('div'));
}
function remove() {
host.removeChild(host.firstChild);
}
beforeEach(function () {
host = document.createElement('div');
root = host.attachShadow({ mode: 'closed' });
slot = create('slot');
// Now it has something to assign nodes to.
root.appendChild(slot);
});
describe('methods', function () {
it('appendChild()', function () {
const light1 = document.createElement('light-1');
const light2 = document.createElement('light-2');
host.appendChild(light1);
expect(host.childNodes[0]).to.equal(light1, 'internal light dom');
expect(slot.getAssignedNodes().length).to.equal(1, 'slot');
expect(slot.getAssignedNodes()[0]).to.equal(light1, 'slot');
expect(host.childNodes.length).to.equal(1, 'light');
expect(host.childNodes[0]).to.equal(light1, 'light');
host.appendChild(light2);
expect(host.childNodes[1]).to.equal(light2, 'internal light dom');
expect(slot.getAssignedNodes().length).to.equal(2, 'slot');
expect(slot.getAssignedNodes()[0]).to.equal(light1, 'slot');
expect(slot.getAssignedNodes()[1]).to.equal(light2, 'slot');
expect(host.childNodes.length).to.equal(2, 'light');
expect(host.childNodes[0]).to.equal(light1, 'light');
expect(host.childNodes[1]).to.equal(light2, 'light');
});
it('hasChildNodes', function () {
expect(host.hasChildNodes()).to.equal(false);
host.appendChild(document.createElement('div'));
expect(host.hasChildNodes()).to.equal(true);
host.removeChild(host.firstChild);
expect(host.hasChildNodes()).to.equal(false);
});
it('insertBefore()', function () {
const light1 = document.createElement('light1');
const light2 = document.createElement('light2');
host.insertBefore(light2);
expect(host.childNodes[0]).to.equal(light2, 'internal light dom');
expect(slot.getAssignedNodes().length).to.equal(1, 'slot');
expect(slot.getAssignedNodes()[0]).to.equal(light2, 'slot');
expect(host.childNodes.length).to.equal(1, 'light');
expect(host.childNodes[0]).to.equal(light2, 'light');
host.insertBefore(light1, light2);
expect(host.childNodes[0]).to.equal(light1, 'internal light dom');
expect(host.childNodes[1]).to.equal(light2, 'internal light dom');
expect(slot.getAssignedNodes().length).to.equal(2, 'slot');
expect(slot.getAssignedNodes()[0]).to.equal(light1, 'slot');
expect(slot.getAssignedNodes()[1]).to.equal(light2, 'slot');
expect(host.childNodes.length).to.equal(2, 'light');
expect(host.childNodes[0]).to.equal(light1, 'light');
expect(host.childNodes[1]).to.equal(light2, 'light');
});
it('removeChild()', function () {
const light1 = document.createElement('div');
const light2 = document.createElement('div');
host.appendChild(light1);
host.appendChild(light2);
expect(slot.getAssignedNodes().length).to.equal(2, 'slot');
expect(slot.getAssignedNodes()[0]).to.equal(light1, 'slot');
expect(slot.getAssignedNodes()[1]).to.equal(light2, 'slot');
expect(host.childNodes.length).to.equal(2, 'light');
expect(host.childNodes[0]).to.equal(light1, 'light');
expect(host.childNodes[1]).to.equal(light2, 'light');
host.removeChild(light1);
expect(host.childNodes.length).to.equal(1);
expect(host.childNodes[0]).to.equal(light2, 'internal light dom');
expect(slot.getAssignedNodes().length).to.equal(1, 'slot');
expect(slot.getAssignedNodes()[0]).to.equal(light2, 'slot');
expect(host.childNodes.length).to.equal(1, 'light');
expect(host.childNodes[0]).to.equal(light2, 'light');
host.removeChild(light2);
expect(host.childNodes.length).to.equal(0);
expect(slot.getAssignedNodes().length).to.equal(0, 'slot');
expect(host.childNodes.length).to.equal(0, 'light');
});
it('replaceChild()', function () {
const light1 = document.createElement('div');
const light2 = document.createElement('div');
host.appendChild(light1);
expect(slot.getAssignedNodes().length).to.equal(1, 'slot');
expect(slot.getAssignedNodes()[0]).to.equal(light1, 'slot');
expect(host.childNodes.length).to.equal(1, 'light');
expect(host.childNodes[0]).to.equal(light1, 'light');
host.replaceChild(light2, light1);
expect(host.childNodes.length).to.equal(1);
expect(host.childNodes[0]).to.equal(light2, 'internal light dom');
expect(slot.getAssignedNodes().length).to.equal(1, 'slot');
expect(slot.getAssignedNodes()[0]).to.equal(light2, 'slot');
expect(host.childNodes.length).to.equal(1, 'light');
expect(host.childNodes[0]).to.equal(light2, 'light');
});
});
describe('properties', function () {
it('childElementCount', function () {
expect(host.childElementCount).to.equal(0);
add();
expect(host.childElementCount).to.equal(1);
remove();
expect(host.childElementCount).to.equal(0);
});
it('childNodes', function () {
expect(host.childNodes).to.be.an('array');
expect(host.childNodes.item).to.be.a('function');
expect(host.childNodes.length).to.equal(0);
add();
expect(host.childNodes.length).to.equal(1);
remove();
expect(host.childNodes.length).to.equal(0);
});
it('children', function () {
expect(host.childNodes).to.be.an('array');
expect(host.childNodes.item).to.be.a('function');
expect(host.childNodes.length).to.equal(0);
add();
expect(host.childNodes.length).to.equal(1);
remove();
expect(host.childNodes.length).to.equal(0);
});
it('firstChild', function () {
expect(host.firstChild).to.equal(null);
add();
expect(host.firstChild).to.not.equal(null);
expect(host.firstChild.tagName).to.equal('DIV');
remove();
expect(host.firstChild).to.equal(null);
});
it('firstElementChild', function () {
expect(host.firstChild).to.equal(null);
add();
expect(host.firstChild).to.not.equal(null);
expect(host.firstChild.tagName).to.equal('DIV');
remove();
expect(host.firstChild).to.equal(null);
});
it('innerHTML', function () {
expect(host.innerHTML).to.equal('');
host.innerHTML = '<div slot="custom"></div>';
expect(host.innerHTML).to.equal('<div slot="custom"></div>');
expect(host.childNodes.length).to.equal(1);
expect(slot.getAssignedNodes().length).to.equal(0);
host.innerHTML = '<div></div>';
expect(host.innerHTML).to.equal('<div></div>');
expect(host.childNodes.length).to.equal(1);
expect(slot.getAssignedNodes().length).to.equal(1);
host.innerHTML = '<div></div>';
expect(host.innerHTML).to.equal('<div></div>');
expect(host.childNodes.length).to.equal(1);
expect(slot.getAssignedNodes().length).to.equal(1);
});
it('lastChild', function () {
expect(host.lastChild).to.equal(null);
add();
expect(host.lastChild).to.not.equal(null);
expect(host.lastChild.tagName).to.equal('DIV');
remove();
expect(host.lastChild).to.equal(null);
});
it('lastElementChild', function () {
expect(host.lastElementChild).to.equal(null);
add();
expect(host.lastElementChild).to.not.equal(null);
expect(host.lastElementChild.tagName).to.equal('DIV');
remove();
expect(host.lastElementChild).to.equal(null);
});
it('outerHTML', function () {
expect(host.outerHTML).to.equal('<div></div>');
host.innerHTML = '<div slot="custom"></div>';
expect(host.outerHTML).to.equal('<div><div slot="custom"></div></div>');
expect(host.childNodes.length).to.equal(1);
expect(slot.getAssignedNodes().length).to.equal(0);
host.innerHTML = '<div></div>';
expect(host.outerHTML).to.equal('<div><div></div></div>');
expect(host.childNodes.length).to.equal(1);
expect(slot.getAssignedNodes().length).to.equal(1);
host.innerHTML = '<div></div>';
expect(host.outerHTML).to.equal('<div><div></div></div>');
expect(host.childNodes.length).to.equal(1);
expect(slot.getAssignedNodes().length).to.equal(1);
});
it('textContent', function () {
expect(host.textContent).to.equal('');
host.textContent = '<test />';
expect(host.textContent).to.equal('<test />');
// Ensure value was escaped.
expect(host.firstChild.nodeType).to.equal(3);
});
});
});
import './unit/dom/dom';
import './unit/light/polyfill';
import './unit/shadow/polyfill';
import './unit/slot/change-event.js';
import './unit/slot/distribution';
import './unit/slot/fallback-content';
import './unit/slot/polyfill';
import './unit/webcomponents/initialisation';

@@ -7,6 +7,24 @@ import '../../../src/index';

describe('when mode is closed', function () {
beforeEach(function () {
slot = create('slot');
host = create('div');
root = host.attachShadow({ mode: 'closed' });
root.appendChild(slot);
light1 = create('light1');
host.appendChild(light1);
});
it('assignedSlot', function () {
expect(light1.assignedSlot).to.equal(null);
});
});
beforeEach(function () {
slot = create('slot');
host = create('div');
root = host.attachShadow({ mode: 'closed' });
root = host.attachShadow({ mode: 'open' });

@@ -58,3 +76,3 @@ root.appendChild(slot);

anotherNode = create('div');
anotherRoot = anotherHost.attachShadow({ mode: 'closed' });
anotherRoot = anotherHost.attachShadow({ mode: 'open' });
anotherSlot = create('slot');

@@ -123,3 +141,3 @@

anotherNode = create('div');
anotherRoot = anotherHost.attachShadow({ mode: 'closed' });
anotherRoot = anotherHost.attachShadow({ mode: 'open' });
anotherSlot = create('slot');

@@ -172,2 +190,38 @@

});
describe('when text nodes are projected to a different spot than element nodes', function () {
let host, light1, light2, root, namedSlot, unnamedSlot, text;
beforeEach(function () {
namedSlot = create('slot', {name: 'mySlot'});
unnamedSlot = create('slot');
host = create('div');
root = host.attachShadow({ mode: 'open' });
root.appendChild(namedSlot);
root.appendChild(unnamedSlot);
light1 = create('div', {slot: 'mySlot'});
light2 = create('div', {slot: 'mySlot'});
text = document.createTextNode('text');
host.appendChild(light1);
host.appendChild(text);
host.appendChild(light2);
});
it('should polyfill previousSibling of textNode', function () {
expect(text.previousSibling).to.equal(light1);
});
it('should polyfill nextSibling of textNode', function () {
expect(text.nextSibling).to.equal(light2);
});
it('should NOT polyfill textContent of textNode', function () {
expect(text.textContent).to.equal('text');
expect(Object.getPrototypeOf(text).hasOwnProperty('textContent')).to.be.false;
expect(Object.getPrototypeOf(text).hasOwnProperty('__textContent')).to.be.false;
});
});
});
import '../../../src/index';
import create from '../../lib/create';
import canPatchNativeAccessors from '../../../src/util/can-patch-native-accessors';

@@ -41,2 +42,24 @@ describe('shadow/polyfill', function () {

if (canPatchNativeAccessors) {
it('proper node removal', function () {
const host = create('div');
host.appendChild(create('div'));
host.appendChild(create('div'));
host.appendChild(create('div'));
host.appendChild(create('div'));
host.attachShadow({ mode: 'open' });
expect(host.__childNodes.length).to.equal(1);
expect(host.__childNodes[0].tagName).to.equal('_SHADOW_ROOT_');
});
}
it('polyfilled properties with value should be writable', function() {
let elem = create('div');
expect(elem.removeEventListener).not.to.equal('');
elem.removeEventListener = '';
expect(elem.removeEventListener).to.equal('');
});
describe('api', function () {

@@ -62,2 +85,9 @@ let host, root;

expect(root.childNodes[0].name).to.equal('test');
if (canPatchNativeAccessors) {
root.innerHTML = '<h1></h1>';
root.innerHTML = '<div></div>';
// Checking that polyfilled innerHTML is working properly
expect(root.__innerHTML).to.equal('<div></div>');
}
});

@@ -119,6 +149,6 @@

expect(slot1.getAssignedNodes().length).to.equal(1);
expect(slot1.getAssignedNodes()[0]).to.equal(light1);
expect(slot2.getAssignedNodes().length).to.equal(1);
expect(slot2.getAssignedNodes()[0]).to.equal(light2);
expect(slot1.assignedNodes().length).to.equal(1);
expect(slot1.assignedNodes()[0]).to.equal(light1);
expect(slot2.assignedNodes().length).to.equal(1);
expect(slot2.assignedNodes()[0]).to.equal(light2);
});

@@ -132,3 +162,3 @@

const host = create('div', [light1, light2]);
const root = host.attachShadow({ mode: 'closed' });
const root = host.attachShadow({ mode: 'open' });

@@ -145,9 +175,9 @@ // Child nodes should be in the host even if there's no slots.

root.appendChild(slot1);
expect(slot1.getAssignedNodes().length).to.equal(1);
expect(slot1.getAssignedNodes()[0]).to.equal(light1);
expect(slot1.assignedNodes().length).to.equal(1);
expect(slot1.assignedNodes()[0]).to.equal(light1);
// After removing we should not.
root.appendChild(slot2);
expect(slot2.getAssignedNodes().length).to.equal(1);
expect(slot2.getAssignedNodes()[0]).to.equal(light2);
expect(slot2.assignedNodes().length).to.equal(1);
expect(slot2.assignedNodes()[0]).to.equal(light2);

@@ -157,6 +187,6 @@ // After removing we should not have any assigned nodes.

root.removeChild(slot2);
expect(slot1.getAssignedNodes().length).to.equal(0);
expect(slot2.getAssignedNodes().length).to.equal(0);
expect(slot1.assignedNodes().length).to.equal(0);
expect(slot2.assignedNodes().length).to.equal(0);
});
});
});

@@ -1,2 +0,2 @@

import create from '../lib/create';
import create from '../../lib/create';

@@ -3,0 +3,0 @@ describe('slotchange-event', function () {

@@ -1,2 +0,2 @@

import create from '../lib/create';
import create from '../../lib/create';

@@ -8,3 +8,3 @@ describe('fallback-content', function () {

host = create('div');
root = host.attachShadow({ mode: 'closed' });
root = host.attachShadow({ mode: 'open' });
slot = create('slot');

@@ -22,3 +22,3 @@ root.appendChild(slot);

expect(slot.____assignedNodes.length).to.equal(0);
expect(slot.getAssignedNodes().length).to.equal(0);
expect(slot.assignedNodes().length).to.equal(0);
});

@@ -46,3 +46,3 @@

expect(slot.____assignedNodes.length).to.equal(0);
expect(slot.getAssignedNodes().length).to.equal(0);
expect(slot.assignedNodes().length).to.equal(0);
});

@@ -63,3 +63,3 @@

it('should contain assigned nodes', function () {
expect(slot.getAssignedNodes()[0]).to.equal(newNode);
expect(slot.assignedNodes()[0]).to.equal(newNode);
});

@@ -77,3 +77,3 @@

it('should not contain the assigned nodes', function () {
expect(slot.getAssignedNodes().length).to.equal(0);
expect(slot.assignedNodes().length).to.equal(0);
});

@@ -80,0 +80,0 @@

import '../../../src/index';
import create from '../lib/create';
import create from '../../lib/create';

@@ -90,7 +90,7 @@ describe('slot/polyfill', function () {

it('HTMLSlotElement.getAssignedNodes()', function () {
expect(slot.getAssignedNodes().length).to.equal(0);
it('HTMLSlotElement.assignedNodes()', function () {
expect(slot.assignedNodes().length).to.equal(0);
});
it('HTMLSlotElement.getAssignedNodes({ deep: true })', function () {
it('HTMLSlotElement.assignedNodes({ deep: true })', function () {

@@ -109,6 +109,6 @@ });

host.appendChild(document.createTextNode('testing'));
expect(slot.getAssignedNodes().length).to.equal(2);
expect(slot.getAssignedNodes()[0].textContent).to.equal('');
expect(slot.getAssignedNodes()[1].textContent).to.equal('testing');
expect(slot.assignedNodes().length).to.equal(2);
expect(slot.assignedNodes()[0].textContent).to.equal('');
expect(slot.assignedNodes()[1].textContent).to.equal('testing');
});
});

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc