Path: blob/main/static/script/component.js
917 views
/**1* Incognito2*3* This program is free software: you can redistribute it and/or modify4* it under the terms of the GNU General Public License as published by5* the Free Software Foundation, either version 3 of the License, or6* (at your option) any later version.7*8* This program is distributed in the hope that it will be useful,9* but WITHOUT ANY WARRANTY; without even the implied warranty of10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the11* GNU General Public License for more details.12*13* You should have received a copy of the GNU General Public License14* along with this program. If not, see <https://www.gnu.org/licenses/>.15*/1617/*18_____ _ _ _19| __ \ | | | | | |20| |__) | ___ _ __ | |_ ___ __| | | |__ _ _21| ___/ / _ \ | '__| | __| / _ \ / _` | | '_ \ | | | |22| | | (_) | | | | |_ | __/ | (_| | | |_) | | |_| |23|_| \___/ |_| \__| \___| \__,_| |_.__/ \__, |24__/ |25|___/26_ _ _ _ _ _ _27/\ | | | | | | | \ | | | | | |28/ \ _ __ ___ ___ | |_ | |__ _ _ ___ | |_ | \| | ___ | |_ __ __ ___ _ __ | | __29/ /\ \ | '_ ` _ \ / _ \ | __| | '_ \ | | | | / __| | __| | . ` | / _ \ | __| \ \ /\ / / / _ \ | '__| | |/ /30/ ____ \ | | | | | | | __/ | |_ | | | | | |_| | \__ \ | |_ | |\ | | __/ | |_ \ V V / | (_) | | | | <31/_/ \_\ |_| |_| |_| \___| \__| |_| |_| \__, | |___/ \__| |_| \_| \___| \__| \_/\_/ \___/ |_| |_|\_\32__/ |33|___/34*/35function createComponent(element) {36return new Proxy({}, {37get: (target, prop) => {38if (prop === 'target') return element;39if (prop === 'text') return element.textContent;40if (prop === 'style') return element.style;41if (prop === 'clear') return clear;4243return target[prop];44},45set: (target, prop, val) => {46if (prop === 'text') return (element.textContent = val, true);47if (typeof val === 'string') val = document.createElement(val);4849if (prop in target) {50target[prop].remove();51delete target[prop];52};5354element.append(val);55target[prop] = val5657return true;58},59deleteProperty: (target, prop) => {60target[prop].remove();61return delete target[prop];62},63});6465function clear() {66this.text = '';67for (const key in this) {68delete this[key];69};70};71};7273export { createComponent };7475