Skip to content

Latest commit

 

History

History
219 lines (175 loc) · 10.4 KB

development.md

File metadata and controls

219 lines (175 loc) · 10.4 KB

Developing with Displacer

This guide assumes commands run from the repository root. Start with the README for dependencies and build commands, and the specification index for design assets.

Web components

The root libdisplacer-ts import registers the component and prefab custom elements. Use it in a browser; the root entry accesses DOM APIs and is not an SSR entry point. The libdisplacer-ts/tokens entry provides design values without registering elements. The libdisplacer-ts/components entry registers components without the prefab import.

The library build cleans dist/, runs TypeScript checking and Vite bundling, then writes JavaScript and declarations. Build it before installing or rebuilding the showcase's local file dependency. npm run test:editors builds the package and runs Node tests for the optional editors' Unicode ranges, stale analysis, query generation, and graph validation. There is no Storybook configuration or general browser unit-test suite; check interactive behavior in the showcase.

Component attributes, properties, and events vary; the source is the reference for the currently implemented API. The component specifications include design targets that may be ahead of the implementation. Accessibility and keyboard behavior should be checked in the consuming application.

Optional browser editors

Import libdisplacer-ts/editors to register ds-code-editor and ds-node-editor without the rest of the component library. This optional entry includes CodeMirror; ordinary component imports do not. The build also emits the standalone dist/displacer-editors.js ES module and its accompanying displacer-editors.LICENSE.txt for applications that serve assets directly. Complete notices are embedded in the module and reproduced from the installed, locked runtime packages during each build.

The editor specification defines the public properties, events, UTF-8 byte offset analysis adapter, and query graph. The source editor highlights Matrix/Ny and provides local snippets; compiler-backed completion, diagnostics, and signatures require a host provider. No editor evaluates source or performs deployment. The node editor's visual forms generate read-only Concord sources and typed schema 2 filter/sort/limit pipelines; a host validates, authorizes, and compiles the graph separately. A required Limit step selects rows only after source matching, filters, and stable sorting. Labeled request/records ports form one validated path, rendered in edge order.

Schema 1 trigger → query → display graphs remain supported and are never implicitly upgraded. Their missing take means 25. An application offers an explicit server-validated upgrade, then supplies the returned graph through setValue and updates generated source. defaultQueryGraph() still returns schema 1; defaultPipelineGraph() returns a schema 2 source with skip 0/take 25. Adding pipeline steps rewires a linear path in phase order; manual connections, removal, and Undo/Redo retain validation feedback for incomplete graphs.

Run the showcase and open editors.html to exercise both controls. Its optional analysis fixture is explicitly synthetic, operates entirely in memory, and tests adapter UI rather than a compiler. Supply a native child textarea for server-rendered code-editor forms so editing/submission still work before the module loads. Avoid loading preferred fonts remotely when the application's CSP or offline requirements call for system/self-hosted font stacks.

Applying a web theme

import { displacerDark, themeRegistry } from 'libdisplacer-ts'

themeRegistry.register({
  ...displacerDark,
  fonts: { body: 'system-ui, sans-serif', mono: 'monospace' },
})
themeRegistry.apply('displacer-dark')

applyTheme sets document-root CSS custom properties, a data-ds-theme attribute, and the ds-active-theme local-storage value. It does not automatically restore that saved choice at startup. Presets can include remote Google Fonts stylesheets in fonts.imports; applying an unmodified preset with those entries loads them. Omit imports and supply system or self-hosted font families to avoid that request. The registry starts empty; register presets before using themeRegistry.apply(id).

The Observatory preset is exported as observatory, with the registry ID observatory. It combines parchment surfaces with blue research accents.

Execute theme

Execute is the opt-in corporate engineering theme. It is exported from libdisplacer-ts and libdisplacer-ts/theme as execute, with registry ID execute; libdisplacer-ts/tokens exports its palette as colors.execute. Register and apply it explicitly:

import { execute, themeRegistry } from 'libdisplacer-ts/theme'

// Supply these fonts locally to avoid the preset's Google Fonts request.
themeRegistry.register({
  ...execute,
  fonts: {
    display: '"Space Grotesk", Arial, sans-serif',
    heading: '"Space Grotesk", Arial, sans-serif',
    body: '"Space Grotesk", Arial, sans-serif',
    control: '"IBM Plex Mono", ui-monospace, monospace',
    mono: '"IBM Plex Mono", ui-monospace, monospace',
  },
})
themeRegistry.apply('execute')

Use Space Grotesk at weights 400 and 500 for content and headings; use IBM Plex Mono at the same weights for technical labels, controls, and metadata. Naming a font does not provide its files. Supply licensed font files or use the fallback stacks. Applying the unmodified execute preset instead includes the optional Google Fonts stylesheet. Native C and Rust palette selection changes colors; applications supply fonts and apply the type and layout guidance themselves.

For native C, include <displacer/core.h> and call ds_theme_apply(&DS_THEME_EXECUTE). For Rust, call context.set_theme(BuiltinTheme::Execute) on an acquired Displacer context. These choices preserve Clay as the initial native theme and Rust default.

The manifest supplies pill button radii, square form controls and cards, and 1px borders to the basic web components that consume shape. Other components and native applications apply the theme's geometry in their own layouts.

The Execute specification distinguishes the corporate site's structural grid and decorative rules from control boundaries, and lists the adjusted surface, text, and semantic colors used by application UI.

Optional developer console integration

ds-dev-console is a UI prefab, not a backend server. It defaults to the same-origin /api base for its console and agent integrations. Those actions require an application-provided implementation; the showcase needs none of them. Configure the apiBase JavaScript property or the lowercase apibase attribute. System health polling is disabled until the monitorUrl property (or lowercase monitorurl attribute) is set. For example:

<ds-dev-console apibase="/api" monitorurl="/monitor"></ds-dev-console>

The console then reads <monitorUrl>/health while its system view is active. Server-side authorization and command validation belong in the application hosting these optional endpoints.

Native C integration

Public headers are under lib/libdisplacer-native/include/displacer/. The library has no windowing backend. Use ds_canvas_pixels, ds_canvas_width, and ds_canvas_height to present the software canvas using the application's chosen platform layer.

#include <displacer/vis.h>

int main(void) {
    ds_canvas *canvas = ds_canvas_create(320, 200);
    if (!canvas) return 1;
    ds_canvas_clear(canvas, ds_colorf_hex(0x141414));
    ds_canvas_fill_rect(canvas, 20, 20, 120, 40, ds_colorf_hex(0xf2661a));
    ds_canvas_destroy(canvas);
    return 0;
}

After building, CMake can install headers and the library to a chosen prefix:

cmake --install lib/libdisplacer-native/build --prefix ./build/install

The default install also places Displacer's MIT license and the bundled font parser's complete upstream notices under share/licenses/displacer/. If a package selects individual CMake install components, include displacer-licenses alongside the library and headers.

The native showcase expects the library in lib/libdisplacer-native/build. Its optional font argument and DISPLACER_FONT environment variable accept a font chosen by the user. Without either, bitmap text remains available.

Rust integration and font ownership

The Rust build compiles the native canvas, core theme, and font sources using the cc build dependency; keep the sibling native library and root VERSION file when using the crate as a path or Git dependency. It does not wrap the widget tree or provide an event loop.

Displacer::acquire() claims the single process-wide theme/default-font owner. Canvas and FontFace values remain on one thread. Owned font faces support multiple sizes and text roles without replacing the compatibility font. pixels_argb8888() exposes packed 0xAARRGGBB values; native byte order depends on the host, so choose the correct pixel format in the presentation layer.

Both file-based and byte-based TrueType loaders require trusted, valid fonts. Rust marks those operations unsafe because stb_truetype does not validate all table offsets. The native loaders retain their own font-data copy. The bundled bitmap font needs no external font file.

Validation

Run the builds from the README for the affected implementation. The native CTest suite compares optimized drawing against a reference renderer. Rust tests cover canvas behavior, themes, fonts, and ownership constraints. A web build checks types and bundling; use the showcase in a browser to inspect visual, keyboard, and focus behavior. A successful build does not establish full cross-platform or cross-implementation parity.

Execute component preview

Run the web showcase and open execute.html to compare Execute with Displacer Dark on the same buttons, inputs, cards, and color roles. Execute is also listed in the main showcase's theme selector.

Web manifests can opt into shape overrides (buttonRadius, controlRadius, cardRadius, borderWidth), a fonts.control stack, and colors.fgInverse for labels on filled controls. The basic button, input, select, textarea, and card components consume the corresponding properties. Applying another theme clears optional font, inverse-color, and shape overrides that it omits. Other components retain their own geometry; this is not a global CSS reset.