@hyperfixi/core 2.6.0 → 2.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/dist/api/hyperscript-api.d.ts +6 -0
  2. package/dist/ast-utils/index.js +8 -8
  3. package/dist/ast-utils/index.mjs +8 -8
  4. package/dist/bundle-generator/index.js +12 -4
  5. package/dist/bundle-generator/index.mjs +12 -4
  6. package/dist/chunks/{bridge-fFLEvCQs.js → bridge-lZbOVRDD.js} +2 -2
  7. package/dist/chunks/browser-modular-DegkWQ8d.js +2 -0
  8. package/dist/chunks/{index-BRgVy8nY.js → index-i_j9Z-1e.js} +2 -2
  9. package/dist/commands/data/set.d.ts +1 -0
  10. package/dist/commands/index.js +156 -47
  11. package/dist/commands/index.mjs +156 -47
  12. package/dist/core/context.d.ts +4 -0
  13. package/dist/dom/attribute-processor.d.ts +1 -0
  14. package/dist/hyperfixi-browser-classic-i18n.js +1 -1
  15. package/dist/hyperfixi-browser-minimal.js +1 -1
  16. package/dist/hyperfixi-browser-standard.js +1 -1
  17. package/dist/hyperfixi-browser.js +1 -1
  18. package/dist/hyperfixi-classic-i18n.js +1 -1
  19. package/dist/hyperfixi-hx-v4.js +1 -1
  20. package/dist/hyperfixi-hx.js +1 -1
  21. package/dist/hyperfixi-hybrid-complete.js +1 -1
  22. package/dist/hyperfixi-hybrid-hx.js +1 -1
  23. package/dist/hyperfixi-lite-plus.js +1 -1
  24. package/dist/hyperfixi-lite.js +1 -1
  25. package/dist/hyperfixi-minimal.js +1 -1
  26. package/dist/hyperfixi-multilingual.js +1 -1
  27. package/dist/hyperfixi-standard.js +1 -1
  28. package/dist/hyperfixi.js +1 -1
  29. package/dist/hyperfixi.mjs +1 -1
  30. package/dist/index.d.ts +1 -1
  31. package/dist/index.js +694 -459
  32. package/dist/index.min.js +1 -1
  33. package/dist/index.mjs +691 -460
  34. package/dist/lokascript-browser-classic-i18n.js +1 -1
  35. package/dist/lokascript-browser-minimal.js +1 -1
  36. package/dist/lokascript-browser-standard.js +1 -1
  37. package/dist/lokascript-browser.js +1 -1
  38. package/dist/lokascript-hybrid-complete.js +1 -1
  39. package/dist/lokascript-hybrid-hx.js +1 -1
  40. package/dist/lokascript-lite-plus.js +1 -1
  41. package/dist/lokascript-lite.js +1 -1
  42. package/dist/lokascript-multilingual.js +1 -1
  43. package/dist/parser/full-parser.js +70 -35
  44. package/dist/parser/full-parser.mjs +70 -35
  45. package/dist/parser/parser-types.d.ts +1 -1
  46. package/dist/parser/parser.d.ts +2 -0
  47. package/dist/parser/regex-parser.js +23 -14
  48. package/dist/parser/regex-parser.mjs +23 -14
  49. package/dist/registry/index.js +178 -45
  50. package/dist/registry/index.mjs +178 -45
  51. package/dist/types/core-context.d.ts +1 -0
  52. package/package.json +6 -6
  53. package/dist/chunks/browser-modular-BK3IOo93.js +0 -2
  54. package/dist/compatibility/browser-bundle.d.ts +0 -164
package/dist/index.mjs CHANGED
@@ -4224,7 +4224,7 @@ function parseColonVariable(ctx) {
4224
4224
  return {
4225
4225
  type: 'identifier',
4226
4226
  name: varToken.value,
4227
- scope: 'local',
4227
+ scope: 'element',
4228
4228
  start: varToken.start - 1,
4229
4229
  end: varToken.end,
4230
4230
  };
@@ -4276,7 +4276,7 @@ function parseTargetFallback(ctx) {
4276
4276
  expression: {
4277
4277
  type: 'identifier',
4278
4278
  name: varToken.value,
4279
- scope: 'local',
4279
+ scope: 'element',
4280
4280
  start: varToken.start,
4281
4281
  end: varToken.end,
4282
4282
  },
@@ -4357,6 +4357,11 @@ function parseSetCommand(ctx, identifierNode) {
4357
4357
  }
4358
4358
  ctx.advance();
4359
4359
  const value = ctx.parseExpression() ?? ctx.parsePrimary();
4360
+ let scopeTarget;
4361
+ if (ctx.check(KEYWORDS$1.ON) && tokenLooksLikeElementTarget(ctx.peekAt(1))) {
4362
+ ctx.advance();
4363
+ scopeTarget = parseOneArgument(ctx);
4364
+ }
4360
4365
  const finalArgs = [];
4361
4366
  if (targetExpression) {
4362
4367
  finalArgs.push(targetExpression);
@@ -4368,11 +4373,22 @@ function parseSetCommand(ctx, identifierNode) {
4368
4373
  if (value) {
4369
4374
  finalArgs.push(value);
4370
4375
  }
4371
- return CommandNodeBuilder.fromIdentifier(identifierNode)
4372
- .withArgs(...finalArgs)
4373
- .endingAt(ctx.getPosition())
4374
- .build();
4376
+ const builder = CommandNodeBuilder.fromIdentifier(identifierNode).withArgs(...finalArgs);
4377
+ if (scopeTarget) {
4378
+ builder.withModifier('on', scopeTarget);
4379
+ }
4380
+ return builder.endingAt(ctx.getPosition()).build();
4381
+ }
4382
+ function tokenLooksLikeElementTarget(token) {
4383
+ if (!token)
4384
+ return false;
4385
+ if (token.kind === 'selector')
4386
+ return true;
4387
+ if (token.value.startsWith('<'))
4388
+ return true;
4389
+ return ELEMENT_PRONOUNS.has(token.value);
4375
4390
  }
4391
+ const ELEMENT_PRONOUNS = new Set(['me', 'my', 'it', 'its', 'you', 'your', 'yourself']);
4376
4392
  function parseIncrementDecrementCommand(ctx, commandToken) {
4377
4393
  const commandName = commandToken.value;
4378
4394
  const isIncrement = commandName === 'increment';
@@ -4418,6 +4434,7 @@ function parseIncrementDecrementCommand(ctx, commandToken) {
4418
4434
  column: commandToken.column,
4419
4435
  };
4420
4436
  const binaryExpr = createBinaryExpression(operator, target, amount, pos);
4437
+ binaryExpr.coerceNumeric = true;
4421
4438
  const toIdentifier = createIdentifier(KEYWORDS$1.TO, pos);
4422
4439
  const args = [targetWithScope, toIdentifier, binaryExpr];
4423
4440
  return CommandNodeBuilder.from(commandToken)
@@ -5036,6 +5053,18 @@ class Parser {
5036
5053
  this.advance();
5037
5054
  continue;
5038
5055
  }
5056
+ if (this.check('then')) {
5057
+ const next = this.peekAt(1);
5058
+ const startsFeature = next !== null &&
5059
+ (next.value === 'init' ||
5060
+ next.value === 'on' ||
5061
+ next.value === 'def' ||
5062
+ getRegisteredFeature(next.value) !== undefined);
5063
+ if (startsFeature) {
5064
+ this.advance();
5065
+ continue;
5066
+ }
5067
+ }
5039
5068
  if (this.check('init')) {
5040
5069
  this.advance();
5041
5070
  const initBlock = this.parseTopLevelInitBlock();
@@ -5836,7 +5865,7 @@ class Parser {
5836
5865
  return {
5837
5866
  type: 'identifier',
5838
5867
  name: varToken.value,
5839
- scope: 'local',
5868
+ scope: 'element',
5840
5869
  start: varToken.start - 1,
5841
5870
  end: varToken.end,
5842
5871
  line: varToken.line,
@@ -6463,6 +6492,33 @@ class Parser {
6463
6492
  return null;
6464
6493
  }
6465
6494
  }
6495
+ parseTemporalKeywordModifiers(modifiers) {
6496
+ if (!this.check('debounced') && !this.check('throttled')) {
6497
+ return;
6498
+ }
6499
+ const modToken = this.advance();
6500
+ const modName = modToken.value.toLowerCase();
6501
+ const modifierKey = modName === 'debounced' ? 'debounce' : 'throttle';
6502
+ if (this.match('at')) {
6503
+ if (this.checkTimeExpression()) {
6504
+ const timeToken = this.advance();
6505
+ const delayMs = parseTimeToMs(timeToken.value);
6506
+ modifiers[modifierKey] = delayMs;
6507
+ debug.parse(`🔧 parseEventHandler: Parsed '${modName} at ${timeToken.value}' (${delayMs}ms)`);
6508
+ }
6509
+ else if (this.matchNumber()) {
6510
+ const delayMs = parseInt(this.previous().value, 10);
6511
+ modifiers[modifierKey] = delayMs;
6512
+ debug.parse(`🔧 parseEventHandler: Parsed '${modName} at ${delayMs}'`);
6513
+ }
6514
+ else {
6515
+ this.addError(`Expected time expression after '${modName} at', got: ${this.peek().value}`);
6516
+ }
6517
+ }
6518
+ else {
6519
+ this.addError(`Expected 'at' after '${modName}'`);
6520
+ }
6521
+ }
6466
6522
  parseEventHandler() {
6467
6523
  debug.parse(`🔧 parseEventHandler: ENTRY - parsing event handler`);
6468
6524
  const eventNames = [];
@@ -6550,30 +6606,7 @@ class Parser {
6550
6606
  debug.parse(`🔧 parseEventHandler: Warning - unknown modifier '.${modName}'`);
6551
6607
  }
6552
6608
  }
6553
- if (this.check('debounced') || this.check('throttled')) {
6554
- const modToken = this.advance();
6555
- const modName = modToken.value.toLowerCase();
6556
- const modifierKey = modName === 'debounced' ? 'debounce' : 'throttle';
6557
- if (this.match('at')) {
6558
- if (this.checkTimeExpression()) {
6559
- const timeToken = this.advance();
6560
- const delayMs = parseTimeToMs(timeToken.value);
6561
- modifiers[modifierKey] = delayMs;
6562
- debug.parse(`🔧 parseEventHandler: Parsed '${modName} at ${timeToken.value}' (${delayMs}ms)`);
6563
- }
6564
- else if (this.matchNumber()) {
6565
- const delayMs = parseInt(this.previous().value, 10);
6566
- modifiers[modifierKey] = delayMs;
6567
- debug.parse(`🔧 parseEventHandler: Parsed '${modName} at ${delayMs}'`);
6568
- }
6569
- else {
6570
- this.addError(`Expected time expression after '${modName} at', got: ${this.peek().value}`);
6571
- }
6572
- }
6573
- else {
6574
- this.addError(`Expected 'at' after '${modName}'`);
6575
- }
6576
- }
6609
+ this.parseTemporalKeywordModifiers(modifiers);
6577
6610
  if (firstOnceAlias) {
6578
6611
  modifiers.once = true;
6579
6612
  }
@@ -6590,6 +6623,7 @@ class Parser {
6590
6623
  const targetToken = this.advance();
6591
6624
  target = targetToken.value;
6592
6625
  debug.parse(`🔧 parseEventHandler: Parsed 'from' target: ${target} (kind: ${targetToken.kind})`);
6626
+ this.parseTemporalKeywordModifiers(modifiers);
6593
6627
  }
6594
6628
  let attributeName;
6595
6629
  if (this.match('of')) {
@@ -7560,6 +7594,10 @@ class Parser {
7560
7594
  }
7561
7595
  return this.tokens[this.current];
7562
7596
  }
7597
+ peekAt(offset) {
7598
+ const index = this.current + offset;
7599
+ return index >= 0 && index < this.tokens.length ? this.tokens[index] : null;
7600
+ }
7563
7601
  previous() {
7564
7602
  return this.tokens[this.current - 1];
7565
7603
  }
@@ -7764,10 +7802,7 @@ class Parser {
7764
7802
  restorePosition: (pos) => {
7765
7803
  parser.current = pos;
7766
7804
  },
7767
- peekAt: (offset) => {
7768
- const index = parser.current + offset;
7769
- return index >= 0 && index < parser.tokens.length ? parser.tokens[index] : null;
7770
- },
7805
+ peekAt: (offset) => parser.peekAt(offset),
7771
7806
  getInputSlice: (start, end) => {
7772
7807
  if (!this.originalInput)
7773
7808
  return '';
@@ -7916,6 +7951,334 @@ function isOk(result) {
7916
7951
  return result.ok === true;
7917
7952
  }
7918
7953
 
7954
+ const sharedGlobals = new Map();
7955
+ const elementScopes = new WeakMap();
7956
+ function getElementScopeMap(element) {
7957
+ let map = elementScopes.get(element);
7958
+ if (!map) {
7959
+ map = new Map();
7960
+ elementScopes.set(element, map);
7961
+ }
7962
+ return map;
7963
+ }
7964
+ function resolveScopeOwner(context) {
7965
+ const owner = context.owner;
7966
+ if (owner)
7967
+ return owner;
7968
+ return context.me instanceof Element ? context.me : null;
7969
+ }
7970
+ function getElementVar(context, name) {
7971
+ const owner = resolveScopeOwner(context);
7972
+ if (!owner)
7973
+ return undefined;
7974
+ notifyLocalRead(name, context);
7975
+ return getElementScopeMap(owner).get(name);
7976
+ }
7977
+ function setElementVar(context, name, value) {
7978
+ const owner = resolveScopeOwner(context);
7979
+ if (!owner)
7980
+ return;
7981
+ getElementScopeMap(owner).set(name, value);
7982
+ notifyLocalWrite(name, value, context);
7983
+ }
7984
+ function createContext(element, globals) {
7985
+ return {
7986
+ me: element ?? null,
7987
+ owner: element ?? null,
7988
+ it: null,
7989
+ you: null,
7990
+ result: null,
7991
+ locals: new Map(),
7992
+ globals: globals || sharedGlobals,
7993
+ flags: {
7994
+ halted: false,
7995
+ breaking: false,
7996
+ continuing: false,
7997
+ returning: false,
7998
+ async: false,
7999
+ },
8000
+ };
8001
+ }
8002
+ function getSharedGlobals() {
8003
+ return sharedGlobals;
8004
+ }
8005
+ function createChildContext(parent, element) {
8006
+ return {
8007
+ me: element ?? parent.me,
8008
+ owner: parent.owner ?? parent.me ?? element ?? null,
8009
+ it: null,
8010
+ you: null,
8011
+ result: null,
8012
+ locals: new Map(),
8013
+ globals: parent.globals,
8014
+ parent,
8015
+ flags: {
8016
+ halted: false,
8017
+ breaking: false,
8018
+ continuing: false,
8019
+ returning: false,
8020
+ async: false,
8021
+ },
8022
+ };
8023
+ }
8024
+
8025
+ function isHTMLElement$2(value) {
8026
+ return (value !== null &&
8027
+ typeof value === 'object' &&
8028
+ 'nodeType' in value &&
8029
+ value.nodeType === 1 &&
8030
+ 'tagName' in value &&
8031
+ typeof value.tagName === 'string' &&
8032
+ 'classList' in value);
8033
+ }
8034
+ function isNodeList(value) {
8035
+ return (value !== null &&
8036
+ typeof value === 'object' &&
8037
+ 'length' in value &&
8038
+ typeof value.length === 'number' &&
8039
+ (Symbol.iterator in value || typeof value.item === 'function'));
8040
+ }
8041
+ function isDocumentFragment(value) {
8042
+ return (value !== null &&
8043
+ typeof value === 'object' &&
8044
+ 'nodeType' in value &&
8045
+ value.nodeType === 11 &&
8046
+ 'childNodes' in value);
8047
+ }
8048
+
8049
+ function convertToNumber(value) {
8050
+ if (value === null || value === undefined) {
8051
+ return 0;
8052
+ }
8053
+ if (typeof value === 'number') {
8054
+ return isFinite(value) ? value : 0;
8055
+ }
8056
+ if (typeof value === 'string') {
8057
+ const parsed = parseFloat(value);
8058
+ return parsed;
8059
+ }
8060
+ if (typeof value === 'boolean') {
8061
+ return value ? 1 : 0;
8062
+ }
8063
+ if (Array.isArray(value)) {
8064
+ return value.length;
8065
+ }
8066
+ if (typeof value === 'object') {
8067
+ if ('length' in value && typeof value.length === 'number') {
8068
+ return value.length;
8069
+ }
8070
+ if (typeof value.valueOf === 'function') {
8071
+ const result = value.valueOf();
8072
+ if (typeof result === 'number') {
8073
+ return result;
8074
+ }
8075
+ }
8076
+ return NaN;
8077
+ }
8078
+ return 0;
8079
+ }
8080
+ function getVariableValue(name, context, preferredScope) {
8081
+ if (preferredScope === 'element') {
8082
+ return getElementVar(context, name);
8083
+ }
8084
+ if (preferredScope === 'global' && context.globals && context.globals.has(name)) {
8085
+ return context.globals.get(name);
8086
+ }
8087
+ if (preferredScope !== 'global' && context.locals && context.locals.has(name)) {
8088
+ notifyLocalRead(name, context);
8089
+ return context.locals.get(name);
8090
+ }
8091
+ if (context.globals && context.globals.has(name)) {
8092
+ return context.globals.get(name);
8093
+ }
8094
+ if (context.variables && context.variables.has(name)) {
8095
+ return context.variables.get(name);
8096
+ }
8097
+ if (preferredScope === 'global' && context.locals && context.locals.has(name)) {
8098
+ notifyLocalRead(name, context);
8099
+ return context.locals.get(name);
8100
+ }
8101
+ if (typeof window !== 'undefined' && name in window) {
8102
+ return window[name];
8103
+ }
8104
+ if (typeof globalThis !== 'undefined' && name in globalThis) {
8105
+ return globalThis[name];
8106
+ }
8107
+ return undefined;
8108
+ }
8109
+ function setVariableValue(name, value, context, preferredScope) {
8110
+ if (preferredScope === 'element') {
8111
+ setElementVar(context, name, value);
8112
+ return;
8113
+ }
8114
+ if (preferredScope === 'global') {
8115
+ setGlobal(context, name, value);
8116
+ if (typeof window !== 'undefined') {
8117
+ window[name] = value;
8118
+ }
8119
+ return;
8120
+ }
8121
+ if (name.startsWith('$')) {
8122
+ const bare = name.slice(1);
8123
+ setGlobal(context, bare, value);
8124
+ return;
8125
+ }
8126
+ if (context.locals && context.locals.has(name)) {
8127
+ context.locals.set(name, value);
8128
+ notifyLocalWrite(name, value, context);
8129
+ return;
8130
+ }
8131
+ if (context.globals && context.globals.has(name)) {
8132
+ setGlobal(context, name, value);
8133
+ if (typeof window !== 'undefined' && name in window) {
8134
+ window[name] = value;
8135
+ }
8136
+ return;
8137
+ }
8138
+ if (context.variables && context.variables.has(name)) {
8139
+ context.variables.set(name, value);
8140
+ return;
8141
+ }
8142
+ if (typeof window !== 'undefined' && name in window) {
8143
+ window[name] = value;
8144
+ setGlobal(context, name, value);
8145
+ return;
8146
+ }
8147
+ context.locals.set(name, value);
8148
+ notifyLocalWrite(name, value, context);
8149
+ }
8150
+ function resolveElementRef(elementRef, context) {
8151
+ if (elementRef === 'me') {
8152
+ return context.me;
8153
+ }
8154
+ else if (elementRef === 'it') {
8155
+ return context.it;
8156
+ }
8157
+ else if (elementRef === 'you') {
8158
+ return context.you;
8159
+ }
8160
+ else {
8161
+ return getVariableValue(elementRef, context);
8162
+ }
8163
+ }
8164
+ function getElementPropertyValue(propertyPath, context) {
8165
+ const parts = propertyPath.split('.');
8166
+ const elementRef = parts[0];
8167
+ const property = parts[1];
8168
+ const element = resolveElementRef(elementRef, context);
8169
+ if (!element) {
8170
+ return 0;
8171
+ }
8172
+ const value = element[property];
8173
+ return convertToNumber(value);
8174
+ }
8175
+ function setElementPropertyValue(propertyPath, value, context) {
8176
+ const parts = propertyPath.split('.');
8177
+ const elementRef = parts[0];
8178
+ const property = parts[1];
8179
+ const element = resolveElementRef(elementRef, context);
8180
+ if (element) {
8181
+ element[property] = value;
8182
+ }
8183
+ }
8184
+ function getCurrentNumericValue(target, property, scope, context) {
8185
+ if (typeof target === 'number') {
8186
+ return target;
8187
+ }
8188
+ if (isHTMLElement$2(target)) {
8189
+ const element = target;
8190
+ if (property) {
8191
+ if (property.startsWith('data-') ||
8192
+ ['id', 'class', 'title', 'alt', 'src', 'href'].includes(property)) {
8193
+ const value = element.getAttribute(property);
8194
+ return convertToNumber(value);
8195
+ }
8196
+ else {
8197
+ const value = element[property];
8198
+ return convertToNumber(value);
8199
+ }
8200
+ }
8201
+ else {
8202
+ const value = element.value || element.textContent;
8203
+ return convertToNumber(value);
8204
+ }
8205
+ }
8206
+ if (typeof target === 'string') {
8207
+ if (scope === 'element') {
8208
+ return convertToNumber(getVariableValue(target, context, 'element'));
8209
+ }
8210
+ if (scope === 'global') {
8211
+ const value = getVariableValue(target, context, 'global');
8212
+ return convertToNumber(value);
8213
+ }
8214
+ if (target.includes('.')) {
8215
+ return getElementPropertyValue(target, context);
8216
+ }
8217
+ if (target === 'me' && context.me) {
8218
+ return convertToNumber(context.me.value || 0);
8219
+ }
8220
+ else if (target === 'it') {
8221
+ return convertToNumber(context.it || 0);
8222
+ }
8223
+ else if (target === 'you' && context.you) {
8224
+ return convertToNumber(context.you.value || 0);
8225
+ }
8226
+ const value = getVariableValue(target, context);
8227
+ return convertToNumber(value);
8228
+ }
8229
+ return convertToNumber(target);
8230
+ }
8231
+ function setTargetValue(target, property, scope, newValue, context) {
8232
+ if (isHTMLElement$2(target)) {
8233
+ const element = target;
8234
+ if (property) {
8235
+ if (property.startsWith('data-') ||
8236
+ ['id', 'class', 'title', 'alt', 'src', 'href'].includes(property)) {
8237
+ element.setAttribute(property, String(newValue));
8238
+ }
8239
+ else {
8240
+ element[property] = newValue;
8241
+ }
8242
+ }
8243
+ else {
8244
+ if ('value' in element && element.value !== undefined) {
8245
+ element.value = String(newValue);
8246
+ }
8247
+ else {
8248
+ element.textContent = String(newValue);
8249
+ }
8250
+ }
8251
+ return;
8252
+ }
8253
+ if (typeof target === 'string') {
8254
+ if (scope === 'element') {
8255
+ setVariableValue(target, newValue, context, 'element');
8256
+ return;
8257
+ }
8258
+ if (scope === 'global') {
8259
+ setVariableValue(target, newValue, context, 'global');
8260
+ return;
8261
+ }
8262
+ if (target.includes('.')) {
8263
+ setElementPropertyValue(target, newValue, context);
8264
+ return;
8265
+ }
8266
+ if (target === 'me' && context.me) {
8267
+ context.me.value = newValue;
8268
+ return;
8269
+ }
8270
+ else if (target === 'it') {
8271
+ Object.assign(context, { it: newValue });
8272
+ return;
8273
+ }
8274
+ else if (target === 'you' && context.you) {
8275
+ context.you.value = newValue;
8276
+ return;
8277
+ }
8278
+ setVariableValue(target, newValue, context);
8279
+ }
8280
+ }
8281
+
7919
8282
  class ExpressionTypeRegistry {
7920
8283
  constructor(config = {}) {
7921
8284
  this.types = new Map();
@@ -8279,7 +8642,7 @@ function isFormElement$1(el) {
8279
8642
  const tag = el.tagName;
8280
8643
  return tag === 'INPUT' || tag === 'SELECT' || tag === 'TEXTAREA';
8281
8644
  }
8282
- function isHTMLElement$2(el) {
8645
+ function isHTMLElement$1(el) {
8283
8646
  return (el !== null &&
8284
8647
  typeof el === 'object' &&
8285
8648
  'nodeType' in el &&
@@ -8297,7 +8660,7 @@ function isOptionElement$1(el) {
8297
8660
  function isElement(value) {
8298
8661
  return value instanceof Element;
8299
8662
  }
8300
- function isHTMLElement$1(value) {
8663
+ function isHTMLElement(value) {
8301
8664
  return value instanceof HTMLElement;
8302
8665
  }
8303
8666
  const BOOLEAN_ATTRIBUTES = new Set([
@@ -8342,8 +8705,8 @@ const SPECIAL_DOM_PROPERTIES = {
8342
8705
  checked: el => (isInputElement$1(el) ? el.checked : undefined),
8343
8706
  disabled: el => ('disabled' in el ? el.disabled : undefined),
8344
8707
  selected: el => (isOptionElement$1(el) ? el.selected : undefined),
8345
- tabindex: el => (isHTMLElement$2(el) ? el.tabIndex : undefined),
8346
- hidden: el => (isHTMLElement$2(el) ? el.hidden : undefined),
8708
+ tabindex: el => (isHTMLElement$1(el) ? el.tabIndex : undefined),
8709
+ hidden: el => (isHTMLElement$1(el) ? el.hidden : undefined),
8347
8710
  style: el => getComputedStyle(el),
8348
8711
  children: el => Array.from(el.children),
8349
8712
  parent: el => el.parentElement,
@@ -8367,7 +8730,7 @@ function collectFormValues(el) {
8367
8730
  return fd;
8368
8731
  }
8369
8732
  function getElementStyleValue(element, styleProp) {
8370
- if (!isHTMLElement$1(element))
8733
+ if (!isHTMLElement(element))
8371
8734
  return undefined;
8372
8735
  if (styleProp.startsWith('computed-')) {
8373
8736
  return getComputedStyle(element).getPropertyValue(styleProp.slice('computed-'.length)) || '';
@@ -8381,7 +8744,7 @@ function getElementProperty$1(element, property) {
8381
8744
  }
8382
8745
  if (property.startsWith('computed-')) {
8383
8746
  const cssProperty = property.slice('computed-'.length);
8384
- if (isHTMLElement$1(element)) {
8747
+ if (isHTMLElement(element)) {
8385
8748
  const computedStyle = getComputedStyle(element);
8386
8749
  return computedStyle.getPropertyValue(cssProperty);
8387
8750
  }
@@ -10701,7 +11064,7 @@ function evaluateExpressionSync(node, context) {
10701
11064
  case 'selector':
10702
11065
  return evaluateSelectorSync(n, context);
10703
11066
  case 'identifier':
10704
- return resolveIdentifierSync(n.name, context);
11067
+ return resolveIdentifierSync(n.name, context, n.scope);
10705
11068
  case 'contextReference':
10706
11069
  return resolveContextReferenceSync(n.contextType, context);
10707
11070
  case 'arrayLiteral':
@@ -10737,7 +11100,7 @@ function evaluateExpressionSync(node, context) {
10737
11100
  throw new NotSyncEvaluable(n?.type ?? 'unknown');
10738
11101
  }
10739
11102
  }
10740
- function resolveIdentifierSync(name, context) {
11103
+ function resolveIdentifierSync(name, context, scope) {
10741
11104
  if (name === 'me' || name === 'my' || name === 'I')
10742
11105
  return context.me;
10743
11106
  if (name === 'you' || name === 'your' || name === 'yourself')
@@ -10748,6 +11111,8 @@ function resolveIdentifierSync(name, context) {
10748
11111
  return typeof window !== 'undefined' ? window : globalThis;
10749
11112
  if (name === 'document')
10750
11113
  return typeof document !== 'undefined' ? document : undefined;
11114
+ if (scope === 'element')
11115
+ return getElementVar(context, name);
10751
11116
  if (context.locals?.has(name))
10752
11117
  return context.locals.get(name);
10753
11118
  if (context.globals?.has(name))
@@ -10877,6 +11242,9 @@ async function evaluateIdentifier(node, context) {
10877
11242
  notifyGlobalRead(name, context);
10878
11243
  return context.globals.get(name);
10879
11244
  }
11245
+ if (node.scope === 'element') {
11246
+ return getElementVar(context, name);
11247
+ }
10880
11248
  if (context.locals && context.locals.has(name)) {
10881
11249
  notifyLocalRead(name, context);
10882
11250
  return context.locals.get(name);
@@ -10912,6 +11280,9 @@ async function evaluateBinaryExpression(node, context) {
10912
11280
  else if (leftNode.scope === 'global') {
10913
11281
  setGlobal(context, name, value);
10914
11282
  }
11283
+ else if (leftNode.scope === 'element') {
11284
+ setElementVar(context, name, value);
11285
+ }
10915
11286
  else {
10916
11287
  if (!context.locals)
10917
11288
  context.locals = new Map();
@@ -10993,14 +11364,26 @@ async function evaluateBinaryExpression(node, context) {
10993
11364
  const L = node.ignoringCase ? applyCI(left) : left;
10994
11365
  const R = node.ignoringCase ? applyCI(right) : right;
10995
11366
  switch (operator) {
10996
- case '+':
10997
- if (typeof left === 'string' || typeof right === 'string') {
10998
- return String(left ?? '') + String(right ?? '');
10999
- }
11000
- if (Array.isArray(left)) {
11001
- return Array.isArray(right) ? [...left, ...right] : [...left, right];
11002
- }
11003
- return unwrapTypedResult(await getExpr(context, 'addition').evaluate(context, { left, right }));
11367
+ case '+': {
11368
+ let addLeft = left;
11369
+ let addRight = right;
11370
+ if (node.coerceNumeric) {
11371
+ if (typeof addLeft === 'string')
11372
+ addLeft = convertToNumber(addLeft);
11373
+ if (typeof addRight === 'string')
11374
+ addRight = convertToNumber(addRight);
11375
+ }
11376
+ if (typeof addLeft === 'string' || typeof addRight === 'string') {
11377
+ return String(addLeft ?? '') + String(addRight ?? '');
11378
+ }
11379
+ if (Array.isArray(addLeft)) {
11380
+ return Array.isArray(addRight) ? [...addLeft, ...addRight] : [...addLeft, addRight];
11381
+ }
11382
+ return unwrapTypedResult(await getExpr(context, 'addition').evaluate(context, {
11383
+ left: addLeft,
11384
+ right: addRight,
11385
+ }));
11386
+ }
11004
11387
  case '-':
11005
11388
  return unwrapTypedResult(await getExpr(context, 'subtraction').evaluate(context, { left, right }));
11006
11389
  case '*':
@@ -11873,46 +12256,6 @@ class CleanupRegistry {
11873
12256
  }
11874
12257
  }
11875
12258
 
11876
- const sharedGlobals = new Map();
11877
- function createContext(element, globals) {
11878
- return {
11879
- me: element ?? null,
11880
- it: null,
11881
- you: null,
11882
- result: null,
11883
- locals: new Map(),
11884
- globals: globals || sharedGlobals,
11885
- flags: {
11886
- halted: false,
11887
- breaking: false,
11888
- continuing: false,
11889
- returning: false,
11890
- async: false,
11891
- },
11892
- };
11893
- }
11894
- function getSharedGlobals() {
11895
- return sharedGlobals;
11896
- }
11897
- function createChildContext(parent, element) {
11898
- return {
11899
- me: element ?? parent.me,
11900
- it: null,
11901
- you: null,
11902
- result: null,
11903
- locals: new Map(),
11904
- globals: parent.globals,
11905
- parent,
11906
- flags: {
11907
- halted: false,
11908
- breaking: false,
11909
- continuing: false,
11910
- returning: false,
11911
- async: false,
11912
- },
11913
- };
11914
- }
11915
-
11916
12259
  class EventSourceRegistry {
11917
12260
  constructor() {
11918
12261
  this.sources = new Map();
@@ -12143,6 +12486,7 @@ class ContextBridge {
12143
12486
  static toTyped(context) {
12144
12487
  return {
12145
12488
  me: context.me,
12489
+ ...(context.owner !== undefined && { owner: context.owner }),
12146
12490
  it: context.it,
12147
12491
  you: context.you,
12148
12492
  result: context.result,
@@ -13106,6 +13450,7 @@ class RuntimeBase {
13106
13450
  debug.runtime(`BEHAVIOR: Found behavior, eventHandlers count: ${behavior.eventHandlers?.length || 0}`);
13107
13451
  const baseBehaviorContext = {
13108
13452
  me: element,
13453
+ owner: element,
13109
13454
  you: null,
13110
13455
  it: null,
13111
13456
  result: null,
@@ -17236,35 +17581,11 @@ function createFactory(CommandClass) {
17236
17581
  return () => new CommandClass();
17237
17582
  }
17238
17583
 
17239
- function isHTMLElement(value) {
17240
- return (value !== null &&
17241
- typeof value === 'object' &&
17242
- 'nodeType' in value &&
17243
- value.nodeType === 1 &&
17244
- 'tagName' in value &&
17245
- typeof value.tagName === 'string' &&
17246
- 'classList' in value);
17247
- }
17248
- function isNodeList(value) {
17249
- return (value !== null &&
17250
- typeof value === 'object' &&
17251
- 'length' in value &&
17252
- typeof value.length === 'number' &&
17253
- (Symbol.iterator in value || typeof value.item === 'function'));
17254
- }
17255
- function isDocumentFragment(value) {
17256
- return (value !== null &&
17257
- typeof value === 'object' &&
17258
- 'nodeType' in value &&
17259
- value.nodeType === 11 &&
17260
- 'childNodes' in value);
17261
- }
17262
-
17263
17584
  function withCmd(commandName, message) {
17264
17585
  return commandName ? `[${commandName}] ${message}` : message;
17265
17586
  }
17266
17587
  function resolveElement(target, context, commandName) {
17267
- if (isHTMLElement(target)) {
17588
+ if (isHTMLElement$2(target)) {
17268
17589
  return target;
17269
17590
  }
17270
17591
  if (!target) {
@@ -17283,7 +17604,7 @@ function resolveElement(target, context, commandName) {
17283
17604
  return asHTMLElement(context.me);
17284
17605
  }
17285
17606
  if (trimmed === 'it') {
17286
- if (!isHTMLElement(context.it)) {
17607
+ if (!isHTMLElement$2(context.it)) {
17287
17608
  throw new Error(withCmd(commandName, 'Context reference "it" is not an HTMLElement'));
17288
17609
  }
17289
17610
  return context.it;
@@ -17302,7 +17623,7 @@ function resolveElement(target, context, commandName) {
17302
17623
  if (!element) {
17303
17624
  throw new Error(withCmd(commandName, `Element not found with selector: ${trimmed}`));
17304
17625
  }
17305
- if (!isHTMLElement(element)) {
17626
+ if (!isHTMLElement$2(element)) {
17306
17627
  throw new Error(withCmd(commandName, `Element found but is not an HTMLElement: ${trimmed}`));
17307
17628
  }
17308
17629
  return element;
@@ -17311,12 +17632,12 @@ function resolveElement(target, context, commandName) {
17311
17632
  }
17312
17633
  function resolveElements(target, context) {
17313
17634
  if (Array.isArray(target)) {
17314
- return target.filter(isHTMLElement);
17635
+ return target.filter(isHTMLElement$2);
17315
17636
  }
17316
17637
  if (isNodeList(target)) {
17317
- return Array.from(target).filter(isHTMLElement);
17638
+ return Array.from(target).filter(isHTMLElement$2);
17318
17639
  }
17319
- if (isHTMLElement(target)) {
17640
+ if (isHTMLElement$2(target)) {
17320
17641
  return [target];
17321
17642
  }
17322
17643
  if (!target) {
@@ -17324,18 +17645,18 @@ function resolveElements(target, context) {
17324
17645
  if (!me) {
17325
17646
  return [];
17326
17647
  }
17327
- return isHTMLElement(me) ? [me] : [];
17648
+ return isHTMLElement$2(me) ? [me] : [];
17328
17649
  }
17329
17650
  if (typeof target === 'string') {
17330
17651
  const trimmed = target.trim();
17331
17652
  if (trimmed === 'me') {
17332
- return context.me && isHTMLElement(context.me) ? [context.me] : [];
17653
+ return context.me && isHTMLElement$2(context.me) ? [context.me] : [];
17333
17654
  }
17334
17655
  if (trimmed === 'it') {
17335
- return isHTMLElement(context.it) ? [context.it] : [];
17656
+ return isHTMLElement$2(context.it) ? [context.it] : [];
17336
17657
  }
17337
17658
  if (trimmed === 'you') {
17338
- return context.you && isHTMLElement(context.you) ? [context.you] : [];
17659
+ return context.you && isHTMLElement$2(context.you) ? [context.you] : [];
17339
17660
  }
17340
17661
  const doc = context.me?.ownerDocument ?? (typeof document !== 'undefined' ? document : null);
17341
17662
  if (doc) {
@@ -17344,13 +17665,13 @@ function resolveElements(target, context) {
17344
17665
  selector = selector.slice(1, -2).trim();
17345
17666
  }
17346
17667
  const elements = doc.querySelectorAll(selector);
17347
- return Array.from(elements).filter(isHTMLElement);
17668
+ return Array.from(elements).filter(isHTMLElement$2);
17348
17669
  }
17349
17670
  }
17350
17671
  return [];
17351
17672
  }
17352
17673
  function asHTMLElement(value) {
17353
- if (isHTMLElement(value)) {
17674
+ if (isHTMLElement$2(value)) {
17354
17675
  return value;
17355
17676
  }
17356
17677
  throw new Error('Value is not an HTMLElement');
@@ -17361,21 +17682,21 @@ function resolvePossessive(possessive, context, commandName) {
17361
17682
  case 'me':
17362
17683
  if (!context.me)
17363
17684
  throw new Error(withCmd(commandName, 'No "me" element in context'));
17364
- if (!isHTMLElement(context.me))
17685
+ if (!isHTMLElement$2(context.me))
17365
17686
  throw new Error(withCmd(commandName, 'context.me is not an HTMLElement'));
17366
17687
  return context.me;
17367
17688
  case 'its':
17368
17689
  case 'it':
17369
17690
  if (!context.it)
17370
17691
  throw new Error(withCmd(commandName, 'No "it" value in context'));
17371
- if (!isHTMLElement(context.it))
17692
+ if (!isHTMLElement$2(context.it))
17372
17693
  throw new Error(withCmd(commandName, 'context.it is not an HTMLElement'));
17373
17694
  return context.it;
17374
17695
  case 'your':
17375
17696
  case 'you':
17376
17697
  if (!context.you)
17377
17698
  throw new Error(withCmd(commandName, 'No "you" element in context'));
17378
- if (!isHTMLElement(context.you))
17699
+ if (!isHTMLElement$2(context.you))
17379
17700
  throw new Error(withCmd(commandName, 'context.you is not an HTMLElement'));
17380
17701
  return context.you;
17381
17702
  default:
@@ -17404,7 +17725,7 @@ async function resolveTargetsFromArgs(args, evaluator, context, commandName, opt
17404
17725
  if (!context.me) {
17405
17726
  throw new Error(`${commandName} command: no target specified and context.me is null`);
17406
17727
  }
17407
- if (!isHTMLElement(context.me)) {
17728
+ if (!isHTMLElement$2(context.me)) {
17408
17729
  throw new Error(`${commandName} command: context.me must be an HTMLElement`);
17409
17730
  }
17410
17731
  return [context.me];
@@ -17415,15 +17736,15 @@ async function resolveTargetsFromArgs(args, evaluator, context, commandName, opt
17415
17736
  if (evaluated === '' || (typeof evaluated === 'string' && evaluated.trim() === '')) {
17416
17737
  continue;
17417
17738
  }
17418
- if (isHTMLElement(evaluated)) {
17739
+ if (isHTMLElement$2(evaluated)) {
17419
17740
  targets.push(evaluated);
17420
17741
  }
17421
17742
  else if (isNodeList(evaluated)) {
17422
- const elements = Array.from(evaluated).filter(isHTMLElement);
17743
+ const elements = Array.from(evaluated).filter(isHTMLElement$2);
17423
17744
  targets.push(...elements);
17424
17745
  }
17425
17746
  else if (Array.isArray(evaluated)) {
17426
- const elements = evaluated.filter(isHTMLElement);
17747
+ const elements = evaluated.filter(isHTMLElement$2);
17427
17748
  targets.push(...elements);
17428
17749
  }
17429
17750
  else if (typeof evaluated === 'string') {
@@ -17437,7 +17758,7 @@ async function resolveTargetsFromArgs(args, evaluator, context, commandName, opt
17437
17758
  throw new Error('DOM not available - cannot resolve element selector');
17438
17759
  }
17439
17760
  const selected = doc.querySelectorAll(selector);
17440
- const elements = Array.from(selected).filter(isHTMLElement);
17761
+ const elements = Array.from(selected).filter(isHTMLElement$2);
17441
17762
  targets.push(...elements);
17442
17763
  }
17443
17764
  catch (error) {
@@ -17455,7 +17776,7 @@ async function resolveTargetsFromArgs(args, evaluator, context, commandName, opt
17455
17776
  if (!context.me) {
17456
17777
  throw new Error(`${commandName} command: no target specified and context.me is null`);
17457
17778
  }
17458
- if (!isHTMLElement(context.me)) {
17779
+ if (!isHTMLElement$2(context.me)) {
17459
17780
  throw new Error(`${commandName} command: context.me must be an HTMLElement`);
17460
17781
  }
17461
17782
  return [context.me];
@@ -17483,7 +17804,7 @@ class VisibilityCommandBase {
17483
17804
  const typed = input;
17484
17805
  if (!Array.isArray(typed.targets))
17485
17806
  return false;
17486
- if (!typed.targets.every(t => isHTMLElement(t)))
17807
+ if (!typed.targets.every(t => isHTMLElement$2(t)))
17487
17808
  return false;
17488
17809
  if (typed.mode !== 'show' && typed.mode !== 'hide')
17489
17810
  return false;
@@ -17539,7 +17860,7 @@ let HideCommand = (() => {
17539
17860
  const typed = input;
17540
17861
  if (!Array.isArray(typed.targets))
17541
17862
  return false;
17542
- if (!typed.targets.every(t => isHTMLElement(t)))
17863
+ if (!typed.targets.every(t => isHTMLElement$2(t)))
17543
17864
  return false;
17544
17865
  return true;
17545
17866
  }
@@ -17584,7 +17905,7 @@ let ShowCommand = (() => {
17584
17905
  const typed = input;
17585
17906
  if (!Array.isArray(typed.targets))
17586
17907
  return false;
17587
- if (!typed.targets.every(t => isHTMLElement(t)))
17908
+ if (!typed.targets.every(t => isHTMLElement$2(t)))
17588
17909
  return false;
17589
17910
  if (typeof typed.defaultDisplay !== 'string')
17590
17911
  return false;
@@ -17952,7 +18273,7 @@ async function evaluateFirstArg(firstArg, evaluator, context) {
17952
18273
  }
17953
18274
 
17954
18275
  function isValidTargetArray(targets) {
17955
- return Array.isArray(targets) && targets.length > 0 && targets.every(t => isHTMLElement(t));
18276
+ return Array.isArray(targets) && targets.length > 0 && targets.every(t => isHTMLElement$2(t));
17956
18277
  }
17957
18278
  function isValidStringArray(arr, minLength = 1) {
17958
18279
  return (Array.isArray(arr) &&
@@ -18147,13 +18468,13 @@ let RemoveCommand = (() => {
18147
18468
  throw new Error('remove command requires an argument');
18148
18469
  }
18149
18470
  const { value: firstValue } = await this.evaluateFirst(raw.args[0], evaluator, context);
18150
- if (isHTMLElement(firstValue)) {
18471
+ if (isHTMLElement$2(firstValue)) {
18151
18472
  return { type: 'element', targets: [firstValue] };
18152
18473
  }
18153
- if (Array.isArray(firstValue) && firstValue.length > 0 && isHTMLElement(firstValue[0])) {
18474
+ if (Array.isArray(firstValue) && firstValue.length > 0 && isHTMLElement$2(firstValue[0])) {
18154
18475
  return {
18155
18476
  type: 'element',
18156
- targets: firstValue.filter((el) => isHTMLElement(el)),
18477
+ targets: firstValue.filter((el) => isHTMLElement$2(el)),
18157
18478
  };
18158
18479
  }
18159
18480
  if (typeof firstValue === 'string') {
@@ -18532,7 +18853,7 @@ function isEmpty(value) {
18532
18853
  function isPlainObject(value) {
18533
18854
  if (typeof value !== 'object' || value === null || Array.isArray(value))
18534
18855
  return false;
18535
- if (isHTMLElement(value) || value instanceof Node)
18856
+ if (isHTMLElement$2(value) || value instanceof Node)
18536
18857
  return false;
18537
18858
  const proto = Object.getPrototypeOf(value);
18538
18859
  return proto === Object.prototype || proto === null;
@@ -18592,7 +18913,7 @@ async function resolvePropertyTargetFromNode(node, evaluator, context) {
18592
18913
  let element = await evaluator.evaluate(node.target, context);
18593
18914
  if (Array.isArray(element))
18594
18915
  element = element[0];
18595
- if (!isHTMLElement(element))
18916
+ if (!isHTMLElement$2(element))
18596
18917
  return null;
18597
18918
  return { element: element, property };
18598
18919
  }
@@ -18605,7 +18926,7 @@ async function resolvePropertyTargetFromAccessNode(node, evaluator, context) {
18605
18926
  let element = await evaluator.evaluate(node.object, context);
18606
18927
  if (Array.isArray(element))
18607
18928
  element = element[0];
18608
- if (!isHTMLElement(element))
18929
+ if (!isHTMLElement$2(element))
18609
18930
  return null;
18610
18931
  return { element: element, property };
18611
18932
  }
@@ -18635,7 +18956,7 @@ async function resolveAnyPropertyTarget(node, evaluator, context) {
18635
18956
  let element = await evaluator.evaluate(objectNode, context);
18636
18957
  if (Array.isArray(element))
18637
18958
  element = element[0];
18638
- if (!isHTMLElement(element))
18959
+ if (!isHTMLElement$2(element))
18639
18960
  return null;
18640
18961
  const propertyName = (propertyNode?.name || propertyNode?.value);
18641
18962
  if (!propertyName)
@@ -18741,8 +19062,8 @@ async function parseTemporalModifiers(modifiers, evaluator, context) {
18741
19062
  function detectExpressionType(firstValue, firstArg) {
18742
19063
  const firstArgName = firstArg?.name;
18743
19064
  const isBareTag = isBareSmartElementNode(firstArg);
18744
- if (isHTMLElement(firstValue) ||
18745
- (Array.isArray(firstValue) && firstValue.every(el => isHTMLElement(el)))) {
19065
+ if (isHTMLElement$2(firstValue) ||
19066
+ (Array.isArray(firstValue) && firstValue.every(el => isHTMLElement$2(el)))) {
18746
19067
  return { type: 'element', expression: '' };
18747
19068
  }
18748
19069
  if (isBareTag && firstArgName) {
@@ -18888,15 +19209,15 @@ let ToggleCommand = (() => {
18888
19209
  }
18889
19210
  case 'element': {
18890
19211
  let elements;
18891
- if (isHTMLElement(firstValue)) {
19212
+ if (isHTMLElement$2(firstValue)) {
18892
19213
  elements = [firstValue];
18893
19214
  }
18894
- else if (Array.isArray(firstValue) && firstValue.every(el => isHTMLElement(el))) {
19215
+ else if (Array.isArray(firstValue) && firstValue.every(el => isHTMLElement$2(el))) {
18895
19216
  elements = firstValue;
18896
19217
  }
18897
19218
  else if (expression) {
18898
19219
  const selected = document.querySelectorAll(expression);
18899
- elements = Array.from(selected).filter((el) => isHTMLElement(el));
19220
+ elements = Array.from(selected).filter((el) => isHTMLElement$2(el));
18900
19221
  }
18901
19222
  else {
18902
19223
  elements = await resolveTargetsFromArgs([firstArg], evaluator, context, 'toggle', resolveOpts, raw.modifiers);
@@ -19218,23 +19539,23 @@ let PutCommand = (() => {
19218
19539
  }
19219
19540
  async resolveTargets(sel, ctx) {
19220
19541
  if (!sel || sel === 'me') {
19221
- if (!ctx.me || !isHTMLElement(ctx.me))
19542
+ if (!ctx.me || !isHTMLElement$2(ctx.me))
19222
19543
  throw new Error('put: no target and context.me is null');
19223
19544
  return [ctx.me];
19224
19545
  }
19225
- const els = Array.from(document.querySelectorAll(sel)).filter((e) => isHTMLElement(e));
19546
+ const els = Array.from(document.querySelectorAll(sel)).filter((e) => isHTMLElement$2(e));
19226
19547
  if (!els.length)
19227
19548
  throw new Error(`No elements: "${sel}"`);
19228
19549
  return els;
19229
19550
  }
19230
19551
  parseValue(v) {
19231
- if (isHTMLElement(v))
19552
+ if (isHTMLElement$2(v))
19232
19553
  return v;
19233
19554
  return v == null ? '' : String(v);
19234
19555
  }
19235
19556
  insertContent(target, content, pos) {
19236
19557
  if (pos === 'replace') {
19237
- if (isHTMLElement(content)) {
19558
+ if (isHTMLElement$2(content)) {
19238
19559
  target.innerHTML = '';
19239
19560
  target.appendChild(content);
19240
19561
  }
@@ -19247,7 +19568,7 @@ let PutCommand = (() => {
19247
19568
  }
19248
19569
  return;
19249
19570
  }
19250
- if (isHTMLElement(content)) {
19571
+ if (isHTMLElement$2(content)) {
19251
19572
  const el = content;
19252
19573
  switch (pos) {
19253
19574
  case 'beforebegin':
@@ -19273,14 +19594,14 @@ let PutCommand = (() => {
19273
19594
  }
19274
19595
  }
19275
19596
  resolveEvaluatedAsElements(ev) {
19276
- if (isHTMLElement(ev))
19597
+ if (isHTMLElement$2(ev))
19277
19598
  return [ev];
19278
19599
  if (Array.isArray(ev)) {
19279
- const elements = ev.filter(isHTMLElement);
19600
+ const elements = ev.filter(isHTMLElement$2);
19280
19601
  return elements.length > 0 ? elements : null;
19281
19602
  }
19282
19603
  if (typeof NodeList !== 'undefined' && ev instanceof NodeList) {
19283
- const elements = Array.from(ev).filter(isHTMLElement);
19604
+ const elements = Array.from(ev).filter(isHTMLElement$2);
19284
19605
  return elements.length > 0 ? elements : null;
19285
19606
  }
19286
19607
  return null;
@@ -19352,225 +19673,6 @@ let PutCommand = (() => {
19352
19673
  })();
19353
19674
  const createPutCommand = createFactory(PutCommand);
19354
19675
 
19355
- function convertToNumber(value) {
19356
- if (value === null || value === undefined) {
19357
- return 0;
19358
- }
19359
- if (typeof value === 'number') {
19360
- return isFinite(value) ? value : 0;
19361
- }
19362
- if (typeof value === 'string') {
19363
- const parsed = parseFloat(value);
19364
- return parsed;
19365
- }
19366
- if (typeof value === 'boolean') {
19367
- return value ? 1 : 0;
19368
- }
19369
- if (Array.isArray(value)) {
19370
- return value.length;
19371
- }
19372
- if (typeof value === 'object') {
19373
- if ('length' in value && typeof value.length === 'number') {
19374
- return value.length;
19375
- }
19376
- if (typeof value.valueOf === 'function') {
19377
- const result = value.valueOf();
19378
- if (typeof result === 'number') {
19379
- return result;
19380
- }
19381
- }
19382
- return NaN;
19383
- }
19384
- return 0;
19385
- }
19386
- function getVariableValue(name, context, preferredScope) {
19387
- if (preferredScope === 'global' && context.globals && context.globals.has(name)) {
19388
- return context.globals.get(name);
19389
- }
19390
- if (preferredScope !== 'global' && context.locals && context.locals.has(name)) {
19391
- notifyLocalRead(name, context);
19392
- return context.locals.get(name);
19393
- }
19394
- if (context.globals && context.globals.has(name)) {
19395
- return context.globals.get(name);
19396
- }
19397
- if (context.variables && context.variables.has(name)) {
19398
- return context.variables.get(name);
19399
- }
19400
- if (preferredScope === 'global' && context.locals && context.locals.has(name)) {
19401
- notifyLocalRead(name, context);
19402
- return context.locals.get(name);
19403
- }
19404
- if (typeof window !== 'undefined' && name in window) {
19405
- return window[name];
19406
- }
19407
- if (typeof globalThis !== 'undefined' && name in globalThis) {
19408
- return globalThis[name];
19409
- }
19410
- return undefined;
19411
- }
19412
- function setVariableValue(name, value, context, preferredScope) {
19413
- if (preferredScope === 'global') {
19414
- setGlobal(context, name, value);
19415
- if (typeof window !== 'undefined') {
19416
- window[name] = value;
19417
- }
19418
- return;
19419
- }
19420
- if (name.startsWith('$')) {
19421
- const bare = name.slice(1);
19422
- setGlobal(context, bare, value);
19423
- return;
19424
- }
19425
- if (context.locals && context.locals.has(name)) {
19426
- context.locals.set(name, value);
19427
- notifyLocalWrite(name, value, context);
19428
- return;
19429
- }
19430
- if (context.globals && context.globals.has(name)) {
19431
- setGlobal(context, name, value);
19432
- if (typeof window !== 'undefined' && name in window) {
19433
- window[name] = value;
19434
- }
19435
- return;
19436
- }
19437
- if (context.variables && context.variables.has(name)) {
19438
- context.variables.set(name, value);
19439
- return;
19440
- }
19441
- if (typeof window !== 'undefined' && name in window) {
19442
- window[name] = value;
19443
- setGlobal(context, name, value);
19444
- return;
19445
- }
19446
- context.locals.set(name, value);
19447
- notifyLocalWrite(name, value, context);
19448
- }
19449
- function resolveElementRef(elementRef, context) {
19450
- if (elementRef === 'me') {
19451
- return context.me;
19452
- }
19453
- else if (elementRef === 'it') {
19454
- return context.it;
19455
- }
19456
- else if (elementRef === 'you') {
19457
- return context.you;
19458
- }
19459
- else {
19460
- return getVariableValue(elementRef, context);
19461
- }
19462
- }
19463
- function getElementPropertyValue(propertyPath, context) {
19464
- const parts = propertyPath.split('.');
19465
- const elementRef = parts[0];
19466
- const property = parts[1];
19467
- const element = resolveElementRef(elementRef, context);
19468
- if (!element) {
19469
- return 0;
19470
- }
19471
- const value = element[property];
19472
- return convertToNumber(value);
19473
- }
19474
- function setElementPropertyValue(propertyPath, value, context) {
19475
- const parts = propertyPath.split('.');
19476
- const elementRef = parts[0];
19477
- const property = parts[1];
19478
- const element = resolveElementRef(elementRef, context);
19479
- if (element) {
19480
- element[property] = value;
19481
- }
19482
- }
19483
- function getCurrentNumericValue(target, property, scope, context) {
19484
- if (typeof target === 'number') {
19485
- return target;
19486
- }
19487
- if (isHTMLElement(target)) {
19488
- const element = target;
19489
- if (property) {
19490
- if (property.startsWith('data-') ||
19491
- ['id', 'class', 'title', 'alt', 'src', 'href'].includes(property)) {
19492
- const value = element.getAttribute(property);
19493
- return convertToNumber(value);
19494
- }
19495
- else {
19496
- const value = element[property];
19497
- return convertToNumber(value);
19498
- }
19499
- }
19500
- else {
19501
- const value = element.value || element.textContent;
19502
- return convertToNumber(value);
19503
- }
19504
- }
19505
- if (typeof target === 'string') {
19506
- if (scope === 'global') {
19507
- const value = getVariableValue(target, context, 'global');
19508
- return convertToNumber(value);
19509
- }
19510
- if (target.includes('.')) {
19511
- return getElementPropertyValue(target, context);
19512
- }
19513
- if (target === 'me' && context.me) {
19514
- return convertToNumber(context.me.value || 0);
19515
- }
19516
- else if (target === 'it') {
19517
- return convertToNumber(context.it || 0);
19518
- }
19519
- else if (target === 'you' && context.you) {
19520
- return convertToNumber(context.you.value || 0);
19521
- }
19522
- const value = getVariableValue(target, context);
19523
- return convertToNumber(value);
19524
- }
19525
- return convertToNumber(target);
19526
- }
19527
- function setTargetValue(target, property, scope, newValue, context) {
19528
- if (isHTMLElement(target)) {
19529
- const element = target;
19530
- if (property) {
19531
- if (property.startsWith('data-') ||
19532
- ['id', 'class', 'title', 'alt', 'src', 'href'].includes(property)) {
19533
- element.setAttribute(property, String(newValue));
19534
- }
19535
- else {
19536
- element[property] = newValue;
19537
- }
19538
- }
19539
- else {
19540
- if ('value' in element && element.value !== undefined) {
19541
- element.value = String(newValue);
19542
- }
19543
- else {
19544
- element.textContent = String(newValue);
19545
- }
19546
- }
19547
- return;
19548
- }
19549
- if (typeof target === 'string') {
19550
- if (scope === 'global') {
19551
- setVariableValue(target, newValue, context, 'global');
19552
- return;
19553
- }
19554
- if (target.includes('.')) {
19555
- setElementPropertyValue(target, newValue, context);
19556
- return;
19557
- }
19558
- if (target === 'me' && context.me) {
19559
- context.me.value = newValue;
19560
- return;
19561
- }
19562
- else if (target === 'it') {
19563
- Object.assign(context, { it: newValue });
19564
- return;
19565
- }
19566
- else if (target === 'you' && context.you) {
19567
- context.you.value = newValue;
19568
- return;
19569
- }
19570
- setVariableValue(target, newValue, context);
19571
- }
19572
- }
19573
-
19574
19676
  const HTML_ESCAPE = {
19575
19677
  '&': '&amp;',
19576
19678
  '<': '&lt;',
@@ -19634,15 +19736,15 @@ function createElementFromHTML(html) {
19634
19736
  const template = document.createElement('template');
19635
19737
  template.innerHTML = html.trim();
19636
19738
  const fromTemplate = template.content.firstElementChild;
19637
- if (fromTemplate && isHTMLElement(fromTemplate))
19739
+ if (fromTemplate && isHTMLElement$2(fromTemplate))
19638
19740
  return fromTemplate;
19639
19741
  const wrapper = document.createElement('div');
19640
19742
  wrapper.innerHTML = html.trim();
19641
19743
  const child = wrapper.firstElementChild;
19642
- return child && isHTMLElement(child) ? child : wrapper;
19744
+ return child && isHTMLElement$2(child) ? child : wrapper;
19643
19745
  }
19644
19746
  function createClassInstance(className, args, context) {
19645
- if (isHTMLElement(className))
19747
+ if (isHTMLElement$2(className))
19646
19748
  return className;
19647
19749
  const name = String(className);
19648
19750
  let Constructor;
@@ -19766,7 +19868,7 @@ let EmptyCommand = (() => {
19766
19868
  const typed = input;
19767
19869
  if (!Array.isArray(typed.targets))
19768
19870
  return false;
19769
- return typed.targets.every(t => isHTMLElement(t));
19871
+ return typed.targets.every(t => isHTMLElement$2(t));
19770
19872
  }
19771
19873
  };
19772
19874
  __setFunctionName(_classThis, "EmptyCommand");
@@ -19867,7 +19969,7 @@ let OpenCommand = (() => {
19867
19969
  const typed = input;
19868
19970
  if (!Array.isArray(typed.targets))
19869
19971
  return false;
19870
- if (!typed.targets.every(t => isHTMLElement(t)))
19972
+ if (!typed.targets.every(t => isHTMLElement$2(t)))
19871
19973
  return false;
19872
19974
  return typed.dialogMode === 'modal' || typed.dialogMode === 'non-modal';
19873
19975
  }
@@ -19931,7 +20033,7 @@ let CloseCommand = (() => {
19931
20033
  const typed = input;
19932
20034
  if (!Array.isArray(typed.targets))
19933
20035
  return false;
19934
- return typed.targets.every(t => isHTMLElement(t));
20036
+ return typed.targets.every(t => isHTMLElement$2(t));
19935
20037
  }
19936
20038
  };
19937
20039
  __setFunctionName(_classThis, "CloseCommand");
@@ -19996,7 +20098,7 @@ let SelectCommand = (() => {
19996
20098
  const typed = input;
19997
20099
  if (!Array.isArray(typed.targets))
19998
20100
  return false;
19999
- return typed.targets.every(t => isHTMLElement(t));
20101
+ return typed.targets.every(t => isHTMLElement$2(t));
20000
20102
  }
20001
20103
  };
20002
20104
  __setFunctionName(_classThis, "SelectCommand");
@@ -20042,7 +20144,7 @@ let ResetCommand = (() => {
20042
20144
  const typed = input;
20043
20145
  if (!Array.isArray(typed.targets))
20044
20146
  return false;
20045
- return typed.targets.every(t => isHTMLElement(t));
20147
+ return typed.targets.every(t => isHTMLElement$2(t));
20046
20148
  }
20047
20149
  };
20048
20150
  __setFunctionName(_classThis, "ResetCommand");
@@ -20708,8 +20810,8 @@ const STRATEGY_KEYWORDS = {
20708
20810
  outermorph: 'morphOuter',
20709
20811
  };
20710
20812
  function executeSwap(target, content, strategy, morphOptions) {
20711
- const contentStr = content !== null && !isHTMLElement(content) ? content : '';
20712
- const contentEl = isHTMLElement(content) ? content : null;
20813
+ const contentStr = content !== null && !isHTMLElement$2(content) ? content : '';
20814
+ const contentEl = isHTMLElement$2(content) ? content : null;
20713
20815
  switch (strategy) {
20714
20816
  case 'morph':
20715
20817
  if (content !== null) {
@@ -20820,7 +20922,7 @@ function extractContent(value) {
20820
20922
  if (value === null || value === undefined) {
20821
20923
  return null;
20822
20924
  }
20823
- if (isHTMLElement(value)) {
20925
+ if (isHTMLElement$2(value)) {
20824
20926
  return value;
20825
20927
  }
20826
20928
  if (isDocumentFragment(value)) {
@@ -21004,7 +21106,7 @@ let SwapCommand = (() => {
21004
21106
  if (typeof targetArg === 'string') {
21005
21107
  targetSelector = targetArg;
21006
21108
  }
21007
- else if (isHTMLElement(targetArg)) {
21109
+ else if (isHTMLElement$2(targetArg)) {
21008
21110
  return {
21009
21111
  targets: [targetArg],
21010
21112
  content: extractContent(contentArg),
@@ -21145,7 +21247,7 @@ let MorphCommand = (() => {
21145
21247
  if (typeof targetArg === 'string') {
21146
21248
  targets = await resolveTargets(targetArg, context);
21147
21249
  }
21148
- else if (isHTMLElement(targetArg)) {
21250
+ else if (isHTMLElement$2(targetArg)) {
21149
21251
  targets = [targetArg];
21150
21252
  }
21151
21253
  else {
@@ -21712,7 +21814,7 @@ function extractPartials(html) {
21712
21814
  function executePartialSwap(partial, morphOptions) {
21713
21815
  const { target, strategy, content } = partial;
21714
21816
  const targetElement = document.querySelector(target);
21715
- if (!targetElement || !isHTMLElement(targetElement)) {
21817
+ if (!targetElement || !isHTMLElement$2(targetElement)) {
21716
21818
  return { success: false, error: `Target "${target}" not found` };
21717
21819
  }
21718
21820
  try {
@@ -21829,7 +21931,7 @@ let ProcessPartialsCommand = (() => {
21829
21931
  if (typeof contentArg === 'string') {
21830
21932
  html = contentArg;
21831
21933
  }
21832
- else if (isHTMLElement(contentArg)) {
21934
+ else if (isHTMLElement$2(contentArg)) {
21833
21935
  html = contentArg.outerHTML;
21834
21936
  }
21835
21937
  else if (contentArg && typeof contentArg.text === 'function') {
@@ -22386,7 +22488,7 @@ let FetchCommand = (() => {
22386
22488
  const doc = new DOMParser().parseFromString(html, 'text/html');
22387
22489
  const fragment = document.createDocumentFragment();
22388
22490
  Array.from(doc.body.childNodes).forEach(n => fragment.appendChild(n.cloneNode(true)));
22389
- if (fragment.childNodes.length === 1 && isHTMLElement(fragment.firstChild))
22491
+ if (fragment.childNodes.length === 1 && isHTMLElement$2(fragment.firstChild))
22390
22492
  return fragment.firstChild;
22391
22493
  return fragment;
22392
22494
  }
@@ -22423,6 +22525,7 @@ let SetCommand = (() => {
22423
22525
  }
22424
22526
  const firstArg = raw.args[0];
22425
22527
  const argName = (firstArg?.name || firstArg?.value);
22528
+ const argScope = firstArg?.scope;
22426
22529
  const firstArgType = firstArg?.type;
22427
22530
  if (firstArgType) {
22428
22531
  const writer = getRegisteredNodeWriter(firstArgType);
@@ -22500,11 +22603,11 @@ let SetCommand = (() => {
22500
22603
  return { type: 'property', element, property: match[2], value };
22501
22604
  }
22502
22605
  }
22503
- if (isHTMLElement(firstValue)) {
22606
+ if (isHTMLElement$2(firstValue)) {
22504
22607
  const value = await this.extractValue(raw, evaluator, context);
22505
22608
  return { type: 'property', element: firstValue, property: 'textContent', value };
22506
22609
  }
22507
- if (Array.isArray(firstValue) && firstValue.length > 0 && isHTMLElement(firstValue[0])) {
22610
+ if (Array.isArray(firstValue) && firstValue.length > 0 && isHTMLElement$2(firstValue[0])) {
22508
22611
  const value = await this.extractValue(raw, evaluator, context);
22509
22612
  return { type: 'property', element: firstValue[0], property: 'textContent', value };
22510
22613
  }
@@ -22516,12 +22619,21 @@ let SetCommand = (() => {
22516
22619
  throw new Error(`set command target must be a string or object literal${hint}`);
22517
22620
  }
22518
22621
  const value = await this.extractValue(raw, evaluator, context);
22519
- return { type: 'variable', name: firstValue, value };
22622
+ const scope = argScope === 'element' || argScope === 'global' ? argScope : undefined;
22623
+ return { type: 'variable', name: firstValue, value, scope };
22520
22624
  }
22521
22625
  async execute(input, context) {
22522
22626
  switch (input.type) {
22523
22627
  case 'variable':
22524
- setVariableValue(input.name, input.value, context);
22628
+ if (input.scope === 'element') {
22629
+ setElementVar(context, input.name, input.value);
22630
+ }
22631
+ else if (input.scope === 'global') {
22632
+ setVariableValue(input.name, input.value, context, 'global');
22633
+ }
22634
+ else {
22635
+ setVariableValue(input.name, input.value, context);
22636
+ }
22525
22637
  if (input.name === 'result' || input.name === 'it') {
22526
22638
  Object.assign(context, { [input.name]: input.value });
22527
22639
  }
@@ -22592,7 +22704,7 @@ let SetCommand = (() => {
22592
22704
  async evaluateToElement(node, evaluator, context) {
22593
22705
  const value = await evaluator.evaluate(node, context);
22594
22706
  const el = Array.isArray(value) ? value[0] : value;
22595
- return isHTMLElement(el) ? el : null;
22707
+ return isHTMLElement$2(el) ? el : null;
22596
22708
  }
22597
22709
  async tryParseMemberExpression(firstArg, raw, evaluator, context) {
22598
22710
  const objectNode = firstArg.object;
@@ -22689,14 +22801,14 @@ let SetCommand = (() => {
22689
22801
  case 'attribute':
22690
22802
  return (typeof obj.name === 'string' &&
22691
22803
  Array.isArray(obj.elements) &&
22692
- obj.elements.every(isHTMLElement) &&
22804
+ obj.elements.every(isHTMLElement$2) &&
22693
22805
  'value' in obj);
22694
22806
  case 'property':
22695
- return typeof obj.property === 'string' && isHTMLElement(obj.element) && 'value' in obj;
22807
+ return typeof obj.property === 'string' && isHTMLElement$2(obj.element) && 'value' in obj;
22696
22808
  case 'style':
22697
22809
  return (typeof obj.property === 'string' &&
22698
22810
  obj.property !== '' &&
22699
- isHTMLElement(obj.element) &&
22811
+ isHTMLElement$2(obj.element) &&
22700
22812
  typeof obj.value === 'string');
22701
22813
  case 'object-literal':
22702
22814
  return (obj.properties !== null &&
@@ -22938,7 +23050,7 @@ let ClearCommand = (() => {
22938
23050
  (firstArgType === 'identifier' && typeof firstArgName === 'string'))) {
22939
23051
  try {
22940
23052
  const evaluated = await evaluator.evaluate(firstArg, context);
22941
- if (isHTMLElement(evaluated) || Array.isArray(evaluated)) {
23053
+ if (isHTMLElement$2(evaluated) || Array.isArray(evaluated)) {
22942
23054
  }
22943
23055
  else {
22944
23056
  return { type: 'variable', name: firstArgName };
@@ -22976,7 +23088,7 @@ let ClearCommand = (() => {
22976
23088
  return typeof typed.name === 'string';
22977
23089
  if (typed.type === 'form-fields') {
22978
23090
  const targets = typed.targets;
22979
- return Array.isArray(targets) && targets.every(t => isHTMLElement(t));
23091
+ return Array.isArray(targets) && targets.every(t => isHTMLElement$2(t));
22980
23092
  }
22981
23093
  return false;
22982
23094
  }
@@ -23142,23 +23254,23 @@ let EventDispatchCommand = (() => {
23142
23254
  targets.push(context.it);
23143
23255
  continue;
23144
23256
  }
23145
- if (isHTMLElement(val)) {
23257
+ if (isHTMLElement$2(val)) {
23146
23258
  targets.push(val);
23147
23259
  continue;
23148
23260
  }
23149
23261
  if (val instanceof NodeList) {
23150
- targets.push(...Array.from(val).filter(isHTMLElement));
23262
+ targets.push(...Array.from(val).filter(isHTMLElement$2));
23151
23263
  continue;
23152
23264
  }
23153
23265
  if (Array.isArray(val)) {
23154
- targets.push(...val.filter(isHTMLElement));
23266
+ targets.push(...val.filter(isHTMLElement$2));
23155
23267
  continue;
23156
23268
  }
23157
23269
  if (typeof val === 'string') {
23158
23270
  const els = document.querySelectorAll(val);
23159
23271
  if (els.length === 0)
23160
23272
  throw new Error(`No elements found: "${val}"`);
23161
- targets.push(...Array.from(els).filter(isHTMLElement));
23273
+ targets.push(...Array.from(els).filter(isHTMLElement$2));
23162
23274
  continue;
23163
23275
  }
23164
23276
  if (val && typeof val === 'object' && 'addEventListener' in val) {
@@ -23477,14 +23589,14 @@ let GoCommand = (() => {
23477
23589
  return document.body;
23478
23590
  if (str === 'html' && typeof document !== 'undefined')
23479
23591
  return document.documentElement;
23480
- if (str === 'me' && isHTMLElement(context.me))
23592
+ if (str === 'me' && isHTMLElement$2(context.me))
23481
23593
  return context.me;
23482
- if (str === 'it' && isHTMLElement(context.it))
23594
+ if (str === 'it' && isHTMLElement$2(context.it))
23483
23595
  return context.it;
23484
- if (str === 'you' && isHTMLElement(context.you))
23596
+ if (str === 'you' && isHTMLElement$2(context.you))
23485
23597
  return context.you;
23486
23598
  const variable = getVariableValue(str, context);
23487
- if (isHTMLElement(variable))
23599
+ if (isHTMLElement$2(variable))
23488
23600
  return variable;
23489
23601
  if (typeof document !== 'undefined') {
23490
23602
  try {
@@ -23753,18 +23865,18 @@ let ScrollCommand = (() => {
23753
23865
  }
23754
23866
  if (typeof a !== 'string' || skip.has(a))
23755
23867
  continue;
23756
- if (a === 'me' && isHTMLElement(context.me))
23868
+ if (a === 'me' && isHTMLElement$2(context.me))
23757
23869
  return context.me;
23758
- if (a === 'it' && isHTMLElement(context.it))
23870
+ if (a === 'it' && isHTMLElement$2(context.it))
23759
23871
  return context.it;
23760
- if (a === 'you' && isHTMLElement(context.you))
23872
+ if (a === 'you' && isHTMLElement$2(context.you))
23761
23873
  return context.you;
23762
23874
  if (a === 'body' && typeof document !== 'undefined')
23763
23875
  return document.body;
23764
23876
  if (a === 'html' && typeof document !== 'undefined')
23765
23877
  return document.documentElement;
23766
23878
  const variable = getVariableValue(a, context);
23767
- if (isHTMLElement(variable))
23879
+ if (isHTMLElement$2(variable))
23768
23880
  return variable;
23769
23881
  if (typeof document !== 'undefined') {
23770
23882
  try {
@@ -24636,7 +24748,7 @@ let FocusCommand = (() => {
24636
24748
  const typed = input;
24637
24749
  if (!Array.isArray(typed.targets))
24638
24750
  return false;
24639
- return typed.targets.every(t => isHTMLElement(t));
24751
+ return typed.targets.every(t => isHTMLElement$2(t));
24640
24752
  }
24641
24753
  };
24642
24754
  __setFunctionName(_classThis, "FocusCommand");
@@ -24677,7 +24789,7 @@ let BlurCommand = (() => {
24677
24789
  const typed = input;
24678
24790
  if (!Array.isArray(typed.targets))
24679
24791
  return false;
24680
- return typed.targets.every(t => isHTMLElement(t));
24792
+ return typed.targets.every(t => isHTMLElement$2(t));
24681
24793
  }
24682
24794
  };
24683
24795
  __setFunctionName(_classThis, "BlurCommand");
@@ -24746,14 +24858,14 @@ let AppendCommand = (() => {
24746
24858
  }
24747
24859
  if (target === 'me' || target === 'it' || target === 'you') {
24748
24860
  const ctxTarget = this.resolveContextRef(target, context);
24749
- if (isHTMLElement(ctxTarget)) {
24861
+ if (isHTMLElement$2(ctxTarget)) {
24750
24862
  ctxTarget.innerHTML += contentStr;
24751
24863
  return { result: ctxTarget, targetType: 'element', target: ctxTarget };
24752
24864
  }
24753
24865
  }
24754
24866
  const current = getVariableValue(target, context);
24755
24867
  if (current !== undefined) {
24756
- if (isHTMLElement(current)) {
24868
+ if (isHTMLElement$2(current)) {
24757
24869
  current.innerHTML += contentStr;
24758
24870
  return { result: current, targetType: 'element', target: current };
24759
24871
  }
@@ -24774,7 +24886,7 @@ let AppendCommand = (() => {
24774
24886
  target.push(content);
24775
24887
  return { result: target, targetType: 'array' };
24776
24888
  }
24777
- else if (isHTMLElement(target)) {
24889
+ else if (isHTMLElement$2(target)) {
24778
24890
  target.innerHTML += contentStr;
24779
24891
  return { result: target, targetType: 'element', target: target };
24780
24892
  }
@@ -24838,7 +24950,7 @@ let TransitionCommand = (() => {
24838
24950
  let property;
24839
24951
  let target;
24840
24952
  const firstArg = await evaluator.evaluate(raw.args[0], context);
24841
- if (isHTMLElement(firstArg) ||
24953
+ if (isHTMLElement$2(firstArg) ||
24842
24954
  (typeof firstArg === 'string' && /^[#.]|^(?:me|it|you)$/.test(firstArg))) {
24843
24955
  target = firstArg;
24844
24956
  property = String(await evaluator.evaluate(raw.args[1], context));
@@ -24941,7 +25053,7 @@ let MeasureCommand = (() => {
24941
25053
  const name = first.name.toLowerCase();
24942
25054
  if (name === 'me' || name === 'it' || name === 'you') {
24943
25055
  const ev = await evaluator.evaluate(first, context);
24944
- if (isHTMLElement(ev)) {
25056
+ if (isHTMLElement$2(ev)) {
24945
25057
  target = ev;
24946
25058
  if (raw.args.length > 1) {
24947
25059
  const s = raw.args[1];
@@ -24956,7 +25068,7 @@ let MeasureCommand = (() => {
24956
25068
  }
24957
25069
  else {
24958
25070
  const ev = await evaluator.evaluate(first, context);
24959
- if (isHTMLElement(ev) || (typeof ev === 'string' && /^[#.]/.test(ev))) {
25071
+ if (isHTMLElement$2(ev) || (typeof ev === 'string' && /^[#.]/.test(ev))) {
24960
25072
  target = ev;
24961
25073
  if (raw.args.length > 1) {
24962
25074
  const s = raw.args[1];
@@ -25079,7 +25191,7 @@ let SettleCommand = (() => {
25079
25191
  let timeout;
25080
25192
  if (raw.args && raw.args.length > 0) {
25081
25193
  const firstArg = await evaluator.evaluate(raw.args[0], context);
25082
- if (isHTMLElement(firstArg) ||
25194
+ if (isHTMLElement$2(firstArg) ||
25083
25195
  (typeof firstArg === 'string' &&
25084
25196
  (firstArg.startsWith('#') ||
25085
25197
  firstArg.startsWith('.') ||
@@ -25441,7 +25553,7 @@ let DefaultCommand = (() => {
25441
25553
  }
25442
25554
  return this.defaultVariable(context, target, value);
25443
25555
  }
25444
- if (isHTMLElement(target)) {
25556
+ if (isHTMLElement$2(target)) {
25445
25557
  return this.defaultElementValue(context, target, value);
25446
25558
  }
25447
25559
  throw new Error(`Invalid target type: ${typeof target}`);
@@ -25857,10 +25969,10 @@ let CopyCommand = (() => {
25857
25969
  extractText(source, format, context) {
25858
25970
  if (typeof source === 'string')
25859
25971
  return source;
25860
- if (isHTMLElement(source)) {
25972
+ if (isHTMLElement$2(source)) {
25861
25973
  return format === 'html' ? source.outerHTML : source.textContent || '';
25862
25974
  }
25863
- if (source === context.me && isHTMLElement(context.me)) {
25975
+ if (source === context.me && isHTMLElement$2(context.me)) {
25864
25976
  const el = context.me;
25865
25977
  return format === 'html' ? el.outerHTML : el.textContent || '';
25866
25978
  }
@@ -25887,7 +25999,7 @@ let CopyCommand = (() => {
25887
25999
  }
25888
26000
  }
25889
26001
  dispatchCopyEvent(context, eventName, detail) {
25890
- if (isHTMLElement(context.me)) {
26002
+ if (isHTMLElement$2(context.me)) {
25891
26003
  const event = new CustomEvent(eventName, { detail, bubbles: true, cancelable: false });
25892
26004
  context.me.dispatchEvent(event);
25893
26005
  }
@@ -26239,7 +26351,7 @@ let BeepCommand = (() => {
26239
26351
  return 'undefined';
26240
26352
  if (Array.isArray(value))
26241
26353
  return 'array';
26242
- if (isHTMLElement(value))
26354
+ if (isHTMLElement$2(value))
26243
26355
  return 'HTMLElement';
26244
26356
  if (value instanceof Element)
26245
26357
  return 'Element';
@@ -26264,7 +26376,7 @@ let BeepCommand = (() => {
26264
26376
  .map(v => this.getRepresentation(v))
26265
26377
  .join(', ')}${value.length > 3 ? '...' : ''}]`;
26266
26378
  }
26267
- if (isHTMLElement(value)) {
26379
+ if (isHTMLElement$2(value)) {
26268
26380
  const el = value;
26269
26381
  const tag = el.tagName.toLowerCase();
26270
26382
  const id = el.id ? `#${el.id}` : '';
@@ -26406,16 +26518,16 @@ class InstallCommand {
26406
26518
  resolveTarget(target, context) {
26407
26519
  if (target === undefined || target === null) {
26408
26520
  const me = context.me || context.locals.get('me');
26409
- if (isHTMLElement(me)) {
26521
+ if (isHTMLElement$2(me)) {
26410
26522
  return [me];
26411
26523
  }
26412
26524
  throw new Error('No target specified and "me" is not available in context');
26413
26525
  }
26414
- if (isHTMLElement(target)) {
26526
+ if (isHTMLElement$2(target)) {
26415
26527
  return [target];
26416
26528
  }
26417
26529
  if (Array.isArray(target)) {
26418
- const elements = target.filter((t) => isHTMLElement(t));
26530
+ const elements = target.filter((t) => isHTMLElement$2(t));
26419
26531
  if (elements.length === 0) {
26420
26532
  throw new Error('Target array contains no valid HTMLElements');
26421
26533
  }
@@ -26424,14 +26536,14 @@ class InstallCommand {
26424
26536
  if (typeof target === 'string') {
26425
26537
  if (target === 'me') {
26426
26538
  const me = context.me || context.locals.get('me');
26427
- if (isHTMLElement(me)) {
26539
+ if (isHTMLElement$2(me)) {
26428
26540
  return [me];
26429
26541
  }
26430
26542
  throw new Error('"me" is not available in context');
26431
26543
  }
26432
26544
  if (typeof document !== 'undefined') {
26433
26545
  const elements = document.querySelectorAll(target);
26434
- const htmlElements = Array.from(elements).filter((el) => isHTMLElement(el));
26546
+ const htmlElements = Array.from(elements).filter((el) => isHTMLElement$2(el));
26435
26547
  if (htmlElements.length === 0) {
26436
26548
  throw new Error(`No elements found matching selector: "${target}"`);
26437
26549
  }
@@ -26440,7 +26552,7 @@ class InstallCommand {
26440
26552
  throw new Error('document is not available (not in browser environment)');
26441
26553
  }
26442
26554
  if (target && typeof target === 'object' && 'length' in target) {
26443
- const elements = Array.from(target).filter((t) => isHTMLElement(t));
26555
+ const elements = Array.from(target).filter((t) => isHTMLElement$2(t));
26444
26556
  if (elements.length === 0) {
26445
26557
  throw new Error('Target collection contains no valid HTMLElements');
26446
26558
  }
@@ -26448,7 +26560,7 @@ class InstallCommand {
26448
26560
  }
26449
26561
  if (typeof target === 'object' && 'element' in target) {
26450
26562
  const element = target.element;
26451
- if (isHTMLElement(element)) {
26563
+ if (isHTMLElement$2(element)) {
26452
26564
  return [element];
26453
26565
  }
26454
26566
  }
@@ -33333,22 +33445,6 @@ function withDefaultExtractors(tokenizer) {
33333
33445
  return tokenizer;
33334
33446
  }
33335
33447
 
33336
- // src/core/tokenization/char-classifiers.ts
33337
- function createUnicodeRangeClassifier(ranges) {
33338
- return (char) => {
33339
- const code = char.charCodeAt(0);
33340
- return ranges.some(([start, end]) => code >= start && code <= end);
33341
- };
33342
- }
33343
- function combineClassifiers(...classifiers) {
33344
- return (char) => classifiers.some((fn) => fn(char));
33345
- }
33346
- function createLatinCharClassifiers(letterPattern) {
33347
- const isLetter = (char) => letterPattern.test(char);
33348
- const isIdentifierChar = (char) => isLetter(char) || /[0-9_-]/.test(char);
33349
- return { isLetter, isIdentifierChar };
33350
- }
33351
-
33352
33448
  // src/core/tokenization/base-tokenizer.ts
33353
33449
  var SIMPLE_TOKENIZER_OPERATOR_SET = new Set(DEFAULT_OPERATORS$1);
33354
33450
  var MARKER_CONCEPT_NORMALIZEDS = /* @__PURE__ */ new Set([
@@ -34110,6 +34206,119 @@ function createSimpleTokenizer(config) {
34110
34206
  return new SimpleTokenizer();
34111
34207
  }
34112
34208
 
34209
+ // src/multilingual/builders.ts
34210
+ function mergeRoleMarkers(slice, vocab) {
34211
+ const merged = {};
34212
+ const add = (role, marker) => {
34213
+ if (!marker?.primary) {
34214
+ delete merged[role];
34215
+ return;
34216
+ }
34217
+ merged[role] = {
34218
+ primary: marker.primary,
34219
+ ...marker.alternatives?.length && { alternatives: [...marker.alternatives] },
34220
+ ...marker.position && { position: marker.position }
34221
+ };
34222
+ };
34223
+ for (const [role, marker] of Object.entries(slice.roleMarkers ?? {})) add(role, marker);
34224
+ for (const [role, marker] of Object.entries(vocab.roleMarkerOverrides ?? {})) add(role, marker);
34225
+ return merged;
34226
+ }
34227
+ function buildPatternProfile(slice, vocab) {
34228
+ const keywords = {};
34229
+ for (const [action, translation] of Object.entries(vocab.keywords)) {
34230
+ keywords[action] = {
34231
+ primary: translation.primary,
34232
+ ...translation.alternatives?.length && { alternatives: [...translation.alternatives] }
34233
+ };
34234
+ }
34235
+ const roleMarkers = mergeRoleMarkers(slice, vocab);
34236
+ return {
34237
+ code: slice.code,
34238
+ wordOrder: slice.wordOrder,
34239
+ keywords,
34240
+ ...Object.keys(roleMarkers).length > 0 && { roleMarkers }
34241
+ };
34242
+ }
34243
+ function defaultCaseInsensitive(script) {
34244
+ return script === void 0 || script === "latin" || script === "cyrillic";
34245
+ }
34246
+ function buildDomainTokenizer(slice, vocab, options = {}) {
34247
+ const roleMarkers = mergeRoleMarkers(slice, vocab);
34248
+ const keywords = /* @__PURE__ */ new Set();
34249
+ for (const translation of Object.values(vocab.keywords)) {
34250
+ keywords.add(translation.primary);
34251
+ for (const alt of translation.alternatives ?? []) keywords.add(alt);
34252
+ }
34253
+ for (const marker of Object.values(roleMarkers)) {
34254
+ keywords.add(marker.primary);
34255
+ for (const alt of marker.alternatives ?? []) keywords.add(alt);
34256
+ }
34257
+ for (const particle of slice.tokenization?.particles ?? []) keywords.add(particle);
34258
+ for (const extra of vocab.tokenizerKeywords ?? []) keywords.add(extra);
34259
+ const profileKeywords = {};
34260
+ for (const [action, translation] of Object.entries(vocab.keywords)) {
34261
+ profileKeywords[action] = {
34262
+ primary: translation.primary,
34263
+ ...translation.alternatives?.length && { alternatives: [...translation.alternatives] },
34264
+ normalized: translation.normalized ?? action
34265
+ };
34266
+ }
34267
+ const keywordProfile = {
34268
+ keywords: profileKeywords,
34269
+ ...Object.keys(roleMarkers).length > 0 && { roleMarkers }
34270
+ };
34271
+ const customExtractors = [
34272
+ ...options.customExtractors ?? [],
34273
+ ...slice.script === "latin" ? [new LatinExtendedIdentifierExtractor()] : []
34274
+ ];
34275
+ return createSimpleTokenizer({
34276
+ language: slice.code,
34277
+ direction: slice.direction ?? "ltr",
34278
+ keywords: [...keywords],
34279
+ ...vocab.keywordExtras?.length && { keywordExtras: vocab.keywordExtras.map((e) => ({ ...e })) },
34280
+ keywordProfile,
34281
+ includeOperators: options.includeOperators ?? false,
34282
+ caseInsensitive: options.caseInsensitive ?? defaultCaseInsensitive(slice.script),
34283
+ ...customExtractors.length > 0 && { customExtractors }
34284
+ });
34285
+ }
34286
+ function buildLanguageConfig(slice, vocab, meta = {}) {
34287
+ const name = meta.name ?? slice.name ?? slice.code;
34288
+ return {
34289
+ code: slice.code,
34290
+ name,
34291
+ nativeName: meta.nativeName ?? slice.nativeName ?? name,
34292
+ tokenizer: meta.tokenizer ?? buildDomainTokenizer(slice, vocab, meta.tokenizerOptions),
34293
+ patternProfile: buildPatternProfile(slice, vocab),
34294
+ ...meta.grammarProfile && { grammarProfile: meta.grammarProfile }
34295
+ };
34296
+ }
34297
+ function deriveRoleMarkers(slice, roleMapping) {
34298
+ const derived = {};
34299
+ for (const [domainRole, semanticRole] of Object.entries(roleMapping)) {
34300
+ const marker = slice.roleMarkers?.[semanticRole];
34301
+ if (marker?.primary) derived[domainRole] = marker.primary;
34302
+ }
34303
+ return derived;
34304
+ }
34305
+
34306
+ // src/core/tokenization/char-classifiers.ts
34307
+ function createUnicodeRangeClassifier(ranges) {
34308
+ return (char) => {
34309
+ const code = char.charCodeAt(0);
34310
+ return ranges.some(([start, end]) => code >= start && code <= end);
34311
+ };
34312
+ }
34313
+ function combineClassifiers(...classifiers) {
34314
+ return (char) => classifiers.some((fn) => fn(char));
34315
+ }
34316
+ function createLatinCharClassifiers(letterPattern) {
34317
+ const isLetter = (char) => letterPattern.test(char);
34318
+ const isIdentifierChar = (char) => isLetter(char) || /[0-9_-]/.test(char);
34319
+ return { isLetter, isIdentifierChar };
34320
+ }
34321
+
34113
34322
  // src/core/tokenization/morphology/types.ts
34114
34323
  function noChange(word) {
34115
34324
  return { stem: word, confidence: 1 };
@@ -34677,7 +34886,10 @@ var index$2 = /*#__PURE__*/Object.freeze({
34677
34886
  WhitespaceExtractor: WhitespaceExtractor,
34678
34887
  accumulateBlocks: accumulateBlocks,
34679
34888
  buildDisambiguation: buildDisambiguation,
34889
+ buildDomainTokenizer: buildDomainTokenizer,
34680
34890
  buildFeedback: buildFeedback,
34891
+ buildLanguageConfig: buildLanguageConfig,
34892
+ buildPatternProfile: buildPatternProfile,
34681
34893
  buildPhrase: buildPhrase,
34682
34894
  buildTablesFromProfiles: buildTablesFromProfiles,
34683
34895
  combineClassifiers: combineClassifiers,
@@ -34708,6 +34920,7 @@ var index$2 = /*#__PURE__*/Object.freeze({
34708
34920
  createUnicodeRangeClassifier: createUnicodeRangeClassifier,
34709
34921
  defineCommand: defineCommand,
34710
34922
  defineRole: defineRole,
34923
+ deriveRoleMarkers: deriveRoleMarkers,
34711
34924
  detectWordOrders: detectWordOrders,
34712
34925
  extractCssSelector: extractCssSelector$1,
34713
34926
  extractNumber: extractNumber,
@@ -74044,6 +74257,21 @@ init_turkish();
74044
74257
  init_ukrainian();
74045
74258
  init_vietnamese();
74046
74259
 
74260
+ // src/generators/profile-queries.ts
74261
+ function getKeywordTranslations(keyword, languages) {
74262
+ const codes = languages ?? Object.keys(KNOWN_PROFILES);
74263
+ const translations = {};
74264
+ for (const code of codes) {
74265
+ const translation = KNOWN_PROFILES[code]?.keywords[keyword];
74266
+ if (translation) translations[code] = translation;
74267
+ }
74268
+ return translations;
74269
+ }
74270
+ function getRoleMarkers(language, role) {
74271
+ const markers = KNOWN_PROFILES[language]?.roleMarkers ?? {};
74272
+ return role ? markers[role] : markers;
74273
+ }
74274
+
74047
74275
  // src/generators/index.ts
74048
74276
  init_command_schemas();
74049
74277
  init_pattern_generator();
@@ -74911,6 +75139,7 @@ var index$1 = /*#__PURE__*/Object.freeze({
74911
75139
  getEventHandlerPatternsForLanguage: getEventHandlerPatternsForLanguage,
74912
75140
  getGeneratorSummary: getGeneratorSummary,
74913
75141
  getHyperscriptExtractors: getHyperscriptExtractors,
75142
+ getKeywordTranslations: getKeywordTranslations,
74914
75143
  getLoadedLanguages: getLoadedLanguages,
74915
75144
  getPatternById: getPatternById,
74916
75145
  getPatternStats: getPatternStats,
@@ -74919,6 +75148,7 @@ var index$1 = /*#__PURE__*/Object.freeze({
74919
75148
  getPutPatternsForLanguage: getPutPatternsForLanguage,
74920
75149
  getRegisteredLanguages: getRegisteredLanguages,
74921
75150
  getRegisteredMappers: getRegisteredMappers,
75151
+ getRoleMarkers: getRoleMarkers,
74922
75152
  getSchema: getSchema,
74923
75153
  getSchemasByCategory: getSchemasByCategory,
74924
75154
  getSupportedCommands: getSupportedCommands,
@@ -75012,9 +75242,9 @@ function createHistorySwap(config) {
75012
75242
  const resolveTarget = () => {
75013
75243
  if (typeof target === 'string') {
75014
75244
  const element = document.querySelector(target);
75015
- return isHTMLElement(element) ? element : null;
75245
+ return isHTMLElement$2(element) ? element : null;
75016
75246
  }
75017
- return isHTMLElement(target) ? target : null;
75247
+ return isHTMLElement$2(target) ? target : null;
75018
75248
  };
75019
75249
  const handlePopstate = async (_event) => {
75020
75250
  const targetElement = resolveTarget();
@@ -75130,9 +75360,9 @@ function createBoosted(config) {
75130
75360
  }
75131
75361
  if (typeof target === 'string') {
75132
75362
  const element = document.querySelector(target);
75133
- return isHTMLElement(element) ? element : null;
75363
+ return isHTMLElement$2(element) ? element : null;
75134
75364
  }
75135
- return isHTMLElement(target) ? target : null;
75365
+ return isHTMLElement$2(target) ? target : null;
75136
75366
  };
75137
75367
  const boost = async (url, method = 'GET', body = null) => {
75138
75368
  const targetElement = resolveTarget();
@@ -75916,6 +76146,7 @@ const config = {
75916
76146
  confidenceThreshold: DEFAULT_CONFIDENCE_THRESHOLD,
75917
76147
  logAll: false,
75918
76148
  conversions: conversionConfig.conversions,
76149
+ onCompileError: null,
75919
76150
  };
75920
76151
  async function getOrCreateBridge() {
75921
76152
  if (!bridgeInstance) {
@@ -83614,5 +83845,5 @@ var index = /*#__PURE__*/Object.freeze({
83614
83845
  validateProtocolJSON: validateProtocolJSON
83615
83846
  });
83616
83847
 
83617
- export { DebugController, Lexer, ParserExtensionRegistry, Runtime, RuntimeBase, Tokens, TypedBehaviorsFeatureImplementation, TypedDefFeatureImplementation, TypedEventSourceFeatureImplementation, TypedOnFeatureImplementation, TypedSocketsFeatureImplementation, TypedWebWorkerFeatureImplementation, configurePartialValidation, createBehaviors, createBehaviorsFeature, createChildContext, createContext, createDebugController, createDef, createDefFeature, createEventSource, createEventSourceFeature, createOn, createOnFeature, createSockets, createSocketsFeature, createWebWorker, createWebWorkerFeature, emitPartialValidationWarnings, enhancedBehaviorsImplementation, enhancedDefImplementation, enhancedEventSourceImplementation, enhancedOnImplementation, enhancedSocketsImplementation, enhancedWebWorkerImplementation, formatIssueAsString, formatIssuesAsStrings, formatResultSummary, fromCoreAST, getParserExtensionRegistry, getPartialValidationConfig, hyperscript, installPlugin, lokascript, parse$1 as parse, resetPartialValidationConfig, setGlobal, toCoreAST, validatePartialContent };
83848
+ export { DebugController, Lexer, ParserExtensionRegistry, Runtime, RuntimeBase, Tokens, TypedBehaviorsFeatureImplementation, TypedDefFeatureImplementation, TypedEventSourceFeatureImplementation, TypedOnFeatureImplementation, TypedSocketsFeatureImplementation, TypedWebWorkerFeatureImplementation, configurePartialValidation, createBehaviors, createBehaviorsFeature, createChildContext, createContext, createDebugController, createDef, createDefFeature, createEventSource, createEventSourceFeature, createOn, createOnFeature, createSockets, createSocketsFeature, createWebWorker, createWebWorkerFeature, emitPartialValidationWarnings, enhancedBehaviorsImplementation, enhancedDefImplementation, enhancedEventSourceImplementation, enhancedOnImplementation, enhancedSocketsImplementation, enhancedWebWorkerImplementation, formatIssueAsString, formatIssuesAsStrings, formatResultSummary, fromCoreAST, getElementScopeMap, getElementVar, getParserExtensionRegistry, getPartialValidationConfig, hyperscript, installPlugin, lokascript, parse$1 as parse, resetPartialValidationConfig, resolveScopeOwner, setElementVar, setGlobal, toCoreAST, validatePartialContent };
83618
83849
  //# sourceMappingURL=index.mjs.map