diff --git a/src/components/Watermark.ts b/src/components/Watermark.ts index fe3af64..c9365d3 100644 --- a/src/components/Watermark.ts +++ b/src/components/Watermark.ts @@ -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 ') + if (!slots) + throw new Error('@watermarkify: Slot is required to use ') // Throw an error if more than one slot content is provided - if (slots.length !== 1) throw new Error(`@watermarkify: requires exactly one slot, but got ${slots.length}`) + if (slots.length !== 1) + throw new Error(`@watermarkify: requires exactly one slot, but got ${slots.length}`) // Merge props.options with defaultOptions const options = reactive({ @@ -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 @@ -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 @@ -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) }