@katlux/toolkit 0.1.1-alpha.129 → 0.1.1-alpha.130

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.
Files changed (90) hide show
  1. package/bin/add-ai-reference.mjs +85 -46
  2. package/dist/module.json +1 -1
  3. package/dist/runtime/components/KButton/KButton.global.d.vue.ts +2 -2
  4. package/dist/runtime/components/KButton/KButton.global.vue.d.ts +2 -2
  5. package/dist/runtime/components/KButton/KButton.logic.d.ts +1 -1
  6. package/dist/runtime/components/KCheckbox/KCheckbox.global.d.vue.ts +1 -1
  7. package/dist/runtime/components/KCheckbox/KCheckbox.global.vue.d.ts +1 -1
  8. package/dist/runtime/components/KCombobox/KCombobox.global.d.vue.ts +1 -1
  9. package/dist/runtime/components/KCombobox/KCombobox.global.vue.d.ts +1 -1
  10. package/dist/runtime/components/KDatatable/KDataIterator.global.d.vue.ts +1 -1
  11. package/dist/runtime/components/KDatatable/KDataIterator.global.vue.d.ts +1 -1
  12. package/dist/runtime/components/KHourPicker/KHourPicker.global.d.vue.ts +1 -1
  13. package/dist/runtime/components/KHourPicker/KHourPicker.global.vue.d.ts +1 -1
  14. package/dist/runtime/components/KRangeSlider/KRangeSlider.global.d.vue.ts +1 -1
  15. package/dist/runtime/components/KRangeSlider/KRangeSlider.global.vue.d.ts +1 -1
  16. package/dist/runtime/components/KSlider/KSlider.global.d.vue.ts +1 -1
  17. package/dist/runtime/components/KSlider/KSlider.global.vue.d.ts +1 -1
  18. package/dist/runtime/components/KTreePicker/KTreePicker.global.d.vue.ts +1 -1
  19. package/dist/runtime/components/KTreePicker/KTreePicker.global.vue.d.ts +1 -1
  20. package/dist/skills/KATLUX_INDEX.md +40 -0
  21. package/dist/skills/katlux-components/SKILL.md +106 -0
  22. package/dist/skills/katlux-components/components/KAccordion.md +27 -0
  23. package/dist/skills/katlux-components/components/KAlert.md +22 -0
  24. package/dist/skills/katlux-components/components/KAreaChart.md +19 -0
  25. package/dist/skills/katlux-components/components/KBarChart.md +20 -0
  26. package/dist/skills/katlux-components/components/KBulkActions.md +19 -0
  27. package/dist/skills/katlux-components/components/KButton.md +12 -0
  28. package/dist/skills/katlux-components/components/KCalendar.md +17 -0
  29. package/dist/skills/katlux-components/components/KCheckbox.md +15 -0
  30. package/dist/skills/katlux-components/components/KCombobox.md +41 -0
  31. package/dist/skills/katlux-components/components/KCompositeInput.md +67 -0
  32. package/dist/skills/katlux-components/components/KContextMenu.md +20 -0
  33. package/dist/skills/katlux-components/components/KDataIterator.md +35 -0
  34. package/dist/skills/katlux-components/components/KDatatable.md +55 -0
  35. package/dist/skills/katlux-components/components/KDatePicker.md +26 -0
  36. package/dist/skills/katlux-components/components/KDropdown.md +18 -0
  37. package/dist/skills/katlux-components/components/KGantt.md +28 -0
  38. package/dist/skills/katlux-components/components/KGrid.md +17 -0
  39. package/dist/skills/katlux-components/components/KHeatMap.md +32 -0
  40. package/dist/skills/katlux-components/components/KHourSelect.md +11 -0
  41. package/dist/skills/katlux-components/components/KIcon.md +5 -0
  42. package/dist/skills/katlux-components/components/KLayout.md +34 -0
  43. package/dist/skills/katlux-components/components/KLineChart.md +18 -0
  44. package/dist/skills/katlux-components/components/KLoader.md +7 -0
  45. package/dist/skills/katlux-components/components/KMaskTextbox.md +12 -0
  46. package/dist/skills/katlux-components/components/KModal.md +22 -0
  47. package/dist/skills/katlux-components/components/KPagination.md +22 -0
  48. package/dist/skills/katlux-components/components/KPanel.md +18 -0
  49. package/dist/skills/katlux-components/components/KPieChart.md +14 -0
  50. package/dist/skills/katlux-components/components/KProductList.md +42 -0
  51. package/dist/skills/katlux-components/components/KScatterChart.md +20 -0
  52. package/dist/skills/katlux-components/components/KSlider.md +28 -0
  53. package/dist/skills/katlux-components/components/KTabs.md +31 -0
  54. package/dist/skills/katlux-components/components/KTextbox.md +15 -0
  55. package/dist/skills/katlux-components/components/KToast.md +14 -0
  56. package/dist/skills/katlux-components/components/KTooltip.md +13 -0
  57. package/dist/skills/katlux-components/components/KTree.md +45 -0
  58. package/dist/skills/katlux-components/components/KTreePicker.md +35 -0
  59. package/dist/skills/katlux-components/components/KTreeView.md +30 -0
  60. package/dist/skills/katlux-components/components/MultiTabs.md +20 -0
  61. package/dist/skills/katlux-components/components/calendar-customization.md +6 -0
  62. package/dist/skills/katlux-components/components/datatable-customization.md +14 -0
  63. package/dist/skills/katlux-components/components/directives.md +11 -0
  64. package/dist/skills/katlux-components/components/form-validation.md +125 -0
  65. package/dist/skills/katlux-components/components/tree-customization.md +9 -0
  66. package/dist/skills/katlux-components/components/useToast.md +27 -0
  67. package/dist/skills/katlux-components/components/validation-directives.md +6 -0
  68. package/dist/skills/katlux-config/SKILL.md +156 -0
  69. package/dist/skills/katlux-presets/SKILL.md +356 -0
  70. package/dist/skills/katlux-providers/SKILL.md +64 -0
  71. package/dist/skills/katlux-providers/providers/ADataProvider.md +59 -0
  72. package/dist/skills/katlux-providers/providers/CAPIFlatClientDataProvider.md +28 -0
  73. package/dist/skills/katlux-providers/providers/CAPIFlatServerDataProvider.md +20 -0
  74. package/dist/skills/katlux-providers/providers/CFlatClientDataProvider.md +11 -0
  75. package/dist/skills/katlux-providers/providers/CFlatServerDataProvider.md +58 -0
  76. package/dist/skills/katlux-providers/providers/CTreeClientDataProvider.md +14 -0
  77. package/dist/skills/katlux-providers/providers/CTreeServerDataProvider.md +5 -0
  78. package/dist/skills/katlux-providers/providers/KatluxIndexedDB.md +10 -0
  79. package/dist/skills/katlux-providers/providers/RequestProvider.md +49 -0
  80. package/dist/skills/katlux-providers/providers/RequestQueue.md +52 -0
  81. package/dist/skills/katlux-providers/providers/api-protocol.md +40 -0
  82. package/dist/skills/katlux-providers/providers/caching.md +170 -0
  83. package/dist/skills/katlux-providers/providers/composables.md +107 -0
  84. package/dist/skills/katlux-providers/providers/encryption.md +151 -0
  85. package/dist/skills/katlux-providers/providers/react-integration.md +45 -0
  86. package/dist/skills/katlux-providers/providers/testing-isolation.md +6 -0
  87. package/dist/skills/katlux-providers/providers/types.md +27 -0
  88. package/dist/skills/katlux-providers/providers/useDataProvider.md +51 -0
  89. package/dist/skills/katlux-tokens/SKILL.md +133 -0
  90. package/package.json +2 -2
@@ -0,0 +1,151 @@
1
+ ### `EncryptionProvider` (`CWebCryptoEncryptionProvider`, `CWebCryptoAESCBCProvider`, `CRSAEncryptionProvider`, `CECDHEncryptionProvider`, `CNodeCryptoEncryptionProvider`, `CKeyManager`, `AEncryptionProvider`)
2
+ Zero-dependency, native cryptographic toolkit for end-to-end client-side, in-flight, and server-side encryption/decryption using native Web Crypto API (`crypto.subtle`) and `node:crypto`. Zero WASM, zero npm dependencies.
3
+
4
+ > [!IMPORTANT]
5
+ > **E2EE Architecture & Threat Model Boundary**:
6
+ > - **Primary Objective**: Provide robust **End-to-End Encryption (E2EE)** to prevent catastrophic server-side data leaks (database dumps, cloud infrastructure compromises, rogue backend admin access). In multi-tenant, multi-user SaaS architectures, all GDPR-protected and sensitive data is stored and relayed exclusively as ciphertext envelopes (`__encrypted: true`).
7
+ > - **Multi-User Role-Based Key Sharing**: Users with appropriate roles (defined in database permissions) can encrypt and decrypt shared tenant data. Roles may contain symmetric keys or wrapped/encrypted keys. Keys may exist in memory or be wrapped for secure transport across the network to client sessions.
8
+ > - **Asymmetric Sender Authenticity Boundary**: Hybrid asymmetric ciphers (`CRSAEncryptionProvider`, `CECDHEncryptionProvider`) provide **recipient confidentiality** (only the holder of the recipient private key can decrypt), but do **not** provide sender authenticity on their own—anyone possessing the recipient public key can encrypt envelopes. In multi-user multi-tenant architectures where write authenticity must be strictly enforced, pair asymmetric encryption with digital signatures (ECDSA/Ed25519) or symmetric tenant role keys (AES-GCM).
9
+ > - **Explicit Non-Goals (Client Endpoint Security)**: The encryption system does **not** protect against client-side compromise (OS-level trojans, hardware keyloggers, screen grabbers, or malicious browser extensions). Once data is legitimately decrypted in client DOM/memory for the authorized user to view, local endpoint security is the user's/device owner's responsibility.
10
+
11
+ > **Showcase Pages**:
12
+ > - **Overview & SSR**: `/providers/request/encryption`
13
+ > - **Symmetric**: `/providers/classes/CWebCryptoEncryptionProvider` (AES-GCM) · `/providers/classes/CWebCryptoAESCBCProvider` (AES-CBC) · `/providers/classes/CNodeCryptoEncryptionProvider` (Node Sync)
14
+ > - **Asymmetric / Hybrid**: `/providers/classes/CRSAEncryptionProvider` (RSA-OAEP) · `/providers/classes/CECDHEncryptionProvider` (ECDH)
15
+ > - **Key Management**: `/providers/classes/CKeyManager`
16
+ > - **Base & Contracts**: `/providers/classes/AEncryptionProvider` · `/providers/interfaces/IEncryptionProvider` · `/providers/interfaces/IProviderEncryptionOptions` · `/providers/interfaces/IKeyPair` · `/providers/interfaces/IKDFOptions` · `/providers/interfaces/IHKDFFromSecretOptions`
17
+
18
+ - **Available Providers**:
19
+ - `CWebCryptoEncryptionProvider`: AES-GCM-256 with optional PBKDF2/HKDF key derivation. Built-in AEAD, 100% backward-compatible.
20
+ - `CWebCryptoAESCBCProvider`: Authenticated AES-CBC-256 + HMAC-SHA-256 (Encrypt-then-MAC) for legacy system compatibility.
21
+ - `CRSAEncryptionProvider`: Asymmetric RSA-OAEP-4096 + AES-GCM-256 hybrid cipher for arbitrary-sized single-recipient payloads.
22
+ - `CECDHEncryptionProvider`: Forward-secure Elliptic Curve Diffie-Hellman (P-256/384/521) + HKDF + AES-GCM. Ephemeral key per encryption. Ideal for multi-user role sharing (e.g. Kazan Ledger Account Symmetric Key wrapping).
23
+ - `CNodeCryptoEncryptionProvider`: Server-side synchronous AES-GCM via `node:crypto` (`encryptSync`/`decryptSync`). 100% binary-interoperable with `CWebCryptoEncryptionProvider`.
24
+ - **Provider Methods (`IEncryptionProvider` / `AEncryptionProvider`)**:
25
+ - `encrypt(data: any, options?: IEncryptionContext): Promise<IEncryptedPayload | any>`: Encrypts data into an envelope or field-encrypted record (strictly idempotent; already-encrypted fields/envelopes are never double-encrypted). Attaches `kid` when specified.
26
+ - `decrypt(payload: any, options?: IEncryptionContext): Promise<any>`: Decrypts envelope back into original data, immediately zeroing plaintext byte buffers in memory. Automatically leverages record-level DEK caching across multi-field records for up to 90% latency reduction.
27
+ - `warmupKey(options?: IEncryptionContext): Promise<void>`: Pre-derives and caches CryptoKey / Buffer in memory. Supported on `CWebCrypto`, `CWebCryptoAESCBC`, and `CNodeCrypto`.
28
+ - `isEncrypted(payload: any): boolean`: Polymorphic check if given object is an encrypted envelope. Also available as static `AEncryptionProvider.isEncrypted(payload)`.
29
+ - `clearKeys() / dispose()`: Wipes in-memory key caches, zeroes mutable Buffer bytes, and clears sensitive asymmetric keys upon logout/session end.
30
+ - `resolveRawKey(keyProvider?: TKeyProvider)`: (Protected on `AEncryptionProvider`) Resolves key or async keyProvider callback. Supports `string`, `Uint8Array`, `ArrayBuffer`, and `CryptoKey` without byte corruption.
31
+ - **PEM Import/Export (`CKeyManager` / `CRSA` / `CECDH`)**:
32
+ - `importPublicKeyFromPEM(pem, ...)`: Imports SPKI PEM string to `CryptoKey`.
33
+ - `importPrivateKeyFromPEM(pem, ...)`: Imports PKCS#8 PEM string to `CryptoKey`.
34
+ - `exportPublicKeyToPEM(key)`: Exports `CryptoKey` to standard SPKI PEM string.
35
+ - `exportPrivateKeyToPEM(key)`: Exports `CryptoKey` to standard PKCS#8 PEM string.
36
+
37
+ - **Envelope Contract (`IEncryptedPayload`)**:
38
+ ```ts
39
+ interface IEncryptedPayload {
40
+ __encrypted: true
41
+ ciphertext: string // Base64 ciphertext (always present)
42
+ alg: string // 'AES-GCM' | 'AES-CBC-256+HMAC-SHA-256' | 'RSA-OAEP-4096+AES-GCM-256' | 'ECDH-P-256+AES-GCM-256'
43
+ kid?: string // Key identifier / version for key rotation tracking
44
+ iv?: string // Base64 IV
45
+ salt?: string // Base64 KDF salt
46
+ kdf?: string // 'PBKDF2' | 'HKDF'
47
+ iter?: number // PBKDF2 iteration count (default: 310,000, clamped [1,000, 600,000])
48
+ tag?: string // Explicit HMAC tag (AES-CBC)
49
+ wrappedKey?: string // Base64 RSA-wrapped AES key (RSA hybrid)
50
+ sharedKey?: boolean // Shared DEK marker for field-level encryption
51
+ epk?: JsonWebKey // Ephemeral public key (ECDH)
52
+ }
53
+ ```
54
+
55
+ - **`IProviderEncryptionOptions`**:
56
+ ```ts
57
+ interface IProviderEncryptionOptions {
58
+ enabled?: boolean // Master toggle (default: false)
59
+ key?: TKeyProvider // string | Uint8Array | ArrayBuffer | CryptoKey | (() => Promise<...>)
60
+ kid?: string // Key identifier / version (e.g. 'v1', 'tenant-a-key-2026')
61
+ decryptOnSSR?: boolean // default: false. Prevents SSR decryption unless explicitly enabled with server secrets
62
+ fields?: string[] // Field-level encryption: only encrypt listed fields
63
+ searchIndex?: boolean // Enables HMAC-SHA256 blind index and trigram search index on encrypted fields
64
+ hmacKey?: TKeyProvider // Optional dedicated HMAC key for search indexing (defaults to encryption key)
65
+ algorithm?: 'AES-GCM' | string // default: 'AES-GCM'
66
+ customProvider?: IEncryptionProvider // Custom cipher adapter (e.g. CRSA, CECDH, AES-CBC)
67
+ kdf?: 'none' | 'pbkdf2' | 'hkdf' // Key derivation strategy:
68
+ // - 'pbkdf2': Recommended for human passphrases/passwords (OWASP recommended rounds)
69
+ // - 'hkdf': For high-entropy IKM / subkey derivation (warns if used with string passwords)
70
+ // - 'none': When supplying pre-derived 256-bit raw keys, Buffers, or CryptoKeys
71
+ kdfIterations?: number // PBKDF2 rounds (default: 310,000 per OWASP, clamped [1,000, 600,000])
72
+ kdfHash?: 'SHA-256' | 'SHA-512' // KDF hash algorithm
73
+ kdfSalt?: string | Uint8Array | ArrayBuffer // Optional static salt (random salt in envelope if omitted)
74
+ publicKey?: CryptoKey // Optional public key for asymmetric encryption
75
+ privateKey?: CryptoKey // Optional private key for asymmetric decryption
76
+ recipientPublicKey?: CryptoKey // Recipient public key for hybrid encryption
77
+ recipientPrivateKey?: CryptoKey // Recipient private key for hybrid decryption
78
+ curve?: 'P-256' | 'P-384' | 'P-521' // Curve for ECDH providers
79
+ info?: string // Optional context/info string for HKDF
80
+ }
81
+ ```
82
+
83
+ - **Factory & Provider Creation**:
84
+ - `createEncryptionProvider(options: IProviderEncryptionOptions): IEncryptionProvider`: Unified factory that instantiates and configures the appropriate cipher provider based on `options.algorithm` (`'AES-GCM'`, `'AES-CBC'`, `'RSA-OAEP'`, `'ECDH'`) or returns `options.customProvider`. Supports `IKeyPair` or individual keys, HKDF info, curve configuration, and KDF options.
85
+
86
+ - **Usage in DataProvider (Client & Server)**:
87
+ Supported uniformly across **all** client and server data providers:
88
+ - **Local (Non-API)**: `CFlatClientDataProvider`, `CTreeClientDataProvider` (via `AEncryptedClientProvider`)
89
+ - **API Client-Side**: `CAPIFlatClientDataProvider`, `CAPITreeClientDataProvider`
90
+ - **Server-Side**: `CAPIFlatServerDataProvider`, `CAPITreeServerDataProvider`
91
+
92
+ #### Local DataProvider Encryption Architecture
93
+ - **Eager Encryption**: `setData(rows)` encrypts designated `fields` immediately before storing in `allData`. Plaintext never persists in `allData`.
94
+ - **Non-blocking Ingestion**: `setDataChunked(rows, { chunkSize: 250, yieldStrategy: 'idle' })` yields between chunks to prevent main-thread freezing on large datasets.
95
+ - **Idempotent Ingestion**: Pre-encrypted envelopes (`__encrypted: true`, e.g. from IndexedDB or Web Workers) pass through untouched without double-encryption.
96
+ - **Lazy Page-Level Decryption**: `loadPageData()` slices `allData` and decrypts only the active page (`pageSize` rows) into `pageData`. Only visible rows are plaintext in memory.
97
+ - **Blind Index Search (`CSearchIndex`)**: When `searchIndex: true`, exact match (`==`, `!=`) and substring search (`in`) operate directly on encrypted fields via deterministic HMAC-SHA256 blind tokens and trigram sets without full dataset decryption.
98
+ - **Zero-Cost Path**: When `enabled` is false, `setData` runs 100% synchronously with zero microtask overhead.
99
+
100
+ ```ts
101
+ import { CFlatClientDataProvider } from '@katlux/providers'
102
+
103
+ const customerProvider = new CFlatClientDataProvider({
104
+ pageSize: 20,
105
+ encryption: {
106
+ enabled: true,
107
+ key: 'secret-key-32-chars-long-12345!',
108
+ kid: 'tenant-key-v1',
109
+ fields: ['ssn', 'salary', 'creditCard'],
110
+ searchIndex: true // Enables search/filter on encrypted fields via CSearchIndex
111
+ }
112
+ })
113
+
114
+ // Eagerly encrypts sensitive fields; leaves id, role, department in plaintext
115
+ await customerProvider.setData(rawEmployees)
116
+
117
+ // Large dataset ingestion with progress reporting:
118
+ await customerProvider.setDataChunked(largeEmployees, {
119
+ chunkSize: 500,
120
+ onProgress: (p) => console.log(`Encryption progress: ${(p * 100).toFixed(0)}%`)
121
+ })
122
+
123
+ // Dynamically rotate key:
124
+ customerProvider.setEncryption({ enabled: true, key: newKey, kid: 'tenant-key-v2', fields: ['ssn', 'salary'] })
125
+
126
+ // Upon user logout / session termination:
127
+ customerProvider.clearEncryption() // Clears keys, zeroes memory, and disables encryption
128
+ ```
129
+
130
+ - **Usage with RequestProvider**:
131
+ ```ts
132
+ const rp = new RequestProvider()
133
+ rp.setEncryption({ enabled: true, key: 'my-secret-32-char-key!!!', kid: 'tenant-key-2026' })
134
+ // Outbound POST/PUT/PATCH bodies encrypted; encrypted responses auto-decrypted
135
+
136
+ // Upon user logout:
137
+ rp.clearEncryption() // Safely clears cached cipher instance, scoped WeakMap instances, and zeroes keys
138
+ ```
139
+
140
+ #### Authenticated Additional Data (AAD) & Security Guarantees
141
+ In multi-tenant, field-encrypted, and SSR scenarios, Katlux cryptographic providers enforce strict, integration-tested security guarantees:
142
+ - **Field & Record Binding**: During value-level and field-level encryption, `AEncryptionProvider` and `CNodeCryptoEncryptionProvider` automatically bind:
143
+ `aad:${baseAad}|record:${recordId}|field:${fieldName}`
144
+ Where `recordId` is extracted from `record.id`, `record._id`, or `options.recordId`.
145
+ - **Transposition Tamper Resistance**: Moving or swapping an encrypted envelope from one database row to another, or from one column (`ssn`) to another (`phone`), causes AES-GCM tag verification to immediately fail with an authentication error.
146
+ - **Cache-at-Rest Full Envelope**: When caching responses where field-level encryption is active (`fields: [...]`), `RequestProvider` automatically wraps the entire object in a full envelope at rest. Neither targeted sensitive fields nor unlisted metadata fields appear as plaintext in raw storage across any client or server cache adapter.
147
+ - **Node GCM 16-Byte Tag Enforcement**: `CNodeCryptoEncryptionProvider` strictly validates a 16-byte (128-bit) authentication tag across all synchronous and asynchronous decryption paths (rejecting truncated 12, 8, or 4-byte tags).
148
+ - **Nonce Misuse Resistance**: Initialization Vectors (IVs) are freshly generated via cryptographically secure RNG per operation (12 bytes for GCM, 16 bytes for CBC) with proven uniqueness across sibling fields, batch arrays, and concurrent executions.
149
+ - **Deterministic Search Token Segregation**: `CSearchIndex` HMAC-SHA256 blind index tokens are deterministic for search matching and strictly segregated from non-deterministic ciphertext IVs.
150
+ - **Non-Extractable Tenant Keys**: `CKeyManager.generateAccountDataKey()` and `CKeyManager.unwrapAccountKeyForUser()` produce `CryptoKey` instances with `extractable: false` by default, safeguarding unwrapped symmetric tenant keys against exfiltration via developer tools or malicious extensions.
151
+ - **SSR Confidentiality & Cache Auth Guard**: With `decryptOnSSR: false` (the secure zero-trust default), plaintext is never exposed in server memory or serialized HTML hydration payloads. Requests with `cookie` or `Authorization` headers automatically bypass shared server caches (`CApplicationCache`), preventing cross-user session cache poisoning.
@@ -0,0 +1,45 @@
1
+ ## 3.2.2. React 18+ Integration: `useSyncExternalStore`
2
+
3
+ Because `ADataProvider` implements `subscribe(listener)` and `getState()`, it integrates natively with React 18+ without any external dependencies:
4
+
5
+ ```tsx
6
+ import { useSyncExternalStore, useMemo } from 'react'
7
+ import { CFlatServerDataProvider } from '@katlux/providers'
8
+
9
+ // Generic React hook for any Katlux DataProvider
10
+ export function useDataProvider(provider) {
11
+ return useSyncExternalStore(
12
+ (onStoreChange) => provider.subscribe(onStoreChange),
13
+ () => provider.getState(),
14
+ () => provider.getState() // SSR snapshot
15
+ )
16
+ }
17
+
18
+ // In any React component
19
+ export function UserTable() {
20
+ const provider = useMemo(() => new CFlatServerDataProvider({
21
+ pageDataHandler: async (page, pageSize, filter, sort) => {
22
+ const res = await fetch(`/api/users?page=${page}&pageSize=${pageSize}`)
23
+ return await res.json()
24
+ }
25
+ }), [])
26
+
27
+ const { pageData, rowCount, loading, currentPage } = useDataProvider(provider)
28
+
29
+ return (
30
+ <div>
31
+ {loading && <div>Loading...</div>}
32
+ <table>
33
+ <tbody>
34
+ {pageData.map(row => <tr key={row.id}><td>{row.name}</td></tr>)}
35
+ </tbody>
36
+ </table>
37
+ <button onClick={() => provider.setCurrentPage(currentPage + 1)}>Next</button>
38
+ </div>
39
+ )
40
+ }
41
+ ```
42
+
43
+ ---
44
+
45
+ ## 3.3. Client-Side Data Providers
@@ -0,0 +1,6 @@
1
+ ### Provider Testing & `nuxtAppCompat` Isolation
2
+ In unit test environments (Vitest), `@katlux/providers/nuxtAppCompat` is aliased to `nuxtAppCompat.server.ts` (stub implementation). This allows unit tests to run fast, deterministic provider assertions without needing a running Nuxt Nitro engine. SSR payload hydration transfers and full browser lifecycle are verified via integration and Playwright E2E test suites.
3
+
4
+ ---
5
+
6
+ ## 3.5. Infrastructure Providers
@@ -0,0 +1,27 @@
1
+ ## 3.1. Core Types & Key Interfaces
2
+
3
+ | Interface / Enum | Purpose | Key Properties / Values |
4
+ | --- | --- | --- |
5
+ | `EDataFilterOperator` | Available filter operators | `Equal` (`==`), `NotEqual` (`!=`), `GreaterThan` (`>`), `LessThan` (`<`), `GreaterThanOrEqual` (`>=`), `LessThanOrEqual` (`<=`), `In`, `NotIn`, `And`, `Or`, `Nand`, `Nor` |
6
+ | `IDataFilter` | Structured filter query | `{ operator: EDataFilterOperator, field: string \| IDataFilter[], active: boolean }` |
7
+ | `IDataSort` | Sorting configuration | `{ field: string, direction: 'asc' \| 'desc' }` |
8
+ | `IDataResult` | Standardized API response | `{ rowCount: number, rows: any[] }` |
9
+ | `ECacheStrategy` | Caching persistence tiers | `Memory`, `ServerSession`, `BrowserSession`, `LocalStorage`, `IndexedDB`, `Cookie`, `Application` |
10
+ | `IDataProviderOptions` | Constructor configuration | See table in §3.2 |
11
+ | `IKDatatableAction` | Row/Bulk action config | `{ label: string, action: Function, icon?: string, iconOnly?: boolean, type?: string, visible?: Function }` |
12
+ | `ITreeNode` | Tree node wrapper | `{ data: any, id: any, parentId: any, depth: number, hasChildren: boolean, isExpanded: boolean }` |
13
+ | `ICompositeItem`| Composite input pair | `{ selection: any, value: any }` (e.g. `{ selection: 'en', value: 'Hello' }`) |
14
+
15
+ ### Standard Data Structure (`IDataResult`)
16
+ All Katlux DataProviders (and components consuming them, such as `KDatatable`, `KLineChart`, `KBarChart`, `KPieChart`, `KCombobox`, etc.) use `IDataResult` as the standard payload format:
17
+ ```typescript
18
+ interface IDataResult<T = any> {
19
+ rowCount: number // Total record count (for pagination math)
20
+ rows: T[] // Array of row item objects
21
+ }
22
+ ```
23
+
24
+ - **`CFlatClientDataProvider.setData(data: TDataRow[])`**: Accepts an array of row objects (`TDataRow[]`) to populate local client-side data.
25
+ - **Provider-Agnostic Integration**: Katlux components (Datatables, Charts, Pickers) do NOT depend on a specific DataProvider class. They accept any DataProvider instance (`CAPIFlatServerDataProvider`, `CFlatClientDataProvider`, `CAPIFlatClientDataProvider`, `RequestProvider`, etc.) or plain reactive arrays. Internal composables (`useChartData`, `useFilterLogic`) automatically extract rows from `.pageData` or `.allData` refs.
26
+
27
+ ---
@@ -0,0 +1,51 @@
1
+ ## 3.2.1. Vue 3 Integration: `useDataProvider` Composable & Pinia Store Sync
2
+
3
+ For idiomatic Vue 3 / Nuxt 3 applications, `@katlux/toolkit` provides the `useDataProvider` bridge composable with built-in bidirectional store syncing:
4
+
5
+ ```typescript
6
+ import { CFlatClientDataProvider } from '@katlux/providers'
7
+ import { useDataProvider } from '#toolkit/composables/useDataProvider'
8
+ import { useCatalogStore } from '~/stores/catalog'
9
+ import { storeToRefs } from 'pinia'
10
+
11
+ const provider = new CFlatClientDataProvider({ pageSize: 10 })
12
+ provider.setData(users)
13
+
14
+ // Optional: Pass external Pinia store refs for bidirectional synchronization
15
+ const store = useCatalogStore()
16
+ const { currentPage, pageSize, filter, sortList } = storeToRefs(store)
17
+
18
+ // Idiomatic Vue 3 refs with automatic scope disposal (no SSR leaks) and recursion-safe two-way syncing:
19
+ const {
20
+ pageData, // ShallowRef<T[]> (current page data)
21
+ virtualRows, // ShallowRef<T[]> (full ordered array of visible rows for virtual scroll)
22
+ rowCount, // Ref<number>
23
+ loading, // Ref<boolean>
24
+ error, // Ref<any>
25
+ currentPage, // Ref<number> (synced with Pinia)
26
+ pageSize, // Ref<number> (synced with Pinia)
27
+ filter, // Ref<IDataFilter | null> (synced with Pinia)
28
+ sortList, // Ref<IDataSort[]> (synced with Pinia)
29
+ setCurrentPage, // (page: number) => void
30
+ setPageSize, // (size: number) => void
31
+ setFilter, // (filter: IDataFilter | null) => void
32
+ setSortList, // (sortList: IDataSort[]) => void
33
+ refresh, // (hardRefresh?: boolean) => Promise<void>
34
+ loadPageData, // (options?: { disableCache?: boolean }) => void
35
+ getState, // () => IDataProviderState<T>
36
+ setState, // (partial: Partial<IDataProviderState<T>>) => void
37
+ } = useDataProvider(provider, {
38
+ currentPage,
39
+ pageSize,
40
+ filter,
41
+ sortList
42
+ })
43
+ ```
44
+
45
+ ### Why use `useDataProvider`?
46
+ 1. **Idiomatic Vue Reactivity**: Directly works with `watch()`, `computed()`, and template auto-unwrapping.
47
+ 2. **Lifecycle Safety**: Subscribes to the provider and automatically cleans up via `onScopeDispose()` when the component unmounts. This completely eliminates SSR memory leaks in Nuxt.
48
+ 3. **Pinia & URL Store Bridge**: Connect any external refs directly through `options`; bidirectional updates are guarded with internal recursion locks to prevent endless loops.
49
+ 4. **Component Compatibility**: Katlux components like `KDatatable`, `KCombobox`, and `KProductList` consume `useDataProvider` under the hood when given a provider instance via `:dataProvider="myProvider"`.
50
+
51
+ ---
@@ -0,0 +1,133 @@
1
+ ---
2
+ name: katlux-tokens
3
+ description: Complete CSS Custom Properties and design tokens reference for the Katlux Toolkit. Covers all color tokens, typography/spacing/layout tokens, component-specific tokens (buttons, inputs, panels, datatables), and override patterns. Use this skill when writing styles, overriding CSS variables, or building custom presets.
4
+ ---
5
+
6
+ # Katlux Toolkit: CSS Custom Properties / Design Tokens Reference
7
+
8
+ Katlux Toolkit uses CSS Custom Properties (`var(--variable-name)`) scoped to `[data-preset]` root selectors for dynamic, runtime theming.
9
+
10
+ > [!IMPORTANT]
11
+ > **Never use hardcoded hex colors or arbitrary px values in components; always use these semantic tokens.**
12
+
13
+ ---
14
+
15
+ ## 5.1. Color Tokens
16
+
17
+ | Category | Variable Name | Description |
18
+ | --- | --- | --- |
19
+ | **Primary** | `--primary-100`, `--primary-300`, `--primary-500`, `--primary-700`, `--primary-900` | Lightest to darkest primary brand shades |
20
+ | **Accent** | `--accent-100`, `--accent-300`, `--accent-500`, `--accent-700`, `--accent-900` | Lightest to darkest accent shades |
21
+ | **Neutral Scale** | `--neutral-50`, `--neutral-100`, `--neutral-200`, `--neutral-300`, `--neutral-400`, `--neutral-500`, `--neutral-600`, `--neutral-700`, `--neutral-800`, `--neutral-900` | Neutral surface, border, and text shades |
22
+ | **Yellow Palette** | `--yellow-100`, `--yellow-300`, `--yellow-500`, `--yellow-700`, `--yellow-900` | Extended yellow color ramp |
23
+ | **Red Palette** | `--red-100`, `--red-300`, `--red-500`, `--red-700`, `--red-900` | Extended red color ramp |
24
+ | **Blue Palette** | `--blue-100`, `--blue-300`, `--blue-500`, `--blue-700`, `--blue-900` | Extended blue color ramp |
25
+ | **Pink Palette** | `--pink-100`, `--pink-300`, `--pink-500`, `--pink-700`, `--pink-900` | Extended pink color ramp |
26
+ | **Cyan Palette** | `--cyan-100`, `--cyan-300`, `--cyan-500`, `--cyan-700`, `--cyan-900` | Extended cyan color ramp |
27
+ | **Green Palette** | `--green-100`, `--green-300`, `--green-500`, `--green-700`, `--green-900` | Extended green color ramp |
28
+ | **Semantic Status** | `--success-color`, `--success-color-light`, `--warning-color`, `--warning-color-light`, `--error-color`, `--error-color-light`, `--info-color`, `--info-color-light` | Feedback and status indicator colors |
29
+ | **Semantic Shades** | `--success-500`, `--warning-500`, `--danger-500`, `--info-500` | Direct semantic shade references (used by validation states) |
30
+ | **Font Colors** | `--font-color-primary`, `--font-color-secondary`, `--font-color-heading`, `--font-color-light` | Theme-aware text colors |
31
+ | **Surface & Borders**| `--background-color`, `--background-color-light`, `--background-color-medium`, `--background-color-dark`, `--border-color-light`, `--border-color-medium`, `--border-color-dark` | Surface backgrounds and structural border dividers |
32
+ | **Border** | `--border-color` | Default border color |
33
+
34
+ ---
35
+
36
+ ## 5.2. Typography, Spacing & Layout Tokens
37
+
38
+ | Category | Variable Name | Description |
39
+ | --- | --- | --- |
40
+ | **Typography** | `--font-family`, `--font-family-mono` | Main and monospace font stacks |
41
+ | **Font Sizes** | `--font-size-xs`, `--font-size-sm`, `--font-size-md`, `--font-size-lg`, `--font-size-xl` | Text sizes (`10px` / `12px` / `14px` / `16px` / `18px` default) |
42
+ | **Font Weights** | `--font-weight-normal`, `--font-weight-medium`, `--font-weight-semibold`, `--font-weight-bold` | Font weights (`400` / `500` / `600` / `700`) |
43
+ | **Gaps & Spacing** | `--gap-sm`, `--gap-md`, `--gap-lg`, `--gap-xl`, `--grid-gap`, `--component-gap` | Uniform layout and component spacing |
44
+ | **Transitions** | `--transition-fast`, `--transition-normal`, `--transition-slow`, `--transition-bounce` | Standard micro-animation transition curves |
45
+ | **Layout** | `--layout-header-height`, `--layout-header-bg`, `--layout-sidebar-width`, `--layout-sidebar-bg`, `--layout-content-bg` | Core layout container geometry and backgrounds |
46
+
47
+ ---
48
+
49
+ ## 5.3. Component-Specific Tokens
50
+
51
+ | Category | Variable Name | Description |
52
+ | --- | --- | --- |
53
+ | **Radii & Shadows** | `--border-radius-sm`, `--border-radius-md`, `--border-radius-lg`, `--border-radius-xl`, `--border-radius-full`, `--shadow-sm`, `--shadow-md`, `--shadow-lg`, `--shadow-xl` | Border rounding and depth elevation shadows |
54
+ | **Buttons** | `--button-border-radius`, `--button-font-size-sm`, `--button-font-size-md`, `--button-font-size-lg`, `--button-bg-default`, `--button-text-default`, `--button-hover-bg-default`, `--button-bg-primary`, `--button-text-primary`, `--button-hover-bg-primary`, `--button-bg-success`, `--button-bg-warning`, `--button-bg-danger`, `--button-bg-info`, `--button-bg-light`, `--button-bg-dark` (and corresponding `--button-text-*`, `--button-hover-bg-*`) | Button dimensions, typography, variants, and interactive states |
55
+ | **Panels & Modals** | `--panel-bg-default`, `--panel-header-bg-default`, `--panel-footer-bg-default`, `--panel-bg-primary`, `--panel-bg-success`, `--panel-bg-warning`, `--panel-bg-danger`, `--panel-bg-info`, `--panel-bg-opacity`, `--panel-blur`, `--component-overlay-bg`, `--table-overlay-bg`, `--modal-overlay-bg`, `--modal-backdrop-blur` | Panel headers/footers, overlays, and modal backdrops |
56
+ | **Form Inputs** | `--input-bg`, `--input-border-radius`, `--input-border-color`, `--input-border`, `--input-hover-border-color`, `--input-focus-border-color`, `--input-focus-shadow`, `--input-height`, `--input-min-width`, `--input-label-color`, `--input-button-bg`, `--checkbox-bg`, `--checkbox-checked-bg`, `--checkbox-border-color`, `--checkbox-border-radius` | Textboxes, textareas, comboboxes, pickers, and checkboxes |
57
+ | **Datatables** | `--table-border-color`, `--table-header-bg`, `--table-header-color`, `--table-row-bg`, `--table-row-alt-bg`, `--table-row-hover-bg`, `--table-row-selected-bg`, `--table-row-text-color` | Datatable headers, rows, alternating row colors, and selections |
58
+
59
+ ---
60
+
61
+ ## 5.4. Overriding Design Tokens
62
+
63
+ ### Global Preset Override
64
+ Redefine variables under the `[data-preset="preset-name"]` selector in your preset's `assets/scss/css-variables.scss`:
65
+
66
+ ```scss
67
+ /* presets/modern/assets/scss/css-variables.scss */
68
+ [data-preset="modern"] {
69
+ --primary-500: #8b5cf6; // Custom primary brand color
70
+ --border-radius-md: 12px; // Custom card corner rounding
71
+ --input-bg: #f1f5f9; // Custom form field background
72
+ }
73
+ ```
74
+
75
+ > [!TIP]
76
+ > Use `[data-preset~="preset-name"]` (space-separated attribute selector) when your preset name may appear alongside other preset names in the same attribute. Never use `*=` (substring matching). Avoid `!important` to enable smooth dynamic preset switching.
77
+
78
+ ### Component-Level Override
79
+ Apply scoped variable overrides directly to a CSS class or component container:
80
+
81
+ ```scss
82
+ /* Scoped component override */
83
+ .custom-hero-card {
84
+ --panel-bg-default: #1e293b;
85
+ --font-color-primary: #ffffff;
86
+ --button-bg-primary: #ec4899;
87
+ }
88
+ ```
89
+
90
+ ---
91
+
92
+ ## Quick Reference: Most Commonly Used Tokens
93
+
94
+ ```scss
95
+ // Brand
96
+ --primary-500 // Main brand color
97
+ --accent-500 // Accent/highlight color
98
+
99
+ // Text
100
+ --font-color-primary // Primary text
101
+ --font-color-secondary // Secondary/muted text
102
+ --font-color-heading // Heading text
103
+
104
+ // Surfaces
105
+ --background-color // Page/app background
106
+ --background-color-light // Lighter surface (cards, panels)
107
+ --border-color // Default border
108
+
109
+ // Spacing
110
+ --gap-sm // Small gap (e.g. 4px or 8px)
111
+ --gap-md // Medium gap (e.g. 12px or 16px)
112
+ --gap-lg // Large gap (e.g. 24px)
113
+ --gap-xl // Extra-large gap
114
+
115
+ // Shape
116
+ --border-radius-md // Standard radius for inputs, buttons
117
+ --border-radius-lg // Larger radius for cards, panels
118
+
119
+ // Shadows
120
+ --shadow-sm // Subtle depth
121
+ --shadow-md // Standard card shadow
122
+ --shadow-lg // Elevated/modal shadow
123
+
124
+ // Animation
125
+ --transition-fast // Quick micro-interaction
126
+ --transition-normal // Standard hover/focus transition
127
+
128
+ // Semantic
129
+ --success-500 // Green (validation success)
130
+ --warning-500 // Yellow (validation warning)
131
+ --danger-500 // Red (validation error, danger)
132
+ --info-500 // Blue (informational)
133
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@katlux/toolkit",
3
- "version": "0.1.1-alpha.129",
3
+ "version": "0.1.1-alpha.130",
4
4
  "description": "Core UI toolkit and utilities for the Katlux ecosystem",
5
5
  "author": "Katlux",
6
6
  "license": "Apache-2.0",
@@ -15,7 +15,7 @@
15
15
  "katlux-add-ref": "./bin/add-ai-reference.mjs"
16
16
  },
17
17
  "scripts": {
18
- "build": "nuxt-module-build build && unbuild && node -e \"const fs=require('fs'); fs.mkdirSync('dist/runtime', {recursive:true}); fs.cpSync('src/runtime/presets', 'dist/runtime/presets', {recursive:true}); const clean=(d)=>{if(!fs.existsSync(d))return;for(const f of fs.readdirSync(d,{withFileTypes:true})){const p=d+'/'+f.name;if(f.isDirectory())clean(p);else if(f.name.includes('.spec.'))fs.unlinkSync(p);}};clean('dist');\"",
18
+ "build": "nuxt-module-build build && unbuild && node -e \"const fs=require('fs'); fs.mkdirSync('dist/runtime', {recursive:true}); fs.cpSync('src/runtime/presets', 'dist/runtime/presets', {recursive:true}); const clean=(d)=>{if(!fs.existsSync(d))return;for(const f of fs.readdirSync(d,{withFileTypes:true})){const p=d+'/'+f.name;if(f.isDirectory())clean(p);else if(f.name.includes('.spec.'))fs.unlinkSync(p);}};clean('dist'); const sRoot='../../.agents/skills'; if(fs.existsSync(sRoot)){fs.mkdirSync('dist/skills', {recursive:true}); fs.cpSync(sRoot, 'dist/skills', {recursive:true, filter:(s)=>!s.includes('KATLUX_AI_REFERENCE.md')&&!s.includes('.DS_Store')});}\"",
19
19
  "dev": "nuxt-module-build build --stub",
20
20
  "prepare": "nuxi prepare",
21
21
  "prepublishOnly": "npm run build"