rmapi-js 2.2.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +51 -0
- package/bundle/rmapi-js.cjs.min.js +12 -4
- package/bundle/rmapi-js.esm.min.js +12 -4
- package/bundle/rmapi-js.iife.min.js +12 -4
- package/dist/index.d.ts +114 -41
- package/dist/index.js +173 -73
- package/package.json +17 -7
package/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,57 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
8
8
|
|
|
9
9
|
## [Unreleased]
|
|
10
10
|
|
|
11
|
+
## [3.0.0] - 2023-01-03
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
|
|
15
|
+
- The ability to call `getEntries` without a hash to implicitely fetch the root
|
|
16
|
+
hash.
|
|
17
|
+
- `getJson` and `putJson` methods that use stable hashing.
|
|
18
|
+
|
|
19
|
+
### Changed
|
|
20
|
+
|
|
21
|
+
- Caching behavior: You can no longer customize the caching behavior with a
|
|
22
|
+
custom `CacheLike` object, but instead specify the maximum size of objects to
|
|
23
|
+
cache. This both cleans up the caching code, and makes it easier to remove
|
|
24
|
+
most redundant calls from higher level interfaces.
|
|
25
|
+
- Changed `FetchLike` interfaces to be promises instead of awaitable.
|
|
26
|
+
|
|
27
|
+
### Removed
|
|
28
|
+
|
|
29
|
+
- Removed deprecated versions of `create` and `move`.
|
|
30
|
+
|
|
31
|
+
## [2.3.0] - 2022-12-31
|
|
32
|
+
|
|
33
|
+
### Added
|
|
34
|
+
|
|
35
|
+
- the root hash is now cached, with the default option of using the cached
|
|
36
|
+
value instead of making a request for it.
|
|
37
|
+
|
|
38
|
+
## [2.2.0] - 2022-12-30
|
|
39
|
+
|
|
40
|
+
### Added
|
|
41
|
+
|
|
42
|
+
- `create` and `move` apis added for a simple high level interface for adding
|
|
43
|
+
and moving documents.
|
|
44
|
+
|
|
45
|
+
## [2.1.0] - 2022-12-30
|
|
46
|
+
|
|
47
|
+
### Added
|
|
48
|
+
|
|
49
|
+
- `putMetadata` created for adding metadata and to parallel `getMetadata`. It's
|
|
50
|
+
just a thin wrapper around `putText`.
|
|
51
|
+
- `putCollection` add to simplify folder creation.
|
|
52
|
+
|
|
53
|
+
## [2.0.0] - 2022-12-26
|
|
54
|
+
|
|
55
|
+
### Added
|
|
56
|
+
|
|
57
|
+
- New default URLs to work with the new api.
|
|
58
|
+
- `syncComplete` was readded and working.
|
|
59
|
+
- `putPdf` added for uploading pdfs.
|
|
60
|
+
- `uploadPdf` and `uploadEpub` added to expose a different upload api.
|
|
61
|
+
|
|
11
62
|
## [1.1.0] - 2022-10-07
|
|
12
63
|
|
|
13
64
|
### Removed
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
var Pt=Object.create;var z=Object.defineProperty;var Et=Object.getOwnPropertyDescriptor;var Tt=Object.getOwnPropertyNames;var At=Object.getPrototypeOf,Ot=Object.prototype.hasOwnProperty;var p=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Mt=(e,t)=>{for(var r in t)z(e,r,{get:t[r],enumerable:!0})},Fe=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Tt(t))!Ot.call(e,i)&&i!==r&&z(e,i,{get:()=>t[i],enumerable:!(n=Et(t,i))||n.enumerable});return e};var ge=(e,t,r)=>(r=e!=null?Pt(At(e)):{},Fe(t||!e||!e.__esModule?z(r,"default",{value:e,enumerable:!0}):r,e)),St=e=>Fe(z({},"__esModule",{value:!0}),e);var De=p(V=>{"use strict";V.byteLength=Ft;V.toByteArray=Rt;V.fromByteArray=Ut;var P=[],b=[],kt=typeof Uint8Array<"u"?Uint8Array:Array,he="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(S=0,Ce=he.length;S<Ce;++S)P[S]=he[S],b[he.charCodeAt(S)]=S;var S,Ce;b["-".charCodeAt(0)]=62;b["_".charCodeAt(0)]=63;function Re(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=e.indexOf("=");r===-1&&(r=t);var n=r===t?0:4-r%4;return[r,n]}function Ft(e){var t=Re(e),r=t[0],n=t[1];return(r+n)*3/4-n}function Ct(e,t,r){return(t+r)*3/4-r}function Rt(e){var t,r=Re(e),n=r[0],i=r[1],a=new kt(Ct(e,n,i)),s=0,o=i>0?n-4:n,f;for(f=0;f<o;f+=4)t=b[e.charCodeAt(f)]<<18|b[e.charCodeAt(f+1)]<<12|b[e.charCodeAt(f+2)]<<6|b[e.charCodeAt(f+3)],a[s++]=t>>16&255,a[s++]=t>>8&255,a[s++]=t&255;return i===2&&(t=b[e.charCodeAt(f)]<<2|b[e.charCodeAt(f+1)]>>4,a[s++]=t&255),i===1&&(t=b[e.charCodeAt(f)]<<10|b[e.charCodeAt(f+1)]<<4|b[e.charCodeAt(f+2)]>>2,a[s++]=t>>8&255,a[s++]=t&255),a}function Dt(e){return P[e>>18&63]+P[e>>12&63]+P[e>>6&63]+P[e&63]}function It(e,t,r){for(var n,i=[],a=t;a<r;a+=3)n=(e[a]<<16&16711680)+(e[a+1]<<8&65280)+(e[a+2]&255),i.push(Dt(n));return i.join("")}function Ut(e){for(var t,r=e.length,n=r%3,i=[],a=16383,s=0,o=r-n;s<o;s+=a)i.push(It(e,s,s+a>o?o:s+a));return n===1?(t=e[r-1],i.push(P[t>>2]+P[t<<4&63]+"==")):n===2&&(t=(e[r-2]<<8)+e[r-1],i.push(P[t>>10]+P[t>>4&63]+P[t<<2&63]+"=")),i.join("")}});var xe=p(ve=>{"use strict";Object.defineProperty(ve,"__esModule",{value:!0});ve.default=$t;var qt=Lt(require("crypto"));function Lt(e){return e&&e.__esModule?e:{default:e}}var Y=new Uint8Array(256),G=Y.length;function $t(){return G>Y.length-16&&(qt.default.randomFillSync(Y),G=0),Y.slice(G,G+=16)}});var Ie=p(Z=>{"use strict";Object.defineProperty(Z,"__esModule",{value:!0});Z.default=void 0;var Nt=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;Z.default=Nt});var N=p(W=>{"use strict";Object.defineProperty(W,"__esModule",{value:!0});W.default=void 0;var Bt=Ht(Ie());function Ht(e){return e&&e.__esModule?e:{default:e}}function jt(e){return typeof e=="string"&&Bt.default.test(e)}var Jt=jt;W.default=Jt});var H=p(B=>{"use strict";Object.defineProperty(B,"__esModule",{value:!0});B.default=void 0;B.unsafeStringify=Ue;var zt=Vt(N());function Vt(e){return e&&e.__esModule?e:{default:e}}var y=[];for(let e=0;e<256;++e)y.push((e+256).toString(16).slice(1));function Ue(e,t=0){return(y[e[t+0]]+y[e[t+1]]+y[e[t+2]]+y[e[t+3]]+"-"+y[e[t+4]]+y[e[t+5]]+"-"+y[e[t+6]]+y[e[t+7]]+"-"+y[e[t+8]]+y[e[t+9]]+"-"+y[e[t+10]]+y[e[t+11]]+y[e[t+12]]+y[e[t+13]]+y[e[t+14]]+y[e[t+15]]).toLowerCase()}function Gt(e,t=0){let r=Ue(e,t);if(!(0,zt.default)(r))throw TypeError("Stringified UUID is invalid");return r}var Yt=Gt;B.default=Yt});var Le=p(K=>{"use strict";Object.defineProperty(K,"__esModule",{value:!0});K.default=void 0;var Zt=Kt(xe()),Wt=H();function Kt(e){return e&&e.__esModule?e:{default:e}}var qe,be,we=0,_e=0;function Qt(e,t,r){let n=t&&r||0,i=t||new Array(16);e=e||{};let a=e.node||qe,s=e.clockseq!==void 0?e.clockseq:be;if(a==null||s==null){let c=e.random||(e.rng||Zt.default)();a==null&&(a=qe=[c[0]|1,c[1],c[2],c[3],c[4],c[5]]),s==null&&(s=be=(c[6]<<8|c[7])&16383)}let o=e.msecs!==void 0?e.msecs:Date.now(),f=e.nsecs!==void 0?e.nsecs:_e+1,u=o-we+(f-_e)/1e4;if(u<0&&e.clockseq===void 0&&(s=s+1&16383),(u<0||o>we)&&e.nsecs===void 0&&(f=0),f>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");we=o,_e=f,be=s,o+=122192928e5;let l=((o&268435455)*1e4+f)%4294967296;i[n++]=l>>>24&255,i[n++]=l>>>16&255,i[n++]=l>>>8&255,i[n++]=l&255;let v=o/4294967296*1e4&268435455;i[n++]=v>>>8&255,i[n++]=v&255,i[n++]=v>>>24&15|16,i[n++]=v>>>16&255,i[n++]=s>>>8|128,i[n++]=s&255;for(let c=0;c<6;++c)i[n+c]=a[c];return t||(0,Wt.unsafeStringify)(i)}var Xt=Qt;K.default=Xt});var Pe=p(Q=>{"use strict";Object.defineProperty(Q,"__esModule",{value:!0});Q.default=void 0;var er=tr(N());function tr(e){return e&&e.__esModule?e:{default:e}}function rr(e){if(!(0,er.default)(e))throw TypeError("Invalid UUID");let t,r=new Uint8Array(16);return r[0]=(t=parseInt(e.slice(0,8),16))>>>24,r[1]=t>>>16&255,r[2]=t>>>8&255,r[3]=t&255,r[4]=(t=parseInt(e.slice(9,13),16))>>>8,r[5]=t&255,r[6]=(t=parseInt(e.slice(14,18),16))>>>8,r[7]=t&255,r[8]=(t=parseInt(e.slice(19,23),16))>>>8,r[9]=t&255,r[10]=(t=parseInt(e.slice(24,36),16))/1099511627776&255,r[11]=t/4294967296&255,r[12]=t>>>24&255,r[13]=t>>>16&255,r[14]=t>>>8&255,r[15]=t&255,r}var nr=rr;Q.default=nr});var Ee=p(k=>{"use strict";Object.defineProperty(k,"__esModule",{value:!0});k.URL=k.DNS=void 0;k.default=fr;var ir=H(),ar=sr(Pe());function sr(e){return e&&e.__esModule?e:{default:e}}function or(e){e=unescape(encodeURIComponent(e));let t=[];for(let r=0;r<e.length;++r)t.push(e.charCodeAt(r));return t}var $e="6ba7b810-9dad-11d1-80b4-00c04fd430c8";k.DNS=$e;var Ne="6ba7b811-9dad-11d1-80b4-00c04fd430c8";k.URL=Ne;function fr(e,t,r){function n(i,a,s,o){var f;if(typeof i=="string"&&(i=or(i)),typeof a=="string"&&(a=(0,ar.default)(a)),((f=a)===null||f===void 0?void 0:f.length)!==16)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");let u=new Uint8Array(16+i.length);if(u.set(a),u.set(i,a.length),u=r(u),u[6]=u[6]&15|t,u[8]=u[8]&63|128,s){o=o||0;for(let l=0;l<16;++l)s[o+l]=u[l];return s}return(0,ir.unsafeStringify)(u)}try{n.name=e}catch{}return n.DNS=$e,n.URL=Ne,n}});var Be=p(X=>{"use strict";Object.defineProperty(X,"__esModule",{value:!0});X.default=void 0;var ur=lr(require("crypto"));function lr(e){return e&&e.__esModule?e:{default:e}}function dr(e){return Array.isArray(e)?e=Buffer.from(e):typeof e=="string"&&(e=Buffer.from(e,"utf8")),ur.default.createHash("md5").update(e).digest()}var cr=dr;X.default=cr});var je=p(ee=>{"use strict";Object.defineProperty(ee,"__esModule",{value:!0});ee.default=void 0;var pr=He(Ee()),yr=He(Be());function He(e){return e&&e.__esModule?e:{default:e}}var mr=(0,pr.default)("v3",48,yr.default),gr=mr;ee.default=gr});var Je=p(te=>{"use strict";Object.defineProperty(te,"__esModule",{value:!0});te.default=void 0;var hr=vr(require("crypto"));function vr(e){return e&&e.__esModule?e:{default:e}}var xr={randomUUID:hr.default.randomUUID};te.default=xr});var Ge=p(re=>{"use strict";Object.defineProperty(re,"__esModule",{value:!0});re.default=void 0;var ze=Ve(Je()),br=Ve(xe()),wr=H();function Ve(e){return e&&e.__esModule?e:{default:e}}function _r(e,t,r){if(ze.default.randomUUID&&!t&&!e)return ze.default.randomUUID();e=e||{};let n=e.random||(e.rng||br.default)();if(n[6]=n[6]&15|64,n[8]=n[8]&63|128,t){r=r||0;for(let i=0;i<16;++i)t[r+i]=n[i];return t}return(0,wr.unsafeStringify)(n)}var Pr=_r;re.default=Pr});var Ye=p(ne=>{"use strict";Object.defineProperty(ne,"__esModule",{value:!0});ne.default=void 0;var Er=Tr(require("crypto"));function Tr(e){return e&&e.__esModule?e:{default:e}}function Ar(e){return Array.isArray(e)?e=Buffer.from(e):typeof e=="string"&&(e=Buffer.from(e,"utf8")),Er.default.createHash("sha1").update(e).digest()}var Or=Ar;ne.default=Or});var We=p(ie=>{"use strict";Object.defineProperty(ie,"__esModule",{value:!0});ie.default=void 0;var Mr=Ze(Ee()),Sr=Ze(Ye());function Ze(e){return e&&e.__esModule?e:{default:e}}var kr=(0,Mr.default)("v5",80,Sr.default),Fr=kr;ie.default=Fr});var Ke=p(ae=>{"use strict";Object.defineProperty(ae,"__esModule",{value:!0});ae.default=void 0;var Cr="00000000-0000-0000-0000-000000000000";ae.default=Cr});var Qe=p(se=>{"use strict";Object.defineProperty(se,"__esModule",{value:!0});se.default=void 0;var Rr=Dr(N());function Dr(e){return e&&e.__esModule?e:{default:e}}function Ir(e){if(!(0,Rr.default)(e))throw TypeError("Invalid UUID");return parseInt(e.slice(14,15),16)}var Ur=Ir;se.default=Ur});var Xe=p(_=>{"use strict";Object.defineProperty(_,"__esModule",{value:!0});Object.defineProperty(_,"NIL",{enumerable:!0,get:function(){return Br.default}});Object.defineProperty(_,"parse",{enumerable:!0,get:function(){return zr.default}});Object.defineProperty(_,"stringify",{enumerable:!0,get:function(){return Jr.default}});Object.defineProperty(_,"v1",{enumerable:!0,get:function(){return qr.default}});Object.defineProperty(_,"v3",{enumerable:!0,get:function(){return Lr.default}});Object.defineProperty(_,"v4",{enumerable:!0,get:function(){return $r.default}});Object.defineProperty(_,"v5",{enumerable:!0,get:function(){return Nr.default}});Object.defineProperty(_,"validate",{enumerable:!0,get:function(){return jr.default}});Object.defineProperty(_,"version",{enumerable:!0,get:function(){return Hr.default}});var qr=T(Le()),Lr=T(je()),$r=T(Ge()),Nr=T(We()),Br=T(Ke()),Hr=T(Qe()),jr=T(N()),Jr=T(H()),zr=T(Pe());function T(e){return e&&e.__esModule?e:{default:e}}});var Oe=p(d=>{"use strict";var rt=d&&d.__rest||function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(e);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(r[n[i]]=e[n[i]]);return r};Object.defineProperty(d,"__esModule",{value:!0});d.isSchema=d.isValidSchema=d.isDiscriminatorForm=d.isValuesForm=d.isPropertiesForm=d.isElementsForm=d.isEnumForm=d.isTypeForm=d.isRefForm=d.isEmptyForm=void 0;function Vr(e){let{definitions:t,nullable:r,metadata:n}=e,i=rt(e,["definitions","nullable","metadata"]);return Object.keys(i).length===0}d.isEmptyForm=Vr;function nt(e){return"ref"in e}d.isRefForm=nt;function Gr(e){return"type"in e}d.isTypeForm=Gr;function it(e){return"enum"in e}d.isEnumForm=it;function at(e){return"elements"in e}d.isElementsForm=at;function Ae(e){return"properties"in e||"optionalProperties"in e}d.isPropertiesForm=Ae;function st(e){return"values"in e}d.isValuesForm=st;function ot(e){return"discriminator"in e}d.isDiscriminatorForm=ot;function F(e,t){if(t===void 0&&(t=e),e.definitions!==void 0){if(t!==e)return!1;for(let r of Object.values(e.definitions))if(!F(r,t))return!1}if(nt(e)&&!(e.ref in(t.definitions||{}))||it(e)&&(e.enum.length===0||e.enum.length!==new Set(e.enum).size))return!1;if(at(e))return F(e.elements,t);if(Ae(e)){for(let r of Object.values(e.properties||{}))if(!F(r,t))return!1;for(let r of Object.values(e.optionalProperties||{}))if(!F(r,t))return!1;for(let r of Object.keys(e.properties||{}))if(r in(e.optionalProperties||{}))return!1}if(st(e))return F(e.values,t);if(ot(e)){for(let r of Object.values(e.mapping))if(!F(r,t)||!Ae(r)||r.nullable||e.discriminator in(r.properties||{})||e.discriminator in(r.optionalProperties||{}))return!1}return!0}d.isValidSchema=F;var Yr=[[!1,!1,!1,!1,!1,!1,!1,!1,!1,!1],[!0,!1,!1,!1,!1,!1,!1,!1,!1,!1],[!1,!0,!1,!1,!1,!1,!1,!1,!1,!1],[!1,!1,!0,!1,!1,!1,!1,!1,!1,!1],[!1,!1,!1,!0,!1,!1,!1,!1,!1,!1],[!1,!1,!1,!1,!0,!1,!1,!1,!1,!1],[!1,!1,!1,!1,!1,!0,!1,!1,!1,!1],[!1,!1,!1,!1,!0,!0,!1,!1,!1,!1],[!1,!1,!1,!1,!0,!1,!0,!1,!1,!1],[!1,!1,!1,!1,!1,!0,!0,!1,!1,!1],[!1,!1,!1,!1,!0,!0,!0,!1,!1,!1],[!1,!1,!1,!1,!1,!1,!1,!0,!1,!1],[!1,!1,!1,!1,!1,!1,!1,!1,!0,!0]],Zr=["boolean","float32","float64","int8","uint8","int16","uint16","int32","uint32","string","timestamp"];function C(e){if(typeof e!="object"||Array.isArray(e)||e===null)return!1;let t=e,{definitions:r=void 0,nullable:n=void 0,metadata:i=void 0,ref:a=void 0,type:s=void 0,enum:o=void 0,elements:f=void 0,properties:u=void 0,optionalProperties:l=void 0,additionalProperties:v=void 0,values:c=void 0,discriminator:$=void 0,mapping:A=void 0}=t,pe=rt(t,["definitions","nullable","metadata","ref","type","enum","elements","properties","optionalProperties","additionalProperties","values","discriminator","mapping"]),ye=[a!==void 0,s!==void 0,o!==void 0,f!==void 0,u!==void 0,l!==void 0,v!==void 0,c!==void 0,$!==void 0,A!==void 0],w=!1;for(let x of Yr)w=w||x.every((J,ke)=>J===ye[ke]);if(!w)return!1;if(r!==void 0){if(typeof r!="object"||Array.isArray(r)||r===null)return!1;for(let x of Object.values(r))if(!C(x))return!1}if(n!==void 0&&typeof n!="boolean"||i!==void 0&&(typeof i!="object"||Array.isArray(i)||i===null)||a!==void 0&&typeof a!="string"||s!==void 0&&(typeof s!="string"||!Zr.includes(s))||o!==void 0&&(!Array.isArray(o)||!o.every(x=>typeof x=="string"))||f!==void 0&&!C(f))return!1;if(u!==void 0){if(typeof u!="object"||Array.isArray(u)||u===null)return!1;for(let x of Object.values(u))if(!C(x))return!1}if(l!==void 0){if(typeof l!="object"||Array.isArray(l)||l===null)return!1;for(let x of Object.values(l))if(!C(x))return!1}if(v!==void 0&&typeof v!="boolean"||c!==void 0&&!C(c)||$!==void 0&&typeof $!="string")return!1;if(A!==void 0){if(typeof A!="object"||Array.isArray(A)||A===null)return!1;for(let x of Object.values(A))if(!C(x))return!1}return Object.keys(pe).length===0}d.isSchema=C});var ft=p(Me=>{"use strict";Object.defineProperty(Me,"__esModule",{value:!0});var Wr=/^(\d{4})-(\d{2})-(\d{2})[tT](\d{2}):(\d{2}):(\d{2})(\.\d+)?([zZ]|((\+|-)(\d{2}):(\d{2})))$/;function Kr(e){let t=e.match(Wr);if(t===null)return!1;let r=parseInt(t[1],10),n=parseInt(t[2],10),i=parseInt(t[3],10),a=parseInt(t[4],10),s=parseInt(t[5],10),o=parseInt(t[6],10);return!(n>12||i>Qr(r,n)||a>23||s>59||o>60)}Me.default=Kr;function Qr(e,t){return t===2?Xr(e)?29:28:en[t]}function Xr(e){return e%4===0&&(e%100!==0||e%400===0)}var en=[0,31,0,31,30,31,30,31,31,30,31,30,31]});var ut=p(O=>{"use strict";var tn=O&&O.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(O,"__esModule",{value:!0});O.validate=O.MaxDepthExceededError=void 0;var rn=tn(ft()),R=Oe(),fe=class extends Error{};O.MaxDepthExceededError=fe;var ue=class extends Error{};function nn(e,t,r){let n={errors:[],instanceTokens:[],schemaTokens:[[]],root:e,config:r||{maxDepth:0,maxErrors:0}};try{U(n,e,t)}catch(i){if(!(i instanceof ue))throw i}return n.errors}O.validate=nn;function U(e,t,r,n){if(!(t.nullable&&r===null)){if(R.isRefForm(t)){if(e.schemaTokens.length===e.config.maxDepth)throw new fe;e.schemaTokens.push(["definitions",t.ref]),U(e,e.root.definitions[t.ref],r),e.schemaTokens.pop()}else if(R.isTypeForm(t)){switch(m(e,"type"),t.type){case"boolean":typeof r!="boolean"&&g(e);break;case"float32":case"float64":typeof r!="number"&&g(e);break;case"int8":L(e,r,-128,127);break;case"uint8":L(e,r,0,255);break;case"int16":L(e,r,-32768,32767);break;case"uint16":L(e,r,0,65535);break;case"int32":L(e,r,-2147483648,2147483647);break;case"uint32":L(e,r,0,4294967295);break;case"string":typeof r!="string"&&g(e);break;case"timestamp":typeof r!="string"?g(e):rn.default(r)||g(e);break}h(e)}else if(R.isEnumForm(t))m(e,"enum"),(typeof r!="string"||!t.enum.includes(r))&&g(e),h(e);else if(R.isElementsForm(t)){if(m(e,"elements"),Array.isArray(r))for(let[i,a]of r.entries())D(e,i.toString()),U(e,t.elements,a),I(e);else g(e);h(e)}else if(R.isPropertiesForm(t))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){if(t.properties!==void 0){m(e,"properties");for(let[i,a]of Object.entries(t.properties))m(e,i),r.hasOwnProperty(i)?(D(e,i),U(e,a,r[i]),I(e)):g(e),h(e);h(e)}if(t.optionalProperties!==void 0){m(e,"optionalProperties");for(let[i,a]of Object.entries(t.optionalProperties))m(e,i),r.hasOwnProperty(i)&&(D(e,i),U(e,a,r[i]),I(e)),h(e);h(e)}if(t.additionalProperties!==!0)for(let i of Object.keys(r)){let a=t.properties&&i in t.properties,s=t.optionalProperties&&i in t.optionalProperties;!a&&!s&&i!==n&&(D(e,i),g(e),I(e))}}else t.properties!==void 0?m(e,"properties"):m(e,"optionalProperties"),g(e),h(e);else if(R.isValuesForm(t)){if(m(e,"values"),typeof r=="object"&&r!==null&&!Array.isArray(r))for(let[i,a]of Object.entries(r))D(e,i),U(e,t.values,a),I(e);else g(e);h(e)}else if(R.isDiscriminatorForm(t))if(typeof r=="object"&&r!==null&&!Array.isArray(r))if(r.hasOwnProperty(t.discriminator)){let i=r[t.discriminator];typeof i=="string"?i in t.mapping?(m(e,"mapping"),m(e,i),U(e,t.mapping[i],r,t.discriminator),h(e),h(e)):(m(e,"mapping"),D(e,t.discriminator),g(e),I(e),h(e)):(m(e,"discriminator"),D(e,t.discriminator),g(e),I(e),h(e))}else m(e,"discriminator"),g(e),h(e);else m(e,"discriminator"),g(e),h(e)}}function L(e,t,r,n){(typeof t!="number"||!Number.isInteger(t)||t<r||t>n)&&g(e)}function D(e,t){e.instanceTokens.push(t)}function I(e){e.instanceTokens.pop()}function m(e,t){e.schemaTokens[e.schemaTokens.length-1].push(t)}function h(e){e.schemaTokens[e.schemaTokens.length-1].pop()}function g(e){if(e.errors.push({instancePath:[...e.instanceTokens],schemaPath:[...e.schemaTokens[e.schemaTokens.length-1]]}),e.errors.length===e.config.maxErrors)throw new ue}});var dt=p(M=>{"use strict";var an=M&&M.__createBinding||(Object.create?function(e,t,r,n){n===void 0&&(n=r),Object.defineProperty(e,n,{enumerable:!0,get:function(){return t[r]}})}:function(e,t,r,n){n===void 0&&(n=r),e[n]=t[r]}),lt=M&&M.__exportStar||function(e,t){for(var r in e)r!=="default"&&!t.hasOwnProperty(r)&&an(t,e,r)};Object.defineProperty(M,"__esModule",{value:!0});lt(Oe(),M);lt(ut(),M)});var hn={};Mt(hn,{GenerationError:()=>ce,ResponseError:()=>q,builtinFontNames:()=>ln,builtinLineHeights:()=>bt,builtinMargins:()=>xt,builtinTextScales:()=>vt,builtinTools:()=>un,formatEntry:()=>wt,parseEntry:()=>_t,register:()=>mn,remarkable:()=>gn});module.exports=St(hn);var gt=ge(De());var E=ge(Xe(),1),Un=E.default.v1,qn=E.default.v3,oe=E.default.v4,Ln=E.default.v5,$n=E.default.NIL,Nn=E.default.version,Bn=E.default.validate,Hn=E.default.stringify,jn=E.default.parse;function Te(e){return[...new Uint8Array(e)].map(t=>t.toString(16).padStart(2,"0")).join("")}function et(e){return new Uint8Array((e.match(/../g)??[]).map(t=>parseInt(t,16)))}function tt(e){let t=0;for(let i of e)t+=i.length;let r=new Uint8Array(t),n=0;for(let i of e)r.set(i,n),n+=i.length;return r}var ct=ge(dt());function j(e,t){if((0,ct.validate)(e,t).length)throw new Error(`couldn't validate schema: ${JSON.stringify(t)} didn't match schema ${JSON.stringify(e)}`)}var pt="3",ht="https://webapp-prod.cloud.remarkable.engineering",sn="https://internal.cloud.remarkable.com",yt="x-goog-generation",on="x-goog-if-generation-match",fn="x-goog-content-length-range",un=["Ballpoint","Ballpointv2","Brush","Calligraphy","ClearPage","EraseSection","Eraser","Fineliner","Finelinerv2","Highlighter","Highlighterv2","Marker","Markerv2","Paintbrush","Paintbrushv2","Pencilv2","SharpPencil","SharpPencilv2","SolidPen","ZoomTool"],ln=["Maison Neue","EB Garamond","Noto Sans","Noto Serif","Noto Mono","Noto Sans UI"],vt={xs:.7,sm:.8,md:1,lg:1.2,xl:1.5,xx:2},xt={sm:50,md:125,rr:180,lg:200},bt={df:-1,md:100,lg:150,xl:200},dn={properties:{docID:{type:"string"},hash:{type:"string"}}},cn={properties:{relative_path:{type:"string"},url:{type:"string"},expires:{type:"timestamp"},method:{enum:["POST","GET","PUT","DELETE"]}},optionalProperties:{maxuploadsize_bytes:{type:"float64"}}},le={visibleName:{type:"string"},lastModified:{type:"string"}},de={version:{type:"int32"},pinned:{type:"boolean"},synced:{type:"boolean"},modified:{type:"boolean"},deleted:{type:"boolean"},metadatamodified:{type:"boolean"},parent:{type:"string"}},pn={discriminator:"type",mapping:{CollectionType:{properties:le,optionalProperties:de},DocumentType:{properties:le,optionalProperties:{...de,lastOpened:{type:"string"},lastOpenedPage:{type:"int32"}}}}},mt={id:{type:"string"},hash:{type:"string"}},yn={discriminator:"type",mapping:{CollectionType:{properties:{...le,...mt},optionalProperties:de},DocumentType:{properties:{...le,...mt,fileType:{enum:["notebook","epub","pdf",""]}},optionalProperties:{...de,lastOpened:{type:"string"},lastOpenedPage:{type:"int32"}}}}},q=class extends Error{constructor(r,n,i){super(i);this.status=r,this.statusText=n}},ce=class extends Error{constructor(){super("Generation preconditions failed. This means the current state is out of date with the cloud and needs to be re-synced.")}};async function mn(e,{deviceDesc:t="browser-chrome",uuid:r=oe(),authHost:n=ht,fetch:i=globalThis.fetch}={}){if(e.length!==8)throw new Error(`code should be length 8, but was ${e.length}`);let a=await i(`${n}/token/json/2/device/new`,{method:"POST",headers:{Authorization:"Bearer"},body:JSON.stringify({code:e,deviceDesc:t,deviceID:r})});if(a.ok)return await a.text();throw new q(a.status,a.statusText,"couldn't register api")}function wt({hash:e,type:t,documentId:r,subfiles:n,size:i}){return`${e}:${t}:${r}:${n}:${i}
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
var Yt=Object.create;var ee=Object.defineProperty;var Zt=Object.getOwnPropertyDescriptor;var Kt=Object.getOwnPropertyNames;var Wt=Object.getPrototypeOf,Qt=Object.prototype.hasOwnProperty;var y=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Xt=(e,t)=>{for(var r in t)ee(e,r,{get:t[r],enumerable:!0})},ze=(e,t,r,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Kt(t))!Qt.call(e,n)&&n!==r&&ee(e,n,{get:()=>t[n],enumerable:!(i=Zt(t,n))||i.enumerable});return e};var te=(e,t,r)=>(r=e!=null?Yt(Wt(e)):{},ze(t||!e||!e.__esModule?ee(r,"default",{value:e,enumerable:!0}):r,e)),er=e=>ze(ee({},"__esModule",{value:!0}),e);var Ye=y(re=>{"use strict";re.byteLength=rr;re.toByteArray=ir;re.fromByteArray=sr;var M=[],O=[],tr=typeof Uint8Array<"u"?Uint8Array:Array,Me="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(D=0,Ge=Me.length;D<Ge;++D)M[D]=Me[D],O[Me.charCodeAt(D)]=D;var D,Ge;O["-".charCodeAt(0)]=62;O["_".charCodeAt(0)]=63;function Ve(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=e.indexOf("=");r===-1&&(r=t);var i=r===t?0:4-r%4;return[r,i]}function rr(e){var t=Ve(e),r=t[0],i=t[1];return(r+i)*3/4-i}function nr(e,t,r){return(t+r)*3/4-r}function ir(e){var t,r=Ve(e),i=r[0],n=r[1],a=new tr(nr(e,i,n)),o=0,f=n>0?i-4:i,s;for(s=0;s<f;s+=4)t=O[e.charCodeAt(s)]<<18|O[e.charCodeAt(s+1)]<<12|O[e.charCodeAt(s+2)]<<6|O[e.charCodeAt(s+3)],a[o++]=t>>16&255,a[o++]=t>>8&255,a[o++]=t&255;return n===2&&(t=O[e.charCodeAt(s)]<<2|O[e.charCodeAt(s+1)]>>4,a[o++]=t&255),n===1&&(t=O[e.charCodeAt(s)]<<10|O[e.charCodeAt(s+1)]<<4|O[e.charCodeAt(s+2)]>>2,a[o++]=t>>8&255,a[o++]=t&255),a}function ar(e){return M[e>>18&63]+M[e>>12&63]+M[e>>6&63]+M[e&63]}function or(e,t,r){for(var i,n=[],a=t;a<r;a+=3)i=(e[a]<<16&16711680)+(e[a+1]<<8&65280)+(e[a+2]&255),n.push(ar(i));return n.join("")}function sr(e){for(var t,r=e.length,i=r%3,n=[],a=16383,o=0,f=r-i;o<f;o+=a)n.push(or(e,o,o+a>f?f:o+a));return i===1?(t=e[r-1],n.push(M[t>>2]+M[t<<4&63]+"==")):i===2&&(t=(e[r-2]<<8)+e[r-1],n.push(M[t>>10]+M[t>>4&63]+M[t<<2&63]+"=")),n.join("")}});var Xe=y((Wn,Qe)=>{"use strict";var ne,l,Ze={'"':'"',"\\":"\\","/":"/",b:"\b",f:"\f",n:`
|
|
2
|
+
`,r:"\r",t:" "},Se;function B(e){throw{name:"SyntaxError",message:e,at:ne,text:Se}}function d(e){return e&&e!==l&&B("Expected '"+e+"' instead of '"+l+"'"),l=Se.charAt(ne),ne+=1,l}function Ke(){var e,t="";for(l==="-"&&(t="-",d("-"));l>="0"&&l<="9";)t+=l,d();if(l===".")for(t+=".";d()&&l>="0"&&l<="9";)t+=l;if(l==="e"||l==="E")for(t+=l,d(),(l==="-"||l==="+")&&(t+=l,d());l>="0"&&l<="9";)t+=l,d();return e=Number(t),isFinite(e)||B("Bad number"),e}function We(){var e,t,r="",i;if(l==='"')for(;d();){if(l==='"')return d(),r;if(l==="\\")if(d(),l==="u"){for(i=0,t=0;t<4&&(e=parseInt(d(),16),!!isFinite(e));t+=1)i=i*16+e;r+=String.fromCharCode(i)}else if(typeof Ze[l]=="string")r+=Ze[l];else break;else r+=l}B("Bad string")}function k(){for(;l&&l<=" ";)d()}function fr(){switch(l){case"t":return d("t"),d("r"),d("u"),d("e"),!0;case"f":return d("f"),d("a"),d("l"),d("s"),d("e"),!1;case"n":return d("n"),d("u"),d("l"),d("l"),null;default:B("Unexpected '"+l+"'")}}function ur(){var e=[];if(l==="["){if(d("["),k(),l==="]")return d("]"),e;for(;l;){if(e.push(ie()),k(),l==="]")return d("]"),e;d(","),k()}}B("Bad array")}function lr(){var e,t={};if(l==="{"){if(d("{"),k(),l==="}")return d("}"),t;for(;l;){if(e=We(),k(),d(":"),Object.prototype.hasOwnProperty.call(t,e)&&B('Duplicate key "'+e+'"'),t[e]=ie(),k(),l==="}")return d("}"),t;d(","),k()}}B("Bad object")}function ie(){switch(k(),l){case"{":return lr();case"[":return ur();case'"':return We();case"-":return Ke();default:return l>="0"&&l<="9"?Ke():fr()}}Qe.exports=function(e,t){var r;return Se=e,ne=0,l=" ",r=ie(),k(),l&&B("Syntax error"),typeof t=="function"?function i(n,a){var o,f,s=n[a];if(s&&typeof s=="object")for(o in ie)Object.prototype.hasOwnProperty.call(s,o)&&(f=i(s,o),typeof f>"u"?delete s[o]:s[o]=f);return t.call(n,a,s)}({"":r},""):r}});var tt=y((Qn,et)=>{"use strict";var ke=/[\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,_,ae,cr={"\b":"\\b"," ":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},q;function Fe(e){return ke.lastIndex=0,ke.test(e)?'"'+e.replace(ke,function(t){var r=cr[t];return typeof r=="string"?r:"\\u"+("0000"+t.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+e+'"'}function oe(e,t){var r,i,n,a,o=_,f,s=t[e];switch(s&&typeof s=="object"&&typeof s.toJSON=="function"&&(s=s.toJSON(e)),typeof q=="function"&&(s=q.call(t,e,s)),typeof s){case"string":return Fe(s);case"number":return isFinite(s)?String(s):"null";case"boolean":case"null":return String(s);case"object":if(!s)return"null";if(_+=ae,f=[],Object.prototype.toString.apply(s)==="[object Array]"){for(a=s.length,r=0;r<a;r+=1)f[r]=oe(r,s)||"null";return n=f.length===0?"[]":_?`[
|
|
3
|
+
`+_+f.join(`,
|
|
4
|
+
`+_)+`
|
|
5
|
+
`+o+"]":"["+f.join(",")+"]",_=o,n}if(q&&typeof q=="object")for(a=q.length,r=0;r<a;r+=1)i=q[r],typeof i=="string"&&(n=oe(i,s),n&&f.push(Fe(i)+(_?": ":":")+n));else for(i in s)Object.prototype.hasOwnProperty.call(s,i)&&(n=oe(i,s),n&&f.push(Fe(i)+(_?": ":":")+n));return n=f.length===0?"{}":_?`{
|
|
6
|
+
`+_+f.join(`,
|
|
7
|
+
`+_)+`
|
|
8
|
+
`+o+"}":"{"+f.join(",")+"}",_=o,n;default:}}et.exports=function(e,t,r){var i;if(_="",ae="",typeof r=="number")for(i=0;i<r;i+=1)ae+=" ";else typeof r=="string"&&(ae=r);if(q=t,t&&typeof t!="function"&&(typeof t!="object"||typeof t.length!="number"))throw new Error("JSON.stringify");return oe("",{"":e})}});var rt=y(Ce=>{"use strict";Ce.parse=Xe();Ce.stringify=tt()});var it=y((ei,nt)=>{"use strict";var se=typeof JSON<"u"?JSON:rt(),dr=Array.isArray||function(e){return{}.toString.call(e)==="[object Array]"},pr=Object.keys||function(e){var t=Object.prototype.hasOwnProperty||function(){return!0},r=[];for(var i in e)t.call(e,i)&&r.push(i);return r};nt.exports=function(e,t){t||(t={}),typeof t=="function"&&(t={cmp:t});var r=t.space||"";typeof r=="number"&&(r=Array(r+1).join(" "));var i=typeof t.cycles=="boolean"?t.cycles:!1,n=t.replacer||function(f,s){return s},a=t.cmp&&function(f){return function(s){return function(c,u){var g={key:c,value:s[c]},p={key:u,value:s[u]};return f(g,p)}}}(t.cmp),o=[];return function f(s,c,u,g){var p=r?`
|
|
9
|
+
`+new Array(g+1).join(r):"",C=r?": ":":";if(u&&u.toJSON&&typeof u.toJSON=="function"&&(u=u.toJSON()),u=n.call(s,c,u),u!==void 0){if(typeof u!="object"||u===null)return se.stringify(u);if(dr(u)){for(var T=[],h=0;h<u.length;h++){var V=f(u,h,u[h],g+1)||se.stringify(null);T.push(p+r+V)}return"["+T.join(",")+p+"]"}if(o.indexOf(u)!==-1){if(i)return se.stringify("__cycle__");throw new TypeError("Converting circular structure to JSON")}else o.push(u);for(var E=pr(u).sort(a&&a(u)),T=[],h=0;h<E.length;h++){var c=E[h],v=f(u,c,u[c],g+1);if(v){var X=se.stringify(c)+C+v;T.push(p+r+X)}}return o.splice(o.indexOf(u),1),"{"+T.join(",")+p+"}"}}({"":e},"",e,0)}});var Re=y(Be=>{"use strict";Object.defineProperty(Be,"__esModule",{value:!0});Be.default=gr;var yr=mr(require("crypto"));function mr(e){return e&&e.__esModule?e:{default:e}}var ue=new Uint8Array(256),fe=ue.length;function gr(){return fe>ue.length-16&&(yr.default.randomFillSync(ue),fe=0),ue.slice(fe,fe+=16)}});var at=y(le=>{"use strict";Object.defineProperty(le,"__esModule",{value:!0});le.default=void 0;var hr=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;le.default=hr});var Z=y(ce=>{"use strict";Object.defineProperty(ce,"__esModule",{value:!0});ce.default=void 0;var vr=br(at());function br(e){return e&&e.__esModule?e:{default:e}}function wr(e){return typeof e=="string"&&vr.default.test(e)}var xr=wr;ce.default=xr});var W=y(K=>{"use strict";Object.defineProperty(K,"__esModule",{value:!0});K.default=void 0;K.unsafeStringify=ot;var Pr=_r(Z());function _r(e){return e&&e.__esModule?e:{default:e}}var b=[];for(let e=0;e<256;++e)b.push((e+256).toString(16).slice(1));function ot(e,t=0){return(b[e[t+0]]+b[e[t+1]]+b[e[t+2]]+b[e[t+3]]+"-"+b[e[t+4]]+b[e[t+5]]+"-"+b[e[t+6]]+b[e[t+7]]+"-"+b[e[t+8]]+b[e[t+9]]+"-"+b[e[t+10]]+b[e[t+11]]+b[e[t+12]]+b[e[t+13]]+b[e[t+14]]+b[e[t+15]]).toLowerCase()}function Er(e,t=0){let r=ot(e,t);if(!(0,Pr.default)(r))throw TypeError("Stringified UUID is invalid");return r}var Or=Er;K.default=Or});var ft=y(de=>{"use strict";Object.defineProperty(de,"__esModule",{value:!0});de.default=void 0;var Tr=Mr(Re()),Ar=W();function Mr(e){return e&&e.__esModule?e:{default:e}}var st,Ie,De=0,qe=0;function Sr(e,t,r){let i=t&&r||0,n=t||new Array(16);e=e||{};let a=e.node||st,o=e.clockseq!==void 0?e.clockseq:Ie;if(a==null||o==null){let p=e.random||(e.rng||Tr.default)();a==null&&(a=st=[p[0]|1,p[1],p[2],p[3],p[4],p[5]]),o==null&&(o=Ie=(p[6]<<8|p[7])&16383)}let f=e.msecs!==void 0?e.msecs:Date.now(),s=e.nsecs!==void 0?e.nsecs:qe+1,c=f-De+(s-qe)/1e4;if(c<0&&e.clockseq===void 0&&(o=o+1&16383),(c<0||f>De)&&e.nsecs===void 0&&(s=0),s>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");De=f,qe=s,Ie=o,f+=122192928e5;let u=((f&268435455)*1e4+s)%4294967296;n[i++]=u>>>24&255,n[i++]=u>>>16&255,n[i++]=u>>>8&255,n[i++]=u&255;let g=f/4294967296*1e4&268435455;n[i++]=g>>>8&255,n[i++]=g&255,n[i++]=g>>>24&15|16,n[i++]=g>>>16&255,n[i++]=o>>>8|128,n[i++]=o&255;for(let p=0;p<6;++p)n[i+p]=a[p];return t||(0,Ar.unsafeStringify)(n)}var kr=Sr;de.default=kr});var Ne=y(pe=>{"use strict";Object.defineProperty(pe,"__esModule",{value:!0});pe.default=void 0;var Fr=Cr(Z());function Cr(e){return e&&e.__esModule?e:{default:e}}function Br(e){if(!(0,Fr.default)(e))throw TypeError("Invalid UUID");let t,r=new Uint8Array(16);return r[0]=(t=parseInt(e.slice(0,8),16))>>>24,r[1]=t>>>16&255,r[2]=t>>>8&255,r[3]=t&255,r[4]=(t=parseInt(e.slice(9,13),16))>>>8,r[5]=t&255,r[6]=(t=parseInt(e.slice(14,18),16))>>>8,r[7]=t&255,r[8]=(t=parseInt(e.slice(19,23),16))>>>8,r[9]=t&255,r[10]=(t=parseInt(e.slice(24,36),16))/1099511627776&255,r[11]=t/4294967296&255,r[12]=t>>>24&255,r[13]=t>>>16&255,r[14]=t>>>8&255,r[15]=t&255,r}var Rr=Br;pe.default=Rr});var je=y(N=>{"use strict";Object.defineProperty(N,"__esModule",{value:!0});N.URL=N.DNS=void 0;N.default=jr;var Ir=W(),Dr=qr(Ne());function qr(e){return e&&e.__esModule?e:{default:e}}function Nr(e){e=unescape(encodeURIComponent(e));let t=[];for(let r=0;r<e.length;++r)t.push(e.charCodeAt(r));return t}var ut="6ba7b810-9dad-11d1-80b4-00c04fd430c8";N.DNS=ut;var lt="6ba7b811-9dad-11d1-80b4-00c04fd430c8";N.URL=lt;function jr(e,t,r){function i(n,a,o,f){var s;if(typeof n=="string"&&(n=Nr(n)),typeof a=="string"&&(a=(0,Dr.default)(a)),((s=a)===null||s===void 0?void 0:s.length)!==16)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");let c=new Uint8Array(16+n.length);if(c.set(a),c.set(n,a.length),c=r(c),c[6]=c[6]&15|t,c[8]=c[8]&63|128,o){f=f||0;for(let u=0;u<16;++u)o[f+u]=c[u];return o}return(0,Ir.unsafeStringify)(c)}try{i.name=e}catch{}return i.DNS=ut,i.URL=lt,i}});var ct=y(ye=>{"use strict";Object.defineProperty(ye,"__esModule",{value:!0});ye.default=void 0;var Lr=$r(require("crypto"));function $r(e){return e&&e.__esModule?e:{default:e}}function Ur(e){return Array.isArray(e)?e=Buffer.from(e):typeof e=="string"&&(e=Buffer.from(e,"utf8")),Lr.default.createHash("md5").update(e).digest()}var Hr=Ur;ye.default=Hr});var pt=y(me=>{"use strict";Object.defineProperty(me,"__esModule",{value:!0});me.default=void 0;var Jr=dt(je()),zr=dt(ct());function dt(e){return e&&e.__esModule?e:{default:e}}var Gr=(0,Jr.default)("v3",48,zr.default),Vr=Gr;me.default=Vr});var yt=y(ge=>{"use strict";Object.defineProperty(ge,"__esModule",{value:!0});ge.default=void 0;var Yr=Zr(require("crypto"));function Zr(e){return e&&e.__esModule?e:{default:e}}var Kr={randomUUID:Yr.default.randomUUID};ge.default=Kr});var ht=y(he=>{"use strict";Object.defineProperty(he,"__esModule",{value:!0});he.default=void 0;var mt=gt(yt()),Wr=gt(Re()),Qr=W();function gt(e){return e&&e.__esModule?e:{default:e}}function Xr(e,t,r){if(mt.default.randomUUID&&!t&&!e)return mt.default.randomUUID();e=e||{};let i=e.random||(e.rng||Wr.default)();if(i[6]=i[6]&15|64,i[8]=i[8]&63|128,t){r=r||0;for(let n=0;n<16;++n)t[r+n]=i[n];return t}return(0,Qr.unsafeStringify)(i)}var en=Xr;he.default=en});var vt=y(ve=>{"use strict";Object.defineProperty(ve,"__esModule",{value:!0});ve.default=void 0;var tn=rn(require("crypto"));function rn(e){return e&&e.__esModule?e:{default:e}}function nn(e){return Array.isArray(e)?e=Buffer.from(e):typeof e=="string"&&(e=Buffer.from(e,"utf8")),tn.default.createHash("sha1").update(e).digest()}var an=nn;ve.default=an});var wt=y(be=>{"use strict";Object.defineProperty(be,"__esModule",{value:!0});be.default=void 0;var on=bt(je()),sn=bt(vt());function bt(e){return e&&e.__esModule?e:{default:e}}var fn=(0,on.default)("v5",80,sn.default),un=fn;be.default=un});var xt=y(we=>{"use strict";Object.defineProperty(we,"__esModule",{value:!0});we.default=void 0;var ln="00000000-0000-0000-0000-000000000000";we.default=ln});var Pt=y(xe=>{"use strict";Object.defineProperty(xe,"__esModule",{value:!0});xe.default=void 0;var cn=dn(Z());function dn(e){return e&&e.__esModule?e:{default:e}}function pn(e){if(!(0,cn.default)(e))throw TypeError("Invalid UUID");return parseInt(e.slice(14,15),16)}var yn=pn;xe.default=yn});var _t=y(A=>{"use strict";Object.defineProperty(A,"__esModule",{value:!0});Object.defineProperty(A,"NIL",{enumerable:!0,get:function(){return bn.default}});Object.defineProperty(A,"parse",{enumerable:!0,get:function(){return _n.default}});Object.defineProperty(A,"stringify",{enumerable:!0,get:function(){return Pn.default}});Object.defineProperty(A,"v1",{enumerable:!0,get:function(){return mn.default}});Object.defineProperty(A,"v3",{enumerable:!0,get:function(){return gn.default}});Object.defineProperty(A,"v4",{enumerable:!0,get:function(){return hn.default}});Object.defineProperty(A,"v5",{enumerable:!0,get:function(){return vn.default}});Object.defineProperty(A,"validate",{enumerable:!0,get:function(){return xn.default}});Object.defineProperty(A,"version",{enumerable:!0,get:function(){return wn.default}});var mn=F(ft()),gn=F(pt()),hn=F(ht()),vn=F(wt()),bn=F(xt()),wn=F(Pt()),xn=F(Z()),Pn=F(W()),_n=F(Ne());function F(e){return e&&e.__esModule?e:{default:e}}});var Ue=y(m=>{"use strict";var Tt=m&&m.__rest||function(e,t){var r={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(r[i]=e[i]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var n=0,i=Object.getOwnPropertySymbols(e);n<i.length;n++)t.indexOf(i[n])<0&&Object.prototype.propertyIsEnumerable.call(e,i[n])&&(r[i[n]]=e[i[n]]);return r};Object.defineProperty(m,"__esModule",{value:!0});m.isSchema=m.isValidSchema=m.isDiscriminatorForm=m.isValuesForm=m.isPropertiesForm=m.isElementsForm=m.isEnumForm=m.isTypeForm=m.isRefForm=m.isEmptyForm=void 0;function En(e){let{definitions:t,nullable:r,metadata:i}=e,n=Tt(e,["definitions","nullable","metadata"]);return Object.keys(n).length===0}m.isEmptyForm=En;function At(e){return"ref"in e}m.isRefForm=At;function On(e){return"type"in e}m.isTypeForm=On;function Mt(e){return"enum"in e}m.isEnumForm=Mt;function St(e){return"elements"in e}m.isElementsForm=St;function $e(e){return"properties"in e||"optionalProperties"in e}m.isPropertiesForm=$e;function kt(e){return"values"in e}m.isValuesForm=kt;function Ft(e){return"discriminator"in e}m.isDiscriminatorForm=Ft;function j(e,t){if(t===void 0&&(t=e),e.definitions!==void 0){if(t!==e)return!1;for(let r of Object.values(e.definitions))if(!j(r,t))return!1}if(At(e)&&!(e.ref in(t.definitions||{}))||Mt(e)&&(e.enum.length===0||e.enum.length!==new Set(e.enum).size))return!1;if(St(e))return j(e.elements,t);if($e(e)){for(let r of Object.values(e.properties||{}))if(!j(r,t))return!1;for(let r of Object.values(e.optionalProperties||{}))if(!j(r,t))return!1;for(let r of Object.keys(e.properties||{}))if(r in(e.optionalProperties||{}))return!1}if(kt(e))return j(e.values,t);if(Ft(e)){for(let r of Object.values(e.mapping))if(!j(r,t)||!$e(r)||r.nullable||e.discriminator in(r.properties||{})||e.discriminator in(r.optionalProperties||{}))return!1}return!0}m.isValidSchema=j;var Tn=[[!1,!1,!1,!1,!1,!1,!1,!1,!1,!1],[!0,!1,!1,!1,!1,!1,!1,!1,!1,!1],[!1,!0,!1,!1,!1,!1,!1,!1,!1,!1],[!1,!1,!0,!1,!1,!1,!1,!1,!1,!1],[!1,!1,!1,!0,!1,!1,!1,!1,!1,!1],[!1,!1,!1,!1,!0,!1,!1,!1,!1,!1],[!1,!1,!1,!1,!1,!0,!1,!1,!1,!1],[!1,!1,!1,!1,!0,!0,!1,!1,!1,!1],[!1,!1,!1,!1,!0,!1,!0,!1,!1,!1],[!1,!1,!1,!1,!1,!0,!0,!1,!1,!1],[!1,!1,!1,!1,!0,!0,!0,!1,!1,!1],[!1,!1,!1,!1,!1,!1,!1,!0,!1,!1],[!1,!1,!1,!1,!1,!1,!1,!1,!0,!0]],An=["boolean","float32","float64","int8","uint8","int16","uint16","int32","uint32","string","timestamp"];function L(e){if(typeof e!="object"||Array.isArray(e)||e===null)return!1;let t=e,{definitions:r=void 0,nullable:i=void 0,metadata:n=void 0,ref:a=void 0,type:o=void 0,enum:f=void 0,elements:s=void 0,properties:c=void 0,optionalProperties:u=void 0,additionalProperties:g=void 0,values:p=void 0,discriminator:C=void 0,mapping:h=void 0}=t,V=Tt(t,["definitions","nullable","metadata","ref","type","enum","elements","properties","optionalProperties","additionalProperties","values","discriminator","mapping"]),E=[a!==void 0,o!==void 0,f!==void 0,s!==void 0,c!==void 0,u!==void 0,g!==void 0,p!==void 0,C!==void 0,h!==void 0],T=!1;for(let v of Tn)T=T||v.every((X,Y)=>X===E[Y]);if(!T)return!1;if(r!==void 0){if(typeof r!="object"||Array.isArray(r)||r===null)return!1;for(let v of Object.values(r))if(!L(v))return!1}if(i!==void 0&&typeof i!="boolean"||n!==void 0&&(typeof n!="object"||Array.isArray(n)||n===null)||a!==void 0&&typeof a!="string"||o!==void 0&&(typeof o!="string"||!An.includes(o))||f!==void 0&&(!Array.isArray(f)||!f.every(v=>typeof v=="string"))||s!==void 0&&!L(s))return!1;if(c!==void 0){if(typeof c!="object"||Array.isArray(c)||c===null)return!1;for(let v of Object.values(c))if(!L(v))return!1}if(u!==void 0){if(typeof u!="object"||Array.isArray(u)||u===null)return!1;for(let v of Object.values(u))if(!L(v))return!1}if(g!==void 0&&typeof g!="boolean"||p!==void 0&&!L(p)||C!==void 0&&typeof C!="string")return!1;if(h!==void 0){if(typeof h!="object"||Array.isArray(h)||h===null)return!1;for(let v of Object.values(h))if(!L(v))return!1}return Object.keys(V).length===0}m.isSchema=L});var Ct=y(He=>{"use strict";Object.defineProperty(He,"__esModule",{value:!0});var Mn=/^(\d{4})-(\d{2})-(\d{2})[tT](\d{2}):(\d{2}):(\d{2})(\.\d+)?([zZ]|((\+|-)(\d{2}):(\d{2})))$/;function Sn(e){let t=e.match(Mn);if(t===null)return!1;let r=parseInt(t[1],10),i=parseInt(t[2],10),n=parseInt(t[3],10),a=parseInt(t[4],10),o=parseInt(t[5],10),f=parseInt(t[6],10);return!(i>12||n>kn(r,i)||a>23||o>59||f>60)}He.default=Sn;function kn(e,t){return t===2?Fn(e)?29:28:Cn[t]}function Fn(e){return e%4===0&&(e%100!==0||e%400===0)}var Cn=[0,31,0,31,30,31,30,31,31,30,31,30,31]});var Bt=y(R=>{"use strict";var Bn=R&&R.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(R,"__esModule",{value:!0});R.validate=R.MaxDepthExceededError=void 0;var Rn=Bn(Ct()),$=Ue(),_e=class extends Error{};R.MaxDepthExceededError=_e;var Ee=class extends Error{};function In(e,t,r){let i={errors:[],instanceTokens:[],schemaTokens:[[]],root:e,config:r||{maxDepth:0,maxErrors:0}};try{J(i,e,t)}catch(n){if(!(n instanceof Ee))throw n}return i.errors}R.validate=In;function J(e,t,r,i){if(!(t.nullable&&r===null)){if($.isRefForm(t)){if(e.schemaTokens.length===e.config.maxDepth)throw new _e;e.schemaTokens.push(["definitions",t.ref]),J(e,e.root.definitions[t.ref],r),e.schemaTokens.pop()}else if($.isTypeForm(t)){switch(w(e,"type"),t.type){case"boolean":typeof r!="boolean"&&x(e);break;case"float32":case"float64":typeof r!="number"&&x(e);break;case"int8":G(e,r,-128,127);break;case"uint8":G(e,r,0,255);break;case"int16":G(e,r,-32768,32767);break;case"uint16":G(e,r,0,65535);break;case"int32":G(e,r,-2147483648,2147483647);break;case"uint32":G(e,r,0,4294967295);break;case"string":typeof r!="string"&&x(e);break;case"timestamp":typeof r!="string"?x(e):Rn.default(r)||x(e);break}P(e)}else if($.isEnumForm(t))w(e,"enum"),(typeof r!="string"||!t.enum.includes(r))&&x(e),P(e);else if($.isElementsForm(t)){if(w(e,"elements"),Array.isArray(r))for(let[n,a]of r.entries())U(e,n.toString()),J(e,t.elements,a),H(e);else x(e);P(e)}else if($.isPropertiesForm(t))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){if(t.properties!==void 0){w(e,"properties");for(let[n,a]of Object.entries(t.properties))w(e,n),r.hasOwnProperty(n)?(U(e,n),J(e,a,r[n]),H(e)):x(e),P(e);P(e)}if(t.optionalProperties!==void 0){w(e,"optionalProperties");for(let[n,a]of Object.entries(t.optionalProperties))w(e,n),r.hasOwnProperty(n)&&(U(e,n),J(e,a,r[n]),H(e)),P(e);P(e)}if(t.additionalProperties!==!0)for(let n of Object.keys(r)){let a=t.properties&&n in t.properties,o=t.optionalProperties&&n in t.optionalProperties;!a&&!o&&n!==i&&(U(e,n),x(e),H(e))}}else t.properties!==void 0?w(e,"properties"):w(e,"optionalProperties"),x(e),P(e);else if($.isValuesForm(t)){if(w(e,"values"),typeof r=="object"&&r!==null&&!Array.isArray(r))for(let[n,a]of Object.entries(r))U(e,n),J(e,t.values,a),H(e);else x(e);P(e)}else if($.isDiscriminatorForm(t))if(typeof r=="object"&&r!==null&&!Array.isArray(r))if(r.hasOwnProperty(t.discriminator)){let n=r[t.discriminator];typeof n=="string"?n in t.mapping?(w(e,"mapping"),w(e,n),J(e,t.mapping[n],r,t.discriminator),P(e),P(e)):(w(e,"mapping"),U(e,t.discriminator),x(e),H(e),P(e)):(w(e,"discriminator"),U(e,t.discriminator),x(e),H(e),P(e))}else w(e,"discriminator"),x(e),P(e);else w(e,"discriminator"),x(e),P(e)}}function G(e,t,r,i){(typeof t!="number"||!Number.isInteger(t)||t<r||t>i)&&x(e)}function U(e,t){e.instanceTokens.push(t)}function H(e){e.instanceTokens.pop()}function w(e,t){e.schemaTokens[e.schemaTokens.length-1].push(t)}function P(e){e.schemaTokens[e.schemaTokens.length-1].pop()}function x(e){if(e.errors.push({instancePath:[...e.instanceTokens],schemaPath:[...e.schemaTokens[e.schemaTokens.length-1]]}),e.errors.length===e.config.maxErrors)throw new Ee}});var It=y(I=>{"use strict";var Dn=I&&I.__createBinding||(Object.create?function(e,t,r,i){i===void 0&&(i=r),Object.defineProperty(e,i,{enumerable:!0,get:function(){return t[r]}})}:function(e,t,r,i){i===void 0&&(i=r),e[i]=t[r]}),Rt=I&&I.__exportStar||function(e,t){for(var r in e)r!=="default"&&!t.hasOwnProperty(r)&&Dn(t,e,r)};Object.defineProperty(I,"__esModule",{value:!0});Rt(Ue(),I);Rt(Bt(),I)});var Yn={};Xt(Yn,{GenerationError:()=>Ae,ResponseError:()=>z,builtinFontNames:()=>$n,builtinLineHeights:()=>zt,builtinMargins:()=>Jt,builtinTextScales:()=>Ht,builtinTools:()=>Ln,formatEntry:()=>Gt,parseEntry:()=>Vt,register:()=>Gn,remarkable:()=>Vn});module.exports=er(Yn);var Lt=te(Ye()),$t=te(it());var S=te(_t(),1),hi=S.default.v1,vi=S.default.v3,Pe=S.default.v4,bi=S.default.v5,wi=S.default.NIL,xi=S.default.version,Pi=S.default.validate,_i=S.default.stringify,Ei=S.default.parse;function Le(e){return[...new Uint8Array(e)].map(t=>t.toString(16).padStart(2,"0")).join("")}function Et(e){return new Uint8Array((e.match(/../g)??[]).map(t=>parseInt(t,16)))}function Ot(e){let t=0;for(let n of e)t+=n.length;let r=new Uint8Array(t),i=0;for(let n of e)r.set(n,i),i+=n.length;return r}var Dt=te(It());function Q(e,t){if((0,Dt.validate)(e,t).length)throw new Error(`couldn't validate schema: ${JSON.stringify(t)} didn't match schema ${JSON.stringify(e)}`)}var qt="3",Ut="https://webapp-prod.cloud.remarkable.engineering",qn="https://internal.cloud.remarkable.com",Nt="x-goog-generation",Nn="x-goog-if-generation-match",jn="x-goog-content-length-range",Ln=["Ballpoint","Ballpointv2","Brush","Calligraphy","ClearPage","EraseSection","Eraser","Fineliner","Finelinerv2","Highlighter","Highlighterv2","Marker","Markerv2","Paintbrush","Paintbrushv2","Pencilv2","SharpPencil","SharpPencilv2","SolidPen","ZoomTool"],$n=["Maison Neue","EB Garamond","Noto Sans","Noto Serif","Noto Mono","Noto Sans UI"],Ht={xs:.7,sm:.8,md:1,lg:1.2,xl:1.5,xx:2},Jt={sm:50,md:125,rr:180,lg:200},zt={df:-1,md:100,lg:150,xl:200},Un={properties:{docID:{type:"string"},hash:{type:"string"}}},Hn={properties:{relative_path:{type:"string"},url:{type:"string"},expires:{type:"timestamp"},method:{enum:["POST","GET","PUT","DELETE"]}},optionalProperties:{maxuploadsize_bytes:{type:"float64"}}},Oe={visibleName:{type:"string"},lastModified:{type:"string"}},Te={version:{type:"int32"},pinned:{type:"boolean"},synced:{type:"boolean"},modified:{type:"boolean"},deleted:{type:"boolean"},metadatamodified:{type:"boolean"},parent:{type:"string"}},Jn={discriminator:"type",mapping:{CollectionType:{properties:Oe,optionalProperties:Te},DocumentType:{properties:Oe,optionalProperties:{...Te,lastOpened:{type:"string"},lastOpenedPage:{type:"int32"}}}}},jt={id:{type:"string"},hash:{type:"string"}},zn={discriminator:"type",mapping:{CollectionType:{properties:{...Oe,...jt},optionalProperties:Te},DocumentType:{properties:{...Oe,...jt,fileType:{enum:["notebook","epub","pdf",""]}},optionalProperties:{...Te,lastOpened:{type:"string"},lastOpenedPage:{type:"int32"}}}}},z=class extends Error{constructor(r,i,n){super(n);this.status=r,this.statusText=i}},Ae=class extends Error{constructor(){super("Generation preconditions failed. This means the current state is out of date with the cloud and needs to be re-synced.")}};async function Gn(e,{deviceDesc:t="browser-chrome",uuid:r=Pe(),authHost:i=Ut,fetch:n=globalThis.fetch}={}){if(e.length!==8)throw new Error(`code should be length 8, but was ${e.length}`);let a=await n(`${i}/token/json/2/device/new`,{method:"POST",headers:{Authorization:"Bearer"},body:JSON.stringify({code:e,deviceDesc:t,deviceID:r})});if(a.ok)return await a.text();throw new z(a.status,a.statusText,"couldn't register api")}function Gt({hash:e,type:t,documentId:r,subfiles:i,size:n}){return`${e}:${t}:${r}:${i}:${n}
|
|
10
|
+
`}function Vt(e){let[t,r,i,n,a]=e.split(":");if(t===void 0||r===void 0||i===void 0||n===void 0||a===void 0)throw new Error(`entries line didn't contain five fields: '${e}'`);if(r==="80000000")return{hash:t,type:r,documentId:i,subfiles:parseInt(n),size:BigInt(a)};if(r==="0"){if(n!=="0")throw new Error(`file type entry had nonzero number of subfiles: ${n}`);return{hash:t,type:r,documentId:i,subfiles:0,size:BigInt(a)}}else throw new Error(`entries line contained invalid type: ${r}`)}var Je=class{#u;#s;#f;#r;#n;#e=new Map;#t=null;constructor(t,r,i,n,a,o){this.#u=t,this.#s=r,this.#f=i,this.#r=n,this.#n=a;for(let[f,s]of o)this.#e.set(f,Promise.resolve(s))}async#i(t,{body:r,method:i="POST",headers:n={}}){let a=await this.#s(t,{method:i,headers:{Authorization:`Bearer ${this.#u}`,...n},body:r});if(a.ok)return a;{let o=await a.text();throw new z(a.status,a.statusText,`failed reMarkable request: ${o}`)}}async#a({url:t,method:r,maxuploadsize_bytes:i},n,a={}){let o=i?{...a,[jn]:`0,${i}`}:a,f=await this.#s(t,{method:r,body:n,headers:o});if(f.ok)return f;{let s=await f.text();throw new z(f.status,f.statusText,s)}}async#o(t,r,i){let n=r===void 0?"downloads":"uploads",a=i&&r!==null&&r!==void 0?`{ "http_method": "PUT", "relative_path": "${t}", "root_schema": "${i}", "generation": ${r} }`:JSON.stringify({http_method:"GET",relative_path:t}),f=await(await this.#i(`${this.#r}/sync/v2/signed-urls/${n}`,{body:a})).text(),s=JSON.parse(f);return Q(Hn,s),s}async getRootHash({cache:t=!0}={}){if(t)for(;this.#t;)try{let[a,o]=await this.#t;return[a,o]}catch{}let r=(async()=>{try{let a=await this.#o("root"),o=await this.#a(a),f=o.headers.get(Nt);if(f)return[await o.text(),BigInt(f)];throw new Error("no generation header in root hash")}catch(a){throw this.#t=null,a}})();this.#t=r;let[i,n]=await r;return[i,n]}async putRootHash(t,r){let i=await this.#o("root",r,t),n;try{n=await this.#a(i,t,{[Nn]:`${r}`})}catch(f){throw f instanceof z&&f.status===412?(this.#t=null,new Ae):f}let a=n.headers.get(Nt);if(!a)throw new Error("no generation header in root hash");let o=BigInt(a);return this.#t=Promise.resolve([t,o]),o}async#l(t){let r=this.#e.get(t);for(;r;)try{let n=await r;if(n)return n;r=void 0}catch{r=this.#e.get(t)}let i=(async()=>{let n=await this.#o(t);return await(await this.#a(n)).arrayBuffer()})();return this.#e.set(t,i.then(n=>n.byteLength<this.#n?n:null,n=>{throw this.#e.delete(t),n})),await i}async getBuffer(t){let r=await this.#l(t);return r.byteLength<this.#n?r.slice(0):r}async getText(t){let r=await this.#l(t);return new TextDecoder().decode(r)}async getJson(t){let r=await this.getText(t);return JSON.parse(r)}async getMetadata(t){let r=await this.getJson(t);return Q(Jn,r),r}async getEntries(t){if(t===void 0){let[a]=await this.getRootHash({cache:!0});t=a}let r=await this.getText(t),[i,...n]=r.slice(0,-1).split(`
|
|
11
|
+
`);if(i!==qt)throw new Error(`got unexpected schema version: ${i}`);return n.map(Vt)}async#c(t,r){let i=this.#e.get(t);if(i)try{await i;return}catch{}let n=(async()=>{try{let a=await this.#o(t,null);return await this.#a(a,r),r.byteLength<this.#n?r:null}catch(a){throw this.#e.delete(t),a}})();this.#e.set(t,n),await n}async putEntries(t,r){let i=new TextEncoder;r.sort((u,g)=>u.documentId.localeCompare(g.documentId));let n=Ot(r.map(u=>Et(u.hash))),a=await this.#f.digest("SHA-256",n),o=Le(a),f=r.map(Gt).join(""),s=`${qt}
|
|
12
|
+
${f}`,c=i.encode(s);return await this.#c(o,c),{hash:o,type:"80000000",documentId:t,subfiles:r.length,size:0n}}async putBuffer(t,r){let i=await this.#f.digest("SHA-256",r),n=Le(i);return await this.#c(n,r),{hash:n,type:"0",documentId:t,subfiles:0,size:BigInt(r.byteLength)}}async putText(t,r){let i=new TextEncoder;return await this.putBuffer(t,i.encode(r))}async putJson(t,r){return await this.putText(t,(0,$t.default)(r))}async putMetadata(t,r){return await this.putJson(`${t}.metadata`,r)}async putCollection(t,r=""){let i=Pe(),n=`${new Date().valueOf()}`,a=[],o={type:"CollectionType",visibleName:t,version:0,parent:r,synced:!0,lastModified:n};a.push(this.putMetadata(i,o)),a.push(this.putText(`${i}.content`,"{}"));let f=await Promise.all(a);return await this.putEntries(i,f)}async#d(t,r,i,n,a){if(a.fileType!==i)throw new Error(`internal error: fileTypes don't match: ${i}, ${a.fileType}`);let o=Pe(),f=`${new Date().valueOf()}`,s=[];s.push(this.putBuffer(`${o}.${i}`,r));let c={type:"DocumentType",visibleName:t,version:0,parent:n,synced:!0,lastModified:f};s.push(this.putMetadata(o,c)),s.push(this.putText(`${o}.content`,JSON.stringify(a)));let u=await Promise.all(s);return await this.putEntries(o,u)}async putEpub(t,r,{parent:i="",margins:n=125,orientation:a,textAlignment:o,textScale:f=1,lineHeight:s=-1,fontName:c="",cover:u="visited",lastTool:g}={}){let p={dummyDocument:!1,extraMetadata:{LastTool:g},fileType:"epub",pageCount:0,lastOpenedPage:0,lineHeight:typeof s=="string"?zt[s]:s,margins:typeof n=="string"?Jt[n]:n,textScale:typeof f=="string"?Ht[f]:f,pages:[],coverPageNumber:u==="first"?0:-1,formatVersion:1,orientation:a,textAlignment:o,fontName:c};return await this.#d(t,r,"epub",i,p)}async putPdf(t,r,{parent:i="",orientation:n,cover:a="first",lastTool:o}={}){let f={dummyDocument:!1,extraMetadata:{LastTool:o},fileType:"pdf",pageCount:0,lastOpenedPage:0,lineHeight:-1,margins:125,textScale:1,pages:[],coverPageNumber:a==="first"?0:-1,formatVersion:1,orientation:n};return await this.#d(t,r,"pdf",i,f)}async syncComplete(t){let r=`{ "generation": ${t} }`;await this.#i(`${this.#r}/sync/v2/sync-complete`,{body:r})}async#p(t,r,i){let{hash:n}=await this.putEntries("",r),a=await this.putRootHash(n,t);if(i)try{return await this.syncComplete(a),!0}catch{return!1}else return!1}async create(t,{cache:r=!0,sync:i=!0}={}){let[n,a]=await this.getRootHash({cache:r}),o=await this.getEntries(n);return o.push(t),await this.#p(a,o,i)}async move(t,r,{cache:i=!0,sync:n=!0}={}){let[a,o]=await this.getRootHash({cache:i}),f=await this.getEntries(a);if(!(!r||r==="trash")){let E=f.find(Y=>Y.documentId===r);if(E){if(E.type!=="80000000")throw new Error(`destination id was a raw file: ${r}`)}else throw new Error(`destination id not found: ${r}`);let T=await this.getEntries(E.hash),[v]=T.filter(Y=>Y.documentId===`${r}.metadata`);if(!v)throw new Error(`destination id didn't have metadata: ${r}`);if((await this.getMetadata(v.hash)).type!=="CollectionType")throw new Error(`destination id wasn't a collection: ${r}`)}let s=f.findIndex(E=>E.documentId===t);if(s===-1)throw new Error(`document not found: ${t}`);let[c]=f.splice(s,1);if(c.type!=="80000000")throw new Error(`document was a raw file: ${t}`);let u=await this.getEntries(c.hash),g=u.findIndex(E=>E.documentId===`${t}.metadata`);if(g===-1)throw new Error(`document didn't have metadata: ${t}`);let[p]=u.splice(g,1),C=await this.getMetadata(p.hash);C.parent=r;let h=await this.putMetadata(t,C);u.push(h);let V=await this.putEntries(t,u);return f.push(V),await this.#p(o,f,n)}async getEntriesMetadata(){let r=await(await this.#i(`${this.#r}/doc/v2/files`,{method:"GET",headers:{"rm-source":"RoR-Browser"}})).text(),i=JSON.parse(r);return Q({elements:zn},i),i}async#y(t,r,i){let a=new TextEncoder().encode(JSON.stringify({file_name:t})),f=await(await this.#i(`${this.#r}/doc/v2/files`,{body:r,headers:{"content-type":i,"rm-meta":(0,Lt.fromByteArray)(a),"rm-source":"RoR-Browser"}})).text(),s=JSON.parse(f);return Q(Un,s),s}async uploadEpub(t,r){return await this.#y(t,r,"application/epub+zip")}async uploadPdf(t,r){return await this.#y(t,r,"application/pdf")}async getCache(){let t=[];for(let[n,a]of this.#e)t.push(a.then(o=>[n,o],()=>[n,null]));let r=await Promise.all(t),i=new Map;for(let[n,a]of r)a&&i.set(n,a);return i}};async function Vn(e,{fetch:t=globalThis.fetch,subtle:r=globalThis.crypto?.subtle,authHost:i=Ut,syncHost:n=qn,cacheLimitBytes:a=1048576,initCache:o=[]}={}){if(!r)throw new Error("subtle was missing, try specifying it manually");let f=await t(`${i}/token/json/2/user/new`,{method:"POST",headers:{Authorization:`Bearer ${e}`}});if(!f.ok)throw new Error(`couldn't fetch auth token: ${f.statusText}`);let s=await f.text();return new Je(s,t,r,n,a,o)}0&&(module.exports={GenerationError,ResponseError,builtinFontNames,builtinLineHeights,builtinMargins,builtinTextScales,builtinTools,formatEntry,parseEntry,register,remarkable});
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
var He=Object.create;var ye=Object.defineProperty;var Je=Object.getOwnPropertyDescriptor;var Ve=Object.getOwnPropertyNames;var qe=Object.getPrototypeOf,Ge=Object.prototype.hasOwnProperty;var j=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports);var ze=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of Ve(r))!Ge.call(e,i)&&i!==t&&ye(e,i,{get:()=>r[i],enumerable:!(n=Je(r,i))||n.enumerable});return e};var ge=(e,r,t)=>(t=e!=null?He(qe(e)):{},ze(r||!e||!e.__esModule?ye(t,"default",{value:e,enumerable:!0}):t,e));var we=j(W=>{"use strict";W.byteLength=Ye;W.toByteArray=Ke;W.fromByteArray=et;var S=[],T=[],We=typeof Uint8Array<"u"?Uint8Array:Array,ie="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(C=0,he=ie.length;C<he;++C)S[C]=ie[C],T[ie.charCodeAt(C)]=C;var C,he;T["-".charCodeAt(0)]=62;T["_".charCodeAt(0)]=63;function be(e){var r=e.length;if(r%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var t=e.indexOf("=");t===-1&&(t=r);var n=t===r?0:4-t%4;return[t,n]}function Ye(e){var r=be(e),t=r[0],n=r[1];return(t+n)*3/4-n}function Ze(e,r,t){return(r+t)*3/4-t}function Ke(e){var r,t=be(e),n=t[0],i=t[1],o=new We(Ze(e,n,i)),s=0,a=i>0?n-4:n,f;for(f=0;f<a;f+=4)r=T[e.charCodeAt(f)]<<18|T[e.charCodeAt(f+1)]<<12|T[e.charCodeAt(f+2)]<<6|T[e.charCodeAt(f+3)],o[s++]=r>>16&255,o[s++]=r>>8&255,o[s++]=r&255;return i===2&&(r=T[e.charCodeAt(f)]<<2|T[e.charCodeAt(f+1)]>>4,o[s++]=r&255),i===1&&(r=T[e.charCodeAt(f)]<<10|T[e.charCodeAt(f+1)]<<4|T[e.charCodeAt(f+2)]>>2,o[s++]=r>>8&255,o[s++]=r&255),o}function Xe(e){return S[e>>18&63]+S[e>>12&63]+S[e>>6&63]+S[e&63]}function Qe(e,r,t){for(var n,i=[],o=r;o<t;o+=3)n=(e[o]<<16&16711680)+(e[o+1]<<8&65280)+(e[o+2]&255),i.push(Xe(n));return i.join("")}function et(e){for(var r,t=e.length,n=t%3,i=[],o=16383,s=0,a=t-n;s<a;s+=o)i.push(Qe(e,s,s+o>a?a:s+o));return n===1?(r=e[t-1],i.push(S[r>>2]+S[r<<4&63]+"==")):n===2&&(r=(e[t-2]<<8)+e[t-1],i.push(S[r>>10]+S[r>>4&63]+S[r<<2&63]+"=")),i.join("")}});var ue=j(d=>{"use strict";var ke=d&&d.__rest||function(e,r){var t={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&r.indexOf(n)<0&&(t[n]=e[n]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(e);i<n.length;i++)r.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(t[n[i]]=e[n[i]]);return t};Object.defineProperty(d,"__esModule",{value:!0});d.isSchema=d.isValidSchema=d.isDiscriminatorForm=d.isValuesForm=d.isPropertiesForm=d.isElementsForm=d.isEnumForm=d.isTypeForm=d.isRefForm=d.isEmptyForm=void 0;function gt(e){let{definitions:r,nullable:t,metadata:n}=e,i=ke(e,["definitions","nullable","metadata"]);return Object.keys(i).length===0}d.isEmptyForm=gt;function Se(e){return"ref"in e}d.isRefForm=Se;function ht(e){return"type"in e}d.isTypeForm=ht;function Oe(e){return"enum"in e}d.isEnumForm=Oe;function Fe(e){return"elements"in e}d.isElementsForm=Fe;function le(e){return"properties"in e||"optionalProperties"in e}d.isPropertiesForm=le;function Me(e){return"values"in e}d.isValuesForm=Me;function Ce(e){return"discriminator"in e}d.isDiscriminatorForm=Ce;function U(e,r){if(r===void 0&&(r=e),e.definitions!==void 0){if(r!==e)return!1;for(let t of Object.values(e.definitions))if(!U(t,r))return!1}if(Se(e)&&!(e.ref in(r.definitions||{}))||Oe(e)&&(e.enum.length===0||e.enum.length!==new Set(e.enum).size))return!1;if(Fe(e))return U(e.elements,r);if(le(e)){for(let t of Object.values(e.properties||{}))if(!U(t,r))return!1;for(let t of Object.values(e.optionalProperties||{}))if(!U(t,r))return!1;for(let t of Object.keys(e.properties||{}))if(t in(e.optionalProperties||{}))return!1}if(Me(e))return U(e.values,r);if(Ce(e)){for(let t of Object.values(e.mapping))if(!U(t,r)||!le(t)||t.nullable||e.discriminator in(t.properties||{})||e.discriminator in(t.optionalProperties||{}))return!1}return!0}d.isValidSchema=U;var bt=[[!1,!1,!1,!1,!1,!1,!1,!1,!1,!1],[!0,!1,!1,!1,!1,!1,!1,!1,!1,!1],[!1,!0,!1,!1,!1,!1,!1,!1,!1,!1],[!1,!1,!0,!1,!1,!1,!1,!1,!1,!1],[!1,!1,!1,!0,!1,!1,!1,!1,!1,!1],[!1,!1,!1,!1,!0,!1,!1,!1,!1,!1],[!1,!1,!1,!1,!1,!0,!1,!1,!1,!1],[!1,!1,!1,!1,!0,!0,!1,!1,!1,!1],[!1,!1,!1,!1,!0,!1,!0,!1,!1,!1],[!1,!1,!1,!1,!1,!0,!0,!1,!1,!1],[!1,!1,!1,!1,!0,!0,!0,!1,!1,!1],[!1,!1,!1,!1,!1,!1,!1,!0,!1,!1],[!1,!1,!1,!1,!1,!1,!1,!1,!0,!0]],wt=["boolean","float32","float64","int8","uint8","int16","uint16","int32","uint32","string","timestamp"];function I(e){if(typeof e!="object"||Array.isArray(e)||e===null)return!1;let r=e,{definitions:t=void 0,nullable:n=void 0,metadata:i=void 0,ref:o=void 0,type:s=void 0,enum:a=void 0,elements:f=void 0,properties:l=void 0,optionalProperties:u=void 0,additionalProperties:E=void 0,values:P=void 0,discriminator:c=void 0,mapping:A=void 0}=r,B=ke(r,["definitions","nullable","metadata","ref","type","enum","elements","properties","optionalProperties","additionalProperties","values","discriminator","mapping"]),re=[o!==void 0,s!==void 0,a!==void 0,f!==void 0,l!==void 0,u!==void 0,E!==void 0,P!==void 0,c!==void 0,A!==void 0],k=!1;for(let v of bt)k=k||v.every((z,me)=>z===re[me]);if(!k)return!1;if(t!==void 0){if(typeof t!="object"||Array.isArray(t)||t===null)return!1;for(let v of Object.values(t))if(!I(v))return!1}if(n!==void 0&&typeof n!="boolean"||i!==void 0&&(typeof i!="object"||Array.isArray(i)||i===null)||o!==void 0&&typeof o!="string"||s!==void 0&&(typeof s!="string"||!wt.includes(s))||a!==void 0&&(!Array.isArray(a)||!a.every(v=>typeof v=="string"))||f!==void 0&&!I(f))return!1;if(l!==void 0){if(typeof l!="object"||Array.isArray(l)||l===null)return!1;for(let v of Object.values(l))if(!I(v))return!1}if(u!==void 0){if(typeof u!="object"||Array.isArray(u)||u===null)return!1;for(let v of Object.values(u))if(!I(v))return!1}if(E!==void 0&&typeof E!="boolean"||P!==void 0&&!I(P)||c!==void 0&&typeof c!="string")return!1;if(A!==void 0){if(typeof A!="object"||Array.isArray(A)||A===null)return!1;for(let v of Object.values(A))if(!I(v))return!1}return Object.keys(B).length===0}d.isSchema=I});var Ue=j(de=>{"use strict";Object.defineProperty(de,"__esModule",{value:!0});var xt=/^(\d{4})-(\d{2})-(\d{2})[tT](\d{2}):(\d{2}):(\d{2})(\.\d+)?([zZ]|((\+|-)(\d{2}):(\d{2})))$/;function Et(e){let r=e.match(xt);if(r===null)return!1;let t=parseInt(r[1],10),n=parseInt(r[2],10),i=parseInt(r[3],10),o=parseInt(r[4],10),s=parseInt(r[5],10),a=parseInt(r[6],10);return!(n>12||i>vt(t,n)||o>23||s>59||a>60)}de.default=Et;function vt(e,r){return r===2?Pt(e)?29:28:Tt[r]}function Pt(e){return e%4===0&&(e%100!==0||e%400===0)}var Tt=[0,31,0,31,30,31,30,31,31,30,31,30,31]});var Ie=j(F=>{"use strict";var At=F&&F.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(F,"__esModule",{value:!0});F.validate=F.MaxDepthExceededError=void 0;var kt=At(Ue()),R=ue(),X=class extends Error{};F.MaxDepthExceededError=X;var Q=class extends Error{};function St(e,r,t){let n={errors:[],instanceTokens:[],schemaTokens:[[]],root:e,config:t||{maxDepth:0,maxErrors:0}};try{L(n,e,r)}catch(i){if(!(i instanceof Q))throw i}return n.errors}F.validate=St;function L(e,r,t,n){if(!(r.nullable&&t===null)){if(R.isRefForm(r)){if(e.schemaTokens.length===e.config.maxDepth)throw new X;e.schemaTokens.push(["definitions",r.ref]),L(e,e.root.definitions[r.ref],t),e.schemaTokens.pop()}else if(R.isTypeForm(r)){switch(b(e,"type"),r.type){case"boolean":typeof t!="boolean"&&w(e);break;case"float32":case"float64":typeof t!="number"&&w(e);break;case"int8":D(e,t,-128,127);break;case"uint8":D(e,t,0,255);break;case"int16":D(e,t,-32768,32767);break;case"uint16":D(e,t,0,65535);break;case"int32":D(e,t,-2147483648,2147483647);break;case"uint32":D(e,t,0,4294967295);break;case"string":typeof t!="string"&&w(e);break;case"timestamp":typeof t!="string"?w(e):kt.default(t)||w(e);break}x(e)}else if(R.isEnumForm(r))b(e,"enum"),(typeof t!="string"||!r.enum.includes(t))&&w(e),x(e);else if(R.isElementsForm(r)){if(b(e,"elements"),Array.isArray(t))for(let[i,o]of t.entries())_(e,i.toString()),L(e,r.elements,o),$(e);else w(e);x(e)}else if(R.isPropertiesForm(r))if(typeof t=="object"&&t!==null&&!Array.isArray(t)){if(r.properties!==void 0){b(e,"properties");for(let[i,o]of Object.entries(r.properties))b(e,i),t.hasOwnProperty(i)?(_(e,i),L(e,o,t[i]),$(e)):w(e),x(e);x(e)}if(r.optionalProperties!==void 0){b(e,"optionalProperties");for(let[i,o]of Object.entries(r.optionalProperties))b(e,i),t.hasOwnProperty(i)&&(_(e,i),L(e,o,t[i]),$(e)),x(e);x(e)}if(r.additionalProperties!==!0)for(let i of Object.keys(t)){let o=r.properties&&i in r.properties,s=r.optionalProperties&&i in r.optionalProperties;!o&&!s&&i!==n&&(_(e,i),w(e),$(e))}}else r.properties!==void 0?b(e,"properties"):b(e,"optionalProperties"),w(e),x(e);else if(R.isValuesForm(r)){if(b(e,"values"),typeof t=="object"&&t!==null&&!Array.isArray(t))for(let[i,o]of Object.entries(t))_(e,i),L(e,r.values,o),$(e);else w(e);x(e)}else if(R.isDiscriminatorForm(r))if(typeof t=="object"&&t!==null&&!Array.isArray(t))if(t.hasOwnProperty(r.discriminator)){let i=t[r.discriminator];typeof i=="string"?i in r.mapping?(b(e,"mapping"),b(e,i),L(e,r.mapping[i],t,r.discriminator),x(e),x(e)):(b(e,"mapping"),_(e,r.discriminator),w(e),$(e),x(e)):(b(e,"discriminator"),_(e,r.discriminator),w(e),$(e),x(e))}else b(e,"discriminator"),w(e),x(e);else b(e,"discriminator"),w(e),x(e)}}function D(e,r,t,n){(typeof r!="number"||!Number.isInteger(r)||r<t||r>n)&&w(e)}function _(e,r){e.instanceTokens.push(r)}function $(e){e.instanceTokens.pop()}function b(e,r){e.schemaTokens[e.schemaTokens.length-1].push(r)}function x(e){e.schemaTokens[e.schemaTokens.length-1].pop()}function w(e){if(e.errors.push({instancePath:[...e.instanceTokens],schemaPath:[...e.schemaTokens[e.schemaTokens.length-1]]}),e.errors.length===e.config.maxErrors)throw new Q}});var _e=j(M=>{"use strict";var Ot=M&&M.__createBinding||(Object.create?function(e,r,t,n){n===void 0&&(n=t),Object.defineProperty(e,n,{enumerable:!0,get:function(){return r[t]}})}:function(e,r,t,n){n===void 0&&(n=t),e[n]=r[t]}),Re=M&&M.__exportStar||function(e,r){for(var t in e)t!=="default"&&!r.hasOwnProperty(t)&&Ot(r,e,t)};Object.defineProperty(M,"__esModule",{value:!0});Re(ue(),M);Re(Ie(),M)});var Be=ge(we());var Y,tt=new Uint8Array(16);function Z(){if(!Y&&(Y=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!Y))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return Y(tt)}var xe=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;function rt(e){return typeof e=="string"&&xe.test(e)}var H=rt;var p=[];for(let e=0;e<256;++e)p.push((e+256).toString(16).slice(1));function J(e,r=0){return(p[e[r+0]]+p[e[r+1]]+p[e[r+2]]+p[e[r+3]]+"-"+p[e[r+4]]+p[e[r+5]]+"-"+p[e[r+6]]+p[e[r+7]]+"-"+p[e[r+8]]+p[e[r+9]]+"-"+p[e[r+10]]+p[e[r+11]]+p[e[r+12]]+p[e[r+13]]+p[e[r+14]]+p[e[r+15]]).toLowerCase()}function nt(e){if(!H(e))throw TypeError("Invalid UUID");let r,t=new Uint8Array(16);return t[0]=(r=parseInt(e.slice(0,8),16))>>>24,t[1]=r>>>16&255,t[2]=r>>>8&255,t[3]=r&255,t[4]=(r=parseInt(e.slice(9,13),16))>>>8,t[5]=r&255,t[6]=(r=parseInt(e.slice(14,18),16))>>>8,t[7]=r&255,t[8]=(r=parseInt(e.slice(19,23),16))>>>8,t[9]=r&255,t[10]=(r=parseInt(e.slice(24,36),16))/1099511627776&255,t[11]=r/4294967296&255,t[12]=r>>>24&255,t[13]=r>>>16&255,t[14]=r>>>8&255,t[15]=r&255,t}var oe=nt;function it(e){e=unescape(encodeURIComponent(e));let r=[];for(let t=0;t<e.length;++t)r.push(e.charCodeAt(t));return r}var ot="6ba7b810-9dad-11d1-80b4-00c04fd430c8",st="6ba7b811-9dad-11d1-80b4-00c04fd430c8";function V(e,r,t){function n(i,o,s,a){var f;if(typeof i=="string"&&(i=it(i)),typeof o=="string"&&(o=oe(o)),((f=o)===null||f===void 0?void 0:f.length)!==16)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");let l=new Uint8Array(16+i.length);if(l.set(o),l.set(i,o.length),l=t(l),l[6]=l[6]&15|r,l[8]=l[8]&63|128,s){a=a||0;for(let u=0;u<16;++u)s[a+u]=l[u];return s}return J(l)}try{n.name=e}catch{}return n.DNS=ot,n.URL=st,n}function at(e){if(typeof e=="string"){let r=unescape(encodeURIComponent(e));e=new Uint8Array(r.length);for(let t=0;t<r.length;++t)e[t]=r.charCodeAt(t)}return ft(lt(ut(e),e.length*8))}function ft(e){let r=[],t=e.length*32,n="0123456789abcdef";for(let i=0;i<t;i+=8){let o=e[i>>5]>>>i%32&255,s=parseInt(n.charAt(o>>>4&15)+n.charAt(o&15),16);r.push(s)}return r}function Ee(e){return(e+64>>>9<<4)+14+1}function lt(e,r){e[r>>5]|=128<<r%32,e[Ee(r)-1]=r;let t=1732584193,n=-271733879,i=-1732584194,o=271733878;for(let s=0;s<e.length;s+=16){let a=t,f=n,l=i,u=o;t=m(t,n,i,o,e[s],7,-680876936),o=m(o,t,n,i,e[s+1],12,-389564586),i=m(i,o,t,n,e[s+2],17,606105819),n=m(n,i,o,t,e[s+3],22,-1044525330),t=m(t,n,i,o,e[s+4],7,-176418897),o=m(o,t,n,i,e[s+5],12,1200080426),i=m(i,o,t,n,e[s+6],17,-1473231341),n=m(n,i,o,t,e[s+7],22,-45705983),t=m(t,n,i,o,e[s+8],7,1770035416),o=m(o,t,n,i,e[s+9],12,-1958414417),i=m(i,o,t,n,e[s+10],17,-42063),n=m(n,i,o,t,e[s+11],22,-1990404162),t=m(t,n,i,o,e[s+12],7,1804603682),o=m(o,t,n,i,e[s+13],12,-40341101),i=m(i,o,t,n,e[s+14],17,-1502002290),n=m(n,i,o,t,e[s+15],22,1236535329),t=y(t,n,i,o,e[s+1],5,-165796510),o=y(o,t,n,i,e[s+6],9,-1069501632),i=y(i,o,t,n,e[s+11],14,643717713),n=y(n,i,o,t,e[s],20,-373897302),t=y(t,n,i,o,e[s+5],5,-701558691),o=y(o,t,n,i,e[s+10],9,38016083),i=y(i,o,t,n,e[s+15],14,-660478335),n=y(n,i,o,t,e[s+4],20,-405537848),t=y(t,n,i,o,e[s+9],5,568446438),o=y(o,t,n,i,e[s+14],9,-1019803690),i=y(i,o,t,n,e[s+3],14,-187363961),n=y(n,i,o,t,e[s+8],20,1163531501),t=y(t,n,i,o,e[s+13],5,-1444681467),o=y(o,t,n,i,e[s+2],9,-51403784),i=y(i,o,t,n,e[s+7],14,1735328473),n=y(n,i,o,t,e[s+12],20,-1926607734),t=g(t,n,i,o,e[s+5],4,-378558),o=g(o,t,n,i,e[s+8],11,-2022574463),i=g(i,o,t,n,e[s+11],16,1839030562),n=g(n,i,o,t,e[s+14],23,-35309556),t=g(t,n,i,o,e[s+1],4,-1530992060),o=g(o,t,n,i,e[s+4],11,1272893353),i=g(i,o,t,n,e[s+7],16,-155497632),n=g(n,i,o,t,e[s+10],23,-1094730640),t=g(t,n,i,o,e[s+13],4,681279174),o=g(o,t,n,i,e[s],11,-358537222),i=g(i,o,t,n,e[s+3],16,-722521979),n=g(n,i,o,t,e[s+6],23,76029189),t=g(t,n,i,o,e[s+9],4,-640364487),o=g(o,t,n,i,e[s+12],11,-421815835),i=g(i,o,t,n,e[s+15],16,530742520),n=g(n,i,o,t,e[s+2],23,-995338651),t=h(t,n,i,o,e[s],6,-198630844),o=h(o,t,n,i,e[s+7],10,1126891415),i=h(i,o,t,n,e[s+14],15,-1416354905),n=h(n,i,o,t,e[s+5],21,-57434055),t=h(t,n,i,o,e[s+12],6,1700485571),o=h(o,t,n,i,e[s+3],10,-1894986606),i=h(i,o,t,n,e[s+10],15,-1051523),n=h(n,i,o,t,e[s+1],21,-2054922799),t=h(t,n,i,o,e[s+8],6,1873313359),o=h(o,t,n,i,e[s+15],10,-30611744),i=h(i,o,t,n,e[s+6],15,-1560198380),n=h(n,i,o,t,e[s+13],21,1309151649),t=h(t,n,i,o,e[s+4],6,-145523070),o=h(o,t,n,i,e[s+11],10,-1120210379),i=h(i,o,t,n,e[s+2],15,718787259),n=h(n,i,o,t,e[s+9],21,-343485551),t=O(t,a),n=O(n,f),i=O(i,l),o=O(o,u)}return[t,n,i,o]}function ut(e){if(e.length===0)return[];let r=e.length*8,t=new Uint32Array(Ee(r));for(let n=0;n<r;n+=8)t[n>>5]|=(e[n/8]&255)<<n%32;return t}function O(e,r){let t=(e&65535)+(r&65535);return(e>>16)+(r>>16)+(t>>16)<<16|t&65535}function dt(e,r){return e<<r|e>>>32-r}function K(e,r,t,n,i,o){return O(dt(O(O(r,e),O(n,o)),i),t)}function m(e,r,t,n,i,o,s){return K(r&t|~r&n,e,r,i,o,s)}function y(e,r,t,n,i,o,s){return K(r&n|t&~n,e,r,i,o,s)}function g(e,r,t,n,i,o,s){return K(r^t^n,e,r,i,o,s)}function h(e,r,t,n,i,o,s){return K(t^(r|~n),e,r,i,o,s)}var ve=at;var sr=V("v3",48,ve);var ct=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),se={randomUUID:ct};function pt(e,r,t){if(se.randomUUID&&!r&&!e)return se.randomUUID();e=e||{};let n=e.random||(e.rng||Z)();if(n[6]=n[6]&15|64,n[8]=n[8]&63|128,r){t=t||0;for(let i=0;i<16;++i)r[t+i]=n[i];return r}return J(n)}var q=pt;function mt(e,r,t,n){switch(e){case 0:return r&t^~r&n;case 1:return r^t^n;case 2:return r&t^r&n^t&n;case 3:return r^t^n}}function ae(e,r){return e<<r|e>>>32-r}function yt(e){let r=[1518500249,1859775393,2400959708,3395469782],t=[1732584193,4023233417,2562383102,271733878,3285377520];if(typeof e=="string"){let s=unescape(encodeURIComponent(e));e=[];for(let a=0;a<s.length;++a)e.push(s.charCodeAt(a))}else Array.isArray(e)||(e=Array.prototype.slice.call(e));e.push(128);let n=e.length/4+2,i=Math.ceil(n/16),o=new Array(i);for(let s=0;s<i;++s){let a=new Uint32Array(16);for(let f=0;f<16;++f)a[f]=e[s*64+f*4]<<24|e[s*64+f*4+1]<<16|e[s*64+f*4+2]<<8|e[s*64+f*4+3];o[s]=a}o[i-1][14]=(e.length-1)*8/Math.pow(2,32),o[i-1][14]=Math.floor(o[i-1][14]),o[i-1][15]=(e.length-1)*8&4294967295;for(let s=0;s<i;++s){let a=new Uint32Array(80);for(let c=0;c<16;++c)a[c]=o[s][c];for(let c=16;c<80;++c)a[c]=ae(a[c-3]^a[c-8]^a[c-14]^a[c-16],1);let f=t[0],l=t[1],u=t[2],E=t[3],P=t[4];for(let c=0;c<80;++c){let A=Math.floor(c/20),B=ae(f,5)+mt(A,l,u,E)+P+r[A]+a[c]>>>0;P=E,E=u,u=ae(l,30)>>>0,l=f,f=B}t[0]=t[0]+f>>>0,t[1]=t[1]+l>>>0,t[2]=t[2]+u>>>0,t[3]=t[3]+E>>>0,t[4]=t[4]+P>>>0}return[t[0]>>24&255,t[0]>>16&255,t[0]>>8&255,t[0]&255,t[1]>>24&255,t[1]>>16&255,t[1]>>8&255,t[1]&255,t[2]>>24&255,t[2]>>16&255,t[2]>>8&255,t[2]&255,t[3]>>24&255,t[3]>>16&255,t[3]>>8&255,t[3]&255,t[4]>>24&255,t[4]>>16&255,t[4]>>8&255,t[4]&255]}var Pe=yt;var gr=V("v5",80,Pe);function fe(e){return[...new Uint8Array(e)].map(r=>r.toString(16).padStart(2,"0")).join("")}function Te(e){return new Uint8Array((e.match(/../g)??[]).map(r=>parseInt(r,16)))}function Ae(e){let r=0;for(let i of e)r+=i.length;let t=new Uint8Array(r),n=0;for(let i of e)t.set(i,n),n+=i.length;return t}var $e=ge(_e());function G(e,r){if((0,$e.validate)(e,r).length)throw new Error(`couldn't validate schema: ${JSON.stringify(r)} didn't match schema ${JSON.stringify(e)}`)}var Le="3",je="https://webapp-prod.cloud.remarkable.engineering",Ft="https://internal.cloud.remarkable.com",De="x-goog-generation",Mt="x-goog-if-generation-match",Ct="x-goog-content-length-range",zr=["Ballpoint","Ballpointv2","Brush","Calligraphy","ClearPage","EraseSection","Eraser","Fineliner","Finelinerv2","Highlighter","Highlighterv2","Marker","Markerv2","Paintbrush","Paintbrushv2","Pencilv2","SharpPencil","SharpPencilv2","SolidPen","ZoomTool"],Wr=["Maison Neue","EB Garamond","Noto Sans","Noto Serif","Noto Mono","Noto Sans UI"],Ut={xs:.7,sm:.8,md:1,lg:1.2,xl:1.5,xx:2},It={sm:50,md:125,rr:180,lg:200},Rt={df:-1,md:100,lg:150,xl:200},_t={properties:{docID:{type:"string"},hash:{type:"string"}}},$t={properties:{relative_path:{type:"string"},url:{type:"string"},expires:{type:"timestamp"},method:{enum:["POST","GET","PUT","DELETE"]}},optionalProperties:{maxuploadsize_bytes:{type:"float64"}}},ee={visibleName:{type:"string"},lastModified:{type:"string"}},te={version:{type:"int32"},pinned:{type:"boolean"},synced:{type:"boolean"},modified:{type:"boolean"},deleted:{type:"boolean"},metadatamodified:{type:"boolean"},parent:{type:"string"}},Lt={discriminator:"type",mapping:{CollectionType:{properties:ee,optionalProperties:te},DocumentType:{properties:ee,optionalProperties:{...te,lastOpened:{type:"string"},lastOpenedPage:{type:"int32"}}}}},Ne={id:{type:"string"},hash:{type:"string"}},Dt={discriminator:"type",mapping:{CollectionType:{properties:{...ee,...Ne},optionalProperties:te},DocumentType:{properties:{...ee,...Ne,fileType:{enum:["notebook","epub","pdf",""]}},optionalProperties:{...te,lastOpened:{type:"string"},lastOpenedPage:{type:"int32"}}}}},N=class extends Error{constructor(t,n,i){super(i);this.status=t,this.statusText=n}},ce=class extends Error{constructor(){super("Generation preconditions failed. This means the current state is out of date with the cloud and needs to be re-synced.")}};async function Yr(e,{deviceDesc:r="browser-chrome",uuid:t=q(),authHost:n=je,fetch:i=globalThis.fetch}={}){if(e.length!==8)throw new Error(`code should be length 8, but was ${e.length}`);let o=await i(`${n}/token/json/2/device/new`,{method:"POST",headers:{Authorization:"Bearer"},body:JSON.stringify({code:e,deviceDesc:r,deviceID:t})});if(o.ok)return await o.text();throw new N(o.status,o.statusText,"couldn't register api")}function Nt({hash:e,type:r,documentId:t,subfiles:n,size:i}){return`${e}:${r}:${t}:${n}:${i}
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
var pt=Object.create;var Ce=Object.defineProperty;var yt=Object.getOwnPropertyDescriptor;var mt=Object.getOwnPropertyNames;var ht=Object.getPrototypeOf,gt=Object.prototype.hasOwnProperty;var j=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports);var bt=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of mt(r))!gt.call(e,i)&&i!==t&&Ce(e,i,{get:()=>r[i],enumerable:!(n=yt(r,i))||n.enumerable});return e};var me=(e,r,t)=>(t=e!=null?pt(ht(e)):{},bt(r||!e||!e.__esModule?Ce(t,"default",{value:e,enumerable:!0}):t,e));var Be=j(re=>{"use strict";re.byteLength=vt;re.toByteArray=Et;re.fromByteArray=At;var F=[],M=[],wt=typeof Uint8Array<"u"?Uint8Array:Array,he="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(L=0,Fe=he.length;L<Fe;++L)F[L]=he[L],M[he.charCodeAt(L)]=L;var L,Fe;M["-".charCodeAt(0)]=62;M["_".charCodeAt(0)]=63;function je(e){var r=e.length;if(r%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var t=e.indexOf("=");t===-1&&(t=r);var n=t===r?0:4-t%4;return[t,n]}function vt(e){var r=je(e),t=r[0],n=r[1];return(t+n)*3/4-n}function xt(e,r,t){return(r+t)*3/4-t}function Et(e){var r,t=je(e),n=t[0],i=t[1],o=new wt(xt(e,n,i)),a=0,f=i>0?n-4:n,s;for(s=0;s<f;s+=4)r=M[e.charCodeAt(s)]<<18|M[e.charCodeAt(s+1)]<<12|M[e.charCodeAt(s+2)]<<6|M[e.charCodeAt(s+3)],o[a++]=r>>16&255,o[a++]=r>>8&255,o[a++]=r&255;return i===2&&(r=M[e.charCodeAt(s)]<<2|M[e.charCodeAt(s+1)]>>4,o[a++]=r&255),i===1&&(r=M[e.charCodeAt(s)]<<10|M[e.charCodeAt(s+1)]<<4|M[e.charCodeAt(s+2)]>>2,o[a++]=r>>8&255,o[a++]=r&255),o}function Pt(e){return F[e>>18&63]+F[e>>12&63]+F[e>>6&63]+F[e&63]}function Tt(e,r,t){for(var n,i=[],o=r;o<t;o+=3)n=(e[o]<<16&16711680)+(e[o+1]<<8&65280)+(e[o+2]&255),i.push(Pt(n));return i.join("")}function At(e){for(var r,t=e.length,n=t%3,i=[],o=16383,a=0,f=t-n;a<f;a+=o)i.push(Tt(e,a,a+o>f?f:a+o));return n===1?(r=e[t-1],i.push(F[r>>2]+F[r<<4&63]+"==")):n===2&&(r=(e[t-2]<<8)+e[t-1],i.push(F[r>>10]+F[r>>4&63]+F[r<<2&63]+"=")),i.join("")}});var Ue=j((vr,Ne)=>{"use strict";var ne,u,Ie={'"':'"',"\\":"\\","/":"/",b:"\b",f:"\f",n:`
|
|
2
|
+
`,r:"\r",t:" "},ge;function I(e){throw{name:"SyntaxError",message:e,at:ne,text:ge}}function d(e){return e&&e!==u&&I("Expected '"+e+"' instead of '"+u+"'"),u=ge.charAt(ne),ne+=1,u}function Re(){var e,r="";for(u==="-"&&(r="-",d("-"));u>="0"&&u<="9";)r+=u,d();if(u===".")for(r+=".";d()&&u>="0"&&u<="9";)r+=u;if(u==="e"||u==="E")for(r+=u,d(),(u==="-"||u==="+")&&(r+=u,d());u>="0"&&u<="9";)r+=u,d();return e=Number(r),isFinite(e)||I("Bad number"),e}function _e(){var e,r,t="",n;if(u==='"')for(;d();){if(u==='"')return d(),t;if(u==="\\")if(d(),u==="u"){for(n=0,r=0;r<4&&(e=parseInt(d(),16),!!isFinite(e));r+=1)n=n*16+e;t+=String.fromCharCode(n)}else if(typeof Ie[u]=="string")t+=Ie[u];else break;else t+=u}I("Bad string")}function B(){for(;u&&u<=" ";)d()}function Ot(){switch(u){case"t":return d("t"),d("r"),d("u"),d("e"),!0;case"f":return d("f"),d("a"),d("l"),d("s"),d("e"),!1;case"n":return d("n"),d("u"),d("l"),d("l"),null;default:I("Unexpected '"+u+"'")}}function St(){var e=[];if(u==="["){if(d("["),B(),u==="]")return d("]"),e;for(;u;){if(e.push(ie()),B(),u==="]")return d("]"),e;d(","),B()}}I("Bad array")}function kt(){var e,r={};if(u==="{"){if(d("{"),B(),u==="}")return d("}"),r;for(;u;){if(e=_e(),B(),d(":"),Object.prototype.hasOwnProperty.call(r,e)&&I('Duplicate key "'+e+'"'),r[e]=ie(),B(),u==="}")return d("}"),r;d(","),B()}}I("Bad object")}function ie(){switch(B(),u){case"{":return kt();case"[":return St();case'"':return _e();case"-":return Re();default:return u>="0"&&u<="9"?Re():Ot()}}Ne.exports=function(e,r){var t;return ge=e,ne=0,u=" ",t=ie(),B(),u&&I("Syntax error"),typeof r=="function"?function n(i,o){var a,f,s=i[o];if(s&&typeof s=="object")for(a in ie)Object.prototype.hasOwnProperty.call(s,a)&&(f=n(s,a),typeof f>"u"?delete s[a]:s[a]=f);return r.call(i,o,s)}({"":t},""):t}});var De=j((xr,Le)=>{"use strict";var be=/[\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,S,oe,Mt={"\b":"\\b"," ":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},D;function we(e){return be.lastIndex=0,be.test(e)?'"'+e.replace(be,function(r){var t=Mt[r];return typeof t=="string"?t:"\\u"+("0000"+r.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+e+'"'}function ae(e,r){var t,n,i,o,a=S,f,s=r[e];switch(s&&typeof s=="object"&&typeof s.toJSON=="function"&&(s=s.toJSON(e)),typeof D=="function"&&(s=D.call(r,e,s)),typeof s){case"string":return we(s);case"number":return isFinite(s)?String(s):"null";case"boolean":case"null":return String(s);case"object":if(!s)return"null";if(S+=oe,f=[],Object.prototype.toString.apply(s)==="[object Array]"){for(o=s.length,t=0;t<o;t+=1)f[t]=ae(t,s)||"null";return i=f.length===0?"[]":S?`[
|
|
3
|
+
`+S+f.join(`,
|
|
4
|
+
`+S)+`
|
|
5
|
+
`+a+"]":"["+f.join(",")+"]",S=a,i}if(D&&typeof D=="object")for(o=D.length,t=0;t<o;t+=1)n=D[t],typeof n=="string"&&(i=ae(n,s),i&&f.push(we(n)+(S?": ":":")+i));else for(n in s)Object.prototype.hasOwnProperty.call(s,n)&&(i=ae(n,s),i&&f.push(we(n)+(S?": ":":")+i));return i=f.length===0?"{}":S?`{
|
|
6
|
+
`+S+f.join(`,
|
|
7
|
+
`+S)+`
|
|
8
|
+
`+a+"}":"{"+f.join(",")+"}",S=a,i;default:}}Le.exports=function(e,r,t){var n;if(S="",oe="",typeof t=="number")for(n=0;n<t;n+=1)oe+=" ";else typeof t=="string"&&(oe=t);if(D=r,r&&typeof r!="function"&&(typeof r!="object"||typeof r.length!="number"))throw new Error("JSON.stringify");return ae("",{"":e})}});var $e=j(ve=>{"use strict";ve.parse=Ue();ve.stringify=De()});var Je=j((Pr,He)=>{"use strict";var se=typeof JSON<"u"?JSON:$e(),Ct=Array.isArray||function(e){return{}.toString.call(e)==="[object Array]"},Ft=Object.keys||function(e){var r=Object.prototype.hasOwnProperty||function(){return!0},t=[];for(var n in e)r.call(e,n)&&t.push(n);return t};He.exports=function(e,r){r||(r={}),typeof r=="function"&&(r={cmp:r});var t=r.space||"";typeof t=="number"&&(t=Array(t+1).join(" "));var n=typeof r.cycles=="boolean"?r.cycles:!1,i=r.replacer||function(f,s){return s},o=r.cmp&&function(f){return function(s){return function(c,l){var m={key:c,value:s[c]},g={key:l,value:s[l]};return f(m,g)}}}(r.cmp),a=[];return function f(s,c,l,m){var g=t?`
|
|
9
|
+
`+new Array(m+1).join(t):"",p=t?": ":":";if(l&&l.toJSON&&typeof l.toJSON=="function"&&(l=l.toJSON()),l=i.call(s,c,l),l!==void 0){if(typeof l!="object"||l===null)return se.stringify(l);if(Ct(l)){for(var C=[],h=0;h<l.length;h++){var U=f(l,h,l[h],m+1)||se.stringify(null);C.push(g+t+U)}return"["+C.join(",")+g+"]"}if(a.indexOf(l)!==-1){if(n)return se.stringify("__cycle__");throw new TypeError("Converting circular structure to JSON")}else a.push(l);for(var k=Ft(l).sort(o&&o(l)),C=[],h=0;h<k.length;h++){var c=k[h],b=f(l,c,l[c],m+1);if(b){var te=se.stringify(c)+p+b;C.push(g+t+te)}}return a.splice(a.indexOf(l),1),"{"+C.join(",")+g+"}"}}({"":e},"",e,0)}});var Oe=j(y=>{"use strict";var Ke=y&&y.__rest||function(e,r){var t={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&r.indexOf(n)<0&&(t[n]=e[n]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(e);i<n.length;i++)r.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(t[n[i]]=e[n[i]]);return t};Object.defineProperty(y,"__esModule",{value:!0});y.isSchema=y.isValidSchema=y.isDiscriminatorForm=y.isValuesForm=y.isPropertiesForm=y.isElementsForm=y.isEnumForm=y.isTypeForm=y.isRefForm=y.isEmptyForm=void 0;function zt(e){let{definitions:r,nullable:t,metadata:n}=e,i=Ke(e,["definitions","nullable","metadata"]);return Object.keys(i).length===0}y.isEmptyForm=zt;function Ze(e){return"ref"in e}y.isRefForm=Ze;function Wt(e){return"type"in e}y.isTypeForm=Wt;function Xe(e){return"enum"in e}y.isEnumForm=Xe;function Qe(e){return"elements"in e}y.isElementsForm=Qe;function Ae(e){return"properties"in e||"optionalProperties"in e}y.isPropertiesForm=Ae;function et(e){return"values"in e}y.isValuesForm=et;function tt(e){return"discriminator"in e}y.isDiscriminatorForm=tt;function $(e,r){if(r===void 0&&(r=e),e.definitions!==void 0){if(r!==e)return!1;for(let t of Object.values(e.definitions))if(!$(t,r))return!1}if(Ze(e)&&!(e.ref in(r.definitions||{}))||Xe(e)&&(e.enum.length===0||e.enum.length!==new Set(e.enum).size))return!1;if(Qe(e))return $(e.elements,r);if(Ae(e)){for(let t of Object.values(e.properties||{}))if(!$(t,r))return!1;for(let t of Object.values(e.optionalProperties||{}))if(!$(t,r))return!1;for(let t of Object.keys(e.properties||{}))if(t in(e.optionalProperties||{}))return!1}if(et(e))return $(e.values,r);if(tt(e)){for(let t of Object.values(e.mapping))if(!$(t,r)||!Ae(t)||t.nullable||e.discriminator in(t.properties||{})||e.discriminator in(t.optionalProperties||{}))return!1}return!0}y.isValidSchema=$;var Yt=[[!1,!1,!1,!1,!1,!1,!1,!1,!1,!1],[!0,!1,!1,!1,!1,!1,!1,!1,!1,!1],[!1,!0,!1,!1,!1,!1,!1,!1,!1,!1],[!1,!1,!0,!1,!1,!1,!1,!1,!1,!1],[!1,!1,!1,!0,!1,!1,!1,!1,!1,!1],[!1,!1,!1,!1,!0,!1,!1,!1,!1,!1],[!1,!1,!1,!1,!1,!0,!1,!1,!1,!1],[!1,!1,!1,!1,!0,!0,!1,!1,!1,!1],[!1,!1,!1,!1,!0,!1,!0,!1,!1,!1],[!1,!1,!1,!1,!1,!0,!0,!1,!1,!1],[!1,!1,!1,!1,!0,!0,!0,!1,!1,!1],[!1,!1,!1,!1,!1,!1,!1,!0,!1,!1],[!1,!1,!1,!1,!1,!1,!1,!1,!0,!0]],Kt=["boolean","float32","float64","int8","uint8","int16","uint16","int32","uint32","string","timestamp"];function H(e){if(typeof e!="object"||Array.isArray(e)||e===null)return!1;let r=e,{definitions:t=void 0,nullable:n=void 0,metadata:i=void 0,ref:o=void 0,type:a=void 0,enum:f=void 0,elements:s=void 0,properties:c=void 0,optionalProperties:l=void 0,additionalProperties:m=void 0,values:g=void 0,discriminator:p=void 0,mapping:h=void 0}=r,U=Ke(r,["definitions","nullable","metadata","ref","type","enum","elements","properties","optionalProperties","additionalProperties","values","discriminator","mapping"]),k=[o!==void 0,a!==void 0,f!==void 0,s!==void 0,c!==void 0,l!==void 0,m!==void 0,g!==void 0,p!==void 0,h!==void 0],C=!1;for(let b of Yt)C=C||b.every((te,Y)=>te===k[Y]);if(!C)return!1;if(t!==void 0){if(typeof t!="object"||Array.isArray(t)||t===null)return!1;for(let b of Object.values(t))if(!H(b))return!1}if(n!==void 0&&typeof n!="boolean"||i!==void 0&&(typeof i!="object"||Array.isArray(i)||i===null)||o!==void 0&&typeof o!="string"||a!==void 0&&(typeof a!="string"||!Kt.includes(a))||f!==void 0&&(!Array.isArray(f)||!f.every(b=>typeof b=="string"))||s!==void 0&&!H(s))return!1;if(c!==void 0){if(typeof c!="object"||Array.isArray(c)||c===null)return!1;for(let b of Object.values(c))if(!H(b))return!1}if(l!==void 0){if(typeof l!="object"||Array.isArray(l)||l===null)return!1;for(let b of Object.values(l))if(!H(b))return!1}if(m!==void 0&&typeof m!="boolean"||g!==void 0&&!H(g)||p!==void 0&&typeof p!="string")return!1;if(h!==void 0){if(typeof h!="object"||Array.isArray(h)||h===null)return!1;for(let b of Object.values(h))if(!H(b))return!1}return Object.keys(U).length===0}y.isSchema=H});var rt=j(Se=>{"use strict";Object.defineProperty(Se,"__esModule",{value:!0});var Zt=/^(\d{4})-(\d{2})-(\d{2})[tT](\d{2}):(\d{2}):(\d{2})(\.\d+)?([zZ]|((\+|-)(\d{2}):(\d{2})))$/;function Xt(e){let r=e.match(Zt);if(r===null)return!1;let t=parseInt(r[1],10),n=parseInt(r[2],10),i=parseInt(r[3],10),o=parseInt(r[4],10),a=parseInt(r[5],10),f=parseInt(r[6],10);return!(n>12||i>Qt(t,n)||o>23||a>59||f>60)}Se.default=Xt;function Qt(e,r){return r===2?er(e)?29:28:tr[r]}function er(e){return e%4===0&&(e%100!==0||e%400===0)}var tr=[0,31,0,31,30,31,30,31,31,30,31,30,31]});var nt=j(_=>{"use strict";var rr=_&&_.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(_,"__esModule",{value:!0});_.validate=_.MaxDepthExceededError=void 0;var nr=rr(rt()),J=Oe(),ce=class extends Error{};_.MaxDepthExceededError=ce;var de=class extends Error{};function ir(e,r,t){let n={errors:[],instanceTokens:[],schemaTokens:[[]],root:e,config:t||{maxDepth:0,maxErrors:0}};try{G(n,e,r)}catch(i){if(!(i instanceof de))throw i}return n.errors}_.validate=ir;function G(e,r,t,n){if(!(r.nullable&&t===null)){if(J.isRefForm(r)){if(e.schemaTokens.length===e.config.maxDepth)throw new ce;e.schemaTokens.push(["definitions",r.ref]),G(e,e.root.definitions[r.ref],t),e.schemaTokens.pop()}else if(J.isTypeForm(r)){switch(T(e,"type"),r.type){case"boolean":typeof t!="boolean"&&A(e);break;case"float32":case"float64":typeof t!="number"&&A(e);break;case"int8":z(e,t,-128,127);break;case"uint8":z(e,t,0,255);break;case"int16":z(e,t,-32768,32767);break;case"uint16":z(e,t,0,65535);break;case"int32":z(e,t,-2147483648,2147483647);break;case"uint32":z(e,t,0,4294967295);break;case"string":typeof t!="string"&&A(e);break;case"timestamp":typeof t!="string"?A(e):nr.default(t)||A(e);break}O(e)}else if(J.isEnumForm(r))T(e,"enum"),(typeof t!="string"||!r.enum.includes(t))&&A(e),O(e);else if(J.isElementsForm(r)){if(T(e,"elements"),Array.isArray(t))for(let[i,o]of t.entries())q(e,i.toString()),G(e,r.elements,o),V(e);else A(e);O(e)}else if(J.isPropertiesForm(r))if(typeof t=="object"&&t!==null&&!Array.isArray(t)){if(r.properties!==void 0){T(e,"properties");for(let[i,o]of Object.entries(r.properties))T(e,i),t.hasOwnProperty(i)?(q(e,i),G(e,o,t[i]),V(e)):A(e),O(e);O(e)}if(r.optionalProperties!==void 0){T(e,"optionalProperties");for(let[i,o]of Object.entries(r.optionalProperties))T(e,i),t.hasOwnProperty(i)&&(q(e,i),G(e,o,t[i]),V(e)),O(e);O(e)}if(r.additionalProperties!==!0)for(let i of Object.keys(t)){let o=r.properties&&i in r.properties,a=r.optionalProperties&&i in r.optionalProperties;!o&&!a&&i!==n&&(q(e,i),A(e),V(e))}}else r.properties!==void 0?T(e,"properties"):T(e,"optionalProperties"),A(e),O(e);else if(J.isValuesForm(r)){if(T(e,"values"),typeof t=="object"&&t!==null&&!Array.isArray(t))for(let[i,o]of Object.entries(t))q(e,i),G(e,r.values,o),V(e);else A(e);O(e)}else if(J.isDiscriminatorForm(r))if(typeof t=="object"&&t!==null&&!Array.isArray(t))if(t.hasOwnProperty(r.discriminator)){let i=t[r.discriminator];typeof i=="string"?i in r.mapping?(T(e,"mapping"),T(e,i),G(e,r.mapping[i],t,r.discriminator),O(e),O(e)):(T(e,"mapping"),q(e,r.discriminator),A(e),V(e),O(e)):(T(e,"discriminator"),q(e,r.discriminator),A(e),V(e),O(e))}else T(e,"discriminator"),A(e),O(e);else T(e,"discriminator"),A(e),O(e)}}function z(e,r,t,n){(typeof r!="number"||!Number.isInteger(r)||r<t||r>n)&&A(e)}function q(e,r){e.instanceTokens.push(r)}function V(e){e.instanceTokens.pop()}function T(e,r){e.schemaTokens[e.schemaTokens.length-1].push(r)}function O(e){e.schemaTokens[e.schemaTokens.length-1].pop()}function A(e){if(e.errors.push({instancePath:[...e.instanceTokens],schemaPath:[...e.schemaTokens[e.schemaTokens.length-1]]}),e.errors.length===e.config.maxErrors)throw new de}});var ot=j(N=>{"use strict";var or=N&&N.__createBinding||(Object.create?function(e,r,t,n){n===void 0&&(n=t),Object.defineProperty(e,n,{enumerable:!0,get:function(){return r[t]}})}:function(e,r,t,n){n===void 0&&(n=t),e[n]=r[t]}),it=N&&N.__exportStar||function(e,r){for(var t in e)t!=="default"&&!r.hasOwnProperty(t)&&or(r,e,t)};Object.defineProperty(N,"__esModule",{value:!0});it(Oe(),N);it(nt(),N)});var ut=me(Be()),ct=me(Je());var fe,jt=new Uint8Array(16);function le(){if(!fe&&(fe=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!fe))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return fe(jt)}var qe=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;function Bt(e){return typeof e=="string"&&qe.test(e)}var K=Bt;var w=[];for(let e=0;e<256;++e)w.push((e+256).toString(16).slice(1));function Z(e,r=0){return(w[e[r+0]]+w[e[r+1]]+w[e[r+2]]+w[e[r+3]]+"-"+w[e[r+4]]+w[e[r+5]]+"-"+w[e[r+6]]+w[e[r+7]]+"-"+w[e[r+8]]+w[e[r+9]]+"-"+w[e[r+10]]+w[e[r+11]]+w[e[r+12]]+w[e[r+13]]+w[e[r+14]]+w[e[r+15]]).toLowerCase()}function It(e){if(!K(e))throw TypeError("Invalid UUID");let r,t=new Uint8Array(16);return t[0]=(r=parseInt(e.slice(0,8),16))>>>24,t[1]=r>>>16&255,t[2]=r>>>8&255,t[3]=r&255,t[4]=(r=parseInt(e.slice(9,13),16))>>>8,t[5]=r&255,t[6]=(r=parseInt(e.slice(14,18),16))>>>8,t[7]=r&255,t[8]=(r=parseInt(e.slice(19,23),16))>>>8,t[9]=r&255,t[10]=(r=parseInt(e.slice(24,36),16))/1099511627776&255,t[11]=r/4294967296&255,t[12]=r>>>24&255,t[13]=r>>>16&255,t[14]=r>>>8&255,t[15]=r&255,t}var xe=It;function Rt(e){e=unescape(encodeURIComponent(e));let r=[];for(let t=0;t<e.length;++t)r.push(e.charCodeAt(t));return r}var _t="6ba7b810-9dad-11d1-80b4-00c04fd430c8",Nt="6ba7b811-9dad-11d1-80b4-00c04fd430c8";function X(e,r,t){function n(i,o,a,f){var s;if(typeof i=="string"&&(i=Rt(i)),typeof o=="string"&&(o=xe(o)),((s=o)===null||s===void 0?void 0:s.length)!==16)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");let c=new Uint8Array(16+i.length);if(c.set(o),c.set(i,o.length),c=t(c),c[6]=c[6]&15|r,c[8]=c[8]&63|128,a){f=f||0;for(let l=0;l<16;++l)a[f+l]=c[l];return a}return Z(c)}try{n.name=e}catch{}return n.DNS=_t,n.URL=Nt,n}function Ut(e){if(typeof e=="string"){let r=unescape(encodeURIComponent(e));e=new Uint8Array(r.length);for(let t=0;t<r.length;++t)e[t]=r.charCodeAt(t)}return Lt(Dt($t(e),e.length*8))}function Lt(e){let r=[],t=e.length*32,n="0123456789abcdef";for(let i=0;i<t;i+=8){let o=e[i>>5]>>>i%32&255,a=parseInt(n.charAt(o>>>4&15)+n.charAt(o&15),16);r.push(a)}return r}function Ve(e){return(e+64>>>9<<4)+14+1}function Dt(e,r){e[r>>5]|=128<<r%32,e[Ve(r)-1]=r;let t=1732584193,n=-271733879,i=-1732584194,o=271733878;for(let a=0;a<e.length;a+=16){let f=t,s=n,c=i,l=o;t=v(t,n,i,o,e[a],7,-680876936),o=v(o,t,n,i,e[a+1],12,-389564586),i=v(i,o,t,n,e[a+2],17,606105819),n=v(n,i,o,t,e[a+3],22,-1044525330),t=v(t,n,i,o,e[a+4],7,-176418897),o=v(o,t,n,i,e[a+5],12,1200080426),i=v(i,o,t,n,e[a+6],17,-1473231341),n=v(n,i,o,t,e[a+7],22,-45705983),t=v(t,n,i,o,e[a+8],7,1770035416),o=v(o,t,n,i,e[a+9],12,-1958414417),i=v(i,o,t,n,e[a+10],17,-42063),n=v(n,i,o,t,e[a+11],22,-1990404162),t=v(t,n,i,o,e[a+12],7,1804603682),o=v(o,t,n,i,e[a+13],12,-40341101),i=v(i,o,t,n,e[a+14],17,-1502002290),n=v(n,i,o,t,e[a+15],22,1236535329),t=x(t,n,i,o,e[a+1],5,-165796510),o=x(o,t,n,i,e[a+6],9,-1069501632),i=x(i,o,t,n,e[a+11],14,643717713),n=x(n,i,o,t,e[a],20,-373897302),t=x(t,n,i,o,e[a+5],5,-701558691),o=x(o,t,n,i,e[a+10],9,38016083),i=x(i,o,t,n,e[a+15],14,-660478335),n=x(n,i,o,t,e[a+4],20,-405537848),t=x(t,n,i,o,e[a+9],5,568446438),o=x(o,t,n,i,e[a+14],9,-1019803690),i=x(i,o,t,n,e[a+3],14,-187363961),n=x(n,i,o,t,e[a+8],20,1163531501),t=x(t,n,i,o,e[a+13],5,-1444681467),o=x(o,t,n,i,e[a+2],9,-51403784),i=x(i,o,t,n,e[a+7],14,1735328473),n=x(n,i,o,t,e[a+12],20,-1926607734),t=E(t,n,i,o,e[a+5],4,-378558),o=E(o,t,n,i,e[a+8],11,-2022574463),i=E(i,o,t,n,e[a+11],16,1839030562),n=E(n,i,o,t,e[a+14],23,-35309556),t=E(t,n,i,o,e[a+1],4,-1530992060),o=E(o,t,n,i,e[a+4],11,1272893353),i=E(i,o,t,n,e[a+7],16,-155497632),n=E(n,i,o,t,e[a+10],23,-1094730640),t=E(t,n,i,o,e[a+13],4,681279174),o=E(o,t,n,i,e[a],11,-358537222),i=E(i,o,t,n,e[a+3],16,-722521979),n=E(n,i,o,t,e[a+6],23,76029189),t=E(t,n,i,o,e[a+9],4,-640364487),o=E(o,t,n,i,e[a+12],11,-421815835),i=E(i,o,t,n,e[a+15],16,530742520),n=E(n,i,o,t,e[a+2],23,-995338651),t=P(t,n,i,o,e[a],6,-198630844),o=P(o,t,n,i,e[a+7],10,1126891415),i=P(i,o,t,n,e[a+14],15,-1416354905),n=P(n,i,o,t,e[a+5],21,-57434055),t=P(t,n,i,o,e[a+12],6,1700485571),o=P(o,t,n,i,e[a+3],10,-1894986606),i=P(i,o,t,n,e[a+10],15,-1051523),n=P(n,i,o,t,e[a+1],21,-2054922799),t=P(t,n,i,o,e[a+8],6,1873313359),o=P(o,t,n,i,e[a+15],10,-30611744),i=P(i,o,t,n,e[a+6],15,-1560198380),n=P(n,i,o,t,e[a+13],21,1309151649),t=P(t,n,i,o,e[a+4],6,-145523070),o=P(o,t,n,i,e[a+11],10,-1120210379),i=P(i,o,t,n,e[a+2],15,718787259),n=P(n,i,o,t,e[a+9],21,-343485551),t=R(t,f),n=R(n,s),i=R(i,c),o=R(o,l)}return[t,n,i,o]}function $t(e){if(e.length===0)return[];let r=e.length*8,t=new Uint32Array(Ve(r));for(let n=0;n<r;n+=8)t[n>>5]|=(e[n/8]&255)<<n%32;return t}function R(e,r){let t=(e&65535)+(r&65535);return(e>>16)+(r>>16)+(t>>16)<<16|t&65535}function Ht(e,r){return e<<r|e>>>32-r}function ue(e,r,t,n,i,o){return R(Ht(R(R(r,e),R(n,o)),i),t)}function v(e,r,t,n,i,o,a){return ue(r&t|~r&n,e,r,i,o,a)}function x(e,r,t,n,i,o,a){return ue(r&n|t&~n,e,r,i,o,a)}function E(e,r,t,n,i,o,a){return ue(r^t^n,e,r,i,o,a)}function P(e,r,t,n,i,o,a){return ue(t^(r|~n),e,r,i,o,a)}var Ge=Ut;var $r=X("v3",48,Ge);var Jt=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Ee={randomUUID:Jt};function qt(e,r,t){if(Ee.randomUUID&&!r&&!e)return Ee.randomUUID();e=e||{};let n=e.random||(e.rng||le)();if(n[6]=n[6]&15|64,n[8]=n[8]&63|128,r){t=t||0;for(let i=0;i<16;++i)r[t+i]=n[i];return r}return Z(n)}var Q=qt;function Vt(e,r,t,n){switch(e){case 0:return r&t^~r&n;case 1:return r^t^n;case 2:return r&t^r&n^t&n;case 3:return r^t^n}}function Pe(e,r){return e<<r|e>>>32-r}function Gt(e){let r=[1518500249,1859775393,2400959708,3395469782],t=[1732584193,4023233417,2562383102,271733878,3285377520];if(typeof e=="string"){let a=unescape(encodeURIComponent(e));e=[];for(let f=0;f<a.length;++f)e.push(a.charCodeAt(f))}else Array.isArray(e)||(e=Array.prototype.slice.call(e));e.push(128);let n=e.length/4+2,i=Math.ceil(n/16),o=new Array(i);for(let a=0;a<i;++a){let f=new Uint32Array(16);for(let s=0;s<16;++s)f[s]=e[a*64+s*4]<<24|e[a*64+s*4+1]<<16|e[a*64+s*4+2]<<8|e[a*64+s*4+3];o[a]=f}o[i-1][14]=(e.length-1)*8/Math.pow(2,32),o[i-1][14]=Math.floor(o[i-1][14]),o[i-1][15]=(e.length-1)*8&4294967295;for(let a=0;a<i;++a){let f=new Uint32Array(80);for(let p=0;p<16;++p)f[p]=o[a][p];for(let p=16;p<80;++p)f[p]=Pe(f[p-3]^f[p-8]^f[p-14]^f[p-16],1);let s=t[0],c=t[1],l=t[2],m=t[3],g=t[4];for(let p=0;p<80;++p){let h=Math.floor(p/20),U=Pe(s,5)+Vt(h,c,l,m)+g+r[h]+f[p]>>>0;g=m,m=l,l=Pe(c,30)>>>0,c=s,s=U}t[0]=t[0]+s>>>0,t[1]=t[1]+c>>>0,t[2]=t[2]+l>>>0,t[3]=t[3]+m>>>0,t[4]=t[4]+g>>>0}return[t[0]>>24&255,t[0]>>16&255,t[0]>>8&255,t[0]&255,t[1]>>24&255,t[1]>>16&255,t[1]>>8&255,t[1]&255,t[2]>>24&255,t[2]>>16&255,t[2]>>8&255,t[2]&255,t[3]>>24&255,t[3]>>16&255,t[3]>>8&255,t[3]&255,t[4]>>24&255,t[4]>>16&255,t[4]>>8&255,t[4]&255]}var ze=Gt;var Zr=X("v5",80,ze);function Te(e){return[...new Uint8Array(e)].map(r=>r.toString(16).padStart(2,"0")).join("")}function We(e){return new Uint8Array((e.match(/../g)??[]).map(r=>parseInt(r,16)))}function Ye(e){let r=0;for(let i of e)r+=i.length;let t=new Uint8Array(r),n=0;for(let i of e)t.set(i,n),n+=i.length;return t}var at=me(ot());function ee(e,r){if((0,at.validate)(e,r).length)throw new Error(`couldn't validate schema: ${JSON.stringify(r)} didn't match schema ${JSON.stringify(e)}`)}var st="3",dt="https://webapp-prod.cloud.remarkable.engineering",ar="https://internal.cloud.remarkable.com",ft="x-goog-generation",sr="x-goog-if-generation-match",fr="x-goog-content-length-range",Mn=["Ballpoint","Ballpointv2","Brush","Calligraphy","ClearPage","EraseSection","Eraser","Fineliner","Finelinerv2","Highlighter","Highlighterv2","Marker","Markerv2","Paintbrush","Paintbrushv2","Pencilv2","SharpPencil","SharpPencilv2","SolidPen","ZoomTool"],Cn=["Maison Neue","EB Garamond","Noto Sans","Noto Serif","Noto Mono","Noto Sans UI"],lr={xs:.7,sm:.8,md:1,lg:1.2,xl:1.5,xx:2},ur={sm:50,md:125,rr:180,lg:200},cr={df:-1,md:100,lg:150,xl:200},dr={properties:{docID:{type:"string"},hash:{type:"string"}}},pr={properties:{relative_path:{type:"string"},url:{type:"string"},expires:{type:"timestamp"},method:{enum:["POST","GET","PUT","DELETE"]}},optionalProperties:{maxuploadsize_bytes:{type:"float64"}}},pe={visibleName:{type:"string"},lastModified:{type:"string"}},ye={version:{type:"int32"},pinned:{type:"boolean"},synced:{type:"boolean"},modified:{type:"boolean"},deleted:{type:"boolean"},metadatamodified:{type:"boolean"},parent:{type:"string"}},yr={discriminator:"type",mapping:{CollectionType:{properties:pe,optionalProperties:ye},DocumentType:{properties:pe,optionalProperties:{...ye,lastOpened:{type:"string"},lastOpenedPage:{type:"int32"}}}}},lt={id:{type:"string"},hash:{type:"string"}},mr={discriminator:"type",mapping:{CollectionType:{properties:{...pe,...lt},optionalProperties:ye},DocumentType:{properties:{...pe,...lt,fileType:{enum:["notebook","epub","pdf",""]}},optionalProperties:{...ye,lastOpened:{type:"string"},lastOpenedPage:{type:"int32"}}}}},W=class extends Error{constructor(t,n,i){super(i);this.status=t,this.statusText=n}},ke=class extends Error{constructor(){super("Generation preconditions failed. This means the current state is out of date with the cloud and needs to be re-synced.")}};async function Fn(e,{deviceDesc:r="browser-chrome",uuid:t=Q(),authHost:n=dt,fetch:i=globalThis.fetch}={}){if(e.length!==8)throw new Error(`code should be length 8, but was ${e.length}`);let o=await i(`${n}/token/json/2/device/new`,{method:"POST",headers:{Authorization:"Bearer"},body:JSON.stringify({code:e,deviceDesc:r,deviceID:t})});if(o.ok)return await o.text();throw new W(o.status,o.statusText,"couldn't register api")}function hr({hash:e,type:r,documentId:t,subfiles:n,size:i}){return`${e}:${r}:${t}:${n}:${i}
|
|
10
|
+
`}function gr(e){let[r,t,n,i,o]=e.split(":");if(r===void 0||t===void 0||n===void 0||i===void 0||o===void 0)throw new Error(`entries line didn't contain five fields: '${e}'`);if(t==="80000000")return{hash:r,type:t,documentId:n,subfiles:parseInt(i),size:BigInt(o)};if(t==="0"){if(i!=="0")throw new Error(`file type entry had nonzero number of subfiles: ${i}`);return{hash:r,type:t,documentId:n,subfiles:0,size:BigInt(o)}}else throw new Error(`entries line contained invalid type: ${t}`)}var Me=class{#l;#s;#f;#r;#n;#e=new Map;#t=null;constructor(r,t,n,i,o,a){this.#l=r,this.#s=t,this.#f=n,this.#r=i,this.#n=o;for(let[f,s]of a)this.#e.set(f,Promise.resolve(s))}async#i(r,{body:t,method:n="POST",headers:i={}}){let o=await this.#s(r,{method:n,headers:{Authorization:`Bearer ${this.#l}`,...i},body:t});if(o.ok)return o;{let a=await o.text();throw new W(o.status,o.statusText,`failed reMarkable request: ${a}`)}}async#o({url:r,method:t,maxuploadsize_bytes:n},i,o={}){let a=n?{...o,[fr]:`0,${n}`}:o,f=await this.#s(r,{method:t,body:i,headers:a});if(f.ok)return f;{let s=await f.text();throw new W(f.status,f.statusText,s)}}async#a(r,t,n){let i=t===void 0?"downloads":"uploads",o=n&&t!==null&&t!==void 0?`{ "http_method": "PUT", "relative_path": "${r}", "root_schema": "${n}", "generation": ${t} }`:JSON.stringify({http_method:"GET",relative_path:r}),f=await(await this.#i(`${this.#r}/sync/v2/signed-urls/${i}`,{body:o})).text(),s=JSON.parse(f);return ee(pr,s),s}async getRootHash({cache:r=!0}={}){if(r)for(;this.#t;)try{let[o,a]=await this.#t;return[o,a]}catch{}let t=(async()=>{try{let o=await this.#a("root"),a=await this.#o(o),f=a.headers.get(ft);if(f)return[await a.text(),BigInt(f)];throw new Error("no generation header in root hash")}catch(o){throw this.#t=null,o}})();this.#t=t;let[n,i]=await t;return[n,i]}async putRootHash(r,t){let n=await this.#a("root",t,r),i;try{i=await this.#o(n,r,{[sr]:`${t}`})}catch(f){throw f instanceof W&&f.status===412?(this.#t=null,new ke):f}let o=i.headers.get(ft);if(!o)throw new Error("no generation header in root hash");let a=BigInt(o);return this.#t=Promise.resolve([r,a]),a}async#u(r){let t=this.#e.get(r);for(;t;)try{let i=await t;if(i)return i;t=void 0}catch{t=this.#e.get(r)}let n=(async()=>{let i=await this.#a(r);return await(await this.#o(i)).arrayBuffer()})();return this.#e.set(r,n.then(i=>i.byteLength<this.#n?i:null,i=>{throw this.#e.delete(r),i})),await n}async getBuffer(r){let t=await this.#u(r);return t.byteLength<this.#n?t.slice(0):t}async getText(r){let t=await this.#u(r);return new TextDecoder().decode(t)}async getJson(r){let t=await this.getText(r);return JSON.parse(t)}async getMetadata(r){let t=await this.getJson(r);return ee(yr,t),t}async getEntries(r){if(r===void 0){let[o]=await this.getRootHash({cache:!0});r=o}let t=await this.getText(r),[n,...i]=t.slice(0,-1).split(`
|
|
11
|
+
`);if(n!==st)throw new Error(`got unexpected schema version: ${n}`);return i.map(gr)}async#c(r,t){let n=this.#e.get(r);if(n)try{await n;return}catch{}let i=(async()=>{try{let o=await this.#a(r,null);return await this.#o(o,t),t.byteLength<this.#n?t:null}catch(o){throw this.#e.delete(r),o}})();this.#e.set(r,i),await i}async putEntries(r,t){let n=new TextEncoder;t.sort((l,m)=>l.documentId.localeCompare(m.documentId));let i=Ye(t.map(l=>We(l.hash))),o=await this.#f.digest("SHA-256",i),a=Te(o),f=t.map(hr).join(""),s=`${st}
|
|
12
|
+
${f}`,c=n.encode(s);return await this.#c(a,c),{hash:a,type:"80000000",documentId:r,subfiles:t.length,size:0n}}async putBuffer(r,t){let n=await this.#f.digest("SHA-256",t),i=Te(n);return await this.#c(i,t),{hash:i,type:"0",documentId:r,subfiles:0,size:BigInt(t.byteLength)}}async putText(r,t){let n=new TextEncoder;return await this.putBuffer(r,n.encode(t))}async putJson(r,t){return await this.putText(r,(0,ct.default)(t))}async putMetadata(r,t){return await this.putJson(`${r}.metadata`,t)}async putCollection(r,t=""){let n=Q(),i=`${new Date().valueOf()}`,o=[],a={type:"CollectionType",visibleName:r,version:0,parent:t,synced:!0,lastModified:i};o.push(this.putMetadata(n,a)),o.push(this.putText(`${n}.content`,"{}"));let f=await Promise.all(o);return await this.putEntries(n,f)}async#d(r,t,n,i,o){if(o.fileType!==n)throw new Error(`internal error: fileTypes don't match: ${n}, ${o.fileType}`);let a=Q(),f=`${new Date().valueOf()}`,s=[];s.push(this.putBuffer(`${a}.${n}`,t));let c={type:"DocumentType",visibleName:r,version:0,parent:i,synced:!0,lastModified:f};s.push(this.putMetadata(a,c)),s.push(this.putText(`${a}.content`,JSON.stringify(o)));let l=await Promise.all(s);return await this.putEntries(a,l)}async putEpub(r,t,{parent:n="",margins:i=125,orientation:o,textAlignment:a,textScale:f=1,lineHeight:s=-1,fontName:c="",cover:l="visited",lastTool:m}={}){let g={dummyDocument:!1,extraMetadata:{LastTool:m},fileType:"epub",pageCount:0,lastOpenedPage:0,lineHeight:typeof s=="string"?cr[s]:s,margins:typeof i=="string"?ur[i]:i,textScale:typeof f=="string"?lr[f]:f,pages:[],coverPageNumber:l==="first"?0:-1,formatVersion:1,orientation:o,textAlignment:a,fontName:c};return await this.#d(r,t,"epub",n,g)}async putPdf(r,t,{parent:n="",orientation:i,cover:o="first",lastTool:a}={}){let f={dummyDocument:!1,extraMetadata:{LastTool:a},fileType:"pdf",pageCount:0,lastOpenedPage:0,lineHeight:-1,margins:125,textScale:1,pages:[],coverPageNumber:o==="first"?0:-1,formatVersion:1,orientation:i};return await this.#d(r,t,"pdf",n,f)}async syncComplete(r){let t=`{ "generation": ${r} }`;await this.#i(`${this.#r}/sync/v2/sync-complete`,{body:t})}async#p(r,t,n){let{hash:i}=await this.putEntries("",t),o=await this.putRootHash(i,r);if(n)try{return await this.syncComplete(o),!0}catch{return!1}else return!1}async create(r,{cache:t=!0,sync:n=!0}={}){let[i,o]=await this.getRootHash({cache:t}),a=await this.getEntries(i);return a.push(r),await this.#p(o,a,n)}async move(r,t,{cache:n=!0,sync:i=!0}={}){let[o,a]=await this.getRootHash({cache:n}),f=await this.getEntries(o);if(!(!t||t==="trash")){let k=f.find(Y=>Y.documentId===t);if(k){if(k.type!=="80000000")throw new Error(`destination id was a raw file: ${t}`)}else throw new Error(`destination id not found: ${t}`);let C=await this.getEntries(k.hash),[b]=C.filter(Y=>Y.documentId===`${t}.metadata`);if(!b)throw new Error(`destination id didn't have metadata: ${t}`);if((await this.getMetadata(b.hash)).type!=="CollectionType")throw new Error(`destination id wasn't a collection: ${t}`)}let s=f.findIndex(k=>k.documentId===r);if(s===-1)throw new Error(`document not found: ${r}`);let[c]=f.splice(s,1);if(c.type!=="80000000")throw new Error(`document was a raw file: ${r}`);let l=await this.getEntries(c.hash),m=l.findIndex(k=>k.documentId===`${r}.metadata`);if(m===-1)throw new Error(`document didn't have metadata: ${r}`);let[g]=l.splice(m,1),p=await this.getMetadata(g.hash);p.parent=t;let h=await this.putMetadata(r,p);l.push(h);let U=await this.putEntries(r,l);return f.push(U),await this.#p(a,f,i)}async getEntriesMetadata(){let t=await(await this.#i(`${this.#r}/doc/v2/files`,{method:"GET",headers:{"rm-source":"RoR-Browser"}})).text(),n=JSON.parse(t);return ee({elements:mr},n),n}async#y(r,t,n){let o=new TextEncoder().encode(JSON.stringify({file_name:r})),f=await(await this.#i(`${this.#r}/doc/v2/files`,{body:t,headers:{"content-type":n,"rm-meta":(0,ut.fromByteArray)(o),"rm-source":"RoR-Browser"}})).text(),s=JSON.parse(f);return ee(dr,s),s}async uploadEpub(r,t){return await this.#y(r,t,"application/epub+zip")}async uploadPdf(r,t){return await this.#y(r,t,"application/pdf")}async getCache(){let r=[];for(let[i,o]of this.#e)r.push(o.then(a=>[i,a],()=>[i,null]));let t=await Promise.all(r),n=new Map;for(let[i,o]of t)o&&n.set(i,o);return n}};async function jn(e,{fetch:r=globalThis.fetch,subtle:t=globalThis.crypto?.subtle,authHost:n=dt,syncHost:i=ar,cacheLimitBytes:o=1048576,initCache:a=[]}={}){if(!t)throw new Error("subtle was missing, try specifying it manually");let f=await r(`${n}/token/json/2/user/new`,{method:"POST",headers:{Authorization:`Bearer ${e}`}});if(!f.ok)throw new Error(`couldn't fetch auth token: ${f.statusText}`);let s=await f.text();return new Me(s,r,t,i,o,a)}export{ke as GenerationError,W as ResponseError,Cn as builtinFontNames,cr as builtinLineHeights,ur as builtinMargins,lr as builtinTextScales,Mn as builtinTools,hr as formatEntry,gr as parseEntry,Fn as register,jn as remarkable};
|