@umber-style/rtl 0.10.0-alpha.0 → 0.10.1
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.
- package/dist/index.cjs +28 -3
- package/dist/index.d.cts +5 -2
- package/dist/index.d.mts +5 -2
- package/dist/index.mjs +28 -3
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -456,7 +456,9 @@ function createName(base, switches) {
|
|
|
456
456
|
/**
|
|
457
457
|
* A value of a property for each direction (`marginTop: dir({ ltr: 2, rtl: 4 })`): with the plugin
|
|
458
458
|
* `rtl()`, each side is written as it is given under its `:dir()`, and never flipped; a side that is left
|
|
459
|
-
* out writes nothing for that direction.
|
|
459
|
+
* out writes nothing for that direction. With no plugin that reads it, nothing is written, and in
|
|
460
|
+
* development the engine reports it with `console.error`. Typed as the values it is given, so it goes
|
|
461
|
+
* wherever they go.
|
|
460
462
|
*/
|
|
461
463
|
function dir(values) {
|
|
462
464
|
const given = {};
|
|
@@ -469,6 +471,26 @@ function dir(values) {
|
|
|
469
471
|
const LTR = ":dir(ltr)";
|
|
470
472
|
/** The condition of a declaration flipped, for right to left. */
|
|
471
473
|
const RTL = ":dir(rtl)";
|
|
474
|
+
/** A selector that already names a direction: `[dir="rtl"] .c`, `.c:dir(rtl)`. */
|
|
475
|
+
const NAMES_DIRECTION = /\[dir|:dir\(/;
|
|
476
|
+
/** Whether this is a production build: `process.env.NODE_ENV` is `production`. Where `process` does not exist it is taken as one. */
|
|
477
|
+
function isProduction() {
|
|
478
|
+
try {
|
|
479
|
+
return process.env.NODE_ENV === "production";
|
|
480
|
+
} catch {
|
|
481
|
+
return true;
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* In development, warns once for each selector that names a direction: with `rtl()` its rule is flipped
|
|
486
|
+
* too. The selector of the compile that only names a class (`&`) is not the rule's, so it is not warned
|
|
487
|
+
* about; nothing is warned about in production.
|
|
488
|
+
*/
|
|
489
|
+
function warnAboutDirection(selector, warned) {
|
|
490
|
+
if (isProduction() || selector.includes("&") || !NAMES_DIRECTION.test(selector) || warned.has(selector)) return;
|
|
491
|
+
warned.add(selector);
|
|
492
|
+
console.warn(`[rtl] The rule "${selector}" names a direction, and with rtl() it is flipped too, so its value is flipped twice. Use dir({ ltr, rtl }) for a value per direction instead.`);
|
|
493
|
+
}
|
|
472
494
|
/** The declaration of the property of the other side, with the same value. */
|
|
473
495
|
const renameEdge = (property, value) => [flipEdge(property), value];
|
|
474
496
|
/** A rule that flips the value of a declaration with `flip`, and keeps its property. */
|
|
@@ -538,17 +560,20 @@ function toSides(property, value) {
|
|
|
538
560
|
* other side under `:dir(rtl)` (`margin-left` is `margin-right`, never a logical property), and a value
|
|
539
561
|
* that names or measures a side is written for the other one; `@supports not selector(:dir(ltr))` gives
|
|
540
562
|
* the left-to-right declarations to a browser without `:dir()`. A `dir()` value is written as it is given,
|
|
541
|
-
* each side under its own condition.
|
|
563
|
+
* each side under its own condition. In development a rule whose selector names a direction (`[dir` or
|
|
564
|
+
* `:dir(`) is warned about once: it is flipped like any other. Logical properties, the values `start` and `end`, vertical values and
|
|
542
565
|
* unknown properties are left as they are. `options` turns kinds off (or `urls` on).
|
|
543
566
|
*/
|
|
544
567
|
function rtl(options = {}) {
|
|
568
|
+
const warned = /* @__PURE__ */ new Set();
|
|
545
569
|
const switches = readSwitches(options);
|
|
546
570
|
return {
|
|
547
571
|
name: createName("rtl", switches),
|
|
548
572
|
native: (style, { dir }) => transformNativeStyle(style, dir, switches),
|
|
549
573
|
conditions: [LTR, RTL],
|
|
550
574
|
fallback: `@supports not selector(${LTR})`,
|
|
551
|
-
declaration(property, value) {
|
|
575
|
+
declaration(property, value, selector) {
|
|
576
|
+
warnAboutDirection(selector, warned);
|
|
552
577
|
if (typeof value !== "string") return value.mark === "dir" ? toSides(property, value) : void 0;
|
|
553
578
|
const rule = RULES.get(property);
|
|
554
579
|
const isRuled = rule !== void 0 && switches[rule[0]];
|
package/dist/index.d.cts
CHANGED
|
@@ -42,7 +42,9 @@ interface DirValues<T> {
|
|
|
42
42
|
/**
|
|
43
43
|
* A value of a property for each direction (`marginTop: dir({ ltr: 2, rtl: 4 })`): with the plugin
|
|
44
44
|
* `rtl()`, each side is written as it is given under its `:dir()`, and never flipped; a side that is left
|
|
45
|
-
* out writes nothing for that direction.
|
|
45
|
+
* out writes nothing for that direction. With no plugin that reads it, nothing is written, and in
|
|
46
|
+
* development the engine reports it with `console.error`. Typed as the values it is given, so it goes
|
|
47
|
+
* wherever they go.
|
|
46
48
|
*/
|
|
47
49
|
export declare function dir<T extends string | number>(values: DirValues<T>): T;
|
|
48
50
|
/**
|
|
@@ -65,7 +67,8 @@ export interface RtlPlugin extends CachePlugin$1 {
|
|
|
65
67
|
* other side under `:dir(rtl)` (`margin-left` is `margin-right`, never a logical property), and a value
|
|
66
68
|
* that names or measures a side is written for the other one; `@supports not selector(:dir(ltr))` gives
|
|
67
69
|
* the left-to-right declarations to a browser without `:dir()`. A `dir()` value is written as it is given,
|
|
68
|
-
* each side under its own condition.
|
|
70
|
+
* each side under its own condition. In development a rule whose selector names a direction (`[dir` or
|
|
71
|
+
* `:dir(`) is warned about once: it is flipped like any other. Logical properties, the values `start` and `end`, vertical values and
|
|
69
72
|
* unknown properties are left as they are. `options` turns kinds off (or `urls` on).
|
|
70
73
|
*/
|
|
71
74
|
export declare function rtl(options?: RtlOptions): RtlPlugin;
|
package/dist/index.d.mts
CHANGED
|
@@ -42,7 +42,9 @@ interface DirValues<T> {
|
|
|
42
42
|
/**
|
|
43
43
|
* A value of a property for each direction (`marginTop: dir({ ltr: 2, rtl: 4 })`): with the plugin
|
|
44
44
|
* `rtl()`, each side is written as it is given under its `:dir()`, and never flipped; a side that is left
|
|
45
|
-
* out writes nothing for that direction.
|
|
45
|
+
* out writes nothing for that direction. With no plugin that reads it, nothing is written, and in
|
|
46
|
+
* development the engine reports it with `console.error`. Typed as the values it is given, so it goes
|
|
47
|
+
* wherever they go.
|
|
46
48
|
*/
|
|
47
49
|
export declare function dir<T extends string | number>(values: DirValues<T>): T;
|
|
48
50
|
/**
|
|
@@ -65,7 +67,8 @@ export interface RtlPlugin extends CachePlugin$1 {
|
|
|
65
67
|
* other side under `:dir(rtl)` (`margin-left` is `margin-right`, never a logical property), and a value
|
|
66
68
|
* that names or measures a side is written for the other one; `@supports not selector(:dir(ltr))` gives
|
|
67
69
|
* the left-to-right declarations to a browser without `:dir()`. A `dir()` value is written as it is given,
|
|
68
|
-
* each side under its own condition.
|
|
70
|
+
* each side under its own condition. In development a rule whose selector names a direction (`[dir` or
|
|
71
|
+
* `:dir(`) is warned about once: it is flipped like any other. Logical properties, the values `start` and `end`, vertical values and
|
|
69
72
|
* unknown properties are left as they are. `options` turns kinds off (or `urls` on).
|
|
70
73
|
*/
|
|
71
74
|
export declare function rtl(options?: RtlOptions): RtlPlugin;
|
package/dist/index.mjs
CHANGED
|
@@ -455,7 +455,9 @@ function createName(base, switches) {
|
|
|
455
455
|
/**
|
|
456
456
|
* A value of a property for each direction (`marginTop: dir({ ltr: 2, rtl: 4 })`): with the plugin
|
|
457
457
|
* `rtl()`, each side is written as it is given under its `:dir()`, and never flipped; a side that is left
|
|
458
|
-
* out writes nothing for that direction.
|
|
458
|
+
* out writes nothing for that direction. With no plugin that reads it, nothing is written, and in
|
|
459
|
+
* development the engine reports it with `console.error`. Typed as the values it is given, so it goes
|
|
460
|
+
* wherever they go.
|
|
459
461
|
*/
|
|
460
462
|
function dir(values) {
|
|
461
463
|
const given = {};
|
|
@@ -468,6 +470,26 @@ function dir(values) {
|
|
|
468
470
|
const LTR = ":dir(ltr)";
|
|
469
471
|
/** The condition of a declaration flipped, for right to left. */
|
|
470
472
|
const RTL = ":dir(rtl)";
|
|
473
|
+
/** A selector that already names a direction: `[dir="rtl"] .c`, `.c:dir(rtl)`. */
|
|
474
|
+
const NAMES_DIRECTION = /\[dir|:dir\(/;
|
|
475
|
+
/** Whether this is a production build: `process.env.NODE_ENV` is `production`. Where `process` does not exist it is taken as one. */
|
|
476
|
+
function isProduction() {
|
|
477
|
+
try {
|
|
478
|
+
return process.env.NODE_ENV === "production";
|
|
479
|
+
} catch {
|
|
480
|
+
return true;
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* In development, warns once for each selector that names a direction: with `rtl()` its rule is flipped
|
|
485
|
+
* too. The selector of the compile that only names a class (`&`) is not the rule's, so it is not warned
|
|
486
|
+
* about; nothing is warned about in production.
|
|
487
|
+
*/
|
|
488
|
+
function warnAboutDirection(selector, warned) {
|
|
489
|
+
if (isProduction() || selector.includes("&") || !NAMES_DIRECTION.test(selector) || warned.has(selector)) return;
|
|
490
|
+
warned.add(selector);
|
|
491
|
+
console.warn(`[rtl] The rule "${selector}" names a direction, and with rtl() it is flipped too, so its value is flipped twice. Use dir({ ltr, rtl }) for a value per direction instead.`);
|
|
492
|
+
}
|
|
471
493
|
/** The declaration of the property of the other side, with the same value. */
|
|
472
494
|
const renameEdge = (property, value) => [flipEdge(property), value];
|
|
473
495
|
/** A rule that flips the value of a declaration with `flip`, and keeps its property. */
|
|
@@ -537,17 +559,20 @@ function toSides(property, value) {
|
|
|
537
559
|
* other side under `:dir(rtl)` (`margin-left` is `margin-right`, never a logical property), and a value
|
|
538
560
|
* that names or measures a side is written for the other one; `@supports not selector(:dir(ltr))` gives
|
|
539
561
|
* the left-to-right declarations to a browser without `:dir()`. A `dir()` value is written as it is given,
|
|
540
|
-
* each side under its own condition.
|
|
562
|
+
* each side under its own condition. In development a rule whose selector names a direction (`[dir` or
|
|
563
|
+
* `:dir(`) is warned about once: it is flipped like any other. Logical properties, the values `start` and `end`, vertical values and
|
|
541
564
|
* unknown properties are left as they are. `options` turns kinds off (or `urls` on).
|
|
542
565
|
*/
|
|
543
566
|
function rtl(options = {}) {
|
|
567
|
+
const warned = /* @__PURE__ */ new Set();
|
|
544
568
|
const switches = readSwitches(options);
|
|
545
569
|
return {
|
|
546
570
|
name: createName("rtl", switches),
|
|
547
571
|
native: (style, { dir }) => transformNativeStyle(style, dir, switches),
|
|
548
572
|
conditions: [LTR, RTL],
|
|
549
573
|
fallback: `@supports not selector(${LTR})`,
|
|
550
|
-
declaration(property, value) {
|
|
574
|
+
declaration(property, value, selector) {
|
|
575
|
+
warnAboutDirection(selector, warned);
|
|
551
576
|
if (typeof value !== "string") return value.mark === "dir" ? toSides(property, value) : void 0;
|
|
552
577
|
const rule = RULES.get(property);
|
|
553
578
|
const isRuled = rule !== void 0 && switches[rule[0]];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umber-style/rtl",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.1",
|
|
4
4
|
"description": "The plugin of the UmberStyle default style that writes both directions of a style in one class: each declaration that has a side under :dir(ltr) as written and under :dir(rtl) flipped.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"styling",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"access": "public"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@umber-style/core": "0.10.
|
|
45
|
+
"@umber-style/core": "^0.10.1"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@types/node": "^26.6.6",
|