@hyperfixi/core 2.6.0 → 2.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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.js CHANGED
@@ -4226,7 +4226,7 @@ function parseColonVariable(ctx) {
4226
4226
  return {
4227
4227
  type: 'identifier',
4228
4228
  name: varToken.value,
4229
- scope: 'local',
4229
+ scope: 'element',
4230
4230
  start: varToken.start - 1,
4231
4231
  end: varToken.end,
4232
4232
  };
@@ -4278,7 +4278,7 @@ function parseTargetFallback(ctx) {
4278
4278
  expression: {
4279
4279
  type: 'identifier',
4280
4280
  name: varToken.value,
4281
- scope: 'local',
4281
+ scope: 'element',
4282
4282
  start: varToken.start,
4283
4283
  end: varToken.end,
4284
4284
  },
@@ -4359,6 +4359,11 @@ function parseSetCommand(ctx, identifierNode) {
4359
4359
  }
4360
4360
  ctx.advance();
4361
4361
  const value = ctx.parseExpression() ?? ctx.parsePrimary();
4362
+ let scopeTarget;
4363
+ if (ctx.check(KEYWORDS$1.ON) && tokenLooksLikeElementTarget(ctx.peekAt(1))) {
4364
+ ctx.advance();
4365
+ scopeTarget = parseOneArgument(ctx);
4366
+ }
4362
4367
  const finalArgs = [];
4363
4368
  if (targetExpression) {
4364
4369
  finalArgs.push(targetExpression);
@@ -4370,11 +4375,22 @@ function parseSetCommand(ctx, identifierNode) {
4370
4375
  if (value) {
4371
4376
  finalArgs.push(value);
4372
4377
  }
4373
- return CommandNodeBuilder.fromIdentifier(identifierNode)
4374
- .withArgs(...finalArgs)
4375
- .endingAt(ctx.getPosition())
4376
- .build();
4378
+ const builder = CommandNodeBuilder.fromIdentifier(identifierNode).withArgs(...finalArgs);
4379
+ if (scopeTarget) {
4380
+ builder.withModifier('on', scopeTarget);
4381
+ }
4382
+ return builder.endingAt(ctx.getPosition()).build();
4383
+ }
4384
+ function tokenLooksLikeElementTarget(token) {
4385
+ if (!token)
4386
+ return false;
4387
+ if (token.kind === 'selector')
4388
+ return true;
4389
+ if (token.value.startsWith('<'))
4390
+ return true;
4391
+ return ELEMENT_PRONOUNS.has(token.value);
4377
4392
  }
4393
+ const ELEMENT_PRONOUNS = new Set(['me', 'my', 'it', 'its', 'you', 'your', 'yourself']);
4378
4394
  function parseIncrementDecrementCommand(ctx, commandToken) {
4379
4395
  const commandName = commandToken.value;
4380
4396
  const isIncrement = commandName === 'increment';
@@ -4420,6 +4436,7 @@ function parseIncrementDecrementCommand(ctx, commandToken) {
4420
4436
  column: commandToken.column,
4421
4437
  };
4422
4438
  const binaryExpr = createBinaryExpression(operator, target, amount, pos);
4439
+ binaryExpr.coerceNumeric = true;
4423
4440
  const toIdentifier = createIdentifier(KEYWORDS$1.TO, pos);
4424
4441
  const args = [targetWithScope, toIdentifier, binaryExpr];
4425
4442
  return CommandNodeBuilder.from(commandToken)
@@ -5038,6 +5055,18 @@ class Parser {
5038
5055
  this.advance();
5039
5056
  continue;
5040
5057
  }
5058
+ if (this.check('then')) {
5059
+ const next = this.peekAt(1);
5060
+ const startsFeature = next !== null &&
5061
+ (next.value === 'init' ||
5062
+ next.value === 'on' ||
5063
+ next.value === 'def' ||
5064
+ getRegisteredFeature(next.value) !== undefined);
5065
+ if (startsFeature) {
5066
+ this.advance();
5067
+ continue;
5068
+ }
5069
+ }
5041
5070
  if (this.check('init')) {
5042
5071
  this.advance();
5043
5072
  const initBlock = this.parseTopLevelInitBlock();
@@ -5838,7 +5867,7 @@ class Parser {
5838
5867
  return {
5839
5868
  type: 'identifier',
5840
5869
  name: varToken.value,
5841
- scope: 'local',
5870
+ scope: 'element',
5842
5871
  start: varToken.start - 1,
5843
5872
  end: varToken.end,
5844
5873
  line: varToken.line,
@@ -6465,6 +6494,33 @@ class Parser {
6465
6494
  return null;
6466
6495
  }
6467
6496
  }
6497
+ parseTemporalKeywordModifiers(modifiers) {
6498
+ if (!this.check('debounced') && !this.check('throttled')) {
6499
+ return;
6500
+ }
6501
+ const modToken = this.advance();
6502
+ const modName = modToken.value.toLowerCase();
6503
+ const modifierKey = modName === 'debounced' ? 'debounce' : 'throttle';
6504
+ if (this.match('at')) {
6505
+ if (this.checkTimeExpression()) {
6506
+ const timeToken = this.advance();
6507
+ const delayMs = parseTimeToMs(timeToken.value);
6508
+ modifiers[modifierKey] = delayMs;
6509
+ debug.parse(`🔧 parseEventHandler: Parsed '${modName} at ${timeToken.value}' (${delayMs}ms)`);
6510
+ }
6511
+ else if (this.matchNumber()) {
6512
+ const delayMs = parseInt(this.previous().value, 10);
6513
+ modifiers[modifierKey] = delayMs;
6514
+ debug.parse(`🔧 parseEventHandler: Parsed '${modName} at ${delayMs}'`);
6515
+ }
6516
+ else {
6517
+ this.addError(`Expected time expression after '${modName} at', got: ${this.peek().value}`);
6518
+ }
6519
+ }
6520
+ else {
6521
+ this.addError(`Expected 'at' after '${modName}'`);
6522
+ }
6523
+ }
6468
6524
  parseEventHandler() {
6469
6525
  debug.parse(`🔧 parseEventHandler: ENTRY - parsing event handler`);
6470
6526
  const eventNames = [];
@@ -6552,30 +6608,7 @@ class Parser {
6552
6608
  debug.parse(`🔧 parseEventHandler: Warning - unknown modifier '.${modName}'`);
6553
6609
  }
6554
6610
  }
6555
- if (this.check('debounced') || this.check('throttled')) {
6556
- const modToken = this.advance();
6557
- const modName = modToken.value.toLowerCase();
6558
- const modifierKey = modName === 'debounced' ? 'debounce' : 'throttle';
6559
- if (this.match('at')) {
6560
- if (this.checkTimeExpression()) {
6561
- const timeToken = this.advance();
6562
- const delayMs = parseTimeToMs(timeToken.value);
6563
- modifiers[modifierKey] = delayMs;
6564
- debug.parse(`🔧 parseEventHandler: Parsed '${modName} at ${timeToken.value}' (${delayMs}ms)`);
6565
- }
6566
- else if (this.matchNumber()) {
6567
- const delayMs = parseInt(this.previous().value, 10);
6568
- modifiers[modifierKey] = delayMs;
6569
- debug.parse(`🔧 parseEventHandler: Parsed '${modName} at ${delayMs}'`);
6570
- }
6571
- else {
6572
- this.addError(`Expected time expression after '${modName} at', got: ${this.peek().value}`);
6573
- }
6574
- }
6575
- else {
6576
- this.addError(`Expected 'at' after '${modName}'`);
6577
- }
6578
- }
6611
+ this.parseTemporalKeywordModifiers(modifiers);
6579
6612
  if (firstOnceAlias) {
6580
6613
  modifiers.once = true;
6581
6614
  }
@@ -6592,6 +6625,7 @@ class Parser {
6592
6625
  const targetToken = this.advance();
6593
6626
  target = targetToken.value;
6594
6627
  debug.parse(`🔧 parseEventHandler: Parsed 'from' target: ${target} (kind: ${targetToken.kind})`);
6628
+ this.parseTemporalKeywordModifiers(modifiers);
6595
6629
  }
6596
6630
  let attributeName;
6597
6631
  if (this.match('of')) {
@@ -7562,6 +7596,10 @@ class Parser {
7562
7596
  }
7563
7597
  return this.tokens[this.current];
7564
7598
  }
7599
+ peekAt(offset) {
7600
+ const index = this.current + offset;
7601
+ return index >= 0 && index < this.tokens.length ? this.tokens[index] : null;
7602
+ }
7565
7603
  previous() {
7566
7604
  return this.tokens[this.current - 1];
7567
7605
  }
@@ -7766,10 +7804,7 @@ class Parser {
7766
7804
  restorePosition: (pos) => {
7767
7805
  parser.current = pos;
7768
7806
  },
7769
- peekAt: (offset) => {
7770
- const index = parser.current + offset;
7771
- return index >= 0 && index < parser.tokens.length ? parser.tokens[index] : null;
7772
- },
7807
+ peekAt: (offset) => parser.peekAt(offset),
7773
7808
  getInputSlice: (start, end) => {
7774
7809
  if (!this.originalInput)
7775
7810
  return '';
@@ -7918,6 +7953,334 @@ function isOk(result) {
7918
7953
  return result.ok === true;
7919
7954
  }
7920
7955
 
7956
+ const sharedGlobals = new Map();
7957
+ const elementScopes = new WeakMap();
7958
+ function getElementScopeMap(element) {
7959
+ let map = elementScopes.get(element);
7960
+ if (!map) {
7961
+ map = new Map();
7962
+ elementScopes.set(element, map);
7963
+ }
7964
+ return map;
7965
+ }
7966
+ function resolveScopeOwner(context) {
7967
+ const owner = context.owner;
7968
+ if (owner)
7969
+ return owner;
7970
+ return context.me instanceof Element ? context.me : null;
7971
+ }
7972
+ function getElementVar(context, name) {
7973
+ const owner = resolveScopeOwner(context);
7974
+ if (!owner)
7975
+ return undefined;
7976
+ notifyLocalRead(name, context);
7977
+ return getElementScopeMap(owner).get(name);
7978
+ }
7979
+ function setElementVar(context, name, value) {
7980
+ const owner = resolveScopeOwner(context);
7981
+ if (!owner)
7982
+ return;
7983
+ getElementScopeMap(owner).set(name, value);
7984
+ notifyLocalWrite(name, value, context);
7985
+ }
7986
+ function createContext(element, globals) {
7987
+ return {
7988
+ me: element ?? null,
7989
+ owner: element ?? null,
7990
+ it: null,
7991
+ you: null,
7992
+ result: null,
7993
+ locals: new Map(),
7994
+ globals: globals || sharedGlobals,
7995
+ flags: {
7996
+ halted: false,
7997
+ breaking: false,
7998
+ continuing: false,
7999
+ returning: false,
8000
+ async: false,
8001
+ },
8002
+ };
8003
+ }
8004
+ function getSharedGlobals() {
8005
+ return sharedGlobals;
8006
+ }
8007
+ function createChildContext(parent, element) {
8008
+ return {
8009
+ me: element ?? parent.me,
8010
+ owner: parent.owner ?? parent.me ?? element ?? null,
8011
+ it: null,
8012
+ you: null,
8013
+ result: null,
8014
+ locals: new Map(),
8015
+ globals: parent.globals,
8016
+ parent,
8017
+ flags: {
8018
+ halted: false,
8019
+ breaking: false,
8020
+ continuing: false,
8021
+ returning: false,
8022
+ async: false,
8023
+ },
8024
+ };
8025
+ }
8026
+
8027
+ function isHTMLElement$2(value) {
8028
+ return (value !== null &&
8029
+ typeof value === 'object' &&
8030
+ 'nodeType' in value &&
8031
+ value.nodeType === 1 &&
8032
+ 'tagName' in value &&
8033
+ typeof value.tagName === 'string' &&
8034
+ 'classList' in value);
8035
+ }
8036
+ function isNodeList(value) {
8037
+ return (value !== null &&
8038
+ typeof value === 'object' &&
8039
+ 'length' in value &&
8040
+ typeof value.length === 'number' &&
8041
+ (Symbol.iterator in value || typeof value.item === 'function'));
8042
+ }
8043
+ function isDocumentFragment(value) {
8044
+ return (value !== null &&
8045
+ typeof value === 'object' &&
8046
+ 'nodeType' in value &&
8047
+ value.nodeType === 11 &&
8048
+ 'childNodes' in value);
8049
+ }
8050
+
8051
+ function convertToNumber(value) {
8052
+ if (value === null || value === undefined) {
8053
+ return 0;
8054
+ }
8055
+ if (typeof value === 'number') {
8056
+ return isFinite(value) ? value : 0;
8057
+ }
8058
+ if (typeof value === 'string') {
8059
+ const parsed = parseFloat(value);
8060
+ return parsed;
8061
+ }
8062
+ if (typeof value === 'boolean') {
8063
+ return value ? 1 : 0;
8064
+ }
8065
+ if (Array.isArray(value)) {
8066
+ return value.length;
8067
+ }
8068
+ if (typeof value === 'object') {
8069
+ if ('length' in value && typeof value.length === 'number') {
8070
+ return value.length;
8071
+ }
8072
+ if (typeof value.valueOf === 'function') {
8073
+ const result = value.valueOf();
8074
+ if (typeof result === 'number') {
8075
+ return result;
8076
+ }
8077
+ }
8078
+ return NaN;
8079
+ }
8080
+ return 0;
8081
+ }
8082
+ function getVariableValue(name, context, preferredScope) {
8083
+ if (preferredScope === 'element') {
8084
+ return getElementVar(context, name);
8085
+ }
8086
+ if (preferredScope === 'global' && context.globals && context.globals.has(name)) {
8087
+ return context.globals.get(name);
8088
+ }
8089
+ if (preferredScope !== 'global' && context.locals && context.locals.has(name)) {
8090
+ notifyLocalRead(name, context);
8091
+ return context.locals.get(name);
8092
+ }
8093
+ if (context.globals && context.globals.has(name)) {
8094
+ return context.globals.get(name);
8095
+ }
8096
+ if (context.variables && context.variables.has(name)) {
8097
+ return context.variables.get(name);
8098
+ }
8099
+ if (preferredScope === 'global' && context.locals && context.locals.has(name)) {
8100
+ notifyLocalRead(name, context);
8101
+ return context.locals.get(name);
8102
+ }
8103
+ if (typeof window !== 'undefined' && name in window) {
8104
+ return window[name];
8105
+ }
8106
+ if (typeof globalThis !== 'undefined' && name in globalThis) {
8107
+ return globalThis[name];
8108
+ }
8109
+ return undefined;
8110
+ }
8111
+ function setVariableValue(name, value, context, preferredScope) {
8112
+ if (preferredScope === 'element') {
8113
+ setElementVar(context, name, value);
8114
+ return;
8115
+ }
8116
+ if (preferredScope === 'global') {
8117
+ setGlobal(context, name, value);
8118
+ if (typeof window !== 'undefined') {
8119
+ window[name] = value;
8120
+ }
8121
+ return;
8122
+ }
8123
+ if (name.startsWith('$')) {
8124
+ const bare = name.slice(1);
8125
+ setGlobal(context, bare, value);
8126
+ return;
8127
+ }
8128
+ if (context.locals && context.locals.has(name)) {
8129
+ context.locals.set(name, value);
8130
+ notifyLocalWrite(name, value, context);
8131
+ return;
8132
+ }
8133
+ if (context.globals && context.globals.has(name)) {
8134
+ setGlobal(context, name, value);
8135
+ if (typeof window !== 'undefined' && name in window) {
8136
+ window[name] = value;
8137
+ }
8138
+ return;
8139
+ }
8140
+ if (context.variables && context.variables.has(name)) {
8141
+ context.variables.set(name, value);
8142
+ return;
8143
+ }
8144
+ if (typeof window !== 'undefined' && name in window) {
8145
+ window[name] = value;
8146
+ setGlobal(context, name, value);
8147
+ return;
8148
+ }
8149
+ context.locals.set(name, value);
8150
+ notifyLocalWrite(name, value, context);
8151
+ }
8152
+ function resolveElementRef(elementRef, context) {
8153
+ if (elementRef === 'me') {
8154
+ return context.me;
8155
+ }
8156
+ else if (elementRef === 'it') {
8157
+ return context.it;
8158
+ }
8159
+ else if (elementRef === 'you') {
8160
+ return context.you;
8161
+ }
8162
+ else {
8163
+ return getVariableValue(elementRef, context);
8164
+ }
8165
+ }
8166
+ function getElementPropertyValue(propertyPath, context) {
8167
+ const parts = propertyPath.split('.');
8168
+ const elementRef = parts[0];
8169
+ const property = parts[1];
8170
+ const element = resolveElementRef(elementRef, context);
8171
+ if (!element) {
8172
+ return 0;
8173
+ }
8174
+ const value = element[property];
8175
+ return convertToNumber(value);
8176
+ }
8177
+ function setElementPropertyValue(propertyPath, value, context) {
8178
+ const parts = propertyPath.split('.');
8179
+ const elementRef = parts[0];
8180
+ const property = parts[1];
8181
+ const element = resolveElementRef(elementRef, context);
8182
+ if (element) {
8183
+ element[property] = value;
8184
+ }
8185
+ }
8186
+ function getCurrentNumericValue(target, property, scope, context) {
8187
+ if (typeof target === 'number') {
8188
+ return target;
8189
+ }
8190
+ if (isHTMLElement$2(target)) {
8191
+ const element = target;
8192
+ if (property) {
8193
+ if (property.startsWith('data-') ||
8194
+ ['id', 'class', 'title', 'alt', 'src', 'href'].includes(property)) {
8195
+ const value = element.getAttribute(property);
8196
+ return convertToNumber(value);
8197
+ }
8198
+ else {
8199
+ const value = element[property];
8200
+ return convertToNumber(value);
8201
+ }
8202
+ }
8203
+ else {
8204
+ const value = element.value || element.textContent;
8205
+ return convertToNumber(value);
8206
+ }
8207
+ }
8208
+ if (typeof target === 'string') {
8209
+ if (scope === 'element') {
8210
+ return convertToNumber(getVariableValue(target, context, 'element'));
8211
+ }
8212
+ if (scope === 'global') {
8213
+ const value = getVariableValue(target, context, 'global');
8214
+ return convertToNumber(value);
8215
+ }
8216
+ if (target.includes('.')) {
8217
+ return getElementPropertyValue(target, context);
8218
+ }
8219
+ if (target === 'me' && context.me) {
8220
+ return convertToNumber(context.me.value || 0);
8221
+ }
8222
+ else if (target === 'it') {
8223
+ return convertToNumber(context.it || 0);
8224
+ }
8225
+ else if (target === 'you' && context.you) {
8226
+ return convertToNumber(context.you.value || 0);
8227
+ }
8228
+ const value = getVariableValue(target, context);
8229
+ return convertToNumber(value);
8230
+ }
8231
+ return convertToNumber(target);
8232
+ }
8233
+ function setTargetValue(target, property, scope, newValue, context) {
8234
+ if (isHTMLElement$2(target)) {
8235
+ const element = target;
8236
+ if (property) {
8237
+ if (property.startsWith('data-') ||
8238
+ ['id', 'class', 'title', 'alt', 'src', 'href'].includes(property)) {
8239
+ element.setAttribute(property, String(newValue));
8240
+ }
8241
+ else {
8242
+ element[property] = newValue;
8243
+ }
8244
+ }
8245
+ else {
8246
+ if ('value' in element && element.value !== undefined) {
8247
+ element.value = String(newValue);
8248
+ }
8249
+ else {
8250
+ element.textContent = String(newValue);
8251
+ }
8252
+ }
8253
+ return;
8254
+ }
8255
+ if (typeof target === 'string') {
8256
+ if (scope === 'element') {
8257
+ setVariableValue(target, newValue, context, 'element');
8258
+ return;
8259
+ }
8260
+ if (scope === 'global') {
8261
+ setVariableValue(target, newValue, context, 'global');
8262
+ return;
8263
+ }
8264
+ if (target.includes('.')) {
8265
+ setElementPropertyValue(target, newValue, context);
8266
+ return;
8267
+ }
8268
+ if (target === 'me' && context.me) {
8269
+ context.me.value = newValue;
8270
+ return;
8271
+ }
8272
+ else if (target === 'it') {
8273
+ Object.assign(context, { it: newValue });
8274
+ return;
8275
+ }
8276
+ else if (target === 'you' && context.you) {
8277
+ context.you.value = newValue;
8278
+ return;
8279
+ }
8280
+ setVariableValue(target, newValue, context);
8281
+ }
8282
+ }
8283
+
7921
8284
  class ExpressionTypeRegistry {
7922
8285
  constructor(config = {}) {
7923
8286
  this.types = new Map();
@@ -8281,7 +8644,7 @@ function isFormElement$1(el) {
8281
8644
  const tag = el.tagName;
8282
8645
  return tag === 'INPUT' || tag === 'SELECT' || tag === 'TEXTAREA';
8283
8646
  }
8284
- function isHTMLElement$2(el) {
8647
+ function isHTMLElement$1(el) {
8285
8648
  return (el !== null &&
8286
8649
  typeof el === 'object' &&
8287
8650
  'nodeType' in el &&
@@ -8299,7 +8662,7 @@ function isOptionElement$1(el) {
8299
8662
  function isElement(value) {
8300
8663
  return value instanceof Element;
8301
8664
  }
8302
- function isHTMLElement$1(value) {
8665
+ function isHTMLElement(value) {
8303
8666
  return value instanceof HTMLElement;
8304
8667
  }
8305
8668
  const BOOLEAN_ATTRIBUTES = new Set([
@@ -8344,8 +8707,8 @@ const SPECIAL_DOM_PROPERTIES = {
8344
8707
  checked: el => (isInputElement$1(el) ? el.checked : undefined),
8345
8708
  disabled: el => ('disabled' in el ? el.disabled : undefined),
8346
8709
  selected: el => (isOptionElement$1(el) ? el.selected : undefined),
8347
- tabindex: el => (isHTMLElement$2(el) ? el.tabIndex : undefined),
8348
- hidden: el => (isHTMLElement$2(el) ? el.hidden : undefined),
8710
+ tabindex: el => (isHTMLElement$1(el) ? el.tabIndex : undefined),
8711
+ hidden: el => (isHTMLElement$1(el) ? el.hidden : undefined),
8349
8712
  style: el => getComputedStyle(el),
8350
8713
  children: el => Array.from(el.children),
8351
8714
  parent: el => el.parentElement,
@@ -8369,7 +8732,7 @@ function collectFormValues(el) {
8369
8732
  return fd;
8370
8733
  }
8371
8734
  function getElementStyleValue(element, styleProp) {
8372
- if (!isHTMLElement$1(element))
8735
+ if (!isHTMLElement(element))
8373
8736
  return undefined;
8374
8737
  if (styleProp.startsWith('computed-')) {
8375
8738
  return getComputedStyle(element).getPropertyValue(styleProp.slice('computed-'.length)) || '';
@@ -8383,7 +8746,7 @@ function getElementProperty$1(element, property) {
8383
8746
  }
8384
8747
  if (property.startsWith('computed-')) {
8385
8748
  const cssProperty = property.slice('computed-'.length);
8386
- if (isHTMLElement$1(element)) {
8749
+ if (isHTMLElement(element)) {
8387
8750
  const computedStyle = getComputedStyle(element);
8388
8751
  return computedStyle.getPropertyValue(cssProperty);
8389
8752
  }
@@ -10703,7 +11066,7 @@ function evaluateExpressionSync(node, context) {
10703
11066
  case 'selector':
10704
11067
  return evaluateSelectorSync(n, context);
10705
11068
  case 'identifier':
10706
- return resolveIdentifierSync(n.name, context);
11069
+ return resolveIdentifierSync(n.name, context, n.scope);
10707
11070
  case 'contextReference':
10708
11071
  return resolveContextReferenceSync(n.contextType, context);
10709
11072
  case 'arrayLiteral':
@@ -10739,7 +11102,7 @@ function evaluateExpressionSync(node, context) {
10739
11102
  throw new NotSyncEvaluable(n?.type ?? 'unknown');
10740
11103
  }
10741
11104
  }
10742
- function resolveIdentifierSync(name, context) {
11105
+ function resolveIdentifierSync(name, context, scope) {
10743
11106
  if (name === 'me' || name === 'my' || name === 'I')
10744
11107
  return context.me;
10745
11108
  if (name === 'you' || name === 'your' || name === 'yourself')
@@ -10750,6 +11113,8 @@ function resolveIdentifierSync(name, context) {
10750
11113
  return typeof window !== 'undefined' ? window : globalThis;
10751
11114
  if (name === 'document')
10752
11115
  return typeof document !== 'undefined' ? document : undefined;
11116
+ if (scope === 'element')
11117
+ return getElementVar(context, name);
10753
11118
  if (context.locals?.has(name))
10754
11119
  return context.locals.get(name);
10755
11120
  if (context.globals?.has(name))
@@ -10879,6 +11244,9 @@ async function evaluateIdentifier(node, context) {
10879
11244
  notifyGlobalRead(name, context);
10880
11245
  return context.globals.get(name);
10881
11246
  }
11247
+ if (node.scope === 'element') {
11248
+ return getElementVar(context, name);
11249
+ }
10882
11250
  if (context.locals && context.locals.has(name)) {
10883
11251
  notifyLocalRead(name, context);
10884
11252
  return context.locals.get(name);
@@ -10914,6 +11282,9 @@ async function evaluateBinaryExpression(node, context) {
10914
11282
  else if (leftNode.scope === 'global') {
10915
11283
  setGlobal(context, name, value);
10916
11284
  }
11285
+ else if (leftNode.scope === 'element') {
11286
+ setElementVar(context, name, value);
11287
+ }
10917
11288
  else {
10918
11289
  if (!context.locals)
10919
11290
  context.locals = new Map();
@@ -10995,14 +11366,26 @@ async function evaluateBinaryExpression(node, context) {
10995
11366
  const L = node.ignoringCase ? applyCI(left) : left;
10996
11367
  const R = node.ignoringCase ? applyCI(right) : right;
10997
11368
  switch (operator) {
10998
- case '+':
10999
- if (typeof left === 'string' || typeof right === 'string') {
11000
- return String(left ?? '') + String(right ?? '');
11001
- }
11002
- if (Array.isArray(left)) {
11003
- return Array.isArray(right) ? [...left, ...right] : [...left, right];
11004
- }
11005
- return unwrapTypedResult(await getExpr(context, 'addition').evaluate(context, { left, right }));
11369
+ case '+': {
11370
+ let addLeft = left;
11371
+ let addRight = right;
11372
+ if (node.coerceNumeric) {
11373
+ if (typeof addLeft === 'string')
11374
+ addLeft = convertToNumber(addLeft);
11375
+ if (typeof addRight === 'string')
11376
+ addRight = convertToNumber(addRight);
11377
+ }
11378
+ if (typeof addLeft === 'string' || typeof addRight === 'string') {
11379
+ return String(addLeft ?? '') + String(addRight ?? '');
11380
+ }
11381
+ if (Array.isArray(addLeft)) {
11382
+ return Array.isArray(addRight) ? [...addLeft, ...addRight] : [...addLeft, addRight];
11383
+ }
11384
+ return unwrapTypedResult(await getExpr(context, 'addition').evaluate(context, {
11385
+ left: addLeft,
11386
+ right: addRight,
11387
+ }));
11388
+ }
11006
11389
  case '-':
11007
11390
  return unwrapTypedResult(await getExpr(context, 'subtraction').evaluate(context, { left, right }));
11008
11391
  case '*':
@@ -11875,46 +12258,6 @@ class CleanupRegistry {
11875
12258
  }
11876
12259
  }
11877
12260
 
11878
- const sharedGlobals = new Map();
11879
- function createContext(element, globals) {
11880
- return {
11881
- me: element ?? null,
11882
- it: null,
11883
- you: null,
11884
- result: null,
11885
- locals: new Map(),
11886
- globals: globals || sharedGlobals,
11887
- flags: {
11888
- halted: false,
11889
- breaking: false,
11890
- continuing: false,
11891
- returning: false,
11892
- async: false,
11893
- },
11894
- };
11895
- }
11896
- function getSharedGlobals() {
11897
- return sharedGlobals;
11898
- }
11899
- function createChildContext(parent, element) {
11900
- return {
11901
- me: element ?? parent.me,
11902
- it: null,
11903
- you: null,
11904
- result: null,
11905
- locals: new Map(),
11906
- globals: parent.globals,
11907
- parent,
11908
- flags: {
11909
- halted: false,
11910
- breaking: false,
11911
- continuing: false,
11912
- returning: false,
11913
- async: false,
11914
- },
11915
- };
11916
- }
11917
-
11918
12261
  class EventSourceRegistry {
11919
12262
  constructor() {
11920
12263
  this.sources = new Map();
@@ -12145,6 +12488,7 @@ class ContextBridge {
12145
12488
  static toTyped(context) {
12146
12489
  return {
12147
12490
  me: context.me,
12491
+ ...(context.owner !== undefined && { owner: context.owner }),
12148
12492
  it: context.it,
12149
12493
  you: context.you,
12150
12494
  result: context.result,
@@ -13108,6 +13452,7 @@ class RuntimeBase {
13108
13452
  debug.runtime(`BEHAVIOR: Found behavior, eventHandlers count: ${behavior.eventHandlers?.length || 0}`);
13109
13453
  const baseBehaviorContext = {
13110
13454
  me: element,
13455
+ owner: element,
13111
13456
  you: null,
13112
13457
  it: null,
13113
13458
  result: null,
@@ -17238,35 +17583,11 @@ function createFactory(CommandClass) {
17238
17583
  return () => new CommandClass();
17239
17584
  }
17240
17585
 
17241
- function isHTMLElement(value) {
17242
- return (value !== null &&
17243
- typeof value === 'object' &&
17244
- 'nodeType' in value &&
17245
- value.nodeType === 1 &&
17246
- 'tagName' in value &&
17247
- typeof value.tagName === 'string' &&
17248
- 'classList' in value);
17249
- }
17250
- function isNodeList(value) {
17251
- return (value !== null &&
17252
- typeof value === 'object' &&
17253
- 'length' in value &&
17254
- typeof value.length === 'number' &&
17255
- (Symbol.iterator in value || typeof value.item === 'function'));
17256
- }
17257
- function isDocumentFragment(value) {
17258
- return (value !== null &&
17259
- typeof value === 'object' &&
17260
- 'nodeType' in value &&
17261
- value.nodeType === 11 &&
17262
- 'childNodes' in value);
17263
- }
17264
-
17265
17586
  function withCmd(commandName, message) {
17266
17587
  return commandName ? `[${commandName}] ${message}` : message;
17267
17588
  }
17268
17589
  function resolveElement(target, context, commandName) {
17269
- if (isHTMLElement(target)) {
17590
+ if (isHTMLElement$2(target)) {
17270
17591
  return target;
17271
17592
  }
17272
17593
  if (!target) {
@@ -17285,7 +17606,7 @@ function resolveElement(target, context, commandName) {
17285
17606
  return asHTMLElement(context.me);
17286
17607
  }
17287
17608
  if (trimmed === 'it') {
17288
- if (!isHTMLElement(context.it)) {
17609
+ if (!isHTMLElement$2(context.it)) {
17289
17610
  throw new Error(withCmd(commandName, 'Context reference "it" is not an HTMLElement'));
17290
17611
  }
17291
17612
  return context.it;
@@ -17304,7 +17625,7 @@ function resolveElement(target, context, commandName) {
17304
17625
  if (!element) {
17305
17626
  throw new Error(withCmd(commandName, `Element not found with selector: ${trimmed}`));
17306
17627
  }
17307
- if (!isHTMLElement(element)) {
17628
+ if (!isHTMLElement$2(element)) {
17308
17629
  throw new Error(withCmd(commandName, `Element found but is not an HTMLElement: ${trimmed}`));
17309
17630
  }
17310
17631
  return element;
@@ -17313,12 +17634,12 @@ function resolveElement(target, context, commandName) {
17313
17634
  }
17314
17635
  function resolveElements(target, context) {
17315
17636
  if (Array.isArray(target)) {
17316
- return target.filter(isHTMLElement);
17637
+ return target.filter(isHTMLElement$2);
17317
17638
  }
17318
17639
  if (isNodeList(target)) {
17319
- return Array.from(target).filter(isHTMLElement);
17640
+ return Array.from(target).filter(isHTMLElement$2);
17320
17641
  }
17321
- if (isHTMLElement(target)) {
17642
+ if (isHTMLElement$2(target)) {
17322
17643
  return [target];
17323
17644
  }
17324
17645
  if (!target) {
@@ -17326,18 +17647,18 @@ function resolveElements(target, context) {
17326
17647
  if (!me) {
17327
17648
  return [];
17328
17649
  }
17329
- return isHTMLElement(me) ? [me] : [];
17650
+ return isHTMLElement$2(me) ? [me] : [];
17330
17651
  }
17331
17652
  if (typeof target === 'string') {
17332
17653
  const trimmed = target.trim();
17333
17654
  if (trimmed === 'me') {
17334
- return context.me && isHTMLElement(context.me) ? [context.me] : [];
17655
+ return context.me && isHTMLElement$2(context.me) ? [context.me] : [];
17335
17656
  }
17336
17657
  if (trimmed === 'it') {
17337
- return isHTMLElement(context.it) ? [context.it] : [];
17658
+ return isHTMLElement$2(context.it) ? [context.it] : [];
17338
17659
  }
17339
17660
  if (trimmed === 'you') {
17340
- return context.you && isHTMLElement(context.you) ? [context.you] : [];
17661
+ return context.you && isHTMLElement$2(context.you) ? [context.you] : [];
17341
17662
  }
17342
17663
  const doc = context.me?.ownerDocument ?? (typeof document !== 'undefined' ? document : null);
17343
17664
  if (doc) {
@@ -17346,13 +17667,13 @@ function resolveElements(target, context) {
17346
17667
  selector = selector.slice(1, -2).trim();
17347
17668
  }
17348
17669
  const elements = doc.querySelectorAll(selector);
17349
- return Array.from(elements).filter(isHTMLElement);
17670
+ return Array.from(elements).filter(isHTMLElement$2);
17350
17671
  }
17351
17672
  }
17352
17673
  return [];
17353
17674
  }
17354
17675
  function asHTMLElement(value) {
17355
- if (isHTMLElement(value)) {
17676
+ if (isHTMLElement$2(value)) {
17356
17677
  return value;
17357
17678
  }
17358
17679
  throw new Error('Value is not an HTMLElement');
@@ -17363,21 +17684,21 @@ function resolvePossessive(possessive, context, commandName) {
17363
17684
  case 'me':
17364
17685
  if (!context.me)
17365
17686
  throw new Error(withCmd(commandName, 'No "me" element in context'));
17366
- if (!isHTMLElement(context.me))
17687
+ if (!isHTMLElement$2(context.me))
17367
17688
  throw new Error(withCmd(commandName, 'context.me is not an HTMLElement'));
17368
17689
  return context.me;
17369
17690
  case 'its':
17370
17691
  case 'it':
17371
17692
  if (!context.it)
17372
17693
  throw new Error(withCmd(commandName, 'No "it" value in context'));
17373
- if (!isHTMLElement(context.it))
17694
+ if (!isHTMLElement$2(context.it))
17374
17695
  throw new Error(withCmd(commandName, 'context.it is not an HTMLElement'));
17375
17696
  return context.it;
17376
17697
  case 'your':
17377
17698
  case 'you':
17378
17699
  if (!context.you)
17379
17700
  throw new Error(withCmd(commandName, 'No "you" element in context'));
17380
- if (!isHTMLElement(context.you))
17701
+ if (!isHTMLElement$2(context.you))
17381
17702
  throw new Error(withCmd(commandName, 'context.you is not an HTMLElement'));
17382
17703
  return context.you;
17383
17704
  default:
@@ -17406,7 +17727,7 @@ async function resolveTargetsFromArgs(args, evaluator, context, commandName, opt
17406
17727
  if (!context.me) {
17407
17728
  throw new Error(`${commandName} command: no target specified and context.me is null`);
17408
17729
  }
17409
- if (!isHTMLElement(context.me)) {
17730
+ if (!isHTMLElement$2(context.me)) {
17410
17731
  throw new Error(`${commandName} command: context.me must be an HTMLElement`);
17411
17732
  }
17412
17733
  return [context.me];
@@ -17417,15 +17738,15 @@ async function resolveTargetsFromArgs(args, evaluator, context, commandName, opt
17417
17738
  if (evaluated === '' || (typeof evaluated === 'string' && evaluated.trim() === '')) {
17418
17739
  continue;
17419
17740
  }
17420
- if (isHTMLElement(evaluated)) {
17741
+ if (isHTMLElement$2(evaluated)) {
17421
17742
  targets.push(evaluated);
17422
17743
  }
17423
17744
  else if (isNodeList(evaluated)) {
17424
- const elements = Array.from(evaluated).filter(isHTMLElement);
17745
+ const elements = Array.from(evaluated).filter(isHTMLElement$2);
17425
17746
  targets.push(...elements);
17426
17747
  }
17427
17748
  else if (Array.isArray(evaluated)) {
17428
- const elements = evaluated.filter(isHTMLElement);
17749
+ const elements = evaluated.filter(isHTMLElement$2);
17429
17750
  targets.push(...elements);
17430
17751
  }
17431
17752
  else if (typeof evaluated === 'string') {
@@ -17439,7 +17760,7 @@ async function resolveTargetsFromArgs(args, evaluator, context, commandName, opt
17439
17760
  throw new Error('DOM not available - cannot resolve element selector');
17440
17761
  }
17441
17762
  const selected = doc.querySelectorAll(selector);
17442
- const elements = Array.from(selected).filter(isHTMLElement);
17763
+ const elements = Array.from(selected).filter(isHTMLElement$2);
17443
17764
  targets.push(...elements);
17444
17765
  }
17445
17766
  catch (error) {
@@ -17457,7 +17778,7 @@ async function resolveTargetsFromArgs(args, evaluator, context, commandName, opt
17457
17778
  if (!context.me) {
17458
17779
  throw new Error(`${commandName} command: no target specified and context.me is null`);
17459
17780
  }
17460
- if (!isHTMLElement(context.me)) {
17781
+ if (!isHTMLElement$2(context.me)) {
17461
17782
  throw new Error(`${commandName} command: context.me must be an HTMLElement`);
17462
17783
  }
17463
17784
  return [context.me];
@@ -17485,7 +17806,7 @@ class VisibilityCommandBase {
17485
17806
  const typed = input;
17486
17807
  if (!Array.isArray(typed.targets))
17487
17808
  return false;
17488
- if (!typed.targets.every(t => isHTMLElement(t)))
17809
+ if (!typed.targets.every(t => isHTMLElement$2(t)))
17489
17810
  return false;
17490
17811
  if (typed.mode !== 'show' && typed.mode !== 'hide')
17491
17812
  return false;
@@ -17541,7 +17862,7 @@ let HideCommand = (() => {
17541
17862
  const typed = input;
17542
17863
  if (!Array.isArray(typed.targets))
17543
17864
  return false;
17544
- if (!typed.targets.every(t => isHTMLElement(t)))
17865
+ if (!typed.targets.every(t => isHTMLElement$2(t)))
17545
17866
  return false;
17546
17867
  return true;
17547
17868
  }
@@ -17586,7 +17907,7 @@ let ShowCommand = (() => {
17586
17907
  const typed = input;
17587
17908
  if (!Array.isArray(typed.targets))
17588
17909
  return false;
17589
- if (!typed.targets.every(t => isHTMLElement(t)))
17910
+ if (!typed.targets.every(t => isHTMLElement$2(t)))
17590
17911
  return false;
17591
17912
  if (typeof typed.defaultDisplay !== 'string')
17592
17913
  return false;
@@ -17954,7 +18275,7 @@ async function evaluateFirstArg(firstArg, evaluator, context) {
17954
18275
  }
17955
18276
 
17956
18277
  function isValidTargetArray(targets) {
17957
- return Array.isArray(targets) && targets.length > 0 && targets.every(t => isHTMLElement(t));
18278
+ return Array.isArray(targets) && targets.length > 0 && targets.every(t => isHTMLElement$2(t));
17958
18279
  }
17959
18280
  function isValidStringArray(arr, minLength = 1) {
17960
18281
  return (Array.isArray(arr) &&
@@ -18149,13 +18470,13 @@ let RemoveCommand = (() => {
18149
18470
  throw new Error('remove command requires an argument');
18150
18471
  }
18151
18472
  const { value: firstValue } = await this.evaluateFirst(raw.args[0], evaluator, context);
18152
- if (isHTMLElement(firstValue)) {
18473
+ if (isHTMLElement$2(firstValue)) {
18153
18474
  return { type: 'element', targets: [firstValue] };
18154
18475
  }
18155
- if (Array.isArray(firstValue) && firstValue.length > 0 && isHTMLElement(firstValue[0])) {
18476
+ if (Array.isArray(firstValue) && firstValue.length > 0 && isHTMLElement$2(firstValue[0])) {
18156
18477
  return {
18157
18478
  type: 'element',
18158
- targets: firstValue.filter((el) => isHTMLElement(el)),
18479
+ targets: firstValue.filter((el) => isHTMLElement$2(el)),
18159
18480
  };
18160
18481
  }
18161
18482
  if (typeof firstValue === 'string') {
@@ -18534,7 +18855,7 @@ function isEmpty(value) {
18534
18855
  function isPlainObject(value) {
18535
18856
  if (typeof value !== 'object' || value === null || Array.isArray(value))
18536
18857
  return false;
18537
- if (isHTMLElement(value) || value instanceof Node)
18858
+ if (isHTMLElement$2(value) || value instanceof Node)
18538
18859
  return false;
18539
18860
  const proto = Object.getPrototypeOf(value);
18540
18861
  return proto === Object.prototype || proto === null;
@@ -18594,7 +18915,7 @@ async function resolvePropertyTargetFromNode(node, evaluator, context) {
18594
18915
  let element = await evaluator.evaluate(node.target, context);
18595
18916
  if (Array.isArray(element))
18596
18917
  element = element[0];
18597
- if (!isHTMLElement(element))
18918
+ if (!isHTMLElement$2(element))
18598
18919
  return null;
18599
18920
  return { element: element, property };
18600
18921
  }
@@ -18607,7 +18928,7 @@ async function resolvePropertyTargetFromAccessNode(node, evaluator, context) {
18607
18928
  let element = await evaluator.evaluate(node.object, context);
18608
18929
  if (Array.isArray(element))
18609
18930
  element = element[0];
18610
- if (!isHTMLElement(element))
18931
+ if (!isHTMLElement$2(element))
18611
18932
  return null;
18612
18933
  return { element: element, property };
18613
18934
  }
@@ -18637,7 +18958,7 @@ async function resolveAnyPropertyTarget(node, evaluator, context) {
18637
18958
  let element = await evaluator.evaluate(objectNode, context);
18638
18959
  if (Array.isArray(element))
18639
18960
  element = element[0];
18640
- if (!isHTMLElement(element))
18961
+ if (!isHTMLElement$2(element))
18641
18962
  return null;
18642
18963
  const propertyName = (propertyNode?.name || propertyNode?.value);
18643
18964
  if (!propertyName)
@@ -18743,8 +19064,8 @@ async function parseTemporalModifiers(modifiers, evaluator, context) {
18743
19064
  function detectExpressionType(firstValue, firstArg) {
18744
19065
  const firstArgName = firstArg?.name;
18745
19066
  const isBareTag = isBareSmartElementNode(firstArg);
18746
- if (isHTMLElement(firstValue) ||
18747
- (Array.isArray(firstValue) && firstValue.every(el => isHTMLElement(el)))) {
19067
+ if (isHTMLElement$2(firstValue) ||
19068
+ (Array.isArray(firstValue) && firstValue.every(el => isHTMLElement$2(el)))) {
18748
19069
  return { type: 'element', expression: '' };
18749
19070
  }
18750
19071
  if (isBareTag && firstArgName) {
@@ -18890,15 +19211,15 @@ let ToggleCommand = (() => {
18890
19211
  }
18891
19212
  case 'element': {
18892
19213
  let elements;
18893
- if (isHTMLElement(firstValue)) {
19214
+ if (isHTMLElement$2(firstValue)) {
18894
19215
  elements = [firstValue];
18895
19216
  }
18896
- else if (Array.isArray(firstValue) && firstValue.every(el => isHTMLElement(el))) {
19217
+ else if (Array.isArray(firstValue) && firstValue.every(el => isHTMLElement$2(el))) {
18897
19218
  elements = firstValue;
18898
19219
  }
18899
19220
  else if (expression) {
18900
19221
  const selected = document.querySelectorAll(expression);
18901
- elements = Array.from(selected).filter((el) => isHTMLElement(el));
19222
+ elements = Array.from(selected).filter((el) => isHTMLElement$2(el));
18902
19223
  }
18903
19224
  else {
18904
19225
  elements = await resolveTargetsFromArgs([firstArg], evaluator, context, 'toggle', resolveOpts, raw.modifiers);
@@ -19220,23 +19541,23 @@ let PutCommand = (() => {
19220
19541
  }
19221
19542
  async resolveTargets(sel, ctx) {
19222
19543
  if (!sel || sel === 'me') {
19223
- if (!ctx.me || !isHTMLElement(ctx.me))
19544
+ if (!ctx.me || !isHTMLElement$2(ctx.me))
19224
19545
  throw new Error('put: no target and context.me is null');
19225
19546
  return [ctx.me];
19226
19547
  }
19227
- const els = Array.from(document.querySelectorAll(sel)).filter((e) => isHTMLElement(e));
19548
+ const els = Array.from(document.querySelectorAll(sel)).filter((e) => isHTMLElement$2(e));
19228
19549
  if (!els.length)
19229
19550
  throw new Error(`No elements: "${sel}"`);
19230
19551
  return els;
19231
19552
  }
19232
19553
  parseValue(v) {
19233
- if (isHTMLElement(v))
19554
+ if (isHTMLElement$2(v))
19234
19555
  return v;
19235
19556
  return v == null ? '' : String(v);
19236
19557
  }
19237
19558
  insertContent(target, content, pos) {
19238
19559
  if (pos === 'replace') {
19239
- if (isHTMLElement(content)) {
19560
+ if (isHTMLElement$2(content)) {
19240
19561
  target.innerHTML = '';
19241
19562
  target.appendChild(content);
19242
19563
  }
@@ -19249,7 +19570,7 @@ let PutCommand = (() => {
19249
19570
  }
19250
19571
  return;
19251
19572
  }
19252
- if (isHTMLElement(content)) {
19573
+ if (isHTMLElement$2(content)) {
19253
19574
  const el = content;
19254
19575
  switch (pos) {
19255
19576
  case 'beforebegin':
@@ -19275,14 +19596,14 @@ let PutCommand = (() => {
19275
19596
  }
19276
19597
  }
19277
19598
  resolveEvaluatedAsElements(ev) {
19278
- if (isHTMLElement(ev))
19599
+ if (isHTMLElement$2(ev))
19279
19600
  return [ev];
19280
19601
  if (Array.isArray(ev)) {
19281
- const elements = ev.filter(isHTMLElement);
19602
+ const elements = ev.filter(isHTMLElement$2);
19282
19603
  return elements.length > 0 ? elements : null;
19283
19604
  }
19284
19605
  if (typeof NodeList !== 'undefined' && ev instanceof NodeList) {
19285
- const elements = Array.from(ev).filter(isHTMLElement);
19606
+ const elements = Array.from(ev).filter(isHTMLElement$2);
19286
19607
  return elements.length > 0 ? elements : null;
19287
19608
  }
19288
19609
  return null;
@@ -19354,225 +19675,6 @@ let PutCommand = (() => {
19354
19675
  })();
19355
19676
  const createPutCommand = createFactory(PutCommand);
19356
19677
 
19357
- function convertToNumber(value) {
19358
- if (value === null || value === undefined) {
19359
- return 0;
19360
- }
19361
- if (typeof value === 'number') {
19362
- return isFinite(value) ? value : 0;
19363
- }
19364
- if (typeof value === 'string') {
19365
- const parsed = parseFloat(value);
19366
- return parsed;
19367
- }
19368
- if (typeof value === 'boolean') {
19369
- return value ? 1 : 0;
19370
- }
19371
- if (Array.isArray(value)) {
19372
- return value.length;
19373
- }
19374
- if (typeof value === 'object') {
19375
- if ('length' in value && typeof value.length === 'number') {
19376
- return value.length;
19377
- }
19378
- if (typeof value.valueOf === 'function') {
19379
- const result = value.valueOf();
19380
- if (typeof result === 'number') {
19381
- return result;
19382
- }
19383
- }
19384
- return NaN;
19385
- }
19386
- return 0;
19387
- }
19388
- function getVariableValue(name, context, preferredScope) {
19389
- if (preferredScope === 'global' && context.globals && context.globals.has(name)) {
19390
- return context.globals.get(name);
19391
- }
19392
- if (preferredScope !== 'global' && context.locals && context.locals.has(name)) {
19393
- notifyLocalRead(name, context);
19394
- return context.locals.get(name);
19395
- }
19396
- if (context.globals && context.globals.has(name)) {
19397
- return context.globals.get(name);
19398
- }
19399
- if (context.variables && context.variables.has(name)) {
19400
- return context.variables.get(name);
19401
- }
19402
- if (preferredScope === 'global' && context.locals && context.locals.has(name)) {
19403
- notifyLocalRead(name, context);
19404
- return context.locals.get(name);
19405
- }
19406
- if (typeof window !== 'undefined' && name in window) {
19407
- return window[name];
19408
- }
19409
- if (typeof globalThis !== 'undefined' && name in globalThis) {
19410
- return globalThis[name];
19411
- }
19412
- return undefined;
19413
- }
19414
- function setVariableValue(name, value, context, preferredScope) {
19415
- if (preferredScope === 'global') {
19416
- setGlobal(context, name, value);
19417
- if (typeof window !== 'undefined') {
19418
- window[name] = value;
19419
- }
19420
- return;
19421
- }
19422
- if (name.startsWith('$')) {
19423
- const bare = name.slice(1);
19424
- setGlobal(context, bare, value);
19425
- return;
19426
- }
19427
- if (context.locals && context.locals.has(name)) {
19428
- context.locals.set(name, value);
19429
- notifyLocalWrite(name, value, context);
19430
- return;
19431
- }
19432
- if (context.globals && context.globals.has(name)) {
19433
- setGlobal(context, name, value);
19434
- if (typeof window !== 'undefined' && name in window) {
19435
- window[name] = value;
19436
- }
19437
- return;
19438
- }
19439
- if (context.variables && context.variables.has(name)) {
19440
- context.variables.set(name, value);
19441
- return;
19442
- }
19443
- if (typeof window !== 'undefined' && name in window) {
19444
- window[name] = value;
19445
- setGlobal(context, name, value);
19446
- return;
19447
- }
19448
- context.locals.set(name, value);
19449
- notifyLocalWrite(name, value, context);
19450
- }
19451
- function resolveElementRef(elementRef, context) {
19452
- if (elementRef === 'me') {
19453
- return context.me;
19454
- }
19455
- else if (elementRef === 'it') {
19456
- return context.it;
19457
- }
19458
- else if (elementRef === 'you') {
19459
- return context.you;
19460
- }
19461
- else {
19462
- return getVariableValue(elementRef, context);
19463
- }
19464
- }
19465
- function getElementPropertyValue(propertyPath, context) {
19466
- const parts = propertyPath.split('.');
19467
- const elementRef = parts[0];
19468
- const property = parts[1];
19469
- const element = resolveElementRef(elementRef, context);
19470
- if (!element) {
19471
- return 0;
19472
- }
19473
- const value = element[property];
19474
- return convertToNumber(value);
19475
- }
19476
- function setElementPropertyValue(propertyPath, value, context) {
19477
- const parts = propertyPath.split('.');
19478
- const elementRef = parts[0];
19479
- const property = parts[1];
19480
- const element = resolveElementRef(elementRef, context);
19481
- if (element) {
19482
- element[property] = value;
19483
- }
19484
- }
19485
- function getCurrentNumericValue(target, property, scope, context) {
19486
- if (typeof target === 'number') {
19487
- return target;
19488
- }
19489
- if (isHTMLElement(target)) {
19490
- const element = target;
19491
- if (property) {
19492
- if (property.startsWith('data-') ||
19493
- ['id', 'class', 'title', 'alt', 'src', 'href'].includes(property)) {
19494
- const value = element.getAttribute(property);
19495
- return convertToNumber(value);
19496
- }
19497
- else {
19498
- const value = element[property];
19499
- return convertToNumber(value);
19500
- }
19501
- }
19502
- else {
19503
- const value = element.value || element.textContent;
19504
- return convertToNumber(value);
19505
- }
19506
- }
19507
- if (typeof target === 'string') {
19508
- if (scope === 'global') {
19509
- const value = getVariableValue(target, context, 'global');
19510
- return convertToNumber(value);
19511
- }
19512
- if (target.includes('.')) {
19513
- return getElementPropertyValue(target, context);
19514
- }
19515
- if (target === 'me' && context.me) {
19516
- return convertToNumber(context.me.value || 0);
19517
- }
19518
- else if (target === 'it') {
19519
- return convertToNumber(context.it || 0);
19520
- }
19521
- else if (target === 'you' && context.you) {
19522
- return convertToNumber(context.you.value || 0);
19523
- }
19524
- const value = getVariableValue(target, context);
19525
- return convertToNumber(value);
19526
- }
19527
- return convertToNumber(target);
19528
- }
19529
- function setTargetValue(target, property, scope, newValue, context) {
19530
- if (isHTMLElement(target)) {
19531
- const element = target;
19532
- if (property) {
19533
- if (property.startsWith('data-') ||
19534
- ['id', 'class', 'title', 'alt', 'src', 'href'].includes(property)) {
19535
- element.setAttribute(property, String(newValue));
19536
- }
19537
- else {
19538
- element[property] = newValue;
19539
- }
19540
- }
19541
- else {
19542
- if ('value' in element && element.value !== undefined) {
19543
- element.value = String(newValue);
19544
- }
19545
- else {
19546
- element.textContent = String(newValue);
19547
- }
19548
- }
19549
- return;
19550
- }
19551
- if (typeof target === 'string') {
19552
- if (scope === 'global') {
19553
- setVariableValue(target, newValue, context, 'global');
19554
- return;
19555
- }
19556
- if (target.includes('.')) {
19557
- setElementPropertyValue(target, newValue, context);
19558
- return;
19559
- }
19560
- if (target === 'me' && context.me) {
19561
- context.me.value = newValue;
19562
- return;
19563
- }
19564
- else if (target === 'it') {
19565
- Object.assign(context, { it: newValue });
19566
- return;
19567
- }
19568
- else if (target === 'you' && context.you) {
19569
- context.you.value = newValue;
19570
- return;
19571
- }
19572
- setVariableValue(target, newValue, context);
19573
- }
19574
- }
19575
-
19576
19678
  const HTML_ESCAPE = {
19577
19679
  '&': '&amp;',
19578
19680
  '<': '&lt;',
@@ -19636,15 +19738,15 @@ function createElementFromHTML(html) {
19636
19738
  const template = document.createElement('template');
19637
19739
  template.innerHTML = html.trim();
19638
19740
  const fromTemplate = template.content.firstElementChild;
19639
- if (fromTemplate && isHTMLElement(fromTemplate))
19741
+ if (fromTemplate && isHTMLElement$2(fromTemplate))
19640
19742
  return fromTemplate;
19641
19743
  const wrapper = document.createElement('div');
19642
19744
  wrapper.innerHTML = html.trim();
19643
19745
  const child = wrapper.firstElementChild;
19644
- return child && isHTMLElement(child) ? child : wrapper;
19746
+ return child && isHTMLElement$2(child) ? child : wrapper;
19645
19747
  }
19646
19748
  function createClassInstance(className, args, context) {
19647
- if (isHTMLElement(className))
19749
+ if (isHTMLElement$2(className))
19648
19750
  return className;
19649
19751
  const name = String(className);
19650
19752
  let Constructor;
@@ -19768,7 +19870,7 @@ let EmptyCommand = (() => {
19768
19870
  const typed = input;
19769
19871
  if (!Array.isArray(typed.targets))
19770
19872
  return false;
19771
- return typed.targets.every(t => isHTMLElement(t));
19873
+ return typed.targets.every(t => isHTMLElement$2(t));
19772
19874
  }
19773
19875
  };
19774
19876
  __setFunctionName(_classThis, "EmptyCommand");
@@ -19869,7 +19971,7 @@ let OpenCommand = (() => {
19869
19971
  const typed = input;
19870
19972
  if (!Array.isArray(typed.targets))
19871
19973
  return false;
19872
- if (!typed.targets.every(t => isHTMLElement(t)))
19974
+ if (!typed.targets.every(t => isHTMLElement$2(t)))
19873
19975
  return false;
19874
19976
  return typed.dialogMode === 'modal' || typed.dialogMode === 'non-modal';
19875
19977
  }
@@ -19933,7 +20035,7 @@ let CloseCommand = (() => {
19933
20035
  const typed = input;
19934
20036
  if (!Array.isArray(typed.targets))
19935
20037
  return false;
19936
- return typed.targets.every(t => isHTMLElement(t));
20038
+ return typed.targets.every(t => isHTMLElement$2(t));
19937
20039
  }
19938
20040
  };
19939
20041
  __setFunctionName(_classThis, "CloseCommand");
@@ -19998,7 +20100,7 @@ let SelectCommand = (() => {
19998
20100
  const typed = input;
19999
20101
  if (!Array.isArray(typed.targets))
20000
20102
  return false;
20001
- return typed.targets.every(t => isHTMLElement(t));
20103
+ return typed.targets.every(t => isHTMLElement$2(t));
20002
20104
  }
20003
20105
  };
20004
20106
  __setFunctionName(_classThis, "SelectCommand");
@@ -20044,7 +20146,7 @@ let ResetCommand = (() => {
20044
20146
  const typed = input;
20045
20147
  if (!Array.isArray(typed.targets))
20046
20148
  return false;
20047
- return typed.targets.every(t => isHTMLElement(t));
20149
+ return typed.targets.every(t => isHTMLElement$2(t));
20048
20150
  }
20049
20151
  };
20050
20152
  __setFunctionName(_classThis, "ResetCommand");
@@ -20710,8 +20812,8 @@ const STRATEGY_KEYWORDS = {
20710
20812
  outermorph: 'morphOuter',
20711
20813
  };
20712
20814
  function executeSwap(target, content, strategy, morphOptions) {
20713
- const contentStr = content !== null && !isHTMLElement(content) ? content : '';
20714
- const contentEl = isHTMLElement(content) ? content : null;
20815
+ const contentStr = content !== null && !isHTMLElement$2(content) ? content : '';
20816
+ const contentEl = isHTMLElement$2(content) ? content : null;
20715
20817
  switch (strategy) {
20716
20818
  case 'morph':
20717
20819
  if (content !== null) {
@@ -20822,7 +20924,7 @@ function extractContent(value) {
20822
20924
  if (value === null || value === undefined) {
20823
20925
  return null;
20824
20926
  }
20825
- if (isHTMLElement(value)) {
20927
+ if (isHTMLElement$2(value)) {
20826
20928
  return value;
20827
20929
  }
20828
20930
  if (isDocumentFragment(value)) {
@@ -21006,7 +21108,7 @@ let SwapCommand = (() => {
21006
21108
  if (typeof targetArg === 'string') {
21007
21109
  targetSelector = targetArg;
21008
21110
  }
21009
- else if (isHTMLElement(targetArg)) {
21111
+ else if (isHTMLElement$2(targetArg)) {
21010
21112
  return {
21011
21113
  targets: [targetArg],
21012
21114
  content: extractContent(contentArg),
@@ -21147,7 +21249,7 @@ let MorphCommand = (() => {
21147
21249
  if (typeof targetArg === 'string') {
21148
21250
  targets = await resolveTargets(targetArg, context);
21149
21251
  }
21150
- else if (isHTMLElement(targetArg)) {
21252
+ else if (isHTMLElement$2(targetArg)) {
21151
21253
  targets = [targetArg];
21152
21254
  }
21153
21255
  else {
@@ -21714,7 +21816,7 @@ function extractPartials(html) {
21714
21816
  function executePartialSwap(partial, morphOptions) {
21715
21817
  const { target, strategy, content } = partial;
21716
21818
  const targetElement = document.querySelector(target);
21717
- if (!targetElement || !isHTMLElement(targetElement)) {
21819
+ if (!targetElement || !isHTMLElement$2(targetElement)) {
21718
21820
  return { success: false, error: `Target "${target}" not found` };
21719
21821
  }
21720
21822
  try {
@@ -21831,7 +21933,7 @@ let ProcessPartialsCommand = (() => {
21831
21933
  if (typeof contentArg === 'string') {
21832
21934
  html = contentArg;
21833
21935
  }
21834
- else if (isHTMLElement(contentArg)) {
21936
+ else if (isHTMLElement$2(contentArg)) {
21835
21937
  html = contentArg.outerHTML;
21836
21938
  }
21837
21939
  else if (contentArg && typeof contentArg.text === 'function') {
@@ -22388,7 +22490,7 @@ let FetchCommand = (() => {
22388
22490
  const doc = new DOMParser().parseFromString(html, 'text/html');
22389
22491
  const fragment = document.createDocumentFragment();
22390
22492
  Array.from(doc.body.childNodes).forEach(n => fragment.appendChild(n.cloneNode(true)));
22391
- if (fragment.childNodes.length === 1 && isHTMLElement(fragment.firstChild))
22493
+ if (fragment.childNodes.length === 1 && isHTMLElement$2(fragment.firstChild))
22392
22494
  return fragment.firstChild;
22393
22495
  return fragment;
22394
22496
  }
@@ -22425,6 +22527,7 @@ let SetCommand = (() => {
22425
22527
  }
22426
22528
  const firstArg = raw.args[0];
22427
22529
  const argName = (firstArg?.name || firstArg?.value);
22530
+ const argScope = firstArg?.scope;
22428
22531
  const firstArgType = firstArg?.type;
22429
22532
  if (firstArgType) {
22430
22533
  const writer = getRegisteredNodeWriter(firstArgType);
@@ -22502,11 +22605,11 @@ let SetCommand = (() => {
22502
22605
  return { type: 'property', element, property: match[2], value };
22503
22606
  }
22504
22607
  }
22505
- if (isHTMLElement(firstValue)) {
22608
+ if (isHTMLElement$2(firstValue)) {
22506
22609
  const value = await this.extractValue(raw, evaluator, context);
22507
22610
  return { type: 'property', element: firstValue, property: 'textContent', value };
22508
22611
  }
22509
- if (Array.isArray(firstValue) && firstValue.length > 0 && isHTMLElement(firstValue[0])) {
22612
+ if (Array.isArray(firstValue) && firstValue.length > 0 && isHTMLElement$2(firstValue[0])) {
22510
22613
  const value = await this.extractValue(raw, evaluator, context);
22511
22614
  return { type: 'property', element: firstValue[0], property: 'textContent', value };
22512
22615
  }
@@ -22518,12 +22621,21 @@ let SetCommand = (() => {
22518
22621
  throw new Error(`set command target must be a string or object literal${hint}`);
22519
22622
  }
22520
22623
  const value = await this.extractValue(raw, evaluator, context);
22521
- return { type: 'variable', name: firstValue, value };
22624
+ const scope = argScope === 'element' || argScope === 'global' ? argScope : undefined;
22625
+ return { type: 'variable', name: firstValue, value, scope };
22522
22626
  }
22523
22627
  async execute(input, context) {
22524
22628
  switch (input.type) {
22525
22629
  case 'variable':
22526
- setVariableValue(input.name, input.value, context);
22630
+ if (input.scope === 'element') {
22631
+ setElementVar(context, input.name, input.value);
22632
+ }
22633
+ else if (input.scope === 'global') {
22634
+ setVariableValue(input.name, input.value, context, 'global');
22635
+ }
22636
+ else {
22637
+ setVariableValue(input.name, input.value, context);
22638
+ }
22527
22639
  if (input.name === 'result' || input.name === 'it') {
22528
22640
  Object.assign(context, { [input.name]: input.value });
22529
22641
  }
@@ -22594,7 +22706,7 @@ let SetCommand = (() => {
22594
22706
  async evaluateToElement(node, evaluator, context) {
22595
22707
  const value = await evaluator.evaluate(node, context);
22596
22708
  const el = Array.isArray(value) ? value[0] : value;
22597
- return isHTMLElement(el) ? el : null;
22709
+ return isHTMLElement$2(el) ? el : null;
22598
22710
  }
22599
22711
  async tryParseMemberExpression(firstArg, raw, evaluator, context) {
22600
22712
  const objectNode = firstArg.object;
@@ -22691,14 +22803,14 @@ let SetCommand = (() => {
22691
22803
  case 'attribute':
22692
22804
  return (typeof obj.name === 'string' &&
22693
22805
  Array.isArray(obj.elements) &&
22694
- obj.elements.every(isHTMLElement) &&
22806
+ obj.elements.every(isHTMLElement$2) &&
22695
22807
  'value' in obj);
22696
22808
  case 'property':
22697
- return typeof obj.property === 'string' && isHTMLElement(obj.element) && 'value' in obj;
22809
+ return typeof obj.property === 'string' && isHTMLElement$2(obj.element) && 'value' in obj;
22698
22810
  case 'style':
22699
22811
  return (typeof obj.property === 'string' &&
22700
22812
  obj.property !== '' &&
22701
- isHTMLElement(obj.element) &&
22813
+ isHTMLElement$2(obj.element) &&
22702
22814
  typeof obj.value === 'string');
22703
22815
  case 'object-literal':
22704
22816
  return (obj.properties !== null &&
@@ -22940,7 +23052,7 @@ let ClearCommand = (() => {
22940
23052
  (firstArgType === 'identifier' && typeof firstArgName === 'string'))) {
22941
23053
  try {
22942
23054
  const evaluated = await evaluator.evaluate(firstArg, context);
22943
- if (isHTMLElement(evaluated) || Array.isArray(evaluated)) {
23055
+ if (isHTMLElement$2(evaluated) || Array.isArray(evaluated)) {
22944
23056
  }
22945
23057
  else {
22946
23058
  return { type: 'variable', name: firstArgName };
@@ -22978,7 +23090,7 @@ let ClearCommand = (() => {
22978
23090
  return typeof typed.name === 'string';
22979
23091
  if (typed.type === 'form-fields') {
22980
23092
  const targets = typed.targets;
22981
- return Array.isArray(targets) && targets.every(t => isHTMLElement(t));
23093
+ return Array.isArray(targets) && targets.every(t => isHTMLElement$2(t));
22982
23094
  }
22983
23095
  return false;
22984
23096
  }
@@ -23144,23 +23256,23 @@ let EventDispatchCommand = (() => {
23144
23256
  targets.push(context.it);
23145
23257
  continue;
23146
23258
  }
23147
- if (isHTMLElement(val)) {
23259
+ if (isHTMLElement$2(val)) {
23148
23260
  targets.push(val);
23149
23261
  continue;
23150
23262
  }
23151
23263
  if (val instanceof NodeList) {
23152
- targets.push(...Array.from(val).filter(isHTMLElement));
23264
+ targets.push(...Array.from(val).filter(isHTMLElement$2));
23153
23265
  continue;
23154
23266
  }
23155
23267
  if (Array.isArray(val)) {
23156
- targets.push(...val.filter(isHTMLElement));
23268
+ targets.push(...val.filter(isHTMLElement$2));
23157
23269
  continue;
23158
23270
  }
23159
23271
  if (typeof val === 'string') {
23160
23272
  const els = document.querySelectorAll(val);
23161
23273
  if (els.length === 0)
23162
23274
  throw new Error(`No elements found: "${val}"`);
23163
- targets.push(...Array.from(els).filter(isHTMLElement));
23275
+ targets.push(...Array.from(els).filter(isHTMLElement$2));
23164
23276
  continue;
23165
23277
  }
23166
23278
  if (val && typeof val === 'object' && 'addEventListener' in val) {
@@ -23479,14 +23591,14 @@ let GoCommand = (() => {
23479
23591
  return document.body;
23480
23592
  if (str === 'html' && typeof document !== 'undefined')
23481
23593
  return document.documentElement;
23482
- if (str === 'me' && isHTMLElement(context.me))
23594
+ if (str === 'me' && isHTMLElement$2(context.me))
23483
23595
  return context.me;
23484
- if (str === 'it' && isHTMLElement(context.it))
23596
+ if (str === 'it' && isHTMLElement$2(context.it))
23485
23597
  return context.it;
23486
- if (str === 'you' && isHTMLElement(context.you))
23598
+ if (str === 'you' && isHTMLElement$2(context.you))
23487
23599
  return context.you;
23488
23600
  const variable = getVariableValue(str, context);
23489
- if (isHTMLElement(variable))
23601
+ if (isHTMLElement$2(variable))
23490
23602
  return variable;
23491
23603
  if (typeof document !== 'undefined') {
23492
23604
  try {
@@ -23755,18 +23867,18 @@ let ScrollCommand = (() => {
23755
23867
  }
23756
23868
  if (typeof a !== 'string' || skip.has(a))
23757
23869
  continue;
23758
- if (a === 'me' && isHTMLElement(context.me))
23870
+ if (a === 'me' && isHTMLElement$2(context.me))
23759
23871
  return context.me;
23760
- if (a === 'it' && isHTMLElement(context.it))
23872
+ if (a === 'it' && isHTMLElement$2(context.it))
23761
23873
  return context.it;
23762
- if (a === 'you' && isHTMLElement(context.you))
23874
+ if (a === 'you' && isHTMLElement$2(context.you))
23763
23875
  return context.you;
23764
23876
  if (a === 'body' && typeof document !== 'undefined')
23765
23877
  return document.body;
23766
23878
  if (a === 'html' && typeof document !== 'undefined')
23767
23879
  return document.documentElement;
23768
23880
  const variable = getVariableValue(a, context);
23769
- if (isHTMLElement(variable))
23881
+ if (isHTMLElement$2(variable))
23770
23882
  return variable;
23771
23883
  if (typeof document !== 'undefined') {
23772
23884
  try {
@@ -24638,7 +24750,7 @@ let FocusCommand = (() => {
24638
24750
  const typed = input;
24639
24751
  if (!Array.isArray(typed.targets))
24640
24752
  return false;
24641
- return typed.targets.every(t => isHTMLElement(t));
24753
+ return typed.targets.every(t => isHTMLElement$2(t));
24642
24754
  }
24643
24755
  };
24644
24756
  __setFunctionName(_classThis, "FocusCommand");
@@ -24679,7 +24791,7 @@ let BlurCommand = (() => {
24679
24791
  const typed = input;
24680
24792
  if (!Array.isArray(typed.targets))
24681
24793
  return false;
24682
- return typed.targets.every(t => isHTMLElement(t));
24794
+ return typed.targets.every(t => isHTMLElement$2(t));
24683
24795
  }
24684
24796
  };
24685
24797
  __setFunctionName(_classThis, "BlurCommand");
@@ -24748,14 +24860,14 @@ let AppendCommand = (() => {
24748
24860
  }
24749
24861
  if (target === 'me' || target === 'it' || target === 'you') {
24750
24862
  const ctxTarget = this.resolveContextRef(target, context);
24751
- if (isHTMLElement(ctxTarget)) {
24863
+ if (isHTMLElement$2(ctxTarget)) {
24752
24864
  ctxTarget.innerHTML += contentStr;
24753
24865
  return { result: ctxTarget, targetType: 'element', target: ctxTarget };
24754
24866
  }
24755
24867
  }
24756
24868
  const current = getVariableValue(target, context);
24757
24869
  if (current !== undefined) {
24758
- if (isHTMLElement(current)) {
24870
+ if (isHTMLElement$2(current)) {
24759
24871
  current.innerHTML += contentStr;
24760
24872
  return { result: current, targetType: 'element', target: current };
24761
24873
  }
@@ -24776,7 +24888,7 @@ let AppendCommand = (() => {
24776
24888
  target.push(content);
24777
24889
  return { result: target, targetType: 'array' };
24778
24890
  }
24779
- else if (isHTMLElement(target)) {
24891
+ else if (isHTMLElement$2(target)) {
24780
24892
  target.innerHTML += contentStr;
24781
24893
  return { result: target, targetType: 'element', target: target };
24782
24894
  }
@@ -24840,7 +24952,7 @@ let TransitionCommand = (() => {
24840
24952
  let property;
24841
24953
  let target;
24842
24954
  const firstArg = await evaluator.evaluate(raw.args[0], context);
24843
- if (isHTMLElement(firstArg) ||
24955
+ if (isHTMLElement$2(firstArg) ||
24844
24956
  (typeof firstArg === 'string' && /^[#.]|^(?:me|it|you)$/.test(firstArg))) {
24845
24957
  target = firstArg;
24846
24958
  property = String(await evaluator.evaluate(raw.args[1], context));
@@ -24943,7 +25055,7 @@ let MeasureCommand = (() => {
24943
25055
  const name = first.name.toLowerCase();
24944
25056
  if (name === 'me' || name === 'it' || name === 'you') {
24945
25057
  const ev = await evaluator.evaluate(first, context);
24946
- if (isHTMLElement(ev)) {
25058
+ if (isHTMLElement$2(ev)) {
24947
25059
  target = ev;
24948
25060
  if (raw.args.length > 1) {
24949
25061
  const s = raw.args[1];
@@ -24958,7 +25070,7 @@ let MeasureCommand = (() => {
24958
25070
  }
24959
25071
  else {
24960
25072
  const ev = await evaluator.evaluate(first, context);
24961
- if (isHTMLElement(ev) || (typeof ev === 'string' && /^[#.]/.test(ev))) {
25073
+ if (isHTMLElement$2(ev) || (typeof ev === 'string' && /^[#.]/.test(ev))) {
24962
25074
  target = ev;
24963
25075
  if (raw.args.length > 1) {
24964
25076
  const s = raw.args[1];
@@ -25081,7 +25193,7 @@ let SettleCommand = (() => {
25081
25193
  let timeout;
25082
25194
  if (raw.args && raw.args.length > 0) {
25083
25195
  const firstArg = await evaluator.evaluate(raw.args[0], context);
25084
- if (isHTMLElement(firstArg) ||
25196
+ if (isHTMLElement$2(firstArg) ||
25085
25197
  (typeof firstArg === 'string' &&
25086
25198
  (firstArg.startsWith('#') ||
25087
25199
  firstArg.startsWith('.') ||
@@ -25443,7 +25555,7 @@ let DefaultCommand = (() => {
25443
25555
  }
25444
25556
  return this.defaultVariable(context, target, value);
25445
25557
  }
25446
- if (isHTMLElement(target)) {
25558
+ if (isHTMLElement$2(target)) {
25447
25559
  return this.defaultElementValue(context, target, value);
25448
25560
  }
25449
25561
  throw new Error(`Invalid target type: ${typeof target}`);
@@ -25859,10 +25971,10 @@ let CopyCommand = (() => {
25859
25971
  extractText(source, format, context) {
25860
25972
  if (typeof source === 'string')
25861
25973
  return source;
25862
- if (isHTMLElement(source)) {
25974
+ if (isHTMLElement$2(source)) {
25863
25975
  return format === 'html' ? source.outerHTML : source.textContent || '';
25864
25976
  }
25865
- if (source === context.me && isHTMLElement(context.me)) {
25977
+ if (source === context.me && isHTMLElement$2(context.me)) {
25866
25978
  const el = context.me;
25867
25979
  return format === 'html' ? el.outerHTML : el.textContent || '';
25868
25980
  }
@@ -25889,7 +26001,7 @@ let CopyCommand = (() => {
25889
26001
  }
25890
26002
  }
25891
26003
  dispatchCopyEvent(context, eventName, detail) {
25892
- if (isHTMLElement(context.me)) {
26004
+ if (isHTMLElement$2(context.me)) {
25893
26005
  const event = new CustomEvent(eventName, { detail, bubbles: true, cancelable: false });
25894
26006
  context.me.dispatchEvent(event);
25895
26007
  }
@@ -26241,7 +26353,7 @@ let BeepCommand = (() => {
26241
26353
  return 'undefined';
26242
26354
  if (Array.isArray(value))
26243
26355
  return 'array';
26244
- if (isHTMLElement(value))
26356
+ if (isHTMLElement$2(value))
26245
26357
  return 'HTMLElement';
26246
26358
  if (value instanceof Element)
26247
26359
  return 'Element';
@@ -26266,7 +26378,7 @@ let BeepCommand = (() => {
26266
26378
  .map(v => this.getRepresentation(v))
26267
26379
  .join(', ')}${value.length > 3 ? '...' : ''}]`;
26268
26380
  }
26269
- if (isHTMLElement(value)) {
26381
+ if (isHTMLElement$2(value)) {
26270
26382
  const el = value;
26271
26383
  const tag = el.tagName.toLowerCase();
26272
26384
  const id = el.id ? `#${el.id}` : '';
@@ -26408,16 +26520,16 @@ class InstallCommand {
26408
26520
  resolveTarget(target, context) {
26409
26521
  if (target === undefined || target === null) {
26410
26522
  const me = context.me || context.locals.get('me');
26411
- if (isHTMLElement(me)) {
26523
+ if (isHTMLElement$2(me)) {
26412
26524
  return [me];
26413
26525
  }
26414
26526
  throw new Error('No target specified and "me" is not available in context');
26415
26527
  }
26416
- if (isHTMLElement(target)) {
26528
+ if (isHTMLElement$2(target)) {
26417
26529
  return [target];
26418
26530
  }
26419
26531
  if (Array.isArray(target)) {
26420
- const elements = target.filter((t) => isHTMLElement(t));
26532
+ const elements = target.filter((t) => isHTMLElement$2(t));
26421
26533
  if (elements.length === 0) {
26422
26534
  throw new Error('Target array contains no valid HTMLElements');
26423
26535
  }
@@ -26426,14 +26538,14 @@ class InstallCommand {
26426
26538
  if (typeof target === 'string') {
26427
26539
  if (target === 'me') {
26428
26540
  const me = context.me || context.locals.get('me');
26429
- if (isHTMLElement(me)) {
26541
+ if (isHTMLElement$2(me)) {
26430
26542
  return [me];
26431
26543
  }
26432
26544
  throw new Error('"me" is not available in context');
26433
26545
  }
26434
26546
  if (typeof document !== 'undefined') {
26435
26547
  const elements = document.querySelectorAll(target);
26436
- const htmlElements = Array.from(elements).filter((el) => isHTMLElement(el));
26548
+ const htmlElements = Array.from(elements).filter((el) => isHTMLElement$2(el));
26437
26549
  if (htmlElements.length === 0) {
26438
26550
  throw new Error(`No elements found matching selector: "${target}"`);
26439
26551
  }
@@ -26442,7 +26554,7 @@ class InstallCommand {
26442
26554
  throw new Error('document is not available (not in browser environment)');
26443
26555
  }
26444
26556
  if (target && typeof target === 'object' && 'length' in target) {
26445
- const elements = Array.from(target).filter((t) => isHTMLElement(t));
26557
+ const elements = Array.from(target).filter((t) => isHTMLElement$2(t));
26446
26558
  if (elements.length === 0) {
26447
26559
  throw new Error('Target collection contains no valid HTMLElements');
26448
26560
  }
@@ -26450,7 +26562,7 @@ class InstallCommand {
26450
26562
  }
26451
26563
  if (typeof target === 'object' && 'element' in target) {
26452
26564
  const element = target.element;
26453
- if (isHTMLElement(element)) {
26565
+ if (isHTMLElement$2(element)) {
26454
26566
  return [element];
26455
26567
  }
26456
26568
  }
@@ -33335,22 +33447,6 @@ function withDefaultExtractors(tokenizer) {
33335
33447
  return tokenizer;
33336
33448
  }
33337
33449
 
33338
- // src/core/tokenization/char-classifiers.ts
33339
- function createUnicodeRangeClassifier(ranges) {
33340
- return (char) => {
33341
- const code = char.charCodeAt(0);
33342
- return ranges.some(([start, end]) => code >= start && code <= end);
33343
- };
33344
- }
33345
- function combineClassifiers(...classifiers) {
33346
- return (char) => classifiers.some((fn) => fn(char));
33347
- }
33348
- function createLatinCharClassifiers(letterPattern) {
33349
- const isLetter = (char) => letterPattern.test(char);
33350
- const isIdentifierChar = (char) => isLetter(char) || /[0-9_-]/.test(char);
33351
- return { isLetter, isIdentifierChar };
33352
- }
33353
-
33354
33450
  // src/core/tokenization/base-tokenizer.ts
33355
33451
  var SIMPLE_TOKENIZER_OPERATOR_SET = new Set(DEFAULT_OPERATORS$1);
33356
33452
  var MARKER_CONCEPT_NORMALIZEDS = /* @__PURE__ */ new Set([
@@ -34112,6 +34208,119 @@ function createSimpleTokenizer(config) {
34112
34208
  return new SimpleTokenizer();
34113
34209
  }
34114
34210
 
34211
+ // src/multilingual/builders.ts
34212
+ function mergeRoleMarkers(slice, vocab) {
34213
+ const merged = {};
34214
+ const add = (role, marker) => {
34215
+ if (!marker?.primary) {
34216
+ delete merged[role];
34217
+ return;
34218
+ }
34219
+ merged[role] = {
34220
+ primary: marker.primary,
34221
+ ...marker.alternatives?.length && { alternatives: [...marker.alternatives] },
34222
+ ...marker.position && { position: marker.position }
34223
+ };
34224
+ };
34225
+ for (const [role, marker] of Object.entries(slice.roleMarkers ?? {})) add(role, marker);
34226
+ for (const [role, marker] of Object.entries(vocab.roleMarkerOverrides ?? {})) add(role, marker);
34227
+ return merged;
34228
+ }
34229
+ function buildPatternProfile(slice, vocab) {
34230
+ const keywords = {};
34231
+ for (const [action, translation] of Object.entries(vocab.keywords)) {
34232
+ keywords[action] = {
34233
+ primary: translation.primary,
34234
+ ...translation.alternatives?.length && { alternatives: [...translation.alternatives] }
34235
+ };
34236
+ }
34237
+ const roleMarkers = mergeRoleMarkers(slice, vocab);
34238
+ return {
34239
+ code: slice.code,
34240
+ wordOrder: slice.wordOrder,
34241
+ keywords,
34242
+ ...Object.keys(roleMarkers).length > 0 && { roleMarkers }
34243
+ };
34244
+ }
34245
+ function defaultCaseInsensitive(script) {
34246
+ return script === void 0 || script === "latin" || script === "cyrillic";
34247
+ }
34248
+ function buildDomainTokenizer(slice, vocab, options = {}) {
34249
+ const roleMarkers = mergeRoleMarkers(slice, vocab);
34250
+ const keywords = /* @__PURE__ */ new Set();
34251
+ for (const translation of Object.values(vocab.keywords)) {
34252
+ keywords.add(translation.primary);
34253
+ for (const alt of translation.alternatives ?? []) keywords.add(alt);
34254
+ }
34255
+ for (const marker of Object.values(roleMarkers)) {
34256
+ keywords.add(marker.primary);
34257
+ for (const alt of marker.alternatives ?? []) keywords.add(alt);
34258
+ }
34259
+ for (const particle of slice.tokenization?.particles ?? []) keywords.add(particle);
34260
+ for (const extra of vocab.tokenizerKeywords ?? []) keywords.add(extra);
34261
+ const profileKeywords = {};
34262
+ for (const [action, translation] of Object.entries(vocab.keywords)) {
34263
+ profileKeywords[action] = {
34264
+ primary: translation.primary,
34265
+ ...translation.alternatives?.length && { alternatives: [...translation.alternatives] },
34266
+ normalized: translation.normalized ?? action
34267
+ };
34268
+ }
34269
+ const keywordProfile = {
34270
+ keywords: profileKeywords,
34271
+ ...Object.keys(roleMarkers).length > 0 && { roleMarkers }
34272
+ };
34273
+ const customExtractors = [
34274
+ ...options.customExtractors ?? [],
34275
+ ...slice.script === "latin" ? [new LatinExtendedIdentifierExtractor()] : []
34276
+ ];
34277
+ return createSimpleTokenizer({
34278
+ language: slice.code,
34279
+ direction: slice.direction ?? "ltr",
34280
+ keywords: [...keywords],
34281
+ ...vocab.keywordExtras?.length && { keywordExtras: vocab.keywordExtras.map((e) => ({ ...e })) },
34282
+ keywordProfile,
34283
+ includeOperators: options.includeOperators ?? false,
34284
+ caseInsensitive: options.caseInsensitive ?? defaultCaseInsensitive(slice.script),
34285
+ ...customExtractors.length > 0 && { customExtractors }
34286
+ });
34287
+ }
34288
+ function buildLanguageConfig(slice, vocab, meta = {}) {
34289
+ const name = meta.name ?? slice.name ?? slice.code;
34290
+ return {
34291
+ code: slice.code,
34292
+ name,
34293
+ nativeName: meta.nativeName ?? slice.nativeName ?? name,
34294
+ tokenizer: meta.tokenizer ?? buildDomainTokenizer(slice, vocab, meta.tokenizerOptions),
34295
+ patternProfile: buildPatternProfile(slice, vocab),
34296
+ ...meta.grammarProfile && { grammarProfile: meta.grammarProfile }
34297
+ };
34298
+ }
34299
+ function deriveRoleMarkers(slice, roleMapping) {
34300
+ const derived = {};
34301
+ for (const [domainRole, semanticRole] of Object.entries(roleMapping)) {
34302
+ const marker = slice.roleMarkers?.[semanticRole];
34303
+ if (marker?.primary) derived[domainRole] = marker.primary;
34304
+ }
34305
+ return derived;
34306
+ }
34307
+
34308
+ // src/core/tokenization/char-classifiers.ts
34309
+ function createUnicodeRangeClassifier(ranges) {
34310
+ return (char) => {
34311
+ const code = char.charCodeAt(0);
34312
+ return ranges.some(([start, end]) => code >= start && code <= end);
34313
+ };
34314
+ }
34315
+ function combineClassifiers(...classifiers) {
34316
+ return (char) => classifiers.some((fn) => fn(char));
34317
+ }
34318
+ function createLatinCharClassifiers(letterPattern) {
34319
+ const isLetter = (char) => letterPattern.test(char);
34320
+ const isIdentifierChar = (char) => isLetter(char) || /[0-9_-]/.test(char);
34321
+ return { isLetter, isIdentifierChar };
34322
+ }
34323
+
34115
34324
  // src/core/tokenization/morphology/types.ts
34116
34325
  function noChange(word) {
34117
34326
  return { stem: word, confidence: 1 };
@@ -34679,7 +34888,10 @@ var index$2 = /*#__PURE__*/Object.freeze({
34679
34888
  WhitespaceExtractor: WhitespaceExtractor,
34680
34889
  accumulateBlocks: accumulateBlocks,
34681
34890
  buildDisambiguation: buildDisambiguation,
34891
+ buildDomainTokenizer: buildDomainTokenizer,
34682
34892
  buildFeedback: buildFeedback,
34893
+ buildLanguageConfig: buildLanguageConfig,
34894
+ buildPatternProfile: buildPatternProfile,
34683
34895
  buildPhrase: buildPhrase,
34684
34896
  buildTablesFromProfiles: buildTablesFromProfiles,
34685
34897
  combineClassifiers: combineClassifiers,
@@ -34710,6 +34922,7 @@ var index$2 = /*#__PURE__*/Object.freeze({
34710
34922
  createUnicodeRangeClassifier: createUnicodeRangeClassifier,
34711
34923
  defineCommand: defineCommand,
34712
34924
  defineRole: defineRole,
34925
+ deriveRoleMarkers: deriveRoleMarkers,
34713
34926
  detectWordOrders: detectWordOrders,
34714
34927
  extractCssSelector: extractCssSelector$1,
34715
34928
  extractNumber: extractNumber,
@@ -74046,6 +74259,21 @@ init_turkish();
74046
74259
  init_ukrainian();
74047
74260
  init_vietnamese();
74048
74261
 
74262
+ // src/generators/profile-queries.ts
74263
+ function getKeywordTranslations(keyword, languages) {
74264
+ const codes = languages ?? Object.keys(KNOWN_PROFILES);
74265
+ const translations = {};
74266
+ for (const code of codes) {
74267
+ const translation = KNOWN_PROFILES[code]?.keywords[keyword];
74268
+ if (translation) translations[code] = translation;
74269
+ }
74270
+ return translations;
74271
+ }
74272
+ function getRoleMarkers(language, role) {
74273
+ const markers = KNOWN_PROFILES[language]?.roleMarkers ?? {};
74274
+ return role ? markers[role] : markers;
74275
+ }
74276
+
74049
74277
  // src/generators/index.ts
74050
74278
  init_command_schemas();
74051
74279
  init_pattern_generator();
@@ -74913,6 +75141,7 @@ var index$1 = /*#__PURE__*/Object.freeze({
74913
75141
  getEventHandlerPatternsForLanguage: getEventHandlerPatternsForLanguage,
74914
75142
  getGeneratorSummary: getGeneratorSummary,
74915
75143
  getHyperscriptExtractors: getHyperscriptExtractors,
75144
+ getKeywordTranslations: getKeywordTranslations,
74916
75145
  getLoadedLanguages: getLoadedLanguages,
74917
75146
  getPatternById: getPatternById,
74918
75147
  getPatternStats: getPatternStats,
@@ -74921,6 +75150,7 @@ var index$1 = /*#__PURE__*/Object.freeze({
74921
75150
  getPutPatternsForLanguage: getPutPatternsForLanguage,
74922
75151
  getRegisteredLanguages: getRegisteredLanguages,
74923
75152
  getRegisteredMappers: getRegisteredMappers,
75153
+ getRoleMarkers: getRoleMarkers,
74924
75154
  getSchema: getSchema,
74925
75155
  getSchemasByCategory: getSchemasByCategory,
74926
75156
  getSupportedCommands: getSupportedCommands,
@@ -75014,9 +75244,9 @@ function createHistorySwap(config) {
75014
75244
  const resolveTarget = () => {
75015
75245
  if (typeof target === 'string') {
75016
75246
  const element = document.querySelector(target);
75017
- return isHTMLElement(element) ? element : null;
75247
+ return isHTMLElement$2(element) ? element : null;
75018
75248
  }
75019
- return isHTMLElement(target) ? target : null;
75249
+ return isHTMLElement$2(target) ? target : null;
75020
75250
  };
75021
75251
  const handlePopstate = async (_event) => {
75022
75252
  const targetElement = resolveTarget();
@@ -75132,9 +75362,9 @@ function createBoosted(config) {
75132
75362
  }
75133
75363
  if (typeof target === 'string') {
75134
75364
  const element = document.querySelector(target);
75135
- return isHTMLElement(element) ? element : null;
75365
+ return isHTMLElement$2(element) ? element : null;
75136
75366
  }
75137
- return isHTMLElement(target) ? target : null;
75367
+ return isHTMLElement$2(target) ? target : null;
75138
75368
  };
75139
75369
  const boost = async (url, method = 'GET', body = null) => {
75140
75370
  const targetElement = resolveTarget();
@@ -75918,6 +76148,7 @@ const config = {
75918
76148
  confidenceThreshold: DEFAULT_CONFIDENCE_THRESHOLD,
75919
76149
  logAll: false,
75920
76150
  conversions: conversionConfig.conversions,
76151
+ onCompileError: null,
75921
76152
  };
75922
76153
  async function getOrCreateBridge() {
75923
76154
  if (!bridgeInstance) {
@@ -83655,6 +83886,8 @@ exports.formatIssueAsString = formatIssueAsString;
83655
83886
  exports.formatIssuesAsStrings = formatIssuesAsStrings;
83656
83887
  exports.formatResultSummary = formatResultSummary;
83657
83888
  exports.fromCoreAST = fromCoreAST;
83889
+ exports.getElementScopeMap = getElementScopeMap;
83890
+ exports.getElementVar = getElementVar;
83658
83891
  exports.getParserExtensionRegistry = getParserExtensionRegistry;
83659
83892
  exports.getPartialValidationConfig = getPartialValidationConfig;
83660
83893
  exports.hyperscript = hyperscript;
@@ -83662,6 +83895,8 @@ exports.installPlugin = installPlugin;
83662
83895
  exports.lokascript = lokascript;
83663
83896
  exports.parse = parse$1;
83664
83897
  exports.resetPartialValidationConfig = resetPartialValidationConfig;
83898
+ exports.resolveScopeOwner = resolveScopeOwner;
83899
+ exports.setElementVar = setElementVar;
83665
83900
  exports.setGlobal = setGlobal;
83666
83901
  exports.toCoreAST = toCoreAST;
83667
83902
  exports.validatePartialContent = validatePartialContent;