@yaks/blob 0.0.0-stage → 0.2.36

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.
Files changed (172) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +946 -2
  3. package/_dist/accepts.d.ts +38 -0
  4. package/_dist/accepts.d.ts.map +1 -0
  5. package/_dist/artifact.d.ts +29 -0
  6. package/_dist/artifact.d.ts.map +1 -0
  7. package/_dist/attachment.d.ts +53 -0
  8. package/_dist/attachment.d.ts.map +1 -0
  9. package/_dist/backend.d.ts +20 -0
  10. package/_dist/backend.d.ts.map +1 -0
  11. package/_dist/broken.d.ts +24 -0
  12. package/_dist/broken.d.ts.map +1 -0
  13. package/_dist/browser.d.ts +27 -0
  14. package/_dist/browser.d.ts.map +1 -0
  15. package/_dist/compare.d.ts +4 -0
  16. package/_dist/compare.d.ts.map +1 -0
  17. package/_dist/content_type.d.ts +20 -0
  18. package/_dist/content_type.d.ts.map +1 -0
  19. package/_dist/graph.d.ts +13 -0
  20. package/_dist/graph.d.ts.map +1 -0
  21. package/_dist/hydrate.d.ts +36 -0
  22. package/_dist/hydrate.d.ts.map +1 -0
  23. package/_dist/identify.d.ts +7 -0
  24. package/_dist/identify.d.ts.map +1 -0
  25. package/_dist/image.d.ts +37 -0
  26. package/_dist/image.d.ts.map +1 -0
  27. package/_dist/keywords.d.ts +10 -0
  28. package/_dist/keywords.d.ts.map +1 -0
  29. package/_dist/mime.d.ts +2 -0
  30. package/_dist/mime.d.ts.map +1 -0
  31. package/_dist/mod.d.ts +97 -0
  32. package/_dist/mod.d.ts.map +1 -0
  33. package/_dist/object-put.d.ts +2 -0
  34. package/_dist/object-put.d.ts.map +1 -0
  35. package/_dist/object.d.ts +175 -0
  36. package/_dist/object.d.ts.map +1 -0
  37. package/_dist/parts.d.ts +91 -0
  38. package/_dist/parts.d.ts.map +1 -0
  39. package/_dist/plugin.d.ts +38 -0
  40. package/_dist/plugin.d.ts.map +1 -0
  41. package/_dist/png.d.ts +14 -0
  42. package/_dist/png.d.ts.map +1 -0
  43. package/_dist/props.d.ts +20 -0
  44. package/_dist/props.d.ts.map +1 -0
  45. package/_dist/representation.d.ts +17 -0
  46. package/_dist/representation.d.ts.map +1 -0
  47. package/_dist/representation_rules.d.ts +3 -0
  48. package/_dist/representation_rules.d.ts.map +1 -0
  49. package/_dist/routes.d.ts +65 -0
  50. package/_dist/routes.d.ts.map +1 -0
  51. package/_dist/serve.d.ts +29 -0
  52. package/_dist/serve.d.ts.map +1 -0
  53. package/_dist/sha256.d.ts +26 -0
  54. package/_dist/sha256.d.ts.map +1 -0
  55. package/_dist/sqlite.d.ts +57 -0
  56. package/_dist/sqlite.d.ts.map +1 -0
  57. package/_dist/store.d.ts +41 -0
  58. package/_dist/store.d.ts.map +1 -0
  59. package/_dist/stream.d.ts +91 -0
  60. package/_dist/stream.d.ts.map +1 -0
  61. package/_dist/upload.d.ts +114 -0
  62. package/_dist/upload.d.ts.map +1 -0
  63. package/_dist/value.d.ts +62 -0
  64. package/_dist/value.d.ts.map +1 -0
  65. package/_dist/vocab.d.ts +13 -0
  66. package/_dist/vocab.d.ts.map +1 -0
  67. package/accepts.js +76 -0
  68. package/accepts.js.map +1 -0
  69. package/accepts.ts +95 -0
  70. package/artifact.js +50 -0
  71. package/artifact.js.map +1 -0
  72. package/artifact.ts +93 -0
  73. package/attachment.js +190 -0
  74. package/attachment.js.map +1 -0
  75. package/attachment.ts +201 -0
  76. package/backend.js +37 -0
  77. package/backend.js.map +1 -0
  78. package/backend.ts +44 -0
  79. package/broken.js +278 -0
  80. package/broken.js.map +1 -0
  81. package/broken.ts +217 -0
  82. package/browser.js +124 -0
  83. package/browser.js.map +1 -0
  84. package/browser.ts +179 -0
  85. package/compare.js +82 -0
  86. package/compare.js.map +1 -0
  87. package/compare.ts +90 -0
  88. package/content_type.js +43 -0
  89. package/content_type.js.map +1 -0
  90. package/content_type.ts +58 -0
  91. package/deno.json +1 -0
  92. package/fixed.js +53 -0
  93. package/fixed.js.map +1 -0
  94. package/fixed.ts +61 -0
  95. package/graph.js +15 -0
  96. package/graph.js.map +1 -0
  97. package/graph.ts +22 -0
  98. package/hydrate.js +69 -0
  99. package/hydrate.js.map +1 -0
  100. package/hydrate.ts +72 -0
  101. package/identify.js +38 -0
  102. package/identify.js.map +1 -0
  103. package/identify.ts +50 -0
  104. package/image.js +111 -0
  105. package/image.js.map +1 -0
  106. package/image.ts +120 -0
  107. package/keywords.js +28 -0
  108. package/keywords.js.map +1 -0
  109. package/keywords.ts +28 -0
  110. package/meta/blob.vocab.json +17 -0
  111. package/mime.js +72 -0
  112. package/mime.js.map +1 -0
  113. package/mime.ts +73 -0
  114. package/mod.js +97 -0
  115. package/mod.js.map +1 -0
  116. package/mod.ts +115 -0
  117. package/object-put.js +90 -0
  118. package/object-put.js.map +1 -0
  119. package/object-put.ts +114 -0
  120. package/object.js +369 -0
  121. package/object.js.map +1 -0
  122. package/object.ts +592 -0
  123. package/package.json +84 -4
  124. package/parts.js +354 -0
  125. package/parts.js.map +1 -0
  126. package/parts.ts +423 -0
  127. package/plugin.js +158 -0
  128. package/plugin.js.map +1 -0
  129. package/plugin.ts +184 -0
  130. package/png.js +74 -0
  131. package/png.js.map +1 -0
  132. package/png.ts +58 -0
  133. package/props.js +32 -0
  134. package/props.js.map +1 -0
  135. package/props.ts +47 -0
  136. package/purge.js +65 -0
  137. package/purge.js.map +1 -0
  138. package/purge.ts +72 -0
  139. package/representation.js +34 -0
  140. package/representation.js.map +1 -0
  141. package/representation.ts +44 -0
  142. package/representation_rules.js +44 -0
  143. package/representation_rules.js.map +1 -0
  144. package/representation_rules.ts +57 -0
  145. package/routes.js +454 -0
  146. package/routes.js.map +1 -0
  147. package/routes.ts +575 -0
  148. package/serve.js +196 -0
  149. package/serve.js.map +1 -0
  150. package/serve.ts +242 -0
  151. package/sha256.js +185 -0
  152. package/sha256.js.map +1 -0
  153. package/sha256.ts +210 -0
  154. package/sqlite.js +201 -0
  155. package/sqlite.js.map +1 -0
  156. package/sqlite.ts +250 -0
  157. package/store.js +40 -0
  158. package/store.js.map +1 -0
  159. package/store.ts +93 -0
  160. package/stream.js +203 -0
  161. package/stream.js.map +1 -0
  162. package/stream.ts +256 -0
  163. package/upload.js +256 -0
  164. package/upload.js.map +1 -0
  165. package/upload.ts +404 -0
  166. package/value.js +234 -0
  167. package/value.js.map +1 -0
  168. package/value.ts +281 -0
  169. package/vocab.js +27 -0
  170. package/vocab.js.map +1 -0
  171. package/vocab.json +123 -0
  172. package/vocab.ts +32 -0
package/hydrate.js ADDED
@@ -0,0 +1,69 @@
1
+ // The read side for a store SQL cannot read into. Where the bytes live in the
2
+ // same database as the rows, the resolution is a SQL expression and a bundle
3
+ // already comes back carrying text (see ./sqlite.ts); where they live in a
4
+ // directory or a bucket, something has to fetch them, and this is that
5
+ // something.
6
+ //
7
+ // It takes bundles and returns bundles — the shape a read already produces — so
8
+ // it fits wherever the entities arrive: after `read()`, after a subscription
9
+ // push, after `apply()` returns.
10
+ import { after, each } from "@yaks/fp";
11
+ import { bodies } from "./props.js";
12
+ import { decode } from "./store.js";
13
+ /**
14
+ * Resolve every content-addressed property in these bundles: each address is
15
+ * looked up in the store and replaced by the text it names. An address the
16
+ * store does not hold is left in place — dropping the value would be a worse
17
+ * result than an address nobody can resolve.
18
+ *
19
+ * ```ts
20
+ * import { assertEquals } from '@std/assert'
21
+ * import { loadVocab } from '@yaks/vocab'
22
+ * import {
23
+ * address,
24
+ * blobKeywords,
25
+ * encode,
26
+ * hydrate,
27
+ * memoryBlobs,
28
+ * } from '@yaks/blob'
29
+ *
30
+ * let body = { type: 'string', store: 'blob' }
31
+ * let post = { component: true, type: 'object', properties: { body } }
32
+ * let vocab = loadVocab([{ $defs: { post } }], [blobKeywords])
33
+ * let store = memoryBlobs()
34
+ * store.put(address('A long essay.'), encode('A long essay.'))
35
+ *
36
+ * let essay = address('A long essay.')
37
+ * let read = { entity: { eid: 'p1' }, post: { body: essay } }
38
+ * let [p1] = await hydrate(vocab, store, [read])
39
+ * assertEquals(p1.post, { body: 'A long essay.' })
40
+ * ```
41
+ *
42
+ * Asynchronous only when the store is: over a synchronous backend this returns
43
+ * the bundles directly.
44
+ */ export let hydrate = (vocab, store, bundles)=>{
45
+ let props = bodies(vocab);
46
+ if (!props.length) return bundles;
47
+ return each(bundles, [], (out, b)=>{
48
+ let one = {
49
+ ...b
50
+ };
51
+ return after(each(props, null, (_, { comp, prop })=>{
52
+ let held = one[comp];
53
+ if (!held || typeof held != 'object') return null;
54
+ let sha = held[prop];
55
+ if (typeof sha != 'string' || !sha) return null;
56
+ return after(store.get(sha), (bytes)=>{
57
+ if (bytes) one[comp] = {
58
+ ...held,
59
+ [prop]: decode(bytes)
60
+ };
61
+ return null;
62
+ });
63
+ }), ()=>[
64
+ ...out,
65
+ one
66
+ ]);
67
+ });
68
+ };
69
+ //# sourceMappingURL=hydrate.js.map
package/hydrate.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hydrate.js","sources":["./hydrate.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,6EAA6E;AAC7E,2EAA2E;AAC3E,uEAAuE;AACvE,aAAa;AACb,EAAE;AACF,gFAAgF;AAChF,6EAA6E;AAC7E,iCAAiC;AAGjC,SAAS,KAAK,EAAE,IAAI,wBAA6B;AAEjD,SAAS,MAAM,qBAAoB;AACnC,SAAqB,MAAM,qBAAoB;AAE/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+BC,GACD,OAAO,IAAI,UAAU,CACnB,OACA,OACA;EAEA,IAAI,QAAQ,OAAO;EACnB,IAAI,CAAC,MAAM,MAAM,EAAE,OAAO;EAC1B,OAAO,KAAK,SAAS,EAAE,EAAc,CAAC,KAAK;IACzC,IAAI,MAAc;MAAE,GAAG,CAAC;IAAC;IACzB,OAAO,MACL,KAAK,OAAO,MAAM,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE;MAClC,IAAI,OAAO,GAAG,CAAC,KAAK;MACpB,IAAI,CAAC,QAAQ,OAAO,QAAQ,UAAU,OAAO;MAC7C,IAAI,MAAM,AAAC,IAAa,CAAC,KAAK;MAC9B,IAAI,OAAO,OAAO,YAAY,CAAC,KAAK,OAAO;MAC3C,OAAO,MAAM,MAAM,GAAG,CAAC,MAAM,CAAC;QAC5B,IAAI,OAAO,GAAG,CAAC,KAAK,GAAG;UAAE,GAAG,IAAI;UAAU,CAAC,KAAK,EAAE,OAAO;QAAO;QAChE,OAAO;MACT;IACF,IACA,IAAM;WAAI;QAAK;OAAI;EAEvB;AACF,EAAC"}
package/hydrate.ts ADDED
@@ -0,0 +1,72 @@
1
+ // The read side for a store SQL cannot read into. Where the bytes live in the
2
+ // same database as the rows, the resolution is a SQL expression and a bundle
3
+ // already comes back carrying text (see ./sqlite.ts); where they live in a
4
+ // directory or a bucket, something has to fetch them, and this is that
5
+ // something.
6
+ //
7
+ // It takes bundles and returns bundles — the shape a read already produces — so
8
+ // it fits wherever the entities arrive: after `read()`, after a subscription
9
+ // push, after `apply()` returns.
10
+
11
+ import type { Bundle, Comp } from 'jsr:@yaks/graph@0.2.36'
12
+ import { after, each } from '@yaks/fp'
13
+ import type { Vocab } from 'jsr:@yaks/vocab@0.2.36'
14
+ import { bodies } from './props.js'
15
+ import { type Blobs, decode } from './store.js'
16
+
17
+ /**
18
+ * Resolve every content-addressed property in these bundles: each address is
19
+ * looked up in the store and replaced by the text it names. An address the
20
+ * store does not hold is left in place — dropping the value would be a worse
21
+ * result than an address nobody can resolve.
22
+ *
23
+ * ```ts
24
+ * import { assertEquals } from '@std/assert'
25
+ * import { loadVocab } from '@yaks/vocab'
26
+ * import {
27
+ * address,
28
+ * blobKeywords,
29
+ * encode,
30
+ * hydrate,
31
+ * memoryBlobs,
32
+ * } from '@yaks/blob'
33
+ *
34
+ * let body = { type: 'string', store: 'blob' }
35
+ * let post = { component: true, type: 'object', properties: { body } }
36
+ * let vocab = loadVocab([{ $defs: { post } }], [blobKeywords])
37
+ * let store = memoryBlobs()
38
+ * store.put(address('A long essay.'), encode('A long essay.'))
39
+ *
40
+ * let essay = address('A long essay.')
41
+ * let read = { entity: { eid: 'p1' }, post: { body: essay } }
42
+ * let [p1] = await hydrate(vocab, store, [read])
43
+ * assertEquals(p1.post, { body: 'A long essay.' })
44
+ * ```
45
+ *
46
+ * Asynchronous only when the store is: over a synchronous backend this returns
47
+ * the bundles directly.
48
+ */
49
+ export let hydrate = (
50
+ vocab: Vocab,
51
+ store: Blobs,
52
+ bundles: Bundle[],
53
+ ): Bundle[] | Promise<Bundle[]> => {
54
+ let props = bodies(vocab)
55
+ if (!props.length) return bundles
56
+ return each(bundles, [] as Bundle[], (out, b) => {
57
+ let one: Bundle = { ...b }
58
+ return after(
59
+ each(props, null, (_, { comp, prop }) => {
60
+ let held = one[comp]
61
+ if (!held || typeof held != 'object') return null
62
+ let sha = (held as Comp)[prop]
63
+ if (typeof sha != 'string' || !sha) return null
64
+ return after(store.get(sha), (bytes) => {
65
+ if (bytes) one[comp] = { ...held as Comp, [prop]: decode(bytes) }
66
+ return null
67
+ })
68
+ }),
69
+ () => [...out, one],
70
+ )
71
+ })
72
+ }
package/identify.js ADDED
@@ -0,0 +1,38 @@
1
+ // Host-side byte identification. The detector's declarations include Node
2
+ // streams; portable graphs use ArtifactStore, lent by their host.
3
+ import { mediaTypeOf } from "./image.js";
4
+ import { matchesMediaType, mediaType, utf8 } from "./content_type.js";
5
+ import { addressOf, keep } from "./artifact.js";
6
+ const SAMPLE = 4100;
7
+ const UNKNOWN = 'application/octet-stream';
8
+ let textual = (mime)=>mime.startsWith('text/') || mime.endsWith('+json') || mime.endsWith('+xml') || [
9
+ 'application/json',
10
+ 'application/javascript',
11
+ 'application/xml',
12
+ 'application/vnd.apple.mpegurl'
13
+ ].includes(mime);
14
+ /** A stable media type chosen from bytes and, for text, a valid declaration.
15
+ * `whole` false says the bytes are only a file's first ones. */ export let contentType = async (bytes, declared = '', whole = true)=>{
16
+ let image = mediaTypeOf(bytes);
17
+ if (image) return image;
18
+ let { fileTypeFromBuffer } = await import("file-type/core");
19
+ let found = await fileTypeFromBuffer(bytes.subarray(0, SAMPLE));
20
+ let mime = mediaType(declared);
21
+ if (found && (mime == 'audio/pcm' || !found.mime.startsWith('audio/'))) {
22
+ return found.mime;
23
+ }
24
+ if (matchesMediaType(bytes, mime)) return mime;
25
+ if (found) return found.mime;
26
+ return textual(mime) && utf8(bytes, whole) ? mime : UNKNOWN;
27
+ };
28
+ /** Store bytes and their media type, and return the {@link Artifact} a row
29
+ * records. */ export let artifactStore = (blobs)=>async (bytes, mediaType)=>{
30
+ let address = await addressOf(bytes);
31
+ await keep(blobs, address, bytes);
32
+ return {
33
+ address,
34
+ media_type: await contentType(bytes, mediaType),
35
+ size: bytes.byteLength
36
+ };
37
+ };
38
+ //# sourceMappingURL=identify.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identify.js","sources":["./identify.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,kEAAkE;AAClE,SAAS,WAAW,qBAAoB;AACxC,SAAS,gBAAgB,EAAE,SAAS,EAAE,IAAI,4BAA2B;AACrE,SAAS,SAAS,EAAsB,IAAI,wBAAuB;AAGnE,MAAM,SAAS;AACf,MAAM,UAAU;AAChB,IAAI,UAAU,CAAC,OACb,KAAK,UAAU,CAAC,YAAY,KAAK,QAAQ,CAAC,YAC1C,KAAK,QAAQ,CAAC,WAAW;IACvB;IACA;IACA;IACA;GACD,CAAC,QAAQ,CAAC;AAEb;8DAC8D,GAC9D,OAAO,IAAI,cAAc,OACvB,OACA,WAAW,EAAE,EACb,QAAQ,IAAI;EAEZ,IAAI,QAAQ,YAAY;EACxB,IAAI,OAAO,OAAO;EAClB,IAAI,EAAE,kBAAkB,EAAE,GAAG,MAAM,MAAM,CAAC;EAC1C,IAAI,QAAQ,MAAM,mBAAmB,MAAM,QAAQ,CAAC,GAAG;EACvD,IAAI,OAAO,UAAU;EACrB,IAAI,SAAS,CAAC,QAAQ,eAAe,CAAC,MAAM,IAAI,CAAC,UAAU,CAAC,SAAS,GAAG;IACtE,OAAO,MAAM,IAAI;EACnB;EACA,IAAI,iBAAiB,OAAO,OAAO,OAAO;EAC1C,IAAI,OAAO,OAAO,MAAM,IAAI;EAC5B,OAAO,QAAQ,SAAS,KAAK,OAAO,SAAS,OAAO;AACtD,EAAC;AAED;YACY,GACZ,OAAO,IAAI,gBACT,CAAC,QAAgC,OAAO,OAAO;IAC7C,IAAI,UAAU,MAAM,UAAU;IAC9B,MAAM,KAAK,OAAO,SAAS;IAC3B,OAAO;MACL;MACA,YAAY,MAAM,YAAY,OAAO;MACrC,MAAM,MAAM,UAAU;IACxB;EACF,EAAC"}
package/identify.ts ADDED
@@ -0,0 +1,50 @@
1
+ // Host-side byte identification. The detector's declarations include Node
2
+ // streams; portable graphs use ArtifactStore, lent by their host.
3
+ import { mediaTypeOf } from './image.js'
4
+ import { matchesMediaType, mediaType, utf8 } from './content_type.js'
5
+ import { addressOf, type ArtifactStore, keep } from './artifact.js'
6
+ import type { Blobs } from './store.ts'
7
+
8
+ const SAMPLE = 4100
9
+ const UNKNOWN = 'application/octet-stream'
10
+ let textual = (mime: string) =>
11
+ mime.startsWith('text/') || mime.endsWith('+json') ||
12
+ mime.endsWith('+xml') || [
13
+ 'application/json',
14
+ 'application/javascript',
15
+ 'application/xml',
16
+ 'application/vnd.apple.mpegurl',
17
+ ].includes(mime)
18
+
19
+ /** A stable media type chosen from bytes and, for text, a valid declaration.
20
+ * `whole` false says the bytes are only a file's first ones. */
21
+ export let contentType = async (
22
+ bytes: Uint8Array,
23
+ declared = '',
24
+ whole = true,
25
+ ): Promise<string> => {
26
+ let image = mediaTypeOf(bytes)
27
+ if (image) return image
28
+ let { fileTypeFromBuffer } = await import('file-type/core')
29
+ let found = await fileTypeFromBuffer(bytes.subarray(0, SAMPLE))
30
+ let mime = mediaType(declared)
31
+ if (found && (mime == 'audio/pcm' || !found.mime.startsWith('audio/'))) {
32
+ return found.mime
33
+ }
34
+ if (matchesMediaType(bytes, mime)) return mime
35
+ if (found) return found.mime
36
+ return textual(mime) && utf8(bytes, whole) ? mime : UNKNOWN
37
+ }
38
+
39
+ /** Store bytes and their media type, and return the {@link Artifact} a row
40
+ * records. */
41
+ export let artifactStore =
42
+ (blobs: Blobs): ArtifactStore => async (bytes, mediaType) => {
43
+ let address = await addressOf(bytes)
44
+ await keep(blobs, address, bytes)
45
+ return {
46
+ address,
47
+ media_type: await contentType(bytes, mediaType),
48
+ size: bytes.byteLength,
49
+ }
50
+ }
package/image.js ADDED
@@ -0,0 +1,111 @@
1
+ // A picture's dimensions, read out of its own first bytes. A page wants to
2
+ // reserve a photo's space before the bytes arrive, so whoever stores one
3
+ // records `{w, h}` beside it — from the header, never by decoding: the size is
4
+ // written down in the first few dozen bytes of every format that has one, and
5
+ // there is no reason to unpack 20 MB of pixels to learn a number the file
6
+ // already states.
7
+ //
8
+ // Four formats state it — png, jpeg, gif, webp — and anything else gets no size
9
+ // at all. A guess would be worse than nothing: a page can measure the bitmap
10
+ // itself, but it cannot un-believe a row.
11
+ // Whether the bytes at `i` are this ASCII string — a format's own signature,
12
+ // written the way the spec writes it ('\x89PNG\r\n\x1a\n').
13
+ let at = (b, i, sig)=>[
14
+ ...sig
15
+ ].every((c, j)=>b[i + j] == c.charCodeAt(0));
16
+ let be16 = (b, i)=>b[i] << 8 | b[i + 1];
17
+ let be32 = (b, i)=>be16(b, i) * 0x10000 + be16(b, i + 2);
18
+ let le16 = (b, i)=>b[i] | b[i + 1] << 8;
19
+ let le24 = (b, i)=>le16(b, i) | b[i + 2] << 16;
20
+ let le32 = (b, i)=>le24(b, i) + b[i + 3] * 0x1000000;
21
+ // PNG: the IHDR chunk is always first, and opens with the two dimensions.
22
+ let png = (b)=>b.length >= 24 && at(b, 0, '\x89PNG\r\n\x1a\n') && at(b, 12, 'IHDR') ? {
23
+ w: be32(b, 16),
24
+ h: be32(b, 20)
25
+ } : undefined;
26
+ // GIF: the logical screen, little-endian, right behind the version.
27
+ let gif = (b)=>b.length >= 10 && (at(b, 0, 'GIF87a') || at(b, 0, 'GIF89a')) ? {
28
+ w: le16(b, 6),
29
+ h: le16(b, 8)
30
+ } : undefined;
31
+ // WebP is three formats in a RIFF wrapper, each stating its size in a different
32
+ // place: lossy after the keyframe's sync code, lossless packed 14 bits apiece
33
+ // into one little-endian word, and extended as the canvas size, stored one less
34
+ // than it is.
35
+ let webp = (b)=>{
36
+ if (b.length < 30 || !at(b, 0, 'RIFF') || !at(b, 8, 'WEBP')) return;
37
+ if (at(b, 12, 'VP8 ') && at(b, 23, '\x9d\x01\x2a')) {
38
+ return {
39
+ w: le16(b, 26) & 0x3fff,
40
+ h: le16(b, 28) & 0x3fff
41
+ };
42
+ }
43
+ if (at(b, 12, 'VP8L') && b[20] == 0x2f) {
44
+ let bits = le32(b, 21);
45
+ return {
46
+ w: (bits & 0x3fff) + 1,
47
+ h: (bits >>> 14 & 0x3fff) + 1
48
+ };
49
+ }
50
+ if (at(b, 12, 'VP8X')) return {
51
+ w: le24(b, 24) + 1,
52
+ h: le24(b, 27) + 1
53
+ };
54
+ };
55
+ // A JPEG states its size in a frame header somewhere after the start, so the
56
+ // markers are walked until one is found: each carries its own length, a handful
57
+ // stand alone, and any of the SOF variants opens with precision, height, width.
58
+ // The walk stops at the start of scan — past it the bytes are entropy-coded,
59
+ // and an 0xff there is data, not a marker.
60
+ let SOF = (m)=>m >= 0xc0 && m <= 0xcf && m != 0xc4 && m != 0xc8 && m != 0xcc;
61
+ let jpeg = (b)=>{
62
+ if (!at(b, 0, '\xff\xd8')) return;
63
+ for(let i = 2; i + 9 < b.length;){
64
+ if (b[i] != 0xff) return;
65
+ let m = b[i + 1];
66
+ if (m == 0xff) i++; // fill bytes pad a marker
67
+ else if (m == 0xd8 || m == 0x01 || m >= 0xd0 && m <= 0xd7) i += 2;
68
+ else if (m == 0xda) return;
69
+ else if (SOF(m)) return {
70
+ w: be16(b, i + 7),
71
+ h: be16(b, i + 5)
72
+ };
73
+ else i += 2 + be16(b, i + 2);
74
+ }
75
+ };
76
+ /**
77
+ * What kind of picture the bytes are, read from their own signature — the one
78
+ * thing a caller can trust over the label it was handed — or `undefined` for
79
+ * anything that is not one of the four formats.
80
+ *
81
+ * ```ts
82
+ * import { assertEquals } from '@std/assert'
83
+ * import { mediaTypeOf } from '@yaks/blob'
84
+ *
85
+ * let png = new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a])
86
+ * assertEquals(mediaTypeOf(png), 'image/png')
87
+ * assertEquals(mediaTypeOf(new TextEncoder().encode('<svg/>')), undefined)
88
+ * ```
89
+ */ export let mediaTypeOf = (b)=>at(b, 0, '\x89PNG\r\n\x1a\n') ? 'image/png' : at(b, 0, '\xff\xd8\xff') ? 'image/jpeg' : at(b, 0, 'GIF87a') || at(b, 0, 'GIF89a') ? 'image/gif' : at(b, 0, 'RIFF') && at(b, 8, 'WEBP') ? 'image/webp' : undefined;
90
+ /**
91
+ * The size a file states about itself, or `undefined` — including for a header
92
+ * that states a zero, which is a broken file and not a picture of no width.
93
+ *
94
+ * ```ts
95
+ * import { assertEquals } from '@std/assert'
96
+ * import { sizeOf } from '@yaks/blob'
97
+ *
98
+ * // A PNG's signature and the head of its IHDR chunk: 1600 by 900.
99
+ * let png = new Uint8Array([
100
+ * 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a,
101
+ * 0, 0, 0, 13, 0x49, 0x48, 0x44, 0x52,
102
+ * 0, 0, 0x06, 0x40, 0, 0, 0x03, 0x84,
103
+ * ])
104
+ * assertEquals(sizeOf(png), { w: 1600, h: 900 })
105
+ * assertEquals(sizeOf(new TextEncoder().encode('%PDF-1.7')), undefined)
106
+ * ```
107
+ */ export let sizeOf = (b)=>{
108
+ let s = png(b) ?? jpeg(b) ?? gif(b) ?? webp(b);
109
+ return s && s.w > 0 && s.h > 0 ? s : undefined;
110
+ };
111
+ //# sourceMappingURL=image.js.map
package/image.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"image.js","sources":["./image.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,yEAAyE;AACzE,+EAA+E;AAC/E,8EAA8E;AAC9E,0EAA0E;AAC1E,kBAAkB;AAClB,EAAE;AACF,gFAAgF;AAChF,6EAA6E;AAC7E,0CAA0C;AAI1C,6EAA6E;AAC7E,4DAA4D;AAC5D,IAAI,KAAK,CAAC,GAAe,GAAW,MAClC;OAAI;GAAI,CAAC,KAAK,CAAC,CAAC,GAAG,IAAM,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,UAAU,CAAC;AAEpD,IAAI,OAAO,CAAC,GAAe,IAAc,AAAC,CAAC,CAAC,EAAE,IAAI,IAAK,CAAC,CAAC,IAAI,EAAE;AAC/D,IAAI,OAAO,CAAC,GAAe,IAAc,KAAK,GAAG,KAAK,UAAU,KAAK,GAAG,IAAI;AAC5E,IAAI,OAAO,CAAC,GAAe,IAAc,CAAC,CAAC,EAAE,GAAI,CAAC,CAAC,IAAI,EAAE,IAAI;AAC7D,IAAI,OAAO,CAAC,GAAe,IAAc,KAAK,GAAG,KAAM,CAAC,CAAC,IAAI,EAAE,IAAI;AACnE,IAAI,OAAO,CAAC,GAAe,IAAc,KAAK,GAAG,KAAK,CAAC,CAAC,IAAI,EAAE,GAAG;AAEjE,0EAA0E;AAC1E,IAAI,MAAM,CAAC,IACT,EAAE,MAAM,IAAI,MAAM,GAAG,GAAG,GAAG,wBAAwB,GAAG,GAAG,IAAI,UACzD;IAAE,GAAG,KAAK,GAAG;IAAK,GAAG,KAAK,GAAG;EAAI,IACjC;AAEN,oEAAoE;AACpE,IAAI,MAAM,CAAC,IACT,EAAE,MAAM,IAAI,MAAM,CAAC,GAAG,GAAG,GAAG,aAAa,GAAG,GAAG,GAAG,SAAS,IACvD;IAAE,GAAG,KAAK,GAAG;IAAI,GAAG,KAAK,GAAG;EAAG,IAC/B;AAEN,gFAAgF;AAChF,8EAA8E;AAC9E,gFAAgF;AAChF,cAAc;AACd,IAAI,OAAO,CAAC;EACV,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,GAAG,GAAG,GAAG,WAAW,CAAC,GAAG,GAAG,GAAG,SAAS;EAC7D,IAAI,GAAG,GAAG,IAAI,WAAW,GAAG,GAAG,IAAI,iBAAiB;IAClD,OAAO;MAAE,GAAG,KAAK,GAAG,MAAM;MAAQ,GAAG,KAAK,GAAG,MAAM;IAAO;EAC5D;EACA,IAAI,GAAG,GAAG,IAAI,WAAW,CAAC,CAAC,GAAG,IAAI,MAAM;IACtC,IAAI,OAAO,KAAK,GAAG;IACnB,OAAO;MAAE,GAAG,CAAC,OAAO,MAAM,IAAI;MAAG,GAAG,CAAC,AAAC,SAAS,KAAM,MAAM,IAAI;IAAE;EACnE;EACA,IAAI,GAAG,GAAG,IAAI,SAAS,OAAO;IAAE,GAAG,KAAK,GAAG,MAAM;IAAG,GAAG,KAAK,GAAG,MAAM;EAAE;AACzE;AAEA,6EAA6E;AAC7E,gFAAgF;AAChF,gFAAgF;AAChF,6EAA6E;AAC7E,2CAA2C;AAC3C,IAAI,MAAM,CAAC,IACT,KAAK,QAAQ,KAAK,QAAQ,KAAK,QAAQ,KAAK,QAAQ,KAAK;AAE3D,IAAI,OAAO,CAAC;EACV,IAAI,CAAC,GAAG,GAAG,GAAG,aAAa;EAC3B,IAAK,IAAI,IAAI,GAAG,IAAI,IAAI,EAAE,MAAM,EAAG;IACjC,IAAI,CAAC,CAAC,EAAE,IAAI,MAAM;IAClB,IAAI,IAAI,CAAC,CAAC,IAAI,EAAE;IAChB,IAAI,KAAK,MAAM,KAAI,0BAA0B;SACxC,IAAI,KAAK,QAAQ,KAAK,QAAS,KAAK,QAAQ,KAAK,MAAO,KAAK;SAC7D,IAAI,KAAK,MAAM;SACf,IAAI,IAAI,IAAI,OAAO;MAAE,GAAG,KAAK,GAAG,IAAI;MAAI,GAAG,KAAK,GAAG,IAAI;IAAG;SAC1D,KAAK,IAAI,KAAK,GAAG,IAAI;EAC5B;AACF;AAEA;;;;;;;;;;;;;CAaC,GACD,OAAO,IAAI,cAAc,CAAC,IACxB,GAAG,GAAG,GAAG,uBACL,cACA,GAAG,GAAG,GAAG,kBACT,eACA,GAAG,GAAG,GAAG,aAAa,GAAG,GAAG,GAAG,YAC/B,cACA,GAAG,GAAG,GAAG,WAAW,GAAG,GAAG,GAAG,UAC7B,eACA,UAAS;AAEf;;;;;;;;;;;;;;;;;CAiBC,GACD,OAAO,IAAI,SAAS,CAAC;EACnB,IAAI,IAAI,IAAI,MAAM,KAAK,MAAM,IAAI,MAAM,KAAK;EAC5C,OAAO,KAAK,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,GAAG,IAAI,IAAI;AACvC,EAAC"}
package/image.ts ADDED
@@ -0,0 +1,120 @@
1
+ // A picture's dimensions, read out of its own first bytes. A page wants to
2
+ // reserve a photo's space before the bytes arrive, so whoever stores one
3
+ // records `{w, h}` beside it — from the header, never by decoding: the size is
4
+ // written down in the first few dozen bytes of every format that has one, and
5
+ // there is no reason to unpack 20 MB of pixels to learn a number the file
6
+ // already states.
7
+ //
8
+ // Four formats state it — png, jpeg, gif, webp — and anything else gets no size
9
+ // at all. A guess would be worse than nothing: a page can measure the bitmap
10
+ // itself, but it cannot un-believe a row.
11
+
12
+ export type Size = { w: number; h: number }
13
+
14
+ // Whether the bytes at `i` are this ASCII string — a format's own signature,
15
+ // written the way the spec writes it ('\x89PNG\r\n\x1a\n').
16
+ let at = (b: Uint8Array, i: number, sig: string) =>
17
+ [...sig].every((c, j) => b[i + j] == c.charCodeAt(0))
18
+
19
+ let be16 = (b: Uint8Array, i: number) => (b[i] << 8) | b[i + 1]
20
+ let be32 = (b: Uint8Array, i: number) => be16(b, i) * 0x10000 + be16(b, i + 2)
21
+ let le16 = (b: Uint8Array, i: number) => b[i] | (b[i + 1] << 8)
22
+ let le24 = (b: Uint8Array, i: number) => le16(b, i) | (b[i + 2] << 16)
23
+ let le32 = (b: Uint8Array, i: number) => le24(b, i) + b[i + 3] * 0x1000000
24
+
25
+ // PNG: the IHDR chunk is always first, and opens with the two dimensions.
26
+ let png = (b: Uint8Array) =>
27
+ b.length >= 24 && at(b, 0, '\x89PNG\r\n\x1a\n') && at(b, 12, 'IHDR')
28
+ ? { w: be32(b, 16), h: be32(b, 20) }
29
+ : undefined
30
+
31
+ // GIF: the logical screen, little-endian, right behind the version.
32
+ let gif = (b: Uint8Array) =>
33
+ b.length >= 10 && (at(b, 0, 'GIF87a') || at(b, 0, 'GIF89a'))
34
+ ? { w: le16(b, 6), h: le16(b, 8) }
35
+ : undefined
36
+
37
+ // WebP is three formats in a RIFF wrapper, each stating its size in a different
38
+ // place: lossy after the keyframe's sync code, lossless packed 14 bits apiece
39
+ // into one little-endian word, and extended as the canvas size, stored one less
40
+ // than it is.
41
+ let webp = (b: Uint8Array) => {
42
+ if (b.length < 30 || !at(b, 0, 'RIFF') || !at(b, 8, 'WEBP')) return
43
+ if (at(b, 12, 'VP8 ') && at(b, 23, '\x9d\x01\x2a')) {
44
+ return { w: le16(b, 26) & 0x3fff, h: le16(b, 28) & 0x3fff }
45
+ }
46
+ if (at(b, 12, 'VP8L') && b[20] == 0x2f) {
47
+ let bits = le32(b, 21)
48
+ return { w: (bits & 0x3fff) + 1, h: ((bits >>> 14) & 0x3fff) + 1 }
49
+ }
50
+ if (at(b, 12, 'VP8X')) return { w: le24(b, 24) + 1, h: le24(b, 27) + 1 }
51
+ }
52
+
53
+ // A JPEG states its size in a frame header somewhere after the start, so the
54
+ // markers are walked until one is found: each carries its own length, a handful
55
+ // stand alone, and any of the SOF variants opens with precision, height, width.
56
+ // The walk stops at the start of scan — past it the bytes are entropy-coded,
57
+ // and an 0xff there is data, not a marker.
58
+ let SOF = (m: number) =>
59
+ m >= 0xc0 && m <= 0xcf && m != 0xc4 && m != 0xc8 && m != 0xcc
60
+
61
+ let jpeg = (b: Uint8Array) => {
62
+ if (!at(b, 0, '\xff\xd8')) return
63
+ for (let i = 2; i + 9 < b.length;) {
64
+ if (b[i] != 0xff) return
65
+ let m = b[i + 1]
66
+ if (m == 0xff) i++ // fill bytes pad a marker
67
+ else if (m == 0xd8 || m == 0x01 || (m >= 0xd0 && m <= 0xd7)) i += 2
68
+ else if (m == 0xda) return
69
+ else if (SOF(m)) return { w: be16(b, i + 7), h: be16(b, i + 5) }
70
+ else i += 2 + be16(b, i + 2)
71
+ }
72
+ }
73
+
74
+ /**
75
+ * What kind of picture the bytes are, read from their own signature — the one
76
+ * thing a caller can trust over the label it was handed — or `undefined` for
77
+ * anything that is not one of the four formats.
78
+ *
79
+ * ```ts
80
+ * import { assertEquals } from '@std/assert'
81
+ * import { mediaTypeOf } from '@yaks/blob'
82
+ *
83
+ * let png = new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a])
84
+ * assertEquals(mediaTypeOf(png), 'image/png')
85
+ * assertEquals(mediaTypeOf(new TextEncoder().encode('<svg/>')), undefined)
86
+ * ```
87
+ */
88
+ export let mediaTypeOf = (b: Uint8Array): string | undefined =>
89
+ at(b, 0, '\x89PNG\r\n\x1a\n')
90
+ ? 'image/png'
91
+ : at(b, 0, '\xff\xd8\xff')
92
+ ? 'image/jpeg'
93
+ : at(b, 0, 'GIF87a') || at(b, 0, 'GIF89a')
94
+ ? 'image/gif'
95
+ : at(b, 0, 'RIFF') && at(b, 8, 'WEBP')
96
+ ? 'image/webp'
97
+ : undefined
98
+
99
+ /**
100
+ * The size a file states about itself, or `undefined` — including for a header
101
+ * that states a zero, which is a broken file and not a picture of no width.
102
+ *
103
+ * ```ts
104
+ * import { assertEquals } from '@std/assert'
105
+ * import { sizeOf } from '@yaks/blob'
106
+ *
107
+ * // A PNG's signature and the head of its IHDR chunk: 1600 by 900.
108
+ * let png = new Uint8Array([
109
+ * 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a,
110
+ * 0, 0, 0, 13, 0x49, 0x48, 0x44, 0x52,
111
+ * 0, 0, 0x06, 0x40, 0, 0, 0x03, 0x84,
112
+ * ])
113
+ * assertEquals(sizeOf(png), { w: 1600, h: 900 })
114
+ * assertEquals(sizeOf(new TextEncoder().encode('%PDF-1.7')), undefined)
115
+ * ```
116
+ */
117
+ export let sizeOf = (b: Uint8Array): Size | undefined => {
118
+ let s = png(b) ?? jpeg(b) ?? gif(b) ?? webp(b)
119
+ return s && s.w > 0 && s.h > 0 ? s : undefined
120
+ }
package/keywords.js ADDED
@@ -0,0 +1,28 @@
1
+ // The registration: what @yaks/blob adds to a component vocabulary, declared in
2
+ // JSON Schema's own extension form. `meta/blob.vocab.json` is the authored
3
+ // source (the keyword's schema and its prose); this module gives it a URI and
4
+ // wraps it in the shape `loadVocab(docs, [blobKeywords])` accepts.
5
+ //
6
+ // One keyword, on a property rather than a component, because what varies from
7
+ // application to application is which values are too big — or too repeated — to
8
+ // keep in the row. The schema language itself has no opinion about that; it
9
+ // only carries the keyword.
10
+ import doc from './meta/blob.vocab.json' with {
11
+ type: 'json'
12
+ };
13
+ /** The URI a vocabulary file lists under `$vocabulary` to use `store` and
14
+ * `address`. */ export let BLOB_URI = 'https://yak.sh/vocab/blob';
15
+ /**
16
+ * The `store` and `address` keyword vocabulary, ready to register:
17
+ * `loadVocab(docs, [blobKeywords])` carries each property's declaration onto
18
+ * `v.prop(comp, prop).keywords.store`, which is where {@link bodies} reads
19
+ * it.
20
+ */ export let blobKeywords = {
21
+ uri: BLOB_URI,
22
+ prop: [
23
+ 'store',
24
+ 'address'
25
+ ],
26
+ doc
27
+ };
28
+ //# sourceMappingURL=keywords.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keywords.js","sources":["./keywords.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,2EAA2E;AAC3E,8EAA8E;AAC9E,mEAAmE;AACnE,EAAE;AACF,+EAA+E;AAC/E,gFAAgF;AAChF,4EAA4E;AAC5E,4BAA4B;AAG5B,OAAO,SAAS,8BAA8B;EAAE,MAAM;AAAO,EAAC;AAE9D;cACc,GACd,OAAO,IAAI,WAAW,4BAA2B;AAEjD;;;;;CAKC,GACD,OAAO,IAAI,eAAyB;EAClC,KAAK;EACL,MAAM;IAAC;IAAS;GAAU;EAC1B;AACF,EAAC"}
package/keywords.ts ADDED
@@ -0,0 +1,28 @@
1
+ // The registration: what @yaks/blob adds to a component vocabulary, declared in
2
+ // JSON Schema's own extension form. `meta/blob.vocab.json` is the authored
3
+ // source (the keyword's schema and its prose); this module gives it a URI and
4
+ // wraps it in the shape `loadVocab(docs, [blobKeywords])` accepts.
5
+ //
6
+ // One keyword, on a property rather than a component, because what varies from
7
+ // application to application is which values are too big — or too repeated — to
8
+ // keep in the row. The schema language itself has no opinion about that; it
9
+ // only carries the keyword.
10
+
11
+ import type { Keywords } from 'jsr:@yaks/vocab@0.2.36'
12
+ import doc from './meta/blob.vocab.json' with { type: 'json' }
13
+
14
+ /** The URI a vocabulary file lists under `$vocabulary` to use `store` and
15
+ * `address`. */
16
+ export let BLOB_URI = 'https://yak.sh/vocab/blob'
17
+
18
+ /**
19
+ * The `store` and `address` keyword vocabulary, ready to register:
20
+ * `loadVocab(docs, [blobKeywords])` carries each property's declaration onto
21
+ * `v.prop(comp, prop).keywords.store`, which is where {@link bodies} reads
22
+ * it.
23
+ */
24
+ export let blobKeywords: Keywords = {
25
+ uri: BLOB_URI,
26
+ prop: ['store', 'address'],
27
+ doc,
28
+ }
@@ -0,0 +1,17 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://yak.sh/vocab/blob",
4
+ "title": "yaks blob keyword vocabulary",
5
+ "description": "The keywords @yaks/blob adds to a component vocabulary. A string property declaring `store: \"blob\"` keeps its value in a content-addressed store instead of in the row: the row holds the value's hash, the store holds the bytes, and both the write and the read go through unchanged — a writer sends text and a reader gets text back. A property declaring `address: true` holds such an address itself.",
6
+ "$comment": "A vocabulary declaration in the JSON Schema sense: a URI naming this keyword set, plus the schema of each keyword. A vocab file declares it under $vocabulary; a loader registers it with loadVocab(docs, [blobKeywords]).",
7
+ "$defs": {
8
+ "store": {
9
+ "description": "Where this property's value is kept. \"blob\" moves it to a content-addressed store, keyed by the SHA-256 of the text — so two rows holding the same long value hold one copy of it. The property stays an ordinary string property everywhere else: it is declared, queried and written as text.",
10
+ "enum": ["blob"]
11
+ },
12
+ "address": {
13
+ "description": "This property's value is the address of bytes in the content-addressed store, written there by its package rather than substituted for text. While any row names an address, by this keyword or `store: \"blob\"`, its bytes are kept.",
14
+ "type": "boolean"
15
+ }
16
+ }
17
+ }
package/mime.js ADDED
@@ -0,0 +1,72 @@
1
+ // The media type of a named file. App assets and named uploads use the same
2
+ // vocabulary; a caller's specific Content-Type still takes precedence.
3
+ let MIME = {
4
+ html: 'text/html; charset=utf-8',
5
+ htm: 'text/html; charset=utf-8',
6
+ css: 'text/css; charset=utf-8',
7
+ js: 'text/javascript; charset=utf-8',
8
+ mjs: 'text/javascript; charset=utf-8',
9
+ cjs: 'text/javascript; charset=utf-8',
10
+ json: 'application/json',
11
+ map: 'application/json',
12
+ webmanifest: 'application/manifest+json',
13
+ xml: 'application/xml',
14
+ rss: 'application/rss+xml',
15
+ atom: 'application/atom+xml',
16
+ svg: 'image/svg+xml',
17
+ png: 'image/png',
18
+ apng: 'image/apng',
19
+ jpg: 'image/jpeg',
20
+ jpeg: 'image/jpeg',
21
+ gif: 'image/gif',
22
+ webp: 'image/webp',
23
+ avif: 'image/avif',
24
+ ico: 'image/x-icon',
25
+ txt: 'text/plain; charset=utf-8',
26
+ // TypeScript source, which every browser shows as text; the extension is
27
+ // also MPEG-TS's, but an app's .ts is far more often its source.
28
+ ts: 'text/plain; charset=utf-8',
29
+ mts: 'text/plain; charset=utf-8',
30
+ cts: 'text/plain; charset=utf-8',
31
+ md: 'text/markdown; charset=utf-8',
32
+ csv: 'text/csv; charset=utf-8',
33
+ vtt: 'text/vtt; charset=utf-8',
34
+ ics: 'text/calendar; charset=utf-8',
35
+ woff: 'font/woff',
36
+ woff2: 'font/woff2',
37
+ ttf: 'font/ttf',
38
+ otf: 'font/otf',
39
+ wasm: 'application/wasm',
40
+ glb: 'model/gltf-binary',
41
+ gltf: 'model/gltf+json',
42
+ zip: 'application/zip',
43
+ pdf: 'application/pdf',
44
+ mp4: 'video/mp4',
45
+ m4v: 'video/x-m4v',
46
+ mov: 'video/quicktime',
47
+ webm: 'video/webm',
48
+ ogv: 'video/ogg',
49
+ mp3: 'audio/mpeg',
50
+ m4a: 'audio/mp4',
51
+ aac: 'audio/aac',
52
+ wav: 'audio/wav',
53
+ oga: 'audio/ogg',
54
+ ogg: 'audio/ogg',
55
+ opus: 'audio/ogg',
56
+ flac: 'audio/flac',
57
+ m3u8: 'application/vnd.apple.mpegurl',
58
+ mpd: 'application/dash+xml'
59
+ };
60
+ ///
61
+ /// mimeOf('dist/_astro/hero.avif') -> 'image/avif'
62
+ /// mimeOf('feed.xml') -> 'application/xml'
63
+ /// mimeOf('fonts/Inter.ttf') -> 'font/ttf'
64
+ /// mimeOf('src/setup.ts') -> 'text/plain; charset=utf-8'
65
+ /// mimeOf('LICENSE') -> 'application/octet-stream'
66
+ export let mimeOf = (name)=>{
67
+ let base = name.split('/').pop() ?? '';
68
+ let dot = base.lastIndexOf('.');
69
+ let ext = dot < 0 ? '' : base.slice(dot + 1).toLowerCase();
70
+ return MIME[ext] ?? 'application/octet-stream';
71
+ };
72
+ //# sourceMappingURL=mime.js.map
package/mime.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mime.js","sources":["./mime.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,uEAAuE;AAEvE,IAAI,OAA+B;EACjC,MAAM;EACN,KAAK;EACL,KAAK;EACL,IAAI;EACJ,KAAK;EACL,KAAK;EACL,MAAM;EACN,KAAK;EACL,aAAa;EACb,KAAK;EACL,KAAK;EACL,MAAM;EACN,KAAK;EACL,KAAK;EACL,MAAM;EACN,KAAK;EACL,MAAM;EACN,KAAK;EACL,MAAM;EACN,MAAM;EACN,KAAK;EACL,KAAK;EACL,yEAAyE;EACzE,iEAAiE;EACjE,IAAI;EACJ,KAAK;EACL,KAAK;EACL,IAAI;EACJ,KAAK;EACL,KAAK;EACL,KAAK;EACL,MAAM;EACN,OAAO;EACP,KAAK;EACL,KAAK;EACL,MAAM;EACN,KAAK;EACL,MAAM;EACN,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,MAAM;EACN,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,MAAM;EACN,MAAM;EACN,MAAM;EACN,KAAK;AACP;AAEA,GAAG;AACH,mDAAmD;AACnD,2CAA2C;AAC3C,2CAA2C;AAC3C,yDAAyD;AACzD,mDAAmD;AACnD,OAAO,IAAI,SAAS,CAAC;EACnB,IAAI,OAAO,KAAK,KAAK,CAAC,KAAK,GAAG,MAAM;EACpC,IAAI,MAAM,KAAK,WAAW,CAAC;EAC3B,IAAI,MAAM,MAAM,IAAI,KAAK,KAAK,KAAK,CAAC,MAAM,GAAG,WAAW;EACxD,OAAO,IAAI,CAAC,IAAI,IAAI;AACtB,EAAC"}