(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'], factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.riotDOMBindings = {})); })(this, (function (exports) { 'use strict'; /** * Convert a string from camel case to dash-case * @param {string} string - probably a component tag name * @returns {string} component name normalized */ /** * Convert a string containing dashes to camel case * @param {string} string - input string * @returns {string} my-string -> myString */ function dashToCamelCase(string) { return string.replace(/-(\w)/g, (_, c) => c.toUpperCase()) } /** * Move all the child nodes from a source tag to another * @param {HTMLElement} source - source node * @param {HTMLElement} target - target node * @returns {undefined} it's a void method ¯\_(ツ)_/¯ */ // Ignore this helper because it's needed only for svg tags function moveChildren(source, target) { // eslint-disable-next-line fp/no-loops while (source.firstChild) target.appendChild(source.firstChild); } /** * Remove the child nodes from any DOM node * @param {HTMLElement} node - target node * @returns {undefined} */ function cleanNode(node) { // eslint-disable-next-line fp/no-loops while (node.firstChild) node.removeChild(node.firstChild); } /** * Clear multiple children in a node * @param {HTMLElement[]} children - direct children nodes * @returns {undefined} */ function clearChildren(children) { // eslint-disable-next-line fp/no-loops,fp/no-let for (let i = 0; i < children.length; i++) removeChild(children[i]); } /** * Remove a node * @param {HTMLElement}node - node to remove * @returns {undefined} */ const removeChild = (node) => node.remove(); /** * Insert before a node * @param {HTMLElement} newNode - node to insert * @param {HTMLElement} refNode - ref child * @returns {undefined} */ const insertBefore = (newNode, refNode) => refNode && refNode.parentNode && refNode.parentNode.insertBefore(newNode, refNode); /** * Replace a node * @param {HTMLElement} newNode - new node to add to the DOM * @param {HTMLElement} replaced - node to replace * @returns {undefined} */ const replaceChild = (newNode, replaced) => replaced && replaced.parentNode && replaced.parentNode.replaceChild(newNode, replaced); // Riot.js constants that can be used across more modules const IS_PURE_SYMBOL = Symbol('pure'), PARENT_KEY_SYMBOL = Symbol('parent'); const EACH = 0; const IF = 1; const SIMPLE = 2; const TAG = 3; const SLOT = 4; const bindingTypes = { EACH, IF, SIMPLE, TAG, SLOT, }; const ATTRIBUTE = 0; const EVENT = 1; const TEXT = 2; const VALUE = 3; const expressionTypes = { ATTRIBUTE, EVENT, TEXT, VALUE, }; /** * Quick type checking * @param {*} element - anything * @param {string} type - type definition * @returns {boolean} true if the type corresponds */ function checkType(element, type) { return typeof element === type } /** * Check if an element is part of an svg * @param {HTMLElement} el - element to check * @returns {boolean} true if we are in an svg context */ function isSvg(el) { const owner = el.ownerSVGElement; return !!owner || owner === null } /** * Check if an element is a template tag * @param {HTMLElement} el - element to check * @returns {boolean} true if it's a