@gramlot/gramlot 0.2.16 → 0.2.17

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.
@@ -6,7 +6,7 @@
6
6
  */
7
7
  import {SvgRenderer, svgAttributes} from '@genrojs/builders';
8
8
  import {
9
- boundaryAttributes, domNames, requireNoScriptAttributes, textValue, withoutBindingAttributes, withoutNullValues,
9
+ boundaryAttributes, domNames, requireNoScriptAttributes, requireStyleClassAttributes, textValue, withoutBindingAttributes, withoutNullValues,
10
10
  } from './attributes.js';
11
11
 
12
12
  // SVG elements written `<tag … />`, as the Python SvgRenderer of Builder (the grammar gives them no children).
@@ -42,6 +42,7 @@ export class GramlotSvgRenderer extends SvgRenderer {
42
42
  const evaluated = this.owner.evaluateExpressions(node, runtimeAttrs);
43
43
  requireNoScriptAttributes(node, evaluated);
44
44
  const [tag, attrs] = super._handleMeta(node, evaluated);
45
+ requireStyleClassAttributes(node, attrs);
45
46
  return node._getMeta('subbuilder') ? [tag, svgAttributes(boundaryAttributes(attrs))] : [tag, attrs];
46
47
  }
47
48
 
@@ -120,8 +120,28 @@ export async function checkProtocol(baseUrl, pagePath) {
120
120
 
121
121
  response = await request('GET', rpc);
122
122
  expect('GC-230-120', response.status === 405, `GET ${rpc} answers ${response.status}, not 405`);
123
- response = await request('POST', rpc, {body: toTytx(envelope('source', 'main')), contentType: 'text/plain'});
124
- expect('GC-230-120', response.status === 415, `rpc as text/plain answers ${response.status}, not 415`);
123
+ for (const [path, rule, body] of [
124
+ [rpc, 'GC-230-120', toTytx(envelope('data', 'check_endpoint', {value: 'invalid-byte'}))],
125
+ [config.closeUrl, 'GC-230-125', JSON.stringify({pageId, value: 'invalid-byte'})],
126
+ ]) {
127
+ for (const contentType of ['text/plain', 'application/jsonp', 'application/json-extra', '']) {
128
+ response = await request('POST', path, {body, contentType});
129
+ expect(rule, response.status === 415, `${path} as ${JSON.stringify(contentType)} answers ${response.status}, not 415`);
130
+ }
131
+ // Keep JSON syntax valid: a replacing decoder would dispatch this body instead of rejecting it.
132
+ const invalidUtf8 = Buffer.from(body);
133
+ invalidUtf8[invalidUtf8.indexOf('invalid-byte')] = 0xff;
134
+ response = await request('POST', path, {body: invalidUtf8});
135
+ expect(rule, response.status === 400, `${path} with invalid UTF-8 inside a JSON string answers ${response.status}, not 400`);
136
+ }
137
+ for (const contentType of ['Application/JSON', 'application/json; charset=utf-8', 'application/json ; charset=UTF-8']) {
138
+ response = await call(envelope('data', 'check_endpoint', {value: 'media-type'}), {contentType});
139
+ expect('GC-230-120', response.status === 200 && response.received?.value === 'media-type',
140
+ `rpc as ${contentType} answers ${response.status} ${response.body.slice(0, 200)}, not the endpoint value`);
141
+ response = await request('POST', config.closeUrl, {body: JSON.stringify({pageId: '0'.repeat(32)}), contentType});
142
+ expect('GC-230-125', response.status === 200 && isDeepStrictEqual(parse(response.body, JSON.parse), {ok: true}),
143
+ `close as ${contentType} answers ${response.status} ${response.body.slice(0, 200)}, not 200 {"ok": true}`);
144
+ }
125
145
  response = await request('POST', rpc, {body: '{'});
126
146
  expect('GC-230-120', response.status === 400, `rpc with invalid JSON answers ${response.status}, not 400`);
127
147
  const {pageId: omitted, ...withoutPageId} = envelope('source', 'main');
@@ -102,6 +102,7 @@ export class GramlotServer {
102
102
  /** Create a server. */
103
103
  constructor(options?: GramlotServerOptions);
104
104
  /** The Page class of `path`, or `PageNotFound`. */
105
+ pageManifest(options?: {prefix?: string}): Promise<Record<string, unknown>>;
105
106
  resolvePage(path: string): Promise<typeof Page>;
106
107
  /** The resources of the page at `path` in load order and without mount prefix, or `PageNotFound`. */
107
108
  resolveResources(path: string, PageClass: typeof Page): Promise<Resources>;
@@ -106,6 +106,15 @@ export class GramlotServer {
106
106
  for (const [id, record] of this.pages) if (record.expires <= now) this.pages.delete(id);
107
107
  }
108
108
 
109
+ /** Describe the root application without registering a page session. */
110
+ async pageManifest({prefix = ''} = {}) {
111
+ const PageClass = await this.resolvePage('/');
112
+ if (PageClass.installable !== true) throw new PageNotFound('The root page is not installable');
113
+ const result = await new PageClass().manifest({baseUrl: prefix + '/'});
114
+ if (!isMapping(result)) throw new TypeError('Page.manifest must return a JSON object');
115
+ return result;
116
+ }
117
+
109
118
  /** Register a page independently of its HTTP or Worker transport. */
110
119
  async registerPage(path, {owner = null} = {}) {
111
120
  const PageClass = await this.resolvePage(path);
@@ -139,6 +148,9 @@ export class GramlotServer {
139
148
  const head = root.head();
140
149
  head.meta({charset: 'utf-8'});
141
150
  head.title(title);
151
+ if (['', 'index'].includes(path.replace(/^\/+|\/+$/g, '')) && this.pages.get(pageId).PageClass.installable === true) {
152
+ head.link({rel: 'manifest', href: prefix + '/app.webmanifest'});
153
+ }
142
154
  // A page module served for its Logic imports the core from the runtime already loaded.
143
155
  head.script(scriptJson({imports: {'@gramlot/gramlot/page': prefixed(prefix, this.runtimeUrl)}}),
144
156
  {type: 'importmap', nonce});
@@ -0,0 +1,14 @@
1
+ import {Page} from './page.js';
2
+ export interface IndexItem { key: string; title: string; url: string; }
3
+ export interface IndexGroup { key: string; title: string; children: IndexItem[]; }
4
+ /** One index shell per document. Override footer to replace or extend standard controls. */
5
+ export class IndexPage extends Page {
6
+ static logoUrl: string;
7
+ static shellId: string;
8
+ static navigation: IndexGroup[];
9
+ introduction(pane: any): void;
10
+ groupPanel(pane: any, group: IndexGroup): void;
11
+ panel(pane: any, item: IndexItem): void;
12
+ footer(pane: any): void;
13
+ behavior(pane: any): void;
14
+ }
@@ -0,0 +1,102 @@
1
+ /* @ts-self-types="./index-page.d.ts" */
2
+ /** Reusable application index authored with Gramlot Source. */
3
+ import {Page as GramlotPage} from './page-base.js';
4
+
5
+ export class IndexPage extends GramlotPage {
6
+ static title = 'Application';
7
+ static logoUrl = '';
8
+ static shellId = 'index';
9
+ static navigation = [];
10
+ static css = ['/themes/gramlot-base/theme.css', '/themes/gramlot-index/theme.css'];
11
+
12
+ main(root) {
13
+ const families = this.constructor.navigation;
14
+ const shell = root.div({class: 'index-shell', id: this.constructor.shellId});
15
+ const sidebar = shell.aside({class: 'index-sidebar', id: 'index-sidebar'});
16
+ const brand = sidebar.header();
17
+ if (this.constructor.logoUrl) brand.img({src: this.constructor.logoUrl, alt: this.constructor.title, class: 'index-logo'});
18
+ brand.h1(this.constructor.title);
19
+ const navigation = sidebar.nav({'aria-label': 'Pages'}).ul({class: 'index-list'});
20
+ for (const family of families) {
21
+ const category = navigation.li().details({open: family === families[0]});
22
+ category.summary({tabindex: -1}).a(family.title, {id: `open-${family.key}`, href: `#panel-${family.key}`,
23
+ class: 'index-family', aria_current: null, tabindex: -1});
24
+ const examplesList = category.ul({class: 'index-list'});
25
+ for (const example of family.children) {
26
+ examplesList.li().a(example.title, {id: `open-${example.key}`, href: example.url,
27
+ aria_current: null, tabindex: -1});
28
+ }
29
+ }
30
+ shell.div({class: 'index-divider', id: 'index-sidebar-divider',
31
+ role: 'separator', aria_orientation: 'vertical', tabindex: 0,
32
+ aria_label: 'Resize sidebar', aria_controls: 'index-sidebar',
33
+ aria_valuemin: 120, aria_valuemax: 460, aria_valuenow: 240});
34
+ const content = shell.main({class: 'index-main'});
35
+ const tabs = content.div({class: 'index-tabs', role: 'tablist', aria_label: 'Open pages'});
36
+ tabs.button('Introduction', {type: 'button', role: 'tab', id: 'tab-intro',
37
+ aria_controls: 'panel-intro',
38
+ aria_selected: 'true', tabindex: -1, hidden: false});
39
+ for (const family of families) {
40
+ for (const {key, title} of [family, ...family.children]) {
41
+ tabs.button(title, {type: 'button', role: 'tab', id: `tab-${key}`,
42
+ aria_controls: `panel-${key}`,
43
+ aria_selected: 'false', tabindex: -1, hidden: true});
44
+ }
45
+ }
46
+
47
+ const panels = content.div({class: 'index-panels'});
48
+ const intro = panels.section({id: 'panel-intro', class: 'index-intro', role: 'tabpanel',
49
+ aria_labelledby: 'tab-intro', hidden: false});
50
+ this.introduction(intro);
51
+
52
+ for (const family of families) {
53
+ const categoryPanel = panels.section({id: `panel-${family.key}`, class: 'index-category',
54
+ role: 'tabpanel',
55
+ aria_labelledby: `tab-${family.key}`, hidden: true});
56
+ this.groupPanel(categoryPanel, family);
57
+ for (const example of family.children) this.panel(panels, example);
58
+ }
59
+ const footer = shell.footer({class: 'index-footer'});
60
+ this.footer(footer);
61
+ this.behavior(shell);
62
+ }
63
+
64
+ behavior(shell) {
65
+ shell.dataController({func: 'indexMount', _onStart: true, shell_id: this.constructor.shellId});
66
+ }
67
+ introduction(pane) {
68
+ pane.h2(this.constructor.title);
69
+ pane.p('Choose a page from the navigation. Open pages remain available in tabs.');
70
+ }
71
+ groupPanel(pane, group) { pane.h2(group.title); }
72
+ footer(footer) {
73
+ const theme = footer.div({class: 'index-theme'});
74
+ theme.html_label('Theme', {for: 'index-appearance'});
75
+ const appearance = theme.select({id: 'index-appearance', value: 'compact'});
76
+ appearance.option('Base', {value: 'base', selected: false});
77
+ appearance.option('Compact', {value: 'compact', selected: true});
78
+ const color = footer.div({class: 'index-theme'});
79
+ color.html_label('Color mode', {for: 'index-theme'});
80
+ const choices = color.select({id: 'index-theme', value: 'light'});
81
+ choices.option('Light', {value: 'light', selected: true});
82
+ choices.option('Dark', {value: 'dark', selected: false});
83
+ const keyboard = footer.div({class: 'index-keyboard'});
84
+ const label = keyboard.html_label({for: 'keyboard-navigation'});
85
+ label.input({type: 'checkbox', id: 'keyboard-navigation', checked: false});
86
+ label.span('Keyboard navigation');
87
+
88
+ if (this.constructor.installable) {
89
+ const app = footer.details({class: 'index-install'});
90
+ app.summary('Install app');
91
+ app.button('Install', {type: 'button', id: 'index-install-button', hidden: true});
92
+ app.p('', {id: 'index-install-status', role: 'status'});
93
+ app.p('Chrome: use Install page as app in the browser menu. Safari on macOS Sonoma or later: File > Add to Dock.');
94
+ app.p('Use HTTPS or localhost. For a static export, serve the directory; direct file opening is not installable. Keep the server running for hosted pages.');
95
+ }
96
+ }
97
+ panel(parent, item) {
98
+ const pane = parent.section({id: `panel-${item.key}`, class: 'index-panel', role: 'tabpanel',
99
+ aria_labelledby: `tab-${item.key}`, hidden: true});
100
+ pane.iframe({id: `frame-${item.key}`, title: item.title, name: `page-${item.key}`});
101
+ }
102
+ }
@@ -0,0 +1,88 @@
1
+ /* @ts-self-types="./page.d.ts" */
2
+ /**
3
+ * Server-side page base class and the `registerSource` and `registerEndpoint` markers.
4
+ *
5
+ * @module
6
+ */
7
+ import {GramlotBuilder} from '../builder/gramlot-builder.js';
8
+
9
+ /** The marker of a Source method and of an endpoint: `{auth}` on the method, as the Python
10
+ * `__gramlot_source__` and `__gramlot_endpoint__` attributes. */
11
+ export const SOURCE_METHOD = Symbol('gramlot.source');
12
+ export const ENDPOINT_METHOD = Symbol('gramlot.endpoint');
13
+ const MARKERS = new Map([[SOURCE_METHOD, 'registerSource'], [ENDPOINT_METHOD, 'registerEndpoint']]);
14
+
15
+ function declaredMethod(page, name, marker) {
16
+ if (typeof name !== 'string' || !/^[A-Za-z][\w]*$/.test(name)) return null;
17
+ for (let proto = Object.getPrototypeOf(page); proto; proto = Object.getPrototypeOf(proto)) {
18
+ const descriptor = Object.getOwnPropertyDescriptor(proto, name);
19
+ if (descriptor) return descriptor.value?.[marker] ? descriptor.value : null;
20
+ }
21
+ return null;
22
+ }
23
+
24
+ export function sourceMethod(page, name) {
25
+ return declaredMethod(page, name, SOURCE_METHOD);
26
+ }
27
+
28
+ export function endpointMethod(page, name) {
29
+ return declaredMethod(page, name, ENDPOINT_METHOD);
30
+ }
31
+
32
+ function declare(PageClass, methodName, marker, auth) {
33
+ const register = MARKERS.get(marker);
34
+ if (methodName === 'main') throw new TypeError(`${register} cannot declare main`);
35
+ const method = Object.getOwnPropertyDescriptor(PageClass.prototype, methodName)?.value;
36
+ if (typeof method !== 'function') {
37
+ throw new TypeError(`${register} requires an own method of ${PageClass.name}: ${String(methodName)}`);
38
+ }
39
+ if (method[marker]) {
40
+ throw new TypeError(`${marker === SOURCE_METHOD ? 'Source method' : 'Endpoint'} already registered: ${methodName}`);
41
+ }
42
+ if (method[SOURCE_METHOD] || method[ENDPOINT_METHOD]) {
43
+ throw new TypeError(`${methodName} is declared both as Source method and endpoint`);
44
+ }
45
+ method[marker] = {auth};
46
+ }
47
+
48
+ /** Server-side page base; unrelated to browser view components. */
49
+ export class Page {
50
+ static title = 'Gramlot';
51
+ static installable = false;
52
+ static appIcon = null;
53
+
54
+ /** Default root manifest. appIcon is a 512px square PNG below the app root. */
55
+ manifest({baseUrl = './'} = {}) {
56
+ const {title, appIcon} = this.constructor;
57
+ if (typeof appIcon !== 'string' || !appIcon) throw new TypeError('An installable Page needs appIcon');
58
+ return {id: baseUrl, name: title, short_name: title, start_url: baseUrl,
59
+ scope: baseUrl, display: 'standalone',
60
+ icons: [{src: baseUrl + appIcon.replace(/^\/+/, ''), sizes: '512x512', type: 'image/png'}]};
61
+ }
62
+
63
+ static css = [];
64
+ static css_requires = '';
65
+ static js_requires = '';
66
+ static sourceBuilder = GramlotBuilder;
67
+
68
+ main(root) {
69
+ throw new Error('Page.main(root) must be implemented');
70
+ }
71
+
72
+ /**
73
+ * Mark the own method `methodName` of this page class as a remote Source method,
74
+ * equivalent to Python `@source`; call it after the class.
75
+ *
76
+ * A declared fragment is requested from code with `gramlot.src.remoteSource` (GC-230 §035);
77
+ * the `remote` attribute requests it declaratively (GC-095 §105).
78
+ */
79
+ static registerSource(methodName, {auth = null} = {}) {
80
+ declare(this, methodName, SOURCE_METHOD, auth);
81
+ }
82
+
83
+ /** Mark the own method `methodName` of this page class as an endpoint called with
84
+ * `contentType: 'data'`, equivalent to Python `@endpoint`; call it after the class. */
85
+ static registerEndpoint(methodName, {auth = null} = {}) {
86
+ declare(this, methodName, ENDPOINT_METHOD, auth);
87
+ }
88
+ }
@@ -19,6 +19,9 @@ export function endpointMethod(page: Page, name: string): Function | null;
19
19
  export class Page {
20
20
  /** The title of the page document. */
21
21
  static title: string;
22
+ static installable: boolean;
23
+ static appIcon: string | null;
24
+ manifest(options?: {baseUrl?: string}): Record<string, unknown> | Promise<Record<string, unknown>>;
22
25
  /** CSS URLs of the page. */
23
26
  static css: string[];
24
27
  /** Comma-separated names of the CSS resources of the page. */
@@ -36,11 +39,14 @@ export class Page {
36
39
  * equivalent to the Python `@source`; call it after the class. A Source method populates
37
40
  * its `root` argument and returns nothing.
38
41
  *
39
- * A declared fragment is requested from code with `gramlot.src.remoteSource` (GC-230 §035); the
40
- * declarative `remote` grammar attribute is not yet available.
42
+ * A declared fragment is requested from code with `gramlot.src.remoteSource` (GC-230 §035);
43
+ * the `remote` attribute requests it declaratively (GC-095 §105).
41
44
  */
42
45
  static registerSource(methodName: string, options?: {auth?: string | null}): void;
43
46
  /** Mark the own method `methodName` of this page class as an endpoint called with
44
47
  * `contentType: 'data'`, equivalent to the Python `@endpoint`; call it after the class. */
45
48
  static registerEndpoint(methodName: string, options?: {auth?: string | null}): void;
46
49
  }
50
+
51
+ export {IndexPage} from "./index-page.js";
52
+ export {IndexLogic, mountIndexPage} from "../index-page-runtime.js";
@@ -1,76 +1,3 @@
1
- /* @ts-self-types="./page.d.ts" */
2
- /**
3
- * Server-side page base class and the `registerSource` and `registerEndpoint` markers.
4
- *
5
- * @module
6
- */
7
- import {GramlotBuilder} from '../builder/gramlot-builder.js';
8
-
9
- /** The marker of a Source method and of an endpoint: `{auth}` on the method, as the Python
10
- * `__gramlot_source__` and `__gramlot_endpoint__` attributes. */
11
- export const SOURCE_METHOD = Symbol('gramlot.source');
12
- export const ENDPOINT_METHOD = Symbol('gramlot.endpoint');
13
- const MARKERS = new Map([[SOURCE_METHOD, 'registerSource'], [ENDPOINT_METHOD, 'registerEndpoint']]);
14
-
15
- function declaredMethod(page, name, marker) {
16
- if (typeof name !== 'string' || !/^[A-Za-z][\w]*$/.test(name)) return null;
17
- for (let proto = Object.getPrototypeOf(page); proto; proto = Object.getPrototypeOf(proto)) {
18
- const descriptor = Object.getOwnPropertyDescriptor(proto, name);
19
- if (descriptor) return descriptor.value?.[marker] ? descriptor.value : null;
20
- }
21
- return null;
22
- }
23
-
24
- export function sourceMethod(page, name) {
25
- return declaredMethod(page, name, SOURCE_METHOD);
26
- }
27
-
28
- export function endpointMethod(page, name) {
29
- return declaredMethod(page, name, ENDPOINT_METHOD);
30
- }
31
-
32
- function declare(PageClass, methodName, marker, auth) {
33
- const register = MARKERS.get(marker);
34
- if (methodName === 'main') throw new TypeError(`${register} cannot declare main`);
35
- const method = Object.getOwnPropertyDescriptor(PageClass.prototype, methodName)?.value;
36
- if (typeof method !== 'function') {
37
- throw new TypeError(`${register} requires an own method of ${PageClass.name}: ${String(methodName)}`);
38
- }
39
- if (method[marker]) {
40
- throw new TypeError(`${marker === SOURCE_METHOD ? 'Source method' : 'Endpoint'} already registered: ${methodName}`);
41
- }
42
- if (method[SOURCE_METHOD] || method[ENDPOINT_METHOD]) {
43
- throw new TypeError(`${methodName} is declared both as Source method and endpoint`);
44
- }
45
- method[marker] = {auth};
46
- }
47
-
48
- /** Server-side page base; unrelated to browser view components. */
49
- export class Page {
50
- static title = 'Gramlot';
51
- static css = [];
52
- static css_requires = '';
53
- static js_requires = '';
54
- static sourceBuilder = GramlotBuilder;
55
-
56
- main(root) {
57
- throw new Error('Page.main(root) must be implemented');
58
- }
59
-
60
- /**
61
- * Mark the own method `methodName` of this page class as a remote Source method,
62
- * equivalent to Python `@source`; call it after the class.
63
- *
64
- * A declared fragment is requested from code with `gramlot.src.remoteSource` (GC-230 §035); the
65
- * declarative `remote` grammar attribute is not yet available.
66
- */
67
- static registerSource(methodName, {auth = null} = {}) {
68
- declare(this, methodName, SOURCE_METHOD, auth);
69
- }
70
-
71
- /** Mark the own method `methodName` of this page class as an endpoint called with
72
- * `contentType: 'data'`, equivalent to Python `@endpoint`; call it after the class. */
73
- static registerEndpoint(methodName, {auth = null} = {}) {
74
- declare(this, methodName, ENDPOINT_METHOD, auth);
75
- }
76
- }
1
+ export * from './page-base.js';
2
+ export {IndexPage} from './index-page.js';
3
+ export {IndexLogic, mountIndexPage} from '../index-page-runtime.js';
package/src/view/html.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import {SourceBag, META_ATTRS, resolveRenderTag, sourceAttributeItems, SvgBuilder} from '@genrojs/builders';
2
2
  import {ControlAdapter} from './controls.js';
3
3
  import {SVG_NS, XHTML_NS} from '../renderer/attributes.js';
4
+ import {webcomponentCode} from '../webcomponent.js';
4
5
 
5
6
  const DEFAULT_TEXT = Symbol('source text');
6
7
  const ATTRIBUTE_NS = {
@@ -42,7 +43,7 @@ export class HtmlElement {
42
43
  const builder = node.builder;
43
44
  const declaration = builder.schema[builder.schemaTag(node.nodeTag)];
44
45
  const meta = {...declaration._meta, ...node.getAttr('_meta')};
45
- const tag = resolveRenderTag(node.nodeTag, {
46
+ const tag = node.nodeTag === 'webcomponent' ? webcomponentCode(node.getAttr()) : resolveRenderTag(node.nodeTag, {
46
47
  renderTag: meta.render_tag, ns: node.getAttr('ns'),
47
48
  dialectName: builder.constructor._name,
48
49
  });
@@ -0,0 +1,13 @@
1
+ // Custom-element names, shared by inert authoring and DOM projection.
2
+ const NAME = /^[a-z][.0-9_a-z\-\u00B7\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u037D\u037F-\u1FFF\u200C-\u200D\u203F-\u2040\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u{10000}-\u{EFFFF}]*$/u;
3
+ const RESERVED = new Set(['annotation-xml', 'color-profile', 'font-face', 'font-face-src',
4
+ 'font-face-uri', 'font-face-format', 'font-face-name', 'missing-glyph']);
5
+
6
+ /** The literal DOM tag of a webcomponent; code is never a Data pointer or expression. */
7
+ export function webcomponentCode(attrs) {
8
+ const code = attrs.code;
9
+ if (typeof code !== 'string' || NAME.exec(code)?.[0] !== code || !code.includes('-') || RESERVED.has(code)) {
10
+ throw new TypeError('webcomponent: code must be a literal custom-element name');
11
+ }
12
+ return code;
13
+ }
@@ -8,6 +8,14 @@
8
8
 
9
9
  The adapters of `gramlot-py-server` and `gramlot-js-server` serve the themes packaged with the core at `/themes/…`, below the mount prefix, and `@gramlot/gramlot-serverless` copies or inlines them in its export. Another host must serve this file at that path. The theme styles semantic HTML, forms, tables, dialogs, details, code, focus states, and a few optional layout classes: `.example-page`, `.stack`, `.grid`, `.card`, `.muted`, and fluid SVG `.example-art`. Secondary button variants are `.button--secondary` and `.button--quiet`; status chips use `.status` with a semantic modifier. SVG icons can use `.gramlot-icon` (fill) or `.gramlot-icon--stroke` (stroke) and inherit `currentColor`. Supply an accessible name or mark decorative icons `aria-hidden="true"` in the application.
10
10
 
11
+ ## Available themes
12
+
13
+ Base is the original theme. [Compact](../gramlot-compact/README.md) is its denser
14
+ alternative, with smaller headings, gaps, card padding and form controls. Both
15
+ support light and dark mode. Load Base alone for the original appearance, or Base
16
+ followed by `/themes/gramlot-compact/theme.css` for Compact. The existing `Page.css`
17
+ list can be declared once on a shared application Page base class.
18
+
11
19
  ## Tokens and extension
12
20
 
13
21
  The light palette follows [`assets/branding/theme-tokens.json`](../../assets/branding/theme-tokens.json) and the [visual guide](../../assets/branding/theme-guide.md). All theme variables use the `--gramlot-` prefix. The design primitives include spacing, radii, font stacks, a shadow, focus ring, and page width. Override variables after this stylesheet to customize a page or create a sibling theme:
@@ -0,0 +1,49 @@
1
+ # Gramlot Compact theme
2
+
3
+ Compact is the denser alternative to Gramlot Base. It reduces typography, spacing,
4
+ headings, card padding, table cells and form controls. It shares Base's palette,
5
+ light/dark modes, focus indicators and semantic HTML rules.
6
+
7
+ Load both stylesheets, in this order. Compact contains only the size and spacing
8
+ rules that differ; it does not duplicate the Base stylesheet or import another URL.
9
+ The same resource list works with Python servers, JavaScript servers and standalone
10
+ exports using the existing `Page.css` mechanism.
11
+
12
+ ```python
13
+ from gramlot import Page as BasePage
14
+
15
+ class Page(BasePage):
16
+ css = (
17
+ "/themes/gramlot-base/theme.css",
18
+ "/themes/gramlot-compact/theme.css",
19
+ )
20
+ ```
21
+
22
+ ```javascript
23
+ import {Page as BasePage} from '@gramlot/gramlot/page';
24
+
25
+ export class Page extends BasePage {
26
+ static css = [
27
+ '/themes/gramlot-base/theme.css',
28
+ '/themes/gramlot-compact/theme.css',
29
+ ];
30
+ }
31
+ ```
32
+
33
+ Declare this list on a shared application Page base class to reuse it across pages.
34
+ Keep the usual native elements and classes in `main`; there is no theme-specific
35
+ builder syntax. Load only Base to use the original theme.
36
+
37
+ | Setting | Base | Compact |
38
+ | --- | --- | --- |
39
+ | Root font size | 14px | 13px |
40
+ | Body line height | 1.5 | 1.35 |
41
+ | Stack/grid gap | 1rem | .6rem |
42
+ | Button and single-line field minimum height | 2.75rem | 28px |
43
+ | Card padding | .75–1rem | .6rem |
44
+ | Table cell padding | .7rem .8rem | .4rem .5rem |
45
+
46
+ Color mode is independent: `data-theme="light"` or `data-theme="dark"` on the
47
+ document root selects it, otherwise Base follows the system preference. Application
48
+ CSS outside the Gramlot cascade layers can override both themes. Browser zoom remains
49
+ available; multiline controls keep their native behavior.
@@ -0,0 +1,57 @@
1
+ /* Gramlot Compact: load after gramlot-base/theme.css. Colors and behavior stay in Base. */
2
+ @layer gramlot.tokens {
3
+ :root {
4
+ --gramlot-space-1: .2rem;
5
+ --gramlot-space-2: .4rem;
6
+ --gramlot-space-3: .5rem;
7
+ --gramlot-space-4: .6rem;
8
+ --gramlot-space-6: .9rem;
9
+ --gramlot-space-8: 1.2rem;
10
+ --gramlot-space-12: 1.8rem;
11
+ --gramlot-radius-sm: .25rem;
12
+ --gramlot-radius: .35rem;
13
+ --gramlot-radius-lg: .4rem;
14
+ }
15
+ }
16
+
17
+ @layer gramlot.base {
18
+ html { font-size: 13px; }
19
+ body { line-height: 1.35; }
20
+ :where(h1, h2, h3, h4, h5, h6, p, ul, ol, dl, blockquote, pre, figure) { margin-block: 0 .5rem; }
21
+ h1 { font-size: 1.35rem; }
22
+ h2 { font-size: 1.15rem; }
23
+ h3 { font-size: 1.05rem; }
24
+ pre { padding: .5rem; }
25
+ blockquote { padding-inline-start: .6rem; }
26
+ hr { margin-block: 1rem; }
27
+ }
28
+
29
+ @layer gramlot.components {
30
+ :where(button, input[type="button"], input[type="submit"], input[type="reset"], .button) {
31
+ min-block-size: 28px;
32
+ padding: .25rem .5rem;
33
+ font-size: 1rem;
34
+ line-height: 1.35;
35
+ }
36
+ :where(label) { font-size: .95rem; }
37
+ :where(input:not([type="button"]):not([type="submit"]):not([type="reset"]):not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"]):not([type="hidden"]), select, textarea) {
38
+ min-block-size: 28px;
39
+ padding: .25rem .5rem;
40
+ font-size: 1rem;
41
+ line-height: 1.35;
42
+ }
43
+ :where(textarea) { min-block-size: 5rem; }
44
+ :where(input[type="color"]) { min-block-size: 28px; }
45
+ :where(input[type="file"])::file-selector-button { margin-inline-end: .5rem; padding: .25rem .5rem; }
46
+ :where(fieldset) { margin-block-end: .6rem; padding: .5rem; }
47
+ :where(table) { font-size: 1rem; }
48
+ :where(th, td) { padding: .4rem .5rem; }
49
+ :where(details) { padding: .4rem .5rem; }
50
+ :where(details[open] > summary) { margin-block-end: .5rem; }
51
+ :where(dialog) { padding: .75rem; }
52
+ }
53
+
54
+ @layer gramlot.utilities {
55
+ .example-page { inline-size: min(100% - 1.2rem, var(--gramlot-page-width)); padding-block: .6rem; }
56
+ .card { padding: .6rem; box-shadow: none; }
57
+ }
@@ -0,0 +1,51 @@
1
+ .index-shell { block-size: 100dvh; display: grid; grid-template-rows: minmax(0, 1fr) auto; grid-template-columns: min(var(--sidebar-width, 240px), 60vw) 8px minmax(0, 1fr); overflow: hidden; }
2
+ .index-sidebar { min-block-size: 0; min-inline-size: 0; display: flex; flex-direction: column; overflow: hidden; padding: .5rem; background: var(--gramlot-navigation); color: var(--gramlot-navigation-text); border-block-start: 3px solid var(--gramlot-brand-yellow); border-inline-end: 1px solid var(--gramlot-border); }
3
+ .index-sidebar nav { flex: 1; min-block-size: 0; overflow: auto; }
4
+ .index-sidebar h1 { margin: 0 .4rem .5rem; font-size: 1.1rem; }
5
+ .index-logo { display: block; inline-size: 56px; block-size: auto; margin: 0 auto .3rem; }
6
+ .index-list { list-style: none; margin: 0; padding: 0; }
7
+ .index-list li + li { margin-block-start: 1px; }
8
+ .index-list a { display: block; inline-size: 100%; min-block-size: 26px; padding: .25rem .45rem; border: 0; border-radius: .25rem; background: transparent; color: var(--gramlot-navigation-text); text-align: start; text-decoration: none; font-size: 1rem; font-weight: 450; overflow-wrap: normal; }
9
+ .index-list a:hover { background: var(--gramlot-action-hover); color: var(--gramlot-navigation-text); }
10
+ .index-list a[aria-current="page"] { background: var(--gramlot-brand-blue); color: #fff; font-weight: 650; }
11
+ .index-list .index-list { margin-inline-start: .5rem; padding-inline-start: .3rem; border-inline-start: 1px solid var(--gramlot-border-control); }
12
+ .index-list .index-family { font-weight: 650; }
13
+ .index-list details { border: 0; border-radius: 0; background: transparent; padding: 0; }
14
+ .index-list summary { display: flex; align-items: center; list-style: none; cursor: pointer; border-radius: .25rem; }
15
+ .index-list summary::-webkit-details-marker { display: none; }
16
+ .index-list summary::before { content: '\25B8'; flex: none; inline-size: 1rem; text-align: center; color: var(--gramlot-navigation-text); opacity: .75; transition: transform .15s; }
17
+ .index-list summary:hover::before { opacity: 1; }
18
+ .index-list details[open] > summary::before { transform: rotate(90deg); }
19
+ .index-list details[open] > summary { margin-block-end: 0; }
20
+ .index-list summary > .index-family { flex: 1; min-inline-size: 0; padding-inline-start: .1rem; }
21
+ .index-footer { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: center; gap: .35rem 1.25rem; padding: .3rem .75rem; border-block-start: 1px solid var(--gramlot-border); background: var(--gramlot-surface-subtle); color: var(--gramlot-ink); font-size: .95rem; }
22
+ .index-keyboard { flex: none; }
23
+ .index-keyboard label { display: flex; align-items: center; gap: .4rem; margin: 0; font-size: inherit; color: inherit; }
24
+ .index-keyboard input { margin: 0; }
25
+ .index-theme { display: flex; align-items: center; gap: .4rem; }
26
+ .index-theme label { margin: 0; font-size: inherit; }
27
+ .index-theme select { inline-size: auto; min-inline-size: 7rem; min-block-size: 26px; padding: .15rem .4rem; font-size: inherit; }
28
+ .index-shell:not(:has(#keyboard-navigation:checked)) :is(.index-list a, .index-list summary, .index-tabs button):focus-visible { outline: none; }
29
+ .index-shell:has(#keyboard-navigation:checked) :is(.index-list a, .index-list summary):focus-visible { outline: 2px solid var(--gramlot-brand-yellow); outline-offset: -2px; }
30
+ .index-main { display: grid; grid-template-rows: auto minmax(0, 1fr); min-inline-size: 0; min-block-size: 0; }
31
+ .index-tabs { display: flex; gap: .15rem; overflow-x: auto; padding: .25rem .4rem 0; border-block-end: 1px solid var(--gramlot-border); background: var(--gramlot-surface-subtle); }
32
+ .index-tabs button { flex: none; white-space: nowrap; min-block-size: 27px; border: 1px solid var(--gramlot-border); border-block-end: 0; border-radius: .25rem .25rem 0 0; background: transparent; color: var(--gramlot-text-secondary); padding: .2rem .55rem; font-size: 1rem; line-height: 1.25; }
33
+ .index-tabs button:hover, .index-tabs button[aria-selected="true"] { background: var(--gramlot-surface); color: var(--gramlot-action); }
34
+ .index-tabs button[aria-selected="true"] { border-block-start: 2px solid var(--gramlot-brand-blue); }
35
+ .index-panels { min-block-size: 0; min-inline-size: 0; overflow: hidden; }
36
+ .index-intro, .index-category { block-size: 100%; overflow: auto; padding: .8rem; background: var(--gramlot-surface); font-size: 1rem; }
37
+ .index-intro > * { max-inline-size: 70ch; }
38
+ .index-intro h2, .index-category h1 { font-size: 1.3rem; margin-block: 0 .5rem; }
39
+ .index-intro p { font-size: 1rem; }
40
+ .index-category table { font-size: 1rem; }
41
+ .index-divider { min-inline-size: 8px; block-size: 100%; cursor: col-resize; touch-action: none; user-select: none; background: var(--gramlot-surface-subtle); border-inline: 1px solid var(--gramlot-border); position: relative; }
42
+ .index-divider::after { content: ''; position: absolute; inline-size: 2px; block-size: 24px; inset-inline-start: calc(50% - 1px); inset-block-start: calc(50% - 12px); border-radius: 2px; background: var(--gramlot-border-control); }
43
+ .index-divider:focus-visible { outline: 2px solid var(--gramlot-focus-ring); outline-offset: -2px; }
44
+ .index-shell[data-resizing="true"] iframe { pointer-events: none; }
45
+
46
+
47
+ .index-panel { height:100%; min-height:0; }
48
+ .index-panel > iframe { width:100%; height:100%; display:block; border:0; }
49
+ .index-install { position:relative; margin:0; padding:.2rem .4rem; }
50
+ .index-install[open] { position:absolute; bottom:0; right:0; z-index:5; max-width:32rem; background:var(--gramlot-surface); padding:.6rem; }
51
+ .index-install p { font-size:inherit; }