rmapi-js 0.0.1
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/LICENSE +21 -0
- package/README.md +110 -0
- package/bundle/rmapi-js.cjs.min.js +4 -0
- package/bundle/rmapi-js.esm.min.js +4 -0
- package/bundle/rmapi-js.iife.min.js +4 -0
- package/bundle/rmapi.cjs.min.js +4 -0
- package/bundle/rmapi.esm.min.js +4 -0
- package/bundle/rmapi.iife.min.js +4 -0
- package/dist/index.d.ts +404 -0
- package/dist/index.js +535 -0
- package/dist/utils.d.ts +6 -0
- package/dist/utils.js +24 -0
- package/dist/validate.d.ts +3 -0
- package/dist/validate.js +8 -0
- package/package.json +141 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Erik Brinkman
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
rmapi-js
|
|
2
|
+
========
|
|
3
|
+
[](https://github.com/erikbrinkman/rmapi-js/actions/workflows/node.js.yml)
|
|
4
|
+
[](https://erikbrinkman.github.io/rmapi-js/)
|
|
5
|
+
[](https://www.npmjs.com/package/rmapi-js)
|
|
6
|
+
[](LICENSE)
|
|
7
|
+
|
|
8
|
+
JavaScript implementation of the reMarkable 1.5 api. This implementation is
|
|
9
|
+
built around web standards for fetch and crypto, but can easily be patched to
|
|
10
|
+
work for node. At the current time it's only partially complete, but has the
|
|
11
|
+
backbone to flush out more.
|
|
12
|
+
|
|
13
|
+
This implementation is based off of [`rmapi`](https://github.com/juruen/rmapi),
|
|
14
|
+
but aims to be a little simpler. Currently this does no direct handling of the
|
|
15
|
+
document tree or syncing efficiently with the cloud, although that support can
|
|
16
|
+
be build on top of this library. To make those calls efficient, it will be
|
|
17
|
+
helpful to supply a custom cache.
|
|
18
|
+
|
|
19
|
+
API
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
Before using this API it's necessary to have some rudimentary understand of how
|
|
23
|
+
the API works.
|
|
24
|
+
|
|
25
|
+
All data is stored via its sha256 hash. This includes raw files and
|
|
26
|
+
"collections", which have a special format listing all of their `Entry`s by
|
|
27
|
+
hash and id. Each document or folder is a collection of it's constituant files,
|
|
28
|
+
which inclue metadata about the object. All documents and folders are in the
|
|
29
|
+
root collection, and there's a versioned hash which indicates the hash of the
|
|
30
|
+
root collection. The root hash version is it's "generation".
|
|
31
|
+
|
|
32
|
+
Usage
|
|
33
|
+
-----
|
|
34
|
+
|
|
35
|
+
To explore files in the cloud, you need to first register your api and persist
|
|
36
|
+
the token. Then you can use `getEntries` to explore entries of different file
|
|
37
|
+
collections.
|
|
38
|
+
```ts
|
|
39
|
+
import { register, remarkable } from "rmapi-js";
|
|
40
|
+
|
|
41
|
+
const code = "..." // eight letter code from https://my.remarkable.com/device/desktop/connect
|
|
42
|
+
const token = await register(code)
|
|
43
|
+
// persist token
|
|
44
|
+
const api = await remarkable(token);
|
|
45
|
+
const [root] = await api.getRootHash();
|
|
46
|
+
const fileEntries = await api.getEntries(root);
|
|
47
|
+
for (const entry of fileEntries) {
|
|
48
|
+
const children = await api.getEntries(entry.hash);
|
|
49
|
+
for (const { hash, documentId } of children) {
|
|
50
|
+
if (documentId.endsWith(".metadata")) {
|
|
51
|
+
const meta = api.getMetadata(hash);
|
|
52
|
+
// get metadata for entry
|
|
53
|
+
console.log(meta);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
To upload an epub, simply call upload with the appropriate name and buffer.
|
|
60
|
+
```ts
|
|
61
|
+
import { remarkable } from "rmapi-js";
|
|
62
|
+
|
|
63
|
+
const api = await remarkable(...);
|
|
64
|
+
await api.putEpub("document name", epubBuffer);
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Node
|
|
68
|
+
|
|
69
|
+
This uses web standards by default, so using within node takes a little more effort.
|
|
70
|
+
|
|
71
|
+
You need import the node crypto library and assign it to globals
|
|
72
|
+
```js
|
|
73
|
+
import { webcrypto } from "crypto";
|
|
74
|
+
global.crypto = webcrypto;
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
or optionally pass it into the constructor
|
|
78
|
+
```js
|
|
79
|
+
import { webcrypto } from "crypto";
|
|
80
|
+
const api = await remarkable(token, { digest: webcrypto.subtle.digest });
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
You also need to have a globally defined fetch. There are several ways to
|
|
84
|
+
accomplish this. In node 17.5 or higher you can enable global fetch with
|
|
85
|
+
`node --experimental-fetch`
|
|
86
|
+
|
|
87
|
+
You can also rely on `"node-fetch"` which is compliant enough
|
|
88
|
+
```js
|
|
89
|
+
import fetch from "node-fetch";
|
|
90
|
+
global.fetch = fetch;
|
|
91
|
+
```
|
|
92
|
+
or
|
|
93
|
+
```js
|
|
94
|
+
import fetch from "node-fetch";
|
|
95
|
+
const api = await remarkable(token, { fetch });
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Design
|
|
99
|
+
------
|
|
100
|
+
|
|
101
|
+
Building a full syncing version of the remarkable filesystem from the cloud API
|
|
102
|
+
is a project in itselfs, so I opted to only implement the primative calls which
|
|
103
|
+
should still be possible to composte to advanced functionality.
|
|
104
|
+
|
|
105
|
+
In order to make this as easily cross platform as possible, web standards were
|
|
106
|
+
chosen as the basis since they enjoy relative adoption in node. However, node
|
|
107
|
+
has middling support of webstreams and since none of the reading or writing is
|
|
108
|
+
that intensive or doesn't already required the whole file in memory, we opted
|
|
109
|
+
to process strings or ArrayBuffers ignoring Readable and WriteableStreams for
|
|
110
|
+
the time being.
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
var ct=Object.create;var H=Object.defineProperty;var pt=Object.getOwnPropertyDescriptor;var yt=Object.getOwnPropertyNames;var gt=Object.getPrototypeOf,mt=Object.prototype.hasOwnProperty;var d=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),ht=(e,t)=>{for(var r in t)H(e,r,{get:t[r],enumerable:!0})},Pe=(e,t,r,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of yt(t))!mt.call(e,n)&&n!==r&&H(e,n,{get:()=>t[n],enumerable:!(i=pt(t,n))||i.enumerable});return e};var Te=(e,t,r)=>(r=e!=null?ct(gt(e)):{},Pe(t||!e||!e.__esModule?H(r,"default",{value:e,enumerable:!0}):r,e)),vt=e=>Pe(H({},"__esModule",{value:!0}),e);var ue=d(fe=>{"use strict";Object.defineProperty(fe,"__esModule",{value:!0});fe.default=xt;var bt=_t(require("crypto"));function _t(e){return e&&e.__esModule?e:{default:e}}var z=new Uint8Array(256),j=z.length;function xt(){return j>z.length-16&&(bt.default.randomFillSync(z),j=0),z.slice(j,j+=16)}});var Ee=d(J=>{"use strict";Object.defineProperty(J,"__esModule",{value:!0});J.default=void 0;var wt=/^(?:[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;J.default=wt});var B=d(V=>{"use strict";Object.defineProperty(V,"__esModule",{value:!0});V.default=void 0;var Pt=Tt(Ee());function Tt(e){return e&&e.__esModule?e:{default:e}}function Et(e){return typeof e=="string"&&Pt.default.test(e)}var Ot=Et;V.default=Ot});var N=d(G=>{"use strict";Object.defineProperty(G,"__esModule",{value:!0});G.default=void 0;var kt=At(B());function At(e){return e&&e.__esModule?e:{default:e}}var y=[];for(let e=0;e<256;++e)y.push((e+256).toString(16).substr(1));function St(e,t=0){let r=(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();if(!(0,kt.default)(r))throw TypeError("Stringified UUID is invalid");return r}var Mt=St;G.default=Mt});var Ae=d(Y=>{"use strict";Object.defineProperty(Y,"__esModule",{value:!0});Y.default=void 0;var Rt=ke(ue()),Ft=ke(N());function ke(e){return e&&e.__esModule?e:{default:e}}var Oe,le,de=0,ce=0;function qt(e,t,r){let i=t&&r||0,n=t||new Array(16);e=e||{};let s=e.node||Oe,o=e.clockseq!==void 0?e.clockseq:le;if(s==null||o==null){let l=e.random||(e.rng||Rt.default)();s==null&&(s=Oe=[l[0]|1,l[1],l[2],l[3],l[4],l[5]]),o==null&&(o=le=(l[6]<<8|l[7])&16383)}let a=e.msecs!==void 0?e.msecs:Date.now(),f=e.nsecs!==void 0?e.nsecs:ce+1,c=a-de+(f-ce)/1e4;if(c<0&&e.clockseq===void 0&&(o=o+1&16383),(c<0||a>de)&&e.nsecs===void 0&&(f=0),f>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");de=a,ce=f,le=o,a+=122192928e5;let p=((a&268435455)*1e4+f)%4294967296;n[i++]=p>>>24&255,n[i++]=p>>>16&255,n[i++]=p>>>8&255,n[i++]=p&255;let b=a/4294967296*1e4&268435455;n[i++]=b>>>8&255,n[i++]=b&255,n[i++]=b>>>24&15|16,n[i++]=b>>>16&255,n[i++]=o>>>8|128,n[i++]=o&255;for(let l=0;l<6;++l)n[i+l]=s[l];return t||(0,Ft.default)(n)}var It=qt;Y.default=It});var pe=d(Z=>{"use strict";Object.defineProperty(Z,"__esModule",{value:!0});Z.default=void 0;var Dt=Ut(B());function Ut(e){return e&&e.__esModule?e:{default:e}}function Lt(e){if(!(0,Dt.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 Bt=Lt;Z.default=Bt});var ye=d(O=>{"use strict";Object.defineProperty(O,"__esModule",{value:!0});O.default=Ht;O.URL=O.DNS=void 0;var Nt=Se(N()),Ct=Se(pe());function Se(e){return e&&e.__esModule?e:{default:e}}function $t(e){e=unescape(encodeURIComponent(e));let t=[];for(let r=0;r<e.length;++r)t.push(e.charCodeAt(r));return t}var Me="6ba7b810-9dad-11d1-80b4-00c04fd430c8";O.DNS=Me;var Re="6ba7b811-9dad-11d1-80b4-00c04fd430c8";O.URL=Re;function Ht(e,t,r){function i(n,s,o,a){if(typeof n=="string"&&(n=$t(n)),typeof s=="string"&&(s=(0,Ct.default)(s)),s.length!==16)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");let f=new Uint8Array(16+n.length);if(f.set(s),f.set(n,s.length),f=r(f),f[6]=f[6]&15|t,f[8]=f[8]&63|128,o){a=a||0;for(let c=0;c<16;++c)o[a+c]=f[c];return o}return(0,Nt.default)(f)}try{i.name=e}catch{}return i.DNS=Me,i.URL=Re,i}});var Fe=d(W=>{"use strict";Object.defineProperty(W,"__esModule",{value:!0});W.default=void 0;var jt=zt(require("crypto"));function zt(e){return e&&e.__esModule?e:{default:e}}function Jt(e){return Array.isArray(e)?e=Buffer.from(e):typeof e=="string"&&(e=Buffer.from(e,"utf8")),jt.default.createHash("md5").update(e).digest()}var Vt=Jt;W.default=Vt});var Ie=d(K=>{"use strict";Object.defineProperty(K,"__esModule",{value:!0});K.default=void 0;var Gt=qe(ye()),Yt=qe(Fe());function qe(e){return e&&e.__esModule?e:{default:e}}var Zt=(0,Gt.default)("v3",48,Yt.default),Wt=Zt;K.default=Wt});var Ue=d(Q=>{"use strict";Object.defineProperty(Q,"__esModule",{value:!0});Q.default=void 0;var Kt=De(ue()),Qt=De(N());function De(e){return e&&e.__esModule?e:{default:e}}function Xt(e,t,r){e=e||{};let i=e.random||(e.rng||Kt.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,Qt.default)(i)}var er=Xt;Q.default=er});var Le=d(X=>{"use strict";Object.defineProperty(X,"__esModule",{value:!0});X.default=void 0;var tr=rr(require("crypto"));function rr(e){return e&&e.__esModule?e:{default:e}}function nr(e){return Array.isArray(e)?e=Buffer.from(e):typeof e=="string"&&(e=Buffer.from(e,"utf8")),tr.default.createHash("sha1").update(e).digest()}var ir=nr;X.default=ir});var Ne=d(ee=>{"use strict";Object.defineProperty(ee,"__esModule",{value:!0});ee.default=void 0;var sr=Be(ye()),or=Be(Le());function Be(e){return e&&e.__esModule?e:{default:e}}var ar=(0,sr.default)("v5",80,or.default),fr=ar;ee.default=fr});var Ce=d(te=>{"use strict";Object.defineProperty(te,"__esModule",{value:!0});te.default=void 0;var ur="00000000-0000-0000-0000-000000000000";te.default=ur});var $e=d(re=>{"use strict";Object.defineProperty(re,"__esModule",{value:!0});re.default=void 0;var lr=dr(B());function dr(e){return e&&e.__esModule?e:{default:e}}function cr(e){if(!(0,lr.default)(e))throw TypeError("Invalid UUID");return parseInt(e.substr(14,1),16)}var pr=cr;re.default=pr});var He=d(x=>{"use strict";Object.defineProperty(x,"__esModule",{value:!0});Object.defineProperty(x,"v1",{enumerable:!0,get:function(){return yr.default}});Object.defineProperty(x,"v3",{enumerable:!0,get:function(){return gr.default}});Object.defineProperty(x,"v4",{enumerable:!0,get:function(){return mr.default}});Object.defineProperty(x,"v5",{enumerable:!0,get:function(){return hr.default}});Object.defineProperty(x,"NIL",{enumerable:!0,get:function(){return vr.default}});Object.defineProperty(x,"version",{enumerable:!0,get:function(){return br.default}});Object.defineProperty(x,"validate",{enumerable:!0,get:function(){return _r.default}});Object.defineProperty(x,"stringify",{enumerable:!0,get:function(){return xr.default}});Object.defineProperty(x,"parse",{enumerable:!0,get:function(){return wr.default}});var yr=P(Ae()),gr=P(Ie()),mr=P(Ue()),hr=P(Ne()),vr=P(Ce()),br=P($e()),_r=P(B()),xr=P(N()),wr=P(pe());function P(e){return e&&e.__esModule?e:{default:e}}});var ve=d(u=>{"use strict";var Je=u&&u.__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(u,"__esModule",{value:!0});u.isSchema=u.isValidSchema=u.isDiscriminatorForm=u.isValuesForm=u.isPropertiesForm=u.isElementsForm=u.isEnumForm=u.isTypeForm=u.isRefForm=u.isEmptyForm=void 0;function Pr(e){let{definitions:t,nullable:r,metadata:i}=e,n=Je(e,["definitions","nullable","metadata"]);return Object.keys(n).length===0}u.isEmptyForm=Pr;function Ve(e){return"ref"in e}u.isRefForm=Ve;function Tr(e){return"type"in e}u.isTypeForm=Tr;function Ge(e){return"enum"in e}u.isEnumForm=Ge;function Ye(e){return"elements"in e}u.isElementsForm=Ye;function he(e){return"properties"in e||"optionalProperties"in e}u.isPropertiesForm=he;function Ze(e){return"values"in e}u.isValuesForm=Ze;function We(e){return"discriminator"in e}u.isDiscriminatorForm=We;function k(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(!k(r,t))return!1}if(Ve(e)&&!(e.ref in(t.definitions||{}))||Ge(e)&&(e.enum.length===0||e.enum.length!==new Set(e.enum).size))return!1;if(Ye(e))return k(e.elements,t);if(he(e)){for(let r of Object.values(e.properties||{}))if(!k(r,t))return!1;for(let r of Object.values(e.optionalProperties||{}))if(!k(r,t))return!1;for(let r of Object.keys(e.properties||{}))if(r in(e.optionalProperties||{}))return!1}if(Ze(e))return k(e.values,t);if(We(e)){for(let r of Object.values(e.mapping))if(!k(r,t)||!he(r)||r.nullable||e.discriminator in(r.properties||{})||e.discriminator in(r.optionalProperties||{}))return!1}return!0}u.isValidSchema=k;var Er=[[!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]],Or=["boolean","float32","float64","int8","uint8","int16","uint16","int32","uint32","string","timestamp"];function A(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:s=void 0,type:o=void 0,enum:a=void 0,elements:f=void 0,properties:c=void 0,optionalProperties:p=void 0,additionalProperties:b=void 0,values:l=void 0,discriminator:I=void 0,mapping:_=void 0}=t,se=Je(t,["definitions","nullable","metadata","ref","type","enum","elements","properties","optionalProperties","additionalProperties","values","discriminator","mapping"]),D=[s!==void 0,o!==void 0,a!==void 0,f!==void 0,c!==void 0,p!==void 0,b!==void 0,l!==void 0,I!==void 0,_!==void 0],L=!1;for(let v of Er)L=L||v.every((oe,ae)=>oe===D[ae]);if(!L)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(!A(v))return!1}if(i!==void 0&&typeof i!="boolean"||n!==void 0&&(typeof n!="object"||Array.isArray(n)||n===null)||s!==void 0&&typeof s!="string"||o!==void 0&&(typeof o!="string"||!Or.includes(o))||a!==void 0&&(!Array.isArray(a)||!a.every(v=>typeof v=="string"))||f!==void 0&&!A(f))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(!A(v))return!1}if(p!==void 0){if(typeof p!="object"||Array.isArray(p)||p===null)return!1;for(let v of Object.values(p))if(!A(v))return!1}if(b!==void 0&&typeof b!="boolean"||l!==void 0&&!A(l)||I!==void 0&&typeof I!="string")return!1;if(_!==void 0){if(typeof _!="object"||Array.isArray(_)||_===null)return!1;for(let v of Object.values(_))if(!A(v))return!1}return Object.keys(se).length===0}u.isSchema=A});var Ke=d(be=>{"use strict";Object.defineProperty(be,"__esModule",{value:!0});var kr=/^(\d{4})-(\d{2})-(\d{2})[tT](\d{2}):(\d{2}):(\d{2})(\.\d+)?([zZ]|((\+|-)(\d{2}):(\d{2})))$/;function Ar(e){let t=e.match(kr);if(t===null)return!1;let r=parseInt(t[1],10),i=parseInt(t[2],10),n=parseInt(t[3],10),s=parseInt(t[4],10),o=parseInt(t[5],10),a=parseInt(t[6],10);return!(i>12||n>Sr(r,i)||s>23||o>59||a>60)}be.default=Ar;function Sr(e,t){return t===2?Mr(e)?29:28:Rr[t]}function Mr(e){return e%4===0&&(e%100!==0||e%400===0)}var Rr=[0,31,0,31,30,31,30,31,31,30,31,30,31]});var Qe=d(T=>{"use strict";var Fr=T&&T.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(T,"__esModule",{value:!0});T.validate=T.MaxDepthExceededError=void 0;var qr=Fr(Ke()),S=ve(),ne=class extends Error{};T.MaxDepthExceededError=ne;var ie=class extends Error{};function Ir(e,t,r){let i={errors:[],instanceTokens:[],schemaTokens:[[]],root:e,config:r||{maxDepth:0,maxErrors:0}};try{F(i,e,t)}catch(n){if(!(n instanceof ie))throw n}return i.errors}T.validate=Ir;function F(e,t,r,i){if(!(t.nullable&&r===null)){if(S.isRefForm(t)){if(e.schemaTokens.length===e.config.maxDepth)throw new ne;e.schemaTokens.push(["definitions",t.ref]),F(e,e.root.definitions[t.ref],r),e.schemaTokens.pop()}else if(S.isTypeForm(t)){switch(g(e,"type"),t.type){case"boolean":typeof r!="boolean"&&m(e);break;case"float32":case"float64":typeof r!="number"&&m(e);break;case"int8":U(e,r,-128,127);break;case"uint8":U(e,r,0,255);break;case"int16":U(e,r,-32768,32767);break;case"uint16":U(e,r,0,65535);break;case"int32":U(e,r,-2147483648,2147483647);break;case"uint32":U(e,r,0,4294967295);break;case"string":typeof r!="string"&&m(e);break;case"timestamp":typeof r!="string"?m(e):qr.default(r)||m(e);break}h(e)}else if(S.isEnumForm(t))g(e,"enum"),(typeof r!="string"||!t.enum.includes(r))&&m(e),h(e);else if(S.isElementsForm(t)){if(g(e,"elements"),Array.isArray(r))for(let[n,s]of r.entries())M(e,n.toString()),F(e,t.elements,s),R(e);else m(e);h(e)}else if(S.isPropertiesForm(t))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){if(t.properties!==void 0){g(e,"properties");for(let[n,s]of Object.entries(t.properties))g(e,n),r.hasOwnProperty(n)?(M(e,n),F(e,s,r[n]),R(e)):m(e),h(e);h(e)}if(t.optionalProperties!==void 0){g(e,"optionalProperties");for(let[n,s]of Object.entries(t.optionalProperties))g(e,n),r.hasOwnProperty(n)&&(M(e,n),F(e,s,r[n]),R(e)),h(e);h(e)}if(t.additionalProperties!==!0)for(let n of Object.keys(r)){let s=t.properties&&n in t.properties,o=t.optionalProperties&&n in t.optionalProperties;!s&&!o&&n!==i&&(M(e,n),m(e),R(e))}}else t.properties!==void 0?g(e,"properties"):g(e,"optionalProperties"),m(e),h(e);else if(S.isValuesForm(t)){if(g(e,"values"),typeof r=="object"&&r!==null&&!Array.isArray(r))for(let[n,s]of Object.entries(r))M(e,n),F(e,t.values,s),R(e);else m(e);h(e)}else if(S.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?(g(e,"mapping"),g(e,n),F(e,t.mapping[n],r,t.discriminator),h(e),h(e)):(g(e,"mapping"),M(e,t.discriminator),m(e),R(e),h(e)):(g(e,"discriminator"),M(e,t.discriminator),m(e),R(e),h(e))}else g(e,"discriminator"),m(e),h(e);else g(e,"discriminator"),m(e),h(e)}}function U(e,t,r,i){(typeof t!="number"||!Number.isInteger(t)||t<r||t>i)&&m(e)}function M(e,t){e.instanceTokens.push(t)}function R(e){e.instanceTokens.pop()}function g(e,t){e.schemaTokens[e.schemaTokens.length-1].push(t)}function h(e){e.schemaTokens[e.schemaTokens.length-1].pop()}function m(e){if(e.errors.push({instancePath:[...e.instanceTokens],schemaPath:[...e.schemaTokens[e.schemaTokens.length-1]]}),e.errors.length===e.config.maxErrors)throw new ie}});var et=d(E=>{"use strict";var Dr=E&&E.__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]}),Xe=E&&E.__exportStar||function(e,t){for(var r in e)r!=="default"&&!t.hasOwnProperty(r)&&Dr(t,e,r)};Object.defineProperty(E,"__esModule",{value:!0});Xe(ve(),E);Xe(Qe(),E)});var Vr={};ht(Vr,{GenerationError:()=>C,ResponseError:()=>q,builtinFontNames:()=>Nr,builtinLineHeights:()=>ut,builtinMargins:()=>ft,builtinTextScales:()=>at,builtinTools:()=>Br,register:()=>Hr,remarkable:()=>Jr});module.exports=vt(Vr);var w=Te(He(),1),ln=w.default.v1,dn=w.default.v3,ge=w.default.v4,cn=w.default.v5,pn=w.default.NIL,yn=w.default.version,gn=w.default.validate,mn=w.default.stringify,hn=w.default.parse;function me(e){return[...new Uint8Array(e)].map(t=>t.toString(16).padStart(2,"0")).join("")}function je(e){return new Uint8Array((e.match(/../g)??[]).map(t=>parseInt(t,16)))}function ze(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 tt=Te(et());function _e(e,t){if((0,tt.validate)(e,t).length)throw new Error(`couldn't validate schema: ${JSON.stringify(t)} didn't match schema ${JSON.stringify(e)}`)}var rt="3",ot="https://webapp-production-dot-remarkable-production.appspot.com",Ur="https://rm-blob-storage-prod.appspot.com",nt="x-goog-generation",Lr="x-goog-if-generation-match",Br=["Ballpoint","Ballpointv2","Brush","Calligraphy","ClearPage","EraseSection","Eraser","Fineliner","Finelinerv2","Highlighter","Highlighterv2","Marker","Markerv2","Paintbrush","Paintbrushv2","Pencilv2","SharpPencil","SharpPencilv2","SolidPen","ZoomTool"],Nr=["Maison Neue","EB Garamond","Noto Sans","Noto Serif","Noto Mono","Noto Sans UI"],at={xs:.7,sm:.8,md:1,lg:1.2,xl:1.5,xx:2},ft={sm:50,md:125,rr:180,lg:200},ut={df:-1,md:100,lg:150,xl:200},Cr={properties:{relative_path:{type:"string"},url:{type:"string"},expires:{type:"timestamp"},method:{enum:["POST","GET","PUT","DELETE"]}}},it={visibleName:{type:"string"},parent:{type:"string"},lastModified:{type:"string"},version:{type:"int32"},synced:{type:"boolean"}},st={pinned:{type:"boolean"},modified:{type:"boolean"},deleted:{type:"boolean"},metadatamodified:{type:"boolean"}},$r={discriminator:"type",mapping:{CollectionType:{properties:it,optionalProperties:st},DocumentType:{properties:it,optionalProperties:{...st,lastOpened:{type:"string"},lastOpenedPage:{type:"int32"}}}}},q=class extends Error{constructor(r,i,n){super(n);this.status=r,this.statusText=i}},C=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 Hr(e,{deviceDesc:t="desktop-linux",uuid:r=ge(),authUrl:i=ot,fetch:n=globalThis.fetch}={}){if(e.length!==8)throw new Error(`code should be length 8, but was ${e.length}`);let s=await n(`${i}/token/json/2/device/new`,{method:"POST",headers:{Authorization:"Bearer"},body:JSON.stringify({code:e,deviceDesc:t,deviceID:r})});if(s.ok)return await s.text();throw new q(s.status,s.statusText,"couldn't register api")}function jr({hash:e,type:t,documentId:r,subfiles:i,size:n}){return`${e}:${t}:${r}:${i}:${n}
|
|
2
|
+
`}function zr(e){let[t,r,i,n,s]=e.split(":");if(t===void 0||r===void 0||i===void 0||n===void 0||s===void 0)throw new Error(`entries line didn't contain five fields: '${e}'`);if(r==="80000000"){if(s!=="0")throw new Error(`collection type entry had nonzero size: ${s}`);return{hash:t,type:r,documentId:i,subfiles:parseInt(n),size:0n}}else 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(s)}}else throw new Error(`entries line contained invalid type: ${r}`)}var xe=class{constructor(t,r,i,n,s){this.userToken=t;this.fetch=r;this.cache=i;this.subtle=n;this.blobUrl=s}async authedFetch(t,r,i="POST"){let n=await this.fetch(t,{method:i,headers:{Authorization:`Bearer ${this.userToken}`},body:r&&JSON.stringify(r)});if(n.ok)return n;throw new q(n.status,n.statusText,"failed reMarkable request")}async signedFetch({url:t,method:r},i,n){let s=await this.fetch(t,{method:r,body:i,headers:n});if(s.ok)return s;{let o=await s.text();throw new q(s.status,s.statusText,o)}}async getUrl(t,r){let i=r===void 0?"downloads":"uploads",n=r==null?void 0:`${r}`,o=await(await this.authedFetch(`${this.blobUrl}/api/v1/signed-urls/${i}`,{http_method:n===void 0?"GET":"PUT",relative_path:t,generation:n})).text(),a=JSON.parse(o);return _e(Cr,a),a}async syncComplete(){await this.authedFetch(`${this.blobUrl}/api/v1/sync-complete`)}async getRootHash(){let t=await this.getUrl("root"),r=await this.signedFetch(t),i=r.headers.get(nt);if(!i)throw new Error("no generation header in root hash");return[await r.text(),BigInt(i)]}async putRootHash(t,r){let i=await this.getUrl("root",r),n;try{n=await this.signedFetch(i,t,{[Lr]:`${r}`})}catch(o){throw o instanceof q&&o.status===412?new C:o}let s=n.headers.get(nt);if(!s)throw new Error("no generation header in root hash");return BigInt(s)}async getBuffer(t){let r=await this.getUrl(t);return await(await this.signedFetch(r)).arrayBuffer()}async getText(t){let r=this.cache&&await this.cache.get(t);if(r)return r;{let i=await this.getUrl(t),s=await(await this.signedFetch(i)).text();return this.cache&&await this.cache.set(t,s),s}}async getMetadata(t){let r=await this.getText(t),i=JSON.parse(r);return _e($r,i),i}async getEntries(t){let r=await this.getText(t),[i,...n]=r.slice(0,-1).split(`
|
|
3
|
+
`);if(i!==rt)throw new Error(`got unexpected schema version: ${i}`);return n.map(zr)}async putHash(t,r){let i=await this.getUrl(t,null);await this.signedFetch(i,r)}async putEntries(t,r){let i=new TextEncoder;r.sort((p,b)=>p.documentId.localeCompare(b.documentId));let n=ze(r.map(p=>je(p.hash))),s=await this.subtle.digest("SHA-256",n),o=me(s),a=r.map(jr).join(""),f=`${rt}
|
|
4
|
+
${a}`,c=i.encode(f);return await this.putHash(o,c),this.cache&&await this.cache.set(o,f),{hash:o,type:"80000000",documentId:t,subfiles:r.length,size:0n}}async putBuffer(t,r){let i=await this.subtle.digest("SHA-256",r),n=me(i);return await this.putHash(n,r),{hash:n,type:"0",documentId:t,subfiles:0,size:BigInt(r.length)}}async putText(t,r){let i=new TextEncoder,n=await this.putBuffer(t,i.encode(r));return this.cache&&await this.cache.set(n.hash,r),n}async putEpub(t,r,{parent:i="",margins:n=125,orientation:s,textAlignment:o,textScale:a=1,lineHeight:f=-1,fontName:c="",cover:p="visited",lastTool:b,notify:l=!0,retries:I=3}={}){let _=ge(),se=`${new Date().valueOf()}`,D=[];D.push(this.putBuffer(`${_}.epub`,r));let L={type:"DocumentType",visibleName:t,version:0,parent:i,synced:!0,lastModified:se};D.push(this.putText(`${_}.metadata`,JSON.stringify(L)));let v={dummyDocument:!1,extraMetadata:{LastTool:b},fileType:"epub",pageCount:0,lastOpenedPage:0,lineHeight:typeof f=="string"?ut[f]:f,margins:typeof n=="string"?ft[n]:n,textScale:typeof a=="string"?at[a]:a,pages:[],coverPageNumber:p==="first"?0:-1,formatVersion:1,orientation:s,textAlignment:o,fontName:c};D.push(this.putText(`${_}.content`,JSON.stringify(v)));let oe=await Promise.all(D),ae=await this.putEntries(_,oe);for(;;--I)try{let[$,lt]=await this.getRootHash(),we=await this.getEntries($);we.push(ae);let{hash:dt}=await this.putEntries("",we);await this.putRootHash(dt,lt);break}catch($){if(I<=0||!($ instanceof C))throw $}l&&await this.syncComplete()}};async function Jr(e,{fetch:t=globalThis.fetch,cache:r,subtle:i=globalThis.crypto?.subtle,authUrl:n=ot,blobUrl:s=Ur}={}){let o=await t(`${n}/token/json/2/user/new`,{method:"POST",headers:{Authorization:`Bearer ${e}`}});if(!o.ok)throw new Error(`couldn't fetch auth token: ${o.statusText}`);let a=await o.text();return new xe(a,t,r,i,s)}0&&(module.exports={GenerationError,ResponseError,builtinFontNames,builtinLineHeights,builtinMargins,builtinTextScales,builtinTools,register,remarkable});
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
var Ce=Object.create;var ue=Object.defineProperty;var Le=Object.getOwnPropertyDescriptor;var je=Object.getOwnPropertyNames;var De=Object.getPrototypeOf,Ne=Object.prototype.hasOwnProperty;var q=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports);var $e=(e,r,t,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of je(r))!Ne.call(e,n)&&n!==t&&ue(e,n,{get:()=>r[n],enumerable:!(i=Le(r,n))||i.enumerable});return e};var He=(e,r,t)=>(t=e!=null?Ce(De(e)):{},$e(r||!e||!e.__esModule?ue(t,"default",{value:e,enumerable:!0}):t,e));var oe=q(l=>{"use strict";var ye=l&&l.__rest||function(e,r){var t={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&r.indexOf(i)<0&&(t[i]=e[i]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var n=0,i=Object.getOwnPropertySymbols(e);n<i.length;n++)r.indexOf(i[n])<0&&Object.prototype.propertyIsEnumerable.call(e,i[n])&&(t[i[n]]=e[i[n]]);return t};Object.defineProperty(l,"__esModule",{value:!0});l.isSchema=l.isValidSchema=l.isDiscriminatorForm=l.isValuesForm=l.isPropertiesForm=l.isElementsForm=l.isEnumForm=l.isTypeForm=l.isRefForm=l.isEmptyForm=void 0;function rt(e){let{definitions:r,nullable:t,metadata:i}=e,n=ye(e,["definitions","nullable","metadata"]);return Object.keys(n).length===0}l.isEmptyForm=rt;function ve(e){return"ref"in e}l.isRefForm=ve;function nt(e){return"type"in e}l.isTypeForm=nt;function be(e){return"enum"in e}l.isEnumForm=be;function xe(e){return"elements"in e}l.isElementsForm=xe;function ie(e){return"properties"in e||"optionalProperties"in e}l.isPropertiesForm=ie;function we(e){return"values"in e}l.isValuesForm=we;function Te(e){return"discriminator"in e}l.isDiscriminatorForm=Te;function C(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(!C(t,r))return!1}if(ve(e)&&!(e.ref in(r.definitions||{}))||be(e)&&(e.enum.length===0||e.enum.length!==new Set(e.enum).size))return!1;if(xe(e))return C(e.elements,r);if(ie(e)){for(let t of Object.values(e.properties||{}))if(!C(t,r))return!1;for(let t of Object.values(e.optionalProperties||{}))if(!C(t,r))return!1;for(let t of Object.keys(e.properties||{}))if(t in(e.optionalProperties||{}))return!1}if(we(e))return C(e.values,r);if(Te(e)){for(let t of Object.values(e.mapping))if(!C(t,r)||!ie(t)||t.nullable||e.discriminator in(t.properties||{})||e.discriminator in(t.optionalProperties||{}))return!1}return!0}l.isValidSchema=C;var it=[[!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]],ot=["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 r=e,{definitions:t=void 0,nullable:i=void 0,metadata:n=void 0,ref:o=void 0,type:s=void 0,enum:f=void 0,elements:a=void 0,properties:d=void 0,optionalProperties:u=void 0,additionalProperties:E=void 0,values:T=void 0,discriminator:P=void 0,mapping:p=void 0}=r,S=ye(r,["definitions","nullable","metadata","ref","type","enum","elements","properties","optionalProperties","additionalProperties","values","discriminator","mapping"]),A=[o!==void 0,s!==void 0,f!==void 0,a!==void 0,d!==void 0,u!==void 0,E!==void 0,T!==void 0,P!==void 0,p!==void 0],k=!1;for(let c of it)k=k||c.every((U,O)=>U===A[O]);if(!k)return!1;if(t!==void 0){if(typeof t!="object"||Array.isArray(t)||t===null)return!1;for(let c of Object.values(t))if(!L(c))return!1}if(i!==void 0&&typeof i!="boolean"||n!==void 0&&(typeof n!="object"||Array.isArray(n)||n===null)||o!==void 0&&typeof o!="string"||s!==void 0&&(typeof s!="string"||!ot.includes(s))||f!==void 0&&(!Array.isArray(f)||!f.every(c=>typeof c=="string"))||a!==void 0&&!L(a))return!1;if(d!==void 0){if(typeof d!="object"||Array.isArray(d)||d===null)return!1;for(let c of Object.values(d))if(!L(c))return!1}if(u!==void 0){if(typeof u!="object"||Array.isArray(u)||u===null)return!1;for(let c of Object.values(u))if(!L(c))return!1}if(E!==void 0&&typeof E!="boolean"||T!==void 0&&!L(T)||P!==void 0&&typeof P!="string")return!1;if(p!==void 0){if(typeof p!="object"||Array.isArray(p)||p===null)return!1;for(let c of Object.values(p))if(!L(c))return!1}return Object.keys(S).length===0}l.isSchema=L});var Ee=q(se=>{"use strict";Object.defineProperty(se,"__esModule",{value:!0});var st=/^(\d{4})-(\d{2})-(\d{2})[tT](\d{2}):(\d{2}):(\d{2})(\.\d+)?([zZ]|((\+|-)(\d{2}):(\d{2})))$/;function at(e){let r=e.match(st);if(r===null)return!1;let t=parseInt(r[1],10),i=parseInt(r[2],10),n=parseInt(r[3],10),o=parseInt(r[4],10),s=parseInt(r[5],10),f=parseInt(r[6],10);return!(i>12||n>ft(t,i)||o>23||s>59||f>60)}se.default=at;function ft(e,r){return r===2?lt(e)?29:28:ut[r]}function lt(e){return e%4===0&&(e%100!==0||e%400===0)}var ut=[0,31,0,31,30,31,30,31,31,30,31,30,31]});var Pe=q(F=>{"use strict";var dt=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 pt=dt(Ee()),j=oe(),X=class extends Error{};F.MaxDepthExceededError=X;var Q=class extends Error{};function ct(e,r,t){let i={errors:[],instanceTokens:[],schemaTokens:[[]],root:e,config:t||{maxDepth:0,maxErrors:0}};try{$(i,e,r)}catch(n){if(!(n instanceof Q))throw n}return i.errors}F.validate=ct;function $(e,r,t,i){if(!(r.nullable&&t===null)){if(j.isRefForm(r)){if(e.schemaTokens.length===e.config.maxDepth)throw new X;e.schemaTokens.push(["definitions",r.ref]),$(e,e.root.definitions[r.ref],t),e.schemaTokens.pop()}else if(j.isTypeForm(r)){switch(b(e,"type"),r.type){case"boolean":typeof t!="boolean"&&x(e);break;case"float32":case"float64":typeof t!="number"&&x(e);break;case"int8":B(e,t,-128,127);break;case"uint8":B(e,t,0,255);break;case"int16":B(e,t,-32768,32767);break;case"uint16":B(e,t,0,65535);break;case"int32":B(e,t,-2147483648,2147483647);break;case"uint32":B(e,t,0,4294967295);break;case"string":typeof t!="string"&&x(e);break;case"timestamp":typeof t!="string"?x(e):pt.default(t)||x(e);break}w(e)}else if(j.isEnumForm(r))b(e,"enum"),(typeof t!="string"||!r.enum.includes(t))&&x(e),w(e);else if(j.isElementsForm(r)){if(b(e,"elements"),Array.isArray(t))for(let[n,o]of t.entries())D(e,n.toString()),$(e,r.elements,o),N(e);else x(e);w(e)}else if(j.isPropertiesForm(r))if(typeof t=="object"&&t!==null&&!Array.isArray(t)){if(r.properties!==void 0){b(e,"properties");for(let[n,o]of Object.entries(r.properties))b(e,n),t.hasOwnProperty(n)?(D(e,n),$(e,o,t[n]),N(e)):x(e),w(e);w(e)}if(r.optionalProperties!==void 0){b(e,"optionalProperties");for(let[n,o]of Object.entries(r.optionalProperties))b(e,n),t.hasOwnProperty(n)&&(D(e,n),$(e,o,t[n]),N(e)),w(e);w(e)}if(r.additionalProperties!==!0)for(let n of Object.keys(t)){let o=r.properties&&n in r.properties,s=r.optionalProperties&&n in r.optionalProperties;!o&&!s&&n!==i&&(D(e,n),x(e),N(e))}}else r.properties!==void 0?b(e,"properties"):b(e,"optionalProperties"),x(e),w(e);else if(j.isValuesForm(r)){if(b(e,"values"),typeof t=="object"&&t!==null&&!Array.isArray(t))for(let[n,o]of Object.entries(t))D(e,n),$(e,r.values,o),N(e);else x(e);w(e)}else if(j.isDiscriminatorForm(r))if(typeof t=="object"&&t!==null&&!Array.isArray(t))if(t.hasOwnProperty(r.discriminator)){let n=t[r.discriminator];typeof n=="string"?n in r.mapping?(b(e,"mapping"),b(e,n),$(e,r.mapping[n],t,r.discriminator),w(e),w(e)):(b(e,"mapping"),D(e,r.discriminator),x(e),N(e),w(e)):(b(e,"discriminator"),D(e,r.discriminator),x(e),N(e),w(e))}else b(e,"discriminator"),x(e),w(e);else b(e,"discriminator"),x(e),w(e)}}function B(e,r,t,i){(typeof r!="number"||!Number.isInteger(r)||r<t||r>i)&&x(e)}function D(e,r){e.instanceTokens.push(r)}function N(e){e.instanceTokens.pop()}function b(e,r){e.schemaTokens[e.schemaTokens.length-1].push(r)}function w(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 Q}});var ke=q(I=>{"use strict";var mt=I&&I.__createBinding||(Object.create?function(e,r,t,i){i===void 0&&(i=t),Object.defineProperty(e,i,{enumerable:!0,get:function(){return r[t]}})}:function(e,r,t,i){i===void 0&&(i=t),e[i]=r[t]}),Ae=I&&I.__exportStar||function(e,r){for(var t in e)t!=="default"&&!r.hasOwnProperty(t)&&mt(r,e,t)};Object.defineProperty(I,"__esModule",{value:!0});Ae(oe(),I);Ae(Pe(),I)});var J,_e=new Uint8Array(16);function z(){if(!J&&(J=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||typeof msCrypto<"u"&&typeof msCrypto.getRandomValues=="function"&&msCrypto.getRandomValues.bind(msCrypto),!J))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return J(_e)}var de=/^(?:[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 Be(e){return typeof e=="string"&&de.test(e)}var H=Be;var m=[];for(G=0;G<256;++G)m.push((G+256).toString(16).substr(1));var G;function Ve(e){var r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,t=(m[e[r+0]]+m[e[r+1]]+m[e[r+2]]+m[e[r+3]]+"-"+m[e[r+4]]+m[e[r+5]]+"-"+m[e[r+6]]+m[e[r+7]]+"-"+m[e[r+8]]+m[e[r+9]]+"-"+m[e[r+10]]+m[e[r+11]]+m[e[r+12]]+m[e[r+13]]+m[e[r+14]]+m[e[r+15]]).toLowerCase();if(!H(t))throw TypeError("Stringified UUID is invalid");return t}var _=Ve;function qe(e){if(!H(e))throw TypeError("Invalid UUID");var 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 te=qe;function Je(e){e=unescape(encodeURIComponent(e));for(var r=[],t=0;t<e.length;++t)r.push(e.charCodeAt(t));return r}var ze="6ba7b810-9dad-11d1-80b4-00c04fd430c8",Ge="6ba7b811-9dad-11d1-80b4-00c04fd430c8";function Y(e,r,t){function i(n,o,s,f){if(typeof n=="string"&&(n=Je(n)),typeof o=="string"&&(o=te(o)),o.length!==16)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");var a=new Uint8Array(16+n.length);if(a.set(o),a.set(n,o.length),a=t(a),a[6]=a[6]&15|r,a[8]=a[8]&63|128,s){f=f||0;for(var d=0;d<16;++d)s[f+d]=a[d];return s}return _(a)}try{i.name=e}catch{}return i.DNS=ze,i.URL=Ge,i}function Ye(e){if(typeof e=="string"){var r=unescape(encodeURIComponent(e));e=new Uint8Array(r.length);for(var t=0;t<r.length;++t)e[t]=r.charCodeAt(t)}return Ze(Ke(Xe(e),e.length*8))}function Ze(e){for(var r=[],t=e.length*32,i="0123456789abcdef",n=0;n<t;n+=8){var o=e[n>>5]>>>n%32&255,s=parseInt(i.charAt(o>>>4&15)+i.charAt(o&15),16);r.push(s)}return r}function pe(e){return(e+64>>>9<<4)+14+1}function Ke(e,r){e[r>>5]|=128<<r%32,e[pe(r)-1]=r;for(var t=1732584193,i=-271733879,n=-1732584194,o=271733878,s=0;s<e.length;s+=16){var f=t,a=i,d=n,u=o;t=g(t,i,n,o,e[s],7,-680876936),o=g(o,t,i,n,e[s+1],12,-389564586),n=g(n,o,t,i,e[s+2],17,606105819),i=g(i,n,o,t,e[s+3],22,-1044525330),t=g(t,i,n,o,e[s+4],7,-176418897),o=g(o,t,i,n,e[s+5],12,1200080426),n=g(n,o,t,i,e[s+6],17,-1473231341),i=g(i,n,o,t,e[s+7],22,-45705983),t=g(t,i,n,o,e[s+8],7,1770035416),o=g(o,t,i,n,e[s+9],12,-1958414417),n=g(n,o,t,i,e[s+10],17,-42063),i=g(i,n,o,t,e[s+11],22,-1990404162),t=g(t,i,n,o,e[s+12],7,1804603682),o=g(o,t,i,n,e[s+13],12,-40341101),n=g(n,o,t,i,e[s+14],17,-1502002290),i=g(i,n,o,t,e[s+15],22,1236535329),t=h(t,i,n,o,e[s+1],5,-165796510),o=h(o,t,i,n,e[s+6],9,-1069501632),n=h(n,o,t,i,e[s+11],14,643717713),i=h(i,n,o,t,e[s],20,-373897302),t=h(t,i,n,o,e[s+5],5,-701558691),o=h(o,t,i,n,e[s+10],9,38016083),n=h(n,o,t,i,e[s+15],14,-660478335),i=h(i,n,o,t,e[s+4],20,-405537848),t=h(t,i,n,o,e[s+9],5,568446438),o=h(o,t,i,n,e[s+14],9,-1019803690),n=h(n,o,t,i,e[s+3],14,-187363961),i=h(i,n,o,t,e[s+8],20,1163531501),t=h(t,i,n,o,e[s+13],5,-1444681467),o=h(o,t,i,n,e[s+2],9,-51403784),n=h(n,o,t,i,e[s+7],14,1735328473),i=h(i,n,o,t,e[s+12],20,-1926607734),t=y(t,i,n,o,e[s+5],4,-378558),o=y(o,t,i,n,e[s+8],11,-2022574463),n=y(n,o,t,i,e[s+11],16,1839030562),i=y(i,n,o,t,e[s+14],23,-35309556),t=y(t,i,n,o,e[s+1],4,-1530992060),o=y(o,t,i,n,e[s+4],11,1272893353),n=y(n,o,t,i,e[s+7],16,-155497632),i=y(i,n,o,t,e[s+10],23,-1094730640),t=y(t,i,n,o,e[s+13],4,681279174),o=y(o,t,i,n,e[s],11,-358537222),n=y(n,o,t,i,e[s+3],16,-722521979),i=y(i,n,o,t,e[s+6],23,76029189),t=y(t,i,n,o,e[s+9],4,-640364487),o=y(o,t,i,n,e[s+12],11,-421815835),n=y(n,o,t,i,e[s+15],16,530742520),i=y(i,n,o,t,e[s+2],23,-995338651),t=v(t,i,n,o,e[s],6,-198630844),o=v(o,t,i,n,e[s+7],10,1126891415),n=v(n,o,t,i,e[s+14],15,-1416354905),i=v(i,n,o,t,e[s+5],21,-57434055),t=v(t,i,n,o,e[s+12],6,1700485571),o=v(o,t,i,n,e[s+3],10,-1894986606),n=v(n,o,t,i,e[s+10],15,-1051523),i=v(i,n,o,t,e[s+1],21,-2054922799),t=v(t,i,n,o,e[s+8],6,1873313359),o=v(o,t,i,n,e[s+15],10,-30611744),n=v(n,o,t,i,e[s+6],15,-1560198380),i=v(i,n,o,t,e[s+13],21,1309151649),t=v(t,i,n,o,e[s+4],6,-145523070),o=v(o,t,i,n,e[s+11],10,-1120210379),n=v(n,o,t,i,e[s+2],15,718787259),i=v(i,n,o,t,e[s+9],21,-343485551),t=R(t,f),i=R(i,a),n=R(n,d),o=R(o,u)}return[t,i,n,o]}function Xe(e){if(e.length===0)return[];for(var r=e.length*8,t=new Uint32Array(pe(r)),i=0;i<r;i+=8)t[i>>5]|=(e[i/8]&255)<<i%32;return t}function R(e,r){var t=(e&65535)+(r&65535),i=(e>>16)+(r>>16)+(t>>16);return i<<16|t&65535}function Qe(e,r){return e<<r|e>>>32-r}function Z(e,r,t,i,n,o){return R(Qe(R(R(r,e),R(i,o)),n),t)}function g(e,r,t,i,n,o,s){return Z(r&t|~r&i,e,r,n,o,s)}function h(e,r,t,i,n,o,s){return Z(r&i|t&~i,e,r,n,o,s)}function y(e,r,t,i,n,o,s){return Z(r^t^i,e,r,n,o,s)}function v(e,r,t,i,n,o,s){return Z(t^(r|~i),e,r,n,o,s)}var ce=Ye;var Bt=Y("v3",48,ce);function We(e,r,t){e=e||{};var i=e.random||(e.rng||z)();if(i[6]=i[6]&15|64,i[8]=i[8]&63|128,r){t=t||0;for(var n=0;n<16;++n)r[t+n]=i[n];return r}return _(i)}var K=We;function et(e,r,t,i){switch(e){case 0:return r&t^~r&i;case 1:return r^t^i;case 2:return r&t^r&i^t&i;case 3:return r^t^i}}function re(e,r){return e<<r|e>>>32-r}function tt(e){var r=[1518500249,1859775393,2400959708,3395469782],t=[1732584193,4023233417,2562383102,271733878,3285377520];if(typeof e=="string"){var i=unescape(encodeURIComponent(e));e=[];for(var n=0;n<i.length;++n)e.push(i.charCodeAt(n))}else Array.isArray(e)||(e=Array.prototype.slice.call(e));e.push(128);for(var o=e.length/4+2,s=Math.ceil(o/16),f=new Array(s),a=0;a<s;++a){for(var d=new Uint32Array(16),u=0;u<16;++u)d[u]=e[a*64+u*4]<<24|e[a*64+u*4+1]<<16|e[a*64+u*4+2]<<8|e[a*64+u*4+3];f[a]=d}f[s-1][14]=(e.length-1)*8/Math.pow(2,32),f[s-1][14]=Math.floor(f[s-1][14]),f[s-1][15]=(e.length-1)*8&4294967295;for(var E=0;E<s;++E){for(var T=new Uint32Array(80),P=0;P<16;++P)T[P]=f[E][P];for(var p=16;p<80;++p)T[p]=re(T[p-3]^T[p-8]^T[p-14]^T[p-16],1);for(var S=t[0],A=t[1],k=t[2],c=t[3],U=t[4],O=0;O<80;++O){var M=Math.floor(O/20),ee=re(S,5)+et(M,A,k,c)+U+r[M]+T[O]>>>0;U=c,c=k,k=re(A,30)>>>0,A=S,S=ee}t[0]=t[0]+S>>>0,t[1]=t[1]+A>>>0,t[2]=t[2]+k>>>0,t[3]=t[3]+c>>>0,t[4]=t[4]+U>>>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 me=tt;var Kt=Y("v5",80,me);function ne(e){return[...new Uint8Array(e)].map(r=>r.toString(16).padStart(2,"0")).join("")}function ge(e){return new Uint8Array((e.match(/../g)??[]).map(r=>parseInt(r,16)))}function he(e){let r=0;for(let n of e)r+=n.length;let t=new Uint8Array(r),i=0;for(let n of e)t.set(n,i),i+=n.length;return t}var Se=He(ke());function ae(e,r){if((0,Se.validate)(e,r).length)throw new Error(`couldn't validate schema: ${JSON.stringify(r)} didn't match schema ${JSON.stringify(e)}`)}var Oe="3",Ue="https://webapp-production-dot-remarkable-production.appspot.com",gt="https://rm-blob-storage-prod.appspot.com",Re="x-goog-generation",ht="x-goog-if-generation-match",kr=["Ballpoint","Ballpointv2","Brush","Calligraphy","ClearPage","EraseSection","Eraser","Fineliner","Finelinerv2","Highlighter","Highlighterv2","Marker","Markerv2","Paintbrush","Paintbrushv2","Pencilv2","SharpPencil","SharpPencilv2","SolidPen","ZoomTool"],Sr=["Maison Neue","EB Garamond","Noto Sans","Noto Serif","Noto Mono","Noto Sans UI"],yt={xs:.7,sm:.8,md:1,lg:1.2,xl:1.5,xx:2},vt={sm:50,md:125,rr:180,lg:200},bt={df:-1,md:100,lg:150,xl:200},xt={properties:{relative_path:{type:"string"},url:{type:"string"},expires:{type:"timestamp"},method:{enum:["POST","GET","PUT","DELETE"]}}},Fe={visibleName:{type:"string"},parent:{type:"string"},lastModified:{type:"string"},version:{type:"int32"},synced:{type:"boolean"}},Ie={pinned:{type:"boolean"},modified:{type:"boolean"},deleted:{type:"boolean"},metadatamodified:{type:"boolean"}},wt={discriminator:"type",mapping:{CollectionType:{properties:Fe,optionalProperties:Ie},DocumentType:{properties:Fe,optionalProperties:{...Ie,lastOpened:{type:"string"},lastOpenedPage:{type:"int32"}}}}},V=class extends Error{constructor(t,i,n){super(n);this.status=t,this.statusText=i}},W=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 Or(e,{deviceDesc:r="desktop-linux",uuid:t=K(),authUrl:i=Ue,fetch:n=globalThis.fetch}={}){if(e.length!==8)throw new Error(`code should be length 8, but was ${e.length}`);let o=await n(`${i}/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 V(o.status,o.statusText,"couldn't register api")}function Tt({hash:e,type:r,documentId:t,subfiles:i,size:n}){return`${e}:${r}:${t}:${i}:${n}
|
|
2
|
+
`}function Et(e){let[r,t,i,n,o]=e.split(":");if(r===void 0||t===void 0||i===void 0||n===void 0||o===void 0)throw new Error(`entries line didn't contain five fields: '${e}'`);if(t==="80000000"){if(o!=="0")throw new Error(`collection type entry had nonzero size: ${o}`);return{hash:r,type:t,documentId:i,subfiles:parseInt(n),size:0n}}else if(t==="0"){if(n!=="0")throw new Error(`file type entry had nonzero number of subfiles: ${n}`);return{hash:r,type:t,documentId:i,subfiles:0,size:BigInt(o)}}else throw new Error(`entries line contained invalid type: ${t}`)}var fe=class{constructor(r,t,i,n,o){this.userToken=r;this.fetch=t;this.cache=i;this.subtle=n;this.blobUrl=o}async authedFetch(r,t,i="POST"){let n=await this.fetch(r,{method:i,headers:{Authorization:`Bearer ${this.userToken}`},body:t&&JSON.stringify(t)});if(n.ok)return n;throw new V(n.status,n.statusText,"failed reMarkable request")}async signedFetch({url:r,method:t},i,n){let o=await this.fetch(r,{method:t,body:i,headers:n});if(o.ok)return o;{let s=await o.text();throw new V(o.status,o.statusText,s)}}async getUrl(r,t){let i=t===void 0?"downloads":"uploads",n=t==null?void 0:`${t}`,s=await(await this.authedFetch(`${this.blobUrl}/api/v1/signed-urls/${i}`,{http_method:n===void 0?"GET":"PUT",relative_path:r,generation:n})).text(),f=JSON.parse(s);return ae(xt,f),f}async syncComplete(){await this.authedFetch(`${this.blobUrl}/api/v1/sync-complete`)}async getRootHash(){let r=await this.getUrl("root"),t=await this.signedFetch(r),i=t.headers.get(Re);if(!i)throw new Error("no generation header in root hash");return[await t.text(),BigInt(i)]}async putRootHash(r,t){let i=await this.getUrl("root",t),n;try{n=await this.signedFetch(i,r,{[ht]:`${t}`})}catch(s){throw s instanceof V&&s.status===412?new W:s}let o=n.headers.get(Re);if(!o)throw new Error("no generation header in root hash");return BigInt(o)}async getBuffer(r){let t=await this.getUrl(r);return await(await this.signedFetch(t)).arrayBuffer()}async getText(r){let t=this.cache&&await this.cache.get(r);if(t)return t;{let i=await this.getUrl(r),o=await(await this.signedFetch(i)).text();return this.cache&&await this.cache.set(r,o),o}}async getMetadata(r){let t=await this.getText(r),i=JSON.parse(t);return ae(wt,i),i}async getEntries(r){let t=await this.getText(r),[i,...n]=t.slice(0,-1).split(`
|
|
3
|
+
`);if(i!==Oe)throw new Error(`got unexpected schema version: ${i}`);return n.map(Et)}async putHash(r,t){let i=await this.getUrl(r,null);await this.signedFetch(i,t)}async putEntries(r,t){let i=new TextEncoder;t.sort((u,E)=>u.documentId.localeCompare(E.documentId));let n=he(t.map(u=>ge(u.hash))),o=await this.subtle.digest("SHA-256",n),s=ne(o),f=t.map(Tt).join(""),a=`${Oe}
|
|
4
|
+
${f}`,d=i.encode(a);return await this.putHash(s,d),this.cache&&await this.cache.set(s,a),{hash:s,type:"80000000",documentId:r,subfiles:t.length,size:0n}}async putBuffer(r,t){let i=await this.subtle.digest("SHA-256",t),n=ne(i);return await this.putHash(n,t),{hash:n,type:"0",documentId:r,subfiles:0,size:BigInt(t.length)}}async putText(r,t){let i=new TextEncoder,n=await this.putBuffer(r,i.encode(t));return this.cache&&await this.cache.set(n.hash,t),n}async putEpub(r,t,{parent:i="",margins:n=125,orientation:o,textAlignment:s,textScale:f=1,lineHeight:a=-1,fontName:d="",cover:u="visited",lastTool:E,notify:T=!0,retries:P=3}={}){let p=K(),S=`${new Date().valueOf()}`,A=[];A.push(this.putBuffer(`${p}.epub`,t));let k={type:"DocumentType",visibleName:r,version:0,parent:i,synced:!0,lastModified:S};A.push(this.putText(`${p}.metadata`,JSON.stringify(k)));let c={dummyDocument:!1,extraMetadata:{LastTool:E},fileType:"epub",pageCount:0,lastOpenedPage:0,lineHeight:typeof a=="string"?bt[a]:a,margins:typeof n=="string"?vt[n]:n,textScale:typeof f=="string"?yt[f]:f,pages:[],coverPageNumber:u==="first"?0:-1,formatVersion:1,orientation:o,textAlignment:s,fontName:d};A.push(this.putText(`${p}.content`,JSON.stringify(c)));let U=await Promise.all(A),O=await this.putEntries(p,U);for(;;--P)try{let[M,ee]=await this.getRootHash(),le=await this.getEntries(M);le.push(O);let{hash:Me}=await this.putEntries("",le);await this.putRootHash(Me,ee);break}catch(M){if(P<=0||!(M instanceof W))throw M}T&&await this.syncComplete()}};async function Rr(e,{fetch:r=globalThis.fetch,cache:t,subtle:i=globalThis.crypto?.subtle,authUrl:n=Ue,blobUrl:o=gt}={}){let s=await r(`${n}/token/json/2/user/new`,{method:"POST",headers:{Authorization:`Bearer ${e}`}});if(!s.ok)throw new Error(`couldn't fetch auth token: ${s.statusText}`);let f=await s.text();return new fe(f,r,t,i,o)}export{W as GenerationError,V as ResponseError,Sr as builtinFontNames,bt as builtinLineHeights,vt as builtinMargins,yt as builtinTextScales,kr as builtinTools,Or as register,Rr as remarkable};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
var rmapi=(()=>{var Ne=Object.create;var J=Object.defineProperty;var $e=Object.getOwnPropertyDescriptor;var He=Object.getOwnPropertyNames;var _e=Object.getPrototypeOf,Be=Object.prototype.hasOwnProperty;var z=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports),Ve=(e,r)=>{for(var t in r)J(e,t,{get:r[t],enumerable:!0})},de=(e,r,t,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of He(r))!Be.call(e,n)&&n!==t&&J(e,n,{get:()=>r[n],enumerable:!(i=$e(r,n))||i.enumerable});return e};var qe=(e,r,t)=>(t=e!=null?Ne(_e(e)):{},de(r||!e||!e.__esModule?J(t,"default",{value:e,enumerable:!0}):t,e)),Je=e=>de(J({},"__esModule",{value:!0}),e);var se=z(l=>{"use strict";var ve=l&&l.__rest||function(e,r){var t={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&r.indexOf(i)<0&&(t[i]=e[i]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var n=0,i=Object.getOwnPropertySymbols(e);n<i.length;n++)r.indexOf(i[n])<0&&Object.prototype.propertyIsEnumerable.call(e,i[n])&&(t[i[n]]=e[i[n]]);return t};Object.defineProperty(l,"__esModule",{value:!0});l.isSchema=l.isValidSchema=l.isDiscriminatorForm=l.isValuesForm=l.isPropertiesForm=l.isElementsForm=l.isEnumForm=l.isTypeForm=l.isRefForm=l.isEmptyForm=void 0;function at(e){let{definitions:r,nullable:t,metadata:i}=e,n=ve(e,["definitions","nullable","metadata"]);return Object.keys(n).length===0}l.isEmptyForm=at;function be(e){return"ref"in e}l.isRefForm=be;function ft(e){return"type"in e}l.isTypeForm=ft;function xe(e){return"enum"in e}l.isEnumForm=xe;function we(e){return"elements"in e}l.isElementsForm=we;function oe(e){return"properties"in e||"optionalProperties"in e}l.isPropertiesForm=oe;function Te(e){return"values"in e}l.isValuesForm=Te;function Ee(e){return"discriminator"in e}l.isDiscriminatorForm=Ee;function C(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(!C(t,r))return!1}if(be(e)&&!(e.ref in(r.definitions||{}))||xe(e)&&(e.enum.length===0||e.enum.length!==new Set(e.enum).size))return!1;if(we(e))return C(e.elements,r);if(oe(e)){for(let t of Object.values(e.properties||{}))if(!C(t,r))return!1;for(let t of Object.values(e.optionalProperties||{}))if(!C(t,r))return!1;for(let t of Object.keys(e.properties||{}))if(t in(e.optionalProperties||{}))return!1}if(Te(e))return C(e.values,r);if(Ee(e)){for(let t of Object.values(e.mapping))if(!C(t,r)||!oe(t)||t.nullable||e.discriminator in(t.properties||{})||e.discriminator in(t.optionalProperties||{}))return!1}return!0}l.isValidSchema=C;var lt=[[!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]],ut=["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 r=e,{definitions:t=void 0,nullable:i=void 0,metadata:n=void 0,ref:o=void 0,type:s=void 0,enum:f=void 0,elements:a=void 0,properties:d=void 0,optionalProperties:u=void 0,additionalProperties:E=void 0,values:T=void 0,discriminator:P=void 0,mapping:p=void 0}=r,S=ve(r,["definitions","nullable","metadata","ref","type","enum","elements","properties","optionalProperties","additionalProperties","values","discriminator","mapping"]),A=[o!==void 0,s!==void 0,f!==void 0,a!==void 0,d!==void 0,u!==void 0,E!==void 0,T!==void 0,P!==void 0,p!==void 0],k=!1;for(let c of lt)k=k||c.every((U,O)=>U===A[O]);if(!k)return!1;if(t!==void 0){if(typeof t!="object"||Array.isArray(t)||t===null)return!1;for(let c of Object.values(t))if(!L(c))return!1}if(i!==void 0&&typeof i!="boolean"||n!==void 0&&(typeof n!="object"||Array.isArray(n)||n===null)||o!==void 0&&typeof o!="string"||s!==void 0&&(typeof s!="string"||!ut.includes(s))||f!==void 0&&(!Array.isArray(f)||!f.every(c=>typeof c=="string"))||a!==void 0&&!L(a))return!1;if(d!==void 0){if(typeof d!="object"||Array.isArray(d)||d===null)return!1;for(let c of Object.values(d))if(!L(c))return!1}if(u!==void 0){if(typeof u!="object"||Array.isArray(u)||u===null)return!1;for(let c of Object.values(u))if(!L(c))return!1}if(E!==void 0&&typeof E!="boolean"||T!==void 0&&!L(T)||P!==void 0&&typeof P!="string")return!1;if(p!==void 0){if(typeof p!="object"||Array.isArray(p)||p===null)return!1;for(let c of Object.values(p))if(!L(c))return!1}return Object.keys(S).length===0}l.isSchema=L});var Pe=z(ae=>{"use strict";Object.defineProperty(ae,"__esModule",{value:!0});var dt=/^(\d{4})-(\d{2})-(\d{2})[tT](\d{2}):(\d{2}):(\d{2})(\.\d+)?([zZ]|((\+|-)(\d{2}):(\d{2})))$/;function pt(e){let r=e.match(dt);if(r===null)return!1;let t=parseInt(r[1],10),i=parseInt(r[2],10),n=parseInt(r[3],10),o=parseInt(r[4],10),s=parseInt(r[5],10),f=parseInt(r[6],10);return!(i>12||n>ct(t,i)||o>23||s>59||f>60)}ae.default=pt;function ct(e,r){return r===2?mt(e)?29:28:gt[r]}function mt(e){return e%4===0&&(e%100!==0||e%400===0)}var gt=[0,31,0,31,30,31,30,31,31,30,31,30,31]});var Ae=z(F=>{"use strict";var ht=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 yt=ht(Pe()),j=se(),W=class extends Error{};F.MaxDepthExceededError=W;var ee=class extends Error{};function vt(e,r,t){let i={errors:[],instanceTokens:[],schemaTokens:[[]],root:e,config:t||{maxDepth:0,maxErrors:0}};try{$(i,e,r)}catch(n){if(!(n instanceof ee))throw n}return i.errors}F.validate=vt;function $(e,r,t,i){if(!(r.nullable&&t===null)){if(j.isRefForm(r)){if(e.schemaTokens.length===e.config.maxDepth)throw new W;e.schemaTokens.push(["definitions",r.ref]),$(e,e.root.definitions[r.ref],t),e.schemaTokens.pop()}else if(j.isTypeForm(r)){switch(b(e,"type"),r.type){case"boolean":typeof t!="boolean"&&x(e);break;case"float32":case"float64":typeof t!="number"&&x(e);break;case"int8":V(e,t,-128,127);break;case"uint8":V(e,t,0,255);break;case"int16":V(e,t,-32768,32767);break;case"uint16":V(e,t,0,65535);break;case"int32":V(e,t,-2147483648,2147483647);break;case"uint32":V(e,t,0,4294967295);break;case"string":typeof t!="string"&&x(e);break;case"timestamp":typeof t!="string"?x(e):yt.default(t)||x(e);break}w(e)}else if(j.isEnumForm(r))b(e,"enum"),(typeof t!="string"||!r.enum.includes(t))&&x(e),w(e);else if(j.isElementsForm(r)){if(b(e,"elements"),Array.isArray(t))for(let[n,o]of t.entries())D(e,n.toString()),$(e,r.elements,o),N(e);else x(e);w(e)}else if(j.isPropertiesForm(r))if(typeof t=="object"&&t!==null&&!Array.isArray(t)){if(r.properties!==void 0){b(e,"properties");for(let[n,o]of Object.entries(r.properties))b(e,n),t.hasOwnProperty(n)?(D(e,n),$(e,o,t[n]),N(e)):x(e),w(e);w(e)}if(r.optionalProperties!==void 0){b(e,"optionalProperties");for(let[n,o]of Object.entries(r.optionalProperties))b(e,n),t.hasOwnProperty(n)&&(D(e,n),$(e,o,t[n]),N(e)),w(e);w(e)}if(r.additionalProperties!==!0)for(let n of Object.keys(t)){let o=r.properties&&n in r.properties,s=r.optionalProperties&&n in r.optionalProperties;!o&&!s&&n!==i&&(D(e,n),x(e),N(e))}}else r.properties!==void 0?b(e,"properties"):b(e,"optionalProperties"),x(e),w(e);else if(j.isValuesForm(r)){if(b(e,"values"),typeof t=="object"&&t!==null&&!Array.isArray(t))for(let[n,o]of Object.entries(t))D(e,n),$(e,r.values,o),N(e);else x(e);w(e)}else if(j.isDiscriminatorForm(r))if(typeof t=="object"&&t!==null&&!Array.isArray(t))if(t.hasOwnProperty(r.discriminator)){let n=t[r.discriminator];typeof n=="string"?n in r.mapping?(b(e,"mapping"),b(e,n),$(e,r.mapping[n],t,r.discriminator),w(e),w(e)):(b(e,"mapping"),D(e,r.discriminator),x(e),N(e),w(e)):(b(e,"discriminator"),D(e,r.discriminator),x(e),N(e),w(e))}else b(e,"discriminator"),x(e),w(e);else b(e,"discriminator"),x(e),w(e)}}function V(e,r,t,i){(typeof r!="number"||!Number.isInteger(r)||r<t||r>i)&&x(e)}function D(e,r){e.instanceTokens.push(r)}function N(e){e.instanceTokens.pop()}function b(e,r){e.schemaTokens[e.schemaTokens.length-1].push(r)}function w(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 Se=z(I=>{"use strict";var bt=I&&I.__createBinding||(Object.create?function(e,r,t,i){i===void 0&&(i=t),Object.defineProperty(e,i,{enumerable:!0,get:function(){return r[t]}})}:function(e,r,t,i){i===void 0&&(i=t),e[i]=r[t]}),ke=I&&I.__exportStar||function(e,r){for(var t in e)t!=="default"&&!r.hasOwnProperty(t)&&bt(r,e,t)};Object.defineProperty(I,"__esModule",{value:!0});ke(se(),I);ke(Ae(),I)});var Ft={};Ve(Ft,{GenerationError:()=>q,ResponseError:()=>H,builtinFontNames:()=>Et,builtinLineHeights:()=>je,builtinMargins:()=>Le,builtinTextScales:()=>Ce,builtinTools:()=>Tt,register:()=>kt,remarkable:()=>Rt});var G,ze=new Uint8Array(16);function Y(){if(!G&&(G=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||typeof msCrypto<"u"&&typeof msCrypto.getRandomValues=="function"&&msCrypto.getRandomValues.bind(msCrypto),!G))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return G(ze)}var pe=/^(?:[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 Ge(e){return typeof e=="string"&&pe.test(e)}var _=Ge;var m=[];for(Z=0;Z<256;++Z)m.push((Z+256).toString(16).substr(1));var Z;function Ye(e){var r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,t=(m[e[r+0]]+m[e[r+1]]+m[e[r+2]]+m[e[r+3]]+"-"+m[e[r+4]]+m[e[r+5]]+"-"+m[e[r+6]]+m[e[r+7]]+"-"+m[e[r+8]]+m[e[r+9]]+"-"+m[e[r+10]]+m[e[r+11]]+m[e[r+12]]+m[e[r+13]]+m[e[r+14]]+m[e[r+15]]).toLowerCase();if(!_(t))throw TypeError("Stringified UUID is invalid");return t}var B=Ye;function Ze(e){if(!_(e))throw TypeError("Invalid UUID");var 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 re=Ze;function Ke(e){e=unescape(encodeURIComponent(e));for(var r=[],t=0;t<e.length;++t)r.push(e.charCodeAt(t));return r}var Xe="6ba7b810-9dad-11d1-80b4-00c04fd430c8",Qe="6ba7b811-9dad-11d1-80b4-00c04fd430c8";function K(e,r,t){function i(n,o,s,f){if(typeof n=="string"&&(n=Ke(n)),typeof o=="string"&&(o=re(o)),o.length!==16)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");var a=new Uint8Array(16+n.length);if(a.set(o),a.set(n,o.length),a=t(a),a[6]=a[6]&15|r,a[8]=a[8]&63|128,s){f=f||0;for(var d=0;d<16;++d)s[f+d]=a[d];return s}return B(a)}try{i.name=e}catch{}return i.DNS=Xe,i.URL=Qe,i}function We(e){if(typeof e=="string"){var r=unescape(encodeURIComponent(e));e=new Uint8Array(r.length);for(var t=0;t<r.length;++t)e[t]=r.charCodeAt(t)}return et(tt(rt(e),e.length*8))}function et(e){for(var r=[],t=e.length*32,i="0123456789abcdef",n=0;n<t;n+=8){var o=e[n>>5]>>>n%32&255,s=parseInt(i.charAt(o>>>4&15)+i.charAt(o&15),16);r.push(s)}return r}function ce(e){return(e+64>>>9<<4)+14+1}function tt(e,r){e[r>>5]|=128<<r%32,e[ce(r)-1]=r;for(var t=1732584193,i=-271733879,n=-1732584194,o=271733878,s=0;s<e.length;s+=16){var f=t,a=i,d=n,u=o;t=g(t,i,n,o,e[s],7,-680876936),o=g(o,t,i,n,e[s+1],12,-389564586),n=g(n,o,t,i,e[s+2],17,606105819),i=g(i,n,o,t,e[s+3],22,-1044525330),t=g(t,i,n,o,e[s+4],7,-176418897),o=g(o,t,i,n,e[s+5],12,1200080426),n=g(n,o,t,i,e[s+6],17,-1473231341),i=g(i,n,o,t,e[s+7],22,-45705983),t=g(t,i,n,o,e[s+8],7,1770035416),o=g(o,t,i,n,e[s+9],12,-1958414417),n=g(n,o,t,i,e[s+10],17,-42063),i=g(i,n,o,t,e[s+11],22,-1990404162),t=g(t,i,n,o,e[s+12],7,1804603682),o=g(o,t,i,n,e[s+13],12,-40341101),n=g(n,o,t,i,e[s+14],17,-1502002290),i=g(i,n,o,t,e[s+15],22,1236535329),t=h(t,i,n,o,e[s+1],5,-165796510),o=h(o,t,i,n,e[s+6],9,-1069501632),n=h(n,o,t,i,e[s+11],14,643717713),i=h(i,n,o,t,e[s],20,-373897302),t=h(t,i,n,o,e[s+5],5,-701558691),o=h(o,t,i,n,e[s+10],9,38016083),n=h(n,o,t,i,e[s+15],14,-660478335),i=h(i,n,o,t,e[s+4],20,-405537848),t=h(t,i,n,o,e[s+9],5,568446438),o=h(o,t,i,n,e[s+14],9,-1019803690),n=h(n,o,t,i,e[s+3],14,-187363961),i=h(i,n,o,t,e[s+8],20,1163531501),t=h(t,i,n,o,e[s+13],5,-1444681467),o=h(o,t,i,n,e[s+2],9,-51403784),n=h(n,o,t,i,e[s+7],14,1735328473),i=h(i,n,o,t,e[s+12],20,-1926607734),t=y(t,i,n,o,e[s+5],4,-378558),o=y(o,t,i,n,e[s+8],11,-2022574463),n=y(n,o,t,i,e[s+11],16,1839030562),i=y(i,n,o,t,e[s+14],23,-35309556),t=y(t,i,n,o,e[s+1],4,-1530992060),o=y(o,t,i,n,e[s+4],11,1272893353),n=y(n,o,t,i,e[s+7],16,-155497632),i=y(i,n,o,t,e[s+10],23,-1094730640),t=y(t,i,n,o,e[s+13],4,681279174),o=y(o,t,i,n,e[s],11,-358537222),n=y(n,o,t,i,e[s+3],16,-722521979),i=y(i,n,o,t,e[s+6],23,76029189),t=y(t,i,n,o,e[s+9],4,-640364487),o=y(o,t,i,n,e[s+12],11,-421815835),n=y(n,o,t,i,e[s+15],16,530742520),i=y(i,n,o,t,e[s+2],23,-995338651),t=v(t,i,n,o,e[s],6,-198630844),o=v(o,t,i,n,e[s+7],10,1126891415),n=v(n,o,t,i,e[s+14],15,-1416354905),i=v(i,n,o,t,e[s+5],21,-57434055),t=v(t,i,n,o,e[s+12],6,1700485571),o=v(o,t,i,n,e[s+3],10,-1894986606),n=v(n,o,t,i,e[s+10],15,-1051523),i=v(i,n,o,t,e[s+1],21,-2054922799),t=v(t,i,n,o,e[s+8],6,1873313359),o=v(o,t,i,n,e[s+15],10,-30611744),n=v(n,o,t,i,e[s+6],15,-1560198380),i=v(i,n,o,t,e[s+13],21,1309151649),t=v(t,i,n,o,e[s+4],6,-145523070),o=v(o,t,i,n,e[s+11],10,-1120210379),n=v(n,o,t,i,e[s+2],15,718787259),i=v(i,n,o,t,e[s+9],21,-343485551),t=R(t,f),i=R(i,a),n=R(n,d),o=R(o,u)}return[t,i,n,o]}function rt(e){if(e.length===0)return[];for(var r=e.length*8,t=new Uint32Array(ce(r)),i=0;i<r;i+=8)t[i>>5]|=(e[i/8]&255)<<i%32;return t}function R(e,r){var t=(e&65535)+(r&65535),i=(e>>16)+(r>>16)+(t>>16);return i<<16|t&65535}function nt(e,r){return e<<r|e>>>32-r}function X(e,r,t,i,n,o){return R(nt(R(R(r,e),R(i,o)),n),t)}function g(e,r,t,i,n,o,s){return X(r&t|~r&i,e,r,n,o,s)}function h(e,r,t,i,n,o,s){return X(r&i|t&~i,e,r,n,o,s)}function y(e,r,t,i,n,o,s){return X(r^t^i,e,r,n,o,s)}function v(e,r,t,i,n,o,s){return X(t^(r|~i),e,r,n,o,s)}var me=We;var Zt=K("v3",48,me);function it(e,r,t){e=e||{};var i=e.random||(e.rng||Y)();if(i[6]=i[6]&15|64,i[8]=i[8]&63|128,r){t=t||0;for(var n=0;n<16;++n)r[t+n]=i[n];return r}return B(i)}var Q=it;function ot(e,r,t,i){switch(e){case 0:return r&t^~r&i;case 1:return r^t^i;case 2:return r&t^r&i^t&i;case 3:return r^t^i}}function ne(e,r){return e<<r|e>>>32-r}function st(e){var r=[1518500249,1859775393,2400959708,3395469782],t=[1732584193,4023233417,2562383102,271733878,3285377520];if(typeof e=="string"){var i=unescape(encodeURIComponent(e));e=[];for(var n=0;n<i.length;++n)e.push(i.charCodeAt(n))}else Array.isArray(e)||(e=Array.prototype.slice.call(e));e.push(128);for(var o=e.length/4+2,s=Math.ceil(o/16),f=new Array(s),a=0;a<s;++a){for(var d=new Uint32Array(16),u=0;u<16;++u)d[u]=e[a*64+u*4]<<24|e[a*64+u*4+1]<<16|e[a*64+u*4+2]<<8|e[a*64+u*4+3];f[a]=d}f[s-1][14]=(e.length-1)*8/Math.pow(2,32),f[s-1][14]=Math.floor(f[s-1][14]),f[s-1][15]=(e.length-1)*8&4294967295;for(var E=0;E<s;++E){for(var T=new Uint32Array(80),P=0;P<16;++P)T[P]=f[E][P];for(var p=16;p<80;++p)T[p]=ne(T[p-3]^T[p-8]^T[p-14]^T[p-16],1);for(var S=t[0],A=t[1],k=t[2],c=t[3],U=t[4],O=0;O<80;++O){var M=Math.floor(O/20),te=ne(S,5)+ot(M,A,k,c)+U+r[M]+T[O]>>>0;U=c,c=k,k=ne(A,30)>>>0,A=S,S=te}t[0]=t[0]+S>>>0,t[1]=t[1]+A>>>0,t[2]=t[2]+k>>>0,t[3]=t[3]+c>>>0,t[4]=t[4]+U>>>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 ge=st;var nr=K("v5",80,ge);function ie(e){return[...new Uint8Array(e)].map(r=>r.toString(16).padStart(2,"0")).join("")}function he(e){return new Uint8Array((e.match(/../g)??[]).map(r=>parseInt(r,16)))}function ye(e){let r=0;for(let n of e)r+=n.length;let t=new Uint8Array(r),i=0;for(let n of e)t.set(n,i),i+=n.length;return t}var Oe=qe(Se());function fe(e,r){if((0,Oe.validate)(e,r).length)throw new Error(`couldn't validate schema: ${JSON.stringify(r)} didn't match schema ${JSON.stringify(e)}`)}var Re="3",Me="https://webapp-production-dot-remarkable-production.appspot.com",xt="https://rm-blob-storage-prod.appspot.com",Fe="x-goog-generation",wt="x-goog-if-generation-match",Tt=["Ballpoint","Ballpointv2","Brush","Calligraphy","ClearPage","EraseSection","Eraser","Fineliner","Finelinerv2","Highlighter","Highlighterv2","Marker","Markerv2","Paintbrush","Paintbrushv2","Pencilv2","SharpPencil","SharpPencilv2","SolidPen","ZoomTool"],Et=["Maison Neue","EB Garamond","Noto Sans","Noto Serif","Noto Mono","Noto Sans UI"],Ce={xs:.7,sm:.8,md:1,lg:1.2,xl:1.5,xx:2},Le={sm:50,md:125,rr:180,lg:200},je={df:-1,md:100,lg:150,xl:200},Pt={properties:{relative_path:{type:"string"},url:{type:"string"},expires:{type:"timestamp"},method:{enum:["POST","GET","PUT","DELETE"]}}},Ie={visibleName:{type:"string"},parent:{type:"string"},lastModified:{type:"string"},version:{type:"int32"},synced:{type:"boolean"}},Ue={pinned:{type:"boolean"},modified:{type:"boolean"},deleted:{type:"boolean"},metadatamodified:{type:"boolean"}},At={discriminator:"type",mapping:{CollectionType:{properties:Ie,optionalProperties:Ue},DocumentType:{properties:Ie,optionalProperties:{...Ue,lastOpened:{type:"string"},lastOpenedPage:{type:"int32"}}}}},H=class extends Error{constructor(t,i,n){super(n);this.status=t,this.statusText=i}},q=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 kt(e,{deviceDesc:r="desktop-linux",uuid:t=Q(),authUrl:i=Me,fetch:n=globalThis.fetch}={}){if(e.length!==8)throw new Error(`code should be length 8, but was ${e.length}`);let o=await n(`${i}/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 H(o.status,o.statusText,"couldn't register api")}function St({hash:e,type:r,documentId:t,subfiles:i,size:n}){return`${e}:${r}:${t}:${i}:${n}
|
|
2
|
+
`}function Ot(e){let[r,t,i,n,o]=e.split(":");if(r===void 0||t===void 0||i===void 0||n===void 0||o===void 0)throw new Error(`entries line didn't contain five fields: '${e}'`);if(t==="80000000"){if(o!=="0")throw new Error(`collection type entry had nonzero size: ${o}`);return{hash:r,type:t,documentId:i,subfiles:parseInt(n),size:0n}}else if(t==="0"){if(n!=="0")throw new Error(`file type entry had nonzero number of subfiles: ${n}`);return{hash:r,type:t,documentId:i,subfiles:0,size:BigInt(o)}}else throw new Error(`entries line contained invalid type: ${t}`)}var le=class{constructor(r,t,i,n,o){this.userToken=r;this.fetch=t;this.cache=i;this.subtle=n;this.blobUrl=o}async authedFetch(r,t,i="POST"){let n=await this.fetch(r,{method:i,headers:{Authorization:`Bearer ${this.userToken}`},body:t&&JSON.stringify(t)});if(n.ok)return n;throw new H(n.status,n.statusText,"failed reMarkable request")}async signedFetch({url:r,method:t},i,n){let o=await this.fetch(r,{method:t,body:i,headers:n});if(o.ok)return o;{let s=await o.text();throw new H(o.status,o.statusText,s)}}async getUrl(r,t){let i=t===void 0?"downloads":"uploads",n=t==null?void 0:`${t}`,s=await(await this.authedFetch(`${this.blobUrl}/api/v1/signed-urls/${i}`,{http_method:n===void 0?"GET":"PUT",relative_path:r,generation:n})).text(),f=JSON.parse(s);return fe(Pt,f),f}async syncComplete(){await this.authedFetch(`${this.blobUrl}/api/v1/sync-complete`)}async getRootHash(){let r=await this.getUrl("root"),t=await this.signedFetch(r),i=t.headers.get(Fe);if(!i)throw new Error("no generation header in root hash");return[await t.text(),BigInt(i)]}async putRootHash(r,t){let i=await this.getUrl("root",t),n;try{n=await this.signedFetch(i,r,{[wt]:`${t}`})}catch(s){throw s instanceof H&&s.status===412?new q:s}let o=n.headers.get(Fe);if(!o)throw new Error("no generation header in root hash");return BigInt(o)}async getBuffer(r){let t=await this.getUrl(r);return await(await this.signedFetch(t)).arrayBuffer()}async getText(r){let t=this.cache&&await this.cache.get(r);if(t)return t;{let i=await this.getUrl(r),o=await(await this.signedFetch(i)).text();return this.cache&&await this.cache.set(r,o),o}}async getMetadata(r){let t=await this.getText(r),i=JSON.parse(t);return fe(At,i),i}async getEntries(r){let t=await this.getText(r),[i,...n]=t.slice(0,-1).split(`
|
|
3
|
+
`);if(i!==Re)throw new Error(`got unexpected schema version: ${i}`);return n.map(Ot)}async putHash(r,t){let i=await this.getUrl(r,null);await this.signedFetch(i,t)}async putEntries(r,t){let i=new TextEncoder;t.sort((u,E)=>u.documentId.localeCompare(E.documentId));let n=ye(t.map(u=>he(u.hash))),o=await this.subtle.digest("SHA-256",n),s=ie(o),f=t.map(St).join(""),a=`${Re}
|
|
4
|
+
${f}`,d=i.encode(a);return await this.putHash(s,d),this.cache&&await this.cache.set(s,a),{hash:s,type:"80000000",documentId:r,subfiles:t.length,size:0n}}async putBuffer(r,t){let i=await this.subtle.digest("SHA-256",t),n=ie(i);return await this.putHash(n,t),{hash:n,type:"0",documentId:r,subfiles:0,size:BigInt(t.length)}}async putText(r,t){let i=new TextEncoder,n=await this.putBuffer(r,i.encode(t));return this.cache&&await this.cache.set(n.hash,t),n}async putEpub(r,t,{parent:i="",margins:n=125,orientation:o,textAlignment:s,textScale:f=1,lineHeight:a=-1,fontName:d="",cover:u="visited",lastTool:E,notify:T=!0,retries:P=3}={}){let p=Q(),S=`${new Date().valueOf()}`,A=[];A.push(this.putBuffer(`${p}.epub`,t));let k={type:"DocumentType",visibleName:r,version:0,parent:i,synced:!0,lastModified:S};A.push(this.putText(`${p}.metadata`,JSON.stringify(k)));let c={dummyDocument:!1,extraMetadata:{LastTool:E},fileType:"epub",pageCount:0,lastOpenedPage:0,lineHeight:typeof a=="string"?je[a]:a,margins:typeof n=="string"?Le[n]:n,textScale:typeof f=="string"?Ce[f]:f,pages:[],coverPageNumber:u==="first"?0:-1,formatVersion:1,orientation:o,textAlignment:s,fontName:d};A.push(this.putText(`${p}.content`,JSON.stringify(c)));let U=await Promise.all(A),O=await this.putEntries(p,U);for(;;--P)try{let[M,te]=await this.getRootHash(),ue=await this.getEntries(M);ue.push(O);let{hash:De}=await this.putEntries("",ue);await this.putRootHash(De,te);break}catch(M){if(P<=0||!(M instanceof q))throw M}T&&await this.syncComplete()}};async function Rt(e,{fetch:r=globalThis.fetch,cache:t,subtle:i=globalThis.crypto?.subtle,authUrl:n=Me,blobUrl:o=xt}={}){let s=await r(`${n}/token/json/2/user/new`,{method:"POST",headers:{Authorization:`Bearer ${e}`}});if(!s.ok)throw new Error(`couldn't fetch auth token: ${s.statusText}`);let f=await s.text();return new le(f,r,t,i,o)}return Je(Ft);})();
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
var ct=Object.create;var H=Object.defineProperty;var pt=Object.getOwnPropertyDescriptor;var yt=Object.getOwnPropertyNames;var gt=Object.getPrototypeOf,mt=Object.prototype.hasOwnProperty;var d=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),ht=(e,t)=>{for(var r in t)H(e,r,{get:t[r],enumerable:!0})},Pe=(e,t,r,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of yt(t))!mt.call(e,n)&&n!==r&&H(e,n,{get:()=>t[n],enumerable:!(i=pt(t,n))||i.enumerable});return e};var Te=(e,t,r)=>(r=e!=null?ct(gt(e)):{},Pe(t||!e||!e.__esModule?H(r,"default",{value:e,enumerable:!0}):r,e)),vt=e=>Pe(H({},"__esModule",{value:!0}),e);var ue=d(fe=>{"use strict";Object.defineProperty(fe,"__esModule",{value:!0});fe.default=xt;var bt=_t(require("crypto"));function _t(e){return e&&e.__esModule?e:{default:e}}var z=new Uint8Array(256),j=z.length;function xt(){return j>z.length-16&&(bt.default.randomFillSync(z),j=0),z.slice(j,j+=16)}});var Ee=d(J=>{"use strict";Object.defineProperty(J,"__esModule",{value:!0});J.default=void 0;var wt=/^(?:[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;J.default=wt});var B=d(V=>{"use strict";Object.defineProperty(V,"__esModule",{value:!0});V.default=void 0;var Pt=Tt(Ee());function Tt(e){return e&&e.__esModule?e:{default:e}}function Et(e){return typeof e=="string"&&Pt.default.test(e)}var Ot=Et;V.default=Ot});var N=d(G=>{"use strict";Object.defineProperty(G,"__esModule",{value:!0});G.default=void 0;var kt=At(B());function At(e){return e&&e.__esModule?e:{default:e}}var y=[];for(let e=0;e<256;++e)y.push((e+256).toString(16).substr(1));function St(e,t=0){let r=(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();if(!(0,kt.default)(r))throw TypeError("Stringified UUID is invalid");return r}var Mt=St;G.default=Mt});var Ae=d(Y=>{"use strict";Object.defineProperty(Y,"__esModule",{value:!0});Y.default=void 0;var Rt=ke(ue()),Ft=ke(N());function ke(e){return e&&e.__esModule?e:{default:e}}var Oe,le,de=0,ce=0;function qt(e,t,r){let i=t&&r||0,n=t||new Array(16);e=e||{};let s=e.node||Oe,o=e.clockseq!==void 0?e.clockseq:le;if(s==null||o==null){let l=e.random||(e.rng||Rt.default)();s==null&&(s=Oe=[l[0]|1,l[1],l[2],l[3],l[4],l[5]]),o==null&&(o=le=(l[6]<<8|l[7])&16383)}let a=e.msecs!==void 0?e.msecs:Date.now(),f=e.nsecs!==void 0?e.nsecs:ce+1,c=a-de+(f-ce)/1e4;if(c<0&&e.clockseq===void 0&&(o=o+1&16383),(c<0||a>de)&&e.nsecs===void 0&&(f=0),f>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");de=a,ce=f,le=o,a+=122192928e5;let p=((a&268435455)*1e4+f)%4294967296;n[i++]=p>>>24&255,n[i++]=p>>>16&255,n[i++]=p>>>8&255,n[i++]=p&255;let b=a/4294967296*1e4&268435455;n[i++]=b>>>8&255,n[i++]=b&255,n[i++]=b>>>24&15|16,n[i++]=b>>>16&255,n[i++]=o>>>8|128,n[i++]=o&255;for(let l=0;l<6;++l)n[i+l]=s[l];return t||(0,Ft.default)(n)}var It=qt;Y.default=It});var pe=d(Z=>{"use strict";Object.defineProperty(Z,"__esModule",{value:!0});Z.default=void 0;var Dt=Ut(B());function Ut(e){return e&&e.__esModule?e:{default:e}}function Lt(e){if(!(0,Dt.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 Bt=Lt;Z.default=Bt});var ye=d(O=>{"use strict";Object.defineProperty(O,"__esModule",{value:!0});O.default=Ht;O.URL=O.DNS=void 0;var Nt=Se(N()),Ct=Se(pe());function Se(e){return e&&e.__esModule?e:{default:e}}function $t(e){e=unescape(encodeURIComponent(e));let t=[];for(let r=0;r<e.length;++r)t.push(e.charCodeAt(r));return t}var Me="6ba7b810-9dad-11d1-80b4-00c04fd430c8";O.DNS=Me;var Re="6ba7b811-9dad-11d1-80b4-00c04fd430c8";O.URL=Re;function Ht(e,t,r){function i(n,s,o,a){if(typeof n=="string"&&(n=$t(n)),typeof s=="string"&&(s=(0,Ct.default)(s)),s.length!==16)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");let f=new Uint8Array(16+n.length);if(f.set(s),f.set(n,s.length),f=r(f),f[6]=f[6]&15|t,f[8]=f[8]&63|128,o){a=a||0;for(let c=0;c<16;++c)o[a+c]=f[c];return o}return(0,Nt.default)(f)}try{i.name=e}catch{}return i.DNS=Me,i.URL=Re,i}});var Fe=d(W=>{"use strict";Object.defineProperty(W,"__esModule",{value:!0});W.default=void 0;var jt=zt(require("crypto"));function zt(e){return e&&e.__esModule?e:{default:e}}function Jt(e){return Array.isArray(e)?e=Buffer.from(e):typeof e=="string"&&(e=Buffer.from(e,"utf8")),jt.default.createHash("md5").update(e).digest()}var Vt=Jt;W.default=Vt});var Ie=d(K=>{"use strict";Object.defineProperty(K,"__esModule",{value:!0});K.default=void 0;var Gt=qe(ye()),Yt=qe(Fe());function qe(e){return e&&e.__esModule?e:{default:e}}var Zt=(0,Gt.default)("v3",48,Yt.default),Wt=Zt;K.default=Wt});var Ue=d(Q=>{"use strict";Object.defineProperty(Q,"__esModule",{value:!0});Q.default=void 0;var Kt=De(ue()),Qt=De(N());function De(e){return e&&e.__esModule?e:{default:e}}function Xt(e,t,r){e=e||{};let i=e.random||(e.rng||Kt.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,Qt.default)(i)}var er=Xt;Q.default=er});var Le=d(X=>{"use strict";Object.defineProperty(X,"__esModule",{value:!0});X.default=void 0;var tr=rr(require("crypto"));function rr(e){return e&&e.__esModule?e:{default:e}}function nr(e){return Array.isArray(e)?e=Buffer.from(e):typeof e=="string"&&(e=Buffer.from(e,"utf8")),tr.default.createHash("sha1").update(e).digest()}var ir=nr;X.default=ir});var Ne=d(ee=>{"use strict";Object.defineProperty(ee,"__esModule",{value:!0});ee.default=void 0;var sr=Be(ye()),or=Be(Le());function Be(e){return e&&e.__esModule?e:{default:e}}var ar=(0,sr.default)("v5",80,or.default),fr=ar;ee.default=fr});var Ce=d(te=>{"use strict";Object.defineProperty(te,"__esModule",{value:!0});te.default=void 0;var ur="00000000-0000-0000-0000-000000000000";te.default=ur});var $e=d(re=>{"use strict";Object.defineProperty(re,"__esModule",{value:!0});re.default=void 0;var lr=dr(B());function dr(e){return e&&e.__esModule?e:{default:e}}function cr(e){if(!(0,lr.default)(e))throw TypeError("Invalid UUID");return parseInt(e.substr(14,1),16)}var pr=cr;re.default=pr});var He=d(x=>{"use strict";Object.defineProperty(x,"__esModule",{value:!0});Object.defineProperty(x,"v1",{enumerable:!0,get:function(){return yr.default}});Object.defineProperty(x,"v3",{enumerable:!0,get:function(){return gr.default}});Object.defineProperty(x,"v4",{enumerable:!0,get:function(){return mr.default}});Object.defineProperty(x,"v5",{enumerable:!0,get:function(){return hr.default}});Object.defineProperty(x,"NIL",{enumerable:!0,get:function(){return vr.default}});Object.defineProperty(x,"version",{enumerable:!0,get:function(){return br.default}});Object.defineProperty(x,"validate",{enumerable:!0,get:function(){return _r.default}});Object.defineProperty(x,"stringify",{enumerable:!0,get:function(){return xr.default}});Object.defineProperty(x,"parse",{enumerable:!0,get:function(){return wr.default}});var yr=P(Ae()),gr=P(Ie()),mr=P(Ue()),hr=P(Ne()),vr=P(Ce()),br=P($e()),_r=P(B()),xr=P(N()),wr=P(pe());function P(e){return e&&e.__esModule?e:{default:e}}});var ve=d(u=>{"use strict";var Je=u&&u.__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(u,"__esModule",{value:!0});u.isSchema=u.isValidSchema=u.isDiscriminatorForm=u.isValuesForm=u.isPropertiesForm=u.isElementsForm=u.isEnumForm=u.isTypeForm=u.isRefForm=u.isEmptyForm=void 0;function Pr(e){let{definitions:t,nullable:r,metadata:i}=e,n=Je(e,["definitions","nullable","metadata"]);return Object.keys(n).length===0}u.isEmptyForm=Pr;function Ve(e){return"ref"in e}u.isRefForm=Ve;function Tr(e){return"type"in e}u.isTypeForm=Tr;function Ge(e){return"enum"in e}u.isEnumForm=Ge;function Ye(e){return"elements"in e}u.isElementsForm=Ye;function he(e){return"properties"in e||"optionalProperties"in e}u.isPropertiesForm=he;function Ze(e){return"values"in e}u.isValuesForm=Ze;function We(e){return"discriminator"in e}u.isDiscriminatorForm=We;function k(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(!k(r,t))return!1}if(Ve(e)&&!(e.ref in(t.definitions||{}))||Ge(e)&&(e.enum.length===0||e.enum.length!==new Set(e.enum).size))return!1;if(Ye(e))return k(e.elements,t);if(he(e)){for(let r of Object.values(e.properties||{}))if(!k(r,t))return!1;for(let r of Object.values(e.optionalProperties||{}))if(!k(r,t))return!1;for(let r of Object.keys(e.properties||{}))if(r in(e.optionalProperties||{}))return!1}if(Ze(e))return k(e.values,t);if(We(e)){for(let r of Object.values(e.mapping))if(!k(r,t)||!he(r)||r.nullable||e.discriminator in(r.properties||{})||e.discriminator in(r.optionalProperties||{}))return!1}return!0}u.isValidSchema=k;var Er=[[!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]],Or=["boolean","float32","float64","int8","uint8","int16","uint16","int32","uint32","string","timestamp"];function A(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:s=void 0,type:o=void 0,enum:a=void 0,elements:f=void 0,properties:c=void 0,optionalProperties:p=void 0,additionalProperties:b=void 0,values:l=void 0,discriminator:I=void 0,mapping:_=void 0}=t,se=Je(t,["definitions","nullable","metadata","ref","type","enum","elements","properties","optionalProperties","additionalProperties","values","discriminator","mapping"]),D=[s!==void 0,o!==void 0,a!==void 0,f!==void 0,c!==void 0,p!==void 0,b!==void 0,l!==void 0,I!==void 0,_!==void 0],L=!1;for(let v of Er)L=L||v.every((oe,ae)=>oe===D[ae]);if(!L)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(!A(v))return!1}if(i!==void 0&&typeof i!="boolean"||n!==void 0&&(typeof n!="object"||Array.isArray(n)||n===null)||s!==void 0&&typeof s!="string"||o!==void 0&&(typeof o!="string"||!Or.includes(o))||a!==void 0&&(!Array.isArray(a)||!a.every(v=>typeof v=="string"))||f!==void 0&&!A(f))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(!A(v))return!1}if(p!==void 0){if(typeof p!="object"||Array.isArray(p)||p===null)return!1;for(let v of Object.values(p))if(!A(v))return!1}if(b!==void 0&&typeof b!="boolean"||l!==void 0&&!A(l)||I!==void 0&&typeof I!="string")return!1;if(_!==void 0){if(typeof _!="object"||Array.isArray(_)||_===null)return!1;for(let v of Object.values(_))if(!A(v))return!1}return Object.keys(se).length===0}u.isSchema=A});var Ke=d(be=>{"use strict";Object.defineProperty(be,"__esModule",{value:!0});var kr=/^(\d{4})-(\d{2})-(\d{2})[tT](\d{2}):(\d{2}):(\d{2})(\.\d+)?([zZ]|((\+|-)(\d{2}):(\d{2})))$/;function Ar(e){let t=e.match(kr);if(t===null)return!1;let r=parseInt(t[1],10),i=parseInt(t[2],10),n=parseInt(t[3],10),s=parseInt(t[4],10),o=parseInt(t[5],10),a=parseInt(t[6],10);return!(i>12||n>Sr(r,i)||s>23||o>59||a>60)}be.default=Ar;function Sr(e,t){return t===2?Mr(e)?29:28:Rr[t]}function Mr(e){return e%4===0&&(e%100!==0||e%400===0)}var Rr=[0,31,0,31,30,31,30,31,31,30,31,30,31]});var Qe=d(T=>{"use strict";var Fr=T&&T.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(T,"__esModule",{value:!0});T.validate=T.MaxDepthExceededError=void 0;var qr=Fr(Ke()),S=ve(),ne=class extends Error{};T.MaxDepthExceededError=ne;var ie=class extends Error{};function Ir(e,t,r){let i={errors:[],instanceTokens:[],schemaTokens:[[]],root:e,config:r||{maxDepth:0,maxErrors:0}};try{F(i,e,t)}catch(n){if(!(n instanceof ie))throw n}return i.errors}T.validate=Ir;function F(e,t,r,i){if(!(t.nullable&&r===null)){if(S.isRefForm(t)){if(e.schemaTokens.length===e.config.maxDepth)throw new ne;e.schemaTokens.push(["definitions",t.ref]),F(e,e.root.definitions[t.ref],r),e.schemaTokens.pop()}else if(S.isTypeForm(t)){switch(g(e,"type"),t.type){case"boolean":typeof r!="boolean"&&m(e);break;case"float32":case"float64":typeof r!="number"&&m(e);break;case"int8":U(e,r,-128,127);break;case"uint8":U(e,r,0,255);break;case"int16":U(e,r,-32768,32767);break;case"uint16":U(e,r,0,65535);break;case"int32":U(e,r,-2147483648,2147483647);break;case"uint32":U(e,r,0,4294967295);break;case"string":typeof r!="string"&&m(e);break;case"timestamp":typeof r!="string"?m(e):qr.default(r)||m(e);break}h(e)}else if(S.isEnumForm(t))g(e,"enum"),(typeof r!="string"||!t.enum.includes(r))&&m(e),h(e);else if(S.isElementsForm(t)){if(g(e,"elements"),Array.isArray(r))for(let[n,s]of r.entries())M(e,n.toString()),F(e,t.elements,s),R(e);else m(e);h(e)}else if(S.isPropertiesForm(t))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){if(t.properties!==void 0){g(e,"properties");for(let[n,s]of Object.entries(t.properties))g(e,n),r.hasOwnProperty(n)?(M(e,n),F(e,s,r[n]),R(e)):m(e),h(e);h(e)}if(t.optionalProperties!==void 0){g(e,"optionalProperties");for(let[n,s]of Object.entries(t.optionalProperties))g(e,n),r.hasOwnProperty(n)&&(M(e,n),F(e,s,r[n]),R(e)),h(e);h(e)}if(t.additionalProperties!==!0)for(let n of Object.keys(r)){let s=t.properties&&n in t.properties,o=t.optionalProperties&&n in t.optionalProperties;!s&&!o&&n!==i&&(M(e,n),m(e),R(e))}}else t.properties!==void 0?g(e,"properties"):g(e,"optionalProperties"),m(e),h(e);else if(S.isValuesForm(t)){if(g(e,"values"),typeof r=="object"&&r!==null&&!Array.isArray(r))for(let[n,s]of Object.entries(r))M(e,n),F(e,t.values,s),R(e);else m(e);h(e)}else if(S.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?(g(e,"mapping"),g(e,n),F(e,t.mapping[n],r,t.discriminator),h(e),h(e)):(g(e,"mapping"),M(e,t.discriminator),m(e),R(e),h(e)):(g(e,"discriminator"),M(e,t.discriminator),m(e),R(e),h(e))}else g(e,"discriminator"),m(e),h(e);else g(e,"discriminator"),m(e),h(e)}}function U(e,t,r,i){(typeof t!="number"||!Number.isInteger(t)||t<r||t>i)&&m(e)}function M(e,t){e.instanceTokens.push(t)}function R(e){e.instanceTokens.pop()}function g(e,t){e.schemaTokens[e.schemaTokens.length-1].push(t)}function h(e){e.schemaTokens[e.schemaTokens.length-1].pop()}function m(e){if(e.errors.push({instancePath:[...e.instanceTokens],schemaPath:[...e.schemaTokens[e.schemaTokens.length-1]]}),e.errors.length===e.config.maxErrors)throw new ie}});var et=d(E=>{"use strict";var Dr=E&&E.__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]}),Xe=E&&E.__exportStar||function(e,t){for(var r in e)r!=="default"&&!t.hasOwnProperty(r)&&Dr(t,e,r)};Object.defineProperty(E,"__esModule",{value:!0});Xe(ve(),E);Xe(Qe(),E)});var Vr={};ht(Vr,{GenerationError:()=>C,ResponseError:()=>q,builtinFontNames:()=>Nr,builtinLineHeights:()=>ut,builtinMargins:()=>ft,builtinTextScales:()=>at,builtinTools:()=>Br,register:()=>Hr,remarkable:()=>Jr});module.exports=vt(Vr);var w=Te(He(),1),ln=w.default.v1,dn=w.default.v3,ge=w.default.v4,cn=w.default.v5,pn=w.default.NIL,yn=w.default.version,gn=w.default.validate,mn=w.default.stringify,hn=w.default.parse;function me(e){return[...new Uint8Array(e)].map(t=>t.toString(16).padStart(2,"0")).join("")}function je(e){return new Uint8Array((e.match(/../g)??[]).map(t=>parseInt(t,16)))}function ze(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 tt=Te(et());function _e(e,t){if((0,tt.validate)(e,t).length)throw new Error(`couldn't validate schema: ${JSON.stringify(t)} didn't match schema ${JSON.stringify(e)}`)}var rt="3",ot="https://webapp-production-dot-remarkable-production.appspot.com",Ur="https://rm-blob-storage-prod.appspot.com",nt="x-goog-generation",Lr="x-goog-if-generation-match",Br=["Ballpoint","Ballpointv2","Brush","Calligraphy","ClearPage","EraseSection","Eraser","Fineliner","Finelinerv2","Highlighter","Highlighterv2","Marker","Markerv2","Paintbrush","Paintbrushv2","Pencilv2","SharpPencil","SharpPencilv2","SolidPen","ZoomTool"],Nr=["Maison Neue","EB Garamond","Noto Sans","Noto Serif","Noto Mono","Noto Sans UI"],at={xs:.7,sm:.8,md:1,lg:1.2,xl:1.5,xx:2},ft={sm:50,md:125,rr:180,lg:200},ut={df:-1,md:100,lg:150,xl:200},Cr={properties:{relative_path:{type:"string"},url:{type:"string"},expires:{type:"timestamp"},method:{enum:["POST","GET","PUT","DELETE"]}}},it={visibleName:{type:"string"},parent:{type:"string"},lastModified:{type:"string"},version:{type:"int32"},synced:{type:"boolean"}},st={pinned:{type:"boolean"},modified:{type:"boolean"},deleted:{type:"boolean"},metadatamodified:{type:"boolean"}},$r={discriminator:"type",mapping:{CollectionType:{properties:it,optionalProperties:st},DocumentType:{properties:it,optionalProperties:{...st,lastOpened:{type:"string"},lastOpenedPage:{type:"int32"}}}}},q=class extends Error{constructor(r,i,n){super(n);this.status=r,this.statusText=i}},C=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 Hr(e,{deviceDesc:t="desktop-linux",uuid:r=ge(),authUrl:i=ot,fetch:n=globalThis.fetch}={}){if(e.length!==8)throw new Error(`code should be length 8, but was ${e.length}`);let s=await n(`${i}/token/json/2/device/new`,{method:"POST",headers:{Authorization:"Bearer"},body:JSON.stringify({code:e,deviceDesc:t,deviceID:r})});if(s.ok)return await s.text();throw new q(s.status,s.statusText,"couldn't register api")}function jr({hash:e,type:t,documentId:r,subfiles:i,size:n}){return`${e}:${t}:${r}:${i}:${n}
|
|
2
|
+
`}function zr(e){let[t,r,i,n,s]=e.split(":");if(t===void 0||r===void 0||i===void 0||n===void 0||s===void 0)throw new Error(`entries line didn't contain five fields: '${e}'`);if(r==="80000000"){if(s!=="0")throw new Error(`collection type entry had nonzero size: ${s}`);return{hash:t,type:r,documentId:i,subfiles:parseInt(n),size:0n}}else 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(s)}}else throw new Error(`entries line contained invalid type: ${r}`)}var xe=class{constructor(t,r,i,n,s){this.userToken=t;this.fetch=r;this.cache=i;this.subtle=n;this.blobUrl=s}async authedFetch(t,r,i="POST"){let n=await this.fetch(t,{method:i,headers:{Authorization:`Bearer ${this.userToken}`},body:r&&JSON.stringify(r)});if(n.ok)return n;throw new q(n.status,n.statusText,"failed reMarkable request")}async signedFetch({url:t,method:r},i,n){let s=await this.fetch(t,{method:r,body:i,headers:n});if(s.ok)return s;{let o=await s.text();throw new q(s.status,s.statusText,o)}}async getUrl(t,r){let i=r===void 0?"downloads":"uploads",n=r==null?void 0:`${r}`,o=await(await this.authedFetch(`${this.blobUrl}/api/v1/signed-urls/${i}`,{http_method:n===void 0?"GET":"PUT",relative_path:t,generation:n})).text(),a=JSON.parse(o);return _e(Cr,a),a}async syncComplete(){await this.authedFetch(`${this.blobUrl}/api/v1/sync-complete`)}async getRootHash(){let t=await this.getUrl("root"),r=await this.signedFetch(t),i=r.headers.get(nt);if(!i)throw new Error("no generation header in root hash");return[await r.text(),BigInt(i)]}async putRootHash(t,r){let i=await this.getUrl("root",r),n;try{n=await this.signedFetch(i,t,{[Lr]:`${r}`})}catch(o){throw o instanceof q&&o.status===412?new C:o}let s=n.headers.get(nt);if(!s)throw new Error("no generation header in root hash");return BigInt(s)}async getBuffer(t){let r=await this.getUrl(t);return await(await this.signedFetch(r)).arrayBuffer()}async getText(t){let r=this.cache&&await this.cache.get(t);if(r)return r;{let i=await this.getUrl(t),s=await(await this.signedFetch(i)).text();return this.cache&&await this.cache.set(t,s),s}}async getMetadata(t){let r=await this.getText(t),i=JSON.parse(r);return _e($r,i),i}async getEntries(t){let r=await this.getText(t),[i,...n]=r.slice(0,-1).split(`
|
|
3
|
+
`);if(i!==rt)throw new Error(`got unexpected schema version: ${i}`);return n.map(zr)}async putHash(t,r){let i=await this.getUrl(t,null);await this.signedFetch(i,r)}async putEntries(t,r){let i=new TextEncoder;r.sort((p,b)=>p.documentId.localeCompare(b.documentId));let n=ze(r.map(p=>je(p.hash))),s=await this.subtle.digest("SHA-256",n),o=me(s),a=r.map(jr).join(""),f=`${rt}
|
|
4
|
+
${a}`,c=i.encode(f);return await this.putHash(o,c),this.cache&&await this.cache.set(o,f),{hash:o,type:"80000000",documentId:t,subfiles:r.length,size:0n}}async putBuffer(t,r){let i=await this.subtle.digest("SHA-256",r),n=me(i);return await this.putHash(n,r),{hash:n,type:"0",documentId:t,subfiles:0,size:BigInt(r.length)}}async putText(t,r){let i=new TextEncoder,n=await this.putBuffer(t,i.encode(r));return this.cache&&await this.cache.set(n.hash,r),n}async putEpub(t,r,{parent:i="",margins:n=125,orientation:s,textAlignment:o,textScale:a=1,lineHeight:f=-1,fontName:c="",cover:p="visited",lastTool:b,notify:l=!0,retries:I=3}={}){let _=ge(),se=`${new Date().valueOf()}`,D=[];D.push(this.putBuffer(`${_}.epub`,r));let L={type:"DocumentType",visibleName:t,version:0,parent:i,synced:!0,lastModified:se};D.push(this.putText(`${_}.metadata`,JSON.stringify(L)));let v={dummyDocument:!1,extraMetadata:{LastTool:b},fileType:"epub",pageCount:0,lastOpenedPage:0,lineHeight:typeof f=="string"?ut[f]:f,margins:typeof n=="string"?ft[n]:n,textScale:typeof a=="string"?at[a]:a,pages:[],coverPageNumber:p==="first"?0:-1,formatVersion:1,orientation:s,textAlignment:o,fontName:c};D.push(this.putText(`${_}.content`,JSON.stringify(v)));let oe=await Promise.all(D),ae=await this.putEntries(_,oe);for(;;--I)try{let[$,lt]=await this.getRootHash(),we=await this.getEntries($);we.push(ae);let{hash:dt}=await this.putEntries("",we);await this.putRootHash(dt,lt);break}catch($){if(I<=0||!($ instanceof C))throw $}l&&await this.syncComplete()}};async function Jr(e,{fetch:t=globalThis.fetch,cache:r,subtle:i=globalThis.crypto?.subtle,authUrl:n=ot,blobUrl:s=Ur}={}){let o=await t(`${n}/token/json/2/user/new`,{method:"POST",headers:{Authorization:`Bearer ${e}`}});if(!o.ok)throw new Error(`couldn't fetch auth token: ${o.statusText}`);let a=await o.text();return new xe(a,t,r,i,s)}0&&(module.exports={GenerationError,ResponseError,builtinFontNames,builtinLineHeights,builtinMargins,builtinTextScales,builtinTools,register,remarkable});
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
var Ce=Object.create;var ue=Object.defineProperty;var Le=Object.getOwnPropertyDescriptor;var je=Object.getOwnPropertyNames;var De=Object.getPrototypeOf,Ne=Object.prototype.hasOwnProperty;var q=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports);var $e=(e,r,t,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of je(r))!Ne.call(e,n)&&n!==t&&ue(e,n,{get:()=>r[n],enumerable:!(i=Le(r,n))||i.enumerable});return e};var He=(e,r,t)=>(t=e!=null?Ce(De(e)):{},$e(r||!e||!e.__esModule?ue(t,"default",{value:e,enumerable:!0}):t,e));var oe=q(l=>{"use strict";var ye=l&&l.__rest||function(e,r){var t={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&r.indexOf(i)<0&&(t[i]=e[i]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var n=0,i=Object.getOwnPropertySymbols(e);n<i.length;n++)r.indexOf(i[n])<0&&Object.prototype.propertyIsEnumerable.call(e,i[n])&&(t[i[n]]=e[i[n]]);return t};Object.defineProperty(l,"__esModule",{value:!0});l.isSchema=l.isValidSchema=l.isDiscriminatorForm=l.isValuesForm=l.isPropertiesForm=l.isElementsForm=l.isEnumForm=l.isTypeForm=l.isRefForm=l.isEmptyForm=void 0;function rt(e){let{definitions:r,nullable:t,metadata:i}=e,n=ye(e,["definitions","nullable","metadata"]);return Object.keys(n).length===0}l.isEmptyForm=rt;function ve(e){return"ref"in e}l.isRefForm=ve;function nt(e){return"type"in e}l.isTypeForm=nt;function be(e){return"enum"in e}l.isEnumForm=be;function xe(e){return"elements"in e}l.isElementsForm=xe;function ie(e){return"properties"in e||"optionalProperties"in e}l.isPropertiesForm=ie;function we(e){return"values"in e}l.isValuesForm=we;function Te(e){return"discriminator"in e}l.isDiscriminatorForm=Te;function C(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(!C(t,r))return!1}if(ve(e)&&!(e.ref in(r.definitions||{}))||be(e)&&(e.enum.length===0||e.enum.length!==new Set(e.enum).size))return!1;if(xe(e))return C(e.elements,r);if(ie(e)){for(let t of Object.values(e.properties||{}))if(!C(t,r))return!1;for(let t of Object.values(e.optionalProperties||{}))if(!C(t,r))return!1;for(let t of Object.keys(e.properties||{}))if(t in(e.optionalProperties||{}))return!1}if(we(e))return C(e.values,r);if(Te(e)){for(let t of Object.values(e.mapping))if(!C(t,r)||!ie(t)||t.nullable||e.discriminator in(t.properties||{})||e.discriminator in(t.optionalProperties||{}))return!1}return!0}l.isValidSchema=C;var it=[[!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]],ot=["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 r=e,{definitions:t=void 0,nullable:i=void 0,metadata:n=void 0,ref:o=void 0,type:s=void 0,enum:f=void 0,elements:a=void 0,properties:d=void 0,optionalProperties:u=void 0,additionalProperties:E=void 0,values:T=void 0,discriminator:P=void 0,mapping:p=void 0}=r,S=ye(r,["definitions","nullable","metadata","ref","type","enum","elements","properties","optionalProperties","additionalProperties","values","discriminator","mapping"]),A=[o!==void 0,s!==void 0,f!==void 0,a!==void 0,d!==void 0,u!==void 0,E!==void 0,T!==void 0,P!==void 0,p!==void 0],k=!1;for(let c of it)k=k||c.every((U,O)=>U===A[O]);if(!k)return!1;if(t!==void 0){if(typeof t!="object"||Array.isArray(t)||t===null)return!1;for(let c of Object.values(t))if(!L(c))return!1}if(i!==void 0&&typeof i!="boolean"||n!==void 0&&(typeof n!="object"||Array.isArray(n)||n===null)||o!==void 0&&typeof o!="string"||s!==void 0&&(typeof s!="string"||!ot.includes(s))||f!==void 0&&(!Array.isArray(f)||!f.every(c=>typeof c=="string"))||a!==void 0&&!L(a))return!1;if(d!==void 0){if(typeof d!="object"||Array.isArray(d)||d===null)return!1;for(let c of Object.values(d))if(!L(c))return!1}if(u!==void 0){if(typeof u!="object"||Array.isArray(u)||u===null)return!1;for(let c of Object.values(u))if(!L(c))return!1}if(E!==void 0&&typeof E!="boolean"||T!==void 0&&!L(T)||P!==void 0&&typeof P!="string")return!1;if(p!==void 0){if(typeof p!="object"||Array.isArray(p)||p===null)return!1;for(let c of Object.values(p))if(!L(c))return!1}return Object.keys(S).length===0}l.isSchema=L});var Ee=q(se=>{"use strict";Object.defineProperty(se,"__esModule",{value:!0});var st=/^(\d{4})-(\d{2})-(\d{2})[tT](\d{2}):(\d{2}):(\d{2})(\.\d+)?([zZ]|((\+|-)(\d{2}):(\d{2})))$/;function at(e){let r=e.match(st);if(r===null)return!1;let t=parseInt(r[1],10),i=parseInt(r[2],10),n=parseInt(r[3],10),o=parseInt(r[4],10),s=parseInt(r[5],10),f=parseInt(r[6],10);return!(i>12||n>ft(t,i)||o>23||s>59||f>60)}se.default=at;function ft(e,r){return r===2?lt(e)?29:28:ut[r]}function lt(e){return e%4===0&&(e%100!==0||e%400===0)}var ut=[0,31,0,31,30,31,30,31,31,30,31,30,31]});var Pe=q(F=>{"use strict";var dt=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 pt=dt(Ee()),j=oe(),X=class extends Error{};F.MaxDepthExceededError=X;var Q=class extends Error{};function ct(e,r,t){let i={errors:[],instanceTokens:[],schemaTokens:[[]],root:e,config:t||{maxDepth:0,maxErrors:0}};try{$(i,e,r)}catch(n){if(!(n instanceof Q))throw n}return i.errors}F.validate=ct;function $(e,r,t,i){if(!(r.nullable&&t===null)){if(j.isRefForm(r)){if(e.schemaTokens.length===e.config.maxDepth)throw new X;e.schemaTokens.push(["definitions",r.ref]),$(e,e.root.definitions[r.ref],t),e.schemaTokens.pop()}else if(j.isTypeForm(r)){switch(b(e,"type"),r.type){case"boolean":typeof t!="boolean"&&x(e);break;case"float32":case"float64":typeof t!="number"&&x(e);break;case"int8":B(e,t,-128,127);break;case"uint8":B(e,t,0,255);break;case"int16":B(e,t,-32768,32767);break;case"uint16":B(e,t,0,65535);break;case"int32":B(e,t,-2147483648,2147483647);break;case"uint32":B(e,t,0,4294967295);break;case"string":typeof t!="string"&&x(e);break;case"timestamp":typeof t!="string"?x(e):pt.default(t)||x(e);break}w(e)}else if(j.isEnumForm(r))b(e,"enum"),(typeof t!="string"||!r.enum.includes(t))&&x(e),w(e);else if(j.isElementsForm(r)){if(b(e,"elements"),Array.isArray(t))for(let[n,o]of t.entries())D(e,n.toString()),$(e,r.elements,o),N(e);else x(e);w(e)}else if(j.isPropertiesForm(r))if(typeof t=="object"&&t!==null&&!Array.isArray(t)){if(r.properties!==void 0){b(e,"properties");for(let[n,o]of Object.entries(r.properties))b(e,n),t.hasOwnProperty(n)?(D(e,n),$(e,o,t[n]),N(e)):x(e),w(e);w(e)}if(r.optionalProperties!==void 0){b(e,"optionalProperties");for(let[n,o]of Object.entries(r.optionalProperties))b(e,n),t.hasOwnProperty(n)&&(D(e,n),$(e,o,t[n]),N(e)),w(e);w(e)}if(r.additionalProperties!==!0)for(let n of Object.keys(t)){let o=r.properties&&n in r.properties,s=r.optionalProperties&&n in r.optionalProperties;!o&&!s&&n!==i&&(D(e,n),x(e),N(e))}}else r.properties!==void 0?b(e,"properties"):b(e,"optionalProperties"),x(e),w(e);else if(j.isValuesForm(r)){if(b(e,"values"),typeof t=="object"&&t!==null&&!Array.isArray(t))for(let[n,o]of Object.entries(t))D(e,n),$(e,r.values,o),N(e);else x(e);w(e)}else if(j.isDiscriminatorForm(r))if(typeof t=="object"&&t!==null&&!Array.isArray(t))if(t.hasOwnProperty(r.discriminator)){let n=t[r.discriminator];typeof n=="string"?n in r.mapping?(b(e,"mapping"),b(e,n),$(e,r.mapping[n],t,r.discriminator),w(e),w(e)):(b(e,"mapping"),D(e,r.discriminator),x(e),N(e),w(e)):(b(e,"discriminator"),D(e,r.discriminator),x(e),N(e),w(e))}else b(e,"discriminator"),x(e),w(e);else b(e,"discriminator"),x(e),w(e)}}function B(e,r,t,i){(typeof r!="number"||!Number.isInteger(r)||r<t||r>i)&&x(e)}function D(e,r){e.instanceTokens.push(r)}function N(e){e.instanceTokens.pop()}function b(e,r){e.schemaTokens[e.schemaTokens.length-1].push(r)}function w(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 Q}});var ke=q(I=>{"use strict";var mt=I&&I.__createBinding||(Object.create?function(e,r,t,i){i===void 0&&(i=t),Object.defineProperty(e,i,{enumerable:!0,get:function(){return r[t]}})}:function(e,r,t,i){i===void 0&&(i=t),e[i]=r[t]}),Ae=I&&I.__exportStar||function(e,r){for(var t in e)t!=="default"&&!r.hasOwnProperty(t)&&mt(r,e,t)};Object.defineProperty(I,"__esModule",{value:!0});Ae(oe(),I);Ae(Pe(),I)});var J,_e=new Uint8Array(16);function z(){if(!J&&(J=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||typeof msCrypto<"u"&&typeof msCrypto.getRandomValues=="function"&&msCrypto.getRandomValues.bind(msCrypto),!J))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return J(_e)}var de=/^(?:[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 Be(e){return typeof e=="string"&&de.test(e)}var H=Be;var m=[];for(G=0;G<256;++G)m.push((G+256).toString(16).substr(1));var G;function Ve(e){var r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,t=(m[e[r+0]]+m[e[r+1]]+m[e[r+2]]+m[e[r+3]]+"-"+m[e[r+4]]+m[e[r+5]]+"-"+m[e[r+6]]+m[e[r+7]]+"-"+m[e[r+8]]+m[e[r+9]]+"-"+m[e[r+10]]+m[e[r+11]]+m[e[r+12]]+m[e[r+13]]+m[e[r+14]]+m[e[r+15]]).toLowerCase();if(!H(t))throw TypeError("Stringified UUID is invalid");return t}var _=Ve;function qe(e){if(!H(e))throw TypeError("Invalid UUID");var 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 te=qe;function Je(e){e=unescape(encodeURIComponent(e));for(var r=[],t=0;t<e.length;++t)r.push(e.charCodeAt(t));return r}var ze="6ba7b810-9dad-11d1-80b4-00c04fd430c8",Ge="6ba7b811-9dad-11d1-80b4-00c04fd430c8";function Y(e,r,t){function i(n,o,s,f){if(typeof n=="string"&&(n=Je(n)),typeof o=="string"&&(o=te(o)),o.length!==16)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");var a=new Uint8Array(16+n.length);if(a.set(o),a.set(n,o.length),a=t(a),a[6]=a[6]&15|r,a[8]=a[8]&63|128,s){f=f||0;for(var d=0;d<16;++d)s[f+d]=a[d];return s}return _(a)}try{i.name=e}catch{}return i.DNS=ze,i.URL=Ge,i}function Ye(e){if(typeof e=="string"){var r=unescape(encodeURIComponent(e));e=new Uint8Array(r.length);for(var t=0;t<r.length;++t)e[t]=r.charCodeAt(t)}return Ze(Ke(Xe(e),e.length*8))}function Ze(e){for(var r=[],t=e.length*32,i="0123456789abcdef",n=0;n<t;n+=8){var o=e[n>>5]>>>n%32&255,s=parseInt(i.charAt(o>>>4&15)+i.charAt(o&15),16);r.push(s)}return r}function pe(e){return(e+64>>>9<<4)+14+1}function Ke(e,r){e[r>>5]|=128<<r%32,e[pe(r)-1]=r;for(var t=1732584193,i=-271733879,n=-1732584194,o=271733878,s=0;s<e.length;s+=16){var f=t,a=i,d=n,u=o;t=g(t,i,n,o,e[s],7,-680876936),o=g(o,t,i,n,e[s+1],12,-389564586),n=g(n,o,t,i,e[s+2],17,606105819),i=g(i,n,o,t,e[s+3],22,-1044525330),t=g(t,i,n,o,e[s+4],7,-176418897),o=g(o,t,i,n,e[s+5],12,1200080426),n=g(n,o,t,i,e[s+6],17,-1473231341),i=g(i,n,o,t,e[s+7],22,-45705983),t=g(t,i,n,o,e[s+8],7,1770035416),o=g(o,t,i,n,e[s+9],12,-1958414417),n=g(n,o,t,i,e[s+10],17,-42063),i=g(i,n,o,t,e[s+11],22,-1990404162),t=g(t,i,n,o,e[s+12],7,1804603682),o=g(o,t,i,n,e[s+13],12,-40341101),n=g(n,o,t,i,e[s+14],17,-1502002290),i=g(i,n,o,t,e[s+15],22,1236535329),t=h(t,i,n,o,e[s+1],5,-165796510),o=h(o,t,i,n,e[s+6],9,-1069501632),n=h(n,o,t,i,e[s+11],14,643717713),i=h(i,n,o,t,e[s],20,-373897302),t=h(t,i,n,o,e[s+5],5,-701558691),o=h(o,t,i,n,e[s+10],9,38016083),n=h(n,o,t,i,e[s+15],14,-660478335),i=h(i,n,o,t,e[s+4],20,-405537848),t=h(t,i,n,o,e[s+9],5,568446438),o=h(o,t,i,n,e[s+14],9,-1019803690),n=h(n,o,t,i,e[s+3],14,-187363961),i=h(i,n,o,t,e[s+8],20,1163531501),t=h(t,i,n,o,e[s+13],5,-1444681467),o=h(o,t,i,n,e[s+2],9,-51403784),n=h(n,o,t,i,e[s+7],14,1735328473),i=h(i,n,o,t,e[s+12],20,-1926607734),t=y(t,i,n,o,e[s+5],4,-378558),o=y(o,t,i,n,e[s+8],11,-2022574463),n=y(n,o,t,i,e[s+11],16,1839030562),i=y(i,n,o,t,e[s+14],23,-35309556),t=y(t,i,n,o,e[s+1],4,-1530992060),o=y(o,t,i,n,e[s+4],11,1272893353),n=y(n,o,t,i,e[s+7],16,-155497632),i=y(i,n,o,t,e[s+10],23,-1094730640),t=y(t,i,n,o,e[s+13],4,681279174),o=y(o,t,i,n,e[s],11,-358537222),n=y(n,o,t,i,e[s+3],16,-722521979),i=y(i,n,o,t,e[s+6],23,76029189),t=y(t,i,n,o,e[s+9],4,-640364487),o=y(o,t,i,n,e[s+12],11,-421815835),n=y(n,o,t,i,e[s+15],16,530742520),i=y(i,n,o,t,e[s+2],23,-995338651),t=v(t,i,n,o,e[s],6,-198630844),o=v(o,t,i,n,e[s+7],10,1126891415),n=v(n,o,t,i,e[s+14],15,-1416354905),i=v(i,n,o,t,e[s+5],21,-57434055),t=v(t,i,n,o,e[s+12],6,1700485571),o=v(o,t,i,n,e[s+3],10,-1894986606),n=v(n,o,t,i,e[s+10],15,-1051523),i=v(i,n,o,t,e[s+1],21,-2054922799),t=v(t,i,n,o,e[s+8],6,1873313359),o=v(o,t,i,n,e[s+15],10,-30611744),n=v(n,o,t,i,e[s+6],15,-1560198380),i=v(i,n,o,t,e[s+13],21,1309151649),t=v(t,i,n,o,e[s+4],6,-145523070),o=v(o,t,i,n,e[s+11],10,-1120210379),n=v(n,o,t,i,e[s+2],15,718787259),i=v(i,n,o,t,e[s+9],21,-343485551),t=R(t,f),i=R(i,a),n=R(n,d),o=R(o,u)}return[t,i,n,o]}function Xe(e){if(e.length===0)return[];for(var r=e.length*8,t=new Uint32Array(pe(r)),i=0;i<r;i+=8)t[i>>5]|=(e[i/8]&255)<<i%32;return t}function R(e,r){var t=(e&65535)+(r&65535),i=(e>>16)+(r>>16)+(t>>16);return i<<16|t&65535}function Qe(e,r){return e<<r|e>>>32-r}function Z(e,r,t,i,n,o){return R(Qe(R(R(r,e),R(i,o)),n),t)}function g(e,r,t,i,n,o,s){return Z(r&t|~r&i,e,r,n,o,s)}function h(e,r,t,i,n,o,s){return Z(r&i|t&~i,e,r,n,o,s)}function y(e,r,t,i,n,o,s){return Z(r^t^i,e,r,n,o,s)}function v(e,r,t,i,n,o,s){return Z(t^(r|~i),e,r,n,o,s)}var ce=Ye;var Bt=Y("v3",48,ce);function We(e,r,t){e=e||{};var i=e.random||(e.rng||z)();if(i[6]=i[6]&15|64,i[8]=i[8]&63|128,r){t=t||0;for(var n=0;n<16;++n)r[t+n]=i[n];return r}return _(i)}var K=We;function et(e,r,t,i){switch(e){case 0:return r&t^~r&i;case 1:return r^t^i;case 2:return r&t^r&i^t&i;case 3:return r^t^i}}function re(e,r){return e<<r|e>>>32-r}function tt(e){var r=[1518500249,1859775393,2400959708,3395469782],t=[1732584193,4023233417,2562383102,271733878,3285377520];if(typeof e=="string"){var i=unescape(encodeURIComponent(e));e=[];for(var n=0;n<i.length;++n)e.push(i.charCodeAt(n))}else Array.isArray(e)||(e=Array.prototype.slice.call(e));e.push(128);for(var o=e.length/4+2,s=Math.ceil(o/16),f=new Array(s),a=0;a<s;++a){for(var d=new Uint32Array(16),u=0;u<16;++u)d[u]=e[a*64+u*4]<<24|e[a*64+u*4+1]<<16|e[a*64+u*4+2]<<8|e[a*64+u*4+3];f[a]=d}f[s-1][14]=(e.length-1)*8/Math.pow(2,32),f[s-1][14]=Math.floor(f[s-1][14]),f[s-1][15]=(e.length-1)*8&4294967295;for(var E=0;E<s;++E){for(var T=new Uint32Array(80),P=0;P<16;++P)T[P]=f[E][P];for(var p=16;p<80;++p)T[p]=re(T[p-3]^T[p-8]^T[p-14]^T[p-16],1);for(var S=t[0],A=t[1],k=t[2],c=t[3],U=t[4],O=0;O<80;++O){var M=Math.floor(O/20),ee=re(S,5)+et(M,A,k,c)+U+r[M]+T[O]>>>0;U=c,c=k,k=re(A,30)>>>0,A=S,S=ee}t[0]=t[0]+S>>>0,t[1]=t[1]+A>>>0,t[2]=t[2]+k>>>0,t[3]=t[3]+c>>>0,t[4]=t[4]+U>>>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 me=tt;var Kt=Y("v5",80,me);function ne(e){return[...new Uint8Array(e)].map(r=>r.toString(16).padStart(2,"0")).join("")}function ge(e){return new Uint8Array((e.match(/../g)??[]).map(r=>parseInt(r,16)))}function he(e){let r=0;for(let n of e)r+=n.length;let t=new Uint8Array(r),i=0;for(let n of e)t.set(n,i),i+=n.length;return t}var Se=He(ke());function ae(e,r){if((0,Se.validate)(e,r).length)throw new Error(`couldn't validate schema: ${JSON.stringify(r)} didn't match schema ${JSON.stringify(e)}`)}var Oe="3",Ue="https://webapp-production-dot-remarkable-production.appspot.com",gt="https://rm-blob-storage-prod.appspot.com",Re="x-goog-generation",ht="x-goog-if-generation-match",kr=["Ballpoint","Ballpointv2","Brush","Calligraphy","ClearPage","EraseSection","Eraser","Fineliner","Finelinerv2","Highlighter","Highlighterv2","Marker","Markerv2","Paintbrush","Paintbrushv2","Pencilv2","SharpPencil","SharpPencilv2","SolidPen","ZoomTool"],Sr=["Maison Neue","EB Garamond","Noto Sans","Noto Serif","Noto Mono","Noto Sans UI"],yt={xs:.7,sm:.8,md:1,lg:1.2,xl:1.5,xx:2},vt={sm:50,md:125,rr:180,lg:200},bt={df:-1,md:100,lg:150,xl:200},xt={properties:{relative_path:{type:"string"},url:{type:"string"},expires:{type:"timestamp"},method:{enum:["POST","GET","PUT","DELETE"]}}},Fe={visibleName:{type:"string"},parent:{type:"string"},lastModified:{type:"string"},version:{type:"int32"},synced:{type:"boolean"}},Ie={pinned:{type:"boolean"},modified:{type:"boolean"},deleted:{type:"boolean"},metadatamodified:{type:"boolean"}},wt={discriminator:"type",mapping:{CollectionType:{properties:Fe,optionalProperties:Ie},DocumentType:{properties:Fe,optionalProperties:{...Ie,lastOpened:{type:"string"},lastOpenedPage:{type:"int32"}}}}},V=class extends Error{constructor(t,i,n){super(n);this.status=t,this.statusText=i}},W=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 Or(e,{deviceDesc:r="desktop-linux",uuid:t=K(),authUrl:i=Ue,fetch:n=globalThis.fetch}={}){if(e.length!==8)throw new Error(`code should be length 8, but was ${e.length}`);let o=await n(`${i}/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 V(o.status,o.statusText,"couldn't register api")}function Tt({hash:e,type:r,documentId:t,subfiles:i,size:n}){return`${e}:${r}:${t}:${i}:${n}
|
|
2
|
+
`}function Et(e){let[r,t,i,n,o]=e.split(":");if(r===void 0||t===void 0||i===void 0||n===void 0||o===void 0)throw new Error(`entries line didn't contain five fields: '${e}'`);if(t==="80000000"){if(o!=="0")throw new Error(`collection type entry had nonzero size: ${o}`);return{hash:r,type:t,documentId:i,subfiles:parseInt(n),size:0n}}else if(t==="0"){if(n!=="0")throw new Error(`file type entry had nonzero number of subfiles: ${n}`);return{hash:r,type:t,documentId:i,subfiles:0,size:BigInt(o)}}else throw new Error(`entries line contained invalid type: ${t}`)}var fe=class{constructor(r,t,i,n,o){this.userToken=r;this.fetch=t;this.cache=i;this.subtle=n;this.blobUrl=o}async authedFetch(r,t,i="POST"){let n=await this.fetch(r,{method:i,headers:{Authorization:`Bearer ${this.userToken}`},body:t&&JSON.stringify(t)});if(n.ok)return n;throw new V(n.status,n.statusText,"failed reMarkable request")}async signedFetch({url:r,method:t},i,n){let o=await this.fetch(r,{method:t,body:i,headers:n});if(o.ok)return o;{let s=await o.text();throw new V(o.status,o.statusText,s)}}async getUrl(r,t){let i=t===void 0?"downloads":"uploads",n=t==null?void 0:`${t}`,s=await(await this.authedFetch(`${this.blobUrl}/api/v1/signed-urls/${i}`,{http_method:n===void 0?"GET":"PUT",relative_path:r,generation:n})).text(),f=JSON.parse(s);return ae(xt,f),f}async syncComplete(){await this.authedFetch(`${this.blobUrl}/api/v1/sync-complete`)}async getRootHash(){let r=await this.getUrl("root"),t=await this.signedFetch(r),i=t.headers.get(Re);if(!i)throw new Error("no generation header in root hash");return[await t.text(),BigInt(i)]}async putRootHash(r,t){let i=await this.getUrl("root",t),n;try{n=await this.signedFetch(i,r,{[ht]:`${t}`})}catch(s){throw s instanceof V&&s.status===412?new W:s}let o=n.headers.get(Re);if(!o)throw new Error("no generation header in root hash");return BigInt(o)}async getBuffer(r){let t=await this.getUrl(r);return await(await this.signedFetch(t)).arrayBuffer()}async getText(r){let t=this.cache&&await this.cache.get(r);if(t)return t;{let i=await this.getUrl(r),o=await(await this.signedFetch(i)).text();return this.cache&&await this.cache.set(r,o),o}}async getMetadata(r){let t=await this.getText(r),i=JSON.parse(t);return ae(wt,i),i}async getEntries(r){let t=await this.getText(r),[i,...n]=t.slice(0,-1).split(`
|
|
3
|
+
`);if(i!==Oe)throw new Error(`got unexpected schema version: ${i}`);return n.map(Et)}async putHash(r,t){let i=await this.getUrl(r,null);await this.signedFetch(i,t)}async putEntries(r,t){let i=new TextEncoder;t.sort((u,E)=>u.documentId.localeCompare(E.documentId));let n=he(t.map(u=>ge(u.hash))),o=await this.subtle.digest("SHA-256",n),s=ne(o),f=t.map(Tt).join(""),a=`${Oe}
|
|
4
|
+
${f}`,d=i.encode(a);return await this.putHash(s,d),this.cache&&await this.cache.set(s,a),{hash:s,type:"80000000",documentId:r,subfiles:t.length,size:0n}}async putBuffer(r,t){let i=await this.subtle.digest("SHA-256",t),n=ne(i);return await this.putHash(n,t),{hash:n,type:"0",documentId:r,subfiles:0,size:BigInt(t.length)}}async putText(r,t){let i=new TextEncoder,n=await this.putBuffer(r,i.encode(t));return this.cache&&await this.cache.set(n.hash,t),n}async putEpub(r,t,{parent:i="",margins:n=125,orientation:o,textAlignment:s,textScale:f=1,lineHeight:a=-1,fontName:d="",cover:u="visited",lastTool:E,notify:T=!0,retries:P=3}={}){let p=K(),S=`${new Date().valueOf()}`,A=[];A.push(this.putBuffer(`${p}.epub`,t));let k={type:"DocumentType",visibleName:r,version:0,parent:i,synced:!0,lastModified:S};A.push(this.putText(`${p}.metadata`,JSON.stringify(k)));let c={dummyDocument:!1,extraMetadata:{LastTool:E},fileType:"epub",pageCount:0,lastOpenedPage:0,lineHeight:typeof a=="string"?bt[a]:a,margins:typeof n=="string"?vt[n]:n,textScale:typeof f=="string"?yt[f]:f,pages:[],coverPageNumber:u==="first"?0:-1,formatVersion:1,orientation:o,textAlignment:s,fontName:d};A.push(this.putText(`${p}.content`,JSON.stringify(c)));let U=await Promise.all(A),O=await this.putEntries(p,U);for(;;--P)try{let[M,ee]=await this.getRootHash(),le=await this.getEntries(M);le.push(O);let{hash:Me}=await this.putEntries("",le);await this.putRootHash(Me,ee);break}catch(M){if(P<=0||!(M instanceof W))throw M}T&&await this.syncComplete()}};async function Rr(e,{fetch:r=globalThis.fetch,cache:t,subtle:i=globalThis.crypto?.subtle,authUrl:n=Ue,blobUrl:o=gt}={}){let s=await r(`${n}/token/json/2/user/new`,{method:"POST",headers:{Authorization:`Bearer ${e}`}});if(!s.ok)throw new Error(`couldn't fetch auth token: ${s.statusText}`);let f=await s.text();return new fe(f,r,t,i,o)}export{W as GenerationError,V as ResponseError,Sr as builtinFontNames,bt as builtinLineHeights,vt as builtinMargins,yt as builtinTextScales,kr as builtinTools,Or as register,Rr as remarkable};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
var rmapi=(()=>{var Ne=Object.create;var J=Object.defineProperty;var $e=Object.getOwnPropertyDescriptor;var He=Object.getOwnPropertyNames;var _e=Object.getPrototypeOf,Be=Object.prototype.hasOwnProperty;var z=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports),Ve=(e,r)=>{for(var t in r)J(e,t,{get:r[t],enumerable:!0})},de=(e,r,t,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of He(r))!Be.call(e,n)&&n!==t&&J(e,n,{get:()=>r[n],enumerable:!(i=$e(r,n))||i.enumerable});return e};var qe=(e,r,t)=>(t=e!=null?Ne(_e(e)):{},de(r||!e||!e.__esModule?J(t,"default",{value:e,enumerable:!0}):t,e)),Je=e=>de(J({},"__esModule",{value:!0}),e);var se=z(l=>{"use strict";var ve=l&&l.__rest||function(e,r){var t={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&r.indexOf(i)<0&&(t[i]=e[i]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var n=0,i=Object.getOwnPropertySymbols(e);n<i.length;n++)r.indexOf(i[n])<0&&Object.prototype.propertyIsEnumerable.call(e,i[n])&&(t[i[n]]=e[i[n]]);return t};Object.defineProperty(l,"__esModule",{value:!0});l.isSchema=l.isValidSchema=l.isDiscriminatorForm=l.isValuesForm=l.isPropertiesForm=l.isElementsForm=l.isEnumForm=l.isTypeForm=l.isRefForm=l.isEmptyForm=void 0;function at(e){let{definitions:r,nullable:t,metadata:i}=e,n=ve(e,["definitions","nullable","metadata"]);return Object.keys(n).length===0}l.isEmptyForm=at;function be(e){return"ref"in e}l.isRefForm=be;function ft(e){return"type"in e}l.isTypeForm=ft;function xe(e){return"enum"in e}l.isEnumForm=xe;function we(e){return"elements"in e}l.isElementsForm=we;function oe(e){return"properties"in e||"optionalProperties"in e}l.isPropertiesForm=oe;function Te(e){return"values"in e}l.isValuesForm=Te;function Ee(e){return"discriminator"in e}l.isDiscriminatorForm=Ee;function C(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(!C(t,r))return!1}if(be(e)&&!(e.ref in(r.definitions||{}))||xe(e)&&(e.enum.length===0||e.enum.length!==new Set(e.enum).size))return!1;if(we(e))return C(e.elements,r);if(oe(e)){for(let t of Object.values(e.properties||{}))if(!C(t,r))return!1;for(let t of Object.values(e.optionalProperties||{}))if(!C(t,r))return!1;for(let t of Object.keys(e.properties||{}))if(t in(e.optionalProperties||{}))return!1}if(Te(e))return C(e.values,r);if(Ee(e)){for(let t of Object.values(e.mapping))if(!C(t,r)||!oe(t)||t.nullable||e.discriminator in(t.properties||{})||e.discriminator in(t.optionalProperties||{}))return!1}return!0}l.isValidSchema=C;var lt=[[!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]],ut=["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 r=e,{definitions:t=void 0,nullable:i=void 0,metadata:n=void 0,ref:o=void 0,type:s=void 0,enum:f=void 0,elements:a=void 0,properties:d=void 0,optionalProperties:u=void 0,additionalProperties:E=void 0,values:T=void 0,discriminator:P=void 0,mapping:p=void 0}=r,S=ve(r,["definitions","nullable","metadata","ref","type","enum","elements","properties","optionalProperties","additionalProperties","values","discriminator","mapping"]),A=[o!==void 0,s!==void 0,f!==void 0,a!==void 0,d!==void 0,u!==void 0,E!==void 0,T!==void 0,P!==void 0,p!==void 0],k=!1;for(let c of lt)k=k||c.every((U,O)=>U===A[O]);if(!k)return!1;if(t!==void 0){if(typeof t!="object"||Array.isArray(t)||t===null)return!1;for(let c of Object.values(t))if(!L(c))return!1}if(i!==void 0&&typeof i!="boolean"||n!==void 0&&(typeof n!="object"||Array.isArray(n)||n===null)||o!==void 0&&typeof o!="string"||s!==void 0&&(typeof s!="string"||!ut.includes(s))||f!==void 0&&(!Array.isArray(f)||!f.every(c=>typeof c=="string"))||a!==void 0&&!L(a))return!1;if(d!==void 0){if(typeof d!="object"||Array.isArray(d)||d===null)return!1;for(let c of Object.values(d))if(!L(c))return!1}if(u!==void 0){if(typeof u!="object"||Array.isArray(u)||u===null)return!1;for(let c of Object.values(u))if(!L(c))return!1}if(E!==void 0&&typeof E!="boolean"||T!==void 0&&!L(T)||P!==void 0&&typeof P!="string")return!1;if(p!==void 0){if(typeof p!="object"||Array.isArray(p)||p===null)return!1;for(let c of Object.values(p))if(!L(c))return!1}return Object.keys(S).length===0}l.isSchema=L});var Pe=z(ae=>{"use strict";Object.defineProperty(ae,"__esModule",{value:!0});var dt=/^(\d{4})-(\d{2})-(\d{2})[tT](\d{2}):(\d{2}):(\d{2})(\.\d+)?([zZ]|((\+|-)(\d{2}):(\d{2})))$/;function pt(e){let r=e.match(dt);if(r===null)return!1;let t=parseInt(r[1],10),i=parseInt(r[2],10),n=parseInt(r[3],10),o=parseInt(r[4],10),s=parseInt(r[5],10),f=parseInt(r[6],10);return!(i>12||n>ct(t,i)||o>23||s>59||f>60)}ae.default=pt;function ct(e,r){return r===2?mt(e)?29:28:gt[r]}function mt(e){return e%4===0&&(e%100!==0||e%400===0)}var gt=[0,31,0,31,30,31,30,31,31,30,31,30,31]});var Ae=z(F=>{"use strict";var ht=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 yt=ht(Pe()),j=se(),W=class extends Error{};F.MaxDepthExceededError=W;var ee=class extends Error{};function vt(e,r,t){let i={errors:[],instanceTokens:[],schemaTokens:[[]],root:e,config:t||{maxDepth:0,maxErrors:0}};try{$(i,e,r)}catch(n){if(!(n instanceof ee))throw n}return i.errors}F.validate=vt;function $(e,r,t,i){if(!(r.nullable&&t===null)){if(j.isRefForm(r)){if(e.schemaTokens.length===e.config.maxDepth)throw new W;e.schemaTokens.push(["definitions",r.ref]),$(e,e.root.definitions[r.ref],t),e.schemaTokens.pop()}else if(j.isTypeForm(r)){switch(b(e,"type"),r.type){case"boolean":typeof t!="boolean"&&x(e);break;case"float32":case"float64":typeof t!="number"&&x(e);break;case"int8":V(e,t,-128,127);break;case"uint8":V(e,t,0,255);break;case"int16":V(e,t,-32768,32767);break;case"uint16":V(e,t,0,65535);break;case"int32":V(e,t,-2147483648,2147483647);break;case"uint32":V(e,t,0,4294967295);break;case"string":typeof t!="string"&&x(e);break;case"timestamp":typeof t!="string"?x(e):yt.default(t)||x(e);break}w(e)}else if(j.isEnumForm(r))b(e,"enum"),(typeof t!="string"||!r.enum.includes(t))&&x(e),w(e);else if(j.isElementsForm(r)){if(b(e,"elements"),Array.isArray(t))for(let[n,o]of t.entries())D(e,n.toString()),$(e,r.elements,o),N(e);else x(e);w(e)}else if(j.isPropertiesForm(r))if(typeof t=="object"&&t!==null&&!Array.isArray(t)){if(r.properties!==void 0){b(e,"properties");for(let[n,o]of Object.entries(r.properties))b(e,n),t.hasOwnProperty(n)?(D(e,n),$(e,o,t[n]),N(e)):x(e),w(e);w(e)}if(r.optionalProperties!==void 0){b(e,"optionalProperties");for(let[n,o]of Object.entries(r.optionalProperties))b(e,n),t.hasOwnProperty(n)&&(D(e,n),$(e,o,t[n]),N(e)),w(e);w(e)}if(r.additionalProperties!==!0)for(let n of Object.keys(t)){let o=r.properties&&n in r.properties,s=r.optionalProperties&&n in r.optionalProperties;!o&&!s&&n!==i&&(D(e,n),x(e),N(e))}}else r.properties!==void 0?b(e,"properties"):b(e,"optionalProperties"),x(e),w(e);else if(j.isValuesForm(r)){if(b(e,"values"),typeof t=="object"&&t!==null&&!Array.isArray(t))for(let[n,o]of Object.entries(t))D(e,n),$(e,r.values,o),N(e);else x(e);w(e)}else if(j.isDiscriminatorForm(r))if(typeof t=="object"&&t!==null&&!Array.isArray(t))if(t.hasOwnProperty(r.discriminator)){let n=t[r.discriminator];typeof n=="string"?n in r.mapping?(b(e,"mapping"),b(e,n),$(e,r.mapping[n],t,r.discriminator),w(e),w(e)):(b(e,"mapping"),D(e,r.discriminator),x(e),N(e),w(e)):(b(e,"discriminator"),D(e,r.discriminator),x(e),N(e),w(e))}else b(e,"discriminator"),x(e),w(e);else b(e,"discriminator"),x(e),w(e)}}function V(e,r,t,i){(typeof r!="number"||!Number.isInteger(r)||r<t||r>i)&&x(e)}function D(e,r){e.instanceTokens.push(r)}function N(e){e.instanceTokens.pop()}function b(e,r){e.schemaTokens[e.schemaTokens.length-1].push(r)}function w(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 Se=z(I=>{"use strict";var bt=I&&I.__createBinding||(Object.create?function(e,r,t,i){i===void 0&&(i=t),Object.defineProperty(e,i,{enumerable:!0,get:function(){return r[t]}})}:function(e,r,t,i){i===void 0&&(i=t),e[i]=r[t]}),ke=I&&I.__exportStar||function(e,r){for(var t in e)t!=="default"&&!r.hasOwnProperty(t)&&bt(r,e,t)};Object.defineProperty(I,"__esModule",{value:!0});ke(se(),I);ke(Ae(),I)});var Ft={};Ve(Ft,{GenerationError:()=>q,ResponseError:()=>H,builtinFontNames:()=>Et,builtinLineHeights:()=>je,builtinMargins:()=>Le,builtinTextScales:()=>Ce,builtinTools:()=>Tt,register:()=>kt,remarkable:()=>Rt});var G,ze=new Uint8Array(16);function Y(){if(!G&&(G=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||typeof msCrypto<"u"&&typeof msCrypto.getRandomValues=="function"&&msCrypto.getRandomValues.bind(msCrypto),!G))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return G(ze)}var pe=/^(?:[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 Ge(e){return typeof e=="string"&&pe.test(e)}var _=Ge;var m=[];for(Z=0;Z<256;++Z)m.push((Z+256).toString(16).substr(1));var Z;function Ye(e){var r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,t=(m[e[r+0]]+m[e[r+1]]+m[e[r+2]]+m[e[r+3]]+"-"+m[e[r+4]]+m[e[r+5]]+"-"+m[e[r+6]]+m[e[r+7]]+"-"+m[e[r+8]]+m[e[r+9]]+"-"+m[e[r+10]]+m[e[r+11]]+m[e[r+12]]+m[e[r+13]]+m[e[r+14]]+m[e[r+15]]).toLowerCase();if(!_(t))throw TypeError("Stringified UUID is invalid");return t}var B=Ye;function Ze(e){if(!_(e))throw TypeError("Invalid UUID");var 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 re=Ze;function Ke(e){e=unescape(encodeURIComponent(e));for(var r=[],t=0;t<e.length;++t)r.push(e.charCodeAt(t));return r}var Xe="6ba7b810-9dad-11d1-80b4-00c04fd430c8",Qe="6ba7b811-9dad-11d1-80b4-00c04fd430c8";function K(e,r,t){function i(n,o,s,f){if(typeof n=="string"&&(n=Ke(n)),typeof o=="string"&&(o=re(o)),o.length!==16)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");var a=new Uint8Array(16+n.length);if(a.set(o),a.set(n,o.length),a=t(a),a[6]=a[6]&15|r,a[8]=a[8]&63|128,s){f=f||0;for(var d=0;d<16;++d)s[f+d]=a[d];return s}return B(a)}try{i.name=e}catch{}return i.DNS=Xe,i.URL=Qe,i}function We(e){if(typeof e=="string"){var r=unescape(encodeURIComponent(e));e=new Uint8Array(r.length);for(var t=0;t<r.length;++t)e[t]=r.charCodeAt(t)}return et(tt(rt(e),e.length*8))}function et(e){for(var r=[],t=e.length*32,i="0123456789abcdef",n=0;n<t;n+=8){var o=e[n>>5]>>>n%32&255,s=parseInt(i.charAt(o>>>4&15)+i.charAt(o&15),16);r.push(s)}return r}function ce(e){return(e+64>>>9<<4)+14+1}function tt(e,r){e[r>>5]|=128<<r%32,e[ce(r)-1]=r;for(var t=1732584193,i=-271733879,n=-1732584194,o=271733878,s=0;s<e.length;s+=16){var f=t,a=i,d=n,u=o;t=g(t,i,n,o,e[s],7,-680876936),o=g(o,t,i,n,e[s+1],12,-389564586),n=g(n,o,t,i,e[s+2],17,606105819),i=g(i,n,o,t,e[s+3],22,-1044525330),t=g(t,i,n,o,e[s+4],7,-176418897),o=g(o,t,i,n,e[s+5],12,1200080426),n=g(n,o,t,i,e[s+6],17,-1473231341),i=g(i,n,o,t,e[s+7],22,-45705983),t=g(t,i,n,o,e[s+8],7,1770035416),o=g(o,t,i,n,e[s+9],12,-1958414417),n=g(n,o,t,i,e[s+10],17,-42063),i=g(i,n,o,t,e[s+11],22,-1990404162),t=g(t,i,n,o,e[s+12],7,1804603682),o=g(o,t,i,n,e[s+13],12,-40341101),n=g(n,o,t,i,e[s+14],17,-1502002290),i=g(i,n,o,t,e[s+15],22,1236535329),t=h(t,i,n,o,e[s+1],5,-165796510),o=h(o,t,i,n,e[s+6],9,-1069501632),n=h(n,o,t,i,e[s+11],14,643717713),i=h(i,n,o,t,e[s],20,-373897302),t=h(t,i,n,o,e[s+5],5,-701558691),o=h(o,t,i,n,e[s+10],9,38016083),n=h(n,o,t,i,e[s+15],14,-660478335),i=h(i,n,o,t,e[s+4],20,-405537848),t=h(t,i,n,o,e[s+9],5,568446438),o=h(o,t,i,n,e[s+14],9,-1019803690),n=h(n,o,t,i,e[s+3],14,-187363961),i=h(i,n,o,t,e[s+8],20,1163531501),t=h(t,i,n,o,e[s+13],5,-1444681467),o=h(o,t,i,n,e[s+2],9,-51403784),n=h(n,o,t,i,e[s+7],14,1735328473),i=h(i,n,o,t,e[s+12],20,-1926607734),t=y(t,i,n,o,e[s+5],4,-378558),o=y(o,t,i,n,e[s+8],11,-2022574463),n=y(n,o,t,i,e[s+11],16,1839030562),i=y(i,n,o,t,e[s+14],23,-35309556),t=y(t,i,n,o,e[s+1],4,-1530992060),o=y(o,t,i,n,e[s+4],11,1272893353),n=y(n,o,t,i,e[s+7],16,-155497632),i=y(i,n,o,t,e[s+10],23,-1094730640),t=y(t,i,n,o,e[s+13],4,681279174),o=y(o,t,i,n,e[s],11,-358537222),n=y(n,o,t,i,e[s+3],16,-722521979),i=y(i,n,o,t,e[s+6],23,76029189),t=y(t,i,n,o,e[s+9],4,-640364487),o=y(o,t,i,n,e[s+12],11,-421815835),n=y(n,o,t,i,e[s+15],16,530742520),i=y(i,n,o,t,e[s+2],23,-995338651),t=v(t,i,n,o,e[s],6,-198630844),o=v(o,t,i,n,e[s+7],10,1126891415),n=v(n,o,t,i,e[s+14],15,-1416354905),i=v(i,n,o,t,e[s+5],21,-57434055),t=v(t,i,n,o,e[s+12],6,1700485571),o=v(o,t,i,n,e[s+3],10,-1894986606),n=v(n,o,t,i,e[s+10],15,-1051523),i=v(i,n,o,t,e[s+1],21,-2054922799),t=v(t,i,n,o,e[s+8],6,1873313359),o=v(o,t,i,n,e[s+15],10,-30611744),n=v(n,o,t,i,e[s+6],15,-1560198380),i=v(i,n,o,t,e[s+13],21,1309151649),t=v(t,i,n,o,e[s+4],6,-145523070),o=v(o,t,i,n,e[s+11],10,-1120210379),n=v(n,o,t,i,e[s+2],15,718787259),i=v(i,n,o,t,e[s+9],21,-343485551),t=R(t,f),i=R(i,a),n=R(n,d),o=R(o,u)}return[t,i,n,o]}function rt(e){if(e.length===0)return[];for(var r=e.length*8,t=new Uint32Array(ce(r)),i=0;i<r;i+=8)t[i>>5]|=(e[i/8]&255)<<i%32;return t}function R(e,r){var t=(e&65535)+(r&65535),i=(e>>16)+(r>>16)+(t>>16);return i<<16|t&65535}function nt(e,r){return e<<r|e>>>32-r}function X(e,r,t,i,n,o){return R(nt(R(R(r,e),R(i,o)),n),t)}function g(e,r,t,i,n,o,s){return X(r&t|~r&i,e,r,n,o,s)}function h(e,r,t,i,n,o,s){return X(r&i|t&~i,e,r,n,o,s)}function y(e,r,t,i,n,o,s){return X(r^t^i,e,r,n,o,s)}function v(e,r,t,i,n,o,s){return X(t^(r|~i),e,r,n,o,s)}var me=We;var Zt=K("v3",48,me);function it(e,r,t){e=e||{};var i=e.random||(e.rng||Y)();if(i[6]=i[6]&15|64,i[8]=i[8]&63|128,r){t=t||0;for(var n=0;n<16;++n)r[t+n]=i[n];return r}return B(i)}var Q=it;function ot(e,r,t,i){switch(e){case 0:return r&t^~r&i;case 1:return r^t^i;case 2:return r&t^r&i^t&i;case 3:return r^t^i}}function ne(e,r){return e<<r|e>>>32-r}function st(e){var r=[1518500249,1859775393,2400959708,3395469782],t=[1732584193,4023233417,2562383102,271733878,3285377520];if(typeof e=="string"){var i=unescape(encodeURIComponent(e));e=[];for(var n=0;n<i.length;++n)e.push(i.charCodeAt(n))}else Array.isArray(e)||(e=Array.prototype.slice.call(e));e.push(128);for(var o=e.length/4+2,s=Math.ceil(o/16),f=new Array(s),a=0;a<s;++a){for(var d=new Uint32Array(16),u=0;u<16;++u)d[u]=e[a*64+u*4]<<24|e[a*64+u*4+1]<<16|e[a*64+u*4+2]<<8|e[a*64+u*4+3];f[a]=d}f[s-1][14]=(e.length-1)*8/Math.pow(2,32),f[s-1][14]=Math.floor(f[s-1][14]),f[s-1][15]=(e.length-1)*8&4294967295;for(var E=0;E<s;++E){for(var T=new Uint32Array(80),P=0;P<16;++P)T[P]=f[E][P];for(var p=16;p<80;++p)T[p]=ne(T[p-3]^T[p-8]^T[p-14]^T[p-16],1);for(var S=t[0],A=t[1],k=t[2],c=t[3],U=t[4],O=0;O<80;++O){var M=Math.floor(O/20),te=ne(S,5)+ot(M,A,k,c)+U+r[M]+T[O]>>>0;U=c,c=k,k=ne(A,30)>>>0,A=S,S=te}t[0]=t[0]+S>>>0,t[1]=t[1]+A>>>0,t[2]=t[2]+k>>>0,t[3]=t[3]+c>>>0,t[4]=t[4]+U>>>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 ge=st;var nr=K("v5",80,ge);function ie(e){return[...new Uint8Array(e)].map(r=>r.toString(16).padStart(2,"0")).join("")}function he(e){return new Uint8Array((e.match(/../g)??[]).map(r=>parseInt(r,16)))}function ye(e){let r=0;for(let n of e)r+=n.length;let t=new Uint8Array(r),i=0;for(let n of e)t.set(n,i),i+=n.length;return t}var Oe=qe(Se());function fe(e,r){if((0,Oe.validate)(e,r).length)throw new Error(`couldn't validate schema: ${JSON.stringify(r)} didn't match schema ${JSON.stringify(e)}`)}var Re="3",Me="https://webapp-production-dot-remarkable-production.appspot.com",xt="https://rm-blob-storage-prod.appspot.com",Fe="x-goog-generation",wt="x-goog-if-generation-match",Tt=["Ballpoint","Ballpointv2","Brush","Calligraphy","ClearPage","EraseSection","Eraser","Fineliner","Finelinerv2","Highlighter","Highlighterv2","Marker","Markerv2","Paintbrush","Paintbrushv2","Pencilv2","SharpPencil","SharpPencilv2","SolidPen","ZoomTool"],Et=["Maison Neue","EB Garamond","Noto Sans","Noto Serif","Noto Mono","Noto Sans UI"],Ce={xs:.7,sm:.8,md:1,lg:1.2,xl:1.5,xx:2},Le={sm:50,md:125,rr:180,lg:200},je={df:-1,md:100,lg:150,xl:200},Pt={properties:{relative_path:{type:"string"},url:{type:"string"},expires:{type:"timestamp"},method:{enum:["POST","GET","PUT","DELETE"]}}},Ie={visibleName:{type:"string"},parent:{type:"string"},lastModified:{type:"string"},version:{type:"int32"},synced:{type:"boolean"}},Ue={pinned:{type:"boolean"},modified:{type:"boolean"},deleted:{type:"boolean"},metadatamodified:{type:"boolean"}},At={discriminator:"type",mapping:{CollectionType:{properties:Ie,optionalProperties:Ue},DocumentType:{properties:Ie,optionalProperties:{...Ue,lastOpened:{type:"string"},lastOpenedPage:{type:"int32"}}}}},H=class extends Error{constructor(t,i,n){super(n);this.status=t,this.statusText=i}},q=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 kt(e,{deviceDesc:r="desktop-linux",uuid:t=Q(),authUrl:i=Me,fetch:n=globalThis.fetch}={}){if(e.length!==8)throw new Error(`code should be length 8, but was ${e.length}`);let o=await n(`${i}/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 H(o.status,o.statusText,"couldn't register api")}function St({hash:e,type:r,documentId:t,subfiles:i,size:n}){return`${e}:${r}:${t}:${i}:${n}
|
|
2
|
+
`}function Ot(e){let[r,t,i,n,o]=e.split(":");if(r===void 0||t===void 0||i===void 0||n===void 0||o===void 0)throw new Error(`entries line didn't contain five fields: '${e}'`);if(t==="80000000"){if(o!=="0")throw new Error(`collection type entry had nonzero size: ${o}`);return{hash:r,type:t,documentId:i,subfiles:parseInt(n),size:0n}}else if(t==="0"){if(n!=="0")throw new Error(`file type entry had nonzero number of subfiles: ${n}`);return{hash:r,type:t,documentId:i,subfiles:0,size:BigInt(o)}}else throw new Error(`entries line contained invalid type: ${t}`)}var le=class{constructor(r,t,i,n,o){this.userToken=r;this.fetch=t;this.cache=i;this.subtle=n;this.blobUrl=o}async authedFetch(r,t,i="POST"){let n=await this.fetch(r,{method:i,headers:{Authorization:`Bearer ${this.userToken}`},body:t&&JSON.stringify(t)});if(n.ok)return n;throw new H(n.status,n.statusText,"failed reMarkable request")}async signedFetch({url:r,method:t},i,n){let o=await this.fetch(r,{method:t,body:i,headers:n});if(o.ok)return o;{let s=await o.text();throw new H(o.status,o.statusText,s)}}async getUrl(r,t){let i=t===void 0?"downloads":"uploads",n=t==null?void 0:`${t}`,s=await(await this.authedFetch(`${this.blobUrl}/api/v1/signed-urls/${i}`,{http_method:n===void 0?"GET":"PUT",relative_path:r,generation:n})).text(),f=JSON.parse(s);return fe(Pt,f),f}async syncComplete(){await this.authedFetch(`${this.blobUrl}/api/v1/sync-complete`)}async getRootHash(){let r=await this.getUrl("root"),t=await this.signedFetch(r),i=t.headers.get(Fe);if(!i)throw new Error("no generation header in root hash");return[await t.text(),BigInt(i)]}async putRootHash(r,t){let i=await this.getUrl("root",t),n;try{n=await this.signedFetch(i,r,{[wt]:`${t}`})}catch(s){throw s instanceof H&&s.status===412?new q:s}let o=n.headers.get(Fe);if(!o)throw new Error("no generation header in root hash");return BigInt(o)}async getBuffer(r){let t=await this.getUrl(r);return await(await this.signedFetch(t)).arrayBuffer()}async getText(r){let t=this.cache&&await this.cache.get(r);if(t)return t;{let i=await this.getUrl(r),o=await(await this.signedFetch(i)).text();return this.cache&&await this.cache.set(r,o),o}}async getMetadata(r){let t=await this.getText(r),i=JSON.parse(t);return fe(At,i),i}async getEntries(r){let t=await this.getText(r),[i,...n]=t.slice(0,-1).split(`
|
|
3
|
+
`);if(i!==Re)throw new Error(`got unexpected schema version: ${i}`);return n.map(Ot)}async putHash(r,t){let i=await this.getUrl(r,null);await this.signedFetch(i,t)}async putEntries(r,t){let i=new TextEncoder;t.sort((u,E)=>u.documentId.localeCompare(E.documentId));let n=ye(t.map(u=>he(u.hash))),o=await this.subtle.digest("SHA-256",n),s=ie(o),f=t.map(St).join(""),a=`${Re}
|
|
4
|
+
${f}`,d=i.encode(a);return await this.putHash(s,d),this.cache&&await this.cache.set(s,a),{hash:s,type:"80000000",documentId:r,subfiles:t.length,size:0n}}async putBuffer(r,t){let i=await this.subtle.digest("SHA-256",t),n=ie(i);return await this.putHash(n,t),{hash:n,type:"0",documentId:r,subfiles:0,size:BigInt(t.length)}}async putText(r,t){let i=new TextEncoder,n=await this.putBuffer(r,i.encode(t));return this.cache&&await this.cache.set(n.hash,t),n}async putEpub(r,t,{parent:i="",margins:n=125,orientation:o,textAlignment:s,textScale:f=1,lineHeight:a=-1,fontName:d="",cover:u="visited",lastTool:E,notify:T=!0,retries:P=3}={}){let p=Q(),S=`${new Date().valueOf()}`,A=[];A.push(this.putBuffer(`${p}.epub`,t));let k={type:"DocumentType",visibleName:r,version:0,parent:i,synced:!0,lastModified:S};A.push(this.putText(`${p}.metadata`,JSON.stringify(k)));let c={dummyDocument:!1,extraMetadata:{LastTool:E},fileType:"epub",pageCount:0,lastOpenedPage:0,lineHeight:typeof a=="string"?je[a]:a,margins:typeof n=="string"?Le[n]:n,textScale:typeof f=="string"?Ce[f]:f,pages:[],coverPageNumber:u==="first"?0:-1,formatVersion:1,orientation:o,textAlignment:s,fontName:d};A.push(this.putText(`${p}.content`,JSON.stringify(c)));let U=await Promise.all(A),O=await this.putEntries(p,U);for(;;--P)try{let[M,te]=await this.getRootHash(),ue=await this.getEntries(M);ue.push(O);let{hash:De}=await this.putEntries("",ue);await this.putRootHash(De,te);break}catch(M){if(P<=0||!(M instanceof q))throw M}T&&await this.syncComplete()}};async function Rt(e,{fetch:r=globalThis.fetch,cache:t,subtle:i=globalThis.crypto?.subtle,authUrl:n=Me,blobUrl:o=xt}={}){let s=await r(`${n}/token/json/2/user/new`,{method:"POST",headers:{Authorization:`Bearer ${e}`}});if(!s.ok)throw new Error(`couldn't fetch auth token: ${s.statusText}`);let f=await s.text();return new le(f,r,t,i,o)}return Je(Ft);})();
|