@leancodepl/styled-tools 8.3.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 ADDED
@@ -0,0 +1,7 @@
1
+ # styled-tools
2
+
3
+ This library was generated with [Nx](https://nx.dev).
4
+
5
+ ## Running unit tests
6
+
7
+ Run `nx test styled-tools` to execute the unit tests via [Jest](https://jestjs.io).
package/index.cjs.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "./src/index";
@@ -0,0 +1 @@
1
+ exports._default = require('./index.cjs.js').default;
package/index.cjs.js ADDED
@@ -0,0 +1,37 @@
1
+ 'use strict';
2
+
3
+ var styledComponents = require('styled-components');
4
+
5
+ function mkProxy(accessor) {
6
+ var cache = {};
7
+ return new Proxy(accessor, {
8
+ get: function get(target, property) {
9
+ var _cache, _property;
10
+ if (property === "prototype") {
11
+ return Function.prototype;
12
+ }
13
+ var _;
14
+ (_ = (_cache = cache)[_property = property]) !== null && _ !== void 0 ? _ : _cache[_property] = mkProxy(function(context) {
15
+ var value = target(context);
16
+ return guard(value) ? value === null || value === void 0 ? void 0 : value[property] : undefined;
17
+ });
18
+ return cache[property];
19
+ }
20
+ });
21
+ }
22
+ function guard(value) {
23
+ return typeof value === "object";
24
+ }
25
+
26
+ function mkTheme() {
27
+ return {
28
+ theme: mkProxy(function(ctx) {
29
+ return ctx.theme;
30
+ }),
31
+ useTheme: function() {
32
+ return styledComponents.useTheme();
33
+ }
34
+ };
35
+ }
36
+
37
+ exports.mkTheme = mkTheme;
package/index.cjs.mjs ADDED
@@ -0,0 +1,2 @@
1
+ export * from './index.cjs.js';
2
+ export { _default as default } from './index.cjs.default.js';
package/index.esm.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "./src/index";
package/index.esm.js ADDED
@@ -0,0 +1,35 @@
1
+ import { useTheme } from 'styled-components';
2
+
3
+ function mkProxy(accessor) {
4
+ var cache = {};
5
+ return new Proxy(accessor, {
6
+ get: function get(target, property) {
7
+ var _cache, _property;
8
+ if (property === "prototype") {
9
+ return Function.prototype;
10
+ }
11
+ var _;
12
+ (_ = (_cache = cache)[_property = property]) !== null && _ !== void 0 ? _ : _cache[_property] = mkProxy(function(context) {
13
+ var value = target(context);
14
+ return guard(value) ? value === null || value === void 0 ? void 0 : value[property] : undefined;
15
+ });
16
+ return cache[property];
17
+ }
18
+ });
19
+ }
20
+ function guard(value) {
21
+ return typeof value === "object";
22
+ }
23
+
24
+ function mkTheme() {
25
+ return {
26
+ theme: mkProxy(function(ctx) {
27
+ return ctx.theme;
28
+ }),
29
+ useTheme: function() {
30
+ return useTheme();
31
+ }
32
+ };
33
+ }
34
+
35
+ export { mkTheme };
package/package.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "@leancodepl/styled-tools",
3
+ "version": "8.3.0",
4
+ "peerDependencies": {
5
+ "styled-components": ">=6.0.0"
6
+ },
7
+ "exports": {
8
+ "./package.json": "./package.json",
9
+ ".": {
10
+ "module": "./index.esm.js",
11
+ "types": "./index.esm.d.ts",
12
+ "import": "./index.cjs.mjs",
13
+ "default": "./index.cjs.js"
14
+ }
15
+ },
16
+ "module": "./index.esm.js",
17
+ "main": "./index.cjs.js",
18
+ "types": "./index.esm.d.ts"
19
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "./lib/mkTheme";
@@ -0,0 +1,5 @@
1
+ import type { ExecutionContext, RuleSet } from "styled-components";
2
+ export declare function mkProxy(accessor: (context: ExecutionContext) => Value): (context: ExecutionContext) => Value;
3
+ export type Value = {
4
+ [key: string | symbol]: Value | undefined;
5
+ } | RuleSet | string | undefined;
@@ -0,0 +1,10 @@
1
+ import { type ExecutionContext, type RuleSet } from "styled-components";
2
+ import { Value } from "./mkProxy";
3
+ export declare function mkTheme<TTheme extends Value>(): {
4
+ theme: TransformDeep<TTheme>;
5
+ useTheme: () => TTheme;
6
+ };
7
+ type TransformDeep<T> = T extends RuleSet ? (context: ExecutionContext) => RuleSet : T extends Array<infer TArrayElement> ? Array<TransformDeep<TArrayElement>> : T extends object ? {
8
+ [TKey in keyof T]: TransformDeep<T[TKey]>;
9
+ } : T extends null ? undefined : (context: ExecutionContext) => T;
10
+ export {};