@jam-overture/loom 0.1.0
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.
- package/LICENSE +21 -0
- package/README.md +743 -0
- package/dist/catalogue.d.ts +70 -0
- package/dist/catalogue.js +88 -0
- package/dist/cli/args.d.ts +17 -0
- package/dist/cli/args.js +83 -0
- package/dist/cli/filesystem.d.ts +15 -0
- package/dist/cli/filesystem.js +31 -0
- package/dist/cli/index.d.ts +12 -0
- package/dist/cli/index.js +12 -0
- package/dist/cli/main.d.ts +3 -0
- package/dist/cli/main.js +30 -0
- package/dist/cli/namespace.d.ts +40 -0
- package/dist/cli/namespace.js +40 -0
- package/dist/cli/plan.d.ts +84 -0
- package/dist/cli/plan.js +113 -0
- package/dist/cli/run.d.ts +17 -0
- package/dist/cli/run.js +75 -0
- package/dist/cli/templates.d.ts +43 -0
- package/dist/cli/templates.js +134 -0
- package/dist/closed-set.d.ts +34 -0
- package/dist/closed-set.js +34 -0
- package/dist/data/adapter.d.ts +123 -0
- package/dist/data/adapter.js +91 -0
- package/dist/data/binding.d.ts +48 -0
- package/dist/data/binding.js +39 -0
- package/dist/data/catalogue.d.ts +26 -0
- package/dist/data/catalogue.js +6 -0
- package/dist/data/index.d.ts +14 -0
- package/dist/data/index.js +14 -0
- package/dist/data/plan.d.ts +58 -0
- package/dist/data/plan.js +0 -0
- package/dist/data/resolution.d.ts +91 -0
- package/dist/data/resolution.js +96 -0
- package/dist/data/resolve.d.ts +46 -0
- package/dist/data/resolve.js +37 -0
- package/dist/data/source.d.ts +40 -0
- package/dist/data/source.js +45 -0
- package/dist/deadline.d.ts +57 -0
- package/dist/deadline.js +78 -0
- package/dist/frame/catalogue.d.ts +24 -0
- package/dist/frame/catalogue.js +5 -0
- package/dist/frame/index.d.ts +12 -0
- package/dist/frame/index.js +12 -0
- package/dist/frame/origin.d.ts +87 -0
- package/dist/frame/origin.js +114 -0
- package/dist/frame/resolution.d.ts +85 -0
- package/dist/frame/resolution.js +79 -0
- package/dist/grammar.d.ts +26 -0
- package/dist/grammar.js +28 -0
- package/dist/ids.d.ts +57 -0
- package/dist/ids.js +104 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +26 -0
- package/dist/interactivity.d.ts +50 -0
- package/dist/interactivity.js +22 -0
- package/dist/interpretation/anthropic.d.ts +22 -0
- package/dist/interpretation/anthropic.js +76 -0
- package/dist/interpretation/client.d.ts +83 -0
- package/dist/interpretation/client.js +2 -0
- package/dist/interpretation/draft.d.ts +234 -0
- package/dist/interpretation/draft.js +84 -0
- package/dist/interpretation/index.d.ts +15 -0
- package/dist/interpretation/index.js +15 -0
- package/dist/interpretation/interpreter.d.ts +62 -0
- package/dist/interpretation/interpreter.js +151 -0
- package/dist/interpretation/materialize.d.ts +42 -0
- package/dist/interpretation/materialize.js +107 -0
- package/dist/interpretation/prompt.d.ts +229 -0
- package/dist/interpretation/prompt.js +285 -0
- package/dist/interpretation/render.d.ts +76 -0
- package/dist/interpretation/render.js +272 -0
- package/dist/interpretation/schema.d.ts +49 -0
- package/dist/interpretation/schema.js +131 -0
- package/dist/json.d.ts +35 -0
- package/dist/json.js +11 -0
- package/dist/paging.d.ts +60 -0
- package/dist/paging.js +49 -0
- package/dist/primitive-type.d.ts +32 -0
- package/dist/primitive-type.js +39 -0
- package/dist/render/addressing.d.ts +59 -0
- package/dist/render/addressing.js +60 -0
- package/dist/render/anchor.d.ts +105 -0
- package/dist/render/anchor.js +84 -0
- package/dist/render/behaviour-adjust.d.ts +62 -0
- package/dist/render/behaviour-adjust.js +78 -0
- package/dist/render/behaviour-copy.d.ts +53 -0
- package/dist/render/behaviour-copy.js +75 -0
- package/dist/render/behaviour-disclose.d.ts +74 -0
- package/dist/render/behaviour-disclose.js +77 -0
- package/dist/render/behaviour-present.d.ts +123 -0
- package/dist/render/behaviour-present.js +173 -0
- package/dist/render/behaviour.d.ts +243 -0
- package/dist/render/behaviour.js +284 -0
- package/dist/render/control.d.ts +81 -0
- package/dist/render/control.js +80 -0
- package/dist/render/decorative.d.ts +62 -0
- package/dist/render/decorative.js +2 -0
- package/dist/render/diagnostics.d.ts +260 -0
- package/dist/render/diagnostics.js +61 -0
- package/dist/render/disclosed.d.ts +37 -0
- package/dist/render/disclosed.js +37 -0
- package/dist/render/editable.d.ts +34 -0
- package/dist/render/editable.js +35 -0
- package/dist/render/frame.d.ts +42 -0
- package/dist/render/frame.js +31 -0
- package/dist/render/index.d.ts +35 -0
- package/dist/render/index.js +35 -0
- package/dist/render/inline-variables.d.ts +77 -0
- package/dist/render/inline-variables.js +220 -0
- package/dist/render/presented.d.ts +82 -0
- package/dist/render/presented.js +82 -0
- package/dist/render/primitive.d.ts +228 -0
- package/dist/render/primitive.js +36 -0
- package/dist/render/props.d.ts +48 -0
- package/dist/render/props.js +2 -0
- package/dist/render/reads.d.ts +73 -0
- package/dist/render/reads.js +45 -0
- package/dist/render/render.d.ts +164 -0
- package/dist/render/render.js +571 -0
- package/dist/render/request.d.ts +111 -0
- package/dist/render/request.js +60 -0
- package/dist/render/text.d.ts +91 -0
- package/dist/render/text.js +44 -0
- package/dist/render/theme.d.ts +61 -0
- package/dist/render/theme.js +52 -0
- package/dist/reserved-props.d.ts +35 -0
- package/dist/reserved-props.js +45 -0
- package/dist/result.d.ts +27 -0
- package/dist/result.js +30 -0
- package/dist/role.d.ts +71 -0
- package/dist/role.js +22 -0
- package/dist/runtime/analysis.d.ts +149 -0
- package/dist/runtime/analysis.js +187 -0
- package/dist/runtime/assessment.d.ts +35 -0
- package/dist/runtime/assessment.js +13 -0
- package/dist/runtime/disposition.d.ts +102 -0
- package/dist/runtime/disposition.js +59 -0
- package/dist/runtime/events.d.ts +187 -0
- package/dist/runtime/events.js +7 -0
- package/dist/runtime/gate.d.ts +43 -0
- package/dist/runtime/gate.js +169 -0
- package/dist/runtime/index.d.ts +27 -0
- package/dist/runtime/index.js +27 -0
- package/dist/runtime/intent.d.ts +60 -0
- package/dist/runtime/intent.js +36 -0
- package/dist/runtime/interpreter.d.ts +117 -0
- package/dist/runtime/interpreter.js +46 -0
- package/dist/runtime/inverse-interpreter.d.ts +90 -0
- package/dist/runtime/inverse-interpreter.js +56 -0
- package/dist/runtime/inverse.d.ts +87 -0
- package/dist/runtime/inverse.js +48 -0
- package/dist/runtime/narration.d.ts +24 -0
- package/dist/runtime/narration.js +36 -0
- package/dist/runtime/nesting.d.ts +31 -0
- package/dist/runtime/nesting.js +46 -0
- package/dist/runtime/pipeline.d.ts +124 -0
- package/dist/runtime/pipeline.js +178 -0
- package/dist/runtime/policy-fingerprint.d.ts +29 -0
- package/dist/runtime/policy-fingerprint.js +119 -0
- package/dist/runtime/policy-source.d.ts +42 -0
- package/dist/runtime/policy-source.js +8 -0
- package/dist/runtime/policy.d.ts +156 -0
- package/dist/runtime/policy.js +107 -0
- package/dist/runtime/proposal.d.ts +423 -0
- package/dist/runtime/proposal.js +109 -0
- package/dist/runtime/redirection.d.ts +53 -0
- package/dist/runtime/redirection.js +38 -0
- package/dist/runtime/repointing.d.ts +71 -0
- package/dist/runtime/repointing.js +0 -0
- package/dist/runtime/reversibility.d.ts +36 -0
- package/dist/runtime/reversibility.js +39 -0
- package/dist/runtime/stake-level.d.ts +33 -0
- package/dist/runtime/stake-level.js +58 -0
- package/dist/runtime/stakes.d.ts +47 -0
- package/dist/runtime/stakes.js +305 -0
- package/dist/runtime/vocabulary.d.ts +122 -0
- package/dist/runtime/vocabulary.js +87 -0
- package/dist/sdk/audit.d.ts +195 -0
- package/dist/sdk/audit.js +128 -0
- package/dist/sdk/catalogue.d.ts +37 -0
- package/dist/sdk/catalogue.js +16 -0
- package/dist/sdk/conformance.d.ts +342 -0
- package/dist/sdk/conformance.js +494 -0
- package/dist/sdk/copy.d.ts +105 -0
- package/dist/sdk/copy.js +90 -0
- package/dist/sdk/definition.d.ts +242 -0
- package/dist/sdk/definition.js +64 -0
- package/dist/sdk/index.d.ts +19 -0
- package/dist/sdk/index.js +19 -0
- package/dist/sdk/interactivity.d.ts +29 -0
- package/dist/sdk/interactivity.js +34 -0
- package/dist/sdk/pairings.d.ts +124 -0
- package/dist/sdk/pairings.js +81 -0
- package/dist/sdk/registry.d.ts +162 -0
- package/dist/sdk/registry.js +329 -0
- package/dist/sdk/selection.d.ts +46 -0
- package/dist/sdk/selection.js +24 -0
- package/dist/sdk/text.d.ts +100 -0
- package/dist/sdk/text.js +105 -0
- package/dist/sdk/vocabulary.d.ts +39 -0
- package/dist/sdk/vocabulary.js +36 -0
- package/dist/signals/broadcast.d.ts +134 -0
- package/dist/signals/broadcast.js +451 -0
- package/dist/signals/collect.d.ts +184 -0
- package/dist/signals/collect.js +196 -0
- package/dist/signals/deliver.d.ts +64 -0
- package/dist/signals/deliver.js +85 -0
- package/dist/signals/fold.d.ts +112 -0
- package/dist/signals/fold.js +76 -0
- package/dist/signals/index.d.ts +31 -0
- package/dist/signals/index.js +31 -0
- package/dist/signals/ingest.d.ts +51 -0
- package/dist/signals/ingest.js +70 -0
- package/dist/signals/intake.d.ts +149 -0
- package/dist/signals/intake.js +154 -0
- package/dist/signals/journal.d.ts +94 -0
- package/dist/signals/journal.js +11 -0
- package/dist/signals/kinds.d.ts +22 -0
- package/dist/signals/kinds.js +22 -0
- package/dist/signals/ledger.d.ts +46 -0
- package/dist/signals/ledger.js +81 -0
- package/dist/signals/memory.d.ts +17 -0
- package/dist/signals/memory.js +99 -0
- package/dist/signals/migrate.d.ts +27 -0
- package/dist/signals/migrate.js +78 -0
- package/dist/signals/postgres.d.ts +7 -0
- package/dist/signals/postgres.js +295 -0
- package/dist/signals/rollup.d.ts +142 -0
- package/dist/signals/rollup.js +0 -0
- package/dist/signals/schema.d.ts +534 -0
- package/dist/signals/schema.js +92 -0
- package/dist/signals/signal.d.ts +381 -0
- package/dist/signals/signal.js +150 -0
- package/dist/signals/tally.d.ts +70 -0
- package/dist/signals/tally.js +2 -0
- package/dist/signals/view.d.ts +51 -0
- package/dist/signals/view.js +54 -0
- package/dist/store/attribution.d.ts +125 -0
- package/dist/store/attribution.js +116 -0
- package/dist/store/database.d.ts +14 -0
- package/dist/store/database.js +2 -0
- package/dist/store/driver.d.ts +29 -0
- package/dist/store/driver.js +39 -0
- package/dist/store/errors.d.ts +56 -0
- package/dist/store/errors.js +37 -0
- package/dist/store/index.d.ts +16 -0
- package/dist/store/index.js +16 -0
- package/dist/store/memory.d.ts +3 -0
- package/dist/store/memory.js +115 -0
- package/dist/store/migrate.d.ts +54 -0
- package/dist/store/migrate.js +122 -0
- package/dist/store/postgres-holds.d.ts +4 -0
- package/dist/store/postgres-holds.js +192 -0
- package/dist/store/postgres.d.ts +8 -0
- package/dist/store/postgres.js +262 -0
- package/dist/store/replay.d.ts +94 -0
- package/dist/store/replay.js +82 -0
- package/dist/store/revert.d.ts +116 -0
- package/dist/store/revert.js +243 -0
- package/dist/store/schema.d.ts +371 -0
- package/dist/store/schema.js +78 -0
- package/dist/store/source.d.ts +23 -0
- package/dist/store/source.js +37 -0
- package/dist/store/store.d.ts +231 -0
- package/dist/store/store.js +52 -0
- package/dist/store/undone.d.ts +18 -0
- package/dist/store/undone.js +89 -0
- package/dist/submit/catalogue.d.ts +20 -0
- package/dist/submit/catalogue.js +5 -0
- package/dist/submit/declaration.d.ts +39 -0
- package/dist/submit/declaration.js +30 -0
- package/dist/submit/endpoint.d.ts +131 -0
- package/dist/submit/endpoint.js +160 -0
- package/dist/submit/index.d.ts +13 -0
- package/dist/submit/index.js +13 -0
- package/dist/submit/plan.d.ts +49 -0
- package/dist/submit/plan.js +47 -0
- package/dist/submit/resolution.d.ts +61 -0
- package/dist/submit/resolution.js +64 -0
- package/dist/submit/resolve.d.ts +45 -0
- package/dist/submit/resolve.js +36 -0
- package/dist/telemetry/calibration.d.ts +132 -0
- package/dist/telemetry/calibration.js +151 -0
- package/dist/telemetry/episode.d.ts +140 -0
- package/dist/telemetry/episode.js +272 -0
- package/dist/telemetry/event.d.ts +2310 -0
- package/dist/telemetry/event.js +405 -0
- package/dist/telemetry/index.d.ts +15 -0
- package/dist/telemetry/index.js +15 -0
- package/dist/telemetry/journal.d.ts +116 -0
- package/dist/telemetry/journal.js +11 -0
- package/dist/telemetry/memory.d.ts +24 -0
- package/dist/telemetry/memory.js +75 -0
- package/dist/telemetry/migrate.d.ts +26 -0
- package/dist/telemetry/migrate.js +40 -0
- package/dist/telemetry/postgres.d.ts +6 -0
- package/dist/telemetry/postgres.js +139 -0
- package/dist/telemetry/retention.d.ts +131 -0
- package/dist/telemetry/retention.js +217 -0
- package/dist/telemetry/schema.d.ts +113 -0
- package/dist/telemetry/schema.js +33 -0
- package/dist/telemetry/sink.d.ts +42 -0
- package/dist/telemetry/sink.js +61 -0
- package/dist/testing/contracts.d.ts +34 -0
- package/dist/testing/contracts.js +34 -0
- package/dist/testing/definitions.d.ts +15 -0
- package/dist/testing/definitions.js +48 -0
- package/dist/testing/doubles.d.ts +94 -0
- package/dist/testing/doubles.js +141 -0
- package/dist/testing/episode-harness.d.ts +49 -0
- package/dist/testing/episode-harness.js +65 -0
- package/dist/testing/filesystem.d.ts +17 -0
- package/dist/testing/filesystem.js +17 -0
- package/dist/testing/fixtures.d.ts +57 -0
- package/dist/testing/fixtures.js +84 -0
- package/dist/testing/hold-contract.d.ts +19 -0
- package/dist/testing/hold-contract.js +374 -0
- package/dist/testing/index.d.ts +41 -0
- package/dist/testing/index.js +41 -0
- package/dist/testing/journal-contract.d.ts +17 -0
- package/dist/testing/journal-contract.js +353 -0
- package/dist/testing/model-replies.d.ts +34 -0
- package/dist/testing/model-replies.js +101 -0
- package/dist/testing/primitives.d.ts +7 -0
- package/dist/testing/primitives.js +29 -0
- package/dist/testing/reader-signal-contract.d.ts +38 -0
- package/dist/testing/reader-signal-contract.js +318 -0
- package/dist/testing/row-security.d.ts +17 -0
- package/dist/testing/row-security.js +21 -0
- package/dist/testing/store-contract.d.ts +25 -0
- package/dist/testing/store-contract.js +500 -0
- package/dist/theme/apply.d.ts +17 -0
- package/dist/theme/apply.js +60 -0
- package/dist/theme/contrast.d.ts +197 -0
- package/dist/theme/contrast.js +259 -0
- package/dist/theme/derive.d.ts +77 -0
- package/dist/theme/derive.js +167 -0
- package/dist/theme/faces.d.ts +73 -0
- package/dist/theme/faces.js +119 -0
- package/dist/theme/font-packs.d.ts +25 -0
- package/dist/theme/font-packs.js +257 -0
- package/dist/theme/index.d.ts +20 -0
- package/dist/theme/index.js +20 -0
- package/dist/theme/lab.d.ts +30 -0
- package/dist/theme/lab.js +46 -0
- package/dist/theme/library.d.ts +114 -0
- package/dist/theme/library.js +300 -0
- package/dist/theme/measure.d.ts +144 -0
- package/dist/theme/measure.js +145 -0
- package/dist/theme/palettes.d.ts +64 -0
- package/dist/theme/palettes.js +497 -0
- package/dist/theme/registry.d.ts +59 -0
- package/dist/theme/registry.js +60 -0
- package/dist/theme/separation.d.ts +177 -0
- package/dist/theme/separation.js +203 -0
- package/dist/theme/style-presets.d.ts +60 -0
- package/dist/theme/style-presets.js +124 -0
- package/dist/theme/theme.d.ts +253 -0
- package/dist/theme/theme.js +171 -0
- package/dist/tree/apply.d.ts +16 -0
- package/dist/tree/apply.js +104 -0
- package/dist/tree/builders.d.ts +19 -0
- package/dist/tree/builders.js +20 -0
- package/dist/tree/compare.d.ts +68 -0
- package/dist/tree/compare.js +75 -0
- package/dist/tree/configuration.d.ts +25 -0
- package/dist/tree/configuration.js +108 -0
- package/dist/tree/delta.d.ts +288 -0
- package/dist/tree/delta.js +88 -0
- package/dist/tree/errors.d.ts +69 -0
- package/dist/tree/errors.js +34 -0
- package/dist/tree/identity.d.ts +117 -0
- package/dist/tree/identity.js +145 -0
- package/dist/tree/index.d.ts +21 -0
- package/dist/tree/index.js +21 -0
- package/dist/tree/inverse.d.ts +24 -0
- package/dist/tree/inverse.js +112 -0
- package/dist/tree/mutation.d.ts +18 -0
- package/dist/tree/mutation.js +49 -0
- package/dist/tree/naming.d.ts +4 -0
- package/dist/tree/naming.js +35 -0
- package/dist/tree/navigation.d.ts +38 -0
- package/dist/tree/navigation.js +83 -0
- package/dist/tree/node.d.ts +103 -0
- package/dist/tree/node.js +46 -0
- package/dist/tree/outline.d.ts +28 -0
- package/dist/tree/outline.js +10 -0
- package/dist/tree/tree.d.ts +83 -0
- package/dist/tree/tree.js +62 -0
- package/dist/write/commit.d.ts +124 -0
- package/dist/write/commit.js +234 -0
- package/dist/write/held.d.ts +674 -0
- package/dist/write/held.js +185 -0
- package/dist/write/index.d.ts +11 -0
- package/dist/write/index.js +11 -0
- package/dist/write/liveness.d.ts +132 -0
- package/dist/write/liveness.js +91 -0
- package/dist/write/revert.d.ts +79 -0
- package/dist/write/revert.js +134 -0
- package/package.json +160 -0
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Every palette declares every slot. Normalised on purpose: a tree themed with
|
|
4
|
+
* one palette can be re-themed with any other, because there is no slot a
|
|
5
|
+
* primitive might read that some palette leaves undefined.
|
|
6
|
+
*/
|
|
7
|
+
export declare const paletteSlotSchema: z.ZodEnum<["bg-canvas", "bg-surface", "bg-surface-muted", "bg-overlay", "fg-default", "fg-muted", "fg-subtle", "fg-on-accent", "accent", "accent-strong", "accent-subtle", "brand-secondary", "brand-secondary-strong", "border-default", "border-strong", "border-subtle", "border-accent"]>;
|
|
8
|
+
export type PaletteSlot = z.infer<typeof paletteSlotSchema>;
|
|
9
|
+
export declare const PALETTE_SLOTS: ["bg-canvas", "bg-surface", "bg-surface-muted", "bg-overlay", "fg-default", "fg-muted", "fg-subtle", "fg-on-accent", "accent", "accent-strong", "accent-subtle", "brand-secondary", "brand-secondary-strong", "border-default", "border-strong", "border-subtle", "border-accent"];
|
|
10
|
+
/**
|
|
11
|
+
* The type ramp and the spacing scale have a fixed number of steps, for exactly
|
|
12
|
+
* the reason every palette declares every slot: a primitive reading
|
|
13
|
+
* `--loom-spacing-7` must get a length from any registered preset, or a
|
|
14
|
+
* re-theme silently unstyles it. A ramp whose length varied would make "renders
|
|
15
|
+
* under both palettes" a property of which two you happened to pick.
|
|
16
|
+
*/
|
|
17
|
+
export declare const RAMP_STEPS = 8;
|
|
18
|
+
export declare const themeIdSchema: z.ZodBranded<z.ZodString, "ThemeId">;
|
|
19
|
+
export type ThemeId = z.infer<typeof themeIdSchema>;
|
|
20
|
+
export declare const paletteSchema: z.ZodObject<{
|
|
21
|
+
id: z.ZodBranded<z.ZodString, "ThemeId">;
|
|
22
|
+
name: z.ZodString;
|
|
23
|
+
description: z.ZodString;
|
|
24
|
+
slots: z.ZodEffects<z.ZodRecord<z.ZodEnum<["bg-canvas", "bg-surface", "bg-surface-muted", "bg-overlay", "fg-default", "fg-muted", "fg-subtle", "fg-on-accent", "accent", "accent-strong", "accent-subtle", "brand-secondary", "brand-secondary-strong", "border-default", "border-strong", "border-subtle", "border-accent"]>, z.ZodString>, Partial<Record<"bg-canvas" | "bg-surface" | "bg-surface-muted" | "bg-overlay" | "fg-default" | "fg-muted" | "fg-subtle" | "fg-on-accent" | "accent" | "accent-strong" | "accent-subtle" | "brand-secondary" | "brand-secondary-strong" | "border-default" | "border-strong" | "border-subtle" | "border-accent", string>>, Partial<Record<"bg-canvas" | "bg-surface" | "bg-surface-muted" | "bg-overlay" | "fg-default" | "fg-muted" | "fg-subtle" | "fg-on-accent" | "accent" | "accent-strong" | "accent-subtle" | "brand-secondary" | "brand-secondary-strong" | "border-default" | "border-strong" | "border-subtle" | "border-accent", string>>>;
|
|
25
|
+
}, "strip", z.ZodTypeAny, {
|
|
26
|
+
name: string;
|
|
27
|
+
id: string & z.BRAND<"ThemeId">;
|
|
28
|
+
description: string;
|
|
29
|
+
slots: Partial<Record<"bg-canvas" | "bg-surface" | "bg-surface-muted" | "bg-overlay" | "fg-default" | "fg-muted" | "fg-subtle" | "fg-on-accent" | "accent" | "accent-strong" | "accent-subtle" | "brand-secondary" | "brand-secondary-strong" | "border-default" | "border-strong" | "border-subtle" | "border-accent", string>>;
|
|
30
|
+
}, {
|
|
31
|
+
name: string;
|
|
32
|
+
id: string;
|
|
33
|
+
description: string;
|
|
34
|
+
slots: Partial<Record<"bg-canvas" | "bg-surface" | "bg-surface-muted" | "bg-overlay" | "fg-default" | "fg-muted" | "fg-subtle" | "fg-on-accent" | "accent" | "accent-strong" | "accent-subtle" | "brand-secondary" | "brand-secondary-strong" | "border-default" | "border-strong" | "border-subtle" | "border-accent", string>>;
|
|
35
|
+
}>;
|
|
36
|
+
export type Palette = z.infer<typeof paletteSchema>;
|
|
37
|
+
export declare const fontFaceSchema: z.ZodObject<{
|
|
38
|
+
/** The family this face provides, as the stack asks for it and without quotes. */
|
|
39
|
+
family: z.ZodString;
|
|
40
|
+
weight: z.ZodNumber;
|
|
41
|
+
style: z.ZodDefault<z.ZodEnum<["normal", "italic"]>>;
|
|
42
|
+
/** Where the face data is: a URL, or a path the host knows how to resolve. */
|
|
43
|
+
source: z.ZodString;
|
|
44
|
+
format: z.ZodOptional<z.ZodEnum<["woff2", "woff", "truetype", "opentype"]>>;
|
|
45
|
+
}, "strip", z.ZodTypeAny, {
|
|
46
|
+
source: string;
|
|
47
|
+
family: string;
|
|
48
|
+
weight: number;
|
|
49
|
+
style: "normal" | "italic";
|
|
50
|
+
format?: "woff2" | "woff" | "truetype" | "opentype" | undefined;
|
|
51
|
+
}, {
|
|
52
|
+
source: string;
|
|
53
|
+
family: string;
|
|
54
|
+
weight: number;
|
|
55
|
+
style?: "normal" | "italic" | undefined;
|
|
56
|
+
format?: "woff2" | "woff" | "truetype" | "opentype" | undefined;
|
|
57
|
+
}>;
|
|
58
|
+
export type FontFace = z.infer<typeof fontFaceSchema>;
|
|
59
|
+
/**
|
|
60
|
+
* A pack declares a face for each role the library actually reads, and no
|
|
61
|
+
* others. There were three roles here and a primitive read two of them: an
|
|
62
|
+
* `accentFamily` was emitted as `--loom-accent-family` and referenced by
|
|
63
|
+
* nothing, while `loom.code` and `loom.kbd` needed a monospace face the
|
|
64
|
+
* vocabulary had no word for. A variable a host can set and no primitive
|
|
65
|
+
* consults is worse than an absent one — it looks like a seam and behaves like
|
|
66
|
+
* a comment (0085).
|
|
67
|
+
*
|
|
68
|
+
* `monoFamily` is optional where the other two are required, and the asymmetry
|
|
69
|
+
* is deliberate rather than an oversight. A palette declares every slot because
|
|
70
|
+
* an undeclared colour has no universal fallback; an undeclared *face* has one,
|
|
71
|
+
* because every operating system ships a monospace. `tokens.ts` asks for
|
|
72
|
+
* `var(--loom-mono-family, <system stack>)`, so a pack with no opinion about
|
|
73
|
+
* code costs a reader nothing, and a pack built around a particular mono gets
|
|
74
|
+
* to say so.
|
|
75
|
+
*/
|
|
76
|
+
export declare const fontPackSchema: z.ZodObject<{
|
|
77
|
+
id: z.ZodBranded<z.ZodString, "ThemeId">;
|
|
78
|
+
name: z.ZodString;
|
|
79
|
+
description: z.ZodString;
|
|
80
|
+
headingFamily: z.ZodString;
|
|
81
|
+
bodyFamily: z.ZodString;
|
|
82
|
+
/** Emitted as `--loom-mono-family` when declared, and omitted when not. */
|
|
83
|
+
monoFamily: z.ZodOptional<z.ZodString>;
|
|
84
|
+
headingWeight: z.ZodNumber;
|
|
85
|
+
bodyWeight: z.ZodNumber;
|
|
86
|
+
/** Typographic ramp in px, smallest first. Emitted as `--loom-scale-1…8`. */
|
|
87
|
+
scaleRamp: z.ZodArray<z.ZodNumber, "many">;
|
|
88
|
+
/**
|
|
89
|
+
* Where the families above are, for a reader that cannot look one up.
|
|
90
|
+
*
|
|
91
|
+
* Optional, and absent on every pack the starter library ships: those name
|
|
92
|
+
* only faces an operating system already has, or say in their description
|
|
93
|
+
* that a host must serve them, and neither case wants this file holding an
|
|
94
|
+
* address on somebody else's CDN. It is here for a host registering its own
|
|
95
|
+
* pack, and for a renderer that draws text without a browser.
|
|
96
|
+
*/
|
|
97
|
+
faces: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
98
|
+
/** The family this face provides, as the stack asks for it and without quotes. */
|
|
99
|
+
family: z.ZodString;
|
|
100
|
+
weight: z.ZodNumber;
|
|
101
|
+
style: z.ZodDefault<z.ZodEnum<["normal", "italic"]>>;
|
|
102
|
+
/** Where the face data is: a URL, or a path the host knows how to resolve. */
|
|
103
|
+
source: z.ZodString;
|
|
104
|
+
format: z.ZodOptional<z.ZodEnum<["woff2", "woff", "truetype", "opentype"]>>;
|
|
105
|
+
}, "strip", z.ZodTypeAny, {
|
|
106
|
+
source: string;
|
|
107
|
+
family: string;
|
|
108
|
+
weight: number;
|
|
109
|
+
style: "normal" | "italic";
|
|
110
|
+
format?: "woff2" | "woff" | "truetype" | "opentype" | undefined;
|
|
111
|
+
}, {
|
|
112
|
+
source: string;
|
|
113
|
+
family: string;
|
|
114
|
+
weight: number;
|
|
115
|
+
style?: "normal" | "italic" | undefined;
|
|
116
|
+
format?: "woff2" | "woff" | "truetype" | "opentype" | undefined;
|
|
117
|
+
}>, "many">>;
|
|
118
|
+
}, "strip", z.ZodTypeAny, {
|
|
119
|
+
name: string;
|
|
120
|
+
id: string & z.BRAND<"ThemeId">;
|
|
121
|
+
description: string;
|
|
122
|
+
headingFamily: string;
|
|
123
|
+
bodyFamily: string;
|
|
124
|
+
headingWeight: number;
|
|
125
|
+
bodyWeight: number;
|
|
126
|
+
scaleRamp: number[];
|
|
127
|
+
monoFamily?: string | undefined;
|
|
128
|
+
faces?: {
|
|
129
|
+
source: string;
|
|
130
|
+
family: string;
|
|
131
|
+
weight: number;
|
|
132
|
+
style: "normal" | "italic";
|
|
133
|
+
format?: "woff2" | "woff" | "truetype" | "opentype" | undefined;
|
|
134
|
+
}[] | undefined;
|
|
135
|
+
}, {
|
|
136
|
+
name: string;
|
|
137
|
+
id: string;
|
|
138
|
+
description: string;
|
|
139
|
+
headingFamily: string;
|
|
140
|
+
bodyFamily: string;
|
|
141
|
+
headingWeight: number;
|
|
142
|
+
bodyWeight: number;
|
|
143
|
+
scaleRamp: number[];
|
|
144
|
+
monoFamily?: string | undefined;
|
|
145
|
+
faces?: {
|
|
146
|
+
source: string;
|
|
147
|
+
family: string;
|
|
148
|
+
weight: number;
|
|
149
|
+
style?: "normal" | "italic" | undefined;
|
|
150
|
+
format?: "woff2" | "woff" | "truetype" | "opentype" | undefined;
|
|
151
|
+
}[] | undefined;
|
|
152
|
+
}>;
|
|
153
|
+
export type FontPack = z.infer<typeof fontPackSchema>;
|
|
154
|
+
export declare const stylePresetSchema: z.ZodObject<{
|
|
155
|
+
id: z.ZodBranded<z.ZodString, "ThemeId">;
|
|
156
|
+
name: z.ZodString;
|
|
157
|
+
description: z.ZodString;
|
|
158
|
+
radii: z.ZodObject<{
|
|
159
|
+
sm: z.ZodNumber;
|
|
160
|
+
md: z.ZodNumber;
|
|
161
|
+
lg: z.ZodNumber;
|
|
162
|
+
full: z.ZodNumber;
|
|
163
|
+
}, "strip", z.ZodTypeAny, {
|
|
164
|
+
sm: number;
|
|
165
|
+
md: number;
|
|
166
|
+
lg: number;
|
|
167
|
+
full: number;
|
|
168
|
+
}, {
|
|
169
|
+
sm: number;
|
|
170
|
+
md: number;
|
|
171
|
+
lg: number;
|
|
172
|
+
full: number;
|
|
173
|
+
}>;
|
|
174
|
+
/** Spacing steps in px, smallest first. Emitted as `--loom-spacing-1…8`. */
|
|
175
|
+
spacingScale: z.ZodArray<z.ZodNumber, "many">;
|
|
176
|
+
motion: z.ZodObject<{
|
|
177
|
+
fast: z.ZodNumber;
|
|
178
|
+
medium: z.ZodNumber;
|
|
179
|
+
slow: z.ZodNumber;
|
|
180
|
+
}, "strip", z.ZodTypeAny, {
|
|
181
|
+
medium: number;
|
|
182
|
+
fast: number;
|
|
183
|
+
slow: number;
|
|
184
|
+
}, {
|
|
185
|
+
medium: number;
|
|
186
|
+
fast: number;
|
|
187
|
+
slow: number;
|
|
188
|
+
}>;
|
|
189
|
+
density: z.ZodEnum<["compact", "comfortable", "spacious"]>;
|
|
190
|
+
}, "strip", z.ZodTypeAny, {
|
|
191
|
+
name: string;
|
|
192
|
+
id: string & z.BRAND<"ThemeId">;
|
|
193
|
+
description: string;
|
|
194
|
+
radii: {
|
|
195
|
+
sm: number;
|
|
196
|
+
md: number;
|
|
197
|
+
lg: number;
|
|
198
|
+
full: number;
|
|
199
|
+
};
|
|
200
|
+
spacingScale: number[];
|
|
201
|
+
motion: {
|
|
202
|
+
medium: number;
|
|
203
|
+
fast: number;
|
|
204
|
+
slow: number;
|
|
205
|
+
};
|
|
206
|
+
density: "compact" | "comfortable" | "spacious";
|
|
207
|
+
}, {
|
|
208
|
+
name: string;
|
|
209
|
+
id: string;
|
|
210
|
+
description: string;
|
|
211
|
+
radii: {
|
|
212
|
+
sm: number;
|
|
213
|
+
md: number;
|
|
214
|
+
lg: number;
|
|
215
|
+
full: number;
|
|
216
|
+
};
|
|
217
|
+
spacingScale: number[];
|
|
218
|
+
motion: {
|
|
219
|
+
medium: number;
|
|
220
|
+
fast: number;
|
|
221
|
+
slow: number;
|
|
222
|
+
};
|
|
223
|
+
density: "compact" | "comfortable" | "spacious";
|
|
224
|
+
}>;
|
|
225
|
+
export type StylePreset = z.infer<typeof stylePresetSchema>;
|
|
226
|
+
/**
|
|
227
|
+
* What a tree carries: three ids, not three documents.
|
|
228
|
+
*
|
|
229
|
+
* This is what makes a theme change a `configure` operation on the root like
|
|
230
|
+
* any other — small enough for a model to emit, bounded by the registry, and
|
|
231
|
+
* gated, attributed and reversed by exactly the machinery §1–§2 already built
|
|
232
|
+
* (0048).
|
|
233
|
+
*/
|
|
234
|
+
export declare const themeSelectionSchema: z.ZodObject<{
|
|
235
|
+
palette: z.ZodBranded<z.ZodString, "ThemeId">;
|
|
236
|
+
fontPack: z.ZodBranded<z.ZodString, "ThemeId">;
|
|
237
|
+
stylePreset: z.ZodBranded<z.ZodString, "ThemeId">;
|
|
238
|
+
}, "strip", z.ZodTypeAny, {
|
|
239
|
+
palette: string & z.BRAND<"ThemeId">;
|
|
240
|
+
fontPack: string & z.BRAND<"ThemeId">;
|
|
241
|
+
stylePreset: string & z.BRAND<"ThemeId">;
|
|
242
|
+
}, {
|
|
243
|
+
palette: string;
|
|
244
|
+
fontPack: string;
|
|
245
|
+
stylePreset: string;
|
|
246
|
+
}>;
|
|
247
|
+
export type ThemeSelection = z.infer<typeof themeSelectionSchema>;
|
|
248
|
+
export type ResolvedTheme = {
|
|
249
|
+
readonly palette: Palette;
|
|
250
|
+
readonly fontPack: FontPack;
|
|
251
|
+
readonly stylePreset: StylePreset;
|
|
252
|
+
};
|
|
253
|
+
//# sourceMappingURL=theme.d.ts.map
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* The theme vocabulary, ported from the Hermes registry (§4b).
|
|
4
|
+
*
|
|
5
|
+
* Three orthogonal pieces — colour, type, and shape — because they vary
|
|
6
|
+
* independently in practice: a host swaps the palette for a dark mode without
|
|
7
|
+
* touching the typographic ramp, and swaps the ramp for a rebrand without
|
|
8
|
+
* touching the radii.
|
|
9
|
+
*
|
|
10
|
+
* Every piece is *registered and addressed by id*, never inlined. That is the
|
|
11
|
+
* same bargain the primitive registry makes: a bounded vocabulary a model may
|
|
12
|
+
* choose from, so "make it warmer" resolves to a named palette a human approved
|
|
13
|
+
* rather than to seventeen colours a model invented. The alternative — letting a
|
|
14
|
+
* proposal carry raw hex — would put an unbounded value space inside the one
|
|
15
|
+
* part of the system that exists to bound what AI may produce.
|
|
16
|
+
*/
|
|
17
|
+
const colourSchema = z
|
|
18
|
+
.string()
|
|
19
|
+
.regex(/^(#[0-9a-fA-F]{3,8}|rgba?\(.+\)|hsla?\(.+\)|[a-z]+)$/);
|
|
20
|
+
/**
|
|
21
|
+
* Every palette declares every slot. Normalised on purpose: a tree themed with
|
|
22
|
+
* one palette can be re-themed with any other, because there is no slot a
|
|
23
|
+
* primitive might read that some palette leaves undefined.
|
|
24
|
+
*/
|
|
25
|
+
export const paletteSlotSchema = z.enum([
|
|
26
|
+
// Surface tier, bottom-up
|
|
27
|
+
"bg-canvas",
|
|
28
|
+
"bg-surface",
|
|
29
|
+
"bg-surface-muted",
|
|
30
|
+
"bg-overlay",
|
|
31
|
+
// Foreground tier
|
|
32
|
+
"fg-default",
|
|
33
|
+
"fg-muted",
|
|
34
|
+
"fg-subtle",
|
|
35
|
+
"fg-on-accent",
|
|
36
|
+
// Accent tier
|
|
37
|
+
"accent",
|
|
38
|
+
"accent-strong",
|
|
39
|
+
"accent-subtle",
|
|
40
|
+
// Brand secondary — reserved even for single-accent palettes, which mirror
|
|
41
|
+
// their accent into it, so every palette has the same shape.
|
|
42
|
+
"brand-secondary",
|
|
43
|
+
"brand-secondary-strong",
|
|
44
|
+
// Border tier
|
|
45
|
+
"border-default",
|
|
46
|
+
"border-strong",
|
|
47
|
+
"border-subtle",
|
|
48
|
+
"border-accent",
|
|
49
|
+
]);
|
|
50
|
+
export const PALETTE_SLOTS = paletteSlotSchema.options;
|
|
51
|
+
/**
|
|
52
|
+
* The type ramp and the spacing scale have a fixed number of steps, for exactly
|
|
53
|
+
* the reason every palette declares every slot: a primitive reading
|
|
54
|
+
* `--loom-spacing-7` must get a length from any registered preset, or a
|
|
55
|
+
* re-theme silently unstyles it. A ramp whose length varied would make "renders
|
|
56
|
+
* under both palettes" a property of which two you happened to pick.
|
|
57
|
+
*/
|
|
58
|
+
export const RAMP_STEPS = 8;
|
|
59
|
+
export const themeIdSchema = z
|
|
60
|
+
.string()
|
|
61
|
+
.regex(/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/)
|
|
62
|
+
.brand();
|
|
63
|
+
export const paletteSchema = z.object({
|
|
64
|
+
id: themeIdSchema,
|
|
65
|
+
name: z.string().min(1),
|
|
66
|
+
description: z.string().min(1),
|
|
67
|
+
slots: z.record(paletteSlotSchema, colourSchema).refine((slots) => PALETTE_SLOTS.every((slot) => slots[slot] !== undefined), { message: "a palette must declare every slot" }),
|
|
68
|
+
});
|
|
69
|
+
/**
|
|
70
|
+
* Where one face is, for a reader that cannot look a family name up.
|
|
71
|
+
*
|
|
72
|
+
* A family stack is an instruction to something that already has fonts. A
|
|
73
|
+
* browser resolves `Fraunces` against the faces the machine holds and the ones
|
|
74
|
+
* the host's stylesheet loaded; anything drawing text itself resolves it against
|
|
75
|
+
* nothing, falls back silently, and looks entirely deliberate while doing it.
|
|
76
|
+
*
|
|
77
|
+
* So a pack may say where a face is as well as what to ask for. The value is an
|
|
78
|
+
* address and the runtime never dereferences one — a host or a renderer fetches
|
|
79
|
+
* it, on its own schedule and against its own allowlist. Everything that reads
|
|
80
|
+
* this is in `faces.ts`.
|
|
81
|
+
*
|
|
82
|
+
* The character class is narrow because both fields are interpolated into CSS
|
|
83
|
+
* by `fontFaceRules`, and a family or a URL carrying a quote or a brace would
|
|
84
|
+
* be closing a declaration rather than naming a font.
|
|
85
|
+
*/
|
|
86
|
+
const cssSafe = z
|
|
87
|
+
.string()
|
|
88
|
+
.min(1)
|
|
89
|
+
.regex(/^[^"'{};\r\n]+$/, "may not contain quotes, braces, semicolons or newlines");
|
|
90
|
+
export const fontFaceSchema = z.object({
|
|
91
|
+
/** The family this face provides, as the stack asks for it and without quotes. */
|
|
92
|
+
family: cssSafe,
|
|
93
|
+
weight: z.number().int().positive(),
|
|
94
|
+
style: z.enum(["normal", "italic"]).default("normal"),
|
|
95
|
+
/** Where the face data is: a URL, or a path the host knows how to resolve. */
|
|
96
|
+
source: cssSafe,
|
|
97
|
+
format: z.enum(["woff2", "woff", "truetype", "opentype"]).optional(),
|
|
98
|
+
});
|
|
99
|
+
/**
|
|
100
|
+
* A pack declares a face for each role the library actually reads, and no
|
|
101
|
+
* others. There were three roles here and a primitive read two of them: an
|
|
102
|
+
* `accentFamily` was emitted as `--loom-accent-family` and referenced by
|
|
103
|
+
* nothing, while `loom.code` and `loom.kbd` needed a monospace face the
|
|
104
|
+
* vocabulary had no word for. A variable a host can set and no primitive
|
|
105
|
+
* consults is worse than an absent one — it looks like a seam and behaves like
|
|
106
|
+
* a comment (0085).
|
|
107
|
+
*
|
|
108
|
+
* `monoFamily` is optional where the other two are required, and the asymmetry
|
|
109
|
+
* is deliberate rather than an oversight. A palette declares every slot because
|
|
110
|
+
* an undeclared colour has no universal fallback; an undeclared *face* has one,
|
|
111
|
+
* because every operating system ships a monospace. `tokens.ts` asks for
|
|
112
|
+
* `var(--loom-mono-family, <system stack>)`, so a pack with no opinion about
|
|
113
|
+
* code costs a reader nothing, and a pack built around a particular mono gets
|
|
114
|
+
* to say so.
|
|
115
|
+
*/
|
|
116
|
+
export const fontPackSchema = z.object({
|
|
117
|
+
id: themeIdSchema,
|
|
118
|
+
name: z.string().min(1),
|
|
119
|
+
description: z.string().min(1),
|
|
120
|
+
headingFamily: z.string().min(1),
|
|
121
|
+
bodyFamily: z.string().min(1),
|
|
122
|
+
/** Emitted as `--loom-mono-family` when declared, and omitted when not. */
|
|
123
|
+
monoFamily: z.string().min(1).optional(),
|
|
124
|
+
headingWeight: z.number().int().positive(),
|
|
125
|
+
bodyWeight: z.number().int().positive(),
|
|
126
|
+
/** Typographic ramp in px, smallest first. Emitted as `--loom-scale-1…8`. */
|
|
127
|
+
scaleRamp: z.array(z.number().positive()).length(RAMP_STEPS),
|
|
128
|
+
/**
|
|
129
|
+
* Where the families above are, for a reader that cannot look one up.
|
|
130
|
+
*
|
|
131
|
+
* Optional, and absent on every pack the starter library ships: those name
|
|
132
|
+
* only faces an operating system already has, or say in their description
|
|
133
|
+
* that a host must serve them, and neither case wants this file holding an
|
|
134
|
+
* address on somebody else's CDN. It is here for a host registering its own
|
|
135
|
+
* pack, and for a renderer that draws text without a browser.
|
|
136
|
+
*/
|
|
137
|
+
faces: z.array(fontFaceSchema).optional(),
|
|
138
|
+
});
|
|
139
|
+
export const stylePresetSchema = z.object({
|
|
140
|
+
id: themeIdSchema,
|
|
141
|
+
name: z.string().min(1),
|
|
142
|
+
description: z.string().min(1),
|
|
143
|
+
radii: z.object({
|
|
144
|
+
sm: z.number().nonnegative(),
|
|
145
|
+
md: z.number().nonnegative(),
|
|
146
|
+
lg: z.number().nonnegative(),
|
|
147
|
+
full: z.number().nonnegative(),
|
|
148
|
+
}),
|
|
149
|
+
/** Spacing steps in px, smallest first. Emitted as `--loom-spacing-1…8`. */
|
|
150
|
+
spacingScale: z.array(z.number().nonnegative()).length(RAMP_STEPS),
|
|
151
|
+
motion: z.object({
|
|
152
|
+
fast: z.number().nonnegative(),
|
|
153
|
+
medium: z.number().nonnegative(),
|
|
154
|
+
slow: z.number().nonnegative(),
|
|
155
|
+
}),
|
|
156
|
+
density: z.enum(["compact", "comfortable", "spacious"]),
|
|
157
|
+
});
|
|
158
|
+
/**
|
|
159
|
+
* What a tree carries: three ids, not three documents.
|
|
160
|
+
*
|
|
161
|
+
* This is what makes a theme change a `configure` operation on the root like
|
|
162
|
+
* any other — small enough for a model to emit, bounded by the registry, and
|
|
163
|
+
* gated, attributed and reversed by exactly the machinery §1–§2 already built
|
|
164
|
+
* (0048).
|
|
165
|
+
*/
|
|
166
|
+
export const themeSelectionSchema = z.object({
|
|
167
|
+
palette: themeIdSchema,
|
|
168
|
+
fontPack: themeIdSchema,
|
|
169
|
+
stylePreset: themeIdSchema,
|
|
170
|
+
});
|
|
171
|
+
//# sourceMappingURL=theme.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type Result } from "../result.js";
|
|
2
|
+
import type { TreeDelta, TreeOperation } from "./delta.js";
|
|
3
|
+
import type { TreeError } from "./errors.js";
|
|
4
|
+
import type { LoomNode } from "./node.js";
|
|
5
|
+
import { type LoomTree } from "./tree.js";
|
|
6
|
+
/**
|
|
7
|
+
* One operation against one tree, with no delta around it.
|
|
8
|
+
*
|
|
9
|
+
* An operation applied on its own has retired nothing, so the recycling rule
|
|
10
|
+
* cannot fire here — it is a rule about what a *delta* may do to an id it
|
|
11
|
+
* removed. `invertOperations` walks operations this way, and inverting a delta
|
|
12
|
+
* must never be stricter than applying one.
|
|
13
|
+
*/
|
|
14
|
+
export declare const applyOperation: (root: LoomNode, operation: TreeOperation) => Result<LoomNode, TreeError>;
|
|
15
|
+
export declare const applyDelta: (tree: LoomTree, delta: TreeDelta) => Result<LoomTree, TreeError>;
|
|
16
|
+
//# sourceMappingURL=apply.d.ts.map
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { assertNever, err, flatMapResult, mapResult, ok, reduceResult } from "../result.js";
|
|
2
|
+
import { configureNode } from "./configuration.js";
|
|
3
|
+
import { nodeFingerprint } from "./identity.js";
|
|
4
|
+
import { detachNode, insertChild, replaceNode } from "./mutation.js";
|
|
5
|
+
import { collectNodeIds, duplicateNodeIds, isDescendantOf, walkTree } from "./navigation.js";
|
|
6
|
+
import { withRoot } from "./tree.js";
|
|
7
|
+
const withRetired = (applied, retired) => mapResult(applied, (root) => ({ root, retired }));
|
|
8
|
+
const rejectIdCollisions = (root, incoming) => {
|
|
9
|
+
const [internalDuplicate] = duplicateNodeIds(incoming);
|
|
10
|
+
if (internalDuplicate)
|
|
11
|
+
return err({ code: "duplicate-node-id", nodeId: internalDuplicate });
|
|
12
|
+
const existing = new Set(collectNodeIds(root));
|
|
13
|
+
const collision = collectNodeIds(incoming).find((nodeId) => existing.has(nodeId));
|
|
14
|
+
if (collision)
|
|
15
|
+
return err({ code: "duplicate-node-id", nodeId: collision });
|
|
16
|
+
return ok(incoming);
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* An id this delta retired may come back, but only as the node that left. That
|
|
20
|
+
* is what an undo of a `remove` does — it re-inserts the exact subtree — and
|
|
21
|
+
* refusing it would refuse taking a removal back.
|
|
22
|
+
*/
|
|
23
|
+
const rejectRecycling = (retired, incoming) => {
|
|
24
|
+
const recycled = Array.from(walkTree(incoming)).find((node) => {
|
|
25
|
+
const departed = retired.get(node.id);
|
|
26
|
+
return departed !== undefined && departed !== nodeFingerprint(node);
|
|
27
|
+
});
|
|
28
|
+
return recycled ? err({ code: "recycled-node-id", nodeId: recycled.id }) : ok(incoming);
|
|
29
|
+
};
|
|
30
|
+
const applyInsert = (state, operation) => withRetired(flatMapResult(rejectRecycling(state.retired, operation.node), (node) => flatMapResult(rejectIdCollisions(state.root, node), (checked) => insertChild(state.root, operation.parentId, operation.index, checked))), state.retired);
|
|
31
|
+
const retire = (retired, detached) => new Map([
|
|
32
|
+
...retired,
|
|
33
|
+
...Array.from(walkTree(detached), (node) => [node.id, nodeFingerprint(node)]),
|
|
34
|
+
]);
|
|
35
|
+
const applyRemove = (state, operation) => mapResult(detachNode(state.root, operation.nodeId), (detached) => ({
|
|
36
|
+
root: detached.root,
|
|
37
|
+
retired: retire(state.retired, detached.detached),
|
|
38
|
+
}));
|
|
39
|
+
/**
|
|
40
|
+
* A move is a detach followed by an insert, so `index` is interpreted against
|
|
41
|
+
* the child list the node has already left. Reordering within one parent is
|
|
42
|
+
* therefore expressed in post-removal coordinates: moving the first of three
|
|
43
|
+
* siblings to the end is index 2, not 3.
|
|
44
|
+
*/
|
|
45
|
+
const applyMove = (root, operation) => {
|
|
46
|
+
if (root.id === operation.nodeId) {
|
|
47
|
+
return err({ code: "root-not-detachable", nodeId: operation.nodeId });
|
|
48
|
+
}
|
|
49
|
+
if (operation.nodeId === operation.parentId) {
|
|
50
|
+
return err({ code: "move-into-self", nodeId: operation.nodeId });
|
|
51
|
+
}
|
|
52
|
+
if (isDescendantOf(root, operation.nodeId, operation.parentId)) {
|
|
53
|
+
return err({
|
|
54
|
+
code: "move-into-descendant",
|
|
55
|
+
nodeId: operation.nodeId,
|
|
56
|
+
parentId: operation.parentId,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
return flatMapResult(detachNode(root, operation.nodeId), (detached) => insertChild(detached.root, operation.parentId, operation.index, detached.detached));
|
|
60
|
+
};
|
|
61
|
+
const applyConfigure = (root, operation) => replaceNode(root, operation.nodeId, (node) => configureNode(node, { set: operation.set, unset: operation.unset }));
|
|
62
|
+
const advance = (state, operation) => {
|
|
63
|
+
switch (operation.op) {
|
|
64
|
+
case "insert":
|
|
65
|
+
return applyInsert(state, operation);
|
|
66
|
+
case "remove":
|
|
67
|
+
return applyRemove(state, operation);
|
|
68
|
+
case "move":
|
|
69
|
+
return withRetired(applyMove(state.root, operation), state.retired);
|
|
70
|
+
case "configure":
|
|
71
|
+
return withRetired(applyConfigure(state.root, operation), state.retired);
|
|
72
|
+
default:
|
|
73
|
+
return assertNever(operation, "advance");
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
const NOTHING_RETIRED = new Map();
|
|
77
|
+
/**
|
|
78
|
+
* One operation against one tree, with no delta around it.
|
|
79
|
+
*
|
|
80
|
+
* An operation applied on its own has retired nothing, so the recycling rule
|
|
81
|
+
* cannot fire here — it is a rule about what a *delta* may do to an id it
|
|
82
|
+
* removed. `invertOperations` walks operations this way, and inverting a delta
|
|
83
|
+
* must never be stricter than applying one.
|
|
84
|
+
*/
|
|
85
|
+
export const applyOperation = (root, operation) => mapResult(advance({ root, retired: NOTHING_RETIRED }, operation), (state) => state.root);
|
|
86
|
+
/**
|
|
87
|
+
* The root cannot be removed or moved, and `configure` never changes a node's
|
|
88
|
+
* kind, so this narrowing always succeeds. It is checked rather than cast so
|
|
89
|
+
* that a future operation cannot quietly violate the invariant.
|
|
90
|
+
*/
|
|
91
|
+
const requireElementRoot = (node) => node.kind === "element"
|
|
92
|
+
? ok(node)
|
|
93
|
+
: err({ code: "schema-violation", path: "root", detail: `root became a ${node.kind} node` });
|
|
94
|
+
export const applyDelta = (tree, delta) => {
|
|
95
|
+
if (delta.treeId !== tree.treeId) {
|
|
96
|
+
return err({ code: "tree-mismatch", expected: delta.treeId, actual: tree.treeId });
|
|
97
|
+
}
|
|
98
|
+
if (delta.baseRevision !== tree.revision) {
|
|
99
|
+
return err({ code: "revision-mismatch", expected: delta.baseRevision, actual: tree.revision });
|
|
100
|
+
}
|
|
101
|
+
const applied = reduceResult(delta.operations, { root: tree.root, retired: NOTHING_RETIRED }, advance);
|
|
102
|
+
return mapResult(flatMapResult(mapResult(applied, (state) => state.root), requireElementRoot), (root) => withRoot(tree, root));
|
|
103
|
+
};
|
|
104
|
+
//# sourceMappingURL=apply.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { IdFactory } from "../ids.js";
|
|
2
|
+
import type { JsonObject } from "../json.js";
|
|
3
|
+
import type { ElementNode, LoomNode, SlotNode, TextNode } from "./node.js";
|
|
4
|
+
/**
|
|
5
|
+
* Construction helpers for trusted, in-process callers — tests, fixtures, and
|
|
6
|
+
* the SDK's scaffolding. They parse their string arguments eagerly and throw on
|
|
7
|
+
* a malformed literal, because a bad primitive type here is a typo in source
|
|
8
|
+
* rather than untrusted input. Data arriving from the wire or from AI goes
|
|
9
|
+
* through `parseTree` / `parseDelta`, which never throw.
|
|
10
|
+
*/
|
|
11
|
+
export type ElementSpec = {
|
|
12
|
+
readonly type: string;
|
|
13
|
+
readonly props?: JsonObject;
|
|
14
|
+
readonly children?: readonly LoomNode[];
|
|
15
|
+
};
|
|
16
|
+
export declare const buildElement: (idFactory: IdFactory, spec: ElementSpec) => ElementNode;
|
|
17
|
+
export declare const buildText: (idFactory: IdFactory, value: string) => TextNode;
|
|
18
|
+
export declare const buildSlot: (idFactory: IdFactory, name: string, fallback?: readonly LoomNode[]) => SlotNode;
|
|
19
|
+
//# sourceMappingURL=builders.d.ts.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { primitiveTypeSchema, slotNameSchema } from "../primitive-type.js";
|
|
2
|
+
export const buildElement = (idFactory, spec) => ({
|
|
3
|
+
kind: "element",
|
|
4
|
+
id: idFactory.nodeId(),
|
|
5
|
+
type: primitiveTypeSchema.parse(spec.type),
|
|
6
|
+
props: spec.props ?? {},
|
|
7
|
+
children: spec.children ?? [],
|
|
8
|
+
});
|
|
9
|
+
export const buildText = (idFactory, value) => ({
|
|
10
|
+
kind: "text",
|
|
11
|
+
id: idFactory.nodeId(),
|
|
12
|
+
value,
|
|
13
|
+
});
|
|
14
|
+
export const buildSlot = (idFactory, name, fallback = []) => ({
|
|
15
|
+
kind: "slot",
|
|
16
|
+
id: idFactory.nodeId(),
|
|
17
|
+
name: slotNameSchema.parse(name),
|
|
18
|
+
children: fallback,
|
|
19
|
+
});
|
|
20
|
+
//# sourceMappingURL=builders.js.map
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { NodeId } from "../ids.js";
|
|
2
|
+
import type { LoomTree } from "./tree.js";
|
|
3
|
+
/**
|
|
4
|
+
* Why two trees are not the same tree.
|
|
5
|
+
*
|
|
6
|
+
* This is a *description*, never a recipe. A `TreeDifference` cannot be applied
|
|
7
|
+
* and deliberately does not resemble a `TreeDelta`: a delta is authored against
|
|
8
|
+
* a known base revision and is the only thing that may change a tree (0001), so
|
|
9
|
+
* a second shape that also described change would eventually be applied by
|
|
10
|
+
* somebody, and the log would gain entries nobody proposed.
|
|
11
|
+
*
|
|
12
|
+
* It exists for the case 0016 created: the log is the truth and the snapshot is
|
|
13
|
+
* a view of it, and `auditSnapshot` can prove the two disagree without being
|
|
14
|
+
* able to say *how*. "Diverged" is a fact an operator cannot act on. "The fold
|
|
15
|
+
* produced a card the snapshot does not have, at `node-7`" is.
|
|
16
|
+
*
|
|
17
|
+
* Node ids are the join key, which is what makes this comparison meaningful
|
|
18
|
+
* rather than a structural guess: ids are minted once by the runtime (0003), so
|
|
19
|
+
* the same id on both sides is the same node in two states, and an id on one
|
|
20
|
+
* side only is a node one side lost or invented.
|
|
21
|
+
*
|
|
22
|
+
* That the join key holds is a claim about the log rather than about these two
|
|
23
|
+
* trees, and `identity.ts` is what checks it (0038). Comparing two folds of one
|
|
24
|
+
* log is the case this was written for and is safe regardless — both sides read
|
|
25
|
+
* the same id the same way.
|
|
26
|
+
*/
|
|
27
|
+
/**
|
|
28
|
+
* What differs about a node both trees have. Ordered as listed.
|
|
29
|
+
*
|
|
30
|
+
* `type` is an element's primitive and `name` is a slot's name. They were one
|
|
31
|
+
* facet until an operator reading `/audit` was told a renamed slot differed in
|
|
32
|
+
* "which primitive it is", which is a sentence about a node kind that has no
|
|
33
|
+
* primitive.
|
|
34
|
+
*/
|
|
35
|
+
export type NodeFacet = "kind" | "type" | "name" | "props" | "text" | "parent" | "position";
|
|
36
|
+
export type TreeDifference =
|
|
37
|
+
/** Present in the base tree, absent from the compared one. */
|
|
38
|
+
{
|
|
39
|
+
readonly code: "missing";
|
|
40
|
+
readonly nodeId: NodeId;
|
|
41
|
+
readonly label: string;
|
|
42
|
+
}
|
|
43
|
+
/** Present in the compared tree, absent from the base one. */
|
|
44
|
+
| {
|
|
45
|
+
readonly code: "extra";
|
|
46
|
+
readonly nodeId: NodeId;
|
|
47
|
+
readonly label: string;
|
|
48
|
+
} | {
|
|
49
|
+
readonly code: "changed";
|
|
50
|
+
readonly nodeId: NodeId;
|
|
51
|
+
readonly label: string;
|
|
52
|
+
/** Never empty — an unchanged node produces no difference at all. */
|
|
53
|
+
readonly facets: readonly NodeFacet[];
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Every way `compared` differs from `base`, one entry per node.
|
|
57
|
+
*
|
|
58
|
+
* In document order of whichever tree holds the node, base first: a reader is
|
|
59
|
+
* looking at a tree, and a list ordered by id would scatter one broken subtree
|
|
60
|
+
* across the whole report.
|
|
61
|
+
*
|
|
62
|
+
* A moved node produces one `changed` with a `parent` or `position` facet, not a
|
|
63
|
+
* `missing` and an `extra`. The id is what makes that possible, and it is the
|
|
64
|
+
* reason this is worth having over a structural diff — a structural diff of a
|
|
65
|
+
* moved card reports the entire subtree twice.
|
|
66
|
+
*/
|
|
67
|
+
export declare const compareTrees: (base: LoomTree, compared: LoomTree) => readonly TreeDifference[];
|
|
68
|
+
//# sourceMappingURL=compare.d.ts.map
|