UNPKG

@cycle/dom

Version:

The standard DOM Driver for Cycle.js, based on Snabbdom

75 lines 2.37 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); function isValidNode(obj) { var ELEM_TYPE = 1; var FRAG_TYPE = 11; return typeof HTMLElement === 'object' ? obj instanceof HTMLElement || obj instanceof DocumentFragment : obj && typeof obj === 'object' && obj !== null && (obj.nodeType === ELEM_TYPE || obj.nodeType === FRAG_TYPE) && typeof obj.nodeName === 'string'; } function isClassOrId(str) { return str.length > 1 && (str[0] === '.' || str[0] === '#'); } exports.isClassOrId = isClassOrId; function isDocFrag(el) { return el.nodeType === 11; } exports.isDocFrag = isDocFrag; function checkValidContainer(container) { if (typeof container !== 'string' && !isValidNode(container)) { throw new Error('Given container is not a DOM element neither a selector string.'); } } exports.checkValidContainer = checkValidContainer; function getValidNode(selectors) { var domElement = typeof selectors === 'string' ? document.querySelector(selectors) : selectors; if (typeof selectors === 'string' && domElement === null) { throw new Error("Cannot render into unknown element `" + selectors + "`"); } return domElement; } exports.getValidNode = getValidNode; function getSelectors(namespace) { var res = ''; for (var i = namespace.length - 1; i >= 0; i--) { if (namespace[i].type !== 'selector') { break; } res = namespace[i].scope + ' ' + res; } return res.trim(); } exports.getSelectors = getSelectors; function isEqualNamespace(a, b) { if (!Array.isArray(a) || !Array.isArray(b) || a.length !== b.length) { return false; } for (var i = 0; i < a.length; i++) { if (a[i].type !== b[i].type || a[i].scope !== b[i].scope) { return false; } } return true; } exports.isEqualNamespace = isEqualNamespace; function makeInsert(map) { return function (type, elm, value) { if (map.has(type)) { var innerMap = map.get(type); innerMap.set(elm, value); } else { var innerMap = new Map(); innerMap.set(elm, value); map.set(type, innerMap); } }; } exports.makeInsert = makeInsert; //# sourceMappingURL=utils.js.map