@nghitrum/dsforge 0.1.5-alpha.1 → 0.1.5-alpha.11

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.
@@ -0,0 +1,118 @@
1
+ // src/lib/license.ts
2
+ import { readFileSync } from "fs";
3
+ import { join } from "path";
4
+ function readKeyFromDotEnv() {
5
+ try {
6
+ const content = readFileSync(join(process.cwd(), ".env"), "utf8");
7
+ for (const raw of content.split("\n")) {
8
+ const line = raw.trim();
9
+ if (!line || line.startsWith("#")) continue;
10
+ const eq = line.indexOf("=");
11
+ if (eq === -1) continue;
12
+ const key = line.slice(0, eq).trim();
13
+ if (key !== "DSFORGE_KEY") continue;
14
+ const val = line.slice(eq + 1).trim().replace(/^["']|["']$/g, "");
15
+ return val || void 0;
16
+ }
17
+ } catch {
18
+ }
19
+ return void 0;
20
+ }
21
+ function isProUnlocked() {
22
+ const key = process.env["DSFORGE_KEY"] ?? readKeyFromDotEnv();
23
+ return typeof key === "string" && key.length > 0;
24
+ }
25
+
26
+ // src/presets/index.ts
27
+ var PRESETS = [
28
+ "compact",
29
+ "comfortable",
30
+ "spacious"
31
+ ];
32
+ var SPACING_PRESETS = {
33
+ compact: {
34
+ "1": 2,
35
+ "2": 4,
36
+ "3": 8,
37
+ "4": 12,
38
+ "5": 16,
39
+ "6": 24,
40
+ "7": 32,
41
+ "8": 48
42
+ },
43
+ comfortable: {
44
+ "1": 4,
45
+ "2": 8,
46
+ "3": 12,
47
+ "4": 16,
48
+ "5": 24,
49
+ "6": 32,
50
+ "7": 48,
51
+ "8": 64
52
+ },
53
+ spacious: {
54
+ "1": 6,
55
+ "2": 12,
56
+ "3": 18,
57
+ "4": 24,
58
+ "5": 36,
59
+ "6": 48,
60
+ "7": 72,
61
+ "8": 96
62
+ }
63
+ };
64
+ var RADIUS_PRESETS = {
65
+ compact: { none: 0, sm: 2, md: 3, lg: 6, xl: 10, full: 9999 },
66
+ comfortable: { none: 0, sm: 2, md: 4, lg: 8, xl: 16, full: 9999 },
67
+ spacious: { none: 0, sm: 3, md: 6, lg: 12, xl: 20, full: 9999 }
68
+ };
69
+ var CONTROL_SIZE_PRESETS = {
70
+ compact: { sm: 12, md: 14, lg: 18 },
71
+ comfortable: { sm: 14, md: 16, lg: 20 },
72
+ spacious: { sm: 16, md: 18, lg: 24 }
73
+ };
74
+ var PRESET_BASE_UNITS = {
75
+ compact: 2,
76
+ comfortable: 4,
77
+ spacious: 6
78
+ };
79
+ function buildSemanticSpacing(scale) {
80
+ return {
81
+ "component-padding-xs": `${scale["1"]}`,
82
+ "component-padding-sm": `${scale["2"]}`,
83
+ "component-padding-md": `${scale["4"]}`,
84
+ "component-padding-lg": `${scale["5"]}`,
85
+ "layout-gap-xs": `${scale["2"]}`,
86
+ "layout-gap-sm": `${scale["3"]}`,
87
+ "layout-gap-md": `${scale["5"]}`,
88
+ "layout-gap-lg": `${scale["6"]}`,
89
+ "layout-section": `${scale["7"]}`
90
+ };
91
+ }
92
+ function applyPreset(config, preset) {
93
+ const scale = SPACING_PRESETS[preset];
94
+ const radius = RADIUS_PRESETS[preset];
95
+ const baseUnit = PRESET_BASE_UNITS[preset];
96
+ config.spacing = {
97
+ ...config.spacing,
98
+ baseUnit,
99
+ scale,
100
+ semantic: buildSemanticSpacing(scale)
101
+ };
102
+ config.radius = { ...config.radius, ...radius };
103
+ config.philosophy = {
104
+ ...config.philosophy,
105
+ density: preset
106
+ };
107
+ }
108
+
109
+ export {
110
+ isProUnlocked,
111
+ PRESETS,
112
+ SPACING_PRESETS,
113
+ RADIUS_PRESETS,
114
+ CONTROL_SIZE_PRESETS,
115
+ PRESET_BASE_UNITS,
116
+ buildSemanticSpacing,
117
+ applyPreset
118
+ };
@@ -22,12 +22,14 @@ function generatePackageJson(config, componentNames) {
22
22
  ),
23
23
  "./tokens": "./tokens/tokens.js",
24
24
  "./tailwind": "./tokens/tailwind.js",
25
- "./metadata": "./metadata/index.json",
26
25
  ...Object.fromEntries(
27
- componentNames.map((c) => [`./metadata/${c}`, `./metadata/${c}.json`])
26
+ componentNames.map((c) => {
27
+ const pascal = c.charAt(0).toUpperCase() + c.slice(1);
28
+ return [`./components/${pascal}`, `./components/${pascal}/${pascal}.json`];
29
+ })
28
30
  )
29
31
  },
30
- files: ["dist", "tokens", "metadata", "docs", "CHANGELOG.md"],
32
+ files: ["dist", "tokens", "components", "CHANGELOG.md"],
31
33
  scripts: {
32
34
  build: "tsc",
33
35
  prepublishOnly: "npm run build"
@@ -67,7 +69,7 @@ function generateTsConfig() {
67
69
  moduleResolution: "NodeNext",
68
70
  lib: ["ES2020", "DOM"],
69
71
  outDir: "./dist",
70
- rootDir: "./src",
72
+ rootDir: ".",
71
73
  declaration: true,
72
74
  declarationMap: true,
73
75
  sourceMap: true,
@@ -76,7 +78,7 @@ function generateTsConfig() {
76
78
  skipLibCheck: true,
77
79
  jsx: "react-jsx"
78
80
  },
79
- include: ["src/**/*"],
81
+ include: ["index.ts", "components/**/*"],
80
82
  exclude: ["node_modules", "dist"]
81
83
  },
82
84
  null,
@@ -125,7 +127,10 @@ function App() {
125
127
  ## Components
126
128
 
127
129
  ${componentNames.map(
128
- (c) => `- **${c.charAt(0).toUpperCase() + c.slice(1)}** \u2014 see \`metadata/${c}.json\` for contract`
130
+ (c) => {
131
+ const pascal = c.charAt(0).toUpperCase() + c.slice(1);
132
+ return `- **${pascal}** \u2014 see \`components/${pascal}/${pascal}.json\` for props and usage`;
133
+ }
129
134
  ).join("\n")}
130
135
 
131
136
  ## Themes
@@ -200,20 +205,10 @@ every semantic and component token that references it.
200
205
 
201
206
  ## AI tool integration
202
207
 
203
- The \`metadata/\` directory contains machine-readable component contracts.
208
+ Each component ships with a machine-readable JSON contract (e.g. \`components/Button/Button.json\`).
204
209
  AI coding assistants (Copilot, Cursor, Claude Code) can read these to
205
210
  generate UI that respects your governance rules automatically.
206
211
 
207
- \`\`\`json
208
- // ${pkgName}/metadata/button.json
209
- {
210
- "component": "Button",
211
- "allowedVariants": ["primary", "secondary", "danger", "ghost"],
212
- "requiredProps": ["aria-label"],
213
- "accessibilityContract": { "keyboard": true, "focusRing": true }
214
- }
215
- \`\`\`
216
-
217
212
  ---
218
213
 
219
214
  Generated by [dsforge](https://github.com/nghitrum/dsforge) v${config.meta.version}.