theseus/bundled-addons/pdf-editor/vendor/pdfjs/pdf.worker.min.mjs

29 lines
1.2 MiB
JavaScript
Raw Normal View History

feat(pdf-editor): read, mark up and reshape a PDF without leaving the browser A PDF that needs a signature, a highlight or a page removed currently sends the user out to a desktop application or, worse, to a web service that wants the document uploaded first. Both are poor answers for a browser whose point is that nothing has to leave the machine. This is a full-tab editor that opens a PDF, marks it up, fills its forms and saves a new copy, entirely locally. Two engines, vendored rather than installed, because an add-on ships as a self-contained folder over the signed update channel and nothing runs a package manager on the way: pdf.js reads and renders, pdf-lib writes. They share no state. Everything in between lives in PDF user space — points, origin bottom-left — which is the one coordinate vocabulary both speak, so a mark survives zooming, rotating and reordering with no conversion table and save-time needs to know nothing about how a page happened to be displayed. The page strip is built from pdf.js's PDFPageView components rather than its PDFViewer, which renders pages in the file's own order and cannot hide, reorder or individually rotate one — three of the features here. Text layers are ours and stay attached for every page, drawn or not, because Theseus's find bar is Chromium's findInPage over the live DOM and a torn-down text layer is a page Ctrl+F cannot see. Canvases are virtualised; a letter page at 100% is 3.4 MB of bitmap. Redaction is the part worth being careful about. A black box over text hides nothing — the text stays in the content stream and comes straight out of a copy-paste — so the editor says so in a modal before the tool can be used, and on save rebuilds each redacted page as an image, which genuinely removes it. Pages that were not redacted are untouched. Form widgets and links are kept, since they were never the leak. Saving never writes over the original: every save reloads the source bytes and replays the session onto a fresh copy, so a botched save cannot poison the next one. Out of scope for this first version: editing the text that is already in the document, and writing XFA forms back (pdf-lib cannot, so those are fill-and- print only, and the editor says so on open).
2026-09-20 20:58:21 +02:00
/**
* @licstart The following is the entire license notice for the
* JavaScript code in this page
*
* Copyright 2024 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @licend The above is the entire license notice for the
* JavaScript code in this page
*/
/**
* pdfjsVersion = 6.3.289
* pdfjsBuild = 1c8020a7d
*/
const e=!("object"!=typeof process||process+""!="[object process]"||process.versions.nw||process.versions.electron&&process.type&&"browser"!==process.type),t=[1/0,1/0,-1/0,-1/0],n=new Float32Array(t),a=[.001,0,0,.001,0,0],s=.35/1.35,r="http://www.w3.org/2000/svg",i=1,o=2,l=4,f=8,c=16,h=64,u=128,m=256,p="pdfjs_internal_editor_",d=3,g=9,b=13,w=15,j=101,k={PRINT:4,MODIFY_CONTENTS:8,COPY:16,MODIFY_ANNOTATIONS:32,FILL_INTERACTIVE_FORMS:256,COPY_FOR_ACCESSIBILITY:512,ASSEMBLE:1024,PRINT_HIGH_QUALITY:2048},y=1,q=2,v=3,S=0,x=4,C=1,F=2,T=3,R={TEXT:1,LINK:2,FREETEXT:3,LINE:4,SQUARE:5,CIRCLE:6,POLYGON:7,POLYLINE:8,HIGHLIGHT:9,UNDERLINE:10,SQUIGGLY:11,STRIKEOUT:12,STAMP:13,CARET:14,INK:15,POPUP:16,FILEATTACHMENT:17,SOUND:18,MOVIE:19,WIDGET:20,SCREEN:21,PRINTERMARK:22,TRAPNET:23,WATERMARK:24,THREED:25,REDACT:26,RICHMEDIA:27},O="Group",H="R",D=0,M=4,N=1,E=2,_=4,z=16,L=32,U=128,W=512,X=1,K=2,G=4096,V=8192,$=32768,Y=65536,J=131072,Q=1048576,Z=2097152,ee=8388608,te=16777216,ne=1,ae=2,se=3,re=4,ie=5,oe={E:"Mouse Enter",X:"Mouse Exit",D:"Mouse Down",U:"Mouse Up",Fo:"Focus",Bl:"Blur",PO:"PageOpen",PC:"PageClose",PV:"PageVisible",PI:"PageInvisible",K:"Keystroke",F:"Format",V:"Validate",C:"Calculate"},le={WC:"WillClose",WS:"WillSave",DS:"DidSave",WP:"WillPrint",DP:"DidPrint"},fe={O:"PageOpen",C:"PageClose"},ce=1,he=5,ue=1,me=2,pe=3,de=4,ge=5,be=6,we=7,je=8,ke=9,ye=10,qe=11,ve=12,Se=13,Ae=14,xe=15,Ce=16,Ie=17,Fe=18,Te=19,Re=20,Oe=21,He=22,Be=23,De=24,Me=25,Ne=26,Pe=27,Ee=28,_e=29,ze=30,Le=31,Ue=32,We=33,Xe=34,Ke=35,Ge=36,Ve=37,$e=38,Ye=39,Je=40,Qe=41,Ze=42,et=43,tt=44,nt=45,at=46,st=47,rt=48,it=49,ot=50,lt=51,ft=52,ct=53,ht=54,ut=55,mt=56,pt=57,dt=58,gt=59,bt=60,wt=61,jt=62,kt=63,yt=64,qt=65,vt=66,St=67,At=68,xt=69,Ct=70,It=71,Ft=72,Tt=73,Rt=74,Ot=75,Ht=76,Bt=77,Dt=80,Mt=81,Nt=83,Pt=84,Et=85,_t=86,zt=87,Lt=88,Ut=89,Wt=90,Xt=91,Kt=92,Gt=93,Vt=94,$t=0,Yt=1,Jt=2,Qt=3,Zt=4,en=1,tn=2;let nn=ce;function getVerbosityLevel(){return nn}function info(e){nn>=he&&console.info(`Info: ${e}`)}function warn(e){nn>=ce&&console.warn(`Warning: ${e}`)}function unreachable(e){throw new Error(e)}function assert(e,t){e||unreachable(t)}function createValidAbsoluteUrl(e,t=null,n=null){if(!e)return null;if(n&&"string"==typeof e){if(n.addDefaultProtocol&&e.startsWith("www.")){const t=e.match(/\./g);t?.length>=2&&(e=`http://${e}`)}if(n.tryConvertEncoding)try{e=stringToUTF8String(e)}catch{}}const a=t?URL.parse(e,t):URL.parse(e);return function _isValidProtocol(e){switch(e?.protocol){case"http:":case"https:":case"ftp:":case"mailto:":case"tel:":return!0;default:return!1}}(a)?a:null}function shadow(e,t,n,a=!1){Object.defineProperty(e,t,{value:n,enumerable:!a,configurable:!0,writable:!1});return n}const an=function BaseExceptionClosure(){function BaseException(e,t){this.message=e;this.name=t}BaseException.prototype=new Error;BaseException.constructor=BaseException;return BaseException}();class PasswordException extends an{constructor(e,t){super(e,"PasswordException");this.code=t}}class UnknownErrorException extends an{constructor(e,t){super(e,"UnknownErrorException");this.details=t}}class InvalidPDFException extends an{constructor(e){super(e,"InvalidPDFException")}}class ResponseException extends an{constructor(e,t,n){super(e,"ResponseException");this.status=t;this.missing=n}}class FormatError extends an{constructor(e){super(e,"FormatError")}}class AbortException extends an{constructor(e){super(e,"AbortException")}}function bytesToString(e){"object"==typeof e&&void 0!==e?.length||unreachable("Invalid argument for bytesToString");const t=e.length,n=8192;if(t<n)return String.fromCharCode.apply(null,e);const a=[];for(let s=0;s<t;s+=n){const r=Math.min(s+n,t),i=e.subarray(s,r);a.push(String.fromCharCode.apply(null,i))}return a.join("")}function stringToBytes(e){"string"!=typeof e&&unreachable("Invalid argument for stringToBytes");const t=e.length,n=new Uint8Array(t);for(let a=0;a<t;++a)n[a]=255&e.charCodeAt(a);return n}class FeatureTest{static get isLittleEndian(){const e=new Uint8Array(4);e[0]=1;return shadow(this,"isLittleEndian",1===new Uint32Array(e.buffer,0,1)[0])}static ge
/*webpackIgnore: true*/
/*@vite-ignore*/
`${WasmImage.#R}${this._noWasmFilename}`)).default()}catch(e){warn(`#getJsModule: ${e}`)}e(t)}async#Q(e,t,n){try{this.#$||(WasmImage.#V?this.#$=await fetchBinaryData(`${WasmImage.#R}${this._filename}`):this.#$=await WasmImage.#K.sendWithPromise("FetchBinaryData",{kind:"wasmUrl",filename:this._filename}));return n((await WebAssembly.instantiate(this.#$,t)).instance)}catch(t){warn(`#instantiateWasm: ${t}`);this.#J(e);return null}}_getModule(e){if(!this.#Y){const{promise:t,resolve:n}=Promise.withResolvers(),a=[t];WasmImage.#T?a.push(e({warn,instantiateWasm:this.#Q.bind(this,n)})):this.#J(n);this.#Y=Promise.race(a)}return this.#Y}async decode(e,t){unreachable("Abstract method `decode` called")}}class Jbig2Error extends an{constructor(e){super(e,"Jbig2Error")}}class JBig2CCITTFaxImage extends WasmImage{_filename="jbig2.wasm";_noWasmFilename="jbig2_nowasm_fallback.js";static get instance(){return shadow(this,"instance",new JBig2CCITTFaxImage(!0))}async decode(e,t,n,a,s){const r=await this._getModule(ta);if(!r)throw new Jbig2Error("JBig2 failed to initialize");let i,o;try{const l=e.length;i=r._malloc(l);r.writeArrayToMemory(e,i);if(s)r._ccitt_decode(i,l,t,n,s.K,s.EndOfLine?1:0,s.EncodedByteAlign?1:0,s.BlackIs1?1:0,s.Columns,s.Rows);else{const e=a?a.length:0;if(e>0){o=r._malloc(e);r.writeArrayToMemory(a,o)}r._jbig2_decode(i,l,t,n,o,e)}if(!r.imageData)throw new Jbig2Error("Unknown error");const{imageData:f}=r;r.imageData=null;return f}finally{i&&r._free(i);o&&r._free(o)}}}class CCITTFaxStream extends DecodeStream{constructor(e,t,n){super(t);this.stream=e;this.maybeLength=t;this.dict=e.dict;n instanceof Dict||(n=Dict.empty);this.params={K:n.get("K")||0,EndOfLine:!!n.get("EndOfLine"),EncodedByteAlign:!!n.get("EncodedByteAlign"),Columns:n.get("Columns")||1728,Rows:n.get("Rows")||0,EndOfBlock:!!(n.get("EndOfBlock")??1),BlackIs1:!!n.get("BlackIs1")}}get bytes(){return shadow(this,"bytes",this.stream.getBytes(this.maybeLength))}get isImageStream(){return!0}get isAsyncDecoder(){return!0}async decodeImage(e,t,n){if(this.eof)return this.buffer;e??=this.stream.isAsync&&await this.stream.asyncGetBytes()||this.bytes;this.buffer=await JBig2CCITTFaxImage.instance.decode(e,this.dict.get("W","Width"),this.dict.get("H","Height"),null,this.params);this.bufferLength=this.buffer.length;this.eof=!0;return this.buffer}}const na=new Int32Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),aa=new Int32Array([3,4,5,6,7,8,9,10,65547,65549,65551,65553,131091,131095,131099,131103,196643,196651,196659,196667,262211,262227,262243,262259,327811,327843,327875,327907,258,258,258]),sa=new Int32Array([1,2,3,4,65541,65543,131081,131085,196625,196633,262177,262193,327745,327777,393345,393409,459009,459137,524801,525057,590849,591361,657409,658433,724993,727041,794625,798721,868353,876545]),ra=[new Int32Array([459008,524368,524304,524568,459024,524400,524336,590016,459016,524384,524320,589984,524288,524416,524352,590048,459012,524376,524312,589968,459028,524408,524344,590032,459020,524392,524328,59e4,524296,524424,524360,590064,459010,524372,524308,524572,459026,524404,524340,590024,459018,524388,524324,589992,524292,524420,524356,590056,459014,524380,524316,589976,459030,524412,524348,590040,459022,524396,524332,590008,524300,524428,524364,590072,459009,524370,524306,524570,459025,524402,524338,590020,459017,524386,524322,589988,524290,524418,524354,590052,459013,524378,524314,589972,459029,524410,524346,590036,459021,524394,524330,590004,524298,524426,524362,590068,459011,524374,524310,524574,459027,524406,524342,590028,459019,524390,524326,589996,524294,524422,524358,590060,459015,524382,524318,589980,459031,524414,524350,590044,459023,524398,524334,590012,524302,524430,524366,590076,459008,524369,524305,524569,459024,524401,524337,590018,459016,524385,524321,589986,524289,524417,524353,590050,459012,524377,524313,589970,459028,524409,524345,590034,459020,524393,524329,590002,524297,524425,524361,590066,459010,524373,524309,524573,459026,524405,524341,590026,459018,524389,524325,589994,524293,524421,524357,590058,459014,524381,524317,589978,459030,524413,5243