10 lines
9.9 KiB
JavaScript
10 lines
9.9 KiB
JavaScript
|
/*!
|
||
|
* Tiny Export plugin
|
||
|
*
|
||
|
* Copyright (c) 2023 Ephox Corporation DBA Tiny Technologies, Inc.
|
||
|
* Licensed under the Tiny commercial license. See https://www.tiny.cloud/legal/
|
||
|
*
|
||
|
* Version: 2.1.0-76
|
||
|
*/
|
||
|
|
||
|
!function(){"use strict";const e=e=>parseInt(e,10),t=(e,t)=>{const r=e-t;return 0===r?0:r>0?1:-1},r=(e,t,r)=>({major:e,minor:t,patch:r}),o=t=>{const o=/([0-9]+)\.([0-9]+)\.([0-9]+)(?:(\-.+)?)/.exec(t);return o?r(e(o[1]),e(o[2]),e(o[3])):r(0,0,0)},n=e=>t=>(e=>{const t=typeof e;return null===e?"null":"object"===t&&Array.isArray(e)?"array":"object"===t&&(r=o=e,(n=String).prototype.isPrototypeOf(r)||(null===(s=o.constructor)||void 0===s?void 0:s.name)===n.name)?"string":t;var r,o,n,s})(t)===e,s=e=>t=>typeof t===e,i=n("string"),a=n("array"),l=s("boolean"),c=(void 0,e=>undefined===e);const u=e=>!(e=>null==e)(e),d=s("function"),m=s("number"),p=e=>()=>e;function h(e,...t){return(...r)=>{const o=t.concat(r);return e.apply(null,o)}}const g=p(!1);class y{constructor(e,t){this.tag=e,this.value=t}static some(e){return new y(!0,e)}static none(){return y.singletonNone}fold(e,t){return this.tag?t(this.value):e()}isSome(){return this.tag}isNone(){return!this.tag}map(e){return this.tag?y.some(e(this.value)):y.none()}bind(e){return this.tag?e(this.value):y.none()}exists(e){return this.tag&&e(this.value)}forall(e){return!this.tag||e(this.value)}filter(e){return!this.tag||e(this.value)?this:y.none()}getOr(e){return this.tag?this.value:e}or(e){return this.tag?this:e}getOrThunk(e){return this.tag?this.value:e()}orThunk(e){return this.tag?this:e()}getOrDie(e){if(this.tag)return this.value;throw new Error(null!=e?e:"Called getOrDie on None")}static from(e){return u(e)?y.some(e):y.none()}getOrNull(){return this.tag?this.value:null}getOrUndefined(){return this.value}each(e){this.tag&&e(this.value)}toArray(){return this.tag?[this.value]:[]}toString(){return this.tag?`some(${this.value})`:"none()"}}y.singletonNone=new y(!1);const f=Array.prototype.indexOf,v=(e,t)=>{const r=e.length,o=new Array(r);for(let n=0;n<r;n++){const r=e[n];o[n]=t(r,n)}return o},_=(e,t)=>{for(let r=0,o=e.length;r<o;r++)t(e[r],r)},x=(e,t)=>((e,t,r)=>{for(let o=0,n=e.length;o<n;o++){const n=e[o];if(t(n,o))return y.some(n);if(r(n,o))break}return y.none()})(e,t,g),b=Object.keys,w=Object.hasOwnProperty,P=(e,t,r=!1)=>fetch(e,{credentials:r?"include":"same-origin",headers:t}).then((async e=>{const t=await e.blob();return{ok:e.ok,status:e.status,blob:t}}),(()=>({ok:!1,status:0}))),k=[{code:404,message:"Could not find Image Proxy"},{code:403,message:"Rejected request"},{code:0,message:"Incorrect Image Proxy URL"}],j=[{type:"not_found",message:"Failed to load image."},{type:"key_missing",message:"The request did not include an api key."},{type:"key_not_found",message:"The provided api key could not be found."},{type:"domain_not_trusted",message:"The api key is not valid for the request origins."}],O=e=>{const t=(e=>"ImageProxy HTTP error: "+x(k,(t=>e===t.code)).fold(p("Unknown ImageProxy error"),(e=>e.message)))(e);return Promise.reject(t)},I=e=>x(j,(t=>t.type===e)).fold(p("Unknown service error"),(e=>e.message)),R=e=>{const t=(e=>{try{return y.some(JSON.parse(e))}catch(e){return y.none()}})(e);return"ImageProxy Service error: "+t.bind((e=>((e,t)=>{const r=(o=(e,t)=>u(e)?e[t]:void 0,n=e,_(t,((e,t)=>{n=o(n,e)})),n);var o,n;return y.from(r)})(e,["error","type"]).map(I))).getOr("Invalid JSON in service error message")},S=(e,t)=>{const r={"Content-Type":"application/json;charset=UTF-8","tiny-api-key":t};return P(((e,t)=>{const r=-1===e.indexOf("?")?"?":"&";return/[?&]apiKey=/.test(e)?e:e+r+"apiKey="+encodeURIComponent(t)})(e,t),r).then((e=>{return e.ok?Promise.resolve(e.blob):((e,t)=>"application/json"===(null==t?void 0:t.type)&&(400===e||403===e||404===e||500===e))(t=e.status,r=e.blob)?(e=>(e=>new Promise(((t,r)=>{const o=new FileReader;o.onload=()=>{t(o.result)},o.onerror=e=>{r(e)},o.readAsText(e)})))(e).then((e=>{const t=R(e);return Promise.reject(t)})))(r):O(t);var t,r}))},U=e=>t=>t.options.get(e),C=e=>{return"clientpdf"===e?"PDF":""===(t=e)?"":t.charAt(0).toUpperCase()+t.substring(1);var t},T=U("export_formats"),A=U("export_ignore_elements"),N=U("export_image_proxy_max_in_flight"),E=U("content_style"),F=U("content_css_cors"),L=e=>new Promise((t=>{const r=new FileReader;r.onload=()=>{t
|