@mhmttosun/dnd 0.0.0-stage → 1.1.0
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/LICENSE +21 -0
- package/README.md +327 -2
- package/css/answer-key.css +200 -0
- package/css/editor.css +1797 -0
- package/css/player.css +782 -0
- package/css/stage.css +490 -0
- package/dist/dnd-player-element.js +1758 -0
- package/dist/dnd.js +2041 -0
- package/dist/editor.css +3278 -0
- package/dist/editor.d.ts +23 -0
- package/dist/editor.js +8506 -0
- package/dist/index.d.ts +102 -0
- package/dist/player.css +782 -0
- package/dist/player.d.ts +1 -0
- package/dist/player.js +2041 -0
- package/dist/player.umd.cjs +1758 -0
- package/index.html +203 -0
- package/js/app.js +188 -0
- package/js/core/AnswerKeyManager.js +494 -0
- package/js/core/EditorCore.js +220 -0
- package/js/core/HistoryManager.js +194 -0
- package/js/core/LayerManager.js +86 -0
- package/js/core/ObjectManager.js +468 -0
- package/js/core/SelectionManager.js +459 -0
- package/js/core/StageManager.js +295 -0
- package/js/data/SampleProjects.js +883 -0
- package/js/engine/TransformEngine.js +632 -0
- package/js/engine/ValidationEngine.js +147 -0
- package/js/player/ActivityEngine.js +1272 -0
- package/js/player/ExportManager.js +820 -0
- package/js/ui/MiniToolbar.js +1546 -0
- package/js/ui/PropertyPanel.js +776 -0
- package/js/ui/UIManager.js +596 -0
- package/js/utils/AudioSynthesizer.js +111 -0
- package/package.json +69 -4
- package/src/ActivityPlayer.js +309 -0
- package/src/DNDEditor.js +217 -0
- package/src/components/DNDPlayerElement.js +191 -0
- package/src/index.js +12 -0
- package/src/player.js +13 -0
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* <dnd-player> Web Component (Custom Element)
|
|
3
|
+
*
|
|
4
|
+
* Herhangi bir framework (React, Vue, Svelte, Angular veya düz HTML) içinde
|
|
5
|
+
* standart bir HTML etiketi gibi çalışan bağımsız etkinlik oynatıcı bileşeni.
|
|
6
|
+
*
|
|
7
|
+
* Kullanım Örneği:
|
|
8
|
+
* <dnd-player src="/samples/2_hayvanlar_eslestirme.json" sound="true"></dnd-player>
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { ActivityPlayer } from '../ActivityPlayer.js';
|
|
12
|
+
|
|
13
|
+
export class DNDPlayerElement extends HTMLElement {
|
|
14
|
+
static get observedAttributes() {
|
|
15
|
+
return ['src', 'sound', 'mode'];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
constructor() {
|
|
19
|
+
super();
|
|
20
|
+
this._player = null;
|
|
21
|
+
this._data = null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
connectedCallback() {
|
|
25
|
+
this.render();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
disconnectedCallback() {
|
|
29
|
+
if (this._player) {
|
|
30
|
+
this._player.destroy();
|
|
31
|
+
this._player = null;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
36
|
+
if (oldValue === newValue || !this.isConnected) return;
|
|
37
|
+
|
|
38
|
+
if (name === 'src' && newValue) {
|
|
39
|
+
this.initPlayer();
|
|
40
|
+
} else if (name === 'sound' && this._player) {
|
|
41
|
+
this._player.setSound(newValue !== 'false');
|
|
42
|
+
} else if (name === 'mode' && this._player && (newValue === 'learning' || newValue === 'assessment')) {
|
|
43
|
+
this._player.setPlayMode(newValue);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Doğrudan JavaScript nesnesi olarak etkinlik verisi atanabilir:
|
|
49
|
+
* element.data = { ... }
|
|
50
|
+
*/
|
|
51
|
+
get data() {
|
|
52
|
+
return this._data;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
set data(val) {
|
|
56
|
+
this._data = val;
|
|
57
|
+
this.initPlayer();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
get player() {
|
|
61
|
+
return this._player;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
render() {
|
|
65
|
+
this.style.display = 'block';
|
|
66
|
+
this.style.position = 'relative';
|
|
67
|
+
this.style.width = '100%';
|
|
68
|
+
this.style.height = this.style.height || '100%';
|
|
69
|
+
this.style.minHeight = this.style.minHeight || '500px';
|
|
70
|
+
|
|
71
|
+
this.initPlayer();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
initPlayer() {
|
|
75
|
+
if (this._player) {
|
|
76
|
+
this._player.destroy();
|
|
77
|
+
this._player = null;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const src = this.getAttribute('src');
|
|
81
|
+
const soundAttr = this.getAttribute('sound');
|
|
82
|
+
const sound = soundAttr !== 'false';
|
|
83
|
+
const modeAttr = this.getAttribute('mode') || 'learning';
|
|
84
|
+
|
|
85
|
+
if (!src && !this._data) return;
|
|
86
|
+
|
|
87
|
+
this._player = new ActivityPlayer({
|
|
88
|
+
target: this,
|
|
89
|
+
src: src || undefined,
|
|
90
|
+
data: this._data || undefined,
|
|
91
|
+
sound: sound,
|
|
92
|
+
playMode: modeAttr,
|
|
93
|
+
onComplete: (stats) => {
|
|
94
|
+
this.dispatchEvent(new CustomEvent('dnd:complete', { detail: stats, bubbles: true }));
|
|
95
|
+
},
|
|
96
|
+
onStep: (state) => {
|
|
97
|
+
this.dispatchEvent(new CustomEvent('dnd:step', { detail: state, bubbles: true }));
|
|
98
|
+
},
|
|
99
|
+
onDrop: (dropInfo) => {
|
|
100
|
+
this.dispatchEvent(new CustomEvent('dnd:drop', { detail: dropInfo, bubbles: true }));
|
|
101
|
+
},
|
|
102
|
+
onReset: (state) => {
|
|
103
|
+
this.dispatchEvent(new CustomEvent('dnd:reset', { detail: state, bubbles: true }));
|
|
104
|
+
},
|
|
105
|
+
onReady: (p) => {
|
|
106
|
+
this.dispatchEvent(new CustomEvent('dnd:ready', { detail: { player: p }, bubbles: true }));
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Bir File veya Blob nesnesi yükler (<input type="file"> için)
|
|
113
|
+
*/
|
|
114
|
+
loadFile(file) {
|
|
115
|
+
if (this._player) {
|
|
116
|
+
this._player.loadFromFile(file);
|
|
117
|
+
} else {
|
|
118
|
+
this._player = new ActivityPlayer({
|
|
119
|
+
target: this,
|
|
120
|
+
file: file,
|
|
121
|
+
sound: this.getAttribute('sound') !== 'false'
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Ham JSON metni yükler
|
|
128
|
+
*/
|
|
129
|
+
loadJsonString(jsonString) {
|
|
130
|
+
if (this._player) {
|
|
131
|
+
this._player.loadFromJsonString(jsonString);
|
|
132
|
+
} else {
|
|
133
|
+
this._player = new ActivityPlayer({
|
|
134
|
+
target: this,
|
|
135
|
+
jsonString: jsonString,
|
|
136
|
+
sound: this.getAttribute('sound') !== 'false'
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Kontrol alanındaki geri bildirim mesajını günceller
|
|
143
|
+
*/
|
|
144
|
+
setFeedback(message, type = 'info', duration = 0) {
|
|
145
|
+
if (this._player) {
|
|
146
|
+
this._player.setFeedback(message, type, duration);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Anlık geri bildirim durumunu döner
|
|
152
|
+
*/
|
|
153
|
+
getFeedback() {
|
|
154
|
+
return this._player ? this._player.getFeedback() : null;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Etkinliği sıfırlama metodu
|
|
159
|
+
*/
|
|
160
|
+
reset() {
|
|
161
|
+
if (this._player) this._player.reset();
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Durum sorgulama metodu
|
|
166
|
+
*/
|
|
167
|
+
getState() {
|
|
168
|
+
return this._player ? this._player.getState() : null;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Aktif oyun modunu döner ('learning' veya 'assessment')
|
|
173
|
+
*/
|
|
174
|
+
getPlayMode() {
|
|
175
|
+
return this._player ? this._player.getPlayMode() : (this.getAttribute('mode') || 'learning');
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Oyun modunu değiştirir ('learning' veya 'assessment')
|
|
180
|
+
* @param {'learning'|'assessment'} mode
|
|
181
|
+
*/
|
|
182
|
+
setPlayMode(mode) {
|
|
183
|
+
if (this._player) this._player.setPlayMode(mode);
|
|
184
|
+
this.setAttribute('mode', mode);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// Custom element kaydı
|
|
189
|
+
if (typeof customElements !== 'undefined' && !customElements.get('dnd-player')) {
|
|
190
|
+
customElements.define('dnd-player', DNDPlayerElement);
|
|
191
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DND Interactive Activity Library (Full Bundle Entrypoint)
|
|
3
|
+
*
|
|
4
|
+
* Hem oynatıcıyı (ActivityPlayer / DNDPlayerElement) hem de
|
|
5
|
+
* görsel düzenleyici bileşenlerini dışa aktarır.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export { ActivityPlayer } from './ActivityPlayer.js';
|
|
9
|
+
export { DNDPlayerElement } from './components/DNDPlayerElement.js';
|
|
10
|
+
|
|
11
|
+
// Global window.DND altındaki motor sınıfları
|
|
12
|
+
export const getDND = () => (typeof window !== 'undefined' ? window.DND : {});
|
package/src/player.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DND Player Kütüphane Giriş Noktası (Player Only)
|
|
3
|
+
*
|
|
4
|
+
* Sadece etkinlik oynatıcıyı iç projelerinde kullanmak isteyenler için hafif paket.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export { ActivityPlayer } from './ActivityPlayer.js';
|
|
8
|
+
export { DNDPlayerElement } from './components/DNDPlayerElement.js';
|
|
9
|
+
|
|
10
|
+
// Eğer global window nesnesinde ActivityEngine varsa dışa aktar
|
|
11
|
+
export const ActivityEngine = (typeof window !== 'undefined' && window.DND) ? window.DND.ActivityEngine : undefined;
|
|
12
|
+
export const AudioSynthesizer = (typeof window !== 'undefined' && window.DND) ? window.DND.AudioSynthesizer : undefined;
|
|
13
|
+
export const ValidationEngine = (typeof window !== 'undefined' && window.DND) ? window.DND.ValidationEngine : undefined;
|