UNPKG

@easylogic/editor

Version:

Fantastic Web Design Tool

1,841 lines 2.22 MB
var __defProp = Object.defineProperty; var __defProps = Object.defineProperties; var __getOwnPropDescs = Object.getOwnPropertyDescriptors; var __getOwnPropSymbols = Object.getOwnPropertySymbols; var __hasOwnProp = Object.prototype.hasOwnProperty; var __propIsEnum = Object.prototype.propertyIsEnumerable; var __defNormalProp = (obj2, key, value) => key in obj2 ? __defProp(obj2, key, { enumerable: true, configurable: true, writable: true, value }) : obj2[key] = value; var __spreadValues = (a, b) => { for (var prop in b || (b = {})) if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]); if (__getOwnPropSymbols) for (var prop of __getOwnPropSymbols(b)) { if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]); } return a; }; var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b)); var __accessCheck = (obj2, member, msg) => { if (!member.has(obj2)) throw TypeError("Cannot " + msg); }; var __privateGet = (obj2, member, getter) => { __accessCheck(obj2, member, "read from private field"); return getter ? getter.call(obj2) : member.get(obj2); }; var __privateAdd = (obj2, member, value) => { if (member.has(obj2)) throw TypeError("Cannot add the same private member more than once"); member instanceof WeakSet ? member.add(obj2) : member.set(obj2, value); }; var __privateSet = (obj2, member, value, setter) => { __accessCheck(obj2, member, "write to private field"); setter ? setter.call(obj2, value) : member.set(obj2, value); return value; }; var __privateWrapper = (obj2, member, setter, getter) => { return { set _(value) { __privateSet(obj2, member, value, setter); }, get _() { return __privateGet(obj2, member, getter); } }; }; var __privateMethod = (obj2, member, method) => { __accessCheck(obj2, member, "access private method"); return method; }; var _state, _prevState, _localTimestamp, _loadMethods, _timestamp, _cachedMethodList, _props, _propsKeys, _isServer, _propsKeyList, _refreshTimestamp, refreshTimestamp_fn, _setProps, setProps_fn, _getProp, getProp_fn, _storeInstance, _modelManager, _json, _cachedValue, _timestamp2, _lastChangedField, _collapsed, _compiledTimeline, _id, _renderers; function collectProps(root, filterFunction = () => true) { let p = root; let results = []; do { const isObject2 = p instanceof Object; if (isObject2 === false) { break; } const names2 = Object.getOwnPropertyNames(p).filter(filterFunction); results.push.apply(results, names2); } while (p = Object.getPrototypeOf(p)); return results; } function debounce(callback, delay = 0) { if (delay === 0) { return callback; } var t = void 0; return function($1, $2, $3, $4, $5) { if (t) { window.clearTimeout(t); } t = window.setTimeout(function() { callback($1, $2, $3, $4, $5); }, delay || 300); }; } function throttle(callback, delay) { var t = void 0; return function($1, $2, $3, $4, $5) { if (!t) { t = window.setTimeout(function() { callback($1, $2, $3, $4, $5); t = null; }, delay || 300); } }; } function ifCheck(callback, context, checkMethods) { return (...args2) => { const ifResult = checkMethods.every((check2) => { return context[check2].apply(context, args2); }); if (ifResult) { callback.apply(context, args2); } }; } function makeRequestAnimationFrame(callback, context) { return (...args2) => { window.requestAnimationFrame(() => { callback.apply(context, args2); }); }; } function keyEach(obj2, callback) { Object.keys(obj2).forEach((key, index2) => { callback(key, obj2[key], index2); }); } function keyMap(obj2, callback) { return Object.keys(obj2).map((key, index2) => { return callback(key, obj2[key], index2); }); } function keyMapJoin(obj2, callback, joinString = "") { return keyMap(obj2, callback).join(joinString); } function get(obj2, key, callback) { var returnValue = defaultValue(obj2[key], key); if (isFunction(callback)) { return callback(returnValue); } return returnValue; } function defaultValue(value, defaultValue2) { return typeof value == "undefined" ? defaultValue2 : value; } function isUndefined(value) { return typeof value == "undefined"; } function isNotUndefined(value) { return !isUndefined(value); } function isBoolean(value) { return typeof value == "boolean"; } function isString(value) { return typeof value == "string"; } function isNotString(value) { return !isString(value); } function isArray(value) { return Array.isArray(value); } function isObject(value) { return typeof value == "object" && !Array.isArray(value) && !isNumber(value) && !isString(value) && value !== null; } function isFunction(value) { return typeof value == "function"; } function isNumber(value) { return typeof value == "number"; } function isZero(num) { return num === 0; } function isNotZero(num) { return !isZero(num); } const CLONE_FUNCTION = (obj2) => JSON.parse(JSON.stringify(obj2)); function clone$1(obj2) { if (isUndefined(obj2)) return void 0; return CLONE_FUNCTION(obj2); } function combineKeyArray(obj2) { Object.keys(obj2).forEach((key) => { if (Array.isArray(obj2[key])) { obj2[key] = obj2[key].join(", "); } }); return obj2; } function classnames(...args2) { const result = []; args2.filter(Boolean).forEach((it) => { if (isArray(it)) { result.push(classnames(...it)); } else if (isObject(it)) { Object.keys(it).filter((k) => Boolean(it[k])).forEach((key) => { result.push(key); }); } else if (isString(it)) { result.push(it); } }); return result.join(" "); } const setBooleanProp = (el, name, value) => { if (value) { el.setAttribute(name, name); el[name] = value; } else { el.removeAttribute(name); el[name] = value; } }; const setProp = (el, name, value) => { if (typeof value === "boolean") { setBooleanProp(el, name, value); } else { el.setAttribute(name, value); } }; const removeBooleanProp = (node, name) => { node.removeAttribute(name); node[name] = false; }; const removeUndefinedProp = (node, name) => { node.removeAttribute(name); }; const removeProp = (node, name, value) => { if (typeof value === "boolean") { removeBooleanProp(node, name); } else if (name) { removeUndefinedProp(node, name); } }; const updateProp = (node, name, newValue, oldValue) => { if (!newValue) { removeProp(node, name, oldValue); } else if (!oldValue || newValue !== oldValue) { setProp(node, name, newValue); } else ; }; const updateProps = (node, newProps = {}, oldProps = {}) => { const keyList2 = []; keyList2.push.apply(keyList2, Object.keys(newProps)); keyList2.push.apply(keyList2, Object.keys(oldProps)); const props = new Set(keyList2); props.forEach((key) => { updateProp(node, key, newProps[key], oldProps[key]); }); }; function changed(node1, node2) { return node1.nodeType === window.Node.TEXT_NODE && node1.textContent !== node2.textContent || node1.nodeName !== node2.nodeName; } function hasPassed(node1) { if ((node1 == null ? void 0 : node1.nodeType) === 8) { return true; } return node1.nodeType !== window.Node.TEXT_NODE && node1.getAttribute("data-domdiff-pass") === "true"; } function hasRefClass(node1) { return node1.nodeType !== window.Node.TEXT_NODE && node1.getAttribute("refClass"); } function getProps(attributes) { var results = {}; const len2 = attributes.length; for (let i = 0; i < len2; i++) { const t = attributes[i]; results[t.name] = t.value; } return results; } function checkAllHTML(newEl, oldEl) { return newEl.outerHTML == oldEl.outerHTML; } function updateElement(parentElement, oldEl, newEl, i, options2 = {}) { if (!oldEl) { parentElement.appendChild(newEl.cloneNode(true)); } else if (!newEl) { parentElement.removeChild(oldEl); } else if (hasPassed(oldEl) || hasPassed(newEl)) ; else if (checkAllHTML(newEl, oldEl)) { return; } else if (changed(newEl, oldEl) || hasRefClass(newEl)) { parentElement.replaceChild(newEl.cloneNode(true), oldEl); } else if (newEl.nodeType !== window.Node.TEXT_NODE && newEl.nodeType !== window.Node.COMMENT_NODE && newEl.toString() !== "[object HTMLUnknownElement]") { if (options2.checkPassed && options2.checkPassed(oldEl, newEl)) ; else { updateProps(oldEl, getProps(newEl.attributes), getProps(oldEl.attributes)); } var oldChildren = children(oldEl); var newChildren = children(newEl); var max = Math.max(oldChildren.length, newChildren.length); for (var index2 = 0; index2 < max; index2++) { updateElement(oldEl, oldChildren[index2], newChildren[index2], index2, options2); } } } const children = (el) => { var element = el.firstChild; if (!element) { return []; } var results = []; do { results.push(element); element = element.nextSibling; } while (element); return results; }; function DomDiff(A, B, options2 = {}) { options2.checkPassed = isFunction(options2.checkPassed) ? options2.checkPassed : void 0; options2.removedElements = []; A = A.el || A; B = B.el || B; var childrenA = children(A); var childrenB = children(B); var len2 = Math.max(childrenA.length, childrenB.length); if (len2 === 0) { return; } if (childrenA.length === 0 && childrenB.length > 0) { A.append(...childrenB); } else if (childrenA.length > 0 && childrenB.length === 0) { A.textContent = ""; } else { for (var i = 0; i < len2; i++) { updateElement(A, childrenA[i], childrenB[i], i, options2); } } } const UUID_REG$1 = /[xy]/g; function uuid$1() { var dt = new Date().getTime(); var uuid2 = "xxx12-xx-34xx".replace(UUID_REG$1, function(c2) { var r = (dt + Math.random() * 16) % 16 | 0; dt = Math.floor(dt / 16); return (c2 == "x" ? r : r & 3 | 8).toString(16); }); return uuid2; } function uuidShort$1() { var dt = new Date().getTime(); var uuid2 = "idxxxxxxx".replace(UUID_REG$1, function(c2) { var r = (dt + Math.random() * 16) % 16 | 0; dt = Math.floor(dt / 16); return (c2 == "x" ? r : r & 3 | 8).toString(16); }); return uuid2; } const map = {}; const handlerMap = {}; const aliasMap = {}; const __rootInstance = /* @__PURE__ */ new Set(); const __tempVariables = /* @__PURE__ */ new Map(); const __tempVariablesGroup = /* @__PURE__ */ new Map(); const VARIABLE_SAPARATOR = "v:"; function variable$4(value, groupId = "") { const id = `${VARIABLE_SAPARATOR}${uuidShort$1()}`; __tempVariables.set(id, value); if (groupId) { __tempVariablesGroup.has(groupId) || __tempVariablesGroup.set(groupId, /* @__PURE__ */ new Set()); __tempVariablesGroup.get(groupId).add(id); } return id; } function initializeGroupVariables(groupId) { if (__tempVariablesGroup.has(groupId)) { __tempVariablesGroup.get(groupId).forEach((id) => { __tempVariables.delete(id); }); __tempVariablesGroup.delete(groupId); } } function recoverVariable(id, removeVariable = true) { if (isString(id) === false) { return id; } let value = id; if (__tempVariables.has(id)) { value = __tempVariables.get(id); if (removeVariable) { __tempVariables.delete(id); } } return value; } function getVariable(idOrValue) { if (__tempVariables.has(idOrValue)) { return __tempVariables.get(idOrValue); } return idOrValue; } function hasVariable(id) { return __tempVariables.has(id); } function spreadVariable(obj2) { return Object.entries(obj2).map(([key, value]) => { return `${key}=${variable$4(value)}`; }).join(" "); } function registElement(classes = {}) { Object.keys(classes).forEach((key) => { map[key] = classes[key]; }); } function replaceElement(module) { if (map[module.name]) { map[module.name] = module; } } function registAlias(a, b) { aliasMap[a] = b; } function retriveAlias(key) { return aliasMap[key]; } function retriveElement(className) { return map[retriveAlias(className) || className]; } function registRootElementInstance(instance) { __rootInstance.add(instance); } function getRootElementInstanceList() { return [...__rootInstance]; } function renderRootElementInstance(module) { replaceElement(module); getRootElementInstanceList().forEach((instance) => { instance.hmr(); }); } function registHandler(handlers) { Object.keys(handlers).forEach((key) => { handlerMap[key] = handlers[key]; }); } function retriveHandler(className) { return handlerMap[className]; } function createHandlerInstance(context) { return Object.keys(handlerMap).filter((key) => Boolean(handlerMap[key])).map((key) => { const HandlerClass = handlerMap[key]; return new HandlerClass(context); }); } class Dom { constructor(tag, className, attr) { if (typeof tag !== "string") { if (tag instanceof Dom) { this.el = tag.el; } else { this.el = tag; } } else { var el = document.createElement(tag); if (className) { el.className = className; } attr = attr || {}; Object.assign(el, attr); this.el = el; } } static create(tag, className, attr) { return new Dom(tag, className, attr); } static createByHTML(htmlString) { var div2 = Dom.create("div"); return div2.html(htmlString).firstChild; } static makeElementList(html) { const TEMP_DIV2 = Dom.create("div"); let list2 = []; if (!isArray(html)) { html = [html]; } html = html.filter(Boolean); for (let i = 0, len2 = html.length; i < len2; i++) { const item = html[i]; if (isString(item)) { list2.push(...TEMP_DIV2.html(item == null ? void 0 : item.trim()).childNodes || []); } else if (item) { list2.push(Dom.create(item)); } else ; } return list2; } static getScrollTop() { return Math.max(window.pageYOffset, document.documentElement.scrollTop, document.body.scrollTop); } static getScrollLeft() { return Math.max(window.pageXOffset, document.documentElement.scrollLeft, document.body.scrollLeft); } static parse(html) { var parser = window.DOMParser(); return parser.parseFromString(html, "text/htmll"); } static body() { return Dom.create(document.body); } get exists() { return Boolean(this.el); } setAttr(obj2) { Object.keys(obj2).forEach((key) => { this.attr(key, obj2[key]); }); return this; } setAttrNS(obj2, namespace = "http://www.w3.org/2000/svg") { Object.keys(obj2).forEach((key) => { this.attr(key, obj2[key], namespace); }); return this; } setProp(obj2) { Object.keys(obj2).forEach((key) => { if (this.el[key] != obj2[key]) { this.el[key] = obj2[key]; } }); return this; } data(key, value) { if (arguments.length === 1) { const value2 = this.attr("data-" + key); return recoverVariable(value2, false); } else if (arguments.length === 2) { return this.attr("data-" + key, value); } return this; } attr(...args2) { if (args2.length == 1) { return isFunction(this.el.getAttribute) && this.el.getAttribute(args2[0]); } if (this.el.getAttribute(args2[0]) != args2[1]) { this.el.setAttribute(args2[0], args2[1]); } return this; } attrNS(key, value, namespace = "http://www.w3.org/2000/svg") { if (arguments.length == 1) { return this.el.getAttributeNS(namespace, key); } if (this.el.getAttributeNS(namespace, key) != value) { this.el.setAttributeNS(namespace, key, value); } return this; } attrKeyValue(keyField) { return { [this.el.getAttribute(keyField)]: this.val() }; } get attributes() { try { [...this.el.attributes]; return this.el.attributes; } catch (e) { const length2 = this.el.attributes.length; const attributes = []; for (var i = 0; i < length2; i++) { attributes.push(this.el.attributes[`${i}`]); } return attributes; } } attrs(...args2) { return args2.map((key) => { return this.el.getAttribute(key); }); } styles(...args2) { return args2.map((key) => { return this.el.style[key]; }); } removeAttr(key) { this.el.removeAttribute(key); return this; } removeStyle(key) { this.el.style.removeProperty(key); return this; } is(checkElement) { if (checkElement instanceof Dom) { return this.el === checkElement.el; } return this.el === checkElement; } isTag(tag) { return this.el.tagName.toLowerCase() === tag.toLowerCase(); } closest(cls) { var temp = this; var checkCls = false; while (!(checkCls = temp.hasClass(cls))) { if (temp.el.parentNode) { temp = Dom.create(temp.el.parentNode); } else { return null; } } if (checkCls) { return temp; } return null; } path() { if (!this.el) return []; let pathList = [this]; let $parentNode = this.parent(); if (!$parentNode.el) return pathList; while ($parentNode) { pathList.unshift($parentNode); $parentNode = $parentNode.parent(); if (!$parentNode.el) break; } return pathList; } get $parent() { return this.parent(); } parent() { return Dom.create(this.el.parentNode); } hasParent() { return !!this.el.parentNode; } removeClass(...args2) { this.el.classList.remove(...args2); return this; } updateClass(className) { this.el.className = className; return this; } replaceClass(oldClass, newClass) { this.el.classList.replace(oldClass, newClass); return this; } hasClass(cls) { if (!this.el.classList) return false; return this.el.classList.contains(cls); } addClass(...args2) { this.el.classList.add(...args2); return this; } onlyOneClass(cls) { var parent = this.parent(); parent.children().forEach((it) => { it.removeClass(cls); }); this.addClass(cls); } toggleClass(cls, isForce) { this.el.classList.toggle(cls, isForce); return this; } outerHTML() { if (this.isTextNode) { return this.text(); } return this.el.outerHTML; } html(html) { try { if (typeof html === "undefined") { return this.el.innerHTML; } if (typeof html === "string") { Object.assign(this.el, { innerHTML: html }); } else { this.empty().append(html); } return this; } catch (e) { console.log(e, html); return this; } } htmlDiff(fragment) { DomDiff(this, fragment); } updateDiff(html, rootElement = "div", options2 = {}) { DomDiff(this, Dom.create(rootElement).html(html), options2); } updateSVGDiff(html, rootElement = "div") { DomDiff(this, Dom.create(rootElement).html(`<svg>${html}</svg>`).firstChild.firstChild); } getById(id) { return this.el.getElementById(id); } find(selector2) { if (this.isTextNode) return void 0; return this.el.querySelector(selector2); } $(selector2) { var node = this.find(selector2); return node ? Dom.create(node) : null; } findAll(selector2) { if (this.isTextNode) return []; return Array.from(this.el.querySelectorAll(selector2)); } $$(selector2) { var arr = this.findAll(selector2); return arr.map((node) => Dom.create(node)); } empty() { while (this.el.firstChild) this.el.removeChild(this.el.firstChild); return this; } append(el) { if (!el) return this; if (isArray(el)) { this.el.append(...el.map((it) => it.el || it)); } else if (typeof el === "string") { this.el.appendChild(document.createTextNode(el)); } else { this.el.appendChild(el.el || el); } return this; } prepend(el) { if (typeof el === "string") { this.el.prepend(document.createTextNode(el)); } else { this.el.prepend(el.el || el); } return this; } prependHTML(html) { var $dom = Dom.create("div").html(html); this.prepend($dom.createChildrenFragment()); return $dom; } appendHTML(html) { var $dom = Dom.create("div").html(html); this.append($dom.createChildrenFragment()); return $dom; } createChildrenFragment() { const list2 = this.childNodes; var fragment = document.createDocumentFragment(); list2.forEach(($el) => fragment.appendChild($el.el)); return fragment; } appendTo(target) { var t = target.el ? target.el : target; t.appendChild(this.el); return this; } remove() { if (this.el.parentNode) { this.el.parentNode.removeChild(this.el); } return this; } removeChild(el) { this.el.removeChild(el.el || el); return this; } text(value) { if (typeof value === "undefined") { return this.el.textContent; } else { var tempText = value; if (value instanceof Dom) { tempText = value.text(); } if (this.el.textContent !== tempText) { this.el.textContent = tempText; } return this; } } css(key, value) { if (typeof key !== "undefined" && typeof value !== "undefined") { if (key.indexOf("--") === 0 && typeof value !== "undefined") { this.el.style.setProperty(key, value); } else { this.el.style[key] = value; } } else if (typeof key !== "undefined") { if (typeof key === "string") { return window.getComputedStyle(this.el)[key]; } else { Object.entries(key).forEach(([localKey, value2]) => { if (localKey.indexOf("--") === 0 && typeof value2 !== "undefined") { this.el.style.setProperty(localKey, value2); } else { this.el.style[localKey] = value2; } }); } } return this; } getComputedStyle(...list2) { var css = window.getComputedStyle(this.el); var obj2 = {}; list2.forEach((it) => { obj2[it] = css[it]; }); return obj2; } getStyleList(...list2) { var style = {}; var len2 = this.el.style.length; for (var i = 0; i < len2; i++) { var key = this.el.style[i]; style[key] = this.el.style[key]; } list2.forEach((key2) => { style[key2] = this.css(key2); }); return style; } cssText(value) { if (typeof value === "undefined") { return this.el.style.cssText; } if (value != this.el.tempCssText) { this.el.style.cssText = value; this.el.tempCssText = value; } return this; } cssArray(arr) { if (arr[0]) this.el.style[arr[0]] = arr[1]; if (arr[2]) this.el.style[arr[2]] = arr[3]; if (arr[4]) this.el.style[arr[4]] = arr[5]; if (arr[6]) this.el.style[arr[6]] = arr[7]; if (arr[8]) this.el.style[arr[8]] = arr[9]; return this; } cssFloat(key) { return parseFloat(this.css(key)); } cssInt(key) { return parseInt(this.css(key)); } px(key, value) { return this.css(key, `${value}px`); } rect() { return this.el.getBoundingClientRect(); } bbox() { return this.el.getBBox(); } isSVG() { if (!this.el._cachedIsSVG) { this.el._cachedIsSVG = { value: this.el.tagName.toLowerCase() === "svg" }; } return this.el._cachedIsSVG.value; } offsetRect() { if (this.isSVG()) { const parentBox = this.parent().rect(); const box = this.rect(); return { x: box.x - parentBox.x, y: box.y - parentBox.y, width: box.width, height: box.height }; } const el = this.el; return { x: el.offsetLeft, y: el.offsetTop, width: el.offsetWidth, height: el.offsetHeight }; } offsetClientRect() { if (this.isSVG()) { const parentBox2 = this.parent().rect(); const box2 = this.rect(); return { x: box2.x - parentBox2.x, y: box2.y - parentBox2.y, width: box2.width, height: box2.height }; } const parentBox = this.parent().rect(); const box = this.rect(); return { x: box.x - parentBox.x, y: box.y - parentBox.y, width: box.width, height: box.height }; } offset() { var rect2 = this.rect(); var scrollTop = Dom.getScrollTop(); var scrollLeft = Dom.getScrollLeft(); return { top: rect2.top + scrollTop, left: rect2.left + scrollLeft }; } offsetLeft() { return this.offset().left; } offsetTop() { return this.offset().top; } position() { if (this.el.style.top) { return { top: parseFloat(this.css("top")), left: parseFloat(this.css("left")) }; } else { return this.rect(); } } size() { return [this.width(), this.height()]; } width() { return this.el.offsetWidth || this.rect().width; } contentWidth() { return this.width() - this.cssFloat("padding-left") - this.cssFloat("padding-right"); } height() { return this.el.offsetHeight || this.rect().height; } contentHeight() { return this.height() - this.cssFloat("padding-top") - this.cssFloat("padding-bottom"); } val(value) { if (typeof value === "undefined") { return this.el.value; } else if (typeof value !== "undefined") { var tempValue = value; if (value instanceof Dom) { tempValue = value.val(); } this.el.value = tempValue; } return this; } matches(selector2) { if (this.el) { if (!this.el.matches) return null; if (this.el.matches(selector2)) { return this; } return this.parent().matches(selector2); } return null; } get value() { return this.el.value; } get naturalWidth() { return this.el.naturalWidth; } get naturalHeight() { return this.el.naturalHeight; } get files() { return this.el.files ? [...this.el.files] : []; } get isTextNode() { return this.el.nodeType === 3; } realVal() { switch (this.el.nodeType) { case "INPUT": var type = this.attr("type"); if (type == "checkbox" || type == "radio") { return this.checked(); } return this.el.value; case "SELECT": case "TEXTAREA": return this.el.value; } return ""; } int() { return parseInt(this.val(), 10); } float() { return parseFloat(this.val()); } show(displayType = "block") { this.el.style.display = displayType != "none" ? displayType : "block"; return this; } hide() { this.el.style.display = "none"; return this; } isHide() { return this.el.style.display === "none"; } isShow() { return !this.isHide(); } toggle(isForce) { var currentHide = this.isHide(); if (arguments.length == 1) { if (isForce) { return this.show(); } else { return this.hide(); } } else { if (currentHide) { return this.show(); } else { return this.hide(); } } } get totalLength() { return this.el.getTotalLength(); } scrollIntoView() { this.el.scrollIntoView(); } addScrollLeft(dt) { this.el.scrollLeft += dt; return this; } addScrollTop(dt) { this.el.scrollTop += dt; return this; } setScrollTop(scrollTop) { this.el.scrollTop = scrollTop; return this; } setScrollLeft(scrollLeft) { this.el.scrollLeft = scrollLeft; return this; } scrollTop() { if (this.el === document.body) { return Dom.getScrollTop(); } return this.el.scrollTop; } scrollLeft() { if (this.el === document.body) { return Dom.getScrollLeft(); } return this.el.scrollLeft; } scrollHeight() { return this.el.scrollHeight; } scrollWidth() { return this.el.scrollWidth; } on(eventName, callback, opt1, opt2) { this.el.addEventListener(eventName, callback, opt1, opt2); return this; } off(eventName, callback) { this.el.removeEventListener(eventName, callback); return this; } getElement() { return this.el; } createChild(tag, className = "", attrs = {}, css = {}) { let $element = Dom.create(tag, className, attrs); $element.css(css); this.append($element); return $element; } get firstChild() { return Dom.create(this.el.firstElementChild); } get first() { return Dom.create(this.el.firstChild); } children() { var element = this.el.firstElementChild; if (!element) { return []; } var results = []; do { results.push(Dom.create(element)); element = element.nextElementSibling; } while (element); return results; } get childNodes() { const result = []; if (this.el.hasChildNodes()) { const childNodes = this.el.childNodes; for (let i = 0; i < childNodes.length; i++) { result.push(Dom.create(childNodes[i])); } } return result; } childLength() { return this.el.children.length; } replace(newElement) { if (this.el.parentNode) { this.el.parentNode.replaceChild(newElement.el || newElement, this.el); } return this; } replaceChild(oldElement, newElement) { this.el.replaceChild(newElement.el || newElement, oldElement.el || oldElement); return this; } checked(isChecked = false) { if (arguments.length == 0) { return !!this.el.checked; } this.el.checked = !!isChecked; return this; } click() { this.el.click(); return this; } focus() { this.el.focus(); return this; } select() { if (this.attr("contenteditable") === "true") { var range = document.createRange(); range.selectNodeContents(this.el); var sel = window.getSelection(); sel.removeAllRanges(); sel.addRange(range); } else { this.el.select(); } return this; } blur() { this.el.blur(); return this; } context(contextType = "2d") { if (!this._initContext) { this._initContext = this.el.getContext(contextType); } return this._initContext; } resize({ width: width2, height: height2 }) { this._initContext = null; var ctx = this.context(); var scale2 = window.devicePixelRatio || 1; this.px("width", +width2); this.px("height", +height2); this.el.width = width2 * scale2; this.el.height = height2 * scale2; ctx.scale(scale2, scale2); } toDataURL(type = "image/png", quality = 1) { return this.el.toDataURL(type, quality); } clear() { this.context().clearRect(0, 0, this.el.width, this.el.height); } update(callback) { this.clear(); callback.call(this, this); } drawImage(img, dx = 0, dy = 0) { var ctx = this.context(); var scale2 = window.devicePixelRatio || 1; ctx.drawImage(img, dx, dy, img.width, img.height, 0, 0, this.el.width / scale2, this.el.height / scale2); } drawOption(option = {}) { var ctx = this.context(); Object.assign(ctx, option); } drawLine(x1, y1, x2, y2) { var ctx = this.context(); ctx.beginPath(); ctx.moveTo(x1, y1); ctx.lineTo(x2, y2); ctx.stroke(); ctx.closePath(); } drawPath(...path) { var ctx = this.context(); ctx.beginPath(); path.forEach((p, index2) => { if (index2 == 0) { ctx.moveTo(p[0], p[1]); } else { ctx.lineTo(p[0], p[1]); } }); ctx.stroke(); ctx.fill(); ctx.closePath(); } drawCircle(cx, cy, r) { var ctx = this.context(); ctx.beginPath(); ctx.arc(cx, cy, r, 0, 2 * Math.PI); ctx.stroke(); ctx.fill(); } drawText(x, y, text2) { this.context().fillText(text2, x, y); } fullscreen() { var element = this.el; if (element.requestFullscreen) { element.requestFullscreen(); } else if (element.wekitRequestFullscreen) { element.wekitRequestFullscreen(); } } toggleFullscreen() { if (this.el === document.fullscreenElement) { document.exitFullscreen(); } else { this.fullscreen(); } } } class BaseStore { constructor(editor) { this.id = uuidShort$1(); this.cachedCallback = {}; this.callbacks = {}; this.editor = editor; } getCallbacks(event) { if (!this.callbacks[event]) { this.callbacks[event] = []; } return this.callbacks[event]; } setCallbacks(event, list2 = []) { this.callbacks[event] = list2; } debug(...args2) { if (this.editor && this.editor.context.config.get("debug.mode")) { console.debug(...args2); } } on(event, originalCallback, context, debounceDelay = 0, throttleDelay = 0, enableAllTrigger = false, enableSelfTrigger = false, beforeMethods = [], frame = false) { var callback = originalCallback; if (debounceDelay > 0) callback = debounce(originalCallback, debounceDelay); else if (throttleDelay > 0) callback = throttle(originalCallback, throttleDelay); if (beforeMethods.length) { callback = ifCheck(callback, context, beforeMethods); } if (frame) { callback = makeRequestAnimationFrame(callback, context); } this.getCallbacks(event).push({ event, callback, context, originalCallback, enableAllTrigger, enableSelfTrigger }); return () => { this.off(event, originalCallback); }; } off(event, originalCallback) { this.debug("off message event", event); if (arguments.length == 1) { this.setCallbacks(event); } else if (arguments.length == 2) { this.setCallbacks(event, this.getCallbacks(event).filter((f) => { return f.originalCallback !== originalCallback; })); } } offAll(context) { Object.keys(this.callbacks).forEach((event) => { this.setCallbacks(event, this.getCallbacks(event).filter((f) => { return f.context !== context; })); }); this.debug("off all message", context.sourceName); } getCachedCallbacks(event) { return this.getCallbacks(event); } sendMessage(source2, event, ...args2) { this.sendMessageList(source2, [[event, ...args2]]); } runMessage(runnableFunction, args2) { const result = runnableFunction.callback.apply(runnableFunction.context, args2); if (isNotUndefined(result)) { if (result === false) { return; } else if (isFunction(result)) { result(); return; } } } sendMessageList(source2, messages = []) { window.Promise.resolve().then(() => { messages.forEach(([event, ...args2]) => { var list2 = this.getCachedCallbacks(event); if (list2 && list2.length) { const runnableFunctions = list2.filter((f) => !f.enableSelfTrigger).filter((f) => f.enableAllTrigger || f.originalCallback.source !== source2); let i = runnableFunctions.length; while (i--) { const f = runnableFunctions[i]; this.runMessage(f, args2); } } else { this.debug(`message event ${event} is not exist.`); } }); }); } nextSendMessage(source2, callback, ...args2) { window.Promise.resolve().then(() => { callback(...args2); }); } triggerMessage(source2, event, ...args2) { window.Promise.resolve().then(() => { var list2 = this.getCachedCallbacks(event); if (list2) { const runnableFunctions = list2.filter((f) => f.originalCallback.source === source2); runnableFunctions.forEach((f) => { f.callback.apply(f.context, args2); }); } else { this.debug(event, " is not valid event"); } }); } emit(event, ...args2) { if (isFunction(event)) { event(...args2); } else if (isArray(event)) { this.sendMessageList(this.source, event); } else { this.sendMessage(this.source, event, ...args2); } } nextTick(callback) { this.nextSendMessage(this.source, callback); } trigger(event, ...args2) { if (isFunction(event)) { event(...args2); } else { this.triggerMessage(this.source, event, ...args2); } } } const MAGIC_METHOD_REG = /^@magic:([a-zA-Z][a-zA-Z0-9]*)[\W]{1}(.*)*$/g; const MAGIC_METHOD = "@magic:"; const SPLITTER = "|"; const FUNC_REGEXP = /(([\$a-z_\-]+)\([^\(\)]*\)|([a-z_\-]+))/gi; const FUNC_START_CHARACTER = "("; const FUNC_END_CHARACTER = ")"; const MAGICMETHOD_EXTRA = { KEYWORD: "keyword", FUNCTION: "function", VALUE: "value" }; class MagicMethod { constructor(obj2) { this.context = obj2.context; this.originalMethod = obj2.originalMethod; this.method = obj2.method; this.args = obj2.args; this.pipes = obj2.pipes; this.keys = obj2.keys; this.__cache = /* @__PURE__ */ new Map(); } setCache(key, value) { this.__cache.set(key, value); } hasCache(key) { return this.__cache.has(key); } getCache(key) { return this.__cache.get(key); } hasKeyword(keyword) { if (this.hasCache(keyword)) { return this.getCache(keyword); } let exists = false; this.pipes.forEach((pipe) => { switch (pipe.type) { case MAGICMETHOD_EXTRA.KEYWORD: if (pipe.value === keyword) { exists = true; } break; } }); this.setCache(keyword, exists); return exists; } hasFunction(funcName) { if (this.hasCache(funcName)) { return this.getCache(funcName); } let exists = !!this.getFunction(funcName); this.setCache(funcName, exists); return exists; } getFunction(funcName) { return this.functions.find((pipe) => pipe.func === funcName); } getFunctionList(funcName) { return this.functions.filter((pipe) => pipe.func === funcName); } get originalCallback() { return this.context[this.originalMethod]; } get keywords() { return this.keys[MAGICMETHOD_EXTRA.KEYWORD].map((pipe) => pipe.value); } get functions() { return this.keys[MAGICMETHOD_EXTRA.FUNCTION]; } get values() { return this.keys[MAGICMETHOD_EXTRA.VALUE].map((pipe) => pipe.value); } execute(...args2) { return this.originalCallback.call(this.context, ...args2); } executeWithContext(context, ...args2) { return this.originalCallback.call(context, ...args2); } static make(str, ...args2) { return `${MAGIC_METHOD}${str} ${args2.join(SPLITTER)}`; } static check(str) { return str.match(MAGIC_METHOD_REG) !== null; } static parse(str, context = {}) { const matches2 = str.match(MAGIC_METHOD_REG); if (!matches2) { return void 0; } const result = matches2[0].split(MAGIC_METHOD)[1].split(SPLITTER).map((item) => item.trim()); let [initializer, ...pipes] = result; const [method, ...args2] = initializer.split(" "); const pipeList = pipes.map((it) => { return this.parsePipe(it); }).filter((it) => it.value); const pipeObjects = { function: [], keyword: [], value: [] }; pipeList.forEach((pipe) => { if (pipe.type === "function") { pipeObjects.function.push(pipe); } else if (pipe.type === "keyword") { pipeObjects.keyword.push(pipe); } else { pipeObjects.value.push(pipe); } }); return new MagicMethod({ context, originalMethod: str, method, args: args2, pipes: pipeList, keys: pipeObjects }); } static parsePipe(it) { const result = it.match(FUNC_REGEXP); if (!result) { return { type: "value", value: it }; } const [value] = result; if (value.includes(FUNC_START_CHARACTER)) { const [func, rest] = value.split(FUNC_START_CHARACTER); const [args2] = rest.split(FUNC_END_CHARACTER); return { type: "function", value, func, args: args2.split(",").map((it2) => it2.trim()).filter(Boolean) }; } return { type: "keyword", value: result[0] }; } } const makeEventChecker = (value, split = SPLITTER) => { return ` ${split} ${value}`; }; const MULTI_PREFIX = "ME@"; const PIPE = (...args2) => { return args2.join(SPLITTER); }; const EVENT = (...args2) => { return MULTI_PREFIX + PIPE(...args2); }; const COMMAND = EVENT; const ON = EVENT; const NAME_SAPARATOR = ":"; const SAPARATOR = " "; const refManager = {}; const DOM_EVENT_MAKE = (...keys2) => { var key = keys2.join(NAME_SAPARATOR); return (...args2) => { const [selector2, ...result] = args2; return MagicMethod.make("domevent", [key, selector2].join(" "), ...result); }; }; const SUBSCRIBE_EVENT_MAKE = (...args2) => { return MagicMethod.make("subscribe", ...args2); }; const CALLBACK_EVENT_MAKE = (...args2) => { return MagicMethod.make("callback", ...args2); }; const OBSERVER_EVENT_MAKE = (...args2) => { return MagicMethod.make("observer", ...args2); }; const CHECKER = (value, split = SPLITTER) => { return makeEventChecker(value, split); }; const AFTER = (value, split = SPLITTER) => { return CHECKER(`after(${value})`, split); }; const BEFORE = (value, split = SPLITTER) => { return CHECKER(`before(${value})`, split); }; const IF = CHECKER; const KEY = CHECKER; const ARROW_UP = CHECKER("ArrowUp"); const ARROW_DOWN = CHECKER("ArrowDown"); const ARROW_LEFT = CHECKER("ArrowLeft"); const ARROW_RIGHT = CHECKER("ArrowRight"); const ENTER = CHECKER("Enter"); const SPACE = CHECKER("Space"); const ESCAPE = CHECKER("Escape"); const BACKSPACE = CHECKER("Backspace"); const DELETE = CHECKER("Delete"); const EQUAL = CHECKER("Equal"); const MINUS = CHECKER("Minus"); const BRACKET_RIGHT = CHECKER("BracketRight"); const BRACKET_LEFT = CHECKER("BracketLeft"); const ALT = CHECKER("isAltKey"); const SHIFT = CHECKER("isShiftKey"); const META = CHECKER("isMetaKey"); const CONTROL = CHECKER("isCtrlKey"); const MOUSE = CHECKER("hasMouse"); const TOUCH = CHECKER("hasTouch"); const PEN = CHECKER("hasPen"); const SELF = CHECKER("self"); const LEFT_BUTTON = CHECKER("isMouseLeftButton"); const RIGHT_BUTTON = CHECKER("isMouseRightButton"); const FIT = CHECKER("fit"); const PASSIVE = CHECKER("passive"); const DOMDIFF = CHECKER("domdiff"); const DEBOUNCE = (t = 100) => { return CHECKER(`debounce(${t})`); }; const DELAY = (t = 300) => { return CHECKER(`delay(${t})`); }; const D1000 = DEBOUNCE(1e3); const THROTTLE = (t = 100) => { return CHECKER(`throttle(${t})`); }; const ALL_TRIGGER = CHECKER("allTrigger()"); const SELF_TRIGGER = CHECKER("selfTrigger()"); const FRAME = CHECKER("frame()"); const PARAMS = (obj2) => { return CHECKER(`params(${variable$4(obj2)})`); }; const CAPTURE = CHECKER("capture()"); const PREVENT = AFTER(`preventDefault`); const STOP = AFTER(`stopPropagation`); const SUBSCRIBE = SUBSCRIBE_EVENT_MAKE; const SUBSCRIBE_ALL = (...args2) => SUBSCRIBE_EVENT_MAKE(...args2, ALL_TRIGGER); const SUBSCRIBE_SELF = (...args2) => SUBSCRIBE_EVENT_MAKE(...args2, SELF_TRIGGER); const CONFIG = (config, ...args2) => SUBSCRIBE_EVENT_MAKE(`config:${config}`, ...args2); const CALLBACK = CALLBACK_EVENT_MAKE; const RAF = CALLBACK("requestAnimationFrame"); const OBSERVER = OBSERVER_EVENT_MAKE; const CUSTOM = DOM_EVENT_MAKE; const CLICK = DOM_EVENT_MAKE("click"); const DOUBLECLICK = DOM_EVENT_MAKE("dblclick"); const MOUSEDOWN = DOM_EVENT_MAKE("mousedown"); const MOUSEUP = DOM_EVENT_MAKE("mouseup"); const MOUSEMOVE = DOM_EVENT_MAKE("mousemove"); const MOUSEOVER = DOM_EVENT_MAKE("mouseover"); const MOUSEOUT = DOM_EVENT_MAKE("mouseout"); const MOUSEENTER = DOM_EVENT_MAKE("mouseenter"); const MOUSELEAVE = DOM_EVENT_MAKE("mouseleave"); const TOUCHSTART = DOM_EVENT_MAKE("touchstart"); const TOUCHMOVE = DOM_EVENT_MAKE("touchmove"); const TOUCHEND = DOM_EVENT_MAKE("touchend"); const KEYDOWN = DOM_EVENT_MAKE("keydown"); const KEYUP = DOM_EVENT_MAKE("keyup"); const KEYPRESS = DOM_EVENT_MAKE("keypress"); const DRAG = DOM_EVENT_MAKE("drag"); const DRAGSTART = DOM_EVENT_MAKE("dragstart"); const DROP = DOM_EVENT_MAKE("drop"); const DRAGOVER = DOM_EVENT_MAKE("dragover"); const DRAGENTER = DOM_EVENT_MAKE("dragenter"); const DRAGLEAVE = DOM_EVENT_MAKE("dragleave"); const DRAGEXIT = DOM_EVENT_MAKE("dragexit"); const DRAGOUT = DOM_EVENT_MAKE("dragout"); const DRAGEND = DOM_EVENT_MAKE("dragend"); const CONTEXTMENU = DOM_EVENT_MAKE("contextmenu"); const CHANGE = DOM_EVENT_MAKE("change"); const INPUT = DOM_EVENT_MAKE("input"); const FOCUS = DOM_EVENT_MAKE("focus"); const FOCUSIN = DOM_EVENT_MAKE("focusin"); const FOCUSOUT = DOM_EVENT_MAKE("focusout"); const BLUR = DOM_EVENT_MAKE("blur"); const PASTE = DOM_EVENT_MAKE("paste"); const RESIZE = DOM_EVENT_MAKE("resize"); const SCROLL = DOM_EVENT_MAKE("scroll"); const SUBMIT = DOM_EVENT_MAKE("submit"); const POINTERSTART = (...args2) => { return CUSTOM("pointerdown")(...args2) + LEFT_BUTTON; }; const POINTEROVER = CUSTOM("pointerover"); const POINTERENTER = CUSTOM("pointerenter"); const POINTEROUT = CUSTOM("pointerout"); const POINTERMOVE = CUSTOM("pointermove"); const POINTEREND = CUSTOM("pointerup"); const CHANGEINPUT = CUSTOM("change", "input"); const WHEEL = CUSTOM("wheel", "mousewheel", "DOMMouseScroll"); const ANIMATIONSTART = DOM_EVENT_MAKE("animationstart"); const ANIMATIONEND = DOM_EVENT_MAKE("animationend"); const ANIMATIONITERATION = DOM_EVENT_MAKE("animationiteration"); const TRANSITIONSTART = DOM_EVENT_MAKE("transitionstart"); const TRANSITIONEND = DOM_EVENT_MAKE("transitionend"); const TRANSITIONRUN = DOM_EVENT_MAKE("transitionrun"); const TRANSITIONCANCEL = DOM_EVENT_MAKE("transitioncancel"); const DOUBLETAB = CUSTOM("doubletab"); const LOAD = (value = "$el") => { return MagicMethod.make("load", value); }; const getRef = (id) => { return refManager[id] || ""; }; const BIND_CHECK_FUNCTION = (field) => { return function() { return this.prevState[field] != this.state[field]; }; }; const BIND_CHECK_DEFAULT_FUNCTION = () => { return true; }; const BIND = (value = "$el") => { return MagicMethod.make("bind", value); }; function normalizeWheelEvent(e) { let dx = e.deltaX; let dy = e.deltaY; if (dx === 0 && e.shiftKey) { [dy, dx] = [dx, dy]; } if (e.deltaMode === window.WheelEvent.DOM_DELTA_LINE) { dy *= 8; } else if (e.deltaMode === window.WheelEvent.DOM_DELTA_PAGE) { dy *= 24; } return [limit(dx, 24), limit(dy, 24), 0]; } function limit(delta, maxDelta) { return Math.sign(delta) * Math.min(maxDelta, Math.abs(delta)); } var Event = { addDomEvent(dom, eventName, callback, useCapture = false) { if (dom) { dom.addEventListener(eventName, callback, useCapture); } }, removeDomEvent(dom, eventName, callback) { if (dom) { dom.removeEventListener(eventName, callback); } }, pos(e) { if (e.touches && e.touches[0]) { return e.touches[0]; } return e; }, posXY(e) { var pos = this.pos(e); return { x: pos.pageX, y: pos.pageY }; } }; class BaseHandler { constructor(context, options2 = {}) { this.context = context; this.options = options2; } initialize() { } load() { } refresh() { } render() { } getRef(id) { return this.context.getRef(id); } run() { } destroy() { } } const convertToPx = (key, value) => { if (isNumber(value)) { switch (key) { case "width": case "height": case "top": case "left": case "right": case "bottom": return value + "px"; } } return value; }; const applyElementAttribute = ($element, key, value, hasStyleAttribute = false) => { if (key === "cssText") { $element.cssText(value); return; } else if (key === "style") { if (typeof value !== "string") { const css = {}; Object.entries(value).forEach(([key2, value2]) => { css[key2] = convertToPx(key2, value2); }); if (hasStyleAttribute) { const styleText = Object.keys(css).map((key2) => { return `${key2}:${css[key2]};`; }).join(""); $element.attr("style", styleText); } else { $element.css(css); } } return; } else if (key === "class") { if (Array.isArray(value)) { $element.updateClass(classnames(...value)); } else { $element.updateClass(classnames(value)); } return; } else if (key === "callback") { if (typeof value === "function") { value(); return; } } if (typeof value === "undefined") { $element.removeAttr(key); } else { if ($element.el.nodeName === "TEXTAREA" && key === "value") { $element.text(value); } else if (key === "text" || key === "textContent") { $element.text(value); } else if (key === "innerHTML" || key === "html") { $element.html(value); } else if (key === "htmlDiff") { $element.updateDiff(value); } else if (key === "svgDiff") { $element.updateSVGDiff(value); } else if (key === "value") { $element.val(value); } else { $element.attr(key, value); } } }; const FunctionMap = {}; class BindHandler extends BaseHandler { async initialize() { if (!FunctionMap[this.context.sourceName]) { FunctionMap[this.context.sourceName] = this.context.filterMethodes("bind"); } } getBindMethods() { return FunctionMap[this.context.sourceName] || []; } async bindData(...args2) { const list2 = this.getBindMethods(); if (!(list2 == null ? void 0 : list2.length)) return; const bindList = list2 == null ? void 0 : list2.filter((it) => { if (!args2.length) return true; return args2.indexOf(it.args[0]) > -1; }); await Promise.all(bindList == null ? void 0 : bindList.map(async (magicMethod) => { let refObject = this.getRef(`${magicMethod.keywords[0]}`); let refCallback = BIND_CHECK_DEFAULT_FUNCTION; if (typeof ref