LCOV - code coverage report
Current view: top level - packages/layer-editor-ui/src - LayerPropertiesPanel.vue Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 44.9 % 49 22
Test Date: 2026-11-17 04:17:53

            Line data    Source code
       1            2 : <template>
       2            9 :   <div
       3              :     class="flex w-56 min-w-56 flex-col overflow-y-auto border-l bg-background"
       4              :     data-testid="layer-properties-panel"
       5              :   >
       6              :     <div class="flex items-center gap-2 border-b px-3 py-2">
       7              :       <i
       8              :         :class="
       9              :           isLayerContext ? 'icon-[lucide--image]' : 'icon-[lucide--grid-2x2]'
      10              :         "
      11              :       />
      12              :       <span class="truncate text-xs font-semibold text-foreground">
      13              :         {{ isLayerContext ? activeNode?.name : t('layerEditor.background') }}
      14              :       </span>
      15              :     </div>
      16              : 
      17              :     <template v-if="isLayerContext && activeNode">
      18              :       <div :class="sectionClass">
      19              :         <span :class="sectionLabelClass">{{ t('layerEditor.position') }}</span>
      20              :         <div class="flex gap-2">
      21              :           <PropertyNumberField
      22              :             label="X"
      23              :             :value="round(activeNode.transform.x)"
      24              :             @commit="onPosition($event, undefined)"
      25              :           />
      26              :           <PropertyNumberField
      27              :             label="Y"
      28              :             :value="round(activeNode.transform.y)"
      29              :             @commit="onPosition(undefined, $event)"
      30              :           />
      31              :         </div>
      32              :       </div>
      33              : 
      34              :       <div :class="sectionClass">
      35              :         <span :class="sectionLabelClass">
      36              :           {{ t('layerEditor.dimensions') }}
      37              :         </span>
      38              :         <div class="flex gap-2">
      39              :           <PropertyNumberField
      40              :             label="W"
      41              :             :value="round(activeNode.transform.w)"
      42              :             :min="1"
      43              :             @commit="onDimensions($event, undefined)"
      44              :           />
      45              :           <PropertyNumberField
      46              :             label="H"
      47              :             :value="round(activeNode.transform.h)"
      48              :             :min="1"
      49              :             @commit="onDimensions(undefined, $event)"
      50              :           />
      51              :         </div>
      52              :       </div>
      53              : 
      54              :       <div :class="sectionClass">
      55              :         <span :class="sectionLabelClass">{{ t('layerEditor.alignment') }}</span>
      56              :         <div class="flex gap-1">
      57           42 :           <Button
      58              :             v-for="item in alignItems"
      59              :             :key="item.op"
      60              :             variant="textonly"
      61              :             size="icon"
      62              :             class="size-7 rounded-md"
      63              :             :title="item.label"
      64              :             :aria-label="item.label"
      65              :             @click="onAlign(item.op)"
      66              :           >
      67              :             <i :class="item.icon" />
      68              :           </Button>
      69              :         </div>
      70              :       </div>
      71              : 
      72              :       <div :class="sectionClass">
      73              :         <div class="flex gap-2">
      74              :           <div class="flex min-w-0 flex-1 flex-col gap-2">
      75              :             <span :class="sectionLabelClass">
      76              :               {{ t('layerEditor.rotation') }}
      77              :             </span>
      78              :             <PropertyNumberField
      79              :               label="°"
      80              :               :value="rotationDeg"
      81              :               @commit="onRotation"
      82              :             />
      83              :           </div>
      84              :           <div class="flex flex-col gap-2">
      85              :             <span :class="sectionLabelClass">{{ t('layerEditor.flip') }}</span>
      86              :             <div class="flex gap-1">
      87              :               <Button
      88              :                 variant="textonly"
      89              :                 size="icon"
      90              :                 class="size-7 rounded-md"
      91              :                 :title="t('layerEditor.flipHorizontal')"
      92              :                 :aria-label="t('layerEditor.flipHorizontal')"
      93              :                 @click="onFlip('h')"
      94              :               >
      95              :                 <i class="icon-[lucide--flip-horizontal-2]" />
      96              :               </Button>
      97              :               <Button
      98              :                 variant="textonly"
      99              :                 size="icon"
     100              :                 class="size-7 rounded-md"
     101              :                 :title="t('layerEditor.flipVertical')"
     102              :                 :aria-label="t('layerEditor.flipVertical')"
     103              :                 @click="onFlip('v')"
     104              :               >
     105              :                 <i class="icon-[lucide--flip-vertical-2]" />
     106              :               </Button>
     107              :             </div>
     108              :           </div>
     109              :         </div>
     110              :       </div>
     111              : 
     112              :       <div :class="sectionClass">
     113              :         <div class="flex gap-2">
     114              :           <div class="flex min-w-0 flex-1 flex-col gap-2">
     115              :             <span :class="sectionLabelClass">
     116              :               {{ t('layerEditor.opacity') }}
     117              :             </span>
     118              :             <PropertyNumberField
     119              :               label="%"
     120              :               :value="opacityPercent"
     121              :               :min="0"
     122              :               :max="100"
     123              :               @commit="onOpacity"
     124              :             />
     125              :           </div>
     126              :           <div class="flex min-w-0 flex-1 flex-col gap-2">
     127              :             <span :class="sectionLabelClass">
     128              :               {{ t('layerEditor.blendMode') }}
     129              :             </span>
     130              :             <Select
     131              :               :model-value="activeNode.mode.blend"
     132              :               @update:model-value="onBlendChange"
     133              :             >
     134              :               <SelectTrigger
     135              :                 size="md"
     136              :                 class="h-7 min-w-0 px-2"
     137              :                 :aria-label="t('layerEditor.blendMode')"
     138              :               >
     139              :                 <SelectValue />
     140              :               </SelectTrigger>
     141              :               <SelectContent>
     142           52 :                 <SelectItem
     143              :                   v-for="option in blendOptions"
     144              :                   :key="option.value"
     145              :                   :value="option.value"
     146              :                   class="py-1.5 text-xs"
     147              :                 >
     148              :                   {{ option.label }}
     149              :                 </SelectItem>
     150              :               </SelectContent>
     151              :             </Select>
     152              :           </div>
     153              :         </div>
     154              :       </div>
     155              :     </template>
     156              : 
     157              :     <template v-else>
     158              :       <div :class="sectionClass">
     159              :         <span :class="sectionLabelClass">
     160              :           {{ t('layerEditor.dimensions') }}
     161              :         </span>
     162              :         <div class="flex gap-2">
     163              :           <PropertyNumberField
     164              :             label="W"
     165              :             :value="canvasSize.w"
     166              :             :min="CANVAS_SIZE_MIN"
     167              :             :max="CANVAS_SIZE_MAX"
     168              :             @commit="session.setCanvasSize($event, canvasSize.h)"
     169              :           />
     170              :           <PropertyNumberField
     171              :             label="H"
     172              :             :value="canvasSize.h"
     173              :             :min="CANVAS_SIZE_MIN"
     174              :             :max="CANVAS_SIZE_MAX"
     175              :             @commit="session.setCanvasSize(canvasSize.w, $event)"
     176              :           />
     177              :         </div>
     178              :       </div>
     179              : 
     180              :       <div v-if="backgroundLayer" :class="sectionClass">
     181              :         <span :class="sectionLabelClass">{{ t('layerEditor.fill') }}</span>
     182              :         <div data-testid="background-color-swatch">
     183              :           <ColorPicker
     184              :             v-model="backgroundColorModel"
     185              :             class="h-7"
     186              :             :accessible-label="t('layerEditor.backgroundColor')"
     187              :             :hex-label="t('color.hex')"
     188              :             :rgba-label="t('color.rgba')"
     189              :             :hue-label="t('color.hue')"
     190              :             :alpha-label="t('color.alpha')"
     191              :             :red-label="t('color.red')"
     192              :             :green-label="t('color.green')"
     193              :             :blue-label="t('color.blue')"
     194              :             :saturation-brightness-label="t('color.saturationBrightness')"
     195              :             :format-label="t('g.color')"
     196              :           />
     197              :         </div>
     198              :       </div>
     199              :     </template>
     200              :   </div>
     201              : </template>
     202              : 
     203              : <script setup lang="ts">
     204              : import Button from '@comfyorg/design-system/button/Button'
     205              : import type { AcceptableValue } from 'reka-ui'
     206              : import { computed } from 'vue'
     207              : import { useI18n } from 'vue-i18n'
     208              : 
     209              : import PropertyNumberField from '@comfyorg/design-system/number-field/PropertyNumberField'
     210              : import ColorPicker from '@comfyorg/design-system/color-picker/ColorPicker'
     211              : import Select from '@comfyorg/design-system/select/Select'
     212              : import SelectContent from '@comfyorg/design-system/select/SelectContent'
     213              : import SelectItem from '@comfyorg/design-system/select/SelectItem'
     214              : import SelectTrigger from '@comfyorg/design-system/select/SelectTrigger'
     215              : import SelectValue from '@comfyorg/design-system/select/SelectValue'
     216              : import type {
     217              :   LayerEditorAlignOp,
     218              :   LayerEditorSession
     219              : } from '@comfyorg/layer-editor/vue'
     220              : import {
     221              :   CANVAS_SIZE_MAX,
     222              :   CANVAS_SIZE_MIN,
     223              :   DEFAULT_BACKGROUND_COLOR
     224              : } from '@comfyorg/layer-editor/vue'
     225              : import type { BlendFn } from '@comfyorg/layer-editor/mode'
     226              : import { LAYER_MODES } from '@comfyorg/layer-editor/mode'
     227              : 
     228              : const { session } = defineProps<{ session: LayerEditorSession }>()
     229              : 
     230            2 : const { t } = useI18n()
     231            2 : const {
     232              :   activeNode,
     233              :   activeNodeId,
     234              :   selectedContext,
     235              :   canvasSize,
     236              :   backgroundLayer
     237              : } = session
     238              : 
     239            2 : const isLayerContext = computed(
     240              :   () => selectedContext.value === 'layer' && activeNode.value !== null
     241              : )
     242              : 
     243            2 : const sectionClass = 'flex flex-col gap-2 border-b border-border p-3'
     244            2 : const sectionLabelClass = 'text-xs text-muted-foreground'
     245              : 
     246            2 : const BLEND_KEYS: Record<BlendFn, string> = {
     247              :   normal: 'normal',
     248              :   multiply: 'multiply',
     249              :   screen: 'screen',
     250              :   overlay: 'overlay',
     251              :   darken: 'darken',
     252              :   lighten: 'lighten',
     253              :   'color-dodge': 'colorDodge',
     254              :   'color-burn': 'colorBurn',
     255              :   'hard-light': 'hardLight',
     256              :   'soft-light': 'softLight',
     257              :   difference: 'difference',
     258              :   exclusion: 'exclusion',
     259              :   'linear-dodge': 'linearDodge',
     260              :   'linear-burn': 'linearBurn',
     261              :   'vivid-light': 'vividLight',
     262              :   'pin-light': 'pinLight',
     263              :   'linear-light': 'linearLight',
     264              :   'hard-mix': 'hardMix',
     265              :   subtract: 'subtract',
     266              :   divide: 'divide',
     267              :   'grain-extract': 'grainExtract',
     268              :   'grain-merge': 'grainMerge',
     269              :   hue: 'hue',
     270              :   saturation: 'saturation',
     271              :   color: 'color',
     272              :   luminosity: 'luminosity'
     273              : }
     274              : 
     275            2 : const blendOptions = computed(() =>
     276              :   (Object.keys(LAYER_MODES) as BlendFn[]).map((mode) => ({
     277              :     label: t(`layerEditor.blend.${BLEND_KEYS[mode]}`),
     278              :     value: mode
     279              :   }))
     280              : )
     281              : 
     282            2 : const alignItems = computed<
     283              :   { op: LayerEditorAlignOp; icon: string; label: string }[]
     284              : >(() => [
     285              :   {
     286              :     op: 'left',
     287              :     icon: 'icon-[lucide--align-start-vertical]',
     288              :     label: t('layerEditor.alignLeft')
     289              :   },
     290              :   {
     291              :     op: 'centerH',
     292              :     icon: 'icon-[lucide--align-center-vertical]',
     293              :     label: t('layerEditor.alignCenterHorizontal')
     294              :   },
     295              :   {
     296              :     op: 'right',
     297              :     icon: 'icon-[lucide--align-end-vertical]',
     298              :     label: t('layerEditor.alignRight')
     299              :   },
     300              :   {
     301              :     op: 'top',
     302              :     icon: 'icon-[lucide--align-start-horizontal]',
     303              :     label: t('layerEditor.alignTop')
     304              :   },
     305              :   {
     306              :     op: 'centerV',
     307              :     icon: 'icon-[lucide--align-center-horizontal]',
     308              :     label: t('layerEditor.alignCenterVertical')
     309              :   },
     310              :   {
     311              :     op: 'bottom',
     312              :     icon: 'icon-[lucide--align-end-horizontal]',
     313              :     label: t('layerEditor.alignBottom')
     314              :   }
     315              : ])
     316              : 
     317            2 : const rotationDeg = computed(() =>
     318              :   Math.round(((activeNode.value?.transform.rotation ?? 0) * 180) / Math.PI)
     319              : )
     320              : 
     321            2 : const opacityPercent = computed(() =>
     322              :   Math.round((activeNode.value?.opacity ?? 1) * 100)
     323              : )
     324              : 
     325           28 : function round(v: number): number {
     326           28 :   return Math.round(v)
     327              : }
     328              : 
     329            0 : function onPosition(x?: number, y?: number): void {
     330            0 :   const id = activeNodeId.value
     331            0 :   if (id) session.setLayerPosition(id, x, y)
     332              : }
     333              : 
     334            0 : function onDimensions(w?: number, h?: number): void {
     335            0 :   const id = activeNodeId.value
     336            0 :   if (id) session.setLayerDimensions(id, w, h)
     337              : }
     338              : 
     339            0 : function onRotation(deg: number): void {
     340            0 :   const id = activeNodeId.value
     341            0 :   if (id) session.setLayerRotationDeg(id, deg)
     342              : }
     343              : 
     344            0 : function onAlign(op: LayerEditorAlignOp): void {
     345            0 :   const id = activeNodeId.value
     346            0 :   if (id) session.alignLayer(id, op)
     347              : }
     348              : 
     349            0 : function onFlip(axis: 'h' | 'v'): void {
     350            0 :   const id = activeNodeId.value
     351            0 :   if (id) session.flipLayer(id, axis)
     352              : }
     353              : 
     354            0 : function onOpacity(percent: number): void {
     355            0 :   const id = activeNodeId.value
     356            0 :   if (id) session.setOpacity(id, percent / 100)
     357              : }
     358              : 
     359            0 : function isBlendFn(value: unknown): value is BlendFn {
     360            0 :   return typeof value === 'string' && Object.hasOwn(LAYER_MODES, value)
     361              : }
     362              : 
     363            0 : function onBlendChange(value: AcceptableValue): void {
     364            0 :   const id = activeNodeId.value
     365            0 :   if (id && isBlendFn(value)) session.setBlendMode(id, value)
     366              : }
     367              : 
     368            2 : const backgroundColor = computed(() => {
     369            2 :   const fill = backgroundLayer.value?.fill
     370            2 :   return fill?.type === 'solid' ? fill.color : DEFAULT_BACKGROUND_COLOR
     371              : })
     372              : 
     373            2 : const backgroundColorModel = computed({
     374              :   get: () => {
     375            2 :     const percent = Math.round((backgroundLayer.value?.opacity ?? 1) * 100)
     376            2 :     if (percent >= 100) return backgroundColor.value
     377            0 :     const alphaHex = Math.round((percent / 100) * 255)
     378              :       .toString(16)
     379              :       .padStart(2, '0')
     380            0 :     return `${backgroundColor.value}${alphaHex}`
     381              :   },
     382              :   set: (hex: string) => {
     383            0 :     session.setBackgroundColor(hex.slice(0, 7))
     384            0 :     session.setBackgroundOpacity(
     385              :       hex.length === 9 ? parseInt(hex.slice(7, 9), 16) / 255 : 1
     386              :     )
     387              :   }
     388              : })
     389              : </script>
        

Generated by: LCOV version 2.0-1