No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

rpg-card.html 2.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <link href='http://fonts.googleapis.com/css?family=Noto+Sans:400,700,400italic,700italic' rel='stylesheet' type='text/css'>
  2. <template id="rpg-card">
  3. <style type='text/css'>
  4. :host {
  5. /* Fill the whole area of the shadow root */
  6. width: 100%;
  7. height: 100%;
  8. /* Border */
  9. padding: 6px;
  10. border-radius: 4px;
  11. box-sizing: border-box;
  12. /* Flex display of children */
  13. position: relative;
  14. display: flex;
  15. flex-direction: column;
  16. /* Font */
  17. font-family: 'Noto Sans', 'Myriad Pro', Calibri, Helvetica, Arial, sans-serif;
  18. font-size: 8pt;
  19. }
  20. ::content > card-title:first-child {
  21. margin-top: -2px;
  22. margin-bottom: 4px;
  23. }
  24. ::content > card-title:last-child {
  25. margin-top: 4px;
  26. margin-bottom: -2px;
  27. }
  28. </style>
  29. <style type='text/css' id="color-style">
  30. </style>
  31. <content></content>
  32. </template>
  33. <script>
  34. (function (window, document) {
  35. var elemName = 'rpg-card';
  36. var mainDoc = document;
  37. var importDoc = document.currentScript.ownerDocument;
  38. var proto = Object.create(HTMLElement.prototype);
  39. Object.defineProperty(proto, "color", {
  40. get: function () {
  41. return "";
  42. },
  43. set: function (value) {
  44. var root = this.shadowRoot;
  45. var style = root.getElementById("color-style");
  46. style.innerHTML = "\
  47. :host {\
  48. color: "+value+";\
  49. background-color: " + value + ";\
  50. border-color: " + value + ";\
  51. }\
  52. ::content card-rule /deep/ svg {\
  53. fill: " + value + ";\
  54. }\
  55. ::content card-boxes /deep/ svg rect {\
  56. stroke: " + value + ";\
  57. }\
  58. ::content card-icon {\
  59. background-color: " + value + ";\
  60. }\
  61. ::content card-back /deep/ #outer {\
  62. background: radial-gradient(ellipse at center, white 20%, " + value + " 120%);\
  63. }\
  64. ";
  65. }
  66. });
  67. proto.createdCallback = function () {
  68. var template = importDoc.getElementById(elemName);
  69. var clone = mainDoc.importNode(template.content, true);
  70. var root = this.createShadowRoot();
  71. root.appendChild(clone);
  72. this.color = this.getAttribute('color') || "black";
  73. }
  74. proto.attributeChangedCallback = function (name, oldValue, newValue) {
  75. switch (name) {
  76. case "color": this.color = newValue; break;
  77. }
  78. }
  79. mainDoc.registerElement(elemName, { prototype: proto });
  80. })(window, document);
  81. </script>