postcss-clampwind 0.0.6 → 0.0.8

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.
@@ -154,6 +154,28 @@ var sortScreens = (screens) => {
154
154
  return acc;
155
155
  }, {});
156
156
  };
157
+ var extractMaxValue = (params) => {
158
+ if (!params) return null;
159
+ let match = params.match(/<\s*([^),\s]+)/);
160
+ if (match) return match[1].trim();
161
+ match = params.match(/max-width:\s*([^),\s]+)/);
162
+ if (match) return match[1].trim();
163
+ match = params.match(/not\s+all\s+and\s*\(\s*min-width:\s*([^),\s]+)\s*\)/);
164
+ if (match) return match[1].trim();
165
+ return null;
166
+ };
167
+ var extractMinValue = (params) => {
168
+ if (!params) return null;
169
+ let match = params.match(/>=?\s*([^),\s]+)/);
170
+ if (match) return match[1].trim();
171
+ match = params.match(/min-width:\s*([^),\s]+)/);
172
+ if (match) return match[1].trim();
173
+ match = params.match(/not\s+all\s+and\s*\(\s*max-width:\s*([^),\s]+)\s*\)/);
174
+ if (match) {
175
+ return match[1].trim();
176
+ }
177
+ return null;
178
+ };
157
179
 
158
180
  // src/clampwind.js
159
181
  var clampwind = (opts = {}) => {
@@ -339,197 +361,130 @@ var clampwind = (opts = {}) => {
339
361
  decl.value = clamp;
340
362
  return true;
341
363
  };
364
+ const getNestedStructure = (atRule) => {
365
+ const isNested = atRule.parent?.type === "atrule" && atRule.parent?.name === "media";
366
+ const hasNestedMedia = atRule.nodes?.some(
367
+ (node) => node.type === "atrule" && node.name === "media"
368
+ );
369
+ return { isNested, hasNestedMedia };
370
+ };
371
+ const processMediaQuery = (atRule, parentAtRule = null) => {
372
+ const clampDecls = [];
373
+ atRule.walkDecls((decl) => {
374
+ if (extractTwoValidClampArgs(decl.value)) {
375
+ clampDecls.push(decl);
376
+ }
377
+ });
378
+ if (!clampDecls.length) return;
379
+ const screenValues = Object.values(screens);
380
+ if (parentAtRule) {
381
+ const currentParams = atRule.params;
382
+ const parentParams = parentAtRule.params;
383
+ const minScreen = extractMinValue(parentParams) || extractMinValue(currentParams);
384
+ const maxScreen = extractMaxValue(parentParams) || extractMaxValue(currentParams);
385
+ if (minScreen && maxScreen) {
386
+ clampDecls.forEach((decl) => {
387
+ processClampDeclaration(decl, minScreen, maxScreen, false);
388
+ });
389
+ }
390
+ } else {
391
+ const currentParams = atRule.params;
392
+ const minValue = extractMinValue(currentParams);
393
+ const maxValue = extractMaxValue(currentParams);
394
+ if (minValue && !maxValue) {
395
+ const minScreen = minValue;
396
+ const maxScreen = defaultClampRange.max || screenValues[screenValues.length - 1];
397
+ clampDecls.forEach((decl) => {
398
+ processClampDeclaration(decl, minScreen, maxScreen, false);
399
+ });
400
+ } else if (maxValue && !minValue) {
401
+ const minScreen = defaultClampRange.min || screenValues[0];
402
+ const maxScreen = maxValue;
403
+ clampDecls.forEach((decl) => {
404
+ processClampDeclaration(decl, minScreen, maxScreen, false);
405
+ });
406
+ } else if (minValue && maxValue) {
407
+ clampDecls.forEach((decl) => {
408
+ processClampDeclaration(decl, minValue, maxValue, false);
409
+ });
410
+ }
411
+ }
412
+ };
413
+ const processContainerQuery = (atRule, parentAtRule = null) => {
414
+ const clampDecls = [];
415
+ atRule.walkDecls((decl) => {
416
+ if (extractTwoValidClampArgs(decl.value)) {
417
+ clampDecls.push(decl);
418
+ }
419
+ });
420
+ if (!clampDecls.length) return;
421
+ const containerValues = Object.values(containerScreens);
422
+ if (parentAtRule) {
423
+ const currentParams = atRule.params;
424
+ const parentParams = parentAtRule.params;
425
+ const minContainer = extractMinValue(parentParams) || extractMinValue(currentParams);
426
+ const maxContainer = extractMaxValue(parentParams) || extractMaxValue(currentParams);
427
+ if (minContainer && maxContainer) {
428
+ clampDecls.forEach((decl) => {
429
+ processClampDeclaration(decl, minContainer, maxContainer, true);
430
+ });
431
+ }
432
+ } else {
433
+ const currentParams = atRule.params;
434
+ const minValue = extractMinValue(currentParams);
435
+ const maxValue = extractMaxValue(currentParams);
436
+ if (minValue && !maxValue) {
437
+ const minContainer = minValue;
438
+ const maxContainer = containerValues[containerValues.length - 1];
439
+ clampDecls.forEach((decl) => {
440
+ processClampDeclaration(decl, minContainer, maxContainer, true);
441
+ });
442
+ } else if (maxValue && !minValue) {
443
+ const minContainer = containerValues[0];
444
+ const maxContainer = maxValue;
445
+ clampDecls.forEach((decl) => {
446
+ processClampDeclaration(decl, minContainer, maxContainer, true);
447
+ });
448
+ } else if (minValue && maxValue) {
449
+ clampDecls.forEach((decl) => {
450
+ processClampDeclaration(decl, minValue, maxValue, true);
451
+ });
452
+ }
453
+ }
454
+ };
342
455
  return {
343
456
  // Use OnceExit to ensure Tailwind has generated its content
344
457
  OnceExit(root, { result }) {
345
458
  collectConfig(root);
346
459
  finalizeConfig();
460
+ const processedAtRules = /* @__PURE__ */ new WeakSet();
347
461
  root.walkAtRules("media", (atRule) => {
348
- const clampDecls = [];
349
- atRule.walkDecls((decl) => {
350
- if (extractTwoValidClampArgs(decl.value)) {
351
- clampDecls.push(decl);
352
- }
353
- });
354
- if (!clampDecls.length) return;
355
- clampDecls.forEach((decl) => {
356
- const isNested = decl.parent?.type === "atrule" && decl.parent?.parent.type === "atrule";
357
- const isSameAtRule = decl.parent?.name === decl.parent?.parent.name;
358
- if (isNested && isSameAtRule) {
359
- const currentParams2 = decl.parent.params;
360
- const parentParams = decl.parent.parent.params;
361
- let minScreen = null;
362
- let maxScreen = null;
363
- if (parentParams.includes(">") || parentParams.includes("min-width")) {
364
- let match = parentParams.match(/>=?\s*([^),\s]+)/);
365
- if (match) {
366
- minScreen = match[1].trim();
367
- } else {
368
- match = parentParams.match(/min-width:\s*([^),\s]+)/);
369
- if (match) minScreen = match[1].trim();
370
- }
371
- }
372
- if (!minScreen && (currentParams2.includes(">") || currentParams2.includes("min-width"))) {
373
- let match = currentParams2.match(/>=?\s*([^),\s]+)/);
374
- if (match) {
375
- minScreen = match[1].trim();
376
- } else {
377
- match = currentParams2.match(/min-width:\s*([^),\s]+)/);
378
- if (match) minScreen = match[1].trim();
379
- }
380
- }
381
- if (parentParams.includes("<") || parentParams.includes("max-width")) {
382
- let match = parentParams.match(/<\s*([^),\s]+)/);
383
- if (match) {
384
- maxScreen = match[1].trim();
385
- } else {
386
- match = parentParams.match(/max-width:\s*([^),\s]+)/);
387
- if (match) maxScreen = match[1].trim();
388
- }
389
- }
390
- if (!maxScreen && (currentParams2.includes("<") || currentParams2.includes("max-width"))) {
391
- let match = currentParams2.match(/<\s*([^),\s]+)/);
392
- if (match) {
393
- maxScreen = match[1].trim();
394
- } else {
395
- match = currentParams2.match(/max-width:\s*([^),\s]+)/);
396
- if (match) maxScreen = match[1].trim();
397
- }
398
- }
399
- if (minScreen && maxScreen) {
400
- clampDecls.forEach((decl2) => {
401
- processClampDeclaration(decl2, minScreen, maxScreen, false);
402
- });
403
- }
404
- return;
405
- }
406
- if (isNested && !isSameAtRule) {
407
- clampDecls.forEach((decl2) => {
408
- decl2.value = ` ${decl2.value} /* Invalid nested @media rules */`;
409
- });
410
- return;
411
- }
412
- const screenValues = Object.values(screens);
413
- const currentParams = decl.parent.params;
414
- if (currentParams.includes(">") || currentParams.includes("min-width")) {
415
- let match = currentParams.match(/>=?\s*([^),\s]+)/);
416
- if (!match) {
417
- match = currentParams.match(/min-width:\s*([^),\s]+)/);
418
- }
419
- if (match) {
420
- const minScreen = match[1].trim();
421
- const maxScreen = defaultClampRange.max || screenValues[screenValues.length - 1];
422
- processClampDeclaration(decl, minScreen, maxScreen, false);
423
- }
424
- } else if (currentParams.includes("<") || currentParams.includes("max-width")) {
425
- let match = currentParams.match(/<\s*([^),\s]+)/);
426
- if (!match) {
427
- match = currentParams.match(/max-width:\s*([^),\s]+)/);
428
- }
429
- if (match) {
430
- const minScreen = defaultClampRange.min || screenValues[0];
431
- const maxScreen = match[1].trim();
432
- processClampDeclaration(decl, minScreen, maxScreen, false);
433
- }
434
- }
435
- });
462
+ if (processedAtRules.has(atRule)) return;
463
+ const { isNested, hasNestedMedia } = getNestedStructure(atRule);
464
+ if (hasNestedMedia) {
465
+ atRule.walkAtRules("media", (nestedAtRule) => {
466
+ processedAtRules.add(nestedAtRule);
467
+ processMediaQuery(nestedAtRule, atRule);
468
+ });
469
+ } else if (isNested) {
470
+ return;
471
+ } else {
472
+ processMediaQuery(atRule);
473
+ }
436
474
  });
437
475
  root.walkAtRules("container", (atRule) => {
438
- const clampDecls = [];
439
- atRule.walkDecls((decl) => {
440
- if (extractTwoValidClampArgs(decl.value)) {
441
- clampDecls.push(decl);
442
- }
443
- });
444
- if (!clampDecls.length) return;
445
- clampDecls.forEach((decl) => {
446
- const isNested = decl.parent?.type === "atrule" && decl.parent?.parent.type === "atrule";
447
- const isSameAtRule = decl.parent?.name === decl.parent?.parent.name;
448
- if (isNested && isSameAtRule) {
449
- const currentParams2 = decl.parent.params;
450
- const parentParams = decl.parent.parent.params;
451
- let minContainer = null;
452
- let maxContainer = null;
453
- if (parentParams.includes(">") || parentParams.includes("min-width")) {
454
- let match = parentParams.match(/>=?\s*([^),\s]+)/);
455
- if (!match) {
456
- match = parentParams.match(/min-width:\s*([^),\s]+)/);
457
- }
458
- if (match) minContainer = match[1].trim();
459
- }
460
- if (!minContainer && (currentParams2.includes(">") || currentParams2.includes("min-width"))) {
461
- let match = currentParams2.match(/>=?\s*([^),\s]+)/);
462
- if (!match) {
463
- match = currentParams2.match(/min-width:\s*([^),\s]+)/);
464
- }
465
- if (match) minContainer = match[1].trim();
466
- }
467
- if (parentParams.includes("<") || parentParams.includes("max-width")) {
468
- let match = parentParams.match(/<\s*([^),\s]+)/);
469
- if (!match) {
470
- match = parentParams.match(/max-width:\s*([^),\s]+)/);
471
- }
472
- if (match) maxContainer = match[1].trim();
473
- }
474
- if (!maxContainer && (currentParams2.includes("<") || currentParams2.includes("max-width"))) {
475
- let match = currentParams2.match(/<\s*([^),\s]+)/);
476
- if (!match) {
477
- match = currentParams2.match(/max-width:\s*([^),\s]+)/);
478
- }
479
- if (match) maxContainer = match[1].trim();
480
- }
481
- if (minContainer && maxContainer) {
482
- clampDecls.forEach((decl2) => {
483
- processClampDeclaration(
484
- decl2,
485
- minContainer,
486
- maxContainer,
487
- true
488
- );
489
- });
490
- }
491
- return;
492
- }
493
- if (isNested && !isSameAtRule) {
494
- clampDecls.forEach((decl2) => {
495
- decl2.value = ` ${decl2.value} /* Invalid nested @container rules */`;
496
- });
497
- return;
498
- }
499
- const containerValues = Object.values(containerScreens);
500
- const currentParams = decl.parent.params;
501
- if (currentParams.includes(">") || currentParams.includes("min-width")) {
502
- let match = currentParams.match(/>=?\s*([^),\s]+)/);
503
- if (!match) {
504
- match = currentParams.match(/min-width:\s*([^),\s]+)/);
505
- }
506
- if (match) {
507
- const minContainer = match[1].trim();
508
- const maxContainer = containerValues[containerValues.length - 1];
509
- processClampDeclaration(
510
- decl,
511
- minContainer,
512
- maxContainer,
513
- true
514
- );
515
- }
516
- } else if (currentParams.includes("<") || currentParams.includes("max-width")) {
517
- let match = currentParams.match(/<\s*([^),\s]+)/);
518
- if (!match) {
519
- match = currentParams.match(/max-width:\s*([^),\s]+)/);
520
- }
521
- if (match) {
522
- const minContainer = containerValues[0];
523
- const maxContainer = match[1].trim();
524
- processClampDeclaration(
525
- decl,
526
- minContainer,
527
- maxContainer,
528
- true
529
- );
530
- }
531
- }
532
- });
476
+ if (processedAtRules.has(atRule)) return;
477
+ const { isNested, hasNestedMedia } = getNestedStructure(atRule);
478
+ if (hasNestedMedia) {
479
+ atRule.walkAtRules("container", (nestedAtRule) => {
480
+ processedAtRules.add(nestedAtRule);
481
+ processContainerQuery(nestedAtRule, atRule);
482
+ });
483
+ } else if (isNested) {
484
+ return;
485
+ } else {
486
+ processContainerQuery(atRule);
487
+ }
533
488
  });
534
489
  root.walkRules((rule) => {
535
490
  let parent = rule.parent;
@@ -129,6 +129,28 @@ var sortScreens = (screens) => {
129
129
  return acc;
130
130
  }, {});
131
131
  };
132
+ var extractMaxValue = (params) => {
133
+ if (!params) return null;
134
+ let match = params.match(/<\s*([^),\s]+)/);
135
+ if (match) return match[1].trim();
136
+ match = params.match(/max-width:\s*([^),\s]+)/);
137
+ if (match) return match[1].trim();
138
+ match = params.match(/not\s+all\s+and\s*\(\s*min-width:\s*([^),\s]+)\s*\)/);
139
+ if (match) return match[1].trim();
140
+ return null;
141
+ };
142
+ var extractMinValue = (params) => {
143
+ if (!params) return null;
144
+ let match = params.match(/>=?\s*([^),\s]+)/);
145
+ if (match) return match[1].trim();
146
+ match = params.match(/min-width:\s*([^),\s]+)/);
147
+ if (match) return match[1].trim();
148
+ match = params.match(/not\s+all\s+and\s*\(\s*max-width:\s*([^),\s]+)\s*\)/);
149
+ if (match) {
150
+ return match[1].trim();
151
+ }
152
+ return null;
153
+ };
132
154
 
133
155
  // src/clampwind.js
134
156
  var clampwind = (opts = {}) => {
@@ -314,197 +336,130 @@ var clampwind = (opts = {}) => {
314
336
  decl.value = clamp;
315
337
  return true;
316
338
  };
339
+ const getNestedStructure = (atRule) => {
340
+ const isNested = atRule.parent?.type === "atrule" && atRule.parent?.name === "media";
341
+ const hasNestedMedia = atRule.nodes?.some(
342
+ (node) => node.type === "atrule" && node.name === "media"
343
+ );
344
+ return { isNested, hasNestedMedia };
345
+ };
346
+ const processMediaQuery = (atRule, parentAtRule = null) => {
347
+ const clampDecls = [];
348
+ atRule.walkDecls((decl) => {
349
+ if (extractTwoValidClampArgs(decl.value)) {
350
+ clampDecls.push(decl);
351
+ }
352
+ });
353
+ if (!clampDecls.length) return;
354
+ const screenValues = Object.values(screens);
355
+ if (parentAtRule) {
356
+ const currentParams = atRule.params;
357
+ const parentParams = parentAtRule.params;
358
+ const minScreen = extractMinValue(parentParams) || extractMinValue(currentParams);
359
+ const maxScreen = extractMaxValue(parentParams) || extractMaxValue(currentParams);
360
+ if (minScreen && maxScreen) {
361
+ clampDecls.forEach((decl) => {
362
+ processClampDeclaration(decl, minScreen, maxScreen, false);
363
+ });
364
+ }
365
+ } else {
366
+ const currentParams = atRule.params;
367
+ const minValue = extractMinValue(currentParams);
368
+ const maxValue = extractMaxValue(currentParams);
369
+ if (minValue && !maxValue) {
370
+ const minScreen = minValue;
371
+ const maxScreen = defaultClampRange.max || screenValues[screenValues.length - 1];
372
+ clampDecls.forEach((decl) => {
373
+ processClampDeclaration(decl, minScreen, maxScreen, false);
374
+ });
375
+ } else if (maxValue && !minValue) {
376
+ const minScreen = defaultClampRange.min || screenValues[0];
377
+ const maxScreen = maxValue;
378
+ clampDecls.forEach((decl) => {
379
+ processClampDeclaration(decl, minScreen, maxScreen, false);
380
+ });
381
+ } else if (minValue && maxValue) {
382
+ clampDecls.forEach((decl) => {
383
+ processClampDeclaration(decl, minValue, maxValue, false);
384
+ });
385
+ }
386
+ }
387
+ };
388
+ const processContainerQuery = (atRule, parentAtRule = null) => {
389
+ const clampDecls = [];
390
+ atRule.walkDecls((decl) => {
391
+ if (extractTwoValidClampArgs(decl.value)) {
392
+ clampDecls.push(decl);
393
+ }
394
+ });
395
+ if (!clampDecls.length) return;
396
+ const containerValues = Object.values(containerScreens);
397
+ if (parentAtRule) {
398
+ const currentParams = atRule.params;
399
+ const parentParams = parentAtRule.params;
400
+ const minContainer = extractMinValue(parentParams) || extractMinValue(currentParams);
401
+ const maxContainer = extractMaxValue(parentParams) || extractMaxValue(currentParams);
402
+ if (minContainer && maxContainer) {
403
+ clampDecls.forEach((decl) => {
404
+ processClampDeclaration(decl, minContainer, maxContainer, true);
405
+ });
406
+ }
407
+ } else {
408
+ const currentParams = atRule.params;
409
+ const minValue = extractMinValue(currentParams);
410
+ const maxValue = extractMaxValue(currentParams);
411
+ if (minValue && !maxValue) {
412
+ const minContainer = minValue;
413
+ const maxContainer = containerValues[containerValues.length - 1];
414
+ clampDecls.forEach((decl) => {
415
+ processClampDeclaration(decl, minContainer, maxContainer, true);
416
+ });
417
+ } else if (maxValue && !minValue) {
418
+ const minContainer = containerValues[0];
419
+ const maxContainer = maxValue;
420
+ clampDecls.forEach((decl) => {
421
+ processClampDeclaration(decl, minContainer, maxContainer, true);
422
+ });
423
+ } else if (minValue && maxValue) {
424
+ clampDecls.forEach((decl) => {
425
+ processClampDeclaration(decl, minValue, maxValue, true);
426
+ });
427
+ }
428
+ }
429
+ };
317
430
  return {
318
431
  // Use OnceExit to ensure Tailwind has generated its content
319
432
  OnceExit(root, { result }) {
320
433
  collectConfig(root);
321
434
  finalizeConfig();
435
+ const processedAtRules = /* @__PURE__ */ new WeakSet();
322
436
  root.walkAtRules("media", (atRule) => {
323
- const clampDecls = [];
324
- atRule.walkDecls((decl) => {
325
- if (extractTwoValidClampArgs(decl.value)) {
326
- clampDecls.push(decl);
327
- }
328
- });
329
- if (!clampDecls.length) return;
330
- clampDecls.forEach((decl) => {
331
- const isNested = decl.parent?.type === "atrule" && decl.parent?.parent.type === "atrule";
332
- const isSameAtRule = decl.parent?.name === decl.parent?.parent.name;
333
- if (isNested && isSameAtRule) {
334
- const currentParams2 = decl.parent.params;
335
- const parentParams = decl.parent.parent.params;
336
- let minScreen = null;
337
- let maxScreen = null;
338
- if (parentParams.includes(">") || parentParams.includes("min-width")) {
339
- let match = parentParams.match(/>=?\s*([^),\s]+)/);
340
- if (match) {
341
- minScreen = match[1].trim();
342
- } else {
343
- match = parentParams.match(/min-width:\s*([^),\s]+)/);
344
- if (match) minScreen = match[1].trim();
345
- }
346
- }
347
- if (!minScreen && (currentParams2.includes(">") || currentParams2.includes("min-width"))) {
348
- let match = currentParams2.match(/>=?\s*([^),\s]+)/);
349
- if (match) {
350
- minScreen = match[1].trim();
351
- } else {
352
- match = currentParams2.match(/min-width:\s*([^),\s]+)/);
353
- if (match) minScreen = match[1].trim();
354
- }
355
- }
356
- if (parentParams.includes("<") || parentParams.includes("max-width")) {
357
- let match = parentParams.match(/<\s*([^),\s]+)/);
358
- if (match) {
359
- maxScreen = match[1].trim();
360
- } else {
361
- match = parentParams.match(/max-width:\s*([^),\s]+)/);
362
- if (match) maxScreen = match[1].trim();
363
- }
364
- }
365
- if (!maxScreen && (currentParams2.includes("<") || currentParams2.includes("max-width"))) {
366
- let match = currentParams2.match(/<\s*([^),\s]+)/);
367
- if (match) {
368
- maxScreen = match[1].trim();
369
- } else {
370
- match = currentParams2.match(/max-width:\s*([^),\s]+)/);
371
- if (match) maxScreen = match[1].trim();
372
- }
373
- }
374
- if (minScreen && maxScreen) {
375
- clampDecls.forEach((decl2) => {
376
- processClampDeclaration(decl2, minScreen, maxScreen, false);
377
- });
378
- }
379
- return;
380
- }
381
- if (isNested && !isSameAtRule) {
382
- clampDecls.forEach((decl2) => {
383
- decl2.value = ` ${decl2.value} /* Invalid nested @media rules */`;
384
- });
385
- return;
386
- }
387
- const screenValues = Object.values(screens);
388
- const currentParams = decl.parent.params;
389
- if (currentParams.includes(">") || currentParams.includes("min-width")) {
390
- let match = currentParams.match(/>=?\s*([^),\s]+)/);
391
- if (!match) {
392
- match = currentParams.match(/min-width:\s*([^),\s]+)/);
393
- }
394
- if (match) {
395
- const minScreen = match[1].trim();
396
- const maxScreen = defaultClampRange.max || screenValues[screenValues.length - 1];
397
- processClampDeclaration(decl, minScreen, maxScreen, false);
398
- }
399
- } else if (currentParams.includes("<") || currentParams.includes("max-width")) {
400
- let match = currentParams.match(/<\s*([^),\s]+)/);
401
- if (!match) {
402
- match = currentParams.match(/max-width:\s*([^),\s]+)/);
403
- }
404
- if (match) {
405
- const minScreen = defaultClampRange.min || screenValues[0];
406
- const maxScreen = match[1].trim();
407
- processClampDeclaration(decl, minScreen, maxScreen, false);
408
- }
409
- }
410
- });
437
+ if (processedAtRules.has(atRule)) return;
438
+ const { isNested, hasNestedMedia } = getNestedStructure(atRule);
439
+ if (hasNestedMedia) {
440
+ atRule.walkAtRules("media", (nestedAtRule) => {
441
+ processedAtRules.add(nestedAtRule);
442
+ processMediaQuery(nestedAtRule, atRule);
443
+ });
444
+ } else if (isNested) {
445
+ return;
446
+ } else {
447
+ processMediaQuery(atRule);
448
+ }
411
449
  });
412
450
  root.walkAtRules("container", (atRule) => {
413
- const clampDecls = [];
414
- atRule.walkDecls((decl) => {
415
- if (extractTwoValidClampArgs(decl.value)) {
416
- clampDecls.push(decl);
417
- }
418
- });
419
- if (!clampDecls.length) return;
420
- clampDecls.forEach((decl) => {
421
- const isNested = decl.parent?.type === "atrule" && decl.parent?.parent.type === "atrule";
422
- const isSameAtRule = decl.parent?.name === decl.parent?.parent.name;
423
- if (isNested && isSameAtRule) {
424
- const currentParams2 = decl.parent.params;
425
- const parentParams = decl.parent.parent.params;
426
- let minContainer = null;
427
- let maxContainer = null;
428
- if (parentParams.includes(">") || parentParams.includes("min-width")) {
429
- let match = parentParams.match(/>=?\s*([^),\s]+)/);
430
- if (!match) {
431
- match = parentParams.match(/min-width:\s*([^),\s]+)/);
432
- }
433
- if (match) minContainer = match[1].trim();
434
- }
435
- if (!minContainer && (currentParams2.includes(">") || currentParams2.includes("min-width"))) {
436
- let match = currentParams2.match(/>=?\s*([^),\s]+)/);
437
- if (!match) {
438
- match = currentParams2.match(/min-width:\s*([^),\s]+)/);
439
- }
440
- if (match) minContainer = match[1].trim();
441
- }
442
- if (parentParams.includes("<") || parentParams.includes("max-width")) {
443
- let match = parentParams.match(/<\s*([^),\s]+)/);
444
- if (!match) {
445
- match = parentParams.match(/max-width:\s*([^),\s]+)/);
446
- }
447
- if (match) maxContainer = match[1].trim();
448
- }
449
- if (!maxContainer && (currentParams2.includes("<") || currentParams2.includes("max-width"))) {
450
- let match = currentParams2.match(/<\s*([^),\s]+)/);
451
- if (!match) {
452
- match = currentParams2.match(/max-width:\s*([^),\s]+)/);
453
- }
454
- if (match) maxContainer = match[1].trim();
455
- }
456
- if (minContainer && maxContainer) {
457
- clampDecls.forEach((decl2) => {
458
- processClampDeclaration(
459
- decl2,
460
- minContainer,
461
- maxContainer,
462
- true
463
- );
464
- });
465
- }
466
- return;
467
- }
468
- if (isNested && !isSameAtRule) {
469
- clampDecls.forEach((decl2) => {
470
- decl2.value = ` ${decl2.value} /* Invalid nested @container rules */`;
471
- });
472
- return;
473
- }
474
- const containerValues = Object.values(containerScreens);
475
- const currentParams = decl.parent.params;
476
- if (currentParams.includes(">") || currentParams.includes("min-width")) {
477
- let match = currentParams.match(/>=?\s*([^),\s]+)/);
478
- if (!match) {
479
- match = currentParams.match(/min-width:\s*([^),\s]+)/);
480
- }
481
- if (match) {
482
- const minContainer = match[1].trim();
483
- const maxContainer = containerValues[containerValues.length - 1];
484
- processClampDeclaration(
485
- decl,
486
- minContainer,
487
- maxContainer,
488
- true
489
- );
490
- }
491
- } else if (currentParams.includes("<") || currentParams.includes("max-width")) {
492
- let match = currentParams.match(/<\s*([^),\s]+)/);
493
- if (!match) {
494
- match = currentParams.match(/max-width:\s*([^),\s]+)/);
495
- }
496
- if (match) {
497
- const minContainer = containerValues[0];
498
- const maxContainer = match[1].trim();
499
- processClampDeclaration(
500
- decl,
501
- minContainer,
502
- maxContainer,
503
- true
504
- );
505
- }
506
- }
507
- });
451
+ if (processedAtRules.has(atRule)) return;
452
+ const { isNested, hasNestedMedia } = getNestedStructure(atRule);
453
+ if (hasNestedMedia) {
454
+ atRule.walkAtRules("container", (nestedAtRule) => {
455
+ processedAtRules.add(nestedAtRule);
456
+ processContainerQuery(nestedAtRule, atRule);
457
+ });
458
+ } else if (isNested) {
459
+ return;
460
+ } else {
461
+ processContainerQuery(atRule);
462
+ }
508
463
  });
509
464
  root.walkRules((rule) => {
510
465
  let parent = rule.parent;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "postcss-clampwind",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "description": "A PostCSS plugin to create fluid clamp values for any Tailwind CSS utility",
5
5
  "license": "Apache-2.0",
6
6
  "keywords": [
@@ -36,6 +36,7 @@
36
36
  },
37
37
  "scripts": {
38
38
  "dev": "node scripts/build.js --watch",
39
- "build": "node scripts/build.js"
39
+ "build": "node scripts/build.js",
40
+ "publish": "npm publish"
40
41
  }
41
42
  }