diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json
index 267c606..027b9ea 100644
--- a/.devcontainer/devcontainer.json
+++ b/.devcontainer/devcontainer.json
@@ -1,26 +1,26 @@
{
- "name": "Svelte-Static",
- "dockerComposeFile": "./docker-compose.yml",
- "service": "svelte-static",
- "remoteUser": "developer",
- "workspaceFolder": "/svelte-static",
- "postCreateCommand": ".devcontainer/post-create.sh",
- "customizations": {
- "vscode": {
- "extensions": [
- "ms-vscode.vscode-typescript-next",
- "dbaeumer.vscode-eslint",
- "esbenp.prettier-vscode",
- "dozerg.tsimportsorter",
- "svelte.svelte-vscode",
- "bradlc.vscode-tailwindcss",
- "vunguyentuan.vscode-postcss",
- "vunguyentuan.vscode-css-variables",
- "EthanSK.restore-terminals",
- "antfu.iconify",
- "heybourn.headwind",
- "bierner.github-markdown-preview"
- ]
- }
- }
-}
\ No newline at end of file
+ "name": "Svelte-Static",
+ "dockerComposeFile": "./docker-compose.yml",
+ "service": "svelte-static",
+ "remoteUser": "developer",
+ "workspaceFolder": "/svelte-static",
+ "postCreateCommand": ".devcontainer/post-create.sh",
+ "customizations": {
+ "vscode": {
+ "extensions": [
+ "ms-vscode.vscode-typescript-next",
+ "dbaeumer.vscode-eslint",
+ "esbenp.prettier-vscode",
+ "dozerg.tsimportsorter",
+ "svelte.svelte-vscode",
+ "bradlc.vscode-tailwindcss",
+ "vunguyentuan.vscode-postcss",
+ "vunguyentuan.vscode-css-variables",
+ "EthanSK.restore-terminals",
+ "antfu.iconify",
+ "heybourn.headwind",
+ "bierner.github-markdown-preview"
+ ]
+ }
+ }
+}
diff --git a/.prettierrc b/.prettierrc
index 7ebb855..16b3fd8 100644
--- a/.prettierrc
+++ b/.prettierrc
@@ -1,15 +1,15 @@
{
- "useTabs": true,
- "singleQuote": true,
- "trailingComma": "none",
- "printWidth": 100,
- "plugins": ["prettier-plugin-svelte", "prettier-plugin-tailwindcss"],
- "overrides": [
- {
- "files": "*.svelte",
- "options": {
- "parser": "svelte"
- }
- }
- ]
+ "useTabs": false,
+ "singleQuote": true,
+ "trailingComma": "none",
+ "printWidth": 100,
+ "plugins": ["prettier-plugin-svelte", "prettier-plugin-tailwindcss"],
+ "overrides": [
+ {
+ "files": "*.svelte",
+ "options": {
+ "parser": "svelte"
+ }
+ }
+ ]
}
diff --git a/.vscode/settings.json b/.vscode/settings.json
index 3463aba..79aad35 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -1,59 +1,55 @@
{
- "[typescript]": {
- "editor.defaultFormatter": "esbenp.prettier-vscode"
- },
- "[javascript]": {
- "editor.defaultFormatter": "esbenp.prettier-vscode"
- },
- "[svelte]": {
- "editor.defaultFormatter": "svelte.svelte-vscode"
- },
- "editor.codeActionsOnSave": {
- "source.fixAll": "explicit",
- "source.unusedImports": "explicit",
- "source.organizeImports": "explicit"
- },
- "files.associations": {
- "*.css": "tailwindcss"
- },
- "restoreTerminals.terminals": [
- {
- "splitTerminals": [
- {
- "name": "mock api",
- "commands": [
- "echo 'Pretending you have a local server running...'",
- "echo 'You can delete this in your .vscode/settings.json.'",
- "npx local-cors-proxy --proxyUrl https://dummyjson.com --port 3000"
- ]
- },
- ]
- },
- {
- "splitTerminals": [
- {
- "name": "dev",
- "commands": [
- "npm install && npm run test:unit -- --run && npm run dev -- --host"
- ]
- },
- {
- "name": "preview",
- "commands": [
- "npm install && npm run test:e2e && npm run preview -- --host"
- ]
- },
- ]
- },
- {
- "splitTerminals": [
- {
- "name": "bash",
- "commands": []
- },
- ]
- }
- ],
- // Fix the double formatter issue that leaves invalid code for imports.
- "typescript.format.enable": false
-}
\ No newline at end of file
+ "[typescript]": {
+ "editor.defaultFormatter": "esbenp.prettier-vscode"
+ },
+ "[javascript]": {
+ "editor.defaultFormatter": "esbenp.prettier-vscode"
+ },
+ "[svelte]": {
+ "editor.defaultFormatter": "svelte.svelte-vscode"
+ },
+ "editor.codeActionsOnSave": {
+ "source.fixAll": "explicit",
+ "source.unusedImports": "explicit",
+ "source.organizeImports": "explicit"
+ },
+ "files.associations": {
+ "*.css": "tailwindcss"
+ },
+ "restoreTerminals.terminals": [
+ {
+ "splitTerminals": [
+ {
+ "name": "mock api",
+ "commands": [
+ "echo 'Pretending you have a local server running...'",
+ "echo 'You can delete this in your .vscode/settings.json.'",
+ "npx local-cors-proxy --proxyUrl https://dummyjson.com --port 3000"
+ ]
+ }
+ ]
+ },
+ {
+ "splitTerminals": [
+ {
+ "name": "dev",
+ "commands": ["npm install && npm run test:unit -- --run && npm run dev -- --host"]
+ },
+ {
+ "name": "preview",
+ "commands": ["npm install && npm run test:e2e && npm run preview -- --host"]
+ }
+ ]
+ },
+ {
+ "splitTerminals": [
+ {
+ "name": "bash",
+ "commands": []
+ }
+ ]
+ }
+ ],
+ // Fix the double formatter issue that leaves invalid code for imports.
+ "typescript.format.enable": false
+}
diff --git a/e2e/demo.test.ts b/e2e/demo.test.ts
index 9985ce1..a67e4e7 100644
--- a/e2e/demo.test.ts
+++ b/e2e/demo.test.ts
@@ -1,6 +1,6 @@
import { expect, test } from '@playwright/test';
test('home page has expected h1', async ({ page }) => {
- await page.goto('/');
- await expect(page.locator('h1')).toBeVisible();
+ await page.goto('/');
+ await expect(page.locator('h1')).toBeVisible();
});
diff --git a/eslint.config.js b/eslint.config.js
index a526565..841d476 100644
--- a/eslint.config.js
+++ b/eslint.config.js
@@ -5,29 +5,29 @@ import globals from 'globals';
import ts from 'typescript-eslint';
export default ts.config(
- js.configs.recommended,
- ...ts.configs.recommended,
- ...svelte.configs['flat/recommended'],
- prettier,
- ...svelte.configs['flat/prettier'],
- {
- languageOptions: {
- globals: {
- ...globals.browser,
- ...globals.node
- }
- }
- },
- {
- files: ['**/*.svelte'],
+ js.configs.recommended,
+ ...ts.configs.recommended,
+ ...svelte.configs['flat/recommended'],
+ prettier,
+ ...svelte.configs['flat/prettier'],
+ {
+ languageOptions: {
+ globals: {
+ ...globals.browser,
+ ...globals.node
+ }
+ }
+ },
+ {
+ files: ['**/*.svelte'],
- languageOptions: {
- parserOptions: {
- parser: ts.parser
- }
- }
- },
- {
- ignores: ['build/', '.svelte-kit/', 'dist/']
- }
+ languageOptions: {
+ parserOptions: {
+ parser: ts.parser
+ }
+ }
+ },
+ {
+ ignores: ['build/', '.svelte-kit/', 'dist/']
+ }
);
diff --git a/package.json b/package.json
index 518d048..163c5e1 100644
--- a/package.json
+++ b/package.json
@@ -1,52 +1,52 @@
{
- "name": "svelte-static",
- "version": "0.0.1",
- "type": "module",
- "scripts": {
- "dev": "vite dev",
- "build": "vite build",
- "preview": "vite preview",
- "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
- "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
- "format": "prettier --write .",
- "lint": "prettier --check . && eslint .",
- "obfuscate": "javascript-obfuscator ./build --output ./build",
- "test:unit": "vitest",
- "test": "npm run test:unit -- --run && npm run test:e2e",
- "test:e2e": "playwright test"
- },
- "devDependencies": {
- "@iconify/json": "^2.2.273",
- "@playwright/test": "^1.45.3",
- "@sveltejs/adapter-static": "^3.0.6",
- "@sveltejs/kit": "^2.0.0",
- "@sveltejs/vite-plugin-svelte": "^4.0.0",
- "@types/eslint": "^9.6.0",
- "autoprefixer": "^10.4.20",
- "eslint": "^9.7.0",
- "eslint-config-prettier": "^9.1.0",
- "eslint-plugin-svelte": "^2.36.0",
- "globals": "^15.0.0",
- "javascript-obfuscator": "^4.1.1",
- "luxon": "^3.5.0",
- "postcss": "^8.4.49",
- "postcss-import": "^16.1.0",
- "prettier": "^3.3.2",
- "prettier-plugin-svelte": "^3.2.6",
- "prettier-plugin-tailwindcss": "^0.6.5",
- "svelte": "^5.0.0",
- "svelte-check": "^4.0.0",
- "tailwindcss": "^3.4.9",
- "typescript": "^5.0.0",
- "typescript-eslint": "^8.0.0",
- "unplugin-icons": "^0.20.1",
- "vite": "^5.0.3",
- "vitest": "^2.0.4"
- },
- "dependencies": {
- "@tailwindcss/aspect-ratio": "^0.4.2",
- "@tailwindcss/container-queries": "^0.1.1",
- "@tailwindcss/forms": "^0.5.9",
- "@tailwindcss/typography": "^0.5.15"
- }
+ "name": "svelte-static",
+ "version": "0.0.1",
+ "type": "module",
+ "scripts": {
+ "dev": "vite dev",
+ "build": "vite build",
+ "preview": "vite preview",
+ "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
+ "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
+ "format": "prettier --write .",
+ "lint": "prettier --check . && eslint .",
+ "obfuscate": "javascript-obfuscator ./build --output ./build",
+ "test:unit": "vitest",
+ "test": "npm run test:unit -- --run && npm run test:e2e",
+ "test:e2e": "playwright test"
+ },
+ "devDependencies": {
+ "@iconify/json": "^2.2.273",
+ "@playwright/test": "^1.45.3",
+ "@sveltejs/adapter-static": "^3.0.6",
+ "@sveltejs/kit": "^2.0.0",
+ "@sveltejs/vite-plugin-svelte": "^4.0.0",
+ "@types/eslint": "^9.6.0",
+ "autoprefixer": "^10.4.20",
+ "eslint": "^9.7.0",
+ "eslint-config-prettier": "^9.1.0",
+ "eslint-plugin-svelte": "^2.36.0",
+ "globals": "^15.0.0",
+ "javascript-obfuscator": "^4.1.1",
+ "luxon": "^3.5.0",
+ "postcss": "^8.4.49",
+ "postcss-import": "^16.1.0",
+ "prettier": "^3.3.2",
+ "prettier-plugin-svelte": "^3.2.6",
+ "prettier-plugin-tailwindcss": "^0.6.5",
+ "svelte": "^5.0.0",
+ "svelte-check": "^4.0.0",
+ "tailwindcss": "^3.4.9",
+ "typescript": "^5.0.0",
+ "typescript-eslint": "^8.0.0",
+ "unplugin-icons": "^0.20.1",
+ "vite": "^5.0.3",
+ "vitest": "^2.0.4"
+ },
+ "dependencies": {
+ "@tailwindcss/aspect-ratio": "^0.4.2",
+ "@tailwindcss/container-queries": "^0.1.1",
+ "@tailwindcss/forms": "^0.5.9",
+ "@tailwindcss/typography": "^0.5.15"
+ }
}
diff --git a/playwright.config.ts b/playwright.config.ts
index d4d2822..8de3d5b 100644
--- a/playwright.config.ts
+++ b/playwright.config.ts
@@ -1,11 +1,11 @@
import { defineConfig } from '@playwright/test';
export default defineConfig({
- webServer: {
- command: 'npm run build && npm run obfuscate && npm run preview',
- port: 4173,
- reuseExistingServer: true
- },
+ webServer: {
+ command: 'npm run build && npm run obfuscate && npm run preview',
+ port: 4173,
+ reuseExistingServer: true
+ },
- testDir: 'e2e'
+ testDir: 'e2e'
});
diff --git a/postcss.config.js b/postcss.config.js
index ef13dbe..71fb00f 100644
--- a/postcss.config.js
+++ b/postcss.config.js
@@ -1,7 +1,7 @@
export default {
- plugins: {
- 'postcss-import': {},
- tailwindcss: {},
- autoprefixer: {}
- }
+ plugins: {
+ 'postcss-import': {},
+ tailwindcss: {},
+ autoprefixer: {}
+ }
};
diff --git a/src/app.css b/src/app.css
index 6fb9a13..48f88c0 100644
--- a/src/app.css
+++ b/src/app.css
@@ -3,33 +3,33 @@
@import 'tailwindcss/utilities';
@layer base {
- /* Toogle light/dark mode on your OS to see changes. */
- body {
- @apply font-sans antialiased;
- @apply bg-white text-neutral-900;
- @apply dark:bg-neutral-900 dark:text-white;
- }
+ /* Toogle light/dark mode on your OS to see changes. */
+ body {
+ @apply font-sans antialiased;
+ @apply bg-white text-neutral-900;
+ @apply dark:bg-neutral-900 dark:text-white;
+ }
- h1 {
- @apply text-2xl font-bold;
- }
- h2 {
- @apply text-xl font-bold;
- }
- h3 {
- @apply text-lg font-bold;
- }
- h4 {
- @apply text-base font-bold;
- }
- h5 {
- @apply text-sm font-bold;
- }
- h6 {
- @apply text-xs font-bold;
- }
+ h1 {
+ @apply text-2xl font-bold;
+ }
+ h2 {
+ @apply text-xl font-bold;
+ }
+ h3 {
+ @apply text-lg font-bold;
+ }
+ h4 {
+ @apply text-base font-bold;
+ }
+ h5 {
+ @apply text-sm font-bold;
+ }
+ h6 {
+ @apply text-xs font-bold;
+ }
- a {
- @apply text-blue-600 dark:text-blue-500;
- }
+ a {
+ @apply text-blue-600 dark:text-blue-500;
+ }
}
diff --git a/src/app.d.ts b/src/app.d.ts
index e83202f..a80673f 100644
--- a/src/app.d.ts
+++ b/src/app.d.ts
@@ -4,11 +4,11 @@
import 'unplugin-icons/types/svelte';
declare global {
- namespace App {
- // interface Error {}
- // interface Locals {}
- // interface PageData {}
- // interface PageState {}
- // interface Platform {}
- }
+ namespace App {
+ // interface Error {}
+ // interface Locals {}
+ // interface PageData {}
+ // interface PageState {}
+ // interface Platform {}
+ }
}
diff --git a/src/app.html b/src/app.html
index 77a5ff5..84ffad1 100644
--- a/src/app.html
+++ b/src/app.html
@@ -1,12 +1,12 @@
-
-
-
-
- %sveltekit.head%
-
-
- %sveltekit.body%
-
+
+
+
+
+ %sveltekit.head%
+
+
+ %sveltekit.body%
+
diff --git a/src/demo.spec.ts b/src/demo.spec.ts
index e07cbbd..964d287 100644
--- a/src/demo.spec.ts
+++ b/src/demo.spec.ts
@@ -1,7 +1,7 @@
import { describe, it, expect } from 'vitest';
describe('sum test', () => {
- it('adds 1 + 2 to equal 3', () => {
- expect(1 + 2).toBe(3);
- });
+ it('adds 1 + 2 to equal 3', () => {
+ expect(1 + 2).toBe(3);
+ });
});
diff --git a/src/lib/advertising/service.ts b/src/lib/advertising/service.ts
index afcfa32..b81121b 100644
--- a/src/lib/advertising/service.ts
+++ b/src/lib/advertising/service.ts
@@ -1,3 +1,3 @@
export abstract class AdvertisingService {
- abstract loadAd(element: HTMLElement, adSlot: string, format: string): Promise;
+ abstract loadAd(element: HTMLElement, adSlot: string, format: string): Promise;
}
diff --git a/src/lib/advertising/service_google_adsense.ts b/src/lib/advertising/service_google_adsense.ts
index 120ce7d..3cb31fd 100644
--- a/src/lib/advertising/service_google_adsense.ts
+++ b/src/lib/advertising/service_google_adsense.ts
@@ -1,33 +1,33 @@
import { AdvertisingService } from './service';
declare global {
- interface Window {
- adsbygoogle: any[];
- }
+ interface Window {
+ adsbygoogle: any[];
+ }
}
export class AdvertisingServiceGoogleAdsense extends AdvertisingService {
- private clientId: string;
+ private clientId: string;
- constructor(clientId: string) {
- super();
- this.clientId = clientId;
- window.adsbygoogle = window.adsbygoogle || [];
- const script = document.createElement('script');
- script.async = true;
- script.src = `https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=${this.clientId}`;
- script.crossOrigin = 'anonymous';
- document.head.appendChild(script);
- }
+ constructor(clientId: string) {
+ super();
+ this.clientId = clientId;
+ window.adsbygoogle = window.adsbygoogle || [];
+ const script = document.createElement('script');
+ script.async = true;
+ script.src = `https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=${this.clientId}`;
+ script.crossOrigin = 'anonymous';
+ document.head.appendChild(script);
+ }
- async loadAd(element: HTMLElement, adSlot: string, format: string = 'auto'): Promise {
- window.adsbygoogle.push({
- element,
- adUnitPath: adSlot,
- format: format
- });
- return new Promise((resolve) => {
- element.addEventListener('load', () => resolve());
- });
- }
+ async loadAd(element: HTMLElement, adSlot: string, format: string = 'auto'): Promise {
+ window.adsbygoogle.push({
+ element,
+ adUnitPath: adSlot,
+ format: format
+ });
+ return new Promise((resolve) => {
+ element.addEventListener('load', () => resolve());
+ });
+ }
}
diff --git a/src/lib/advertising/service_mock.ts b/src/lib/advertising/service_mock.ts
index 51bb2dd..bbe9c02 100644
--- a/src/lib/advertising/service_mock.ts
+++ b/src/lib/advertising/service_mock.ts
@@ -1,13 +1,13 @@
import { AdvertisingService } from './service';
export class AdvertisingServiceMock extends AdvertisingService {
- override async loadAd(element: HTMLElement, adSlot: string, format: string): Promise {
- element.classList.add('block', 'bg-neutral-500', 'rounded-lg', 'overflow-hidden');
- element.innerHTML = `
+ override async loadAd(element: HTMLElement, adSlot: string, format: string): Promise {
+ element.classList.add('block', 'bg-neutral-500', 'rounded-lg', 'overflow-hidden');
+ element.innerHTML = `
Ad Placeholder ${element.offsetWidth}x${element.offsetHeight}
`;
- return Promise.resolve();
- }
+ return Promise.resolve();
+ }
}
diff --git a/src/lib/app.ts b/src/lib/app.ts
index 00184ce..6032b59 100644
--- a/src/lib/app.ts
+++ b/src/lib/app.ts
@@ -2,11 +2,11 @@ import type { AdvertisingService } from './advertising/service';
import type { TelemetryService } from './telemetry/service';
export class App {
- advertising: AdvertisingService;
- telemetry: TelemetryService;
+ advertising: AdvertisingService;
+ telemetry: TelemetryService;
- constructor(advertising: AdvertisingService, telemetry: TelemetryService) {
- this.advertising = advertising;
- this.telemetry = telemetry;
- }
+ constructor(advertising: AdvertisingService, telemetry: TelemetryService) {
+ this.advertising = advertising;
+ this.telemetry = telemetry;
+ }
}
diff --git a/src/lib/config.ts b/src/lib/config.ts
index 4700bf9..9d80833 100644
--- a/src/lib/config.ts
+++ b/src/lib/config.ts
@@ -4,9 +4,9 @@ export const IS_PRODUCTION_BUILD = BUILD_MODE === 'production';
/** Check if running on localhost or a local network. */
export const IS_LOCAL_ENVIRONMENT =
- window.location.hostname === 'localhost' ||
- window.location.hostname === '127.0.0.1' ||
- window.location.hostname.includes('.local');
+ window.location.hostname === 'localhost' ||
+ window.location.hostname === '127.0.0.1' ||
+ window.location.hostname.includes('.local');
/** The base URL for the backend API. */
export const API_URL = import.meta.env.VITE_API_URL as string;
diff --git a/src/lib/error.ts b/src/lib/error.ts
index 729ffa4..141265e 100644
--- a/src/lib/error.ts
+++ b/src/lib/error.ts
@@ -1,28 +1,28 @@
import { log } from '$lib';
export type ErrorData = {
- /** A well-defined error code such as `user/not-found` */
- code: string;
+ /** A well-defined error code such as `user/not-found` */
+ code: string;
- /** A message to log to the console. */
- logMessage?: string;
+ /** A message to log to the console. */
+ logMessage?: string;
- /** A message for displaying to the user. */
- displayMessage?: string;
+ /** A message for displaying to the user. */
+ displayMessage?: string;
- /** The cause of the error. */
- exception?: Error;
+ /** The cause of the error. */
+ exception?: Error;
- /** Any additional data. */
- extra?: any;
+ /** Any additional data. */
+ extra?: any;
};
/** The base class for errors in the application. */
export class AppError extends Error {
- constructor(data: ErrorData) {
- super(data.code);
- this.data = data;
- log.error(data.code, data.logMessage ?? data.extra, data.exception);
- }
- data: ErrorData;
+ constructor(data: ErrorData) {
+ super(data.code);
+ this.data = data;
+ log.error(data.code, data.logMessage ?? data.extra, data.exception);
+ }
+ data: ErrorData;
}
diff --git a/src/lib/index.ts b/src/lib/index.ts
index 4fc8ebb..45df786 100644
--- a/src/lib/index.ts
+++ b/src/lib/index.ts
@@ -6,12 +6,12 @@ import { AdvertisingServiceGoogleAdsense } from './advertising/service_google_ad
import { AdvertisingServiceMock } from './advertising/service_mock';
import { App } from './app';
import {
- ADSENSE_CLIENT_ID,
- API_URL,
- BUILD_MODE,
- GA_MEASUREMENT_ID,
- IS_LOCAL_ENVIRONMENT,
- IS_PRODUCTION_BUILD
+ ADSENSE_CLIENT_ID,
+ API_URL,
+ BUILD_MODE,
+ GA_MEASUREMENT_ID,
+ IS_LOCAL_ENVIRONMENT,
+ IS_PRODUCTION_BUILD
} from './config';
import { Log } from './log';
import { TelemetryServiceGoogleAnalytics } from './telemetry/service_google_analytics';
@@ -23,21 +23,21 @@ export const log = new Log(IS_PRODUCTION_BUILD ? Log.INFO : Log.TRACE);
log.debug(init_start, 'Initializing...');
log.debug('Config:', {
- BUILD_MODE,
- API_URL,
- IS_PRODUCTION_BUILD,
- IS_LOCAL_ENVIRONMENT,
- GA_MEASUREMENT_ID,
- ADSENSE_CLIENT_ID
+ BUILD_MODE,
+ API_URL,
+ IS_PRODUCTION_BUILD,
+ IS_LOCAL_ENVIRONMENT,
+ GA_MEASUREMENT_ID,
+ ADSENSE_CLIENT_ID
});
export const app = new App(
- ADSENSE_CLIENT_ID && IS_PRODUCTION_BUILD && !IS_LOCAL_ENVIRONMENT
- ? new AdvertisingServiceGoogleAdsense(ADSENSE_CLIENT_ID)
- : new AdvertisingServiceMock(),
- GA_MEASUREMENT_ID && IS_PRODUCTION_BUILD && !IS_LOCAL_ENVIRONMENT
- ? new TelemetryServiceGoogleAnalytics(GA_MEASUREMENT_ID)
- : new TelemetryServiceMock()
+ ADSENSE_CLIENT_ID && IS_PRODUCTION_BUILD && !IS_LOCAL_ENVIRONMENT
+ ? new AdvertisingServiceGoogleAdsense(ADSENSE_CLIENT_ID)
+ : new AdvertisingServiceMock(),
+ GA_MEASUREMENT_ID && IS_PRODUCTION_BUILD && !IS_LOCAL_ENVIRONMENT
+ ? new TelemetryServiceGoogleAnalytics(GA_MEASUREMENT_ID)
+ : new TelemetryServiceMock()
);
log.info(performance.now(), base ? `Initialized at ${base}.` : 'Initialized.');
diff --git a/src/lib/log.ts b/src/lib/log.ts
index 53c2255..871ba0c 100644
--- a/src/lib/log.ts
+++ b/src/lib/log.ts
@@ -1,40 +1,40 @@
export class Log {
- static readonly ASSERT = 1;
- static readonly ERROR = 2;
- static readonly WARN = 3;
- static readonly INFO = 4;
- static readonly DEBUG = 5;
- static readonly TRACE = 6;
+ static readonly ASSERT = 1;
+ static readonly ERROR = 2;
+ static readonly WARN = 3;
+ static readonly INFO = 4;
+ static readonly DEBUG = 5;
+ static readonly TRACE = 6;
- assert = console.assert.bind(console);
- error = console.error.bind(console);
- warn = console.warn.bind(console);
- info = console.info.bind(console);
- debug = console.debug.bind(console);
- trace = console.log.bind(console);
+ assert = console.assert.bind(console);
+ error = console.error.bind(console);
+ warn = console.warn.bind(console);
+ info = console.info.bind(console);
+ debug = console.debug.bind(console);
+ trace = console.log.bind(console);
- level = Log.INFO;
+ level = Log.INFO;
- constructor(level?: number) {
- if (level !== undefined) {
- this.level = level;
- }
- this.setLevel(this.level);
- }
+ constructor(level?: number) {
+ if (level !== undefined) {
+ this.level = level;
+ }
+ this.setLevel(this.level);
+ }
- setLevel(level: number) {
- this.level = level;
- if (level >= Log.ASSERT) this.assert = console.assert.bind(console);
- else this.assert = function () {};
- if (level >= Log.ERROR) this.error = console.error.bind(console);
- else this.error = function () {};
- if (level >= Log.WARN) this.warn = console.warn.bind(console);
- else this.warn = function () {};
- if (level >= Log.INFO) this.info = console.info.bind(console);
- else this.info = function () {};
- if (level >= Log.DEBUG) this.debug = console.debug.bind(console);
- else this.debug = function () {};
- if (level >= Log.TRACE) this.trace = console.log.bind(console);
- else this.trace = function () {};
- }
+ setLevel(level: number) {
+ this.level = level;
+ if (level >= Log.ASSERT) this.assert = console.assert.bind(console);
+ else this.assert = function () {};
+ if (level >= Log.ERROR) this.error = console.error.bind(console);
+ else this.error = function () {};
+ if (level >= Log.WARN) this.warn = console.warn.bind(console);
+ else this.warn = function () {};
+ if (level >= Log.INFO) this.info = console.info.bind(console);
+ else this.info = function () {};
+ if (level >= Log.DEBUG) this.debug = console.debug.bind(console);
+ else this.debug = function () {};
+ if (level >= Log.TRACE) this.trace = console.log.bind(console);
+ else this.trace = function () {};
+ }
}
diff --git a/src/lib/telemetry/service.ts b/src/lib/telemetry/service.ts
index 436b126..bd3b345 100644
--- a/src/lib/telemetry/service.ts
+++ b/src/lib/telemetry/service.ts
@@ -1,5 +1,5 @@
export abstract class TelemetryService {
- abstract pageView(path: string): void;
- abstract event(name: string, params?: Record): void;
- abstract timing(name: string, value: number): void;
+ abstract pageView(path: string): void;
+ abstract event(name: string, params?: Record): void;
+ abstract timing(name: string, value: number): void;
}
diff --git a/src/lib/telemetry/service_google_analytics.ts b/src/lib/telemetry/service_google_analytics.ts
index 38ade43..2cfd6f2 100644
--- a/src/lib/telemetry/service_google_analytics.ts
+++ b/src/lib/telemetry/service_google_analytics.ts
@@ -1,44 +1,44 @@
import { TelemetryService } from './service';
declare global {
- interface Window {
- dataLayer: any[];
- }
+ interface Window {
+ dataLayer: any[];
+ }
}
/**
* Google Analytics 4 adapter for the telemetry service.
*/
export class TelemetryServiceGoogleAnalytics extends TelemetryService {
- constructor(measurementId: string) {
- super();
- const script = document.createElement('script');
- script.async = true;
- script.src = `https://www.googletagmanager.com/gtag/js?id=${measurementId}`;
- document.head.appendChild(script);
- window.dataLayer = window.dataLayer || [];
- this.gtag('js', new Date());
- this.gtag('config', measurementId);
- }
+ constructor(measurementId: string) {
+ super();
+ const script = document.createElement('script');
+ script.async = true;
+ script.src = `https://www.googletagmanager.com/gtag/js?id=${measurementId}`;
+ document.head.appendChild(script);
+ window.dataLayer = window.dataLayer || [];
+ this.gtag('js', new Date());
+ this.gtag('config', measurementId);
+ }
- private gtag(..._: any[]): void {
- window.dataLayer.push(arguments);
- }
+ private gtag(..._: any[]): void {
+ window.dataLayer.push(arguments);
+ }
- pageView(path: string): void {
- this.gtag('event', 'page_view', {
- page_path: path
- });
- }
+ pageView(path: string): void {
+ this.gtag('event', 'page_view', {
+ page_path: path
+ });
+ }
- event(name: string, params?: Record): void {
- this.gtag('event', name, params);
- }
+ event(name: string, params?: Record): void {
+ this.gtag('event', name, params);
+ }
- timing(name: string, value: number): void {
- this.gtag('event', 'timing_complete', {
- name,
- value
- });
- }
+ timing(name: string, value: number): void {
+ this.gtag('event', 'timing_complete', {
+ name,
+ value
+ });
+ }
}
diff --git a/src/lib/telemetry/service_mock.ts b/src/lib/telemetry/service_mock.ts
index b776dae..3dae856 100644
--- a/src/lib/telemetry/service_mock.ts
+++ b/src/lib/telemetry/service_mock.ts
@@ -6,15 +6,15 @@ import { TelemetryService } from './service';
* Mock adapter for the telemetry service that logs to the console.
*/
export class TelemetryServiceMock extends TelemetryService {
- pageView(path: string): void {
- log.trace('Telemetry:', 'page_view', path);
- }
+ pageView(path: string): void {
+ log.trace('Telemetry:', 'page_view', path);
+ }
- event(name: string, params?: Record): void {
- log.trace('Telemetry:', 'event', name, params);
- }
+ event(name: string, params?: Record): void {
+ log.trace('Telemetry:', 'event', name, params);
+ }
- timing(name: string, value: number): void {
- log.trace('Telemetry:', 'timing_complete', name, value);
- }
+ timing(name: string, value: number): void {
+ log.trace('Telemetry:', 'timing_complete', name, value);
+ }
}
diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte
index e22f8d8..7029d7e 100644
--- a/src/routes/+layout.svelte
+++ b/src/routes/+layout.svelte
@@ -1,15 +1,15 @@
-
+
diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte
index 8f7913f..3209de3 100644
--- a/src/routes/+page.svelte
+++ b/src/routes/+page.svelte
@@ -1,30 +1,30 @@
- Welcome to SvelteKit
-
- Visit svelte.dev/docs/kit to read the documentation.
-
- API test: {testResult}
+ Welcome to SvelteKit
+
+ Visit svelte.dev/docs/kit to read the documentation.
+
+ API test: {testResult}
diff --git a/svelte.config.js b/svelte.config.js
index 5ff7ea0..9dec356 100644
--- a/svelte.config.js
+++ b/svelte.config.js
@@ -3,19 +3,19 @@ import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
/** @type {import('@sveltejs/kit').Config} */
const config = {
- // Consult https://svelte.dev/docs/kit/integrations
- // for more information about preprocessors
- preprocess: vitePreprocess(),
+ // Consult https://svelte.dev/docs/kit/integrations
+ // for more information about preprocessors
+ preprocess: vitePreprocess(),
- kit: {
- // adapter-auto only supports some environments, see https://svelte.dev/docs/kit/adapter-auto for a list.
- // If your environment is not supported, or you settled on a specific environment, switch out the adapter.
- // See https://svelte.dev/docs/kit/adapters for more information about adapters.
- adapter: adapter(),
- paths: {
- base: process.env.BASE_PATH || ''
- }
- }
+ kit: {
+ // adapter-auto only supports some environments, see https://svelte.dev/docs/kit/adapter-auto for a list.
+ // If your environment is not supported, or you settled on a specific environment, switch out the adapter.
+ // See https://svelte.dev/docs/kit/adapters for more information about adapters.
+ adapter: adapter(),
+ paths: {
+ base: process.env.BASE_PATH || ''
+ }
+ }
};
export default config;
diff --git a/tailwind.config.ts b/tailwind.config.ts
index 3e931a7..a0d107a 100644
--- a/tailwind.config.ts
+++ b/tailwind.config.ts
@@ -5,11 +5,11 @@ import typography from '@tailwindcss/typography';
import type { Config } from 'tailwindcss';
export default {
- content: ['./src/**/*.{html,js,svelte,ts}'],
+ content: ['./src/**/*.{html,js,svelte,ts}'],
- theme: {
- extend: {}
- },
+ theme: {
+ extend: {}
+ },
- plugins: [typography, forms, containerQueries, aspectRatio]
+ plugins: [typography, forms, containerQueries, aspectRatio]
} satisfies Config;
diff --git a/tsconfig.json b/tsconfig.json
index 0b2d886..f4d0a0e 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -1,19 +1,19 @@
{
- "extends": "./.svelte-kit/tsconfig.json",
- "compilerOptions": {
- "allowJs": true,
- "checkJs": true,
- "esModuleInterop": true,
- "forceConsistentCasingInFileNames": true,
- "resolveJsonModule": true,
- "skipLibCheck": true,
- "sourceMap": true,
- "strict": true,
- "moduleResolution": "bundler"
- }
- // Path aliases are handled by https://svelte.dev/docs/kit/configuration#alias
- // except $lib which is handled by https://svelte.dev/docs/kit/configuration#files
- //
- // If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes
- // from the referenced tsconfig.json - TypeScript does not merge them in
+ "extends": "./.svelte-kit/tsconfig.json",
+ "compilerOptions": {
+ "allowJs": true,
+ "checkJs": true,
+ "esModuleInterop": true,
+ "forceConsistentCasingInFileNames": true,
+ "resolveJsonModule": true,
+ "skipLibCheck": true,
+ "sourceMap": true,
+ "strict": true,
+ "moduleResolution": "bundler"
+ }
+ // Path aliases are handled by https://svelte.dev/docs/kit/configuration#alias
+ // except $lib which is handled by https://svelte.dev/docs/kit/configuration#files
+ //
+ // If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes
+ // from the referenced tsconfig.json - TypeScript does not merge them in
}
diff --git a/vite.config.ts b/vite.config.ts
index 5d89b0a..0de2ae2 100644
--- a/vite.config.ts
+++ b/vite.config.ts
@@ -4,14 +4,14 @@ import { defineConfig } from 'vitest/config';
import { sveltekit } from '@sveltejs/kit/vite';
export default defineConfig({
- plugins: [
- sveltekit(),
- Icons({
- compiler: 'svelte'
- })
- ],
+ plugins: [
+ sveltekit(),
+ Icons({
+ compiler: 'svelte'
+ })
+ ],
- test: {
- include: ['src/**/*.{test,spec}.{js,ts}']
- }
+ test: {
+ include: ['src/**/*.{test,spec}.{js,ts}']
+ }
});