@pandacss/transformer 2.0.0-beta.18 → 2.0.0-beta.20

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.
@@ -9,8 +9,8 @@ declare function splitClassName(className: string): string[];
9
9
  /** Merge key for one Panda atomic class token (conditions + property). */
10
10
  declare function getMergeKey(className: string, separator: string): string | null;
11
11
  /** Build a transform-time `cx` helper bound to the project separator. */
12
- declare function createCx(options?: CxOptions): (...parts: PandaClassPart[]) => string;
12
+ declare function createCx(options?: CxOptions): (...args: PandaClassPart[]) => string;
13
13
  /** Default transform-time `cx` — mirrors styled-system naming with Panda merge semantics. */
14
- declare const cx: (...parts: PandaClassPart[]) => string;
14
+ declare const cx: (...args: PandaClassPart[]) => string;
15
15
 
16
16
  export { type CxOptions, type CxSeparator, type PandaClassPart, createCx, cx, getMergeKey, splitClassName };
@@ -42,70 +42,199 @@ function getMergeKey(className, separator) {
42
42
  const propStart = lastColon + 1;
43
43
  const sepIdx = className.indexOf(separator, propStart);
44
44
  if (sepIdx < propStart + 1 || sepIdx >= end) return null;
45
- const property = className.slice(propStart, sepIdx);
46
- if (lastColon === -1) return property;
47
- return `${className.slice(0, lastColon)}:${property}`;
45
+ return className.slice(0, sepIdx);
48
46
  }
49
- function flattenParts(parts, out) {
50
- for (const part of parts) {
51
- if (!part) continue;
52
- if (Array.isArray(part)) {
53
- flattenParts(part, out);
47
+ var CACHE_LIMIT = 2048;
48
+ var CHAR_SPACE = 32;
49
+ var CHAR_BANG = 33;
50
+ var FIELDS = 4;
51
+ function createCache(limit = CACHE_LIMIT) {
52
+ let size = 0;
53
+ let current = /* @__PURE__ */ new Map();
54
+ let previous = /* @__PURE__ */ new Map();
55
+ const set = (key, value) => {
56
+ current.set(key, value);
57
+ if (++size > limit) {
58
+ size = 0;
59
+ previous = current;
60
+ current = /* @__PURE__ */ new Map();
61
+ }
62
+ };
63
+ return {
64
+ get(key) {
65
+ let value = current.get(key);
66
+ if (value === void 0 && (value = previous.get(key)) !== void 0) set(key, value);
67
+ return value;
68
+ },
69
+ set
70
+ };
71
+ }
72
+ function scanPart(part, separator, out, offset) {
73
+ let count = 0;
74
+ let clean = part.length > 0;
75
+ let start = 0;
76
+ for (let i = 0; i <= part.length; i++) {
77
+ const code = i === part.length ? CHAR_SPACE : part.charCodeAt(i);
78
+ if (code !== CHAR_SPACE && (code < 9 || code > 13)) continue;
79
+ if (code !== CHAR_SPACE || i === start) clean = false;
80
+ if (i === start) {
81
+ start = i + 1;
54
82
  continue;
55
83
  }
56
- if (part === "") continue;
57
- out.push(part);
84
+ const at = offset + count * FIELDS;
85
+ count++;
86
+ out[at] = start;
87
+ out[at + 1] = i;
88
+ out[at + 2] = -1;
89
+ let end = i;
90
+ if (part.charCodeAt(end - 1) === CHAR_BANG) end--;
91
+ let depth = 0;
92
+ let propStart = start;
93
+ for (let c = start; c < end; c++) {
94
+ const code2 = part.charCodeAt(c);
95
+ if (code2 === CHAR_OPEN_BRACKET) depth++;
96
+ else if (code2 === CHAR_CLOSE_BRACKET) depth--;
97
+ else if (code2 === CHAR_COLON && depth === 0) propStart = c + 1;
98
+ }
99
+ const sep = part.indexOf(separator, propStart);
100
+ if (sep > propStart && sep < end) {
101
+ let hash = 2166136261;
102
+ for (let c = start; c < sep; c++) hash = Math.imul(hash ^ part.charCodeAt(c), 16777619);
103
+ out[at + 2] = sep;
104
+ out[at + 3] = hash;
105
+ }
106
+ start = i + 1;
58
107
  }
108
+ return clean ? count : -count;
59
109
  }
60
- function mergeClassStrings(separator, classes) {
61
- const seen = /* @__PURE__ */ new Map();
62
- const order = [];
63
- let id = 0;
64
- for (const cls of classes) {
65
- let tokenStart = 0;
66
- for (let i = 0; i <= cls.length; i++) {
67
- if (i !== cls.length && cls.charCodeAt(i) !== 32) continue;
68
- if (i === tokenStart) {
69
- tokenStart = i + 1;
70
- continue;
110
+ function createCx(options = {}) {
111
+ const separator = options.separator ?? bakedSeparator;
112
+ const scanned = createCache();
113
+ const seenOnce = createCache(512);
114
+ const parts = [];
115
+ let tokens = new Int32Array(64 * FIELDS);
116
+ let tokenPart = new Int32Array(64);
117
+ let winner = new Int32Array(64);
118
+ let tableSize = 128;
119
+ let table = new Int32Array(tableSize);
120
+ let stamps = new Int32Array(tableSize);
121
+ let stamp = 0;
122
+ function collect(value) {
123
+ if (!value) return;
124
+ if (typeof value === "string") parts.push(value);
125
+ else for (let i = 0; i < value.length; i++) collect(value[i]);
126
+ }
127
+ function reserve(tokenCount) {
128
+ if (tokenCount <= tokenPart.length) return;
129
+ let size = tokenPart.length;
130
+ while (size < tokenCount) size *= 2;
131
+ const grow = (from, length) => {
132
+ const next = new Int32Array(length);
133
+ next.set(from);
134
+ return next;
135
+ };
136
+ tokens = grow(tokens, size * FIELDS);
137
+ tokenPart = grow(tokenPart, size);
138
+ winner = grow(winner, size);
139
+ }
140
+ function sameKey(a, b) {
141
+ const aStart = tokens[a * FIELDS];
142
+ const bStart = tokens[b * FIELDS];
143
+ const length = tokens[a * FIELDS + 2] - aStart;
144
+ if (tokens[b * FIELDS + 2] - bStart !== length) return false;
145
+ const left = parts[tokenPart[a]];
146
+ const right = parts[tokenPart[b]];
147
+ for (let i = 0; i < length; i++) {
148
+ if (left.charCodeAt(aStart + i) !== right.charCodeAt(bStart + i)) return false;
149
+ }
150
+ return true;
151
+ }
152
+ function merge() {
153
+ let count = 0;
154
+ let clean = true;
155
+ for (let p = 0; p < parts.length; p++) {
156
+ const part = parts[p];
157
+ const cached = scanned.get(part);
158
+ let partCount;
159
+ if (cached !== void 0) {
160
+ partCount = cached[0];
161
+ reserve(count + Math.abs(partCount));
162
+ const base = count * FIELDS;
163
+ for (let i = 1; i < cached.length; i++) tokens[base + i - 1] = cached[i];
164
+ } else {
165
+ reserve(count + part.length);
166
+ partCount = scanPart(part, separator, tokens, count * FIELDS);
167
+ if (seenOnce.get(part) === void 0) seenOnce.set(part, true);
168
+ else {
169
+ const record = new Int32Array(1 + Math.abs(partCount) * FIELDS);
170
+ record[0] = partCount;
171
+ record.set(tokens.subarray(count * FIELDS, (count + Math.abs(partCount)) * FIELDS), 1);
172
+ scanned.set(part, record);
173
+ }
71
174
  }
72
- const token = cls.slice(tokenStart, i);
73
- tokenStart = i + 1;
74
- const key = getMergeKey(token, separator);
75
- if (key !== null) {
76
- if (!seen.has(key)) order.push(key);
77
- seen.set(key, token);
175
+ if (partCount <= 0) clean = false;
176
+ const end = count + Math.abs(partCount);
177
+ for (; count < end; count++) tokenPart[count] = p;
178
+ }
179
+ if (count * 2 > tableSize) {
180
+ while (count * 2 > tableSize) tableSize *= 2;
181
+ table = new Int32Array(tableSize);
182
+ stamps = new Int32Array(tableSize);
183
+ stamp = 0;
184
+ }
185
+ if (++stamp === 2147483647) {
186
+ stamp = 1;
187
+ stamps.fill(0);
188
+ }
189
+ const mask = tableSize - 1;
190
+ let replaced = false;
191
+ for (let t = 0; t < count; t++) {
192
+ winner[t] = t;
193
+ if (tokens[t * FIELDS + 2] < 0) continue;
194
+ const hash = tokens[t * FIELDS + 3];
195
+ let slot = hash & mask;
196
+ let owner = -1;
197
+ while (stamps[slot] === stamp) {
198
+ const candidate = table[slot];
199
+ if (tokens[candidate * FIELDS + 3] === hash && sameKey(candidate, t)) {
200
+ owner = candidate;
201
+ break;
202
+ }
203
+ slot = slot + 1 & mask;
204
+ }
205
+ if (owner === -1) {
206
+ stamps[slot] = stamp;
207
+ table[slot] = t;
78
208
  } else {
79
- const uniqueKey = `__${id++}`;
80
- order.push(uniqueKey);
81
- seen.set(uniqueKey, token);
209
+ winner[owner] = t;
210
+ winner[t] = -1;
211
+ replaced = true;
82
212
  }
83
213
  }
84
- }
85
- if (order.length === 0) return "";
86
- if (order.length === 1) return seen.get(order[0]);
87
- let str = seen.get(order[0]);
88
- for (let i = 1; i < order.length; i++) {
89
- str += ` ${seen.get(order[i])}`;
90
- }
91
- return str;
92
- }
93
- function createCx(options = {}) {
94
- const separator = options.separator ?? bakedSeparator;
95
- return function cx2(...parts) {
96
- if (parts.length === 1) {
97
- const only = parts[0];
98
- if (typeof only === "string") return only;
99
- if (!only) return "";
214
+ if (!replaced && clean) {
215
+ let joined = parts[0];
216
+ for (let p = 1; p < parts.length; p++) joined += " " + parts[p];
217
+ return joined;
218
+ }
219
+ let result = "";
220
+ for (let t = 0; t < count; t++) {
221
+ const w = winner[t];
222
+ if (w === -1) continue;
223
+ const piece = parts[tokenPart[w]].slice(tokens[w * FIELDS], tokens[w * FIELDS + 1]);
224
+ result = result ? result + " " + piece : piece;
100
225
  }
101
- const flat = [];
102
- flattenParts(parts, flat);
103
- if (flat.length === 0) return "";
104
- if (flat.length === 1) return flat[0];
105
- return mergeClassStrings(separator, flat);
226
+ return result;
227
+ }
228
+ return function cx2(...args) {
229
+ parts.length = 0;
230
+ for (let i = 0; i < args.length; i++) collect(args[i]);
231
+ const count = parts.length;
232
+ if (count === 0) return "";
233
+ if (count === 1) return parts[0];
234
+ return merge();
106
235
  };
107
236
  }
108
- var cx = createCx();
237
+ var cx = /* @__PURE__ */ createCx();
109
238
  export {
110
239
  createCx,
111
240
  cx,
@@ -1,65 +1,54 @@
1
1
  export { CxOptions, CxSeparator, PandaClassPart, createCx, cx, getMergeKey, splitClassName } from './cx.js';
2
+ export { c as css } from '../css-BPeL3U6s.js';
2
3
 
3
- /** Transformed `css()` sites receive pre-encoded class strings only. */
4
- declare function css(...styles: string[]): string;
5
-
6
- type VariantMap = Record<string, Record<string, string>>;
7
4
  type VariantValue = string | number | boolean;
8
5
  type CompoundVariant = Record<string, unknown> & {
9
6
  css?: string;
10
7
  className?: string;
11
8
  };
12
9
 
13
- interface StringCvaConfig {
14
- base?: string;
15
- variants?: VariantMap;
10
+ type Style = Record<string, unknown>;
11
+ type Props$1 = Record<string, unknown>;
12
+ interface RecipeConfig {
13
+ slots?: string[];
14
+ base?: Style;
15
+ variants?: Record<string, Record<string, Style>>;
16
16
  defaultVariants?: Record<string, VariantValue>;
17
17
  compoundVariants?: CompoundVariant[];
18
18
  }
19
- /** The shape `merge` needs from the other recipe — `cva()`'s own return satisfies it. */
20
- interface MergeableCva {
21
- config: StringCvaConfig;
22
- variantKeys: string[];
19
+ /** The public surface of a styled-system `cva` that `merge` reads from its operand. */
20
+ interface RecipeLike {
21
+ (props?: Props$1): string;
22
+ raw(props?: Props$1): Style;
23
+ variantKeys?: string[];
24
+ variantMap?: Record<string, string[]>;
25
+ config?: RecipeConfig;
23
26
  }
24
- /** String-branch recipe factory for transformed source (TW-style cva). */
25
- declare function cva(config: StringCvaConfig): ((props?: Record<string, unknown>) => string) & {
26
- __cva__: true;
27
+ /**
28
+ * Attach the observable recipe surface to a compiler-specialized `cva`/`sva` function.
29
+ * A `classNameMap` marks the function as a slot recipe.
30
+ */
31
+ declare function attachRecipe<F extends (props?: Props$1) => any, C extends object>(fn: F, config: C, variantKeys: string[], variantMap: Record<string, string[]>, classNameMap?: Record<string, string>): F & {
32
+ config: C;
33
+ raw: (props?: Props$1) => any;
34
+ merge: (other: RecipeLike, cva?: (config: C) => {
35
+ merge(other: RecipeLike): unknown;
36
+ }) => unknown;
37
+ getVariantProps: (props?: Props$1) => Record<string, unknown>;
38
+ splitVariantProps: (props: Props$1) => readonly [Props$1, Props$1];
39
+ classNameMap?: Record<string, string> | undefined;
40
+ __cva__: boolean;
27
41
  variantKeys: string[];
28
42
  variantMap: Record<string, string[]>;
29
- raw: (props?: Record<string, unknown>) => string;
30
- merge: (other: MergeableCva) => ((props?: Record<string, unknown>) => string) & /*elided*/ any;
31
- config: StringCvaConfig;
32
- getVariantProps: (props: Record<string, unknown>) => Record<string, unknown>;
33
- splitVariantProps: (props: Record<string, unknown>) => [Record<string, unknown>, Record<string, unknown>];
34
43
  };
35
44
 
36
- type SvaCompound = Record<string, unknown> & {
37
- css?: Record<string, string> | string;
38
- className?: string;
39
- classNames?: Record<string, string>;
40
- };
41
- /** An option is one string for every slot, or a map of the slots it styles. */
42
- type SlotVariantMap = Record<string, Record<string, string | Record<string, string>>>;
43
- type SvaConfig = {
44
- slots?: string[];
45
- base?: Record<string, string>;
46
- variants?: SlotVariantMap;
47
- defaultVariants?: Record<string, VariantValue>;
48
- compoundVariants?: SvaCompound[];
49
- className?: Record<string, string>;
50
- };
51
- /** String-branch slot recipe factory for transformed source. */
52
- declare function sva(config: SvaConfig): ((props?: Record<string, unknown>) => Record<string, string>) & {
53
- __cva__: false;
54
- raw: (props?: Record<string, unknown>) => Record<string, string>;
55
- config: SvaConfig;
56
- variantMap: {
57
- [k: string]: string[];
58
- };
59
- variantKeys: string[];
60
- classNameMap: Record<string, string>;
61
- getVariantProps: (props: Record<string, unknown>) => Record<string, unknown>;
62
- splitVariantProps: (props: Record<string, unknown>) => [Record<string, unknown>, Record<string, unknown>];
63
- };
45
+ type Props = Record<string, unknown>;
46
+ type Resolve<T> = (props?: Props) => T;
47
+ type Memoized<T> = (props?: Props | null) => T;
48
+ /**
49
+ * Memoize a compiler-specialized recipe. `variantMap` lists every prop the function reads; the
50
+ * compiler only specializes recipes whose compounds select on declared variants.
51
+ */
52
+ declare function memoRecipe<T>(resolve: Resolve<T>, variantMap: Record<string, string[]>, hasCompounds?: unknown): Memoized<T>;
64
53
 
65
- export { type StringCvaConfig, css, cva, sva };
54
+ export { attachRecipe, memoRecipe };