@pibbl/core 0.0.1 → 0.0.2
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/README.md +1 -1
- package/dist/features/machines/animation.d.ts +64 -0
- package/dist/features/machines/animation.js +55 -0
- package/dist/features/machines/animation.js.map +7 -0
- package/dist/features/machines/animation.mjs +1 -0
- package/dist/features/machines/assign.d.ts +16 -0
- package/dist/features/machines/assign.js +15 -0
- package/dist/features/machines/assign.js.map +7 -0
- package/dist/features/machines/callback.d.ts +9 -0
- package/dist/features/machines/callback.js +7 -0
- package/dist/features/machines/callback.js.map +7 -0
- package/dist/features/machines/hook.d.ts +30 -0
- package/dist/features/machines/hook.js +37 -0
- package/dist/features/machines/hook.js.map +7 -0
- package/dist/features/machines/index.d.ts +6 -0
- package/dist/features/machines/index.js +12 -0
- package/dist/features/machines/index.js.map +7 -0
- package/dist/features/machines/index.mjs +1 -0
- package/dist/features/machines/runtime.d.ts +18 -0
- package/dist/features/machines/runtime.js +363 -0
- package/dist/features/machines/runtime.js.map +7 -0
- package/dist/features/machines/types.d.ts +164 -0
- package/dist/features/physics/2d-geometry.d.ts +3 -3
- package/dist/features/physics/2d-geometry.js.map +1 -1
- package/dist/features/physics/2d.d.ts +115 -62
- package/dist/features/physics/2d.js +59 -28
- package/dist/features/physics/2d.js.map +2 -2
- package/dist/features/physics/lib/2d/query-types.d.ts +6 -0
- package/dist/features/physics/lib/2d/runtime/controller.d.ts +7 -6
- package/dist/features/physics/lib/2d/runtime/controller.js.map +2 -2
- package/dist/features/physics/lib/2d/types.d.ts +8 -30
- package/dist/features/physics/lib/2d/world/queries.d.ts +7 -6
- package/dist/features/physics/lib/2d/world/queries.js.map +2 -2
- package/dist/features/sprites/formats/aseprite.d.ts +5 -0
- package/dist/features/sprites/formats/texture-packer.d.ts +5 -0
- package/dist/features/sprites/index.d.ts +6 -0
- package/dist/features/sprites/loader.d.ts +25 -0
- package/dist/features/sprites/model.d.ts +75 -0
- package/dist/features/sprites/sprite.d.ts +22 -0
- package/dist/features/viz/index.d.ts +28 -3
- package/dist/features/viz/index.js +40 -4
- package/dist/features/viz/index.js.map +2 -2
- package/dist/features/viz/lib/axis-labels.d.ts +2 -0
- package/dist/features/viz/lib/axis-labels.js +41 -0
- package/dist/features/viz/lib/axis-labels.js.map +7 -0
- package/dist/features/viz/lib/axis-title.d.ts +23 -0
- package/dist/features/viz/lib/axis-title.js +23 -0
- package/dist/features/viz/lib/axis-title.js.map +7 -0
- package/dist/features/viz/lib/axis.d.ts +1 -1
- package/dist/features/viz/lib/axis.js +50 -50
- package/dist/features/viz/lib/axis.js.map +2 -2
- package/dist/features/viz/lib/bar-scale.d.ts +7 -0
- package/dist/features/viz/lib/bar-scale.js +34 -0
- package/dist/features/viz/lib/bar-scale.js.map +7 -0
- package/dist/features/viz/lib/bar-series.js +5 -4
- package/dist/features/viz/lib/bar-series.js.map +2 -2
- package/dist/features/viz/lib/chart-lines.d.ts +41 -0
- package/dist/features/viz/lib/chart-lines.js +32 -0
- package/dist/features/viz/lib/chart-lines.js.map +7 -0
- package/dist/features/viz/lib/hover-data.js +2 -2
- package/dist/features/viz/lib/hover-data.js.map +2 -2
- package/dist/features/viz/lib/hover-types.d.ts +5 -5
- package/dist/features/viz/lib/line-series.js +3 -3
- package/dist/features/viz/lib/line-series.js.map +2 -2
- package/dist/features/viz/lib/linear-scale-component.d.ts +7 -0
- package/dist/features/viz/lib/linear-scale-component.js +18 -0
- package/dist/features/viz/lib/linear-scale-component.js.map +7 -0
- package/dist/features/viz/lib/linear-scale.js +1 -1
- package/dist/features/viz/lib/linear-scale.js.map +2 -2
- package/dist/features/viz/lib/log-scale-component.d.ts +7 -0
- package/dist/features/viz/lib/log-scale-component.js +19 -0
- package/dist/features/viz/lib/log-scale-component.js.map +7 -0
- package/dist/features/viz/lib/log-scale.d.ts +2 -0
- package/dist/features/viz/lib/log-scale.js +53 -0
- package/dist/features/viz/lib/log-scale.js.map +7 -0
- package/dist/features/viz/lib/nearest.d.ts +9 -9
- package/dist/features/viz/lib/nearest.js.map +1 -1
- package/dist/features/viz/lib/numeric-ticks.d.ts +38 -0
- package/dist/features/viz/lib/numeric-ticks.js +54 -0
- package/dist/features/viz/lib/numeric-ticks.js.map +7 -0
- package/dist/features/viz/lib/plot-series.js +2 -2
- package/dist/features/viz/lib/plot-series.js.map +2 -2
- package/dist/features/viz/lib/point-scale-component.d.ts +7 -0
- package/dist/features/viz/lib/point-scale-component.js +19 -0
- package/dist/features/viz/lib/point-scale-component.js.map +7 -0
- package/dist/features/viz/lib/point-scale.d.ts +2 -0
- package/dist/features/viz/lib/point-scale.js +45 -0
- package/dist/features/viz/lib/point-scale.js.map +7 -0
- package/dist/features/viz/lib/point-series.js +2 -2
- package/dist/features/viz/lib/point-series.js.map +2 -2
- package/dist/features/viz/lib/reference-band.d.ts +16 -0
- package/dist/features/viz/lib/reference-band.js +27 -0
- package/dist/features/viz/lib/reference-band.js.map +7 -0
- package/dist/features/viz/lib/scale-adjust.js +9 -4
- package/dist/features/viz/lib/scale-adjust.js.map +2 -2
- package/dist/features/viz/lib/scale-context.d.ts +5 -4
- package/dist/features/viz/lib/scale-context.js +15 -11
- package/dist/features/viz/lib/scale-context.js.map +2 -2
- package/dist/features/viz/lib/scale-provider.d.ts +2 -0
- package/dist/features/viz/lib/scale-provider.js +13 -0
- package/dist/features/viz/lib/scale-provider.js.map +7 -0
- package/dist/features/viz/lib/scale-ticks.d.ts +5 -0
- package/dist/features/viz/lib/scale-ticks.js +49 -0
- package/dist/features/viz/lib/scale-ticks.js.map +7 -0
- package/dist/features/viz/lib/scale-view.d.ts +4 -0
- package/dist/features/viz/lib/scale-view.js +21 -0
- package/dist/features/viz/lib/scale-view.js.map +7 -0
- package/dist/features/viz/lib/symlog-scale-component.d.ts +7 -0
- package/dist/features/viz/lib/symlog-scale-component.js +19 -0
- package/dist/features/viz/lib/symlog-scale-component.js.map +7 -0
- package/dist/features/viz/lib/symlog-scale.d.ts +2 -0
- package/dist/features/viz/lib/symlog-scale.js +38 -0
- package/dist/features/viz/lib/symlog-scale.js.map +7 -0
- package/dist/features/viz/lib/types.d.ts +95 -18
- package/dist/features/viz/lib/use-bar-scale.d.ts +8 -0
- package/dist/features/viz/lib/use-bar-scale.js +9 -0
- package/dist/features/viz/lib/use-bar-scale.js.map +7 -0
- package/dist/features/viz/lib/use-continuous-scale.d.ts +8 -0
- package/dist/features/viz/lib/use-continuous-scale.js +9 -0
- package/dist/features/viz/lib/use-continuous-scale.js.map +7 -0
- package/dist/features/viz/lib/use-linear-scale.d.ts +8 -0
- package/dist/features/viz/lib/use-linear-scale.js +9 -0
- package/dist/features/viz/lib/use-linear-scale.js.map +7 -0
- package/dist/features/viz/lib/use-log-scale.d.ts +8 -0
- package/dist/features/viz/lib/use-log-scale.js +9 -0
- package/dist/features/viz/lib/use-log-scale.js.map +7 -0
- package/dist/features/viz/lib/use-point-scale.d.ts +8 -0
- package/dist/features/viz/lib/use-point-scale.js +9 -0
- package/dist/features/viz/lib/use-point-scale.js.map +7 -0
- package/dist/features/viz/lib/use-symlog-scale.d.ts +8 -0
- package/dist/features/viz/lib/use-symlog-scale.js +9 -0
- package/dist/features/viz/lib/use-symlog-scale.js.map +7 -0
- package/dist/features/viz/lib/use-utc-scale.d.ts +8 -0
- package/dist/features/viz/lib/use-utc-scale.js +9 -0
- package/dist/features/viz/lib/use-utc-scale.js.map +7 -0
- package/dist/features/viz/lib/utc-labels.d.ts +12 -0
- package/dist/features/viz/lib/utc-labels.js +27 -0
- package/dist/features/viz/lib/utc-labels.js.map +7 -0
- package/dist/features/viz/lib/utc-scale-component.d.ts +7 -0
- package/dist/features/viz/lib/utc-scale-component.js +18 -0
- package/dist/features/viz/lib/utc-scale-component.js.map +7 -0
- package/dist/features/viz/lib/utc-scale.d.ts +21 -0
- package/dist/features/viz/lib/utc-scale.js +123 -0
- package/dist/features/viz/lib/utc-scale.js.map +7 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/animation/definition.d.ts +5 -3
- package/dist/lib/animation/definition.js +29 -4
- package/dist/lib/animation/definition.js.map +2 -2
- package/dist/lib/animation/playback.d.ts +8 -0
- package/dist/lib/animation/playback.js +33 -11
- package/dist/lib/animation/playback.js.map +2 -2
- package/dist/lib/animation/spring.d.ts +3 -1
- package/dist/lib/animation/spring.js.map +2 -2
- package/dist/lib/animation/types.d.ts +29 -73
- package/dist/lib/hooks/use-animated-value.d.ts +11 -21
- package/dist/lib/hooks/use-animated-value.js +23 -70
- package/dist/lib/hooks/use-animated-value.js.map +3 -3
- package/dist/lib/hooks/use-playback.js +1 -0
- package/dist/lib/hooks/use-playback.js.map +2 -2
- package/package.json +18 -4
- package/dist/features/viz/lib/scale.d.ts +0 -11
- package/dist/features/viz/lib/scale.js +0 -80
- package/dist/features/viz/lib/scale.js.map +0 -7
- package/dist/features/viz/lib/use-scale.d.ts +0 -20
- package/dist/features/viz/lib/use-scale.js +0 -10
- package/dist/features/viz/lib/use-scale.js.map +0 -7
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/features/physics/lib/2d/world/queries.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n boundsOfShape2D,\n type PibblPhysicsAabb2D,\n type PibblPhysicsPose2D,\n type PibblPhysicsRay2D,\n type PibblPhysicsShape2D,\n type PibblPhysicsVector2,\n} from \"../../../2d-geometry.js\";\nimport { copyFiniteVector2, requireNonnegativeNumber } from \"../../shared/validation.js\";\nimport { containsPointInShape2D, overlapPreparedShapes2D } from \"../collision/pairs.js\";\nimport { raycastShape2D, shapeCastAgainstShape2D } from \"../collision/casts.js\";\nimport { RADIANS_TO_DEGREES } from \"../numeric-policy.js\";\nimport { createShape2D, type ShapeRecord2D } from \"../shape-records.js\";\nimport type {\n PibblPhysicsBodyHandle2D,\n PibblPhysicsColliderHandle2D,\n PibblPhysicsCollisionFilter,\n PibblPhysicsQueryHit2D,\n PibblPhysicsQueryMatch2D,\n PibblPhysicsQueryMode,\n PibblPhysicsQueryOptions2D,\n PibblPhysicsQueryResult2D,\n} from \"../types.js\";\nimport type { DynamicAabbBroadPhase2D } from \"./broad-phase.js\";\nimport { collisionFiltersAllow2D } from \"./ccd.js\";\nimport { COLLIDER_SENSOR_2D } from \"./contact-cache.js\";\nimport type { BodyStore2D, ColliderStore2D } from \"./storage.js\";\n\ninterface HandleIdentity2D {\n readonly index: number;\n readonly generation: number;\n}\n\nexport interface CommittedWorldQueriesOptions2D {\n readonly generation: number;\n readonly bodies: BodyStore2D;\n readonly colliders: ColliderStore2D;\n readonly broadPhase: DynamicAabbBroadPhase2D;\n readonly materializeBody: (index: number, generation: number) => PibblPhysicsBodyHandle2D;\n readonly materializeCollider: (index: number, generation: number) => PibblPhysicsColliderHandle2D;\n readonly resolveBody: (handle: PibblPhysicsBodyHandle2D) => HandleIdentity2D | null;\n readonly resolveCollider: (handle: PibblPhysicsColliderHandle2D) => HandleIdentity2D | null;\n}\n\ninterface PreparedQueryOptions2D {\n readonly mode: PibblPhysicsQueryMode;\n readonly sensors: \"include\" | \"exclude\" | \"only\";\n readonly collisionFilter: PibblPhysicsCollisionFilter | null;\n readonly excludeBody: HandleIdentity2D | null;\n readonly excludeCollider: HandleIdentity2D | null;\n readonly valid: boolean;\n}\n\nexport class CommittedWorldQueries2D {\n private active = true;\n private candidateProxies: Int32Array;\n private hitColliderIndices: Int32Array;\n private hitColliderGenerations: Uint32Array;\n private hitBodyIndices: Int32Array;\n private hitBodyGenerations: Uint32Array;\n private hitPointX: Float64Array;\n private hitPointY: Float64Array;\n private hitNormalX: Float64Array;\n private hitNormalY: Float64Array;\n private hitDistances: Float64Array;\n private hitTimes: Float64Array;\n private hitCount = 0;\n private readonly shapeShells = new WeakMap<ShapeRecord2D, PibblPhysicsShape2D>();\n\n constructor(private readonly options: CommittedWorldQueriesOptions2D) {\n const capacity = normalizedCapacity(options.broadPhase.proxyCapacity);\n this.candidateProxies = new Int32Array(capacity);\n this.hitColliderIndices = new Int32Array(capacity);\n this.hitColliderGenerations = new Uint32Array(capacity);\n this.hitBodyIndices = new Int32Array(capacity);\n this.hitBodyGenerations = new Uint32Array(capacity);\n this.hitPointX = new Float64Array(capacity);\n this.hitPointY = new Float64Array(capacity);\n this.hitNormalX = new Float64Array(capacity);\n this.hitNormalY = new Float64Array(capacity);\n this.hitDistances = new Float64Array(capacity);\n this.hitTimes = new Float64Array(capacity);\n }\n\n invalidate(): void {\n this.active = false;\n this.hitCount = 0;\n }\n\n raycast<Mode extends PibblPhysicsQueryMode = \"closest\">(\n worldGeneration: number,\n ray: PibblPhysicsRay2D,\n queryOptions?: PibblPhysicsQueryOptions2D<Mode>,\n ): PibblPhysicsQueryResult2D<Mode, PibblPhysicsQueryHit2D> {\n const prepared = this.prepareOptions(queryOptions);\n if (!this.isUsable(worldGeneration, prepared)) return emptyResult(prepared.mode);\n const origin = copyFiniteVector2(ray.origin, \"ray.origin\");\n const direction = copyFiniteVector2(ray.direction, \"ray.direction\");\n const directionLength = Math.hypot(direction[0], direction[1]);\n if (directionLength === 0) throw new RangeError(\"ray.direction must be non-zero.\");\n const maxDistance = requireNonnegativeNumber(ray.maxDistance, \"ray.maxDistance\");\n const endX = origin[0] + (direction[0] / directionLength) * maxDistance;\n const endY = origin[1] + (direction[1] / directionLength) * maxDistance;\n this.beginQuery();\n const candidateCount = this.queryCandidates(\n Math.min(origin[0], endX),\n Math.min(origin[1], endY),\n Math.max(origin[0], endX),\n Math.max(origin[1], endY),\n );\n for (let candidate = 0; candidate < candidateCount; candidate += 1) {\n const collider = this.semanticColliderAt(candidate, prepared);\n if (collider === null) continue;\n const hit = raycastShape2D(collider.shape, collider.pose, ray);\n if (hit === null) continue;\n if (prepared.mode === \"any\") return true as PibblPhysicsQueryResult2D<Mode, PibblPhysicsQueryHit2D>;\n this.appendHit(collider, hit.point, hit.normal, hit.distance, hit.timeOfImpact);\n }\n return this.finishHits<Mode>(prepared.mode);\n }\n\n shapeCast<Mode extends PibblPhysicsQueryMode = \"closest\">(\n worldGeneration: number,\n shape: PibblPhysicsShape2D,\n from: PibblPhysicsPose2D,\n translation: PibblPhysicsVector2,\n queryOptions?: PibblPhysicsQueryOptions2D<Mode>,\n ): PibblPhysicsQueryResult2D<Mode, PibblPhysicsQueryHit2D> {\n const prepared = this.prepareOptions(queryOptions);\n if (!this.isUsable(worldGeneration, prepared)) return emptyResult(prepared.mode);\n const copiedTranslation = copyFiniteVector2(translation, \"translation\");\n const start = boundsOfShape2D(shape, from);\n const end = boundsOfShape2D(shape, {\n position: [from.position[0] + copiedTranslation[0], from.position[1] + copiedTranslation[1]],\n rotationDegrees: from.rotationDegrees,\n });\n this.beginQuery();\n const candidateCount = this.queryCandidates(\n Math.min(start.min[0], end.min[0]),\n Math.min(start.min[1], end.min[1]),\n Math.max(start.max[0], end.max[0]),\n Math.max(start.max[1], end.max[1]),\n );\n for (let candidate = 0; candidate < candidateCount; candidate += 1) {\n const collider = this.semanticColliderAt(candidate, prepared);\n if (collider === null) continue;\n const hit = shapeCastAgainstShape2D(shape, from, copiedTranslation, collider.shape, collider.pose);\n if (hit === null) continue;\n if (prepared.mode === \"any\") return true as PibblPhysicsQueryResult2D<Mode, PibblPhysicsQueryHit2D>;\n this.appendHit(collider, hit.point, hit.normal, hit.distance, hit.timeOfImpact);\n }\n return this.finishHits<Mode>(prepared.mode);\n }\n\n overlapShape<Mode extends PibblPhysicsQueryMode = \"closest\">(\n worldGeneration: number,\n shape: PibblPhysicsShape2D,\n pose: PibblPhysicsPose2D,\n queryOptions?: PibblPhysicsQueryOptions2D<Mode>,\n ): PibblPhysicsQueryResult2D<Mode, PibblPhysicsQueryMatch2D> {\n const bounds = this.isGenerationLive(worldGeneration) ? boundsOfShape2D(shape, pose) : null;\n return this.runMatchQuery(worldGeneration, bounds, queryOptions, (collider) =>\n overlapPreparedShapes2D(shape, pose, collider.shape, collider.pose),\n );\n }\n\n queryAabb<Mode extends PibblPhysicsQueryMode = \"closest\">(\n worldGeneration: number,\n bounds: PibblPhysicsAabb2D,\n queryOptions?: PibblPhysicsQueryOptions2D<Mode>,\n ): PibblPhysicsQueryResult2D<Mode, PibblPhysicsQueryMatch2D> {\n if (!this.isGenerationLive(worldGeneration)) {\n return emptyResult(modeOf(queryOptions));\n }\n const copied = copyAabb(bounds);\n return this.runMatchQuery(worldGeneration, copied, queryOptions, (collider) => {\n const colliderBounds = boundsOfShape2D(collider.shape, collider.pose);\n return aabbsOverlap(copied, colliderBounds);\n });\n }\n\n queryPoint<Mode extends PibblPhysicsQueryMode = \"closest\">(\n worldGeneration: number,\n point: PibblPhysicsVector2,\n queryOptions?: PibblPhysicsQueryOptions2D<Mode>,\n ): PibblPhysicsQueryResult2D<Mode, PibblPhysicsQueryMatch2D> {\n if (!this.isGenerationLive(worldGeneration)) {\n return emptyResult(modeOf(queryOptions));\n }\n const copied = copyFiniteVector2(point, \"point\");\n const bounds = Object.freeze({ min: copied, max: copied });\n return this.runMatchQuery(worldGeneration, bounds, queryOptions, (collider) =>\n containsPointInShape2D(collider.shape, collider.pose, copied),\n );\n }\n\n private runMatchQuery<Mode extends PibblPhysicsQueryMode>(\n worldGeneration: number,\n bounds: PibblPhysicsAabb2D | null,\n queryOptions: PibblPhysicsQueryOptions2D<Mode> | undefined,\n matches: (collider: SemanticCollider2D) => boolean,\n ): PibblPhysicsQueryResult2D<Mode, PibblPhysicsQueryMatch2D> {\n const prepared = this.prepareOptions(queryOptions);\n if (bounds === null || !this.isUsable(worldGeneration, prepared)) {\n return emptyResult(prepared.mode);\n }\n this.beginQuery();\n const candidateCount = this.queryCandidates(bounds.min[0], bounds.min[1], bounds.max[0], bounds.max[1]);\n for (let candidate = 0; candidate < candidateCount; candidate += 1) {\n const collider = this.semanticColliderAt(candidate, prepared);\n if (collider === null || !matches(collider)) continue;\n if (prepared.mode === \"any\") {\n return true as PibblPhysicsQueryResult2D<Mode, PibblPhysicsQueryMatch2D>;\n }\n this.appendMatch(collider);\n }\n return this.finishMatches<Mode>(prepared.mode);\n }\n\n private prepareOptions<Mode extends PibblPhysicsQueryMode>(\n queryOptions: PibblPhysicsQueryOptions2D<Mode> | undefined,\n ): PreparedQueryOptions2D {\n const mode = modeOf(queryOptions);\n const sensors = queryOptions?.sensors ?? \"include\";\n if (sensors !== \"include\" && sensors !== \"exclude\" && sensors !== \"only\") {\n throw new RangeError(\"query sensors must be include, exclude, or only.\");\n }\n const excludeBody =\n queryOptions?.excludeBody === undefined ? null : this.options.resolveBody(queryOptions.excludeBody);\n const excludeCollider =\n queryOptions?.excludeCollider === undefined ? null : this.options.resolveCollider(queryOptions.excludeCollider);\n const validBody =\n queryOptions?.excludeBody === undefined ||\n (excludeBody !== null && this.options.bodies.has(excludeBody.index, excludeBody.generation));\n const validCollider =\n queryOptions?.excludeCollider === undefined ||\n (excludeCollider !== null && this.options.colliders.has(excludeCollider.index, excludeCollider.generation));\n return {\n mode,\n sensors,\n collisionFilter: queryOptions?.collisionFilter ?? null,\n excludeBody,\n excludeCollider,\n valid: validBody && validCollider,\n };\n }\n\n private isUsable(worldGeneration: number, prepared: PreparedQueryOptions2D): boolean {\n return this.isGenerationLive(worldGeneration) && prepared.valid;\n }\n\n private isGenerationLive(worldGeneration: number): boolean {\n return this.active && worldGeneration === this.options.generation;\n }\n\n private beginQuery(): void {\n this.hitCount = 0;\n this.ensureCapacity(this.options.broadPhase.proxyCapacity);\n }\n\n private queryCandidates(minX: number, minY: number, maxX: number, maxY: number): number {\n return this.options.broadPhase.queryAabbInto(\n minX,\n minY,\n maxX,\n maxY,\n this.candidateProxies,\n 0,\n this.candidateProxies.length,\n );\n }\n\n private semanticColliderAt(candidate: number, prepared: PreparedQueryOptions2D): SemanticCollider2D | null {\n const proxy = this.candidateProxies[candidate]!;\n const colliderIndex = this.options.broadPhase.proxyColliderIndices[proxy]!;\n const colliderGeneration = this.options.broadPhase.proxyColliderGenerations[proxy]!;\n const { colliders, bodies } = this.options;\n if (!colliders.has(colliderIndex, colliderGeneration)) return null;\n const bodyIndex = colliders.bodyIndices[colliderIndex]!;\n const bodyGeneration = colliders.bodyGenerations[colliderIndex]!;\n if (!bodies.has(bodyIndex, bodyGeneration)) return null;\n if (sameIdentity(prepared.excludeBody, bodyIndex, bodyGeneration)) return null;\n if (sameIdentity(prepared.excludeCollider, colliderIndex, colliderGeneration)) return null;\n const sensor = (colliders.flags[colliderIndex]! & COLLIDER_SENSOR_2D) !== 0;\n if (prepared.sensors === \"exclude\" && sensor) return null;\n if (prepared.sensors === \"only\" && !sensor) return null;\n if (\n prepared.collisionFilter !== null &&\n !collisionFiltersAllow2D(prepared.collisionFilter, colliders.filters[colliderIndex])\n )\n return null;\n const record = colliders.shapes[colliderIndex];\n if (record === null) return null;\n return {\n colliderIndex,\n colliderGeneration,\n bodyIndex,\n bodyGeneration,\n shape: this.shapeShell(record),\n pose: publicBodyOriginPose(bodies, bodyIndex),\n };\n }\n\n private appendHit(\n collider: SemanticCollider2D,\n point: PibblPhysicsVector2,\n normal: PibblPhysicsVector2,\n distance: number,\n time: number,\n ): void {\n const target = this.hitCount;\n this.writeIdentity(target, collider);\n this.hitPointX[target] = point[0];\n this.hitPointY[target] = point[1];\n this.hitNormalX[target] = normal[0];\n this.hitNormalY[target] = normal[1];\n this.hitDistances[target] = distance;\n this.hitTimes[target] = time;\n this.hitCount += 1;\n }\n\n private appendMatch(collider: SemanticCollider2D): void {\n this.writeIdentity(this.hitCount, collider);\n this.hitCount += 1;\n }\n\n private writeIdentity(target: number, collider: SemanticCollider2D): void {\n this.hitColliderIndices[target] = collider.colliderIndex;\n this.hitColliderGenerations[target] = collider.colliderGeneration;\n this.hitBodyIndices[target] = collider.bodyIndex;\n this.hitBodyGenerations[target] = collider.bodyGeneration;\n }\n\n private finishHits<Mode extends PibblPhysicsQueryMode>(\n mode: PibblPhysicsQueryMode,\n ): PibblPhysicsQueryResult2D<Mode, PibblPhysicsQueryHit2D> {\n this.sortHits(true);\n if (mode === \"any\") {\n return false as PibblPhysicsQueryResult2D<Mode, PibblPhysicsQueryHit2D>;\n }\n if (mode === \"closest\") {\n return (this.hitCount === 0 ? null : this.materializeHit(0)) as PibblPhysicsQueryResult2D<\n Mode,\n PibblPhysicsQueryHit2D\n >;\n }\n const results: PibblPhysicsQueryHit2D[] = [];\n for (let index = 0; index < this.hitCount; index += 1) {\n results.push(this.materializeHit(index));\n }\n return Object.freeze(results) as PibblPhysicsQueryResult2D<Mode, PibblPhysicsQueryHit2D>;\n }\n\n private finishMatches<Mode extends PibblPhysicsQueryMode>(\n mode: PibblPhysicsQueryMode,\n ): PibblPhysicsQueryResult2D<Mode, PibblPhysicsQueryMatch2D> {\n this.sortHits(false);\n if (mode === \"any\") {\n return false as PibblPhysicsQueryResult2D<Mode, PibblPhysicsQueryMatch2D>;\n }\n if (mode === \"closest\") {\n return (this.hitCount === 0 ? null : this.materializeMatch(0)) as PibblPhysicsQueryResult2D<\n Mode,\n PibblPhysicsQueryMatch2D\n >;\n }\n const results: PibblPhysicsQueryMatch2D[] = [];\n for (let index = 0; index < this.hitCount; index += 1) {\n results.push(this.materializeMatch(index));\n }\n return Object.freeze(results) as PibblPhysicsQueryResult2D<Mode, PibblPhysicsQueryMatch2D>;\n }\n\n private materializeHit(index: number): PibblPhysicsQueryHit2D {\n return Object.freeze({\n ...this.materializeMatch(index),\n point: freezeVector(this.hitPointX[index]!, this.hitPointY[index]!),\n normal: freezeVector(this.hitNormalX[index]!, this.hitNormalY[index]!),\n distance: this.hitDistances[index]!,\n timeOfImpact: this.hitTimes[index]!,\n });\n }\n\n private materializeMatch(index: number): PibblPhysicsQueryMatch2D {\n const bodyIndex = this.hitBodyIndices[index]!;\n const bodyGeneration = this.hitBodyGenerations[index]!;\n const colliderIndex = this.hitColliderIndices[index]!;\n const colliderGeneration = this.hitColliderGenerations[index]!;\n return Object.freeze({\n body: this.options.materializeBody(bodyIndex, bodyGeneration),\n collider: this.options.materializeCollider(colliderIndex, colliderGeneration),\n bodyGeneration,\n colliderGeneration,\n tag: this.options.colliders.tags[colliderIndex],\n });\n }\n\n private sortHits(withDistance: boolean): void {\n for (let index = 1; index < this.hitCount; index += 1) {\n let current = index;\n while (current > 0 && this.compareHits(current, current - 1, withDistance) < 0) {\n this.swapHits(current, current - 1, withDistance);\n current -= 1;\n }\n }\n }\n\n private compareHits(first: number, second: number, withDistance: boolean): number {\n if (withDistance) {\n const time = this.hitTimes[first]! - this.hitTimes[second]!;\n if (time !== 0) return time;\n const distance = this.hitDistances[first]! - this.hitDistances[second]!;\n if (distance !== 0) return distance;\n }\n return (\n this.hitColliderIndices[first]! - this.hitColliderIndices[second]! ||\n this.hitColliderGenerations[first]! - this.hitColliderGenerations[second]!\n );\n }\n\n private swapHits(first: number, second: number, withDistance: boolean): void {\n swapInt32(this.hitColliderIndices, first, second);\n swapUint32(this.hitColliderGenerations, first, second);\n swapInt32(this.hitBodyIndices, first, second);\n swapUint32(this.hitBodyGenerations, first, second);\n if (!withDistance) return;\n swapFloat64(this.hitPointX, first, second);\n swapFloat64(this.hitPointY, first, second);\n swapFloat64(this.hitNormalX, first, second);\n swapFloat64(this.hitNormalY, first, second);\n swapFloat64(this.hitDistances, first, second);\n swapFloat64(this.hitTimes, first, second);\n }\n\n private shapeShell(record: ShapeRecord2D): PibblPhysicsShape2D {\n let shell = this.shapeShells.get(record);\n if (shell === undefined) {\n shell = createShape2D(record);\n this.shapeShells.set(record, shell);\n }\n return shell;\n }\n\n private ensureCapacity(required: number): void {\n if (required <= this.candidateProxies.length) return;\n const capacity = normalizedCapacity(required);\n this.candidateProxies = growInt32(this.candidateProxies, capacity);\n this.hitColliderIndices = growInt32(this.hitColliderIndices, capacity);\n this.hitColliderGenerations = growUint32(this.hitColliderGenerations, capacity);\n this.hitBodyIndices = growInt32(this.hitBodyIndices, capacity);\n this.hitBodyGenerations = growUint32(this.hitBodyGenerations, capacity);\n this.hitPointX = growFloat64(this.hitPointX, capacity);\n this.hitPointY = growFloat64(this.hitPointY, capacity);\n this.hitNormalX = growFloat64(this.hitNormalX, capacity);\n this.hitNormalY = growFloat64(this.hitNormalY, capacity);\n this.hitDistances = growFloat64(this.hitDistances, capacity);\n this.hitTimes = growFloat64(this.hitTimes, capacity);\n }\n}\n\ninterface SemanticCollider2D {\n readonly colliderIndex: number;\n readonly colliderGeneration: number;\n readonly bodyIndex: number;\n readonly bodyGeneration: number;\n readonly shape: PibblPhysicsShape2D;\n readonly pose: PibblPhysicsPose2D;\n}\n\nfunction modeOf<Mode extends PibblPhysicsQueryMode>(\n options: PibblPhysicsQueryOptions2D<Mode> | undefined,\n): PibblPhysicsQueryMode {\n const mode = options?.mode ?? \"closest\";\n if (mode !== \"closest\" && mode !== \"any\" && mode !== \"all\") {\n throw new RangeError(\"query mode must be closest, any, or all.\");\n }\n return mode;\n}\n\nfunction emptyResult<Mode extends PibblPhysicsQueryMode, Result>(\n mode: PibblPhysicsQueryMode,\n): PibblPhysicsQueryResult2D<Mode, Result> {\n return (mode === \"any\" ? false : mode === \"all\" ? Object.freeze([]) : null) as PibblPhysicsQueryResult2D<Mode, Result>;\n}\n\nfunction sameIdentity(identity: HandleIdentity2D | null, index: number, generation: number): boolean {\n return identity !== null && identity.index === index && identity.generation === generation;\n}\n\nfunction publicPose(x: number, y: number, rotationRadians: number): PibblPhysicsPose2D {\n return {\n position: [x, y],\n rotationDegrees: rotationRadians * RADIANS_TO_DEGREES,\n };\n}\n\nfunction publicBodyOriginPose(\n bodies: BodyStore2D,\n index: number,\n): PibblPhysicsPose2D {\n const rotationRadians = bodies.rotationRadians[index]!;\n const cosine = Math.cos(rotationRadians);\n const sine = Math.sin(rotationRadians);\n const localCenterX = bodies.localCenterX[index]!;\n const localCenterY = bodies.localCenterY[index]!;\n return publicPose(\n bodies.positionX[index]! - cosine * localCenterX + sine * localCenterY,\n bodies.positionY[index]! - sine * localCenterX - cosine * localCenterY,\n rotationRadians,\n );\n}\n\nfunction copyAabb(bounds: PibblPhysicsAabb2D): PibblPhysicsAabb2D {\n const min = copyFiniteVector2(bounds.min, \"bounds.min\");\n const max = copyFiniteVector2(bounds.max, \"bounds.max\");\n if (min[0] > max[0] || min[1] > max[1]) {\n throw new RangeError(\"bounds.min must not exceed bounds.max.\");\n }\n return Object.freeze({ min, max });\n}\n\nfunction aabbsOverlap(first: PibblPhysicsAabb2D, second: PibblPhysicsAabb2D): boolean {\n return (\n first.min[0] <= second.max[0] &&\n first.max[0] >= second.min[0] &&\n first.min[1] <= second.max[1] &&\n first.max[1] >= second.min[1]\n );\n}\n\nfunction freezeVector(x: number, y: number): PibblPhysicsVector2 {\n return Object.freeze([x, y] as const);\n}\n\nfunction normalizedCapacity(required: number): number {\n let capacity = 1;\n while (capacity < required) capacity *= 2;\n return capacity;\n}\n\nfunction growInt32(source: Int32Array, capacity: number): Int32Array {\n const result = new Int32Array(capacity);\n result.set(source);\n return result;\n}\n\nfunction growUint32(source: Uint32Array, capacity: number): Uint32Array {\n const result = new Uint32Array(capacity);\n result.set(source);\n return result;\n}\n\nfunction growFloat64(source: Float64Array, capacity: number): Float64Array {\n const result = new Float64Array(capacity);\n result.set(source);\n return result;\n}\n\nfunction swapInt32(values: Int32Array, first: number, second: number): void {\n const value = values[first]!;\n values[first] = values[second]!;\n values[second] = value;\n}\n\nfunction swapUint32(values: Uint32Array, first: number, second: number): void {\n const value = values[first]!;\n values[first] = values[second]!;\n values[second] = value;\n}\n\nfunction swapFloat64(values: Float64Array, first: number, second: number): void {\n const value = values[first]!;\n values[first] = values[second]!;\n values[second] = value;\n}\n"],
|
|
5
|
-
"mappings": "AAAA;AAAA,EACE;AAAA,OAMK;AACP,SAAS,mBAAmB,gCAAgC;AAC5D,SAAS,wBAAwB,+BAA+B;AAChE,SAAS,gBAAgB,+BAA+B;AACxD,SAAS,0BAA0B;AACnC,SAAS,qBAAyC;AAYlD,SAAS,+BAA+B;AACxC,SAAS,0BAA0B;AA4B5B,MAAM,wBAAwB;AAAA,EAgBnC,YAA6B,SAAyC;AAAzC;AAC3B,UAAM,W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C;AAC/D,SAAO,OAAO,OAAO,CAAC,GAAG,CAAC,CAAU;AACtC;AAEA,SAAS,mBAAmB,UAA0B;AACpD,MAAI,WAAW;AACf,SAAO,WAAW,SAAU,aAAY;AACxC,SAAO;AACT;AAEA,SAAS,UAAU,QAAoB,UAA8B;AACnE,QAAM,SAAS,IAAI,WAAW,QAAQ;AACtC,SAAO,IAAI,MAAM;AACjB,SAAO;AACT;AAEA,SAAS,WAAW,QAAqB,UAA+B;AACtE,QAAM,SAAS,IAAI,YAAY,QAAQ;AACvC,SAAO,IAAI,MAAM;AACjB,SAAO;AACT;AAEA,SAAS,YAAY,QAAsB,UAAgC;AACzE,QAAM,SAAS,IAAI,aAAa,QAAQ;AACxC,SAAO,IAAI,MAAM;AACjB,SAAO;AACT;AAEA,SAAS,UAAU,QAAoB,OAAe,QAAsB;AAC1E,QAAM,QAAQ,OAAO,KAAK;AAC1B,SAAO,KAAK,IAAI,OAAO,MAAM;AAC7B,SAAO,MAAM,IAAI;AACnB;AAEA,SAAS,WAAW,QAAqB,OAAe,QAAsB;AAC5E,QAAM,QAAQ,OAAO,KAAK;AAC1B,SAAO,KAAK,IAAI,OAAO,MAAM;AAC7B,SAAO,MAAM,IAAI;AACnB;AAEA,SAAS,YAAY,QAAsB,OAAe,QAAsB;AAC9E,QAAM,QAAQ,OAAO,KAAK;AAC1B,SAAO,KAAK,IAAI,OAAO,MAAM;AAC7B,SAAO,MAAM,IAAI;AACnB;",
|
|
4
|
+
"sourcesContent": ["import type { QueryMode, QueryOptions, QueryResult } from '../query-types.js';\nimport {\n boundsOfShape2D,\n type PibblPhysicsAabb2D,\n type PibblPhysicsPose2D,\n type PibblPhysicsRay2D,\n type PibblPhysicsShape2D,\n type PibblPhysicsVector2,\n} from \"../../../2d-geometry.js\";\nimport { copyFiniteVector2, requireNonnegativeNumber } from \"../../shared/validation.js\";\nimport { containsPointInShape2D, overlapPreparedShapes2D } from \"../collision/pairs.js\";\nimport { raycastShape2D, shapeCastAgainstShape2D } from \"../collision/casts.js\";\nimport { RADIANS_TO_DEGREES } from \"../numeric-policy.js\";\nimport { createShape2D, type ShapeRecord2D } from \"../shape-records.js\";\nimport type {\n PibblPhysicsBodyHandle2D,\n PibblPhysicsColliderHandle2D,\n PibblPhysicsCollisionFilter,\n PibblPhysicsQueryHit2D,\n PibblPhysicsQueryMatch2D,\n} from \"../types.js\";\nimport type { DynamicAabbBroadPhase2D } from \"./broad-phase.js\";\nimport { collisionFiltersAllow2D } from \"./ccd.js\";\nimport { COLLIDER_SENSOR_2D } from \"./contact-cache.js\";\nimport type { BodyStore2D, ColliderStore2D } from \"./storage.js\";\n\ninterface HandleIdentity2D {\n readonly index: number;\n readonly generation: number;\n}\n\nexport interface CommittedWorldQueriesOptions2D {\n readonly generation: number;\n readonly bodies: BodyStore2D;\n readonly colliders: ColliderStore2D;\n readonly broadPhase: DynamicAabbBroadPhase2D;\n readonly materializeBody: (index: number, generation: number) => PibblPhysicsBodyHandle2D;\n readonly materializeCollider: (index: number, generation: number) => PibblPhysicsColliderHandle2D;\n readonly resolveBody: (handle: PibblPhysicsBodyHandle2D) => HandleIdentity2D | null;\n readonly resolveCollider: (handle: PibblPhysicsColliderHandle2D) => HandleIdentity2D | null;\n}\n\ninterface PreparedQueryOptions2D {\n readonly mode: QueryMode;\n readonly sensors: \"include\" | \"exclude\" | \"only\";\n readonly collisionFilter: PibblPhysicsCollisionFilter | null;\n readonly excludeBody: HandleIdentity2D | null;\n readonly excludeCollider: HandleIdentity2D | null;\n readonly valid: boolean;\n}\n\nexport class CommittedWorldQueries2D {\n private active = true;\n private candidateProxies: Int32Array;\n private hitColliderIndices: Int32Array;\n private hitColliderGenerations: Uint32Array;\n private hitBodyIndices: Int32Array;\n private hitBodyGenerations: Uint32Array;\n private hitPointX: Float64Array;\n private hitPointY: Float64Array;\n private hitNormalX: Float64Array;\n private hitNormalY: Float64Array;\n private hitDistances: Float64Array;\n private hitTimes: Float64Array;\n private hitCount = 0;\n private readonly shapeShells = new WeakMap<ShapeRecord2D, PibblPhysicsShape2D>();\n\n constructor(private readonly options: CommittedWorldQueriesOptions2D) {\n const capacity = normalizedCapacity(options.broadPhase.proxyCapacity);\n this.candidateProxies = new Int32Array(capacity);\n this.hitColliderIndices = new Int32Array(capacity);\n this.hitColliderGenerations = new Uint32Array(capacity);\n this.hitBodyIndices = new Int32Array(capacity);\n this.hitBodyGenerations = new Uint32Array(capacity);\n this.hitPointX = new Float64Array(capacity);\n this.hitPointY = new Float64Array(capacity);\n this.hitNormalX = new Float64Array(capacity);\n this.hitNormalY = new Float64Array(capacity);\n this.hitDistances = new Float64Array(capacity);\n this.hitTimes = new Float64Array(capacity);\n }\n\n invalidate(): void {\n this.active = false;\n this.hitCount = 0;\n }\n\n raycast<Mode extends QueryMode = \"closest\">(\n worldGeneration: number,\n ray: PibblPhysicsRay2D,\n queryOptions?: QueryOptions<Mode>,\n ): QueryResult<Mode, PibblPhysicsQueryHit2D> {\n const prepared = this.prepareOptions(queryOptions);\n if (!this.isUsable(worldGeneration, prepared)) return emptyResult(prepared.mode);\n const origin = copyFiniteVector2(ray.origin, \"ray.origin\");\n const direction = copyFiniteVector2(ray.direction, \"ray.direction\");\n const directionLength = Math.hypot(direction[0], direction[1]);\n if (directionLength === 0) throw new RangeError(\"ray.direction must be non-zero.\");\n const maxDistance = requireNonnegativeNumber(ray.maxDistance, \"ray.maxDistance\");\n const endX = origin[0] + (direction[0] / directionLength) * maxDistance;\n const endY = origin[1] + (direction[1] / directionLength) * maxDistance;\n this.beginQuery();\n const candidateCount = this.queryCandidates(\n Math.min(origin[0], endX),\n Math.min(origin[1], endY),\n Math.max(origin[0], endX),\n Math.max(origin[1], endY),\n );\n for (let candidate = 0; candidate < candidateCount; candidate += 1) {\n const collider = this.semanticColliderAt(candidate, prepared);\n if (collider === null) continue;\n const hit = raycastShape2D(collider.shape, collider.pose, ray);\n if (hit === null) continue;\n if (prepared.mode === \"any\") return true as QueryResult<Mode, PibblPhysicsQueryHit2D>;\n this.appendHit(collider, hit.point, hit.normal, hit.distance, hit.timeOfImpact);\n }\n return this.finishHits<Mode>(prepared.mode);\n }\n\n shapeCast<Mode extends QueryMode = \"closest\">(\n worldGeneration: number,\n shape: PibblPhysicsShape2D,\n from: PibblPhysicsPose2D,\n translation: PibblPhysicsVector2,\n queryOptions?: QueryOptions<Mode>,\n ): QueryResult<Mode, PibblPhysicsQueryHit2D> {\n const prepared = this.prepareOptions(queryOptions);\n if (!this.isUsable(worldGeneration, prepared)) return emptyResult(prepared.mode);\n const copiedTranslation = copyFiniteVector2(translation, \"translation\");\n const start = boundsOfShape2D(shape, from);\n const end = boundsOfShape2D(shape, {\n position: [from.position[0] + copiedTranslation[0], from.position[1] + copiedTranslation[1]],\n rotationDegrees: from.rotationDegrees,\n });\n this.beginQuery();\n const candidateCount = this.queryCandidates(\n Math.min(start.min[0], end.min[0]),\n Math.min(start.min[1], end.min[1]),\n Math.max(start.max[0], end.max[0]),\n Math.max(start.max[1], end.max[1]),\n );\n for (let candidate = 0; candidate < candidateCount; candidate += 1) {\n const collider = this.semanticColliderAt(candidate, prepared);\n if (collider === null) continue;\n const hit = shapeCastAgainstShape2D(shape, from, copiedTranslation, collider.shape, collider.pose);\n if (hit === null) continue;\n if (prepared.mode === \"any\") return true as QueryResult<Mode, PibblPhysicsQueryHit2D>;\n this.appendHit(collider, hit.point, hit.normal, hit.distance, hit.timeOfImpact);\n }\n return this.finishHits<Mode>(prepared.mode);\n }\n\n overlapShape<Mode extends QueryMode = \"closest\">(\n worldGeneration: number,\n shape: PibblPhysicsShape2D,\n pose: PibblPhysicsPose2D,\n queryOptions?: QueryOptions<Mode>,\n ): QueryResult<Mode, PibblPhysicsQueryMatch2D> {\n const bounds = this.isGenerationLive(worldGeneration) ? boundsOfShape2D(shape, pose) : null;\n return this.runMatchQuery(worldGeneration, bounds, queryOptions, (collider) =>\n overlapPreparedShapes2D(shape, pose, collider.shape, collider.pose),\n );\n }\n\n queryAabb<Mode extends QueryMode = \"closest\">(\n worldGeneration: number,\n bounds: PibblPhysicsAabb2D,\n queryOptions?: QueryOptions<Mode>,\n ): QueryResult<Mode, PibblPhysicsQueryMatch2D> {\n if (!this.isGenerationLive(worldGeneration)) {\n return emptyResult(modeOf(queryOptions));\n }\n const copied = copyAabb(bounds);\n return this.runMatchQuery(worldGeneration, copied, queryOptions, (collider) => {\n const colliderBounds = boundsOfShape2D(collider.shape, collider.pose);\n return aabbsOverlap(copied, colliderBounds);\n });\n }\n\n queryPoint<Mode extends QueryMode = \"closest\">(\n worldGeneration: number,\n point: PibblPhysicsVector2,\n queryOptions?: QueryOptions<Mode>,\n ): QueryResult<Mode, PibblPhysicsQueryMatch2D> {\n if (!this.isGenerationLive(worldGeneration)) {\n return emptyResult(modeOf(queryOptions));\n }\n const copied = copyFiniteVector2(point, \"point\");\n const bounds = Object.freeze({ min: copied, max: copied });\n return this.runMatchQuery(worldGeneration, bounds, queryOptions, (collider) =>\n containsPointInShape2D(collider.shape, collider.pose, copied),\n );\n }\n\n private runMatchQuery<Mode extends QueryMode>(\n worldGeneration: number,\n bounds: PibblPhysicsAabb2D | null,\n queryOptions: QueryOptions<Mode> | undefined,\n matches: (collider: SemanticCollider2D) => boolean,\n ): QueryResult<Mode, PibblPhysicsQueryMatch2D> {\n const prepared = this.prepareOptions(queryOptions);\n if (bounds === null || !this.isUsable(worldGeneration, prepared)) {\n return emptyResult(prepared.mode);\n }\n this.beginQuery();\n const candidateCount = this.queryCandidates(bounds.min[0], bounds.min[1], bounds.max[0], bounds.max[1]);\n for (let candidate = 0; candidate < candidateCount; candidate += 1) {\n const collider = this.semanticColliderAt(candidate, prepared);\n if (collider === null || !matches(collider)) continue;\n if (prepared.mode === \"any\") {\n return true as QueryResult<Mode, PibblPhysicsQueryMatch2D>;\n }\n this.appendMatch(collider);\n }\n return this.finishMatches<Mode>(prepared.mode);\n }\n\n private prepareOptions<Mode extends QueryMode>(\n queryOptions: QueryOptions<Mode> | undefined,\n ): PreparedQueryOptions2D {\n const mode = modeOf(queryOptions);\n const sensors = queryOptions?.sensors ?? \"include\";\n if (sensors !== \"include\" && sensors !== \"exclude\" && sensors !== \"only\") {\n throw new RangeError(\"query sensors must be include, exclude, or only.\");\n }\n const excludeBody =\n queryOptions?.excludeBody === undefined ? null : this.options.resolveBody(queryOptions.excludeBody);\n const excludeCollider =\n queryOptions?.excludeCollider === undefined ? null : this.options.resolveCollider(queryOptions.excludeCollider);\n const validBody =\n queryOptions?.excludeBody === undefined ||\n (excludeBody !== null && this.options.bodies.has(excludeBody.index, excludeBody.generation));\n const validCollider =\n queryOptions?.excludeCollider === undefined ||\n (excludeCollider !== null && this.options.colliders.has(excludeCollider.index, excludeCollider.generation));\n return {\n mode,\n sensors,\n collisionFilter: queryOptions?.collisionFilter ?? null,\n excludeBody,\n excludeCollider,\n valid: validBody && validCollider,\n };\n }\n\n private isUsable(worldGeneration: number, prepared: PreparedQueryOptions2D): boolean {\n return this.isGenerationLive(worldGeneration) && prepared.valid;\n }\n\n private isGenerationLive(worldGeneration: number): boolean {\n return this.active && worldGeneration === this.options.generation;\n }\n\n private beginQuery(): void {\n this.hitCount = 0;\n this.ensureCapacity(this.options.broadPhase.proxyCapacity);\n }\n\n private queryCandidates(minX: number, minY: number, maxX: number, maxY: number): number {\n return this.options.broadPhase.queryAabbInto(\n minX,\n minY,\n maxX,\n maxY,\n this.candidateProxies,\n 0,\n this.candidateProxies.length,\n );\n }\n\n private semanticColliderAt(candidate: number, prepared: PreparedQueryOptions2D): SemanticCollider2D | null {\n const proxy = this.candidateProxies[candidate]!;\n const colliderIndex = this.options.broadPhase.proxyColliderIndices[proxy]!;\n const colliderGeneration = this.options.broadPhase.proxyColliderGenerations[proxy]!;\n const { colliders, bodies } = this.options;\n if (!colliders.has(colliderIndex, colliderGeneration)) return null;\n const bodyIndex = colliders.bodyIndices[colliderIndex]!;\n const bodyGeneration = colliders.bodyGenerations[colliderIndex]!;\n if (!bodies.has(bodyIndex, bodyGeneration)) return null;\n if (sameIdentity(prepared.excludeBody, bodyIndex, bodyGeneration)) return null;\n if (sameIdentity(prepared.excludeCollider, colliderIndex, colliderGeneration)) return null;\n const sensor = (colliders.flags[colliderIndex]! & COLLIDER_SENSOR_2D) !== 0;\n if (prepared.sensors === \"exclude\" && sensor) return null;\n if (prepared.sensors === \"only\" && !sensor) return null;\n if (\n prepared.collisionFilter !== null &&\n !collisionFiltersAllow2D(prepared.collisionFilter, colliders.filters[colliderIndex])\n )\n return null;\n const record = colliders.shapes[colliderIndex];\n if (record === null) return null;\n return {\n colliderIndex,\n colliderGeneration,\n bodyIndex,\n bodyGeneration,\n shape: this.shapeShell(record),\n pose: publicBodyOriginPose(bodies, bodyIndex),\n };\n }\n\n private appendHit(\n collider: SemanticCollider2D,\n point: PibblPhysicsVector2,\n normal: PibblPhysicsVector2,\n distance: number,\n time: number,\n ): void {\n const target = this.hitCount;\n this.writeIdentity(target, collider);\n this.hitPointX[target] = point[0];\n this.hitPointY[target] = point[1];\n this.hitNormalX[target] = normal[0];\n this.hitNormalY[target] = normal[1];\n this.hitDistances[target] = distance;\n this.hitTimes[target] = time;\n this.hitCount += 1;\n }\n\n private appendMatch(collider: SemanticCollider2D): void {\n this.writeIdentity(this.hitCount, collider);\n this.hitCount += 1;\n }\n\n private writeIdentity(target: number, collider: SemanticCollider2D): void {\n this.hitColliderIndices[target] = collider.colliderIndex;\n this.hitColliderGenerations[target] = collider.colliderGeneration;\n this.hitBodyIndices[target] = collider.bodyIndex;\n this.hitBodyGenerations[target] = collider.bodyGeneration;\n }\n\n private finishHits<Mode extends QueryMode>(\n mode: QueryMode,\n ): QueryResult<Mode, PibblPhysicsQueryHit2D> {\n this.sortHits(true);\n if (mode === \"any\") {\n return false as QueryResult<Mode, PibblPhysicsQueryHit2D>;\n }\n if (mode === \"closest\") {\n return (this.hitCount === 0 ? null : this.materializeHit(0)) as QueryResult<\n Mode,\n PibblPhysicsQueryHit2D\n >;\n }\n const results: PibblPhysicsQueryHit2D[] = [];\n for (let index = 0; index < this.hitCount; index += 1) {\n results.push(this.materializeHit(index));\n }\n return Object.freeze(results) as QueryResult<Mode, PibblPhysicsQueryHit2D>;\n }\n\n private finishMatches<Mode extends QueryMode>(\n mode: QueryMode,\n ): QueryResult<Mode, PibblPhysicsQueryMatch2D> {\n this.sortHits(false);\n if (mode === \"any\") {\n return false as QueryResult<Mode, PibblPhysicsQueryMatch2D>;\n }\n if (mode === \"closest\") {\n return (this.hitCount === 0 ? null : this.materializeMatch(0)) as QueryResult<\n Mode,\n PibblPhysicsQueryMatch2D\n >;\n }\n const results: PibblPhysicsQueryMatch2D[] = [];\n for (let index = 0; index < this.hitCount; index += 1) {\n results.push(this.materializeMatch(index));\n }\n return Object.freeze(results) as QueryResult<Mode, PibblPhysicsQueryMatch2D>;\n }\n\n private materializeHit(index: number): PibblPhysicsQueryHit2D {\n return Object.freeze({\n ...this.materializeMatch(index),\n point: freezeVector(this.hitPointX[index]!, this.hitPointY[index]!),\n normal: freezeVector(this.hitNormalX[index]!, this.hitNormalY[index]!),\n distance: this.hitDistances[index]!,\n timeOfImpact: this.hitTimes[index]!,\n });\n }\n\n private materializeMatch(index: number): PibblPhysicsQueryMatch2D {\n const bodyIndex = this.hitBodyIndices[index]!;\n const bodyGeneration = this.hitBodyGenerations[index]!;\n const colliderIndex = this.hitColliderIndices[index]!;\n const colliderGeneration = this.hitColliderGenerations[index]!;\n return Object.freeze({\n body: this.options.materializeBody(bodyIndex, bodyGeneration),\n collider: this.options.materializeCollider(colliderIndex, colliderGeneration),\n bodyGeneration,\n colliderGeneration,\n tag: this.options.colliders.tags[colliderIndex],\n });\n }\n\n private sortHits(withDistance: boolean): void {\n for (let index = 1; index < this.hitCount; index += 1) {\n let current = index;\n while (current > 0 && this.compareHits(current, current - 1, withDistance) < 0) {\n this.swapHits(current, current - 1, withDistance);\n current -= 1;\n }\n }\n }\n\n private compareHits(first: number, second: number, withDistance: boolean): number {\n if (withDistance) {\n const time = this.hitTimes[first]! - this.hitTimes[second]!;\n if (time !== 0) return time;\n const distance = this.hitDistances[first]! - this.hitDistances[second]!;\n if (distance !== 0) return distance;\n }\n return (\n this.hitColliderIndices[first]! - this.hitColliderIndices[second]! ||\n this.hitColliderGenerations[first]! - this.hitColliderGenerations[second]!\n );\n }\n\n private swapHits(first: number, second: number, withDistance: boolean): void {\n swapInt32(this.hitColliderIndices, first, second);\n swapUint32(this.hitColliderGenerations, first, second);\n swapInt32(this.hitBodyIndices, first, second);\n swapUint32(this.hitBodyGenerations, first, second);\n if (!withDistance) return;\n swapFloat64(this.hitPointX, first, second);\n swapFloat64(this.hitPointY, first, second);\n swapFloat64(this.hitNormalX, first, second);\n swapFloat64(this.hitNormalY, first, second);\n swapFloat64(this.hitDistances, first, second);\n swapFloat64(this.hitTimes, first, second);\n }\n\n private shapeShell(record: ShapeRecord2D): PibblPhysicsShape2D {\n let shell = this.shapeShells.get(record);\n if (shell === undefined) {\n shell = createShape2D(record);\n this.shapeShells.set(record, shell);\n }\n return shell;\n }\n\n private ensureCapacity(required: number): void {\n if (required <= this.candidateProxies.length) return;\n const capacity = normalizedCapacity(required);\n this.candidateProxies = growInt32(this.candidateProxies, capacity);\n this.hitColliderIndices = growInt32(this.hitColliderIndices, capacity);\n this.hitColliderGenerations = growUint32(this.hitColliderGenerations, capacity);\n this.hitBodyIndices = growInt32(this.hitBodyIndices, capacity);\n this.hitBodyGenerations = growUint32(this.hitBodyGenerations, capacity);\n this.hitPointX = growFloat64(this.hitPointX, capacity);\n this.hitPointY = growFloat64(this.hitPointY, capacity);\n this.hitNormalX = growFloat64(this.hitNormalX, capacity);\n this.hitNormalY = growFloat64(this.hitNormalY, capacity);\n this.hitDistances = growFloat64(this.hitDistances, capacity);\n this.hitTimes = growFloat64(this.hitTimes, capacity);\n }\n}\n\ninterface SemanticCollider2D {\n readonly colliderIndex: number;\n readonly colliderGeneration: number;\n readonly bodyIndex: number;\n readonly bodyGeneration: number;\n readonly shape: PibblPhysicsShape2D;\n readonly pose: PibblPhysicsPose2D;\n}\n\nfunction modeOf<Mode extends QueryMode>(\n options: QueryOptions<Mode> | undefined,\n): QueryMode {\n const mode = options?.mode ?? \"closest\";\n if (mode !== \"closest\" && mode !== \"any\" && mode !== \"all\") {\n throw new RangeError(\"query mode must be closest, any, or all.\");\n }\n return mode;\n}\n\nfunction emptyResult<Mode extends QueryMode, Result>(\n mode: QueryMode,\n): QueryResult<Mode, Result> {\n return (mode === \"any\" ? false : mode === \"all\" ? Object.freeze([]) : null) as QueryResult<Mode, Result>;\n}\n\nfunction sameIdentity(identity: HandleIdentity2D | null, index: number, generation: number): boolean {\n return identity !== null && identity.index === index && identity.generation === generation;\n}\n\nfunction publicPose(x: number, y: number, rotationRadians: number): PibblPhysicsPose2D {\n return {\n position: [x, y],\n rotationDegrees: rotationRadians * RADIANS_TO_DEGREES,\n };\n}\n\nfunction publicBodyOriginPose(\n bodies: BodyStore2D,\n index: number,\n): PibblPhysicsPose2D {\n const rotationRadians = bodies.rotationRadians[index]!;\n const cosine = Math.cos(rotationRadians);\n const sine = Math.sin(rotationRadians);\n const localCenterX = bodies.localCenterX[index]!;\n const localCenterY = bodies.localCenterY[index]!;\n return publicPose(\n bodies.positionX[index]! - cosine * localCenterX + sine * localCenterY,\n bodies.positionY[index]! - sine * localCenterX - cosine * localCenterY,\n rotationRadians,\n );\n}\n\nfunction copyAabb(bounds: PibblPhysicsAabb2D): PibblPhysicsAabb2D {\n const min = copyFiniteVector2(bounds.min, \"bounds.min\");\n const max = copyFiniteVector2(bounds.max, \"bounds.max\");\n if (min[0] > max[0] || min[1] > max[1]) {\n throw new RangeError(\"bounds.min must not exceed bounds.max.\");\n }\n return Object.freeze({ min, max });\n}\n\nfunction aabbsOverlap(first: PibblPhysicsAabb2D, second: PibblPhysicsAabb2D): boolean {\n return (\n first.min[0] <= second.max[0] &&\n first.max[0] >= second.min[0] &&\n first.min[1] <= second.max[1] &&\n first.max[1] >= second.min[1]\n );\n}\n\nfunction freezeVector(x: number, y: number): PibblPhysicsVector2 {\n return Object.freeze([x, y] as const);\n}\n\nfunction normalizedCapacity(required: number): number {\n let capacity = 1;\n while (capacity < required) capacity *= 2;\n return capacity;\n}\n\nfunction growInt32(source: Int32Array, capacity: number): Int32Array {\n const result = new Int32Array(capacity);\n result.set(source);\n return result;\n}\n\nfunction growUint32(source: Uint32Array, capacity: number): Uint32Array {\n const result = new Uint32Array(capacity);\n result.set(source);\n return result;\n}\n\nfunction growFloat64(source: Float64Array, capacity: number): Float64Array {\n const result = new Float64Array(capacity);\n result.set(source);\n return result;\n}\n\nfunction swapInt32(values: Int32Array, first: number, second: number): void {\n const value = values[first]!;\n values[first] = values[second]!;\n values[second] = value;\n}\n\nfunction swapUint32(values: Uint32Array, first: number, second: number): void {\n const value = values[first]!;\n values[first] = values[second]!;\n values[second] = value;\n}\n\nfunction swapFloat64(values: Float64Array, first: number, second: number): void {\n const value = values[first]!;\n values[first] = values[second]!;\n values[second] = value;\n}\n"],
|
|
5
|
+
"mappings": "AACA;AAAA,EACE;AAAA,OAMK;AACP,SAAS,mBAAmB,gCAAgC;AAC5D,SAAS,wBAAwB,+BAA+B;AAChE,SAAS,gBAAgB,+BAA+B;AACxD,SAAS,0BAA0B;AACnC,SAAS,qBAAyC;AASlD,SAAS,+BAA+B;AACxC,SAAS,0BAA0B;AA4B5B,MAAM,wBAAwB;AAAA,EAgBnC,YAA6B,SAAyC;AAAzC;AAC3B,UAAM,WAAW,mBAAmB,QAAQ,WAAW,aAAa;AACpE,SAAK,mBAAmB,IAAI,WAAW,QAAQ;AAC/C,SAAK,qBAAqB,IAAI,WAAW,QAAQ;AACjD,SAAK,yBAAyB,IAAI,YAAY,QAAQ;AACtD,SAAK,iBAAiB,IAAI,WAAW,QAAQ;AAC7C,SAAK,qBAAqB,IAAI,YAAY,QAAQ;AAClD,SAAK,YAAY,IAAI,aAAa,QAAQ;AAC1C,SAAK,YAAY,IAAI,aAAa,QAAQ;AAC1C,SAAK,aAAa,IAAI,aAAa,QAAQ;AAC3C,S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AAM;AACjB,SAAO;AACT;AAEA,SAAS,YAAY,QAAsB,UAAgC;AACzE,QAAM,SAAS,IAAI,aAAa,QAAQ;AACxC,SAAO,IAAI,MAAM;AACjB,SAAO;AACT;AAEA,SAAS,UAAU,QAAoB,OAAe,QAAsB;AAC1E,QAAM,QAAQ,OAAO,KAAK;AAC1B,SAAO,KAAK,IAAI,OAAO,MAAM;AAC7B,SAAO,MAAM,IAAI;AACnB;AAEA,SAAS,WAAW,QAAqB,OAAe,QAAsB;AAC5E,QAAM,QAAQ,OAAO,KAAK;AAC1B,SAAO,KAAK,IAAI,OAAO,MAAM;AAC7B,SAAO,MAAM,IAAI;AACnB;AAEA,SAAS,YAAY,QAAsB,OAAe,QAAsB;AAC9E,QAAM,QAAQ,OAAO,KAAK;AAC1B,SAAO,KAAK,IAAI,OAAO,MAAM;AAC7B,SAAO,MAAM,IAAI;AACnB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { SpriteSheetFormat } from '../model.js';
|
|
2
|
+
/** Import Aseprite JSON hash or array exports, including frame tags and millisecond timing. See {@link SpriteSheetFormat}.
|
|
3
|
+
* @returns An explicit atlas metadata adapter.
|
|
4
|
+
*/
|
|
5
|
+
export declare function aseprite(): SpriteSheetFormat;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { SpriteSheetFormat } from '../model.js';
|
|
2
|
+
/** Import TexturePacker JSON hash/array rectangles with clockwise packed rotation and trim offsets. See {@link SpriteSheetFormat}.
|
|
3
|
+
* @returns An explicit atlas metadata adapter.
|
|
4
|
+
*/
|
|
5
|
+
export declare function texturePacker(): SpriteSheetFormat;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { Sprite } from './sprite.js';
|
|
2
|
+
export type { SpriteProps, SpriteStyle } from './sprite.js';
|
|
3
|
+
export { loadSpriteSheet } from './loader.js';
|
|
4
|
+
export type { SpriteSheet, SpriteGrid } from './loader.js';
|
|
5
|
+
export { defineSpriteAnimation } from './model.js';
|
|
6
|
+
export type { SpriteFrame, SpriteRectangle, SpriteFrameData, SpriteAnimationFrameData, SpriteSheetData, SpriteSheetFormat } from './model.js';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type SpriteFrame, type SpriteSheetFormat } from './model.js';
|
|
2
|
+
import type { PibblAnimationDefinition } from '../../lib/animation/types.js';
|
|
3
|
+
/** Shared decoded atlas and immutable frames/clips. Dispose after all consumers unmount. See {@link SpriteFrame}. */
|
|
4
|
+
export interface SpriteSheet {
|
|
5
|
+
/** Frames indexed by atlas name or numeric grid index. */ readonly frames: Readonly<Record<string | number, SpriteFrame>>;
|
|
6
|
+
/** Named, seekable animation definitions from the atlas. */ readonly animations: Readonly<Record<string, PibblAnimationDefinition<SpriteFrame>>>;
|
|
7
|
+
/** Release decoded images; unmount every consumer before calling. */ readonly dispose: () => void;
|
|
8
|
+
}
|
|
9
|
+
/** Dimensions of a regular grid, in image pixels. See {@link SpriteFrame}. */
|
|
10
|
+
export interface SpriteGrid {
|
|
11
|
+
readonly frameWidth: number; /** Positive cell height in pixels. */
|
|
12
|
+
readonly frameHeight: number; /** Outer border width in pixels; defaults to zero. */
|
|
13
|
+
readonly margin?: number; /** Gap between cells in pixels; defaults to zero. */
|
|
14
|
+
readonly spacing?: number;
|
|
15
|
+
}
|
|
16
|
+
/** Load a grid image or metadata through an explicitly supplied import adapter. See {@link SpriteFrame}.
|
|
17
|
+
* @param url - Grid image URL or atlas metadata URL.
|
|
18
|
+
* @param options - Grid dimensions or an explicit metadata format adapter.
|
|
19
|
+
* @returns A decoded sprite sheet with explicit disposal ownership.
|
|
20
|
+
*/
|
|
21
|
+
export declare function loadSpriteSheet(url: string, options: {
|
|
22
|
+
readonly grid: SpriteGrid;
|
|
23
|
+
} | {
|
|
24
|
+
readonly format: SpriteSheetFormat;
|
|
25
|
+
}): Promise<SpriteSheet>;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { PibblAnimationDefinition } from '../../lib/animation/types.js';
|
|
2
|
+
/** Pixel rectangle within an atlas page or original frame. See {@link SpriteFrame}. */
|
|
3
|
+
export interface SpriteRectangle {
|
|
4
|
+
readonly x: number; /** Vertical pixel offset. */
|
|
5
|
+
readonly y: number; /** Width in pixels. */
|
|
6
|
+
readonly width: number; /** Height in pixels. */
|
|
7
|
+
readonly height: number;
|
|
8
|
+
}
|
|
9
|
+
/** Normalized frame information returned by a format adapter. See {@link SpriteFrame}. */
|
|
10
|
+
export interface SpriteFrameData {
|
|
11
|
+
/** Unique frame name in this sheet. */ readonly name: string;
|
|
12
|
+
/** Zero-based atlas page index; defaults to zero. */ readonly page?: number;
|
|
13
|
+
/** Packed rectangle within the atlas page. */ readonly rect: SpriteRectangle;
|
|
14
|
+
/** Original frame dimensions before trimming. */ readonly sourceSize?: Readonly<{
|
|
15
|
+
width: number; /** Height in pixels. */
|
|
16
|
+
height: number;
|
|
17
|
+
}>;
|
|
18
|
+
/** Trimmed content offset within the original frame. */ readonly trim?: Readonly<{
|
|
19
|
+
x: number; /** Vertical pixel offset. */
|
|
20
|
+
y: number;
|
|
21
|
+
}>;
|
|
22
|
+
/** Whether the packed rectangle is rotated clockwise. */ readonly rotated?: boolean;
|
|
23
|
+
}
|
|
24
|
+
/** One normalized timed frame reference. Durations are milliseconds. See {@link SpriteFrame}. */
|
|
25
|
+
export interface SpriteAnimationFrameData {
|
|
26
|
+
readonly frame: string; /** Positive duration of the animation step in milliseconds. */
|
|
27
|
+
readonly duration: number;
|
|
28
|
+
}
|
|
29
|
+
/** Adapter result. Image paths resolve relative to the metadata URL. See {@link SpriteFrame}. */
|
|
30
|
+
export interface SpriteSheetData {
|
|
31
|
+
/** Atlas image URLs, relative to the metadata URL. */ readonly images: readonly string[];
|
|
32
|
+
/** Normalized frame records for this sheet. */ readonly frames: readonly SpriteFrameData[];
|
|
33
|
+
/** Named sequences of timed frame references. */ readonly animations?: Readonly<Record<string, readonly SpriteAnimationFrameData[]>>;
|
|
34
|
+
}
|
|
35
|
+
/** Import adapter; loaders invoke this directly without a format registry. See {@link SpriteFrame}. */
|
|
36
|
+
export interface SpriteSheetFormat {
|
|
37
|
+
readonly parse: (data: unknown) => SpriteSheetData;
|
|
38
|
+
}
|
|
39
|
+
export interface FrameRecord extends SpriteFrameData {
|
|
40
|
+
readonly image: HTMLImageElement;
|
|
41
|
+
readonly owner: {
|
|
42
|
+
disposed: boolean;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/** Immutable atlas frame. Obtain frames from loadSpriteSheet; images belong to the sheet. See {@link SpriteFrame}. */
|
|
46
|
+
export declare class SpriteFrame {
|
|
47
|
+
private readonly identity;
|
|
48
|
+
/** Original logical frame width, before transparent borders were trimmed.
|
|
49
|
+
* @returns Width in logical pixels.
|
|
50
|
+
*/
|
|
51
|
+
get width(): number;
|
|
52
|
+
/** Original logical frame height, before transparent borders were trimmed.
|
|
53
|
+
* @returns Height in logical pixels.
|
|
54
|
+
*/
|
|
55
|
+
get height(): number;
|
|
56
|
+
/** Stable name supplied by the atlas or numeric grid index.
|
|
57
|
+
* @returns The frame name.
|
|
58
|
+
*/
|
|
59
|
+
get name(): string;
|
|
60
|
+
}
|
|
61
|
+
export declare function makeFrame(record: FrameRecord): SpriteFrame;
|
|
62
|
+
export declare function frameRecord(frame: SpriteFrame): FrameRecord;
|
|
63
|
+
/** Author a finite discrete animation using FPS or explicit positive millisecond durations. See {@link SpriteFrame}.
|
|
64
|
+
* @param options - Frames with a shared FPS or individual millisecond durations.
|
|
65
|
+
* @returns A seekable discrete animation definition.
|
|
66
|
+
*/
|
|
67
|
+
export declare function defineSpriteAnimation(options: {
|
|
68
|
+
readonly frames: readonly SpriteFrame[];
|
|
69
|
+
readonly fps: number;
|
|
70
|
+
} | {
|
|
71
|
+
readonly frames: readonly Readonly<{
|
|
72
|
+
frame: SpriteFrame;
|
|
73
|
+
duration: number;
|
|
74
|
+
}>[];
|
|
75
|
+
}): PibblAnimationDefinition<SpriteFrame>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ImageProps } from '../../lib/components/img.js';
|
|
2
|
+
import type { SystemStyle } from '../../lib/types.js';
|
|
3
|
+
import { type SpriteFrame } from './model.js';
|
|
4
|
+
/** Drawing inputs; frame also accepts a signal through Pibbl's declared primitive inputs. See {@link SpriteFrame}. */
|
|
5
|
+
export interface SpriteProps extends ImageProps {
|
|
6
|
+
/** Atlas frame to draw; its sheet must remain undisposed. */ readonly frame: SpriteFrame;
|
|
7
|
+
/** Image interpolation; defaults to linear. */ readonly sampling?: 'nearest' | 'linear';
|
|
8
|
+
/** Normalized origin within the original frame, defaulting to the top-left. */ readonly anchor?: Readonly<{
|
|
9
|
+
x: number; /** Vertical anchor fraction. */
|
|
10
|
+
y: number;
|
|
11
|
+
}>;
|
|
12
|
+
/** Mirror the frame horizontally. */ readonly flipX?: boolean;
|
|
13
|
+
/** Mirror the frame vertically. */ readonly flipY?: boolean;
|
|
14
|
+
}
|
|
15
|
+
/** Logical size overrides; omitted dimensions use the original untrimmed frame size. See {@link SpriteFrame}. */
|
|
16
|
+
export interface SpriteStyle extends SystemStyle {
|
|
17
|
+
readonly width?: number; /** Logical height; defaults to the original frame height. */
|
|
18
|
+
readonly height?: number; /** Opacity multiplier applied to the frame. */
|
|
19
|
+
readonly opacity?: number;
|
|
20
|
+
}
|
|
21
|
+
/** Draw a shared atlas frame, preserving its logical geometry across frame changes. See {@link SpriteFrame}. */
|
|
22
|
+
export declare const Sprite: import("@pibbl/core").PibblPrimitiveComponent<SpriteProps, import("@pibbl/core").PrimitiveInput<SpriteProps, SpriteStyle>>;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export
|
|
1
|
+
export { LinearScale } from "./lib/linear-scale-component.js";
|
|
2
|
+
export { BarScale } from "./lib/bar-scale.js";
|
|
3
|
+
export { UTCScale } from "./lib/utc-scale-component.js";
|
|
4
|
+
export { useLinearScale } from "./lib/use-linear-scale.js";
|
|
5
|
+
export { useBarScale } from "./lib/use-bar-scale.js";
|
|
6
|
+
export { useUTCScale } from "./lib/use-utc-scale.js";
|
|
7
|
+
export type { ScaleId, LinearDomain, BandCategory, BandDomain, BarScaleProps, BandScaleRange, ResolvedBandScale, ScaleRange, ScaleLayoutStyle, LinearScaleProps, ResolvedLinearScale, ResolvedScale, } from "./lib/types.js";
|
|
4
8
|
export { Axis } from "./lib/axis.js";
|
|
5
9
|
export { LineSeries } from "./lib/line-series.js";
|
|
6
10
|
export { ScaleAdjust } from "./lib/scale-adjust.js";
|
|
@@ -26,3 +30,24 @@ export { pieSlices } from "./lib/pie-slices.js";
|
|
|
26
30
|
export type { PieOptions, PieSliceGeometry } from "./lib/pie-slices.js";
|
|
27
31
|
export { PieLayout, PieSlice, PieLabel } from "./lib/pie-layout.js";
|
|
28
32
|
export type { PieLayoutProps, PieLayoutStyle, PieLayoutSlice, PieLabelPlacement, PieLabelLayout, PieSliceProps, PieSliceStyle, PieLabelProps, PieLabelStyle } from "./lib/pie-types.js";
|
|
33
|
+
export { extent, niceUTCDomain } from "./lib/utc-scale.js";
|
|
34
|
+
export type { NumericDomain, UtcDomain, UTCScaleProps, ResolvedUtcScale, ResolvedContinuousScale } from "./lib/types.js";
|
|
35
|
+
export { linearTicks, niceLinearDomain, formatNumber } from "./lib/numeric-ticks.js";
|
|
36
|
+
export type { LinearTickOptions, NumberFormatOptions } from "./lib/numeric-ticks.js";
|
|
37
|
+
export { utcTickLabels } from "./lib/utc-labels.js";
|
|
38
|
+
export type { UTCTickLabelOptions } from "./lib/utc-labels.js";
|
|
39
|
+
export { LogScale } from "./lib/log-scale-component.js";
|
|
40
|
+
export { useLogScale } from "./lib/use-log-scale.js";
|
|
41
|
+
export type { LogScaleProps, ResolvedLogScale } from "./lib/types.js";
|
|
42
|
+
export { SymlogScale } from "./lib/symlog-scale-component.js";
|
|
43
|
+
export { useSymlogScale } from "./lib/use-symlog-scale.js";
|
|
44
|
+
export type { SymlogScaleProps, ResolvedSymlogScale } from "./lib/types.js";
|
|
45
|
+
export { PointScale } from "./lib/point-scale-component.js";
|
|
46
|
+
export { usePointScale } from "./lib/use-point-scale.js";
|
|
47
|
+
export type { PointScaleProps, ResolvedPointScale } from "./lib/types.js";
|
|
48
|
+
export { GridLines, ReferenceLine } from "./lib/chart-lines.js";
|
|
49
|
+
export type { ChartLineProps, GridLinesProps, ReferenceLineProps } from "./lib/chart-lines.js";
|
|
50
|
+
export { ReferenceBand } from "./lib/reference-band.js";
|
|
51
|
+
export type { ReferenceBandProps } from "./lib/reference-band.js";
|
|
52
|
+
export { AxisTitle } from "./lib/axis-title.js";
|
|
53
|
+
export type { AxisTitleProps } from "./lib/axis-title.js";
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { LinearScale } from "./lib/linear-scale-component.js";
|
|
2
|
+
import { BarScale } from "./lib/bar-scale.js";
|
|
3
|
+
import { UTCScale } from "./lib/utc-scale-component.js";
|
|
4
|
+
import { useLinearScale } from "./lib/use-linear-scale.js";
|
|
5
|
+
import { useBarScale } from "./lib/use-bar-scale.js";
|
|
6
|
+
import { useUTCScale } from "./lib/use-utc-scale.js";
|
|
3
7
|
import { Axis } from "./lib/axis.js";
|
|
4
8
|
import { LineSeries } from "./lib/line-series.js";
|
|
5
9
|
import { ScaleAdjust } from "./lib/scale-adjust.js";
|
|
@@ -18,28 +22,60 @@ import { AnchoredLayout } from "./lib/anchored-layout.js";
|
|
|
18
22
|
import { BarSeries } from "./lib/bar-series.js";
|
|
19
23
|
import { pieSlices } from "./lib/pie-slices.js";
|
|
20
24
|
import { PieLayout, PieSlice, PieLabel } from "./lib/pie-layout.js";
|
|
25
|
+
import { extent, niceUTCDomain } from "./lib/utc-scale.js";
|
|
26
|
+
import { linearTicks, niceLinearDomain, formatNumber } from "./lib/numeric-ticks.js";
|
|
27
|
+
import { utcTickLabels } from "./lib/utc-labels.js";
|
|
28
|
+
import { LogScale } from "./lib/log-scale-component.js";
|
|
29
|
+
import { useLogScale } from "./lib/use-log-scale.js";
|
|
30
|
+
import { SymlogScale } from "./lib/symlog-scale-component.js";
|
|
31
|
+
import { useSymlogScale } from "./lib/use-symlog-scale.js";
|
|
32
|
+
import { PointScale } from "./lib/point-scale-component.js";
|
|
33
|
+
import { usePointScale } from "./lib/use-point-scale.js";
|
|
34
|
+
import { GridLines, ReferenceLine } from "./lib/chart-lines.js";
|
|
35
|
+
import { ReferenceBand } from "./lib/reference-band.js";
|
|
36
|
+
import { AxisTitle } from "./lib/axis-title.js";
|
|
21
37
|
export {
|
|
22
38
|
AnchoredLayout,
|
|
23
39
|
Axis,
|
|
40
|
+
AxisTitle,
|
|
41
|
+
BarScale,
|
|
24
42
|
BarSeries,
|
|
43
|
+
GridLines,
|
|
25
44
|
HoverCard,
|
|
26
45
|
HoverData,
|
|
27
46
|
LineSeries,
|
|
47
|
+
LinearScale,
|
|
48
|
+
LogScale,
|
|
28
49
|
PieLabel,
|
|
29
50
|
PieLayout,
|
|
30
51
|
PieSlice,
|
|
31
52
|
PlotSeries,
|
|
53
|
+
PointScale,
|
|
32
54
|
PointSeries,
|
|
33
|
-
|
|
55
|
+
ReferenceBand,
|
|
56
|
+
ReferenceLine,
|
|
34
57
|
ScaleAdjust,
|
|
58
|
+
SymlogScale,
|
|
59
|
+
UTCScale,
|
|
35
60
|
closestPoint,
|
|
36
61
|
closestX,
|
|
37
62
|
defineSeries,
|
|
63
|
+
extent,
|
|
64
|
+
formatNumber,
|
|
38
65
|
interpolateX,
|
|
39
66
|
linearInterpolation,
|
|
67
|
+
linearTicks,
|
|
40
68
|
nearestDomainValue,
|
|
41
69
|
nearestPoint,
|
|
70
|
+
niceLinearDomain,
|
|
71
|
+
niceUTCDomain,
|
|
42
72
|
pieSlices,
|
|
43
|
-
|
|
73
|
+
useBarScale,
|
|
74
|
+
useLinearScale,
|
|
75
|
+
useLogScale,
|
|
76
|
+
usePointScale,
|
|
77
|
+
useSymlogScale,
|
|
78
|
+
useUTCScale,
|
|
79
|
+
utcTickLabels
|
|
44
80
|
};
|
|
45
81
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/features/viz/index.ts"],
|
|
4
|
-
"sourcesContent": ["export {
|
|
5
|
-
"mappings": "AAAA,SAAS,
|
|
4
|
+
"sourcesContent": ["export { LinearScale } from \"./lib/linear-scale-component.js\";\nexport { BarScale } from \"./lib/bar-scale.js\";\nexport { UTCScale } from \"./lib/utc-scale-component.js\";\nexport { useLinearScale } from \"./lib/use-linear-scale.js\";\nexport { useBarScale } from \"./lib/use-bar-scale.js\";\nexport { useUTCScale } from \"./lib/use-utc-scale.js\";\nexport type {\n ScaleId,\n LinearDomain,\n BandCategory,\n BandDomain,\n BarScaleProps,\n BandScaleRange,\n ResolvedBandScale,\n ScaleRange,\n ScaleLayoutStyle,\n LinearScaleProps,\n ResolvedLinearScale,\n ResolvedScale,\n} from \"./lib/types.js\";\nexport { Axis } from \"./lib/axis.js\";\nexport { LineSeries } from \"./lib/line-series.js\";\nexport { ScaleAdjust } from \"./lib/scale-adjust.js\";\nexport type {\n AxisStyle,\n AxisProps,\n LineCoordinate,\n LineAccessor,\n LineCurve,\n LineSeriesStyle,\n LineSeriesProps,\n ScaleAdjustProps,\n} from \"./lib/types.js\";\nexport { PointSeries } from \"./lib/point-series.js\";\nexport type {\n PointAccessor,\n PointMarkStyle,\n PointSeriesStyle,\n PointStyleResolver,\n PointSeriesProps,\n} from \"./lib/point-types.js\";\nexport { PlotSeries } from \"./lib/plot-series.js\";\nexport type { PlotSeriesProps, PlotKeyAccessor } from \"./lib/plot-types.js\";\nexport { nearestDomainValue, nearestPoint } from \"./lib/nearest.js\";\nexport type { NearestPointOptions, NearestPoint } from \"./lib/nearest.js\";\n\nexport { HoverData } from \"./lib/hover-data.js\";\nexport { defineSeries, closestPoint } from \"./lib/hover-queries.js\";\nexport type {\n HoverQueryContext,\n HoverQuery,\n HoverDataProps,\n HoverSeries,\n HoverPoint,\n HoverHit,\n HoverSeriesMap,\n ClosestPointHit,\n ClosestPointOptions,\n} from \"./lib/hover-types.js\";\n\nexport { HoverCard } from \"./lib/hover-card.js\";\nexport type {\n HoverCardProps,\n HoverCardStyle,\n HoverBounds,\n HoverPlacement,\n} from \"./lib/hover-card.js\";\n\nexport {\n closestX,\n interpolateX,\n linearInterpolation,\n} from \"./lib/hover-queries.js\";\nexport type {\n ClosestXOptions,\n ClosestXHit,\n HoverInterpolation,\n InterpolateXOptions,\n HoverSample,\n} from \"./lib/hover-types.js\";\n\nexport { AnchoredLayout } from \"./lib/anchored-layout.js\";\nexport type {\n AnchoredItem,\n AnchoredPlacement,\n AnchoredLayoutProps,\n} from \"./lib/anchored-layout.js\";\n\nexport { BarSeries } from \"./lib/bar-series.js\";\nexport type {\n BarThresholdFill,\n BarCategoryAccessor,\n BarSeriesStyle,\n BarStyleResolver,\n BarSeriesProps,\n} from \"./lib/bar-series.js\";\n\nexport { pieSlices } from \"./lib/pie-slices.js\";\nexport type { PieOptions, PieSliceGeometry } from \"./lib/pie-slices.js\";\n\nexport { PieLayout, PieSlice, PieLabel } from \"./lib/pie-layout.js\";\nexport type { PieLayoutProps, PieLayoutStyle, PieLayoutSlice, PieLabelPlacement, PieLabelLayout, PieSliceProps, PieSliceStyle, PieLabelProps, PieLabelStyle } from \"./lib/pie-types.js\";\n\nexport { extent, niceUTCDomain } from \"./lib/utc-scale.js\";\nexport type { NumericDomain, UtcDomain, UTCScaleProps, ResolvedUtcScale, ResolvedContinuousScale } from \"./lib/types.js\";\n\nexport { linearTicks, niceLinearDomain, formatNumber } from \"./lib/numeric-ticks.js\";\nexport type { LinearTickOptions, NumberFormatOptions } from \"./lib/numeric-ticks.js\";\n\nexport { utcTickLabels } from \"./lib/utc-labels.js\";\nexport type { UTCTickLabelOptions } from \"./lib/utc-labels.js\";\n\nexport { LogScale } from \"./lib/log-scale-component.js\";\nexport { useLogScale } from \"./lib/use-log-scale.js\";\nexport type { LogScaleProps, ResolvedLogScale } from \"./lib/types.js\";\n\nexport { SymlogScale } from \"./lib/symlog-scale-component.js\";\nexport { useSymlogScale } from \"./lib/use-symlog-scale.js\";\nexport type { SymlogScaleProps, ResolvedSymlogScale } from \"./lib/types.js\";\n\nexport { PointScale } from \"./lib/point-scale-component.js\";\nexport { usePointScale } from \"./lib/use-point-scale.js\";\nexport type { PointScaleProps, ResolvedPointScale } from \"./lib/types.js\";\nexport { GridLines, ReferenceLine } from \"./lib/chart-lines.js\";\nexport type { ChartLineProps, GridLinesProps, ReferenceLineProps } from \"./lib/chart-lines.js\";\nexport { ReferenceBand } from \"./lib/reference-band.js\";\nexport type { ReferenceBandProps } from \"./lib/reference-band.js\";\nexport { AxisTitle } from \"./lib/axis-title.js\";\nexport type { AxisTitleProps } from \"./lib/axis-title.js\";\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,mBAAmB;AAC5B,SAAS,gBAAgB;AACzB,SAAS,gBAAgB;AACzB,SAAS,sBAAsB;AAC/B,SAAS,mBAAmB;AAC5B,SAAS,mBAAmB;AAe5B,SAAS,YAAY;AACrB,SAAS,kBAAkB;AAC3B,SAAS,mBAAmB;AAW5B,SAAS,mBAAmB;AAQ5B,SAAS,kBAAkB;AAE3B,SAAS,oBAAoB,oBAAoB;AAGjD,SAAS,iBAAiB;AAC1B,SAAS,cAAc,oBAAoB;AAa3C,SAAS,iBAAiB;AAQ1B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AASP,SAAS,sBAAsB;AAO/B,SAAS,iBAAiB;AAS1B,SAAS,iBAAiB;AAG1B,SAAS,WAAW,UAAU,gBAAgB;AAG9C,SAAS,QAAQ,qBAAqB;AAGtC,SAAS,aAAa,kBAAkB,oBAAoB;AAG5D,SAAS,qBAAqB;AAG9B,SAAS,gBAAgB;AACzB,SAAS,mBAAmB;AAG5B,SAAS,mBAAmB;AAC5B,SAAS,sBAAsB;AAG/B,SAAS,kBAAkB;AAC3B,SAAS,qBAAqB;AAE9B,SAAS,WAAW,qBAAqB;AAEzC,SAAS,qBAAqB;AAE9B,SAAS,iBAAiB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
function fitAxisLabel(context, text, maxWidth, overflow, maxLines) {
|
|
2
|
+
if (overflow === "allow") return [text];
|
|
3
|
+
const graphemes = (value) => Array.from(new Intl.Segmenter(void 0, { granularity: "grapheme" }).segment(value), (part) => part.segment);
|
|
4
|
+
const truncate = (value, force = false) => {
|
|
5
|
+
if (!force && context.measureText(value).width <= maxWidth) return value;
|
|
6
|
+
if (context.measureText("\u2026").width > maxWidth) return "";
|
|
7
|
+
const parts = graphemes(value);
|
|
8
|
+
while (parts.length && context.measureText(parts.join("").trimEnd() + "\u2026").width > maxWidth) parts.pop();
|
|
9
|
+
return parts.join("").trimEnd() + "\u2026";
|
|
10
|
+
};
|
|
11
|
+
if (overflow === "truncate") return [truncate(text)];
|
|
12
|
+
const words = text.trim().split(/\s+/u);
|
|
13
|
+
const lines = [];
|
|
14
|
+
let line = "";
|
|
15
|
+
for (const word of words) {
|
|
16
|
+
const joined = line ? `${line} ${word}` : word;
|
|
17
|
+
if (context.measureText(joined).width <= maxWidth) {
|
|
18
|
+
line = joined;
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
if (line) {
|
|
22
|
+
lines.push(line);
|
|
23
|
+
line = "";
|
|
24
|
+
}
|
|
25
|
+
for (const part of graphemes(word)) {
|
|
26
|
+
if (line && context.measureText(line + part).width > maxWidth) {
|
|
27
|
+
lines.push(line);
|
|
28
|
+
line = "";
|
|
29
|
+
}
|
|
30
|
+
line += part;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (line || !lines.length) lines.push(line);
|
|
34
|
+
const fitted = lines.slice(0, maxLines).map((value) => truncate(value));
|
|
35
|
+
if (lines.length > maxLines) fitted[maxLines - 1] = truncate(fitted[maxLines - 1], true);
|
|
36
|
+
return fitted;
|
|
37
|
+
}
|
|
38
|
+
export {
|
|
39
|
+
fitAxisLabel
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=axis-labels.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/features/viz/lib/axis-labels.ts"],
|
|
4
|
+
"sourcesContent": ["/** Fit text without changing its coordinate or the owning scale. */\nexport function fitAxisLabel(context: Pick<CanvasRenderingContext2D, \"measureText\">, text: string, maxWidth: number, overflow: \"allow\" | \"wrap\" | \"truncate\", maxLines: number): readonly string[] {\n if (overflow === \"allow\") return [text];\n const graphemes = (value: string) => Array.from(new Intl.Segmenter(undefined, { granularity: \"grapheme\" }).segment(value), part => part.segment);\n const truncate = (value: string, force = false) => {\n if (!force && context.measureText(value).width <= maxWidth) return value;\n if (context.measureText(\"\u2026\").width > maxWidth) return \"\";\n const parts = graphemes(value);\n while (parts.length && context.measureText(parts.join(\"\").trimEnd() + \"\u2026\").width > maxWidth) parts.pop();\n return parts.join(\"\").trimEnd() + \"\u2026\";\n };\n if (overflow === \"truncate\") return [truncate(text)];\n const words = text.trim().split(/\\s+/u);\n const lines: string[] = [];\n let line = \"\";\n for (const word of words) {\n const joined = line ? `${line} ${word}` : word;\n if (context.measureText(joined).width <= maxWidth) { line = joined; continue; }\n if (line) { lines.push(line); line = \"\"; }\n for (const part of graphemes(word)) {\n if (line && context.measureText(line + part).width > maxWidth) { lines.push(line); line = \"\"; }\n line += part;\n }\n }\n if (line || !lines.length) lines.push(line);\n const fitted = lines.slice(0, maxLines).map(value => truncate(value));\n if (lines.length > maxLines) fitted[maxLines - 1] = truncate(fitted[maxLines - 1], true);\n return fitted;\n}\n"],
|
|
5
|
+
"mappings": "AACO,SAAS,aAAa,SAAwD,MAAc,UAAkB,UAAyC,UAAqC;AACjM,MAAI,aAAa,QAAS,QAAO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AM,SAAS,SAAU,QAAO,WAAW,CAAC,IAAI,SAAS,OAAO,WAAW,CAAC,GAAG,IAAI;AACvF,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type SignalValue } from "@pibbl/core";
|
|
2
|
+
import type { SignalStyle } from "@pibbl/core/internal";
|
|
3
|
+
import type { AxisProps, AxisStyle, ScaleId } from "./types.js";
|
|
4
|
+
/** Scale-aligned axis text; callers reserve the margin outside the plot. See {@link AxisTitle}. */
|
|
5
|
+
export interface AxisTitleProps {
|
|
6
|
+
/** Ancestor scale whose range supplies the title midpoint. */
|
|
7
|
+
readonly scale: ScaleId;
|
|
8
|
+
/** Plot edge; left/right titles rotate along the axis. */
|
|
9
|
+
readonly position: AxisProps["position"];
|
|
10
|
+
/** Single-line title. */
|
|
11
|
+
readonly label: SignalValue<string>;
|
|
12
|
+
/** Optional unit appended in parentheses; empty string omits it. */
|
|
13
|
+
readonly unit?: SignalValue<string>;
|
|
14
|
+
/** Nonnegative finite distance outside the plot edge, default 40 pixels. */
|
|
15
|
+
readonly offset?: SignalValue<number>;
|
|
16
|
+
/** Font defaults to 12px sans-serif, fill to #617783, opacity to 1. */
|
|
17
|
+
readonly style?: SignalValue<SignalStyle<Pick<AxisStyle, "font" | "fill" | "opacity">>>;
|
|
18
|
+
}
|
|
19
|
+
/** Paint an axis title with optional units, without allocating margins or changing ticks.
|
|
20
|
+
* @param props - Scale geometry and presentation. See {@link AxisTitleProps}.
|
|
21
|
+
* @returns Decorative chart content in the caller's coordinate space.
|
|
22
|
+
*/
|
|
23
|
+
export declare function AxisTitle(props: AxisTitleProps): import("../../../jsx-runtime.js").JSX.Element;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { jsx } from "@pibbl/core/jsx-runtime";
|
|
2
|
+
import { Group, Text, resolveSignalValue } from "@pibbl/core";
|
|
3
|
+
import { lookupScale } from "./scale-context.js";
|
|
4
|
+
import { opacity } from "./paint.js";
|
|
5
|
+
function AxisTitle(props) {
|
|
6
|
+
if (!["top", "bottom", "left", "right"].includes(props.position)) throw new TypeError("AxisTitle position must be top, bottom, left, or right.");
|
|
7
|
+
const source = lookupScale(props.scale, "AxisTitle");
|
|
8
|
+
if (!source) throw new TypeError("AxisTitle requires a scale ID.");
|
|
9
|
+
const scale = source.get(), label = resolveSignalValue(props.label), unit = resolveSignalValue(props.unit) ?? "";
|
|
10
|
+
if ([label, unit].some((value) => typeof value !== "string" || /[\r\n]/.test(value))) throw new TypeError("AxisTitle label and unit must be single-line strings.");
|
|
11
|
+
const offset = resolveSignalValue(props.offset) ?? 40;
|
|
12
|
+
if (typeof offset !== "number" || !Number.isFinite(offset) || offset < 0) throw new RangeError("AxisTitle offset must be finite and nonnegative.");
|
|
13
|
+
const horizontal = props.position === "top" || props.position === "bottom";
|
|
14
|
+
const midpoint = scale.range[0] / 2 + scale.range[1] / 2;
|
|
15
|
+
const x = horizontal ? midpoint : props.position === "left" ? -offset : scale.frame.width + offset;
|
|
16
|
+
const y = horizontal ? props.position === "top" ? -offset : scale.frame.height + offset : midpoint;
|
|
17
|
+
const style = resolveSignalValue(props.style) ?? {};
|
|
18
|
+
return /* @__PURE__ */ jsx(Group, { style: { translateX: x, translateY: y }, children: /* @__PURE__ */ jsx(Group, { style: { rotationDegrees: horizontal ? 0 : props.position === "left" ? -90 : 90 }, children: /* @__PURE__ */ jsx(Text, { pointerEvents: "none", style: { textAlign: "center", textBaseline: "middle", font: resolveSignalValue(style.font) ?? "12px sans-serif", fill: resolveSignalValue(style.fill) ?? "#617783", opacity: opacity(resolveSignalValue(style.opacity) ?? 1, "AxisTitle") }, children: unit ? `${label} (${unit})` : label }) }) });
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
AxisTitle
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=axis-title.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/features/viz/lib/axis-title.tsx"],
|
|
4
|
+
"sourcesContent": ["import { Group, Text, resolveSignalValue, type SignalValue } from \"@pibbl/core\";\nimport type { SignalStyle } from \"@pibbl/core/internal\";\nimport type { AxisProps, AxisStyle, ScaleId } from \"./types.js\";\nimport { lookupScale } from \"./scale-context.js\";\nimport { opacity } from \"./paint.js\";\n/** Scale-aligned axis text; callers reserve the margin outside the plot. See {@link AxisTitle}. */\nexport interface AxisTitleProps {\n /** Ancestor scale whose range supplies the title midpoint. */\n readonly scale: ScaleId;\n /** Plot edge; left/right titles rotate along the axis. */\n readonly position: AxisProps[\"position\"];\n /** Single-line title. */\n readonly label: SignalValue<string>;\n /** Optional unit appended in parentheses; empty string omits it. */\n readonly unit?: SignalValue<string>;\n /** Nonnegative finite distance outside the plot edge, default 40 pixels. */\n readonly offset?: SignalValue<number>;\n /** Font defaults to 12px sans-serif, fill to #617783, opacity to 1. */\n readonly style?: SignalValue<SignalStyle<Pick<AxisStyle, \"font\" | \"fill\" | \"opacity\">>>;\n}\n/** Paint an axis title with optional units, without allocating margins or changing ticks.\n * @param props - Scale geometry and presentation. See {@link AxisTitleProps}.\n * @returns Decorative chart content in the caller's coordinate space.\n */\nexport function AxisTitle(props: AxisTitleProps) {\n if (![\"top\", \"bottom\", \"left\", \"right\"].includes(props.position)) throw new TypeError(\"AxisTitle position must be top, bottom, left, or right.\");\n const source = lookupScale(props.scale, \"AxisTitle\");\n if (!source) throw new TypeError(\"AxisTitle requires a scale ID.\");\n const scale = source.get(), label = resolveSignalValue(props.label), unit = resolveSignalValue(props.unit) ?? \"\";\n if ([label, unit].some(value => typeof value !== \"string\" || /[\\r\\n]/.test(value))) throw new TypeError(\"AxisTitle label and unit must be single-line strings.\");\n const offset = resolveSignalValue(props.offset) ?? 40;\n if (typeof offset !== \"number\" || !Number.isFinite(offset) || offset < 0) throw new RangeError(\"AxisTitle offset must be finite and nonnegative.\");\n const horizontal = props.position === \"top\" || props.position === \"bottom\";\n const midpoint = scale.range[0] / 2 + scale.range[1] / 2;\n const x = horizontal ? midpoint : props.position === \"left\" ? -offset : scale.frame.width + offset;\n const y = horizontal ? props.position === \"top\" ? -offset : scale.frame.height + offset : midpoint;\n const style = resolveSignalValue(props.style) ?? {};\n return <Group style={{ translateX: x, translateY: y }}><Group style={{ rotationDegrees: horizontal ? 0 : props.position === \"left\" ? -90 : 90 }}>\n <Text pointerEvents=\"none\" style={{ textAlign: \"center\", textBaseline: \"middle\", font: resolveSignalValue(style.font) ?? \"12px sans-serif\", fill: resolveSignalValue(style.fill) ?? \"#617783\", opacity: opacity(resolveSignalValue(style.opacity) ?? 1, \"AxisTitle\") }}>{unit ? `${label} (${unit})` : label}</Text>\n </Group></Group>;\n}\n"],
|
|
5
|
+
"mappings": "AAsCI;AAtCJ,SAAS,OAAO,MAAM,0BAA4C;AAGlE,SAAS,mBAAmB;AAC5B,SAAS,eAAe;AAoBjB,SAAS,UAAU,OAAuB;AAC/C,MAAI,CAAC,CAAC,OAAO,UAAU,QAAQ,OAAO,EAAE,SAAS,MAAM,QAAQ,EAAG,OAAM,IAAI,UAAU,yDAAyD;AAC/I,QAAM,SAAS,YAAY,MAAM,OAAO,WAAW;AACnD,MAAI,CAAC,OAAQ,OAAM,IAAI,UAAU,gCAAgC;AACjE,QAAM,QAAQ,OAAO,IAAI,GAAG,QAAQ,mBAAmB,MAAM,KAAK,GAAG,OAAO,mBAAmB,MAAM,IAAI,KAAK;AAC9G,MAAI,CAAC,OAAO,IAAI,EAAE,KAAK,WAAS,OAAO,UAAU,YAAY,SAAS,KAAK,KAAK,CAAC,EAAG,OAAM,IAAI,UAAU,uDAAuD;AAC/J,QAAM,SAAS,mBAAmB,MAAM,MAAM,KAAK;AACnD,MAAI,OAAO,WAAW,YAAY,CAAC,OAAO,SAAS,MAAM,KAAK,SAAS,EAAG,OAAM,IAAI,WAAW,kDAAkD;AACjJ,QAAM,aAAa,MAAM,aAAa,SAAS,MAAM,aAAa;AAClE,QAAM,WAAW,MAAM,MAAM,CAAC,IAAI,IAAI,MAAM,MAAM,CAAC,IAAI;AACvD,QAAM,IAAI,aAAa,WAAW,MAAM,aAAa,SAAS,CAAC,SAAS,MAAM,MAAM,QAAQ;AAC5F,QAAM,IAAI,aAAa,MAAM,aAAa,QAAQ,CAAC,SAAS,MAAM,MAAM,SAAS,SAAS;AAC1F,QAAM,QAAQ,mBAAmB,MAAM,KAAK,KAAK,CAAC;AAClD,SAAO,oBAAC,SAAM,OAAO,EAAE,YAAY,GAAG,YAAY,EAAE,GAAG,8BAAC,SAAM,OAAO,EAAE,iBAAiB,aAAa,IAAI,MAAM,aAAa,SAAS,MAAM,GAAG,GAC5I,8BAAC,QAAK,eAAc,QAAO,OAAO,EAAE,WAAW,UAAU,cAAc,UAAU,MAAM,mBAAmB,MAAM,IAAI,KAAK,mBAAmB,MAAM,mBAAmB,MAAM,IAAI,KAAK,WAAW,SAAS,QAAQ,mBAAmB,MAAM,OAAO,KAAK,GAAG,WAAW,EAAE,GAAI,iBAAO,GAAG,KAAK,KAAK,IAAI,MAAM,OAAM,GAC/S,GAAQ;AACV;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -7,4 +7,4 @@ import type { AxisProps } from "./types.js";
|
|
|
7
7
|
*
|
|
8
8
|
* @see {@link AxisProps}
|
|
9
9
|
*/
|
|
10
|
-
export declare function Axis(props: AxisProps): (import("../../../jsx-runtime.js").JSX.Element[] | import("../../../jsx-runtime.js").JSX.Element)[];
|
|
10
|
+
export declare function Axis(props: AxisProps): ((import("../../../jsx-runtime.js").JSX.Element[] | null)[] | import("../../../jsx-runtime.js").JSX.Element)[];
|