BxBaseIconsetLucide.php 5.8 KB

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