@rien7/seji 0.0.0 → 0.6.1

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 (414) hide show
  1. package/bin/design-surface.mjs +6 -0
  2. package/bin/postinstall.mjs +19 -0
  3. package/bin/seji.mjs +585 -0
  4. package/dist/agent/host.d.mts +34 -0
  5. package/dist/agent/host.mjs +387 -0
  6. package/dist/agent/messages.d.mts +9 -0
  7. package/dist/agent/messages.mjs +70 -0
  8. package/dist/agent/runtimes.mjs +157 -0
  9. package/dist/cli/app.mjs +321 -0
  10. package/dist/cli/appScan.mjs +284 -0
  11. package/dist/cli/catalog.mjs +78 -0
  12. package/dist/cli/component.mjs +165 -0
  13. package/dist/cli/consolidate.mjs +159 -0
  14. package/dist/cli/cssImport.mjs +68 -0
  15. package/dist/cli/dev.mjs +339 -0
  16. package/dist/cli/doctor.mjs +311 -0
  17. package/dist/cli/init.mjs +338 -0
  18. package/dist/cli/legacyNames.mjs +266 -0
  19. package/dist/cli/migrate.mjs +163 -0
  20. package/dist/cli/prompt.mjs +34 -0
  21. package/dist/cli/propose.mjs +208 -0
  22. package/dist/cli/providers.mjs +344 -0
  23. package/dist/cli/reviewOps.mjs +110 -0
  24. package/dist/cli/semver.mjs +45 -0
  25. package/dist/cli/setup.mjs +360 -0
  26. package/dist/cli/sketches.mjs +47 -0
  27. package/dist/cli/skills.mjs +150 -0
  28. package/dist/cli/snapshot.mjs +107 -0
  29. package/dist/cli/tokenOps.mjs +120 -0
  30. package/dist/cli/types.mjs +191 -0
  31. package/dist/cli/updater.mjs +274 -0
  32. package/dist/components/astIndex.mjs +992 -0
  33. package/dist/components/ops.mjs +1069 -0
  34. package/dist/editor/AgentProposalCard.d.ts +10 -0
  35. package/dist/editor/AgentProposalCard.d.ts.map +1 -0
  36. package/dist/editor/AgentProposalCard.js +31 -0
  37. package/dist/editor/AgentProposalCard.js.map +1 -0
  38. package/dist/editor/App.d.ts +2 -0
  39. package/dist/editor/App.d.ts.map +1 -0
  40. package/dist/editor/App.js +2834 -0
  41. package/dist/editor/App.js.map +1 -0
  42. package/dist/editor/CanvasHud.d.ts +12 -0
  43. package/dist/editor/CanvasHud.d.ts.map +1 -0
  44. package/dist/editor/CanvasHud.js +13 -0
  45. package/dist/editor/CanvasHud.js.map +1 -0
  46. package/dist/editor/CanvasSurface.d.ts +31 -0
  47. package/dist/editor/CanvasSurface.d.ts.map +1 -0
  48. package/dist/editor/CanvasSurface.js +270 -0
  49. package/dist/editor/CanvasSurface.js.map +1 -0
  50. package/dist/editor/CommentPopover.d.ts +17 -0
  51. package/dist/editor/CommentPopover.d.ts.map +1 -0
  52. package/dist/editor/CommentPopover.js +62 -0
  53. package/dist/editor/CommentPopover.js.map +1 -0
  54. package/dist/editor/Comments.d.ts +13 -0
  55. package/dist/editor/Comments.d.ts.map +1 -0
  56. package/dist/editor/Comments.js +41 -0
  57. package/dist/editor/Comments.js.map +1 -0
  58. package/dist/editor/ComponentPage.d.ts +28 -0
  59. package/dist/editor/ComponentPage.d.ts.map +1 -0
  60. package/dist/editor/ComponentPage.js +55 -0
  61. package/dist/editor/ComponentPage.js.map +1 -0
  62. package/dist/editor/ComponentPanel.d.ts +38 -0
  63. package/dist/editor/ComponentPanel.d.ts.map +1 -0
  64. package/dist/editor/ComponentPanel.js +275 -0
  65. package/dist/editor/ComponentPanel.js.map +1 -0
  66. package/dist/editor/Glyph.d.ts +51 -0
  67. package/dist/editor/Glyph.d.ts.map +1 -0
  68. package/dist/editor/Glyph.js +50 -0
  69. package/dist/editor/Glyph.js.map +1 -0
  70. package/dist/editor/History.d.ts +7 -0
  71. package/dist/editor/History.d.ts.map +1 -0
  72. package/dist/editor/History.js +51 -0
  73. package/dist/editor/History.js.map +1 -0
  74. package/dist/editor/Inspector.d.ts +56 -0
  75. package/dist/editor/Inspector.d.ts.map +1 -0
  76. package/dist/editor/Inspector.js +510 -0
  77. package/dist/editor/Inspector.js.map +1 -0
  78. package/dist/editor/LazyMount.d.ts +10 -0
  79. package/dist/editor/LazyMount.d.ts.map +1 -0
  80. package/dist/editor/LazyMount.js +29 -0
  81. package/dist/editor/LazyMount.js.map +1 -0
  82. package/dist/editor/LocaleSwitch.d.ts +3 -0
  83. package/dist/editor/LocaleSwitch.d.ts.map +1 -0
  84. package/dist/editor/LocaleSwitch.js +9 -0
  85. package/dist/editor/LocaleSwitch.js.map +1 -0
  86. package/dist/editor/PreviewFrame.d.ts +10 -0
  87. package/dist/editor/PreviewFrame.d.ts.map +1 -0
  88. package/dist/editor/PreviewFrame.js +22 -0
  89. package/dist/editor/PreviewFrame.js.map +1 -0
  90. package/dist/editor/ProjectIndex.d.ts +12 -0
  91. package/dist/editor/ProjectIndex.d.ts.map +1 -0
  92. package/dist/editor/ProjectIndex.js +43 -0
  93. package/dist/editor/ProjectIndex.js.map +1 -0
  94. package/dist/editor/PromoteComponent.d.ts +28 -0
  95. package/dist/editor/PromoteComponent.d.ts.map +1 -0
  96. package/dist/editor/PromoteComponent.js +33 -0
  97. package/dist/editor/PromoteComponent.js.map +1 -0
  98. package/dist/editor/PromoteForm.d.ts +18 -0
  99. package/dist/editor/PromoteForm.d.ts.map +1 -0
  100. package/dist/editor/PromoteForm.js +35 -0
  101. package/dist/editor/PromoteForm.js.map +1 -0
  102. package/dist/editor/PromoteToken.d.ts +31 -0
  103. package/dist/editor/PromoteToken.d.ts.map +1 -0
  104. package/dist/editor/PromoteToken.js +94 -0
  105. package/dist/editor/PromoteToken.js.map +1 -0
  106. package/dist/editor/StatePreviews.d.ts +28 -0
  107. package/dist/editor/StatePreviews.d.ts.map +1 -0
  108. package/dist/editor/StatePreviews.js +113 -0
  109. package/dist/editor/StatePreviews.js.map +1 -0
  110. package/dist/editor/ValueCombo.d.ts +51 -0
  111. package/dist/editor/ValueCombo.d.ts.map +1 -0
  112. package/dist/editor/ValueCombo.js +260 -0
  113. package/dist/editor/ValueCombo.js.map +1 -0
  114. package/dist/editor/agent/AgentPanel.d.ts +19 -0
  115. package/dist/editor/agent/AgentPanel.d.ts.map +1 -0
  116. package/dist/editor/agent/AgentPanel.js +271 -0
  117. package/dist/editor/agent/AgentPanel.js.map +1 -0
  118. package/dist/editor/agent/Markdown.d.ts +5 -0
  119. package/dist/editor/agent/Markdown.d.ts.map +1 -0
  120. package/dist/editor/agent/Markdown.js +28 -0
  121. package/dist/editor/agent/Markdown.js.map +1 -0
  122. package/dist/editor/agent/agentApi.d.ts +106 -0
  123. package/dist/editor/agent/agentApi.d.ts.map +1 -0
  124. package/dist/editor/agent/agentApi.js +66 -0
  125. package/dist/editor/agent/agentApi.js.map +1 -0
  126. package/dist/editor/agent/toolLines.d.ts +38 -0
  127. package/dist/editor/agent/toolLines.d.ts.map +1 -0
  128. package/dist/editor/agent/toolLines.js +159 -0
  129. package/dist/editor/agent/toolLines.js.map +1 -0
  130. package/dist/editor/agent/useAgent.d.ts +15 -0
  131. package/dist/editor/agent/useAgent.d.ts.map +1 -0
  132. package/dist/editor/agent/useAgent.js +65 -0
  133. package/dist/editor/agent/useAgent.js.map +1 -0
  134. package/dist/editor/api.d.ts +378 -0
  135. package/dist/editor/api.d.ts.map +1 -0
  136. package/dist/editor/api.js +247 -0
  137. package/dist/editor/api.js.map +1 -0
  138. package/dist/editor/camera.d.ts +18 -0
  139. package/dist/editor/camera.d.ts.map +1 -0
  140. package/dist/editor/camera.js +40 -0
  141. package/dist/editor/camera.js.map +1 -0
  142. package/dist/editor/canvas.d.ts +25 -0
  143. package/dist/editor/canvas.d.ts.map +1 -0
  144. package/dist/editor/canvas.js +35 -0
  145. package/dist/editor/canvas.js.map +1 -0
  146. package/dist/editor/changes/ChangesPage.d.ts +25 -0
  147. package/dist/editor/changes/ChangesPage.d.ts.map +1 -0
  148. package/dist/editor/changes/ChangesPage.js +132 -0
  149. package/dist/editor/changes/ChangesPage.js.map +1 -0
  150. package/dist/editor/changes/changeModel.d.ts +25 -0
  151. package/dist/editor/changes/changeModel.d.ts.map +1 -0
  152. package/dist/editor/changes/changeModel.js +81 -0
  153. package/dist/editor/changes/changeModel.js.map +1 -0
  154. package/dist/editor/changes/changeState.d.mts +29 -0
  155. package/dist/editor/changes/changeState.mjs +187 -0
  156. package/dist/editor/chrome/EditorChrome.d.ts +49 -0
  157. package/dist/editor/chrome/EditorChrome.d.ts.map +1 -0
  158. package/dist/editor/chrome/EditorChrome.js +21 -0
  159. package/dist/editor/chrome/EditorChrome.js.map +1 -0
  160. package/dist/editor/drafts.d.ts +46 -0
  161. package/dist/editor/drafts.d.ts.map +1 -0
  162. package/dist/editor/drafts.js +38 -0
  163. package/dist/editor/drafts.js.map +1 -0
  164. package/dist/editor/i18n.d.ts +29 -0
  165. package/dist/editor/i18n.d.ts.map +1 -0
  166. package/dist/editor/i18n.js +2320 -0
  167. package/dist/editor/i18n.js.map +1 -0
  168. package/dist/editor/iconStroke.d.ts +6 -0
  169. package/dist/editor/iconStroke.d.ts.map +1 -0
  170. package/dist/editor/iconStroke.js +6 -0
  171. package/dist/editor/iconStroke.js.map +1 -0
  172. package/dist/editor/main.d.ts +2 -0
  173. package/dist/editor/main.d.ts.map +1 -0
  174. package/dist/editor/main.js +14 -0
  175. package/dist/editor/main.js.map +1 -0
  176. package/dist/editor/model.d.ts +16 -0
  177. package/dist/editor/model.d.ts.map +1 -0
  178. package/dist/editor/model.js +11 -0
  179. package/dist/editor/model.js.map +1 -0
  180. package/dist/editor/reasons.d.ts +44 -0
  181. package/dist/editor/reasons.d.ts.map +1 -0
  182. package/dist/editor/reasons.js +131 -0
  183. package/dist/editor/reasons.js.map +1 -0
  184. package/dist/editor/reviewLifecycle.d.ts +8 -0
  185. package/dist/editor/reviewLifecycle.d.ts.map +1 -0
  186. package/dist/editor/reviewLifecycle.js +21 -0
  187. package/dist/editor/reviewLifecycle.js.map +1 -0
  188. package/dist/editor/styles.css +8737 -0
  189. package/dist/editor/tokenMatch.d.ts +59 -0
  190. package/dist/editor/tokenMatch.d.ts.map +1 -0
  191. package/dist/editor/tokenMatch.js +198 -0
  192. package/dist/editor/tokenMatch.js.map +1 -0
  193. package/dist/editor/tokens/ConsolidatePage.d.ts +16 -0
  194. package/dist/editor/tokens/ConsolidatePage.d.ts.map +1 -0
  195. package/dist/editor/tokens/ConsolidatePage.js +244 -0
  196. package/dist/editor/tokens/ConsolidatePage.js.map +1 -0
  197. package/dist/editor/tokens/TokenActivity.d.ts +18 -0
  198. package/dist/editor/tokens/TokenActivity.d.ts.map +1 -0
  199. package/dist/editor/tokens/TokenActivity.js +18 -0
  200. package/dist/editor/tokens/TokenActivity.js.map +1 -0
  201. package/dist/editor/tokens/TokenDialogs.d.ts +26 -0
  202. package/dist/editor/tokens/TokenDialogs.d.ts.map +1 -0
  203. package/dist/editor/tokens/TokenDialogs.js +119 -0
  204. package/dist/editor/tokens/TokenDialogs.js.map +1 -0
  205. package/dist/editor/tokens/TokenList.d.ts +21 -0
  206. package/dist/editor/tokens/TokenList.d.ts.map +1 -0
  207. package/dist/editor/tokens/TokenList.js +98 -0
  208. package/dist/editor/tokens/TokenList.js.map +1 -0
  209. package/dist/editor/tokens/TokenPage.d.ts +25 -0
  210. package/dist/editor/tokens/TokenPage.d.ts.map +1 -0
  211. package/dist/editor/tokens/TokenPage.js +108 -0
  212. package/dist/editor/tokens/TokenPage.js.map +1 -0
  213. package/dist/editor/tokens/tokenModel.d.ts +35 -0
  214. package/dist/editor/tokens/tokenModel.d.ts.map +1 -0
  215. package/dist/editor/tokens/tokenModel.js +72 -0
  216. package/dist/editor/tokens/tokenModel.js.map +1 -0
  217. package/dist/editor/ui/Button.d.ts +3 -0
  218. package/dist/editor/ui/Button.d.ts.map +1 -0
  219. package/dist/editor/ui/Button.js +6 -0
  220. package/dist/editor/ui/Button.js.map +1 -0
  221. package/dist/editor/ui/CommentBox.d.ts +23 -0
  222. package/dist/editor/ui/CommentBox.d.ts.map +1 -0
  223. package/dist/editor/ui/CommentBox.js +41 -0
  224. package/dist/editor/ui/CommentBox.js.map +1 -0
  225. package/dist/editor/ui/Icon.d.ts +8 -0
  226. package/dist/editor/ui/Icon.d.ts.map +1 -0
  227. package/dist/editor/ui/Icon.js +6 -0
  228. package/dist/editor/ui/Icon.js.map +1 -0
  229. package/dist/editor/ui/IconButton.d.ts +11 -0
  230. package/dist/editor/ui/IconButton.d.ts.map +1 -0
  231. package/dist/editor/ui/IconButton.js +6 -0
  232. package/dist/editor/ui/IconButton.js.map +1 -0
  233. package/dist/editor/ui/NumberInput.d.ts +14 -0
  234. package/dist/editor/ui/NumberInput.d.ts.map +1 -0
  235. package/dist/editor/ui/NumberInput.js +6 -0
  236. package/dist/editor/ui/NumberInput.js.map +1 -0
  237. package/dist/editor/ui/PageLine.d.ts +14 -0
  238. package/dist/editor/ui/PageLine.d.ts.map +1 -0
  239. package/dist/editor/ui/PageLine.js +7 -0
  240. package/dist/editor/ui/PageLine.js.map +1 -0
  241. package/dist/editor/ui/SearchPicker.d.ts +41 -0
  242. package/dist/editor/ui/SearchPicker.d.ts.map +1 -0
  243. package/dist/editor/ui/SearchPicker.js +82 -0
  244. package/dist/editor/ui/SearchPicker.js.map +1 -0
  245. package/dist/editor/ui/Select.d.ts +19 -0
  246. package/dist/editor/ui/Select.d.ts.map +1 -0
  247. package/dist/editor/ui/Select.js +12 -0
  248. package/dist/editor/ui/Select.js.map +1 -0
  249. package/dist/editor/ui/TokenField.d.ts +14 -0
  250. package/dist/editor/ui/TokenField.d.ts.map +1 -0
  251. package/dist/editor/ui/TokenField.js +41 -0
  252. package/dist/editor/ui/TokenField.js.map +1 -0
  253. package/dist/editor/ui/TokenPicker.d.ts +31 -0
  254. package/dist/editor/ui/TokenPicker.d.ts.map +1 -0
  255. package/dist/editor/ui/TokenPicker.js +26 -0
  256. package/dist/editor/ui/TokenPicker.js.map +1 -0
  257. package/dist/editor/useBuildError.d.ts +7 -0
  258. package/dist/editor/useBuildError.d.ts.map +1 -0
  259. package/dist/editor/useBuildError.js +30 -0
  260. package/dist/editor/useBuildError.js.map +1 -0
  261. package/dist/editor/useLatestRequest.d.ts +22 -0
  262. package/dist/editor/useLatestRequest.d.ts.map +1 -0
  263. package/dist/editor/useLatestRequest.js +49 -0
  264. package/dist/editor/useLatestRequest.js.map +1 -0
  265. package/dist/editor-bundle/editor.css +2 -0
  266. package/dist/editor-bundle/editor.js +83 -0
  267. package/dist/editor-ui.d.ts +15 -0
  268. package/dist/editor-ui.d.ts.map +1 -0
  269. package/dist/editor-ui.js +14 -0
  270. package/dist/editor-ui.js.map +1 -0
  271. package/dist/inspector/runtime.d.ts +18 -0
  272. package/dist/inspector/runtime.d.ts.map +1 -0
  273. package/dist/inspector/runtime.js +1280 -0
  274. package/dist/inspector/runtime.js.map +1 -0
  275. package/dist/preview/main.d.ts +3 -0
  276. package/dist/preview/main.d.ts.map +1 -0
  277. package/dist/preview/main.js +320 -0
  278. package/dist/preview/main.js.map +1 -0
  279. package/dist/preview/preview.css +40 -0
  280. package/dist/runtime/index.d.ts +3 -0
  281. package/dist/runtime/index.d.ts.map +1 -0
  282. package/dist/runtime/index.js +2 -0
  283. package/dist/runtime/index.js.map +1 -0
  284. package/dist/shared/buildError.d.mts +27 -0
  285. package/dist/shared/buildError.mjs +141 -0
  286. package/dist/shared/cameraFit.d.mts +16 -0
  287. package/dist/shared/cameraFit.mjs +47 -0
  288. package/dist/shared/canvasLayout.d.mts +13 -0
  289. package/dist/shared/canvasLayout.mjs +171 -0
  290. package/dist/shared/commentShots.d.mts +12 -0
  291. package/dist/shared/commentShots.mjs +53 -0
  292. package/dist/shared/componentExtract.d.mts +43 -0
  293. package/dist/shared/componentExtract.mjs +136 -0
  294. package/dist/shared/componentMeta.d.mts +26 -0
  295. package/dist/shared/componentMeta.mjs +87 -0
  296. package/dist/shared/componentOps.d.mts +70 -0
  297. package/dist/shared/componentOps.mjs +407 -0
  298. package/dist/shared/componentTarget.d.mts +15 -0
  299. package/dist/shared/componentTarget.mjs +58 -0
  300. package/dist/shared/components.d.mts +30 -0
  301. package/dist/shared/components.mjs +106 -0
  302. package/dist/shared/consolidateCategories.d.mts +2 -0
  303. package/dist/shared/consolidateCategories.mjs +6 -0
  304. package/dist/shared/env.d.mts +4 -0
  305. package/dist/shared/env.mjs +18 -0
  306. package/dist/shared/gitChanges.d.mts +2 -0
  307. package/dist/shared/gitChanges.mjs +30 -0
  308. package/dist/shared/legacyPaths.d.mts +1 -0
  309. package/dist/shared/legacyPaths.mjs +9 -0
  310. package/dist/shared/oklab.d.mts +6 -0
  311. package/dist/shared/oklab.mjs +56 -0
  312. package/dist/shared/optimizeEntries.d.mts +5 -0
  313. package/dist/shared/optimizeEntries.mjs +24 -0
  314. package/dist/shared/packages.d.mts +11 -0
  315. package/dist/shared/packages.mjs +96 -0
  316. package/dist/shared/projectFiles.d.mts +23 -0
  317. package/dist/shared/projectFiles.mjs +72 -0
  318. package/dist/shared/prompt.d.mts +25 -0
  319. package/dist/shared/prompt.mjs +217 -0
  320. package/dist/shared/proposals.d.mts +11 -0
  321. package/dist/shared/proposals.mjs +42 -0
  322. package/dist/shared/protocol.d.ts +122 -0
  323. package/dist/shared/protocol.d.ts.map +1 -0
  324. package/dist/shared/protocol.js +7 -0
  325. package/dist/shared/protocol.js.map +1 -0
  326. package/dist/shared/reviewArchive.d.mts +4 -0
  327. package/dist/shared/reviewArchive.mjs +19 -0
  328. package/dist/shared/reviewStore.d.mts +30 -0
  329. package/dist/shared/reviewStore.mjs +218 -0
  330. package/dist/shared/reviewVerify.d.mts +21 -0
  331. package/dist/shared/reviewVerify.mjs +158 -0
  332. package/dist/shared/sizeModes.d.mts +15 -0
  333. package/dist/shared/sizeModes.mjs +53 -0
  334. package/dist/shared/sketches.d.mts +10 -0
  335. package/dist/shared/sketches.mjs +64 -0
  336. package/dist/shared/snapshotCheck.d.mts +13 -0
  337. package/dist/shared/snapshotCheck.mjs +81 -0
  338. package/dist/shared/timeout.d.mts +1 -0
  339. package/dist/shared/timeout.mjs +15 -0
  340. package/dist/shared/tokens.d.ts +2 -0
  341. package/dist/shared/tokens.d.ts.map +1 -0
  342. package/dist/shared/tokens.js +2 -0
  343. package/dist/shared/tokens.js.map +1 -0
  344. package/dist/shared/types.d.ts +689 -0
  345. package/dist/shared/types.d.ts.map +1 -0
  346. package/dist/shared/types.js +13 -0
  347. package/dist/shared/types.js.map +1 -0
  348. package/dist/shared/wheelRouting.d.mts +9 -0
  349. package/dist/shared/wheelRouting.mjs +31 -0
  350. package/dist/shared/writeScope.mjs +96 -0
  351. package/dist/snapshots/diff.d.mts +28 -0
  352. package/dist/snapshots/diff.mjs +263 -0
  353. package/dist/snapshots/index.d.mts +110 -0
  354. package/dist/snapshots/index.mjs +638 -0
  355. package/dist/snapshots/render.d.mts +24 -0
  356. package/dist/snapshots/render.mjs +250 -0
  357. package/dist/snapshots/toolOps.d.mts +25 -0
  358. package/dist/snapshots/toolOps.mjs +69 -0
  359. package/dist/tokens/adapters/css.mjs +51 -0
  360. package/dist/tokens/adapters/cssInCode.mjs +314 -0
  361. package/dist/tokens/adapters/oxcShared.mjs +80 -0
  362. package/dist/tokens/adapters/preprocessor.mjs +63 -0
  363. package/dist/tokens/adapters/registry.mjs +53 -0
  364. package/dist/tokens/adapters/tailwindcss.mjs +424 -0
  365. package/dist/tokens/adapters/types.mjs +117 -0
  366. package/dist/tokens/consolidate/index.d.mts +42 -0
  367. package/dist/tokens/consolidate/index.mjs +111 -0
  368. package/dist/tokens/consolidate/normalize.mjs +479 -0
  369. package/dist/tokens/consolidate/plan.mjs +726 -0
  370. package/dist/tokens/consolidate/scan.mjs +928 -0
  371. package/dist/tokens/extract.mjs +441 -0
  372. package/dist/tokens/moduleData.d.mts +14 -0
  373. package/dist/tokens/moduleData.mjs +32 -0
  374. package/dist/tokens/opLock.d.mts +4 -0
  375. package/dist/tokens/opLock.mjs +108 -0
  376. package/dist/tokens/ops.d.mts +71 -0
  377. package/dist/tokens/ops.mjs +1511 -0
  378. package/dist/tokens/pipeline.mjs +813 -0
  379. package/dist/tokens/report.d.mts +47 -0
  380. package/dist/tokens/report.mjs +257 -0
  381. package/dist/tokens/rewrite/code.mjs +172 -0
  382. package/dist/tokens/rewrite/css.mjs +154 -0
  383. package/dist/tokens/rewrite/index.mjs +244 -0
  384. package/dist/tokens/rewrite/tailwind.mjs +288 -0
  385. package/dist/tokens/rewrite/text.mjs +116 -0
  386. package/dist/tokens/rewrite/value.mjs +115 -0
  387. package/dist/tokens/usage.d.mts +97 -0
  388. package/dist/tokens/usage.mjs +680 -0
  389. package/dist/vite/agent.d.ts +21 -0
  390. package/dist/vite/agent.d.ts.map +1 -0
  391. package/dist/vite/agent.js +165 -0
  392. package/dist/vite/agent.js.map +1 -0
  393. package/dist/vite/events.d.ts +27 -0
  394. package/dist/vite/events.d.ts.map +1 -0
  395. package/dist/vite/events.js +156 -0
  396. package/dist/vite/events.js.map +1 -0
  397. package/dist/vite/layout.d.ts +2 -0
  398. package/dist/vite/layout.d.ts.map +1 -0
  399. package/dist/vite/layout.js +4 -0
  400. package/dist/vite/layout.js.map +1 -0
  401. package/dist/vite/plugin.d.ts +40 -0
  402. package/dist/vite/plugin.d.ts.map +1 -0
  403. package/dist/vite/plugin.js +1264 -0
  404. package/dist/vite/plugin.js.map +1 -0
  405. package/dist/vite/requestGuard.d.mts +3 -0
  406. package/dist/vite/requestGuard.mjs +43 -0
  407. package/dist/vite/review.d.ts +11 -0
  408. package/dist/vite/review.d.ts.map +1 -0
  409. package/dist/vite/review.js +283 -0
  410. package/dist/vite/review.js.map +1 -0
  411. package/package.json +106 -1
  412. package/skills/seji/SKILL.md +400 -0
  413. package/skills/seji-authoring/SKILL.md +397 -0
  414. package/skills/seji-tokens/SKILL.md +432 -0
@@ -0,0 +1,244 @@
1
+ // Rewrite planning and committing across files. Planning parses each file and records the
2
+ // sha256 of the exact text that was parsed; committing re-reads the file and, if it changed
3
+ // since, re-parses and re-plans it from the new text before writing (never writes edits
4
+ // computed against stale offsets).
5
+ import { randomBytes } from 'node:crypto'
6
+ import { existsSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from 'node:fs'
7
+ import { basename, dirname, join, relative, resolve, sep } from 'node:path'
8
+
9
+ import { planCodeFile } from './code.mjs'
10
+ import { cssSyntaxOf, planStylesheet } from './css.mjs'
11
+ import { applyEdits, sha256 } from './text.mjs'
12
+
13
+ const CODE_EXT = /\.(?:tsx|jsx|ts|js|mts|cts|mjs|cjs)$/i
14
+ const toPosix = (file) => file.split(sep).join('/')
15
+
16
+ /** Plan one file's rewrite from `content` (null when the file type has no rewriter). */
17
+ export async function planFile(file, content, spec) {
18
+ if (cssSyntaxOf(file)) return planStylesheet(file, content, spec)
19
+ if (CODE_EXT.test(file)) return planCodeFile(file, content, spec)
20
+ return null
21
+ }
22
+
23
+ /**
24
+ * Plan a chain of rewrite steps on one file's `content`: each step `{ spec, files? }` is
25
+ * planned (with the same AST rewriters) on the output of the previous one. `files` (a Set of
26
+ * absolute paths) limits a step to the files it concerns. Changes and leftovers of every step
27
+ * are kept; the result has the plan shape of `planFile` with `before` the original content.
28
+ */
29
+ export async function planFileSteps(file, abs, content, steps) {
30
+ let current = content
31
+ let applicable = false
32
+ const changes = []
33
+ const leftovers = []
34
+ for (const step of steps) {
35
+ if (step.files && !step.files.has(abs)) continue
36
+ const plan = await planFile(file, current, step.spec)
37
+ if (!plan) continue
38
+ applicable = true
39
+ changes.push(...plan.changes)
40
+ leftovers.push(...plan.leftovers)
41
+ current = plan.after
42
+ }
43
+ if (!applicable) return null
44
+ const order = (a, b) => a.line - b.line || a.column - b.column
45
+ return {
46
+ file,
47
+ hash: sha256(content),
48
+ before: content,
49
+ after: current,
50
+ // Offsets of later steps refer to intermediate text, so no per-edit undo regions.
51
+ edits: [],
52
+ changes: changes.sort(order),
53
+ leftovers: leftovers.sort(order),
54
+ }
55
+ }
56
+
57
+ const replan = (file, abs, text, spec, steps) => (steps ? planFileSteps(file, abs, text, steps) : planFile(file, text, spec))
58
+
59
+ /**
60
+ * Plan rewrites for absolute `files`; only files with changes or leftovers are returned.
61
+ * Pass `spec` for one rewrite, or `steps` (`[{ spec, files? }]`) for a chain on each file.
62
+ */
63
+ export async function planRewrites({ root, files, spec, steps }) {
64
+ const plans = []
65
+ for (const abs of files) {
66
+ if (!existsSync(abs)) continue
67
+ const rel = toPosix(relative(root, abs))
68
+ const content = readFileSync(abs, 'utf8')
69
+ const plan = await replan(rel, abs, content, spec, steps)
70
+ if (plan && (plan.changes.length || plan.leftovers.length)) plans.push({ ...plan, abs })
71
+ }
72
+ return plans
73
+ }
74
+
75
+ /**
76
+ * Undo edits that turn `after` back into `before`: one minimal region (common prefix and
77
+ * suffix trimmed). Stored in the ledger so a batch can be reverted without keeping copies.
78
+ */
79
+ export function undoEdits(before, after) {
80
+ if (before === after) return []
81
+ let start = 0
82
+ const max = Math.min(before.length, after.length)
83
+ while (start < max && before.charCodeAt(start) === after.charCodeAt(start)) start += 1
84
+ let endBefore = before.length
85
+ let endAfter = after.length
86
+ while (endBefore > start && endAfter > start && before.charCodeAt(endBefore - 1) === after.charCodeAt(endAfter - 1)) {
87
+ endBefore -= 1
88
+ endAfter -= 1
89
+ }
90
+ return [{ start, end: endAfter, text: before.slice(start, endBefore) }]
91
+ }
92
+
93
+ /** Per-change undo for position edits (keeps the ledger small for scattered edits). */
94
+ export function undoForChanges(before, after, regions) {
95
+ if (!regions?.length) return undoEdits(before, after)
96
+ const sorted = [...regions].sort((a, b) => a.start - b.start)
97
+ const undo = []
98
+ let delta = 0
99
+ for (const edit of sorted) {
100
+ const start = edit.start + delta
101
+ undo.push({ start, end: start + edit.text.length, text: before.slice(edit.start, edit.end) })
102
+ delta += edit.text.length - (edit.end - edit.start)
103
+ }
104
+ return applyEdits(after, undo) === before ? undo : undoEdits(before, after)
105
+ }
106
+
107
+ /**
108
+ * Re-read every planned file and re-plan the ones whose content changed since planning.
109
+ * Nothing is written. `missing` lists files that disappeared (the caller should start over).
110
+ */
111
+ export async function prepareRewrites({ root, plans, spec, steps }) {
112
+ const finals = []
113
+ const missing = []
114
+ for (const plan of plans) {
115
+ const abs = plan.abs ?? resolve(root, plan.file)
116
+ let text
117
+ try {
118
+ text = readFileSync(abs, 'utf8')
119
+ } catch (error) {
120
+ if (error?.code === 'ENOENT') {
121
+ missing.push(plan.file)
122
+ continue
123
+ }
124
+ throw error
125
+ }
126
+ if (sha256(text) === plan.hash) {
127
+ finals.push({ ...plan, abs })
128
+ continue
129
+ }
130
+ const replanned = await replan(plan.file, abs, text, spec, steps)
131
+ finals.push({
132
+ ...(replanned ?? { ...plan, before: text, after: text, changes: [], leftovers: [], edits: [] }),
133
+ hash: sha256(text),
134
+ abs,
135
+ reparsed: true,
136
+ })
137
+ }
138
+ return { plans: finals, missing }
139
+ }
140
+
141
+ /** Revert records for prepared plans that change their file. */
142
+ export function writesFor(plans) {
143
+ return plans
144
+ .filter((plan) => plan.after !== plan.before)
145
+ .map((plan) => ({
146
+ file: plan.file,
147
+ abs: plan.abs,
148
+ before: plan.before,
149
+ after: plan.after,
150
+ beforeHash: sha256(plan.before),
151
+ afterHash: sha256(plan.after),
152
+ undo: undoForChanges(plan.before, plan.after, plan.edits),
153
+ }))
154
+ }
155
+
156
+ /** Write `text` to `abs` through a temp file + rename, so a reader never sees half a file. */
157
+ export function writeFileAtomic(abs, text) {
158
+ const temp = join(dirname(abs), `.${basename(abs)}.${process.pid}.${randomBytes(4).toString('hex')}.tmp`)
159
+ let mode
160
+ try {
161
+ mode = statSync(abs).mode
162
+ } catch {
163
+ mode = undefined
164
+ }
165
+ try {
166
+ writeFileSync(temp, text, mode === undefined ? undefined : { mode })
167
+ renameSync(temp, abs)
168
+ } catch (error) {
169
+ rmSync(temp, { force: true })
170
+ throw error
171
+ }
172
+ }
173
+
174
+ export class StaleFileError extends Error {
175
+ constructor(file) {
176
+ super(`${file} changed while the operation was writing`)
177
+ this.name = 'StaleFileError'
178
+ this.file = file
179
+ }
180
+ }
181
+
182
+ /**
183
+ * Write every entry `{ abs, file, before, after, beforeHash }` or none: each file is checked
184
+ * against `beforeHash` right before it is written, and any failure restores the files
185
+ * already written (see `restoreWrites`) before rethrowing. Returns the written entries.
186
+ */
187
+ export function writeAll(writes, { written = [], onWritten } = {}) {
188
+ try {
189
+ for (const entry of writes) {
190
+ const current = readFileSync(entry.abs, 'utf8')
191
+ if (sha256(current) !== entry.beforeHash) throw new StaleFileError(entry.file)
192
+ writeFileAtomic(entry.abs, entry.after)
193
+ written.push(entry)
194
+ onWritten?.(entry)
195
+ }
196
+ } catch (error) {
197
+ const conflicts = restoreWrites(written)
198
+ if (conflicts.length) error.restoreConflicts = conflicts
199
+ throw error
200
+ }
201
+ return written
202
+ }
203
+
204
+ /**
205
+ * Undo `written` entries (newest first). A file is only restored while it still holds what
206
+ * was written (`afterHash`); a file someone changed since is left alone and returned.
207
+ */
208
+ export function restoreWrites(written) {
209
+ const conflicts = []
210
+ for (const entry of [...written].reverse()) {
211
+ let current = null
212
+ try {
213
+ current = readFileSync(entry.abs, 'utf8')
214
+ } catch {
215
+ current = null
216
+ }
217
+ if (current !== null && sha256(current) !== entry.afterHash) {
218
+ conflicts.push({ file: entry.file, reason: 'changed by someone else; not restored' })
219
+ continue
220
+ }
221
+ try {
222
+ writeFileAtomic(entry.abs, entry.before)
223
+ } catch (error) {
224
+ conflicts.push({ file: entry.file, reason: `could not restore: ${error instanceof Error ? error.message : error}` })
225
+ }
226
+ }
227
+ written.length = 0
228
+ return conflicts
229
+ }
230
+
231
+ /**
232
+ * Write planned rewrites: re-read and re-plan changed files first (no write happens before
233
+ * every file is prepared), then write all of them or none. Returns the final plans plus
234
+ * revert records `{ file, beforeHash, afterHash, undo }`.
235
+ */
236
+ export async function commitRewrites({ root, plans, spec }) {
237
+ const prepared = await prepareRewrites({ root, plans, spec })
238
+ if (prepared.missing.length) throw new StaleFileError(prepared.missing[0])
239
+ const written = writeAll(writesFor(prepared.plans))
240
+ return {
241
+ plans: prepared.plans,
242
+ written: written.map(({ file, beforeHash, afterHash, undo }) => ({ file, beforeHash, afterHash, undo })),
243
+ }
244
+ }
@@ -0,0 +1,288 @@
1
+ // Tailwind class rewriting. A class list is split into class tokens (offsets kept), each token
2
+ // is decomposed into variants / important / negative / utility / modifier, and only the
3
+ // matched part is replaced:
4
+ // - `bg-(--old)` / `bg-(color:--old)` → the custom-property name inside the parentheses
5
+ // - `bg-[var(--old)]`, `[color:var(--old)]` → var() names inside the brackets (value-parser)
6
+ // - theme utilities (`bg-ink` from `@theme { --color-ink }`) → `bg-<newKey>` when the new
7
+ // token stays in a utility namespace, otherwise `bg-(--new)`
8
+ import valueParser from 'postcss-value-parser'
9
+
10
+ import { splitClassesWithOffsets } from './text.mjs'
11
+ import { rewriteValueVars } from './value.mjs'
12
+
13
+ const SIDES = ['', '-x', '-y', '-t', '-r', '-b', '-l', '-s', '-e']
14
+ const CORNERS = ['', '-t', '-r', '-b', '-l', '-s', '-e', '-tl', '-tr', '-br', '-bl', '-ss', '-se', '-ee', '-es']
15
+
16
+ const COLOR_UTILITIES = [
17
+ 'bg',
18
+ 'text',
19
+ ...SIDES.map((side) => `border${side}`),
20
+ 'outline',
21
+ 'ring',
22
+ 'ring-offset',
23
+ 'inset-ring',
24
+ 'divide',
25
+ 'accent',
26
+ 'caret',
27
+ 'fill',
28
+ 'stroke',
29
+ 'decoration',
30
+ 'shadow',
31
+ 'inset-shadow',
32
+ 'drop-shadow',
33
+ 'from',
34
+ 'via',
35
+ 'to',
36
+ 'placeholder',
37
+ ]
38
+
39
+ const SPACING_UTILITIES = [
40
+ ...['p', 'px', 'py', 'pt', 'pr', 'pb', 'pl', 'ps', 'pe'],
41
+ ...['m', 'mx', 'my', 'mt', 'mr', 'mb', 'ml', 'ms', 'me'],
42
+ ...['gap', 'gap-x', 'gap-y', 'space-x', 'space-y'],
43
+ ...['w', 'h', 'size', 'min-w', 'min-h', 'max-w', 'max-h', 'basis', 'indent'],
44
+ ...['inset', 'inset-x', 'inset-y', 'top', 'right', 'bottom', 'left', 'start', 'end'],
45
+ ...['translate-x', 'translate-y', 'scroll-m', 'scroll-p'],
46
+ ]
47
+
48
+ /** Tailwind v4 theme namespaces (`--<ns>-<key>`) and the utilities that read them. */
49
+ export const THEME_NAMESPACES = {
50
+ color: COLOR_UTILITIES,
51
+ spacing: SPACING_UTILITIES,
52
+ radius: CORNERS.map((corner) => `rounded${corner}`),
53
+ text: ['text'],
54
+ 'font-weight': ['font'],
55
+ font: ['font'],
56
+ tracking: ['tracking'],
57
+ leading: ['leading'],
58
+ shadow: ['shadow'],
59
+ 'inset-shadow': ['inset-shadow'],
60
+ 'drop-shadow': ['drop-shadow'],
61
+ blur: ['blur'],
62
+ ease: ['ease'],
63
+ animate: ['animate'],
64
+ perspective: ['perspective'],
65
+ aspect: ['aspect'],
66
+ container: ['max-w', 'w', 'min-w'],
67
+ }
68
+
69
+ const NAMESPACE_ORDER = Object.keys(THEME_NAMESPACES).sort((a, b) => b.length - a.length)
70
+
71
+ /** `--color-ink` → { ns: 'color', key: 'ink' } (or null when not in a theme namespace). */
72
+ export function themeKeyOf(cssName) {
73
+ for (const ns of NAMESPACE_ORDER) {
74
+ const prefix = `--${ns}-`
75
+ if (cssName.startsWith(prefix) && cssName.length > prefix.length) {
76
+ return { ns, key: cssName.slice(prefix.length) }
77
+ }
78
+ }
79
+ return null
80
+ }
81
+
82
+ const COLOR_HINT_UTILITIES = new Set(['shadow', 'inset-shadow', 'drop-shadow', 'ring', 'inset-ring', 'ring-offset', 'stroke'])
83
+
84
+ // Tailwind v4: `border-(--x)` / `outline-(--x)` / `divide-x-(--x)` set the COLOR; the width needs
85
+ // `length:`. `ring-(--x)` / `inset-ring-(--x)` are already the ring width.
86
+ const LENGTH_HINT_UTILITIES = new Set([...SIDES.map((side) => `border${side}`), 'outline', 'divide-x', 'divide-y'])
87
+
88
+ function parenHint(ns, utility) {
89
+ if (ns === 'border-width') return LENGTH_HINT_UTILITIES.has(utility) ? 'length:' : ''
90
+ if (ns === 'color' && COLOR_HINT_UTILITIES.has(utility)) return 'color:'
91
+ if (ns === 'text' && utility === 'text') return 'length:'
92
+ if (ns === 'font' && utility === 'font') return 'family-name:'
93
+ return ''
94
+ }
95
+
96
+ /** Class text a utility should use to reference `cssName` (theme key when possible). */
97
+ export function utilityFor(utility, cssName, { theme, namespaceHint } = {}) {
98
+ const key = theme ? themeKeyOf(cssName) : null
99
+ if (key && THEME_NAMESPACES[key.ns].includes(utility)) return `${utility}-${key.key}`
100
+ return `${utility}-(${parenHint(namespaceHint ?? key?.ns, utility)}${cssName})`
101
+ }
102
+
103
+ /** Map every theme-utility class base (`bg-ink`) to the tokens it could come from. */
104
+ export function buildThemeUtilityIndex(cssNames) {
105
+ const index = new Map()
106
+ for (const name of cssNames) {
107
+ const key = themeKeyOf(name)
108
+ if (!key) continue
109
+ for (const utility of THEME_NAMESPACES[key.ns]) {
110
+ const base = `${utility}-${key.key}`
111
+ const list = index.get(base) ?? []
112
+ list.push({ token: name, ns: key.ns, utility })
113
+ index.set(base, list)
114
+ }
115
+ }
116
+ return index
117
+ }
118
+
119
+ /** Decompose one class token. Offsets are into the token. */
120
+ export function parseClassToken(token) {
121
+ let bracketDepth = 0
122
+ let parenDepth = 0
123
+ let lastColon = -1
124
+ for (let i = 0; i < token.length; i += 1) {
125
+ const ch = token[i]
126
+ if (ch === '[') bracketDepth += 1
127
+ else if (ch === ']' && bracketDepth > 0) bracketDepth -= 1
128
+ else if (ch === '(') parenDepth += 1
129
+ else if (ch === ')' && parenDepth > 0) parenDepth -= 1
130
+ else if (ch === ':' && bracketDepth === 0 && parenDepth === 0) lastColon = i
131
+ }
132
+ let start = lastColon + 1
133
+ let end = token.length
134
+ if (token[start] === '!') start += 1
135
+ else if (end > start && token[end - 1] === '!') end -= 1
136
+ const negative = token[start] === '-'
137
+ if (negative) start += 1
138
+ // Modifier: the last top-level `/` (opacity or line-height), e.g. `bg-ink/50`, `text-sm/6`.
139
+ bracketDepth = 0
140
+ parenDepth = 0
141
+ let slash = -1
142
+ for (let i = start; i < end; i += 1) {
143
+ const ch = token[i]
144
+ if (ch === '[') bracketDepth += 1
145
+ else if (ch === ']' && bracketDepth > 0) bracketDepth -= 1
146
+ else if (ch === '(') parenDepth += 1
147
+ else if (ch === ')' && parenDepth > 0) parenDepth -= 1
148
+ else if (ch === '/' && bracketDepth === 0 && parenDepth === 0) slash = i
149
+ }
150
+ const baseEnd = slash === -1 ? end : slash
151
+ return { baseStart: start, baseEnd, negative, base: token.slice(start, baseEnd) }
152
+ }
153
+
154
+ /** Top-level `[...]` and `(...)` segments of a class base, with inner offsets. */
155
+ export function groupSegments(base) {
156
+ const segments = []
157
+ let depth = 0
158
+ let open = -1
159
+ let kind = null
160
+ for (let i = 0; i < base.length; i += 1) {
161
+ const ch = base[i]
162
+ if (depth === 0 && (ch === '[' || ch === '(')) {
163
+ kind = ch
164
+ open = i
165
+ depth = 1
166
+ continue
167
+ }
168
+ if (depth > 0) {
169
+ if (ch === kind) depth += 1
170
+ else if ((kind === '[' && ch === ']') || (kind === '(' && ch === ')')) {
171
+ depth -= 1
172
+ if (depth === 0) {
173
+ segments.push({ kind, innerStart: open + 1, innerEnd: i })
174
+ kind = null
175
+ }
176
+ }
177
+ }
178
+ }
179
+ return segments
180
+ }
181
+
182
+ /**
183
+ * Rewrite one class token for a rename spec. Calls `emit(start, end, text)` /
184
+ * `leftover(offset, reason, text)` with offsets into the token.
185
+ * spec: { renames: Map<old, new>, theme: boolean, themeIndex, themeUnsupported?: string }
186
+ */
187
+ export function rewriteClassToken(token, spec, { emit, leftover }) {
188
+ const parsed = parseClassToken(token)
189
+ const { base, baseStart } = parsed
190
+ const segments = groupSegments(base)
191
+ if (segments.length) {
192
+ for (const segment of segments) {
193
+ const inner = base.slice(segment.innerStart, segment.innerEnd)
194
+ const at = baseStart + segment.innerStart
195
+ if (segment.kind === '(') {
196
+ // `(--x)` or `(hint:--x)`
197
+ const colon = inner.indexOf(':')
198
+ const nameStart = inner.startsWith('--') ? 0 : colon + 1
199
+ const name = inner.slice(nameStart)
200
+ if (spec.renames.has(name)) emit(at + nameStart, at + inner.length, spec.renames.get(name))
201
+ continue
202
+ }
203
+ // `[var(--x)]`, `[color:var(--x)]`, v3 `[--x]`
204
+ if (spec.renames.has(inner)) {
205
+ emit(at, at + inner.length, spec.renames.get(inner))
206
+ continue
207
+ }
208
+ rewriteValueVars(inner, spec.renames, {
209
+ emit: (s, e, text) => emit(at + s, at + e, text),
210
+ leftover: (offset, reason, text) => leftover(at + offset, reason, text),
211
+ })
212
+ }
213
+ return
214
+ }
215
+ if (!spec.themeIndex) return
216
+ const candidates = spec.themeIndex.get(base)
217
+ if (!candidates) return
218
+ const matched = candidates.filter((entry) => spec.renames.has(entry.token))
219
+ if (!matched.length) return
220
+ if (spec.themeUnsupported) {
221
+ leftover(baseStart, spec.themeUnsupported, token)
222
+ return
223
+ }
224
+ const tokens = new Set(candidates.map((entry) => entry.token))
225
+ if (tokens.size > 1) {
226
+ leftover(baseStart, 'ambiguous-theme-utility', `${token} could be ${[...tokens].join(' or ')}`)
227
+ return
228
+ }
229
+ const { token: oldName, utility, ns } = matched[0]
230
+ const next = spec.renames.get(oldName)
231
+ const nextKey = themeKeyOf(next)
232
+ if (!(nextKey && THEME_NAMESPACES[nextKey.ns].includes(utility)) && parsed.negative) {
233
+ leftover(baseStart, 'needs-judgment', `${token}: negative utility for a token outside the ${ns} namespace`)
234
+ return
235
+ }
236
+ emit(baseStart, parsed.baseEnd, utilityFor(utility, next, { theme: spec.theme, namespaceHint: ns }))
237
+ }
238
+
239
+ /**
240
+ * Literal → token for one class token: only an arbitrary value that is exactly the literal
241
+ * (`bg-[#2563eb]` → `bg-primary` / `bg-(--brand)`). Mixed arbitrary values are leftovers.
242
+ * spec: { literal, token, theme, utilities?, namespaceHint? }
243
+ */
244
+ export function rewriteClassLiteral(token, spec, { emit, leftover }) {
245
+ const parsed = parseClassToken(token)
246
+ const { base, baseStart } = parsed
247
+ const segments = groupSegments(base)
248
+ if (segments.length !== 1 || segments[0].kind !== '[') return
249
+ const segment = segments[0]
250
+ const inner = base.slice(segment.innerStart, segment.innerEnd)
251
+ const target = spec.literal.trim().toLowerCase()
252
+ const prefix = base.slice(0, segment.innerStart - 1)
253
+ const utility = prefix.endsWith('-') ? prefix.slice(0, -1) : ''
254
+ // `utilities`: only these utilities (one style category, e.g. `rounded*` for radius).
255
+ if (spec.utilities && !spec.utilities.includes(utility)) return
256
+ if (inner.trim().toLowerCase() === target && utility && segment.innerEnd === base.length - 1) {
257
+ if (parsed.negative) {
258
+ leftover(baseStart, 'needs-judgment', token)
259
+ return
260
+ }
261
+ emit(baseStart, parsed.baseEnd, utilityFor(utility, spec.token, { theme: spec.theme, namespaceHint: spec.namespaceHint }))
262
+ return
263
+ }
264
+ let parsedInner
265
+ try {
266
+ parsedInner = valueParser(inner.split('_').join(' '))
267
+ } catch {
268
+ return
269
+ }
270
+ let found = false
271
+ valueParser.walk(parsedInner.nodes, (node) => {
272
+ if (node.type === 'word' && node.value.toLowerCase() === target) found = true
273
+ if (node.type === 'function' && valueParser.stringify(node).toLowerCase() === target) found = true
274
+ })
275
+ if (found) leftover(baseStart, 'mixed-value', token)
276
+ }
277
+
278
+ /** Rewrite a whole class list string; offsets into `raw`. */
279
+ export function rewriteClassList(raw, spec, handlers, mode = 'rename') {
280
+ for (const entry of splitClassesWithOffsets(raw)) {
281
+ const shift = {
282
+ emit: (s, e, text) => handlers.emit(entry.start + s, entry.start + e, text),
283
+ leftover: (offset, reason, text) => handlers.leftover(entry.start + offset, reason, text ?? entry.value),
284
+ }
285
+ if (mode === 'literal') rewriteClassLiteral(entry.value, spec, shift)
286
+ else rewriteClassToken(entry.value, spec, shift)
287
+ }
288
+ }
@@ -0,0 +1,116 @@
1
+ // Position-based text edits. Rewriters never search file text: they locate nodes through a
2
+ // parser (postcss / @babel/parser / postcss-value-parser), turn node positions into absolute
3
+ // offsets, and hand those offsets here.
4
+ import { createHash } from 'node:crypto'
5
+
6
+ import { createLineIndex } from '../adapters/types.mjs'
7
+
8
+ export const sha256 = (value) => createHash('sha256').update(value).digest('hex')
9
+
10
+ /**
11
+ * Apply `{ start, end, text }` edits (absolute offsets into `content`). Edits must not
12
+ * overlap; identical duplicates (the same node reached twice) collapse into one.
13
+ */
14
+ export function applyEdits(content, edits) {
15
+ const unique = new Map()
16
+ for (const edit of edits) {
17
+ if (!(edit.start >= 0 && edit.end >= edit.start && edit.end <= content.length)) {
18
+ throw new Error(`edit out of range: ${edit.start}-${edit.end}`)
19
+ }
20
+ const key = `${edit.start}:${edit.end}`
21
+ const existing = unique.get(key)
22
+ if (existing && existing.text !== edit.text) {
23
+ throw new Error(`conflicting edits at ${edit.start}-${edit.end}`)
24
+ }
25
+ unique.set(key, edit)
26
+ }
27
+ const sorted = [...unique.values()].sort((a, b) => a.start - b.start)
28
+ for (let i = 1; i < sorted.length; i += 1) {
29
+ if (sorted[i].start < sorted[i - 1].end) {
30
+ throw new Error(`overlapping edits at ${sorted[i - 1].start}-${sorted[i - 1].end} and ${sorted[i].start}-${sorted[i].end}`)
31
+ }
32
+ }
33
+ let out = ''
34
+ let cursor = 0
35
+ for (const edit of sorted) {
36
+ out += content.slice(cursor, edit.start) + edit.text
37
+ cursor = edit.end
38
+ }
39
+ return out + content.slice(cursor)
40
+ }
41
+
42
+ /** Per-file collector: edits (with change records) and leftovers, both with line/column. */
43
+ export function createFileResult(file, content) {
44
+ const locationAt = createLineIndex(content)
45
+ const edits = []
46
+ const changes = []
47
+ const leftovers = []
48
+ return {
49
+ file,
50
+ content,
51
+ hash: sha256(content),
52
+ locationAt,
53
+ edits,
54
+ changes,
55
+ leftovers,
56
+ edit(start, end, text, info = {}) {
57
+ const from = content.slice(start, end)
58
+ if (from === text) return
59
+ edits.push({ start, end, text })
60
+ changes.push({ file, ...locationAt(start), from, to: text, ...info })
61
+ },
62
+ leftover(offset, reason, text, info = {}) {
63
+ leftovers.push({ file, ...locationAt(offset), reason, ...(text ? { text: String(text).slice(0, 120) } : {}), ...info })
64
+ },
65
+ }
66
+ }
67
+
68
+ /** Collapse a file result into the plan shape the commit step consumes. */
69
+ export function finishFileResult(result) {
70
+ const after = result.edits.length ? applyEdits(result.content, result.edits) : result.content
71
+ const dedupe = (list) => {
72
+ const seen = new Set()
73
+ return list.filter((entry) => {
74
+ const key = `${entry.line}:${entry.column}:${entry.reason ?? ''}:${entry.from ?? ''}:${entry.to ?? ''}`
75
+ if (seen.has(key)) return false
76
+ seen.add(key)
77
+ return true
78
+ })
79
+ }
80
+ const edits = [...new Map(result.edits.map((edit) => [`${edit.start}:${edit.end}`, edit])).values()]
81
+ return {
82
+ file: result.file,
83
+ hash: result.hash,
84
+ before: result.content,
85
+ after,
86
+ edits,
87
+ changes: dedupe(result.changes).sort((a, b) => a.line - b.line || a.column - b.column),
88
+ leftovers: dedupe(result.leftovers).sort((a, b) => a.line - b.line || a.column - b.column),
89
+ }
90
+ }
91
+
92
+ /** Split a class list into tokens with their offsets, keeping `[...]` / `(...)` groups whole. */
93
+ export function splitClassesWithOffsets(raw) {
94
+ const tokens = []
95
+ let start = -1
96
+ let bracketDepth = 0
97
+ let parenDepth = 0
98
+ const isSpace = (ch) => ch === ' ' || ch === '\n' || ch === '\t' || ch === '\r' || ch === '\f'
99
+ for (let i = 0; i < raw.length; i += 1) {
100
+ const ch = raw[i]
101
+ if (ch === '[') bracketDepth += 1
102
+ else if (ch === ']' && bracketDepth > 0) bracketDepth -= 1
103
+ else if (ch === '(') parenDepth += 1
104
+ else if (ch === ')' && parenDepth > 0) parenDepth -= 1
105
+ if (isSpace(ch) && bracketDepth === 0 && parenDepth === 0) {
106
+ if (start !== -1) {
107
+ tokens.push({ value: raw.slice(start, i), start })
108
+ start = -1
109
+ }
110
+ continue
111
+ }
112
+ if (start === -1) start = i
113
+ }
114
+ if (start !== -1) tokens.push({ value: raw.slice(start), start })
115
+ return tokens
116
+ }