@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.
@@ -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;