@pikacss/integration 0.0.48 → 0.0.49
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/dist/index.d.mts +2 -0
- package/dist/index.mjs +14 -6
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -170,6 +170,8 @@ interface IntegrationContext {
|
|
|
170
170
|
loadConfig: () => Promise<LoadedConfigResult>;
|
|
171
171
|
/** Map from source file ID to the list of `UsageRecord` entries extracted during transforms. Keyed by the file path relative to `cwd`. */
|
|
172
172
|
usages: Map<string, UsageRecord[]>;
|
|
173
|
+
/** Map from source file ID to preview-only `UsageRecord` entries (from `pikap()` calls). Only these drive TypeScript preview overload generation. */
|
|
174
|
+
previewUsages: Map<string, UsageRecord[]>;
|
|
173
175
|
/** Event hooks for notifying plugins when generated outputs need refreshing. `styleUpdated` fires on CSS changes; `tsCodegenUpdated` fires on TypeScript declaration changes. */
|
|
174
176
|
hooks: {
|
|
175
177
|
styleUpdated: ReturnType<typeof createEventHook<void>>;
|
package/dist/index.mjs
CHANGED
|
@@ -277,13 +277,13 @@ function generateAutocomplete(ctx) {
|
|
|
277
277
|
const { layers } = ctx.engine.config;
|
|
278
278
|
const layerNames = sortLayerNames(layers);
|
|
279
279
|
return [
|
|
280
|
-
"export type Autocomplete =
|
|
280
|
+
"export type Autocomplete = {",
|
|
281
281
|
` Selector: ${formatAutocompleteUnion(autocomplete.selectors, patterns.selectors)}`,
|
|
282
282
|
` Shortcut: ${formatAutocompleteUnion(autocomplete.shortcuts, patterns.shortcuts)}`,
|
|
283
283
|
` PropertyValue: ${formatAutocompleteValueMap(autocomplete.extraProperties, autocomplete.properties, patterns.properties, (values, patterns) => formatUnionType([...values, ...patterns]))}`,
|
|
284
284
|
` CSSPropertyValue: ${formatAutocompleteValueMap(autocomplete.extraCssProperties, autocomplete.cssProperties, patterns.cssProperties, (values, patterns) => formatAutocompleteUnion(values, patterns))}`,
|
|
285
285
|
` Layer: ${formatUnionStringType(layerNames)}`,
|
|
286
|
-
"}
|
|
286
|
+
"}",
|
|
287
287
|
""
|
|
288
288
|
];
|
|
289
289
|
}
|
|
@@ -336,8 +336,8 @@ async function generateOverloadContent(ctx) {
|
|
|
336
336
|
log.debug("Generating TypeScript overload content");
|
|
337
337
|
const paramsLines = [];
|
|
338
338
|
const fnsLines = [];
|
|
339
|
-
const usages = [...ctx.
|
|
340
|
-
log.debug(`Processing ${usages.length}
|
|
339
|
+
const usages = [...ctx.previewUsages.values()].flat();
|
|
340
|
+
log.debug(`Processing ${usages.length} preview usages for overload generation`);
|
|
341
341
|
for (let i = 0; i < usages.length; i++) {
|
|
342
342
|
const usage = usages[i];
|
|
343
343
|
try {
|
|
@@ -387,7 +387,7 @@ async function generateTsCodegenContent(ctx) {
|
|
|
387
387
|
log.debug("Generating TypeScript code generation content");
|
|
388
388
|
const lines = [
|
|
389
389
|
`// Auto-generated by ${ctx.currentPackageName}`,
|
|
390
|
-
`import type { CSSProperty, CSSSelector,
|
|
390
|
+
`import type { CSSProperty, CSSSelector, Properties, StyleDefinition, StyleItem } from \'${ctx.currentPackageName}\'`,
|
|
391
391
|
"",
|
|
392
392
|
`declare module \'${ctx.currentPackageName}\' {`,
|
|
393
393
|
" interface PikaAugment {",
|
|
@@ -525,7 +525,7 @@ function useConfig({ cwd, tsCodegenFilepath, currentPackageName, autoCreateConfi
|
|
|
525
525
|
loadConfig
|
|
526
526
|
};
|
|
527
527
|
}
|
|
528
|
-
function useTransform({ cwd, cssCodegenFilepath, tsCodegenFilepath, scan, fnName, usages, engine, transformedFormat, triggerStyleUpdated, triggerTsCodegenUpdated }) {
|
|
528
|
+
function useTransform({ cwd, cssCodegenFilepath, tsCodegenFilepath, scan, fnName, usages, previewUsages, engine, transformedFormat, triggerStyleUpdated, triggerTsCodegenUpdated }) {
|
|
529
529
|
const fnUtils = createFnUtils(fnName);
|
|
530
530
|
async function transform(code, id) {
|
|
531
531
|
const _engine = engine();
|
|
@@ -533,10 +533,12 @@ function useTransform({ cwd, cssCodegenFilepath, tsCodegenFilepath, scan, fnName
|
|
|
533
533
|
try {
|
|
534
534
|
log.debug(`Transforming file: ${id}`);
|
|
535
535
|
usages.delete(id);
|
|
536
|
+
previewUsages.delete(id);
|
|
536
537
|
const functionCalls = findFunctionCalls(code, fnUtils);
|
|
537
538
|
if (functionCalls.length === 0) return;
|
|
538
539
|
log.debug(`Found ${functionCalls.length} style function calls in ${id}`);
|
|
539
540
|
const usageList = [];
|
|
541
|
+
const previewUsageList = [];
|
|
540
542
|
const transformed = new MagicString(code);
|
|
541
543
|
for (const fnCall of functionCalls) {
|
|
542
544
|
const argsStr = `[${fnCall.snippet.slice(fnCall.fnName.length + 1, -1)}]`;
|
|
@@ -547,6 +549,7 @@ function useTransform({ cwd, cssCodegenFilepath, tsCodegenFilepath, scan, fnName
|
|
|
547
549
|
params: args
|
|
548
550
|
};
|
|
549
551
|
usageList.push(usage);
|
|
552
|
+
if (fnUtils.isPreview(fnCall.fnName)) previewUsageList.push(usage);
|
|
550
553
|
let transformedContent;
|
|
551
554
|
if (fnUtils.isNormal(fnCall.fnName)) transformedContent = transformedFormat === "array" ? `[${names.map((n) => `'${n}'`).join(", ")}]` : `'${names.join(" ")}'`;
|
|
552
555
|
else if (fnUtils.isForceString(fnCall.fnName)) transformedContent = `'${names.join(" ")}'`;
|
|
@@ -555,6 +558,7 @@ function useTransform({ cwd, cssCodegenFilepath, tsCodegenFilepath, scan, fnName
|
|
|
555
558
|
transformed.update(fnCall.start, fnCall.end + 1, transformedContent);
|
|
556
559
|
}
|
|
557
560
|
usages.set(id, usageList);
|
|
561
|
+
if (previewUsageList.length > 0) previewUsages.set(id, previewUsageList);
|
|
558
562
|
triggerStyleUpdated();
|
|
559
563
|
triggerTsCodegenUpdated();
|
|
560
564
|
log.debug(`Transformed ${usageList.length} style usages in ${id}`);
|
|
@@ -599,6 +603,7 @@ function createCtx(options) {
|
|
|
599
603
|
tsCodegenFilepath
|
|
600
604
|
});
|
|
601
605
|
const usages = /* @__PURE__ */ new Map();
|
|
606
|
+
const previewUsages = /* @__PURE__ */ new Map();
|
|
602
607
|
const engine = signal(null);
|
|
603
608
|
const hooks = {
|
|
604
609
|
styleUpdated: createEventHook(),
|
|
@@ -610,6 +615,7 @@ function createCtx(options) {
|
|
|
610
615
|
cssCodegenFilepath,
|
|
611
616
|
tsCodegenFilepath,
|
|
612
617
|
usages,
|
|
618
|
+
previewUsages,
|
|
613
619
|
engine,
|
|
614
620
|
triggerStyleUpdated: () => hooks.styleUpdated.trigger(),
|
|
615
621
|
triggerTsCodegenUpdated: () => hooks.tsCodegenUpdated.trigger()
|
|
@@ -644,6 +650,7 @@ function createCtx(options) {
|
|
|
644
650
|
},
|
|
645
651
|
loadConfig,
|
|
646
652
|
usages,
|
|
653
|
+
previewUsages,
|
|
647
654
|
hooks,
|
|
648
655
|
get engine() {
|
|
649
656
|
const _engine = engine();
|
|
@@ -721,6 +728,7 @@ function createCtx(options) {
|
|
|
721
728
|
async function setup() {
|
|
722
729
|
log.debug("Setting up integration context");
|
|
723
730
|
usages.clear();
|
|
731
|
+
previewUsages.clear();
|
|
724
732
|
hooks.styleUpdated.listeners.clear();
|
|
725
733
|
hooks.tsCodegenUpdated.listeners.clear();
|
|
726
734
|
engine(null);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pikacss/integration",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.49",
|
|
5
5
|
"author": "DevilTea <ch19980814@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://pikacss.com",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"magic-string": "^0.30.21",
|
|
49
49
|
"pathe": "^2.0.3",
|
|
50
50
|
"perfect-debounce": "^2.1.0",
|
|
51
|
-
"@pikacss/core": "0.0.
|
|
51
|
+
"@pikacss/core": "0.0.49"
|
|
52
52
|
},
|
|
53
53
|
"scripts": {
|
|
54
54
|
"build": "tsdown",
|