@yak/solid 0.0.0 → 0.2.0

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.
@@ -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, 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
- * Set-like collector for class names.
116
- *
117
- * Implemented as a string builder in the runtime (a Set<string>
118
- * split → Set → Array.from → join round-trip dominates render cost);
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
- add(name: string): void;
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
- * The `styled` method works perfectly on all of your own or any third-party component,
182
- * as long as they attach the passed `class` prop to a DOM element.
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
- * css() runtime factory of css``
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
- * /!\ @yak/solid transpiles css`` and styled``
257
- *
258
- * This changes the typings of the css`` and styled`` functions.
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>(styles: TemplateStringsArray, ...values: CSSInterpolation<NoInfer<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
- * This is an internal helper function to merge relevant props of a native element with a css prop.
301
- * It's automatically added when using the `css` prop in a JSX element.
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
- * <p
305
- * class="foo"
306
- * css={css`
307
- * color: green;
308
- * `}
309
- * {...{ style: { padding: "30px" }}}
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: (relevantProps: {
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