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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 215d1cc5e872b8400676638c4a0930d8f20d6e334caf0e7c117677c735cea53a
4
- data.tar.gz: d506d01b5a4d3be6145fad24cbc3b5f1d89aa289f948394d1939d86cd3963de9
3
+ metadata.gz: 7bf05dee064782565d442d3da54c6203328456debe4b7d183ec0e24d582b4a55
4
+ data.tar.gz: 58af1f5a62cb959dcbadafb2ebece37fa53558b5cd9d6cba683d5a40efa51b16
5
5
  SHA512:
6
- metadata.gz: 9f781c2741cc7892415faab886987a2993d568dcfabf2f60c84e90eecede885351876cd09b3cd32aa8ae5d4599a5536a430a0b6d3a91b711f6f9fe341f02c09d
7
- data.tar.gz: 8685f9666f1a2443e490ef3210d0882bd56643f079ee4e385e431f5a1e0786716a72375b63ce2022fd9d8e825362a6de5db87ca9b4c4649d352e561399d5dd07
6
+ metadata.gz: 6a72721e29aad60328fc4b8a61a90ed9107355f2a55d34ffa6adf27e58c6c89449b67ad50f626c0ab56f5ac1290a9bcfa9178643350d6533f7cad3000c4ab179
7
+ data.tar.gz: 15248d41bac918b3b03e4724182903de1d2d3f2ef4af133412335b563d6477d1ef6b6cd65eb84549a3ec1131d4ca2d407c886693dcc6a50314e2dba5777bcff6
@@ -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
- private_constant :SPACING_BASE_UNIT_PX
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. It is the package's
49
- # sole public spacing API, matching the TypeScript reader.
50
- def self.spacing(multiplier)
51
- return "auto".freeze if multiplier == "auto"
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
- "#{pixels.to_i}px".freeze
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meetcleo/design-tokens",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "Canonical source of truth for Cleo's design tokens (DTCG JSON), plus a TypeScript reader.",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cleo_design_tokens
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cleo