'use strict';

var chunkK65UI6KX_cjs = require('./chunk-K65UI6KX.cjs');
var chunkKHF2VXWO_cjs = require('./chunk-KHF2VXWO.cjs');

// src/syntax-highlighter/spec.ts
var KEYWORDS = Object.values(chunkKHF2VXWO_cjs.ReservedKeyword);
var TYPES = [
  chunkK65UI6KX_cjs.StringSymbol.type,
  chunkK65UI6KX_cjs.NumberSymbol.type,
  chunkK65UI6KX_cjs.NumberWithUnitSymbol.type,
  chunkK65UI6KX_cjs.ColorSymbol.type,
  chunkK65UI6KX_cjs.ListSymbol.type,
  chunkK65UI6KX_cjs.DictionarySymbol.type,
  chunkK65UI6KX_cjs.BooleanSymbol.type
];
var BUILTIN_FUNCTIONS = [
  "rgb",
  "hsl",
  "srgb",
  "lrgb",
  "hex",
  "oklch",
  "oklchRamp",
  "lighten",
  "darken",
  "saturate",
  "desaturate",
  "spin",
  "mix",
  "round_to",
  "snap",
  "remap",
  "pow",
  "linear-gradient",
  "type"
];
var UNITS = Object.values(chunkKHF2VXWO_cjs.SupportedFormats);
var OPERATORS = [
  ...Object.values(chunkKHF2VXWO_cjs.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`);
}
chunkKHF2VXWO_cjs.__name(createKeywordPattern, "createKeywordPattern");
function createUnitPattern(units) {
  const escapedUnits = units.map((unit) => unit.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
  return new RegExp(`\\b\\d+(?:\\.\\d+)?(?:${escapedUnits.join("|")})(?!\\w)`);
}
chunkKHF2VXWO_cjs.__name(createUnitPattern, "createUnitPattern");

// 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;
}
chunkKHF2VXWO_cjs.__name(tokenscriptLanguage, "tokenscriptLanguage");

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