{"version":3,"file":"plugin-aWvTAXR4.js","sources":["../../../node_modules/tinymce/tinymce.js","../../../node_modules/tinymce/models/dom/model.js","../../../node_modules/tinymce/icons/default/icons.js","../../../node_modules/tinymce/skins/content/default/content.js","../../../node_modules/tinymce/themes/silver/theme.js","../../../node_modules/tinymce/plugins/autoresize/plugin.js","../../../node_modules/tinymce/plugins/wordcount/plugin.js"],"sourcesContent":["/**\n * TinyMCE version 7.6.1 (2025-01-22)\n */\n\n(function () {\n 'use strict';\n\n var typeOf$1 = function (x) {\n if (x === null) {\n return 'null';\n }\n if (x === undefined) {\n return 'undefined';\n }\n var t = typeof x;\n if (t === 'object' && (Array.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === 'Array')) {\n return 'array';\n }\n if (t === 'object' && (String.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === 'String')) {\n return 'string';\n }\n return t;\n };\n var isEquatableType = function (x) {\n return [\n 'undefined',\n 'boolean',\n 'number',\n 'string',\n 'function',\n 'xml',\n 'null'\n ].indexOf(x) !== -1;\n };\n\n var sort$1 = function (xs, compareFn) {\n var clone = Array.prototype.slice.call(xs);\n return clone.sort(compareFn);\n };\n\n var contramap = function (eqa, f) {\n return eq$2(function (x, y) {\n return eqa.eq(f(x), f(y));\n });\n };\n var eq$2 = function (f) {\n return { eq: f };\n };\n var tripleEq = eq$2(function (x, y) {\n return x === y;\n });\n var eqString = tripleEq;\n var eqArray = function (eqa) {\n return eq$2(function (x, y) {\n if (x.length !== y.length) {\n return false;\n }\n var len = x.length;\n for (var i = 0; i < len; i++) {\n if (!eqa.eq(x[i], y[i])) {\n return false;\n }\n }\n return true;\n });\n };\n var eqSortedArray = function (eqa, compareFn) {\n return contramap(eqArray(eqa), function (xs) {\n return sort$1(xs, compareFn);\n });\n };\n var eqRecord = function (eqa) {\n return eq$2(function (x, y) {\n var kx = Object.keys(x);\n var ky = Object.keys(y);\n if (!eqSortedArray(eqString).eq(kx, ky)) {\n return false;\n }\n var len = kx.length;\n for (var i = 0; i < len; i++) {\n var q = kx[i];\n if (!eqa.eq(x[q], y[q])) {\n return false;\n }\n }\n return true;\n });\n };\n var eqAny = eq$2(function (x, y) {\n if (x === y) {\n return true;\n }\n var tx = typeOf$1(x);\n var ty = typeOf$1(y);\n if (tx !== ty) {\n return false;\n }\n if (isEquatableType(tx)) {\n return x === y;\n } else if (tx === 'array') {\n return eqArray(eqAny).eq(x, y);\n } else if (tx === 'object') {\n return eqRecord(eqAny).eq(x, y);\n }\n return false;\n });\n\n const getPrototypeOf$2 = Object.getPrototypeOf;\n const hasProto = (v, constructor, predicate) => {\n var _a;\n if (predicate(v, constructor.prototype)) {\n return true;\n } else {\n return ((_a = v.constructor) === null || _a === void 0 ? void 0 : _a.name) === constructor.name;\n }\n };\n const typeOf = x => {\n const t = typeof x;\n if (x === null) {\n return 'null';\n } else if (t === 'object' && Array.isArray(x)) {\n return 'array';\n } else if (t === 'object' && hasProto(x, String, (o, proto) => proto.isPrototypeOf(o))) {\n return 'string';\n } else {\n return t;\n }\n };\n const isType$1 = type => value => typeOf(value) === type;\n const isSimpleType = type => value => typeof value === type;\n const eq$1 = t => a => t === a;\n const is$4 = (value, constructor) => isObject(value) && hasProto(value, constructor, (o, proto) => getPrototypeOf$2(o) === proto);\n const isString = isType$1('string');\n const isObject = isType$1('object');\n const isPlainObject = value => is$4(value, Object);\n const isArray$1 = isType$1('array');\n const isNull = eq$1(null);\n const isBoolean = isSimpleType('boolean');\n const isUndefined = eq$1(undefined);\n const isNullable = a => a === null || a === undefined;\n const isNonNullable = a => !isNullable(a);\n const isFunction = isSimpleType('function');\n const isNumber = isSimpleType('number');\n const isArrayOf = (value, pred) => {\n if (isArray$1(value)) {\n for (let i = 0, len = value.length; i < len; ++i) {\n if (!pred(value[i])) {\n return false;\n }\n }\n return true;\n }\n return false;\n };\n\n const noop = () => {\n };\n const compose = (fa, fb) => {\n return (...args) => {\n return fa(fb.apply(null, args));\n };\n };\n const compose1 = (fbc, fab) => a => fbc(fab(a));\n const constant = value => {\n return () => {\n return value;\n };\n };\n const identity = x => {\n return x;\n };\n const tripleEquals = (a, b) => {\n return a === b;\n };\n function curry(fn, ...initialArgs) {\n return (...restArgs) => {\n const all = initialArgs.concat(restArgs);\n return fn.apply(null, all);\n };\n }\n const not = f => t => !f(t);\n const die = msg => {\n return () => {\n throw new Error(msg);\n };\n };\n const apply$1 = f => {\n return f();\n };\n const call = f => {\n f();\n };\n const never = constant(false);\n const always = constant(true);\n\n class Optional {\n constructor(tag, value) {\n this.tag = tag;\n this.value = value;\n }\n static some(value) {\n return new Optional(true, value);\n }\n static none() {\n return Optional.singletonNone;\n }\n fold(onNone, onSome) {\n if (this.tag) {\n return onSome(this.value);\n } else {\n return onNone();\n }\n }\n isSome() {\n return this.tag;\n }\n isNone() {\n return !this.tag;\n }\n map(mapper) {\n if (this.tag) {\n return Optional.some(mapper(this.value));\n } else {\n return Optional.none();\n }\n }\n bind(binder) {\n if (this.tag) {\n return binder(this.value);\n } else {\n return Optional.none();\n }\n }\n exists(predicate) {\n return this.tag && predicate(this.value);\n }\n forall(predicate) {\n return !this.tag || predicate(this.value);\n }\n filter(predicate) {\n if (!this.tag || predicate(this.value)) {\n return this;\n } else {\n return Optional.none();\n }\n }\n getOr(replacement) {\n return this.tag ? this.value : replacement;\n }\n or(replacement) {\n return this.tag ? this : replacement;\n }\n getOrThunk(thunk) {\n return this.tag ? this.value : thunk();\n }\n orThunk(thunk) {\n return this.tag ? this : thunk();\n }\n getOrDie(message) {\n if (!this.tag) {\n throw new Error(message !== null && message !== void 0 ? message : 'Called getOrDie on None');\n } else {\n return this.value;\n }\n }\n static from(value) {\n return isNonNullable(value) ? Optional.some(value) : Optional.none();\n }\n getOrNull() {\n return this.tag ? this.value : null;\n }\n getOrUndefined() {\n return this.value;\n }\n each(worker) {\n if (this.tag) {\n worker(this.value);\n }\n }\n toArray() {\n return this.tag ? [this.value] : [];\n }\n toString() {\n return this.tag ? `some(${ this.value })` : 'none()';\n }\n }\n Optional.singletonNone = new Optional(false);\n\n const nativeSlice = Array.prototype.slice;\n const nativeIndexOf = Array.prototype.indexOf;\n const nativePush = Array.prototype.push;\n const rawIndexOf = (ts, t) => nativeIndexOf.call(ts, t);\n const indexOf$1 = (xs, x) => {\n const r = rawIndexOf(xs, x);\n return r === -1 ? Optional.none() : Optional.some(r);\n };\n const contains$2 = (xs, x) => rawIndexOf(xs, x) > -1;\n const exists = (xs, pred) => {\n for (let i = 0, len = xs.length; i < len; i++) {\n const x = xs[i];\n if (pred(x, i)) {\n return true;\n }\n }\n return false;\n };\n const map$3 = (xs, f) => {\n const len = xs.length;\n const r = new Array(len);\n for (let i = 0; i < len; i++) {\n const x = xs[i];\n r[i] = f(x, i);\n }\n return r;\n };\n const each$e = (xs, f) => {\n for (let i = 0, len = xs.length; i < len; i++) {\n const x = xs[i];\n f(x, i);\n }\n };\n const eachr = (xs, f) => {\n for (let i = xs.length - 1; i >= 0; i--) {\n const x = xs[i];\n f(x, i);\n }\n };\n const partition$2 = (xs, pred) => {\n const pass = [];\n const fail = [];\n for (let i = 0, len = xs.length; i < len; i++) {\n const x = xs[i];\n const arr = pred(x, i) ? pass : fail;\n arr.push(x);\n }\n return {\n pass,\n fail\n };\n };\n const filter$5 = (xs, pred) => {\n const r = [];\n for (let i = 0, len = xs.length; i < len; i++) {\n const x = xs[i];\n if (pred(x, i)) {\n r.push(x);\n }\n }\n return r;\n };\n const foldr = (xs, f, acc) => {\n eachr(xs, (x, i) => {\n acc = f(acc, x, i);\n });\n return acc;\n };\n const foldl = (xs, f, acc) => {\n each$e(xs, (x, i) => {\n acc = f(acc, x, i);\n });\n return acc;\n };\n const findUntil$1 = (xs, pred, until) => {\n for (let i = 0, len = xs.length; i < len; i++) {\n const x = xs[i];\n if (pred(x, i)) {\n return Optional.some(x);\n } else if (until(x, i)) {\n break;\n }\n }\n return Optional.none();\n };\n const find$2 = (xs, pred) => {\n return findUntil$1(xs, pred, never);\n };\n const findIndex$2 = (xs, pred) => {\n for (let i = 0, len = xs.length; i < len; i++) {\n const x = xs[i];\n if (pred(x, i)) {\n return Optional.some(i);\n }\n }\n return Optional.none();\n };\n const flatten = xs => {\n const r = [];\n for (let i = 0, len = xs.length; i < len; ++i) {\n if (!isArray$1(xs[i])) {\n throw new Error('Arr.flatten item ' + i + ' was not an array, input: ' + xs);\n }\n nativePush.apply(r, xs[i]);\n }\n return r;\n };\n const bind$3 = (xs, f) => flatten(map$3(xs, f));\n const forall = (xs, pred) => {\n for (let i = 0, len = xs.length; i < len; ++i) {\n const x = xs[i];\n if (pred(x, i) !== true) {\n return false;\n }\n }\n return true;\n };\n const reverse = xs => {\n const r = nativeSlice.call(xs, 0);\n r.reverse();\n return r;\n };\n const difference = (a1, a2) => filter$5(a1, x => !contains$2(a2, x));\n const mapToObject = (xs, f) => {\n const r = {};\n for (let i = 0, len = xs.length; i < len; i++) {\n const x = xs[i];\n r[String(x)] = f(x, i);\n }\n return r;\n };\n const sort = (xs, comparator) => {\n const copy = nativeSlice.call(xs, 0);\n copy.sort(comparator);\n return copy;\n };\n const get$b = (xs, i) => i >= 0 && i < xs.length ? Optional.some(xs[i]) : Optional.none();\n const head = xs => get$b(xs, 0);\n const last$2 = xs => get$b(xs, xs.length - 1);\n const from = isFunction(Array.from) ? Array.from : x => nativeSlice.call(x);\n const findMap = (arr, f) => {\n for (let i = 0; i < arr.length; i++) {\n const r = f(arr[i], i);\n if (r.isSome()) {\n return r;\n }\n }\n return Optional.none();\n };\n const unique$1 = (xs, comparator) => {\n const r = [];\n const isDuplicated = isFunction(comparator) ? x => exists(r, i => comparator(i, x)) : x => contains$2(r, x);\n for (let i = 0, len = xs.length; i < len; i++) {\n const x = xs[i];\n if (!isDuplicated(x)) {\n r.push(x);\n }\n }\n return r;\n };\n\n const keys = Object.keys;\n const hasOwnProperty$1 = Object.hasOwnProperty;\n const each$d = (obj, f) => {\n const props = keys(obj);\n for (let k = 0, len = props.length; k < len; k++) {\n const i = props[k];\n const x = obj[i];\n f(x, i);\n }\n };\n const map$2 = (obj, f) => {\n return tupleMap(obj, (x, i) => ({\n k: i,\n v: f(x, i)\n }));\n };\n const tupleMap = (obj, f) => {\n const r = {};\n each$d(obj, (x, i) => {\n const tuple = f(x, i);\n r[tuple.k] = tuple.v;\n });\n return r;\n };\n const objAcc = r => (x, i) => {\n r[i] = x;\n };\n const internalFilter = (obj, pred, onTrue, onFalse) => {\n each$d(obj, (x, i) => {\n (pred(x, i) ? onTrue : onFalse)(x, i);\n });\n };\n const bifilter = (obj, pred) => {\n const t = {};\n const f = {};\n internalFilter(obj, pred, objAcc(t), objAcc(f));\n return {\n t,\n f\n };\n };\n const filter$4 = (obj, pred) => {\n const t = {};\n internalFilter(obj, pred, objAcc(t), noop);\n return t;\n };\n const mapToArray = (obj, f) => {\n const r = [];\n each$d(obj, (value, name) => {\n r.push(f(value, name));\n });\n return r;\n };\n const values = obj => {\n return mapToArray(obj, identity);\n };\n const get$a = (obj, key) => {\n return has$2(obj, key) ? Optional.from(obj[key]) : Optional.none();\n };\n const has$2 = (obj, key) => hasOwnProperty$1.call(obj, key);\n const hasNonNullableKey = (obj, key) => has$2(obj, key) && obj[key] !== undefined && obj[key] !== null;\n const equal$1 = (a1, a2, eq = eqAny) => eqRecord(eq).eq(a1, a2);\n\n const stringArray = a => {\n const all = {};\n each$e(a, key => {\n all[key] = {};\n });\n return keys(all);\n };\n\n const isArrayLike = o => o.length !== undefined;\n const isArray = Array.isArray;\n const toArray$1 = obj => {\n if (!isArray(obj)) {\n const array = [];\n for (let i = 0, l = obj.length; i < l; i++) {\n array[i] = obj[i];\n }\n return array;\n } else {\n return obj;\n }\n };\n const each$c = (o, cb, s) => {\n if (!o) {\n return false;\n }\n s = s || o;\n if (isArrayLike(o)) {\n for (let n = 0, l = o.length; n < l; n++) {\n if (cb.call(s, o[n], n, o) === false) {\n return false;\n }\n }\n } else {\n for (const n in o) {\n if (has$2(o, n)) {\n if (cb.call(s, o[n], n, o) === false) {\n return false;\n }\n }\n }\n }\n return true;\n };\n const map$1 = (array, callback) => {\n const out = [];\n each$c(array, (item, index) => {\n out.push(callback(item, index, array));\n });\n return out;\n };\n const filter$3 = (a, f) => {\n const o = [];\n each$c(a, (v, index) => {\n if (!f || f(v, index, a)) {\n o.push(v);\n }\n });\n return o;\n };\n const indexOf = (a, v) => {\n if (a) {\n for (let i = 0, l = a.length; i < l; i++) {\n if (a[i] === v) {\n return i;\n }\n }\n }\n return -1;\n };\n const reduce = (collection, iteratee, accumulator, thisArg) => {\n let acc = isUndefined(accumulator) ? collection[0] : accumulator;\n for (let i = 0; i < collection.length; i++) {\n acc = iteratee.call(thisArg, acc, collection[i], i);\n }\n return acc;\n };\n const findIndex$1 = (array, predicate, thisArg) => {\n for (let i = 0, l = array.length; i < l; i++) {\n if (predicate.call(thisArg, array[i], i, array)) {\n return i;\n }\n }\n return -1;\n };\n const last$1 = collection => collection[collection.length - 1];\n\n const cached = f => {\n let called = false;\n let r;\n return (...args) => {\n if (!called) {\n called = true;\n r = f.apply(null, args);\n }\n return r;\n };\n };\n\n const DeviceType = (os, browser, userAgent, mediaMatch) => {\n const isiPad = os.isiOS() && /ipad/i.test(userAgent) === true;\n const isiPhone = os.isiOS() && !isiPad;\n const isMobile = os.isiOS() || os.isAndroid();\n const isTouch = isMobile || mediaMatch('(pointer:coarse)');\n const isTablet = isiPad || !isiPhone && isMobile && mediaMatch('(min-device-width:768px)');\n const isPhone = isiPhone || isMobile && !isTablet;\n const iOSwebview = browser.isSafari() && os.isiOS() && /safari/i.test(userAgent) === false;\n const isDesktop = !isPhone && !isTablet && !iOSwebview;\n return {\n isiPad: constant(isiPad),\n isiPhone: constant(isiPhone),\n isTablet: constant(isTablet),\n isPhone: constant(isPhone),\n isTouch: constant(isTouch),\n isAndroid: os.isAndroid,\n isiOS: os.isiOS,\n isWebView: constant(iOSwebview),\n isDesktop: constant(isDesktop)\n };\n };\n\n const firstMatch = (regexes, s) => {\n for (let i = 0; i < regexes.length; i++) {\n const x = regexes[i];\n if (x.test(s)) {\n return x;\n }\n }\n return undefined;\n };\n const find$1 = (regexes, agent) => {\n const r = firstMatch(regexes, agent);\n if (!r) {\n return {\n major: 0,\n minor: 0\n };\n }\n const group = i => {\n return Number(agent.replace(r, '$' + i));\n };\n return nu$3(group(1), group(2));\n };\n const detect$4 = (versionRegexes, agent) => {\n const cleanedAgent = String(agent).toLowerCase();\n if (versionRegexes.length === 0) {\n return unknown$2();\n }\n return find$1(versionRegexes, cleanedAgent);\n };\n const unknown$2 = () => {\n return nu$3(0, 0);\n };\n const nu$3 = (major, minor) => {\n return {\n major,\n minor\n };\n };\n const Version = {\n nu: nu$3,\n detect: detect$4,\n unknown: unknown$2\n };\n\n const detectBrowser$1 = (browsers, userAgentData) => {\n return findMap(userAgentData.brands, uaBrand => {\n const lcBrand = uaBrand.brand.toLowerCase();\n return find$2(browsers, browser => {\n var _a;\n return lcBrand === ((_a = browser.brand) === null || _a === void 0 ? void 0 : _a.toLowerCase());\n }).map(info => ({\n current: info.name,\n version: Version.nu(parseInt(uaBrand.version, 10), 0)\n }));\n });\n };\n\n const detect$3 = (candidates, userAgent) => {\n const agent = String(userAgent).toLowerCase();\n return find$2(candidates, candidate => {\n return candidate.search(agent);\n });\n };\n const detectBrowser = (browsers, userAgent) => {\n return detect$3(browsers, userAgent).map(browser => {\n const version = Version.detect(browser.versionRegexes, userAgent);\n return {\n current: browser.name,\n version\n };\n });\n };\n const detectOs = (oses, userAgent) => {\n return detect$3(oses, userAgent).map(os => {\n const version = Version.detect(os.versionRegexes, userAgent);\n return {\n current: os.name,\n version\n };\n });\n };\n\n const removeFromStart = (str, numChars) => {\n return str.substring(numChars);\n };\n\n const checkRange = (str, substr, start) => substr === '' || str.length >= substr.length && str.substr(start, start + substr.length) === substr;\n const removeLeading = (str, prefix) => {\n return startsWith(str, prefix) ? removeFromStart(str, prefix.length) : str;\n };\n const contains$1 = (str, substr, start = 0, end) => {\n const idx = str.indexOf(substr, start);\n if (idx !== -1) {\n return isUndefined(end) ? true : idx + substr.length <= end;\n } else {\n return false;\n }\n };\n const startsWith = (str, prefix) => {\n return checkRange(str, prefix, 0);\n };\n const endsWith = (str, suffix) => {\n return checkRange(str, suffix, str.length - suffix.length);\n };\n const blank = r => s => s.replace(r, '');\n const trim$4 = blank(/^\\s+|\\s+$/g);\n const lTrim = blank(/^\\s+/g);\n const rTrim = blank(/\\s+$/g);\n const isNotEmpty = s => s.length > 0;\n const isEmpty$3 = s => !isNotEmpty(s);\n const repeat = (s, count) => count <= 0 ? '' : new Array(count + 1).join(s);\n const toInt = (value, radix = 10) => {\n const num = parseInt(value, radix);\n return isNaN(num) ? Optional.none() : Optional.some(num);\n };\n\n const normalVersionRegex = /.*?version\\/\\ ?([0-9]+)\\.([0-9]+).*/;\n const checkContains = target => {\n return uastring => {\n return contains$1(uastring, target);\n };\n };\n const browsers = [\n {\n name: 'Edge',\n versionRegexes: [/.*?edge\\/ ?([0-9]+)\\.([0-9]+)$/],\n search: uastring => {\n return contains$1(uastring, 'edge/') && contains$1(uastring, 'chrome') && contains$1(uastring, 'safari') && contains$1(uastring, 'applewebkit');\n }\n },\n {\n name: 'Chromium',\n brand: 'Chromium',\n versionRegexes: [\n /.*?chrome\\/([0-9]+)\\.([0-9]+).*/,\n normalVersionRegex\n ],\n search: uastring => {\n return contains$1(uastring, 'chrome') && !contains$1(uastring, 'chromeframe');\n }\n },\n {\n name: 'IE',\n versionRegexes: [\n /.*?msie\\ ?([0-9]+)\\.([0-9]+).*/,\n /.*?rv:([0-9]+)\\.([0-9]+).*/\n ],\n search: uastring => {\n return contains$1(uastring, 'msie') || contains$1(uastring, 'trident');\n }\n },\n {\n name: 'Opera',\n versionRegexes: [\n normalVersionRegex,\n /.*?opera\\/([0-9]+)\\.([0-9]+).*/\n ],\n search: checkContains('opera')\n },\n {\n name: 'Firefox',\n versionRegexes: [/.*?firefox\\/\\ ?([0-9]+)\\.([0-9]+).*/],\n search: checkContains('firefox')\n },\n {\n name: 'Safari',\n versionRegexes: [\n normalVersionRegex,\n /.*?cpu os ([0-9]+)_([0-9]+).*/\n ],\n search: uastring => {\n return (contains$1(uastring, 'safari') || contains$1(uastring, 'mobile/')) && contains$1(uastring, 'applewebkit');\n }\n }\n ];\n const oses = [\n {\n name: 'Windows',\n search: checkContains('win'),\n versionRegexes: [/.*?windows\\ nt\\ ?([0-9]+)\\.([0-9]+).*/]\n },\n {\n name: 'iOS',\n search: uastring => {\n return contains$1(uastring, 'iphone') || contains$1(uastring, 'ipad');\n },\n versionRegexes: [\n /.*?version\\/\\ ?([0-9]+)\\.([0-9]+).*/,\n /.*cpu os ([0-9]+)_([0-9]+).*/,\n /.*cpu iphone os ([0-9]+)_([0-9]+).*/\n ]\n },\n {\n name: 'Android',\n search: checkContains('android'),\n versionRegexes: [/.*?android\\ ?([0-9]+)\\.([0-9]+).*/]\n },\n {\n name: 'macOS',\n search: checkContains('mac os x'),\n versionRegexes: [/.*?mac\\ os\\ x\\ ?([0-9]+)_([0-9]+).*/]\n },\n {\n name: 'Linux',\n search: checkContains('linux'),\n versionRegexes: []\n },\n {\n name: 'Solaris',\n search: checkContains('sunos'),\n versionRegexes: []\n },\n {\n name: 'FreeBSD',\n search: checkContains('freebsd'),\n versionRegexes: []\n },\n {\n name: 'ChromeOS',\n search: checkContains('cros'),\n versionRegexes: [/.*?chrome\\/([0-9]+)\\.([0-9]+).*/]\n }\n ];\n const PlatformInfo = {\n browsers: constant(browsers),\n oses: constant(oses)\n };\n\n const edge = 'Edge';\n const chromium = 'Chromium';\n const ie = 'IE';\n const opera = 'Opera';\n const firefox = 'Firefox';\n const safari = 'Safari';\n const unknown$1 = () => {\n return nu$2({\n current: undefined,\n version: Version.unknown()\n });\n };\n const nu$2 = info => {\n const current = info.current;\n const version = info.version;\n const isBrowser = name => () => current === name;\n return {\n current,\n version,\n isEdge: isBrowser(edge),\n isChromium: isBrowser(chromium),\n isIE: isBrowser(ie),\n isOpera: isBrowser(opera),\n isFirefox: isBrowser(firefox),\n isSafari: isBrowser(safari)\n };\n };\n const Browser = {\n unknown: unknown$1,\n nu: nu$2,\n edge: constant(edge),\n chromium: constant(chromium),\n ie: constant(ie),\n opera: constant(opera),\n firefox: constant(firefox),\n safari: constant(safari)\n };\n\n const windows = 'Windows';\n const ios = 'iOS';\n const android = 'Android';\n const linux = 'Linux';\n const macos = 'macOS';\n const solaris = 'Solaris';\n const freebsd = 'FreeBSD';\n const chromeos = 'ChromeOS';\n const unknown = () => {\n return nu$1({\n current: undefined,\n version: Version.unknown()\n });\n };\n const nu$1 = info => {\n const current = info.current;\n const version = info.version;\n const isOS = name => () => current === name;\n return {\n current,\n version,\n isWindows: isOS(windows),\n isiOS: isOS(ios),\n isAndroid: isOS(android),\n isMacOS: isOS(macos),\n isLinux: isOS(linux),\n isSolaris: isOS(solaris),\n isFreeBSD: isOS(freebsd),\n isChromeOS: isOS(chromeos)\n };\n };\n const OperatingSystem = {\n unknown,\n nu: nu$1,\n windows: constant(windows),\n ios: constant(ios),\n android: constant(android),\n linux: constant(linux),\n macos: constant(macos),\n solaris: constant(solaris),\n freebsd: constant(freebsd),\n chromeos: constant(chromeos)\n };\n\n const detect$2 = (userAgent, userAgentDataOpt, mediaMatch) => {\n const browsers = PlatformInfo.browsers();\n const oses = PlatformInfo.oses();\n const browser = userAgentDataOpt.bind(userAgentData => detectBrowser$1(browsers, userAgentData)).orThunk(() => detectBrowser(browsers, userAgent)).fold(Browser.unknown, Browser.nu);\n const os = detectOs(oses, userAgent).fold(OperatingSystem.unknown, OperatingSystem.nu);\n const deviceType = DeviceType(os, browser, userAgent, mediaMatch);\n return {\n browser,\n os,\n deviceType\n };\n };\n const PlatformDetection = { detect: detect$2 };\n\n const mediaMatch = query => window.matchMedia(query).matches;\n let platform$4 = cached(() => PlatformDetection.detect(window.navigator.userAgent, Optional.from(window.navigator.userAgentData), mediaMatch));\n const detect$1 = () => platform$4();\n\n const userAgent = window.navigator.userAgent;\n const platform$3 = detect$1();\n const browser$3 = platform$3.browser;\n const os$1 = platform$3.os;\n const deviceType = platform$3.deviceType;\n const windowsPhone = userAgent.indexOf('Windows Phone') !== -1;\n const Env = {\n transparentSrc: 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7',\n documentMode: browser$3.isIE() ? document.documentMode || 7 : 10,\n cacheSuffix: null,\n container: null,\n canHaveCSP: !browser$3.isIE(),\n windowsPhone,\n browser: {\n current: browser$3.current,\n version: browser$3.version,\n isChromium: browser$3.isChromium,\n isEdge: browser$3.isEdge,\n isFirefox: browser$3.isFirefox,\n isIE: browser$3.isIE,\n isOpera: browser$3.isOpera,\n isSafari: browser$3.isSafari\n },\n os: {\n current: os$1.current,\n version: os$1.version,\n isAndroid: os$1.isAndroid,\n isChromeOS: os$1.isChromeOS,\n isFreeBSD: os$1.isFreeBSD,\n isiOS: os$1.isiOS,\n isLinux: os$1.isLinux,\n isMacOS: os$1.isMacOS,\n isSolaris: os$1.isSolaris,\n isWindows: os$1.isWindows\n },\n deviceType: {\n isDesktop: deviceType.isDesktop,\n isiPad: deviceType.isiPad,\n isiPhone: deviceType.isiPhone,\n isPhone: deviceType.isPhone,\n isTablet: deviceType.isTablet,\n isTouch: deviceType.isTouch,\n isWebView: deviceType.isWebView\n }\n };\n\n const whiteSpaceRegExp$1 = /^\\s*|\\s*$/g;\n const trim$3 = str => {\n return isNullable(str) ? '' : ('' + str).replace(whiteSpaceRegExp$1, '');\n };\n const is$3 = (obj, type) => {\n if (!type) {\n return obj !== undefined;\n }\n if (type === 'array' && isArray(obj)) {\n return true;\n }\n return typeof obj === type;\n };\n const makeMap$4 = (items, delim, map = {}) => {\n const resolvedItems = isString(items) ? items.split(delim || ',') : items || [];\n let i = resolvedItems.length;\n while (i--) {\n map[resolvedItems[i]] = {};\n }\n return map;\n };\n const hasOwnProperty = has$2;\n const extend$3 = (obj, ...exts) => {\n for (let i = 0; i < exts.length; i++) {\n const ext = exts[i];\n for (const name in ext) {\n if (has$2(ext, name)) {\n const value = ext[name];\n if (value !== undefined) {\n obj[name] = value;\n }\n }\n }\n }\n return obj;\n };\n const walk$4 = function (o, f, n, s) {\n s = s || this;\n if (o) {\n if (n) {\n o = o[n];\n }\n each$c(o, (o, i) => {\n if (f.call(s, o, i, n) === false) {\n return false;\n } else {\n walk$4(o, f, n, s);\n return true;\n }\n });\n }\n };\n const resolve$3 = (n, o = window) => {\n const path = n.split('.');\n for (let i = 0, l = path.length; i < l; i++) {\n o = o[path[i]];\n if (!o) {\n break;\n }\n }\n return o;\n };\n const explode$3 = (s, d) => {\n if (isArray$1(s)) {\n return s;\n } else if (s === '') {\n return [];\n } else {\n return map$1(s.split(d || ','), trim$3);\n }\n };\n const _addCacheSuffix = url => {\n const cacheSuffix = Env.cacheSuffix;\n if (cacheSuffix) {\n url += (url.indexOf('?') === -1 ? '?' : '&') + cacheSuffix;\n }\n return url;\n };\n const Tools = {\n trim: trim$3,\n isArray: isArray,\n is: is$3,\n toArray: toArray$1,\n makeMap: makeMap$4,\n each: each$c,\n map: map$1,\n grep: filter$3,\n inArray: indexOf,\n hasOwn: hasOwnProperty,\n extend: extend$3,\n walk: walk$4,\n resolve: resolve$3,\n explode: explode$3,\n _addCacheSuffix\n };\n\n const is$2 = (lhs, rhs, comparator = tripleEquals) => lhs.exists(left => comparator(left, rhs));\n const equals = (lhs, rhs, comparator = tripleEquals) => lift2(lhs, rhs, comparator).getOr(lhs.isNone() && rhs.isNone());\n const cat = arr => {\n const r = [];\n const push = x => {\n r.push(x);\n };\n for (let i = 0; i < arr.length; i++) {\n arr[i].each(push);\n }\n return r;\n };\n const lift2 = (oa, ob, f) => oa.isSome() && ob.isSome() ? Optional.some(f(oa.getOrDie(), ob.getOrDie())) : Optional.none();\n const lift3 = (oa, ob, oc, f) => oa.isSome() && ob.isSome() && oc.isSome() ? Optional.some(f(oa.getOrDie(), ob.getOrDie(), oc.getOrDie())) : Optional.none();\n const someIf = (b, a) => b ? Optional.some(a) : Optional.none();\n\n const Global = typeof window !== 'undefined' ? window : Function('return this;')();\n\n const path = (parts, scope) => {\n let o = scope !== undefined && scope !== null ? scope : Global;\n for (let i = 0; i < parts.length && o !== undefined && o !== null; ++i) {\n o = o[parts[i]];\n }\n return o;\n };\n const resolve$2 = (p, scope) => {\n const parts = p.split('.');\n return path(parts, scope);\n };\n\n const unsafe = (name, scope) => {\n return resolve$2(name, scope);\n };\n const getOrDie = (name, scope) => {\n const actual = unsafe(name, scope);\n if (actual === undefined || actual === null) {\n throw new Error(name + ' not available on this browser');\n }\n return actual;\n };\n\n const getPrototypeOf$1 = Object.getPrototypeOf;\n const sandHTMLElement = scope => {\n return getOrDie('HTMLElement', scope);\n };\n const isPrototypeOf = x => {\n const scope = resolve$2('ownerDocument.defaultView', x);\n return isObject(x) && (sandHTMLElement(scope).prototype.isPrototypeOf(x) || /^HTML\\w*Element$/.test(getPrototypeOf$1(x).constructor.name));\n };\n\n const COMMENT = 8;\n const DOCUMENT = 9;\n const DOCUMENT_FRAGMENT = 11;\n const ELEMENT = 1;\n const TEXT = 3;\n\n const name = element => {\n const r = element.dom.nodeName;\n return r.toLowerCase();\n };\n const type$1 = element => element.dom.nodeType;\n const isType = t => element => type$1(element) === t;\n const isComment$1 = element => type$1(element) === COMMENT || name(element) === '#comment';\n const isHTMLElement$1 = element => isElement$7(element) && isPrototypeOf(element.dom);\n const isElement$7 = isType(ELEMENT);\n const isText$c = isType(TEXT);\n const isDocument$2 = isType(DOCUMENT);\n const isDocumentFragment$1 = isType(DOCUMENT_FRAGMENT);\n const isTag = tag => e => isElement$7(e) && name(e) === tag;\n\n const rawSet = (dom, key, value) => {\n if (isString(value) || isBoolean(value) || isNumber(value)) {\n dom.setAttribute(key, value + '');\n } else {\n console.error('Invalid call to Attribute.set. Key ', key, ':: Value ', value, ':: Element ', dom);\n throw new Error('Attribute value was not simple');\n }\n };\n const set$4 = (element, key, value) => {\n rawSet(element.dom, key, value);\n };\n const setAll$1 = (element, attrs) => {\n const dom = element.dom;\n each$d(attrs, (v, k) => {\n rawSet(dom, k, v);\n });\n };\n const get$9 = (element, key) => {\n const v = element.dom.getAttribute(key);\n return v === null ? undefined : v;\n };\n const getOpt = (element, key) => Optional.from(get$9(element, key));\n const has$1 = (element, key) => {\n const dom = element.dom;\n return dom && dom.hasAttribute ? dom.hasAttribute(key) : false;\n };\n const remove$9 = (element, key) => {\n element.dom.removeAttribute(key);\n };\n const hasNone = element => {\n const attrs = element.dom.attributes;\n return attrs === undefined || attrs === null || attrs.length === 0;\n };\n const clone$4 = element => foldl(element.dom.attributes, (acc, attr) => {\n acc[attr.name] = attr.value;\n return acc;\n }, {});\n\n const read$4 = (element, attr) => {\n const value = get$9(element, attr);\n return value === undefined || value === '' ? [] : value.split(' ');\n };\n const add$4 = (element, attr, id) => {\n const old = read$4(element, attr);\n const nu = old.concat([id]);\n set$4(element, attr, nu.join(' '));\n return true;\n };\n const remove$8 = (element, attr, id) => {\n const nu = filter$5(read$4(element, attr), v => v !== id);\n if (nu.length > 0) {\n set$4(element, attr, nu.join(' '));\n } else {\n remove$9(element, attr);\n }\n return false;\n };\n\n const supports = element => element.dom.classList !== undefined;\n const get$8 = element => read$4(element, 'class');\n const add$3 = (element, clazz) => add$4(element, 'class', clazz);\n const remove$7 = (element, clazz) => remove$8(element, 'class', clazz);\n const toggle$2 = (element, clazz) => {\n if (contains$2(get$8(element), clazz)) {\n return remove$7(element, clazz);\n } else {\n return add$3(element, clazz);\n }\n };\n\n const add$2 = (element, clazz) => {\n if (supports(element)) {\n element.dom.classList.add(clazz);\n } else {\n add$3(element, clazz);\n }\n };\n const cleanClass = element => {\n const classList = supports(element) ? element.dom.classList : get$8(element);\n if (classList.length === 0) {\n remove$9(element, 'class');\n }\n };\n const remove$6 = (element, clazz) => {\n if (supports(element)) {\n const classList = element.dom.classList;\n classList.remove(clazz);\n } else {\n remove$7(element, clazz);\n }\n cleanClass(element);\n };\n const toggle$1 = (element, clazz) => {\n const result = supports(element) ? element.dom.classList.toggle(clazz) : toggle$2(element, clazz);\n cleanClass(element);\n return result;\n };\n const has = (element, clazz) => supports(element) && element.dom.classList.contains(clazz);\n\n const fromHtml$1 = (html, scope) => {\n const doc = scope || document;\n const div = doc.createElement('div');\n div.innerHTML = html;\n if (!div.hasChildNodes() || div.childNodes.length > 1) {\n const message = 'HTML does not have a single root node';\n console.error(message, html);\n throw new Error(message);\n }\n return fromDom$2(div.childNodes[0]);\n };\n const fromTag = (tag, scope) => {\n const doc = scope || document;\n const node = doc.createElement(tag);\n return fromDom$2(node);\n };\n const fromText = (text, scope) => {\n const doc = scope || document;\n const node = doc.createTextNode(text);\n return fromDom$2(node);\n };\n const fromDom$2 = node => {\n if (node === null || node === undefined) {\n throw new Error('Node cannot be null or undefined');\n }\n return { dom: node };\n };\n const fromPoint$2 = (docElm, x, y) => Optional.from(docElm.dom.elementFromPoint(x, y)).map(fromDom$2);\n const SugarElement = {\n fromHtml: fromHtml$1,\n fromTag,\n fromText,\n fromDom: fromDom$2,\n fromPoint: fromPoint$2\n };\n\n const toArray = (target, f) => {\n const r = [];\n const recurse = e => {\n r.push(e);\n return f(e);\n };\n let cur = f(target);\n do {\n cur = cur.bind(recurse);\n } while (cur.isSome());\n return r;\n };\n\n const is$1 = (element, selector) => {\n const dom = element.dom;\n if (dom.nodeType !== ELEMENT) {\n return false;\n } else {\n const elem = dom;\n if (elem.matches !== undefined) {\n return elem.matches(selector);\n } else if (elem.msMatchesSelector !== undefined) {\n return elem.msMatchesSelector(selector);\n } else if (elem.webkitMatchesSelector !== undefined) {\n return elem.webkitMatchesSelector(selector);\n } else if (elem.mozMatchesSelector !== undefined) {\n return elem.mozMatchesSelector(selector);\n } else {\n throw new Error('Browser lacks native selectors');\n }\n }\n };\n const bypassSelector = dom => dom.nodeType !== ELEMENT && dom.nodeType !== DOCUMENT && dom.nodeType !== DOCUMENT_FRAGMENT || dom.childElementCount === 0;\n const all = (selector, scope) => {\n const base = scope === undefined ? document : scope.dom;\n return bypassSelector(base) ? [] : map$3(base.querySelectorAll(selector), SugarElement.fromDom);\n };\n const one = (selector, scope) => {\n const base = scope === undefined ? document : scope.dom;\n return bypassSelector(base) ? Optional.none() : Optional.from(base.querySelector(selector)).map(SugarElement.fromDom);\n };\n\n const eq = (e1, e2) => e1.dom === e2.dom;\n const contains = (e1, e2) => {\n const d1 = e1.dom;\n const d2 = e2.dom;\n return d1 === d2 ? false : d1.contains(d2);\n };\n\n const owner$1 = element => SugarElement.fromDom(element.dom.ownerDocument);\n const documentOrOwner = dos => isDocument$2(dos) ? dos : owner$1(dos);\n const documentElement = element => SugarElement.fromDom(documentOrOwner(element).dom.documentElement);\n const defaultView = element => SugarElement.fromDom(documentOrOwner(element).dom.defaultView);\n const parent = element => Optional.from(element.dom.parentNode).map(SugarElement.fromDom);\n const parentElement = element => Optional.from(element.dom.parentElement).map(SugarElement.fromDom);\n const parents$1 = (element, isRoot) => {\n const stop = isFunction(isRoot) ? isRoot : never;\n let dom = element.dom;\n const ret = [];\n while (dom.parentNode !== null && dom.parentNode !== undefined) {\n const rawParent = dom.parentNode;\n const p = SugarElement.fromDom(rawParent);\n ret.push(p);\n if (stop(p) === true) {\n break;\n } else {\n dom = rawParent;\n }\n }\n return ret;\n };\n const siblings = element => {\n const filterSelf = elements => filter$5(elements, x => !eq(element, x));\n return parent(element).map(children$1).map(filterSelf).getOr([]);\n };\n const prevSibling = element => Optional.from(element.dom.previousSibling).map(SugarElement.fromDom);\n const nextSibling = element => Optional.from(element.dom.nextSibling).map(SugarElement.fromDom);\n const prevSiblings = element => reverse(toArray(element, prevSibling));\n const nextSiblings = element => toArray(element, nextSibling);\n const children$1 = element => map$3(element.dom.childNodes, SugarElement.fromDom);\n const child$1 = (element, index) => {\n const cs = element.dom.childNodes;\n return Optional.from(cs[index]).map(SugarElement.fromDom);\n };\n const firstChild = element => child$1(element, 0);\n const lastChild = element => child$1(element, element.dom.childNodes.length - 1);\n const childNodesCount = element => element.dom.childNodes.length;\n\n const getHead = doc => {\n const b = doc.dom.head;\n if (b === null || b === undefined) {\n throw new Error('Head is not available yet');\n }\n return SugarElement.fromDom(b);\n };\n\n const isShadowRoot = dos => isDocumentFragment$1(dos) && isNonNullable(dos.dom.host);\n const getRootNode = e => SugarElement.fromDom(e.dom.getRootNode());\n const getStyleContainer = dos => isShadowRoot(dos) ? dos : getHead(documentOrOwner(dos));\n const getContentContainer = dos => isShadowRoot(dos) ? dos : SugarElement.fromDom(documentOrOwner(dos).dom.body);\n const getShadowRoot = e => {\n const r = getRootNode(e);\n return isShadowRoot(r) ? Optional.some(r) : Optional.none();\n };\n const getShadowHost = e => SugarElement.fromDom(e.dom.host);\n const getOriginalEventTarget = event => {\n if (isNonNullable(event.target)) {\n const el = SugarElement.fromDom(event.target);\n if (isElement$7(el) && isOpenShadowHost(el)) {\n if (event.composed && event.composedPath) {\n const composedPath = event.composedPath();\n if (composedPath) {\n return head(composedPath);\n }\n }\n }\n }\n return Optional.from(event.target);\n };\n const isOpenShadowHost = element => isNonNullable(element.dom.shadowRoot);\n\n const inBody = element => {\n const dom = isText$c(element) ? element.dom.parentNode : element.dom;\n if (dom === undefined || dom === null || dom.ownerDocument === null) {\n return false;\n }\n const doc = dom.ownerDocument;\n return getShadowRoot(SugarElement.fromDom(dom)).fold(() => doc.body.contains(dom), compose1(inBody, getShadowHost));\n };\n\n var ClosestOrAncestor = (is, ancestor, scope, a, isRoot) => {\n if (is(scope, a)) {\n return Optional.some(scope);\n } else if (isFunction(isRoot) && isRoot(scope)) {\n return Optional.none();\n } else {\n return ancestor(scope, a, isRoot);\n }\n };\n\n const ancestor$4 = (scope, predicate, isRoot) => {\n let element = scope.dom;\n const stop = isFunction(isRoot) ? isRoot : never;\n while (element.parentNode) {\n element = element.parentNode;\n const el = SugarElement.fromDom(element);\n if (predicate(el)) {\n return Optional.some(el);\n } else if (stop(el)) {\n break;\n }\n }\n return Optional.none();\n };\n const closest$4 = (scope, predicate, isRoot) => {\n const is = (s, test) => test(s);\n return ClosestOrAncestor(is, ancestor$4, scope, predicate, isRoot);\n };\n const sibling$1 = (scope, predicate) => {\n const element = scope.dom;\n if (!element.parentNode) {\n return Optional.none();\n }\n return child(SugarElement.fromDom(element.parentNode), x => !eq(scope, x) && predicate(x));\n };\n const child = (scope, predicate) => {\n const pred = node => predicate(SugarElement.fromDom(node));\n const result = find$2(scope.dom.childNodes, pred);\n return result.map(SugarElement.fromDom);\n };\n const descendant$2 = (scope, predicate) => {\n const descend = node => {\n for (let i = 0; i < node.childNodes.length; i++) {\n const child = SugarElement.fromDom(node.childNodes[i]);\n if (predicate(child)) {\n return Optional.some(child);\n }\n const res = descend(node.childNodes[i]);\n if (res.isSome()) {\n return res;\n }\n }\n return Optional.none();\n };\n return descend(scope.dom);\n };\n\n const ancestor$3 = (scope, selector, isRoot) => ancestor$4(scope, e => is$1(e, selector), isRoot);\n const descendant$1 = (scope, selector) => one(selector, scope);\n const closest$3 = (scope, selector, isRoot) => {\n const is = (element, selector) => is$1(element, selector);\n return ClosestOrAncestor(is, ancestor$3, scope, selector, isRoot);\n };\n\n const closest$2 = target => closest$3(target, '[contenteditable]');\n const isEditable$2 = (element, assumeEditable = false) => {\n if (inBody(element)) {\n return element.dom.isContentEditable;\n } else {\n return closest$2(element).fold(constant(assumeEditable), editable => getRaw$1(editable) === 'true');\n }\n };\n const getRaw$1 = element => element.dom.contentEditable;\n const set$3 = (element, editable) => {\n element.dom.contentEditable = editable ? 'true' : 'false';\n };\n\n const isSupported = dom => dom.style !== undefined && isFunction(dom.style.getPropertyValue);\n\n const internalSet = (dom, property, value) => {\n if (!isString(value)) {\n console.error('Invalid call to CSS.set. Property ', property, ':: Value ', value, ':: Element ', dom);\n throw new Error('CSS value must be a string: ' + value);\n }\n if (isSupported(dom)) {\n dom.style.setProperty(property, value);\n }\n };\n const internalRemove = (dom, property) => {\n if (isSupported(dom)) {\n dom.style.removeProperty(property);\n }\n };\n const set$2 = (element, property, value) => {\n const dom = element.dom;\n internalSet(dom, property, value);\n };\n const setAll = (element, css) => {\n const dom = element.dom;\n each$d(css, (v, k) => {\n internalSet(dom, k, v);\n });\n };\n const get$7 = (element, property) => {\n const dom = element.dom;\n const styles = window.getComputedStyle(dom);\n const r = styles.getPropertyValue(property);\n return r === '' && !inBody(element) ? getUnsafeProperty(dom, property) : r;\n };\n const getUnsafeProperty = (dom, property) => isSupported(dom) ? dom.style.getPropertyValue(property) : '';\n const getRaw = (element, property) => {\n const dom = element.dom;\n const raw = getUnsafeProperty(dom, property);\n return Optional.from(raw).filter(r => r.length > 0);\n };\n const getAllRaw = element => {\n const css = {};\n const dom = element.dom;\n if (isSupported(dom)) {\n for (let i = 0; i < dom.style.length; i++) {\n const ruleName = dom.style.item(i);\n css[ruleName] = dom.style[ruleName];\n }\n }\n return css;\n };\n const remove$5 = (element, property) => {\n const dom = element.dom;\n internalRemove(dom, property);\n if (is$2(getOpt(element, 'style').map(trim$4), '')) {\n remove$9(element, 'style');\n }\n };\n const reflow = e => e.dom.offsetWidth;\n\n const before$3 = (marker, element) => {\n const parent$1 = parent(marker);\n parent$1.each(v => {\n v.dom.insertBefore(element.dom, marker.dom);\n });\n };\n const after$4 = (marker, element) => {\n const sibling = nextSibling(marker);\n sibling.fold(() => {\n const parent$1 = parent(marker);\n parent$1.each(v => {\n append$1(v, element);\n });\n }, v => {\n before$3(v, element);\n });\n };\n const prepend = (parent, element) => {\n const firstChild$1 = firstChild(parent);\n firstChild$1.fold(() => {\n append$1(parent, element);\n }, v => {\n parent.dom.insertBefore(element.dom, v.dom);\n });\n };\n const append$1 = (parent, element) => {\n parent.dom.appendChild(element.dom);\n };\n const wrap$2 = (element, wrapper) => {\n before$3(element, wrapper);\n append$1(wrapper, element);\n };\n\n const after$3 = (marker, elements) => {\n each$e(elements, (x, i) => {\n const e = i === 0 ? marker : elements[i - 1];\n after$4(e, x);\n });\n };\n const append = (parent, elements) => {\n each$e(elements, x => {\n append$1(parent, x);\n });\n };\n\n const empty = element => {\n element.dom.textContent = '';\n each$e(children$1(element), rogue => {\n remove$4(rogue);\n });\n };\n const remove$4 = element => {\n const dom = element.dom;\n if (dom.parentNode !== null) {\n dom.parentNode.removeChild(dom);\n }\n };\n const unwrap = wrapper => {\n const children = children$1(wrapper);\n if (children.length > 0) {\n after$3(wrapper, children);\n }\n remove$4(wrapper);\n };\n\n const fromHtml = (html, scope) => {\n const doc = scope || document;\n const div = doc.createElement('div');\n div.innerHTML = html;\n return children$1(SugarElement.fromDom(div));\n };\n const fromDom$1 = nodes => map$3(nodes, SugarElement.fromDom);\n\n const get$6 = element => element.dom.innerHTML;\n const set$1 = (element, content) => {\n const owner = owner$1(element);\n const docDom = owner.dom;\n const fragment = SugarElement.fromDom(docDom.createDocumentFragment());\n const contentElements = fromHtml(content, docDom);\n append(fragment, contentElements);\n empty(element);\n append$1(element, fragment);\n };\n const getOuter = element => {\n const container = SugarElement.fromTag('div');\n const clone = SugarElement.fromDom(element.dom.cloneNode(true));\n append$1(container, clone);\n return get$6(container);\n };\n\n const mkEvent = (target, x, y, stop, prevent, kill, raw) => ({\n target,\n x,\n y,\n stop,\n prevent,\n kill,\n raw\n });\n const fromRawEvent = rawEvent => {\n const target = SugarElement.fromDom(getOriginalEventTarget(rawEvent).getOr(rawEvent.target));\n const stop = () => rawEvent.stopPropagation();\n const prevent = () => rawEvent.preventDefault();\n const kill = compose(prevent, stop);\n return mkEvent(target, rawEvent.clientX, rawEvent.clientY, stop, prevent, kill, rawEvent);\n };\n const handle$1 = (filter, handler) => rawEvent => {\n if (filter(rawEvent)) {\n handler(fromRawEvent(rawEvent));\n }\n };\n const binder = (element, event, filter, handler, useCapture) => {\n const wrapped = handle$1(filter, handler);\n element.dom.addEventListener(event, wrapped, useCapture);\n return { unbind: curry(unbind, element, event, wrapped, useCapture) };\n };\n const bind$2 = (element, event, filter, handler) => binder(element, event, filter, handler, false);\n const unbind = (element, event, handler, useCapture) => {\n element.dom.removeEventListener(event, handler, useCapture);\n };\n\n const r = (left, top) => {\n const translate = (x, y) => r(left + x, top + y);\n return {\n left,\n top,\n translate\n };\n };\n const SugarPosition = r;\n\n const boxPosition = dom => {\n const box = dom.getBoundingClientRect();\n return SugarPosition(box.left, box.top);\n };\n const firstDefinedOrZero = (a, b) => {\n if (a !== undefined) {\n return a;\n } else {\n return b !== undefined ? b : 0;\n }\n };\n const absolute = element => {\n const doc = element.dom.ownerDocument;\n const body = doc.body;\n const win = doc.defaultView;\n const html = doc.documentElement;\n if (body === element.dom) {\n return SugarPosition(body.offsetLeft, body.offsetTop);\n }\n const scrollTop = firstDefinedOrZero(win === null || win === void 0 ? void 0 : win.pageYOffset, html.scrollTop);\n const scrollLeft = firstDefinedOrZero(win === null || win === void 0 ? void 0 : win.pageXOffset, html.scrollLeft);\n const clientTop = firstDefinedOrZero(html.clientTop, body.clientTop);\n const clientLeft = firstDefinedOrZero(html.clientLeft, body.clientLeft);\n return viewport(element).translate(scrollLeft - clientLeft, scrollTop - clientTop);\n };\n const viewport = element => {\n const dom = element.dom;\n const doc = dom.ownerDocument;\n const body = doc.body;\n if (body === dom) {\n return SugarPosition(body.offsetLeft, body.offsetTop);\n }\n if (!inBody(element)) {\n return SugarPosition(0, 0);\n }\n return boxPosition(dom);\n };\n\n const get$5 = _DOC => {\n const doc = _DOC !== undefined ? _DOC.dom : document;\n const x = doc.body.scrollLeft || doc.documentElement.scrollLeft;\n const y = doc.body.scrollTop || doc.documentElement.scrollTop;\n return SugarPosition(x, y);\n };\n const to = (x, y, _DOC) => {\n const doc = _DOC !== undefined ? _DOC.dom : document;\n const win = doc.defaultView;\n if (win) {\n win.scrollTo(x, y);\n }\n };\n const intoView = (element, alignToTop) => {\n const isSafari = detect$1().browser.isSafari();\n if (isSafari && isFunction(element.dom.scrollIntoViewIfNeeded)) {\n element.dom.scrollIntoViewIfNeeded(false);\n } else {\n element.dom.scrollIntoView(alignToTop);\n }\n };\n\n const get$4 = _win => {\n const win = _win === undefined ? window : _win;\n if (detect$1().browser.isFirefox()) {\n return Optional.none();\n } else {\n return Optional.from(win.visualViewport);\n }\n };\n const bounds = (x, y, width, height) => ({\n x,\n y,\n width,\n height,\n right: x + width,\n bottom: y + height\n });\n const getBounds = _win => {\n const win = _win === undefined ? window : _win;\n const doc = win.document;\n const scroll = get$5(SugarElement.fromDom(doc));\n return get$4(win).fold(() => {\n const html = win.document.documentElement;\n const width = html.clientWidth;\n const height = html.clientHeight;\n return bounds(scroll.left, scroll.top, width, height);\n }, visualViewport => bounds(Math.max(visualViewport.pageLeft, scroll.left), Math.max(visualViewport.pageTop, scroll.top), visualViewport.width, visualViewport.height));\n };\n\n const children = (scope, predicate) => filter$5(children$1(scope), predicate);\n const descendants$1 = (scope, predicate) => {\n let result = [];\n each$e(children$1(scope), x => {\n if (predicate(x)) {\n result = result.concat([x]);\n }\n result = result.concat(descendants$1(x, predicate));\n });\n return result;\n };\n\n const descendants = (scope, selector) => all(selector, scope);\n\n const ancestor$2 = (scope, predicate, isRoot) => ancestor$4(scope, predicate, isRoot).isSome();\n const sibling = (scope, predicate) => sibling$1(scope, predicate).isSome();\n const descendant = (scope, predicate) => descendant$2(scope, predicate).isSome();\n\n class DomTreeWalker {\n constructor(startNode, rootNode) {\n this.node = startNode;\n this.rootNode = rootNode;\n this.current = this.current.bind(this);\n this.next = this.next.bind(this);\n this.prev = this.prev.bind(this);\n this.prev2 = this.prev2.bind(this);\n }\n current() {\n return this.node;\n }\n next(shallow) {\n this.node = this.findSibling(this.node, 'firstChild', 'nextSibling', shallow);\n return this.node;\n }\n prev(shallow) {\n this.node = this.findSibling(this.node, 'lastChild', 'previousSibling', shallow);\n return this.node;\n }\n prev2(shallow) {\n this.node = this.findPreviousNode(this.node, shallow);\n return this.node;\n }\n findSibling(node, startName, siblingName, shallow) {\n if (node) {\n if (!shallow && node[startName]) {\n return node[startName];\n }\n if (node !== this.rootNode) {\n let sibling = node[siblingName];\n if (sibling) {\n return sibling;\n }\n for (let parent = node.parentNode; parent && parent !== this.rootNode; parent = parent.parentNode) {\n sibling = parent[siblingName];\n if (sibling) {\n return sibling;\n }\n }\n }\n }\n return undefined;\n }\n findPreviousNode(node, shallow) {\n if (node) {\n const sibling = node.previousSibling;\n if (this.rootNode && sibling === this.rootNode) {\n return;\n }\n if (sibling) {\n if (!shallow) {\n for (let child = sibling.lastChild; child; child = child.lastChild) {\n if (!child.lastChild) {\n return child;\n }\n }\n }\n return sibling;\n }\n const parent = node.parentNode;\n if (parent && parent !== this.rootNode) {\n return parent;\n }\n }\n return undefined;\n }\n }\n\n const zeroWidth = '\\uFEFF';\n const nbsp = '\\xA0';\n const isZwsp$2 = char => char === zeroWidth;\n const removeZwsp = s => s.replace(/\\uFEFF/g, '');\n\n const whiteSpaceRegExp = /^[ \\t\\r\\n]*$/;\n const isWhitespaceText = text => whiteSpaceRegExp.test(text);\n const isZwsp$1 = text => {\n for (const c of text) {\n if (!isZwsp$2(c)) {\n return false;\n }\n }\n return true;\n };\n const isCollapsibleWhitespace$1 = c => ' \\f\\t\\x0B'.indexOf(c) !== -1;\n const isNewLineChar = c => c === '\\n' || c === '\\r';\n const isNewline = (text, idx) => idx < text.length && idx >= 0 ? isNewLineChar(text[idx]) : false;\n const normalize$4 = (text, tabSpaces = 4, isStartOfContent = true, isEndOfContent = true) => {\n const tabSpace = repeat(' ', tabSpaces);\n const normalizedText = text.replace(/\\t/g, tabSpace);\n const result = foldl(normalizedText, (acc, c) => {\n if (isCollapsibleWhitespace$1(c) || c === nbsp) {\n if (acc.pcIsSpace || acc.str === '' && isStartOfContent || acc.str.length === normalizedText.length - 1 && isEndOfContent || isNewline(normalizedText, acc.str.length + 1)) {\n return {\n pcIsSpace: false,\n str: acc.str + nbsp\n };\n } else {\n return {\n pcIsSpace: true,\n str: acc.str + ' '\n };\n }\n } else {\n return {\n pcIsSpace: isNewLineChar(c),\n str: acc.str + c\n };\n }\n }, {\n pcIsSpace: false,\n str: ''\n });\n return result.str;\n };\n\n const isNodeType = type => {\n return node => {\n return !!node && node.nodeType === type;\n };\n };\n const isRestrictedNode = node => !!node && !Object.getPrototypeOf(node);\n const isElement$6 = isNodeType(1);\n const isHTMLElement = node => isElement$6(node) && isHTMLElement$1(SugarElement.fromDom(node));\n const isSVGElement = node => isElement$6(node) && node.namespaceURI === 'http://www.w3.org/2000/svg';\n const matchNodeName = name => {\n const lowerCasedName = name.toLowerCase();\n return node => isNonNullable(node) && node.nodeName.toLowerCase() === lowerCasedName;\n };\n const matchNodeNames = names => {\n const lowerCasedNames = names.map(s => s.toLowerCase());\n return node => {\n if (node && node.nodeName) {\n const nodeName = node.nodeName.toLowerCase();\n return contains$2(lowerCasedNames, nodeName);\n }\n return false;\n };\n };\n const matchStyleValues = (name, values) => {\n const items = values.toLowerCase().split(' ');\n return node => {\n if (isElement$6(node)) {\n const win = node.ownerDocument.defaultView;\n if (win) {\n for (let i = 0; i < items.length; i++) {\n const computed = win.getComputedStyle(node, null);\n const cssValue = computed ? computed.getPropertyValue(name) : null;\n if (cssValue === items[i]) {\n return true;\n }\n }\n }\n }\n return false;\n };\n };\n const hasAttribute = attrName => {\n return node => {\n return isElement$6(node) && node.hasAttribute(attrName);\n };\n };\n const isBogus$1 = node => isElement$6(node) && node.hasAttribute('data-mce-bogus');\n const isBogusAll = node => isElement$6(node) && node.getAttribute('data-mce-bogus') === 'all';\n const isTable$2 = node => isElement$6(node) && node.tagName === 'TABLE';\n const hasContentEditableState = value => {\n return node => {\n if (isHTMLElement(node)) {\n if (node.contentEditable === value) {\n return true;\n }\n if (node.getAttribute('data-mce-contenteditable') === value) {\n return true;\n }\n }\n return false;\n };\n };\n const isTextareaOrInput = matchNodeNames([\n 'textarea',\n 'input'\n ]);\n const isText$b = isNodeType(3);\n const isCData = isNodeType(4);\n const isPi = isNodeType(7);\n const isComment = isNodeType(8);\n const isDocument$1 = isNodeType(9);\n const isDocumentFragment = isNodeType(11);\n const isBr$6 = matchNodeName('br');\n const isImg = matchNodeName('img');\n const isContentEditableTrue$3 = hasContentEditableState('true');\n const isContentEditableFalse$b = hasContentEditableState('false');\n const isTableCell$3 = matchNodeNames([\n 'td',\n 'th'\n ]);\n const isTableCellOrCaption = matchNodeNames([\n 'td',\n 'th',\n 'caption'\n ]);\n const isMedia$2 = matchNodeNames([\n 'video',\n 'audio',\n 'object',\n 'embed'\n ]);\n const isListItem$2 = matchNodeName('li');\n const isDetails = matchNodeName('details');\n const isSummary$1 = matchNodeName('summary');\n\n const defaultOptionValues = {\n skipBogus: true,\n includeZwsp: false,\n checkRootAsContent: false\n };\n const hasWhitespacePreserveParent = (node, rootNode, schema) => {\n const rootElement = SugarElement.fromDom(rootNode);\n const startNode = SugarElement.fromDom(node);\n const whitespaceElements = schema.getWhitespaceElements();\n const predicate = node => has$2(whitespaceElements, name(node));\n return ancestor$2(startNode, predicate, curry(eq, rootElement));\n };\n const isNamedAnchor = node => {\n return isElement$6(node) && node.nodeName === 'A' && !node.hasAttribute('href') && (node.hasAttribute('name') || node.hasAttribute('id'));\n };\n const isNonEmptyElement$1 = (node, schema) => {\n return isElement$6(node) && has$2(schema.getNonEmptyElements(), node.nodeName);\n };\n const isBookmark = hasAttribute('data-mce-bookmark');\n const hasNonEditableParent = node => parentElement(SugarElement.fromDom(node)).exists(parent => !isEditable$2(parent));\n const isWhitespace$1 = (node, rootNode, schema) => isWhitespaceText(node.data) && !hasWhitespacePreserveParent(node, rootNode, schema);\n const isText$a = (node, rootNode, schema, options) => isText$b(node) && !isWhitespace$1(node, rootNode, schema) && (!options.includeZwsp || !isZwsp$1(node.data));\n const isContentNode = (schema, node, rootNode, options) => {\n return isFunction(options.isContent) && options.isContent(node) || isNonEmptyElement$1(node, schema) || isBookmark(node) || isNamedAnchor(node) || isText$a(node, rootNode, schema, options) || isContentEditableFalse$b(node) || isContentEditableTrue$3(node) && hasNonEditableParent(node);\n };\n const isEmptyNode = (schema, targetNode, opts) => {\n const options = {\n ...defaultOptionValues,\n ...opts\n };\n if (options.checkRootAsContent) {\n if (isContentNode(schema, targetNode, targetNode, options)) {\n return false;\n }\n }\n let node = targetNode.firstChild;\n let brCount = 0;\n if (!node) {\n return true;\n }\n const walker = new DomTreeWalker(node, targetNode);\n do {\n if (options.skipBogus && isElement$6(node)) {\n const bogusValue = node.getAttribute('data-mce-bogus');\n if (bogusValue) {\n node = walker.next(bogusValue === 'all');\n continue;\n }\n }\n if (isComment(node)) {\n node = walker.next(true);\n continue;\n }\n if (isBr$6(node)) {\n brCount++;\n node = walker.next();\n continue;\n }\n if (isContentNode(schema, node, targetNode, options)) {\n return false;\n }\n node = walker.next();\n } while (node);\n return brCount <= 1;\n };\n const isEmpty$2 = (schema, elm, options) => {\n return isEmptyNode(schema, elm.dom, {\n checkRootAsContent: true,\n ...options\n });\n };\n const isContent$1 = (schema, node, options) => {\n return isContentNode(schema, node, node, {\n includeZwsp: defaultOptionValues.includeZwsp,\n ...options\n });\n };\n\n const Cell = initial => {\n let value = initial;\n const get = () => {\n return value;\n };\n const set = v => {\n value = v;\n };\n return {\n get,\n set\n };\n };\n\n const singleton = doRevoke => {\n const subject = Cell(Optional.none());\n const revoke = () => subject.get().each(doRevoke);\n const clear = () => {\n revoke();\n subject.set(Optional.none());\n };\n const isSet = () => subject.get().isSome();\n const get = () => subject.get();\n const set = s => {\n revoke();\n subject.set(Optional.some(s));\n };\n return {\n clear,\n isSet,\n get,\n set\n };\n };\n const repeatable = delay => {\n const intervalId = Cell(Optional.none());\n const revoke = () => intervalId.get().each(id => clearInterval(id));\n const clear = () => {\n revoke();\n intervalId.set(Optional.none());\n };\n const isSet = () => intervalId.get().isSome();\n const get = () => intervalId.get();\n const set = functionToRepeat => {\n revoke();\n intervalId.set(Optional.some(setInterval(functionToRepeat, delay)));\n };\n return {\n clear,\n isSet,\n get,\n set\n };\n };\n const value$2 = () => {\n const subject = singleton(noop);\n const on = f => subject.get().each(f);\n return {\n ...subject,\n on\n };\n };\n\n const nodeNameToNamespaceType = name => {\n const lowerCaseName = name.toLowerCase();\n if (lowerCaseName === 'svg') {\n return 'svg';\n } else if (lowerCaseName === 'math') {\n return 'math';\n } else {\n return 'html';\n }\n };\n const isNonHtmlElementRootName = name => nodeNameToNamespaceType(name) !== 'html';\n const isNonHtmlElementRoot = node => isNonHtmlElementRootName(node.nodeName);\n const toScopeType = node => nodeNameToNamespaceType(node.nodeName);\n const namespaceElements = [\n 'svg',\n 'math'\n ];\n const createNamespaceTracker = () => {\n const currentScope = value$2();\n const current = () => currentScope.get().map(toScopeType).getOr('html');\n const track = node => {\n if (isNonHtmlElementRoot(node)) {\n currentScope.set(node);\n } else if (currentScope.get().exists(scopeNode => !scopeNode.contains(node))) {\n currentScope.clear();\n }\n return current();\n };\n const reset = () => {\n currentScope.clear();\n };\n return {\n track,\n current,\n reset\n };\n };\n\n const transparentBlockAttr = 'data-mce-block';\n const elementNames = map => filter$5(keys(map), key => !/[A-Z]/.test(key));\n const makeSelectorFromSchemaMap = map => map$3(elementNames(map), name => {\n const escapedName = CSS.escape(name);\n return `${ escapedName }:` + map$3(namespaceElements, ns => `not(${ ns } ${ escapedName })`).join(':');\n }).join(',');\n const updateTransparent = (blocksSelector, transparent) => {\n if (isNonNullable(transparent.querySelector(blocksSelector))) {\n transparent.setAttribute(transparentBlockAttr, 'true');\n if (transparent.getAttribute('data-mce-selected') === 'inline-boundary') {\n transparent.removeAttribute('data-mce-selected');\n }\n return true;\n } else {\n transparent.removeAttribute(transparentBlockAttr);\n return false;\n }\n };\n const updateBlockStateOnChildren = (schema, scope) => {\n const transparentSelector = makeSelectorFromSchemaMap(schema.getTransparentElements());\n const blocksSelector = makeSelectorFromSchemaMap(schema.getBlockElements());\n return filter$5(scope.querySelectorAll(transparentSelector), transparent => updateTransparent(blocksSelector, transparent));\n };\n const trimEdge = (schema, el, leftSide) => {\n var _a;\n const childPropertyName = leftSide ? 'lastChild' : 'firstChild';\n for (let child = el[childPropertyName]; child; child = child[childPropertyName]) {\n if (isEmptyNode(schema, child, { checkRootAsContent: true })) {\n (_a = child.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(child);\n return;\n }\n }\n };\n const split$2 = (schema, parentElm, splitElm) => {\n const range = document.createRange();\n const parentNode = parentElm.parentNode;\n if (parentNode) {\n range.setStartBefore(parentElm);\n range.setEndBefore(splitElm);\n const beforeFragment = range.extractContents();\n trimEdge(schema, beforeFragment, true);\n range.setStartAfter(splitElm);\n range.setEndAfter(parentElm);\n const afterFragment = range.extractContents();\n trimEdge(schema, afterFragment, false);\n if (!isEmptyNode(schema, beforeFragment, { checkRootAsContent: true })) {\n parentNode.insertBefore(beforeFragment, parentElm);\n }\n if (!isEmptyNode(schema, splitElm, { checkRootAsContent: true })) {\n parentNode.insertBefore(splitElm, parentElm);\n }\n if (!isEmptyNode(schema, afterFragment, { checkRootAsContent: true })) {\n parentNode.insertBefore(afterFragment, parentElm);\n }\n parentNode.removeChild(parentElm);\n }\n };\n const splitInvalidChildren = (schema, scope, transparentBlocks) => {\n const blocksElements = schema.getBlockElements();\n const rootNode = SugarElement.fromDom(scope);\n const isBlock = el => name(el) in blocksElements;\n const isRoot = el => eq(el, rootNode);\n each$e(fromDom$1(transparentBlocks), transparentBlock => {\n ancestor$4(transparentBlock, isBlock, isRoot).each(parentBlock => {\n const invalidChildren = children(transparentBlock, el => isBlock(el) && !schema.isValidChild(name(parentBlock), name(el)));\n if (invalidChildren.length > 0) {\n const stateScope = parentElement(parentBlock);\n each$e(invalidChildren, child => {\n ancestor$4(child, isBlock, isRoot).each(parentBlock => {\n split$2(schema, parentBlock.dom, child.dom);\n });\n });\n stateScope.each(scope => updateBlockStateOnChildren(schema, scope.dom));\n }\n });\n });\n };\n const unwrapInvalidChildren = (schema, scope, transparentBlocks) => {\n each$e([\n ...transparentBlocks,\n ...isTransparentBlock(schema, scope) ? [scope] : []\n ], block => each$e(descendants(SugarElement.fromDom(block), block.nodeName.toLowerCase()), elm => {\n if (isTransparentInline(schema, elm.dom)) {\n unwrap(elm);\n }\n }));\n };\n const updateChildren = (schema, scope) => {\n const transparentBlocks = updateBlockStateOnChildren(schema, scope);\n splitInvalidChildren(schema, scope, transparentBlocks);\n unwrapInvalidChildren(schema, scope, transparentBlocks);\n };\n const updateElement = (schema, target) => {\n if (isTransparentElement(schema, target)) {\n const blocksSelector = makeSelectorFromSchemaMap(schema.getBlockElements());\n updateTransparent(blocksSelector, target);\n }\n };\n const updateCaret = (schema, root, caretParent) => {\n const isRoot = el => eq(el, SugarElement.fromDom(root));\n const parents = parents$1(SugarElement.fromDom(caretParent), isRoot);\n get$b(parents, parents.length - 2).filter(isElement$7).fold(() => updateChildren(schema, root), scope => updateChildren(schema, scope.dom));\n };\n const hasBlockAttr = el => el.hasAttribute(transparentBlockAttr);\n const isTransparentElementName = (schema, name) => has$2(schema.getTransparentElements(), name);\n const isTransparentElement = (schema, node) => isElement$6(node) && isTransparentElementName(schema, node.nodeName);\n const isTransparentBlock = (schema, node) => isTransparentElement(schema, node) && hasBlockAttr(node);\n const isTransparentInline = (schema, node) => isTransparentElement(schema, node) && !hasBlockAttr(node);\n const isTransparentAstBlock = (schema, node) => node.type === 1 && isTransparentElementName(schema, node.name) && isString(node.attr(transparentBlockAttr));\n\n const browser$2 = detect$1().browser;\n const firstElement = nodes => find$2(nodes, isElement$7);\n const getTableCaptionDeltaY = elm => {\n if (browser$2.isFirefox() && name(elm) === 'table') {\n return firstElement(children$1(elm)).filter(elm => {\n return name(elm) === 'caption';\n }).bind(caption => {\n return firstElement(nextSiblings(caption)).map(body => {\n const bodyTop = body.dom.offsetTop;\n const captionTop = caption.dom.offsetTop;\n const captionHeight = caption.dom.offsetHeight;\n return bodyTop <= captionTop ? -captionHeight : 0;\n });\n }).getOr(0);\n } else {\n return 0;\n }\n };\n const hasChild = (elm, child) => elm.children && contains$2(elm.children, child);\n const getPos = (body, elm, rootElm) => {\n let x = 0, y = 0;\n const doc = body.ownerDocument;\n rootElm = rootElm ? rootElm : body;\n if (elm) {\n if (rootElm === body && elm.getBoundingClientRect && get$7(SugarElement.fromDom(body), 'position') === 'static') {\n const pos = elm.getBoundingClientRect();\n x = pos.left + (doc.documentElement.scrollLeft || body.scrollLeft) - doc.documentElement.clientLeft;\n y = pos.top + (doc.documentElement.scrollTop || body.scrollTop) - doc.documentElement.clientTop;\n return {\n x,\n y\n };\n }\n let offsetParent = elm;\n while (offsetParent && offsetParent !== rootElm && offsetParent.nodeType && !hasChild(offsetParent, rootElm)) {\n const castOffsetParent = offsetParent;\n x += castOffsetParent.offsetLeft || 0;\n y += castOffsetParent.offsetTop || 0;\n offsetParent = castOffsetParent.offsetParent;\n }\n offsetParent = elm.parentNode;\n while (offsetParent && offsetParent !== rootElm && offsetParent.nodeType && !hasChild(offsetParent, rootElm)) {\n x -= offsetParent.scrollLeft || 0;\n y -= offsetParent.scrollTop || 0;\n offsetParent = offsetParent.parentNode;\n }\n y += getTableCaptionDeltaY(SugarElement.fromDom(elm));\n }\n return {\n x,\n y\n };\n };\n\n const StyleSheetLoader = (documentOrShadowRoot, settings = {}) => {\n let idCount = 0;\n const loadedStates = {};\n const edos = SugarElement.fromDom(documentOrShadowRoot);\n const doc = documentOrOwner(edos);\n const _setReferrerPolicy = referrerPolicy => {\n settings.referrerPolicy = referrerPolicy;\n };\n const _setContentCssCors = contentCssCors => {\n settings.contentCssCors = contentCssCors;\n };\n const addStyle = element => {\n append$1(getStyleContainer(edos), element);\n };\n const removeStyle = id => {\n const styleContainer = getStyleContainer(edos);\n descendant$1(styleContainer, '#' + id).each(remove$4);\n };\n const getOrCreateState = url => get$a(loadedStates, url).getOrThunk(() => ({\n id: 'mce-u' + idCount++,\n passed: [],\n failed: [],\n count: 0\n }));\n const load = url => new Promise((success, failure) => {\n let link;\n const urlWithSuffix = Tools._addCacheSuffix(url);\n const state = getOrCreateState(urlWithSuffix);\n loadedStates[urlWithSuffix] = state;\n state.count++;\n const resolve = (callbacks, status) => {\n each$e(callbacks, call);\n state.status = status;\n state.passed = [];\n state.failed = [];\n if (link) {\n link.onload = null;\n link.onerror = null;\n link = null;\n }\n };\n const passed = () => resolve(state.passed, 2);\n const failed = () => resolve(state.failed, 3);\n if (success) {\n state.passed.push(success);\n }\n if (failure) {\n state.failed.push(failure);\n }\n if (state.status === 1) {\n return;\n }\n if (state.status === 2) {\n passed();\n return;\n }\n if (state.status === 3) {\n failed();\n return;\n }\n state.status = 1;\n const linkElem = SugarElement.fromTag('link', doc.dom);\n setAll$1(linkElem, {\n rel: 'stylesheet',\n type: 'text/css',\n id: state.id\n });\n if (settings.contentCssCors) {\n set$4(linkElem, 'crossOrigin', 'anonymous');\n }\n if (settings.referrerPolicy) {\n set$4(linkElem, 'referrerpolicy', settings.referrerPolicy);\n }\n link = linkElem.dom;\n link.onload = passed;\n link.onerror = failed;\n addStyle(linkElem);\n set$4(linkElem, 'href', urlWithSuffix);\n });\n const loadRawCss = (key, css) => {\n const state = getOrCreateState(key);\n loadedStates[key] = state;\n state.count++;\n const styleElem = SugarElement.fromTag('style', doc.dom);\n setAll$1(styleElem, {\n 'rel': 'stylesheet',\n 'type': 'text/css',\n 'id': state.id,\n 'data-mce-key': key\n });\n styleElem.dom.innerHTML = css;\n addStyle(styleElem);\n };\n const loadAll = urls => {\n const loadedUrls = Promise.allSettled(map$3(urls, url => load(url).then(constant(url))));\n return loadedUrls.then(results => {\n const parts = partition$2(results, r => r.status === 'fulfilled');\n if (parts.fail.length > 0) {\n return Promise.reject(map$3(parts.fail, result => result.reason));\n } else {\n return map$3(parts.pass, result => result.value);\n }\n });\n };\n const unload = url => {\n const urlWithSuffix = Tools._addCacheSuffix(url);\n get$a(loadedStates, urlWithSuffix).each(state => {\n const count = --state.count;\n if (count === 0) {\n delete loadedStates[urlWithSuffix];\n removeStyle(state.id);\n }\n });\n };\n const unloadRawCss = key => {\n get$a(loadedStates, key).each(state => {\n const count = --state.count;\n if (count === 0) {\n delete loadedStates[key];\n removeStyle(state.id);\n }\n });\n };\n const unloadAll = urls => {\n each$e(urls, url => {\n unload(url);\n });\n };\n return {\n load,\n loadRawCss,\n loadAll,\n unload,\n unloadRawCss,\n unloadAll,\n _setReferrerPolicy,\n _setContentCssCors\n };\n };\n\n const create$c = () => {\n const map = new WeakMap();\n const forElement = (referenceElement, settings) => {\n const root = getRootNode(referenceElement);\n const rootDom = root.dom;\n return Optional.from(map.get(rootDom)).getOrThunk(() => {\n const sl = StyleSheetLoader(rootDom, settings);\n map.set(rootDom, sl);\n return sl;\n });\n };\n return { forElement };\n };\n const instance = create$c();\n\n const isSpan = node => node.nodeName.toLowerCase() === 'span';\n const isInlineContent = (node, schema) => isNonNullable(node) && (isContent$1(schema, node) || schema.isInline(node.nodeName.toLowerCase()));\n const surroundedByInlineContent = (node, root, schema) => {\n const prev = new DomTreeWalker(node, root).prev(false);\n const next = new DomTreeWalker(node, root).next(false);\n const prevIsInline = isUndefined(prev) || isInlineContent(prev, schema);\n const nextIsInline = isUndefined(next) || isInlineContent(next, schema);\n return prevIsInline && nextIsInline;\n };\n const isBookmarkNode$2 = node => isSpan(node) && node.getAttribute('data-mce-type') === 'bookmark';\n const isKeepTextNode = (node, root, schema) => isText$b(node) && node.data.length > 0 && surroundedByInlineContent(node, root, schema);\n const isKeepElement = node => isElement$6(node) ? node.childNodes.length > 0 : false;\n const isDocument = node => isDocumentFragment(node) || isDocument$1(node);\n const trimNode = (dom, node, schema, root) => {\n var _a;\n const rootNode = root || node;\n if (isElement$6(node) && isBookmarkNode$2(node)) {\n return node;\n }\n const children = node.childNodes;\n for (let i = children.length - 1; i >= 0; i--) {\n trimNode(dom, children[i], schema, rootNode);\n }\n if (isElement$6(node)) {\n const currentChildren = node.childNodes;\n if (currentChildren.length === 1 && isBookmarkNode$2(currentChildren[0])) {\n (_a = node.parentNode) === null || _a === void 0 ? void 0 : _a.insertBefore(currentChildren[0], node);\n }\n }\n if (!isDocument(node) && !isContent$1(schema, node) && !isKeepElement(node) && !isKeepTextNode(node, rootNode, schema)) {\n dom.remove(node);\n }\n return node;\n };\n\n const makeMap$3 = Tools.makeMap;\n const attrsCharsRegExp = /[&<>\\\"\\u0060\\u007E-\\uD7FF\\uE000-\\uFFEF]|[\\uD800-\\uDBFF][\\uDC00-\\uDFFF]/g;\n const textCharsRegExp = /[<>&\\u007E-\\uD7FF\\uE000-\\uFFEF]|[\\uD800-\\uDBFF][\\uDC00-\\uDFFF]/g;\n const rawCharsRegExp = /[<>&\\\"\\']/g;\n const entityRegExp = /([a-z0-9]+);?|&([a-z0-9]+);/gi;\n const asciiMap = {\n 128: '\\u20AC',\n 130: '\\u201A',\n 131: '\\u0192',\n 132: '\\u201E',\n 133: '\\u2026',\n 134: '\\u2020',\n 135: '\\u2021',\n 136: '\\u02c6',\n 137: '\\u2030',\n 138: '\\u0160',\n 139: '\\u2039',\n 140: '\\u0152',\n 142: '\\u017d',\n 145: '\\u2018',\n 146: '\\u2019',\n 147: '\\u201C',\n 148: '\\u201D',\n 149: '\\u2022',\n 150: '\\u2013',\n 151: '\\u2014',\n 152: '\\u02DC',\n 153: '\\u2122',\n 154: '\\u0161',\n 155: '\\u203A',\n 156: '\\u0153',\n 158: '\\u017e',\n 159: '\\u0178'\n };\n const baseEntities = {\n '\"': '"',\n '\\'': ''',\n '<': '<',\n '>': '>',\n '&': '&',\n '`': '`'\n };\n const reverseEntities = {\n '<': '<',\n '>': '>',\n '&': '&',\n '"': '\"',\n ''': `'`\n };\n const nativeDecode = text => {\n const elm = SugarElement.fromTag('div').dom;\n elm.innerHTML = text;\n return elm.textContent || elm.innerText || text;\n };\n const buildEntitiesLookup = (items, radix) => {\n const lookup = {};\n if (items) {\n const itemList = items.split(',');\n radix = radix || 10;\n for (let i = 0; i < itemList.length; i += 2) {\n const chr = String.fromCharCode(parseInt(itemList[i], radix));\n if (!baseEntities[chr]) {\n const entity = '&' + itemList[i + 1] + ';';\n lookup[chr] = entity;\n lookup[entity] = chr;\n }\n }\n return lookup;\n } else {\n return undefined;\n }\n };\n const namedEntities = buildEntitiesLookup('50,nbsp,51,iexcl,52,cent,53,pound,54,curren,55,yen,56,brvbar,57,sect,58,uml,59,copy,' + '5a,ordf,5b,laquo,5c,not,5d,shy,5e,reg,5f,macr,5g,deg,5h,plusmn,5i,sup2,5j,sup3,5k,acute,' + '5l,micro,5m,para,5n,middot,5o,cedil,5p,sup1,5q,ordm,5r,raquo,5s,frac14,5t,frac12,5u,frac34,' + '5v,iquest,60,Agrave,61,Aacute,62,Acirc,63,Atilde,64,Auml,65,Aring,66,AElig,67,Ccedil,' + '68,Egrave,69,Eacute,6a,Ecirc,6b,Euml,6c,Igrave,6d,Iacute,6e,Icirc,6f,Iuml,6g,ETH,6h,Ntilde,' + '6i,Ograve,6j,Oacute,6k,Ocirc,6l,Otilde,6m,Ouml,6n,times,6o,Oslash,6p,Ugrave,6q,Uacute,' + '6r,Ucirc,6s,Uuml,6t,Yacute,6u,THORN,6v,szlig,70,agrave,71,aacute,72,acirc,73,atilde,74,auml,' + '75,aring,76,aelig,77,ccedil,78,egrave,79,eacute,7a,ecirc,7b,euml,7c,igrave,7d,iacute,7e,icirc,' + '7f,iuml,7g,eth,7h,ntilde,7i,ograve,7j,oacute,7k,ocirc,7l,otilde,7m,ouml,7n,divide,7o,oslash,' + '7p,ugrave,7q,uacute,7r,ucirc,7s,uuml,7t,yacute,7u,thorn,7v,yuml,ci,fnof,sh,Alpha,si,Beta,' + 'sj,Gamma,sk,Delta,sl,Epsilon,sm,Zeta,sn,Eta,so,Theta,sp,Iota,sq,Kappa,sr,Lambda,ss,Mu,' + 'st,Nu,su,Xi,sv,Omicron,t0,Pi,t1,Rho,t3,Sigma,t4,Tau,t5,Upsilon,t6,Phi,t7,Chi,t8,Psi,' + 't9,Omega,th,alpha,ti,beta,tj,gamma,tk,delta,tl,epsilon,tm,zeta,tn,eta,to,theta,tp,iota,' + 'tq,kappa,tr,lambda,ts,mu,tt,nu,tu,xi,tv,omicron,u0,pi,u1,rho,u2,sigmaf,u3,sigma,u4,tau,' + 'u5,upsilon,u6,phi,u7,chi,u8,psi,u9,omega,uh,thetasym,ui,upsih,um,piv,812,bull,816,hellip,' + '81i,prime,81j,Prime,81u,oline,824,frasl,88o,weierp,88h,image,88s,real,892,trade,89l,alefsym,' + '8cg,larr,8ch,uarr,8ci,rarr,8cj,darr,8ck,harr,8dl,crarr,8eg,lArr,8eh,uArr,8ei,rArr,8ej,dArr,' + '8ek,hArr,8g0,forall,8g2,part,8g3,exist,8g5,empty,8g7,nabla,8g8,isin,8g9,notin,8gb,ni,8gf,prod,' + '8gh,sum,8gi,minus,8gn,lowast,8gq,radic,8gt,prop,8gu,infin,8h0,ang,8h7,and,8h8,or,8h9,cap,8ha,cup,' + '8hb,int,8hk,there4,8hs,sim,8i5,cong,8i8,asymp,8j0,ne,8j1,equiv,8j4,le,8j5,ge,8k2,sub,8k3,sup,8k4,' + 'nsub,8k6,sube,8k7,supe,8kl,oplus,8kn,otimes,8l5,perp,8m5,sdot,8o8,lceil,8o9,rceil,8oa,lfloor,8ob,' + 'rfloor,8p9,lang,8pa,rang,9ea,loz,9j0,spades,9j3,clubs,9j5,hearts,9j6,diams,ai,OElig,aj,oelig,b0,' + 'Scaron,b1,scaron,bo,Yuml,m6,circ,ms,tilde,802,ensp,803,emsp,809,thinsp,80c,zwnj,80d,zwj,80e,lrm,' + '80f,rlm,80j,ndash,80k,mdash,80o,lsquo,80p,rsquo,80q,sbquo,80s,ldquo,80t,rdquo,80u,bdquo,810,dagger,' + '811,Dagger,81g,permil,81p,lsaquo,81q,rsaquo,85c,euro', 32);\n const encodeRaw = (text, attr) => text.replace(attr ? attrsCharsRegExp : textCharsRegExp, chr => {\n return baseEntities[chr] || chr;\n });\n const encodeAllRaw = text => ('' + text).replace(rawCharsRegExp, chr => {\n return baseEntities[chr] || chr;\n });\n const encodeNumeric = (text, attr) => text.replace(attr ? attrsCharsRegExp : textCharsRegExp, chr => {\n if (chr.length > 1) {\n return '' + ((chr.charCodeAt(0) - 55296) * 1024 + (chr.charCodeAt(1) - 56320) + 65536) + ';';\n }\n return baseEntities[chr] || '' + chr.charCodeAt(0) + ';';\n });\n const encodeNamed = (text, attr, entities) => {\n const resolveEntities = entities || namedEntities;\n return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, chr => {\n return baseEntities[chr] || resolveEntities[chr] || chr;\n });\n };\n const getEncodeFunc = (name, entities) => {\n const entitiesMap = buildEntitiesLookup(entities) || namedEntities;\n const encodeNamedAndNumeric = (text, attr) => text.replace(attr ? attrsCharsRegExp : textCharsRegExp, chr => {\n if (baseEntities[chr] !== undefined) {\n return baseEntities[chr];\n }\n if (entitiesMap[chr] !== undefined) {\n return entitiesMap[chr];\n }\n if (chr.length > 1) {\n return '' + ((chr.charCodeAt(0) - 55296) * 1024 + (chr.charCodeAt(1) - 56320) + 65536) + ';';\n }\n return '' + chr.charCodeAt(0) + ';';\n });\n const encodeCustomNamed = (text, attr) => {\n return encodeNamed(text, attr, entitiesMap);\n };\n const nameMap = makeMap$3(name.replace(/\\+/g, ','));\n if (nameMap.named && nameMap.numeric) {\n return encodeNamedAndNumeric;\n }\n if (nameMap.named) {\n if (entities) {\n return encodeCustomNamed;\n }\n return encodeNamed;\n }\n if (nameMap.numeric) {\n return encodeNumeric;\n }\n return encodeRaw;\n };\n const decode = text => text.replace(entityRegExp, (all, numeric) => {\n if (numeric) {\n if (numeric.charAt(0).toLowerCase() === 'x') {\n numeric = parseInt(numeric.substr(1), 16);\n } else {\n numeric = parseInt(numeric, 10);\n }\n if (numeric > 65535) {\n numeric -= 65536;\n return String.fromCharCode(55296 + (numeric >> 10), 56320 + (numeric & 1023));\n }\n return asciiMap[numeric] || String.fromCharCode(numeric);\n }\n return reverseEntities[all] || namedEntities[all] || nativeDecode(all);\n });\n const Entities = {\n encodeRaw,\n encodeAllRaw,\n encodeNumeric,\n encodeNamed,\n getEncodeFunc,\n decode\n };\n\n const split$1 = (items, delim) => {\n items = Tools.trim(items);\n return items ? items.split(delim || ' ') : [];\n };\n const patternToRegExp = str => new RegExp('^' + str.replace(/([?+*])/g, '.$1') + '$');\n const isRegExp$1 = obj => isObject(obj) && obj.source && Object.prototype.toString.call(obj) === '[object RegExp]';\n const deepCloneElementRule = obj => {\n const helper = value => {\n if (isArray$1(value)) {\n return map$3(value, helper);\n } else if (isRegExp$1(value)) {\n return new RegExp(value.source, value.flags);\n } else if (isObject(value)) {\n return map$2(value, helper);\n } else {\n return value;\n }\n };\n return helper(obj);\n };\n\n const parseCustomElementsRules = value => {\n const customElementRegExp = /^(~)?(.+)$/;\n return bind$3(split$1(value, ','), rule => {\n const matches = customElementRegExp.exec(rule);\n if (matches) {\n const inline = matches[1] === '~';\n const cloneName = inline ? 'span' : 'div';\n const name = matches[2];\n return [{\n cloneName,\n name\n }];\n } else {\n return [];\n }\n });\n };\n\n const getGlobalAttributeSet = type => {\n return Object.freeze([\n 'id',\n 'accesskey',\n 'class',\n 'dir',\n 'lang',\n 'style',\n 'tabindex',\n 'title',\n 'role',\n ...type !== 'html4' ? [\n 'contenteditable',\n 'contextmenu',\n 'draggable',\n 'dropzone',\n 'hidden',\n 'spellcheck',\n 'translate',\n 'itemprop',\n 'itemscope',\n 'itemtype'\n ] : [],\n ...type !== 'html5-strict' ? ['xml:lang'] : []\n ]);\n };\n\n const getElementSetsAsStrings = type => {\n let blockContent;\n let phrasingContent;\n blockContent = 'address blockquote div dl fieldset form h1 h2 h3 h4 h5 h6 hr menu ol p pre table ul';\n phrasingContent = 'a abbr b bdo br button cite code del dfn em embed i iframe img input ins kbd ' + 'label map noscript object q s samp script select small span strong sub sup ' + 'textarea u var #text #comment';\n if (type !== 'html4') {\n const transparentContent = 'a ins del canvas map';\n blockContent += ' article aside details dialog figure main header footer hgroup section nav ' + transparentContent;\n phrasingContent += ' audio canvas command data datalist mark meter output picture ' + 'progress time wbr video ruby bdi keygen svg';\n }\n if (type !== 'html5-strict') {\n const html4PhrasingContent = 'acronym applet basefont big font strike tt';\n phrasingContent = [\n phrasingContent,\n html4PhrasingContent\n ].join(' ');\n const html4BlockContent = 'center dir isindex noframes';\n blockContent = [\n blockContent,\n html4BlockContent\n ].join(' ');\n }\n const flowContent = [\n blockContent,\n phrasingContent\n ].join(' ');\n return {\n blockContent,\n phrasingContent,\n flowContent\n };\n };\n const getElementSets = type => {\n const {blockContent, phrasingContent, flowContent} = getElementSetsAsStrings(type);\n const toArr = value => {\n return Object.freeze(value.split(' '));\n };\n return Object.freeze({\n blockContent: toArr(blockContent),\n phrasingContent: toArr(phrasingContent),\n flowContent: toArr(flowContent)\n });\n };\n\n const cachedSets = {\n 'html4': cached(() => getElementSets('html4')),\n 'html5': cached(() => getElementSets('html5')),\n 'html5-strict': cached(() => getElementSets('html5-strict'))\n };\n const getElementsPreset = (type, name) => {\n const {blockContent, phrasingContent, flowContent} = cachedSets[type]();\n if (name === 'blocks') {\n return Optional.some(blockContent);\n } else if (name === 'phrasing') {\n return Optional.some(phrasingContent);\n } else if (name === 'flow') {\n return Optional.some(flowContent);\n } else {\n return Optional.none();\n }\n };\n\n const makeSchema = type => {\n const globalAttributes = getGlobalAttributeSet(type);\n const {phrasingContent, flowContent} = getElementSetsAsStrings(type);\n const schema = {};\n const addElement = (name, attributes, children) => {\n schema[name] = {\n attributes: mapToObject(attributes, constant({})),\n attributesOrder: attributes,\n children: mapToObject(children, constant({}))\n };\n };\n const add = (name, attributes = '', children = '') => {\n const childNames = split$1(children);\n const names = split$1(name);\n let ni = names.length;\n const allAttributes = [\n ...globalAttributes,\n ...split$1(attributes)\n ];\n while (ni--) {\n addElement(names[ni], allAttributes.slice(), childNames);\n }\n };\n const addAttrs = (name, attributes) => {\n const names = split$1(name);\n const attrs = split$1(attributes);\n let ni = names.length;\n while (ni--) {\n const schemaItem = schema[names[ni]];\n for (let i = 0, l = attrs.length; i < l; i++) {\n schemaItem.attributes[attrs[i]] = {};\n schemaItem.attributesOrder.push(attrs[i]);\n }\n }\n };\n if (type !== 'html5-strict') {\n const html4PhrasingContent = 'acronym applet basefont big font strike tt';\n each$e(split$1(html4PhrasingContent), name => {\n add(name, '', phrasingContent);\n });\n const html4BlockContent = 'center dir isindex noframes';\n each$e(split$1(html4BlockContent), name => {\n add(name, '', flowContent);\n });\n }\n add('html', 'manifest', 'head body');\n add('head', '', 'base command link meta noscript script style title');\n add('title hr noscript br');\n add('base', 'href target');\n add('link', 'href rel media hreflang type sizes hreflang');\n add('meta', 'name http-equiv content charset');\n add('style', 'media type scoped');\n add('script', 'src async defer type charset');\n add('body', 'onafterprint onbeforeprint onbeforeunload onblur onerror onfocus ' + 'onhashchange onload onmessage onoffline ononline onpagehide onpageshow ' + 'onpopstate onresize onscroll onstorage onunload', flowContent);\n add('dd div', '', flowContent);\n add('address dt caption', '', type === 'html4' ? phrasingContent : flowContent);\n add('h1 h2 h3 h4 h5 h6 pre p abbr code var samp kbd sub sup i b u bdo span legend em strong small s cite dfn', '', phrasingContent);\n add('blockquote', 'cite', flowContent);\n add('ol', 'reversed start type', 'li');\n add('ul', '', 'li');\n add('li', 'value', flowContent);\n add('dl', '', 'dt dd');\n add('a', 'href target rel media hreflang type', type === 'html4' ? phrasingContent : flowContent);\n add('q', 'cite', phrasingContent);\n add('ins del', 'cite datetime', flowContent);\n add('img', 'src sizes srcset alt usemap ismap width height');\n add('iframe', 'src name width height', flowContent);\n add('embed', 'src type width height');\n add('object', 'data type typemustmatch name usemap form width height', [\n flowContent,\n 'param'\n ].join(' '));\n add('param', 'name value');\n add('map', 'name', [\n flowContent,\n 'area'\n ].join(' '));\n add('area', 'alt coords shape href target rel media hreflang type');\n add('table', 'border', 'caption colgroup thead tfoot tbody tr' + (type === 'html4' ? ' col' : ''));\n add('colgroup', 'span', 'col');\n add('col', 'span');\n add('tbody thead tfoot', '', 'tr');\n add('tr', '', 'td th');\n add('td', 'colspan rowspan headers', flowContent);\n add('th', 'colspan rowspan headers scope abbr', flowContent);\n add('form', 'accept-charset action autocomplete enctype method name novalidate target', flowContent);\n add('fieldset', 'disabled form name', [\n flowContent,\n 'legend'\n ].join(' '));\n add('label', 'form for', phrasingContent);\n add('input', 'accept alt autocomplete checked dirname disabled form formaction formenctype formmethod formnovalidate ' + 'formtarget height list max maxlength min multiple name pattern readonly required size src step type value width');\n add('button', 'disabled form formaction formenctype formmethod formnovalidate formtarget name type value', type === 'html4' ? flowContent : phrasingContent);\n add('select', 'disabled form multiple name required size', 'option optgroup');\n add('optgroup', 'disabled label', 'option');\n add('option', 'disabled label selected value');\n add('textarea', 'cols dirname disabled form maxlength name readonly required rows wrap');\n add('menu', 'type label', [\n flowContent,\n 'li'\n ].join(' '));\n add('noscript', '', flowContent);\n if (type !== 'html4') {\n add('wbr');\n add('ruby', '', [\n phrasingContent,\n 'rt rp'\n ].join(' '));\n add('figcaption', '', flowContent);\n add('mark rt rp bdi', '', phrasingContent);\n add('summary', '', [\n phrasingContent,\n 'h1 h2 h3 h4 h5 h6'\n ].join(' '));\n add('canvas', 'width height', flowContent);\n add('data', 'value', phrasingContent);\n add('video', 'src crossorigin poster preload autoplay mediagroup loop ' + 'muted controls width height buffered', [\n flowContent,\n 'track source'\n ].join(' '));\n add('audio', 'src crossorigin preload autoplay mediagroup loop muted controls ' + 'buffered volume', [\n flowContent,\n 'track source'\n ].join(' '));\n add('picture', '', 'img source');\n add('source', 'src srcset type media sizes');\n add('track', 'kind src srclang label default');\n add('datalist', '', [\n phrasingContent,\n 'option'\n ].join(' '));\n add('article section nav aside main header footer', '', flowContent);\n add('hgroup', '', 'h1 h2 h3 h4 h5 h6');\n add('figure', '', [\n flowContent,\n 'figcaption'\n ].join(' '));\n add('time', 'datetime', phrasingContent);\n add('dialog', 'open', flowContent);\n add('command', 'type label icon disabled checked radiogroup command');\n add('output', 'for form name', phrasingContent);\n add('progress', 'value max', phrasingContent);\n add('meter', 'value min max low high optimum', phrasingContent);\n add('details', 'open', [\n flowContent,\n 'summary'\n ].join(' '));\n add('keygen', 'autofocus challenge disabled form keytype name');\n addElement('svg', 'id tabindex lang xml:space class style x y width height viewBox preserveAspectRatio zoomAndPan transform'.split(' '), []);\n }\n if (type !== 'html5-strict') {\n addAttrs('script', 'language xml:space');\n addAttrs('style', 'xml:space');\n addAttrs('object', 'declare classid code codebase codetype archive standby align border hspace vspace');\n addAttrs('embed', 'align name hspace vspace');\n addAttrs('param', 'valuetype type');\n addAttrs('a', 'charset name rev shape coords');\n addAttrs('br', 'clear');\n addAttrs('applet', 'codebase archive code object alt name width height align hspace vspace');\n addAttrs('img', 'name longdesc align border hspace vspace');\n addAttrs('iframe', 'longdesc frameborder marginwidth marginheight scrolling align');\n addAttrs('font basefont', 'size color face');\n addAttrs('input', 'usemap align');\n addAttrs('select');\n addAttrs('textarea');\n addAttrs('h1 h2 h3 h4 h5 h6 div p legend caption', 'align');\n addAttrs('ul', 'type compact');\n addAttrs('li', 'type');\n addAttrs('ol dl menu dir', 'compact');\n addAttrs('pre', 'width xml:space');\n addAttrs('hr', 'align noshade size width');\n addAttrs('isindex', 'prompt');\n addAttrs('table', 'summary width frame rules cellspacing cellpadding align bgcolor');\n addAttrs('col', 'width align char charoff valign');\n addAttrs('colgroup', 'width align char charoff valign');\n addAttrs('thead', 'align char charoff valign');\n addAttrs('tr', 'align char charoff valign bgcolor');\n addAttrs('th', 'axis align char charoff valign nowrap bgcolor width height');\n addAttrs('form', 'accept');\n addAttrs('td', 'abbr axis scope align char charoff valign nowrap bgcolor width height');\n addAttrs('tfoot', 'align char charoff valign');\n addAttrs('tbody', 'align char charoff valign');\n addAttrs('area', 'nohref');\n addAttrs('body', 'background bgcolor text link vlink alink');\n }\n if (type !== 'html4') {\n addAttrs('input button select textarea', 'autofocus');\n addAttrs('input textarea', 'placeholder');\n addAttrs('a', 'download');\n addAttrs('link script img', 'crossorigin');\n addAttrs('img', 'loading');\n addAttrs('iframe', 'sandbox seamless allow allowfullscreen loading referrerpolicy');\n }\n if (type !== 'html4') {\n each$e([\n schema.video,\n schema.audio\n ], item => {\n delete item.children.audio;\n delete item.children.video;\n });\n }\n each$e(split$1('a form meter progress dfn'), name => {\n if (schema[name]) {\n delete schema[name].children[name];\n }\n });\n delete schema.caption.children.table;\n delete schema.script;\n return schema;\n };\n\n const prefixToOperation = prefix => prefix === '-' ? 'remove' : 'add';\n const parseValidChild = name => {\n const validChildRegExp = /^(@?)([A-Za-z0-9_\\-.\\u00b7\\u00c0-\\u00d6\\u00d8-\\u00f6\\u00f8-\\u037d\\u037f-\\u1fff\\u200c-\\u200d\\u203f-\\u2040\\u2070-\\u218f\\u2c00-\\u2fef\\u3001-\\ud7ff\\uf900-\\ufdcf\\ufdf0-\\ufffd]+)$/;\n return Optional.from(validChildRegExp.exec(name)).map(matches => ({\n preset: matches[1] === '@',\n name: matches[2]\n }));\n };\n const parseValidChildrenRules = value => {\n const childRuleRegExp = /^([+\\-]?)([A-Za-z0-9_\\-.\\u00b7\\u00c0-\\u00d6\\u00d8-\\u00f6\\u00f8-\\u037d\\u037f-\\u1fff\\u200c-\\u200d\\u203f-\\u2040\\u2070-\\u218f\\u2c00-\\u2fef\\u3001-\\ud7ff\\uf900-\\ufdcf\\ufdf0-\\ufffd]+)\\[([^\\]]+)]$/;\n return bind$3(split$1(value, ','), rule => {\n const matches = childRuleRegExp.exec(rule);\n if (matches) {\n const prefix = matches[1];\n const operation = prefix ? prefixToOperation(prefix) : 'replace';\n const name = matches[2];\n const validChildren = bind$3(split$1(matches[3], '|'), validChild => parseValidChild(validChild).toArray());\n return [{\n operation,\n name,\n validChildren\n }];\n } else {\n return [];\n }\n });\n };\n\n const parseValidElementsAttrDataIntoElement = (attrData, targetElement) => {\n const attrRuleRegExp = /^([!\\-])?(\\w+[\\\\:]:\\w+|[^=~<]+)?(?:([=~<])(.*))?$/;\n const hasPatternsRegExp = /[*?+]/;\n const {attributes, attributesOrder} = targetElement;\n return each$e(split$1(attrData, '|'), rule => {\n const matches = attrRuleRegExp.exec(rule);\n if (matches) {\n const attr = {};\n const attrType = matches[1];\n const attrName = matches[2].replace(/[\\\\:]:/g, ':');\n const attrPrefix = matches[3];\n const value = matches[4];\n if (attrType === '!') {\n targetElement.attributesRequired = targetElement.attributesRequired || [];\n targetElement.attributesRequired.push(attrName);\n attr.required = true;\n }\n if (attrType === '-') {\n delete attributes[attrName];\n attributesOrder.splice(Tools.inArray(attributesOrder, attrName), 1);\n return;\n }\n if (attrPrefix) {\n if (attrPrefix === '=') {\n targetElement.attributesDefault = targetElement.attributesDefault || [];\n targetElement.attributesDefault.push({\n name: attrName,\n value\n });\n attr.defaultValue = value;\n } else if (attrPrefix === '~') {\n targetElement.attributesForced = targetElement.attributesForced || [];\n targetElement.attributesForced.push({\n name: attrName,\n value\n });\n attr.forcedValue = value;\n } else if (attrPrefix === '<') {\n attr.validValues = Tools.makeMap(value, '?');\n }\n }\n if (hasPatternsRegExp.test(attrName)) {\n const attrPattern = attr;\n targetElement.attributePatterns = targetElement.attributePatterns || [];\n attrPattern.pattern = patternToRegExp(attrName);\n targetElement.attributePatterns.push(attrPattern);\n } else {\n if (!attributes[attrName]) {\n attributesOrder.push(attrName);\n }\n attributes[attrName] = attr;\n }\n }\n });\n };\n const cloneAttributesInto = (from, to) => {\n each$d(from.attributes, (value, key) => {\n to.attributes[key] = value;\n });\n to.attributesOrder.push(...from.attributesOrder);\n };\n const parseValidElementsRules = (globalElement, validElements) => {\n const elementRuleRegExp = /^([#+\\-])?([^\\[!\\/]+)(?:\\/([^\\[!]+))?(?:(!?)\\[([^\\]]+)])?$/;\n return bind$3(split$1(validElements, ','), rule => {\n const matches = elementRuleRegExp.exec(rule);\n if (matches) {\n const prefix = matches[1];\n const elementName = matches[2];\n const outputName = matches[3];\n const attrsPrefix = matches[4];\n const attrData = matches[5];\n const element = {\n attributes: {},\n attributesOrder: []\n };\n globalElement.each(el => cloneAttributesInto(el, element));\n if (prefix === '#') {\n element.paddEmpty = true;\n } else if (prefix === '-') {\n element.removeEmpty = true;\n }\n if (attrsPrefix === '!') {\n element.removeEmptyAttrs = true;\n }\n if (attrData) {\n parseValidElementsAttrDataIntoElement(attrData, element);\n }\n if (outputName) {\n element.outputName = elementName;\n }\n if (elementName === '@') {\n if (globalElement.isNone()) {\n globalElement = Optional.some(element);\n } else {\n return [];\n }\n }\n return [outputName ? {\n name: elementName,\n element,\n aliasName: outputName\n } : {\n name: elementName,\n element\n }];\n } else {\n return [];\n }\n });\n };\n\n const mapCache = {};\n const makeMap$2 = Tools.makeMap, each$b = Tools.each, extend$2 = Tools.extend, explode$2 = Tools.explode;\n const createMap = (defaultValue, extendWith = {}) => {\n const value = makeMap$2(defaultValue, ' ', makeMap$2(defaultValue.toUpperCase(), ' '));\n return extend$2(value, extendWith);\n };\n const getTextRootBlockElements = schema => createMap('td th li dt dd figcaption caption details summary', schema.getTextBlockElements());\n const compileElementMap = (value, mode) => {\n if (value) {\n const styles = {};\n if (isString(value)) {\n value = { '*': value };\n }\n each$b(value, (value, key) => {\n styles[key] = styles[key.toUpperCase()] = mode === 'map' ? makeMap$2(value, /[, ]/) : explode$2(value, /[, ]/);\n });\n return styles;\n } else {\n return undefined;\n }\n };\n const Schema = (settings = {}) => {\n var _a;\n const elements = {};\n const children = {};\n let patternElements = [];\n const customElementsMap = {};\n const specialElements = {};\n const createLookupTable = (option, defaultValue, extendWith) => {\n const value = settings[option];\n if (!value) {\n let newValue = mapCache[option];\n if (!newValue) {\n newValue = createMap(defaultValue, extendWith);\n mapCache[option] = newValue;\n }\n return newValue;\n } else {\n return makeMap$2(value, /[, ]/, makeMap$2(value.toUpperCase(), /[, ]/));\n }\n };\n const schemaType = (_a = settings.schema) !== null && _a !== void 0 ? _a : 'html5';\n const schemaItems = makeSchema(schemaType);\n if (settings.verify_html === false) {\n settings.valid_elements = '*[*]';\n }\n const validStyles = compileElementMap(settings.valid_styles);\n const invalidStyles = compileElementMap(settings.invalid_styles, 'map');\n const validClasses = compileElementMap(settings.valid_classes, 'map');\n const whitespaceElementsMap = createLookupTable('whitespace_elements', 'pre script noscript style textarea video audio iframe object code');\n const selfClosingElementsMap = createLookupTable('self_closing_elements', 'colgroup dd dt li option p td tfoot th thead tr');\n const voidElementsMap = createLookupTable('void_elements', 'area base basefont br col frame hr img input isindex link ' + 'meta param embed source wbr track');\n const boolAttrMap = createLookupTable('boolean_attributes', 'checked compact declare defer disabled ismap multiple nohref noresize ' + 'noshade nowrap readonly selected autoplay loop controls allowfullscreen');\n const nonEmptyOrMoveCaretBeforeOnEnter = 'td th iframe video audio object script code';\n const nonEmptyElementsMap = createLookupTable('non_empty_elements', nonEmptyOrMoveCaretBeforeOnEnter + ' pre svg textarea summary', voidElementsMap);\n const moveCaretBeforeOnEnterElementsMap = createLookupTable('move_caret_before_on_enter_elements', nonEmptyOrMoveCaretBeforeOnEnter + ' table', voidElementsMap);\n const headings = 'h1 h2 h3 h4 h5 h6';\n const textBlockElementsMap = createLookupTable('text_block_elements', headings + ' p div address pre form ' + 'blockquote center dir fieldset header footer article section hgroup aside main nav figure');\n const blockElementsMap = createLookupTable('block_elements', 'hr table tbody thead tfoot ' + 'th tr td li ol ul caption dl dt dd noscript menu isindex option ' + 'datalist select optgroup figcaption details summary html body multicol listing', textBlockElementsMap);\n const textInlineElementsMap = createLookupTable('text_inline_elements', 'span strong b em i font s strike u var cite ' + 'dfn code mark q sup sub samp');\n const transparentElementsMap = createLookupTable('transparent_elements', 'a ins del canvas map');\n const wrapBlockElementsMap = createLookupTable('wrap_block_elements', 'pre ' + headings);\n each$b('script noscript iframe noframes noembed title style textarea xmp plaintext'.split(' '), name => {\n specialElements[name] = new RegExp('' + name + '[^>]*>', 'gi');\n });\n const addValidElements = validElements => {\n const globalElement = Optional.from(elements['@']);\n const hasPatternsRegExp = /[*?+]/;\n each$e(parseValidElementsRules(globalElement, validElements !== null && validElements !== void 0 ? validElements : ''), ({name, element, aliasName}) => {\n if (aliasName) {\n elements[aliasName] = element;\n }\n if (hasPatternsRegExp.test(name)) {\n const patternElement = element;\n patternElement.pattern = patternToRegExp(name);\n patternElements.push(patternElement);\n } else {\n elements[name] = element;\n }\n });\n };\n const setValidElements = validElements => {\n patternElements = [];\n each$e(keys(elements), name => {\n delete elements[name];\n });\n addValidElements(validElements);\n };\n const addCustomElement = (name, spec) => {\n var _a, _b;\n delete mapCache.text_block_elements;\n delete mapCache.block_elements;\n const inline = spec.extends ? !isBlock(spec.extends) : false;\n const cloneName = spec.extends;\n children[name] = cloneName ? children[cloneName] : {};\n customElementsMap[name] = cloneName !== null && cloneName !== void 0 ? cloneName : name;\n nonEmptyElementsMap[name.toUpperCase()] = {};\n nonEmptyElementsMap[name] = {};\n if (!inline) {\n blockElementsMap[name.toUpperCase()] = {};\n blockElementsMap[name] = {};\n }\n if (cloneName && !elements[name] && elements[cloneName]) {\n const customRule = deepCloneElementRule(elements[cloneName]);\n delete customRule.removeEmptyAttrs;\n delete customRule.removeEmpty;\n elements[name] = customRule;\n } else {\n elements[name] = {\n attributesOrder: [],\n attributes: {}\n };\n }\n if (isArray$1(spec.attributes)) {\n const processAttrName = name => {\n customRule.attributesOrder.push(name);\n customRule.attributes[name] = {};\n };\n const customRule = (_a = elements[name]) !== null && _a !== void 0 ? _a : {};\n delete customRule.attributesDefault;\n delete customRule.attributesForced;\n delete customRule.attributePatterns;\n delete customRule.attributesRequired;\n customRule.attributesOrder = [];\n customRule.attributes = {};\n each$e(spec.attributes, attrName => {\n const globalAttrs = getGlobalAttributeSet(schemaType);\n parseValidChild(attrName).each(({preset, name}) => {\n if (preset) {\n if (name === 'global') {\n each$e(globalAttrs, processAttrName);\n }\n } else {\n processAttrName(name);\n }\n });\n });\n elements[name] = customRule;\n }\n if (isBoolean(spec.padEmpty)) {\n const customRule = (_b = elements[name]) !== null && _b !== void 0 ? _b : {};\n customRule.paddEmpty = spec.padEmpty;\n elements[name] = customRule;\n }\n if (isArray$1(spec.children)) {\n const customElementChildren = {};\n const processNodeName = name => {\n customElementChildren[name] = {};\n };\n const processPreset = name => {\n getElementsPreset(schemaType, name).each(names => {\n each$e(names, processNodeName);\n });\n };\n each$e(spec.children, child => {\n parseValidChild(child).each(({preset, name}) => {\n if (preset) {\n processPreset(name);\n } else {\n processNodeName(name);\n }\n });\n });\n children[name] = customElementChildren;\n }\n if (cloneName) {\n each$d(children, (element, elmName) => {\n if (element[cloneName]) {\n children[elmName] = element = extend$2({}, children[elmName]);\n element[name] = element[cloneName];\n }\n });\n }\n };\n const addCustomElementsFromString = customElements => {\n each$e(parseCustomElementsRules(customElements !== null && customElements !== void 0 ? customElements : ''), ({name, cloneName}) => {\n addCustomElement(name, { extends: cloneName });\n });\n };\n const addCustomElements = customElements => {\n if (isObject(customElements)) {\n each$d(customElements, (spec, name) => addCustomElement(name, spec));\n } else if (isString(customElements)) {\n addCustomElementsFromString(customElements);\n }\n };\n const addValidChildren = validChildren => {\n each$e(parseValidChildrenRules(validChildren !== null && validChildren !== void 0 ? validChildren : ''), ({operation, name, validChildren}) => {\n const parent = operation === 'replace' ? { '#comment': {} } : children[name];\n const processNodeName = name => {\n if (operation === 'remove') {\n delete parent[name];\n } else {\n parent[name] = {};\n }\n };\n const processPreset = name => {\n getElementsPreset(schemaType, name).each(names => {\n each$e(names, processNodeName);\n });\n };\n each$e(validChildren, ({preset, name}) => {\n if (preset) {\n processPreset(name);\n } else {\n processNodeName(name);\n }\n });\n children[name] = parent;\n });\n };\n const getElementRule = name => {\n const element = elements[name];\n if (element) {\n return element;\n }\n let i = patternElements.length;\n while (i--) {\n const patternElement = patternElements[i];\n if (patternElement.pattern.test(name)) {\n return patternElement;\n }\n }\n return undefined;\n };\n const setup = () => {\n if (!settings.valid_elements) {\n each$b(schemaItems, (element, name) => {\n elements[name] = {\n attributes: element.attributes,\n attributesOrder: element.attributesOrder\n };\n children[name] = element.children;\n });\n each$b(split$1('strong/b em/i'), item => {\n const items = split$1(item, '/');\n elements[items[1]].outputName = items[0];\n });\n each$b(textInlineElementsMap, (_val, name) => {\n if (elements[name]) {\n if (settings.padd_empty_block_inline_children) {\n elements[name].paddInEmptyBlock = true;\n }\n elements[name].removeEmpty = true;\n }\n });\n each$b(split$1('ol ul blockquote a table tbody'), name => {\n if (elements[name]) {\n elements[name].removeEmpty = true;\n }\n });\n each$b(split$1('p h1 h2 h3 h4 h5 h6 th td pre div address caption li summary'), name => {\n if (elements[name]) {\n elements[name].paddEmpty = true;\n }\n });\n each$b(split$1('span'), name => {\n elements[name].removeEmptyAttrs = true;\n });\n } else {\n setValidElements(settings.valid_elements);\n each$b(schemaItems, (element, name) => {\n children[name] = element.children;\n });\n }\n delete elements.svg;\n addCustomElements(settings.custom_elements);\n addValidChildren(settings.valid_children);\n addValidElements(settings.extended_valid_elements);\n addValidChildren('+ol[ul|ol],+ul[ul|ol]');\n each$b({\n dd: 'dl',\n dt: 'dl',\n li: 'ul ol',\n td: 'tr',\n th: 'tr',\n tr: 'tbody thead tfoot',\n tbody: 'table',\n thead: 'table',\n tfoot: 'table',\n legend: 'fieldset',\n area: 'map',\n param: 'video audio object'\n }, (parents, item) => {\n if (elements[item]) {\n elements[item].parentsRequired = split$1(parents);\n }\n });\n if (settings.invalid_elements) {\n each$b(explode$2(settings.invalid_elements), item => {\n if (elements[item]) {\n delete elements[item];\n }\n });\n }\n if (!getElementRule('span')) {\n addValidElements('span[!data-mce-type|*]');\n }\n };\n const getValidStyles = constant(validStyles);\n const getInvalidStyles = constant(invalidStyles);\n const getValidClasses = constant(validClasses);\n const getBoolAttrs = constant(boolAttrMap);\n const getBlockElements = constant(blockElementsMap);\n const getTextBlockElements = constant(textBlockElementsMap);\n const getTextInlineElements = constant(textInlineElementsMap);\n const getVoidElements = constant(Object.seal(voidElementsMap));\n const getSelfClosingElements = constant(selfClosingElementsMap);\n const getNonEmptyElements = constant(nonEmptyElementsMap);\n const getMoveCaretBeforeOnEnterElements = constant(moveCaretBeforeOnEnterElementsMap);\n const getWhitespaceElements = constant(whitespaceElementsMap);\n const getTransparentElements = constant(transparentElementsMap);\n const getWrapBlockElements = constant(wrapBlockElementsMap);\n const getSpecialElements = constant(Object.seal(specialElements));\n const isValidChild = (name, child) => {\n const parent = children[name.toLowerCase()];\n return !!(parent && parent[child.toLowerCase()]);\n };\n const isValid = (name, attr) => {\n const rule = getElementRule(name);\n if (rule) {\n if (attr) {\n if (rule.attributes[attr]) {\n return true;\n }\n const attrPatterns = rule.attributePatterns;\n if (attrPatterns) {\n let i = attrPatterns.length;\n while (i--) {\n if (attrPatterns[i].pattern.test(attr)) {\n return true;\n }\n }\n }\n } else {\n return true;\n }\n }\n return false;\n };\n const isBlock = name => has$2(getBlockElements(), name);\n const isInline = name => !startsWith(name, '#') && isValid(name) && !isBlock(name);\n const isWrapper = name => has$2(getWrapBlockElements(), name) || isInline(name);\n const getCustomElements = constant(customElementsMap);\n setup();\n return {\n type: schemaType,\n children,\n elements,\n getValidStyles,\n getValidClasses,\n getBlockElements,\n getInvalidStyles,\n getVoidElements,\n getTextBlockElements,\n getTextInlineElements,\n getBoolAttrs,\n getElementRule,\n getSelfClosingElements,\n getNonEmptyElements,\n getMoveCaretBeforeOnEnterElements,\n getWhitespaceElements,\n getTransparentElements,\n getSpecialElements,\n isValidChild,\n isValid,\n isBlock,\n isInline,\n isWrapper,\n getCustomElements,\n addValidElements,\n setValidElements,\n addCustomElements,\n addValidChildren\n };\n };\n\n const hexColour = value => ({ value: normalizeHex(value) });\n const normalizeHex = hex => removeLeading(hex, '#').toUpperCase();\n const toHex = component => {\n const hex = component.toString(16);\n return (hex.length === 1 ? '0' + hex : hex).toUpperCase();\n };\n const fromRgba = rgbaColour => {\n const value = toHex(rgbaColour.red) + toHex(rgbaColour.green) + toHex(rgbaColour.blue);\n return hexColour(value);\n };\n\n const rgbRegex = /^\\s*rgb\\s*\\(\\s*(\\d+)\\s*[,\\s]\\s*(\\d+)\\s*[,\\s]\\s*(\\d+)\\s*\\)\\s*$/i;\n const rgbaRegex = /^\\s*rgba\\s*\\(\\s*(\\d+)\\s*[,\\s]\\s*(\\d+)\\s*[,\\s]\\s*(\\d+)\\s*[,\\s]\\s*((?:\\d?\\.\\d+|\\d+)%?)\\s*\\)\\s*$/i;\n const rgbaColour = (red, green, blue, alpha) => ({\n red,\n green,\n blue,\n alpha\n });\n const fromStringValues = (red, green, blue, alpha) => {\n const r = parseInt(red, 10);\n const g = parseInt(green, 10);\n const b = parseInt(blue, 10);\n const a = parseFloat(alpha);\n return rgbaColour(r, g, b, a);\n };\n const getColorFormat = colorString => {\n if (rgbRegex.test(colorString)) {\n return 'rgb';\n } else if (rgbaRegex.test(colorString)) {\n return 'rgba';\n }\n return 'other';\n };\n const fromString = rgbaString => {\n const rgbMatch = rgbRegex.exec(rgbaString);\n if (rgbMatch !== null) {\n return Optional.some(fromStringValues(rgbMatch[1], rgbMatch[2], rgbMatch[3], '1'));\n }\n const rgbaMatch = rgbaRegex.exec(rgbaString);\n if (rgbaMatch !== null) {\n return Optional.some(fromStringValues(rgbaMatch[1], rgbaMatch[2], rgbaMatch[3], rgbaMatch[4]));\n }\n return Optional.none();\n };\n const toString = rgba => `rgba(${ rgba.red },${ rgba.green },${ rgba.blue },${ rgba.alpha })`;\n\n const rgbaToHexString = color => fromString(color).map(fromRgba).map(h => '#' + h.value).getOr(color);\n\n const Styles = (settings = {}, schema) => {\n const urlOrStrRegExp = /(?:url(?:(?:\\(\\s*\\\"([^\\\"]+)\\\"\\s*\\))|(?:\\(\\s*\\'([^\\']+)\\'\\s*\\))|(?:\\(\\s*([^)\\s]+)\\s*\\))))|(?:\\'([^\\']+)\\')|(?:\\\"([^\\\"]+)\\\")/gi;\n const styleRegExp = /\\s*([^:]+):\\s*([^;]+);?/g;\n const trimRightRegExp = /\\s+$/;\n const encodingLookup = {};\n let validStyles;\n let invalidStyles;\n const invisibleChar = zeroWidth;\n if (schema) {\n validStyles = schema.getValidStyles();\n invalidStyles = schema.getInvalidStyles();\n }\n const encodingItems = (`\\\\\" \\\\' \\\\; \\\\: ; : ` + invisibleChar).split(' ');\n for (let i = 0; i < encodingItems.length; i++) {\n encodingLookup[encodingItems[i]] = invisibleChar + i;\n encodingLookup[invisibleChar + i] = encodingItems[i];\n }\n const self = {\n parse: css => {\n const styles = {};\n let isEncoded = false;\n const urlConverter = settings.url_converter;\n const urlConverterScope = settings.url_converter_scope || self;\n const compress = (prefix, suffix, noJoin) => {\n const top = styles[prefix + '-top' + suffix];\n if (!top) {\n return;\n }\n const right = styles[prefix + '-right' + suffix];\n if (!right) {\n return;\n }\n const bottom = styles[prefix + '-bottom' + suffix];\n if (!bottom) {\n return;\n }\n const left = styles[prefix + '-left' + suffix];\n if (!left) {\n return;\n }\n const box = [\n top,\n right,\n bottom,\n left\n ];\n let i = box.length - 1;\n while (i--) {\n if (box[i] !== box[i + 1]) {\n break;\n }\n }\n if (i > -1 && noJoin) {\n return;\n }\n styles[prefix + suffix] = i === -1 ? box[0] : box.join(' ');\n delete styles[prefix + '-top' + suffix];\n delete styles[prefix + '-right' + suffix];\n delete styles[prefix + '-bottom' + suffix];\n delete styles[prefix + '-left' + suffix];\n };\n const canCompress = key => {\n const value = styles[key];\n if (!value) {\n return;\n }\n const values = value.indexOf(',') > -1 ? [value] : value.split(' ');\n let i = values.length;\n while (i--) {\n if (values[i] !== values[0]) {\n return false;\n }\n }\n styles[key] = values[0];\n return true;\n };\n const compress2 = (target, a, b, c) => {\n if (!canCompress(a)) {\n return;\n }\n if (!canCompress(b)) {\n return;\n }\n if (!canCompress(c)) {\n return;\n }\n styles[target] = styles[a] + ' ' + styles[b] + ' ' + styles[c];\n delete styles[a];\n delete styles[b];\n delete styles[c];\n };\n const encode = str => {\n isEncoded = true;\n return encodingLookup[str];\n };\n const decode = (str, keepSlashes) => {\n if (isEncoded) {\n str = str.replace(/\\uFEFF[0-9]/g, str => {\n return encodingLookup[str];\n });\n }\n if (!keepSlashes) {\n str = str.replace(/\\\\([\\'\\\";:])/g, '$1');\n }\n return str;\n };\n const decodeSingleHexSequence = escSeq => {\n return String.fromCharCode(parseInt(escSeq.slice(1), 16));\n };\n const decodeHexSequences = value => {\n return value.replace(/\\\\[0-9a-f]+/gi, decodeSingleHexSequence);\n };\n const processUrl = (match, url, url2, url3, str, str2) => {\n str = str || str2;\n if (str) {\n str = decode(str);\n return `'` + str.replace(/\\'/g, `\\\\'`) + `'`;\n }\n url = decode(url || url2 || url3 || '');\n if (!settings.allow_script_urls) {\n const scriptUrl = url.replace(/[\\s\\r\\n]+/g, '');\n if (/(java|vb)script:/i.test(scriptUrl)) {\n return '';\n }\n if (!settings.allow_svg_data_urls && /^data:image\\/svg/i.test(scriptUrl)) {\n return '';\n }\n }\n if (urlConverter) {\n url = urlConverter.call(urlConverterScope, url, 'style');\n }\n return `url('` + url.replace(/\\'/g, `\\\\'`) + `')`;\n };\n if (css) {\n css = css.replace(/[\\u0000-\\u001F]/g, '');\n css = css.replace(/\\\\[\\\"\\';:\\uFEFF]/g, encode).replace(/\\\"[^\\\"]+\\\"|\\'[^\\']+\\'/g, str => {\n return str.replace(/[;:]/g, encode);\n });\n let matches;\n while (matches = styleRegExp.exec(css)) {\n styleRegExp.lastIndex = matches.index + matches[0].length;\n let name = matches[1].replace(trimRightRegExp, '').toLowerCase();\n let value = matches[2].replace(trimRightRegExp, '');\n if (name && value) {\n name = decodeHexSequences(name);\n value = decodeHexSequences(value);\n if (name.indexOf(invisibleChar) !== -1 || name.indexOf('\"') !== -1) {\n continue;\n }\n if (!settings.allow_script_urls && (name === 'behavior' || /expression\\s*\\(|\\/\\*|\\*\\//.test(value))) {\n continue;\n }\n if (name === 'font-weight' && value === '700') {\n value = 'bold';\n } else if (name === 'color' || name === 'background-color') {\n value = value.toLowerCase();\n }\n if (getColorFormat(value) === 'rgb') {\n fromString(value).each(rgba => {\n value = rgbaToHexString(toString(rgba)).toLowerCase();\n });\n }\n value = value.replace(urlOrStrRegExp, processUrl);\n styles[name] = isEncoded ? decode(value, true) : value;\n }\n }\n compress('border', '', true);\n compress('border', '-width');\n compress('border', '-color');\n compress('border', '-style');\n compress('padding', '');\n compress('margin', '');\n compress2('border', 'border-width', 'border-style', 'border-color');\n if (styles.border === 'medium none') {\n delete styles.border;\n }\n if (styles['border-image'] === 'none') {\n delete styles['border-image'];\n }\n }\n return styles;\n },\n serialize: (styles, elementName) => {\n let css = '';\n const serializeStyles = (elemName, validStyleList) => {\n const styleList = validStyleList[elemName];\n if (styleList) {\n for (let i = 0, l = styleList.length; i < l; i++) {\n const name = styleList[i];\n const value = styles[name];\n if (value) {\n css += (css.length > 0 ? ' ' : '') + name + ': ' + value + ';';\n }\n }\n }\n };\n const isValid = (name, elemName) => {\n if (!invalidStyles || !elemName) {\n return true;\n }\n let styleMap = invalidStyles['*'];\n if (styleMap && styleMap[name]) {\n return false;\n }\n styleMap = invalidStyles[elemName];\n return !(styleMap && styleMap[name]);\n };\n if (elementName && validStyles) {\n serializeStyles('*', validStyles);\n serializeStyles(elementName, validStyles);\n } else {\n each$d(styles, (value, name) => {\n if (value && isValid(name, elementName)) {\n css += (css.length > 0 ? ' ' : '') + name + ': ' + value + ';';\n }\n });\n }\n return css;\n }\n };\n return self;\n };\n\n const deprecated = {\n keyLocation: true,\n layerX: true,\n layerY: true,\n returnValue: true,\n webkitMovementX: true,\n webkitMovementY: true,\n keyIdentifier: true,\n mozPressure: true\n };\n const isNativeEvent = event => event instanceof Event || isFunction(event.initEvent);\n const hasIsDefaultPrevented = event => event.isDefaultPrevented === always || event.isDefaultPrevented === never;\n const needsNormalizing = event => isNullable(event.preventDefault) || isNativeEvent(event);\n const clone$3 = (originalEvent, data) => {\n const event = data !== null && data !== void 0 ? data : {};\n for (const name in originalEvent) {\n if (!has$2(deprecated, name)) {\n event[name] = originalEvent[name];\n }\n }\n if (isNonNullable(originalEvent.composedPath)) {\n event.composedPath = () => originalEvent.composedPath();\n }\n if (isNonNullable(originalEvent.getModifierState)) {\n event.getModifierState = keyArg => originalEvent.getModifierState(keyArg);\n }\n if (isNonNullable(originalEvent.getTargetRanges)) {\n event.getTargetRanges = () => originalEvent.getTargetRanges();\n }\n return event;\n };\n const normalize$3 = (type, originalEvent, fallbackTarget, data) => {\n var _a;\n const event = clone$3(originalEvent, data);\n event.type = type;\n if (isNullable(event.target)) {\n event.target = (_a = event.srcElement) !== null && _a !== void 0 ? _a : fallbackTarget;\n }\n if (needsNormalizing(originalEvent)) {\n event.preventDefault = () => {\n event.defaultPrevented = true;\n event.isDefaultPrevented = always;\n if (isFunction(originalEvent.preventDefault)) {\n originalEvent.preventDefault();\n }\n };\n event.stopPropagation = () => {\n event.cancelBubble = true;\n event.isPropagationStopped = always;\n if (isFunction(originalEvent.stopPropagation)) {\n originalEvent.stopPropagation();\n }\n };\n event.stopImmediatePropagation = () => {\n event.isImmediatePropagationStopped = always;\n event.stopPropagation();\n };\n if (!hasIsDefaultPrevented(event)) {\n event.isDefaultPrevented = event.defaultPrevented === true ? always : never;\n event.isPropagationStopped = event.cancelBubble === true ? always : never;\n event.isImmediatePropagationStopped = never;\n }\n }\n return event;\n };\n\n const eventExpandoPrefix = 'mce-data-';\n const mouseEventRe = /^(?:mouse|contextmenu)|click/;\n const addEvent = (target, name, callback, capture) => {\n target.addEventListener(name, callback, capture || false);\n };\n const removeEvent = (target, name, callback, capture) => {\n target.removeEventListener(name, callback, capture || false);\n };\n const isMouseEvent = event => isNonNullable(event) && mouseEventRe.test(event.type);\n const fix = (originalEvent, data) => {\n const event = normalize$3(originalEvent.type, originalEvent, document, data);\n if (isMouseEvent(originalEvent) && isUndefined(originalEvent.pageX) && !isUndefined(originalEvent.clientX)) {\n const eventDoc = event.target.ownerDocument || document;\n const doc = eventDoc.documentElement;\n const body = eventDoc.body;\n const mouseEvent = event;\n mouseEvent.pageX = originalEvent.clientX + (doc && doc.scrollLeft || body && body.scrollLeft || 0) - (doc && doc.clientLeft || body && body.clientLeft || 0);\n mouseEvent.pageY = originalEvent.clientY + (doc && doc.scrollTop || body && body.scrollTop || 0) - (doc && doc.clientTop || body && body.clientTop || 0);\n }\n return event;\n };\n const bindOnReady = (win, callback, eventUtils) => {\n const doc = win.document, event = { type: 'ready' };\n if (eventUtils.domLoaded) {\n callback(event);\n return;\n }\n const isDocReady = () => {\n return doc.readyState === 'complete' || doc.readyState === 'interactive' && doc.body;\n };\n const readyHandler = () => {\n removeEvent(win, 'DOMContentLoaded', readyHandler);\n removeEvent(win, 'load', readyHandler);\n if (!eventUtils.domLoaded) {\n eventUtils.domLoaded = true;\n callback(event);\n }\n win = null;\n };\n if (isDocReady()) {\n readyHandler();\n } else {\n addEvent(win, 'DOMContentLoaded', readyHandler);\n }\n if (!eventUtils.domLoaded) {\n addEvent(win, 'load', readyHandler);\n }\n };\n class EventUtils {\n constructor() {\n this.domLoaded = false;\n this.events = {};\n this.count = 1;\n this.expando = eventExpandoPrefix + (+new Date()).toString(32);\n this.hasFocusIn = 'onfocusin' in document.documentElement;\n this.count = 1;\n }\n bind(target, names, callback, scope) {\n const self = this;\n let callbackList;\n const win = window;\n const defaultNativeHandler = evt => {\n self.executeHandlers(fix(evt || win.event), id);\n };\n if (!target || isText$b(target) || isComment(target)) {\n return callback;\n }\n let id;\n if (!target[self.expando]) {\n id = self.count++;\n target[self.expando] = id;\n self.events[id] = {};\n } else {\n id = target[self.expando];\n }\n scope = scope || target;\n const namesList = names.split(' ');\n let i = namesList.length;\n while (i--) {\n let name = namesList[i];\n let nativeHandler = defaultNativeHandler;\n let capture = false;\n let fakeName = false;\n if (name === 'DOMContentLoaded') {\n name = 'ready';\n }\n if (self.domLoaded && name === 'ready' && target.readyState === 'complete') {\n callback.call(scope, fix({ type: name }));\n continue;\n }\n if (!self.hasFocusIn && (name === 'focusin' || name === 'focusout')) {\n capture = true;\n fakeName = name === 'focusin' ? 'focus' : 'blur';\n nativeHandler = evt => {\n const event = fix(evt || win.event);\n event.type = event.type === 'focus' ? 'focusin' : 'focusout';\n self.executeHandlers(event, id);\n };\n }\n callbackList = self.events[id][name];\n if (!callbackList) {\n self.events[id][name] = callbackList = [{\n func: callback,\n scope\n }];\n callbackList.fakeName = fakeName;\n callbackList.capture = capture;\n callbackList.nativeHandler = nativeHandler;\n if (name === 'ready') {\n bindOnReady(target, nativeHandler, self);\n } else {\n addEvent(target, fakeName || name, nativeHandler, capture);\n }\n } else {\n if (name === 'ready' && self.domLoaded) {\n callback(fix({ type: name }));\n } else {\n callbackList.push({\n func: callback,\n scope\n });\n }\n }\n }\n target = callbackList = null;\n return callback;\n }\n unbind(target, names, callback) {\n if (!target || isText$b(target) || isComment(target)) {\n return this;\n }\n const id = target[this.expando];\n if (id) {\n let eventMap = this.events[id];\n if (names) {\n const namesList = names.split(' ');\n let i = namesList.length;\n while (i--) {\n const name = namesList[i];\n const callbackList = eventMap[name];\n if (callbackList) {\n if (callback) {\n let ci = callbackList.length;\n while (ci--) {\n if (callbackList[ci].func === callback) {\n const nativeHandler = callbackList.nativeHandler;\n const fakeName = callbackList.fakeName, capture = callbackList.capture;\n const newCallbackList = callbackList.slice(0, ci).concat(callbackList.slice(ci + 1));\n newCallbackList.nativeHandler = nativeHandler;\n newCallbackList.fakeName = fakeName;\n newCallbackList.capture = capture;\n eventMap[name] = newCallbackList;\n }\n }\n }\n if (!callback || callbackList.length === 0) {\n delete eventMap[name];\n removeEvent(target, callbackList.fakeName || name, callbackList.nativeHandler, callbackList.capture);\n }\n }\n }\n } else {\n each$d(eventMap, (callbackList, name) => {\n removeEvent(target, callbackList.fakeName || name, callbackList.nativeHandler, callbackList.capture);\n });\n eventMap = {};\n }\n for (const name in eventMap) {\n if (has$2(eventMap, name)) {\n return this;\n }\n }\n delete this.events[id];\n try {\n delete target[this.expando];\n } catch (ex) {\n target[this.expando] = null;\n }\n }\n return this;\n }\n fire(target, name, args) {\n return this.dispatch(target, name, args);\n }\n dispatch(target, name, args) {\n if (!target || isText$b(target) || isComment(target)) {\n return this;\n }\n const event = fix({\n type: name,\n target\n }, args);\n do {\n const id = target[this.expando];\n if (id) {\n this.executeHandlers(event, id);\n }\n target = target.parentNode || target.ownerDocument || target.defaultView || target.parentWindow;\n } while (target && !event.isPropagationStopped());\n return this;\n }\n clean(target) {\n if (!target || isText$b(target) || isComment(target)) {\n return this;\n }\n if (target[this.expando]) {\n this.unbind(target);\n }\n if (!target.getElementsByTagName) {\n target = target.document;\n }\n if (target && target.getElementsByTagName) {\n this.unbind(target);\n const children = target.getElementsByTagName('*');\n let i = children.length;\n while (i--) {\n target = children[i];\n if (target[this.expando]) {\n this.unbind(target);\n }\n }\n }\n return this;\n }\n destroy() {\n this.events = {};\n }\n cancel(e) {\n if (e) {\n e.preventDefault();\n e.stopImmediatePropagation();\n }\n return false;\n }\n executeHandlers(evt, id) {\n const container = this.events[id];\n const callbackList = container && container[evt.type];\n if (callbackList) {\n for (let i = 0, l = callbackList.length; i < l; i++) {\n const callback = callbackList[i];\n if (callback && callback.func.call(callback.scope, evt) === false) {\n evt.preventDefault();\n }\n if (evt.isImmediatePropagationStopped()) {\n return;\n }\n }\n }\n }\n }\n EventUtils.Event = new EventUtils();\n\n const each$a = Tools.each;\n const grep = Tools.grep;\n const internalStyleName = 'data-mce-style';\n const numericalCssMap = Tools.makeMap('fill-opacity font-weight line-height opacity orphans widows z-index zoom', ' ');\n const legacySetAttribute = (elm, name, value) => {\n if (isNullable(value) || value === '') {\n remove$9(elm, name);\n } else {\n set$4(elm, name, value);\n }\n };\n const camelCaseToHyphens = name => name.replace(/[A-Z]/g, v => '-' + v.toLowerCase());\n const findNodeIndex = (node, normalized) => {\n let idx = 0;\n if (node) {\n for (let lastNodeType = node.nodeType, tempNode = node.previousSibling; tempNode; tempNode = tempNode.previousSibling) {\n const nodeType = tempNode.nodeType;\n if (normalized && isText$b(tempNode)) {\n if (nodeType === lastNodeType || !tempNode.data.length) {\n continue;\n }\n }\n idx++;\n lastNodeType = nodeType;\n }\n }\n return idx;\n };\n const updateInternalStyleAttr = (styles, elm) => {\n const rawValue = get$9(elm, 'style');\n const value = styles.serialize(styles.parse(rawValue), name(elm));\n legacySetAttribute(elm, internalStyleName, value);\n };\n const convertStyleToString = (cssValue, cssName) => {\n if (isNumber(cssValue)) {\n return has$2(numericalCssMap, cssName) ? cssValue + '' : cssValue + 'px';\n } else {\n return cssValue;\n }\n };\n const applyStyle$1 = ($elm, cssName, cssValue) => {\n const normalizedName = camelCaseToHyphens(cssName);\n if (isNullable(cssValue) || cssValue === '') {\n remove$5($elm, normalizedName);\n } else {\n set$2($elm, normalizedName, convertStyleToString(cssValue, normalizedName));\n }\n };\n const setupAttrHooks = (styles, settings, getContext) => {\n const keepValues = settings.keep_values;\n const keepUrlHook = {\n set: (elm, value, name) => {\n const sugarElm = SugarElement.fromDom(elm);\n if (isFunction(settings.url_converter) && isNonNullable(value)) {\n value = settings.url_converter.call(settings.url_converter_scope || getContext(), String(value), name, elm);\n }\n const internalName = 'data-mce-' + name;\n legacySetAttribute(sugarElm, internalName, value);\n legacySetAttribute(sugarElm, name, value);\n },\n get: (elm, name) => {\n const sugarElm = SugarElement.fromDom(elm);\n return get$9(sugarElm, 'data-mce-' + name) || get$9(sugarElm, name);\n }\n };\n const attrHooks = {\n style: {\n set: (elm, value) => {\n const sugarElm = SugarElement.fromDom(elm);\n if (keepValues) {\n legacySetAttribute(sugarElm, internalStyleName, value);\n }\n remove$9(sugarElm, 'style');\n if (isString(value)) {\n setAll(sugarElm, styles.parse(value));\n }\n },\n get: elm => {\n const sugarElm = SugarElement.fromDom(elm);\n const value = get$9(sugarElm, internalStyleName) || get$9(sugarElm, 'style');\n return styles.serialize(styles.parse(value), name(sugarElm));\n }\n }\n };\n if (keepValues) {\n attrHooks.href = attrHooks.src = keepUrlHook;\n }\n return attrHooks;\n };\n const DOMUtils = (doc, settings = {}) => {\n const addedStyles = {};\n const win = window;\n const files = {};\n let counter = 0;\n const stdMode = true;\n const boxModel = true;\n const styleSheetLoader = instance.forElement(SugarElement.fromDom(doc), {\n contentCssCors: settings.contentCssCors,\n referrerPolicy: settings.referrerPolicy\n });\n const boundEvents = [];\n const schema = settings.schema ? settings.schema : Schema({});\n const styles = Styles({\n url_converter: settings.url_converter,\n url_converter_scope: settings.url_converter_scope\n }, settings.schema);\n const events = settings.ownEvents ? new EventUtils() : EventUtils.Event;\n const blockElementsMap = schema.getBlockElements();\n const isBlock = node => {\n if (isString(node)) {\n return has$2(blockElementsMap, node);\n } else {\n return isElement$6(node) && (has$2(blockElementsMap, node.nodeName) || isTransparentBlock(schema, node));\n }\n };\n const get = elm => elm && doc && isString(elm) ? doc.getElementById(elm) : elm;\n const _get = elm => {\n const value = get(elm);\n return isNonNullable(value) ? SugarElement.fromDom(value) : null;\n };\n const getAttrib = (elm, name, defaultVal = '') => {\n let value;\n const $elm = _get(elm);\n if (isNonNullable($elm) && isElement$7($elm)) {\n const hook = attrHooks[name];\n if (hook && hook.get) {\n value = hook.get($elm.dom, name);\n } else {\n value = get$9($elm, name);\n }\n }\n return isNonNullable(value) ? value : defaultVal;\n };\n const getAttribs = elm => {\n const node = get(elm);\n return isNullable(node) ? [] : node.attributes;\n };\n const setAttrib = (elm, name, value) => {\n run(elm, e => {\n if (isElement$6(e)) {\n const $elm = SugarElement.fromDom(e);\n const val = value === '' ? null : value;\n const originalValue = get$9($elm, name);\n const hook = attrHooks[name];\n if (hook && hook.set) {\n hook.set($elm.dom, val, name);\n } else {\n legacySetAttribute($elm, name, val);\n }\n if (originalValue !== val && settings.onSetAttrib) {\n settings.onSetAttrib({\n attrElm: $elm.dom,\n attrName: name,\n attrValue: val\n });\n }\n }\n });\n };\n const clone = (node, deep) => {\n return node.cloneNode(deep);\n };\n const getRoot = () => settings.root_element || doc.body;\n const getViewPort = argWin => {\n const vp = getBounds(argWin);\n return {\n x: vp.x,\n y: vp.y,\n w: vp.width,\n h: vp.height\n };\n };\n const getPos$1 = (elm, rootElm) => getPos(doc.body, get(elm), rootElm);\n const setStyle = (elm, name, value) => {\n run(elm, e => {\n const $elm = SugarElement.fromDom(e);\n applyStyle$1($elm, name, value);\n if (settings.update_styles) {\n updateInternalStyleAttr(styles, $elm);\n }\n });\n };\n const setStyles = (elm, stylesArg) => {\n run(elm, e => {\n const $elm = SugarElement.fromDom(e);\n each$d(stylesArg, (v, n) => {\n applyStyle$1($elm, n, v);\n });\n if (settings.update_styles) {\n updateInternalStyleAttr(styles, $elm);\n }\n });\n };\n const getStyle = (elm, name, computed) => {\n const $elm = get(elm);\n if (isNullable($elm) || !isHTMLElement($elm) && !isSVGElement($elm)) {\n return undefined;\n }\n if (computed) {\n return get$7(SugarElement.fromDom($elm), camelCaseToHyphens(name));\n } else {\n name = name.replace(/-(\\D)/g, (a, b) => b.toUpperCase());\n if (name === 'float') {\n name = 'cssFloat';\n }\n return $elm.style ? $elm.style[name] : undefined;\n }\n };\n const getSize = elm => {\n const $elm = get(elm);\n if (!$elm) {\n return {\n w: 0,\n h: 0\n };\n }\n let w = getStyle($elm, 'width');\n let h = getStyle($elm, 'height');\n if (!w || w.indexOf('px') === -1) {\n w = '0';\n }\n if (!h || h.indexOf('px') === -1) {\n h = '0';\n }\n return {\n w: parseInt(w, 10) || $elm.offsetWidth || $elm.clientWidth,\n h: parseInt(h, 10) || $elm.offsetHeight || $elm.clientHeight\n };\n };\n const getRect = elm => {\n const $elm = get(elm);\n const pos = getPos$1($elm);\n const size = getSize($elm);\n return {\n x: pos.x,\n y: pos.y,\n w: size.w,\n h: size.h\n };\n };\n const is = (elm, selector) => {\n if (!elm) {\n return false;\n }\n const elms = isArray$1(elm) ? elm : [elm];\n return exists(elms, e => {\n return is$1(SugarElement.fromDom(e), selector);\n });\n };\n const getParents = (elm, selector, root, collect) => {\n const result = [];\n let node = get(elm);\n collect = collect === undefined;\n const resolvedRoot = root || (getRoot().nodeName !== 'BODY' ? getRoot().parentNode : null);\n if (isString(selector)) {\n if (selector === '*') {\n selector = isElement$6;\n } else {\n const selectorVal = selector;\n selector = node => is(node, selectorVal);\n }\n }\n while (node) {\n if (node === resolvedRoot || isNullable(node.nodeType) || isDocument$1(node) || isDocumentFragment(node)) {\n break;\n }\n if (!selector || selector(node)) {\n if (collect) {\n result.push(node);\n } else {\n return [node];\n }\n }\n node = node.parentNode;\n }\n return collect ? result : null;\n };\n const getParent = (node, selector, root) => {\n const parents = getParents(node, selector, root, false);\n return parents && parents.length > 0 ? parents[0] : null;\n };\n const _findSib = (node, selector, name) => {\n let func = selector;\n if (node) {\n if (isString(selector)) {\n func = node => {\n return is(node, selector);\n };\n }\n for (let tempNode = node[name]; tempNode; tempNode = tempNode[name]) {\n if (isFunction(func) && func(tempNode)) {\n return tempNode;\n }\n }\n }\n return null;\n };\n const getNext = (node, selector) => _findSib(node, selector, 'nextSibling');\n const getPrev = (node, selector) => _findSib(node, selector, 'previousSibling');\n const isParentNode = node => isFunction(node.querySelectorAll);\n const select = (selector, scope) => {\n var _a, _b;\n const elm = (_b = (_a = get(scope)) !== null && _a !== void 0 ? _a : settings.root_element) !== null && _b !== void 0 ? _b : doc;\n return isParentNode(elm) ? from(elm.querySelectorAll(selector)) : [];\n };\n const run = function (elm, func, scope) {\n const context = scope !== null && scope !== void 0 ? scope : this;\n if (isArray$1(elm)) {\n const result = [];\n each$a(elm, (e, i) => {\n const node = get(e);\n if (node) {\n result.push(func.call(context, node, i));\n }\n });\n return result;\n } else {\n const node = get(elm);\n return !node ? false : func.call(context, node);\n }\n };\n const setAttribs = (elm, attrs) => {\n run(elm, $elm => {\n each$d(attrs, (value, name) => {\n setAttrib($elm, name, value);\n });\n });\n };\n const setHTML = (elm, html) => {\n run(elm, e => {\n const $elm = SugarElement.fromDom(e);\n set$1($elm, html);\n });\n };\n const add = (parentElm, name, attrs, html, create) => run(parentElm, parentElm => {\n const newElm = isString(name) ? doc.createElement(name) : name;\n if (isNonNullable(attrs)) {\n setAttribs(newElm, attrs);\n }\n if (html) {\n if (!isString(html) && html.nodeType) {\n newElm.appendChild(html);\n } else if (isString(html)) {\n setHTML(newElm, html);\n }\n }\n return !create ? parentElm.appendChild(newElm) : newElm;\n });\n const create = (name, attrs, html) => add(doc.createElement(name), name, attrs, html, true);\n const decode = Entities.decode;\n const encode = Entities.encodeAllRaw;\n const createHTML = (name, attrs, html = '') => {\n let outHtml = '<' + name;\n for (const key in attrs) {\n if (hasNonNullableKey(attrs, key)) {\n outHtml += ' ' + key + '=\"' + encode(attrs[key]) + '\"';\n }\n }\n if (isEmpty$3(html) && has$2(schema.getVoidElements(), name)) {\n return outHtml + ' />';\n } else {\n return outHtml + '>' + html + '' + name + '>';\n }\n };\n const createFragment = html => {\n const container = doc.createElement('div');\n const frag = doc.createDocumentFragment();\n frag.appendChild(container);\n if (html) {\n container.innerHTML = html;\n }\n let node;\n while (node = container.firstChild) {\n frag.appendChild(node);\n }\n frag.removeChild(container);\n return frag;\n };\n const remove = (node, keepChildren) => {\n return run(node, n => {\n const $node = SugarElement.fromDom(n);\n if (keepChildren) {\n each$e(children$1($node), child => {\n if (isText$c(child) && child.dom.length === 0) {\n remove$4(child);\n } else {\n before$3($node, child);\n }\n });\n }\n remove$4($node);\n return $node.dom;\n });\n };\n const removeAllAttribs = e => run(e, e => {\n const attrs = e.attributes;\n for (let i = attrs.length - 1; i >= 0; i--) {\n e.removeAttributeNode(attrs.item(i));\n }\n });\n const parseStyle = cssText => styles.parse(cssText);\n const serializeStyle = (stylesArg, name) => styles.serialize(stylesArg, name);\n const addStyle = cssText => {\n if (self !== DOMUtils.DOM && doc === document) {\n if (addedStyles[cssText]) {\n return;\n }\n addedStyles[cssText] = true;\n }\n let styleElm = doc.getElementById('mceDefaultStyles');\n if (!styleElm) {\n styleElm = doc.createElement('style');\n styleElm.id = 'mceDefaultStyles';\n styleElm.type = 'text/css';\n const head = doc.head;\n if (head.firstChild) {\n head.insertBefore(styleElm, head.firstChild);\n } else {\n head.appendChild(styleElm);\n }\n }\n if (styleElm.styleSheet) {\n styleElm.styleSheet.cssText += cssText;\n } else {\n styleElm.appendChild(doc.createTextNode(cssText));\n }\n };\n const loadCSS = urls => {\n if (!urls) {\n urls = '';\n }\n each$e(urls.split(','), url => {\n files[url] = true;\n styleSheetLoader.load(url).catch(noop);\n });\n };\n const toggleClass = (elm, cls, state) => {\n run(elm, e => {\n if (isElement$6(e)) {\n const $elm = SugarElement.fromDom(e);\n const classes = cls.split(' ');\n each$e(classes, c => {\n if (isNonNullable(state)) {\n const fn = state ? add$2 : remove$6;\n fn($elm, c);\n } else {\n toggle$1($elm, c);\n }\n });\n }\n });\n };\n const addClass = (elm, cls) => {\n toggleClass(elm, cls, true);\n };\n const removeClass = (elm, cls) => {\n toggleClass(elm, cls, false);\n };\n const hasClass = (elm, cls) => {\n const $elm = _get(elm);\n const classes = cls.split(' ');\n return isNonNullable($elm) && forall(classes, c => has($elm, c));\n };\n const show = elm => {\n run(elm, e => remove$5(SugarElement.fromDom(e), 'display'));\n };\n const hide = elm => {\n run(elm, e => set$2(SugarElement.fromDom(e), 'display', 'none'));\n };\n const isHidden = elm => {\n const $elm = _get(elm);\n return isNonNullable($elm) && is$2(getRaw($elm, 'display'), 'none');\n };\n const uniqueId = prefix => (!prefix ? 'mce_' : prefix) + counter++;\n const getOuterHTML = elm => {\n const $elm = _get(elm);\n if (isNonNullable($elm)) {\n return isElement$6($elm.dom) ? $elm.dom.outerHTML : getOuter($elm);\n } else {\n return '';\n }\n };\n const setOuterHTML = (elm, html) => {\n run(elm, $elm => {\n if (isElement$6($elm)) {\n $elm.outerHTML = html;\n }\n });\n };\n const insertAfter = (node, reference) => {\n const referenceNode = get(reference);\n return run(node, node => {\n const parent = referenceNode === null || referenceNode === void 0 ? void 0 : referenceNode.parentNode;\n const nextSibling = referenceNode === null || referenceNode === void 0 ? void 0 : referenceNode.nextSibling;\n if (parent) {\n if (nextSibling) {\n parent.insertBefore(node, nextSibling);\n } else {\n parent.appendChild(node);\n }\n }\n return node;\n });\n };\n const replace = (newElm, oldElm, keepChildren) => run(oldElm, elm => {\n var _a;\n const replacee = isArray$1(oldElm) ? newElm.cloneNode(true) : newElm;\n if (keepChildren) {\n each$a(grep(elm.childNodes), node => {\n replacee.appendChild(node);\n });\n }\n (_a = elm.parentNode) === null || _a === void 0 ? void 0 : _a.replaceChild(replacee, elm);\n return elm;\n });\n const rename = (elm, name) => {\n if (elm.nodeName !== name.toUpperCase()) {\n const newElm = create(name);\n each$a(getAttribs(elm), attrNode => {\n setAttrib(newElm, attrNode.nodeName, getAttrib(elm, attrNode.nodeName));\n });\n replace(newElm, elm, true);\n return newElm;\n } else {\n return elm;\n }\n };\n const findCommonAncestor = (a, b) => {\n let ps = a;\n while (ps) {\n let pe = b;\n while (pe && ps !== pe) {\n pe = pe.parentNode;\n }\n if (ps === pe) {\n break;\n }\n ps = ps.parentNode;\n }\n if (!ps && a.ownerDocument) {\n return a.ownerDocument.documentElement;\n } else {\n return ps;\n }\n };\n const isEmpty = (node, elements, options) => {\n if (isPlainObject(elements)) {\n const isContent = node => {\n const name = node.nodeName.toLowerCase();\n return Boolean(elements[name]);\n };\n return isEmptyNode(schema, node, {\n ...options,\n isContent\n });\n } else {\n return isEmptyNode(schema, node, options);\n }\n };\n const createRng = () => doc.createRange();\n const split = (parentElm, splitElm, replacementElm) => {\n let range = createRng();\n let beforeFragment;\n let afterFragment;\n if (parentElm && splitElm && parentElm.parentNode && splitElm.parentNode) {\n const parentNode = parentElm.parentNode;\n range.setStart(parentNode, findNodeIndex(parentElm));\n range.setEnd(splitElm.parentNode, findNodeIndex(splitElm));\n beforeFragment = range.extractContents();\n range = createRng();\n range.setStart(splitElm.parentNode, findNodeIndex(splitElm) + 1);\n range.setEnd(parentNode, findNodeIndex(parentElm) + 1);\n afterFragment = range.extractContents();\n parentNode.insertBefore(trimNode(self, beforeFragment, schema), parentElm);\n if (replacementElm) {\n parentNode.insertBefore(replacementElm, parentElm);\n } else {\n parentNode.insertBefore(splitElm, parentElm);\n }\n parentNode.insertBefore(trimNode(self, afterFragment, schema), parentElm);\n remove(parentElm);\n return replacementElm || splitElm;\n } else {\n return undefined;\n }\n };\n const bind = (target, name, func, scope) => {\n if (isArray$1(target)) {\n let i = target.length;\n const rv = [];\n while (i--) {\n rv[i] = bind(target[i], name, func, scope);\n }\n return rv;\n } else {\n if (settings.collect && (target === doc || target === win)) {\n boundEvents.push([\n target,\n name,\n func,\n scope\n ]);\n }\n return events.bind(target, name, func, scope || self);\n }\n };\n const unbind = (target, name, func) => {\n if (isArray$1(target)) {\n let i = target.length;\n const rv = [];\n while (i--) {\n rv[i] = unbind(target[i], name, func);\n }\n return rv;\n } else {\n if (boundEvents.length > 0 && (target === doc || target === win)) {\n let i = boundEvents.length;\n while (i--) {\n const [boundTarget, boundName, boundFunc] = boundEvents[i];\n if (target === boundTarget && (!name || name === boundName) && (!func || func === boundFunc)) {\n events.unbind(boundTarget, boundName, boundFunc);\n }\n }\n }\n return events.unbind(target, name, func);\n }\n };\n const dispatch = (target, name, evt) => events.dispatch(target, name, evt);\n const fire = (target, name, evt) => events.dispatch(target, name, evt);\n const getContentEditable = node => {\n if (node && isHTMLElement(node)) {\n const contentEditable = node.getAttribute('data-mce-contenteditable');\n if (contentEditable && contentEditable !== 'inherit') {\n return contentEditable;\n }\n return node.contentEditable !== 'inherit' ? node.contentEditable : null;\n } else {\n return null;\n }\n };\n const getContentEditableParent = node => {\n const root = getRoot();\n let state = null;\n for (let tempNode = node; tempNode && tempNode !== root; tempNode = tempNode.parentNode) {\n state = getContentEditable(tempNode);\n if (state !== null) {\n break;\n }\n }\n return state;\n };\n const isEditable = node => {\n if (isNonNullable(node)) {\n const scope = isElement$6(node) ? node : node.parentElement;\n return isNonNullable(scope) && isHTMLElement(scope) && isEditable$2(SugarElement.fromDom(scope));\n } else {\n return false;\n }\n };\n const destroy = () => {\n if (boundEvents.length > 0) {\n let i = boundEvents.length;\n while (i--) {\n const [boundTarget, boundName, boundFunc] = boundEvents[i];\n events.unbind(boundTarget, boundName, boundFunc);\n }\n }\n each$d(files, (_, url) => {\n styleSheetLoader.unload(url);\n delete files[url];\n });\n };\n const isChildOf = (node, parent) => {\n return node === parent || parent.contains(node);\n };\n const dumpRng = r => 'startContainer: ' + r.startContainer.nodeName + ', startOffset: ' + r.startOffset + ', endContainer: ' + r.endContainer.nodeName + ', endOffset: ' + r.endOffset;\n const self = {\n doc,\n settings,\n win,\n files,\n stdMode,\n boxModel,\n styleSheetLoader,\n boundEvents,\n styles,\n schema,\n events,\n isBlock: isBlock,\n root: null,\n clone,\n getRoot,\n getViewPort,\n getRect,\n getSize,\n getParent,\n getParents: getParents,\n get,\n getNext,\n getPrev,\n select,\n is,\n add,\n create,\n createHTML,\n createFragment,\n remove,\n setStyle,\n getStyle: getStyle,\n setStyles,\n removeAllAttribs,\n setAttrib,\n setAttribs,\n getAttrib,\n getPos: getPos$1,\n parseStyle,\n serializeStyle,\n addStyle,\n loadCSS,\n addClass,\n removeClass,\n hasClass,\n toggleClass,\n show,\n hide,\n isHidden,\n uniqueId,\n setHTML,\n getOuterHTML,\n setOuterHTML,\n decode,\n encode,\n insertAfter,\n replace,\n rename,\n findCommonAncestor,\n run,\n getAttribs,\n isEmpty,\n createRng,\n nodeIndex: findNodeIndex,\n split,\n bind: bind,\n unbind: unbind,\n fire,\n dispatch,\n getContentEditable,\n getContentEditableParent,\n isEditable,\n destroy,\n isChildOf,\n dumpRng\n };\n const attrHooks = setupAttrHooks(styles, settings, constant(self));\n return self;\n };\n DOMUtils.DOM = DOMUtils(document);\n DOMUtils.nodeIndex = findNodeIndex;\n\n const DOM$b = DOMUtils.DOM;\n const QUEUED = 0;\n const LOADING = 1;\n const LOADED = 2;\n const FAILED = 3;\n class ScriptLoader {\n constructor(settings = {}) {\n this.states = {};\n this.queue = [];\n this.scriptLoadedCallbacks = {};\n this.queueLoadedCallbacks = [];\n this.loading = false;\n this.settings = settings;\n }\n _setReferrerPolicy(referrerPolicy) {\n this.settings.referrerPolicy = referrerPolicy;\n }\n loadScript(url) {\n return new Promise((resolve, reject) => {\n const dom = DOM$b;\n let elm;\n const cleanup = () => {\n dom.remove(id);\n if (elm) {\n elm.onerror = elm.onload = elm = null;\n }\n };\n const done = () => {\n cleanup();\n resolve();\n };\n const error = () => {\n cleanup();\n reject('Failed to load script: ' + url);\n };\n const id = dom.uniqueId();\n elm = document.createElement('script');\n elm.id = id;\n elm.type = 'text/javascript';\n elm.src = Tools._addCacheSuffix(url);\n if (this.settings.referrerPolicy) {\n dom.setAttrib(elm, 'referrerpolicy', this.settings.referrerPolicy);\n }\n elm.onload = done;\n elm.onerror = error;\n (document.getElementsByTagName('head')[0] || document.body).appendChild(elm);\n });\n }\n isDone(url) {\n return this.states[url] === LOADED;\n }\n markDone(url) {\n this.states[url] = LOADED;\n }\n add(url) {\n const self = this;\n self.queue.push(url);\n const state = self.states[url];\n if (state === undefined) {\n self.states[url] = QUEUED;\n }\n return new Promise((resolve, reject) => {\n if (!self.scriptLoadedCallbacks[url]) {\n self.scriptLoadedCallbacks[url] = [];\n }\n self.scriptLoadedCallbacks[url].push({\n resolve,\n reject\n });\n });\n }\n load(url) {\n return this.add(url);\n }\n remove(url) {\n delete this.states[url];\n delete this.scriptLoadedCallbacks[url];\n }\n loadQueue() {\n const queue = this.queue;\n this.queue = [];\n return this.loadScripts(queue);\n }\n loadScripts(scripts) {\n const self = this;\n const execCallbacks = (name, url) => {\n get$a(self.scriptLoadedCallbacks, url).each(callbacks => {\n each$e(callbacks, callback => callback[name](url));\n });\n delete self.scriptLoadedCallbacks[url];\n };\n const processResults = results => {\n const failures = filter$5(results, result => result.status === 'rejected');\n if (failures.length > 0) {\n return Promise.reject(bind$3(failures, ({reason}) => isArray$1(reason) ? reason : [reason]));\n } else {\n return Promise.resolve();\n }\n };\n const load = urls => Promise.allSettled(map$3(urls, url => {\n if (self.states[url] === LOADED) {\n execCallbacks('resolve', url);\n return Promise.resolve();\n } else if (self.states[url] === FAILED) {\n execCallbacks('reject', url);\n return Promise.reject(url);\n } else {\n self.states[url] = LOADING;\n return self.loadScript(url).then(() => {\n self.states[url] = LOADED;\n execCallbacks('resolve', url);\n const queue = self.queue;\n if (queue.length > 0) {\n self.queue = [];\n return load(queue).then(processResults);\n } else {\n return Promise.resolve();\n }\n }, () => {\n self.states[url] = FAILED;\n execCallbacks('reject', url);\n return Promise.reject(url);\n });\n }\n }));\n const processQueue = urls => {\n self.loading = true;\n return load(urls).then(results => {\n self.loading = false;\n const nextQueuedItem = self.queueLoadedCallbacks.shift();\n Optional.from(nextQueuedItem).each(call);\n return processResults(results);\n });\n };\n const uniqueScripts = stringArray(scripts);\n if (self.loading) {\n return new Promise((resolve, reject) => {\n self.queueLoadedCallbacks.push(() => {\n processQueue(uniqueScripts).then(resolve, reject);\n });\n });\n } else {\n return processQueue(uniqueScripts);\n }\n }\n }\n ScriptLoader.ScriptLoader = new ScriptLoader();\n\n const isDuplicated = (items, item) => {\n const firstIndex = items.indexOf(item);\n return firstIndex !== -1 && items.indexOf(item, firstIndex + 1) > firstIndex;\n };\n const isRaw = str => isObject(str) && has$2(str, 'raw');\n const isTokenised = str => isArray$1(str) && str.length > 1;\n const data = {};\n const currentCode = Cell('en');\n const getLanguageData = () => get$a(data, currentCode.get());\n const getData$1 = () => map$2(data, value => ({ ...value }));\n const setCode = newCode => {\n if (newCode) {\n currentCode.set(newCode);\n }\n };\n const getCode = () => currentCode.get();\n const add$1 = (code, items) => {\n let langData = data[code];\n if (!langData) {\n data[code] = langData = {};\n }\n const lcNames = map$3(keys(items), name => name.toLowerCase());\n each$d(items, (translation, name) => {\n const lcName = name.toLowerCase();\n if (lcName !== name && isDuplicated(lcNames, lcName)) {\n if (!has$2(items, lcName)) {\n langData[lcName] = translation;\n }\n langData[name] = translation;\n } else {\n langData[lcName] = translation;\n }\n });\n };\n const translate = text => {\n const langData = getLanguageData().getOr({});\n const toString = obj => {\n if (isFunction(obj)) {\n return Object.prototype.toString.call(obj);\n }\n return !isEmpty(obj) ? '' + obj : '';\n };\n const isEmpty = text => text === '' || text === null || text === undefined;\n const getLangData = text => {\n const textStr = toString(text);\n return has$2(langData, textStr) ? toString(langData[textStr]) : get$a(langData, textStr.toLowerCase()).map(toString).getOr(textStr);\n };\n const removeContext = str => str.replace(/{context:\\w+}$/, '');\n if (isEmpty(text)) {\n return '';\n }\n if (isRaw(text)) {\n return toString(text.raw);\n }\n if (isTokenised(text)) {\n const values = text.slice(1);\n const substitued = getLangData(text[0]).replace(/\\{([0-9]+)\\}/g, ($1, $2) => has$2(values, $2) ? toString(values[$2]) : $1);\n return removeContext(substitued);\n }\n return removeContext(getLangData(text));\n };\n const isRtl$1 = () => getLanguageData().bind(items => get$a(items, '_dir')).exists(dir => dir === 'rtl');\n const hasCode = code => has$2(data, code);\n const I18n = {\n getData: getData$1,\n setCode,\n getCode,\n add: add$1,\n translate,\n isRtl: isRtl$1,\n hasCode\n };\n\n const AddOnManager = () => {\n const items = [];\n const urls = {};\n const lookup = {};\n const _listeners = [];\n const runListeners = (name, state) => {\n const matchedListeners = filter$5(_listeners, listener => listener.name === name && listener.state === state);\n each$e(matchedListeners, listener => listener.resolve());\n };\n const isLoaded = name => has$2(urls, name);\n const isAdded = name => has$2(lookup, name);\n const get = name => {\n if (lookup[name]) {\n return lookup[name].instance;\n }\n return undefined;\n };\n const loadLanguagePack = (name, languages) => {\n const language = I18n.getCode();\n const wrappedLanguages = ',' + (languages || '') + ',';\n if (!language || languages && wrappedLanguages.indexOf(',' + language + ',') === -1) {\n return;\n }\n ScriptLoader.ScriptLoader.add(urls[name] + '/langs/' + language + '.js');\n };\n const requireLangPack = (name, languages) => {\n if (AddOnManager.languageLoad !== false) {\n if (isLoaded(name)) {\n loadLanguagePack(name, languages);\n } else {\n waitFor(name, 'loaded').then(() => loadLanguagePack(name, languages));\n }\n }\n };\n const add = (id, addOn) => {\n items.push(addOn);\n lookup[id] = { instance: addOn };\n runListeners(id, 'added');\n return addOn;\n };\n const remove = name => {\n delete urls[name];\n delete lookup[name];\n };\n const createUrl = (baseUrl, dep) => {\n if (isString(dep)) {\n return isString(baseUrl) ? {\n prefix: '',\n resource: dep,\n suffix: ''\n } : {\n prefix: baseUrl.prefix,\n resource: dep,\n suffix: baseUrl.suffix\n };\n } else {\n return dep;\n }\n };\n const load = (name, addOnUrl) => {\n if (urls[name]) {\n return Promise.resolve();\n }\n let urlString = isString(addOnUrl) ? addOnUrl : addOnUrl.prefix + addOnUrl.resource + addOnUrl.suffix;\n if (urlString.indexOf('/') !== 0 && urlString.indexOf('://') === -1) {\n urlString = AddOnManager.baseURL + '/' + urlString;\n }\n urls[name] = urlString.substring(0, urlString.lastIndexOf('/'));\n const done = () => {\n runListeners(name, 'loaded');\n return Promise.resolve();\n };\n if (lookup[name]) {\n return done();\n } else {\n return ScriptLoader.ScriptLoader.add(urlString).then(done);\n }\n };\n const waitFor = (name, state = 'added') => {\n if (state === 'added' && isAdded(name)) {\n return Promise.resolve();\n } else if (state === 'loaded' && isLoaded(name)) {\n return Promise.resolve();\n } else {\n return new Promise(resolve => {\n _listeners.push({\n name,\n state,\n resolve\n });\n });\n }\n };\n return {\n items,\n urls,\n lookup,\n get,\n requireLangPack,\n add,\n remove,\n createUrl,\n load,\n waitFor\n };\n };\n AddOnManager.languageLoad = true;\n AddOnManager.baseURL = '';\n AddOnManager.PluginManager = AddOnManager();\n AddOnManager.ThemeManager = AddOnManager();\n AddOnManager.ModelManager = AddOnManager();\n\n const first$1 = (fn, rate) => {\n let timer = null;\n const cancel = () => {\n if (!isNull(timer)) {\n clearTimeout(timer);\n timer = null;\n }\n };\n const throttle = (...args) => {\n if (isNull(timer)) {\n timer = setTimeout(() => {\n timer = null;\n fn.apply(null, args);\n }, rate);\n }\n };\n return {\n cancel,\n throttle\n };\n };\n const last = (fn, rate) => {\n let timer = null;\n const cancel = () => {\n if (!isNull(timer)) {\n clearTimeout(timer);\n timer = null;\n }\n };\n const throttle = (...args) => {\n cancel();\n timer = setTimeout(() => {\n timer = null;\n fn.apply(null, args);\n }, rate);\n };\n return {\n cancel,\n throttle\n };\n };\n\n const ancestor$1 = (scope, selector, isRoot) => ancestor$3(scope, selector, isRoot).isSome();\n\n const annotation = constant('mce-annotation');\n const dataAnnotation = constant('data-mce-annotation');\n const dataAnnotationId = constant('data-mce-annotation-uid');\n const dataAnnotationActive = constant('data-mce-annotation-active');\n const dataAnnotationClasses = constant('data-mce-annotation-classes');\n const dataAnnotationAttributes = constant('data-mce-annotation-attrs');\n\n const isRoot$1 = root => node => eq(node, root);\n const identify = (editor, annotationName) => {\n const rng = editor.selection.getRng();\n const start = SugarElement.fromDom(rng.startContainer);\n const root = SugarElement.fromDom(editor.getBody());\n const selector = annotationName.fold(() => '.' + annotation(), an => `[${ dataAnnotation() }=\"${ an }\"]`);\n const newStart = child$1(start, rng.startOffset).getOr(start);\n const closest = closest$3(newStart, selector, isRoot$1(root));\n return closest.bind(c => getOpt(c, `${ dataAnnotationId() }`).bind(uid => getOpt(c, `${ dataAnnotation() }`).map(name => {\n const elements = findMarkers(editor, uid);\n return {\n uid,\n name,\n elements\n };\n })));\n };\n const isAnnotation = elem => isElement$7(elem) && has(elem, annotation());\n const isBogusElement = (elem, root) => has$1(elem, 'data-mce-bogus') || ancestor$1(elem, '[data-mce-bogus=\"all\"]', isRoot$1(root));\n const findMarkers = (editor, uid) => {\n const body = SugarElement.fromDom(editor.getBody());\n const descendants$1 = descendants(body, `[${ dataAnnotationId() }=\"${ uid }\"]`);\n return filter$5(descendants$1, descendant => !isBogusElement(descendant, body));\n };\n const findAll = (editor, name) => {\n const body = SugarElement.fromDom(editor.getBody());\n const markers = descendants(body, `[${ dataAnnotation() }=\"${ name }\"]`);\n const directory = {};\n each$e(markers, m => {\n if (!isBogusElement(m, body)) {\n const uid = get$9(m, dataAnnotationId());\n const nodesAlready = get$a(directory, uid).getOr([]);\n directory[uid] = nodesAlready.concat([m]);\n }\n });\n return directory;\n };\n\n const setup$y = (editor, registry) => {\n const changeCallbacks = Cell({});\n const initData = () => ({\n listeners: [],\n previous: value$2()\n });\n const withCallbacks = (name, f) => {\n updateCallbacks(name, data => {\n f(data);\n return data;\n });\n };\n const updateCallbacks = (name, f) => {\n const callbackMap = changeCallbacks.get();\n const data = get$a(callbackMap, name).getOrThunk(initData);\n const outputData = f(data);\n callbackMap[name] = outputData;\n changeCallbacks.set(callbackMap);\n };\n const fireCallbacks = (name, uid, elements) => {\n withCallbacks(name, data => {\n each$e(data.listeners, f => f(true, name, {\n uid,\n nodes: map$3(elements, elem => elem.dom)\n }));\n });\n };\n const fireNoAnnotation = name => {\n withCallbacks(name, data => {\n each$e(data.listeners, f => f(false, name));\n });\n };\n const toggleActiveAttr = (uid, state) => {\n each$e(findMarkers(editor, uid), elem => {\n if (state) {\n set$4(elem, dataAnnotationActive(), 'true');\n } else {\n remove$9(elem, dataAnnotationActive());\n }\n });\n };\n const onNodeChange = last(() => {\n const annotations = sort(registry.getNames());\n each$e(annotations, name => {\n updateCallbacks(name, data => {\n const prev = data.previous.get();\n identify(editor, Optional.some(name)).fold(() => {\n prev.each(uid => {\n fireNoAnnotation(name);\n data.previous.clear();\n toggleActiveAttr(uid, false);\n });\n }, ({uid, name, elements}) => {\n if (!is$2(prev, uid)) {\n prev.each(uid => toggleActiveAttr(uid, false));\n fireCallbacks(name, uid, elements);\n data.previous.set(uid);\n toggleActiveAttr(uid, true);\n }\n });\n return {\n previous: data.previous,\n listeners: data.listeners\n };\n });\n });\n }, 30);\n editor.on('remove', () => {\n onNodeChange.cancel();\n });\n editor.on('NodeChange', () => {\n onNodeChange.throttle();\n });\n const addListener = (name, f) => {\n updateCallbacks(name, data => ({\n previous: data.previous,\n listeners: data.listeners.concat([f])\n }));\n };\n return { addListener };\n };\n\n const setup$x = (editor, registry) => {\n const dataAnnotation$1 = dataAnnotation();\n const identifyParserNode = node => Optional.from(node.attr(dataAnnotation$1)).bind(registry.lookup);\n const removeDirectAnnotation = node => {\n var _a, _b;\n node.attr(dataAnnotationId(), null);\n node.attr(dataAnnotation(), null);\n node.attr(dataAnnotationActive(), null);\n const customAttrNames = Optional.from(node.attr(dataAnnotationAttributes())).map(names => names.split(',')).getOr([]);\n const customClasses = Optional.from(node.attr(dataAnnotationClasses())).map(names => names.split(',')).getOr([]);\n each$e(customAttrNames, name => node.attr(name, null));\n const classList = (_b = (_a = node.attr('class')) === null || _a === void 0 ? void 0 : _a.split(' ')) !== null && _b !== void 0 ? _b : [];\n const newClassList = difference(classList, [annotation()].concat(customClasses));\n node.attr('class', newClassList.length > 0 ? newClassList.join(' ') : null);\n node.attr(dataAnnotationClasses(), null);\n node.attr(dataAnnotationAttributes(), null);\n };\n editor.serializer.addTempAttr(dataAnnotationActive());\n editor.serializer.addAttributeFilter(dataAnnotation$1, nodes => {\n for (const node of nodes) {\n identifyParserNode(node).each(settings => {\n if (settings.persistent === false) {\n if (node.name === 'span') {\n node.unwrap();\n } else {\n removeDirectAnnotation(node);\n }\n }\n });\n }\n });\n };\n\n const create$b = () => {\n const annotations = {};\n const register = (name, settings) => {\n annotations[name] = {\n name,\n settings\n };\n };\n const lookup = name => get$a(annotations, name).map(a => a.settings);\n const getNames = () => keys(annotations);\n return {\n register,\n lookup,\n getNames\n };\n };\n\n const clamp$2 = (value, min, max) => Math.min(Math.max(value, min), max);\n const random = () => window.crypto.getRandomValues(new Uint32Array(1))[0] / 4294967295;\n\n let unique = 0;\n const generate$1 = prefix => {\n const date = new Date();\n const time = date.getTime();\n const random$1 = Math.floor(random() * 1000000000);\n unique++;\n return prefix + '_' + random$1 + unique + String(time);\n };\n\n const add = (element, classes) => {\n each$e(classes, x => {\n add$2(element, x);\n });\n };\n const remove$3 = (element, classes) => {\n each$e(classes, x => {\n remove$6(element, x);\n });\n };\n\n const clone$2 = (original, isDeep) => SugarElement.fromDom(original.dom.cloneNode(isDeep));\n const shallow$1 = original => clone$2(original, false);\n const deep$1 = original => clone$2(original, true);\n const shallowAs = (original, tag) => {\n const nu = SugarElement.fromTag(tag);\n const attributes = clone$4(original);\n setAll$1(nu, attributes);\n return nu;\n };\n const mutate = (original, tag) => {\n const nu = shallowAs(original, tag);\n after$4(original, nu);\n const children = children$1(original);\n append(nu, children);\n remove$4(original);\n return nu;\n };\n\n const TextWalker = (startNode, rootNode, isBoundary = never) => {\n const walker = new DomTreeWalker(startNode, rootNode);\n const walk = direction => {\n let next;\n do {\n next = walker[direction]();\n } while (next && !isText$b(next) && !isBoundary(next));\n return Optional.from(next).filter(isText$b);\n };\n return {\n current: () => Optional.from(walker.current()).filter(isText$b),\n next: () => walk('next'),\n prev: () => walk('prev'),\n prev2: () => walk('prev2')\n };\n };\n\n const TextSeeker = (dom, isBoundary) => {\n const isBlockBoundary = isBoundary ? isBoundary : node => dom.isBlock(node) || isBr$6(node) || isContentEditableFalse$b(node);\n const walk = (node, offset, walker, process) => {\n if (isText$b(node)) {\n const newOffset = process(node, offset, node.data);\n if (newOffset !== -1) {\n return Optional.some({\n container: node,\n offset: newOffset\n });\n }\n }\n return walker().bind(next => walk(next.container, next.offset, walker, process));\n };\n const backwards = (node, offset, process, root) => {\n const walker = TextWalker(node, root !== null && root !== void 0 ? root : dom.getRoot(), isBlockBoundary);\n return walk(node, offset, () => walker.prev().map(prev => ({\n container: prev,\n offset: prev.length\n })), process).getOrNull();\n };\n const forwards = (node, offset, process, root) => {\n const walker = TextWalker(node, root !== null && root !== void 0 ? root : dom.getRoot(), isBlockBoundary);\n return walk(node, offset, () => walker.next().map(next => ({\n container: next,\n offset: 0\n })), process).getOrNull();\n };\n return {\n backwards,\n forwards\n };\n };\n\n const NodeValue = (is, name) => {\n const get = element => {\n if (!is(element)) {\n throw new Error('Can only get ' + name + ' value of a ' + name + ' node');\n }\n return getOption(element).getOr('');\n };\n const getOption = element => is(element) ? Optional.from(element.dom.nodeValue) : Optional.none();\n const set = (element, value) => {\n if (!is(element)) {\n throw new Error('Can only set raw ' + name + ' value of a ' + name + ' node');\n }\n element.dom.nodeValue = value;\n };\n return {\n get,\n getOption,\n set\n };\n };\n\n const api$1 = NodeValue(isText$c, 'text');\n const get$3 = element => api$1.get(element);\n const getOption = element => api$1.getOption(element);\n const set = (element, value) => api$1.set(element, value);\n\n const tableCells = [\n 'td',\n 'th'\n ];\n const tableSections = [\n 'thead',\n 'tbody',\n 'tfoot'\n ];\n const textBlocks = [\n 'h1',\n 'h2',\n 'h3',\n 'h4',\n 'h5',\n 'h6',\n 'p',\n 'div',\n 'address',\n 'pre',\n 'form',\n 'blockquote',\n 'center',\n 'dir',\n 'fieldset',\n 'header',\n 'footer',\n 'article',\n 'section',\n 'hgroup',\n 'aside',\n 'nav',\n 'figure'\n ];\n const listItems$1 = [\n 'li',\n 'dd',\n 'dt'\n ];\n const lists = [\n 'ul',\n 'ol',\n 'dl'\n ];\n const wsElements = [\n 'pre',\n 'script',\n 'textarea',\n 'style'\n ];\n const lazyLookup = items => {\n let lookup;\n return node => {\n lookup = lookup ? lookup : mapToObject(items, always);\n return has$2(lookup, name(node));\n };\n };\n const isTable$1 = node => name(node) === 'table';\n const isBr$5 = node => isElement$7(node) && name(node) === 'br';\n const isTextBlock$2 = lazyLookup(textBlocks);\n const isList = lazyLookup(lists);\n const isListItem$1 = lazyLookup(listItems$1);\n const isTableSection = lazyLookup(tableSections);\n const isTableCell$2 = lazyLookup(tableCells);\n const isWsPreserveElement = lazyLookup(wsElements);\n\n const getLastChildren$1 = elm => {\n const children = [];\n let rawNode = elm.dom;\n while (rawNode) {\n children.push(SugarElement.fromDom(rawNode));\n rawNode = rawNode.lastChild;\n }\n return children;\n };\n const removeTrailingBr = elm => {\n const allBrs = descendants(elm, 'br');\n const brs = filter$5(getLastChildren$1(elm).slice(-1), isBr$5);\n if (allBrs.length === brs.length) {\n each$e(brs, remove$4);\n }\n };\n const createPaddingBr = () => {\n const br = SugarElement.fromTag('br');\n set$4(br, 'data-mce-bogus', '1');\n return br;\n };\n const fillWithPaddingBr = elm => {\n empty(elm);\n append$1(elm, createPaddingBr());\n };\n const trimBlockTrailingBr = (elm, schema) => {\n lastChild(elm).each(lastChild => {\n prevSibling(lastChild).each(lastChildPrevSibling => {\n if (schema.isBlock(name(elm)) && isBr$5(lastChild) && schema.isBlock(name(lastChildPrevSibling))) {\n remove$4(lastChild);\n }\n });\n });\n };\n\n const ZWSP$1 = zeroWidth;\n const isZwsp = isZwsp$2;\n const trim$2 = removeZwsp;\n const insert$5 = editor => editor.insertContent(ZWSP$1, { preserve_zwsp: true });\n\n const isElement$5 = isElement$6;\n const isText$9 = isText$b;\n const isCaretContainerBlock$1 = node => {\n if (isText$9(node)) {\n node = node.parentNode;\n }\n return isElement$5(node) && node.hasAttribute('data-mce-caret');\n };\n const isCaretContainerInline = node => isText$9(node) && isZwsp(node.data);\n const isCaretContainer$2 = node => isCaretContainerBlock$1(node) || isCaretContainerInline(node);\n const hasContent = node => node.firstChild !== node.lastChild || !isBr$6(node.firstChild);\n const insertInline$1 = (node, before) => {\n var _a;\n const doc = (_a = node.ownerDocument) !== null && _a !== void 0 ? _a : document;\n const textNode = doc.createTextNode(ZWSP$1);\n const parentNode = node.parentNode;\n if (!before) {\n const sibling = node.nextSibling;\n if (isText$9(sibling)) {\n if (isCaretContainer$2(sibling)) {\n return sibling;\n }\n if (startsWithCaretContainer$1(sibling)) {\n sibling.splitText(1);\n return sibling;\n }\n }\n if (node.nextSibling) {\n parentNode === null || parentNode === void 0 ? void 0 : parentNode.insertBefore(textNode, node.nextSibling);\n } else {\n parentNode === null || parentNode === void 0 ? void 0 : parentNode.appendChild(textNode);\n }\n } else {\n const sibling = node.previousSibling;\n if (isText$9(sibling)) {\n if (isCaretContainer$2(sibling)) {\n return sibling;\n }\n if (endsWithCaretContainer$1(sibling)) {\n return sibling.splitText(sibling.data.length - 1);\n }\n }\n parentNode === null || parentNode === void 0 ? void 0 : parentNode.insertBefore(textNode, node);\n }\n return textNode;\n };\n const isBeforeInline = pos => {\n const container = pos.container();\n if (!isText$b(container)) {\n return false;\n }\n return container.data.charAt(pos.offset()) === ZWSP$1 || pos.isAtStart() && isCaretContainerInline(container.previousSibling);\n };\n const isAfterInline = pos => {\n const container = pos.container();\n if (!isText$b(container)) {\n return false;\n }\n return container.data.charAt(pos.offset() - 1) === ZWSP$1 || pos.isAtEnd() && isCaretContainerInline(container.nextSibling);\n };\n const insertBlock = (blockName, node, before) => {\n var _a;\n const doc = (_a = node.ownerDocument) !== null && _a !== void 0 ? _a : document;\n const blockNode = doc.createElement(blockName);\n blockNode.setAttribute('data-mce-caret', before ? 'before' : 'after');\n blockNode.setAttribute('data-mce-bogus', 'all');\n blockNode.appendChild(createPaddingBr().dom);\n const parentNode = node.parentNode;\n if (!before) {\n if (node.nextSibling) {\n parentNode === null || parentNode === void 0 ? void 0 : parentNode.insertBefore(blockNode, node.nextSibling);\n } else {\n parentNode === null || parentNode === void 0 ? void 0 : parentNode.appendChild(blockNode);\n }\n } else {\n parentNode === null || parentNode === void 0 ? void 0 : parentNode.insertBefore(blockNode, node);\n }\n return blockNode;\n };\n const startsWithCaretContainer$1 = node => isText$9(node) && node.data[0] === ZWSP$1;\n const endsWithCaretContainer$1 = node => isText$9(node) && node.data[node.data.length - 1] === ZWSP$1;\n const trimBogusBr = elm => {\n var _a;\n const brs = elm.getElementsByTagName('br');\n const lastBr = brs[brs.length - 1];\n if (isBogus$1(lastBr)) {\n (_a = lastBr.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(lastBr);\n }\n };\n const showCaretContainerBlock = caretContainer => {\n if (caretContainer && caretContainer.hasAttribute('data-mce-caret')) {\n trimBogusBr(caretContainer);\n caretContainer.removeAttribute('data-mce-caret');\n caretContainer.removeAttribute('data-mce-bogus');\n caretContainer.removeAttribute('style');\n caretContainer.removeAttribute('data-mce-style');\n caretContainer.removeAttribute('_moz_abspos');\n return caretContainer;\n }\n return null;\n };\n const isRangeInCaretContainerBlock = range => isCaretContainerBlock$1(range.startContainer);\n\n const round$2 = Math.round;\n const clone$1 = rect => {\n if (!rect) {\n return {\n left: 0,\n top: 0,\n bottom: 0,\n right: 0,\n width: 0,\n height: 0\n };\n }\n return {\n left: round$2(rect.left),\n top: round$2(rect.top),\n bottom: round$2(rect.bottom),\n right: round$2(rect.right),\n width: round$2(rect.width),\n height: round$2(rect.height)\n };\n };\n const collapse = (rect, toStart) => {\n rect = clone$1(rect);\n if (toStart) {\n rect.right = rect.left;\n } else {\n rect.left = rect.left + rect.width;\n rect.right = rect.left;\n }\n rect.width = 0;\n return rect;\n };\n const isEqual = (rect1, rect2) => rect1.left === rect2.left && rect1.top === rect2.top && rect1.bottom === rect2.bottom && rect1.right === rect2.right;\n const isValidOverflow = (overflowY, rect1, rect2) => overflowY >= 0 && overflowY <= Math.min(rect1.height, rect2.height) / 2;\n const isAbove$1 = (rect1, rect2) => {\n const halfHeight = Math.min(rect2.height / 2, rect1.height / 2);\n if (rect1.bottom - halfHeight < rect2.top) {\n return true;\n }\n if (rect1.top > rect2.bottom) {\n return false;\n }\n return isValidOverflow(rect2.top - rect1.bottom, rect1, rect2);\n };\n const isBelow$1 = (rect1, rect2) => {\n if (rect1.top > rect2.bottom) {\n return true;\n }\n if (rect1.bottom < rect2.top) {\n return false;\n }\n return isValidOverflow(rect2.bottom - rect1.top, rect1, rect2);\n };\n const containsXY = (rect, clientX, clientY) => clientX >= rect.left && clientX <= rect.right && clientY >= rect.top && clientY <= rect.bottom;\n const boundingClientRectFromRects = rects => {\n return foldl(rects, (acc, rect) => {\n return acc.fold(() => Optional.some(rect), prevRect => {\n const left = Math.min(rect.left, prevRect.left);\n const top = Math.min(rect.top, prevRect.top);\n const right = Math.max(rect.right, prevRect.right);\n const bottom = Math.max(rect.bottom, prevRect.bottom);\n return Optional.some({\n top,\n right,\n bottom,\n left,\n width: right - left,\n height: bottom - top\n });\n });\n }, Optional.none());\n };\n const distanceToRectEdgeFromXY = (rect, x, y) => {\n const cx = Math.max(Math.min(x, rect.left + rect.width), rect.left);\n const cy = Math.max(Math.min(y, rect.top + rect.height), rect.top);\n return Math.sqrt((x - cx) * (x - cx) + (y - cy) * (y - cy));\n };\n const overlapY = (r1, r2) => Math.max(0, Math.min(r1.bottom, r2.bottom) - Math.max(r1.top, r2.top));\n\n const getSelectedNode = range => {\n const startContainer = range.startContainer, startOffset = range.startOffset;\n if (startContainer === range.endContainer && startContainer.hasChildNodes() && range.endOffset === startOffset + 1) {\n return startContainer.childNodes[startOffset];\n }\n return null;\n };\n const getNode$1 = (container, offset) => {\n if (isElement$6(container) && container.hasChildNodes()) {\n const childNodes = container.childNodes;\n const safeOffset = clamp$2(offset, 0, childNodes.length - 1);\n return childNodes[safeOffset];\n } else {\n return container;\n }\n };\n const getNodeUnsafe = (container, offset) => {\n if (offset < 0 && isElement$6(container) && container.hasChildNodes()) {\n return undefined;\n } else {\n return getNode$1(container, offset);\n }\n };\n\n const extendingChars = new RegExp('[\\u0300-\\u036f\\u0483-\\u0487\\u0488-\\u0489\\u0591-\\u05bd\\u05bf\\u05c1-\\u05c2\\u05c4-\\u05c5\\u05c7\\u0610-\\u061a' + '\\u064b-\\u065f\\u0670\\u06d6-\\u06dc\\u06df-\\u06e4\\u06e7-\\u06e8\\u06ea-\\u06ed\\u0711\\u0730-\\u074a\\u07a6-\\u07b0' + '\\u07eb-\\u07f3\\u0816-\\u0819\\u081b-\\u0823\\u0825-\\u0827\\u0829-\\u082d\\u0859-\\u085b\\u08e3-\\u0902\\u093a\\u093c' + '\\u0941-\\u0948\\u094d\\u0951-\\u0957\\u0962-\\u0963\\u0981\\u09bc\\u09be\\u09c1-\\u09c4\\u09cd\\u09d7\\u09e2-\\u09e3' + '\\u0a01-\\u0a02\\u0a3c\\u0a41-\\u0a42\\u0a47-\\u0a48\\u0a4b-\\u0a4d\\u0a51\\u0a70-\\u0a71\\u0a75\\u0a81-\\u0a82\\u0abc' + '\\u0ac1-\\u0ac5\\u0ac7-\\u0ac8\\u0acd\\u0ae2-\\u0ae3\\u0b01\\u0b3c\\u0b3e\\u0b3f\\u0b41-\\u0b44\\u0b4d\\u0b56\\u0b57' + '\\u0b62-\\u0b63\\u0b82\\u0bbe\\u0bc0\\u0bcd\\u0bd7\\u0c00\\u0c3e-\\u0c40\\u0c46-\\u0c48\\u0c4a-\\u0c4d\\u0c55-\\u0c56' + '\\u0c62-\\u0c63\\u0c81\\u0cbc\\u0cbf\\u0cc2\\u0cc6\\u0ccc-\\u0ccd\\u0cd5-\\u0cd6\\u0ce2-\\u0ce3\\u0d01\\u0d3e\\u0d41-\\u0d44' + '\\u0d4d\\u0d57\\u0d62-\\u0d63\\u0dca\\u0dcf\\u0dd2-\\u0dd4\\u0dd6\\u0ddf\\u0e31\\u0e34-\\u0e3a\\u0e47-\\u0e4e\\u0eb1\\u0eb4-\\u0eb9' + '\\u0ebb-\\u0ebc\\u0ec8-\\u0ecd\\u0f18-\\u0f19\\u0f35\\u0f37\\u0f39\\u0f71-\\u0f7e\\u0f80-\\u0f84\\u0f86-\\u0f87\\u0f8d-\\u0f97' + '\\u0f99-\\u0fbc\\u0fc6\\u102d-\\u1030\\u1032-\\u1037\\u1039-\\u103a\\u103d-\\u103e\\u1058-\\u1059\\u105e-\\u1060\\u1071-\\u1074' + '\\u1082\\u1085-\\u1086\\u108d\\u109d\\u135d-\\u135f\\u1712-\\u1714\\u1732-\\u1734\\u1752-\\u1753\\u1772-\\u1773\\u17b4-\\u17b5' + '\\u17b7-\\u17bd\\u17c6\\u17c9-\\u17d3\\u17dd\\u180b-\\u180d\\u18a9\\u1920-\\u1922\\u1927-\\u1928\\u1932\\u1939-\\u193b\\u1a17-\\u1a18' + '\\u1a1b\\u1a56\\u1a58-\\u1a5e\\u1a60\\u1a62\\u1a65-\\u1a6c\\u1a73-\\u1a7c\\u1a7f\\u1ab0-\\u1abd\\u1ABE\\u1b00-\\u1b03\\u1b34' + '\\u1b36-\\u1b3a\\u1b3c\\u1b42\\u1b6b-\\u1b73\\u1b80-\\u1b81\\u1ba2-\\u1ba5\\u1ba8-\\u1ba9\\u1bab-\\u1bad\\u1be6\\u1be8-\\u1be9' + '\\u1bed\\u1bef-\\u1bf1\\u1c2c-\\u1c33\\u1c36-\\u1c37\\u1cd0-\\u1cd2\\u1cd4-\\u1ce0\\u1ce2-\\u1ce8\\u1ced\\u1cf4\\u1cf8-\\u1cf9' + '\\u1dc0-\\u1df5\\u1dfc-\\u1dff\\u200c-\\u200d\\u20d0-\\u20dc\\u20DD-\\u20E0\\u20e1\\u20E2-\\u20E4\\u20e5-\\u20f0\\u2cef-\\u2cf1' + '\\u2d7f\\u2de0-\\u2dff\\u302a-\\u302d\\u302e-\\u302f\\u3099-\\u309a\\ua66f\\uA670-\\uA672\\ua674-\\ua67d\\ua69e-\\ua69f\\ua6f0-\\ua6f1' + '\\ua802\\ua806\\ua80b\\ua825-\\ua826\\ua8c4\\ua8e0-\\ua8f1\\ua926-\\ua92d\\ua947-\\ua951\\ua980-\\ua982\\ua9b3\\ua9b6-\\ua9b9\\ua9bc' + '\\ua9e5\\uaa29-\\uaa2e\\uaa31-\\uaa32\\uaa35-\\uaa36\\uaa43\\uaa4c\\uaa7c\\uaab0\\uaab2-\\uaab4\\uaab7-\\uaab8\\uaabe-\\uaabf\\uaac1' + '\\uaaec-\\uaaed\\uaaf6\\uabe5\\uabe8\\uabed\\ufb1e\\ufe00-\\ufe0f\\ufe20-\\ufe2f\\uff9e-\\uff9f]');\n const isExtendingChar = ch => isString(ch) && ch.charCodeAt(0) >= 768 && extendingChars.test(ch);\n\n const or = (...args) => {\n return x => {\n for (let i = 0; i < args.length; i++) {\n if (args[i](x)) {\n return true;\n }\n }\n return false;\n };\n };\n const and = (...args) => {\n return x => {\n for (let i = 0; i < args.length; i++) {\n if (!args[i](x)) {\n return false;\n }\n }\n return true;\n };\n };\n\n const isContentEditableTrue$2 = isContentEditableTrue$3;\n const isContentEditableFalse$a = isContentEditableFalse$b;\n const isBr$4 = isBr$6;\n const isText$8 = isText$b;\n const isInvalidTextElement = matchNodeNames([\n 'script',\n 'style',\n 'textarea'\n ]);\n const isAtomicInline = matchNodeNames([\n 'img',\n 'input',\n 'textarea',\n 'hr',\n 'iframe',\n 'video',\n 'audio',\n 'object',\n 'embed'\n ]);\n const isTable = matchNodeNames(['table']);\n const isCaretContainer$1 = isCaretContainer$2;\n const isCaretCandidate$3 = node => {\n if (isCaretContainer$1(node)) {\n return false;\n }\n if (isText$8(node)) {\n return !isInvalidTextElement(node.parentNode);\n }\n return isAtomicInline(node) || isBr$4(node) || isTable(node) || isNonUiContentEditableFalse(node);\n };\n const isUnselectable = node => isElement$6(node) && node.getAttribute('unselectable') === 'true';\n const isNonUiContentEditableFalse = node => !isUnselectable(node) && isContentEditableFalse$a(node);\n const isInEditable = (node, root) => {\n for (let tempNode = node.parentNode; tempNode && tempNode !== root; tempNode = tempNode.parentNode) {\n if (isNonUiContentEditableFalse(tempNode)) {\n return false;\n }\n if (isContentEditableTrue$2(tempNode)) {\n return true;\n }\n }\n return true;\n };\n const isAtomicContentEditableFalse = node => {\n if (!isNonUiContentEditableFalse(node)) {\n return false;\n }\n return !foldl(from(node.getElementsByTagName('*')), (result, elm) => {\n return result || isContentEditableTrue$2(elm);\n }, false);\n };\n const isAtomic$1 = node => isAtomicInline(node) || isAtomicContentEditableFalse(node);\n const isEditableCaretCandidate$1 = (node, root) => isCaretCandidate$3(node) && isInEditable(node, root);\n\n const isElement$4 = isElement$6;\n const isCaretCandidate$2 = isCaretCandidate$3;\n const isBlock$2 = matchStyleValues('display', 'block table');\n const isFloated = matchStyleValues('float', 'left right');\n const isValidElementCaretCandidate = and(isElement$4, isCaretCandidate$2, not(isFloated));\n const isNotPre = not(matchStyleValues('white-space', 'pre pre-line pre-wrap'));\n const isText$7 = isText$b;\n const isBr$3 = isBr$6;\n const nodeIndex$1 = DOMUtils.nodeIndex;\n const resolveIndex$1 = getNodeUnsafe;\n const createRange$1 = doc => doc ? doc.createRange() : DOMUtils.DOM.createRng();\n const isWhiteSpace$1 = chr => isString(chr) && /[\\r\\n\\t ]/.test(chr);\n const isRange = rng => !!rng.setStart && !!rng.setEnd;\n const isHiddenWhiteSpaceRange = range => {\n const container = range.startContainer;\n const offset = range.startOffset;\n if (isWhiteSpace$1(range.toString()) && isNotPre(container.parentNode) && isText$b(container)) {\n const text = container.data;\n if (isWhiteSpace$1(text[offset - 1]) || isWhiteSpace$1(text[offset + 1])) {\n return true;\n }\n }\n return false;\n };\n const getBrClientRect = brNode => {\n const doc = brNode.ownerDocument;\n const rng = createRange$1(doc);\n const nbsp$1 = doc.createTextNode(nbsp);\n const parentNode = brNode.parentNode;\n parentNode.insertBefore(nbsp$1, brNode);\n rng.setStart(nbsp$1, 0);\n rng.setEnd(nbsp$1, 1);\n const clientRect = clone$1(rng.getBoundingClientRect());\n parentNode.removeChild(nbsp$1);\n return clientRect;\n };\n const getBoundingClientRectWebKitText = rng => {\n const sc = rng.startContainer;\n const ec = rng.endContainer;\n const so = rng.startOffset;\n const eo = rng.endOffset;\n if (sc === ec && isText$b(ec) && so === 0 && eo === 1) {\n const newRng = rng.cloneRange();\n newRng.setEndAfter(ec);\n return getBoundingClientRect$1(newRng);\n } else {\n return null;\n }\n };\n const isZeroRect = r => r.left === 0 && r.right === 0 && r.top === 0 && r.bottom === 0;\n const getBoundingClientRect$1 = item => {\n var _a;\n let clientRect;\n const clientRects = item.getClientRects();\n if (clientRects.length > 0) {\n clientRect = clone$1(clientRects[0]);\n } else {\n clientRect = clone$1(item.getBoundingClientRect());\n }\n if (!isRange(item) && isBr$3(item) && isZeroRect(clientRect)) {\n return getBrClientRect(item);\n }\n if (isZeroRect(clientRect) && isRange(item)) {\n return (_a = getBoundingClientRectWebKitText(item)) !== null && _a !== void 0 ? _a : clientRect;\n }\n return clientRect;\n };\n const collapseAndInflateWidth = (clientRect, toStart) => {\n const newClientRect = collapse(clientRect, toStart);\n newClientRect.width = 1;\n newClientRect.right = newClientRect.left + 1;\n return newClientRect;\n };\n const getCaretPositionClientRects = caretPosition => {\n const clientRects = [];\n const addUniqueAndValidRect = clientRect => {\n if (clientRect.height === 0) {\n return;\n }\n if (clientRects.length > 0) {\n if (isEqual(clientRect, clientRects[clientRects.length - 1])) {\n return;\n }\n }\n clientRects.push(clientRect);\n };\n const addCharacterOffset = (container, offset) => {\n const range = createRange$1(container.ownerDocument);\n if (offset < container.data.length) {\n if (isExtendingChar(container.data[offset])) {\n return;\n }\n if (isExtendingChar(container.data[offset - 1])) {\n range.setStart(container, offset);\n range.setEnd(container, offset + 1);\n if (!isHiddenWhiteSpaceRange(range)) {\n addUniqueAndValidRect(collapseAndInflateWidth(getBoundingClientRect$1(range), false));\n return;\n }\n }\n }\n if (offset > 0) {\n range.setStart(container, offset - 1);\n range.setEnd(container, offset);\n if (!isHiddenWhiteSpaceRange(range)) {\n addUniqueAndValidRect(collapseAndInflateWidth(getBoundingClientRect$1(range), false));\n }\n }\n if (offset < container.data.length) {\n range.setStart(container, offset);\n range.setEnd(container, offset + 1);\n if (!isHiddenWhiteSpaceRange(range)) {\n addUniqueAndValidRect(collapseAndInflateWidth(getBoundingClientRect$1(range), true));\n }\n }\n };\n const container = caretPosition.container();\n const offset = caretPosition.offset();\n if (isText$7(container)) {\n addCharacterOffset(container, offset);\n return clientRects;\n }\n if (isElement$4(container)) {\n if (caretPosition.isAtEnd()) {\n const node = resolveIndex$1(container, offset);\n if (isText$7(node)) {\n addCharacterOffset(node, node.data.length);\n }\n if (isValidElementCaretCandidate(node) && !isBr$3(node)) {\n addUniqueAndValidRect(collapseAndInflateWidth(getBoundingClientRect$1(node), false));\n }\n } else {\n const node = resolveIndex$1(container, offset);\n if (isText$7(node)) {\n addCharacterOffset(node, 0);\n }\n if (isValidElementCaretCandidate(node) && caretPosition.isAtEnd()) {\n addUniqueAndValidRect(collapseAndInflateWidth(getBoundingClientRect$1(node), false));\n return clientRects;\n }\n const beforeNode = resolveIndex$1(caretPosition.container(), caretPosition.offset() - 1);\n if (isValidElementCaretCandidate(beforeNode) && !isBr$3(beforeNode)) {\n if (isBlock$2(beforeNode) || isBlock$2(node) || !isValidElementCaretCandidate(node)) {\n addUniqueAndValidRect(collapseAndInflateWidth(getBoundingClientRect$1(beforeNode), false));\n }\n }\n if (isValidElementCaretCandidate(node)) {\n addUniqueAndValidRect(collapseAndInflateWidth(getBoundingClientRect$1(node), true));\n }\n }\n }\n return clientRects;\n };\n const CaretPosition = (container, offset, clientRects) => {\n const isAtStart = () => {\n if (isText$7(container)) {\n return offset === 0;\n }\n return offset === 0;\n };\n const isAtEnd = () => {\n if (isText$7(container)) {\n return offset >= container.data.length;\n }\n return offset >= container.childNodes.length;\n };\n const toRange = () => {\n const range = createRange$1(container.ownerDocument);\n range.setStart(container, offset);\n range.setEnd(container, offset);\n return range;\n };\n const getClientRects = () => {\n if (!clientRects) {\n clientRects = getCaretPositionClientRects(CaretPosition(container, offset));\n }\n return clientRects;\n };\n const isVisible = () => getClientRects().length > 0;\n const isEqual = caretPosition => caretPosition && container === caretPosition.container() && offset === caretPosition.offset();\n const getNode = before => resolveIndex$1(container, before ? offset - 1 : offset);\n return {\n container: constant(container),\n offset: constant(offset),\n toRange,\n getClientRects,\n isVisible,\n isAtStart,\n isAtEnd,\n isEqual,\n getNode\n };\n };\n CaretPosition.fromRangeStart = range => CaretPosition(range.startContainer, range.startOffset);\n CaretPosition.fromRangeEnd = range => CaretPosition(range.endContainer, range.endOffset);\n CaretPosition.after = node => CaretPosition(node.parentNode, nodeIndex$1(node) + 1);\n CaretPosition.before = node => CaretPosition(node.parentNode, nodeIndex$1(node));\n CaretPosition.isAbove = (pos1, pos2) => lift2(head(pos2.getClientRects()), last$2(pos1.getClientRects()), isAbove$1).getOr(false);\n CaretPosition.isBelow = (pos1, pos2) => lift2(last$2(pos2.getClientRects()), head(pos1.getClientRects()), isBelow$1).getOr(false);\n CaretPosition.isAtStart = pos => pos ? pos.isAtStart() : false;\n CaretPosition.isAtEnd = pos => pos ? pos.isAtEnd() : false;\n CaretPosition.isTextPosition = pos => pos ? isText$b(pos.container()) : false;\n CaretPosition.isElementPosition = pos => !CaretPosition.isTextPosition(pos);\n\n const trimEmptyTextNode$1 = (dom, node) => {\n if (isText$b(node) && node.data.length === 0) {\n dom.remove(node);\n }\n };\n const insertNode = (dom, rng, node) => {\n rng.insertNode(node);\n trimEmptyTextNode$1(dom, node.previousSibling);\n trimEmptyTextNode$1(dom, node.nextSibling);\n };\n const insertFragment = (dom, rng, frag) => {\n const firstChild = Optional.from(frag.firstChild);\n const lastChild = Optional.from(frag.lastChild);\n rng.insertNode(frag);\n firstChild.each(child => trimEmptyTextNode$1(dom, child.previousSibling));\n lastChild.each(child => trimEmptyTextNode$1(dom, child.nextSibling));\n };\n const rangeInsertNode = (dom, rng, node) => {\n if (isDocumentFragment(node)) {\n insertFragment(dom, rng, node);\n } else {\n insertNode(dom, rng, node);\n }\n };\n\n const isText$6 = isText$b;\n const isBogus = isBogus$1;\n const nodeIndex = DOMUtils.nodeIndex;\n const normalizedParent = node => {\n const parentNode = node.parentNode;\n if (isBogus(parentNode)) {\n return normalizedParent(parentNode);\n }\n return parentNode;\n };\n const getChildNodes = node => {\n if (!node) {\n return [];\n }\n return reduce(node.childNodes, (result, node) => {\n if (isBogus(node) && node.nodeName !== 'BR') {\n result = result.concat(getChildNodes(node));\n } else {\n result.push(node);\n }\n return result;\n }, []);\n };\n const normalizedTextOffset = (node, offset) => {\n let tempNode = node;\n while (tempNode = tempNode.previousSibling) {\n if (!isText$6(tempNode)) {\n break;\n }\n offset += tempNode.data.length;\n }\n return offset;\n };\n const equal = a => b => a === b;\n const normalizedNodeIndex = node => {\n let nodes, index;\n nodes = getChildNodes(normalizedParent(node));\n index = findIndex$1(nodes, equal(node), node);\n nodes = nodes.slice(0, index + 1);\n const numTextFragments = reduce(nodes, (result, node, i) => {\n if (isText$6(node) && isText$6(nodes[i - 1])) {\n result++;\n }\n return result;\n }, 0);\n nodes = filter$3(nodes, matchNodeNames([node.nodeName]));\n index = findIndex$1(nodes, equal(node), node);\n return index - numTextFragments;\n };\n const createPathItem = node => {\n const name = isText$6(node) ? 'text()' : node.nodeName.toLowerCase();\n return name + '[' + normalizedNodeIndex(node) + ']';\n };\n const parentsUntil$1 = (root, node, predicate) => {\n const parents = [];\n for (let tempNode = node.parentNode; tempNode && tempNode !== root; tempNode = tempNode.parentNode) {\n if (predicate && predicate(tempNode)) {\n break;\n }\n parents.push(tempNode);\n }\n return parents;\n };\n const create$a = (root, caretPosition) => {\n let path = [];\n let container = caretPosition.container();\n let offset = caretPosition.offset();\n let outputOffset;\n if (isText$6(container)) {\n outputOffset = normalizedTextOffset(container, offset);\n } else {\n const childNodes = container.childNodes;\n if (offset >= childNodes.length) {\n outputOffset = 'after';\n offset = childNodes.length - 1;\n } else {\n outputOffset = 'before';\n }\n container = childNodes[offset];\n }\n path.push(createPathItem(container));\n let parents = parentsUntil$1(root, container);\n parents = filter$3(parents, not(isBogus$1));\n path = path.concat(map$1(parents, node => {\n return createPathItem(node);\n }));\n return path.reverse().join('/') + ',' + outputOffset;\n };\n const resolvePathItem = (node, name, index) => {\n let nodes = getChildNodes(node);\n nodes = filter$3(nodes, (node, index) => {\n return !isText$6(node) || !isText$6(nodes[index - 1]);\n });\n nodes = filter$3(nodes, matchNodeNames([name]));\n return nodes[index];\n };\n const findTextPosition = (container, offset) => {\n let node = container;\n let targetOffset = 0;\n while (isText$6(node)) {\n const dataLen = node.data.length;\n if (offset >= targetOffset && offset <= targetOffset + dataLen) {\n container = node;\n offset = offset - targetOffset;\n break;\n }\n if (!isText$6(node.nextSibling)) {\n container = node;\n offset = dataLen;\n break;\n }\n targetOffset += dataLen;\n node = node.nextSibling;\n }\n if (isText$6(container) && offset > container.data.length) {\n offset = container.data.length;\n }\n return CaretPosition(container, offset);\n };\n const resolve$1 = (root, path) => {\n if (!path) {\n return null;\n }\n const parts = path.split(',');\n const paths = parts[0].split('/');\n const offset = parts.length > 1 ? parts[1] : 'before';\n const container = reduce(paths, (result, value) => {\n const match = /([\\w\\-\\(\\)]+)\\[([0-9]+)\\]/.exec(value);\n if (!match) {\n return null;\n }\n if (match[1] === 'text()') {\n match[1] = '#text';\n }\n return resolvePathItem(result, match[1], parseInt(match[2], 10));\n }, root);\n if (!container) {\n return null;\n }\n if (!isText$6(container) && container.parentNode) {\n let nodeOffset;\n if (offset === 'after') {\n nodeOffset = nodeIndex(container) + 1;\n } else {\n nodeOffset = nodeIndex(container);\n }\n return CaretPosition(container.parentNode, nodeOffset);\n }\n return findTextPosition(container, parseInt(offset, 10));\n };\n\n const isContentEditableFalse$9 = isContentEditableFalse$b;\n const getNormalizedTextOffset$1 = (trim, container, offset) => {\n let trimmedOffset = trim(container.data.slice(0, offset)).length;\n for (let node = container.previousSibling; node && isText$b(node); node = node.previousSibling) {\n trimmedOffset += trim(node.data).length;\n }\n return trimmedOffset;\n };\n const getPoint = (dom, trim, normalized, rng, start) => {\n const container = start ? rng.startContainer : rng.endContainer;\n let offset = start ? rng.startOffset : rng.endOffset;\n const point = [];\n const root = dom.getRoot();\n if (isText$b(container)) {\n point.push(normalized ? getNormalizedTextOffset$1(trim, container, offset) : offset);\n } else {\n let after = 0;\n const childNodes = container.childNodes;\n if (offset >= childNodes.length && childNodes.length) {\n after = 1;\n offset = Math.max(0, childNodes.length - 1);\n }\n point.push(dom.nodeIndex(childNodes[offset], normalized) + after);\n }\n for (let node = container; node && node !== root; node = node.parentNode) {\n point.push(dom.nodeIndex(node, normalized));\n }\n return point;\n };\n const getLocation = (trim, selection, normalized, rng) => {\n const dom = selection.dom;\n const start = getPoint(dom, trim, normalized, rng, true);\n const forward = selection.isForward();\n const fakeCaret = isRangeInCaretContainerBlock(rng) ? { isFakeCaret: true } : {};\n if (!selection.isCollapsed()) {\n const end = getPoint(dom, trim, normalized, rng, false);\n return {\n start,\n end,\n forward,\n ...fakeCaret\n };\n } else {\n return {\n start,\n forward,\n ...fakeCaret\n };\n }\n };\n const findIndex = (dom, name, element) => {\n let count = 0;\n Tools.each(dom.select(name), node => {\n if (node.getAttribute('data-mce-bogus') === 'all') {\n return;\n } else if (node === element) {\n return false;\n } else {\n count++;\n return;\n }\n });\n return count;\n };\n const moveEndPoint$1 = (rng, start) => {\n let container = start ? rng.startContainer : rng.endContainer;\n let offset = start ? rng.startOffset : rng.endOffset;\n if (isElement$6(container) && container.nodeName === 'TR') {\n const childNodes = container.childNodes;\n container = childNodes[Math.min(start ? offset : offset - 1, childNodes.length - 1)];\n if (container) {\n offset = start ? 0 : container.childNodes.length;\n if (start) {\n rng.setStart(container, offset);\n } else {\n rng.setEnd(container, offset);\n }\n }\n }\n };\n const normalizeTableCellSelection = rng => {\n moveEndPoint$1(rng, true);\n moveEndPoint$1(rng, false);\n return rng;\n };\n const findSibling = (node, offset) => {\n if (isElement$6(node)) {\n node = getNode$1(node, offset);\n if (isContentEditableFalse$9(node)) {\n return node;\n }\n }\n if (isCaretContainer$2(node)) {\n if (isText$b(node) && isCaretContainerBlock$1(node)) {\n node = node.parentNode;\n }\n let sibling = node.previousSibling;\n if (isContentEditableFalse$9(sibling)) {\n return sibling;\n }\n sibling = node.nextSibling;\n if (isContentEditableFalse$9(sibling)) {\n return sibling;\n }\n }\n return undefined;\n };\n const findAdjacentContentEditableFalseElm = rng => {\n return findSibling(rng.startContainer, rng.startOffset) || findSibling(rng.endContainer, rng.endOffset);\n };\n const getOffsetBookmark = (trim, normalized, selection) => {\n const element = selection.getNode();\n const rng = selection.getRng();\n if (element.nodeName === 'IMG' || isContentEditableFalse$9(element)) {\n const name = element.nodeName;\n return {\n name,\n index: findIndex(selection.dom, name, element)\n };\n }\n const sibling = findAdjacentContentEditableFalseElm(rng);\n if (sibling) {\n const name = sibling.tagName;\n return {\n name,\n index: findIndex(selection.dom, name, sibling)\n };\n }\n return getLocation(trim, selection, normalized, rng);\n };\n const getCaretBookmark = selection => {\n const rng = selection.getRng();\n return {\n start: create$a(selection.dom.getRoot(), CaretPosition.fromRangeStart(rng)),\n end: create$a(selection.dom.getRoot(), CaretPosition.fromRangeEnd(rng)),\n forward: selection.isForward()\n };\n };\n const getRangeBookmark = selection => {\n return {\n rng: selection.getRng(),\n forward: selection.isForward()\n };\n };\n const createBookmarkSpan = (dom, id, filled) => {\n const args = {\n 'data-mce-type': 'bookmark',\n id,\n 'style': 'overflow:hidden;line-height:0px'\n };\n return filled ? dom.create('span', args, '') : dom.create('span', args);\n };\n const getPersistentBookmark = (selection, filled) => {\n const dom = selection.dom;\n let rng = selection.getRng();\n const id = dom.uniqueId();\n const collapsed = selection.isCollapsed();\n const element = selection.getNode();\n const name = element.nodeName;\n const forward = selection.isForward();\n if (name === 'IMG') {\n return {\n name,\n index: findIndex(dom, name, element)\n };\n }\n const rng2 = normalizeTableCellSelection(rng.cloneRange());\n if (!collapsed) {\n rng2.collapse(false);\n const endBookmarkNode = createBookmarkSpan(dom, id + '_end', filled);\n rangeInsertNode(dom, rng2, endBookmarkNode);\n }\n rng = normalizeTableCellSelection(rng);\n rng.collapse(true);\n const startBookmarkNode = createBookmarkSpan(dom, id + '_start', filled);\n rangeInsertNode(dom, rng, startBookmarkNode);\n selection.moveToBookmark({\n id,\n keep: true,\n forward\n });\n return {\n id,\n forward\n };\n };\n const getBookmark$3 = (selection, type, normalized = false) => {\n if (type === 2) {\n return getOffsetBookmark(trim$2, normalized, selection);\n } else if (type === 3) {\n return getCaretBookmark(selection);\n } else if (type) {\n return getRangeBookmark(selection);\n } else {\n return getPersistentBookmark(selection, false);\n }\n };\n const getUndoBookmark = curry(getOffsetBookmark, identity, true);\n\n const value$1 = value => {\n const applyHelper = fn => fn(value);\n const constHelper = constant(value);\n const outputHelper = () => output;\n const output = {\n tag: true,\n inner: value,\n fold: (_onError, onValue) => onValue(value),\n isValue: always,\n isError: never,\n map: mapper => Result.value(mapper(value)),\n mapError: outputHelper,\n bind: applyHelper,\n exists: applyHelper,\n forall: applyHelper,\n getOr: constHelper,\n or: outputHelper,\n getOrThunk: constHelper,\n orThunk: outputHelper,\n getOrDie: constHelper,\n each: fn => {\n fn(value);\n },\n toOptional: () => Optional.some(value)\n };\n return output;\n };\n const error = error => {\n const outputHelper = () => output;\n const output = {\n tag: false,\n inner: error,\n fold: (onError, _onValue) => onError(error),\n isValue: never,\n isError: always,\n map: outputHelper,\n mapError: mapper => Result.error(mapper(error)),\n bind: outputHelper,\n exists: never,\n forall: always,\n getOr: identity,\n or: identity,\n getOrThunk: apply$1,\n orThunk: apply$1,\n getOrDie: die(String(error)),\n each: noop,\n toOptional: Optional.none\n };\n return output;\n };\n const fromOption = (optional, err) => optional.fold(() => error(err), value$1);\n const Result = {\n value: value$1,\n error,\n fromOption\n };\n\n const generate = cases => {\n if (!isArray$1(cases)) {\n throw new Error('cases must be an array');\n }\n if (cases.length === 0) {\n throw new Error('there must be at least one case');\n }\n const constructors = [];\n const adt = {};\n each$e(cases, (acase, count) => {\n const keys$1 = keys(acase);\n if (keys$1.length !== 1) {\n throw new Error('one and only one name per case');\n }\n const key = keys$1[0];\n const value = acase[key];\n if (adt[key] !== undefined) {\n throw new Error('duplicate key detected:' + key);\n } else if (key === 'cata') {\n throw new Error('cannot have a case named cata (sorry)');\n } else if (!isArray$1(value)) {\n throw new Error('case arguments must be an array');\n }\n constructors.push(key);\n adt[key] = (...args) => {\n const argLength = args.length;\n if (argLength !== value.length) {\n throw new Error('Wrong number of arguments to case ' + key + '. Expected ' + value.length + ' (' + value + '), got ' + argLength);\n }\n const match = branches => {\n const branchKeys = keys(branches);\n if (constructors.length !== branchKeys.length) {\n throw new Error('Wrong number of arguments to match. Expected: ' + constructors.join(',') + '\\nActual: ' + branchKeys.join(','));\n }\n const allReqd = forall(constructors, reqKey => {\n return contains$2(branchKeys, reqKey);\n });\n if (!allReqd) {\n throw new Error('Not all branches were specified when using match. Specified: ' + branchKeys.join(', ') + '\\nRequired: ' + constructors.join(', '));\n }\n return branches[key].apply(null, args);\n };\n return {\n fold: (...foldArgs) => {\n if (foldArgs.length !== cases.length) {\n throw new Error('Wrong number of arguments to fold. Expected ' + cases.length + ', got ' + foldArgs.length);\n }\n const target = foldArgs[count];\n return target.apply(null, args);\n },\n match,\n log: label => {\n console.log(label, {\n constructors,\n constructor: key,\n params: args\n });\n }\n };\n };\n });\n return adt;\n };\n const Adt = { generate };\n\n Adt.generate([\n {\n bothErrors: [\n 'error1',\n 'error2'\n ]\n },\n {\n firstError: [\n 'error1',\n 'value2'\n ]\n },\n {\n secondError: [\n 'value1',\n 'error2'\n ]\n },\n {\n bothValues: [\n 'value1',\n 'value2'\n ]\n }\n ]);\n const partition$1 = results => {\n const errors = [];\n const values = [];\n each$e(results, result => {\n result.fold(err => {\n errors.push(err);\n }, value => {\n values.push(value);\n });\n });\n return {\n errors,\n values\n };\n };\n\n const isInlinePattern = pattern => pattern.type === 'inline-command' || pattern.type === 'inline-format';\n const isBlockPattern = pattern => pattern.type === 'block-command' || pattern.type === 'block-format';\n const hasBlockTrigger = (pattern, trigger) => (pattern.type === 'block-command' || pattern.type === 'block-format') && pattern.trigger === trigger;\n const normalizePattern = pattern => {\n var _a;\n const err = message => Result.error({\n message,\n pattern\n });\n const formatOrCmd = (name, onFormat, onCommand) => {\n if (pattern.format !== undefined) {\n let formats;\n if (isArray$1(pattern.format)) {\n if (!forall(pattern.format, isString)) {\n return err(name + ' pattern has non-string items in the `format` array');\n }\n formats = pattern.format;\n } else if (isString(pattern.format)) {\n formats = [pattern.format];\n } else {\n return err(name + ' pattern has non-string `format` parameter');\n }\n return Result.value(onFormat(formats));\n } else if (pattern.cmd !== undefined) {\n if (!isString(pattern.cmd)) {\n return err(name + ' pattern has non-string `cmd` parameter');\n }\n return Result.value(onCommand(pattern.cmd, pattern.value));\n } else {\n return err(name + ' pattern is missing both `format` and `cmd` parameters');\n }\n };\n if (!isObject(pattern)) {\n return err('Raw pattern is not an object');\n }\n if (!isString(pattern.start)) {\n return err('Raw pattern is missing `start` parameter');\n }\n if (pattern.end !== undefined) {\n if (!isString(pattern.end)) {\n return err('Inline pattern has non-string `end` parameter');\n }\n if (pattern.start.length === 0 && pattern.end.length === 0) {\n return err('Inline pattern has empty `start` and `end` parameters');\n }\n let start = pattern.start;\n let end = pattern.end;\n if (end.length === 0) {\n end = start;\n start = '';\n }\n return formatOrCmd('Inline', format => ({\n type: 'inline-format',\n start,\n end,\n format\n }), (cmd, value) => ({\n type: 'inline-command',\n start,\n end,\n cmd,\n value\n }));\n } else if (pattern.replacement !== undefined) {\n if (!isString(pattern.replacement)) {\n return err('Replacement pattern has non-string `replacement` parameter');\n }\n if (pattern.start.length === 0) {\n return err('Replacement pattern has empty `start` parameter');\n }\n return Result.value({\n type: 'inline-command',\n start: '',\n end: pattern.start,\n cmd: 'mceInsertContent',\n value: pattern.replacement\n });\n } else {\n const trigger = (_a = pattern.trigger) !== null && _a !== void 0 ? _a : 'space';\n if (pattern.start.length === 0) {\n return err('Block pattern has empty `start` parameter');\n }\n return formatOrCmd('Block', formats => ({\n type: 'block-format',\n start: pattern.start,\n format: formats[0],\n trigger\n }), (command, commandValue) => ({\n type: 'block-command',\n start: pattern.start,\n cmd: command,\n value: commandValue,\n trigger\n }));\n }\n };\n const getBlockPatterns = patterns => filter$5(patterns, isBlockPattern);\n const getInlinePatterns = patterns => filter$5(patterns, isInlinePattern);\n const createPatternSet = (patterns, dynamicPatternsLookup) => ({\n inlinePatterns: getInlinePatterns(patterns),\n blockPatterns: getBlockPatterns(patterns),\n dynamicPatternsLookup\n });\n const filterByTrigger = (patterns, trigger) => {\n return {\n ...patterns,\n blockPatterns: filter$5(patterns.blockPatterns, pattern => hasBlockTrigger(pattern, trigger))\n };\n };\n const fromRawPatterns = patterns => {\n const normalized = partition$1(map$3(patterns, normalizePattern));\n each$e(normalized.errors, err => console.error(err.message, err.pattern));\n return normalized.values;\n };\n const fromRawPatternsLookup = lookupFn => {\n return ctx => {\n const rawPatterns = lookupFn(ctx);\n return fromRawPatterns(rawPatterns);\n };\n };\n\n const firePreProcess = (editor, args) => editor.dispatch('PreProcess', args);\n const firePostProcess = (editor, args) => editor.dispatch('PostProcess', args);\n const fireRemove = editor => {\n editor.dispatch('remove');\n };\n const fireDetach = editor => {\n editor.dispatch('detach');\n };\n const fireSwitchMode = (editor, mode) => {\n editor.dispatch('SwitchMode', { mode });\n };\n const fireObjectResizeStart = (editor, target, width, height, origin) => {\n editor.dispatch('ObjectResizeStart', {\n target,\n width,\n height,\n origin\n });\n };\n const fireObjectResized = (editor, target, width, height, origin) => {\n editor.dispatch('ObjectResized', {\n target,\n width,\n height,\n origin\n });\n };\n const firePreInit = editor => {\n editor.dispatch('PreInit');\n };\n const firePostRender = editor => {\n editor.dispatch('PostRender');\n };\n const fireInit = editor => {\n editor.dispatch('Init');\n };\n const firePlaceholderToggle = (editor, state) => {\n editor.dispatch('PlaceholderToggle', { state });\n };\n const fireError = (editor, errorType, error) => {\n editor.dispatch(errorType, error);\n };\n const fireFormatApply = (editor, format, node, vars) => {\n editor.dispatch('FormatApply', {\n format,\n node,\n vars\n });\n };\n const fireFormatRemove = (editor, format, node, vars) => {\n editor.dispatch('FormatRemove', {\n format,\n node,\n vars\n });\n };\n const fireBeforeSetContent = (editor, args) => editor.dispatch('BeforeSetContent', args);\n const fireSetContent = (editor, args) => editor.dispatch('SetContent', args);\n const fireBeforeGetContent = (editor, args) => editor.dispatch('BeforeGetContent', args);\n const fireGetContent = (editor, args) => editor.dispatch('GetContent', args);\n const fireAutocompleterStart = (editor, args) => {\n editor.dispatch('AutocompleterStart', args);\n };\n const fireAutocompleterUpdate = (editor, args) => {\n editor.dispatch('AutocompleterUpdate', args);\n };\n const fireAutocompleterUpdateActiveRange = (editor, args) => {\n editor.dispatch('AutocompleterUpdateActiveRange', args);\n };\n const fireAutocompleterEnd = editor => {\n editor.dispatch('AutocompleterEnd');\n };\n const firePastePreProcess = (editor, html, internal) => editor.dispatch('PastePreProcess', {\n content: html,\n internal\n });\n const firePastePostProcess = (editor, node, internal) => editor.dispatch('PastePostProcess', {\n node,\n internal\n });\n const firePastePlainTextToggle = (editor, state) => editor.dispatch('PastePlainTextToggle', { state });\n const fireEditableRootStateChange = (editor, state) => editor.dispatch('EditableRootStateChange', { state });\n const fireDisabledStateChange = (editor, state) => editor.dispatch('DisabledStateChange', { state });\n\n const deviceDetection$1 = detect$1().deviceType;\n const isTouch = deviceDetection$1.isTouch();\n const DOM$a = DOMUtils.DOM;\n const getHash = value => {\n const items = value.indexOf('=') > 0 ? value.split(/[;,](?![^=;,]*(?:[;,]|$))/) : value.split(',');\n return foldl(items, (output, item) => {\n const arr = item.split('=');\n const key = arr[0];\n const val = arr.length > 1 ? arr[1] : key;\n output[trim$4(key)] = trim$4(val);\n return output;\n }, {});\n };\n const isRegExp = x => is$4(x, RegExp);\n const option = name => editor => editor.options.get(name);\n const stringOrObjectProcessor = value => isString(value) || isObject(value);\n const bodyOptionProcessor = (editor, defaultValue = '') => value => {\n const valid = isString(value);\n if (valid) {\n if (value.indexOf('=') !== -1) {\n const bodyObj = getHash(value);\n return {\n value: get$a(bodyObj, editor.id).getOr(defaultValue),\n valid\n };\n } else {\n return {\n value,\n valid\n };\n }\n } else {\n return {\n valid: false,\n message: 'Must be a string.'\n };\n }\n };\n const register$7 = editor => {\n const registerOption = editor.options.register;\n registerOption('id', {\n processor: 'string',\n default: editor.id\n });\n registerOption('selector', { processor: 'string' });\n registerOption('target', { processor: 'object' });\n registerOption('suffix', { processor: 'string' });\n registerOption('cache_suffix', { processor: 'string' });\n registerOption('base_url', { processor: 'string' });\n registerOption('referrer_policy', {\n processor: 'string',\n default: ''\n });\n registerOption('language_load', {\n processor: 'boolean',\n default: true\n });\n registerOption('inline', {\n processor: 'boolean',\n default: false\n });\n registerOption('iframe_attrs', {\n processor: 'object',\n default: {}\n });\n registerOption('doctype', {\n processor: 'string',\n default: ''\n });\n registerOption('document_base_url', {\n processor: 'string',\n default: editor.documentBaseUrl\n });\n registerOption('body_id', {\n processor: bodyOptionProcessor(editor, 'tinymce'),\n default: 'tinymce'\n });\n registerOption('body_class', {\n processor: bodyOptionProcessor(editor),\n default: ''\n });\n registerOption('content_security_policy', {\n processor: 'string',\n default: ''\n });\n registerOption('br_in_pre', {\n processor: 'boolean',\n default: true\n });\n registerOption('forced_root_block', {\n processor: value => {\n const valid = isString(value) && isNotEmpty(value);\n if (valid) {\n return {\n value,\n valid\n };\n } else {\n return {\n valid: false,\n message: 'Must be a non-empty string.'\n };\n }\n },\n default: 'p'\n });\n registerOption('forced_root_block_attrs', {\n processor: 'object',\n default: {}\n });\n registerOption('newline_behavior', {\n processor: value => {\n const valid = contains$2([\n 'block',\n 'linebreak',\n 'invert',\n 'default'\n ], value);\n return valid ? {\n value,\n valid\n } : {\n valid: false,\n message: 'Must be one of: block, linebreak, invert or default.'\n };\n },\n default: 'default'\n });\n registerOption('br_newline_selector', {\n processor: 'string',\n default: '.mce-toc h2,figcaption,caption'\n });\n registerOption('no_newline_selector', {\n processor: 'string',\n default: ''\n });\n registerOption('keep_styles', {\n processor: 'boolean',\n default: true\n });\n registerOption('end_container_on_empty_block', {\n processor: value => {\n if (isBoolean(value)) {\n return {\n valid: true,\n value\n };\n } else if (isString(value)) {\n return {\n valid: true,\n value\n };\n } else {\n return {\n valid: false,\n message: 'Must be boolean or a string'\n };\n }\n },\n default: 'blockquote'\n });\n registerOption('font_size_style_values', {\n processor: 'string',\n default: 'xx-small,x-small,small,medium,large,x-large,xx-large'\n });\n registerOption('font_size_legacy_values', {\n processor: 'string',\n default: 'xx-small,small,medium,large,x-large,xx-large,300%'\n });\n registerOption('font_size_classes', {\n processor: 'string',\n default: ''\n });\n registerOption('automatic_uploads', {\n processor: 'boolean',\n default: true\n });\n registerOption('images_reuse_filename', {\n processor: 'boolean',\n default: false\n });\n registerOption('images_replace_blob_uris', {\n processor: 'boolean',\n default: true\n });\n registerOption('icons', {\n processor: 'string',\n default: ''\n });\n registerOption('icons_url', {\n processor: 'string',\n default: ''\n });\n registerOption('images_upload_url', {\n processor: 'string',\n default: ''\n });\n registerOption('images_upload_base_path', {\n processor: 'string',\n default: ''\n });\n registerOption('images_upload_credentials', {\n processor: 'boolean',\n default: false\n });\n registerOption('images_upload_handler', { processor: 'function' });\n registerOption('language', {\n processor: 'string',\n default: 'en'\n });\n registerOption('language_url', {\n processor: 'string',\n default: ''\n });\n registerOption('entity_encoding', {\n processor: 'string',\n default: 'named'\n });\n registerOption('indent', {\n processor: 'boolean',\n default: true\n });\n registerOption('indent_before', {\n processor: 'string',\n default: 'p,h1,h2,h3,h4,h5,h6,blockquote,div,title,style,pre,script,td,th,ul,ol,li,dl,dt,dd,area,table,thead,' + 'tfoot,tbody,tr,section,details,summary,article,hgroup,aside,figure,figcaption,option,optgroup,datalist'\n });\n registerOption('indent_after', {\n processor: 'string',\n default: 'p,h1,h2,h3,h4,h5,h6,blockquote,div,title,style,pre,script,td,th,ul,ol,li,dl,dt,dd,area,table,thead,' + 'tfoot,tbody,tr,section,details,summary,article,hgroup,aside,figure,figcaption,option,optgroup,datalist'\n });\n registerOption('indent_use_margin', {\n processor: 'boolean',\n default: false\n });\n registerOption('indentation', {\n processor: 'string',\n default: '40px'\n });\n registerOption('content_css', {\n processor: value => {\n const valid = value === false || isString(value) || isArrayOf(value, isString);\n if (valid) {\n if (isString(value)) {\n return {\n value: map$3(value.split(','), trim$4),\n valid\n };\n } else if (isArray$1(value)) {\n return {\n value,\n valid\n };\n } else if (value === false) {\n return {\n value: [],\n valid\n };\n } else {\n return {\n value,\n valid\n };\n }\n } else {\n return {\n valid: false,\n message: 'Must be false, a string or an array of strings.'\n };\n }\n },\n default: isInline$1(editor) ? [] : ['default']\n });\n registerOption('content_style', { processor: 'string' });\n registerOption('content_css_cors', {\n processor: 'boolean',\n default: false\n });\n registerOption('font_css', {\n processor: value => {\n const valid = isString(value) || isArrayOf(value, isString);\n if (valid) {\n const newValue = isArray$1(value) ? value : map$3(value.split(','), trim$4);\n return {\n value: newValue,\n valid\n };\n } else {\n return {\n valid: false,\n message: 'Must be a string or an array of strings.'\n };\n }\n },\n default: []\n });\n registerOption('inline_boundaries', {\n processor: 'boolean',\n default: true\n });\n registerOption('inline_boundaries_selector', {\n processor: 'string',\n default: 'a[href],code,span.mce-annotation'\n });\n registerOption('object_resizing', {\n processor: value => {\n const valid = isBoolean(value) || isString(value);\n if (valid) {\n if (value === false || deviceDetection$1.isiPhone() || deviceDetection$1.isiPad()) {\n return {\n value: '',\n valid\n };\n } else {\n return {\n value: value === true ? 'table,img,figure.image,div,video,iframe' : value,\n valid\n };\n }\n } else {\n return {\n valid: false,\n message: 'Must be boolean or a string'\n };\n }\n },\n default: !isTouch\n });\n registerOption('resize_img_proportional', {\n processor: 'boolean',\n default: true\n });\n registerOption('event_root', { processor: 'string' });\n registerOption('service_message', { processor: 'string' });\n registerOption('theme', {\n processor: value => value === false || isString(value) || isFunction(value),\n default: 'silver'\n });\n registerOption('theme_url', { processor: 'string' });\n registerOption('formats', { processor: 'object' });\n registerOption('format_empty_lines', {\n processor: 'boolean',\n default: false\n });\n registerOption('format_noneditable_selector', {\n processor: 'string',\n default: ''\n });\n registerOption('preview_styles', {\n processor: value => {\n const valid = value === false || isString(value);\n if (valid) {\n return {\n value: value === false ? '' : value,\n valid\n };\n } else {\n return {\n valid: false,\n message: 'Must be false or a string'\n };\n }\n },\n default: 'font-family font-size font-weight font-style text-decoration text-transform color background-color border border-radius outline text-shadow'\n });\n registerOption('custom_ui_selector', {\n processor: 'string',\n default: ''\n });\n registerOption('hidden_input', {\n processor: 'boolean',\n default: true\n });\n registerOption('submit_patch', {\n processor: 'boolean',\n default: true\n });\n registerOption('encoding', { processor: 'string' });\n registerOption('add_form_submit_trigger', {\n processor: 'boolean',\n default: true\n });\n registerOption('add_unload_trigger', {\n processor: 'boolean',\n default: true\n });\n registerOption('custom_undo_redo_levels', {\n processor: 'number',\n default: 0\n });\n registerOption('disable_nodechange', {\n processor: 'boolean',\n default: false\n });\n registerOption('disabled', {\n processor: value => {\n if (isBoolean(value)) {\n if (editor.initialized && isDisabled$1(editor) !== value) {\n Promise.resolve().then(() => {\n fireDisabledStateChange(editor, value);\n });\n }\n return {\n valid: true,\n value\n };\n }\n return {\n valid: false,\n message: 'The value must be a boolean.'\n };\n },\n default: false\n });\n registerOption('readonly', {\n processor: 'boolean',\n default: false\n });\n registerOption('editable_root', {\n processor: 'boolean',\n default: true\n });\n registerOption('plugins', {\n processor: 'string[]',\n default: []\n });\n registerOption('external_plugins', { processor: 'object' });\n registerOption('forced_plugins', { processor: 'string[]' });\n registerOption('model', {\n processor: 'string',\n default: editor.hasPlugin('rtc') ? 'plugin' : 'dom'\n });\n registerOption('model_url', { processor: 'string' });\n registerOption('block_unsupported_drop', {\n processor: 'boolean',\n default: true\n });\n registerOption('visual', {\n processor: 'boolean',\n default: true\n });\n registerOption('visual_table_class', {\n processor: 'string',\n default: 'mce-item-table'\n });\n registerOption('visual_anchor_class', {\n processor: 'string',\n default: 'mce-item-anchor'\n });\n registerOption('iframe_aria_text', {\n processor: 'string',\n default: 'Rich Text Area. Press ALT-0 for help.'\n });\n registerOption('setup', { processor: 'function' });\n registerOption('init_instance_callback', { processor: 'function' });\n registerOption('url_converter', {\n processor: 'function',\n default: editor.convertURL\n });\n registerOption('url_converter_scope', {\n processor: 'object',\n default: editor\n });\n registerOption('urlconverter_callback', { processor: 'function' });\n registerOption('allow_conditional_comments', {\n processor: 'boolean',\n default: false\n });\n registerOption('allow_html_data_urls', {\n processor: 'boolean',\n default: false\n });\n registerOption('allow_svg_data_urls', { processor: 'boolean' });\n registerOption('allow_html_in_named_anchor', {\n processor: 'boolean',\n default: false\n });\n registerOption('allow_script_urls', {\n processor: 'boolean',\n default: false\n });\n registerOption('allow_unsafe_link_target', {\n processor: 'boolean',\n default: false\n });\n registerOption('allow_mathml_annotation_encodings', {\n processor: value => {\n const valid = isArrayOf(value, isString);\n return valid ? {\n value,\n valid\n } : {\n valid: false,\n message: 'Must be an array of strings.'\n };\n },\n default: []\n });\n registerOption('convert_fonts_to_spans', {\n processor: 'boolean',\n default: true,\n deprecated: true\n });\n registerOption('fix_list_elements', {\n processor: 'boolean',\n default: false\n });\n registerOption('preserve_cdata', {\n processor: 'boolean',\n default: false\n });\n registerOption('remove_trailing_brs', {\n processor: 'boolean',\n default: true\n });\n registerOption('pad_empty_with_br', {\n processor: 'boolean',\n default: false\n });\n registerOption('inline_styles', {\n processor: 'boolean',\n default: true,\n deprecated: true\n });\n registerOption('element_format', {\n processor: 'string',\n default: 'html'\n });\n registerOption('entities', { processor: 'string' });\n registerOption('schema', {\n processor: 'string',\n default: 'html5'\n });\n registerOption('convert_urls', {\n processor: 'boolean',\n default: true\n });\n registerOption('relative_urls', {\n processor: 'boolean',\n default: true\n });\n registerOption('remove_script_host', {\n processor: 'boolean',\n default: true\n });\n registerOption('custom_elements', { processor: stringOrObjectProcessor });\n registerOption('extended_valid_elements', { processor: 'string' });\n registerOption('invalid_elements', { processor: 'string' });\n registerOption('invalid_styles', { processor: stringOrObjectProcessor });\n registerOption('valid_children', { processor: 'string' });\n registerOption('valid_classes', { processor: stringOrObjectProcessor });\n registerOption('valid_elements', { processor: 'string' });\n registerOption('valid_styles', { processor: stringOrObjectProcessor });\n registerOption('verify_html', {\n processor: 'boolean',\n default: true\n });\n registerOption('auto_focus', { processor: value => isString(value) || value === true });\n registerOption('browser_spellcheck', {\n processor: 'boolean',\n default: false\n });\n registerOption('protect', { processor: 'array' });\n registerOption('images_file_types', {\n processor: 'string',\n default: 'jpeg,jpg,jpe,jfi,jif,jfif,png,gif,bmp,webp'\n });\n registerOption('deprecation_warnings', {\n processor: 'boolean',\n default: true\n });\n registerOption('a11y_advanced_options', {\n processor: 'boolean',\n default: false\n });\n registerOption('api_key', { processor: 'string' });\n registerOption('license_key', { processor: 'string' });\n registerOption('paste_block_drop', {\n processor: 'boolean',\n default: false\n });\n registerOption('paste_data_images', {\n processor: 'boolean',\n default: true\n });\n registerOption('paste_preprocess', { processor: 'function' });\n registerOption('paste_postprocess', { processor: 'function' });\n registerOption('paste_webkit_styles', {\n processor: 'string',\n default: 'none'\n });\n registerOption('paste_remove_styles_if_webkit', {\n processor: 'boolean',\n default: true\n });\n registerOption('paste_merge_formats', {\n processor: 'boolean',\n default: true\n });\n registerOption('smart_paste', {\n processor: 'boolean',\n default: true\n });\n registerOption('paste_as_text', {\n processor: 'boolean',\n default: false\n });\n registerOption('paste_tab_spaces', {\n processor: 'number',\n default: 4\n });\n registerOption('text_patterns', {\n processor: value => {\n if (isArrayOf(value, isObject) || value === false) {\n const patterns = value === false ? [] : value;\n return {\n value: fromRawPatterns(patterns),\n valid: true\n };\n } else {\n return {\n valid: false,\n message: 'Must be an array of objects or false.'\n };\n }\n },\n default: [\n {\n start: '*',\n end: '*',\n format: 'italic'\n },\n {\n start: '**',\n end: '**',\n format: 'bold'\n },\n {\n start: '#',\n format: 'h1',\n trigger: 'space'\n },\n {\n start: '##',\n format: 'h2',\n trigger: 'space'\n },\n {\n start: '###',\n format: 'h3',\n trigger: 'space'\n },\n {\n start: '####',\n format: 'h4',\n trigger: 'space'\n },\n {\n start: '#####',\n format: 'h5',\n trigger: 'space'\n },\n {\n start: '######',\n format: 'h6',\n trigger: 'space'\n },\n {\n start: '1.',\n cmd: 'InsertOrderedList',\n trigger: 'space'\n },\n {\n start: '*',\n cmd: 'InsertUnorderedList',\n trigger: 'space'\n },\n {\n start: '-',\n cmd: 'InsertUnorderedList',\n trigger: 'space'\n },\n {\n start: '>',\n cmd: 'mceBlockQuote',\n trigger: 'space'\n },\n {\n start: '---',\n cmd: 'InsertHorizontalRule',\n trigger: 'space'\n }\n ]\n });\n registerOption('text_patterns_lookup', {\n processor: value => {\n if (isFunction(value)) {\n return {\n value: fromRawPatternsLookup(value),\n valid: true\n };\n } else {\n return {\n valid: false,\n message: 'Must be a single function'\n };\n }\n },\n default: _ctx => []\n });\n registerOption('noneditable_class', {\n processor: 'string',\n default: 'mceNonEditable'\n });\n registerOption('editable_class', {\n processor: 'string',\n default: 'mceEditable'\n });\n registerOption('noneditable_regexp', {\n processor: value => {\n if (isArrayOf(value, isRegExp)) {\n return {\n value,\n valid: true\n };\n } else if (isRegExp(value)) {\n return {\n value: [value],\n valid: true\n };\n } else {\n return {\n valid: false,\n message: 'Must be a RegExp or an array of RegExp.'\n };\n }\n },\n default: []\n });\n registerOption('table_tab_navigation', {\n processor: 'boolean',\n default: true\n });\n registerOption('highlight_on_focus', {\n processor: 'boolean',\n default: true\n });\n registerOption('xss_sanitization', {\n processor: 'boolean',\n default: true\n });\n registerOption('details_initial_state', {\n processor: value => {\n const valid = contains$2([\n 'inherited',\n 'collapsed',\n 'expanded'\n ], value);\n return valid ? {\n value,\n valid\n } : {\n valid: false,\n message: 'Must be one of: inherited, collapsed, or expanded.'\n };\n },\n default: 'inherited'\n });\n registerOption('details_serialized_state', {\n processor: value => {\n const valid = contains$2([\n 'inherited',\n 'collapsed',\n 'expanded'\n ], value);\n return valid ? {\n value,\n valid\n } : {\n valid: false,\n message: 'Must be one of: inherited, collapsed, or expanded.'\n };\n },\n default: 'inherited'\n });\n registerOption('init_content_sync', {\n processor: 'boolean',\n default: false\n });\n registerOption('newdocument_content', {\n processor: 'string',\n default: ''\n });\n registerOption('sandbox_iframes', {\n processor: 'boolean',\n default: true\n });\n registerOption('sandbox_iframes_exclusions', {\n processor: 'string[]',\n default: [\n 'youtube.com',\n 'youtu.be',\n 'vimeo.com',\n 'player.vimeo.com',\n 'dailymotion.com',\n 'embed.music.apple.com',\n 'open.spotify.com',\n 'giphy.com',\n 'dai.ly',\n 'codepen.io'\n ]\n });\n registerOption('convert_unsafe_embeds', {\n processor: 'boolean',\n default: true\n });\n editor.on('ScriptsLoaded', () => {\n registerOption('directionality', {\n processor: 'string',\n default: I18n.isRtl() ? 'rtl' : undefined\n });\n registerOption('placeholder', {\n processor: 'string',\n default: DOM$a.getAttrib(editor.getElement(), 'placeholder')\n });\n });\n };\n const getIframeAttrs = option('iframe_attrs');\n const getDocType = option('doctype');\n const getDocumentBaseUrl = option('document_base_url');\n const getBodyId = option('body_id');\n const getBodyClass = option('body_class');\n const getContentSecurityPolicy = option('content_security_policy');\n const shouldPutBrInPre$1 = option('br_in_pre');\n const getForcedRootBlock = option('forced_root_block');\n const getForcedRootBlockAttrs = option('forced_root_block_attrs');\n const getNewlineBehavior = option('newline_behavior');\n const getBrNewLineSelector = option('br_newline_selector');\n const getNoNewLineSelector = option('no_newline_selector');\n const shouldKeepStyles = option('keep_styles');\n const shouldEndContainerOnEmptyBlock = option('end_container_on_empty_block');\n const isAutomaticUploadsEnabled = option('automatic_uploads');\n const shouldReuseFileName = option('images_reuse_filename');\n const shouldReplaceBlobUris = option('images_replace_blob_uris');\n const getIconPackName = option('icons');\n const getIconsUrl = option('icons_url');\n const getImageUploadUrl = option('images_upload_url');\n const getImageUploadBasePath = option('images_upload_base_path');\n const getImagesUploadCredentials = option('images_upload_credentials');\n const getImagesUploadHandler = option('images_upload_handler');\n const shouldUseContentCssCors = option('content_css_cors');\n const getReferrerPolicy = option('referrer_policy');\n const getLanguageCode = option('language');\n const getLanguageUrl = option('language_url');\n const shouldIndentUseMargin = option('indent_use_margin');\n const getIndentation = option('indentation');\n const getContentCss = option('content_css');\n const getContentStyle = option('content_style');\n const getFontCss = option('font_css');\n const getDirectionality = option('directionality');\n const getInlineBoundarySelector = option('inline_boundaries_selector');\n const getObjectResizing = option('object_resizing');\n const getResizeImgProportional = option('resize_img_proportional');\n const getPlaceholder = option('placeholder');\n const getEventRoot = option('event_root');\n const getServiceMessage = option('service_message');\n const getTheme = option('theme');\n const getThemeUrl = option('theme_url');\n const getModel = option('model');\n const getModelUrl = option('model_url');\n const isInlineBoundariesEnabled = option('inline_boundaries');\n const getFormats = option('formats');\n const getPreviewStyles = option('preview_styles');\n const canFormatEmptyLines = option('format_empty_lines');\n const getFormatNoneditableSelector = option('format_noneditable_selector');\n const getCustomUiSelector = option('custom_ui_selector');\n const isInline$1 = option('inline');\n const hasHiddenInput = option('hidden_input');\n const shouldPatchSubmit = option('submit_patch');\n const shouldAddFormSubmitTrigger = option('add_form_submit_trigger');\n const shouldAddUnloadTrigger = option('add_unload_trigger');\n const getCustomUndoRedoLevels = option('custom_undo_redo_levels');\n const shouldDisableNodeChange = option('disable_nodechange');\n const isReadOnly$1 = option('readonly');\n const hasEditableRoot$1 = option('editable_root');\n const hasContentCssCors = option('content_css_cors');\n const getPlugins = option('plugins');\n const getExternalPlugins$1 = option('external_plugins');\n const shouldBlockUnsupportedDrop = option('block_unsupported_drop');\n const isVisualAidsEnabled = option('visual');\n const getVisualAidsTableClass = option('visual_table_class');\n const getVisualAidsAnchorClass = option('visual_anchor_class');\n const getIframeAriaText = option('iframe_aria_text');\n const getSetupCallback = option('setup');\n const getInitInstanceCallback = option('init_instance_callback');\n const getUrlConverterCallback = option('urlconverter_callback');\n const getAutoFocus = option('auto_focus');\n const shouldBrowserSpellcheck = option('browser_spellcheck');\n const getProtect = option('protect');\n const shouldPasteBlockDrop = option('paste_block_drop');\n const shouldPasteDataImages = option('paste_data_images');\n const getPastePreProcess = option('paste_preprocess');\n const getPastePostProcess = option('paste_postprocess');\n const getNewDocumentContent = option('newdocument_content');\n const getPasteWebkitStyles = option('paste_webkit_styles');\n const shouldPasteRemoveWebKitStyles = option('paste_remove_styles_if_webkit');\n const shouldPasteMergeFormats = option('paste_merge_formats');\n const isSmartPasteEnabled = option('smart_paste');\n const isPasteAsTextEnabled = option('paste_as_text');\n const getPasteTabSpaces = option('paste_tab_spaces');\n const shouldAllowHtmlDataUrls = option('allow_html_data_urls');\n const getTextPatterns = option('text_patterns');\n const getTextPatternsLookup = option('text_patterns_lookup');\n const getNonEditableClass = option('noneditable_class');\n const getEditableClass = option('editable_class');\n const getNonEditableRegExps = option('noneditable_regexp');\n const shouldPreserveCData = option('preserve_cdata');\n const shouldHighlightOnFocus = option('highlight_on_focus');\n const shouldSanitizeXss = option('xss_sanitization');\n const shouldUseDocumentWrite = option('init_content_sync');\n const hasTextPatternsLookup = editor => editor.options.isSet('text_patterns_lookup');\n const getFontStyleValues = editor => Tools.explode(editor.options.get('font_size_style_values'));\n const getFontSizeClasses = editor => Tools.explode(editor.options.get('font_size_classes'));\n const isEncodingXml = editor => editor.options.get('encoding') === 'xml';\n const getAllowedImageFileTypes = editor => Tools.explode(editor.options.get('images_file_types'));\n const hasTableTabNavigation = option('table_tab_navigation');\n const getDetailsInitialState = option('details_initial_state');\n const getDetailsSerializedState = option('details_serialized_state');\n const shouldSandboxIframes = option('sandbox_iframes');\n const getSandboxIframesExclusions = editor => editor.options.get('sandbox_iframes_exclusions');\n const shouldConvertUnsafeEmbeds = option('convert_unsafe_embeds');\n const getLicenseKey = option('license_key');\n const getApiKey = option('api_key');\n const isDisabled$1 = option('disabled');\n\n const isElement$3 = isElement$6;\n const isText$5 = isText$b;\n const removeNode$1 = node => {\n const parentNode = node.parentNode;\n if (parentNode) {\n parentNode.removeChild(node);\n }\n };\n const trimCount = text => {\n const trimmedText = trim$2(text);\n return {\n count: text.length - trimmedText.length,\n text: trimmedText\n };\n };\n const deleteZwspChars = caretContainer => {\n let idx;\n while ((idx = caretContainer.data.lastIndexOf(ZWSP$1)) !== -1) {\n caretContainer.deleteData(idx, 1);\n }\n };\n const removeUnchanged = (caretContainer, pos) => {\n remove$2(caretContainer);\n return pos;\n };\n const removeTextAndReposition = (caretContainer, pos) => {\n const before = trimCount(caretContainer.data.substr(0, pos.offset()));\n const after = trimCount(caretContainer.data.substr(pos.offset()));\n const text = before.text + after.text;\n if (text.length > 0) {\n deleteZwspChars(caretContainer);\n return CaretPosition(caretContainer, pos.offset() - before.count);\n } else {\n return pos;\n }\n };\n const removeElementAndReposition = (caretContainer, pos) => {\n const parentNode = pos.container();\n const newPosition = indexOf$1(from(parentNode.childNodes), caretContainer).map(index => {\n return index < pos.offset() ? CaretPosition(parentNode, pos.offset() - 1) : pos;\n }).getOr(pos);\n remove$2(caretContainer);\n return newPosition;\n };\n const removeTextCaretContainer = (caretContainer, pos) => isText$5(caretContainer) && pos.container() === caretContainer ? removeTextAndReposition(caretContainer, pos) : removeUnchanged(caretContainer, pos);\n const removeElementCaretContainer = (caretContainer, pos) => pos.container() === caretContainer.parentNode ? removeElementAndReposition(caretContainer, pos) : removeUnchanged(caretContainer, pos);\n const removeAndReposition = (container, pos) => CaretPosition.isTextPosition(pos) ? removeTextCaretContainer(container, pos) : removeElementCaretContainer(container, pos);\n const remove$2 = caretContainerNode => {\n if (isElement$3(caretContainerNode) && isCaretContainer$2(caretContainerNode)) {\n if (hasContent(caretContainerNode)) {\n caretContainerNode.removeAttribute('data-mce-caret');\n } else {\n removeNode$1(caretContainerNode);\n }\n }\n if (isText$5(caretContainerNode)) {\n deleteZwspChars(caretContainerNode);\n if (caretContainerNode.data.length === 0) {\n removeNode$1(caretContainerNode);\n }\n }\n };\n\n const isContentEditableFalse$8 = isContentEditableFalse$b;\n const isMedia$1 = isMedia$2;\n const isTableCell$1 = isTableCell$3;\n const inlineFakeCaretSelector = '*[contentEditable=false],video,audio,embed,object';\n const getAbsoluteClientRect = (root, element, before) => {\n const clientRect = collapse(element.getBoundingClientRect(), before);\n let scrollX;\n let scrollY;\n if (root.tagName === 'BODY') {\n const docElm = root.ownerDocument.documentElement;\n scrollX = root.scrollLeft || docElm.scrollLeft;\n scrollY = root.scrollTop || docElm.scrollTop;\n } else {\n const rootRect = root.getBoundingClientRect();\n scrollX = root.scrollLeft - rootRect.left;\n scrollY = root.scrollTop - rootRect.top;\n }\n clientRect.left += scrollX;\n clientRect.right += scrollX;\n clientRect.top += scrollY;\n clientRect.bottom += scrollY;\n clientRect.width = 1;\n let margin = element.offsetWidth - element.clientWidth;\n if (margin > 0) {\n if (before) {\n margin *= -1;\n }\n clientRect.left += margin;\n clientRect.right += margin;\n }\n return clientRect;\n };\n const trimInlineCaretContainers = root => {\n var _a, _b;\n const fakeCaretTargetNodes = descendants(SugarElement.fromDom(root), inlineFakeCaretSelector);\n for (let i = 0; i < fakeCaretTargetNodes.length; i++) {\n const node = fakeCaretTargetNodes[i].dom;\n let sibling = node.previousSibling;\n if (endsWithCaretContainer$1(sibling)) {\n const data = sibling.data;\n if (data.length === 1) {\n (_a = sibling.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(sibling);\n } else {\n sibling.deleteData(data.length - 1, 1);\n }\n }\n sibling = node.nextSibling;\n if (startsWithCaretContainer$1(sibling)) {\n const data = sibling.data;\n if (data.length === 1) {\n (_b = sibling.parentNode) === null || _b === void 0 ? void 0 : _b.removeChild(sibling);\n } else {\n sibling.deleteData(0, 1);\n }\n }\n }\n };\n const FakeCaret = (editor, root, isBlock, hasFocus) => {\n const lastVisualCaret = value$2();\n let cursorInterval;\n let caretContainerNode;\n const caretBlock = getForcedRootBlock(editor);\n const dom = editor.dom;\n const show = (before, element) => {\n let rng;\n hide();\n if (isTableCell$1(element)) {\n return null;\n }\n if (isBlock(element)) {\n const caretContainer = insertBlock(caretBlock, element, before);\n const clientRect = getAbsoluteClientRect(root, element, before);\n dom.setStyle(caretContainer, 'top', clientRect.top);\n dom.setStyle(caretContainer, 'caret-color', 'transparent');\n caretContainerNode = caretContainer;\n const caret = dom.create('div', {\n 'class': 'mce-visual-caret',\n 'data-mce-bogus': 'all'\n });\n dom.setStyles(caret, { ...clientRect });\n dom.add(root, caret);\n lastVisualCaret.set({\n caret,\n element,\n before\n });\n if (before) {\n dom.addClass(caret, 'mce-visual-caret-before');\n }\n startBlink();\n rng = element.ownerDocument.createRange();\n rng.setStart(caretContainer, 0);\n rng.setEnd(caretContainer, 0);\n } else {\n caretContainerNode = insertInline$1(element, before);\n rng = element.ownerDocument.createRange();\n if (isInlineFakeCaretTarget(caretContainerNode.nextSibling)) {\n rng.setStart(caretContainerNode, 0);\n rng.setEnd(caretContainerNode, 0);\n } else {\n rng.setStart(caretContainerNode, 1);\n rng.setEnd(caretContainerNode, 1);\n }\n return rng;\n }\n return rng;\n };\n const hide = () => {\n trimInlineCaretContainers(root);\n if (caretContainerNode) {\n remove$2(caretContainerNode);\n caretContainerNode = null;\n }\n lastVisualCaret.on(caretState => {\n dom.remove(caretState.caret);\n lastVisualCaret.clear();\n });\n if (cursorInterval) {\n clearInterval(cursorInterval);\n cursorInterval = undefined;\n }\n };\n const startBlink = () => {\n cursorInterval = setInterval(() => {\n lastVisualCaret.on(caretState => {\n if (hasFocus()) {\n dom.toggleClass(caretState.caret, 'mce-visual-caret-hidden');\n } else {\n dom.addClass(caretState.caret, 'mce-visual-caret-hidden');\n }\n });\n }, 500);\n };\n const reposition = () => {\n lastVisualCaret.on(caretState => {\n const clientRect = getAbsoluteClientRect(root, caretState.element, caretState.before);\n dom.setStyles(caretState.caret, { ...clientRect });\n });\n };\n const destroy = () => clearInterval(cursorInterval);\n const getCss = () => '.mce-visual-caret {' + 'position: absolute;' + 'background-color: black;' + 'background-color: currentcolor;' + '}' + '.mce-visual-caret-hidden {' + 'display: none;' + '}' + '*[data-mce-caret] {' + 'position: absolute;' + 'left: -1000px;' + 'right: auto;' + 'top: 0;' + 'margin: 0;' + 'padding: 0;' + '}';\n return {\n show,\n hide,\n getCss,\n reposition,\n destroy\n };\n };\n const isFakeCaretTableBrowser = () => Env.browser.isFirefox();\n const isInlineFakeCaretTarget = node => isContentEditableFalse$8(node) || isMedia$1(node);\n const isFakeCaretTarget = node => {\n const isTarget = isInlineFakeCaretTarget(node) || isTable$2(node) && isFakeCaretTableBrowser();\n return isTarget && parentElement(SugarElement.fromDom(node)).exists(isEditable$2);\n };\n\n const isContentEditableTrue$1 = isContentEditableTrue$3;\n const isContentEditableFalse$7 = isContentEditableFalse$b;\n const isMedia = isMedia$2;\n const isBlockLike = matchStyleValues('display', 'block table table-cell table-row table-caption list-item');\n const isCaretContainer = isCaretContainer$2;\n const isCaretContainerBlock = isCaretContainerBlock$1;\n const isElement$2 = isElement$6;\n const isText$4 = isText$b;\n const isCaretCandidate$1 = isCaretCandidate$3;\n const isForwards = direction => direction > 0;\n const isBackwards = direction => direction < 0;\n const skipCaretContainers = (walk, shallow) => {\n let node;\n while (node = walk(shallow)) {\n if (!isCaretContainerBlock(node)) {\n return node;\n }\n }\n return null;\n };\n const findNode = (node, direction, predicateFn, rootNode, shallow) => {\n const walker = new DomTreeWalker(node, rootNode);\n const isCefOrCaretContainer = isContentEditableFalse$7(node) || isCaretContainerBlock(node);\n let tempNode;\n if (isBackwards(direction)) {\n if (isCefOrCaretContainer) {\n tempNode = skipCaretContainers(walker.prev.bind(walker), true);\n if (predicateFn(tempNode)) {\n return tempNode;\n }\n }\n while (tempNode = skipCaretContainers(walker.prev.bind(walker), shallow)) {\n if (predicateFn(tempNode)) {\n return tempNode;\n }\n }\n }\n if (isForwards(direction)) {\n if (isCefOrCaretContainer) {\n tempNode = skipCaretContainers(walker.next.bind(walker), true);\n if (predicateFn(tempNode)) {\n return tempNode;\n }\n }\n while (tempNode = skipCaretContainers(walker.next.bind(walker), shallow)) {\n if (predicateFn(tempNode)) {\n return tempNode;\n }\n }\n }\n return null;\n };\n const getEditingHost = (node, rootNode) => {\n const isCETrue = node => isContentEditableTrue$1(node.dom);\n const isRoot = node => node.dom === rootNode;\n return ancestor$4(SugarElement.fromDom(node), isCETrue, isRoot).map(elm => elm.dom).getOr(rootNode);\n };\n const getParentBlock$3 = (node, rootNode) => {\n while (node && node !== rootNode) {\n if (isBlockLike(node)) {\n return node;\n }\n node = node.parentNode;\n }\n return null;\n };\n const isInSameBlock = (caretPosition1, caretPosition2, rootNode) => getParentBlock$3(caretPosition1.container(), rootNode) === getParentBlock$3(caretPosition2.container(), rootNode);\n const getChildNodeAtRelativeOffset = (relativeOffset, caretPosition) => {\n if (!caretPosition) {\n return Optional.none();\n }\n const container = caretPosition.container();\n const offset = caretPosition.offset();\n if (!isElement$2(container)) {\n return Optional.none();\n }\n return Optional.from(container.childNodes[offset + relativeOffset]);\n };\n const beforeAfter = (before, node) => {\n var _a;\n const doc = (_a = node.ownerDocument) !== null && _a !== void 0 ? _a : document;\n const range = doc.createRange();\n if (before) {\n range.setStartBefore(node);\n range.setEndBefore(node);\n } else {\n range.setStartAfter(node);\n range.setEndAfter(node);\n }\n return range;\n };\n const isNodesInSameBlock = (root, node1, node2) => getParentBlock$3(node1, root) === getParentBlock$3(node2, root);\n const lean = (left, root, node) => {\n const siblingName = left ? 'previousSibling' : 'nextSibling';\n let tempNode = node;\n while (tempNode && tempNode !== root) {\n let sibling = tempNode[siblingName];\n if (sibling && isCaretContainer(sibling)) {\n sibling = sibling[siblingName];\n }\n if (isContentEditableFalse$7(sibling) || isMedia(sibling)) {\n if (isNodesInSameBlock(root, sibling, tempNode)) {\n return sibling;\n }\n break;\n }\n if (isCaretCandidate$1(sibling)) {\n break;\n }\n tempNode = tempNode.parentNode;\n }\n return null;\n };\n const before$2 = curry(beforeAfter, true);\n const after$2 = curry(beforeAfter, false);\n const normalizeRange = (direction, root, range) => {\n let node;\n const leanLeft = curry(lean, true, root);\n const leanRight = curry(lean, false, root);\n const container = range.startContainer;\n const offset = range.startOffset;\n if (isCaretContainerBlock$1(container)) {\n const block = isText$4(container) ? container.parentNode : container;\n const location = block.getAttribute('data-mce-caret');\n if (location === 'before') {\n node = block.nextSibling;\n if (isFakeCaretTarget(node)) {\n return before$2(node);\n }\n }\n if (location === 'after') {\n node = block.previousSibling;\n if (isFakeCaretTarget(node)) {\n return after$2(node);\n }\n }\n }\n if (!range.collapsed) {\n return range;\n }\n if (isText$b(container)) {\n if (isCaretContainer(container)) {\n if (direction === 1) {\n node = leanRight(container);\n if (node) {\n return before$2(node);\n }\n node = leanLeft(container);\n if (node) {\n return after$2(node);\n }\n }\n if (direction === -1) {\n node = leanLeft(container);\n if (node) {\n return after$2(node);\n }\n node = leanRight(container);\n if (node) {\n return before$2(node);\n }\n }\n return range;\n }\n if (endsWithCaretContainer$1(container) && offset >= container.data.length - 1) {\n if (direction === 1) {\n node = leanRight(container);\n if (node) {\n return before$2(node);\n }\n }\n return range;\n }\n if (startsWithCaretContainer$1(container) && offset <= 1) {\n if (direction === -1) {\n node = leanLeft(container);\n if (node) {\n return after$2(node);\n }\n }\n return range;\n }\n if (offset === container.data.length) {\n node = leanRight(container);\n if (node) {\n return before$2(node);\n }\n return range;\n }\n if (offset === 0) {\n node = leanLeft(container);\n if (node) {\n return after$2(node);\n }\n return range;\n }\n }\n return range;\n };\n const getRelativeCefElm = (forward, caretPosition) => getChildNodeAtRelativeOffset(forward ? 0 : -1, caretPosition).filter(isContentEditableFalse$7);\n const getNormalizedRangeEndPoint = (direction, root, range) => {\n const normalizedRange = normalizeRange(direction, root, range);\n return direction === -1 ? CaretPosition.fromRangeStart(normalizedRange) : CaretPosition.fromRangeEnd(normalizedRange);\n };\n const getElementFromPosition = pos => Optional.from(pos.getNode()).map(SugarElement.fromDom);\n const getElementFromPrevPosition = pos => Optional.from(pos.getNode(true)).map(SugarElement.fromDom);\n const getVisualCaretPosition = (walkFn, caretPosition) => {\n let pos = caretPosition;\n while (pos = walkFn(pos)) {\n if (pos.isVisible()) {\n return pos;\n }\n }\n return pos;\n };\n const isMoveInsideSameBlock = (from, to) => {\n const inSameBlock = isInSameBlock(from, to);\n if (!inSameBlock && isBr$6(from.getNode())) {\n return true;\n }\n return inSameBlock;\n };\n\n var HDirection;\n (function (HDirection) {\n HDirection[HDirection['Backwards'] = -1] = 'Backwards';\n HDirection[HDirection['Forwards'] = 1] = 'Forwards';\n }(HDirection || (HDirection = {})));\n const isContentEditableFalse$6 = isContentEditableFalse$b;\n const isText$3 = isText$b;\n const isElement$1 = isElement$6;\n const isBr$2 = isBr$6;\n const isCaretCandidate = isCaretCandidate$3;\n const isAtomic = isAtomic$1;\n const isEditableCaretCandidate = isEditableCaretCandidate$1;\n const getParents$3 = (node, root) => {\n const parents = [];\n let tempNode = node;\n while (tempNode && tempNode !== root) {\n parents.push(tempNode);\n tempNode = tempNode.parentNode;\n }\n return parents;\n };\n const nodeAtIndex = (container, offset) => {\n if (container.hasChildNodes() && offset < container.childNodes.length) {\n return container.childNodes[offset];\n }\n return null;\n };\n const getCaretCandidatePosition = (direction, node) => {\n if (isForwards(direction)) {\n if (isCaretCandidate(node.previousSibling) && !isText$3(node.previousSibling)) {\n return CaretPosition.before(node);\n }\n if (isText$3(node)) {\n return CaretPosition(node, 0);\n }\n }\n if (isBackwards(direction)) {\n if (isCaretCandidate(node.nextSibling) && !isText$3(node.nextSibling)) {\n return CaretPosition.after(node);\n }\n if (isText$3(node)) {\n return CaretPosition(node, node.data.length);\n }\n }\n if (isBackwards(direction)) {\n if (isBr$2(node)) {\n return CaretPosition.before(node);\n }\n return CaretPosition.after(node);\n }\n return CaretPosition.before(node);\n };\n const moveForwardFromBr = (root, nextNode) => {\n const nextSibling = nextNode.nextSibling;\n if (nextSibling && isCaretCandidate(nextSibling)) {\n if (isText$3(nextSibling)) {\n return CaretPosition(nextSibling, 0);\n } else {\n return CaretPosition.before(nextSibling);\n }\n } else {\n return findCaretPosition$1(HDirection.Forwards, CaretPosition.after(nextNode), root);\n }\n };\n const findCaretPosition$1 = (direction, startPos, root) => {\n let node;\n let nextNode;\n let innerNode;\n let caretPosition;\n if (!isElement$1(root) || !startPos) {\n return null;\n }\n if (startPos.isEqual(CaretPosition.after(root)) && root.lastChild) {\n caretPosition = CaretPosition.after(root.lastChild);\n if (isBackwards(direction) && isCaretCandidate(root.lastChild) && isElement$1(root.lastChild)) {\n return isBr$2(root.lastChild) ? CaretPosition.before(root.lastChild) : caretPosition;\n }\n } else {\n caretPosition = startPos;\n }\n const container = caretPosition.container();\n let offset = caretPosition.offset();\n if (isText$3(container)) {\n if (isBackwards(direction) && offset > 0) {\n return CaretPosition(container, --offset);\n }\n if (isForwards(direction) && offset < container.length) {\n return CaretPosition(container, ++offset);\n }\n node = container;\n } else {\n if (isBackwards(direction) && offset > 0) {\n nextNode = nodeAtIndex(container, offset - 1);\n if (isCaretCandidate(nextNode)) {\n if (!isAtomic(nextNode)) {\n innerNode = findNode(nextNode, direction, isEditableCaretCandidate, nextNode);\n if (innerNode) {\n if (isText$3(innerNode)) {\n return CaretPosition(innerNode, innerNode.data.length);\n }\n return CaretPosition.after(innerNode);\n }\n }\n if (isText$3(nextNode)) {\n return CaretPosition(nextNode, nextNode.data.length);\n }\n return CaretPosition.before(nextNode);\n }\n }\n if (isForwards(direction) && offset < container.childNodes.length) {\n nextNode = nodeAtIndex(container, offset);\n if (isCaretCandidate(nextNode)) {\n if (isBr$2(nextNode)) {\n return moveForwardFromBr(root, nextNode);\n }\n if (!isAtomic(nextNode)) {\n innerNode = findNode(nextNode, direction, isEditableCaretCandidate, nextNode);\n if (innerNode) {\n if (isText$3(innerNode)) {\n return CaretPosition(innerNode, 0);\n }\n return CaretPosition.before(innerNode);\n }\n }\n if (isText$3(nextNode)) {\n return CaretPosition(nextNode, 0);\n }\n return CaretPosition.after(nextNode);\n }\n }\n node = nextNode ? nextNode : caretPosition.getNode();\n }\n if (node && (isForwards(direction) && caretPosition.isAtEnd() || isBackwards(direction) && caretPosition.isAtStart())) {\n node = findNode(node, direction, always, root, true);\n if (isEditableCaretCandidate(node, root)) {\n return getCaretCandidatePosition(direction, node);\n }\n }\n nextNode = node ? findNode(node, direction, isEditableCaretCandidate, root) : node;\n const rootContentEditableFalseElm = last$1(filter$5(getParents$3(container, root), isContentEditableFalse$6));\n if (rootContentEditableFalseElm && (!nextNode || !rootContentEditableFalseElm.contains(nextNode))) {\n if (isForwards(direction)) {\n caretPosition = CaretPosition.after(rootContentEditableFalseElm);\n } else {\n caretPosition = CaretPosition.before(rootContentEditableFalseElm);\n }\n return caretPosition;\n }\n if (nextNode) {\n return getCaretCandidatePosition(direction, nextNode);\n }\n return null;\n };\n const CaretWalker = root => ({\n next: caretPosition => {\n return findCaretPosition$1(HDirection.Forwards, caretPosition, root);\n },\n prev: caretPosition => {\n return findCaretPosition$1(HDirection.Backwards, caretPosition, root);\n }\n });\n\n const walkToPositionIn = (forward, root, start) => {\n const position = forward ? CaretPosition.before(start) : CaretPosition.after(start);\n return fromPosition(forward, root, position);\n };\n const afterElement = node => isBr$6(node) ? CaretPosition.before(node) : CaretPosition.after(node);\n const isBeforeOrStart = position => {\n if (CaretPosition.isTextPosition(position)) {\n return position.offset() === 0;\n } else {\n return isCaretCandidate$3(position.getNode());\n }\n };\n const isAfterOrEnd = position => {\n if (CaretPosition.isTextPosition(position)) {\n const container = position.container();\n return position.offset() === container.data.length;\n } else {\n return isCaretCandidate$3(position.getNode(true));\n }\n };\n const isBeforeAfterSameElement = (from, to) => !CaretPosition.isTextPosition(from) && !CaretPosition.isTextPosition(to) && from.getNode() === to.getNode(true);\n const isAtBr = position => !CaretPosition.isTextPosition(position) && isBr$6(position.getNode());\n const shouldSkipPosition = (forward, from, to) => {\n if (forward) {\n return !isBeforeAfterSameElement(from, to) && !isAtBr(from) && isAfterOrEnd(from) && isBeforeOrStart(to);\n } else {\n return !isBeforeAfterSameElement(to, from) && isBeforeOrStart(from) && isAfterOrEnd(to);\n }\n };\n const fromPosition = (forward, root, pos) => {\n const walker = CaretWalker(root);\n return Optional.from(forward ? walker.next(pos) : walker.prev(pos));\n };\n const navigate = (forward, root, from) => fromPosition(forward, root, from).bind(to => {\n if (isInSameBlock(from, to, root) && shouldSkipPosition(forward, from, to)) {\n return fromPosition(forward, root, to);\n } else {\n return Optional.some(to);\n }\n });\n const navigateIgnore = (forward, root, from, ignoreFilter) => navigate(forward, root, from).bind(pos => ignoreFilter(pos) ? navigateIgnore(forward, root, pos, ignoreFilter) : Optional.some(pos));\n const positionIn = (forward, element) => {\n const startNode = forward ? element.firstChild : element.lastChild;\n if (isText$b(startNode)) {\n return Optional.some(CaretPosition(startNode, forward ? 0 : startNode.data.length));\n } else if (startNode) {\n if (isCaretCandidate$3(startNode)) {\n return Optional.some(forward ? CaretPosition.before(startNode) : afterElement(startNode));\n } else {\n return walkToPositionIn(forward, element, startNode);\n }\n } else {\n return Optional.none();\n }\n };\n const nextPosition = curry(fromPosition, true);\n const prevPosition = curry(fromPosition, false);\n const firstPositionIn = curry(positionIn, true);\n const lastPositionIn = curry(positionIn, false);\n\n const CARET_ID = '_mce_caret';\n const isCaretNode = node => isElement$6(node) && node.id === CARET_ID;\n const getParentCaretContainer = (body, node) => {\n let currentNode = node;\n while (currentNode && currentNode !== body) {\n if (isCaretNode(currentNode)) {\n return currentNode;\n }\n currentNode = currentNode.parentNode;\n }\n return null;\n };\n\n const isStringPathBookmark = bookmark => isString(bookmark.start);\n const isRangeBookmark = bookmark => has$2(bookmark, 'rng');\n const isIdBookmark = bookmark => has$2(bookmark, 'id');\n const isIndexBookmark = bookmark => has$2(bookmark, 'name');\n const isPathBookmark = bookmark => Tools.isArray(bookmark.start);\n\n const isForwardBookmark = bookmark => !isIndexBookmark(bookmark) && isBoolean(bookmark.forward) ? bookmark.forward : true;\n const addBogus = (dom, node) => {\n if (isElement$6(node) && dom.isBlock(node) && !node.innerHTML) {\n node.innerHTML = '
';\n }\n return node;\n };\n const resolveCaretPositionBookmark = (dom, bookmark) => {\n const startPos = Optional.from(resolve$1(dom.getRoot(), bookmark.start));\n const endPos = Optional.from(resolve$1(dom.getRoot(), bookmark.end));\n return lift2(startPos, endPos, (start, end) => {\n const range = dom.createRng();\n range.setStart(start.container(), start.offset());\n range.setEnd(end.container(), end.offset());\n return {\n range,\n forward: isForwardBookmark(bookmark)\n };\n });\n };\n const insertZwsp = (node, rng) => {\n var _a;\n const doc = (_a = node.ownerDocument) !== null && _a !== void 0 ? _a : document;\n const textNode = doc.createTextNode(ZWSP$1);\n node.appendChild(textNode);\n rng.setStart(textNode, 0);\n rng.setEnd(textNode, 0);\n };\n const isEmpty$1 = node => !node.hasChildNodes();\n const tryFindRangePosition = (node, rng) => lastPositionIn(node).fold(never, pos => {\n rng.setStart(pos.container(), pos.offset());\n rng.setEnd(pos.container(), pos.offset());\n return true;\n });\n const padEmptyCaretContainer = (root, node, rng) => {\n if (isEmpty$1(node) && getParentCaretContainer(root, node)) {\n insertZwsp(node, rng);\n return true;\n } else {\n return false;\n }\n };\n const setEndPoint = (dom, start, bookmark, rng) => {\n const point = bookmark[start ? 'start' : 'end'];\n const root = dom.getRoot();\n if (point) {\n let node = root;\n let offset = point[0];\n for (let i = point.length - 1; node && i >= 1; i--) {\n const children = node.childNodes;\n if (padEmptyCaretContainer(root, node, rng)) {\n return true;\n }\n if (point[i] > children.length - 1) {\n if (padEmptyCaretContainer(root, node, rng)) {\n return true;\n }\n return tryFindRangePosition(node, rng);\n }\n node = children[point[i]];\n }\n if (isText$b(node)) {\n offset = Math.min(point[0], node.data.length);\n }\n if (isElement$6(node)) {\n offset = Math.min(point[0], node.childNodes.length);\n }\n if (start) {\n rng.setStart(node, offset);\n } else {\n rng.setEnd(node, offset);\n }\n }\n return true;\n };\n const isValidTextNode = node => isText$b(node) && node.data.length > 0;\n const restoreEndPoint = (dom, suffix, bookmark) => {\n const marker = dom.get(bookmark.id + '_' + suffix);\n const markerParent = marker === null || marker === void 0 ? void 0 : marker.parentNode;\n const keep = bookmark.keep;\n if (marker && markerParent) {\n let container;\n let offset;\n if (suffix === 'start') {\n if (!keep) {\n container = markerParent;\n offset = dom.nodeIndex(marker);\n } else {\n if (marker.hasChildNodes()) {\n container = marker.firstChild;\n offset = 1;\n } else if (isValidTextNode(marker.nextSibling)) {\n container = marker.nextSibling;\n offset = 0;\n } else if (isValidTextNode(marker.previousSibling)) {\n container = marker.previousSibling;\n offset = marker.previousSibling.data.length;\n } else {\n container = markerParent;\n offset = dom.nodeIndex(marker) + 1;\n }\n }\n } else {\n if (!keep) {\n container = markerParent;\n offset = dom.nodeIndex(marker);\n } else {\n if (marker.hasChildNodes()) {\n container = marker.firstChild;\n offset = 1;\n } else if (isValidTextNode(marker.previousSibling)) {\n container = marker.previousSibling;\n offset = marker.previousSibling.data.length;\n } else {\n container = markerParent;\n offset = dom.nodeIndex(marker);\n }\n }\n }\n if (!keep) {\n const prev = marker.previousSibling;\n const next = marker.nextSibling;\n Tools.each(Tools.grep(marker.childNodes), node => {\n if (isText$b(node)) {\n node.data = node.data.replace(/\\uFEFF/g, '');\n }\n });\n let otherMarker;\n while (otherMarker = dom.get(bookmark.id + '_' + suffix)) {\n dom.remove(otherMarker, true);\n }\n if (isText$b(next) && isText$b(prev) && !Env.browser.isOpera()) {\n const idx = prev.data.length;\n prev.appendData(next.data);\n dom.remove(next);\n container = prev;\n offset = idx;\n }\n }\n return Optional.some(CaretPosition(container, offset));\n } else {\n return Optional.none();\n }\n };\n const resolvePaths = (dom, bookmark) => {\n const range = dom.createRng();\n if (setEndPoint(dom, true, bookmark, range) && setEndPoint(dom, false, bookmark, range)) {\n return Optional.some({\n range,\n forward: isForwardBookmark(bookmark)\n });\n } else {\n return Optional.none();\n }\n };\n const resolveId = (dom, bookmark) => {\n const startPos = restoreEndPoint(dom, 'start', bookmark);\n const endPos = restoreEndPoint(dom, 'end', bookmark);\n return lift2(startPos, endPos.or(startPos), (spos, epos) => {\n const range = dom.createRng();\n range.setStart(addBogus(dom, spos.container()), spos.offset());\n range.setEnd(addBogus(dom, epos.container()), epos.offset());\n return {\n range,\n forward: isForwardBookmark(bookmark)\n };\n });\n };\n const resolveIndex = (dom, bookmark) => Optional.from(dom.select(bookmark.name)[bookmark.index]).map(elm => {\n const range = dom.createRng();\n range.selectNode(elm);\n return {\n range,\n forward: true\n };\n });\n const resolve = (selection, bookmark) => {\n const dom = selection.dom;\n if (bookmark) {\n if (isPathBookmark(bookmark)) {\n return resolvePaths(dom, bookmark);\n } else if (isStringPathBookmark(bookmark)) {\n return resolveCaretPositionBookmark(dom, bookmark);\n } else if (isIdBookmark(bookmark)) {\n return resolveId(dom, bookmark);\n } else if (isIndexBookmark(bookmark)) {\n return resolveIndex(dom, bookmark);\n } else if (isRangeBookmark(bookmark)) {\n return Optional.some({\n range: bookmark.rng,\n forward: isForwardBookmark(bookmark)\n });\n }\n }\n return Optional.none();\n };\n\n const getBookmark$2 = (selection, type, normalized) => {\n return getBookmark$3(selection, type, normalized);\n };\n const moveToBookmark = (selection, bookmark) => {\n resolve(selection, bookmark).each(({range, forward}) => {\n selection.setRng(range, forward);\n });\n };\n const isBookmarkNode$1 = node => {\n return isElement$6(node) && node.tagName === 'SPAN' && node.getAttribute('data-mce-type') === 'bookmark';\n };\n\n const is = expected => actual => expected === actual;\n const isNbsp = is(nbsp);\n const isWhiteSpace = chr => chr !== '' && ' \\f\\n\\r\\t\\x0B'.indexOf(chr) !== -1;\n const isContent = chr => !isWhiteSpace(chr) && !isNbsp(chr) && !isZwsp$2(chr);\n\n const getRanges$1 = selection => {\n const ranges = [];\n if (selection) {\n for (let i = 0; i < selection.rangeCount; i++) {\n ranges.push(selection.getRangeAt(i));\n }\n }\n return ranges;\n };\n const getSelectedNodes = ranges => {\n return bind$3(ranges, range => {\n const node = getSelectedNode(range);\n return node ? [SugarElement.fromDom(node)] : [];\n });\n };\n const hasMultipleRanges = selection => {\n return getRanges$1(selection).length > 1;\n };\n\n const getCellsFromRanges = ranges => filter$5(getSelectedNodes(ranges), isTableCell$2);\n const getCellsFromElement = elm => descendants(elm, 'td[data-mce-selected],th[data-mce-selected]');\n const getCellsFromElementOrRanges = (ranges, element) => {\n const selectedCells = getCellsFromElement(element);\n return selectedCells.length > 0 ? selectedCells : getCellsFromRanges(ranges);\n };\n const getCellsFromEditor = editor => getCellsFromElementOrRanges(getRanges$1(editor.selection.getSel()), SugarElement.fromDom(editor.getBody()));\n const getClosestTable = (cell, isRoot) => ancestor$3(cell, 'table', isRoot);\n\n const getStartNode = rng => {\n const sc = rng.startContainer, so = rng.startOffset;\n if (isText$b(sc)) {\n return so === 0 ? Optional.some(SugarElement.fromDom(sc)) : Optional.none();\n } else {\n return Optional.from(sc.childNodes[so]).map(SugarElement.fromDom);\n }\n };\n const getEndNode = rng => {\n const ec = rng.endContainer, eo = rng.endOffset;\n if (isText$b(ec)) {\n return eo === ec.data.length ? Optional.some(SugarElement.fromDom(ec)) : Optional.none();\n } else {\n return Optional.from(ec.childNodes[eo - 1]).map(SugarElement.fromDom);\n }\n };\n const getFirstChildren = node => {\n return firstChild(node).fold(constant([node]), child => {\n return [node].concat(getFirstChildren(child));\n });\n };\n const getLastChildren = node => {\n return lastChild(node).fold(constant([node]), child => {\n if (name(child) === 'br') {\n return prevSibling(child).map(sibling => {\n return [node].concat(getLastChildren(sibling));\n }).getOr([]);\n } else {\n return [node].concat(getLastChildren(child));\n }\n });\n };\n const hasAllContentsSelected = (elm, rng) => {\n return lift2(getStartNode(rng), getEndNode(rng), (startNode, endNode) => {\n const start = find$2(getFirstChildren(elm), curry(eq, startNode));\n const end = find$2(getLastChildren(elm), curry(eq, endNode));\n return start.isSome() && end.isSome();\n }).getOr(false);\n };\n const moveEndPoint = (dom, rng, node, start) => {\n const root = node;\n const walker = new DomTreeWalker(node, root);\n const moveCaretBeforeOnEnterElementsMap = filter$4(dom.schema.getMoveCaretBeforeOnEnterElements(), (_, name) => !contains$2([\n 'td',\n 'th',\n 'table'\n ], name.toLowerCase()));\n let currentNode = node;\n do {\n if (isText$b(currentNode) && Tools.trim(currentNode.data).length !== 0) {\n if (start) {\n rng.setStart(currentNode, 0);\n } else {\n rng.setEnd(currentNode, currentNode.data.length);\n }\n return;\n }\n if (moveCaretBeforeOnEnterElementsMap[currentNode.nodeName]) {\n if (start) {\n rng.setStartBefore(currentNode);\n } else {\n if (currentNode.nodeName === 'BR') {\n rng.setEndBefore(currentNode);\n } else {\n rng.setEndAfter(currentNode);\n }\n }\n return;\n }\n } while (currentNode = start ? walker.next() : walker.prev());\n if (root.nodeName === 'BODY') {\n if (start) {\n rng.setStart(root, 0);\n } else {\n rng.setEnd(root, root.childNodes.length);\n }\n }\n };\n const hasAnyRanges = editor => {\n const sel = editor.selection.getSel();\n return isNonNullable(sel) && sel.rangeCount > 0;\n };\n const runOnRanges = (editor, executor) => {\n const fakeSelectionNodes = getCellsFromEditor(editor);\n if (fakeSelectionNodes.length > 0) {\n each$e(fakeSelectionNodes, elem => {\n const node = elem.dom;\n const fakeNodeRng = editor.dom.createRng();\n fakeNodeRng.setStartBefore(node);\n fakeNodeRng.setEndAfter(node);\n executor(fakeNodeRng, true);\n });\n } else {\n executor(editor.selection.getRng(), false);\n }\n };\n const preserve = (selection, fillBookmark, executor) => {\n const bookmark = getPersistentBookmark(selection, fillBookmark);\n executor(bookmark);\n selection.moveToBookmark(bookmark);\n };\n\n const isNode = node => isNumber(node === null || node === void 0 ? void 0 : node.nodeType);\n const isElementNode$1 = node => isElement$6(node) && !isBookmarkNode$1(node) && !isCaretNode(node) && !isBogus$1(node);\n const isElementDirectlySelected = (dom, node) => {\n if (isElementNode$1(node) && !/^(TD|TH)$/.test(node.nodeName)) {\n const selectedAttr = dom.getAttrib(node, 'data-mce-selected');\n const value = parseInt(selectedAttr, 10);\n return !isNaN(value) && value > 0;\n } else {\n return false;\n }\n };\n const preserveSelection = (editor, action, shouldMoveStart) => {\n const {selection, dom} = editor;\n const selectedNodeBeforeAction = selection.getNode();\n const isSelectedBeforeNodeNoneditable = isContentEditableFalse$b(selectedNodeBeforeAction);\n preserve(selection, true, () => {\n action();\n });\n const isBeforeNodeStillNoneditable = isSelectedBeforeNodeNoneditable && isContentEditableFalse$b(selectedNodeBeforeAction);\n if (isBeforeNodeStillNoneditable && dom.isChildOf(selectedNodeBeforeAction, editor.getBody())) {\n editor.selection.select(selectedNodeBeforeAction);\n } else if (shouldMoveStart(selection.getStart())) {\n moveStartToNearestText(dom, selection);\n }\n };\n const moveStartToNearestText = (dom, selection) => {\n var _a, _b;\n const rng = selection.getRng();\n const {startContainer, startOffset} = rng;\n const selectedNode = selection.getNode();\n if (isElementDirectlySelected(dom, selectedNode)) {\n return;\n }\n if (isElement$6(startContainer)) {\n const nodes = startContainer.childNodes;\n const root = dom.getRoot();\n let walker;\n if (startOffset < nodes.length) {\n const startNode = nodes[startOffset];\n walker = new DomTreeWalker(startNode, (_a = dom.getParent(startNode, dom.isBlock)) !== null && _a !== void 0 ? _a : root);\n } else {\n const startNode = nodes[nodes.length - 1];\n walker = new DomTreeWalker(startNode, (_b = dom.getParent(startNode, dom.isBlock)) !== null && _b !== void 0 ? _b : root);\n walker.next(true);\n }\n for (let node = walker.current(); node; node = walker.next()) {\n if (dom.getContentEditable(node) === 'false') {\n return;\n } else if (isText$b(node) && !isWhiteSpaceNode$1(node)) {\n rng.setStart(node, 0);\n selection.setRng(rng);\n return;\n }\n }\n }\n };\n const getNonWhiteSpaceSibling = (node, next, inc) => {\n if (node) {\n const nextName = next ? 'nextSibling' : 'previousSibling';\n for (node = inc ? node : node[nextName]; node; node = node[nextName]) {\n if (isElement$6(node) || !isWhiteSpaceNode$1(node)) {\n return node;\n }\n }\n }\n return undefined;\n };\n const isTextBlock$1 = (schema, node) => !!schema.getTextBlockElements()[node.nodeName.toLowerCase()] || isTransparentBlock(schema, node);\n const isValid = (ed, parent, child) => {\n return ed.schema.isValidChild(parent, child);\n };\n const isWhiteSpaceNode$1 = (node, allowSpaces = false) => {\n if (isNonNullable(node) && isText$b(node)) {\n const data = allowSpaces ? node.data.replace(/ /g, '\\xA0') : node.data;\n return isWhitespaceText(data);\n } else {\n return false;\n }\n };\n const isEmptyTextNode$1 = node => {\n return isNonNullable(node) && isText$b(node) && node.length === 0;\n };\n const isWrapNoneditableTarget = (editor, node) => {\n const baseDataSelector = '[data-mce-cef-wrappable]';\n const formatNoneditableSelector = getFormatNoneditableSelector(editor);\n const selector = isEmpty$3(formatNoneditableSelector) ? baseDataSelector : `${ baseDataSelector },${ formatNoneditableSelector }`;\n return is$1(SugarElement.fromDom(node), selector);\n };\n const isWrappableNoneditable = (editor, node) => {\n const dom = editor.dom;\n return isElementNode$1(node) && dom.getContentEditable(node) === 'false' && isWrapNoneditableTarget(editor, node) && dom.select('[contenteditable=\"true\"]', node).length === 0;\n };\n const replaceVars = (value, vars) => {\n if (isFunction(value)) {\n return value(vars);\n } else if (isNonNullable(vars)) {\n value = value.replace(/%(\\w+)/g, (str, name) => {\n return vars[name] || str;\n });\n }\n return value;\n };\n const isEq$5 = (str1, str2) => {\n str1 = str1 || '';\n str2 = str2 || '';\n str1 = '' + (str1.nodeName || str1);\n str2 = '' + (str2.nodeName || str2);\n return str1.toLowerCase() === str2.toLowerCase();\n };\n const normalizeStyleValue = (value, name) => {\n if (isNullable(value)) {\n return null;\n } else {\n let strValue = String(value);\n if (name === 'color' || name === 'backgroundColor') {\n strValue = rgbaToHexString(strValue);\n }\n if (name === 'fontWeight' && value === 700) {\n strValue = 'bold';\n }\n if (name === 'fontFamily') {\n strValue = strValue.replace(/[\\'\\\"]/g, '').replace(/,\\s+/g, ',');\n }\n return strValue;\n }\n };\n const getStyle = (dom, node, name) => {\n const style = dom.getStyle(node, name);\n return normalizeStyleValue(style, name);\n };\n const getTextDecoration = (dom, node) => {\n let decoration;\n dom.getParent(node, n => {\n if (isElement$6(n)) {\n decoration = dom.getStyle(n, 'text-decoration');\n return !!decoration && decoration !== 'none';\n } else {\n return false;\n }\n });\n return decoration;\n };\n const getParents$2 = (dom, node, selector) => {\n return dom.getParents(node, selector, dom.getRoot());\n };\n const isFormatPredicate = (editor, formatName, predicate) => {\n const formats = editor.formatter.get(formatName);\n return isNonNullable(formats) && exists(formats, predicate);\n };\n const isVariableFormatName = (editor, formatName) => {\n const hasVariableValues = format => {\n const isVariableValue = val => isFunction(val) || val.length > 1 && val.charAt(0) === '%';\n return exists([\n 'styles',\n 'attributes'\n ], key => get$a(format, key).exists(field => {\n const fieldValues = isArray$1(field) ? field : values(field);\n return exists(fieldValues, isVariableValue);\n }));\n };\n return isFormatPredicate(editor, formatName, hasVariableValues);\n };\n const areSimilarFormats = (editor, formatName, otherFormatName) => {\n const validKeys = [\n 'inline',\n 'block',\n 'selector',\n 'attributes',\n 'styles',\n 'classes'\n ];\n const filterObj = format => filter$4(format, (_, key) => exists(validKeys, validKey => validKey === key));\n return isFormatPredicate(editor, formatName, fmt1 => {\n const filteredFmt1 = filterObj(fmt1);\n return isFormatPredicate(editor, otherFormatName, fmt2 => {\n const filteredFmt2 = filterObj(fmt2);\n return equal$1(filteredFmt1, filteredFmt2);\n });\n });\n };\n const isBlockFormat = format => hasNonNullableKey(format, 'block');\n const isWrappingBlockFormat = format => isBlockFormat(format) && format.wrapper === true;\n const isNonWrappingBlockFormat = format => isBlockFormat(format) && format.wrapper !== true;\n const isSelectorFormat = format => hasNonNullableKey(format, 'selector');\n const isInlineFormat = format => hasNonNullableKey(format, 'inline');\n const isMixedFormat = format => isSelectorFormat(format) && isInlineFormat(format) && is$2(get$a(format, 'mixed'), true);\n const shouldExpandToSelector = format => isSelectorFormat(format) && format.expand !== false && !isInlineFormat(format);\n const getEmptyCaretContainers = node => {\n const nodes = [];\n let tempNode = node;\n while (tempNode) {\n if (isText$b(tempNode) && tempNode.data !== ZWSP$1 || tempNode.childNodes.length > 1) {\n return [];\n }\n if (isElement$6(tempNode)) {\n nodes.push(tempNode);\n }\n tempNode = tempNode.firstChild;\n }\n return nodes;\n };\n const isCaretContainerEmpty = node => {\n return getEmptyCaretContainers(node).length > 0;\n };\n const isEmptyCaretFormatElement = element => {\n return isCaretNode(element.dom) && isCaretContainerEmpty(element.dom);\n };\n\n const isBookmarkNode = isBookmarkNode$1;\n const getParents$1 = getParents$2;\n const isWhiteSpaceNode = isWhiteSpaceNode$1;\n const isTextBlock = isTextBlock$1;\n const isBogusBr = node => {\n return isBr$6(node) && node.getAttribute('data-mce-bogus') && !node.nextSibling;\n };\n const findParentContentEditable = (dom, node) => {\n let parent = node;\n while (parent) {\n if (isElement$6(parent) && dom.getContentEditable(parent)) {\n return dom.getContentEditable(parent) === 'false' ? parent : node;\n }\n parent = parent.parentNode;\n }\n return node;\n };\n const walkText = (start, node, offset, predicate) => {\n const str = node.data;\n if (start) {\n for (let i = offset; i > 0; i--) {\n if (predicate(str.charAt(i - 1))) {\n return i;\n }\n }\n } else {\n for (let i = offset; i < str.length; i++) {\n if (predicate(str.charAt(i))) {\n return i;\n }\n }\n }\n return -1;\n };\n const findSpace = (start, node, offset) => walkText(start, node, offset, c => isNbsp(c) || isWhiteSpace(c));\n const findContent = (start, node, offset) => walkText(start, node, offset, isContent);\n const findWordEndPoint = (dom, body, container, offset, start, includeTrailingSpaces) => {\n let lastTextNode;\n const rootNode = dom.getParent(container, dom.isBlock) || body;\n const walk = (container, offset, pred) => {\n const textSeeker = TextSeeker(dom);\n const walker = start ? textSeeker.backwards : textSeeker.forwards;\n return Optional.from(walker(container, offset, (text, textOffset) => {\n if (isBookmarkNode(text.parentNode)) {\n return -1;\n } else {\n lastTextNode = text;\n return pred(start, text, textOffset);\n }\n }, rootNode));\n };\n const spaceResult = walk(container, offset, findSpace);\n return spaceResult.bind(result => includeTrailingSpaces ? walk(result.container, result.offset + (start ? -1 : 0), findContent) : Optional.some(result)).orThunk(() => lastTextNode ? Optional.some({\n container: lastTextNode,\n offset: start ? 0 : lastTextNode.length\n }) : Optional.none());\n };\n const findSelectorEndPoint = (dom, formatList, rng, container, siblingName) => {\n const sibling = container[siblingName];\n if (isText$b(container) && isEmpty$3(container.data) && sibling) {\n container = sibling;\n }\n const parents = getParents$1(dom, container);\n for (let i = 0; i < parents.length; i++) {\n for (let y = 0; y < formatList.length; y++) {\n const curFormat = formatList[y];\n if (isNonNullable(curFormat.collapsed) && curFormat.collapsed !== rng.collapsed) {\n continue;\n }\n if (isSelectorFormat(curFormat) && dom.is(parents[i], curFormat.selector)) {\n return parents[i];\n }\n }\n }\n return container;\n };\n const findBlockEndPoint = (dom, formatList, container, siblingName) => {\n var _a;\n let node = container;\n const root = dom.getRoot();\n const format = formatList[0];\n if (isBlockFormat(format)) {\n node = format.wrapper ? null : dom.getParent(container, format.block, root);\n }\n if (!node) {\n const scopeRoot = (_a = dom.getParent(container, 'LI,TD,TH,SUMMARY')) !== null && _a !== void 0 ? _a : root;\n node = dom.getParent(isText$b(container) ? container.parentNode : container, node => node !== root && isTextBlock(dom.schema, node), scopeRoot);\n }\n if (node && isBlockFormat(format) && format.wrapper) {\n node = getParents$1(dom, node, 'ul,ol').reverse()[0] || node;\n }\n if (!node) {\n node = container;\n while (node && node[siblingName] && !dom.isBlock(node[siblingName])) {\n node = node[siblingName];\n if (isEq$5(node, 'br')) {\n break;\n }\n }\n }\n return node || container;\n };\n const isAtBlockBoundary$1 = (dom, root, container, siblingName) => {\n const parent = container.parentNode;\n if (isNonNullable(container[siblingName])) {\n return false;\n } else if (parent === root || isNullable(parent) || dom.isBlock(parent)) {\n return true;\n } else {\n return isAtBlockBoundary$1(dom, root, parent, siblingName);\n }\n };\n const findParentContainer = (dom, formatList, container, offset, start) => {\n let parent = container;\n const siblingName = start ? 'previousSibling' : 'nextSibling';\n const root = dom.getRoot();\n if (isText$b(container) && !isWhiteSpaceNode(container)) {\n if (start ? offset > 0 : offset < container.data.length) {\n return container;\n }\n }\n while (parent) {\n if (!formatList[0].block_expand && dom.isBlock(parent)) {\n return parent;\n }\n for (let sibling = parent[siblingName]; sibling; sibling = sibling[siblingName]) {\n const allowSpaces = isText$b(sibling) && !isAtBlockBoundary$1(dom, root, sibling, siblingName);\n if (!isBookmarkNode(sibling) && !isBogusBr(sibling) && !isWhiteSpaceNode(sibling, allowSpaces)) {\n return parent;\n }\n }\n if (parent === root || parent.parentNode === root) {\n container = parent;\n break;\n }\n parent = parent.parentNode;\n }\n return container;\n };\n const isSelfOrParentBookmark = container => isBookmarkNode(container.parentNode) || isBookmarkNode(container);\n const expandRng = (dom, rng, formatList, includeTrailingSpace = false) => {\n let {startContainer, startOffset, endContainer, endOffset} = rng;\n const format = formatList[0];\n if (isElement$6(startContainer) && startContainer.hasChildNodes()) {\n startContainer = getNode$1(startContainer, startOffset);\n if (isText$b(startContainer)) {\n startOffset = 0;\n }\n }\n if (isElement$6(endContainer) && endContainer.hasChildNodes()) {\n endContainer = getNode$1(endContainer, rng.collapsed ? endOffset : endOffset - 1);\n if (isText$b(endContainer)) {\n endOffset = endContainer.data.length;\n }\n }\n startContainer = findParentContentEditable(dom, startContainer);\n endContainer = findParentContentEditable(dom, endContainer);\n if (isSelfOrParentBookmark(startContainer)) {\n startContainer = isBookmarkNode(startContainer) ? startContainer : startContainer.parentNode;\n if (rng.collapsed) {\n startContainer = startContainer.previousSibling || startContainer;\n } else {\n startContainer = startContainer.nextSibling || startContainer;\n }\n if (isText$b(startContainer)) {\n startOffset = rng.collapsed ? startContainer.length : 0;\n }\n }\n if (isSelfOrParentBookmark(endContainer)) {\n endContainer = isBookmarkNode(endContainer) ? endContainer : endContainer.parentNode;\n if (rng.collapsed) {\n endContainer = endContainer.nextSibling || endContainer;\n } else {\n endContainer = endContainer.previousSibling || endContainer;\n }\n if (isText$b(endContainer)) {\n endOffset = rng.collapsed ? 0 : endContainer.length;\n }\n }\n if (rng.collapsed) {\n const startPoint = findWordEndPoint(dom, dom.getRoot(), startContainer, startOffset, true, includeTrailingSpace);\n startPoint.each(({container, offset}) => {\n startContainer = container;\n startOffset = offset;\n });\n const endPoint = findWordEndPoint(dom, dom.getRoot(), endContainer, endOffset, false, includeTrailingSpace);\n endPoint.each(({container, offset}) => {\n endContainer = container;\n endOffset = offset;\n });\n }\n if (isInlineFormat(format) || format.block_expand) {\n if (!isInlineFormat(format) || (!isText$b(startContainer) || startOffset === 0)) {\n startContainer = findParentContainer(dom, formatList, startContainer, startOffset, true);\n }\n if (!isInlineFormat(format) || (!isText$b(endContainer) || endOffset === endContainer.data.length)) {\n endContainer = findParentContainer(dom, formatList, endContainer, endOffset, false);\n }\n }\n if (shouldExpandToSelector(format)) {\n startContainer = findSelectorEndPoint(dom, formatList, rng, startContainer, 'previousSibling');\n endContainer = findSelectorEndPoint(dom, formatList, rng, endContainer, 'nextSibling');\n }\n if (isBlockFormat(format) || isSelectorFormat(format)) {\n startContainer = findBlockEndPoint(dom, formatList, startContainer, 'previousSibling');\n endContainer = findBlockEndPoint(dom, formatList, endContainer, 'nextSibling');\n if (isBlockFormat(format)) {\n if (!dom.isBlock(startContainer)) {\n startContainer = findParentContainer(dom, formatList, startContainer, startOffset, true);\n if (isText$b(startContainer)) {\n startOffset = 0;\n }\n }\n if (!dom.isBlock(endContainer)) {\n endContainer = findParentContainer(dom, formatList, endContainer, endOffset, false);\n if (isText$b(endContainer)) {\n endOffset = endContainer.data.length;\n }\n }\n }\n }\n if (isElement$6(startContainer) && startContainer.parentNode) {\n startOffset = dom.nodeIndex(startContainer);\n startContainer = startContainer.parentNode;\n }\n if (isElement$6(endContainer) && endContainer.parentNode) {\n endOffset = dom.nodeIndex(endContainer) + 1;\n endContainer = endContainer.parentNode;\n }\n return {\n startContainer,\n startOffset,\n endContainer,\n endOffset\n };\n };\n\n const walk$3 = (dom, rng, callback) => {\n var _a;\n const startOffset = rng.startOffset;\n const startContainer = getNode$1(rng.startContainer, startOffset);\n const endOffset = rng.endOffset;\n const endContainer = getNode$1(rng.endContainer, endOffset - 1);\n const exclude = nodes => {\n const firstNode = nodes[0];\n if (isText$b(firstNode) && firstNode === startContainer && startOffset >= firstNode.data.length) {\n nodes.splice(0, 1);\n }\n const lastNode = nodes[nodes.length - 1];\n if (endOffset === 0 && nodes.length > 0 && lastNode === endContainer && isText$b(lastNode)) {\n nodes.splice(nodes.length - 1, 1);\n }\n return nodes;\n };\n const collectSiblings = (node, name, endNode) => {\n const siblings = [];\n for (; node && node !== endNode; node = node[name]) {\n siblings.push(node);\n }\n return siblings;\n };\n const findEndPoint = (node, root) => dom.getParent(node, node => node.parentNode === root, root);\n const walkBoundary = (startNode, endNode, next) => {\n const siblingName = next ? 'nextSibling' : 'previousSibling';\n for (let node = startNode, parent = node.parentNode; node && node !== endNode; node = parent) {\n parent = node.parentNode;\n const siblings = collectSiblings(node === startNode ? node : node[siblingName], siblingName);\n if (siblings.length) {\n if (!next) {\n siblings.reverse();\n }\n callback(exclude(siblings));\n }\n }\n };\n if (startContainer === endContainer) {\n return callback(exclude([startContainer]));\n }\n const ancestor = (_a = dom.findCommonAncestor(startContainer, endContainer)) !== null && _a !== void 0 ? _a : dom.getRoot();\n if (dom.isChildOf(startContainer, endContainer)) {\n return walkBoundary(startContainer, ancestor, true);\n }\n if (dom.isChildOf(endContainer, startContainer)) {\n return walkBoundary(endContainer, ancestor);\n }\n const startPoint = findEndPoint(startContainer, ancestor) || startContainer;\n const endPoint = findEndPoint(endContainer, ancestor) || endContainer;\n walkBoundary(startContainer, startPoint, true);\n const siblings = collectSiblings(startPoint === startContainer ? startPoint : startPoint.nextSibling, 'nextSibling', endPoint === endContainer ? endPoint.nextSibling : endPoint);\n if (siblings.length) {\n callback(exclude(siblings));\n }\n walkBoundary(endContainer, endPoint);\n };\n\n const validBlocks = [\n 'pre[class*=language-][contenteditable=\"false\"]',\n 'figure.image',\n 'div[data-ephox-embed-iri]',\n 'div.tiny-pageembed',\n 'div.mce-toc',\n 'div[data-mce-toc]'\n ];\n const isZeroWidth = elem => isText$c(elem) && get$3(elem) === ZWSP$1;\n const context = (editor, elem, wrapName, nodeName) => parent(elem).fold(() => 'skipping', parent => {\n if (nodeName === 'br' || isZeroWidth(elem)) {\n return 'valid';\n } else if (isAnnotation(elem)) {\n return 'existing';\n } else if (isCaretNode(elem.dom)) {\n return 'caret';\n } else if (exists(validBlocks, selector => is$1(elem, selector))) {\n return 'valid-block';\n } else if (!isValid(editor, wrapName, nodeName) || !isValid(editor, name(parent), wrapName)) {\n return 'invalid-child';\n } else {\n return 'valid';\n }\n });\n\n const applyWordGrab = (editor, rng) => {\n const r = expandRng(editor.dom, rng, [{ inline: 'span' }]);\n rng.setStart(r.startContainer, r.startOffset);\n rng.setEnd(r.endContainer, r.endOffset);\n editor.selection.setRng(rng);\n };\n const applyAnnotation = (elem, masterUId, data, annotationName, decorate, directAnnotation) => {\n const {uid = masterUId, ...otherData} = data;\n add$2(elem, annotation());\n set$4(elem, `${ dataAnnotationId() }`, uid);\n set$4(elem, `${ dataAnnotation() }`, annotationName);\n const {attributes = {}, classes = []} = decorate(uid, otherData);\n setAll$1(elem, attributes);\n add(elem, classes);\n if (directAnnotation) {\n if (classes.length > 0) {\n set$4(elem, `${ dataAnnotationClasses() }`, classes.join(','));\n }\n const attributeNames = keys(attributes);\n if (attributeNames.length > 0) {\n set$4(elem, `${ dataAnnotationAttributes() }`, attributeNames.join(','));\n }\n }\n };\n const removeDirectAnnotation = elem => {\n remove$6(elem, annotation());\n remove$9(elem, `${ dataAnnotationId() }`);\n remove$9(elem, `${ dataAnnotation() }`);\n remove$9(elem, `${ dataAnnotationActive() }`);\n const customAttrNames = getOpt(elem, `${ dataAnnotationAttributes() }`).map(names => names.split(',')).getOr([]);\n const customClasses = getOpt(elem, `${ dataAnnotationClasses() }`).map(names => names.split(',')).getOr([]);\n each$e(customAttrNames, name => remove$9(elem, name));\n remove$3(elem, customClasses);\n remove$9(elem, `${ dataAnnotationClasses() }`);\n remove$9(elem, `${ dataAnnotationAttributes() }`);\n };\n const makeAnnotation = (eDoc, uid, data, annotationName, decorate) => {\n const master = SugarElement.fromTag('span', eDoc);\n applyAnnotation(master, uid, data, annotationName, decorate, false);\n return master;\n };\n const annotate = (editor, rng, uid, annotationName, decorate, data) => {\n const newWrappers = [];\n const master = makeAnnotation(editor.getDoc(), uid, data, annotationName, decorate);\n const wrapper = value$2();\n const finishWrapper = () => {\n wrapper.clear();\n };\n const getOrOpenWrapper = () => wrapper.get().getOrThunk(() => {\n const nu = shallow$1(master);\n newWrappers.push(nu);\n wrapper.set(nu);\n return nu;\n });\n const processElements = elems => {\n each$e(elems, processElement);\n };\n const processElement = elem => {\n const ctx = context(editor, elem, 'span', name(elem));\n switch (ctx) {\n case 'invalid-child': {\n finishWrapper();\n const children = children$1(elem);\n processElements(children);\n finishWrapper();\n break;\n }\n case 'valid-block': {\n finishWrapper();\n applyAnnotation(elem, uid, data, annotationName, decorate, true);\n break;\n }\n case 'valid': {\n const w = getOrOpenWrapper();\n wrap$2(elem, w);\n break;\n }\n }\n };\n const processNodes = nodes => {\n const elems = map$3(nodes, SugarElement.fromDom);\n processElements(elems);\n };\n walk$3(editor.dom, rng, nodes => {\n finishWrapper();\n processNodes(nodes);\n });\n return newWrappers;\n };\n const annotateWithBookmark = (editor, name, settings, data) => {\n editor.undoManager.transact(() => {\n const selection = editor.selection;\n const initialRng = selection.getRng();\n const hasFakeSelection = getCellsFromEditor(editor).length > 0;\n const masterUid = generate$1('mce-annotation');\n if (initialRng.collapsed && !hasFakeSelection) {\n applyWordGrab(editor, initialRng);\n }\n if (selection.getRng().collapsed && !hasFakeSelection) {\n const wrapper = makeAnnotation(editor.getDoc(), masterUid, data, name, settings.decorate);\n set$1(wrapper, nbsp);\n selection.getRng().insertNode(wrapper.dom);\n selection.select(wrapper.dom);\n } else {\n preserve(selection, false, () => {\n runOnRanges(editor, selectionRng => {\n annotate(editor, selectionRng, masterUid, name, settings.decorate, data);\n });\n });\n }\n });\n };\n\n const Annotator = editor => {\n const registry = create$b();\n setup$x(editor, registry);\n const changes = setup$y(editor, registry);\n const isSpan = isTag('span');\n const removeAnnotations = elements => {\n each$e(elements, element => {\n if (isSpan(element)) {\n unwrap(element);\n } else {\n removeDirectAnnotation(element);\n }\n });\n };\n return {\n register: (name, settings) => {\n registry.register(name, settings);\n },\n annotate: (name, data) => {\n registry.lookup(name).each(settings => {\n annotateWithBookmark(editor, name, settings, data);\n });\n },\n annotationChanged: (name, callback) => {\n changes.addListener(name, callback);\n },\n remove: name => {\n identify(editor, Optional.some(name)).each(({elements}) => {\n const bookmark = editor.selection.getBookmark();\n removeAnnotations(elements);\n editor.selection.moveToBookmark(bookmark);\n });\n },\n removeAll: name => {\n const bookmark = editor.selection.getBookmark();\n each$d(findAll(editor, name), (elements, _) => {\n removeAnnotations(elements);\n });\n editor.selection.moveToBookmark(bookmark);\n },\n getAll: name => {\n const directory = findAll(editor, name);\n return map$2(directory, elems => map$3(elems, elem => elem.dom));\n }\n };\n };\n\n const BookmarkManager = selection => {\n return {\n getBookmark: curry(getBookmark$2, selection),\n moveToBookmark: curry(moveToBookmark, selection)\n };\n };\n BookmarkManager.isBookmarkNode = isBookmarkNode$1;\n\n const isXYWithinRange = (clientX, clientY, range) => {\n if (range.collapsed) {\n return false;\n } else {\n return exists(range.getClientRects(), rect => containsXY(rect, clientX, clientY));\n }\n };\n\n const getDocument = () => SugarElement.fromDom(document);\n\n const focus$1 = (element, preventScroll = false) => element.dom.focus({ preventScroll });\n const hasFocus$1 = element => {\n const root = getRootNode(element).dom;\n return element.dom === root.activeElement;\n };\n const active$1 = (root = getDocument()) => Optional.from(root.dom.activeElement).map(SugarElement.fromDom);\n const search = element => active$1(getRootNode(element)).filter(e => element.dom.contains(e.dom));\n\n const create$9 = (start, soffset, finish, foffset) => ({\n start,\n soffset,\n finish,\n foffset\n });\n const SimRange = { create: create$9 };\n\n const adt$3 = Adt.generate([\n { before: ['element'] },\n {\n on: [\n 'element',\n 'offset'\n ]\n },\n { after: ['element'] }\n ]);\n const cata = (subject, onBefore, onOn, onAfter) => subject.fold(onBefore, onOn, onAfter);\n const getStart$2 = situ => situ.fold(identity, identity, identity);\n const before$1 = adt$3.before;\n const on = adt$3.on;\n const after$1 = adt$3.after;\n const Situ = {\n before: before$1,\n on,\n after: after$1,\n cata,\n getStart: getStart$2\n };\n\n const adt$2 = Adt.generate([\n { domRange: ['rng'] },\n {\n relative: [\n 'startSitu',\n 'finishSitu'\n ]\n },\n {\n exact: [\n 'start',\n 'soffset',\n 'finish',\n 'foffset'\n ]\n }\n ]);\n const exactFromRange = simRange => adt$2.exact(simRange.start, simRange.soffset, simRange.finish, simRange.foffset);\n const getStart$1 = selection => selection.match({\n domRange: rng => SugarElement.fromDom(rng.startContainer),\n relative: (startSitu, _finishSitu) => Situ.getStart(startSitu),\n exact: (start, _soffset, _finish, _foffset) => start\n });\n const domRange = adt$2.domRange;\n const relative = adt$2.relative;\n const exact = adt$2.exact;\n const getWin = selection => {\n const start = getStart$1(selection);\n return defaultView(start);\n };\n const range = SimRange.create;\n const SimSelection = {\n domRange,\n relative,\n exact,\n exactFromRange,\n getWin,\n range\n };\n\n const clamp$1 = (offset, element) => {\n const max = isText$c(element) ? get$3(element).length : children$1(element).length + 1;\n if (offset > max) {\n return max;\n } else if (offset < 0) {\n return 0;\n }\n return offset;\n };\n const normalizeRng = rng => SimSelection.range(rng.start, clamp$1(rng.soffset, rng.start), rng.finish, clamp$1(rng.foffset, rng.finish));\n const isOrContains = (root, elm) => !isRestrictedNode(elm.dom) && (contains(root, elm) || eq(root, elm));\n const isRngInRoot = root => rng => isOrContains(root, rng.start) && isOrContains(root, rng.finish);\n const shouldStore = editor => editor.inline || Env.browser.isFirefox();\n const nativeRangeToSelectionRange = r => SimSelection.range(SugarElement.fromDom(r.startContainer), r.startOffset, SugarElement.fromDom(r.endContainer), r.endOffset);\n const readRange = win => {\n const selection = win.getSelection();\n const rng = !selection || selection.rangeCount === 0 ? Optional.none() : Optional.from(selection.getRangeAt(0));\n return rng.map(nativeRangeToSelectionRange);\n };\n const getBookmark$1 = root => {\n const win = defaultView(root);\n return readRange(win.dom).filter(isRngInRoot(root));\n };\n const validate = (root, bookmark) => Optional.from(bookmark).filter(isRngInRoot(root)).map(normalizeRng);\n const bookmarkToNativeRng = bookmark => {\n const rng = document.createRange();\n try {\n rng.setStart(bookmark.start.dom, bookmark.soffset);\n rng.setEnd(bookmark.finish.dom, bookmark.foffset);\n return Optional.some(rng);\n } catch (_) {\n return Optional.none();\n }\n };\n const store = editor => {\n const newBookmark = shouldStore(editor) ? getBookmark$1(SugarElement.fromDom(editor.getBody())) : Optional.none();\n editor.bookmark = newBookmark.isSome() ? newBookmark : editor.bookmark;\n };\n const getRng = editor => {\n const bookmark = editor.bookmark ? editor.bookmark : Optional.none();\n return bookmark.bind(x => validate(SugarElement.fromDom(editor.getBody()), x)).bind(bookmarkToNativeRng);\n };\n const restore = editor => {\n getRng(editor).each(rng => editor.selection.setRng(rng));\n };\n\n const isEditorUIElement$1 = elm => {\n const className = elm.className.toString();\n return className.indexOf('tox-') !== -1 || className.indexOf('mce-') !== -1;\n };\n const FocusManager = { isEditorUIElement: isEditorUIElement$1 };\n\n const wrappedSetTimeout = (callback, time) => {\n if (!isNumber(time)) {\n time = 0;\n }\n return setTimeout(callback, time);\n };\n const wrappedSetInterval = (callback, time) => {\n if (!isNumber(time)) {\n time = 0;\n }\n return setInterval(callback, time);\n };\n const Delay = {\n setEditorTimeout: (editor, callback, time) => {\n return wrappedSetTimeout(() => {\n if (!editor.removed) {\n callback();\n }\n }, time);\n },\n setEditorInterval: (editor, callback, time) => {\n const timer = wrappedSetInterval(() => {\n if (!editor.removed) {\n callback();\n } else {\n clearInterval(timer);\n }\n }, time);\n return timer;\n }\n };\n\n const isManualNodeChange = e => {\n return e.type === 'nodechange' && e.selectionChange;\n };\n const registerPageMouseUp = (editor, throttledStore) => {\n const mouseUpPage = () => {\n throttledStore.throttle();\n };\n DOMUtils.DOM.bind(document, 'mouseup', mouseUpPage);\n editor.on('remove', () => {\n DOMUtils.DOM.unbind(document, 'mouseup', mouseUpPage);\n });\n };\n const registerMouseUp = (editor, throttledStore) => {\n editor.on('mouseup touchend', _e => {\n throttledStore.throttle();\n });\n };\n const registerEditorEvents = (editor, throttledStore) => {\n registerMouseUp(editor, throttledStore);\n editor.on('keyup NodeChange AfterSetSelectionRange', e => {\n if (!isManualNodeChange(e)) {\n store(editor);\n }\n });\n };\n const register$6 = editor => {\n const throttledStore = first$1(() => {\n store(editor);\n }, 0);\n editor.on('init', () => {\n if (editor.inline) {\n registerPageMouseUp(editor, throttledStore);\n }\n registerEditorEvents(editor, throttledStore);\n });\n editor.on('remove', () => {\n throttledStore.cancel();\n });\n };\n\n let documentFocusInHandler;\n const DOM$9 = DOMUtils.DOM;\n const isEditorUIElement = elm => {\n return isElement$6(elm) && FocusManager.isEditorUIElement(elm);\n };\n const isEditorContentAreaElement = elm => {\n const classList = elm.classList;\n if (classList !== undefined) {\n return classList.contains('tox-edit-area') || classList.contains('tox-edit-area__iframe') || classList.contains('mce-content-body');\n } else {\n return false;\n }\n };\n const isUIElement = (editor, elm) => {\n const customSelector = getCustomUiSelector(editor);\n const parent = DOM$9.getParent(elm, elm => {\n return isEditorUIElement(elm) || (customSelector ? editor.dom.is(elm, customSelector) : false);\n });\n return parent !== null;\n };\n const getActiveElement = editor => {\n try {\n const root = getRootNode(SugarElement.fromDom(editor.getElement()));\n return active$1(root).fold(() => document.body, x => x.dom);\n } catch (ex) {\n return document.body;\n }\n };\n const registerEvents$1 = (editorManager, e) => {\n const editor = e.editor;\n register$6(editor);\n const toggleContentAreaOnFocus = (editor, fn) => {\n if (shouldHighlightOnFocus(editor) && editor.inline !== true) {\n const contentArea = SugarElement.fromDom(editor.getContainer());\n fn(contentArea, 'tox-edit-focus');\n }\n };\n editor.on('focusin', () => {\n const focusedEditor = editorManager.focusedEditor;\n if (isEditorContentAreaElement(getActiveElement(editor))) {\n toggleContentAreaOnFocus(editor, add$2);\n }\n if (focusedEditor !== editor) {\n if (focusedEditor) {\n focusedEditor.dispatch('blur', { focusedEditor: editor });\n }\n editorManager.setActive(editor);\n editorManager.focusedEditor = editor;\n editor.dispatch('focus', { blurredEditor: focusedEditor });\n editor.focus(true);\n }\n });\n editor.on('focusout', () => {\n Delay.setEditorTimeout(editor, () => {\n const focusedEditor = editorManager.focusedEditor;\n if (!isEditorContentAreaElement(getActiveElement(editor)) || focusedEditor !== editor) {\n toggleContentAreaOnFocus(editor, remove$6);\n }\n if (!isUIElement(editor, getActiveElement(editor)) && focusedEditor === editor) {\n editor.dispatch('blur', { focusedEditor: null });\n editorManager.focusedEditor = null;\n }\n });\n });\n if (!documentFocusInHandler) {\n documentFocusInHandler = e => {\n const activeEditor = editorManager.activeEditor;\n if (activeEditor) {\n getOriginalEventTarget(e).each(target => {\n const elem = target;\n if (elem.ownerDocument === document) {\n if (elem !== document.body && !isUIElement(activeEditor, elem) && editorManager.focusedEditor === activeEditor) {\n activeEditor.dispatch('blur', { focusedEditor: null });\n editorManager.focusedEditor = null;\n }\n }\n });\n }\n };\n DOM$9.bind(document, 'focusin', documentFocusInHandler);\n }\n };\n const unregisterDocumentEvents = (editorManager, e) => {\n if (editorManager.focusedEditor === e.editor) {\n editorManager.focusedEditor = null;\n }\n if (!editorManager.activeEditor && documentFocusInHandler) {\n DOM$9.unbind(document, 'focusin', documentFocusInHandler);\n documentFocusInHandler = null;\n }\n };\n const setup$w = editorManager => {\n editorManager.on('AddEditor', curry(registerEvents$1, editorManager));\n editorManager.on('RemoveEditor', curry(unregisterDocumentEvents, editorManager));\n };\n\n const getContentEditableHost = (editor, node) => editor.dom.getParent(node, node => editor.dom.getContentEditable(node) === 'true');\n const hasContentEditableFalseParent$1 = (editor, node) => editor.dom.getParent(node, node => editor.dom.getContentEditable(node) === 'false') !== null;\n const getCollapsedNode = rng => rng.collapsed ? Optional.from(getNode$1(rng.startContainer, rng.startOffset)).map(SugarElement.fromDom) : Optional.none();\n const getFocusInElement = (root, rng) => getCollapsedNode(rng).bind(node => {\n if (isTableSection(node)) {\n return Optional.some(node);\n } else if (!contains(root, node)) {\n return Optional.some(root);\n } else {\n return Optional.none();\n }\n });\n const normalizeSelection = (editor, rng) => {\n getFocusInElement(SugarElement.fromDom(editor.getBody()), rng).bind(elm => {\n return firstPositionIn(elm.dom);\n }).fold(() => {\n editor.selection.normalize();\n }, caretPos => editor.selection.setRng(caretPos.toRange()));\n };\n const focusBody = body => {\n if (body.setActive) {\n try {\n body.setActive();\n } catch (ex) {\n body.focus();\n }\n } else {\n body.focus();\n }\n };\n const hasElementFocus = elm => hasFocus$1(elm) || search(elm).isSome();\n const hasIframeFocus = editor => isNonNullable(editor.iframeElement) && hasFocus$1(SugarElement.fromDom(editor.iframeElement));\n const hasInlineFocus = editor => {\n const rawBody = editor.getBody();\n return rawBody && hasElementFocus(SugarElement.fromDom(rawBody));\n };\n const hasUiFocus = editor => {\n const dos = getRootNode(SugarElement.fromDom(editor.getElement()));\n return active$1(dos).filter(elem => !isEditorContentAreaElement(elem.dom) && isUIElement(editor, elem.dom)).isSome();\n };\n const hasFocus = editor => editor.inline ? hasInlineFocus(editor) : hasIframeFocus(editor);\n const hasEditorOrUiFocus = editor => hasFocus(editor) || hasUiFocus(editor);\n const focusEditor = editor => {\n const selection = editor.selection;\n const body = editor.getBody();\n let rng = selection.getRng();\n editor.quirks.refreshContentEditable();\n const restoreBookmark = editor => {\n getRng(editor).each(bookmarkRng => {\n editor.selection.setRng(bookmarkRng);\n rng = bookmarkRng;\n });\n };\n if (!hasFocus(editor) && editor.hasEditableRoot()) {\n restoreBookmark(editor);\n }\n const contentEditableHost = getContentEditableHost(editor, selection.getNode());\n if (contentEditableHost && editor.dom.isChildOf(contentEditableHost, body)) {\n if (!hasContentEditableFalseParent$1(editor, contentEditableHost)) {\n focusBody(body);\n }\n focusBody(contentEditableHost);\n if (!editor.hasEditableRoot()) {\n restoreBookmark(editor);\n }\n normalizeSelection(editor, rng);\n activateEditor(editor);\n return;\n }\n if (!editor.inline) {\n if (!Env.browser.isOpera()) {\n focusBody(body);\n }\n editor.getWin().focus();\n }\n if (Env.browser.isFirefox() || editor.inline) {\n focusBody(body);\n normalizeSelection(editor, rng);\n }\n activateEditor(editor);\n };\n const activateEditor = editor => editor.editorManager.setActive(editor);\n const focus = (editor, skipFocus) => {\n if (editor.removed) {\n return;\n }\n if (skipFocus) {\n activateEditor(editor);\n } else {\n focusEditor(editor);\n }\n };\n\n const VK = {\n BACKSPACE: 8,\n DELETE: 46,\n DOWN: 40,\n ENTER: 13,\n ESC: 27,\n LEFT: 37,\n RIGHT: 39,\n SPACEBAR: 32,\n TAB: 9,\n UP: 38,\n PAGE_UP: 33,\n PAGE_DOWN: 34,\n END: 35,\n HOME: 36,\n modifierPressed: e => {\n return e.shiftKey || e.ctrlKey || e.altKey || VK.metaKeyPressed(e);\n },\n metaKeyPressed: e => {\n return Env.os.isMacOS() || Env.os.isiOS() ? e.metaKey : e.ctrlKey && !e.altKey;\n }\n };\n\n const elementSelectionAttr = 'data-mce-selected';\n const controlElmSelector = 'table,img,figure.image,hr,video,span.mce-preview-object,details';\n const abs = Math.abs;\n const round$1 = Math.round;\n const resizeHandles = {\n nw: [\n 0,\n 0,\n -1,\n -1\n ],\n ne: [\n 1,\n 0,\n 1,\n -1\n ],\n se: [\n 1,\n 1,\n 1,\n 1\n ],\n sw: [\n 0,\n 1,\n -1,\n 1\n ]\n };\n const isTouchEvent = evt => evt.type === 'longpress' || evt.type.indexOf('touch') === 0;\n const ControlSelection = (selection, editor) => {\n const dom = editor.dom;\n const editableDoc = editor.getDoc();\n const rootDocument = document;\n const rootElement = editor.getBody();\n let selectedElm, selectedElmGhost, resizeHelper, selectedHandle, resizeBackdrop;\n let startX, startY, selectedElmX, selectedElmY, startW, startH, ratio, resizeStarted;\n let width;\n let height;\n let startScrollWidth;\n let startScrollHeight;\n const isImage = elm => isNonNullable(elm) && (isImg(elm) || dom.is(elm, 'figure.image'));\n const isMedia = elm => isMedia$2(elm) || dom.hasClass(elm, 'mce-preview-object');\n const isEventOnImageOutsideRange = (evt, range) => {\n if (isTouchEvent(evt)) {\n const touch = evt.touches[0];\n return isImage(evt.target) && !isXYWithinRange(touch.clientX, touch.clientY, range);\n } else {\n return isImage(evt.target) && !isXYWithinRange(evt.clientX, evt.clientY, range);\n }\n };\n const contextMenuSelectImage = evt => {\n const target = evt.target;\n if (isEventOnImageOutsideRange(evt, editor.selection.getRng()) && !evt.isDefaultPrevented()) {\n editor.selection.select(target);\n }\n };\n const getResizeTargets = elm => {\n if (dom.hasClass(elm, 'mce-preview-object') && isNonNullable(elm.firstElementChild)) {\n return [\n elm,\n elm.firstElementChild\n ];\n } else if (dom.is(elm, 'figure.image')) {\n return [elm.querySelector('img')];\n } else {\n return [elm];\n }\n };\n const isResizable = elm => {\n const selector = getObjectResizing(editor);\n if (!selector || editor.mode.isReadOnly()) {\n return false;\n }\n if (elm.getAttribute('data-mce-resize') === 'false') {\n return false;\n }\n if (elm === editor.getBody()) {\n return false;\n }\n if (dom.hasClass(elm, 'mce-preview-object') && isNonNullable(elm.firstElementChild)) {\n return is$1(SugarElement.fromDom(elm.firstElementChild), selector);\n } else {\n return is$1(SugarElement.fromDom(elm), selector);\n }\n };\n const createGhostElement = (dom, elm) => {\n if (isMedia(elm)) {\n return dom.create('img', { src: Env.transparentSrc });\n } else if (isTable$2(elm)) {\n const isNorth = startsWith(selectedHandle.name, 'n');\n const rowSelect = isNorth ? head : last$2;\n const tableElm = elm.cloneNode(true);\n rowSelect(dom.select('tr', tableElm)).each(tr => {\n const cells = dom.select('td,th', tr);\n dom.setStyle(tr, 'height', null);\n each$e(cells, cell => dom.setStyle(cell, 'height', null));\n });\n return tableElm;\n } else {\n return elm.cloneNode(true);\n }\n };\n const setSizeProp = (element, name, value) => {\n if (isNonNullable(value)) {\n const targets = getResizeTargets(element);\n each$e(targets, target => {\n if (target.style[name] || !editor.schema.isValid(target.nodeName.toLowerCase(), name)) {\n dom.setStyle(target, name, value);\n } else {\n dom.setAttrib(target, name, '' + value);\n }\n });\n }\n };\n const setGhostElmSize = (ghostElm, width, height) => {\n setSizeProp(ghostElm, 'width', width);\n setSizeProp(ghostElm, 'height', height);\n };\n const resizeGhostElement = e => {\n let deltaX, deltaY, proportional;\n let resizeHelperX, resizeHelperY;\n deltaX = e.screenX - startX;\n deltaY = e.screenY - startY;\n width = deltaX * selectedHandle[2] + startW;\n height = deltaY * selectedHandle[3] + startH;\n width = width < 5 ? 5 : width;\n height = height < 5 ? 5 : height;\n if ((isImage(selectedElm) || isMedia(selectedElm)) && getResizeImgProportional(editor) !== false) {\n proportional = !VK.modifierPressed(e);\n } else {\n proportional = VK.modifierPressed(e);\n }\n if (proportional) {\n if (abs(deltaX) > abs(deltaY)) {\n height = round$1(width * ratio);\n width = round$1(height / ratio);\n } else {\n width = round$1(height / ratio);\n height = round$1(width * ratio);\n }\n }\n setGhostElmSize(selectedElmGhost, width, height);\n resizeHelperX = selectedHandle.startPos.x + deltaX;\n resizeHelperY = selectedHandle.startPos.y + deltaY;\n resizeHelperX = resizeHelperX > 0 ? resizeHelperX : 0;\n resizeHelperY = resizeHelperY > 0 ? resizeHelperY : 0;\n dom.setStyles(resizeHelper, {\n left: resizeHelperX,\n top: resizeHelperY,\n display: 'block'\n });\n resizeHelper.innerHTML = width + ' × ' + height;\n if (selectedHandle[2] < 0 && selectedElmGhost.clientWidth <= width) {\n dom.setStyle(selectedElmGhost, 'left', selectedElmX + (startW - width));\n }\n if (selectedHandle[3] < 0 && selectedElmGhost.clientHeight <= height) {\n dom.setStyle(selectedElmGhost, 'top', selectedElmY + (startH - height));\n }\n deltaX = rootElement.scrollWidth - startScrollWidth;\n deltaY = rootElement.scrollHeight - startScrollHeight;\n if (deltaX + deltaY !== 0) {\n dom.setStyles(resizeHelper, {\n left: resizeHelperX - deltaX,\n top: resizeHelperY - deltaY\n });\n }\n if (!resizeStarted) {\n fireObjectResizeStart(editor, selectedElm, startW, startH, 'corner-' + selectedHandle.name);\n resizeStarted = true;\n }\n };\n const endGhostResize = () => {\n const wasResizeStarted = resizeStarted;\n resizeStarted = false;\n if (wasResizeStarted) {\n setSizeProp(selectedElm, 'width', width);\n setSizeProp(selectedElm, 'height', height);\n }\n dom.unbind(editableDoc, 'mousemove', resizeGhostElement);\n dom.unbind(editableDoc, 'mouseup', endGhostResize);\n if (rootDocument !== editableDoc) {\n dom.unbind(rootDocument, 'mousemove', resizeGhostElement);\n dom.unbind(rootDocument, 'mouseup', endGhostResize);\n }\n dom.remove(selectedElmGhost);\n dom.remove(resizeHelper);\n dom.remove(resizeBackdrop);\n showResizeRect(selectedElm);\n if (wasResizeStarted) {\n fireObjectResized(editor, selectedElm, width, height, 'corner-' + selectedHandle.name);\n dom.setAttrib(selectedElm, 'style', dom.getAttrib(selectedElm, 'style'));\n }\n editor.nodeChanged();\n };\n const showResizeRect = targetElm => {\n unbindResizeHandleEvents();\n const position = dom.getPos(targetElm, rootElement);\n const selectedElmX = position.x;\n const selectedElmY = position.y;\n const rect = targetElm.getBoundingClientRect();\n const targetWidth = rect.width || rect.right - rect.left;\n const targetHeight = rect.height || rect.bottom - rect.top;\n if (selectedElm !== targetElm) {\n hideResizeRect();\n selectedElm = targetElm;\n width = height = 0;\n }\n const e = editor.dispatch('ObjectSelected', { target: targetElm });\n if (isResizable(targetElm) && !e.isDefaultPrevented()) {\n each$d(resizeHandles, (handle, name) => {\n const startDrag = e => {\n const target = getResizeTargets(selectedElm)[0];\n startX = e.screenX;\n startY = e.screenY;\n startW = target.clientWidth;\n startH = target.clientHeight;\n ratio = startH / startW;\n selectedHandle = handle;\n selectedHandle.name = name;\n selectedHandle.startPos = {\n x: targetWidth * handle[0] + selectedElmX,\n y: targetHeight * handle[1] + selectedElmY\n };\n startScrollWidth = rootElement.scrollWidth;\n startScrollHeight = rootElement.scrollHeight;\n resizeBackdrop = dom.add(rootElement, 'div', {\n 'class': 'mce-resize-backdrop',\n 'data-mce-bogus': 'all'\n });\n dom.setStyles(resizeBackdrop, {\n position: 'fixed',\n left: '0',\n top: '0',\n width: '100%',\n height: '100%'\n });\n selectedElmGhost = createGhostElement(dom, selectedElm);\n dom.addClass(selectedElmGhost, 'mce-clonedresizable');\n dom.setAttrib(selectedElmGhost, 'data-mce-bogus', 'all');\n selectedElmGhost.contentEditable = 'false';\n dom.setStyles(selectedElmGhost, {\n left: selectedElmX,\n top: selectedElmY,\n margin: 0\n });\n setGhostElmSize(selectedElmGhost, targetWidth, targetHeight);\n selectedElmGhost.removeAttribute(elementSelectionAttr);\n rootElement.appendChild(selectedElmGhost);\n dom.bind(editableDoc, 'mousemove', resizeGhostElement);\n dom.bind(editableDoc, 'mouseup', endGhostResize);\n if (rootDocument !== editableDoc) {\n dom.bind(rootDocument, 'mousemove', resizeGhostElement);\n dom.bind(rootDocument, 'mouseup', endGhostResize);\n }\n resizeHelper = dom.add(rootElement, 'div', {\n 'class': 'mce-resize-helper',\n 'data-mce-bogus': 'all'\n }, startW + ' × ' + startH);\n };\n let handleElm = dom.get('mceResizeHandle' + name);\n if (handleElm) {\n dom.remove(handleElm);\n }\n handleElm = dom.add(rootElement, 'div', {\n 'id': 'mceResizeHandle' + name,\n 'data-mce-bogus': 'all',\n 'class': 'mce-resizehandle',\n 'unselectable': true,\n 'style': 'cursor:' + name + '-resize; margin:0; padding:0'\n });\n dom.bind(handleElm, 'mousedown', e => {\n e.stopImmediatePropagation();\n e.preventDefault();\n startDrag(e);\n });\n handle.elm = handleElm;\n dom.setStyles(handleElm, {\n left: targetWidth * handle[0] + selectedElmX - handleElm.offsetWidth / 2,\n top: targetHeight * handle[1] + selectedElmY - handleElm.offsetHeight / 2\n });\n });\n } else {\n hideResizeRect(false);\n }\n };\n const throttledShowResizeRect = first$1(showResizeRect, 0);\n const hideResizeRect = (removeSelected = true) => {\n throttledShowResizeRect.cancel();\n unbindResizeHandleEvents();\n if (selectedElm && removeSelected) {\n selectedElm.removeAttribute(elementSelectionAttr);\n }\n each$d(resizeHandles, (value, name) => {\n const handleElm = dom.get('mceResizeHandle' + name);\n if (handleElm) {\n dom.unbind(handleElm);\n dom.remove(handleElm);\n }\n });\n };\n const isChildOrEqual = (node, parent) => dom.isChildOf(node, parent);\n const updateResizeRect = e => {\n if (resizeStarted || editor.removed || editor.composing) {\n return;\n }\n const targetElm = e.type === 'mousedown' ? e.target : selection.getNode();\n const controlElm = closest$3(SugarElement.fromDom(targetElm), controlElmSelector).map(e => e.dom).filter(e => dom.isEditable(e.parentElement) || e.nodeName === 'IMG' && dom.isEditable(e)).getOrUndefined();\n const selectedValue = isNonNullable(controlElm) ? dom.getAttrib(controlElm, elementSelectionAttr, '1') : '1';\n each$e(dom.select(`img[${ elementSelectionAttr }],hr[${ elementSelectionAttr }]`), img => {\n img.removeAttribute(elementSelectionAttr);\n });\n if (isNonNullable(controlElm) && isChildOrEqual(controlElm, rootElement) && hasEditorOrUiFocus(editor)) {\n disableGeckoResize();\n const startElm = selection.getStart(true);\n if (isChildOrEqual(startElm, controlElm) && isChildOrEqual(selection.getEnd(true), controlElm)) {\n dom.setAttrib(controlElm, elementSelectionAttr, selectedValue);\n throttledShowResizeRect.throttle(controlElm);\n return;\n }\n }\n hideResizeRect();\n };\n const unbindResizeHandleEvents = () => {\n each$d(resizeHandles, handle => {\n if (handle.elm) {\n dom.unbind(handle.elm);\n delete handle.elm;\n }\n });\n };\n const disableGeckoResize = () => {\n try {\n editor.getDoc().execCommand('enableObjectResizing', false, 'false');\n } catch (ex) {\n }\n };\n editor.on('init', () => {\n disableGeckoResize();\n editor.on('NodeChange ResizeEditor ResizeWindow ResizeContent drop', updateResizeRect);\n editor.on('keyup compositionend', e => {\n if (selectedElm && selectedElm.nodeName === 'TABLE') {\n updateResizeRect(e);\n }\n });\n editor.on('hide blur', hideResizeRect);\n editor.on('contextmenu longpress', contextMenuSelectImage, true);\n });\n editor.on('remove', unbindResizeHandleEvents);\n const destroy = () => {\n throttledShowResizeRect.cancel();\n selectedElm = selectedElmGhost = resizeBackdrop = null;\n };\n return {\n isResizable,\n showResizeRect,\n hideResizeRect,\n updateResizeRect,\n destroy\n };\n };\n\n const setStart = (rng, situ) => {\n situ.fold(e => {\n rng.setStartBefore(e.dom);\n }, (e, o) => {\n rng.setStart(e.dom, o);\n }, e => {\n rng.setStartAfter(e.dom);\n });\n };\n const setFinish = (rng, situ) => {\n situ.fold(e => {\n rng.setEndBefore(e.dom);\n }, (e, o) => {\n rng.setEnd(e.dom, o);\n }, e => {\n rng.setEndAfter(e.dom);\n });\n };\n const relativeToNative = (win, startSitu, finishSitu) => {\n const range = win.document.createRange();\n setStart(range, startSitu);\n setFinish(range, finishSitu);\n return range;\n };\n const exactToNative = (win, start, soffset, finish, foffset) => {\n const rng = win.document.createRange();\n rng.setStart(start.dom, soffset);\n rng.setEnd(finish.dom, foffset);\n return rng;\n };\n\n const adt$1 = Adt.generate([\n {\n ltr: [\n 'start',\n 'soffset',\n 'finish',\n 'foffset'\n ]\n },\n {\n rtl: [\n 'start',\n 'soffset',\n 'finish',\n 'foffset'\n ]\n }\n ]);\n const fromRange = (win, type, range) => type(SugarElement.fromDom(range.startContainer), range.startOffset, SugarElement.fromDom(range.endContainer), range.endOffset);\n const getRanges = (win, selection) => selection.match({\n domRange: rng => {\n return {\n ltr: constant(rng),\n rtl: Optional.none\n };\n },\n relative: (startSitu, finishSitu) => {\n return {\n ltr: cached(() => relativeToNative(win, startSitu, finishSitu)),\n rtl: cached(() => Optional.some(relativeToNative(win, finishSitu, startSitu)))\n };\n },\n exact: (start, soffset, finish, foffset) => {\n return {\n ltr: cached(() => exactToNative(win, start, soffset, finish, foffset)),\n rtl: cached(() => Optional.some(exactToNative(win, finish, foffset, start, soffset)))\n };\n }\n });\n const doDiagnose = (win, ranges) => {\n const rng = ranges.ltr();\n if (rng.collapsed) {\n const reversed = ranges.rtl().filter(rev => rev.collapsed === false);\n return reversed.map(rev => adt$1.rtl(SugarElement.fromDom(rev.endContainer), rev.endOffset, SugarElement.fromDom(rev.startContainer), rev.startOffset)).getOrThunk(() => fromRange(win, adt$1.ltr, rng));\n } else {\n return fromRange(win, adt$1.ltr, rng);\n }\n };\n const diagnose = (win, selection) => {\n const ranges = getRanges(win, selection);\n return doDiagnose(win, ranges);\n };\n adt$1.ltr;\n adt$1.rtl;\n\n const caretPositionFromPoint = (doc, x, y) => {\n var _a;\n return Optional.from((_a = doc.caretPositionFromPoint) === null || _a === void 0 ? void 0 : _a.call(doc, x, y)).bind(pos => {\n if (pos.offsetNode === null) {\n return Optional.none();\n }\n const r = doc.createRange();\n r.setStart(pos.offsetNode, pos.offset);\n r.collapse();\n return Optional.some(r);\n });\n };\n const caretRangeFromPoint = (doc, x, y) => {\n var _a;\n return Optional.from((_a = doc.caretRangeFromPoint) === null || _a === void 0 ? void 0 : _a.call(doc, x, y));\n };\n const availableSearch = (doc, x, y) => {\n if (doc.caretPositionFromPoint) {\n return caretPositionFromPoint(doc, x, y);\n } else if (doc.caretRangeFromPoint) {\n return caretRangeFromPoint(doc, x, y);\n } else {\n return Optional.none();\n }\n };\n const fromPoint$1 = (win, x, y) => {\n const doc = win.document;\n return availableSearch(doc, x, y).map(rng => SimRange.create(SugarElement.fromDom(rng.startContainer), rng.startOffset, SugarElement.fromDom(rng.endContainer), rng.endOffset));\n };\n\n const beforeSpecial = (element, offset) => {\n const name$1 = name(element);\n if ('input' === name$1) {\n return Situ.after(element);\n } else if (!contains$2([\n 'br',\n 'img'\n ], name$1)) {\n return Situ.on(element, offset);\n } else {\n return offset === 0 ? Situ.before(element) : Situ.after(element);\n }\n };\n const preprocessRelative = (startSitu, finishSitu) => {\n const start = startSitu.fold(Situ.before, beforeSpecial, Situ.after);\n const finish = finishSitu.fold(Situ.before, beforeSpecial, Situ.after);\n return SimSelection.relative(start, finish);\n };\n const preprocessExact = (start, soffset, finish, foffset) => {\n const startSitu = beforeSpecial(start, soffset);\n const finishSitu = beforeSpecial(finish, foffset);\n return SimSelection.relative(startSitu, finishSitu);\n };\n const preprocess = selection => selection.match({\n domRange: rng => {\n const start = SugarElement.fromDom(rng.startContainer);\n const finish = SugarElement.fromDom(rng.endContainer);\n return preprocessExact(start, rng.startOffset, finish, rng.endOffset);\n },\n relative: preprocessRelative,\n exact: preprocessExact\n });\n\n const fromElements = (elements, scope) => {\n const doc = scope || document;\n const fragment = doc.createDocumentFragment();\n each$e(elements, element => {\n fragment.appendChild(element.dom);\n });\n return SugarElement.fromDom(fragment);\n };\n\n const toNative = selection => {\n const win = SimSelection.getWin(selection).dom;\n const getDomRange = (start, soffset, finish, foffset) => exactToNative(win, start, soffset, finish, foffset);\n const filtered = preprocess(selection);\n return diagnose(win, filtered).match({\n ltr: getDomRange,\n rtl: getDomRange\n });\n };\n const getAtPoint = (win, x, y) => fromPoint$1(win, x, y);\n\n const fromPoint = (clientX, clientY, doc) => {\n const win = defaultView(SugarElement.fromDom(doc));\n return getAtPoint(win.dom, clientX, clientY).map(simRange => {\n const rng = doc.createRange();\n rng.setStart(simRange.start.dom, simRange.soffset);\n rng.setEnd(simRange.finish.dom, simRange.foffset);\n return rng;\n }).getOrUndefined();\n };\n\n const isEq$4 = (rng1, rng2) => {\n return isNonNullable(rng1) && isNonNullable(rng2) && (rng1.startContainer === rng2.startContainer && rng1.startOffset === rng2.startOffset) && (rng1.endContainer === rng2.endContainer && rng1.endOffset === rng2.endOffset);\n };\n\n const findParent = (node, rootNode, predicate) => {\n let currentNode = node;\n while (currentNode && currentNode !== rootNode) {\n if (predicate(currentNode)) {\n return currentNode;\n }\n currentNode = currentNode.parentNode;\n }\n return null;\n };\n const hasParent$1 = (node, rootNode, predicate) => findParent(node, rootNode, predicate) !== null;\n const hasParentWithName = (node, rootNode, name) => hasParent$1(node, rootNode, node => node.nodeName === name);\n const isCeFalseCaretContainer = (node, rootNode) => isCaretContainer$2(node) && !hasParent$1(node, rootNode, isCaretNode);\n const hasBrBeforeAfter = (dom, node, left) => {\n const parentNode = node.parentNode;\n if (parentNode) {\n const walker = new DomTreeWalker(node, dom.getParent(parentNode, dom.isBlock) || dom.getRoot());\n let currentNode;\n while (currentNode = walker[left ? 'prev' : 'next']()) {\n if (isBr$6(currentNode)) {\n return true;\n }\n }\n }\n return false;\n };\n const isPrevNode = (node, name) => {\n var _a;\n return ((_a = node.previousSibling) === null || _a === void 0 ? void 0 : _a.nodeName) === name;\n };\n const hasContentEditableFalseParent = (root, node) => {\n let currentNode = node;\n while (currentNode && currentNode !== root) {\n if (isContentEditableFalse$b(currentNode)) {\n return true;\n }\n currentNode = currentNode.parentNode;\n }\n return false;\n };\n const findTextNodeRelative = (dom, isAfterNode, collapsed, left, startNode) => {\n const body = dom.getRoot();\n const nonEmptyElementsMap = dom.schema.getNonEmptyElements();\n const parentNode = startNode.parentNode;\n let lastInlineElement;\n let node;\n if (!parentNode) {\n return Optional.none();\n }\n const parentBlockContainer = dom.getParent(parentNode, dom.isBlock) || body;\n if (left && isBr$6(startNode) && isAfterNode && dom.isEmpty(parentBlockContainer)) {\n return Optional.some(CaretPosition(parentNode, dom.nodeIndex(startNode)));\n }\n const walker = new DomTreeWalker(startNode, parentBlockContainer);\n while (node = walker[left ? 'prev' : 'next']()) {\n if (dom.getContentEditableParent(node) === 'false' || isCeFalseCaretContainer(node, body)) {\n return Optional.none();\n }\n if (isText$b(node) && node.data.length > 0) {\n if (!hasParentWithName(node, body, 'A')) {\n return Optional.some(CaretPosition(node, left ? node.data.length : 0));\n }\n return Optional.none();\n }\n if (dom.isBlock(node) || nonEmptyElementsMap[node.nodeName.toLowerCase()]) {\n return Optional.none();\n }\n lastInlineElement = node;\n }\n if (isComment(lastInlineElement)) {\n return Optional.none();\n }\n if (collapsed && lastInlineElement) {\n return Optional.some(CaretPosition(lastInlineElement, 0));\n }\n return Optional.none();\n };\n const normalizeEndPoint = (dom, collapsed, start, rng) => {\n const body = dom.getRoot();\n let node;\n let normalized = false;\n let container = start ? rng.startContainer : rng.endContainer;\n let offset = start ? rng.startOffset : rng.endOffset;\n const isAfterNode = isElement$6(container) && offset === container.childNodes.length;\n const nonEmptyElementsMap = dom.schema.getNonEmptyElements();\n let directionLeft = start;\n if (isCaretContainer$2(container)) {\n return Optional.none();\n }\n if (isElement$6(container) && offset > container.childNodes.length - 1) {\n directionLeft = false;\n }\n if (isDocument$1(container)) {\n container = body;\n offset = 0;\n }\n if (container === body) {\n if (directionLeft) {\n node = container.childNodes[offset > 0 ? offset - 1 : 0];\n if (node) {\n if (isCaretContainer$2(node)) {\n return Optional.none();\n }\n if (nonEmptyElementsMap[node.nodeName] || isTable$2(node)) {\n return Optional.none();\n }\n }\n }\n if (container.hasChildNodes()) {\n offset = Math.min(!directionLeft && offset > 0 ? offset - 1 : offset, container.childNodes.length - 1);\n container = container.childNodes[offset];\n offset = isText$b(container) && isAfterNode ? container.data.length : 0;\n if (!collapsed && container === body.lastChild && isTable$2(container)) {\n return Optional.none();\n }\n if (hasContentEditableFalseParent(body, container) || isCaretContainer$2(container)) {\n return Optional.none();\n }\n if (isDetails(container)) {\n return Optional.none();\n }\n if (container.hasChildNodes() && !isTable$2(container)) {\n node = container;\n const walker = new DomTreeWalker(container, body);\n do {\n if (isContentEditableFalse$b(node) || isCaretContainer$2(node)) {\n normalized = false;\n break;\n }\n if (isText$b(node) && node.data.length > 0) {\n offset = directionLeft ? 0 : node.data.length;\n container = node;\n normalized = true;\n break;\n }\n if (nonEmptyElementsMap[node.nodeName.toLowerCase()] && !isTableCellOrCaption(node)) {\n offset = dom.nodeIndex(node);\n container = node.parentNode;\n if (!directionLeft) {\n offset++;\n }\n normalized = true;\n break;\n }\n } while (node = directionLeft ? walker.next() : walker.prev());\n }\n }\n }\n if (collapsed) {\n if (isText$b(container) && offset === 0) {\n findTextNodeRelative(dom, isAfterNode, collapsed, true, container).each(pos => {\n container = pos.container();\n offset = pos.offset();\n normalized = true;\n });\n }\n if (isElement$6(container)) {\n node = container.childNodes[offset];\n if (!node) {\n node = container.childNodes[offset - 1];\n }\n if (node && isBr$6(node) && !isPrevNode(node, 'A') && !hasBrBeforeAfter(dom, node, false) && !hasBrBeforeAfter(dom, node, true)) {\n findTextNodeRelative(dom, isAfterNode, collapsed, true, node).each(pos => {\n container = pos.container();\n offset = pos.offset();\n normalized = true;\n });\n }\n }\n }\n if (directionLeft && !collapsed && isText$b(container) && offset === container.data.length) {\n findTextNodeRelative(dom, isAfterNode, collapsed, false, container).each(pos => {\n container = pos.container();\n offset = pos.offset();\n normalized = true;\n });\n }\n return normalized && container ? Optional.some(CaretPosition(container, offset)) : Optional.none();\n };\n const normalize$2 = (dom, rng) => {\n const collapsed = rng.collapsed, normRng = rng.cloneRange();\n const startPos = CaretPosition.fromRangeStart(rng);\n normalizeEndPoint(dom, collapsed, true, normRng).each(pos => {\n if (!collapsed || !CaretPosition.isAbove(startPos, pos)) {\n normRng.setStart(pos.container(), pos.offset());\n }\n });\n if (!collapsed) {\n normalizeEndPoint(dom, collapsed, false, normRng).each(pos => {\n normRng.setEnd(pos.container(), pos.offset());\n });\n }\n if (collapsed) {\n normRng.collapse(true);\n }\n return isEq$4(rng, normRng) ? Optional.none() : Optional.some(normRng);\n };\n\n const splitText = (node, offset) => {\n return node.splitText(offset);\n };\n const split = rng => {\n let startContainer = rng.startContainer, startOffset = rng.startOffset, endContainer = rng.endContainer, endOffset = rng.endOffset;\n if (startContainer === endContainer && isText$b(startContainer)) {\n if (startOffset > 0 && startOffset < startContainer.data.length) {\n endContainer = splitText(startContainer, startOffset);\n startContainer = endContainer.previousSibling;\n if (endOffset > startOffset) {\n endOffset = endOffset - startOffset;\n const newContainer = splitText(endContainer, endOffset).previousSibling;\n startContainer = endContainer = newContainer;\n endOffset = newContainer.data.length;\n startOffset = 0;\n } else {\n endOffset = 0;\n }\n }\n } else {\n if (isText$b(startContainer) && startOffset > 0 && startOffset < startContainer.data.length) {\n startContainer = splitText(startContainer, startOffset);\n startOffset = 0;\n }\n if (isText$b(endContainer) && endOffset > 0 && endOffset < endContainer.data.length) {\n const newContainer = splitText(endContainer, endOffset).previousSibling;\n endContainer = newContainer;\n endOffset = newContainer.data.length;\n }\n }\n return {\n startContainer,\n startOffset,\n endContainer,\n endOffset\n };\n };\n\n const RangeUtils = dom => {\n const walk = (rng, callback) => {\n return walk$3(dom, rng, callback);\n };\n const split$1 = split;\n const normalize = rng => {\n return normalize$2(dom, rng).fold(never, normalizedRng => {\n rng.setStart(normalizedRng.startContainer, normalizedRng.startOffset);\n rng.setEnd(normalizedRng.endContainer, normalizedRng.endOffset);\n return true;\n });\n };\n const expand = (rng, options = { type: 'word' }) => {\n if (options.type === 'word') {\n const rangeLike = expandRng(dom, rng, [{ inline: 'span' }]);\n const newRange = dom.createRng();\n newRange.setStart(rangeLike.startContainer, rangeLike.startOffset);\n newRange.setEnd(rangeLike.endContainer, rangeLike.endOffset);\n return newRange;\n }\n return rng;\n };\n return {\n walk,\n split: split$1,\n expand,\n normalize\n };\n };\n RangeUtils.compareRanges = isEq$4;\n RangeUtils.getCaretRangeFromPoint = fromPoint;\n RangeUtils.getSelectedNode = getSelectedNode;\n RangeUtils.getNode = getNode$1;\n\n const Dimension = (name, getOffset) => {\n const set = (element, h) => {\n if (!isNumber(h) && !h.match(/^[0-9]+$/)) {\n throw new Error(name + '.set accepts only positive integer values. Value was ' + h);\n }\n const dom = element.dom;\n if (isSupported(dom)) {\n dom.style[name] = h + 'px';\n }\n };\n const get = element => {\n const r = getOffset(element);\n if (r <= 0 || r === null) {\n const css = get$7(element, name);\n return parseFloat(css) || 0;\n }\n return r;\n };\n const getOuter = get;\n const aggregate = (element, properties) => foldl(properties, (acc, property) => {\n const val = get$7(element, property);\n const value = val === undefined ? 0 : parseInt(val, 10);\n return isNaN(value) ? acc : acc + value;\n }, 0);\n const max = (element, value, properties) => {\n const cumulativeInclusions = aggregate(element, properties);\n const absoluteMax = value > cumulativeInclusions ? value - cumulativeInclusions : 0;\n return absoluteMax;\n };\n return {\n set,\n get,\n getOuter,\n aggregate,\n max\n };\n };\n\n const api = Dimension('height', element => {\n const dom = element.dom;\n return inBody(element) ? dom.getBoundingClientRect().height : dom.offsetHeight;\n });\n const get$2 = element => api.get(element);\n\n const walkUp = (navigation, doc) => {\n const frame = navigation.view(doc);\n return frame.fold(constant([]), f => {\n const parent = navigation.owner(f);\n const rest = walkUp(navigation, parent);\n return [f].concat(rest);\n });\n };\n const pathTo = (element, navigation) => {\n const d = navigation.owner(element);\n return walkUp(navigation, d);\n };\n\n const view = doc => {\n var _a;\n const element = doc.dom === document ? Optional.none() : Optional.from((_a = doc.dom.defaultView) === null || _a === void 0 ? void 0 : _a.frameElement);\n return element.map(SugarElement.fromDom);\n };\n const owner = element => documentOrOwner(element);\n\n var Navigation = /*#__PURE__*/Object.freeze({\n __proto__: null,\n view: view,\n owner: owner\n });\n\n const find = element => {\n const doc = getDocument();\n const scroll = get$5(doc);\n const frames = pathTo(element, Navigation);\n const offset = viewport(element);\n const r = foldr(frames, (b, a) => {\n const loc = viewport(a);\n return {\n left: b.left + loc.left,\n top: b.top + loc.top\n };\n }, {\n left: 0,\n top: 0\n });\n return SugarPosition(r.left + offset.left + scroll.left, r.top + offset.top + scroll.top);\n };\n\n const excludeFromDescend = element => name(element) === 'textarea';\n const fireScrollIntoViewEvent = (editor, data) => {\n const scrollEvent = editor.dispatch('ScrollIntoView', data);\n return scrollEvent.isDefaultPrevented();\n };\n const fireAfterScrollIntoViewEvent = (editor, data) => {\n editor.dispatch('AfterScrollIntoView', data);\n };\n const descend = (element, offset) => {\n const children = children$1(element);\n if (children.length === 0 || excludeFromDescend(element)) {\n return {\n element,\n offset\n };\n } else if (offset < children.length && !excludeFromDescend(children[offset])) {\n return {\n element: children[offset],\n offset: 0\n };\n } else {\n const last = children[children.length - 1];\n if (excludeFromDescend(last)) {\n return {\n element,\n offset\n };\n } else {\n if (name(last) === 'img') {\n return {\n element: last,\n offset: 1\n };\n } else if (isText$c(last)) {\n return {\n element: last,\n offset: get$3(last).length\n };\n } else {\n return {\n element: last,\n offset: children$1(last).length\n };\n }\n }\n }\n };\n const markerInfo = (element, cleanupFun) => {\n const pos = absolute(element);\n const height = get$2(element);\n return {\n element,\n bottom: pos.top + height,\n height,\n pos,\n cleanup: cleanupFun\n };\n };\n const createMarker$1 = (element, offset) => {\n const startPoint = descend(element, offset);\n const span = SugarElement.fromHtml('' + ZWSP$1 + '');\n before$3(startPoint.element, span);\n return markerInfo(span, () => remove$4(span));\n };\n const elementMarker = element => markerInfo(SugarElement.fromDom(element), noop);\n const withMarker = (editor, f, rng, alignToTop) => {\n preserveWith(editor, (_s, _e) => applyWithMarker(editor, f, rng, alignToTop), rng);\n };\n const withScrollEvents = (editor, doc, f, marker, alignToTop) => {\n const data = {\n elm: marker.element.dom,\n alignToTop\n };\n if (fireScrollIntoViewEvent(editor, data)) {\n return;\n }\n const scrollTop = get$5(doc).top;\n f(editor, doc, scrollTop, marker, alignToTop);\n fireAfterScrollIntoViewEvent(editor, data);\n };\n const applyWithMarker = (editor, f, rng, alignToTop) => {\n const body = SugarElement.fromDom(editor.getBody());\n const doc = SugarElement.fromDom(editor.getDoc());\n reflow(body);\n const marker = createMarker$1(SugarElement.fromDom(rng.startContainer), rng.startOffset);\n withScrollEvents(editor, doc, f, marker, alignToTop);\n marker.cleanup();\n };\n const withElement = (editor, element, f, alignToTop) => {\n const doc = SugarElement.fromDom(editor.getDoc());\n withScrollEvents(editor, doc, f, elementMarker(element), alignToTop);\n };\n const preserveWith = (editor, f, rng) => {\n const startElement = rng.startContainer;\n const startOffset = rng.startOffset;\n const endElement = rng.endContainer;\n const endOffset = rng.endOffset;\n f(SugarElement.fromDom(startElement), SugarElement.fromDom(endElement));\n const newRng = editor.dom.createRng();\n newRng.setStart(startElement, startOffset);\n newRng.setEnd(endElement, endOffset);\n editor.selection.setRng(rng);\n };\n const scrollToMarker = (editor, marker, viewHeight, alignToTop, doc) => {\n const pos = marker.pos;\n if (alignToTop) {\n to(pos.left, pos.top, doc);\n } else {\n const y = pos.top - viewHeight + marker.height;\n to(-editor.getBody().getBoundingClientRect().left, y, doc);\n }\n };\n const intoWindowIfNeeded = (editor, doc, scrollTop, viewHeight, marker, alignToTop) => {\n const viewportBottom = viewHeight + scrollTop;\n const markerTop = marker.pos.top;\n const markerBottom = marker.bottom;\n const largerThanViewport = markerBottom - markerTop >= viewHeight;\n if (markerTop < scrollTop) {\n scrollToMarker(editor, marker, viewHeight, alignToTop !== false, doc);\n } else if (markerTop > viewportBottom) {\n const align = largerThanViewport ? alignToTop !== false : alignToTop === true;\n scrollToMarker(editor, marker, viewHeight, align, doc);\n } else if (markerBottom > viewportBottom && !largerThanViewport) {\n scrollToMarker(editor, marker, viewHeight, alignToTop === true, doc);\n }\n };\n const intoWindow = (editor, doc, scrollTop, marker, alignToTop) => {\n const viewHeight = defaultView(doc).dom.innerHeight;\n intoWindowIfNeeded(editor, doc, scrollTop, viewHeight, marker, alignToTop);\n };\n const intoFrame = (editor, doc, scrollTop, marker, alignToTop) => {\n const frameViewHeight = defaultView(doc).dom.innerHeight;\n intoWindowIfNeeded(editor, doc, scrollTop, frameViewHeight, marker, alignToTop);\n const op = find(marker.element);\n const viewportBounds = getBounds(window);\n if (op.top < viewportBounds.y) {\n intoView(marker.element, alignToTop !== false);\n } else if (op.top > viewportBounds.bottom) {\n intoView(marker.element, alignToTop === true);\n }\n };\n const rangeIntoWindow = (editor, rng, alignToTop) => withMarker(editor, intoWindow, rng, alignToTop);\n const elementIntoWindow = (editor, element, alignToTop) => withElement(editor, element, intoWindow, alignToTop);\n const rangeIntoFrame = (editor, rng, alignToTop) => withMarker(editor, intoFrame, rng, alignToTop);\n const elementIntoFrame = (editor, element, alignToTop) => withElement(editor, element, intoFrame, alignToTop);\n const scrollElementIntoView = (editor, element, alignToTop) => {\n const scroller = editor.inline ? elementIntoWindow : elementIntoFrame;\n scroller(editor, element, alignToTop);\n };\n const scrollRangeIntoView = (editor, rng, alignToTop) => {\n const scroller = editor.inline ? rangeIntoWindow : rangeIntoFrame;\n scroller(editor, rng, alignToTop);\n };\n\n const isEditableRange = (dom, rng) => {\n if (rng.collapsed) {\n return dom.isEditable(rng.startContainer);\n } else {\n return dom.isEditable(rng.startContainer) && dom.isEditable(rng.endContainer);\n }\n };\n\n const getEndpointElement = (root, rng, start, real, resolve) => {\n const container = start ? rng.startContainer : rng.endContainer;\n const offset = start ? rng.startOffset : rng.endOffset;\n return Optional.from(container).map(SugarElement.fromDom).map(elm => !real || !rng.collapsed ? child$1(elm, resolve(elm, offset)).getOr(elm) : elm).bind(elm => isElement$7(elm) ? Optional.some(elm) : parent(elm).filter(isElement$7)).map(elm => elm.dom).getOr(root);\n };\n const getStart = (root, rng, real = false) => getEndpointElement(root, rng, true, real, (elm, offset) => Math.min(childNodesCount(elm), offset));\n const getEnd = (root, rng, real = false) => getEndpointElement(root, rng, false, real, (elm, offset) => offset > 0 ? offset - 1 : offset);\n const skipEmptyTextNodes = (node, forwards) => {\n const orig = node;\n while (node && isText$b(node) && node.length === 0) {\n node = forwards ? node.nextSibling : node.previousSibling;\n }\n return node || orig;\n };\n const getNode = (root, rng) => {\n if (!rng) {\n return root;\n }\n let startContainer = rng.startContainer;\n let endContainer = rng.endContainer;\n const startOffset = rng.startOffset;\n const endOffset = rng.endOffset;\n let node = rng.commonAncestorContainer;\n if (!rng.collapsed) {\n if (startContainer === endContainer) {\n if (endOffset - startOffset < 2) {\n if (startContainer.hasChildNodes()) {\n node = startContainer.childNodes[startOffset];\n }\n }\n }\n if (isText$b(startContainer) && isText$b(endContainer)) {\n if (startContainer.length === startOffset) {\n startContainer = skipEmptyTextNodes(startContainer.nextSibling, true);\n } else {\n startContainer = startContainer.parentNode;\n }\n if (endOffset === 0) {\n endContainer = skipEmptyTextNodes(endContainer.previousSibling, false);\n } else {\n endContainer = endContainer.parentNode;\n }\n if (startContainer && startContainer === endContainer) {\n node = startContainer;\n }\n }\n }\n const elm = isText$b(node) ? node.parentNode : node;\n return isHTMLElement(elm) ? elm : root;\n };\n const getSelectedBlocks = (dom, rng, startElm, endElm) => {\n const selectedBlocks = [];\n const root = dom.getRoot();\n const start = dom.getParent(startElm || getStart(root, rng, rng.collapsed), dom.isBlock);\n const end = dom.getParent(endElm || getEnd(root, rng, rng.collapsed), dom.isBlock);\n if (start && start !== root) {\n selectedBlocks.push(start);\n }\n if (start && end && start !== end) {\n let node;\n const walker = new DomTreeWalker(start, root);\n while ((node = walker.next()) && node !== end) {\n if (dom.isBlock(node)) {\n selectedBlocks.push(node);\n }\n }\n }\n if (end && start !== end && end !== root) {\n selectedBlocks.push(end);\n }\n return selectedBlocks;\n };\n const select = (dom, node, content) => Optional.from(node).bind(node => Optional.from(node.parentNode).map(parent => {\n const idx = dom.nodeIndex(node);\n const rng = dom.createRng();\n rng.setStart(parent, idx);\n rng.setEnd(parent, idx + 1);\n if (content) {\n moveEndPoint(dom, rng, node, true);\n moveEndPoint(dom, rng, node, false);\n }\n return rng;\n }));\n\n const processRanges = (editor, ranges) => map$3(ranges, range => {\n const evt = editor.dispatch('GetSelectionRange', { range });\n return evt.range !== range ? evt.range : range;\n });\n\n const typeLookup = {\n '#text': 3,\n '#comment': 8,\n '#cdata': 4,\n '#pi': 7,\n '#doctype': 10,\n '#document-fragment': 11\n };\n const walk$2 = (node, root, prev) => {\n const startName = prev ? 'lastChild' : 'firstChild';\n const siblingName = prev ? 'prev' : 'next';\n if (node[startName]) {\n return node[startName];\n }\n if (node !== root) {\n let sibling = node[siblingName];\n if (sibling) {\n return sibling;\n }\n for (let parent = node.parent; parent && parent !== root; parent = parent.parent) {\n sibling = parent[siblingName];\n if (sibling) {\n return sibling;\n }\n }\n }\n return undefined;\n };\n const isEmptyTextNode = node => {\n var _a;\n const text = (_a = node.value) !== null && _a !== void 0 ? _a : '';\n if (!isWhitespaceText(text)) {\n return false;\n }\n const parentNode = node.parent;\n if (parentNode && (parentNode.name !== 'span' || parentNode.attr('style')) && /^[ ]+$/.test(text)) {\n return false;\n }\n return true;\n };\n const isNonEmptyElement = node => {\n const isNamedAnchor = node.name === 'a' && !node.attr('href') && node.attr('id');\n return node.attr('name') || node.attr('id') && !node.firstChild || node.attr('data-mce-bookmark') || isNamedAnchor;\n };\n class AstNode {\n static create(name, attrs) {\n const node = new AstNode(name, typeLookup[name] || 1);\n if (attrs) {\n each$d(attrs, (value, attrName) => {\n node.attr(attrName, value);\n });\n }\n return node;\n }\n constructor(name, type) {\n this.name = name;\n this.type = type;\n if (type === 1) {\n this.attributes = [];\n this.attributes.map = {};\n }\n }\n replace(node) {\n const self = this;\n if (node.parent) {\n node.remove();\n }\n self.insert(node, self);\n self.remove();\n return self;\n }\n attr(name, value) {\n const self = this;\n if (!isString(name)) {\n if (isNonNullable(name)) {\n each$d(name, (value, key) => {\n self.attr(key, value);\n });\n }\n return self;\n }\n const attrs = self.attributes;\n if (attrs) {\n if (value !== undefined) {\n if (value === null) {\n if (name in attrs.map) {\n delete attrs.map[name];\n let i = attrs.length;\n while (i--) {\n if (attrs[i].name === name) {\n attrs.splice(i, 1);\n return self;\n }\n }\n }\n return self;\n }\n if (name in attrs.map) {\n let i = attrs.length;\n while (i--) {\n if (attrs[i].name === name) {\n attrs[i].value = value;\n break;\n }\n }\n } else {\n attrs.push({\n name,\n value\n });\n }\n attrs.map[name] = value;\n return self;\n }\n return attrs.map[name];\n }\n return undefined;\n }\n clone() {\n const self = this;\n const clone = new AstNode(self.name, self.type);\n const selfAttrs = self.attributes;\n if (selfAttrs) {\n const cloneAttrs = [];\n cloneAttrs.map = {};\n for (let i = 0, l = selfAttrs.length; i < l; i++) {\n const selfAttr = selfAttrs[i];\n if (selfAttr.name !== 'id') {\n cloneAttrs[cloneAttrs.length] = {\n name: selfAttr.name,\n value: selfAttr.value\n };\n cloneAttrs.map[selfAttr.name] = selfAttr.value;\n }\n }\n clone.attributes = cloneAttrs;\n }\n clone.value = self.value;\n return clone;\n }\n wrap(wrapper) {\n const self = this;\n if (self.parent) {\n self.parent.insert(wrapper, self);\n wrapper.append(self);\n }\n return self;\n }\n unwrap() {\n const self = this;\n for (let node = self.firstChild; node;) {\n const next = node.next;\n self.insert(node, self, true);\n node = next;\n }\n self.remove();\n }\n remove() {\n const self = this, parent = self.parent, next = self.next, prev = self.prev;\n if (parent) {\n if (parent.firstChild === self) {\n parent.firstChild = next;\n if (next) {\n next.prev = null;\n }\n } else if (prev) {\n prev.next = next;\n }\n if (parent.lastChild === self) {\n parent.lastChild = prev;\n if (prev) {\n prev.next = null;\n }\n } else if (next) {\n next.prev = prev;\n }\n self.parent = self.next = self.prev = null;\n }\n return self;\n }\n append(node) {\n const self = this;\n if (node.parent) {\n node.remove();\n }\n const last = self.lastChild;\n if (last) {\n last.next = node;\n node.prev = last;\n self.lastChild = node;\n } else {\n self.lastChild = self.firstChild = node;\n }\n node.parent = self;\n return node;\n }\n insert(node, refNode, before) {\n if (node.parent) {\n node.remove();\n }\n const parent = refNode.parent || this;\n if (before) {\n if (refNode === parent.firstChild) {\n parent.firstChild = node;\n } else if (refNode.prev) {\n refNode.prev.next = node;\n }\n node.prev = refNode.prev;\n node.next = refNode;\n refNode.prev = node;\n } else {\n if (refNode === parent.lastChild) {\n parent.lastChild = node;\n } else if (refNode.next) {\n refNode.next.prev = node;\n }\n node.next = refNode.next;\n node.prev = refNode;\n refNode.next = node;\n }\n node.parent = parent;\n return node;\n }\n getAll(name) {\n const self = this;\n const collection = [];\n for (let node = self.firstChild; node; node = walk$2(node, self)) {\n if (node.name === name) {\n collection.push(node);\n }\n }\n return collection;\n }\n children() {\n const self = this;\n const collection = [];\n for (let node = self.firstChild; node; node = node.next) {\n collection.push(node);\n }\n return collection;\n }\n empty() {\n const self = this;\n if (self.firstChild) {\n const nodes = [];\n for (let node = self.firstChild; node; node = walk$2(node, self)) {\n nodes.push(node);\n }\n let i = nodes.length;\n while (i--) {\n const node = nodes[i];\n node.parent = node.firstChild = node.lastChild = node.next = node.prev = null;\n }\n }\n self.firstChild = self.lastChild = null;\n return self;\n }\n isEmpty(elements, whitespace = {}, predicate) {\n var _a;\n const self = this;\n let node = self.firstChild;\n if (isNonEmptyElement(self)) {\n return false;\n }\n if (node) {\n do {\n if (node.type === 1) {\n if (node.attr('data-mce-bogus')) {\n continue;\n }\n if (elements[node.name]) {\n return false;\n }\n if (isNonEmptyElement(node)) {\n return false;\n }\n }\n if (node.type === 8) {\n return false;\n }\n if (node.type === 3 && !isEmptyTextNode(node)) {\n return false;\n }\n if (node.type === 3 && node.parent && whitespace[node.parent.name] && isWhitespaceText((_a = node.value) !== null && _a !== void 0 ? _a : '')) {\n return false;\n }\n if (predicate && predicate(node)) {\n return false;\n }\n } while (node = walk$2(node, self));\n }\n return true;\n }\n walk(prev) {\n return walk$2(this, null, prev);\n }\n }\n\n const unescapedTextParents = Tools.makeMap('NOSCRIPT STYLE SCRIPT XMP IFRAME NOEMBED NOFRAMES PLAINTEXT', ' ');\n const containsZwsp = node => isString(node.nodeValue) && node.nodeValue.includes(ZWSP$1);\n const getTemporaryNodeSelector = tempAttrs => `${ tempAttrs.length === 0 ? '' : `${ map$3(tempAttrs, attr => `[${ attr }]`).join(',') },` }[data-mce-bogus=\"all\"]`;\n const getTemporaryNodes = (tempAttrs, body) => body.querySelectorAll(getTemporaryNodeSelector(tempAttrs));\n const createZwspCommentWalker = body => document.createTreeWalker(body, NodeFilter.SHOW_COMMENT, node => containsZwsp(node) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP);\n const createUnescapedZwspTextWalker = body => document.createTreeWalker(body, NodeFilter.SHOW_TEXT, node => {\n if (containsZwsp(node)) {\n const parent = node.parentNode;\n return parent && has$2(unescapedTextParents, parent.nodeName) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;\n } else {\n return NodeFilter.FILTER_SKIP;\n }\n });\n const hasZwspComment = body => createZwspCommentWalker(body).nextNode() !== null;\n const hasUnescapedZwspText = body => createUnescapedZwspTextWalker(body).nextNode() !== null;\n const hasTemporaryNode = (tempAttrs, body) => body.querySelector(getTemporaryNodeSelector(tempAttrs)) !== null;\n const trimTemporaryNodes = (tempAttrs, body) => {\n each$e(getTemporaryNodes(tempAttrs, body), elm => {\n const element = SugarElement.fromDom(elm);\n if (get$9(element, 'data-mce-bogus') === 'all') {\n remove$4(element);\n } else {\n each$e(tempAttrs, attr => {\n if (has$1(element, attr)) {\n remove$9(element, attr);\n }\n });\n }\n });\n };\n const emptyAllNodeValuesInWalker = walker => {\n let curr = walker.nextNode();\n while (curr !== null) {\n curr.nodeValue = null;\n curr = walker.nextNode();\n }\n };\n const emptyZwspComments = compose(emptyAllNodeValuesInWalker, createZwspCommentWalker);\n const emptyUnescapedZwspTexts = compose(emptyAllNodeValuesInWalker, createUnescapedZwspTextWalker);\n const trim$1 = (body, tempAttrs) => {\n const conditionalTrims = [\n {\n condition: curry(hasTemporaryNode, tempAttrs),\n action: curry(trimTemporaryNodes, tempAttrs)\n },\n {\n condition: hasZwspComment,\n action: emptyZwspComments\n },\n {\n condition: hasUnescapedZwspText,\n action: emptyUnescapedZwspTexts\n }\n ];\n let trimmed = body;\n let cloned = false;\n each$e(conditionalTrims, ({condition, action}) => {\n if (condition(trimmed)) {\n if (!cloned) {\n trimmed = body.cloneNode(true);\n cloned = true;\n }\n action(trimmed);\n }\n });\n return trimmed;\n };\n\n const cleanupBogusElements = parent => {\n const bogusElements = descendants(parent, '[data-mce-bogus]');\n each$e(bogusElements, elem => {\n const bogusValue = get$9(elem, 'data-mce-bogus');\n if (bogusValue === 'all') {\n remove$4(elem);\n } else if (isBr$5(elem)) {\n before$3(elem, SugarElement.fromText(zeroWidth));\n remove$4(elem);\n } else {\n unwrap(elem);\n }\n });\n };\n const cleanupInputNames = parent => {\n const inputs = descendants(parent, 'input');\n each$e(inputs, input => {\n remove$9(input, 'name');\n });\n };\n\n const trimEmptyContents = (editor, html) => {\n const blockName = getForcedRootBlock(editor);\n const emptyRegExp = new RegExp(`^(<${ blockName }[^>]*>( | |\\\\s|\\u00a0|
|)<\\\\/${ blockName }>[\\r\\n]*|
[\\r\\n]*)$`);\n return html.replace(emptyRegExp, '');\n };\n const getPlainTextContent = (editor, body) => {\n const doc = editor.getDoc();\n const dos = getRootNode(SugarElement.fromDom(editor.getBody()));\n const offscreenDiv = SugarElement.fromTag('div', doc);\n set$4(offscreenDiv, 'data-mce-bogus', 'all');\n setAll(offscreenDiv, {\n position: 'fixed',\n left: '-9999999px',\n top: '0'\n });\n set$1(offscreenDiv, body.innerHTML);\n cleanupBogusElements(offscreenDiv);\n cleanupInputNames(offscreenDiv);\n const root = getContentContainer(dos);\n append$1(root, offscreenDiv);\n const content = trim$2(offscreenDiv.dom.innerText);\n remove$4(offscreenDiv);\n return content;\n };\n const getContentFromBody = (editor, args, body) => {\n let content;\n if (args.format === 'raw') {\n content = Tools.trim(trim$2(trim$1(body, editor.serializer.getTempAttrs()).innerHTML));\n } else if (args.format === 'text') {\n content = getPlainTextContent(editor, body);\n } else if (args.format === 'tree') {\n content = editor.serializer.serialize(body, args);\n } else {\n content = trimEmptyContents(editor, editor.serializer.serialize(body, args));\n }\n const shouldTrim = args.format !== 'text' && !isWsPreserveElement(SugarElement.fromDom(body));\n return shouldTrim && isString(content) ? Tools.trim(content) : content;\n };\n const getContentInternal = (editor, args) => Optional.from(editor.getBody()).fold(constant(args.format === 'tree' ? new AstNode('body', 11) : ''), body => getContentFromBody(editor, args, body));\n\n const makeMap$1 = Tools.makeMap;\n const Writer = settings => {\n const html = [];\n settings = settings || {};\n const indent = settings.indent;\n const indentBefore = makeMap$1(settings.indent_before || '');\n const indentAfter = makeMap$1(settings.indent_after || '');\n const encode = Entities.getEncodeFunc(settings.entity_encoding || 'raw', settings.entities);\n const htmlOutput = settings.element_format !== 'xhtml';\n return {\n start: (name, attrs, empty) => {\n if (indent && indentBefore[name] && html.length > 0) {\n const value = html[html.length - 1];\n if (value.length > 0 && value !== '\\n') {\n html.push('\\n');\n }\n }\n html.push('<', name);\n if (attrs) {\n for (let i = 0, l = attrs.length; i < l; i++) {\n const attr = attrs[i];\n html.push(' ', attr.name, '=\"', encode(attr.value, true), '\"');\n }\n }\n if (!empty || htmlOutput) {\n html[html.length] = '>';\n } else {\n html[html.length] = ' />';\n }\n if (empty && indent && indentAfter[name] && html.length > 0) {\n const value = html[html.length - 1];\n if (value.length > 0 && value !== '\\n') {\n html.push('\\n');\n }\n }\n },\n end: name => {\n let value;\n html.push('', name, '>');\n if (indent && indentAfter[name] && html.length > 0) {\n value = html[html.length - 1];\n if (value.length > 0 && value !== '\\n') {\n html.push('\\n');\n }\n }\n },\n text: (text, raw) => {\n if (text.length > 0) {\n html[html.length] = raw ? text : encode(text);\n }\n },\n cdata: text => {\n html.push('');\n },\n comment: text => {\n html.push('');\n },\n pi: (name, text) => {\n if (text) {\n html.push('', name, ' ', encode(text), '?>');\n } else {\n html.push('', name, '?>');\n }\n if (indent) {\n html.push('\\n');\n }\n },\n doctype: text => {\n html.push('', indent ? '\\n' : '');\n },\n reset: () => {\n html.length = 0;\n },\n getContent: () => {\n return html.join('').replace(/\\n$/, '');\n }\n };\n };\n\n const HtmlSerializer = (settings = {}, schema = Schema()) => {\n const writer = Writer(settings);\n settings.validate = 'validate' in settings ? settings.validate : true;\n const serialize = node => {\n const validate = settings.validate;\n const handlers = {\n 3: node => {\n var _a;\n writer.text((_a = node.value) !== null && _a !== void 0 ? _a : '', node.raw);\n },\n 8: node => {\n var _a;\n writer.comment((_a = node.value) !== null && _a !== void 0 ? _a : '');\n },\n 7: node => {\n writer.pi(node.name, node.value);\n },\n 10: node => {\n var _a;\n writer.doctype((_a = node.value) !== null && _a !== void 0 ? _a : '');\n },\n 4: node => {\n var _a;\n writer.cdata((_a = node.value) !== null && _a !== void 0 ? _a : '');\n },\n 11: node => {\n let tempNode = node;\n if (tempNode = tempNode.firstChild) {\n do {\n walk(tempNode);\n } while (tempNode = tempNode.next);\n }\n }\n };\n writer.reset();\n const walk = node => {\n var _a;\n const handler = handlers[node.type];\n if (!handler) {\n const name = node.name;\n const isEmpty = name in schema.getVoidElements();\n let attrs = node.attributes;\n if (validate && attrs && attrs.length > 1) {\n const sortedAttrs = [];\n sortedAttrs.map = {};\n const elementRule = schema.getElementRule(node.name);\n if (elementRule) {\n for (let i = 0, l = elementRule.attributesOrder.length; i < l; i++) {\n const attrName = elementRule.attributesOrder[i];\n if (attrName in attrs.map) {\n const attrValue = attrs.map[attrName];\n sortedAttrs.map[attrName] = attrValue;\n sortedAttrs.push({\n name: attrName,\n value: attrValue\n });\n }\n }\n for (let i = 0, l = attrs.length; i < l; i++) {\n const attrName = attrs[i].name;\n if (!(attrName in sortedAttrs.map)) {\n const attrValue = attrs.map[attrName];\n sortedAttrs.map[attrName] = attrValue;\n sortedAttrs.push({\n name: attrName,\n value: attrValue\n });\n }\n }\n attrs = sortedAttrs;\n }\n }\n writer.start(name, attrs, isEmpty);\n if (isNonHtmlElementRootName(name)) {\n if (isString(node.value)) {\n writer.text(node.value, true);\n }\n writer.end(name);\n } else {\n if (!isEmpty) {\n let child = node.firstChild;\n if (child) {\n if ((name === 'pre' || name === 'textarea') && child.type === 3 && ((_a = child.value) === null || _a === void 0 ? void 0 : _a[0]) === '\\n') {\n writer.text('\\n', true);\n }\n do {\n walk(child);\n } while (child = child.next);\n }\n writer.end(name);\n }\n }\n } else {\n handler(node);\n }\n };\n if (node.type === 1 && !settings.inner) {\n walk(node);\n } else if (node.type === 3) {\n handlers[3](node);\n } else {\n handlers[11](node);\n }\n return writer.getContent();\n };\n return { serialize };\n };\n\n const nonInheritableStyles = new Set();\n (() => {\n const nonInheritableStylesArr = [\n 'margin',\n 'margin-left',\n 'margin-right',\n 'margin-top',\n 'margin-bottom',\n 'padding',\n 'padding-left',\n 'padding-right',\n 'padding-top',\n 'padding-bottom',\n 'border',\n 'border-width',\n 'border-style',\n 'border-color',\n 'background',\n 'background-attachment',\n 'background-clip',\n 'background-image',\n 'background-origin',\n 'background-position',\n 'background-repeat',\n 'background-size',\n 'float',\n 'position',\n 'left',\n 'right',\n 'top',\n 'bottom',\n 'z-index',\n 'display',\n 'transform',\n 'width',\n 'max-width',\n 'min-width',\n 'height',\n 'max-height',\n 'min-height',\n 'overflow',\n 'overflow-x',\n 'overflow-y',\n 'text-overflow',\n 'vertical-align',\n 'transition',\n 'transition-delay',\n 'transition-duration',\n 'transition-property',\n 'transition-timing-function'\n ];\n each$e(nonInheritableStylesArr, style => {\n nonInheritableStyles.add(style);\n });\n })();\n const conditionalNonInheritableStyles = new Set();\n (() => {\n const conditionalNonInheritableStylesArr = ['background-color'];\n each$e(conditionalNonInheritableStylesArr, style => {\n conditionalNonInheritableStyles.add(style);\n });\n })();\n const shorthandStyleProps = [\n 'font',\n 'text-decoration',\n 'text-emphasis'\n ];\n const getStyles$1 = (dom, node) => dom.parseStyle(dom.getAttrib(node, 'style'));\n const getStyleProps = (dom, node) => keys(getStyles$1(dom, node));\n const isNonInheritableStyle = style => nonInheritableStyles.has(style);\n const isConditionalNonInheritableStyle = style => conditionalNonInheritableStyles.has(style);\n const hasNonInheritableStyles = (dom, node) => exists(getStyleProps(dom, node), style => isNonInheritableStyle(style));\n const hasConditionalNonInheritableStyles = (dom, node) => hasNonInheritableStyles(dom, node) && exists(getStyleProps(dom, node), style => isConditionalNonInheritableStyle(style));\n const getLonghandStyleProps = styles => filter$5(styles, style => exists(shorthandStyleProps, prop => startsWith(style, prop)));\n const hasStyleConflict = (dom, node, parentNode) => {\n const nodeStyleProps = getStyleProps(dom, node);\n const parentNodeStyleProps = getStyleProps(dom, parentNode);\n const valueMismatch = prop => {\n var _a, _b;\n const nodeValue = (_a = dom.getStyle(node, prop)) !== null && _a !== void 0 ? _a : '';\n const parentValue = (_b = dom.getStyle(parentNode, prop)) !== null && _b !== void 0 ? _b : '';\n return isNotEmpty(nodeValue) && isNotEmpty(parentValue) && nodeValue !== parentValue;\n };\n return exists(nodeStyleProps, nodeStyleProp => {\n const propExists = props => exists(props, prop => prop === nodeStyleProp);\n if (!propExists(parentNodeStyleProps) && propExists(shorthandStyleProps)) {\n const longhandProps = getLonghandStyleProps(parentNodeStyleProps);\n return exists(longhandProps, valueMismatch);\n } else {\n return valueMismatch(nodeStyleProp);\n }\n });\n };\n\n const isChar = (forward, predicate, pos) => Optional.from(pos.container()).filter(isText$b).exists(text => {\n const delta = forward ? 0 : -1;\n return predicate(text.data.charAt(pos.offset() + delta));\n });\n const isBeforeSpace = curry(isChar, true, isWhiteSpace);\n const isAfterSpace = curry(isChar, false, isWhiteSpace);\n const isEmptyText = pos => {\n const container = pos.container();\n return isText$b(container) && (container.data.length === 0 || isZwsp(container.data) && BookmarkManager.isBookmarkNode(container.parentNode));\n };\n const matchesElementPosition = (before, predicate) => pos => getChildNodeAtRelativeOffset(before ? 0 : -1, pos).filter(predicate).isSome();\n const isImageBlock = node => isImg(node) && get$7(SugarElement.fromDom(node), 'display') === 'block';\n const isCefNode = node => isContentEditableFalse$b(node) && !isBogusAll(node);\n const isBeforeImageBlock = matchesElementPosition(true, isImageBlock);\n const isAfterImageBlock = matchesElementPosition(false, isImageBlock);\n const isBeforeMedia = matchesElementPosition(true, isMedia$2);\n const isAfterMedia = matchesElementPosition(false, isMedia$2);\n const isBeforeTable = matchesElementPosition(true, isTable$2);\n const isAfterTable = matchesElementPosition(false, isTable$2);\n const isBeforeContentEditableFalse = matchesElementPosition(true, isCefNode);\n const isAfterContentEditableFalse = matchesElementPosition(false, isCefNode);\n\n const dropLast = xs => xs.slice(0, -1);\n const parentsUntil = (start, root, predicate) => {\n if (contains(root, start)) {\n return dropLast(parents$1(start, elm => {\n return predicate(elm) || eq(elm, root);\n }));\n } else {\n return [];\n }\n };\n const parents = (start, root) => parentsUntil(start, root, never);\n const parentsAndSelf = (start, root) => [start].concat(parents(start, root));\n\n const navigateIgnoreEmptyTextNodes = (forward, root, from) => navigateIgnore(forward, root, from, isEmptyText);\n const isBlock$1 = schema => el => schema.isBlock(name(el));\n const getClosestBlock$1 = (root, pos, schema) => find$2(parentsAndSelf(SugarElement.fromDom(pos.container()), root), isBlock$1(schema));\n const isAtBeforeAfterBlockBoundary = (forward, root, pos, schema) => navigateIgnoreEmptyTextNodes(forward, root.dom, pos).forall(newPos => getClosestBlock$1(root, pos, schema).fold(() => !isInSameBlock(newPos, pos, root.dom), fromBlock => !isInSameBlock(newPos, pos, root.dom) && contains(fromBlock, SugarElement.fromDom(newPos.container()))));\n const isAtBlockBoundary = (forward, root, pos, schema) => getClosestBlock$1(root, pos, schema).fold(() => navigateIgnoreEmptyTextNodes(forward, root.dom, pos).forall(newPos => !isInSameBlock(newPos, pos, root.dom)), parent => navigateIgnoreEmptyTextNodes(forward, parent.dom, pos).isNone());\n const isAtStartOfBlock = curry(isAtBlockBoundary, false);\n const isAtEndOfBlock = curry(isAtBlockBoundary, true);\n const isBeforeBlock = curry(isAtBeforeAfterBlockBoundary, false);\n const isAfterBlock = curry(isAtBeforeAfterBlockBoundary, true);\n\n const isBr$1 = pos => getElementFromPosition(pos).exists(isBr$5);\n const findBr = (forward, root, pos, schema) => {\n const parentBlocks = filter$5(parentsAndSelf(SugarElement.fromDom(pos.container()), root), el => schema.isBlock(name(el)));\n const scope = head(parentBlocks).getOr(root);\n return fromPosition(forward, scope.dom, pos).filter(isBr$1);\n };\n const isBeforeBr$1 = (root, pos, schema) => getElementFromPosition(pos).exists(isBr$5) || findBr(true, root, pos, schema).isSome();\n const isAfterBr = (root, pos, schema) => getElementFromPrevPosition(pos).exists(isBr$5) || findBr(false, root, pos, schema).isSome();\n const findPreviousBr = curry(findBr, false);\n const findNextBr = curry(findBr, true);\n\n const isInMiddleOfText = pos => CaretPosition.isTextPosition(pos) && !pos.isAtStart() && !pos.isAtEnd();\n const getClosestBlock = (root, pos, schema) => {\n const parentBlocks = filter$5(parentsAndSelf(SugarElement.fromDom(pos.container()), root), el => schema.isBlock(name(el)));\n return head(parentBlocks).getOr(root);\n };\n const hasSpaceBefore = (root, pos, schema) => {\n if (isInMiddleOfText(pos)) {\n return isAfterSpace(pos);\n } else {\n return isAfterSpace(pos) || prevPosition(getClosestBlock(root, pos, schema).dom, pos).exists(isAfterSpace);\n }\n };\n const hasSpaceAfter = (root, pos, schema) => {\n if (isInMiddleOfText(pos)) {\n return isBeforeSpace(pos);\n } else {\n return isBeforeSpace(pos) || nextPosition(getClosestBlock(root, pos, schema).dom, pos).exists(isBeforeSpace);\n }\n };\n const isPreValue = value => contains$2([\n 'pre',\n 'pre-wrap'\n ], value);\n const isInPre = pos => getElementFromPosition(pos).bind(elm => closest$4(elm, isElement$7)).exists(elm => isPreValue(get$7(elm, 'white-space')));\n const isAtBeginningOfBody = (root, pos) => prevPosition(root.dom, pos).isNone();\n const isAtEndOfBody = (root, pos) => nextPosition(root.dom, pos).isNone();\n const isAtLineBoundary = (root, pos, schema) => isAtBeginningOfBody(root, pos) || isAtEndOfBody(root, pos) || isAtStartOfBlock(root, pos, schema) || isAtEndOfBlock(root, pos, schema) || isAfterBr(root, pos, schema) || isBeforeBr$1(root, pos, schema);\n const isCefBlock = node => isNonNullable(node) && isContentEditableFalse$b(node) && isBlockLike(node);\n const isSiblingCefBlock = (root, direction) => container => {\n return isCefBlock(new DomTreeWalker(container, root)[direction]());\n };\n const isBeforeCefBlock = (root, pos) => {\n const nextPos = nextPosition(root.dom, pos).getOr(pos);\n const isNextCefBlock = isSiblingCefBlock(root.dom, 'next');\n return pos.isAtEnd() && (isNextCefBlock(pos.container()) || isNextCefBlock(nextPos.container()));\n };\n const isAfterCefBlock = (root, pos) => {\n const prevPos = prevPosition(root.dom, pos).getOr(pos);\n const isPrevCefBlock = isSiblingCefBlock(root.dom, 'prev');\n return pos.isAtStart() && (isPrevCefBlock(pos.container()) || isPrevCefBlock(prevPos.container()));\n };\n const needsToHaveNbsp = (root, pos, schema) => {\n if (isInPre(pos)) {\n return false;\n } else {\n return isAtLineBoundary(root, pos, schema) || hasSpaceBefore(root, pos, schema) || hasSpaceAfter(root, pos, schema);\n }\n };\n const needsToBeNbspLeft = (root, pos, schema) => {\n if (isInPre(pos)) {\n return false;\n } else {\n return isAtStartOfBlock(root, pos, schema) || isBeforeBlock(root, pos, schema) || isAfterBr(root, pos, schema) || hasSpaceBefore(root, pos, schema) || isAfterCefBlock(root, pos);\n }\n };\n const leanRight = pos => {\n const container = pos.container();\n const offset = pos.offset();\n if (isText$b(container) && offset < container.data.length) {\n return CaretPosition(container, offset + 1);\n } else {\n return pos;\n }\n };\n const needsToBeNbspRight = (root, pos, schema) => {\n if (isInPre(pos)) {\n return false;\n } else {\n return isAtEndOfBlock(root, pos, schema) || isAfterBlock(root, pos, schema) || isBeforeBr$1(root, pos, schema) || hasSpaceAfter(root, pos, schema) || isBeforeCefBlock(root, pos);\n }\n };\n const needsToBeNbsp = (root, pos, schema) => needsToBeNbspLeft(root, pos, schema) || needsToBeNbspRight(root, leanRight(pos), schema);\n const isNbspAt = (text, offset) => isNbsp(text.charAt(offset));\n const isWhiteSpaceAt = (text, offset) => isWhiteSpace(text.charAt(offset));\n const hasNbsp = pos => {\n const container = pos.container();\n return isText$b(container) && contains$1(container.data, nbsp);\n };\n const normalizeNbspMiddle = text => {\n const chars = text.split('');\n return map$3(chars, (chr, i) => {\n if (isNbsp(chr) && i > 0 && i < chars.length - 1 && isContent(chars[i - 1]) && isContent(chars[i + 1])) {\n return ' ';\n } else {\n return chr;\n }\n }).join('');\n };\n const normalizeNbspAtStart = (root, node, makeNbsp, schema) => {\n const text = node.data;\n const firstPos = CaretPosition(node, 0);\n if (!makeNbsp && isNbspAt(text, 0) && !needsToBeNbsp(root, firstPos, schema)) {\n node.data = ' ' + text.slice(1);\n return true;\n } else if (makeNbsp && isWhiteSpaceAt(text, 0) && needsToBeNbspLeft(root, firstPos, schema)) {\n node.data = nbsp + text.slice(1);\n return true;\n } else {\n return false;\n }\n };\n const normalizeNbspInMiddleOfTextNode = node => {\n const text = node.data;\n const newText = normalizeNbspMiddle(text);\n if (newText !== text) {\n node.data = newText;\n return true;\n } else {\n return false;\n }\n };\n const normalizeNbspAtEnd = (root, node, makeNbsp, schema) => {\n const text = node.data;\n const lastPos = CaretPosition(node, text.length - 1);\n if (!makeNbsp && isNbspAt(text, text.length - 1) && !needsToBeNbsp(root, lastPos, schema)) {\n node.data = text.slice(0, -1) + ' ';\n return true;\n } else if (makeNbsp && isWhiteSpaceAt(text, text.length - 1) && needsToBeNbspRight(root, lastPos, schema)) {\n node.data = text.slice(0, -1) + nbsp;\n return true;\n } else {\n return false;\n }\n };\n const normalizeNbsps$1 = (root, pos, schema) => {\n const container = pos.container();\n if (!isText$b(container)) {\n return Optional.none();\n }\n if (hasNbsp(pos)) {\n const normalized = normalizeNbspAtStart(root, container, false, schema) || normalizeNbspInMiddleOfTextNode(container) || normalizeNbspAtEnd(root, container, false, schema);\n return someIf(normalized, pos);\n } else if (needsToBeNbsp(root, pos, schema)) {\n const normalized = normalizeNbspAtStart(root, container, true, schema) || normalizeNbspAtEnd(root, container, true, schema);\n return someIf(normalized, pos);\n } else {\n return Optional.none();\n }\n };\n const normalizeNbspsInEditor = editor => {\n const root = SugarElement.fromDom(editor.getBody());\n if (editor.selection.isCollapsed()) {\n normalizeNbsps$1(root, CaretPosition.fromRangeStart(editor.selection.getRng()), editor.schema).each(pos => {\n editor.selection.setRng(pos.toRange());\n });\n }\n };\n\n const normalize$1 = (node, offset, count, schema) => {\n if (count === 0) {\n return;\n }\n const elm = SugarElement.fromDom(node);\n const root = ancestor$4(elm, el => schema.isBlock(name(el))).getOr(elm);\n const whitespace = node.data.slice(offset, offset + count);\n const isEndOfContent = offset + count >= node.data.length && needsToBeNbspRight(root, CaretPosition(node, node.data.length), schema);\n const isStartOfContent = offset === 0 && needsToBeNbspLeft(root, CaretPosition(node, 0), schema);\n node.replaceData(offset, count, normalize$4(whitespace, 4, isStartOfContent, isEndOfContent));\n };\n const normalizeWhitespaceAfter = (node, offset, schema) => {\n const content = node.data.slice(offset);\n const whitespaceCount = content.length - lTrim(content).length;\n normalize$1(node, offset, whitespaceCount, schema);\n };\n const normalizeWhitespaceBefore = (node, offset, schema) => {\n const content = node.data.slice(0, offset);\n const whitespaceCount = content.length - rTrim(content).length;\n normalize$1(node, offset - whitespaceCount, whitespaceCount, schema);\n };\n const mergeTextNodes = (prevNode, nextNode, schema, normalizeWhitespace, mergeToPrev = true) => {\n const whitespaceOffset = rTrim(prevNode.data).length;\n const newNode = mergeToPrev ? prevNode : nextNode;\n const removeNode = mergeToPrev ? nextNode : prevNode;\n if (mergeToPrev) {\n newNode.appendData(removeNode.data);\n } else {\n newNode.insertData(0, removeNode.data);\n }\n remove$4(SugarElement.fromDom(removeNode));\n if (normalizeWhitespace) {\n normalizeWhitespaceAfter(newNode, whitespaceOffset, schema);\n }\n return newNode;\n };\n\n const needsReposition = (pos, elm) => {\n const container = pos.container();\n const offset = pos.offset();\n return !CaretPosition.isTextPosition(pos) && container === elm.parentNode && offset > CaretPosition.before(elm).offset();\n };\n const reposition = (elm, pos) => needsReposition(pos, elm) ? CaretPosition(pos.container(), pos.offset() - 1) : pos;\n const beforeOrStartOf = node => isText$b(node) ? CaretPosition(node, 0) : CaretPosition.before(node);\n const afterOrEndOf = node => isText$b(node) ? CaretPosition(node, node.data.length) : CaretPosition.after(node);\n const getPreviousSiblingCaretPosition = elm => {\n if (isCaretCandidate$3(elm.previousSibling)) {\n return Optional.some(afterOrEndOf(elm.previousSibling));\n } else {\n return elm.previousSibling ? lastPositionIn(elm.previousSibling) : Optional.none();\n }\n };\n const getNextSiblingCaretPosition = elm => {\n if (isCaretCandidate$3(elm.nextSibling)) {\n return Optional.some(beforeOrStartOf(elm.nextSibling));\n } else {\n return elm.nextSibling ? firstPositionIn(elm.nextSibling) : Optional.none();\n }\n };\n const findCaretPositionBackwardsFromElm = (rootElement, elm) => {\n return Optional.from(elm.previousSibling ? elm.previousSibling : elm.parentNode).bind(node => prevPosition(rootElement, CaretPosition.before(node))).orThunk(() => nextPosition(rootElement, CaretPosition.after(elm)));\n };\n const findCaretPositionForwardsFromElm = (rootElement, elm) => nextPosition(rootElement, CaretPosition.after(elm)).orThunk(() => prevPosition(rootElement, CaretPosition.before(elm)));\n const findCaretPositionBackwards = (rootElement, elm) => getPreviousSiblingCaretPosition(elm).orThunk(() => getNextSiblingCaretPosition(elm)).orThunk(() => findCaretPositionBackwardsFromElm(rootElement, elm));\n const findCaretPositionForward = (rootElement, elm) => getNextSiblingCaretPosition(elm).orThunk(() => getPreviousSiblingCaretPosition(elm)).orThunk(() => findCaretPositionForwardsFromElm(rootElement, elm));\n const findCaretPosition = (forward, rootElement, elm) => forward ? findCaretPositionForward(rootElement, elm) : findCaretPositionBackwards(rootElement, elm);\n const findCaretPosOutsideElmAfterDelete = (forward, rootElement, elm) => findCaretPosition(forward, rootElement, elm).map(curry(reposition, elm));\n const setSelection$1 = (editor, forward, pos) => {\n pos.fold(() => {\n editor.focus();\n }, pos => {\n editor.selection.setRng(pos.toRange(), forward);\n });\n };\n const eqRawNode = rawNode => elm => elm.dom === rawNode;\n const isBlock = (editor, elm) => elm && has$2(editor.schema.getBlockElements(), name(elm));\n const paddEmptyBlock = (schema, elm, preserveEmptyCaret) => {\n if (isEmpty$2(schema, elm)) {\n const br = SugarElement.fromHtml('
');\n if (preserveEmptyCaret) {\n each$e(children$1(elm), node => {\n if (!isEmptyCaretFormatElement(node)) {\n remove$4(node);\n }\n });\n } else {\n empty(elm);\n }\n append$1(elm, br);\n return Optional.some(CaretPosition.before(br.dom));\n } else {\n return Optional.none();\n }\n };\n const deleteNormalized = (elm, afterDeletePosOpt, schema, normalizeWhitespace) => {\n const prevTextOpt = prevSibling(elm).filter(isText$c);\n const nextTextOpt = nextSibling(elm).filter(isText$c);\n remove$4(elm);\n return lift3(prevTextOpt, nextTextOpt, afterDeletePosOpt, (prev, next, pos) => {\n const prevNode = prev.dom, nextNode = next.dom;\n const offset = prevNode.data.length;\n mergeTextNodes(prevNode, nextNode, schema, normalizeWhitespace);\n return pos.container() === nextNode ? CaretPosition(prevNode, offset) : pos;\n }).orThunk(() => {\n if (normalizeWhitespace) {\n prevTextOpt.each(elm => normalizeWhitespaceBefore(elm.dom, elm.dom.length, schema));\n nextTextOpt.each(elm => normalizeWhitespaceAfter(elm.dom, 0, schema));\n }\n return afterDeletePosOpt;\n });\n };\n const isInlineElement = (editor, element) => has$2(editor.schema.getTextInlineElements(), name(element));\n const deleteElement$2 = (editor, forward, elm, moveCaret = true, preserveEmptyCaret = false) => {\n const afterDeletePos = findCaretPosOutsideElmAfterDelete(forward, editor.getBody(), elm.dom);\n const parentBlock = ancestor$4(elm, curry(isBlock, editor), eqRawNode(editor.getBody()));\n const normalizedAfterDeletePos = deleteNormalized(elm, afterDeletePos, editor.schema, isInlineElement(editor, elm));\n if (editor.dom.isEmpty(editor.getBody())) {\n editor.setContent('');\n editor.selection.setCursorLocation();\n } else {\n parentBlock.bind(elm => paddEmptyBlock(editor.schema, elm, preserveEmptyCaret)).fold(() => {\n if (moveCaret) {\n setSelection$1(editor, forward, normalizedAfterDeletePos);\n }\n }, paddPos => {\n if (moveCaret) {\n setSelection$1(editor, forward, Optional.some(paddPos));\n }\n });\n }\n };\n\n const strongRtl = /[\\u0591-\\u07FF\\uFB1D-\\uFDFF\\uFE70-\\uFEFC]/;\n const hasStrongRtl = text => strongRtl.test(text);\n\n const isInlineTarget = (editor, elm) => is$1(SugarElement.fromDom(elm), getInlineBoundarySelector(editor)) && !isTransparentBlock(editor.schema, elm) && editor.dom.isEditable(elm);\n const isRtl = element => {\n var _a;\n return DOMUtils.DOM.getStyle(element, 'direction', true) === 'rtl' || hasStrongRtl((_a = element.textContent) !== null && _a !== void 0 ? _a : '');\n };\n const findInlineParents = (isInlineTarget, rootNode, pos) => filter$5(DOMUtils.DOM.getParents(pos.container(), '*', rootNode), isInlineTarget);\n const findRootInline = (isInlineTarget, rootNode, pos) => {\n const parents = findInlineParents(isInlineTarget, rootNode, pos);\n return Optional.from(parents[parents.length - 1]);\n };\n const hasSameParentBlock = (rootNode, node1, node2) => {\n const block1 = getParentBlock$3(node1, rootNode);\n const block2 = getParentBlock$3(node2, rootNode);\n return isNonNullable(block1) && block1 === block2;\n };\n const isAtZwsp = pos => isBeforeInline(pos) || isAfterInline(pos);\n const normalizePosition = (forward, pos) => {\n const container = pos.container(), offset = pos.offset();\n if (forward) {\n if (isCaretContainerInline(container)) {\n if (isText$b(container.nextSibling)) {\n return CaretPosition(container.nextSibling, 0);\n } else {\n return CaretPosition.after(container);\n }\n } else {\n return isBeforeInline(pos) ? CaretPosition(container, offset + 1) : pos;\n }\n } else {\n if (isCaretContainerInline(container)) {\n if (isText$b(container.previousSibling)) {\n return CaretPosition(container.previousSibling, container.previousSibling.data.length);\n } else {\n return CaretPosition.before(container);\n }\n } else {\n return isAfterInline(pos) ? CaretPosition(container, offset - 1) : pos;\n }\n }\n };\n const normalizeForwards = curry(normalizePosition, true);\n const normalizeBackwards = curry(normalizePosition, false);\n\n const execCommandIgnoreInputEvents = (editor, command) => {\n const inputBlocker = e => e.stopImmediatePropagation();\n editor.on('beforeinput input', inputBlocker, true);\n editor.getDoc().execCommand(command);\n editor.off('beforeinput input', inputBlocker);\n };\n const execEditorDeleteCommand = editor => {\n editor.execCommand('delete');\n };\n const execNativeDeleteCommand = editor => execCommandIgnoreInputEvents(editor, 'Delete');\n const execNativeForwardDeleteCommand = editor => execCommandIgnoreInputEvents(editor, 'ForwardDelete');\n const isBeforeRoot = rootNode => elm => is$2(parent(elm), rootNode, eq);\n const isTextBlockOrListItem = element => isTextBlock$2(element) || isListItem$1(element);\n const getParentBlock$2 = (rootNode, elm) => {\n if (contains(rootNode, elm)) {\n return closest$4(elm, isTextBlockOrListItem, isBeforeRoot(rootNode));\n } else {\n return Optional.none();\n }\n };\n const paddEmptyBody = (editor, moveSelection = true) => {\n if (editor.dom.isEmpty(editor.getBody())) {\n editor.setContent('', { no_selection: !moveSelection });\n }\n };\n const willDeleteLastPositionInElement = (forward, fromPos, elm) => lift2(firstPositionIn(elm), lastPositionIn(elm), (firstPos, lastPos) => {\n const normalizedFirstPos = normalizePosition(true, firstPos);\n const normalizedLastPos = normalizePosition(false, lastPos);\n const normalizedFromPos = normalizePosition(false, fromPos);\n if (forward) {\n return nextPosition(elm, normalizedFromPos).exists(nextPos => nextPos.isEqual(normalizedLastPos) && fromPos.isEqual(normalizedFirstPos));\n } else {\n return prevPosition(elm, normalizedFromPos).exists(prevPos => prevPos.isEqual(normalizedFirstPos) && fromPos.isEqual(normalizedLastPos));\n }\n }).getOr(true);\n const freefallRtl = root => {\n const child = isComment$1(root) ? prevSibling(root) : lastChild(root);\n return child.bind(freefallRtl).orThunk(() => Optional.some(root));\n };\n const deleteRangeContents = (editor, rng, root, moveSelection = true) => {\n var _a;\n rng.deleteContents();\n const lastNode = freefallRtl(root).getOr(root);\n const lastBlock = SugarElement.fromDom((_a = editor.dom.getParent(lastNode.dom, editor.dom.isBlock)) !== null && _a !== void 0 ? _a : root.dom);\n if (lastBlock.dom === editor.getBody()) {\n paddEmptyBody(editor, moveSelection);\n } else if (isEmpty$2(editor.schema, lastBlock, { checkRootAsContent: false })) {\n fillWithPaddingBr(lastBlock);\n if (moveSelection) {\n editor.selection.setCursorLocation(lastBlock.dom, 0);\n }\n }\n if (!eq(root, lastBlock)) {\n const additionalCleanupNodes = is$2(parent(lastBlock), root) ? [] : siblings(lastBlock);\n each$e(additionalCleanupNodes.concat(children$1(root)), node => {\n if (!eq(node, lastBlock) && !contains(node, lastBlock) && isEmpty$2(editor.schema, node)) {\n remove$4(node);\n }\n });\n }\n };\n\n const isRootFromElement = root => cur => eq(root, cur);\n const getTableCells = table => descendants(table, 'td,th');\n const getTable$1 = (node, isRoot) => getClosestTable(SugarElement.fromDom(node), isRoot);\n const selectionInTableWithNestedTable = details => {\n return lift2(details.startTable, details.endTable, (startTable, endTable) => {\n const isStartTableParentOfEndTable = descendant(startTable, t => eq(t, endTable));\n const isEndTableParentOfStartTable = descendant(endTable, t => eq(t, startTable));\n return !isStartTableParentOfEndTable && !isEndTableParentOfStartTable ? details : {\n ...details,\n startTable: isStartTableParentOfEndTable ? Optional.none() : details.startTable,\n endTable: isEndTableParentOfStartTable ? Optional.none() : details.endTable,\n isSameTable: false,\n isMultiTable: false\n };\n }).getOr(details);\n };\n const adjustQuirksInDetails = details => {\n return selectionInTableWithNestedTable(details);\n };\n const getTableDetailsFromRange = (rng, isRoot) => {\n const startTable = getTable$1(rng.startContainer, isRoot);\n const endTable = getTable$1(rng.endContainer, isRoot);\n const isStartInTable = startTable.isSome();\n const isEndInTable = endTable.isSome();\n const isSameTable = lift2(startTable, endTable, eq).getOr(false);\n const isMultiTable = !isSameTable && isStartInTable && isEndInTable;\n return adjustQuirksInDetails({\n startTable,\n endTable,\n isStartInTable,\n isEndInTable,\n isSameTable,\n isMultiTable\n });\n };\n\n const tableCellRng = (start, end) => ({\n start,\n end\n });\n const tableSelection = (rng, table, cells) => ({\n rng,\n table,\n cells\n });\n const deleteAction = Adt.generate([\n {\n singleCellTable: [\n 'rng',\n 'cell'\n ]\n },\n { fullTable: ['table'] },\n {\n partialTable: [\n 'cells',\n 'outsideDetails'\n ]\n },\n {\n multiTable: [\n 'startTableCells',\n 'endTableCells',\n 'betweenRng'\n ]\n }\n ]);\n const getClosestCell$1 = (container, isRoot) => closest$3(SugarElement.fromDom(container), 'td,th', isRoot);\n const isExpandedCellRng = cellRng => !eq(cellRng.start, cellRng.end);\n const getTableFromCellRng = (cellRng, isRoot) => getClosestTable(cellRng.start, isRoot).bind(startParentTable => getClosestTable(cellRng.end, isRoot).bind(endParentTable => someIf(eq(startParentTable, endParentTable), startParentTable)));\n const isSingleCellTable = (cellRng, isRoot) => !isExpandedCellRng(cellRng) && getTableFromCellRng(cellRng, isRoot).exists(table => {\n const rows = table.dom.rows;\n return rows.length === 1 && rows[0].cells.length === 1;\n });\n const getCellRng = (rng, isRoot) => {\n const startCell = getClosestCell$1(rng.startContainer, isRoot);\n const endCell = getClosestCell$1(rng.endContainer, isRoot);\n return lift2(startCell, endCell, tableCellRng);\n };\n const getCellRangeFromStartTable = isRoot => startCell => getClosestTable(startCell, isRoot).bind(table => last$2(getTableCells(table)).map(endCell => tableCellRng(startCell, endCell)));\n const getCellRangeFromEndTable = isRoot => endCell => getClosestTable(endCell, isRoot).bind(table => head(getTableCells(table)).map(startCell => tableCellRng(startCell, endCell)));\n const getTableSelectionFromCellRng = isRoot => cellRng => getTableFromCellRng(cellRng, isRoot).map(table => tableSelection(cellRng, table, getTableCells(table)));\n const getTableSelections = (cellRng, selectionDetails, rng, isRoot) => {\n if (rng.collapsed || !cellRng.forall(isExpandedCellRng)) {\n return Optional.none();\n } else if (selectionDetails.isSameTable) {\n const sameTableSelection = cellRng.bind(getTableSelectionFromCellRng(isRoot));\n return Optional.some({\n start: sameTableSelection,\n end: sameTableSelection\n });\n } else {\n const startCell = getClosestCell$1(rng.startContainer, isRoot);\n const endCell = getClosestCell$1(rng.endContainer, isRoot);\n const startTableSelection = startCell.bind(getCellRangeFromStartTable(isRoot)).bind(getTableSelectionFromCellRng(isRoot));\n const endTableSelection = endCell.bind(getCellRangeFromEndTable(isRoot)).bind(getTableSelectionFromCellRng(isRoot));\n return Optional.some({\n start: startTableSelection,\n end: endTableSelection\n });\n }\n };\n const getCellIndex = (cells, cell) => findIndex$2(cells, x => eq(x, cell));\n const getSelectedCells = tableSelection => lift2(getCellIndex(tableSelection.cells, tableSelection.rng.start), getCellIndex(tableSelection.cells, tableSelection.rng.end), (startIndex, endIndex) => tableSelection.cells.slice(startIndex, endIndex + 1));\n const isSingleCellTableContentSelected = (optCellRng, rng, isRoot) => optCellRng.exists(cellRng => isSingleCellTable(cellRng, isRoot) && hasAllContentsSelected(cellRng.start, rng));\n const unselectCells = (rng, selectionDetails) => {\n const {startTable, endTable} = selectionDetails;\n const otherContentRng = rng.cloneRange();\n startTable.each(table => otherContentRng.setStartAfter(table.dom));\n endTable.each(table => otherContentRng.setEndBefore(table.dom));\n return otherContentRng;\n };\n const handleSingleTable = (cellRng, selectionDetails, rng, isRoot) => getTableSelections(cellRng, selectionDetails, rng, isRoot).bind(({start, end}) => start.or(end)).bind(tableSelection => {\n const {isSameTable} = selectionDetails;\n const selectedCells = getSelectedCells(tableSelection).getOr([]);\n if (isSameTable && tableSelection.cells.length === selectedCells.length) {\n return Optional.some(deleteAction.fullTable(tableSelection.table));\n } else if (selectedCells.length > 0) {\n if (isSameTable) {\n return Optional.some(deleteAction.partialTable(selectedCells, Optional.none()));\n } else {\n const otherContentRng = unselectCells(rng, selectionDetails);\n return Optional.some(deleteAction.partialTable(selectedCells, Optional.some({\n ...selectionDetails,\n rng: otherContentRng\n })));\n }\n } else {\n return Optional.none();\n }\n });\n const handleMultiTable = (cellRng, selectionDetails, rng, isRoot) => getTableSelections(cellRng, selectionDetails, rng, isRoot).bind(({start, end}) => {\n const startTableSelectedCells = start.bind(getSelectedCells).getOr([]);\n const endTableSelectedCells = end.bind(getSelectedCells).getOr([]);\n if (startTableSelectedCells.length > 0 && endTableSelectedCells.length > 0) {\n const otherContentRng = unselectCells(rng, selectionDetails);\n return Optional.some(deleteAction.multiTable(startTableSelectedCells, endTableSelectedCells, otherContentRng));\n } else {\n return Optional.none();\n }\n });\n const getActionFromRange = (root, rng) => {\n const isRoot = isRootFromElement(root);\n const optCellRng = getCellRng(rng, isRoot);\n const selectionDetails = getTableDetailsFromRange(rng, isRoot);\n if (isSingleCellTableContentSelected(optCellRng, rng, isRoot)) {\n return optCellRng.map(cellRng => deleteAction.singleCellTable(rng, cellRng.start));\n } else if (selectionDetails.isMultiTable) {\n return handleMultiTable(optCellRng, selectionDetails, rng, isRoot);\n } else {\n return handleSingleTable(optCellRng, selectionDetails, rng, isRoot);\n }\n };\n\n const cleanCells = cells => each$e(cells, cell => {\n remove$9(cell, 'contenteditable');\n fillWithPaddingBr(cell);\n });\n const getOutsideBlock = (editor, container) => Optional.from(editor.dom.getParent(container, editor.dom.isBlock)).map(SugarElement.fromDom);\n const handleEmptyBlock = (editor, startInTable, emptyBlock) => {\n emptyBlock.each(block => {\n if (startInTable) {\n remove$4(block);\n } else {\n fillWithPaddingBr(block);\n editor.selection.setCursorLocation(block.dom, 0);\n }\n });\n };\n const deleteContentInsideCell = (editor, cell, rng, isFirstCellInSelection) => {\n const insideTableRng = rng.cloneRange();\n if (isFirstCellInSelection) {\n insideTableRng.setStart(rng.startContainer, rng.startOffset);\n insideTableRng.setEndAfter(cell.dom.lastChild);\n } else {\n insideTableRng.setStartBefore(cell.dom.firstChild);\n insideTableRng.setEnd(rng.endContainer, rng.endOffset);\n }\n deleteCellContents(editor, insideTableRng, cell, false).each(action => action());\n };\n const collapseAndRestoreCellSelection = editor => {\n const selectedCells = getCellsFromEditor(editor);\n const selectedNode = SugarElement.fromDom(editor.selection.getNode());\n if (isTableCell$3(selectedNode.dom) && isEmpty$2(editor.schema, selectedNode)) {\n editor.selection.setCursorLocation(selectedNode.dom, 0);\n } else {\n editor.selection.collapse(true);\n }\n if (selectedCells.length > 1 && exists(selectedCells, cell => eq(cell, selectedNode))) {\n set$4(selectedNode, 'data-mce-selected', '1');\n }\n };\n const emptySingleTableCells = (editor, cells, outsideDetails) => Optional.some(() => {\n const editorRng = editor.selection.getRng();\n const cellsToClean = outsideDetails.bind(({rng, isStartInTable}) => {\n const outsideBlock = getOutsideBlock(editor, isStartInTable ? rng.endContainer : rng.startContainer);\n rng.deleteContents();\n handleEmptyBlock(editor, isStartInTable, outsideBlock.filter(curry(isEmpty$2, editor.schema)));\n const endPointCell = isStartInTable ? cells[0] : cells[cells.length - 1];\n deleteContentInsideCell(editor, endPointCell, editorRng, isStartInTable);\n if (!isEmpty$2(editor.schema, endPointCell)) {\n return Optional.some(isStartInTable ? cells.slice(1) : cells.slice(0, -1));\n } else {\n return Optional.none();\n }\n }).getOr(cells);\n cleanCells(cellsToClean);\n collapseAndRestoreCellSelection(editor);\n });\n const emptyMultiTableCells = (editor, startTableCells, endTableCells, betweenRng) => Optional.some(() => {\n const rng = editor.selection.getRng();\n const startCell = startTableCells[0];\n const endCell = endTableCells[endTableCells.length - 1];\n deleteContentInsideCell(editor, startCell, rng, true);\n deleteContentInsideCell(editor, endCell, rng, false);\n const startTableCellsToClean = isEmpty$2(editor.schema, startCell) ? startTableCells : startTableCells.slice(1);\n const endTableCellsToClean = isEmpty$2(editor.schema, endCell) ? endTableCells : endTableCells.slice(0, -1);\n cleanCells(startTableCellsToClean.concat(endTableCellsToClean));\n betweenRng.deleteContents();\n collapseAndRestoreCellSelection(editor);\n });\n const deleteCellContents = (editor, rng, cell, moveSelection = true) => Optional.some(() => {\n deleteRangeContents(editor, rng, cell, moveSelection);\n });\n const deleteTableElement = (editor, table) => Optional.some(() => deleteElement$2(editor, false, table));\n const deleteCellRange = (editor, rootElm, rng) => getActionFromRange(rootElm, rng).bind(action => action.fold(curry(deleteCellContents, editor), curry(deleteTableElement, editor), curry(emptySingleTableCells, editor), curry(emptyMultiTableCells, editor)));\n const deleteCaptionRange = (editor, caption) => emptyElement(editor, caption);\n const deleteTableRange = (editor, rootElm, rng, startElm) => getParentCaption(rootElm, startElm).fold(() => deleteCellRange(editor, rootElm, rng), caption => deleteCaptionRange(editor, caption));\n const deleteRange$3 = (editor, startElm, selectedCells) => {\n const rootNode = SugarElement.fromDom(editor.getBody());\n const rng = editor.selection.getRng();\n return selectedCells.length !== 0 ? emptySingleTableCells(editor, selectedCells, Optional.none()) : deleteTableRange(editor, rootNode, rng, startElm);\n };\n const getParentCell = (rootElm, elm) => find$2(parentsAndSelf(elm, rootElm), isTableCell$2);\n const getParentCaption = (rootElm, elm) => find$2(parentsAndSelf(elm, rootElm), isTag('caption'));\n const deleteBetweenCells = (editor, rootElm, forward, fromCell, from) => navigate(forward, editor.getBody(), from).bind(to => getParentCell(rootElm, SugarElement.fromDom(to.getNode())).bind(toCell => eq(toCell, fromCell) ? Optional.none() : Optional.some(noop)));\n const emptyElement = (editor, elm) => Optional.some(() => {\n fillWithPaddingBr(elm);\n editor.selection.setCursorLocation(elm.dom, 0);\n });\n const isDeleteOfLastCharPos = (fromCaption, forward, from, to) => firstPositionIn(fromCaption.dom).bind(first => lastPositionIn(fromCaption.dom).map(last => forward ? from.isEqual(first) && to.isEqual(last) : from.isEqual(last) && to.isEqual(first))).getOr(true);\n const emptyCaretCaption = (editor, elm) => emptyElement(editor, elm);\n const validateCaretCaption = (rootElm, fromCaption, to) => getParentCaption(rootElm, SugarElement.fromDom(to.getNode())).fold(() => Optional.some(noop), toCaption => someIf(!eq(toCaption, fromCaption), noop));\n const deleteCaretInsideCaption = (editor, rootElm, forward, fromCaption, from) => navigate(forward, editor.getBody(), from).fold(() => Optional.some(noop), to => isDeleteOfLastCharPos(fromCaption, forward, from, to) ? emptyCaretCaption(editor, fromCaption) : validateCaretCaption(rootElm, fromCaption, to));\n const deleteCaretCells = (editor, forward, rootElm, startElm) => {\n const from = CaretPosition.fromRangeStart(editor.selection.getRng());\n return getParentCell(rootElm, startElm).bind(fromCell => isEmpty$2(editor.schema, fromCell, { checkRootAsContent: false }) ? emptyElement(editor, fromCell) : deleteBetweenCells(editor, rootElm, forward, fromCell, from));\n };\n const deleteCaretCaption = (editor, forward, rootElm, fromCaption) => {\n const from = CaretPosition.fromRangeStart(editor.selection.getRng());\n return isEmpty$2(editor.schema, fromCaption) ? emptyElement(editor, fromCaption) : deleteCaretInsideCaption(editor, rootElm, forward, fromCaption, from);\n };\n const isNearTable = (forward, pos) => forward ? isBeforeTable(pos) : isAfterTable(pos);\n const isBeforeOrAfterTable = (editor, forward) => {\n const fromPos = CaretPosition.fromRangeStart(editor.selection.getRng());\n return isNearTable(forward, fromPos) || fromPosition(forward, editor.getBody(), fromPos).exists(pos => isNearTable(forward, pos));\n };\n const deleteCaret$3 = (editor, forward, startElm) => {\n const rootElm = SugarElement.fromDom(editor.getBody());\n return getParentCaption(rootElm, startElm).fold(() => deleteCaretCells(editor, forward, rootElm, startElm).orThunk(() => someIf(isBeforeOrAfterTable(editor, forward), noop)), fromCaption => deleteCaretCaption(editor, forward, rootElm, fromCaption));\n };\n const backspaceDelete$b = (editor, forward) => {\n const startElm = SugarElement.fromDom(editor.selection.getStart(true));\n const cells = getCellsFromEditor(editor);\n return editor.selection.isCollapsed() && cells.length === 0 ? deleteCaret$3(editor, forward, startElm) : deleteRange$3(editor, startElm, cells);\n };\n\n const getContentEditableRoot$1 = (root, node) => {\n let tempNode = node;\n while (tempNode && tempNode !== root) {\n if (isContentEditableTrue$3(tempNode) || isContentEditableFalse$b(tempNode)) {\n return tempNode;\n }\n tempNode = tempNode.parentNode;\n }\n return null;\n };\n\n const internalAttributesPrefixes = [\n 'data-ephox-',\n 'data-mce-',\n 'data-alloy-',\n 'data-snooker-',\n '_'\n ];\n const each$9 = Tools.each;\n const ElementUtils = editor => {\n const dom = editor.dom;\n const internalAttributes = new Set(editor.serializer.getTempAttrs());\n const compare = (node1, node2) => {\n if (node1.nodeName !== node2.nodeName || node1.nodeType !== node2.nodeType) {\n return false;\n }\n const getAttribs = node => {\n const attribs = {};\n each$9(dom.getAttribs(node), attr => {\n const name = attr.nodeName.toLowerCase();\n if (name !== 'style' && !isAttributeInternal(name)) {\n attribs[name] = dom.getAttrib(node, name);\n }\n });\n return attribs;\n };\n const compareObjects = (obj1, obj2) => {\n for (const name in obj1) {\n if (has$2(obj1, name)) {\n const value = obj2[name];\n if (isUndefined(value)) {\n return false;\n }\n if (obj1[name] !== value) {\n return false;\n }\n delete obj2[name];\n }\n }\n for (const name in obj2) {\n if (has$2(obj2, name)) {\n return false;\n }\n }\n return true;\n };\n if (isElement$6(node1) && isElement$6(node2)) {\n if (!compareObjects(getAttribs(node1), getAttribs(node2))) {\n return false;\n }\n if (!compareObjects(dom.parseStyle(dom.getAttrib(node1, 'style')), dom.parseStyle(dom.getAttrib(node2, 'style')))) {\n return false;\n }\n }\n return !isBookmarkNode$1(node1) && !isBookmarkNode$1(node2);\n };\n const isAttributeInternal = attributeName => exists(internalAttributesPrefixes, value => startsWith(attributeName, value)) || internalAttributes.has(attributeName);\n return {\n compare,\n isAttributeInternal\n };\n };\n\n const isHeading = node => [\n 'h1',\n 'h2',\n 'h3',\n 'h4',\n 'h5',\n 'h6'\n ].includes(node.name);\n const isSummary = node => node.name === 'summary';\n\n const traverse = (root, fn) => {\n let node = root;\n while (node = node.walk()) {\n fn(node);\n }\n };\n const matchNode$1 = (nodeFilters, attributeFilters, node, matches) => {\n const name = node.name;\n for (let ni = 0, nl = nodeFilters.length; ni < nl; ni++) {\n const filter = nodeFilters[ni];\n if (filter.name === name) {\n const match = matches.nodes[name];\n if (match) {\n match.nodes.push(node);\n } else {\n matches.nodes[name] = {\n filter,\n nodes: [node]\n };\n }\n }\n }\n if (node.attributes) {\n for (let ai = 0, al = attributeFilters.length; ai < al; ai++) {\n const filter = attributeFilters[ai];\n const attrName = filter.name;\n if (attrName in node.attributes.map) {\n const match = matches.attributes[attrName];\n if (match) {\n match.nodes.push(node);\n } else {\n matches.attributes[attrName] = {\n filter,\n nodes: [node]\n };\n }\n }\n }\n }\n };\n const findMatchingNodes = (nodeFilters, attributeFilters, node) => {\n const matches = {\n nodes: {},\n attributes: {}\n };\n if (node.firstChild) {\n traverse(node, childNode => {\n matchNode$1(nodeFilters, attributeFilters, childNode, matches);\n });\n }\n return matches;\n };\n const runFilters = (matches, args) => {\n const run = (matchRecord, filteringAttributes) => {\n each$d(matchRecord, match => {\n const nodes = from(match.nodes);\n each$e(match.filter.callbacks, callback => {\n for (let i = nodes.length - 1; i >= 0; i--) {\n const node = nodes[i];\n const valueMatches = filteringAttributes ? node.attr(match.filter.name) !== undefined : node.name === match.filter.name;\n if (!valueMatches || isNullable(node.parent)) {\n nodes.splice(i, 1);\n }\n }\n if (nodes.length > 0) {\n callback(nodes, match.filter.name, args);\n }\n });\n });\n };\n run(matches.nodes, false);\n run(matches.attributes, true);\n };\n const filter$2 = (nodeFilters, attributeFilters, node, args = {}) => {\n const matches = findMatchingNodes(nodeFilters, attributeFilters, node);\n runFilters(matches, args);\n };\n\n const paddEmptyNode = (settings, args, isBlock, node) => {\n const brPreferred = settings.pad_empty_with_br || args.insert;\n if (brPreferred && isBlock(node)) {\n const astNode = new AstNode('br', 1);\n if (args.insert) {\n astNode.attr('data-mce-bogus', '1');\n }\n node.empty().append(astNode);\n } else {\n node.empty().append(new AstNode('#text', 3)).value = nbsp;\n }\n };\n const isPaddedWithNbsp = node => {\n var _a;\n return hasOnlyChild(node, '#text') && ((_a = node === null || node === void 0 ? void 0 : node.firstChild) === null || _a === void 0 ? void 0 : _a.value) === nbsp;\n };\n const hasOnlyChild = (node, name) => {\n const firstChild = node === null || node === void 0 ? void 0 : node.firstChild;\n return isNonNullable(firstChild) && firstChild === node.lastChild && firstChild.name === name;\n };\n const isPadded = (schema, node) => {\n const rule = schema.getElementRule(node.name);\n return (rule === null || rule === void 0 ? void 0 : rule.paddEmpty) === true;\n };\n const isEmpty = (schema, nonEmptyElements, whitespaceElements, node) => node.isEmpty(nonEmptyElements, whitespaceElements, node => isPadded(schema, node));\n const isLineBreakNode = (node, isBlock) => isNonNullable(node) && (isBlock(node) || node.name === 'br');\n const findClosestEditingHost = scope => {\n let editableNode;\n for (let node = scope; node; node = node.parent) {\n const contentEditable = node.attr('contenteditable');\n if (contentEditable === 'false') {\n break;\n } else if (contentEditable === 'true') {\n editableNode = node;\n }\n }\n return Optional.from(editableNode);\n };\n\n const removeOrUnwrapInvalidNode = (node, schema, originalNodeParent = node.parent) => {\n if (schema.getSpecialElements()[node.name]) {\n node.empty().remove();\n } else {\n const children = node.children();\n for (const childNode of children) {\n if (originalNodeParent && !schema.isValidChild(originalNodeParent.name, childNode.name)) {\n removeOrUnwrapInvalidNode(childNode, schema, originalNodeParent);\n }\n }\n node.unwrap();\n }\n };\n const cleanInvalidNodes = (nodes, schema, rootNode, onCreate = noop) => {\n const textBlockElements = schema.getTextBlockElements();\n const nonEmptyElements = schema.getNonEmptyElements();\n const whitespaceElements = schema.getWhitespaceElements();\n const nonSplittableElements = Tools.makeMap('tr,td,th,tbody,thead,tfoot,table,summary');\n const fixed = new Set();\n const isSplittableElement = node => node !== rootNode && !nonSplittableElements[node.name];\n for (let ni = 0; ni < nodes.length; ni++) {\n const node = nodes[ni];\n let parent;\n let newParent;\n let tempNode;\n if (!node.parent || fixed.has(node)) {\n continue;\n }\n if (textBlockElements[node.name] && node.parent.name === 'li') {\n let sibling = node.next;\n while (sibling) {\n if (textBlockElements[sibling.name]) {\n sibling.name = 'li';\n fixed.add(sibling);\n node.parent.insert(sibling, node.parent);\n } else {\n break;\n }\n sibling = sibling.next;\n }\n node.unwrap();\n continue;\n }\n const parents = [node];\n for (parent = node.parent; parent && !schema.isValidChild(parent.name, node.name) && isSplittableElement(parent); parent = parent.parent) {\n parents.push(parent);\n }\n if (parent && parents.length > 1) {\n if (!isInvalid(schema, node, parent)) {\n parents.reverse();\n newParent = parents[0].clone();\n onCreate(newParent);\n let currentNode = newParent;\n for (let i = 0; i < parents.length - 1; i++) {\n if (schema.isValidChild(currentNode.name, parents[i].name) && i > 0) {\n tempNode = parents[i].clone();\n onCreate(tempNode);\n currentNode.append(tempNode);\n } else {\n tempNode = currentNode;\n }\n for (let childNode = parents[i].firstChild; childNode && childNode !== parents[i + 1];) {\n const nextNode = childNode.next;\n tempNode.append(childNode);\n childNode = nextNode;\n }\n currentNode = tempNode;\n }\n if (!isEmpty(schema, nonEmptyElements, whitespaceElements, newParent)) {\n parent.insert(newParent, parents[0], true);\n parent.insert(node, newParent);\n } else {\n parent.insert(node, parents[0], true);\n }\n parent = parents[0];\n if (isEmpty(schema, nonEmptyElements, whitespaceElements, parent) || hasOnlyChild(parent, 'br')) {\n parent.empty().remove();\n }\n } else {\n removeOrUnwrapInvalidNode(node, schema);\n }\n } else if (node.parent) {\n if (node.name === 'li') {\n let sibling = node.prev;\n if (sibling && (sibling.name === 'ul' || sibling.name === 'ol')) {\n sibling.append(node);\n continue;\n }\n sibling = node.next;\n if (sibling && (sibling.name === 'ul' || sibling.name === 'ol') && sibling.firstChild) {\n sibling.insert(node, sibling.firstChild, true);\n continue;\n }\n const wrapper = new AstNode('ul', 1);\n onCreate(wrapper);\n node.wrap(wrapper);\n continue;\n }\n if (schema.isValidChild(node.parent.name, 'div') && schema.isValidChild('div', node.name)) {\n const wrapper = new AstNode('div', 1);\n onCreate(wrapper);\n node.wrap(wrapper);\n } else {\n removeOrUnwrapInvalidNode(node, schema);\n }\n }\n }\n };\n const hasClosest = (node, parentName) => {\n let tempNode = node;\n while (tempNode) {\n if (tempNode.name === parentName) {\n return true;\n }\n tempNode = tempNode.parent;\n }\n return false;\n };\n const isInvalid = (schema, node, parent = node.parent) => {\n if (!parent) {\n return false;\n }\n if (schema.children[node.name] && !schema.isValidChild(parent.name, node.name)) {\n return true;\n }\n if (node.name === 'a' && hasClosest(parent, 'a')) {\n return true;\n }\n if (isSummary(parent) && isHeading(node)) {\n return !((parent === null || parent === void 0 ? void 0 : parent.firstChild) === node && (parent === null || parent === void 0 ? void 0 : parent.lastChild) === node);\n }\n return false;\n };\n\n const createRange = (sc, so, ec, eo) => {\n const rng = document.createRange();\n rng.setStart(sc, so);\n rng.setEnd(ec, eo);\n return rng;\n };\n const normalizeBlockSelectionRange = rng => {\n const startPos = CaretPosition.fromRangeStart(rng);\n const endPos = CaretPosition.fromRangeEnd(rng);\n const rootNode = rng.commonAncestorContainer;\n return fromPosition(false, rootNode, endPos).map(newEndPos => {\n if (!isInSameBlock(startPos, endPos, rootNode) && isInSameBlock(startPos, newEndPos, rootNode)) {\n return createRange(startPos.container(), startPos.offset(), newEndPos.container(), newEndPos.offset());\n } else {\n return rng;\n }\n }).getOr(rng);\n };\n const normalize = rng => rng.collapsed ? rng : normalizeBlockSelectionRange(rng);\n\n const hasOnlyOneChild$1 = node => {\n return isNonNullable(node.firstChild) && node.firstChild === node.lastChild;\n };\n const isPaddingNode = node => {\n return node.name === 'br' || node.value === nbsp;\n };\n const isPaddedEmptyBlock = (schema, node) => {\n const blockElements = schema.getBlockElements();\n return blockElements[node.name] && hasOnlyOneChild$1(node) && isPaddingNode(node.firstChild);\n };\n const isEmptyFragmentElement = (schema, node) => {\n const nonEmptyElements = schema.getNonEmptyElements();\n return isNonNullable(node) && (node.isEmpty(nonEmptyElements) || isPaddedEmptyBlock(schema, node));\n };\n const isListFragment = (schema, fragment) => {\n let firstChild = fragment.firstChild;\n let lastChild = fragment.lastChild;\n if (firstChild && firstChild.name === 'meta') {\n firstChild = firstChild.next;\n }\n if (lastChild && lastChild.attr('id') === 'mce_marker') {\n lastChild = lastChild.prev;\n }\n if (isEmptyFragmentElement(schema, lastChild)) {\n lastChild = lastChild === null || lastChild === void 0 ? void 0 : lastChild.prev;\n }\n if (!firstChild || firstChild !== lastChild) {\n return false;\n }\n return firstChild.name === 'ul' || firstChild.name === 'ol';\n };\n const cleanupDomFragment = domFragment => {\n var _a, _b;\n const firstChild = domFragment.firstChild;\n const lastChild = domFragment.lastChild;\n if (firstChild && firstChild.nodeName === 'META') {\n (_a = firstChild.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(firstChild);\n }\n if (lastChild && lastChild.id === 'mce_marker') {\n (_b = lastChild.parentNode) === null || _b === void 0 ? void 0 : _b.removeChild(lastChild);\n }\n return domFragment;\n };\n const toDomFragment = (dom, serializer, fragment) => {\n const html = serializer.serialize(fragment);\n const domFragment = dom.createFragment(html);\n return cleanupDomFragment(domFragment);\n };\n const listItems = elm => {\n var _a;\n return filter$5((_a = elm === null || elm === void 0 ? void 0 : elm.childNodes) !== null && _a !== void 0 ? _a : [], child => {\n return child.nodeName === 'LI';\n });\n };\n const isPadding = node => {\n return node.data === nbsp || isBr$6(node);\n };\n const isListItemPadded = node => {\n return isNonNullable(node === null || node === void 0 ? void 0 : node.firstChild) && node.firstChild === node.lastChild && isPadding(node.firstChild);\n };\n const isEmptyOrPadded = elm => {\n return !elm.firstChild || isListItemPadded(elm);\n };\n const trimListItems = elms => {\n return elms.length > 0 && isEmptyOrPadded(elms[elms.length - 1]) ? elms.slice(0, -1) : elms;\n };\n const getParentLi = (dom, node) => {\n const parentBlock = dom.getParent(node, dom.isBlock);\n return parentBlock && parentBlock.nodeName === 'LI' ? parentBlock : null;\n };\n const isParentBlockLi = (dom, node) => {\n return !!getParentLi(dom, node);\n };\n const getSplit = (parentNode, rng) => {\n const beforeRng = rng.cloneRange();\n const afterRng = rng.cloneRange();\n beforeRng.setStartBefore(parentNode);\n afterRng.setEndAfter(parentNode);\n return [\n beforeRng.cloneContents(),\n afterRng.cloneContents()\n ];\n };\n const findFirstIn = (node, rootNode) => {\n const caretPos = CaretPosition.before(node);\n const caretWalker = CaretWalker(rootNode);\n const newCaretPos = caretWalker.next(caretPos);\n return newCaretPos ? newCaretPos.toRange() : null;\n };\n const findLastOf = (node, rootNode) => {\n const caretPos = CaretPosition.after(node);\n const caretWalker = CaretWalker(rootNode);\n const newCaretPos = caretWalker.prev(caretPos);\n return newCaretPos ? newCaretPos.toRange() : null;\n };\n const insertMiddle = (target, elms, rootNode, rng) => {\n const parts = getSplit(target, rng);\n const parentElm = target.parentNode;\n if (parentElm) {\n parentElm.insertBefore(parts[0], target);\n Tools.each(elms, li => {\n parentElm.insertBefore(li, target);\n });\n parentElm.insertBefore(parts[1], target);\n parentElm.removeChild(target);\n }\n return findLastOf(elms[elms.length - 1], rootNode);\n };\n const insertBefore$2 = (target, elms, rootNode) => {\n const parentElm = target.parentNode;\n if (parentElm) {\n Tools.each(elms, elm => {\n parentElm.insertBefore(elm, target);\n });\n }\n return findFirstIn(target, rootNode);\n };\n const insertAfter$2 = (target, elms, rootNode, dom) => {\n dom.insertAfter(elms.reverse(), target);\n return findLastOf(elms[0], rootNode);\n };\n const insertAtCaret$1 = (serializer, dom, rng, fragment) => {\n const domFragment = toDomFragment(dom, serializer, fragment);\n const liTarget = getParentLi(dom, rng.startContainer);\n const liElms = trimListItems(listItems(domFragment.firstChild));\n const BEGINNING = 1, END = 2;\n const rootNode = dom.getRoot();\n const isAt = location => {\n const caretPos = CaretPosition.fromRangeStart(rng);\n const caretWalker = CaretWalker(dom.getRoot());\n const newPos = location === BEGINNING ? caretWalker.prev(caretPos) : caretWalker.next(caretPos);\n const newPosNode = newPos === null || newPos === void 0 ? void 0 : newPos.getNode();\n return newPosNode ? getParentLi(dom, newPosNode) !== liTarget : true;\n };\n if (!liTarget) {\n return null;\n } else if (isAt(BEGINNING)) {\n return insertBefore$2(liTarget, liElms, rootNode);\n } else if (isAt(END)) {\n return insertAfter$2(liTarget, liElms, rootNode, dom);\n } else {\n return insertMiddle(liTarget, liElms, rootNode, rng);\n }\n };\n\n const mergeableWrappedElements = ['pre'];\n const shouldPasteContentOnly = (dom, fragment, parentNode, root) => {\n var _a;\n const firstNode = fragment.firstChild;\n const lastNode = fragment.lastChild;\n const last = lastNode.attr('data-mce-type') === 'bookmark' ? lastNode.prev : lastNode;\n const isPastingSingleElement = firstNode === last;\n const isWrappedElement = contains$2(mergeableWrappedElements, firstNode.name);\n if (isPastingSingleElement && isWrappedElement) {\n const isContentEditable = firstNode.attr('contenteditable') !== 'false';\n const isPastingInTheSameBlockTag = ((_a = dom.getParent(parentNode, dom.isBlock)) === null || _a === void 0 ? void 0 : _a.nodeName.toLowerCase()) === firstNode.name;\n const isPastingInContentEditable = Optional.from(getContentEditableRoot$1(root, parentNode)).forall(isContentEditableTrue$3);\n return isContentEditable && isPastingInTheSameBlockTag && isPastingInContentEditable;\n } else {\n return false;\n }\n };\n const isTableCell = isTableCell$3;\n const isTableCellContentSelected = (dom, rng, cell) => {\n if (isNonNullable(cell)) {\n const endCell = dom.getParent(rng.endContainer, isTableCell);\n return cell === endCell && hasAllContentsSelected(SugarElement.fromDom(cell), rng);\n } else {\n return false;\n }\n };\n const validInsertion = (editor, value, parentNode) => {\n var _a;\n if (parentNode.getAttribute('data-mce-bogus') === 'all') {\n (_a = parentNode.parentNode) === null || _a === void 0 ? void 0 : _a.insertBefore(editor.dom.createFragment(value), parentNode);\n } else {\n const node = parentNode.firstChild;\n const node2 = parentNode.lastChild;\n if (!node || node === node2 && node.nodeName === 'BR') {\n editor.dom.setHTML(parentNode, value);\n } else {\n editor.selection.setContent(value, { no_events: true });\n }\n }\n };\n const trimBrsFromTableCell = (dom, elm, schema) => {\n Optional.from(dom.getParent(elm, 'td,th')).map(SugarElement.fromDom).each(el => trimBlockTrailingBr(el, schema));\n };\n const reduceInlineTextElements = (editor, merge) => {\n const textInlineElements = editor.schema.getTextInlineElements();\n const dom = editor.dom;\n if (merge) {\n const root = editor.getBody();\n const elementUtils = ElementUtils(editor);\n const fragmentSelector = '*[data-mce-fragment]';\n const fragments = dom.select(fragmentSelector);\n Tools.each(fragments, node => {\n const isInline = currentNode => isNonNullable(textInlineElements[currentNode.nodeName.toLowerCase()]);\n const hasOneChild = currentNode => currentNode.childNodes.length === 1;\n const hasNoNonInheritableStyles = currentNode => !(hasNonInheritableStyles(dom, currentNode) || hasConditionalNonInheritableStyles(dom, currentNode));\n if (hasNoNonInheritableStyles(node) && isInline(node) && hasOneChild(node)) {\n const styles = getStyleProps(dom, node);\n const isOverridden = (oldStyles, newStyles) => forall(oldStyles, style => contains$2(newStyles, style));\n const overriddenByAllChildren = childNode => hasOneChild(node) && dom.is(childNode, fragmentSelector) && isInline(childNode) && (childNode.nodeName === node.nodeName && isOverridden(styles, getStyleProps(dom, childNode)) || overriddenByAllChildren(childNode.children[0]));\n const identicalToParent = parentNode => isNonNullable(parentNode) && parentNode !== root && (elementUtils.compare(node, parentNode) || identicalToParent(parentNode.parentElement));\n const conflictWithInsertedParent = parentNode => isNonNullable(parentNode) && parentNode !== root && dom.is(parentNode, fragmentSelector) && (hasStyleConflict(dom, node, parentNode) || conflictWithInsertedParent(parentNode.parentElement));\n if (overriddenByAllChildren(node.children[0]) || identicalToParent(node.parentElement) && !conflictWithInsertedParent(node.parentElement)) {\n dom.remove(node, true);\n }\n }\n });\n }\n };\n const markFragmentElements = fragment => {\n let node = fragment;\n while (node = node.walk()) {\n if (node.type === 1) {\n node.attr('data-mce-fragment', '1');\n }\n }\n };\n const unmarkFragmentElements = elm => {\n Tools.each(elm.getElementsByTagName('*'), elm => {\n elm.removeAttribute('data-mce-fragment');\n });\n };\n const isPartOfFragment = node => {\n return !!node.getAttribute('data-mce-fragment');\n };\n const canHaveChildren = (editor, node) => {\n return isNonNullable(node) && !editor.schema.getVoidElements()[node.nodeName];\n };\n const moveSelectionToMarker = (editor, marker) => {\n var _a, _b, _c;\n let nextRng;\n const dom = editor.dom;\n const selection = editor.selection;\n if (!marker) {\n return;\n }\n selection.scrollIntoView(marker);\n const parentEditableElm = getContentEditableRoot$1(editor.getBody(), marker);\n if (parentEditableElm && dom.getContentEditable(parentEditableElm) === 'false') {\n dom.remove(marker);\n selection.select(parentEditableElm);\n return;\n }\n let rng = dom.createRng();\n const node = marker.previousSibling;\n if (isText$b(node)) {\n rng.setStart(node, (_b = (_a = node.nodeValue) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0);\n const node2 = marker.nextSibling;\n if (isText$b(node2)) {\n node.appendData(node2.data);\n (_c = node2.parentNode) === null || _c === void 0 ? void 0 : _c.removeChild(node2);\n }\n } else {\n rng.setStartBefore(marker);\n rng.setEndBefore(marker);\n }\n const findNextCaretRng = rng => {\n let caretPos = CaretPosition.fromRangeStart(rng);\n const caretWalker = CaretWalker(editor.getBody());\n caretPos = caretWalker.next(caretPos);\n return caretPos === null || caretPos === void 0 ? void 0 : caretPos.toRange();\n };\n const parentBlock = dom.getParent(marker, dom.isBlock);\n dom.remove(marker);\n if (parentBlock && dom.isEmpty(parentBlock)) {\n const isCell = isTableCell(parentBlock);\n empty(SugarElement.fromDom(parentBlock));\n rng.setStart(parentBlock, 0);\n rng.setEnd(parentBlock, 0);\n if (!isCell && !isPartOfFragment(parentBlock) && (nextRng = findNextCaretRng(rng))) {\n rng = nextRng;\n dom.remove(parentBlock);\n } else {\n dom.add(parentBlock, dom.create('br', isCell ? {} : { 'data-mce-bogus': '1' }));\n }\n }\n selection.setRng(rng);\n };\n const deleteSelectedContent = editor => {\n const dom = editor.dom;\n const rng = normalize(editor.selection.getRng());\n editor.selection.setRng(rng);\n const startCell = dom.getParent(rng.startContainer, isTableCell);\n if (isTableCellContentSelected(dom, rng, startCell)) {\n deleteCellContents(editor, rng, SugarElement.fromDom(startCell));\n } else if (rng.startContainer === rng.endContainer && rng.endOffset - rng.startOffset === 1 && isText$b(rng.startContainer.childNodes[rng.startOffset])) {\n rng.deleteContents();\n } else {\n editor.getDoc().execCommand('Delete', false);\n }\n };\n const findMarkerNode = scope => {\n for (let markerNode = scope; markerNode; markerNode = markerNode.walk()) {\n if (markerNode.attr('id') === 'mce_marker') {\n return Optional.some(markerNode);\n }\n }\n return Optional.none();\n };\n const notHeadingsInSummary = (dom, node, fragment) => {\n var _a;\n return exists(fragment.children(), isHeading) && ((_a = dom.getParent(node, dom.isBlock)) === null || _a === void 0 ? void 0 : _a.nodeName) === 'SUMMARY';\n };\n const insertHtmlAtCaret = (editor, value, details) => {\n var _a, _b;\n const selection = editor.selection;\n const dom = editor.dom;\n const parser = editor.parser;\n const merge = details.merge;\n const serializer = HtmlSerializer({ validate: true }, editor.schema);\n const bookmarkHtml = '';\n if (!details.preserve_zwsp) {\n value = trim$2(value);\n }\n if (value.indexOf('{$caret}') === -1) {\n value += '{$caret}';\n }\n value = value.replace(/\\{\\$caret\\}/, bookmarkHtml);\n let rng = selection.getRng();\n const caretElement = rng.startContainer;\n const body = editor.getBody();\n if (caretElement === body && selection.isCollapsed()) {\n if (dom.isBlock(body.firstChild) && canHaveChildren(editor, body.firstChild) && dom.isEmpty(body.firstChild)) {\n rng = dom.createRng();\n rng.setStart(body.firstChild, 0);\n rng.setEnd(body.firstChild, 0);\n selection.setRng(rng);\n }\n }\n if (!selection.isCollapsed()) {\n deleteSelectedContent(editor);\n }\n const parentNode = selection.getNode();\n const parserArgs = {\n context: parentNode.nodeName.toLowerCase(),\n data: details.data,\n insert: true\n };\n const fragment = parser.parse(value, parserArgs);\n if (details.paste === true && isListFragment(editor.schema, fragment) && isParentBlockLi(dom, parentNode)) {\n rng = insertAtCaret$1(serializer, dom, selection.getRng(), fragment);\n if (rng) {\n selection.setRng(rng);\n }\n return value;\n }\n if (details.paste === true && shouldPasteContentOnly(dom, fragment, parentNode, editor.getBody())) {\n (_a = fragment.firstChild) === null || _a === void 0 ? void 0 : _a.unwrap();\n }\n markFragmentElements(fragment);\n let node = fragment.lastChild;\n if (node && node.attr('id') === 'mce_marker') {\n const marker = node;\n for (node = node.prev; node; node = node.walk(true)) {\n if (node.name === 'table') {\n break;\n }\n if (node.type === 3 || !dom.isBlock(node.name)) {\n if (node.parent && editor.schema.isValidChild(node.parent.name, 'span')) {\n node.parent.insert(marker, node, node.name === 'br');\n }\n break;\n }\n }\n }\n editor._selectionOverrides.showBlockCaretContainer(parentNode);\n if (!parserArgs.invalid && !notHeadingsInSummary(dom, parentNode, fragment)) {\n value = serializer.serialize(fragment);\n validInsertion(editor, value, parentNode);\n } else {\n editor.selection.setContent(bookmarkHtml);\n let parentNode = selection.getNode();\n let tempNode;\n const rootNode = editor.getBody();\n if (isDocument$1(parentNode)) {\n parentNode = tempNode = rootNode;\n } else {\n tempNode = parentNode;\n }\n while (tempNode && tempNode !== rootNode) {\n parentNode = tempNode;\n tempNode = tempNode.parentNode;\n }\n value = parentNode === rootNode ? rootNode.innerHTML : dom.getOuterHTML(parentNode);\n const root = parser.parse(value);\n const markerNode = findMarkerNode(root);\n const editingHost = markerNode.bind(findClosestEditingHost).getOr(root);\n markerNode.each(marker => marker.replace(fragment));\n const toExtract = fragment.children();\n const parent = (_b = fragment.parent) !== null && _b !== void 0 ? _b : root;\n fragment.unwrap();\n const invalidChildren = filter$5(toExtract, node => isInvalid(editor.schema, node, parent));\n cleanInvalidNodes(invalidChildren, editor.schema, editingHost);\n filter$2(parser.getNodeFilters(), parser.getAttributeFilters(), root);\n value = serializer.serialize(root);\n if (parentNode === rootNode) {\n dom.setHTML(rootNode, value);\n } else {\n dom.setOuterHTML(parentNode, value);\n }\n }\n reduceInlineTextElements(editor, merge);\n moveSelectionToMarker(editor, dom.get('mce_marker'));\n unmarkFragmentElements(editor.getBody());\n trimBrsFromTableCell(dom, selection.getStart(), editor.schema);\n updateCaret(editor.schema, editor.getBody(), selection.getStart());\n return value;\n };\n\n const isTreeNode = content => content instanceof AstNode;\n\n const moveSelection = editor => {\n if (hasFocus(editor)) {\n firstPositionIn(editor.getBody()).each(pos => {\n const node = pos.getNode();\n const caretPos = isTable$2(node) ? firstPositionIn(node).getOr(pos) : pos;\n editor.selection.setRng(caretPos.toRange());\n });\n }\n };\n const setEditorHtml = (editor, html, noSelection) => {\n editor.dom.setHTML(editor.getBody(), html);\n if (noSelection !== true) {\n moveSelection(editor);\n }\n };\n const setContentString = (editor, body, content, args) => {\n content = trim$2(content);\n if (content.length === 0 || /^\\s+$/.test(content)) {\n const padd = '
';\n if (body.nodeName === 'TABLE') {\n content = '