@formicoidea/labre-framework-cynefin 0.23.0 → 0.23.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.
@@ -1,156 +1,156 @@
1
- import { DefaultTool } from '@formicoidea/labre-core/blocks/surface';
2
- import { EmptyTool } from '@formicoidea/labre-core/gfx/pointer';
3
- import { ShapeStyle } from '@formicoidea/labre-core/model';
4
- import { EdgelessToolbarToolMixin } from '@formicoidea/labre-core/widgets/edgeless-toolbar';
5
- import { Bound } from '@formicoidea/labre-core/global/gfx';
6
- import { css, html, LitElement } from 'lit';
7
-
8
- import { REF_H as CYN_H, REF_W as CYN_W } from '../cynefin/consts';
9
- import { REF_H as EST_H, REF_W as EST_W } from '../estuarine/consts';
10
- import {
11
- cynefinMenuIcon,
12
- estuarineMenuIcon,
13
- hexagonMenuIcon,
14
- } from './icons';
15
-
16
- /** Estuarine map default size (REF aspect, scaled up so it reads on canvas). */
17
- const MAP_SCALE = 1.2;
18
- const HEX_SIZE = 60;
19
- const HEX_FILL = '#34c724';
20
- const HEX_STROKE = '#1f1f1f';
21
- /** Flat-top regular hexagon, normalized vertices. */
22
- const HEX_VERTICES: number[][] = [
23
- [1, 0.5],
24
- [0.75, 0.933],
25
- [0.25, 0.933],
26
- [0, 0.5],
27
- [0.25, 0.067],
28
- [0.75, 0.067],
29
- ];
30
-
31
- /**
32
- * The popover above the toolbar hosting both frameworks: create the Cynefin
33
- * diagram, the Estuarine map, or a hexagon constraint node.
34
- */
35
- export class EdgelessCynefinEstuarineMenu extends EdgelessToolbarToolMixin(
36
- LitElement
37
- ) {
38
- static override styles = css`
39
- :host {
40
- position: absolute;
41
- display: flex;
42
- z-index: -1;
43
- }
44
- .menu-content {
45
- display: flex;
46
- align-items: center;
47
- justify-content: center;
48
- }
49
- .button-group-container {
50
- display: flex;
51
- align-items: center;
52
- gap: 14px;
53
- fill: var(--affine-icon-color);
54
- }
55
- .button-group-container svg {
56
- width: 24px;
57
- height: 24px;
58
- }
59
- `;
60
-
61
- override type = EmptyTool;
62
-
63
- private _finish(id: string) {
64
- const { gfx } = this;
65
- gfx.doc.captureSync();
66
- gfx.tool.setTool(DefaultTool);
67
- gfx.selection.set({ elements: [id], editing: false });
68
- }
69
-
70
- private _createCynefin() {
71
- const { gfx } = this;
72
- if (!gfx.surface) return;
73
- const { centerX, centerY } = gfx.viewport;
74
- const id = gfx.surface.addElement({
75
- type: 'cynefin',
76
- xywh: new Bound(
77
- centerX - CYN_W / 2,
78
- centerY - CYN_H / 2,
79
- CYN_W,
80
- CYN_H
81
- ).serialize(),
82
- });
83
- this._finish(id);
84
- }
85
-
86
- private _createMap() {
87
- const { gfx } = this;
88
- if (!gfx.surface) return;
89
- const width = EST_W * MAP_SCALE;
90
- const height = EST_H * MAP_SCALE;
91
- const { centerX, centerY } = gfx.viewport;
92
- const id = gfx.surface.addElement({
93
- type: 'estuarine',
94
- xywh: new Bound(
95
- centerX - width / 2,
96
- centerY - height / 2,
97
- width,
98
- height
99
- ).serialize(),
100
- });
101
- this._finish(id);
102
- }
103
-
104
- private _createHexagon() {
105
- const { gfx } = this;
106
- if (!gfx.surface) return;
107
- const { centerX: cx, centerY: cy } = gfx.viewport;
108
- const id = gfx.surface.addElement({
109
- type: 'shape',
110
- shapeType: 'polygon',
111
- vertices: HEX_VERTICES,
112
- filled: true,
113
- fillColor: HEX_FILL,
114
- strokeColor: HEX_STROKE,
115
- strokeWidth: 2,
116
- shapeStyle: ShapeStyle.General,
117
- roughness: 0,
118
- xywh: new Bound(
119
- cx - HEX_SIZE / 2,
120
- cy - HEX_SIZE / 2,
121
- HEX_SIZE,
122
- HEX_SIZE
123
- ).serialize(),
124
- });
125
- this._finish(id);
126
- }
127
-
128
- override render() {
129
- return html`
130
- <edgeless-slide-menu>
131
- <div class="menu-content">
132
- <div class="button-group-container">
133
- <edgeless-tool-icon-button
134
- .tooltip=${'Cynefin framework'}
135
- @click=${this._createCynefin}
136
- >
137
- ${cynefinMenuIcon}
138
- </edgeless-tool-icon-button>
139
- <edgeless-tool-icon-button
140
- .tooltip=${'Estuarine map'}
141
- @click=${this._createMap}
142
- >
143
- ${estuarineMenuIcon}
144
- </edgeless-tool-icon-button>
145
- <edgeless-tool-icon-button
146
- .tooltip=${'Hexagon node'}
147
- @click=${this._createHexagon}
148
- >
149
- ${hexagonMenuIcon}
150
- </edgeless-tool-icon-button>
151
- </div>
152
- </div>
153
- </edgeless-slide-menu>
154
- `;
155
- }
156
- }
1
+ import { DefaultTool } from '@formicoidea/labre-core/blocks/surface';
2
+ import { EmptyTool } from '@formicoidea/labre-core/gfx/pointer';
3
+ import { ShapeStyle } from '@formicoidea/labre-core/model';
4
+ import { EdgelessToolbarToolMixin } from '@formicoidea/labre-core/widgets/edgeless-toolbar';
5
+ import { Bound } from '@formicoidea/labre-core/global/gfx';
6
+ import { css, html, LitElement } from 'lit';
7
+
8
+ import { REF_H as CYN_H, REF_W as CYN_W } from '../cynefin/consts';
9
+ import { REF_H as EST_H, REF_W as EST_W } from '../estuarine/consts';
10
+ import {
11
+ cynefinMenuIcon,
12
+ estuarineMenuIcon,
13
+ hexagonMenuIcon,
14
+ } from './icons';
15
+
16
+ /** Estuarine map default size (REF aspect, scaled up so it reads on canvas). */
17
+ const MAP_SCALE = 1.2;
18
+ const HEX_SIZE = 60;
19
+ const HEX_FILL = '#34c724';
20
+ const HEX_STROKE = '#1f1f1f';
21
+ /** Flat-top regular hexagon, normalized vertices. */
22
+ const HEX_VERTICES: number[][] = [
23
+ [1, 0.5],
24
+ [0.75, 0.933],
25
+ [0.25, 0.933],
26
+ [0, 0.5],
27
+ [0.25, 0.067],
28
+ [0.75, 0.067],
29
+ ];
30
+
31
+ /**
32
+ * The popover above the toolbar hosting both frameworks: create the Cynefin
33
+ * diagram, the Estuarine map, or a hexagon constraint node.
34
+ */
35
+ export class EdgelessCynefinEstuarineMenu extends EdgelessToolbarToolMixin(
36
+ LitElement
37
+ ) {
38
+ static override styles = css`
39
+ :host {
40
+ position: absolute;
41
+ display: flex;
42
+ z-index: -1;
43
+ }
44
+ .menu-content {
45
+ display: flex;
46
+ align-items: center;
47
+ justify-content: center;
48
+ }
49
+ .button-group-container {
50
+ display: flex;
51
+ align-items: center;
52
+ gap: 14px;
53
+ fill: var(--affine-icon-color);
54
+ }
55
+ .button-group-container svg {
56
+ width: 24px;
57
+ height: 24px;
58
+ }
59
+ `;
60
+
61
+ override type = EmptyTool;
62
+
63
+ private _finish(id: string) {
64
+ const { gfx } = this;
65
+ gfx.doc.captureSync();
66
+ gfx.tool.setTool(DefaultTool);
67
+ gfx.selection.set({ elements: [id], editing: false });
68
+ }
69
+
70
+ private _createCynefin() {
71
+ const { gfx } = this;
72
+ if (!gfx.surface) return;
73
+ const { centerX, centerY } = gfx.viewport;
74
+ const id = gfx.surface.addElement({
75
+ type: 'cynefin',
76
+ xywh: new Bound(
77
+ centerX - CYN_W / 2,
78
+ centerY - CYN_H / 2,
79
+ CYN_W,
80
+ CYN_H
81
+ ).serialize(),
82
+ });
83
+ this._finish(id);
84
+ }
85
+
86
+ private _createMap() {
87
+ const { gfx } = this;
88
+ if (!gfx.surface) return;
89
+ const width = EST_W * MAP_SCALE;
90
+ const height = EST_H * MAP_SCALE;
91
+ const { centerX, centerY } = gfx.viewport;
92
+ const id = gfx.surface.addElement({
93
+ type: 'estuarine',
94
+ xywh: new Bound(
95
+ centerX - width / 2,
96
+ centerY - height / 2,
97
+ width,
98
+ height
99
+ ).serialize(),
100
+ });
101
+ this._finish(id);
102
+ }
103
+
104
+ private _createHexagon() {
105
+ const { gfx } = this;
106
+ if (!gfx.surface) return;
107
+ const { centerX: cx, centerY: cy } = gfx.viewport;
108
+ const id = gfx.surface.addElement({
109
+ type: 'shape',
110
+ shapeType: 'polygon',
111
+ vertices: HEX_VERTICES,
112
+ filled: true,
113
+ fillColor: HEX_FILL,
114
+ strokeColor: HEX_STROKE,
115
+ strokeWidth: 2,
116
+ shapeStyle: ShapeStyle.General,
117
+ roughness: 0,
118
+ xywh: new Bound(
119
+ cx - HEX_SIZE / 2,
120
+ cy - HEX_SIZE / 2,
121
+ HEX_SIZE,
122
+ HEX_SIZE
123
+ ).serialize(),
124
+ });
125
+ this._finish(id);
126
+ }
127
+
128
+ override render() {
129
+ return html`
130
+ <edgeless-slide-menu>
131
+ <div class="menu-content">
132
+ <div class="button-group-container">
133
+ <edgeless-tool-icon-button
134
+ .tooltip=${'Cynefin framework'}
135
+ @click=${this._createCynefin}
136
+ >
137
+ ${cynefinMenuIcon}
138
+ </edgeless-tool-icon-button>
139
+ <edgeless-tool-icon-button
140
+ .tooltip=${'Estuarine map'}
141
+ @click=${this._createMap}
142
+ >
143
+ ${estuarineMenuIcon}
144
+ </edgeless-tool-icon-button>
145
+ <edgeless-tool-icon-button
146
+ .tooltip=${'Hexagon node'}
147
+ @click=${this._createHexagon}
148
+ >
149
+ ${hexagonMenuIcon}
150
+ </edgeless-tool-icon-button>
151
+ </div>
152
+ </div>
153
+ </edgeless-slide-menu>
154
+ `;
155
+ }
156
+ }
@@ -1,95 +1,95 @@
1
- import { DefaultTool } from '@formicoidea/labre-core/blocks/surface';
2
- import { EmptyTool } from '@formicoidea/labre-core/gfx/pointer';
3
- import { EdgelessToolbarToolMixin } from '@formicoidea/labre-core/widgets/edgeless-toolbar';
4
- import { SignalWatcher } from '@formicoidea/labre-core/global/lit';
5
- import { css, html, LitElement } from 'lit';
6
-
7
- import { cynefinToolbarIcon } from './icons';
8
-
9
- /** Main toolbar button that opens the combined Cynefin / Estuarine sub-menu. */
10
- export class EdgelessCynefinEstuarineSeniorButton extends EdgelessToolbarToolMixin(
11
- SignalWatcher(LitElement)
12
- ) {
13
- static override styles = css`
14
- :host,
15
- .ce-button {
16
- display: block;
17
- width: 100%;
18
- height: 100%;
19
- }
20
- :host {
21
- position: relative;
22
- }
23
- .ce-root {
24
- width: 100%;
25
- height: 64px;
26
- position: relative;
27
- overflow: hidden;
28
- cursor: pointer;
29
- display: flex;
30
- align-items: flex-end;
31
- justify-content: center;
32
- }
33
- .ce-card {
34
- --y: -4px;
35
- --s: 1;
36
- position: absolute;
37
- bottom: 0;
38
- width: 54px;
39
- height: 54px;
40
- transform: translateY(var(--y)) scale(var(--s));
41
- transition: transform 0.3s ease;
42
- }
43
- .ce-card svg {
44
- display: block;
45
- width: 100%;
46
- height: 100%;
47
- }
48
- .ce-root:hover .ce-card {
49
- --y: -10px;
50
- --s: 1.07;
51
- }
52
- `;
53
-
54
- override enableActiveBackground = true;
55
-
56
- override type = EmptyTool;
57
-
58
- private _toggleMenu() {
59
- if (this.popper) {
60
- this.popper.dispose();
61
- this.popper = null;
62
- return;
63
- }
64
- this.setEdgelessTool(DefaultTool);
65
- const menu = this.createPopper('edgeless-cynefin-estuarine-menu', this);
66
- menu.element.edgeless = this.edgeless;
67
-
68
- const el = menu.element as HTMLElement;
69
- const wrap = el.parentElement;
70
- if (wrap) {
71
- wrap.style.overflow = 'visible';
72
- wrap.style.justifyContent = 'flex-end';
73
- }
74
- Object.assign(el.style, {
75
- position: 'static',
76
- width: 'max-content',
77
- maxWidth: 'calc(100vw - 16px)',
78
- marginLeft: '0',
79
- });
80
- }
81
-
82
- override render() {
83
- return html`<edgeless-toolbar-button
84
- class="ce-button"
85
- .tooltip=${this.popper ? '' : 'Cynefin / Estuarine'}
86
- .tooltipOffset=${4}
87
- .active=${!!this.popper}
88
- @click=${this._toggleMenu}
89
- >
90
- <div class="ce-root">
91
- <div class="ce-card">${cynefinToolbarIcon}</div>
92
- </div>
93
- </edgeless-toolbar-button>`;
94
- }
95
- }
1
+ import { DefaultTool } from '@formicoidea/labre-core/blocks/surface';
2
+ import { EmptyTool } from '@formicoidea/labre-core/gfx/pointer';
3
+ import { EdgelessToolbarToolMixin } from '@formicoidea/labre-core/widgets/edgeless-toolbar';
4
+ import { SignalWatcher } from '@formicoidea/labre-core/global/lit';
5
+ import { css, html, LitElement } from 'lit';
6
+
7
+ import { cynefinToolbarIcon } from './icons';
8
+
9
+ /** Main toolbar button that opens the combined Cynefin / Estuarine sub-menu. */
10
+ export class EdgelessCynefinEstuarineSeniorButton extends EdgelessToolbarToolMixin(
11
+ SignalWatcher(LitElement)
12
+ ) {
13
+ static override styles = css`
14
+ :host,
15
+ .ce-button {
16
+ display: block;
17
+ width: 100%;
18
+ height: 100%;
19
+ }
20
+ :host {
21
+ position: relative;
22
+ }
23
+ .ce-root {
24
+ width: 100%;
25
+ height: 64px;
26
+ position: relative;
27
+ overflow: hidden;
28
+ cursor: pointer;
29
+ display: flex;
30
+ align-items: flex-end;
31
+ justify-content: center;
32
+ }
33
+ .ce-card {
34
+ --y: -4px;
35
+ --s: 1;
36
+ position: absolute;
37
+ bottom: 0;
38
+ width: 54px;
39
+ height: 54px;
40
+ transform: translateY(var(--y)) scale(var(--s));
41
+ transition: transform 0.3s ease;
42
+ }
43
+ .ce-card svg {
44
+ display: block;
45
+ width: 100%;
46
+ height: 100%;
47
+ }
48
+ .ce-root:hover .ce-card {
49
+ --y: -10px;
50
+ --s: 1.07;
51
+ }
52
+ `;
53
+
54
+ override enableActiveBackground = true;
55
+
56
+ override type = EmptyTool;
57
+
58
+ private _toggleMenu() {
59
+ if (this.popper) {
60
+ this.popper.dispose();
61
+ this.popper = null;
62
+ return;
63
+ }
64
+ this.setEdgelessTool(DefaultTool);
65
+ const menu = this.createPopper('edgeless-cynefin-estuarine-menu', this);
66
+ menu.element.edgeless = this.edgeless;
67
+
68
+ const el = menu.element as HTMLElement;
69
+ const wrap = el.parentElement;
70
+ if (wrap) {
71
+ wrap.style.overflow = 'visible';
72
+ wrap.style.justifyContent = 'flex-end';
73
+ }
74
+ Object.assign(el.style, {
75
+ position: 'static',
76
+ width: 'max-content',
77
+ maxWidth: 'calc(100vw - 16px)',
78
+ marginLeft: '0',
79
+ });
80
+ }
81
+
82
+ override render() {
83
+ return html`<edgeless-toolbar-button
84
+ class="ce-button"
85
+ .tooltip=${this.popper ? '' : 'Cynefin / Estuarine'}
86
+ .tooltipOffset=${4}
87
+ .active=${!!this.popper}
88
+ @click=${this._toggleMenu}
89
+ >
90
+ <div class="ce-root">
91
+ <div class="ce-card">${cynefinToolbarIcon}</div>
92
+ </div>
93
+ </edgeless-toolbar-button>`;
94
+ }
95
+ }
@@ -1,15 +1,15 @@
1
- import { SeniorToolExtension } from '@formicoidea/labre-core/widgets/edgeless-toolbar';
2
- import { html } from 'lit';
3
-
4
- /** A single senior tool hosting both the Cynefin and Estuarine frameworks. */
5
- export const cynefinEstuarineSeniorTool = SeniorToolExtension(
6
- 'cynefin-estuarine',
7
- ({ block }) => {
8
- return {
9
- name: 'Cynefin / Estuarine',
10
- content: html`<edgeless-cynefin-estuarine-senior-button
11
- .edgeless=${block}
12
- ></edgeless-cynefin-estuarine-senior-button>`,
13
- };
14
- }
15
- );
1
+ import { SeniorToolExtension } from '@formicoidea/labre-core/widgets/edgeless-toolbar';
2
+ import { html } from 'lit';
3
+
4
+ /** A single senior tool hosting both the Cynefin and Estuarine frameworks. */
5
+ export const cynefinEstuarineSeniorTool = SeniorToolExtension(
6
+ 'cynefin-estuarine',
7
+ ({ block }) => {
8
+ return {
9
+ name: 'Cynefin / Estuarine',
10
+ content: html`<edgeless-cynefin-estuarine-senior-button
11
+ .edgeless=${block}
12
+ ></edgeless-cynefin-estuarine-senior-button>`,
13
+ };
14
+ }
15
+ );