@vorplex/solid 0.0.11 → 0.0.20

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.
@@ -2,5 +2,6 @@ import { type JSX } from 'solid-js';
2
2
  export interface ForInProps<TKey extends string, TValue> {
3
3
  each: Record<TKey, TValue>;
4
4
  children: (value: TValue, key: TKey) => JSX.Element;
5
+ fallback?: JSX.Element;
5
6
  }
6
- export declare function ForIn<T extends string, TT>(props: ForInProps<T, TT>): JSX.Element;
7
+ export declare function ForIn<TKey extends string, TValue>(props: ForInProps<TKey, TValue>): JSX.Element;
@@ -1,4 +1,6 @@
1
1
  import { For } from 'solid-js';
2
2
  export function ForIn(props) {
3
- return (<For each={Object.entries(props.each)}>{([key, value]) => props.children(value, key)}</For>);
3
+ return (<For each={Object.entries(props.each)} fallback={props.fallback}>
4
+ {([key, value]) => props.children(value, key)}
5
+ </For>);
4
6
  }
@@ -1,3 +1,4 @@
1
1
  import { Accessor } from 'solid-js';
2
- import { type StyleClasses, type StyleNames } from '../utils/style-sheet.util';
2
+ import { CssProperties, type StyleClasses, type StyleNames } from '../utils/style-sheet.util';
3
3
  export declare function createStyle<T extends object>(styles: () => StyleClasses<T>, container?: Node): Accessor<StyleNames<T>>;
4
+ export declare function createAnimation<T extends object>(styles: () => Record<string, CssProperties>, container?: Node): Accessor<string>;
@@ -1,7 +1,18 @@
1
- import { onCleanup } from 'solid-js';
1
+ import { createEffect, onCleanup } from 'solid-js';
2
2
  import { $StyleSheet } from '../utils/style-sheet.util';
3
3
  export function createStyle(styles, container) {
4
- const style = $StyleSheet.create(styles, container);
5
- onCleanup(() => style().element.remove());
4
+ const style = $StyleSheet.create(styles);
5
+ const element = document.createElement('style');
6
+ (container ?? document.head).appendChild(element);
7
+ createEffect(() => element.innerText = style().css);
8
+ onCleanup(() => element.remove());
6
9
  return () => style().classes;
7
10
  }
11
+ export function createAnimation(styles, container) {
12
+ const style = $StyleSheet.createAnimation(styles);
13
+ const element = document.createElement('style');
14
+ (container ?? document.head).appendChild(element);
15
+ createEffect(() => element.innerText = style().css);
16
+ onCleanup(() => element.remove());
17
+ return () => style().name;
18
+ }
@@ -3,26 +3,26 @@ import { Accessor, type JSX } from 'solid-js';
3
3
  export type StyleNames<T> = {
4
4
  [name in keyof T]: string;
5
5
  };
6
+ export type CssProperties = {
7
+ [key in keyof JSX.CSSProperties as CamelToKebab<key>]: JSX.CSSProperties[key] | CssProperties;
8
+ };
6
9
  export type StyleClass = CssProperties | {
7
10
  [property: string]: StyleClass;
8
11
  };
9
- export type StyleClasses<T extends object = any> = {
12
+ export type StyleClasses<T extends Record<string, any> = any> = {
10
13
  [name in keyof T]: StyleClass;
11
14
  };
12
- export type StyleSheet = {
13
- element: HTMLStyleElement;
15
+ export interface StyleSheet {
16
+ sheet: CSSStyleSheet;
14
17
  css: string;
15
- };
16
- export type ClassStyleSheet<T extends object> = StyleSheet & {
18
+ }
19
+ export interface ClassStyleSheet<T extends Record<string, any>> extends StyleSheet {
17
20
  classes: StyleNames<T>;
18
21
  value: StyleClasses<T>;
19
- };
20
- export type AnimationStyleSheet = StyleSheet & {
22
+ }
23
+ export interface AnimationStyleSheet extends StyleSheet {
21
24
  name: string;
22
- };
23
- export type CssProperties = {
24
- [key in keyof JSX.CSSProperties as CamelToKebab<key>]: JSX.CSSProperties[key] | CssProperties;
25
- };
25
+ }
26
26
  export declare class $StyleSheet {
27
27
  private constructor();
28
28
  static parseClass(selector: string, properties: CssProperties): string;
@@ -33,8 +33,7 @@ export declare class $StyleSheet {
33
33
  classes: StyleNames<T>;
34
34
  css: string;
35
35
  };
36
- static create<T extends object>(styles: () => StyleClasses<T>, container?: Node): Accessor<ClassStyleSheet<T>>;
37
- static createAnimation(animation: Record<string, CssProperties>): AnimationStyleSheet;
36
+ static create<T extends object>(styles: () => StyleClasses<T>): Accessor<ClassStyleSheet<T>>;
37
+ static createAnimation(animation: () => Record<string, CssProperties>): Accessor<AnimationStyleSheet>;
38
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
39
  }
@@ -1,5 +1,5 @@
1
1
  import { $Id, $String, $Value, State } from '@vorplex/core';
2
- import { createMemo, onCleanup } from 'solid-js';
2
+ import { createMemo } from 'solid-js';
3
3
  export class $StyleSheet {
4
4
  constructor() { }
5
5
  static parseClass(selector, properties) {
@@ -51,51 +51,45 @@ export class $StyleSheet {
51
51
  css,
52
52
  };
53
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()));
54
+ static create(styles) {
55
+ const sheet = new CSSStyleSheet();
56
+ return createMemo(() => {
57
+ const value = styles();
58
+ const { classes, css } = $StyleSheet.parse(value);
59
+ sheet.replaceSync(css);
60
+ return {
61
+ classes,
62
+ css,
63
+ sheet,
64
+ value
65
+ };
66
+ });
61
67
  }
62
68
  static createAnimation(animation) {
63
- const element = document.createElement('style');
64
- element.toggleAttribute('animation');
65
- document.head.appendChild(element);
69
+ const sheet = new CSSStyleSheet();
66
70
  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
- };
71
+ return createMemo(() => {
72
+ const css = $StyleSheet.parseAnimation(name, animation());
73
+ sheet.replaceSync(css);
74
+ return {
75
+ sheet,
76
+ css,
77
+ name
78
+ };
79
+ });
74
80
  }
75
81
  static update(style, changes = {}) {
76
82
  changes = State.update(style.value, changes);
77
83
  if ($Value.equals(style.value, changes))
78
84
  return style;
79
85
  const { classes, css } = $StyleSheet.parse(changes, style.classes);
80
- style.element.innerHTML = css;
86
+ style.sheet.replaceSync(css);
81
87
  style.value = changes;
82
88
  return {
83
- element: style.element,
89
+ sheet: style.sheet,
84
90
  css,
85
91
  classes: classes,
86
92
  value: style.value,
87
93
  };
88
94
  }
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
95
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vorplex/solid",
3
- "version": "0.0.11",
3
+ "version": "0.0.20",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "files": [
@@ -15,20 +15,18 @@
15
15
  "types": "./dist/index.d.ts",
16
16
  "main": "./dist/index.js",
17
17
  "dependencies": {
18
- "tslib": "^2.8.1",
19
- "@vorplex/core": "0.0.11",
20
- "@vorplex/web": "0.0.11"
18
+ "@vorplex/core": "0.0.20",
19
+ "@vorplex/web": "0.0.20",
20
+ "tslib": "2.8.1"
21
21
  },
22
22
  "devDependencies": {
23
- "@types/jest": "^29.5.2",
24
- "jest": "^29.5.0",
25
- "ts-jest": "^29.1.0"
23
+ "vitest": "3.2.4"
26
24
  },
27
25
  "peerDependencies": {
28
26
  "solid-js": "*"
29
27
  },
30
28
  "scripts": {
31
29
  "build": "tsc -b --force tsconfig.build.json",
32
- "test": "jest"
30
+ "test": "vitest run"
33
31
  }
34
32
  }