# core/factories/field.factory.ts

> 30 lines of code and 6 definitions.

Tree: Bane's Lab Social Share
Language: typescript
Layer: infrastructure
Canonical: https://banes-lab.com/anatomy/social-share#file-social-share-core-factories-field-factory-ts
Source text: https://banes-lab.com/source/social-share/core/factories/field.factory.ts.txt

Listed in [core/factories](https://banes-lab.com/api/source/social-share/core/factories.md), after [core/factories/card.factory.ts](https://banes-lab.com/source/social-share/core/factories/card.factory.ts.md) and before [core/factories/page.factory.ts](https://banes-lab.com/source/social-share/core/factories/page.factory.ts.md).

## Definitions

- `angle` (lexical_declaration, line 9)
- `fieldLayers` (lexical_declaration, line 25, exported)
- `poolLayer` (lexical_declaration, line 7)
- `TURN` (lexical_declaration, line 5)
- `phase` (lexical_declaration, line 8)
- `ground` (lexical_declaration, line 26, exported)

## Contained in

- [core/factories](https://banes-lab.com/anatomy/social-share/folder-social-share-core-factories.md)

## Uses

- [core/evaluators/card.fragment.evaluator.ts](https://banes-lab.com/source/social-share/core/evaluators/card.fragment.evaluator.ts.md)

## Used by

- [core/factories/page.factory.ts](https://banes-lab.com/source/social-share/core/factories/page.factory.ts.md)

## Linked from

- [core/evaluators](https://banes-lab.com/anatomy/social-share/folder-social-share-core-evaluators.md)
- [core/factories](https://banes-lab.com/anatomy/social-share/folder-social-share-core-factories.md)

## Source

```typescript
import type { FrameContext, Layer } from "#types/card.types";
import { PAGE_POOL_OPACITY, PAGE_POOL_ORIGINS, PAGE_POOL_REACH, PAGE_POOL_SIZE } from "#configuration/data/page.data";
import { squareHeight } from "#core/evaluators/card.fragment.evaluator";

const TURN = Math.PI * 2;

const poolLayer = function poolLayer(origin: readonly [number, number], index: number): Layer {
    const phase = index / PAGE_POOL_ORIGINS.length;
    const angle = (frame: FrameContext): number => (frame.progress + phase) * TURN;
    return {
        className: "share-pool",
        id: `pool-${String(index)}`,
        kind: "box",
        opacity: PAGE_POOL_OPACITY[index] ?? 0,
        placement: {
            anchor: "center",
            height: (frame) => squareHeight(PAGE_POOL_SIZE, frame),
            width: PAGE_POOL_SIZE,
            x: (frame) => origin[0] + PAGE_POOL_REACH * Math.cos(angle(frame)),
            y: (frame) => origin[1] + PAGE_POOL_REACH * Math.sin(angle(frame)),
        },
    };
};

export const fieldLayers = function fieldLayers(field?: readonly Layer[]): readonly Layer[] {
    const ground: Layer = {
        className: "share-ground",
        id: "ground",
        kind: "box",
        placement: { height: 1, width: 1, x: 0, y: 0 },
    };
    return field ?? [ground, ...PAGE_POOL_ORIGINS.map(poolLayer)];
};
```
