/** @license MIT | @cube-dev/ui-kit v0.0.0-canary-f1f3d22 | Cube Dev Team */
//#region src/tasty/parser/tokenizer.ts
const isWhitespace = (ch) => ch === " " || ch === "\n" || ch === "	" || ch === "\r" || ch === "\f";
function scan(src, cb) {
	let depth = 0;
	let inUrl = false;
	let inQuote = 0;
	let start = 0;
	let i = 0;
	let pendingSlash = false;
	const flush = (isComma, isSlash) => {
		const actualSlash = isSlash || pendingSlash;
		pendingSlash = false;
		if (start < i) {
			const prevChar = start > 0 ? src[start - 1] : null;
			cb(src.slice(start, i), isComma, actualSlash, prevChar);
		} else if (isComma) cb("", true, false, null);
		else if (actualSlash) cb("", false, true, null);
		start = i + 1;
	};
	for (; i < src.length; i++) {
		const ch = src[i];
		if (inQuote) {
			if (ch === inQuote && src[i - 1] !== "\\") inQuote = 0;
			continue;
		}
		if (ch === "\"" || ch === "'") {
			inQuote = ch;
			continue;
		}
		if (ch === "(") {
			if (!depth) {
				if (src.slice(Math.max(0, i - 3), i + 1) === "url(") inUrl = true;
			}
			depth++;
			continue;
		}
		if (ch === ")") {
			depth = Math.max(0, depth - 1);
			if (inUrl && depth === 0) inUrl = false;
			continue;
		}
		if (inUrl) continue;
		if (!depth) {
			if (ch === ",") {
				flush(true, false);
				continue;
			}
			if (ch === "/") {
				const prevIsWhitespace = isWhitespace(src[i - 1]);
				const nextIsWhitespace = isWhitespace(src[i + 1]);
				if (prevIsWhitespace && nextIsWhitespace) {
					pendingSlash = true;
					start = i + 1;
					continue;
				}
				continue;
			}
			if (isWhitespace(ch)) {
				flush(false, false);
				continue;
			}
		}
	}
	flush(false, false);
}

//#endregion
export { scan };
//# sourceMappingURL=tokenizer.js.map