@plumeria/utils 21.1.4 → 21.1.6

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 (2) hide show
  1. package/dist/dynamicKey.js +49 -4
  2. package/package.json +1 -1
@@ -163,9 +163,53 @@ const writtenUnitAfter = (rest) => {
163
163
  return token;
164
164
  return unitSet.has(token.toLowerCase()) ? token : '';
165
165
  };
166
- const unitAt = (prop, rest) => {
166
+ const UNITLESS_FUNCTIONS = new Set([
167
+ 'rgb',
168
+ 'rgba',
169
+ 'hsl',
170
+ 'hsla',
171
+ 'hwb',
172
+ 'lab',
173
+ 'lch',
174
+ 'oklab',
175
+ 'oklch',
176
+ 'color',
177
+ 'scale',
178
+ 'scalex',
179
+ 'scaley',
180
+ 'scalez',
181
+ 'scale3d',
182
+ 'matrix',
183
+ 'matrix3d',
184
+ 'brightness',
185
+ 'contrast',
186
+ 'grayscale',
187
+ 'invert',
188
+ 'opacity',
189
+ 'saturate',
190
+ 'sepia',
191
+ ]);
192
+ const FUNCTION_NAME_BEFORE = /[a-z0-9-]*$/i;
193
+ const inUnitlessFunction = (before) => {
194
+ let depth = 0;
195
+ for (let i = before.length - 1; i >= 0; i--) {
196
+ if (before[i] === ')')
197
+ depth++;
198
+ else if (before[i] === '(') {
199
+ if (depth > 0)
200
+ depth--;
201
+ else {
202
+ const name = FUNCTION_NAME_BEFORE.exec(before.slice(0, i))[0];
203
+ if (UNITLESS_FUNCTIONS.has(name.toLowerCase()))
204
+ return true;
205
+ }
206
+ }
207
+ }
208
+ return false;
209
+ };
210
+ const unitAt = (prop, before, rest) => {
167
211
  const written = writtenUnitAfter(rest);
168
- if (written)
212
+ if (written || inUnitlessFunction(before))
169
213
  return { unit: written, written: true };
170
214
  return { unit: (0, exports.isUnitlessProp)(prop) ? '' : 'px', written: false };
171
215
  };
@@ -180,8 +224,9 @@ const rewriteVarOccurrences = (style, cssVar, assign) => {
180
224
  let at = rest.indexOf(reference);
181
225
  while (at !== -1) {
182
226
  const after = rest.slice(at + reference.length);
183
- const unit = unitAt(prop, after);
184
- rewritten += `${rest.slice(0, at)}var(${assign(prop, unit)})`;
227
+ rewritten += rest.slice(0, at);
228
+ const unit = unitAt(prop, rewritten, after);
229
+ rewritten += `var(${assign(prop, unit)})`;
185
230
  rest = unit.written ? after.slice(unit.unit.length) : after;
186
231
  at = rest.indexOf(reference);
187
232
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/utils",
3
- "version": "21.1.4",
3
+ "version": "21.1.6",
4
4
  "description": "Plumeria Utils",
5
5
  "author": "Refirst 11",
6
6
  "license": "MIT",