@reykjavik/webtools 0.2.8 → 0.2.9

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 CHANGED
@@ -4,6 +4,14 @@
4
4
 
5
5
  - ... <!-- Add new lines here. -->
6
6
 
7
+ ## 0.2.9
8
+
9
+ _2025-09-30_
10
+
11
+ - `@reykjavik/webtools/next/vanillaExtract`:
12
+ - feat: Make `vanillaVars` return a type-safe `setVars()` helper to avoid
13
+ offending VSCode's CSS syntax parser too much.
14
+
7
15
  ## 0.2.8
8
16
 
9
17
  _2025-09-17_
package/README.md CHANGED
@@ -847,9 +847,11 @@ editor), but there's a brief summary:
847
847
  `scriptUrl` prop).
848
848
  - `scriptUrl?: string` — The full SiteImprove analytics script URL.
849
849
  (alternative to `accountId` prop).
850
- - `hasConsented?: boolean` — Manual GDPR 'analytics' consent flag. Allows hard
851
- opt-out, but defers to [`CookieHubProvider` values](#usecookiehubconsent) if
852
- they are available.
850
+ - `hasConsented?: boolean` — Manual GDPR 'analytics' consent flag. A `false`
851
+ value allows hard opt-out, but defers to
852
+ [`CookieHubProvider` values](#usecookiehubconsent) if they are available.
853
+ Defaults to `undefined` which means "ask CookieHub if available, otherwise
854
+ no".
853
855
  - `onLoad?: (e: unknown) => void` — Fires when the script has loaded.
854
856
  - `onError?: (e: unknown) => void` — Fires if loading the script failed.
855
857
 
@@ -1186,21 +1188,21 @@ import {
1186
1188
  vanillaGlobal,
1187
1189
  } from '@reykjavik/webtools/vanillaExtract';
1188
1190
 
1189
- export const { varPrimaryColor, varSecondaryColor } = vanillaVars(
1191
+ const { varPrimaryColor, varSecondaryColor, setVars } = vanillaVars(
1190
1192
  'primaryColor',
1191
1193
  'secondaryColor'
1192
1194
  );
1193
1195
 
1194
- vanillaGlobal(`
1195
- :root {
1196
- ${varPrimaryColor}: #ff0000;
1197
- ${varSecondaryColor}: #00ff00;
1198
- }
1199
- body {
1200
- background-color: var(${varPrimaryColor});
1201
- color: var(${varSecondaryColor});
1202
- }
1203
- `);
1196
+ export { varPrimaryColor, varSecondaryColor };
1197
+
1198
+ export const wrapper = vanillaClass(`
1199
+ ${setVars({
1200
+ primaryColor: '#ff0000',
1201
+ secondaryColor: '#00ff00',
1202
+ })}
1203
+ background-color: var(${varPrimaryColor});
1204
+ color: var(${varSecondaryColor});
1205
+ `);
1204
1206
  ```
1205
1207
 
1206
1208
  …and then in your component:
@@ -1213,6 +1215,7 @@ import * as cl from './someFile.css.ts';
1213
1215
  export function MyComponent() {
1214
1216
  return (
1215
1217
  <div
1218
+ className={cl.wrapper}
1216
1219
  style={{
1217
1220
  [cl.varPrimaryColor]: 'yellow',
1218
1221
  [cl.varSecondaryColor]: 'blue',
@@ -37,5 +37,8 @@ export declare function vanillaClass(debugId: string, css: string | ClassNameCal
37
37
  *
38
38
  * @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#vanillacvars
39
39
  */
40
- export declare const vanillaVars: <T extends string>(...varNames: Array<T>) => Record<`var${Capitalize<T>}`, string>;
40
+ export declare const vanillaVars: <T extends string>(...varNames: Array<T>) => Record<`var${Capitalize<T>}`, string> & {
41
+ /** Allows initializing all or some of the variables in CSS, without offending VSCode's CSS syntax parser too much. */
42
+ setVars: (vars: Partial<Record<T, unknown>>) => string;
43
+ };
41
44
  export {};
@@ -36,8 +36,12 @@ export function vanillaClass(cssOrDebugId, css) {
36
36
  export const vanillaVars = (...varNames) => {
37
37
  const id = vanillaClass(``);
38
38
  const vars = {};
39
+ vars.setVars = (vars) => Object.entries(vars)
40
+ .map(([name, value]) => `--${id}--${name}: ${value || ''};`)
41
+ .join('\n');
39
42
  for (const name of varNames) {
40
43
  vars[`var${capitalize(name)}`] = `--${id}--${name}`;
41
44
  }
42
45
  return vars;
43
46
  };
47
+ const { varColor, varBg, setVars } = vanillaVars('color', 'bg');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reykjavik/webtools",
3
- "version": "0.2.8",
3
+ "version": "0.2.9",
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",
@@ -37,5 +37,8 @@ export declare function vanillaClass(debugId: string, css: string | ClassNameCal
37
37
  *
38
38
  * @see https://github.com/reykjavikcity/webtools/blob/v0.2/README.md#vanillacvars
39
39
  */
40
- export declare const vanillaVars: <T extends string>(...varNames: Array<T>) => Record<`var${Capitalize<T>}`, string>;
40
+ export declare const vanillaVars: <T extends string>(...varNames: Array<T>) => Record<`var${Capitalize<T>}`, string> & {
41
+ /** Allows initializing all or some of the variables in CSS, without offending VSCode's CSS syntax parser too much. */
42
+ setVars: (vars: Partial<Record<T, unknown>>) => string;
43
+ };
41
44
  export {};
package/vanillaExtract.js CHANGED
@@ -42,9 +42,13 @@ function vanillaClass(cssOrDebugId, css) {
42
42
  const vanillaVars = (...varNames) => {
43
43
  const id = vanillaClass(``);
44
44
  const vars = {};
45
+ vars.setVars = (vars) => Object.entries(vars)
46
+ .map(([name, value]) => `--${id}--${name}: ${value || ''};`)
47
+ .join('\n');
45
48
  for (const name of varNames) {
46
49
  vars[`var${(0, hanna_utils_1.capitalize)(name)}`] = `--${id}--${name}`;
47
50
  }
48
51
  return vars;
49
52
  };
50
53
  exports.vanillaVars = vanillaVars;
54
+ const { varColor, varBg, setVars } = (0, exports.vanillaVars)('color', 'bg');