function draw_with_swatch(ctx, x_min, y_min, x_max, y_max, swatch, callback) {
	const stroke_margin = ~~(stroke_size * 1.1);

	x_max = Math.max(x_max, x_min + 1);
	y_max = Math.max(y_max, y_min + 1);
	op_canvas_2d.width = x_max - x_min + stroke_margin * 2;
	op_canvas_2d.height = y_max - y_min + stroke_margin * 2;

	const x = x_min - stroke_margin;
	const y = y_min - stroke_margin;

	op_ctx_2d.save();
	op_ctx_2d.translate(-x, -y);
	callback(op_ctx_2d);
	op_ctx_2d.restore(); // for replace_colors_with_swatch!

	replace_colors_with_swatch(op_ctx_2d, swatch, x, y);
	ctx.drawImage(op_canvas_2d, x, y);

	// for debug:
	// ctx.fillStyle = "rgba(255, 0, 255, 0.1)";
	// ctx.fillRect(x, y, op_canvas_2d.width, op_canvas_2d.height);
}
@param {CanvasRenderingContext2D} ctx
@param {number} x_min
@param {number} y_min
@param {number} x_max
@param {number} y_max
@param {CanvasPattern | string} swatch
@param {(ctx: CanvasRenderingContext2D) => void} callback