koffing 0.5.0 → 1.0.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 (64) hide show
  1. package/LICENSE +2 -2
  2. package/README.md +6 -180
  3. package/dist/index.d.ts +106 -0
  4. package/dist/index.js +431 -0
  5. package/dist/index.mjs +400 -0
  6. package/package.json +24 -40
  7. package/Makefile +0 -21
  8. package/build/asset-manifest.json +0 -22
  9. package/build/favicon.png +0 -0
  10. package/build/index.html +0 -1
  11. package/build/precache-manifest.5382b78dea2866c8a94cee003da35d84.js +0 -26
  12. package/build/robots.txt +0 -3
  13. package/build/service-worker.js +0 -39
  14. package/build/static/css/main.102b9840.chunk.css +0 -2
  15. package/build/static/css/main.102b9840.chunk.css.map +0 -1
  16. package/build/static/js/2.4b3dd85a.chunk.js +0 -3
  17. package/build/static/js/2.4b3dd85a.chunk.js.LICENSE.txt +0 -67
  18. package/build/static/js/2.4b3dd85a.chunk.js.map +0 -1
  19. package/build/static/js/main.07f66bec.chunk.js +0 -2
  20. package/build/static/js/main.07f66bec.chunk.js.map +0 -1
  21. package/build/static/js/runtime-main.525bb0ff.js +0 -2
  22. package/build/static/js/runtime-main.525bb0ff.js.map +0 -1
  23. package/public/favicon.png +0 -0
  24. package/public/index.html +0 -30
  25. package/public/robots.txt +0 -3
  26. package/src/App.test.js +0 -9
  27. package/src/components/App.js +0 -18
  28. package/src/components/AppFooter/AppFooter.css.js +0 -12
  29. package/src/components/AppFooter/AppFooter.js +0 -31
  30. package/src/components/AppFooter/index.js +0 -3
  31. package/src/components/AppHeader/AppHeader.css.js +0 -21
  32. package/src/components/AppHeader/AppHeader.js +0 -34
  33. package/src/components/AppHeader/index.js +0 -3
  34. package/src/components/Board/Board.css.js +0 -21
  35. package/src/components/Board/Board.js +0 -110
  36. package/src/components/Board/index.js +0 -3
  37. package/src/components/BoardInput/BoardInput.css.js +0 -14
  38. package/src/components/BoardInput/BoardInput.js +0 -36
  39. package/src/components/BoardInput/index.js +0 -3
  40. package/src/components/BoardOutput/BoardOutput.css.js +0 -17
  41. package/src/components/BoardOutput/BoardOutput.js +0 -36
  42. package/src/components/BoardOutput/index.js +0 -3
  43. package/src/components/Code/Code.css.js +0 -10
  44. package/src/components/Code/Code.js +0 -28
  45. package/src/components/Code/index.js +0 -3
  46. package/src/components/StyledComponent.js +0 -24
  47. package/src/components/ThemedApp.js +0 -25
  48. package/src/core/Koffing.js +0 -71
  49. package/src/core/Pokemon.js +0 -181
  50. package/src/core/PokemonTeam.js +0 -78
  51. package/src/core/PokemonTeamSet.js +0 -52
  52. package/src/core/ShowdownParser.js +0 -280
  53. package/src/core/index.js +0 -7
  54. package/src/img/koffing-shiny.png +0 -0
  55. package/src/img/koffing.png +0 -0
  56. package/src/index.css +0 -42
  57. package/src/index.js +0 -17
  58. package/src/serviceWorker.js +0 -141
  59. package/src/setupTests.js +0 -5
  60. package/src/teams/example.koffing.js +0 -25
  61. package/src/tools/base64.js +0 -25
  62. package/src/tools/history.js +0 -17
  63. package/src/tools/index.js +0 -4
  64. package/src/variables.json +0 -5
package/dist/index.js ADDED
@@ -0,0 +1,431 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ Koffing: () => Koffing,
24
+ Pokemon: () => Pokemon,
25
+ PokemonTeam: () => PokemonTeam,
26
+ PokemonTeamSet: () => PokemonTeamSet,
27
+ ShowdownParser: () => ShowdownParser
28
+ });
29
+ module.exports = __toCommonJS(src_exports);
30
+
31
+ // src/Pokemon.ts
32
+ var POKEMON_STAT_NAMES = ["HP", "Atk", "Def", "SpA", "SpD", "Spe"];
33
+ var Pokemon = class {
34
+ constructor() {
35
+ this.moves = [];
36
+ }
37
+ static fromObject(obj) {
38
+ const p = new Pokemon();
39
+ p.name = obj.name;
40
+ p.nickname = obj.nickname;
41
+ p.gender = obj.gender;
42
+ p.item = obj.item;
43
+ p.ability = obj.ability;
44
+ p.level = obj.level;
45
+ p.shiny = obj.shiny;
46
+ p.happiness = obj.happiness;
47
+ p.nature = obj.nature;
48
+ p.evs = obj.evs;
49
+ p.ivs = obj.ivs;
50
+ p.teraType = obj.teraType;
51
+ p.dynamaxLevel = obj.dynamaxLevel;
52
+ p.gigantamax = obj.gigantamax;
53
+ p.pokeball = obj.pokeball;
54
+ p.moves = Array.isArray(obj.moves) ? obj.moves : [];
55
+ return p;
56
+ }
57
+ toJson(indentation = 2) {
58
+ return JSON.stringify(this, null, indentation);
59
+ }
60
+ toShowdown() {
61
+ let str = "";
62
+ if (this.nickname) {
63
+ str += `${this.nickname} (${this.name})`;
64
+ } else {
65
+ str += `${this.name}`;
66
+ }
67
+ if (this.gender && this.gender.match(/^[MF]$/i)) {
68
+ str += ` (${this.gender.toUpperCase()})`;
69
+ }
70
+ if (this.item) {
71
+ str += ` @ ${this.item}`;
72
+ }
73
+ str += "\n";
74
+ if (this.ability) {
75
+ str += `Ability: ${this.ability}
76
+ `;
77
+ }
78
+ if (!Number.isNaN(this.level)) {
79
+ str += `Level: ${this.level}
80
+ `;
81
+ }
82
+ if (this.shiny === true) {
83
+ str += `Shiny: Yes
84
+ `;
85
+ }
86
+ if (!Number.isNaN(this.happiness)) {
87
+ str += `Happiness: ${this.happiness}
88
+ `;
89
+ }
90
+ if (this.pokeball) {
91
+ str += `Pokeball: ${this.pokeball}
92
+ `;
93
+ }
94
+ if (!Number.isNaN(this.dynamaxLevel)) {
95
+ str += `Dynamax Level: ${this.dynamaxLevel}
96
+ `;
97
+ }
98
+ if (this.gigantamax === true) {
99
+ str += `Gigantamax: Yes
100
+ `;
101
+ }
102
+ if (this.teraType) {
103
+ str += `Tera Type: ${this.teraType}
104
+ `;
105
+ }
106
+ if (this.evs) {
107
+ const evs = this.evs;
108
+ str += `EVs: ` + POKEMON_STAT_NAMES.filter(function(prop) {
109
+ return !isNaN(evs[prop.toLowerCase()]);
110
+ }).map(function(prop) {
111
+ const val = evs[prop.toLowerCase()];
112
+ return `${val} ${prop}`;
113
+ }).join(" / ") + "\n";
114
+ }
115
+ if (this.nature) {
116
+ str += `${this.nature} Nature
117
+ `;
118
+ }
119
+ if (this.ivs) {
120
+ const ivs = this.ivs;
121
+ str += `IVs: ` + POKEMON_STAT_NAMES.filter(function(prop) {
122
+ return !isNaN(ivs[prop.toLowerCase()]);
123
+ }).map(function(prop) {
124
+ const val = ivs[prop.toLowerCase()];
125
+ return `${val} ${prop}`;
126
+ }).join(" / ") + "\n";
127
+ }
128
+ if (this.moves) {
129
+ str += this.moves.map(function(move) {
130
+ return `- ${move}`;
131
+ }).join("\n") + "\n";
132
+ }
133
+ return str.trim();
134
+ }
135
+ toString() {
136
+ return this.toShowdown();
137
+ }
138
+ };
139
+
140
+ // src/PokemonTeam.ts
141
+ var PokemonTeam = class {
142
+ constructor(format = "gen9", name = "Untitled", folder = void 0) {
143
+ this.pokemon = [];
144
+ this.name = name;
145
+ this.format = format;
146
+ this.folder = folder;
147
+ }
148
+ static fromObject(obj) {
149
+ const team = new PokemonTeam();
150
+ team.name = obj.name;
151
+ team.format = obj.format;
152
+ team.folder = obj.folder;
153
+ team.pokemon = obj.pokemon ? obj.pokemon.map(function(pokemon) {
154
+ return Pokemon.fromObject(pokemon);
155
+ }) : [];
156
+ return team;
157
+ }
158
+ toJson(indentation = 2) {
159
+ return JSON.stringify(this, null, indentation);
160
+ }
161
+ toShowdown() {
162
+ const name = this.folder ? `${this.folder}/${this.name}` : this.name;
163
+ let str = `=== [${this.format}] ${name} ===
164
+
165
+ `;
166
+ str += this.pokemon.map(function(p) {
167
+ return p.toString();
168
+ }).join("\n\n");
169
+ return str.trim();
170
+ }
171
+ toString() {
172
+ return this.toShowdown();
173
+ }
174
+ };
175
+
176
+ // src/PokemonTeamSet.ts
177
+ var PokemonTeamSet = class {
178
+ constructor(teams = []) {
179
+ this.teams = teams;
180
+ }
181
+ static fromObject(obj) {
182
+ const teamSet = new PokemonTeamSet();
183
+ teamSet.teams = obj.teams ? obj.teams.map(function(team) {
184
+ return PokemonTeam.fromObject(team);
185
+ }) : [];
186
+ return teamSet;
187
+ }
188
+ toJson(indentation = 2) {
189
+ return JSON.stringify(this, null, indentation);
190
+ }
191
+ toShowdown() {
192
+ return this.teams.map(function(p) {
193
+ return p.toString();
194
+ }).join("\n\n").trim();
195
+ }
196
+ toString() {
197
+ return this.toShowdown();
198
+ }
199
+ };
200
+
201
+ // src/ShowdownParser.ts
202
+ var clamp = (num, min, max) => {
203
+ if (Number.isNaN(num)) {
204
+ return min;
205
+ }
206
+ return Math.min(Math.max(num, min), max);
207
+ };
208
+ var _ShowdownParser = class {
209
+ constructor(code) {
210
+ this.code = code.toString().trim();
211
+ }
212
+ parse() {
213
+ const regexes = _ShowdownParser.regexes;
214
+ const teams = [];
215
+ const current = {
216
+ team: null,
217
+ pokemon: null
218
+ };
219
+ const lines = this.code.trim().split("\n").map(function(line) {
220
+ return line.trim();
221
+ });
222
+ lines.forEach((line) => {
223
+ if (line.match(regexes.team)) {
224
+ current.team = new PokemonTeam();
225
+ this._parseTeam(line, current.team);
226
+ teams.push(current.team);
227
+ return;
228
+ }
229
+ if (line === "" || line.match(/^[- ]+$/)) {
230
+ this._saveCurrent(teams, current);
231
+ return;
232
+ }
233
+ if (!current.pokemon) {
234
+ current.pokemon = new Pokemon();
235
+ this._parseNameLine(line, current.pokemon);
236
+ return;
237
+ }
238
+ if (this._parseKeyValuePairs(line, current.pokemon)) {
239
+ return;
240
+ }
241
+ if (this._parseEvsIvs(line, current.pokemon)) {
242
+ return;
243
+ }
244
+ if (current.pokemon.moves.length < 4 && line.match(regexes.move)) {
245
+ const moveMatches = regexes.move.exec(line);
246
+ if (moveMatches !== null) {
247
+ current.pokemon.moves.push(moveMatches[1].trim());
248
+ }
249
+ }
250
+ });
251
+ this._saveCurrent(teams, current);
252
+ return new PokemonTeamSet(teams);
253
+ }
254
+ _parseTeam(line, team) {
255
+ const rg = _ShowdownParser.regexes;
256
+ const teamDataMatches = rg.team.exec(line);
257
+ if (teamDataMatches && teamDataMatches.length >= 2) {
258
+ const teamNames = teamDataMatches[2].split("/");
259
+ let teamName, teamFolder;
260
+ if (teamNames.length > 1) {
261
+ teamFolder = teamNames.shift();
262
+ teamName = teamNames.join("/");
263
+ } else {
264
+ teamName = teamDataMatches[2];
265
+ }
266
+ team.format = teamDataMatches[1].trim();
267
+ team.name = teamName.trim();
268
+ team.folder = teamFolder ? teamFolder.trim() : void 0;
269
+ }
270
+ }
271
+ _parseNameLine(line, pokemon) {
272
+ const rg = _ShowdownParser.regexes;
273
+ if (line.match(rg.nickname_name)) {
274
+ const nameMatches = rg.nickname_name.exec(line);
275
+ if (nameMatches) {
276
+ pokemon.nickname = nameMatches[1].trim();
277
+ pokemon.name = nameMatches[2].trim();
278
+ }
279
+ } else if (line.match(rg.name)) {
280
+ const nameMatches = rg.name.exec(line);
281
+ if (nameMatches) {
282
+ pokemon.name = nameMatches[1].trim();
283
+ }
284
+ }
285
+ if (line.match(rg.gender)) {
286
+ const genderMatches = rg.gender.exec(line);
287
+ if (genderMatches) {
288
+ pokemon.gender = genderMatches[1].toUpperCase().trim();
289
+ }
290
+ }
291
+ if (line.match(rg.item)) {
292
+ const itemMatches = rg.item.exec(line);
293
+ if (itemMatches) {
294
+ pokemon.item = itemMatches[1].trim();
295
+ }
296
+ }
297
+ }
298
+ _parseEvsIvs(line, pokemon) {
299
+ const rg = _ShowdownParser.regexes;
300
+ if (line.match(rg.eivs)) {
301
+ const data = rg.eivs.exec(line);
302
+ if (data === null) {
303
+ return false;
304
+ }
305
+ const prop = data[1].toLowerCase();
306
+ const values = data[2].split("/");
307
+ const limit = prop === "evs" ? 255 : 31;
308
+ values.forEach(function(stat) {
309
+ const statData = rg.eivs_value.exec(stat.trim().toLowerCase());
310
+ if (!statData) {
311
+ console.error("Invalid syntax for " + prop + ": " + stat);
312
+ return;
313
+ }
314
+ if (!pokemon[prop]) {
315
+ pokemon[prop] = {};
316
+ }
317
+ pokemon[prop][statData[2]] = clamp(parseInt(statData[1]), 0, limit);
318
+ });
319
+ return true;
320
+ }
321
+ return false;
322
+ }
323
+ _parseKeyValuePairs(line, pokemon) {
324
+ const propNames = [
325
+ "nature",
326
+ "ability",
327
+ "level",
328
+ "shiny",
329
+ "happiness",
330
+ "pokeball",
331
+ "dynamaxLevel",
332
+ "gigantamax",
333
+ "teraType"
334
+ ];
335
+ return propNames.some(function(key) {
336
+ const matches = _ShowdownParser.regexes[key].exec(line);
337
+ if (matches === null) {
338
+ return false;
339
+ }
340
+ let value = matches[1].trim();
341
+ if (key === "happiness") {
342
+ value = clamp(parseInt(value), 0, 255);
343
+ } else if (key === "level") {
344
+ value = clamp(parseInt(value), 1, 100);
345
+ } else if (key === "dynamaxLevel") {
346
+ value = clamp(parseInt(value), 0, 10);
347
+ } else if (key.match(/^(shiny|gigantamax)$/i)) {
348
+ value = value.match(/yes/i) !== null ? true : void 0;
349
+ }
350
+ pokemon[key] = value;
351
+ return true;
352
+ });
353
+ }
354
+ _saveCurrent(teams, current) {
355
+ if (!current.team) {
356
+ current.team = new PokemonTeam();
357
+ teams.push(current.team);
358
+ }
359
+ if (current.pokemon) {
360
+ current.team.pokemon.push(current.pokemon);
361
+ current.pokemon = null;
362
+ }
363
+ return this;
364
+ }
365
+ format() {
366
+ this.code = this.parse().toString();
367
+ return this;
368
+ }
369
+ toString() {
370
+ return this.code;
371
+ }
372
+ };
373
+ var ShowdownParser = _ShowdownParser;
374
+ ShowdownParser.regexes = {
375
+ team: /^===\s+\[(.*)\]\s+(.*)\s+===$/,
376
+ nickname_name: /^([^()=@]*)\s+\(([^()=@]{2,})\)/i,
377
+ name: /^([^()=@]{2,})/i,
378
+ gender: /\((F|M)\)/i,
379
+ item: /@\s?(.*)$/i,
380
+ eivs: /^([EI]Vs):\s?(.*)$/i,
381
+ eivs_value: /^([0-9]+)\s+(hp|atk|def|spa|spd|spe)$/i,
382
+ move: /^[-~]\s?(.*)$/i,
383
+ nature: /^(.*)\s+Nature$/,
384
+ ability: /^(?:Ability|Trait):\s?(.*)$/i,
385
+ level: /^Level:\s?([0-9]{1,3})$/i,
386
+ shiny: /^Shiny:\s?(Yes|No)$/i,
387
+ happiness: /^(?:Happiness|Friendship):\s?([0-9]{1,3})$/i,
388
+ pokeball: /^(?:Pokeball|Ball):\s?(.*)$/i,
389
+ dynamaxLevel: /^Dynamax Level:\s?([0-9]{1,2})$/i,
390
+ gigantamax: /^Gigantamax:\s?(Yes|No)$/i,
391
+ teraType: /^Tera Type:\s?(.*)$/i
392
+ };
393
+
394
+ // src/Koffing.ts
395
+ var Koffing = class {
396
+ static parse(data) {
397
+ if (data instanceof PokemonTeamSet || data instanceof PokemonTeam || data instanceof Pokemon) {
398
+ return data;
399
+ }
400
+ if (data instanceof ShowdownParser) {
401
+ return data.parse();
402
+ }
403
+ return new ShowdownParser(data).parse();
404
+ }
405
+ static format(data) {
406
+ return this.parse(data).toShowdown();
407
+ }
408
+ static toJson(data) {
409
+ return this.parse(data).toJson();
410
+ }
411
+ static toShowdown(data) {
412
+ if (data instanceof PokemonTeamSet || data instanceof PokemonTeam || data instanceof Pokemon) {
413
+ return data.toShowdown();
414
+ }
415
+ if (data instanceof ShowdownParser) {
416
+ return data.parse().toShowdown();
417
+ }
418
+ if (typeof data === "string") {
419
+ data = JSON.parse(data);
420
+ }
421
+ return PokemonTeamSet.fromObject(data).toShowdown();
422
+ }
423
+ };
424
+ // Annotate the CommonJS export names for ESM import in node:
425
+ 0 && (module.exports = {
426
+ Koffing,
427
+ Pokemon,
428
+ PokemonTeam,
429
+ PokemonTeamSet,
430
+ ShowdownParser
431
+ });