From 5a4cebb230926b815f7bc8108d53778fea6a403a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20D=C4=9Bdi=C4=8D?= Date: Fri, 13 Sep 2024 19:06:10 +0300 Subject: [PATCH 1/2] Stricter tsconfig --- tsconfig.json | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tsconfig.json b/tsconfig.json index f08840a1..59438e1f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,14 +1,21 @@ { "compilerOptions": { - "module": "es6", - "moduleResolution": "node", "allowSyntheticDefaultImports": true, "forceConsistentCasingInFileNames": true, + "module": "es6", + "moduleResolution": "node", + + "skipLibCheck": true, + + "allowUnreachableCode": false, + "allowUnusedLabels": false, + "exactOptionalPropertyTypes": true, "noFallthroughCasesInSwitch": true, + "noImplicitOverride": true, "noImplicitReturns": true, + "noPropertyAccessFromIndexSignature": true, "noUnusedLocals": true, "noUnusedParameters": true, - "skipLibCheck": true, "strict": true } } From 6b132a4a7fcbeffbe7c73e0a6b50a131213f474b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20D=C4=9Bdi=C4=8D?= Date: Fri, 13 Sep 2024 19:23:28 +0300 Subject: [PATCH 2/2] Using index signature to access index properties --- src/index.ts | 2 +- src/lib/ImageView.ts | 4 ++-- src/lib/PreloadedVideo.ts | 6 +++--- src/lib/State.ts | 4 ++-- src/lib/VideoCache.ts | 2 +- src/lib/history.ts | 6 +++--- src/lib/imagelightbox.ts | 2 +- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/index.ts b/src/index.ts index e0b9ca45..f0056ada 100644 --- a/src/index.ts +++ b/src/index.ts @@ -98,7 +98,7 @@ document linkContainer.appendChild(newLi); const newAnchor = document.createElement("a"); - newAnchor.dataset.imagelightbox = "i"; + newAnchor.dataset["imagelightbox"] = "i"; newAnchor.href = "images/demo4.jpg"; newLi.appendChild(newAnchor); diff --git a/src/lib/ImageView.ts b/src/lib/ImageView.ts index 8976b067..edecf768 100644 --- a/src/lib/ImageView.ts +++ b/src/lib/ImageView.ts @@ -38,10 +38,10 @@ export function ImageView( containerElement.classList.add("ilb-image-container"); let isVideoPreloaded: boolean | undefined = undefined; - const isVideo = image.dataset.ilb2Video !== undefined; + const isVideo = image.dataset["ilb2Video"] !== undefined; if (isVideo) { [imageElement, isVideoPreloaded] = videoCache.element( - image.dataset.ilb2VideoId!, + image.dataset["ilb2VideoId"]!, ); } containerElement.appendChild(imageElement); diff --git a/src/lib/PreloadedVideo.ts b/src/lib/PreloadedVideo.ts index 4899d6d3..e5ff0081 100644 --- a/src/lib/PreloadedVideo.ts +++ b/src/lib/PreloadedVideo.ts @@ -10,18 +10,18 @@ export function PreloadedVideo( image: HTMLAnchorElement, videoOptions: VideoOptions, ): PreloadedVideo { - let tempId = image.dataset.ilb2Id; + let tempId = image.dataset["ilb2Id"]; if (tempId === undefined) { // Random id tempId = `a${(((1 + Math.random()) * 0x10000) | 0).toString(16)}`; } - image.dataset.ilb2VideoId = tempId; + image.dataset["ilb2VideoId"] = tempId; const videoId = tempId; const videoElement = document.createElement("video"); videoElement.setAttribute("id", "ilb-image"); videoElement.preload = "metadata"; - videoElement.dataset.ilb2VideoId = videoId; + videoElement.dataset["ilb2VideoId"] = videoId; let isLoaded = false; let autoplay = false; let height: number | undefined = undefined; diff --git a/src/lib/State.ts b/src/lib/State.ts index fe6bb68b..639a81cf 100644 --- a/src/lib/State.ts +++ b/src/lib/State.ts @@ -110,7 +110,7 @@ export function State( const image = targetImages[currentImage!]; if (options.caption) { setCaption( - image.dataset.ilb2Caption ?? + image.dataset["ilb2Caption"] ?? image.getElementsByTagName("img").item(0)?.alt ?? "", options.animationSpeed, @@ -283,7 +283,7 @@ export function State( (element): boolean => element.tagName.toLowerCase() === "a" && (new RegExp(`.(${options.allowedTypes})$`, "i").test(element.href) || - element.dataset.ilb2Video !== undefined), + element.dataset["ilb2Video"] !== undefined), ); videoCache.add(validImages); targetImages.push(...validImages); diff --git a/src/lib/VideoCache.ts b/src/lib/VideoCache.ts index f1157a18..368f822f 100644 --- a/src/lib/VideoCache.ts +++ b/src/lib/VideoCache.ts @@ -13,7 +13,7 @@ export function VideoCache(): VideoCache { function add(elements: Array): void { for (const image of elements) { - const videoOptions = image.dataset.ilb2Video; + const videoOptions = image.dataset["ilb2Video"]; if (videoOptions === undefined) { continue; } diff --git a/src/lib/history.ts b/src/lib/history.ts index 5a457edf..dd2f0368 100644 --- a/src/lib/history.ts +++ b/src/lib/history.ts @@ -20,7 +20,7 @@ export function pushToHistory( set: string | undefined, images: Array, ): void { - const newIndex = images[index].dataset.ilb2Id ?? index.toString(); + const newIndex = images[index].dataset["ilb2Id"] ?? index.toString(); let newQuery = addQueryField( document.location.search, "imageLightboxIndex", @@ -53,7 +53,7 @@ export function openHistory( if (id === undefined) { return; } - let newIndex = images.findIndex((image) => image.dataset.ilb2Id === id); + let newIndex = images.findIndex((image) => image.dataset["ilb2Id"] === id); if (newIndex < 0) { newIndex = parseInt(id, 10); } @@ -92,7 +92,7 @@ export function popHistory( return; } let newIndex = images.findIndex( - (e: HTMLElement) => e.dataset.ilb2Id === newId, + (e: HTMLElement) => e.dataset["ilb2Id"] === newId, ); if (newIndex < 0) { newIndex = parseInt(newId, 10); diff --git a/src/lib/imagelightbox.ts b/src/lib/imagelightbox.ts index accd4254..500c10c6 100644 --- a/src/lib/imagelightbox.ts +++ b/src/lib/imagelightbox.ts @@ -33,7 +33,7 @@ export class ImageLightbox { }; this.s = State( opts, - images.length > 0 ? (images[0].dataset.imagelightbox ?? "") : "", + images.length > 0 ? (images[0].dataset["imagelightbox"] ?? "") : "", Array.from(images), );