@orangecatai/adgen-canvas 0.0.33 → 0.0.35

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 (36) hide show
  1. package/dist/dev/{chunk-BSCN3CPW.js → chunk-AVI2TDX6.js} +2 -2
  2. package/dist/dev/{chunk-O66HSY73.js → chunk-KJZTX4HK.js} +9 -6
  3. package/dist/dev/{chunk-O66HSY73.js.map → chunk-KJZTX4HK.js.map} +3 -3
  4. package/dist/dev/data/{image-ADAEIYVZ.js → image-JWQCODTZ.js} +3 -3
  5. package/dist/dev/index.css +714 -704
  6. package/dist/dev/index.css.map +3 -3
  7. package/dist/dev/index.js +9779 -8212
  8. package/dist/dev/index.js.map +4 -4
  9. package/dist/dev/subset-shared.chunk.js +1 -1
  10. package/dist/dev/subset-worker.chunk.js +1 -1
  11. package/dist/prod/{chunk-MBLHWEZ7.js → chunk-R3CESCMK.js} +3 -3
  12. package/dist/prod/{chunk-DB27YYNM.js → chunk-TE4JIU3E.js} +1 -1
  13. package/dist/prod/data/image-EQCUXFMW.js +1 -0
  14. package/dist/prod/index.css +1 -1
  15. package/dist/prod/index.js +165 -103
  16. package/dist/prod/subset-shared.chunk.js +1 -1
  17. package/dist/prod/subset-worker.chunk.js +1 -1
  18. package/dist/types/element/src/frame.d.ts +16 -0
  19. package/dist/types/excalidraw/components/ImageGeneratorPanel.d.ts +15 -0
  20. package/dist/types/excalidraw/components/ai-chat/imagePayload.d.ts +2 -19
  21. package/dist/types/excalidraw/components/auto-resize/AutoResizePanel.d.ts +3 -4
  22. package/dist/types/excalidraw/components/auto-resize/autoResizeEngine.d.ts +17 -14
  23. package/dist/types/excalidraw/components/auto-resize/backgroundExtend.d.ts +105 -0
  24. package/dist/types/excalidraw/components/auto-resize/frameSource.d.ts +16 -0
  25. package/dist/types/excalidraw/components/frameToolbarVariant.d.ts +34 -1
  26. package/dist/types/excalidraw/components/video/pendingVideoGenerations.d.ts +46 -0
  27. package/dist/types/excalidraw/renderer/staticSvgScene.d.ts +1 -1
  28. package/dist/types/excalidraw/types.d.ts +23 -4
  29. package/dist/types/excalidraw/utils/brandContextUtils.d.ts +11 -6
  30. package/dist/types/excalidraw/utils/imageApi.d.ts +52 -6
  31. package/dist/types/excalidraw/utils/imageCompression.d.ts +46 -0
  32. package/dist/types/excalidraw/utils/referenceBudget.d.ts +138 -0
  33. package/package.json +1 -1
  34. package/dist/prod/data/image-ALVZ6E6S.js +0 -1
  35. /package/dist/dev/{chunk-BSCN3CPW.js.map → chunk-AVI2TDX6.js.map} +0 -0
  36. /package/dist/dev/data/{image-ADAEIYVZ.js.map → image-JWQCODTZ.js.map} +0 -0
@@ -0,0 +1,138 @@
1
+ /**
2
+ * Ranked slot allocation for the reference images attached to an image
3
+ * generation request.
4
+ *
5
+ * ## Why this exists
6
+ *
7
+ * The previous rule was a single boolean: if the user attached ANY reference,
8
+ * the brand logo, both font specimens, and every host-injected brand asset were
9
+ * deleted. Unconditionally — no size check, no count check. That made
10
+ * "replace their logo with ours" unsatisfiable, because the logo the prompt
11
+ * asked for was never attached.
12
+ *
13
+ * The real constraint was never "brand assets compete with the user" — it is
14
+ * the host proxy's platform request cap (Vercel rejects bodies over 4.5 MB at
15
+ * the edge with an opaque 413). Competition is solved by ORDER and by the
16
+ * prompt's precedence rules, not by deletion.
17
+ *
18
+ * ## The contract
19
+ *
20
+ * Priority, highest first:
21
+ *
22
+ * 1. `user` — references the user attached themselves (max 6)
23
+ * 2. `source` — the image being edited or resized (quick edit, resize)
24
+ * 3. `logo` — the brand logo
25
+ * 4. `brandAsset` — product / lifestyle photos from the brand bank
26
+ * 5. `adReference` — existing ad creatives and template thumbnails
27
+ *
28
+ * Everything is sent when it fits. Truncation happens ONLY when the count or
29
+ * byte budget is exceeded, and always from the bottom up — never touching
30
+ * `user`, and never touching `logo` unless the caller marks it droppable
31
+ * (quick edit and resize, where the source image matters more).
32
+ *
33
+ * Brand assets and ad references degrade gracefully: surplus copies go first,
34
+ * so one of each survives as long as possible, and only then is a whole tier
35
+ * given up — ad references before brand assets, per the priority order.
36
+ *
37
+ * The floor is therefore 6 user references + the logo.
38
+ *
39
+ * ## Compression first, always
40
+ *
41
+ * Dropping a reference is the last resort, not the first. `prepareReferences`
42
+ * downscales everything, then escalates compression on the largest offenders,
43
+ * and only starts shedding slots if the payload is *still* over budget.
44
+ */
45
+ /** Reference tiers in descending priority. Index === priority rank. */
46
+ export declare const REFERENCE_TIERS: readonly ["user", "source", "logo", "brandAsset", "adReference"];
47
+ export type ReferenceTier = typeof REFERENCE_TIERS[number];
48
+ export interface ReferenceSlot {
49
+ tier: ReferenceTier;
50
+ /**
51
+ * The image itself. Empty string marks a *placeholder* — a slot the host
52
+ * proxy will fill from the brand database, which the SDK can only reserve
53
+ * room for because it never sees the bytes. `bytes` carries the reservation.
54
+ */
55
+ dataUrl: string;
56
+ /** Human label used in the reference manifest. */
57
+ label?: string;
58
+ /** Wire-byte estimate. Derived from `dataUrl` when omitted. */
59
+ bytes?: number;
60
+ }
61
+ export interface DroppedSlot {
62
+ tier: ReferenceTier;
63
+ label?: string;
64
+ reason: "count" | "bytes";
65
+ }
66
+ /**
67
+ * Hard cap on user-supplied reference images per generation. Six covers every
68
+ * realistic ad brief and keeps the request inside the limits of the models we
69
+ * route to.
70
+ */
71
+ export declare const MAX_USER_REFERENCE_IMAGES = 6;
72
+ /**
73
+ * Ceiling on total attached references. 6 user + 1 source + 1 logo + 2 brand
74
+ * assets + 2 ad references. Comfortably under the ~20 images-per-request cap
75
+ * observed on OpenRouter.
76
+ */
77
+ export declare const MAX_REFERENCE_IMAGES = 12;
78
+ /**
79
+ * Wire-byte budget for the attached images alone.
80
+ *
81
+ * Vercel rejects at 4.5 MB. This leaves ~1.3 MB of headroom for the prompt,
82
+ * the brand context block, and the JSON envelope — all of which the caller can
83
+ * further reserve against via `reservedBytes`.
84
+ */
85
+ export declare const REFERENCE_WIRE_BUDGET_BYTES: number;
86
+ /**
87
+ * What the SDK assumes a host-injected brand asset costs on the wire, and the
88
+ * ceiling the host compresses each one down to before injecting it. Keeping
89
+ * both sides on the same number is what makes the SDK's reservation honest.
90
+ */
91
+ export declare const HOST_ASSET_BYTE_RESERVATION: number;
92
+ /** Sort into priority order, stable within a tier. */
93
+ export declare function orderByPriority(slots: ReferenceSlot[]): ReferenceSlot[];
94
+ /**
95
+ * The order in which slots may be shed, first to go listed first.
96
+ *
97
+ * `user` and `source` never appear — they are the request. `logo` appears only
98
+ * when `protectLogo` is false, and always last, so it outlives every brand
99
+ * asset.
100
+ */
101
+ export declare function shedOrder(slots: ReferenceSlot[], protectLogo: boolean): ReferenceSlot[];
102
+ export interface AllocateOptions {
103
+ /** Count ceiling. Defaults to {@link MAX_REFERENCE_IMAGES}. */
104
+ maxImages?: number;
105
+ /** Byte ceiling for images. Defaults to {@link REFERENCE_WIRE_BUDGET_BYTES}. */
106
+ maxBytes?: number;
107
+ /** Non-image payload (prompt, schemas) to charge against `maxBytes`. */
108
+ reservedBytes?: number;
109
+ /**
110
+ * False on surfaces where the source image outranks the logo — quick edit and
111
+ * resize. On generate flows the logo is part of the protected core.
112
+ */
113
+ protectLogo?: boolean;
114
+ }
115
+ export interface Allocation {
116
+ kept: ReferenceSlot[];
117
+ dropped: DroppedSlot[];
118
+ bytes: number;
119
+ /**
120
+ * True when the protected core alone still exceeds the budget. The caller
121
+ * should send anyway — a 413 with the user's own images is a better failure
122
+ * than silently generating without them.
123
+ */
124
+ overBudget: boolean;
125
+ }
126
+ /**
127
+ * Pure allocation: order, cap the user tier, then shed bottom-up until the
128
+ * count and byte budgets are met. No compression — see `prepareReferences`.
129
+ */
130
+ export declare function allocateReferences(slots: ReferenceSlot[], options?: AllocateOptions): Allocation;
131
+ /**
132
+ * Compress everything, escalate on the largest offenders, and only then shed
133
+ * slots. This is the entry point every image-generation surface should use.
134
+ *
135
+ * Placeholder slots (`dataUrl === ""`) are carried through untouched — the host
136
+ * compresses those on its side against {@link HOST_ASSET_BYTE_RESERVATION}.
137
+ */
138
+ export declare function prepareReferences(slots: ReferenceSlot[], options?: AllocateOptions): Promise<Allocation>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orangecatai/adgen-canvas",
3
- "version": "0.0.33",
3
+ "version": "0.0.35",
4
4
  "type": "module",
5
5
  "types": "./dist/types/excalidraw/index.d.ts",
6
6
  "main": "./dist/prod/index.js",
@@ -1 +0,0 @@
1
- import{S as a,T as b,U as c}from"../chunk-MBLHWEZ7.js";import"../chunk-DB27YYNM.js";import"../chunk-SRAX5OIU.js";export{c as decodePngMetadata,b as encodePngMetadata,a as getTEXtChunk};