packages/core/src/lib/components/g.ts
This is the source snapshot used to build these API details. View this revision on GitHub.
1 import { registerContentsTransform } from '../layout/participation.js';
2 import type { PibblDragHandleStyle } from '../manipulation/handles.js';
3 import type { HtmlBoxStyle } from '../html/types.js';
4 import { definePrimitive } from '../define-primitive.js';
5 import { PibblNodeInput, SystemStyle } from '../types.js';
6 import type { PibblPhysics2DPropExtension } from '../types.js';
7 import {
8 createGroupTransform,
9 setPrimitivePresentation,
10 } from '../primitive-presentation.js';
11 import { stripLayoutParticipation } from '../style/resolve-built-in.js';
12 import {
13 type PibblStructuralEventProps,
14 wireStructuralEvents,
15 } from './structural-events.js';
16 import type {
17 BoxStyle,
18 LayoutItemStyle,
19 ResolvedDrawingStyle,
20 } from '../style/types.js';
21
22 /**
23 * Authored inputs for Group, including the declared data and presentation options.
24 *
25 * @see {@link PibblPhysics2DPropExtension}
26 * @see {@link PibblNodeInput}
27 * @see {@link Group}
28 */
29 export interface GroupProps extends PibblStructuralEventProps, PibblPhysics2DPropExtension {
30 /** Descendant content or the callback that supplies it. See {@link PibblNodeInput}. */
31 children: PibblNodeInput;
32 }
33
34 /**
35 * Transforms, layout participation, and shared style properties for Group.
36 *
37 * @see {@link SystemStyle}
38 * @see {@link BoxStyle}
39 * @see {@link LayoutItemStyle}
40 * @see {@link Group}
41 * @see {@link PibblDragHandleStyle}
42 * @see {@link HtmlBoxStyle}
43 */
44 export interface GStyle extends SystemStyle, BoxStyle, LayoutItemStyle {
45 /** Horizontal scale factor. See {@link GStyle}. */
46 scaleX?: number;
47 /** Vertical scale factor. See {@link GStyle}. */
48 scaleY?: number;
49 /** Clockwise rotation in degrees. */
50 rotationDegrees?: number;
51 /** Point around which the rotation is applied. See {@link GStyle}. */
52 rotationOrigin?: [number, number];
53 /** Horizontal translation in the current logical coordinate system. See {@link GStyle}. */
54 translateX?: number;
55 /** Vertical translation in the current logical coordinate system. See {@link GStyle}. */
56 translateY?: number;
57 /** Horizontal skew angle in degrees. */
58 skewX?: number;
59 /** Vertical skew angle in degrees. */
60 skewY?: number;
61 }
62
63 type ResolvedGStyle = ResolvedDrawingStyle<GStyle>;
64
65 function renderGroup(
66 props: GroupProps,
67 ) {
68 wireStructuralEvents(props);
69 return props.children;
70 }
71
72 /**
73 * Describes a transformation group for JSX or createElement authoring.
74 *
75 * @param props - Authored component inputs, supplied through JSX or createElement. See the linked
76 * props and style types.
77 * @throws When called directly; Pibbl mounts this component through JSX or createElement.
78 *
79 * @see {@link GroupProps}
80 * @see {@link GStyle}
81 */
82 export const Group = definePrimitive<
83 GroupProps,
84 GStyle,
85 GStyle,
86 ResolvedGStyle
87 >(renderGroup, {
88 childInput: 'structural',
89 resolveStyle: style => stripLayoutParticipation(style) as ResolvedGStyle,
90 });
91
92 setPrimitivePresentation<ResolvedGStyle>(Group, style => ({
93 transform: createGroupTransform(style),
94 }));
95
96 registerContentsTransform(Group);
97
Documentation version
Section titled “Documentation version”Documentation built with @pibbl/core 0.0.2, revision a1dcf8e. ALPHA — NOT FOR PRODUCTION USE.