UNPKG

tinymce

Version:

Web based JavaScript HTML WYSIWYG editor control.

1,560 lines (1,508 loc) 290 kB
/** * TinyMCE version 6.0.1 (2022-03-23) */ (function () { 'use strict'; var global$1 = tinymce.util.Tools.resolve('tinymce.ModelManager'); const hasProto = (v, constructor, predicate) => { var _a; if (predicate(v, constructor.prototype)) { return true; } else { return ((_a = v.constructor) === null || _a === void 0 ? void 0 : _a.name) === constructor.name; } }; const typeOf = x => { const t = typeof x; if (x === null) { return 'null'; } else if (t === 'object' && Array.isArray(x)) { return 'array'; } else if (t === 'object' && hasProto(x, String, (o, proto) => proto.isPrototypeOf(o))) { return 'string'; } else { return t; } }; const isType$1 = type => value => typeOf(value) === type; const isSimpleType = type => value => typeof value === type; const eq$2 = t => a => t === a; const isString = isType$1('string'); const isObject = isType$1('object'); const isArray = isType$1('array'); const isNull = eq$2(null); const isBoolean = isSimpleType('boolean'); const isNullable = a => a === null || a === undefined; const isNonNullable = a => !isNullable(a); const isFunction = isSimpleType('function'); const isNumber = isSimpleType('number'); const noop = () => { }; const compose = (fa, fb) => { return (...args) => { return fa(fb.apply(null, args)); }; }; const compose1 = (fbc, fab) => a => fbc(fab(a)); const constant = value => { return () => { return value; }; }; const identity = x => { return x; }; const tripleEquals = (a, b) => { return a === b; }; function curry(fn, ...initialArgs) { return (...restArgs) => { const all = initialArgs.concat(restArgs); return fn.apply(null, all); }; } const not = f => t => !f(t); const die = msg => { return () => { throw new Error(msg); }; }; const apply = f => { return f(); }; const never = constant(false); const always = constant(true); class Optional { constructor(tag, value) { this.tag = tag; this.value = value; } static some(value) { return new Optional(true, value); } static none() { return Optional.singletonNone; } fold(onNone, onSome) { if (this.tag) { return onSome(this.value); } else { return onNone(); } } isSome() { return this.tag; } isNone() { return !this.tag; } map(mapper) { if (this.tag) { return Optional.some(mapper(this.value)); } else { return Optional.none(); } } bind(binder) { if (this.tag) { return binder(this.value); } else { return Optional.none(); } } exists(predicate) { return this.tag && predicate(this.value); } forall(predicate) { return !this.tag || predicate(this.value); } filter(predicate) { if (!this.tag || predicate(this.value)) { return this; } else { return Optional.none(); } } getOr(replacement) { return this.tag ? this.value : replacement; } or(replacement) { return this.tag ? this : replacement; } getOrThunk(thunk) { return this.tag ? this.value : thunk(); } orThunk(thunk) { return this.tag ? this : thunk(); } getOrDie(message) { if (!this.tag) { throw new Error(message !== null && message !== void 0 ? message : 'Called getOrDie on None'); } else { return this.value; } } static from(value) { return isNonNullable(value) ? Optional.some(value) : Optional.none(); } getOrNull() { return this.tag ? this.value : null; } getOrUndefined() { return this.value; } each(worker) { if (this.tag) { worker(this.value); } } toArray() { return this.tag ? [this.value] : []; } toString() { return this.tag ? `some(${ this.value })` : 'none()'; } } Optional.singletonNone = new Optional(false); const nativeSlice = Array.prototype.slice; const nativeIndexOf = Array.prototype.indexOf; const nativePush = Array.prototype.push; const rawIndexOf = (ts, t) => nativeIndexOf.call(ts, t); const contains$2 = (xs, x) => rawIndexOf(xs, x) > -1; const exists = (xs, pred) => { for (let i = 0, len = xs.length; i < len; i++) { const x = xs[i]; if (pred(x, i)) { return true; } } return false; }; const range$1 = (num, f) => { const r = []; for (let i = 0; i < num; i++) { r.push(f(i)); } return r; }; const map$1 = (xs, f) => { const len = xs.length; const r = new Array(len); for (let i = 0; i < len; i++) { const x = xs[i]; r[i] = f(x, i); } return r; }; const each$2 = (xs, f) => { for (let i = 0, len = xs.length; i < len; i++) { const x = xs[i]; f(x, i); } }; const eachr = (xs, f) => { for (let i = xs.length - 1; i >= 0; i--) { const x = xs[i]; f(x, i); } }; const partition = (xs, pred) => { const pass = []; const fail = []; for (let i = 0, len = xs.length; i < len; i++) { const x = xs[i]; const arr = pred(x, i) ? pass : fail; arr.push(x); } return { pass, fail }; }; const filter$2 = (xs, pred) => { const r = []; for (let i = 0, len = xs.length; i < len; i++) { const x = xs[i]; if (pred(x, i)) { r.push(x); } } return r; }; const foldr = (xs, f, acc) => { eachr(xs, (x, i) => { acc = f(acc, x, i); }); return acc; }; const foldl = (xs, f, acc) => { each$2(xs, (x, i) => { acc = f(acc, x, i); }); return acc; }; const findUntil = (xs, pred, until) => { for (let i = 0, len = xs.length; i < len; i++) { const x = xs[i]; if (pred(x, i)) { return Optional.some(x); } else if (until(x, i)) { break; } } return Optional.none(); }; const find$1 = (xs, pred) => { return findUntil(xs, pred, never); }; const findIndex = (xs, pred) => { for (let i = 0, len = xs.length; i < len; i++) { const x = xs[i]; if (pred(x, i)) { return Optional.some(i); } } return Optional.none(); }; const flatten = xs => { const r = []; for (let i = 0, len = xs.length; i < len; ++i) { if (!isArray(xs[i])) { throw new Error('Arr.flatten item ' + i + ' was not an array, input: ' + xs); } nativePush.apply(r, xs[i]); } return r; }; const bind$2 = (xs, f) => flatten(map$1(xs, f)); const forall = (xs, pred) => { for (let i = 0, len = xs.length; i < len; ++i) { const x = xs[i]; if (pred(x, i) !== true) { return false; } } return true; }; const reverse = xs => { const r = nativeSlice.call(xs, 0); r.reverse(); return r; }; const mapToObject = (xs, f) => { const r = {}; for (let i = 0, len = xs.length; i < len; i++) { const x = xs[i]; r[String(x)] = f(x, i); } return r; }; const sort$1 = (xs, comparator) => { const copy = nativeSlice.call(xs, 0); copy.sort(comparator); return copy; }; const get$d = (xs, i) => i >= 0 && i < xs.length ? Optional.some(xs[i]) : Optional.none(); const head = xs => get$d(xs, 0); const last$2 = xs => get$d(xs, xs.length - 1); const findMap = (arr, f) => { for (let i = 0; i < arr.length; i++) { const r = f(arr[i], i); if (r.isSome()) { return r; } } return Optional.none(); }; const keys = Object.keys; const hasOwnProperty = Object.hasOwnProperty; const each$1 = (obj, f) => { const props = keys(obj); for (let k = 0, len = props.length; k < len; k++) { const i = props[k]; const x = obj[i]; f(x, i); } }; const map = (obj, f) => { return tupleMap(obj, (x, i) => ({ k: i, v: f(x, i) })); }; const tupleMap = (obj, f) => { const r = {}; each$1(obj, (x, i) => { const tuple = f(x, i); r[tuple.k] = tuple.v; }); return r; }; const objAcc = r => (x, i) => { r[i] = x; }; const internalFilter = (obj, pred, onTrue, onFalse) => { const r = {}; each$1(obj, (x, i) => { (pred(x, i) ? onTrue : onFalse)(x, i); }); return r; }; const filter$1 = (obj, pred) => { const t = {}; internalFilter(obj, pred, objAcc(t), noop); return t; }; const mapToArray = (obj, f) => { const r = []; each$1(obj, (value, name) => { r.push(f(value, name)); }); return r; }; const values = obj => { return mapToArray(obj, identity); }; const get$c = (obj, key) => { return has$1(obj, key) ? Optional.from(obj[key]) : Optional.none(); }; const has$1 = (obj, key) => hasOwnProperty.call(obj, key); const hasNonNullableKey = (obj, key) => has$1(obj, key) && obj[key] !== undefined && obj[key] !== null; const isEmpty = r => { for (const x in r) { if (hasOwnProperty.call(r, x)) { return false; } } return true; }; typeof window !== 'undefined' ? window : Function('return this;')(); const COMMENT = 8; const DOCUMENT = 9; const DOCUMENT_FRAGMENT = 11; const ELEMENT = 1; const TEXT = 3; const name = element => { const r = element.dom.nodeName; return r.toLowerCase(); }; const type = element => element.dom.nodeType; const isType = t => element => type(element) === t; const isComment = element => type(element) === COMMENT || name(element) === '#comment'; const isElement = isType(ELEMENT); const isText = isType(TEXT); const isDocument = isType(DOCUMENT); const isDocumentFragment = isType(DOCUMENT_FRAGMENT); const isTag = tag => e => isElement(e) && name(e) === tag; const rawSet = (dom, key, value) => { if (isString(value) || isBoolean(value) || isNumber(value)) { dom.setAttribute(key, value + ''); } else { console.error('Invalid call to Attribute.set. Key ', key, ':: Value ', value, ':: Element ', dom); throw new Error('Attribute value was not simple'); } }; const set$2 = (element, key, value) => { rawSet(element.dom, key, value); }; const setAll$1 = (element, attrs) => { const dom = element.dom; each$1(attrs, (v, k) => { rawSet(dom, k, v); }); }; const setOptions = (element, attrs) => { each$1(attrs, (v, k) => { v.fold(() => { remove$7(element, k); }, value => { rawSet(element.dom, k, value); }); }); }; const get$b = (element, key) => { const v = element.dom.getAttribute(key); return v === null ? undefined : v; }; const getOpt = (element, key) => Optional.from(get$b(element, key)); const remove$7 = (element, key) => { element.dom.removeAttribute(key); }; const clone$2 = element => foldl(element.dom.attributes, (acc, attr) => { acc[attr.name] = attr.value; return acc; }, {}); const fromHtml$1 = (html, scope) => { const doc = scope || document; const div = doc.createElement('div'); div.innerHTML = html; if (!div.hasChildNodes() || div.childNodes.length > 1) { const message = 'HTML does not have a single root node'; console.error(message, html); throw new Error(message); } return fromDom$1(div.childNodes[0]); }; const fromTag = (tag, scope) => { const doc = scope || document; const node = doc.createElement(tag); return fromDom$1(node); }; const fromText = (text, scope) => { const doc = scope || document; const node = doc.createTextNode(text); return fromDom$1(node); }; const fromDom$1 = node => { if (node === null || node === undefined) { throw new Error('Node cannot be null or undefined'); } return { dom: node }; }; const fromPoint$1 = (docElm, x, y) => Optional.from(docElm.dom.elementFromPoint(x, y)).map(fromDom$1); const SugarElement = { fromHtml: fromHtml$1, fromTag, fromText, fromDom: fromDom$1, fromPoint: fromPoint$1 }; const is$2 = (element, selector) => { const dom = element.dom; if (dom.nodeType !== ELEMENT) { return false; } else { const elem = dom; if (elem.matches !== undefined) { return elem.matches(selector); } else if (elem.msMatchesSelector !== undefined) { return elem.msMatchesSelector(selector); } else if (elem.webkitMatchesSelector !== undefined) { return elem.webkitMatchesSelector(selector); } else if (elem.mozMatchesSelector !== undefined) { return elem.mozMatchesSelector(selector); } else { throw new Error('Browser lacks native selectors'); } } }; const bypassSelector = dom => dom.nodeType !== ELEMENT && dom.nodeType !== DOCUMENT && dom.nodeType !== DOCUMENT_FRAGMENT || dom.childElementCount === 0; const all$1 = (selector, scope) => { const base = scope === undefined ? document : scope.dom; return bypassSelector(base) ? [] : map$1(base.querySelectorAll(selector), SugarElement.fromDom); }; const one = (selector, scope) => { const base = scope === undefined ? document : scope.dom; return bypassSelector(base) ? Optional.none() : Optional.from(base.querySelector(selector)).map(SugarElement.fromDom); }; const eq$1 = (e1, e2) => e1.dom === e2.dom; const contains$1 = (e1, e2) => { const d1 = e1.dom; const d2 = e2.dom; return d1 === d2 ? false : d1.contains(d2); }; const is$1 = is$2; const owner = element => SugarElement.fromDom(element.dom.ownerDocument); const documentOrOwner = dos => isDocument(dos) ? dos : owner(dos); const documentElement = element => SugarElement.fromDom(documentOrOwner(element).dom.documentElement); const defaultView = element => SugarElement.fromDom(documentOrOwner(element).dom.defaultView); const parent = element => Optional.from(element.dom.parentNode).map(SugarElement.fromDom); const parentElement = element => Optional.from(element.dom.parentElement).map(SugarElement.fromDom); const parents = (element, isRoot) => { const stop = isFunction(isRoot) ? isRoot : never; let dom = element.dom; const ret = []; while (dom.parentNode !== null && dom.parentNode !== undefined) { const rawParent = dom.parentNode; const p = SugarElement.fromDom(rawParent); ret.push(p); if (stop(p) === true) { break; } else { dom = rawParent; } } return ret; }; const prevSibling = element => Optional.from(element.dom.previousSibling).map(SugarElement.fromDom); const nextSibling = element => Optional.from(element.dom.nextSibling).map(SugarElement.fromDom); const children$2 = element => map$1(element.dom.childNodes, SugarElement.fromDom); const child$2 = (element, index) => { const cs = element.dom.childNodes; return Optional.from(cs[index]).map(SugarElement.fromDom); }; const firstChild = element => child$2(element, 0); const before$3 = (marker, element) => { const parent$1 = parent(marker); parent$1.each(v => { v.dom.insertBefore(element.dom, marker.dom); }); }; const after$5 = (marker, element) => { const sibling = nextSibling(marker); sibling.fold(() => { const parent$1 = parent(marker); parent$1.each(v => { append$1(v, element); }); }, v => { before$3(v, element); }); }; const prepend = (parent, element) => { const firstChild$1 = firstChild(parent); firstChild$1.fold(() => { append$1(parent, element); }, v => { parent.dom.insertBefore(element.dom, v.dom); }); }; const append$1 = (parent, element) => { parent.dom.appendChild(element.dom); }; const appendAt = (parent, element, index) => { child$2(parent, index).fold(() => { append$1(parent, element); }, v => { before$3(v, element); }); }; const wrap = (element, wrapper) => { before$3(element, wrapper); append$1(wrapper, element); }; const after$4 = (marker, elements) => { each$2(elements, (x, i) => { const e = i === 0 ? marker : elements[i - 1]; after$5(e, x); }); }; const append = (parent, elements) => { each$2(elements, x => { append$1(parent, x); }); }; const empty = element => { element.dom.textContent = ''; each$2(children$2(element), rogue => { remove$6(rogue); }); }; const remove$6 = element => { const dom = element.dom; if (dom.parentNode !== null) { dom.parentNode.removeChild(dom); } }; const unwrap = wrapper => { const children = children$2(wrapper); if (children.length > 0) { after$4(wrapper, children); } remove$6(wrapper); }; const clone$1 = (original, isDeep) => SugarElement.fromDom(original.dom.cloneNode(isDeep)); const shallow = original => clone$1(original, false); const deep = original => clone$1(original, true); const shallowAs = (original, tag) => { const nu = SugarElement.fromTag(tag); const attributes = clone$2(original); setAll$1(nu, attributes); return nu; }; const copy$2 = (original, tag) => { const nu = shallowAs(original, tag); const cloneChildren = children$2(deep(original)); append(nu, cloneChildren); return nu; }; const mutate$1 = (original, tag) => { const nu = shallowAs(original, tag); after$5(original, nu); const children = children$2(original); append(nu, children); remove$6(original); return nu; }; const validSectionList = [ 'tfoot', 'thead', 'tbody', 'colgroup' ]; const isValidSection = parentName => contains$2(validSectionList, parentName); const grid = (rows, columns) => ({ rows, columns }); const address = (row, column) => ({ row, column }); const detail = (element, rowspan, colspan) => ({ element, rowspan, colspan }); const detailnew = (element, rowspan, colspan, isNew) => ({ element, rowspan, colspan, isNew }); const extended = (element, rowspan, colspan, row, column, isLocked) => ({ element, rowspan, colspan, row, column, isLocked }); const rowdetail = (element, cells, section) => ({ element, cells, section }); const rowdetailnew = (element, cells, section, isNew) => ({ element, cells, section, isNew }); const elementnew = (element, isNew, isLocked) => ({ element, isNew, isLocked }); const rowcells = (element, cells, section, isNew) => ({ element, cells, section, isNew }); const bounds = (startRow, startCol, finishRow, finishCol) => ({ startRow, startCol, finishRow, finishCol }); const columnext = (element, colspan, column) => ({ element, colspan, column }); const colgroup = (element, columns) => ({ element, columns }); const isShadowRoot = dos => isDocumentFragment(dos) && isNonNullable(dos.dom.host); const supported = isFunction(Element.prototype.attachShadow) && isFunction(Node.prototype.getRootNode); const isSupported$1 = constant(supported); const getRootNode = supported ? e => SugarElement.fromDom(e.dom.getRootNode()) : documentOrOwner; const getShadowRoot = e => { const r = getRootNode(e); return isShadowRoot(r) ? Optional.some(r) : Optional.none(); }; const getShadowHost = e => SugarElement.fromDom(e.dom.host); const getOriginalEventTarget = event => { if (isSupported$1() && isNonNullable(event.target)) { const el = SugarElement.fromDom(event.target); if (isElement(el) && isOpenShadowHost(el)) { if (event.composed && event.composedPath) { const composedPath = event.composedPath(); if (composedPath) { return head(composedPath); } } } } return Optional.from(event.target); }; const isOpenShadowHost = element => isNonNullable(element.dom.shadowRoot); const inBody = element => { const dom = isText(element) ? element.dom.parentNode : element.dom; if (dom === undefined || dom === null || dom.ownerDocument === null) { return false; } const doc = dom.ownerDocument; return getShadowRoot(SugarElement.fromDom(dom)).fold(() => doc.body.contains(dom), compose1(inBody, getShadowHost)); }; const body$1 = () => getBody$1(SugarElement.fromDom(document)); const getBody$1 = doc => { const b = doc.dom.body; if (b === null || b === undefined) { throw new Error('Body is not available yet'); } return SugarElement.fromDom(b); }; const ancestors$4 = (scope, predicate, isRoot) => filter$2(parents(scope, isRoot), predicate); const children$1 = (scope, predicate) => filter$2(children$2(scope), predicate); const descendants$1 = (scope, predicate) => { let result = []; each$2(children$2(scope), x => { if (predicate(x)) { result = result.concat([x]); } result = result.concat(descendants$1(x, predicate)); }); return result; }; const ancestors$3 = (scope, selector, isRoot) => ancestors$4(scope, e => is$2(e, selector), isRoot); const children = (scope, selector) => children$1(scope, e => is$2(e, selector)); const descendants = (scope, selector) => all$1(selector, scope); var ClosestOrAncestor = (is, ancestor, scope, a, isRoot) => { if (is(scope, a)) { return Optional.some(scope); } else if (isFunction(isRoot) && isRoot(scope)) { return Optional.none(); } else { return ancestor(scope, a, isRoot); } }; const ancestor$2 = (scope, predicate, isRoot) => { let element = scope.dom; const stop = isFunction(isRoot) ? isRoot : never; while (element.parentNode) { element = element.parentNode; const el = SugarElement.fromDom(element); if (predicate(el)) { return Optional.some(el); } else if (stop(el)) { break; } } return Optional.none(); }; const closest$2 = (scope, predicate, isRoot) => { const is = (s, test) => test(s); return ClosestOrAncestor(is, ancestor$2, scope, predicate, isRoot); }; const child$1 = (scope, predicate) => { const pred = node => predicate(SugarElement.fromDom(node)); const result = find$1(scope.dom.childNodes, pred); return result.map(SugarElement.fromDom); }; const descendant$1 = (scope, predicate) => { const descend = node => { for (let i = 0; i < node.childNodes.length; i++) { const child = SugarElement.fromDom(node.childNodes[i]); if (predicate(child)) { return Optional.some(child); } const res = descend(node.childNodes[i]); if (res.isSome()) { return res; } } return Optional.none(); }; return descend(scope.dom); }; const ancestor$1 = (scope, selector, isRoot) => ancestor$2(scope, e => is$2(e, selector), isRoot); const child = (scope, selector) => child$1(scope, e => is$2(e, selector)); const descendant = (scope, selector) => one(selector, scope); const closest$1 = (scope, selector, isRoot) => { const is = (element, selector) => is$2(element, selector); return ClosestOrAncestor(is, ancestor$1, scope, selector, isRoot); }; const is = (lhs, rhs, comparator = tripleEquals) => lhs.exists(left => comparator(left, rhs)); const cat = arr => { const r = []; const push = x => { r.push(x); }; for (let i = 0; i < arr.length; i++) { arr[i].each(push); } return r; }; const bindFrom = (a, f) => a !== undefined && a !== null ? f(a) : Optional.none(); const someIf = (b, a) => b ? Optional.some(a) : Optional.none(); const checkRange = (str, substr, start) => substr === '' || str.length >= substr.length && str.substr(start, start + substr.length) === substr; const contains = (str, substr) => { return str.indexOf(substr) !== -1; }; const startsWith = (str, prefix) => { return checkRange(str, prefix, 0); }; const endsWith = (str, suffix) => { return checkRange(str, suffix, str.length - suffix.length); }; const blank = r => s => s.replace(r, ''); const trim = blank(/^\s+|\s+$/g); const isNotEmpty = s => s.length > 0; const toFloat = value => { const num = parseFloat(value); return isNaN(num) ? Optional.none() : Optional.some(num); }; const isSupported = dom => dom.style !== undefined && isFunction(dom.style.getPropertyValue); const internalSet = (dom, property, value) => { if (!isString(value)) { console.error('Invalid call to CSS.set. Property ', property, ':: Value ', value, ':: Element ', dom); throw new Error('CSS value must be a string: ' + value); } if (isSupported(dom)) { dom.style.setProperty(property, value); } }; const internalRemove = (dom, property) => { if (isSupported(dom)) { dom.style.removeProperty(property); } }; const set$1 = (element, property, value) => { const dom = element.dom; internalSet(dom, property, value); }; const setAll = (element, css) => { const dom = element.dom; each$1(css, (v, k) => { internalSet(dom, k, v); }); }; const get$a = (element, property) => { const dom = element.dom; const styles = window.getComputedStyle(dom); const r = styles.getPropertyValue(property); return r === '' && !inBody(element) ? getUnsafeProperty(dom, property) : r; }; const getUnsafeProperty = (dom, property) => isSupported(dom) ? dom.style.getPropertyValue(property) : ''; const getRaw$2 = (element, property) => { const dom = element.dom; const raw = getUnsafeProperty(dom, property); return Optional.from(raw).filter(r => r.length > 0); }; const remove$5 = (element, property) => { const dom = element.dom; internalRemove(dom, property); if (is(getOpt(element, 'style').map(trim), '')) { remove$7(element, 'style'); } }; const copy$1 = (source, target) => { const sourceDom = source.dom; const targetDom = target.dom; if (isSupported(sourceDom) && isSupported(targetDom)) { targetDom.style.cssText = sourceDom.style.cssText; } }; const getAttrValue = (cell, name, fallback = 0) => getOpt(cell, name).map(value => parseInt(value, 10)).getOr(fallback); const getSpan = (cell, type) => getAttrValue(cell, type, 1); const hasColspan = cellOrCol => { if (isTag('col')(cellOrCol)) { return getAttrValue(cellOrCol, 'span', 1) > 1; } else { return getSpan(cellOrCol, 'colspan') > 1; } }; const hasRowspan = cell => getSpan(cell, 'rowspan') > 1; const getCssValue = (element, property) => parseInt(get$a(element, property), 10); const minWidth = constant(10); const minHeight = constant(10); const firstLayer = (scope, selector) => { return filterFirstLayer(scope, selector, always); }; const filterFirstLayer = (scope, selector, predicate) => { return bind$2(children$2(scope), x => { if (is$2(x, selector)) { return predicate(x) ? [x] : []; } else { return filterFirstLayer(x, selector, predicate); } }); }; const lookup = (tags, element, isRoot = never) => { if (isRoot(element)) { return Optional.none(); } if (contains$2(tags, name(element))) { return Optional.some(element); } const isRootOrUpperTable = elm => is$2(elm, 'table') || isRoot(elm); return ancestor$1(element, tags.join(','), isRootOrUpperTable); }; const cell = (element, isRoot) => lookup([ 'td', 'th' ], element, isRoot); const cells$1 = ancestor => firstLayer(ancestor, 'th,td'); const columns$1 = ancestor => { if (is$2(ancestor, 'colgroup')) { return children(ancestor, 'col'); } else { return bind$2(columnGroups(ancestor), columnGroup => children(columnGroup, 'col')); } }; const table = (element, isRoot) => closest$1(element, 'table', isRoot); const rows$1 = ancestor => firstLayer(ancestor, 'tr'); const columnGroups = ancestor => table(ancestor).fold(constant([]), table => children(table, 'colgroup')); const fromRowsOrColGroups = (elems, getSection) => map$1(elems, row => { if (name(row) === 'colgroup') { const cells = map$1(columns$1(row), column => { const colspan = getAttrValue(column, 'span', 1); return detail(column, 1, colspan); }); return rowdetail(row, cells, 'colgroup'); } else { const cells = map$1(cells$1(row), cell => { const rowspan = getAttrValue(cell, 'rowspan', 1); const colspan = getAttrValue(cell, 'colspan', 1); return detail(cell, rowspan, colspan); }); return rowdetail(row, cells, getSection(row)); } }); const getParentSection = group => parent(group).map(parent => { const parentName = name(parent); return isValidSection(parentName) ? parentName : 'tbody'; }).getOr('tbody'); const fromTable$1 = table => { const rows = rows$1(table); const columnGroups$1 = columnGroups(table); const elems = [ ...columnGroups$1, ...rows ]; return fromRowsOrColGroups(elems, getParentSection); }; const fromPastedRows = (elems, section) => fromRowsOrColGroups(elems, () => section); const cached = f => { let called = false; let r; return (...args) => { if (!called) { called = true; r = f.apply(null, args); } return r; }; }; const DeviceType = (os, browser, userAgent, mediaMatch) => { const isiPad = os.isiOS() && /ipad/i.test(userAgent) === true; const isiPhone = os.isiOS() && !isiPad; const isMobile = os.isiOS() || os.isAndroid(); const isTouch = isMobile || mediaMatch('(pointer:coarse)'); const isTablet = isiPad || !isiPhone && isMobile && mediaMatch('(min-device-width:768px)'); const isPhone = isiPhone || isMobile && !isTablet; const iOSwebview = browser.isSafari() && os.isiOS() && /safari/i.test(userAgent) === false; const isDesktop = !isPhone && !isTablet && !iOSwebview; return { isiPad: constant(isiPad), isiPhone: constant(isiPhone), isTablet: constant(isTablet), isPhone: constant(isPhone), isTouch: constant(isTouch), isAndroid: os.isAndroid, isiOS: os.isiOS, isWebView: constant(iOSwebview), isDesktop: constant(isDesktop) }; }; const firstMatch = (regexes, s) => { for (let i = 0; i < regexes.length; i++) { const x = regexes[i]; if (x.test(s)) { return x; } } return undefined; }; const find = (regexes, agent) => { const r = firstMatch(regexes, agent); if (!r) { return { major: 0, minor: 0 }; } const group = i => { return Number(agent.replace(r, '$' + i)); }; return nu$2(group(1), group(2)); }; const detect$5 = (versionRegexes, agent) => { const cleanedAgent = String(agent).toLowerCase(); if (versionRegexes.length === 0) { return unknown$2(); } return find(versionRegexes, cleanedAgent); }; const unknown$2 = () => { return nu$2(0, 0); }; const nu$2 = (major, minor) => { return { major, minor }; }; const Version = { nu: nu$2, detect: detect$5, unknown: unknown$2 }; const detectBrowser$1 = (browsers, userAgentData) => { return findMap(userAgentData.brands, uaBrand => { const lcBrand = uaBrand.brand.toLowerCase(); return find$1(browsers, browser => { var _a; return lcBrand === ((_a = browser.brand) === null || _a === void 0 ? void 0 : _a.toLowerCase()); }).map(info => ({ current: info.name, version: Version.nu(parseInt(uaBrand.version, 10), 0) })); }); }; const detect$4 = (candidates, userAgent) => { const agent = String(userAgent).toLowerCase(); return find$1(candidates, candidate => { return candidate.search(agent); }); }; const detectBrowser = (browsers, userAgent) => { return detect$4(browsers, userAgent).map(browser => { const version = Version.detect(browser.versionRegexes, userAgent); return { current: browser.name, version }; }); }; const detectOs = (oses, userAgent) => { return detect$4(oses, userAgent).map(os => { const version = Version.detect(os.versionRegexes, userAgent); return { current: os.name, version }; }); }; const normalVersionRegex = /.*?version\/\ ?([0-9]+)\.([0-9]+).*/; const checkContains = target => { return uastring => { return contains(uastring, target); }; }; const browsers = [ { name: 'Edge', versionRegexes: [/.*?edge\/ ?([0-9]+)\.([0-9]+)$/], search: uastring => { return contains(uastring, 'edge/') && contains(uastring, 'chrome') && contains(uastring, 'safari') && contains(uastring, 'applewebkit'); } }, { name: 'Chromium', brand: 'Chromium', versionRegexes: [ /.*?chrome\/([0-9]+)\.([0-9]+).*/, normalVersionRegex ], search: uastring => { return contains(uastring, 'chrome') && !contains(uastring, 'chromeframe'); } }, { name: 'IE', versionRegexes: [ /.*?msie\ ?([0-9]+)\.([0-9]+).*/, /.*?rv:([0-9]+)\.([0-9]+).*/ ], search: uastring => { return contains(uastring, 'msie') || contains(uastring, 'trident'); } }, { name: 'Opera', versionRegexes: [ normalVersionRegex, /.*?opera\/([0-9]+)\.([0-9]+).*/ ], search: checkContains('opera') }, { name: 'Firefox', versionRegexes: [/.*?firefox\/\ ?([0-9]+)\.([0-9]+).*/], search: checkContains('firefox') }, { name: 'Safari', versionRegexes: [ normalVersionRegex, /.*?cpu os ([0-9]+)_([0-9]+).*/ ], search: uastring => { return (contains(uastring, 'safari') || contains(uastring, 'mobile/')) && contains(uastring, 'applewebkit'); } } ]; const oses = [ { name: 'Windows', search: checkContains('win'), versionRegexes: [/.*?windows\ nt\ ?([0-9]+)\.([0-9]+).*/] }, { name: 'iOS', search: uastring => { return contains(uastring, 'iphone') || contains(uastring, 'ipad'); }, versionRegexes: [ /.*?version\/\ ?([0-9]+)\.([0-9]+).*/, /.*cpu os ([0-9]+)_([0-9]+).*/, /.*cpu iphone os ([0-9]+)_([0-9]+).*/ ] }, { name: 'Android', search: checkContains('android'), versionRegexes: [/.*?android\ ?([0-9]+)\.([0-9]+).*/] }, { name: 'macOS', search: checkContains('mac os x'), versionRegexes: [/.*?mac\ os\ x\ ?([0-9]+)_([0-9]+).*/] }, { name: 'Linux', search: checkContains('linux'), versionRegexes: [] }, { name: 'Solaris', search: checkContains('sunos'), versionRegexes: [] }, { name: 'FreeBSD', search: checkContains('freebsd'), versionRegexes: [] }, { name: 'ChromeOS', search: checkContains('cros'), versionRegexes: [/.*?chrome\/([0-9]+)\.([0-9]+).*/] } ]; const PlatformInfo = { browsers: constant(browsers), oses: constant(oses) }; const edge = 'Edge'; const chromium = 'Chromium'; const ie = 'IE'; const opera = 'Opera'; const firefox = 'Firefox'; const safari = 'Safari'; const unknown$1 = () => { return nu$1({ current: undefined, version: Version.unknown() }); }; const nu$1 = info => { const current = info.current; const version = info.version; const isBrowser = name => () => current === name; return { current, version, isEdge: isBrowser(edge), isChromium: isBrowser(chromium), isIE: isBrowser(ie), isOpera: isBrowser(opera), isFirefox: isBrowser(firefox), isSafari: isBrowser(safari) }; }; const Browser = { unknown: unknown$1, nu: nu$1, edge: constant(edge), chromium: constant(chromium), ie: constant(ie), opera: constant(opera), firefox: constant(firefox), safari: constant(safari) }; const windows = 'Windows'; const ios = 'iOS'; const android = 'Android'; const linux = 'Linux'; const macos = 'macOS'; const solaris = 'Solaris'; const freebsd = 'FreeBSD'; const chromeos = 'ChromeOS'; const unknown = () => { return nu({ current: undefined, version: Version.unknown() }); }; const nu = info => { const current = info.current; const version = info.version; const isOS = name => () => current === name; return { current, version, isWindows: isOS(windows), isiOS: isOS(ios), isAndroid: isOS(android), isMacOS: isOS(macos), isLinux: isOS(linux), isSolaris: isOS(solaris), isFreeBSD: isOS(freebsd), isChromeOS: isOS(chromeos) }; }; const OperatingSystem = { unknown, nu, windows: constant(windows), ios: constant(ios), android: constant(android), linux: constant(linux), macos: constant(macos), solaris: constant(solaris), freebsd: constant(freebsd), chromeos: constant(chromeos) }; const detect$3 = (userAgent, userAgentDataOpt, mediaMatch) => { const browsers = PlatformInfo.browsers(); const oses = PlatformInfo.oses(); const browser = userAgentDataOpt.bind(userAgentData => detectBrowser$1(browsers, userAgentData)).orThunk(() => detectBrowser(browsers, userAgent)).fold(Browser.unknown, Browser.nu); const os = detectOs(oses, userAgent).fold(OperatingSystem.unknown, OperatingSystem.nu); const deviceType = DeviceType(os, browser, userAgent, mediaMatch); return { browser, os, deviceType }; }; const PlatformDetection = { detect: detect$3 }; const mediaMatch = query => window.matchMedia(query).matches; let platform = cached(() => PlatformDetection.detect(navigator.userAgent, Optional.from(navigator.userAgentData), mediaMatch)); const detect$2 = () => platform(); const Dimension = (name, getOffset) => { const set = (element, h) => { if (!isNumber(h) && !h.match(/^[0-9]+$/)) { throw new Error(name + '.set accepts only positive integer values. Value was ' + h); } const dom = element.dom; if (isSupported(dom)) { dom.style[name] = h + 'px'; } }; const get = element => { const r = getOffset(element); if (r <= 0 || r === null) { const css = get$a(element, name); return parseFloat(css) || 0; } return r; }; const getOuter = get; const aggregate = (element, properties) => foldl(properties, (acc, property) => { const val = get$a(element, property); const value = val === undefined ? 0 : parseInt(val, 10); return isNaN(value) ? acc : acc + value; }, 0); const max = (element, value, properties) => { const cumulativeInclusions = aggregate(element, properties); const absoluteMax = value > cumulativeInclusions ? value - cumulativeInclusions : 0; return absoluteMax; }; return { set, get, getOuter, aggregate, max }; }; const toNumber = (px, fallback) => toFloat(px).getOr(fallback); const getProp = (element, name, fallback) => toNumber(get$a(element, name), fallback); const calcContentBoxSize = (element, size, upper, lower) => { const paddingUpper = getProp(element, `padding-${ upper }`, 0); const paddingLower = getProp(element, `padding-${ lower }`, 0); const borderUpper = getProp(element, `border-${ upper }-width`, 0); const borderLower = getProp(element, `border-${ lower }-width`, 0); return size - paddingUpper - paddingLower - borderUpper - borderLower; }; const getCalculatedWidth = (element, boxSizing) => { const dom = element.dom; const width = dom.getBoundingClientRect().width || dom.offsetWidth; return boxSizing === 'border-box' ? width : calcContentBoxSize(element, width, 'left', 'right'); }; const getHeight$1 = element => getProp(element, 'height', element.dom.offsetHeight); const getWidth = element => getProp(element, 'width', element.dom.offsetWidth); const getInnerWidth = element => getCalculatedWidth(element, 'content-box'); const api$2 = Dimension('width', element => element.dom.offsetWidth); const get$9 = element => api$2.get(element); const getOuter$2 = element => api$2.getOuter(element); const getInner = getInnerWidth; const getRuntime$1 = getWidth; const addCells = (gridRow, index, cells) => { const existingCells = gridRow.cells; const before = existingCells.slice(0, index); const after = existingCells.slice(index); const newCells = before.concat(cells).concat(after); return setCells(gridRow, newCells); }; const addCell = (gridRow, index, cell) => addCells(gridRow, index, [cell]); const mutateCell = (gridRow, index, cell) => { const cells = gridRow.cells; cells[index] = cell; }; const setCells = (gridRow, cells) => rowcells(gridRow.element, cells, gridRow.section, gridRow.isNew); const mapCells = (gridRow, f) => { const cells = gridRow.cells; const r = map$1(cells, f); return rowcells(gridRow.element, r, gridRow.section, gridRow.isNew); }; const getCell = (gridRow, index) => gridRow.cells[index]; const getCellElement = (gridRow, index) => getCell(gridRow, index).element; const cellLength = gridRow => gridRow.cells.length; const extractGridDetails = grid => { const result = partition(grid, row => row.section === 'colgroup'); return { rows: result.fail, cols: result.pass }; }; const clone = (gridRow, cloneRow, cloneCell) => { const newCells = map$1(gridRow.cells, cloneCell); return rowcells(cloneRow(gridRow.element), newCells, gridRow.section, true); }; const LOCKED_COL_ATTR = 'data-snooker-locked-cols'; const getLockedColumnsFromTable = table => getOpt(table, LOCKED_COL_ATTR).bind(lockedColStr => Optional.from(lockedColStr.match(/\d+/g))).map(lockedCols => mapToObject(lockedCols, always)); const getLockedColumnsFromGrid = grid => { const locked = foldl(extractGridDetails(grid).rows, (acc, row) => { each$2(row.cells, (cell, idx) => { if (cell.isLocked) { acc[idx] = true; } }); return acc; }, {}); const lockedArr = mapToArray(locked, (_val, key) => parseInt(key, 10)); return sort$1(lockedArr); }; const key = (row, column) => { return row + ',' + column; }; const getAt = (warehouse, row, column) => Optional.from(warehouse.access[key(row, column)]); const findItem = (warehouse, item, comparator) => { const filtered = filterItems(warehouse, detail => { return comparator(item, detail.element); }); return filtered.length > 0 ? Optional.some(filtered[0]) : Optional.none(); }; const filterItems = (warehouse, predicate) => { const all = bind$2(warehouse.all, r => { return r.cells; }); return filter$2(all, predicate); }; const generateColumns = rowData => { const columnsGroup = {}; let index = 0; each$2(rowData.cells, column => { const colspan = column.colspan; range$1(colspan, columnIndex => { const colIndex = index + columnIndex; columnsGroup[colIndex] = columnext(column.element, colspan, colIndex); }); index += colspan; }); return columnsGroup; }; const generate$1 = list => { const access = {}; const cells = []; const tableOpt = head(list).map(rowData => rowData.element).bind(table); const lockedColumns = tableOpt.bind(getLockedColumnsFromTable).getOr({}); let maxRows = 0; let maxColumns = 0; let rowCount = 0; const { pass: colgroupRows, fail: rows } = partition(list, rowData => rowData.section === 'colgroup'); each$2(rows, rowData => { const currentRow = []; each$2(rowData.cells, rowCell => { let start = 0; while (access[key(rowCount, start)] !== undefined) { start++; } const isLocked = hasNonNullableKey(lockedColumns, start.toString()); const current = extended(rowCell.element, rowCell.rowspan, rowCell.colspan, rowCount, start, isLocked); for (let occupiedColumnPosition = 0; occupiedColumnPosition < rowCell.colspan; occupiedColumnPosition++) { for (let occupiedRowPosition = 0; occupiedRowPosition < rowCell.rowspan; occupiedRowPosition++) { const rowPosition = rowCount + occupiedRowPosition; const columnPosition = start + occupiedColumnPosition; const newpos = key(rowPosition, columnPosition); access[newpos] = current; maxColumns = Math.max(maxColumns, columnPosition + 1); } } currentRow.push(current); }); maxRows++; cells.push(rowdetail(rowData.element, currentRow, rowData.section)); rowCount++; }); const {columns, colgroups} = last$2(colgroupRows).map(rowData => { const columns = generateColumns(rowData); const colgroup$1 = colgroup(rowData.element, values(columns)); return { colgroups: [colgroup$1], columns }; }).getOrThunk(() => ({ colgroups: [], columns: {} })); const grid$1 = grid(maxRows, maxColumns); return { grid: grid$1, access, all: cells, columns, colgroups }; }; const fromTable = table => { const list = fromTable$1(table); return generate$1(list); }; const justCells = warehouse => bind$2(warehouse.all, w => w.cells); const justColumns = warehouse => values(warehouse.columns); const hasColumns = warehouse => keys(warehouse.columns).length > 0; const getColumnAt = (warehouse, columnIndex) => Optional.from(warehouse.columns[columnIndex]); const Warehouse = { fromTable, generate: generate$1, getAt, findItem, filterItems, justCells, justColumns, hasColumns, getColumnAt }; const columns = (warehouse, isValidCell = always) => { const grid = warehouse.grid; const cols = range$1(grid.columns, identity); const rowsArr = range$1(grid.rows, identity); return map$1(cols, col => { const getBlock = () => bind$2(rowsArr, r => Warehouse.getAt(warehouse, r, col).filter(detail => detail.column === col).toArray()); const isValid = detail => detail.colspan === 1 && isValidCell(detail.element); const getFallback = () => Warehouse.getAt(warehouse, 0, col); return decide(getBlock, isValid, getFallback); }); }; const decide = (getBlock, isValid, getFallback) => { const