@popcraft/kit 1.1.0 → 1.2.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 (92) hide show
  1. package/dist/chunks/{agent-UXEVU3PP.js → agent-ORS5BEZC.js} +1 -1
  2. package/dist/chunks/{builtin-Z3JB7AQR.js → builtin-2KL2EXTB.js} +3 -3
  3. package/dist/chunks/{buy-credits-G7NUE6ZB.js → buy-credits-NARMZ33F.js} +2 -2
  4. package/dist/chunks/{check-template-SOF7SCBW.js → check-template-6D3CE5JN.js} +2 -2
  5. package/dist/chunks/{chunk-XXR2TY7O.js → chunk-5DIPBJ54.js} +5 -5
  6. package/dist/chunks/{chunk-KSOUY2WC.js → chunk-7JRE5KFW.js} +17 -5
  7. package/dist/chunks/{chunk-TTHTG4AT.js → chunk-7K4DVIS7.js} +1 -1
  8. package/dist/chunks/{chunk-ODX6NC4Y.js → chunk-A433G4Q3.js} +1 -1
  9. package/dist/chunks/{chunk-YAIPIG2T.js → chunk-AQ7VIL3I.js} +5 -5
  10. package/dist/chunks/{chunk-FQAXGCTR.js → chunk-AX7B2WCS.js} +3 -3
  11. package/dist/chunks/{chunk-HJ2OTGEV.js → chunk-BO35G3Z6.js} +1 -1
  12. package/dist/chunks/{chunk-7HZDPAV4.js → chunk-BPU5YIDG.js} +11 -11
  13. package/dist/chunks/{chunk-JDKR2URT.js → chunk-C7L2KQY5.js} +2 -2
  14. package/dist/chunks/{chunk-EPXMVWU6.js → chunk-E56VSHG3.js} +9 -9
  15. package/dist/chunks/{chunk-KBH3DY37.js → chunk-FF2OZPHF.js} +3 -3
  16. package/dist/chunks/{chunk-ICG7LWCM.js → chunk-G73CQMMJ.js} +2 -2
  17. package/dist/chunks/{chunk-YBXHSJZG.js → chunk-H3F5EWSJ.js} +1 -1
  18. package/dist/chunks/{chunk-TU3AYIIJ.js → chunk-I5NXE524.js} +43 -43
  19. package/dist/chunks/{chunk-QU4HXR5E.js → chunk-IXK5DQVP.js} +5 -5
  20. package/dist/chunks/{chunk-TNQNH3V3.js → chunk-JGC6PIT5.js} +88 -13
  21. package/dist/chunks/{chunk-OI74BAIT.js → chunk-MBS22UU3.js} +1 -1
  22. package/dist/chunks/{chunk-TC7IHZZL.js → chunk-MJVFENH4.js} +3 -3
  23. package/dist/chunks/{chunk-253XHQUI.js → chunk-MO6VTJRB.js} +2 -2
  24. package/dist/chunks/{chunk-VULPLVRT.js → chunk-MWHXK5L3.js} +4 -4
  25. package/dist/chunks/{chunk-3LA7EL7G.js → chunk-OBCV7RHJ.js} +1 -1
  26. package/dist/chunks/{chunk-TWG5JTA7.js → chunk-PNLVMTDJ.js} +1 -1
  27. package/dist/chunks/{chunk-R2SDI262.js → chunk-Q2ZB3FHK.js} +12 -5
  28. package/dist/chunks/{chunk-KDLFP3DC.js → chunk-RAKVPFZV.js} +1 -1
  29. package/dist/chunks/{chunk-HRYJ5YQT.js → chunk-RUD5NE4E.js} +1 -1
  30. package/dist/chunks/{chunk-ZODSUXQL.js → chunk-U63R2IUJ.js} +2 -2
  31. package/dist/chunks/{chunk-QQL3GGJD.js → chunk-UGUFREHV.js} +4 -4
  32. package/dist/chunks/{chunk-3KNQR6CL.js → chunk-ULSPD424.js} +2 -2
  33. package/dist/chunks/{chunk-XLLXOVVZ.js → chunk-UMPR42SA.js} +5 -5
  34. package/dist/chunks/{chunk-YRGHWQT5.js → chunk-WEM3QUB5.js} +53 -20
  35. package/dist/chunks/{chunk-WFOR35TQ.js → chunk-XATKFHIC.js} +6 -6
  36. package/dist/chunks/{chunk-NCKYRWBR.js → chunk-XDEOO7Q3.js} +1 -1
  37. package/dist/chunks/{chunk-HFBXTTUQ.js → chunk-XLMMVQTY.js} +1 -1
  38. package/dist/chunks/{client-IKQMNK4P.js → client-3XVU7EZN.js} +2 -2
  39. package/dist/chunks/{client-J5DLHQY5.js → client-NKXABBB2.js} +1 -1
  40. package/dist/chunks/{client-CFUYJ27O.js → client-UEBKLRWH.js} +3 -3
  41. package/dist/chunks/{client-actions-MGRTGVLB.js → client-actions-HSU6LXB3.js} +5 -5
  42. package/dist/chunks/{dangerous-ZXVEEDTX.js → dangerous-IUSV6JMX.js} +3 -3
  43. package/dist/chunks/{delete-current-file-ATFSV5HE.js → delete-current-file-B7GF6WKT.js} +5 -5
  44. package/dist/chunks/{editor-seams-MNACNSMF.js → editor-seams-7V7DY52W.js} +12 -12
  45. package/dist/chunks/{editor-store-FGXPU3UO.js → editor-store-JFHEOFHY.js} +1 -1
  46. package/dist/chunks/{export-watermark-MYN7T5KL.js → export-watermark-22LJTK5X.js} +5 -5
  47. package/dist/chunks/{eyedropper-6T3GH5QA.js → eyedropper-BGMQDPTB.js} +1 -1
  48. package/dist/chunks/{generate-media-PUC27DFY.js → generate-media-7RV2ZT4X.js} +3 -3
  49. package/dist/chunks/{host-YBEAX4RZ.js → host-PPWYGYTN.js} +6 -6
  50. package/dist/chunks/{integrations-YFBT6VMA.js → integrations-TMJB7SEY.js} +1 -1
  51. package/dist/chunks/{libraries-XPQT4ICF.js → libraries-7AUYSQU4.js} +5 -5
  52. package/dist/chunks/{live-RWTT4BGD.js → live-JRCK5ROW.js} +1 -1
  53. package/dist/chunks/{media-tool-PRVEIKYF.js → media-tool-BGIARYN2.js} +1 -1
  54. package/dist/chunks/{new-file-7WMZVHYL.js → new-file-XB2B4U6V.js} +3 -3
  55. package/dist/chunks/{next-commerce-LNSNGX4Z.js → next-commerce-A7ZHR63R.js} +2 -2
  56. package/dist/chunks/{plugin-4JOUMU3A.js → plugin-J6JF3PXI.js} +2 -2
  57. package/dist/chunks/{plugin-import-3VAIIKAX.js → plugin-import-YRTFZW5S.js} +16 -16
  58. package/dist/chunks/{presence-WCPLK37W.js → presence-MW5DBXWS.js} +2 -2
  59. package/dist/chunks/{project-OXKZCAUE.js → project-37JVFD6K.js} +1 -1
  60. package/dist/chunks/{publish-site-W74H7AYH.js → publish-site-4BKVML3W.js} +6 -6
  61. package/dist/chunks/{publish-store-756CUU4F.js → publish-store-QXVBQRV7.js} +5 -5
  62. package/dist/chunks/{raster-actions-U5WAAU7C.js → raster-actions-FSIUMW5Y.js} +1 -1
  63. package/dist/chunks/{runner-KWTHN3U5.js → runner-Q53FUQ4P.js} +18 -18
  64. package/dist/chunks/{store-FFLZCMSB.js → store-QGNPU45L.js} +6 -6
  65. package/dist/chunks/{storefront-N3Q5WUPF.js → storefront-YZAY7XSO.js} +2 -2
  66. package/dist/chunks/{sync-ZMDBWZV7.js → sync-XVXFWCTT.js} +5 -5
  67. package/dist/chunks/{tabs-SSQFEWTW.js → tabs-GRBJ3KDT.js} +8 -8
  68. package/dist/chunks/{team-ZWNOX4CP.js → team-GWLLCLUM.js} +1 -1
  69. package/dist/chunks/{team-client-24UFEZIK.js → team-client-JTGXOWAU.js} +1 -1
  70. package/dist/chunks/{tools-P67S2SXN.js → tools-RMNATBMU.js} +2 -2
  71. package/dist/chunks/{ui-commands-OGE7WUKH.js → ui-commands-C4R3GX3N.js} +12 -12
  72. package/dist/chunks/{versions-77MNOGSJ.js → versions-33OVXBDN.js} +5 -5
  73. package/dist/index.js +1 -1
  74. package/dist/templates/count.js +1 -1
  75. package/dist/templates/index.js +12 -12
  76. package/dist/templates/motion/landing-hero/index.js +4 -4
  77. package/dist/templates/motion/launch-trailer/document.js +12 -12
  78. package/dist/templates/motion/launch-trailer/index.js +4 -4
  79. package/dist/templates/motion/launch-trailer/scenes.js +3 -3
  80. package/dist/templates/motion/template-wall.js +2 -2
  81. package/dist/templates/print/knit-christmas-tree-sweater.js +2 -2
  82. package/dist/templates/print/knit-nordic-snowflake-sweater.js +2 -2
  83. package/dist/templates/print/knit-shared.js +74 -1
  84. package/dist/templates/print/knit-snowflake-beanie.js +2 -2
  85. package/dist/templates/themes/holidays.js +5 -5
  86. package/dist/templates/themes/index.js +6 -6
  87. package/package.json +1 -1
  88. package/src/templates/print/knit-christmas-tree-sweater.ts +57 -20
  89. package/src/templates/print/knit-nordic-snowflake-sweater.ts +19 -6
  90. package/src/templates/print/knit-shared.ts +98 -11
  91. package/src/templates/print/knit-snowflake-beanie.ts +12 -4
  92. package/types/templates/src/print/knit-shared.d.ts +49 -1
@@ -6,7 +6,7 @@
6
6
 
7
7
  import { Kit } from '../kit'
8
8
  import { defineTemplate } from '../build'
9
- import { SWEATER_3XL, Stitches, YARN, clear, diamonds, knitPanel, knitPreset, lice, nordicStar, popcraftLogo, snowflake, zigzag } from './knit-shared'
9
+ import { SWEATER_3XL, Stitches, YARN, clear, diamonds, knitPanel, knitPreset, between, lice, linear, nordicStar, popcraftLogo, snowflake, zigzag } from './knit-shared'
10
10
 
11
11
  const NAME = 'Nordic snowflake knit sweater'
12
12
  // Palette slots: 0 base, 1 trim, then the design's.
@@ -46,12 +46,17 @@ export default defineTemplate({
46
46
  snowflake(f, 255, 282, 100, BLEACH)
47
47
  snowflake(f, 84, 262, 44, BLEACH)
48
48
  snowflake(f, 426, 262, 44, BLEACH)
49
- // The PopCraft wordmark under the big snowflake, in bleach, with a red snowflake either side like a pattern band.
50
- popcraftLogo(f, 255, 466, 290, BLEACH)
51
49
  for (const x of [44, 467]) snowflake(f, x, 466, 24, CHILI)
52
50
  hemBand(f, 628)
53
51
  lice(f, 160, 540, 32, BLEACH, clear(f, 6))
54
- knitPanel(k, k.sheet, front, YARNS, f, BLEACH)
52
+ knitPanel(k, k.sheet, front, YARNS, f, BLEACH, { layers: L => {
53
+ // Frost: an icy ring round the big snowflake, and a frost rising from the hem band, navy dithered with bleach.
54
+ L.halo(255, 290, 148, 148, YARN.bleach, 0.55, 0.8, 'Frost glow')
55
+ L.rect(0, 500, f.width, 66, linear(90, [[0, YARN.bleach, 0], [1, YARN.bleach, 0.5]]), 'Frost')
56
+ // The wordmark under it: a red shadow, then the letters frosting from bleach into navy at their feet.
57
+ L.logo(258, 470, 290, linear(90, [[0, YARN.chili]]), 'Logo shadow')
58
+ L.logo(255, 466, 290, linear(90, [[0, YARN.bleach], [0.5, YARN.bleach], [1, between(YARN.bleach, YARN.navy, 0.45)]]))
59
+ } })
55
60
 
56
61
  const b = new Stitches(back.width, back.height)
57
62
  yoke(b, 20)
@@ -60,14 +65,22 @@ export default defineTemplate({
60
65
  for (let x = 32; x < b.width; x += 64) snowflake(b, x, 470, 20, CHILI)
61
66
  hemBand(b, 628)
62
67
  lice(b, 130, 540, 32, BLEACH, clear(b, 6))
63
- knitPanel(k, k.addSheet(knitPreset(back)), back, YARNS, b, BLEACH)
68
+ knitPanel(k, k.addSheet(knitPreset(back)), back, YARNS, b, BLEACH, { layers: L => {
69
+ // Northern lights behind the wordmark: a red and a bleach ring dithered into the navy.
70
+ L.halo(255, 290, 280, 150, YARN.chili, 0.5, 0.9, 'Aurora red')
71
+ L.halo(255, 290, 250, 125, YARN.bleach, 0.35, 0.92, 'Aurora frost')
72
+ // Over the knitted letters (red, ringed in bleach) a shade: red at the top deepening toward navy below.
73
+ L.logo(255, 290, 410, linear(90, [[0, YARN.chili, 0], [0.45, YARN.chili, 0], [1, between(YARN.chili, YARN.navy, 0.55)]]), 'Logo shade')
74
+ } })
64
75
 
65
76
  for (const sleeve of [right, left]) {
66
77
  const s = new Stitches(sleeve.width, sleeve.height)
67
78
  for (let y = 110; y < 520; y += 130) snowflake(s, 255, y, 44, BLEACH)
68
79
  hemBand(s, 628)
69
80
  lice(s, 40, 540, 32, BLEACH, clear(s, 6))
70
- knitPanel(k, k.addSheet(knitPreset(sleeve)), sleeve, YARNS, s, BLEACH)
81
+ knitPanel(k, k.addSheet(knitPreset(sleeve)), sleeve, YARNS, s, BLEACH, { layers: L => {
82
+ for (let y = 110; y < 520; y += 130) L.halo(255, y, 66, 66, YARN.bleach, 0.45, 0.8, 'Frost glow')
83
+ } })
71
84
  }
72
85
  return k.doc
73
86
  },
@@ -14,7 +14,8 @@
14
14
  // The palette order is Popprint's: base, trim, then the design's own yarns. That is how the plugin reads a template
15
15
  // it did not build: the base and trim from the palette, the product and size from the grid.
16
16
 
17
- import { Kit } from '../kit'
17
+ import { Kit, hex } from '../kit'
18
+ import type { Paint, VectorPath } from '@/lib/document/types'
18
19
  import { LOGO_H, LOGO_ROWS, LOGO_W } from './knit-logo'
19
20
  import type { PagePreset } from '@/lib/presets/page-presets'
20
21
 
@@ -203,9 +204,9 @@ export const logoHeight = (width: number) => Math.round((width * LOGO_H) / LOGO_
203
204
  * it is inked. With `outline`, a ring `ring` stitches thick is knitted round it first, so it reads on a busy ground.
204
205
  * Returns its box, so the motifs around it can keep clear.
205
206
  */
206
- export function popcraftLogo(s: Stitches, cx: number, cy: number, width: number, c: number, outline?: { c: number, ring: number }) {
207
- const bits = logoMask(), h = logoHeight(width), x0 = Math.round(cx - width / 2), y0 = Math.round(cy - h / 2)
208
- const scale = LOGO_W / width
207
+ /** The wordmark as stitches, `width` across: each stitch is on when at least half of it is inked. */
208
+ export function logoStitches(width: number) {
209
+ const bits = logoMask(), h = logoHeight(width), scale = LOGO_W / width
209
210
  const on = new Uint8Array(width * h)
210
211
  for (let y = 0; y < h; y++) for (let x = 0; x < width; x++) {
211
212
  let ink = 0, all = 0
@@ -213,18 +214,26 @@ export function popcraftLogo(s: Stitches, cx: number, cy: number, width: number,
213
214
  for (let sx = Math.floor(x * scale); sx < Math.floor((x + 1) * scale); sx++) { all++; ink += bits[sy * LOGO_W + sx] }
214
215
  on[y * width + x] = ink * 2 >= all && all ? 1 : 0
215
216
  }
216
- const at = (x: number, y: number) => x >= 0 && y >= 0 && x < width && y < h && on[y * width + x] === 1
217
+ return { on, width, height: h, at: (x: number, y: number) => x >= 0 && y >= 0 && x < width && y < h && on[y * width + x] === 1 }
218
+ }
219
+
220
+ /**
221
+ * The PopCraft wordmark knitted into the stitches, `width` stitches wide, centred on (cx, cy). With `outline`, a ring
222
+ * `ring` stitches thick is knitted round it first, so it reads on a busy ground. Returns its box.
223
+ */
224
+ export function popcraftLogo(s: Stitches, cx: number, cy: number, width: number, c: number, outline?: { c: number, ring: number }) {
225
+ const L = logoStitches(width), x0 = Math.round(cx - width / 2), y0 = Math.round(cy - L.height / 2)
217
226
  if (outline) {
218
227
  const r = outline.ring
219
- for (let y = -r; y < h + r; y++) for (let x = -r; x < width + r; x++) {
228
+ for (let y = -r; y < L.height + r; y++) for (let x = -r; x < width + r; x++) {
220
229
  let near = false
221
- for (let dy = -r; dy <= r && !near; dy++) for (let dx = -r; dx <= r && !near; dx++) if (dx * dx + dy * dy <= r * r + r && at(x + dx, y + dy)) near = true
230
+ for (let dy = -r; dy <= r && !near; dy++) for (let dx = -r; dx <= r && !near; dx++) if (dx * dx + dy * dy <= r * r + r && L.at(x + dx, y + dy)) near = true
222
231
  if (near) s.set(x0 + x, y0 + y, outline.c)
223
232
  }
224
233
  }
225
- for (let y = 0; y < h; y++) for (let x = 0; x < width; x++) if (at(x, y)) s.set(x0 + x, y0 + y, c)
234
+ for (let y = 0; y < L.height; y++) for (let x = 0; x < width; x++) if (L.at(x, y)) s.set(x0 + x, y0 + y, c)
226
235
  const pad = outline ? outline.ring : 0
227
- return { x0: x0 - pad, y0: y0 - pad, x1: x0 + width + pad, y1: y0 + h + pad }
236
+ return { x0: x0 - pad, y0: y0 - pad, x1: x0 + width + pad, y1: y0 + L.height + pad }
228
237
  }
229
238
 
230
239
  /** A ribbon banner across (cx, cy): a band `w` by `h` with notched tails folded behind it in `shade`. */
@@ -260,7 +269,8 @@ export const clear = (s: Stitches, pad: number) => (x: number, y: number) => {
260
269
  * One panel on its sheet: the knit area, its stitch grid in `yarns` (base first, then trim, then the design's), and
261
270
  * the locked trim bands (in the `trim` palette role the template defines). Trim rows are knitted in the trim yarn whatever is drawn there, so they are filled with it.
262
271
  */
263
- export function knitPanel(k: Kit, sheet: string, panel: KnitPanel, yarns: readonly string[], s: Stitches, trimSlot: number) {
272
+ export function knitPanel(k: Kit, sheet: string, panel: KnitPanel, yarns: readonly string[], s: Stitches, trimSlot: number,
273
+ o: { blend?: 'DITHER' | 'HALFTONE', dot?: number, layers?: (L: KnitLayers) => void } = {}) {
264
274
  s.removeStrays()
265
275
  for (const [a, b] of panel.trim) s.rows(a, b, trimSlot)
266
276
  const chars = 'abcdefgh'
@@ -277,9 +287,86 @@ export function knitPanel(k: Kit, sheet: string, panel: KnitPanel, yarns: readon
277
287
  const area = k.frame(sheet, { x: 0, y: 0, width: panel.width * CELL, height: panel.height * CELL }, { name: 'Knit area', clip: true })
278
288
  const grid = k.pixels(area, [rows], key, { cell: CELL, name: 'Stitches', palette: [...yarns], absolute: { x: 0, y: 0 } })
279
289
  // Art dropped on the stitches snaps to the yarns, as on a knit Popprint builds.
280
- k.patch(grid, { layerPaletteSnap: true })
290
+ k.patch(grid, { layerPaletteSnap: true, layerBlend: o.blend ?? 'DITHER', ...(o.dot ? { layerHalftoneSize: o.dot } : {}) })
291
+ o.layers?.(new KnitLayers(k, grid))
292
+ // The trim yarn is knitted over whatever is drawn in the trim rows, so the layers are kept out of them too: a
293
+ // band of the trim yarn on top, at the grid's own level.
294
+ if (o.layers) for (const [a, b] of panel.trim) new KnitLayers(k, grid).rect(0, a, panel.width, b - a + 1, [{ ...k.paint('trim')[0] }], 'Trim yarn')
281
295
  for (const [a, b] of panel.trim) {
282
296
  const id = k.rect(sheet, panel.width * CELL, (b - a + 1) * CELL, 'trim', { name: 'Trim', absolute: { x: 0, y: a * CELL } })
283
297
  k.patch(id, { locked: true })
284
298
  }
285
299
  }
300
+
301
+ // ── Blended layers: art that lives INSIDE the stitch canvas as editable shapes ───────────────────────────────────
302
+ //
303
+ // A pixel canvas renders its child layers through its palette (lib/engine/shaders/pixel-layer-shader.wgsl): a colour
304
+ // between two yarns becomes a pattern of those two yarns in proportion, and a fading layer thins out stitch by stitch.
305
+ // `DITHER` knits the mix as an ordered (Bayer) pattern, the fine bird's-eye look of jacquard shading; `HALFTONE` as a
306
+ // 45° dot screen whose dots grow with the amount, the pop-art look. So with 4 yarns a design has every pair's blend
307
+ // as well — glows, shaded baubles, ombré bands — and each stays a shape the user can recolour, move or reshape.
308
+
309
+ /** A gradient stop: position 0–1, a yarn hex (or any colour between yarns), and an alpha. */
310
+ export type Stop = readonly [number, string, number?]
311
+ const stops = (s: readonly Stop[]) => s.map(([position, h, a]) => ({ position, color: hex(h, a ?? 1) }))
312
+ /** Linear, across the shape at `angle` degrees (0 = left to right, 90 = top to bottom). */
313
+ export function linear(angle: number, s: readonly Stop[]): Paint[] {
314
+ const r = (angle * Math.PI) / 180, dx = Math.cos(r) / 2, dy = Math.sin(r) / 2
315
+ return [{ type: 'GRADIENT_LINEAR', gradientStops: stops(s), gradientHandlePositions: [{ x: 0.5 - dx, y: 0.5 - dy }, { x: 0.5 + dx, y: 0.5 + dy }, { x: 0.5 - dy, y: 0.5 + dx }], opacity: 1, visible: true } as Paint]
316
+ }
317
+ /** Radial, from (cx, cy) in the shape's box (0–1) out to `r` of its size. */
318
+ export function radial(s: readonly Stop[], cx = 0.5, cy = 0.5, r = 0.5): Paint[] {
319
+ return [{ type: 'GRADIENT_RADIAL', gradientStops: stops(s), gradientHandlePositions: [{ x: cx, y: cy }, { x: cx + r, y: cy }, { x: cx, y: cy + r }], opacity: 1, visible: true } as Paint]
320
+ }
321
+ /** The colour halfway (or `t` of the way) between two yarns: what the canvas knits as a mix of them. */
322
+ export function between(a: string, b: string, t = 0.5) {
323
+ const p = (h: string, i: number) => parseInt(h.slice(1 + i * 2, 3 + i * 2), 16)
324
+ return '#' + [0, 1, 2].map(i => Math.round(p(a, i) + (p(b, i) - p(a, i)) * t).toString(16).padStart(2, '0')).join('')
325
+ }
326
+
327
+ /** Shapes added to a stitch canvas, in stitch coordinates; each is a layer the canvas blends into yarns. */
328
+ export class KnitLayers {
329
+ constructor(private k: Kit, private grid: string) {}
330
+ private add(x0: number, y0: number, w: number, h: number, paths: VectorPath[], fill: Paint[], name: string) {
331
+ return this.k.vector(this.grid, w * CELL, h * CELL, paths, fill, { name, absolute: { x: x0 * CELL, y: y0 * CELL } })
332
+ }
333
+ /** A closed shape through `pts` (stitches). */
334
+ poly(pts: readonly (readonly [number, number])[], fill: Paint[], name: string) {
335
+ const xs = pts.map(p => p[0]), ys = pts.map(p => p[1]), x0 = Math.min(...xs), y0 = Math.min(...ys)
336
+ const points = pts.map(([x, y]) => ({ x: (x - x0) * CELL, y: (y - y0) * CELL }))
337
+ return this.add(x0, y0, Math.max(...xs) - x0, Math.max(...ys) - y0, [{ points, closed: true }], fill, name)
338
+ }
339
+ /** An ellipse round (cx, cy), `rx` by `ry` stitches. */
340
+ ellipse(cx: number, cy: number, rx: number, ry: number, fill: Paint[], name: string) {
341
+ const n = 48, pts: [number, number][] = []
342
+ for (let i = 0; i < n; i++) { const a = (i / n) * Math.PI * 2; pts.push([cx + Math.cos(a) * rx, cy + Math.sin(a) * ry]) }
343
+ return this.poly(pts, fill, name)
344
+ }
345
+ rect(x: number, y: number, w: number, h: number, fill: Paint[], name: string) {
346
+ return this.poly([[x, y], [x + w, y], [x + w, y + h], [x, y + h]], fill, name)
347
+ }
348
+ /** A glow: a soft ring of `hex` round (cx, cy), densest `at` of the way out, fading to nothing both ways. */
349
+ halo(cx: number, cy: number, rx: number, ry: number, h: string, peak: number, at = 0.6, name = 'Glow') {
350
+ return this.ellipse(cx, cy, rx, ry, radial([[0, h, 0], [at * 0.6, h, peak * 0.35], [at, h, peak], [1, h, 0]]), name)
351
+ }
352
+ /** A shaded ball: lit from the upper left, `light` → `body` → `shadow`. */
353
+ bauble(cx: number, cy: number, r: number, light: string, body: string, shadow: string, name = 'Bauble') {
354
+ return this.ellipse(cx, cy, r, r, radial([[0, light], [0.35, body], [1, shadow]], 0.36, 0.32, 0.75), name)
355
+ }
356
+ /** The PopCraft wordmark as one vector layer, `width` stitches wide, centred on (cx, cy), filled with `fill`. */
357
+ logo(cx: number, cy: number, width: number, fill: Paint[], name = 'PopCraft logo') {
358
+ const L = logoStitches(width), x0 = Math.round(cx - width / 2), y0 = Math.round(cy - L.height / 2)
359
+ const paths: VectorPath[] = []
360
+ for (let y = 0; y < L.height; y++) {
361
+ for (let x = 0; x < width; x++) {
362
+ if (!L.at(x, y)) continue
363
+ let e = x
364
+ while (L.at(e + 1, y)) e++
365
+ const a = x * CELL, b = (e + 1) * CELL, t = y * CELL, u = (y + 1) * CELL
366
+ paths.push({ points: [{ x: a, y: t }, { x: b, y: t }, { x: b, y: u }, { x: a, y: u }], closed: true })
367
+ x = e
368
+ }
369
+ }
370
+ return { id: this.add(x0, y0, width, L.height, paths, fill, name), x0, y0, x1: x0 + width, y1: y0 + L.height }
371
+ }
372
+ }
@@ -5,7 +5,7 @@
5
5
 
6
6
  import { Kit } from '../kit'
7
7
  import { defineTemplate } from '../build'
8
- import { BEANIE, Stitches, YARN, clear, heart, knitPanel, knitPreset, lice, nordicStar, popcraftLogo, snowflake, zigzag } from './knit-shared'
8
+ import { BEANIE, Stitches, YARN, clear, heart, knitPanel, knitPreset, lice, between, linear, logoStitches, nordicStar, snowflake, zigzag } from './knit-shared'
9
9
 
10
10
  const NAME = 'Snowflake knit beanie'
11
11
  // No trim: the palette is the base, then the design's yarns (Popprint reads the base from the first).
@@ -30,12 +30,20 @@ export default defineTemplate({
30
30
  for (let x = 0; x < s.width; x += 82) snowflake(s, x + 41, 40, 24, BLEACH)
31
31
  zigzag(s, 80, 20, 7, 3, CHILI)
32
32
  // The PopCraft wordmark at the centre of the star band, a star either side of it.
33
- const logo = popcraftLogo(s, 205, 121, 150, BLEACH)
34
- for (let x = 0; x < s.width; x += 58) if (x + 29 + 27 < logo.x0 || x + 29 - 27 > logo.x1) nordicStar(s, x + 29, 124, 24, BLEACH, PINE)
33
+ const half = logoStitches(150).width / 2
34
+ for (let x = 0; x < s.width; x += 58) if (x + 29 + 27 < 205 - half || x + 29 - 27 > 205 + half) nordicStar(s, x + 29, 124, 24, BLEACH, PINE)
35
35
  zigzag(s, 160, 20, 7, 3, CHILI)
36
36
  for (let x = 0; x < s.width; x += 41) heart(s, x + 20, 198, 11, BLEACH)
37
37
  lice(s, 6, 70, 26, BLEACH, clear(s, 6))
38
- knitPanel(k, k.sheet, panel, YARNS, s, PINE)
38
+ knitPanel(k, k.sheet, panel, YARNS, s, PINE, { layers: L => {
39
+ // A glow behind the wordmark and the wordmark itself as layers, dithered: bleach letters warming toward red at
40
+ // their feet, in a soft bleach halo.
41
+ L.halo(205, 121, 110, 46, YARN.bleach, 0.45, 0.85, 'Logo glow')
42
+ L.logo(207, 123, 150, linear(90, [[0, YARN.chili]]), 'Logo shadow')
43
+ L.logo(205, 121, 150, linear(90, [[0, YARN.bleach], [0.55, YARN.bleach], [1, between(YARN.bleach, YARN.chili, 0.45)]]))
44
+ // Ombré at the crown: the snowflake band dithered from bleach-frosted to plain pine.
45
+ L.rect(0, 0, s.width, 18, linear(90, [[0, YARN.bleach, 0.55], [1, YARN.bleach, 0]]), 'Crown frost')
46
+ } })
39
47
  return k.doc
40
48
  },
41
49
  })
@@ -1,4 +1,5 @@
1
1
  import { Kit } from '../kit.js';
2
+ import type { Paint } from '../../../lib/document/types.js';
2
3
  import type { PagePreset } from '../../../lib/presets/page-presets.js';
3
4
  /** Printful's yarns used here (the 36 are in Popprint's catalog). */
4
5
  export declare const YARN: {
@@ -65,6 +66,17 @@ export declare const logoHeight: (width: number) => number;
65
66
  * it is inked. With `outline`, a ring `ring` stitches thick is knitted round it first, so it reads on a busy ground.
66
67
  * Returns its box, so the motifs around it can keep clear.
67
68
  */
69
+ /** The wordmark as stitches, `width` across: each stitch is on when at least half of it is inked. */
70
+ export declare function logoStitches(width: number): {
71
+ on: Uint8Array<ArrayBuffer>;
72
+ width: number;
73
+ height: number;
74
+ at: (x: number, y: number) => boolean;
75
+ };
76
+ /**
77
+ * The PopCraft wordmark knitted into the stitches, `width` stitches wide, centred on (cx, cy). With `outline`, a ring
78
+ * `ring` stitches thick is knitted round it first, so it reads on a busy ground. Returns its box.
79
+ */
68
80
  export declare function popcraftLogo(s: Stitches, cx: number, cy: number, width: number, c: number, outline?: {
69
81
  c: number;
70
82
  ring: number;
@@ -84,4 +96,40 @@ export declare const clear: (s: Stitches, pad: number) => (x: number, y: number)
84
96
  * One panel on its sheet: the knit area, its stitch grid in `yarns` (base first, then trim, then the design's), and
85
97
  * the locked trim bands (in the `trim` palette role the template defines). Trim rows are knitted in the trim yarn whatever is drawn there, so they are filled with it.
86
98
  */
87
- export declare function knitPanel(k: Kit, sheet: string, panel: KnitPanel, yarns: readonly string[], s: Stitches, trimSlot: number): void;
99
+ export declare function knitPanel(k: Kit, sheet: string, panel: KnitPanel, yarns: readonly string[], s: Stitches, trimSlot: number, o?: {
100
+ blend?: 'DITHER' | 'HALFTONE';
101
+ dot?: number;
102
+ layers?: (L: KnitLayers) => void;
103
+ }): void;
104
+ /** A gradient stop: position 0–1, a yarn hex (or any colour between yarns), and an alpha. */
105
+ export type Stop = readonly [number, string, number?];
106
+ /** Linear, across the shape at `angle` degrees (0 = left to right, 90 = top to bottom). */
107
+ export declare function linear(angle: number, s: readonly Stop[]): Paint[];
108
+ /** Radial, from (cx, cy) in the shape's box (0–1) out to `r` of its size. */
109
+ export declare function radial(s: readonly Stop[], cx?: number, cy?: number, r?: number): Paint[];
110
+ /** The colour halfway (or `t` of the way) between two yarns: what the canvas knits as a mix of them. */
111
+ export declare function between(a: string, b: string, t?: number): string;
112
+ /** Shapes added to a stitch canvas, in stitch coordinates; each is a layer the canvas blends into yarns. */
113
+ export declare class KnitLayers {
114
+ private k;
115
+ private grid;
116
+ constructor(k: Kit, grid: string);
117
+ private add;
118
+ /** A closed shape through `pts` (stitches). */
119
+ poly(pts: readonly (readonly [number, number])[], fill: Paint[], name: string): string;
120
+ /** An ellipse round (cx, cy), `rx` by `ry` stitches. */
121
+ ellipse(cx: number, cy: number, rx: number, ry: number, fill: Paint[], name: string): string;
122
+ rect(x: number, y: number, w: number, h: number, fill: Paint[], name: string): string;
123
+ /** A glow: a soft ring of `hex` round (cx, cy), densest `at` of the way out, fading to nothing both ways. */
124
+ halo(cx: number, cy: number, rx: number, ry: number, h: string, peak: number, at?: number, name?: string): string;
125
+ /** A shaded ball: lit from the upper left, `light` → `body` → `shadow`. */
126
+ bauble(cx: number, cy: number, r: number, light: string, body: string, shadow: string, name?: string): string;
127
+ /** The PopCraft wordmark as one vector layer, `width` stitches wide, centred on (cx, cy), filled with `fill`. */
128
+ logo(cx: number, cy: number, width: number, fill: Paint[], name?: string): {
129
+ id: string;
130
+ x0: number;
131
+ y0: number;
132
+ x1: number;
133
+ y1: number;
134
+ };
135
+ }