@vorplex/solid 0.0.8 → 0.0.11

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.
@@ -0,0 +1,6 @@
1
+ import { type JSX } from 'solid-js';
2
+ export interface ForInProps<TKey extends string, TValue> {
3
+ each: Record<TKey, TValue>;
4
+ children: (value: TValue, key: TKey) => JSX.Element;
5
+ }
6
+ export declare function ForIn<T extends string, TT>(props: ForInProps<T, TT>): JSX.Element;
@@ -0,0 +1,4 @@
1
+ import { For } from 'solid-js';
2
+ export function ForIn(props) {
3
+ return (<For each={Object.entries(props.each)}>{([key, value]) => props.children(value, key)}</For>);
4
+ }
@@ -0,0 +1,140 @@
1
+ import type { JSX } from 'solid-js';
2
+ export type IconPack = {
3
+ Key: string;
4
+ Cube: string;
5
+ FileLines: string;
6
+ Download: string;
7
+ List: string;
8
+ MagnifyingGlassMinus: string;
9
+ MagnifyingGlassPlus: string;
10
+ Rocket: string;
11
+ RulerCombined: string;
12
+ Shapes: string;
13
+ Hand: string;
14
+ RightLeft: string;
15
+ Server: string;
16
+ Globe: string;
17
+ CalenderDays: string;
18
+ Error: string;
19
+ Warning: string;
20
+ AddressCard: string;
21
+ PuzzlePiece: string;
22
+ ObjectGroup: string;
23
+ Tv: string;
24
+ Code: string;
25
+ FileCode: string;
26
+ Cubes: string;
27
+ FolderPlus: string;
28
+ Foursquare: string;
29
+ LayerGroup: string;
30
+ OutlineCircleQuestion: string;
31
+ CircleQuestion: string;
32
+ CubesStacked: string;
33
+ Message: string;
34
+ CloudArrowUp: string;
35
+ ArrowUpRightFromSquare: string;
36
+ PenToSquare: string;
37
+ Sliders: string;
38
+ PaintBrush: string;
39
+ BarsStaggered: string;
40
+ FolderTree: string;
41
+ Star: string;
42
+ StarOutline: string;
43
+ CartPlus: string;
44
+ Equals: string;
45
+ Clock: string;
46
+ ListCheck: string;
47
+ Eye: string;
48
+ EyeSlash: string;
49
+ Comment: string;
50
+ ICursor: string;
51
+ SquareCaretDown: string;
52
+ SquareCaretUp: string;
53
+ Link: string;
54
+ LinkSlash: string;
55
+ SquarePen: string;
56
+ Clone: string;
57
+ Copy: string;
58
+ CodeBranch: string;
59
+ Stopwatch: string;
60
+ PlusCircle: string;
61
+ MinusCircle: string;
62
+ ClipboardList: string;
63
+ Expand: string;
64
+ Swatchbook: string;
65
+ Gears: string;
66
+ Computer: string;
67
+ HouseLaptop: string;
68
+ Desktop: string;
69
+ MagnifyingGlass: string;
70
+ ClipboardQuestion: string;
71
+ Pause: string;
72
+ CircleNodes: string;
73
+ FileCirclePlus: string;
74
+ ArrowRight: string;
75
+ ArrowRightToBracket: string;
76
+ PaperPlane: string;
77
+ Box: string;
78
+ Database: string;
79
+ Diagram: string;
80
+ Screen: string;
81
+ Move: string;
82
+ Circle: string;
83
+ OutlineCircle: string;
84
+ Check: string;
85
+ CheckCircle: string;
86
+ OutlineCheckCircle: string;
87
+ CheckSquare: string;
88
+ TimesCircle: string;
89
+ TimesSquare: string;
90
+ CaretDown: string;
91
+ ChevronDown: string;
92
+ ChevronRight: string;
93
+ ChevronUp: string;
94
+ CaretUp: string;
95
+ CaretRight: string;
96
+ Flag: string;
97
+ Trash: string;
98
+ Plus: string;
99
+ Spinner: string;
100
+ Folder: string;
101
+ File: string;
102
+ Times: string;
103
+ Minus: string;
104
+ MinusSquare: string;
105
+ Square: string;
106
+ Rectangle: string;
107
+ Refresh: string;
108
+ Info: string;
109
+ Bolt: string;
110
+ User: string;
111
+ Gear: string;
112
+ Stack: string;
113
+ Network: string;
114
+ Ellipsis: string;
115
+ History: string;
116
+ Boxes: string;
117
+ Bell: string;
118
+ Play: string;
119
+ Reset: string;
120
+ Test: string;
121
+ SignIn: string;
122
+ Home: string;
123
+ Settings: string;
124
+ Account: string;
125
+ Cursor: string;
126
+ Mouse: string;
127
+ Resize: string;
128
+ Terminal: string;
129
+ Font: string;
130
+ Button: string;
131
+ None: string;
132
+ };
133
+ export declare const IconPacks: {
134
+ FontAwesome: IconPack;
135
+ };
136
+ export declare const ActiveIconPack: IconPack;
137
+ export declare function Icon(props: {
138
+ icon: keyof IconPack;
139
+ class?: string;
140
+ } & JSX.HTMLAttributes<HTMLDivElement>): JSX.Element;
@@ -0,0 +1,159 @@
1
+ import { classNames } from '@vorplex/web';
2
+ import { createStyle } from '../../functions/create-style.function';
3
+ if (!document.querySelector('link[data-fontawesome-icons]')) {
4
+ const link = document.createElement('link');
5
+ link.setAttribute('data-fontawesome-icons', '');
6
+ link.href = 'https://unpkg.com/@fortawesome/fontawesome-free@6.1.1/css/all.min.css';
7
+ link.rel = 'stylesheet';
8
+ document.head.append(link);
9
+ }
10
+ export const IconPacks = {
11
+ // https://fontawesome.com/search?ic=free&o=r
12
+ FontAwesome: {
13
+ None: '',
14
+ Key: 'fas fa-fw fa-key',
15
+ Cube: 'fas fa-fw fa-cube',
16
+ FileLines: 'fas fa-fw fa-file-lines',
17
+ Download: 'fas fa-fw fa-download',
18
+ List: 'fas fa-fw fa-list',
19
+ MagnifyingGlassMinus: 'fas fa-fw fa-magnifying-glass-minus',
20
+ MagnifyingGlassPlus: 'fas fa-fw fa-magnifying-glass-plus',
21
+ Rocket: 'fas fa-fw fa-rocket',
22
+ RulerCombined: 'fas fa-fw fa-ruler-combined',
23
+ Shapes: 'fas fa-fw fa-shapes',
24
+ Hand: 'fas fa-fw fa-hand',
25
+ RightLeft: 'fas fa-fw fa-right-left',
26
+ Server: 'fas fa-fw fa-server',
27
+ Globe: 'fas fa-fw fa-globe',
28
+ CalenderDays: 'fas fa-fw fa-calendar-days',
29
+ Error: 'fas fa-fw fa-circle-exclamation',
30
+ Warning: 'fas fa-fw fa-triangle-exclamation',
31
+ AddressCard: 'fas fa-fw fa-address-card',
32
+ PuzzlePiece: 'fas fa-fw fa-puzzle-piece',
33
+ ObjectGroup: 'fas fa-fw fa-object-group',
34
+ Code: 'fas fa-fw fa-code',
35
+ FileCode: 'fas fa-fw fa-file-code',
36
+ Tv: 'fas fa-fw fa-tv',
37
+ Cubes: 'fas fa-fw fa-cube',
38
+ FolderPlus: 'fas fa-folder-plus',
39
+ Foursquare: 'fa-brands fa-foursquare',
40
+ LayerGroup: 'fas fa-layer-group',
41
+ OutlineCircleQuestion: 'fa-regular fa-circle-question',
42
+ CircleQuestion: 'fas fa-circle-question',
43
+ CubesStacked: 'fas fa-cubes-stacked',
44
+ Message: 'fas fa-message',
45
+ CloudArrowUp: 'fas fa-cloud-arrow-up',
46
+ ArrowUpRightFromSquare: 'fas fa-arrow-up-right-from-square',
47
+ PenToSquare: 'fas fa-pen-to-square',
48
+ Sliders: 'fas fa-sliders',
49
+ PaintBrush: 'fas fa-paint-brush',
50
+ BarsStaggered: 'fas fa-bars-staggered',
51
+ FolderTree: 'fas fa-folder-tree',
52
+ Star: 'fa-fw fas fa-star',
53
+ StarOutline: 'fa-fw far fa-star',
54
+ CartPlus: 'fa-fw fas fa-cart-plus',
55
+ Equals: 'fa-fw fas fa-equals',
56
+ Clock: 'fa-fw fas fa-clock',
57
+ ListCheck: 'fa-fw fas fa-list-check',
58
+ Eye: 'fa-fw fas fa-eye',
59
+ EyeSlash: 'fa-fw fas fa-eye-slash',
60
+ Comment: 'fa-fw fas fa-comment',
61
+ ICursor: 'fa-fw fas fa-i-cursor',
62
+ SquareCaretDown: 'fa-fw fas fa-square-caret-down',
63
+ SquareCaretUp: 'fa-fw fas fa-square-caret-up',
64
+ Link: 'fa-fw fas fa-link',
65
+ LinkSlash: 'fa-fw fas fa-link-slash',
66
+ SquarePen: 'fa-fw fas fa-square-pen',
67
+ Clone: 'fa-fw fas fa-clone',
68
+ Copy: 'fa-fw fas fa-copy',
69
+ CodeBranch: 'fa-fw fas fa-code-branch',
70
+ Stopwatch: 'fa-fw fas fa-stopwatch',
71
+ PlusCircle: 'fa-fw fas fa-plus-circle',
72
+ MinusCircle: 'fa-fw fas fa-minus-circle',
73
+ ClipboardList: 'fa-fw fas fa-clipboard-list',
74
+ Expand: 'fa-fw fas fa-expand',
75
+ Swatchbook: 'fa-fw fas fa-swatchbook',
76
+ Gears: 'fw-fw fas fa-gears',
77
+ Computer: 'fa-fw fas fa-computer',
78
+ HouseLaptop: 'fa-fw fas fa-house-laptop',
79
+ Desktop: 'fa-fw fas fa-desktop',
80
+ MagnifyingGlass: 'fa-fw fas fa-magnifying-glass',
81
+ ClipboardQuestion: 'fa-fw fas fa-clipboard-question',
82
+ Pause: 'fa-fw fas fa-pause',
83
+ CircleNodes: 'fa-fw fas fa-circle-nodes',
84
+ FileCirclePlus: 'fa-fw fas fa-file-circle-plus',
85
+ ArrowRight: 'fa-fw fas fa-arrow-right',
86
+ ArrowRightToBracket: 'fa-fw fas fa-arrow-right-to-bracket',
87
+ PaperPlane: 'fa-fw fas fa-paper-plane',
88
+ Box: 'fa-fw fas fa-archive',
89
+ Database: 'fa-fw fas fa-database',
90
+ Diagram: 'fa-fw fas fa-project-diagram',
91
+ Screen: 'fa-fw fas fa-desktop',
92
+ Move: 'fa-fw fas fa-arrows-alt',
93
+ Circle: 'fa-fw fas fa-circle',
94
+ OutlineCircle: 'fa-fw far fa-circle',
95
+ Check: 'fa-fw fas fa-check',
96
+ CheckCircle: 'fa-fw fas fa-check-circle',
97
+ OutlineCheckCircle: 'fa-fw fa-regular fa-check-circle',
98
+ CheckSquare: 'fa-fw fas fa-check-square',
99
+ TimesCircle: 'fa-fw fas fa-times-circle',
100
+ TimesSquare: 'fa-fw fas fa-square-xmark',
101
+ CaretDown: 'fa-fw fas fa-caret-down',
102
+ ChevronDown: 'fa-fw fas fa-chevron-down',
103
+ ChevronRight: 'fa-fw fas fa-chevron-right',
104
+ ChevronUp: 'fa-fw fas fa-chevron-up',
105
+ CaretUp: 'fa-fw fas fa-caret-up',
106
+ CaretRight: 'fa-fw fas fa-caret-right',
107
+ Flag: 'fa-fw fas fa-flag',
108
+ Trash: 'fa-fw fas fa-trash',
109
+ Plus: 'fa-fw fas fa-plus',
110
+ Spinner: 'fa-fw fas fa-circle-notch fa-spin',
111
+ Folder: 'fa-fw fas fa-folder',
112
+ File: 'fa-fw fas fa-file',
113
+ Times: 'fa-fw fas fa-times',
114
+ Minus: 'fa-fw fas fa-minus',
115
+ MinusSquare: 'fa-fw fas fa-square-minus',
116
+ Square: 'fa-fw far fa-square',
117
+ Rectangle: 'fa-fw far fa-square',
118
+ Refresh: 'fa-fw fas fa-sync',
119
+ Info: 'fa-fw fas fa-info-circle',
120
+ Bolt: 'fa-fw fas fa-bolt',
121
+ User: 'fa-fw fas fa-user',
122
+ Gear: 'fa-fw fas fa-cog',
123
+ Stack: 'fa-fw fas fa-layer-group',
124
+ Network: 'fa-fw fas fa-network-wired',
125
+ Ellipsis: 'fa-fw fas fa-ellipsis-h',
126
+ History: 'fa-fw fas fa-history',
127
+ Boxes: 'fa-fw fas fa-boxes',
128
+ Bell: 'fa-fw fas fa-bell',
129
+ Play: 'fa-fw fas fa-play',
130
+ Reset: 'fa-fw fas fa-eraser',
131
+ Test: 'fa-fw fas fa-flask',
132
+ SignIn: 'fa-fw fas fa-sign-in-alt',
133
+ Home: 'fa-fw fas fa-home',
134
+ Settings: 'fa-fw fas fa-cog',
135
+ Account: 'fa-fw fas fa-user-circle',
136
+ Cursor: 'fa-fw fas fa-mouse-pointer',
137
+ Mouse: 'fa-fw fas fa-mouse',
138
+ Resize: 'fa-fw fas fa-expand-arrows-alt',
139
+ Terminal: 'fa-fw fas fa-terminal',
140
+ Font: 'fa-fw fas fa-font',
141
+ Button: 'fa-fw fas fa-ad',
142
+ },
143
+ };
144
+ export const ActiveIconPack = IconPacks.FontAwesome;
145
+ const classes = createStyle(() => ({
146
+ icon: {
147
+ display: 'inline-grid',
148
+ justifyContent: 'center',
149
+ alignContent: 'center',
150
+ boxSizing: 'content-box',
151
+ minWidth: '1.25em',
152
+ minHeight: '1.25em',
153
+ },
154
+ }));
155
+ export function Icon(props) {
156
+ return (<div {...props} class={classNames(classes().icon, props.class)}>
157
+ <i class={ActiveIconPack[props.icon]}></i>
158
+ </div>);
159
+ }
@@ -0,0 +1,11 @@
1
+ import { Injector, type Instance, type Type } from '@vorplex/core';
2
+ import { type JSX } from 'solid-js';
3
+ export declare const InjectorContext: import("solid-js").Context<Injector>;
4
+ export declare function useInjector<T extends any[]>(map: T): {
5
+ [K in keyof T]: Instance<T[K]>;
6
+ };
7
+ export declare function useInjector<T extends Record<string, Type>>(map: T): Instance<T>;
8
+ export declare function InjectorComponent(props: {
9
+ inject?: (injector: Injector) => Injector;
10
+ children: JSX.Element | ((injector: Injector) => JSX.Element);
11
+ }): JSX.Element;
@@ -0,0 +1,17 @@
1
+ import { Injector } from '@vorplex/core';
2
+ import { createContext, useContext } from 'solid-js';
3
+ export const InjectorContext = createContext(new Injector());
4
+ export function useInjector(map) {
5
+ const injector = useContext(InjectorContext);
6
+ if (Array.isArray(map)) {
7
+ return map.map((type) => injector.get(type));
8
+ }
9
+ else {
10
+ return injector.map(map);
11
+ }
12
+ }
13
+ export function InjectorComponent(props) {
14
+ let injector = useContext(InjectorContext).scope();
15
+ injector = props.inject?.(injector) ?? useContext(InjectorContext).scope();
16
+ return (<InjectorContext.Provider value={injector}>{typeof props.children === 'function' ? props.children(injector) : props.children}</InjectorContext.Provider>);
17
+ }
@@ -0,0 +1,6 @@
1
+ import { JSX } from 'solid-js/jsx-runtime';
2
+ export declare const ShadowDomContext: import("solid-js").Context<ShadowRoot>;
3
+ export declare function ShadowDomComponent(props: {
4
+ ref?: (root: ShadowRoot) => void;
5
+ children: JSX.Element;
6
+ }): JSX.Element;
@@ -0,0 +1,13 @@
1
+ import { createContext, onCleanup, onMount } from 'solid-js';
2
+ import { render } from 'solid-js/web';
3
+ export const ShadowDomContext = createContext();
4
+ export function ShadowDomComponent(props) {
5
+ let ref;
6
+ onMount(() => {
7
+ const root = ref.attachShadow({ mode: 'open' });
8
+ const dispose = render(() => <ShadowDomContext.Provider value={root}>{props.children}</ShadowDomContext.Provider>, root);
9
+ props.ref?.(root);
10
+ onCleanup(() => dispose?.());
11
+ });
12
+ return <div ref={ref} style={{ display: 'contents' }}/>;
13
+ }
@@ -0,0 +1,6 @@
1
+ import { State } from '@vorplex/core';
2
+ import { type Accessor } from 'solid-js';
3
+ export declare function useState<TState, TValue = TState>(state: State<TState>, select?: (state: TState) => TValue): Accessor<TValue>;
4
+ export declare function useState<T extends any[], TValue>(state: {
5
+ [K in keyof T]: State<T[K]>;
6
+ }, select?: (state: T) => TValue): Accessor<TValue>;
@@ -0,0 +1,29 @@
1
+ import { $Value, State } from '@vorplex/core';
2
+ import { createMemo, createSignal, onCleanup } from 'solid-js';
3
+ export function useState(state, select) {
4
+ const [get, set] = createSignal();
5
+ createMemo(() => {
6
+ let current = null;
7
+ const subscription = State.combineLatest(Array.isArray(state) ? state : [state], (action) => {
8
+ try {
9
+ let value = Array.isArray(state) ? action : action[0];
10
+ if (select)
11
+ value = select(value);
12
+ if (!$Value.equals(current, value)) {
13
+ current = value;
14
+ set(value);
15
+ }
16
+ }
17
+ catch (error) {
18
+ set(error instanceof Error ? error : new Error(error));
19
+ }
20
+ });
21
+ onCleanup(() => subscription.unsubscribe());
22
+ });
23
+ return () => {
24
+ const value = get();
25
+ if (value instanceof Error)
26
+ throw value;
27
+ return value;
28
+ };
29
+ }
@@ -0,0 +1,2 @@
1
+ import { Subscribable } from '@vorplex/core';
2
+ export declare function useSubscription<T>(subscribable: Subscribable<T>, defaultValue?: T): import("solid-js").Accessor<T>;
@@ -0,0 +1,8 @@
1
+ import { createSignal, onCleanup, onMount } from 'solid-js';
2
+ export function useSubscription(subscribable, defaultValue) {
3
+ const [value, setValue] = createSignal(defaultValue, { equals: false });
4
+ let subscription;
5
+ onMount(() => subscription = subscribable.subscribe(change => setValue(() => change)));
6
+ onCleanup(() => subscription?.unsubscribe());
7
+ return value;
8
+ }
@@ -0,0 +1,11 @@
1
+ import type { Point } from '@vorplex/core';
2
+ import { type JSXElement } from 'solid-js';
3
+ import { type Portal } from './create-portal.function';
4
+ export type PopupOptions = {
5
+ location: Point;
6
+ ghost?: boolean;
7
+ autoTransform?: boolean;
8
+ render: (menu: Portal) => JSXElement;
9
+ onDestroy?: () => void;
10
+ };
11
+ export declare function createPopup(options: PopupOptions): Portal;
@@ -0,0 +1,42 @@
1
+ import { onCleanup, onMount } from 'solid-js';
2
+ import { createPortal } from './create-portal.function';
3
+ import { $Element } from '@vorplex/web';
4
+ export function createPopup(options) {
5
+ const portal = createPortal({
6
+ render: (portal) => {
7
+ onMount(() => {
8
+ const dispose = $Element.addEventListener(document, 'keyup', event => {
9
+ if (event.code === 'Escape')
10
+ portal.destroy();
11
+ });
12
+ onCleanup(() => dispose());
13
+ });
14
+ return (<div style={{
15
+ position: 'fixed',
16
+ top: '0px',
17
+ left: '0px',
18
+ border: 'none',
19
+ width: '100vw',
20
+ height: '100vh',
21
+ 'pointer-events': options.ghost ? 'none' : 'initial',
22
+ }} onPointerUp={(event) => {
23
+ if (options.ghost)
24
+ return;
25
+ if (event.currentTarget !== event.target)
26
+ return;
27
+ portal.destroy();
28
+ }}>
29
+ <div style={{
30
+ position: 'fixed',
31
+ top: `${options.location.y}px`,
32
+ left: `${options.location.x}px`,
33
+ transform: options.autoTransform ? `translate(${options.location.x > window.innerWidth / 2 ? '-100%' : '0%'}, ${options.location.y > window.innerHeight / 2 ? '-100%' : '0%'})` : undefined
34
+ }}>
35
+ {options.render(portal)}
36
+ </div>
37
+ </div>);
38
+ },
39
+ onDestroy: options.onDestroy
40
+ });
41
+ return portal;
42
+ }
@@ -0,0 +1,10 @@
1
+ import { type JSX } from 'solid-js';
2
+ export type Portal = {
3
+ container: HTMLDivElement;
4
+ destroy: () => void;
5
+ };
6
+ export interface PortalOptions {
7
+ render: (portal: Portal) => JSX.Element;
8
+ onDestroy?: () => void;
9
+ }
10
+ export declare function createPortal(options: PortalOptions): Portal;
@@ -0,0 +1,37 @@
1
+ import { createMemo } from 'solid-js';
2
+ import { render } from 'solid-js/web';
3
+ import { createStyle } from './create-style.function';
4
+ const classes = createStyle(() => ({
5
+ container: {
6
+ position: 'fixed',
7
+ left: '0px',
8
+ top: '0px',
9
+ width: '100vw',
10
+ height: '100vh',
11
+ overflow: 'hidden',
12
+ pointerEvents: 'none',
13
+ '& > *': {
14
+ pointerEvents: 'initial',
15
+ },
16
+ },
17
+ }));
18
+ export function createPortal(options) {
19
+ const container = document.createElement('div');
20
+ container.style.zIndex = '1';
21
+ createMemo(() => container.className = classes().container);
22
+ document.body.appendChild(container);
23
+ let disposed = false;
24
+ const portal = {
25
+ container,
26
+ destroy: () => {
27
+ if (dispose)
28
+ dispose();
29
+ else
30
+ disposed = true;
31
+ container.remove();
32
+ options.onDestroy?.();
33
+ },
34
+ };
35
+ const dispose = disposed ? () => { } : render(() => options.render(portal), container);
36
+ return portal;
37
+ }
@@ -0,0 +1,3 @@
1
+ import { Accessor } from 'solid-js';
2
+ import { type StyleClasses, type StyleNames } from '../utils/style-sheet.util';
3
+ export declare function createStyle<T extends object>(styles: () => StyleClasses<T>, container?: Node): Accessor<StyleNames<T>>;
@@ -0,0 +1,7 @@
1
+ import { onCleanup } from 'solid-js';
2
+ import { $StyleSheet } from '../utils/style-sheet.util';
3
+ export function createStyle(styles, container) {
4
+ const style = $StyleSheet.create(styles, container);
5
+ onCleanup(() => style().element.remove());
6
+ return () => style().classes;
7
+ }
@@ -0,0 +1,2 @@
1
+ import { Signal } from 'solid-js';
2
+ export declare function useCachedSignal<T>(cacheKey: string, value?: T): Signal<T>;
@@ -0,0 +1,12 @@
1
+ import { createSignal } from 'solid-js';
2
+ const SignalCache = {};
3
+ export function useCachedSignal(cacheKey, value) {
4
+ const [get, set] = createSignal(SignalCache[cacheKey] ?? value);
5
+ return [
6
+ get,
7
+ ((value) => {
8
+ SignalCache[cacheKey] = value;
9
+ set(value);
10
+ })
11
+ ];
12
+ }
@@ -0,0 +1,11 @@
1
+ export * from './effects/use-state.effect';
2
+ export * from './effects/use-subscription';
3
+ export * from './utils/style-sheet.util';
4
+ export * from './components/for-in/for-in.component';
5
+ export * from './components/icon/icons.component';
6
+ export * from './components/injector/injector.component';
7
+ export * from './components/shadow-dom/shadow-dom.component';
8
+ export * from './functions/create-popup.function';
9
+ export * from './functions/create-portal.function';
10
+ export * from './functions/create-style.function';
11
+ export * from './functions/use-cached-signal.function';
package/dist/index.js ADDED
@@ -0,0 +1,13 @@
1
+ // **/*.ts
2
+ export * from './effects/use-state.effect';
3
+ export * from './effects/use-subscription';
4
+ export * from './utils/style-sheet.util';
5
+ // **/*.tsx
6
+ export * from './components/for-in/for-in.component';
7
+ export * from './components/icon/icons.component';
8
+ export * from './components/injector/injector.component';
9
+ export * from './components/shadow-dom/shadow-dom.component';
10
+ export * from './functions/create-popup.function';
11
+ export * from './functions/create-portal.function';
12
+ export * from './functions/create-style.function';
13
+ export * from './functions/use-cached-signal.function';
@@ -0,0 +1,40 @@
1
+ import { type CamelToKebab, type Update } from '@vorplex/core';
2
+ import { Accessor, type JSX } from 'solid-js';
3
+ export type StyleNames<T> = {
4
+ [name in keyof T]: string;
5
+ };
6
+ export type StyleClass = CssProperties | {
7
+ [property: string]: StyleClass;
8
+ };
9
+ export type StyleClasses<T extends object = any> = {
10
+ [name in keyof T]: StyleClass;
11
+ };
12
+ export type StyleSheet = {
13
+ element: HTMLStyleElement;
14
+ css: string;
15
+ };
16
+ export type ClassStyleSheet<T extends object> = StyleSheet & {
17
+ classes: StyleNames<T>;
18
+ value: StyleClasses<T>;
19
+ };
20
+ export type AnimationStyleSheet = StyleSheet & {
21
+ name: string;
22
+ };
23
+ export type CssProperties = {
24
+ [key in keyof JSX.CSSProperties as CamelToKebab<key>]: JSX.CSSProperties[key] | CssProperties;
25
+ };
26
+ export declare class $StyleSheet {
27
+ private constructor();
28
+ static parseClass(selector: string, properties: CssProperties): string;
29
+ static parseAnimation(name: string, animation: Record<string, CssProperties>): string;
30
+ static parse<T extends {
31
+ [rule: string]: CssProperties;
32
+ }>(style: T, classNames?: StyleNames<T>): {
33
+ classes: StyleNames<T>;
34
+ css: string;
35
+ };
36
+ static create<T extends object>(styles: () => StyleClasses<T>, container?: Node): Accessor<ClassStyleSheet<T>>;
37
+ static createAnimation(animation: Record<string, CssProperties>): AnimationStyleSheet;
38
+ static update<T extends object>(style: ClassStyleSheet<T>, changes?: Update<StyleClasses<T>>): ClassStyleSheet<T>;
39
+ static updateSheet<T extends object>(element: HTMLStyleElement, styles: StyleClasses<T>): ClassStyleSheet<T>;
40
+ }
@@ -0,0 +1,101 @@
1
+ import { $Id, $String, $Value, State } from '@vorplex/core';
2
+ import { createMemo, onCleanup } from 'solid-js';
3
+ export class $StyleSheet {
4
+ constructor() { }
5
+ static parseClass(selector, properties) {
6
+ let css = `${selector} {\n`;
7
+ let suffix = '';
8
+ for (const rule in properties) {
9
+ const value = properties[rule];
10
+ if (typeof value === 'string') {
11
+ css += `\t${$String.kebabCase(rule)}: ${value};\n`;
12
+ }
13
+ else {
14
+ for (const childSelector of rule.split(',')) {
15
+ suffix += $StyleSheet.parseClass(childSelector.trim().split('&').join(selector), value);
16
+ }
17
+ }
18
+ }
19
+ css += `}`;
20
+ return `${css}\n${suffix}\n`;
21
+ }
22
+ static parseAnimation(name, animation) {
23
+ let css = `@keyframes ${name} {\n`;
24
+ for (const state in animation) {
25
+ css += `${state} {\n`;
26
+ for (const rule in animation[state]) {
27
+ const value = animation[state][rule];
28
+ css += `\t${$String.kebabCase(rule)}: ${value};\n`;
29
+ }
30
+ css += `}\n`;
31
+ }
32
+ css += '}\n';
33
+ return css;
34
+ }
35
+ static parse(style, classNames) {
36
+ const classes = classNames ?? {};
37
+ let css = '';
38
+ for (const name in style) {
39
+ if (name === '_') {
40
+ for (const key in style[name]) {
41
+ css += $StyleSheet.parseClass(key, style[name][key]);
42
+ }
43
+ }
44
+ else {
45
+ classes[name] = classes[name] ?? `${name}-${$Id.uid()}`;
46
+ css += $StyleSheet.parseClass(`.${classes[name]}`, style[name]);
47
+ }
48
+ }
49
+ return {
50
+ classes,
51
+ css,
52
+ };
53
+ }
54
+ static create(styles, container) {
55
+ container ??= document.head;
56
+ const sheet = document.createElement('style');
57
+ sheet.toggleAttribute('style-classes');
58
+ container.appendChild(sheet);
59
+ onCleanup(() => sheet.remove());
60
+ return createMemo(() => $StyleSheet.updateSheet(sheet, styles()));
61
+ }
62
+ static createAnimation(animation) {
63
+ const element = document.createElement('style');
64
+ element.toggleAttribute('animation');
65
+ document.head.appendChild(element);
66
+ const name = `anim-${$Id.uid()}`;
67
+ const css = $StyleSheet.parseAnimation(name, animation);
68
+ element.innerHTML = css;
69
+ return {
70
+ element,
71
+ css,
72
+ name,
73
+ };
74
+ }
75
+ static update(style, changes = {}) {
76
+ changes = State.update(style.value, changes);
77
+ if ($Value.equals(style.value, changes))
78
+ return style;
79
+ const { classes, css } = $StyleSheet.parse(changes, style.classes);
80
+ style.element.innerHTML = css;
81
+ style.value = changes;
82
+ return {
83
+ element: style.element,
84
+ css,
85
+ classes: classes,
86
+ value: style.value,
87
+ };
88
+ }
89
+ static updateSheet(element, styles) {
90
+ const { classes, css } = $StyleSheet.parse(styles);
91
+ if (element.innerHTML !== css) {
92
+ element.innerHTML = css;
93
+ }
94
+ return {
95
+ element: element,
96
+ css,
97
+ classes,
98
+ value: styles,
99
+ };
100
+ }
101
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vorplex/solid",
3
- "version": "0.0.8",
3
+ "version": "0.0.11",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "files": [
@@ -16,8 +16,8 @@
16
16
  "main": "./dist/index.js",
17
17
  "dependencies": {
18
18
  "tslib": "^2.8.1",
19
- "@vorplex/web": "0.0.8",
20
- "@vorplex/core": "0.0.8"
19
+ "@vorplex/core": "0.0.11",
20
+ "@vorplex/web": "0.0.11"
21
21
  },
22
22
  "devDependencies": {
23
23
  "@types/jest": "^29.5.2",