@usefragments/core 2.0.0 → 2.0.1

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.
package/dist/index.d.ts CHANGED
@@ -1053,6 +1053,8 @@ interface UsageComponentFact extends BaseFact {
1053
1053
  kind: "usage_component";
1054
1054
  nodeId: FactId;
1055
1055
  componentId: ComponentId;
1056
+ /** Exact local definition resolved from source, separate from catalog/policy identity. */
1057
+ definitionKey?: string;
1056
1058
  }
1057
1059
  interface UsageImportFact extends BaseFact {
1058
1060
  kind: "usage_import";
@@ -1342,6 +1344,8 @@ interface ComponentDefinitionFact extends BaseFact {
1342
1344
  componentKey: string;
1343
1345
  renderRoot: ComponentDefinitionRenderRoot;
1344
1346
  propSurface: string[];
1347
+ /** Implementation region, used to scope exemptions; never part of fact identity. */
1348
+ location?: FactLocation;
1345
1349
  stylingChannel?: {
1346
1350
  module: string;
1347
1351
  ownsVisualRole: boolean;
@@ -1846,6 +1850,7 @@ declare function makeComponentDefinitionFact(input: {
1846
1850
  componentKey: string;
1847
1851
  renderRoot: ComponentDefinitionFact["renderRoot"];
1848
1852
  propSurface: string[];
1853
+ location?: FactLocation;
1849
1854
  stylingChannel?: ComponentDefinitionFact["stylingChannel"];
1850
1855
  }): ComponentDefinitionFact;
1851
1856
  declare function makeComponentIdentityFact(input: {
@@ -2014,6 +2019,7 @@ declare function makeUsageNodeFact(input: {
2014
2019
  declare function makeUsageComponentFact(input: {
2015
2020
  nodeId: FactId;
2016
2021
  componentId: ComponentId;
2022
+ definitionKey?: string;
2017
2023
  }): UsageComponentFact;
2018
2024
  declare function makeUsageImportFact(input: {
2019
2025
  file: string;
@@ -12745,6 +12751,12 @@ interface ComponentIdentityUsage {
12745
12751
  /** Join resolved component usages to their usage nodes once for rules and DX surfaces. */
12746
12752
  declare function indexComponentIdentityUsage(ix: FactIndex): ReadonlyMap<string, ComponentIdentityUsage>;
12747
12753
 
12754
+ /** Export filters narrow source ownership; an empty include approves nothing. */
12755
+ declare function canonicalSourceIncludesExport(source: CanonicalSource, name: string): boolean;
12756
+ /** Filesystem ownership only. Package import specifiers are not local paths. */
12757
+ declare function canonicalSourceContainsFile(source: CanonicalSource, file: string): boolean;
12758
+ declare function isCanonicalSourceDefinition(file: string, exportName: string, sources: readonly CanonicalSource[]): boolean;
12759
+
12748
12760
  /**
12749
12761
  * Rule helpers — small internal queries shared by Phase 5 rules.
12750
12762
  *
@@ -14530,4 +14542,4 @@ declare const APPROVED_CONTRACT_TOKEN_MAX_NAME_LENGTH = 512;
14530
14542
  /** Empty is authored absence; missing is unavailable authority. */
14531
14543
  declare function isApprovedContractTokenNames(value: unknown): value is string[];
14532
14544
 
14533
- export { type A11yNameRequiredFact, AGENT_CONTEXT_RELATIVE_PATH, ANALYSIS_LIMIT_CEILINGS_V1, ANALYSIS_PLAN_MAX_CAPABILITIES_V1, ANALYSIS_PLAN_MAX_DIALECTS_PER_REGION_V1, ANALYSIS_PLAN_MAX_REGIONS_V1, APPROVED_CONTRACT_TOKEN_MAX_NAMES, APPROVED_CONTRACT_TOKEN_MAX_NAME_LENGTH, AgentFormat, type AnalysisLimitsV1, type AnalysisPlanId, type AnalysisPlanInputV1, type AnalysisPlanV1, type AnalysisRegionV1, BLOCKING_RULE_ALLOWLIST, BRAND, BlockDefinition, type Brand, type BuildAgentFormatInput, type BuildRegistryInstallPlanInput, type BundleArtifactMetadata, type BundleComponentShard, type BundleManifest, type BundleManifestComponentEntry, type BundleSchemaVersion, type BundleTarget, type BundleTokenFile, CANONICAL_FACT_MAX_CONFLICTS_V1, CANONICAL_FACT_MAX_PROVENANCE_PER_VALUE_V1, CANONICAL_FACT_MAX_VALUES_PER_CONFLICT_V1, CATALOG_FIXTURE_A_FCID, type CSSGeneratorOptions, type CanonicalBridgeIdentityBinding, CanonicalBridgeV1, type CanonicalCandidateFact, type CanonicalDirectionConflict, type CanonicalFactConflictV1, type CanonicalFactConflictValueV1, type CanonicalFactIntegrityV1, Finding as CanonicalFinding, type CanonicalIdentityReference, type CanonicalMappingFact, type CanonicalReplacementFact, CanonicalSource, type CheckedSpacingValue, type ClassNameDynamicFact, type ClassNameDynamicReason, type ClassNameFact, type ClassNameLiteralFact, type ClassNameOrigin, type ClassifyIdentityInput, type CompileEffectiveGovernanceInputsOptions, CompiledBlock, type CompiledContractOutput, CompiledFragment, type ComplexityTier, type ComponentCapabilityFact, type ComponentContract, type ComponentDefinitionFact, type ComponentDefinitionRenderRoot, type ComponentFactInput, type ComponentId, type ComponentIdentityFact, type ComponentIdentityUsage, type ComponentKeyInput, type ComponentLevelFact, type ComponentMetadataFact, type CompositionAnalysis, type CompositionAuthoringEntry, type CompositionChildSelector, type CompositionConstraint, type CompositionGuideline, type CompositionPattern, type CompositionRegionSelector, type CompositionSuggestion, type CompositionWarning, type ConformChange, type ConformComponentMapping, type ConformConfidence, type ConformCoverage, type ConformInput, type ConformLocation, type ConformPropMapping, type ConformResult, type ConformSuggestion, type ConformToken, type ConformUnresolved, ContractCanonicalMappingInput, ContractCatalogInput, ContractDomain, ContractPreimage, type ContractStampPin, type ContractStampRecord, type ContractTokenReferenceCensus, type CoverageRegionV1, type CoverageStateV1, type CoverageSummaryV1, CoverageValidationErrorV1, DEFAULTS, DEFAULT_ENHANCED_STYLE_PROPERTIES, DEFAULT_STYLE_PROPERTIES, type DTCGColorValue, type DTCGDimensionValue, type DTCGGroup, type DTCGToken, type DTCGTokenFile, type DTCGTokenType, type Defaults, type DeltaEMatch, type DesignSystemContext, type DesignToken, type DesignTokenParseOptions, type DigestHex, type DiscoverComponentsOptions, EFFECTIVE_GOVERNANCE_INPUTS_SCHEMA, EMPTY_VOCABULARY_MESSAGE, EVALUATION_MAX_FINDINGS_V2, EVALUATION_MAX_MAP_ENTRIES_V2, EVALUATION_MAX_POLICY_RULES_V2, EVALUATION_MAX_REASON_CODES_V2, EVALUATION_MAX_WAIVERS_V2, EVALUATION_MAX_WAIVER_MATCHES_V2, EVALUATION_RECEIPT_STRING_MAX_BYTES_V1, EVALUATOR_VERSION, EVALUATOR_VERSION_V2, type EffectiveEvaluationWaiverV2, type EffectiveGovernanceInputs, type EffectiveGovernanceInputsSourceState, type EffectivePolicy, type EffectiveRulePolicy, type EnhancedStyleComparisonResult, type EnhancedStyleDiffItem, type EvaluatedFinding, type EvaluationAuthorityV1, type EvaluationBaseline, type EvaluationContractInput, type EvaluationEvidence, type EvaluationEvidenceTrustV1, type EvaluationFindingInput, type EvaluationFindingState, type EvaluationInput, type EvaluationInputV2, type EvaluationIntegrityInput, type EvaluationIntegrityInputV2, type EvaluationMappingTrust, type EvaluationReason, type EvaluationReasonV2, type EvaluationReceiptId, type EvaluationReceiptMintInputV1, type EvaluationReceiptSemanticV1, type EvaluationReceiptV1, type EvaluationResult, type EvaluationResultV2, type EvaluationScope, type EvaluationSourceTrust, type EvaluationTrust, type EvaluationVerdict, type EvaluationWaiver, EvidenceGrade, type ExternalIdentityReference, FRAGMENTS_INTERNAL_RULE_IDS, FRAGMENT_V3_SCHEMA_URL, type Fact, type FactConflict, type FactEvidence, type FactId, FactIndex, type FactKind, type FactLocation, type FactOfKind, FigmaBooleanMapping, FigmaChildrenMapping, FigmaEnumMapping, FigmaInstanceMapping, FigmaStringMapping, FigmaTextContentMapping, type FigmaVariable, type FigmaVariableCollection, Finding, FindingFix, type FindingV2, FragmentAnnotationsV3, FragmentComponent, FragmentDefinition, FragmentDefinitionV2, FragmentDefinitionV3, FragmentDefinitionV3Body, FragmentDesignV3, FragmentDontExampleV3, FragmentGuidanceV3, FragmentMatrixV3, FragmentMetaV3, FragmentPreviewV3, FragmentStateV3, FragmentsConfig, Severity as FuiSeverity, GovernanceConfig, type GovernanceIntegrityFamily, type GovernanceIntegrityFamilyId, type GovernanceIntegrityInput, type GovernanceIntegrityRoster, type GovernanceIntegrityStatus, type GovernanceIntegrityVerdict, GovernanceSeverity, GovernedFragmentDefinition, type IdentityClassification, type IdentityConfidence, type IdentityDecision, type IdentityFact, type IdentityState, type InertConfigDiagnostic, type InertConfigDiagnosticCode, type InertConfigDiagnosticKind, type InferProps, type JsxComponentPreferredFact, type JsxImportPathPreferredFact, type JsxInlineStyleForbiddenRawFact, type JsxUnknownPropsForbiddenFact, type LocalIdentityReference, type McpBlock, type McpCapability, type McpComponent, type McpComponentExample, type McpComponentGuidance, type McpComponentMetadata, type McpComponentProp, type McpComponentRelation, type McpCompoundChild, type McpGuidancePattern, type McpPerformanceData, type McpPerformanceImport, type McpPerformanceSummary, type McpSnapshot, type McpSnapshotMetadata, type McpSnapshotSchemaVersion, type McpSourceType, type McpToken, type McpTokenData, type NearestByDeltaEOptions, type NormalizedStyleMap, type NormalizedToken, PRESET_NAMES, PROVE_DEFAULT_MAX_PASSES, PROVE_MAX_PASSES, PROVIDER_ID_MAX_BYTES_V1, type ParseTokensOptions, type ParsedToken, type PerformanceData as PerfData, type PerformanceSummary as PerfSummary, type PerformanceBudgets, type PerformanceConfig, type PolicyExclude, type PolicyExcludeInput, type PolicyFact, type PresetRuleState, PropAnnotation, type PropMetadataFact, type PropValueAvoidedFact, type PropValueForbiddenFact, type ProveCallbacks, type ProveLoopResult, type ProveOptions, type ProvePass, type ProvePassSampling, type ProveResidual, type ProveSample, type ProveSamplerArgs, type ProveVerdict, type ProviderProofSemanticV1, type ProviderProofV1, RAW_HTML_ADVISORY_TAGS, RAW_HTML_CANONICAL_TAGS, RAW_HTML_INPUT_TYPE_CANONICALS, RAW_HTML_ROLE_CANONICALS, REPOSITORY_BINDING_ID_MAX_BYTES_V1, type RGB, type RGBA, RULES, RULE_FAMILY_IDS, RULE_FAMILY_MEMBERS, RULE_TIER, type RawHtmlCanonicalMatch, type RawHtmlPrecisionTier, RegistryArtifact, RegistryDependency, RegistryFile, type RegistryInstallPlan, RegistryInstallReceipt, type RegistryInstallSelection, type RegistryInstallSelectionInput, type RegistryInstallSourceFile, type RegistryInstallSources, type RegistryInstallSourcesInput, RegistryManifest, type RegistryWritePlan, RelationshipType, type RepositoryBindingKeyV1, type RepositoryBindingKeyV1Input, type ResolvedDTCGToken, ResolvedGovernedFragmentDefinition, type ResolvedIdentityRenderRoot, type ResolvedIntrinsicIdentityRoot, type Rule, type RuleConfigView, type RuleFn, type RuleTier, type SCSSGeneratorOptions, type ScaleFact, type ScaleValueFact, Severity, type SpacingResolutionScale, type SpacingTokenLookup, type StructuralConfidenceFact, type StyleComparisonOptions, type StyleComparisonResult, type StyleCssVarsMustBeDefinedFact, type StyleDeclarationFact, type StyleDiffItem, type StyleFontSizeScaleFact, type StylePropertyScaleFact, type StyleRawColorForbiddenFact, type StyleUnsupportedFact, type StyleValueProvenance, type SupersededImportPathPreference, type SuppressionDirectiveFact, type TailwindClassFact, type TailwindModifier, type TailwindModifierKind, type TailwindPaletteAllowFact, type TailwindPaletteDenyFact, type TailwindResolutionSource, type TailwindResolvedKind, type TailwindResolvedValue, type TailwindTokenResolvedFact, type TailwindUnknownClassEnabledFact, type TailwindValue, type ThemeDeclarationFact, type ThemeParserResult, type TokenCatalog, type TokenCatalogDefinition, type TokenCatalogDiagnostic, type TokenCatalogLocation, type TokenCatalogReference, type TokenCatalogSourceState, type TokenCategory, TokenConfig, type TokenDefinitionFact, type TokenFix, type TokenFormat, type TokenLookup, type TokenMatchRequest, type TokenMatchResult, type TokenParseError, type TokenParseOutput, type TokenParseResult, type TokenRegistry, type TokenRegistryMeta, type TokenUsageSummary, type UnsupportedStyleReason, type UsageChildContentFact, type UsageComponentFact, type UsageFact, type UsageImportFact, type UsageInlineStyleFact, type UsageNodeFact, type UsagePropResolvedFact, type UsageTextChildFact, aiMetadataSchema, analysisLimitsV1Schema, analysisObligationsDigestV1, analysisPlanDigestV1, analysisPlanIdFromDigest, analysisPlanIdSchema, analysisPlanIdStringSchema, analysisPlanInputV1Schema, analysisPlanV1Schema, analysisRegionV1Schema, analyzeComposition, artifactContentHash, asComponentId, assertPortableRegistryPath, blockDefinitionSchema, budgetBar, buildAgentFormat, buildAnalysisPlanV1, buildComponentKey, buildRegistryInstallPlan, buildRegistryInstallReceipt, buildSpacingTokenLookup, bundleArtifactMetadataSchema, bundleComponentShardSchema, bundleManifestComponentEntrySchema, bundleManifestSchema, bundleSchemaVersionSchema, bundleTargetSchema, bundleTokenFileSchema, calculateDeltaE, canonicalBridgeContractMappings, canonicalBridgeIdentityBindings, canonicalBridgeIdentitySources, canonicalDirectionConflictsTarget, canonicalFactConflictV1Schema, canonicalFactConflictValueV1Schema, canonicalFactIntegrityV1Schema, canonicalJson, canonicalPreimage, capConfiguredSeverity, catalogFixtureA, catalogFixtureAContractPayload, catalogFixtureATokensDtcg, clampMaxPasses, classifyComplexity, classifyIdentity, collectRegistryInstallDependencies, collidingRecordDiagnostic, collidingRecordDiagnostics, colorSimilarity, compareByVocabularyRank, compareColors, compareNumericValues, compareStyleValue, compareStyles, compareStylesWithTokens, compileBlock, compileComponentFacts, compileEffectiveGovernanceInputs, compileFragment, compileGlobalGovernanceFacts, componentContractSchema, componentId, componentRelationSchema, compositionAuthoringEntrySchema, compositionMetadataSchema, compositionPatternSchema, configDeclarationForDiagnostics, configRecordShape, configuredFindingSeverity, containsTailwindV4Theme, contractHash, contractTierRuleIds, contractTokenReferenceCensus, coverageArtifactDigestV1, coverageRegionV1Schema, coverageStateV1Schema, coverageSummaryV1Schema, customerDefaultRuleStates, defineBlock, defineConfig, defineFragment, deriveCoverageSummaryV1, describePolicyExclude, detectOrphanGovernanceScales, detectUnconsumedConfigKeys, detectUnmatchedPolicyExcludes, digestHexSchema, digestHexStringSchema, discoverComponents, dtcgTokenFileSchema, effectiveEvaluationWaiverV2Schema, emptyConformResult, emptyVocabularyConfigFile, evaluate, evaluateGovernanceIntegrity, evaluationInputDigestV2, evaluationInputV2Schema, evaluationReceiptDigestV1, evaluationReceiptIdFromDigest, evaluationReceiptIdSchema, evaluationReceiptIdStringSchema, evaluationReceiptMintInputV1Schema, evaluationReceiptV1Schema, evaluationResultDigestV2, evaluationResultV2Schema, excludeGlobToRegExp, expandRegistryComponentClosure, factId, familyDistance, figma, figmaPropMappingSchema, formatBytes, formatStampHeader, formatStampPin, formatStampVersionHash, formatTokenSummary, fragmentAnnotationsV3Schema, fragmentBanSchema, fragmentContractSchema, fragmentDefinitionSchema, fragmentDefinitionV2Schema, fragmentDefinitionV3BodySchema, fragmentDefinitionV3Schema, fragmentDesignV3Schema, fragmentDontExampleV3Schema, fragmentGeneratedSchema, fragmentGuidanceV3Schema, fragmentMatrixV3Schema, fragmentMetaSchema, fragmentMetaV3Schema, fragmentPreviewV3Schema, fragmentProvenanceSchema, fragmentSourceValues, fragmentStateV3Schema, fragmentUsageSchema, fragmentVariantSchema, fragmentsConfigSchema, fragmentsPresetRuleStates, gatesCi, generateCSSCustomProperties, generateFigmaVariables, generateSCSSVariables, generateTailwindConfig, getComplianceBadge, governedFragmentDefinitionSchema, hasEffectiveComponentVocabulary, hash64Hex, hexToRgb, hygieneTierRuleIds, indexComponentIdentityUsage, inferTokenCategory, inferTokenGroup, isApprovedContractTokenNames, isColorLike, isCompositionPattern, isContractFile, isContractTierRule, isDTCGFile, isDenyEligible, isEffectiveCanonicalSource, isEnforceableHtmlEquivalent, isFigmaPropMapping, isPortableRepoPath, isRawHtmlAdvisoryTier, isReactComponent, isRuleFamilyId, lowerCompositionContract, makeA11yNameRequiredFact, makeCanonicalCandidateFact, makeCanonicalMappingFact, makeCanonicalReplacementFact, makeClassNameDynamicFact, makeClassNameLiteralFact, makeComponentCapabilityFact, makeComponentDefinitionFact, makeComponentIdentityFact, makeComponentMetadataFact, makeContractTokenFact, makeFinding, makeJsxComponentPreferredFact, makeJsxImportPathPreferredFact, makeJsxInlineStyleForbiddenRawFact, makeJsxUnknownPropsForbiddenFact, makePropMetadataFact, makePropValueAvoidedFact, makePropValueForbiddenFact, makeScaleFact, makeScaleValueFact, makeStructuralConfidenceFact, makeStyleCssVarsMustBeDefinedFact, makeStyleDeclarationFact, makeStyleFontSizeScaleFact, makeStylePropertyScaleFact, makeStyleRawColorForbiddenFact, makeStyleUnsupportedFact, makeTailwindClassFact, makeTailwindPaletteAllowFact, makeTailwindPaletteDenyFact, makeTailwindTokenResolvedFact, makeTailwindUnknownClassEnabledFact, makeThemeDeclarationFact, makeTokenDefinitionFact, makeUsageChildContentFact, makeUsageComponentFact, makeUsageImportFact, makeUsageInlineStyleFact, makeUsageNodeFact, makeUsagePropResolvedFact, makeUsageTextChildFact, matchPolicyExclude, matchesGlob, mcpBlockSchema, mcpCapabilitySchema, mcpComponentExampleSchema, mcpComponentGuidanceSchema, mcpComponentMetadataSchema, mcpComponentPropSchema, mcpComponentRelationSchema, mcpComponentSchema, mcpCompoundChildSchema, mcpGuidancePatternSchema, mcpPerformanceDataSchema, mcpPerformanceImportSchema, mcpPerformanceSummarySchema, mcpSnapshotMetadataSchema, mcpSnapshotSchema, mcpSnapshotSchemaVersionSchema, mcpSourceTypeSchema, mcpTokenDataSchema, mcpTokenSchema, mintEvaluationReceiptId, nearestByDeltaE, nearestSignedScaleValue, normalizeAnalysisPlanInputV1, normalizeCanonicalFactIntegrityV1, normalizeColor, normalizeConfigPath, normalizeExcludePath, normalizePolicyExcludes, normalizeRegistryRepoPath, normalizeRepositoryBindingKeyV1, normalizeStyleValue, normalizeToV1, normalizeTokenGroupComment, normalizeTokenValue, overriddenRecordSeverityDiagnostic, parseAnalysisPlanId, parseAnalysisPlanV1, parseColor, parseColorToRgb, parseComponentContract, parseContractStamp, parseCssTokens, parseDtcgTokens as parseDTCGFile, parseDesignTokenContent, parseDigestHex, parseDtcgTokens, parseEvaluationReceiptId, parseEvaluationReceiptV1, parseRgb, parseScssTokens, parseScssVariables, parseTailwindV4Theme, parseTokenFile, parseTokens, policyExcludeMatchesPath, policyExcludeSchema, portableRepoPathError, projectCanonicalDirectionConflicts, projectSupersededImportPathPreferences, propAnnotationSchema, propDefinitionSchema, proveCompliant, proveIssueCount, providerProofDigestV1, providerProofV1Schema, readRuleConfig, repositoryBindingDigestV1, repositoryBindingKeyV1Schema, resolveCanonicalForAriaRole, resolveCanonicalForRawHtml, resolveConfiguredAppPath, resolveDesignTokenValue, resolveFigmaMapping, resolvePerformanceConfig, resolveProveVerdict, resolveRegistryComponentId, resolveRegistryInstallSelection, resolveRegistryInstallSources, resolveSpacingValue, resolveTokenValue, rgbToHex, ruleA11yRequiredAccessibleName, ruleA11yStandard, ruleComponentsForbiddenPropValue, ruleComponentsPreferLibrary, ruleComponentsShadowComponent, ruleComponentsUnknownProp, ruleFamilyMembers, ruleJsxPreferredComponent, ruleJsxPreferredImportPath, rulePropsInvalidValue, ruleStylesNoRawColor, ruleStylesNoRawDimensions, ruleStylesNoRawSpacing, ruleStylesNoRawTypography, ruleTailwindArbitraryColor, ruleTailwindArbitrarySpacing, ruleTailwindForbiddenPalette, ruleTailwindOffScaleSpacingToken, ruleTailwindRawColorViaToken, ruleTailwindUnknownClass, ruleThemeNoThemeCoupledLiteral, ruleTokensRequireDualFallback, runRules, serializeContractStamp, sha256Hex, sourceToRegistryTargetPath, tierFor, tokenIncludesFromConfig, topologyBase, vocabularyRank };
14545
+ export { type A11yNameRequiredFact, AGENT_CONTEXT_RELATIVE_PATH, ANALYSIS_LIMIT_CEILINGS_V1, ANALYSIS_PLAN_MAX_CAPABILITIES_V1, ANALYSIS_PLAN_MAX_DIALECTS_PER_REGION_V1, ANALYSIS_PLAN_MAX_REGIONS_V1, APPROVED_CONTRACT_TOKEN_MAX_NAMES, APPROVED_CONTRACT_TOKEN_MAX_NAME_LENGTH, AgentFormat, type AnalysisLimitsV1, type AnalysisPlanId, type AnalysisPlanInputV1, type AnalysisPlanV1, type AnalysisRegionV1, BLOCKING_RULE_ALLOWLIST, BRAND, BlockDefinition, type Brand, type BuildAgentFormatInput, type BuildRegistryInstallPlanInput, type BundleArtifactMetadata, type BundleComponentShard, type BundleManifest, type BundleManifestComponentEntry, type BundleSchemaVersion, type BundleTarget, type BundleTokenFile, CANONICAL_FACT_MAX_CONFLICTS_V1, CANONICAL_FACT_MAX_PROVENANCE_PER_VALUE_V1, CANONICAL_FACT_MAX_VALUES_PER_CONFLICT_V1, CATALOG_FIXTURE_A_FCID, type CSSGeneratorOptions, type CanonicalBridgeIdentityBinding, CanonicalBridgeV1, type CanonicalCandidateFact, type CanonicalDirectionConflict, type CanonicalFactConflictV1, type CanonicalFactConflictValueV1, type CanonicalFactIntegrityV1, Finding as CanonicalFinding, type CanonicalIdentityReference, type CanonicalMappingFact, type CanonicalReplacementFact, CanonicalSource, type CheckedSpacingValue, type ClassNameDynamicFact, type ClassNameDynamicReason, type ClassNameFact, type ClassNameLiteralFact, type ClassNameOrigin, type ClassifyIdentityInput, type CompileEffectiveGovernanceInputsOptions, CompiledBlock, type CompiledContractOutput, CompiledFragment, type ComplexityTier, type ComponentCapabilityFact, type ComponentContract, type ComponentDefinitionFact, type ComponentDefinitionRenderRoot, type ComponentFactInput, type ComponentId, type ComponentIdentityFact, type ComponentIdentityUsage, type ComponentKeyInput, type ComponentLevelFact, type ComponentMetadataFact, type CompositionAnalysis, type CompositionAuthoringEntry, type CompositionChildSelector, type CompositionConstraint, type CompositionGuideline, type CompositionPattern, type CompositionRegionSelector, type CompositionSuggestion, type CompositionWarning, type ConformChange, type ConformComponentMapping, type ConformConfidence, type ConformCoverage, type ConformInput, type ConformLocation, type ConformPropMapping, type ConformResult, type ConformSuggestion, type ConformToken, type ConformUnresolved, ContractCanonicalMappingInput, ContractCatalogInput, ContractDomain, ContractPreimage, type ContractStampPin, type ContractStampRecord, type ContractTokenReferenceCensus, type CoverageRegionV1, type CoverageStateV1, type CoverageSummaryV1, CoverageValidationErrorV1, DEFAULTS, DEFAULT_ENHANCED_STYLE_PROPERTIES, DEFAULT_STYLE_PROPERTIES, type DTCGColorValue, type DTCGDimensionValue, type DTCGGroup, type DTCGToken, type DTCGTokenFile, type DTCGTokenType, type Defaults, type DeltaEMatch, type DesignSystemContext, type DesignToken, type DesignTokenParseOptions, type DigestHex, type DiscoverComponentsOptions, EFFECTIVE_GOVERNANCE_INPUTS_SCHEMA, EMPTY_VOCABULARY_MESSAGE, EVALUATION_MAX_FINDINGS_V2, EVALUATION_MAX_MAP_ENTRIES_V2, EVALUATION_MAX_POLICY_RULES_V2, EVALUATION_MAX_REASON_CODES_V2, EVALUATION_MAX_WAIVERS_V2, EVALUATION_MAX_WAIVER_MATCHES_V2, EVALUATION_RECEIPT_STRING_MAX_BYTES_V1, EVALUATOR_VERSION, EVALUATOR_VERSION_V2, type EffectiveEvaluationWaiverV2, type EffectiveGovernanceInputs, type EffectiveGovernanceInputsSourceState, type EffectivePolicy, type EffectiveRulePolicy, type EnhancedStyleComparisonResult, type EnhancedStyleDiffItem, type EvaluatedFinding, type EvaluationAuthorityV1, type EvaluationBaseline, type EvaluationContractInput, type EvaluationEvidence, type EvaluationEvidenceTrustV1, type EvaluationFindingInput, type EvaluationFindingState, type EvaluationInput, type EvaluationInputV2, type EvaluationIntegrityInput, type EvaluationIntegrityInputV2, type EvaluationMappingTrust, type EvaluationReason, type EvaluationReasonV2, type EvaluationReceiptId, type EvaluationReceiptMintInputV1, type EvaluationReceiptSemanticV1, type EvaluationReceiptV1, type EvaluationResult, type EvaluationResultV2, type EvaluationScope, type EvaluationSourceTrust, type EvaluationTrust, type EvaluationVerdict, type EvaluationWaiver, EvidenceGrade, type ExternalIdentityReference, FRAGMENTS_INTERNAL_RULE_IDS, FRAGMENT_V3_SCHEMA_URL, type Fact, type FactConflict, type FactEvidence, type FactId, FactIndex, type FactKind, type FactLocation, type FactOfKind, FigmaBooleanMapping, FigmaChildrenMapping, FigmaEnumMapping, FigmaInstanceMapping, FigmaStringMapping, FigmaTextContentMapping, type FigmaVariable, type FigmaVariableCollection, Finding, FindingFix, type FindingV2, FragmentAnnotationsV3, FragmentComponent, FragmentDefinition, FragmentDefinitionV2, FragmentDefinitionV3, FragmentDefinitionV3Body, FragmentDesignV3, FragmentDontExampleV3, FragmentGuidanceV3, FragmentMatrixV3, FragmentMetaV3, FragmentPreviewV3, FragmentStateV3, FragmentsConfig, Severity as FuiSeverity, GovernanceConfig, type GovernanceIntegrityFamily, type GovernanceIntegrityFamilyId, type GovernanceIntegrityInput, type GovernanceIntegrityRoster, type GovernanceIntegrityStatus, type GovernanceIntegrityVerdict, GovernanceSeverity, GovernedFragmentDefinition, type IdentityClassification, type IdentityConfidence, type IdentityDecision, type IdentityFact, type IdentityState, type InertConfigDiagnostic, type InertConfigDiagnosticCode, type InertConfigDiagnosticKind, type InferProps, type JsxComponentPreferredFact, type JsxImportPathPreferredFact, type JsxInlineStyleForbiddenRawFact, type JsxUnknownPropsForbiddenFact, type LocalIdentityReference, type McpBlock, type McpCapability, type McpComponent, type McpComponentExample, type McpComponentGuidance, type McpComponentMetadata, type McpComponentProp, type McpComponentRelation, type McpCompoundChild, type McpGuidancePattern, type McpPerformanceData, type McpPerformanceImport, type McpPerformanceSummary, type McpSnapshot, type McpSnapshotMetadata, type McpSnapshotSchemaVersion, type McpSourceType, type McpToken, type McpTokenData, type NearestByDeltaEOptions, type NormalizedStyleMap, type NormalizedToken, PRESET_NAMES, PROVE_DEFAULT_MAX_PASSES, PROVE_MAX_PASSES, PROVIDER_ID_MAX_BYTES_V1, type ParseTokensOptions, type ParsedToken, type PerformanceData as PerfData, type PerformanceSummary as PerfSummary, type PerformanceBudgets, type PerformanceConfig, type PolicyExclude, type PolicyExcludeInput, type PolicyFact, type PresetRuleState, PropAnnotation, type PropMetadataFact, type PropValueAvoidedFact, type PropValueForbiddenFact, type ProveCallbacks, type ProveLoopResult, type ProveOptions, type ProvePass, type ProvePassSampling, type ProveResidual, type ProveSample, type ProveSamplerArgs, type ProveVerdict, type ProviderProofSemanticV1, type ProviderProofV1, RAW_HTML_ADVISORY_TAGS, RAW_HTML_CANONICAL_TAGS, RAW_HTML_INPUT_TYPE_CANONICALS, RAW_HTML_ROLE_CANONICALS, REPOSITORY_BINDING_ID_MAX_BYTES_V1, type RGB, type RGBA, RULES, RULE_FAMILY_IDS, RULE_FAMILY_MEMBERS, RULE_TIER, type RawHtmlCanonicalMatch, type RawHtmlPrecisionTier, RegistryArtifact, RegistryDependency, RegistryFile, type RegistryInstallPlan, RegistryInstallReceipt, type RegistryInstallSelection, type RegistryInstallSelectionInput, type RegistryInstallSourceFile, type RegistryInstallSources, type RegistryInstallSourcesInput, RegistryManifest, type RegistryWritePlan, RelationshipType, type RepositoryBindingKeyV1, type RepositoryBindingKeyV1Input, type ResolvedDTCGToken, ResolvedGovernedFragmentDefinition, type ResolvedIdentityRenderRoot, type ResolvedIntrinsicIdentityRoot, type Rule, type RuleConfigView, type RuleFn, type RuleTier, type SCSSGeneratorOptions, type ScaleFact, type ScaleValueFact, Severity, type SpacingResolutionScale, type SpacingTokenLookup, type StructuralConfidenceFact, type StyleComparisonOptions, type StyleComparisonResult, type StyleCssVarsMustBeDefinedFact, type StyleDeclarationFact, type StyleDiffItem, type StyleFontSizeScaleFact, type StylePropertyScaleFact, type StyleRawColorForbiddenFact, type StyleUnsupportedFact, type StyleValueProvenance, type SupersededImportPathPreference, type SuppressionDirectiveFact, type TailwindClassFact, type TailwindModifier, type TailwindModifierKind, type TailwindPaletteAllowFact, type TailwindPaletteDenyFact, type TailwindResolutionSource, type TailwindResolvedKind, type TailwindResolvedValue, type TailwindTokenResolvedFact, type TailwindUnknownClassEnabledFact, type TailwindValue, type ThemeDeclarationFact, type ThemeParserResult, type TokenCatalog, type TokenCatalogDefinition, type TokenCatalogDiagnostic, type TokenCatalogLocation, type TokenCatalogReference, type TokenCatalogSourceState, type TokenCategory, TokenConfig, type TokenDefinitionFact, type TokenFix, type TokenFormat, type TokenLookup, type TokenMatchRequest, type TokenMatchResult, type TokenParseError, type TokenParseOutput, type TokenParseResult, type TokenRegistry, type TokenRegistryMeta, type TokenUsageSummary, type UnsupportedStyleReason, type UsageChildContentFact, type UsageComponentFact, type UsageFact, type UsageImportFact, type UsageInlineStyleFact, type UsageNodeFact, type UsagePropResolvedFact, type UsageTextChildFact, aiMetadataSchema, analysisLimitsV1Schema, analysisObligationsDigestV1, analysisPlanDigestV1, analysisPlanIdFromDigest, analysisPlanIdSchema, analysisPlanIdStringSchema, analysisPlanInputV1Schema, analysisPlanV1Schema, analysisRegionV1Schema, analyzeComposition, artifactContentHash, asComponentId, assertPortableRegistryPath, blockDefinitionSchema, budgetBar, buildAgentFormat, buildAnalysisPlanV1, buildComponentKey, buildRegistryInstallPlan, buildRegistryInstallReceipt, buildSpacingTokenLookup, bundleArtifactMetadataSchema, bundleComponentShardSchema, bundleManifestComponentEntrySchema, bundleManifestSchema, bundleSchemaVersionSchema, bundleTargetSchema, bundleTokenFileSchema, calculateDeltaE, canonicalBridgeContractMappings, canonicalBridgeIdentityBindings, canonicalBridgeIdentitySources, canonicalDirectionConflictsTarget, canonicalFactConflictV1Schema, canonicalFactConflictValueV1Schema, canonicalFactIntegrityV1Schema, canonicalJson, canonicalPreimage, canonicalSourceContainsFile, canonicalSourceIncludesExport, capConfiguredSeverity, catalogFixtureA, catalogFixtureAContractPayload, catalogFixtureATokensDtcg, clampMaxPasses, classifyComplexity, classifyIdentity, collectRegistryInstallDependencies, collidingRecordDiagnostic, collidingRecordDiagnostics, colorSimilarity, compareByVocabularyRank, compareColors, compareNumericValues, compareStyleValue, compareStyles, compareStylesWithTokens, compileBlock, compileComponentFacts, compileEffectiveGovernanceInputs, compileFragment, compileGlobalGovernanceFacts, componentContractSchema, componentId, componentRelationSchema, compositionAuthoringEntrySchema, compositionMetadataSchema, compositionPatternSchema, configDeclarationForDiagnostics, configRecordShape, configuredFindingSeverity, containsTailwindV4Theme, contractHash, contractTierRuleIds, contractTokenReferenceCensus, coverageArtifactDigestV1, coverageRegionV1Schema, coverageStateV1Schema, coverageSummaryV1Schema, customerDefaultRuleStates, defineBlock, defineConfig, defineFragment, deriveCoverageSummaryV1, describePolicyExclude, detectOrphanGovernanceScales, detectUnconsumedConfigKeys, detectUnmatchedPolicyExcludes, digestHexSchema, digestHexStringSchema, discoverComponents, dtcgTokenFileSchema, effectiveEvaluationWaiverV2Schema, emptyConformResult, emptyVocabularyConfigFile, evaluate, evaluateGovernanceIntegrity, evaluationInputDigestV2, evaluationInputV2Schema, evaluationReceiptDigestV1, evaluationReceiptIdFromDigest, evaluationReceiptIdSchema, evaluationReceiptIdStringSchema, evaluationReceiptMintInputV1Schema, evaluationReceiptV1Schema, evaluationResultDigestV2, evaluationResultV2Schema, excludeGlobToRegExp, expandRegistryComponentClosure, factId, familyDistance, figma, figmaPropMappingSchema, formatBytes, formatStampHeader, formatStampPin, formatStampVersionHash, formatTokenSummary, fragmentAnnotationsV3Schema, fragmentBanSchema, fragmentContractSchema, fragmentDefinitionSchema, fragmentDefinitionV2Schema, fragmentDefinitionV3BodySchema, fragmentDefinitionV3Schema, fragmentDesignV3Schema, fragmentDontExampleV3Schema, fragmentGeneratedSchema, fragmentGuidanceV3Schema, fragmentMatrixV3Schema, fragmentMetaSchema, fragmentMetaV3Schema, fragmentPreviewV3Schema, fragmentProvenanceSchema, fragmentSourceValues, fragmentStateV3Schema, fragmentUsageSchema, fragmentVariantSchema, fragmentsConfigSchema, fragmentsPresetRuleStates, gatesCi, generateCSSCustomProperties, generateFigmaVariables, generateSCSSVariables, generateTailwindConfig, getComplianceBadge, governedFragmentDefinitionSchema, hasEffectiveComponentVocabulary, hash64Hex, hexToRgb, hygieneTierRuleIds, indexComponentIdentityUsage, inferTokenCategory, inferTokenGroup, isApprovedContractTokenNames, isCanonicalSourceDefinition, isColorLike, isCompositionPattern, isContractFile, isContractTierRule, isDTCGFile, isDenyEligible, isEffectiveCanonicalSource, isEnforceableHtmlEquivalent, isFigmaPropMapping, isPortableRepoPath, isRawHtmlAdvisoryTier, isReactComponent, isRuleFamilyId, lowerCompositionContract, makeA11yNameRequiredFact, makeCanonicalCandidateFact, makeCanonicalMappingFact, makeCanonicalReplacementFact, makeClassNameDynamicFact, makeClassNameLiteralFact, makeComponentCapabilityFact, makeComponentDefinitionFact, makeComponentIdentityFact, makeComponentMetadataFact, makeContractTokenFact, makeFinding, makeJsxComponentPreferredFact, makeJsxImportPathPreferredFact, makeJsxInlineStyleForbiddenRawFact, makeJsxUnknownPropsForbiddenFact, makePropMetadataFact, makePropValueAvoidedFact, makePropValueForbiddenFact, makeScaleFact, makeScaleValueFact, makeStructuralConfidenceFact, makeStyleCssVarsMustBeDefinedFact, makeStyleDeclarationFact, makeStyleFontSizeScaleFact, makeStylePropertyScaleFact, makeStyleRawColorForbiddenFact, makeStyleUnsupportedFact, makeTailwindClassFact, makeTailwindPaletteAllowFact, makeTailwindPaletteDenyFact, makeTailwindTokenResolvedFact, makeTailwindUnknownClassEnabledFact, makeThemeDeclarationFact, makeTokenDefinitionFact, makeUsageChildContentFact, makeUsageComponentFact, makeUsageImportFact, makeUsageInlineStyleFact, makeUsageNodeFact, makeUsagePropResolvedFact, makeUsageTextChildFact, matchPolicyExclude, matchesGlob, mcpBlockSchema, mcpCapabilitySchema, mcpComponentExampleSchema, mcpComponentGuidanceSchema, mcpComponentMetadataSchema, mcpComponentPropSchema, mcpComponentRelationSchema, mcpComponentSchema, mcpCompoundChildSchema, mcpGuidancePatternSchema, mcpPerformanceDataSchema, mcpPerformanceImportSchema, mcpPerformanceSummarySchema, mcpSnapshotMetadataSchema, mcpSnapshotSchema, mcpSnapshotSchemaVersionSchema, mcpSourceTypeSchema, mcpTokenDataSchema, mcpTokenSchema, mintEvaluationReceiptId, nearestByDeltaE, nearestSignedScaleValue, normalizeAnalysisPlanInputV1, normalizeCanonicalFactIntegrityV1, normalizeColor, normalizeConfigPath, normalizeExcludePath, normalizePolicyExcludes, normalizeRegistryRepoPath, normalizeRepositoryBindingKeyV1, normalizeStyleValue, normalizeToV1, normalizeTokenGroupComment, normalizeTokenValue, overriddenRecordSeverityDiagnostic, parseAnalysisPlanId, parseAnalysisPlanV1, parseColor, parseColorToRgb, parseComponentContract, parseContractStamp, parseCssTokens, parseDtcgTokens as parseDTCGFile, parseDesignTokenContent, parseDigestHex, parseDtcgTokens, parseEvaluationReceiptId, parseEvaluationReceiptV1, parseRgb, parseScssTokens, parseScssVariables, parseTailwindV4Theme, parseTokenFile, parseTokens, policyExcludeMatchesPath, policyExcludeSchema, portableRepoPathError, projectCanonicalDirectionConflicts, projectSupersededImportPathPreferences, propAnnotationSchema, propDefinitionSchema, proveCompliant, proveIssueCount, providerProofDigestV1, providerProofV1Schema, readRuleConfig, repositoryBindingDigestV1, repositoryBindingKeyV1Schema, resolveCanonicalForAriaRole, resolveCanonicalForRawHtml, resolveConfiguredAppPath, resolveDesignTokenValue, resolveFigmaMapping, resolvePerformanceConfig, resolveProveVerdict, resolveRegistryComponentId, resolveRegistryInstallSelection, resolveRegistryInstallSources, resolveSpacingValue, resolveTokenValue, rgbToHex, ruleA11yRequiredAccessibleName, ruleA11yStandard, ruleComponentsForbiddenPropValue, ruleComponentsPreferLibrary, ruleComponentsShadowComponent, ruleComponentsUnknownProp, ruleFamilyMembers, ruleJsxPreferredComponent, ruleJsxPreferredImportPath, rulePropsInvalidValue, ruleStylesNoRawColor, ruleStylesNoRawDimensions, ruleStylesNoRawSpacing, ruleStylesNoRawTypography, ruleTailwindArbitraryColor, ruleTailwindArbitrarySpacing, ruleTailwindForbiddenPalette, ruleTailwindOffScaleSpacingToken, ruleTailwindRawColorViaToken, ruleTailwindUnknownClass, ruleThemeNoThemeCoupledLiteral, ruleTokensRequireDualFallback, runRules, serializeContractStamp, sha256Hex, sourceToRegistryTargetPath, tierFor, tokenIncludesFromConfig, topologyBase, vocabularyRank };
package/dist/index.js CHANGED
@@ -201,7 +201,7 @@ import {
201
201
  suppressionDirectiveSchema,
202
202
  validatorResultSchema,
203
203
  violationSchema
204
- } from "./chunk-BMPYIUZE.js";
204
+ } from "./chunk-QPOKQ5H6.js";
205
205
  import {
206
206
  isPortableRepoPath,
207
207
  normalizeConfigPath,
@@ -5260,6 +5260,56 @@ function isEnforceableHtmlEquivalent(args) {
5260
5260
  return builtIn !== null && builtIn.canonical === args.canonical;
5261
5261
  }
5262
5262
 
5263
+ // src/identity/usage.ts
5264
+ function indexComponentIdentityUsage(ix) {
5265
+ const nodesById = new Map(ix.byKind("usage_node").map((node) => [node.id, node]));
5266
+ const definitions = new Set(
5267
+ ix.byKind("component_definition").map((definition) => definition.componentKey)
5268
+ );
5269
+ const nodesByComponent = /* @__PURE__ */ new Map();
5270
+ for (const usage of ix.byKind("usage_component")) {
5271
+ const node = nodesById.get(usage.nodeId);
5272
+ if (!node) continue;
5273
+ const componentKey = usage.definitionKey && definitions.has(usage.definitionKey) ? usage.definitionKey : String(usage.componentId);
5274
+ const nodes = nodesByComponent.get(componentKey) ?? /* @__PURE__ */ new Map();
5275
+ nodes.set(node.id, node);
5276
+ nodesByComponent.set(componentKey, nodes);
5277
+ }
5278
+ return new Map(
5279
+ [...nodesByComponent].map(([componentKey, nodesByIdForComponent]) => {
5280
+ const nodes = [...nodesByIdForComponent.values()];
5281
+ return [
5282
+ componentKey,
5283
+ {
5284
+ usageCount: nodes.length,
5285
+ blastRadius: new Set(nodes.map((node) => node.file)).size,
5286
+ nodes
5287
+ }
5288
+ ];
5289
+ })
5290
+ );
5291
+ }
5292
+
5293
+ // src/canonical-source.ts
5294
+ function canonicalSourceIncludesExport(source, name) {
5295
+ const role = name.split(".").at(-1) ?? name;
5296
+ const matches = (names) => names.includes(name) || names.includes(role);
5297
+ return !matches(source.exclude ?? []) && (source.include === void 0 || matches(source.include));
5298
+ }
5299
+ function canonicalSourceContainsFile(source, file) {
5300
+ const root = source.kind === "directory" ? source.path : source.kind === "registry" ? source.installPath : source.implementationPath;
5301
+ if (!root) return false;
5302
+ const normalize = (value) => value.replace(/\\/g, "/").replace(/^\.\//, "").replace(/\/$/, "");
5303
+ const normalizedRoot = normalize(root);
5304
+ const normalizedFile = normalize(file);
5305
+ return normalizedRoot === "." || normalizedFile === normalizedRoot || normalizedFile.startsWith(`${normalizedRoot}/`);
5306
+ }
5307
+ function isCanonicalSourceDefinition(file, exportName, sources) {
5308
+ return sources.some(
5309
+ (source) => canonicalSourceContainsFile(source, file) && canonicalSourceIncludesExport(source, exportName)
5310
+ );
5311
+ }
5312
+
5263
5313
  // src/canonical-direction.ts
5264
5314
  function projectCanonicalDirectionConflicts(ix, canonicalSources) {
5265
5315
  const npmSources = canonicalSources.filter(
@@ -5493,6 +5543,11 @@ function ruleComponentsPreferLibrary(ix) {
5493
5543
  const configuredSources = canonicalSourcesFromPolicy(policy.options?.canonicalSources);
5494
5544
  const conflicts = projectCanonicalDirectionConflicts(ix, configuredSources);
5495
5545
  const sources = configuredSources.map((source) => suppressConflictedExports(source, conflicts));
5546
+ const approvedLocalDefinitionKeys = Array.isArray(policy.options?.approvedLocalDefinitionKeys) ? new Set(
5547
+ policy.options.approvedLocalDefinitionKeys.filter(
5548
+ (key) => typeof key === "string"
5549
+ )
5550
+ ) : void 0;
5496
5551
  const mappings = canonicalMappingsFromPolicy(policy.options?.canonicalMappings).filter(
5497
5552
  (mapping) => !canonicalDirectionConflictsTarget(conflicts, mapping.importPath, mapping.name)
5498
5553
  );
@@ -5502,12 +5557,33 @@ function ruleComponentsPreferLibrary(ix) {
5502
5557
  const textByNode = indexTextChildrenByNodeId(ix);
5503
5558
  const classTokensByNode = indexClassTokensByNode(ix);
5504
5559
  const reimplTargets = canonicalReimplTargets(sources, mappings);
5505
- const canonicalDirectoryResolvedNodes = indexCanonicalDirectoryResolvedNodes(ix, sources);
5560
+ const canonicalDirectoryResolvedNodes = indexCanonicalDirectoryResolvedNodes(
5561
+ ix,
5562
+ sources,
5563
+ approvedLocalDefinitionKeys
5564
+ );
5506
5565
  const shadowRenderRootNodeIds = ix.policy.ruleConfig("components/shadow-component")?.enabled === true ? indexShadowRenderRootNodeIds(ix) : /* @__PURE__ */ new Set();
5507
5566
  const findings = [];
5508
5567
  const seenImportFixes = /* @__PURE__ */ new Set();
5568
+ const canonicalIdentities = new Map(
5569
+ ix.byKind("component_identity").map((identity) => [identity.componentKey, identity.state === "canonical"])
5570
+ );
5571
+ const definitionsByFile = /* @__PURE__ */ new Map();
5572
+ for (const definition of ix.byKind("component_definition")) {
5573
+ const file = normalizePath(definition.file);
5574
+ const definitions = definitionsByFile.get(file) ?? [];
5575
+ definitions.push(definition);
5576
+ definitionsByFile.set(file, definitions);
5577
+ }
5509
5578
  for (const node of ix.byKind("usage_node")) {
5510
- if (isCanonicalSourceImplementationFile(node.file, sources)) continue;
5579
+ if (isCanonicalSourceImplementation(
5580
+ node,
5581
+ sources,
5582
+ definitionsByFile,
5583
+ canonicalIdentities,
5584
+ approvedLocalDefinitionKeys
5585
+ ))
5586
+ continue;
5511
5587
  if (node.element.includes(".")) continue;
5512
5588
  if (canonicalDirectoryResolvedNodes.has(node.id)) continue;
5513
5589
  if (shadowRenderRootNodeIds.has(node.id)) continue;
@@ -5518,7 +5594,12 @@ function ruleComponentsPreferLibrary(ix) {
5518
5594
  const nodeInputType = node.element === "input" ? readStaticStringProp(props, "type") : void 0;
5519
5595
  const mapped = findMapping(node, nodeInputType, mappings);
5520
5596
  if (mapped && imported && isMappedCanonicalImport(imported, mapped)) continue;
5521
- if (imported && isCanonicalImport(imported, node.element, sources)) continue;
5597
+ if (imported && isCanonicalImport(
5598
+ imported,
5599
+ node.element,
5600
+ approvedLocalDefinitionKeys === void 0 ? sources : sources.filter((source) => source.kind !== "directory")
5601
+ ))
5602
+ continue;
5522
5603
  if (mapped) {
5523
5604
  if (!shouldSuggestMapped(node, nodeInputType, imported, mapped)) continue;
5524
5605
  const importPath = mapped.importPath;
@@ -6069,18 +6150,27 @@ function canonicalImportPath(source) {
6069
6150
  if (source.kind === "registry") return source.importPath;
6070
6151
  return void 0;
6071
6152
  }
6072
- function indexCanonicalDirectoryResolvedNodes(ix, sources) {
6153
+ function indexCanonicalDirectoryResolvedNodes(ix, sources, approvedLocalDefinitionKeys) {
6073
6154
  const out = /* @__PURE__ */ new Set();
6074
- const directoryPaths = sources.filter(
6155
+ const directorySources = sources.filter(
6075
6156
  (source) => source.kind === "directory"
6076
- ).map((source) => normalizePath(source.path));
6077
- if (directoryPaths.length === 0) return out;
6078
- for (const fact of ix.byKind("usage_component")) {
6079
- const module = componentIdModule(fact.componentId);
6157
+ );
6158
+ if (directorySources.length === 0) return out;
6159
+ const identities = new Map(
6160
+ ix.byKind("component_identity").map((identity) => [identity.componentKey, identity])
6161
+ );
6162
+ for (const [componentKey, usage] of indexComponentIdentityUsage(ix)) {
6163
+ if (approvedLocalDefinitionKeys !== void 0 && !approvedLocalDefinitionKeys.has(componentKey))
6164
+ continue;
6165
+ const identity = identities.get(componentKey);
6166
+ if (identity && identity.state !== "canonical") continue;
6167
+ const module = componentIdModule(componentKey);
6080
6168
  if (module === void 0) continue;
6081
- const normalizedModule = normalizePath(module);
6082
- if (directoryPaths.some((path) => isPathInSource(normalizedModule, path))) {
6083
- out.add(fact.nodeId);
6169
+ const exportName = componentKey.slice(componentKey.indexOf("#") + 1);
6170
+ if (directorySources.some(
6171
+ (source) => canonicalSourceContainsFile(source, module) && canonicalSourceIncludesExport(source, exportName)
6172
+ )) {
6173
+ for (const node of usage.nodes) out.add(node.id);
6084
6174
  }
6085
6175
  }
6086
6176
  return out;
@@ -6089,24 +6179,23 @@ function componentIdModule(componentId2) {
6089
6179
  const hash = componentId2.indexOf("#");
6090
6180
  return hash > 0 ? componentId2.slice(0, hash) : void 0;
6091
6181
  }
6092
- function isCanonicalSourceImplementationFile(file, sources) {
6093
- const normalizedFile = normalizePath(file);
6182
+ function isCanonicalSourceImplementation(node, sources, definitionsByFile, canonicalIdentities, approvedLocalDefinitionKeys) {
6183
+ const definitions = definitionsByFile.get(normalizePath(node.file)) ?? [];
6094
6184
  return sources.some((source) => {
6095
- if (source.kind === "npm" && source.implementationPath) {
6096
- return isPathInSource(normalizedFile, source.implementationPath);
6097
- }
6098
- if (source.kind === "directory") {
6099
- return isPathInSource(normalizedFile, source.path);
6100
- }
6101
- if (source.kind === "registry") {
6102
- return isPathInSource(normalizedFile, source.installPath);
6103
- }
6104
- return false;
6185
+ if (!canonicalSourceContainsFile(source, node.file)) return false;
6186
+ if (approvedLocalDefinitionKeys === void 0 && (source.kind !== "directory" || source.include === void 0 && !source.exclude?.length))
6187
+ return true;
6188
+ const owners = definitions.filter(
6189
+ (definition) => definition.location && locationContains(definition.location, node.location)
6190
+ );
6191
+ return owners.length > 0 && owners.every(
6192
+ (definition) => (approvedLocalDefinitionKeys === void 0 || approvedLocalDefinitionKeys.has(definition.componentKey)) && canonicalIdentities.get(definition.componentKey) !== false && canonicalSourceIncludesExport(source, definition.exportName)
6193
+ );
6105
6194
  });
6106
6195
  }
6107
- function isPathInSource(file, sourcePath) {
6108
- const normalizedSource = normalizePath(sourcePath).replace(/\/$/, "");
6109
- return file === normalizedSource || file.startsWith(`${normalizedSource}/`);
6196
+ function locationContains(region, node) {
6197
+ if (region.endLine === void 0 || region.endColumn === void 0) return false;
6198
+ return (node.line > region.line || node.line === region.line && node.column >= region.column) && (node.line < region.endLine || node.line === region.endLine && node.column < region.endColumn);
6110
6199
  }
6111
6200
  function normalizePath(path) {
6112
6201
  return path.replace(/\\/g, "/").replace(/^\.\//, "");
@@ -6115,33 +6204,6 @@ function isIdentifier(value) {
6115
6204
  return /^[A-Za-z_$][\w$]*$/.test(value);
6116
6205
  }
6117
6206
 
6118
- // src/identity/usage.ts
6119
- function indexComponentIdentityUsage(ix) {
6120
- const nodesById = new Map(ix.byKind("usage_node").map((node) => [node.id, node]));
6121
- const nodesByComponent = /* @__PURE__ */ new Map();
6122
- for (const usage of ix.byKind("usage_component")) {
6123
- const node = nodesById.get(usage.nodeId);
6124
- if (!node) continue;
6125
- const componentKey = String(usage.componentId);
6126
- const nodes = nodesByComponent.get(componentKey) ?? /* @__PURE__ */ new Map();
6127
- nodes.set(node.id, node);
6128
- nodesByComponent.set(componentKey, nodes);
6129
- }
6130
- return new Map(
6131
- [...nodesByComponent].map(([componentKey, nodesByIdForComponent]) => {
6132
- const nodes = [...nodesByIdForComponent.values()];
6133
- return [
6134
- componentKey,
6135
- {
6136
- usageCount: nodes.length,
6137
- blastRadius: new Set(nodes.map((node) => node.file)).size,
6138
- nodes
6139
- }
6140
- ];
6141
- })
6142
- );
6143
- }
6144
-
6145
6207
  // src/rules/components-shadow-component.ts
6146
6208
  var RULE_ID4 = "components/shadow-component";
6147
6209
  var RULE_VERSION4 = "1";
@@ -12016,6 +12078,8 @@ export {
12016
12078
  canonicalFactIntegrityV1Schema,
12017
12079
  canonicalJson,
12018
12080
  canonicalPreimage,
12081
+ canonicalSourceContainsFile,
12082
+ canonicalSourceIncludesExport,
12019
12083
  canonicalizeOwnedComponentId,
12020
12084
  canonicalizeOwnedImport,
12021
12085
  capConfiguredSeverity,
@@ -12170,6 +12234,7 @@ export {
12170
12234
  inferTokenCategory,
12171
12235
  inferTokenGroup,
12172
12236
  isApprovedContractTokenNames,
12237
+ isCanonicalSourceDefinition,
12173
12238
  isColorLike,
12174
12239
  isCompositionPattern,
12175
12240
  isContractFile,