@rokkit/ui 1.0.0-next.114 → 1.0.0-next.115
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.
- package/dist/index.d.ts +3 -0
- package/package.json +1 -1
- package/src/Card.svelte +41 -0
- package/src/Shine.svelte +79 -0
- package/src/Tilt.svelte +66 -0
- package/src/index.js +4 -0
package/dist/index.d.ts
CHANGED
|
@@ -40,3 +40,6 @@ export { default as DataEditor } from "./DataEditor.svelte";
|
|
|
40
40
|
export { default as NestedEditor } from "./NestedEditor.svelte";
|
|
41
41
|
export { default as Stepper } from "./Stepper.svelte";
|
|
42
42
|
export { default as ProgressDots } from "./ProgressDots.svelte";
|
|
43
|
+
export { default as Card } from "./Card.svelte";
|
|
44
|
+
export { default as Shine } from "./Shine.svelte";
|
|
45
|
+
export { default as Tilt } from "./Tilt.svelte";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rokkit/ui",
|
|
3
|
-
"version": "1.0.0-next.
|
|
3
|
+
"version": "1.0.0-next.115",
|
|
4
4
|
"description": "Organisms are larger, more complex building blocks that are composed of multiple molecules",
|
|
5
5
|
"author": "Jerry Thomas <me@jerrythomas.name>",
|
|
6
6
|
"license": "MIT",
|
package/src/Card.svelte
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { Proxy } from '@rokkit/states'
|
|
3
|
+
let { class: classNames = '', value = $bindable(), fields, child, onClick } = $props()
|
|
4
|
+
|
|
5
|
+
const proxy = $state(new Proxy(value, fields))
|
|
6
|
+
const childSnippet = $derived(child ?? defaultChild)
|
|
7
|
+
const href = $derived(proxy.get('href'))
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Handles enter key
|
|
11
|
+
* @param {KeyboardEvent} event
|
|
12
|
+
*/
|
|
13
|
+
function handleKeyUp(event) {
|
|
14
|
+
if (event.key === 'Enter') onClick?.()
|
|
15
|
+
}
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
{#snippet defaultChild(/** @type {Proxy}*/ proxy)}
|
|
19
|
+
<icon class="flex flex-col">
|
|
20
|
+
<i class={proxy.get('icon')}></i>
|
|
21
|
+
</icon>
|
|
22
|
+
<h1>{proxy.get('title')}</h1>
|
|
23
|
+
<h2>{proxy.get('description')}</h2>
|
|
24
|
+
{/snippet}
|
|
25
|
+
|
|
26
|
+
{#if href}
|
|
27
|
+
<a {href} data-card-root class={classNames}>
|
|
28
|
+
{@render childSnippet(proxy)}
|
|
29
|
+
</a>
|
|
30
|
+
{:else}
|
|
31
|
+
<div
|
|
32
|
+
data-card-root
|
|
33
|
+
onclick={onClick}
|
|
34
|
+
onkeyup={handleKeyUp}
|
|
35
|
+
role="button"
|
|
36
|
+
tabindex="-1"
|
|
37
|
+
class={classNames}
|
|
38
|
+
>
|
|
39
|
+
{@render childSnippet(proxy)}
|
|
40
|
+
</div>
|
|
41
|
+
{/if}
|
package/src/Shine.svelte
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { id } from '@rokkit/core'
|
|
3
|
+
// import { clsx } from 'clsx'
|
|
4
|
+
|
|
5
|
+
let {
|
|
6
|
+
color = 'var(--primary-500)',
|
|
7
|
+
radius = 300,
|
|
8
|
+
/** Depth of effect */
|
|
9
|
+
depth = 1,
|
|
10
|
+
/** Represents the height of the surface for a light filter primitive */
|
|
11
|
+
surfaceScale = 2,
|
|
12
|
+
/** The bigger the value the bigger the reflection */
|
|
13
|
+
specularConstant = 0.75,
|
|
14
|
+
/** controls the focus for the light source. The bigger the value the brighter the light */
|
|
15
|
+
specularExponent = 120,
|
|
16
|
+
children,
|
|
17
|
+
...restProps
|
|
18
|
+
} = $props()
|
|
19
|
+
|
|
20
|
+
const filterId = id('filter')
|
|
21
|
+
|
|
22
|
+
let mouse = $state({ x: 0, y: 0 })
|
|
23
|
+
let wrapperBox = $state({ left: 0, top: 0 })
|
|
24
|
+
/** @type {HTMLDivElement|null} */
|
|
25
|
+
let wrapperEl = null
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
*
|
|
29
|
+
* @param {PointerEvent} e
|
|
30
|
+
*/
|
|
31
|
+
function onPointerMove(e) {
|
|
32
|
+
wrapperBox = wrapperEl?.getBoundingClientRect() ?? { left: 0, top: 0 }
|
|
33
|
+
mouse = { x: e.clientX, y: e.clientY }
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function onScroll() {
|
|
37
|
+
wrapperBox = wrapperEl?.getBoundingClientRect() ?? { left: 0, top: 0 }
|
|
38
|
+
}
|
|
39
|
+
</script>
|
|
40
|
+
|
|
41
|
+
<svelte:window onpointermove={onPointerMove} onscroll={onScroll} />
|
|
42
|
+
|
|
43
|
+
<svg data-shine-filter class="pointer-events-none fixed inset-0">
|
|
44
|
+
<filter id={filterId} color-interpolation-filters="sRGB">
|
|
45
|
+
<feGaussianBlur in="SourceAlpha" stdDeviation={depth} />
|
|
46
|
+
|
|
47
|
+
<feSpecularLighting
|
|
48
|
+
result="light-source"
|
|
49
|
+
{surfaceScale}
|
|
50
|
+
{specularConstant}
|
|
51
|
+
{specularExponent}
|
|
52
|
+
lighting-color={color}
|
|
53
|
+
>
|
|
54
|
+
<fePointLight x={mouse.x - wrapperBox.left} y={mouse.y - wrapperBox.top} z={radius} />
|
|
55
|
+
</feSpecularLighting>
|
|
56
|
+
|
|
57
|
+
<feComposite result="reflections" in="light-source" in2="SourceAlpha" operator="in" />
|
|
58
|
+
|
|
59
|
+
<feComposite
|
|
60
|
+
in="SourceGraphic"
|
|
61
|
+
in2="reflections"
|
|
62
|
+
operator="arithmetic"
|
|
63
|
+
k1="0"
|
|
64
|
+
k2="1"
|
|
65
|
+
k3="1"
|
|
66
|
+
k4="0"
|
|
67
|
+
/>
|
|
68
|
+
</filter>
|
|
69
|
+
</svg>
|
|
70
|
+
|
|
71
|
+
<div
|
|
72
|
+
data-shine-root
|
|
73
|
+
style:filter="url(#{filterId})"
|
|
74
|
+
{...restProps}
|
|
75
|
+
class="inline-block"
|
|
76
|
+
bind:this={wrapperEl}
|
|
77
|
+
>
|
|
78
|
+
{@render children?.()}
|
|
79
|
+
</div>
|
package/src/Tilt.svelte
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { scaleLinear } from 'd3-scale'
|
|
3
|
+
import { clsx } from 'clsx'
|
|
4
|
+
|
|
5
|
+
let {
|
|
6
|
+
maxRotation = 10,
|
|
7
|
+
setBrightness = false,
|
|
8
|
+
perspective = 600,
|
|
9
|
+
class: classNames = undefined,
|
|
10
|
+
children
|
|
11
|
+
} = $props()
|
|
12
|
+
|
|
13
|
+
let width = $state(0)
|
|
14
|
+
let height = $state(0)
|
|
15
|
+
|
|
16
|
+
let rotateX = $state(0)
|
|
17
|
+
let rotateY = $state(0)
|
|
18
|
+
let brightness = $state(1)
|
|
19
|
+
|
|
20
|
+
let scaleX = $derived(scaleLinear().domain([0, height]).range([-maxRotation, maxRotation]))
|
|
21
|
+
let scaleY = $derived(scaleLinear().domain([0, width]).range([maxRotation, -maxRotation]))
|
|
22
|
+
let scaleBrightness = $derived(scaleLinear().domain([0, height]).range([2.0, 1.0]))
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
*
|
|
26
|
+
* @param {MouseEvent} e
|
|
27
|
+
*/
|
|
28
|
+
function onMouseMove(e) {
|
|
29
|
+
rotateY = scaleY(e.offsetX)
|
|
30
|
+
rotateX = scaleX(e.offsetY)
|
|
31
|
+
|
|
32
|
+
if (setBrightness) {
|
|
33
|
+
brightness = scaleBrightness(e.offsetY)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
*
|
|
39
|
+
*/
|
|
40
|
+
function onMouseLeave() {
|
|
41
|
+
rotateX = 0
|
|
42
|
+
rotateY = 0
|
|
43
|
+
brightness = 1
|
|
44
|
+
}
|
|
45
|
+
</script>
|
|
46
|
+
|
|
47
|
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
48
|
+
<div
|
|
49
|
+
data-tilt-root
|
|
50
|
+
style:--perspective="{perspective}px"
|
|
51
|
+
style:--rotateX="{rotateX}deg"
|
|
52
|
+
style:--rotateY="{rotateY}deg"
|
|
53
|
+
style:--brightness={brightness}
|
|
54
|
+
class={clsx(
|
|
55
|
+
'[perspective:var(--perspective)]',
|
|
56
|
+
'[&>*]:[transform:rotateX(var(--rotateX))_rotateY(var(--rotateY))]',
|
|
57
|
+
'[&>*]:brightness-[var(--brightness)]',
|
|
58
|
+
classNames
|
|
59
|
+
)}
|
|
60
|
+
bind:clientWidth={width}
|
|
61
|
+
bind:clientHeight={height}
|
|
62
|
+
onmousemove={onMouseMove}
|
|
63
|
+
onmouseleave={onMouseLeave}
|
|
64
|
+
>
|
|
65
|
+
{@render children?.()}
|
|
66
|
+
</div>
|
package/src/index.js
CHANGED
|
@@ -46,3 +46,7 @@ export { default as DataEditor } from './DataEditor.svelte'
|
|
|
46
46
|
export { default as NestedEditor } from './NestedEditor.svelte'
|
|
47
47
|
export { default as Stepper } from './Stepper.svelte'
|
|
48
48
|
export { default as ProgressDots } from './ProgressDots.svelte'
|
|
49
|
+
|
|
50
|
+
export { default as Card } from './Card.svelte'
|
|
51
|
+
export { default as Shine } from './Shine.svelte'
|
|
52
|
+
export { default as Tilt } from './Tilt.svelte'
|