windsock 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 17a5c3493485dca9b8a49c5f8e1b1515f6240e143d4fb338d7f52546ea5509af
4
+ data.tar.gz: 3b082d317bf4b09ca3385d574f390beaa46729defde92ab67501ca3922fa31c1
5
+ SHA512:
6
+ metadata.gz: b3a6452c7e01ca3a2b2b4edad7be005a9e49742f7545775a171a3b33880ceb803fa496ade998cd94d99b81ef36e3a41e1a3a56d675e0c5f4c9639a702b6d4f14
7
+ data.tar.gz: fcf098d9aa027d0dddd130cc0f07bf21a83c3e44965e71509436ce818389ee6f0d9ad6899e7a35834e3a944dc7913f7faf8c440981164c8bb8af9f1651cd3513
data/CHANGELOG.md ADDED
@@ -0,0 +1,22 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2026-10-14
4
+
5
+ Initial release.
6
+
7
+ - Parse Tailwind v4 `@theme` blocks with Tailwind's precedence rules; resolve `@import`
8
+ (including a bundled copy of Tailwind's default theme), `var()` and `--theme()`.
9
+ - Convert oklch/oklab/hsl/rgb/hex/named colors to hex, `rgb()` and `rgba()`, with CSS
10
+ Color 4 gamut mapping.
11
+ - `Theme` lookups: `#color`, `#colors`, `#scale`, `#scales`, `#scale_names`,
12
+ `#breakpoints`, `#fonts`, `#spacing` and the other namespaces; `#white`, `#black`
13
+ and `#text_color` use the theme's own `--color-white` / `--color-black`.
14
+ - `color(:brand)` returns the brand `Scale` when the theme has `brand-*` steps but no
15
+ bare `--color-brand`.
16
+ - `Windsock::Scale`: Hash-like steps that print as a WCAG contrast table in the console,
17
+ plus `contrast(on)`, `accessible(on:, level:)`, `text_colors` and `table(level:, color:)`.
18
+ - WCAG helpers on `Color`: `#contrast`, `#accessible?`, `#aa?`, `#aaa?`,
19
+ `#contrast_level` (`:aaa`, `:aa`, `:aa_large` or `:fail`), `#text_color`, `#dark?`, `#name`;
20
+ `Color::WHITE` / `Color::BLACK`.
21
+ - Rails: Railtie with dev reload, and `tailwind_color`, `tailwind_text_color`,
22
+ `tailwind_scale` and `tailwind_value` view helpers.
@@ -0,0 +1,85 @@
1
+
2
+ # Contributor Covenant Code of Conduct
3
+
4
+ ## Our Pledge
5
+
6
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, caste, color, religion, or sexual identity and orientation.
7
+
8
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
9
+
10
+ ## Our Standards
11
+
12
+ Examples of behavior that contributes to a positive environment for our community include:
13
+
14
+ * Demonstrating empathy and kindness toward other people
15
+ * Being respectful of differing opinions, viewpoints, and experiences
16
+ * Giving and gracefully accepting constructive feedback
17
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
18
+ * Focusing on what is best not just for us as individuals, but for the overall community
19
+
20
+ Examples of unacceptable behavior include:
21
+
22
+ * The use of sexualized language or imagery, and sexual attention or advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email address, without their explicit permission
26
+ * Other conduct which could reasonably be considered inappropriate in a professional setting
27
+
28
+ ## Enforcement Responsibilities
29
+
30
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
31
+
32
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
33
+
34
+ ## Scope
35
+
36
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
37
+
38
+ ## Enforcement
39
+
40
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at rave@beflagrant.com. All complaints will be reviewed and investigated promptly and fairly.
41
+
42
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
43
+
44
+ ## Enforcement Guidelines
45
+
46
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
47
+
48
+ ### 1. Correction
49
+
50
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
51
+
52
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
53
+
54
+ ### 2. Warning
55
+
56
+ **Community Impact**: A violation through a single incident or series of actions.
57
+
58
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
59
+
60
+ ### 3. Temporary Ban
61
+
62
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
63
+
64
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
65
+
66
+ ### 4. Permanent Ban
67
+
68
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
69
+
70
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
71
+
72
+ ## Attribution
73
+
74
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.1, available at [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
75
+
76
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
77
+
78
+ For answers to common questions about this code of conduct, see the FAQ at [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at [https://www.contributor-covenant.org/translations][translations].
79
+
80
+ [homepage]: https://www.contributor-covenant.org
81
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
82
+ [Mozilla CoC]: https://github.com/mozilla/diversity
83
+ [FAQ]: https://www.contributor-covenant.org/faq
84
+ [translations]: https://www.contributor-covenant.org/translations
85
+
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,30 @@
1
+ # Contributing
2
+
3
+ Bug reports and pull requests are welcome at https://github.com/beflagrant/windsock.
4
+ Everyone taking part is expected to follow the [Code of Conduct](CODE_OF_CONDUCT.md).
5
+
6
+ ## Reporting bugs
7
+
8
+ Include the Ruby and Windsock versions, the `@theme` CSS that misbehaves (trimmed
9
+ to the smallest case you can), what you expected and what you got.
10
+
11
+ ## Making changes
12
+
13
+ ```
14
+ bin/setup
15
+ bundle exec rake # tests + rubocop
16
+ bin/console
17
+ ```
18
+
19
+ - Add a test for the change. `bundle exec rake` must pass.
20
+ - Add a line under `## [Unreleased]` in `CHANGELOG.md` for anything users would notice.
21
+ - Keep pull requests to one change each.
22
+
23
+ ## Updating the bundled Tailwind theme
24
+
25
+ Copy `theme.css` from the `tailwindcss` npm package into `lib/windsock/tailwind/`,
26
+ update its `LICENSE` if it changed, and bump `Windsock::TAILWIND_VERSION`.
27
+
28
+ ## Security issues
29
+
30
+ See [SECURITY.md](SECURITY.md). Don't open a public issue.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 Flagrant, LLC
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,200 @@
1
+ # Windsock
2
+
3
+ Read your Tailwind v4 theme from Ruby.
4
+
5
+ Tailwind v4 keeps your design tokens in CSS: `@theme { --color-brand-500: oklch(...) }`. That's the right place for them, but sometimes Ruby needs the same values. Windsock parses the stylesheet so you don't keep a second copy.
6
+
7
+ ```ruby
8
+ Windsock.color(:brand, 500).to_hex # => "#2b7fff"
9
+ Windsock.scale(:brand) # => every brand-* step, with WCAG contrast
10
+ Windsock.scale_names # => ["red", "orange", ..., "brand"]
11
+ Windsock.theme.breakpoints["md"] # => "48rem"
12
+ Windsock.theme.fonts["sans"] # => "ui-sans-serif, system-ui, ..."
13
+ ```
14
+
15
+ Where it helps:
16
+
17
+ - **Mailers.** Email clients ignore CSS variables and don't understand `oklch()`. `tailwind_color(:brand, 500)` gives you a hex value to inline.
18
+ - **PDFs, OG images, charts.** Prawn, Grover, Chartkick and friends want plain colors.
19
+ - **Meta tags and manifests.** `theme-color`, PWA `manifest.json`.
20
+ - **Tests.** Assert your brand palette is what you think it is.
21
+
22
+ No Node, no Tailwind binary. It reads the CSS, resolves `@import` and `var()`, and converts colors.
23
+
24
+ ## Install
25
+
26
+ ```ruby
27
+ gem "windsock"
28
+ ```
29
+
30
+ ## Rails
31
+
32
+ Windsock reads `app/assets/tailwind/application.css` (the tailwindcss-rails default) and reloads when any `.css` in that directory changes in development.
33
+
34
+ ```ruby
35
+ # config/application.rb (only if your stylesheet lives elsewhere)
36
+ config.windsock.path = Rails.root.join("app/assets/stylesheets/main.css")
37
+ ```
38
+
39
+ Views and mailers get helpers:
40
+
41
+ ```erb
42
+ <a style="background: <%= tailwind_color(:brand, 500) %>; color: <%= tailwind_color(:white) %>">
43
+ <meta name="theme-color" content="<%= tailwind_color(:brand, 900) %>">
44
+ <%= tailwind_color(:brand, 500, format: :rgb) %> <%# rgb(43 127 255) %>
45
+ <%= tailwind_color(:brand, 500, format: :rgba) %> <%# rgba(43, 127, 255, 1) — safest for email %>
46
+ <%= tailwind_color(:brand, 500, format: :css) %> <%# the value as written %>
47
+ <%= tailwind_text_color(:brand, 500) %> <%# the theme's black or white, whichever reads better on brand-500 %>
48
+ <%= tailwind_value(:breakpoint, :md) %> <%# 48rem %>
49
+ ```
50
+
51
+ ## Without Rails
52
+
53
+ ```ruby
54
+ Windsock.path = "path/to/application.css"
55
+ Windsock.theme
56
+
57
+ # or
58
+ theme = Windsock.load("path/to/application.css")
59
+ theme = Windsock.parse(css_string, base_dir: "dir/for/relative/imports")
60
+ ```
61
+
62
+ ## Theme API
63
+
64
+ ```ruby
65
+ theme = Windsock.theme
66
+
67
+ theme[:color, :brand, 500] # "oklch(62.3% 0.214 259.815)" — var() references resolved
68
+ theme["color-brand-500"] # same thing
69
+ theme.raw(:color, :primary) # "var(--color-brand-500)" — as written
70
+ theme.fetch(:nope) # raises Windsock::NotFound
71
+ theme.key?(:color, :blue, 500)
72
+
73
+ theme.color(:brand, 500) # => Windsock::Color (or nil)
74
+ theme.color!(:brand, 500) # raises if missing
75
+ theme.color(:brand) # => the brand Scale when there is no --color-brand but there are brand-* steps
76
+ theme.white, theme.black # --color-white / --color-black, else pure #fff / #000
77
+ theme.text_color(:brand, 500) # theme.white or theme.black, whichever reads better on brand-500
78
+ theme.colors # { "brand-500" => Color, "red-50" => Color, ... }
79
+ theme.scale(:brand) # Windsock::Scale: 50 => Color, ..., 950 => Color
80
+ theme.scale_names # ["red", "orange", ..., "brand"] — what #scale accepts
81
+ theme.scales # { "brand" => Scale, "red" => Scale, ... }
82
+
83
+ theme.breakpoints # { "sm" => "40rem", "md" => "48rem", ... }
84
+ theme.fonts, theme.radii, theme.shadows, theme.text_sizes, theme.containers,
85
+ theme.tracking, theme.leading, theme.easings, theme.animations, theme.blurs
86
+ theme.namespace(:anything) # any --anything-* prefix
87
+
88
+ theme.spacing # "0.25rem"
89
+ theme.spacing(4) # "1rem"
90
+ theme.spacing(:gutter) # a named --spacing-gutter
91
+
92
+ theme.to_h # every variable, resolved
93
+ Windsock.default_theme # Tailwind's stock palette, untouched
94
+
95
+ # Shortcuts on the module go to Windsock.theme:
96
+ Windsock[...], Windsock.fetch, Windsock.color, Windsock.color!, Windsock.colors,
97
+ Windsock.scale, Windsock.scales, Windsock.scale_names
98
+ ```
99
+
100
+ ## Scale API
101
+
102
+ `scale(:brand)` returns a `Windsock::Scale`. It acts like a Hash of step => Color and prints as a table in the console, so you can see at a glance which steps work as text or background. In a terminal, ratios that meet AA (4.5:1) are green and the rest red; `scale.table(level: :aaa)` raises the bar, `scale.table(color: false)` turns the ANSI off.
103
+
104
+ ```
105
+ >> Windsock.scale(:brand)
106
+ #<Windsock::Scale brand (11 steps; contrast vs white #ffffff / black #000000; AA needs 4.5:1; text = what to write on it)
107
+ step hex white black text
108
+ 50 #eff6ff 1.09 19.27 black
109
+ 100 #dbeafe 1.22 17.22 black
110
+ ...
111
+ 500 #2b7fff 3.76 5.58 black
112
+ 600 #155dfc 5.26 4.00 white
113
+ ...
114
+ 950 #162456 14.72 1.43 white
115
+ >
116
+ ```
117
+
118
+ ```ruby
119
+ scale = Windsock.scale(:brand)
120
+
121
+ scale[500] # Color (also scale["500"], scale[:muted])
122
+ scale.fetch(500) # raises Windsock::NotFound if missing
123
+ scale.steps # [50, 100, ..., 950, "muted"]
124
+ scale.each { |step, color| ... } # Enumerable over [step, color]
125
+ scale.to_h # plain Hash
126
+
127
+ scale.contrast(:white) # { 50 => 1.09, ..., 950 => 14.72 } — WCAG ratios
128
+ scale.accessible(on: :white) # steps usable as text on white (AA, 4.5:1), as a Scale
129
+ scale.accessible(on: "#000", level: :aaa)
130
+ scale.text_colors # { 50 => black, ..., 950 => white } — text to put on each step
131
+ scale.white, scale.black # what "white" and "black" mean here
132
+ ```
133
+
134
+ "White" and "black" are the theme's `--color-white` / `--color-black`. Tailwind ships them as `#fff` / `#000`, but an app that softens white to `#f5f5f5` gets its contrast measured against `#f5f5f5`, and the table title says so. `on:` also takes any theme color name (`scale.contrast(:surface)`) before falling back to CSS parsing.
135
+
136
+ Levels are `:aa` (4.5:1), `:aa_large` (3:1, 18pt+ or 14pt bold), `:aaa` (7:1) and `:aaa_large` (4.5:1). Contrast ignores alpha: a translucent color is rated as if opaque.
137
+
138
+ `color(:brand)` also returns the scale when the theme has `--color-brand-*` steps but no bare `--color-brand`. An exact `--color-brand` always wins. The view helpers want one color, so `tailwind_color(:brand)` raises `ArgumentError` naming the steps instead.
139
+
140
+ ## Color API
141
+
142
+ ```ruby
143
+ c = Windsock.color(:brand, 500)
144
+ c.to_hex # "#2b7fff" ("#2b7fff80" when alpha < 1)
145
+ c.to_hex(alpha: false)
146
+ c.to_rgb # "rgb(43 127 255)"
147
+ c.to_rgba # "rgba(43, 127, 255, 1)"
148
+ c.rgb # [43, 127, 255]
149
+ c.alpha # 1.0
150
+ c.source # "oklch(62.3% 0.214 259.815)"
151
+ c.luminance # WCAG relative luminance
152
+ c.contrast("#fff") # WCAG contrast ratio (any CSS color, a Color, or :white / :black)
153
+ c.accessible?("#fff") # contrast >= 4.5 (AA for normal text)
154
+ c.accessible?(:white, level: :aaa) # :aa, :aa_large, :aaa, :aaa_large
155
+ c.aa?("#fff") / c.aaa?("#fff", large: true)
156
+ c.contrast_level("#fff") # :aaa, :aa, :aa_large or :fail
157
+ c.text_color # Windsock::Color::BLACK or ::WHITE, whichever reads better on c
158
+ c.text_color(white: theme.white, black: theme.black) # same, with the theme's own
159
+ c.dark? # same question as a boolean
160
+
161
+ Windsock::Color.parse("hsl(217 91% 60%)") # any CSS color
162
+ ```
163
+
164
+ Parses hex, named colors, `rgb()`, `hsl()`, `oklch()`, `oklab()`, `color(srgb ...)` and Tailwind's `--alpha(color / 50%)`.
165
+
166
+ Colors outside the sRGB gamut (several of Tailwind's v4 defaults are) are gamut-mapped the way CSS Color 4 and browsers do it, so the hex values match what the Tailwind docs and DevTools show.
167
+
168
+ ## What it understands
169
+
170
+ - `@theme`, `@theme inline`, `@theme static`, `@theme reference`, `@theme default`, with Tailwind's precedence rules
171
+ - `@import "tailwindcss"` and `@import "tailwindcss/theme.css"` → bundled copy of Tailwind's default theme (currently v4.3.3, see `Windsock::TAILWIND_VERSION`)
172
+ - Relative `@import "./partials/brand.css"` (missing files raise `Windsock::ImportError`)
173
+ - `--color-blue-*: initial` and `--*: initial` resets
174
+ - `var(--x)`, `var(--x, fallback)`, `--theme(--x, initial)`
175
+ - Comments, multi-line values, `@keyframes` inside `@theme`
176
+
177
+ ## What it doesn't
178
+
179
+ - **Tailwind v3** `tailwind.config.js`. The theme lives in JavaScript; you need Node for that.
180
+ - **Plugins** (`@plugin "daisyui"`) that register their own theme values.
181
+ - **Dark mode / variant overrides.** Values set in `.dark { --color-surface: ... }` aren't theme variables. You get the `@theme` value.
182
+ - **Bare imports** from `node_modules` are skipped silently.
183
+
184
+ ## Development
185
+
186
+ ```
187
+ bin/setup
188
+ bundle exec rake # tests + rubocop
189
+ bin/console
190
+ ```
191
+
192
+ To bump the bundled Tailwind theme: copy `theme.css` from the `tailwindcss` npm package into `lib/windsock/tailwind/` (and its `LICENSE` if it changed) and update `Windsock::TAILWIND_VERSION`.
193
+
194
+ ## Contributing
195
+
196
+ Bug reports and pull requests are welcome at https://github.com/beflagrant/windsock. See [CONTRIBUTING.md](CONTRIBUTING.md) and the [Code of Conduct](CODE_OF_CONDUCT.md).
197
+
198
+ ## License
199
+
200
+ MIT, see [LICENSE.txt](LICENSE.txt). The bundled `theme.css` is from [Tailwind CSS](https://github.com/tailwindlabs/tailwindcss), also MIT; its license is in [lib/windsock/tailwind/LICENSE](lib/windsock/tailwind/LICENSE).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "minitest/test_task"
5
+
6
+ Minitest::TestTask.create
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[test rubocop]
data/SECURITY.md ADDED
@@ -0,0 +1,14 @@
1
+ # Security Policy
2
+
3
+ ## Supported versions
4
+
5
+ Security fixes go into the latest release only.
6
+
7
+ ## Reporting a vulnerability
8
+
9
+ Please don't open a public issue. Report it privately through
10
+ [GitHub's security advisories](https://github.com/beflagrant/windsock/security/advisories/new)
11
+ or by email to rave@beflagrant.com.
12
+
13
+ We'll acknowledge the report within a few business days and keep you posted
14
+ until it's fixed and released.