@gramlot/gramlot 0.2.16 → 0.2.18

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.
Files changed (47) hide show
  1. package/assets/branding/app-icon.png +0 -0
  2. package/dist/gramlot.js +1413 -235
  3. package/dist/gramlot.min.js +74 -17
  4. package/package.json +9 -5
  5. package/src/binding/ask-dialog.js +108 -0
  6. package/src/binding/providers.js +41 -6
  7. package/src/binding/remote.js +19 -20
  8. package/src/binding/runtime.js +38 -2
  9. package/src/builder/gramlot-builder.js +21 -3
  10. package/src/builder/source.js +18 -5
  11. package/src/builder/webcomponent.json +51 -0
  12. package/src/frame-messages.js +177 -0
  13. package/src/gramlot.d.ts +14 -0
  14. package/src/gramlot.js +9 -1
  15. package/src/handlers/rpc-handler.js +2 -0
  16. package/src/handlers/source-handler.js +1 -0
  17. package/src/handlers/subscriptions-handler.js +103 -0
  18. package/src/index-page-runtime.d.ts +11 -0
  19. package/src/index-page-runtime.js +287 -0
  20. package/src/index-page-styles.js +2 -0
  21. package/src/index-theme.js +5 -0
  22. package/src/index.d.ts +4 -1
  23. package/src/index.js +3 -0
  24. package/src/inout.js +3 -1
  25. package/src/references.d.ts +5 -0
  26. package/src/references.js +23 -1
  27. package/src/renderer/attributes.js +14 -3
  28. package/src/renderer/gramlot-html-renderer.js +9 -2
  29. package/src/renderer/gramlot-renderer.js +5 -1
  30. package/src/renderer/gramlot-svg-renderer.js +2 -1
  31. package/src/server/conformance.js +22 -2
  32. package/src/server/gramlot-server.d.ts +1 -0
  33. package/src/server/gramlot-server.js +12 -0
  34. package/src/server/index-page.d.ts +14 -0
  35. package/src/server/index-page.js +102 -0
  36. package/src/server/page-base.js +88 -0
  37. package/src/server/page.d.ts +8 -2
  38. package/src/server/page.js +3 -76
  39. package/src/view/button.js +17 -3
  40. package/src/view/html.js +4 -3
  41. package/src/webcomponent.js +13 -0
  42. package/themes/gramlot-base/README.md +8 -0
  43. package/themes/gramlot-compact/README.md +49 -0
  44. package/themes/gramlot-compact/theme.css +57 -0
  45. package/themes/gramlot-index/theme.css +51 -0
  46. package/tools/gramlot-tools-inspector.js +1733 -0
  47. package/tools/inspector-agent.js +252 -0
@@ -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';
@@ -9,6 +9,7 @@
9
9
  * native. A closed NodeBinding does nothing (R12).
10
10
  */
11
11
 
12
+ import {AskDialog} from '../binding/ask-dialog.js';
12
13
  import {XHTML_NS} from '../renderer/attributes.js';
13
14
 
14
15
  export class ButtonBinding {
@@ -102,9 +103,22 @@ export class ButtonBinding {
102
103
  const provider = this.binding.runtime.bindingFor(this.controllers[0])?.providers[0];
103
104
  provider?.invoke({kind: 'click', event, counter});
104
105
  } else if (mechanism === 'action') {
105
- const [, attrs] = node.builder.runtimeValues(node);
106
- const values = {...attrs, event, _counter: counter, modifiers};
107
- this.binding.runtime.inlineCompiler.compile(node, 'action', node.getAttr('action'), Object.keys(values))(values);
106
+ const read = () => {
107
+ const [, attrs] = node.builder.runtimeValues(node);
108
+ const authored = Object.fromEntries(Object.entries(attrs).filter(([name]) => name !== 'ask'));
109
+ return {...this.binding.runtime.renderer.references.resolveArguments(authored), event, _counter: counter, modifiers};
110
+ };
111
+ const execute = result => {
112
+ if (this.binding.closed || result === null) return;
113
+ const values = {...read(), ...result};
114
+ if (result) values._askResult = result;
115
+ this.binding.runtime.inlineCompiler.compile(node, 'action', node.getAttr('action'), Object.keys(values))(values);
116
+ };
117
+ const ask = node.getAttr('ask');
118
+ if (ask && AskDialog.required(this.binding, ask, read(), 'ask')) {
119
+ return AskDialog.show(this.binding, ask, read()).then(execute);
120
+ }
121
+ execute(undefined);
108
122
  } else {
109
123
  const attributes = {modifier: modifiers, _counter: counter};
110
124
  // `fire` wins over the `fire_*` of the same button, as the legacy chain.
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
  });
@@ -60,7 +61,7 @@ export class HtmlElement {
60
61
  throw new TypeError('HTML text must be scalar');
61
62
  }
62
63
  for (const [key, value] of Object.entries(node.attr)) {
63
- if (this.metadataAttributes.has(key)) continue;
64
+ if (this.metadataAttributes.has(key) || ['ask', '_ask'].includes(key) || (value && typeof value === 'object' && Object.hasOwn(value, '$gramlotRef'))) continue;
64
65
  if (value != null && !['string', 'number', 'boolean'].includes(typeof value)) {
65
66
  throw new TypeError(`HTML attribute ${key} must be scalar`);
66
67
  }
@@ -116,7 +117,7 @@ export class HtmlElement {
116
117
  // The browser reads `sandbox` when `src` or `srcdoc` starts a navigation: `sandbox` is written first.
117
118
  keys.sort((a, b) => (b === 'sandbox') - (a === 'sandbox'));
118
119
  for (const key of keys) {
119
- if (this.metadataAttributes.has(key) || (controlled && key === 'value')) continue;
120
+ if (this.metadataAttributes.has(key) || ['ask', '_ask'].includes(key) || (controlled && key === 'value')) continue;
120
121
  const value = attrs[key];
121
122
  const attrName = key;
122
123
  const propertyName = domPropertyName(attrName);
@@ -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; }