@popcraft/kit 1.2.2 → 1.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.
- package/dist/chunks/{agent-A7BOM22T.js → agent-FBOFA4L2.js} +1 -1
- package/dist/chunks/{builtin-AOXFUXCD.js → builtin-UNS7IRTZ.js} +3 -3
- package/dist/chunks/{buy-credits-EJCPC5V7.js → buy-credits-37KIF2FX.js} +2 -2
- package/dist/chunks/{check-template-V5U2PC6J.js → check-template-NTW22VNY.js} +2 -2
- package/dist/chunks/{chunk-33CFABZ2.js → chunk-2CMHDBFD.js} +43 -43
- package/dist/chunks/{chunk-X4B7SE3J.js → chunk-2ISMXQZH.js} +1 -1
- package/dist/chunks/{chunk-VV7HKDNH.js → chunk-4WOODRGC.js} +4 -4
- package/dist/chunks/{chunk-BOIBQ7MZ.js → chunk-5OKROQS5.js} +2 -2
- package/dist/chunks/{chunk-JZM5HWEX.js → chunk-6QIOHC6D.js} +1 -1
- package/dist/chunks/{chunk-OV2W3YJU.js → chunk-7ETSVZDD.js} +5 -5
- package/dist/chunks/{chunk-6RIRRH4P.js → chunk-7KJGH5DA.js} +3 -3
- package/dist/chunks/{chunk-JY7KJGXS.js → chunk-AIF72RXH.js} +8 -10
- package/dist/chunks/{chunk-JCV2E7HJ.js → chunk-BOJUI3OG.js} +20 -17
- package/dist/chunks/{chunk-DWEPCHQV.js → chunk-EA7WPVPB.js} +11 -11
- package/dist/chunks/{chunk-3UBIOYSA.js → chunk-EOER2JCK.js} +9 -9
- package/dist/chunks/{chunk-CVZA6HPL.js → chunk-FSM6RE22.js} +139 -4
- package/dist/chunks/{chunk-7CEUBEEL.js → chunk-GJXUDC7M.js} +40 -24
- package/dist/chunks/{chunk-MJVFENH4.js → chunk-HCFZGHJQ.js} +3 -3
- package/dist/chunks/{chunk-EUKKWV3G.js → chunk-IO6ER43U.js} +1 -1
- package/dist/chunks/{chunk-A72CYF2R.js → chunk-J3BR4XR7.js} +1 -1
- package/dist/chunks/{chunk-NPUNFQF3.js → chunk-JKYYRNHA.js} +6 -6
- package/dist/chunks/{chunk-24ZYL3SN.js → chunk-LEUINJWK.js} +1 -1
- package/dist/chunks/{chunk-SRY4ZWCH.js → chunk-LP7KEPZV.js} +3 -3
- package/dist/chunks/{chunk-HDSIM2CO.js → chunk-MBNDFL52.js} +2 -2
- package/dist/chunks/{chunk-C22ZRLC7.js → chunk-MRYCR76X.js} +5 -5
- package/dist/chunks/{chunk-KSNXRXZE.js → chunk-O2IDQSID.js} +1 -1
- package/dist/chunks/{chunk-M5ETLHVZ.js → chunk-ORSEXNAN.js} +2 -2
- package/dist/chunks/{chunk-WIQJ4QRA.js → chunk-OZDD4X2Z.js} +1 -1
- package/dist/chunks/{chunk-F7TJGTY6.js → chunk-QLMN2B6V.js} +2 -2
- package/dist/chunks/{chunk-S3LCCBYA.js → chunk-SYM2BMBO.js} +5 -5
- package/dist/chunks/{chunk-QTBLWSUJ.js → chunk-TEJDLWJQ.js} +1 -1
- package/dist/chunks/{chunk-FIJDYPTN.js → chunk-TMSCTWTK.js} +1 -1
- package/dist/chunks/{chunk-HSBUM7AM.js → chunk-TR73N5K3.js} +2 -2
- package/dist/chunks/{chunk-GZN3CWWE.js → chunk-UVHQ6OC6.js} +5 -5
- package/dist/chunks/{chunk-6S57YBJX.js → chunk-VH7BAQHO.js} +3 -1
- package/dist/chunks/{chunk-KA2MGAQJ.js → chunk-WLNCMP4R.js} +4 -4
- package/dist/chunks/{chunk-TPLD3ZO5.js → chunk-XPXDYITB.js} +1 -1
- package/dist/chunks/{client-ATCRQ4Z2.js → client-3O4IP7IV.js} +2 -2
- package/dist/chunks/{client-FKUY77S6.js → client-MGVU6BYH.js} +1 -1
- package/dist/chunks/{client-LD6UEIKF.js → client-NN7D5KOY.js} +3 -3
- package/dist/chunks/{client-actions-5ZFSAP4E.js → client-actions-EGFPGDRF.js} +5 -5
- package/dist/chunks/{dangerous-C7S2EUYQ.js → dangerous-KA4XBNPQ.js} +3 -3
- package/dist/chunks/{delete-current-file-BV4SUOBR.js → delete-current-file-JWRQEJD7.js} +5 -5
- package/dist/chunks/{editor-seams-Y5E3HJSY.js → editor-seams-SVNNJYML.js} +12 -12
- package/dist/chunks/{editor-store-JQA3IFQ4.js → editor-store-F55ZEWJH.js} +1 -1
- package/dist/chunks/{export-watermark-YUXHSEHB.js → export-watermark-2JR3IBVA.js} +5 -5
- package/dist/chunks/{eyedropper-OTQO5UFY.js → eyedropper-6GKVVVEE.js} +1 -1
- package/dist/chunks/{generate-media-4YZWLMG5.js → generate-media-XPID2HER.js} +3 -3
- package/dist/chunks/{host-SV2ZGKB3.js → host-I6KIHIVJ.js} +6 -6
- package/dist/chunks/{integrations-2J5ACHB3.js → integrations-QLSOUP5Z.js} +1 -1
- package/dist/chunks/{libraries-5WFWU4EA.js → libraries-AS5KS6VS.js} +5 -5
- package/dist/chunks/{live-7CTGJ4VD.js → live-ZQRP46FK.js} +1 -1
- package/dist/chunks/{media-tool-IHV3MK22.js → media-tool-M33SALHX.js} +1 -1
- package/dist/chunks/{new-file-Z5VURBEJ.js → new-file-J7EH3YKS.js} +3 -3
- package/dist/chunks/{next-commerce-BAVLRG73.js → next-commerce-7KAFFBWA.js} +2 -2
- package/dist/chunks/{plugin-MTBJ57I6.js → plugin-IQEMDPM3.js} +2 -2
- package/dist/chunks/{plugin-import-OW37E42K.js → plugin-import-EILLZJLX.js} +16 -16
- package/dist/chunks/{presence-AGLEN24G.js → presence-IJN6TO2U.js} +2 -2
- package/dist/chunks/{project-D3353YKF.js → project-GOALAIWW.js} +1 -1
- package/dist/chunks/{publish-site-ATYXDIV6.js → publish-site-I5BQK7VR.js} +6 -6
- package/dist/chunks/{publish-store-3LC6WJ4I.js → publish-store-WDLIOS5E.js} +5 -5
- package/dist/chunks/{raster-actions-IKOFMSP3.js → raster-actions-7CCO2RS5.js} +1 -1
- package/dist/chunks/{runner-66VO3EOK.js → runner-535UPLGO.js} +18 -18
- package/dist/chunks/{store-VLXBAKCI.js → store-J33GD3OK.js} +6 -6
- package/dist/chunks/{storefront-6LO77DYV.js → storefront-VZ5JGP6Q.js} +2 -2
- package/dist/chunks/{sync-E2ZSQO7W.js → sync-LN254R24.js} +5 -5
- package/dist/chunks/{tabs-UF4G2SFX.js → tabs-SRMAPWDX.js} +8 -8
- package/dist/chunks/{team-ZEB7U5XZ.js → team-P7EP6HAH.js} +1 -1
- package/dist/chunks/{team-client-GFSAI3BD.js → team-client-ATTL4BUG.js} +1 -1
- package/dist/chunks/{tools-AJX5HK2L.js → tools-F566WZLK.js} +2 -2
- package/dist/chunks/{ui-commands-IO47EC2X.js → ui-commands-2E6YO3G7.js} +12 -12
- package/dist/chunks/{versions-QBEREZYR.js → versions-ZSGH7ZJN.js} +5 -5
- package/dist/index.js +1 -1
- package/dist/templates/count.js +1 -1
- package/dist/templates/index.js +12 -12
- package/dist/templates/motion/landing-hero/index.js +4 -4
- package/dist/templates/motion/launch-trailer/document.js +12 -12
- package/dist/templates/motion/launch-trailer/index.js +4 -4
- package/dist/templates/motion/launch-trailer/scenes.js +3 -3
- package/dist/templates/motion/template-wall.js +2 -2
- package/dist/templates/print/knit-christmas-tree-sweater.js +2 -2
- package/dist/templates/print/knit-nordic-snowflake-sweater.js +2 -2
- package/dist/templates/print/knit-shared.js +3 -1
- package/dist/templates/print/knit-snowflake-beanie.js +2 -2
- package/dist/templates/themes/holidays.js +5 -5
- package/dist/templates/themes/index.js +6 -6
- package/package.json +1 -1
- package/src/templates/print/knit-christmas-tree-sweater.ts +21 -17
- package/src/templates/print/knit-nordic-snowflake-sweater.ts +45 -26
- package/src/templates/print/knit-shared.ts +118 -7
- package/src/templates/print/knit-snowflake-beanie.ts +9 -9
- package/types/templates/src/print/knit-shared.d.ts +49 -3
|
@@ -53,9 +53,28 @@ export const knitPreset = (p: KnitPanel): PagePreset => ({ id: `knit-${p.width}x
|
|
|
53
53
|
/** A panel's stitches, as palette slots (0 = the base). Everything draws in stitch coordinates. */
|
|
54
54
|
export class Stitches {
|
|
55
55
|
readonly cells: Uint8Array
|
|
56
|
-
|
|
56
|
+
/** Which motif layer drew each stitch last (-1: painted, not a layer). */
|
|
57
|
+
readonly owner: Int32Array
|
|
58
|
+
/** The motif layers, in the order first drawn: a name and a palette slot each. */
|
|
59
|
+
readonly motifs: { name: string, c: number }[] = []
|
|
60
|
+
private current: string | null = null
|
|
61
|
+
constructor(readonly width: number, readonly height: number) {
|
|
62
|
+
this.cells = new Uint8Array(width * height)
|
|
63
|
+
this.owner = new Int32Array(width * height).fill(-1)
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* What is drawn from here on is the motif `name`: knitPanel makes it a vector layer inside the stitch canvas (one
|
|
67
|
+
* per yarn it uses), so it can be moved, recoloured or deleted like any shape. `null` paints stitches directly.
|
|
68
|
+
*/
|
|
69
|
+
motif(name: string | null) { this.current = name; return this }
|
|
57
70
|
set(x: number, y: number, c: number) {
|
|
58
|
-
if (x
|
|
71
|
+
if (x < 0 || y < 0 || x >= this.width || y >= this.height) return
|
|
72
|
+
const i = y * this.width + x
|
|
73
|
+
this.cells[i] = c
|
|
74
|
+
if (this.current === null) { this.owner[i] = -1; return }
|
|
75
|
+
let m = this.motifs.findIndex(l => l.name === this.current && l.c === c)
|
|
76
|
+
if (m < 0) { m = this.motifs.length; this.motifs.push({ name: this.current, c }) }
|
|
77
|
+
this.owner[i] = m
|
|
59
78
|
}
|
|
60
79
|
get(x: number, y: number) { return this.cells[y * this.width + x] }
|
|
61
80
|
/** Every stitch in the box for which `inside(x, y)` holds, tested at the stitch's centre. */
|
|
@@ -270,9 +289,19 @@ export const clear = (s: Stitches, pad: number) => (x: number, y: number) => {
|
|
|
270
289
|
* 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.
|
|
271
290
|
*/
|
|
272
291
|
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 } = {}) {
|
|
292
|
+
o: { blend?: 'DITHER' | 'HALFTONE', dot?: number, under?: (L: KnitLayers) => void, layers?: (L: KnitLayers) => void } = {}) {
|
|
274
293
|
s.removeStrays()
|
|
294
|
+
s.motif(null)
|
|
275
295
|
for (const [a, b] of panel.trim) s.rows(a, b, trimSlot)
|
|
296
|
+
// Motifs become layers: each motif layer takes the stitches it drew last that still knit in its yarn (stray
|
|
297
|
+
// clean-up may have changed a few); everything else stays painted. The painted stitches under a layer are the base.
|
|
298
|
+
const masks = s.motifs.map(() => new Uint8Array(s.width * s.height))
|
|
299
|
+
const painted = s.cells.slice()
|
|
300
|
+
for (let i = 0; i < s.cells.length; i++) {
|
|
301
|
+
const m = s.owner[i]
|
|
302
|
+
if (m >= 0 && s.motifs[m].c === s.cells[i]) { masks[m][i] = 1; painted[i] = 0 }
|
|
303
|
+
}
|
|
304
|
+
s.cells.set(painted)
|
|
276
305
|
const chars = 'abcdefgh'
|
|
277
306
|
const key: Record<string, string> = {}
|
|
278
307
|
yarns.forEach((hex, i) => { key[chars[i]] = hex })
|
|
@@ -288,10 +317,13 @@ export function knitPanel(k: Kit, sheet: string, panel: KnitPanel, yarns: readon
|
|
|
288
317
|
const grid = k.pixels(area, [rows], key, { cell: CELL, name: 'Stitches', palette: [...yarns], absolute: { x: 0, y: 0 } })
|
|
289
318
|
// Art dropped on the stitches snaps to the yarns, as on a knit Popprint builds.
|
|
290
319
|
k.patch(grid, { layerPaletteSnap: true, layerBlend: o.blend ?? 'DITHER', ...(o.dot ? { layerHalftoneSize: o.dot } : {}) })
|
|
291
|
-
|
|
320
|
+
const L = new KnitLayers(k, grid, s.width, s.height)
|
|
321
|
+
o.under?.(L)
|
|
322
|
+
s.motifs.forEach((m, i) => L.mask(masks[i], s.width, s.height, solid(yarns[m.c]), s.motifs.filter(n => n.name === m.name).length > 1 ? `${m.name} · ${yarnName(yarns[m.c])}` : m.name))
|
|
323
|
+
o.layers?.(L)
|
|
292
324
|
// The trim yarn is knitted over whatever is drawn in the trim rows, so the layers are kept out of them too: a
|
|
293
325
|
// band of the trim yarn on top, at the grid's own level.
|
|
294
|
-
|
|
326
|
+
for (const [a, b] of panel.trim) L.rect(0, a, panel.width, b - a + 1, [{ ...k.paint('trim')[0] }], 'Trim yarn')
|
|
295
327
|
for (const [a, b] of panel.trim) {
|
|
296
328
|
const id = k.rect(sheet, panel.width * CELL, (b - a + 1) * CELL, 'trim', { name: 'Trim', absolute: { x: 0, y: a * CELL } })
|
|
297
329
|
k.patch(id, { locked: true })
|
|
@@ -324,10 +356,14 @@ export function between(a: string, b: string, t = 0.5) {
|
|
|
324
356
|
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
357
|
}
|
|
326
358
|
|
|
359
|
+
/** A flat fill in one yarn. */
|
|
360
|
+
export const solid = (h: string): Paint[] => [{ type: 'SOLID', color: hex(h), opacity: 1, visible: true } as Paint]
|
|
361
|
+
const yarnName = (h: string) => (Object.entries(YARN).find(([, v]) => v === h)?.[0] ?? h).replace(/^./, c => c.toUpperCase())
|
|
362
|
+
|
|
327
363
|
/** Shapes added to a stitch canvas, in stitch coordinates; each is a layer the canvas blends into yarns. */
|
|
328
364
|
export class KnitLayers {
|
|
329
|
-
constructor(private k: Kit, private grid: string) {}
|
|
330
|
-
|
|
365
|
+
constructor(private k: Kit, private grid: string, readonly width = 0, readonly height = 0) {}
|
|
366
|
+
add(x0: number, y0: number, w: number, h: number, paths: VectorPath[], fill: Paint[], name: string) {
|
|
331
367
|
return this.k.vector(this.grid, w * CELL, h * CELL, paths, fill, { name, absolute: { x: x0 * CELL, y: y0 * CELL } })
|
|
332
368
|
}
|
|
333
369
|
/** A closed shape through `pts` (stitches). */
|
|
@@ -353,6 +389,81 @@ export class KnitLayers {
|
|
|
353
389
|
bauble(cx: number, cy: number, r: number, light: string, body: string, shadow: string, name = 'Bauble') {
|
|
354
390
|
return this.ellipse(cx, cy, r, r, radial([[0, light], [0.35, body], [1, shadow]], 0.36, 0.32, 0.75), name)
|
|
355
391
|
}
|
|
392
|
+
/** A vector layer covering exactly the stitches set in `mask` (row runs), cropped to their box. */
|
|
393
|
+
mask(bits: Uint8Array, w: number, h: number, fill: Paint[], name: string) {
|
|
394
|
+
let x0 = w, y0 = h, x1 = -1, y1 = -1
|
|
395
|
+
for (let y = 0; y < h; y++) for (let x = 0; x < w; x++) if (bits[y * w + x]) { x0 = Math.min(x0, x); y0 = Math.min(y0, y); x1 = Math.max(x1, x); y1 = Math.max(y1, y) }
|
|
396
|
+
if (x1 < 0) return null
|
|
397
|
+
const paths: VectorPath[] = []
|
|
398
|
+
for (let y = y0; y <= y1; y++) for (let x = x0; x <= x1; x++) {
|
|
399
|
+
if (!bits[y * w + x]) continue
|
|
400
|
+
let e = x
|
|
401
|
+
while (e + 1 <= x1 && bits[y * w + e + 1]) e++
|
|
402
|
+
const a = (x - x0) * CELL, b = (e + 1 - x0) * CELL, t = (y - y0) * CELL, u = (y + 1 - y0) * CELL
|
|
403
|
+
paths.push({ points: [{ x: a, y: t }, { x: b, y: t }, { x: b, y: u }, { x: a, y: u }], closed: true })
|
|
404
|
+
x = e
|
|
405
|
+
}
|
|
406
|
+
return this.add(x0, y0, x1 - x0 + 1, y1 - y0 + 1, paths, fill, name)
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* Pop-art sunburst: `rays` wedges round (cx, cy) out to `r`, every other one filled, each with `fill` (a radial
|
|
410
|
+
* gradient fading outward reads as light). Hard-edged wedges, so the screen inside them looks designed.
|
|
411
|
+
*/
|
|
412
|
+
sunburst(cx: number, cy: number, r: number, rays: number, light: readonly Stop[], name = 'Sunburst', turn = 0) {
|
|
413
|
+
const ids: string[] = []
|
|
414
|
+
for (let i = 0; i < rays; i += 2) {
|
|
415
|
+
const a0 = turn + (i / rays) * Math.PI * 2, a1 = turn + ((i + 1) / rays) * Math.PI * 2
|
|
416
|
+
const pts: [number, number][] = [[cx, cy]]
|
|
417
|
+
for (let s = 0; s <= 6; s++) { const a = a0 + ((a1 - a0) * s) / 6; pts.push([cx + Math.cos(a) * r, cy + Math.sin(a) * r]) }
|
|
418
|
+
// The light is centred on the burst, not on each ray's own box.
|
|
419
|
+
const xs = pts.map(p => p[0]), ys = pts.map(p => p[1]), x0 = Math.min(...xs), y0 = Math.min(...ys), bw = Math.max(...xs) - x0 || 1, bh = Math.max(...ys) - y0 || 1
|
|
420
|
+
const fill = [{ type: 'GRADIENT_RADIAL', gradientStops: stops(light), gradientHandlePositions: [{ x: (cx - x0) / bw, y: (cy - y0) / bh }, { x: (cx - x0 + r) / bw, y: (cy - y0) / bh }, { x: (cx - x0) / bw, y: (cy - y0 + r) / bh }], opacity: 1, visible: true } as Paint]
|
|
421
|
+
ids.push(this.poly(pts, fill, `${name} ray ${i / 2 + 1}`))
|
|
422
|
+
}
|
|
423
|
+
return ids
|
|
424
|
+
}
|
|
425
|
+
/** A ribbon of light across the panel: a band `thick` stitches deep riding a sine wave. */
|
|
426
|
+
wave(yc: number, amp: number, period: number, thick: number, phase: number, fill: Paint[], name = 'Aurora') {
|
|
427
|
+
const top: [number, number][] = [], bot: [number, number][] = []
|
|
428
|
+
for (let x = -4; x <= this.width + 4; x += 4) {
|
|
429
|
+
const y = yc + amp * Math.sin((x / period) * Math.PI * 2 + phase), t = thick
|
|
430
|
+
top.push([x, y - t / 2]); bot.push([x, y + t / 2])
|
|
431
|
+
}
|
|
432
|
+
return this.poly([...top, ...bot.reverse()], fill, name)
|
|
433
|
+
}
|
|
434
|
+
/** Diagonal candy stripes between rows y0 and y1: bands `w` wide every `period`, slanting by the band's height. */
|
|
435
|
+
stripes(y0: number, y1: number, period: number, w: number, fill: Paint[], name = 'Candy stripes') {
|
|
436
|
+
return this.mask(this.bits((x, y) => y >= y0 && y < y1 && (((x + (y - y0)) % period) + period) % period < w), this.width, this.height, fill, name)
|
|
437
|
+
}
|
|
438
|
+
/** A panel-sized stitch mask from a test on each stitch. */
|
|
439
|
+
private bits(inside: (x: number, y: number) => boolean) {
|
|
440
|
+
const b = new Uint8Array(this.width * this.height)
|
|
441
|
+
for (let y = 0; y < this.height; y++) for (let x = 0; x < this.width; x++) if (inside(x, y)) b[y * this.width + x] = 1
|
|
442
|
+
return b
|
|
443
|
+
}
|
|
444
|
+
/** A ring of stitches `w` thick at radius `r` round (cx, cy): a medallion frame. */
|
|
445
|
+
ring(cx: number, cy: number, r: number, w: number, fill: Paint[], name = 'Ring') {
|
|
446
|
+
return this.mask(this.bits((x, y) => { const d = Math.hypot(x - cx, y - cy); return d >= r && d < r + w }), this.width, this.height, fill, name)
|
|
447
|
+
}
|
|
448
|
+
/** A dotted ring: single dots `gap` stitches apart round a circle, each a 2×2 stitch block (never a lone stitch). */
|
|
449
|
+
dots(cx: number, cy: number, r: number, gap: number, fill: Paint[], name = 'Dotted ring') {
|
|
450
|
+
const n = Math.round((2 * Math.PI * r) / gap), pts = Array.from({ length: n }, (_, i) => [Math.round(cx + Math.cos((i / n) * 2 * Math.PI) * r), Math.round(cy + Math.sin((i / n) * 2 * Math.PI) * r)])
|
|
451
|
+
return this.mask(this.bits((x, y) => pts.some(([px, py]) => x >= px && x <= px + 1 && y >= py && y <= py + 1)), this.width, this.height, fill, name)
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* The wordmark, solid, with what makes knit lettering read from across a room: an outline `ring` stitches thick
|
|
455
|
+
* and/or a drop shadow offset (dx, dy), each a solid yarn — never a blend inside the letters.
|
|
456
|
+
*/
|
|
457
|
+
badge(cx: number, cy: number, width: number, letters: string, o: { outline?: string, ring?: number, shadow?: string, dx?: number, dy?: number } = {}) {
|
|
458
|
+
const L = logoStitches(width), x0 = Math.round(cx - width / 2), y0 = Math.round(cy - L.height / 2)
|
|
459
|
+
const at = (x: number, y: number) => L.at(x - x0, y - y0)
|
|
460
|
+
if (o.shadow) { const dx = o.dx ?? 3, dy = o.dy ?? 3; this.mask(this.bits((x, y) => at(x - dx, y - dy)), this.width, this.height, solid(o.shadow), 'Logo shadow') }
|
|
461
|
+
if (o.outline) {
|
|
462
|
+
const r = o.ring ?? 2
|
|
463
|
+
this.mask(this.bits((x, y) => { for (let dy = -r; dy <= r; dy++) for (let dx = -r; dx <= r; dx++) if (dx * dx + dy * dy <= r * r + r && at(x + dx, y + dy)) return true; return false }), this.width, this.height, solid(o.outline), 'Logo outline')
|
|
464
|
+
}
|
|
465
|
+
return this.mask(this.bits(at), this.width, this.height, solid(letters), 'PopCraft logo')
|
|
466
|
+
}
|
|
356
467
|
/** The PopCraft wordmark as one vector layer, `width` stitches wide, centred on (cx, cy), filled with `fill`. */
|
|
357
468
|
logo(cx: number, cy: number, width: number, fill: Paint[], name = 'PopCraft logo') {
|
|
358
469
|
const L = logoStitches(width), x0 = Math.round(cx - width / 2), y0 = Math.round(cy - L.height / 2)
|
|
@@ -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,
|
|
8
|
+
import { BEANIE, Stitches, YARN, clear, heart, knitPanel, knitPreset, lice, 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).
|
|
@@ -27,22 +27,22 @@ export default defineTemplate({
|
|
|
27
27
|
const k = new Kit(NAME, knitPreset(panel))
|
|
28
28
|
k.palette({ trim: YARN.pine })
|
|
29
29
|
const s = new Stitches(panel.width, panel.height)
|
|
30
|
+
s.motif('Snowflake row')
|
|
30
31
|
for (let x = 0; x < s.width; x += 82) snowflake(s, x + 41, 40, 24, BLEACH)
|
|
31
|
-
zigzag(s, 80, 20, 7, 3, CHILI)
|
|
32
|
+
zigzag(s.motif('Zigzag top'), 80, 20, 7, 3, CHILI)
|
|
32
33
|
// The PopCraft wordmark at the centre of the star band, a star either side of it.
|
|
33
34
|
const half = logoStitches(150).width / 2
|
|
35
|
+
s.motif('Nordic stars')
|
|
34
36
|
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
|
-
zigzag(s, 160, 20, 7, 3, CHILI)
|
|
37
|
+
zigzag(s.motif('Zigzag bottom'), 160, 20, 7, 3, CHILI)
|
|
38
|
+
s.motif('Hearts')
|
|
36
39
|
for (let x = 0; x < s.width; x += 41) heart(s, x + 20, 198, 11, BLEACH)
|
|
37
|
-
lice(s, 6, 70, 26, BLEACH, clear(s, 6))
|
|
40
|
+
lice(s.motif('Sprinkles'), 6, 70, 26, BLEACH, clear(s, 6))
|
|
38
41
|
knitPanel(k, k.sheet, panel, YARNS, s, PINE, { layers: L => {
|
|
39
42
|
// A glow behind the wordmark and the wordmark itself as layers, dithered: bleach letters warming toward red at
|
|
40
43
|
// their feet, in a soft bleach halo.
|
|
41
|
-
|
|
42
|
-
L.
|
|
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')
|
|
44
|
+
// The wordmark as a knitted badge: solid bleach letters, a red outline two stitches thick.
|
|
45
|
+
L.badge(205, 121, 150, YARN.bleach, { outline: YARN.chili, ring: 2 })
|
|
46
46
|
} })
|
|
47
47
|
return k.doc
|
|
48
48
|
},
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Kit } from '../kit.js';
|
|
2
|
-
import type { Paint } from '../../../lib/document/types.js';
|
|
2
|
+
import type { Paint, VectorPath } from '../../../lib/document/types.js';
|
|
3
3
|
import type { PagePreset } from '../../../lib/presets/page-presets.js';
|
|
4
4
|
/** Printful's yarns used here (the 36 are in Popprint's catalog). */
|
|
5
5
|
export declare const YARN: {
|
|
@@ -30,7 +30,20 @@ export declare class Stitches {
|
|
|
30
30
|
readonly width: number;
|
|
31
31
|
readonly height: number;
|
|
32
32
|
readonly cells: Uint8Array;
|
|
33
|
+
/** Which motif layer drew each stitch last (-1: painted, not a layer). */
|
|
34
|
+
readonly owner: Int32Array;
|
|
35
|
+
/** The motif layers, in the order first drawn: a name and a palette slot each. */
|
|
36
|
+
readonly motifs: {
|
|
37
|
+
name: string;
|
|
38
|
+
c: number;
|
|
39
|
+
}[];
|
|
40
|
+
private current;
|
|
33
41
|
constructor(width: number, height: number);
|
|
42
|
+
/**
|
|
43
|
+
* What is drawn from here on is the motif `name`: knitPanel makes it a vector layer inside the stitch canvas (one
|
|
44
|
+
* per yarn it uses), so it can be moved, recoloured or deleted like any shape. `null` paints stitches directly.
|
|
45
|
+
*/
|
|
46
|
+
motif(name: string | null): this;
|
|
34
47
|
set(x: number, y: number, c: number): void;
|
|
35
48
|
get(x: number, y: number): number;
|
|
36
49
|
/** Every stitch in the box for which `inside(x, y)` holds, tested at the stitch's centre. */
|
|
@@ -99,6 +112,7 @@ export declare const clear: (s: Stitches, pad: number) => (x: number, y: number)
|
|
|
99
112
|
export declare function knitPanel(k: Kit, sheet: string, panel: KnitPanel, yarns: readonly string[], s: Stitches, trimSlot: number, o?: {
|
|
100
113
|
blend?: 'DITHER' | 'HALFTONE';
|
|
101
114
|
dot?: number;
|
|
115
|
+
under?: (L: KnitLayers) => void;
|
|
102
116
|
layers?: (L: KnitLayers) => void;
|
|
103
117
|
}): void;
|
|
104
118
|
/** A gradient stop: position 0–1, a yarn hex (or any colour between yarns), and an alpha. */
|
|
@@ -109,12 +123,16 @@ export declare function linear(angle: number, s: readonly Stop[]): Paint[];
|
|
|
109
123
|
export declare function radial(s: readonly Stop[], cx?: number, cy?: number, r?: number): Paint[];
|
|
110
124
|
/** The colour halfway (or `t` of the way) between two yarns: what the canvas knits as a mix of them. */
|
|
111
125
|
export declare function between(a: string, b: string, t?: number): string;
|
|
126
|
+
/** A flat fill in one yarn. */
|
|
127
|
+
export declare const solid: (h: string) => Paint[];
|
|
112
128
|
/** Shapes added to a stitch canvas, in stitch coordinates; each is a layer the canvas blends into yarns. */
|
|
113
129
|
export declare class KnitLayers {
|
|
114
130
|
private k;
|
|
115
131
|
private grid;
|
|
116
|
-
|
|
117
|
-
|
|
132
|
+
readonly width: number;
|
|
133
|
+
readonly height: number;
|
|
134
|
+
constructor(k: Kit, grid: string, width?: number, height?: number);
|
|
135
|
+
add(x0: number, y0: number, w: number, h: number, paths: VectorPath[], fill: Paint[], name: string): string;
|
|
118
136
|
/** A closed shape through `pts` (stitches). */
|
|
119
137
|
poly(pts: readonly (readonly [number, number])[], fill: Paint[], name: string): string;
|
|
120
138
|
/** An ellipse round (cx, cy), `rx` by `ry` stitches. */
|
|
@@ -124,6 +142,34 @@ export declare class KnitLayers {
|
|
|
124
142
|
halo(cx: number, cy: number, rx: number, ry: number, h: string, peak: number, at?: number, name?: string): string;
|
|
125
143
|
/** A shaded ball: lit from the upper left, `light` → `body` → `shadow`. */
|
|
126
144
|
bauble(cx: number, cy: number, r: number, light: string, body: string, shadow: string, name?: string): string;
|
|
145
|
+
/** A vector layer covering exactly the stitches set in `mask` (row runs), cropped to their box. */
|
|
146
|
+
mask(bits: Uint8Array, w: number, h: number, fill: Paint[], name: string): string | null;
|
|
147
|
+
/**
|
|
148
|
+
* Pop-art sunburst: `rays` wedges round (cx, cy) out to `r`, every other one filled, each with `fill` (a radial
|
|
149
|
+
* gradient fading outward reads as light). Hard-edged wedges, so the screen inside them looks designed.
|
|
150
|
+
*/
|
|
151
|
+
sunburst(cx: number, cy: number, r: number, rays: number, light: readonly Stop[], name?: string, turn?: number): string[];
|
|
152
|
+
/** A ribbon of light across the panel: a band `thick` stitches deep riding a sine wave. */
|
|
153
|
+
wave(yc: number, amp: number, period: number, thick: number, phase: number, fill: Paint[], name?: string): string;
|
|
154
|
+
/** Diagonal candy stripes between rows y0 and y1: bands `w` wide every `period`, slanting by the band's height. */
|
|
155
|
+
stripes(y0: number, y1: number, period: number, w: number, fill: Paint[], name?: string): string | null;
|
|
156
|
+
/** A panel-sized stitch mask from a test on each stitch. */
|
|
157
|
+
private bits;
|
|
158
|
+
/** A ring of stitches `w` thick at radius `r` round (cx, cy): a medallion frame. */
|
|
159
|
+
ring(cx: number, cy: number, r: number, w: number, fill: Paint[], name?: string): string | null;
|
|
160
|
+
/** A dotted ring: single dots `gap` stitches apart round a circle, each a 2×2 stitch block (never a lone stitch). */
|
|
161
|
+
dots(cx: number, cy: number, r: number, gap: number, fill: Paint[], name?: string): string | null;
|
|
162
|
+
/**
|
|
163
|
+
* The wordmark, solid, with what makes knit lettering read from across a room: an outline `ring` stitches thick
|
|
164
|
+
* and/or a drop shadow offset (dx, dy), each a solid yarn — never a blend inside the letters.
|
|
165
|
+
*/
|
|
166
|
+
badge(cx: number, cy: number, width: number, letters: string, o?: {
|
|
167
|
+
outline?: string;
|
|
168
|
+
ring?: number;
|
|
169
|
+
shadow?: string;
|
|
170
|
+
dx?: number;
|
|
171
|
+
dy?: number;
|
|
172
|
+
}): string | null;
|
|
127
173
|
/** The PopCraft wordmark as one vector layer, `width` stitches wide, centred on (cx, cy), filled with `fill`. */
|
|
128
174
|
logo(cx: number, cy: number, width: number, fill: Paint[], name?: string): {
|
|
129
175
|
id: string;
|