plugin.js 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346
  1. /**
  2. * Copyright (c) Tiny Technologies, Inc. All rights reserved.
  3. * Licensed under the LGPL or a commercial license.
  4. * For LGPL see License.txt in the project root for license information.
  5. * For commercial licenses see https://www.tiny.cloud/
  6. *
  7. * Version: 5.10.2 (2021-11-17)
  8. */
  9. (function () {
  10. 'use strict';
  11. var Cell = function (initial) {
  12. var value = initial;
  13. var get = function () {
  14. return value;
  15. };
  16. var set = function (v) {
  17. value = v;
  18. };
  19. return {
  20. get: get,
  21. set: set
  22. };
  23. };
  24. var global$3 = tinymce.util.Tools.resolve('tinymce.PluginManager');
  25. var get$5 = function (fullscreenState) {
  26. return {
  27. isFullscreen: function () {
  28. return fullscreenState.get() !== null;
  29. }
  30. };
  31. };
  32. var typeOf = function (x) {
  33. var t = typeof x;
  34. if (x === null) {
  35. return 'null';
  36. } else if (t === 'object' && (Array.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === 'Array')) {
  37. return 'array';
  38. } else if (t === 'object' && (String.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === 'String')) {
  39. return 'string';
  40. } else {
  41. return t;
  42. }
  43. };
  44. var isType$1 = function (type) {
  45. return function (value) {
  46. return typeOf(value) === type;
  47. };
  48. };
  49. var isSimpleType = function (type) {
  50. return function (value) {
  51. return typeof value === type;
  52. };
  53. };
  54. var isString = isType$1('string');
  55. var isArray = isType$1('array');
  56. var isBoolean = isSimpleType('boolean');
  57. var isNullable = function (a) {
  58. return a === null || a === undefined;
  59. };
  60. var isNonNullable = function (a) {
  61. return !isNullable(a);
  62. };
  63. var isFunction = isSimpleType('function');
  64. var isNumber = isSimpleType('number');
  65. var noop = function () {
  66. };
  67. var compose = function (fa, fb) {
  68. return function () {
  69. var args = [];
  70. for (var _i = 0; _i < arguments.length; _i++) {
  71. args[_i] = arguments[_i];
  72. }
  73. return fa(fb.apply(null, args));
  74. };
  75. };
  76. var compose1 = function (fbc, fab) {
  77. return function (a) {
  78. return fbc(fab(a));
  79. };
  80. };
  81. var constant = function (value) {
  82. return function () {
  83. return value;
  84. };
  85. };
  86. var identity = function (x) {
  87. return x;
  88. };
  89. function curry(fn) {
  90. var initialArgs = [];
  91. for (var _i = 1; _i < arguments.length; _i++) {
  92. initialArgs[_i - 1] = arguments[_i];
  93. }
  94. return function () {
  95. var restArgs = [];
  96. for (var _i = 0; _i < arguments.length; _i++) {
  97. restArgs[_i] = arguments[_i];
  98. }
  99. var all = initialArgs.concat(restArgs);
  100. return fn.apply(null, all);
  101. };
  102. }
  103. var never = constant(false);
  104. var always = constant(true);
  105. var none = function () {
  106. return NONE;
  107. };
  108. var NONE = function () {
  109. var call = function (thunk) {
  110. return thunk();
  111. };
  112. var id = identity;
  113. var me = {
  114. fold: function (n, _s) {
  115. return n();
  116. },
  117. isSome: never,
  118. isNone: always,
  119. getOr: id,
  120. getOrThunk: call,
  121. getOrDie: function (msg) {
  122. throw new Error(msg || 'error: getOrDie called on none.');
  123. },
  124. getOrNull: constant(null),
  125. getOrUndefined: constant(undefined),
  126. or: id,
  127. orThunk: call,
  128. map: none,
  129. each: noop,
  130. bind: none,
  131. exists: never,
  132. forall: always,
  133. filter: function () {
  134. return none();
  135. },
  136. toArray: function () {
  137. return [];
  138. },
  139. toString: constant('none()')
  140. };
  141. return me;
  142. }();
  143. var some = function (a) {
  144. var constant_a = constant(a);
  145. var self = function () {
  146. return me;
  147. };
  148. var bind = function (f) {
  149. return f(a);
  150. };
  151. var me = {
  152. fold: function (n, s) {
  153. return s(a);
  154. },
  155. isSome: always,
  156. isNone: never,
  157. getOr: constant_a,
  158. getOrThunk: constant_a,
  159. getOrDie: constant_a,
  160. getOrNull: constant_a,
  161. getOrUndefined: constant_a,
  162. or: self,
  163. orThunk: self,
  164. map: function (f) {
  165. return some(f(a));
  166. },
  167. each: function (f) {
  168. f(a);
  169. },
  170. bind: bind,
  171. exists: bind,
  172. forall: bind,
  173. filter: function (f) {
  174. return f(a) ? me : NONE;
  175. },
  176. toArray: function () {
  177. return [a];
  178. },
  179. toString: function () {
  180. return 'some(' + a + ')';
  181. }
  182. };
  183. return me;
  184. };
  185. var from = function (value) {
  186. return value === null || value === undefined ? NONE : some(value);
  187. };
  188. var Optional = {
  189. some: some,
  190. none: none,
  191. from: from
  192. };
  193. var __assign = function () {
  194. __assign = Object.assign || function __assign(t) {
  195. for (var s, i = 1, n = arguments.length; i < n; i++) {
  196. s = arguments[i];
  197. for (var p in s)
  198. if (Object.prototype.hasOwnProperty.call(s, p))
  199. t[p] = s[p];
  200. }
  201. return t;
  202. };
  203. return __assign.apply(this, arguments);
  204. };
  205. var singleton = function (doRevoke) {
  206. var subject = Cell(Optional.none());
  207. var revoke = function () {
  208. return subject.get().each(doRevoke);
  209. };
  210. var clear = function () {
  211. revoke();
  212. subject.set(Optional.none());
  213. };
  214. var isSet = function () {
  215. return subject.get().isSome();
  216. };
  217. var get = function () {
  218. return subject.get();
  219. };
  220. var set = function (s) {
  221. revoke();
  222. subject.set(Optional.some(s));
  223. };
  224. return {
  225. clear: clear,
  226. isSet: isSet,
  227. get: get,
  228. set: set
  229. };
  230. };
  231. var unbindable = function () {
  232. return singleton(function (s) {
  233. return s.unbind();
  234. });
  235. };
  236. var value = function () {
  237. var subject = singleton(noop);
  238. var on = function (f) {
  239. return subject.get().each(f);
  240. };
  241. return __assign(__assign({}, subject), { on: on });
  242. };
  243. var nativePush = Array.prototype.push;
  244. var map = function (xs, f) {
  245. var len = xs.length;
  246. var r = new Array(len);
  247. for (var i = 0; i < len; i++) {
  248. var x = xs[i];
  249. r[i] = f(x, i);
  250. }
  251. return r;
  252. };
  253. var each$1 = function (xs, f) {
  254. for (var i = 0, len = xs.length; i < len; i++) {
  255. var x = xs[i];
  256. f(x, i);
  257. }
  258. };
  259. var filter$1 = function (xs, pred) {
  260. var r = [];
  261. for (var i = 0, len = xs.length; i < len; i++) {
  262. var x = xs[i];
  263. if (pred(x, i)) {
  264. r.push(x);
  265. }
  266. }
  267. return r;
  268. };
  269. var findUntil = function (xs, pred, until) {
  270. for (var i = 0, len = xs.length; i < len; i++) {
  271. var x = xs[i];
  272. if (pred(x, i)) {
  273. return Optional.some(x);
  274. } else if (until(x, i)) {
  275. break;
  276. }
  277. }
  278. return Optional.none();
  279. };
  280. var find$1 = function (xs, pred) {
  281. return findUntil(xs, pred, never);
  282. };
  283. var flatten = function (xs) {
  284. var r = [];
  285. for (var i = 0, len = xs.length; i < len; ++i) {
  286. if (!isArray(xs[i])) {
  287. throw new Error('Arr.flatten item ' + i + ' was not an array, input: ' + xs);
  288. }
  289. nativePush.apply(r, xs[i]);
  290. }
  291. return r;
  292. };
  293. var bind$3 = function (xs, f) {
  294. return flatten(map(xs, f));
  295. };
  296. var get$4 = function (xs, i) {
  297. return i >= 0 && i < xs.length ? Optional.some(xs[i]) : Optional.none();
  298. };
  299. var head = function (xs) {
  300. return get$4(xs, 0);
  301. };
  302. var findMap = function (arr, f) {
  303. for (var i = 0; i < arr.length; i++) {
  304. var r = f(arr[i], i);
  305. if (r.isSome()) {
  306. return r;
  307. }
  308. }
  309. return Optional.none();
  310. };
  311. var keys = Object.keys;
  312. var each = function (obj, f) {
  313. var props = keys(obj);
  314. for (var k = 0, len = props.length; k < len; k++) {
  315. var i = props[k];
  316. var x = obj[i];
  317. f(x, i);
  318. }
  319. };
  320. var contains = function (str, substr) {
  321. return str.indexOf(substr) !== -1;
  322. };
  323. var isSupported$1 = function (dom) {
  324. return dom.style !== undefined && isFunction(dom.style.getPropertyValue);
  325. };
  326. var fromHtml = function (html, scope) {
  327. var doc = scope || document;
  328. var div = doc.createElement('div');
  329. div.innerHTML = html;
  330. if (!div.hasChildNodes() || div.childNodes.length > 1) {
  331. console.error('HTML does not have a single root node', html);
  332. throw new Error('HTML must have a single root node');
  333. }
  334. return fromDom(div.childNodes[0]);
  335. };
  336. var fromTag = function (tag, scope) {
  337. var doc = scope || document;
  338. var node = doc.createElement(tag);
  339. return fromDom(node);
  340. };
  341. var fromText = function (text, scope) {
  342. var doc = scope || document;
  343. var node = doc.createTextNode(text);
  344. return fromDom(node);
  345. };
  346. var fromDom = function (node) {
  347. if (node === null || node === undefined) {
  348. throw new Error('Node cannot be null or undefined');
  349. }
  350. return { dom: node };
  351. };
  352. var fromPoint = function (docElm, x, y) {
  353. return Optional.from(docElm.dom.elementFromPoint(x, y)).map(fromDom);
  354. };
  355. var SugarElement = {
  356. fromHtml: fromHtml,
  357. fromTag: fromTag,
  358. fromText: fromText,
  359. fromDom: fromDom,
  360. fromPoint: fromPoint
  361. };
  362. typeof window !== 'undefined' ? window : Function('return this;')();
  363. var DOCUMENT = 9;
  364. var DOCUMENT_FRAGMENT = 11;
  365. var ELEMENT = 1;
  366. var TEXT = 3;
  367. var type = function (element) {
  368. return element.dom.nodeType;
  369. };
  370. var isType = function (t) {
  371. return function (element) {
  372. return type(element) === t;
  373. };
  374. };
  375. var isElement = isType(ELEMENT);
  376. var isText = isType(TEXT);
  377. var isDocument = isType(DOCUMENT);
  378. var isDocumentFragment = isType(DOCUMENT_FRAGMENT);
  379. var cached = function (f) {
  380. var called = false;
  381. var r;
  382. return function () {
  383. var args = [];
  384. for (var _i = 0; _i < arguments.length; _i++) {
  385. args[_i] = arguments[_i];
  386. }
  387. if (!called) {
  388. called = true;
  389. r = f.apply(null, args);
  390. }
  391. return r;
  392. };
  393. };
  394. var DeviceType = function (os, browser, userAgent, mediaMatch) {
  395. var isiPad = os.isiOS() && /ipad/i.test(userAgent) === true;
  396. var isiPhone = os.isiOS() && !isiPad;
  397. var isMobile = os.isiOS() || os.isAndroid();
  398. var isTouch = isMobile || mediaMatch('(pointer:coarse)');
  399. var isTablet = isiPad || !isiPhone && isMobile && mediaMatch('(min-device-width:768px)');
  400. var isPhone = isiPhone || isMobile && !isTablet;
  401. var iOSwebview = browser.isSafari() && os.isiOS() && /safari/i.test(userAgent) === false;
  402. var isDesktop = !isPhone && !isTablet && !iOSwebview;
  403. return {
  404. isiPad: constant(isiPad),
  405. isiPhone: constant(isiPhone),
  406. isTablet: constant(isTablet),
  407. isPhone: constant(isPhone),
  408. isTouch: constant(isTouch),
  409. isAndroid: os.isAndroid,
  410. isiOS: os.isiOS,
  411. isWebView: constant(iOSwebview),
  412. isDesktop: constant(isDesktop)
  413. };
  414. };
  415. var firstMatch = function (regexes, s) {
  416. for (var i = 0; i < regexes.length; i++) {
  417. var x = regexes[i];
  418. if (x.test(s)) {
  419. return x;
  420. }
  421. }
  422. return undefined;
  423. };
  424. var find = function (regexes, agent) {
  425. var r = firstMatch(regexes, agent);
  426. if (!r) {
  427. return {
  428. major: 0,
  429. minor: 0
  430. };
  431. }
  432. var group = function (i) {
  433. return Number(agent.replace(r, '$' + i));
  434. };
  435. return nu$2(group(1), group(2));
  436. };
  437. var detect$3 = function (versionRegexes, agent) {
  438. var cleanedAgent = String(agent).toLowerCase();
  439. if (versionRegexes.length === 0) {
  440. return unknown$2();
  441. }
  442. return find(versionRegexes, cleanedAgent);
  443. };
  444. var unknown$2 = function () {
  445. return nu$2(0, 0);
  446. };
  447. var nu$2 = function (major, minor) {
  448. return {
  449. major: major,
  450. minor: minor
  451. };
  452. };
  453. var Version = {
  454. nu: nu$2,
  455. detect: detect$3,
  456. unknown: unknown$2
  457. };
  458. var detectBrowser$1 = function (browsers, userAgentData) {
  459. return findMap(userAgentData.brands, function (uaBrand) {
  460. var lcBrand = uaBrand.brand.toLowerCase();
  461. return find$1(browsers, function (browser) {
  462. var _a;
  463. return lcBrand === ((_a = browser.brand) === null || _a === void 0 ? void 0 : _a.toLowerCase());
  464. }).map(function (info) {
  465. return {
  466. current: info.name,
  467. version: Version.nu(parseInt(uaBrand.version, 10), 0)
  468. };
  469. });
  470. });
  471. };
  472. var detect$2 = function (candidates, userAgent) {
  473. var agent = String(userAgent).toLowerCase();
  474. return find$1(candidates, function (candidate) {
  475. return candidate.search(agent);
  476. });
  477. };
  478. var detectBrowser = function (browsers, userAgent) {
  479. return detect$2(browsers, userAgent).map(function (browser) {
  480. var version = Version.detect(browser.versionRegexes, userAgent);
  481. return {
  482. current: browser.name,
  483. version: version
  484. };
  485. });
  486. };
  487. var detectOs = function (oses, userAgent) {
  488. return detect$2(oses, userAgent).map(function (os) {
  489. var version = Version.detect(os.versionRegexes, userAgent);
  490. return {
  491. current: os.name,
  492. version: version
  493. };
  494. });
  495. };
  496. var normalVersionRegex = /.*?version\/\ ?([0-9]+)\.([0-9]+).*/;
  497. var checkContains = function (target) {
  498. return function (uastring) {
  499. return contains(uastring, target);
  500. };
  501. };
  502. var browsers = [
  503. {
  504. name: 'Edge',
  505. versionRegexes: [/.*?edge\/ ?([0-9]+)\.([0-9]+)$/],
  506. search: function (uastring) {
  507. return contains(uastring, 'edge/') && contains(uastring, 'chrome') && contains(uastring, 'safari') && contains(uastring, 'applewebkit');
  508. }
  509. },
  510. {
  511. name: 'Chrome',
  512. brand: 'Chromium',
  513. versionRegexes: [
  514. /.*?chrome\/([0-9]+)\.([0-9]+).*/,
  515. normalVersionRegex
  516. ],
  517. search: function (uastring) {
  518. return contains(uastring, 'chrome') && !contains(uastring, 'chromeframe');
  519. }
  520. },
  521. {
  522. name: 'IE',
  523. versionRegexes: [
  524. /.*?msie\ ?([0-9]+)\.([0-9]+).*/,
  525. /.*?rv:([0-9]+)\.([0-9]+).*/
  526. ],
  527. search: function (uastring) {
  528. return contains(uastring, 'msie') || contains(uastring, 'trident');
  529. }
  530. },
  531. {
  532. name: 'Opera',
  533. versionRegexes: [
  534. normalVersionRegex,
  535. /.*?opera\/([0-9]+)\.([0-9]+).*/
  536. ],
  537. search: checkContains('opera')
  538. },
  539. {
  540. name: 'Firefox',
  541. versionRegexes: [/.*?firefox\/\ ?([0-9]+)\.([0-9]+).*/],
  542. search: checkContains('firefox')
  543. },
  544. {
  545. name: 'Safari',
  546. versionRegexes: [
  547. normalVersionRegex,
  548. /.*?cpu os ([0-9]+)_([0-9]+).*/
  549. ],
  550. search: function (uastring) {
  551. return (contains(uastring, 'safari') || contains(uastring, 'mobile/')) && contains(uastring, 'applewebkit');
  552. }
  553. }
  554. ];
  555. var oses = [
  556. {
  557. name: 'Windows',
  558. search: checkContains('win'),
  559. versionRegexes: [/.*?windows\ nt\ ?([0-9]+)\.([0-9]+).*/]
  560. },
  561. {
  562. name: 'iOS',
  563. search: function (uastring) {
  564. return contains(uastring, 'iphone') || contains(uastring, 'ipad');
  565. },
  566. versionRegexes: [
  567. /.*?version\/\ ?([0-9]+)\.([0-9]+).*/,
  568. /.*cpu os ([0-9]+)_([0-9]+).*/,
  569. /.*cpu iphone os ([0-9]+)_([0-9]+).*/
  570. ]
  571. },
  572. {
  573. name: 'Android',
  574. search: checkContains('android'),
  575. versionRegexes: [/.*?android\ ?([0-9]+)\.([0-9]+).*/]
  576. },
  577. {
  578. name: 'OSX',
  579. search: checkContains('mac os x'),
  580. versionRegexes: [/.*?mac\ os\ x\ ?([0-9]+)_([0-9]+).*/]
  581. },
  582. {
  583. name: 'Linux',
  584. search: checkContains('linux'),
  585. versionRegexes: []
  586. },
  587. {
  588. name: 'Solaris',
  589. search: checkContains('sunos'),
  590. versionRegexes: []
  591. },
  592. {
  593. name: 'FreeBSD',
  594. search: checkContains('freebsd'),
  595. versionRegexes: []
  596. },
  597. {
  598. name: 'ChromeOS',
  599. search: checkContains('cros'),
  600. versionRegexes: [/.*?chrome\/([0-9]+)\.([0-9]+).*/]
  601. }
  602. ];
  603. var PlatformInfo = {
  604. browsers: constant(browsers),
  605. oses: constant(oses)
  606. };
  607. var edge = 'Edge';
  608. var chrome = 'Chrome';
  609. var ie = 'IE';
  610. var opera = 'Opera';
  611. var firefox = 'Firefox';
  612. var safari = 'Safari';
  613. var unknown$1 = function () {
  614. return nu$1({
  615. current: undefined,
  616. version: Version.unknown()
  617. });
  618. };
  619. var nu$1 = function (info) {
  620. var current = info.current;
  621. var version = info.version;
  622. var isBrowser = function (name) {
  623. return function () {
  624. return current === name;
  625. };
  626. };
  627. return {
  628. current: current,
  629. version: version,
  630. isEdge: isBrowser(edge),
  631. isChrome: isBrowser(chrome),
  632. isIE: isBrowser(ie),
  633. isOpera: isBrowser(opera),
  634. isFirefox: isBrowser(firefox),
  635. isSafari: isBrowser(safari)
  636. };
  637. };
  638. var Browser = {
  639. unknown: unknown$1,
  640. nu: nu$1,
  641. edge: constant(edge),
  642. chrome: constant(chrome),
  643. ie: constant(ie),
  644. opera: constant(opera),
  645. firefox: constant(firefox),
  646. safari: constant(safari)
  647. };
  648. var windows = 'Windows';
  649. var ios = 'iOS';
  650. var android = 'Android';
  651. var linux = 'Linux';
  652. var osx = 'OSX';
  653. var solaris = 'Solaris';
  654. var freebsd = 'FreeBSD';
  655. var chromeos = 'ChromeOS';
  656. var unknown = function () {
  657. return nu({
  658. current: undefined,
  659. version: Version.unknown()
  660. });
  661. };
  662. var nu = function (info) {
  663. var current = info.current;
  664. var version = info.version;
  665. var isOS = function (name) {
  666. return function () {
  667. return current === name;
  668. };
  669. };
  670. return {
  671. current: current,
  672. version: version,
  673. isWindows: isOS(windows),
  674. isiOS: isOS(ios),
  675. isAndroid: isOS(android),
  676. isOSX: isOS(osx),
  677. isLinux: isOS(linux),
  678. isSolaris: isOS(solaris),
  679. isFreeBSD: isOS(freebsd),
  680. isChromeOS: isOS(chromeos)
  681. };
  682. };
  683. var OperatingSystem = {
  684. unknown: unknown,
  685. nu: nu,
  686. windows: constant(windows),
  687. ios: constant(ios),
  688. android: constant(android),
  689. linux: constant(linux),
  690. osx: constant(osx),
  691. solaris: constant(solaris),
  692. freebsd: constant(freebsd),
  693. chromeos: constant(chromeos)
  694. };
  695. var detect$1 = function (userAgent, userAgentDataOpt, mediaMatch) {
  696. var browsers = PlatformInfo.browsers();
  697. var oses = PlatformInfo.oses();
  698. var browser = userAgentDataOpt.bind(function (userAgentData) {
  699. return detectBrowser$1(browsers, userAgentData);
  700. }).orThunk(function () {
  701. return detectBrowser(browsers, userAgent);
  702. }).fold(Browser.unknown, Browser.nu);
  703. var os = detectOs(oses, userAgent).fold(OperatingSystem.unknown, OperatingSystem.nu);
  704. var deviceType = DeviceType(os, browser, userAgent, mediaMatch);
  705. return {
  706. browser: browser,
  707. os: os,
  708. deviceType: deviceType
  709. };
  710. };
  711. var PlatformDetection = { detect: detect$1 };
  712. var mediaMatch = function (query) {
  713. return window.matchMedia(query).matches;
  714. };
  715. var platform = cached(function () {
  716. return PlatformDetection.detect(navigator.userAgent, Optional.from(navigator.userAgentData), mediaMatch);
  717. });
  718. var detect = function () {
  719. return platform();
  720. };
  721. var is = function (element, selector) {
  722. var dom = element.dom;
  723. if (dom.nodeType !== ELEMENT) {
  724. return false;
  725. } else {
  726. var elem = dom;
  727. if (elem.matches !== undefined) {
  728. return elem.matches(selector);
  729. } else if (elem.msMatchesSelector !== undefined) {
  730. return elem.msMatchesSelector(selector);
  731. } else if (elem.webkitMatchesSelector !== undefined) {
  732. return elem.webkitMatchesSelector(selector);
  733. } else if (elem.mozMatchesSelector !== undefined) {
  734. return elem.mozMatchesSelector(selector);
  735. } else {
  736. throw new Error('Browser lacks native selectors');
  737. }
  738. }
  739. };
  740. var bypassSelector = function (dom) {
  741. return dom.nodeType !== ELEMENT && dom.nodeType !== DOCUMENT && dom.nodeType !== DOCUMENT_FRAGMENT || dom.childElementCount === 0;
  742. };
  743. var all$1 = function (selector, scope) {
  744. var base = scope === undefined ? document : scope.dom;
  745. return bypassSelector(base) ? [] : map(base.querySelectorAll(selector), SugarElement.fromDom);
  746. };
  747. var eq = function (e1, e2) {
  748. return e1.dom === e2.dom;
  749. };
  750. var owner = function (element) {
  751. return SugarElement.fromDom(element.dom.ownerDocument);
  752. };
  753. var documentOrOwner = function (dos) {
  754. return isDocument(dos) ? dos : owner(dos);
  755. };
  756. var parent = function (element) {
  757. return Optional.from(element.dom.parentNode).map(SugarElement.fromDom);
  758. };
  759. var parents = function (element, isRoot) {
  760. var stop = isFunction(isRoot) ? isRoot : never;
  761. var dom = element.dom;
  762. var ret = [];
  763. while (dom.parentNode !== null && dom.parentNode !== undefined) {
  764. var rawParent = dom.parentNode;
  765. var p = SugarElement.fromDom(rawParent);
  766. ret.push(p);
  767. if (stop(p) === true) {
  768. break;
  769. } else {
  770. dom = rawParent;
  771. }
  772. }
  773. return ret;
  774. };
  775. var siblings$2 = function (element) {
  776. var filterSelf = function (elements) {
  777. return filter$1(elements, function (x) {
  778. return !eq(element, x);
  779. });
  780. };
  781. return parent(element).map(children).map(filterSelf).getOr([]);
  782. };
  783. var children = function (element) {
  784. return map(element.dom.childNodes, SugarElement.fromDom);
  785. };
  786. var isShadowRoot = function (dos) {
  787. return isDocumentFragment(dos) && isNonNullable(dos.dom.host);
  788. };
  789. var supported = isFunction(Element.prototype.attachShadow) && isFunction(Node.prototype.getRootNode);
  790. var isSupported = constant(supported);
  791. var getRootNode = supported ? function (e) {
  792. return SugarElement.fromDom(e.dom.getRootNode());
  793. } : documentOrOwner;
  794. var getShadowRoot = function (e) {
  795. var r = getRootNode(e);
  796. return isShadowRoot(r) ? Optional.some(r) : Optional.none();
  797. };
  798. var getShadowHost = function (e) {
  799. return SugarElement.fromDom(e.dom.host);
  800. };
  801. var getOriginalEventTarget = function (event) {
  802. if (isSupported() && isNonNullable(event.target)) {
  803. var el = SugarElement.fromDom(event.target);
  804. if (isElement(el) && isOpenShadowHost(el)) {
  805. if (event.composed && event.composedPath) {
  806. var composedPath = event.composedPath();
  807. if (composedPath) {
  808. return head(composedPath);
  809. }
  810. }
  811. }
  812. }
  813. return Optional.from(event.target);
  814. };
  815. var isOpenShadowHost = function (element) {
  816. return isNonNullable(element.dom.shadowRoot);
  817. };
  818. var inBody = function (element) {
  819. var dom = isText(element) ? element.dom.parentNode : element.dom;
  820. if (dom === undefined || dom === null || dom.ownerDocument === null) {
  821. return false;
  822. }
  823. var doc = dom.ownerDocument;
  824. return getShadowRoot(SugarElement.fromDom(dom)).fold(function () {
  825. return doc.body.contains(dom);
  826. }, compose1(inBody, getShadowHost));
  827. };
  828. var getBody = function (doc) {
  829. var b = doc.dom.body;
  830. if (b === null || b === undefined) {
  831. throw new Error('Body is not available yet');
  832. }
  833. return SugarElement.fromDom(b);
  834. };
  835. var rawSet = function (dom, key, value) {
  836. if (isString(value) || isBoolean(value) || isNumber(value)) {
  837. dom.setAttribute(key, value + '');
  838. } else {
  839. console.error('Invalid call to Attribute.set. Key ', key, ':: Value ', value, ':: Element ', dom);
  840. throw new Error('Attribute value was not simple');
  841. }
  842. };
  843. var set = function (element, key, value) {
  844. rawSet(element.dom, key, value);
  845. };
  846. var get$3 = function (element, key) {
  847. var v = element.dom.getAttribute(key);
  848. return v === null ? undefined : v;
  849. };
  850. var remove = function (element, key) {
  851. element.dom.removeAttribute(key);
  852. };
  853. var internalSet = function (dom, property, value) {
  854. if (!isString(value)) {
  855. console.error('Invalid call to CSS.set. Property ', property, ':: Value ', value, ':: Element ', dom);
  856. throw new Error('CSS value must be a string: ' + value);
  857. }
  858. if (isSupported$1(dom)) {
  859. dom.style.setProperty(property, value);
  860. }
  861. };
  862. var setAll = function (element, css) {
  863. var dom = element.dom;
  864. each(css, function (v, k) {
  865. internalSet(dom, k, v);
  866. });
  867. };
  868. var get$2 = function (element, property) {
  869. var dom = element.dom;
  870. var styles = window.getComputedStyle(dom);
  871. var r = styles.getPropertyValue(property);
  872. return r === '' && !inBody(element) ? getUnsafeProperty(dom, property) : r;
  873. };
  874. var getUnsafeProperty = function (dom, property) {
  875. return isSupported$1(dom) ? dom.style.getPropertyValue(property) : '';
  876. };
  877. var mkEvent = function (target, x, y, stop, prevent, kill, raw) {
  878. return {
  879. target: target,
  880. x: x,
  881. y: y,
  882. stop: stop,
  883. prevent: prevent,
  884. kill: kill,
  885. raw: raw
  886. };
  887. };
  888. var fromRawEvent = function (rawEvent) {
  889. var target = SugarElement.fromDom(getOriginalEventTarget(rawEvent).getOr(rawEvent.target));
  890. var stop = function () {
  891. return rawEvent.stopPropagation();
  892. };
  893. var prevent = function () {
  894. return rawEvent.preventDefault();
  895. };
  896. var kill = compose(prevent, stop);
  897. return mkEvent(target, rawEvent.clientX, rawEvent.clientY, stop, prevent, kill, rawEvent);
  898. };
  899. var handle = function (filter, handler) {
  900. return function (rawEvent) {
  901. if (filter(rawEvent)) {
  902. handler(fromRawEvent(rawEvent));
  903. }
  904. };
  905. };
  906. var binder = function (element, event, filter, handler, useCapture) {
  907. var wrapped = handle(filter, handler);
  908. element.dom.addEventListener(event, wrapped, useCapture);
  909. return { unbind: curry(unbind, element, event, wrapped, useCapture) };
  910. };
  911. var bind$2 = function (element, event, filter, handler) {
  912. return binder(element, event, filter, handler, false);
  913. };
  914. var unbind = function (element, event, handler, useCapture) {
  915. element.dom.removeEventListener(event, handler, useCapture);
  916. };
  917. var filter = always;
  918. var bind$1 = function (element, event, handler) {
  919. return bind$2(element, event, filter, handler);
  920. };
  921. var r = function (left, top) {
  922. var translate = function (x, y) {
  923. return r(left + x, top + y);
  924. };
  925. return {
  926. left: left,
  927. top: top,
  928. translate: translate
  929. };
  930. };
  931. var SugarPosition = r;
  932. var get$1 = function (_DOC) {
  933. var doc = _DOC !== undefined ? _DOC.dom : document;
  934. var x = doc.body.scrollLeft || doc.documentElement.scrollLeft;
  935. var y = doc.body.scrollTop || doc.documentElement.scrollTop;
  936. return SugarPosition(x, y);
  937. };
  938. var get = function (_win) {
  939. var win = _win === undefined ? window : _win;
  940. if (detect().browser.isFirefox()) {
  941. return Optional.none();
  942. } else {
  943. return Optional.from(win['visualViewport']);
  944. }
  945. };
  946. var bounds = function (x, y, width, height) {
  947. return {
  948. x: x,
  949. y: y,
  950. width: width,
  951. height: height,
  952. right: x + width,
  953. bottom: y + height
  954. };
  955. };
  956. var getBounds = function (_win) {
  957. var win = _win === undefined ? window : _win;
  958. var doc = win.document;
  959. var scroll = get$1(SugarElement.fromDom(doc));
  960. return get(win).fold(function () {
  961. var html = win.document.documentElement;
  962. var width = html.clientWidth;
  963. var height = html.clientHeight;
  964. return bounds(scroll.left, scroll.top, width, height);
  965. }, function (visualViewport) {
  966. return bounds(Math.max(visualViewport.pageLeft, scroll.left), Math.max(visualViewport.pageTop, scroll.top), visualViewport.width, visualViewport.height);
  967. });
  968. };
  969. var bind = function (name, callback, _win) {
  970. return get(_win).map(function (visualViewport) {
  971. var handler = function (e) {
  972. return callback(fromRawEvent(e));
  973. };
  974. visualViewport.addEventListener(name, handler);
  975. return {
  976. unbind: function () {
  977. return visualViewport.removeEventListener(name, handler);
  978. }
  979. };
  980. }).getOrThunk(function () {
  981. return { unbind: noop };
  982. });
  983. };
  984. var global$2 = tinymce.util.Tools.resolve('tinymce.dom.DOMUtils');
  985. var global$1 = tinymce.util.Tools.resolve('tinymce.Env');
  986. var global = tinymce.util.Tools.resolve('tinymce.util.Delay');
  987. var fireFullscreenStateChanged = function (editor, state) {
  988. editor.fire('FullscreenStateChanged', { state: state });
  989. };
  990. var getFullscreenNative = function (editor) {
  991. return editor.getParam('fullscreen_native', false, 'boolean');
  992. };
  993. var getFullscreenRoot = function (editor) {
  994. var elem = SugarElement.fromDom(editor.getElement());
  995. return getShadowRoot(elem).map(getShadowHost).getOrThunk(function () {
  996. return getBody(owner(elem));
  997. });
  998. };
  999. var getFullscreenElement = function (root) {
  1000. if (root.fullscreenElement !== undefined) {
  1001. return root.fullscreenElement;
  1002. } else if (root.msFullscreenElement !== undefined) {
  1003. return root.msFullscreenElement;
  1004. } else if (root.webkitFullscreenElement !== undefined) {
  1005. return root.webkitFullscreenElement;
  1006. } else {
  1007. return null;
  1008. }
  1009. };
  1010. var getFullscreenchangeEventName = function () {
  1011. if (document.fullscreenElement !== undefined) {
  1012. return 'fullscreenchange';
  1013. } else if (document.msFullscreenElement !== undefined) {
  1014. return 'MSFullscreenChange';
  1015. } else if (document.webkitFullscreenElement !== undefined) {
  1016. return 'webkitfullscreenchange';
  1017. } else {
  1018. return 'fullscreenchange';
  1019. }
  1020. };
  1021. var requestFullscreen = function (sugarElem) {
  1022. var elem = sugarElem.dom;
  1023. if (elem.requestFullscreen) {
  1024. elem.requestFullscreen();
  1025. } else if (elem.msRequestFullscreen) {
  1026. elem.msRequestFullscreen();
  1027. } else if (elem.webkitRequestFullScreen) {
  1028. elem.webkitRequestFullScreen();
  1029. }
  1030. };
  1031. var exitFullscreen = function (sugarDoc) {
  1032. var doc = sugarDoc.dom;
  1033. if (doc.exitFullscreen) {
  1034. doc.exitFullscreen();
  1035. } else if (doc.msExitFullscreen) {
  1036. doc.msExitFullscreen();
  1037. } else if (doc.webkitCancelFullScreen) {
  1038. doc.webkitCancelFullScreen();
  1039. }
  1040. };
  1041. var isFullscreenElement = function (elem) {
  1042. return elem.dom === getFullscreenElement(owner(elem).dom);
  1043. };
  1044. var ancestors$1 = function (scope, predicate, isRoot) {
  1045. return filter$1(parents(scope, isRoot), predicate);
  1046. };
  1047. var siblings$1 = function (scope, predicate) {
  1048. return filter$1(siblings$2(scope), predicate);
  1049. };
  1050. var all = function (selector) {
  1051. return all$1(selector);
  1052. };
  1053. var ancestors = function (scope, selector, isRoot) {
  1054. return ancestors$1(scope, function (e) {
  1055. return is(e, selector);
  1056. }, isRoot);
  1057. };
  1058. var siblings = function (scope, selector) {
  1059. return siblings$1(scope, function (e) {
  1060. return is(e, selector);
  1061. });
  1062. };
  1063. var attr = 'data-ephox-mobile-fullscreen-style';
  1064. var siblingStyles = 'display:none!important;';
  1065. var ancestorPosition = 'position:absolute!important;';
  1066. var ancestorStyles = 'top:0!important;left:0!important;margin:0!important;padding:0!important;width:100%!important;height:100%!important;overflow:visible!important;';
  1067. var bgFallback = 'background-color:rgb(255,255,255)!important;';
  1068. var isAndroid = global$1.os.isAndroid();
  1069. var matchColor = function (editorBody) {
  1070. var color = get$2(editorBody, 'background-color');
  1071. return color !== undefined && color !== '' ? 'background-color:' + color + '!important' : bgFallback;
  1072. };
  1073. var clobberStyles = function (dom, container, editorBody) {
  1074. var gatherSiblings = function (element) {
  1075. return siblings(element, '*:not(.tox-silver-sink)');
  1076. };
  1077. var clobber = function (clobberStyle) {
  1078. return function (element) {
  1079. var styles = get$3(element, 'style');
  1080. var backup = styles === undefined ? 'no-styles' : styles.trim();
  1081. if (backup === clobberStyle) {
  1082. return;
  1083. } else {
  1084. set(element, attr, backup);
  1085. setAll(element, dom.parseStyle(clobberStyle));
  1086. }
  1087. };
  1088. };
  1089. var ancestors$1 = ancestors(container, '*');
  1090. var siblings$1 = bind$3(ancestors$1, gatherSiblings);
  1091. var bgColor = matchColor(editorBody);
  1092. each$1(siblings$1, clobber(siblingStyles));
  1093. each$1(ancestors$1, clobber(ancestorPosition + ancestorStyles + bgColor));
  1094. var containerStyles = isAndroid === true ? '' : ancestorPosition;
  1095. clobber(containerStyles + ancestorStyles + bgColor)(container);
  1096. };
  1097. var restoreStyles = function (dom) {
  1098. var clobberedEls = all('[' + attr + ']');
  1099. each$1(clobberedEls, function (element) {
  1100. var restore = get$3(element, attr);
  1101. if (restore !== 'no-styles') {
  1102. setAll(element, dom.parseStyle(restore));
  1103. } else {
  1104. remove(element, 'style');
  1105. }
  1106. remove(element, attr);
  1107. });
  1108. };
  1109. var DOM = global$2.DOM;
  1110. var getScrollPos = function () {
  1111. return getBounds(window);
  1112. };
  1113. var setScrollPos = function (pos) {
  1114. return window.scrollTo(pos.x, pos.y);
  1115. };
  1116. var viewportUpdate = get().fold(function () {
  1117. return {
  1118. bind: noop,
  1119. unbind: noop
  1120. };
  1121. }, function (visualViewport) {
  1122. var editorContainer = value();
  1123. var resizeBinder = unbindable();
  1124. var scrollBinder = unbindable();
  1125. var refreshScroll = function () {
  1126. document.body.scrollTop = 0;
  1127. document.documentElement.scrollTop = 0;
  1128. };
  1129. var refreshVisualViewport = function () {
  1130. window.requestAnimationFrame(function () {
  1131. editorContainer.on(function (container) {
  1132. return setAll(container, {
  1133. top: visualViewport.offsetTop + 'px',
  1134. left: visualViewport.offsetLeft + 'px',
  1135. height: visualViewport.height + 'px',
  1136. width: visualViewport.width + 'px'
  1137. });
  1138. });
  1139. });
  1140. };
  1141. var update = global.throttle(function () {
  1142. refreshScroll();
  1143. refreshVisualViewport();
  1144. }, 50);
  1145. var bind$1 = function (element) {
  1146. editorContainer.set(element);
  1147. update();
  1148. resizeBinder.set(bind('resize', update));
  1149. scrollBinder.set(bind('scroll', update));
  1150. };
  1151. var unbind = function () {
  1152. editorContainer.on(function () {
  1153. resizeBinder.clear();
  1154. scrollBinder.clear();
  1155. });
  1156. editorContainer.clear();
  1157. };
  1158. return {
  1159. bind: bind$1,
  1160. unbind: unbind
  1161. };
  1162. });
  1163. var toggleFullscreen = function (editor, fullscreenState) {
  1164. var body = document.body;
  1165. var documentElement = document.documentElement;
  1166. var editorContainer = editor.getContainer();
  1167. var editorContainerS = SugarElement.fromDom(editorContainer);
  1168. var fullscreenRoot = getFullscreenRoot(editor);
  1169. var fullscreenInfo = fullscreenState.get();
  1170. var editorBody = SugarElement.fromDom(editor.getBody());
  1171. var isTouch = global$1.deviceType.isTouch();
  1172. var editorContainerStyle = editorContainer.style;
  1173. var iframe = editor.iframeElement;
  1174. var iframeStyle = iframe.style;
  1175. var handleClasses = function (handler) {
  1176. handler(body, 'tox-fullscreen');
  1177. handler(documentElement, 'tox-fullscreen');
  1178. handler(editorContainer, 'tox-fullscreen');
  1179. getShadowRoot(editorContainerS).map(function (root) {
  1180. return getShadowHost(root).dom;
  1181. }).each(function (host) {
  1182. handler(host, 'tox-fullscreen');
  1183. handler(host, 'tox-shadowhost');
  1184. });
  1185. };
  1186. var cleanup = function () {
  1187. if (isTouch) {
  1188. restoreStyles(editor.dom);
  1189. }
  1190. handleClasses(DOM.removeClass);
  1191. viewportUpdate.unbind();
  1192. Optional.from(fullscreenState.get()).each(function (info) {
  1193. return info.fullscreenChangeHandler.unbind();
  1194. });
  1195. };
  1196. if (!fullscreenInfo) {
  1197. var fullscreenChangeHandler = bind$1(owner(fullscreenRoot), getFullscreenchangeEventName(), function (_evt) {
  1198. if (getFullscreenNative(editor)) {
  1199. if (!isFullscreenElement(fullscreenRoot) && fullscreenState.get() !== null) {
  1200. toggleFullscreen(editor, fullscreenState);
  1201. }
  1202. }
  1203. });
  1204. var newFullScreenInfo = {
  1205. scrollPos: getScrollPos(),
  1206. containerWidth: editorContainerStyle.width,
  1207. containerHeight: editorContainerStyle.height,
  1208. containerTop: editorContainerStyle.top,
  1209. containerLeft: editorContainerStyle.left,
  1210. iframeWidth: iframeStyle.width,
  1211. iframeHeight: iframeStyle.height,
  1212. fullscreenChangeHandler: fullscreenChangeHandler
  1213. };
  1214. if (isTouch) {
  1215. clobberStyles(editor.dom, editorContainerS, editorBody);
  1216. }
  1217. iframeStyle.width = iframeStyle.height = '100%';
  1218. editorContainerStyle.width = editorContainerStyle.height = '';
  1219. handleClasses(DOM.addClass);
  1220. viewportUpdate.bind(editorContainerS);
  1221. editor.on('remove', cleanup);
  1222. fullscreenState.set(newFullScreenInfo);
  1223. if (getFullscreenNative(editor)) {
  1224. requestFullscreen(fullscreenRoot);
  1225. }
  1226. fireFullscreenStateChanged(editor, true);
  1227. } else {
  1228. fullscreenInfo.fullscreenChangeHandler.unbind();
  1229. if (getFullscreenNative(editor) && isFullscreenElement(fullscreenRoot)) {
  1230. exitFullscreen(owner(fullscreenRoot));
  1231. }
  1232. iframeStyle.width = fullscreenInfo.iframeWidth;
  1233. iframeStyle.height = fullscreenInfo.iframeHeight;
  1234. editorContainerStyle.width = fullscreenInfo.containerWidth;
  1235. editorContainerStyle.height = fullscreenInfo.containerHeight;
  1236. editorContainerStyle.top = fullscreenInfo.containerTop;
  1237. editorContainerStyle.left = fullscreenInfo.containerLeft;
  1238. setScrollPos(fullscreenInfo.scrollPos);
  1239. fullscreenState.set(null);
  1240. fireFullscreenStateChanged(editor, false);
  1241. cleanup();
  1242. editor.off('remove', cleanup);
  1243. }
  1244. };
  1245. var register$1 = function (editor, fullscreenState) {
  1246. editor.addCommand('mceFullScreen', function () {
  1247. toggleFullscreen(editor, fullscreenState);
  1248. });
  1249. };
  1250. var makeSetupHandler = function (editor, fullscreenState) {
  1251. return function (api) {
  1252. api.setActive(fullscreenState.get() !== null);
  1253. var editorEventCallback = function (e) {
  1254. return api.setActive(e.state);
  1255. };
  1256. editor.on('FullscreenStateChanged', editorEventCallback);
  1257. return function () {
  1258. return editor.off('FullscreenStateChanged', editorEventCallback);
  1259. };
  1260. };
  1261. };
  1262. var register = function (editor, fullscreenState) {
  1263. var onAction = function () {
  1264. return editor.execCommand('mceFullScreen');
  1265. };
  1266. editor.ui.registry.addToggleMenuItem('fullscreen', {
  1267. text: 'Fullscreen',
  1268. icon: 'fullscreen',
  1269. shortcut: 'Meta+Shift+F',
  1270. onAction: onAction,
  1271. onSetup: makeSetupHandler(editor, fullscreenState)
  1272. });
  1273. editor.ui.registry.addToggleButton('fullscreen', {
  1274. tooltip: 'Fullscreen',
  1275. icon: 'fullscreen',
  1276. onAction: onAction,
  1277. onSetup: makeSetupHandler(editor, fullscreenState)
  1278. });
  1279. };
  1280. function Plugin () {
  1281. global$3.add('fullscreen', function (editor) {
  1282. var fullscreenState = Cell(null);
  1283. if (editor.inline) {
  1284. return get$5(fullscreenState);
  1285. }
  1286. register$1(editor, fullscreenState);
  1287. register(editor, fullscreenState);
  1288. editor.addShortcut('Meta+Shift+F', '', 'mceFullScreen');
  1289. return get$5(fullscreenState);
  1290. });
  1291. }
  1292. Plugin();
  1293. }());