siphon-cli
Version:
Simple bundler for web applications. 📦🔧🧡
36 lines (35 loc) • 1.43 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var getDOMNodes_1 = require("./getDOMNodes");
function createDOMTree(source) {
var _a, _b, _c, _d;
var nodes = (0, getDOMNodes_1.default)(source);
var filledNodes = [];
for (var i = 0; nodes[i]; i++) {
var h = i - 1;
if ((_a = nodes[i].attributes) === null || _a === void 0 ? void 0 : _a.class) {
nodes[i].classList = nodes[i].attributes.class
.split(/\s+[\s]*/)
.filter(function (classname) { return classname !== ""; });
}
else
nodes[i].classList = [];
if (nodes[i].parent) {
while (nodes[h] &&
!(nodes[i].parent[0] === nodes[h].tagName &&
nodes[i].parent[1] === nodes[h].identifier))
h--;
if (nodes[h]) {
if (!nodes[h].children)
nodes[h].children = [];
nodes[i].parent = nodes[h];
nodes[i].childID = (_c = (_b = nodes[h].children) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0;
(_d = nodes[h].children) === null || _d === void 0 ? void 0 : _d.push(nodes[i]);
}
}
else
filledNodes.push(nodes[i]);
}
return filledNodes;
}
exports.default = createDOMTree;