diff --git a/package-lock.json b/package-lock.json index f4dd6cfb..63f00c58 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6,7 +6,7 @@ "packages": { "": { "name": "stwui", - "version": "0.9.2-next", + "version": "0.9.3-next", "license": "MIT", "dependencies": { "color": "^4.2.3", @@ -22,7 +22,7 @@ "@sveltejs/adapter-auto": "2.0.0", "@sveltejs/adapter-vercel": "2.4.1", "@sveltejs/kit": "1.15.2", - "@sveltejs/package": "2.0.2", + "@sveltejs/package": "^2.0.0", "@tailwindcss/forms": "^0.5.3", "@testing-library/dom": "^9.2.0", "@testing-library/svelte": "^3.2.2", @@ -35,6 +35,7 @@ "eslint": "^8.38.0", "eslint-config-prettier": "^8.8.0", "eslint-plugin-svelte3": "^4.0.0", + "esm-env": "^1.0.0", "highlight.js": "^11.7.0", "husky": "^8.0.3", "jsdom": "^21.1.1", @@ -53,6 +54,7 @@ "vitest": "^0.30.0" }, "peerDependencies": { + "@sveltejs/kit": "1.15.2", "svelte": "^3.55.1" } }, diff --git a/package.json b/package.json index 5133a600..0a7286f1 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "scripts": { "dev": "vite dev --open --host", "build": "vite build", - "package": "svelte-package", + "package": "svelte-package -o package", "preview": "vite preview", "test": "vitest", "coverage": "vitest run --coverage", @@ -38,7 +38,7 @@ "@sveltejs/adapter-auto": "2.0.0", "@sveltejs/adapter-vercel": "2.4.1", "@sveltejs/kit": "1.15.2", - "@sveltejs/package": "2.0.2", + "@sveltejs/package": "^2.0.0", "@tailwindcss/forms": "^0.5.3", "@testing-library/dom": "^9.2.0", "@testing-library/svelte": "^3.2.2", @@ -51,6 +51,7 @@ "eslint": "^8.38.0", "eslint-config-prettier": "^8.8.0", "eslint-plugin-svelte3": "^4.0.0", + "esm-env": "^1.0.0", "highlight.js": "^11.7.0", "husky": "^8.0.3", "jsdom": "^21.1.1", @@ -80,15 +81,99 @@ "tippy.js": "^6.3.7" }, "peerDependencies": { + "@sveltejs/kit": "1.15.2", "svelte": "^3.55.1" }, "exports": { + "./package.json": "./package.json", ".": "./index.js", "./actions": "./actions/index.js", - "./plugin": "./plugin/index.js", + "./plugin": "./package/plugin/index.js", "./types": "./types/index.js", "./utils": "./utils/index.js", "./icons": "./icons.js", - "./enums": "./enums.js" + "./enums": "./enums.js", + "./plugin/base": { + "types": "./package/plugin/base/index.d.ts", + "svelte": "./package/plugin/base/index.js", + "default": "./package/plugin/base/index.js" + }, + "./plugin/colors": { + "types": "./package/plugin/colors/index.d.ts", + "svelte": "./package/plugin/colors/index.js", + "default": "./package/plugin/colors/index.js" + }, + "./plugin/components": { + "types": "./package/plugin/components/index.d.ts", + "svelte": "./package/plugin/components/index.js", + "default": "./package/plugin/components/index.js" + }, + "./plugin/node_modules/color": { + "types": "./package/plugin/node_modules/color/index.d.ts", + "svelte": "./package/plugin/node_modules/color/index.js", + "default": "./package/plugin/node_modules/color/index.js" + }, + "./plugin/node_modules/color-convert": { + "types": "./package/plugin/node_modules/color-convert/index.d.ts", + "svelte": "./package/plugin/node_modules/color-convert/index.js", + "default": "./package/plugin/node_modules/color-convert/index.js" + }, + "./plugin/node_modules/color-name": { + "types": "./package/plugin/node_modules/color-name/index.d.ts", + "svelte": "./package/plugin/node_modules/color-name/index.js", + "default": "./package/plugin/node_modules/color-name/index.js" + }, + "./plugin/node_modules/color-string": { + "types": "./package/plugin/node_modules/color-string/index.d.ts", + "svelte": "./package/plugin/node_modules/color-string/index.js", + "default": "./package/plugin/node_modules/color-string/index.js" + }, + "./plugin/node_modules/is-arrayish": { + "types": "./package/plugin/node_modules/is-arrayish/index.d.ts", + "svelte": "./package/plugin/node_modules/is-arrayish/index.js", + "default": "./package/plugin/node_modules/is-arrayish/index.js" + }, + "./plugin/node_modules/simple-swizzle": { + "types": "./package/plugin/node_modules/simple-swizzle/index.d.ts", + "svelte": "./package/plugin/node_modules/simple-swizzle/index.js", + "default": "./package/plugin/node_modules/simple-swizzle/index.js" + } + }, + "files": [ + "package" + ], + "typesVersions": { + ">4.0": { + "plugin/base": [ + "./package/plugin/base/index.d.ts" + ], + "plugin/colors": [ + "./package/plugin/colors/index.d.ts" + ], + "plugin/components": [ + "./package/plugin/components/index.d.ts" + ], + "plugin": [ + "./package/plugin/index.d.ts" + ], + "plugin/node_modules/color": [ + "./package/plugin/node_modules/color/index.d.ts" + ], + "plugin/node_modules/color-convert": [ + "./package/plugin/node_modules/color-convert/index.d.ts" + ], + "plugin/node_modules/color-name": [ + "./package/plugin/node_modules/color-name/index.d.ts" + ], + "plugin/node_modules/color-string": [ + "./package/plugin/node_modules/color-string/index.d.ts" + ], + "plugin/node_modules/is-arrayish": [ + "./package/plugin/node_modules/is-arrayish/index.d.ts" + ], + "plugin/node_modules/simple-swizzle": [ + "./package/plugin/node_modules/simple-swizzle/index.d.ts" + ] + } } } diff --git a/src/docs/components/search/Search.svelte b/src/docs/components/search/Search.svelte index 71b47825..472639d0 100644 --- a/src/docs/components/search/Search.svelte +++ b/src/docs/components/search/Search.svelte @@ -12,7 +12,7 @@ toggle_switch } from '../../icons'; import { close, info } from '../../../lib/icons'; - import { browser } from '$app/environment'; + import { BROWSER } from 'esm-env'; import HoverBackground from '$lib/components/HoverBackground.svelte'; let input: HTMLInputElement; @@ -103,7 +103,7 @@ } } - $: if (open && browser && input) { + $: if (open && BROWSER && input) { input.focus(); } diff --git a/src/lib/stores/theme.ts b/src/lib/stores/theme.ts index 25c97643..83c57b54 100644 --- a/src/lib/stores/theme.ts +++ b/src/lib/stores/theme.ts @@ -1,12 +1,12 @@ -import { browser } from '$app/environment'; +import { BROWSER } from 'esm-env'; import { writable } from 'svelte/store'; const defaultValue = 'light'; -const initialValue = browser ? window.localStorage.getItem('theme') ?? defaultValue : defaultValue; +const initialValue = BROWSER ? window.localStorage.getItem('theme') ?? defaultValue : defaultValue; const theme = writable(initialValue); theme.subscribe((value) => { - if (browser) { + if (BROWSER) { window.localStorage.setItem('theme', value === 'dark' ? 'dark' : 'light'); } }); diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 57d775c0..938b66c7 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -3,7 +3,7 @@ import { theme } from '$lib/stores'; import { page } from '$app/stores'; import { Button, Drawer, Swap, Icon, Layout, Portal, Row, Toggle, Col, Divider } from '../lib'; - import { browser } from '$app/environment'; + import { DEV, BROWSER } from 'esm-env'; import { Navigation, Search } from '../docs'; import { brightness_4, brightness_5 } from '../docs/icons'; import { menu, close } from '../lib/icons'; @@ -19,12 +19,12 @@ } $: darkTheme = $theme === 'dark'; - $: if (browser && darkTheme) { + $: if (BROWSER && darkTheme) { const htmlElement = document.documentElement; // htmlElement.classList.add('dark'); htmlElement.dataset.theme = 'dark'; theme.set('dark'); - } else if (browser) { + } else if (BROWSER) { const htmlElement = document.documentElement; // htmlElement.classList.remove('dark'); htmlElement.dataset.theme = 'light'; @@ -36,7 +36,7 @@ async function scrollToTop(pathname: string) { const newPath = pathname; if (path !== newPath) { - if (browser) { + if (BROWSER) { const scrollEl = document.getElementById('content-body') as HTMLDivElement; if (scrollEl) { scrollEl.scrollTop = 0; diff --git a/svelte.config.js b/svelte.config.js index bc59487f..7c8e1030 100644 --- a/svelte.config.js +++ b/svelte.config.js @@ -13,14 +13,6 @@ const config = { kit: { adapter: vercel() }, - package: { - exports: (filepath) => { - return filepath.endsWith('index.js'); - }, - files: (filepath) => { - return filepath.indexOf('test') == -1 ? true : false; - } - } -}; + }; export default config;