cleo_design_tokens 0.2.1 → 0.2.2
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.
- checksums.yaml +4 -4
- data/lib/cleo_design_tokens.rb +29 -6
- data/package.json +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7bf05dee064782565d442d3da54c6203328456debe4b7d183ec0e24d582b4a55
|
|
4
|
+
data.tar.gz: 58af1f5a62cb959dcbadafb2ebece37fa53558b5cd9d6cba683d5a40efa51b16
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6a72721e29aad60328fc4b8a61a90ed9107355f2a55d34ffa6adf27e58c6c89449b67ad50f626c0ab56f5ac1290a9bcfa9178643350d6533f7cad3000c4ab179
|
|
7
|
+
data.tar.gz: 15248d41bac918b3b03e4724182903de1d2d3f2ef4af133412335b563d6477d1ef6b6cd65eb84549a3ec1131d4ca2d407c886693dcc6a50314e2dba5777bcff6
|
data/lib/cleo_design_tokens.rb
CHANGED
|
@@ -21,7 +21,8 @@ module CleoDesignTokens
|
|
|
21
21
|
PRIMITIVES_PATH = File.join(TOKENS_DIR, "primitives.json")
|
|
22
22
|
SEMANTIC_PATH = File.join(TOKENS_DIR, "semantic.json")
|
|
23
23
|
SPACING_BASE_UNIT_PX = 4
|
|
24
|
-
|
|
24
|
+
RELATIVE_UNIT_BASE_PX = 16
|
|
25
|
+
private_constant :SPACING_BASE_UNIT_PX, :RELATIVE_UNIT_BASE_PX
|
|
25
26
|
|
|
26
27
|
# Built at load, into constants — not `@lookup ||=`, which would race under
|
|
27
28
|
# concurrent access. Frozen from the moment the gem loads, so every reader
|
|
@@ -45,10 +46,11 @@ module CleoDesignTokens
|
|
|
45
46
|
COLORS
|
|
46
47
|
end
|
|
47
48
|
|
|
48
|
-
# Spacing is code-owned, not generated from Figma.
|
|
49
|
-
#
|
|
50
|
-
def self.spacing(multiplier)
|
|
51
|
-
|
|
49
|
+
# Spacing is code-owned, not generated from Figma. Without a unit it is a
|
|
50
|
+
# numeric React Native-ready pixel value; CSS callers opt into a unit.
|
|
51
|
+
def self.spacing(multiplier, unit: nil)
|
|
52
|
+
normalized_unit = normalize_spacing_unit(unit)
|
|
53
|
+
return "auto".freeze if multiplier == "auto" || multiplier == :auto
|
|
52
54
|
|
|
53
55
|
pixels = multiplier * SPACING_BASE_UNIT_PX if multiplier.is_a?(Numeric)
|
|
54
56
|
unless multiplier.is_a?(Numeric) && !multiplier.is_a?(Complex) && multiplier.finite? && (pixels % 1).zero?
|
|
@@ -56,6 +58,27 @@ module CleoDesignTokens
|
|
|
56
58
|
"spacing multiplier must be \"auto\" or a finite multiple of 0.25; received #{multiplier.inspect}"
|
|
57
59
|
end
|
|
58
60
|
|
|
59
|
-
|
|
61
|
+
pixels = pixels.to_i
|
|
62
|
+
return pixels if normalized_unit.nil?
|
|
63
|
+
return "#{pixels}px".freeze if normalized_unit == :px
|
|
64
|
+
|
|
65
|
+
format_relative_spacing(pixels, normalized_unit).freeze
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def self.normalize_spacing_unit(unit)
|
|
69
|
+
return nil if unit.nil?
|
|
70
|
+
return unit if %i[px rem em].include?(unit)
|
|
71
|
+
return unit.to_sym if %w[px rem em].include?(unit)
|
|
72
|
+
|
|
73
|
+
raise ArgumentError, "spacing unit must be one of :px, :rem, :em; received #{unit.inspect}"
|
|
74
|
+
end
|
|
75
|
+
private_class_method :normalize_spacing_unit
|
|
76
|
+
|
|
77
|
+
def self.format_relative_spacing(pixels, unit)
|
|
78
|
+
sign = pixels.negative? ? "-" : ""
|
|
79
|
+
whole, sixteenths = pixels.abs.divmod(RELATIVE_UNIT_BASE_PX)
|
|
80
|
+
fraction = format("%04d", sixteenths * 625).sub(/0+\z/, "")
|
|
81
|
+
"#{sign}#{whole}#{fraction.empty? ? "" : ".#{fraction}"}#{unit}"
|
|
60
82
|
end
|
|
83
|
+
private_class_method :format_relative_spacing
|
|
61
84
|
end
|
data/package.json
CHANGED