postcss-clampwind 0.0.10 → 0.0.12

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.
@@ -158,6 +158,7 @@ var extractMaxValue = (params) => {
158
158
  if (!params) return null;
159
159
  let match = params.match(/<\s*([^),\s]+)/);
160
160
  if (match) return match[1].trim();
161
+ if (params.match(/not\s+all\s+and\s*\(\s*max-width:/)) return null;
161
162
  match = params.match(/max-width:\s*([^),\s]+)/);
162
163
  if (match) return match[1].trim();
163
164
  match = params.match(/not\s+all\s+and\s*\(\s*min-width:\s*([^),\s]+)\s*\)/);
@@ -168,6 +169,7 @@ var extractMinValue = (params) => {
168
169
  if (!params) return null;
169
170
  let match = params.match(/>=?\s*([^),\s]+)/);
170
171
  if (match) return match[1].trim();
172
+ if (params.match(/not\s+all\s+and\s*\(\s*min-width:/)) return null;
171
173
  match = params.match(/min-width:\s*([^),\s]+)/);
172
174
  if (match) return match[1].trim();
173
175
  match = params.match(/not\s+all\s+and\s*\(\s*max-width:\s*([^),\s]+)\s*\)/);
@@ -367,17 +369,26 @@ var clampwind = (opts = {}) => {
367
369
  decl.value = clamp;
368
370
  return true;
369
371
  };
370
- const getNestedStructure = (atRule) => {
371
- const isNested = atRule.parent?.type === "atrule" && atRule.parent?.name === "media";
372
+ const getNestedStructure = (atRule, ruleName = "media") => {
373
+ const isNested = atRule.parent?.type === "atrule" && atRule.parent?.name === ruleName;
372
374
  const hasNestedMedia = atRule.nodes?.some(
373
- (node) => node.type === "atrule" && node.name === "media"
375
+ (node) => node.type === "atrule" && node.name === ruleName
374
376
  );
375
377
  return { isNested, hasNestedMedia };
376
378
  };
377
- const processMediaQuery = (atRule, parentAtRule = null) => {
379
+ const isDeclInsideNestedAtRule = (decl, boundaryAtRule, ruleName) => {
380
+ let parent = decl.parent;
381
+ while (parent && parent !== boundaryAtRule) {
382
+ if (parent.type === "atrule" && parent.name === ruleName) return true;
383
+ parent = parent.parent;
384
+ }
385
+ return false;
386
+ };
387
+ const processMediaQuery = (atRule, parentAtRule = null, skipNestedAtRuleName = null) => {
378
388
  const clampDecls = [];
379
389
  atRule.walkDecls((decl) => {
380
390
  if (extractTwoValidClampArgs(decl.value)) {
391
+ if (skipNestedAtRuleName && isDeclInsideNestedAtRule(decl, atRule, skipNestedAtRuleName)) return;
381
392
  clampDecls.push(decl);
382
393
  }
383
394
  });
@@ -416,10 +427,11 @@ var clampwind = (opts = {}) => {
416
427
  }
417
428
  }
418
429
  };
419
- const processContainerQuery = (atRule, parentAtRule = null) => {
430
+ const processContainerQuery = (atRule, parentAtRule = null, skipNestedAtRuleName = null) => {
420
431
  const clampDecls = [];
421
432
  atRule.walkDecls((decl) => {
422
433
  if (extractTwoValidClampArgs(decl.value)) {
434
+ if (skipNestedAtRuleName && isDeclInsideNestedAtRule(decl, atRule, skipNestedAtRuleName)) return;
423
435
  clampDecls.push(decl);
424
436
  }
425
437
  });
@@ -468,6 +480,7 @@ var clampwind = (opts = {}) => {
468
480
  if (processedAtRules.has(atRule)) return;
469
481
  const { isNested, hasNestedMedia } = getNestedStructure(atRule);
470
482
  if (hasNestedMedia) {
483
+ processMediaQuery(atRule, null, "media");
471
484
  atRule.walkAtRules("media", (nestedAtRule) => {
472
485
  processedAtRules.add(nestedAtRule);
473
486
  processMediaQuery(nestedAtRule, atRule);
@@ -480,8 +493,9 @@ var clampwind = (opts = {}) => {
480
493
  });
481
494
  root.walkAtRules("container", (atRule) => {
482
495
  if (processedAtRules.has(atRule)) return;
483
- const { isNested, hasNestedMedia } = getNestedStructure(atRule);
496
+ const { isNested, hasNestedMedia } = getNestedStructure(atRule, "container");
484
497
  if (hasNestedMedia) {
498
+ processContainerQuery(atRule, null, "container");
485
499
  atRule.walkAtRules("container", (nestedAtRule) => {
486
500
  processedAtRules.add(nestedAtRule);
487
501
  processContainerQuery(nestedAtRule, atRule);
@@ -133,6 +133,7 @@ var extractMaxValue = (params) => {
133
133
  if (!params) return null;
134
134
  let match = params.match(/<\s*([^),\s]+)/);
135
135
  if (match) return match[1].trim();
136
+ if (params.match(/not\s+all\s+and\s*\(\s*max-width:/)) return null;
136
137
  match = params.match(/max-width:\s*([^),\s]+)/);
137
138
  if (match) return match[1].trim();
138
139
  match = params.match(/not\s+all\s+and\s*\(\s*min-width:\s*([^),\s]+)\s*\)/);
@@ -143,6 +144,7 @@ var extractMinValue = (params) => {
143
144
  if (!params) return null;
144
145
  let match = params.match(/>=?\s*([^),\s]+)/);
145
146
  if (match) return match[1].trim();
147
+ if (params.match(/not\s+all\s+and\s*\(\s*min-width:/)) return null;
146
148
  match = params.match(/min-width:\s*([^),\s]+)/);
147
149
  if (match) return match[1].trim();
148
150
  match = params.match(/not\s+all\s+and\s*\(\s*max-width:\s*([^),\s]+)\s*\)/);
@@ -342,17 +344,26 @@ var clampwind = (opts = {}) => {
342
344
  decl.value = clamp;
343
345
  return true;
344
346
  };
345
- const getNestedStructure = (atRule) => {
346
- const isNested = atRule.parent?.type === "atrule" && atRule.parent?.name === "media";
347
+ const getNestedStructure = (atRule, ruleName = "media") => {
348
+ const isNested = atRule.parent?.type === "atrule" && atRule.parent?.name === ruleName;
347
349
  const hasNestedMedia = atRule.nodes?.some(
348
- (node) => node.type === "atrule" && node.name === "media"
350
+ (node) => node.type === "atrule" && node.name === ruleName
349
351
  );
350
352
  return { isNested, hasNestedMedia };
351
353
  };
352
- const processMediaQuery = (atRule, parentAtRule = null) => {
354
+ const isDeclInsideNestedAtRule = (decl, boundaryAtRule, ruleName) => {
355
+ let parent = decl.parent;
356
+ while (parent && parent !== boundaryAtRule) {
357
+ if (parent.type === "atrule" && parent.name === ruleName) return true;
358
+ parent = parent.parent;
359
+ }
360
+ return false;
361
+ };
362
+ const processMediaQuery = (atRule, parentAtRule = null, skipNestedAtRuleName = null) => {
353
363
  const clampDecls = [];
354
364
  atRule.walkDecls((decl) => {
355
365
  if (extractTwoValidClampArgs(decl.value)) {
366
+ if (skipNestedAtRuleName && isDeclInsideNestedAtRule(decl, atRule, skipNestedAtRuleName)) return;
356
367
  clampDecls.push(decl);
357
368
  }
358
369
  });
@@ -391,10 +402,11 @@ var clampwind = (opts = {}) => {
391
402
  }
392
403
  }
393
404
  };
394
- const processContainerQuery = (atRule, parentAtRule = null) => {
405
+ const processContainerQuery = (atRule, parentAtRule = null, skipNestedAtRuleName = null) => {
395
406
  const clampDecls = [];
396
407
  atRule.walkDecls((decl) => {
397
408
  if (extractTwoValidClampArgs(decl.value)) {
409
+ if (skipNestedAtRuleName && isDeclInsideNestedAtRule(decl, atRule, skipNestedAtRuleName)) return;
398
410
  clampDecls.push(decl);
399
411
  }
400
412
  });
@@ -443,6 +455,7 @@ var clampwind = (opts = {}) => {
443
455
  if (processedAtRules.has(atRule)) return;
444
456
  const { isNested, hasNestedMedia } = getNestedStructure(atRule);
445
457
  if (hasNestedMedia) {
458
+ processMediaQuery(atRule, null, "media");
446
459
  atRule.walkAtRules("media", (nestedAtRule) => {
447
460
  processedAtRules.add(nestedAtRule);
448
461
  processMediaQuery(nestedAtRule, atRule);
@@ -455,8 +468,9 @@ var clampwind = (opts = {}) => {
455
468
  });
456
469
  root.walkAtRules("container", (atRule) => {
457
470
  if (processedAtRules.has(atRule)) return;
458
- const { isNested, hasNestedMedia } = getNestedStructure(atRule);
471
+ const { isNested, hasNestedMedia } = getNestedStructure(atRule, "container");
459
472
  if (hasNestedMedia) {
473
+ processContainerQuery(atRule, null, "container");
460
474
  atRule.walkAtRules("container", (nestedAtRule) => {
461
475
  processedAtRules.add(nestedAtRule);
462
476
  processContainerQuery(nestedAtRule, atRule);
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "postcss-clampwind",
3
- "version": "0.0.10",
3
+ "version": "0.0.12",
4
4
  "description": "A PostCSS plugin to create fluid clamp values for any Tailwind CSS utility",
5
5
  "license": "Apache-2.0",
6
- "keywords": [
6
+ "keywords": [
7
7
  "clampwind",
8
8
  "postcss-plugin",
9
9
  "tailwindcss",
@@ -38,4 +38,4 @@
38
38
  "dev": "node scripts/build.js --watch",
39
39
  "build": "node scripts/build.js"
40
40
  }
41
- }
41
+ }