LCOV - code coverage report
Current view: top level - packages/layer-editor/src/kinds - fill.ts Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 21.1 % 19 4
Test Date: 2026-11-17 04:17:53

            Line data    Source code
       1              : import type { NodeTexture } from '#/compositor'
       2              : import {
       3              :   defaultFillSpec,
       4              :   fillSpecStamp,
       5              :   normalizeFillSpec,
       6              :   renderFillBitmap
       7              : } from '#/fill'
       8              : import { generateId } from '#/id'
       9              : import { defaultMode } from '#/mode'
      10              : import type { FillData } from '#/node'
      11              : import type { CompactRect as Rect } from '@comfyorg/shared-frontend-utils/geometry'
      12              : import type { NodeKind, RenderNodeCtx } from '#/nodeKind'
      13              : 
      14            2 : const bitmapCache = new Map<
      15              :   string,
      16              :   { stamp: string; canvas: HTMLCanvasElement | null }
      17              : >()
      18              : 
      19            0 : export function fillBitmap(
      20              :   node: FillData,
      21              :   w: number,
      22              :   h: number
      23              : ): HTMLCanvasElement | null {
      24            0 :   const stamp = `${fillSpecStamp(node.fill)}|${w}x${h}`
      25            0 :   const hit = bitmapCache.get(node.id)
      26            0 :   if (hit && hit.stamp === stamp) return hit.canvas
      27            0 :   if (bitmapCache.size > 64) {
      28            0 :     const first = bitmapCache.keys().next().value
      29            0 :     if (first !== undefined) bitmapCache.delete(first)
      30              :   }
      31            0 :   const canvas = renderFillBitmap(node.fill, w, h)
      32            0 :   bitmapCache.set(node.id, { stamp, canvas })
      33            0 :   return canvas
      34              : }
      35              : 
      36            2 : export const fillKind: NodeKind<FillData> = {
      37              :   kind: 'fill',
      38              : 
      39              :   create(init: Partial<FillData> = {}): FillData {
      40            2 :     return {
      41              :       kind: 'fill',
      42              :       id: init.id ?? generateId('fill'),
      43              :       name: init.name ?? 'Fill',
      44              :       visible: init.visible ?? true,
      45              :       opacity: init.opacity ?? 1,
      46              :       mode: init.mode ?? defaultMode('normal'),
      47              :       transform: { x: 0, y: 0, w: 0, h: 0, rotation: 0 },
      48              :       locks: init.locks ?? {
      49              :         content: false,
      50              :         position: false,
      51              :         visibility: false
      52              :       },
      53              :       fill: init.fill ? normalizeFillSpec(init.fill) : defaultFillSpec(),
      54              :       mask: init.mask
      55              :     }
      56              :   },
      57              : 
      58              :   contentIds(node: FillData): string[] {
      59           15 :     return node.mask ? [node.mask.contentId].filter(Boolean) : []
      60              :   },
      61              : 
      62              :   renderNode(node: FillData, ctx: RenderNodeCtx): NodeTexture | null {
      63            0 :     const bitmap = fillBitmap(node, ctx.region.w, ctx.region.h)
      64            0 :     if (!bitmap) return null
      65            0 :     return ctx.placed(`content:${node.id}`, fillSpecStamp(node.fill), bitmap, {
      66              :       x: 0,
      67              :       y: 0,
      68              :       w: ctx.region.w,
      69              :       h: ctx.region.h,
      70              :       rotation: 0
      71              :     })
      72              :   },
      73              : 
      74              :   bbox(): Rect {
      75            0 :     return { x: 0, y: 0, w: 0, h: 0 }
      76              :   },
      77              : 
      78              :   hitTest(): boolean {
      79            0 :     return false
      80              :   }
      81              : }
        

Generated by: LCOV version 2.0-1