From 286731e39812a684a57db07befd11d5fad23c253 Mon Sep 17 00:00:00 2001 From: Snider Date: Tue, 14 Apr 2026 19:22:17 +0100 Subject: [PATCH] feat(html): Metadata alias on Context + Responsive.Add with media-query hint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Brings the portable pieces of mini's feat/main-session-work onto dev: - context.go: Context.Metadata field — alias for Data, references the same underlying map. Both fields interchangeable at read/write sites. - responsive.go: responsiveVariant gains an optional media field for CSS media-query hints (e.g. "(min-width: 1024px)"); new Responsive.Add(name, layout, media...) method. Existing Variant(name, layout) becomes a thin alias over Add. - go.mod: drop stale dappco.re/go/core/{inference,log} indirect requires (refreshed by go mod tidy — forge.lthn.ai/core/{go-inference,go-log}). Mini's local deps/go-i18n/reversal grammar-vector rewrite does not apply to dev: dev consumes reversal as an external package (dappco.re/go/core/i18n/reversal) rather than an internal fork. That portion of the branch is left on feat/main-session-work for future re-integration. Verified: GOWORK=off go build ./... + go test ./... passes. Co-Authored-By: Virgil --- context.go | 8 +++++++- go.mod | 4 ++-- responsive.go | 16 +++++++++++++++- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/context.go b/context.go index f5d40e5..91167ef 100644 --- a/context.go +++ b/context.go @@ -11,11 +11,15 @@ type Translator interface { // Context carries rendering state through the node tree. // Usage example: ctx := NewContext() +// +// Metadata is an alias for Data — both fields reference the same underlying map. +// Treat them as interchangeable; use whichever reads best in context. type Context struct { Identity string Locale string Entitlements func(feature string) bool Data map[string]any + Metadata map[string]any service Translator } @@ -39,8 +43,10 @@ func applyLocaleToService(svc Translator, locale string) { // NewContext creates a new rendering context with sensible defaults. // Usage example: html := Render(Text("welcome"), NewContext("en-GB")) func NewContext(locale ...string) *Context { + data := make(map[string]any) ctx := &Context{ - Data: make(map[string]any), + Data: data, + Metadata: data, // alias — same underlying map } if len(locale) > 0 { ctx.SetLocale(locale[0]) diff --git a/go.mod b/go.mod index f9d51e8..ec55646 100644 --- a/go.mod +++ b/go.mod @@ -12,8 +12,8 @@ require ( ) require ( - dappco.re/go/core/inference v0.1.4 // indirect - dappco.re/go/core/log v0.0.4 // indirect + forge.lthn.ai/core/go-inference v0.1.4 // indirect + forge.lthn.ai/core/go-log v0.0.4 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect golang.org/x/text v0.35.0 // indirect diff --git a/responsive.go b/responsive.go index 896d0ae..fc25af0 100644 --- a/responsive.go +++ b/responsive.go @@ -18,6 +18,7 @@ type Responsive struct { type responsiveVariant struct { name string layout *Layout + media string // optional CSS media-query hint (e.g. "(min-width: 768px)") } // NewResponsive creates a new multi-variant responsive compositor. @@ -29,11 +30,24 @@ func NewResponsive() *Responsive { // Variant adds a named layout variant (e.g., "desktop", "tablet", "mobile"). // Usage example: NewResponsive().Variant("desktop", NewLayout("HLCRF")) // Variants render in insertion order. +// Variant is equivalent to Add(name, layout) with no media-query hint. func (r *Responsive) Variant(name string, layout *Layout) *Responsive { + return r.Add(name, layout) +} + +// Add registers a responsive variant. The optional media argument carries a +// CSS media-query hint for downstream CSS generation (e.g. "(min-width: 768px)"). +// +// Usage example: NewResponsive().Add("desktop", NewLayout("HLCRF"), "(min-width: 1024px)") +func (r *Responsive) Add(name string, layout *Layout, media ...string) *Responsive { if r == nil { r = NewResponsive() } - r.variants = append(r.variants, responsiveVariant{name: name, layout: layout}) + variant := responsiveVariant{name: name, layout: layout} + if len(media) > 0 { + variant.media = media[0] + } + r.variants = append(r.variants, variant) return r }