@css-hooks/core 1.0.1 → 1.1.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.
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
 
8
8
  <p align="center">
9
9
  <a href="https://github.com/css-hooks/css-hooks/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/css-hooks/css-hooks/ci.yml?branch=master" alt="Build Status"></a>
10
- <a href="https://github.com/css-hooks/css-hooks/releases"><img src="https://img.shields.io/npm/v/@css-hooks%2Fcore.svg" alt="Latest Release"></a>
10
+ <a href="https://www.npmjs.com/org/css-hooks"><img src="https://img.shields.io/npm/v/@css-hooks%2Fcore.svg" alt="Latest Release"></a>
11
11
  <a href="https://github.com/css-hooks/css-hooks/blob/master/LICENSE"><img src="https://img.shields.io/npm/l/css-hooks.svg" alt="License"></a>
12
12
  </p>
13
13
 
@@ -50,7 +50,7 @@ Please visit [css-hooks.com](https://css-hooks.com) to get started.
50
50
  - [@css-hooks/react](packages/react): React framework integration
51
51
  - [@css-hooks/solid](packages/solid): Solid framework integration
52
52
  - [@css-hooks/preact](packages/preact): Preact framework integration
53
- - [@css-hooks/core](packages/core): Core package (internal use only)
53
+ - [@css-hooks/core](packages/core): Core package (internal / advanced use cases)
54
54
 
55
55
  ## Contributing
56
56
 
package/cjs/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.recommended = exports.buildHooksSystem = void 0;
3
+ exports.recommended = exports.buildHooksSystem = exports.genericStringify = void 0;
4
4
  function isHookSpec(x) {
5
5
  if (!x) {
6
6
  return false;
@@ -18,7 +18,18 @@ function isHookSpec(x) {
18
18
  }
19
19
  return false;
20
20
  }
21
- function buildHooksSystem(stringify) {
21
+ /** @internal */
22
+ function genericStringify(_, value) {
23
+ if (typeof value === "string") {
24
+ return value;
25
+ }
26
+ if (typeof value === "number") {
27
+ return `${value}`;
28
+ }
29
+ return null;
30
+ }
31
+ exports.genericStringify = genericStringify;
32
+ function buildHooksSystem(stringify = genericStringify) {
22
33
  return function createHooks(config) {
23
34
  const stringifyImpl = (propertyName, value) => {
24
35
  return typeof value === "string" && value.startsWith("var(")
@@ -97,7 +108,7 @@ function buildHooksSystem(stringify) {
97
108
  }),
98
109
  ].join(""),
99
110
  function hooks(properties) {
100
- return hooksImpl(properties);
111
+ return hooksImpl(JSON.parse(JSON.stringify(properties)));
101
112
  },
102
113
  ];
103
114
  };
package/esm/index.js CHANGED
@@ -15,7 +15,17 @@ function isHookSpec(x) {
15
15
  }
16
16
  return false;
17
17
  }
18
- export function buildHooksSystem(stringify) {
18
+ /** @internal */
19
+ export function genericStringify(_, value) {
20
+ if (typeof value === "string") {
21
+ return value;
22
+ }
23
+ if (typeof value === "number") {
24
+ return `${value}`;
25
+ }
26
+ return null;
27
+ }
28
+ export function buildHooksSystem(stringify = genericStringify) {
19
29
  return function createHooks(config) {
20
30
  const stringifyImpl = (propertyName, value) => {
21
31
  return typeof value === "string" && value.startsWith("var(")
@@ -94,7 +104,7 @@ export function buildHooksSystem(stringify) {
94
104
  }),
95
105
  ].join(""),
96
106
  function hooks(properties) {
97
- return hooksImpl(properties);
107
+ return hooksImpl(JSON.parse(JSON.stringify(properties)));
98
108
  },
99
109
  ];
100
110
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@css-hooks/core",
3
3
  "description": "CSS Hooks core library",
4
- "version": "1.0.1",
4
+ "version": "1.1.0",
5
5
  "author": "Nick Saunders",
6
6
  "devDependencies": {
7
7
  "@tsconfig/node-lts": "^18.12.3",
package/types/index.d.ts CHANGED
@@ -6,7 +6,9 @@ export type WithHooks<HookProperties, Properties> = WithHooksImpl<Properties, Ho
6
6
  type WithHooksImpl<Properties, HookProperties, HookPropertiesSub extends HookProperties = HookProperties> = Properties & Partial<UnionToIntersection<HookPropertiesSub extends string ? {
7
7
  [K in HookPropertiesSub]: WithHooksImpl<Properties, Exclude<HookProperties, HookPropertiesSub>>;
8
8
  } : never>>;
9
- export declare function buildHooksSystem<Properties>(stringify: (propertyName: keyof Properties, value: unknown) => string | null): <HookProperties extends string | number | symbol>(config: Record<HookProperties, HookSpec>) => readonly [string, (properties: WithHooks<HookProperties, Properties>) => Properties];
9
+ /** @internal */
10
+ export declare function genericStringify(_: unknown, value: unknown): string | null;
11
+ export declare function buildHooksSystem<Properties = Record<string, unknown>>(stringify?: (propertyName: keyof Properties, value: unknown) => string | null): <HookProperties extends string | number | symbol>(config: Record<HookProperties, HookSpec>) => readonly [string, (properties: WithHooks<HookProperties, Properties>) => Properties];
10
12
  /**
11
13
  * A list of hooks offered as a "sensible default" to solve the most common use cases.
12
14
  */