'use strict';

// src/types.ts
var Operations = /* @__PURE__ */ ((Operations2) => {
  Operations2["SUBTRACT"] = "-";
  Operations2["ADD"] = "+";
  Operations2["MULTIPLY"] = "*";
  Operations2["DIVIDE"] = "/";
  Operations2["POWER"] = "^";
  Operations2["LOGIC_AND"] = "&&";
  Operations2["LOGIC_OR"] = "||";
  Operations2["LOGIC_NOT"] = "!";
  return Operations2;
})(Operations || {});
var SupportedFormats = /* @__PURE__ */ ((SupportedFormats2) => {
  SupportedFormats2["PX"] = "px";
  SupportedFormats2["EM"] = "em";
  SupportedFormats2["REM"] = "rem";
  SupportedFormats2["VW"] = "vw";
  SupportedFormats2["VH"] = "vh";
  SupportedFormats2["PT"] = "pt";
  SupportedFormats2["IN"] = "in";
  SupportedFormats2["CM"] = "cm";
  SupportedFormats2["MM"] = "mm";
  SupportedFormats2["DEG"] = "deg";
  SupportedFormats2["PERCENTAGE"] = "%";
  return SupportedFormats2;
})(SupportedFormats || {});
var ReservedKeyword = /* @__PURE__ */ ((ReservedKeyword2) => {
  ReservedKeyword2["TRUE"] = "true";
  ReservedKeyword2["FALSE"] = "false";
  ReservedKeyword2["NULL"] = "null";
  ReservedKeyword2["UNDEFINED"] = "undefined";
  ReservedKeyword2["WHILE"] = "while";
  ReservedKeyword2["IF"] = "if";
  ReservedKeyword2["ELSE"] = "else";
  ReservedKeyword2["ELIF"] = "elif";
  ReservedKeyword2["RETURN"] = "return";
  ReservedKeyword2["VARIABLE"] = "variable";
  return ReservedKeyword2;
})(ReservedKeyword || {});

// src/interpreter/errors/messages/en.ts
var messages = {
  // Lexer errors
  ["LEXER_INVALID_CHARACTER" /* INVALID_CHARACTER */]: (data) => `Invalid character '${data.char}' at position ${data.position}.${data.description ? ` ${data.description}` : ""}`,
  ["LEXER_UNTERMINATED_STRING" /* UNTERMINATED_STRING */]: (data) => `Unterminated string, missing '${data.quoteType}'.`,
  ["LEXER_UNTERMINATED_REFERENCE" /* UNTERMINATED_REFERENCE */]: "Unterminated reference, missing '}'.",
  ["LEXER_EMPTY_VARIABLE_NAME" /* EMPTY_VARIABLE_NAME */]: "Empty variable name.",
  ["LEXER_INVALID_HEX_COLOR_FORMAT" /* INVALID_HEX_COLOR_FORMAT */]: (data) => `Invalid hex color format: ${data.value}. Length should be ${data.expectedLength}.`,
  ["LEXER_EXPECTED_CHARACTER" /* EXPECTED_CHARACTER */]: (data) => `Expected character ${data.expected} got ${data.got}`,
  // Parser errors
  ["PARSER_UNEXPECTED_TOKEN" /* UNEXPECTED_TOKEN */]: (data) => `Unexpected token: ${data.token}`,
  ["PARSER_EXPECTED_TOKEN_TYPE" /* EXPECTED_TOKEN_TYPE */]: (data) => `Expected token type ${data.expected} but got ${data.got}`,
  ["PARSER_CONDITION_MUST_BE_BOOLEAN" /* CONDITION_MUST_BE_BOOLEAN */]: "If/elif condition must be a boolean",
  ["PARSER_INVALID_SYNTAX" /* INVALID_SYNTAX */]: (data) => data?.message ? String(data.message) : "Invalid syntax",
  ["PARSER_UNEXPECTED_END" /* UNEXPECTED_END */]: "Unexpected end of input",
  // Interpreter errors
  ["INT_UNKNOWN_NODE_TYPE" /* UNKNOWN_NODE_TYPE */]: (data) => `No visit method for AST node type: ${data.nodeType}`,
  ["INT_ARITHMETIC_REQUIRES_NUMBER" /* ARITHMETIC_REQUIRES_NUMBER */]: (data) => `Arithmetic operator ${data.operator} requires Number or NumberWithUnit operands, got ${data.leftType} and ${data.rightType}.`,
  ["INT_UNKNOWN_BINARY_OPERATOR" /* UNKNOWN_BINARY_OPERATOR */]: (data) => `Unknown binary operator: ${data.operator} or type ${data.tokenType}`,
  ["INT_UNARY_MINUS_NULL" /* UNARY_MINUS_NULL */]: (data) => `Cannot apply unary '-' to a null ${data.symbolType}.`,
  ["INT_UNARY_PLUS_NON_NUMBER" /* UNARY_PLUS_NON_NUMBER */]: (data) => `Cannot apply unary '+' to non-number value: ${data.value}`,
  ["INT_UNARY_NOT_NON_BOOLEAN" /* UNARY_NOT_NON_BOOLEAN */]: (data) => `Cannot apply NOT to non-boolean value: ${data.value}.`,
  ["INT_UNKNOWN_UNARY_OPERATOR" /* UNKNOWN_UNARY_OPERATOR */]: (data) => `Unknown unary operator type: ${data.operator}`,
  ["INT_UNKNOWN_REFERENCE" /* UNKNOWN_REFERENCE */]: (data) => `Unknown reference: ${data.reference}`,
  ["INT_UNKNOWN_FUNCTION" /* UNKNOWN_FUNCTION */]: (data) => `Unknown function: '${data.functionName}'`,
  ["INT_INVALID_VARIABLE_NAME" /* INVALID_VARIABLE_NAME */]: (data) => `Invalid variable name '${data.name}'. Use a simple name (and underscores) without '.', '-', '['.`,
  ["INT_VARIABLE_ALREADY_DEFINED" /* VARIABLE_ALREADY_DEFINED */]: (data) => `Variable '${data.name}' already defined. Use a different name.`,
  ["INT_INVALID_VARIABLE_TYPE" /* INVALID_VARIABLE_TYPE */]: (data) => `Invalid variable type '${data.typeName}'. Use a valid type. (${data.validTypes})`,
  ["INT_INVALID_VALUE_FOR_VARIABLE" /* INVALID_VALUE_FOR_VARIABLE */]: (data) => `Invalid value '${data.value}' ('${data.type}') for variable '${data.name}'. Use a valid value.`,
  ["INT_VARIABLE_NOT_FOUND" /* VARIABLE_NOT_FOUND */]: (data) => `Variable '${data.name}' not found.`,
  ["INT_ASSIGNMENT_VALUE_NULL" /* ASSIGNMENT_VALUE_NULL */]: (data) => `Assignment value for '${data.identifier}' is null.`,
  ["INT_TYPE_MISMATCH" /* TYPE_MISMATCH */]: (data) => `Invalid value '${data.value}' (Found '${data.foundType}', expected '${data.expectedType}') for variable '${data.identifier}'. Use a valid value.`,
  ["INT_CANNOT_ASSIGN_TYPE" /* CANNOT_ASSIGN_TYPE */]: (data) => `Cannot assign ${data.valueType} to variable '${data.identifier}' of type ${data.variableType}.`,
  ["INT_METHOD_RETURNED_NULL" /* METHOD_RETURNED_NULL */]: (data) => `Method '${data.methodName}' returned null or undefined`,
  ["INT_METHOD_NOT_FOUND" /* METHOD_NOT_FOUND */]: (data) => `Method '${data.methodName}' not found on '${data.value}' (${data.type})`,
  ["INT_ATTRIBUTE_RETURNED_NULL" /* ATTRIBUTE_RETURNED_NULL */]: (data) => `Attribute '${data.attributeName}' returned null or undefined`,
  ["INT_ATTRIBUTE_NOT_FOUND" /* ATTRIBUTE_NOT_FOUND */]: (data) => `Attribute '${data.attributeName}' not found on '${data.value}' (${data.type})`,
  ["INT_CANNOT_ACCESS_ATTRIBUTES" /* CANNOT_ACCESS_ATTRIBUTES */]: (data) => `Cannot access attributes on ${data.type}`,
  ["INT_MAX_ITERATIONS_EXCEEDED" /* MAX_ITERATIONS_EXCEEDED */]: "Max iterations exceeded in while loop.",
  ["INT_WHILE_CONDITION_NOT_BOOLEAN" /* WHILE_CONDITION_NOT_BOOLEAN */]: "While loop condition must be a boolean.",
  ["INT_IF_CONDITION_NOT_BOOLEAN" /* IF_CONDITION_NOT_BOOLEAN */]: "If/elif condition must be a boolean.",
  ["INT_UNKNOWN_ERROR" /* UNKNOWN_ERROR */]: "An unknown error occurred during interpretation.",
  // Operations errors
  ["OP_UNSUPPORTED_OPERAND_TYPE" /* UNSUPPORTED_OPERAND_TYPE */]: (data) => `Unsupported operand type for unit decomposition: ${data.type}`,
  ["OP_CANNOT_MIX_UNITS" /* CANNOT_MIX_UNITS */]: (data) => `Cannot mix units: ${data.units.join(", ")}`,
  ["OP_INCOMPATIBLE_TYPES" /* INCOMPATIBLE_TYPES */]: (data) => `Cannot compare ${data.typeA} with ${data.typeB}. Incompatible types.`,
  ["OP_CANNOT_COMPARE_UNITS" /* CANNOT_COMPARE_UNITS */]: (data) => `Cannot compare NumberWithUnit of different units: ${data.unitA} and ${data.unitB}`,
  ["OP_ORDERING_WITH_NULL" /* ORDERING_WITH_NULL */]: "Cannot perform ordering comparison with null values.",
  ["OP_LOGICAL_REQUIRES_BOOLEAN" /* LOGICAL_REQUIRES_BOOLEAN */]: (data) => `${data.operator} operator requires boolean operands.`,
  ["OP_DIVISION_BY_ZERO" /* DIVISION_BY_ZERO */]: "Division by zero.",
  ["OP_UNIT_EXPONENT_NOT_SUPPORTED" /* UNIT_EXPONENT_NOT_SUPPORTED */]: (data) => `Cannot raise ${data.unitA} to the power of ${data.unitB}. Unit exponents are not supported.`,
  // Symbols errors
  ["SYM_VALUE_MUST_BE_TYPE" /* VALUE_MUST_BE_TYPE */]: (data) => `Value must be ${data.expectedType}, got ${data.actualType}.`,
  ["SYM_VALUE_IS_NULL" /* VALUE_IS_NULL */]: (data) => `Value must be ${data.expectedType}, got null.`,
  ["SYM_METHOD_NOT_FOUND" /* METHOD_NOT_FOUND */]: (data) => `Method '${data.methodName}' not found or invalid arguments on type '${data.type}'.`,
  ["SYM_MISSING_REQUIRED_ARGUMENT" /* MISSING_REQUIRED_ARGUMENT */]: (data) => `Missing required argument '${data.argumentName}' for method '${data.methodName}'.`,
  ["SYM_ATTRIBUTE_NOT_FOUND" /* ATTRIBUTE_NOT_FOUND */]: (data) => `Attribute '${data.attributeName}' not found on ${data.type}.`,
  ["SYM_CANNOT_SET_ATTRIBUTE" /* CANNOT_SET_ATTRIBUTE */]: (data) => `Cannot set attribute '${data.attributeName}' on type '${data.type}'.`,
  ["SYM_INVALID_RADIX" /* INVALID_RADIX */]: (data) => `Invalid radix: ${data.radix}. Must be between 2 and 36.`,
  ["SYM_RADIX_CONVERSION_ERROR" /* RADIX_CONVERSION_ERROR */]: (data) => `Error converting to base ${data.base}: ${data.error}.`,
  ["SYM_CANNOT_CONCATENATE" /* CANNOT_CONCATENATE */]: (data) => `Cannot concatenate ${data.type} to String.`,
  ["SYM_CANNOT_SPLIT" /* CANNOT_SPLIT */]: (data) => `Cannot split String by ${data.type}.`,
  ["SYM_INDEX_OUT_OF_RANGE" /* INDEX_OUT_OF_RANGE */]: (data) => `Index out of range for ${data.operation}.`,
  ["SYM_KEY_MUST_BE_STRING" /* KEY_MUST_BE_STRING */]: (data) => `Key must be a StringSymbol or string, got ${data.type}.`,
  ["SYM_CANNOT_OPERATION_ON_TOKEN_TYPE" /* CANNOT_OPERATION_ON_TOKEN_TYPE */]: (data) => `Cannot ${data.operation} Token with ${data.valueType} value.`,
  ["SYM_INVALID_HEX_COLOR" /* INVALID_HEX_COLOR */]: (data) => `Invalid hex color format: ${data.value}`,
  ["SYM_COLOR_MANAGER_NOT_AVAILABLE" /* COLOR_MANAGER_NOT_AVAILABLE */]: "ColorManager not available",
  ["SYM_INVALID_COLOR_VALUE" /* INVALID_COLOR_VALUE */]: (data) => `Value ${data.value} must be string, attributes record, or null, got ${data.type}.`,
  // Functions errors
  ["FN_EXPECTS_NUMBER_ARGUMENTS" /* EXPECTS_NUMBER_ARGUMENTS */]: (data) => `${data.functionName}() expects number arguments.`,
  ["FN_REQUIRES_MIN_ARGUMENTS" /* REQUIRES_MIN_ARGUMENTS */]: (data) => `${data.functionName}() requires at least ${data.minArgs} argument${data.minArgs === 1 ? "" : "s"}.`,
  ["FN_EXPECTS_TYPE_ARGUMENT" /* EXPECTS_TYPE_ARGUMENT */]: (data) => `${data.functionName}() expects ${data.expectedType} as ${data.argumentPosition} argument.`,
  ["FN_DIVISION_BY_ZERO" /* DIVISION_BY_ZERO */]: (data) => `${data.functionName}() division by zero.`,
  ["FN_ARGUMENT_OUT_OF_RANGE" /* ARGUMENT_OUT_OF_RANGE */]: (data) => `${data.functionName}() argument must be ${data.constraint}.`,
  ["FN_INVALID_BASE" /* INVALID_BASE */]: (data) => `${data.functionName}() base must be ${data.constraint}.`,
  ["FN_PARSE_ERROR" /* PARSE_ERROR */]: (data) => `Invalid string for ${data.functionName}: "${data.value}" with base ${data.base}.`,
  ["FN_UNIT_CONVERSION_FAILED" /* UNIT_CONVERSION_FAILED */]: (data) => `${data.functionName || "function"}() unit conversion failed${data.error ? `: ${data.error}` : ""}`,
  ["FN_NO_CONFIG_AVAILABLE" /* NO_CONFIG_AVAILABLE */]: (data) => `No config available for dynamic function '${data.functionName || "unknown"}'`,
  ["FN_FUNCTION_RETURNED_NULL" /* FUNCTION_RETURNED_NULL */]: (data) => `Dynamic function '${data.functionName || "unknown"}' returned null`,
  ["FN_EXECUTION_ERROR" /* EXECUTION_ERROR */]: (data) => `Error executing dynamic function '${data.functionName || "unknown"}'${data.error ? `: ${data.error}` : ""}`,
  // Config errors
  ["CFG_NO_SPEC_FOUND" /* NO_SPEC_FOUND */]: (data) => `No spec found for ${data.specName}`,
  ["CFG_NO_TYPE_FOUND" /* NO_TYPE_FOUND */]: (data) => `No type found for ${data.typeName}`,
  // Processor errors
  ["PROC_TOKEN_NOT_FOUND" /* TOKEN_NOT_FOUND */]: (data) => `Token '${data.tokenName}' not found`,
  ["PROC_CIRCULAR_DEPENDENCY" /* CIRCULAR_DEPENDENCY */]: (data) => `Circular dependency detected: ${Array.isArray(data.tokens) ? data.tokens.join(", ") : data.tokens}`,
  ["PROC_SUB_FIELD_NOT_RESOLVED" /* SUB_FIELD_NOT_RESOLVED */]: (data) => `Sub-field '${data.fieldPath}' not resolved`,
  ["PROC_DEPENDENCY_ERROR" /* DEPENDENCY_ERROR */]: (data) => `Token '${data.tokenName}' failed due to dependency error: ${data.chain}
Root cause: ${data.rootCause}`,
  ["PROC_NO_THEMES_FOUND" /* NO_THEMES_FOUND */]: (data) => `No themes found for theme "${data.themeName}"`,
  ["PROC_THEME_NOT_FOUND" /* THEME_NOT_FOUND */]: (data) => `Theme "${data.themeName}" not found. Available: ${data.availableThemes.join(", ")}`,
  ["PROC_TOKEN_SET_NOT_FOUND" /* TOKEN_SET_NOT_FOUND */]: (data) => `Token set "${data.setName}" not found`,
  ["PROC_TOKEN_SET_INVALID" /* TOKEN_SET_INVALID */]: (data) => `Token set "${data.setName}" is not an object`,
  ["PROC_NO_SETS_TO_PROCESS" /* NO_SETS_TO_PROCESS */]: "No sets to process",
  ["PROC_MULTIPLE_SETS_NO_SELECTION" /* MULTIPLE_SETS_NO_SELECTION */]: (data) => `Multiple sets found (${data.setNames.join(", ")}) - specify activeSets or activeTheme`,
  // Color errors
  ["COLOR_INITIALIZER_CRASHED" /* INITIALIZER_CRASHED */]: "Initializer crashed!",
  ["COLOR_INITIALIZER_CONSTRUCT_FAILED" /* INITIALIZER_CONSTRUCT_FAILED */]: (data) => `Could not construct initializer from schema${data.error ? `: ${data.error}` : ""}`,
  ["COLOR_INITIALIZER_NOT_FOUND" /* INITIALIZER_NOT_FOUND */]: (data) => `No initializer found for keyword '${data.keyword}'`,
  ["COLOR_CONVERSION_TARGET_NOT_FOUND" /* CONVERSION_TARGET_NOT_FOUND */]: (data) => `Conversion function crashed! No target spec found for ${data.targetUri}`,
  ["COLOR_SOURCE_URI_NOT_FOUND" /* SOURCE_URI_NOT_FOUND */]: (data) => `No source URI found for color type '${data.colorType}'`,
  ["COLOR_TARGET_URI_NOT_FOUND" /* TARGET_URI_NOT_FOUND */]: (data) => `No target URI found for color type '${data.colorType}'`,
  ["COLOR_CONVERSION_ERROR" /* CONVERSION_ERROR */]: (data) => data.message ? String(data.message) : "Color conversion failed",
  ["COLOR_STRING_VALUE_ASSIGNMENT" /* STRING_VALUE_ASSIGNMENT */]: (data) => `Cannot set attributes '${data.attributes}' for variable ${data.identifier} on Color type ${data.colorType}.`,
  ["COLOR_ATTRIBUTE_CHAIN_TOO_LONG" /* ATTRIBUTE_CHAIN_TOO_LONG */]: (data) => `Attributes chain '${data.attributes}' for variable ${data.identifier} on Color type ${data.colorType} may not exceed one element.`,
  ["COLOR_MISSING_SPEC" /* MISSING_SPEC */]: (data) => `No spec ${data.colorType} defined for variable ${data.identifier} on Color type ${data.colorType}.`,
  ["COLOR_MISSING_SCHEMA" /* MISSING_SCHEMA */]: (data) => `No schema defined for Color type ${data.colorType}.`,
  ["COLOR_MISSING_ATTRIBUTE_SCHEMA" /* MISSING_ATTRIBUTE_SCHEMA */]: (data) => `No schema found for key ${data.attribute} for variable ${data.identifier} on Color type ${data.colorType}.`,
  ["COLOR_INVALID_ATTRIBUTE_TYPE" /* INVALID_ATTRIBUTE_TYPE */]: (data) => `Invalid attribute type '${data.attributeType}'. Use a valid type. (${data.validTypes})`,
  // Unit errors
  ["UNIT_CONVERSION_CRASHED" /* CONVERSION_CRASHED */]: (data) => `Conversion function crashed!${data.error ? ` ${data.error}` : ""}`,
  ["UNIT_SOURCE_URI_NOT_FOUND" /* SOURCE_URI_NOT_FOUND */]: (data) => `No source URI found for unit '${data.unit}'`,
  ["UNIT_RELATIVE_REQUIRES_TWO_NUMBERS" /* RELATIVE_REQUIRES_TWO_NUMBERS */]: "Relative conversion requires exactly 2 numbers",
  ["UNIT_NO_TO_ABSOLUTE_SCRIPT" /* NO_TO_ABSOLUTE_SCRIPT */]: (data) => `No to_absolute script found for relative unit '${data.unit}'`,
  ["UNIT_TO_ABSOLUTE_MUST_RETURN_NUMBER" /* TO_ABSOLUTE_MUST_RETURN_NUMBER */]: "to_absolute script must return a number",
  ["UNIT_CANNOT_CONVERT_MULTIPLE_RELATIVE" /* CANNOT_CONVERT_MULTIPLE_RELATIVE */]: "Cannot convert multiple relative units to a common format.",
  ["UNIT_NO_VALID_CONVERSION_PATH" /* NO_VALID_CONVERSION_PATH */]: "No valid conversion paths found for the provided inputs."
};

// src/interpreter/errors/messages/index.ts
var getMessage = (code, data) => {
  const template = messages[code];
  if (!template) {
    return `Unknown error: ${code}`;
  }
  if (typeof template === "function") {
    return template(data || {});
  }
  return template;
};

// src/interpreter/errors/base.ts
var LanguageError = class extends Error {
  constructor(code, options) {
    const message = getMessage(code, options?.data);
    super(message, options?.cause ? { cause: options.cause } : void 0);
    this.name = this.constructor.name;
    this.code = code;
    this.data = options?.data || {};
    this.token = options?.token;
    this.line = options?.line ?? options?.token?.line;
    this.originalMessage = message;
    this.message = this.formatMessage();
  }
  formatMessage() {
    let base = this.originalMessage;
    if (this.line !== void 0) {
      base = `Line ${this.line}: ${base}`;
    }
    if (this.token?.value) {
      base += `
Near token: ${String(this.token.value)}`;
    }
    return base;
  }
};
var InterpreterError = class extends LanguageError {
  constructor(code, options) {
    super(code, options);
    this.name = "InterpreterError";
    this.code = code;
  }
};

// src/interpreter/utils/type.ts
var isSome = (v) => {
  return v != null;
};
var isNone = (v) => {
  return v == null;
};
var isNull = (v) => {
  return v === null;
};
var isUndefined = (v) => {
  return v === void 0;
};
var isObject = (v) => {
  return typeof v === "object" && v !== null && !Array.isArray(v);
};
var isString = (v) => {
  return typeof v === "string";
};
var isNumber = (v) => {
  return typeof v === "number" && !Number.isNaN(v);
};
var isArray = (v) => {
  return Array.isArray(v);
};
var isMap = (v) => v instanceof Map;
var isOutOfBounds = (value, index) => {
  if (!isArray(value)) return true;
  return index < 0 || index >= value.length;
};
var isOutOfBoundsInclusive = (value, index) => {
  if (!isArray(value)) return true;
  return index < 0 || index > value.length;
};
var nullToUndefined = (v) => isNull(v) ? void 0 : v;

// src/interpreter/utils/color.ts
function isValidHex(value) {
  if (!isString(value)) return false;
  if (!value.startsWith("#")) return false;
  const hexPart = value.substring(1);
  if (!(hexPart.length === 3 || hexPart.length === 6)) return false;
  for (let i = 0; i < hexPart.length; i++) {
    const char = hexPart[i].toLowerCase();
    if (!(char >= "0" && char <= "9" || char >= "a" && char <= "f")) {
      return false;
    }
  }
  return true;
}

// src/interpreter/utils/string.ts
var capitalize = (str) => `${str.charAt(0).toUpperCase()}${str.slice(1).toLowerCase()}`;

// src/interpreter/symbols.ts
var typeEquals = (typeA, typeB) => typeA?.toLowerCase() === typeB?.toLowerCase();
var typeName = (base, sub) => {
  const baseStr = capitalize(base);
  if (sub) {
    const subStr = capitalize(sub);
    return `${baseStr}.${subStr}`;
  }
  return baseStr;
};
var formatObjectEntries = (data) => {
  let entries;
  if (isArray(data)) {
    entries = data;
  } else if (isMap(data)) {
    entries = Array.from(data.entries());
  } else {
    entries = Object.entries(data);
  }
  const formattedEntries = entries.map(([key, value]) => `${key}: ${String(value)}`).join(", ");
  return `{${formattedEntries}}`;
};
var expectStringKey = (key) => {
  if (isString(key)) {
    return key;
  }
  if (key instanceof StringSymbol && isSome(key.value)) {
    return key.value;
  }
  throw new InterpreterError("SYM_KEY_MUST_BE_STRING" /* KEY_MUST_BE_STRING */, {
    data: { type: typeof key }
  });
};
var DictionaryImpl = {
  get(value, key, config) {
    const keyStr = expectStringKey(key);
    const result = value.get(keyStr);
    if (isSome(result)) {
      return result;
    }
    return new NullSymbol(config);
  },
  set(value, key, val) {
    const keyStr = expectStringKey(key);
    value.set(keyStr, val.cloneIfMutable());
  },
  deleteKey(value, key) {
    const keyStr = expectStringKey(key);
    value.delete(keyStr);
  },
  keys(value, config) {
    const keys = Array.from(value.keys()).map((key) => new StringSymbol(key, config));
    return new ListSymbol(keys, false, config);
  },
  values(value, config) {
    const values = Array.from(value.values());
    return new ListSymbol(values, false, config);
  },
  keyExists(value, key, config) {
    const keyStr = expectStringKey(key);
    return new BooleanSymbol(value.has(keyStr), config);
  },
  length(value, config) {
    return new NumberSymbol(value.size, config);
  },
  clear(value) {
    value.clear();
  },
  deepCopy(value) {
    const copiedMap = /* @__PURE__ */ new Map();
    for (const [key, val] of value.entries()) {
      copiedMap.set(key, val.deepCopy());
    }
    return copiedMap;
  },
  toString(value) {
    return formatObjectEntries(value);
  },
  hasAttribute(value, attributeName) {
    return value.has(attributeName);
  },
  getAttribute(value, attributeName) {
    const val = value.get(attributeName);
    return val !== void 0 ? val : null;
  }
};
var ListImpl = {
  append(value, item) {
    value.push(item.cloneIfMutable());
  },
  extend(value, ...items) {
    for (const item of items) {
      if (item instanceof ListSymbol) {
        value.push(...item.value.map((element) => element.cloneIfMutable()));
      } else {
        value.push(item.cloneIfMutable());
      }
    }
  },
  insert(value, indexSymbol, item) {
    const index = indexSymbol.value;
    if (isOutOfBoundsInclusive(value, index)) {
      throw new InterpreterError("SYM_INDEX_OUT_OF_RANGE" /* INDEX_OUT_OF_RANGE */, {
        data: { operation: "insert" }
      });
    }
    value.splice(index, 0, item.cloneIfMutable());
  },
  deleteAt(value, indexSymbol) {
    const index = indexSymbol.value;
    if (isOutOfBounds(value, index)) {
      throw new InterpreterError("SYM_INDEX_OUT_OF_RANGE" /* INDEX_OUT_OF_RANGE */, {
        data: { operation: "deletion" }
      });
    }
    value.splice(index, 1);
  },
  length(value, config) {
    return new NumberSymbol(value.length, config);
  },
  indexOf(value, item, config) {
    const idx = value.findIndex((el) => el.equals(item));
    return new NumberSymbol(idx, config);
  },
  get(value, indexSymbol) {
    const index = indexSymbol.value;
    if (isOutOfBounds(value, index)) {
      throw new InterpreterError("SYM_INDEX_OUT_OF_RANGE" /* INDEX_OUT_OF_RANGE */, {
        data: { operation: "get" }
      });
    }
    return value[index];
  },
  update(value, indexSymbol, item) {
    const index = indexSymbol.value;
    if (isOutOfBounds(value, index)) {
      throw new InterpreterError("SYM_INDEX_OUT_OF_RANGE" /* INDEX_OUT_OF_RANGE */, {
        data: { operation: "update" }
      });
    }
    value[index] = item.cloneIfMutable();
  },
  join(value, separator, config) {
    const sep = separator?.value || "";
    const stringElements = value.map((element) => {
      if (element.value === null) {
        return "null";
      }
      return element.toString();
    });
    return new StringSymbol(stringElements.join(sep), config);
  },
  deepCopy(value) {
    return value.map((element) => element.deepCopy());
  },
  toString(value, isImplicit = false) {
    const delimiter = isImplicit ? " " : ", ";
    return value.map((x) => x.value === null ? "null" : x.toString()).join(delimiter);
  }
};
var BaseSymbolType = class {
  constructor(value, config) {
    this.value = value;
    this.config = config;
  }
  toString() {
    return String(this.value);
  }
  getTypeName() {
    return this.type;
  }
  typeEquals(other) {
    return typeEquals(this.type, other.type);
  }
  equals(other) {
    return this.typeEquals(other) && this.value === other.value;
  }
  hasMethod(methodName, args) {
    const methodDefinition = this.constructor._SUPPORTED_METHODS?.[methodName.toLowerCase()];
    if (!methodDefinition) return false;
    if (methodDefinition.args.length === 0) return true;
    const requiredArgs = methodDefinition.args.filter((arg) => !arg.optional);
    if (args.length < requiredArgs.length) {
      return false;
    }
    if (args.length > methodDefinition.args.length) {
      return false;
    }
    return true;
  }
  callMethod(methodName, args) {
    const methodDefinition = this.constructor._SUPPORTED_METHODS?.[methodName.toLowerCase()];
    if (!methodDefinition || !this.hasMethod?.(methodName, args)) {
      throw new InterpreterError("SYM_METHOD_NOT_FOUND" /* METHOD_NOT_FOUND */, {
        data: { methodName, type: this.type }
      });
    }
    if (methodDefinition.args.length === 0) {
      return methodDefinition.function.call(this, ...args);
    }
    const processedArgs = [];
    methodDefinition.args.forEach((argDef, index) => {
      if (args[index] !== void 0) {
        processedArgs.push(args[index]);
      } else if (!argDef.optional) {
        throw new InterpreterError("SYM_MISSING_REQUIRED_ARGUMENT" /* MISSING_REQUIRED_ARGUMENT */, {
          data: { argumentName: argDef.name, methodName }
        });
      }
    });
    return methodDefinition.function.call(this, ...processedArgs);
  }
  hasAttribute(_attributeName) {
    return false;
  }
  getAttribute(attributeName) {
    throw new InterpreterError("SYM_ATTRIBUTE_NOT_FOUND" /* ATTRIBUTE_NOT_FOUND */, {
      data: { attributeName, type: this.type }
    });
  }
  setAttribute(attributeName, _value) {
    throw new InterpreterError("SYM_CANNOT_SET_ATTRIBUTE" /* CANNOT_SET_ATTRIBUTE */, {
      data: { attributeName, type: this.type }
    });
  }
};
var _NullSymbol = class _NullSymbol extends BaseSymbolType {
  constructor(config) {
    super(null, config);
    this.type = "Null";
  }
  validValue(val) {
    return isNone(val);
  }
  toString() {
    return "null";
  }
  deepCopy() {
    return new _NullSymbol(this.config);
  }
  cloneIfMutable() {
    return this;
  }
  equals(other) {
    return other instanceof _NullSymbol;
  }
  static empty() {
    return new _NullSymbol();
  }
};
_NullSymbol.type = "Null";
var NullSymbol = _NullSymbol;
var _NumberSymbol = class _NumberSymbol extends BaseSymbolType {
  constructor(value, config) {
    let safeValue;
    if (isNumber(value)) {
      safeValue = value;
    } else if (value instanceof _NumberSymbol || value instanceof NumberWithUnitSymbol) {
      safeValue = value.value;
    } else if (isNull(value)) {
      safeValue = null;
    } else {
      throw new InterpreterError("SYM_VALUE_MUST_BE_TYPE" /* VALUE_MUST_BE_TYPE */, {
        data: { expectedType: "int or float", actualType: typeof value }
      });
    }
    super(safeValue, config);
    this.type = "Number";
    this.value = safeValue;
  }
  validValue(val) {
    return isNumber(val) || val instanceof _NumberSymbol;
  }
  expectSafeValue(val) {
    if (isNone(val)) {
      throw new InterpreterError("SYM_VALUE_IS_NULL" /* VALUE_IS_NULL */, {
        data: { expectedType: "int or float" }
      });
    }
  }
  toString() {
    return String(this.value);
  }
  deepCopy() {
    return new _NumberSymbol(this.value, this.config);
  }
  cloneIfMutable() {
    return this;
  }
  static empty() {
    return new _NumberSymbol(null);
  }
  hasAttribute(attributeName) {
    return attributeName === "value";
  }
  getAttribute(attributeName) {
    if (attributeName === "value") {
      return new _NumberSymbol(this.value, this.config);
    }
    throw new InterpreterError("SYM_ATTRIBUTE_NOT_FOUND" /* ATTRIBUTE_NOT_FOUND */, {
      data: { attributeName, type: "Number" }
    });
  }
  // Direct translation of to_string method from token_interpreter/symbols.py
  toStringSymbol(radix) {
    this.expectSafeValue(this.value);
    if (radix) {
      this.expectSafeValue(radix?.value);
    } else {
      return new StringSymbol(String(this.value), this.config);
    }
    const base = radix.value;
    if (!Number.isInteger(base) || base < 2 || base > 36) {
      throw new InterpreterError("SYM_INVALID_RADIX" /* INVALID_RADIX */, {
        data: { radix: base }
      });
    }
    let numValue;
    if (base === 16) {
      numValue = Math.round(this.value);
      const fractionalPart = Math.abs(this.value % 1);
      if (fractionalPart === 0.5) {
        numValue = Math.floor(this.value);
      } else {
        numValue = Math.round(this.value);
      }
    } else {
      numValue = this.value;
    }
    try {
      if (Number.isInteger(numValue) && radix) {
        return new StringSymbol(numValue.toString(base), this.config);
      } else {
        return new StringSymbol(String(this.value), this.config);
      }
    } catch (e) {
      throw new InterpreterError("SYM_RADIX_CONVERSION_ERROR" /* RADIX_CONVERSION_ERROR */, {
        data: { base, error: String(e) }
      });
    }
  }
};
_NumberSymbol.type = "Number";
_NumberSymbol._SUPPORTED_METHODS = {
  to_string: {
    name: "to_string",
    function: function(radix) {
      return this.toStringSymbol(radix);
    },
    args: [
      {
        name: "radix",
        type: "Number",
        optional: true
      }
    ],
    returnType: "String"
  }
};
var NumberSymbol = _NumberSymbol;
var _StringSymbol = class _StringSymbol extends BaseSymbolType {
  constructor(value, config) {
    let safeValue;
    if (typeof value === "string") {
      safeValue = value;
    } else if (value instanceof _StringSymbol) {
      safeValue = value.value;
    } else if (value === null) {
      safeValue = null;
    } else {
      throw new InterpreterError("SYM_VALUE_MUST_BE_TYPE" /* VALUE_MUST_BE_TYPE */, {
        data: { expectedType: "string", actualType: typeof value }
      });
    }
    super(safeValue, config);
    this.type = "String";
    this.value = safeValue;
  }
  validValue(val) {
    return typeof val === "string" || val instanceof _StringSymbol;
  }
  expectSafeValue(val) {
    if (val === null || val === void 0) {
      throw new InterpreterError("SYM_VALUE_IS_NULL" /* VALUE_IS_NULL */, {
        data: { expectedType: "string" }
      });
    }
  }
  upper() {
    this.expectSafeValue(this.value);
    return new _StringSymbol(this.value.toUpperCase(), this.config);
  }
  deepCopy() {
    return new _StringSymbol(this.value, this.config);
  }
  cloneIfMutable() {
    return this;
  }
  static empty() {
    return new _StringSymbol(null);
  }
  lower() {
    this.expectSafeValue(this.value);
    return new _StringSymbol(this.value.toLowerCase(), this.config);
  }
  length() {
    this.expectSafeValue(this.value);
    return new NumberSymbol(this.value.length, this.config);
  }
  concat(other) {
    this.expectSafeValue(this.value);
    if (other instanceof _StringSymbol) {
      other.expectSafeValue(other.value);
      return new _StringSymbol(this.value + other.value, this.config);
    }
    throw new InterpreterError("SYM_CANNOT_CONCATENATE" /* CANNOT_CONCATENATE */, {
      data: { type: `String ${typeof other}` }
    });
  }
  split(delimiter) {
    this.expectSafeValue(this.value);
    const strValue = this.value;
    if (delimiter instanceof _StringSymbol) {
      const parts = strValue.split(delimiter.value);
      return new ListSymbol(
        parts.map((p) => new _StringSymbol(p, this.config)),
        false,
        this.config
      );
    } else if (typeof delimiter === "string") {
      const parts = strValue.split(delimiter);
      return new ListSymbol(
        parts.map((p) => new _StringSymbol(p, this.config)),
        false,
        this.config
      );
    } else if (delimiter === void 0 || delimiter === null) {
      const parts = Array.from(strValue);
      return new ListSymbol(
        parts.map((p) => new _StringSymbol(p, this.config)),
        false,
        this.config
      );
    }
    throw new InterpreterError("SYM_CANNOT_SPLIT" /* CANNOT_SPLIT */, {
      data: { type: typeof delimiter }
    });
  }
};
_StringSymbol.type = "String";
_StringSymbol._SUPPORTED_METHODS = {
  upper: {
    function: function() {
      return this.upper();
    },
    args: [],
    returnType: "String"
  },
  lower: {
    function: function() {
      return this.lower();
    },
    args: [],
    returnType: "String"
  },
  length: {
    function: function() {
      return this.length();
    },
    args: [],
    returnType: "Number"
  },
  concat: {
    function: function(other) {
      return this.concat(other);
    },
    args: [{ name: "other", type: "String" }],
    returnType: "String"
  },
  split: {
    function: function(delimiter) {
      return this.split(delimiter);
    },
    args: [{ name: "delimiter", type: "String", optional: true }],
    returnType: "List"
  }
};
var StringSymbol = _StringSymbol;
var _BooleanSymbol = class _BooleanSymbol extends BaseSymbolType {
  constructor(value, config) {
    let safeValue;
    if (typeof value === "boolean") {
      safeValue = value;
    } else if (value instanceof _BooleanSymbol) {
      safeValue = value.value;
    } else if (value === null) {
      safeValue = null;
    } else {
      throw new InterpreterError("SYM_VALUE_MUST_BE_TYPE" /* VALUE_MUST_BE_TYPE */, {
        data: { expectedType: "boolean", actualType: typeof value }
      });
    }
    super(safeValue, config);
    this.type = "Boolean";
    this.value = safeValue;
  }
  validValue(val) {
    return typeof val === "boolean" || val instanceof _BooleanSymbol;
  }
  expectSafeValue(val) {
    if (val === null || val === void 0) {
      throw new InterpreterError("SYM_VALUE_IS_NULL" /* VALUE_IS_NULL */, {
        data: { expectedType: "boolean" }
      });
    }
  }
  deepCopy() {
    return new _BooleanSymbol(this.value, this.config);
  }
  cloneIfMutable() {
    return this;
  }
  static empty() {
    return new _BooleanSymbol(null);
  }
};
_BooleanSymbol.type = "Boolean";
var BooleanSymbol = _BooleanSymbol;
var _ListSymbol = class _ListSymbol extends BaseSymbolType {
  constructor(elements, isImplicit = false, config) {
    const safeElements = elements === null ? [] : elements;
    super(safeElements, config);
    this.type = "List";
    this.value = safeElements;
    this.isImplicit = isImplicit;
  }
  validValue(val) {
    return Array.isArray(val) || val instanceof _ListSymbol;
  }
  toString() {
    return ListImpl.toString(this.value, this.isImplicit);
  }
  append(item) {
    ListImpl.append(this.value, item);
    return this;
  }
  extend(...items) {
    ListImpl.extend(this.value, ...items);
    return this;
  }
  insert(indexSymbol, item) {
    ListImpl.insert(this.value, indexSymbol, item);
    return this;
  }
  delete(indexSymbol) {
    ListImpl.deleteAt(this.value, indexSymbol);
    return this;
  }
  length() {
    return ListImpl.length(this.value, this.config);
  }
  index(item) {
    return ListImpl.indexOf(this.value, item, this.config);
  }
  get(indexSymbol) {
    return ListImpl.get(this.value, indexSymbol);
  }
  update(indexSymbol, item) {
    ListImpl.update(this.value, indexSymbol, item);
    return this;
  }
  join(separator) {
    return ListImpl.join(this.value, separator, this.config);
  }
  deepCopy() {
    const copiedElements = ListImpl.deepCopy(this.value);
    return new _ListSymbol(copiedElements, this.isImplicit, this.config);
  }
  cloneIfMutable() {
    return this.deepCopy();
  }
  static empty() {
    return new _ListSymbol(null);
  }
  getTypeName() {
    return this.isImplicit ? typeName(this.type, "Implicit") : typeName(this.type);
  }
};
_ListSymbol.type = "List";
_ListSymbol._SUPPORTED_METHODS = {
  append: {
    function: function(item) {
      return this.append(item);
    },
    args: [{ name: "item", type: "any" }],
    returnType: "List"
  },
  extend: {
    function: function(...items) {
      return this.extend(...items);
    },
    args: [],
    returnType: "List"
  },
  insert: {
    function: function(index, item) {
      return this.insert(index, item);
    },
    args: [
      { name: "index", type: "Number" },
      { name: "item", type: "any" }
    ],
    returnType: "List"
  },
  delete: {
    function: function(index) {
      return this.delete(index);
    },
    args: [{ name: "index", type: "Number" }],
    returnType: "List"
  },
  length: {
    function: function() {
      return this.length();
    },
    args: [],
    returnType: "Number"
  },
  index: {
    function: function(item) {
      return this.index(item);
    },
    args: [{ name: "item", type: "any" }],
    returnType: "Number"
  },
  get: {
    function: function(index) {
      return this.get(index);
    },
    args: [{ name: "index", type: "Number" }],
    returnType: "any"
  },
  update: {
    function: function(index, item) {
      return this.update(index, item);
    },
    args: [
      { name: "index", type: "Number" },
      { name: "item", type: "any" }
    ],
    returnType: "List"
  },
  join: {
    function: function(separator) {
      return this.join(separator);
    },
    args: [{ name: "separator", type: "String", optional: true }],
    returnType: "String"
  }
};
var ListSymbol = _ListSymbol;
var _NumberWithUnitSymbol = class _NumberWithUnitSymbol extends BaseSymbolType {
  constructor(value, unit, config) {
    let safeValue;
    if (typeof value === "number") {
      safeValue = value;
    } else if (value instanceof NumberSymbol) {
      safeValue = value.value;
    } else if (value === null) {
      safeValue = null;
    } else {
      throw new InterpreterError("SYM_VALUE_MUST_BE_TYPE" /* VALUE_MUST_BE_TYPE */, {
        data: { expectedType: "number or NumberSymbol", actualType: typeof value }
      });
    }
    super(safeValue, config);
    this.type = "NumberWithUnit";
    this.value = safeValue;
    if (typeof unit === "string" && !Object.values(SupportedFormats).includes(unit)) {
      throw new InterpreterError("SYM_ATTRIBUTE_NOT_FOUND" /* ATTRIBUTE_NOT_FOUND */, {
        data: { attributeName: unit, type: "Unit" }
      });
    }
    this.unit = typeof unit === "string" ? unit : unit;
  }
  validValue(val) {
    return val instanceof _NumberWithUnitSymbol;
  }
  static fromRecord(record, config) {
    if (record === null || typeof record !== "object") return;
    if (record.type !== "NumberWithUnit") return;
    if (!record.value && !record.unit) return;
    if (typeof record.value !== "number") return;
    return new _NumberWithUnitSymbol(record.value, record.unit, config);
  }
  toString() {
    return `${this.value}${this.unit}`;
  }
  expectSafeValue(val) {
    if (val === null || val === void 0) {
      throw new InterpreterError("SYM_VALUE_IS_NULL" /* VALUE_IS_NULL */, {
        data: { expectedType: "number" }
      });
    }
  }
  toStringSymbol() {
    this.expectSafeValue(this.value);
    return new StringSymbol(`${this.value}${this.unit}`, this.config);
  }
  to_number() {
    this.expectSafeValue(this.value);
    return new NumberSymbol(this.value, this.config);
  }
  equals(other) {
    return other instanceof _NumberWithUnitSymbol && this.value === other.value && this.unit.toLowerCase() === other?.unit.toLowerCase();
  }
  deepCopy() {
    return new _NumberWithUnitSymbol(this.value, this.unit, this.config);
  }
  cloneIfMutable() {
    return this;
  }
  static empty() {
    return new _NumberWithUnitSymbol(null, "px");
  }
  hasAttribute(attributeName) {
    return attributeName === "value";
  }
  getAttribute(attributeName) {
    if (attributeName === "value") {
      return new NumberSymbol(this.value, this.config);
    }
    throw new InterpreterError("SYM_ATTRIBUTE_NOT_FOUND" /* ATTRIBUTE_NOT_FOUND */, {
      data: { attributeName, type: "NumberWithUnit" }
    });
  }
  getTypeName() {
    return `${this.type}.${capitalize(this.unit)}`;
  }
};
_NumberWithUnitSymbol.type = "NumberWithUnit";
_NumberWithUnitSymbol._SUPPORTED_METHODS = {
  to_string: {
    name: "to_string",
    function: function() {
      return this.toStringSymbol();
    },
    args: [
      {
        name: "radix",
        type: "Number",
        optional: true
      }
    ],
    returnType: "String"
  },
  to_number: {
    function: function() {
      return this.to_number();
    },
    args: [],
    returnType: "Number"
  }
};
var NumberWithUnitSymbol = _NumberWithUnitSymbol;
var _DictionarySymbol = class _DictionarySymbol extends BaseSymbolType {
  constructor(value, config) {
    let safeValue;
    if (value instanceof _DictionarySymbol) {
      safeValue = value.value;
    } else if (isMap(value)) {
      safeValue = value;
    } else if (isNull(value)) {
      safeValue = /* @__PURE__ */ new Map();
    } else if (isObject(value)) {
      safeValue = new Map(Object.entries(value));
    } else {
      throw new InterpreterError("SYM_VALUE_MUST_BE_TYPE" /* VALUE_MUST_BE_TYPE */, {
        data: { expectedType: "dict", actualType: typeof value }
      });
    }
    super(safeValue, config);
    this.type = "Dictionary";
    this.value = safeValue;
  }
  validValue(val) {
    return isMap(val) || isNull(val);
  }
  toString() {
    return DictionaryImpl.toString(this.value);
  }
  get(key) {
    return DictionaryImpl.get(this.value, key, this.config);
  }
  set(key, value) {
    DictionaryImpl.set(this.value, key, value);
    return this;
  }
  delete(key) {
    DictionaryImpl.deleteKey(this.value, key);
    return this;
  }
  keys() {
    return DictionaryImpl.keys(this.value, this.config);
  }
  values() {
    return DictionaryImpl.values(this.value, this.config);
  }
  keyExists(key) {
    return DictionaryImpl.keyExists(this.value, key, this.config);
  }
  length() {
    return DictionaryImpl.length(this.value, this.config);
  }
  clear() {
    DictionaryImpl.clear(this.value);
    return this;
  }
  deepCopy() {
    const copiedMap = DictionaryImpl.deepCopy(this.value);
    return new _DictionarySymbol(copiedMap, this.config);
  }
  cloneIfMutable() {
    return this.deepCopy();
  }
  static empty() {
    return new _DictionarySymbol(null);
  }
  hasAttribute(attributeName) {
    return DictionaryImpl.hasAttribute(this.value, attributeName);
  }
  getAttribute(attributeName) {
    return DictionaryImpl.getAttribute(this.value, attributeName);
  }
};
_DictionarySymbol.type = "Dictionary";
_DictionarySymbol._SUPPORTED_METHODS = {
  get: {
    function: function(key) {
      return this.get(key);
    },
    args: [{ name: "key", type: "String", optional: false }],
    returnType: "any"
  },
  set: {
    function: function(key, value) {
      return this.set(key, value);
    },
    args: [
      { name: "key", type: "String", optional: false },
      { name: "value", type: "any", optional: false }
    ],
    returnType: "Dictionary"
  },
  delete: {
    function: function(key) {
      return this.delete(key);
    },
    args: [{ name: "key", type: "String", optional: false }],
    returnType: "Dictionary"
  },
  keys: {
    function: function() {
      return this.keys();
    },
    args: [],
    returnType: "List"
  },
  values: {
    function: function() {
      return this.values();
    },
    args: [],
    returnType: "List"
  },
  key_exists: {
    function: function(key) {
      return this.keyExists(key);
    },
    args: [{ name: "key", type: "String", optional: false }],
    returnType: "Boolean"
  },
  length: {
    function: function() {
      return this.length();
    },
    args: [],
    returnType: "Number"
  },
  clear: {
    function: function() {
      return this.clear();
    },
    args: [],
    returnType: "Dictionary"
  }
};
var DictionarySymbol = _DictionarySymbol;
var _TokenSymbol = class _TokenSymbol extends BaseSymbolType {
  constructor(subType, value, config) {
    let safeValue;
    if (value instanceof _TokenSymbol) {
      safeValue = value.value;
    } else if (isMap(value)) {
      safeValue = value;
    } else if (isObject(value)) {
      safeValue = new Map(Object.entries(value));
    } else if (isArray(value)) {
      safeValue = value;
    } else if (isNull(value)) {
      safeValue = /* @__PURE__ */ new Map();
    } else {
      throw new InterpreterError("SYM_VALUE_MUST_BE_TYPE" /* VALUE_MUST_BE_TYPE */, {
        data: { expectedType: "Record or List", actualType: typeof value }
      });
    }
    super(safeValue, config);
    this.type = "Token";
    this.value = safeValue;
    this.subType = subType;
  }
  validValue(val) {
    return isMap(val) || isArray(val) || isNull(val);
  }
  toString() {
    if (isMap(this.value)) {
      return DictionaryImpl.toString(this.value);
    }
    return ListImpl.toString(this.value);
  }
  get(keyOrIndex) {
    if (isArray(this.value)) {
      const indexSymbol = typeof keyOrIndex === "number" ? new NumberSymbol(keyOrIndex, this.config) : keyOrIndex;
      if (!(indexSymbol instanceof NumberSymbol)) {
        throw new InterpreterError("SYM_CANNOT_OPERATION_ON_TOKEN_TYPE" /* CANNOT_OPERATION_ON_TOKEN_TYPE */, {
          data: { operation: "List get", valueType: "non-Number index" }
        });
      }
      return ListImpl.get(this.value, indexSymbol);
    }
    const keySymbol = typeof keyOrIndex === "string" ? new StringSymbol(keyOrIndex, this.config) : keyOrIndex;
    if (!(keySymbol instanceof StringSymbol)) {
      throw new InterpreterError("SYM_CANNOT_OPERATION_ON_TOKEN_TYPE" /* CANNOT_OPERATION_ON_TOKEN_TYPE */, {
        data: { operation: "Dictionary get", valueType: "non-String key" }
      });
    }
    return DictionaryImpl.get(this.value, keySymbol, this.config);
  }
  set(key, value) {
    if (isArray(this.value)) {
      throw new InterpreterError("SYM_CANNOT_OPERATION_ON_TOKEN_TYPE" /* CANNOT_OPERATION_ON_TOKEN_TYPE */, {
        data: { operation: "set key", valueType: "List" }
      });
    }
    DictionaryImpl.set(this.value, key, value);
    return this;
  }
  keys() {
    if (isArray(this.value)) {
      throw new InterpreterError("SYM_CANNOT_OPERATION_ON_TOKEN_TYPE" /* CANNOT_OPERATION_ON_TOKEN_TYPE */, {
        data: { operation: "get keys", valueType: "List" }
      });
    }
    return DictionaryImpl.keys(this.value, this.config);
  }
  values() {
    if (isMap(this.value)) {
      return DictionaryImpl.values(this.value, this.config);
    }
    return new ListSymbol(this.value, false, this.config);
  }
  length() {
    if (isMap(this.value)) {
      return DictionaryImpl.length(this.value, this.config);
    }
    return ListImpl.length(this.value, this.config);
  }
  // List-specific methods
  append(item) {
    if (isMap(this.value)) {
      throw new InterpreterError("SYM_CANNOT_OPERATION_ON_TOKEN_TYPE" /* CANNOT_OPERATION_ON_TOKEN_TYPE */, {
        data: { operation: "append", valueType: "Dictionary" }
      });
    }
    ListImpl.append(this.value, item);
    return this;
  }
  extend(...items) {
    if (isMap(this.value)) {
      throw new InterpreterError("SYM_CANNOT_OPERATION_ON_TOKEN_TYPE" /* CANNOT_OPERATION_ON_TOKEN_TYPE */, {
        data: { operation: "extend", valueType: "Dictionary" }
      });
    }
    ListImpl.extend(this.value, ...items);
    return this;
  }
  insert(indexSymbol, item) {
    if (isMap(this.value)) {
      throw new InterpreterError("SYM_CANNOT_OPERATION_ON_TOKEN_TYPE" /* CANNOT_OPERATION_ON_TOKEN_TYPE */, {
        data: { operation: "insert", valueType: "Dictionary" }
      });
    }
    ListImpl.insert(this.value, indexSymbol, item);
    return this;
  }
  delete(indexSymbol) {
    if (isMap(this.value)) {
      throw new InterpreterError("SYM_CANNOT_OPERATION_ON_TOKEN_TYPE" /* CANNOT_OPERATION_ON_TOKEN_TYPE */, {
        data: { operation: "delete", valueType: "Dictionary" }
      });
    }
    ListImpl.deleteAt(this.value, indexSymbol);
    return this;
  }
  index(item) {
    if (isMap(this.value)) {
      throw new InterpreterError("SYM_CANNOT_OPERATION_ON_TOKEN_TYPE" /* CANNOT_OPERATION_ON_TOKEN_TYPE */, {
        data: { operation: "get index", valueType: "Dictionary" }
      });
    }
    return ListImpl.indexOf(this.value, item, this.config);
  }
  update(indexSymbol, item) {
    if (isMap(this.value)) {
      throw new InterpreterError("SYM_CANNOT_OPERATION_ON_TOKEN_TYPE" /* CANNOT_OPERATION_ON_TOKEN_TYPE */, {
        data: { operation: "update", valueType: "Dictionary" }
      });
    }
    ListImpl.update(this.value, indexSymbol, item);
    return this;
  }
  join(separator) {
    if (isMap(this.value)) {
      throw new InterpreterError("SYM_CANNOT_OPERATION_ON_TOKEN_TYPE" /* CANNOT_OPERATION_ON_TOKEN_TYPE */, {
        data: { operation: "join", valueType: "Dictionary" }
      });
    }
    return ListImpl.join(this.value, separator, this.config);
  }
  deepCopy() {
    if (isMap(this.value)) {
      return new _TokenSymbol(this.subType, DictionaryImpl.deepCopy(this.value), this.config);
    }
    return new _TokenSymbol(this.subType, ListImpl.deepCopy(this.value), this.config);
  }
  cloneIfMutable() {
    return this.deepCopy();
  }
  static empty() {
    return new _TokenSymbol("unknown", null);
  }
  hasAttribute(attributeName) {
    if (attributeName === "subType" || attributeName === "type") {
      return true;
    }
    if (isMap(this.value)) {
      return DictionaryImpl.hasAttribute(this.value, attributeName);
    }
    return false;
  }
  getAttribute(attributeName) {
    if (attributeName === "subType") {
      return new StringSymbol(this.subType, this.config);
    }
    if (attributeName === "type") {
      return new StringSymbol(this.type, this.config);
    }
    if (isMap(this.value)) {
      return DictionaryImpl.getAttribute(this.value, attributeName);
    }
    return null;
  }
  getTypeName() {
    return typeName(this.type, this.subType);
  }
};
_TokenSymbol.type = "Token";
_TokenSymbol._SUPPORTED_METHODS = {
  get: {
    function: function(keyOrIndex) {
      return this.get(keyOrIndex);
    },
    args: [{ name: "keyOrIndex", type: "String|Number", optional: false }],
    returnType: "any"
  },
  set: {
    function: function(key, value) {
      return this.set(key, value);
    },
    args: [
      { name: "key", type: "String", optional: false },
      { name: "value", type: "any", optional: false }
    ],
    returnType: "Token"
  },
  keys: {
    function: function() {
      return this.keys();
    },
    args: [],
    returnType: "List"
  },
  values: {
    function: function() {
      return this.values();
    },
    args: [],
    returnType: "List"
  },
  length: {
    function: function() {
      return this.length();
    },
    args: [],
    returnType: "Number"
  },
  // List methods (when value is Array)
  append: {
    function: function(item) {
      return this.append(item);
    },
    args: [{ name: "item", type: "any" }],
    returnType: "Token"
  },
  extend: {
    function: function(...items) {
      return this.extend(...items);
    },
    args: [],
    returnType: "Token"
  },
  insert: {
    function: function(index, item) {
      return this.insert(index, item);
    },
    args: [
      { name: "index", type: "Number" },
      { name: "item", type: "any" }
    ],
    returnType: "Token"
  },
  delete: {
    function: function(index) {
      return this.delete(index);
    },
    args: [{ name: "index", type: "Number" }],
    returnType: "Token"
  },
  index: {
    function: function(item) {
      return this.index(item);
    },
    args: [{ name: "item", type: "any" }],
    returnType: "Number"
  },
  update: {
    function: function(index, item) {
      return this.update(index, item);
    },
    args: [
      { name: "index", type: "Number" },
      { name: "item", type: "any" }
    ],
    returnType: "Token"
  },
  join: {
    function: function(separator) {
      return this.join(separator);
    },
    args: [{ name: "separator", type: "String", optional: true }],
    returnType: "String"
  }
};
var TokenSymbol = _TokenSymbol;
var _ColorSymbol = class _ColorSymbol extends BaseSymbolType {
  constructor(value, subType, config) {
    const isHex = (isUndefined(subType) || subType?.toLowerCase() === "hex") && isString(value);
    const isDynamic = isString(subType) && isObject(value);
    const isValid = isNull(value) || isHex || isDynamic;
    if (!isValid) {
      throw new InterpreterError("SYM_INVALID_COLOR_VALUE" /* INVALID_COLOR_VALUE */, {
        data: { value: String(value), type: typeof value }
      });
    }
    if (isHex) {
      if (!isValidHex(value)) {
        throw new InterpreterError("SYM_INVALID_HEX_COLOR" /* INVALID_HEX_COLOR */, {
          data: { value: String(value) }
        });
      }
    }
    super(value, config);
    this.type = "Color";
    this.subType = null;
    this.value = value;
    this.subType = isHex ? "Hex" : subType || null;
  }
  static empty() {
    return new _ColorSymbol(null);
  }
  toStringSymbol() {
    if (this.config?.colorManager) {
      const formatted = this.config.colorManager.formatColorMethod(this);
      return new StringSymbol(formatted, this.config);
    }
    if (isObject(this.value)) {
      return new StringSymbol(formatObjectEntries(this.value), this.config);
    }
    if (isString(this.value)) {
      return new StringSymbol(this.value, this.config);
    }
    return new StringSymbol("", this.config);
  }
  toString() {
    return this.toStringSymbol().toString();
  }
  to(targetType) {
    if (!this.config?.colorManager) {
      throw new InterpreterError("SYM_COLOR_MANAGER_NOT_AVAILABLE" /* COLOR_MANAGER_NOT_AVAILABLE */);
    }
    return this.config.colorManager.convertToByType(this, targetType);
  }
  typeEquals(other) {
    if (!typeEquals(this.type, other.type)) return false;
    const otherColor = other;
    if (!this.subType && otherColor.isHex() || this.isHex() && !otherColor.subType) return true;
    return typeEquals(this.subType, other.subType);
  }
  isHex() {
    return typeEquals(this.subType, "hex");
  }
  validValue(val) {
    return val instanceof _ColorSymbol || isNull(val) || isObject(val) || isValidHex(val);
  }
  deepCopy() {
    if (isObject(this.value)) {
      const copiedValue = {};
      for (const [key, val] of Object.entries(this.value)) {
        copiedValue[key] = val.deepCopy();
      }
      return new _ColorSymbol(copiedValue, this.subType || void 0, this.config);
    }
    return new _ColorSymbol(this.value, this.subType || void 0, this.config);
  }
  cloneIfMutable() {
    if (isObject(this.value)) {
      return this.deepCopy();
    }
    return this;
  }
  hasAttribute(attributeName) {
    if (attributeName === "to") {
      return true;
    }
    if (isObject(this.value)) {
      return attributeName in this.value;
    }
    return false;
  }
  getAttribute(attributeName) {
    if (attributeName === "to") {
      return this;
    }
    if (isObject(this.value)) {
      const attributeValue = this.value[attributeName];
      if (attributeValue !== void 0) {
        return attributeValue;
      }
    }
    throw new InterpreterError("SYM_ATTRIBUTE_NOT_FOUND" /* ATTRIBUTE_NOT_FOUND */, {
      data: { attributeName, type: "Color" }
    });
  }
  hasMethod(methodName, args) {
    if (super.hasMethod?.(methodName, args)) {
      return true;
    }
    if (this.config?.colorManager.hasInitializer(methodName)) {
      return true;
    }
    return false;
  }
  callMethod(methodName, args) {
    const methodDefinition = this.constructor._SUPPORTED_METHODS?.[methodName.toLowerCase()];
    if (methodDefinition && super.hasMethod?.(methodName, args)) {
      return super.callMethod?.(methodName, args);
    }
    if (this.config?.colorManager.hasInitializer(methodName)) {
      return this.config.colorManager.convertToByType(this, methodName);
    }
    throw new InterpreterError("SYM_METHOD_NOT_FOUND" /* METHOD_NOT_FOUND */, {
      data: { methodName, type: this.type }
    });
  }
  getTypeName() {
    return typeName(this.type, nullToUndefined(this.subType));
  }
};
_ColorSymbol.type = "Color";
_ColorSymbol._SUPPORTED_METHODS = {
  to_string: {
    name: "to_string",
    function: function() {
      return this.toStringSymbol();
    },
    args: [],
    returnType: "String"
  }
};
var ColorSymbol = _ColorSymbol;
({
  [NumberSymbol.type.toLowerCase()]: NumberSymbol,
  [StringSymbol.type.toLowerCase()]: StringSymbol,
  [BooleanSymbol.type.toLowerCase()]: BooleanSymbol,
  [NumberWithUnitSymbol.type.toLowerCase()]: NumberWithUnitSymbol,
  [ColorSymbol.type.toLowerCase()]: ColorSymbol,
  [NullSymbol.type.toLowerCase()]: NullSymbol
});
({
  [ListSymbol.type.toLowerCase()]: ListSymbol,
  [DictionarySymbol.type.toLowerCase()]: DictionarySymbol,
  [TokenSymbol.type.toLowerCase()]: TokenSymbol
});

// src/syntax-highlighter/spec.ts
var KEYWORDS = Object.values(ReservedKeyword);
var TYPES = [
  StringSymbol.type,
  NumberSymbol.type,
  NumberWithUnitSymbol.type,
  ColorSymbol.type,
  ListSymbol.type,
  DictionarySymbol.type,
  BooleanSymbol.type
];
var BUILTIN_FUNCTIONS = [
  "rgb",
  "rgba",
  "hsl",
  "hsla",
  "srgb",
  "lrgb",
  "hex",
  "oklch",
  "oklchRamp",
  "lighten",
  "darken",
  "saturate",
  "desaturate",
  "spin",
  "mix",
  "round_to",
  "snap",
  "remap",
  "pow",
  "linear-gradient",
  "type"
];
var UNITS = Object.values(SupportedFormats);
var OPERATORS = [
  ...Object.values(Operations),
  "=",
  ">",
  "<",
  ":",
  "==",
  "<=",
  ">=",
  "!="
];
var numberWithUnit = createUnitPattern(UNITS);
var PATTERNS = {
  /** Single-line comments */
  comment: /\/\/.*/,
  /** String literals (single or double quotes) */
  string: /(["'])(?:\\[\s\S]|(?!\1)[^\\])*\1/,
  /** TokenScript references with curly braces (e.g., {token.path}) */
  reference: /\{[^}]+\}/,
  /** Hex color codes (#RGB, #RRGGBB, #RRGGBBAA) */
  hexColor: /#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})\b/,
  /** Numbers with CSS units (e.g., 10px, 1.5em, 45deg) - dynamically constructed from UNITS */
  numberWithUnit,
  /** Plain numbers (integers and floats, including scientific notation) */
  number: /\b\d+(?:\.\d+)?(?:[eE][+-]?\d+)?\b/,
  /** Float numbers with decimal point */
  float: /\d*\.\d+(?:[eE][-+]?\d+)?/,
  /** Identifiers and keywords */
  identifier: /[a-zA-Z_$][\w$]*/,
  /** Operators */
  operator: /[+\-*/%=<>!&|^~?:]+/,
  /** Punctuation */
  punctuation: /[[\]();,.:]/,
  /** Method calls (e.g., .methodName() ) */
  method: /\.\w+(?=\()/,
  /** Property access (e.g., .propertyName) */
  property: /\.\w+\b(?!\()/,
  /** Color type constructors (e.g., Color, Color.Rgb, Color.Hex) - accepts any subtype */
  colorType: /\bColor(?:\.\w+)?\b/
};
var MONACO_PATTERNS = {
  /** Invalid string (unterminated double quote) - Monaco-specific for error highlighting */
  stringInvalidDouble: /"([^"\\]|\\.)*$/,
  /** Invalid string (unterminated single quote) - Monaco-specific for error highlighting */
  stringInvalidSingle: /'([^'\\]|\\.)*$/,
  /** String start (double quote) - Monaco-specific for state-based tokenization */
  stringStartDouble: /"/,
  /** String start (single quote) - Monaco-specific for state-based tokenization */
  stringStartSingle: /'/,
  /** Number with any unit (captures unit for dynamic validation) - Monaco-specific for unit validation */
  numberWithDynamicUnit: /\d+(\.\d+)?([a-zA-Z%]+)\b/
};
function createKeywordPattern(keywords) {
  return new RegExp(`\\b(?:${keywords.join("|")})\\b`);
}
function createUnitPattern(units) {
  const escapedUnits = units.map((unit) => unit.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
  return new RegExp(`\\b\\d+(?:\\.\\d+)?(?:${escapedUnits.join("|")})(?!\\w)`);
}

// src/syntax-highlighter/monaco.ts
var tokenscriptLanguageDefinition = {
  keywords: [...KEYWORDS],
  types: [...TYPES],
  colorFunctions: [...BUILTIN_FUNCTIONS],
  units: [...UNITS],
  operators: [...OPERATORS],
  symbols: /[=><!~?:&|+\-*/^%]+/,
  tokenizer: {
    root: [
      // Comments - must come first
      [PATTERNS.comment, "comment"],
      // Strings - Monaco requires state-based tokenization for multi-line strings
      // Cannot use PATTERNS.string because Monaco needs separate start/end tokens
      [MONACO_PATTERNS.stringInvalidDouble, "string.invalid"],
      [MONACO_PATTERNS.stringInvalidSingle, "string.invalid"],
      [MONACO_PATTERNS.stringStartDouble, "string", "@string_double"],
      [MONACO_PATTERNS.stringStartSingle, "string", "@string_single"],
      // TokenScript references with curly braces
      [PATTERNS.reference, "reference"],
      // Hex colors
      [PATTERNS.hexColor, "number.hex"],
      // Numbers with units - Monaco requires capture groups for dynamic unit validation
      // Cannot use PATTERNS.numberWithUnit because Monaco needs $2 to validate against @units
      [
        MONACO_PATTERNS.numberWithDynamicUnit,
        {
          cases: {
            "$2@units": "number.unit",
            "@default": "number"
          }
        }
      ],
      // Float numbers - must come before integer pattern to match decimals first
      [PATTERNS.float, "number.float"],
      // Integer numbers
      [PATTERNS.number, "number"],
      // Color types (Color.Hex, Color.Rgb, etc.)
      [PATTERNS.colorType, "type"],
      // Method calls (.method())
      [PATTERNS.method, "method"],
      // Property access (.property)
      [PATTERNS.property, "property"],
      // Identifiers and keywords
      [
        PATTERNS.identifier,
        {
          cases: {
            "@keywords": "keyword",
            "@types": "type",
            "@colorFunctions": "function",
            "@default": "identifier"
          }
        }
      ],
      // Whitespace
      { include: "@whitespace" },
      // Delimiters and operators
      [/[()[\]]/, "delimiter"],
      [/[<>]=?/, "operator"],
      [/[=!]=?/, "operator"],
      [/&&|\|\|/, "operator"],
      [/[+\-*/^%]/, "operator"],
      [/[;:,]/, "delimiter"],
      [/@symbols/, "operator"]
    ],
    // String handling
    string_double: [
      [/[^\\"]+/, "string"],
      [/"/, "string", "@pop"]
    ],
    string_single: [
      [/[^\\']+/, "string"],
      [/'/, "string", "@pop"]
    ],
    // Whitespace
    whitespace: [[/[ \t\r\n]+/, "white"]]
  }
};
var tokenscriptLanguageConfig = {
  comments: {
    lineComment: "//"
  },
  brackets: [
    ["[", "]"],
    ["(", ")"]
  ],
  autoClosingPairs: [
    { open: "[", close: "]" },
    { open: "(", close: ")" },
    { open: '"', close: '"', notIn: ["string"] },
    { open: "'", close: "'", notIn: ["string"] }
  ],
  surroundingPairs: [
    { open: "[", close: "]" },
    { open: "(", close: ")" },
    { open: '"', close: '"' },
    { open: "'", close: "'" }
  ],
  folding: {
    markers: {
      start: /^\s*\/\/\s*#?region\b/,
      end: /^\s*\/\/\s*#?endregion\b/
    }
  },
  wordPattern: /(-?\d*\.\d\w*)|([a-zA-Z_$][\w$]*)/g,
  indentationRules: {
    increaseIndentPattern: /^((?!.*?\/\*).*)*\[[^\]]*$/,
    decreaseIndentPattern: /^((?!.*?\/\*).*)*\].*$/
  }
};

// src/syntax-highlighter/prism.ts
function tokenscriptLanguage(Prism) {
  Prism.languages.tokenscript = {
    comment: {
      pattern: PATTERNS.comment,
      greedy: true
    },
    string: {
      pattern: PATTERNS.string,
      greedy: true
    },
    reference: {
      pattern: PATTERNS.reference,
      greedy: true,
      alias: "variable"
    },
    "hex-color": {
      pattern: PATTERNS.hexColor,
      alias: "number"
    },
    "number-with-unit": {
      pattern: PATTERNS.numberWithUnit,
      alias: "number"
    },
    number: {
      pattern: PATTERNS.number
    },
    keyword: {
      pattern: createKeywordPattern(KEYWORDS)
    },
    type: {
      pattern: createKeywordPattern(TYPES),
      alias: "class-name"
    },
    "color-type": {
      pattern: PATTERNS.colorType,
      alias: "class-name"
    },
    function: {
      pattern: createKeywordPattern([...BUILTIN_FUNCTIONS, "(?=\\()"])
    },
    method: {
      pattern: PATTERNS.method,
      inside: {
        punctuation: /\./
      }
    },
    property: {
      pattern: PATTERNS.property,
      inside: {
        punctuation: /\./
      }
    },
    operator: PATTERNS.operator,
    punctuation: PATTERNS.punctuation
  };
  Prism.languages.ts = Prism.languages.tokenscript;
  return Prism.languages.tokenscript;
}

exports.BUILTIN_FUNCTIONS = BUILTIN_FUNCTIONS;
exports.KEYWORDS = KEYWORDS;
exports.MONACO_PATTERNS = MONACO_PATTERNS;
exports.OPERATORS = OPERATORS;
exports.PATTERNS = PATTERNS;
exports.TYPES = TYPES;
exports.UNITS = UNITS;
exports.createKeywordPattern = createKeywordPattern;
exports.createUnitPattern = createUnitPattern;
exports.tokenscriptLanguage = tokenscriptLanguage;
exports.tokenscriptLanguageConfig = tokenscriptLanguageConfig;
exports.tokenscriptLanguageDefinition = tokenscriptLanguageDefinition;
//# sourceMappingURL=syntax-highlighting.cjs.map
//# sourceMappingURL=syntax-highlighting.cjs.map