@hyperfixi/core 3.3.0 → 4.0.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.
- package/README.md +57 -179
- package/dist/ast-utils/index.cjs +74 -806
- package/dist/ast-utils/index.d.ts +1 -1
- package/dist/ast-utils/index.mjs +74 -805
- package/dist/ast-utils/interchange/engine-positions.d.ts +3 -0
- package/dist/ast-utils/interchange/index.d.ts +1 -2
- package/dist/hyperfixi.js +19 -2
- package/dist/index.d.ts +2 -22
- package/dist/index.mjs +3 -29128
- package/dist/lsp-metadata.cjs +77 -73
- package/dist/lsp-metadata.d.ts +4 -4
- package/dist/lsp-metadata.mjs +77 -73
- package/dist/metadata.cjs +34 -266
- package/dist/metadata.d.ts +31 -26
- package/dist/metadata.mjs +34 -266
- package/dist/multilingual/index.cjs +16 -382
- package/dist/multilingual/index.d.ts +4 -32
- package/dist/multilingual/index.mjs +15 -377
- package/dist/reference/index.cjs +67 -216
- package/dist/reference/index.d.ts +0 -3
- package/dist/reference/index.mjs +68 -216
- package/dist/version.d.ts +1 -1
- package/package.json +13 -179
- package/dist/__test-utils__/context-builders.d.ts +0 -42
- package/dist/__test-utils__/error-testing.d.ts +0 -18
- package/dist/__test-utils__/index.d.ts +0 -6
- package/dist/__test-utils__/mock-types.d.ts +0 -57
- package/dist/__test-utils__/parser-context-mock.d.ts +0 -7
- package/dist/__test-utils__/parser-helpers.d.ts +0 -38
- package/dist/api/hyperscript-api.d.ts +0 -90
- package/dist/api/lokascript-api.d.ts +0 -9
- package/dist/ast/command-slots.d.ts +0 -140
- package/dist/ast/guards.d.ts +0 -15
- package/dist/ast/legacy.d.ts +0 -15
- package/dist/ast/nodes.d.ts +0 -243
- package/dist/ast-utils/interchange/from-core.d.ts +0 -12
- package/dist/ast-utils/interchange/to-core.d.ts +0 -8
- package/dist/behaviors/boosted.d.ts +0 -29
- package/dist/behaviors/history-swap.d.ts +0 -24
- package/dist/behaviors/index.cjs +0 -1155
- package/dist/behaviors/index.d.ts +0 -4
- package/dist/behaviors/index.mjs +0 -1145
- package/dist/bundle-generator/executor-core.d.ts +0 -4
- package/dist/bundle-generator/generator.d.ts +0 -4
- package/dist/bundle-generator/index.cjs +0 -2804
- package/dist/bundle-generator/index.d.ts +0 -6
- package/dist/bundle-generator/index.mjs +0 -2779
- package/dist/bundle-generator/parser-templates.d.ts +0 -6
- package/dist/bundle-generator/template-capabilities.d.ts +0 -12
- package/dist/bundle-generator/templates.d.ts +0 -12
- package/dist/bundle-generator/types.d.ts +0 -34
- package/dist/chunks/bridge-CI9SOl8u.js +0 -2
- package/dist/chunks/browser-modular-7CpI5VF2.js +0 -2
- package/dist/chunks/index-BwXDEK0m.js +0 -2
- package/dist/chunks/index-DQi2o8Lk.js +0 -2
- package/dist/chunks/index-uCOQ8Qn0.js +0 -2
- package/dist/commands/advanced/js.d.ts +0 -40
- package/dist/commands/animation/measure.d.ts +0 -43
- package/dist/commands/animation/settle.d.ts +0 -38
- package/dist/commands/animation/start-view-transition.d.ts +0 -38
- package/dist/commands/animation/take.d.ts +0 -41
- package/dist/commands/animation/transition.d.ts +0 -49
- package/dist/commands/async/fetch.d.ts +0 -61
- package/dist/commands/async/wait.d.ts +0 -51
- package/dist/commands/behaviors/install.d.ts +0 -40
- package/dist/commands/content/append.d.ts +0 -26
- package/dist/commands/content/insertion-base.d.ts +0 -60
- package/dist/commands/content/prepend.d.ts +0 -26
- package/dist/commands/control-flow/break.d.ts +0 -29
- package/dist/commands/control-flow/continue.d.ts +0 -29
- package/dist/commands/control-flow/exit.d.ts +0 -29
- package/dist/commands/control-flow/halt.d.ts +0 -39
- package/dist/commands/control-flow/if.d.ts +0 -58
- package/dist/commands/control-flow/repeat.d.ts +0 -50
- package/dist/commands/control-flow/return.d.ts +0 -33
- package/dist/commands/control-flow/signal-base.d.ts +0 -18
- package/dist/commands/control-flow/throw.d.ts +0 -34
- package/dist/commands/control-flow/unless.d.ts +0 -3
- package/dist/commands/data/clear.d.ts +0 -37
- package/dist/commands/data/decrement.d.ts +0 -3
- package/dist/commands/data/default.d.ts +0 -60
- package/dist/commands/data/get.d.ts +0 -35
- package/dist/commands/data/increment.d.ts +0 -42
- package/dist/commands/data/set.d.ts +0 -76
- package/dist/commands/decorators/index.d.ts +0 -14
- package/dist/commands/dom/add.d.ts +0 -44
- package/dist/commands/dom/close.d.ts +0 -32
- package/dist/commands/dom/dom-modification-base.d.ts +0 -48
- package/dist/commands/dom/empty.d.ts +0 -32
- package/dist/commands/dom/hide.d.ts +0 -28
- package/dist/commands/dom/make.d.ts +0 -34
- package/dist/commands/dom/open.d.ts +0 -34
- package/dist/commands/dom/process-partials.d.ts +0 -51
- package/dist/commands/dom/put.d.ts +0 -42
- package/dist/commands/dom/remove.d.ts +0 -46
- package/dist/commands/dom/reset.d.ts +0 -32
- package/dist/commands/dom/select.d.ts +0 -32
- package/dist/commands/dom/show.d.ts +0 -29
- package/dist/commands/dom/swap.d.ts +0 -65
- package/dist/commands/dom/toggle.d.ts +0 -69
- package/dist/commands/dom/visibility-base.d.ts +0 -22
- package/dist/commands/events/send.d.ts +0 -3
- package/dist/commands/events/trigger.d.ts +0 -49
- package/dist/commands/execution/blur.d.ts +0 -32
- package/dist/commands/execution/call.d.ts +0 -35
- package/dist/commands/execution/focus.d.ts +0 -32
- package/dist/commands/execution/pseudo-command.d.ts +0 -41
- package/dist/commands/helpers/attribute-manipulation.d.ts +0 -11
- package/dist/commands/helpers/attribute-target.d.ts +0 -9
- package/dist/commands/helpers/batch-dom-operations.d.ts +0 -12
- package/dist/commands/helpers/body-ops.d.ts +0 -10
- package/dist/commands/helpers/class-manipulation.d.ts +0 -11
- package/dist/commands/helpers/condition-helpers.d.ts +0 -4
- package/dist/commands/helpers/dom-mutation.d.ts +0 -16
- package/dist/commands/helpers/duration-parsing.d.ts +0 -8
- package/dist/commands/helpers/element-property-access.d.ts +0 -7
- package/dist/commands/helpers/element-resolution.d.ts +0 -16
- package/dist/commands/helpers/error-helpers.d.ts +0 -17
- package/dist/commands/helpers/event-helpers.d.ts +0 -13
- package/dist/commands/helpers/event-waiting.d.ts +0 -37
- package/dist/commands/helpers/index.d.ts +0 -32
- package/dist/commands/helpers/input-validator.d.ts +0 -23
- package/dist/commands/helpers/loop-executor.d.ts +0 -56
- package/dist/commands/helpers/numeric-target-parser.d.ts +0 -21
- package/dist/commands/helpers/property-target.d.ts +0 -20
- package/dist/commands/helpers/selector-type-detection.d.ts +0 -24
- package/dist/commands/helpers/slots.d.ts +0 -5
- package/dist/commands/helpers/smart-element.d.ts +0 -16
- package/dist/commands/helpers/style-manipulation.d.ts +0 -16
- package/dist/commands/helpers/target-elements.d.ts +0 -5
- package/dist/commands/helpers/temporal-modifiers.d.ts +0 -15
- package/dist/commands/helpers/url-argument-parser.d.ts +0 -13
- package/dist/commands/helpers/url-validation.d.ts +0 -7
- package/dist/commands/helpers/variable-access.d.ts +0 -13
- package/dist/commands/helpers/visibility-target-parser.d.ts +0 -15
- package/dist/commands/helpers/write-target.d.ts +0 -42
- package/dist/commands/index.cjs +0 -24168
- package/dist/commands/index.d.ts +0 -171
- package/dist/commands/index.mjs +0 -23981
- package/dist/commands/manifest.d.ts +0 -17
- package/dist/commands/navigation/go.d.ts +0 -58
- package/dist/commands/navigation/push-url.d.ts +0 -48
- package/dist/commands/navigation/replace-url.d.ts +0 -3
- package/dist/commands/navigation/scroll-to.d.ts +0 -43
- package/dist/commands/templates/render.d.ts +0 -47
- package/dist/commands/utility/beep.d.ts +0 -41
- package/dist/commands/utility/breakpoint.d.ts +0 -32
- package/dist/commands/utility/copy.d.ts +0 -41
- package/dist/commands/utility/log.d.ts +0 -36
- package/dist/commands/utility/pick.d.ts +0 -47
- package/dist/commands/utility/tell.d.ts +0 -39
- package/dist/compatibility/browser-bundle-classic.d.ts +0 -17
- package/dist/compatibility/browser-bundle-hybrid-complete.d.ts +0 -22
- package/dist/compatibility/browser-bundle-hybrid-hx.d.ts +0 -43
- package/dist/compatibility/browser-bundle-lite.d.ts +0 -15
- package/dist/compatibility/browser-bundle-modular.d.ts +0 -18
- package/dist/compatibility/browser-bundle-multilingual.d.ts +0 -19
- package/dist/compatibility/browser-bundle-semantic-complete.d.ts +0 -24
- package/dist/compatibility/browser-bundle-textshelf-minimal.d.ts +0 -16
- package/dist/compatibility/browser-bundle-textshelf-profile.d.ts +0 -18
- package/dist/compatibility/browser-modular.d.ts +0 -42
- package/dist/compatibility/browser-tests/helpers/semantic-page.d.ts +0 -3
- package/dist/compatibility/browser-tests/test-utils.d.ts +0 -21
- package/dist/compatibility/bundle-shell.d.ts +0 -13
- package/dist/compatibility/bundle-sources.d.ts +0 -4
- package/dist/compatibility/eval-hyperscript.d.ts +0 -16
- package/dist/compatibility/hyperscript-adapter.d.ts +0 -38
- package/dist/core/ast-property-utils.d.ts +0 -2
- package/dist/core/context.d.ts +0 -19
- package/dist/core/dom.d.ts +0 -15
- package/dist/core/evaluator-types.d.ts +0 -5
- package/dist/core/events.d.ts +0 -48
- package/dist/core/executor.d.ts +0 -34
- package/dist/core/expression-evaluator.d.ts +0 -6
- package/dist/core/expression-registry.d.ts +0 -8
- package/dist/core/scope-hooks.d.ts +0 -24
- package/dist/debug/debug-controller.d.ts +0 -62
- package/dist/debug/index.d.ts +0 -5
- package/dist/dom/attribute-processor.d.ts +0 -75
- package/dist/dom/detect-language.d.ts +0 -3
- package/dist/dom/minimal-attribute-processor.d.ts +0 -20
- package/dist/expressions/base-expression.d.ts +0 -27
- package/dist/expressions/bundles/common-expressions.d.ts +0 -10
- package/dist/expressions/bundles/core-expressions.d.ts +0 -8
- package/dist/expressions/bundles/full-expressions.d.ts +0 -11
- package/dist/expressions/bundles/index.d.ts +0 -7
- package/dist/expressions/collection/index.d.ts +0 -10
- package/dist/expressions/conversion/index.d.ts +0 -31
- package/dist/expressions/expression-tiers.d.ts +0 -13
- package/dist/expressions/index.cjs +0 -4331
- package/dist/expressions/index.d.ts +0 -13
- package/dist/expressions/index.mjs +0 -4312
- package/dist/expressions/logical/index.d.ts +0 -61
- package/dist/expressions/mathematical/index.d.ts +0 -80
- package/dist/expressions/positional/index.d.ts +0 -31
- package/dist/expressions/properties/index.d.ts +0 -27
- package/dist/expressions/property-access-utils.d.ts +0 -23
- package/dist/expressions/references/index.d.ts +0 -39
- package/dist/expressions/shared/comparison-utils.d.ts +0 -10
- package/dist/expressions/shared/index.d.ts +0 -10
- package/dist/expressions/shared/number-utils.d.ts +0 -8
- package/dist/expressions/shared/tracking.d.ts +0 -20
- package/dist/expressions/shared/validation-utils.d.ts +0 -13
- package/dist/expressions/special/index.d.ts +0 -78
- package/dist/expressions/type-helpers.d.ts +0 -11
- package/dist/expressions/type-registry.d.ts +0 -57
- package/dist/expressions/validation-helpers.d.ts +0 -15
- package/dist/htmx/hcon.d.ts +0 -9
- package/dist/htmx/htmx-attribute-processor.d.ts +0 -120
- package/dist/htmx/htmx-translator.d.ts +0 -22
- package/dist/htmx/i18n-hooks.d.ts +0 -18
- package/dist/htmx/i18n-orchestrator.d.ts +0 -16
- package/dist/htmx/index.d.ts +0 -3
- package/dist/htmx/lang-resolver.d.ts +0 -3
- package/dist/htmx/sse.d.ts +0 -60
- package/dist/htmx/ws.d.ts +0 -59
- package/dist/hyperfixi-browser-classic-i18n.js +0 -2
- package/dist/hyperfixi-browser.js +0 -2
- package/dist/hyperfixi-classic-i18n.js +0 -2
- package/dist/hyperfixi-hx-v4.js +0 -1
- package/dist/hyperfixi-hx.js +0 -1
- package/dist/hyperfixi-hybrid-complete.js +0 -1
- package/dist/hyperfixi-hybrid-hx.js +0 -1
- package/dist/hyperfixi-multilingual.js +0 -2
- package/dist/hyperfixi.mjs +0 -2
- package/dist/i18n/error-catalog.d.ts +0 -12
- package/dist/index.cjs +0 -29159
- package/dist/index.min.js +0 -2
- package/dist/lib/dom-globals-shim.d.ts +0 -2
- package/dist/lib/index.d.ts +0 -4
- package/dist/lib/morph-adapter.d.ts +0 -9
- package/dist/lib/swap-executor.d.ts +0 -12
- package/dist/lib/view-transitions.d.ts +0 -7
- package/dist/lokascript-browser-classic-i18n.js +0 -2
- package/dist/lokascript-browser.js +0 -2
- package/dist/lokascript-hybrid-complete.js +0 -1
- package/dist/lokascript-hybrid-hx.js +0 -1
- package/dist/lokascript-multilingual.js +0 -2
- package/dist/lse/index.cjs +0 -84
- package/dist/lse/index.d.ts +0 -15
- package/dist/lse/index.mjs +0 -71
- package/dist/multilingual/bridge.d.ts +0 -38
- package/dist/multilingual/schema-roles.d.ts +0 -3
- package/dist/parser/__types__/test-helpers.d.ts +0 -25
- package/dist/parser/command-grammar.d.ts +0 -14
- package/dist/parser/command-node-builder.d.ts +0 -46
- package/dist/parser/command-parsers/animation-commands.d.ts +0 -6
- package/dist/parser/command-parsers/async-commands.d.ts +0 -5
- package/dist/parser/command-parsers/control-flow-commands.d.ts +0 -7
- package/dist/parser/command-parsers/declared-commands.d.ts +0 -6
- package/dist/parser/command-parsers/dom-commands.d.ts +0 -11
- package/dist/parser/command-parsers/event-commands.d.ts +0 -4
- package/dist/parser/command-parsers/navigation-commands.d.ts +0 -6
- package/dist/parser/command-parsers/utility-commands.d.ts +0 -14
- package/dist/parser/command-parsers/variable-commands.d.ts +0 -12
- package/dist/parser/error-handler.d.ts +0 -34
- package/dist/parser/extensions.d.ts +0 -43
- package/dist/parser/full-parser.cjs +0 -7943
- package/dist/parser/full-parser.d.ts +0 -4
- package/dist/parser/full-parser.mjs +0 -7940
- package/dist/parser/helpers/ast-helpers.d.ts +0 -24
- package/dist/parser/helpers/parsing-helpers.d.ts +0 -19
- package/dist/parser/helpers/token-helpers.d.ts +0 -28
- package/dist/parser/hybrid/aliases.cjs +0 -44
- package/dist/parser/hybrid/aliases.d.ts +0 -7
- package/dist/parser/hybrid/aliases.mjs +0 -37
- package/dist/parser/hybrid/ast-types.cjs +0 -3
- package/dist/parser/hybrid/ast-types.d.ts +0 -97
- package/dist/parser/hybrid/ast-types.mjs +0 -2
- package/dist/parser/hybrid/index.cjs +0 -1185
- package/dist/parser/hybrid/index.d.ts +0 -6
- package/dist/parser/hybrid/index.mjs +0 -1175
- package/dist/parser/hybrid/parser-core.cjs +0 -1171
- package/dist/parser/hybrid/parser-core.d.ts +0 -69
- package/dist/parser/hybrid/parser-core.mjs +0 -1169
- package/dist/parser/hybrid/tokenizer.cjs +0 -255
- package/dist/parser/hybrid/tokenizer.d.ts +0 -9
- package/dist/parser/hybrid/tokenizer.mjs +0 -252
- package/dist/parser/hybrid-parser.cjs +0 -1249
- package/dist/parser/hybrid-parser.d.ts +0 -10
- package/dist/parser/hybrid-parser.mjs +0 -1242
- package/dist/parser/parser-constants.d.ts +0 -100
- package/dist/parser/parser-interface.d.ts +0 -12
- package/dist/parser/parser-types.d.ts +0 -164
- package/dist/parser/parser.d.ts +0 -165
- package/dist/parser/pratt-parser.d.ts +0 -41
- package/dist/parser/regex-parser.cjs +0 -422
- package/dist/parser/regex-parser.d.ts +0 -4
- package/dist/parser/regex-parser.mjs +0 -419
- package/dist/parser/runtime.d.ts +0 -14
- package/dist/parser/semantic-integration.d.ts +0 -17
- package/dist/parser/token-consumer.d.ts +0 -34
- package/dist/parser/token-predicates.d.ts +0 -77
- package/dist/parser/tokenizer.d.ts +0 -28
- package/dist/parser/types.d.ts +0 -105
- package/dist/performance/expression-cache.d.ts +0 -78
- package/dist/performance/integration.d.ts +0 -40
- package/dist/performance/production-monitor.d.ts +0 -67
- package/dist/registry/browser-types.cjs +0 -81
- package/dist/registry/browser-types.d.ts +0 -20
- package/dist/registry/browser-types.mjs +0 -76
- package/dist/registry/environment.cjs +0 -36
- package/dist/registry/environment.d.ts +0 -19
- package/dist/registry/environment.mjs +0 -30
- package/dist/registry/event-source-registry.d.ts +0 -54
- package/dist/registry/examples/server-commands.d.ts +0 -6
- package/dist/registry/examples/server-event-source.d.ts +0 -32
- package/dist/registry/index.cjs +0 -14055
- package/dist/registry/index.d.ts +0 -39
- package/dist/registry/index.mjs +0 -14039
- package/dist/registry/runtime-integration.d.ts +0 -23
- package/dist/registry/universal-types.cjs +0 -91
- package/dist/registry/universal-types.d.ts +0 -35
- package/dist/registry/universal-types.mjs +0 -86
- package/dist/runtime/cleanup-registry.d.ts +0 -47
- package/dist/runtime/command-adapter.d.ts +0 -69
- package/dist/runtime/environment.d.ts +0 -75
- package/dist/runtime/plugin.d.ts +0 -14
- package/dist/runtime/runtime-base.d.ts +0 -100
- package/dist/runtime/runtime-factory.d.ts +0 -29
- package/dist/runtime/runtime.d.ts +0 -20
- package/dist/runtime/temporal-modifiers.d.ts +0 -37
- package/dist/test-setup.d.ts +0 -28
- package/dist/test-utilities.d.ts +0 -39
- package/dist/types/base-types.d.ts +0 -231
- package/dist/types/code-fix.d.ts +0 -39
- package/dist/types/command-metadata.d.ts +0 -57
- package/dist/types/command-types.d.ts +0 -262
- package/dist/types/context-types.d.ts +0 -106
- package/dist/types/core-context.d.ts +0 -22
- package/dist/types/core.d.ts +0 -143
- package/dist/types/error-codes.d.ts +0 -207
- package/dist/types/expression-types.d.ts +0 -155
- package/dist/types/hooks.d.ts +0 -45
- package/dist/types/index.d.ts +0 -32
- package/dist/types/program.d.ts +0 -8
- package/dist/types/result.d.ts +0 -73
- package/dist/types/template-types.d.ts +0 -162
- package/dist/types/type-guards.d.ts +0 -24
- package/dist/types/unified-types.d.ts +0 -91
- package/dist/utils/beep.d.ts +0 -8
- package/dist/utils/debug-events.d.ts +0 -41
- package/dist/utils/debug.d.ts +0 -35
- package/dist/utils/dom-utils.d.ts +0 -16
- package/dist/utils/element-check.d.ts +0 -8
- package/dist/utils/keyboard-shortcuts.d.ts +0 -18
- package/dist/utils/performance.d.ts +0 -40
- package/dist/validation/command-pattern-validator.d.ts +0 -53
- package/dist/validation/common-validators.d.ts +0 -24
- package/dist/validation/lightweight-validators.d.ts +0 -113
- package/dist/validation/partial-validation-types.d.ts +0 -50
- package/dist/validation/partial-validator.d.ts +0 -6
- package/dist/validation/partial-warning-formatter.d.ts +0 -6
- package/dist/validation/validate-cli.d.ts +0 -41
- package/vocab/htmx/ar.js +0 -62
- package/vocab/htmx/bn.js +0 -65
- package/vocab/htmx/de.js +0 -83
- package/vocab/htmx/en.js +0 -24
- package/vocab/htmx/es.js +0 -79
- package/vocab/htmx/fr.js +0 -79
- package/vocab/htmx/he.js +0 -61
- package/vocab/htmx/hi.js +0 -81
- package/vocab/htmx/id.js +0 -76
- package/vocab/htmx/it.js +0 -79
- package/vocab/htmx/ja.js +0 -85
- package/vocab/htmx/ko.js +0 -81
- package/vocab/htmx/ms.js +0 -58
- package/vocab/htmx/pl.js +0 -80
- package/vocab/htmx/pt.js +0 -81
- package/vocab/htmx/qu.js +0 -83
- package/vocab/htmx/ru.js +0 -82
- package/vocab/htmx/sw.js +0 -79
- package/vocab/htmx/th.js +0 -67
- package/vocab/htmx/tl.js +0 -56
- package/vocab/htmx/tr.js +0 -86
- package/vocab/htmx/uk.js +0 -82
- package/vocab/htmx/vi.js +0 -59
- package/vocab/htmx/zh.js +0 -79
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
function e(e,t){return t?{type:"literal",value:e,dataType:t}:{type:"literal",value:e}}function t(e,t){return t?{type:"selector",value:e,selectorKind:t}:{type:"selector",value:e}}function n(e){return{type:"reference",value:e}}function r(e,t){return{type:"property-path",object:e,property:t}}function o(e){return{type:"expression",raw:e}}function s(e,t=!0){return{type:"flag",name:e,enabled:t}}function i(e,t,n){const r={kind:"command",action:e,roles:t instanceof Map?t:new Map(Object.entries(t))};return n?{...r,metadata:n}:r}function a(e,t,n,r,o){return{kind:"event-handler",action:e,roles:t instanceof Map?t:new Map(Object.entries(t)),body:n,...o&&{eventModifiers:o},...r&&{metadata:r}}}function c(e,t,n,r,o){return{kind:"conditional",action:e,roles:t instanceof Map?t:new Map(Object.entries(t)),thenBranch:n,...r&&{elseBranch:r},...o&&{metadata:o}}}function l(e,t="sequential",n){const r={kind:"compound",action:"compound",roles:new Map,statements:e,chainType:t};return n?{...r,metadata:n}:r}function u(e,t,n,r,o,s,i){return{kind:"loop",action:e,roles:t instanceof Map?t:new Map(Object.entries(t)),loopVariant:n,body:r,...o&&{loopVariable:o},...s&&{indexVariable:s},...i&&{metadata:i}}}function d(e,t,n,r){return{kind:"command",action:"try",roles:new Map,body:e,...t&&t.length>0?{catchBranch:t}:{},...n&&n.length>0?{finallyBranch:n}:{},...r?{metadata:r}:{}}}function f(e,t,n){return{kind:"command",action:e,roles:new Map,asyncVariant:e,asyncBody:t,...n?{metadata:n}:{}}}function p(e,t,n,r){return{kind:"command",action:"match",roles:e instanceof Map?e:new Map(Object.entries(e)),arms:t,...n&&n.length>0?{defaultArm:n}:{},...r?{metadata:r}:{}}}function h(e){return"flag"===e.type?e.name:"raw"in e&&void 0!==e.raw?e.raw+"":"value"in e&&void 0!==e.value?e.value+"":"property-path"===e.type?`${h(e.object)}.${e.property}`:""}function m(e,t){return e.roles.get(t)}function g(e,t){const n=e.roles.get(t);return n?h(n):""}function y(){const e=[];function t(t,n,r){const o={message:n,severity:t,...null!=r?.code&&{code:r.code},...null!=r?.line&&{line:r.line},...null!=r?.column&&{column:r.column},...null!=r?.source&&{source:r.source},...null!=r?.suggestions&&r.suggestions.length>0&&{suggestions:r.suggestions}};e.push(o)}return{error(e,n,r){"string"==typeof n?t("error",n,{...r,code:e}):t("error",e,n)},warning(e,n){t("warning",e,n)},info(e,n){t("info",e,n)},add(t){e.push(t)},hasErrors:()=>e.some(e=>"error"===e.severity),getDiagnostics:()=>e,toResult(){let t=0,n=0,r=0;for(const o of e)"error"===o.severity?t++:"warning"===o.severity?n++:r++;return{ok:0===t,diagnostics:e,summary:{errors:t,warnings:n,infos:r}}}}}function v(e,t){return{message:e instanceof Error?e.message:e+"",severity:"error",...null!=t?.code&&{code:t.code},...null!=t?.line&&{line:t.line},...null!=t?.column&&{column:t.column},...null!=t?.source&&{source:t.source},...null!=t?.suggestions&&t.suggestions.length>0&&{suggestions:t.suggestions}}}function b(e,t){return e.filter(e=>e.severity===t)}function k(e){if("object"!=typeof e||null===e)throw new TypeError(`defineCommand: expected a schema object, got ${S(e)}.`);if("string"!=typeof e.action||0===e.action.length)throw new TypeError(`defineCommand: 'action' must be a non-empty string (got ${S(e.action)}).`);if(!Array.isArray(e.roles))throw new TypeError(`defineCommand("${e.action}"): 'roles' must be an array of RoleSpec (got ${S(e.roles)}). Build entries with defineRole().`);for(const[t,n]of e.roles.entries())if("object"!=typeof n||null===n||"string"!=typeof n.role)throw new TypeError(`defineCommand("${e.action}"): roles[${t}] must be a RoleSpec with a string 'role' field (got ${S(n)}). Build it with defineRole().`);return{description:e.description||e.action+" command",category:e.category||"general",primaryRole:e.primaryRole||e.roles[0]?.role||"patient",...e,action:e.action,roles:e.roles}}function w(e){return{description:e.description||e.role+" role",...e,role:e.role,required:e.required,expectedTypes:e.expectedTypes}}function x(e,t){if(e&&Array.isArray(e.roles))return e.roles.find(e=>e.role===t)}function S(e){return null===e?"null":Array.isArray(e)?"an array of length "+e.length:"string"==typeof e?"the string "+JSON.stringify(e):"object"==typeof e?"an object":void 0===e?"undefined":e+""}var E=new Set(["me","you","it","result","event","target","body","document","window","detail"]);function T(e,t=E){return t.has(e)}var L=new Set(["body","then","else","condition","loop-body","variable","catch","finally"]),A=new Set(["repeat","for"]),M=new Set(["loop-variant","index-variable"]);function $(e,t={}){const n=e.trim(),r=!0===t.collectDiagnostics,o=[];if(!n.startsWith("[")||!n.endsWith("]"))throw Error("Explicit syntax must be wrapped in brackets: [command role:value ...]");const l=n.slice(1,-1).trim();if(!l)throw Error("Empty explicit statement");const d=function(e){const t=[];let n="",r=!1,o="",s=!1,i=0;for(let a=0;e.length>a;a++){const c=e[a];if(r){if(n+=c,c===o){let t=0;for(let n=a-1;n>=0&&"\\"===e[n];n--)t++;t%2==0&&(r=!1)}}else'"'!==c&&"'"!==c?s?(n+=c,">"===c&&n.endsWith("/>")&&(s=!1)):"<"!==c||""!==n&&!n.endsWith(":")?"["!==c?"]"!==c?" "!==c||0!==i?n+=c:n&&(t.push(n),n=""):(i--,n+=c):(i++,n+=c):(s=!0,n+=c):(r=!0,o=c,n+=c)}n&&t.push(n);return t}(l);if(0===d.length)throw Error("No command specified in explicit statement");const f=d[0].toLowerCase(),p=new Map,h=t.referenceSet??E,m=t.schemaLookup?.getSchema(f),g=m?new Set(m.roles.map(e=>e.role)):null;for(let e=1;d.length>e;e++){const t=d[e];if(t.startsWith("+")||t.startsWith("~")){const e=t.startsWith("+"),n=t.slice(1);if(!n){if(r){o.push({severity:"error",code:"EMPTY_FLAG",message:`Empty flag name: "${t}"`,source:"schema"});continue}throw Error(`Empty flag name: "${t}"`)}if(g&&!g.has(n)){if(r){o.push({severity:"error",code:"UNKNOWN_FLAG",message:`Unknown flag "${n}" for command "${f}"`,source:"schema",suggestions:[...g].map(e=>"+"+e)}),p.set(n,s(n,e));continue}throw Error(`Unknown flag "${n}" for command "${f}". Valid roles: ${[...g].join(", ")}`)}p.set(n,s(n,e));continue}const n=t.indexOf(":");if(-1===n){if(r){o.push({severity:"error",code:"INVALID_ROLE_FORMAT",message:`Invalid role format: "${t}". Expected role:value or +flag`,source:"schema"});continue}throw Error(`Invalid role format: "${t}". Expected role:value or +flag`)}const i=t.slice(0,n);if(g&&!L.has(i)&&(!A.has(f)||!M.has(i))&&!g.has(i)){if(!r)throw Error(`Unknown role "${i}" for command "${f}". Valid roles: ${[...g].join(", ")}`);o.push({severity:"error",code:"UNKNOWN_ROLE",message:`Unknown role "${i}" for command "${f}"`,source:"schema",suggestions:[...g]})}const a=i,c=t.slice(n+1);if(L.has(i)&&c.startsWith("[")){const e=D(t,n+1),r=t.slice(n+1,e+1);p.set(a,{type:"expression",raw:r});continue}const l=B(c,h);p.set(a,l)}if(m&&"on"!==f)for(const e of m.roles)if(e.required&&!p.has(e.role)&&!e.default){if(!r)throw Error(`Missing required role "${e.role}" for command "${f}": ${e.description}`);o.push({severity:"error",code:"MISSING_REQUIRED_ROLE",message:`Missing required role "${e.role}" for command "${f}": ${e.description}`,source:"schema"})}const y=e=>0===o.length?e:{...e,diagnostics:o};switch(f){case"on":{if(!p.get("event")){if(r)return o.push({severity:"error",code:"MISSING_EVENT_ROLE",message:"Event handler requires event role: [on event:click ...]",source:"schema"}),y(a("on",p,[],{sourceLanguage:"explicit"}));throw Error("Event handler requires event role: [on event:click ...]")}const e=P(p,"body",t);return p.delete("body"),y(a("on",p,e,{sourceLanguage:"explicit"}))}case"if":{const e=P(p,"then",t),n=P(p,"else",t);return p.delete("then"),p.delete("else"),y(c(f,p,e,n.length>0?n:void 0,{sourceLanguage:"explicit"}))}case"repeat":case"for":{const e=P(p,"loop-body",t),n=p.get("loop-variant"),r=p.get("variable"),o=p.get("index-variable");let s;p.delete("loop-body"),p.delete("loop-variant"),p.delete("variable"),p.delete("index-variable"),s=n&&"literal"===n.type&&"string"==typeof n.value?n.value:p.has("quantity")?"times":p.has("source")?"for":p.has("condition")?"while":"forever";return y(u(f,p,s,e,"literal"===r?.type&&"string"==typeof r.value?r.value:"expression"===r?.type?r.raw:void 0,"literal"===o?.type&&"string"==typeof o.value?o.value:void 0,{sourceLanguage:"explicit"}))}default:return y(i(f,p,{sourceLanguage:"explicit"}))}}function N(e){const t=e.trim();return t.startsWith("[")&&t.endsWith("]")}var O=new Set(["then","and","async","sequential"]);function j(e){const t=[];let n=null,r="",o=0,s=!1,i="";for(let a=0;e.length>a;a++){const c=e[a];if(s)r+=c,c===i&&"\\"!==e[a-1]&&(s=!1);else if('"'!==c&&"'"!==c)if("["!==c){if("]"!==c)r+=c;else if(o--,r+=c,0===o){const o=e.slice(a+1),s=o.match(/^\s*\|>\s*/);if(s){t.push(r.trim()),r="",n??(n="pipe"),a+=s[0].length;continue}const i=o.match(/^\s+(then|and|async|sequential)\s+/);if(i&&O.has(i[1])){t.push(r.trim()),r="",n??(n=i[1]),a+=i[0].length;continue}}}else o++,r+=c;else s=!0,i=c,r+=c}return r.trim()&&t.push(r.trim()),{segments:t,chainType:n}}function C(e,t){const n=e.trim(),{annotations:r,remainder:o}=function(e){const t=[];let n=0;for(;e.length>n;){for(;e.length>n&&(" "===e[n]||"\t"===e[n]);)n++;if(n>=e.length||"@"!==e[n])break;n++;const r=n;for(;e.length>n&&/[A-Za-z0-9\-_]/.test(e[n]);)n++;const o=e.slice(r,n);if(!o)break;let s;if(e.length>n&&"("===e[n]){n++;const t=n;if(e.length<=n||'"'!==e[n]&&"'"!==e[n]){for(;e.length>n&&")"!==e[n];)n++;s=e.slice(t,n)}else{const r=e[n];for(n++;e.length>n&&e[n]!==r;)"\\"===e[n]&&n++,n++;n++,s=e.slice(t+1,n-1)}e.length>n&&")"===e[n]&&n++}t.push(void 0!==s?{name:o,value:s}:{name:o})}return{annotations:t,remainder:e.slice(n).trim()}}(n),{segments:s,chainType:i}=j(o);let a;if(1<s.length){a=l(s.map(e=>$(e,t)),i??"sequential")}else a=$(s[0]||o,t);return r.length>0?{...a,annotations:r}:a}var I=/^#!lse\s+(\d+\.\d+(?:\.\d+)?)\s*$/;function R(e,t){const n=e.split("\n");let r="1.0";const o=[];let s=0;for(let e=0;n.length>e;e++){const t=n[e].trim();if(!t)continue;const o=t.match(I);o&&(r=o[1],s=e+1);break}for(let e=s;n.length>e;e++){const r=n[e].trim();r&&(r.startsWith("//")||r.startsWith("#")&&!r.startsWith("#!")||o.push(C(r,t)))}return{lseVersion:r,nodes:o}}function _(e){const{segments:t}=j(e.trim());return t.length>1}function W(e){const t=e.trim();return!!t.includes("\n")||(!!I.test(t)||!!(t.startsWith("//")||t.startsWith("#")&&!t.startsWith("#!")))}function P(e,t,n){const r=e.get(t);return r&&"expression"===r.type?[$(r.raw,n)]:[]}function V(e){if(e)return function(e){let t="";for(const n of e)if(t)n===t&&(t="");else if('"'!==n&&"'"!==n){if(" "===n||">"===n||"+"===n||"~"===n||","===n)return!0}else t=n;return!1}(e)?"complex":e.startsWith("#")?"id":e.startsWith(".")?"class":e.startsWith("[")?"attribute":e.startsWith("*")?"element":void 0}function B(r,o){if(r.startsWith("<")){if(!r.endsWith("/>"))throw Error(`Unterminated selector literal: "${r}". Expected a closing "/>"`);const e=r.slice(1,-2);if(!e)throw Error(`Empty selector literal: "${r}"`);return t(e,V(e))}if(r.startsWith("#")||r.startsWith(".")||r.startsWith("[")||r.startsWith("@")||r.startsWith("*"))return t(r,V(r));if(r.startsWith('"')||r.startsWith("'"))return e(function(e){if(!e.includes("\\"))return e;let t="";for(let n=0;e.length>n;n++){if("\\"===e[n]&&e.length>n+1){const r=e[n+1],o="\\"===r?"\\":'"'===r?'"':"'"===r?"'":"n"===r?"\n":"r"===r?"\r":"t"===r?"\t":"";if(o){t+=o,n++;continue}}t+=e[n]}return t}(r.slice(1,-1)),"string");if("true"===r)return e(!0,"boolean");if("false"===r)return e(!1,"boolean");const s=r.toLowerCase();if(T(s,o))return n(s);const i=r.match(/^(-?\d+(?:\.\d+)?)(ms|s|m|h)?$/);if(i){const t=parseFloat(i[1]);return i[2]?e(r,"duration"):e(t,"number")}return e(r)}function D(e,t){let n=0;for(let r=t;e.length>r;r++)if("["===e[r])n++;else if("]"===e[r]&&(n--,0===n))return r;return e.length-1}function z(e){let t;if("compound"===e.kind){const n=e;t=n.statements.map(e=>z(e)).join(` ${n.chainType} `)}else t=function(e){const t=[e.action];for(const[n,r]of e.roles)t.push("flag"===r.type?r.enabled?"+"+r.name:"~"+r.name:`${n}:${K(r)}`);if("event-handler"===e.kind){e.body&&e.body.length>0&&t.push("body:"+e.body.map(e=>z(e)).join(" "))}if("conditional"===e.kind){const n=e;n.thenBranch&&n.thenBranch.length>0&&t.push("then:"+n.thenBranch.map(e=>z(e)).join(" ")),n.elseBranch&&n.elseBranch.length>0&&t.push("else:"+n.elseBranch.map(e=>z(e)).join(" "))}if("loop"===e.kind){const n=e;n.loopVariant&&t.push("loop-variant:"+n.loopVariant),n.loopVariable&&t.push("variable:"+n.loopVariable),n.indexVariable&&t.push("index-variable:"+n.indexVariable),n.body&&n.body.length>0&&t.push("loop-body:"+n.body.map(e=>z(e)).join(" "))}if("command"===e.kind){const n=e;n.body&&n.body.length>0&&t.push("body:"+n.body.map(e=>z(e)).join(" ")),n.catchBranch&&n.catchBranch.length>0&&t.push("catch:"+n.catchBranch.map(e=>z(e)).join(" ")),n.finallyBranch&&n.finallyBranch.length>0&&t.push("finally:"+n.finallyBranch.map(e=>z(e)).join(" ")),n.asyncVariant&&t.push("async-variant:"+n.asyncVariant),n.asyncBody&&n.asyncBody.length>0&&t.push("async-body:"+n.asyncBody.map(e=>z(e)).join(" "))}return`[${t.join(" ")}]`}(e);if(e.annotations&&e.annotations.length>0){return e.annotations.map(e=>void 0!==e.value?`@${e.name}(${e.value})`:"@"+e.name).join(" ")+" "+t}return t}function q(e){const t=[];e.lseVersion&&"1.0"!==e.lseVersion&&t.push("#!lse "+e.lseVersion);for(const n of e.nodes)t.push(z(n));return t.join("\n")}function K(e){switch(e.type){case"literal":return"string"==typeof e.value?"string"===e.dataType||/\s/.test(e.value)?JSON.stringify(e.value):e.value:e.value+"";case"selector":return e.value&&function(e){if(e.includes(" "))return!0;const t=e[0];return!("#"===t||"."===t||"@"===t||"*"===t)}(e.value)?`<${e.value}/>`:e.value;case"reference":return e.value;case"property-path":return`${K(e.object)}'s ${e.property}`;case"expression":return e.raw;case"flag":return e.name}}function G(e){const t=F(e.roles);let n;switch(e.kind){case"command":{const r=e;n={kind:"command",action:e.action,roles:t},r.body&&r.body.length>0&&(n.body=r.body.map(G)),r.catchBranch&&r.catchBranch.length>0&&(n.catchBranch=r.catchBranch.map(G)),r.finallyBranch&&r.finallyBranch.length>0&&(n.finallyBranch=r.finallyBranch.map(G)),r.asyncVariant&&(n.asyncVariant=r.asyncVariant),r.asyncBody&&r.asyncBody.length>0&&(n.asyncBody=r.asyncBody.map(G)),r.arms&&r.arms.length>0&&(n.arms=r.arms.map(e=>({pattern:U(e.pattern),body:e.body.map(G)}))),r.defaultArm&&r.defaultArm.length>0&&(n.defaultArm=r.defaultArm.map(G));break}case"event-handler":{const r=e;if(function(e){if(!e.body||1!==e.body.length)return!1;const t=e.body[0];if("command"!==t.kind)return!1;const n=t;if(n.body&&n.body.length>0)return!1;if(n.catchBranch&&n.catchBranch.length>0)return!1;if(n.finallyBranch&&n.finallyBranch.length>0)return!1;if(n.asyncVariant)return!1;if(n.asyncBody&&n.asyncBody.length>0)return!1;if(n.arms&&n.arms.length>0)return!1;if(n.defaultArm&&n.defaultArm.length>0)return!1;const r=e.roles.get("event");return!(!r||"literal"!==r.type)&&("string"==typeof r.value&&(!n.roles.has("event")&&((!e.additionalEvents||0>=e.additionalEvents.length)&&((!e.parameterNames||0>=e.parameterNames.length)&&((!e.annotations||0>=e.annotations.length)&&((!e.diagnostics||0>=e.diagnostics.length)&&((!n.annotations||0>=n.annotations.length)&&(!n.diagnostics||0>=n.diagnostics.length))))))))}(r)){const e=r.body[0],t={event:r.roles.get("event").value},o=function(e){if(!e)return;const t={};e.once&&(t.once=!0);"number"==typeof e.debounce&&(t.debounce=e.debounce);"number"==typeof e.throttle&&(t.throttle=e.throttle);e.queue&&(t.queue=e.queue);return Object.keys(t).length>0?t:void 0}(r.eventModifiers);o&&(t.modifiers=o),n={action:e.action,roles:F(e.roles),trigger:t};break}n={kind:"event-handler",action:e.action,roles:t,body:r.body.map(G)};break}case"compound":{const t=e;n={kind:"compound",action:"compound",statements:t.statements.map(G),chainType:t.chainType};break}case"conditional":{const r=e;n={kind:"command",action:e.action,roles:t},n.thenBranch=r.thenBranch.map(G),r.elseBranch&&r.elseBranch.length>0&&(n.elseBranch=r.elseBranch.map(G));break}case"loop":{const r=e;n={kind:"command",action:e.action,roles:t},n.loopVariant=r.loopVariant,n.loopBody=r.body.map(G),r.loopVariable&&(n.loopVariable=r.loopVariable),r.indexVariable&&(n.indexVariable=r.indexVariable);break}}return e.annotations&&e.annotations.length>0&&(n.annotations=e.annotations.map(e=>void 0!==e.value?{name:e.name,value:e.value}:{name:e.name})),e.diagnostics&&e.diagnostics.length>0&&(n.diagnostics=e.diagnostics.map(e=>{const t={level:e.severity,message:e.message};return e.role&&(t.role=e.role),e.code&&(t.code=e.code),e.source&&(t.source=e.source),e.suggestions&&e.suggestions.length>0&&(t.suggestions=[...e.suggestions]),t})),n}function F(e){const t={};for(const[n,r]of e)t[n]=U(r);return t}function U(e){switch(e.type){case"selector":{const t="selectorKind"in e?e.selectorKind:void 0,n={type:"selector",value:e.value};return t&&new Set(["id","class","attribute","element","complex"]).has(t)&&(n.selectorKind=t),n}case"literal":return e.dataType?{type:"literal",value:e.value,dataType:e.dataType}:{type:"literal",value:e.value};case"reference":return{type:"reference",value:e.value};case"expression":return{type:"expression",raw:e.raw};case"property-path":return{type:"expression",raw:h(e)};case"flag":return{type:"flag",name:e.name,enabled:e.enabled}}}function J(t){const n=new Map(Object.entries(t.roles??{}).map(([e,t])=>[e,Z(t)])),r=t.annotations?.map(e=>void 0!==e.value?{name:e.name,value:e.value}:{name:e.name}),o=t.diagnostics?.map(e=>({severity:e.level,message:e.message,...e.role?{role:e.role}:{},...e.code?{code:e.code}:{},...e.source?{source:e.source}:{},...e.suggestions&&e.suggestions.length>0?{suggestions:e.suggestions}:{}}));if(t.trigger){n.set("event",e(t.trigger.event,"string"));const s=new Map(n);s.delete("event");return H(a("on",n,[i(t.action,s)],{sourceLanguage:"json"},t.trigger.modifiers??{}),r,o)}const s=t.kind??"command";if("event-handler"===s){const e=(t.body??[]).map(J);return H(a(t.action,n,e),r,o)}if("compound"===s){return H(l((t.statements??[]).map(J),t.chainType??"sequential"),r,o)}if(t.thenBranch&&t.thenBranch.length>0){const e=t.thenBranch.map(J),s=t.elseBranch?t.elseBranch.map(J):void 0;return H(c(t.action,n,e,s),r,o)}if(t.loopVariant){const e=(t.loopBody??[]).map(J);return H(u(t.action,n,t.loopVariant,e,t.loopVariable,t.indexVariable),r,o)}if(t.catchBranch||t.finallyBranch){return H(d((t.body??[]).map(J),t.catchBranch?t.catchBranch.map(J):void 0,t.finallyBranch?t.finallyBranch.map(J):void 0),r,o)}if(t.asyncVariant){const e=(t.asyncBody??[]).map(J);return H(f(t.asyncVariant,e),r,o)}if(t.arms&&t.arms.length>0){return H(p(n,t.arms.map(e=>({pattern:Z(e.pattern),body:e.body.map(J)})),t.defaultArm?t.defaultArm.map(J):void 0),r,o)}return H(t.body&&t.body.length>0&&"command"===s?d(t.body.map(J)):i(t.action,n),r,o)}function H(e,t,n){return t&&0!==t.length||n&&0!==n.length?{...e,...t&&t.length>0?{annotations:t}:{},...n&&n.length>0?{diagnostics:n}:{}}:e}function Z(r){switch(r.type){case"selector":return t((r.value??"")+"",r.selectorKind);case"literal":return e(void 0!==r.value?r.value:"",r.dataType);case"reference":return n((r.value??"")+"");case"expression":return o(r.raw??(r.value??"")+"");case"flag":return s(r.name??(r.value??"")+"",r.enabled??("boolean"!=typeof r.value||r.value));case"property-path":return o((r.value??r.raw??"")+"")}}function Y(e){const t={lseVersion:e.lseVersion,nodes:e.nodes.map(G)};return e.features&&e.features.length>0&&(t.features=[...e.features]),t}function Q(e){return{lseVersion:e.lseVersion,...e.features&&e.features.length>0?{features:e.features}:{},nodes:e.nodes.map(J)}}function X(e){return"object"==typeof e&&null!==e&&"lseVersion"in e&&"nodes"in e&&Array.isArray(e.nodes)}var ee=new Set(["command","event-handler","compound"]),te=new Set(["selector","literal","reference","expression","property-path","flag"]),ne=new Set(["then","and","async","sequential","pipe"]),re=new Set(["all","race"]),oe=new Set(["error","warning","info"]);function se(e){const t=[];if("object"!=typeof e||null===e)return[{severity:"error",code:"INVALID_ROOT",message:"Root must be a JSON object"}];const n=e,r="kind"in n?n.kind+"":"command";if("kind"in n&&!ee.has(r)&&t.push({severity:"error",code:"INVALID_KIND",message:`Invalid kind "${n.kind}". Must be one of: command, event-handler, compound`}),"action"in n?"string"==typeof n.action&&0!==n.action.length||t.push({severity:"error",code:"INVALID_ACTION",message:"action must be a non-empty string"}):t.push({severity:"error",code:"MISSING_ACTION",message:"Missing required field: action"}),"roles"in n||"compound"===r){if("roles"in n&&("object"!=typeof n.roles||null===n.roles||Array.isArray(n.roles)))t.push({severity:"error",code:"INVALID_ROLES",message:"roles must be a plain object"});else if("roles"in n&&n.roles)for(const[e,r]of Object.entries(n.roles)){if("object"!=typeof r||null===r){t.push({severity:"error",code:"INVALID_ROLE_VALUE",message:`Role "${e}" value must be an object`});continue}const n=r;"type"in n&&te.has(n.type+"")||t.push({severity:"error",code:"INVALID_VALUE_TYPE",message:`Role "${e}" has invalid type "${n.type}"`}),"flag"===n.type&&("string"==typeof n.name||"value"in n||t.push({severity:"error",code:"MISSING_FLAG_NAME",message:`Flag role "${e}" missing required field: name (or value)`}),"boolean"==typeof n.enabled||"value"in n||t.push({severity:"error",code:"MISSING_FLAG_ENABLED",message:`Flag role "${e}" missing required field: enabled (or value)`})),"expression"!==n.type||"string"==typeof n.raw||"value"in n||t.push({severity:"error",code:"MISSING_EXPRESSION_RAW",message:`Expression role "${e}" missing required field: raw (or value)`})}}else t.push({severity:"error",code:"MISSING_ROLES",message:"Missing required field: roles"});if("trigger"in n&&n.trigger){const e=n.trigger;"object"!=typeof e||null===e?t.push({severity:"error",code:"INVALID_TRIGGER",message:"trigger must be an object"}):e.event&&"string"==typeof e.event||t.push({severity:"error",code:"INVALID_TRIGGER",message:"trigger.event is required and must be a non-empty string"})}if("event-handler"!==r||"trigger"in n||"body"in n&&Array.isArray(n.body)||t.push({severity:"error",code:"MISSING_BODY",message:"event-handler node requires a body array"}),"compound"===r&&("statements"in n&&Array.isArray(n.statements)||t.push({severity:"error",code:"MISSING_STATEMENTS",message:"compound node requires a statements array"}),"chainType"in n&&!ne.has(n.chainType+"")&&t.push({severity:"error",code:"INVALID_CHAIN_TYPE",message:`Invalid chainType "${n.chainType}"`})),"diagnostics"in n&&!Array.isArray(n.diagnostics)&&t.push({severity:"error",code:"INVALID_DIAGNOSTICS",message:"diagnostics must be an array"}),"annotations"in n)if(Array.isArray(n.annotations))for(let e=0;n.annotations.length>e;e++){const r=n.annotations[e];r&&"object"==typeof r?"string"==typeof r.name&&0!==r.name.length||t.push({severity:"error",code:"MISSING_ANNOTATION_NAME",message:`annotations[${e}] missing required field: name`}):t.push({severity:"error",code:"INVALID_ANNOTATION_ENTRY",message:`annotations[${e}] must be an object`})}else t.push({severity:"error",code:"INVALID_ANNOTATIONS",message:"annotations must be an array"});if("asyncVariant"in n&&!re.has(n.asyncVariant+"")&&t.push({severity:"error",code:"INVALID_ASYNC_VARIANT",message:`Invalid asyncVariant "${n.asyncVariant}". Must be "all" or "race"`}),"arms"in n)if(Array.isArray(n.arms))for(let e=0;n.arms.length>e;e++){const r=n.arms[e];r&&"object"==typeof r?(r.pattern&&"object"==typeof r.pattern||t.push({severity:"error",code:"MISSING_ARM_PATTERN",message:`arms[${e}] missing required field: pattern`}),Array.isArray(r.body)||t.push({severity:"error",code:"MISSING_ARM_BODY",message:`arms[${e}] missing required field: body (array)`})):t.push({severity:"error",code:"INVALID_ARM_ENTRY",message:`arms[${e}] must be an object`})}else t.push({severity:"error",code:"INVALID_ARMS",message:"arms must be an array"});if("diagnostics"in n&&Array.isArray(n.diagnostics))for(let e=0;n.diagnostics.length>e;e++){const r=n.diagnostics[e];r&&"object"==typeof r?(oe.has(r.level+"")||t.push({severity:"error",code:"INVALID_DIAGNOSTIC_LEVEL",message:`diagnostics[${e}].level must be "error", "warning", or "info"`}),"string"!=typeof r.message&&t.push({severity:"error",code:"MISSING_DIAGNOSTIC_MESSAGE",message:`diagnostics[${e}] missing required field: message`})):t.push({severity:"error",code:"INVALID_DIAGNOSTIC_ENTRY",message:`diagnostics[${e}] must be an object`})}return t}var ie=class{constructor(e){this.namespace=e,this.enabled=this.checkEnabled()}checkEnabled(){if("undefined"!=typeof process&&process.env){const e=process.env.DEBUG||"";return"*"===e||e.includes("framework:*")||e.includes("framework:"+this.namespace)}return!1}log(e,t,...n){if(!this.enabled)return;const r=`[framework:${this.namespace}]`,o=(new Date).toISOString();switch(e){case"debug":case"info":break;case"warn":console.warn(`${o} ${r} WARN:`,t,...n);break;case"error":console.error(`${o} ${r} ERROR:`,t,...n)}}debug(e,...t){this.log("debug",e,...t)}info(e,...t){this.log("info",e,...t)}warn(e,...t){this.log("warn",e,...t)}error(e,...t){this.log("error",e,...t)}isEnabled(){return this.enabled}enable(){this.enabled=!0}disable(){this.enabled=!1}};function ae(e,t){return!t||0===t.length||(!!t.includes(e)||(!!t.includes("expression")||"property-path"===e&&t.some(e=>["selector","reference","expression"].includes(e))))}function ce(e,t){return!t||0===t.length||ae(e.type,t)}function le(e){return e.startsWith(".")||e.startsWith("#")||e.startsWith("<")}function ue(e){return e.startsWith(".")}function de(e){return e.startsWith("#")}function fe(e){return e.startsWith("*")}function pe(e){if(e.match(/^(\d+(?:\.\d+)?)(ms|s|m|h)?$/))return!0;const t=parseFloat(e);return!isNaN(t)&&isFinite(t)}function he(e){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e)}function me(e){return e.startsWith(":")}function ge(e){return new Set(["me","you","it","result","event","target","body"]).has(e.toLowerCase())}function ye(e,t){return e?.possessive?.keywords?.[t]}function ve(e,t){return void 0!==e?.possessive?.keywords?.[t]}function be(e){return e?.possessive?.keywords??{}}var ke=class o{constructor(){this.logger=new ie("pattern-matcher"),this.stemMatchCount=0,this.totalKeywordMatches=0}safeToLowerCase(e){return"string"==typeof e?e.toLowerCase():null==e?"":(e+"").toLowerCase()}matchPattern(e,t,n){const r=e.mark(),o=new Map;if(this.logger.debug("========================================"),this.logger.debug("matchPattern ENTRY"),this.logger.debug("Pattern ID:",t.id),this.logger.debug("Pattern command:",t.command),this.logger.debug("Pattern language:",t.language),this.logger.debug("Pattern template:",JSON.stringify(t.template,null,2)),this.logger.isEnabled()){const t=[];for(let n=0;10>n;n++){const r=e.peek(n);if(!r)break;t.push({type:r.type,value:r.value,kind:r.kind})}this.logger.debug("Input tokens (first 10):",t),this.logger.debug("Profile code:",n?.code)}this.currentProfile=n,this.stemMatchCount=0,this.totalKeywordMatches=0,this.logger.debug("--- Calling matchTokenSequence ---"),this.logger.debug("Pattern tokens to match:",JSON.stringify(t.template.tokens,null,2));const s=this.matchTokenSequence(e,t.template.tokens,o);if(this.logger.debug("matchTokenSequence returned:",s),this.logger.debug("Captured roles:",Array.from(o.entries()).map(([e,t])=>[e,JSON.stringify(t)])),!s)return this.logger.debug(">>> MATCH FAILED - resetting token position"),e.reset(r),null;const i=this.calculateConfidence(t,o);return this.applyExtractionRules(t,o),{pattern:t,captured:o,consumedTokens:e.position()-r.position,confidence:i}}matchBest(e,t,n){const r=[];for(const o of t){const t=e.mark(),s=this.matchPattern(e,o,n);s&&r.push(s),e.reset(t)}if(0===r.length)return null;r.sort((e,t)=>{const n=t.pattern.priority-e.pattern.priority;if(0!==n)return n;const r=t.confidence-e.confidence;return Math.abs(r)>.001?r:t.consumedTokens-e.consumedTokens});const o=r[0];return this.matchPattern(e,o.pattern),o}matchTokenSequence(e,t,n,r){const o=t[0],s="literal"===o?.type&&("and"===o.value||"then"===o.value||o.alternatives?.includes("and")||o.alternatives?.includes("then"));if("ar"===this.currentProfile?.code&&!s)for(;"conjunction"===e.peek()?.kind;)e.advance();let i=null,a=null;for(let o=0;t.length>o;o++){const s=t[o];this.logger.debug(" >> Matching pattern token:",JSON.stringify(s,null,2));const c=e.peek();if(this.logger.debug(" >> Current input token:",c?JSON.stringify({type:c.type,value:c.value,kind:c.kind}):"EOF"),"role"===s.type&&s.greedy){const c=this.collectStopMarkers(t,o+1);if(r)for(const e of r)c.add(e);const l=[];for(;!e.isAtEnd();){const t=e.peek();if(!t)break;if(this.isStopMarker(t,c))break;l.push(t.value),e.advance()}if(l.length>0){n.set(s.role,{type:"expression",raw:l.join(" ")}),i=null,a=null;continue}if(s.optional)continue;return!1}if("group"===s.type){const c=this.collectStopMarkers(t,o+1);if(r)for(const e of r)c.add(e);if(this.matchGroupToken(e,s,n,c)){i=null,a=null;continue}if(this.isOptional(s))continue;return!1}const l="role"===s.type&&!0===s.optional,u=l?e.mark():null;if("role"===s.type&&!l){const r=t.length>o+1?t[o+1]:null;if("literal"===r?.type){const t=e.peek();if(t&&"none"!==this.getMatchType(t,r.value)){if(this.logger.debug(" >> MARKER-STEAL GUARD: current token matches next literal, skipping role"),this.logger.debug(" >> Token match FAILED"),this.isOptional(s))continue;if(i&&a){this.logger.debug(" >> BACKTRACKING: undoing optional role",a),e.reset(i),n.delete(a),i=null,a=null;const t=this.matchPatternToken(e,s,n);if(this.logger.debug(" >> Backtrack retry result:",t),t)continue}return!1}}}const d=this.matchPatternToken(e,s,n);if(this.logger.debug(" >> Match result:",d),d)l?(i=u,a=s.role):(i=null,a=null);else if(this.logger.debug(" >> Token match FAILED"),!this.isOptional(s)){if(i&&a){this.logger.debug(" >> BACKTRACKING: undoing optional role",a),e.reset(i),n.delete(a),i=null,a=null;const t=this.matchPatternToken(e,s,n);if(this.logger.debug(" >> Backtrack retry result:",t),t)continue}return!1}}return!0}matchPatternToken(e,t,n){switch(t.type){case"literal":return this.matchLiteralToken(e,t);case"role":return this.matchRoleToken(e,t,n);case"group":return this.matchGroupToken(e,t,n);default:return!1}}matchLiteralToken(e,t){const n=e.peek();if(this.logger.debug(" >>> matchLiteralToken: expecting",t.value),this.logger.debug(" >>> matchLiteralToken: got token",n?JSON.stringify({type:n.type,value:n.value,kind:n.kind}):"null"),!n)return this.logger.debug(" >>> matchLiteralToken: FAIL - no token"),!1;const r=this.getMatchType(n,t.value);if(this.logger.debug(" >>> matchType for",n.value,"vs",t.value,":",r),"none"!==r)return this.totalKeywordMatches++,"stem"===r&&this.stemMatchCount++,e.advance(),!0;if(t.alternatives)for(const r of t.alternatives){const t=this.getMatchType(n,r);if("none"!==t)return this.totalKeywordMatches++,"stem"===t&&this.stemMatchCount++,e.advance(),!0}return!1}matchRoleToken(e,t,n){this.logger.debug(" >>> matchRoleToken ENTRY: capturing role",t.role),this.logger.debug(" >>> matchRoleToken: expected types",t.expectedTypes),this.logger.debug(" >>> matchRoleToken: optional?",t.optional),this.skipNoiseWords(e);const r=e.peek();if(this.logger.debug(" >>> After skipNoiseWords, current token:",r?JSON.stringify({value:r.value,kind:r.kind}):"null"),!r)return t.optional||!1;const o=this.tryMatchPossessiveExpression(e);if(o)return t.expectedTypes&&t.expectedTypes.length>0&&!ae(o.type,t.expectedTypes)?t.optional||!1:(n.set(t.role,o),!0);const s=this.tryMatchMethodCallExpression(e);if(s)return t.expectedTypes&&t.expectedTypes.length>0&&!ae(s.type,t.expectedTypes)?t.optional||!1:(n.set(t.role,s),!0);const i=this.tryMatchPossessiveSelectorExpression(e);if(i)return t.expectedTypes&&t.expectedTypes.length>0&&!ae(i.type,t.expectedTypes)?t.optional||!1:(n.set(t.role,i),!0);const a=this.tryMatchPropertyAccessExpression(e);if(a)return t.expectedTypes&&t.expectedTypes.length>0&&!ae(a.type,t.expectedTypes)?t.optional||!1:(n.set(t.role,a),!0);const c=this.tryMatchSelectorPropertyExpression(e);if(c)return t.expectedTypes&&t.expectedTypes.length>0&&!ae(c.type,t.expectedTypes)?t.optional||!1:(n.set(t.role,c),!0);this.logger.debug(" >>> Trying tokenToSemanticValue for token:",r?JSON.stringify({value:r.value,kind:r.kind}):"null");const l=this.tokenToSemanticValue(r);return this.logger.debug(" >>> tokenToSemanticValue returned:",l?JSON.stringify(l):"null"),l?(this.logger.debug(" >>> Validating type:",l.type,"against expected:",t.expectedTypes),t.expectedTypes&&t.expectedTypes.length>0&&!ae(l.type,t.expectedTypes)?(this.logger.debug(" >>> TYPE MISMATCH - returning",t.optional||!1),t.optional||!1):(this.logger.debug(" >>> Type validation PASSED"),n.set(t.role,l),e.advance(),!0)):t.optional||!1}tryMatchPossessiveExpression(e){const t=e.peek();if(!t)return null;if(!this.currentProfile)return null;const o=this.safeToLowerCase(t.normalized||t.value),s=ye(this.currentProfile,o);if(!s)return null;const i=e.mark();e.advance();const a=e.peek();if(!a)return e.reset(i),null;if("identifier"===a.kind||"keyword"===a.kind&&!this.isStructuralKeyword(a.value)||"selector"===a.kind&&a.value.startsWith("*")||"selector"===a.kind&&a.value.startsWith("@")||"selector"===a.kind&&a.value.startsWith(".")&&/^\.[a-zA-Z_]\w*/.test(a.value)){e.advance();let t=a.value;"selector"===a.kind&&t.startsWith(".")&&/^\.[a-zA-Z_]\w*/.test(t)&&(t=t.substring(1));let o=t;for(;"selector"===e.peek()?.kind&&e.peek().value.startsWith(".")&&/^\.[a-zA-Z_]\w*/.test(e.peek().value);)o+=e.peek().value,e.advance();const i=e.peek();return"literal"===i?.kind&&i.value.startsWith("(")&&(o+=i.value,e.advance()),r(n(s),o)}return e.reset(i),null}isStructuralKeyword(e){return new Set(["into","in","to","from","at","by","with","without","before","after","of","as","on","then","end","else","if","repeat","while","for","toggle","add","remove","put","set","show","hide","increment","decrement","send","trigger","call"]).has(e.toLowerCase())}tryMatchMethodCallExpression(e){const t=e.peek();if(!t||"selector"!==t.kind)return null;const n=e.mark();e.advance();const r=e.peek();if(!r||"operator"!==r.kind||"."!==r.value)return e.reset(n),null;e.advance();const s=e.peek();if(!s||"identifier"!==s.kind)return e.reset(n),null;e.advance();const i=e.peek();if(!i||"punctuation"!==i.kind||"("!==i.value)return e.reset(n),null;e.advance();const a=[];for(;!e.isAtEnd()&&o.MAX_METHOD_ARGS>a.length;){const t=e.peek();if(!t)break;if("punctuation"===t.kind&&")"===t.value){e.advance();break}"punctuation"!==t.kind||","!==t.value?(a.push(t.value),e.advance()):e.advance()}return{type:"expression",raw:`${t.value}.${s.value}(${a.join(", ")})`}}tryMatchPropertyAccessExpression(e){const t=e.peek();if(!t)return null;if("identifier"!==t.kind&&"keyword"!==t.kind)return null;const n=e.mark();e.advance();const r=e.peek();if(!r||"operator"!==r.kind||"."!==r.value)return e.reset(n),null;e.advance();const s=e.peek();if(!s||"identifier"!==s.kind)return e.reset(n),null;e.advance();let i=`${t.value}.${s.value}`,a=1;for(;!e.isAtEnd()&&o.MAX_PROPERTY_DEPTH>a;){const t=e.peek();if(!t||"operator"!==t.kind||"."!==t.value)break;e.advance();const n=e.peek();if(!n||"identifier"!==n.kind)break;e.advance(),i+="."+n.value,a++}const c=e.peek();if(c&&"punctuation"===c.kind&&"("===c.value){e.advance();const t=[];let n=0;for(;!e.isAtEnd()&&o.MAX_METHOD_ARGS>t.length;){const r=e.peek();if(!r)break;if("punctuation"===r.kind&&")"===r.value){if(0===n){e.advance();break}n--}"punctuation"===r.kind&&"("===r.value&&n++,"punctuation"!==r.kind||","!==r.value?(t.push(r.value),e.advance()):e.advance()}return{type:"expression",raw:`${i}(${t.join(", ")})`}}return{type:"expression",raw:i}}tryMatchPossessiveSelectorExpression(e){const n=e.peek();if(!n||"selector"!==n.kind)return null;const o=e.mark();e.advance();const s=e.peek();if(!s||"punctuation"!==s.kind||"'s"!==s.value)return e.reset(o),null;e.advance();const i=e.peek();return i?"selector"!==i.kind&&"identifier"!==i.kind?(e.reset(o),null):(e.advance(),r(t(n.value),i.value)):(e.reset(o),null)}tryMatchSelectorPropertyExpression(e){const n=e.peek();if(!n||"selector"!==n.kind)return null;if("string"!=typeof n.value||!n.value.startsWith("#"))return null;const o=e.mark();e.advance();const s=e.peek();if(!s||"selector"!==s.kind)return e.reset(o),null;if(!s.value.startsWith("."))return e.reset(o),null;e.peek(1);e.advance();const i=s.value.slice(1);return r(t(n.value),i)}matchGroupToken(e,t,n,r){const s=e.mark(),i=new Set(n.keys());if(this.matchTokenSequence(e,t.tokens,n,r))return!0;e.reset(s);for(const e of n.keys())i.has(e)||n.delete(e);if(!t.optional)return!1;const a=this.getGroupLeadingMarker(t);if(a)for(let c=1;o.MAX_MARKER_SCAN>=c;c++){const o=e.peek(c);if(!o)break;if((o.normalized||o.value).toLowerCase()===a){this.logger.debug(" >> MARKER SCAN: found",a,"at offset",c,"- skipping intervening tokens");for(let t=0;c>t;t++)e.advance();if(this.matchTokenSequence(e,t.tokens,n,r))return!0;e.reset(s);for(const e of n.keys())i.has(e)||n.delete(e);break}}return!0}getGroupLeadingMarker(e){const t=e.tokens[0];return"literal"===t?.type?t.value.toLowerCase():null}getMatchType(e,t){return e.value===t?"exact":e.normalized===t?"normalized":e.stem!==t||void 0===e.stemConfidence||.7>e.stemConfidence?"keyword"===e.kind&&this.safeToLowerCase(e.value)===t.toLowerCase()?"case-insensitive":"none":"stem"}collectStopMarkers(e,t){const n=new Set;for(let r=t;e.length>r;r++){const t=e[r];if("literal"===t.type){if(n.add(t.value.toLowerCase()),t.alternatives)for(const e of t.alternatives)n.add(e.toLowerCase());break}if("group"===t.type){for(const e of t.tokens)if("literal"===e.type){if(n.add(e.value.toLowerCase()),e.alternatives)for(const t of e.alternatives)n.add(t.toLowerCase());break}if(!t.optional)break}}return n}isStopMarker(e,t){return 0!==t.size&&(!!t.has(e.value.toLowerCase())||!(!e.normalized||!t.has(e.normalized.toLowerCase())))}tokenToSemanticValue(r){switch(r.kind){case"selector":return t(r.value);case"literal":return this.parseLiteralValue(r.value);case"keyword":return this.safeToLowerCase(r.normalized||r.value),e(r.normalized||r.value);case"identifier":return"string"==typeof r.value&&r.value.startsWith(":")?n(r.value):(this.safeToLowerCase(r.value),{type:"expression",raw:r.value});case"url":return e(r.value,"string");default:return null}}parseLiteralValue(t){if(t.startsWith('"')||t.startsWith("'")||t.startsWith("`")||t.startsWith("\u300c")){return e(t.slice(1,-1),"string")}if("true"===t)return e(!0,"boolean");if("false"===t)return e(!1,"boolean");const n=t.match(/^(\d+(?:\.\d+)?)(ms|s|m|h)?$/);if(n){const r=parseFloat(n[1]);return n[2]?e(t,"duration"):e(r,"number")}const r=parseFloat(t);return isNaN(r)?e(t,"string"):e(r,"number")}applyExtractionRules(e,t){for(const[n,r]of Object.entries(e.extraction))t.has(n)||(void 0!==r.value?t.set(n,{type:"literal",value:r.value}):r.default&&t.set(n,r.default))}isOptional(e){return"literal"!==e.type&&!0===e.optional}calculateConfidence(e,t){let n=0,r=0;const o=t=>void 0!==e.extraction?.[t]?.default;for(const s of e.template.tokens)if("role"===s.type)r+=1,t.has(s.role)&&(n+=1);else if("group"===s.type)for(const e of s.tokens)if("role"===e.type){const s=o(e.role),i=.8;r+=i,t.has(e.role)?n+=i:s&&(n+=.6*i)}let s=r>0?n/r:1;if(this.stemMatchCount>0&&this.totalKeywordMatches>0){s=Math.max(.5,s-this.stemMatchCount/this.totalKeywordMatches*.15)}const i=this.calculateVSOConfidenceBoost(e);s=Math.min(1,s+i);const a=this.arabicPrepositionDisambiguation(e,t);return s=Math.max(0,Math.min(1,s+a)),s}calculateVSOConfidenceBoost(e){if("ar"!==e.language)return 0;const t=e.template.tokens[0];if(!t||"literal"!==t.type)return 0;const n=new Set(["\u0628\u062f\u0644","\u063a\u064a\u0631","\u0623\u0636\u0641","\u0623\u0632\u0644","\u0636\u0639","\u0627\u062c\u0639\u0644","\u0639\u064a\u0646","\u0632\u062f","\u0627\u0646\u0642\u0635","\u0633\u062c\u0644","\u0623\u0638\u0647\u0631","\u0623\u062e\u0641","\u0634\u063a\u0644","\u0623\u0631\u0633\u0644","\u0631\u0643\u0632","\u0634\u0648\u0634","\u062a\u0648\u0642\u0641","\u0627\u0646\u0633\u062e","\u0627\u062d\u0630\u0641","\u0627\u0635\u0646\u0639","\u0627\u0646\u062a\u0638\u0631","\u0627\u0646\u062a\u0642\u0627\u0644","\u0623\u0648"]);if(n.has(t.value))return.15;if(t.alternatives)for(const e of t.alternatives)if(n.has(e))return.15;return 0}arabicPrepositionDisambiguation(e,t){if("ar"!==e.language)return 0;let n=0;const r={patient:["\u0639\u0644\u0649"],destination:["\u0625\u0644\u0649","\u0627\u0644\u0649"],source:["\u0645\u0646"],agent:["\u0645\u0646"],manner:["\u0628"],style:["\u0628"],goal:["\u0625\u0644\u0649","\u0627\u0644\u0649"],method:["\u0628"]};for(const[e,o]of t.entries()){const t=r[e];if(!t||0===t.length)continue;const s="metadata"in o?o.metadata:void 0;if(s&&"string"==typeof s.prepositionValue){t.includes(s.prepositionValue)?n+=.1:n-=.1}}return Math.max(-.1,Math.min(.1,n))}skipNoiseWords(e){const t=e.peek();if(!t)return;const n=this.safeToLowerCase(t.value);if(o.ENGLISH_NOISE_WORDS.has(n)){const t=e.mark();e.advance();const n=e.peek();if(n&&"selector"===n.kind)return;e.reset(t)}"class"===n&&e.advance()}extractEventModifiers(e){const t={};let n=!1;for(;!e.isAtEnd();){const r=e.peek();if(!r||"event-modifier"!==r.kind)break;const o=r.metadata;if(!o)break;switch(n=!0,o.modifierName){case"once":t.once=!0;break;case"debounce":"number"==typeof o.value&&(t.debounce=o.value);break;case"throttle":"number"==typeof o.value&&(t.throttle=o.value);break;case"queue":"first"!==o.value&&"last"!==o.value&&"all"!==o.value&&"none"!==o.value||(t.queue=o.value)}e.advance()}return n?t:void 0}};ke.MAX_MARKER_SCAN=3,ke.MAX_PROPERTY_DEPTH=10,ke.MAX_METHOD_ARGS=20,ke.ENGLISH_NOISE_WORDS=new Set(["the","a","an"]);var we=ke,xe=new we;function Se(e,t){return xe.matchPattern(e,t)}function Ee(e,t){return xe.matchBest(e,t)}var Te={basePriority:100,includeOptionalVariants:!0};function Le(e,t,n=Te){const r=`${e.action}-${t.code}-generated`,o=n.basePriority??100,s=t.keywords[e.action];if(!s)throw Error(`No keyword translation for '${e.action}' in ${t.code}`);const i=function(e,t,n,r){const o=[],s={type:"literal",value:n,...r?.length&&{alternatives:r}},i=$e(e.roles,t.wordOrder);if("SVO"===t.wordOrder){o.push(s);for(const e of i)Ae(o,e,t)}else if("SOV"===t.wordOrder){const e=[],n=[];for(const r of i)Ae("postVerb"===r.sovSlot?n:e,r,t);o.push(...e,s,...n)}else if("VSO"===t.wordOrder){o.push(s);for(const e of i)Ae(o,e,t)}else{o.push(s);for(const e of i)Ae(o,e,t)}return o}(e,t,s.primary,s.alternatives),a=function(e,t){const n={};for(const r of e.roles){const e=Me(r,t),o={...void 0!==r.default&&{default:r.default},...e&&{marker:e}};n[r.role]=o}return n}(e,t),c=function(e,t,n){const r="SOV"===t.wordOrder,o=[],s=[],i=$e(e.roles,t.wordOrder);for(const e of i){const n=Me(e,t),i=`{${e.role}}`,a=r&&"postVerb"===e.sovSlot?s:o;if(n){const r=t.roleMarkers?.[e.role];a.push("after"===r?.position?`${i} ${n}`:`${n} ${i}`)}else a.push(i)}return(r?[...o,n,...s]:[n,...o,...s]).join(" ")}(e,t,s.primary);return{id:r,language:t.code,command:e.action,priority:o,template:{format:c,tokens:i},extraction:a}}function Ae(e,t,n){const r=Me(t,n),o=!t.required,s={type:"role",role:t.role,optional:o,expectedTypes:t.expectedTypes,...t.greedy&&{greedy:!0}};if(r){const i=n.roleMarkers?.[t.role],a="SOV"===n.wordOrder?"after":"before",c=t.markerPosition??i?.position??a;o?e.push("before"===c?{type:"group",optional:!0,tokens:[{type:"literal",value:r},s]}:{type:"group",optional:!0,tokens:[s,{type:"literal",value:r}]}):"before"===c?(e.push({type:"literal",value:r}),e.push(s)):(e.push(s),e.push({type:"literal",value:r}))}else e.push(s)}function Me(e,t){return e.markerOverride?.[t.code]?e.markerOverride[t.code]:t.roleMarkers?.[e.role]?.primary}function $e(e,t){const n=[...e];return"SVO"===t?n.sort((e,t)=>(t.svoPosition??0)-(e.svoPosition??0)):"SOV"===t&&n.sort((e,t)=>(t.sovPosition??0)-(e.sovPosition??0)),n}function Ne(e,t,n=Te){const r=[];return r.push(Le(e,t,n)),r}function Oe(e,t,n){return e[t]?.[n]??t}function je(e,t,n){return e[t]?.[n]??t}function Ce(...e){return e.filter(Boolean).join(" ")}function Ie(e,t){const n={},r={};for(const e of t)for(const[t,r]of Object.entries(e.keywords))n[t]||(n[t]={}),n[t][e.code]=r.primary;for(const t of e)for(const e of t.roles)if(e.markerOverride){const t=e.role;r[t]||(r[t]={});for(const[n,o]of Object.entries(e.markerOverride))r[t][n]=o}for(const e of t)if(e.roleMarkers)for(const[t,n]of Object.entries(e.roleMarkers))r[t]||(r[t]={}),r[t][e.code]=n.primary;return{keywords:n,markers:r}}function Re(e){const t=new Set,n=new Set;for(const r of e)"SOV"===r.wordOrder&&t.add(r.code),"VSO"===r.wordOrder&&n.add(r.code);return{sovLanguages:t,vsoLanguages:n}}function _e(e,t){const n=Pe(e,t);return{render:(e,t)=>Ve(e,t,n)??e.action}}function We(e){const{schemas:t,profiles:n,overrides:r}=e;let o;return(e,s)=>{const i=r?.[e.action];return i?i(e,s):(o??(o=Pe(t,n)),Ve(e,s,o))}}function Pe(e,t){const{keywords:n,markers:r}=Ie(e,t),{sovLanguages:o}=Re(t),s={};for(const e of t)for(const[t,n]of Object.entries(e.roleMarkers??{}))n.position&&(s[t]??(s[t]={}),s[t][e.code]=n.position);const i=new Map;for(const t of e)i.set(t.action,t);return{keywords:n,markers:r,markerPositions:s,sovLanguages:o,schemaMap:i}}function Ve(e,t,n){const r=n.schemaMap.get(e.action);if(!r)return null;const o=Oe(n.keywords,e.action,t),s=n.sovLanguages.has(t),i=$e([...r.roles],s?"SOV":"SVO"),a=[],c=[];for(const r of i){let o=g(e,r.role);if(o||void 0===r.default||(o=h(r.default)+""),!o)continue;r.quoteMultiword&&/\s/.test(o)&&!/^(["']).*\1$/.test(o)&&(o=`"${o}"`);const i=r.renderOverride?.[t]??r.markerOverride?.[t]??r.renderOverride?.["*"]??n.markers[r.role]?.[t],l=s&&"postVerb"===r.sovSlot?c:a;i&&"before"===(r.markerPositionOverride?.[t]??r.markerPosition??n.markerPositions[r.role]?.[t]??(s?"after":"before"))?l.push(i,o):i?l.push(o,i):l.push(o)}return s?Ce(...a,o,...c):Ce(o,...a,...c)}function Be(e,t){const n=[],r=new Set;for(const o of t){const t=e.get(o);t&&(n.push(t),r.add(o))}for(const[t,o]of e)r.has(t)||n.push(o);return n}function De(e,t,n){const r=[];for(const o of e){const e=t.find(e=>e.role===o.role);e?"preposition"===n?(e.form&&r.push(e.form),r.push(o.translated||o.value)):"postposition"===n?(r.push(o.translated||o.value),e.form&&r.push(e.form)):r.push(o.translated||o.value):r.push(o.translated||o.value)}return r}function ze(e){if(0===e.length)return"";let t="";for(let n=0;e.length>n;n++){const r=e[n],o=e[n+1],s=r.endsWith("-"),i=r.startsWith("-");let a=r;if(s&&(a=r.slice(0,-1)),i&&(a=r.substring(1)),t+=a,o){const e=o.startsWith("-");s||e||(t+=" ")}}return t}var qe=class{constructor(e){this.dictionary=e.dictionary,this.profileProvider=e.profileProvider}transform(e,t,n){const r=this.profileProvider.getProfile(t),o=this.profileProvider.getProfile(n);if(!r)throw Error("No profile found for language: "+t);if(!o)throw Error("No profile found for language: "+n);const s=this.parseStatement(e,t,r);return ze(De(Be(this.translateRoles(s,t,n),o.canonicalOrder),o.markers,o.adpositionType))}parseStatement(e,t,n){const r=new Map,o=e.split(/\s+/);let s=0;for(;o.length>s;){const e=o[s],i=n.markers.find(t=>t.form===e);if(i)o.length>s+1?(r.set(i.role,o[s+1]),s+=2):s++;else{const n=this.dictionary.lookup(e,t);n?r.set("action",n):(e.startsWith("#")||e.startsWith("."),r.set("patient",e)),s++}}return r}translateRoles(e,t,n){const r=new Map;for(const[t,o]of e){const e=this.dictionary.translate(o,n);r.set(t,{role:t,value:o,translated:e??o})}return r}},Ke=class{constructor(e){this.translations=e}lookup(e,t){const n=this.translations[t];if(!n)return;const r=e.toLowerCase();for(const[e,t]of Object.entries(n))if(t.toLowerCase()===r)return e}translate(e,t){return this.translations[t]?.[e]}getAllTranslations(e,t){const n=this.lookup(e,t);if(!n)return{};const r={};for(const[e,t]of Object.entries(this.translations)){const o=t[n];o&&(r[e]=o)}return r}},Ge=class{lookup(e,t){return e}translate(e,t){return e}getAllTranslations(e,t){return{en:e}}},Fe=class{constructor(e){this.profiles=e}getProfile(e){return this.profiles[e]}getSupportedLanguages(){return Object.keys(this.profiles)}hasLanguage(e){return e in this.profiles}},Ue=class{getProfile(e){}getSupportedLanguages(){return[]}hasLanguage(e){return!1}},Je=class{constructor(){this.name="string-literal"}canExtract(e,t){const n=e[t];return("'"!==n||0>=t||!/[\p{L}\p{M}\p{N}_)\]]/u.test(e[t-1]))&&('"'===n||"'"===n||"`"===n||"\u201c"===n||"\u2018"===n)}extract(e,t){const n=e[t];if("\u201c"===n){let n=1;for(;e.length>t+n;){if("\u201d"===e[t+n])return n++,{value:e.substring(t,t+n),length:n};n++}return null}if("\u2018"===n){let n=1;for(;e.length>t+n;){if("\u2019"===e[t+n])return n++,{value:e.substring(t,t+n),length:n};n++}return null}let r=1,o=!1;for(;e.length>t+r;){const s=e[t+r];if(o)o=!1,r++;else if("\\"!==s){if(s===n)return r++,{value:e.substring(t,t+r),length:r};r++}else o=!0,r++}return null}},He=class{constructor(){this.name="number"}canExtract(e,t){return/\d/.test(e[t])}extract(e,t){let n=0,r=!1;for(;e.length>t+n;){const o=e[t+n];if(/\d/.test(o))n++;else{if("."!==o||r)break;r=!0,n++}}if(0===n)return null;const o=e.substring(t,t+n),s=t+n;if(e.length>s){const t=e.slice(s),r=[{pattern:"\u6beb\u79d2",suffix:"ms"},{pattern:"\u5206\u949f",suffix:"m"},{pattern:"\u5c0f\u65f6",suffix:"h"},{pattern:"\u30df\u30ea\u79d2",suffix:"ms"},{pattern:"\u6642\u9593",suffix:"h"}];for(const e of r)if(t.startsWith(e.pattern))return{value:o+e.suffix,length:n+e.pattern.length,metadata:{hasTimeUnit:!0}};if(t.startsWith("ms"))return{value:o+"ms",length:n+2,metadata:{hasTimeUnit:!0}};const i=[{pattern:"\u79d2",suffix:"s"},{pattern:"\u5206",suffix:"m"}];for(const e of i)if(t.startsWith(e.pattern))return{value:o+e.suffix,length:n+1,metadata:{hasTimeUnit:!0}};if(/^[smh](?![a-zA-Z])/.test(t))return{value:o+t[0],length:n+1,metadata:{hasTimeUnit:!0}}}return{value:o,length:n}}},Ze=class{constructor(){this.name="identifier"}canExtract(e,t){return/[a-zA-Z_]/.test(e[t])}extract(e,t){let n=0;for(;e.length>t+n;){if(!/[a-zA-Z0-9_]/.test(e[t+n]))break;n++}return n>0?{value:e.substring(t,t+n),length:n}:null}},Ye=class{constructor(){this.name="unicode-identifier"}canExtract(e,t){return e.charCodeAt(t)>=128&&/\p{L}/u.test(e[t])}extract(e,t){let n=0;for(;e.length>t+n;){if(!/[\p{L}\p{N}\p{M}]/u.test(e[t+n]))break;n++}return n>0?{value:e.substring(t,t+n),length:n}:null}},Qe=class{constructor(){this.name="latin-extended-identifier"}canExtract(e,t){return/\p{L}/u.test(e[t])}extract(e,t){let n=t;for(;e.length>n&&/[\p{L}\p{N}_-]/u.test(e[n]);)n++;return n===t?null:{value:e.slice(t,n),length:n-t}}},Xe=/[\p{L}\p{N}_-]/u,et=/[\p{sc=Han}\p{sc=Hiragana}\p{sc=Katakana}\p{sc=Hangul}]/u;function tt(e){return Xe.test(e)&&!et.test(e)}var nt=class{constructor(){this.name="css-selector"}canExtract(e,t){const n=e[t];if("#"!==n&&"."!==n)return!1;const r=e[t+1];return void 0!==r&&("_"===r||"-"===r||/\p{L}/u.test(r)&&!et.test(r))}extract(e,t){let n=t+1;for(;e.length>n&&tt(e[n]);)n++;return n===t+1?null:{value:e.slice(t,n),length:n-t}}},rt=class{constructor(){this.name="whitespace"}canExtract(e,t){return/\s/.test(e[t])}extract(e,t){let n=0;for(;e.length>t+n&&/\s/.test(e[t+n]);)n++;return n>0?{value:e.substring(t,t+n),length:n}:null}};function ot(e){return"setContext"in e&&"function"==typeof e.setContext}function st(e){const t={language:e.language,direction:e.direction,lookupKeyword:e.lookupKeyword.bind(e),isKeyword:e.isKeyword.bind(e),isKeywordStart:e.isKeywordStart.bind(e),...e.isKeywordStartAtBoundary?{isKeywordStartAtBoundary:e.isKeywordStartAtBoundary.bind(e)}:{}};return e.normalizer?{...t,normalizer:e.normalizer}:t}var it=new Set(["selector","literal","reference","expression","property-path","flag"]);function at(e){const t=[];if(!e.action||"string"!=typeof e.action)return t.push({severity:"error",code:"INVALID_ACTION",message:'Field "action" is required and must be a string.',suggestion:'Provide a command name like "toggle", "add", "set", etc.'}),t;if(e.roles&&"object"==typeof e.roles)for(const[n,r]of Object.entries(e.roles)){if(!r||"object"!=typeof r){t.push({severity:"error",code:"INVALID_ROLE_VALUE",message:`Role "${n}" must be an object with "type" and "value" fields.`,suggestion:'Use: { "type": "selector", "value": ".active" }'});continue}const e=r;it.has(e.type)||t.push({severity:"error",code:"INVALID_VALUE_TYPE",message:`Role "${n}" has invalid type "${e.type}".`,suggestion:"Valid types: selector, literal, reference, expression, property-path."}),null==e.value&&t.push({severity:"error",code:"MISSING_VALUE",message:`Role "${n}" is missing the "value" field.`})}return e.trigger&&(e.trigger.event&&"string"==typeof e.trigger.event||t.push({severity:"error",code:"INVALID_TRIGGER",message:'Trigger "event" is required and must be a string.',suggestion:'Use an event name like "click", "mouseover", "keydown".'})),t}function ct(t){const n=new Map;if(t.roles)for(const[e,r]of Object.entries(t.roles))n.set(e,ut(r));if(t.trigger){n.set("event",e(t.trigger.event,"string"));const r=new Map(n);r.delete("event");return a("on",n,[i(t.action,r)],{sourceLanguage:"json"},t.trigger.modifiers??{})}return i(t.action,n,{sourceLanguage:"json"})}function lt(e){if("compound"===e.kind){return e.statements.length>0?lt(e.statements[0]):{action:"compound",roles:{}}}if("event-handler"===e.kind){const t=e,n=t.body?.[0]?.action??e.action,r={};if(t.body?.[0])for(const[e,n]of t.body[0].roles)r[e]=dt(n);const o=e.roles.get("event"),s=o?"value"in o?o.value+"":"raw"in o?o.raw:"unknown":"unknown",i={action:"on"===n?t.body?.[0]?.action??"on":n,roles:r,trigger:{event:s}};return t.eventModifiers&&Object.keys(t.eventModifiers).length>0&&(i.trigger.modifiers=t.eventModifiers),i}const t={};for(const[n,r]of e.roles)t[n]=dt(r);return{action:e.action,roles:t}}function ut(r){switch(r.type){case"selector":return t(r.value+"",(i=r.value+"").startsWith("#")?"id":i.startsWith(".")?"class":i.startsWith("[")?"attribute":"complex");case"literal":return e(r.value,"number"==typeof r.value?"number":"boolean"==typeof r.value?"boolean":"string");case"reference":return n(r.value+"");case"expression":case"property-path":return o(r.value+"");case"flag":return s(r.value+"",!0);default:return e(r.value+"","string")}var i}function dt(e){switch(e.type){case"selector":return{type:"selector",value:e.value};case"literal":return{type:"literal",value:e.value};case"reference":return{type:"reference",value:e.value};case"expression":return{type:"expression",value:e.raw};case"property-path":return{type:"property-path",value:`${dt(e.object).value}.${e.property}`};case"flag":return{type:"flag",value:e.enabled}}}function ft(r){if(!r||"object"!=typeof r)return i("unknown",{});switch(r.type){case"event":return function(r){const o=(r.event??"click")+"",s=Array.isArray(r.body)?r.body:[],i=s.map(ft),c={event:e(o)};r.target&&"object"==typeof r.target&&(c.source=mt(r.target));const l=r.modifiers;let u;l&&(u=function(r){const o=!0===r.once||void 0,s="number"==typeof r.debounce?r.debounce:void 0,i="number"==typeof r.throttle?r.throttle:void 0,a="string"==typeof r.from?function(r){if(E.has(r))return n(r);const o=wt(r);return o?t(r,o):e(r)}(r.from):void 0;if(void 0===o&&void 0===s&&void 0===i&&void 0===a)return;return{...void 0!==o?{once:o}:{},...void 0!==s?{debounce:s}:{},...void 0!==i?{throttle:i}:{},...void 0!==a?{from:a}:{}}}(l),l.prevent&&(c.prevent=e(!0)),l.stop&&(c.stop=e(!0)),l.passive&&(c.passive=e(!0)),l.capture&&(c.capture=e(!0)));return a("on",c,i,void 0,u)}(r);case"command":return function(t){const n=(t.name??"unknown")+"",r=Array.isArray(t.args)?t.args:[],o=t.target&&"object"==typeof t.target?t.target:void 0,s=t.roles,a=t.modifiers;let c;if(s&&"object"==typeof s&&Object.keys(s).length>0){c={};for(const[e,t]of Object.entries(s))t&&"object"==typeof t&&"type"in t&&(c[e]=mt(t))}else c=function(t,n,r,o){const s={};switch(t){case"set":{n[0]&&(s.destination=mt(n[0]));const e=r?.to;e&&"object"==typeof e&&"type"in e?s.patient=mt(e):n[1]&&(s.patient=mt(n[1]));break}case"put":if(n[0]&&(s.patient=mt(n[0])),r)for(const t of["into","before","after"]){const n=r[t];if(n&&"object"==typeof n&&"type"in n){s.destination=mt(n),s.method=e(t);break}}!s.destination&&o&&(s.destination=mt(o));break;case"increment":case"decrement":{n[0]&&(s.destination=mt(n[0]));const e=r?.by;e&&"object"==typeof e&&"type"in e?s.quantity=mt(e):n[1]&&(s.quantity=mt(n[1]));break}case"fetch":{n[0]&&(s.source=mt(n[0]));const t=r?.as;t&&"object"==typeof t&&"type"in t?s.responseType=mt(t):"string"==typeof t&&(s.responseType=e(t));break}case"wait":case"settle":n[0]&&(s.duration=mt(n[0]));break;case"toggle":case"add":case"show":case"hide":case"send":case"trigger":default:n[0]&&(s.patient=mt(n[0])),o&&(s.destination=mt(o));break;case"remove":n[0]&&(s.patient=mt(n[0])),o&&(s.source=mt(o));break;case"log":n[0]&&(s.patient=mt(n[0]));break;case"scroll":{const e=kt(n,yt);e&&(s.destination=mt(e));break}case"push":case"replace":{const e=kt(n,vt);e&&(s.patient=mt(e));break}case"process":{const e=kt(n,bt);e&&(s.patient=mt(e));break}}return s}(n,r,a,o);return i(n,c)}(r);case"if":return function(e){const t=e.condition&&"object"==typeof e.condition?mt(e.condition):o("true"),n=Array.isArray(e.thenBranch)?e.thenBranch:[],r=n.map(ft);let s;const i=e.elseIfBranches;i&&i.length>0?s=[pt(i,e.elseBranch)]:Array.isArray(e.elseBranch)&&e.elseBranch.length>0&&(s=e.elseBranch.map(ft));return c("if",{condition:t},r,s)}(r);case"repeat":return function(t){const n=Array.isArray(t.body)?t.body:[],r=n.map(ft),o={};let s;null!=t.count?(s="times","number"==typeof t.count?o.quantity=e(t.count,"number"):"object"==typeof t.count&&(o.quantity=mt(t.count))):t.whileCondition&&"object"==typeof t.whileCondition?(s="while",o.condition=mt(t.whileCondition)):"string"==typeof t.untilEvent?(s="until",o.loopType=e("until-event"),o.event=e(t.untilEvent),t.untilEventTarget&&"object"==typeof t.untilEventTarget&&(o.source=mt(t.untilEventTarget))):s="forever";return u("repeat",o,s,r,void 0,ht(t))}(r);case"foreach":return function(e){const t=Array.isArray(e.body)?e.body:[],n=t.map(ft),r={};e.collection&&"object"==typeof e.collection&&(r.source=mt(e.collection));const o="string"==typeof e.itemName?e.itemName:void 0;return u("repeat",r,"for",n,o,ht(e))}(r);case"while":return function(e){const t=Array.isArray(e.body)?e.body:[],n=t.map(ft),r={};e.condition&&"object"==typeof e.condition&&(r.condition=mt(e.condition));return u("repeat",r,"while",n,void 0,ht(e))}(r);default:return i("get",{patient:mt(r)})}}function pt(e,t){const[n,...r]=e,o=mt(n.condition),s=n.body.map(ft);let i;return r.length>0?i=[pt(r,t)]:t&&t.length>0&&(i=t.map(ft)),c("if",{condition:o},s,i)}function ht(e){return"string"==typeof e.indexName?e.indexName:void 0}function mt(s){switch(s.type){case"literal":return function(t){const n=t.value;if(null==n)return e("null");return e(n,"number"==typeof n?"number":"boolean"==typeof n?"boolean":void 0)}(s);case"selector":return t((s.value??"")+"",wt((s.value??"")+""));case"identifier":return function(t){const r=(t.value??"")+"";if(E.has(r))return n(r);return e(r)}(s);case"variable":return function(e){const t=(e.name??"")+"";switch((e.scope??"local")+""){case"element":return o(":"+t);case"global":return o("$"+t);default:return o(t)}}(s);case"possessive":return r(s.object&&"object"==typeof s.object?mt(s.object):n("me"),(s.property??"")+"");case"binary":case"unary":case"member":case"call":case"positional":return o(gt(s));default:return"value"in s?e((s.value??"")+""):o(gt(s))}}function gt(e){if(!e||"object"!=typeof e)return"";switch(e.type){case"literal":{const t=e.value;return null==t?"null":"string"==typeof t?/\s/.test(t)?`"${t}"`:t:t+""}case"identifier":case"selector":return(e.value??"")+"";case"variable":{const t=(e.name??"")+"",n=(e.scope??"local")+"";return"element"===n?":"+t:"global"===n?"$"+t:t}case"binary":{const t=e.left&&"object"==typeof e.left?gt(e.left):"",n=e.right&&"object"==typeof e.right?gt(e.right):"";return`${t} ${e.operator??""} ${n}`}case"unary":{const t=e.operand&&"object"==typeof e.operand?gt(e.operand):"";return`${e.operator??""} ${t}`}case"member":{const t=e.object&&"object"==typeof e.object?gt(e.object):"";if(e.computed&&e.property&&"object"==typeof e.property)return`${t}[${gt(e.property)}]`;return`${t}.${"string"==typeof e.property?e.property:e.property&&"object"==typeof e.property?gt(e.property):""}`}case"possessive":return`${e.object&&"object"==typeof e.object?gt(e.object):""}'s ${e.property??""}`;case"call":return`${e.callee&&"object"==typeof e.callee?gt(e.callee):""}(${Array.isArray(e.args)?e.args.map(e=>gt(e)).join(", "):""})`;case"positional":{const t=e.target&&"object"==typeof e.target?gt(e.target):"";return t?`${e.position??""} ${t}`:(e.position??"")+""}default:return"value"in e?(e.value??"")+"":""}}var yt=new Set(["to","of","the","top","bottom","middle","center","nearest","left","right","smoothly","instantly"]),vt=new Set(["url"]),bt=new Set(["partials","in"]);function kt(e,t){for(const n of e){if("identifier"===n.type){const e="string"==typeof n.name?n.name:n.value;if("string"==typeof e&&t.has(e))continue}return n}}function wt(e){if(e)return e.startsWith("#")?"id":e.startsWith(".")?"class":e.startsWith("[")?"attribute":e.startsWith("<")||e.startsWith("*")?"element":/[>\+~ ]/.test(e)&&e.length>1?"complex":void 0}function xt(e){switch(e.kind){case"event-handler":return function(e){const t=e.roles.get("event"),n=t&&"value"in t?t.value+"":"click",r={};e.eventModifiers&&(e.eventModifiers.once&&(r.once=!0),e.eventModifiers.debounce&&(r.debounce=e.eventModifiers.debounce),e.eventModifiers.throttle&&(r.throttle=e.eventModifiers.throttle),e.eventModifiers.queue&&(r.queue=e.eventModifiers.queue));return{type:"event",event:n,modifiers:r,body:(e.body??[]).map(xt)}}(e);case"conditional":return function(e){const t="unless"===e.action?"unless":"if",n=e.roles.get("condition");return n?{type:"command",name:t,args:[Lt(n),St(e.thenBranch),...e.elseBranch&&e.elseBranch.length>0?[St(e.elseBranch)]:[]]}:{type:"command",name:t,args:[]}}(e);case"loop":return function(e){const t=e=>({type:"string",value:e}),n=t=>{const n=e.roles.get(t);return n?Lt(n):void 0},r=Tt(e.roles.get("loopType")),o="for"===e.action?"for":r&&Et.has(r)?r:e.loopVariant??"forever",s={loopType:t(o)},i=(e,t)=>{t&&(s[e]=t)};switch(o){case"for":e.loopVariable&&i("for",t(e.loopVariable)),i("in",n("source"));break;case"times":i("times",n("quantity")??n("patient")??n("count"));break;case"while":case"until":i(o,n("condition"));break;case"until-event":{const r=Tt(e.roles.get("event"));r&&i("event",t(r)),i("from",n("source"));break}}e.indexVariable&&i("index",t(e.indexVariable));return{type:"command",name:"repeat",args:[St(e.body)],modifiers:s}}(e);case"compound":return{type:"CommandSequence",commands:(e.statements??[]).map(xt)};default:return function(e){const t={},n=[];for(const[r,o]of e.roles){const e=Lt(o);t[r]=e,n.push(e)}return{type:"command",name:e.action,args:n,roles:t}}(e)}}function St(e){return{type:"block",commands:(e??[]).map(xt)}}var Et=new Set(["for","times","while","until","until-event","forever"]);function Tt(e){if(e)return"literal"===e.type?e.value+"":"expression"===e.type?e.raw:"reference"===e.type||"selector"===e.type?e.value:void 0}function Lt(e){switch(e.type){case"selector":return{type:"selector",value:e.value};case"reference":return{type:"identifier",value:e.value};case"literal":{const t=e;if("duration"===t.dataType){const e=/^(\d+(?:\.\d+)?)(ms|s)$/.exec(t.value+"");if(e){return{type:"literal",value:"s"===e[2]?1e3*parseFloat(e[1]):parseFloat(e[1])}}}return{type:"literal",value:t.value}}case"property-path":{const t=e;return{type:"member",object:Lt(t.object),property:t.property}}case"expression":return{type:"expression",value:e.raw};case"flag":return{type:"literal",value:e.enabled};default:return{type:"literal",value:(e.value??"")+""}}}var At=class{constructor(e,t=new Set){this.patterns=new Map,this.tokenizers=new Map,this.schemas=e.schemas,this.partiallyTranslatedActions=t;for(const t of e.languages)this.registerLanguage(t)}registerLanguage(e){this.tokenizers.set(e.code,e.tokenizer);const t=[];for(const n of this.schemas){if(this.partiallyTranslatedActions.has(n.action)&&!e.patternProfile.keywords[n.action])continue;const r=Le(n,e.patternProfile);t.push(r)}this.patterns.set(e.code,t)}getPatterns(e){return this.patterns.get(e)||[]}getTokenizer(e){return this.tokenizers.get(e)}getSupportedLanguages(){return Array.from(this.patterns.keys())}},Mt=class{constructor(e,t,n,r){this.registry=t,this.matcher=new we,this.transformer=n,this.profileProvider=r,e.codeGenerator&&(this.codeGenerator=e.codeGenerator),e.renderer&&(this.domainRenderer=e.renderer),this.extensionRenderers=new Map;for(const t of e.extensions??[])t.render&&this.extensionRenderers.set(t.schema.action,t.render);this.schemaFallbackRenderer=We({schemas:e.schemas,profiles:e.languages.map(e=>e.patternProfile)});const o=new Map(e.schemas.map(e=>[e.action,e]));this.schemaLookup={getSchema:e=>o.get(e)}}parse(e,t){return this.parseWithConfidence(e,t).node}parseWithConfidence(e,t){if(N(e)){const t=$(e,{schemaLookup:this.schemaLookup});if(!this.schemaLookup.getSchema(t.action))throw Error(`No schema for action "${t.action}" in this DSL`);return{node:t,confidence:1}}const n=this.registry.getTokenizer(t);if(!n)throw Error("No tokenizer registered for language: "+t);const r=n.tokenize(e),o=this.registry.getPatterns(t),s={code:t};for(const n of o){const o=this.matcher.matchPattern(r,n,s);if(o){return{node:{kind:"command",action:n.command,roles:o.captured,metadata:{sourceLanguage:t,sourceText:e,patternId:n.id,confidence:o.confidence}},confidence:o.confidence}}}throw Error("No pattern matched for input: "+e)}validate(e,t){try{return{valid:!0,node:this.parseWithConfidence(e,t).node}}catch(e){return{valid:!1,errors:[e instanceof Error?e.message:e+""]}}}translate(e,t,n){if(N(e))return e;let r;try{r=this.parseWithConfidence(e,t).node}catch(r){if(this.hasGrammarProfile(t)&&this.hasGrammarProfile(n))return this.transformer.transform(e,t,n);throw r}const o=this.registry.getSupportedLanguages().includes(n)?this.render(r,n):null;if(null!=o)return o;if(this.hasGrammarProfile(t)&&this.hasGrammarProfile(n))return this.transformer.transform(e,t,n);throw Error(`translate() could not render action "${r.action}" in language "${n}": no custom renderer, domain renderer, or schema pattern covers it, and no grammar profile is configured for the transformer fallback. Either add "${n}" to the DSL's languages/renderer, or set 'grammarProfile' on its LanguageConfig in createMultilingualDSL() (parse/validate/compile do not need it).`)}hasGrammarProfile(e){return null!=this.profileProvider.getProfile(e)}compile(e,t){if(!this.codeGenerator)return{ok:!1,errors:["No code generator configured for this DSL"]};try{const n=this.parseWithConfidence(e,t);return{ok:!0,code:this.codeGenerator.generate(n.node),node:n.node,metadata:{parser:"semantic",confidence:n.confidence}}}catch(e){return{ok:!1,errors:[e instanceof Error?e.message:e+""]}}}render(e,t){const n=this.extensionRenderers.get(e.action);if(n){const r=n(e,t);if(null!=r)return r}if(this.domainRenderer){const n=this.domainRenderer(e,t);if(null!=n)return n}return this.schemaFallbackRenderer(e,t)}getSupportedLanguages(){return this.registry.getSupportedLanguages()}};function $t(e){const t=function(e){const t=e.extensions;if(!t||0===t.length)return e;const n=new Set(e.languages.map(e=>e.code)),r=new Set(e.schemas.map(e=>e.action));for(const e of t){const{action:t}=e.schema;if(r.has(t))throw Error(`Extension command "${t}" collides with a command this DSL already defines. Pick a different action name.`);r.add(t);for(const r of Object.keys(e.vocabulary))if(!n.has(r))throw Error(`Extension command "${t}" supplies vocabulary for language "${r}", which is not configured on this DSL. Configured languages: ${[...n].join(", ")}.`)}const o=[...e.schemas,...t.map(e=>e.schema)],s=e.languages.map(e=>{const n={...e.patternProfile.keywords};let r=e.patternProfile.roleMarkers;for(const o of t){const t=o.vocabulary[e.code];t&&(n[o.schema.action]={...t.keyword},t.roleMarkers&&(r={...r,...t.roleMarkers}))}return{...e,patternProfile:{...e.patternProfile,keywords:n,...void 0!==r&&{roleMarkers:r}}}}),i=new Map(t.filter(e=>e.generate).map(e=>[e.schema.action,e.generate])),a=e.codeGenerator,c=i.size>0?{generate(e){const t=i.get(e.action);if(t)return t(e);if(!a)throw Error(`No code generator for action "${e.action}"`);return a.generate(e)}}:a;return{...e,schemas:o,languages:s,...void 0!==c&&{codeGenerator:c}}}(e),n=new Set((e.extensions??[]).map(e=>e.schema.action)),r=t.dictionary??function(e){const t={};for(const n of e.languages){const e={};for(const[t,r]of Object.entries(n.patternProfile.keywords))e[t]=r.primary;t[n.code]=e}return new Ke(t)}(t),o=t.profileProvider??function(e){const t={};for(const n of e.languages)n.grammarProfile&&(t[n.code]=n.grammarProfile);return new Fe(t)}(t),s=new qe({dictionary:r,profileProvider:o}),i=new At(t,n);return new Mt(t,i,s,o)}function Nt(e){const t=e.outputFormat??"both",n=e.examplesPerCommand??2,r=[Ct(),It(),Rt(e.schemas,t,n),_t(t),Wt()];let o=r;e.maxTokens&&e.maxTokens>0&&(o=function(e,t){const n=[];let r=t;for(const t of e){if(t.approximateTokens>r){const e=t.content.slice(0,Math.max(4*r,40))+"\n\n*(truncated)*";n.push({...t,content:e,approximateTokens:qt(e)});break}n.push(t),r-=t.approximateTokens}return n}(r,e.maxTokens));const s=o.map(e=>`## ${e.title}\n\n${e.content}`).join("\n\n---\n\n"),i=e.schemas.reduce((e,t)=>e+t.roles.length,0),a=qt(s);return{text:s,sections:o,metadata:{domain:e.domain,commandCount:e.schemas.length,roleCount:i,approximateTokens:a}}}function Ot(e,t=2){const n=function(e){const t=e.roles.filter(e=>e.required),n=e.roles.filter(e=>!e.required),r=[];t.length>0&&r.push(t);for(const e of n)r.push([...t,e]);2>n.length||r.push([...t,...n]);0===r.length&&r.push(e.roles.slice());return r}(e),r=[];for(let o=0;Math.min(t,n.length)>o;o++){const t=n[o],s=new Map;for(const e of t){const t=Bt(e);s.set(e.role,t)}const a=new Map;for(const[e,t]of s)a.set(e,Dt(t));const c=z(i(e.action,a)),l={};for(const[e,t]of s)l[e]=t;r.push({explicit:c,json:{action:e.action,roles:l}})}return r}function jt(){const e=Ct(),t=It();return`# LokaScript Explicit Syntax (LSE) Quick Reference\n\n${e.content}\n\n${t.content}`}function Ct(){const e='LokaScript Explicit Syntax (LSE) is a bracket-based format for imperative commands.\n\n### Syntax\n\n```\n[command role1:value1 role2:value2 +flag1 ~flag2]\n```\n\n- **Command**: The first token inside brackets (lowercased)\n- **Role pair**: `name:value` \u2014 a named semantic role with a typed value (no space around colon)\n- **Enabled flag**: `+name` \u2014 boolean attribute present\n- **Disabled flag**: `~name` \u2014 boolean attribute negated\n- **Nested body**: `body:[command ...]` \u2014 a bracket command inside a role value\n\n### Rules\n\n1. Commands are always lowercased\n2. Role names preserve their original case\n3. No spaces around the colon in role:value pairs\n4. Strings with spaces must be quoted: `patient:"hello world"`\n5. Selectors start with `#`, `.`, `[`, `@`, or `*`\n6. A selector containing a space, a combinator (`>` `+` `~`), or a comma must use a selector literal: `patient:<ul > li/>`, `patient:<.a, .b/>`\n7. Inside a structural role (`body`, `then`, `else`, `condition`, `loop-body`, `variable`, `catch`, `finally`) a `[...]` value is always a nested command. Write an attribute selector there as `condition:<[data-active]/>`\n8. Output must be valid bracket syntax: `[action role:value ...]`';return{id:"protocol",title:"LSE Protocol",content:e,approximateTokens:qt(e)}}function It(){const e="Values in LSE are classified by their syntactic form (first match wins):\n\n| Type | Syntax | Example |\n|------|--------|---------|\n| Selector literal | Delimited by `<` and `/>` | `<ul > li/>`, `<.a, .b/>`, `<[data-id]/>` |\n| Selector | Starts with `#` `.` `[` `@` `*` | `#button`, `.active`, `[data-id]` |\n| String | Quoted with `\"` or `'` | `\"hello world\"`, `'json'` |\n| Boolean | Exact: `true` / `false` | `visible:true` |\n| Reference | Built-in name | `me`, `you`, `it`, `result`, `event`, `target`, `body` |\n| Duration | Number + suffix | `500ms`, `2s`, `1m`, `1h` |\n| Number | Digits with optional decimal | `5`, `3.14`, `-1` |\n| Plain | Fallback (any non-whitespace) | `/api/users`, `json`, `production` |\n\n**Important**: Classification is by prefix, not by intent. `#true` is a selector (not boolean). `event` as a value is a reference (not plain text).";return{id:"value-types",title:"Value Types",content:e,approximateTokens:qt(e)}}function Rt(e,t,n){const r=[];for(const o of e)r.push(Pt(o,t,n));const o=r.join("\n\n");return{id:"commands",title:"Available Commands",content:o,approximateTokens:qt(o)}}function _t(e){let t;return t="explicit"===e?"Output valid LSE bracket syntax. Each command must be wrapped in brackets:\n\n```\n[command role:value ...]\n```\n\nDo NOT output JSON. Only use bracket syntax.":"json"===e?'Output valid JSON in the LLM-simplified format:\n\n```json\n{\n "action": "command-name",\n "roles": {\n "roleName": { "type": "valueType", "value": "theValue" }\n }\n}\n```\n\nValid value types: `selector`, `literal`, `reference`, `expression`.\nDo NOT output bracket syntax. Only use JSON.':'You may output EITHER format:\n\n**Bracket syntax** (preferred for single commands):\n```\n[command role:value ...]\n```\n\n**JSON format** (preferred when structured data is needed):\n```json\n{\n "action": "command-name",\n "roles": {\n "roleName": { "type": "valueType", "value": "theValue" }\n }\n}\n```\n\nBoth formats are equally valid. Use whichever is more natural for the context.',{id:"output-format",title:"Output Format",content:t,approximateTokens:qt(t)}}function Wt(){const e="If you're unsure about a command or role:\n\n1. **Unknown command**: Use the closest matching command from the Available Commands section. Do not invent commands.\n2. **Unknown role**: Use only the roles listed for each command. Do not add roles not in the schema.\n3. **Ambiguous value type**: When in doubt, use `expression` type (it's the most permissive).\n4. **Missing required role**: Always include all required roles. Check the Required/Optional labels.\n5. **Selector vs plain value**: If a value starts with `#`, `.`, `[`, `@`, or `*`, it's a selector. URLs like `/api/data` are plain values.\n\nWhen generating LSE, prefer explicit role labeling over positional guessing. Every value should have a role name.";return{id:"error-recovery",title:"Error Recovery",content:e,approximateTokens:qt(e)}}function Pt(e,t,n){const r=[];r.push(`### \`${e.action}\` \u2014 ${e.description}`),r.push("");const o=e.roles.filter(e=>e.required),s=e.roles.filter(e=>!e.required);if(o.length>0){r.push("**Required roles:**");for(const e of o)r.push(`- \`${e.role}\`: ${e.description} (type: ${Vt(e)})`)}if(s.length>0){r.push("**Optional roles:**");for(const e of s)r.push(`- \`${e.role}\`: ${e.description} (type: ${Vt(e)})`)}const i=Ot(e,n);if(i.length>0){if(r.push(""),"explicit"===t||"both"===t){r.push("**Bracket syntax:**");for(const e of i)r.push(`\`\`\`\n${e.explicit}\n\`\`\``)}if("json"===t||"both"===t){r.push("**JSON format:**");for(const e of i)r.push(`\`\`\`json\n${JSON.stringify(e.json,null,2)}\n\`\`\``)}}return r.join("\n")}function Vt(e){return e.expectedTypes.join(" | ")}function Bt(e){switch(e.expectedTypes[0]||"expression"){case"selector":return{type:"selector",value:{patient:".active",destination:"#output",source:"#input",target:"#target"}[t=e.role]||"#"+t};case"literal":return function(e){return{type:"literal",value:{duration:"30s",interval:"5s",delay:"500ms",timeout:"10s",quantity:5,limit:10,style:"json",manner:"rolling",format:"html"}[e]||e}}(e.role);case"reference":return{type:"reference",value:"me"};case"expression":return function(e){return{type:"expression",value:{source:"/api/data",destination:"#output",patient:".active",instrument:"toUpperCase",condition:"age > 18",style:"json",duration:"5s",url:"/api/users"}[e]||"/api/"+e}}(e.role);case"flag":return{type:"flag",value:!0};default:return{type:"literal",value:"example"}}var t}function Dt(e){switch(e.type){case"selector":return{type:"selector",value:e.value+"",selectorKind:zt(e.value+"")};case"literal":return{type:"literal",value:e.value,dataType:"number"==typeof e.value?"number":"boolean"==typeof e.value?"boolean":"string"};case"reference":return{type:"reference",value:e.value+""};case"expression":return{type:"expression",value:e.value+"",raw:e.value+""};case"flag":return{type:"flag",value:e.value};default:return{type:"literal",value:e.value+"",dataType:"string"}}}function zt(e){return e.startsWith("#")?"id":e.startsWith(".")?"class":e.startsWith("[")?"attribute":"complex"}function qt(e){return Math.ceil(e.length/4)}function Kt(e,t){const n=t.maxPairsPerCommand??5,r=t.minQuality??.5,o=t.shuffleRoles??!0,s=t.languages??["en"],i=[];let a=0;for(const c of e){const e=Gt(c);for(const l of s){let s=0;for(const u of e){if(s>=n)break;const e=Ft(c,u,l,t.domain,`${t.domain}-synth-${a++}`);if(r>e.quality||(i.push(e),s++),o&&u.length>=2&&n>s){const e=Ft(c,[...u].reverse(),l,t.domain,`${t.domain}-synth-${a++}`);r>e.quality||(i.push(e),s++)}}}}return{pairs:i,metadata:{domain:t.domain,commandCount:e.length,pairCount:i.length,bySource:{synthetic:i.length},languages:s}}}function Gt(e){const t=e.roles.filter(e=>e.required),n=e.roles.filter(e=>!e.required),r=[];t.length>0&&r.push(t);for(const e of n)r.push([...t,e]);return 2>n.length||r.push([...t,...n]),0===r.length&&r.push(e.roles.slice()),r}function Ft(e,t,n,r,o){const s=new Map;for(const e of t)s.set(e.role,Ut(e));const a=new Map;for(const[e,t]of s)a.set(e,Jt(t));const c=z(i(e.action,a)),l={};for(const[e,t]of s)l[e]=t;const u={action:e.action,roles:l},d=function(e,t,n){const r=[e.action];for(const o of e.roles){const e=t.get(o.role);if(!e)continue;const s=o.markerOverride?.[n];s&&r.push(s),r.push(e.value+"")}return r.join(" ")}(e,s,n),f=e.roles.filter(e=>e.required).length,p=t.filter(e=>e.required).length;return{id:o,natural:d,language:n,explicit:c,json:u,domain:r,action:e.action,source:"synthetic",quality:f>0?p/f:.8}}function Ut(e){switch(e.expectedTypes[0]||"expression"){case"selector":return{type:"selector",value:{patient:".active",destination:"#output",source:"#input",target:"#target"}[t=e.role]||"#"+t};case"literal":return function(e){return{type:"literal",value:{duration:"30s",interval:"5s",delay:"500ms",timeout:"10s",quantity:5,limit:10,style:"json",manner:"rolling",format:"html"}[e]||e}}(e.role);case"reference":return{type:"reference",value:"me"};case"expression":return function(e){return{type:"expression",value:{source:"/api/data",destination:"#output",patient:".active",instrument:"toUpperCase",condition:"age > 18",style:"json",duration:"5s",url:"/api/users"}[e]||"/api/"+e}}(e.role);case"flag":return{type:"flag",value:!0};default:return{type:"literal",value:"example"}}var t}function Jt(e){switch(e.type){case"selector":return{type:"selector",value:e.value+"",selectorKind:Ht(e.value+"")};case"literal":return{type:"literal",value:e.value,dataType:"number"==typeof e.value?"number":"boolean"==typeof e.value?"boolean":"string"};case"reference":return{type:"reference",value:e.value+""};case"expression":return{type:"expression",value:e.value+"",raw:e.value+""};case"flag":return{type:"flag",value:e.value};default:return{type:"literal",value:e.value+"",dataType:"string"}}}function Ht(e){return e.startsWith("#")?"id":e.startsWith(".")?"class":e.startsWith("[")?"attribute":"complex"}function Zt(e,t,n,r,o){const s=n.some(e=>"error"===e.severity),a=n.map(e=>function(e){const t=function(e){const t=(e.code||"").toLowerCase(),n=e.message.toLowerCase();if(t.includes("missing-role")||t.includes("missing_role")||n.includes("required role")||n.includes("missing role"))return"missing_role";if(t.includes("invalid-type")||t.includes("invalid_type")||t.includes("type-mismatch")||n.includes("invalid type")||n.includes("expected type"))return"invalid_type";if(t.includes("unknown-command")||t.includes("unknown_command")||n.includes("unknown command")||n.includes("not recognized")&&n.includes("command"))return"unknown_command";if(t.includes("unknown-role")||t.includes("unknown_role")||n.includes("unknown role")||n.includes("not recognized")&&n.includes("role"))return"unknown_role";if(t.includes("parse")||t.includes("syntax")||n.includes("syntax error")||n.includes("parse error")||n.includes("unexpected"))return"syntax_error";return}(e);return{severity:e.severity,code:e.code||"unknown",message:e.message,...e.suggestions?.[0]&&{suggestion:e.suggestions[0]},...t&&{fixType:t}}}(e)),c=function(e,t,n){const r=[],o=n&&t?t.getSchema(n):void 0;for(const t of e)if("error"===t.severity)switch(t.fixType){case"missing_role":if(o){const e=o.roles.filter(e=>e.required).map(e=>`'${e.role}' (${e.description}, type: ${e.expectedTypes.join("|")})`).join(", ");r.push(`Required roles for '${n}': ${e}`)}else r.push("Check that all required roles are present.");break;case"unknown_command":r.push("Command not recognized. Ensure you're using a valid command from the domain schema.");break;case"unknown_role":if(o){const e=o.roles.map(e=>`'${e.role}'`).join(", ");r.push(`Valid roles for '${n}': ${e}`)}else r.push("Use only roles defined in the command schema.");break;case"invalid_type":r.push("Check value types: selectors start with #.[@*, strings use quotes, numbers are plain digits.");break;case"syntax_error":r.push("Ensure bracket syntax: [command role:value ...]. No spaces around the colon.");break;default:t.suggestion&&r.push(t.suggestion)}return[...new Set(r)]}(a,r,o);let l,u;if(o&&r){const e=r.getSchema(o);e&&(l=function(e){const t=[],n=[],r={};for(const o of e.roles)o.required?t.push(o.role):n.push(o.role),r[o.role]=o.description;return{action:e.action,requiredRoles:t,optionalRoles:n,roleDescriptions:r}}(e),s&&(u=function(e){const t=new Map,n={};for(const r of e.roles){if(!r.required)continue;const e=Yt(r.role,r.expectedTypes[0]||"expression");t.set(r.role,Qt(e)),n[r.role]=e}const r=i(e.action,t),o=z(r),s={action:e.action,roles:n};return{explicit:o,json:s}}(e)))}return{accepted:!s,input:{format:t,text:e},diagnostics:a,hints:c,...l&&{schema:l},...u&&{correctedExample:u}}}function Yt(e,t){switch(t){case"selector":return{type:"selector",value:"#"+e};case"expression":default:return{type:"expression",value:`<${e}-value>`};case"literal":return{type:"literal",value:`<${e}-value>`};case"reference":return{type:"reference",value:"me"}}}function Qt(e){switch(e.type){case"selector":return{type:"selector",value:e.value,selectorKind:"id"};case"expression":return{type:"expression",value:e.value,raw:e.value};case"literal":default:return{type:"literal",value:e.value,dataType:"string"};case"reference":return{type:"reference",value:e.value}}}var Xt=class{constructor(){this.descriptors=new Map,this.dslCache=new Map,this.rendererCache=new Map}register(e){if(this.descriptors.has(e.name))throw Error("Domain already registered: "+e.name);this.descriptors.set(e.name,e)}setSchemas(e,t){const n=this.descriptors.get(e);if(!n)throw Error("Domain not registered: "+e);this.descriptors.set(e,{...n,schemas:t})}getDomainNames(){return Array.from(this.descriptors.keys())}getDescriptor(e){return this.descriptors.get(e)}getToolDefinitions(){const e=[];for(const t of this.descriptors.values())e.push(...en(t));return e}canHandle(e){const t=tn(e);return!!t&&this.descriptors.has(t.domain)}async handleToolCall(e,t){const n=tn(e);if(!n)return null;const r=this.descriptors.get(n.domain);if(!r)return null;try{const e=await this.getDSL(r);switch(n.operation){case"parse":return await this.handleParse(r,e,t);case"compile":return await this.handleCompile(r,e,t);case"validate":return await this.handleValidate(r,e,t);case"translate":return await this.handleTranslate(r,e,t);default:return rn({error:"Unknown operation: "+n.operation},!0)}}catch(e){return rn({error:`${r.name} tool error: ${e instanceof Error?e.message:e+""}`},!0)}}async getDSLForDomain(e){const t=this.descriptors.get(e);return t?this.getDSL(t):null}generatePrompt(e,t){const n=this.descriptors.get(e);return n?.schemas&&0!==n.schemas.length?Nt({domain:e,description:n.description,schemas:n.schemas,...t}):null}generateTrainingData(e,t){const n=this.descriptors.get(e);return n?.schemas&&0!==n.schemas.length?Kt(n.schemas,{domain:e,...t}):null}buildFeedback(e,t,n,r){const o=this.descriptors.get(e);if(!o?.schemas||0===o.schemas.length)return null;const s=this.createSchemaLookup(o.schemas);let i;try{if("explicit"===n){i=$(t,{schemaLookup:s}).action}}catch{}return Zt(t,n,r,s,i)}getSchemas(e){const t=this.descriptors.get(e);return t?.schemas?t.schemas:null}createSchemaLookup(e){const t=new Map;for(const n of e)t.set(n.action,n);return{getSchema:e=>t.get(e)}}async getDSL(e){const t=this.dslCache.get(e.name);if(t)return t;const n=await e.getDSL();return this.dslCache.set(e.name,n),n}async getRenderer(e){if(!e.getRenderer)return null;const t=this.rendererCache.get(e.name);if(t)return t;const n=await e.getRenderer();return this.rendererCache.set(e.name,n),n}async handleParse(e,t,n){const r=nn(n,e.inputLabel);if(!r)return on(e.inputLabel);const o=nn(n,"language","en"),s=t.parse(r,o),i={};for(const[e,t]of s.roles)i[e]=t;return rn({action:s.action,roles:i,language:o,[e.inputLabel]:r})}async handleCompile(e,t,n){const r=nn(n,e.inputLabel);if(!r)return on(e.inputLabel);const o=nn(n,"language","en"),s=t.compile(r,o);return rn({ok:s.ok,code:s.code,errors:s.errors,language:o,input:r})}async handleValidate(e,t,n){const r=nn(n,e.inputLabel);if(!r)return on(e.inputLabel);const o=nn(n,"language","en"),s=t.validate(r,o);return rn({valid:s.valid,errors:s.errors,language:o,[e.inputLabel]:r})}async handleTranslate(e,t,n){const r=nn(n,e.inputLabel);if(!r)return on(e.inputLabel);const o=nn(n,"from");if(!o)return on("from");const s=nn(n,"to");if(!s)return on("to");const i=t.parse(r,o),a=t.compile(r,o);let c=null;const l=await this.getRenderer(e);if(l)try{c="function"==typeof l?l(i,s):l.render(i,s)}catch{}else if(t.render)try{c=t.render(i,s)}catch{}const u={};for(const[e,t]of i.roles)u[e]=t;return rn({input:{[e.inputLabel]:r,language:o},...null!=c&&{rendered:{text:c,language:s}},semantic:{action:i.action,roles:u},...a.ok&&null!=a.code&&{compiled:a.code}})}};function en(e){const t=[],n=e.tools??["parse","compile","validate","translate"],r=e.languages.join(", ");for(const o of n)switch(o){case"parse":t.push({name:"parse_"+e.name,description:`Parse a ${e.description} input into a semantic representation (action, roles, confidence). Supports: ${r}.`,inputSchema:{type:"object",properties:{[e.inputLabel]:{type:"string",description:e.inputDescription},language:{type:"string",description:"Language code: "+r,default:"en"}},required:[e.inputLabel]}});break;case"compile":t.push({name:"compile_"+e.name,description:`Compile a ${e.description} input to ${e.outputDescription??"target code"}. Supports: ${r}.`,inputSchema:{type:"object",properties:{[e.inputLabel]:{type:"string",description:e.inputDescription},language:{type:"string",description:"Language code: "+r,default:"en"}},required:[e.inputLabel]}});break;case"validate":t.push({name:"validate_"+e.name,description:`Check ${e.description} syntax for errors. Returns {valid, errors[]}. Supports: ${r}.`,inputSchema:{type:"object",properties:{[e.inputLabel]:{type:"string",description:e.inputDescription+" to validate"},language:{type:"string",description:"Language code: "+r,default:"en"}},required:[e.inputLabel]}});break;case"translate":t.push({name:"translate_"+e.name,description:`Translate ${e.description} input between natural languages (requires 'from' and 'to' codes). Supports: ${r}.`,inputSchema:{type:"object",properties:{[e.inputLabel]:{type:"string",description:e.inputDescription+" to translate"},from:{type:"string",description:"Source language code: "+r},to:{type:"string",description:"Target language code: "+r}},required:[e.inputLabel,"from","to"]}})}return t}function tn(e){const t=e.match(/^(parse|compile|validate|translate)_(.+)$/);return t?{operation:t[1],domain:t[2]}:null}function nn(e,t,n=""){const r=e[t];return"string"==typeof r?r:n}function rn(e,t){return{content:[{type:"text",text:JSON.stringify(e,null,2)}],...t&&{isError:!0}}}function on(e){return rn({error:"Missing required parameter: "+e},!0)}var sn=/^\s*(\/\/|--|#)/;function an(e){const t=e.trim();return""===t||sn.test(t)}var cn=class{constructor(e,t){this.registry=e,this.minConfidence=t?.minConfidence??.5,this.priority=t?.priority??[]}async detect(e,t="en"){const n=this.registry.getDomainNames();if(0===n.length)return null;const r=[];for(const o of n)try{const n=await this.registry.getDSLForDomain(o);if(!n)continue;const{node:s,confidence:i}=n.parseWithConfidence(e,t);this.minConfidence>i||r.push({domain:o,node:s,confidence:i,dsl:n})}catch{}return 0===r.length?null:(r.sort(this.priority.length>0?(e,t)=>{const n=this.getPriorityIndex(e.domain),r=this.getPriorityIndex(t.domain);return n!==r?n-r:t.confidence-e.confidence}:(e,t)=>t.confidence-e.confidence),r[0])}async parseComposite(e,t="en"){const n=e.split("\n"),r=[],o=[];for(let e=0;n.length>e;e++){const s=n[e];if(an(s))continue;const i=s.trim(),a=await this.detect(i,t);a?r.push({line:e+1,input:i,domain:a.domain,node:a.node,confidence:a.confidence}):o.push({line:e+1,input:i,message:"No domain matched this input"})}return{statements:r,errors:o}}async compile(e,t="en"){const n=await this.detect(e,t);if(!n)return null;return{...n.dsl.compile(e,t),domain:n.domain}}async compileComposite(e,t="en"){const n=e.split("\n"),r=[],o=[];for(let e=0;n.length>e;e++){const s=n[e];if(an(s))continue;const i=s.trim(),a=await this.detect(i,t);if(a){const n=a.dsl.compile(i,t);r.push({line:e+1,input:i,domain:a.domain,ok:n.ok,code:n.code,errors:n.errors})}else o.push({line:e+1,input:i,message:"No domain matched this input"})}return{statements:r,errors:o}}async validate(e,t="en"){const n=await this.detect(e,t);if(!n)return{valid:!1,errors:["No domain matched this input"]};return{...n.dsl.validate(e,t),domain:n.domain}}getPriorityIndex(e){const t=this.priority.indexOf(e);return-1===t?this.priority.length:t}};function ln(e){const t=[];for(const n of e){const e=n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");t.push(RegExp(e+'\\s*=\\s*"([^"]+)"',"g")),t.push(RegExp(e+"\\s*=\\s*'([^']+)'","g")),t.push(RegExp(e+"\\s*=\\s*`([^`]+)`","g"))}return t}function un(e){return e.map(e=>{const t=e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");return RegExp(`<script[^>]*type=["']?${t}["']?[^>]*>([\\s\\S]*?)<\\/script>`,"gi")})}function dn(e,t){let n=1;for(let r=0;t>r&&e.length>r;r++)"\n"===e[r]&&n++;return n}function fn(e,t){const n=e.lastIndexOf("<",t);if(-1===n)return;const r=e.slice(n,t+200).match(/\bid=["']([^"']+)["']/);return r?.[1]}function pn(e,t){const n=e.lastIndexOf("<",t);if(-1===n)return;const r=e.slice(n,t+200).match(/\blang=["']([^"']+)["']/);return r?.[1]}var hn=class{constructor(e){this.configs=e}extract(e,t){const n=[];for(const r of this.configs){const o=r.defaultLanguage??"en",s=ln(r.attributes);for(const i of s){let s;for(i.lastIndex=0;s=i.exec(e);){const i=s[1].trim();if(!i)continue;const a=dn(e,s.index),c=fn(e,s.index),l=pn(e,s.index);n.push({domain:r.domain,code:i,language:l??o,file:t,line:a,column:1,...null!=c&&{elementId:c}})}}if(r.scriptTypes){const s=un(r.scriptTypes);for(const i of s){let s;for(i.lastIndex=0;s=i.exec(e);){const i=s[1].trim();if(!i)continue;const a=dn(e,s.index);n.push({domain:r.domain,code:i,language:o,file:t,line:a,column:1})}}}}return n}async extractFromFiles(e,t){const n=[];for(const r of e)try{const e=await t(r),o=this.extract(e,r);n.push(...o)}catch{}return n}},mn=class{constructor(e){this.backends=new Map,this.options={confidenceThreshold:e?.confidenceThreshold??.7,continueOnError:e?.continueOnError??!0,debug:e?.debug??!1}}registerBackend(e){if(this.backends.has(e.domain))throw Error("Backend already registered for domain: "+e.domain);this.backends.set(e.domain,e)}async compileFiles(e,t){const n=Array.from(this.backends.values()).map(e=>e.scanConfig),r=new hn(n),o=await r.extractFromFiles(e,t),s=[],i=[],a={};for(const e of o){a[e.domain]=(a[e.domain]??0)+1;const t=this.compileSnippet(e);if("error"in t){if(i.push({domain:e.domain,source:e.code,file:e.file,line:e.line,message:t.error}),!this.options.continueOnError)break}else s.push(t)}return{compiled:s,errors:i,stats:{totalSnippets:o.length,compiledCount:s.length,errorCount:i.length,domainBreakdown:a}}}compileSnippet(e){const t=this.backends.get(e.domain);if(!t)return{error:"No backend registered for domain: "+e.domain};try{const n=t.dsl.compile(e.code,e.language);return n.ok&&n.code?{domain:e.domain,source:e.code,compiled:n.code,language:e.language,file:e.file,line:e.line}:{error:n.errors?.join("; ")??"Compilation failed"}}catch(e){return{error:e instanceof Error?e.message:e+""}}}generateOutput(e,t){const n=t?.format??"esm",r=t?.includeComments??!0,o=t?.groupByDomain??!0,s=[];if(r&&(s.push("// Generated by @lokascript/framework AOT compiler"),s.push(`// ${e.stats.compiledCount} snippets compiled, ${e.stats.errorCount} errors`),s.push("")),o){const t=new Map;for(const n of e.compiled){const e=t.get(n.domain)??[];e.push(n),t.set(n.domain,e)}for(const[e,n]of t){r&&(s.push(`// === Domain: ${e} ===`),s.push(""));for(const e of n)r&&(s.push(`// Source: ${e.file}:${e.line}`),s.push("// Language: "+e.language)),s.push(e.compiled),s.push("")}}else for(const t of e.compiled)r&&s.push(`// [${t.domain}] ${t.file}:${t.line}`),s.push(t.compiled),s.push("");const i=s.join("\n").trimEnd();switch(n){case"cjs":return`'use strict';\n\n${i}\n`;case"iife":return`(function() {\n${i}\n})();\n`;default:return i+"\n"}}};async function gn(e){const t=[];for(const n of e.getDomainNames()){const r=e.getDescriptor(n);if(!r?.scanConfig)continue;const o=await e.getDSLForDomain(n);if(!o)continue;const s={domain:n,attributes:[...r.scanConfig.attributes],...r.scanConfig.scriptTypes?{scriptTypes:[...r.scanConfig.scriptTypes]}:{},defaultLanguage:r.scanConfig.defaultLanguage??"en"};t.push({domain:n,dsl:o,codeGenerator:{generate:e=>JSON.stringify({action:e.action,roles:Object.fromEntries(e.roles)})},scanConfig:s})}return t}var yn=class{constructor(e,t){this.pos=0,this.tokens=e,this.language=t}peek(e=0){const t=this.pos+e;return 0>t||t>=this.tokens.length?null:this.tokens[t]}advance(){if(this.isAtEnd())throw Error("Unexpected end of token stream");return this.tokens[this.pos++]}isAtEnd(){return this.pos>=this.tokens.length}mark(){return{position:this.pos}}reset(e){this.pos=e.position}position(){return this.pos}remaining(){return this.tokens.slice(this.pos)}takeWhile(e){const t=[];for(;!this.isAtEnd()&&e(this.peek());)t.push(this.advance());return t}skipWhile(e){for(;!this.isAtEnd()&&e(this.peek());)this.advance()}};function vn(e,t){return{start:e,end:t}}function bn(e,t,n,r){if("object"==typeof e){const{value:t,kind:n,position:r,normalized:o,stem:s,stemConfidence:i,metadata:a}=e;return{value:t,kind:n,position:r,...void 0!==o&&{normalized:o},...void 0!==s&&{stem:s},...void 0!==i&&{stemConfidence:i},...void 0!==a&&{metadata:a}}}const o=e;if(!t||!n)throw Error("createToken requires kind and position parameters");if("string"==typeof r)return{value:o,kind:t,position:n,normalized:r};if(r){const{normalized:e,stem:s,stemConfidence:i,metadata:a}=r;return{value:o,kind:t,position:n,...void 0!==e&&{normalized:e},...void 0!==s&&{stem:s},...void 0!==i&&{stemConfidence:i},...void 0!==a&&{metadata:a}}}return{value:o,kind:t,position:n}}function kn(e){return/\s/.test(e)}function wn(e){return"#"===e||"."===e||"["===e||"@"===e||"*"===e||"<"===e}function xn(e){return'"'===e||"'"===e||"`"===e||"\u300c"===e||"\u300d"===e}function Sn(e){return/\d/.test(e)}function En(e){return e.replace(/[\u064b-\u0652\u0670]/g,"")}function Tn(e){return/[a-zA-Z]/.test(e)}function Ln(e){return/[a-zA-Z0-9_-]/.test(e)}function An(e,t){if(t>=e.length)return null;const n=e[t];if(!wn(n))return null;let r=t,o="";if("#"===n||"."===n){for(o+=e[r++];e.length>r&&Ln(e[r]);)o+=e[r++];if(1>=o.length)return null;if(e.length>r&&"."===e[r]&&"#"===n){let t=r+1;for(;e.length>t&&Ln(e[t]);)t++;if(e.length>t&&"("===e[t])return o}}else if("["===n){let t=1,n=!1,s=null,i=!1;for(o+=e[r++];e.length>r&&t>0;){const a=e[r];o+=a,i?i=!1:"\\"===a?i=!0:n?a===s&&(n=!1,s=null):'"'===a||"'"===a||"`"===a?(n=!0,s=a):"["===a?t++:"]"===a&&t--,r++}if(0!==t)return null}else if("@"===n){for(o+=e[r++];e.length>r&&Ln(e[r]);)o+=e[r++];if(1>=o.length)return null}else if("*"===n){for(o+=e[r++];e.length>r&&Ln(e[r]);)o+=e[r++];if(1>=o.length)return null}else if("<"===n){if(o+=e[r++],r>=e.length||!Tn(e[r]))return null;for(;e.length>r&&Ln(e[r]);)o+=e[r++];for(;e.length>r;){const t=e[r];if("."===t){if(o+=e[r++],r>=e.length||!Ln(e[r]))return null;for(;e.length>r&&Ln(e[r]);)o+=e[r++]}else if("#"===t){if(o+=e[r++],r>=e.length||!Ln(e[r]))return null;for(;e.length>r&&Ln(e[r]);)o+=e[r++]}else{if("["!==t)break;{let t=1,n=!1,s=null,i=!1;for(o+=e[r++];e.length>r&&t>0;){const a=e[r];o+=a,i?i=!1:"\\"===a?i=!0:n?a===s&&(n=!1,s=null):'"'===a||"'"===a||"`"===a?(n=!0,s=a):"["===a?t++:"]"===a&&t--,r++}if(0!==t)return null}}}for(;e.length>r&&kn(e[r]);)o+=e[r++];if(e.length>r&&"/"===e[r])for(o+=e[r++];e.length>r&&kn(e[r]);)o+=e[r++];if(r>=e.length||">"!==e[r])return null;o+=e[r++]}return o||null}function Mn(e,t){if(t>=e.length||"'"!==e[t])return!1;if(t+1>=e.length)return!1;if("s"!==e[t+1].toLowerCase())return!1;if(t+2>=e.length)return!0;const n=e[t+2];return kn(n)||"*"===n||!Ln(n)}function $n(e,t){if(t>=e.length)return null;const n=e[t];if(!xn(n))return null;if("'"===n&&Mn(e,t))return null;const r={'"':'"',"'":"'","`":"`","\u300c":"\u300d"}[n];if(!r)return null;let o=t+1,s=n,i=!1;for(;e.length>o;){const t=e[o];if(s+=t,i)i=!1;else if("\\"===t)i=!0;else if(t===r)return s;o++}return s}function Nn(e,t){if(t>=e.length)return!1;const n=e[t],r=e[t+1]||"",o=e[t+2]||"";if("/"===n&&"/"!==r&&/[a-zA-Z0-9._-]/.test(r))return!0;if("/"===n&&"/"===r&&/[a-zA-Z]/.test(o))return!0;if("."===n&&("/"===r||"."===r&&"/"===o))return!0;const s=e.slice(t,t+8).toLowerCase();return!(!s.startsWith("http://")&&!s.startsWith("https://"))}function On(e,t){if(!Nn(e,t))return null;let n=t,r="";const o=/[a-zA-Z0-9/:._\-?&=%@+~!$'()*,;[\]]/;for(;e.length>n;){const t=e[n];if("#"===t){if(r.length>0&&/[a-zA-Z0-9/.]$/.test(r))for(r+=t,n++;e.length>n&&/[a-zA-Z0-9_-]/.test(e[n]);)r+=e[n++];break}if(!o.test(t))break;r+=t,n++}return 2>r.length?null:r}function jn(e,t){if(t>=e.length)return null;const n=e[t];if(!Sn(n)&&"-"!==n&&"+"!==n)return null;let r=t,o="";if("-"!==e[r]&&"+"!==e[r]||(o+=e[r++]),r>=e.length||!Sn(e[r]))return null;for(;e.length>r&&Sn(e[r]);)o+=e[r++];if(e.length>r&&"."===e[r])for(o+=e[r++];e.length>r&&Sn(e[r]);)o+=e[r++];if(e.length>r){"ms"===e.slice(r,r+2)?o+="ms":"s"!==e[r]&&"m"!==e[r]&&"h"!==e[r]||(o+=e[r])}return o}var Cn=["===","!==","->","==","!=","<=",">=","&&","||","**","+=","-=","*=","/=","+","-","*","/","=",">","<","!","&","|","%","^","~"],In=class{constructor(e=Cn){this.operators=e,this.name="operator",this.operators=[...e].sort((e,t)=>t.length-e.length)}canExtract(e,t){return this.operators.some(n=>e.startsWith(n,t))}extract(e,t){for(const n of this.operators)if(e.startsWith(n,t))return{value:n,length:n.length};return null}},Rn="()[]{},:;",_n=class{constructor(e=Rn){this.punctuation=e,this.name="punctuation"}canExtract(e,t){return this.punctuation.includes(e[t])}extract(e,t){const n=e[t];return this.punctuation.includes(n)?{value:n,length:1}:null}};function Wn(){return[new Je,new He,new In,new _n,new Ze,new Ye]}function Pn(e){return e.registerExtractors(Wn()),e}var Vn=new Set(Cn),Bn=new Set(["patient","destination","source","style","event","eventMarker","agent","goal","manner","into","from","to","with","at","of","as","by","in","on","over","under","between","through","without"]);var Dn=["click","dblclick","input","change","submit","keydown","keyup","keypress","mousedown","mouseup","mouseover","mouseout","mouseenter","mouseleave","mousemove","pointerdown","pointerup","pointermove","focus","blur","load","resize","scroll"],zn=class e{constructor(){this.profileKeywords=[],this.multiWordKeywords=[],this.profileKeywordMap=new Map,this.rawExtraEntries=[],this.extractors=[]}getExtraKeywordEntries(){return this.rawExtraEntries}tokenize(e){if(this.isUsingExtractors())return this.tokenizeWithExtractors(e);throw Error(this.constructor.name+": tokenize() not implemented and no extractors registered. Either register extractors or override tokenize() method.")}registerExtractor(e){ot(e)&&e.setContext(st(this)),this.extractors.push(e)}registerExtractors(e){for(const t of e)this.registerExtractor(t)}clearExtractors(){this.extractors=[]}isUsingExtractors(){return this.extractors.length>0}tokenizeWithExtractors(e){const t=[];let n=0;for(;e.length>n;){for(;e.length>n&&kn(e[n]);)n++;if(n>=e.length)break;const r=this.tryMultiWordKeyword(e,n);if(r){t.push(r),n=r.position.end;continue}let o=!1;for(const r of this.extractors)if(r.canExtract(e,n)){const s=r.extract(e,n);if(s){const e=s.metadata?.normalized,r=s.metadata?.stem,i=s.metadata?.stemConfidence,a={};if(s.metadata)for(const[e,t]of Object.entries(s.metadata))"normalized"!==e&&"stem"!==e&&"stemConfidence"!==e&&(a[e]=t);const c={};e&&(c.normalized=e),r&&(c.stem=r),void 0!==i&&(c.stemConfidence=i),Object.keys(a).length>0&&(c.metadata=a),t.push(bn(s.value,this.classifyToken(s.value),vn(n,n+s.length),Object.keys(c).length>0?c:void 0)),n+=s.length,o=!0;break}}if(!o){const r=e[n],o=this.classifyUnknownChar(r);t.push(bn(r,o,vn(n,n+1))),n++}}return new yn(this.mergeColonQualifiedNames(t),this.language)}mergeColonQualifiedNames(t){const n=[];for(const r of t){const t=n[n.length-1];if(t&&e.ASCII_WORD.test(t.value)&&e.COLON_QUALIFIER.test(r.value)&&t.position.end===r.position.start){const e=t.value+r.value;n[n.length-1]=bn(e,this.classifyToken(e),vn(t.position.start,r.position.end));continue}n.push(r)}return n}classifyUnknownChar(e){return"()[]{},:;".includes(e)?"punctuation":"+-*/<>=!&|".includes(e)?"operator":"identifier"}tryPropertyAccess(e,t,n){if("."!==e[t])return!1;const r=n[n.length-1];if(r&&!(r&&t>r.position.end)&&("identifier"===r.kind||"keyword"===r.kind||"selector"===r.kind))return n.push(bn(".","operator",vn(t,t+1))),!0;let o=t+1;for(;e.length>o&&Ln(e[o]);)o++;return e.length>o&&"("===e[o]&&(n.push(bn(".","operator",vn(t,t+1))),!0)}initializeKeywordsFromProfile(e,t=[]){const n=new Map;if(this.rawExtraEntries=t,e.keywords)for(const[t,r]of Object.entries(e.keywords))if(n.set(r.primary,{native:r.primary,normalized:r.normalized||t}),r.alternatives)for(const e of r.alternatives)n.set(e,{native:e,normalized:r.normalized||t});if(e.references){for(const[t,r]of Object.entries(e.references))n.set(r,{native:r,normalized:t});for(const t of Object.keys(e.references))n.has(t)||n.set(t,{native:t,normalized:t})}if(e.roleMarkers)for(const[t,r]of Object.entries(e.roleMarkers))if(r.primary&&n.set(r.primary,{native:r.primary,normalized:t}),r.alternatives)for(const e of r.alternatives)n.set(e,{native:e,normalized:t});if(e.possessive?.keywords)for(const[t,r]of Object.entries(e.possessive.keywords))n.set(t,{native:t,normalized:r});for(const e of Dn)n.has(e)||n.set(e,{native:e,normalized:e});for(const e of t)n.set(e.native,e);this.profileKeywords=Array.from(n.values()).sort((e,t)=>t.native.length-e.native.length),this.multiWordKeywords=this.profileKeywords.filter(e=>{return(e.native.includes(" ")||(t=e.native).includes("-")&&/^[\p{L}\p{N}_]+(-[\p{L}\p{N}_]+)+$/u.test(t))&&!Bn.has(e.normalized);var t}),this.profileKeywordMap=new Map;for(const e of this.profileKeywords){this.profileKeywordMap.set(e.native.toLowerCase(),e);const t=this.removeDiacritics(e.native);t===e.native||this.profileKeywordMap.has(t.toLowerCase())||this.profileKeywordMap.set(t.toLowerCase(),e)}}removeDiacritics(e){return En(e)}tryProfileKeyword(e,t){for(const n of this.profileKeywords)if(e.slice(t).startsWith(n.native))return bn(n.native,"keyword",vn(t,t+n.native.length),n.normalized);return null}tryMultiWordKeyword(e,t,n=e=>/[\p{L}\p{N}_]/u.test(e)){if(0===this.multiWordKeywords.length)return null;const r=e.slice(t);for(const o of this.multiWordKeywords){if(!r.startsWith(o.native))continue;const s=e[t+o.native.length];if(void 0===s||!n(s))return bn(o.native,"keyword",vn(t,t+o.native.length),o.normalized)}return null}isKeywordStart(e,t){const n=e.slice(t);return this.profileKeywords.some(e=>n.startsWith(e.native))}isKeywordStartAtBoundary(e,t,n=e=>/[\p{L}\p{N}_]/u.test(e)){const r=e.slice(t);return this.profileKeywords.some(o=>{if(!r.startsWith(o.native))return!1;const s=e[t+o.native.length];return void 0===s||!n(s)})}lookupKeyword(e){const t=this.profileKeywordMap.get(e.toLowerCase());if(t)return t;const n=this.removeDiacritics(e);return n!==e?this.profileKeywordMap.get(n.toLowerCase()):void 0}isKeyword(e){return void 0!==this.lookupKeyword(e)}setNormalizer(e){this.normalizer=e}tryNormalize(e){if(!this.normalizer)return null;const t=this.normalizer.normalize(e);return t.stem===e||.7>t.confidence?null:t}tryMorphKeywordMatch(e,t,n){const r=this.tryNormalize(e);if(!r)return null;const o=this.lookupKeyword(r.stem);if(!o)return null;const s={normalized:o.normalized,stem:r.stem,stemConfidence:r.confidence};return bn(e,"keyword",vn(t,n),s)}trySelector(e,t){const n=An(e,t);return n?bn(n,"selector",vn(t,t+n.length)):null}tryEventModifier(e,t){if("."!==e[t])return null;const n=e.slice(t).match(/^\.(?:once|debounce|throttle|queue)(?:\(([^)]+)\))?(?:\s|$|\.)/);if(!n)return null;const r=n[0].replace(/(\s|\.)$/,""),o=r.slice(1).split("(")[0],s=n[1];return{...bn(r,"event-modifier",vn(t,t+r.length)),metadata:{modifierName:o,value:s?"queue"===o?s:parseInt(s,10):void 0}}}tryString(e,t){const n=$n(e,t);return n?bn(n,"literal",vn(t,t+n.length)):null}tryNumber(e,t){const n=jn(e,t);return n?bn(n,"literal",vn(t,t+n.length)):null}tryMatchTimeUnit(e,t,n,r=!1){let o=t;if(r)for(;e.length>o&&kn(e[o]);)o++;const s=e.slice(o);for(const e of n){const t=s.slice(0,e.length);if(e.caseInsensitive?t.toLowerCase()===e.pattern.toLowerCase():t===e.pattern){if(e.notFollowedBy){if((s[e.length]||"")===e.notFollowedBy)continue}if(e.checkBoundary){if(Ln(s[e.length]||""))continue}return{suffix:e.suffix,endPos:o+e.length}}}return null}parseBaseNumber(e,t,n=!0){let r=t,o="";if(!n||"-"!==e[r]&&"+"!==e[r]||(o+=e[r++]),r>=e.length||!Sn(e[r]))return null;for(;e.length>r&&Sn(e[r]);)o+=e[r++];if(e.length>r&&"."===e[r])for(o+=e[r++];e.length>r&&Sn(e[r]);)o+=e[r++];return o&&"-"!==o&&"+"!==o?{number:o,endPos:r}:null}tryNumberWithTimeUnits(t,n,r,o={}){const{allowSign:s=!0,skipWhitespace:i=!1}=o,a=this.parseBaseNumber(t,n,s);if(!a)return null;let{number:c,endPos:l}=a;const u=[...r,...e.STANDARD_TIME_UNITS],d=this.tryMatchTimeUnit(t,l,u,i);return d&&(c+=d.suffix,l=d.endPos),bn(c,"literal",vn(n,l))}tryUrl(e,t){const n=On(e,t);return n?bn(n,"url",vn(t,t+n.length)):null}tryVariableRef(e,t){if(":"!==e[t])return null;if(t+1>=e.length)return null;if(!Ln(e[t+1]))return null;let n=t+1;for(;e.length>n&&Ln(e[n]);)n++;return bn(e.slice(t,n),"identifier",vn(t,n))}tryOperator(e,t){const n=e.slice(t,t+2);if(["==","!=","<=",">=","&&","||","->"].includes(n))return bn(n,"operator",vn(t,t+2));const r=e[t];return["<",">","!","+","-","*","/","="].includes(r)?bn(r,"operator",vn(t,t+1)):["(",")","{","}",",",";",":"].includes(r)?bn(r,"punctuation",vn(t,t+1)):null}tryMultiCharParticle(e,t,n){for(const r of n)if(e.slice(t,t+r.length)===r)return bn(r,"particle",vn(t,t+r.length));return null}};zn.ASCII_WORD=/^[A-Za-z_][A-Za-z0-9_]*$/,zn.COLON_QUALIFIER=/^:[A-Za-z_][A-Za-z0-9_]*$/,zn.STANDARD_TIME_UNITS=[{pattern:"ms",suffix:"ms",length:2},{pattern:"s",suffix:"s",length:1,checkBoundary:!0},{pattern:"m",suffix:"m",length:1,checkBoundary:!0,notFollowedBy:"s"},{pattern:"h",suffix:"h",length:1,checkBoundary:!0}];var qn=zn;function Kn(e){const{language:t,direction:n="ltr",keywords:r,keywordExtras:o,keywordProfile:s,includeOperators:i=!1,caseInsensitive:a=!0,customExtractors:c}=e,l=new Set(a?r.map(e=>e.toLowerCase()):r);return new class extends qn{constructor(){super(),this.language=t,this.direction=n,c&&this.registerExtractors(c),this.registerExtractors(Wn()),s&&this.initializeKeywordsFromProfile(s,o)}classifyToken(e){const t=a?e.toLowerCase():e;return l.has(t)||this.isKeyword(e)?"keyword":/^\d/.test(e)||/^['"]/.test(e)?"literal":i&&Vn.has(e)?"operator":"identifier"}}}function Gn(e,t){const n={},r=(e,t)=>{t?.primary?n[e]={primary:t.primary,...t.alternatives?.length&&{alternatives:[...t.alternatives]},...t.position&&{position:t.position}}:delete n[e]};for(const[t,n]of Object.entries(e.roleMarkers??{}))r(t,n);for(const[e,n]of Object.entries(t.roleMarkerOverrides??{}))r(e,n);return n}function Fn(e,t){const n={};for(const[e,r]of Object.entries(t.keywords))n[e]={primary:r.primary,...r.alternatives?.length&&{alternatives:[...r.alternatives]}};const r=Gn(e,t);return{code:e.code,wordOrder:e.wordOrder,keywords:n,...Object.keys(r).length>0&&{roleMarkers:r}}}function Un(e,t,n={}){const r=Gn(e,t),o=new Set;for(const e of Object.values(t.keywords)){o.add(e.primary);for(const t of e.alternatives??[])o.add(t)}for(const e of Object.values(r)){o.add(e.primary);for(const t of e.alternatives??[])o.add(t)}for(const t of e.tokenization?.particles??[])o.add(t);for(const e of t.tokenizerKeywords??[])o.add(e);const s={};for(const[e,n]of Object.entries(t.keywords))s[e]={primary:n.primary,...n.alternatives?.length&&{alternatives:[...n.alternatives]},normalized:n.normalized??e};const i={keywords:s,...Object.keys(r).length>0&&{roleMarkers:r}},a=[...n.customExtractors??[],..."latin"===e.script?[new Qe]:[]];return Kn({language:e.code,direction:e.direction??"ltr",keywords:[...o],...t.keywordExtras?.length&&{keywordExtras:t.keywordExtras.map(e=>({...e}))},keywordProfile:i,includeOperators:n.includeOperators??!1,caseInsensitive:n.caseInsensitive??(c=e.script,void 0===c||"latin"===c||"cyrillic"===c),...a.length>0&&{customExtractors:a}});var c}function Jn(e,t,n={}){const r=n.name??e.name??e.code;return{code:e.code,name:r,nativeName:n.nativeName??e.nativeName??r,tokenizer:n.tokenizer??Un(e,t,n.tokenizerOptions),patternProfile:Fn(e,t),...n.grammarProfile&&{grammarProfile:n.grammarProfile}}}function Hn(e,t){const n={};for(const[r,o]of Object.entries(t)){const t=e.roleMarkers?.[o];t?.primary&&(n[r]=t.primary)}return n}function Zn(e){return t=>{const n=t.charCodeAt(0);return e.some(([e,t])=>n>=e&&t>=n)}}function Yn(...e){return t=>e.some(e=>e(t))}function Qn(e){const t=t=>e.test(t);return{isLetter:t,isIdentifierChar:e=>t(e)||/[0-9_-]/.test(e)}}function Xn(e){return{stem:e,confidence:1}}function er(e,t,n){return n?{stem:e,confidence:t,metadata:n}:{stem:e,confidence:t}}var tr=class{constructor(e){this.language=e.language,this.config={minWordLength:3,minStemLength:2,...e}}normalize(e){const t=e.toLowerCase();if(this.isAlreadyNormalized(t))return Xn(e);if(this.config.reflexiveSuffixes){const e=this.tryReflexiveNormalization(t);if(e)return e}if(this.config.endings){const e=this.tryConjugationEndings(t);if(e)return e}if(this.config.suffixRules){const e=this.trySuffixRules(t);if(e)return e}if(this.config.prefixRules){const e=this.tryPrefixRules(t);if(e)return e}return Xn(e)}isAlreadyNormalized(e){return!!this.config.infinitiveEndings&&this.config.infinitiveEndings.some(t=>e.endsWith(t))}tryReflexiveNormalization(e){const t=this.config.reflexiveSuffixes;if(!t)return null;for(const n of t){if(!e.endsWith(n))continue;const t=e.slice(0,-n.length);if(this.isAlreadyNormalized(t))return er(t,.88,{removedSuffixes:[n],conjugationType:"reflexive"});const r=this.tryConjugationEndings(t)||this.trySuffixRules(t);if(r&&r.stem!==t)return er(r.stem,.95*r.confidence,{removedSuffixes:[n,...r.metadata?.removedSuffixes||[]],conjugationType:"reflexive"})}return null}tryConjugationEndings(e){const t=this.config.endings;if(!t)return null;const n=this.config.minStemLength??2;for(const r of t){if(!e.endsWith(r.ending))continue;const t=e.slice(0,-r.ending.length);if(n>t.length)continue;return er(t+r.stem,r.confidence,{removedSuffixes:[r.ending],conjugationType:r.type})}return null}trySuffixRules(e){const t=this.config.suffixRules;if(!t)return null;const n=this.config.minStemLength??2;for(const r of t){if(!e.endsWith(r.pattern))continue;const t=e.slice(0,-r.pattern.length);if((r.minStemLength??n)>t.length)continue;return er(t+(r.replacement||""),r.confidence,{removedSuffixes:[r.pattern],...r.conjugationType&&{conjugationType:r.conjugationType}})}return null}tryPrefixRules(e){const t=this.config.prefixRules;if(!t)return null;for(const n of t){if(!e.startsWith(n.pattern))continue;const t=e.slice(n.pattern.length);if(t.length>=(n.minRemaining??this.config.minStemLength??2))return er(t,1-n.confidencePenalty,{removedPrefixes:[n.pattern]})}return null}};function nr(e){return e.map(e=>JSON.stringify(rr(e))).join("\n")}function rr(e){return{id:e.id,prompt:e.natural,completion:e.explicit,metadata:{domain:e.domain,action:e.action,language:e.language,source:e.source,quality:e.quality,...void 0!==e.confidence&&{confidence:e.confidence}}}}function or(e){return e.split("\n").filter(e=>e.trim().length>0).map(e=>JSON.parse(e))}function sr(e,t=.5,n=.7){return e>=t&&n>e}function ir(e,t){const n=[...t].sort((e,t)=>t.confidence-e.confidence),r=n.map((e,t)=>({action:e.action,confidence:e.confidence,explicit:z(e.node),description:e.description||`${e.action} (option ${String.fromCharCode(97+t)})`})),o=r.map((e,t)=>` (${String.fromCharCode(97+t)}) ${e.explicit} \u2014 ${e.description} (conf: ${e.confidence.toFixed(2)})`);return{input:e,candidates:r,question:[`Your input parsed with confidence ${n[0]?.confidence.toFixed(2)??"?"}.`,...o,"Which did you mean?"].join("\n")}}var ar=class{constructor(e=1e3){this.events=[],this.maxEvents=e}record(e){this.events.push(e),this.events.length>this.maxEvents&&(this.events=this.events.slice(this.events.length-this.maxEvents))}getHitRateByCommand(){return this.computeHitRate(e=>e.action)}getHitRateByLanguage(){return this.computeHitRate(e=>e.language)}getTopFailures(e=10){const t=new Map;for(const e of this.events)if("rejected"===e.outcome&&e.diagnosticCodes)for(const n of e.diagnosticCodes){const r=t.get(n)||{count:0,actions:new Set};r.count++,r.actions.add(e.action),t.set(n,r)}return Array.from(t.entries()).map(([e,{count:t,actions:n}])=>({code:e,count:t,actions:Array.from(n)})).sort((e,t)=>t.count-e.count).slice(0,e)}getSummary(){const e={};for(const t of this.events)e[t.outcome]=(e[t.outcome]||0)+1;return{totalEvents:this.events.length,byOutcome:e,byCommand:this.getHitRateByCommand(),byLanguage:this.getHitRateByLanguage(),topFailures:this.getTopFailures()}}exportJSONL(){return this.events.map(e=>JSON.stringify(e)).join("\n")}get size(){return this.events.length}clear(){this.events=[]}computeHitRate(e){const t=new Map;for(const n of this.events){const r=e(n),o=t.get(r)||{attempts:0,successes:0};o.attempts++,"accepted"===n.outcome&&o.successes++,t.set(r,o)}const n={};for(const[e,{attempts:r,successes:o}]of t)n[e]={attempts:r,successes:o,rate:r>0?o/r:0};return n}};function cr(e,t){return new lr(e,t)}var lr=class{constructor(e,t){this.dsl=e,this.config=t}parse(e,t){const n=this.splitStatements(e,t),r=[],o=[];let s;for(const e of n){const n=this.classifyLine(e.text,t);let i=e.text;if(this.config.continuation){const n=this.resolveContinuation(e.text,t,s?.category);null!==n&&(i=n)}if(this.config.preprocessor){const r=this.config.preprocessor(i,n,t,{...null!=s&&{previous:s},lineNumber:e.line,indent:e.indent});if(null===r)continue;i=r}try{const o={node:this.dsl.parse(i,t),source:e.text,line:e.line,...null!=n&&{category:n},indent:e.indent};r.push(o),s=o}catch(t){o.push({message:t instanceof Error?t.message:t+"",line:e.line,source:e.text,code:"parse-error"})}}return{statements:r,errors:o}}splitStatements(e,t){const{mode:n,trim:r=!0,commentPrefixes:o=["--","//"]}=this.config.split;if("delimiter"===n)return this.splitByDelimiter(e,t,r,o);const s=e.split("\n"),i=[];for(let e=0;s.length>e;e++){const t=s[e],n=t.length-t.trimStart().length,a=r?t.trim():t;a&&(o.some(e=>a.startsWith(e))||i.push({text:a,line:e+1,indent:n}))}return i}splitByDelimiter(e,t,n,r){const o=e.split(this.config.split.delimiters?.[t]??this.config.split.defaultDelimiter??/,\s*|\n\s*/),s=[];for(let e=0;o.length>e;e++){const t=o[e],i=n?t.trim():t;i&&(r.some(e=>i.startsWith(e))||s.push({text:i,line:e+1,indent:0}))}return s}classifyLine(e,t){if(!this.config.keywords)return;const n=e.toLowerCase(),r=this.config.keywords.wordOrders?.[t]??"SVO";for(const[e,o]of Object.entries(this.config.keywords.categories)){const s=o[t]??o.en??[];for(const t of s){const o=t.toLowerCase();if("SOV"===r){if(n.endsWith(o)||n.startsWith(o))return e}else if(n.startsWith(o))return e}}}resolveContinuation(e,t,n){if(!this.config.continuation||!n)return null;const r=this.config.continuation.keywords[t]??this.config.continuation.keywords.en??[],o=e.toLowerCase();for(const s of r){const r=s.toLowerCase();if(o.startsWith(r)){const r=e.slice(s.length).trim();if(!r)return null;if(this.config.continuation.resolve)return this.config.continuation.resolve(r,n,t,this.config.keywords?.categories??{});const o=this.config.keywords?.categories[n]?.[t]??this.config.keywords?.categories[n]?.en;return o?.[0]?o[0]+" "+r:null}}return null}};function ur(e,t){return"flat"===t.nesting?function(e,t){const n=[],r=[];let o=null;const s=()=>{o&&(n.push({type:o.type,...null!=o.name&&{name:o.name},statements:o.stmts,children:[],line:o.line,indent:o.indent}),o=null)};for(const n of e)if(n.category&&t.blockTypes.includes(n.category)){s();const e=t.extractName?.(n.source,n.category);o={type:n.category,...null!=e&&{name:e},stmts:[n],line:n.line,indent:n.indent}}else o?o.stmts.push(n):r.push(n);return s(),{blocks:n,orphans:r}}(e,t):function(e,t){const n=[],r=[],o=[],s=e=>{for(;o.length>0;){const t=o[o.length-1];if(e>t.indent)break;{o.pop();const e={type:t.type,...null!=t.name&&{name:t.name},statements:t.stmts,children:t.children,line:t.line,indent:t.indent};o.length>0?o[o.length-1].children.push(e):n.push(e)}}};for(const n of e)if(n.category&&t.blockTypes.includes(n.category)){s(n.indent);const e=t.extractName?.(n.source,n.category);o.push({type:n.category,...null!=e&&{name:e},stmts:[n],children:[],line:n.line,indent:n.indent})}else o.length>0?o[o.length-1].stmts.push(n):r.push(n);return s(-1),{blocks:n,orphans:r}}(e,t)}export{mn as AOTOrchestrator,tr as BaseMorphologicalNormalizer,qn as BaseTokenizer,cn as CrossDomainDispatcher,nt as CssSelectorExtractor,Cn as DEFAULT_OPERATORS,Rn as DEFAULT_PUNCTUATION,E as DEFAULT_REFERENCES,hn as DomainAwareScanner,Xt as DomainRegistry,qe as GrammarTransformer,Ze as IdentifierExtractor,Ke as InMemoryDictionary,Fe as InMemoryProfileProvider,Qe as LatinExtendedIdentifierExtractor,Ge as NullDictionary,Ue as NullProfileProvider,He as NumberExtractor,In as OperatorExtractor,we as PatternMatcher,ar as PatternTracker,_n as PunctuationExtractor,Je as StringLiteralExtractor,yn as TokenStreamImpl,Ye as UnicodeIdentifierExtractor,rt as WhitespaceExtractor,ur as accumulateBlocks,ir as buildDisambiguation,Un as buildDomainTokenizer,Zt as buildFeedback,Jn as buildLanguageConfig,Fn as buildPatternProfile,Ce as buildPhrase,Ie as buildTablesFromProfiles,Yn as combineClassifiers,mt as convertValue,f as createAsyncNode,i as createCommandNode,l as createCompoundNode,c as createConditionalNode,y as createDiagnosticCollector,We as createDomainRenderer,a as createEventHandlerNode,o as createExpression,s as createFlag,Qn as createLatinCharClassifiers,e as createLiteral,u as createLoopNode,p as createMatchNode,cr as createMultiStatementParser,$t as createMultilingualDSL,vn as createPosition,r as createPropertyPath,n as createReference,_e as createSchemaRenderer,t as createSelector,Kn as createSimpleTokenizer,bn as createToken,st as createTokenizerContext,d as createTryNode,Zn as createUnicodeRangeClassifier,k as defineCommand,w as defineRole,Hn as deriveRoleMarkers,Re as detectWordOrders,An as extractCssSelector,jn as extractNumber,g as extractRoleValue,$n as extractStringLiteral,On as extractUrl,h as extractValue,b as filterBySeverity,Q as fromEnvelopeJSON,v as fromError,ft as fromInterchangeNode,J as fromProtocolJSON,Ot as generateExamples,Le as generatePattern,Ne as generatePatternVariants,Nt as generatePrompt,jt as generateProtocolReference,be as getAllPossessiveKeywords,Wn as getDefaultExtractors,ye as getPossessiveReference,x as getRoleSpec,m as getRoleValue,De as insertMarkers,Ln as isAsciiIdentifierChar,Tn as isAsciiLetter,ge as isBuiltInReference,fe as isCSSPropertyRef,le as isCSSSelector,ue as isClassName,_ as isCompoundSyntax,ot as isContextAwareExtractor,Sn as isDigit,W as isDocumentSyntax,X as isEnvelope,N as isExplicitSyntax,de as isIdSelector,pe as isNumericValue,ve as isPossessiveKeyword,Mn as isPossessiveMarker,he as isPropertyName,xn as isQuote,wn as isSelectorStart,ae as isTypeCompatible,Nn as isUrlStart,T as isValidReference,me as isVariableRef,kn as isWhitespace,ze as joinTokens,ct as jsonToSemanticNode,Oe as lookupKeyword,je as lookupMarker,Ee as matchBest,Se as matchPattern,sr as needsDisambiguation,Xn as noChange,er as normalized,C as parseCompound,R as parseDocument,$ as parseExplicit,or as parseJSONL,xe as patternMatcher,gn as registryToAOTBackends,q as renderDocument,z as renderExplicit,gt as renderExpr,Be as reorderRoles,lt as semanticNodeToJSON,xt as semanticNodeToRuntimeAST,Lt as semanticValueToAST,$e as sortRolesByWordOrder,En as stripOptionalDiacritics,Kt as synthesizeFromSchemas,Y as toEnvelopeJSON,nr as toJSONL,rr as toJSONLRow,G as toProtocolJSON,se as validateProtocolJSON,at as validateSemanticJSON,ce as validateValueType,Pn as withDefaultExtractors};
|
|
2
|
-
//# sourceMappingURL=index-DQi2o8Lk.js.map
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
let t=null;async function n(){if(!t)try{t=await(import("./index-DQi2o8Lk.js"))}catch{throw Error("@lokascript/framework is required for LSE support. Install it: npm install @lokascript/framework")}return t}function r(){if(t)return!0;try{return require.resolve("@lokascript/framework"),!0}catch{return!1}}async function a(t,r){return(await n()).parseExplicit(t,r)}async function i(t){return(await n()).isExplicitSyntax(t)}async function o(t){return(await n()).renderExplicit(t)}async function e(t){return(await n()).fromInterchangeNode(t)}async function c(t){return(await n()).toProtocolJSON(t)}async function u(t){return(await n()).fromProtocolJSON(t)}async function s(t){return(await n()).validateProtocolJSON(t)}async function f(t){return(await n()).toEnvelopeJSON(t)}async function l(t){return(await n()).fromEnvelopeJSON(t)}async function w(t){return(await n()).isEnvelope(t)}async function p(t){return(await n()).semanticNodeToRuntimeAST(t)}export{l as fromEnvelopeJSON,e as fromInterchangeNode,u as fromProtocolJSON,w as isEnvelope,i as isExplicitSyntax,r as isLSEAvailable,a as parseExplicit,o as renderExplicit,p as semanticNodeToRuntimeAST,f as toEnvelopeJSON,c as toProtocolJSON,s as validateProtocolJSON};
|
|
2
|
-
//# sourceMappingURL=index-uCOQ8Qn0.js.map
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import type { ExecutionContext, TypedExecutionContext } from '../../types/core';
|
|
2
|
-
import type { ExpressionEvaluator } from '../../core/expression-evaluator';
|
|
3
|
-
import { type DecoratedCommand } from '../decorators';
|
|
4
|
-
import type { CommandRaw } from '../../ast/command-slots';
|
|
5
|
-
export interface JsCommandInput {
|
|
6
|
-
code: string;
|
|
7
|
-
parameters?: string[];
|
|
8
|
-
}
|
|
9
|
-
export interface JsCommandOutput {
|
|
10
|
-
result: unknown;
|
|
11
|
-
executed: boolean;
|
|
12
|
-
codeLength: number;
|
|
13
|
-
parameters?: string[];
|
|
14
|
-
preserveArrayResult: true;
|
|
15
|
-
}
|
|
16
|
-
export declare class JsCommand implements DecoratedCommand {
|
|
17
|
-
static readonly metadata: {
|
|
18
|
-
readonly description: "Execute inline JavaScript code with access to hyperscript context";
|
|
19
|
-
readonly syntax: readonly ["js <code> end", "js(param1, param2) <code> end"];
|
|
20
|
-
readonly examples: readonly ["js console.log(\"Hello\") end", "js(x, y) return x + y end", "js me.style.color = \"red\" end"];
|
|
21
|
-
readonly sideEffects: readonly ["code-execution", "data-mutation"];
|
|
22
|
-
readonly category: "advanced";
|
|
23
|
-
readonly compatibility: "standard";
|
|
24
|
-
};
|
|
25
|
-
get metadata(): {
|
|
26
|
-
readonly description: "Execute inline JavaScript code with access to hyperscript context";
|
|
27
|
-
readonly syntax: readonly ["js <code> end", "js(param1, param2) <code> end"];
|
|
28
|
-
readonly examples: readonly ["js console.log(\"Hello\") end", "js(x, y) return x + y end", "js me.style.color = \"red\" end"];
|
|
29
|
-
readonly sideEffects: readonly ["code-execution", "data-mutation"];
|
|
30
|
-
readonly category: "advanced";
|
|
31
|
-
readonly compatibility: "standard";
|
|
32
|
-
};
|
|
33
|
-
readonly name: string;
|
|
34
|
-
parseInput(raw: CommandRaw<'js'>, _evaluator: ExpressionEvaluator, _context: ExecutionContext): Promise<JsCommandInput>;
|
|
35
|
-
execute(input: JsCommandInput, context: TypedExecutionContext): Promise<JsCommandOutput>;
|
|
36
|
-
private createExecutionContext;
|
|
37
|
-
}
|
|
38
|
-
export declare const createJsCommand: () => JsCommand;
|
|
39
|
-
export default JsCommand;
|
|
40
|
-
//# sourceMappingURL=js.d.ts.map
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import type { ExecutionContext, TypedExecutionContext } from '../../types/core';
|
|
2
|
-
import type { ExpressionEvaluator } from '../../core/expression-evaluator';
|
|
3
|
-
import { type DecoratedCommand } from '../decorators';
|
|
4
|
-
import type { CommandRaw } from '../../ast/command-slots';
|
|
5
|
-
export interface MeasureCommandInput {
|
|
6
|
-
target?: string | HTMLElement;
|
|
7
|
-
property?: string;
|
|
8
|
-
variable?: string;
|
|
9
|
-
}
|
|
10
|
-
export interface MeasureCommandOutput {
|
|
11
|
-
result: number;
|
|
12
|
-
wasAsync: boolean;
|
|
13
|
-
element: HTMLElement;
|
|
14
|
-
property: string;
|
|
15
|
-
value: number;
|
|
16
|
-
unit: string;
|
|
17
|
-
stored?: boolean;
|
|
18
|
-
}
|
|
19
|
-
export declare class MeasureCommand implements DecoratedCommand {
|
|
20
|
-
static readonly metadata: {
|
|
21
|
-
readonly description: "Measure DOM element dimensions, positions, and properties";
|
|
22
|
-
readonly syntax: readonly ["measure", "measure <property>", "measure <target> <property>"];
|
|
23
|
-
readonly examples: readonly ["measure", "measure width", "measure #element height", "measure x and set dragX"];
|
|
24
|
-
readonly sideEffects: readonly ["data-mutation"];
|
|
25
|
-
readonly category: "animation";
|
|
26
|
-
readonly compatibility: "standard";
|
|
27
|
-
};
|
|
28
|
-
get metadata(): {
|
|
29
|
-
readonly description: "Measure DOM element dimensions, positions, and properties";
|
|
30
|
-
readonly syntax: readonly ["measure", "measure <property>", "measure <target> <property>"];
|
|
31
|
-
readonly examples: readonly ["measure", "measure width", "measure #element height", "measure x and set dragX"];
|
|
32
|
-
readonly sideEffects: readonly ["data-mutation"];
|
|
33
|
-
readonly category: "animation";
|
|
34
|
-
readonly compatibility: "standard";
|
|
35
|
-
};
|
|
36
|
-
readonly name: string;
|
|
37
|
-
parseInput(raw: CommandRaw<'measure'>, evaluator: ExpressionEvaluator, context: ExecutionContext): Promise<MeasureCommandInput>;
|
|
38
|
-
execute(input: MeasureCommandInput, context: TypedExecutionContext): Promise<MeasureCommandOutput>;
|
|
39
|
-
private getMeasurement;
|
|
40
|
-
}
|
|
41
|
-
export declare const createMeasureCommand: () => MeasureCommand;
|
|
42
|
-
export default MeasureCommand;
|
|
43
|
-
//# sourceMappingURL=measure.d.ts.map
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type { ExecutionContext, TypedExecutionContext } from '../../types/core';
|
|
2
|
-
import type { ExpressionEvaluator } from '../../core/expression-evaluator';
|
|
3
|
-
import { type DecoratedCommand } from '../decorators';
|
|
4
|
-
import type { CommandRaw } from '../../ast/command-slots';
|
|
5
|
-
export interface SettleCommandInput {
|
|
6
|
-
target?: string | HTMLElement;
|
|
7
|
-
timeout?: number | string;
|
|
8
|
-
}
|
|
9
|
-
export interface SettleCommandOutput {
|
|
10
|
-
element: HTMLElement;
|
|
11
|
-
settled: boolean;
|
|
12
|
-
timeout: number;
|
|
13
|
-
duration: number;
|
|
14
|
-
}
|
|
15
|
-
export declare class SettleCommand implements DecoratedCommand {
|
|
16
|
-
static readonly metadata: {
|
|
17
|
-
readonly description: "Wait for CSS transitions and animations to complete";
|
|
18
|
-
readonly syntax: "settle [<target>] [for <timeout>]";
|
|
19
|
-
readonly examples: readonly ["settle", "settle #animated-element", "settle for 3000"];
|
|
20
|
-
readonly sideEffects: readonly ["timing"];
|
|
21
|
-
readonly category: "animation";
|
|
22
|
-
readonly compatibility: "standard";
|
|
23
|
-
};
|
|
24
|
-
get metadata(): {
|
|
25
|
-
readonly description: "Wait for CSS transitions and animations to complete";
|
|
26
|
-
readonly syntax: "settle [<target>] [for <timeout>]";
|
|
27
|
-
readonly examples: readonly ["settle", "settle #animated-element", "settle for 3000"];
|
|
28
|
-
readonly sideEffects: readonly ["timing"];
|
|
29
|
-
readonly category: "animation";
|
|
30
|
-
readonly compatibility: "standard";
|
|
31
|
-
};
|
|
32
|
-
readonly name: string;
|
|
33
|
-
parseInput(raw: CommandRaw<'settle'>, evaluator: ExpressionEvaluator, context: ExecutionContext): Promise<SettleCommandInput>;
|
|
34
|
-
execute(input: SettleCommandInput, context: TypedExecutionContext): Promise<SettleCommandOutput>;
|
|
35
|
-
}
|
|
36
|
-
export declare const createSettleCommand: () => SettleCommand;
|
|
37
|
-
export default SettleCommand;
|
|
38
|
-
//# sourceMappingURL=settle.d.ts.map
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type { ExecutionSignal } from '../../types/result';
|
|
2
|
-
import type { Op } from '../../types/program';
|
|
3
|
-
import type { ExecutionContext, TypedExecutionContext } from '../../types/core';
|
|
4
|
-
import type { ExpressionEvaluator } from '../../core/expression-evaluator';
|
|
5
|
-
import { type DecoratedCommand } from '../decorators';
|
|
6
|
-
import type { CommandRaw } from '../../ast/command-slots';
|
|
7
|
-
export interface StartViewTransitionInput {
|
|
8
|
-
transitionName?: string;
|
|
9
|
-
body: Op[];
|
|
10
|
-
}
|
|
11
|
-
export interface StartViewTransitionOutput {
|
|
12
|
-
usedViewTransition: boolean;
|
|
13
|
-
commandsExecuted: number;
|
|
14
|
-
}
|
|
15
|
-
export declare class StartViewTransitionCommand implements DecoratedCommand {
|
|
16
|
-
static readonly metadata: {
|
|
17
|
-
readonly description: "Wrap a block of commands in document.startViewTransition()";
|
|
18
|
-
readonly syntax: readonly ["start view transition [using <type>] <body> end"];
|
|
19
|
-
readonly examples: readonly ["start view transition add .highlight to me end", "start view transition using \"slide\" add .active to #panel end", "start view transition using \"slide\" then put result into #panel end"];
|
|
20
|
-
readonly sideEffects: readonly ["animation", "dom-mutation"];
|
|
21
|
-
readonly category: "animation";
|
|
22
|
-
readonly compatibility: "standard";
|
|
23
|
-
};
|
|
24
|
-
get metadata(): {
|
|
25
|
-
readonly description: "Wrap a block of commands in document.startViewTransition()";
|
|
26
|
-
readonly syntax: readonly ["start view transition [using <type>] <body> end"];
|
|
27
|
-
readonly examples: readonly ["start view transition add .highlight to me end", "start view transition using \"slide\" add .active to #panel end", "start view transition using \"slide\" then put result into #panel end"];
|
|
28
|
-
readonly sideEffects: readonly ["animation", "dom-mutation"];
|
|
29
|
-
readonly category: "animation";
|
|
30
|
-
readonly compatibility: "standard";
|
|
31
|
-
};
|
|
32
|
-
readonly name: string;
|
|
33
|
-
parseInput(raw: CommandRaw<'start'>, evaluator: ExpressionEvaluator, context: ExecutionContext): Promise<StartViewTransitionInput>;
|
|
34
|
-
execute(input: StartViewTransitionInput, context: TypedExecutionContext): Promise<StartViewTransitionOutput | ExecutionSignal>;
|
|
35
|
-
}
|
|
36
|
-
export declare const createStartViewTransitionCommand: () => StartViewTransitionCommand;
|
|
37
|
-
export default StartViewTransitionCommand;
|
|
38
|
-
//# sourceMappingURL=start-view-transition.d.ts.map
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import type { ExecutionContext, TypedExecutionContext } from '../../types/core';
|
|
2
|
-
import type { ExpressionEvaluator } from '../../core/expression-evaluator';
|
|
3
|
-
import { type DecoratedCommand } from '../decorators';
|
|
4
|
-
import type { CommandRaw } from '../../ast/command-slots';
|
|
5
|
-
export interface TakeCommandInput {
|
|
6
|
-
property: string;
|
|
7
|
-
source?: unknown;
|
|
8
|
-
target?: unknown;
|
|
9
|
-
}
|
|
10
|
-
export interface TakeCommandOutput {
|
|
11
|
-
targetElement: HTMLElement;
|
|
12
|
-
property: string;
|
|
13
|
-
value: unknown;
|
|
14
|
-
}
|
|
15
|
-
export declare class TakeCommand implements DecoratedCommand {
|
|
16
|
-
static readonly metadata: {
|
|
17
|
-
readonly description: "Move classes, attributes, and properties from one element to another";
|
|
18
|
-
readonly syntax: readonly ["take <class> [from <source>] [for <recipient>]", "take <property> from <source>", "take <property> from <source> and put it on <target>"];
|
|
19
|
-
readonly examples: readonly ["take .active from .tab for me", "take class from <#source/>", "take @data-value from <.source/> and put it on <#target/>"];
|
|
20
|
-
readonly sideEffects: readonly ["dom-mutation", "property-transfer"];
|
|
21
|
-
readonly category: "animation";
|
|
22
|
-
readonly compatibility: "standard";
|
|
23
|
-
};
|
|
24
|
-
get metadata(): {
|
|
25
|
-
readonly description: "Move classes, attributes, and properties from one element to another";
|
|
26
|
-
readonly syntax: readonly ["take <class> [from <source>] [for <recipient>]", "take <property> from <source>", "take <property> from <source> and put it on <target>"];
|
|
27
|
-
readonly examples: readonly ["take .active from .tab for me", "take class from <#source/>", "take @data-value from <.source/> and put it on <#target/>"];
|
|
28
|
-
readonly sideEffects: readonly ["dom-mutation", "property-transfer"];
|
|
29
|
-
readonly category: "animation";
|
|
30
|
-
readonly compatibility: "standard";
|
|
31
|
-
};
|
|
32
|
-
readonly name: string;
|
|
33
|
-
parseInput(raw: CommandRaw<'take'>, evaluator: ExpressionEvaluator, context: ExecutionContext): Promise<TakeCommandInput>;
|
|
34
|
-
execute(input: TakeCommandInput, context: TypedExecutionContext): Promise<TakeCommandOutput>;
|
|
35
|
-
private firstOf;
|
|
36
|
-
private takeProperty;
|
|
37
|
-
private putProperty;
|
|
38
|
-
}
|
|
39
|
-
export declare const createTakeCommand: () => TakeCommand;
|
|
40
|
-
export default TakeCommand;
|
|
41
|
-
//# sourceMappingURL=take.d.ts.map
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import type { ExecutionContext, TypedExecutionContext } from '../../types/core';
|
|
2
|
-
import type { ExpressionEvaluator } from '../../core/expression-evaluator';
|
|
3
|
-
import { type DecoratedCommand } from '../decorators';
|
|
4
|
-
import type { CommandRaw } from '../../ast/command-slots';
|
|
5
|
-
export interface TransitionPairInput {
|
|
6
|
-
target?: string | HTMLElement | HTMLElement[];
|
|
7
|
-
property: string;
|
|
8
|
-
value: string | number;
|
|
9
|
-
from?: string | number;
|
|
10
|
-
}
|
|
11
|
-
export interface TransitionCommandInput extends TransitionPairInput {
|
|
12
|
-
duration?: number | string;
|
|
13
|
-
timingFunction?: string;
|
|
14
|
-
using?: string;
|
|
15
|
-
pairs?: TransitionPairInput[];
|
|
16
|
-
}
|
|
17
|
-
export interface TransitionCommandOutput {
|
|
18
|
-
element: HTMLElement;
|
|
19
|
-
property: string;
|
|
20
|
-
fromValue: string;
|
|
21
|
-
toValue: string;
|
|
22
|
-
duration: number;
|
|
23
|
-
completed: boolean;
|
|
24
|
-
}
|
|
25
|
-
export declare class TransitionCommand implements DecoratedCommand {
|
|
26
|
-
static readonly metadata: {
|
|
27
|
-
readonly description: "Animate CSS properties using CSS transitions";
|
|
28
|
-
readonly syntax: "transition <property> [from <value>] to <value> [<property> … to <value>]… [over <duration>] [using <css> | with <timing>]";
|
|
29
|
-
readonly examples: readonly ["transition opacity to 0.5", "transition my *opacity to 0 over 200ms", "transition #box's *opacity to 0 over 200ms", "transition left to 100px over 500ms", "transition background-color to red over 1s with ease-in-out", "transition *width to 100px *height to 50px over 300ms", "transition *opacity of #panel from 0 to 1 over 200ms", "transition my *opacity to 0 using \"opacity 1s ease-in\""];
|
|
30
|
-
readonly sideEffects: readonly ["style-change", "timing"];
|
|
31
|
-
readonly category: "animation";
|
|
32
|
-
readonly compatibility: "standard";
|
|
33
|
-
};
|
|
34
|
-
get metadata(): {
|
|
35
|
-
readonly description: "Animate CSS properties using CSS transitions";
|
|
36
|
-
readonly syntax: "transition <property> [from <value>] to <value> [<property> … to <value>]… [over <duration>] [using <css> | with <timing>]";
|
|
37
|
-
readonly examples: readonly ["transition opacity to 0.5", "transition my *opacity to 0 over 200ms", "transition #box's *opacity to 0 over 200ms", "transition left to 100px over 500ms", "transition background-color to red over 1s with ease-in-out", "transition *width to 100px *height to 50px over 300ms", "transition *opacity of #panel from 0 to 1 over 200ms", "transition my *opacity to 0 using \"opacity 1s ease-in\""];
|
|
38
|
-
readonly sideEffects: readonly ["style-change", "timing"];
|
|
39
|
-
readonly category: "animation";
|
|
40
|
-
readonly compatibility: "standard";
|
|
41
|
-
};
|
|
42
|
-
readonly name: string;
|
|
43
|
-
parseInput(raw: CommandRaw<'transition'>, evaluator: ExpressionEvaluator, context: ExecutionContext): Promise<TransitionCommandInput>;
|
|
44
|
-
private laterPairs;
|
|
45
|
-
execute(input: TransitionCommandInput, context: TypedExecutionContext): Promise<TransitionCommandOutput>;
|
|
46
|
-
}
|
|
47
|
-
export declare const createTransitionCommand: () => TransitionCommand;
|
|
48
|
-
export default TransitionCommand;
|
|
49
|
-
//# sourceMappingURL=transition.d.ts.map
|