100+ copy-paste UI components in plain HTML and CSS: no dependencies, no build step.

0 downloads

dbbasic-web-native/ONE-CODEBASE.md
Download zip
Clone
Clone with git
git clone https://gitstable.com/git/askrobots/dbbasic-web-native.git
HTTPS
https://gitstable.com/git/askrobots/dbbasic-web-native.git
SSH
ssh://git@gitstable.com:2222/askrobots/dbbasic-web-native.git

Cloning needs no sign-in. Pushing over HTTPS asks for your username and an access token. SSH needs your key under SSH keys.

danq9 Add canonical.html v1.0 - The single source of truth for usability standards fb6e650 1 year ago History
ONE-CODEBASE.md · 15.4 KB · 681 lines

One Codebase, All Modalities

The Problem Today

Building a single app feature requires 10+ separate implementations:

1. Web Desktop

<button onclick="save()">Save</button>
// Mouse hover, click events

2. Mobile Web

<button class="touch-optimized" ontouchstart="save()">Save</button>
// Touch events, 44px targets, different gestures

3. iOS Native (Swift/SwiftUI)

Button("Save") {
    save()
}
.buttonStyle(.borderedProminent)

4. Android Native (Kotlin)

Button(onClick = { save() }) {
    Text("Save")
}

5. Tablet/iPad (different layouts)

// Completely different UI for landscape/portrait
// Gesture support, Apple Pencil

6. Voice Assistant (Alexa)

{
  "intents": [{
    "name": "SaveIntent",
    "samples": ["save", "save changes", "save my work"]
  }]
}

7. Voice Assistant (Google Home)

intents:
  - name: save
    trainingPhrases:
      - save
      - save changes

8. AR/VR Interface (Unity/WebXR)

public class SaveButton : MonoBehaviour {
    void OnGaze() { /* highlight */ }
    void OnAirTap() { save(); }
}

9. Accessibility Version

<button
  onclick="save()"
  aria-label="Save changes"
  role="button"
  tabindex="0">
  Save
</button>

10. Watch/Wearable

Button("Save") { save() }
.frame(minWidth: 44, minHeight: 44)

11. TV/Remote Control

// D-pad navigation, back button, voice remote

12. Car Interface (CarPlay/Android Auto)

// Voice-first, minimal visual, steering wheel controls

Total Cost per Feature

PlatformDevelopment TimeMaintenanceTestingTotal
Web Desktop2 daysHigh2 days4 days
Mobile Web2 daysHigh2 days4 days
iOS Native3 daysHigh2 days5 days
Android Native3 daysHigh2 days5 days
Voice (Alexa)2 daysMedium1 day3 days
Voice (Google)2 daysMedium1 day3 days
AR/VR4 daysHigh3 days7 days
Accessibility1 dayHigh2 days3 days
Wearables2 daysMedium1 day3 days
TV/Remote2 daysMedium1 day3 days
Car Interface3 daysHigh2 days5 days
TOTAL26 days19 days45 days

45 days of work for ONE FEATURE across all platforms.

When you change that feature? 45 more days.

When you fix a bug? Test and deploy 11 times.


The Semantic Solution

Write Once:

<semantic-action intent="primary">
  Save Changes
</semantic-action>

Works Everywhere:

Desktop (Screen + Mouse)

  • Renders as styled button
  • Hover: lifts up, shows shadow
  • Click: activates
  • Keyboard: Tab to focus, Enter/Space to activate
  • Screen reader: "Button: Save Changes"

Mobile (Touch)

  • 44px minimum touch target (automatic)
  • Tap: activates
  • Long-press (500ms): shows "inspect" intent
  • Pinch/swipe gestures: recognized
  • Haptic feedback: vibrates on press

Voice (Any assistant)

  • Auto-registered command: "Save Changes"
  • Alternative phrasings: "save", "save my changes"
  • Confirmation: "Changes saved" (speaks back)
  • Context-aware: louder in noisy environments

AR/Spatial

  • Renders as floating button in 3D space
  • Gaze: highlights (dwell time counts as hover)
  • Air tap: activates
  • Hand gesture: pinch to click
  • Voice: "Save Changes"

Accessibility

  • ARIA role: button (automatic)
  • ARIA label: "Save Changes" (from content)
  • Focus indicator: 3px blue outline (automatic)
  • Keyboard navigation: works (automatic)
  • Screen reader: announces intent and state
  • High contrast: meets WCAG AA (enforced)

Car Interface

  • Voice-first: "Save Changes" works
  • Visual: large button if safe to look
  • Steering wheel button: can be mapped
  • Context-aware: hides if driving, voice-only

Wearable

  • Simplified visual (small screen)
  • Voice command works
  • Haptic feedback on press
  • Battery-conscious rendering

TV/Remote

  • D-pad navigation: focuses button
  • Select button: activates
  • Voice remote: "Save Changes"
  • Large text for 10-foot UI

Development Time Comparison

ApproachInitial DevMaintenanceTestingTotal
Traditional (11 platforms)26 daysNightmare19 days45 days
Semantic Components10 minutesEasy1 hour1 day

Savings: 44 days per feature.

For a 100-feature app: 4,400 days saved (12 years!)


What Makes This Work

1. Intent-Based API

You declare WHAT users want to do, not HOW to implement it:

<semantic-action intent="primary">Save</semantic-action>

NOT:

<button class="btn btn-primary" onclick="..." ontouch="..." voice="...">

2. Automatic Modality Detection

The system knows the current context:

window.semanticContext.context = {
  modality: 'voice-screen',  // Voice + screen active
  environment: {
    noiseLevel: 80,           // Loud environment
    viewerCount: 3,           // Multiple people watching
    lighting: 'dim'           // Dark room
  },
  user: {
    isBusy: true,             // User multitasking
    inFocusMode: false        // Not in focus mode
  }
}

Components automatically adapt:

  • Voice feedback gets louder in noise
  • Visual elements get larger in dim light
  • Notifications are suppressed when busy
  • Text is spoken when looking away

3. Built-in Multi-Modal Events

Every component fires intent events, not platform-specific ones:

// ONE event handler for ALL modalities
element.addEventListener('intent', (e) => {
  if (e.detail.type === 'activate') {
    save(); // Triggered by: click, tap, voice, gesture, gaze, etc.
  }
});

NOT:

// 5 different handlers for 5 different inputs
element.addEventListener('click', handleClick);
element.addEventListener('touchend', handleTouch);
element.addEventListener('voiceCommand', handleVoice);
element.addEventListener('gesture', handleGesture);
element.addEventListener('gaze', handleGaze);

4. Shadow DOM Isolation

Styles can't leak or break across platforms:

  • Desktop CSS doesn't break mobile
  • Mobile gestures don't break desktop
  • Future modalities can be added without breaking existing ones

5. Attention Budget System

System automatically decides what to show based on:

  • Screen space available
  • User's cognitive load
  • Environmental context
  • Component urgency
// System decides: show notification or suppress it?
<semantic-feedback
  type="info"
  urgency="low"      // Low priority
  message="Update available">
</semantic-feedback>

If user is busy + screen is full + noise is high = suppressed

If user is idle + screen has space + quiet = shown

6. Machine Learning Adaptation

System learns from user behavior:

  • Which components they engage with
  • What time of day they're most active
  • Which modalities they prefer
  • Their interaction patterns

Gets smarter over time without you doing anything.


Real-World Example: "Save Button"

Traditional Approach

// lib/
//   ├── web/
//   │   ├── desktop/
//   │   │   └── SaveButton.tsx       (300 lines)
//   │   └── mobile/
//   │       └── SaveButton.tsx       (350 lines)
//   ├── native/
//   │   ├── ios/
//   │   │   └── SaveButton.swift    (200 lines)
//   │   └── android/
//   │       └── SaveButton.kt       (200 lines)
//   ├── voice/
//   │   ├── alexa/
//   │   │   └── save-intent.json    (50 lines)
//   │   └── google/
//   │       └── save-intent.yaml    (50 lines)
//   ├── ar/
//   │   └── SaveButton.cs           (400 lines)
//   ├── accessibility/
//   │   └── SaveButton.a11y.tsx     (100 lines)
//   └── tests/
//       └── SaveButton.test.*       (1000+ lines)
//
// TOTAL: ~2,650 lines across 11 files
// Maintenance: Update 11 files when logic changes
// Testing: 11 separate test suites

Semantic Approach

<semantic-action intent="primary">
  Save Changes
</semantic-action>

5 lines of HTML.

  • Works on all 11+ platforms
  • Accessibility built-in
  • Voice commands auto-registered
  • Tests run once
  • Update once, deploys everywhere

When You Add a New Feature

Traditional:

  1. Write web version (2 days)
  2. Write mobile version (2 days)
  3. Write iOS native (3 days)
  4. Write Android native (3 days)
  5. Configure Alexa (2 days)
  6. Configure Google Home (2 days)
  7. Build AR version (4 days)
  8. Add accessibility (1 day)
  9. Build wearable version (2 days)
  10. Build TV version (2 days)
  11. Build car interface (3 days)
  12. Test everything (19 days)

Total: 45 days, 2,000+ lines of code

Semantic:

  1. Write semantic component (10 minutes)
  2. Test once (1 hour)

Total: 1 day, 5 lines of code


When the Platform Changes (e.g., iOS 18)

Traditional:

  • Update iOS Swift code
  • Rewrite broken APIs
  • Re-test everything
  • Hope Android didn't also break
  • Fix accessibility regressions
  • Push update

Time: 1-2 weeks per platform change

Semantic:

  • System updates automatically
  • Components keep working
  • Intent-based API doesn't break
  • Zero code changes needed

Time: 0 days


When You Want to Add a NEW Modality (e.g., Brain-Computer Interface)

Traditional:

  • Hire specialist engineers
  • Build entire new platform
  • Rewrite every feature for BCI
  • Test everything again
  • Maintain forever

Time: 6+ months, millions of dollars

Semantic:

  • Add BCI adapter to framework
  • Map "think activate" → activate intent
  • Done. All existing components work.

Time: 1 week for adapter, then it's free


The Math

For a 100-feature app:

Traditional Multi-Platform:

  • 4,500 days of development (12+ years)
  • 200,000+ lines of code
  • 11 separate codebases to maintain
  • Forever diverging as platforms evolve
  • Accessibility bolted on (if at all)

Semantic Components:

  • 100 days of development (3 months)
  • 5,000 lines of code
  • 1 codebase
  • Automatic platform updates
  • Accessibility built-in

You save 4,400 days (12 years) of work.

You write 40x less code.

You maintain 1 codebase instead of 11.


What This Enables

1. Startups Can Compete

No longer need a 100-person team to build multi-platform apps.

2 developers can build what used to take 20 developers.

2. Accessibility by Default

Can't ship inaccessible apps because it's impossible - the framework enforces it.

3. Future-Proof

When Apple Vision Pro 2 or Meta Quest 5 launches, your app already works on it.

4. Faster Iteration

Change business logic once, deploys everywhere. A/B test across all platforms simultaneously.

5. Better UX

Components adapt to user context automatically. User in a loud coffee shop? Voice feedback is louder. User multitasking? Notifications are suppressed.


The Web Should Have Been This

The original promise of the web: write once, run anywhere.

Reality: Write once, fight browsers forever.

Semantic Components delivers the original promise:

  • Write intent, not implementation
  • Works on any modality
  • Adapts to any context
  • Accessible by default
  • Future-proof API

Code Comparison

Building a form with validation

Traditional (Bootstrap + React + Voice SDK + iOS + Android):

Web (React + Bootstrap):

// SaveForm.tsx - 150 lines
import { useState } from 'react';

function SaveForm() {
  const [email, setEmail] = useState('');
  const [error, setError] = useState('');

  const validate = () => {
    if (!email.includes('@')) {
      setError('Invalid email');
      return false;
    }
    return true;
  };

  return (
    <form onSubmit={handleSubmit}>
      <div className="mb-3">
        <label htmlFor="email" className="form-label">Email</label>
        <input
          type="email"
          className={`form-control ${error ? 'is-invalid' : ''}`}
          id="email"
          value={email}
          onChange={(e) => setEmail(e.target.value)}
        />
        {error && <div className="invalid-feedback">{error}</div>}
      </div>
      <button type="submit" className="btn btn-primary" disabled={!email}>
        Save
      </button>
    </form>
  );
}

iOS (Swift):

// SaveForm.swift - 100 lines
struct SaveForm: View {
    @State private var email = ""
    @State private var error = ""

    var body: some View {
        Form {
            TextField("Email", text: $email)
                .textContentType(.emailAddress)
                .autocapitalization(.none)

            if !error.isEmpty {
                Text(error).foregroundColor(.red)
            }

            Button("Save") {
                if !email.contains("@") {
                    error = "Invalid email"
                }
            }
            .disabled(email.isEmpty)
        }
    }
}

Android (Kotlin):

// SaveForm.kt - 120 lines
@Composable
fun SaveForm() {
    var email by remember { mutableStateOf("") }
    var error by remember { mutableStateOf("") }

    Column {
        TextField(
            value = email,
            onValueChange = { email = it },
            label = { Text("Email") },
            isError = error.isNotEmpty()
        )

        if (error.isNotEmpty()) {
            Text(error, color = Color.Red)
        }

        Button(
            onClick = {
                if (!email.contains("@")) {
                    error = "Invalid email"
                }
            },
            enabled = email.isNotEmpty()
        ) {
            Text("Save")
        }
    }
}

Voice (Alexa):

// intents.json - 30 lines
{
  "interactionModel": {
    "languageModel": {
      "intents": [
        {
          "name": "SaveEmailIntent",
          "slots": [{
            "name": "email",
            "type": "AMAZON.EmailAddress"
          }],
          "samples": [
            "save email {email}",
            "my email is {email}"
          ]
        }
      ]
    }
  }
}

Total: 400+ lines across 4 platforms (not counting tests)


Semantic Components:

<form>
  <semantic-input
    label="Email"
    type="email"
    placeholder="you@example.com"
    required
    error="Invalid email">
  </semantic-input>

  <semantic-action intent="primary">
    Save
  </semantic-action>
</form>

Total: 12 lines. Works on all platforms.

  • Web desktop: ✓
  • Mobile: ✓
  • iOS: ✓
  • Android: ✓
  • Voice (all assistants): ✓ (auto-registered)
  • AR/VR: ✓
  • Accessibility: ✓
  • TV/Remote: ✓
  • Wearables: ✓
  • Car: ✓
  • Future devices: ✓

This Changes Everything

Instead of:

"We can't afford to build a mobile app AND a web app AND accessibility."

You get:

"We wrote it once. It works everywhere."

Instead of:

"Voice support will take 3 more months."

You get:

"Voice commands work automatically."

Instead of:

"We'll add accessibility later." (never happens)

You get:

"Accessibility is built-in, can't be disabled."

The Vision

A world where:

  • Developers write intent, not implementation
  • Users interact however they want (touch, voice, gesture, etc.)
  • Devices all work, no separate "apps" needed
  • Accessibility is automatic, not optional
  • New modalities just work with existing code

This is what the web should have been.

Now it can be.