Gets the name of a number, even if it's stupidly big. Supersedes TheoryOfNekomata/number-name.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. <!DOCTYPE html>
  2. <html lang="en-PH">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>@modal-sh/numerica-core</title>
  6. <meta name="viewport" content="width=device-width, initial-scale=1">
  7. <style>
  8. .main-form {
  9. position: fixed;
  10. top: 0;
  11. left: 0;
  12. width: 100%;
  13. height: 100%;
  14. display: flex;
  15. flex-direction: column;
  16. align-items: stretch;
  17. }
  18. .main-form > fieldset {
  19. display: contents;
  20. }
  21. .main-form > fieldset > div {
  22. padding: 1rem;
  23. box-sizing: border-box;
  24. display: flex;
  25. gap: 1rem;
  26. }
  27. .main-form > fieldset > legend {
  28. position: absolute;
  29. left: -999999px;
  30. }
  31. .main-form > div {
  32. flex-direction: column;
  33. display: flex;
  34. flex: auto;
  35. }
  36. .main-form > div > textarea {
  37. flex: auto;
  38. width: 100%;
  39. height: 0;
  40. font-size: 1.5rem;
  41. padding: 1rem;
  42. border: 0;
  43. outline: 0;
  44. resize: none;
  45. box-sizing: border-box;
  46. }
  47. .main-form > div > textarea:invalid {
  48. color: red;
  49. }
  50. .select {
  51. font: inherit;
  52. padding: 0 1rem;
  53. }
  54. .checkbox > input {
  55. position: absolute;
  56. left: -999999px;
  57. }
  58. .checkbox > input + span {
  59. display: inline-flex;
  60. align-items: center;
  61. justify-content: center;
  62. height: 3rem;
  63. padding: 0 1rem;
  64. border: 1px solid #ccc;
  65. border-radius: 0.25rem;
  66. cursor: pointer;
  67. }
  68. .checkbox > input:checked + span {
  69. border-color: #000;
  70. background-color: #000;
  71. color: #fff;
  72. }
  73. @media (min-width: 1080px) {
  74. .main-form > div {
  75. flex-direction: row;
  76. }
  77. .main-form > div > textarea {
  78. width: 0;
  79. height: 100%;
  80. }
  81. }
  82. </style>
  83. </head>
  84. <body>
  85. <form id="mainForm" class="main-form">
  86. <fieldset>
  87. <legend>
  88. Options
  89. </legend>
  90. <div>
  91. <select class="select" aria-label="Locale" name="system.locale">
  92. <option value="enUS">
  93. English (US)
  94. </option>
  95. <option value="enUK">
  96. English (UK)
  97. </option>
  98. </select>
  99. <select class="select" aria-label="Variant" name="system.count">
  100. <option value="shortCount">
  101. Short Count
  102. </option>
  103. <option value="longCount">
  104. Long Count
  105. </option>
  106. </select>
  107. <label class="checkbox">
  108. <input type="checkbox" name="shortenMillia">
  109. <span>Shorten millia</span>
  110. </label><label class="checkbox">
  111. <input type="checkbox" name="addTensDashes" checked>
  112. <span>Add dashes to tens</span>
  113. </label><label class="checkbox">
  114. <input type="checkbox" name="oneGroupPerLine" checked>
  115. <span>One group per line</span>
  116. </label><!--<label class="checkbox">
  117. <input type="groupDigits" name="groupDigits" checked>
  118. <span>Group digits</span>
  119. </label>-->
  120. </div>
  121. </fieldset>
  122. <div>
  123. <textarea aria-label="Number" name="number" placeholder="1234"></textarea>
  124. <textarea aria-label="Name" name="name" placeholder="one thousand&#x0A;two hundred thirty-four"></textarea>
  125. </div>
  126. </form>
  127. <script type="module">
  128. import { stringify, parse, systems } from './numerica.js';
  129. function MainForm(el) {
  130. const numberInput = el.querySelector('[name="number"]');
  131. const nameInput = el.querySelector('[name="name"]');
  132. const addTensDashesCheckbox = el.querySelector('[name="addTensDashes"]');
  133. const shortenMilliaCheckbox = el.querySelector('[name="shortenMillia"]');
  134. const oneGroupPerLineCheckbox = el.querySelector('[name="oneGroupPerLine"]');
  135. const localeSelect = el.querySelector('[name="system.locale"]');
  136. const variantSelect = el.querySelector('[name="system.count"]');
  137. const options = {
  138. stringify: {
  139. stringifyGroupsOptions: {},
  140. mergeTokensOptions: {},
  141. },
  142. parse: {
  143. type: 'bigint',
  144. },
  145. };
  146. const createNamePlaceholder = (theOptions) => {
  147. return stringify(1234, theOptions.stringify);
  148. };
  149. numberInput.addEventListener('input', (e) => {
  150. e.currentTarget.setCustomValidity('');
  151. nameInput.value = '';
  152. if (e.currentTarget.value.trim() === '') {
  153. return;
  154. }
  155. try {
  156. nameInput.value = stringify(e.currentTarget.value, options.stringify);
  157. } catch (err) {
  158. console.error(err);
  159. e.currentTarget.setCustomValidity('Invalid number.');
  160. }
  161. });
  162. nameInput.addEventListener('input', (e) => {
  163. e.currentTarget.setCustomValidity('');
  164. numberInput.value = '';
  165. if (e.currentTarget.value.trim() === '') {
  166. return;
  167. }
  168. let newValue;
  169. try {
  170. newValue = parse(e.currentTarget.value, options.parse)
  171. } catch (err) {
  172. console.error(err);
  173. e.currentTarget.setCustomValidity('Invalid name.');
  174. }
  175. numberInput.value = newValue.toString();
  176. // TODO group digits function from system.
  177. });
  178. addTensDashesCheckbox.addEventListener('change', (e) => {
  179. options.stringify.stringifyGroupsOptions.addTensDashes = e.currentTarget.checked;
  180. numberInput.dispatchEvent(new Event('input'));
  181. nameInput.placeholder = createNamePlaceholder(options);
  182. });
  183. shortenMilliaCheckbox.addEventListener('change', (e) => {
  184. options.stringify.stringifyGroupsOptions.shortenMillia = e.currentTarget.checked;
  185. numberInput.dispatchEvent(new Event('input'));
  186. nameInput.placeholder = createNamePlaceholder(options);
  187. });
  188. oneGroupPerLineCheckbox.addEventListener('change', (e) => {
  189. options.stringify.mergeTokensOptions.oneGroupPerLine = e.currentTarget.checked;
  190. numberInput.dispatchEvent(new Event('input'));
  191. nameInput.placeholder = createNamePlaceholder(options);
  192. });
  193. localeSelect.addEventListener('change', (e) => {
  194. const variantOptions = Array.from(variantSelect.options);
  195. variantOptions.forEach((option) => {
  196. option.disabled = !systems[e.currentTarget.value][option.value];
  197. });
  198. variantSelect.value = variantOptions.find((option) => !option.disabled).value;
  199. options.stringify.system = systems[e.currentTarget.value][variantSelect.value];
  200. options.parse.system = systems[e.currentTarget.value][variantSelect.value];
  201. numberInput.dispatchEvent(new Event('input'));
  202. nameInput.placeholder = createNamePlaceholder(options);
  203. });
  204. variantSelect.addEventListener('change', (e) => {
  205. options.stringify.system = systems[localeSelect.value][e.currentTarget.value];
  206. options.parse.system = systems[localeSelect.value][e.currentTarget.value];
  207. numberInput.dispatchEvent(new Event('input'));
  208. nameInput.placeholder = createNamePlaceholder(options);
  209. });
  210. options.stringify.stringifyGroupsOptions.addTensDashes = addTensDashesCheckbox.checked;
  211. options.stringify.stringifyGroupsOptions.shortenMillia = shortenMilliaCheckbox.checked;
  212. options.stringify.mergeTokensOptions.oneGroupPerLine = oneGroupPerLineCheckbox.checked;
  213. options.stringify.system = systems[localeSelect.value][variantSelect.value];
  214. options.parse.system = systems[localeSelect.value][variantSelect.value];
  215. Array.from(variantSelect.options).forEach((option) => {
  216. option.disabled = !systems[localeSelect.value][option.value];
  217. });
  218. nameInput.placeholder = createNamePlaceholder(options);
  219. }
  220. const mainForm = window.document.getElementById('mainForm');
  221. new MainForm(mainForm);
  222. </script>
  223. </body>
  224. </html>