@reykjavik/webtools 0.1.26 → 0.1.28
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 +15 -0
- package/README.md +26 -5
- package/esm/http.d.ts +2 -2
- package/esm/http.js +3 -9
- package/esm/vanillaExtract.d.ts +2 -2
- package/esm/vanillaExtract.js +5 -0
- package/http.d.ts +2 -2
- package/http.js +3 -9
- package/package.json +1 -1
- package/vanillaExtract.d.ts +2 -2
- package/vanillaExtract.js +5 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,21 @@
|
|
|
4
4
|
|
|
5
5
|
- ... <!-- Add new lines here. -->
|
|
6
6
|
|
|
7
|
+
## 0.1.28
|
|
8
|
+
|
|
9
|
+
_2024-08-26_
|
|
10
|
+
|
|
11
|
+
- `@reykjavik/webtools/http`:
|
|
12
|
+
- feat: `cacheControl` now also accepts `Map<string, string>` for headers
|
|
13
|
+
|
|
14
|
+
## 0.1.27
|
|
15
|
+
|
|
16
|
+
_2024-07-18_
|
|
17
|
+
|
|
18
|
+
- `@reykjavik/webtools/next/vanillaExtract`:
|
|
19
|
+
- feat: `vanillaClass` now accepts a function that receives the generated
|
|
20
|
+
`className` as parameter
|
|
21
|
+
|
|
7
22
|
## 0.1.26
|
|
8
23
|
|
|
9
24
|
_2024-05-25_
|
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# @reykjavik/webtools
|
|
1
|
+
# @reykjavik/webtools <!-- omit from toc -->
|
|
2
2
|
|
|
3
3
|
Miscellaneous JavaScript/TypeScript helpers used by Reykjavík City's web dev
|
|
4
4
|
teams.
|
|
@@ -112,10 +112,10 @@ codes, are also available:
|
|
|
112
112
|
### `cacheControl` helper
|
|
113
113
|
|
|
114
114
|
**Syntax:**
|
|
115
|
-
`cacheConrol(response: ServerResponse | { res: ServerResponse }, ttlCfg: TTLConfig, eTag?: string|number): void`
|
|
115
|
+
`cacheConrol(response: ServerResponse | Response | Map<string, string> | { res: ServerResponse | Response }, ttlCfg: TTLConfig, eTag?: string|number): void`
|
|
116
116
|
|
|
117
117
|
Use this function to quickly set the `Cache-Control` header with a `max-age=`
|
|
118
|
-
on a HTTP response.
|
|
118
|
+
on a HTTP response (or a `Map` object representing response headers).
|
|
119
119
|
|
|
120
120
|
```js
|
|
121
121
|
import { cacheControl } from '@reykjavik/webtools/http';
|
|
@@ -530,8 +530,10 @@ const myStyle = style({
|
|
|
530
530
|
|
|
531
531
|
### `vanillaClass`
|
|
532
532
|
|
|
533
|
-
**Syntax:**
|
|
534
|
-
|
|
533
|
+
**Syntax:**
|
|
534
|
+
`vanillaClass(css: string | ((className: string) => string)): string`
|
|
535
|
+
**Syntax:**
|
|
536
|
+
`vanillaClass(debugId: string, css: string | ((className: string) => string)): string`
|
|
535
537
|
|
|
536
538
|
Returns a scoped cssClassName styled with free-form CSS. This function is a
|
|
537
539
|
thin wrapper around vanilla-extract's `style` function.
|
|
@@ -545,6 +547,25 @@ export const myClass = vanillaClass(`
|
|
|
545
547
|
padding: .5em 1em;
|
|
546
548
|
`);
|
|
547
549
|
|
|
550
|
+
// Passing a function to get the generated class name for
|
|
551
|
+
// more complex styles.
|
|
552
|
+
export const myOtherClass = vanillaClass(
|
|
553
|
+
(className) => `
|
|
554
|
+
.${className} {
|
|
555
|
+
background-color: #ccc;
|
|
556
|
+
padding: .5em 1em;
|
|
557
|
+
}
|
|
558
|
+
.${className} > strong {
|
|
559
|
+
color: #c00;
|
|
560
|
+
}
|
|
561
|
+
@media (min-width: 800px) {
|
|
562
|
+
.${className} {
|
|
563
|
+
background-color: #eee;
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
`
|
|
567
|
+
);
|
|
568
|
+
|
|
548
569
|
export const humanReadableClass = vanillaClass(
|
|
549
570
|
'HumanReadable',
|
|
550
571
|
`
|
package/esm/http.d.ts
CHANGED
|
@@ -168,7 +168,7 @@ type ServerResponseStub = Pick<ServerResponse, 'setHeader' | 'getHeader' | 'remo
|
|
|
168
168
|
headers?: Record<string, string | Array<string>>;
|
|
169
169
|
};
|
|
170
170
|
type ResponseStub = {
|
|
171
|
-
headers: Pick<Headers, 'set' | 'get' | 'delete'
|
|
171
|
+
headers: Pick<Headers, 'set' | 'get' | 'delete'>;
|
|
172
172
|
};
|
|
173
173
|
/**
|
|
174
174
|
* Use this function to quickly set the `Cache-Control` header with a `max-age=`
|
|
@@ -176,7 +176,7 @@ type ResponseStub = {
|
|
|
176
176
|
*
|
|
177
177
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#getcssbundleurl
|
|
178
178
|
*/
|
|
179
|
-
export declare const cacheControl: (response: ServerResponseStub | ResponseStub | {
|
|
179
|
+
export declare const cacheControl: (response: ServerResponseStub | ResponseStub | Map<string, string> | {
|
|
180
180
|
res: ServerResponseStub | ResponseStub;
|
|
181
181
|
}, ttlCfg: TTLConfig, eTag?: string | number) => void;
|
|
182
182
|
export {};
|
package/esm/http.js
CHANGED
|
@@ -147,6 +147,9 @@ export const toSec = (ttl) => {
|
|
|
147
147
|
return Math.max(0, Math.round(ttl)) || 0;
|
|
148
148
|
};
|
|
149
149
|
const toRespnseStubHeaders = (response) => {
|
|
150
|
+
if (response instanceof Map) {
|
|
151
|
+
return response;
|
|
152
|
+
}
|
|
150
153
|
if ('headers' in response && !('setHeader' in response)) {
|
|
151
154
|
return response.headers;
|
|
152
155
|
}
|
|
@@ -159,15 +162,6 @@ const toRespnseStubHeaders = (response) => {
|
|
|
159
162
|
return val != null ? `${val}` : null;
|
|
160
163
|
},
|
|
161
164
|
set: (name, value) => response.setHeader(name, value),
|
|
162
|
-
append: (name, value) => {
|
|
163
|
-
const existing = response.getHeader(name);
|
|
164
|
-
if (existing) {
|
|
165
|
-
response.setHeader(name, `${existing}, ${value}`);
|
|
166
|
-
}
|
|
167
|
-
else {
|
|
168
|
-
response.setHeader(name, value);
|
|
169
|
-
}
|
|
170
|
-
},
|
|
171
165
|
delete: (name) => response.removeHeader(name),
|
|
172
166
|
};
|
|
173
167
|
};
|
package/esm/vanillaExtract.d.ts
CHANGED
|
@@ -17,8 +17,8 @@ export declare const vanillaProps: (css: string) => GlobalStyleRule;
|
|
|
17
17
|
*
|
|
18
18
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#vanillaclass
|
|
19
19
|
*/
|
|
20
|
-
export declare function vanillaClass(css: string): string;
|
|
21
|
-
export declare function vanillaClass(debugId: string, css: string): string;
|
|
20
|
+
export declare function vanillaClass(css: string | ((className: string) => string)): string;
|
|
21
|
+
export declare function vanillaClass(debugId: string, css: string | ((className: string) => string)): string;
|
|
22
22
|
/**
|
|
23
23
|
* Replaces all `&` tokens with the given selector string, in a direct
|
|
24
24
|
* (read. "dumb") way. It's mainly useful when used with style-mixins, etc.
|
package/esm/vanillaExtract.js
CHANGED
|
@@ -16,6 +16,11 @@ export const vanillaProps = (css) => ({ x: `; ${css}` });
|
|
|
16
16
|
export function vanillaClass(cssOrDebugId, css) {
|
|
17
17
|
const debugId = css != null ? cssOrDebugId : undefined;
|
|
18
18
|
css = css != null ? css : cssOrDebugId;
|
|
19
|
+
if (typeof css === 'function') {
|
|
20
|
+
const className = style({}, debugId);
|
|
21
|
+
vanillaGlobal(css(className));
|
|
22
|
+
return className;
|
|
23
|
+
}
|
|
19
24
|
return style(vanillaProps(css), debugId);
|
|
20
25
|
}
|
|
21
26
|
// ---------------------------------------------------------------------------
|
package/http.d.ts
CHANGED
|
@@ -168,7 +168,7 @@ type ServerResponseStub = Pick<ServerResponse, 'setHeader' | 'getHeader' | 'remo
|
|
|
168
168
|
headers?: Record<string, string | Array<string>>;
|
|
169
169
|
};
|
|
170
170
|
type ResponseStub = {
|
|
171
|
-
headers: Pick<Headers, 'set' | 'get' | 'delete'
|
|
171
|
+
headers: Pick<Headers, 'set' | 'get' | 'delete'>;
|
|
172
172
|
};
|
|
173
173
|
/**
|
|
174
174
|
* Use this function to quickly set the `Cache-Control` header with a `max-age=`
|
|
@@ -176,7 +176,7 @@ type ResponseStub = {
|
|
|
176
176
|
*
|
|
177
177
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#getcssbundleurl
|
|
178
178
|
*/
|
|
179
|
-
export declare const cacheControl: (response: ServerResponseStub | ResponseStub | {
|
|
179
|
+
export declare const cacheControl: (response: ServerResponseStub | ResponseStub | Map<string, string> | {
|
|
180
180
|
res: ServerResponseStub | ResponseStub;
|
|
181
181
|
}, ttlCfg: TTLConfig, eTag?: string | number) => void;
|
|
182
182
|
export {};
|
package/http.js
CHANGED
|
@@ -152,6 +152,9 @@ const toSec = (ttl) => {
|
|
|
152
152
|
};
|
|
153
153
|
exports.toSec = toSec;
|
|
154
154
|
const toRespnseStubHeaders = (response) => {
|
|
155
|
+
if (response instanceof Map) {
|
|
156
|
+
return response;
|
|
157
|
+
}
|
|
155
158
|
if ('headers' in response && !('setHeader' in response)) {
|
|
156
159
|
return response.headers;
|
|
157
160
|
}
|
|
@@ -164,15 +167,6 @@ const toRespnseStubHeaders = (response) => {
|
|
|
164
167
|
return val != null ? `${val}` : null;
|
|
165
168
|
},
|
|
166
169
|
set: (name, value) => response.setHeader(name, value),
|
|
167
|
-
append: (name, value) => {
|
|
168
|
-
const existing = response.getHeader(name);
|
|
169
|
-
if (existing) {
|
|
170
|
-
response.setHeader(name, `${existing}, ${value}`);
|
|
171
|
-
}
|
|
172
|
-
else {
|
|
173
|
-
response.setHeader(name, value);
|
|
174
|
-
}
|
|
175
|
-
},
|
|
176
170
|
delete: (name) => response.removeHeader(name),
|
|
177
171
|
};
|
|
178
172
|
};
|
package/package.json
CHANGED
package/vanillaExtract.d.ts
CHANGED
|
@@ -17,8 +17,8 @@ export declare const vanillaProps: (css: string) => GlobalStyleRule;
|
|
|
17
17
|
*
|
|
18
18
|
* @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#vanillaclass
|
|
19
19
|
*/
|
|
20
|
-
export declare function vanillaClass(css: string): string;
|
|
21
|
-
export declare function vanillaClass(debugId: string, css: string): string;
|
|
20
|
+
export declare function vanillaClass(css: string | ((className: string) => string)): string;
|
|
21
|
+
export declare function vanillaClass(debugId: string, css: string | ((className: string) => string)): string;
|
|
22
22
|
/**
|
|
23
23
|
* Replaces all `&` tokens with the given selector string, in a direct
|
|
24
24
|
* (read. "dumb") way. It's mainly useful when used with style-mixins, etc.
|
package/vanillaExtract.js
CHANGED
|
@@ -21,6 +21,11 @@ exports.vanillaProps = vanillaProps;
|
|
|
21
21
|
function vanillaClass(cssOrDebugId, css) {
|
|
22
22
|
const debugId = css != null ? cssOrDebugId : undefined;
|
|
23
23
|
css = css != null ? css : cssOrDebugId;
|
|
24
|
+
if (typeof css === 'function') {
|
|
25
|
+
const className = (0, css_1.style)({}, debugId);
|
|
26
|
+
(0, exports.vanillaGlobal)(css(className));
|
|
27
|
+
return className;
|
|
28
|
+
}
|
|
24
29
|
return (0, css_1.style)((0, exports.vanillaProps)(css), debugId);
|
|
25
30
|
}
|
|
26
31
|
exports.vanillaClass = vanillaClass;
|