The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
deprecate includeMargin, use margin instead
Steven Teyf8e6926b1dc2
diff --git a/apps/web/lib/qr/api.tsx b/apps/web/lib/qr/api.tsxindex ac88b82001..0d3312f182 100644--- a/apps/web/lib/qr/api.tsx+++ b/apps/web/lib/qr/api.tsx@@ -2,11 +2,10 @@ import qrcodegen from "./codegen";import {DEFAULT_BGCOLOR,DEFAULT_FGCOLOR,- DEFAULT_INCLUDEMARGIN,DEFAULT_LEVEL,+ DEFAULT_MARGIN,DEFAULT_SIZE,ERROR_LEVEL_MAP,- MARGIN_SIZE,} from "./constants";import { QRPropsSVG } from "./types";import { excavateModules, generatePath, getImageSettings } from "./utils";@@ -18,7 +17,7 @@ export async function getQRAsSVG(props: QRPropsSVG) {level = DEFAULT_LEVEL,bgColor = DEFAULT_BGCOLOR,fgColor = DEFAULT_FGCOLOR,- includeMargin = DEFAULT_INCLUDEMARGIN,+ margin = DEFAULT_MARGIN,imageSettings,...otherProps} = props;@@ -28,12 +27,11 @@ export async function getQRAsSVG(props: QRPropsSVG) {ERROR_LEVEL_MAP[level],).getModules();- const margin = includeMargin ? MARGIN_SIZE : 0;const numCells = cells.length + margin * 2;const calculatedImageSettings = getImageSettings(cells,size,- includeMargin,+ margin,imageSettings,);diff --git a/apps/web/lib/qr/constants.ts b/apps/web/lib/qr/constants.tsindex f7565cb908..4d0802658c 100644--- a/apps/web/lib/qr/constants.ts+++ b/apps/web/lib/qr/constants.ts@@ -11,9 +11,7 @@ export const DEFAULT_SIZE = 128;export const DEFAULT_LEVEL = "L";export const DEFAULT_BGCOLOR = "#FFFFFF";export const DEFAULT_FGCOLOR = "#000000";-export const DEFAULT_INCLUDEMARGIN = true;--export const MARGIN_SIZE = 2;+export const DEFAULT_MARGIN = 2;export const QR_LEVELS = ["L", "M", "Q", "H"] as const;diff --git a/apps/web/lib/qr/index.tsx b/apps/web/lib/qr/index.tsxindex b996a3d8e3..a23d58550b 100644--- a/apps/web/lib/qr/index.tsx+++ b/apps/web/lib/qr/index.tsx@@ -9,11 +9,10 @@ import qrcodegen from "./codegen";import {DEFAULT_BGCOLOR,DEFAULT_FGCOLOR,- DEFAULT_INCLUDEMARGIN,DEFAULT_LEVEL,+ DEFAULT_MARGIN,DEFAULT_SIZE,ERROR_LEVEL_MAP,- MARGIN_SIZE,} from "./constants";import { QRProps, QRPropsCanvas } from "./types";import {@@ -32,7 +31,7 @@ export function QRCodeCanvas(props: QRPropsCanvas) {level = DEFAULT_LEVEL,bgColor = DEFAULT_BGCOLOR,fgColor = DEFAULT_FGCOLOR,- includeMargin = DEFAULT_INCLUDEMARGIN,+ margin = DEFAULT_MARGIN,style,imageSettings,...otherProps@@ -63,12 +62,11 @@ export function QRCodeCanvas(props: QRPropsCanvas) {ERROR_LEVEL_MAP[level],).getModules();- const margin = includeMargin ? MARGIN_SIZE : 0;const numCells = cells.length + margin * 2;const calculatedImageSettings = getImageSettings(cells,size,- includeMargin,+ margin,imageSettings,);@@ -168,7 +166,7 @@ export async function getQRAsSVGDataUri(props: QRProps) {level = DEFAULT_LEVEL,bgColor = DEFAULT_BGCOLOR,fgColor = DEFAULT_FGCOLOR,- includeMargin = DEFAULT_INCLUDEMARGIN,+ margin = DEFAULT_MARGIN,imageSettings,} = props;@@ -177,12 +175,11 @@ export async function getQRAsSVGDataUri(props: QRProps) {ERROR_LEVEL_MAP[level],).getModules();- const margin = includeMargin ? MARGIN_SIZE : 0;const numCells = cells.length + margin * 2;const calculatedImageSettings = getImageSettings(cells,size,- includeMargin,+ margin,imageSettings,);@@ -266,7 +263,7 @@ export async function getQRAsCanvas(level = DEFAULT_LEVEL,bgColor = DEFAULT_BGCOLOR,fgColor = DEFAULT_FGCOLOR,- includeMargin = DEFAULT_INCLUDEMARGIN,+ margin = DEFAULT_MARGIN,imageSettings,} = props;@@ -277,12 +274,11 @@ export async function getQRAsCanvas(value,ERROR_LEVEL_MAP[level],).getModules();- const margin = includeMargin ? MARGIN_SIZE : 0;const numCells = cells.length + margin * 2;const calculatedImageSettings = getImageSettings(cells,size,- includeMargin,+ margin,imageSettings,);diff --git a/apps/web/lib/qr/types.ts b/apps/web/lib/qr/types.tsindex cbac647afe..0470554813 100644--- a/apps/web/lib/qr/types.ts+++ b/apps/web/lib/qr/types.ts@@ -19,8 +19,8 @@ export type QRProps = {level?: string;bgColor?: string;fgColor?: string;+ margin?: number;style?: CSSProperties;- includeMargin?: boolean;imageSettings?: ImageSettings;isOGContext?: boolean;};diff --git a/apps/web/lib/qr/utils.tsx b/apps/web/lib/qr/utils.tsxindex a48e203efd..d943c105b8 100644--- a/apps/web/lib/qr/utils.tsx+++ b/apps/web/lib/qr/utils.tsx@@ -3,11 +3,10 @@ import {DEFAULT_BGCOLOR,DEFAULT_FGCOLOR,DEFAULT_IMG_SCALE,- DEFAULT_INCLUDEMARGIN,DEFAULT_LEVEL,+ DEFAULT_MARGIN,DEFAULT_SIZE,ERROR_LEVEL_MAP,- MARGIN_SIZE,} from "./constants";import { Excavation, ImageSettings, Modules, QRPropsSVG } from "./types";@@ -77,7 +76,7 @@ export function generatePath(modules: Modules, margin = 0): string {export function getImageSettings(cells: Modules,size: number,- includeMargin: boolean,+ margin: number,imageSettings?: ImageSettings,): null | {x: number;@@ -89,7 +88,6 @@ export function getImageSettings(if (imageSettings == null) {return null;}- const margin = includeMargin ? MARGIN_SIZE : 0;const numCells = cells.length + margin * 2;const defaultSize = Math.floor(size * DEFAULT_IMG_SCALE);const scale = numCells / size;@@ -148,7 +146,7 @@ export function QRCodeSVG(props: QRPropsSVG) {level = DEFAULT_LEVEL,bgColor = DEFAULT_BGCOLOR,fgColor = DEFAULT_FGCOLOR,- includeMargin = DEFAULT_INCLUDEMARGIN,+ margin = DEFAULT_MARGIN,isOGContext = false,imageSettings,...otherProps@@ -166,12 +164,11 @@ export function QRCodeSVG(props: QRPropsSVG) {ERROR_LEVEL_MAP[effectiveLevel],).getModules();- const margin = includeMargin ? MARGIN_SIZE : 0;const numCells = cells.length + margin * 2;const calculatedImageSettings = getImageSettings(cells,size,- includeMargin,+ margin,imageSettings,);diff --git a/apps/web/lib/zod/schemas/qr.ts b/apps/web/lib/zod/schemas/qr.tsindex 7123d1584c..5701453922 100644--- a/apps/web/lib/zod/schemas/qr.ts+++ b/apps/web/lib/zod/schemas/qr.ts@@ -1,7 +1,7 @@import {DEFAULT_BGCOLOR,DEFAULT_FGCOLOR,- DEFAULT_INCLUDEMARGIN,+ DEFAULT_MARGIN,QR_LEVELS,} from "@/lib/qr/constants";import z from "@/lib/zod";@@ -50,10 +50,18 @@ export const getQRCodeQuerySchema = z.object({.describe("Whether to hide the logo in the QR code. Can only be used with a paid plan on Dub.co.",),- includeMargin: booleanQuerySchema+ margin: z.coerce+ .number().optional()- .default(`${DEFAULT_INCLUDEMARGIN}`)+ .default(DEFAULT_MARGIN).describe(- "Whether to include a margin around the QR code. Defaults to `true` if not provided.",+ "The size of the margin around the QR code. Defaults to `4` if not provided.",),+ includeMargin: booleanQuerySchema+ .optional()+ .default("true")+ .describe(+ "DEPRECATED: Margin is included by default. Use the `margin` prop to customize the margin size.",+ )+ .openapi({ deprecated: true }),});