Skip to content

Commit 5592934

Browse files
committed
feat: soft dot type
1 parent 99d7484 commit 5592934

2 files changed

Lines changed: 38 additions & 1 deletion

File tree

src/figures/dot.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,42 @@ const qrDotFigures: { [type in DotType]: (args: DrawArgs) => SVGElement } = {
146146
if (!b && !bl && !l)
147147
corners.bl = 'round'
148148

149+
return DotElements.blob(args, corners)
150+
},
151+
[DotType.soft]: ({ getNeighbor, ...args }) => {
152+
const tl = getNeighbor?.(-1, -1)
153+
const t = getNeighbor?.(0, -1)
154+
const tr = getNeighbor?.(1, -1)
155+
const r = getNeighbor?.(1, 0)
156+
const br = getNeighbor?.(1, 1)
157+
const b = getNeighbor?.(0, 1)
158+
const bl = getNeighbor?.(-1, 1)
159+
const l = getNeighbor?.(-1, 0)
160+
const corners: Record<'tl' | 'tr' | 'bl' | 'br', 'round' | 'out' | 'square'> = {
161+
tl: 'square',
162+
tr: 'square',
163+
bl: 'square',
164+
br: 'square'
165+
}
166+
167+
if (!l && tl && t)
168+
corners.tl = 'out'
169+
if (!t && tr && r)
170+
corners.tr = 'out'
171+
if (!r && br && b)
172+
corners.br = 'out'
173+
if (!b && bl && l)
174+
corners.bl = 'out'
175+
176+
if (!l && !t)
177+
corners.tl = 'round'
178+
if (!t && !r)
179+
corners.tr = 'round'
180+
if (!r && !b)
181+
corners.br = 'round'
182+
if (!b && !l)
183+
corners.bl = 'round'
184+
149185
return DotElements.blob(args, corners)
150186
}
151187
}

src/utils/options.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ export enum DotType {
2626
zebraVertical = 'zebra-vertical',
2727
blocksHorizontal = 'blocks-horizontal',
2828
blocksVertical = 'blocks-vertical',
29-
blobs = 'blobs'
29+
blobs = 'blobs',
30+
soft = 'soft'
3031
}
3132

3233
export enum CornerDotType {

0 commit comments

Comments
 (0)