@gongbaodd/qr-renderer 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -12,12 +12,17 @@ npm install @gongbaodd/qr-renderer
12
12
  import { readFile, writeFile } from 'node:fs/promises'
13
13
  import { renderRecipeFile } from '@gongbaodd/qr-renderer/node'
14
14
 
15
- const { png, filename } = await renderRecipeFile(await readFile('mahu-qr.recipe.json'), { artifact: 'poster.png' })
15
+ const { png, filename } = await renderRecipeFile(await readFile('mahu-qr.recipe.json'), {
16
+ artifact: 'poster.png',
17
+ content: 'https://example.com/new',
18
+ })
16
19
  await writeFile(filename, png)
17
20
  ```
18
21
 
19
22
  `poster.png` is the default and contains the full assembled poster. Select `{ artifact: 'qr.png' }` for the standalone transparent QR image. The API returns `Uint8Array` PNG bytes and the matching filename; it does not read or write filesystem paths itself.
20
23
 
24
+ Set the optional `content` option to replace the recipe's saved QR text for this render while preserving its poster, placement, and settings. It must be non-empty, one line, and within QR capacity.
25
+
21
26
  `renderRecipeFile(input, options?)` accepts UTF-8 JSON text or bytes. `renderRecipeJson(value, options?)` accepts an already parsed JSON value. Both validate the recipe schema and renderer version, enforce recipe and PNG limits, verify embedded image SHA-256 digests and dimensions, and run the normal assembly validation before returning an image. Invalid or unsupported recipes reject with an error. Inputs are processed locally: recipe content is never fetched, and this package makes no network requests.
22
27
 
23
28
  Recipes are versioned rendering inputs. A package release does not promise replay of renderer versions it does not support. Keep the recipe with its source assets and use a compatible renderer release for long-term reproduction.
package/dist/node.js CHANGED
@@ -3083,8 +3083,9 @@ async function sha256Hex(bytes) {
3083
3083
  const digest = await crypto.subtle.digest("SHA-256", bytes.slice().buffer);
3084
3084
  return [...new Uint8Array(digest)].map((byte) => byte.toString(16).padStart(2, "0")).join("");
3085
3085
  }
3086
- async function renderRecipe(imaging2, rawRecipe, artifact) {
3086
+ async function renderRecipe(imaging2, rawRecipe, artifact, contentOverride) {
3087
3087
  const recipe = recipeSchema.parse(rawRecipe);
3088
+ const content = contentOverride === void 0 ? recipe.content : contentSchema.parse(contentOverride);
3088
3089
  const poster = fromBase64(recipe.source.poster.data);
3089
3090
  const regionMask = fromBase64(recipe.source.regionMask.data);
3090
3091
  const [posterSha, maskSha] = await Promise.all([sha256Hex(poster), sha256Hex(regionMask)]);
@@ -3099,7 +3100,7 @@ async function renderRecipe(imaging2, rawRecipe, artifact) {
3099
3100
  posterBytes: poster,
3100
3101
  maskBytes: regionMask,
3101
3102
  transparentBlank: recipe.source.transparentBlank,
3102
- content: recipe.content,
3103
+ content,
3103
3104
  placement: recipe.placement,
3104
3105
  ...settings
3105
3106
  });
@@ -3111,7 +3112,7 @@ async function renderRecipe(imaging2, rawRecipe, artifact) {
3111
3112
  // src/node.ts
3112
3113
  async function renderRecipeJson(rawRecipe, options = {}) {
3113
3114
  const artifact = options.artifact ?? "poster.png";
3114
- const result = await renderRecipe(nodeImaging, rawRecipe, artifact);
3115
+ const result = await renderRecipe(nodeImaging, rawRecipe, artifact, options.content);
3115
3116
  return { png: new Uint8Array(await result.png.arrayBuffer()), filename: result.filename };
3116
3117
  }
3117
3118
  async function renderRecipeFile(input, options = {}) {
@@ -2,6 +2,7 @@ import { type PortableRecipe } from './recipe';
2
2
  export type RecipeArtifact = 'poster.png' | 'qr.png';
3
3
  export interface RenderRecipeOptions {
4
4
  artifact?: RecipeArtifact;
5
+ content?: string;
5
6
  }
6
7
  export interface RenderRecipeResult {
7
8
  png: Uint8Array;
@@ -126,7 +126,7 @@ export declare const recipeSchema: z.ZodObject<{
126
126
  }, z.core.$strict>;
127
127
  export type PortableRecipe = z.infer<typeof recipeSchema>;
128
128
  export declare function createRecipeBlob(input: AssembleInput, finalMask: Blob): Promise<Blob>;
129
- export declare function renderRecipe(imaging: Imaging, rawRecipe: unknown, artifact: 'poster.png' | 'qr.png'): Promise<{
129
+ export declare function renderRecipe(imaging: Imaging, rawRecipe: unknown, artifact: 'poster.png' | 'qr.png', contentOverride?: string): Promise<{
130
130
  png: Blob;
131
131
  filename: string;
132
132
  }>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gongbaodd/qr-renderer",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Generate artistic QR posters from mahu-QR portable recipe JSON.",
5
5
  "license": "MIT",
6
6
  "repository": {
package/src/node.ts CHANGED
@@ -6,6 +6,7 @@ export type RecipeArtifact = 'poster.png' | 'qr.png'
6
6
 
7
7
  export interface RenderRecipeOptions {
8
8
  artifact?: RecipeArtifact
9
+ content?: string
9
10
  }
10
11
 
11
12
  export interface RenderRecipeResult {
@@ -19,7 +20,7 @@ export async function renderRecipeJson(
19
20
  options: RenderRecipeOptions = {},
20
21
  ): Promise<RenderRecipeResult> {
21
22
  const artifact = options.artifact ?? 'poster.png'
22
- const result = await renderRecipe(nodeImaging, rawRecipe, artifact)
23
+ const result = await renderRecipe(nodeImaging, rawRecipe, artifact, options.content)
23
24
  return { png: new Uint8Array(await result.png.arrayBuffer()), filename: result.filename as RecipeArtifact }
24
25
  }
25
26
 
package/src/recipe.ts CHANGED
@@ -129,8 +129,10 @@ export async function renderRecipe(
129
129
  imaging: Imaging,
130
130
  rawRecipe: unknown,
131
131
  artifact: 'poster.png' | 'qr.png',
132
+ contentOverride?: string,
132
133
  ): Promise<{ png: Blob; filename: string }> {
133
134
  const recipe = recipeSchema.parse(rawRecipe)
135
+ const content = contentOverride === undefined ? recipe.content : contentSchema.parse(contentOverride)
134
136
  const poster = fromBase64(recipe.source.poster.data)
135
137
  const regionMask = fromBase64(recipe.source.regionMask.data)
136
138
  const [posterSha, maskSha] = await Promise.all([sha256Hex(poster), sha256Hex(regionMask)])
@@ -151,7 +153,7 @@ export async function renderRecipe(
151
153
  posterBytes: poster,
152
154
  maskBytes: regionMask,
153
155
  transparentBlank: recipe.source.transparentBlank,
154
- content: recipe.content,
156
+ content,
155
157
  placement: recipe.placement,
156
158
  ...settings,
157
159
  })