{"version":3,"file":"index.mjs","names":["wasmModule: any","initPromise: Promise<void> | null"],"sources":["../src/index.ts"],"sourcesContent":["/**\n * @windpress/oxide-parser\n * WASM-powered Tailwind CSS candidate parser.\n */\n\n// Import the WASM module - this will be handled by the bundler or CDN\nlet wasmModule: any = null;\nlet wasmInitialized = false;\nlet initPromise: Promise<void> | null = null;\n\n/**\n * Initialize the WASM module.\n * Safe to call multiple times (no-op if already initialized).\n * \n * @param wasmUrl - Optional custom WASM file URL\n */\nexport async function init(wasmUrl?: string): Promise<void> {\n  if (wasmInitialized) {\n    return;\n  }\n\n  // If initialization is already in progress, return the existing promise\n  if (initPromise) {\n    return initPromise;\n  }\n\n  initPromise = (async () => {\n    try {\n      // Try to import from the pkg directory (for local builds)\n      const module = await import('../pkg/oxide_parser.js');\n      \n      if (wasmUrl) {\n        // If custom WASM URL provided, use it\n        await module.default(wasmUrl);\n      } else {\n        // Auto-detect WASM location\n        await module.default();\n      }\n      \n      wasmModule = module;\n      wasmInitialized = true;\n    } catch (error) {\n      initPromise = null; // Reset so retry is possible\n      throw new Error(\n        `Failed to initialize WASM module: ${error instanceof Error ? error.message : 'Unknown error'}`\n      );\n    }\n  })();\n\n  return initPromise;\n}\n\n/**\n * Extract Tailwind CSS candidates from input (auto-initializes WASM).\n * Returns unique candidates only.\n * \n * @param input - String or array of strings to parse\n * @returns Array of unique candidate strings\n */\nexport async function getCandidates(input: string | string[]): Promise<string[]> {\n  // Auto-initialize if not already initialized\n  if (!wasmInitialized) {\n    await init();\n  }\n\n  return wasmModule.getCandidates(input);\n}\n\n/**\n * Extract Tailwind CSS candidates synchronously.\n * Requires init() to be called first.\n * \n * @param input - String or array of strings to parse\n * @returns Array of unique candidate strings\n * @throws Error if not initialized\n */\nexport function getCandidatesSync(input: string | string[]): string[] {\n  if (!wasmInitialized || !wasmModule) {\n    throw new Error(\n      'WASM module not initialized. Call init() and await it before using getCandidatesSync(), or use the async getCandidates() instead.'\n    );\n  }\n\n  return wasmModule.getCandidates(input);\n}\n\n/**\n * Check if WASM module is initialized.\n */\nexport function isInitialized(): boolean {\n  return wasmInitialized;\n}\n\n// Export types\nexport type TailwindCandidate = string;\nexport type ParseResult = TailwindCandidate[];\nexport type BatchParseResult = ParseResult[];\n\n// Re-export for convenience\nexport { init as default };\n"],"mappings":";;;;;AAMA,IAAIA,aAAkB;AACtB,IAAI,kBAAkB;AACtB,IAAIC,cAAoC;;;;;;;AAQxC,eAAsB,KAAK,SAAiC;AAC1D,KAAI,gBACF;AAIF,KAAI,YACF,QAAO;AAGT,gBAAe,YAAY;AACzB,MAAI;GAEF,MAAM,SAAS,MAAM,OAAO;AAE5B,OAAI,QAEF,OAAM,OAAO,QAAQ,QAAQ;OAG7B,OAAM,OAAO,SAAS;AAGxB,gBAAa;AACb,qBAAkB;WACX,OAAO;AACd,iBAAc;AACd,SAAM,IAAI,MACR,qCAAqC,iBAAiB,QAAQ,MAAM,UAAU,kBAC/E;;KAED;AAEJ,QAAO;;;;;;;;;AAUT,eAAsB,cAAc,OAA6C;AAE/E,KAAI,CAAC,gBACH,OAAM,MAAM;AAGd,QAAO,WAAW,cAAc,MAAM;;;;;;;;;;AAWxC,SAAgB,kBAAkB,OAAoC;AACpE,KAAI,CAAC,mBAAmB,CAAC,WACvB,OAAM,IAAI,MACR,oIACD;AAGH,QAAO,WAAW,cAAc,MAAM;;;;;AAMxC,SAAgB,gBAAyB;AACvC,QAAO"}