@css-hooks/qwik 4.0.0-next.9 → 4.0.0-next.93

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/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Nick Saunders
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,35 +1,36 @@
1
1
  <div align="center">
2
- <a id="logomark" href="https://next.css-hooks.com"><img alt="CSS Hooks" src="https://github.com/css-hooks/css-hooks/raw/v4.0.0-next.9/.github/logomark.svg" height="128" /></a><br/><br/>
2
+ <a id="logomark" href="https://next.css-hooks.com"><img alt="CSS Hooks" src="https://github.com/css-hooks/css-hooks/raw/v4.0.0-next.93/.github/logomark.svg" height="128" /></a><br/><br/>
3
3
  <div id="wordmark">
4
- <a href="https://next.css-hooks.com"><img alt="CSS Hooks" src="https://github.com/css-hooks/css-hooks/raw/v4.0.0-next.9/.github/wordmark-dark.svg" width="256"></a>
4
+ <a href="https://next.css-hooks.com"><img alt="CSS Hooks" src="https://github.com/css-hooks/css-hooks/raw/v4.0.0-next.93/.github/wordmark-dark.svg" width="256"></a>
5
5
  </div>
6
6
  </div>
7
7
 
8
8
  <br/>
9
9
 
10
10
  <div align="center" id="badges">
11
- <a href="https://github.com/css-hooks/css-hooks/tree/v4.0.0-next.9"><img src="https://img.shields.io/badge/tag-v4.0.0--next.9-ffd700" alt="tag v4.0.0-next.9"></a>
12
- <a href="https://www.npmjs.com/package/@css-hooks/qwik/v/4.0.0-next.9"><img src="https://img.shields.io/badge/npm-v4.0.0--next.9-ffd700" alt="npm version"></a>
13
- <a href="https://github.com/css-hooks/css-hooks/blob/v4.0.0-next.9/LICENSE"><img src="https://img.shields.io/badge/license-MIT-ffd700" alt="license"></a>
11
+ <a href="https://github.com/css-hooks/css-hooks/tree/v4.0.0-next.93"><img src="https://img.shields.io/badge/tag-v4.0.0--next.93-ffd700" alt="tag v4.0.0-next.93"></a>
12
+ <a href="https://www.npmjs.com/package/@css-hooks/qwik/v/4.0.0-next.93"><img src="https://img.shields.io/badge/npm-v4.0.0--next.93-ffd700" alt="npm version"></a>
13
+ <a href="https://github.com/css-hooks/css-hooks/blob/v4.0.0-next.93/LICENSE"><img src="https://img.shields.io/badge/license-MIT-ffd700" alt="license"></a>
14
14
  </div>
15
15
 
16
16
  ---
17
17
 
18
18
  ## Overview
19
19
 
20
- Hooks add CSS features to native inline styles, enabling you to apply styles
21
- conditionally based on pseudo-classes, custom selectors, media queries, and
22
- more—all without leaving the `style` prop. By exploiting the hidden
23
- programmability of CSS Variables, CSS Hooks delivers a flexible CSS-in-JS
24
- experience without runtime style injection or build steps.
20
+ **CSS power. Inline style simplicity.**
21
+
22
+ Respond to user interaction, layout context, and inherited state. All
23
+ CSS-driven. All without leaving the `style` prop. By exploiting the hidden
24
+ programmability of CSS Variables, CSS Hooks delivers flexible component-owned
25
+ styling without runtime style injection or build steps.
25
26
 
26
27
  ## Feature highlights
27
28
 
28
- ### Pseudo-classes
29
+ ### User interaction
29
30
 
30
31
  ```jsx
31
32
  <button
32
- style={pipe(
33
+ style={mergeStyles(
33
34
  {
34
35
  background: "#004982",
35
36
  color: "#eeeff0",
@@ -46,64 +47,65 @@ experience without runtime style injection or build steps.
46
47
  </button>
47
48
  ```
48
49
 
49
- ### Selectors
50
+ ### Layout context
50
51
 
51
52
  ```jsx
52
- <label>
53
- <input type="checkbox" checked />
54
- <span
55
- style={pipe(
56
- {},
57
- on(":checked + &", {
58
- textDecoration: "line-through",
59
- }),
60
- )}
61
- >
62
- Simplify CSS architecture
63
- </span>
64
- </label>
53
+ <span
54
+ style={mergeStyles(
55
+ { display: "none" },
56
+ on("@container (width >= 50px)", {
57
+ display: "revert-layer",
58
+ }),
59
+ on("@container (width >= 100px)", {
60
+ display: "none",
61
+ }),
62
+ )}
63
+ >
64
+ sm
65
+ </span>
66
+ <span
67
+ style={mergeStyles(
68
+ { display: "none" },
69
+ on("@container (width >= 100px)", {
70
+ display: "revert-layer",
71
+ }),
72
+ )}
73
+ >
74
+ lg
75
+ </span>
65
76
  ```
66
77
 
67
- ### Responsive design
78
+ ### Inherited state
68
79
 
69
80
  ```jsx
70
- <>
81
+ <div style={mergeStyles({ padding: 24 }, on("&:hover", enable("%active")))}>
82
+ Hover parent
71
83
  <span
72
- style={pipe(
73
- {},
74
- on(not("@container (width < 400px)"), {
75
- display: "none",
84
+ style={mergeStyles(
85
+ { color: "gray" },
86
+ on("%active", {
87
+ color: "purple",
76
88
  }),
77
89
  )}
78
90
  >
79
- sm
91
+ Child responds
80
92
  </span>
81
- <span
82
- style={pipe(
83
- {},
84
- on("@container (width < 400px)", {
85
- display: "none",
86
- }),
87
- )}
88
- >
89
- lg
90
- </span>
91
- </>
93
+ </div>
92
94
  ```
93
95
 
94
96
  ## Compatibility
95
97
 
96
- ### Framework integrations
98
+ ### Frameworks
97
99
 
98
- | <img src="https://dl.svgcdn.com/svg/logos/react.svg" alt="React" width="24" height="24" /><br/>React | <img src="https://dl.svgcdn.com/svg/logos/preact.svg" alt="Preact" width="24" height="24" /><br/>Preact | <img src="https://dl.svgcdn.com/svg/logos/solidjs-icon.svg" alt="Solid" width="24" height="24" /><br/>Solid | <img src="https://dl.svgcdn.com/svg/logos/qwik-icon.svg" alt="Qwik" width="24" height="24" /><br/>Qwik |
99
- | :--------------------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------: |
100
- | ✅ | ✅ | ✅ | ✅ |
100
+ | <img src="https://cdn.jsdelivr.net/gh/gilbarbara/logos@37a6b807fd71c622efea27a9309b5d4edc792969/logos/react.svg" alt="React" width="24" height="24" /><br/>React | <img src="https://cdn.jsdelivr.net/gh/gilbarbara/logos@37a6b807fd71c622efea27a9309b5d4edc792969/logos/preact.svg" alt="Preact" width="24" height="24" /><br/>Preact | <img src="https://cdn.jsdelivr.net/gh/gilbarbara/logos@37a6b807fd71c622efea27a9309b5d4edc792969/logos/solidjs-icon.svg" alt="Solid" width="24" height="24" /><br/>Solid | <img src="https://cdn.jsdelivr.net/gh/gilbarbara/logos@37a6b807fd71c622efea27a9309b5d4edc792969/logos/qwik-icon.svg" alt="Qwik" width="24" height="24" /><br/>Qwik |
101
+ | :--------------------------------------------------------------------------------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------------------------------------------: |
102
+ | ✅ | ✅ | ✅ | ✅ |
101
103
 
102
104
  ### Browser support
103
105
 
104
- | <img src="https://dl.svgcdn.com/svg/logos/chrome.svg" alt="Chrome" width="24" height="24" /><br/>Chrome | <img src="https://dl.svgcdn.com/svg/logos/microsoft-edge.svg" alt="Edge" width="24" height="24" /><br/>Edge | <img src="https://dl.svgcdn.com/svg/logos/safari.svg" alt="Safari" width="24" height="24" /><br/>Safari | <img src="https://dl.svgcdn.com/svg/logos/firefox.svg" alt="Firefox" width="24" height="24" /><br/>Firefox | <img src="https://dl.svgcdn.com/svg/logos/opera.svg" alt="Opera" width="24" height="24" /><br/>Opera |
105
- | :-----------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------: |
106
- | 99+ | 99+ | 15.4+ | 97+ | 85+ |
106
+ | <img src="https://cdnjs.cloudflare.com/ajax/libs/browser-logos/74.1.0/chrome/chrome_24x24.png" alt="Chrome" /><br/>Chrome | <img src="https://cdnjs.cloudflare.com/ajax/libs/browser-logos/74.1.0/edge/edge_24x24.png" alt="Edge" /><br/>Edge | <img src="https://cdnjs.cloudflare.com/ajax/libs/browser-logos/74.1.0/safari/safari_24x24.png" alt="Safari" /><br/>Safari | <img src="https://cdnjs.cloudflare.com/ajax/libs/browser-logos/74.1.0/firefox/firefox_24x24.png" alt="Firefox" /><br/>Firefox | <img src="https://cdnjs.cloudflare.com/ajax/libs/browser-logos/74.1.0/opera/opera_24x24.png" alt="Opera" /><br/>Opera |
107
+ | ------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------- |
108
+ | <div align="center">118+</div> | <div align="center">118+</div> | <div align="center">18+</div> | <div align="center">151+</div> | <div align="center">104+</div> |
107
109
 
108
110
  ## Documentation
109
111
 
package/cjs/index.d.ts ADDED
@@ -0,0 +1,23 @@
1
+ /**
2
+ * CSS Hooks for {@link https://qwik.dev | Qwik}
3
+ *
4
+ * @packageDocumentation
5
+ */
6
+ import type { HooksSystem } from "@css-hooks/core";
7
+ import type { CSSProperties } from "@qwik.dev/core" with {
8
+ "resolution-mode": "import"
9
+ };
10
+ import type { CSSPropertyConflicts } from "./css-property-conflicts.ts";
11
+ export type * from "@css-hooks/core";
12
+ export type { CSSPropertyConflicts } from "./css-property-conflicts.ts";
13
+ /** @internal */
14
+ export declare function _stringifyValue(value: unknown, propertyName: string): string | null;
15
+ /**
16
+ * A hook factory configured to use Qwik’s `CSSProperties` type and logic for
17
+ * converting CSS values into strings
18
+ *
19
+ * @public
20
+ */
21
+ export declare const createHooks: import("@css-hooks/core").CreateHooksFn<CSSProperties>;
22
+ /** A style merger configured to use Qwik’s `CSSProperties` type. @public */
23
+ export declare const mergeStyles: HooksSystem<CSSProperties, CSSPropertyConflicts>["mergeStyles"];
package/cjs/index.js CHANGED
@@ -5,9 +5,11 @@
5
5
  * @packageDocumentation
6
6
  */
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
- exports._unitlessNumbers = exports.createHooks = void 0;
8
+ exports.mergeStyles = exports.createHooks = void 0;
9
9
  exports._stringifyValue = _stringifyValue;
10
10
  const core_1 = require("@css-hooks/core");
11
+ /** Unitless properties observed in Chromium, Firefox, and WebKit */
12
+ const UNITLESS = /^(--|(Moz(ForceBrokenImageIcon|TabSize)|lineHeight|tabSize|font(SizeAdjus|Weigh)t|widows|scale|(s|WebkitS)hapeImageThreshold|((border|WebkitMaskBox)Image|maskBorder)(Outset|Slice|Width)?|(Moz|Webkit)Bo(rderImage|x(Flex|OrdinalGroup))|stroke(Dash(array|offset)|Miterlimit|Width)|mathDepth|hyphenateLimit(Char|Line)s|readingOrder|Webkit(BoxFlexGroup|HyphenateLimit(After|Before|Lines)|LineClamp|Perspective)|aspectRatio|(i|WebkitI)nitialLetter|flexLineCount|(a|(Moz|Webkit)A)nimation(IterationCount)?|(c|WebkitC)olumn(s|Count)|(f|WebkitF)lex(Grow|Shrink)?|(o|WebkitO)(pacity|rder)|grid(Area|(Column|Row)(End|Start)?)|(fill|flood|stop|stroke)Opacity|orphans|z(Index|oom))$)/;
11
13
  /** @internal */
12
14
  function _stringifyValue(value, propertyName) {
13
15
  switch (typeof value) {
@@ -19,68 +21,22 @@ function _stringifyValue(value, propertyName) {
19
21
  return null;
20
22
  }
21
23
  }
24
+ const hooksSystem = (0, core_1.createHooksSystem)(_stringifyValue);
22
25
  /**
23
- * A {@link @css-hooks/core#CreateHooksFn} configured to use Qwik's
24
- * `CSSProperties` type and logic for converting CSS values into strings
26
+ * A hook factory configured to use Qwik’s `CSSProperties` type and logic for
27
+ * converting CSS values into strings
25
28
  *
26
29
  * @public
27
30
  */
28
- exports.createHooks = (0, core_1.buildHooksSystem)(_stringifyValue);
29
- /**
30
- * Following code (c) Builder.io. Source modified to account for custom
31
- * properties.
32
- */
33
- /**
34
- * CSS properties which accept numbers but are not in units of "px".
35
- *
36
- * @internal
37
- */
38
- exports._unitlessNumbers = new Set([
39
- "animationIterationCount",
40
- "aspectRatio",
41
- "borderImageOutset",
42
- "borderImageSlice",
43
- "borderImageWidth",
44
- "boxFlex",
45
- "boxFlexGroup",
46
- "boxOrdinalGroup",
47
- "columnCount",
48
- "columns",
49
- "flex",
50
- "flexGrow",
51
- "flexShrink",
52
- "gridArea",
53
- "gridRow",
54
- "gridRowEnd",
55
- "gridRowStart",
56
- "gridColumn",
57
- "gridColumnEnd",
58
- "gridColumnStart",
59
- "fontWeight",
60
- "lineClamp",
61
- "lineHeight",
62
- "opacity",
63
- "order",
64
- "orphans",
65
- "scale",
66
- "tabSize",
67
- "widows",
68
- "zIndex",
69
- "zoom",
70
- "MozAnimationIterationCount", // Known Prefixed Properties
71
- "MozBoxFlex", // TODO: Remove these since they shouldn't be used in modern code
72
- "msFlex",
73
- "msFlexPositive",
74
- "WebkitAnimationIterationCount",
75
- "WebkitBoxFlex",
76
- "WebkitBoxOrdinalGroup",
77
- "WebkitColumnCount",
78
- "WebkitColumns",
79
- "WebkitFlex",
80
- "WebkitFlexGrow",
81
- "WebkitFlexShrink",
82
- "WebkitLineClamp",
83
- ]);
31
+ exports.createHooks = hooksSystem.createHooks;
32
+ /** A style merger configured to use Qwik’s `CSSProperties` type. @public */
33
+ exports.mergeStyles = hooksSystem.mergeStyles;
84
34
  function isUnitlessNumber(name) {
85
- return /^--/.test(name) || exports._unitlessNumbers.has(name);
35
+ if (name.startsWith("--")) {
36
+ return true;
37
+ }
38
+ const camelCaseName = name
39
+ .replace(/^-ms-/, "ms-")
40
+ .replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
41
+ return UNITLESS.test(camelCaseName);
86
42
  }
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}