Skip to content

Commit

Permalink
feat(svelte): implement svelte package
Browse files Browse the repository at this point in the history
  • Loading branch information
oktaysenkan committed Oct 5, 2024
1 parent d4d7a07 commit 60ddf67
Show file tree
Hide file tree
Showing 17 changed files with 553 additions and 30 deletions.
2 changes: 0 additions & 2 deletions apps/vite-vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
"preview": "vite preview"
},
"dependencies": {
"svg-parser": "^2.0.4",
"svgson": "^5.3.1",
"vue": "^3.5.10",
"@oktaytest/vue": "*"
},
Expand Down
22 changes: 22 additions & 0 deletions packages/svelte/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
node_modules

# Output
.output
.vercel
/.svelte-kit
/build
/dist

# OS
.DS_Store
Thumbs.db

# Env
.env
.env.*
!.env.example
!.env.test

# Vite
vite.config.js.timestamp-*
vite.config.ts.timestamp-*
1 change: 1 addition & 0 deletions packages/svelte/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
engine-strict=true
58 changes: 58 additions & 0 deletions packages/svelte/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# create-svelte

Everything you need to build a Svelte library, powered by [`create-svelte`](https://github.com/sveltejs/kit/tree/main/packages/create-svelte).

Read more about creating a library [in the docs](https://kit.svelte.dev/docs/packaging).

## Creating a project

If you're seeing this, you've probably already done this step. Congrats!

```bash
# create a new project in the current directory
npm create svelte@latest

# create a new project in my-app
npm create svelte@latest my-app
```

## Developing

Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:

```bash
npm run dev

# or start the server and open the app in a new browser tab
npm run dev -- --open
```

Everything inside `src/lib` is part of your library, everything inside `src/routes` can be used as a showcase or preview app.

## Building

To build your library:

```bash
npm run package
```

To create a production version of your showcase app:

```bash
npm run build
```

You can preview the production build with `npm run preview`.

> To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment.
## Publishing

Go into the `package.json` and give your package the desired name through the `"name"` option. Also consider adding a `"license"` field and point it to a `LICENSE` file which you can create from a template (one popular option is the [MIT license](https://opensource.org/license/mit/)).

To publish your library to [npm](https://www.npmjs.com):

```bash
npm publish
```
46 changes: 46 additions & 0 deletions packages/svelte/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"name": "@oktaytest/svelte",
"version": "0.0.118",
"scripts": {
"dev": "vite dev",
"build": "vite build && npm run package",
"preview": "vite preview",
"package": "svelte-kit sync && svelte-package && publint",
"prepublishOnly": "npm run package",
"prepack": "yarn build",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch"
},
"typings": "./dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"svelte": "./dist/index.js"
}
},
"files": [
"dist",
"!dist/**/*.test.*",
"!dist/**/*.spec.*"
],
"peerDependencies": {
"svelte": "^4.0.0"
},
"devDependencies": {
"@sveltejs/adapter-auto": "^3.0.0",
"@sveltejs/kit": "^2.0.0",
"@sveltejs/package": "^2.0.0",
"@sveltejs/vite-plugin-svelte": "^3.0.0",
"publint": "^0.2.0",
"svelte": "^4.2.7",
"svelte-check": "^4.0.0",
"typescript": "^5.0.0",
"vite": "^5.0.11"
},
"svelte": "./dist/index.js",
"types": "./dist/index.d.ts",
"type": "module",
"dependencies": {
"svgson": "^5.3.1"
}
}
13 changes: 13 additions & 0 deletions packages/svelte/src/app.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// See https://kit.svelte.dev/docs/types#app
// for information about these interfaces
declare global {
namespace App {
// interface Error {}
// interface Locals {}
// interface PageData {}
// interface PageState {}
// interface Platform {}
}
}

export {};
12 changes: 12 additions & 0 deletions packages/svelte/src/app.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
%sveltekit.head%
</head>
<body data-sveltekit-preload-data="hover">
<div>%sveltekit.body%</div>
</body>
</html>
45 changes: 45 additions & 0 deletions packages/svelte/src/lib/Iconify.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<script lang="ts">
import { parseSync, stringify } from "svgson";
import { fallbackIcon } from "@oktaytest/core/constants";
// @ts-ignore
import icons from "oktay";
export let name: string;
export let size: number | undefined = undefined;
export let color: string | undefined = undefined;
$: icon = icons[name] || fallbackIcon;
if (!icons[name]) {
console.warn(
`[Iconify] The icon "${name}" is missing from the configuration. To resolve this, ensure it is added to the 'icons' array within the Iconify plugin's configuration.`
);
}
$: parsed = parseSync(icon.svg);
$: children = parsed.children.map((child) => {
if (child.name !== "path" || !child.attributes.fill || !color) return child;
child.attributes.fill = color;
return child;
});
$: html = stringify(children as any);
$: ratio = icon.width / icon.height;
$: height = size ? Number(size) : icon.height;
$: width = size ? Number(size) * ratio : icon.width;
$: attributes = {
...parsed.attributes,
width,
height,
};
</script>

<svg {...attributes}>
{@html html}
</svg>
4 changes: 4 additions & 0 deletions packages/svelte/src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Iconify from "./Iconify.svelte";

export { Iconify };
export default Iconify;
27 changes: 27 additions & 0 deletions packages/svelte/src/routes/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<script>
import Iconify from "../lib/Iconify.svelte";
</script>

<main>
<Iconify name="mdi:home" size={24} />
<Iconify name="logos:active-campaign" />
<Iconify name="logos:apache-superset-icon" />
<Iconify name="invalid:icon" color="red" />
</main>

<style>
:global(html),
:global(body) {
margin: 0;
padding: 0;
}
main {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #242424;
color: rgba(255, 255, 255, 0.87);
}
</style>
Binary file added packages/svelte/static/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions packages/svelte/svelte.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import adapter from '@sveltejs/adapter-auto';
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';

/** @type {import('@sveltejs/kit').Config} */
const config = {
// Consult https://kit.svelte.dev/docs/integrations#preprocessors
// for more information about preprocessors
preprocess: vitePreprocess(),

kit: {
// adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list.
// If your environment is not supported, or you settled on a specific environment, switch out the adapter.
// See https://kit.svelte.dev/docs/adapters for more information about adapters.
adapter: adapter()
}
};

export default config;
15 changes: 15 additions & 0 deletions packages/svelte/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"extends": "./.svelte-kit/tsconfig.json",
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
"module": "NodeNext",
"moduleResolution": "NodeNext"
}
}
21 changes: 21 additions & 0 deletions packages/svelte/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vite';
import { IconifyPlugin } from "@oktaytest/vite";

export default defineConfig({
plugins: [
sveltekit(),
IconifyPlugin({
icons: [
"mdi:home",
"mdi:account",
"mdi:account-badge-outline",
"feather:activity",
"feather:alert-circle",
"logos:active-campaign",
"logos:apache-superset-icon",
],
outputFileName: "vite-vue",
})
]
});
3 changes: 2 additions & 1 deletion packages/vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"vite-plugin-dts": "^4.2.3"
},
"dependencies": {
"@oktaytest/core": "*"
"@oktaytest/core": "*",
"svgson": "^5.3.1"
},
"peerDependencies": {
"vue": "^2.6.14 || ^3.0.0"
Expand Down
4 changes: 2 additions & 2 deletions packages/vue/src/Iconify.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<script setup lang="ts">
import { parseSync, stringify, INode } from "svgson";
import { defineProps, computed } from "vue";
import { parseSync, stringify } from "svgson";
// @ts-ignore
import icons from "oktay";
// @ts-ignore
import { fallbackIcon } from "@oktaytest/core/constants";
import { defineProps, computed } from "vue";
export type IconifyProps = {
name: string;
Expand Down
Loading

0 comments on commit 60ddf67

Please sign in to comment.