dom-render
Advanced tools
Comparing version 1.0.7 to 1.0.8
@@ -0,1 +1,4 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Config = void 0; | ||
var Config = (function () { | ||
@@ -18,2 +21,2 @@ function Config(_document, factoryScopeObject) { | ||
}()); | ||
export { Config }; | ||
exports.Config = Config; |
'use strict'; | ||
try{if(!exports) {var exports = {}}}catch (e) {var exports = {}} Object.defineProperty(exports, '__esModule', { value: true }); | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. | ||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted. | ||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | ||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | ||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR | ||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */ | ||
/* global Reflect, Promise */ | ||
var extendStatics = function(d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
function __extends(d, b) { | ||
if (typeof b !== "function" && b !== null) | ||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
} | ||
var ScopeResultSet = (function () { | ||
function ScopeResultSet(uuid, object, fragment, startComment, endComment, calls) { | ||
if (calls === void 0) { calls = []; } | ||
this.uuid = uuid; | ||
this.object = object; | ||
this.fragment = fragment; | ||
this.startComment = startComment; | ||
this.endComment = endComment; | ||
this.calls = calls; | ||
this.childNodes = []; | ||
for (var i = 0; i < fragment.childNodes.length; i++) { | ||
var childNode = fragment.childNodes[i]; | ||
this.childNodes.push(childNode); | ||
} | ||
} | ||
ScopeResultSet.prototype.childAllRemove = function () { | ||
var next = this.startComment.nextSibling; | ||
while (next) { | ||
if (next === this.endComment) { | ||
break; | ||
} | ||
next.remove(); | ||
next = this.startComment.nextSibling; | ||
} | ||
}; | ||
return ScopeResultSet; | ||
}()); | ||
var ValidUtils = (function () { | ||
function ValidUtils() { | ||
} | ||
ValidUtils.isNullOrUndefined = function (data) { | ||
if (data == null || undefined === data) { | ||
return true; | ||
} | ||
else { | ||
return false; | ||
} | ||
}; | ||
ValidUtils.isNull = function (data) { | ||
if (data == null) { | ||
return true; | ||
} | ||
else { | ||
return false; | ||
} | ||
}; | ||
ValidUtils.isArray = function (object_o) { | ||
if (ValidUtils.isNullOrUndefined(object_o)) { | ||
return false; | ||
} | ||
else { | ||
return Object.prototype.toString.call(object_o).trim() === '[object Array]'; | ||
} | ||
}; | ||
ValidUtils.isNumber = function (object_o) { | ||
if (ValidUtils.isNullOrUndefined(object_o)) { | ||
return false; | ||
} | ||
else { | ||
return Object.prototype.toString.call(object_o).trim() === '[object Number]'; | ||
} | ||
}; | ||
ValidUtils.isString = function (object_o) { | ||
if (ValidUtils.isNullOrUndefined(object_o)) { | ||
return false; | ||
} | ||
else { | ||
return Object.prototype.toString.call(object_o).trim() === '[object String]'; | ||
} | ||
}; | ||
ValidUtils.isFunction = function (object_o) { | ||
if (ValidUtils.isNullOrUndefined(object_o)) { | ||
return false; | ||
} | ||
else { | ||
return Object.prototype.toString.call(object_o).trim() === '[object Function]'; | ||
} | ||
}; | ||
ValidUtils.isObject = function (object_o) { | ||
if (ValidUtils.isNullOrUndefined(object_o)) { | ||
return false; | ||
} | ||
else { | ||
return Object.prototype.toString.call(object_o).trim() === '[object Object]'; | ||
} | ||
}; | ||
ValidUtils.isMap = function (object_o) { | ||
if (ValidUtils.isNullOrUndefined(object_o)) { | ||
return false; | ||
} | ||
else { | ||
return Object.prototype.toString.call(object_o).trim() === '[object Map]'; | ||
} | ||
}; | ||
return ValidUtils; | ||
}()); | ||
var RandomUtils = (function () { | ||
function RandomUtils() { | ||
} | ||
RandomUtils.random = function (min, max) { | ||
if (ValidUtils.isNullOrUndefined(min)) { | ||
return Math.random(); | ||
} | ||
else if (!ValidUtils.isNullOrUndefined(min) && ValidUtils.isNullOrUndefined(max)) { | ||
return Math.random() * (min || 0); | ||
} | ||
else { | ||
return Math.random() * ((max || 0) - (min || 0)) + (min || 0); | ||
} | ||
}; | ||
RandomUtils.uuid = function (format) { | ||
if (format === void 0) { format = 'xxxx-xxxx-xxxx-xxxx'; } | ||
return format.replace(/[xy]/g, function (c) { | ||
var r = Math.random() * 16 | 0; | ||
var v = c === 'x' ? r : (r & 0x3 | 0x8); | ||
return v.toString(16); | ||
}); | ||
}; | ||
RandomUtils.getRandomColor = function () { | ||
var letters = '0123456789ABCDEF'.split(''); | ||
var color = '#'; | ||
for (var i = 0; i < 6; i++) { | ||
color += letters[Math.floor(Math.random() * 16)]; | ||
} | ||
return color; | ||
}; | ||
RandomUtils.getRandomString = function (len) { | ||
var letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split(''); | ||
var color = ''; | ||
for (var i = 0; i < len; i++) { | ||
color += letters[Math.floor(Math.random() * letters.length)]; | ||
} | ||
return color; | ||
}; | ||
RandomUtils.d = ''; | ||
return RandomUtils; | ||
}()); | ||
var ScopeObject = (function () { | ||
function ScopeObject(config, uuid) { | ||
if (uuid === void 0) { uuid = RandomUtils.uuid(); } | ||
this.config = config; | ||
this.uuid = uuid; | ||
this.calls = []; | ||
this.writes = ''; | ||
} | ||
ScopeObject.prototype.executeResultSet = function (code) { | ||
var _this = this; | ||
this.eval(code); | ||
var templateElement = this.config.document.createElement('template'); | ||
templateElement.innerHTML = this.writes; | ||
var startComment = this.config.document.createComment('scope start ' + this.uuid); | ||
var endComment = this.config.document.createComment('scope end ' + this.uuid); | ||
templateElement.content.childNodes.forEach(function (it) { | ||
if (it.nodeType === 1) { | ||
it.setAttribute('scope-uuid', _this.uuid); | ||
} | ||
}); | ||
return new ScopeResultSet(this.uuid, this, templateElement.content, startComment, endComment, this.calls); | ||
}; | ||
ScopeObject.prototype.eval = function (str) { | ||
return this.scopeEval(this, str); | ||
}; | ||
ScopeObject.prototype.scopeEval = function (scope, script) { | ||
return Function("\"use strict\";\n const write = (str) => {\n this.appendWrite(str);\n }\n \n " + this.customScript() + "\n \n " + script + "\n ").bind(scope)(); | ||
}; | ||
ScopeObject.prototype.customScript = function () { | ||
return ''; | ||
}; | ||
ScopeObject.prototype.appendWrite = function (str) { | ||
this.writes += str; | ||
}; | ||
return ScopeObject; | ||
}()); | ||
var ScopePosition = (function () { | ||
function ScopePosition(startIndex, endIndex) { | ||
this.startIndex = startIndex; | ||
this.endIndex = endIndex; | ||
} | ||
return ScopePosition; | ||
}()); | ||
var Config = (function () { | ||
function Config(_document, factoryScopeObject) { | ||
this._document = _document; | ||
this.factoryScopeObject = factoryScopeObject; | ||
this.start = '<!--%'; | ||
this.end = '%-->'; | ||
} | ||
Object.defineProperty(Config.prototype, "document", { | ||
get: function () { | ||
var _a; | ||
return (_a = this._document) !== null && _a !== void 0 ? _a : document; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
return Config; | ||
}()); | ||
var Scope = (function () { | ||
function Scope(raws, obj, uuid, config, position) { | ||
if (uuid === void 0) { uuid = RandomUtils.uuid(); } | ||
if (config === void 0) { config = new Config(); } | ||
if (position === void 0) { position = new ScopePosition(0, raws.length); } | ||
this.raws = raws; | ||
this.obj = obj; | ||
this.uuid = uuid; | ||
this.config = config; | ||
this.position = position; | ||
this.childs = []; | ||
this.usingVars = []; | ||
this.run(); | ||
} | ||
Scope.prototype.childIsContain = function () { | ||
var _a; | ||
for (var i = 0; i < this.childs.length; i++) { | ||
if ((_a = this.childs[i].scopeResult) === null || _a === void 0 ? void 0 : _a.startComment.isConnected) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
}; | ||
Scope.prototype.exec = function (obj) { | ||
if (obj === void 0) { obj = this.obj; } | ||
var scopeObject = this.config.factoryScopeObject ? this.config.factoryScopeObject(this) : new ScopeObject(this.config); | ||
var object = Object.assign(scopeObject, obj); | ||
this.scopeResult = object.executeResultSet(this.raws); | ||
return { object: object, result: this.scopeResult }; | ||
}; | ||
Scope.prototype.run = function () { | ||
var targetRaws = this.raws; | ||
this.usingVars = Scope.usingThisVar(targetRaws); | ||
var i = this.indexOf(targetRaws, this.config.start); | ||
while (i !== -1) { | ||
var startIdx = i; | ||
var endIdx = this.tailIndexOf(targetRaws, this.config.end, i); | ||
while (endIdx !== -1) { | ||
var sub = targetRaws.substring(startIdx, endIdx); | ||
var matchStart = sub.match(RegExp(this.config.start, 'gm')) || []; | ||
var matchEnd = sub.match(RegExp(this.config.end, 'gm')) || []; | ||
if (matchStart.length === matchEnd.length) { | ||
var scope = new Scope(sub.substring(this.config.start.length, sub.length - this.config.end.length), this.obj, RandomUtils.uuid(), this.config, new ScopePosition(startIdx, endIdx)); | ||
this.childs.push(scope); | ||
break; | ||
} | ||
endIdx = this.tailIndexOf(targetRaws, this.config.end, endIdx); | ||
} | ||
if (endIdx !== -1) { | ||
i = this.indexOf(targetRaws, this.config.start, endIdx); | ||
} | ||
else { | ||
break; | ||
} | ||
} | ||
return this; | ||
}; | ||
Scope.prototype.indexOf = function (data, searchString, position) { | ||
return data.indexOf(searchString, position); | ||
}; | ||
Scope.prototype.tailIndexOf = function (data, searchString, position) { | ||
var number = data.indexOf(searchString, position); | ||
return number !== -1 ? number + searchString.length : number; | ||
}; | ||
Scope.usingThisVar = function (raws) { | ||
var regex = /["'].*["']/gm; | ||
raws = raws.replace(regex, ''); | ||
var varRegexStr = 'this\\.([a-zA-Z_$][a-zA-Z_.$0-9]*)'; | ||
var varRegex = RegExp(varRegexStr, 'gm'); | ||
var varExec = varRegex.exec(raws); | ||
var usingVars = []; | ||
while (varExec) { | ||
usingVars.push(varExec[1]); | ||
varExec = varRegex.exec(varExec.input); | ||
} | ||
return usingVars; | ||
}; | ||
return Scope; | ||
}()); | ||
var ScopeRawSet = (function () { | ||
function ScopeRawSet(raw, styles) { | ||
if (styles === void 0) { styles = []; } | ||
this.raw = raw; | ||
this.styles = styles; | ||
} | ||
return ScopeRawSet; | ||
}()); | ||
var NodeUtils = (function () { | ||
function NodeUtils() { | ||
} | ||
NodeUtils.removeAllChildNode = function (node) { | ||
while (node === null || node === void 0 ? void 0 : node.firstChild) { | ||
node.firstChild.remove(); | ||
} | ||
}; | ||
NodeUtils.appendChild = function (parentNode, childNode) { | ||
return parentNode.appendChild(childNode); | ||
}; | ||
NodeUtils.replaceNode = function (targetNode, newNode) { | ||
var _a; | ||
return (_a = targetNode.parentNode) === null || _a === void 0 ? void 0 : _a.replaceChild(newNode, targetNode); | ||
}; | ||
NodeUtils.addNode = function (targetNode, newNode) { | ||
var _a; | ||
return (_a = targetNode.parentNode) === null || _a === void 0 ? void 0 : _a.insertBefore(newNode, targetNode.nextSibling); | ||
}; | ||
return NodeUtils; | ||
}()); | ||
var TargetNodeMode; | ||
(function (TargetNodeMode) { | ||
TargetNodeMode["child"] = "child"; | ||
TargetNodeMode["appendChild"] = "appendChild"; | ||
TargetNodeMode["prepend"] = "prepend"; | ||
TargetNodeMode["replace"] = "replace"; | ||
})(TargetNodeMode || (TargetNodeMode = {})); | ||
var TargetNode = (function () { | ||
function TargetNode(_node, mode) { | ||
if (_node === void 0) { _node = document.body; } | ||
if (mode === void 0) { mode = TargetNodeMode.child; } | ||
this._node = _node; | ||
this.mode = mode; | ||
} | ||
Object.defineProperty(TargetNode.prototype, "node", { | ||
get: function () { | ||
if (typeof this._node === 'string') { | ||
return document.querySelector(this._node); | ||
} | ||
else { | ||
return this._node; | ||
} | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
return TargetNode; | ||
}()); | ||
var RootScope = (function (_super) { | ||
__extends(RootScope, _super); | ||
function RootScope(rawSet, obj, uuid, config, targetNode, position) { | ||
if (uuid === void 0) { uuid = RandomUtils.uuid(); } | ||
if (config === void 0) { config = new Config(); } | ||
if (targetNode === void 0) { targetNode = new TargetNode(config.document); } | ||
if (position === void 0) { position = new ScopePosition(0, rawSet.raw.length); } | ||
var _this = _super.call(this, rawSet.raw, obj, uuid, config, position) || this; | ||
_this.rawSet = rawSet; | ||
_this.targetNode = targetNode; | ||
return _this; | ||
} | ||
RootScope.prototype.executeRender = function (option) { | ||
var _a; | ||
var fragment = this.executeFragment(option); | ||
if (this.targetNode.node && TargetNodeMode.child === this.targetNode.mode) { | ||
NodeUtils.removeAllChildNode(this.targetNode.node); | ||
NodeUtils.appendChild(this.targetNode.node, fragment); | ||
} | ||
if (this.targetNode.node && TargetNodeMode.appendChild === this.targetNode.mode) { | ||
NodeUtils.appendChild(this.targetNode.node, fragment); | ||
} | ||
if (this.targetNode.node && TargetNodeMode.prepend === this.targetNode.mode) { | ||
(_a = this.targetNode.node) === null || _a === void 0 ? void 0 : _a.prepend(fragment); | ||
} | ||
else if (this.targetNode.node && TargetNodeMode.replace === this.targetNode.mode) { | ||
NodeUtils.replaceNode(this.targetNode.node, fragment); | ||
} | ||
else ; | ||
return this.targetNode; | ||
}; | ||
RootScope.prototype.executeFragment = function (option) { | ||
var _this = this; | ||
var _a; | ||
var templateElement = this.config.document.createElement('template'); | ||
templateElement.innerHTML = this.raws; | ||
var rawFragment = templateElement.content; | ||
this.childs.forEach(function (it) { | ||
var _a; | ||
var childScopeObject = it.exec().result; | ||
var currentNode = _this.extracted(rawFragment, it, childScopeObject); | ||
if (option === null || option === void 0 ? void 0 : option.head) { | ||
childScopeObject.fragment.prepend(option === null || option === void 0 ? void 0 : option.head); | ||
} | ||
if (option === null || option === void 0 ? void 0 : option.tail) { | ||
childScopeObject.fragment.append(option === null || option === void 0 ? void 0 : option.tail); | ||
} | ||
(_a = currentNode === null || currentNode === void 0 ? void 0 : currentNode.parentNode) === null || _a === void 0 ? void 0 : _a.replaceChild(childScopeObject.fragment, currentNode); | ||
}); | ||
if (this.rawSet.styles.length > 0) { | ||
var styleScope = new RootScope(new ScopeRawSet(this.rawSet.styles.join(' ')), this.obj, RandomUtils.uuid(), this.config); | ||
var styleFragment = styleScope.executeFragment(); | ||
styleScope.childs.forEach(function (it) { return _this.childs.push(it); }); | ||
var style = this.config.document.createElement('style'); | ||
style.appendChild(styleFragment); | ||
rawFragment.prepend(style); | ||
} | ||
if ((option === null || option === void 0 ? void 0 : option.childElementAttr) && ((_a = option === null || option === void 0 ? void 0 : option.childElementAttr) === null || _a === void 0 ? void 0 : _a.size) > 0) { | ||
rawFragment.childNodes.forEach(function (it) { | ||
var _a; | ||
if (it.nodeType === 1) { | ||
(_a = option === null || option === void 0 ? void 0 : option.childElementAttr) === null || _a === void 0 ? void 0 : _a.forEach(function (v, k) { | ||
it.setAttribute(k, v); | ||
}); | ||
} | ||
}); | ||
} | ||
return rawFragment; | ||
}; | ||
RootScope.prototype.extracted = function (rawFragment, it, childScopeObject) { | ||
var _a, _b; | ||
var nodeIterator = this.config.document.createNodeIterator(rawFragment, 128, { | ||
acceptNode: function (node) { | ||
var coment = node.data.replace(/[\r\n]/g, ''); | ||
var b = coment.startsWith('%') && coment.endsWith('%') && coment === ('%' + it.raws.replace(/[\r\n]/g, '') + '%'); | ||
return b ? 1 : 2; | ||
} | ||
}); | ||
var currentNode = nodeIterator.nextNode(); | ||
(_a = currentNode === null || currentNode === void 0 ? void 0 : currentNode.parentNode) === null || _a === void 0 ? void 0 : _a.insertBefore(childScopeObject.startComment, currentNode); | ||
(_b = currentNode === null || currentNode === void 0 ? void 0 : currentNode.parentNode) === null || _b === void 0 ? void 0 : _b.insertBefore(childScopeObject.endComment, currentNode.nextSibling); | ||
return currentNode; | ||
}; | ||
return RootScope; | ||
}(Scope)); | ||
var ScopeObjectProxyHandler = (function () { | ||
function ScopeObjectProxyHandler() { | ||
this._refs = []; | ||
} | ||
ScopeObjectProxyHandler.prototype.run = function (_targetProxy, _targetOrigin, _rootScope) { | ||
var _this = this; | ||
this._targetProxy = _targetProxy; | ||
this._targetOrigin = _targetOrigin; | ||
this._rootScope = _rootScope; | ||
var data = Object.keys(_targetOrigin) || []; | ||
data.forEach(function (it) { | ||
_this._targetOrigin[it] = _this.proxy(_this._targetOrigin[it]); | ||
}); | ||
}; | ||
ScopeObjectProxyHandler.prototype.proxy = function (target) { | ||
var _a; | ||
if (typeof target === 'object' && !('_ScopeObjectProxyHandler_isProxy' in target)) { | ||
var scopeObjectProxyHandler = new ScopeObjectProxyHandler(); | ||
scopeObjectProxyHandler._refs.push(this._targetProxy); | ||
var targetProxy = new Proxy(target, scopeObjectProxyHandler); | ||
(_a = targetProxy === null || targetProxy === void 0 ? void 0 : targetProxy._ScopeObjectProxyHandler) === null || _a === void 0 ? void 0 : _a.run(targetProxy, target); | ||
return targetProxy; | ||
} | ||
return target; | ||
}; | ||
ScopeObjectProxyHandler.prototype.get = function (target, name, receiver) { | ||
if (name === '_ScopeObjectProxyHandler') { | ||
return this; | ||
} | ||
else if (name === '_ScopeObjectProxyHandler_refs') { | ||
return this._refs; | ||
} | ||
else if (name === '_ScopeObjectProxyHandler_targetProxy') { | ||
return this._targetProxy; | ||
} | ||
else if (name === '_ScopeObjectProxyHandler_targetOrigin') { | ||
return this._targetOrigin; | ||
} | ||
else if (name === '_ScopeObjectProxyHandler_rootScope') { | ||
return this._rootScope; | ||
} | ||
else { | ||
return target[name]; | ||
} | ||
}; | ||
ScopeObjectProxyHandler.prototype.depth = function (depths, obj) { | ||
}; | ||
ScopeObjectProxyHandler.prototype.getRefsProxyProp = function (obj) { | ||
var fields = []; | ||
this._refs.forEach(function (it) { | ||
var data = Object.keys(it) || []; | ||
data.filter(function (sit) { return typeof it[sit] === 'object' && ('_ScopeObjectProxyHandler_isProxy' in it[sit]) && obj === it[sit]._ScopeObjectProxyHandler_targetOrigin; }).forEach(function (sit) { | ||
fields.push({ | ||
parent: it, | ||
name: sit, | ||
fieldValue: it[sit] | ||
}); | ||
}); | ||
}); | ||
return fields; | ||
}; | ||
ScopeObjectProxyHandler.prototype.goRoot = function (depths, obj) { | ||
var arr = []; | ||
var refsProxyProp = this.getRefsProxyProp(obj); | ||
if (refsProxyProp.length > 0) { | ||
refsProxyProp.forEach(function (it) { | ||
var newDepths = depths.slice(); | ||
newDepths.unshift(it.name); | ||
var patharray = it.parent._ScopeObjectProxyHandler.goRoot(newDepths, it.parent._ScopeObjectProxyHandler_targetOrigin); | ||
patharray.forEach(function (it) { return arr.push(it); }); | ||
}); | ||
} | ||
else { | ||
var item = { | ||
rootScope: this._rootScope, | ||
rootTargetOrigin: this._targetOrigin, | ||
depths: depths | ||
}; | ||
arr.push(item); | ||
} | ||
return arr; | ||
}; | ||
ScopeObjectProxyHandler.prototype.set = function (obj, prop, value) { | ||
obj[prop] = this.proxy(value); | ||
var depths = [prop]; | ||
var parentDepths = this.goRoot(depths, obj); | ||
parentDepths.filter(function (it) { return it.rootScope; }).forEach(function (it) { | ||
var _a; | ||
var fullDepth = it.depths.join('.'); | ||
(_a = it.rootScope) === null || _a === void 0 ? void 0 : _a.childs.filter(function (sit) { return sit.scopeResult && sit.usingVars.includes(fullDepth); }).forEach(function (sit) { | ||
if (sit.scopeResult) { | ||
sit.scopeResult.childAllRemove(); | ||
var startComment_1 = sit.scopeResult.startComment; | ||
var endComment = sit.scopeResult.endComment; | ||
sit.exec(it.rootTargetOrigin); | ||
sit.scopeResult.childNodes.forEach(function (cit) { return NodeUtils.addNode(startComment_1, cit); }); | ||
NodeUtils.replaceNode(startComment_1, sit.scopeResult.startComment); | ||
NodeUtils.replaceNode(endComment, sit.scopeResult.endComment); | ||
} | ||
}); | ||
}); | ||
return true; | ||
}; | ||
ScopeObjectProxyHandler.prototype.has = function (target, key) { | ||
return key === '_ScopeObjectProxyHandler_isProxy' || key in target; | ||
}; | ||
return ScopeObjectProxyHandler; | ||
}()); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.DomRender = void 0; | ||
var RootScope_1 = require("./RootScope"); | ||
var RandomUtils_1 = require("./utils/random/RandomUtils"); | ||
var Config_1 = require("./Config"); | ||
var ScopeObjectProxyHandler_1 = require("./ScopeObjectProxyHandler"); | ||
var DomRender = (function () { | ||
@@ -576,16 +14,16 @@ function DomRender(raws, uuidAndConfig, uuid) { | ||
if (typeof uuidAndConfig === 'string') { | ||
this.config = new Config(document); | ||
this.config = new Config_1.Config(document); | ||
this.rootUUID = uuidAndConfig; | ||
} | ||
else if (uuidAndConfig instanceof Config) { | ||
else if (uuidAndConfig instanceof Config_1.Config) { | ||
this.config = uuidAndConfig; | ||
this.rootUUID = uuid !== null && uuid !== void 0 ? uuid : RandomUtils.uuid(); | ||
this.rootUUID = uuid !== null && uuid !== void 0 ? uuid : RandomUtils_1.RandomUtils.uuid(); | ||
} | ||
else { | ||
this.config = new Config(document); | ||
this.rootUUID = RandomUtils.uuid(); | ||
this.config = new Config_1.Config(document); | ||
this.rootUUID = RandomUtils_1.RandomUtils.uuid(); | ||
} | ||
} | ||
DomRender.prototype.compile = function (target, targetNode) { | ||
this.root = new RootScope(this.raws, target, this.rootUUID, this.config, targetNode); | ||
this.root = new RootScope_1.RootScope(this.raws, target, this.rootUUID, this.config, targetNode); | ||
return this.root; | ||
@@ -595,4 +33,4 @@ }; | ||
var _a; | ||
this.root = new RootScope(this.raws, target, this.rootUUID, this.config, targetNode); | ||
var proxy = new Proxy(target, new ScopeObjectProxyHandler()); | ||
this.root = new RootScope_1.RootScope(this.raws, target, this.rootUUID, this.config, targetNode); | ||
var proxy = new Proxy(target, new ScopeObjectProxyHandler_1.ScopeObjectProxyHandler()); | ||
(_a = proxy === null || proxy === void 0 ? void 0 : proxy._ScopeObjectProxyHandler) === null || _a === void 0 ? void 0 : _a.run(proxy, target, this.root); | ||
@@ -609,3 +47,2 @@ return proxy; | ||
}()); | ||
exports.DomRender = DomRender; |
@@ -1,5 +0,8 @@ | ||
import { RootScope } from './RootScope'; | ||
import { RandomUtils } from './utils/random/RandomUtils'; | ||
import { Config } from './Config'; | ||
import { ScopeObjectProxyHandler } from './ScopeObjectProxyHandler'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.DomRender = void 0; | ||
var RootScope_1 = require("./RootScope"); | ||
var RandomUtils_1 = require("./utils/random/RandomUtils"); | ||
var Config_1 = require("./Config"); | ||
var ScopeObjectProxyHandler_1 = require("./ScopeObjectProxyHandler"); | ||
var DomRender = (function () { | ||
@@ -10,16 +13,16 @@ function DomRender(raws, uuidAndConfig, uuid) { | ||
if (typeof uuidAndConfig === 'string') { | ||
this.config = new Config(document); | ||
this.config = new Config_1.Config(document); | ||
this.rootUUID = uuidAndConfig; | ||
} | ||
else if (uuidAndConfig instanceof Config) { | ||
else if (uuidAndConfig instanceof Config_1.Config) { | ||
this.config = uuidAndConfig; | ||
this.rootUUID = uuid !== null && uuid !== void 0 ? uuid : RandomUtils.uuid(); | ||
this.rootUUID = uuid !== null && uuid !== void 0 ? uuid : RandomUtils_1.RandomUtils.uuid(); | ||
} | ||
else { | ||
this.config = new Config(document); | ||
this.rootUUID = RandomUtils.uuid(); | ||
this.config = new Config_1.Config(document); | ||
this.rootUUID = RandomUtils_1.RandomUtils.uuid(); | ||
} | ||
} | ||
DomRender.prototype.compile = function (target, targetNode) { | ||
this.root = new RootScope(this.raws, target, this.rootUUID, this.config, targetNode); | ||
this.root = new RootScope_1.RootScope(this.raws, target, this.rootUUID, this.config, targetNode); | ||
return this.root; | ||
@@ -29,4 +32,4 @@ }; | ||
var _a; | ||
this.root = new RootScope(this.raws, target, this.rootUUID, this.config, targetNode); | ||
var proxy = new Proxy(target, new ScopeObjectProxyHandler()); | ||
this.root = new RootScope_1.RootScope(this.raws, target, this.rootUUID, this.config, targetNode); | ||
var proxy = new Proxy(target, new ScopeObjectProxyHandler_1.ScopeObjectProxyHandler()); | ||
(_a = proxy === null || proxy === void 0 ? void 0 : proxy._ScopeObjectProxyHandler) === null || _a === void 0 ? void 0 : _a.run(proxy, target, this.root); | ||
@@ -43,2 +46,2 @@ return proxy; | ||
}()); | ||
export { DomRender }; | ||
exports.DomRender = DomRender; |
{ | ||
"name": "dom-render", | ||
"version": "1.0.7", | ||
"version": "1.0.8", | ||
"main": "DomRenderCompiler.js", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
@@ -16,9 +17,11 @@ var extendStatics = function (d, b) { | ||
})(); | ||
import { Scope } from './Scope'; | ||
import { ScopePosition } from './ScopePosition'; | ||
import { ScopeRawSet } from './ScopeRawSet'; | ||
import { RandomUtils } from './utils/random/RandomUtils'; | ||
import { NodeUtils } from './utils/node/NodeUtils'; | ||
import { Config } from './Config'; | ||
export var TargetNodeMode; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.RootScope = exports.TargetNode = exports.TargetNodeMode = void 0; | ||
var Scope_1 = require("./Scope"); | ||
var ScopePosition_1 = require("./ScopePosition"); | ||
var ScopeRawSet_1 = require("./ScopeRawSet"); | ||
var RandomUtils_1 = require("./utils/random/RandomUtils"); | ||
var NodeUtils_1 = require("./utils/node/NodeUtils"); | ||
var Config_1 = require("./Config"); | ||
var TargetNodeMode; | ||
(function (TargetNodeMode) { | ||
@@ -29,3 +32,3 @@ TargetNodeMode["child"] = "child"; | ||
TargetNodeMode["replace"] = "replace"; | ||
})(TargetNodeMode || (TargetNodeMode = {})); | ||
})(TargetNodeMode = exports.TargetNodeMode || (exports.TargetNodeMode = {})); | ||
var TargetNode = (function () { | ||
@@ -52,10 +55,10 @@ function TargetNode(_node, mode) { | ||
}()); | ||
export { TargetNode }; | ||
exports.TargetNode = TargetNode; | ||
var RootScope = (function (_super) { | ||
__extends(RootScope, _super); | ||
function RootScope(rawSet, obj, uuid, config, targetNode, position) { | ||
if (uuid === void 0) { uuid = RandomUtils.uuid(); } | ||
if (config === void 0) { config = new Config(); } | ||
if (uuid === void 0) { uuid = RandomUtils_1.RandomUtils.uuid(); } | ||
if (config === void 0) { config = new Config_1.Config(); } | ||
if (targetNode === void 0) { targetNode = new TargetNode(config.document); } | ||
if (position === void 0) { position = new ScopePosition(0, rawSet.raw.length); } | ||
if (position === void 0) { position = new ScopePosition_1.ScopePosition(0, rawSet.raw.length); } | ||
var _this = _super.call(this, rawSet.raw, obj, uuid, config, position) || this; | ||
@@ -70,7 +73,7 @@ _this.rawSet = rawSet; | ||
if (this.targetNode.node && TargetNodeMode.child === this.targetNode.mode) { | ||
NodeUtils.removeAllChildNode(this.targetNode.node); | ||
NodeUtils.appendChild(this.targetNode.node, fragment); | ||
NodeUtils_1.NodeUtils.removeAllChildNode(this.targetNode.node); | ||
NodeUtils_1.NodeUtils.appendChild(this.targetNode.node, fragment); | ||
} | ||
if (this.targetNode.node && TargetNodeMode.appendChild === this.targetNode.mode) { | ||
NodeUtils.appendChild(this.targetNode.node, fragment); | ||
NodeUtils_1.NodeUtils.appendChild(this.targetNode.node, fragment); | ||
} | ||
@@ -81,3 +84,3 @@ if (this.targetNode.node && TargetNodeMode.prepend === this.targetNode.mode) { | ||
else if (this.targetNode.node && TargetNodeMode.replace === this.targetNode.mode) { | ||
NodeUtils.replaceNode(this.targetNode.node, fragment); | ||
NodeUtils_1.NodeUtils.replaceNode(this.targetNode.node, fragment); | ||
} | ||
@@ -107,3 +110,3 @@ else { | ||
if (this.rawSet.styles.length > 0) { | ||
var styleScope = new RootScope(new ScopeRawSet(this.rawSet.styles.join(' ')), this.obj, RandomUtils.uuid(), this.config); | ||
var styleScope = new RootScope(new ScopeRawSet_1.ScopeRawSet(this.rawSet.styles.join(' ')), this.obj, RandomUtils_1.RandomUtils.uuid(), this.config); | ||
var styleFragment = styleScope.executeFragment(); | ||
@@ -142,3 +145,3 @@ styleScope.childs.forEach(function (it) { return _this.childs.push(it); }); | ||
return RootScope; | ||
}(Scope)); | ||
export { RootScope }; | ||
}(Scope_1.Scope)); | ||
exports.RootScope = RootScope; |
23
Scope.js
@@ -1,10 +0,13 @@ | ||
import { ScopeObject } from './ScopeObject'; | ||
import { ScopePosition } from './ScopePosition'; | ||
import { RandomUtils } from './utils/random/RandomUtils'; | ||
import { Config } from './Config'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Scope = void 0; | ||
var ScopeObject_1 = require("./ScopeObject"); | ||
var ScopePosition_1 = require("./ScopePosition"); | ||
var RandomUtils_1 = require("./utils/random/RandomUtils"); | ||
var Config_1 = require("./Config"); | ||
var Scope = (function () { | ||
function Scope(raws, obj, uuid, config, position) { | ||
if (uuid === void 0) { uuid = RandomUtils.uuid(); } | ||
if (config === void 0) { config = new Config(); } | ||
if (position === void 0) { position = new ScopePosition(0, raws.length); } | ||
if (uuid === void 0) { uuid = RandomUtils_1.RandomUtils.uuid(); } | ||
if (config === void 0) { config = new Config_1.Config(); } | ||
if (position === void 0) { position = new ScopePosition_1.ScopePosition(0, raws.length); } | ||
this.raws = raws; | ||
@@ -30,3 +33,3 @@ this.obj = obj; | ||
if (obj === void 0) { obj = this.obj; } | ||
var scopeObject = this.config.factoryScopeObject ? this.config.factoryScopeObject(this) : new ScopeObject(this.config); | ||
var scopeObject = this.config.factoryScopeObject ? this.config.factoryScopeObject(this) : new ScopeObject_1.ScopeObject(this.config); | ||
var object = Object.assign(scopeObject, obj); | ||
@@ -48,3 +51,3 @@ this.scopeResult = object.executeResultSet(this.raws); | ||
if (matchStart.length === matchEnd.length) { | ||
var scope = new Scope(sub.substring(this.config.start.length, sub.length - this.config.end.length), this.obj, RandomUtils.uuid(), this.config, new ScopePosition(startIdx, endIdx)); | ||
var scope = new Scope(sub.substring(this.config.start.length, sub.length - this.config.end.length), this.obj, RandomUtils_1.RandomUtils.uuid(), this.config, new ScopePosition_1.ScopePosition(startIdx, endIdx)); | ||
this.childs.push(scope); | ||
@@ -86,2 +89,2 @@ break; | ||
}()); | ||
export { Scope }; | ||
exports.Scope = Scope; |
@@ -1,6 +0,9 @@ | ||
import { ScopeResultSet } from './ScopeResultSet'; | ||
import { RandomUtils } from './utils/random/RandomUtils'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ScopeObject = void 0; | ||
var ScopeResultSet_1 = require("./ScopeResultSet"); | ||
var RandomUtils_1 = require("./utils/random/RandomUtils"); | ||
var ScopeObject = (function () { | ||
function ScopeObject(config, uuid) { | ||
if (uuid === void 0) { uuid = RandomUtils.uuid(); } | ||
if (uuid === void 0) { uuid = RandomUtils_1.RandomUtils.uuid(); } | ||
this.config = config; | ||
@@ -23,3 +26,3 @@ this.uuid = uuid; | ||
}); | ||
return new ScopeResultSet(this.uuid, this, templateElement.content, startComment, endComment, this.calls); | ||
return new ScopeResultSet_1.ScopeResultSet(this.uuid, this, templateElement.content, startComment, endComment, this.calls); | ||
}; | ||
@@ -40,2 +43,2 @@ ScopeObject.prototype.eval = function (str) { | ||
}()); | ||
export { ScopeObject }; | ||
exports.ScopeObject = ScopeObject; |
@@ -1,2 +0,5 @@ | ||
import { NodeUtils } from './utils/node/NodeUtils'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ScopeObjectProxyHandler = void 0; | ||
var NodeUtils_1 = require("./utils/node/NodeUtils"); | ||
var ScopeObjectProxyHandler = (function () { | ||
@@ -97,5 +100,5 @@ function ScopeObjectProxyHandler() { | ||
sit.exec(it.rootTargetOrigin); | ||
sit.scopeResult.childNodes.forEach(function (cit) { return NodeUtils.addNode(startComment_1, cit); }); | ||
NodeUtils.replaceNode(startComment_1, sit.scopeResult.startComment); | ||
NodeUtils.replaceNode(endComment, sit.scopeResult.endComment); | ||
sit.scopeResult.childNodes.forEach(function (cit) { return NodeUtils_1.NodeUtils.addNode(startComment_1, cit); }); | ||
NodeUtils_1.NodeUtils.replaceNode(startComment_1, sit.scopeResult.startComment); | ||
NodeUtils_1.NodeUtils.replaceNode(endComment, sit.scopeResult.endComment); | ||
} | ||
@@ -111,2 +114,2 @@ }); | ||
}()); | ||
export { ScopeObjectProxyHandler }; | ||
exports.ScopeObjectProxyHandler = ScopeObjectProxyHandler; |
@@ -0,1 +1,4 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ScopePosition = void 0; | ||
var ScopePosition = (function () { | ||
@@ -8,2 +11,2 @@ function ScopePosition(startIndex, endIndex) { | ||
}()); | ||
export { ScopePosition }; | ||
exports.ScopePosition = ScopePosition; |
@@ -0,1 +1,4 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ScopeRawSet = void 0; | ||
var ScopeRawSet = (function () { | ||
@@ -9,2 +12,2 @@ function ScopeRawSet(raw, styles) { | ||
}()); | ||
export { ScopeRawSet }; | ||
exports.ScopeRawSet = ScopeRawSet; |
@@ -0,1 +1,4 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ScopeResultSet = void 0; | ||
var ScopeResultSet = (function () { | ||
@@ -28,2 +31,2 @@ function ScopeResultSet(uuid, object, fragment, startComment, endComment, calls) { | ||
}()); | ||
export { ScopeResultSet }; | ||
exports.ScopeResultSet = ScopeResultSet; |
@@ -0,1 +1,4 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.DomUtils = void 0; | ||
var DomUtils = (function () { | ||
@@ -42,2 +45,2 @@ function DomUtils() { | ||
}()); | ||
export { DomUtils }; | ||
exports.DomUtils = DomUtils; |
@@ -0,1 +1,4 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.NodeUtils = void 0; | ||
var NodeUtils = (function () { | ||
@@ -22,2 +25,2 @@ function NodeUtils() { | ||
}()); | ||
export { NodeUtils }; | ||
exports.NodeUtils = NodeUtils; |
@@ -1,2 +0,5 @@ | ||
import { ValidUtils } from '../valid/ValidUtils'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.RandomUtils = void 0; | ||
var ValidUtils_1 = require("../valid/ValidUtils"); | ||
var RandomUtils = (function () { | ||
@@ -6,6 +9,6 @@ function RandomUtils() { | ||
RandomUtils.random = function (min, max) { | ||
if (ValidUtils.isNullOrUndefined(min)) { | ||
if (ValidUtils_1.ValidUtils.isNullOrUndefined(min)) { | ||
return Math.random(); | ||
} | ||
else if (!ValidUtils.isNullOrUndefined(min) && ValidUtils.isNullOrUndefined(max)) { | ||
else if (!ValidUtils_1.ValidUtils.isNullOrUndefined(min) && ValidUtils_1.ValidUtils.isNullOrUndefined(max)) { | ||
return Math.random() * (min || 0); | ||
@@ -44,2 +47,2 @@ } | ||
}()); | ||
export { RandomUtils }; | ||
exports.RandomUtils = RandomUtils; |
@@ -0,1 +1,4 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ValidUtils = void 0; | ||
var ValidUtils = (function () { | ||
@@ -70,2 +73,2 @@ function ValidUtils() { | ||
}()); | ||
export { ValidUtils }; | ||
exports.ValidUtils = ValidUtils; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
41810
927