@reykjavik/webtools 0.1.32 → 0.1.34
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/CHANGELOG.md +20 -0
- package/README.md +38 -136
- package/esm/next/http.d.ts +1 -1
- package/esm/vanillaExtract.d.ts +113 -7
- package/esm/vanillaExtract.js +44 -4
- package/next/http.d.ts +1 -1
- package/package.json +1 -1
- package/vanillaExtract.d.ts +113 -7
- package/vanillaExtract.js +44 -4
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,26 @@
|
|
|
4
4
|
|
|
5
5
|
- ... <!-- Add new lines here. -->
|
|
6
6
|
|
|
7
|
+
## 0.1.34
|
|
8
|
+
|
|
9
|
+
_2024-10-17_
|
|
10
|
+
|
|
11
|
+
- `@reykjavik/webtools/next/vanillaExtract`:
|
|
12
|
+
- feat: `vanillaClass` passes `classNameSelector` a second parameter to the
|
|
13
|
+
render callback.
|
|
14
|
+
|
|
15
|
+
## 0.1.33
|
|
16
|
+
|
|
17
|
+
_2024-10-16_
|
|
18
|
+
|
|
19
|
+
- `@reykjavik/webtools/next/vanillaExtract`:
|
|
20
|
+
- feat: Deprecate `vanillaNest` and `vanillaClassNested` — in favor of
|
|
21
|
+
`vanillaClass` with `className` function parameter, or other home-brew
|
|
22
|
+
solutions.
|
|
23
|
+
- docs: Improve inline JSDocs and README for the `vanilla*` helpers
|
|
24
|
+
- `@reykjavik/webtools/errorhandling`:
|
|
25
|
+
- docs: Improve code examples in README
|
|
26
|
+
|
|
7
27
|
## 0.1.32
|
|
8
28
|
|
|
9
29
|
_2024-10-02_
|
package/README.md
CHANGED
|
@@ -47,11 +47,9 @@ bun add @reykjavik/webtools
|
|
|
47
47
|
- [`CookieHubProvider` component](#cookiehubprovider-component)
|
|
48
48
|
- [`useCookieHubConsent`](#usecookiehubconsent)
|
|
49
49
|
- [`@reykjavik/webtools/vanillaExtract`](#reykjavikwebtoolsvanillaextract)
|
|
50
|
+
- [`vanillaClass`](#vanillaclass)
|
|
50
51
|
- [`vanillaGlobal`](#vanillaglobal)
|
|
51
52
|
- [`vanillaProps`](#vanillaprops)
|
|
52
|
-
- [`vanillaClass`](#vanillaclass)
|
|
53
|
-
- [`vanillaClassNested`](#vanillaclassnested)
|
|
54
|
-
- [`vanillaNest`](#vanillanest)
|
|
55
53
|
- [Framework Specific Tools](#framework-specific-tools)
|
|
56
54
|
- [Remix.run Tools](#remixrun-tools)
|
|
57
55
|
- [Next.js Tools](#nextjs-tools)
|
|
@@ -372,7 +370,7 @@ console.log(posts?.reason); // undefined | unknown
|
|
|
372
370
|
## `@reykjavik/webtools/errorhandling`
|
|
373
371
|
|
|
374
372
|
A small set of lightweight tools for handling errors and promises in a safer,
|
|
375
|
-
more structured, FP-
|
|
373
|
+
more structured, FP-ish way.
|
|
376
374
|
|
|
377
375
|
Errors are always the first return value to promote early, explicit error
|
|
378
376
|
handling.
|
|
@@ -386,7 +384,7 @@ Guarantees that a caught (`catch (e)`) value of `unknown` type, is indeed an
|
|
|
386
384
|
|
|
387
385
|
If the input is an `Error` instance, it is returned as-is. If the input is
|
|
388
386
|
something else it is wrapped in a new `ErrorFromPayload` instance, and the
|
|
389
|
-
original value is stored in a `payload`
|
|
387
|
+
original value is stored in as a `payload` property.
|
|
390
388
|
|
|
391
389
|
```ts
|
|
392
390
|
import { asError, type ErrorFromPayload } from '@reykjavik/webtools/errorhandling';
|
|
@@ -408,6 +406,7 @@ try {
|
|
|
408
406
|
console.error(error === someObject); // false
|
|
409
407
|
console.error(error.message === someObject.join(',')); // false
|
|
410
408
|
console.error(error instanceOf ErrorFromPayload); // true
|
|
409
|
+
|
|
411
410
|
console.error(error.payload === someObject); // true
|
|
412
411
|
}
|
|
413
412
|
```
|
|
@@ -437,7 +436,7 @@ import { type ResultTuple } from '@reykjavik/webtools/errorhandling';
|
|
|
437
436
|
declare const myResult: ResultTuple<string, Error>;
|
|
438
437
|
|
|
439
438
|
const [error, result] = myResult;
|
|
440
|
-
//
|
|
439
|
+
// (One of these two is always `undefined`)
|
|
441
440
|
|
|
442
441
|
if (error) {
|
|
443
442
|
// Here `error` is an Error instance
|
|
@@ -463,7 +462,7 @@ import { type ResultTuple } from '@reykjavik/webtools/errorhandling';
|
|
|
463
462
|
declare const myResult: ResultTuple<string, Error>;
|
|
464
463
|
|
|
465
464
|
const [error, result] = myResult;
|
|
466
|
-
//
|
|
465
|
+
// (One of these two is always `undefined`)
|
|
467
466
|
|
|
468
467
|
if (error) {
|
|
469
468
|
// Here `error` is an Error instance
|
|
@@ -589,7 +588,7 @@ import { Result } from '@reykjavik/webtools/errorhandling';
|
|
|
589
588
|
try {
|
|
590
589
|
const fooResults = Result.throw(await getFooResultsTuple());
|
|
591
590
|
} catch (fooError) {
|
|
592
|
-
// error
|
|
591
|
+
// Do something with the error from `getFooResultsTuple()`
|
|
593
592
|
}
|
|
594
593
|
```
|
|
595
594
|
|
|
@@ -765,54 +764,12 @@ local type-safety for access to the full features and expressiveness of real
|
|
|
765
764
|
CSS.
|
|
766
765
|
([Background info](https://github.com/vanilla-extract-css/vanilla-extract/discussions/898#discussioncomment-7125457).)
|
|
767
766
|
|
|
768
|
-
### `vanillaGlobal`
|
|
769
|
-
|
|
770
|
-
**Syntax:** `vanillaGlobal(css: string): void`
|
|
771
|
-
|
|
772
|
-
Inserts free-form CSS as a vanilla-extract `globalStyle`.
|
|
773
|
-
|
|
774
|
-
```ts
|
|
775
|
-
// someFile.css.ts
|
|
776
|
-
import { vanillaGlobal } from '@reykjavik/webtools/vanillaExtract';
|
|
777
|
-
|
|
778
|
-
vanillaGlobal(`
|
|
779
|
-
body {
|
|
780
|
-
background-color: rebeccapurple;
|
|
781
|
-
}
|
|
782
|
-
`);
|
|
783
|
-
```
|
|
784
|
-
|
|
785
|
-
### `vanillaProps`
|
|
786
|
-
|
|
787
|
-
**Syntax:** `vanillaProps(css: string): GlobalStyleRule`
|
|
788
|
-
|
|
789
|
-
Spreads the return value into a style object, to inject free-form CSS
|
|
790
|
-
properties (or nested blocks)
|
|
791
|
-
|
|
792
|
-
```ts
|
|
793
|
-
// someFile.css.ts
|
|
794
|
-
import { style } from '@vanilla-extract/css';
|
|
795
|
-
import { vanillaProps } from '@reykjavik/webtools/vanillaExtract';
|
|
796
|
-
|
|
797
|
-
const myStyle = style({
|
|
798
|
-
color: 'darksalmon',
|
|
799
|
-
// ...other style props...
|
|
800
|
-
|
|
801
|
-
...vanillaProps(`
|
|
802
|
-
/* Plain CSS that's injected into the "myStyle" style block */
|
|
803
|
-
border-bottom: 1px solid red;
|
|
804
|
-
color: ${theme.color.primary}; /* I can still use typesafe values */
|
|
805
|
-
random-css-prop-normally-rejected-by-vanilla-extract: 'YOLO!';
|
|
806
|
-
`),
|
|
807
|
-
});
|
|
808
|
-
```
|
|
809
|
-
|
|
810
767
|
### `vanillaClass`
|
|
811
768
|
|
|
812
769
|
**Syntax:**
|
|
813
|
-
`vanillaClass(css: string | ((className: string) => string)): string`
|
|
770
|
+
`vanillaClass(css: string | ((className: string, classNameSelector: string) => string)): string`
|
|
814
771
|
**Syntax:**
|
|
815
|
-
`vanillaClass(debugId: string, css: string | ((className: string) => string)): string`
|
|
772
|
+
`vanillaClass(debugId: string, css: string | ((className: string, classNameSelector: string) => string)): string`
|
|
816
773
|
|
|
817
774
|
Returns a scoped cssClassName styled with free-form CSS. This function is a
|
|
818
775
|
thin wrapper around vanilla-extract's `style` function.
|
|
@@ -826,19 +783,19 @@ export const myClass = vanillaClass(`
|
|
|
826
783
|
padding: .5em 1em;
|
|
827
784
|
`);
|
|
828
785
|
|
|
829
|
-
// Passing a function to get the generated class
|
|
786
|
+
// Passing a function to get the generated class-name for
|
|
830
787
|
// more complex styles.
|
|
831
788
|
export const myOtherClass = vanillaClass(
|
|
832
|
-
(className) => `
|
|
833
|
-
|
|
789
|
+
(className, classNameSelector) => `
|
|
790
|
+
${classNameSelector} {
|
|
834
791
|
background-color: #ccc;
|
|
835
792
|
padding: .5em 1em;
|
|
836
793
|
}
|
|
837
|
-
|
|
794
|
+
[class="${className}"] > strong {
|
|
838
795
|
color: #c00;
|
|
839
796
|
}
|
|
840
797
|
@media (min-width: 800px) {
|
|
841
|
-
|
|
798
|
+
${classNameSelector} {
|
|
842
799
|
background-color: #eee;
|
|
843
800
|
}
|
|
844
801
|
}
|
|
@@ -854,112 +811,57 @@ export const humanReadableClass = vanillaClass(
|
|
|
854
811
|
);
|
|
855
812
|
```
|
|
856
813
|
|
|
857
|
-
### `
|
|
858
|
-
|
|
859
|
-
**Syntax:** `vanillaClassNested(css: string): string`
|
|
860
|
-
**Syntax:** `vanillaClassNested(debugId: string, css: string): string`
|
|
814
|
+
### `vanillaGlobal`
|
|
861
815
|
|
|
862
|
-
|
|
816
|
+
**Syntax:** `vanillaGlobal(css: string): void`
|
|
863
817
|
|
|
864
|
-
|
|
865
|
-
auto-generated class-name.
|
|
818
|
+
Inserts free-form CSS as a vanilla-extract `globalStyle`.
|
|
866
819
|
|
|
867
820
|
```ts
|
|
868
821
|
// someFile.css.ts
|
|
869
|
-
import {
|
|
870
|
-
|
|
871
|
-
export const myClass = vanillaClassNested(`
|
|
872
|
-
background-color: #ccc;
|
|
873
|
-
padding: .5em 1em;
|
|
822
|
+
import { vanillaGlobal } from '@reykjavik/webtools/vanillaExtract';
|
|
874
823
|
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
background-color:
|
|
878
|
-
color: white;
|
|
879
|
-
}
|
|
880
|
-
& > strong {
|
|
881
|
-
color: maroon;
|
|
882
|
-
}
|
|
883
|
-
html[data-color-theme="unicorn"] & {
|
|
884
|
-
background-color: pink;
|
|
824
|
+
vanillaGlobal(`
|
|
825
|
+
body {
|
|
826
|
+
background-color: rebeccapurple;
|
|
885
827
|
}
|
|
886
828
|
`);
|
|
887
829
|
```
|
|
888
830
|
|
|
889
|
-
|
|
890
|
-
any nested blocks.
|
|
891
|
-
|
|
892
|
-
**NOTE 2:** `vanillaClassNested` does NOT support deeply nested blocks, or
|
|
893
|
-
anything so fancy. It will also replace `&` characters inside values,
|
|
894
|
-
comments, etc. If you need something more sophisticated, use a custom
|
|
895
|
-
`postcss` config.
|
|
896
|
-
|
|
897
|
-
### `vanillaNest`
|
|
898
|
-
|
|
899
|
-
**Syntax:** `vanillaNest(ampSelector: string, css: string): string`
|
|
831
|
+
### `vanillaProps`
|
|
900
832
|
|
|
901
|
-
|
|
902
|
-
"dumb") way. It's mainly useful when used with style-mixins, etc.
|
|
833
|
+
**Syntax:** `vanillaProps(css: string): GlobalStyleRule`
|
|
903
834
|
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
something more sophisticated, use a custom `postcss` config.
|
|
835
|
+
Returns an object that can be safely spread into a vanilla-extract style
|
|
836
|
+
object, to inject free-form CSS properties (or nested blocks).
|
|
907
837
|
|
|
908
838
|
```ts
|
|
909
|
-
//
|
|
910
|
-
import {
|
|
911
|
-
|
|
912
|
-
export const hoverGlow = (
|
|
913
|
-
ampSelector: string,
|
|
914
|
-
glowiness?: 'normal' | 'insane'
|
|
915
|
-
) =>
|
|
916
|
-
vanillaNest(
|
|
917
|
-
ampSelector,
|
|
918
|
-
`
|
|
919
|
-
&:hover {
|
|
920
|
-
box-shadow: 0 0 20px 5px ${
|
|
921
|
-
glowiness === 'insane' ? 'hotpink' : 'salmon'
|
|
922
|
-
};
|
|
923
|
-
}
|
|
924
|
-
`
|
|
925
|
-
);
|
|
926
|
-
|
|
927
|
-
// ...then, somewhere else in a *.css.ts file:
|
|
928
|
-
|
|
929
|
-
import { hoverGlow } from '~/someCssHelper.js';
|
|
930
|
-
import { vanillaGlobal } from '@reykjavik/webtools/vanillaExtract';
|
|
839
|
+
// someFile.css.ts
|
|
840
|
+
import { style } from '@vanilla-extract/css';
|
|
841
|
+
import { vanillaProps } from '@reykjavik/webtools/vanillaExtract';
|
|
931
842
|
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
padding: 1em;
|
|
936
|
-
}
|
|
937
|
-
${hoverGlow('.MyComponent')}
|
|
843
|
+
const myStyle = style({
|
|
844
|
+
color: 'darksalmon',
|
|
845
|
+
// ...other style props...
|
|
938
846
|
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
`)
|
|
847
|
+
...vanillaProps(`
|
|
848
|
+
/* Plain CSS that's injected into the "myStyle" style block */
|
|
849
|
+
border-bottom: 1px solid red;
|
|
850
|
+
color: ${theme.color.primary}; /* I can still use typesafe values */
|
|
851
|
+
random-css-prop-normally-rejected-by-vanilla-extract: 'YOLO!';
|
|
852
|
+
`),
|
|
853
|
+
});
|
|
945
854
|
```
|
|
946
855
|
|
|
947
|
-
(This low-level utility function is used internally by
|
|
948
|
-
[`vanillaClassNested`](#vanillaclassnested).)
|
|
949
|
-
|
|
950
856
|
---
|
|
951
857
|
|
|
952
858
|
## Framework Specific Tools
|
|
953
859
|
|
|
954
|
-
---
|
|
955
|
-
|
|
956
860
|
### Remix.run Tools
|
|
957
861
|
|
|
958
862
|
See [README-remix.md](./README-remix.md) for helpers and components
|
|
959
863
|
specifically designed for use in Remix.run projects.
|
|
960
864
|
|
|
961
|
-
---
|
|
962
|
-
|
|
963
865
|
<!-- #fragment anchors to not break older v0.1 @see links -->
|
|
964
866
|
|
|
965
867
|
<a name="reykjavikwebtoolsnexthttp"></a> <a name="makeerrorizeapphoc"></a>
|
package/esm/next/http.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
2
|
import React, { FunctionComponent } from 'react';
|
|
3
3
|
import type { Cleanup } from '@reykjavik/hanna-utils';
|
|
4
|
-
import type { ServerResponse } from 'http';
|
|
5
4
|
import type { AppType } from 'next/app.js';
|
|
5
|
+
import type { ServerResponse } from 'node:http';
|
|
6
6
|
import type { HTTP_ERROR_ALL, TTLConfig } from '../http.js';
|
|
7
7
|
export * from '../http.js';
|
|
8
8
|
type NextContextLike = {
|
package/esm/vanillaExtract.d.ts
CHANGED
|
@@ -12,35 +12,141 @@ export declare const vanillaGlobal: (css: string) => void;
|
|
|
12
12
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#vanillaprops
|
|
13
13
|
*/
|
|
14
14
|
export declare const vanillaProps: (css: string) => GlobalStyleRule;
|
|
15
|
+
type ClassNameCallback = (className: string, classNameSelector: string) => string;
|
|
15
16
|
/**
|
|
16
17
|
* Returns a scoped cssClassName styled with free-form CSS
|
|
17
18
|
*
|
|
18
19
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#vanillaclass
|
|
19
20
|
*/
|
|
20
|
-
export declare function vanillaClass(css: string |
|
|
21
|
-
export declare function vanillaClass(debugId: string, css: string |
|
|
21
|
+
export declare function vanillaClass(css: string | ClassNameCallback): string;
|
|
22
|
+
export declare function vanillaClass(debugId: string, css: string | ClassNameCallback): string;
|
|
22
23
|
/**
|
|
24
|
+
* @deprecated (Will be removed in v0.2)
|
|
25
|
+
*
|
|
23
26
|
* Replaces all `&` tokens with the given selector string, in a direct
|
|
24
27
|
* (read. "dumb") way. It's mainly useful when used with style-mixins, etc.
|
|
25
28
|
*
|
|
26
|
-
* NOTE
|
|
27
|
-
* It will also replace
|
|
29
|
+
* **NOTE:** `vanillaNest` does NOT support deeply nested blocks, or anything
|
|
30
|
+
* so fancy. It will also replace `&` characters inside values, comments, etc.
|
|
28
31
|
* If you need something more sophisticated, use a custom `postcss` config.
|
|
29
32
|
*
|
|
33
|
+
* ```ts
|
|
34
|
+
* // someCssHelper.ts
|
|
35
|
+
* import { vanillaNest } from '@reykjavik/webtools/vanillaExtract';
|
|
36
|
+
*
|
|
37
|
+
* export const hoverGlow = (
|
|
38
|
+
* ampSelector: string,
|
|
39
|
+
* glowiness?: 'normal' | 'insane'
|
|
40
|
+
* ) =>
|
|
41
|
+
* vanillaNest(
|
|
42
|
+
* ampSelector,
|
|
43
|
+
* `
|
|
44
|
+
* &:hover {
|
|
45
|
+
* box-shadow: 0 0 20px 5px ${
|
|
46
|
+
* glowiness === 'insane' ? 'hotpink' : 'salmon'
|
|
47
|
+
* };
|
|
48
|
+
* }
|
|
49
|
+
* `
|
|
50
|
+
* );
|
|
51
|
+
*
|
|
52
|
+
* // ...then, somewhere else in a *.css.ts file:
|
|
53
|
+
*
|
|
54
|
+
* import { hoverGlow } from '~/someCssHelper.js';
|
|
55
|
+
* import { vanillaGlobal } from '@reykjavik/webtools/vanillaExtract';
|
|
56
|
+
*
|
|
57
|
+
* vanillaGlobal(`
|
|
58
|
+
* .MyComponent {
|
|
59
|
+
* border: 1px solid #ccc;
|
|
60
|
+
* padding: 1em;
|
|
61
|
+
* }
|
|
62
|
+
* ${hoverGlow('.MyComponent')}
|
|
63
|
+
*
|
|
64
|
+
* .MyOtherComponent {
|
|
65
|
+
* border: 1px solid #ccc;
|
|
66
|
+
* padding: 1em;
|
|
67
|
+
* }
|
|
68
|
+
* ${hoverGlow('.MyOtherComponent', 'insane')}
|
|
69
|
+
* `);
|
|
70
|
+
* ```
|
|
30
71
|
*
|
|
31
|
-
*
|
|
72
|
+
* (This low-level utility function is used internally by `vanillaClassNested`.
|
|
32
73
|
*/
|
|
33
74
|
export declare const vanillaNest: (ampSelector: string, css: string) => string;
|
|
34
75
|
/**
|
|
76
|
+
* @deprecated (Will be removed in v0.2)
|
|
77
|
+
*
|
|
35
78
|
* Returns a scoped cssClassName styled with free-form CSS.
|
|
36
79
|
*
|
|
37
80
|
* It also automatically replaces all `&`-tokens with
|
|
38
81
|
* the selector for the auto-generated class-name.
|
|
39
82
|
*
|
|
40
|
-
*
|
|
83
|
+
* ```ts
|
|
84
|
+
* // someFile.css.ts
|
|
85
|
+
* import { vanillaClassNested } from '@reykjavik/webtools/vanillaExtract';
|
|
86
|
+
*
|
|
87
|
+
* export const myClass = vanillaClassNested(`
|
|
88
|
+
* background-color: #ccc;
|
|
89
|
+
* padding: .5em 1em;
|
|
90
|
+
*
|
|
91
|
+
* /* Nested blocks begin: */
|
|
92
|
+
* &:hover {
|
|
93
|
+
* background-color: #666;
|
|
94
|
+
* color: white;
|
|
95
|
+
* }
|
|
96
|
+
* & > strong {
|
|
97
|
+
* color: maroon;
|
|
98
|
+
* }
|
|
99
|
+
* html[data-color-theme="unicorn"] & {
|
|
100
|
+
* background-color: pink;
|
|
101
|
+
* }
|
|
102
|
+
* `);
|
|
103
|
+
* ```
|
|
104
|
+
*
|
|
105
|
+
* **NOTE:** All "bare" (un-nested) style properties **must come first**,
|
|
41
106
|
* before any nested blocks.
|
|
42
107
|
*
|
|
43
|
-
*
|
|
108
|
+
* **NOTE 2:** `vanillaClassNested` does NOT support deeply nested blocks, or
|
|
109
|
+
* anything so fancy. It will also replace `&` characters inside values,
|
|
110
|
+
* comments, etc. If you need something more sophisticated, use a custom
|
|
111
|
+
* `postcss` config.
|
|
44
112
|
*/
|
|
45
113
|
export declare function vanillaClassNested(css: string): string;
|
|
114
|
+
/** @deprecated (Will be removed in v0.2) */
|
|
115
|
+
/**
|
|
116
|
+
* Returns a scoped cssClassName styled with free-form CSS.
|
|
117
|
+
*
|
|
118
|
+
* It also automatically replaces all `&`-tokens with
|
|
119
|
+
* the selector for the auto-generated class-name.
|
|
120
|
+
*
|
|
121
|
+
* ```ts
|
|
122
|
+
* // someFile.css.ts
|
|
123
|
+
* import { vanillaClassNested } from '@reykjavik/webtools/vanillaExtract';
|
|
124
|
+
*
|
|
125
|
+
* export const myClass = vanillaClassNested(`
|
|
126
|
+
* background-color: #ccc;
|
|
127
|
+
* padding: .5em 1em;
|
|
128
|
+
*
|
|
129
|
+
* /* Nested blocks begin: */
|
|
130
|
+
* &:hover {
|
|
131
|
+
* background-color: #666;
|
|
132
|
+
* color: white;
|
|
133
|
+
* }
|
|
134
|
+
* & > strong {
|
|
135
|
+
* color: maroon;
|
|
136
|
+
* }
|
|
137
|
+
* html[data-color-theme="unicorn"] & {
|
|
138
|
+
* background-color: pink;
|
|
139
|
+
* }
|
|
140
|
+
* `);
|
|
141
|
+
* ```
|
|
142
|
+
*
|
|
143
|
+
* **NOTE:** All "bare" (un-nested) style properties **must come first**,
|
|
144
|
+
* before any nested blocks.
|
|
145
|
+
*
|
|
146
|
+
* **NOTE 2:** `vanillaClassNested` does NOT support deeply nested blocks, or
|
|
147
|
+
* anything so fancy. It will also replace `&` characters inside values,
|
|
148
|
+
* comments, etc. If you need something more sophisticated, use a custom
|
|
149
|
+
* `postcss` config.
|
|
150
|
+
*/
|
|
46
151
|
export declare function vanillaClassNested(debugId: string, css: string): string;
|
|
152
|
+
export {};
|
package/esm/vanillaExtract.js
CHANGED
|
@@ -18,22 +18,62 @@ export function vanillaClass(cssOrDebugId, css) {
|
|
|
18
18
|
css = css != null ? css : cssOrDebugId;
|
|
19
19
|
if (typeof css === 'function') {
|
|
20
20
|
const className = style({}, debugId);
|
|
21
|
-
vanillaGlobal(css(className));
|
|
21
|
+
vanillaGlobal(css(className, `.${className}`));
|
|
22
22
|
return className;
|
|
23
23
|
}
|
|
24
24
|
return style(vanillaProps(css), debugId);
|
|
25
25
|
}
|
|
26
26
|
// ---------------------------------------------------------------------------
|
|
27
27
|
/**
|
|
28
|
+
* @deprecated (Will be removed in v0.2)
|
|
29
|
+
*
|
|
28
30
|
* Replaces all `&` tokens with the given selector string, in a direct
|
|
29
31
|
* (read. "dumb") way. It's mainly useful when used with style-mixins, etc.
|
|
30
32
|
*
|
|
31
|
-
* NOTE
|
|
32
|
-
* It will also replace
|
|
33
|
+
* **NOTE:** `vanillaNest` does NOT support deeply nested blocks, or anything
|
|
34
|
+
* so fancy. It will also replace `&` characters inside values, comments, etc.
|
|
33
35
|
* If you need something more sophisticated, use a custom `postcss` config.
|
|
34
36
|
*
|
|
37
|
+
* ```ts
|
|
38
|
+
* // someCssHelper.ts
|
|
39
|
+
* import { vanillaNest } from '@reykjavik/webtools/vanillaExtract';
|
|
40
|
+
*
|
|
41
|
+
* export const hoverGlow = (
|
|
42
|
+
* ampSelector: string,
|
|
43
|
+
* glowiness?: 'normal' | 'insane'
|
|
44
|
+
* ) =>
|
|
45
|
+
* vanillaNest(
|
|
46
|
+
* ampSelector,
|
|
47
|
+
* `
|
|
48
|
+
* &:hover {
|
|
49
|
+
* box-shadow: 0 0 20px 5px ${
|
|
50
|
+
* glowiness === 'insane' ? 'hotpink' : 'salmon'
|
|
51
|
+
* };
|
|
52
|
+
* }
|
|
53
|
+
* `
|
|
54
|
+
* );
|
|
55
|
+
*
|
|
56
|
+
* // ...then, somewhere else in a *.css.ts file:
|
|
57
|
+
*
|
|
58
|
+
* import { hoverGlow } from '~/someCssHelper.js';
|
|
59
|
+
* import { vanillaGlobal } from '@reykjavik/webtools/vanillaExtract';
|
|
60
|
+
*
|
|
61
|
+
* vanillaGlobal(`
|
|
62
|
+
* .MyComponent {
|
|
63
|
+
* border: 1px solid #ccc;
|
|
64
|
+
* padding: 1em;
|
|
65
|
+
* }
|
|
66
|
+
* ${hoverGlow('.MyComponent')}
|
|
67
|
+
*
|
|
68
|
+
* .MyOtherComponent {
|
|
69
|
+
* border: 1px solid #ccc;
|
|
70
|
+
* padding: 1em;
|
|
71
|
+
* }
|
|
72
|
+
* ${hoverGlow('.MyOtherComponent', 'insane')}
|
|
73
|
+
* `);
|
|
74
|
+
* ```
|
|
35
75
|
*
|
|
36
|
-
*
|
|
76
|
+
* (This low-level utility function is used internally by `vanillaClassNested`.
|
|
37
77
|
*/
|
|
38
78
|
export const vanillaNest = (ampSelector, css) => css.replace(/&/g, ampSelector);
|
|
39
79
|
export function vanillaClassNested(cssOrDebugId, css) {
|
package/next/http.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import React, { FunctionComponent } from 'react';
|
|
3
3
|
import type { Cleanup } from '@reykjavik/hanna-utils';
|
|
4
|
-
import type { ServerResponse } from 'http';
|
|
5
4
|
import type { AppType } from 'next/app.js';
|
|
5
|
+
import type { ServerResponse } from 'node:http';
|
|
6
6
|
import type { HTTP_ERROR_ALL, TTLConfig } from '../http.js';
|
|
7
7
|
export * from '../http.js';
|
|
8
8
|
type NextContextLike = {
|
package/package.json
CHANGED
package/vanillaExtract.d.ts
CHANGED
|
@@ -12,35 +12,141 @@ export declare const vanillaGlobal: (css: string) => void;
|
|
|
12
12
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#vanillaprops
|
|
13
13
|
*/
|
|
14
14
|
export declare const vanillaProps: (css: string) => GlobalStyleRule;
|
|
15
|
+
type ClassNameCallback = (className: string, classNameSelector: string) => string;
|
|
15
16
|
/**
|
|
16
17
|
* Returns a scoped cssClassName styled with free-form CSS
|
|
17
18
|
*
|
|
18
19
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#vanillaclass
|
|
19
20
|
*/
|
|
20
|
-
export declare function vanillaClass(css: string |
|
|
21
|
-
export declare function vanillaClass(debugId: string, css: string |
|
|
21
|
+
export declare function vanillaClass(css: string | ClassNameCallback): string;
|
|
22
|
+
export declare function vanillaClass(debugId: string, css: string | ClassNameCallback): string;
|
|
22
23
|
/**
|
|
24
|
+
* @deprecated (Will be removed in v0.2)
|
|
25
|
+
*
|
|
23
26
|
* Replaces all `&` tokens with the given selector string, in a direct
|
|
24
27
|
* (read. "dumb") way. It's mainly useful when used with style-mixins, etc.
|
|
25
28
|
*
|
|
26
|
-
* NOTE
|
|
27
|
-
* It will also replace
|
|
29
|
+
* **NOTE:** `vanillaNest` does NOT support deeply nested blocks, or anything
|
|
30
|
+
* so fancy. It will also replace `&` characters inside values, comments, etc.
|
|
28
31
|
* If you need something more sophisticated, use a custom `postcss` config.
|
|
29
32
|
*
|
|
33
|
+
* ```ts
|
|
34
|
+
* // someCssHelper.ts
|
|
35
|
+
* import { vanillaNest } from '@reykjavik/webtools/vanillaExtract';
|
|
36
|
+
*
|
|
37
|
+
* export const hoverGlow = (
|
|
38
|
+
* ampSelector: string,
|
|
39
|
+
* glowiness?: 'normal' | 'insane'
|
|
40
|
+
* ) =>
|
|
41
|
+
* vanillaNest(
|
|
42
|
+
* ampSelector,
|
|
43
|
+
* `
|
|
44
|
+
* &:hover {
|
|
45
|
+
* box-shadow: 0 0 20px 5px ${
|
|
46
|
+
* glowiness === 'insane' ? 'hotpink' : 'salmon'
|
|
47
|
+
* };
|
|
48
|
+
* }
|
|
49
|
+
* `
|
|
50
|
+
* );
|
|
51
|
+
*
|
|
52
|
+
* // ...then, somewhere else in a *.css.ts file:
|
|
53
|
+
*
|
|
54
|
+
* import { hoverGlow } from '~/someCssHelper.js';
|
|
55
|
+
* import { vanillaGlobal } from '@reykjavik/webtools/vanillaExtract';
|
|
56
|
+
*
|
|
57
|
+
* vanillaGlobal(`
|
|
58
|
+
* .MyComponent {
|
|
59
|
+
* border: 1px solid #ccc;
|
|
60
|
+
* padding: 1em;
|
|
61
|
+
* }
|
|
62
|
+
* ${hoverGlow('.MyComponent')}
|
|
63
|
+
*
|
|
64
|
+
* .MyOtherComponent {
|
|
65
|
+
* border: 1px solid #ccc;
|
|
66
|
+
* padding: 1em;
|
|
67
|
+
* }
|
|
68
|
+
* ${hoverGlow('.MyOtherComponent', 'insane')}
|
|
69
|
+
* `);
|
|
70
|
+
* ```
|
|
30
71
|
*
|
|
31
|
-
*
|
|
72
|
+
* (This low-level utility function is used internally by `vanillaClassNested`.
|
|
32
73
|
*/
|
|
33
74
|
export declare const vanillaNest: (ampSelector: string, css: string) => string;
|
|
34
75
|
/**
|
|
76
|
+
* @deprecated (Will be removed in v0.2)
|
|
77
|
+
*
|
|
35
78
|
* Returns a scoped cssClassName styled with free-form CSS.
|
|
36
79
|
*
|
|
37
80
|
* It also automatically replaces all `&`-tokens with
|
|
38
81
|
* the selector for the auto-generated class-name.
|
|
39
82
|
*
|
|
40
|
-
*
|
|
83
|
+
* ```ts
|
|
84
|
+
* // someFile.css.ts
|
|
85
|
+
* import { vanillaClassNested } from '@reykjavik/webtools/vanillaExtract';
|
|
86
|
+
*
|
|
87
|
+
* export const myClass = vanillaClassNested(`
|
|
88
|
+
* background-color: #ccc;
|
|
89
|
+
* padding: .5em 1em;
|
|
90
|
+
*
|
|
91
|
+
* /* Nested blocks begin: */
|
|
92
|
+
* &:hover {
|
|
93
|
+
* background-color: #666;
|
|
94
|
+
* color: white;
|
|
95
|
+
* }
|
|
96
|
+
* & > strong {
|
|
97
|
+
* color: maroon;
|
|
98
|
+
* }
|
|
99
|
+
* html[data-color-theme="unicorn"] & {
|
|
100
|
+
* background-color: pink;
|
|
101
|
+
* }
|
|
102
|
+
* `);
|
|
103
|
+
* ```
|
|
104
|
+
*
|
|
105
|
+
* **NOTE:** All "bare" (un-nested) style properties **must come first**,
|
|
41
106
|
* before any nested blocks.
|
|
42
107
|
*
|
|
43
|
-
*
|
|
108
|
+
* **NOTE 2:** `vanillaClassNested` does NOT support deeply nested blocks, or
|
|
109
|
+
* anything so fancy. It will also replace `&` characters inside values,
|
|
110
|
+
* comments, etc. If you need something more sophisticated, use a custom
|
|
111
|
+
* `postcss` config.
|
|
44
112
|
*/
|
|
45
113
|
export declare function vanillaClassNested(css: string): string;
|
|
114
|
+
/** @deprecated (Will be removed in v0.2) */
|
|
115
|
+
/**
|
|
116
|
+
* Returns a scoped cssClassName styled with free-form CSS.
|
|
117
|
+
*
|
|
118
|
+
* It also automatically replaces all `&`-tokens with
|
|
119
|
+
* the selector for the auto-generated class-name.
|
|
120
|
+
*
|
|
121
|
+
* ```ts
|
|
122
|
+
* // someFile.css.ts
|
|
123
|
+
* import { vanillaClassNested } from '@reykjavik/webtools/vanillaExtract';
|
|
124
|
+
*
|
|
125
|
+
* export const myClass = vanillaClassNested(`
|
|
126
|
+
* background-color: #ccc;
|
|
127
|
+
* padding: .5em 1em;
|
|
128
|
+
*
|
|
129
|
+
* /* Nested blocks begin: */
|
|
130
|
+
* &:hover {
|
|
131
|
+
* background-color: #666;
|
|
132
|
+
* color: white;
|
|
133
|
+
* }
|
|
134
|
+
* & > strong {
|
|
135
|
+
* color: maroon;
|
|
136
|
+
* }
|
|
137
|
+
* html[data-color-theme="unicorn"] & {
|
|
138
|
+
* background-color: pink;
|
|
139
|
+
* }
|
|
140
|
+
* `);
|
|
141
|
+
* ```
|
|
142
|
+
*
|
|
143
|
+
* **NOTE:** All "bare" (un-nested) style properties **must come first**,
|
|
144
|
+
* before any nested blocks.
|
|
145
|
+
*
|
|
146
|
+
* **NOTE 2:** `vanillaClassNested` does NOT support deeply nested blocks, or
|
|
147
|
+
* anything so fancy. It will also replace `&` characters inside values,
|
|
148
|
+
* comments, etc. If you need something more sophisticated, use a custom
|
|
149
|
+
* `postcss` config.
|
|
150
|
+
*/
|
|
46
151
|
export declare function vanillaClassNested(debugId: string, css: string): string;
|
|
152
|
+
export {};
|
package/vanillaExtract.js
CHANGED
|
@@ -23,7 +23,7 @@ function vanillaClass(cssOrDebugId, css) {
|
|
|
23
23
|
css = css != null ? css : cssOrDebugId;
|
|
24
24
|
if (typeof css === 'function') {
|
|
25
25
|
const className = (0, css_1.style)({}, debugId);
|
|
26
|
-
(0, exports.vanillaGlobal)(css(className));
|
|
26
|
+
(0, exports.vanillaGlobal)(css(className, `.${className}`));
|
|
27
27
|
return className;
|
|
28
28
|
}
|
|
29
29
|
return (0, css_1.style)((0, exports.vanillaProps)(css), debugId);
|
|
@@ -31,15 +31,55 @@ function vanillaClass(cssOrDebugId, css) {
|
|
|
31
31
|
exports.vanillaClass = vanillaClass;
|
|
32
32
|
// ---------------------------------------------------------------------------
|
|
33
33
|
/**
|
|
34
|
+
* @deprecated (Will be removed in v0.2)
|
|
35
|
+
*
|
|
34
36
|
* Replaces all `&` tokens with the given selector string, in a direct
|
|
35
37
|
* (read. "dumb") way. It's mainly useful when used with style-mixins, etc.
|
|
36
38
|
*
|
|
37
|
-
* NOTE
|
|
38
|
-
* It will also replace
|
|
39
|
+
* **NOTE:** `vanillaNest` does NOT support deeply nested blocks, or anything
|
|
40
|
+
* so fancy. It will also replace `&` characters inside values, comments, etc.
|
|
39
41
|
* If you need something more sophisticated, use a custom `postcss` config.
|
|
40
42
|
*
|
|
43
|
+
* ```ts
|
|
44
|
+
* // someCssHelper.ts
|
|
45
|
+
* import { vanillaNest } from '@reykjavik/webtools/vanillaExtract';
|
|
46
|
+
*
|
|
47
|
+
* export const hoverGlow = (
|
|
48
|
+
* ampSelector: string,
|
|
49
|
+
* glowiness?: 'normal' | 'insane'
|
|
50
|
+
* ) =>
|
|
51
|
+
* vanillaNest(
|
|
52
|
+
* ampSelector,
|
|
53
|
+
* `
|
|
54
|
+
* &:hover {
|
|
55
|
+
* box-shadow: 0 0 20px 5px ${
|
|
56
|
+
* glowiness === 'insane' ? 'hotpink' : 'salmon'
|
|
57
|
+
* };
|
|
58
|
+
* }
|
|
59
|
+
* `
|
|
60
|
+
* );
|
|
61
|
+
*
|
|
62
|
+
* // ...then, somewhere else in a *.css.ts file:
|
|
63
|
+
*
|
|
64
|
+
* import { hoverGlow } from '~/someCssHelper.js';
|
|
65
|
+
* import { vanillaGlobal } from '@reykjavik/webtools/vanillaExtract';
|
|
66
|
+
*
|
|
67
|
+
* vanillaGlobal(`
|
|
68
|
+
* .MyComponent {
|
|
69
|
+
* border: 1px solid #ccc;
|
|
70
|
+
* padding: 1em;
|
|
71
|
+
* }
|
|
72
|
+
* ${hoverGlow('.MyComponent')}
|
|
73
|
+
*
|
|
74
|
+
* .MyOtherComponent {
|
|
75
|
+
* border: 1px solid #ccc;
|
|
76
|
+
* padding: 1em;
|
|
77
|
+
* }
|
|
78
|
+
* ${hoverGlow('.MyOtherComponent', 'insane')}
|
|
79
|
+
* `);
|
|
80
|
+
* ```
|
|
41
81
|
*
|
|
42
|
-
*
|
|
82
|
+
* (This low-level utility function is used internally by `vanillaClassNested`.
|
|
43
83
|
*/
|
|
44
84
|
const vanillaNest = (ampSelector, css) => css.replace(/&/g, ampSelector);
|
|
45
85
|
exports.vanillaNest = vanillaNest;
|