tapmach 0.2.1 → 0.3.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.
Files changed (2) hide show
  1. package/dist/index.js +52 -8
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -391,11 +391,15 @@ var main_default = `<!DOCTYPE html>
391
391
  </head>
392
392
  <body>
393
393
  <div class="controls-header">
394
+ <div class="status">
395
+ -
396
+ </div>
394
397
  <div class="lang-control">
395
398
  <label for="lang">Mode:</label>
396
399
  <select id="lang">
397
400
  <option value="default">Default</option>
398
401
  <option value="shortcodes">Shortcodes</option>
402
+ <option value="numberless shortcodes">Numberless Shortcodes</option>
399
403
  </select>
400
404
  </div>
401
405
  <div class="speed-control">
@@ -485,6 +489,26 @@ var main_default = `<!DOCTYPE html>
485
489
  }
486
490
  }
487
491
 
492
+ function tokenToCode_Numberless_Shortcodes(code, currentToken, nextToken, speed) {
493
+ if (currentToken === 'cc') {
494
+ code.push('create_cell();');
495
+ } else if (currentToken === 'dc') {
496
+ code.push('destroy_cell();');
497
+ } else if (currentToken === 'add') {
498
+ code.push('add(1);')
499
+ } else if (currentToken === 'sub') {
500
+ code.push('add(-1);')
501
+ } else if (currentToken === 'mov') {
502
+ code.push('move(1);')
503
+ } else if (currentToken === 'vom') {
504
+ code.push('move(-1);')
505
+ } else if (currentToken === 'line_end') {
506
+ code.push(\`await sleep(\${speed});\`);
507
+ } else {
508
+ throw Error(\`Can't parse the code, wrong instruction: \${currentToken}\`);
509
+ }
510
+ }
511
+
488
512
  function convertToCode(text, lang = 'default') {
489
513
  let tokens = parse(text);
490
514
  const speed = document.getElementById('speed').value || 1000;
@@ -494,17 +518,22 @@ var main_default = `<!DOCTYPE html>
494
518
  tokenToCode = tokenToCode_Default;
495
519
  } else if (lang === 'shortcodes') {
496
520
  tokenToCode = tokenToCode_Shortcodes;
521
+ } else if (lang === 'numberless shortcodes') {
522
+ tokenToCode = tokenToCode_Numberless_Shortcodes;
497
523
  } else {
498
524
  tokenToCode = tokenToCode_Default;
499
525
  }
500
526
 
527
+ code.push(\`status.style.color = '#eed49f';status.innerHTML = ' ... ';\`);
528
+
501
529
  for (let i = 0; i < tokens.length; i++) {
502
530
  tokenToCode(code, tokens[i], tokens[i+1], speed);
503
531
  }
504
-
532
+
533
+ code.push(\`status.innerHTML = ' :) ';status.style.color = '#a6da95';setTimeout(() => { status.style.color = '#cad3f5'; status.innerHTML = ' - '; }, 2000);\`);
505
534
  code.push('})();')
506
535
  code = code.join('');
507
-
536
+
508
537
  return code;
509
538
  }
510
539
  </script>
@@ -556,7 +585,7 @@ var main_default = `<!DOCTYPE html>
556
585
  let current_cell = 0;
557
586
  let list = [];
558
587
 
559
- async function update() {
588
+ function update() {
560
589
  if (cells.length === 0) return;
561
590
 
562
591
  const target = cells[current_cell];
@@ -569,7 +598,7 @@ var main_default = `<!DOCTYPE html>
569
598
  target.classList.add('animate-update')
570
599
  }
571
600
 
572
- async function create_cell() {
601
+ function create_cell() {
573
602
  const val = 0;
574
603
  const div = document.createElement('div');
575
604
  div.classList.add('cell', 'animate-create', \`i\${list.length+1}\`);
@@ -592,17 +621,30 @@ var main_default = `<!DOCTYPE html>
592
621
  update();
593
622
  }
594
623
 
595
- async function destroy_cell() {
624
+ function destroy_cell() {
596
625
  const target = cells[current_cell];
597
626
  if (typeof target === null) return;
598
627
 
599
628
  target.classList.add('animate-destroy');
600
629
 
601
- setTimeout(() => target.remove(), 300);
602
- move(-1);
630
+ setTimeout(() => {
631
+ target.remove();
632
+ }, 300);
633
+ if (current_cell === 0) {
634
+ move(1);
635
+ list.splice(current_cell-1, 1);
636
+ cells.splice(current_cell-1, 1);
637
+ current_cell = 0;
638
+ } else {
639
+ move(-1);
640
+ list.splice(current_cell+1, 1);
641
+ cells.splice(current_cell+1, 1);
642
+ }
643
+
644
+ console.log(current_cell);
603
645
  }
604
646
 
605
- async function move(index) {
647
+ function move(index) {
606
648
  if (current_cell+index < 0 || current_cell+index >= cells.length) return;
607
649
 
608
650
  previous_cell = current_cell;
@@ -631,9 +673,11 @@ var main_default = `<!DOCTYPE html>
631
673
 
632
674
  <script>
633
675
  const button = document.querySelector('.run-btn');
676
+ const status = document.querySelector('.status');
634
677
  button.addEventListener('click', async (e) => {
635
678
  let text = localStorage.getItem('text-content');
636
679
  let selectedLang = localStorage.getItem('selectedLang');
680
+
637
681
  eval(convertToCode(text, selectedLang));
638
682
  })
639
683
  </script>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tapmach",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "module": "./src/index.ts",
5
5
  "type": "module",
6
6
  "private": false,