@pikacss/core 0.0.38 → 0.0.40

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 CHANGED
@@ -10,39 +10,28 @@ pnpm add @pikacss/core
10
10
 
11
11
  ## Quick Start
12
12
 
13
- **pika.config.ts**:
14
- ```typescript
15
- import { defineEngineConfig } from '@pikacss/core'
16
-
17
- export default defineEngineConfig({
18
- // Your configuration
19
- })
20
- ```
21
-
22
- **Your code**:
23
13
  ```typescript
24
14
  import { createEngine, defineEngineConfig } from '@pikacss/core'
25
15
 
26
16
  const config = defineEngineConfig({
27
- // Engine configuration
28
- prefix: 'pk-',
29
- defaultSelector: '.%',
30
- plugins: []
17
+ // Engine configuration
18
+ prefix: 'pk-',
19
+ defaultSelector: '.%',
20
+ plugins: []
31
21
  })
32
22
 
33
- const engine = createEngine(config)
34
- await engine.setup()
23
+ // createEngine is async and returns a fully initialized engine
24
+ const engine = await createEngine(config)
35
25
  ```
36
26
 
37
27
  ## Features
38
28
 
39
29
  - ⚡ High-performance Atomic CSS-in-JS engine
40
30
  - 🎯 Type-safe with full TypeScript support
41
- - 🔌 Extensible plugin system
42
- - 🎨 Built-in support for shortcuts, selectors, variables, keyframes
43
- - 📦 Works at build-time, zero runtime overhead
44
- - 🔧 Fully configurable
45
- - 🌐 Framework-agnostic core
31
+ - 🔌 Extensible plugin system with hooks
32
+ - 🎨 Built-in support for shortcuts, selectors, variables, keyframes, and important rules
33
+ - 🔧 Fully configurable with type-safe helpers
34
+ - 🌐 Framework-agnostic core (zero dependencies except csstype)
46
35
 
47
36
  ## Usage for Integration Developers
48
37
 
@@ -52,37 +41,52 @@ await engine.setup()
52
41
  import { createEngine, defineEngineConfig } from '@pikacss/core'
53
42
 
54
43
  const config = defineEngineConfig({
55
- // Prefix for generated atomic CSS class names
56
- prefix: 'pk-',
57
-
58
- // Default selector format (% will be replaced with atomic ID)
59
- defaultSelector: '.%',
60
-
61
- // Plugins to extend functionality
62
- plugins: [],
63
-
64
- // Global CSS preflights
65
- preflights: [],
44
+ // Prefix for generated atomic CSS class names
45
+ prefix: 'pk-',
46
+
47
+ // Default selector format (% will be replaced with atomic ID)
48
+ defaultSelector: '.%',
49
+
50
+ // Plugins to extend functionality
51
+ plugins: [],
52
+
53
+ // Global CSS preflights
54
+ preflights: [],
66
55
  })
67
56
 
68
- const engine = createEngine(config)
69
- await engine.setup()
57
+ // createEngine is async - it returns a fully initialized engine
58
+ const engine = await createEngine(config)
70
59
  ```
71
60
 
72
- ### Engine Methods
61
+ ### Engine Methods and Properties
73
62
 
74
- The engine provides methods for managing CSS generation:
63
+ The `Engine` instance provides methods and sub-systems for managing CSS generation:
75
64
 
76
65
  ```typescript
77
- // Add global CSS
66
+ // Add global CSS preflight
78
67
  engine.addPreflight('* { box-sizing: border-box; }')
79
68
 
80
- // Access sub-systems
81
- engine.variables // CSS variables management
82
- engine.keyframes // CSS keyframes management
83
- engine.selectors // CSS selectors management
84
- engine.shortcuts // CSS shortcuts management
85
- engine.important // Important rules management
69
+ // Process style items and get atomic class IDs
70
+ const classNames = await engine.use({ color: 'red' }, { display: 'flex' })
71
+
72
+ // Render generated preflights
73
+ const preflightCSS = await engine.renderPreflights(true)
74
+
75
+ // Render generated atomic styles
76
+ const atomicCSS = await engine.renderAtomicStyles(true)
77
+
78
+ // Access sub-systems (provided by built-in plugins)
79
+ engine.variables // { store: Map, add: (variables) => void }
80
+ engine.keyframes // { store: Map, add: (...keyframes) => void }
81
+ engine.selectors // { resolver: SelectorResolver, add: (...selectors) => void }
82
+ engine.shortcuts // { resolver: ShortcutResolver, add: (...shortcuts) => void }
83
+
84
+ // Access configuration
85
+ engine.config // ResolvedEngineConfig
86
+
87
+ // Autocomplete helpers
88
+ engine.appendAutocompleteSelectors('hover', 'focus')
89
+ engine.appendAutocompleteStyleItemStrings('flex-center')
86
90
  ```
87
91
 
88
92
  ### Configuration
@@ -93,32 +97,32 @@ Use `defineEngineConfig` for type-safe configuration:
93
97
  import { defineEngineConfig } from '@pikacss/core'
94
98
 
95
99
  export default defineEngineConfig({
96
- // Prefix for atomic class IDs
97
- prefix: 'pk-',
98
-
99
- // Default selector format (% = atomic ID)
100
- defaultSelector: '.%',
101
-
102
- // Global CSS preflights
103
- preflights: [
104
- ':root { --primary: #3b82f6; }',
105
- // Or function:
106
- ({ engine, isFormatted }) => '/* Generated CSS */'
107
- ],
108
-
109
- // Shortcuts configuration
110
- shortcuts: {
111
- shortcuts: [
112
- ['flex-center', {
113
- display: 'flex',
114
- alignItems: 'center',
115
- justifyContent: 'center'
116
- }],
117
- ]
118
- },
119
-
120
- // Plugins to extend functionality
121
- plugins: []
100
+ // Prefix for atomic class IDs
101
+ prefix: 'pk-',
102
+
103
+ // Default selector format (% = atomic ID)
104
+ defaultSelector: '.%',
105
+
106
+ // Global CSS preflights (string or function)
107
+ preflights: [
108
+ ':root { --primary: #3b82f6; }',
109
+ // Or function:
110
+ (engine, isFormatted) => '/* Generated CSS */'
111
+ ],
112
+
113
+ // Shortcuts configuration
114
+ shortcuts: {
115
+ shortcuts: [
116
+ ['flex-center', {
117
+ display: 'flex',
118
+ alignItems: 'center',
119
+ justifyContent: 'center'
120
+ }],
121
+ ]
122
+ },
123
+
124
+ // Plugins to extend functionality
125
+ plugins: []
122
126
  })
123
127
  ```
124
128
 
@@ -127,8 +131,8 @@ export default defineEngineConfig({
127
131
  ### Main Exports
128
132
 
129
133
  ```typescript
130
- // Engine creation
131
- export function createEngine(config: EngineConfig): Engine
134
+ // Engine creation (async)
135
+ export function createEngine(config?: EngineConfig): Promise<Engine>
132
136
 
133
137
  // Type-safe config helpers
134
138
  export function defineEngineConfig(config: EngineConfig): EngineConfig
@@ -141,60 +145,93 @@ export function defineShortcut(shortcut: Shortcut): Shortcut
141
145
  export function defineVariables(variables: VariablesDefinition): VariablesDefinition
142
146
 
143
147
  // Utilities
144
- export { log, createLogger } from './internal/utils'
148
+ export {
149
+ appendAutocompleteCssPropertyValues,
150
+ appendAutocompleteExtraCssProperties,
151
+ appendAutocompleteExtraProperties,
152
+ appendAutocompletePropertyValues,
153
+ appendAutocompleteSelectors,
154
+ appendAutocompleteStyleItemStrings,
155
+ createLogger,
156
+ log,
157
+ renderCSSStyleBlocks,
158
+ }
145
159
  ```
146
160
 
147
161
  ### Engine Instance
148
162
 
149
- The `Engine` instance provides methods for managing the CSS generation:
163
+ The `Engine` instance provides:
164
+
165
+ **Core methods:**
166
+ - `engine.addPreflight(css)` - Add global CSS preflight
167
+ - `engine.use(...styleItems)` - Process style items and return atomic class IDs
168
+ - `engine.renderPreflights(isFormatted)` - Render all preflight CSS
169
+ - `engine.renderAtomicStyles(isFormatted, options?)` - Render atomic style CSS
170
+
171
+ **Sub-systems (provided by built-in plugins):**
172
+ - `engine.variables` - CSS variables management with `store` and `add()`
173
+ - `engine.keyframes` - CSS keyframes management with `store` and `add()`
174
+ - `engine.selectors` - CSS selectors management with `resolver` and `add()`
175
+ - `engine.shortcuts` - CSS shortcuts management with `resolver` and `add()`
150
176
 
151
- - `engine.setup()` - Initialize the engine with plugins
152
- - `engine.addPreflight(css)` - Add global CSS
153
- - `engine.variables` - Manage CSS variables
154
- - `engine.keyframes` - Manage CSS keyframes
155
- - `engine.selectors` - Manage CSS selectors
156
- - `engine.shortcuts` - Manage CSS shortcuts
157
- - `engine.important` - Manage important rules
177
+ **Properties:**
178
+ - `engine.config` - Resolved engine configuration
179
+ - `engine.store` - Internal storage for atomic styles and IDs
180
+ - `engine.extract` - Style extraction function
158
181
 
159
182
  ## Plugin Development
160
183
 
161
- Create custom plugins to extend PikaCSS:
184
+ Create custom plugins to extend PikaCSS using the `EnginePlugin` interface:
162
185
 
163
186
  ```typescript
164
- import type { Plugin } from '@pikacss/core'
165
-
166
- export function myPlugin(): Plugin {
167
- return {
168
- name: 'my-plugin',
169
-
170
- setup(api) {
171
- // Add preflights
172
- api.addPreflight({
173
- css: '/* your global CSS */'
174
- })
175
-
176
- // Add rules
177
- api.addRule({
178
- /* rule configuration */
179
- })
180
-
181
- // Add shortcuts
182
- api.addShortcut({
183
- /* shortcut configuration */
184
- })
185
-
186
- // Add variants
187
- api.addVariant({
188
- /* variant configuration */
189
- })
190
- }
191
- }
187
+ /* eslint-disable pikacss/pika-module-augmentation */
188
+ import type { EnginePlugin } from '@pikacss/core'
189
+ import { defineEnginePlugin } from '@pikacss/core'
190
+
191
+ export function myPlugin(): EnginePlugin {
192
+ return defineEnginePlugin({
193
+ name: 'my-plugin',
194
+
195
+ // Optional: Control execution order ('pre' | 'post')
196
+ order: 'pre',
197
+
198
+ // Hook into engine lifecycle
199
+ async configureEngine(engine) {
200
+ // Add global CSS
201
+ engine.addPreflight('/* plugin styles */')
202
+
203
+ // Add custom shortcuts
204
+ engine.shortcuts.add([
205
+ 'my-shortcut',
206
+ { display: 'flex', gap: '1rem' }
207
+ ])
208
+
209
+ // Add custom selectors
210
+ engine.selectors.add(['hover', '$:hover'])
211
+ },
212
+
213
+ // Transform style definitions
214
+ async transformStyleDefinitions(definitions) {
215
+ // Modify or add style definitions
216
+ return definitions
217
+ },
218
+
219
+ // Other available hooks:
220
+ // - configureRawConfig(config)
221
+ // - rawConfigConfigured(config)
222
+ // - configureResolvedConfig(config)
223
+ // - transformSelectors(selectors)
224
+ // - transformStyleItems(styleItems)
225
+ // - preflightUpdated()
226
+ // - atomicStyleAdded(atomicStyle)
227
+ // - autocompleteConfigUpdated()
228
+ })
192
229
  }
193
230
  ```
194
231
 
195
232
  ## Documentation
196
233
 
197
- For complete documentation, visit: [PikaCSS Documentation](https://pikacss.dev)
234
+ For complete documentation, visit: [PikaCSS Documentation](https://pikacss.github.io/pikacss/)
198
235
 
199
236
  ## License
200
237
 
package/dist/index.cjs CHANGED
@@ -223,7 +223,7 @@ const hooks = {
223
223
  transformStyleItems: (plugins, styleItems) => execAsyncHook(plugins, "transformStyleItems", styleItems),
224
224
  transformStyleDefinitions: (plugins, styleDefinitions) => execAsyncHook(plugins, "transformStyleDefinitions", styleDefinitions),
225
225
  preflightUpdated: (plugins) => execSyncHook(plugins, "preflightUpdated", void 0),
226
- atomicStyleAdded: (plugins) => execSyncHook(plugins, "atomicStyleAdded", void 0),
226
+ atomicStyleAdded: (plugins, atomicStyle) => execSyncHook(plugins, "atomicStyleAdded", atomicStyle),
227
227
  autocompleteConfigUpdated: (plugins) => execSyncHook(plugins, "autocompleteConfigUpdated", void 0)
228
228
  };
229
229
  const orderMap = new Map([
package/dist/index.d.cts CHANGED
@@ -326,20 +326,18 @@ declare class Engine {
326
326
  }
327
327
  //#endregion
328
328
  //#region src/internal/plugin.d.ts
329
- type DefineHooks<Hooks extends Record<string, [type: 'sync' | 'async', payload: any, returnValue?: any]>> = Hooks;
330
- type EngineHooksDefinition = DefineHooks<{
331
- configureRawConfig: ['async', config: EngineConfig$1];
332
- rawConfigConfigured: ['sync', config: EngineConfig$1, void];
333
- configureResolvedConfig: ['async', resolvedConfig: ResolvedEngineConfig];
334
- configureEngine: ['async', engine: Engine];
335
- transformSelectors: ['async', selectors: string[]];
336
- transformStyleItems: ['async', styleItems: ResolvedStyleItem[]];
337
- transformStyleDefinitions: ['async', styleDefinitions: ResolvedStyleDefinition[]];
338
- preflightUpdated: ['sync', void];
339
- atomicStyleAdded: ['sync', AtomicStyle];
340
- autocompleteConfigUpdated: ['sync', void];
341
- }>;
342
- type EnginePluginHooksOptions = { [K in keyof EngineHooksDefinition]?: EngineHooksDefinition[K][0] extends 'async' ? (...params: EngineHooksDefinition[K][1] extends void ? [] : [payload: EngineHooksDefinition[K][1]]) => Awaitable<EngineHooksDefinition[K][1] | void> : (...params: EngineHooksDefinition[K][1] extends void ? [] : [payload: EngineHooksDefinition[K][1]]) => EngineHooksDefinition[K][1] | void };
329
+ interface EnginePluginHooksOptions {
330
+ configureRawConfig?: (config: EngineConfig$1) => Awaitable<EngineConfig$1 | void>;
331
+ rawConfigConfigured?: (config: EngineConfig$1) => void;
332
+ configureResolvedConfig?: (resolvedConfig: ResolvedEngineConfig) => Awaitable<ResolvedEngineConfig | void>;
333
+ configureEngine?: (engine: Engine) => Awaitable<void>;
334
+ transformSelectors?: (selectors: string[]) => Awaitable<string[] | void>;
335
+ transformStyleItems?: (styleItems: ResolvedStyleItem[]) => Awaitable<ResolvedStyleItem[] | void>;
336
+ transformStyleDefinitions?: (styleDefinitions: ResolvedStyleDefinition[]) => Awaitable<ResolvedStyleDefinition[] | void>;
337
+ preflightUpdated?: () => void;
338
+ atomicStyleAdded?: (atomicStyle: AtomicStyle) => void;
339
+ autocompleteConfigUpdated?: () => void;
340
+ }
343
341
  interface EnginePlugin extends EnginePluginHooksOptions {
344
342
  name: string;
345
343
  order?: 'pre' | 'post';
package/dist/index.d.mts CHANGED
@@ -326,20 +326,18 @@ declare class Engine {
326
326
  }
327
327
  //#endregion
328
328
  //#region src/internal/plugin.d.ts
329
- type DefineHooks<Hooks extends Record<string, [type: 'sync' | 'async', payload: any, returnValue?: any]>> = Hooks;
330
- type EngineHooksDefinition = DefineHooks<{
331
- configureRawConfig: ['async', config: EngineConfig$1];
332
- rawConfigConfigured: ['sync', config: EngineConfig$1, void];
333
- configureResolvedConfig: ['async', resolvedConfig: ResolvedEngineConfig];
334
- configureEngine: ['async', engine: Engine];
335
- transformSelectors: ['async', selectors: string[]];
336
- transformStyleItems: ['async', styleItems: ResolvedStyleItem[]];
337
- transformStyleDefinitions: ['async', styleDefinitions: ResolvedStyleDefinition[]];
338
- preflightUpdated: ['sync', void];
339
- atomicStyleAdded: ['sync', AtomicStyle];
340
- autocompleteConfigUpdated: ['sync', void];
341
- }>;
342
- type EnginePluginHooksOptions = { [K in keyof EngineHooksDefinition]?: EngineHooksDefinition[K][0] extends 'async' ? (...params: EngineHooksDefinition[K][1] extends void ? [] : [payload: EngineHooksDefinition[K][1]]) => Awaitable<EngineHooksDefinition[K][1] | void> : (...params: EngineHooksDefinition[K][1] extends void ? [] : [payload: EngineHooksDefinition[K][1]]) => EngineHooksDefinition[K][1] | void };
329
+ interface EnginePluginHooksOptions {
330
+ configureRawConfig?: (config: EngineConfig$1) => Awaitable<EngineConfig$1 | void>;
331
+ rawConfigConfigured?: (config: EngineConfig$1) => void;
332
+ configureResolvedConfig?: (resolvedConfig: ResolvedEngineConfig) => Awaitable<ResolvedEngineConfig | void>;
333
+ configureEngine?: (engine: Engine) => Awaitable<void>;
334
+ transformSelectors?: (selectors: string[]) => Awaitable<string[] | void>;
335
+ transformStyleItems?: (styleItems: ResolvedStyleItem[]) => Awaitable<ResolvedStyleItem[] | void>;
336
+ transformStyleDefinitions?: (styleDefinitions: ResolvedStyleDefinition[]) => Awaitable<ResolvedStyleDefinition[] | void>;
337
+ preflightUpdated?: () => void;
338
+ atomicStyleAdded?: (atomicStyle: AtomicStyle) => void;
339
+ autocompleteConfigUpdated?: () => void;
340
+ }
343
341
  interface EnginePlugin extends EnginePluginHooksOptions {
344
342
  name: string;
345
343
  order?: 'pre' | 'post';
package/dist/index.mjs CHANGED
@@ -222,7 +222,7 @@ const hooks = {
222
222
  transformStyleItems: (plugins, styleItems) => execAsyncHook(plugins, "transformStyleItems", styleItems),
223
223
  transformStyleDefinitions: (plugins, styleDefinitions) => execAsyncHook(plugins, "transformStyleDefinitions", styleDefinitions),
224
224
  preflightUpdated: (plugins) => execSyncHook(plugins, "preflightUpdated", void 0),
225
- atomicStyleAdded: (plugins) => execSyncHook(plugins, "atomicStyleAdded", void 0),
225
+ atomicStyleAdded: (plugins, atomicStyle) => execSyncHook(plugins, "atomicStyleAdded", atomicStyle),
226
226
  autocompleteConfigUpdated: (plugins) => execSyncHook(plugins, "autocompleteConfigUpdated", void 0)
227
227
  };
228
228
  const orderMap = new Map([
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@pikacss/core",
3
3
  "type": "module",
4
- "version": "0.0.38",
4
+ "version": "0.0.40",
5
5
  "author": "DevilTea <ch19980814@gmail.com>",
6
6
  "license": "MIT",
7
7
  "repository": {
8
8
  "type": "git",
9
- "url": "https://github.com/pikacss/pikacss.git",
9
+ "url": "https://github.com/pikacss/pikacss.github.io.git",
10
10
  "directory": "packages/core"
11
11
  },
12
12
  "bugs": {
13
- "url": "https://github.com/pikacss/pikacss/issues"
13
+ "url": "https://github.com/pikacss/pikacss.github.io/issues"
14
14
  },
15
15
  "keywords": [
16
16
  "pikacss",