nodality 1.5.1 → 1.5.3

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 (249) hide show
  1. package/README.md +2 -22
  2. package/bin/mcp-server.mjs +0 -98
  3. package/bin/nodality.mjs +3 -28
  4. package/dist/animator.cjs.js.LICENSE.txt +1 -1
  5. package/dist/animator.esm.js.LICENSE.txt +1 -1
  6. package/dist/audionew.cjs.js +1 -1
  7. package/dist/audionew.cjs.js.LICENSE.txt +1 -1
  8. package/dist/audionew.esm.js +1 -1
  9. package/dist/audionew.esm.js.LICENSE.txt +1 -1
  10. package/dist/base.cjs.js.LICENSE.txt +1 -1
  11. package/dist/base.esm.js.LICENSE.txt +1 -1
  12. package/dist/beta-desktop-bar.cjs.js.LICENSE.txt +1 -1
  13. package/dist/beta-desktop-bar.esm.js.LICENSE.txt +1 -1
  14. package/dist/beta-mobile-bar.cjs.js.LICENSE.txt +1 -1
  15. package/dist/beta-mobile-bar.esm.js.LICENSE.txt +1 -1
  16. package/dist/bundle.umd.js +1 -1
  17. package/dist/bundle.umd.js.LICENSE.txt +28 -1
  18. package/dist/button.cjs.js +1 -1
  19. package/dist/button.cjs.js.LICENSE.txt +1 -1
  20. package/dist/button.esm.js +1 -1
  21. package/dist/button.esm.js.LICENSE.txt +1 -1
  22. package/dist/card-getter.cjs.js.LICENSE.txt +1 -1
  23. package/dist/card-getter.esm.js.LICENSE.txt +1 -1
  24. package/dist/center.cjs.js.LICENSE.txt +1 -1
  25. package/dist/center.esm.js.LICENSE.txt +1 -1
  26. package/dist/checkbox.cjs.js +1 -1
  27. package/dist/checkbox.cjs.js.LICENSE.txt +1 -1
  28. package/dist/checkbox.esm.js +1 -1
  29. package/dist/checkbox.esm.js.LICENSE.txt +1 -1
  30. package/dist/code.cjs.js +1 -1
  31. package/dist/code.cjs.js.LICENSE.txt +1 -1
  32. package/dist/code.esm.js +1 -1
  33. package/dist/code.esm.js.LICENSE.txt +1 -1
  34. package/dist/container.cjs.js +1 -1
  35. package/dist/container.cjs.js.LICENSE.txt +1 -1
  36. package/dist/container.esm.js +1 -1
  37. package/dist/container.esm.js.LICENSE.txt +1 -1
  38. package/dist/data-list.cjs.js.LICENSE.txt +1 -1
  39. package/dist/data-list.esm.js.LICENSE.txt +1 -1
  40. package/dist/designer.cjs.js +1 -1
  41. package/dist/designer.cjs.js.LICENSE.txt +28 -1
  42. package/dist/designer.esm.js +1 -1
  43. package/dist/designer.esm.js.LICENSE.txt +28 -1
  44. package/dist/element-mapper.cjs.js +1 -1
  45. package/dist/element-mapper.cjs.js.LICENSE.txt +1 -1
  46. package/dist/element-mapper.esm.js +1 -1
  47. package/dist/element-mapper.esm.js.LICENSE.txt +1 -1
  48. package/dist/finalresult.esm.js +1 -1
  49. package/dist/finalresult.esm.js.LICENSE.txt +28 -1
  50. package/dist/flex-card.cjs.js.LICENSE.txt +1 -1
  51. package/dist/flex-card.esm.js.LICENSE.txt +1 -1
  52. package/dist/flex-grid.cjs.js +1 -1
  53. package/dist/flex-grid.cjs.js.LICENSE.txt +1 -1
  54. package/dist/flex-grid.esm.js +1 -1
  55. package/dist/flex-grid.esm.js.LICENSE.txt +1 -1
  56. package/dist/flex-row.cjs.js +1 -1
  57. package/dist/flex-row.cjs.js.LICENSE.txt +1 -1
  58. package/dist/flex-row.esm.js +1 -1
  59. package/dist/flex-row.esm.js.LICENSE.txt +1 -1
  60. package/dist/floating-input.cjs.js.LICENSE.txt +1 -1
  61. package/dist/floating-input.esm.js.LICENSE.txt +1 -1
  62. package/dist/free.cjs.js.LICENSE.txt +1 -1
  63. package/dist/free.esm.js.LICENSE.txt +1 -1
  64. package/dist/horizontal-scroller.cjs.js.LICENSE.txt +1 -1
  65. package/dist/horizontal-scroller.esm.js.LICENSE.txt +1 -1
  66. package/dist/image-picker.cjs.js.LICENSE.txt +1 -1
  67. package/dist/image-picker.esm.js.LICENSE.txt +1 -1
  68. package/dist/image.cjs.js +1 -1
  69. package/dist/image.cjs.js.LICENSE.txt +1 -1
  70. package/dist/image.esm.js +1 -1
  71. package/dist/image.esm.js.LICENSE.txt +1 -1
  72. package/dist/index.cjs.js +1 -1
  73. package/dist/index.cjs.js.LICENSE.txt +28 -1
  74. package/dist/index.d.ts +1 -1
  75. package/dist/index.esm.js +1 -1
  76. package/dist/index.esm.js.LICENSE.txt +28 -1
  77. package/dist/keyframe-animation.cjs.js.LICENSE.txt +1 -1
  78. package/dist/keyframe-animation.esm.js.LICENSE.txt +1 -1
  79. package/dist/link-getter.cjs.js +1 -1
  80. package/dist/link-getter.cjs.js.LICENSE.txt +1 -1
  81. package/dist/link-getter.esm.js +1 -1
  82. package/dist/link-getter.esm.js.LICENSE.txt +1 -1
  83. package/dist/link.cjs.js +1 -1
  84. package/dist/link.cjs.js.LICENSE.txt +1 -1
  85. package/dist/link.esm.js +1 -1
  86. package/dist/link.esm.js.LICENSE.txt +1 -1
  87. package/dist/meta-adder.cjs.js.LICENSE.txt +1 -1
  88. package/dist/meta-adder.esm.js.LICENSE.txt +1 -1
  89. package/dist/modal-2025.cjs.js.LICENSE.txt +1 -1
  90. package/dist/modal-2025.esm.js.LICENSE.txt +1 -1
  91. package/dist/multiswitcher.cjs.js +1 -1
  92. package/dist/multiswitcher.cjs.js.LICENSE.txt +1 -1
  93. package/dist/multiswitcher.esm.js +1 -1
  94. package/dist/multiswitcher.esm.js.LICENSE.txt +1 -1
  95. package/dist/new-nav-bar.cjs.js.LICENSE.txt +1 -1
  96. package/dist/new-nav-bar.esm.js.LICENSE.txt +1 -1
  97. package/dist/picker.cjs.js.LICENSE.txt +1 -1
  98. package/dist/picker.esm.js.LICENSE.txt +1 -1
  99. package/dist/progress.cjs.js.LICENSE.txt +1 -1
  100. package/dist/progress.esm.js.LICENSE.txt +1 -1
  101. package/dist/radio.cjs.js.LICENSE.txt +1 -1
  102. package/dist/radio.esm.js.LICENSE.txt +1 -1
  103. package/dist/range.cjs.js.LICENSE.txt +1 -1
  104. package/dist/range.esm.js.LICENSE.txt +1 -1
  105. package/dist/scroll-video.cjs.js.LICENSE.txt +1 -1
  106. package/dist/scroll-video.esm.js.LICENSE.txt +1 -1
  107. package/dist/side-bar.cjs.js.LICENSE.txt +1 -1
  108. package/dist/side-bar.esm.js.LICENSE.txt +1 -1
  109. package/dist/side-nav-bar.cjs.js.LICENSE.txt +1 -1
  110. package/dist/side-nav-bar.esm.js.LICENSE.txt +1 -1
  111. package/dist/simple-bar.cjs.js.LICENSE.txt +1 -1
  112. package/dist/simple-bar.esm.js.LICENSE.txt +1 -1
  113. package/dist/slider-2025.cjs.js +1 -1
  114. package/dist/slider-2025.cjs.js.LICENSE.txt +1 -1
  115. package/dist/slider-2025.esm.js +1 -1
  116. package/dist/slider-2025.esm.js.LICENSE.txt +1 -1
  117. package/dist/spacer.cjs.js.LICENSE.txt +1 -1
  118. package/dist/spacer.esm.js.LICENSE.txt +1 -1
  119. package/dist/stack.cjs.js.LICENSE.txt +1 -1
  120. package/dist/stack.esm.js.LICENSE.txt +1 -1
  121. package/dist/stacker.cjs.js.LICENSE.txt +1 -1
  122. package/dist/stacker.esm.js.LICENSE.txt +1 -1
  123. package/dist/table.cjs.js.LICENSE.txt +1 -1
  124. package/dist/table.esm.js.LICENSE.txt +1 -1
  125. package/dist/text-field.cjs.js.LICENSE.txt +1 -1
  126. package/dist/text-field.esm.js.LICENSE.txt +1 -1
  127. package/dist/text.cjs.js +1 -1
  128. package/dist/text.cjs.js.LICENSE.txt +1 -1
  129. package/dist/text.esm.js +1 -1
  130. package/dist/text.esm.js.LICENSE.txt +1 -1
  131. package/dist/theme.cjs.js.LICENSE.txt +1 -1
  132. package/dist/theme.esm.js.LICENSE.txt +1 -1
  133. package/dist/transform-anim.cjs.js.LICENSE.txt +1 -1
  134. package/dist/transform-anim.esm.js.LICENSE.txt +1 -1
  135. package/dist/ulist.cjs.js +1 -1
  136. package/dist/ulist.cjs.js.LICENSE.txt +1 -1
  137. package/dist/ulist.esm.js +1 -1
  138. package/dist/ulist.esm.js.LICENSE.txt +1 -1
  139. package/dist/video.cjs.js +1 -1
  140. package/dist/video.cjs.js.LICENSE.txt +1 -1
  141. package/dist/video.esm.js +1 -1
  142. package/dist/video.esm.js.LICENSE.txt +1 -1
  143. package/dist/wrap.cjs.js.LICENSE.txt +1 -1
  144. package/dist/wrap.esm.js.LICENSE.txt +1 -1
  145. package/dist/zoom-card.cjs.js.LICENSE.txt +1 -1
  146. package/dist/zoom-card.esm.js.LICENSE.txt +1 -1
  147. package/layout/animator.js +1 -1
  148. package/layout/audio.js +1 -1
  149. package/layout/audionew.js +3 -2
  150. package/layout/base.js +1 -1
  151. package/layout/beta-desktop-bar.js +1 -1
  152. package/layout/beta-mobile-bar.js +1 -1
  153. package/layout/button.js +9 -7
  154. package/layout/center.js +1 -1
  155. package/layout/checkbox.js +3 -2
  156. package/layout/circle.js +1 -1
  157. package/layout/code.js +5 -11
  158. package/layout/container.js +14 -14
  159. package/layout/dropdown-2025.js +3 -2
  160. package/layout/flex-card.js +1 -1
  161. package/layout/flex-grid.js +4 -3
  162. package/layout/flex-row.js +3 -9
  163. package/layout/form-components/custom.js +1 -1
  164. package/layout/form-components/data-list.js +1 -1
  165. package/layout/form-components/floating-input.js +1 -1
  166. package/layout/form-components/form-all.js +1 -1
  167. package/layout/form-components/form.js +1 -1
  168. package/layout/form-components/image-picker.js +1 -1
  169. package/layout/form-components/picker.js +1 -1
  170. package/layout/form-components/radio.js +1 -1
  171. package/layout/form-components/radiogroup.js +1 -1
  172. package/layout/form-components/range.js +1 -1
  173. package/layout/free.js +1 -1
  174. package/layout/grid-overlay.js +1 -1
  175. package/layout/grid-switcher.js +1 -1
  176. package/layout/grid.js +1 -1
  177. package/layout/horizontal-scroller.js +1 -1
  178. package/layout/image.js +18 -17
  179. package/layout/index.js +1 -1
  180. package/layout/link.js +12 -12
  181. package/layout/list.js +1 -1
  182. package/layout/meta-adder.js +1 -1
  183. package/layout/modal-2025.js +1 -1
  184. package/layout/morph.js +1 -1
  185. package/layout/multiswitcher.js +3 -2
  186. package/layout/nav-bar.js +1 -1
  187. package/layout/nav-factor/custom-div.js +1 -1
  188. package/layout/new-nav-bar.js +1 -1
  189. package/layout/polygon.js +1 -1
  190. package/layout/prerender-site.js +1 -1
  191. package/layout/prerender.js +1 -1
  192. package/layout/progress.js +1 -1
  193. package/layout/row.js +1 -1
  194. package/layout/scroll-video.js +1 -1
  195. package/layout/shop.js +1 -1
  196. package/layout/side-bar.js +1 -1
  197. package/layout/side-nav-bar.js +1 -1
  198. package/layout/simple-bar.js +1 -1
  199. package/layout/slider-2025.js +1 -1
  200. package/layout/spacer.js +1 -1
  201. package/layout/stack.js +1 -1
  202. package/layout/svg.js +1 -1
  203. package/layout/switcher.js +3 -2
  204. package/layout/table.js +1 -1
  205. package/layout/text-field.js +1 -1
  206. package/layout/text.js +21 -13
  207. package/layout/ulist.js +3 -2
  208. package/layout/video.js +3 -3
  209. package/layout/wrap.js +1 -1
  210. package/layout/zoom-card.js +1 -1
  211. package/lib/agent-surface.js +1 -1
  212. package/lib/card-getter.js +1 -1
  213. package/lib/check-page.js +1 -1
  214. package/lib/codegen.js +11 -2
  215. package/lib/data.js +1 -1
  216. package/lib/designer.js +4 -3
  217. package/lib/element-mapper.js +3 -2
  218. package/lib/element-params.generated.js +1 -1
  219. package/lib/grid-geometry.js +1 -1
  220. package/lib/keyframe-animation.js +1 -1
  221. package/lib/known-inert.js +1 -1
  222. package/lib/link-getter.js +1 -1
  223. package/lib/morph-node.js +1 -1
  224. package/lib/normalize-spec.js +1 -1
  225. package/lib/op-semantics.js +178 -0
  226. package/lib/parse-html.js +1 -1
  227. package/lib/raster-inspect.js +1 -1
  228. package/lib/raster-ops.js +1 -1
  229. package/lib/raster-presets.js +1 -1
  230. package/lib/react.js +1 -1
  231. package/lib/resolve-refs.js +1 -1
  232. package/lib/responsive.js +41 -1
  233. package/lib/scroll-video.js +1 -1
  234. package/lib/seo.js +1 -1
  235. package/lib/stacker.js +1 -1
  236. package/lib/suggest.js +1 -1
  237. package/lib/theme.js +1 -1
  238. package/lib/transform-anim.js +1 -1
  239. package/lib/transition.js +1 -1
  240. package/lib/validate-nodes.js +13 -2
  241. package/lib/view-transition.js +1 -1
  242. package/lib/webmcp-adapter.js +1 -1
  243. package/package.json +1 -1
  244. package/skills/nodality/SKILL.md +3 -5
  245. package/bin/dev-server.mjs +0 -200
  246. package/lib/dev-inspector.js +0 -295
  247. package/lib/dev-state.js +0 -257
  248. package/skills/nodality-apply-comments/SKILL.md +0 -52
  249. package/skills/nodality-current/SKILL.md +0 -69
package/lib/transition.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * nodality v1.5.1
2
+ * nodality v1.5.3
3
3
  * (c) 2026 Filip Vabrousek
4
4
  * License: MIT
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * nodality v1.5.1
2
+ * nodality v1.5.3
3
3
  * (c) 2026 Filip Vabrousek
4
4
  * License: MIT
5
5
  */
@@ -29,6 +29,7 @@ import {
29
29
  REGISTRY, RASTER_OP_NAMES, DRIVER_NAMES, DRIVER_DOCS, RASTER_UNITS,
30
30
  FRAMEWORK_DOC, EASING_NAMES,
31
31
  } from "./raster-ops.js";
32
+ import { OP_SEMANTICS, shadowedNodes } from "./op-semantics.js";
32
33
  import { presetNames, presetInfo } from "./raster-presets.js";
33
34
  import { collectRefs, isRef, resolveRefs } from "./resolve-refs.js";
34
35
  import { normalizeSpec, aliasConflicts, ALIASES } from "./normalize-spec.js";
@@ -194,7 +195,7 @@ const BARE_DESIGN_OPS = [
194
195
  * node that works, and `preview` refuses to render an invalid pair, so
195
196
  * over-reporting costs more than under-reporting.
196
197
  */
197
- const DESIGN_OP_NAMES = [
198
+ export const DESIGN_OP_NAMES = [
198
199
  "animation", "arrange", "background", "blast", "card-style", "filter", "gradient",
199
200
  "layout", "link-style", "margin", "navStyle", "shadow", "slayout",
200
201
  "span", "transform",
@@ -1080,6 +1081,13 @@ export function validateNodes(nodes, elements, defs) {
1080
1081
  seen.set(key, have);
1081
1082
  });
1082
1083
 
1084
+ // Nodes that can never apply under the declared combine rules
1085
+ // (lib/op-semantics.js): a later node an earlier one shadows, and ops no
1086
+ // renderer code reads. Warnings, because the page still renders.
1087
+ for (const f of shadowedNodes(nodes)) {
1088
+ warn(f.code, `nodes[${f.index}]`, f.lost, [], [], f.detail);
1089
+ }
1090
+
1083
1091
  return { ok: errors.length === 0, errors, warnings };
1084
1092
  }
1085
1093
 
@@ -1132,6 +1140,9 @@ export function describeOps() {
1132
1140
  driverDocs: DRIVER_NAMES.map((name) => ({ name, summary: DRIVER_DOCS[name] || "" })),
1133
1141
  easings: EASING_NAMES,
1134
1142
  units: RASTER_UNITS,
1143
+ // How the nodes of each op combine: first (later ones ignored),
1144
+ // sequence (all apply in order) or inert. See lib/op-semantics.js.
1145
+ semantics: OP_SEMANTICS,
1135
1146
  };
1136
1147
  }
1137
1148
 
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * nodality v1.5.1
2
+ * nodality v1.5.3
3
3
  * (c) 2026 Filip Vabrousek
4
4
  * License: MIT
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * nodality v1.5.1
2
+ * nodality v1.5.3
3
3
  * (c) 2026 Filip Vabrousek
4
4
  * License: MIT
5
5
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodality",
3
- "version": "1.5.1",
3
+ "version": "1.5.3",
4
4
  "description": "A UI is two arrays: what exists, and what is done to it. Zero-dependency declarative UI library with build-time prerendering, composable WebGL effects, and an MCP server and validator for coding agents.",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",
@@ -82,6 +82,8 @@ does not do what you wrote:
82
82
  | `BAD_PARAM_VALUE` | the value is not the shape the parameter takes — `width: 7` is not a CSS length, `mar: 7` is not `[{a: 7}]`. As an *error* where the value is provably inert; as a warning otherwise. |
83
83
  | `PARAM_NOT_ON_TYPE` | a real parameter name that THIS type does not read, so it is accepted and dropped — `keySet` on a `table`. |
84
84
  | `PARAM_INERT` | a parameter the type DOES list, and is known to ignore (the library's conformance baseline) — `size` on a `p`, `color` on a `checkbox`. The hint says what to use instead. |
85
+ | `SHADOWED_NODE` | an earlier node with the same op already decides this element (or the page), so this one does nothing there; `got` lists where it loses. Edit the earlier node instead of appending a new one. `list_ops` → `semantics` says which ops keep the first node (`first`) and which apply all in order (`sequence`). |
86
+ | `INERT_OP` | an op the validator accepts but nothing renders (`navStyle`). |
85
87
  | `STORE_AFTER_PRODUCT` / `NO_STORE` | a commerce `product` placed before the page's `store`, or with none: it renders empty. |
86
88
 
87
89
  `get_schema <type>` carries a `unit` on every parameter whose shape the
@@ -145,16 +147,12 @@ Read only what the task needs. Each file is short and stands alone.
145
147
  | checking a page before you call it done | `references/verifying.md` |
146
148
  | prerendering a static site | `references/prerender.md` |
147
149
 
148
- Four task skills sit beside this one and carry the step-by-step procedure:
150
+ Two task skills sit beside this one and carry the step-by-step procedure:
149
151
 
150
152
  - **`nodality-new-page`**: building a page from a brief, in small validated
151
153
  steps.
152
154
  - **`nodality-edit-page`**: changing one thing on a rendered page without
153
155
  regenerating it.
154
- - **`nodality-current`**: finding the element the person means by "this":
155
- what they picked in `npx nodality dev`, read fresh every turn.
156
- - **`nodality-apply-comments`**: applying the notes they left on the page
157
- in `npx nodality dev`, by element id, then resolving them.
158
156
 
159
157
  ## When NOT to use Nodality
160
158
 
@@ -1,200 +0,0 @@
1
- // bin/dev-server.mjs — `npx nodality dev`: serve the site with the inspector.
2
- //
3
- // npx nodality dev [--upload=DIR] [--port=4000] [--watch=src,pages] [--no-reload]
4
- //
5
- // Serves the upload folder (from nodality.config.json, else `upload/`) on
6
- // 127.0.0.1 only, and adds two things to every HTML page it serves:
7
- //
8
- // 1. `window.__NODALITY_DEV__`, defined before any page script runs. The
9
- // Designer sees it and annotates the page and registers its (E, N)
10
- // pair. Nothing else defines it, so a built page never carries it.
11
- // 2. lib/dev-inspector.js, the in-page toolbar (S select, C comment).
12
- //
13
- // What the person points at lands in `.nodality/` in the folder this was
14
- // started from (the project root, never the upload folder, so it is never
15
- // deployed): current.json and comments.json, read by the agent through the
16
- // MCP tools current_selection / list_comments / resolve_comment, or directly.
17
- //
18
- // A change to any file under the upload folder (or a --watch folder)
19
- // reloads the open pages, so an agent's edit shows as soon as it is built.
20
-
21
- import fs from "node:fs";
22
- import http from "node:http";
23
- import path from "node:path";
24
- import { fileURLToPath } from "node:url";
25
- import { readComments, writeCurrent, addComment, normalizePage, STATE_DIR } from "../lib/dev-state.js";
26
-
27
- const HERE = path.dirname(fileURLToPath(import.meta.url));
28
- const INSPECTOR = path.join(HERE, "..", "lib", "dev-inspector.js");
29
- const API = "/__nodality";
30
- const MAX_BODY = 64 * 1024;
31
-
32
- const TYPES = {
33
- ".html": "text/html; charset=utf-8", ".js": "text/javascript; charset=utf-8", ".mjs": "text/javascript; charset=utf-8",
34
- ".css": "text/css; charset=utf-8", ".json": "application/json; charset=utf-8", ".svg": "image/svg+xml",
35
- ".png": "image/png", ".jpg": "image/jpeg", ".jpeg": "image/jpeg", ".webp": "image/webp", ".gif": "image/gif",
36
- ".avif": "image/avif", ".ico": "image/x-icon", ".woff": "font/woff", ".woff2": "font/woff2", ".ttf": "font/ttf",
37
- ".mp4": "video/mp4", ".webm": "video/webm", ".mp3": "audio/mpeg", ".txt": "text/plain; charset=utf-8", ".xml": "application/xml",
38
- };
39
-
40
- // `sourceOf` turns a stack into the page's own line that created a component
41
- // (pages/index.js:60:5): the first frame on this origin that is not the
42
- // library (dist/, lib/, layout/, the bundle) or the inspector. It has to exist
43
- // before any page script runs, so it lives here rather than in the inspector.
44
- const SOURCE_OF = `function(stack){var ls=String(stack||"").split("\\n");for(var i=0;i<ls.length;i++){` +
45
- `var m=/(https?:\\/\\/[^\\s()]+?):(\\d+):(\\d+)/.exec(ls[i]);if(!m)continue;var u;try{u=new URL(m[1])}catch(e){continue}` +
46
- `if(u.origin!==location.origin)continue;var p=u.pathname;` +
47
- `if(/\\/(dist|lib|layout|__nodality)\\//.test(p)||/lib\\.bundle|node_modules/.test(p))continue;` +
48
- `return p.replace(/^\\//,"")+":"+m[2]+":"+m[3]}return null}`;
49
-
50
- export const DEV_SNIPPET =
51
- `<script>window.__NODALITY_DEV__=window.__NODALITY_DEV__||{pages:[],annotate:true,sourceOf:${SOURCE_OF}};</script>` +
52
- `<script src="${API}/inspector.js" defer></script>`;
53
-
54
- /** Put the snippet first inside <head>, so it runs before any page script. */
55
- export function injectDev(html) {
56
- const m = /<head(\s[^>]*)?>/i.exec(html);
57
- if (m) return html.slice(0, m.index + m[0].length) + DEV_SNIPPET + html.slice(m.index + m[0].length);
58
- const d = /<!doctype[^>]*>/i.exec(html);
59
- return d ? html.slice(0, d.index + d[0].length) + DEV_SNIPPET + html.slice(d.index + d[0].length) : DEV_SNIPPET + html;
60
- }
61
-
62
- function send(res, status, body, type = "application/json; charset=utf-8") {
63
- res.writeHead(status, { "content-type": type, "cache-control": "no-store" });
64
- res.end(typeof body === "string" || Buffer.isBuffer(body) ? body : JSON.stringify(body));
65
- }
66
-
67
- function readBody(req) {
68
- return new Promise((resolve, reject) => {
69
- let size = 0;
70
- const chunks = [];
71
- req.on("data", (c) => {
72
- size += c.length;
73
- if (size > MAX_BODY) { reject(new Error("too large")); req.destroy(); return; }
74
- chunks.push(c);
75
- });
76
- req.on("end", () => {
77
- try { resolve(JSON.parse(Buffer.concat(chunks).toString("utf8") || "{}")); } catch { reject(new Error("bad json")); }
78
- });
79
- req.on("error", reject);
80
- });
81
- }
82
-
83
- // Only a page served from this machine's own name may read or write. The Host
84
- // header is checked against loopback names first: with DNS rebinding an
85
- // attacker's name resolves to 127.0.0.1 and sends its own Host, so comparing
86
- // Origin with Host alone would let it read upload/ and post notes.
87
- const LOOPBACK = new Set(["localhost", "127.0.0.1", "[::1]"]);
88
- function loopbackHost(req) {
89
- try { return LOOPBACK.has(new URL(`http://${req.headers.host || ""}`).hostname); } catch { return false; }
90
- }
91
- // Browsers send Origin on cross-site POSTs, so a foreign one is refused too.
92
- function sameOrigin(req) {
93
- const o = req.headers.origin;
94
- if (!o) return true;
95
- try { return new URL(o).host === req.headers.host; } catch { return false; }
96
- }
97
-
98
- /**
99
- * The server, not yet listening — so tests can bind it to port 0.
100
- * @param {{ root: string, upload: string }} opts
101
- */
102
- export function createDevServer({ root, upload }) {
103
- const uploadDir = path.resolve(upload);
104
- const clients = new Set();
105
-
106
- const server = http.createServer(async (req, res) => {
107
- const url = new URL(req.url, "http://localhost");
108
- const p = url.pathname;
109
- if (!loopbackHost(req)) return send(res, 403, "nodality dev answers to localhost only", TYPES[".txt"]);
110
- try {
111
- if (p === `${API}/inspector.js`) return send(res, 200, fs.readFileSync(INSPECTOR), TYPES[".js"]);
112
- if (p === `${API}/events`) {
113
- res.writeHead(200, { "content-type": "text/event-stream", "cache-control": "no-store", connection: "keep-alive" });
114
- res.write(": nodality dev\n\n");
115
- clients.add(res);
116
- req.on("close", () => clients.delete(res));
117
- return;
118
- }
119
- if (p === `${API}/comments` && req.method === "GET") {
120
- const page = normalizePage(url.searchParams.get("page") || "/");
121
- return send(res, 200, readComments(root).filter((c) => normalizePage(c.page) === page));
122
- }
123
- if ((p === `${API}/current` || p === `${API}/comments`) && req.method === "POST") {
124
- if (!sameOrigin(req)) return send(res, 403, { ok: false, error: { code: "FOREIGN_ORIGIN" } });
125
- let body;
126
- try { body = await readBody(req); } catch (e) { return send(res, 400, { ok: false, error: { code: "BAD_BODY", detail: e.message } }); }
127
- if (p === `${API}/current`) return send(res, 200, { ok: true, current: writeCurrent(root, body, { uploadDir }) });
128
- const r = addComment(root, body, { uploadDir });
129
- return send(res, r.ok ? 200 : 400, r);
130
- }
131
- if (p.startsWith(API)) return send(res, 404, { ok: false, error: { code: "NOT_FOUND" } });
132
- if (req.method !== "GET" && req.method !== "HEAD") return send(res, 405, "method not allowed", TYPES[".txt"]);
133
-
134
- // Static files, confined to the upload folder.
135
- let rel;
136
- try { rel = decodeURIComponent(p); } catch { return send(res, 400, "bad path", TYPES[".txt"]); }
137
- let file = path.resolve(uploadDir, "." + path.posix.normalize("/" + rel));
138
- if (file !== uploadDir && !file.startsWith(uploadDir + path.sep)) return send(res, 403, "outside the upload folder", TYPES[".txt"]);
139
- if (fs.existsSync(file) && fs.statSync(file).isDirectory()) file = path.join(file, "index.html");
140
- if (!fs.existsSync(file) && !path.extname(file) && fs.existsSync(file + ".html")) file += ".html";
141
- if (!fs.existsSync(file) || !fs.statSync(file).isFile()) return send(res, 404, "not found", TYPES[".txt"]);
142
- const ext = path.extname(file).toLowerCase();
143
- if (ext === ".html") return send(res, 200, injectDev(fs.readFileSync(file, "utf8")), TYPES[".html"]);
144
- return send(res, 200, fs.readFileSync(file), TYPES[ext] || "application/octet-stream");
145
- } catch (e) {
146
- return send(res, 500, { ok: false, error: { code: "DEV_SERVER_FAILED", detail: String(e && e.message || e) } });
147
- }
148
- });
149
-
150
- server.reload = () => { for (const c of clients) c.write("event: reload\ndata: {}\n\n"); };
151
- server.uploadDir = uploadDir;
152
- return server;
153
- }
154
-
155
- function watchForReload(server, dirs) {
156
- let timer = null;
157
- const fire = (file) => {
158
- if (file && (String(file).includes(STATE_DIR) || /\.tmp$/.test(String(file)))) return;
159
- clearTimeout(timer);
160
- timer = setTimeout(() => server.reload(), 150);
161
- };
162
- const watchers = [];
163
- for (const d of dirs) {
164
- try { watchers.push(fs.watch(d, { recursive: true }, (_e, f) => fire(f))); }
165
- catch (e) { console.warn(`[nodality] dev: cannot watch ${d} (${e.message}); reload by hand there`); }
166
- }
167
- server.on("close", () => watchers.forEach((w) => w.close()));
168
- }
169
-
170
- export async function runDev(args) {
171
- const flag = (name) => { const a = args.find((x) => x.startsWith(`--${name}=`)); return a ? a.slice(name.length + 3) : null; };
172
- const root = process.cwd();
173
- let upload = flag("upload");
174
- if (!upload) {
175
- try { upload = JSON.parse(fs.readFileSync(path.join(root, "nodality.config.json"), "utf8")).uploadDir; } catch {}
176
- }
177
- upload = path.resolve(root, upload || "upload");
178
- if (!fs.existsSync(upload)) {
179
- console.error(`[nodality] dev: no upload folder at ${upload}. Pass --upload=DIR.`);
180
- process.exitCode = 1;
181
- return;
182
- }
183
- const port = Number(flag("port") || 4000);
184
- const server = createDevServer({ root, upload });
185
- if (!args.includes("--no-reload")) {
186
- const extra = (flag("watch") || "").split(",").filter(Boolean).map((d) => path.resolve(root, d));
187
- watchForReload(server, [upload, ...extra]);
188
- }
189
- await new Promise((resolve, reject) => {
190
- server.once("error", reject);
191
- server.listen(port, "127.0.0.1", resolve);
192
- }).catch((e) => {
193
- console.error(`[nodality] dev: cannot listen on 127.0.0.1:${port} (${e.code || e.message}). Try --port=4001.`);
194
- process.exit(1);
195
- });
196
- console.log(`[nodality] dev: http://localhost:${server.address().port}/ (serving ${path.relative(root, upload) || "."})`);
197
- console.log(`[nodality] dev: S select · C comment · Esc off. Picks and notes go to ${path.join(STATE_DIR, "current.json")} and ${path.join(STATE_DIR, "comments.json")}.`);
198
- console.log(`[nodality] dev: add ${STATE_DIR}/ to .gitignore if the notes should stay on this machine.`);
199
- await new Promise(() => {});
200
- }
@@ -1,295 +0,0 @@
1
- /*!
2
- * nodality v1.5.1
3
- * (c) 2026 Filip Vabrousek
4
- * License: MIT
5
- */
6
-
7
- /*!
8
- * dev-inspector.js — the in-page half of `nodality dev`.
9
- *
10
- * Served by the dev server only; never imported, never bundled, never in a
11
- * built page. It lets a person point at what they mean and leaves the
12
- * meaning in two files an agent reads (see lib/dev-state.js):
13
- *
14
- * S select: click an element → .nodality/current.json
15
- * C comment: click an element, or drag across several, and type a
16
- * note → .nodality/comments.json
17
- * Esc off: the page behaves as a page again (the starting state)
18
- *
19
- * It finds elements by their `id`, which every Nodality element renders, and
20
- * reads the (E, N) pair the Designer registers in __NODALITY_DEV__.pages to
21
- * report which nodes target the pick and which width ranges are in force.
22
- * Everything it draws lives in one shadow root, so page styles cannot reach
23
- * it and it never edits the page's own nodes.
24
- */
25
- (function () {
26
- if (typeof window === "undefined" || window.__NODALITY_INSPECTOR__) return;
27
- window.__NODALITY_INSPECTOR__ = true;
28
- const DEV = (window.__NODALITY_DEV__ = window.__NODALITY_DEV__ || { pages: [], annotate: true });
29
- const API = "/__nodality";
30
- const PAGE = location.pathname;
31
-
32
- // ── the pair: id → spec, node indexes, ranges ──────────────────────
33
- let index = new Map();
34
- const bare = (s) => (typeof s === "string" ? s.replace(/^#/, "") : null);
35
- function names(v, out) {
36
- if (typeof v === "string") out.push(bare(v));
37
- else if (Array.isArray(v)) v.forEach((x) => names(x, out));
38
- else if (v && typeof v === "object") Object.values(v).forEach((x) => names(x, out));
39
- return out;
40
- }
41
- function walk(list, visit) {
42
- for (const el of Array.isArray(list) ? list : []) {
43
- if (Array.isArray(el)) { walk(el, visit); continue; }
44
- if (!el || typeof el !== "object") continue;
45
- if (typeof el.id === "string") visit(el);
46
- walk(el.children, visit);
47
- if (Array.isArray(el.items)) walk(el.items, visit);
48
- }
49
- }
50
- function rebuild() {
51
- index = new Map();
52
- for (const pg of DEV.pages) {
53
- walk(pg.elements, (el) => { if (!index.has(el.id)) index.set(el.id, { spec: el, nodes: [], ranges: [] }); });
54
- (pg.nodes || []).forEach((n, i) => {
55
- if (!n || typeof n !== "object") return;
56
- const hit = names([n.target, n.from, n.to], []);
57
- if (Array.isArray(n.chain)) n.chain.forEach((e) => names([e && e.from, e && e.to], hit));
58
- for (const id of new Set(hit)) {
59
- const rec = index.get(id);
60
- if (!rec) continue;
61
- rec.nodes.push(i);
62
- if (Array.isArray(n.range)) rec.ranges.push({ node: i, range: n.range });
63
- }
64
- });
65
- }
66
- }
67
- window.addEventListener("nodality:rendered", () => { rebuild(); drawPins(); });
68
-
69
- // ── shadow UI ──────────────────────────────────────────────────────
70
- const host = document.createElement("div");
71
- host.setAttribute("data-nodality", "dev-inspector");
72
- host.style.cssText = "position:fixed;inset:0;pointer-events:none;z-index:2147483647";
73
- const root = host.attachShadow({ mode: "open" });
74
- root.innerHTML = `<style>
75
- :host{all:initial}
76
- *{box-sizing:border-box;font:12px/1.4 -apple-system,system-ui,sans-serif}
77
- .box{position:fixed;border:1.5px solid #378ADD;border-radius:3px;display:none;pointer-events:none}
78
- .box.sel{border:2px solid #185FA5;background:rgba(55,138,221,.08)}
79
- .lab{position:absolute;top:-20px;left:-2px;background:#185FA5;color:#fff;padding:1px 6px;border-radius:3px;white-space:nowrap;font:11px ui-monospace,Menlo,monospace}
80
- .drag{position:fixed;border:1.5px dashed #BA7517;background:rgba(239,159,39,.08);display:none}
81
- .pin{position:fixed;width:18px;height:18px;border-radius:50%;background:#FAC775;color:#633806;border:1px solid #BA7517;display:flex;align-items:center;justify-content:center;font-size:11px;pointer-events:auto;cursor:default}
82
- .bar{position:fixed;right:12px;bottom:12px;background:#fff;color:#2C2C2A;border:1px solid #D3D1C7;border-radius:10px;padding:6px;display:flex;flex-direction:column;gap:6px;pointer-events:auto;min-width:220px}
83
- .row{display:flex;gap:6px;align-items:center}
84
- button{border:1px solid #D3D1C7;background:#fff;color:#2C2C2A;border-radius:6px;padding:3px 8px;cursor:pointer}
85
- button.on{background:#E6F1FB;color:#0C447C;border-color:#378ADD}
86
- .st{color:#5F5E5A;margin-left:auto;font-size:11px}
87
- input{flex:1;border:1px solid #B4B2A9;border-radius:6px;padding:4px 6px;min-width:0}
88
- .err{color:#A32D2D;font-size:11px}
89
- .note{display:none}
90
- </style>
91
- <div class="box" id="hover"><span class="lab"></span></div>
92
- <div class="box sel" id="sel"><span class="lab"></span></div>
93
- <div class="drag" id="drag"></div>
94
- <div id="pins"></div>
95
- <div class="bar">
96
- <div class="row"><button id="bS">Select (S)</button><button id="bC">Comment (C)</button><span class="st" id="st"></span></div>
97
- <div class="row note" id="noteRow"><input id="note" maxlength="2000" placeholder="what should change here?"><button id="add">Add</button></div>
98
- <div class="err" id="err"></div>
99
- </div>`;
100
- const $ = (id) => root.getElementById(id);
101
- const mount = () => { if (!host.isConnected) document.body.appendChild(host); };
102
- if (document.body) mount(); else document.addEventListener("DOMContentLoaded", mount);
103
-
104
- let mode = "off";
105
- let pending = null; // { target: [ids], rect } awaiting a note
106
- function setMode(m) {
107
- mode = mode === m ? "off" : m;
108
- $("bS").classList.toggle("on", mode === "select");
109
- $("bC").classList.toggle("on", mode === "comment");
110
- if (mode !== "comment") { pending = null; $("noteRow").style.display = "none"; }
111
- $("hover").style.display = "none";
112
- status();
113
- }
114
- function status(msg) {
115
- $("st").textContent = msg || `${mode === "off" ? "off" : mode} · ${innerWidth}px`;
116
- }
117
- $("bS").onclick = () => setMode("select");
118
- $("bC").onclick = () => setMode("comment");
119
- status();
120
-
121
- // ── finding what was pointed at ─────────────────────────────────────
122
- const ours = (e) => e.composedPath && e.composedPath().includes(host);
123
- // An element is addressable by an id from the pair (or any id, on a page
124
- // with no pair), or — on a page written with the imperative layer — by the
125
- // line that created it (data-nod-src, set in dev by the component base).
126
- const idOk = (n) => n.id && n !== host && (index.size === 0 || index.has(n.id));
127
- const srcOf = (n) => (n.getAttribute && n.getAttribute("data-nod-src")) || null;
128
- function known(node) {
129
- for (let n = node; n && n !== document.documentElement; n = n.parentElement) {
130
- if (idOk(n) || srcOf(n)) return n;
131
- }
132
- return null;
133
- }
134
- function label(node) {
135
- const rec = idOk(node) ? index.get(node.id) : null;
136
- const kind = (rec && rec.spec.type) || node.tagName.toLowerCase();
137
- if (idOk(node)) return `#${node.id} · ${kind}`;
138
- return `${srcOf(node).replace(/:\d+$/, "")} · ${kind}`;
139
- }
140
- function place(box, node) {
141
- const r = node.getBoundingClientRect();
142
- Object.assign(box.style, { display: "block", left: r.left - 3 + "px", top: r.top - 3 + "px", width: r.width + 6 + "px", height: r.height + 6 + "px" });
143
- box.querySelector(".lab").textContent = label(node);
144
- }
145
- function describe(nodes) {
146
- const first = nodes[0];
147
- const rec = (idOk(first) && index.get(first.id)) || { spec: {}, nodes: [], ranges: [] };
148
- const w = innerWidth;
149
- return {
150
- ids: nodes.filter(idOk).map((n) => n.id),
151
- src: srcOf(first),
152
- type: rec.spec.type || null,
153
- tag: first.tagName.toLowerCase(),
154
- text: (first.textContent || "").replace(/\s+/g, " ").trim().slice(0, 120),
155
- nodesTargeting: rec.nodes,
156
- activeRanges: rec.ranges.filter(({ range: [a, b] }) => w >= (a ?? 0) && w <= (b ?? Infinity)),
157
- };
158
- }
159
- const post = (path, body) => fetch(API + path, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(body) })
160
- .then((r) => r.json()).catch(() => ({ ok: false }));
161
- const viewport = () => ({ width: innerWidth, height: innerHeight });
162
-
163
- // ── select ─────────────────────────────────────────────────────────
164
- let selected = null;
165
- function select(node) {
166
- selected = node;
167
- place($("sel"), node);
168
- post("/current", { page: PAGE, viewport: viewport(), selection: describe([node]) })
169
- .then((r) => status(r.ok ? `picked ${label(node).split(" · ")[0]}` : "could not save the pick"));
170
- }
171
-
172
- // ── comment: click one element, or drag across several ─────────────
173
- let drag = null;
174
- let skipClick = false; // the click a finished drag also fires
175
- function askNote(target, rect, src) {
176
- pending = { target, rect, src: src || null };
177
- $("noteRow").style.display = "flex";
178
- $("err").textContent = "";
179
- $("note").value = "";
180
- $("note").focus();
181
- status(`note on ${target.length ? target.map((t) => "#" + t).join(", ") : String(src).replace(/:\d+$/, "")}`);
182
- }
183
- function addNote() {
184
- const note = $("note").value.trim();
185
- if (!note) { $("err").textContent = "Write a note first."; return; }
186
- post("/comments", { page: PAGE, viewport: viewport(), target: pending.target, rect: pending.rect, src: pending.src, note })
187
- .then((r) => {
188
- if (!r.ok) { $("err").textContent = "The note was not saved."; return; }
189
- pending = null;
190
- $("noteRow").style.display = "none";
191
- status("note saved");
192
- loadPins();
193
- });
194
- }
195
- $("add").onclick = addNote;
196
- $("note").addEventListener("keydown", (e) => { if (e.key === "Enter") addNote(); e.stopPropagation(); });
197
- $("note").addEventListener("input", () => { $("err").textContent = ""; });
198
-
199
- // ── pins ───────────────────────────────────────────────────────────
200
- let pins = [];
201
- function loadPins() {
202
- fetch(`${API}/comments?page=${encodeURIComponent(PAGE)}`).then((r) => r.json())
203
- .then((list) => { pins = (Array.isArray(list) ? list : []).filter((c) => c.status === "open"); drawPins(); })
204
- .catch(() => {});
205
- }
206
- function drawPins() {
207
- const box = $("pins");
208
- box.textContent = "";
209
- pins.forEach((c, i) => {
210
- const node = c.target.length ? document.getElementById(c.target[0])
211
- : c.source ? [...document.querySelectorAll("[data-nod-src]")].find((n) => srcOf(n).startsWith(`${c.source.file}:${c.source.line}:`)) : null;
212
- if (!node) return;
213
- const r = node.getBoundingClientRect();
214
- const p = document.createElement("div");
215
- p.className = "pin";
216
- p.textContent = String(i + 1);
217
- p.title = c.note;
218
- p.style.left = r.right - 9 + "px";
219
- p.style.top = r.top - 9 + "px";
220
- box.appendChild(p);
221
- });
222
- }
223
- let raf = 0;
224
- const redraw = () => {
225
- cancelAnimationFrame(raf);
226
- raf = requestAnimationFrame(() => { drawPins(); if (selected && selected.isConnected) place($("sel"), selected); status(); });
227
- };
228
- addEventListener("scroll", redraw, true);
229
- addEventListener("resize", redraw);
230
-
231
- // ── events: capture phase, so the page never sees an inspector click ──
232
- document.addEventListener("mousemove", (e) => {
233
- if (mode === "off" || ours(e)) return;
234
- if (drag) {
235
- const x = Math.min(drag.x, e.clientX), y = Math.min(drag.y, e.clientY);
236
- const w = Math.abs(e.clientX - drag.x), h = Math.abs(e.clientY - drag.y);
237
- if (w + h > 6) { drag.moved = true; Object.assign($("drag").style, { display: "block", left: x + "px", top: y + "px", width: w + "px", height: h + "px" }); }
238
- return;
239
- }
240
- const node = known(e.target);
241
- if (node) place($("hover"), node); else $("hover").style.display = "none";
242
- }, true);
243
- document.addEventListener("mousedown", (e) => {
244
- if (mode !== "comment" || ours(e)) return;
245
- e.preventDefault();
246
- drag = { x: e.clientX, y: e.clientY, moved: false };
247
- }, true);
248
- document.addEventListener("mouseup", (e) => {
249
- if (!drag) return;
250
- const d = drag; drag = null;
251
- $("drag").style.display = "none";
252
- if (!d.moved) return;
253
- skipClick = true;
254
- const box = { l: Math.min(d.x, e.clientX), t: Math.min(d.y, e.clientY), r: Math.max(d.x, e.clientX), b: Math.max(d.y, e.clientY) };
255
- const inside = [...document.querySelectorAll("[id], [data-nod-src]")].filter((n) => {
256
- if (n === host || !(idOk(n) || srcOf(n))) return false;
257
- const r = n.getBoundingClientRect();
258
- return r.width > 0 && r.left >= box.l && r.right <= box.r && r.top >= box.t && r.bottom <= box.b;
259
- });
260
- const outer = inside.filter((n) => !inside.some((m) => m !== n && m.contains(n)));
261
- if (!outer.length) { status("nothing addressable inside that area"); return; }
262
- askNote(outer.filter(idOk).map((n) => n.id), { x: box.l + scrollX, y: box.t + scrollY, w: box.r - box.l, h: box.b - box.t }, srcOf(outer[0]));
263
- }, true);
264
- document.addEventListener("click", (e) => {
265
- if (mode === "off" || ours(e)) return;
266
- e.preventDefault();
267
- e.stopPropagation();
268
- if (skipClick) { skipClick = false; return; }
269
- const node = known(e.target);
270
- if (!node) { status("nothing addressable here: no id, no source line"); return; }
271
- if (mode === "select") select(node);
272
- else askNote(idOk(node) ? [node.id] : [], null, srcOf(node));
273
- }, true);
274
- document.addEventListener("keydown", (e) => {
275
- if (ours(e)) return;
276
- const t = e.target;
277
- if (t && (t.isContentEditable || /^(INPUT|TEXTAREA|SELECT)$/.test(t.tagName))) return;
278
- if (e.metaKey || e.ctrlKey || e.altKey) return;
279
- if (e.key === "s" || e.key === "S") setMode("select");
280
- else if (e.key === "c" || e.key === "C") setMode("comment");
281
- else if (e.key === "Escape" && mode !== "off") setMode(mode);
282
- }, true);
283
-
284
- // ── reload when the site changes; report the page on arrival ───────
285
- try {
286
- const es = new EventSource(`${API}/events`);
287
- es.addEventListener("reload", () => location.reload());
288
- } catch { /* no live reload; everything else still works */ }
289
- rebuild();
290
- addEventListener("load", () => {
291
- rebuild();
292
- loadPins();
293
- post("/current", { page: PAGE, viewport: viewport(), selection: null });
294
- });
295
- })();