@sparkwire/utils 0.0.0-stage → 0.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/dist/index.d.mts +27 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +66 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +42 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +43 -4
- package/README.md +0 -3
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ElementType, ComponentPropsWithRef } from 'react';
|
|
3
|
+
|
|
4
|
+
interface SlotProps {
|
|
5
|
+
[slotName: string]: React.ReactNode;
|
|
6
|
+
}
|
|
7
|
+
interface ApplySlotsProps<C extends React.ElementType> {
|
|
8
|
+
slots: SlotProps;
|
|
9
|
+
component: React.ReactElement<any, C>;
|
|
10
|
+
}
|
|
11
|
+
declare function applySlots<T extends React.ElementType>({ slots, component, }: ApplySlotsProps<T>): React.ReactElement;
|
|
12
|
+
|
|
13
|
+
/** Convert `#RGB` / `#RRGGBB` to an `rgba()` string with the given alpha. */
|
|
14
|
+
declare function alpha(hex: string, opacity: number): string;
|
|
15
|
+
/** True when the user asked the OS to reduce motion. Safe during SSR. */
|
|
16
|
+
declare function prefersReducedMotion(): boolean;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Props of a polymorphic component: the component's own props, plus the props
|
|
20
|
+
* of the element it renders as (minus any the component redefines).
|
|
21
|
+
*/
|
|
22
|
+
type OverrideProps<M extends {
|
|
23
|
+
props: object;
|
|
24
|
+
defaultComponent: ElementType;
|
|
25
|
+
}, C extends ElementType> = M['props'] & Omit<ComponentPropsWithRef<C>, keyof M['props']>;
|
|
26
|
+
|
|
27
|
+
export { type OverrideProps, alpha, applySlots, prefersReducedMotion };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ElementType, ComponentPropsWithRef } from 'react';
|
|
3
|
+
|
|
4
|
+
interface SlotProps {
|
|
5
|
+
[slotName: string]: React.ReactNode;
|
|
6
|
+
}
|
|
7
|
+
interface ApplySlotsProps<C extends React.ElementType> {
|
|
8
|
+
slots: SlotProps;
|
|
9
|
+
component: React.ReactElement<any, C>;
|
|
10
|
+
}
|
|
11
|
+
declare function applySlots<T extends React.ElementType>({ slots, component, }: ApplySlotsProps<T>): React.ReactElement;
|
|
12
|
+
|
|
13
|
+
/** Convert `#RGB` / `#RRGGBB` to an `rgba()` string with the given alpha. */
|
|
14
|
+
declare function alpha(hex: string, opacity: number): string;
|
|
15
|
+
/** True when the user asked the OS to reduce motion. Safe during SSR. */
|
|
16
|
+
declare function prefersReducedMotion(): boolean;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Props of a polymorphic component: the component's own props, plus the props
|
|
20
|
+
* of the element it renders as (minus any the component redefines).
|
|
21
|
+
*/
|
|
22
|
+
type OverrideProps<M extends {
|
|
23
|
+
props: object;
|
|
24
|
+
defaultComponent: ElementType;
|
|
25
|
+
}, C extends ElementType> = M['props'] & Omit<ComponentPropsWithRef<C>, keyof M['props']>;
|
|
26
|
+
|
|
27
|
+
export { type OverrideProps, alpha, applySlots, prefersReducedMotion };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
5
|
+
|
|
6
|
+
function _interopNamespace(e) {
|
|
7
|
+
if (e && e.__esModule) return e;
|
|
8
|
+
var n = Object.create(null);
|
|
9
|
+
if (e) {
|
|
10
|
+
Object.keys(e).forEach(function (k) {
|
|
11
|
+
if (k !== 'default') {
|
|
12
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
13
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function () { return e[k]; }
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
n.default = e;
|
|
21
|
+
return Object.freeze(n);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
25
|
+
|
|
26
|
+
// src/slots.tsx
|
|
27
|
+
function applySlots({
|
|
28
|
+
slots,
|
|
29
|
+
component
|
|
30
|
+
}) {
|
|
31
|
+
const { children, className, css: componentCss, ...restProps } = component.props;
|
|
32
|
+
return React__namespace.cloneElement(component, {
|
|
33
|
+
...restProps,
|
|
34
|
+
css: componentCss,
|
|
35
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
36
|
+
slots.startIcon && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "slot-startIcon", children: slots.startIcon }),
|
|
37
|
+
slots.avatar && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "slot-avatar", children: slots.avatar }),
|
|
38
|
+
children,
|
|
39
|
+
slots.endIcon && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "slot-endIcon", children: slots.endIcon })
|
|
40
|
+
] })
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// src/color.ts
|
|
45
|
+
function alpha(hex, opacity) {
|
|
46
|
+
let h = hex.replace("#", "");
|
|
47
|
+
if (h.length === 3) {
|
|
48
|
+
h = h.split("").map((c) => c + c).join("");
|
|
49
|
+
}
|
|
50
|
+
const n = parseInt(h, 16);
|
|
51
|
+
if (h.length !== 6 || Number.isNaN(n)) return hex;
|
|
52
|
+
const r = n >> 16 & 255;
|
|
53
|
+
const g = n >> 8 & 255;
|
|
54
|
+
const b = n & 255;
|
|
55
|
+
return `rgba(${r}, ${g}, ${b}, ${opacity})`;
|
|
56
|
+
}
|
|
57
|
+
function prefersReducedMotion() {
|
|
58
|
+
if (typeof window === "undefined" || !window.matchMedia) return false;
|
|
59
|
+
return window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
exports.alpha = alpha;
|
|
63
|
+
exports.applySlots = applySlots;
|
|
64
|
+
exports.prefersReducedMotion = prefersReducedMotion;
|
|
65
|
+
//# sourceMappingURL=index.js.map
|
|
66
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/slots.tsx","../src/color.ts"],"names":["React","jsxs","Fragment","jsx"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAWO,SAAS,UAAA,CAAwC;AAAA,EACtD,KAAA;AAAA,EACA;AACF,CAAA,EAA2C;AACzC,EAAA,MAAM,EAAE,UAAU,SAAA,EAAW,GAAA,EAAK,cAAc,GAAG,SAAA,KAAc,SAAA,CAAU,KAAA;AAE3E,EAAA,OAAaA,8BAAa,SAAA,EAAW;AAAA,IACnC,GAAG,SAAA;AAAA,IACH,GAAA,EAAK,YAAA;AAAA,IACL,0BACEC,eAAA,CAAAC,mBAAA,EAAA,EACG,QAAA,EAAA;AAAA,MAAA,KAAA,CAAM,6BAAaC,cAAA,CAAC,MAAA,EAAA,EAAK,SAAA,EAAU,gBAAA,EAAkB,gBAAM,SAAA,EAAU,CAAA;AAAA,MACrE,MAAM,MAAA,oBAAUA,cAAA,CAAC,UAAK,SAAA,EAAU,aAAA,EAAe,gBAAM,MAAA,EAAO,CAAA;AAAA,MAC5D,QAAA;AAAA,MACA,MAAM,OAAA,oBAAWA,cAAA,CAAC,UAAK,SAAA,EAAU,cAAA,EAAgB,gBAAM,OAAA,EAAQ;AAAA,KAAA,EAClE;AAAA,GAEH,CAAA;AACH;;;AC5BO,SAAS,KAAA,CAAM,KAAa,OAAA,EAAyB;AAC1D,EAAA,IAAI,CAAA,GAAI,GAAA,CAAI,OAAA,CAAQ,GAAA,EAAK,EAAE,CAAA;AAC3B,EAAA,IAAI,CAAA,CAAE,WAAW,CAAA,EAAG;AAClB,IAAA,CAAA,GAAI,CAAA,CACD,KAAA,CAAM,EAAE,CAAA,CACR,GAAA,CAAI,CAAC,CAAA,KAAM,CAAA,GAAI,CAAC,CAAA,CAChB,IAAA,CAAK,EAAE,CAAA;AAAA,EACZ;AACA,EAAA,MAAM,CAAA,GAAI,QAAA,CAAS,CAAA,EAAG,EAAE,CAAA;AACxB,EAAA,IAAI,EAAE,MAAA,KAAW,CAAA,IAAK,OAAO,KAAA,CAAM,CAAC,GAAG,OAAO,GAAA;AAC9C,EAAA,MAAM,CAAA,GAAK,KAAK,EAAA,GAAM,GAAA;AACtB,EAAA,MAAM,CAAA,GAAK,KAAK,CAAA,GAAK,GAAA;AACrB,EAAA,MAAM,IAAI,CAAA,GAAI,GAAA;AACd,EAAA,OAAO,QAAQ,CAAC,CAAA,EAAA,EAAK,CAAC,CAAA,EAAA,EAAK,CAAC,KAAK,OAAO,CAAA,CAAA,CAAA;AAC1C;AAGO,SAAS,oBAAA,GAAgC;AAC9C,EAAA,IAAI,OAAO,MAAA,KAAW,WAAA,IAAe,CAAC,MAAA,CAAO,YAAY,OAAO,KAAA;AAChE,EAAA,OAAO,MAAA,CAAO,UAAA,CAAW,kCAAkC,CAAA,CAAE,OAAA;AAC/D","file":"index.js","sourcesContent":["import * as React from 'react';\n\ninterface SlotProps {\n [slotName: string]: React.ReactNode;\n}\n\ninterface ApplySlotsProps<C extends React.ElementType> {\n slots: SlotProps;\n component: React.ReactElement<any, C>;\n}\n\nexport function applySlots<T extends React.ElementType>({\n slots,\n component,\n}: ApplySlotsProps<T>): React.ReactElement {\n const { children, className, css: componentCss, ...restProps } = component.props;\n\n return React.cloneElement(component, {\n ...restProps,\n css: componentCss,\n children: (\n <>\n {slots.startIcon && <span className=\"slot-startIcon\">{slots.startIcon}</span>}\n {slots.avatar && <span className=\"slot-avatar\">{slots.avatar}</span>}\n {children}\n {slots.endIcon && <span className=\"slot-endIcon\">{slots.endIcon}</span>}\n </>\n ),\n });\n}\n","/** Convert `#RGB` / `#RRGGBB` to an `rgba()` string with the given alpha. */\nexport function alpha(hex: string, opacity: number): string {\n let h = hex.replace('#', '');\n if (h.length === 3) {\n h = h\n .split('')\n .map((c) => c + c)\n .join('');\n }\n const n = parseInt(h, 16);\n if (h.length !== 6 || Number.isNaN(n)) return hex;\n const r = (n >> 16) & 255;\n const g = (n >> 8) & 255;\n const b = n & 255;\n return `rgba(${r}, ${g}, ${b}, ${opacity})`;\n}\n\n/** True when the user asked the OS to reduce motion. Safe during SSR. */\nexport function prefersReducedMotion(): boolean {\n if (typeof window === 'undefined' || !window.matchMedia) return false;\n return window.matchMedia('(prefers-reduced-motion: reduce)').matches;\n}\n"]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
3
|
+
|
|
4
|
+
// src/slots.tsx
|
|
5
|
+
function applySlots({
|
|
6
|
+
slots,
|
|
7
|
+
component
|
|
8
|
+
}) {
|
|
9
|
+
const { children, className, css: componentCss, ...restProps } = component.props;
|
|
10
|
+
return React.cloneElement(component, {
|
|
11
|
+
...restProps,
|
|
12
|
+
css: componentCss,
|
|
13
|
+
children: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
14
|
+
slots.startIcon && /* @__PURE__ */ jsx("span", { className: "slot-startIcon", children: slots.startIcon }),
|
|
15
|
+
slots.avatar && /* @__PURE__ */ jsx("span", { className: "slot-avatar", children: slots.avatar }),
|
|
16
|
+
children,
|
|
17
|
+
slots.endIcon && /* @__PURE__ */ jsx("span", { className: "slot-endIcon", children: slots.endIcon })
|
|
18
|
+
] })
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// src/color.ts
|
|
23
|
+
function alpha(hex, opacity) {
|
|
24
|
+
let h = hex.replace("#", "");
|
|
25
|
+
if (h.length === 3) {
|
|
26
|
+
h = h.split("").map((c) => c + c).join("");
|
|
27
|
+
}
|
|
28
|
+
const n = parseInt(h, 16);
|
|
29
|
+
if (h.length !== 6 || Number.isNaN(n)) return hex;
|
|
30
|
+
const r = n >> 16 & 255;
|
|
31
|
+
const g = n >> 8 & 255;
|
|
32
|
+
const b = n & 255;
|
|
33
|
+
return `rgba(${r}, ${g}, ${b}, ${opacity})`;
|
|
34
|
+
}
|
|
35
|
+
function prefersReducedMotion() {
|
|
36
|
+
if (typeof window === "undefined" || !window.matchMedia) return false;
|
|
37
|
+
return window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export { alpha, applySlots, prefersReducedMotion };
|
|
41
|
+
//# sourceMappingURL=index.mjs.map
|
|
42
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/slots.tsx","../src/color.ts"],"names":[],"mappings":";;;;AAWO,SAAS,UAAA,CAAwC;AAAA,EACtD,KAAA;AAAA,EACA;AACF,CAAA,EAA2C;AACzC,EAAA,MAAM,EAAE,UAAU,SAAA,EAAW,GAAA,EAAK,cAAc,GAAG,SAAA,KAAc,SAAA,CAAU,KAAA;AAE3E,EAAA,OAAa,mBAAa,SAAA,EAAW;AAAA,IACnC,GAAG,SAAA;AAAA,IACH,GAAA,EAAK,YAAA;AAAA,IACL,0BACE,IAAA,CAAA,QAAA,EAAA,EACG,QAAA,EAAA;AAAA,MAAA,KAAA,CAAM,6BAAa,GAAA,CAAC,MAAA,EAAA,EAAK,SAAA,EAAU,gBAAA,EAAkB,gBAAM,SAAA,EAAU,CAAA;AAAA,MACrE,MAAM,MAAA,oBAAU,GAAA,CAAC,UAAK,SAAA,EAAU,aAAA,EAAe,gBAAM,MAAA,EAAO,CAAA;AAAA,MAC5D,QAAA;AAAA,MACA,MAAM,OAAA,oBAAW,GAAA,CAAC,UAAK,SAAA,EAAU,cAAA,EAAgB,gBAAM,OAAA,EAAQ;AAAA,KAAA,EAClE;AAAA,GAEH,CAAA;AACH;;;AC5BO,SAAS,KAAA,CAAM,KAAa,OAAA,EAAyB;AAC1D,EAAA,IAAI,CAAA,GAAI,GAAA,CAAI,OAAA,CAAQ,GAAA,EAAK,EAAE,CAAA;AAC3B,EAAA,IAAI,CAAA,CAAE,WAAW,CAAA,EAAG;AAClB,IAAA,CAAA,GAAI,CAAA,CACD,KAAA,CAAM,EAAE,CAAA,CACR,GAAA,CAAI,CAAC,CAAA,KAAM,CAAA,GAAI,CAAC,CAAA,CAChB,IAAA,CAAK,EAAE,CAAA;AAAA,EACZ;AACA,EAAA,MAAM,CAAA,GAAI,QAAA,CAAS,CAAA,EAAG,EAAE,CAAA;AACxB,EAAA,IAAI,EAAE,MAAA,KAAW,CAAA,IAAK,OAAO,KAAA,CAAM,CAAC,GAAG,OAAO,GAAA;AAC9C,EAAA,MAAM,CAAA,GAAK,KAAK,EAAA,GAAM,GAAA;AACtB,EAAA,MAAM,CAAA,GAAK,KAAK,CAAA,GAAK,GAAA;AACrB,EAAA,MAAM,IAAI,CAAA,GAAI,GAAA;AACd,EAAA,OAAO,QAAQ,CAAC,CAAA,EAAA,EAAK,CAAC,CAAA,EAAA,EAAK,CAAC,KAAK,OAAO,CAAA,CAAA,CAAA;AAC1C;AAGO,SAAS,oBAAA,GAAgC;AAC9C,EAAA,IAAI,OAAO,MAAA,KAAW,WAAA,IAAe,CAAC,MAAA,CAAO,YAAY,OAAO,KAAA;AAChE,EAAA,OAAO,MAAA,CAAO,UAAA,CAAW,kCAAkC,CAAA,CAAE,OAAA;AAC/D","file":"index.mjs","sourcesContent":["import * as React from 'react';\n\ninterface SlotProps {\n [slotName: string]: React.ReactNode;\n}\n\ninterface ApplySlotsProps<C extends React.ElementType> {\n slots: SlotProps;\n component: React.ReactElement<any, C>;\n}\n\nexport function applySlots<T extends React.ElementType>({\n slots,\n component,\n}: ApplySlotsProps<T>): React.ReactElement {\n const { children, className, css: componentCss, ...restProps } = component.props;\n\n return React.cloneElement(component, {\n ...restProps,\n css: componentCss,\n children: (\n <>\n {slots.startIcon && <span className=\"slot-startIcon\">{slots.startIcon}</span>}\n {slots.avatar && <span className=\"slot-avatar\">{slots.avatar}</span>}\n {children}\n {slots.endIcon && <span className=\"slot-endIcon\">{slots.endIcon}</span>}\n </>\n ),\n });\n}\n","/** Convert `#RGB` / `#RRGGBB` to an `rgba()` string with the given alpha. */\nexport function alpha(hex: string, opacity: number): string {\n let h = hex.replace('#', '');\n if (h.length === 3) {\n h = h\n .split('')\n .map((c) => c + c)\n .join('');\n }\n const n = parseInt(h, 16);\n if (h.length !== 6 || Number.isNaN(n)) return hex;\n const r = (n >> 16) & 255;\n const g = (n >> 8) & 255;\n const b = n & 255;\n return `rgba(${r}, ${g}, ${b}, ${opacity})`;\n}\n\n/** True when the user asked the OS to reduce motion. Safe during SSR. */\nexport function prefersReducedMotion(): boolean {\n if (typeof window === 'undefined' || !window.matchMedia) return false;\n return window.matchMedia('(prefers-reduced-motion: reduce)').matches;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,45 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sparkwire/utils",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"types": "dist/index.d.ts",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "tsup",
|
|
8
|
+
"test": "jest"
|
|
9
|
+
},
|
|
10
|
+
"devDependencies": {
|
|
11
|
+
"jest": "^29.0.3",
|
|
12
|
+
"typescript": "^5.0.0",
|
|
13
|
+
"ts-jest": "^29.0.3",
|
|
14
|
+
"@types/jest": "^29.0.3"
|
|
15
|
+
},
|
|
16
|
+
"module": "dist/index.mjs",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"import": "./dist/index.mjs",
|
|
21
|
+
"require": "./dist/index.js"
|
|
22
|
+
},
|
|
23
|
+
"./package.json": "./package.json"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist"
|
|
27
|
+
],
|
|
28
|
+
"sideEffects": false,
|
|
29
|
+
"dependencies": {},
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"react": "^18.2.0 || ^19.0.0",
|
|
32
|
+
"react-dom": "^18.2.0 || ^19.0.0"
|
|
33
|
+
},
|
|
34
|
+
"license": "MIT",
|
|
35
|
+
"repository": {
|
|
36
|
+
"type": "git",
|
|
37
|
+
"url": "git+https://github.com/phoenix-am/spark-ui.git",
|
|
38
|
+
"directory": "packages/utils"
|
|
39
|
+
},
|
|
40
|
+
"homepage": "https://github.com/phoenix-am/spark-ui#readme",
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public",
|
|
43
|
+
"provenance": true
|
|
44
|
+
}
|
|
45
|
+
}
|
package/README.md
DELETED