1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | function isValidNode(obj) {
|
4 | var ELEM_TYPE = 1;
|
5 | var FRAG_TYPE = 11;
|
6 | return typeof HTMLElement === 'object'
|
7 | ? obj instanceof HTMLElement || obj instanceof DocumentFragment
|
8 | : obj &&
|
9 | typeof obj === 'object' &&
|
10 | obj !== null &&
|
11 | (obj.nodeType === ELEM_TYPE || obj.nodeType === FRAG_TYPE) &&
|
12 | typeof obj.nodeName === 'string';
|
13 | }
|
14 | function isClassOrId(str) {
|
15 | return str.length > 1 && (str[0] === '.' || str[0] === '#');
|
16 | }
|
17 | exports.isClassOrId = isClassOrId;
|
18 | function isDocFrag(el) {
|
19 | return el.nodeType === 11;
|
20 | }
|
21 | exports.isDocFrag = isDocFrag;
|
22 | function checkValidContainer(container) {
|
23 | if (typeof container !== 'string' && !isValidNode(container)) {
|
24 | throw new Error('Given container is not a DOM element neither a selector string.');
|
25 | }
|
26 | }
|
27 | exports.checkValidContainer = checkValidContainer;
|
28 | function getValidNode(selectors) {
|
29 | var domElement = typeof selectors === 'string'
|
30 | ? document.querySelector(selectors)
|
31 | : selectors;
|
32 | if (typeof selectors === 'string' && domElement === null) {
|
33 | throw new Error("Cannot render into unknown element `" + selectors + "`");
|
34 | }
|
35 | return domElement;
|
36 | }
|
37 | exports.getValidNode = getValidNode;
|
38 | function getSelectors(namespace) {
|
39 | var res = '';
|
40 | for (var i = namespace.length - 1; i >= 0; i--) {
|
41 | if (namespace[i].type !== 'selector') {
|
42 | break;
|
43 | }
|
44 | res = namespace[i].scope + ' ' + res;
|
45 | }
|
46 | return res.trim();
|
47 | }
|
48 | exports.getSelectors = getSelectors;
|
49 | function isEqualNamespace(a, b) {
|
50 | if (!Array.isArray(a) || !Array.isArray(b) || a.length !== b.length) {
|
51 | return false;
|
52 | }
|
53 | for (var i = 0; i < a.length; i++) {
|
54 | if (a[i].type !== b[i].type || a[i].scope !== b[i].scope) {
|
55 | return false;
|
56 | }
|
57 | }
|
58 | return true;
|
59 | }
|
60 | exports.isEqualNamespace = isEqualNamespace;
|
61 | function makeInsert(map) {
|
62 | return function (type, elm, value) {
|
63 | if (map.has(type)) {
|
64 | var innerMap = map.get(type);
|
65 | innerMap.set(elm, value);
|
66 | }
|
67 | else {
|
68 | var innerMap = new Map();
|
69 | innerMap.set(elm, value);
|
70 | map.set(type, innerMap);
|
71 | }
|
72 | };
|
73 | }
|
74 | exports.makeInsert = makeInsert;
|
75 |
|
\ | No newline at end of file |