Skip to content

Commit

Permalink
feat: add svelte-vapor-runtime pkg
Browse files Browse the repository at this point in the history
  • Loading branch information
kazupon committed Sep 4, 2024
1 parent 1de81e3 commit 149c3a2
Show file tree
Hide file tree
Showing 17 changed files with 256 additions and 53 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
"build:react:hooks": "pnpm run --filter=./packages/react-vapor-hooks build",
"build:react:unplugin": "pnpm run --filter=./packages/unplugin-react build",
"build:shared": "pnpm run --filter=./packages/shared build",
"build:svelte": "run-s \"build:svelte:compiler\" \"build:svelte:sfc\" \"build:svelte:unplugin\" \"build:svelte:template\"",
"build:svelte": "run-s \"build:svelte:runtime\" \"build:svelte:compiler\" \"build:svelte:sfc\" \"build:svelte:unplugin\" \"build:svelte:template\"",
"build:svelte:compiler": "pnpm run --filter=./packages/svelte-template-compiler build",
"build:svelte:runtime": "pnpm run --filter=./packages/svelte-vapor-runtime build",
"build:svelte:sfc": "pnpm run --filter=./packages/svelte-sfc-compiler build",
"build:svelte:template": "pnpm run --filter=./packages/svelte-template-explorer build",
"build:svelte:unplugin": "pnpm run --filter=./packages/unplugin-svelte build",
Expand Down
20 changes: 20 additions & 0 deletions packages/svelte-vapor-runtime/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
The MIT License (MIT)

Copyright (c) 2024 kazuya kawaguchi

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
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.
7 changes: 7 additions & 0 deletions packages/svelte-vapor-runtime/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# react-vapor-hooks

> React hooks for vapor
## ©️ License

[MIT](http://opensource.org/licenses/MIT)
54 changes: 54 additions & 0 deletions packages/svelte-vapor-runtime/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"name": "svelte-vapor-runtime",
"description": "svelte runtime for vapor",
"version": "0.0.0",
"author": {
"name": "kazuya kawaguchi",
"email": "[email protected]"
},
"license": "MIT",
"funding": "https://github.com/sponsors/kazupon",
"bugs": {
"url": "https://github.com/kazupon/inclusion-vapor/issues"
},
"repository": {
"type": "git",
"url": "git+https://github.com/kazupon/inclusion-vapor.git",
"directory": "packages/svelte-vapor-runtime"
},
"keywords": [
"svelte",
"runtime",
"vapor"
],
"homepage": "https://github.com/kazupon/inclusion-vapor#readme",
"publishConfig": {
"access": "public"
},
"engines": {
"node": ">= 18.18"
},
"type": "module",
"files": [
"dist/index.cjs",
"dist/index.js"
],
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"exports": {
".": {
"import": "./dist/index.js",
"require": "./dist/index.cjs"
}
},
"scripts": {
"build": "tsdown"
},
"dependencies": {
"@vue-vapor/vapor": "latest"
},
"devDependencies": {
"svelte": "catalog:",
"tsdown": "catalog:"
}
}
81 changes: 81 additions & 0 deletions packages/svelte-vapor-runtime/src/_helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/**
* Helper module for unit tests
*/

import { createVaporApp, defineComponent } from '@vue-vapor/vapor'
import { afterEach, beforeEach } from 'vitest'

import type { App, ComponentInternalInstance, ObjectComponent, SetupFn } from '@vue-vapor/vapor'
type RawProps = NonNullable<Parameters<typeof createVaporApp>[1]>

// forked from `vuejs/core-vapor` test utils

export function makeRender<Component = ObjectComponent | SetupFn>(
initHost = (): HTMLDivElement => {
const host = document.createElement('div')
host.setAttribute('id', 'host')
document.body.append(host)
return host
}
) {
let host: HTMLElement
function resetHost() {
return (host = initHost())
}

beforeEach(() => {
resetHost()
})
afterEach(() => {
host.remove()
})

function define(comp: Component) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-argument
const component = defineComponent(comp as any)
let instance: ComponentInternalInstance | undefined
let app: App

function render(props: RawProps = {}, container: string | ParentNode = host) {
create(props)
return mount(container)
}

function create(props: RawProps = {}) {
app?.unmount()
app = createVaporApp(component, props)
return res()
}

function mount(container: string | ParentNode = host) {
instance = app.mount(container)
return res()
}

// eslint-disable-next-line unicorn/consistent-function-scoping
function html() {
return host.innerHTML
}

const res = () => ({
component,
host,
instance,
app,
create,
mount,
render,
resetHost,
html
})

return res()
}

return define
}

export function triggerEvent(type: string, el: Element) {
const event = new Event(type, { bubbles: true })
el.dispatchEvent(event)
}
1 change: 1 addition & 0 deletions packages/svelte-vapor-runtime/src/action.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {}
1 change: 1 addition & 0 deletions packages/svelte-vapor-runtime/src/animate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {}
1 change: 1 addition & 0 deletions packages/svelte-vapor-runtime/src/context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {}
1 change: 1 addition & 0 deletions packages/svelte-vapor-runtime/src/easing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {}
8 changes: 8 additions & 0 deletions packages/svelte-vapor-runtime/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export * from './action.ts' // eslint-disable-line import-x/export
export * from './animate.ts' // eslint-disable-line import-x/export
export * from './context.ts' // eslint-disable-line import-x/export
export * from './easing.ts' // eslint-disable-line import-x/export
export * from './lifecycle.ts' // eslint-disable-line import-x/export
export * from './motion.ts' // eslint-disable-line import-x/export
export * from './store.ts' // eslint-disable-line import-x/export
export * from './transition.ts' // eslint-disable-line import-x/export
1 change: 1 addition & 0 deletions packages/svelte-vapor-runtime/src/lifecycle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {}
1 change: 1 addition & 0 deletions packages/svelte-vapor-runtime/src/motion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {}
1 change: 1 addition & 0 deletions packages/svelte-vapor-runtime/src/store.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {}
1 change: 1 addition & 0 deletions packages/svelte-vapor-runtime/src/transition.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {}
10 changes: 10 additions & 0 deletions packages/svelte-vapor-runtime/tsdown.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { defineConfig } from 'tsdown'

export default defineConfig({
entry: 'src/index.ts',
format: ['esm', 'cjs'],
platform: 'node',
outDir: 'dist',
clean: true,
dts: true
})
Loading

0 comments on commit 149c3a2

Please sign in to comment.