@tekton-ui/styled 0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Tekton Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, 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,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,76 @@
1
+ # @tekton/styled
2
+
3
+ Token-enforced styled-components wrapper with compile-time and runtime validation.
4
+
5
+ ## Overview
6
+
7
+ Drop-in replacement for styled-components that enforces design token usage and rejects hardcoded CSS values.
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ pnpm add @tekton/styled styled-components
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ```typescript
18
+ import { styled, tokens } from '@tekton/styled';
19
+
20
+ // ✅ Valid: Using tokens
21
+ const Card = styled.div`
22
+ background: ${tokens.bg.surface.elevated};
23
+ padding: ${tokens.spacing[6]};
24
+ border-radius: ${tokens.radius.lg};
25
+ box-shadow: ${tokens.shadow.md};
26
+ `;
27
+
28
+ // ❌ Invalid: Hardcoded values throw runtime errors
29
+ const Bad = styled.div`
30
+ background: #ffffff; // Error: Hardcoded value detected
31
+ padding: 16px; // Error: Hardcoded value detected
32
+ `;
33
+
34
+ // ✅ Valid: Non-token properties work normally
35
+ const Layout = styled.div`
36
+ display: flex;
37
+ flex-direction: column;
38
+ background: ${tokens.bg.surface.default};
39
+ `;
40
+ ```
41
+
42
+ ## Token Accessor
43
+
44
+ The `tokens` accessor provides IDE autocomplete and returns CSS variable references:
45
+
46
+ ```typescript
47
+ tokens.bg.surface.default; // → 'var(--tekton-bg-surface-default)'
48
+ tokens.spacing[4]; // → 'var(--tekton-spacing-4)'
49
+ tokens.fg.primary; // → 'var(--tekton-fg-primary)'
50
+ ```
51
+
52
+ ## Features
53
+
54
+ - **Compile-time Type Safety**: TypeScript enforces token types
55
+ - **Runtime Validation**: Detects hardcoded colors and spacing values
56
+ - **IDE Autocomplete**: Full IntelliSense support for tokens
57
+ - **styled-components Compatible**: Works with all styled-components features
58
+ - **Error Messages**: Clear, actionable error messages with suggestions
59
+
60
+ ## Requirements
61
+
62
+ - REQ-STY-001: Reject hardcoded colors (#fff, rgb(), hsl(), etc.)
63
+ - REQ-STY-002: Reject hardcoded spacing (16px, 2rem, etc.)
64
+ - REQ-STY-003: Provide IDE autocomplete
65
+ - REQ-STY-013: Allow non-token properties (display, position, etc.)
66
+
67
+ ## SPEC Reference
68
+
69
+ - [SPEC-STYLED-001](/.moai/specs/SPEC-STYLED-001/spec.md)
70
+ - TAG-003: Token Accessor
71
+ - TAG-004: Styled Wrapper Core
72
+ - TAG-005: Runtime Validation
73
+
74
+ ## License
75
+
76
+ MIT
@@ -0,0 +1,5 @@
1
+ export { tokens } from './tokens.js';
2
+ export { styled, css, createGlobalStyle } from './styled.js';
3
+ export type { ValidTokenValue } from './styled.js';
4
+ export { validateNoHardcodedValues } from './validation.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAC7D,YAAY,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export { tokens } from './tokens.js';
2
+ export { styled, css, createGlobalStyle } from './styled.js';
3
+ export { validateNoHardcodedValues } from './validation.js';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAE7D,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1,6 @@
1
+ import baseStyled, { css as baseCss, createGlobalStyle as baseCreateGlobalStyle } from 'styled-components';
2
+ import type { TokenReference } from '@tekton-ui/tokens';
3
+ export type ValidTokenValue = TokenReference | string | number | ((props: any) => TokenReference | string | number);
4
+ export declare const styled: typeof baseStyled;
5
+ export { baseCss as css, baseCreateGlobalStyle as createGlobalStyle };
6
+ //# sourceMappingURL=styled.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"styled.d.ts","sourceRoot":"","sources":["../src/styled.ts"],"names":[],"mappings":"AAOA,OAAO,UAAU,EAAE,EACjB,GAAG,IAAI,OAAO,EACd,iBAAiB,IAAI,qBAAqB,EAC3C,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAOxD,MAAM,MAAM,eAAe,GACvB,cAAc,GACd,MAAM,GACN,MAAM,GACN,CAAC,CAAC,KAAK,EAAE,GAAG,KAAK,cAAc,GAAG,MAAM,GAAG,MAAM,CAAC,CAAC;AAOvD,eAAO,MAAM,MAAM,EAAE,OAAO,UAc1B,CAAC;AAmBH,OAAO,EAAE,OAAO,IAAI,GAAG,EAAE,qBAAqB,IAAI,iBAAiB,EAAE,CAAC"}
package/dist/styled.js ADDED
@@ -0,0 +1,22 @@
1
+ import baseStyled, { css as baseCss, createGlobalStyle as baseCreateGlobalStyle, } from 'styled-components';
2
+ import { validateNoHardcodedValues } from './validation.js';
3
+ export const styled = new Proxy(baseStyled, {
4
+ get(target, prop) {
5
+ if (typeof prop === 'symbol' || prop === 'default') {
6
+ return target[prop];
7
+ }
8
+ const component = target[prop];
9
+ if (typeof component === 'function') {
10
+ return createTokenEnforcedStyled(component);
11
+ }
12
+ return component;
13
+ },
14
+ });
15
+ function createTokenEnforcedStyled(styledFn) {
16
+ return (strings, ...values) => {
17
+ validateNoHardcodedValues(strings, values);
18
+ return styledFn(strings, ...values);
19
+ };
20
+ }
21
+ export { baseCss as css, baseCreateGlobalStyle as createGlobalStyle };
22
+ //# sourceMappingURL=styled.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"styled.js","sourceRoot":"","sources":["../src/styled.ts"],"names":[],"mappings":"AAOA,OAAO,UAAU,EAAE,EACjB,GAAG,IAAI,OAAO,EACd,iBAAiB,IAAI,qBAAqB,GAC3C,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAiB5D,MAAM,CAAC,MAAM,MAAM,GAAsB,IAAI,KAAK,CAAC,UAAU,EAAE;IAC7D,GAAG,CAAC,MAAM,EAAE,IAAqB;QAC/B,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACnD,OAAQ,MAAc,CAAC,IAAI,CAAC,CAAC;QAC/B,CAAC;QAED,MAAM,SAAS,GAAI,MAAc,CAAC,IAAI,CAAC,CAAC;QAExC,IAAI,OAAO,SAAS,KAAK,UAAU,EAAE,CAAC;YACpC,OAAO,yBAAyB,CAAC,SAAS,CAAC,CAAC;QAC9C,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;CACF,CAAC,CAAC;AAKH,SAAS,yBAAyB,CAAC,QAAa;IAC9C,OAAO,CAAC,OAA6B,EAAE,GAAG,MAAyB,EAAE,EAAE;QAErE,yBAAyB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAG3C,OAAO,QAAQ,CAAC,OAAO,EAAE,GAAG,MAAM,CAAC,CAAC;IACtC,CAAC,CAAC;AACJ,CAAC;AAMD,OAAO,EAAE,OAAO,IAAI,GAAG,EAAE,qBAAqB,IAAI,iBAAiB,EAAE,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { TektonTokens } from '@tekton-ui/tokens';
2
+ export declare const tokens: TektonTokens;
3
+ //# sourceMappingURL=tokens.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["../src/tokens.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAStD,eAAO,MAAM,MAAM,EAAE,YAInB,CAAC"}
package/dist/tokens.js ADDED
@@ -0,0 +1,29 @@
1
+ export const tokens = new Proxy({}, {
2
+ get(_target, category) {
3
+ return createCategoryProxy(category);
4
+ },
5
+ });
6
+ function createCategoryProxy(category) {
7
+ const target = {};
8
+ return new Proxy(target, {
9
+ get(_target, key) {
10
+ if (key === 'toString' || key === 'valueOf') {
11
+ return () => `var(--tekton-${category})`;
12
+ }
13
+ if (key === Symbol.toPrimitive) {
14
+ return (hint) => {
15
+ if (hint === 'string' || hint === 'default') {
16
+ return `var(--tekton-${category})`;
17
+ }
18
+ return null;
19
+ };
20
+ }
21
+ if (typeof key === 'symbol') {
22
+ return undefined;
23
+ }
24
+ const path = `${category}-${String(key)}`;
25
+ return createCategoryProxy(path);
26
+ },
27
+ });
28
+ }
29
+ //# sourceMappingURL=tokens.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tokens.js","sourceRoot":"","sources":["../src/tokens.ts"],"names":[],"mappings":"AAgBA,MAAM,CAAC,MAAM,MAAM,GAAiB,IAAI,KAAK,CAAC,EAAkB,EAAE;IAChE,GAAG,CAAC,OAAO,EAAE,QAAgB;QAC3B,OAAO,mBAAmB,CAAC,QAAQ,CAAC,CAAC;IACvC,CAAC;CACF,CAAC,CAAC;AAMH,SAAS,mBAAmB,CAAC,QAAgB;IAE3C,MAAM,MAAM,GAAG,EAAE,CAAC;IAElB,OAAO,IAAI,KAAK,CAAC,MAAM,EAAE;QACvB,GAAG,CAAC,OAAO,EAAE,GAAoB;YAE/B,IAAI,GAAG,KAAK,UAAU,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;gBAC5C,OAAO,GAAG,EAAE,CAAC,gBAAgB,QAAQ,GAAG,CAAC;YAC3C,CAAC;YAGD,IAAI,GAAG,KAAK,MAAM,CAAC,WAAW,EAAE,CAAC;gBAC/B,OAAO,CAAC,IAAY,EAAE,EAAE;oBACtB,IAAI,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;wBAC5C,OAAO,gBAAgB,QAAQ,GAAG,CAAC;oBACrC,CAAC;oBACD,OAAO,IAAI,CAAC;gBACd,CAAC,CAAC;YACJ,CAAC;YAGD,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;gBAC5B,OAAO,SAAS,CAAC;YACnB,CAAC;YAGD,MAAM,IAAI,GAAG,GAAG,QAAQ,IAAI,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;YAC1C,OAAO,mBAAmB,CAAC,IAAI,CAAC,CAAC;QACnC,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function validateNoHardcodedValues(strings: TemplateStringsArray, values: any[]): void;
2
+ //# sourceMappingURL=validation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAWA,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,oBAAoB,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,IAAI,CA2E5F"}
@@ -0,0 +1,65 @@
1
+ export function validateNoHardcodedValues(strings, values) {
2
+ let fullTemplate = '';
3
+ for (let i = 0; i < strings.length; i++) {
4
+ fullTemplate += strings[i];
5
+ if (i < values.length) {
6
+ if (typeof values[i] === 'function') {
7
+ fullTemplate += '${...}';
8
+ }
9
+ else {
10
+ fullTemplate += String(values[i]);
11
+ }
12
+ }
13
+ }
14
+ const colorPatterns = [
15
+ {
16
+ regex: /#[0-9a-fA-F]{3,8}\b/g,
17
+ type: 'hex color',
18
+ example: 'tokens.bg.primary.default',
19
+ },
20
+ {
21
+ regex: /rgb\s*\([^)]+\)/gi,
22
+ type: 'rgb() color',
23
+ example: 'tokens.bg.primary.default',
24
+ },
25
+ {
26
+ regex: /rgba\s*\([^)]+\)/gi,
27
+ type: 'rgba() color',
28
+ example: 'tokens.bg.primary.default',
29
+ },
30
+ {
31
+ regex: /hsl\s*\([^)]+\)/gi,
32
+ type: 'hsl() color',
33
+ example: 'tokens.fg.primary',
34
+ },
35
+ {
36
+ regex: /hsla\s*\([^)]+\)/gi,
37
+ type: 'hsla() color',
38
+ example: 'tokens.fg.primary',
39
+ },
40
+ ];
41
+ for (const { regex, type, example } of colorPatterns) {
42
+ const match = regex.exec(fullTemplate);
43
+ if (match) {
44
+ throw new Error(`[Tekton] Hardcoded value detected: ${type} "${match[0]}"\n` +
45
+ `Use tokens instead. Example: ${example}\n` +
46
+ `Template snippet: ${fullTemplate.substring(Math.max(0, match.index - 20), match.index + 40)}...`);
47
+ }
48
+ }
49
+ const spacingPatterns = [
50
+ {
51
+ regex: /(?:padding|margin|gap|top|right|bottom|left|width|height)\s*:\s*\d+px/gi,
52
+ type: 'pixel spacing',
53
+ example: 'tokens.spacing[4]',
54
+ },
55
+ ];
56
+ for (const { regex, type, example } of spacingPatterns) {
57
+ const match = regex.exec(fullTemplate);
58
+ if (match) {
59
+ throw new Error(`[Tekton] Hardcoded value detected: ${type} "${match[0]}"\n` +
60
+ `Use tokens instead. Example: ${example}\n` +
61
+ `Template snippet: ${fullTemplate.substring(Math.max(0, match.index - 20), match.index + 40)}...`);
62
+ }
63
+ }
64
+ }
65
+ //# sourceMappingURL=validation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.js","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAWA,MAAM,UAAU,yBAAyB,CAAC,OAA6B,EAAE,MAAa;IAEpF,IAAI,YAAY,GAAG,EAAE,CAAC;IACtB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACxC,YAAY,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC;QAC3B,IAAI,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC;YAEtB,IAAI,OAAO,MAAM,CAAC,CAAC,CAAC,KAAK,UAAU,EAAE,CAAC;gBACpC,YAAY,IAAI,QAAQ,CAAC;YAC3B,CAAC;iBAAM,CAAC;gBACN,YAAY,IAAI,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;YACpC,CAAC;QACH,CAAC;IACH,CAAC;IAGD,MAAM,aAAa,GAAG;QACpB;YACE,KAAK,EAAE,sBAAsB;YAC7B,IAAI,EAAE,WAAW;YACjB,OAAO,EAAE,2BAA2B;SACrC;QACD;YACE,KAAK,EAAE,mBAAmB;YAC1B,IAAI,EAAE,aAAa;YACnB,OAAO,EAAE,2BAA2B;SACrC;QACD;YACE,KAAK,EAAE,oBAAoB;YAC3B,IAAI,EAAE,cAA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EAAE,KAAK,CAAC,KAAK,GAAG,EAAE,CAAC,KAAK,CACpG,CAAC;QACJ,CAAC;IACH,CAAC;AACH,CAAC"}
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "@tekton-ui/styled",
3
+ "version": "0.3.0",
4
+ "description": "Token-enforced styled-components wrapper with compile-time and runtime validation",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "types": "./dist/index.d.ts"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist",
16
+ "README.md",
17
+ "package.json"
18
+ ],
19
+ "publishConfig": {
20
+ "access": "public",
21
+ "registry": "https://registry.npmjs.org/"
22
+ },
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "https://github.com/soo-kate-yeon/tekton",
26
+ "directory": "packages/styled"
27
+ },
28
+ "dependencies": {
29
+ "styled-components": "^6.1.13",
30
+ "@tekton-ui/tokens": "0.3.0"
31
+ },
32
+ "devDependencies": {
33
+ "@types/node": "^22.10.5",
34
+ "@types/styled-components": "^5.1.34",
35
+ "@typescript-eslint/eslint-plugin": "^8.20.0",
36
+ "@typescript-eslint/parser": "^8.20.0",
37
+ "@vitest/coverage-v8": "^2.1.8",
38
+ "eslint": "^9.18.0",
39
+ "typescript": "^5.7.3",
40
+ "vitest": "^2.1.8"
41
+ },
42
+ "peerDependencies": {
43
+ "styled-components": "^6.0.0"
44
+ },
45
+ "engines": {
46
+ "node": ">=20.0.0"
47
+ },
48
+ "license": "MIT",
49
+ "keywords": [
50
+ "styled-components",
51
+ "design-tokens",
52
+ "token-enforcement",
53
+ "design-system",
54
+ "css-in-js"
55
+ ],
56
+ "scripts": {
57
+ "build": "tsc",
58
+ "test": "vitest run",
59
+ "test:watch": "vitest",
60
+ "test:coverage": "vitest run --coverage",
61
+ "lint": "eslint src __tests__ --ext .ts"
62
+ }
63
+ }