const KEYWORDS = new Set([
    'on',
    'from',
    'to',
    'into',
    'before',
    'after',
    'in',
    'of',
    'at',
    'with',
    'if',
    'else',
    'unless',
    'end',
    'then',
    'and',
    'or',
    'not',
    'repeat',
    'times',
    'for',
    'each',
    'while',
    'until',
    'toggle',
    'add',
    'remove',
    'put',
    'set',
    'get',
    'call',
    'return',
    'append',
    'log',
    'send',
    'trigger',
    'wait',
    'settle',
    'fetch',
    'as',
    'show',
    'hide',
    'take',
    'increment',
    'decrement',
    'focus',
    'blur',
    'go',
    'transition',
    'over',
    'the',
    'a',
    'an',
    'my',
    'its',
    'me',
    'it',
    'you',
    'first',
    'last',
    'next',
    'previous',
    'closest',
    'parent',
    'true',
    'false',
    'null',
    'undefined',
    'is',
    'matches',
    'contains',
    'includes',
    'exists',
    'has',
    'init',
    'every',
    'by',
]);
function tokenize(code) {
    const tokens = [];
    let pos = 0;
    while (pos < code.length) {
        if (/\s/.test(code[pos])) {
            pos++;
            continue;
        }
        if (code.slice(pos, pos + 2) === '--') {
            while (pos < code.length && code[pos] !== '\n')
                pos++;
            continue;
        }
        const start = pos;
        if (code[pos] === '<' && /[a-zA-Z]/.test(code[pos + 1] || '')) {
            pos++;
            while (pos < code.length && code[pos] !== '>')
                pos++;
            if (code[pos] === '>')
                pos++;
            const val = code.slice(start, pos);
            if (val.endsWith('/>') || val.endsWith('>')) {
                const normalized = val.slice(1).replace(/\/?>$/, '');
                tokens.push({ type: 'selector', value: normalized, pos: start });
                continue;
            }
        }
        if (code.slice(pos, pos + 2) === "'s" && !/[a-zA-Z]/.test(code[pos + 2] || '')) {
            tokens.push({ type: 'operator', value: "'s", pos: start });
            pos += 2;
            continue;
        }
        if (code[pos] === '"' || code[pos] === "'") {
            const quote = code[pos++];
            while (pos < code.length && code[pos] !== quote) {
                if (code[pos] === '\\')
                    pos++;
                pos++;
            }
            pos++;
            tokens.push({ type: 'string', value: code.slice(start, pos), pos: start });
            continue;
        }
        if (/\d/.test(code[pos]) || (code[pos] === '-' && /\d/.test(code[pos + 1] || ''))) {
            if (code[pos] === '-')
                pos++;
            while (pos < code.length && /[\d.]/.test(code[pos]))
                pos++;
            if (code.slice(pos, pos + 2) === 'ms')
                pos += 2;
            else if (code[pos] === 's' && !/[a-zA-Z]/.test(code[pos + 1] || ''))
                pos++;
            else if (code.slice(pos, pos + 2) === 'px')
                pos += 2;
            tokens.push({ type: 'number', value: code.slice(start, pos), pos: start });
            continue;
        }
        if (code[pos] === ':') {
            pos++;
            while (pos < code.length && /[\w]/.test(code[pos]))
                pos++;
            tokens.push({ type: 'localVar', value: code.slice(start, pos), pos: start });
            continue;
        }
        if (code[pos] === '$') {
            pos++;
            while (pos < code.length && /[\w]/.test(code[pos]))
                pos++;
            tokens.push({ type: 'globalVar', value: code.slice(start, pos), pos: start });
            continue;
        }
        if (code[pos] === '#' || code[pos] === '.') {
            if (code[pos] === '.') {
                const afterDot = code.slice(pos + 1).match(/^(once|prevent|stop|debounce|throttle)\b/i);
                if (afterDot) {
                    tokens.push({ type: 'symbol', value: '.', pos: start });
                    pos++;
                    continue;
                }
            }
            pos++;
            while (pos < code.length && /[\w-]/.test(code[pos]))
                pos++;
            tokens.push({ type: 'selector', value: code.slice(start, pos), pos: start });
            continue;
        }
        if (code[pos] === '[') {
            let lookahead = pos + 1;
            while (lookahead < code.length && /\s/.test(code[lookahead]))
                lookahead++;
            const nextChar = code[lookahead] || '';
            const isArrayLiteral = /['"\d\[\]:\$\-]/.test(nextChar) || nextChar === '';
            if (isArrayLiteral) {
                tokens.push({ type: 'symbol', value: '[', pos: start });
                pos++;
                continue;
            }
            else {
                pos++;
                let depth = 1;
                while (pos < code.length && depth > 0) {
                    if (code[pos] === '[')
                        depth++;
                    if (code[pos] === ']')
                        depth--;
                    pos++;
                }
                tokens.push({ type: 'selector', value: code.slice(start, pos), pos: start });
                continue;
            }
        }
        if (code[pos] === ']') {
            tokens.push({ type: 'symbol', value: ']', pos: start });
            pos++;
            continue;
        }
        if (code.slice(pos, pos + 2) === "'s") {
            tokens.push({ type: 'operator', value: "'s", pos: start });
            pos += 2;
            continue;
        }
        const twoChar = code.slice(pos, pos + 2);
        if (['==', '!=', '<=', '>=', '&&', '||'].includes(twoChar)) {
            tokens.push({ type: 'operator', value: twoChar, pos: start });
            pos += 2;
            continue;
        }
        if (code[pos] === '*' && /[a-zA-Z]/.test(code[pos + 1] || '')) {
            pos++;
            while (pos < code.length && /[\w-]/.test(code[pos]))
                pos++;
            tokens.push({ type: 'styleProperty', value: code.slice(start, pos), pos: start });
            continue;
        }
        if ('+-*/%<>!'.includes(code[pos])) {
            tokens.push({ type: 'operator', value: code[pos], pos: start });
            pos++;
            continue;
        }
        if ('()[]{},.'.includes(code[pos])) {
            tokens.push({ type: 'symbol', value: code[pos], pos: start });
            pos++;
            continue;
        }
        if (/[a-zA-Z_]/.test(code[pos])) {
            while (pos < code.length && /[\w-]/.test(code[pos]))
                pos++;
            const value = code.slice(start, pos);
            const type = KEYWORDS.has(value.toLowerCase()) ? 'keyword' : 'identifier';
            tokens.push({ type, value, pos: start });
            continue;
        }
        pos++;
    }
    tokens.push({ type: 'eof', value: '', pos: code.length });
    return tokens;
}

export { KEYWORDS, tokenize };
//# sourceMappingURL=tokenizer.mjs.map
