typewritingclass-react 0.2.0 → 0.2.2

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/dist/index.cjs ADDED
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ useStyle: () => useStyle
24
+ });
25
+ module.exports = __toCommonJS(src_exports);
26
+
27
+ // src/useStyle.ts
28
+ var import_react = require("react");
29
+ var import_typewritingclass = require("typewritingclass");
30
+ function useStyle(...args) {
31
+ return (0, import_react.useMemo)(() => (0, import_typewritingclass.dcx)(...args), args);
32
+ }
33
+ // Annotate the CommonJS export names for ESM import in node:
34
+ 0 && (module.exports = {
35
+ useStyle
36
+ });
@@ -1,8 +1,4 @@
1
- 'use client'
2
-
3
- import { useMemo } from 'react'
4
- import type { StyleRule, DynamicResult } from 'typewritingclass'
5
- import { dcx } from 'typewritingclass'
1
+ import { StyleRule, DynamicResult } from 'typewritingclass';
6
2
 
7
3
  /**
8
4
  * React hook that composes style rules into a `className` + `style` object.
@@ -45,6 +41,6 @@ import { dcx } from 'typewritingclass'
45
41
  * }
46
42
  * ```
47
43
  */
48
- export function useStyle(...args: (StyleRule | string)[]): DynamicResult {
49
- return useMemo(() => dcx(...args), args)
50
- }
44
+ declare function useStyle(...args: (StyleRule | string)[]): DynamicResult;
45
+
46
+ export { useStyle };
@@ -0,0 +1,46 @@
1
+ import { StyleRule, DynamicResult } from 'typewritingclass';
2
+
3
+ /**
4
+ * React hook that composes style rules into a `className` + `style` object.
5
+ *
6
+ * Wraps {@link dcx} in `useMemo` for stable references across re-renders.
7
+ * The returned {@link DynamicResult} object can be spread directly onto JSX
8
+ * elements, providing both the generated class name and any inline CSS custom
9
+ * property bindings needed by `dynamic()` values.
10
+ *
11
+ * The memo dependency array is the `args` array itself, so the result is
12
+ * recalculated only when the input rules or class name strings change.
13
+ *
14
+ * @param args - One or more {@link StyleRule} objects or string class names
15
+ * to compose together.
16
+ * @returns A {@link DynamicResult} with `className` and `style` properties,
17
+ * suitable for spreading onto a JSX element.
18
+ *
19
+ * @example
20
+ * ```tsx
21
+ * import { useStyle } from 'typewritingclass-react'
22
+ * import { p, bg, dynamic } from 'typewritingclass'
23
+ *
24
+ * function Card({ color }: { color: string }) {
25
+ * const props = useStyle(p(6), bg(dynamic(color)))
26
+ * return <div {...props}>Content</div>
27
+ * // Renders: <div class="_a1b _c2d" style="--twc-d0: #ff0000">Content</div>
28
+ * }
29
+ * ```
30
+ *
31
+ * @example
32
+ * ```tsx
33
+ * // Mixing style rules with plain class names
34
+ * import { useStyle } from 'typewritingclass-react'
35
+ * import { p, rounded } from 'typewritingclass'
36
+ *
37
+ * function Badge() {
38
+ * const props = useStyle(p(2), rounded('full'), 'custom-badge')
39
+ * return <span {...props}>New</span>
40
+ * // Renders: <span class="_x1y _z2w custom-badge" style={{}}>New</span>
41
+ * }
42
+ * ```
43
+ */
44
+ declare function useStyle(...args: (StyleRule | string)[]): DynamicResult;
45
+
46
+ export { useStyle };
package/dist/index.js ADDED
@@ -0,0 +1,9 @@
1
+ // src/useStyle.ts
2
+ import { useMemo } from "react";
3
+ import { dcx } from "typewritingclass";
4
+ function useStyle(...args) {
5
+ return useMemo(() => dcx(...args), args);
6
+ }
7
+ export {
8
+ useStyle
9
+ };
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/server.ts
21
+ var server_exports = {};
22
+ __export(server_exports, {
23
+ getStyleSheet: () => getStyleSheet,
24
+ getStyleTag: () => getStyleTag
25
+ });
26
+ module.exports = __toCommonJS(server_exports);
27
+ var import_typewritingclass = require("typewritingclass");
28
+ function getStyleSheet() {
29
+ return (0, import_typewritingclass.generateCSS)();
30
+ }
31
+ function getStyleTag() {
32
+ const css = (0, import_typewritingclass.generateCSS)();
33
+ return `<style data-twc>${css}</style>`;
34
+ }
35
+ // Annotate the CommonJS export names for ESM import in node:
36
+ 0 && (module.exports = {
37
+ getStyleSheet,
38
+ getStyleTag
39
+ });
@@ -1,5 +1,3 @@
1
- import { generateCSS } from 'typewritingclass'
2
-
3
1
  /**
4
2
  * Returns the current generated CSS as a raw stylesheet string.
5
3
  *
@@ -22,10 +20,7 @@ import { generateCSS } from 'typewritingclass'
22
20
  * // "._a1b2c { padding: 1rem; }\n\n._d3e4f { margin: 0; }"
23
21
  * ```
24
22
  */
25
- export function getStyleSheet(): string {
26
- return generateCSS()
27
- }
28
-
23
+ declare function getStyleSheet(): string;
29
24
  /**
30
25
  * Returns the current generated CSS wrapped in a `<style>` tag string,
31
26
  * ready to be injected into an HTML document during SSR.
@@ -56,7 +51,6 @@ export function getStyleSheet(): string {
56
51
  * )
57
52
  * ```
58
53
  */
59
- export function getStyleTag(): string {
60
- const css = generateCSS()
61
- return `<style data-twc>${css}</style>`
62
- }
54
+ declare function getStyleTag(): string;
55
+
56
+ export { getStyleSheet, getStyleTag };
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Returns the current generated CSS as a raw stylesheet string.
3
+ *
4
+ * This reads from the runtime style registry, collecting all rules that
5
+ * have been registered so far and rendering them into a single CSS string.
6
+ * Useful for SSR scenarios where you need the raw CSS to inject into a
7
+ * `<style>` tag or write to a file.
8
+ *
9
+ * This function is safe to call from React Server Components since it
10
+ * does not use any client-side APIs (hooks, DOM, etc.).
11
+ *
12
+ * @returns The full CSS string for all registered style rules, or an
13
+ * empty string if no rules have been registered yet.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * import { getStyleSheet } from 'typewritingclass-react/server'
18
+ *
19
+ * const css = getStyleSheet()
20
+ * // "._a1b2c { padding: 1rem; }\n\n._d3e4f { margin: 0; }"
21
+ * ```
22
+ */
23
+ declare function getStyleSheet(): string;
24
+ /**
25
+ * Returns the current generated CSS wrapped in a `<style>` tag string,
26
+ * ready to be injected into an HTML document during SSR.
27
+ *
28
+ * The style tag includes a `data-twc` attribute for easy identification
29
+ * and potential hydration on the client side.
30
+ *
31
+ * This function is safe to call from React Server Components since it
32
+ * does not use any client-side APIs (hooks, DOM, etc.).
33
+ *
34
+ * @returns An HTML `<style>` tag string containing all registered CSS
35
+ * rules, or an empty `<style>` tag if no rules have been registered.
36
+ *
37
+ * @example
38
+ * ```tsx
39
+ * import { getStyleTag } from 'typewritingclass-react/server'
40
+ *
41
+ * // In a server component or SSR render function:
42
+ * const styleTag = getStyleTag()
43
+ * // '<style data-twc>._a1b2c { padding: 1rem; }</style>'
44
+ *
45
+ * // Inject into the document head
46
+ * return (
47
+ * <html>
48
+ * <head dangerouslySetInnerHTML={{ __html: styleTag }} />
49
+ * <body>{children}</body>
50
+ * </html>
51
+ * )
52
+ * ```
53
+ */
54
+ declare function getStyleTag(): string;
55
+
56
+ export { getStyleSheet, getStyleTag };
package/dist/server.js ADDED
@@ -0,0 +1,13 @@
1
+ // src/server.ts
2
+ import { generateCSS } from "typewritingclass";
3
+ function getStyleSheet() {
4
+ return generateCSS();
5
+ }
6
+ function getStyleTag() {
7
+ const css = generateCSS();
8
+ return `<style data-twc>${css}</style>`;
9
+ }
10
+ export {
11
+ getStyleSheet,
12
+ getStyleTag
13
+ };
package/package.json CHANGED
@@ -1,32 +1,53 @@
1
1
  {
2
2
  "name": "typewritingclass-react",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "type": "module",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/corysimmons/typewritingclass",
8
+ "directory": "packages/typewritingclass-react"
9
+ },
5
10
  "exports": {
6
11
  ".": {
7
- "types": "./src/index.ts",
8
- "default": "./src/index.ts"
12
+ "import": {
13
+ "types": "./dist/index.d.ts",
14
+ "default": "./dist/index.js"
15
+ },
16
+ "require": {
17
+ "types": "./dist/index.d.cts",
18
+ "default": "./dist/index.cjs"
19
+ }
9
20
  },
10
21
  "./server": {
11
- "types": "./src/server.ts",
12
- "default": "./src/server.ts"
22
+ "import": {
23
+ "types": "./dist/server.d.ts",
24
+ "default": "./dist/server.js"
25
+ },
26
+ "require": {
27
+ "types": "./dist/server.d.cts",
28
+ "default": "./dist/server.cjs"
29
+ }
13
30
  }
14
31
  },
32
+ "main": "./dist/index.cjs",
33
+ "module": "./dist/index.js",
34
+ "types": "./dist/index.d.ts",
15
35
  "files": [
16
- "src"
36
+ "dist"
17
37
  ],
18
38
  "peerDependencies": {
19
39
  "react": "^18 || ^19",
20
- "typewritingclass": "0.2.0"
40
+ "typewritingclass": "0.2.6"
21
41
  },
22
42
  "devDependencies": {
23
43
  "react": "^19.0.0",
24
44
  "@types/react": "^19.0.0",
25
45
  "vitest": "^3.0.4",
26
46
  "typescript": "^5.7.3",
27
- "typewritingclass": "0.2.0"
47
+ "typewritingclass": "0.2.6"
28
48
  },
29
49
  "scripts": {
50
+ "build": "tsup",
30
51
  "test": "vitest run",
31
52
  "test:watch": "vitest"
32
53
  }
package/src/index.ts DELETED
@@ -1 +0,0 @@
1
- export { useStyle } from './useStyle.ts'