resuxjs 0.4.0-beta.7 → 0.4.0-beta.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (180) hide show
  1. package/dist/_virtual/_rolldown/runtime.js +4 -0
  2. package/dist/build/index.d.ts +1 -2
  3. package/dist/cli.d.ts +3 -3
  4. package/dist/cli.js +125 -31
  5. package/dist/cli.js.map +1 -1
  6. package/dist/compiler/adapter.d.ts +2 -3
  7. package/dist/compiler/adapter.js +2 -2
  8. package/dist/compiler/dev-warnings.d.ts +1 -2
  9. package/dist/compiler/directives.d.ts +1 -2
  10. package/dist/compiler/implementation.d.ts +4 -2
  11. package/dist/compiler/implementation.js +68 -30
  12. package/dist/compiler/index.d.ts +2 -3
  13. package/dist/compiler/index.js +2 -2
  14. package/dist/compiler/index.js.map +1 -1
  15. package/dist/core/config.d.ts +1 -2
  16. package/dist/core/hooks.d.ts +10 -2
  17. package/dist/core/hooks.js.map +1 -1
  18. package/dist/core/index.d.ts +2 -2
  19. package/dist/core/module-container.d.ts +1 -2
  20. package/dist/core/module-container.js +2 -1
  21. package/dist/core/module-container.js.map +1 -1
  22. package/dist/core/resux.d.ts +1 -2
  23. package/dist/create.d.ts +1 -2
  24. package/dist/create.js +104 -33
  25. package/dist/create.js.map +1 -1
  26. package/dist/deploy/cloudflare.d.ts +1 -2
  27. package/dist/deploy/common.d.ts +1 -2
  28. package/dist/deploy/framework-runtime.d.ts +1 -2
  29. package/dist/deploy/index.d.ts +1 -2
  30. package/dist/deploy/netlify.d.ts +1 -2
  31. package/dist/deploy/node.d.ts +1 -2
  32. package/dist/deploy/production-report.d.ts +1 -2
  33. package/dist/deploy/runtime-dependencies.d.ts +1 -2
  34. package/dist/deploy/static.d.ts +1 -2
  35. package/dist/deploy/types.d.ts +1 -2
  36. package/dist/deploy/vercel.d.ts +1 -2
  37. package/dist/deploy/vercel.js +3 -3
  38. package/dist/deploy/vercel.js.map +1 -1
  39. package/dist/fonts/index.d.ts +1 -2
  40. package/dist/fonts/index.js.map +1 -1
  41. package/dist/globals.d.ts +1 -2
  42. package/dist/halal-core/ai/classifyProject.d.ts +1 -2
  43. package/dist/halal-core/ai/classifyRuntimeContent.d.ts +1 -2
  44. package/dist/halal-core/ai/createProjectSummary.d.ts +1 -2
  45. package/dist/halal-core/ai/halalClassifierPrompt.d.ts +1 -2
  46. package/dist/halal-core/ai/redactSensitiveData.d.ts +1 -2
  47. package/dist/halal-core/ai/validateAiResponse.d.ts +1 -2
  48. package/dist/halal-core/cli/check.d.ts +1 -2
  49. package/dist/halal-core/cli/explain.d.ts +1 -2
  50. package/dist/halal-core/cli/report.d.ts +1 -2
  51. package/dist/halal-core/cli/submitReview.d.ts +1 -2
  52. package/dist/halal-core/cli/verifyReview.d.ts +1 -2
  53. package/dist/halal-core/config.d.ts +2 -2
  54. package/dist/halal-core/config.js.map +1 -1
  55. package/dist/halal-core/crypto/integrity.d.ts +1 -2
  56. package/dist/halal-core/crypto/integrity.js +1 -1
  57. package/dist/halal-core/crypto/integrity.js.map +1 -1
  58. package/dist/halal-core/enforce.d.ts +4 -3
  59. package/dist/halal-core/enforce.js +31 -4
  60. package/dist/halal-core/enforce.js.map +1 -1
  61. package/dist/halal-core/lifecycle.d.ts +1 -2
  62. package/dist/halal-core/policy.d.ts +1 -2
  63. package/dist/halal-core/report/formatBrowserOverlay.d.ts +1 -2
  64. package/dist/halal-core/report/formatTerminalReport.d.ts +1 -2
  65. package/dist/halal-core/report/generateHalalReport.d.ts +1 -2
  66. package/dist/halal-core/report/signReport.d.ts +1 -2
  67. package/dist/halal-core/report/verifyReport.d.ts +1 -2
  68. package/dist/halal-core/review/createReviewRequest.d.ts +1 -2
  69. package/dist/halal-core/review/reviewPolicy.d.ts +1 -2
  70. package/dist/halal-core/review/signedReviewFile.d.ts +1 -2
  71. package/dist/halal-core/review/verifyReviewApproval.d.ts +1 -2
  72. package/dist/halal-core/rules/adultContentRules.d.ts +1 -2
  73. package/dist/halal-core/rules/alcoholDrugVapeRules.d.ts +1 -2
  74. package/dist/halal-core/rules/childSafetyRules.d.ts +1 -2
  75. package/dist/halal-core/rules/coreCategories.d.ts +1 -2
  76. package/dist/halal-core/rules/cyberAbuseRules.d.ts +1 -2
  77. package/dist/halal-core/rules/defaultBlockedRules.d.ts +1 -2
  78. package/dist/halal-core/rules/dependencyRules.d.ts +1 -2
  79. package/dist/halal-core/rules/endpointRules.d.ts +1 -2
  80. package/dist/halal-core/rules/environmentalHarmRules.d.ts +1 -2
  81. package/dist/halal-core/rules/financeRibaRules.d.ts +1 -2
  82. package/dist/halal-core/rules/gamblingRules.d.ts +1 -2
  83. package/dist/halal-core/rules/generalHarmRules.d.ts +1 -2
  84. package/dist/halal-core/rules/healthHarmRules.d.ts +1 -2
  85. package/dist/halal-core/rules/keywordRules.d.ts +1 -2
  86. package/dist/halal-core/rules/privacyAbuseRules.d.ts +1 -2
  87. package/dist/halal-core/rules/scamFraudRules.d.ts +1 -2
  88. package/dist/halal-core/rules/selfHarmRules.d.ts +1 -2
  89. package/dist/halal-core/rules/violenceExtremismRules.d.ts +1 -2
  90. package/dist/halal-core/runtime/guard.d.ts +1 -2
  91. package/dist/halal-core/runtime/guard.js.map +1 -1
  92. package/dist/halal-core/runtime/reviewedMemory.d.ts +1 -2
  93. package/dist/halal-core/runtime/serializeRuntimeContent.d.ts +1 -2
  94. package/dist/halal-core/runtime/types.d.ts +1 -2
  95. package/dist/halal-core/scanner/scanApiRoutes.d.ts +1 -2
  96. package/dist/halal-core/scanner/scanComponents.d.ts +1 -2
  97. package/dist/halal-core/scanner/scanContent.d.ts +1 -2
  98. package/dist/halal-core/scanner/scanDependencies.d.ts +1 -2
  99. package/dist/halal-core/scanner/scanDomains.d.ts +1 -2
  100. package/dist/halal-core/scanner/scanEnvNames.d.ts +1 -2
  101. package/dist/halal-core/scanner/scanMetadata.d.ts +1 -2
  102. package/dist/halal-core/scanner/scanPages.d.ts +1 -2
  103. package/dist/halal-core/scanner/scanProject.d.ts +1 -2
  104. package/dist/halal-core/scanner/scanRoutes.d.ts +1 -2
  105. package/dist/halal-core/scanner/scanTranslations.d.ts +1 -2
  106. package/dist/halal-core/status.d.ts +1 -2
  107. package/dist/halal-core/tamper/verifyCoreIntegrity.d.ts +1 -2
  108. package/dist/halal-core/tamper/verifyLifecycleHooks.d.ts +1 -2
  109. package/dist/halal-core/tamper/verifyReportSignature.d.ts +1 -2
  110. package/dist/head/utils.d.ts +15 -0
  111. package/dist/head/utils.js +52 -0
  112. package/dist/head/utils.js.map +1 -0
  113. package/dist/i18n/index.d.ts +1 -2
  114. package/dist/i18n/index.js.map +1 -1
  115. package/dist/i18n/shared.d.ts +1 -2
  116. package/dist/icons/api-fetcher.d.ts +1 -2
  117. package/dist/icons/cache.d.ts +1 -2
  118. package/dist/icons/cache.js.map +1 -1
  119. package/dist/icons/component.d.ts +9 -10
  120. package/dist/icons/constants.d.ts +1 -2
  121. package/dist/icons/css-mode.d.ts +1 -2
  122. package/dist/icons/index.d.ts +1 -2
  123. package/dist/icons/index.js.map +1 -1
  124. package/dist/icons/local-svg.d.ts +1 -2
  125. package/dist/icons/normalize.d.ts +1 -2
  126. package/dist/icons/offline-loader.d.ts +1 -2
  127. package/dist/icons/parser.d.ts +1 -2
  128. package/dist/icons/registry.d.ts +1 -2
  129. package/dist/icons/resolver.d.ts +1 -2
  130. package/dist/icons/svg-mode.d.ts +1 -2
  131. package/dist/icons/transform.d.ts +1 -2
  132. package/dist/icons/types.d.ts +1 -2
  133. package/dist/index.d.ts +2 -2
  134. package/dist/index.js +2 -2
  135. package/dist/kit/index.d.ts +1 -2
  136. package/dist/nitro-server/index.d.ts +1 -2
  137. package/dist/node.d.ts +1 -2
  138. package/dist/reactivity/computed.d.ts +1 -2
  139. package/dist/reactivity/computed.js.map +1 -1
  140. package/dist/reactivity/effect.d.ts +3 -3
  141. package/dist/reactivity/effect.js +8 -3
  142. package/dist/reactivity/effect.js.map +1 -1
  143. package/dist/reactivity/reactive.d.ts +1 -2
  144. package/dist/reactivity/reactive.js +221 -11
  145. package/dist/reactivity/reactive.js.map +1 -1
  146. package/dist/reactivity/ref.d.ts +1 -2
  147. package/dist/reactivity/ref.js.map +1 -1
  148. package/dist/reactivity/scheduler.d.ts +1 -2
  149. package/dist/reactivity/scheduler.js +2 -0
  150. package/dist/reactivity/scheduler.js.map +1 -1
  151. package/dist/reactivity/types.d.ts +1 -2
  152. package/dist/reactivity/utils.d.ts +1 -2
  153. package/dist/reactivity/watch.d.ts +1 -2
  154. package/dist/reactivity/watch.js.map +1 -1
  155. package/dist/runtime/core.d.ts +1 -2
  156. package/dist/runtime/core.js.map +1 -1
  157. package/dist/runtime/index.d.ts +19 -2
  158. package/dist/runtime/index.js +480 -79
  159. package/dist/runtime/index.js.map +1 -1
  160. package/dist/runtime/resume.d.ts +1 -2
  161. package/dist/runtime/resume.js.map +1 -1
  162. package/dist/runtime/router.d.ts +1 -2
  163. package/dist/runtime/router.js.map +1 -1
  164. package/dist/runtime/streaming.d.ts +1 -2
  165. package/dist/runtime/streaming.js.map +1 -1
  166. package/dist/runtime/view-transitions/detect.d.ts +1 -2
  167. package/dist/runtime/view-transitions/transition.d.ts +1 -2
  168. package/dist/runtime/view-transitions/types.d.ts +1 -2
  169. package/dist/security/media-fetch.d.ts +1 -2
  170. package/dist/security/media-fetch.js.map +1 -1
  171. package/dist/security/path-boundary.d.ts +1 -2
  172. package/dist/security/path-boundary.js +10 -4
  173. package/dist/security/path-boundary.js.map +1 -1
  174. package/dist/ui/index.d.ts +47 -48
  175. package/dist/ui/verification-code.d.ts +3 -4
  176. package/dist/ui/verification-code.js.map +1 -1
  177. package/dist/vite-builder/index.d.ts +1 -2
  178. package/package.json +2 -2
  179. package/templates/default/.env.example +3 -0
  180. package/templates/default/nitro.config.ts +16 -4
@@ -8,5 +8,4 @@ export declare function verifyReportSignature(report: HalalCheckResult, options?
8
8
  export declare function isReportValid(report: HalalCheckResult, options?: ReportVerificationOptions): {
9
9
  valid: boolean;
10
10
  reason?: string;
11
- };
12
- //# sourceMappingURL=verifyReport.d.ts.map
11
+ };
@@ -1,3 +1,2 @@
1
1
  import { ResuxHalalPolicy } from "../config.js";
2
- export declare function createReviewRequest(appRoot: string, policy: ResuxHalalPolicy, outDir: string): string;
3
- //# sourceMappingURL=createReviewRequest.d.ts.map
2
+ export declare function createReviewRequest(appRoot: string, policy: ResuxHalalPolicy, outDir: string): string;
@@ -1,4 +1,3 @@
1
1
  export declare const REVIEWABLE_CATEGORIES: string[];
2
2
  export declare const NON_REVIEWABLE_CATEGORIES: string[];
3
- export declare function isCategoryReviewable(category: string): boolean;
4
- //# sourceMappingURL=reviewPolicy.d.ts.map
3
+ export declare function isCategoryReviewable(category: string): boolean;
@@ -10,5 +10,4 @@ export interface SignedReviewApproval {
10
10
  }
11
11
  export declare function generateReviewSignature(approval: Omit<SignedReviewApproval, "signature">, secret?: string): string;
12
12
  export declare function verifyReviewSignature(approval: SignedReviewApproval, secret?: string): boolean;
13
- export declare function createReviewEvidenceHash(report: HalalCheckResult | Omit<HalalCheckResult, "signature">): string;
14
- //# sourceMappingURL=signedReviewFile.d.ts.map
13
+ export declare function createReviewEvidenceHash(report: HalalCheckResult | Omit<HalalCheckResult, "signature">): string;
@@ -7,5 +7,4 @@ export interface ReviewApprovalVerificationOptions {
7
7
  export declare function verifyReviewApproval(appRoot: string, currentStatus: string, options?: ReviewApprovalVerificationOptions): {
8
8
  approved: boolean;
9
9
  reason?: string;
10
- };
11
- //# sourceMappingURL=verifyReviewApproval.d.ts.map
10
+ };
@@ -1,3 +1,2 @@
1
1
  export declare const ADULT_PATTERNS: RegExp[];
2
- export declare function checkAdult(text: string): string[];
3
- //# sourceMappingURL=adultContentRules.d.ts.map
2
+ export declare function checkAdult(text: string): string[];
@@ -1,3 +1,2 @@
1
1
  export declare const ALCOHOL_DRUG_VAPE_PATTERNS: RegExp[];
2
- export declare function checkAlcoholDrugVape(text: string): string[];
3
- //# sourceMappingURL=alcoholDrugVapeRules.d.ts.map
2
+ export declare function checkAlcoholDrugVape(text: string): string[];
@@ -1,3 +1,2 @@
1
1
  export declare const CHILD_SAFETY_PATTERNS: RegExp[];
2
- export declare function checkChildSafety(text: string): string[];
3
- //# sourceMappingURL=childSafetyRules.d.ts.map
2
+ export declare function checkChildSafety(text: string): string[];
@@ -4,5 +4,4 @@ export interface CategoryDefinition {
4
4
  description: string;
5
5
  keywords: string[];
6
6
  }
7
- export declare const BLOCKED_CATEGORIES: CategoryDefinition[];
8
- //# sourceMappingURL=coreCategories.d.ts.map
7
+ export declare const BLOCKED_CATEGORIES: CategoryDefinition[];
@@ -1,3 +1,2 @@
1
1
  export declare const CYBER_ABUSE_PATTERNS: RegExp[];
2
- export declare function checkCyberAbuse(text: string): string[];
3
- //# sourceMappingURL=cyberAbuseRules.d.ts.map
2
+ export declare function checkCyberAbuse(text: string): string[];
@@ -17,5 +17,4 @@ export declare function evaluateRules(scannedData: {
17
17
  text: string;
18
18
  }>;
19
19
  endpoints: string[];
20
- }, policy: ResuxHalalPolicy): HalalCheckResult;
21
- //# sourceMappingURL=defaultBlockedRules.d.ts.map
20
+ }, policy: ResuxHalalPolicy): HalalCheckResult;
@@ -6,5 +6,4 @@ export declare function checkDependencies(dependencies?: Record<string, string>)
6
6
  name: string;
7
7
  category: string;
8
8
  reason: string;
9
- }>;
10
- //# sourceMappingURL=dependencyRules.d.ts.map
9
+ }>;
@@ -3,5 +3,4 @@ export declare function checkEndpoints(endpoints: string[]): Array<{
3
3
  endpoint: string;
4
4
  category: string;
5
5
  reason: string;
6
- }>;
7
- //# sourceMappingURL=endpointRules.d.ts.map
6
+ }>;
@@ -1,3 +1,2 @@
1
1
  export declare const ENVIRONMENTAL_HARM_PATTERNS: RegExp[];
2
- export declare function checkEnvironmentalHarm(text: string): string[];
3
- //# sourceMappingURL=environmentalHarmRules.d.ts.map
2
+ export declare function checkEnvironmentalHarm(text: string): string[];
@@ -1,3 +1,2 @@
1
1
  export declare const RIBA_PATTERNS: RegExp[];
2
- export declare function checkRiba(text: string): string[];
3
- //# sourceMappingURL=financeRibaRules.d.ts.map
2
+ export declare function checkRiba(text: string): string[];
@@ -1,3 +1,2 @@
1
1
  export declare const GAMBLING_PATTERNS: RegExp[];
2
- export declare function checkGambling(text: string): string[];
3
- //# sourceMappingURL=gamblingRules.d.ts.map
2
+ export declare function checkGambling(text: string): string[];
@@ -1,3 +1,2 @@
1
1
  export declare const GENERAL_HARM_PATTERNS: RegExp[];
2
- export declare function checkGeneralHarm(text: string): string[];
3
- //# sourceMappingURL=generalHarmRules.d.ts.map
2
+ export declare function checkGeneralHarm(text: string): string[];
@@ -1,3 +1,2 @@
1
1
  export declare const HEALTH_HARM_PATTERNS: RegExp[];
2
- export declare function checkHealthHarm(text: string): string[];
3
- //# sourceMappingURL=healthHarmRules.d.ts.map
2
+ export declare function checkHealthHarm(text: string): string[];
@@ -7,5 +7,4 @@ export declare const KEYWORD_RULES: {
7
7
  violence: RegExp[];
8
8
  harassment: RegExp[];
9
9
  privacy: RegExp[];
10
- };
11
- //# sourceMappingURL=keywordRules.d.ts.map
10
+ };
@@ -1,3 +1,2 @@
1
1
  export declare const PRIVACY_ABUSE_PATTERNS: RegExp[];
2
- export declare function checkPrivacyAbuse(text: string): string[];
3
- //# sourceMappingURL=privacyAbuseRules.d.ts.map
2
+ export declare function checkPrivacyAbuse(text: string): string[];
@@ -1,3 +1,2 @@
1
1
  export declare const SCAM_FRAUD_PATTERNS: RegExp[];
2
- export declare function checkScamFraud(text: string): string[];
3
- //# sourceMappingURL=scamFraudRules.d.ts.map
2
+ export declare function checkScamFraud(text: string): string[];
@@ -1,3 +1,2 @@
1
1
  export declare const SELF_HARM_PATTERNS: RegExp[];
2
- export declare function checkSelfHarm(text: string): string[];
3
- //# sourceMappingURL=selfHarmRules.d.ts.map
2
+ export declare function checkSelfHarm(text: string): string[];
@@ -1,3 +1,2 @@
1
1
  export declare const VIOLENCE_EXTREMISM_PATTERNS: RegExp[];
2
- export declare function checkViolenceExtremism(text: string): string[];
3
- //# sourceMappingURL=violenceExtremismRules.d.ts.map
2
+ export declare function checkViolenceExtremism(text: string): string[];
@@ -16,5 +16,4 @@ export declare function createHalalRuntimeGuard(options?: HalalRuntimeGuardOptio
16
16
  }[];
17
17
  }>;
18
18
  };
19
- export declare function evaluateHalalRuntimeContent(content: HalalRuntimeContent, options?: HalalRuntimeGuardOptions): Promise<HalalRuntimeDecision>;
20
- //# sourceMappingURL=guard.d.ts.map
19
+ export declare function evaluateHalalRuntimeContent(content: HalalRuntimeContent, options?: HalalRuntimeGuardOptions): Promise<HalalRuntimeDecision>;
@@ -1 +1 @@
1
- {"version":3,"file":"guard.js","names":[],"sources":["../../../src/halal-core/runtime/guard.ts"],"sourcesContent":["import { classifyRuntimeContentWithAi } from \"../ai/classifyRuntimeContent.js\";\nimport { evaluateRules } from \"../rules/defaultBlockedRules.js\";\nimport { scanDomains } from \"../scanner/scanDomains.js\";\nimport type { HalalCheckResult, HalalGuardStatus } from \"../status.js\";\nimport {\n createRuntimeContentFingerprint,\n findReviewedRuntimeDecision,\n} from \"./reviewedMemory.js\";\nimport {\n prepareRuntimeContent,\n type RuntimeContentInspectionIssue,\n} from \"./serializeRuntimeContent.js\";\nimport type {\n HalalRuntimeContent,\n HalalRuntimeDecision,\n HalalRuntimeGuardOptions,\n} from \"./types.js\";\n\nconst STATUS_RANK: Record<HalalGuardStatus, number> = {\n allowed: 0,\n warning: 1,\n review_required: 2,\n blocked: 3,\n};\n\nconst RISK_RANK: Record<HalalCheckResult[\"riskLevel\"], number> = {\n low: 0,\n medium: 1,\n high: 2,\n critical: 3,\n};\n\nexport class HalalRuntimeBlockedError extends Error {\n readonly decision: HalalRuntimeDecision;\n\n constructor(decision: HalalRuntimeDecision) {\n super(decision.reasons[0] || \"Runtime content was rejected by the halal guard.\");\n this.name = \"HalalRuntimeBlockedError\";\n this.decision = decision;\n }\n}\n\nexport function createHalalRuntimeGuard(options: HalalRuntimeGuardOptions = {}) {\n return {\n check(content: HalalRuntimeContent): Promise<HalalRuntimeDecision> {\n return evaluateHalalRuntimeContent(content, options);\n },\n\n checkDynamicPage(content: Omit<HalalRuntimeContent, \"kind\">): Promise<HalalRuntimeDecision> {\n return evaluateHalalRuntimeContent({ ...content, kind: \"dynamic_page\" }, options);\n },\n\n checkAd(content: Omit<HalalRuntimeContent, \"kind\">): Promise<HalalRuntimeDecision> {\n return evaluateHalalRuntimeContent({ ...content, kind: \"advertisement\" }, options);\n },\n\n async assertAllowed(content: HalalRuntimeContent): Promise<HalalRuntimeDecision> {\n const decision = await evaluateHalalRuntimeContent(content, options);\n if (!decision.allowed) {\n throw new HalalRuntimeBlockedError(decision);\n }\n return decision;\n },\n\n async filterAds<T extends Omit<HalalRuntimeContent, \"kind\">>(ads: readonly T[]) {\n const checked = await Promise.all(ads.map(async (ad) => ({\n ad,\n decision: await evaluateHalalRuntimeContent({ ...ad, kind: \"advertisement\" }, options),\n })));\n return {\n allowed: checked.filter((entry) => entry.decision.allowed).map((entry) => entry.ad),\n rejected: checked.filter((entry) => !entry.decision.allowed),\n };\n },\n };\n}\n\nexport async function evaluateHalalRuntimeContent(\n content: HalalRuntimeContent,\n options: HalalRuntimeGuardOptions = {},\n): Promise<HalalRuntimeDecision> {\n const serialized = prepareRuntimeContent(content, options.maxContentCharacters);\n const fingerprint = createRuntimeContentFingerprint(content);\n const file = `runtime:${content.kind}:${content.id || content.route || \"anonymous\"}`;\n const scannedResult = evaluateRules({\n routes: content.route ? [content.route] : [],\n pages: content.kind === \"dynamic_page\" && content.route ? [content.route] : [],\n components: [],\n metadata: {\n title: content.title,\n description: content.advertiser\n ? `Advertiser: ${content.advertiser}`\n : `${content.kind} runtime content`,\n },\n envNames: [],\n dependencies: {},\n i18nWords: [],\n contentTexts: [{ file, text: serialized.localText }],\n endpoints: scanDomains([{ file, text: serialized.localText }]),\n }, options.policy ?? {});\n\n let localResult = scannedResult;\n if (serialized.truncated) {\n localResult = mergeResults(\n localResult,\n truncatedContentResult(file, serialized.maxCharacters),\n );\n }\n if (serialized.inspectionIssues.length > 0) {\n localResult = mergeResults(\n localResult,\n uninspectableContentResult(file, serialized.inspectionIssues),\n );\n }\n\n const reviewed = findReviewedRuntimeDecision(\n content,\n options.reviewedDecisions,\n options.reviewSecret,\n );\n if (reviewed) {\n const reviewedResult = decisionFromReviewedMemory(content, fingerprint, reviewed, options.strict === true);\n if (STATUS_RANK[reviewedResult.status] >= STATUS_RANK[localResult.status]\n || STATUS_RANK[localResult.status] <= STATUS_RANK.warning) {\n return reviewedResult;\n }\n }\n\n if (localResult.status === \"blocked\") {\n return finalizeDecision(content, fingerprint, localResult, \"local_rules\", options.strict === true);\n }\n\n const aiResult = await classifyRuntimeContentWithAi(\n content,\n serialized.aiText,\n localResult,\n options.ai,\n );\n const requiresAi = content.kind === \"advertisement\"\n ? options.ai?.requireForAds !== false\n : options.ai?.requireForDynamicContent === true;\n\n if (!aiResult && requiresAi) {\n const unverified = mergeResults(localResult, {\n status: \"review_required\",\n riskLevel: \"medium\",\n categories: [content.kind === \"advertisement\" ? \"unverified_ad\" : \"unverified_dynamic_content\"],\n confidence: 0,\n reasons: [\"Required runtime AI verification is not configured or unavailable.\"],\n matchedFiles: [file],\n matchedSnippets: [],\n recommendedAction: \"Do not render this content until AI verification or signed human review is available.\",\n });\n return finalizeDecision(content, fingerprint, unverified, \"local_rules\", options.strict === true);\n }\n\n const result = aiResult ? mergeResults(localResult, aiResult) : localResult;\n return finalizeDecision(\n content,\n fingerprint,\n result,\n aiResult ? \"local_and_ai\" : \"local_rules\",\n options.strict === true,\n );\n}\n\nfunction truncatedContentResult(file: string, maxCharacters: number): HalalCheckResult {\n return {\n status: \"review_required\",\n riskLevel: \"medium\",\n categories: [\"runtime_content_truncated\"],\n confidence: 1,\n reasons: [\n `Runtime content exceeded the ${maxCharacters}-character scan limit and was not fully inspected.`,\n ],\n matchedFiles: [file],\n matchedSnippets: [],\n recommendedAction: \"Increase maxContentCharacters or complete a manual review before rendering.\",\n };\n}\n\nfunction uninspectableContentResult(\n file: string,\n issues: readonly RuntimeContentInspectionIssue[],\n): HalalCheckResult {\n const issueDescriptions = issues.map((issue) => {\n if (issue === \"max_depth\") return \"maximum serialization depth was reached\";\n if (issue === \"unreadable_property\") return \"one or more properties could not be read\";\n return \"one or more objects could not be inspected\";\n });\n\n return {\n status: \"review_required\",\n riskLevel: \"high\",\n categories: [\"runtime_content_uninspectable\"],\n confidence: 1,\n reasons: [\n `Runtime content could not be fully inspected: ${uniqueStrings(issueDescriptions).join(\"; \")}.`,\n ],\n matchedFiles: [file],\n matchedSnippets: [],\n recommendedAction: \"Normalize runtime content to plain inspectable data or complete a manual review before rendering.\",\n };\n}\n\nfunction decisionFromReviewedMemory(\n content: HalalRuntimeContent,\n fingerprint: string,\n reviewed: NonNullable<HalalRuntimeGuardOptions[\"reviewedDecisions\"]>[number],\n strict: boolean,\n): HalalRuntimeDecision {\n const result: HalalCheckResult = {\n status: reviewed.status,\n riskLevel: reviewed.status === \"blocked\"\n ? \"high\"\n : reviewed.status === \"review_required\"\n ? \"medium\"\n : reviewed.status === \"warning\"\n ? \"medium\"\n : \"low\",\n categories: reviewed.categories,\n confidence: 1,\n reasons: [`Signed review by ${reviewed.reviewerId}: ${reviewed.reason}`],\n matchedFiles: [],\n matchedSnippets: [],\n recommendedAction: reviewed.status === \"allowed\"\n ? \"Render the exact reviewed content.\"\n : \"Follow the signed runtime review decision.\",\n };\n return finalizeDecision(content, fingerprint, result, \"reviewed_memory\", strict);\n}\n\nfunction finalizeDecision(\n content: HalalRuntimeContent,\n fingerprint: string,\n result: HalalCheckResult,\n source: HalalRuntimeDecision[\"source\"],\n strict: boolean,\n): HalalRuntimeDecision {\n return {\n ...result,\n contentKind: content.kind,\n fingerprint,\n source,\n allowed: result.status === \"allowed\" || (result.status === \"warning\" && !strict),\n };\n}\n\nfunction mergeResults(left: HalalCheckResult, right: HalalCheckResult): HalalCheckResult {\n const leftRank = STATUS_RANK[left.status];\n const rightRank = STATUS_RANK[right.status];\n const dominant = rightRank > leftRank ? right : left;\n const riskLevel = RISK_RANK[right.riskLevel] > RISK_RANK[left.riskLevel]\n ? right.riskLevel\n : left.riskLevel;\n const confidence = leftRank === rightRank\n ? Math.max(left.confidence, right.confidence)\n : dominant.confidence;\n\n return {\n status: dominant.status,\n riskLevel,\n categories: uniqueStrings([...left.categories, ...right.categories]),\n confidence,\n reasons: uniqueStrings([...left.reasons, ...right.reasons]),\n matchedFiles: uniqueStrings([...left.matchedFiles, ...right.matchedFiles]),\n matchedSnippets: uniqueStrings([...left.matchedSnippets, ...right.matchedSnippets]),\n recommendedAction: dominant.recommendedAction,\n };\n}\n\nfunction uniqueStrings(values: string[]): string[] {\n return [...new Set(values.filter(Boolean))];\n}\n"],"mappings":";;;;;;AAkBA,MAAM,cAAgD;CACpD,SAAS;CACT,SAAS;CACT,iBAAiB;CACjB,SAAS;AACX;AAEA,MAAM,YAA2D;CAC/D,KAAK;CACL,QAAQ;CACR,MAAM;CACN,UAAU;AACZ;AAEA,IAAa,2BAAb,cAA8C,MAAM;CAClD;CAEA,YAAY,UAAgC;EAC1C,MAAM,SAAS,QAAQ,MAAM,kDAAkD;EAC/E,KAAK,OAAO;EACZ,KAAK,WAAW;CAClB;AACF;AAEA,SAAgB,wBAAwB,UAAoC,CAAC,GAAG;CAC9E,OAAO;EACL,MAAM,SAA6D;GACjE,OAAO,4BAA4B,SAAS,OAAO;EACrD;EAEA,iBAAiB,SAA2E;GAC1F,OAAO,4BAA4B;IAAE,GAAG;IAAS,MAAM;GAAe,GAAG,OAAO;EAClF;EAEA,QAAQ,SAA2E;GACjF,OAAO,4BAA4B;IAAE,GAAG;IAAS,MAAM;GAAgB,GAAG,OAAO;EACnF;EAEA,MAAM,cAAc,SAA6D;GAC/E,MAAM,WAAW,MAAM,4BAA4B,SAAS,OAAO;GACnE,IAAI,CAAC,SAAS,SACZ,MAAM,IAAI,yBAAyB,QAAQ;GAE7C,OAAO;EACT;EAEA,MAAM,UAAuD,KA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EACzE,iBAAiB,cAAc,CAAC,GAAG,KAAK,iBAAiB,GAAG,MAAM,eAAe,CAAC;EAClF,mBAAmB,SAAS;CAC9B;AACF;AAEA,SAAS,cAAc,QAA4B;CACjD,OAAO,CAAC,GAAG,IAAI,IAAI,OAAO,OAAO,OAAO,CAAC,CAAC;AAC5C"}
1
+ {"version":3,"file":"guard.js","names":[],"sources":["../../../src/halal-core/runtime/guard.ts"],"sourcesContent":["import { classifyRuntimeContentWithAi } from \"../ai/classifyRuntimeContent.js\";\nimport { evaluateRules } from \"../rules/defaultBlockedRules.js\";\nimport { scanDomains } from \"../scanner/scanDomains.js\";\nimport type { HalalCheckResult, HalalGuardStatus } from \"../status.js\";\nimport {\n createRuntimeContentFingerprint,\n findReviewedRuntimeDecision,\n} from \"./reviewedMemory.js\";\nimport {\n prepareRuntimeContent,\n type RuntimeContentInspectionIssue,\n} from \"./serializeRuntimeContent.js\";\nimport type {\n HalalRuntimeContent,\n HalalRuntimeDecision,\n HalalRuntimeGuardOptions,\n} from \"./types.js\";\n\nconst STATUS_RANK: Record<HalalGuardStatus, number> = {\n allowed: 0,\n warning: 1,\n review_required: 2,\n blocked: 3,\n};\n\nconst RISK_RANK: Record<HalalCheckResult[\"riskLevel\"], number> = {\n low: 0,\n medium: 1,\n high: 2,\n critical: 3,\n};\n\nexport class HalalRuntimeBlockedError extends Error {\n readonly decision: HalalRuntimeDecision;\n\n constructor(decision: HalalRuntimeDecision) {\n super(decision.reasons[0] || \"Runtime content was rejected by the halal guard.\");\n this.name = \"HalalRuntimeBlockedError\";\n this.decision = decision;\n }\n}\n\nexport function createHalalRuntimeGuard(options: HalalRuntimeGuardOptions = {}) {\n return {\n check(content: HalalRuntimeContent): Promise<HalalRuntimeDecision> {\n return evaluateHalalRuntimeContent(content, options);\n },\n\n checkDynamicPage(content: Omit<HalalRuntimeContent, \"kind\">): Promise<HalalRuntimeDecision> {\n return evaluateHalalRuntimeContent({ ...content, kind: \"dynamic_page\" }, options);\n },\n\n checkAd(content: Omit<HalalRuntimeContent, \"kind\">): Promise<HalalRuntimeDecision> {\n return evaluateHalalRuntimeContent({ ...content, kind: \"advertisement\" }, options);\n },\n\n async assertAllowed(content: HalalRuntimeContent): Promise<HalalRuntimeDecision> {\n const decision = await evaluateHalalRuntimeContent(content, options);\n if (!decision.allowed) {\n throw new HalalRuntimeBlockedError(decision);\n }\n return decision;\n },\n\n async filterAds<T extends Omit<HalalRuntimeContent, \"kind\">>(ads: readonly T[]) {\n const checked = await Promise.all(ads.map(async (ad) => ({\n ad,\n decision: await evaluateHalalRuntimeContent({ ...ad, kind: \"advertisement\" }, options),\n })));\n return {\n allowed: checked.filter((entry) => entry.decision.allowed).map((entry) => entry.ad),\n rejected: checked.filter((entry) => !entry.decision.allowed),\n };\n },\n };\n}\n\nexport async function evaluateHalalRuntimeContent(\n content: HalalRuntimeContent,\n options: HalalRuntimeGuardOptions = {},\n): Promise<HalalRuntimeDecision> {\n const serialized = prepareRuntimeContent(content, options.maxContentCharacters);\n const fingerprint = createRuntimeContentFingerprint(content);\n const file = `runtime:${content.kind}:${content.id || content.route || \"anonymous\"}`;\n const scannedResult = evaluateRules({\n routes: content.route ? [content.route] : [],\n pages: content.kind === \"dynamic_page\" && content.route ? [content.route] : [],\n components: [],\n metadata: {\n title: content.title,\n description: content.advertiser\n ? `Advertiser: ${content.advertiser}`\n : `${content.kind} runtime content`,\n },\n envNames: [],\n dependencies: {},\n i18nWords: [],\n contentTexts: [{ file, text: serialized.localText }],\n endpoints: scanDomains([{ file, text: serialized.localText }]),\n }, options.policy ?? {});\n\n let localResult = scannedResult;\n if (serialized.truncated) {\n localResult = mergeResults(\n localResult,\n truncatedContentResult(file, serialized.maxCharacters),\n );\n }\n if (serialized.inspectionIssues.length > 0) {\n localResult = mergeResults(\n localResult,\n uninspectableContentResult(file, serialized.inspectionIssues),\n );\n }\n\n const reviewed = findReviewedRuntimeDecision(\n content,\n options.reviewedDecisions,\n options.reviewSecret,\n );\n if (reviewed) {\n const reviewedResult = decisionFromReviewedMemory(content, fingerprint, reviewed, options.strict === true);\n if (STATUS_RANK[reviewedResult.status] >= STATUS_RANK[localResult.status]\n || STATUS_RANK[localResult.status] <= STATUS_RANK.warning) {\n return reviewedResult;\n }\n }\n\n if (localResult.status === \"blocked\") {\n return finalizeDecision(content, fingerprint, localResult, \"local_rules\", options.strict === true);\n }\n\n const aiResult = await classifyRuntimeContentWithAi(\n content,\n serialized.aiText,\n localResult,\n options.ai,\n );\n const requiresAi = content.kind === \"advertisement\"\n ? options.ai?.requireForAds !== false\n : options.ai?.requireForDynamicContent === true;\n\n if (!aiResult && requiresAi) {\n const unverified = mergeResults(localResult, {\n status: \"review_required\",\n riskLevel: \"medium\",\n categories: [content.kind === \"advertisement\" ? \"unverified_ad\" : \"unverified_dynamic_content\"],\n confidence: 0,\n reasons: [\"Required runtime AI verification is not configured or unavailable.\"],\n matchedFiles: [file],\n matchedSnippets: [],\n recommendedAction: \"Do not render this content until AI verification or signed human review is available.\",\n });\n return finalizeDecision(content, fingerprint, unverified, \"local_rules\", options.strict === true);\n }\n\n const result = aiResult ? mergeResults(localResult, aiResult) : localResult;\n return finalizeDecision(\n content,\n fingerprint,\n result,\n aiResult ? \"local_and_ai\" : \"local_rules\",\n options.strict === true,\n );\n}\n\nfunction truncatedContentResult(file: string, maxCharacters: number): HalalCheckResult {\n return {\n status: \"review_required\",\n riskLevel: \"medium\",\n categories: [\"runtime_content_truncated\"],\n confidence: 1,\n reasons: [\n `Runtime content exceeded the ${maxCharacters}-character scan limit and was not fully inspected.`,\n ],\n matchedFiles: [file],\n matchedSnippets: [],\n recommendedAction: \"Increase maxContentCharacters or complete a manual review before rendering.\",\n };\n}\n\nfunction uninspectableContentResult(\n file: string,\n issues: readonly RuntimeContentInspectionIssue[],\n): HalalCheckResult {\n const issueDescriptions = issues.map((issue) => {\n if (issue === \"max_depth\") return \"maximum serialization depth was reached\";\n if (issue === \"unreadable_property\") return \"one or more properties could not be read\";\n return \"one or more objects could not be inspected\";\n });\n\n return {\n status: \"review_required\",\n riskLevel: \"high\",\n categories: [\"runtime_content_uninspectable\"],\n confidence: 1,\n reasons: [\n `Runtime content could not be fully inspected: ${uniqueStrings(issueDescriptions).join(\"; \")}.`,\n ],\n matchedFiles: [file],\n matchedSnippets: [],\n recommendedAction: \"Normalize runtime content to plain inspectable data or complete a manual review before rendering.\",\n };\n}\n\nfunction decisionFromReviewedMemory(\n content: HalalRuntimeContent,\n fingerprint: string,\n reviewed: NonNullable<HalalRuntimeGuardOptions[\"reviewedDecisions\"]>[number],\n strict: boolean,\n): HalalRuntimeDecision {\n const result: HalalCheckResult = {\n status: reviewed.status,\n riskLevel: reviewed.status === \"blocked\"\n ? \"high\"\n : reviewed.status === \"review_required\"\n ? \"medium\"\n : reviewed.status === \"warning\"\n ? \"medium\"\n : \"low\",\n categories: reviewed.categories,\n confidence: 1,\n reasons: [`Signed review by ${reviewed.reviewerId}: ${reviewed.reason}`],\n matchedFiles: [],\n matchedSnippets: [],\n recommendedAction: reviewed.status === \"allowed\"\n ? \"Render the exact reviewed content.\"\n : \"Follow the signed runtime review decision.\",\n };\n return finalizeDecision(content, fingerprint, result, \"reviewed_memory\", strict);\n}\n\nfunction finalizeDecision(\n content: HalalRuntimeContent,\n fingerprint: string,\n result: HalalCheckResult,\n source: HalalRuntimeDecision[\"source\"],\n strict: boolean,\n): HalalRuntimeDecision {\n return {\n ...result,\n contentKind: content.kind,\n fingerprint,\n source,\n allowed: result.status === \"allowed\" || (result.status === \"warning\" && !strict),\n };\n}\n\nfunction mergeResults(left: HalalCheckResult, right: HalalCheckResult): HalalCheckResult {\n const leftRank = STATUS_RANK[left.status];\n const rightRank = STATUS_RANK[right.status];\n const dominant = rightRank > leftRank ? right : left;\n const riskLevel = RISK_RANK[right.riskLevel] > RISK_RANK[left.riskLevel]\n ? right.riskLevel\n : left.riskLevel;\n const confidence = leftRank === rightRank\n ? Math.max(left.confidence, right.confidence)\n : dominant.confidence;\n\n return {\n status: dominant.status,\n riskLevel,\n categories: uniqueStrings([...left.categories, ...right.categories]),\n confidence,\n reasons: uniqueStrings([...left.reasons, ...right.reasons]),\n matchedFiles: uniqueStrings([...left.matchedFiles, ...right.matchedFiles]),\n matchedSnippets: uniqueStrings([...left.matchedSnippets, ...right.matchedSnippets]),\n recommendedAction: dominant.recommendedAction,\n };\n}\n\nfunction uniqueStrings(values: string[]): string[] {\n return [...new Set(values.filter(Boolean))];\n}\n"],"mappings":";;;;;;AAkBA,MAAM,cAAgD;CACpD,SAAS;CACT,SAAS;CACT,iBAAiB;CACjB,SAAS;AACX;AAEA,MAAM,YAA2D;CAC/D,KAAK;CACL,QAAQ;CACR,MAAM;CACN,UAAU;AACZ;AAEA,IAAa,2BAAb,cAA8C,MAAM;CACzC;CAET,YAAY,UAAgC;EAC1C,MAAM,SAAS,QAAQ,MAAM,kDAAkD;EAC/E,KAAK,OAAO;EACZ,KAAK,WAAW;CAClB;AACF;AAEA,SAAgB,wBAAwB,UAAoC,CAAC,GAAG;CAC9E,OAAO;EACL,MAAM,SAA6D;GACjE,OAAO,4BAA4B,SAAS,OAAO;EACrD;EAEA,iBAAiB,SAA2E;GAC1F,OAAO,4BAA4B;IAAE,GAAG;IAAS,MAAM;GAAe,GAAG,OAAO;EAClF;EAEA,QAAQ,SAA2E;GACjF,OAAO,4BAA4B;IAAE,GAAG;IAAS,MAAM;GAAgB,GAAG,OAAO;EACnF;EAEA,MAAM,cAAc,SAA6D;GAC/E,MAAM,WAAW,MAAM,4BAA4B,SAAS,OAAO;GACnE,IAAI,CAAC,SAAS,SACZ,MAAM,IAAI,yBAAyB,QAAQ;GAE7C,OAAO;EACT;EAEA,MAAM,UAAuD,KAAmB;GAC9E,MAAM,UAAU,MAAM,QAAQ,IAAI,IAAI,IAAI,OAAO,QAAQ;IACvD;IACA,UAAU,MAAM,4BAA4B;KAAE,GAAG;KAAI,MAAM;IAAgB,GAAG,OAAO;GACvF,EAAE,CAAC;GACH,OAAO;IACL,SAAS,QAAQ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,CAAC;AAC5C"}
@@ -2,5 +2,4 @@ import { HalalRuntimeContent, HalalRuntimeReviewInput, SignedHalalRuntimeDecisio
2
2
  export declare function createRuntimeContentFingerprint(content: HalalRuntimeContent, _maxContentCharacters?: number): string;
3
3
  export declare function createSignedHalalRuntimeDecision(content: HalalRuntimeContent, review: HalalRuntimeReviewInput, secret?: string): SignedHalalRuntimeDecision;
4
4
  export declare function verifySignedHalalRuntimeDecision(decision: unknown, secret?: string): decision is SignedHalalRuntimeDecision;
5
- export declare function findReviewedRuntimeDecision(content: HalalRuntimeContent, decisions: readonly SignedHalalRuntimeDecision[] | undefined, secret?: string, _maxContentCharacters?: number): SignedHalalRuntimeDecision | undefined;
6
- //# sourceMappingURL=reviewedMemory.d.ts.map
5
+ export declare function findReviewedRuntimeDecision(content: HalalRuntimeContent, decisions: readonly SignedHalalRuntimeDecision[] | undefined, secret?: string, _maxContentCharacters?: number): SignedHalalRuntimeDecision | undefined;
@@ -10,5 +10,4 @@ export interface PreparedRuntimeContent {
10
10
  }
11
11
  export declare function serializeRuntimeContent(content: HalalRuntimeContent, maxCharacters?: number): string;
12
12
  export declare function prepareRuntimeContent(content: HalalRuntimeContent, maxCharacters?: number): PreparedRuntimeContent;
13
- export declare function serializeRuntimeContentCanonical(content: HalalRuntimeContent): string;
14
- //# sourceMappingURL=serializeRuntimeContent.d.ts.map
13
+ export declare function serializeRuntimeContentCanonical(content: HalalRuntimeContent): string;
@@ -54,5 +54,4 @@ export interface HalalRuntimeReviewInput {
54
54
  reason: string;
55
55
  reviewerId: string;
56
56
  expiresAt?: string;
57
- }
58
- //# sourceMappingURL=types.d.ts.map
57
+ }
@@ -1,2 +1 @@
1
- export declare function scanApiRoutes(appRoot: string): string[];
2
- //# sourceMappingURL=scanApiRoutes.d.ts.map
1
+ export declare function scanApiRoutes(appRoot: string): string[];
@@ -1,2 +1 @@
1
- export declare function scanComponents(appRoot: string): string[];
2
- //# sourceMappingURL=scanComponents.d.ts.map
1
+ export declare function scanComponents(appRoot: string): string[];
@@ -2,5 +2,4 @@ export interface ScanResult {
2
2
  file: string;
3
3
  text: string;
4
4
  }
5
- export declare function scanContentFiles(dir: string, appRoot: string, ignoredPaths?: Set<string>): ScanResult[];
6
- //# sourceMappingURL=scanContent.d.ts.map
5
+ export declare function scanContentFiles(dir: string, appRoot: string, ignoredPaths?: Set<string>): ScanResult[];
@@ -1,2 +1 @@
1
- export declare function scanDependencies(appRoot: string): Record<string, string>;
2
- //# sourceMappingURL=scanDependencies.d.ts.map
1
+ export declare function scanDependencies(appRoot: string): Record<string, string>;
@@ -1,5 +1,4 @@
1
1
  export declare function scanDomains(texts: Array<{
2
2
  file: string;
3
3
  text: string;
4
- }>): string[];
5
- //# sourceMappingURL=scanDomains.d.ts.map
4
+ }>): string[];
@@ -1,2 +1 @@
1
- export declare function scanEnvNames(appRoot: string): string[];
2
- //# sourceMappingURL=scanEnvNames.d.ts.map
1
+ export declare function scanEnvNames(appRoot: string): string[];
@@ -3,5 +3,4 @@ export interface ScanMetadataResult {
3
3
  description?: string;
4
4
  meta?: Record<string, string>;
5
5
  }
6
- export declare function scanMetadata(appRoot: string): ScanMetadataResult;
7
- //# sourceMappingURL=scanMetadata.d.ts.map
6
+ export declare function scanMetadata(appRoot: string): ScanMetadataResult;
@@ -1,2 +1 @@
1
- export declare function scanPages(appRoot: string): string[];
2
- //# sourceMappingURL=scanPages.d.ts.map
1
+ export declare function scanPages(appRoot: string): string[];
@@ -12,5 +12,4 @@ export declare function scanProject(appRoot: string): {
12
12
  i18nWords: string[];
13
13
  contentTexts: ScanResult[];
14
14
  endpoints: string[];
15
- };
16
- //# sourceMappingURL=scanProject.d.ts.map
15
+ };
@@ -1,2 +1 @@
1
- export declare function scanRoutes(appRoot: string): string[];
2
- //# sourceMappingURL=scanRoutes.d.ts.map
1
+ export declare function scanRoutes(appRoot: string): string[];
@@ -1,2 +1 @@
1
- export declare function scanTranslations(appRoot: string): string[];
2
- //# sourceMappingURL=scanTranslations.d.ts.map
1
+ export declare function scanTranslations(appRoot: string): string[];
@@ -11,5 +11,4 @@ export interface HalalCheckResult {
11
11
  explanation?: string;
12
12
  signature?: string;
13
13
  createdDate?: string;
14
- }
15
- //# sourceMappingURL=status.d.ts.map
14
+ }
@@ -1,2 +1 @@
1
- export declare function verifyCoreIntegrity(appRoot: string): boolean;
2
- //# sourceMappingURL=verifyCoreIntegrity.d.ts.map
1
+ export declare function verifyCoreIntegrity(appRoot: string): boolean;
@@ -1,2 +1 @@
1
- export declare function verifyLifecycleHooksRegistered(hooks: any): boolean;
2
- //# sourceMappingURL=verifyLifecycleHooks.d.ts.map
1
+ export declare function verifyLifecycleHooksRegistered(hooks: any): boolean;
@@ -2,5 +2,4 @@ import { ReportVerificationOptions } from "../report/verifyReport.js";
2
2
  export declare function checkOnDiskReportSignature(outDir: string, options?: ReportVerificationOptions): {
3
3
  valid: boolean;
4
4
  reason?: string;
5
- };
6
- //# sourceMappingURL=verifyReportSignature.d.ts.map
5
+ };
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Shared helpers for working with Resux head entries and Content
3
+ * Security Policy strings. Used by the runtime head renderer, the
4
+ * module container, and the compiler.
5
+ */
6
+ /**
7
+ * Deduplicate head script entries by their stable identity
8
+ * (key, then id, then src), keeping the latest occurrence in place.
9
+ */
10
+ export declare function dedupeHeadScripts(scripts: unknown[]): Array<Record<string, unknown>>;
11
+ /**
12
+ * Read the source list of the first matching CSP directive.
13
+ * Returns null when no matching directive is present.
14
+ */
15
+ export declare function cspDirectiveSources(csp: string, names: string[]): string[] | null;
@@ -0,0 +1,52 @@
1
+ // src/head/utils.ts
2
+ /**
3
+ * Shared helpers for working with Resux head entries and Content
4
+ * Security Policy strings. Used by the runtime head renderer, the
5
+ * module container, and the compiler.
6
+ */
7
+ /**
8
+ * Deduplicate head script entries by their stable identity
9
+ * (key, then id, then src), keeping the latest occurrence in place.
10
+ */
11
+ function dedupeHeadScripts(scripts) {
12
+ const map = /* @__PURE__ */ new Map();
13
+ const result = [];
14
+ for (const item of scripts) {
15
+ if (!item || typeof item !== "object") continue;
16
+ const script = item;
17
+ const dedupeKey = script.key ?? script.id ?? script.src;
18
+ if (dedupeKey) {
19
+ if (map.has(dedupeKey)) {
20
+ const existing = map.get(dedupeKey);
21
+ const idx = result.indexOf(existing);
22
+ if (idx !== -1) result[idx] = script;
23
+ map.set(dedupeKey, script);
24
+ } else {
25
+ map.set(dedupeKey, script);
26
+ result.push(script);
27
+ }
28
+ } else result.push(script);
29
+ }
30
+ return result;
31
+ }
32
+ /**
33
+ * Read the source list of the first matching CSP directive.
34
+ * Returns null when no matching directive is present.
35
+ */
36
+ function cspDirectiveSources(csp, names) {
37
+ if (!csp.trim()) return null;
38
+ const directives = /* @__PURE__ */ new Map();
39
+ for (const rawDirective of csp.split(";")) {
40
+ const tokens = rawDirective.trim().split(/\s+/).filter(Boolean);
41
+ if (!tokens.length) continue;
42
+ directives.set(tokens[0].toLowerCase(), tokens.slice(1));
43
+ }
44
+ for (const name of names) {
45
+ const sources = directives.get(name);
46
+ if (sources) return sources;
47
+ }
48
+ return null;
49
+ }
50
+ export { cspDirectiveSources, dedupeHeadScripts };
51
+
52
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","names":[],"sources":["../../src/head/utils.ts"],"sourcesContent":["/**\n * Shared helpers for working with Resux head entries and Content\n * Security Policy strings. Used by the runtime head renderer, the\n * module container, and the compiler.\n */\n\n/**\n * Deduplicate head script entries by their stable identity\n * (key, then id, then src), keeping the latest occurrence in place.\n */\nexport function dedupeHeadScripts(scripts: unknown[]): Array<Record<string, unknown>> {\n const map = new Map<string, Record<string, unknown>>();\n const result: Array<Record<string, unknown>> = [];\n for (const item of scripts) {\n if (!item || typeof item !== \"object\") continue;\n const script = item as Record<string, unknown>;\n const dedupeKey = (script.key as string) ?? (script.id as string) ?? (script.src as string);\n if (dedupeKey) {\n if (map.has(dedupeKey)) {\n const existing = map.get(dedupeKey)!;\n const idx = result.indexOf(existing);\n if (idx !== -1) {\n result[idx] = script;\n }\n map.set(dedupeKey, script);\n } else {\n map.set(dedupeKey, script);\n result.push(script);\n }\n } else {\n result.push(script);\n }\n }\n return result;\n}\n\n/**\n * Read the source list of the first matching CSP directive.\n * Returns null when no matching directive is present.\n */\nexport function cspDirectiveSources(csp: string, names: string[]): string[] | null {\n if (!csp.trim()) {\n return null;\n }\n const directives = new Map<string, string[]>();\n for (const rawDirective of csp.split(\";\")) {\n const tokens = rawDirective.trim().split(/\\s+/).filter(Boolean);\n if (!tokens.length) continue;\n directives.set(tokens[0].toLowerCase(), tokens.slice(1));\n }\n for (const name of names) {\n const sources = directives.get(name);\n if (sources) return sources;\n }\n return null;\n}\n"],"mappings":";;;;;;;;;;AAUA,SAAgB,kBAAkB,SAAoD;CACpF,MAAM,sBAAM,IAAI,IAAqC;CACrD,MAAM,SAAyC,CAAC;CAChD,KAAK,MAAM,QAAQ,SAAS;EAC1B,IAAI,CAAC,QAAQ,OAAO,SAAS,UAAU;EACvC,MAAM,SAAS;EACf,MAAM,YAAa,OAAO,OAAmB,OAAO,MAAkB,OAAO;EAC7E,IAAI,WAAW;GACb,IAAI,IAAI,IAAI,SAAS,GAAG;IACtB,MAAM,WAAW,IAAI,IAAI,SAAS;IAClC,MAAM,MAAM,OAAO,QAAQ,QAAQ;IACnC,IAAI,QAAQ,IACV,OAAO,OAAO;IAEhB,IAAI,IAAI,WAAW,MAAM;GAC3B,OAAO;IACL,IAAI,IAAI,WAAW,MAAM;IACzB,OAAO,KAAK,MAAM;GACpB;EACF,OACE,OAAO,KAAK,MAAM;CAEtB;CACA,OAAO;AACT;;;;;AAMA,SAAgB,oBAAoB,KAAa,OAAkC;CACjF,IAAI,CAAC,IAAI,KAAK,GACZ,OAAO;CAET,MAAM,6BAAa,IAAI,IAAsB;CAC7C,KAAK,MAAM,gBAAgB,IAAI,MAAM,GAAG,GAAG;EACzC,MAAM,SAAS,aAAa,KAAK,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,OAAO,OAAO;EAC9D,IAAI,CAAC,OAAO,QAAQ;EACpB,WAAW,IAAI,OAAO,EAAE,CAAC,YAAY,GAAG,OAAO,MAAM,CAAC,CAAC;CACzD;CACA,KAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,UAAU,WAAW,IAAI,IAAI;EACnC,IAAI,SAAS,OAAO;CACtB;CACA,OAAO;AACT"}
@@ -42,5 +42,4 @@ export declare function createI18nHeadEntry(routePath: string, routeOrigin?: str
42
42
  link: Array<Record<string, string>>;
43
43
  };
44
44
  declare const _default: ResuxModule<ResuxI18nModuleOptions>;
45
- export { _default as default };
46
- //# sourceMappingURL=index.d.ts.map
45
+ export { _default as default };
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/i18n/index.ts"],"sourcesContent":["import { readFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { fileURLToPath, pathToFileURL } from \"node:url\";\nimport {\n computed,\n ref,\n defineResuxModule,\n type ResuxModuleContext,\n type Ref,\n useResuxApp,\n type ResuxRouter,\n type RuntimeConfig\n} from \"../runtime/index.js\";\nimport {\n buildLocalePath,\n createI18nHead,\n normalizeI18nRuntimeConfig,\n normalizeI18nStrategy,\n resolveI18nRoute,\n resolveLocaleDirection,\n resolveLocalizedValue,\n translateRaw,\n translateText,\n type ResuxI18nLocale,\n type ResuxI18nRuntimeConfig,\n type ResuxI18nStrategy,\n type ResuxI18nTranslationParams\n} from \"./shared.js\";\n\ntype MessageRecord = Record<string, unknown>;\n\nexport interface ResuxI18nLocaleInput {\n code: string;\n name?: string;\n dir?: \"ltr\" | \"rtl\";\n}\n\nexport type ResuxI18nMessageSource =\n | MessageRecord\n | string\n | (() => unknown | Promise<unknown>);\n\nexport interface ResuxI18nConfigInput {\n defaultLocale: string;\n fallbackLocale?: string;\n strategy?: ResuxI18nStrategy;\n locales: ResuxI18nLocaleInput[];\n messages?: Record<string, ResuxI18nMessageSource>;\n seo?: {\n hreflang?: boolean;\n };\n}\n\nexport interface ResuxI18nModuleOptions extends Partial<ResuxI18nConfigInput> {}\n\nexport interface UseI18nResult {\n locale: ReturnType<typeof computed<string>>;\n dir: ReturnType<typeof computed<\"ltr\" | \"rtl\">>;\n locales: ResuxI18nLocale[];\n defaultLocale: string;\n fallbackLocale: string;\n strategy: ResuxI18nStrategy;\n t: (key: string, params?: ResuxI18nTranslationParams) => string;\n tm: (key: string) => unknown;\n resolveLocalized: (value: unknown) => string | null;\n localePath: (to: string, localeCode?: string) => string;\n switchLocalePath: (localeCode: string, to?: string) => string;\n setLocale: (localeCode: string, to?: string) => Promise<void> | void;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return Boolean(value && typeof value === \"object\" && !Array.isArray(value));\n}\n\nfunction readCurrentRoutePath(): string {\n if (typeof window !== \"undefined\" && typeof location !== \"undefined\") {\n return `${location.pathname}${location.search}${location.hash}`;\n }\n\n const app = useResuxApp();\n const currentRoute = app.route;\n if (currentRoute && typeof currentRoute.path === \"string\" && currentRoute.path.trim()) {\n return currentRoute.path;\n }\n\n return \"/\";\n}\n\nfunction readClientRouter(): ResuxRouter | null {\n const maybeRouter = (globalThis as { __RESUX_ROUTER__?: unknown }).__RESUX_ROUTER__;\n if (!isRecord(maybeRouter)) {\n return null;\n }\n const push = maybeRouter.push;\n const replace = maybeRouter.replace;\n const back = maybeRouter.back;\n const forward = maybeRouter.forward;\n const go = maybeRouter.go;\n if (\n typeof push !== \"function\"\n || typeof replace !== \"function\"\n || typeof back !== \"function\"\n || typeof forward !== \"function\"\n || typeof go !== \"function\"\n ) {\n return null;\n }\n return maybeRouter as unknown as ResuxRouter;\n}\n\nfunction extractDynamicImportPath(fn: () => unknown): string | null {\n const source = String(fn);\n const match = source.match(/import\\(([\"'`])(.+?)\\1\\)/);\n if (!match) {\n return null;\n }\n return match[2] ?? null;\n}\n\nfunction normalizeMessageModule(value: unknown): MessageRecord {\n if (isRecord(value) && isRecord(value.default)) {\n return value.default;\n }\n return isRecord(value) ? value : {};\n}\n\nasync function loadMessageFromPath(rootDir: string, filePath: string): Promise<MessageRecord> {\n let absolute = filePath;\n if (filePath.startsWith(\"file://\")) {\n try {\n absolute = fileURLToPath(filePath);\n } catch {\n absolute = filePath;\n }\n } else if (!path.isAbsolute(filePath)) {\n absolute = path.resolve(rootDir, filePath);\n }\n\n const cleanPath = absolute.split(\"?\")[0].split(\"#\")[0];\n if (cleanPath.toLowerCase().endsWith(\".json\")) {\n try {\n return JSON.parse(await readFile(cleanPath, \"utf8\")) as MessageRecord;\n } catch {\n return {};\n }\n }\n try {\n const imported = await import(filePath.startsWith(\"file://\") ? filePath : pathToFileURL(absolute).href);\n return normalizeMessageModule(imported.default ?? imported);\n } catch {\n return {};\n }\n}\n\nasync function resolveMessageSource(rootDir: string, source: ResuxI18nMessageSource | undefined): Promise<MessageRecord> {\n if (!source) {\n return {};\n }\n\n if (typeof source === \"string\") {\n return loadMessageFromPath(rootDir, source);\n }\n\n if (typeof source === \"function\") {\n const dynamicPath = extractDynamicImportPath(source);\n if (dynamicPath) {\n const absolute = path.isAbsolute(dynamicPath) ? dynamicPath : path.resolve(rootDir, dynamicPath);\n if (absolute.toLowerCase().endsWith(\".json\")) {\n return loadMessageFromPath(rootDir, absolute);\n }\n }\n try {\n const loaded = await source();\n return normalizeMessageModule(loaded);\n } catch {\n if (dynamicPath) {\n return loadMessageFromPath(rootDir, dynamicPath);\n }\n return {};\n }\n }\n\n return normalizeMessageModule(source);\n}\n\nasync function resolveMessages(\n rootDir: string,\n locales: ResuxI18nLocaleInput[],\n messages: Record<string, ResuxI18nMessageSource> | undefined\n): Promise<Record<string, MessageRecord>> {\n const resolved: Record<string, MessageRecord> = {};\n for (const locale of locales) {\n const code = String(locale.code || \"\").trim().toLowerCase();\n if (!code) {\n continue;\n }\n resolved[code] = await resolveMessageSource(rootDir, messages?.[code]);\n }\n return resolved;\n}\n\nasync function buildRuntimeI18nConfig(\n context: ResuxModuleContext,\n inlineOptions: ResuxI18nModuleOptions\n): Promise<ResuxI18nRuntimeConfig | null> {\n const configFromResux = isRecord(context.options.i18n) ? context.options.i18n : {};\n const inline = isRecord(inlineOptions) ? inlineOptions : {};\n const rawLocales = Array.isArray(inline.locales)\n ? inline.locales\n : Array.isArray(configFromResux.locales)\n ? configFromResux.locales\n : [];\n const mergedMessages = {\n ...(isRecord(configFromResux.messages) ? configFromResux.messages : {}),\n ...(isRecord(inline.messages) ? inline.messages : {})\n };\n const mergedSeo = {\n ...(isRecord(configFromResux.seo) ? configFromResux.seo : {}),\n ...(isRecord(inline.seo) ? inline.seo : {})\n };\n const merged = {\n ...configFromResux,\n ...inline,\n locales: rawLocales,\n messages: mergedMessages,\n seo: mergedSeo\n } as ResuxI18nConfigInput;\n\n if (!Array.isArray(merged.locales) || !merged.locales.length) {\n return null;\n }\n\n const locales: ResuxI18nLocaleInput[] = merged.locales\n .filter((locale) => isRecord(locale))\n .map((locale) => ({\n code: String(locale.code ?? \"\").trim().toLowerCase(),\n name: typeof locale.name === \"string\" ? locale.name : undefined,\n dir: locale.dir === \"rtl\" ? \"rtl\" as const : \"ltr\" as const\n }))\n .filter((locale) => locale.code.length > 0);\n\n if (!locales.length) {\n return null;\n }\n\n const firstLocale = locales[0].code;\n const rawConfig: Record<string, unknown> = {\n defaultLocale: typeof merged.defaultLocale === \"string\" ? merged.defaultLocale.toLowerCase() : firstLocale,\n fallbackLocale: typeof merged.fallbackLocale === \"string\" ? merged.fallbackLocale.toLowerCase() : undefined,\n strategy: normalizeI18nStrategy(merged.strategy),\n locales,\n messages: await resolveMessages(context.rootDir, locales, merged.messages),\n seo: {\n hreflang: !isRecord(merged.seo) || merged.seo.hreflang !== false\n }\n };\n\n return normalizeI18nRuntimeConfig(rawConfig);\n}\n\nfunction readRuntimeI18nConfig(): ResuxI18nRuntimeConfig | null {\n const runtimeConfig = useResuxApp().$config as RuntimeConfig;\n const publicConfig = isRecord(runtimeConfig.public) ? runtimeConfig.public : {};\n return normalizeI18nRuntimeConfig(publicConfig.i18n);\n}\n\nconst I18N_LOCALE_STATE_KEY = \"__resux_i18n_locale_state\";\n\nfunction resolveConfiguredLocale(config: ResuxI18nRuntimeConfig, localeCode: string): ResuxI18nLocale | null {\n const normalized = String(localeCode || \"\").trim().toLowerCase();\n return config.locales.find((locale) => locale.code === normalized) ?? null;\n}\n\nfunction useI18nLocaleState(config: ResuxI18nRuntimeConfig): Ref<string> {\n const app = useResuxApp();\n const existing = app.provides[I18N_LOCALE_STATE_KEY];\n if (isRecord(existing) && typeof existing.value === \"string\") {\n return existing as unknown as Ref<string>;\n }\n\n const initialLocale = resolveI18nRoute(readCurrentRoutePath(), config).locale.code;\n const state = ref(initialLocale);\n app.provide(I18N_LOCALE_STATE_KEY, state);\n return state;\n}\n\nfunction applyNoPrefixDocumentLocale(config: ResuxI18nRuntimeConfig, localeCode: string): void {\n if (typeof document === \"undefined\") {\n return;\n }\n const html = document.documentElement;\n if (!html) {\n return;\n }\n html.setAttribute(\"lang\", localeCode);\n html.setAttribute(\"dir\", resolveLocaleDirection(config, localeCode));\n}\n\nfunction fallbackI18nConfig(): ResuxI18nRuntimeConfig {\n return {\n defaultLocale: \"en\",\n fallbackLocale: \"en\",\n strategy: \"prefix_except_default\",\n locales: [{ code: \"en\", dir: \"ltr\", name: \"English\" }],\n messages: { en: {} }\n };\n}\n\nexport function useI18n(): UseI18nResult {\n const runtimeI18n = readRuntimeI18nConfig() ?? fallbackI18nConfig();\n const localeState = useI18nLocaleState(runtimeI18n);\n const locale = computed(() => runtimeI18n.strategy === \"no_prefix\"\n ? localeState.value\n : resolveI18nRoute(readCurrentRoutePath(), runtimeI18n).locale.code);\n const dir = computed(() => resolveLocaleDirection(runtimeI18n, locale.value));\n\n return {\n locale,\n dir,\n locales: runtimeI18n.locales,\n defaultLocale: runtimeI18n.defaultLocale,\n fallbackLocale: runtimeI18n.fallbackLocale,\n strategy: runtimeI18n.strategy,\n t(key: string, params: ResuxI18nTranslationParams = {}): string {\n return translateText(runtimeI18n, locale.value, key, params);\n },\n tm(key: string): unknown {\n return translateRaw(runtimeI18n, locale.value, key);\n },\n resolveLocalized(value: unknown): string | null {\n return resolveLocalizedValue(value, locale.value, runtimeI18n.fallbackLocale);\n },\n localePath(to: string, localeCode?: string): string {\n return buildLocalePath(to, localeCode ?? locale.value, runtimeI18n);\n },\n switchLocalePath(localeCode: string, to?: string): string {\n return buildLocalePath(to ?? readCurrentRoutePath(), localeCode, runtimeI18n);\n },\n setLocale(localeCode: string, to?: string): Promise<void> | void {\n const targetLocale = resolveConfiguredLocale(runtimeI18n, localeCode);\n if (!targetLocale) {\n return;\n }\n if (runtimeI18n.strategy === \"no_prefix\") {\n localeState.value = targetLocale.code;\n applyNoPrefixDocumentLocale(runtimeI18n, targetLocale.code);\n return;\n }\n\n const target = buildLocalePath(to ?? readCurrentRoutePath(), targetLocale.code, runtimeI18n);\n const router = readClientRouter();\n if (router) {\n return router.push(target);\n }\n if (typeof window !== \"undefined\" && typeof location !== \"undefined\") {\n location.assign(target);\n }\n }\n };\n}\n\nexport function useLocalePath(): (to: string, localeCode?: string) => string {\n const { localePath } = useI18n();\n return localePath;\n}\n\nexport function useSwitchLocalePath(): (localeCode: string, to?: string) => string {\n const { switchLocalePath } = useI18n();\n return switchLocalePath;\n}\n\nexport function defineI18nConfig<T extends ResuxI18nConfigInput>(config: T): T {\n return config;\n}\n\nexport function createI18nHeadEntry(routePath: string, routeOrigin?: string): { htmlAttrs: Record<string, string>; link: Array<Record<string, string>> } {\n const runtimeI18n = readRuntimeI18nConfig();\n if (!runtimeI18n) {\n return { htmlAttrs: { lang: \"en\", dir: \"ltr\" }, link: [] };\n }\n return createI18nHead(routePath, routeOrigin, runtimeI18n);\n}\n\nexport default defineResuxModule<ResuxI18nModuleOptions>({\n defaults: {\n strategy: \"prefix_except_default\"\n },\n async setup(options, context) {\n const runtimeI18n = await buildRuntimeI18nConfig(context, options ?? {});\n if (!runtimeI18n) {\n return;\n }\n\n const sourceI18n = isRecord((context.options as Record<string, unknown>).i18n)\n ? (context.options as Record<string, unknown>).i18n as Record<string, unknown>\n : {};\n const sourceSeo = isRecord(sourceI18n.seo) ? sourceI18n.seo : {};\n const inlineSeoSource = isRecord(options) ? options : {};\n const inlineSeo = isRecord(inlineSeoSource.seo) ? inlineSeoSource.seo : {};\n const hreflangEnabled = sourceSeo.hreflang !== false;\n const hreflangInline = inlineSeo.hreflang !== false;\n\n context.extendRuntimeConfig({\n public: {\n i18n: {\n ...runtimeI18n,\n seo: {\n hreflang: hreflangEnabled && hreflangInline\n }\n }\n }\n });\n\n // Under the \"prefix\" strategy every locale is prefixed, so the bare root\n // path has no matching page. Redirect it to the default locale instead of\n // 404ing.\n if (runtimeI18n.strategy === \"prefix\") {\n context.addRouteRule(\"/\", {\n redirect: { to: `/${runtimeI18n.defaultLocale}`, statusCode: 302 }\n });\n }\n }\n});\n\nif (typeof globalThis !== \"undefined\") {\n (globalThis as any).__RESUX_USE_I18N__ ??= useI18n;\n (globalThis as any).__RESUX_USE_LOCALE_PATH__ ??= useLocalePath;\n (globalThis as any).__RESUX_USE_SWITCH_LOCALE_PATH__ ??= useSwitchLocalePath;\n}\n"],"mappings":";;;;;;;;AAsEA,SAAS,SAAS,OAAkD;CAClE,OAAO,QAAQ,SAAS,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK,CAAC;AAC5E;AAEA,SAAS,uBAA+B;CACtC,IAAI,OAAO,WAAW,eAAe,OAAO,aAAa,aACvD,OAAO,GAAG,SAAS,WAAW,SAAS,SAAS,SAAS;CAI3D,MAAM,eADM,YACW,CAAC,CAAC;CACzB,IAAI,gBAAgB,OAAO,aAAa,SAAS,YAAY,aAAa,KAAK,KAAK,GAClF,OAAO,aAAa;CAGtB,OAAO;AACT;AAEA,SAAS,mBAAuC;CAC9C,MAAM,cAAe,WAA8C;CACnE,IAAI,CAAC,SAAS,WAAW,GACvB,OAAO;CAET,MAAM,OAAO,YAAY;CACzB,MAAM,UAAU,YAAY;CAC5B,MAAM,OAAO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,QAAQ,QAAoC,IAAI,IACxE,QAAQ,QAAoC,OAC7C,CAAC;EACL,MAAM,YAAY,SAAS,WAAW,GAAG,IAAI,WAAW,MAAM,CAAC;EAC/D,MAAM,kBAAkB,SAAS,OAAO,IAAI,UAAU,CAAC;EACvD,MAAM,YAAY,SAAS,gBAAgB,GAAG,IAAI,gBAAgB,MAAM,CAAC;EACzE,MAAM,kBAAkB,UAAU,aAAa;EAC/C,MAAM,iBAAiB,UAAU,aAAa;EAE9C,QAAQ,oBAAoB,EAC1B,QAAQ,EACN,MAAM;GACJ,GAAG;GACH,KAAK,EACH,UAAU,mBAAmB,eAC/B;EACF,EACF,EACF,CAAC;EAKD,IAAI,YAAY,aAAa,UAC3B,QAAQ,aAAa,KAAK,EACxB,UAAU;GAAE,IAAI,IAAI,YAAY;GAAiB,YAAY;EAAI,EACnE,CAAC;CAEL;AACF,CAAC;AAED,IAAI,OAAO,eAAe,aAAa;CACrC,WAAoB,uBAAuB;CAC3C,WAAoB,8BAA8B;CAClD,WAAoB,qCAAqC;AAC3D"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/i18n/index.ts"],"sourcesContent":["import { readFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { fileURLToPath, pathToFileURL } from \"node:url\";\nimport {\n computed,\n ref,\n defineResuxModule,\n type ResuxModuleContext,\n type Ref,\n useResuxApp,\n type ResuxRouter,\n type RuntimeConfig\n} from \"../runtime/index.js\";\nimport {\n buildLocalePath,\n createI18nHead,\n normalizeI18nRuntimeConfig,\n normalizeI18nStrategy,\n resolveI18nRoute,\n resolveLocaleDirection,\n resolveLocalizedValue,\n translateRaw,\n translateText,\n type ResuxI18nLocale,\n type ResuxI18nRuntimeConfig,\n type ResuxI18nStrategy,\n type ResuxI18nTranslationParams\n} from \"./shared.js\";\n\ntype MessageRecord = Record<string, unknown>;\n\nexport interface ResuxI18nLocaleInput {\n code: string;\n name?: string;\n dir?: \"ltr\" | \"rtl\";\n}\n\nexport type ResuxI18nMessageSource =\n | MessageRecord\n | string\n | (() => unknown | Promise<unknown>);\n\nexport interface ResuxI18nConfigInput {\n defaultLocale: string;\n fallbackLocale?: string;\n strategy?: ResuxI18nStrategy;\n locales: ResuxI18nLocaleInput[];\n messages?: Record<string, ResuxI18nMessageSource>;\n seo?: {\n hreflang?: boolean;\n };\n}\n\nexport interface ResuxI18nModuleOptions extends Partial<ResuxI18nConfigInput> {}\n\nexport interface UseI18nResult {\n locale: ReturnType<typeof computed<string>>;\n dir: ReturnType<typeof computed<\"ltr\" | \"rtl\">>;\n locales: ResuxI18nLocale[];\n defaultLocale: string;\n fallbackLocale: string;\n strategy: ResuxI18nStrategy;\n t: (key: string, params?: ResuxI18nTranslationParams) => string;\n tm: (key: string) => unknown;\n resolveLocalized: (value: unknown) => string | null;\n localePath: (to: string, localeCode?: string) => string;\n switchLocalePath: (localeCode: string, to?: string) => string;\n setLocale: (localeCode: string, to?: string) => Promise<void> | void;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return Boolean(value && typeof value === \"object\" && !Array.isArray(value));\n}\n\nfunction readCurrentRoutePath(): string {\n if (typeof window !== \"undefined\" && typeof location !== \"undefined\") {\n return `${location.pathname}${location.search}${location.hash}`;\n }\n\n const app = useResuxApp();\n const currentRoute = app.route;\n if (currentRoute && typeof currentRoute.path === \"string\" && currentRoute.path.trim()) {\n return currentRoute.path;\n }\n\n return \"/\";\n}\n\nfunction readClientRouter(): ResuxRouter | null {\n const maybeRouter = (globalThis as { __RESUX_ROUTER__?: unknown }).__RESUX_ROUTER__;\n if (!isRecord(maybeRouter)) {\n return null;\n }\n const push = maybeRouter.push;\n const replace = maybeRouter.replace;\n const back = maybeRouter.back;\n const forward = maybeRouter.forward;\n const go = maybeRouter.go;\n if (\n typeof push !== \"function\"\n || typeof replace !== \"function\"\n || typeof back !== \"function\"\n || typeof forward !== \"function\"\n || typeof go !== \"function\"\n ) {\n return null;\n }\n return maybeRouter as unknown as ResuxRouter;\n}\n\nfunction extractDynamicImportPath(fn: () => unknown): string | null {\n const source = String(fn);\n const match = source.match(/import\\(([\"'`])(.+?)\\1\\)/);\n if (!match) {\n return null;\n }\n return match[2] ?? null;\n}\n\nfunction normalizeMessageModule(value: unknown): MessageRecord {\n if (isRecord(value) && isRecord(value.default)) {\n return value.default;\n }\n return isRecord(value) ? value : {};\n}\n\nasync function loadMessageFromPath(rootDir: string, filePath: string): Promise<MessageRecord> {\n let absolute = filePath;\n if (filePath.startsWith(\"file://\")) {\n try {\n absolute = fileURLToPath(filePath);\n } catch {\n absolute = filePath;\n }\n } else if (!path.isAbsolute(filePath)) {\n absolute = path.resolve(rootDir, filePath);\n }\n\n const cleanPath = absolute.split(\"?\")[0].split(\"#\")[0];\n if (cleanPath.toLowerCase().endsWith(\".json\")) {\n try {\n return JSON.parse(await readFile(cleanPath, \"utf8\")) as MessageRecord;\n } catch {\n return {};\n }\n }\n try {\n const imported = await import(filePath.startsWith(\"file://\") ? filePath : pathToFileURL(absolute).href);\n return normalizeMessageModule(imported.default ?? imported);\n } catch {\n return {};\n }\n}\n\nasync function resolveMessageSource(rootDir: string, source: ResuxI18nMessageSource | undefined): Promise<MessageRecord> {\n if (!source) {\n return {};\n }\n\n if (typeof source === \"string\") {\n return loadMessageFromPath(rootDir, source);\n }\n\n if (typeof source === \"function\") {\n const dynamicPath = extractDynamicImportPath(source);\n if (dynamicPath) {\n const absolute = path.isAbsolute(dynamicPath) ? dynamicPath : path.resolve(rootDir, dynamicPath);\n if (absolute.toLowerCase().endsWith(\".json\")) {\n return loadMessageFromPath(rootDir, absolute);\n }\n }\n try {\n const loaded = await source();\n return normalizeMessageModule(loaded);\n } catch {\n if (dynamicPath) {\n return loadMessageFromPath(rootDir, dynamicPath);\n }\n return {};\n }\n }\n\n return normalizeMessageModule(source);\n}\n\nasync function resolveMessages(\n rootDir: string,\n locales: ResuxI18nLocaleInput[],\n messages: Record<string, ResuxI18nMessageSource> | undefined\n): Promise<Record<string, MessageRecord>> {\n const resolved: Record<string, MessageRecord> = {};\n for (const locale of locales) {\n const code = String(locale.code || \"\").trim().toLowerCase();\n if (!code) {\n continue;\n }\n resolved[code] = await resolveMessageSource(rootDir, messages?.[code]);\n }\n return resolved;\n}\n\nasync function buildRuntimeI18nConfig(\n context: ResuxModuleContext,\n inlineOptions: ResuxI18nModuleOptions\n): Promise<ResuxI18nRuntimeConfig | null> {\n const configFromResux = isRecord(context.options.i18n) ? context.options.i18n : {};\n const inline = isRecord(inlineOptions) ? inlineOptions : {};\n const rawLocales = Array.isArray(inline.locales)\n ? inline.locales\n : Array.isArray(configFromResux.locales)\n ? configFromResux.locales\n : [];\n const mergedMessages = {\n ...(isRecord(configFromResux.messages) ? configFromResux.messages : {}),\n ...(isRecord(inline.messages) ? inline.messages : {})\n };\n const mergedSeo = {\n ...(isRecord(configFromResux.seo) ? configFromResux.seo : {}),\n ...(isRecord(inline.seo) ? inline.seo : {})\n };\n const merged = {\n ...configFromResux,\n ...inline,\n locales: rawLocales,\n messages: mergedMessages,\n seo: mergedSeo\n } as ResuxI18nConfigInput;\n\n if (!Array.isArray(merged.locales) || !merged.locales.length) {\n return null;\n }\n\n const locales: ResuxI18nLocaleInput[] = merged.locales\n .filter((locale) => isRecord(locale))\n .map((locale) => ({\n code: String(locale.code ?? \"\").trim().toLowerCase(),\n name: typeof locale.name === \"string\" ? locale.name : undefined,\n dir: locale.dir === \"rtl\" ? \"rtl\" as const : \"ltr\" as const\n }))\n .filter((locale) => locale.code.length > 0);\n\n if (!locales.length) {\n return null;\n }\n\n const firstLocale = locales[0].code;\n const rawConfig: Record<string, unknown> = {\n defaultLocale: typeof merged.defaultLocale === \"string\" ? merged.defaultLocale.toLowerCase() : firstLocale,\n fallbackLocale: typeof merged.fallbackLocale === \"string\" ? merged.fallbackLocale.toLowerCase() : undefined,\n strategy: normalizeI18nStrategy(merged.strategy),\n locales,\n messages: await resolveMessages(context.rootDir, locales, merged.messages),\n seo: {\n hreflang: !isRecord(merged.seo) || merged.seo.hreflang !== false\n }\n };\n\n return normalizeI18nRuntimeConfig(rawConfig);\n}\n\nfunction readRuntimeI18nConfig(): ResuxI18nRuntimeConfig | null {\n const runtimeConfig = useResuxApp().$config as RuntimeConfig;\n const publicConfig = isRecord(runtimeConfig.public) ? runtimeConfig.public : {};\n return normalizeI18nRuntimeConfig(publicConfig.i18n);\n}\n\nconst I18N_LOCALE_STATE_KEY = \"__resux_i18n_locale_state\";\n\nfunction resolveConfiguredLocale(config: ResuxI18nRuntimeConfig, localeCode: string): ResuxI18nLocale | null {\n const normalized = String(localeCode || \"\").trim().toLowerCase();\n return config.locales.find((locale) => locale.code === normalized) ?? null;\n}\n\nfunction useI18nLocaleState(config: ResuxI18nRuntimeConfig): Ref<string> {\n const app = useResuxApp();\n const existing = app.provides[I18N_LOCALE_STATE_KEY];\n if (isRecord(existing) && typeof existing.value === \"string\") {\n return existing as unknown as Ref<string>;\n }\n\n const initialLocale = resolveI18nRoute(readCurrentRoutePath(), config).locale.code;\n const state = ref(initialLocale);\n app.provide(I18N_LOCALE_STATE_KEY, state);\n return state;\n}\n\nfunction applyNoPrefixDocumentLocale(config: ResuxI18nRuntimeConfig, localeCode: string): void {\n if (typeof document === \"undefined\") {\n return;\n }\n const html = document.documentElement;\n if (!html) {\n return;\n }\n html.setAttribute(\"lang\", localeCode);\n html.setAttribute(\"dir\", resolveLocaleDirection(config, localeCode));\n}\n\nfunction fallbackI18nConfig(): ResuxI18nRuntimeConfig {\n return {\n defaultLocale: \"en\",\n fallbackLocale: \"en\",\n strategy: \"prefix_except_default\",\n locales: [{ code: \"en\", dir: \"ltr\", name: \"English\" }],\n messages: { en: {} }\n };\n}\n\nexport function useI18n(): UseI18nResult {\n const runtimeI18n = readRuntimeI18nConfig() ?? fallbackI18nConfig();\n const localeState = useI18nLocaleState(runtimeI18n);\n const locale = computed(() => runtimeI18n.strategy === \"no_prefix\"\n ? localeState.value\n : resolveI18nRoute(readCurrentRoutePath(), runtimeI18n).locale.code);\n const dir = computed(() => resolveLocaleDirection(runtimeI18n, locale.value));\n\n return {\n locale,\n dir,\n locales: runtimeI18n.locales,\n defaultLocale: runtimeI18n.defaultLocale,\n fallbackLocale: runtimeI18n.fallbackLocale,\n strategy: runtimeI18n.strategy,\n t(key: string, params: ResuxI18nTranslationParams = {}): string {\n return translateText(runtimeI18n, locale.value, key, params);\n },\n tm(key: string): unknown {\n return translateRaw(runtimeI18n, locale.value, key);\n },\n resolveLocalized(value: unknown): string | null {\n return resolveLocalizedValue(value, locale.value, runtimeI18n.fallbackLocale);\n },\n localePath(to: string, localeCode?: string): string {\n return buildLocalePath(to, localeCode ?? locale.value, runtimeI18n);\n },\n switchLocalePath(localeCode: string, to?: string): string {\n return buildLocalePath(to ?? readCurrentRoutePath(), localeCode, runtimeI18n);\n },\n setLocale(localeCode: string, to?: string): Promise<void> | void {\n const targetLocale = resolveConfiguredLocale(runtimeI18n, localeCode);\n if (!targetLocale) {\n return;\n }\n if (runtimeI18n.strategy === \"no_prefix\") {\n localeState.value = targetLocale.code;\n applyNoPrefixDocumentLocale(runtimeI18n, targetLocale.code);\n return;\n }\n\n const target = buildLocalePath(to ?? readCurrentRoutePath(), targetLocale.code, runtimeI18n);\n const router = readClientRouter();\n if (router) {\n return router.push(target);\n }\n if (typeof window !== \"undefined\" && typeof location !== \"undefined\") {\n location.assign(target);\n }\n }\n };\n}\n\nexport function useLocalePath(): (to: string, localeCode?: string) => string {\n const { localePath } = useI18n();\n return localePath;\n}\n\nexport function useSwitchLocalePath(): (localeCode: string, to?: string) => string {\n const { switchLocalePath } = useI18n();\n return switchLocalePath;\n}\n\nexport function defineI18nConfig<T extends ResuxI18nConfigInput>(config: T): T {\n return config;\n}\n\nexport function createI18nHeadEntry(routePath: string, routeOrigin?: string): { htmlAttrs: Record<string, string>; link: Array<Record<string, string>> } {\n const runtimeI18n = readRuntimeI18nConfig();\n if (!runtimeI18n) {\n return { htmlAttrs: { lang: \"en\", dir: \"ltr\" }, link: [] };\n }\n return createI18nHead(routePath, routeOrigin, runtimeI18n);\n}\n\nexport default defineResuxModule<ResuxI18nModuleOptions>({\n defaults: {\n strategy: \"prefix_except_default\"\n },\n async setup(options, context) {\n const runtimeI18n = await buildRuntimeI18nConfig(context, options ?? {});\n if (!runtimeI18n) {\n return;\n }\n\n const sourceI18n = isRecord((context.options as Record<string, unknown>).i18n)\n ? (context.options as Record<string, unknown>).i18n as Record<string, unknown>\n : {};\n const sourceSeo = isRecord(sourceI18n.seo) ? sourceI18n.seo : {};\n const inlineSeoSource = isRecord(options) ? options : {};\n const inlineSeo = isRecord(inlineSeoSource.seo) ? inlineSeoSource.seo : {};\n const hreflangEnabled = sourceSeo.hreflang !== false;\n const hreflangInline = inlineSeo.hreflang !== false;\n\n context.extendRuntimeConfig({\n public: {\n i18n: {\n ...runtimeI18n,\n seo: {\n hreflang: hreflangEnabled && hreflangInline\n }\n }\n }\n });\n\n // Under the \"prefix\" strategy every locale is prefixed, so the bare root\n // path has no matching page. Redirect it to the default locale instead of\n // 404ing.\n if (runtimeI18n.strategy === \"prefix\") {\n context.addRouteRule(\"/\", {\n redirect: { to: `/${runtimeI18n.defaultLocale}`, statusCode: 302 }\n });\n }\n }\n});\n\nif (typeof globalThis !== \"undefined\") {\n (globalThis as any).__RESUX_USE_I18N__ ??= useI18n;\n (globalThis as any).__RESUX_USE_LOCALE_PATH__ ??= useLocalePath;\n (globalThis as any).__RESUX_USE_SWITCH_LOCALE_PATH__ ??= useSwitchLocalePath;\n}\n"],"mappings":";;;;;;;;AAsEA,SAAS,SAAS,OAAkD;CAClE,OAAO,QAAQ,SAAS,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK,CAAC;AAC5E;AAEA,SAAS,uBAA+B;CACtC,IAAI,OAAO,WAAW,eAAe,OAAO,aAAa,aACvD,OAAO,GAAG,SAAS,WAAW,SAAS,SAAS,SAAS;CAI3D,MAAM,eADM,YACW,CAAC,CAAC;CACzB,IAAI,gBAAgB,OAAO,aAAa,SAAS,YAAY,a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AAa,WAAW;AAC3D;AAEA,IAAA,eAAe,kBAA0C;CACvD,UAAU,EACR,UAAU,wBACZ;CACA,MAAM,MAAM,SAAS,SAAS;EAC5B,MAAM,cAAc,MAAM,uBAAuB,SAAS,WAAW,CAAC,CAAC;EACvE,IAAI,CAAC,aACH;EAGF,MAAM,aAAa,SAAU,QAAQ,QAAoC,IAAI,IACxE,QAAQ,QAAoC,OAC7C,CAAC;EACL,MAAM,YAAY,SAAS,WAAW,GAAG,IAAI,WAAW,MAAM,CAAC;EAC/D,MAAM,kBAAkB,SAAS,OAAO,IAAI,UAAU,CAAC;EACvD,MAAM,YAAY,SAAS,gBAAgB,GAAG,IAAI,gBAAgB,MAAM,CAAC;EACzE,MAAM,kBAAkB,UAAU,aAAa;EAC/C,MAAM,iBAAiB,UAAU,aAAa;EAE9C,QAAQ,oBAAoB,EAC1B,QAAQ,EACN,MAAM;GACJ,GAAG;GACH,KAAK,EACH,UAAU,mBAAmB,eAC/B;EACF,EACF,EACF,CAAC;EAKD,IAAI,YAAY,aAAa,UAC3B,QAAQ,aAAa,KAAK,EACxB,UAAU;GAAE,IAAI,IAAI,YAAY;GAAiB,YAAY;EAAI,EACnE,CAAC;CAEL;AACF,CAAC;AAED,IAAI,OAAO,eAAe,aAAa;CACpC,WAAmB,uBAAuB;CAC1C,WAAmB,8BAA8B;CACjD,WAAmB,qCAAqC;AAC3D"}
@@ -32,5 +32,4 @@ export declare function createI18nHead(routePath: string, routeOrigin: string |
32
32
  }): {
33
33
  htmlAttrs: Record<string, string>;
34
34
  link: Array<Record<string, string>>;
35
- };
36
- //# sourceMappingURL=shared.d.ts.map
35
+ };
@@ -1,4 +1,3 @@
1
1
  import { IconCacheManager } from "./cache.js";
2
2
  import { IconData } from "./types.js";
3
- export declare function fetchIconifyIcon(rawName: string, apiProvider?: string, cache?: IconCacheManager): Promise<IconData | null>;
4
- //# sourceMappingURL=api-fetcher.d.ts.map
3
+ export declare function fetchIconifyIcon(rawName: string, apiProvider?: string, cache?: IconCacheManager): Promise<IconData | null>;
@@ -18,5 +18,4 @@ export declare class IconCacheManager {
18
18
  deletePending(key: string): void;
19
19
  runWithSlot<T>(task: () => Promise<T>): Promise<T | null>;
20
20
  }
21
- export declare const defaultIconCache: IconCacheManager;
22
- //# sourceMappingURL=cache.d.ts.map
21
+ export declare const defaultIconCache: IconCacheManager;
@@ -1 +1 @@
1
- {"version":3,"file":"cache.js","names":[],"sources":["../../src/icons/cache.ts"],"sourcesContent":["import {\n ICON_FETCH_CACHE_MAX_ENTRIES,\n ICON_FETCH_MAX_IN_FLIGHT,\n ICON_FETCH_QUEUE_MAX_ENTRIES,\n} from \"./constants.js\";\nimport type { IconData } from \"./types.js\";\n\nexport interface IconCacheOptions {\n maxEntries?: number;\n maxInFlight?: number;\n maxQueue?: number;\n}\n\nexport class IconCacheManager {\n readonly #maxEntries: number;\n readonly #maxInFlight: number;\n readonly #maxQueue: number;\n\n readonly #dataCache = new Map<string, IconData>();\n readonly #pendingFetches = new Map<string, Promise<IconData | null>>();\n readonly #queue: Array<() => void> = [];\n #activeCount = 0;\n\n constructor(options: IconCacheOptions = {}) {\n this.#maxEntries = options.maxEntries ?? ICON_FETCH_CACHE_MAX_ENTRIES;\n this.#maxInFlight = options.maxInFlight ?? ICON_FETCH_MAX_IN_FLIGHT;\n this.#maxQueue = options.maxQueue ?? ICON_FETCH_QUEUE_MAX_ENTRIES;\n }\n\n get size(): number {\n return this.#dataCache.size;\n }\n\n get(key: string): IconData | undefined {\n const value = this.#dataCache.get(key);\n if (!value) return undefined;\n // Refresh LRU order\n this.#dataCache.delete(key);\n this.#dataCache.set(key, value);\n return value;\n }\n\n set(key: string, data: IconData): void {\n this.#dataCache.delete(key);\n this.#dataCache.set(key, data);\n while (this.#dataCache.size > this.#maxEntries) {\n const oldestKey = this.#dataCache.keys().next().value;\n if (oldestKey === undefined) break;\n this.#dataCache.delete(oldestKey);\n }\n }\n\n has(key: string): boolean {\n return this.#dataCache.has(key);\n }\n\n delete(key: string): boolean {\n return this.#dataCache.delete(key);\n }\n\n clear(): void {\n this.#dataCache.clear();\n this.#pendingFetches.clear();\n this.#queue.length = 0;\n this.#activeCount = 0;\n }\n\n getPending(key: string): Promise<IconData | null> | undefined {\n return this.#pendingFetches.get(key);\n }\n\n setPending(key: string, promise: Promise<IconData | null>): void {\n this.#pendingFetches.set(key, promise);\n }\n\n deletePending(key: string): void {\n this.#pendingFetches.delete(key);\n }\n\n runWithSlot<T>(task: () => Promise<T>): Promise<T | null> {\n if (this.#activeCount >= this.#maxInFlight && this.#queue.length >= this.#maxQueue) {\n return Promise.resolve(null);\n }\n\n return new Promise((resolve) => {\n const execute = () => {\n this.#activeCount += 1;\n void task()\n .then(resolve, () => resolve(null))\n .finally(() => {\n this.#activeCount = Math.max(0, this.#activeCount - 1);\n this.#queue.shift()?.();\n });\n };\n\n if (this.#activeCount < this.#maxInFlight) {\n execute();\n } else {\n this.#queue.push(execute);\n }\n });\n }\n}\n\nexport const defaultIconCache = new IconCacheManager();\n"],"mappings":";;AAaA,IAAa,mBAAb,MAA8B;CAC5B;CACA;CACA;CAEA,6BAAsB,IAAI,IAAsB;CAChD,kCAA2B,IAAI,IAAsC;CACrE,SAAqC,CAAC;CACtC,eAAe;CAEf,YAAY,UAA4B,CAAC,GAAG;EAC1C,KAAK,cAAc,QAAQ,cAAA;EAC3B,KAAK,eAAe,QAAQ,eAAA;EAC5B,KAAK,YAAY,QAAQ,YAAA;CAC3B;CAEA,IAAI,OAAe;EACjB,OAAO,KAAK,WAAW;CACzB;CAEA,IAAI,KAAmC;EACrC,MAAM,QAAQ,KAAK,WAAW,IAAI,GAAG;EACrC,IAAI,CAAC,OAAO,OAAO,KAAA;EAEnB,KAAK,WAAW,OAAO,GAAG;EAC1B,KAAK,WAAW,IAAI,KAAK,KAAK;EAC9B,OAAO;CACT;CAEA,IAAI,KAAa,MAAsB;EACrC,KAAK,WAAW,OAAO,GAAG;EAC1B,KAAK,WAAW,IAAI,KAAK,IAAI;EAC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IGHT,\n ICON_FETCH_QUEUE_MAX_ENTRIES,\n} from \"./constants.js\";\nimport type { IconData } from \"./types.js\";\n\nexport interface IconCacheOptions {\n maxEntries?: number;\n maxInFlight?: number;\n maxQueue?: number;\n}\n\nexport class IconCacheManager {\n readonly #maxEntries: number;\n readonly #maxInFlight: number;\n readonly #maxQueue: number;\n\n readonly #dataCache = new Map<string, IconData>();\n readonly #pendingFetches = new Map<string, Promise<IconData | null>>();\n readonly #queue: Array<() => void> = [];\n #activeCount = 0;\n\n constructor(options: IconCacheOptions = {}) {\n this.#maxEntries = options.maxEntries ?? ICON_FETCH_CACHE_MAX_ENTRIES;\n this.#maxInFlight = options.maxInFlight ?? ICON_FETCH_MAX_IN_FLIGHT;\n this.#maxQueue = options.maxQueue ?? ICON_FETCH_QUEUE_MAX_ENTRIES;\n }\n\n get size(): number {\n return this.#dataCache.size;\n }\n\n get(key: string): IconData | undefined {\n const value = this.#dataCache.get(key);\n if (!value) return undefined;\n // Refresh LRU order\n this.#dataCache.delete(key);\n this.#dataCache.set(key, value);\n return value;\n }\n\n set(key: string, data: IconData): void {\n this.#dataCache.delete(key);\n this.#dataCache.set(key, data);\n while (this.#dataCache.size > this.#maxEntries) {\n const oldestKey = this.#dataCache.keys().next().value;\n if (oldestKey === undefined) break;\n this.#dataCache.delete(oldestKey);\n }\n }\n\n has(key: string): boolean {\n return this.#dataCache.has(key);\n }\n\n delete(key: string): boolean {\n return this.#dataCache.delete(key);\n }\n\n clear(): void {\n this.#dataCache.clear();\n this.#pendingFetches.clear();\n this.#queue.length = 0;\n this.#activeCount = 0;\n }\n\n getPending(key: string): Promise<IconData | null> | undefined {\n return this.#pendingFetches.get(key);\n }\n\n setPending(key: string, promise: Promise<IconData | null>): void {\n this.#pendingFetches.set(key, promise);\n }\n\n deletePending(key: string): void {\n this.#pendingFetches.delete(key);\n }\n\n runWithSlot<T>(task: () => Promise<T>): Promise<T | null> {\n if (this.#activeCount >= this.#maxInFlight && this.#queue.length >= this.#maxQueue) {\n return Promise.resolve(null);\n }\n\n return new Promise((resolve) => {\n const execute = () => {\n this.#activeCount += 1;\n void task()\n .then(resolve, () => resolve(null))\n .finally(() => {\n this.#activeCount = Math.max(0, this.#activeCount - 1);\n this.#queue.shift()?.();\n });\n };\n\n if (this.#activeCount < this.#maxInFlight) {\n execute();\n } else {\n this.#queue.push(execute);\n }\n });\n }\n}\n\nexport const defaultIconCache = new IconCacheManager();\n"],"mappings":";;AAaA,IAAa,mBAAb,MAA8B;CACnB;CACA;CACA;CAEA,6BAAa,IAAI,IAAsB;CACvC,kCAAkB,IAAI,IAAsC;CAC5D,SAA4B,CAAC;CACtC,eAAe;CAEf,YAAY,UAA4B,CAAC,GAAG;EAC1C,KAAK,cAAc,QAAQ,cAAA;EAC3B,KAAK,eAAe,QAAQ,eAAA;EAC5B,KAAK,YAAY,QAAQ,YAAA;CAC3B;CAEA,IAAI,OAAe;EACjB,OAAO,KAAK,WAAW;CACzB;CAEA,IAAI,KAAmC;EACrC,MAAM,QAAQ,KAAK,WAAW,IAAI,GAAG;EACrC,IAAI,CAAC,OAAO,OAAO,KAAA;EAEnB,KAAK,WAAW,OAAO,GAAG;EAC1B,KAAK,WAAW,IAAI,KAAK,KAAK;EAC9B,OAAO;CACT;CAEA,IAAI,KAAa,MAAsB;EACrC,KAAK,WAAW,OAAO,GAAG;EAC1B,KAAK,WAAW,IAAI,KAAK,IAAI;EAC7B,OAAO,KAAK,WAAW,OAAO,KAAK,aAAa;GAC9C,MAAM,YAAY,KAAK,WAAW,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC;GAChD,IAAI,cAAc,KAAA,GAAW;GAC7B,KAAK,WAAW,OAAO,SAAS;EAClC;CACF;CAEA,IAAI,KAAsB;EACxB,OAAO,KAAK,WAAW,IAAI,GAAG;CAChC;CAEA,OAAO,KAAsB;EAC3B,OAAO,KAAK,WAAW,OAAO,GAAG;CACnC;CAEA,QAAc;EACZ,KAAK,WAAW,MAAM;EACtB,KAAK,gBAAg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