@almadar/shell-web 0.0.0-stage → 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.
Files changed (274) hide show
  1. package/bundling.d.mts +18 -0
  2. package/bundling.mjs +28 -0
  3. package/dist/ArbitraryClassCompiler-Mzabq-UB.d.ts +100 -0
  4. package/dist/AvlGlyph-JKJOAH23.js +6 -0
  5. package/dist/AvlStateMachine-PI4YGREK.js +8 -0
  6. package/dist/AvlTransitionDetail-ZH7V24UG.js +12 -0
  7. package/dist/AvlTransitionExplainer-ZSRT7L6Y.js +13 -0
  8. package/dist/BehaviorValueFrame-6RUJXT4A.js +29 -0
  9. package/dist/BehaviorValueFrame-SSEMEBTG.css +1756 -0
  10. package/dist/BehaviorView-RFEE5J6E.js +10 -0
  11. package/dist/Canvas3DHost-_Y-5uLM_.d.ts +552 -0
  12. package/dist/EventBusProvider-CVwjkV_2.d.ts +284 -0
  13. package/dist/FileTree-BCFnBEuQ.d.ts +254 -0
  14. package/dist/FlowCanvas-3JRMNJLV.css +1756 -0
  15. package/dist/FlowCanvas-STDC4OWK.js +27 -0
  16. package/dist/GameAudioProvider-Cm9BnvmP.d.ts +93 -0
  17. package/dist/KaTeX_AMS-Regular-CYEKBG2K.woff +0 -0
  18. package/dist/KaTeX_AMS-Regular-JKX5W2C4.ttf +0 -0
  19. package/dist/KaTeX_AMS-Regular-U6PRYMIZ.woff2 +0 -0
  20. package/dist/KaTeX_Caligraphic-Bold-5QL5CMTE.woff2 +0 -0
  21. package/dist/KaTeX_Caligraphic-Bold-WZ3QSGD3.woff +0 -0
  22. package/dist/KaTeX_Caligraphic-Bold-ZTS3R3HK.ttf +0 -0
  23. package/dist/KaTeX_Caligraphic-Regular-3LKEU76G.woff +0 -0
  24. package/dist/KaTeX_Caligraphic-Regular-A7XRTZ5Q.ttf +0 -0
  25. package/dist/KaTeX_Caligraphic-Regular-KX5MEWCF.woff2 +0 -0
  26. package/dist/KaTeX_Fraktur-Bold-2QVFK6NQ.woff2 +0 -0
  27. package/dist/KaTeX_Fraktur-Bold-T4SWXBMT.woff +0 -0
  28. package/dist/KaTeX_Fraktur-Bold-WGHVTYOR.ttf +0 -0
  29. package/dist/KaTeX_Fraktur-Regular-2PEIFJSJ.woff2 +0 -0
  30. package/dist/KaTeX_Fraktur-Regular-5U4OPH2X.ttf +0 -0
  31. package/dist/KaTeX_Fraktur-Regular-PQMHCIK6.woff +0 -0
  32. package/dist/KaTeX_Main-Bold-2GA4IZIN.woff +0 -0
  33. package/dist/KaTeX_Main-Bold-W5FBVCZM.ttf +0 -0
  34. package/dist/KaTeX_Main-Bold-YP5VVQRP.woff2 +0 -0
  35. package/dist/KaTeX_Main-BoldItalic-4P4C7HJH.woff +0 -0
  36. package/dist/KaTeX_Main-BoldItalic-N4V3DX7S.woff2 +0 -0
  37. package/dist/KaTeX_Main-BoldItalic-ODMLBJJQ.ttf +0 -0
  38. package/dist/KaTeX_Main-Italic-I43T2HSR.ttf +0 -0
  39. package/dist/KaTeX_Main-Italic-RELBIK7M.woff2 +0 -0
  40. package/dist/KaTeX_Main-Italic-SASNQFN2.woff +0 -0
  41. package/dist/KaTeX_Main-Regular-ARRPAO67.woff2 +0 -0
  42. package/dist/KaTeX_Main-Regular-P5I74A2A.woff +0 -0
  43. package/dist/KaTeX_Main-Regular-W74P5G27.ttf +0 -0
  44. package/dist/KaTeX_Math-BoldItalic-6EBV3DK5.woff +0 -0
  45. package/dist/KaTeX_Math-BoldItalic-K4WTGH3J.woff2 +0 -0
  46. package/dist/KaTeX_Math-BoldItalic-VB447A4D.ttf +0 -0
  47. package/dist/KaTeX_Math-Italic-6KGCHLFN.woff2 +0 -0
  48. package/dist/KaTeX_Math-Italic-KKK3USB2.woff +0 -0
  49. package/dist/KaTeX_Math-Italic-SON4MRCA.ttf +0 -0
  50. package/dist/KaTeX_SansSerif-Bold-RRNVJFFW.woff2 +0 -0
  51. package/dist/KaTeX_SansSerif-Bold-STQ6RXC7.ttf +0 -0
  52. package/dist/KaTeX_SansSerif-Bold-X5M5EMOD.woff +0 -0
  53. package/dist/KaTeX_SansSerif-Italic-HMPFTM52.woff2 +0 -0
  54. package/dist/KaTeX_SansSerif-Italic-PSN4QKYX.woff +0 -0
  55. package/dist/KaTeX_SansSerif-Italic-WTBAZBGY.ttf +0 -0
  56. package/dist/KaTeX_SansSerif-Regular-2TL3USAE.ttf +0 -0
  57. package/dist/KaTeX_SansSerif-Regular-OQCII6EP.woff +0 -0
  58. package/dist/KaTeX_SansSerif-Regular-XIQ62X4E.woff2 +0 -0
  59. package/dist/KaTeX_Script-Regular-72OLXYNA.ttf +0 -0
  60. package/dist/KaTeX_Script-Regular-A5IFOEBS.woff +0 -0
  61. package/dist/KaTeX_Script-Regular-APUWIHLP.woff2 +0 -0
  62. package/dist/KaTeX_Size1-Regular-4HRHTS65.woff +0 -0
  63. package/dist/KaTeX_Size1-Regular-5LRUTBFT.woff2 +0 -0
  64. package/dist/KaTeX_Size1-Regular-7K6AASVL.ttf +0 -0
  65. package/dist/KaTeX_Size2-Regular-222HN3GT.ttf +0 -0
  66. package/dist/KaTeX_Size2-Regular-K5ZHAIS6.woff +0 -0
  67. package/dist/KaTeX_Size2-Regular-LELKET5D.woff2 +0 -0
  68. package/dist/KaTeX_Size3-Regular-TLFPAHDE.woff +0 -0
  69. package/dist/KaTeX_Size3-Regular-UFCO6WCA.ttf +0 -0
  70. package/dist/KaTeX_Size3-Regular-WQRQ47UD.woff2 +0 -0
  71. package/dist/KaTeX_Size4-Regular-7PGNVPQK.ttf +0 -0
  72. package/dist/KaTeX_Size4-Regular-CDMV7U5C.woff2 +0 -0
  73. package/dist/KaTeX_Size4-Regular-PKMWZHNC.woff +0 -0
  74. package/dist/KaTeX_Typewriter-Regular-3F5K6SQ6.ttf +0 -0
  75. package/dist/KaTeX_Typewriter-Regular-MJMFSK64.woff +0 -0
  76. package/dist/KaTeX_Typewriter-Regular-VBYJ4NRC.woff2 +0 -0
  77. package/dist/KernelEngineContext-BOCQoFwk.d.ts +43 -0
  78. package/dist/LayersPanel-BBQ54IVG.js +7 -0
  79. package/dist/ModuleCard-3TT2X7IW.js +7 -0
  80. package/dist/OrbInspector-K6T6O7GI.js +27 -0
  81. package/dist/OrbInspector-MHLJ6OEE.css +1756 -0
  82. package/dist/Select-mDZIwNqN.d.ts +199 -0
  83. package/dist/ServerBridge-Cm1On51b.d.ts +233 -0
  84. package/dist/ThemeContext-DJmO59xd.d.ts +147 -0
  85. package/dist/TraitValueFrame-2PJGLLVI.js +28 -0
  86. package/dist/TraitValueFrame-4G3KOUBR.css +1756 -0
  87. package/dist/UISlotContext-Dl_ewwCI.d.ts +79 -0
  88. package/dist/UISlotRenderer-JKFSX24W.js +27 -0
  89. package/dist/UISlotRenderer-KVFO6J7R.css +1756 -0
  90. package/dist/UserContext-DqWeZkUZ.d.ts +100 -0
  91. package/dist/auth/browser/index.d.ts +2 -0
  92. package/dist/auth/browser/index.js +1 -0
  93. package/dist/auth/react/index.d.ts +49 -0
  94. package/dist/auth/react/index.js +119 -0
  95. package/dist/avl/index.css +1756 -0
  96. package/dist/avl/index.d.ts +2238 -0
  97. package/dist/avl/index.js +2693 -0
  98. package/dist/avl-3d-context-BIRKWpaL.d.ts +204 -0
  99. package/dist/avl-schema-parser-CtJxJ9KU.d.ts +132 -0
  100. package/dist/avl-zoom-state-CKMVuBFg.d.ts +17 -0
  101. package/dist/chunk-2PY54Z44.js +227 -0
  102. package/dist/chunk-2QOH2HWM.js +95 -0
  103. package/dist/chunk-3BBUBJFF.js +339 -0
  104. package/dist/chunk-42FY4RYA.js +191 -0
  105. package/dist/chunk-5QTYQTPS.js +15 -0
  106. package/dist/chunk-6P3MWXYE.js +440 -0
  107. package/dist/chunk-73SRAB4P.js +1053 -0
  108. package/dist/chunk-A2LR6VQQ.js +349 -0
  109. package/dist/chunk-AILY3XPS.js +562 -0
  110. package/dist/chunk-B4BU77LT.js +432 -0
  111. package/dist/chunk-DFNZUYX4.js +378 -0
  112. package/dist/chunk-DJ433ET5.js +1327 -0
  113. package/dist/chunk-DLZF4PVE.js +24 -0
  114. package/dist/chunk-DYEKAA4L.js +787 -0
  115. package/dist/chunk-DZ42OJQC.js +176 -0
  116. package/dist/chunk-EOWMARUB.js +16 -0
  117. package/dist/chunk-EQAMU2ZC.js +14 -0
  118. package/dist/chunk-FAJDTHWC.js +98 -0
  119. package/dist/chunk-FIW6WN23.js +508 -0
  120. package/dist/chunk-FP3WIKTC.js +303 -0
  121. package/dist/chunk-G7DCAZ22.js +19 -0
  122. package/dist/chunk-GAR5TQ5B.js +199 -0
  123. package/dist/chunk-GKIFONTE.js +131 -0
  124. package/dist/chunk-GYTPOFVC.js +47155 -0
  125. package/dist/chunk-KVQS4GXU.js +328 -0
  126. package/dist/chunk-L2DEKY4J.js +97 -0
  127. package/dist/chunk-L677XGY3.js +701 -0
  128. package/dist/chunk-MBQAMMSE.js +11877 -0
  129. package/dist/chunk-P4LNHAFI.js +1051 -0
  130. package/dist/chunk-P4ZFUQFF.js +93 -0
  131. package/dist/chunk-PC7K4SK7.js +1384 -0
  132. package/dist/chunk-R5O5AUPI.js +573 -0
  133. package/dist/chunk-SGM3FASH.js +672 -0
  134. package/dist/chunk-SJGJJKBY.js +502 -0
  135. package/dist/chunk-TESBIVUA.js +11 -0
  136. package/dist/chunk-TZZBINQY.js +82 -0
  137. package/dist/chunk-U6QRZASX.js +280 -0
  138. package/dist/chunk-VFF5OO47.js +319 -0
  139. package/dist/chunk-YDNJLLG6.js +516 -0
  140. package/dist/chunk-YHMRX6YA.js +455 -0
  141. package/dist/chunk-ZO6MXAS3.js +69 -0
  142. package/dist/components/index.css +1756 -0
  143. package/dist/components/index.d.ts +11093 -0
  144. package/dist/components/index.js +1110 -0
  145. package/dist/context/index.d.ts +9 -0
  146. package/dist/context/index.js +7 -0
  147. package/dist/core.d.ts +2523 -0
  148. package/dist/core.js +2 -0
  149. package/dist/design-classes/index.cjs +429 -0
  150. package/dist/design-classes/index.d.cts +165 -0
  151. package/dist/design-classes/index.d.ts +165 -0
  152. package/dist/design-classes/index.js +397 -0
  153. package/dist/emojiItems-QGSNAABW.js +20 -0
  154. package/dist/fx-CmQjnHmT.d.ts +371 -0
  155. package/dist/hooks/index.d.ts +936 -0
  156. package/dist/hooks/index.js +7 -0
  157. package/dist/index.d.ts +486 -0
  158. package/dist/index.js +38 -0
  159. package/dist/katexPlugin-FA7NX4PE.css +1161 -0
  160. package/dist/katexPlugin-NCDKOOQY.js +2 -0
  161. package/dist/kernel-client-ZH4PSMCN.js +367 -0
  162. package/dist/kernel-wire-B4S8pnP3.d.ts +65 -0
  163. package/dist/lib/index.d.ts +602 -0
  164. package/dist/lib/index.js +1288 -0
  165. package/dist/paintDispatch-ChW5mVuK.d.ts +698 -0
  166. package/dist/parseLessonSegments-GpCeMrb2.d.ts +334 -0
  167. package/dist/perf-CKiBKbkw.d.ts +22 -0
  168. package/dist/perf-Dr28-AgT.d.ts +57 -0
  169. package/dist/prism-AIWGN2X5.js +134 -0
  170. package/dist/providers/index.css +1756 -0
  171. package/dist/providers/index.d.ts +340 -0
  172. package/dist/providers/index.js +30 -0
  173. package/dist/renderer/index.d.ts +467 -0
  174. package/dist/renderer/index.js +3 -0
  175. package/dist/runtime/index.css +1756 -0
  176. package/dist/runtime/index.d.ts +440 -0
  177. package/dist/runtime/index.js +31 -0
  178. package/dist/slot-host-CPzrxLo9.d.ts +48 -0
  179. package/dist/ssr/index.cjs +7631 -0
  180. package/dist/ssr/index.d.cts +487 -0
  181. package/dist/ssr/index.d.ts +487 -0
  182. package/dist/ssr/index.js +7599 -0
  183. package/dist/storage/browser/index.d.ts +1 -0
  184. package/dist/storage/browser/index.js +1 -0
  185. package/dist/test-support.d.ts +35 -0
  186. package/dist/test-support.js +114 -0
  187. package/dist/themeTokens-CRd8AEDF.d.ts +125 -0
  188. package/dist/three/index.css +503 -0
  189. package/dist/three/index.d.ts +1185 -0
  190. package/dist/three/index.js +3896 -0
  191. package/dist/useKeyboardRouter-Dsq553Ur.d.ts +42 -0
  192. package/dist/useUISlots-CiobNFGb.d.ts +211 -0
  193. package/dist/verification-C5pTeMJv.d.ts +66 -0
  194. package/dist/verificationRegistry-CabxhfTv.d.ts +122 -0
  195. package/dist/wrapCallbackForEvent-B9QLbhxX.d.ts +19 -0
  196. package/index.css +199 -0
  197. package/package.json +269 -3
  198. package/src/core/locales/ar.json +1263 -0
  199. package/src/core/locales/en.json +1263 -0
  200. package/src/core/locales/index.ts +54 -0
  201. package/src/core/locales/sl.json +1263 -0
  202. package/src/core/tokens/native-tokens.json +369 -0
  203. package/tailwind-compile.cjs +29 -0
  204. package/tailwind-preset.cjs +991 -0
  205. package/themes/_base.css +451 -0
  206. package/themes/_contract.md +307 -0
  207. package/themes/_fonts-kenney.css +11 -0
  208. package/themes/_fonts.css +12 -0
  209. package/themes/_foundation.css +105 -0
  210. package/themes/_head.css +22 -0
  211. package/themes/_presets.css +67 -0
  212. package/themes/almadar-heritage.css +455 -0
  213. package/themes/almadar-website.css +269 -0
  214. package/themes/almadar.css +269 -0
  215. package/themes/aqua.css +455 -0
  216. package/themes/arabesque.css +459 -0
  217. package/themes/art-deco.css +457 -0
  218. package/themes/art-nouveau.css +459 -0
  219. package/themes/atelier.css +463 -0
  220. package/themes/bauhaus.css +461 -0
  221. package/themes/bloomberg-dense.css +463 -0
  222. package/themes/blueprint.css +457 -0
  223. package/themes/clay.css +449 -0
  224. package/themes/comic.css +453 -0
  225. package/themes/constructivist.css +457 -0
  226. package/themes/corporate.css +449 -0
  227. package/themes/cyberpunk.css +453 -0
  228. package/themes/frutiger-aero.css +458 -0
  229. package/themes/game-adventure.css +201 -0
  230. package/themes/game-rpg.css +203 -0
  231. package/themes/game-sci-fi.css +201 -0
  232. package/themes/game-ui-pack.css +200 -0
  233. package/themes/gazette.css +449 -0
  234. package/themes/glass.css +457 -0
  235. package/themes/gothic.css +453 -0
  236. package/themes/index.css +21 -0
  237. package/themes/ink-wash.css +459 -0
  238. package/themes/kawaii.css +459 -0
  239. package/themes/kflow.css +310 -0
  240. package/themes/kiosk.css +449 -0
  241. package/themes/linear-clean.css +463 -0
  242. package/themes/luxury.css +451 -0
  243. package/themes/mac-classic.css +455 -0
  244. package/themes/material.css +463 -0
  245. package/themes/memphis.css +453 -0
  246. package/themes/mid-century.css +455 -0
  247. package/themes/minimalist.css +449 -0
  248. package/themes/mudcloth.css +459 -0
  249. package/themes/nata.css +310 -0
  250. package/themes/neon.css +453 -0
  251. package/themes/neumorphic.css +451 -0
  252. package/themes/newsprint.css +455 -0
  253. package/themes/notion-editorial.css +463 -0
  254. package/themes/orb.css +465 -0
  255. package/themes/pixel.css +449 -0
  256. package/themes/prism.css +309 -0
  257. package/themes/rawi.css +310 -0
  258. package/themes/retro.css +452 -0
  259. package/themes/risograph.css +463 -0
  260. package/themes/scandi.css +469 -0
  261. package/themes/sketch.css +455 -0
  262. package/themes/solarpunk.css +469 -0
  263. package/themes/steampunk.css +451 -0
  264. package/themes/swiss.css +455 -0
  265. package/themes/terminal.css +466 -0
  266. package/themes/trait-wars.css +487 -0
  267. package/themes/ukiyo-e.css +459 -0
  268. package/themes/vaporwave.css +455 -0
  269. package/themes/victorian.css +453 -0
  270. package/themes/wabi-sabi.css +459 -0
  271. package/themes/win95.css +455 -0
  272. package/themes/wireframe.css +439 -0
  273. package/themes/zine.css +455 -0
  274. package/README.md +0 -3
@@ -0,0 +1,328 @@
1
+ import { useContainerWidth, computeTraitLayout, roundedEdgePath } from './chunk-GAR5TQ5B.js';
2
+ import { AvlExplain, AvlEffectChip } from './chunk-SJGJJKBY.js';
3
+ import { gearTeethPath } from './chunk-TZZBINQY.js';
4
+ import { AVL_INK, AVL_FONT, AVL_STROKE, avlTint } from './chunk-DFNZUYX4.js';
5
+ import { domPassthrough, useTranslate, useEventBus, useMediaQuery, Box, Typography } from './chunk-MBQAMMSE.js';
6
+ import { useState, useRef, useMemo, useEffect } from 'react';
7
+ import { formatSExpr } from '@almadar/core';
8
+ import { createLogger } from '@almadar/logger';
9
+ import { jsxs, jsx } from 'react/jsx-runtime';
10
+
11
+ var log = createLogger("almadar:ui:avl:state-machine");
12
+ var MONO_CHAR = 7.3;
13
+ var BODY_CHAR = 7.6;
14
+ var NODE_H = 44;
15
+ var PILL_H = 24;
16
+ var EFFECT_CHIP = 14;
17
+ var EFFECT_GAP = 4;
18
+ var MARGIN = 28;
19
+ var MIN_SCALE = 0.85;
20
+ var MAX_SCALE = 1.25;
21
+ function effectText(effect) {
22
+ return effect.args.length === 0 ? void 0 : formatSExpr([effect.type, ...effect.args]);
23
+ }
24
+ function guardText(t) {
25
+ return t.guard === void 0 || t.guard === null ? null : formatSExpr(t.guard);
26
+ }
27
+ function pillWidth(t) {
28
+ return 20 + (guardText(t) === null ? 0 : 16) + t.event.length * MONO_CHAR + t.effects.length * (EFFECT_CHIP + EFFECT_GAP);
29
+ }
30
+ function gearDiameter(name) {
31
+ return Math.max(96, Math.round(name.length * BODY_CHAR + 40));
32
+ }
33
+ function metricsFor(nodeShape, direction) {
34
+ return {
35
+ nodeSize: (name) => nodeShape === "gear" ? { width: gearDiameter(name), height: gearDiameter(name) } : { width: Math.max(112, Math.round(name.length * BODY_CHAR + 44)), height: NODE_H },
36
+ labelSize: (t) => ({ width: pillWidth(t), height: PILL_H }),
37
+ nodeSpacing: 40,
38
+ layerSpacing: 88,
39
+ orthogonal: true,
40
+ direction
41
+ };
42
+ }
43
+ var AvlStateMachine = ({
44
+ trait,
45
+ activeState,
46
+ activeTransition,
47
+ visitedStates,
48
+ followActive = false,
49
+ stateClickEvent,
50
+ transitionClickEvent,
51
+ onTransitionClick,
52
+ selectedState,
53
+ pendingSourceState,
54
+ nodeShape = "pill",
55
+ entityFields,
56
+ direction = "ltr",
57
+ showHeader = true,
58
+ annotations,
59
+ className,
60
+ ...rest
61
+ }) => {
62
+ const passthrough = domPassthrough(rest);
63
+ const { t } = useTranslate();
64
+ const eventBus = useEventBus();
65
+ const clickable = transitionClickEvent !== void 0 || onTransitionClick !== void 0;
66
+ const reduceMotion = useMediaQuery("(prefers-reduced-motion: reduce)");
67
+ const [layout, setLayout] = useState(null);
68
+ const hostRef = useRef(null);
69
+ const hostWidth = useContainerWidth(hostRef);
70
+ const traitKey = useMemo(() => JSON.stringify(trait), [trait]);
71
+ useEffect(() => {
72
+ if (trait.states.length === 0) return;
73
+ let live = true;
74
+ computeTraitLayout(trait, metricsFor(nodeShape, direction)).then((l) => {
75
+ if (live) setLayout(l);
76
+ }).catch((error) => log.error("layout-failed", { trait: trait.name, error: error instanceof Error ? error : String(error) }));
77
+ return () => {
78
+ live = false;
79
+ };
80
+ }, [traitKey, nodeShape, direction]);
81
+ useEffect(() => {
82
+ const host = hostRef.current;
83
+ if (!followActive || layout === null || host === null || activeState === void 0) return;
84
+ const node = [...host.querySelectorAll('[data-testid="avl-sm-state"]')].find((n) => n.getAttribute("data-state") === activeState);
85
+ if (node === void 0) return;
86
+ const hostBox = host.getBoundingClientRect();
87
+ const nodeBox = node.getBoundingClientRect();
88
+ const left = host.scrollLeft + (nodeBox.left + nodeBox.width / 2) - (hostBox.left + hostBox.width / 2);
89
+ host.scrollTo({ left: Math.max(0, left), behavior: reduceMotion ? "auto" : "smooth" });
90
+ }, [followActive, layout, activeState, reduceMotion]);
91
+ const visitOrder = useMemo(() => new Map((visitedStates ?? []).map((s, i) => [s, i + 1])), [visitedStates]);
92
+ const nextFromActive = useMemo(
93
+ () => new Set(trait.transitions.filter((tr) => activeState !== void 0 && tr.from === activeState).map((tr) => tr.index)),
94
+ [trait.transitions, activeState]
95
+ );
96
+ const header = showHeader ? /* @__PURE__ */ jsxs(Box, { className: "flex flex-wrap items-baseline justify-between gap-2 pb-3", children: [
97
+ /* @__PURE__ */ jsxs(Box, { className: "flex items-baseline gap-2", children: [
98
+ /* @__PURE__ */ jsx(Typography, { variant: "body", weight: "semibold", children: trait.name }),
99
+ /* @__PURE__ */ jsxs(Typography, { variant: "caption", color: "muted", children: [
100
+ t("avl.onEntity", { entity: trait.linkedEntity }),
101
+ " \xB7 ",
102
+ t("avl.stateCount", { count: trait.states.length }),
103
+ " \xB7 ",
104
+ t("avl.transitionCount", { count: trait.transitions.length })
105
+ ] })
106
+ ] }),
107
+ /* @__PURE__ */ jsxs(Box, { className: "flex flex-wrap gap-2", children: [
108
+ entityFields && entityFields.length > 0 ? /* @__PURE__ */ jsxs(Box, { as: "span", "data-testid": "avl-sm-fields", style: { fontFamily: AVL_FONT.mono, fontSize: 12, lineHeight: "20px", color: AVL_INK.quiet }, children: [
109
+ trait.linkedEntity,
110
+ " ",
111
+ "{ ",
112
+ entityFields.join(", "),
113
+ " }"
114
+ ] }) : null,
115
+ trait.listenedEvents.map((ev) => /* @__PURE__ */ jsx(Rail, { kind: t("avl.listensRail"), event: ev }, `in-${ev}`)),
116
+ trait.emittedEvents.map((ev) => /* @__PURE__ */ jsx(Rail, { kind: t("avl.emitsRail"), event: ev }, `out-${ev}`))
117
+ ] })
118
+ ] }) : null;
119
+ if (trait.states.length === 0) {
120
+ return /* @__PURE__ */ jsxs(Box, { "data-testid": "avl-state-machine", className, style: { width: "100%" }, ...passthrough, children: [
121
+ header,
122
+ /* @__PURE__ */ jsx(Box, { "data-testid": "avl-state-machine-empty", className: "rounded-md border border-dashed p-6 text-center", style: { borderColor: AVL_INK.line }, children: /* @__PURE__ */ jsx(Typography, { variant: "caption", color: "muted", children: t("avl.noStateMachine") }) })
123
+ ] });
124
+ }
125
+ const w = layout ? layout.width + 2 * MARGIN : 0;
126
+ const h = layout ? layout.height + 2 * MARGIN : 0;
127
+ const fit = layout && hostWidth ? hostWidth / w : 1;
128
+ const scale = Math.min(MAX_SCALE, Math.max(MIN_SCALE, fit));
129
+ return /* @__PURE__ */ jsxs(Box, { "data-testid": "avl-state-machine", className, style: { width: "100%" }, ...passthrough, children: [
130
+ header,
131
+ /* @__PURE__ */ jsx(Box, { ref: hostRef, className: "overflow-x-auto", style: { width: "100%" }, children: layout ? /* @__PURE__ */ jsx(Box, { className: "relative mx-auto", style: { width: w * scale, height: h * scale }, children: /* @__PURE__ */ jsxs(Box, { className: "absolute left-0 top-0", style: { width: w, height: h, transform: `scale(${scale})`, transformOrigin: "0 0" }, children: [
132
+ /* @__PURE__ */ jsxs("svg", { width: w, height: h, className: "absolute left-0 top-0 overflow-visible", "aria-hidden": "true", children: [
133
+ /* @__PURE__ */ jsxs("defs", { children: [
134
+ /* @__PURE__ */ jsx("marker", { id: `avl-sm-head-${trait.name}`, viewBox: "0 0 10 10", refX: "9", refY: "5", markerWidth: "7", markerHeight: "7", orient: "auto-start-reverse", children: /* @__PURE__ */ jsx("path", { d: "M0 0 L10 5 L0 10z", fill: AVL_INK.quiet, fillOpacity: 0.8 }) }),
135
+ /* @__PURE__ */ jsx("marker", { id: `avl-sm-head-hot-${trait.name}`, viewBox: "0 0 10 10", refX: "9", refY: "5", markerWidth: "6", markerHeight: "6", orient: "auto-start-reverse", children: /* @__PURE__ */ jsx("path", { d: "M0 0 L10 5 L0 10z", fill: AVL_INK.focus }) })
136
+ ] }),
137
+ /* @__PURE__ */ jsxs("g", { transform: `translate(${MARGIN},${MARGIN})`, children: [
138
+ layout.nodes.filter((n) => n.isInitial).map((n) => {
139
+ const cy = n.y + n.height / 2;
140
+ const rtl = direction === "rtl";
141
+ const dot = rtl ? n.x + n.width + 18 : n.x - 18;
142
+ const d = rtl ? `M ${n.x + n.width + 13} ${cy} H ${n.x + n.width + 1}` : `M ${n.x - 13} ${cy} H ${n.x - 1}`;
143
+ return /* @__PURE__ */ jsxs("g", { children: [
144
+ /* @__PURE__ */ jsx("circle", { cx: dot, cy, r: 5, fill: AVL_INK.text }),
145
+ /* @__PURE__ */ jsx("path", { d, stroke: AVL_INK.quiet, strokeWidth: AVL_STROKE.wire, markerEnd: `url(#avl-sm-head-${trait.name})` })
146
+ ] }, `init-${n.id}`);
147
+ }),
148
+ layout.edges.map((e) => {
149
+ const fired = e.index === activeTransition;
150
+ return /* @__PURE__ */ jsx(
151
+ "path",
152
+ {
153
+ "data-testid": "avl-sm-wire",
154
+ "data-event": e.event,
155
+ "data-fired": fired ? "true" : "false",
156
+ d: roundedEdgePath(e.points, 10),
157
+ fill: "none",
158
+ stroke: fired ? AVL_INK.focus : AVL_INK.quiet,
159
+ strokeOpacity: fired ? 1 : 0.55,
160
+ strokeWidth: fired ? AVL_STROKE.active : AVL_STROKE.wire,
161
+ strokeDasharray: fired ? "8 6" : e.isBackward || e.isSelf ? "5 4" : void 0,
162
+ markerEnd: `url(#avl-sm-head${fired ? "-hot" : ""}-${trait.name})`,
163
+ children: fired && !reduceMotion ? /* @__PURE__ */ jsx("animate", { attributeName: "stroke-dashoffset", from: "0", to: "-14", dur: "0.8s", repeatCount: "indefinite" }) : null
164
+ },
165
+ e.id
166
+ );
167
+ }),
168
+ layout.nodes.filter((n) => n.id === activeState).map((n) => /* @__PURE__ */ jsx(
169
+ "rect",
170
+ {
171
+ x: n.x - 5,
172
+ y: n.y - 5,
173
+ width: n.width + 10,
174
+ height: n.height + 10,
175
+ rx: 12,
176
+ fill: "none",
177
+ stroke: AVL_INK.focus,
178
+ strokeWidth: 4,
179
+ strokeOpacity: 0.22,
180
+ children: !reduceMotion ? /* @__PURE__ */ jsx("animate", { attributeName: "stroke-opacity", values: "0.28;0.06;0.28", dur: "1.6s", repeatCount: "indefinite" }) : null
181
+ },
182
+ `ring-${n.id}`
183
+ ))
184
+ ] })
185
+ ] }),
186
+ layout.edges.map((e) => {
187
+ const tr = trait.transitions.find((x) => x.index === e.index);
188
+ if (!tr) return null;
189
+ const fired = e.index === activeTransition;
190
+ const next = !fired && nextFromActive.has(e.index);
191
+ const guard = guardText(tr);
192
+ const pw = pillWidth(tr);
193
+ return /* @__PURE__ */ jsx(
194
+ Box,
195
+ {
196
+ "data-testid": "avl-sm-label",
197
+ "data-event": tr.event,
198
+ role: clickable ? "button" : void 0,
199
+ tabIndex: clickable ? 0 : void 0,
200
+ "aria-current": fired ? "true" : void 0,
201
+ onClick: clickable ? () => {
202
+ const payload = { index: tr.index, event: tr.event, from: tr.from, to: tr.to };
203
+ onTransitionClick?.(payload);
204
+ if (transitionClickEvent) eventBus.emit(`UI:${transitionClickEvent}`, payload);
205
+ } : void 0,
206
+ className: `absolute flex flex-col items-center justify-center ${clickable ? "cursor-pointer" : ""}`,
207
+ style: { left: MARGIN + e.labelX, top: MARGIN + e.labelY, width: e.labelW, height: e.labelH },
208
+ children: /* @__PURE__ */ jsxs(
209
+ Box,
210
+ {
211
+ className: "flex items-center gap-1 rounded-md px-2",
212
+ style: {
213
+ height: PILL_H,
214
+ width: pw,
215
+ background: AVL_INK.surface,
216
+ border: `1px ${next ? "dashed" : "solid"} ${fired ? AVL_INK.focus : AVL_INK.line}`,
217
+ fontFamily: AVL_FONT.mono,
218
+ fontSize: 12,
219
+ color: fired ? AVL_INK.focus : AVL_INK.text,
220
+ fontWeight: fired ? 600 : 400
221
+ },
222
+ children: [
223
+ guard !== null ? /* @__PURE__ */ jsx(AvlExplain, { lines: [t("avl.guard"), t("avl.guardCaption")], code: guard, children: /* @__PURE__ */ jsx(Box, { as: "span", role: "img", tabIndex: 0, "aria-label": `${t("avl.guard")}: ${guard}`, "data-testid": "avl-guard-glyph", className: "inline-flex shrink-0 cursor-help rounded-sm focus:outline-none focus-visible:ring-2 focus-visible:ring-ring", children: /* @__PURE__ */ jsx("svg", { width: 12, height: 12, viewBox: "0 0 12 12", "aria-hidden": "true", children: /* @__PURE__ */ jsx("path", { d: "M6 1 L11 6 L6 11 L1 6z", fill: AVL_INK.surface, stroke: fired ? AVL_INK.focus : AVL_INK.quiet, strokeWidth: 1.2 }) }) }) }) : null,
224
+ annotations?.transitions?.[tr.event] ? /* @__PURE__ */ jsx(AvlExplain, { lines: [tr.event], code: guard ?? void 0, note: annotations.transitions[tr.event], children: /* @__PURE__ */ jsx(Box, { as: "span", tabIndex: 0, "data-explain": `transition:${tr.event}`, className: "whitespace-nowrap underline decoration-dotted underline-offset-2 cursor-help", children: tr.event }) }) : /* @__PURE__ */ jsx(Box, { as: "span", className: "whitespace-nowrap", children: tr.event }),
225
+ tr.effects.map((fx, i) => /* @__PURE__ */ jsx(AvlEffectChip, { effectType: fx.type, size: EFFECT_CHIP, note: annotations?.effects?.[fx.type], code: effectText(fx) }, `${fx.type}-${i}`))
226
+ ]
227
+ }
228
+ )
229
+ },
230
+ `label-${e.id}`
231
+ );
232
+ }),
233
+ trait.states.map((s) => {
234
+ const n = layout.nodes.find((x) => x.id === s.name);
235
+ if (!n) return null;
236
+ const active = s.name === activeState;
237
+ const selected = s.name === selectedState;
238
+ const pending = s.name === pendingSourceState;
239
+ const visit = visitOrder.get(s.name);
240
+ const idle = activeState !== void 0 && !active && visit === void 0;
241
+ const gear = nodeShape === "gear";
242
+ const emphasis = active || selected || pending;
243
+ return /* @__PURE__ */ jsxs(
244
+ Box,
245
+ {
246
+ "data-testid": "avl-sm-state",
247
+ "data-state": s.name,
248
+ "data-active": active ? "true" : "false",
249
+ "data-selected": selected ? "true" : "false",
250
+ "data-pending": pending ? "true" : "false",
251
+ "data-shape": nodeShape,
252
+ role: stateClickEvent ? "button" : void 0,
253
+ tabIndex: stateClickEvent ? 0 : void 0,
254
+ "aria-current": active ? "true" : void 0,
255
+ "aria-pressed": stateClickEvent ? selected : void 0,
256
+ onClick: stateClickEvent ? () => eventBus.emit(`UI:${stateClickEvent}`, { stateId: s.name }) : void 0,
257
+ className: `absolute flex items-center justify-center ${gear ? "rounded-full" : "rounded-lg"} ${stateClickEvent ? "cursor-pointer" : ""}`,
258
+ style: {
259
+ left: MARGIN + n.x,
260
+ top: MARGIN + n.y,
261
+ width: n.width,
262
+ height: n.height,
263
+ background: gear ? "transparent" : AVL_INK.surface,
264
+ border: gear ? "none" : `${emphasis ? 2 : 1}px ${pending ? "dashed" : "solid"} ${emphasis ? AVL_INK.focus : AVL_INK.line}`,
265
+ boxShadow: gear ? "none" : s.isTerminal ? `0 0 0 3px ${AVL_INK.surface}, 0 0 0 4px ${AVL_INK.line}, var(--shadow-sm)` : selected ? `0 0 0 4px ${avlTint(AVL_INK.focus, 18)}, var(--shadow-hover)` : active ? "var(--shadow-hover)" : "var(--shadow-sm)",
266
+ color: idle ? AVL_INK.quiet : AVL_INK.text,
267
+ fontFamily: AVL_FONT.body,
268
+ fontSize: 13,
269
+ fontWeight: active ? 600 : 500,
270
+ transition: "border-color var(--duration-normal, 200ms), box-shadow var(--duration-normal, 200ms)"
271
+ },
272
+ children: [
273
+ visit !== void 0 && !active ? /* @__PURE__ */ jsx(
274
+ Box,
275
+ {
276
+ as: "span",
277
+ "data-testid": "avl-sm-visit",
278
+ className: "absolute flex items-center justify-center rounded-full",
279
+ style: { top: -9, left: -9, width: 18, height: 18, fontSize: 11, fontWeight: 600, background: AVL_INK.wash, color: AVL_INK.quiet, border: `1px solid ${AVL_INK.line}` },
280
+ children: visit
281
+ }
282
+ ) : null,
283
+ active ? /* @__PURE__ */ jsx(
284
+ Box,
285
+ {
286
+ as: "span",
287
+ className: "absolute rounded-full px-1.5",
288
+ style: { top: -10, right: 8, fontSize: 11, fontWeight: 600, background: AVL_INK.focus, color: AVL_INK.onFocus, boxShadow: `0 0 0 2px ${avlTint(AVL_INK.focus, 18)}` },
289
+ children: t("avl.now")
290
+ }
291
+ ) : null,
292
+ gear ? /* @__PURE__ */ jsxs("svg", { "data-testid": "avl-sm-gear", width: n.width, height: n.height, className: "absolute left-0 top-0", "aria-hidden": "true", children: [
293
+ /* @__PURE__ */ jsx(
294
+ "path",
295
+ {
296
+ d: gearTeethPath(n.width / 2, n.height / 2, n.width / 2 - 8, n.width / 2 - 1, 12),
297
+ fill: AVL_INK.surface,
298
+ stroke: emphasis ? AVL_INK.focus : AVL_INK.line,
299
+ strokeWidth: emphasis ? 2 : 1.25,
300
+ strokeDasharray: pending || s.isTerminal ? "4 3" : void 0
301
+ }
302
+ ),
303
+ /* @__PURE__ */ jsx("circle", { cx: n.width / 2, cy: n.height / 2, r: n.width / 2 - 14, fill: "none", stroke: AVL_INK.line, strokeWidth: 1 })
304
+ ] }) : null,
305
+ annotations?.states?.[s.name] ? /* @__PURE__ */ jsx(AvlExplain, { lines: [s.name], note: annotations.states[s.name], children: /* @__PURE__ */ jsx(Box, { as: "span", tabIndex: 0, "data-explain": `state:${s.name}`, className: "relative underline decoration-dotted underline-offset-2 cursor-help", children: s.name }) }) : /* @__PURE__ */ jsx(Box, { as: "span", className: "relative", children: s.name })
306
+ ]
307
+ },
308
+ s.name
309
+ );
310
+ })
311
+ ] }) }) : /* @__PURE__ */ jsx(Box, { className: "flex items-center justify-center py-10", children: /* @__PURE__ */ jsx(Typography, { variant: "caption", color: "muted", children: t("avl.computingLayout") }) }) })
312
+ ] });
313
+ };
314
+ var Rail = ({ kind, event }) => /* @__PURE__ */ jsxs(
315
+ Box,
316
+ {
317
+ as: "span",
318
+ className: "inline-flex items-center gap-1 rounded-full px-2",
319
+ style: { fontFamily: AVL_FONT.mono, fontSize: 12, lineHeight: "20px", border: `1px solid ${AVL_INK.line}`, background: AVL_INK.wash, color: AVL_INK.quiet },
320
+ children: [
321
+ kind,
322
+ /* @__PURE__ */ jsx(Box, { as: "span", style: { color: AVL_INK.text, fontWeight: 600 }, children: event })
323
+ ]
324
+ }
325
+ );
326
+ AvlStateMachine.displayName = "AvlStateMachine";
327
+
328
+ export { AvlStateMachine };
@@ -0,0 +1,97 @@
1
+ import { useEventBus } from './chunk-MBQAMMSE.js';
2
+ import { useState, useCallback, useMemo } from 'react';
3
+
4
+ var ALMADAR_DND_MIME = "application/x-almadar-dnd";
5
+ function useDraggable({ payload, disabled = false }) {
6
+ const [isDragging, setIsDragging] = useState(false);
7
+ const eventBus = useEventBus();
8
+ const handleDragStart = useCallback(
9
+ (e) => {
10
+ if (disabled) {
11
+ e.preventDefault();
12
+ return;
13
+ }
14
+ e.dataTransfer.setData(ALMADAR_DND_MIME, JSON.stringify(payload));
15
+ e.dataTransfer.effectAllowed = "copy";
16
+ setIsDragging(true);
17
+ eventBus.emit("UI:DRAG_START", { kind: payload.kind, data: payload.data });
18
+ },
19
+ [disabled, payload, eventBus]
20
+ );
21
+ const handleDragEnd = useCallback(
22
+ (e) => {
23
+ setIsDragging(false);
24
+ eventBus.emit("UI:DRAG_END", { kind: payload.kind, data: payload.data });
25
+ },
26
+ [payload, eventBus]
27
+ );
28
+ const dragProps = useMemo(
29
+ () => ({
30
+ draggable: !disabled,
31
+ onDragStart: handleDragStart,
32
+ onDragEnd: handleDragEnd,
33
+ "aria-grabbed": isDragging
34
+ }),
35
+ [disabled, handleDragStart, handleDragEnd, isDragging]
36
+ );
37
+ return { dragProps, isDragging };
38
+ }
39
+ function parsePayload(e) {
40
+ try {
41
+ const raw = e.dataTransfer.getData(ALMADAR_DND_MIME);
42
+ if (!raw) return null;
43
+ const parsed = JSON.parse(raw);
44
+ if (typeof parsed.kind !== "string" || !parsed.data) return null;
45
+ return parsed;
46
+ } catch {
47
+ return null;
48
+ }
49
+ }
50
+ function hasAlmadarPayload(e) {
51
+ return e.dataTransfer.types.includes(ALMADAR_DND_MIME);
52
+ }
53
+ function useDropZone({ accepts, onDrop, disabled = false }) {
54
+ const [isOver, setIsOver] = useState(false);
55
+ const eventBus = useEventBus();
56
+ const handleDragOver = useCallback(
57
+ (e) => {
58
+ if (disabled) return;
59
+ if (!hasAlmadarPayload(e)) return;
60
+ e.preventDefault();
61
+ e.dataTransfer.dropEffect = "copy";
62
+ setIsOver(true);
63
+ },
64
+ [disabled]
65
+ );
66
+ const handleDragLeave = useCallback(
67
+ (e) => {
68
+ setIsOver(false);
69
+ },
70
+ []
71
+ );
72
+ const handleDrop = useCallback(
73
+ (e) => {
74
+ e.preventDefault();
75
+ setIsOver(false);
76
+ if (disabled) return;
77
+ const payload = parsePayload(e);
78
+ if (!payload) return;
79
+ if (!accepts.includes(payload.kind)) return;
80
+ const position = { x: e.clientX, y: e.clientY };
81
+ onDrop(payload, position);
82
+ eventBus.emit("UI:DROP", { kind: payload.kind, data: payload.data, ...position });
83
+ },
84
+ [disabled, accepts, onDrop, eventBus]
85
+ );
86
+ const dropProps = useMemo(
87
+ () => ({
88
+ onDragOver: handleDragOver,
89
+ onDragLeave: handleDragLeave,
90
+ onDrop: handleDrop
91
+ }),
92
+ [handleDragOver, handleDragLeave, handleDrop]
93
+ );
94
+ return { dropProps, isOver };
95
+ }
96
+
97
+ export { ALMADAR_DND_MIME, useDraggable, useDropZone };