@reykjavik/webtools 0.1.31 → 0.1.33
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 +309 -169
- package/errorhandling.d.ts +99 -0
- package/errorhandling.js +107 -0
- package/esm/errorhandling.d.ts +99 -0
- package/esm/errorhandling.js +102 -0
- package/esm/index.d.ts +1 -0
- package/esm/vanillaExtract.d.ts +109 -5
- package/esm/vanillaExtract.js +43 -3
- package/index.d.ts +1 -0
- package/package.json +5 -1
- package/vanillaExtract.d.ts +109 -5
- package/vanillaExtract.js +43 -3
package/errorhandling.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Result = exports.asError = exports.ErrorFromPayload = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Error subclass for thrown values that got cought and turned into an actual
|
|
6
|
+
* Error, with the thrown value as the `payload` property.
|
|
7
|
+
*
|
|
8
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#aserror
|
|
9
|
+
*/
|
|
10
|
+
class ErrorFromPayload extends Error {
|
|
11
|
+
constructor(payload) {
|
|
12
|
+
if (process.env.NODE_ENV !== 'production' && payload instanceof Error) {
|
|
13
|
+
throw new Error('Do not pass an Error instance as payload, just use it directly');
|
|
14
|
+
}
|
|
15
|
+
const message = (payload != null ? String(payload) : '') || 'Threw a falsy/empty value';
|
|
16
|
+
super(message);
|
|
17
|
+
this.name = 'ErrorFromPayload';
|
|
18
|
+
this.payload = payload;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.ErrorFromPayload = ErrorFromPayload;
|
|
22
|
+
/**v
|
|
23
|
+
* Guarantees that a caught (`catch (e)`) value of `unknown` type,
|
|
24
|
+
* is indeed an `Error` instance.
|
|
25
|
+
*
|
|
26
|
+
*If the input is an `Error` instance, it is returned as-is. If the input is
|
|
27
|
+
* something else it is wrapped in a new `ErrorFromPayload` instance, and the
|
|
28
|
+
* original value is stored in a `payload`
|
|
29
|
+
*
|
|
30
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#aserror
|
|
31
|
+
*/
|
|
32
|
+
const asError = (maybeError) => {
|
|
33
|
+
if (maybeError instanceof Error) {
|
|
34
|
+
return maybeError;
|
|
35
|
+
}
|
|
36
|
+
return new ErrorFromPayload(maybeError);
|
|
37
|
+
};
|
|
38
|
+
exports.asError = asError;
|
|
39
|
+
const Success = (result) => {
|
|
40
|
+
const tuple = [undefined, result];
|
|
41
|
+
tuple.result = result;
|
|
42
|
+
return tuple;
|
|
43
|
+
};
|
|
44
|
+
const Fail = (e) => {
|
|
45
|
+
const tuple = [(0, exports.asError)(e)];
|
|
46
|
+
tuple.error = tuple[0];
|
|
47
|
+
return tuple;
|
|
48
|
+
};
|
|
49
|
+
function catch_(something) {
|
|
50
|
+
if (something instanceof Promise) {
|
|
51
|
+
return something.then((result) => Success(result), (e) => Fail(e));
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
return Success(something());
|
|
55
|
+
}
|
|
56
|
+
catch (e) {
|
|
57
|
+
return Fail(e);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Singleton object with small methods for creating, mapping or handling
|
|
62
|
+
* `ResultTupleObj` instances.
|
|
63
|
+
*
|
|
64
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#result-singleton
|
|
65
|
+
*/
|
|
66
|
+
exports.Result = {
|
|
67
|
+
/**
|
|
68
|
+
* Factory for creating a successful `Result.TupleObj`.
|
|
69
|
+
*
|
|
70
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#resultsuccess
|
|
71
|
+
*/
|
|
72
|
+
Success,
|
|
73
|
+
/**
|
|
74
|
+
* Factory for creating a failed `Result.TupleObj`.
|
|
75
|
+
*
|
|
76
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#resultsfail
|
|
77
|
+
*/
|
|
78
|
+
Fail,
|
|
79
|
+
// NOTE: The JSDoc must be placed above the `catch_` function above.
|
|
80
|
+
catch: catch_,
|
|
81
|
+
/**
|
|
82
|
+
* Helper to map a `ResultTuple`-like object to a new `ResultTupleObj`
|
|
83
|
+
* object, applying a transformation function to the result, but retaining
|
|
84
|
+
* the error as-is.
|
|
85
|
+
*
|
|
86
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#resulmap
|
|
87
|
+
*/
|
|
88
|
+
map: (result, mapFn) => {
|
|
89
|
+
const [error, resultValue] = result;
|
|
90
|
+
if (error) {
|
|
91
|
+
return Fail(error);
|
|
92
|
+
}
|
|
93
|
+
return Success(mapFn(resultValue));
|
|
94
|
+
},
|
|
95
|
+
/**
|
|
96
|
+
* Unwraps a discriminated [error, result] `Result.Tuple`-like object
|
|
97
|
+
* and throws if there's an error, but returns the result otherwise.
|
|
98
|
+
*
|
|
99
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#resulthrow
|
|
100
|
+
*/
|
|
101
|
+
throw: (result) => {
|
|
102
|
+
if (result[0]) {
|
|
103
|
+
throw result[0];
|
|
104
|
+
}
|
|
105
|
+
return result[1];
|
|
106
|
+
},
|
|
107
|
+
};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error subclass for thrown values that got cought and turned into an actual
|
|
3
|
+
* Error, with the thrown value as the `payload` property.
|
|
4
|
+
*
|
|
5
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#aserror
|
|
6
|
+
*/
|
|
7
|
+
export declare class ErrorFromPayload extends Error {
|
|
8
|
+
payload?: unknown;
|
|
9
|
+
constructor(payload: unknown);
|
|
10
|
+
name: string;
|
|
11
|
+
}
|
|
12
|
+
/**v
|
|
13
|
+
* Guarantees that a caught (`catch (e)`) value of `unknown` type,
|
|
14
|
+
* is indeed an `Error` instance.
|
|
15
|
+
*
|
|
16
|
+
*If the input is an `Error` instance, it is returned as-is. If the input is
|
|
17
|
+
* something else it is wrapped in a new `ErrorFromPayload` instance, and the
|
|
18
|
+
* original value is stored in a `payload`
|
|
19
|
+
*
|
|
20
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#aserror
|
|
21
|
+
*/
|
|
22
|
+
export declare const asError: (maybeError: unknown) => ErrorFromPayload;
|
|
23
|
+
type SuccessResult<T> = [error: undefined, result: T] & {
|
|
24
|
+
error?: undefined;
|
|
25
|
+
result: T;
|
|
26
|
+
};
|
|
27
|
+
type FailResult<E extends Error> = [error: E] & {
|
|
28
|
+
error: E;
|
|
29
|
+
result?: undefined;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Simple bare-bones discriminated tuple type for a [error, result] pair.
|
|
33
|
+
*
|
|
34
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#type-resulttuple
|
|
35
|
+
*/
|
|
36
|
+
export type ResultTuple<T, E extends Error = Error> = [error: undefined, result: T] | [error: E];
|
|
37
|
+
/**
|
|
38
|
+
* Discriminated tuple type for a `[error, result]` pair (same as `ResultTuple`)
|
|
39
|
+
* but with named properties `error` and `result` attached for dev convenience.
|
|
40
|
+
*
|
|
41
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#type-resulttupleobj
|
|
42
|
+
*/
|
|
43
|
+
export type ResultTupleObj<T, E extends Error = Error> = SuccessResult<T> | FailResult<E>;
|
|
44
|
+
/**
|
|
45
|
+
* Error handling utility that wraps a promise or a callback function.
|
|
46
|
+
*
|
|
47
|
+
* Catches errors and returns a `ResultTupleObj` — a nice discriminated
|
|
48
|
+
* `[error, results]` tuple with the `result` and `error` also attached as
|
|
49
|
+
* named properties.
|
|
50
|
+
*
|
|
51
|
+
* Works on both promises and sync callback functions.
|
|
52
|
+
*
|
|
53
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#resultcatch
|
|
54
|
+
*/
|
|
55
|
+
declare function catch_<T, E extends Error = ErrorFromPayload>(promise: Promise<T>): Promise<ResultTupleObj<T, E>>;
|
|
56
|
+
declare function catch_<T, E extends Error = ErrorFromPayload>(callback: () => T): ResultTupleObj<T, E>;
|
|
57
|
+
/**
|
|
58
|
+
* Singleton object with small methods for creating, mapping or handling
|
|
59
|
+
* `ResultTupleObj` instances.
|
|
60
|
+
*
|
|
61
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#result-singleton
|
|
62
|
+
*/
|
|
63
|
+
export declare const Result: {
|
|
64
|
+
/**
|
|
65
|
+
* Factory for creating a successful `Result.TupleObj`.
|
|
66
|
+
*
|
|
67
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#resultsuccess
|
|
68
|
+
*/
|
|
69
|
+
Success: <T>(result: T) => SuccessResult<T>;
|
|
70
|
+
/**
|
|
71
|
+
* Factory for creating a failed `Result.TupleObj`.
|
|
72
|
+
*
|
|
73
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#resultsfail
|
|
74
|
+
*/
|
|
75
|
+
Fail: <E extends Error = Error>(e: unknown) => FailResult<E>;
|
|
76
|
+
catch: typeof catch_;
|
|
77
|
+
/**
|
|
78
|
+
* Helper to map a `ResultTuple`-like object to a new `ResultTupleObj`
|
|
79
|
+
* object, applying a transformation function to the result, but retaining
|
|
80
|
+
* the error as-is.
|
|
81
|
+
*
|
|
82
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#resulmap
|
|
83
|
+
*/
|
|
84
|
+
map: <T_1, T2, E_1 extends Error>(result: ResultTuple<T_1, E_1>, mapFn: (resultValue: T_1) => T2) => ResultTupleObj<T2, E_1>;
|
|
85
|
+
/**
|
|
86
|
+
* Unwraps a discriminated [error, result] `Result.Tuple`-like object
|
|
87
|
+
* and throws if there's an error, but returns the result otherwise.
|
|
88
|
+
*
|
|
89
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#resulthrow
|
|
90
|
+
*/
|
|
91
|
+
throw: <T_2>(result: ResultTuple<T_2, Error>) => T_2;
|
|
92
|
+
};
|
|
93
|
+
export declare namespace Result {
|
|
94
|
+
type Tuple<T, E extends Error = Error> = ResultTuple<T, E>;
|
|
95
|
+
type TupleObj<T, E extends Error = Error> = ResultTupleObj<T, E>;
|
|
96
|
+
type SuccessObj<T> = SuccessResult<T>;
|
|
97
|
+
type FailObj<E extends Error> = FailResult<E>;
|
|
98
|
+
}
|
|
99
|
+
export {};
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error subclass for thrown values that got cought and turned into an actual
|
|
3
|
+
* Error, with the thrown value as the `payload` property.
|
|
4
|
+
*
|
|
5
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#aserror
|
|
6
|
+
*/
|
|
7
|
+
export class ErrorFromPayload extends Error {
|
|
8
|
+
constructor(payload) {
|
|
9
|
+
if (process.env.NODE_ENV !== 'production' && payload instanceof Error) {
|
|
10
|
+
throw new Error('Do not pass an Error instance as payload, just use it directly');
|
|
11
|
+
}
|
|
12
|
+
const message = (payload != null ? String(payload) : '') || 'Threw a falsy/empty value';
|
|
13
|
+
super(message);
|
|
14
|
+
this.name = 'ErrorFromPayload';
|
|
15
|
+
this.payload = payload;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/**v
|
|
19
|
+
* Guarantees that a caught (`catch (e)`) value of `unknown` type,
|
|
20
|
+
* is indeed an `Error` instance.
|
|
21
|
+
*
|
|
22
|
+
*If the input is an `Error` instance, it is returned as-is. If the input is
|
|
23
|
+
* something else it is wrapped in a new `ErrorFromPayload` instance, and the
|
|
24
|
+
* original value is stored in a `payload`
|
|
25
|
+
*
|
|
26
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#aserror
|
|
27
|
+
*/
|
|
28
|
+
export const asError = (maybeError) => {
|
|
29
|
+
if (maybeError instanceof Error) {
|
|
30
|
+
return maybeError;
|
|
31
|
+
}
|
|
32
|
+
return new ErrorFromPayload(maybeError);
|
|
33
|
+
};
|
|
34
|
+
const Success = (result) => {
|
|
35
|
+
const tuple = [undefined, result];
|
|
36
|
+
tuple.result = result;
|
|
37
|
+
return tuple;
|
|
38
|
+
};
|
|
39
|
+
const Fail = (e) => {
|
|
40
|
+
const tuple = [asError(e)];
|
|
41
|
+
tuple.error = tuple[0];
|
|
42
|
+
return tuple;
|
|
43
|
+
};
|
|
44
|
+
function catch_(something) {
|
|
45
|
+
if (something instanceof Promise) {
|
|
46
|
+
return something.then((result) => Success(result), (e) => Fail(e));
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
return Success(something());
|
|
50
|
+
}
|
|
51
|
+
catch (e) {
|
|
52
|
+
return Fail(e);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Singleton object with small methods for creating, mapping or handling
|
|
57
|
+
* `ResultTupleObj` instances.
|
|
58
|
+
*
|
|
59
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#result-singleton
|
|
60
|
+
*/
|
|
61
|
+
export const Result = {
|
|
62
|
+
/**
|
|
63
|
+
* Factory for creating a successful `Result.TupleObj`.
|
|
64
|
+
*
|
|
65
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#resultsuccess
|
|
66
|
+
*/
|
|
67
|
+
Success,
|
|
68
|
+
/**
|
|
69
|
+
* Factory for creating a failed `Result.TupleObj`.
|
|
70
|
+
*
|
|
71
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#resultsfail
|
|
72
|
+
*/
|
|
73
|
+
Fail,
|
|
74
|
+
// NOTE: The JSDoc must be placed above the `catch_` function above.
|
|
75
|
+
catch: catch_,
|
|
76
|
+
/**
|
|
77
|
+
* Helper to map a `ResultTuple`-like object to a new `ResultTupleObj`
|
|
78
|
+
* object, applying a transformation function to the result, but retaining
|
|
79
|
+
* the error as-is.
|
|
80
|
+
*
|
|
81
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#resulmap
|
|
82
|
+
*/
|
|
83
|
+
map: (result, mapFn) => {
|
|
84
|
+
const [error, resultValue] = result;
|
|
85
|
+
if (error) {
|
|
86
|
+
return Fail(error);
|
|
87
|
+
}
|
|
88
|
+
return Success(mapFn(resultValue));
|
|
89
|
+
},
|
|
90
|
+
/**
|
|
91
|
+
* Unwraps a discriminated [error, result] `Result.Tuple`-like object
|
|
92
|
+
* and throws if there's an error, but returns the result otherwise.
|
|
93
|
+
*
|
|
94
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#resulthrow
|
|
95
|
+
*/
|
|
96
|
+
throw: (result) => {
|
|
97
|
+
if (result[0]) {
|
|
98
|
+
throw result[0];
|
|
99
|
+
}
|
|
100
|
+
return result[1];
|
|
101
|
+
},
|
|
102
|
+
};
|
package/esm/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
/// <reference path="./http.d.ts" />
|
|
3
3
|
/// <reference path="./async.d.ts" />
|
|
4
4
|
/// <reference path="./fixIcelandicLocale.d.ts" />
|
|
5
|
+
/// <reference path="./errorhandling.d.ts" />
|
|
5
6
|
/// <reference path="./remix/http.d.ts" />
|
|
6
7
|
/// <reference path="./SiteImprove.d.tsx" />
|
|
7
8
|
/// <reference path="./CookieHubConsent.d.tsx" />
|
package/esm/vanillaExtract.d.ts
CHANGED
|
@@ -20,27 +20,131 @@ export declare const vanillaProps: (css: string) => GlobalStyleRule;
|
|
|
20
20
|
export declare function vanillaClass(css: string | ((className: string) => string)): string;
|
|
21
21
|
export declare function vanillaClass(debugId: string, css: string | ((className: string) => string)): string;
|
|
22
22
|
/**
|
|
23
|
+
* @deprecated (Will be removed in v0.2)
|
|
24
|
+
*
|
|
23
25
|
* Replaces all `&` tokens with the given selector string, in a direct
|
|
24
26
|
* (read. "dumb") way. It's mainly useful when used with style-mixins, etc.
|
|
25
27
|
*
|
|
26
|
-
* NOTE
|
|
27
|
-
* It will also replace
|
|
28
|
+
* **NOTE:** `vanillaNest` does NOT support deeply nested blocks, or anything
|
|
29
|
+
* so fancy. It will also replace `&` characters inside values, comments, etc.
|
|
28
30
|
* If you need something more sophisticated, use a custom `postcss` config.
|
|
29
31
|
*
|
|
32
|
+
* ```ts
|
|
33
|
+
* // someCssHelper.ts
|
|
34
|
+
* import { vanillaNest } from '@reykjavik/webtools/vanillaExtract';
|
|
35
|
+
*
|
|
36
|
+
* export const hoverGlow = (
|
|
37
|
+
* ampSelector: string,
|
|
38
|
+
* glowiness?: 'normal' | 'insane'
|
|
39
|
+
* ) =>
|
|
40
|
+
* vanillaNest(
|
|
41
|
+
* ampSelector,
|
|
42
|
+
* `
|
|
43
|
+
* &:hover {
|
|
44
|
+
* box-shadow: 0 0 20px 5px ${
|
|
45
|
+
* glowiness === 'insane' ? 'hotpink' : 'salmon'
|
|
46
|
+
* };
|
|
47
|
+
* }
|
|
48
|
+
* `
|
|
49
|
+
* );
|
|
50
|
+
*
|
|
51
|
+
* // ...then, somewhere else in a *.css.ts file:
|
|
52
|
+
*
|
|
53
|
+
* import { hoverGlow } from '~/someCssHelper.js';
|
|
54
|
+
* import { vanillaGlobal } from '@reykjavik/webtools/vanillaExtract';
|
|
55
|
+
*
|
|
56
|
+
* vanillaGlobal(`
|
|
57
|
+
* .MyComponent {
|
|
58
|
+
* border: 1px solid #ccc;
|
|
59
|
+
* padding: 1em;
|
|
60
|
+
* }
|
|
61
|
+
* ${hoverGlow('.MyComponent')}
|
|
62
|
+
*
|
|
63
|
+
* .MyOtherComponent {
|
|
64
|
+
* border: 1px solid #ccc;
|
|
65
|
+
* padding: 1em;
|
|
66
|
+
* }
|
|
67
|
+
* ${hoverGlow('.MyOtherComponent', 'insane')}
|
|
68
|
+
* `);
|
|
69
|
+
* ```
|
|
30
70
|
*
|
|
31
|
-
*
|
|
71
|
+
* (This low-level utility function is used internally by `vanillaClassNested`.
|
|
32
72
|
*/
|
|
33
73
|
export declare const vanillaNest: (ampSelector: string, css: string) => string;
|
|
34
74
|
/**
|
|
75
|
+
* @deprecated (Will be removed in v0.2)
|
|
76
|
+
*
|
|
35
77
|
* Returns a scoped cssClassName styled with free-form CSS.
|
|
36
78
|
*
|
|
37
79
|
* It also automatically replaces all `&`-tokens with
|
|
38
80
|
* the selector for the auto-generated class-name.
|
|
39
81
|
*
|
|
40
|
-
*
|
|
82
|
+
* ```ts
|
|
83
|
+
* // someFile.css.ts
|
|
84
|
+
* import { vanillaClassNested } from '@reykjavik/webtools/vanillaExtract';
|
|
85
|
+
*
|
|
86
|
+
* export const myClass = vanillaClassNested(`
|
|
87
|
+
* background-color: #ccc;
|
|
88
|
+
* padding: .5em 1em;
|
|
89
|
+
*
|
|
90
|
+
* /* Nested blocks begin: */
|
|
91
|
+
* &:hover {
|
|
92
|
+
* background-color: #666;
|
|
93
|
+
* color: white;
|
|
94
|
+
* }
|
|
95
|
+
* & > strong {
|
|
96
|
+
* color: maroon;
|
|
97
|
+
* }
|
|
98
|
+
* html[data-color-theme="unicorn"] & {
|
|
99
|
+
* background-color: pink;
|
|
100
|
+
* }
|
|
101
|
+
* `);
|
|
102
|
+
* ```
|
|
103
|
+
*
|
|
104
|
+
* **NOTE:** All "bare" (un-nested) style properties **must come first**,
|
|
41
105
|
* before any nested blocks.
|
|
42
106
|
*
|
|
43
|
-
*
|
|
107
|
+
* **NOTE 2:** `vanillaClassNested` does NOT support deeply nested blocks, or
|
|
108
|
+
* anything so fancy. It will also replace `&` characters inside values,
|
|
109
|
+
* comments, etc. If you need something more sophisticated, use a custom
|
|
110
|
+
* `postcss` config.
|
|
44
111
|
*/
|
|
45
112
|
export declare function vanillaClassNested(css: string): string;
|
|
113
|
+
/** @deprecated (Will be removed in v0.2) */
|
|
114
|
+
/**
|
|
115
|
+
* Returns a scoped cssClassName styled with free-form CSS.
|
|
116
|
+
*
|
|
117
|
+
* It also automatically replaces all `&`-tokens with
|
|
118
|
+
* the selector for the auto-generated class-name.
|
|
119
|
+
*
|
|
120
|
+
* ```ts
|
|
121
|
+
* // someFile.css.ts
|
|
122
|
+
* import { vanillaClassNested } from '@reykjavik/webtools/vanillaExtract';
|
|
123
|
+
*
|
|
124
|
+
* export const myClass = vanillaClassNested(`
|
|
125
|
+
* background-color: #ccc;
|
|
126
|
+
* padding: .5em 1em;
|
|
127
|
+
*
|
|
128
|
+
* /* Nested blocks begin: */
|
|
129
|
+
* &:hover {
|
|
130
|
+
* background-color: #666;
|
|
131
|
+
* color: white;
|
|
132
|
+
* }
|
|
133
|
+
* & > strong {
|
|
134
|
+
* color: maroon;
|
|
135
|
+
* }
|
|
136
|
+
* html[data-color-theme="unicorn"] & {
|
|
137
|
+
* background-color: pink;
|
|
138
|
+
* }
|
|
139
|
+
* `);
|
|
140
|
+
* ```
|
|
141
|
+
*
|
|
142
|
+
* **NOTE:** All "bare" (un-nested) style properties **must come first**,
|
|
143
|
+
* before any nested blocks.
|
|
144
|
+
*
|
|
145
|
+
* **NOTE 2:** `vanillaClassNested` does NOT support deeply nested blocks, or
|
|
146
|
+
* anything so fancy. It will also replace `&` characters inside values,
|
|
147
|
+
* comments, etc. If you need something more sophisticated, use a custom
|
|
148
|
+
* `postcss` config.
|
|
149
|
+
*/
|
|
46
150
|
export declare function vanillaClassNested(debugId: string, css: string): string;
|
package/esm/vanillaExtract.js
CHANGED
|
@@ -25,15 +25,55 @@ export function vanillaClass(cssOrDebugId, css) {
|
|
|
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/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
/// <reference path="./http.d.ts" />
|
|
3
3
|
/// <reference path="./async.d.ts" />
|
|
4
4
|
/// <reference path="./fixIcelandicLocale.d.ts" />
|
|
5
|
+
/// <reference path="./errorhandling.d.ts" />
|
|
5
6
|
/// <reference path="./remix/http.d.ts" />
|
|
6
7
|
/// <reference path="./SiteImprove.d.tsx" />
|
|
7
8
|
/// <reference path="./CookieHubConsent.d.tsx" />
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reykjavik/webtools",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.33",
|
|
4
4
|
"description": "Misc. JS/TS helpers used by Reykjavík City's web dev teams.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"repository": "ssh://git@github.com:reykjavikcity/webtools.git",
|
|
@@ -64,6 +64,10 @@
|
|
|
64
64
|
"import": "./esm/fixIcelandicLocale.js",
|
|
65
65
|
"require": "./fixIcelandicLocale.js"
|
|
66
66
|
},
|
|
67
|
+
"./errorhandling": {
|
|
68
|
+
"import": "./esm/errorhandling.js",
|
|
69
|
+
"require": "./errorhandling.js"
|
|
70
|
+
},
|
|
67
71
|
"./remix/http": {
|
|
68
72
|
"import": "./esm/remix/http.js",
|
|
69
73
|
"require": "./remix/http.js"
|
package/vanillaExtract.d.ts
CHANGED
|
@@ -20,27 +20,131 @@ export declare const vanillaProps: (css: string) => GlobalStyleRule;
|
|
|
20
20
|
export declare function vanillaClass(css: string | ((className: string) => string)): string;
|
|
21
21
|
export declare function vanillaClass(debugId: string, css: string | ((className: string) => string)): string;
|
|
22
22
|
/**
|
|
23
|
+
* @deprecated (Will be removed in v0.2)
|
|
24
|
+
*
|
|
23
25
|
* Replaces all `&` tokens with the given selector string, in a direct
|
|
24
26
|
* (read. "dumb") way. It's mainly useful when used with style-mixins, etc.
|
|
25
27
|
*
|
|
26
|
-
* NOTE
|
|
27
|
-
* It will also replace
|
|
28
|
+
* **NOTE:** `vanillaNest` does NOT support deeply nested blocks, or anything
|
|
29
|
+
* so fancy. It will also replace `&` characters inside values, comments, etc.
|
|
28
30
|
* If you need something more sophisticated, use a custom `postcss` config.
|
|
29
31
|
*
|
|
32
|
+
* ```ts
|
|
33
|
+
* // someCssHelper.ts
|
|
34
|
+
* import { vanillaNest } from '@reykjavik/webtools/vanillaExtract';
|
|
35
|
+
*
|
|
36
|
+
* export const hoverGlow = (
|
|
37
|
+
* ampSelector: string,
|
|
38
|
+
* glowiness?: 'normal' | 'insane'
|
|
39
|
+
* ) =>
|
|
40
|
+
* vanillaNest(
|
|
41
|
+
* ampSelector,
|
|
42
|
+
* `
|
|
43
|
+
* &:hover {
|
|
44
|
+
* box-shadow: 0 0 20px 5px ${
|
|
45
|
+
* glowiness === 'insane' ? 'hotpink' : 'salmon'
|
|
46
|
+
* };
|
|
47
|
+
* }
|
|
48
|
+
* `
|
|
49
|
+
* );
|
|
50
|
+
*
|
|
51
|
+
* // ...then, somewhere else in a *.css.ts file:
|
|
52
|
+
*
|
|
53
|
+
* import { hoverGlow } from '~/someCssHelper.js';
|
|
54
|
+
* import { vanillaGlobal } from '@reykjavik/webtools/vanillaExtract';
|
|
55
|
+
*
|
|
56
|
+
* vanillaGlobal(`
|
|
57
|
+
* .MyComponent {
|
|
58
|
+
* border: 1px solid #ccc;
|
|
59
|
+
* padding: 1em;
|
|
60
|
+
* }
|
|
61
|
+
* ${hoverGlow('.MyComponent')}
|
|
62
|
+
*
|
|
63
|
+
* .MyOtherComponent {
|
|
64
|
+
* border: 1px solid #ccc;
|
|
65
|
+
* padding: 1em;
|
|
66
|
+
* }
|
|
67
|
+
* ${hoverGlow('.MyOtherComponent', 'insane')}
|
|
68
|
+
* `);
|
|
69
|
+
* ```
|
|
30
70
|
*
|
|
31
|
-
*
|
|
71
|
+
* (This low-level utility function is used internally by `vanillaClassNested`.
|
|
32
72
|
*/
|
|
33
73
|
export declare const vanillaNest: (ampSelector: string, css: string) => string;
|
|
34
74
|
/**
|
|
75
|
+
* @deprecated (Will be removed in v0.2)
|
|
76
|
+
*
|
|
35
77
|
* Returns a scoped cssClassName styled with free-form CSS.
|
|
36
78
|
*
|
|
37
79
|
* It also automatically replaces all `&`-tokens with
|
|
38
80
|
* the selector for the auto-generated class-name.
|
|
39
81
|
*
|
|
40
|
-
*
|
|
82
|
+
* ```ts
|
|
83
|
+
* // someFile.css.ts
|
|
84
|
+
* import { vanillaClassNested } from '@reykjavik/webtools/vanillaExtract';
|
|
85
|
+
*
|
|
86
|
+
* export const myClass = vanillaClassNested(`
|
|
87
|
+
* background-color: #ccc;
|
|
88
|
+
* padding: .5em 1em;
|
|
89
|
+
*
|
|
90
|
+
* /* Nested blocks begin: */
|
|
91
|
+
* &:hover {
|
|
92
|
+
* background-color: #666;
|
|
93
|
+
* color: white;
|
|
94
|
+
* }
|
|
95
|
+
* & > strong {
|
|
96
|
+
* color: maroon;
|
|
97
|
+
* }
|
|
98
|
+
* html[data-color-theme="unicorn"] & {
|
|
99
|
+
* background-color: pink;
|
|
100
|
+
* }
|
|
101
|
+
* `);
|
|
102
|
+
* ```
|
|
103
|
+
*
|
|
104
|
+
* **NOTE:** All "bare" (un-nested) style properties **must come first**,
|
|
41
105
|
* before any nested blocks.
|
|
42
106
|
*
|
|
43
|
-
*
|
|
107
|
+
* **NOTE 2:** `vanillaClassNested` does NOT support deeply nested blocks, or
|
|
108
|
+
* anything so fancy. It will also replace `&` characters inside values,
|
|
109
|
+
* comments, etc. If you need something more sophisticated, use a custom
|
|
110
|
+
* `postcss` config.
|
|
44
111
|
*/
|
|
45
112
|
export declare function vanillaClassNested(css: string): string;
|
|
113
|
+
/** @deprecated (Will be removed in v0.2) */
|
|
114
|
+
/**
|
|
115
|
+
* Returns a scoped cssClassName styled with free-form CSS.
|
|
116
|
+
*
|
|
117
|
+
* It also automatically replaces all `&`-tokens with
|
|
118
|
+
* the selector for the auto-generated class-name.
|
|
119
|
+
*
|
|
120
|
+
* ```ts
|
|
121
|
+
* // someFile.css.ts
|
|
122
|
+
* import { vanillaClassNested } from '@reykjavik/webtools/vanillaExtract';
|
|
123
|
+
*
|
|
124
|
+
* export const myClass = vanillaClassNested(`
|
|
125
|
+
* background-color: #ccc;
|
|
126
|
+
* padding: .5em 1em;
|
|
127
|
+
*
|
|
128
|
+
* /* Nested blocks begin: */
|
|
129
|
+
* &:hover {
|
|
130
|
+
* background-color: #666;
|
|
131
|
+
* color: white;
|
|
132
|
+
* }
|
|
133
|
+
* & > strong {
|
|
134
|
+
* color: maroon;
|
|
135
|
+
* }
|
|
136
|
+
* html[data-color-theme="unicorn"] & {
|
|
137
|
+
* background-color: pink;
|
|
138
|
+
* }
|
|
139
|
+
* `);
|
|
140
|
+
* ```
|
|
141
|
+
*
|
|
142
|
+
* **NOTE:** All "bare" (un-nested) style properties **must come first**,
|
|
143
|
+
* before any nested blocks.
|
|
144
|
+
*
|
|
145
|
+
* **NOTE 2:** `vanillaClassNested` does NOT support deeply nested blocks, or
|
|
146
|
+
* anything so fancy. It will also replace `&` characters inside values,
|
|
147
|
+
* comments, etc. If you need something more sophisticated, use a custom
|
|
148
|
+
* `postcss` config.
|
|
149
|
+
*/
|
|
46
150
|
export declare function vanillaClassNested(debugId: string, css: string): string;
|