foldkit-media 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/README.md +167 -66
  2. package/client.d.ts +2 -2
  3. package/dist/{asset-BNQ_j5tO.d.mts → asset-BLo8VWmd.d.mts} +32 -5
  4. package/dist/asset-BLo8VWmd.d.mts.map +1 -0
  5. package/dist/browser/index.d.mts +86 -4
  6. package/dist/browser/index.d.mts.map +1 -1
  7. package/dist/browser/index.mjs +88 -7
  8. package/dist/browser/index.mjs.map +1 -1
  9. package/dist/cloudflare/index.d.mts +13 -9
  10. package/dist/cloudflare/index.d.mts.map +1 -1
  11. package/dist/cloudflare/index.mjs +28 -12
  12. package/dist/cloudflare/index.mjs.map +1 -1
  13. package/dist/{describe-DdYvLhMY.d.mts → describe-BOgc0xbR.d.mts} +2 -6
  14. package/dist/describe-BOgc0xbR.d.mts.map +1 -0
  15. package/dist/{describe-Cqr63Gxa.mjs → describe-C6sWA_8p.mjs} +10 -10
  16. package/dist/describe-C6sWA_8p.mjs.map +1 -0
  17. package/dist/{errors-qETj7Pgi.mjs → errors-BhEgXJ4m.mjs} +2 -3
  18. package/dist/{errors-qETj7Pgi.mjs.map → errors-BhEgXJ4m.mjs.map} +1 -1
  19. package/dist/{format-BmfnR4jg.mjs → format-BCRTFU9j.mjs} +2 -3
  20. package/dist/{format-BmfnR4jg.mjs.map → format-BCRTFU9j.mjs.map} +1 -1
  21. package/dist/{icon-CowP8fQ0.mjs → icon-0A2dBtqj.mjs} +3 -4
  22. package/dist/{icon-CowP8fQ0.mjs.map → icon-0A2dBtqj.mjs.map} +1 -1
  23. package/dist/{icon-ClqtprHT.d.mts → icon-BGtxExTN.d.mts} +1 -2
  24. package/dist/{icon-ClqtprHT.d.mts.map → icon-BGtxExTN.d.mts.map} +1 -1
  25. package/dist/icons/index.d.mts +1 -3
  26. package/dist/icons/index.d.mts.map +1 -1
  27. package/dist/icons/index.mjs +2 -3
  28. package/dist/index.d.mts +13 -15
  29. package/dist/index.d.mts.map +1 -1
  30. package/dist/index.mjs +19 -21
  31. package/dist/index.mjs.map +1 -1
  32. package/dist/{limits-B6C9OOLl.mjs → limits-B4hHpyfE.mjs} +2 -3
  33. package/dist/{limits-B6C9OOLl.mjs.map → limits-B4hHpyfE.mjs.map} +1 -1
  34. package/dist/{provider-DztvQjOr.d.mts → provider-CB0nqu0m.d.mts} +21 -16
  35. package/dist/provider-CB0nqu0m.d.mts.map +1 -0
  36. package/dist/{rolldown-runtime-8H4AJuhK.mjs → rolldown-runtime-BJohB4LM.mjs} +1 -2
  37. package/dist/server/index.d.mts +34 -27
  38. package/dist/server/index.d.mts.map +1 -1
  39. package/dist/server/index.mjs +174 -8
  40. package/dist/server/index.mjs.map +1 -1
  41. package/dist/{services-BeakQl7F.mjs → services-7B4hsQM7.mjs} +3 -4
  42. package/dist/{services-BeakQl7F.mjs.map → services-7B4hsQM7.mjs.map} +1 -1
  43. package/dist/{services-Ck-7dhIP.d.mts → services-BZoK2VOY.d.mts} +3 -5
  44. package/dist/services-BZoK2VOY.d.mts.map +1 -0
  45. package/dist/sharp/index.d.mts +2 -4
  46. package/dist/sharp/index.d.mts.map +1 -1
  47. package/dist/sharp/index.mjs +5 -6
  48. package/dist/{upload-C5YM5jZR.mjs → stores-CxraN3kt.mjs} +128 -228
  49. package/dist/stores-CxraN3kt.mjs.map +1 -0
  50. package/dist/unpic/index.d.mts +2 -4
  51. package/dist/unpic/index.d.mts.map +1 -1
  52. package/dist/unpic/index.mjs +2 -3
  53. package/dist/{upload-C4_inwfv.d.mts → upload-lVLMRJoC.d.mts} +53 -24
  54. package/dist/upload-lVLMRJoC.d.mts.map +1 -0
  55. package/dist/{variant-BOg1M0Wj.d.mts → variant-B-vyMmFB.d.mts} +2 -3
  56. package/dist/{variant-BOg1M0Wj.d.mts.map → variant-B-vyMmFB.d.mts.map} +1 -1
  57. package/dist/vite/index.d.mts +1 -5
  58. package/dist/vite/index.d.mts.map +1 -1
  59. package/dist/vite/index.mjs +7 -9
  60. package/dist/vite/index.mjs.map +1 -1
  61. package/dist/{widths-BEa9odY6.mjs → widths-qp3jshiF.mjs} +3 -4
  62. package/dist/{widths-BEa9odY6.mjs.map → widths-qp3jshiF.mjs.map} +1 -1
  63. package/dist/{widths-Cg7-x89y.d.mts → widths-upkgLdek.d.mts} +1 -3
  64. package/dist/widths-upkgLdek.d.mts.map +1 -0
  65. package/package.json +6 -6
  66. package/dist/asset-BNQ_j5tO.d.mts.map +0 -1
  67. package/dist/describe-Cqr63Gxa.mjs.map +0 -1
  68. package/dist/describe-DdYvLhMY.d.mts.map +0 -1
  69. package/dist/provider-DztvQjOr.d.mts.map +0 -1
  70. package/dist/services-Ck-7dhIP.d.mts.map +0 -1
  71. package/dist/upload-C4_inwfv.d.mts.map +0 -1
  72. package/dist/upload-C5YM5jZR.mjs.map +0 -1
  73. package/dist/widths-Cg7-x89y.d.mts.map +0 -1
@@ -1,14 +1,18 @@
1
- import { n as Inspector } from "../describe-DdYvLhMY.mjs";
2
- import { a as Uploads, p as Admission } from "../upload-C4_inwfv.mjs";
3
- import { a as Transformer, i as Originals, o as Variants } from "../services-Ck-7dhIP.mjs";
1
+ import { n as Inspector } from "../describe-BOgc0xbR.mjs";
2
+ import { c as Uploads, t as StoredFacts, v as Admission } from "../upload-lVLMRJoC.mjs";
3
+ import { a as Transformer, i as Originals, o as Variants } from "../services-BZoK2VOY.mjs";
4
4
  import { Layer } from "effect";
5
5
  import { KeyValueStore } from "effect/persistence";
6
6
  import { Cache as Cache$1, ImagesBinding, R2Bucket, RateLimit } from "@cloudflare/workers-types";
7
- //#region src/cloudflare/index.d.ts
8
7
  /** Originals in an R2 bucket, each under its content hash. */
9
8
  export declare const originalsR2: (bucket: R2Bucket) => Layer.Layer<Originals>;
10
- /** Uploads into an R2 bucket, each under its content hash: what `originalsR2` reads. */
9
+ /**
10
+ * Uploads into an R2 bucket, each under its content hash, what `originalsR2`
11
+ * reads, and its facts under `facts/<hash>`, what `storedFactsR2` reads.
12
+ */
11
13
  export declare const uploadsR2: (bucket: R2Bucket) => Layer.Layer<Uploads>;
14
+ /** An upload's facts, read back from the bucket `uploadsR2` keeps them in. */
15
+ export declare const storedFactsR2: (bucket: R2Bucket) => Layer.Layer<StoredFacts>;
12
16
  /**
13
17
  * The Images binding as the transformer. It scales down, never up, and names
14
18
  * the format, so the variant is what its URL says. A spent allowance is
@@ -23,12 +27,13 @@ export declare const transformerImages: (images: ImagesBinding) => Layer.Layer<T
23
27
  export declare const keyValueStoreR2: (bucket: R2Bucket) => Layer.Layer<KeyValueStore.KeyValueStore>;
24
28
  /**
25
29
  * Variants kept in R2 under `prefix`, so one made last month is not made, and
26
- * billed, again: `variantsKeyValueStore` over `keyValueStoreR2`. With `cache`
27
- * (`caches.default`), the Cache API stands in front of it.
30
+ * billed, again: `variantsKeyValueStore` over `keyValueStoreR2`. With `cache`,
31
+ * the Cache API stands in front of it: `true` for the Worker's
32
+ * `caches.default`, or a cache of your own (`await caches.open(…)`).
28
33
  */
29
34
  export declare const variantsR2: (bucket: R2Bucket, options?: {
30
35
  readonly prefix?: string;
31
- readonly cache?: Cache$1;
36
+ readonly cache?: Cache$1 | true;
32
37
  }) => Layer.Layer<Variants>;
33
38
  /**
34
39
  * Admission through a Workers rate-limit binding (`[[ratelimits]]`), whose
@@ -49,5 +54,4 @@ export declare const admissionRateLimit: (binding: RateLimit, options?: {
49
54
  * is refused.
50
55
  */
51
56
  export declare const inspectorImages: (images: ImagesBinding) => Layer.Layer<Inspector>;
52
- //#endregion
53
57
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":["Cache"],"sources":["../../src/cloudflare/index.ts"],"mappings":";;;;;;;;qBAiBa,cAAW,QAAY,aAAW,MAAM,MAAM;;qBAiB9C,YAAS,QAAY,aAAW,MAAM,MAAM;;;;;;qBAgB5C,oBAAiB,QAAY,kBAAgB,MAAM,MAAM;;;;;;qBAsCzD,kBAAe,QAAY,aAAW,MAAM,MAAM,cAAc;;;;;;qBA6GhE,aAAU,QACb,UAAQ;WACI;WAA0B,QAAQA;MACrD,MAAM,MAAM;;;;;;;qBAiBF,qBAAkB,SACpB,WAAS;WACE;MACnB,MAAM,MAAM;;;;;;;;;;qBA0BF,kBAAe,QAAY,kBAAgB,MAAM,MAAM"}
1
+ {"version":3,"file":"index.d.mts","names":["Cache"],"sources":["../../src/cloudflare/index.ts"],"mappings":";;;;;;;qBAuBa,cAAW,QAAY,aAAW,MAAM,MAAM;;;;;qBAoB9C,YAAS,QAAY,aAAW,MAAM,MAAM;;qBAU5C,gBAAa,QAAY,aAAW,MAAM,MAAM;;;;;;qBAoBhD,oBAAiB,QAAY,kBAAgB,MAAM,MAAM;;;;;;qBAsCzD,kBAAe,QAAY,aAAW,MAAM,MAAM,cAAc;;;;;;;qBA2HhE,aAAU,QACb,UAAQ;WACI;WAA0B,QAAQA;MACrD,MAAM,MAAM;;;;;;;qBAiBF,qBAAkB,SACpB,WAAS;WACE;MACnB,MAAM,MAAM;;;;;;;;;;qBA0BF,kBAAe,QAAY,kBAAgB,MAAM,MAAM"}
@@ -1,17 +1,28 @@
1
- import { t as Inspector } from "../describe-Cqr63Gxa.mjs";
2
- import { i as TransformFailed, r as QuotaExhausted, t as OriginalNotFound } from "../errors-qETj7Pgi.mjs";
3
- import { _ as Admission, d as makeVariants, i as Uploads, v as RateLimited } from "../upload-C5YM5jZR.mjs";
4
- import { n as Transformer, r as Variants, t as Originals } from "../services-BeakQl7F.mjs";
1
+ import { t as Inspector } from "../describe-C6sWA_8p.mjs";
2
+ import { i as TransformFailed, r as QuotaExhausted, t as OriginalNotFound } from "../errors-BhEgXJ4m.mjs";
3
+ import { S as RateLimited, d as encodeFacts, f as factsKey, i as StoredFacts, l as Uploads, t as makeVariants, u as decodeFacts, x as Admission } from "../stores-CxraN3kt.mjs";
4
+ import { n as Transformer, r as Variants, t as Originals } from "../services-7B4hsQM7.mjs";
5
5
  import { Effect, Layer, Option } from "effect";
6
6
  import { KeyValueStore } from "effect/persistence";
7
- //#region src/cloudflare/index.ts
7
+ // src/cloudflare/index.ts
8
8
  /** Originals in an R2 bucket, each under its content hash. */
9
9
  const originalsR2 = (bucket) => Layer.succeed(Originals, { get: (hash) => Effect.promise(() => bucket.get(hash)).pipe(Effect.flatMap((object) => object === null ? Effect.fail(new OriginalNotFound({ hash })) : Effect.succeed({
10
10
  body: object.body,
11
11
  size: object.size
12
12
  }))) });
13
- /** Uploads into an R2 bucket, each under its content hash: what `originalsR2` reads. */
14
- const uploadsR2 = (bucket) => Layer.succeed(Uploads, { put: (hash, bytes) => Effect.promise(() => bucket.put(hash, bytes)).pipe(Effect.asVoid) });
13
+ /**
14
+ * Uploads into an R2 bucket, each under its content hash, what `originalsR2`
15
+ * reads, and its facts under `facts/<hash>`, what `storedFactsR2` reads.
16
+ */
17
+ const uploadsR2 = (bucket) => Layer.succeed(Uploads, { put: (hash, bytes, facts) => Effect.promise(async () => {
18
+ await bucket.put(hash, bytes);
19
+ await bucket.put(factsKey(hash), encodeFacts(facts));
20
+ }) });
21
+ /** An upload's facts, read back from the bucket `uploadsR2` keeps them in. */
22
+ const storedFactsR2 = (bucket) => Layer.succeed(StoredFacts, { get: (hash) => Effect.promise(async () => {
23
+ const object = await bucket.get(factsKey(hash));
24
+ return object === null ? Option.none() : Option.some(decodeFacts(await object.text()));
25
+ }) });
15
26
  const QUOTA_EXHAUSTED = 9422;
16
27
  const isImagesError = (cause) => typeof cause === "object" && cause !== null && typeof Reflect.get(cause, "code") === "number";
17
28
  /**
@@ -114,16 +125,22 @@ const withEdge = (behind, edge) => {
114
125
  put: (key, encoded) => behind.put(key, encoded).pipe(Effect.andThen(fill(key, encoded)))
115
126
  };
116
127
  };
128
+ const cacheOf = (cache) => {
129
+ if (cache !== true) return cache;
130
+ if (typeof caches === "undefined") throw new Error("variantsR2: `cache: true` reads the Worker global `caches.default`, which this runtime lacks");
131
+ return caches.default;
132
+ };
117
133
  /**
118
134
  * Variants kept in R2 under `prefix`, so one made last month is not made, and
119
- * billed, again: `variantsKeyValueStore` over `keyValueStoreR2`. With `cache`
120
- * (`caches.default`), the Cache API stands in front of it.
135
+ * billed, again: `variantsKeyValueStore` over `keyValueStoreR2`. With `cache`,
136
+ * the Cache API stands in front of it: `true` for the Worker's
137
+ * `caches.default`, or a cache of your own (`await caches.open(…)`).
121
138
  */
122
139
  const variantsR2 = (bucket, options = {}) => {
123
140
  const kept = makeVariants(KeyValueStore.prefix(r2Store(bucket), options.prefix ?? "variants/"));
124
141
  return Layer.succeed(Variants, Option.match(Option.fromNullishOr(options.cache), {
125
142
  onNone: () => kept,
126
- onSome: (edge) => withEdge(kept, edge)
143
+ onSome: (cache) => withEdge(kept, cacheOf(cache))
127
144
  }));
128
145
  };
129
146
  /**
@@ -151,7 +168,6 @@ const inspectorImages = (images) => Layer.succeed(Inspector, { inspect: (bytes)
151
168
  alpha: info.format !== "image/jpeg",
152
169
  thumbnail: Option.none()
153
170
  }) : Effect.fail(info)), Effect.catch((cause) => Effect.logWarning("Media.inspect failed", cause).pipe(Effect.andThen(Effect.fail(new TransformFailed({})))))) });
154
- //#endregion
155
- export { admissionRateLimit, inspectorImages, keyValueStoreR2, originalsR2, transformerImages, uploadsR2, variantsR2 };
171
+ export { admissionRateLimit, inspectorImages, keyValueStoreR2, originalsR2, storedFactsR2, transformerImages, uploadsR2, variantsR2 };
156
172
 
157
173
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../../src/cloudflare/index.ts"],"sourcesContent":["/**\n * The media server's services on Cloudflare: originals in R2, the Images\n * binding as the transformer, and variants kept in R2 behind the Cache API.\n * Each takes the binding it needs, so build them in `serveFetch`'s `layer`\n * from the request's environment.\n */\nimport type { Cache, ImagesBinding, R2Bucket, RateLimit } from '@cloudflare/workers-types'\nimport { Effect, Layer, Option } from 'effect'\nimport { KeyValueStore } from 'effect/persistence'\nimport { Admission, RateLimited } from '../server/admission.js'\nimport { Inspector } from '../describe.js'\nimport { OriginalNotFound, QuotaExhausted, TransformFailed } from '../server/errors.js'\nimport { Originals, Transformer, Variants, type Encoded, type Kept } from '../server/services.js'\nimport { Uploads } from '../server/upload.js'\nimport { makeVariants } from '../server/stores.js'\n\n/** Originals in an R2 bucket, each under its content hash. */\nexport const originalsR2 = (bucket: R2Bucket): Layer.Layer<Originals> =>\n Layer.succeed(Originals, {\n get: hash =>\n Effect.promise(() => bucket.get(hash)).pipe(\n Effect.flatMap(object =>\n object === null\n ? Effect.fail(new OriginalNotFound({ hash }))\n : Effect.succeed({\n // The two runtimes' stream types differ only in their declarations.\n body: object.body as unknown as ReadableStream<Uint8Array>,\n size: object.size,\n }),\n ),\n ),\n })\n\n/** Uploads into an R2 bucket, each under its content hash: what `originalsR2` reads. */\nexport const uploadsR2 = (bucket: R2Bucket): Layer.Layer<Uploads> =>\n Layer.succeed(Uploads, {\n put: (hash, bytes) => Effect.promise(() => bucket.put(hash, bytes)).pipe(Effect.asVoid),\n })\n\n// Cloudflare's code for a spent transformation allowance.\nconst QUOTA_EXHAUSTED = 9422\n\nconst isImagesError = (cause: unknown): cause is { readonly code: number } =>\n typeof cause === 'object' && cause !== null && typeof Reflect.get(cause, 'code') === 'number'\n\n/**\n * The Images binding as the transformer. It scales down, never up, and names\n * the format, so the variant is what its URL says. A spent allowance is\n * `QuotaExhausted`; any other refusal is `TransformFailed`, its reason logged.\n */\nexport const transformerImages = (images: ImagesBinding): Layer.Layer<Transformer> =>\n Layer.succeed(Transformer, {\n transform: (original, variant) =>\n Effect.tryPromise({\n try: async () => {\n const result = await images\n .input(original.body as unknown as Parameters<ImagesBinding['input']>[0])\n .transform({ width: variant.width, fit: 'scale-down' })\n .output({\n format: `image/${variant.format}`,\n ...Option.match(variant.quality, {\n onNone: () => ({}),\n onSome: quality => ({ quality }),\n }),\n })\n const response = result.response()\n return {\n bytes: new Uint8Array(await response.arrayBuffer()),\n contentType: result.contentType(),\n }\n },\n catch: cause => cause,\n }).pipe(\n Effect.catch((cause): Effect.Effect<never, QuotaExhausted | TransformFailed> =>\n isImagesError(cause) && cause.code === QUOTA_EXHAUSTED\n ? Effect.fail(new QuotaExhausted({}))\n : Effect.logWarning('Media.transform failed', cause).pipe(\n Effect.andThen(Effect.fail(new TransformFailed({}))),\n ),\n ),\n ),\n })\n\n/**\n * An R2 bucket as an Effect `KeyValueStore`, for anything that keeps bytes by\n * key: `variantsKeyValueStore`, `originalsKeyValueStore`, or the\n * application's own. `clear` and `size` list the whole bucket.\n */\nexport const keyValueStoreR2 = (bucket: R2Bucket): Layer.Layer<KeyValueStore.KeyValueStore> =>\n Layer.succeed(KeyValueStore.KeyValueStore, r2Store(bucket))\n\nconst r2Store = (bucket: R2Bucket): KeyValueStore.KeyValueStore => {\n const attempt = <A>(method: string, key: string | undefined, run: () => Promise<A>) =>\n Effect.tryPromise({\n try: run,\n catch: cause =>\n new KeyValueStore.KeyValueStoreError({\n message: `R2 ${method} failed`,\n method,\n ...(key === undefined ? {} : { key }),\n cause,\n }),\n })\n // Every key in the bucket, a page of listing at a time.\n const keys = async () => {\n const found: Array<string> = []\n let cursor: string | undefined\n do {\n const page = await bucket.list(cursor === undefined ? {} : { cursor })\n found.push(...page.objects.map(object => object.key))\n cursor = page.truncated ? page.cursor : undefined\n } while (cursor !== undefined)\n return found\n }\n return KeyValueStore.make({\n get: key => attempt('get', key, async () => (await bucket.get(key))?.text()),\n getUint8Array: key =>\n attempt('getUint8Array', key, async () => {\n const object = await bucket.get(key)\n return object === null ? undefined : new Uint8Array(await object.arrayBuffer())\n }),\n set: (key, value) => attempt('set', key, async () => void (await bucket.put(key, value))),\n remove: key => attempt('remove', key, () => bucket.delete(key)),\n clear: attempt('clear', undefined, async () => {\n const all = await keys()\n // R2 deletes at most 1,000 keys a call.\n for (let at = 0; at < all.length; at += 1000) await bucket.delete(all.slice(at, at + 1000))\n }),\n size: attempt('size', undefined, async () => (await keys()).length),\n })\n}\n\n// The Cache API keys by request; this origin is never fetched.\nconst edgeKey = (key: string) => `https://foldkit-media.invalid/${key}`\n\n/**\n * Variants with the edge's Cache API in front: read there first, and filled\n * from what is kept behind it, so a popular variant is served from the edge.\n */\nconst withEdge = (behind: Variants['Service'], edge: Cache): Variants['Service'] => {\n const fill = (key: string, encoded: Encoded) =>\n Effect.tryPromise({\n try: () =>\n edge.put(\n edgeKey(key),\n // The page's Response and workers-types' differ only in their declarations.\n new Response(encoded.bytes, {\n headers: {\n 'content-type': encoded.contentType,\n 'cache-control': 'public, max-age=31536000, immutable',\n },\n }) as never,\n ),\n catch: cause => cause,\n }).pipe(Effect.catch(cause => Effect.logWarning('Media: the edge cache failed a write', cause)))\n const behindEdge = (key: string) =>\n behind.get(key).pipe(\n Effect.tap(found =>\n Option.match(found, {\n onNone: () => Effect.void,\n onSome: kept => fill(key, kept.encoded),\n }),\n ),\n )\n return {\n get: key =>\n Effect.tryPromise({\n try: async () => {\n const hit = await edge.match(edgeKey(key))\n return hit === undefined\n ? Option.none<Kept>()\n : Option.some({\n encoded: {\n bytes: new Uint8Array(await hit.arrayBuffer()),\n contentType: hit.headers.get('content-type') ?? 'application/octet-stream',\n },\n from: 'edge' as const,\n })\n },\n catch: cause => cause,\n }).pipe(\n Effect.catch(cause =>\n Effect.logWarning('Media: the edge cache failed a read', cause).pipe(\n Effect.as(Option.none<Kept>()),\n ),\n ),\n Effect.flatMap(found => (Option.isSome(found) ? Effect.succeed(found) : behindEdge(key))),\n ),\n put: (key, encoded) => behind.put(key, encoded).pipe(Effect.andThen(fill(key, encoded))),\n }\n}\n\n/**\n * Variants kept in R2 under `prefix`, so one made last month is not made, and\n * billed, again: `variantsKeyValueStore` over `keyValueStoreR2`. With `cache`\n * (`caches.default`), the Cache API stands in front of it.\n */\nexport const variantsR2 = (\n bucket: R2Bucket,\n options: { readonly prefix?: string; readonly cache?: Cache } = {},\n): Layer.Layer<Variants> => {\n const kept = makeVariants(KeyValueStore.prefix(r2Store(bucket), options.prefix ?? 'variants/'))\n return Layer.succeed(\n Variants,\n Option.match(Option.fromNullishOr(options.cache), {\n onNone: () => kept,\n onSome: edge => withEdge(kept, edge),\n }),\n )\n}\n\n/**\n * Admission through a Workers rate-limit binding (`[[ratelimits]]`), whose\n * limit and period are its configuration. It answers yes or no, not when, so\n * a refusal says to retry after `retryAfterSeconds` (the binding's period, 60\n * by default). A binding that fails admits the request, logged.\n */\nexport const admissionRateLimit = (\n binding: RateLimit,\n options: { readonly retryAfterSeconds?: number } = {},\n): Layer.Layer<Admission> =>\n Layer.succeed(Admission, {\n admit: client =>\n Effect.tryPromise(() => binding.limit({ key: `foldkit-media:${client}` })).pipe(\n Effect.catch(error =>\n Effect.logWarning('Media: the rate limit binding failed; admitting', error).pipe(\n Effect.as({ success: true }),\n ),\n ),\n Effect.flatMap(({ success }) =>\n success\n ? Effect.void\n : Effect.fail(new RateLimited({ retryAfterSeconds: options.retryAfterSeconds ?? 60 })),\n ),\n ),\n })\n\n/**\n * The `Inspector` through the Images binding: an original's size from `info`,\n * which costs no transformation. It makes no thumbnail, since raw pixels are\n * not offered offline and could not be tested, so an original described here\n * has no ThumbHash; and as `info` does not say whether pixels are\n * transparent, every format but JPEG is taken to be, which costs a\n * placeholder, never shows a wrong one. An SVG, which has no size in pixels,\n * is refused.\n */\nexport const inspectorImages = (images: ImagesBinding): Layer.Layer<Inspector> =>\n Layer.succeed(Inspector, {\n inspect: bytes =>\n Effect.tryPromise({\n try: () =>\n images.info(\n new Blob([bytes]).stream() as unknown as Parameters<ImagesBinding['info']>[0],\n ),\n catch: cause => cause,\n }).pipe(\n Effect.flatMap(info =>\n // An SVG's answer has no width: it has no size in pixels.\n 'width' in info\n ? Effect.succeed({\n width: info.width,\n height: info.height,\n alpha: info.format !== 'image/jpeg',\n thumbnail: Option.none(),\n })\n : Effect.fail(info),\n ),\n Effect.catch(cause =>\n Effect.logWarning('Media.inspect failed', cause).pipe(\n Effect.andThen(Effect.fail(new T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AK;CACb,OAAO,KAAK,WAAW;CACvB,WAAW,OAAO,KAAK;AACzB,CAAC,IACD,OAAO,KAAK,IAAI,CACtB,GACA,OAAO,OAAM,UACX,OAAO,WAAW,wBAAwB,KAAK,CAAC,CAAC,KAC/C,OAAO,QAAQ,OAAO,KAAK,IAAI,gBAAgB,CAAC,CAAC,CAAC,CAAC,CACrD,CACF,CACF,EACJ,CAAC"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../src/cloudflare/index.ts"],"sourcesContent":["/**\n * The media server's services on Cloudflare: originals in R2, the Images\n * binding as the transformer, and variants kept in R2 behind the Cache API.\n * Each takes the binding it needs, so build them in `serveFetch`'s `layer`\n * from the request's environment.\n */\nimport type {\n Cache,\n CacheStorage,\n ImagesBinding,\n R2Bucket,\n RateLimit,\n} from '@cloudflare/workers-types'\nimport { Effect, Layer, Option } from 'effect'\nimport { KeyValueStore } from 'effect/persistence'\nimport { Admission, RateLimited } from '../server/admission.js'\nimport { Inspector } from '../describe.js'\nimport { OriginalNotFound, QuotaExhausted, TransformFailed } from '../server/errors.js'\nimport { Originals, Transformer, Variants, type Encoded, type Kept } from '../server/services.js'\nimport { StoredFacts, Uploads, decodeFacts, encodeFacts, factsKey } from '../server/upload.js'\nimport { makeVariants } from '../server/stores.js'\n\n/** Originals in an R2 bucket, each under its content hash. */\nexport const originalsR2 = (bucket: R2Bucket): Layer.Layer<Originals> =>\n Layer.succeed(Originals, {\n get: hash =>\n Effect.promise(() => bucket.get(hash)).pipe(\n Effect.flatMap(object =>\n object === null\n ? Effect.fail(new OriginalNotFound({ hash }))\n : Effect.succeed({\n // The two runtimes' stream types differ only in their declarations.\n body: object.body as unknown as ReadableStream<Uint8Array>,\n size: object.size,\n }),\n ),\n ),\n })\n\n/**\n * Uploads into an R2 bucket, each under its content hash, what `originalsR2`\n * reads, and its facts under `facts/<hash>`, what `storedFactsR2` reads.\n */\nexport const uploadsR2 = (bucket: R2Bucket): Layer.Layer<Uploads> =>\n Layer.succeed(Uploads, {\n put: (hash, bytes, facts) =>\n Effect.promise(async () => {\n await bucket.put(hash, bytes)\n await bucket.put(factsKey(hash), encodeFacts(facts))\n }),\n })\n\n/** An upload's facts, read back from the bucket `uploadsR2` keeps them in. */\nexport const storedFactsR2 = (bucket: R2Bucket): Layer.Layer<StoredFacts> =>\n Layer.succeed(StoredFacts, {\n get: hash =>\n Effect.promise(async () => {\n const object = await bucket.get(factsKey(hash))\n return object === null ? Option.none() : Option.some(decodeFacts(await object.text()))\n }),\n })\n\n// Cloudflare's code for a spent transformation allowance.\nconst QUOTA_EXHAUSTED = 9422\n\nconst isImagesError = (cause: unknown): cause is { readonly code: number } =>\n typeof cause === 'object' && cause !== null && typeof Reflect.get(cause, 'code') === 'number'\n\n/**\n * The Images binding as the transformer. It scales down, never up, and names\n * the format, so the variant is what its URL says. A spent allowance is\n * `QuotaExhausted`; any other refusal is `TransformFailed`, its reason logged.\n */\nexport const transformerImages = (images: ImagesBinding): Layer.Layer<Transformer> =>\n Layer.succeed(Transformer, {\n transform: (original, variant) =>\n Effect.tryPromise({\n try: async () => {\n const result = await images\n .input(original.body as unknown as Parameters<ImagesBinding['input']>[0])\n .transform({ width: variant.width, fit: 'scale-down' })\n .output({\n format: `image/${variant.format}`,\n ...Option.match(variant.quality, {\n onNone: () => ({}),\n onSome: quality => ({ quality }),\n }),\n })\n const response = result.response()\n return {\n bytes: new Uint8Array(await response.arrayBuffer()),\n contentType: result.contentType(),\n }\n },\n catch: cause => cause,\n }).pipe(\n Effect.catch((cause): Effect.Effect<never, QuotaExhausted | TransformFailed> =>\n isImagesError(cause) && cause.code === QUOTA_EXHAUSTED\n ? Effect.fail(new QuotaExhausted({}))\n : Effect.logWarning('Media.transform failed', cause).pipe(\n Effect.andThen(Effect.fail(new TransformFailed({}))),\n ),\n ),\n ),\n })\n\n/**\n * An R2 bucket as an Effect `KeyValueStore`, for anything that keeps bytes by\n * key: `variantsKeyValueStore`, `originalsKeyValueStore`, or the\n * application's own. `clear` and `size` list the whole bucket.\n */\nexport const keyValueStoreR2 = (bucket: R2Bucket): Layer.Layer<KeyValueStore.KeyValueStore> =>\n Layer.succeed(KeyValueStore.KeyValueStore, r2Store(bucket))\n\nconst r2Store = (bucket: R2Bucket): KeyValueStore.KeyValueStore => {\n const attempt = <A>(method: string, key: string | undefined, run: () => Promise<A>) =>\n Effect.tryPromise({\n try: run,\n catch: cause =>\n new KeyValueStore.KeyValueStoreError({\n message: `R2 ${method} failed`,\n method,\n ...(key === undefined ? {} : { key }),\n cause,\n }),\n })\n // Every key in the bucket, a page of listing at a time.\n const keys = async () => {\n const found: Array<string> = []\n let cursor: string | undefined\n do {\n const page = await bucket.list(cursor === undefined ? {} : { cursor })\n found.push(...page.objects.map(object => object.key))\n cursor = page.truncated ? page.cursor : undefined\n } while (cursor !== undefined)\n return found\n }\n return KeyValueStore.make({\n get: key => attempt('get', key, async () => (await bucket.get(key))?.text()),\n getUint8Array: key =>\n attempt('getUint8Array', key, async () => {\n const object = await bucket.get(key)\n return object === null ? undefined : new Uint8Array(await object.arrayBuffer())\n }),\n set: (key, value) => attempt('set', key, async () => void (await bucket.put(key, value))),\n remove: key => attempt('remove', key, () => bucket.delete(key)),\n clear: attempt('clear', undefined, async () => {\n const all = await keys()\n // R2 deletes at most 1,000 keys a call.\n for (let at = 0; at < all.length; at += 1000) await bucket.delete(all.slice(at, at + 1000))\n }),\n size: attempt('size', undefined, async () => (await keys()).length),\n })\n}\n\n// The Cache API keys by request; this origin is never fetched.\nconst edgeKey = (key: string) => `https://foldkit-media.invalid/${key}`\n\n/**\n * Variants with the edge's Cache API in front: read there first, and filled\n * from what is kept behind it, so a popular variant is served from the edge.\n */\nconst withEdge = (behind: Variants['Service'], edge: Cache): Variants['Service'] => {\n const fill = (key: string, encoded: Encoded) =>\n Effect.tryPromise({\n try: () =>\n edge.put(\n edgeKey(key),\n // The page's Response and workers-types' differ only in their declarations.\n new Response(encoded.bytes, {\n headers: {\n 'content-type': encoded.contentType,\n 'cache-control': 'public, max-age=31536000, immutable',\n },\n }) as never,\n ),\n catch: cause => cause,\n }).pipe(Effect.catch(cause => Effect.logWarning('Media: the edge cache failed a write', cause)))\n const behindEdge = (key: string) =>\n behind.get(key).pipe(\n Effect.tap(found =>\n Option.match(found, {\n onNone: () => Effect.void,\n onSome: kept => fill(key, kept.encoded),\n }),\n ),\n )\n return {\n get: key =>\n Effect.tryPromise({\n try: async () => {\n const hit = await edge.match(edgeKey(key))\n return hit === undefined\n ? Option.none<Kept>()\n : Option.some({\n encoded: {\n bytes: new Uint8Array(await hit.arrayBuffer()),\n contentType: hit.headers.get('content-type') ?? 'application/octet-stream',\n },\n from: 'edge' as const,\n })\n },\n catch: cause => cause,\n }).pipe(\n Effect.catch(cause =>\n Effect.logWarning('Media: the edge cache failed a read', cause).pipe(\n Effect.as(Option.none<Kept>()),\n ),\n ),\n Effect.flatMap(found => (Option.isSome(found) ? Effect.succeed(found) : behindEdge(key))),\n ),\n put: (key, encoded) => behind.put(key, encoded).pipe(Effect.andThen(fill(key, encoded))),\n }\n}\n\n// A Worker's global, which the DOM's `CacheStorage` declares without `default`.\ndeclare const caches: CacheStorage | undefined\n\nconst cacheOf = (cache: Cache | true): Cache => {\n if (cache !== true) return cache\n if (typeof caches === 'undefined') {\n throw new Error(\n 'variantsR2: `cache: true` reads the Worker global `caches.default`, which this runtime lacks',\n )\n }\n return caches.default\n}\n\n/**\n * Variants kept in R2 under `prefix`, so one made last month is not made, and\n * billed, again: `variantsKeyValueStore` over `keyValueStoreR2`. With `cache`,\n * the Cache API stands in front of it: `true` for the Worker's\n * `caches.default`, or a cache of your own (`await caches.open(…)`).\n */\nexport const variantsR2 = (\n bucket: R2Bucket,\n options: { readonly prefix?: string; readonly cache?: Cache | true } = {},\n): Layer.Layer<Variants> => {\n const kept = makeVariants(KeyValueStore.prefix(r2Store(bucket), options.prefix ?? 'variants/'))\n return Layer.succeed(\n Variants,\n Option.match(Option.fromNullishOr(options.cache), {\n onNone: () => kept,\n onSome: cache => withEdge(kept, cacheOf(cache)),\n }),\n )\n}\n\n/**\n * Admission through a Workers rate-limit binding (`[[ratelimits]]`), whose\n * limit and period are its configuration. It answers yes or no, not when, so\n * a refusal says to retry after `retryAfterSeconds` (the binding's period, 60\n * by default). A binding that fails admits the request, logged.\n */\nexport const admissionRateLimit = (\n binding: RateLimit,\n options: { readonly retryAfterSeconds?: number } = {},\n): Layer.Layer<Admission> =>\n Layer.succeed(Admission, {\n admit: client =>\n Effect.tryPromise(() => binding.limit({ key: `foldkit-media:${client}` })).pipe(\n Effect.catch(error =>\n Effect.logWarning('Media: the rate limit binding failed; admitting', error).pipe(\n Effect.as({ success: true }),\n ),\n ),\n Effect.flatMap(({ success }) =>\n success\n ? Effect.void\n : Effect.fail(new RateLimited({ retryAfterSeconds: options.retryAfterSeconds ?? 60 })),\n ),\n ),\n })\n\n/**\n * The `Inspector` through the Images binding: an original's size from `info`,\n * which costs no transformation. It makes no thumbnail, since raw pixels are\n * not offered offline and could not be tested, so an original described here\n * has no ThumbHash; and as `info` does not say whether pixels are\n * transparent, every format but JPEG is taken to be, which costs a\n * placeholder, never shows a wrong one. An SVG, which has no size in pixels,\n * is refused.\n */\nexport const inspectorImages = (images: ImagesBinding): Layer.Layer<Inspector> =>\n Layer.succeed(Inspector, {\n inspect: bytes =>\n Effect.tryPromise({\n try: () =>\n images.info(\n new Blob([bytes]).stream() as unknown as Parameters<ImagesBinding['info']>[0],\n ),\n catch: cause => cause,\n }).pipe(\n Effect.flatMap(info =>\n // An SVG's answer has no width: it has no size in pixels.\n 'width' in info\n ? Effect.succeed({\n width: info.width,\n height: info.height,\n alpha: info.format !== 'image/jpeg',\n thumbnail: Option.none(),\n })\n : Effect.fail(info),\n ),\n Effect.catch(cause =>\n Effect.logWarning('Media.inspect failed', cause).pipe(\n Effect.andThen(Effect.fail(new TransformFailed({}))),\n ),\n ),\n ),\n })\n"],"mappings":";;;;;;;;AAuBA,MAAa,eAAe,WAC1B,MAAM,QAAQ,WAA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KAAK,IAAI,YAAY,EAAE,mBAAmB,QAAQ,qBAAqB,GAAG,CAAC,CAAC,CACzF,CACF,EACJ,CAAC;;;;;;;;;;AAWH,MAAa,mBAAmB,WAC9B,MAAM,QAAQ,WAAW,EACvB,UAAS,UACP,OAAO,WAAW;CAChB,WACE,OAAO,KACL,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAC3B;CACF,QAAO,UAAS;AAClB,CAAC,CAAC,CAAC,KACD,OAAO,SAAQ,SAEb,WAAW,OACP,OAAO,QAAQ;CACb,OAAO,KAAK;CACZ,QAAQ,KAAK;CACb,OAAO,KAAK,WAAW;CACvB,WAAW,OAAO,KAAK;AACzB,CAAC,IACD,OAAO,KAAK,IAAI,CACtB,GACA,OAAO,OAAM,UACX,OAAO,WAAW,wBAAwB,KAAK,CAAC,CAAC,KAC/C,OAAO,QAAQ,OAAO,KAAK,IAAI,gBAAgB,CAAC,CAAC,CAAC,CAAC,CACrD,CACF,CACF,EACJ,CAAC"}
@@ -1,6 +1,5 @@
1
- import { n as ImageAsset } from "./asset-BNQ_j5tO.mjs";
1
+ import { r as ImageAsset } from "./asset-BLo8VWmd.mjs";
2
2
  import { Context, Effect, Option, Schema } from "effect";
3
- //#region src/server/errors.d.ts
4
3
  declare const OriginalNotFound_base: Schema.Class<OriginalNotFound, Schema.TaggedStruct<"OriginalNotFound", {
5
4
  readonly hash: Schema.String;
6
5
  }>, import("effect/Cause").YieldableError>;
@@ -22,8 +21,6 @@ declare class TransformFailed extends TransformFailed_base {}
22
21
  declare const QuotaExhausted_base: Schema.Class<QuotaExhausted, Schema.TaggedStruct<"QuotaExhausted", {}>, import("effect/Cause").YieldableError>;
23
22
  /** The host's transformation allowance is spent; variants already made still serve. */
24
23
  declare class QuotaExhausted extends QuotaExhausted_base {}
25
- //#endregion
26
- //#region src/describe.d.ts
27
24
  /** A picture at most 100 pixels a side, as raw RGBA: what a ThumbHash is made from. */
28
25
  interface Thumbnail {
29
26
  readonly width: number;
@@ -51,6 +48,5 @@ declare class Inspector extends Inspector_base {}
51
48
  * page's content naming a URL), so its facts are derived once and stored.
52
49
  */
53
50
  declare const describe: (key: string, bytes: Uint8Array<ArrayBuffer>) => Effect.Effect<ImageAsset, TransformFailed | OriginalTooLarge, Inspector>;
54
- //#endregion
55
51
  export { OriginalNotFound as a, TransformFailed as c, describe as i, Inspector as n, OriginalTooLarge as o, Thumbnail as r, QuotaExhausted as s, Inspected as t };
56
- //# sourceMappingURL=describe-DdYvLhMY.d.mts.map
52
+ //# sourceMappingURL=describe-BOgc0xbR.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"describe-BOgc0xbR.d.mts","names":[],"sources":["../src/server/errors.ts","../src/describe.ts"],"mappings":";;;;;;cAGa,yBAAyB;;;;;;;cAOzB,yBAAyB;;;;;;cAUzB,wBAAwB;;;cAOxB,uBAAuB;;UCrBnB;WACN;WACA;WACA,MAAM;;;UAIA;WACN;WACA;;WAEA;;WAEA,WAAW,OAAO,OAAO;;;WAOd,UAChB,OAAO,WAAW,iBACf,OAAO,OAAO,WAAW,kBAAkB;;;cALvC,kBAAkB;;;;;;;cAoBlB,WAAQ,aACR,OACJ,WAAW,iBACjB,OAAO,OAAO,YAAY,kBAAkB,kBAAkB"}
@@ -1,8 +1,8 @@
1
- import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.mjs";
2
- import { r as standard$1 } from "./widths-BEa9odY6.mjs";
1
+ import { t as __exportAll } from "./rolldown-runtime-BJohB4LM.mjs";
2
+ import { r as standard$1 } from "./widths-qp3jshiF.mjs";
3
3
  import { Context, Effect, Option, Schema, SchemaGetter } from "effect";
4
4
  import { rgbaToThumbHash } from "thumbhash";
5
- //#region src/variant.ts
5
+ // src/variant.ts
6
6
  var variant_exports = /* @__PURE__ */ __exportAll({
7
7
  ContentHash: () => ContentHash,
8
8
  PATH: () => PATH,
@@ -81,8 +81,7 @@ const space = (options = {}) => {
81
81
  };
82
82
  /** The standard ladder, AVIF and WebP, and no quality in any URL: 16 variants an original. */
83
83
  const standard = space();
84
- //#endregion
85
- //#region src/asset.ts
84
+ // src/asset.ts
86
85
  const CSS_COLOR = /^(?:#[0-9a-f]{3,8}|(?:rgba?|hsla?|hwb|lab|lch|oklab|oklch)\([0-9a-z%.,\s/+-]*\))$/i;
87
86
  const coefficientCount = (x, y) => {
88
87
  let count = 0;
@@ -140,8 +139,10 @@ const ImageAsset = Schema.Struct({
140
139
  placeholder: Schema.OptionFromNullOr(Placeholder),
141
140
  focus: Schema.OptionFromOptionalNullOr(Focus)
142
141
  });
143
- //#endregion
144
- //#region src/describe.ts
142
+ const isHashed = (asset) => Option.isSome(asset.hash);
143
+ /** `ImageAsset`, refusing facts with no content hash. */
144
+ const HashedAsset = ImageAsset.pipe(Schema.refine(isHashed));
145
+ // src/describe.ts
145
146
  /** Reads an original's facts: its size, its alpha, and a thumbnail. */
146
147
  var Inspector = class extends Context.Service()("foldkit-media/Inspector") {};
147
148
  const hex = (buffer) => Array.from(new Uint8Array(buffer), (byte) => byte.toString(16).padStart(2, "0")).join("");
@@ -165,7 +166,6 @@ const describe = (key, bytes) => Effect.gen(function* () {
165
166
  focus: Option.none()
166
167
  };
167
168
  });
168
- //#endregion
169
- export { Placeholder as a, Quality as c, revisionOf as d, standard as f, ImageAsset as i, Spelling as l, describe as n, ContentHash as o, variant_exports as p, Focus as r, PATH as s, Inspector as t, respell as u };
169
+ export { ImageAsset as a, ContentHash as c, Spelling as d, respell as f, variant_exports as h, HashedAsset as i, PATH as l, standard as m, describe as n, Placeholder as o, revisionOf as p, Focus as r, isHashed as s, Inspector as t, Quality as u };
170
170
 
171
- //# sourceMappingURL=describe-Cqr63Gxa.mjs.map
171
+ //# sourceMappingURL=describe-C6sWA_8p.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"describe-C6sWA_8p.mjs","names":["Widths.standard"],"sources":["../src/variant.ts","../src/asset.ts","../src/describe.ts"],"sourcesContent":["import { Option, Schema, SchemaGetter } from 'effect'\nimport { Format } from './format.js'\nimport * as Widths from './widths.js'\n\n/**\n * Where a hosted variant lives: the original's content hash, then the variant.\n * The server routes this path and `Provider.hosted` fills it in, so the two\n * read one string. It ends in the format's extension, so a variant written\n * out as a file is served with its type by any static host.\n */\nexport const PATH = '/_image/:hash/:variant'\n\n/** An original's SHA-256, in lowercase hex: its name in the store. */\nexport const ContentHash = Schema.String.check(Schema.isPattern(/^[0-9a-f]{64}$/))\n\n/** A quality from 1 to 100. */\nexport const Quality = Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 100 }))\n\n// No leading zero anywhere: one request has one spelling, so one cache key. The output's\n// revision is written only above 0, so every URL written before revisions keeps its spelling.\nconst SPELLING = /^w([1-9]\\d{0,4})(?:q([1-9]\\d?|100))?(?:\\.r([1-9]\\d{0,3}))?\\.(avif|webp|jpeg|png)$/\n\n/**\n * The grammar every release reads, whatever its space: a spelling it matches\n * may be one another release offers, so refusing it says nothing for good.\n */\nexport const Spelling = Schema.String.check(Schema.isPattern(SPELLING))\n\n/** The output revision a spelling names: `w640.r2.avif` is 2, and one naming none is 0. */\nexport const revisionOf = (spelling: string): number => Number(SPELLING.exec(spelling)?.[3] ?? 0)\n\n/** `spelling` at `revision`: the same variant, as that revision writes it. */\nexport const respell = (spelling: string, revision: number): string =>\n spelling.replace(/(?:\\.r\\d+)?(\\.[a-z]+)$/, revision === 0 ? '$1' : `.r${revision}$1`)\n\n/** A variant as its server reads it. */\nexport interface Variant {\n readonly width: number\n readonly format: Format\n /** None: the encoder's own default. */\n readonly quality: Option.Option<number>\n}\n\n/**\n * Every variant a server will make: the widths, the formats and the qualities\n * it accepts, and the Schema that reads a variant's spelling against them. A\n * request outside it is refused before any work, so an original has at most\n * `size` variants, whoever asks.\n */\nexport interface Space {\n readonly widths: Widths.Widths\n readonly formats: ReadonlyArray<Format>\n /** Qualities a URL may name; empty, no URL names one. */\n readonly qualities: ReadonlyArray<number>\n /**\n * The generation of what its variants are: raised when the output changes (the encoder's\n * settings, its resizing), so a changed variant has a new URL rather than new bytes behind\n * an old one. 0 writes no revision.\n */\n readonly revision: number\n /** `w640.avif`, `w640q75.webp` or `w640.r1.avif`, decoded to a `Variant` of this space's revision. */\n readonly schema: Schema.Codec<Variant, string>\n /** How many variants one original can have. */\n readonly size: number\n}\n\nconst distinct = <A>(label: string, values: ReadonlyArray<A>) => {\n if (new Set(values).size !== values.length)\n throw new Error(`Variant.space: a ${label} appears twice`)\n}\n\n/**\n * A space from its ladders. Refuses no formats, a repeated format or\n * quality, and a quality outside 1 to 100.\n */\nexport const space = (\n options: {\n readonly widths?: Widths.Widths\n readonly formats?: ReadonlyArray<Format>\n readonly qualities?: ReadonlyArray<number>\n readonly revision?: number\n } = {},\n): Space => {\n const {\n widths = Widths.standard,\n formats = ['avif', 'webp'],\n qualities = [],\n revision = 0,\n } = options\n if (!(Number.isInteger(revision) && revision >= 0 && revision <= 9999)) {\n throw new Error(`Variant.space: revision ${revision} is not an integer from 0 to 9999`)\n }\n const unspellableWidth = widths.values.find(width => width > 99_999)\n if (unspellableWidth !== undefined) {\n throw new Error(`Variant.space: width ${unspellableWidth} cannot be spelled in a variant URL`)\n }\n if (formats.length === 0) throw new Error('Variant.space: a space needs at least one format')\n distinct('format', formats)\n distinct('quality', qualities)\n for (const quality of qualities) {\n if (!Schema.is(Quality)(quality)) {\n throw new Error(`Variant.space: quality ${quality} is not an integer from 1 to 100`)\n }\n }\n const schema = Spelling.check(\n Schema.makeFilter(spelling => revisionOf(spelling) === revision || `not revision ${revision}`),\n ).pipe(\n Schema.decodeTo(\n Schema.Struct({\n width: widths.Schema,\n format: Schema.Literals(formats),\n quality: Schema.Option(Schema.Literals(qualities)),\n }),\n {\n decode: SchemaGetter.transform(spelling => {\n const [, width, quality, , format] = SPELLING.exec(spelling)!\n return {\n width: Number(width),\n // The spelling's pattern admits only formats; the struct checks this space's.\n format: format as Format,\n quality: Option.map(Option.fromNullishOr(quality), Number),\n }\n }),\n encode: SchemaGetter.transform(\n ({ width, format, quality }) =>\n `w${width}${Option.match(quality, { onNone: () => '', onSome: value => `q${value}` })}${revision === 0 ? '' : `.r${revision}`}.${format}`,\n ),\n },\n ),\n )\n return {\n widths,\n formats,\n qualities,\n revision,\n schema,\n size: widths.values.length * formats.length * (1 + qualities.length),\n }\n}\n\n/** The standard ladder, AVIF and WebP, and no quality in any URL: 16 variants an original. */\nexport const standard: Space = space()\n","import { Option, Schema } from 'effect'\nimport { ContentHash } from './variant.js'\n\n// A placeholder's color lands in a style the page writes, so it is a color\n// and nothing else: no `;`, no `url(`, no second declaration.\nconst CSS_COLOR =\n /^(?:#[0-9a-f]{3,8}|(?:rgba?|hsla?|hwb|lab|lch|oklab|oklch)\\([0-9a-z%.,\\s/+-]*\\))$/i\n\nconst coefficientCount = (x: number, y: number): number => {\n let count = 0\n for (let cy = 0; cy < y; cy++)\n for (let cx = cy === 0 ? 1 : 0; cx * y < x * (y - cy); cx++) count++\n return count\n}\n\n// A ThumbHash's header decides exactly how many coefficient bytes follow it.\n// Checking that layout here keeps malformed stored data out of the renderer.\nconst isThumbHash = (encoded: string): boolean => {\n try {\n const bytes = Uint8Array.from(atob(encoded), character => character.charCodeAt(0))\n if (bytes.length < 5) return false\n const hasAlpha = (bytes[2]! & 0x80) !== 0\n const landscape = (bytes[4]! & 0x80) !== 0\n const shorter = bytes[3]! & 7\n if (shorter === 0) return false\n const long = hasAlpha ? 5 : 7\n const lx = landscape ? long : shorter\n const ly = landscape ? shorter : long\n const coefficients =\n coefficientCount(lx, ly) +\n coefficientCount(3, 3) * 2 +\n (hasAlpha ? coefficientCount(5, 5) : 0)\n return bytes.length === (hasAlpha ? 6 : 5) + Math.ceil(coefficients / 2)\n } catch {\n return false\n }\n}\n\n/** What stands in an image's place until it loads. */\nexport const Placeholder = Schema.TaggedUnion({\n /** A flat color, such as one taken from a logo. */\n Color: { value: Schema.String.check(Schema.isPattern(CSS_COLOR)) },\n /** A ThumbHash: a blurred likeness, alpha and aspect ratio included. */\n ThumbHash: {\n hash: Schema.String.check(\n Schema.makeFilter(encoded => isThumbHash(encoded) || 'not a valid ThumbHash'),\n ),\n },\n /** The provider's smallest width of the image itself, scaled up. */\n LowRes: {},\n})\nexport type Placeholder = typeof Placeholder.Type\n\nconst Pixels = Schema.Int.check(Schema.isGreaterThan(0))\n\nconst Share = Schema.Finite.check(Schema.isBetween({ minimum: 0, maximum: 1 }))\n\n/** Where an image's subject is, from its top left (0, 0) to its bottom right (1, 1). */\nexport const Focus = Schema.Struct({ x: Share, y: Share })\nexport type Focus = typeof Focus.Type\n\n/**\n * The facts of one original image, derived from it once and stored beside it.\n * `key` is where the original lives, as its provider reads it. `hash` is the\n * original's content hash, absent for an image never read; `alpha` says\n * whether it has transparent pixels. `focus`, the one fact an editor sets\n * rather than one derived, is where a crop keeps the subject; a stored asset\n * without it reads as none.\n */\nexport const ImageAsset = Schema.Struct({\n key: Schema.String.check(Schema.isNonEmpty()),\n width: Pixels,\n height: Pixels,\n alpha: Schema.Boolean,\n hash: Schema.OptionFromNullOr(ContentHash),\n placeholder: Schema.OptionFromNullOr(Placeholder),\n focus: Schema.OptionFromOptionalNullOr(Focus),\n})\nexport type ImageAsset = typeof ImageAsset.Type\n\n/**\n * Facts that name the original by its content hash: what a build or an upload\n * answers, and what `Provider.hosted` needs to write a URL.\n */\nexport type HashedAsset = ImageAsset & { readonly hash: Option.Some<string> }\n\nexport const isHashed = (asset: ImageAsset): asset is HashedAsset => Option.isSome(asset.hash)\n\n/** `ImageAsset`, refusing facts with no content hash. */\nexport const HashedAsset = ImageAsset.pipe(Schema.refine(isHashed))\n","import { Context, Effect, Option } from 'effect'\nimport { rgbaToThumbHash } from 'thumbhash'\nimport { Placeholder, type ImageAsset } from './asset.js'\nimport type { OriginalTooLarge, TransformFailed } from './server/errors.js'\n\n/** A picture at most 100 pixels a side, as raw RGBA: what a ThumbHash is made from. */\nexport interface Thumbnail {\n readonly width: number\n readonly height: number\n readonly rgba: Uint8Array\n}\n\n/** What an inspector reads of an original. */\nexport interface Inspected {\n readonly width: number\n readonly height: number\n /** Whether it may have transparent pixels; an inspector that cannot tell says yes. */\n readonly alpha: boolean\n /** None where the inspector cannot make one (the Images binding offline makes no raw pixels). */\n readonly thumbnail: Option.Option<Thumbnail>\n}\n\n/** Reads an original's facts: its size, its alpha, and a thumbnail. */\nexport class Inspector extends Context.Service<\n Inspector,\n {\n readonly inspect: (\n bytes: Uint8Array<ArrayBuffer>,\n ) => Effect.Effect<Inspected, TransformFailed | OriginalTooLarge>\n }\n>()('foldkit-media/Inspector') {}\n\nconst hex = (buffer: ArrayBuffer) =>\n Array.from(new Uint8Array(buffer), byte => byte.toString(16).padStart(2, '0')).join('')\n\nconst base64 = (bytes: Uint8Array) => btoa(String.fromCharCode(...bytes))\n\n/**\n * An original's facts, as an `ImageAsset` under `key`: its size and alpha\n * from the `Inspector`, its SHA-256, and a ThumbHash placeholder where the\n * inspector made a thumbnail. Where an original enters (an upload, a build, a\n * page's content naming a URL), so its facts are derived once and stored.\n */\nexport const describe = (\n key: string,\n bytes: Uint8Array<ArrayBuffer>,\n): Effect.Effect<ImageAsset, TransformFailed | OriginalTooLarge, Inspector> =>\n Effect.gen(function* () {\n const inspected = yield* Inspector.use(inspector => inspector.inspect(bytes))\n const digest = yield* Effect.promise(() => crypto.subtle.digest('SHA-256', bytes))\n return {\n key,\n width: inspected.width,\n height: inspected.height,\n alpha: inspected.alpha,\n hash: Option.some(hex(digest)),\n placeholder: Option.map(inspected.thumbnail, ({ width, height, rgba }) =>\n Placeholder.cases.ThumbHash.make({ hash: base64(rgbaToThumbHash(width, height, rgba)) }),\n ),\n focus: Option.none(),\n }\n })\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAUA,MAAa,OAAO;;AAGpB,MAAa,cAAc,OAAO,OAAO,MAAM,OAAO,UAAU,gBAAgB,CAAC;;AAGjF,MAAa,UAAU,OAAO,IAAI,MAAM,OAAO,UAAU;CAAE,SAAS;CAAG,SAAS;AAAI,CAAC,CAAC;A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Y,OAAO,UAAU,KAAI,cAAa,UAAU,QAAQ,KAAK,CAAC;CAC5E,MAAM,SAAS,OAAO,OAAO,cAAc,OAAO,OAAO,OAAO,WAAW,KAAK,CAAC;CACjF,OAAO;EACL;EACA,OAAO,UAAU;EACjB,QAAQ,UAAU;EAClB,OAAO,UAAU;EACjB,MAAM,OAAO,KAAK,IAAI,MAAM,CAAC;EAC7B,aAAa,OAAO,IAAI,UAAU,YAAY,EAAE,OAAO,QAAQ,WAC7D,YAAY,MAAM,UAAU,KAAK,EAAE,MAAM,OAAO,gBAAgB,OAAO,QAAQ,IAAI,CAAC,EAAE,CAAC,CACzF;EACA,OAAO,OAAO,KAAK;CACrB;AACF,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import { Schema } from "effect";
2
- //#region src/server/errors.ts
2
+ // src/server/errors.ts
3
3
  /** No original is stored under this hash. */
4
4
  var OriginalNotFound = class extends Schema.TaggedError()("OriginalNotFound", { hash: Schema.String }, { httpApiStatus: 404 }) {};
5
5
  /** The original is larger than the server will read: in bytes, or in pixels once decoded. */
@@ -15,7 +15,6 @@ var OriginalTooLarge = class extends Schema.TaggedError()("OriginalTooLarge", {
15
15
  var TransformFailed = class extends Schema.TaggedError()("TransformFailed", {}, { httpApiStatus: 502 }) {};
16
16
  /** The host's transformation allowance is spent; variants already made still serve. */
17
17
  var QuotaExhausted = class extends Schema.TaggedError()("QuotaExhausted", {}, { httpApiStatus: 503 }) {};
18
- //#endregion
19
18
  export { TransformFailed as i, OriginalTooLarge as n, QuotaExhausted as r, OriginalNotFound as t };
20
19
 
21
- //# sourceMappingURL=errors-qETj7Pgi.mjs.map
20
+ //# sourceMappingURL=errors-BhEgXJ4m.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors-qETj7Pgi.mjs","names":[],"sources":["../src/server/errors.ts"],"sourcesContent":["import { Schema } from 'effect'\n\n/** No original is stored under this hash. */\nexport class OriginalNotFound extends Schema.TaggedError<OriginalNotFound>()(\n 'OriginalNotFound',\n { hash: Schema.String },\n { httpApiStatus: 404 },\n) {}\n\n/** The original is larger than the server will read: in bytes, or in pixels once decoded. */\nexport class OriginalTooLarge extends Schema.TaggedError<OriginalTooLarge>()(\n 'OriginalTooLarge',\n { size: Schema.Number, limit: Schema.Number, unit: Schema.Literals(['bytes', 'pixels']) },\n { httpApiStatus: 413 },\n) {}\n\n/**\n * The transformer could not make the variant: the original is not an image it\n * reads, or it failed. Its reason stays in the server's log, not the response.\n */\nexport class TransformFailed extends Schema.TaggedError<TransformFailed>()(\n 'TransformFailed',\n {},\n { httpApiStatus: 502 },\n) {}\n\n/** The host's transformation allowance is spent; variants already made still serve. */\nexport class QuotaExhausted extends Schema.TaggedError<QuotaExhausted>()(\n 'QuotaExhausted',\n {},\n { httpApiStatus: 503 },\n) {}\n"],"mappings":";;;AAGA,IAAa,mBAAb,cAAsC,OAAO,YAA8B,CAAC,CAC1E,oBACA,EAAE,MAAM,OAAO,OAAO,GACtB,EAAE,eAAe,IAAI,CACvB,CAAC,CAAC,CAAC;;AAGH,IAAa,mBAAb,cAAsC,OAAO,YAA8B,CAAC,CAC1E,oBACA;CAAE,MAAM,OAAO;CAAQ,OAAO,OAAO;CAAQ,MAAM,OAAO,SAAS,CAAC,SAAS,QAAQ,CAAC;AAAE,GACxF,EAAE,eAAe,IAAI,CACvB,CAAC,CAAC,CAAC;;;;;AAMH,IAAa,kBAAb,cAAqC,OAAO,YAA6B,CAAC,CACxE,mBACA,CAAC,GACD,EAAE,eAAe,IAAI,CACvB,CAAC,CAAC,CAAC;;AAGH,IAAa,iBAAb,cAAoC,OAAO,YAA4B,CAAC,CACtE,kBACA,CAAC,GACD,EAAE,eAAe,IAAI,CACvB,CAAC,CAAC,CAAC"}
1
+ {"version":3,"file":"errors-BhEgXJ4m.mjs","names":[],"sources":["../src/server/errors.ts"],"sourcesContent":["import { Schema } from 'effect'\n\n/** No original is stored under this hash. */\nexport class OriginalNotFound extends Schema.TaggedError<OriginalNotFound>()(\n 'OriginalNotFound',\n { hash: Schema.String },\n { httpApiStatus: 404 },\n) {}\n\n/** The original is larger than the server will read: in bytes, or in pixels once decoded. */\nexport class OriginalTooLarge extends Schema.TaggedError<OriginalTooLarge>()(\n 'OriginalTooLarge',\n { size: Schema.Number, limit: Schema.Number, unit: Schema.Literals(['bytes', 'pixels']) },\n { httpApiStatus: 413 },\n) {}\n\n/**\n * The transformer could not make the variant: the original is not an image it\n * reads, or it failed. Its reason stays in the server's log, not the response.\n */\nexport class TransformFailed extends Schema.TaggedError<TransformFailed>()(\n 'TransformFailed',\n {},\n { httpApiStatus: 502 },\n) {}\n\n/** The host's transformation allowance is spent; variants already made still serve. */\nexport class QuotaExhausted extends Schema.TaggedError<QuotaExhausted>()(\n 'QuotaExhausted',\n {},\n { httpApiStatus: 503 },\n) {}\n"],"mappings":";;;AAGA,IAAa,mBAAb,cAAsC,OAAO,YAA8B,CAAC,CAC1E,oBACA,EAAE,MAAM,OAAO,OAAO,GACtB,EAAE,eAAe,IAAI,CACvB,CAAC,CAAC,CAAC;;AAGH,IAAa,mBAAb,cAAsC,OAAO,YAA8B,CAAC,CAC1E,oBACA;CAAE,MAAM,OAAO;CAAQ,OAAO,OAAO;CAAQ,MAAM,OAAO,SAAS,CAAC,SAAS,QAAQ,CAAC;AAAE,GACxF,EAAE,eAAe,IAAI,CACvB,CAAC,CAAC,CAAC;;;;;AAMH,IAAa,kBAAb,cAAqC,OAAO,YAA6B,CAAC,CACxE,mBACA,CAAC,GACD,EAAE,eAAe,IAAI,CACvB,CAAC,CAAC,CAAC;;AAGH,IAAa,iBAAb,cAAoC,OAAO,YAA4B,CAAC,CACtE,kBACA,CAAC,GACD,EAAE,eAAe,IAAI,CACvB,CAAC,CAAC,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import { Schema } from "effect";
2
- //#region src/format.ts
2
+ // src/format.ts
3
3
  /** An encoding a variant can be written in. */
4
4
  const Format = Schema.Literals([
5
5
  "avif",
@@ -15,7 +15,6 @@ const mimeTypes = {
15
15
  };
16
16
  /** The media type a `source` element names. */
17
17
  const mimeType = (format) => mimeTypes[format];
18
- //#endregion
19
18
  export { mimeType as n, Format as t };
20
19
 
21
- //# sourceMappingURL=format-BmfnR4jg.mjs.map
20
+ //# sourceMappingURL=format-BCRTFU9j.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"format-BmfnR4jg.mjs","names":[],"sources":["../src/format.ts"],"sourcesContent":["import { Schema } from 'effect'\n\n/** An encoding a variant can be written in. */\nexport const Format = Schema.Literals(['avif', 'webp', 'jpeg', 'png'])\nexport type Format = typeof Format.Type\n\n/**\n * What a provider is asked for: a format, or `auto` for a provider that picks\n * the format itself from the request's `Accept`.\n */\nexport type Encoding = Format | 'auto'\n\nconst mimeTypes: Readonly<Record<Format, string>> = {\n avif: 'image/avif',\n webp: 'image/webp',\n jpeg: 'image/jpeg',\n png: 'image/png',\n}\n\n/** The media type a `source` element names. */\nexport const mimeType = (format: Format): string => mimeTypes[format]\n"],"mappings":";;;AAGA,MAAa,SAAS,OAAO,SAAS;CAAC;CAAQ;CAAQ;CAAQ;AAAK,CAAC;AASrE,MAAM,YAA8C;CAClD,MAAM;CACN,MAAM;CACN,MAAM;CACN,KAAK;AACP;;AAGA,MAAa,YAAY,WAA2B,UAAU"}
1
+ {"version":3,"file":"format-BCRTFU9j.mjs","names":[],"sources":["../src/format.ts"],"sourcesContent":["import { Schema } from 'effect'\n\n/** An encoding a variant can be written in. */\nexport const Format = Schema.Literals(['avif', 'webp', 'jpeg', 'png'])\nexport type Format = typeof Format.Type\n\n/**\n * What a provider is asked for: a format, or `auto` for a provider that picks\n * the format itself from the request's `Accept`.\n */\nexport type Encoding = Format | 'auto'\n\nconst mimeTypes: Readonly<Record<Format, string>> = {\n avif: 'image/avif',\n webp: 'image/webp',\n jpeg: 'image/jpeg',\n png: 'image/png',\n}\n\n/** The media type a `source` element names. */\nexport const mimeType = (format: Format): string => mimeTypes[format]\n"],"mappings":";;;AAGA,MAAa,SAAS,OAAO,SAAS;CAAC;CAAQ;CAAQ;CAAQ;AAAK,CAAC;AASrE,MAAM,YAA8C;CAClD,MAAM;CACN,MAAM;CACN,MAAM;CACN,KAAK;AACP;;AAGA,MAAa,YAAY,WAA2B,UAAU"}
@@ -1,5 +1,5 @@
1
- import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.mjs";
2
- //#region src/icon.ts
1
+ import { t as __exportAll } from "./rolldown-runtime-BJohB4LM.mjs";
2
+ // src/icon.ts
3
3
  var icon_exports = /* @__PURE__ */ __exportAll({
4
4
  TAGS: () => TAGS,
5
5
  draw: () => draw,
@@ -179,7 +179,6 @@ const draw = (icon, h, options = {}) => {
179
179
  ...written(attributes)
180
180
  ], nodes.map(drawn));
181
181
  };
182
- //#endregion
183
182
  export { icon_exports as n, TAGS as t };
184
183
 
185
- //# sourceMappingURL=icon-CowP8fQ0.mjs.map
184
+ //# sourceMappingURL=icon-0A2dBtqj.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"icon-CowP8fQ0.mjs","names":[],"sources":["../src/icon.ts"],"sourcesContent":["/**\n * An icon as data: what a build reads from an icon set or an SVG file, parsed\n * (`foldkit-media/icons`), not markup to set as HTML. A view draws it\n * (`draw`), and a style masks with it (`maskUrl`),\n * from the one value.\n */\n\n/** The elements an icon may hold: presentational SVG, nothing that runs, loads or holds text. */\nexport const TAGS = [\n 'g',\n 'path',\n 'circle',\n 'ellipse',\n 'rect',\n 'line',\n 'polyline',\n 'polygon',\n 'defs',\n 'linearGradient',\n 'radialGradient',\n 'stop',\n 'clipPath',\n 'mask',\n 'use',\n] as const\nexport type SvgTag = (typeof TAGS)[number]\n\n/** One element of an icon's drawing, and its children. */\nexport interface SvgNode {\n readonly tag: SvgTag\n readonly attributes: Readonly<Record<string, string>>\n readonly children: ReadonlyArray<SvgNode>\n}\n\n/** An icon: its `viewBox`, the attributes its root `svg` carries (its fill and stroke), and its drawing. */\nexport interface IconData {\n readonly viewBox: string\n readonly attributes: Readonly<Record<string, string>>\n readonly nodes: ReadonlyArray<SvgNode>\n}\n\nconst escapeAttribute = (value: string): string =>\n value.replace(/&/g, '&amp;').replace(/\"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;')\n\nconst attributesOf = (attributes: Readonly<Record<string, string>>): string =>\n Object.entries(attributes)\n .map(([name, value]) => ` ${name}=\"${escapeAttribute(value)}\"`)\n .join('')\n\nconst nodeMarkup = ({ tag, attributes, children }: SvgNode): string =>\n children.length === 0\n ? `<${tag}${attributesOf(attributes)}/>`\n : `<${tag}${attributesOf(attributes)}>${children.map(nodeMarkup).join('')}</${tag}>`\n\n/** The icon as one standalone `svg` document. */\nexport const serialize = (icon: IconData): string =>\n `<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"${escapeAttribute(icon.viewBox)}\"${attributesOf(icon.attributes)}>${icon.nodes.map(nodeMarkup).join('')}</svg>`\n\n/**\n * The icon as a CSS `url()`, for a mask (`Icons.byAttribute`, `Icons.glyph`):\n * a mask reads only the drawing's shape, so its colours do not matter, and\n * the element it masks paints in `currentColor`.\n */\nexport const maskUrl = (icon: IconData): string =>\n // Only what a data URL in a quoted CSS `url()` cannot hold is escaped (a line break ends a CSS\n // string): a theme writes every chrome icon this way, and escaping the spaces, `=` and `/`\n // too adds a quarter to each.\n `url(\"data:image/svg+xml,${serialize(icon).replace(/[%#<>\"\\n\\r\\t]/g, unsafe => `%${unsafe.charCodeAt(0).toString(16).padStart(2, '0').toUpperCase()}`)}\")`\n\nconst keys = new WeakMap<IconData, string>()\n\n/**\n * A short name for the icon, from its content: the same drawing has the same\n * key on a server and in the browser, and two drawings almost never share\n * one. A drawing's ids are prefixed with it, and a sprite names its symbol by it.\n */\nexport const key = (icon: IconData): string => {\n const known = keys.get(icon)\n if (known !== undefined) return known\n // 64-bit FNV-1a over the serialized drawing.\n let hash = 0xcbf29ce484222325n\n for (const unit of serialize(icon)) {\n hash ^= BigInt(unit.codePointAt(0)!)\n hash = BigInt.asUintN(64, hash * 0x100000001b3n)\n }\n const made = `i${hash.toString(36)}`\n keys.set(icon, made)\n return made\n}\n\nconst idsOf = (nodes: ReadonlyArray<SvgNode>, into: Set<string>): Set<string> => {\n for (const node of nodes) {\n if (node.attributes['id'] !== undefined) into.add(node.attributes['id'])\n idsOf(node.children, into)\n }\n return into\n}\n\ninterface Prefixed {\n readonly ids: ReadonlySet<string>\n readonly byPrefix: Map<string, IconData>\n}\n\nconst prefixed = new WeakMap<IconData, Prefixed>()\n\nconst idPrefix = (prefix: string): string => {\n if (/^(?!fk_)[A-Za-z0-9_-]+$/.test(prefix)) return prefix\n let encoded = ''\n for (let at = 0; at < prefix.length; at++) {\n encoded += prefix.charCodeAt(at).toString(16).padStart(4, '0')\n }\n return `fk_${encoded}`\n}\n\n/**\n * The icon with each id it defines, and each `href` and `url()` naming one,\n * prefixed: two icons drawn inline on one page share the document's ids, and\n * an exported SVG's `id=\"a\"` would otherwise paint another icon's gradient.\n * A prefix outside an identifier's safe characters is encoded before it\n * reaches a CSS `url()`. An icon with no ids is returned as it was given.\n * Kept per icon and prefix, since a view asks again on every render.\n */\nexport const prefixIds = (icon: IconData, prefix: string): IconData => {\n const memo = prefixed.get(icon) ?? { ids: idsOf(icon.nodes, new Set()), byPrefix: new Map() }\n prefixed.set(icon, memo)\n const { ids, byPrefix } = memo\n if (ids.size === 0) return icon\n const known = byPrefix.get(prefix)\n if (known !== undefined) return known\n const writtenPrefix = idPrefix(prefix)\n const rename = (id: string) => (ids.has(id) ? `${writtenPrefix}-${id}` : id)\n const rewriteValue = (name: string, value: string): string => {\n if (name === 'id') return rename(value)\n // The parser admits only a fragment `href`.\n if (name === 'href') return `#${rename(value.slice(1))}`\n return value.replace(\n /url\\(\\s*(['\"]?)#([^)'\"\\s]*)\\1\\s*\\)/gi,\n (_, quote: string, id: string) => `url(${quote}#${rename(id)}${quote})`,\n )\n }\n const rewrite = (attributes: Readonly<Record<string, string>>) =>\n Object.fromEntries(\n Object.entries(attributes).map(([name, value]) => [name, rewriteValue(name, value)]),\n )\n const walk = (node: SvgNode): SvgNode => ({\n tag: node.tag,\n attributes: rewrite(node.attributes),\n children: node.children.map(walk),\n })\n const made: IconData = {\n viewBox: icon.viewBox,\n attributes: rewrite(icon.attributes),\n nodes: icon.nodes.map(walk),\n }\n byPrefix.set(prefix, made)\n return made\n}\n\n/** How a drawing's strokes are drawn: their width, and whether their ends and joins are round. */\nexport interface Stroke {\n readonly width?: number | undefined\n readonly corners?: 'round' | 'square' | undefined\n}\n\n/**\n * The icon with its strokes redrawn: every `stroke-width`, `stroke-linecap`\n * and `stroke-linejoin` it sets replaced, or set on its root where it sets\n * none. A filled icon draws no stroke, so it is unchanged in what shows. For\n * a mask, whose drawing CSS cannot reach once it is a `url()`.\n */\nexport const withStroke = (icon: IconData, stroke: Stroke): IconData => {\n const set: Record<string, string> = {}\n if (stroke.width !== undefined) set['stroke-width'] = String(stroke.width)\n if (stroke.corners !== undefined) {\n set['stroke-linecap'] = stroke.corners\n set['stroke-linejoin'] = stroke.corners === 'round' ? 'round' : 'miter'\n }\n const names = Object.keys(set)\n const found = new Set<string>()\n const restroke = (attributes: Readonly<Record<string, string>>) => {\n const written = { ...attributes }\n for (const name of names) {\n if (Object.hasOwn(attributes, name)) {\n written[name] = set[name]!\n found.add(name)\n }\n }\n return written\n }\n const walk = (node: SvgNode): SvgNode => ({\n tag: node.tag,\n attributes: restroke(node.attributes),\n children: node.children.map(walk),\n })\n const nodes = icon.nodes.map(walk)\n const attributes = restroke(icon.attributes)\n // A property the drawing never sets is set once on the root, which every node inherits.\n for (const name of names) if (!found.has(name)) attributes[name] = set[name]!\n return { viewBox: icon.viewBox, attributes, nodes }\n}\n\ntype Element<Node, Attribute> = (\n attributes: ReadonlyArray<Attribute>,\n children: ReadonlyArray<Node>,\n) => Node\n\n/**\n * What `draw` needs of a view's builder: an element per tag an icon may hold,\n * and raw attributes. Foldkit's `HtmlBuilder` is one, so this package needs\n * no view library of its own.\n */\nexport type SvgBuilder<Node, Attribute> = {\n readonly svg: Element<Node, Attribute>\n readonly Attribute: (name: string, value: string) => Attribute\n readonly AriaHidden: (value: boolean) => Attribute\n} & { readonly [Tag in SvgTag]: Element<Node, Attribute> }\n\n/**\n * The icon as inline SVG, through a view's builder (`h`): `size` square\n * (`1em` unless given, so it stands as tall as its text; `foldkit-mixins-ui`'s\n * `Icon.view` fills its glyph with it), kept so in a squeezed flex row, and\n * hidden from assistive technology,\n * since the control it sits in carries the name. Every attribute is written as\n * an attribute, so a server render writes the same markup. Ids are prefixed by\n * `key(icon)`; `options.key` sets one drawing's ids apart from another of the\n * same icon, since a gradient defined in a copy that is hidden paints nothing\n * for the copy that shows. Each key's drawing is kept for the icon's life, so\n * take keys from a small fixed set (a place on the page), not one per row.\n */\nexport const draw = <Node, Attribute>(\n icon: IconData,\n h: SvgBuilder<Node, Attribute>,\n options: { readonly key?: string; readonly size?: string } = {},\n): Node => {\n const prefix = key(icon) + (options.key === undefined ? '' : `-${options.key}`)\n const { viewBox, attributes, nodes } = prefixIds(icon, prefix)\n const size = options.size ?? '1em'\n const written = (from: Readonly<Record<string, string>>) =>\n Object.entries(from).map(([name, value]) => h.Attribute(name, value))\n const drawn = ({ tag, attributes, children }: SvgNode): Node =>\n h[tag](written(attributes), children.map(drawn))\n return h.svg(\n [\n h.Attribute('viewBox', viewBox),\n h.Attribute('width', size),\n h.Attribute('height', size),\n // A flex row squeezed narrower than its content shrinks an svg to nothing, width or not.\n h.Attribute('style', 'flex-shrink: 0'),\n h.AriaHidden(true),\n ...written(attributes),\n ],\n nodes.map(drawn),\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAQA,MAAa,OAAO;CAClB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAiBA,MAAM,mBAAmB,UACvB,MAAM,QAAQ,MAAM,OAAO,CAAC,CAAC,QAAQ,MAAM,QAAQ,CAAC,CAAC,QAAQ,MAAM,MAAM,CAAC,CAAC,QAAQ,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AAM,MAAM;CAC7D,MAAM,OAAO,QAAQ,QAAQ;CAC7B,MAAM,WAAW,SACf,OAAO,QAAQ,IAAI,CAAC,CAAC,KAAK,CAAC,MAAM,WAAW,EAAE,UAAU,MAAM,KAAK,CAAC;CACtE,MAAM,SAAS,EAAE,KAAK,YAAY,eAChC,EAAE,IAAI,CAAC,QAAQ,UAAU,GAAG,SAAS,IAAI,KAAK,CAAC;CACjD,OAAO,EAAE,IACP;EACE,EAAE,UAAU,WAAW,OAAO;EAC9B,EAAE,UAAU,SAAS,IAAI;EACzB,EAAE,UAAU,UAAU,IAAI;EAE1B,EAAE,UAAU,SAAS,gBAAgB;EACrC,EAAE,WAAW,IAAI;EACjB,GAAG,QAAQ,UAAU;CACvB,GACA,MAAM,IAAI,KAAK,CACjB;AACF"}
1
+ {"version":3,"file":"icon-0A2dBtqj.mjs","names":[],"sources":["../src/icon.ts"],"sourcesContent":["/**\n * An icon as data: what a build reads from an icon set or an SVG file, parsed\n * (`foldkit-media/icons`), not markup to set as HTML. A view draws it\n * (`draw`), and a style masks with it (`maskUrl`),\n * from the one value.\n */\n\n/** The elements an icon may hold: presentational SVG, nothing that runs, loads or holds text. */\nexport const TAGS = [\n 'g',\n 'path',\n 'circle',\n 'ellipse',\n 'rect',\n 'line',\n 'polyline',\n 'polygon',\n 'defs',\n 'linearGradient',\n 'radialGradient',\n 'stop',\n 'clipPath',\n 'mask',\n 'use',\n] as const\nexport type SvgTag = (typeof TAGS)[number]\n\n/** One element of an icon's drawing, and its children. */\nexport interface SvgNode {\n readonly tag: SvgTag\n readonly attributes: Readonly<Record<string, string>>\n readonly children: ReadonlyArray<SvgNode>\n}\n\n/** An icon: its `viewBox`, the attributes its root `svg` carries (its fill and stroke), and its drawing. */\nexport interface IconData {\n readonly viewBox: string\n readonly attributes: Readonly<Record<string, string>>\n readonly nodes: ReadonlyArray<SvgNode>\n}\n\nconst escapeAttribute = (value: string): string =>\n value.replace(/&/g, '&amp;').replace(/\"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;')\n\nconst attributesOf = (attributes: Readonly<Record<string, string>>): string =>\n Object.entries(attributes)\n .map(([name, value]) => ` ${name}=\"${escapeAttribute(value)}\"`)\n .join('')\n\nconst nodeMarkup = ({ tag, attributes, children }: SvgNode): string =>\n children.length === 0\n ? `<${tag}${attributesOf(attributes)}/>`\n : `<${tag}${attributesOf(attributes)}>${children.map(nodeMarkup).join('')}</${tag}>`\n\n/** The icon as one standalone `svg` document. */\nexport const serialize = (icon: IconData): string =>\n `<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"${escapeAttribute(icon.viewBox)}\"${attributesOf(icon.attributes)}>${icon.nodes.map(nodeMarkup).join('')}</svg>`\n\n/**\n * The icon as a CSS `url()`, for a mask (`Icons.byAttribute`, `Icons.glyph`):\n * a mask reads only the drawing's shape, so its colours do not matter, and\n * the element it masks paints in `currentColor`.\n */\nexport const maskUrl = (icon: IconData): string =>\n // Only what a data URL in a quoted CSS `url()` cannot hold is escaped (a line break ends a CSS\n // string): a theme writes every chrome icon this way, and escaping the spaces, `=` and `/`\n // too adds a quarter to each.\n `url(\"data:image/svg+xml,${serialize(icon).replace(/[%#<>\"\\n\\r\\t]/g, unsafe => `%${unsafe.charCodeAt(0).toString(16).padStart(2, '0').toUpperCase()}`)}\")`\n\nconst keys = new WeakMap<IconData, string>()\n\n/**\n * A short name for the icon, from its content: the same drawing has the same\n * key on a server and in the browser, and two drawings almost never share\n * one. A drawing's ids are prefixed with it, and a sprite names its symbol by it.\n */\nexport const key = (icon: IconData): string => {\n const known = keys.get(icon)\n if (known !== undefined) return known\n // 64-bit FNV-1a over the serialized drawing.\n let hash = 0xcbf29ce484222325n\n for (const unit of serialize(icon)) {\n hash ^= BigInt(unit.codePointAt(0)!)\n hash = BigInt.asUintN(64, hash * 0x100000001b3n)\n }\n const made = `i${hash.toString(36)}`\n keys.set(icon, made)\n return made\n}\n\nconst idsOf = (nodes: ReadonlyArray<SvgNode>, into: Set<string>): Set<string> => {\n for (const node of nodes) {\n if (node.attributes['id'] !== undefined) into.add(node.attributes['id'])\n idsOf(node.children, into)\n }\n return into\n}\n\ninterface Prefixed {\n readonly ids: ReadonlySet<string>\n readonly byPrefix: Map<string, IconData>\n}\n\nconst prefixed = new WeakMap<IconData, Prefixed>()\n\nconst idPrefix = (prefix: string): string => {\n if (/^(?!fk_)[A-Za-z0-9_-]+$/.test(prefix)) return prefix\n let encoded = ''\n for (let at = 0; at < prefix.length; at++) {\n encoded += prefix.charCodeAt(at).toString(16).padStart(4, '0')\n }\n return `fk_${encoded}`\n}\n\n/**\n * The icon with each id it defines, and each `href` and `url()` naming one,\n * prefixed: two icons drawn inline on one page share the document's ids, and\n * an exported SVG's `id=\"a\"` would otherwise paint another icon's gradient.\n * A prefix outside an identifier's safe characters is encoded before it\n * reaches a CSS `url()`. An icon with no ids is returned as it was given.\n * Kept per icon and prefix, since a view asks again on every render.\n */\nexport const prefixIds = (icon: IconData, prefix: string): IconData => {\n const memo = prefixed.get(icon) ?? { ids: idsOf(icon.nodes, new Set()), byPrefix: new Map() }\n prefixed.set(icon, memo)\n const { ids, byPrefix } = memo\n if (ids.size === 0) return icon\n const known = byPrefix.get(prefix)\n if (known !== undefined) return known\n const writtenPrefix = idPrefix(prefix)\n const rename = (id: string) => (ids.has(id) ? `${writtenPrefix}-${id}` : id)\n const rewriteValue = (name: string, value: string): string => {\n if (name === 'id') return rename(value)\n // The parser admits only a fragment `href`.\n if (name === 'href') return `#${rename(value.slice(1))}`\n return value.replace(\n /url\\(\\s*(['\"]?)#([^)'\"\\s]*)\\1\\s*\\)/gi,\n (_, quote: string, id: string) => `url(${quote}#${rename(id)}${quote})`,\n )\n }\n const rewrite = (attributes: Readonly<Record<string, string>>) =>\n Object.fromEntries(\n Object.entries(attributes).map(([name, value]) => [name, rewriteValue(name, value)]),\n )\n const walk = (node: SvgNode): SvgNode => ({\n tag: node.tag,\n attributes: rewrite(node.attributes),\n children: node.children.map(walk),\n })\n const made: IconData = {\n viewBox: icon.viewBox,\n attributes: rewrite(icon.attributes),\n nodes: icon.nodes.map(walk),\n }\n byPrefix.set(prefix, made)\n return made\n}\n\n/** How a drawing's strokes are drawn: their width, and whether their ends and joins are round. */\nexport interface Stroke {\n readonly width?: number | undefined\n readonly corners?: 'round' | 'square' | undefined\n}\n\n/**\n * The icon with its strokes redrawn: every `stroke-width`, `stroke-linecap`\n * and `stroke-linejoin` it sets replaced, or set on its root where it sets\n * none. A filled icon draws no stroke, so it is unchanged in what shows. For\n * a mask, whose drawing CSS cannot reach once it is a `url()`.\n */\nexport const withStroke = (icon: IconData, stroke: Stroke): IconData => {\n const set: Record<string, string> = {}\n if (stroke.width !== undefined) set['stroke-width'] = String(stroke.width)\n if (stroke.corners !== undefined) {\n set['stroke-linecap'] = stroke.corners\n set['stroke-linejoin'] = stroke.corners === 'round' ? 'round' : 'miter'\n }\n const names = Object.keys(set)\n const found = new Set<string>()\n const restroke = (attributes: Readonly<Record<string, string>>) => {\n const written = { ...attributes }\n for (const name of names) {\n if (Object.hasOwn(attributes, name)) {\n written[name] = set[name]!\n found.add(name)\n }\n }\n return written\n }\n const walk = (node: SvgNode): SvgNode => ({\n tag: node.tag,\n attributes: restroke(node.attributes),\n children: node.children.map(walk),\n })\n const nodes = icon.nodes.map(walk)\n const attributes = restroke(icon.attributes)\n // A property the drawing never sets is set once on the root, which every node inherits.\n for (const name of names) if (!found.has(name)) attributes[name] = set[name]!\n return { viewBox: icon.viewBox, attributes, nodes }\n}\n\ntype Element<Node, Attribute> = (\n attributes: ReadonlyArray<Attribute>,\n children: ReadonlyArray<Node>,\n) => Node\n\n/**\n * What `draw` needs of a view's builder: an element per tag an icon may hold,\n * and raw attributes. Foldkit's `HtmlBuilder` is one, so this package needs\n * no view library of its own.\n */\nexport type SvgBuilder<Node, Attribute> = {\n readonly svg: Element<Node, Attribute>\n readonly Attribute: (name: string, value: string) => Attribute\n readonly AriaHidden: (value: boolean) => Attribute\n} & { readonly [Tag in SvgTag]: Element<Node, Attribute> }\n\n/**\n * The icon as inline SVG, through a view's builder (`h`): `size` square\n * (`1em` unless given, so it stands as tall as its text; `foldkit-mixins-ui`'s\n * `Icon.view` fills its glyph with it), kept so in a squeezed flex row, and\n * hidden from assistive technology,\n * since the control it sits in carries the name. Every attribute is written as\n * an attribute, so a server render writes the same markup. Ids are prefixed by\n * `key(icon)`; `options.key` sets one drawing's ids apart from another of the\n * same icon, since a gradient defined in a copy that is hidden paints nothing\n * for the copy that shows. Each key's drawing is kept for the icon's life, so\n * take keys from a small fixed set (a place on the page), not one per row.\n */\nexport const draw = <Node, Attribute>(\n icon: IconData,\n h: SvgBuilder<Node, Attribute>,\n options: { readonly key?: string; readonly size?: string } = {},\n): Node => {\n const prefix = key(icon) + (options.key === undefined ? '' : `-${options.key}`)\n const { viewBox, attributes, nodes } = prefixIds(icon, prefix)\n const size = options.size ?? '1em'\n const written = (from: Readonly<Record<string, string>>) =>\n Object.entries(from).map(([name, value]) => h.Attribute(name, value))\n const drawn = ({ tag, attributes, children }: SvgNode): Node =>\n h[tag](written(attributes), children.map(drawn))\n return h.svg(\n [\n h.Attribute('viewBox', viewBox),\n h.Attribute('width', size),\n h.Attribute('height', size),\n // A flex row squeezed narrower than its content shrinks an svg to nothing, width or not.\n h.Attribute('style', 'flex-shrink: 0'),\n h.AriaHidden(true),\n ...written(attributes),\n ],\n nodes.map(drawn),\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAQA,MAAa,OAAO;CAClB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAiBA,MAAM,mBAAmB,UACvB,MAAM,QAAQ,MAAM,OAAO,CAAC,CAAC,QAAQ,MAAM,QAAQ,CAAC,CAAC,QAAQ,MAAM,MAAM,CAAC,CAAC,QAAQ,MAAM,MAAM;AAEjG,MAAM,gBAAgB,eACpB,OAAO,QAAQ,UAAU,CAAC,CACvB,KAAK,CAAC,MAAM,WAAW,I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AC,KAAK,CAAC,MAAM,WAAW,EAAE,UAAU,MAAM,KAAK,CAAC;CACtE,MAAM,SAAS,EAAE,KAAK,YAAY,eAChC,EAAE,IAAI,CAAC,QAAQ,UAAU,GAAG,SAAS,IAAI,KAAK,CAAC;CACjD,OAAO,EAAE,IACP;EACE,EAAE,UAAU,WAAW,OAAO;EAC9B,EAAE,UAAU,SAAS,IAAI;EACzB,EAAE,UAAU,UAAU,IAAI;EAE1B,EAAE,UAAU,SAAS,gBAAgB;EACrC,EAAE,WAAW,IAAI;EACjB,GAAG,QAAQ,UAAU;CACvB,GACA,MAAM,IAAI,KAAK,CACjB;AACF"}
@@ -84,6 +84,5 @@ declare const draw: <Node, Attribute>(icon: IconData, h: SvgBuilder<Node, Attrib
84
84
  readonly key?: string;
85
85
  readonly size?: string;
86
86
  }) => Node;
87
- //#endregion
88
87
  export { SvgTag as a, SvgNode as i, Stroke as n, icon_d_exports as o, SvgBuilder as r, IconData as t };
89
- //# sourceMappingURL=icon-ClqtprHT.d.mts.map
88
+ //# sourceMappingURL=icon-BGtxExTN.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"icon-ClqtprHT.d.mts","names":[],"sources":["../src/icon.ts"],"mappings":";;;;;;;;;;cAQa;KAiBD,iBAAiB;;UAGZ;WACN,KAAK;WACL,YAAY,SAAS;WACrB,UAAU,cAAc;;;UAIlB;WACN;WACA,YAAY,SAAS;WACrB,OAAO,cAAc;;;cAiBnB,YAAS,MAAU;;;;;;cAQnB,UAAO,MAAU;;;;;;cAajB,MAAG,MAAU;;;;;;;;;cA8Cb,YAAS,MAAU,UAAQ,mBAAmB;;UAqC1C;WACN;WACA;;;;;;;;cASE,aAAU,MAAU,UAAQ,QAAU,WAAS;KA+BvD,QAAQ,MAAM,cACjB,YAAY,cAAc,YAC1B,UAAU,cAAc,UACrB;;;;;;KAOO,WAAW,MAAM;WAClB,KAAK,QAAQ,MAAM;WACnB,YAAY,cAAc,kBAAkB;WAC5C,aAAa,mBAAmB;gBAC3B,OAAO,SAAS,QAAQ,MAAM;;;;;;;;;;;;;cAcjC,OAAQ,MAAM,WAAS,MAC5B,UAAQ,GACX,WAAW,MAAM,YAAU;WACV;WAAuB;MAC1C"}
1
+ {"version":3,"file":"icon-BGtxExTN.d.mts","names":[],"sources":["../src/icon.ts"],"mappings":";;;;;;;;;;cAQa;KAiBD,iBAAiB;;UAGZ;WACN,KAAK;WACL,YAAY,SAAS;WACrB,UAAU,cAAc;;;UAIlB;WACN;WACA,YAAY,SAAS;WACrB,OAAO,cAAc;;;cAiBnB,YAAS,MAAU;;;;;;cAQnB,UAAO,MAAU;;;;;;cAajB,MAAG,MAAU;;;;;;;;;cA8Cb,YAAS,MAAU,UAAQ,mBAAmB;;UAqC1C;WACN;WACA;;;;;;;;cASE,aAAU,MAAU,UAAQ,QAAU,WAAS;KA+BvD,QAAQ,MAAM,cACjB,YAAY,cAAc,YAC1B,UAAU,cAAc,UACrB;;;;;;KAOO,WAAW,MAAM;WAClB,KAAK,QAAQ,MAAM;WACnB,YAAY,cAAc,kBAAkB;WAC5C,aAAa,mBAAmB;gBAC3B,OAAO,SAAS,QAAQ,MAAM;;;;;;;;;;;;;cAcjC,OAAQ,MAAM,WAAS,MAC5B,UAAQ,GACX,WAAW,MAAM,YAAU;WACV;WAAuB;MAC1C"}
@@ -1,6 +1,5 @@
1
- import { t as IconData } from "../icon-ClqtprHT.mjs";
1
+ import { t as IconData } from "../icon-BGtxExTN.mjs";
2
2
  import { Schema } from "effect";
3
- //#region src/icons/index.d.ts
4
3
  /**
5
4
  * The icon in `svg`, one whole SVG document, as `IconData`; `name` says which
6
5
  * icon a refusal is about. Throws on anything outside the allowlist.
@@ -47,5 +46,4 @@ export declare const namesOf: (set: IconifySet) => ReadonlyArray<string>;
47
46
  * rather than drawn as a second, transformed drawing.
48
47
  */
49
48
  export declare const fromIconify: (set: IconifySet, name: string) => IconData;
50
- //#endregion
51
49
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/icons/index.ts"],"mappings":";;;;;;;qBA0Ha,QAAK,aAAe,iBAAiB;;;;;;qBAgMrC,YAAU,OAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;YAQX,oBAAoB,WAAW;;qBAG9B,UAAO,KAAS,eAAa;;;;;;qBAU7B,cAAW,KAAS,YAAU,iBAAiB"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/icons/index.ts"],"mappings":";;;;;;qBA0Ha,QAAK,aAAe,iBAAiB;;;;;;qBAgMrC,YAAU,OAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;YAQX,oBAAoB,WAAW;;qBAG9B,UAAO,KAAS,eAAa;;;;;;qBAU7B,cAAW,KAAS,YAAU,iBAAiB"}
@@ -1,6 +1,6 @@
1
- import { t as TAGS } from "../icon-CowP8fQ0.mjs";
1
+ import { t as TAGS } from "../icon-0A2dBtqj.mjs";
2
2
  import { Schema } from "effect";
3
- //#region src/icons/index.ts
3
+ // src/icons/index.ts
4
4
  /**
5
5
  * SVG to `IconData`, for builds and generator scripts: a Vite plugin reading
6
6
  * an icon set, a script writing a package's icon constants. The parse is where
@@ -314,7 +314,6 @@ const fromIconify = (set, name) => {
314
314
  const read = (key, otherwise) => nearest.find((box) => box[key] !== void 0)?.[key] ?? otherwise;
315
315
  return parse(`<svg viewBox="${read("left", 0)} ${read("top", 0)} ${read("width", 16)} ${read("height", 16)}">${icon.body}</svg>`, label);
316
316
  };
317
- //#endregion
318
317
  export { IconifySet, fromIconify, namesOf, parse };
319
318
 
320
319
  //# sourceMappingURL=index.mjs.map
package/dist/index.d.mts CHANGED
@@ -1,9 +1,9 @@
1
- import { n as ImageAsset, r as Placeholder, t as Focus } from "./asset-BNQ_j5tO.mjs";
2
- import { i as describe, n as Inspector, r as Thumbnail, t as Inspected } from "./describe-DdYvLhMY.mjs";
3
- import { a as mimeType, i as Format, n as widths_d_exports, r as Encoding, t as Widths } from "./widths-Cg7-x89y.mjs";
4
- import { r as variant_d_exports } from "./variant-BOg1M0Wj.mjs";
5
- import { a as SvgTag, i as SvgNode, n as Stroke, o as icon_d_exports, r as SvgBuilder, t as IconData } from "./icon-ClqtprHT.mjs";
6
- import { n as provider_d_exports, t as Provider } from "./provider-DztvQjOr.mjs";
1
+ import { a as isHashed, i as Placeholder, n as HashedAsset, r as ImageAsset, t as Focus } from "./asset-BLo8VWmd.mjs";
2
+ import { i as describe, n as Inspector, r as Thumbnail, t as Inspected } from "./describe-BOgc0xbR.mjs";
3
+ import { a as mimeType, i as Format, n as widths_d_exports, r as Encoding, t as Widths } from "./widths-upkgLdek.mjs";
4
+ import { r as variant_d_exports } from "./variant-B-vyMmFB.mjs";
5
+ import { a as SvgTag, i as SvgNode, n as Stroke, o as icon_d_exports, r as SvgBuilder, t as IconData } from "./icon-BGtxExTN.mjs";
6
+ import { n as Provider, r as provider_d_exports } from "./provider-CB0nqu0m.mjs";
7
7
  import { Option, Schema } from "effect";
8
8
  declare namespace layout_d_exports {
9
9
  export { Candidate, Constrained, Fixed, FullWidth, Layout, LayoutSchema as Schema, box, candidates, ratio, sizes$1 as sizes };
@@ -63,8 +63,6 @@ declare const box: (layout: Layout, asset: Pick<ImageAsset, 'width' | 'height'>)
63
63
  readonly width: number;
64
64
  readonly height: number;
65
65
  };
66
- //#endregion
67
- //#region src/placeholder.d.ts
68
66
  /**
69
67
  * How much of a ThumbHash a placeholder paints: its blurred picture
70
68
  * (`detail`), or its average color (`average`).
@@ -107,9 +105,10 @@ interface Picture {
107
105
  */
108
106
  readonly placeholder: Option.Option<string>;
109
107
  }
110
- interface Input {
111
- readonly asset: ImageAsset;
112
- readonly provider: Provider;
108
+ /** An image's facts, and a provider that takes them: a hashed one for `Provider.hosted`. */
109
+ interface Input<Asset extends ImageAsset = ImageAsset> {
110
+ readonly asset: Asset;
111
+ readonly provider: Provider<NoInfer<Asset>>;
113
112
  readonly layout: Layout;
114
113
  /** The page's largest image: fetched first, not lazily. */
115
114
  readonly priority?: boolean;
@@ -128,7 +127,7 @@ interface Input {
128
127
  * this image). Candidates the provider lacks are left out, never written as a
129
128
  * broken URL.
130
129
  */
131
- declare const derive: (input: Input) => Option.Option<Picture>;
130
+ declare const derive: <Asset extends ImageAsset>(input: Input<Asset>) => Option.Option<Picture>;
132
131
  /** What a preload names: the candidates the browser will choose from, at the `img`'s sizes. */
133
132
  interface Preloaded {
134
133
  /** A `source`'s media type, so a browser that cannot show it skips the preload. */
@@ -153,7 +152,6 @@ declare const preload: ({ sources, img }: Picture) => string;
153
152
  * AVIF, as an absolute URL against `origin`. None when the provider has no
154
153
  * such variant.
155
154
  */
156
- declare const ogImage: (asset: ImageAsset, provider: Provider, origin: string) => Option.Option<string>;
157
- //#endregion
158
- export { type Encoding, Focus, Format, icon_d_exports as Icon, type IconData, ImageAsset, type Inspected, Inspector, layout_d_exports as Layout, picture_d_exports as Picture, Placeholder, provider_d_exports as Provider, type Stroke, type SvgBuilder, type SvgNode, type SvgTag, type Thumbnail, variant_d_exports as Variant, widths_d_exports as Widths, describe, mimeType };
155
+ declare const ogImage: <Asset extends ImageAsset>(asset: Asset, provider: Provider<NoInfer<Asset>>, origin: string) => Option.Option<string>;
156
+ export { type Encoding, Focus, Format, HashedAsset, icon_d_exports as Icon, type IconData, ImageAsset, type Inspected, Inspector, layout_d_exports as Layout, picture_d_exports as Picture, Placeholder, provider_d_exports as Provider, type Stroke, type SvgBuilder, type SvgNode, type SvgTag, type Thumbnail, variant_d_exports as Variant, widths_d_exports as Widths, describe, isHashed, mimeType };
159
157
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":["sizes","Layout.Layout"],"sources":["../src/layout.ts","../src/placeholder.ts","../src/picture.ts"],"mappings":";;;;;;;;;;;cAOM,cAAY,OAAA;;;;;;;;;KASN,gBAAgB,aAAa;cAE5B,QAAK;;;aAAL,OAAA;;;;cACA,cAAW;;;aAAX,OAAA;;;;cACA,iBAAgB;;;;;;UAOZ;WACN;WACA;;;;;;;;cASE,aAAU,QACb,QAAM,QACN,QAAM,sBAEb,cAAc;;cAkBJA,UAAK,QAAY;;cAQjB,QAAK,OAAW,KAAK;;;;;;cAQrB,MAAG,QACN,QAAM,OACP,KAAK;WACA;WAAwB;;;;;;;;KC3C1B;;;;;UC3BK;WACN;WACA;;;UAIM;WACN;WACA;WACA;WACA;WACA;WACA;WACA,UAAU,OAAO;WACjB,eAAe,OAAO;;;;;;UAOhB;;WAEN,SAAS,cAAc;WACvB,KAAK;;WAEL;;WAEA,OAAO,OAAO;;;;;WAKd,aAAa,OAAO;;UAGd;WACN,OAAO;WACP,UAAU;WACV,QAAQC;;WAER;;WAEA;;;;;;WAMA,cAAc;;;;;;;;cASZ,SAAM,OAAW,UAAQ,OAAO,OAAO;;UA0DnC;;WAEN,MAAM,OAAO;WACb;WACA;;;cAIE,gBAAW,MAAA,QAAA,SAA6B;;;;;;;;;cAoBxC,YAAO,SAAA,OAAsB;;;;;;;cAkB7B,UAAO,OACX,YAAU,UACP,UAAQ,mBAEjB,OAAO"}
1
+ {"version":3,"file":"index.d.mts","names":["sizes","Layout.Layout"],"sources":["../src/layout.ts","../src/placeholder.ts","../src/picture.ts"],"mappings":";;;;;;;;;;;cAOM,cAAY,OAAA;;;;;;;;;KASN,gBAAgB,aAAa;cAE5B,QAAK;;;;;;;cACL,cAAW;;;;;;;cACX,iBAAgB;;;;;;UAOZ;WACN;WACA;;;;;;;;cASE,aAAU,QACb,QAAM,QACN,QAAM,sBAEb,cAAc;;cAkBJA,UAAK,QAAY;;cAQjB,QAAK,OAAW,KAAK;;;;;;cAQrB,MAAG,QACN,QAAM,OACP,KAAK;WACA;WAAwB;;;;;;KC3C1B;;;;;UC3BK;WACN;WACA;;;UAIM;WACN;WACA;WACA;WACA;WACA;WACA;WACA,UAAU,OAAO;WACjB,eAAe,OAAO;;;;;;UAOhB;;WAEN,SAAS,cAAc;WACvB,KAAK;;WAEL;;WAEA,OAAO,OAAO;;;;;WAKd,aAAa,OAAO;;;UAId,MAAM,cAAc,aAAa;WACvC,OAAO;WACP,UAAU,SAAS,QAAQ;WAC3B,QAAQC;;WAER;;WAEA;;;;;;WAMA,cAAc;;;;;;;;cASZ,SAAU,cAAc,YAAU,OAAS,MAAM,WAAS,OAAO,OAAO;;UA0DpE;;WAEN,MAAM,OAAO;WACb;WACA;;;cAIE,gBAAW,MAAA,QAAA,SAA6B;;;;;;;;;cAoBxC,YAAO,SAAA,OAAsB;;;;;;;cAkB7B,UAAW,cAAc,YAAU,OACvC,OAAK,UACF,SAAS,QAAQ,SAAO,mBAEjC,OAAO"}