BxBaseIconsetLucide.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaBaseView UNA Base Representation Classes
  7. * @{
  8. */
  9. /**
  10. * Basic Lucide iconset representation.
  11. * @see BxDolIconset
  12. */
  13. class BxBaseIconsetLucide extends BxBaseIconset
  14. {
  15. protected $_aMap;
  16. public function __construct ($aObject, $oTemplate)
  17. {
  18. parent::__construct ($aObject, $oTemplate);
  19. $this->_aMap = [
  20. 'ad' => 'circle-star',
  21. 'address-card' => 'id-card',
  22. 'angle-double-left' => 'chevrons-left',
  23. 'angle-double-right' => 'chevrons-right',
  24. 'arrows-alt' => 'move',
  25. 'book-reader' => 'book-open-text',
  26. 'buffer' => 'layers',
  27. 'building' => 'building',
  28. 'bullhorn' => 'megaphone',
  29. 'calendar-day' => 'calendar-days',
  30. 'calendar-plus' => 'calendar-plus',
  31. 'camera-retro' => 'camera',
  32. 'cart-arrow-down' => 'shopping-cart',
  33. 'cart-plus' => 'shopping-cart',
  34. 'cc-stripe' => 'credit-card',
  35. 'certificate' => 'award',
  36. 'chart-pie' => 'pie-chart',
  37. 'check-circle' => 'check-circle',
  38. 'check-double' => 'check-check',
  39. 'clipboard-check' => 'clipboard-check',
  40. 'cog' => 'settings',
  41. 'cogs' => 'settings',
  42. 'comment' => 'message-circle',
  43. 'comment-dots' => 'message-square-dashed',
  44. 'comments' => 'messages-square',
  45. 'donate' => 'hand-coins',
  46. 'ellipsis-h' => 'more-horizontal',
  47. 'ellipsis-v' => 'more-vertical',
  48. 'envelope' => 'mail',
  49. 'envelope-open-text' => 'mail-open',
  50. 'exchange-alt' => 'repeat',
  51. 'exclamation-circle' => 'alert-circle',
  52. 'exclamation-triangle' => 'alert-triangle',
  53. 'fa-book' => 'book-text',
  54. 'fa-bookmark' => 'bookmark',
  55. 'fa-smile' => 'smile',
  56. 'fa-thumbs-up' => 'thumbs-up',
  57. 'file-alt' => 'file',
  58. 'file-alt' => 'file-text',
  59. 'file-export' => 'file-output',
  60. 'file-invoice' => 'receipt',
  61. 'file-word' => 'file-text',
  62. 'group' => 'users',
  63. 'hand-holding-usd' => 'hand-coins',
  64. 'hashtag' => 'hash',
  65. 'helpcircle' => 'help-circle',
  66. 'house' => 'home',
  67. 'industry' => 'factory',
  68. 'info-circle' => 'info',
  69. 'keyround' => 'key-round',
  70. 'language' => 'languages',
  71. 'lockopen' => 'unlock',
  72. 'mail-bulk' => 'mails',
  73. 'map-marker' => 'map-pin',
  74. 'money-check-alt' => 'wallet-cards',
  75. 'object-group' => 'layout-dashboard',
  76. 'pencil-alt' => 'pencil-line',
  77. 'pencil-ruler' => 'ruler',
  78. 'photo-video' => 'image-play',
  79. 'plus-circle' => 'plus-circle',
  80. 'qrcode' => 'qr-code',
  81. 'quote-right' => 'quote',
  82. 'remove' => 'x',
  83. 'reply-all' => 'reply-all',
  84. 'search-location' => 'search-check',
  85. 'share-alt' => 'share-2',
  86. 'shield-alt' => 'shield',
  87. 'sign-in-alt' => 'log-in',
  88. 'sign-out-alt' => 'log-out',
  89. 'star-half-o' => 'star-half',
  90. 'swatchbook' => 'swatch-book',
  91. 'sync' => 'refresh-ccw',
  92. 'tachometer-alt' => 'gauge',
  93. 'tasks' => 'check-square',
  94. 'th-large' => 'grid-2x2',
  95. 'thumbtack' => 'pin',
  96. 'times' => 'x',
  97. 'times-circle' => 'x-circle',
  98. 'trash2' => 'trash-2',
  99. 'unlock-alt' => 'unlock',
  100. 'user-friends' => 'users',
  101. 'user-round' => 'user-round',
  102. 'user-slash' => 'user-x',
  103. 'user-times' => 'user-x',
  104. 'users-round' => 'users-round',
  105. 'video-camera' => 'video',
  106. ];
  107. }
  108. public function getPreloaderJs()
  109. {
  110. return 'https://unpkg.com/lucide@latest';
  111. }
  112. public function getIcon($sIcon)
  113. {
  114. $sIcon = trim(preg_replace('/(sys-icon|far|col-\w+)/i', '', $sIcon));
  115. if(isset($this->_aMap[$sIcon]))
  116. $sIcon = $this->_aMap[$sIcon];
  117. return bx_gen_method_name($sIcon, ['_', '-']);
  118. }
  119. public function getCode()
  120. {
  121. $sMap = json_encode($this->_aMap);
  122. $sCode = <<<BLAH
  123. function bx_iconset_init_lucide() {
  124. if(!window.lucide || !lucide.icons)
  125. return;
  126. const aMap = $sMap;
  127. document.querySelectorAll('i.sys-icon').forEach(el => {
  128. if(el.hasAttribute('data-lucide'))
  129. return;
  130. const sName = el.getAttribute('class').replace(/(sys-icon-bigger|sys-icon|fab|far|fas|col-\w+)/gi, '').trim().split(' ').shift();
  131. if(sName)
  132. el.setAttribute('data-lucide', aMap[sName] != undefined ? aMap[sName] : sName);
  133. else
  134. console.warn('Lucide: no icon class found on', el);
  135. });
  136. lucide.createIcons({
  137. attrs: { class: ['sys-icon'] },
  138. nameAttr: 'data-lucide'
  139. });
  140. };
  141. bx_iconset_init_lucide();
  142. if (typeof glOnProcessHtml === 'undefined')
  143. glOnProcessHtml = [];
  144. if (glOnProcessHtml instanceof Array) {
  145. glOnProcessHtml.push(function(e) {
  146. bx_iconset_init_lucide();
  147. });
  148. }
  149. BLAH;
  150. return $this->_oTemplate->_wrapInTagJsCode($sCode);
  151. }
  152. }
  153. /** @} */