next-yak 0.0.36 → 0.1.0

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 (44) hide show
  1. package/dist/loaders/cssloader.cjs +1142 -0
  2. package/dist/loaders/cssloader.cjs.map +1 -0
  3. package/dist/loaders/cssloader.d.cts +8 -0
  4. package/dist/loaders/cssloader.d.ts +8 -0
  5. package/dist/loaders/cssloader.js +1118 -0
  6. package/dist/loaders/cssloader.js.map +1 -0
  7. package/dist/loaders/tsloader.cjs +1114 -0
  8. package/dist/loaders/tsloader.cjs.map +1 -0
  9. package/dist/loaders/tsloader.d.cts +6 -0
  10. package/dist/loaders/tsloader.d.ts +6 -0
  11. package/dist/loaders/tsloader.js +1092 -0
  12. package/dist/loaders/tsloader.js.map +1 -0
  13. package/{withYak → dist/withYak}/index.cjs +14 -7
  14. package/dist/withYak/index.cjs.map +1 -0
  15. package/{withYak → dist/withYak}/index.d.cts +2 -2
  16. package/dist/withYak/index.d.ts +37 -0
  17. package/dist/withYak/index.js +68 -0
  18. package/dist/withYak/index.js.map +1 -0
  19. package/loaders/__tests__/cssloader.test.ts +210 -152
  20. package/loaders/__tests__/getCssName.test.ts +13 -13
  21. package/loaders/__tests__/parseCss.test.ts +717 -0
  22. package/loaders/__tests__/toCss.test.ts +138 -0
  23. package/loaders/__tests__/tsloader.test.ts +544 -168
  24. package/loaders/babel-yak-plugin.ts +796 -0
  25. package/loaders/cssloader.ts +35 -0
  26. package/loaders/lib/{appendCssUnitToExpressionValue.cjs → appendCssUnitToExpressionValue.ts} +10 -13
  27. package/loaders/lib/{getConstantValues.cjs → getConstantValues.ts} +46 -29
  28. package/loaders/lib/{getCssName.cjs → getCssName.ts} +21 -33
  29. package/loaders/lib/{getStyledComponentName.cjs → getStyledComponentName.ts} +5 -8
  30. package/loaders/lib/{getYakImports.cjs → getYakImports.ts} +3 -9
  31. package/loaders/lib/{hash.cjs → hash.ts} +3 -5
  32. package/loaders/lib/parseCss.ts +220 -0
  33. package/loaders/lib/{replaceQuasiExpressionTokens.cjs → replaceQuasiExpressionTokens.ts} +27 -26
  34. package/loaders/lib/{stripCssComments.cjs → stripCssComments.ts} +3 -9
  35. package/loaders/lib/toCss.ts +45 -0
  36. package/loaders/{tsloader.cjs → tsloader.ts} +16 -17
  37. package/package.json +8 -14
  38. package/withYak/index.ts +43 -34
  39. package/loaders/__tests__/classifier.test.ts +0 -133
  40. package/loaders/babel-yak-plugin.cjs +0 -488
  41. package/loaders/cssloader.cjs +0 -432
  42. package/loaders/lib/localIdent.cjs +0 -31
  43. package/loaders/lib/quasiClassifier.cjs +0 -90
  44. package/withYak/index.cjs.map +0 -1
@@ -0,0 +1,1142 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __esm = (fn, res) => function __init() {
9
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
10
+ };
11
+ var __export = (target, all) => {
12
+ for (var name in all)
13
+ __defProp(target, name, { get: all[name], enumerable: true });
14
+ };
15
+ var __copyProps = (to, from, except, desc) => {
16
+ if (from && typeof from === "object" || typeof from === "function") {
17
+ for (let key of __getOwnPropNames(from))
18
+ if (!__hasOwnProp.call(to, key) && key !== except)
19
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
20
+ }
21
+ return to;
22
+ };
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
24
+ // If the importer is in node compatibility mode or this is not an ESM
25
+ // file that has been converted to a CommonJS file using a Babel-
26
+ // compatible transform (i.e. "__esModule" has not been set), then set
27
+ // "default" to the CommonJS "module.exports" for node compatibility.
28
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
29
+ mod
30
+ ));
31
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
+
33
+ // loaders/lib/getConstantValues.ts
34
+ function getConstantValues(path, t) {
35
+ const topLevelConstBindings = /* @__PURE__ */ new Map();
36
+ const bindings = Object.entries(path.scope.bindings);
37
+ for (const [name, binding] of bindings) {
38
+ if (binding.kind === "module") {
39
+ topLevelConstBindings.set(name, {
40
+ value: null,
41
+ type: "module"
42
+ });
43
+ continue;
44
+ }
45
+ if (binding.kind === "let" || binding.kind === "var" || binding.kind === "const") {
46
+ if (!("init" in binding.path.node)) {
47
+ topLevelConstBindings.set(name, {
48
+ type: "variable",
49
+ value: null
50
+ });
51
+ continue;
52
+ }
53
+ const value = binding.path.node.init;
54
+ if (t.isFunctionDeclaration(value) || t.isArrowFunctionExpression(value)) {
55
+ topLevelConstBindings.set(name, {
56
+ type: "function",
57
+ value: null
58
+ });
59
+ continue;
60
+ }
61
+ topLevelConstBindings.set(name, {
62
+ type: "variable",
63
+ value: t.isStringLiteral(value) || t.isNumericLiteral(value) ? value.value : null
64
+ });
65
+ }
66
+ }
67
+ return topLevelConstBindings;
68
+ }
69
+ var getConstantName;
70
+ var init_getConstantValues = __esm({
71
+ "loaders/lib/getConstantValues.ts"() {
72
+ "use strict";
73
+ getConstantName = (expression, t) => {
74
+ if (t.isIdentifier(expression)) {
75
+ return expression.name;
76
+ } else if (t.isMemberExpression(expression) && t.isIdentifier(expression.object)) {
77
+ return expression.object.name;
78
+ } else if (t.isCallExpression(expression) && t.isIdentifier(expression.callee)) {
79
+ return expression.callee.name;
80
+ } else if (t.isCallExpression(expression) && t.isMemberExpression(expression.callee) && t.isIdentifier(expression.callee.object)) {
81
+ return expression.callee.object.name;
82
+ } else {
83
+ return null;
84
+ }
85
+ };
86
+ }
87
+ });
88
+
89
+ // loaders/lib/hash.ts
90
+ function murmurhash2_32_gc(str) {
91
+ let l = str.length;
92
+ let h = l;
93
+ let i = 0;
94
+ let k;
95
+ while (l >= 4) {
96
+ k = str.charCodeAt(i) & 255 | (str.charCodeAt(++i) & 255) << 8 | (str.charCodeAt(++i) & 255) << 16 | (str.charCodeAt(++i) & 255) << 24;
97
+ k = (k & 65535) * 1540483477 + (((k >>> 16) * 1540483477 & 65535) << 16);
98
+ k ^= k >>> 24;
99
+ k = (k & 65535) * 1540483477 + (((k >>> 16) * 1540483477 & 65535) << 16);
100
+ h = (h & 65535) * 1540483477 + (((h >>> 16) * 1540483477 & 65535) << 16) ^ k;
101
+ l -= 4;
102
+ ++i;
103
+ }
104
+ switch (l) {
105
+ case 3:
106
+ h ^= (str.charCodeAt(i + 2) & 255) << 16;
107
+ case 2:
108
+ h ^= (str.charCodeAt(i + 1) & 255) << 8;
109
+ case 1:
110
+ h ^= str.charCodeAt(i) & 255;
111
+ h = (h & 65535) * 1540483477 + (((h >>> 16) * 1540483477 & 65535) << 16);
112
+ }
113
+ h ^= h >>> 13;
114
+ h = (h & 65535) * 1540483477 + (((h >>> 16) * 1540483477 & 65535) << 16);
115
+ h ^= h >>> 15;
116
+ return (h >>> 0).toString(36);
117
+ }
118
+ var init_hash = __esm({
119
+ "loaders/lib/hash.ts"() {
120
+ "use strict";
121
+ }
122
+ });
123
+
124
+ // loaders/lib/replaceQuasiExpressionTokens.ts
125
+ function replaceTokensInQuasiExpressions(quasi, replacer, t) {
126
+ for (let i = quasi.expressions.length - 1; i >= 0; i--) {
127
+ const expression = quasi.expressions[i];
128
+ const parts = getExpressionParts(expression, t);
129
+ const replacement = parts && replacer(parts[0]);
130
+ const replacementValue = replacement && getReplacementValue(replacement, parts);
131
+ if (replacementValue !== false && replacementValue !== null) {
132
+ replaceExpressionAndMergeQuasis(quasi, i, replacementValue);
133
+ }
134
+ }
135
+ }
136
+ function replaceExpressionAndMergeQuasis(quasi, expressionIndex, replacement) {
137
+ const stringReplacement = typeof replacement === "string" ? replacement : replacement == null ? "" : JSON.stringify(replacement);
138
+ quasi.expressions.splice(expressionIndex, 1);
139
+ quasi.quasis[expressionIndex].value.raw += stringReplacement + quasi.quasis[expressionIndex + 1].value.raw;
140
+ quasi.quasis[expressionIndex].value.cooked += stringReplacement + quasi.quasis[expressionIndex + 1].value.cooked;
141
+ quasi.quasis.splice(expressionIndex + 1, 1);
142
+ }
143
+ function getExpressionParts(expression, t) {
144
+ let currentExpression = expression;
145
+ const tokens = [];
146
+ while (currentExpression) {
147
+ if (t.isIdentifier(currentExpression)) {
148
+ tokens.unshift(currentExpression.name);
149
+ break;
150
+ }
151
+ if (t.isMemberExpression(currentExpression)) {
152
+ if (currentExpression.computed === false && t.isIdentifier(currentExpression.property)) {
153
+ tokens.unshift(currentExpression.property.name);
154
+ } else if (t.isStringLiteral(currentExpression.property)) {
155
+ tokens.unshift(currentExpression.property.value);
156
+ } else if (t.isNumericLiteral(currentExpression.property)) {
157
+ tokens.unshift(String(currentExpression.property.value));
158
+ } else {
159
+ return null;
160
+ }
161
+ currentExpression = currentExpression.object;
162
+ } else if (t.isCallExpression(currentExpression)) {
163
+ if (!t.isExpression(currentExpression.callee)) {
164
+ return null;
165
+ }
166
+ currentExpression = currentExpression.callee;
167
+ } else {
168
+ return null;
169
+ }
170
+ }
171
+ return tokens;
172
+ }
173
+ function getReplacementValue(replacement, parts) {
174
+ let currentReplacement = replacement;
175
+ for (let i = 1; i < parts.length; i++) {
176
+ const part = parts[i];
177
+ if (currentReplacement == null || typeof currentReplacement !== "object") {
178
+ return false;
179
+ }
180
+ currentReplacement = currentReplacement[part];
181
+ }
182
+ return currentReplacement;
183
+ }
184
+ var init_replaceQuasiExpressionTokens = __esm({
185
+ "loaders/lib/replaceQuasiExpressionTokens.ts"() {
186
+ "use strict";
187
+ }
188
+ });
189
+
190
+ // loaders/lib/getStyledComponentName.ts
191
+ var getStyledComponentName, getStyledComponentName_default;
192
+ var init_getStyledComponentName = __esm({
193
+ "loaders/lib/getStyledComponentName.ts"() {
194
+ "use strict";
195
+ getStyledComponentName = (taggedTemplateExpressionPath) => {
196
+ const variableDeclaratorPath = taggedTemplateExpressionPath.findParent(
197
+ (path) => path.isVariableDeclarator()
198
+ );
199
+ if (!variableDeclaratorPath || !("id" in variableDeclaratorPath.node) || variableDeclaratorPath.node.id?.type !== "Identifier") {
200
+ throw new Error(
201
+ "Could not find variable declaration for styled component at " + taggedTemplateExpressionPath.node.loc
202
+ );
203
+ }
204
+ return variableDeclaratorPath.node.id.name;
205
+ };
206
+ getStyledComponentName_default = getStyledComponentName;
207
+ }
208
+ });
209
+
210
+ // loaders/lib/getCssName.ts
211
+ function extractConditions(path) {
212
+ const conditions = [];
213
+ const visitedNodes = /* @__PURE__ */ new Set();
214
+ const getConditions = (node, previousNode, isNegated = false) => {
215
+ if (visitedNodes.has(node))
216
+ return;
217
+ visitedNodes.add(node);
218
+ if (node.type === "LogicalExpression") {
219
+ if (node.operator === "&&") {
220
+ getConditions(node.right, previousNode, isNegated);
221
+ conditions.push("and");
222
+ getConditions(node.left, previousNode, isNegated);
223
+ } else if (node.operator === "||") {
224
+ getConditions(node.right, previousNode, isNegated);
225
+ conditions.push("or");
226
+ getConditions(node.left, previousNode, isNegated);
227
+ }
228
+ } else if (node.type === "ConditionalExpression") {
229
+ conditions.push("and");
230
+ getConditions(node.test, previousNode, node.alternate === previousNode);
231
+ } else if (node.type === "UnaryExpression" && node.operator === "!") {
232
+ getConditions(node.argument, previousNode, !isNegated);
233
+ } else if (node.type === "CallExpression" && node.callee.type === "Identifier" && node.callee.name === "Boolean") {
234
+ getConditions(node.arguments[0], previousNode, isNegated);
235
+ } else if (node.type === "Identifier") {
236
+ conditions.push((isNegated ? "not_" : "") + node.name);
237
+ } else if (node.type === "MemberExpression") {
238
+ conditions.push(
239
+ (isNegated ? "not_" : "") + getMemberExpressionName(node)
240
+ );
241
+ }
242
+ };
243
+ let currentPath = path;
244
+ let previousPath = path;
245
+ while (currentPath) {
246
+ getConditions(currentPath.node, previousPath.node);
247
+ previousPath = currentPath;
248
+ currentPath = currentPath.parentPath;
249
+ }
250
+ if (conditions[0] === "or" || conditions[0] === "and") {
251
+ conditions.shift();
252
+ }
253
+ return conditions.reverse();
254
+ }
255
+ function getMemberExpressionName(node) {
256
+ if (!node.object || !node.property || node.object.type !== "Identifier" && node.object.type !== "MemberExpression") {
257
+ return "";
258
+ }
259
+ const objectName = node.object.type === "Identifier" ? node.object.name : getMemberExpressionName(node.object);
260
+ const property = node.property;
261
+ let propertyName = "";
262
+ if (property.type === "Identifier") {
263
+ propertyName = property.name;
264
+ } else if (property.type === "StringLiteral") {
265
+ propertyName = property.value;
266
+ }
267
+ if (!propertyName) {
268
+ return "";
269
+ }
270
+ return objectName + propertyName[0].toUpperCase() + propertyName.slice(1);
271
+ }
272
+ function getCssName(literal) {
273
+ const conditions = extractConditions(literal);
274
+ if (conditions.length === 0) {
275
+ const mixinName = getStyledComponentName2(literal);
276
+ return mixinName ? mixinName : "yak";
277
+ }
278
+ return conditions.join("_").replace(/\$/g, "");
279
+ }
280
+ var getStyledComponentName2;
281
+ var init_getCssName = __esm({
282
+ "loaders/lib/getCssName.ts"() {
283
+ "use strict";
284
+ getStyledComponentName2 = (taggedTemplateExpressionPath) => {
285
+ const variableDeclaratorPath = taggedTemplateExpressionPath.findParent(
286
+ (path) => path.isVariableDeclarator()
287
+ );
288
+ if (!variableDeclaratorPath || !("id" in variableDeclaratorPath.node) || variableDeclaratorPath.node.id?.type !== "Identifier") {
289
+ return null;
290
+ }
291
+ return variableDeclaratorPath.node.id.name;
292
+ };
293
+ }
294
+ });
295
+
296
+ // loaders/lib/parseCss.ts
297
+ function parseCss(cssString, initialState = {
298
+ isInsideString: false,
299
+ isInsideComment: false,
300
+ isInsidePropertyValue: false,
301
+ isInsideAtRule: false,
302
+ currentScopes: [],
303
+ currentDeclaration: newDeclaration()
304
+ }) {
305
+ let isInsideString = initialState.isInsideString;
306
+ let isInsideComment = initialState.isInsideComment;
307
+ let isInsidePropertyValue = initialState.isInsidePropertyValue;
308
+ let currentScopes = [...initialState.currentScopes];
309
+ let currentCode = "";
310
+ let isInsideAtRule = initialState.isInsideAtRule;
311
+ let currentDeclaration = {
312
+ ...initialState.currentDeclaration,
313
+ scope: currentScopes
314
+ };
315
+ let backSlashes = 0;
316
+ const declarations = [currentDeclaration];
317
+ for (let index = 0; index < cssString.length; index++) {
318
+ let previousBackSlashes = backSlashes;
319
+ const currentCharacter = cssString[index];
320
+ if (currentCharacter === "\\") {
321
+ backSlashes++;
322
+ } else {
323
+ backSlashes = 0;
324
+ }
325
+ if (previousBackSlashes % 2 === 0 && (currentCharacter === '"' || currentCharacter === "'")) {
326
+ if (isInsideString === currentCharacter) {
327
+ isInsideString = false;
328
+ } else if (!isInsideString) {
329
+ isInsideString = currentCharacter;
330
+ }
331
+ }
332
+ if (isInsideString) {
333
+ currentCode += currentCharacter;
334
+ currentDeclaration.value += currentCharacter;
335
+ } else if (currentCharacter === "/" && cssString[index + 1] === "*") {
336
+ let index2 = index + 2;
337
+ isInsideComment = true;
338
+ for (; index2 < cssString.length; index2++) {
339
+ if (cssString[index2] === "*" && cssString[index2 + 1] === "/") {
340
+ isInsideComment = false;
341
+ if (cssString[index2 + 2] === "\n") {
342
+ index2++;
343
+ } else if (cssString[index2 + 2] + cssString[index2 + 3] === "\r\n") {
344
+ index2 += 2;
345
+ }
346
+ break;
347
+ }
348
+ }
349
+ index = index2 + 1;
350
+ continue;
351
+ } else if (currentCharacter === "/" && cssString[index + 1] === "/") {
352
+ let index2 = index + 2;
353
+ isInsideComment = true;
354
+ for (; index2 < cssString.length; index2++) {
355
+ if (cssString[index2] === "\n") {
356
+ isInsideComment = false;
357
+ break;
358
+ }
359
+ }
360
+ index = index2 + 1;
361
+ continue;
362
+ } else if (currentCharacter === "}") {
363
+ currentScopes.pop();
364
+ currentCode = "";
365
+ isInsidePropertyValue = false;
366
+ currentDeclaration.scope = [...currentScopes];
367
+ if (currentDeclaration.property) {
368
+ currentDeclaration.closed = true;
369
+ currentDeclaration = newDeclaration();
370
+ declarations.push(currentDeclaration);
371
+ }
372
+ } else if (currentCharacter === "{") {
373
+ currentScopes.push({
374
+ name: currentCode.trim(),
375
+ type: isInsideAtRule ? "at-rule" : "selector"
376
+ });
377
+ currentCode = "";
378
+ isInsidePropertyValue = false;
379
+ isInsideAtRule = false;
380
+ currentDeclaration.property = "";
381
+ currentDeclaration.value = "";
382
+ } else if (currentCharacter === ";") {
383
+ currentCode = "";
384
+ isInsidePropertyValue = false;
385
+ isInsideAtRule = false;
386
+ currentDeclaration.closed = true;
387
+ currentDeclaration.scope = [...currentScopes];
388
+ currentDeclaration = newDeclaration();
389
+ declarations.push(currentDeclaration);
390
+ } else if (!isInsidePropertyValue && !isInsideAtRule && currentCharacter === ":") {
391
+ isInsidePropertyValue = true;
392
+ currentCode += currentCharacter;
393
+ } else if (!isInsidePropertyValue && currentCharacter === "@") {
394
+ isInsideAtRule = true;
395
+ currentCode += currentCharacter;
396
+ } else {
397
+ const previousCharacter = index === 0 ? currentDeclaration.value.at(-1) : cssString[index - 1];
398
+ const isPreviousCharacterEmpty = index > 0 && !currentCode || !previousCharacter || previousCharacter === " " || previousCharacter === "\n" || previousCharacter === "\r" || previousCharacter === " ";
399
+ const isCurrentCharacterEmpty = currentCharacter === " " || currentCharacter === "\n" || currentCharacter === "\r" || currentCharacter === " ";
400
+ if (!isPreviousCharacterEmpty || !isCurrentCharacterEmpty) {
401
+ currentCode += currentCharacter;
402
+ if (isInsidePropertyValue) {
403
+ if (!isCurrentCharacterEmpty || currentDeclaration.value) {
404
+ currentDeclaration.value += currentCharacter;
405
+ }
406
+ } else {
407
+ currentDeclaration.property += currentCharacter;
408
+ }
409
+ }
410
+ }
411
+ }
412
+ if (!currentDeclaration.property) {
413
+ declarations.pop();
414
+ }
415
+ return {
416
+ state: {
417
+ isInsideString,
418
+ isInsideComment,
419
+ isInsidePropertyValue,
420
+ isInsideAtRule,
421
+ currentDeclaration,
422
+ currentScopes
423
+ },
424
+ declarations
425
+ };
426
+ }
427
+ var newDeclaration;
428
+ var init_parseCss = __esm({
429
+ "loaders/lib/parseCss.ts"() {
430
+ "use strict";
431
+ newDeclaration = () => ({
432
+ scope: [],
433
+ property: "",
434
+ value: "",
435
+ closed: false
436
+ });
437
+ }
438
+ });
439
+
440
+ // loaders/lib/toCss.ts
441
+ var toCss;
442
+ var init_toCss = __esm({
443
+ "loaders/lib/toCss.ts"() {
444
+ "use strict";
445
+ toCss = (declarations) => {
446
+ let css = "";
447
+ let previousScopes = [];
448
+ for (const declaration of declarations) {
449
+ const scopes = declaration.scope;
450
+ for (let i = 0; i < previousScopes.length; i++) {
451
+ if (!scopes[i] || scopes[i].name !== previousScopes[i].name || scopes[i].type !== previousScopes[i].type) {
452
+ for (let j = previousScopes.length - 1; j >= i; j--) {
453
+ css += "\n" + " ".repeat(j) + "}";
454
+ }
455
+ break;
456
+ }
457
+ }
458
+ for (let i = 0; i < scopes.length; i++) {
459
+ if (!previousScopes[i] || scopes[i].name !== previousScopes[i].name || scopes[i].type !== previousScopes[i].type) {
460
+ for (let j = i; j < scopes.length; j++) {
461
+ css += "\n" + " ".repeat(j) + scopes[j].name + " {";
462
+ }
463
+ break;
464
+ }
465
+ }
466
+ css += `
467
+ ${" ".repeat(scopes.length)}${declaration.property}: ${declaration.value};`;
468
+ previousScopes = scopes;
469
+ }
470
+ for (let i = previousScopes.length - 1; i >= 0; i--) {
471
+ css += "\n" + " ".repeat(i) + "}";
472
+ }
473
+ return css;
474
+ };
475
+ }
476
+ });
477
+
478
+ // loaders/lib/appendCssUnitToExpressionValue.ts
479
+ var appendCssUnitToExpressionValue, appendCssUnitToExpressionValue_default;
480
+ var init_appendCssUnitToExpressionValue = __esm({
481
+ "loaders/lib/appendCssUnitToExpressionValue.ts"() {
482
+ "use strict";
483
+ appendCssUnitToExpressionValue = (cssUnit, expression, runtimeInternalHelpers, t) => {
484
+ if (expression.type === "ArrowFunctionExpression") {
485
+ if (expression.body.type !== "BlockStatement") {
486
+ const newBody = t.binaryExpression(
487
+ "+",
488
+ t.parenthesizedExpression(expression.body),
489
+ t.stringLiteral(cssUnit)
490
+ );
491
+ const newArrowFunction = t.arrowFunctionExpression(
492
+ expression.params,
493
+ newBody
494
+ );
495
+ return newArrowFunction;
496
+ }
497
+ } else if (expression.type === "NumericLiteral" || expression.type === "BinaryExpression" || expression.type === "Identifier") {
498
+ const cssUnitLiteral = t.stringLiteral(cssUnit);
499
+ const binaryExpression = t.binaryExpression(
500
+ "+",
501
+ expression,
502
+ cssUnitLiteral
503
+ );
504
+ return binaryExpression;
505
+ }
506
+ const callExpression = t.callExpression(t.identifier("__yak_unitPostFix"), [
507
+ expression,
508
+ t.stringLiteral(cssUnit)
509
+ ]);
510
+ runtimeInternalHelpers.add("__yak_unitPostFix");
511
+ return callExpression;
512
+ };
513
+ appendCssUnitToExpressionValue_default = appendCssUnitToExpressionValue;
514
+ }
515
+ });
516
+
517
+ // loaders/babel-yak-plugin.ts
518
+ var babel_yak_plugin_exports = {};
519
+ __export(babel_yak_plugin_exports, {
520
+ InvalidPositionError: () => InvalidPositionError,
521
+ default: () => babel_yak_plugin_default
522
+ });
523
+ function babel_yak_plugin_default(babel2, options) {
524
+ const { replaces } = options;
525
+ const rootContext = options.rootContext || process.cwd();
526
+ const { types: t } = babel2;
527
+ const hashedFilePaths = /* @__PURE__ */ new WeakMap();
528
+ const getHashedFilePath = (file) => {
529
+ const fromCache = hashedFilePaths.get(file);
530
+ if (fromCache) {
531
+ return fromCache;
532
+ }
533
+ const resourcePath = file.opts.filename;
534
+ if (!resourcePath) {
535
+ throw new Error("resourcePath is undefined");
536
+ }
537
+ const relativePath = (0, import_node_path.relative)(
538
+ rootContext,
539
+ (0, import_node_path.resolve)(rootContext, resourcePath)
540
+ );
541
+ const hashedFilePath = murmurhash2_32_gc(relativePath);
542
+ hashedFilePaths.set(file, hashedFilePath);
543
+ return hashedFilePath;
544
+ };
545
+ const getYakExpressionType = (tag, localVarNames) => {
546
+ if (t.isIdentifier(tag)) {
547
+ if (tag.name === localVarNames.css) {
548
+ return "cssLiteral";
549
+ }
550
+ if (tag.name === localVarNames.keyframes) {
551
+ return "keyframesLiteral";
552
+ }
553
+ }
554
+ if (t.isMemberExpression(tag) && t.isIdentifier(tag.object) && tag.object.name === localVarNames.styled) {
555
+ return "styledLiteral";
556
+ }
557
+ if (t.isCallExpression(tag) && t.isIdentifier(tag.callee) && tag.callee.name === localVarNames.styled) {
558
+ return "styledCall";
559
+ }
560
+ if (t.isCallExpression(tag) && t.isMemberExpression(tag.callee) && t.isIdentifier(tag.callee.property) && tag.callee.property.name === "attrs") {
561
+ return "attrsCall";
562
+ }
563
+ return "unknown";
564
+ };
565
+ return {
566
+ name: "next-yak",
567
+ pre() {
568
+ this.localVarNames = {
569
+ css: void 0,
570
+ styled: void 0,
571
+ keyframes: void 0
572
+ };
573
+ this.isImportedInCurrentFile = false;
574
+ this.variableNameToStyledCall = /* @__PURE__ */ new Map();
575
+ this.topLevelConstBindings = /* @__PURE__ */ new Map();
576
+ this.yakTemplateExpressionsByPath = /* @__PURE__ */ new Map();
577
+ this.yakTemplateExpressionsByName = /* @__PURE__ */ new Map();
578
+ },
579
+ visitor: {
580
+ Program: {
581
+ enter(path) {
582
+ this.topLevelConstBindings = getConstantValues(path, t);
583
+ },
584
+ exit(path, state) {
585
+ if (!this.isImportedInCurrentFile) {
586
+ return;
587
+ }
588
+ const devMode = options.devMode || false;
589
+ const runtimeInternalHelpers = /* @__PURE__ */ new Set();
590
+ const existingNames = /* @__PURE__ */ new Set();
591
+ const createUniqueName = (name, hash) => {
592
+ let i = 0;
593
+ const baseName = hash ? (
594
+ // Hashes will only be used for identifiers which can not be minified
595
+ // therefore the readable name will only be used if development is enabled
596
+ `${devMode ? `${name}_` : ""}${getHashedFilePath(state.file)}`
597
+ ) : name;
598
+ let uniqueName = baseName;
599
+ while (existingNames.has(uniqueName)) {
600
+ i++;
601
+ uniqueName = devMode ? `${baseName}_${i}` : `${baseName}${i.toString(32)}`;
602
+ }
603
+ existingNames.add(uniqueName);
604
+ return uniqueName;
605
+ };
606
+ visitYakExpression(
607
+ this.yakTemplateExpressionsByPath,
608
+ (expression, rootExpression, cssParserState, visitChildren) => {
609
+ transformYakExpressions(
610
+ expression,
611
+ rootExpression,
612
+ cssParserState,
613
+ visitChildren,
614
+ createUniqueName,
615
+ runtimeInternalHelpers,
616
+ getComponentTypes(this.yakTemplateExpressionsByPath),
617
+ this.topLevelConstBindings,
618
+ state.file
619
+ );
620
+ }
621
+ );
622
+ if (runtimeInternalHelpers.size && this.yakImportPath) {
623
+ const newImport = t.importDeclaration(
624
+ [...runtimeInternalHelpers].map(
625
+ (helper) => t.importSpecifier(t.identifier(helper), t.identifier(helper))
626
+ ),
627
+ t.stringLiteral("next-yak/runtime-internals")
628
+ );
629
+ this.yakImportPath.insertAfter(newImport);
630
+ }
631
+ }
632
+ },
633
+ /**
634
+ * Store the name of the imported 'css' and 'styled' variables e.g.:
635
+ * - `import { css, styled } from 'next-yak'` -> { css: 'css', styled: 'styled' }
636
+ * - `import { css as yakCss, styled as yakStyled } from 'next-yak'` -> { css: 'yakCss', styled: 'yakStyled' }
637
+ *
638
+ * Inject the import to the css-module (with .yak.module.css extension)
639
+ * e.g. `import './App.yak.module.css!=!./App?./App.yak.module.css'`
640
+ */
641
+ ImportDeclaration(path, state) {
642
+ const node = path.node;
643
+ if (node.source.value !== "next-yak") {
644
+ return;
645
+ }
646
+ const filePath = state.file.opts.filename;
647
+ if (!filePath) {
648
+ throw new Error("filePath is undefined");
649
+ }
650
+ const fileName = (0, import_node_path.basename)(filePath).replace(/\.tsx?/, "");
651
+ path.insertAfter(
652
+ t.importDeclaration(
653
+ [t.importDefaultSpecifier(t.identifier("__styleYak"))],
654
+ t.stringLiteral(
655
+ `./${fileName}.yak.module.css!=!./${fileName}?./${fileName}.yak.module.css`
656
+ )
657
+ )
658
+ );
659
+ this.yakImportPath = path;
660
+ node.specifiers.forEach((specifier) => {
661
+ if (!("imported" in specifier) || !specifier.imported || !t.isIdentifier(specifier.imported)) {
662
+ return;
663
+ }
664
+ const importSpecifier = specifier.imported;
665
+ const localSpecifier = specifier.local || importSpecifier;
666
+ if (importSpecifier.name === "styled" || importSpecifier.name === "css" || importSpecifier.name === "keyframes") {
667
+ this.localVarNames[importSpecifier.name] = localSpecifier.name;
668
+ this.isImportedInCurrentFile = true;
669
+ }
670
+ });
671
+ },
672
+ /**
673
+ * Replace the tagged template expression
674
+ * - css`...`
675
+ * - styled.div`...`
676
+ * - styled(Component)`...`
677
+ * - styled.div.attrs({})`...`
678
+ * - keyframes`...`
679
+ */
680
+ TaggedTemplateExpression(path, state) {
681
+ if (!this.isImportedInCurrentFile) {
682
+ return;
683
+ }
684
+ const tag = path.node.tag;
685
+ const expressionType = getYakExpressionType(tag, this.localVarNames);
686
+ if (expressionType === "unknown") {
687
+ return;
688
+ }
689
+ replaceTokensInQuasiExpressions(
690
+ path.node.quasi,
691
+ (name2) => {
692
+ if (name2 in replaces) {
693
+ return replaces[name2];
694
+ }
695
+ const styledCall = this.variableNameToStyledCall.get(name2);
696
+ if (styledCall) {
697
+ const { wasAdded, className, astNode } = styledCall;
698
+ if (!wasAdded) {
699
+ styledCall.wasAdded = true;
700
+ astNode.arguments.unshift(
701
+ t.memberExpression(
702
+ t.identifier("__styleYak"),
703
+ t.identifier(className)
704
+ )
705
+ );
706
+ }
707
+ return className;
708
+ }
709
+ return false;
710
+ },
711
+ t
712
+ );
713
+ const parentPosition = getClosestTemplateLiteralExpressionParentPath(
714
+ path,
715
+ this.yakTemplateExpressionsByPath
716
+ );
717
+ const name = !parentPosition ? (
718
+ // root name e.g. const MyButton = styled.div`...` -> "MyButton"
719
+ getStyledComponentName_default(path)
720
+ ) : (
721
+ // nested name e.g. `... ${({$active}) => $active && css`color:red`} ...` -> "active"
722
+ getCssName(path)
723
+ );
724
+ const yakTemplateExpression = {
725
+ name,
726
+ path,
727
+ cssPartQuasis: path.node.quasi.quasis.map((quasi) => quasi.value.raw),
728
+ cssPartExpressions: {},
729
+ hasParent: Boolean(parentPosition?.parent),
730
+ type: expressionType,
731
+ referencedBy: /* @__PURE__ */ new Set()
732
+ };
733
+ const referencedIdentifiers = getIdentifierNamesUsedInExpression(path);
734
+ referencedIdentifiers.forEach((referencedIdentifier) => {
735
+ const referencedExpression = this.yakTemplateExpressionsByName.get(referencedIdentifier);
736
+ if (referencedExpression) {
737
+ referencedExpression.referencedBy.add(yakTemplateExpression);
738
+ }
739
+ });
740
+ const parent = parentPosition?.parent && this.yakTemplateExpressionsByPath.get(parentPosition.parent);
741
+ if (parent) {
742
+ parent.cssPartExpressions[parentPosition.currentIndex] ||= [];
743
+ parent.cssPartExpressions[parentPosition.currentIndex].push(
744
+ yakTemplateExpression
745
+ );
746
+ }
747
+ this.yakTemplateExpressionsByPath.set(path, yakTemplateExpression);
748
+ this.yakTemplateExpressionsByName.set(name, yakTemplateExpression);
749
+ }
750
+ }
751
+ };
752
+ }
753
+ function getIdentifierNamesUsedInExpression(path) {
754
+ const names = /* @__PURE__ */ new Set();
755
+ for (const node of path.node.quasi.expressions) {
756
+ if (import_core.types.isIdentifier(node)) {
757
+ names.add(node.name);
758
+ }
759
+ }
760
+ return names;
761
+ }
762
+ function visitYakExpression(yakTemplateExpressions, visitor) {
763
+ const rootYakTemplateExpressions = Array.from(
764
+ yakTemplateExpressions.values()
765
+ ).filter((expression) => !expression.hasParent);
766
+ const recursiveVisitor = (expression, rootExpression, cssParserState) => {
767
+ visitor(
768
+ expression,
769
+ rootExpression,
770
+ cssParserState,
771
+ (quasiIndex, cssParserState2) => {
772
+ expression.cssPartExpressions[quasiIndex]?.forEach(
773
+ (childExpression) => {
774
+ recursiveVisitor(childExpression, rootExpression, cssParserState2);
775
+ }
776
+ );
777
+ }
778
+ );
779
+ };
780
+ rootYakTemplateExpressions.forEach((expression) => {
781
+ const initialParserState = parseCss("");
782
+ recursiveVisitor(expression, expression, initialParserState.state);
783
+ });
784
+ }
785
+ function transformYakExpressions(expression, rootExpression, cssParserState, visitChildren, createUniqueName, runtimeInternalHelpers, componentTypeMapping, constantValues, file) {
786
+ const identifier = createUniqueName(
787
+ expression === rootExpression ? expression.name : `${rootExpression.name}__${expression.name}`
788
+ );
789
+ const rootDeclarations = rootExpressionCssDeclarations.get(rootExpression) || [];
790
+ if (rootExpression === expression) {
791
+ rootExpressionCssDeclarations.set(rootExpression, rootDeclarations);
792
+ }
793
+ const newArguments = /* @__PURE__ */ new Set();
794
+ const cssVariables = {};
795
+ let addedOwnClassName = false;
796
+ let currentCssParserState = cssParserState;
797
+ for (let i = 0; i < expression.cssPartQuasis.length; i++) {
798
+ let cssChunk = expression.cssPartQuasis[i].replace(/\\\\/g, "\\");
799
+ const quasiExpression = expression.path.node.quasi.expressions[i];
800
+ if (import_core.types.isIdentifier(quasiExpression)) {
801
+ let replaceValue = null;
802
+ if (componentTypeMapping[quasiExpression.name]) {
803
+ if (componentTypeMapping[quasiExpression.name] === "keyframesLiteral") {
804
+ replaceValue = quasiExpression.name;
805
+ } else if (componentTypeMapping[quasiExpression.name] === "styledLiteral" || componentTypeMapping[quasiExpression.name] === "styledCall" || componentTypeMapping[quasiExpression.name] === "attrsCall") {
806
+ replaceValue = `.${quasiExpression.name}`;
807
+ }
808
+ } else if (constantValues.has(quasiExpression.name)) {
809
+ const constantValue = constantValues.get(quasiExpression.name);
810
+ if (!constantValue || constantValue.type === "variable" && constantValue.value === null) {
811
+ throw new InvalidPositionError(
812
+ `Could not resolve value for ${quasiExpression.name}`,
813
+ quasiExpression,
814
+ file
815
+ );
816
+ }
817
+ if (constantValue.type === "module") {
818
+ throw new InvalidPositionError(
819
+ `Imported values cannot be used as constants`,
820
+ quasiExpression,
821
+ file,
822
+ "Move the constant into the current file or into a .yak file"
823
+ );
824
+ }
825
+ if (constantValue.type === "function") {
826
+ throw new InvalidPositionError(
827
+ `Function constants are not supported yet`,
828
+ quasiExpression,
829
+ file
830
+ );
831
+ }
832
+ replaceValue = String(constantValue?.value);
833
+ } else {
834
+ }
835
+ if (replaceValue !== null) {
836
+ expression.cssPartQuasis[i + 1] = expression.cssPartQuasis[i] + replaceValue + (expression.cssPartQuasis[i + 1] || "");
837
+ continue;
838
+ }
839
+ }
840
+ const parsedCss = parseCss(cssChunk, currentCssParserState);
841
+ currentCssParserState = parsedCss.state;
842
+ if (import_core.types.isTSType(quasiExpression)) {
843
+ throw new Error(
844
+ "Type annotations are not allowed in css template literals"
845
+ );
846
+ }
847
+ if (parsedCss.declarations.length > 0 && !addedOwnClassName) {
848
+ newArguments.add(
849
+ import_core.types.memberExpression(
850
+ import_core.types.identifier("__styleYak"),
851
+ import_core.types.identifier(identifier)
852
+ )
853
+ );
854
+ addedOwnClassName = true;
855
+ }
856
+ const scopedDeclarations = parsedCss.declarations.map((declaration) => ({
857
+ ...declaration,
858
+ scope: [
859
+ expression.type === "keyframesLiteral" ? { name: `@keyframes ${identifier}`, type: "at-rule" } : { name: `.${identifier}`, type: "selector" },
860
+ ...declaration.scope
861
+ ]
862
+ }));
863
+ if (quasiExpression) {
864
+ if (currentCssParserState.isInsidePropertyValue) {
865
+ const constantName = getConstantName(quasiExpression, import_core.types);
866
+ if (!import_core.types.isArrowFunctionExpression(quasiExpression) && // On top level only arrow functions are allowed as css prop values
867
+ (!expression.hasParent || // Is using root constant inside for a css prop value:
868
+ // const primary = 'red';
869
+ // const Button = styled.button`color: ${({$primary}) => $primary && primaryColor}`
870
+ constantName && constantValues.has(constantName))) {
871
+ throw new InvalidPositionError(
872
+ "Possible constant used as runtime value for a css variable",
873
+ quasiExpression,
874
+ file,
875
+ `Please move the constant to a .yak import or use an arrow function
876
+ e.g.:
877
+ | import { primaryColor } from './foo.yak'
878
+ | const MyStyledDiv = styled.div\`color: \${primaryColor};\``
879
+ );
880
+ }
881
+ const cssVarName = createUniqueName(
882
+ `${identifier}-${parsedCss.state.currentDeclaration.property}`,
883
+ true
884
+ );
885
+ cssVariables[`--${cssVarName}`] = quasiExpression;
886
+ currentCssParserState.currentDeclaration.value += `var(--${cssVarName})`;
887
+ const cssUnit = expression.cssPartQuasis[i + 1]?.match(/^([a-z]+|%)/i)?.[0];
888
+ if (cssUnit) {
889
+ cssVariables[`--${cssVarName}`] = appendCssUnitToExpressionValue_default(
890
+ cssUnit,
891
+ quasiExpression,
892
+ runtimeInternalHelpers,
893
+ import_core.types
894
+ );
895
+ expression.cssPartQuasis[i + 1] = expression.cssPartQuasis[i + 1].substring(cssUnit.length);
896
+ }
897
+ scopedDeclarations.pop();
898
+ } else {
899
+ if (currentCssParserState.currentScopes.length > 0 && quasiExpression.type !== "TaggedTemplateExpression" && quasiExpression.type !== "ArrowFunctionExpression") {
900
+ throw new InvalidPositionError(
901
+ "Mixins are not allowed inside nested selectors",
902
+ quasiExpression,
903
+ file,
904
+ "Use an inline css literal instead or move the selector into the mixin"
905
+ );
906
+ }
907
+ newArguments.add(quasiExpression);
908
+ if (expression.cssPartQuasis[i + 1]?.startsWith(";")) {
909
+ expression.cssPartQuasis[i + 1] = expression.cssPartQuasis[i + 1].substring(1);
910
+ }
911
+ }
912
+ }
913
+ rootDeclarations.push(...scopedDeclarations);
914
+ visitChildren(i, parsedCss.state);
915
+ }
916
+ if (Object.keys(cssVariables).length) {
917
+ newArguments.add(
918
+ import_core.types.objectExpression([
919
+ import_core.types.objectProperty(
920
+ import_core.types.stringLiteral(`style`),
921
+ import_core.types.objectExpression(
922
+ Object.entries(cssVariables).map(
923
+ ([key, value]) => import_core.types.objectProperty(import_core.types.stringLiteral(key), value)
924
+ )
925
+ )
926
+ )
927
+ ])
928
+ );
929
+ }
930
+ if (rootExpression === expression) {
931
+ let cssCode = toCss(rootDeclarations).trimStart();
932
+ const isReferencedByOtherYakComponents = expression.referencedBy.size > 0;
933
+ if (addedOwnClassName === false && isReferencedByOtherYakComponents) {
934
+ newArguments.add(
935
+ import_core.types.memberExpression(
936
+ import_core.types.identifier("__styleYak"),
937
+ import_core.types.identifier(identifier)
938
+ )
939
+ );
940
+ cssCode = `.${identifier} {}
941
+ ${cssCode}`;
942
+ }
943
+ if (cssCode) {
944
+ expression.path.addComment("leading", "YAK Extracted CSS:\n" + cssCode);
945
+ }
946
+ }
947
+ expression.path.replaceWith(
948
+ import_core.types.callExpression(expression.path.node.tag, [...newArguments])
949
+ );
950
+ }
951
+ function getComponentTypes(yakTemplateExpressions) {
952
+ const nameTypeMap = Array.from(yakTemplateExpressions.values()).filter((expression) => !expression.hasParent).map((expression) => [expression.name, expression.type]);
953
+ return Object.fromEntries(nameTypeMap);
954
+ }
955
+ var import_core, import_node_path, InvalidPositionError, getClosestTemplateLiteralExpressionParentPath, rootExpressionCssDeclarations;
956
+ var init_babel_yak_plugin = __esm({
957
+ "loaders/babel-yak-plugin.ts"() {
958
+ "use strict";
959
+ import_core = require("@babel/core");
960
+ import_node_path = require("path");
961
+ init_getConstantValues();
962
+ init_hash();
963
+ init_replaceQuasiExpressionTokens();
964
+ init_getStyledComponentName();
965
+ init_getCssName();
966
+ init_parseCss();
967
+ init_toCss();
968
+ init_appendCssUnitToExpressionValue();
969
+ InvalidPositionError = class extends Error {
970
+ /**
971
+ * Add the expression code that caused the error to the message
972
+ * for better debugging
973
+ */
974
+ constructor(message, expression, file, recommendedFix) {
975
+ let errorText = message;
976
+ const line = expression.loc?.start.line ?? -1;
977
+ if (line !== -1) {
978
+ errorText = `line ${line}: ${errorText}`;
979
+ }
980
+ if (expression.start && expression.end) {
981
+ errorText += `
982
+ found: \${${file.code.slice(
983
+ expression.start,
984
+ expression.end
985
+ )}}`;
986
+ }
987
+ if (recommendedFix) {
988
+ errorText += `
989
+ ${recommendedFix}`;
990
+ }
991
+ super(errorText);
992
+ }
993
+ };
994
+ getClosestTemplateLiteralExpressionParentPath = (path, knownParents) => {
995
+ let grandChild = path;
996
+ let child = path;
997
+ let parent = path.parentPath;
998
+ while (parent) {
999
+ if (import_core.types.isTaggedTemplateExpression(parent.node) && knownParents.has(
1000
+ parent
1001
+ )) {
1002
+ if (!import_core.types.isTemplateLiteral(child.node) || !import_core.types.isExpression(grandChild.node)) {
1003
+ throw new Error(
1004
+ "Unexpected Error - This AST structure is unexpected - please open an issue in the repository"
1005
+ );
1006
+ }
1007
+ const currentIndex = child.node.expressions.indexOf(grandChild.node);
1008
+ return {
1009
+ parent,
1010
+ currentIndex
1011
+ };
1012
+ }
1013
+ if (!parent.parentPath) {
1014
+ return null;
1015
+ }
1016
+ grandChild = child;
1017
+ child = parent;
1018
+ parent = parent.parentPath;
1019
+ }
1020
+ return null;
1021
+ };
1022
+ rootExpressionCssDeclarations = /* @__PURE__ */ new WeakMap();
1023
+ }
1024
+ });
1025
+
1026
+ // loaders/cssloader.ts
1027
+ var cssloader_exports = {};
1028
+ __export(cssloader_exports, {
1029
+ default: () => cssloader
1030
+ });
1031
+ module.exports = __toCommonJS(cssloader_exports);
1032
+
1033
+ // loaders/tsloader.ts
1034
+ var import_core2 = __toESM(require("@babel/core"), 1);
1035
+
1036
+ // loaders/lib/getYakImports.ts
1037
+ var getYakImports = (code) => {
1038
+ const codeWithoutComments = code.replace(/\/\*[\s\S]*?\*\//g, "");
1039
+ const allImports = codeWithoutComments.matchAll(
1040
+ /(^|\n|;)\s*import\s+(?:(\w+(?:\s+as\s+\w+)?)\s*,?\s*)?(?:{([^}]*)})?\s+from\s+["']([^'"]+\.yak)["'](;|\n)/g
1041
+ );
1042
+ return [...allImports].map(([, , defaultImport, namedImports, from]) => {
1043
+ const imports = namedImports?.split(",").map((namedImport) => {
1044
+ const [importedName, localName = importedName] = namedImport.replace(/^type\s+/, "").trim().split(/\s+as\s+/);
1045
+ return { localName, importedName };
1046
+ }) ?? [];
1047
+ if (defaultImport) {
1048
+ imports.push(parseDefaultImport(defaultImport));
1049
+ }
1050
+ return { imports, from };
1051
+ });
1052
+ };
1053
+ function parseDefaultImport(defaultImport) {
1054
+ const defaultImportArray = defaultImport.split(/\s+as\s+/);
1055
+ return {
1056
+ localName: defaultImportArray[1] ?? defaultImportArray[0],
1057
+ importedName: defaultImportArray[0]
1058
+ };
1059
+ }
1060
+ var getYakImports_default = getYakImports;
1061
+
1062
+ // loaders/tsloader.ts
1063
+ init_babel_yak_plugin();
1064
+ async function tsloader(source) {
1065
+ if (!source.includes("next-yak")) {
1066
+ return source;
1067
+ }
1068
+ const callback = this.async();
1069
+ const { rootContext, resourcePath } = this;
1070
+ const isYakFile = /\.yak\.(j|t)sx?$/.test(resourcePath.matches);
1071
+ const importedYakConstants = isYakFile ? [] : getYakImports_default(source);
1072
+ const replaces = {};
1073
+ await Promise.all(
1074
+ importedYakConstants.map(async ({ imports, from }) => {
1075
+ const constantValues = await this.importModule(from, {
1076
+ layer: "yak-importModule"
1077
+ });
1078
+ imports.forEach(({ localName, importedName }) => {
1079
+ replaces[localName] = constantValues[importedName];
1080
+ });
1081
+ })
1082
+ );
1083
+ let result = null;
1084
+ try {
1085
+ result = import_core2.default.transformSync(source, {
1086
+ filename: resourcePath,
1087
+ configFile: false,
1088
+ plugins: [
1089
+ [
1090
+ "@babel/plugin-syntax-typescript",
1091
+ { isTSX: this.resourcePath.endsWith(".tsx") }
1092
+ ],
1093
+ [
1094
+ await Promise.resolve().then(() => (init_babel_yak_plugin(), babel_yak_plugin_exports)).then((m) => m.default),
1095
+ {
1096
+ replaces,
1097
+ rootContext,
1098
+ devMode: this.mode === "development"
1099
+ }
1100
+ ]
1101
+ ]
1102
+ });
1103
+ } catch (error) {
1104
+ if (error instanceof InvalidPositionError) {
1105
+ return callback(new Error(error.message));
1106
+ }
1107
+ return callback(
1108
+ error instanceof Error ? error : new Error("babel transform failed")
1109
+ );
1110
+ }
1111
+ if (!result?.code) {
1112
+ return callback(new Error("babel transform failed"));
1113
+ }
1114
+ return callback(null, result.code, result.map);
1115
+ }
1116
+
1117
+ // loaders/cssloader.ts
1118
+ async function cssloader(source) {
1119
+ const callback = this.async();
1120
+ return tsloader.call(
1121
+ {
1122
+ ...this,
1123
+ async: () => (err, code) => {
1124
+ if (err || !code) {
1125
+ return callback(err || new Error("No code returned"));
1126
+ }
1127
+ return callback(null, extractCss(code));
1128
+ }
1129
+ },
1130
+ source
1131
+ );
1132
+ }
1133
+ function extractCss(code) {
1134
+ const codeParts = code.split("/*YAK Extracted CSS:\n");
1135
+ let result = "";
1136
+ for (let i = 1; i < codeParts.length; i++) {
1137
+ const codeUntilEnd = codeParts[i].split("*/")[0];
1138
+ result += codeUntilEnd;
1139
+ }
1140
+ return result;
1141
+ }
1142
+ //# sourceMappingURL=cssloader.cjs.map