A pixel art painter geared specifically at NES pixel art. Includes export for .chr binary file as well as palette and namespace data.
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.

jst.js 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. class ENode{
  2. constructor(tag){
  3. this.__tag = tag;
  4. this.__classes = [];
  5. this.__attribs = [];
  6. this.__children = [];
  7. }
  8. appendChild(c){
  9. var val = (c instanceof ENode) ? c : c.toString();
  10. this.__children.push(c);
  11. return this;
  12. }
  13. addClass(cname){
  14. this.__classes.push(cname);
  15. }
  16. addAttribute(aname, aval){
  17. this.__attribs.push([aname, aval]);
  18. }
  19. toString(){
  20. var r = "<" + this.__tag.toUpperCase();
  21. if (this.__attribs.length > 0){
  22. var attr = this.__attribs.reduce(function(a, at){
  23. a += ((a !== "") ? " " : "") + at[0].trim() + "=\"" + at[1] + "\"";
  24. return a;
  25. }, "");
  26. r += " " + attr;
  27. }
  28. if (this.__children.length > 0){
  29. r += ">";
  30. r += this.__children.reduce(function(a, c){
  31. if (c instanceof ENode){
  32. a += c.toString() + "\n";
  33. } else {
  34. a += c;
  35. }
  36. return a;
  37. }, "");
  38. r += "</" + this.__tag.toUpperCase() + ">";
  39. } else {
  40. r += " />";
  41. }
  42. return r;
  43. }
  44. }
  45. function el(){
  46. if (arguments.length < 1)
  47. throw new Error("Invalid number of arguments.");
  48. var ename = arguments[0];
  49. var args = Array.prototype.slice.call(arguments, 1);
  50. var e = new ENode(ename);
  51. args.forEach(function(item){
  52. if (item === null){return;}
  53. // If given an array, assume it to be an array children.
  54. if (item instanceof Array){
  55. item.forEach(itm => e.appendChild((itm instanceof ENode) ? itm : itm.toString()));
  56. // If given an ENode, then it IS a child
  57. } else if (item instanceof ENode){
  58. e.appendChild(item);
  59. // All objects are assumed to be attributes.
  60. } else if (item instanceof Object){
  61. var keys = Object.keys(item);
  62. keys.forEach(function(key){
  63. if (item.hasOwnProperty(key)){
  64. if (typeof(item[key]) === "string"){
  65. e.addAttribute(key.toString(), item[key]);
  66. }
  67. }
  68. });
  69. // Everything else is assumed to be a child.
  70. } else {
  71. e.appendChild(item.toString());
  72. }
  73. });
  74. return e;
  75. }
  76. module.exports = {
  77. ENode: ENode,
  78. el: el,
  79. html: el.bind(null, "html"),
  80. head: el.bind(null, "head"),
  81. title: el.bind(null, "title"),
  82. script: el.bind(null, "script"),
  83. link: el.bind(null, "link"),
  84. meta: el.bind(null, "meta"),
  85. body: el.bind(null, "body"),
  86. div: el.bind(null, "div"),
  87. span: el.bind(null, "span"),
  88. a: el.bind(null, "a"),
  89. p: el.bind(null, "p"),
  90. b: el.bind(null, "b"),
  91. i: el.bind(null, "i"),
  92. br: el.bind(null, "br"),
  93. ol: el.bind(null, "ol"),
  94. ul: el.bind(null, "ul"),
  95. li: el.bind(null, "li"),
  96. em: el.bind(null, "em"),
  97. img: el.bind(null, "img"),
  98. font: el.bind(null, "font"),
  99. h1: el.bind(null, "h1"),
  100. h2: el.bind(null, "h2"),
  101. h3: el.bind(null, "h3"),
  102. h4: el.bind(null, "h4"),
  103. h5: el.bind(null, "h5"),
  104. h6: el.bind(null, "h6"),
  105. hr: el.bind(null, "hr"),
  106. blockquote: el.bind(null, "blockquote"),
  107. button: el.bind(null, "button"),
  108. nav: el.bind(null, "nav"),
  109. canvas: el.bind(null, "canvas"),
  110. caption: el.bind(null, "caption")
  111. };