@yak/solid 0.1.0 → 0.2.1
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/README.md +10 -4
- package/dist/context/baseContext.d.ts +0 -1
- package/dist/context/index.d.ts +0 -1
- package/dist/context/index.js +2 -1
- package/dist/context/index.js.map +1 -1
- package/dist/index.d.ts +15 -40
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +42 -55
- package/dist/internal.js +433 -107
- package/dist/internal.js.map +1 -1
- package/dist/isolated-source-eval/index.js +3 -1
- package/dist/isolated-source-eval/index.js.map +1 -1
- package/dist/isolated-source-eval/worker.js.map +1 -1
- package/dist/loaders/vite-plugin.d.ts +2 -7
- package/dist/loaders/vite-plugin.js +30 -13
- package/dist/loaders/vite-plugin.js.map +1 -1
- package/loaders/vite-plugin.ts +2 -2
- package/package.json +15 -14
- package/runtime/atoms.ts +5 -3
- package/runtime/cssLiteral.ts +59 -57
- package/runtime/cssProp.ts +0 -2
- package/runtime/internals/mergeClasses.ts +1 -0
- package/runtime/internals/mergeCssProp.ts +68 -40
- package/runtime/mocks/cssLiteral.ts +2 -4
- package/runtime/mocks/styled.ts +6 -2
- package/runtime/publicStyledApi.ts +19 -7
- package/runtime/styled.ts +806 -306
- package/runtime/__tests__/styled.test.tsx +0 -270
package/dist/internal.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Accessor } from "solid-js";
|
|
2
2
|
import { JSX } from "@solidjs/web";
|
|
3
3
|
import { YakThemeContext, YakThemeProvider, useTheme } from "@yak/solid/context";
|
|
4
|
-
|
|
5
4
|
//#region runtime/cssProp.d.ts
|
|
6
5
|
declare module "@solidjs/web" {
|
|
7
6
|
namespace JSX {
|
|
@@ -47,7 +46,7 @@ interface StyledFn {
|
|
|
47
46
|
* @example styled.svg`${Button}:hover & { fill: red; }` or styled(Button)`color: red;`
|
|
48
47
|
*/
|
|
49
48
|
interface YakComponent<T> extends AnyComponent<T> {
|
|
50
|
-
[yakComponentSymbol]: [unknown, unknown, unknown
|
|
49
|
+
[yakComponentSymbol]: readonly [unknown, unknown, unknown];
|
|
51
50
|
}
|
|
52
51
|
/**
|
|
53
52
|
* Styled component with attrs method for adding default props.
|
|
@@ -85,7 +84,7 @@ type AttrsMerged<TBaseProps, TIn extends object = {}> = Substitute<TBaseProps &
|
|
|
85
84
|
* Maps all HTML tag names to their corresponding styled component types with attributes support.
|
|
86
85
|
* Provides typed access to all standard HTML elements through the styled interface.
|
|
87
86
|
*/
|
|
88
|
-
type MappedHtmlTags = { [Tag in HtmlTags]: LiteralWithAttrs<JSX.IntrinsicElements[Tag]
|
|
87
|
+
type MappedHtmlTags = { [Tag in HtmlTags]: LiteralWithAttrs<JSX.IntrinsicElements[Tag]>; };
|
|
89
88
|
/**
|
|
90
89
|
* The attrs function allows adding additional props to a styled component.
|
|
91
90
|
* Props can be specified as an object or as a function that receives current props.
|
|
@@ -110,16 +109,16 @@ type CustomWebComponentTag = `${string}-${string}`;
|
|
|
110
109
|
* Utility type to efficiently remove properties from an object type.
|
|
111
110
|
* More performant than the built-in Omit type for large object types.
|
|
112
111
|
*/
|
|
113
|
-
type FastOmit<T extends object, U extends string | number | symbol> = { [K in keyof T as K extends U ? never : K]: T[K] };
|
|
112
|
+
type FastOmit<T extends object, U extends string | number | symbol> = { [K in keyof T as K extends U ? never : K]: T[K]; };
|
|
114
113
|
/**
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
* a real Set<string> also satisfies this interface.
|
|
114
|
+
* Collects the class names of one render. The runtime keeps them in one
|
|
115
|
+
* space-separated string (Classes in cssLiteral.ts, the only implementation):
|
|
116
|
+
* add() appends, has() and delete() let a runtime processor take a name back
|
|
117
|
+
* out. A Set would need a split and a join on every render for the same string.
|
|
120
118
|
*/
|
|
121
119
|
type ClassCollector = {
|
|
122
|
-
|
|
120
|
+
/** generated is false for an author string such as an atom; the server writer escapes those */
|
|
121
|
+
add(name: string, generated?: boolean): void;
|
|
123
122
|
has(name: string): boolean;
|
|
124
123
|
delete(name: string): void;
|
|
125
124
|
};
|
|
@@ -133,6 +132,14 @@ type ClassCollector = {
|
|
|
133
132
|
type RuntimeStyleProcessor<T> = ((props: T, classes: ClassCollector, style: StyleObject) => void) & {
|
|
134
133
|
$dynamic?: boolean;
|
|
135
134
|
};
|
|
135
|
+
/** A class-only processor ignores props and needs no style object. */
|
|
136
|
+
type StaticStyleProcessor = ((props: unknown, classes: ClassCollector, style?: StyleObject) => void) & {
|
|
137
|
+
$dynamic: false;
|
|
138
|
+
};
|
|
139
|
+
/** css() marks its output so styled() can select the static render path. */
|
|
140
|
+
type CompiledStyleProcessor<T> = StaticStyleProcessor | (RuntimeStyleProcessor<T> & {
|
|
141
|
+
$dynamic: true;
|
|
142
|
+
});
|
|
136
143
|
//#endregion
|
|
137
144
|
//#region runtime/atoms.d.ts
|
|
138
145
|
/**
|
|
@@ -178,17 +185,9 @@ declare const keyframes: <T extends (string | number | bigint)[] = never>(styles
|
|
|
178
185
|
//#endregion
|
|
179
186
|
//#region runtime/styled.d.ts
|
|
180
187
|
/**
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
184
|
-
* @usage
|
|
185
|
-
*
|
|
186
|
-
* ```tsx
|
|
187
|
-
* const StyledLink = styled(Link)`
|
|
188
|
-
* color: #BF4F74;
|
|
189
|
-
* font-weight: bold;
|
|
190
|
-
* `;
|
|
191
|
-
* ```
|
|
188
|
+
* style a tag or a component that forwards its class prop. styled.div is
|
|
189
|
+
* compiled to styled("div"); the untransformed export in mocks/styled.ts
|
|
190
|
+
* adds the tag properties with a proxy
|
|
192
191
|
*/
|
|
193
192
|
declare const styled: Styled;
|
|
194
193
|
//#endregion
|
|
@@ -251,24 +250,18 @@ type CSSInterpolation<TProps> = string | number | undefined | null | false | Com
|
|
|
251
250
|
[yakComponentSymbol]: any;
|
|
252
251
|
} | ((props: TProps) => CSSInterpolation<TProps>);
|
|
253
252
|
/**
|
|
254
|
-
*
|
|
253
|
+
* the runtime behind css``. the compiler rewrites every css`` and styled``
|
|
254
|
+
* call, so what arrives here is never the template the author wrote but its
|
|
255
|
+
* compiled form: class names, callbacks and css-variable maps (examples in
|
|
256
|
+
* the loop below). the public typings describe the call before compilation,
|
|
257
|
+
* which is why this function is internal: mocks/cssLiteral.ts exports the
|
|
258
|
+
* css the author sees, cast to the public type.
|
|
255
259
|
*
|
|
256
|
-
*
|
|
257
|
-
*
|
|
258
|
-
*
|
|
259
|
-
* During development the user of @yak/solid wants to work with the
|
|
260
|
-
* typings BEFORE compilation.
|
|
261
|
-
*
|
|
262
|
-
* Therefore this is only an internal function only and it must be cast to any
|
|
263
|
-
* before exported to the user.
|
|
264
|
-
*
|
|
265
|
-
* The internal functioning of css`` is to return a single callback function that runs all functions
|
|
266
|
-
* (or creates new ones if needed) that are passed as arguments. These functions receive the props, classes, and style object as arguments
|
|
267
|
-
* and operate directly on the classes and style objects.
|
|
260
|
+
* it returns one processor, (props, classes, style) => void, that runs every
|
|
261
|
+
* compiled piece: class names go into the collector, css values into the
|
|
262
|
+
* style object
|
|
268
263
|
*/
|
|
269
|
-
declare function css<TProps>(
|
|
270
|
-
theme: Accessor<YakTheme>;
|
|
271
|
-
}>[]): ComponentStyles<TProps>;
|
|
264
|
+
declare function css<TProps>(...args: Array<any>): CompiledStyleProcessor<TProps>;
|
|
272
265
|
//#endregion
|
|
273
266
|
//#region runtime/internals/unitPostFix.d.ts
|
|
274
267
|
/**
|
|
@@ -293,29 +286,22 @@ declare function css<TProps>(styles: TemplateStringsArray, ...values: CSSInterpo
|
|
|
293
286
|
* width: unitPostFix({ $width }) => $width, "px")
|
|
294
287
|
* });
|
|
295
288
|
*/
|
|
296
|
-
declare const unitPostFix: (arg: unknown, unit: string) => string | ((props: any) => string | /*elided*/any | undefined) | undefined;
|
|
289
|
+
declare const unitPostFix: (arg: unknown, unit: string) => string | ((props: any) => string | /*elided*/ any | undefined) | undefined;
|
|
297
290
|
//#endregion
|
|
298
291
|
//#region runtime/internals/mergeCssProp.d.ts
|
|
292
|
+
type Source = Record<PropertyKey, unknown>;
|
|
299
293
|
/**
|
|
300
|
-
*
|
|
301
|
-
*
|
|
302
|
-
* e.g.:
|
|
294
|
+
* Merges the relevant props of a native element with a css prop. The
|
|
295
|
+
* compiler adds it for the `css` prop:
|
|
303
296
|
* ```tsx
|
|
304
|
-
* <
|
|
305
|
-
*
|
|
306
|
-
*
|
|
307
|
-
*
|
|
308
|
-
*
|
|
309
|
-
*
|
|
310
|
-
* />
|
|
297
|
+
* <button class="a" {...props} style={s} css={css`color: green;`} />
|
|
298
|
+
* ```
|
|
299
|
+
* compiles to
|
|
300
|
+
* ```tsx
|
|
301
|
+
* <button {...__yak_mergeCssProp(css("yak1"), { class: "a" }, props, { style: s })} />
|
|
302
|
+
* ```
|
|
311
303
|
*/
|
|
312
|
-
declare const mergeCssProp: (
|
|
313
|
-
class?: string;
|
|
314
|
-
style?: Record<string, string>;
|
|
315
|
-
} & Record<string, unknown>, cssProp: RuntimeStyleProcessor<unknown> | false | null | undefined) => Record<string, unknown> & {
|
|
316
|
-
class?: string;
|
|
317
|
-
style?: Record<string, string>;
|
|
318
|
-
};
|
|
304
|
+
declare const mergeCssProp: (cssProp: RuntimeStyleProcessor<unknown> | false | null | undefined, ...sources: (Source | null | undefined)[]) => Source;
|
|
319
305
|
//#endregion
|
|
320
306
|
//#region runtime/internals/mergeClasses.d.ts
|
|
321
307
|
/**
|
|
@@ -331,6 +317,7 @@ declare const mergeCssProp: (relevantProps: {
|
|
|
331
317
|
* ```tsx
|
|
332
318
|
* <div class={__yak_mergeClassNames("yX", active() && "active")} />
|
|
333
319
|
* ```
|
|
320
|
+
* combineProps in styled.ts uses it for two attrs layers' classes as well.
|
|
334
321
|
*/
|
|
335
322
|
declare const mergeClasses: (yakClass: string, userClass: unknown) => string | undefined;
|
|
336
323
|
//#endregion
|