hayun-vite 0.10.1 → 0.11.1

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.
Files changed (37) hide show
  1. package/assets/data/sampleData.js +10 -2
  2. package/assets/templates/mainTemplate.js +128 -0
  3. package/assets/templates/template_combo.js +49 -44
  4. package/package.json +1 -1
  5. package/src/Audiogram/Audiogram.js +43 -21
  6. package/src/Audiogram/Audiogram_100.js +499 -0
  7. package/src/Audiogram/Audiogram_box.js +483 -0
  8. package/src/Audiogram/dims.js +4 -80
  9. package/src/Audiogram/dims_100.js +51 -0
  10. package/src/Audiogram/dims_box.js +125 -0
  11. package/src/Form/Form.js +38 -42
  12. package/src/Form/Form_N.js +194 -0
  13. package/src/Form/Forms.js +0 -2
  14. package/src/Form/Sections.js +0 -6
  15. package/src/Form/Sections_N.js +66 -0
  16. package/src/{Form → Header}/Header.js +1 -4
  17. package/src/Header/Header_N.js +72 -0
  18. package/src/{Form/Box.js → MultiText/MultiText.js} +42 -25
  19. package/src/MultiText/MultiText_N.js +37 -0
  20. package/src/{Form/Reflex_N.js → Reflex/Reflex.js} +17 -4
  21. package/src/Reflex/units.js +65 -0
  22. package/src/{Form/Speech_N.js → Speech/Speech.js} +47 -30
  23. package/src/Speech/Speech_N.js +125 -0
  24. package/src/Speech/units.js +31 -0
  25. package/src/{Form → Tympanogram}/Tympanogram.js +39 -69
  26. package/src/Tympanogram/units.js +76 -0
  27. package/src/common/{putTextBox.js → putCell.js} +6 -6
  28. package/src/common/putG.js +10 -0
  29. package/src/common/putLine.js +1 -1
  30. package/src/common/putText.js +5 -4
  31. package/src/main.js +192 -19
  32. package/assets/fonts/Vazirmatn-Regular.woff2 +0 -0
  33. package/assets/styles-test.css +0 -86
  34. package/assets/styles.css +0 -86
  35. package/src/Form/Reflex.js +0 -145
  36. package/src/Form/Speech.js +0 -121
  37. package/src/Form/globalinfo.js +0 -68
@@ -0,0 +1,499 @@
1
+ import putLine from "../common/putLine.js";
2
+ import putPoint from "../common/putPoint.js";
3
+ import putRect from "../common/putRect.js";
4
+ import putSVG from "../common/putSVG.js";
5
+ import putText from "../common/putText.js";
6
+ import getAllSymbolsSVG from "../Symbol/getAllSymbolsSVG.js";
7
+ import units from './dims.js';
8
+
9
+ export default class Audiogram {
10
+ constructor({ container, side, dims, events = true }) {
11
+
12
+ this.container = container;
13
+ // this.dims = {}
14
+ // Object.assign(this.dims, units)
15
+ this.dims = units; // ابعاد اصلی برای رسم روی دیسپلی به تنهایی کافی هست
16
+
17
+ // اضافه کردن ابعاد جایگزین و یا اختصاصی دیگر به آبجکت ابعاد
18
+ dims && Object.assign(this.dims, dims);
19
+
20
+ // هارد کد نمایش بورد برای همه باکس ها
21
+ this.dims.borderBox = 'display';
22
+
23
+ this.events = events;
24
+ this.side = side;
25
+ this.data = {};
26
+ const symbols = getAllSymbolsSVG();
27
+ this.symbols = symbols;
28
+ this.draw();
29
+ events && this.addEvents();
30
+ }
31
+
32
+ draw() {
33
+ const [container, dims] = [this.container, this.dims]
34
+ let
35
+ {
36
+ vbWidth, vbHeight, width, height, chartPadding, symbolDims, vf, vfArray,
37
+ vfToF, fToVf, intensity, styles, frequencies, borderBox,
38
+ }
39
+ = dims;
40
+
41
+
42
+ let x = dims.margin.left
43
+ let y = dims.margin.top
44
+
45
+ this.symbolDims = symbolDims;
46
+ this.vf = vf;
47
+ this.vfArray = vfArray;
48
+ this.fToVf = fToVf; // index of coresponding frequency
49
+ this.vfToF = vfToF;
50
+ this.intensity = intensity;
51
+ this.styles = styles;
52
+ this.chartPadding = chartPadding;
53
+
54
+ let style;
55
+ const xArea = { min: chartPadding.left, max: vbWidth - (chartPadding.right) }
56
+ this.xArea = xArea
57
+ const yArea = { min: chartPadding.top, max: vbHeight - (chartPadding.bottom) }
58
+
59
+ const xAxisLength = {
60
+ vb: vbWidth - (chartPadding.left + chartPadding.right),
61
+ hzi: vf.max - vf.min // 0, 1, 2, ... instead 125, ...
62
+ }
63
+ this.xAxisLength = xAxisLength
64
+
65
+ const yAxisLength = {
66
+ vb: vbHeight - (chartPadding.top + chartPadding.bottom),
67
+ db: intensity.max - intensity.min
68
+ }
69
+ this.yAxisLength = yAxisLength
70
+
71
+
72
+ // کل چارت
73
+ // Main SVG for Audiogram
74
+ // متناسب سازی مقدار ارتفاع ویوباکس بر حسب نسبت طول و عرض پیکسلی روش اول
75
+ // const kpx = height / width
76
+ // const kvb = vbWidth / vbHeight
77
+ // vbHeight = vbHeight * kpx * kvb;
78
+
79
+ vbHeight = (vbWidth * height) / width // متناسب سازی ارتفاع ویباکس با پهنا و ارتفاع ورودی
80
+
81
+
82
+
83
+ const viewBox = [-chartPadding.left, -chartPadding.top, vbWidth, vbHeight].join(' ')
84
+ const svg = putSVG({ x, y, width, height, viewBox })
85
+ // این خط شد دو خط کد طلایی که مشکل سایز فونت در دیسپلی و کاغذ رو حل کرد
86
+ width = vbWidth; // ثابت می‌ماند همیشه
87
+ height = vbHeight // با نسبت پهنا و ارتفاع ورودی تغییر میکند
88
+
89
+ this.svg = svg; // کل نودی که به کانتینر اپند میشه
90
+
91
+ // برای فرم‌های پیش چاپ نشده
92
+ if (!dims.blank) {
93
+ // محدوده مختصات خطوط جدول
94
+ const chartArea = putRect({
95
+ container: svg,
96
+ x: this.getX(vf.min), y: this.getY(intensity.min),
97
+ width: xAxisLength.vb, height: yAxisLength.vb,
98
+ style: 'stroke-width: 0.4; stroke: gray; fill: transparent'
99
+ });
100
+
101
+ // رسم خطوط افقی از بالا به پایین
102
+ let x1 = this.getX(vf.min);
103
+ let x2 = this.getX(vf.max);
104
+ for (let i = intensity.min; i <= intensity.max; i += intensity.step) {
105
+ const y1 = this.getY(i)
106
+ const y2 = y1;
107
+ style = (i === 0) ? styles.boldLine : styles.line;
108
+ putLine({ container: svg, x1, y1, x2, y2, style })
109
+ }
110
+
111
+ // رسم خطوط عمودی از چپ به راست
112
+ let y1 = this.getY(intensity.min)
113
+ let y2 = this.getY(intensity.max)
114
+ frequencies.forEach(item => {
115
+ const x1 = this.getX(item.vf)
116
+ const x2 = x1
117
+ style = (item.semiOctav) ? styles.semiOctavFreqline : styles.mainFreqline;
118
+ (item.f === 1000) && (style = styles.boldLine);
119
+ putLine({ container: svg, x1, y1, x2, y2, style })
120
+ })
121
+ // برچسب های اعداد فرکانس
122
+ style = styles.frequency
123
+ const y = this.getY(-25)
124
+ frequencies.forEach(item => {
125
+ const value = item.f
126
+ const x = this.getX(item.vf)
127
+ !item.semiOctav && item.f != 125 && item.f != 16000 &&
128
+ putText({ container: svg, value, x, y, style });
129
+ })
130
+
131
+ // رسم اعداد شدت محور عمودی
132
+ style = styles.intensity
133
+ const x = this.getX(-0.1)
134
+ for (let i = -10; i <= 120; i += 10) {
135
+ const y = this.getY(i)
136
+ const value = i
137
+ putText({ container: svg, x, y, value, style })
138
+ }
139
+ }
140
+ // یک بوردر راهنمای توسعه برای اس‌ وی جی به تمام پهنا و ارتفاع رسم می‌کنیم
141
+ // این مربع مرزی را آخرین ایجاد میکنیم تا بالاترین لایه باشد و روی رویدادها درست عمل کند
142
+ // تعیین نمایش یا عدم نمایش با پراپرتی بوردباکس
143
+ let color = borderBox === 'display' ? 'green' : 'transparent'
144
+ const borderRect = putRect({
145
+ container: svg, x: -chartPadding.left, y: -chartPadding.top,
146
+ width: vbWidth, height: vbHeight, name: '',
147
+ style: `fill: transparent; stroke: ${color}; stroke-width: 0.5`,
148
+ });
149
+ this.borderRect = borderRect;
150
+
151
+ const lastCordinate = { f: 125, i: -20 }
152
+ this.lastCordinate = lastCordinate
153
+ const currentCordinate = { f: 125, i: -20 }
154
+ this.currentCordinate = currentCordinate
155
+
156
+ const chartArea = putRect({
157
+ container: svg, x: 0, y: 0,
158
+ width: xAxisLength.vb, height: yAxisLength.vb,
159
+ style: 'fill: transparent; stroke: ;',
160
+ });
161
+
162
+ this.chartArea = chartArea
163
+ this.events && this.drawSymbolsChart();
164
+ container.appendChild(svg);
165
+ }
166
+
167
+ addEvents() {
168
+ // برای قابل فوکوس کردن چارت ادیوگرام و دریافت رویدادهای صفحه کلید
169
+ this.svg.setAttribute('tabindex', 1)
170
+ this.svg.focus({ focusVisible: true });
171
+
172
+ this.svg.style.outline = 'none';
173
+
174
+
175
+ // نقطه راهنما
176
+ const pointer = putPoint({ container: this.svg, x: 0, y: 0, r: 0.6, color: 'black' });
177
+ this.pointer = pointer;
178
+ this.mouseMove();
179
+ this.click();
180
+ this.mouseEnter();
181
+ this.mouseLeave();
182
+ this.keyboard();
183
+
184
+
185
+ }
186
+
187
+ keyboard() {
188
+ this.svg.addEventListener('keydown', e => {
189
+ e.preventDefault();
190
+ console.log(e.code)
191
+ let f, vf, i, x, y, index
192
+ switch (e.code) {
193
+ case 'ArrowDown':
194
+ i = this.currentCordinate.i;
195
+ (this.currentCordinate.i != 125) && (i = this.currentCordinate.i += 5);
196
+ y = this.getY(i)
197
+ this.pointer.setAttribute('cy', y)
198
+ break;
199
+ case 'ArrowUp':
200
+ i = this.currentCordinate.i;
201
+ (this.currentCordinate.i != -15) && (i = this.currentCordinate.i -= 5);
202
+ y = this.getY(i)
203
+ this.pointer.setAttribute('cy', y)
204
+ break;
205
+ case 'ArrowRight':
206
+ f = this.currentCordinate.f;
207
+ vf = this.fToVf[f];
208
+ index = this.vfArray.indexOf(vf);
209
+ (f != 8000) && index++;
210
+ vf = this.vfArray[index]
211
+ this.currentCordinate.f = this.vfToF[vf]
212
+ x = this.getX(vf)
213
+ this.pointer.setAttribute('cx', x)
214
+ break;
215
+ case 'ArrowLeft':
216
+ f = this.currentCordinate.f;
217
+ vf = this.fToVf[f];
218
+ index = this.vfArray.indexOf(vf);
219
+ (f != 250) && index--;
220
+ vf = this.vfArray[index]
221
+ this.currentCordinate.f = this.vfToF[vf]
222
+ x = this.getX(vf)
223
+ this.pointer.setAttribute('cx', x)
224
+ break;
225
+ case 'Space':
226
+ this.updateFreqLine({ shiftKey: e.shiftKey })
227
+ break;
228
+ case 'Delete':
229
+ const container = this.svg
230
+ const dataset = { f: this.currentCordinate.f, i: this.currentCordinate.i }
231
+ this.removeSymbol({ container, dataset })
232
+ break;
233
+ default:
234
+ break;
235
+ }
236
+ })
237
+
238
+ }
239
+
240
+ drawSymbolsChart() {
241
+ const { width, height } = this.dims.symbolsChart
242
+ let style;
243
+ let x = 0
244
+ let y = 0
245
+
246
+ const symbolsChart = putSVG({ container: this.container, width, height, x, y });
247
+ symbolsChart.style.cursor = 'pointer'; // Change Mouse Pointer to to pointer(Hand) cursor
248
+ let container = symbolsChart
249
+ style = 'fill: none;'
250
+ putRect({ container, x, y, width, height, style });
251
+
252
+ const
253
+ dw = width / 4 - 1,
254
+ dh = height - 2,
255
+ rect = {};
256
+ x = 1; y = 1;
257
+ style = 'fill: none; stroke: brown;';
258
+
259
+ (this.side === 'R' ? ['R_AC', 'R_BC', 'R_AC_M', 'R_BC_M'] : ['L_AC', 'L_BC', 'L_AC_M', 'L_BC_M'])
260
+ .forEach(symbolName => {
261
+ let [width, height] = [dw, dh];
262
+ // width = ; height= 50
263
+ rect[symbolName] = putRect({ container, x, y, width, height, name: symbolName, style });
264
+ this.insertSymbol({ container, symbolName, x: x + dw / 2, y: dh / 2 })
265
+ x += dw;
266
+ });
267
+
268
+ // تعیین سمبل پیش‌فرض
269
+ this.currentSymbolName = this.side + '_AC';
270
+ this.symbol = { current: { side: this.side, type: 'AC' }, last: {} }
271
+ this.lastSymbolName = this.currentSymbolName;
272
+ rect[this.currentSymbolName].style = 'fill: yellow; stroke: brown;'
273
+
274
+ symbolsChart.onclick = (e) => {
275
+ this.currentSymbolName = e.target.dataset.name
276
+ // رنگی کردن مربع دور سمبل
277
+ rect[this.lastSymbolName].style = 'fill: none; stroke: brown;'
278
+ rect[this.currentSymbolName].style = 'fill: yellow; stroke: brown;'
279
+ this.lastSymbolName = this.currentSymbolName
280
+ }
281
+ }
282
+
283
+ mouseMove() {
284
+ // وقتی کاربر صفحه را ریسایز می‌کند مختصات آفست تغییر میکند گه با تابع زیر همیشه این مختصات چک می‌شود
285
+ const calcK = () => {
286
+ // دریافت ابعاد بر مبنای پیکسل آفست و صفحه نمایش
287
+ const clientDims = this.chartArea.getBoundingClientRect()
288
+ // ادریافت ابعاد در واحد ویوباکس
289
+ const vbDims = this.chartArea.getBBox()
290
+ const kx = vbDims.width / clientDims.width
291
+ const ky = vbDims.height / clientDims.height
292
+ return { kx, ky }
293
+ }
294
+
295
+ this.chartArea.addEventListener('mousemove', (e) => {
296
+ const { kx, ky } = calcK();
297
+ let x = e.offsetX * kx
298
+ let y = e.offsetY * ky
299
+ const f = this.currentCordinate.f = +this.getFreq(x).f;
300
+ const vf = this.getFreq(x).vf;
301
+ const i = this.currentCordinate.i = this.getIntensity(y)
302
+
303
+ if (
304
+ f >= 250 && i >= -15 && i <= 125 &&
305
+ (
306
+ this.lastCordinate.f != this.currentCordinate.f ||
307
+ this.lastCordinate.i != this.currentCordinate.i
308
+ )
309
+ ) {
310
+ x = this.getX(vf)
311
+ this.pointer.setAttribute('cx', x)
312
+ y = this.getY(i)
313
+ this.pointer.setAttribute('cy', y)
314
+ }
315
+
316
+ this.lastCordinate.f = this.currentCordinate.f
317
+ this.lastCordinate.i = this.currentCordinate.i
318
+ })
319
+ }
320
+
321
+ // تبدیل مقدار ایکس مختصات به فرکانس
322
+ getFreq(x) {
323
+ let vf = ((x - this.xArea.min) * (this.xAxisLength.hzi / this.xAxisLength.vb));
324
+ // یافتن نزدیک ترین
325
+ // const vfArray = [0, 2, 4, 5.2, 6, 7.2, 8, 9.2, 10, 11.2, 12];
326
+ let i = 0;
327
+ while (vf > this.vfArray[i]) {
328
+ i++;
329
+ }
330
+ // حالا بین دو ایندکس پیدا شده
331
+ const index = ((vf - this.vfArray[i - 1]) > (this.vfArray[i] - vf)) ? i : i - 1;
332
+ return { f: this.vfToF[this.vfArray[index]], vf: this.vfArray[index] };
333
+ }
334
+
335
+ click() {
336
+ // رویداد کلیک برای فراخوانی تابع نشاندن سمبل انتخاب شده
337
+ this.chartArea.addEventListener('click', (e) => {
338
+ const shiftKey = e.shiftKey
339
+ this.updateFreqLine({ shiftKey })
340
+ })
341
+ }
342
+
343
+ updateFreqLine({ shiftKey }) {
344
+ const nr = shiftKey;
345
+ let symbolname = this.currentSymbolName;
346
+ const f = this.currentCordinate.f
347
+ const i = this.currentCordinate.i
348
+ // console.log(f,i);
349
+
350
+ const type = symbolname.slice(2, 4)
351
+ const side = symbolname[0]
352
+ const masked = symbolname[5] === 'M' ? true : false;
353
+ nr && (symbolname += '_NR');
354
+
355
+
356
+ const x = this.getX(this.fToVf[f])
357
+ const y = this.getY(i)
358
+ let dataset = { f, type }
359
+ // اینجا رل های رسم را چک میکنیم
360
+ // اگر در این خط فرکانسی سمبل با تایپ مشابه داریم اول اون رو پاک کن
361
+ // دیتا رو چک ببین این فرکانس هست
362
+ this.removeSymbol({ container: this.svg, dataset })
363
+ dataset = { f, i, symbolname, type, side, masked, nr }
364
+ this.insertSymbol({ container: this.svg, symbolName: symbolname, x, y, dataset })
365
+ // بالا آوردن لایه آخر برای دریافت رویدادهای موس
366
+ this.svg.appendChild(this.chartArea)
367
+
368
+ if (this.data[symbolname] === undefined) this.data[symbolname] = {}
369
+ this.data[symbolname][f] = i
370
+
371
+ }
372
+
373
+ removeSymbol({ container, dataset }) {
374
+ const { side, type, f, i, masked } = dataset
375
+ // ساخت رشته کوئری با توجه به پارامترها
376
+ let query = '';
377
+ side && (query += `[data-side='${side}']`);
378
+ type && (query += `[data-type='${type}']`);
379
+ f && (query += `[data-f='${f}']`);
380
+ i && (query += `[data-i='${i}']`);
381
+ const symbol = container.querySelector(query);
382
+ if (symbol) {
383
+ const symbolname = symbol.dataset.symbolname;
384
+ delete this.data[symbolname][f]
385
+ symbol.remove();
386
+ }
387
+ }
388
+
389
+ // ناپدید شدن خطوط
390
+ mouseEnter() {
391
+ this.chartArea.addEventListener('mouseenter', () => {
392
+ this.svg.focus()
393
+ this.svg.querySelectorAll('[data-name=junction]')
394
+ .forEach(elem => elem.style.display = 'none');
395
+ })
396
+ }
397
+
398
+ // آپدیت با دیتای جدید
399
+ mouseLeave() {
400
+ this.svg.addEventListener('mouseleave', () => {
401
+ this.update({ data: this.data, side: this.side })
402
+ })
403
+ }
404
+
405
+ // تبدیل مختصات ایگرگ سیستمی به مقدار شدت
406
+ getIntensity(y) {
407
+ let i = (this.intensity.min) + (y - this.chartPadding.top) * (this.yAxisLength.db / this.yAxisLength.vb)
408
+ // رند کردن مقدار شدت با محدوده عدد پنج
409
+ const roundStep = 5
410
+ // console.log(Math.round(i / roundStep) * roundStep);
411
+
412
+ return (Math.round(i / roundStep) * roundStep)
413
+ }
414
+ // vf = f index ~ 125: 0, 250: 2, 500: 4, 750:5, ...
415
+ getX(vf) {
416
+ return ((vf - this.vf.min) * (this.xAxisLength.vb / this.xAxisLength.hzi)
417
+ )
418
+ }
419
+ // تبدیل مقدار شدت به دسی بل به مقدار مختصات ایگرگ سیستم
420
+ getY(i) {
421
+ return ((i - this.intensity.min) * (this.yAxisLength.vb / this.yAxisLength.db)
422
+ )
423
+ }
424
+
425
+ update({ data, side }) {
426
+ this.data = data
427
+ // پاک کردن نودهای سمبل دیتای قبلی در صورت وجود از نود مربوطه
428
+ this.svg.querySelectorAll('[data-name=symbol]').forEach(symbol => symbol.remove())
429
+ // پاک کردن خطوط اتصال دیتای قبلی در صورت وجود از نود مربوطه
430
+ this.svg.querySelectorAll('[data-name=junction]').forEach(symbol => symbol.remove())
431
+
432
+ const junctions = { AC: {}, BC: {}, side };
433
+ this.junctions = junctions;
434
+ for (const symbolName in data) {
435
+ for (const f in data[symbolName]) {
436
+ const i = data[symbolName][f];
437
+ const x = this.getX(this.fToVf[f]);
438
+ const y = this.getY(i);
439
+ const dataset = { f: f, i: i, symbolname: symbolName }
440
+ this.insertSymbol({ container: this.svg, symbolName, x, y, dataset });
441
+ // جمع آوری مختصات برای رسم خط بین سمبل ها اینجا انجام می‌شود
442
+ // پراپرتی تایپ فقط راهنمای دیباگ هست و کاربردی ندارد
443
+ let NR = (symbolName.at(-1) === 'R') ? true : false;
444
+ (symbolName.slice(2, 4) === 'AC') && (junctions.AC[f] = { x, y, NR, type: symbolName });
445
+ (symbolName.slice(2, 4) === 'BC') && (junctions.BC[f] = { x, y, NR, type: symbolName });
446
+ }
447
+ }
448
+ this.drawJunctions();
449
+ // بالا آوردن مستطیل احاطه کننده به بالاترین لایه برای دریافت صحیح رویدادهای موس
450
+ this.svg.appendChild(this.chartArea)
451
+ }
452
+
453
+ drawJunctions() {
454
+ // console.log(this.junctions);
455
+ // رسم خط بین نقاط
456
+ const junctions = this.junctions
457
+ let color = (junctions.side === 'R') ? 'red' : 'blue';
458
+
459
+ for (const type in junctions) {
460
+ let x1, y1, x2, y2, NR1, NR2;
461
+ for (const freq in junctions[type]) {
462
+ x1 = x2; y1 = y2; NR1 = NR2
463
+ x2 = junctions[type][freq].x
464
+ y2 = junctions[type][freq].y
465
+ NR2 = junctions[type][freq].NR
466
+ let style =
467
+ type === "BC"
468
+ ? this.styles.juncDashLine + `stroke: ${color}`
469
+ : this.styles.juncLine + `stroke: ${color}`;
470
+ x1 && !NR1 && !NR2 && putLine({ container: this.svg, x1, y1, x2, y2, style, name: 'junction' });
471
+ }
472
+ }
473
+ }
474
+
475
+ insertSymbol({ container, symbolName, x, y, dataset }) {
476
+
477
+ let width = this.symbolDims.width
478
+ console.log(width);
479
+ // width = 7;
480
+
481
+
482
+ const symbol = this.getSymbol(symbolName);
483
+ symbol.setAttribute('x', x - width / 2)
484
+ symbol.setAttribute('y', y - width / 2)
485
+ symbol.setAttribute('width', width)
486
+ symbol.setAttribute('height', width)
487
+ // مقادیر دیتاست را در پراپرتی های دیتا بذار
488
+ for (const key in dataset) {
489
+ symbol.setAttribute('data-' + key, dataset[key])
490
+ }
491
+
492
+ container.appendChild(symbol)
493
+ }
494
+
495
+ getSymbol(symbolName) {
496
+ const point = this.symbols[symbolName].cloneNode(true);
497
+ return point
498
+ }
499
+ }