Skip to content

Commit

Permalink
chore(components): lint
Browse files Browse the repository at this point in the history
  • Loading branch information
wingkwong committed Feb 13, 2024
1 parent ae26108 commit 93d770d
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/components/Watermark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ export const Watermark = defineComponent({
// Get the default slot content
const slots = ctx.slots.default?.()
// Throw an error if no slot content is provided
if (!slots) throw new Error('@watermarkify: Slot is required to use <Watermark>')
if (!slots)
throw new Error('@watermarkify: Slot is required to use <Watermark>')
// Throw an error if more than one slot content is provided
if (slots.length !== 1) throw new Error(`@watermarkify: <Watermark> requires exactly one slot, but got ${slots.length}`)
if (slots.length !== 1)
throw new Error(`@watermarkify: <Watermark> requires exactly one slot, but got ${slots.length}`)

// Merge props.options with defaultOptions
const options = reactive({
Expand Down Expand Up @@ -59,7 +61,7 @@ export const Watermark = defineComponent({
canvasCtx.font = `${Number(fontSize)}px ${fontFamily}`
const contents = Array.isArray(content.value) ? content.value : [content.value]
// Measure the width of each content item
const widths = contents.map((item) => canvasCtx.measureText(item!).width)
const widths = contents.map(item => canvasCtx.measureText(item!).width)
// Calculate the default width and height based on the measured content
defaultWidth = Math.ceil(Math.max(...widths))
defaultHeight = Number(fontSize) * contents.length + (contents.length - 1) * FontGap
Expand Down Expand Up @@ -194,7 +196,8 @@ export const Watermark = defineComponent({
const canvasCtx = canvas.getContext('2d')
if (canvasCtx) {
// Create a new div element for the watermark if it doesn't exist yet
if (!watermarkRef.value) watermarkRef.value = document.createElement('div')
if (!watermarkRef.value)
watermarkRef.value = document.createElement('div')
// Get the watermark size and canvas dimensions
const [watermarkWidth, watermarkHeight] = getWatermarkSize(canvasCtx)
const canvasWidth = (gapX.value + watermarkWidth) * devicePixelRatio
Expand Down Expand Up @@ -225,7 +228,8 @@ export const Watermark = defineComponent({

if (image.value) {
// TODO: handle image watermark
} else {
}
else {
// Draw the text watermark
drawText(canvas, canvasCtx, drawWidth, drawHeight, watermarkWidth, drawingParams, alternateDrawingParams)
}
Expand Down

0 comments on commit 93d770d

Please sign in to comment.