diff --git a/src/rendering/cache/bitmap-cache.ts b/src/rendering/cache/bitmap-cache.ts index 9c96d51..906c3c6 100644 --- a/src/rendering/cache/bitmap-cache.ts +++ b/src/rendering/cache/bitmap-cache.ts @@ -20,13 +20,20 @@ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -import type { Layer } from "@/definitions/document"; +import type { Layer, Filters, Text } from "@/definitions/document"; -const layerCache: Map = new Map(); +export type RenderCache = { + text?: Text; + textBitmap?: HTMLCanvasElement; + filters?: Filters; + filterData?: ImageData; +}; -export const getLayerCache = ( layer: Layer ): any => layerCache.get( layer.id ); +const layerCache: Map = new Map(); -export const setLayerCache = ( layer: Layer, props: any ): void => { +export const getLayerCache = ( layer: Layer ): RenderCache => layerCache.get( layer.id ); + +export const setLayerCache = ( layer: Layer, props: RenderCache ): void => { const cache = getLayerCache( layer ) ?? {}; layerCache.set( layer.id, { ...cache, ...props }); }; @@ -35,7 +42,9 @@ export const hasLayerCache = ( layer: Layer ): boolean => layerCache.has( layer. export const clearCacheProperty = ( layer: Layer, propertyName: string ): void => { const cache = getLayerCache( layer ); + // @ts-expect-error using string as key if ( cache?.[ propertyName ] ) { + // @ts-expect-error using string as key delete cache[ propertyName ]; } }; diff --git a/src/services/render-service.ts b/src/services/render-service.ts index 53ef84c..0776d62 100644 --- a/src/services/render-service.ts +++ b/src/services/render-service.ts @@ -21,7 +21,7 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ import Vue from "vue"; -import type { Layer, Filters, Text } from "@/definitions/document"; +import type { Layer } from "@/definitions/document"; import { LayerTypes } from "@/definitions/layer-types"; import { getSpriteForLayer } from "@/factories/sprite-factory"; import { hasFilters, isEqual as isFiltersEqual } from "@/factories/filters-factory"; @@ -29,6 +29,7 @@ import { isEqual as isTextEqual } from "@/factories/text-factory"; import { createCanvas, cloneCanvas, matchDimensions } from "@/utils/canvas-util"; import { replaceLayerSource } from "@/utils/layer-util"; import { getLayerCache, setLayerCache } from "@/rendering/cache/bitmap-cache"; +import type { RenderCache } from "@/rendering/cache/bitmap-cache"; import { renderMultiLineText } from "@/rendering/text"; import { loadGoogleFont } from "@/services/font-service"; import FilterWorker from "@/workers/filter.worker?worker"; @@ -40,13 +41,6 @@ type RenderJob = { error: ( error?: any ) => void; }; -type RenderCache = { - text?: Text; - textBitmap?: HTMLCanvasElement; - filters?: Filters; - filterData?: ImageData; -}; - const jobQueue: RenderJob[] = []; let UID = 0; diff --git a/tests/unit/definitions/file-types.spec.js b/tests/unit/definitions/file-types.spec.ts similarity index 100% rename from tests/unit/definitions/file-types.spec.js rename to tests/unit/definitions/file-types.spec.ts diff --git a/tests/unit/definitions/image-types.spec.js b/tests/unit/definitions/image-types.spec.ts similarity index 100% rename from tests/unit/definitions/image-types.spec.js rename to tests/unit/definitions/image-types.spec.ts diff --git a/tests/unit/factories/brush-factory.spec.js b/tests/unit/factories/brush-factory.spec.ts similarity index 100% rename from tests/unit/factories/brush-factory.spec.js rename to tests/unit/factories/brush-factory.spec.ts diff --git a/tests/unit/factories/document-factory.spec.js b/tests/unit/factories/document-factory.spec.ts similarity index 100% rename from tests/unit/factories/document-factory.spec.js rename to tests/unit/factories/document-factory.spec.ts diff --git a/tests/unit/factories/effects-factory.spec.js b/tests/unit/factories/effects-factory.spec.ts similarity index 100% rename from tests/unit/factories/effects-factory.spec.js rename to tests/unit/factories/effects-factory.spec.ts diff --git a/tests/unit/factories/filters-factory.spec.js b/tests/unit/factories/filters-factory.spec.ts similarity index 100% rename from tests/unit/factories/filters-factory.spec.js rename to tests/unit/factories/filters-factory.spec.ts diff --git a/tests/unit/factories/history-state-factory.spec.js b/tests/unit/factories/history-state-factory.spec.ts similarity index 100% rename from tests/unit/factories/history-state-factory.spec.js rename to tests/unit/factories/history-state-factory.spec.ts diff --git a/tests/unit/factories/layer-factory.spec.js b/tests/unit/factories/layer-factory.spec.ts similarity index 100% rename from tests/unit/factories/layer-factory.spec.js rename to tests/unit/factories/layer-factory.spec.ts diff --git a/tests/unit/factories/sprite-factory.spec.js b/tests/unit/factories/sprite-factory.spec.ts similarity index 100% rename from tests/unit/factories/sprite-factory.spec.js rename to tests/unit/factories/sprite-factory.spec.ts diff --git a/tests/unit/factories/text-factory.spec.js b/tests/unit/factories/text-factory.spec.ts similarity index 100% rename from tests/unit/factories/text-factory.spec.js rename to tests/unit/factories/text-factory.spec.ts diff --git a/tests/unit/math/image-math.spec.js b/tests/unit/math/image-math.spec.ts similarity index 100% rename from tests/unit/math/image-math.spec.js rename to tests/unit/math/image-math.spec.ts diff --git a/tests/unit/math/point-math.spec.js b/tests/unit/math/point-math.spec.ts similarity index 100% rename from tests/unit/math/point-math.spec.js rename to tests/unit/math/point-math.spec.ts diff --git a/tests/unit/math/rectangle-math.spec.js b/tests/unit/math/rectangle-math.spec.ts similarity index 100% rename from tests/unit/math/rectangle-math.spec.js rename to tests/unit/math/rectangle-math.spec.ts diff --git a/tests/unit/math/selection-math.spec.js b/tests/unit/math/selection-math.spec.ts similarity index 100% rename from tests/unit/math/selection-math.spec.js rename to tests/unit/math/selection-math.spec.ts diff --git a/tests/unit/math/unit-math.spec.js b/tests/unit/math/unit-math.spec.ts similarity index 100% rename from tests/unit/math/unit-math.spec.js rename to tests/unit/math/unit-math.spec.ts diff --git a/tests/unit/rendering/cache/bitmap-cache.spec.js b/tests/unit/rendering/cache/bitmap-cache.spec.ts similarity index 100% rename from tests/unit/rendering/cache/bitmap-cache.spec.js rename to tests/unit/rendering/cache/bitmap-cache.spec.ts diff --git a/tests/unit/store/modules/canvas-module.spec.js b/tests/unit/store/modules/canvas-module.spec.ts similarity index 100% rename from tests/unit/store/modules/canvas-module.spec.js rename to tests/unit/store/modules/canvas-module.spec.ts diff --git a/tests/unit/store/modules/document-module.spec.js b/tests/unit/store/modules/document-module.spec.ts similarity index 100% rename from tests/unit/store/modules/document-module.spec.js rename to tests/unit/store/modules/document-module.spec.ts diff --git a/tests/unit/store/modules/history-module.spec.js b/tests/unit/store/modules/history-module.spec.ts similarity index 100% rename from tests/unit/store/modules/history-module.spec.js rename to tests/unit/store/modules/history-module.spec.ts diff --git a/tests/unit/store/modules/image-module.spec.js b/tests/unit/store/modules/image-module.spec.ts similarity index 100% rename from tests/unit/store/modules/image-module.spec.js rename to tests/unit/store/modules/image-module.spec.ts diff --git a/tests/unit/store/modules/preferences-module.spec.js b/tests/unit/store/modules/preferences-module.spec.ts similarity index 100% rename from tests/unit/store/modules/preferences-module.spec.js rename to tests/unit/store/modules/preferences-module.spec.ts diff --git a/tests/unit/store/modules/tool-module.spec.js b/tests/unit/store/modules/tool-module.spec.ts similarity index 100% rename from tests/unit/store/modules/tool-module.spec.js rename to tests/unit/store/modules/tool-module.spec.ts diff --git a/tests/unit/store/store.spec.js b/tests/unit/store/store.spec.ts similarity index 100% rename from tests/unit/store/store.spec.js rename to tests/unit/store/store.spec.ts diff --git a/tests/unit/utils/document-util.spec.js b/tests/unit/utils/document-util.spec.ts similarity index 100% rename from tests/unit/utils/document-util.spec.js rename to tests/unit/utils/document-util.spec.ts diff --git a/tsconfig.app.json b/tsconfig.app.json index 5fe0f43..63f1901 100644 --- a/tsconfig.app.json +++ b/tsconfig.app.json @@ -11,7 +11,7 @@ "noImplicitAny": true, "removeComments": true, "paths": { - "@/*": [ "./src/*" ] + "@/*": [ "./src/*", "./tests/*" ] } }, "exclude": [ diff --git a/tsconfig.check.json b/tsconfig.check.json index e129b63..c49b1d7 100644 --- a/tsconfig.check.json +++ b/tsconfig.check.json @@ -1,6 +1,6 @@ { "extends": "./tsconfig.app.json", - "includes": [ "src/**/*.ts" ], + "includes": [ "src/**/*.ts", "tests/**/*.ts" ], "compilerOptions": { "skipLibCheck": true }