@g9tm/lynxcontrols-canvas 0.0.0-stage → 2.5.8
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 +39 -2
- package/catalog/cards/G9Canvas.md +17 -0
- package/catalog/cards/G9CanvasStylePanel.md +13 -0
- package/catalog/catalog.json +2334 -0
- package/catalog/index.md +6 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/board-controller.d.ts +161 -0
- package/dist/board-controller.d.ts.map +1 -0
- package/dist/board-controller.jsx +812 -0
- package/dist/board-model.d.ts +42 -0
- package/dist/board-model.d.ts.map +1 -0
- package/dist/board-model.jsx +66 -0
- package/dist/canvas.css +81 -0
- package/dist/canvas.css.map +1 -0
- package/dist/canvas.d.ts +144 -0
- package/dist/canvas.d.ts.map +1 -0
- package/dist/canvas.jsx +481 -0
- package/dist/element-core.d.ts +155 -0
- package/dist/element-core.d.ts.map +1 -0
- package/dist/element-core.jsx +1104 -0
- package/dist/export.d.ts +7 -0
- package/dist/export.d.ts.map +1 -0
- package/dist/export.jsx +75 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.jsx +7 -0
- package/dist/observable.d.ts +5 -0
- package/dist/observable.d.ts.map +1 -0
- package/dist/observable.jsx +14 -0
- package/dist/protocol.d.ts +258 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.jsx +2 -0
- package/dist/scene/edit.d.ts +59 -0
- package/dist/scene/edit.d.ts.map +1 -0
- package/dist/scene/edit.jsx +895 -0
- package/dist/scene/elements.d.ts +160 -0
- package/dist/scene/elements.d.ts.map +1 -0
- package/dist/scene/elements.jsx +392 -0
- package/dist/scene/geometry.d.ts +36 -0
- package/dist/scene/geometry.d.ts.map +1 -0
- package/dist/scene/geometry.jsx +367 -0
- package/dist/scene/index.d.ts +8 -0
- package/dist/scene/index.d.ts.map +1 -0
- package/dist/scene/index.jsx +6 -0
- package/dist/scene/path-data-parser.d.ts +17 -0
- package/dist/scene/path-data-parser.d.ts.map +1 -0
- package/dist/scene/path-data-parser.jsx +128 -0
- package/dist/scene/scene.d.ts +58 -0
- package/dist/scene/scene.d.ts.map +1 -0
- package/dist/scene/scene.jsx +169 -0
- package/dist/scene/shapes.d.ts +24 -0
- package/dist/scene/shapes.d.ts.map +1 -0
- package/dist/scene/shapes.jsx +807 -0
- package/dist/scene/types.d.ts +118 -0
- package/dist/scene/types.d.ts.map +1 -0
- package/dist/scene/types.jsx +1 -0
- package/dist/words.d.ts +100 -0
- package/dist/words.d.ts.map +1 -0
- package/dist/words.jsx +186 -0
- package/package.json +50 -4
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { isNewer } from "../board-model.jsx";
|
|
2
|
+
import { bump, compareOrder } from "./elements.jsx";
|
|
3
|
+
function _define_property(obj, key, value) {
|
|
4
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
5
|
+
value: value,
|
|
6
|
+
enumerable: true,
|
|
7
|
+
configurable: true,
|
|
8
|
+
writable: true
|
|
9
|
+
});
|
|
10
|
+
else obj[key] = value;
|
|
11
|
+
return obj;
|
|
12
|
+
}
|
|
13
|
+
const HISTORY_LIMIT = 100;
|
|
14
|
+
class Scene {
|
|
15
|
+
load(elements) {
|
|
16
|
+
this.map.clear();
|
|
17
|
+
for (const element of elements){
|
|
18
|
+
const known = this.map.get(element.id);
|
|
19
|
+
if (!known || isNewer(element, known)) this.map.set(element.id, element);
|
|
20
|
+
}
|
|
21
|
+
this.orderDirty = true;
|
|
22
|
+
this.undoStack.length = 0;
|
|
23
|
+
this.redoStack.length = 0;
|
|
24
|
+
}
|
|
25
|
+
on(listener) {
|
|
26
|
+
this.listeners.add(listener);
|
|
27
|
+
return ()=>this.listeners.delete(listener);
|
|
28
|
+
}
|
|
29
|
+
emit(change) {
|
|
30
|
+
for (const listener of this.listeners)listener(change);
|
|
31
|
+
}
|
|
32
|
+
get(id) {
|
|
33
|
+
return this.map.get(id);
|
|
34
|
+
}
|
|
35
|
+
all() {
|
|
36
|
+
if (this.orderDirty) {
|
|
37
|
+
this.ordered = [
|
|
38
|
+
...this.map.values()
|
|
39
|
+
].sort(compareOrder);
|
|
40
|
+
this.orderDirty = false;
|
|
41
|
+
this.contentDirty = false;
|
|
42
|
+
} else if (this.contentDirty) {
|
|
43
|
+
this.ordered = this.ordered.map((element)=>{
|
|
44
|
+
var _this_map_get;
|
|
45
|
+
return null != (_this_map_get = this.map.get(element.id)) ? _this_map_get : element;
|
|
46
|
+
});
|
|
47
|
+
this.contentDirty = false;
|
|
48
|
+
}
|
|
49
|
+
return this.ordered;
|
|
50
|
+
}
|
|
51
|
+
visible() {
|
|
52
|
+
return this.all().filter((element)=>!element.isDeleted);
|
|
53
|
+
}
|
|
54
|
+
lastIndex() {
|
|
55
|
+
const all = this.all();
|
|
56
|
+
for(let i = all.length - 1; i >= 0; i--)if (all[i].index) return all[i].index;
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
applyRemote(remote) {
|
|
60
|
+
const changed = [];
|
|
61
|
+
let orderChanged = false;
|
|
62
|
+
for (const element of remote){
|
|
63
|
+
const local = this.map.get(element.id);
|
|
64
|
+
if (!(local && (this.editing.has(element.id) || !isNewer(element, local)))) {
|
|
65
|
+
if (!local || local.index !== element.index) orderChanged = true;
|
|
66
|
+
this.map.set(element.id, element);
|
|
67
|
+
changed.push(element);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (orderChanged) this.orderDirty = true;
|
|
71
|
+
if (changed.length) this.contentDirty = true;
|
|
72
|
+
if (changed.length) this.emit({
|
|
73
|
+
changed,
|
|
74
|
+
local: false,
|
|
75
|
+
orderChanged
|
|
76
|
+
});
|
|
77
|
+
return changed;
|
|
78
|
+
}
|
|
79
|
+
commit(elements, history = true) {
|
|
80
|
+
if (!elements.length) return;
|
|
81
|
+
const entry = {
|
|
82
|
+
before: new Map(),
|
|
83
|
+
after: new Map()
|
|
84
|
+
};
|
|
85
|
+
let orderChanged = false;
|
|
86
|
+
for (const element of elements){
|
|
87
|
+
const previous = this.map.get(element.id);
|
|
88
|
+
if (!entry.before.has(element.id)) entry.before.set(element.id, null != previous ? previous : null);
|
|
89
|
+
entry.after.set(element.id, element);
|
|
90
|
+
if (!previous || previous.index !== element.index || previous.isDeleted !== element.isDeleted) orderChanged = true;
|
|
91
|
+
this.map.set(element.id, element);
|
|
92
|
+
}
|
|
93
|
+
if (orderChanged) this.orderDirty = true;
|
|
94
|
+
this.contentDirty = true;
|
|
95
|
+
if (history) {
|
|
96
|
+
this.undoStack.push(entry);
|
|
97
|
+
if (this.undoStack.length > HISTORY_LIMIT) this.undoStack.shift();
|
|
98
|
+
this.redoStack.length = 0;
|
|
99
|
+
}
|
|
100
|
+
this.emit({
|
|
101
|
+
changed: [
|
|
102
|
+
...elements
|
|
103
|
+
],
|
|
104
|
+
local: true,
|
|
105
|
+
orderChanged
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
record(before) {
|
|
109
|
+
const after = new Map();
|
|
110
|
+
for (const id of before.keys()){
|
|
111
|
+
const current = this.map.get(id);
|
|
112
|
+
if (current) after.set(id, current);
|
|
113
|
+
}
|
|
114
|
+
if (!after.size) return;
|
|
115
|
+
this.undoStack.push({
|
|
116
|
+
before,
|
|
117
|
+
after
|
|
118
|
+
});
|
|
119
|
+
if (this.undoStack.length > HISTORY_LIMIT) this.undoStack.shift();
|
|
120
|
+
this.redoStack.length = 0;
|
|
121
|
+
}
|
|
122
|
+
get canUndo() {
|
|
123
|
+
return this.undoStack.length > 0;
|
|
124
|
+
}
|
|
125
|
+
get canRedo() {
|
|
126
|
+
return this.redoStack.length > 0;
|
|
127
|
+
}
|
|
128
|
+
undo() {
|
|
129
|
+
const entry = this.undoStack.pop();
|
|
130
|
+
if (!entry) return [];
|
|
131
|
+
const applied = this.restore(entry.before);
|
|
132
|
+
this.redoStack.push(entry);
|
|
133
|
+
return applied;
|
|
134
|
+
}
|
|
135
|
+
redo() {
|
|
136
|
+
const entry = this.redoStack.pop();
|
|
137
|
+
if (!entry) return [];
|
|
138
|
+
const applied = this.restore(entry.after);
|
|
139
|
+
this.undoStack.push(entry);
|
|
140
|
+
return applied;
|
|
141
|
+
}
|
|
142
|
+
restore(states) {
|
|
143
|
+
const edits = [];
|
|
144
|
+
for (const [id, state] of states){
|
|
145
|
+
const current = this.map.get(id);
|
|
146
|
+
if (!current) continue;
|
|
147
|
+
const target = null != state ? state : {
|
|
148
|
+
...current,
|
|
149
|
+
isDeleted: true
|
|
150
|
+
};
|
|
151
|
+
const { version: _version, versionNonce: _nonce, updated: _updated, ...content } = target;
|
|
152
|
+
edits.push(bump(current, content));
|
|
153
|
+
}
|
|
154
|
+
this.commit(edits, false);
|
|
155
|
+
return edits;
|
|
156
|
+
}
|
|
157
|
+
constructor(elements = []){
|
|
158
|
+
_define_property(this, "map", new Map());
|
|
159
|
+
_define_property(this, "ordered", []);
|
|
160
|
+
_define_property(this, "orderDirty", false);
|
|
161
|
+
_define_property(this, "contentDirty", false);
|
|
162
|
+
_define_property(this, "undoStack", []);
|
|
163
|
+
_define_property(this, "redoStack", []);
|
|
164
|
+
_define_property(this, "listeners", new Set());
|
|
165
|
+
_define_property(this, "editing", new Set());
|
|
166
|
+
this.load(elements);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
export { Scene };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { CvItem, CvOp } from '../protocol.js';
|
|
2
|
+
import type { ExElement, Point } from './types.js';
|
|
3
|
+
/** Whether a line's points close on themselves (filled as a shape). */
|
|
4
|
+
export declare function isPathALoop(points: readonly Point[], zoom?: number): boolean;
|
|
5
|
+
/** A shape's corner for its size and roundness. */
|
|
6
|
+
export declare function cornerRadius(size: number, element: Pick<ExElement, 'roundness'>): number;
|
|
7
|
+
/** A diamond's four corners (flat). */
|
|
8
|
+
export declare function diamondPoints(element: Pick<ExElement, 'width' | 'height'>): number[];
|
|
9
|
+
/** A free stroke as SVG path data (perfect-freehand's outline). */
|
|
10
|
+
export declare function freeDrawPath(element: Pick<ExElement, 'points' | 'pressures' | 'simulatePressure' | 'strokeWidth' | 'lastCommittedPoint'>): string;
|
|
11
|
+
/** Whether a text starts in a right-to-left script. */
|
|
12
|
+
export declare function isRtl(text: string): boolean;
|
|
13
|
+
/** What drawing needs besides the element: the background and the scheme. */
|
|
14
|
+
export interface ShapeContext {
|
|
15
|
+
/** The canvas background (outlined arrowheads are filled with it). */
|
|
16
|
+
background: string;
|
|
17
|
+
/** Dark theme (frame names). */
|
|
18
|
+
dark?: boolean;
|
|
19
|
+
}
|
|
20
|
+
/** The ops of one element, relative to its (x, y). */
|
|
21
|
+
export declare function elementOps(element: ExElement, context: ShapeContext): CvOp[];
|
|
22
|
+
/** The element as a `<g9-canvas>` item. */
|
|
23
|
+
export declare function toItem(element: ExElement, context: ShapeContext): CvItem;
|
|
24
|
+
//# sourceMappingURL=shapes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shapes.d.ts","sourceRoot":"","sources":["../../src/scene/shapes.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAahD,OAAO,KAAK,EAAa,SAAS,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAsC3D,uEAAuE;AACvE,wBAAgB,WAAW,CAAC,MAAM,EAAE,SAAS,KAAK,EAAE,EAAE,IAAI,SAAI,GAAG,OAAO,CAMvE;AAyCD,mDAAmD;AACnD,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,SAAS,EAAE,WAAW,CAAC,GAAG,MAAM,CAQxF;AAED,uCAAuC;AACvC,wBAAgB,aAAa,CAAC,OAAO,EAAE,IAAI,CAAC,SAAS,EAAE,OAAO,GAAG,QAAQ,CAAC,GAAG,MAAM,EAAE,CAIpF;AAiPD,mEAAmE;AACnE,wBAAgB,YAAY,CAC1B,OAAO,EAAE,IAAI,CAAC,SAAS,EAAE,QAAQ,GAAG,WAAW,GAAG,kBAAkB,GAAG,aAAa,GAAG,oBAAoB,CAAC,GAC3G,MAAM,CAkBR;AA6BD,uDAAuD;AACvD,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAO3C;AAED,6EAA6E;AAC7E,MAAM,WAAW,YAAY;IAC3B,sEAAsE;IACtE,UAAU,EAAE,MAAM,CAAC;IACnB,gCAAgC;IAChC,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,sDAAsD;AACtD,wBAAgB,UAAU,CAAC,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,YAAY,GAAG,IAAI,EAAE,CAyJ5E;AA+BD,2CAA2C;AAC3C,wBAAgB,MAAM,CAAC,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,YAAY,GAAG,MAAM,CAcxE"}
|