|
1 | | -import { cls } from '@layerstack/tailwind'; |
2 | | -import { memoize } from 'lodash-es'; |
3 | 1 | import type { ClassValue } from 'svelte/elements'; |
| 2 | +import memoize from 'memoize'; |
| 3 | +import { cls } from '@layerstack/tailwind'; |
4 | 4 | import type { PatternShape } from '$lib/components/Pattern.svelte'; |
5 | 5 |
|
6 | 6 | export const DEFAULT_FILL = 'rgb(0, 0, 0)'; |
@@ -332,20 +332,9 @@ export function _createLinearGradient( |
332 | 332 | } |
333 | 333 |
|
334 | 334 | /** Create linear gradient and memoize result to fix reactivity */ |
335 | | -export const createLinearGradient = memoize( |
336 | | - _createLinearGradient, |
337 | | - ( |
338 | | - ctx: CanvasRenderingContext2D, |
339 | | - x0: number, |
340 | | - y0: number, |
341 | | - x1: number, |
342 | | - y1: number, |
343 | | - stops: { offset: number; color: string }[] |
344 | | - ) => { |
345 | | - const key = JSON.stringify({ x0, y0, x1, y1, stops }); |
346 | | - return key; |
347 | | - } |
348 | | -); |
| 335 | +export const createLinearGradient = memoize(_createLinearGradient, { |
| 336 | + cacheKey: (args) => JSON.stringify(args.slice(1)), // Ignore `ctx` argument |
| 337 | +}); |
349 | 338 |
|
350 | 339 | export function _createPattern( |
351 | 340 | ctx: CanvasRenderingContext2D, |
@@ -395,16 +384,6 @@ export function _createPattern( |
395 | 384 | } |
396 | 385 |
|
397 | 386 | /** Create pattern and memoize result to fix reactivity */ |
398 | | -export const createPattern = memoize( |
399 | | - _createPattern, |
400 | | - ( |
401 | | - ctx: CanvasRenderingContext2D, |
402 | | - width: number, |
403 | | - height: number, |
404 | | - shapes: PatternShape[], |
405 | | - background?: string |
406 | | - ) => { |
407 | | - const key = JSON.stringify({ width, height, shapes, background }); |
408 | | - return key; |
409 | | - } |
410 | | -); |
| 387 | +export const createPattern = memoize(_createPattern, { |
| 388 | + cacheKey: (args) => JSON.stringify(args.slice(1)), // Ignore `ctx` argument |
| 389 | +}); |
0 commit comments