1// Copyright (c) 2021-2025 GrayBits LLC 2 3export function createElement(tag, options = {}){ 4 let element = document.createElement(tag); 5 if (options.class){ 6 element.className = options.class.map((c) => { 7 if (typeof c == 'object'){ 8 return parseOptionalClasses(c); 9 } else { 10 return c; 11 } 12 }).join(' '); 13 } 14 if (options.id) element.setAttribute('id', options.id); 15 16 if (options.html) element.innerHTML = options.html; 17 18 if (options.nodrag){ 19 element.setAttribute('draggable', false); 20 element.addEventListener('dragstart', (e) => e.preventDefault()); 21 } 22 23 if (options.attr){ 24 for (const [attr, value] of Object.entries(options.attr)) element.setAttribute(attr, value); 25 } 26 27 if (options.data){ 28 for (const [key, value] of Object.entries(options.data)) element.dataset[key] = value; 29 } 30 31 if (options.children){ 32 options.children.forEach((child) => { if (child) element.append(child); }); 33 } 34 35 if (options.listeners){ 36 for (const [event, listener] of Object.entries(options.listeners)) element.addEventListener(event, listener); 37 } 38 39 return element; 40} 41 42function parseOptionalClasses(c){ 43 let classes = []; 44 for (const [class_name, condition] of Object.entries(c)) if (condition) classes.push(class_name); 45 return classes.join(' '); 46} 47 48export function createFromHTML(html){ 49 let wrapper = document.createElement('div'); 50 wrapper.innerHTML = html.trim(); 51 52 return wrapper.firstChild; 53} 54 55export function clone(element){ 56 return createFromHTML(element.outerHTML); 57} 58 59export function insertAfter(element, insertion){ 60 element.parentNode.insertBefore(insertion, element.nextSibling); 61} 62 63export function insertBefore(element, insertion){ 64 element.parentNode.insertBefore(insertion, element); 65};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.