antosdk-apps/OpenPage/build/debug/main.js

81 lines
429 KiB
JavaScript
Raw Normal View History

2020-06-25 18:23:33 +02:00
(function(){var e,t,n;n=class n extends this.OS.application.BaseApplication{constructor(e){super("OpenPage",e)}main(){return this.eventSubscriptions=new core.EventSubscriptions,this.initToolbox(),this.userid=`${this.systemsetting.user.username}@${this.pid}`,this.currentStyle="",this.args&&this.args.length>0?this.open(this.args[0].path):this.newdoc(),this.resource={fonts:[],formats:[]},this.bindKey("ALT-N",()=>this.actionFile(this.name+"-New")),this.bindKey("ALT-O",()=>this.actionFile(this.name+"-Open")),this.bindKey("CTRL-S",()=>this.actionFile(this.name+"-Save")),this.bindKey("ALT-W",()=>this.actionFile(this.name+"-Saveas"))}menu(){return[{text:"__(File)",nodes:[{text:"__(New)",dataid:this.name+"-New",shortcut:"A-N"},{text:"__(Open)",dataid:this.name+"-Open",shortcut:"A-O"},{text:"__(Save)",dataid:this.name+"-Save",shortcut:"C-S"},{text:"__(Save as)",dataid:this.name+"-Saveas",shortcut:"A-W"}],onchildselect:e=>this.actionFile(e.data.item.data.dataid)}]}actionFile(e){var t;switch(t=()=>this.openDialog("FileDialog",{title:__("Save as"),file:this.currfile}).then(e=>{var t;return t=e.file.path.asFileHandle(),"file"===e.file.type&&(t=t.parent()),this.currfile.setPath(`${t.path}/${e.name}`),this.save()}),e){case this.name+"-Open":return this.openDialog("FileDialog",{title:__("Open file"),mimes:this.meta().mimes}).then(e=>this.open(e.file.path));case this.name+"-Save":return this.currfile.basename?this.save():t();case this.name+"-Saveas":return t();case this.name+"-New":return this.newdoc()}}newdoc(){var e;return e=this.meta().path+"/blank.odt",this.open(e,!0)}open(e,t){return this.pathAsDataURL(e).then(n=>(this.editorSession&&this.closeDocument(),this.initCanvas(),new odf.OdfContainer(n.data,n=>(this.canvas.setOdfContainer(n,!1),t?this.currfile="Untitled".asFileHandle():(this.currfile?this.currfile.setPath(e):this.currfile=e.asFileHandle(),this.scheme.apptitle=this.currfile.basename,this.notify(__("File {0} opened",e))))))).catch(e=>this.error(__("Problem read file {0}",e.toString()),e))}save(){var e;if(this.editorSession)return(e=this.canvas.odfContainer())?e.createByteArray(e=>(this.currfile.cache=new Blob([e],{type:"application/vnd.oasis.opendocument.text"}),this.currfile.write("application/vnd.oasis.opendocument.text").then(e=>(this.notify(__("File {0} saved",this.currfile.basename)),this.scheme.apptitle=this.currfile.basename,this.currfile.dirty=!1,this.editorFocus())).catch(e=>this.error(__("Cannot save file: {0}",e.toString()),e))),e=>this.error(__("Cannot create byte array from container: {0}",e.toString()||""),e)):this.error(__("No document container found"))}initToolbox(){var e,t,n;for(t in this.basictool={undo:this.find("btundo"),redo:this.find("btredo"),bold:this.find("btbold"),italic:this.find("btitalic"),underline:this.find("btunderline"),strike:this.find("btstrike"),note:this.find("btnote"),link:this.find("btlink"),unlink:this.find("btunlink"),image:this.find("btimage"),ac:this.find("btac"),al:this.find("btal"),ar:this.find("btar"),aj:this.find("btaj"),indent:this.find("btindent"),outdent:this.find("btoutdent"),fonts:this.find("font-list"),fontsize:this.find("font-size"),styles:this.find("format-list"),zoom:this.find("slzoom"),format:this.find("btformat")},e=(e,t)=>t["fonts"===e||"styles"===e?"onlistselect":"fontsize"===e||"zoom"===e?"onvaluechange":"onbtclick"]=t=>{if(this.directFormattingCtl&&this[e])return this[e](t),this.editorFocus()},n=this.basictool)e(t,n[t]);return this.find("btzoomfix").onbtclick=e=>this.zoom({data:100}),this.basictool.zoom.onvaluechanging=e=>this.find("lbzoom").text=Math.floor(e.data)+"%"}initCanvas(){var e;return(e=this.find("odfcanvas")).setAttribute("translate","no"),e.classList.add("notranslate"),this.canvas=new odf.OdfCanvas(e),this.documentChanged=e=>{if(!this.currfile.dirty)return this.currfile.dirty=!0,this.scheme.apptitle=this.currfile.basename+"*"},this.metaChanged=e=>{if(!this.currfile.dirty)return this.currfile.dirty=!0,this.scheme.apptitle=this.currfile.basename+"*"},this.textStylingChanged=e=>this.updateToolbar(e),this.paragrahStyleChanged=e=>{var t,n,i,o,r;if("style"==
2018-09-29 11:19:26 +02:00
/*
This is a generated file. DO NOT EDIT.
Copyright (C) 2010-2015 KO GmbH <copyright@kogmbh.com>
@licstart
The code in this file is free software: you can redistribute it and/or modify it
under the terms of the GNU Affero General Public License (GNU AGPL)
as published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
The code in this file is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with WebODF. If not, see <http://www.gnu.org/licenses/>.
As additional permission under GNU AGPL version 3 section 7, you
may distribute UNMODIFIED VERSIONS OF THIS file without the copy of the GNU AGPL normally
required by section 4, provided you include this license notice and a URL
through which recipients can access the Corresponding Source.
As a special exception to the AGPL, any HTML file which merely makes function
calls to this code, and for that purpose includes it in unmodified form by reference or in-line shall be
deemed a separate work for copyright law purposes. In addition, the copyright
holders of this code give you permission to combine this code with free
software libraries that are released under the GNU LGPL. You may copy and
distribute such a system following the terms of the GNU AGPL for this code
and the LGPL for the libraries. If you modify this code, you may extend this
exception to your version of the code, but you are not obligated to do so.
If you do not wish to do so, delete this exception statement from your
version.
This license applies to this entire compilation.
@licend
@source: http://www.webodf.org/
@source: https://github.com/kogmbh/WebODF/
*/
2020-06-25 18:23:33 +02:00
var webodf_version="0.5.9";function Runtime(){}Runtime.prototype.getVariable=function(e){},Runtime.prototype.toJson=function(e){},Runtime.prototype.fromJson=function(e){},Runtime.prototype.byteArrayFromString=function(e,t){},Runtime.prototype.byteArrayToString=function(e,t){},Runtime.prototype.read=function(e,t,n,i){},Runtime.prototype.readFile=function(e,t,n){},Runtime.prototype.readFileSync=function(e,t){},Runtime.prototype.loadXML=function(e,t){},Runtime.prototype.writeFile=function(e,t,n){},Runtime.prototype.deleteFile=function(e,t){},Runtime.prototype.log=function(e,t){},Runtime.prototype.setTimeout=function(e,t){},Runtime.prototype.clearTimeout=function(e){},Runtime.prototype.libraryPaths=function(){},Runtime.prototype.currentDirectory=function(){},Runtime.prototype.setCurrentDirectory=function(e){},Runtime.prototype.type=function(){},Runtime.prototype.getDOMImplementation=function(){},Runtime.prototype.parseXML=function(e){},Runtime.prototype.exit=function(e){},Runtime.prototype.getWindow=function(){},Runtime.prototype.requestAnimationFrame=function(e){},Runtime.prototype.cancelAnimationFrame=function(e){},Runtime.prototype.assert=function(e,t){};var IS_COMPILED_CODE=!0;function BrowserRuntime(){function e(e){var t,n,i=e.length,o=0;for(t=0;t<i;t+=1)o+=1+(128<(n=e.charCodeAt(t)))+(2048<n),55040<n&&57344>n&&(o+=1,t+=1);return o}function t(e,t,n){var i,o,r=e.length;for(t=new Uint8Array(new ArrayBuffer(t)),n?(t[0]=239,t[1]=187,t[2]=191,o=3):o=0,n=0;n<r;n+=1)128>(i=e.charCodeAt(n))?(t[o]=i,o+=1):2048>i?(t[o]=192|i>>>6,t[o+1]=128|63&i,o+=2):55040>=i||57344<=i?(t[o]=224|i>>>12&15,t[o+1]=128|i>>>6&63,t[o+2]=128|63&i,o+=3):(n+=1,i=65536+(i-55296<<10|e.charCodeAt(n)-56320),t[o]=240|i>>>18&7,t[o+1]=128|i>>>12&63,t[o+2]=128|i>>>6&63,t[o+3]=128|63&i,o+=4);return t}function n(e){var t,n=e.length,i=new Uint8Array(new ArrayBuffer(n));for(t=0;t<n;t+=1)i[t]=255&e.charCodeAt(t);return i}function i(e,t){var n;void 0!==t?n=e:t=e,console.log(t),s.enableAlerts&&"alert"===n&&alert(t)}function o(i,o,r){if(0!==r.status||r.responseText)if(200===r.status||0===r.status){if(r.response&&"string"!=typeof r.response)"binary"===o?(r=r.response,r=new Uint8Array(r)):r=String(r.response);else if("binary"===o)if(null!==r.responseBody&&"undefined"!==String(typeof VBArray)){var a=(r=new VBArray(r.responseBody).toArray()).length;for(o=new Uint8Array(new ArrayBuffer(a)),i=0;i<a;i+=1)o[i]=r[i];r=o}else{if((i=r.getResponseHeader("Content-Length"))&&(i=parseInt(i,10)),i&&i!==r.responseText.length)e:{o=!1;var s=e(a=r.responseText);if("number"==typeof i){if(i!==s&&i!==s+3){a=void 0;break e}o=s+3===i,s=i}a=t(a,s,o)}void 0===a&&(a=n(r.responseText)),r=a}else r=r.responseText;r={err:null,data:r}}else r={err:r.responseText||r.statusText,data:null};else r={err:"File "+i+" is empty.",data:null};return r}function r(e,t,n){var i=new XMLHttpRequest;return i.open("GET",e,n),i.overrideMimeType&&("binary"!==t?i.overrideMimeType("text/plain; charset="+t):i.overrideMimeType("text/plain; charset=x-user-defined")),i}function a(e,t,n){var i=r(e,t,!0);i.onreadystatechange=function(){var r;4===i.readyState&&(r=o(e,t,i),n(r.err,r.data))};try{i.send(null)}catch(e){n(e.message,null)}}var s=this;this.byteArrayFromString=function(i,o){var r;return"utf8"===o?r=t(i,e(i),!1):("binary"!==o&&s.log("unknown encoding: "+o),r=n(i)),r},this.byteArrayToString=Runtime.byteArrayToString,this.getVariable=Runtime.getVariable,this.fromJson=Runtime.fromJson,this.toJson=Runtime.toJson,this.readFile=a,this.read=function(e,t,n,i){a(e,"binary",(function(e,o){var r=null;if(o){if("string"==typeof o)throw"This should not happen.";r=o.subarray(t,t+n)}i(e,r)}))},this.readFileSync=function(e,t){var n,i=r(e,t,!1);try{if(i.send(null),(n=o(e,t,i)).err)throw n.err;if(null===n.data)throw"No data read from "+e+"."}catch(e){throw e}return n.data},this.writeFile=function(e,t,n){var i,o=new XMLHttpRequest;o.open("PUT",e,!0),o.onreadystatechange=function(){4===o.readyState&&(0!==o.status||o.responseText?200<=o.status&&300>o.status||0===o.status?n(null):n("Status "+String(o.status)+": "+o.responseText||o.statusText):n(
/*
2018-09-29 11:19:26 +02:00
@licstart
JSZip - A Javascript class for generating and reading zip files
<http://stuartk.com/jszip>
(c) 2009-2014 Stuart Knightley <stuart [at] stuartk.com>
Dual licenced under the MIT license or GPLv3. See https://raw.github.com/Stuk/jszip/master/LICENSE.markdown.
JSZip uses the library pako released under the MIT license :
https://github.com/nodeca/pako/blob/master/LICENSE
@licend
2020-06-25 18:23:33 +02:00
*/globalScope="undefined"!=typeof window?window:"undefined"!=typeof global?global:{},(globalScope.externs||(globalScope.externs={})).JSZip=function e(t,n,i){function o(a,s){if(!n[a]){if(!t[a]){var l="function"==typeof require&&require;if(!s&&l)return l(a,!0);if(r)return r(a,!0);throw new Error("Cannot find module '"+a+"'")}var u=n[a]={exports:{}};t[a][0].call(u.exports,(function(e){return o(t[a][1][e]||e)}),u,u.exports,e,t,n,i)}return n[a].exports}for(var r="function"==typeof require&&require,a=0;a<i.length;a++)o(i[a]);return o}({1:[function(e,t,n){var i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";n.encode=function(e,t){for(var n,o,r,a,s,l,u,d="",c=0;c<e.length;)a=(n=e.charCodeAt(c++))>>2,s=(3&n)<<4|(o=e.charCodeAt(c++))>>4,l=(15&o)<<2|(r=e.charCodeAt(c++))>>6,u=63&r,isNaN(o)?l=u=64:isNaN(r)&&(u=64),d=d+i.charAt(a)+i.charAt(s)+i.charAt(l)+i.charAt(u);return d},n.decode=function(e,t){var n,o,r,a,s,l,u="",d=0;for(e=e.replace(/[^A-Za-z0-9\+\/\=]/g,"");d<e.length;)n=i.indexOf(e.charAt(d++))<<2|(a=i.indexOf(e.charAt(d++)))>>4,o=(15&a)<<4|(s=i.indexOf(e.charAt(d++)))>>2,r=(3&s)<<6|(l=i.indexOf(e.charAt(d++))),u+=String.fromCharCode(n),64!=s&&(u+=String.fromCharCode(o)),64!=l&&(u+=String.fromCharCode(r));return u}},{}],2:[function(e,t,n){function i(){this.compressedSize=0,this.uncompressedSize=0,this.crc32=0,this.compressionMethod=null,this.compressedContent=null}i.prototype={getContent:function(){return null},getCompressedContent:function(){return null}},t.exports=i},{}],3:[function(e,t,n){n.STORE={magic:"\0\0",compress:function(e){return e},uncompress:function(e){return e},compressInputType:null,uncompressInputType:null},n.DEFLATE=e("./flate")},{"./flate":8}],4:[function(e,t,n){var i=e("./utils"),o=[0,1996959894,3993919788,2567524794,124634137,1886057615,3915621685,2657392035,249268274,2044508324,3772115230,2547177864,162941995,2125561021,3887607047,2428444049,498536548,1789927666,4089016648,2227061214,450548861,1843258603,4107580753,2211677639,325883990,1684777152,4251122042,2321926636,335633487,1661365465,4195302755,2366115317,997073096,1281953886,3579855332,2724688242,1006888145,1258607687,3524101629,2768942443,901097722,1119000684,3686517206,2898065728,853044451,1172266101,3705015759,2882616665,651767980,1373503546,3369554304,3218104598,565507253,1454621731,3485111705,3099436303,671266974,1594198024,3322730930,2970347812,795835527,1483230225,3244367275,3060149565,1994146192,31158534,2563907772,4023717930,1907459465,112637215,2680153253,3904427059,2013776290,251722036,2517215374,3775830040,2137656763,141376813,2439277719,3865271297,1802195444,476864866,2238001368,4066508878,1812370925,453092731,2181625025,4111451223,1706088902,314042704,2344532202,4240017532,1658658271,366619977,2362670323,4224994405,1303535960,984961486,2747007092,3569037538,1256170817,1037604311,2765210733,3554079995,1131014506,879679996,2909243462,3663771856,1141124467,855842277,2852801631,3708648649,1342533948,654459306,3188396048,3373015174,1466479909,544179635,3110523913,3462522015,1591671054,702138776,2966460450,3352799412,1504918807,783551873,3082640443,3233442989,3988292384,2596254646,62317068,1957810842,3939845945,2647816111,81470997,1943803523,3814918930,2489596804,225274430,2053790376,3826175755,2466906013,167816743,2097651377,4027552580,2265490386,503444072,1762050814,4150417245,2154129355,426522225,1852507879,4275313526,2312317920,282753626,1742555852,4189708143,2394877945,397917763,1622183637,3604390888,2714866558,953729732,1340076626,3518719985,2797360999,1068828381,1219638859,3624741850,2936675148,906185462,1090812512,3747672003,2825379669,829329135,1181335161,3412177804,3160834842,628085408,1382605366,3423369109,3138078467,570562233,1426400815,3317316542,2998733608,733239954,1555261956,3268935591,3050360625,752459403,1541320221,2607071920,3965973030,1969922972,40735498,2617837225,3943577151,1913087877,83908371,2512341634,3803740692,2075208622,213261112,2463272603,3855990285,2094854071,198958881,2262029012,4057260610,1759359992,534414190,2176718541,4139329115,1873836001,414664567,2282248934,4279200368,1711684554,28
2018-09-29 11:19:26 +02:00
/**
* Copyright (C) 2013 KO GmbH <copyright@kogmbh.com>
*
* @licstart
* This file is part of WebODF.
*
* WebODF is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License (GNU AGPL)
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* WebODF is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with WebODF. If not, see <http://www.gnu.org/licenses/>.
* @licend
*
* @source: http://www.webodf.org/
* @source: https://github.com/kogmbh/WebODF/
*/
2020-06-25 18:23:33 +02:00
this.OS.application.OpenPage.EditorSession=function(e){"use strict";runtime.loadClass("core.Async"),runtime.loadClass("core.DomUtils"),runtime.loadClass("odf.OdfUtils"),runtime.loadClass("ops.OdtDocument"),runtime.loadClass("ops.OdtStepsTranslator"),runtime.loadClass("ops.Session"),runtime.loadClass("odf.Namespaces"),runtime.loadClass("odf.OdfCanvas"),runtime.loadClass("odf.OdfUtils"),runtime.loadClass("gui.CaretManager"),runtime.loadClass("gui.Caret"),runtime.loadClass("gui.OdfFieldView"),runtime.loadClass("gui.SessionController"),runtime.loadClass("gui.SessionView"),runtime.loadClass("gui.HyperlinkTooltipView"),runtime.loadClass("gui.TrivialUndoManager"),runtime.loadClass("gui.SvgSelectionView"),runtime.loadClass("gui.SelectionViewManager"),runtime.loadClass("core.EventNotifier"),runtime.loadClass("gui.ShadowCursor"),runtime.loadClass("gui.CommonConstraints");var t=function e(t,n,i){var o,r,a,s,l,u,d,c,f=this,p=null,h=null,m=null,g=t.getOdtDocument(),b=odf.Namespaces.textns,y=document.createElement("style"),v=g.getFormatting(),S=core.DomUtils,C=odf.OdfUtils,N=new core.EventNotifier([e.signalMemberAdded,e.signalMemberUpdated,e.signalMemberRemoved,e.signalCursorAdded,e.signalCursorMoved,e.signalCursorRemoved,e.signalParagraphChanged,e.signalCommonStyleCreated,e.signalCommonStyleDeleted,e.signalParagraphStyleModified,e.signalUndoStackChanged]),x=new gui.ShadowCursor(g),w=core.StepDirection.NEXT;function E(){var t,n;if((t=p.getAttributeNS(b,"style-name"))!==m){if(m=t,!(n=v.getFirstCommonParentStyleNameOrSelf(t)))return h=t=m="",void f.emit(e.signalParagraphChanged,{type:"style",node:p,styleName:h});n!==h&&(h=n,f.emit(e.signalParagraphChanged,{type:"style",node:p,styleName:h}))}}function T(e){var t,n,i="";for(n=0;n<e.length;n+=1)null!==(t=e[n]).match(/[a-zA-Z0-9.-_]/)?i+=t:i+="_"+t.charCodeAt(0).toString(16)+"_";return null===i.match(/^[a-zA-Z_]/)&&(i="_"+i),i}function O(e){var t;(t=C.getParagraphElement(e.getNode()))&&(p=t,E())}function A(t){var i=g.getCursor(n),o=i&&i.getSelectedRange(),r=g.getDOMDocument().createRange();r.selectNode(t.paragraphElement),(o&&S.rangesIntersect(o,r)||t.paragraphElement===p)&&(f.emit(e.signalParagraphChanged,t),E()),r.detach()}function R(t){f.emit(e.signalMemberAdded,t.getMemberId())}function _(t){f.emit(e.signalMemberUpdated,t.getMemberId())}function P(t){f.emit(e.signalMemberRemoved,t)}function D(t){f.emit(e.signalCursorAdded,t.getMemberId()),O(t)}function k(t){f.emit(e.signalCursorRemoved,t)}function I(t){t.getMemberId()===n&&(f.emit(e.signalCursorMoved,t),O(t))}function F(t){f.emit(e.signalCommonStyleCreated,t)}function M(t){f.emit(e.signalCommonStyleDeleted,t)}function B(t){f.emit(e.signalParagraphStyleModified,t)}function U(e){return""===e?v.getDefaultStyleElement("paragraph"):v.getStyleElement(e,"paragraph")}function L(t){f.emit(e.signalUndoStackChanged,t)}function z(e){var t=document.getElementsByTagName("head")[0],n=f.sessionController.getEventManager();t.removeChild(y),g.unsubscribe(ops.Document.signalMemberAdded,R),g.unsubscribe(ops.Document.signalMemberUpdated,_),g.unsubscribe(ops.Document.signalMemberRemoved,P),g.unsubscribe(ops.Document.signalCursorAdded,D),g.unsubscribe(ops.Document.signalCursorRemoved,k),g.unsubscribe(ops.Document.signalCursorMoved,I),g.unsubscribe(ops.OdtDocument.signalCommonStyleCreated,F),g.unsubscribe(ops.OdtDocument.signalCommonStyleDeleted,M),g.unsubscribe(ops.OdtDocument.signalParagraphStyleModified,B),g.unsubscribe(ops.OdtDocument.signalParagraphChanged,A),g.unsubscribe(ops.OdtDocument.signalUndoStackChanged,L),n.unsubscribe("mousemove",a.showTooltip),n.unsubscribe("mouseout",a.hideTooltip),delete f.sessionView,delete f.sessionController,e()}this.emit=function(e,t){N.emit(e,t)},this.subscribe=function(e,t){N.subscribe(e,t)},this.unsubscribe=function(e,t){N.unsubscribe(e,t)},this.getCursorPosition=function(){return g.getCursorPosition(n)},this.getCursorSelection=function(){return g.getCursorSelection(n)},this.getOdfCanvas=function(){return g.getOdfCanvas()},this.getCurrentParagraph=function(){return p},this.getAvailableParagraphStyles=function(){return