tinymce_plugins_imagetools.js 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493
  1. import {
  2. __commonJS
  3. } from "./chunk-2LSFTFF7.js";
  4. // node_modules/.pnpm/tinymce@5.10.7/node_modules/tinymce/plugins/imagetools/plugin.js
  5. var require_plugin = __commonJS({
  6. "node_modules/.pnpm/tinymce@5.10.7/node_modules/tinymce/plugins/imagetools/plugin.js"() {
  7. (function() {
  8. "use strict";
  9. var Cell = function(initial) {
  10. var value = initial;
  11. var get = function() {
  12. return value;
  13. };
  14. var set = function(v) {
  15. value = v;
  16. };
  17. return {
  18. get,
  19. set
  20. };
  21. };
  22. var global$5 = tinymce.util.Tools.resolve("tinymce.PluginManager");
  23. var global$4 = tinymce.util.Tools.resolve("tinymce.util.Tools");
  24. var typeOf = function(x) {
  25. var t = typeof x;
  26. if (x === null) {
  27. return "null";
  28. } else if (t === "object" && (Array.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === "Array")) {
  29. return "array";
  30. } else if (t === "object" && (String.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === "String")) {
  31. return "string";
  32. } else {
  33. return t;
  34. }
  35. };
  36. var isType = function(type) {
  37. return function(value) {
  38. return typeOf(value) === type;
  39. };
  40. };
  41. var isSimpleType = function(type) {
  42. return function(value) {
  43. return typeof value === type;
  44. };
  45. };
  46. var isArray = isType("array");
  47. var isNullable = function(a) {
  48. return a === null || a === void 0;
  49. };
  50. var isNonNullable = function(a) {
  51. return !isNullable(a);
  52. };
  53. var isFunction = isSimpleType("function");
  54. var noop = function() {
  55. };
  56. var constant = function(value) {
  57. return function() {
  58. return value;
  59. };
  60. };
  61. var identity = function(x) {
  62. return x;
  63. };
  64. var never = constant(false);
  65. var always = constant(true);
  66. var none = function() {
  67. return NONE;
  68. };
  69. var NONE = function() {
  70. var call = function(thunk) {
  71. return thunk();
  72. };
  73. var id = identity;
  74. var me = {
  75. fold: function(n, _s) {
  76. return n();
  77. },
  78. isSome: never,
  79. isNone: always,
  80. getOr: id,
  81. getOrThunk: call,
  82. getOrDie: function(msg) {
  83. throw new Error(msg || "error: getOrDie called on none.");
  84. },
  85. getOrNull: constant(null),
  86. getOrUndefined: constant(void 0),
  87. or: id,
  88. orThunk: call,
  89. map: none,
  90. each: noop,
  91. bind: none,
  92. exists: never,
  93. forall: always,
  94. filter: function() {
  95. return none();
  96. },
  97. toArray: function() {
  98. return [];
  99. },
  100. toString: constant("none()")
  101. };
  102. return me;
  103. }();
  104. var some = function(a) {
  105. var constant_a = constant(a);
  106. var self2 = function() {
  107. return me;
  108. };
  109. var bind = function(f) {
  110. return f(a);
  111. };
  112. var me = {
  113. fold: function(n, s) {
  114. return s(a);
  115. },
  116. isSome: always,
  117. isNone: never,
  118. getOr: constant_a,
  119. getOrThunk: constant_a,
  120. getOrDie: constant_a,
  121. getOrNull: constant_a,
  122. getOrUndefined: constant_a,
  123. or: self2,
  124. orThunk: self2,
  125. map: function(f) {
  126. return some(f(a));
  127. },
  128. each: function(f) {
  129. f(a);
  130. },
  131. bind,
  132. exists: bind,
  133. forall: bind,
  134. filter: function(f) {
  135. return f(a) ? me : NONE;
  136. },
  137. toArray: function() {
  138. return [a];
  139. },
  140. toString: function() {
  141. return "some(" + a + ")";
  142. }
  143. };
  144. return me;
  145. };
  146. var from = function(value) {
  147. return value === null || value === void 0 ? NONE : some(value);
  148. };
  149. var Optional = {
  150. some,
  151. none,
  152. from
  153. };
  154. var exports$1 = {}, module2 = { exports: exports$1 };
  155. (function(define, exports2, module3, require2) {
  156. (function(global2, factory) {
  157. typeof exports2 === "object" && typeof module3 !== "undefined" ? module3.exports = factory() : typeof define === "function" && define.amd ? define(factory) : (global2 = typeof globalThis !== "undefined" ? globalThis : global2 || self, global2.EphoxContactWrapper = factory());
  158. })(this, function() {
  159. var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
  160. var promise = { exports: {} };
  161. (function(module4) {
  162. (function(root) {
  163. var setTimeoutFunc = setTimeout;
  164. function noop2() {
  165. }
  166. function bind(fn, thisArg) {
  167. return function() {
  168. fn.apply(thisArg, arguments);
  169. };
  170. }
  171. function Promise2(fn) {
  172. if (typeof this !== "object")
  173. throw new TypeError("Promises must be constructed via new");
  174. if (typeof fn !== "function")
  175. throw new TypeError("not a function");
  176. this._state = 0;
  177. this._handled = false;
  178. this._value = void 0;
  179. this._deferreds = [];
  180. doResolve(fn, this);
  181. }
  182. function handle(self2, deferred) {
  183. while (self2._state === 3) {
  184. self2 = self2._value;
  185. }
  186. if (self2._state === 0) {
  187. self2._deferreds.push(deferred);
  188. return;
  189. }
  190. self2._handled = true;
  191. Promise2._immediateFn(function() {
  192. var cb = self2._state === 1 ? deferred.onFulfilled : deferred.onRejected;
  193. if (cb === null) {
  194. (self2._state === 1 ? resolve : reject)(deferred.promise, self2._value);
  195. return;
  196. }
  197. var ret;
  198. try {
  199. ret = cb(self2._value);
  200. } catch (e) {
  201. reject(deferred.promise, e);
  202. return;
  203. }
  204. resolve(deferred.promise, ret);
  205. });
  206. }
  207. function resolve(self2, newValue) {
  208. try {
  209. if (newValue === self2)
  210. throw new TypeError("A promise cannot be resolved with itself.");
  211. if (newValue && (typeof newValue === "object" || typeof newValue === "function")) {
  212. var then = newValue.then;
  213. if (newValue instanceof Promise2) {
  214. self2._state = 3;
  215. self2._value = newValue;
  216. finale(self2);
  217. return;
  218. } else if (typeof then === "function") {
  219. doResolve(bind(then, newValue), self2);
  220. return;
  221. }
  222. }
  223. self2._state = 1;
  224. self2._value = newValue;
  225. finale(self2);
  226. } catch (e) {
  227. reject(self2, e);
  228. }
  229. }
  230. function reject(self2, newValue) {
  231. self2._state = 2;
  232. self2._value = newValue;
  233. finale(self2);
  234. }
  235. function finale(self2) {
  236. if (self2._state === 2 && self2._deferreds.length === 0) {
  237. Promise2._immediateFn(function() {
  238. if (!self2._handled) {
  239. Promise2._unhandledRejectionFn(self2._value);
  240. }
  241. });
  242. }
  243. for (var i = 0, len = self2._deferreds.length; i < len; i++) {
  244. handle(self2, self2._deferreds[i]);
  245. }
  246. self2._deferreds = null;
  247. }
  248. function Handler(onFulfilled, onRejected, promise2) {
  249. this.onFulfilled = typeof onFulfilled === "function" ? onFulfilled : null;
  250. this.onRejected = typeof onRejected === "function" ? onRejected : null;
  251. this.promise = promise2;
  252. }
  253. function doResolve(fn, self2) {
  254. var done = false;
  255. try {
  256. fn(function(value) {
  257. if (done)
  258. return;
  259. done = true;
  260. resolve(self2, value);
  261. }, function(reason) {
  262. if (done)
  263. return;
  264. done = true;
  265. reject(self2, reason);
  266. });
  267. } catch (ex) {
  268. if (done)
  269. return;
  270. done = true;
  271. reject(self2, ex);
  272. }
  273. }
  274. Promise2.prototype["catch"] = function(onRejected) {
  275. return this.then(null, onRejected);
  276. };
  277. Promise2.prototype.then = function(onFulfilled, onRejected) {
  278. var prom = new this.constructor(noop2);
  279. handle(this, new Handler(onFulfilled, onRejected, prom));
  280. return prom;
  281. };
  282. Promise2.all = function(arr) {
  283. var args = Array.prototype.slice.call(arr);
  284. return new Promise2(function(resolve2, reject2) {
  285. if (args.length === 0)
  286. return resolve2([]);
  287. var remaining = args.length;
  288. function res(i2, val) {
  289. try {
  290. if (val && (typeof val === "object" || typeof val === "function")) {
  291. var then = val.then;
  292. if (typeof then === "function") {
  293. then.call(val, function(val2) {
  294. res(i2, val2);
  295. }, reject2);
  296. return;
  297. }
  298. }
  299. args[i2] = val;
  300. if (--remaining === 0) {
  301. resolve2(args);
  302. }
  303. } catch (ex) {
  304. reject2(ex);
  305. }
  306. }
  307. for (var i = 0; i < args.length; i++) {
  308. res(i, args[i]);
  309. }
  310. });
  311. };
  312. Promise2.resolve = function(value) {
  313. if (value && typeof value === "object" && value.constructor === Promise2) {
  314. return value;
  315. }
  316. return new Promise2(function(resolve2) {
  317. resolve2(value);
  318. });
  319. };
  320. Promise2.reject = function(value) {
  321. return new Promise2(function(resolve2, reject2) {
  322. reject2(value);
  323. });
  324. };
  325. Promise2.race = function(values) {
  326. return new Promise2(function(resolve2, reject2) {
  327. for (var i = 0, len = values.length; i < len; i++) {
  328. values[i].then(resolve2, reject2);
  329. }
  330. });
  331. };
  332. Promise2._immediateFn = typeof setImmediate === "function" ? function(fn) {
  333. setImmediate(fn);
  334. } : function(fn) {
  335. setTimeoutFunc(fn, 0);
  336. };
  337. Promise2._unhandledRejectionFn = function _unhandledRejectionFn(err) {
  338. if (typeof console !== "undefined" && console) {
  339. console.warn("Possible Unhandled Promise Rejection:", err);
  340. }
  341. };
  342. Promise2._setImmediateFn = function _setImmediateFn(fn) {
  343. Promise2._immediateFn = fn;
  344. };
  345. Promise2._setUnhandledRejectionFn = function _setUnhandledRejectionFn(fn) {
  346. Promise2._unhandledRejectionFn = fn;
  347. };
  348. if (module4.exports) {
  349. module4.exports = Promise2;
  350. } else if (!root.Promise) {
  351. root.Promise = Promise2;
  352. }
  353. })(commonjsGlobal);
  354. })(promise);
  355. var promisePolyfill = promise.exports;
  356. var Global = function() {
  357. if (typeof window !== "undefined") {
  358. return window;
  359. } else {
  360. return Function("return this;")();
  361. }
  362. }();
  363. var promisePolyfill_1 = { boltExport: Global.Promise || promisePolyfill };
  364. return promisePolyfill_1;
  365. });
  366. })(void 0, exports$1, module2);
  367. var Promise$1 = module2.exports.boltExport;
  368. var create$1 = function(width, height) {
  369. return resize(document.createElement("canvas"), width, height);
  370. };
  371. var clone = function(canvas) {
  372. var tCanvas = create$1(canvas.width, canvas.height);
  373. var ctx = get2dContext(tCanvas);
  374. ctx.drawImage(canvas, 0, 0);
  375. return tCanvas;
  376. };
  377. var get2dContext = function(canvas) {
  378. return canvas.getContext("2d");
  379. };
  380. var resize = function(canvas, width, height) {
  381. canvas.width = width;
  382. canvas.height = height;
  383. return canvas;
  384. };
  385. var getWidth = function(image) {
  386. return image.naturalWidth || image.width;
  387. };
  388. var getHeight = function(image) {
  389. return image.naturalHeight || image.height;
  390. };
  391. var imageToBlob$2 = function(image) {
  392. var src = image.src;
  393. if (src.indexOf("data:") === 0) {
  394. return dataUriToBlob(src);
  395. }
  396. return anyUriToBlob(src);
  397. };
  398. var blobToImage$1 = function(blob) {
  399. return new Promise$1(function(resolve, reject) {
  400. var blobUrl = URL.createObjectURL(blob);
  401. var image = new Image();
  402. var removeListeners = function() {
  403. image.removeEventListener("load", loaded);
  404. image.removeEventListener("error", error);
  405. };
  406. var loaded = function() {
  407. removeListeners();
  408. resolve(image);
  409. };
  410. var error = function() {
  411. removeListeners();
  412. reject("Unable to load data of type " + blob.type + ": " + blobUrl);
  413. };
  414. image.addEventListener("load", loaded);
  415. image.addEventListener("error", error);
  416. image.src = blobUrl;
  417. if (image.complete) {
  418. setTimeout(loaded, 0);
  419. }
  420. });
  421. };
  422. var anyUriToBlob = function(url) {
  423. return new Promise$1(function(resolve, reject) {
  424. var xhr = new XMLHttpRequest();
  425. xhr.open("GET", url, true);
  426. xhr.responseType = "blob";
  427. xhr.onload = function() {
  428. if (this.status === 200) {
  429. resolve(this.response);
  430. }
  431. };
  432. xhr.onerror = function() {
  433. var _this = this;
  434. var corsError = function() {
  435. var obj = new Error("No access to download image");
  436. obj.code = 18;
  437. obj.name = "SecurityError";
  438. return obj;
  439. };
  440. var genericError = function() {
  441. return new Error("Error " + _this.status + " downloading image");
  442. };
  443. reject(this.status === 0 ? corsError() : genericError());
  444. };
  445. xhr.send();
  446. });
  447. };
  448. var dataUriToBlobSync = function(uri) {
  449. var data = uri.split(",");
  450. var matches = /data:([^;]+)/.exec(data[0]);
  451. if (!matches) {
  452. return Optional.none();
  453. }
  454. var mimetype = matches[1];
  455. var base64 = data[1];
  456. var sliceSize = 1024;
  457. var byteCharacters = atob(base64);
  458. var bytesLength = byteCharacters.length;
  459. var slicesCount = Math.ceil(bytesLength / sliceSize);
  460. var byteArrays = new Array(slicesCount);
  461. for (var sliceIndex = 0; sliceIndex < slicesCount; ++sliceIndex) {
  462. var begin = sliceIndex * sliceSize;
  463. var end = Math.min(begin + sliceSize, bytesLength);
  464. var bytes = new Array(end - begin);
  465. for (var offset = begin, i = 0; offset < end; ++i, ++offset) {
  466. bytes[i] = byteCharacters[offset].charCodeAt(0);
  467. }
  468. byteArrays[sliceIndex] = new Uint8Array(bytes);
  469. }
  470. return Optional.some(new Blob(byteArrays, { type: mimetype }));
  471. };
  472. var dataUriToBlob = function(uri) {
  473. return new Promise$1(function(resolve, reject) {
  474. dataUriToBlobSync(uri).fold(function() {
  475. reject("uri is not base64: " + uri);
  476. }, resolve);
  477. });
  478. };
  479. var canvasToBlob = function(canvas, type, quality) {
  480. type = type || "image/png";
  481. if (isFunction(HTMLCanvasElement.prototype.toBlob)) {
  482. return new Promise$1(function(resolve, reject) {
  483. canvas.toBlob(function(blob) {
  484. if (blob) {
  485. resolve(blob);
  486. } else {
  487. reject();
  488. }
  489. }, type, quality);
  490. });
  491. } else {
  492. return dataUriToBlob(canvas.toDataURL(type, quality));
  493. }
  494. };
  495. var canvasToDataURL = function(canvas, type, quality) {
  496. type = type || "image/png";
  497. return canvas.toDataURL(type, quality);
  498. };
  499. var blobToCanvas = function(blob) {
  500. return blobToImage$1(blob).then(function(image) {
  501. revokeImageUrl(image);
  502. var canvas = create$1(getWidth(image), getHeight(image));
  503. var context = get2dContext(canvas);
  504. context.drawImage(image, 0, 0);
  505. return canvas;
  506. });
  507. };
  508. var blobToDataUri = function(blob) {
  509. return new Promise$1(function(resolve) {
  510. var reader = new FileReader();
  511. reader.onloadend = function() {
  512. resolve(reader.result);
  513. };
  514. reader.readAsDataURL(blob);
  515. });
  516. };
  517. var revokeImageUrl = function(image) {
  518. URL.revokeObjectURL(image.src);
  519. };
  520. var blobToImage = function(blob) {
  521. return blobToImage$1(blob);
  522. };
  523. var imageToBlob$1 = function(image) {
  524. return imageToBlob$2(image);
  525. };
  526. var nativeIndexOf = Array.prototype.indexOf;
  527. var rawIndexOf = function(ts, t) {
  528. return nativeIndexOf.call(ts, t);
  529. };
  530. var contains = function(xs, x) {
  531. return rawIndexOf(xs, x) > -1;
  532. };
  533. var each$1 = function(xs, f) {
  534. for (var i = 0, len = xs.length; i < len; i++) {
  535. var x = xs[i];
  536. f(x, i);
  537. }
  538. };
  539. var filter = function(xs, pred) {
  540. var r = [];
  541. for (var i = 0, len = xs.length; i < len; i++) {
  542. var x = xs[i];
  543. if (pred(x, i)) {
  544. r.push(x);
  545. }
  546. }
  547. return r;
  548. };
  549. var foldl = function(xs, f, acc) {
  550. each$1(xs, function(x, i) {
  551. acc = f(acc, x, i);
  552. });
  553. return acc;
  554. };
  555. var findUntil = function(xs, pred, until) {
  556. for (var i = 0, len = xs.length; i < len; i++) {
  557. var x = xs[i];
  558. if (pred(x, i)) {
  559. return Optional.some(x);
  560. } else if (until(x, i)) {
  561. break;
  562. }
  563. }
  564. return Optional.none();
  565. };
  566. var find = function(xs, pred) {
  567. return findUntil(xs, pred, never);
  568. };
  569. var forall = function(xs, pred) {
  570. for (var i = 0, len = xs.length; i < len; ++i) {
  571. var x = xs[i];
  572. if (pred(x, i) !== true) {
  573. return false;
  574. }
  575. }
  576. return true;
  577. };
  578. var keys = Object.keys;
  579. var each = function(obj, f) {
  580. var props = keys(obj);
  581. for (var k = 0, len = props.length; k < len; k++) {
  582. var i = props[k];
  583. var x = obj[i];
  584. f(x, i);
  585. }
  586. };
  587. var generate = function(cases) {
  588. if (!isArray(cases)) {
  589. throw new Error("cases must be an array");
  590. }
  591. if (cases.length === 0) {
  592. throw new Error("there must be at least one case");
  593. }
  594. var constructors = [];
  595. var adt = {};
  596. each$1(cases, function(acase, count2) {
  597. var keys$1 = keys(acase);
  598. if (keys$1.length !== 1) {
  599. throw new Error("one and only one name per case");
  600. }
  601. var key = keys$1[0];
  602. var value = acase[key];
  603. if (adt[key] !== void 0) {
  604. throw new Error("duplicate key detected:" + key);
  605. } else if (key === "cata") {
  606. throw new Error("cannot have a case named cata (sorry)");
  607. } else if (!isArray(value)) {
  608. throw new Error("case arguments must be an array");
  609. }
  610. constructors.push(key);
  611. adt[key] = function() {
  612. var args = [];
  613. for (var _i = 0; _i < arguments.length; _i++) {
  614. args[_i] = arguments[_i];
  615. }
  616. var argLength = args.length;
  617. if (argLength !== value.length) {
  618. throw new Error("Wrong number of arguments to case " + key + ". Expected " + value.length + " (" + value + "), got " + argLength);
  619. }
  620. var match = function(branches) {
  621. var branchKeys = keys(branches);
  622. if (constructors.length !== branchKeys.length) {
  623. throw new Error("Wrong number of arguments to match. Expected: " + constructors.join(",") + "\nActual: " + branchKeys.join(","));
  624. }
  625. var allReqd = forall(constructors, function(reqKey) {
  626. return contains(branchKeys, reqKey);
  627. });
  628. if (!allReqd) {
  629. throw new Error("Not all branches were specified when using match. Specified: " + branchKeys.join(", ") + "\nRequired: " + constructors.join(", "));
  630. }
  631. return branches[key].apply(null, args);
  632. };
  633. return {
  634. fold: function() {
  635. var foldArgs = [];
  636. for (var _i2 = 0; _i2 < arguments.length; _i2++) {
  637. foldArgs[_i2] = arguments[_i2];
  638. }
  639. if (foldArgs.length !== cases.length) {
  640. throw new Error("Wrong number of arguments to fold. Expected " + cases.length + ", got " + foldArgs.length);
  641. }
  642. var target = foldArgs[count2];
  643. return target.apply(null, args);
  644. },
  645. match,
  646. log: function(label) {
  647. console.log(label, {
  648. constructors,
  649. constructor: key,
  650. params: args
  651. });
  652. }
  653. };
  654. };
  655. });
  656. return adt;
  657. };
  658. var Adt = { generate };
  659. Adt.generate([
  660. {
  661. bothErrors: [
  662. "error1",
  663. "error2"
  664. ]
  665. },
  666. {
  667. firstError: [
  668. "error1",
  669. "value2"
  670. ]
  671. },
  672. {
  673. secondError: [
  674. "value1",
  675. "error2"
  676. ]
  677. },
  678. {
  679. bothValues: [
  680. "value1",
  681. "value2"
  682. ]
  683. }
  684. ]);
  685. var create = function(getCanvas, blob, uri) {
  686. var initialType = blob.type;
  687. var getType = constant(initialType);
  688. var toBlob = function() {
  689. return Promise$1.resolve(blob);
  690. };
  691. var toDataURL = constant(uri);
  692. var toBase64 = function() {
  693. return uri.split(",")[1];
  694. };
  695. var toAdjustedBlob = function(type, quality) {
  696. return getCanvas.then(function(canvas) {
  697. return canvasToBlob(canvas, type, quality);
  698. });
  699. };
  700. var toAdjustedDataURL = function(type, quality) {
  701. return getCanvas.then(function(canvas) {
  702. return canvasToDataURL(canvas, type, quality);
  703. });
  704. };
  705. var toAdjustedBase64 = function(type, quality) {
  706. return toAdjustedDataURL(type, quality).then(function(dataurl) {
  707. return dataurl.split(",")[1];
  708. });
  709. };
  710. var toCanvas = function() {
  711. return getCanvas.then(clone);
  712. };
  713. return {
  714. getType,
  715. toBlob,
  716. toDataURL,
  717. toBase64,
  718. toAdjustedBlob,
  719. toAdjustedDataURL,
  720. toAdjustedBase64,
  721. toCanvas
  722. };
  723. };
  724. var fromBlob = function(blob) {
  725. return blobToDataUri(blob).then(function(uri) {
  726. return create(blobToCanvas(blob), blob, uri);
  727. });
  728. };
  729. var fromCanvas = function(canvas, type) {
  730. return canvasToBlob(canvas, type).then(function(blob) {
  731. return create(Promise$1.resolve(canvas), blob, canvas.toDataURL());
  732. });
  733. };
  734. var ceilWithPrecision = function(num, precision) {
  735. if (precision === void 0) {
  736. precision = 2;
  737. }
  738. var mul = Math.pow(10, precision);
  739. var upper = Math.round(num * mul);
  740. return Math.ceil(upper / mul);
  741. };
  742. var rotate$2 = function(ir, angle) {
  743. return ir.toCanvas().then(function(canvas) {
  744. return applyRotate(canvas, ir.getType(), angle);
  745. });
  746. };
  747. var applyRotate = function(image, type, angle) {
  748. var degrees = angle < 0 ? 360 + angle : angle;
  749. var rad = degrees * Math.PI / 180;
  750. var width = image.width;
  751. var height = image.height;
  752. var sin = Math.sin(rad);
  753. var cos = Math.cos(rad);
  754. var newWidth = ceilWithPrecision(Math.abs(width * cos) + Math.abs(height * sin));
  755. var newHeight = ceilWithPrecision(Math.abs(width * sin) + Math.abs(height * cos));
  756. var canvas = create$1(newWidth, newHeight);
  757. var context = get2dContext(canvas);
  758. context.translate(newWidth / 2, newHeight / 2);
  759. context.rotate(rad);
  760. context.drawImage(image, -width / 2, -height / 2);
  761. return fromCanvas(canvas, type);
  762. };
  763. var flip$2 = function(ir, axis) {
  764. return ir.toCanvas().then(function(canvas) {
  765. return applyFlip(canvas, ir.getType(), axis);
  766. });
  767. };
  768. var applyFlip = function(image, type, axis) {
  769. var canvas = create$1(image.width, image.height);
  770. var context = get2dContext(canvas);
  771. if (axis === "v") {
  772. context.scale(1, -1);
  773. context.drawImage(image, 0, -canvas.height);
  774. } else {
  775. context.scale(-1, 1);
  776. context.drawImage(image, -canvas.width, 0);
  777. }
  778. return fromCanvas(canvas, type);
  779. };
  780. var flip$1 = function(ir, axis) {
  781. return flip$2(ir, axis);
  782. };
  783. var rotate$1 = function(ir, angle) {
  784. return rotate$2(ir, angle);
  785. };
  786. var sendRequest = function(url, headers, withCredentials) {
  787. if (withCredentials === void 0) {
  788. withCredentials = false;
  789. }
  790. return new Promise$1(function(resolve) {
  791. var xhr = new XMLHttpRequest();
  792. xhr.onreadystatechange = function() {
  793. if (xhr.readyState === 4) {
  794. resolve({
  795. status: xhr.status,
  796. blob: xhr.response
  797. });
  798. }
  799. };
  800. xhr.open("GET", url, true);
  801. xhr.withCredentials = withCredentials;
  802. each(headers, function(value, key) {
  803. xhr.setRequestHeader(key, value);
  804. });
  805. xhr.responseType = "blob";
  806. xhr.send();
  807. });
  808. };
  809. var readBlobText = function(blob) {
  810. return new Promise$1(function(resolve, reject) {
  811. var reader = new FileReader();
  812. reader.onload = function() {
  813. resolve(reader.result);
  814. };
  815. reader.onerror = function(e) {
  816. reject(e);
  817. };
  818. reader.readAsText(blob);
  819. });
  820. };
  821. var parseJson = function(text) {
  822. try {
  823. return Optional.some(JSON.parse(text));
  824. } catch (ex) {
  825. return Optional.none();
  826. }
  827. };
  828. var friendlyHttpErrors = [
  829. {
  830. code: 404,
  831. message: "Could not find Image Proxy"
  832. },
  833. {
  834. code: 403,
  835. message: "Rejected request"
  836. },
  837. {
  838. code: 0,
  839. message: "Incorrect Image Proxy URL"
  840. }
  841. ];
  842. var friendlyServiceErrors = [
  843. {
  844. type: "not_found",
  845. message: "Failed to load image."
  846. },
  847. {
  848. type: "key_missing",
  849. message: "The request did not include an api key."
  850. },
  851. {
  852. type: "key_not_found",
  853. message: "The provided api key could not be found."
  854. },
  855. {
  856. type: "domain_not_trusted",
  857. message: "The api key is not valid for the request origins."
  858. }
  859. ];
  860. var traverseJson = function(json, path) {
  861. var value = foldl(path, function(result, key) {
  862. return isNonNullable(result) ? result[key] : void 0;
  863. }, json);
  864. return Optional.from(value);
  865. };
  866. var isServiceErrorCode = function(code, blob) {
  867. return (blob === null || blob === void 0 ? void 0 : blob.type) === "application/json" && (code === 400 || code === 403 || code === 404 || code === 500);
  868. };
  869. var getHttpErrorMsg = function(status) {
  870. var message = find(friendlyHttpErrors, function(error) {
  871. return status === error.code;
  872. }).fold(constant("Unknown ImageProxy error"), function(error) {
  873. return error.message;
  874. });
  875. return "ImageProxy HTTP error: " + message;
  876. };
  877. var handleHttpError = function(status) {
  878. var message = getHttpErrorMsg(status);
  879. return Promise$1.reject(message);
  880. };
  881. var getServiceErrorMsg = function(type) {
  882. return find(friendlyServiceErrors, function(error) {
  883. return error.type === type;
  884. }).fold(constant("Unknown service error"), function(error) {
  885. return error.message;
  886. });
  887. };
  888. var getServiceError = function(text) {
  889. var serviceError = parseJson(text);
  890. var errorMsg = serviceError.bind(function(err) {
  891. return traverseJson(err, [
  892. "error",
  893. "type"
  894. ]).map(getServiceErrorMsg);
  895. }).getOr("Invalid JSON in service error message");
  896. return "ImageProxy Service error: " + errorMsg;
  897. };
  898. var handleServiceError = function(blob) {
  899. return readBlobText(blob).then(function(text) {
  900. var serviceError = getServiceError(text);
  901. return Promise$1.reject(serviceError);
  902. });
  903. };
  904. var handleServiceErrorResponse = function(status, blob) {
  905. return isServiceErrorCode(status, blob) ? handleServiceError(blob) : handleHttpError(status);
  906. };
  907. var appendApiKey = function(url, apiKey) {
  908. var separator = url.indexOf("?") === -1 ? "?" : "&";
  909. if (/[?&]apiKey=/.test(url)) {
  910. return url;
  911. } else {
  912. return url + separator + "apiKey=" + encodeURIComponent(apiKey);
  913. }
  914. };
  915. var isError = function(status) {
  916. return status < 200 || status >= 300;
  917. };
  918. var requestServiceBlob = function(url, apiKey) {
  919. var headers = {
  920. "Content-Type": "application/json;charset=UTF-8",
  921. "tiny-api-key": apiKey
  922. };
  923. return sendRequest(appendApiKey(url, apiKey), headers).then(function(result) {
  924. return isError(result.status) ? handleServiceErrorResponse(result.status, result.blob) : Promise$1.resolve(result.blob);
  925. });
  926. };
  927. var requestBlob = function(url, withCredentials) {
  928. return sendRequest(url, {}, withCredentials).then(function(result) {
  929. return isError(result.status) ? handleHttpError(result.status) : Promise$1.resolve(result.blob);
  930. });
  931. };
  932. var getUrl = function(url, apiKey, withCredentials) {
  933. if (withCredentials === void 0) {
  934. withCredentials = false;
  935. }
  936. return apiKey ? requestServiceBlob(url, apiKey) : requestBlob(url, withCredentials);
  937. };
  938. var blobToImageResult = function(blob) {
  939. return fromBlob(blob);
  940. };
  941. var ELEMENT = 1;
  942. var fromHtml = function(html, scope) {
  943. var doc = scope || document;
  944. var div = doc.createElement("div");
  945. div.innerHTML = html;
  946. if (!div.hasChildNodes() || div.childNodes.length > 1) {
  947. console.error("HTML does not have a single root node", html);
  948. throw new Error("HTML must have a single root node");
  949. }
  950. return fromDom(div.childNodes[0]);
  951. };
  952. var fromTag = function(tag, scope) {
  953. var doc = scope || document;
  954. var node = doc.createElement(tag);
  955. return fromDom(node);
  956. };
  957. var fromText = function(text, scope) {
  958. var doc = scope || document;
  959. var node = doc.createTextNode(text);
  960. return fromDom(node);
  961. };
  962. var fromDom = function(node) {
  963. if (node === null || node === void 0) {
  964. throw new Error("Node cannot be null or undefined");
  965. }
  966. return { dom: node };
  967. };
  968. var fromPoint = function(docElm, x, y) {
  969. return Optional.from(docElm.dom.elementFromPoint(x, y)).map(fromDom);
  970. };
  971. var SugarElement = {
  972. fromHtml,
  973. fromTag,
  974. fromText,
  975. fromDom,
  976. fromPoint
  977. };
  978. var is = function(element, selector) {
  979. var dom = element.dom;
  980. if (dom.nodeType !== ELEMENT) {
  981. return false;
  982. } else {
  983. var elem = dom;
  984. if (elem.matches !== void 0) {
  985. return elem.matches(selector);
  986. } else if (elem.msMatchesSelector !== void 0) {
  987. return elem.msMatchesSelector(selector);
  988. } else if (elem.webkitMatchesSelector !== void 0) {
  989. return elem.webkitMatchesSelector(selector);
  990. } else if (elem.mozMatchesSelector !== void 0) {
  991. return elem.mozMatchesSelector(selector);
  992. } else {
  993. throw new Error("Browser lacks native selectors");
  994. }
  995. }
  996. };
  997. typeof window !== "undefined" ? window : Function("return this;")();
  998. var child$1 = function(scope, predicate) {
  999. var pred = function(node) {
  1000. return predicate(SugarElement.fromDom(node));
  1001. };
  1002. var result = find(scope.dom.childNodes, pred);
  1003. return result.map(SugarElement.fromDom);
  1004. };
  1005. var child = function(scope, selector) {
  1006. return child$1(scope, function(e) {
  1007. return is(e, selector);
  1008. });
  1009. };
  1010. var global$3 = tinymce.util.Tools.resolve("tinymce.util.Delay");
  1011. var global$2 = tinymce.util.Tools.resolve("tinymce.util.Promise");
  1012. var global$1 = tinymce.util.Tools.resolve("tinymce.util.URI");
  1013. var getToolbarItems = function(editor) {
  1014. return editor.getParam("imagetools_toolbar", "rotateleft rotateright flipv fliph editimage imageoptions");
  1015. };
  1016. var getProxyUrl = function(editor) {
  1017. return editor.getParam("imagetools_proxy");
  1018. };
  1019. var getCorsHosts = function(editor) {
  1020. return editor.getParam("imagetools_cors_hosts", [], "string[]");
  1021. };
  1022. var getCredentialsHosts = function(editor) {
  1023. return editor.getParam("imagetools_credentials_hosts", [], "string[]");
  1024. };
  1025. var getFetchImage = function(editor) {
  1026. return Optional.from(editor.getParam("imagetools_fetch_image", null, "function"));
  1027. };
  1028. var getApiKey = function(editor) {
  1029. return editor.getParam("api_key", editor.getParam("imagetools_api_key", "", "string"), "string");
  1030. };
  1031. var getUploadTimeout = function(editor) {
  1032. return editor.getParam("images_upload_timeout", 3e4, "number");
  1033. };
  1034. var shouldReuseFilename = function(editor) {
  1035. return editor.getParam("images_reuse_filename", false, "boolean");
  1036. };
  1037. var getImageSize = function(img) {
  1038. var width, height;
  1039. var isPxValue = function(value) {
  1040. return /^[0-9\.]+px$/.test(value);
  1041. };
  1042. width = img.style.width;
  1043. height = img.style.height;
  1044. if (width || height) {
  1045. if (isPxValue(width) && isPxValue(height)) {
  1046. return {
  1047. w: parseInt(width, 10),
  1048. h: parseInt(height, 10)
  1049. };
  1050. }
  1051. return null;
  1052. }
  1053. width = img.width;
  1054. height = img.height;
  1055. if (width && height) {
  1056. return {
  1057. w: parseInt(width, 10),
  1058. h: parseInt(height, 10)
  1059. };
  1060. }
  1061. return null;
  1062. };
  1063. var setImageSize = function(img, size) {
  1064. var width, height;
  1065. if (size) {
  1066. width = img.style.width;
  1067. height = img.style.height;
  1068. if (width || height) {
  1069. img.style.width = size.w + "px";
  1070. img.style.height = size.h + "px";
  1071. img.removeAttribute("data-mce-style");
  1072. }
  1073. width = img.width;
  1074. height = img.height;
  1075. if (width || height) {
  1076. img.setAttribute("width", String(size.w));
  1077. img.setAttribute("height", String(size.h));
  1078. }
  1079. }
  1080. };
  1081. var getNaturalImageSize = function(img) {
  1082. return {
  1083. w: img.naturalWidth,
  1084. h: img.naturalHeight
  1085. };
  1086. };
  1087. var count = 0;
  1088. var getFigureImg = function(elem) {
  1089. return child(SugarElement.fromDom(elem), "img");
  1090. };
  1091. var isFigure = function(editor, elem) {
  1092. return editor.dom.is(elem, "figure");
  1093. };
  1094. var isImage = function(editor, imgNode) {
  1095. return editor.dom.is(imgNode, "img:not([data-mce-object],[data-mce-placeholder])");
  1096. };
  1097. var getEditableImage = function(editor, node) {
  1098. var isEditable = function(imgNode) {
  1099. return isImage(editor, imgNode) && (isLocalImage(editor, imgNode) || isCorsImage(editor, imgNode) || isNonNullable(getProxyUrl(editor)));
  1100. };
  1101. if (isFigure(editor, node)) {
  1102. return getFigureImg(node).bind(function(img) {
  1103. return isEditable(img.dom) ? Optional.some(img.dom) : Optional.none();
  1104. });
  1105. } else {
  1106. return isEditable(node) ? Optional.some(node) : Optional.none();
  1107. }
  1108. };
  1109. var displayError = function(editor, error) {
  1110. editor.notificationManager.open({
  1111. text: error,
  1112. type: "error"
  1113. });
  1114. };
  1115. var getSelectedImage = function(editor) {
  1116. var elem = editor.selection.getNode();
  1117. var figureElm = editor.dom.getParent(elem, "figure.image");
  1118. if (figureElm !== null && isFigure(editor, figureElm)) {
  1119. return getFigureImg(figureElm);
  1120. } else if (isImage(editor, elem)) {
  1121. return Optional.some(SugarElement.fromDom(elem));
  1122. } else {
  1123. return Optional.none();
  1124. }
  1125. };
  1126. var extractFilename = function(editor, url, group) {
  1127. var m = url.match(/(?:\/|^)(([^\/\?]+)\.(?:[a-z0-9.]+))(?:\?|$)/i);
  1128. return isNonNullable(m) ? editor.dom.encode(m[group]) : null;
  1129. };
  1130. var createId = function() {
  1131. return "imagetools" + count++;
  1132. };
  1133. var isLocalImage = function(editor, img) {
  1134. var url = img.src;
  1135. return url.indexOf("data:") === 0 || url.indexOf("blob:") === 0 || new global$1(url).host === editor.documentBaseURI.host;
  1136. };
  1137. var isCorsImage = function(editor, img) {
  1138. return global$4.inArray(getCorsHosts(editor), new global$1(img.src).host) !== -1;
  1139. };
  1140. var isCorsWithCredentialsImage = function(editor, img) {
  1141. return global$4.inArray(getCredentialsHosts(editor), new global$1(img.src).host) !== -1;
  1142. };
  1143. var defaultFetchImage = function(editor, img) {
  1144. if (isCorsImage(editor, img)) {
  1145. return getUrl(img.src, null, isCorsWithCredentialsImage(editor, img));
  1146. }
  1147. if (!isLocalImage(editor, img)) {
  1148. var proxyUrl = getProxyUrl(editor);
  1149. var src = proxyUrl + (proxyUrl.indexOf("?") === -1 ? "?" : "&") + "url=" + encodeURIComponent(img.src);
  1150. var apiKey = getApiKey(editor);
  1151. return getUrl(src, apiKey, false);
  1152. }
  1153. return imageToBlob$1(img);
  1154. };
  1155. var imageToBlob = function(editor, img) {
  1156. return getFetchImage(editor).fold(function() {
  1157. return defaultFetchImage(editor, img);
  1158. }, function(customFetchImage) {
  1159. return customFetchImage(img);
  1160. });
  1161. };
  1162. var findBlob = function(editor, img) {
  1163. var blobInfo = editor.editorUpload.blobCache.getByUri(img.src);
  1164. if (blobInfo) {
  1165. return global$2.resolve(blobInfo.blob());
  1166. }
  1167. return imageToBlob(editor, img);
  1168. };
  1169. var startTimedUpload = function(editor, imageUploadTimerState) {
  1170. var imageUploadTimer = global$3.setEditorTimeout(editor, function() {
  1171. editor.editorUpload.uploadImagesAuto();
  1172. }, getUploadTimeout(editor));
  1173. imageUploadTimerState.set(imageUploadTimer);
  1174. };
  1175. var cancelTimedUpload = function(imageUploadTimerState) {
  1176. global$3.clearTimeout(imageUploadTimerState.get());
  1177. };
  1178. var updateSelectedImage = function(editor, origBlob, ir, uploadImmediately, imageUploadTimerState, selectedImage, size) {
  1179. return ir.toBlob().then(function(blob) {
  1180. var uri, name, filename, blobInfo;
  1181. var blobCache = editor.editorUpload.blobCache;
  1182. uri = selectedImage.src;
  1183. var useFilename = origBlob.type === blob.type;
  1184. if (shouldReuseFilename(editor)) {
  1185. blobInfo = blobCache.getByUri(uri);
  1186. if (isNonNullable(blobInfo)) {
  1187. uri = blobInfo.uri();
  1188. name = blobInfo.name();
  1189. filename = blobInfo.filename();
  1190. } else {
  1191. name = extractFilename(editor, uri, 2);
  1192. filename = extractFilename(editor, uri, 1);
  1193. }
  1194. }
  1195. blobInfo = blobCache.create({
  1196. id: createId(),
  1197. blob,
  1198. base64: ir.toBase64(),
  1199. uri,
  1200. name,
  1201. filename: useFilename ? filename : void 0
  1202. });
  1203. blobCache.add(blobInfo);
  1204. editor.undoManager.transact(function() {
  1205. var imageLoadedHandler = function() {
  1206. editor.$(selectedImage).off("load", imageLoadedHandler);
  1207. editor.nodeChanged();
  1208. if (uploadImmediately) {
  1209. editor.editorUpload.uploadImagesAuto();
  1210. } else {
  1211. cancelTimedUpload(imageUploadTimerState);
  1212. startTimedUpload(editor, imageUploadTimerState);
  1213. }
  1214. };
  1215. editor.$(selectedImage).on("load", imageLoadedHandler);
  1216. if (size) {
  1217. editor.$(selectedImage).attr({
  1218. width: size.w,
  1219. height: size.h
  1220. });
  1221. }
  1222. editor.$(selectedImage).attr({ src: blobInfo.blobUri() }).removeAttr("data-mce-src");
  1223. });
  1224. return blobInfo;
  1225. });
  1226. };
  1227. var selectedImageOperation = function(editor, imageUploadTimerState, fn, size) {
  1228. return function() {
  1229. var imgOpt = getSelectedImage(editor);
  1230. return imgOpt.fold(function() {
  1231. displayError(editor, "Could not find selected image");
  1232. }, function(img) {
  1233. return editor._scanForImages().then(function() {
  1234. return findBlob(editor, img.dom);
  1235. }).then(function(blob) {
  1236. return blobToImageResult(blob).then(fn).then(function(imageResult) {
  1237. return updateSelectedImage(editor, blob, imageResult, false, imageUploadTimerState, img.dom, size);
  1238. });
  1239. }).catch(function(error) {
  1240. displayError(editor, error);
  1241. });
  1242. });
  1243. };
  1244. };
  1245. var rotate = function(editor, imageUploadTimerState, angle) {
  1246. return function() {
  1247. var imgOpt = getSelectedImage(editor);
  1248. var flippedSize = imgOpt.map(function(img) {
  1249. var size = getImageSize(img.dom);
  1250. return size ? {
  1251. w: size.h,
  1252. h: size.w
  1253. } : null;
  1254. }).getOrNull();
  1255. return selectedImageOperation(editor, imageUploadTimerState, function(imageResult) {
  1256. return rotate$1(imageResult, angle);
  1257. }, flippedSize)();
  1258. };
  1259. };
  1260. var flip = function(editor, imageUploadTimerState, axis) {
  1261. return function() {
  1262. return selectedImageOperation(editor, imageUploadTimerState, function(imageResult) {
  1263. return flip$1(imageResult, axis);
  1264. })();
  1265. };
  1266. };
  1267. var handleDialogBlob = function(editor, imageUploadTimerState, img, originalSize, blob) {
  1268. return blobToImage(blob).then(function(newImage) {
  1269. var newSize = getNaturalImageSize(newImage);
  1270. if (originalSize.w !== newSize.w || originalSize.h !== newSize.h) {
  1271. if (getImageSize(img)) {
  1272. setImageSize(img, newSize);
  1273. }
  1274. }
  1275. URL.revokeObjectURL(newImage.src);
  1276. return blob;
  1277. }).then(blobToImageResult).then(function(imageResult) {
  1278. return updateSelectedImage(editor, blob, imageResult, true, imageUploadTimerState, img);
  1279. });
  1280. };
  1281. var saveState = "save-state";
  1282. var disable = "disable";
  1283. var enable = "enable";
  1284. var createState = function(blob) {
  1285. return {
  1286. blob,
  1287. url: URL.createObjectURL(blob)
  1288. };
  1289. };
  1290. var makeOpen = function(editor, imageUploadTimerState) {
  1291. return function() {
  1292. var getLoadedSpec = function(currentState) {
  1293. return {
  1294. title: "Edit Image",
  1295. size: "large",
  1296. body: {
  1297. type: "panel",
  1298. items: [{
  1299. type: "imagetools",
  1300. name: "imagetools",
  1301. label: "Edit Image",
  1302. currentState
  1303. }]
  1304. },
  1305. buttons: [
  1306. {
  1307. type: "cancel",
  1308. name: "cancel",
  1309. text: "Cancel"
  1310. },
  1311. {
  1312. type: "submit",
  1313. name: "save",
  1314. text: "Save",
  1315. primary: true,
  1316. disabled: true
  1317. }
  1318. ],
  1319. onSubmit: function(api) {
  1320. var blob = api.getData().imagetools.blob;
  1321. originalImgOpt.each(function(originalImg) {
  1322. originalSizeOpt.each(function(originalSize) {
  1323. handleDialogBlob(editor, imageUploadTimerState, originalImg.dom, originalSize, blob);
  1324. });
  1325. });
  1326. api.close();
  1327. },
  1328. onCancel: noop,
  1329. onAction: function(api, details) {
  1330. switch (details.name) {
  1331. case saveState:
  1332. if (details.value) {
  1333. api.enable("save");
  1334. } else {
  1335. api.disable("save");
  1336. }
  1337. break;
  1338. case disable:
  1339. api.disable("save");
  1340. api.disable("cancel");
  1341. break;
  1342. case enable:
  1343. api.enable("cancel");
  1344. break;
  1345. }
  1346. }
  1347. };
  1348. };
  1349. var originalImgOpt = getSelectedImage(editor);
  1350. var originalSizeOpt = originalImgOpt.map(function(origImg) {
  1351. return getNaturalImageSize(origImg.dom);
  1352. });
  1353. originalImgOpt.each(function(img) {
  1354. getEditableImage(editor, img.dom).each(function(_) {
  1355. findBlob(editor, img.dom).then(function(blob) {
  1356. var state = createState(blob);
  1357. editor.windowManager.open(getLoadedSpec(state));
  1358. });
  1359. });
  1360. });
  1361. };
  1362. };
  1363. var register$2 = function(editor, imageUploadTimerState) {
  1364. global$4.each({
  1365. mceImageRotateLeft: rotate(editor, imageUploadTimerState, -90),
  1366. mceImageRotateRight: rotate(editor, imageUploadTimerState, 90),
  1367. mceImageFlipVertical: flip(editor, imageUploadTimerState, "v"),
  1368. mceImageFlipHorizontal: flip(editor, imageUploadTimerState, "h"),
  1369. mceEditImage: makeOpen(editor, imageUploadTimerState)
  1370. }, function(fn, cmd) {
  1371. editor.addCommand(cmd, fn);
  1372. });
  1373. };
  1374. var setup = function(editor, imageUploadTimerState, lastSelectedImageState) {
  1375. editor.on("NodeChange", function(e) {
  1376. var lastSelectedImage = lastSelectedImageState.get();
  1377. var selectedImage = getEditableImage(editor, e.element);
  1378. if (lastSelectedImage && !selectedImage.exists(function(img) {
  1379. return lastSelectedImage.src === img.src;
  1380. })) {
  1381. cancelTimedUpload(imageUploadTimerState);
  1382. editor.editorUpload.uploadImagesAuto();
  1383. lastSelectedImageState.set(null);
  1384. }
  1385. selectedImage.each(lastSelectedImageState.set);
  1386. });
  1387. };
  1388. var register$1 = function(editor) {
  1389. var changeHandlers = [];
  1390. var cmd = function(command) {
  1391. return function() {
  1392. return editor.execCommand(command);
  1393. };
  1394. };
  1395. var isEditableImage = function() {
  1396. return getSelectedImage(editor).exists(function(element) {
  1397. return getEditableImage(editor, element.dom).isSome();
  1398. });
  1399. };
  1400. var onSetup = function(api) {
  1401. var handler = function(isEditableImage2) {
  1402. return api.setDisabled(!isEditableImage2);
  1403. };
  1404. handler(isEditableImage());
  1405. changeHandlers = changeHandlers.concat([handler]);
  1406. return function() {
  1407. changeHandlers = filter(changeHandlers, function(h) {
  1408. return h !== handler;
  1409. });
  1410. };
  1411. };
  1412. editor.on("NodeChange", function() {
  1413. var isEditable = isEditableImage();
  1414. each$1(changeHandlers, function(handler) {
  1415. return handler(isEditable);
  1416. });
  1417. });
  1418. editor.ui.registry.addButton("rotateleft", {
  1419. tooltip: "Rotate counterclockwise",
  1420. icon: "rotate-left",
  1421. onAction: cmd("mceImageRotateLeft"),
  1422. onSetup
  1423. });
  1424. editor.ui.registry.addButton("rotateright", {
  1425. tooltip: "Rotate clockwise",
  1426. icon: "rotate-right",
  1427. onAction: cmd("mceImageRotateRight"),
  1428. onSetup
  1429. });
  1430. editor.ui.registry.addButton("flipv", {
  1431. tooltip: "Flip vertically",
  1432. icon: "flip-vertically",
  1433. onAction: cmd("mceImageFlipVertical"),
  1434. onSetup
  1435. });
  1436. editor.ui.registry.addButton("fliph", {
  1437. tooltip: "Flip horizontally",
  1438. icon: "flip-horizontally",
  1439. onAction: cmd("mceImageFlipHorizontal"),
  1440. onSetup
  1441. });
  1442. editor.ui.registry.addButton("editimage", {
  1443. tooltip: "Edit image",
  1444. icon: "edit-image",
  1445. onAction: cmd("mceEditImage"),
  1446. onSetup
  1447. });
  1448. editor.ui.registry.addButton("imageoptions", {
  1449. tooltip: "Image options",
  1450. icon: "image",
  1451. onAction: cmd("mceImage")
  1452. });
  1453. editor.ui.registry.addContextMenu("imagetools", {
  1454. update: function(element) {
  1455. return getEditableImage(editor, element).map(function(_) {
  1456. return {
  1457. text: "Edit image",
  1458. icon: "edit-image",
  1459. onAction: cmd("mceEditImage")
  1460. };
  1461. }).toArray();
  1462. }
  1463. });
  1464. };
  1465. var register = function(editor) {
  1466. editor.ui.registry.addContextToolbar("imagetools", {
  1467. items: getToolbarItems(editor),
  1468. predicate: function(elem) {
  1469. return getEditableImage(editor, elem).isSome();
  1470. },
  1471. position: "node",
  1472. scope: "node"
  1473. });
  1474. };
  1475. function Plugin() {
  1476. global$5.add("imagetools", function(editor) {
  1477. var imageUploadTimerState = Cell(0);
  1478. var lastSelectedImageState = Cell(null);
  1479. register$2(editor, imageUploadTimerState);
  1480. register$1(editor);
  1481. register(editor);
  1482. setup(editor, imageUploadTimerState, lastSelectedImageState);
  1483. });
  1484. }
  1485. Plugin();
  1486. })();
  1487. }
  1488. });
  1489. // node_modules/.pnpm/tinymce@5.10.7/node_modules/tinymce/plugins/imagetools/index.js
  1490. require_plugin();
  1491. //# sourceMappingURL=tinymce_plugins_imagetools.js.map