@manyducks.co/dolla-styled 0.0.2 → 0.0.4
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.mjs +17 -16
- package/dist/styled.d.ts +20 -3
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -50,41 +50,42 @@ function h(e) {
|
|
|
50
50
|
}
|
|
51
51
|
var g = 0;
|
|
52
52
|
function _(i, a = {}) {
|
|
53
|
-
let o =
|
|
54
|
-
let
|
|
53
|
+
let { __name: o, ...s } = a, c = (a, ...c) => {
|
|
54
|
+
let l = h(a.join("||")), u = "", d = [];
|
|
55
55
|
return a.forEach((e, t) => {
|
|
56
|
-
if (
|
|
57
|
-
let e =
|
|
56
|
+
if (u += e, t < c.length) {
|
|
57
|
+
let e = c[t], n = "*", r = null;
|
|
58
58
|
if (Array.isArray(e) && ([e, n, r = null] = e), typeof e == "function") {
|
|
59
|
-
let i = `--${
|
|
60
|
-
r === null ?
|
|
59
|
+
let i = `--${l}-${t}`;
|
|
60
|
+
r === null ? u += `var(${i})` : (u += `var(${i}, ${r})`, n !== "*" && m.register(i, n, r)), d.push({
|
|
61
61
|
varName: i,
|
|
62
62
|
fn: e,
|
|
63
63
|
initialValue: r
|
|
64
64
|
});
|
|
65
|
-
} else
|
|
65
|
+
} else u += e;
|
|
66
66
|
}
|
|
67
|
-
}), f.insert(
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
}), f.insert(l, u), (a, c) => {
|
|
68
|
+
o && (c.name = o);
|
|
69
|
+
let u = [l];
|
|
70
|
+
if (d.length > 0) {
|
|
70
71
|
let e = `styled-inst-${(g++).toString(36)}`;
|
|
71
|
-
|
|
72
|
+
u.push(e);
|
|
72
73
|
let t = p.createInstanceRule(e);
|
|
73
|
-
n(
|
|
74
|
-
|
|
74
|
+
n(c, () => {
|
|
75
|
+
d.forEach(({ varName: e, fn: n, initialValue: r }) => {
|
|
75
76
|
let i = n(a);
|
|
76
77
|
i == null || i === r ? t.removeProperty(e) : t.setProperty(e, i);
|
|
77
78
|
});
|
|
78
79
|
});
|
|
79
80
|
}
|
|
80
81
|
return t(typeof i == "string" && a.as || i, {
|
|
81
|
-
...
|
|
82
|
+
...s,
|
|
82
83
|
...a,
|
|
83
|
-
class: e(() => [a.class && r(a.class), ...
|
|
84
|
+
class: e(() => [a.class && r(a.class), ...u])
|
|
84
85
|
});
|
|
85
86
|
};
|
|
86
87
|
};
|
|
87
|
-
return
|
|
88
|
+
return c.with = () => c, c.named = (e) => _(i, Object.assign({}, a, { __name: e })), c.defaults = (e) => _(i, Object.assign({}, a, e)), c;
|
|
88
89
|
}
|
|
89
90
|
var v = new Proxy(_, { get(e, t) {
|
|
90
91
|
return _(t);
|
package/dist/styled.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { type View } from "@manyducks.co/dolla";
|
|
2
|
+
export type CoreCSSSyntax = "*" | "<length>" | "<percentage>" | "<length-percentage>" | "<color>" | "<image>" | "<url>" | "<integer>" | "<number>" | "<angle>" | "<time>" | "<resolution>" | "<transform-function>" | "<transform-list>" | "<custom-ident>";
|
|
3
|
+
export type CSSSyntaxDescriptor = CoreCSSSyntax | (string & {});
|
|
4
|
+
export type InterpolationValue = string | number | null | undefined;
|
|
5
|
+
export type InterpolationFn<Props> = (props: Props) => InterpolationValue;
|
|
6
|
+
export type Interpolation<Props> = InterpolationValue | InterpolationFn<Props> | [InterpolationFn<Props>, CSSSyntaxDescriptor, InterpolationValue];
|
|
2
7
|
type StyledProps = {
|
|
3
8
|
as?: keyof JSX.IntrinsicElements | string;
|
|
4
9
|
};
|
|
@@ -8,18 +13,30 @@ type Flatten<T> = {
|
|
|
8
13
|
[K in keyof T]: T[K];
|
|
9
14
|
} & {};
|
|
10
15
|
interface TypedTemplateFn<Props> {
|
|
11
|
-
(strings: TemplateStringsArray, ...interpolations:
|
|
16
|
+
(strings: TemplateStringsArray, ...interpolations: Interpolation<Props>[]): StyledView<Props>;
|
|
17
|
+
/**
|
|
18
|
+
* Provides a name for the underlying view.
|
|
19
|
+
*/
|
|
20
|
+
named(name: string): TypedTemplateFn<Props>;
|
|
12
21
|
/**
|
|
13
22
|
* Provides default props that are passed to all instances unless overridden.
|
|
14
23
|
*/
|
|
15
|
-
defaults<D extends Partial<Props>>(defaultProps: D): (strings: TemplateStringsArray, ...interpolations:
|
|
24
|
+
defaults<D extends Partial<Props>>(defaultProps: D): (strings: TemplateStringsArray, ...interpolations: Interpolation<Props>[]) => StyledView<Flatten<ApplyDefaults<Props, D>>>;
|
|
16
25
|
}
|
|
17
26
|
interface TemplateFn<BaseProps = {}> {
|
|
18
|
-
(strings: TemplateStringsArray, ...interpolations:
|
|
27
|
+
(strings: TemplateStringsArray, ...interpolations: Interpolation<BaseProps>[]): StyledView<BaseProps>;
|
|
28
|
+
/**
|
|
29
|
+
* Provides a name for the underlying view.
|
|
30
|
+
*/
|
|
31
|
+
named(name: string): TemplateFn<BaseProps>;
|
|
19
32
|
/**
|
|
20
33
|
* Defines additional props the resulting view takes.
|
|
21
34
|
*/
|
|
22
35
|
with<T>(): TypedTemplateFn<BaseProps & T>;
|
|
36
|
+
/**
|
|
37
|
+
* Provides default props that are passed to all instances unless overridden.
|
|
38
|
+
*/
|
|
39
|
+
defaults<D extends Partial<BaseProps>>(defaultProps: D): (strings: TemplateStringsArray, ...interpolations: any[]) => StyledView<Flatten<ApplyDefaults<BaseProps, D>>>;
|
|
23
40
|
}
|
|
24
41
|
declare function createBuilder<Tag extends keyof JSX.IntrinsicElements>(tag: Tag, boundDefaults?: Partial<JSX.IntrinsicElements[Tag]>): TemplateFn<JSX.IntrinsicElements[Tag]>;
|
|
25
42
|
declare function createBuilder<Props>(view: View<Props>, boundDefaults?: Partial<Props>): TemplateFn<Props>;
|