diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 0000000..f950a5f --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,23 @@ +# makeabox: notes for agents + +## Worktrees and locks + +- Create your own worktree without asking: `git worktree add -b .claude/worktrees/ origin/main`, then enter it by path and seed it with `~/.agents/bin/setup-worktree`. `.claude/` is git-ignored. +- Name the branch with `~/.agents/bin/create-branch-name `. +- Before writing, claim each file with `alock acquire "" -u "$REDIS_URL"`, one path per call (`acquire` takes a single scope). Release them with `alock release-all -u "$REDIS_URL"` when the PR is open. +- Keep unrelated work in separate PRs: a fix to an existing feature merges on its own, before the next feature. + +## Checks + +There is no justfile. CI (`.github/workflows/rubyonrails.yml`) runs: + +```bash +bundle exec rspec +bundle exec rubocop +bundle exec puma -p 3055 -e development -w 0 -t 1:4 config.ru & # then: +npx cypress run +``` + +- Ruby comes from rbenv: prefix commands with `eval "$(rbenv init -)" &&`. +- Port 3055 is usually the human's server from the main checkout. Run a worktree's app on another port and point Cypress at it with `CYPRESS_BASE_URL=http://127.0.0.1:3056`. +- Cypress freezes CSS animations when it takes a screenshot, so an animated SVG stroke shows in its undrawn state there. Check animations in a real browser. diff --git a/app/assets/stylesheets/announce.css b/app/assets/stylesheets/announce.css new file mode 100644 index 0000000..fac6002 --- /dev/null +++ b/app/assets/stylesheets/announce.css @@ -0,0 +1,149 @@ +/* The release banner: a strip of birch plywood that floats out from under the + header. Its left end is cut on a slope, like the front of the box it announces. + The outer element moves and casts the shadow; the plank inside is clipped to + the sloped shape. (A clip-path would cut away a shadow on the same element.) */ +.announce { + --slope: 26px; + --edge: #6b4524; /* the plank's end grain, between the birch and the burnt --char */ + --deep: #9c2d0b; /* the beam, darkened: 4.48:1 on birch, 3.12:1 at the plank's darkest edge (fine for 24px text), 6.43:1 under ink */ + position: fixed; z-index: 2; /* under the header, which it slides out of, and under the panels */ + top: calc(var(--header) + 12px); left: 0; right: 0; + width: fit-content; max-width: min(860px, calc(100vw - 2 * var(--gutter))); margin-inline: auto; + filter: drop-shadow(0 10px 18px rgb(0 0 0 / 0.45)); + opacity: 0; + transform: translateY(-28px); + transition: opacity 0.5s ease-out, transform 0.7s cubic-bezier(0.2, 1.4, 0.4, 1); +} +.announce[hidden] { display: none; } +.announce.in { opacity: 1; transform: none; transition-delay: 0.6s; } +.announce.out { opacity: 0; transform: translateY(-28px); transition-duration: 0.3s; transition-delay: 0s; } + +/* Once it has landed it rocks gently like a seesaw about its middle, as if it hung + in the air: as the right end rises the left end sinks, and back. ±0.45º moves each + end of the wide banner about 6.4px. */ +.announce.in { animation: bob 4.2s ease-in-out 1.4s infinite; } +@keyframes bob { + 0%, 100% { rotate: 0.45deg; } + 50% { rotate: -0.45deg; } +} + +.announce .plank { + position: relative; + /* Wide: one row of sketch, release, line, buttons and close, with the small + print under the line, its checkbox lined up with the line's first word. */ + display: grid; align-items: center; gap: 6px 14px; + grid-template-columns: auto auto minmax(0, 1fr) auto auto; + grid-template-areas: "sketch release line actions close" ". . never . ."; + padding: 10px 12px 8px calc(var(--slope) + 10px); + /* Its thickness shows along the right and bottom, so it reads as a board, not a sticker. */ + border-right: 6px solid var(--edge); border-bottom: 6px solid var(--edge); + color: var(--char); + background: + repeating-linear-gradient(97deg, rgb(255 255 255 / 0.07) 0 2px, transparent 2px 9px), + linear-gradient(180deg, var(--birch-light), var(--birch) 60%, var(--birch-dark)); + /* The left end is cut on the slope; the top-right corner is mitred at 45º, so the + right edge reads as the board's thickness seen from an angle. */ + clip-path: polygon(var(--slope) 0, calc(100% - 6px) 0, 100% 6px, 100% 100%, 0 100%); +} + +/* The burnt edge along the slope, where the laser cut it, down through the bottom edge. */ +.announce .plank::before { + content: ""; position: absolute; inset: 0 0 -6px 0; + clip-path: polygon(var(--slope) 0, calc(var(--slope) + 3px) 0, 3px 100%, 0 100%); + background: var(--char); opacity: 0.85; +} + +/* The little side view is drawn by the beam, then the sloped front glows. */ +.announce .sketch { grid-area: sketch; overflow: visible; } +.announce .trace { + fill: none; stroke: var(--char); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; + stroke-dasharray: 100; stroke-dashoffset: 100; +} +.announce.in .trace { animation: trace 1.1s ease-in-out 1s forwards; } +.announce.in .slope { stroke: var(--beam); animation: trace 0.5s ease-out 2.1s forwards, glow 2.4s ease-in-out 2.6s infinite; } +@keyframes trace { to { stroke-dashoffset: 0; } } +@keyframes glow { + 0%, 100% { filter: drop-shadow(0 0 1px var(--beam)); } + 50% { filter: drop-shadow(0 0 4px var(--amber)); } +} + +/* Wide, the release and the line are cells of the plank's grid; narrower, they stack in one. */ +.announce .words { display: contents; } +.announce .release { + grid-area: release; font: 600 24px/1 "Barlow Condensed", "Archivo", sans-serif; letter-spacing: 0.02em; + color: var(--deep); text-shadow: 0 1px 0 rgb(255 255 255 / 0.35); +} +.announce .release .v { font-size: 0.7em; margin-right: 1px; } +.announce .line { grid-area: line; font-size: 15px; line-height: 1.3; text-wrap: balance; } /* no lone last word once it wraps */ +.announce .line b { font-weight: 750; } + +.announce button { flex: none; cursor: pointer; border: 0; } +.announce .actions { grid-area: actions; display: flex; gap: 8px; } +.announce .try, .announce .comment { + padding: 7px 14px; border-radius: 3px; + font: 600 16px/1 "Barlow Condensed", "Archivo", sans-serif; letter-spacing: 0.04em; text-transform: uppercase; + text-decoration: none; cursor: pointer; +} +.announce .try { color: var(--ink); background: var(--char); } +.announce .try:hover { background: var(--deep); } +/* The second call to action: the same shape, drawn in outline. */ +.announce .comment { padding: 5px 12px; color: var(--char); border: 2px solid var(--char); } +.announce .comment:hover { color: var(--deep); border-color: var(--deep); } + +/* Small print along the bottom edge. */ +.announce .never { + grid-area: never; justify-self: start; + display: flex; align-items: center; gap: 6px; + font-size: 12px; line-height: 1; color: var(--char); opacity: 0.8; cursor: pointer; +} +.announce .never:hover { opacity: 1; } +.announce .never input { width: 13px; height: 13px; margin: 0; accent-color: var(--deep); cursor: pointer; } +.announce .close { + grid-area: close; width: 28px; height: 28px; padding: 0; border-radius: 50%; + font-size: 22px; line-height: 1; color: var(--char); background: transparent; +} +.announce .close:hover { background: rgb(61 38 20 / 0.12); } +.announce :focus-visible { outline-color: var(--char); } + +/* Where it would cover the heading, it stops floating and takes its place in the + page instead: above the h1, lined up with it. */ +@media (max-width: 1180px) { + .announce { + position: relative; z-index: 1; top: auto; left: auto; right: auto; + margin: 14px var(--gutter) 0; max-width: calc(100% - 2 * var(--gutter)); + } +} + +/* Narrower, the line wraps in a column about half the banner wide, the buttons + stay on its right, and the small print moves to the centre. */ +@media (max-width: 900px) { + .announce { width: auto; } + .announce .plank { + grid-template-columns: auto minmax(0, 1fr) auto auto; + grid-template-areas: "sketch words actions close" "never never never never"; + } + .announce .words { grid-area: words; display: flex; flex-direction: column; gap: 2px; } + .announce .never { justify-self: center; } +} + +@media (max-width: 640px) { + .announce { --slope: 18px; } + .announce.in { animation: none; } /* no rocking on a phone: it sits in the page, still */ + .announce .plank { gap: 6px 10px; grid-template-columns: minmax(0, 1fr) auto auto; grid-template-areas: "words actions close" "never never never"; } + .announce .sketch { display: none; } + .announce .line { font-size: 14px; } +} + +/* A phone has no room for half: the buttons go under the line, close keeps the corner. */ +@media (max-width: 480px) { + .announce .plank { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "words close" "actions actions" "never never"; } + .announce .close { align-self: start; } +} + +/* base.css already turns every animation and transition off; this puts the + banner and its drawing in their finished state. */ +@media (prefers-reduced-motion: reduce) { + .announce, .announce.in, .announce.out { transform: none; } + .announce .trace { stroke-dashoffset: 0; animation: none !important; } + .announce .slope { stroke: var(--beam); } +} diff --git a/app/javascript/controllers/announce_controller.js b/app/javascript/controllers/announce_controller.js new file mode 100644 index 0000000..63d00c4 --- /dev/null +++ b/app/javascript/controllers/announce_controller.js @@ -0,0 +1,56 @@ +import { Controller } from "@hotwired/stimulus" + +// The release banner under the header. It drifts in on every page load until +// the visitor ticks "Do not show again"; that choice is kept in localStorage +// under a key that names the release, so the next release announces itself +// afresh. Closing it, trying the feature or opening the discussion hides it +// for this page only. +export default class extends Controller { + static values = { key: String } + static targets = ["never"] + static outlets = ["generator"] + + connect() { + if (this.never) return + this.element.hidden = false + // Two frames later, so the slide-in transition has a starting point. + requestAnimationFrame(() => requestAnimationFrame(() => this.element.classList.add("in"))) + } + + // Switches the generator to a sloped front, the way choosing it by hand + // would. Through the outlet, a renamed generator throws here instead of the + // button quietly doing nothing. + try() { + const generator = this.generatorOutlet + generator.shapeTarget.value = "sloped" + generator.reshape() + generator.shapeTarget.focus({ preventScroll: true }) + generator.shapeTarget.scrollIntoView({ behavior: "smooth", block: "center" }) + this.dismiss() + } + + // Saves the checkbox the moment it changes, so the choice holds even if the + // visitor never closes the banner. + remember() { + this.never = this.neverTarget.checked + } + + dismiss() { + this.element.classList.remove("in") + this.element.classList.add("out") + const hide = () => { this.element.hidden = true } + this.element.addEventListener("transitionend", hide, { once: true }) + setTimeout(hide, 600) // reduced motion turns every transition off (base.css), so transitionend never comes + } + + get never() { + try { return localStorage.getItem(this.keyValue) === "1" } catch { return false } + } + + set never(value) { + try { + if (value) localStorage.setItem(this.keyValue, "1") + else localStorage.removeItem(this.keyValue) + } catch { /* private mode: it shows again next time */ } + } +} diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index dd0046d..9a284f3 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -17,5 +17,6 @@ %a{href: '#discussion', data: {action: 'panels#open menu#close', panels_name_param: 'discussion'}} Discussion %a{href: 'https://github.com/kigster/laser-cutter', target: "_blank", data: {action: 'menu#close'}} GitHub %a{href: '#support', data: {action: 'panels#open menu#close', panels_name_param: 'support'}} Donate + = render 'shared/announcement' = yield = render 'shared/footer' diff --git a/app/views/shared/_announcement.html.haml b/app/views/shared/_announcement.html.haml new file mode 100644 index 0000000..83209a5 --- /dev/null +++ b/app/views/shared/_announcement.html.haml @@ -0,0 +1,29 @@ +-# Floats out from under the header to announce what a release brought. Hidden +-# until announce_controller.js shows it, so it never flashes for someone who +-# ticked "Do not show again". Closing it otherwise hides it for this page only. +-# The release is the one this copy describes, not Makeabox::VERSION: bumping the +-# version must not bring back last release's news under a new number. +- release = '5.0' +%aside.announce{hidden: true, 'aria-label': "New in version #{release}", + data: {controller: 'announce', announce_key_value: "makeabox:announce:#{release}", + announce_generator_outlet: '.bench'}} + .plank + %svg.sketch{viewBox: '0 0 48 40', width: 48, height: 40, 'aria-hidden': 'true'} + -# A box seen from the side: upright back, front rising part-way, then leaning back to the top. + %path.trace{d: 'M22 6 H42 V36 H6 V22', pathLength: 100} + %path.trace.slope{d: 'M6 22 L22 6', pathLength: 100} + .words + %strong.release + %span.v v + = release + %span.line + %b Sloped sides. + The front of a box can now lean back at any angle. + .actions + %button.try{type: 'button', data: {action: 'announce#try'}} Try it + -# panels_controller.js on opens the Discussion panel, as the menu link does. + %a.comment{href: '#discussion', data: {action: 'panels#open announce#dismiss', panels_name_param: 'discussion'}} Comment + %button.close{type: 'button', 'aria-label': 'Dismiss', data: {action: 'announce#dismiss'}} × + %label.never + %input{type: 'checkbox', data: {announce_target: 'never', action: 'announce#remember'}} + Do not show again diff --git a/app/views/shared/_head.html.haml b/app/views/shared/_head.html.haml index 20b41e7..457f215 100644 --- a/app/views/shared/_head.html.haml +++ b/app/views/shared/_head.html.haml @@ -36,6 +36,6 @@ = preload_link_tag 'archivo-variable-latin.woff2', as: 'font', type: 'font/woff2', crossorigin: 'anonymous' = preload_link_tag 'barlow-condensed-600-latin.woff2', as: 'font', type: 'font/woff2', crossorigin: 'anonymous' - = stylesheet_link_tag 'tokens', 'base', 'generator', 'dialogs', 'sections' + = stylesheet_link_tag 'tokens', 'base', 'generator', 'dialogs', 'sections', 'announce' = javascript_importmap_tags = csrf_meta_tags \ No newline at end of file diff --git a/cypress/e2e/announce.cy.js b/cypress/e2e/announce.cy.js new file mode 100644 index 0000000..bcf2b96 --- /dev/null +++ b/cypress/e2e/announce.cy.js @@ -0,0 +1,114 @@ +const KEY = "makeabox:announce:5.0" +const banner = () => cy.get("aside.announce") + +describe("the release banner", () => { + beforeEach(() => { + cy.clearLocalStorage() + cy.visit("/") + }) + + it("floats in under the header and draws the sloped box", () => { + banner().should("be.visible").and("have.class", "in") + banner().should("have.css", "animation-name", "bob") + banner().find(".slope").should("have.css", "stroke-dashoffset", "0px") + cy.screenshot("announce", { capture: "viewport" }) + }) + + it("floats centred under the header on a wide screen", () => { + banner().should("have.class", "in").should("have.css", "position", "fixed").then(($banner) => { + const box = $banner[0].getBoundingClientRect() + const middle = $banner[0].ownerDocument.documentElement.clientWidth / 2 // the viewport less its scrollbar + expect(box.width).to.be.greaterThan(560) + expect(Math.abs(box.left + box.width / 2 - middle)).to.be.lessThan(2) + }) + }) + + for (const [width, height] of [[1000, 800], [390, 844]]) { + it(`sits above the heading, lined up with it, at ${width}px`, () => { + cy.viewport(width, height) + // Where the layout puts it: the slide-in and the bob only move it visually, so measure with them off. + banner().should("have.class", "in").should("have.css", "position", "relative") + cy.get(".hero h1").then(($h1) => { + const heading = $h1[0].getBoundingClientRect() + const el = Cypress.$("aside.announce")[0] + el.style.transition = el.style.animation = "none" + el.style.transform = el.style.translate = el.style.rotate = "none" + const box = el.getBoundingClientRect() + expect(box.bottom).to.be.at.most(heading.top) + expect(Math.abs(box.left - heading.left)).to.be.lessThan(2) + }) + }) + } + + // Where the layout puts something: the slide-in and the bob only move it visually. + const settled = () => banner().should("have.class", "in").then(($banner) => { + const el = $banner[0] + el.style.transition = el.style.animation = "none" + el.style.transform = el.style.translate = el.style.rotate = "none" + }) + const rect = (selector) => Cypress.$(`aside.announce ${selector}`)[0].getBoundingClientRect() + + it("keeps the text and both buttons on one row when wide, with the checkbox under the text", () => { + settled().then(() => { + const line = rect(".line") + const middle = (r) => r.top + r.height / 2 + expect(Math.abs(middle(rect(".try")) - middle(line))).to.be.lessThan(4) + expect(Math.abs(middle(rect(".comment")) - middle(line))).to.be.lessThan(4) + expect(Math.abs(rect(".never input").left - line.left)).to.be.lessThan(1) + expect(rect(".never").top).to.be.greaterThan(line.bottom) + }) + }) + + it("wraps the text beside the buttons when narrower, with the checkbox centred", () => { + cy.viewport(800, 800) + settled().then(() => { + const plank = rect(".plank") + const words = rect(".words") + expect(words.width / plank.width).to.be.within(0.35, 0.65) + expect(rect(".try").left).to.be.greaterThan(words.right) + // Centred in the plank's content box: inside the slope's padding and the wood edge. + const css = getComputedStyle(Cypress.$("aside.announce .plank")[0]) + const px = (name) => parseFloat(css[name]) + const content = (plank.left + px("borderLeftWidth") + px("paddingLeft") + plank.right - px("borderRightWidth") - px("paddingRight")) / 2 + const never = rect(".never") + expect(Math.abs(never.left + never.width / 2 - content)).to.be.lessThan(4) + }) + }) + + it("switches the generator to a sloped front when tried", () => { + banner().find(".try").click() + cy.get('[data-generator-target="shape"]').should("have.value", "sloped") + cy.get('[data-generator-target="sloped"]').should("be.visible") + banner().should("have.attr", "hidden") + cy.window().then((win) => expect(win.localStorage.getItem(KEY)).to.be.null) + }) + + it("opens the discussion when Comment is clicked", () => { + banner().find(".comment").click() + cy.get("dialog#discussion").should("have.attr", "open") + cy.location("hash").should("eq", "#discussion") + banner().should("have.attr", "hidden") + }) + + it("comes back on the next page load unless told not to", () => { + banner().find(".close").click() + banner().should("have.attr", "hidden") + cy.reload() + banner().should("be.visible").and("have.class", "in") + }) + + it("stays gone once Do not show again is ticked", () => { + banner().find(".never input").check() + cy.window().then((win) => expect(win.localStorage.getItem(KEY)).to.eq("1")) + // The server renders it hidden anyway, so prove the controller ran and read its key. + cy.visit("/", { onBeforeLoad: (win) => cy.spy(win.Storage.prototype, "getItem").as("getItem") }) + cy.get("@getItem").should("have.been.calledWith", KEY) + banner().should("not.have.class", "in").and("have.attr", "hidden") + cy.get('[data-generator-target="shape"]').should("have.value", "upright") + }) + + it("forgets the choice when the box is unticked again", () => { + banner().find(".never input").check().uncheck() + cy.window().then((win) => expect(win.localStorage.getItem(KEY)).to.be.null) + }) +}) diff --git a/spec/requests/home_spec.rb b/spec/requests/home_spec.rb index 333f1c4..04192bd 100644 --- a/spec/requests/home_spec.rb +++ b/spec/requests/home_spec.rb @@ -28,6 +28,15 @@ expect(response.body).to include('Kerf matters most', 'The default, 0.026 in (0.66 mm)') end + it 'announces the release with sloped sides, hidden until the script shows it' do + expect(response.body).to include( + '