@teiler/svelte 0.0.30 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,121 +0,0 @@
1
- import { readFileSync } from 'fs'
2
- import path from 'path'
3
- import { compile, preprocess } from 'svelte/compiler'
4
- import sveltePreprocess from 'svelte-preprocess'
5
- import { dts } from 'rolldown-plugin-dts'
6
- import { transformSync } from '@swc/core'
7
-
8
- const globals = {
9
- 'svelte/internal': 'svelte/internal',
10
- 'svelte/internal/disclose-version': 'svelte/internal/disclose-version',
11
- 'svelte/store': 'svelte/store',
12
- svelte: 'svelte',
13
- }
14
-
15
- function sveltePlugin() {
16
- return {
17
- name: 'svelte-rolldown',
18
-
19
- resolveId(source, importer) {
20
- if (source.endsWith('.svelte')) {
21
- if (!importer) return path.resolve(source)
22
- return path.resolve(path.dirname(importer), source)
23
- }
24
- return null
25
- },
26
-
27
- async transform(code, id) {
28
- if (!id.endsWith('.svelte')) return null
29
-
30
- const source = readFileSync(id, 'utf-8')
31
-
32
- const preprocessed = await preprocess(
33
- source,
34
- sveltePreprocess({
35
- typescript({ content, filename }) {
36
- const { code, map } = transformSync(content, {
37
- filename: `${filename}.ts`,
38
- sourceMaps: true,
39
- })
40
- return { code, map }
41
- },
42
- }),
43
- { filename: id },
44
- )
45
-
46
- const { js } = compile(preprocessed.code, {
47
- filename: id,
48
- sourcemap: false,
49
- })
50
-
51
- return {
52
- code: js.code,
53
- moduleType: 'js',
54
- }
55
- },
56
- }
57
- }
58
-
59
- export default [
60
- {
61
- input: 'src/index.ts',
62
- external: ['svelte', 'svelte/internal', /^svelte\//],
63
- resolve: {
64
- alias: {
65
- '@teiler/core': path.resolve('../core/src/index.ts'),
66
- },
67
- },
68
- output: [
69
- {
70
- file: 'dist/teiler-svelte.umd.js',
71
- name: 'teiler-svelte',
72
- format: 'umd',
73
- sourcemap: true,
74
- minify: true,
75
- globals,
76
- },
77
- {
78
- file: 'dist/teiler-svelte.cjs.js',
79
- format: 'cjs',
80
- sourcemap: true,
81
- minify: true,
82
- globals,
83
- },
84
- {
85
- file: 'dist/teiler-svelte.esm.js',
86
- format: 'esm',
87
- sourcemap: true,
88
- minify: true,
89
- globals,
90
- },
91
- ],
92
- plugins: [sveltePlugin()],
93
- watch: {
94
- clearScreen: false,
95
- },
96
- },
97
- {
98
- input: 'src/index.ts',
99
- external: ['svelte', 'svelte/internal', /^svelte\//, '@teiler/core'],
100
- output: {
101
- dir: 'dist',
102
- format: 'es',
103
- entryFileNames: (chunk) => (chunk.name.endsWith('.d') ? 'teiler-svelte.d.ts' : '_entry.js'),
104
- },
105
- plugins: [
106
- {
107
- name: 'svelte-dts-redirect',
108
- resolveId(id, importer) {
109
- if (id.endsWith('.svelte') && importer) {
110
- return { id: path.resolve(path.dirname(importer), id + '.d.ts') }
111
- }
112
- return null
113
- },
114
- },
115
- dts({ emitDtsOnly: true }),
116
- ],
117
- watch: {
118
- clearScreen: false,
119
- },
120
- },
121
- ]
package/src/Styled.svelte DELETED
@@ -1,145 +0,0 @@
1
- <script lang="ts">
2
- type _Ignore = $$Generic
3
- type Props = $$Generic<object>
4
-
5
- type $$Props = {
6
- styleDefinition: StyleDefinition<HTMLElements, Props>
7
- }
8
-
9
- import type { DefaultTheme, HTMLElements, Sheet, StyleDefinition } from '@teiler/core'
10
- import type { Writable } from 'svelte/store'
11
-
12
- import { insert } from '@teiler/core'
13
- import { getStyleSheet } from './sheet'
14
- import { getContext } from 'svelte'
15
- import { context } from './ThemeProvider.svelte'
16
-
17
- export let styleDefinition: StyleDefinition<HTMLElements, Props>
18
-
19
- const sheet: Sheet = getStyleSheet()
20
-
21
- const theme: Writable<DefaultTheme> = getContext(context)
22
-
23
- $: props = $$restProps as Record<string, unknown> & Props
24
-
25
- $: styleClassName = insert(sheet, styleDefinition, { ...props, theme: $theme })
26
-
27
- $: filtredPropsEntries = Object.entries($$restProps).filter(([key, _value]) => key[0] !== '_' && key !== 'class')
28
- $: filtredProps = Object.fromEntries(filtredPropsEntries)
29
-
30
- $: className = $$restProps.class ? `${styleClassName} ${styleDefinition.id} ${$$restProps.class}` : `${styleClassName} ${styleDefinition.id}`
31
- </script>
32
-
33
- <!-- svelte-ignore a11y-no-static-element-interactions -->
34
- <svelte:element
35
- this={styleDefinition.tag}
36
- class={className}
37
- {...filtredProps}
38
- on:copy
39
- on:cut
40
- on:paste
41
- on:compositionend
42
- on:compositionstart
43
- on:compositionupdate
44
- on:focus
45
- on:focusin
46
- on:focusout
47
- on:blur
48
- on:change
49
- on:beforeinput
50
- on:input
51
- on:reset
52
- on:submit
53
- on:invalid
54
- on:formdata
55
- on:load
56
- on:error
57
- on:beforetoggle
58
- on:toggle
59
- on:keydown
60
- on:keypress
61
- on:keyup
62
- on:abort
63
- on:canplay
64
- on:canplaythrough
65
- on:cuechange
66
- on:durationchange
67
- on:emptied
68
- on:encrypted
69
- on:ended
70
- on:loadeddata
71
- on:loadedmetadata
72
- on:loadstart
73
- on:pause
74
- on:play
75
- on:playing
76
- on:progress
77
- on:ratechange
78
- on:seeked
79
- on:seeking
80
- on:stalled
81
- on:suspend
82
- on:timeupdate
83
- on:volumechange
84
- on:waiting
85
- on:auxclick
86
- on:click
87
- on:contextmenu
88
- on:dblclick
89
- on:drag
90
- on:dragend
91
- on:dragenter
92
- on:dragexit
93
- on:dragleave
94
- on:dragover
95
- on:dragstart
96
- on:drop
97
- on:mousedown
98
- on:mouseenter
99
- on:mouseleave
100
- on:mousemove
101
- on:mouseout
102
- on:mouseover
103
- on:mouseup
104
- on:select
105
- on:selectionchange
106
- on:selectstart
107
- on:touchcancel
108
- on:touchend
109
- on:touchmove
110
- on:touchstart
111
- on:gotpointercapture
112
- on:pointercancel
113
- on:pointerdown
114
- on:pointerenter
115
- on:pointerleave
116
- on:pointermove
117
- on:pointerout
118
- on:pointerover
119
- on:pointerup
120
- on:lostpointercapture
121
- on:gamepadconnected
122
- on:gamepaddisconnected
123
- on:scroll
124
- on:scrollend
125
- on:resize
126
- on:wheel
127
- on:animationstart
128
- on:animationend
129
- on:animationiteration
130
- on:transitionstart
131
- on:transitionrun
132
- on:transitionend
133
- on:transitioncancel
134
- on:outrostart
135
- on:outroend
136
- on:introstart
137
- on:introend
138
- on:message
139
- on:messageerror
140
- on:visibilitychange
141
- on:cancel
142
- on:close
143
- on:fullscreenchange
144
- on:fullscreenerror><slot /></svelte:element
145
- >
@@ -1,19 +0,0 @@
1
- <script context="module">
2
- export const context = 'THEME'
3
- </script>
4
-
5
- <script lang="ts">
6
- import type { DefaultTheme } from '@teiler/core'
7
- import { setContext } from 'svelte'
8
- import { writable, type Writable } from 'svelte/store'
9
-
10
- export let theme: DefaultTheme
11
-
12
- const themeStore = writable<DefaultTheme>(theme)
13
-
14
- setContext<Writable<DefaultTheme>>(context, themeStore)
15
-
16
- $: themeStore.set(theme)
17
- </script>
18
-
19
- <slot />
@@ -1,5 +0,0 @@
1
- import type { SvelteComponent } from 'svelte'
2
- import type { DefaultTheme } from '@teiler/core'
3
-
4
- export const context: string = 'THEME'
5
- export default class ThemeProvider extends SvelteComponent<{ theme: DefaultTheme }> {}
@@ -1,17 +0,0 @@
1
- <script lang="ts">
2
- import { DefaultTheme } from '@teiler/core'
3
- import ThemeProvider from './ThemeProvider.svelte'
4
- import { component } from './component'
5
-
6
- const theme: DefaultTheme = {
7
- fontColor: 'green',
8
- }
9
-
10
- const TestComponent = component`
11
- color: ${({ theme }) => theme.fontColor};
12
- `
13
- </script>
14
-
15
- <ThemeProvider {theme}>
16
- <TestComponent>abc</TestComponent>
17
- </ThemeProvider>
package/src/component.ts DELETED
@@ -1,57 +0,0 @@
1
- import type { Compiler, HTMLElements, Properties, StyleDefinition, TeilerComponent } from '@teiler/core'
2
- import type { ComponentType, SvelteComponent } from 'svelte'
3
-
4
- import { component, global, keyframes, styled, tags } from '@teiler/core'
5
- import Styled from './Styled.svelte'
6
-
7
- type SvelteTeilerComponent<Target extends HTMLElements, Props> = TeilerComponent<Target, Props> & ComponentType<SvelteComponent>
8
-
9
- type Options = ConstructorParameters<typeof Styled>[0]
10
-
11
- const createComponent = <Target extends HTMLElements, Props extends object = {}>(styleDefinition: StyleDefinition<Target, Props>): SvelteTeilerComponent<Target, Props> => {
12
- return class extends Styled<{}, Props> {
13
- static styleDefinition = styleDefinition
14
-
15
- constructor(options: Options) {
16
- super({
17
- ...options,
18
- props: {
19
- ...options.props,
20
- styleDefinition,
21
- },
22
- })
23
- }
24
- }
25
- }
26
-
27
- type InferProps<Component, Props> = Component extends SvelteTeilerComponent<HTMLElements, infer P> ? P & Props : Props
28
- type InferComponent<Component, Props, Tag> = Component extends SvelteTeilerComponent<infer E, infer P> ? SvelteTeilerComponent<Tag extends HTMLElements ? Tag : E, Props & P> : SvelteTeilerComponent<HTMLElements, Props>
29
-
30
- type Component<Target extends HTMLElements, Tag extends HTMLElements | undefined = Target> = {
31
- <Props extends object = {}>(string: TemplateStringsArray, ...properties: Properties<Props>[]): SvelteTeilerComponent<Target, Props>
32
- <Component>(binded: Component): <Props extends object = {}>(string: TemplateStringsArray, ...properties: Properties<InferProps<Component, Props>>[]) => InferComponent<Component, Props, Tag>
33
- }
34
-
35
- type Global = {
36
- <Props extends object = {}>(string: TemplateStringsArray, ...properties: Properties<Props>[]): SvelteTeilerComponent<HTMLElements, Props>
37
- }
38
-
39
- type ComponentWithTags = Component<'div', undefined> & { [K in Exclude<HTMLElements, null>]: Component<K> }
40
-
41
- const construct = (tag: HTMLElements | undefined, compiler: Compiler) => {
42
- return <Props extends object = {}>(stringOrBinded: TeilerComponent<HTMLElements, Props> | TemplateStringsArray, ...properties: Properties<Props>[]) => {
43
- return styled<Props, SvelteTeilerComponent<HTMLElements, Props>>(tag, compiler, createComponent, stringOrBinded, ...properties)
44
- }
45
- }
46
-
47
- const svelteComponent = construct(undefined, component) as ComponentWithTags
48
-
49
- tags.forEach((tag) => {
50
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
51
- // @ts-expect-error
52
- svelteComponent[tag] = construct(tag, component)
53
- })
54
-
55
- const svelteGlobal = construct(null, global) as Global
56
-
57
- export { svelteComponent as component, svelteGlobal as global, keyframes, createComponent }
package/src/global.d.ts DELETED
@@ -1,3 +0,0 @@
1
- declare module '*.svelte' {
2
- export { SvelteComponentDev as default } from 'svelte/internal'
3
- }
package/src/index.test.ts DELETED
@@ -1,149 +0,0 @@
1
- import type { StyleDefinition } from '@teiler/core'
2
-
3
- import { writable } from 'svelte/store'
4
- import { describe, expect, test } from '@jest/globals'
5
- import { render } from '@testing-library/svelte'
6
- import { createStyleSheet } from '@teiler/core'
7
- import { component, createComponent, global, keyframes } from './index'
8
-
9
- import ThemeProviderTest from './ThemeProvider.test.svelte'
10
-
11
- describe('createComponent', () => {
12
- test('should create a component', () => {
13
- const styleSheet = createStyleSheet({})
14
-
15
- const styleDefinition: StyleDefinition<'div', {}> = {
16
- type: 'component',
17
- id: 'twq229y',
18
- tag: 'div',
19
- styles: [[['color: red;'], []]],
20
- }
21
-
22
- const component = createComponent(styleDefinition)
23
-
24
- const { baseElement } = render(component, {
25
- context: new Map(Object.entries({ STYLE_SHEET: styleSheet })),
26
- })
27
-
28
- expect(baseElement.innerHTML).toBe('<div><div class="teiler-wq229y twq229y"></div></div>')
29
- expect(styleSheet.dump()).toBe(' .teiler-wq229y{color:red;}')
30
- })
31
- })
32
-
33
- describe('component', () => {
34
- test('should create basic a component', () => {
35
- const StyledComponent = component`color: blue;`
36
-
37
- const { baseElement } = render(StyledComponent)
38
-
39
- expect(baseElement.innerHTML).toBe('<div><div class="teiler-1r77qux t8e9dar"></div></div>')
40
- })
41
-
42
- test('should create a component with props', () => {
43
- const styleSheet = createStyleSheet({})
44
-
45
- const StyledComponent = component<{ _color: string }>`color: ${(props) => props._color};`
46
-
47
- const { baseElement } = render(StyledComponent, {
48
- props: { _color: 'yellow' },
49
- context: new Map(Object.entries({ STYLE_SHEET: styleSheet })),
50
- })
51
-
52
- expect(baseElement.innerHTML).toBe('<div><div class="teiler-100tn2k t1fqd64x"></div></div>')
53
- expect(styleSheet.dump()).toBe(' .teiler-100tn2k{color:yellow;}')
54
- })
55
-
56
- test('should create a component with custom theme', () => {
57
- const styleSheet = createStyleSheet({})
58
-
59
- const StyledComponent = component`color: ${(props) => props.theme.fontColor};`
60
-
61
- const { baseElement } = render(StyledComponent, {
62
- context: new Map(Object.entries({ STYLE_SHEET: styleSheet, THEME: writable({ fontColor: 'green' }) })),
63
- })
64
-
65
- expect(baseElement.innerHTML).toBe('<div><div class="teiler-1dc5e1n t1fqd64x"></div></div>')
66
- expect(styleSheet.dump()).toBe(' .teiler-1dc5e1n{color:green;}')
67
- })
68
-
69
- test('should create a component with custom class', () => {
70
- const styleSheet = createStyleSheet({})
71
-
72
- const StyledComponent = component`color: green;`
73
-
74
- const { baseElement } = render(StyledComponent, {
75
- props: {
76
- class: 'custom-class',
77
- },
78
- context: new Map(Object.entries({ STYLE_SHEET: styleSheet })),
79
- })
80
-
81
- expect(baseElement.innerHTML).toBe('<div><div class="teiler-1dc5e1n tsqxzcw custom-class"></div></div>')
82
- expect(styleSheet.dump()).toBe(' .teiler-1dc5e1n{color:green;}')
83
- })
84
- })
85
-
86
- describe('global', () => {
87
- test('should create a global style', () => {
88
- const styleSheet = createStyleSheet({})
89
-
90
- const GlobalStyle = global`color: red;`
91
-
92
- const { baseElement } = render(GlobalStyle, {
93
- context: new Map(Object.entries({ STYLE_SHEET: styleSheet })),
94
- })
95
-
96
- // expect(GlobalStyle.styleDefinition).toEqual({ id: 'twq229y', styles: [[['color: red;'], []]], tag: null, type: 'global' })
97
-
98
- expect(baseElement.innerHTML).toBe('<div></div>')
99
- expect(styleSheet.dump()).toBe(' color:red;')
100
- })
101
-
102
- test('should create a global style with theme', () => {
103
- const styleSheet = createStyleSheet({})
104
-
105
- const GlobalStyle = global`color: ${(props) => props.theme.fontColor};`
106
-
107
- const { baseElement } = render(GlobalStyle, {
108
- context: new Map(Object.entries({ STYLE_SHEET: styleSheet, THEME: writable({ fontColor: 'green' }) })),
109
- })
110
-
111
- expect(baseElement.innerHTML).toBe('<div></div>')
112
- expect(styleSheet.dump()).toBe(' color:green;')
113
- })
114
- })
115
-
116
- describe('keyframes', () => {
117
- test('should create keyframes', () => {
118
- const styleSheet = createStyleSheet({})
119
-
120
- const animation = keyframes`from { opacity: 0; } to { opacity: 1; }`
121
- const StyledComponent = component`animation: ${animation} 5s infinite;`
122
-
123
- render(StyledComponent, {
124
- context: new Map(Object.entries({ STYLE_SHEET: styleSheet })),
125
- })
126
-
127
- expect(animation).toEqual({
128
- id: 'teiler-g1154k',
129
- styles: [[['from { opacity: 0; } to { opacity: 1; }'], []]],
130
- type: 'keyframes',
131
- tag: null,
132
- })
133
-
134
- expect(styleSheet.dump()).toBe(' @keyframes teiler-g1154k{from{opacity:0;}to{opacity:1;}} .teiler-jq8kuu{animation:teiler-g1154k 5s infinite;}')
135
- })
136
- })
137
-
138
- describe('ThemeProvider', () => {
139
- test('should provide theme', () => {
140
- const styleSheet = createStyleSheet({})
141
-
142
- const { baseElement } = render(ThemeProviderTest, {
143
- context: new Map(Object.entries({ STYLE_SHEET: styleSheet })),
144
- })
145
-
146
- expect(baseElement.innerHTML).toBe('<div><div class="teiler-9hfnro thjt86x">abc</div></div>')
147
- expect(styleSheet.dump()).toBe(' .teiler-9hfnro{color:green;}')
148
- })
149
- })
package/src/sheet.ts DELETED
@@ -1,20 +0,0 @@
1
- import { type Sheet, createStyleSheet } from '@teiler/core'
2
- import { getContext } from 'svelte'
3
-
4
- export let styleSheet: Sheet | null = null
5
-
6
- export const StyleSheet = 'STYLE_SHEET'
7
-
8
- export function getStyleSheet(): Sheet {
9
- const fromContext = getContext<Sheet>(StyleSheet)
10
-
11
- if (fromContext) {
12
- return fromContext
13
- }
14
-
15
- if (styleSheet === null) {
16
- styleSheet = createStyleSheet({})
17
- }
18
-
19
- return styleSheet
20
- }
package/svelte.config.js DELETED
@@ -1,7 +0,0 @@
1
- import preprocess from 'svelte-preprocess';
2
-
3
- const config = {
4
- preprocess: preprocess()
5
- }
6
-
7
- export default config;
package/tsconfig.json DELETED
@@ -1,31 +0,0 @@
1
- {
2
- "include": [
3
- "src/**/*"
4
- ],
5
- "exclude": [
6
- "node_modules"
7
- ],
8
- "compilerOptions": {
9
- "target": "es6",
10
- "lib": [
11
- "esnext",
12
- "DOM"
13
- ],
14
- "module": "esNext",
15
- "importHelpers": true,
16
- "moduleResolution": "bundler",
17
- "experimentalDecorators": true,
18
- "strict": true,
19
- "strictPropertyInitialization": false,
20
- "sourceMap": true,
21
- "allowSyntheticDefaultImports": true,
22
- "esModuleInterop": true,
23
- "verbatimModuleSyntax": false,
24
- "skipLibCheck": true,
25
- "paths": {
26
- "@teiler/core": ["../core/src"]
27
- }
28
- },
29
- "composite": true,
30
- "compileOnSave": false,
31
- }
package/vite.config.mjs DELETED
@@ -1,6 +0,0 @@
1
- import { defineConfig } from "vite";
2
- import { svelte } from "@sveltejs/vite-plugin-svelte";
3
-
4
- export default defineConfig({
5
- plugins: [svelte()],
6
- });