fullstacked 0.12.2-1421 → 0.12.2-1425

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.
@@ -39,6 +39,9 @@ declare module "style" {
39
39
  | {
40
40
  [child: string]: CSSProperties;
41
41
  };
42
+ export type CSSAnimationProperties = Partial<{
43
+ [key in `${number}%` | "from" | "to"]: CSSProperties;
44
+ }>;
42
45
  export declare const createClass: (
43
46
  name: string,
44
47
  cssProperties: CSSProperties,
@@ -46,9 +49,17 @@ declare module "style" {
46
49
  export declare const createGlobalStyle: (
47
50
  cssProperties: CSSProperties,
48
51
  ) => void;
52
+ export declare const createAnimation: (
53
+ name: string,
54
+ cssAnimationProperties: CSSAnimationProperties,
55
+ ) => string;
49
56
  declare const style: {
50
57
  createClass: (name: string, cssProperties: CSSProperties) => string;
51
58
  createGlobalStyle: (cssProperties: CSSProperties) => void;
59
+ createAnimation: (
60
+ name: string,
61
+ cssAnimationProperties: CSSAnimationProperties,
62
+ ) => string;
52
63
  };
53
64
  export default style;
54
65
  }
@@ -1,4 +1,8 @@
1
- import { propertiesDefaultingToPx, CSSProperties } from "../style";
1
+ import {
2
+ CSSAnimationProperties,
3
+ propertiesDefaultingToPx,
4
+ CSSProperties
5
+ } from "../style";
2
6
 
3
7
  const propertiesDefaultingToPxArr = Object.keys(propertiesDefaultingToPx);
4
8
  const allCSSProperties = [];
@@ -10,10 +14,18 @@ type StyleItem = {
10
14
  element: HTMLElement;
11
15
  order: number;
12
16
  children: StyleTree;
17
+ type: "style";
13
18
  };
14
19
 
15
20
  type StyleTree = {
16
- [name: string]: StyleItem;
21
+ [name: string]: StyleItem | AnimationItem;
22
+ };
23
+
24
+ type AnimationItem = {
25
+ element: null;
26
+ order: number;
27
+ children: StyleTree;
28
+ type: "animation";
17
29
  };
18
30
 
19
31
  const styles: StyleTree = {};
@@ -29,7 +41,8 @@ function getOrCreateParentFromPath(path: string[], parent = styles): StyleTree {
29
41
  parent[child] = {
30
42
  element: document.createElement("div"),
31
43
  order: order++,
32
- children: {}
44
+ children: {},
45
+ type: "style"
33
46
  };
34
47
  }
35
48
 
@@ -40,15 +53,20 @@ function createStyle(
40
53
  cssProperties: CSSProperties,
41
54
  path: string[],
42
55
  existing: StyleItem
43
- ): StyleItem {
56
+ ) {
44
57
  const styleItem = existing || {
45
58
  element: document.createElement("div"),
46
59
  order: order++,
47
- children: {}
60
+ children: {},
61
+ type: "style"
48
62
  };
49
63
 
50
64
  Object.entries(cssProperties).forEach(([property, value]) => {
51
- if (!allCSSProperties.includes(property)) {
65
+ if (
66
+ !allCSSProperties.includes(property) &&
67
+ !property.startsWith("Webkit") &&
68
+ !property.startsWith("Moz")
69
+ ) {
52
70
  if (property.startsWith("@media")) {
53
71
  const parentPath = [property, ...path];
54
72
  _createClass(
@@ -80,7 +98,11 @@ function _createClass(
80
98
  cssProperties: CSSProperties,
81
99
  parent = styles
82
100
  ) {
83
- parent[path.at(-1)] = createStyle(cssProperties, path, parent[path.at(-1)]);
101
+ parent[path.at(-1)] = createStyle(
102
+ cssProperties,
103
+ path,
104
+ parent[path.at(-1)] as StyleItem
105
+ );
84
106
  }
85
107
 
86
108
  export function createClass(name: string, cssProperties: CSSProperties) {
@@ -90,10 +112,30 @@ export function createClass(name: string, cssProperties: CSSProperties) {
90
112
 
91
113
  export function createGlobalStyle(globalCssProperties: CSSProperties) {
92
114
  Object.entries(globalCssProperties).forEach(([name, cssProperties]) => {
93
- styles[name] = createStyle(cssProperties, [name], styles[name]);
115
+ styles[name] = createStyle(
116
+ cssProperties,
117
+ [name],
118
+ styles[name] as StyleItem
119
+ );
94
120
  });
95
121
  }
96
122
 
123
+ export function createAnimation(
124
+ name: string,
125
+ cssAnimationProperties: CSSAnimationProperties
126
+ ) {
127
+ styles[name] = {
128
+ ...(createStyle(
129
+ cssAnimationProperties,
130
+ [name],
131
+ styles[name] as StyleItem
132
+ ) as any),
133
+ order: -1,
134
+ type: "animation"
135
+ };
136
+ return name;
137
+ }
138
+
97
139
  function constructClassName(path: string[]) {
98
140
  return path.reduce(
99
141
  (str, item) =>
@@ -106,6 +148,10 @@ function generateStyleRecusively(path: string[] = [], parent = styles) {
106
148
  return Object.entries(parent)
107
149
  .sort(([_, itemA], [__, itemB]) => itemA.order - itemB.order)
108
150
  .map(([tag, styleItem]) => {
151
+ if (styleItem.type === "animation") {
152
+ return `@keyframes ${tag} { ${generateStyleRecusively([], styleItem.children)} }`;
153
+ }
154
+
109
155
  let css = "";
110
156
 
111
157
  const currentPath = [...path, tag];
@@ -144,7 +190,8 @@ export function exportStyles() {
144
190
 
145
191
  const style = {
146
192
  createClass,
147
- createGlobalStyle
193
+ createGlobalStyle,
194
+ createAnimation
148
195
  };
149
196
 
150
197
  export default style;
@@ -48,13 +48,23 @@ export type CSSProperties =
48
48
  [child: string]: CSSProperties;
49
49
  };
50
50
 
51
+ export type CSSAnimationProperties = Partial<{
52
+ [key in `${number}%` | "from" | "to"]: CSSProperties;
53
+ }>;
54
+
51
55
  export const createClass = (name: string, cssProperties: CSSProperties) => name;
52
56
 
53
57
  export const createGlobalStyle = (cssProperties: CSSProperties) => {};
54
58
 
59
+ export const createAnimation = (
60
+ name: string,
61
+ cssAnimationProperties: CSSAnimationProperties
62
+ ) => name;
63
+
55
64
  const style = {
56
65
  createClass,
57
- createGlobalStyle
66
+ createGlobalStyle,
67
+ createAnimation
58
68
  };
59
69
 
60
70
  export default style;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fullstacked",
3
- "version": "0.12.2-1421",
3
+ "version": "0.12.2-1425",
4
4
  "scripts": {
5
5
  "build": "node build.js",
6
6
  "postbuild": "node build.js --binding",