A pixel art painter geared specifically at NES pixel art. Includes export for .chr binary file as well as palette and namespace data.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

jst.js 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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.__classes.length > 0){
  22. var cls = this.__classes.reduce(function(a, c){
  23. c = c.split(" ");
  24. for (var i=0; i < c.length; i++){
  25. c[i] = c[i].trim();
  26. a += ((a !== "" && c[i].length > 0) ? " " : "") + c[i];
  27. }
  28. return a;
  29. }, "");
  30. r += " class=\"" + cls + "\"";
  31. }
  32. if (this.__attribs.length > 0){
  33. var attr = this.__attribs.reduce(function(a, at){
  34. a += ((a !== "") ? " " : "") + at[0].trim() + "=\"" + at[1] + "\"";
  35. return a;
  36. }, "");
  37. r += " " + attr;
  38. }
  39. if (this.__children.length > 0){
  40. r += ">";
  41. r += this.__children.reduce(function(a, c){
  42. if (c instanceof ENode){
  43. a += c.toString() + "\n";
  44. } else {
  45. a += c;
  46. }
  47. return a;
  48. }, "");
  49. r += "</" + this.__tag.toUpperCase() + ">";
  50. } else {
  51. r += " />";
  52. }
  53. return r;
  54. }
  55. }
  56. function appendCTX(el, ctx){
  57. el.appendChild((ctx instanceof ENode) ? ctx : ctx.toString());
  58. }
  59. function el(ename, ctx, cls, attr){
  60. var e = new ENode(ename);
  61. if (ctx){
  62. if (ctx instanceof Array){
  63. ctx.forEach(item => appendCTX(e, item));
  64. } else {
  65. appendCTX(e, ctx);
  66. }
  67. }
  68. if (cls){
  69. var cl = cls;
  70. if (typeof(cl) === "String")
  71. cl = cl.split(" ");
  72. if (cl instanceof Array){
  73. cl.forEach(c => e.addClass(c.trim()));
  74. }
  75. }
  76. if (attr){
  77. var keys = Object.keys(attr);
  78. keys.forEach(function(key){
  79. if (attr.hasOwnProperty(key)){
  80. if (typeof(attr[key]) === "string"){
  81. e.addAttribute(key.toString(), attr[key]);
  82. }
  83. }
  84. });
  85. }
  86. return e;
  87. }
  88. module.exports = {
  89. ENode: ENode,
  90. el: el,
  91. html: el.bind(null, "html"),
  92. head: el.bind(null, "head"),
  93. title: el.bind(null, "title"),
  94. script: el.bind(null, "script"),
  95. link: el.bind(null, "link"),
  96. meta: el.bind(null, "meta"),
  97. body: el.bind(null, "body"),
  98. div: el.bind(null, "div"),
  99. span: el.bind(null, "span"),
  100. a: el.bind(null, "a"),
  101. p: el.bind(null, "p"),
  102. b: el.bind(null, "b"),
  103. i: el.bind(null, "i"),
  104. br: el.bind(null, "br"),
  105. ol: el.bind(null, "ol"),
  106. ul: el.bind(null, "ul"),
  107. li: el.bind(null, "li"),
  108. em: el.bind(null, "em"),
  109. img: el.bind(null, "img"),
  110. font: el.bind(null, "font"),
  111. h1: el.bind(null, "h1"),
  112. h2: el.bind(null, "h2"),
  113. h3: el.bind(null, "h3"),
  114. h4: el.bind(null, "h4"),
  115. h5: el.bind(null, "h5"),
  116. h6: el.bind(null, "h6"),
  117. hr: el.bind(null, "hr"),
  118. blockquote: el.bind(null, "blockquote"),
  119. button: el.bind(null, "button"),
  120. nav: el.bind(null, "nav"),
  121. canvas: el.bind(null, "canvas"),
  122. caption: el.bind(null, "caption")
  123. };