@samva/markup 0.3.0 → 0.5.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.
Files changed (108) hide show
  1. package/AGENTS.md +17 -0
  2. package/dist/{ast-63I-VLQx.d.ts → ast-BLybiDxp.d.ts} +34 -60
  3. package/dist/ast.d.ts +2 -2
  4. package/dist/ast.js +4 -52
  5. package/dist/catalog-Db0UcCTg.d.ts +356 -0
  6. package/dist/{checks-DXuERO4B.js → checks-CmmITP6j.js} +14 -14
  7. package/dist/checks.d.ts +1 -1
  8. package/dist/checks.js +1 -1
  9. package/dist/classes.d.ts +1 -1
  10. package/dist/compile-sms.d.ts +3 -3
  11. package/dist/compile-whatsapp.d.ts +5 -5
  12. package/dist/compile-whatsapp.js +3 -3
  13. package/dist/compile.d.ts +5 -5
  14. package/dist/compile.js +5 -5
  15. package/dist/compiler.d.ts +4 -4
  16. package/dist/compiler.js +6 -6
  17. package/dist/components.d.ts +4 -4
  18. package/dist/conditionals.js +3 -3
  19. package/dist/corpus-CM7rKX41.d.ts +106 -0
  20. package/dist/{css-ar2lU3NC.d.ts → css-DoNc7CiC.d.ts} +4 -5
  21. package/dist/diagnostics-CqepLcpI.d.ts +47 -0
  22. package/dist/diagnostics-eFM9A_TU.d.ts +46 -0
  23. package/dist/diagnostics.d.ts +2 -2
  24. package/dist/diagnostics.js +15 -29
  25. package/dist/{elements-DtwKlFVH.d.ts → elements-ChJULZlh.d.ts} +40 -161
  26. package/dist/email/components.d.ts +1 -1
  27. package/dist/email/diagnostics.d.ts +1 -1
  28. package/dist/email/diagnostics.js +8 -43
  29. package/dist/email/elements.d.ts +1 -1
  30. package/dist/email/html.d.ts +2 -2
  31. package/dist/email/html.js +9 -9
  32. package/dist/email/jsx-dev-runtime.d.ts +3 -21
  33. package/dist/email/jsx-runtime.d.ts +1 -1
  34. package/dist/email/jsx-runtime.js +29 -3
  35. package/dist/email/render.d.ts +4 -4
  36. package/dist/email/render.js +1 -1
  37. package/dist/email/selection.d.ts +20 -31
  38. package/dist/email/selection.js +1 -53
  39. package/dist/email/source-edit.d.ts +1 -1
  40. package/dist/email/source-edit.js +2 -2
  41. package/dist/email/stylesheets.d.ts +1 -1
  42. package/dist/email/text.d.ts +1 -1
  43. package/dist/email/text.js +3 -3
  44. package/dist/emit.d.ts +2 -2
  45. package/dist/emit.js +5 -5
  46. package/dist/guards-eV1qLbf2.js +9 -0
  47. package/dist/{input-schema-BIfzI63B.d.ts → input-schema-7dPFVvNE.d.ts} +2 -2
  48. package/dist/input-schema-zjkgrXn2.js +455 -0
  49. package/dist/input-schema.d.ts +1 -1
  50. package/dist/input-schema.js +1 -169
  51. package/dist/interpolate.d.ts +9 -12
  52. package/dist/interpolate.js +1 -19
  53. package/dist/jsx-dev-runtime.d.ts +2 -2
  54. package/dist/{jsx-runtime-C5k_Zq0A.d.ts → jsx-runtime-BI4gI19E.d.ts} +3 -3
  55. package/dist/jsx-runtime.d.ts +1 -1
  56. package/dist/jsx-runtime.js +3 -3
  57. package/dist/model.d.ts +18 -33
  58. package/dist/model.js +4 -17
  59. package/dist/ops.d.ts +78 -172
  60. package/dist/ops.js +51 -117
  61. package/dist/{parser-CGBS73Gz.d.ts → parser-b_Kp5MT6.d.ts} +5 -5
  62. package/dist/parser.d.ts +1 -1
  63. package/dist/parser.js +8 -8
  64. package/dist/{predicate-G2SeSvoN.d.ts → predicate-Bmvgw7Ao.d.ts} +4 -4
  65. package/dist/{predicate-CvkzT-a2.js → predicate-DwXzmqIY.js} +11 -11
  66. package/dist/predicate.d.ts +1 -1
  67. package/dist/predicate.js +1 -1
  68. package/dist/presets/category-mapping.d.ts +1 -1
  69. package/dist/presets/corpus.d.ts +1 -1
  70. package/dist/presets/corpus.js +87 -140
  71. package/dist/presets/public-gallery.d.ts +106 -130
  72. package/dist/presets/public-gallery.js +131 -209
  73. package/dist/presets/public-handoff.d.ts +4 -4
  74. package/dist/presets/public-handoff.js +13 -11
  75. package/dist/presets/public-preview-artifacts.d.ts +5 -5
  76. package/dist/presets/public-preview-artifacts.js +9 -9
  77. package/dist/presets/public-preview.d.ts +0 -4
  78. package/dist/presets/public-preview.js +37 -362
  79. package/dist/presets/showcase.d.ts +2 -0
  80. package/dist/presets/showcase.js +627 -0
  81. package/dist/presets/sources.d.ts +1 -1
  82. package/dist/presets/sources.js +5767 -2023
  83. package/dist/presets.d.ts +2 -384
  84. package/dist/presets.js +299 -765
  85. package/dist/printer.d.ts +1 -1
  86. package/dist/{render-ykQhtMs_.js → render-T6IFPnP4.js} +12 -12
  87. package/dist/render-template.d.ts +7 -7
  88. package/dist/render-template.js +6 -6
  89. package/dist/showcase-dvJMn-Lo.d.ts +456 -0
  90. package/dist/{source-locations-BCJQnIfU.d.ts → source-locations-D6Te6Gy1.d.ts} +4 -26
  91. package/dist/source-locations.d.ts +2 -2
  92. package/dist/source-locations.js +3 -26
  93. package/dist/{template-Dy5yOPyp.d.ts → template-G-QPcfmn.d.ts} +4 -4
  94. package/dist/template.d.ts +1 -1
  95. package/dist/template.js +3 -3
  96. package/dist/theme-css.d.ts +3 -3
  97. package/dist/theme-css.js +3 -3
  98. package/dist/tsx-source-instrumentation.d.ts +1 -3
  99. package/dist/tsx-source-instrumentation.js +6 -6
  100. package/dist/tsx-tracer.d.ts +7 -11
  101. package/dist/tsx-tracer.js +164 -164
  102. package/dist/{variables-if1VrV34.d.ts → variables-BnKs1iqb.d.ts} +2 -2
  103. package/dist/variables.d.ts +1 -1
  104. package/dist/variables.js +4 -4
  105. package/package.json +8 -3
  106. package/dist/corpus-qrUD5O6r.d.ts +0 -254
  107. package/dist/diagnostics-Djd9ckLg.d.ts +0 -90
  108. package/dist/diagnostics-oveE-laV.d.ts +0 -79
@@ -1,170 +1,2 @@
1
- import { Validator } from "@cfworker/json-schema";
2
- import applicator from "ajv/dist/refs/json-schema-2020-12/meta/applicator.json" with { type: "json" };
3
- import content from "ajv/dist/refs/json-schema-2020-12/meta/content.json" with { type: "json" };
4
- import core from "ajv/dist/refs/json-schema-2020-12/meta/core.json" with { type: "json" };
5
- import format_annotation from "ajv/dist/refs/json-schema-2020-12/meta/format-annotation.json" with { type: "json" };
6
- import meta_data from "ajv/dist/refs/json-schema-2020-12/meta/meta-data.json" with { type: "json" };
7
- import unevaluated from "ajv/dist/refs/json-schema-2020-12/meta/unevaluated.json" with { type: "json" };
8
- import validation from "ajv/dist/refs/json-schema-2020-12/meta/validation.json" with { type: "json" };
9
- import metaSchema from "ajv/dist/refs/json-schema-2020-12/schema.json" with { type: "json" };
10
- import { Predicate } from "effect";
11
- //#region src/input-schema.ts
12
- const meta = new Validator(metaSchema, "2020-12", false);
13
- for (const part of [
14
- applicator,
15
- content,
16
- core,
17
- format_annotation,
18
- meta_data,
19
- unevaluated,
20
- validation
21
- ]) meta.addSchema(part);
22
- /** JSON Schema dialect accepted by template publications. */
23
- const INPUT_SCHEMA_DIALECT = "https://json-schema.org/draft/2020-12/schema";
24
- const canonicalJson = (value) => {
25
- if (Array.isArray(value)) return value.map(canonicalJson);
26
- if (Predicate.isObject(value)) return Object.fromEntries(Object.entries(value).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([key, item]) => [key, canonicalJson(item)]));
27
- return value;
28
- };
29
- const annotations = /* @__PURE__ */ new Set([
30
- "title",
31
- "description",
32
- "default",
33
- "examples",
34
- "deprecated",
35
- "readOnly",
36
- "writeOnly",
37
- "$comment"
38
- ]);
39
- const scalarKeywords = /* @__PURE__ */ new Set([
40
- "$schema",
41
- "$ref",
42
- "type",
43
- "enum",
44
- "const",
45
- "required",
46
- "minProperties",
47
- "maxProperties",
48
- "minItems",
49
- "maxItems",
50
- "uniqueItems",
51
- "minLength",
52
- "maxLength",
53
- "pattern",
54
- "minimum",
55
- "maximum",
56
- "exclusiveMinimum",
57
- "exclusiveMaximum",
58
- "multipleOf"
59
- ]);
60
- const schemaMaps = /* @__PURE__ */ new Set([
61
- "properties",
62
- "$defs",
63
- "patternProperties",
64
- "dependentSchemas"
65
- ]);
66
- const schemaValues = /* @__PURE__ */ new Set([
67
- "additionalProperties",
68
- "items",
69
- "contains",
70
- "not",
71
- "if",
72
- "then",
73
- "else",
74
- "propertyNames"
75
- ]);
76
- const schemaArrays = /* @__PURE__ */ new Set([
77
- "allOf",
78
- "anyOf",
79
- "oneOf",
80
- "prefixItems"
81
- ]);
82
- /** Check every schema position before deriving identity; unknown keywords never disappear. */
83
- const canonicalSchema = (schema, path = "#") => {
84
- if (typeof schema === "boolean") return schema;
85
- if (!Predicate.isObject(schema)) throw new TypeError(`Invalid schema at ${path}`);
86
- const shape = meta.validate(schema);
87
- if (!shape.valid) throw new TypeError(`Invalid JSON Schema at ${path}: ${JSON.stringify(shape.errors)}`);
88
- const result = {};
89
- for (const [key, value] of Object.entries(schema).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0)) {
90
- if (annotations.has(key)) continue;
91
- if (schemaMaps.has(key)) {
92
- if (!Predicate.isObject(value)) throw new TypeError(`Invalid ${path}/${key}`);
93
- result[key] = Object.fromEntries(Object.entries(value).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([name, child]) => [name, canonicalSchema(child, `${path}/${key}/${name}`)]));
94
- } else if (schemaValues.has(key)) result[key] = canonicalSchema(value, `${path}/${key}`);
95
- else if (schemaArrays.has(key)) {
96
- if (!Array.isArray(value)) throw new TypeError(`Invalid ${path}/${key}`);
97
- result[key] = value.map((child, index) => canonicalSchema(child, `${path}/${key}/${index}`));
98
- } else if (scalarKeywords.has(key)) {
99
- if (key === "$ref" && (typeof value !== "string" || !(value === "#" || value.startsWith("#/")))) throw new TypeError(`Only local JSON Pointer references are supported at ${path}/$ref`);
100
- if (key === "$schema" && value !== "https://json-schema.org/draft/2020-12/schema") throw new TypeError(`Expected JSON Schema 2020-12 at ${path}`);
101
- result[key] = canonicalJson(value);
102
- } else throw new TypeError(`Unsupported input schema keyword ${path}/${key}`);
103
- }
104
- return result;
105
- };
106
- /** Direct portable JSON Schema authoring; the caller declares its JSON input type. */
107
- const jsonSchema = (schema) => ({ "~standard": {
108
- version: 1,
109
- vendor: "samva-json-schema",
110
- jsonSchema: {
111
- input: () => schema,
112
- output: () => schema
113
- }
114
- } });
115
- /** Pinned Effect/Zod converters omit arbitrary refinements, so inspect those vendors' check metadata. */
116
- const rejectNonportableChecks = (source) => {
117
- const vendor = source["~standard"].vendor;
118
- if (vendor !== "effect" && vendor !== "zod") return;
119
- const seen = /* @__PURE__ */ new WeakSet();
120
- const visit = (value) => {
121
- if (Array.isArray(value)) {
122
- for (const child of value) visit(child);
123
- return;
124
- }
125
- if (!Predicate.isObject(value) || seen.has(value)) return;
126
- seen.add(value);
127
- if (vendor === "zod" && Predicate.isObject(value._zod)) {
128
- visit(value._zod.def);
129
- return;
130
- }
131
- if (vendor === "effect" && value.encoding !== void 0) throw new TypeError("Nonportable Effect transform; use a JSON input schema without decoding transforms");
132
- if (vendor === "effect" && value._tag === "Suspend") throw new TypeError("Unsupported suspended Effect converter; use local JSON Schema references");
133
- if (vendor === "zod" && value.type === "lazy") throw new TypeError("Unsupported lazy Zod converter; author recursive input with local JSON Schema references");
134
- if (vendor === "zod" && (value.check === "custom" || value.check === "overwrite" || [
135
- "transform",
136
- "default",
137
- "prefault",
138
- "catch"
139
- ].includes(String(value.type)))) throw new TypeError("Nonportable Zod refinement/transform; express constraints in JSON Schema");
140
- if (vendor === "effect" && value._tag === "Filter" && (!Predicate.isObject(value.annotations) || typeof value.annotations.toJsonSchema !== "function")) throw new TypeError("Nonportable Effect refinement; provide a JSON Schema constraint");
141
- for (const [key, child] of Object.entries(value)) if (key !== "~standard" && key !== "annotations") visit(child);
142
- };
143
- if (vendor === "effect" && Predicate.hasProperty(source, "ast")) visit(source.ast);
144
- else visit(source);
145
- };
146
- /** Convert caller input, never validator output. Both conversion directions must be portable. */
147
- const inputSchema = (source) => {
148
- rejectNonportableChecks(source);
149
- const converter = source["~standard"].jsonSchema;
150
- const schema = structuredClone(converter.input({ target: "draft-2020-12" }));
151
- const canonical = canonicalSchema(schema);
152
- const output = canonicalSchema(converter.output({ target: "draft-2020-12" }));
153
- if (JSON.stringify(canonical) !== JSON.stringify(output)) throw new TypeError("Template schemas must preserve JSON input; input/output conversion differs");
154
- const validator = new Validator(schema, "2020-12", false);
155
- const validate = (value) => {
156
- const result = validator.validate(value);
157
- validate.errors = result.errors;
158
- return result.valid;
159
- };
160
- validate.errors = [];
161
- return {
162
- schema,
163
- validationIdentity: JSON.stringify(canonical),
164
- validate
165
- };
166
- };
167
- //#endregion
1
+ import { n as inputSchema, r as jsonSchema, t as INPUT_SCHEMA_DIALECT } from "./input-schema-zjkgrXn2.js";
168
2
  export { INPUT_SCHEMA_DIALECT, inputSchema, jsonSchema };
169
-
170
- //# sourceMappingURL=input-schema.js.map
@@ -1,16 +1,13 @@
1
- import { Schema } from "effect";
2
1
  //#region src/interpolate.d.ts
3
- declare const DocumentVariableTypeSchema: Schema.Literals<readonly ["string", "number", "boolean", "date", "array", "object"]>;
4
- type DocumentVariableType = typeof DocumentVariableTypeSchema.Type;
2
+ type DocumentVariableType = "string" | "number" | "boolean" | "date" | "array" | "object";
5
3
  /** One entry of a template's declared variable schema. */
6
- declare const DocumentVariableSchema: Schema.Struct<{
7
- readonly name: Schema.String;
8
- readonly type: Schema.Literals<readonly ["string", "number", "boolean", "date", "array", "object"]>;
9
- readonly required: Schema.Boolean;
10
- readonly default: Schema.optional<Schema.Unknown>;
11
- readonly description: Schema.optional<Schema.String>;
12
- }>;
13
- interface DocumentVariable extends Schema.Schema.Type<typeof DocumentVariableSchema> {}
4
+ interface DocumentVariable {
5
+ readonly name: string;
6
+ readonly type: DocumentVariableType;
7
+ readonly required: boolean;
8
+ readonly default?: unknown;
9
+ readonly description?: string | undefined;
10
+ }
14
11
  declare const variableReferencePattern: RegExp;
15
12
  declare const getVariableValue: (variables: Record<string, unknown>, variableSchema: ReadonlyArray<DocumentVariable>, name: string) => unknown;
16
13
  declare const stringifyVariable: (value: unknown) => string;
@@ -23,5 +20,5 @@ declare const interpolate: (text: string, variables: Record<string, unknown>, va
23
20
  declare const variableReferences: (text: string) => Set<string>;
24
21
  declare const addVariableReferences: (target: Set<string>, text: string) => void;
25
22
  //#endregion
26
- export { DocumentVariable, DocumentVariableSchema, DocumentVariableType, DocumentVariableTypeSchema, InterpolationResult, addVariableReferences, getVariableValue, interpolate, stringifyVariable, variableReferencePattern, variableReferences };
23
+ export { DocumentVariable, DocumentVariableType, InterpolationResult, addVariableReferences, getVariableValue, interpolate, stringifyVariable, variableReferencePattern, variableReferences };
27
24
  //# sourceMappingURL=interpolate.d.ts.map
@@ -1,22 +1,4 @@
1
- import { Schema } from "effect";
2
1
  //#region src/interpolate.ts
3
- const limitedString = (maxLength) => Schema.String.check(Schema.isMaxLength(maxLength));
4
- const DocumentVariableTypeSchema = Schema.Literals([
5
- "string",
6
- "number",
7
- "boolean",
8
- "date",
9
- "array",
10
- "object"
11
- ]);
12
- /** One entry of a template's declared variable schema. */
13
- const DocumentVariableSchema = Schema.Struct({
14
- name: limitedString(128),
15
- type: DocumentVariableTypeSchema,
16
- required: Schema.Boolean,
17
- default: Schema.optional(Schema.Unknown),
18
- description: Schema.optional(limitedString(512))
19
- });
20
2
  const variableReferencePattern = /\$\{\s*\/?([\w.]+)\s*\}|\{\{\s*([\w.]+)\s*\}\}/g;
21
3
  const getVariableValue = (variables, variableSchema, name) => {
22
4
  const schema = variableSchema.find((item) => item.name === name);
@@ -56,6 +38,6 @@ const addVariableReferences = (target, text) => {
56
38
  variableReferences(text).forEach((name) => target.add(name));
57
39
  };
58
40
  //#endregion
59
- export { DocumentVariableSchema, DocumentVariableTypeSchema, addVariableReferences, getVariableValue, interpolate, stringifyVariable, variableReferencePattern, variableReferences };
41
+ export { addVariableReferences, getVariableValue, interpolate, stringifyVariable, variableReferencePattern, variableReferences };
60
42
 
61
43
  //# sourceMappingURL=interpolate.js.map
@@ -1,5 +1,5 @@
1
- import { r as JsxSource } from "./source-locations-BCJQnIfU.js";
2
- import { a as JsxResult, i as JSX, n as Fragment, t as Component } from "./jsx-runtime-C5k_Zq0A.js";
1
+ import { r as JsxSource } from "./source-locations-D6Te6Gy1.js";
2
+ import { a as JsxResult, i as JSX, n as Fragment, t as Component } from "./jsx-runtime-BI4gI19E.js";
3
3
  //#region src/jsx-dev-runtime.d.ts
4
4
  interface JsxDevProps {
5
5
  readonly children?: unknown;
@@ -1,5 +1,5 @@
1
- import { E as SmlNode, m as ElementNode, n as Attribute } from "./ast-63I-VLQx.js";
2
- import { s as VariableRef } from "./variables-if1VrV34.js";
1
+ import { f as ElementNode, n as Attribute, x as SmlNode } from "./ast-BLybiDxp.js";
2
+ import { s as VariableRef } from "./variables-BnKs1iqb.js";
3
3
  //#region src/jsx-runtime.d.ts
4
4
  /** A component is a plain function of its props that returns a draft node. */
5
5
  type Component<P> = (props: P) => SmlNode;
@@ -54,4 +54,4 @@ declare namespace JSX {
54
54
  }
55
55
  //#endregion
56
56
  export { JsxResult as a, elementDraft as c, normalizeChildren as d, JSX as i, jsx as l, Fragment as n, SmlChild as o, FragmentDraft as r, SmlChildren as s, Component as t, jsxs as u };
57
- //# sourceMappingURL=jsx-runtime-C5k_Zq0A.d.ts.map
57
+ //# sourceMappingURL=jsx-runtime-BI4gI19E.d.ts.map
@@ -1,2 +1,2 @@
1
- import { a as JsxResult, c as elementDraft, d as normalizeChildren, i as JSX, l as jsx, n as Fragment, o as SmlChild, r as FragmentDraft, s as SmlChildren, t as Component, u as jsxs } from "./jsx-runtime-C5k_Zq0A.js";
1
+ import { a as JsxResult, c as elementDraft, d as normalizeChildren, i as JSX, l as jsx, n as Fragment, o as SmlChild, r as FragmentDraft, s as SmlChildren, t as Component, u as jsxs } from "./jsx-runtime-BI4gI19E.js";
2
2
  export { Component, Fragment, FragmentDraft, JSX, JsxResult, SmlChild, SmlChildren, elementDraft, jsx, jsxs, normalizeChildren };
@@ -1,14 +1,14 @@
1
+ import { t as hasProperty } from "./guards-eV1qLbf2.js";
1
2
  import { JSX_SOURCE_LOCATION_PROP, attachJsxSourceLocation, completeJsxSourceLocation } from "./source-locations.js";
2
3
  import { VARIABLE_REF, isVariableRef } from "./variables.js";
3
- import { Predicate } from "effect";
4
4
  //#region src/jsx-runtime.ts
5
5
  const PLACEHOLDER_SPAN = {
6
6
  start: 0,
7
7
  end: 0
8
8
  };
9
- const isFragmentDraft = (value) => Predicate.hasProperty(value, "kind") && value.kind === "fragment";
9
+ const isFragmentDraft = (value) => hasProperty(value, "kind") && value.kind === "fragment";
10
10
  const isSmlNode = (value) => {
11
- if (!Predicate.hasProperty(value, "kind")) return false;
11
+ if (!hasProperty(value, "kind")) return false;
12
12
  const kind = value.kind;
13
13
  return kind === "element" || kind === "text" || kind === "interpolation";
14
14
  };
package/dist/model.d.ts CHANGED
@@ -1,39 +1,24 @@
1
- import { O as SmlTag, w as SmlDocument } from "./ast-63I-VLQx.js";
2
- import { Result, Schema } from "effect";
1
+ import { S as SmlTag, b as SmlDocument } from "./ast-BLybiDxp.js";
2
+ import { Result } from "better-result";
3
3
  //#region src/model.d.ts
4
- declare const SmlNodeKeyAttrsSchema: Schema.$Record<Schema.String, Schema.Union<readonly [Schema.String, Schema.Finite]>>;
5
- declare const SmlNodeIndexEntrySchema: Schema.Struct<{
6
- readonly id: Schema.String;
7
- readonly tag: Schema.String;
8
- readonly order: Schema.Finite;
9
- readonly parentId: Schema.NullOr<Schema.String>;
10
- readonly childIndex: Schema.Finite;
11
- readonly depth: Schema.Finite;
12
- readonly path: Schema.String;
13
- readonly textPreview: Schema.String;
14
- readonly attrs: Schema.$Record<Schema.String, Schema.Union<readonly [Schema.String, Schema.Finite]>>;
15
- }>;
16
- type SmlNodeIndexEntry = typeof SmlNodeIndexEntrySchema.Type & {
4
+ /** The subset of an element's attributes the navigator and agent tools read. */
5
+ type SmlNodeKeyAttrs = Readonly<Record<string, string | number>>;
6
+ interface SmlNodeIndexEntry {
7
+ readonly id: string;
17
8
  readonly tag: SmlTag;
18
- };
19
- declare const SmlNodeIndexSchema: Schema.Struct<{
20
- readonly nodes: Schema.$Array<Schema.Struct<{
21
- readonly id: Schema.String;
22
- readonly tag: Schema.String;
23
- readonly order: Schema.Finite;
24
- readonly parentId: Schema.NullOr<Schema.String>;
25
- readonly childIndex: Schema.Finite;
26
- readonly depth: Schema.Finite;
27
- readonly path: Schema.String;
28
- readonly textPreview: Schema.String;
29
- readonly attrs: Schema.$Record<Schema.String, Schema.Union<readonly [Schema.String, Schema.Finite]>>;
30
- }>>;
31
- }>;
32
- type SmlNodeIndex = typeof SmlNodeIndexSchema.Type & {
9
+ readonly order: number;
10
+ readonly parentId: string | null;
11
+ readonly childIndex: number;
12
+ readonly depth: number;
13
+ readonly path: string;
14
+ readonly textPreview: string;
15
+ readonly attrs: SmlNodeKeyAttrs;
16
+ }
17
+ interface SmlNodeIndex {
33
18
  readonly nodes: readonly SmlNodeIndexEntry[];
34
- };
19
+ }
35
20
  declare const deriveNodeIndexFromDocument: (document: SmlDocument) => SmlNodeIndex;
36
- declare const deriveNodeIndex: (source: string) => Result.Result<SmlNodeIndex, string>;
21
+ declare const deriveNodeIndex: (source: string) => Result<SmlNodeIndex, string>;
37
22
  //#endregion
38
- export { SmlNodeIndex, SmlNodeIndexEntry, SmlNodeIndexEntrySchema, SmlNodeIndexSchema, SmlNodeKeyAttrsSchema, deriveNodeIndex, deriveNodeIndexFromDocument };
23
+ export { SmlNodeIndex, SmlNodeIndexEntry, SmlNodeKeyAttrs, deriveNodeIndex, deriveNodeIndexFromDocument };
39
24
  //# sourceMappingURL=model.d.ts.map
package/dist/model.js CHANGED
@@ -1,19 +1,6 @@
1
1
  import { parseSml } from "./parser.js";
2
- import { Result, Schema } from "effect";
2
+ import { Result } from "better-result";
3
3
  //#region src/model.ts
4
- const SmlNodeKeyAttrsSchema = Schema.Record(Schema.String, Schema.Union([Schema.String, Schema.Finite]));
5
- const SmlNodeIndexEntrySchema = Schema.Struct({
6
- id: Schema.String,
7
- tag: Schema.String,
8
- order: Schema.Finite,
9
- parentId: Schema.NullOr(Schema.String),
10
- childIndex: Schema.Finite,
11
- depth: Schema.Finite,
12
- path: Schema.String,
13
- textPreview: Schema.String,
14
- attrs: SmlNodeKeyAttrsSchema
15
- });
16
- const SmlNodeIndexSchema = Schema.Struct({ nodes: Schema.Array(SmlNodeIndexEntrySchema) });
17
4
  const KEY_ATTRS = /* @__PURE__ */ new Set([
18
5
  "alt",
19
6
  "class",
@@ -81,10 +68,10 @@ const deriveNodeIndexFromDocument = (document) => {
81
68
  };
82
69
  const deriveNodeIndex = (source) => {
83
70
  const parsed = parseSml(source);
84
- if (Result.isFailure(parsed)) return Result.fail(parsed.failure.diagnostics.map((diagnostic) => diagnostic.message).join("\n"));
85
- return Result.succeed(deriveNodeIndexFromDocument(parsed.success));
71
+ if (Result.isError(parsed)) return Result.err(parsed.error.diagnostics.map((diagnostic) => diagnostic.message).join("\n"));
72
+ return Result.ok(deriveNodeIndexFromDocument(parsed.value));
86
73
  };
87
74
  //#endregion
88
- export { SmlNodeIndexEntrySchema, SmlNodeIndexSchema, SmlNodeKeyAttrsSchema, deriveNodeIndex, deriveNodeIndexFromDocument };
75
+ export { deriveNodeIndex, deriveNodeIndexFromDocument };
89
76
 
90
77
  //# sourceMappingURL=model.js.map
package/dist/ops.d.ts CHANGED
@@ -1,184 +1,90 @@
1
- import { o as SmlParseError } from "./diagnostics-oveE-laV.js";
2
- import { E as SmlNode } from "./ast-63I-VLQx.js";
3
- import { Result, Schema } from "effect";
1
+ import { i as SmlParseError, t as Diagnostic } from "./diagnostics-CqepLcpI.js";
2
+ import { S as SmlTag, r as AttributeValue, x as SmlNode } from "./ast-BLybiDxp.js";
3
+ import { Result } from "better-result";
4
4
  //#region src/ops.d.ts
5
+ /** Where an inserted node lands relative to its reference node. */
6
+ type SmlInsertPosition = "before" | "after" | "inside";
7
+ interface SetPropOp {
8
+ readonly type: "setProp";
9
+ readonly nodeId: string;
10
+ readonly name: string;
11
+ readonly value: AttributeValue | null;
12
+ }
13
+ /**
14
+ * Replace a node's complete child list. The normal print → parse → compile
15
+ * preflight remains the authority on whether the replacement satisfies the
16
+ * target's content model.
17
+ */
18
+ interface SetChildrenOp {
19
+ readonly type: "setChildren";
20
+ readonly nodeId: string;
21
+ readonly children: ReadonlyArray<SmlNode>;
22
+ }
23
+ interface InsertBlockOp {
24
+ readonly type: "insertBlock";
25
+ readonly tag: SmlTag;
26
+ readonly referenceId: string | null;
27
+ readonly position: SmlInsertPosition;
28
+ }
29
+ interface InsertSnippetOp {
30
+ readonly type: "insertSnippet";
31
+ readonly snippet: string;
32
+ readonly referenceId: string | null;
33
+ readonly position: SmlInsertPosition;
34
+ }
35
+ /**
36
+ * `insertionIndex` is an element-child index into `targetParentId` evaluated
37
+ * AFTER the moved node has left its old position — the lifted-out model, so a
38
+ * same-parent caller must compute the index against the sibling list without
39
+ * the node. Indexes past the end append.
40
+ */
41
+ interface MoveNodeOp {
42
+ readonly type: "moveNode";
43
+ readonly nodeId: string;
44
+ readonly targetParentId: string;
45
+ readonly insertionIndex: number;
46
+ }
47
+ interface DuplicateNodeOp {
48
+ readonly type: "duplicateNode";
49
+ readonly nodeId: string;
50
+ }
51
+ interface RemoveNodeOp {
52
+ readonly type: "removeNode";
53
+ readonly nodeId: string;
54
+ }
5
55
  /**
6
56
  * A single edit against SML source. `nodeId` (and `referenceId` /
7
57
  * `targetParentId`) are positional ids from the source the caller last read;
8
58
  * within a batch they always resolve against that snapshot — see {@link applyOps}.
9
59
  */
10
- declare const SmlOpSchema: Schema.Union<readonly [Schema.TaggedStruct<"setProp", {
11
- readonly nodeId: Schema.String;
12
- readonly name: Schema.String;
13
- readonly value: Schema.NullOr<Schema.Union<readonly [Schema.Struct<{
14
- readonly kind: Schema.Literal<"string">;
15
- readonly value: Schema.String;
16
- }>, Schema.Struct<{
17
- readonly kind: Schema.Literal<"number">;
18
- readonly value: Schema.Finite;
19
- }>]>>;
20
- }>, Schema.TaggedStruct<"setChildren", {
21
- readonly nodeId: Schema.String;
22
- readonly children: Schema.$Array<Schema.Codec<SmlNode, SmlNode, never, never>>;
23
- }>, Schema.TaggedStruct<"insertBlock", {
24
- readonly tag: Schema.Literals<readonly ["Email", "Subject", "Preview", "Container", "Section", "Row", "Column", "Heading", "Text", "Button", "Image", "Divider", "Spacer", "List", "ListItem", "If", "Else", "strong", "em", "a", "Source", "Sms", "WhatsApp", "Header", "Body", "Footer", "Buttons"]>;
25
- readonly referenceId: Schema.NullOr<Schema.String>;
26
- readonly position: Schema.Literals<readonly ["before", "after", "inside"]>;
27
- }>, Schema.TaggedStruct<"insertSnippet", {
28
- readonly snippet: Schema.String;
29
- readonly referenceId: Schema.NullOr<Schema.String>;
30
- readonly position: Schema.Literals<readonly ["before", "after", "inside"]>;
31
- }>, Schema.TaggedStruct<"moveNode", {
32
- readonly nodeId: Schema.String;
33
- readonly targetParentId: Schema.String;
34
- readonly insertionIndex: Schema.Finite;
35
- }>, Schema.TaggedStruct<"duplicateNode", {
36
- readonly nodeId: Schema.String;
37
- }>, Schema.TaggedStruct<"removeNode", {
38
- readonly nodeId: Schema.String;
39
- }>]>;
40
- type SmlOp = typeof SmlOpSchema.Type;
41
- declare const SmlOpResultSchema: Schema.Struct<{
42
- readonly index: Schema.Finite;
43
- readonly status: Schema.Literals<readonly ["applied", "failed"]>;
44
- readonly op: Schema.Union<readonly [Schema.TaggedStruct<"setProp", {
45
- readonly nodeId: Schema.String;
46
- readonly name: Schema.String;
47
- readonly value: Schema.NullOr<Schema.Union<readonly [Schema.Struct<{
48
- readonly kind: Schema.Literal<"string">;
49
- readonly value: Schema.String;
50
- }>, Schema.Struct<{
51
- readonly kind: Schema.Literal<"number">;
52
- readonly value: Schema.Finite;
53
- }>]>>;
54
- }>, Schema.TaggedStruct<"setChildren", {
55
- readonly nodeId: Schema.String;
56
- readonly children: Schema.$Array<Schema.Codec<SmlNode, SmlNode, never, never>>;
57
- }>, Schema.TaggedStruct<"insertBlock", {
58
- readonly tag: Schema.Literals<readonly ["Email", "Subject", "Preview", "Container", "Section", "Row", "Column", "Heading", "Text", "Button", "Image", "Divider", "Spacer", "List", "ListItem", "If", "Else", "strong", "em", "a", "Source", "Sms", "WhatsApp", "Header", "Body", "Footer", "Buttons"]>;
59
- readonly referenceId: Schema.NullOr<Schema.String>;
60
- readonly position: Schema.Literals<readonly ["before", "after", "inside"]>;
61
- }>, Schema.TaggedStruct<"insertSnippet", {
62
- readonly snippet: Schema.String;
63
- readonly referenceId: Schema.NullOr<Schema.String>;
64
- readonly position: Schema.Literals<readonly ["before", "after", "inside"]>;
65
- }>, Schema.TaggedStruct<"moveNode", {
66
- readonly nodeId: Schema.String;
67
- readonly targetParentId: Schema.String;
68
- readonly insertionIndex: Schema.Finite;
69
- }>, Schema.TaggedStruct<"duplicateNode", {
70
- readonly nodeId: Schema.String;
71
- }>, Schema.TaggedStruct<"removeNode", {
72
- readonly nodeId: Schema.String;
73
- }>]>;
74
- readonly diagnostics: Schema.$Array<Schema.Struct<{
75
- readonly code: Schema.String;
76
- readonly message: Schema.String;
77
- readonly span: Schema.Struct<{
78
- readonly start: Schema.Finite;
79
- readonly end: Schema.Finite;
80
- }>;
81
- readonly repair: Schema.optional<Schema.Struct<{
82
- readonly kind: Schema.Literals<readonly ["replace-class", "remove-class", "rewrite-node", "use-primitive"]>;
83
- readonly raw: Schema.optional<Schema.String>;
84
- readonly suggestions: Schema.$Array<Schema.String>;
85
- readonly explanation: Schema.String;
86
- }>>;
87
- }>>;
88
- }>;
89
- interface SmlOpResult extends Schema.Schema.Type<typeof SmlOpResultSchema> {}
90
- declare const ApplyOpsResultSchema: Schema.Struct<{
91
- readonly source: Schema.String;
92
- readonly revision: Schema.String;
93
- readonly diagnostics: Schema.$Array<Schema.Struct<{
94
- readonly code: Schema.String;
95
- readonly message: Schema.String;
96
- readonly span: Schema.Struct<{
97
- readonly start: Schema.Finite;
98
- readonly end: Schema.Finite;
99
- }>;
100
- readonly repair: Schema.optional<Schema.Struct<{
101
- readonly kind: Schema.Literals<readonly ["replace-class", "remove-class", "rewrite-node", "use-primitive"]>;
102
- readonly raw: Schema.optional<Schema.String>;
103
- readonly suggestions: Schema.$Array<Schema.String>;
104
- readonly explanation: Schema.String;
105
- }>>;
106
- }>>;
107
- readonly results: Schema.$Array<Schema.Struct<{
108
- readonly index: Schema.Finite;
109
- readonly status: Schema.Literals<readonly ["applied", "failed"]>;
110
- readonly op: Schema.Union<readonly [Schema.TaggedStruct<"setProp", {
111
- readonly nodeId: Schema.String;
112
- readonly name: Schema.String;
113
- readonly value: Schema.NullOr<Schema.Union<readonly [Schema.Struct<{
114
- readonly kind: Schema.Literal<"string">;
115
- readonly value: Schema.String;
116
- }>, Schema.Struct<{
117
- readonly kind: Schema.Literal<"number">;
118
- readonly value: Schema.Finite;
119
- }>]>>;
120
- }>, Schema.TaggedStruct<"setChildren", {
121
- readonly nodeId: Schema.String;
122
- readonly children: Schema.$Array<Schema.Codec<SmlNode, SmlNode, never, never>>;
123
- }>, Schema.TaggedStruct<"insertBlock", {
124
- readonly tag: Schema.Literals<readonly ["Email", "Subject", "Preview", "Container", "Section", "Row", "Column", "Heading", "Text", "Button", "Image", "Divider", "Spacer", "List", "ListItem", "If", "Else", "strong", "em", "a", "Source", "Sms", "WhatsApp", "Header", "Body", "Footer", "Buttons"]>;
125
- readonly referenceId: Schema.NullOr<Schema.String>;
126
- readonly position: Schema.Literals<readonly ["before", "after", "inside"]>;
127
- }>, Schema.TaggedStruct<"insertSnippet", {
128
- readonly snippet: Schema.String;
129
- readonly referenceId: Schema.NullOr<Schema.String>;
130
- readonly position: Schema.Literals<readonly ["before", "after", "inside"]>;
131
- }>, Schema.TaggedStruct<"moveNode", {
132
- readonly nodeId: Schema.String;
133
- readonly targetParentId: Schema.String;
134
- readonly insertionIndex: Schema.Finite;
135
- }>, Schema.TaggedStruct<"duplicateNode", {
136
- readonly nodeId: Schema.String;
137
- }>, Schema.TaggedStruct<"removeNode", {
138
- readonly nodeId: Schema.String;
139
- }>]>;
140
- readonly diagnostics: Schema.$Array<Schema.Struct<{
141
- readonly code: Schema.String;
142
- readonly message: Schema.String;
143
- readonly span: Schema.Struct<{
144
- readonly start: Schema.Finite;
145
- readonly end: Schema.Finite;
146
- }>;
147
- readonly repair: Schema.optional<Schema.Struct<{
148
- readonly kind: Schema.Literals<readonly ["replace-class", "remove-class", "rewrite-node", "use-primitive"]>;
149
- readonly raw: Schema.optional<Schema.String>;
150
- readonly suggestions: Schema.$Array<Schema.String>;
151
- readonly explanation: Schema.String;
152
- }>>;
153
- }>>;
154
- }>>;
155
- }>;
156
- interface ApplyOpsResult extends Schema.Schema.Type<typeof ApplyOpsResultSchema> {}
60
+ type SmlOp = SetPropOp | SetChildrenOp | InsertBlockOp | InsertSnippetOp | MoveNodeOp | DuplicateNodeOp | RemoveNodeOp;
61
+ interface SmlOpResult {
62
+ readonly index: number;
63
+ readonly status: "applied" | "failed";
64
+ readonly op: SmlOp;
65
+ readonly diagnostics: ReadonlyArray<Diagnostic>;
66
+ }
67
+ interface ApplyOpsResult {
68
+ readonly source: string;
69
+ readonly revision: string;
70
+ readonly diagnostics: ReadonlyArray<Diagnostic>;
71
+ readonly results: ReadonlyArray<SmlOpResult>;
72
+ }
157
73
  interface ApplyOpsOptions {
158
74
  readonly expectedRevision?: string | number | undefined;
159
75
  readonly currentRevision?: string | number | undefined;
160
76
  }
161
- declare const SmlOpError_base: Schema.Class<SmlOpError, Schema.TaggedStruct<"SmlOpError", {
162
- readonly diagnostics: Schema.$Array<Schema.Struct<{
163
- readonly code: Schema.String;
164
- readonly message: Schema.String;
165
- readonly span: Schema.Struct<{
166
- readonly start: Schema.Finite;
167
- readonly end: Schema.Finite;
168
- }>;
169
- readonly repair: Schema.optional<Schema.Struct<{
170
- readonly kind: Schema.Literals<readonly ["replace-class", "remove-class", "rewrite-node", "use-primitive"]>;
171
- readonly raw: Schema.optional<Schema.String>;
172
- readonly suggestions: Schema.$Array<Schema.String>;
173
- readonly explanation: Schema.String;
174
- }>>;
175
- }>>;
176
- }>, import("effect/Cause").YieldableError>;
177
- declare class SmlOpError extends SmlOpError_base {
178
- get message(): string;
77
+ declare const SmlOpError_base: import("better-result").TaggedErrorClass<"SmlOpError">;
78
+ declare class SmlOpError extends SmlOpError_base<{
79
+ readonly diagnostics: ReadonlyArray<Diagnostic>;
80
+ readonly message: string;
81
+ }> {
82
+ constructor(args: {
83
+ readonly diagnostics: ReadonlyArray<Diagnostic>;
84
+ });
179
85
  }
180
86
  declare const sourceRevision: (source: string) => string;
181
- declare const normalizeSml: (source: string) => Result.Result<string, SmlParseError>;
87
+ declare const normalizeSml: (source: string) => Result<string, SmlParseError>;
182
88
  /**
183
89
  * Apply a batch of ops to SML source, returning the rewritten source, its new
184
90
  * revision, and a per-op result.
@@ -201,8 +107,8 @@ declare const normalizeSml: (source: string) => Result.Result<string, SmlParseEr
201
107
  * as an independent validity gate; a failing op is recorded as `failed` and
202
108
  * does not advance the working document.
203
109
  */
204
- declare const applyOps: (source: string, ops: readonly SmlOp[], options?: ApplyOpsOptions) => Result.Result<ApplyOpsResult, SmlOpError>;
205
- declare const applyOp: (source: string, op: SmlOp, options?: ApplyOpsOptions) => Result.Result<ApplyOpsResult, SmlOpError>;
110
+ declare const applyOps: (source: string, ops: readonly SmlOp[], options?: ApplyOpsOptions) => Result<ApplyOpsResult, SmlOpError>;
111
+ declare const applyOp: (source: string, op: SmlOp, options?: ApplyOpsOptions) => Result<ApplyOpsResult, SmlOpError>;
206
112
  //#endregion
207
- export { ApplyOpsOptions, ApplyOpsResult, ApplyOpsResultSchema, SmlOp, SmlOpError, SmlOpResult, SmlOpResultSchema, SmlOpSchema, applyOp, applyOps, normalizeSml, sourceRevision };
113
+ export { ApplyOpsOptions, ApplyOpsResult, DuplicateNodeOp, InsertBlockOp, InsertSnippetOp, MoveNodeOp, RemoveNodeOp, SetChildrenOp, SetPropOp, SmlInsertPosition, SmlOp, SmlOpError, SmlOpResult, applyOp, applyOps, normalizeSml, sourceRevision };
208
114
  //# sourceMappingURL=ops.d.ts.map