1
+ "use strict" ;
2
+
3
+ function _typeof ( obj ) { "@babel/helpers - typeof" ; if ( typeof Symbol === "function" && typeof Symbol . iterator === "symbol" ) { _typeof = function _typeof ( obj ) { return typeof obj ; } ; } else { _typeof = function _typeof ( obj ) { return obj && typeof Symbol === "function" && obj . constructor === Symbol && obj !== Symbol . prototype ? "symbol" : typeof obj ; } ; } return _typeof ( obj ) ; }
4
+
5
+ Object . defineProperty ( exports , "__esModule" , {
6
+ value : true
7
+ } ) ;
8
+ exports [ "default" ] = void 0 ;
9
+
10
+ function _classCallCheck ( instance , Constructor ) { if ( ! ( instance instanceof Constructor ) ) { throw new TypeError ( "Cannot call a class as a function" ) ; } }
11
+
12
+ function _defineProperties ( target , props ) { for ( var i = 0 ; i < props . length ; i ++ ) { var descriptor = props [ i ] ; descriptor . enumerable = descriptor . enumerable || false ; descriptor . configurable = true ; if ( "value" in descriptor ) descriptor . writable = true ; Object . defineProperty ( target , descriptor . key , descriptor ) ; } }
13
+
14
+ function _createClass ( Constructor , protoProps , staticProps ) { if ( protoProps ) _defineProperties ( Constructor . prototype , protoProps ) ; if ( staticProps ) _defineProperties ( Constructor , staticProps ) ; return Constructor ; }
15
+
16
+ function _inherits ( subClass , superClass ) { if ( typeof superClass !== "function" && superClass !== null ) { throw new TypeError ( "Super expression must either be null or a function" ) ; } subClass . prototype = Object . create ( superClass && superClass . prototype , { constructor : { value : subClass , writable : true , configurable : true } } ) ; if ( superClass ) _setPrototypeOf ( subClass , superClass ) ; }
17
+
18
+ function _createSuper ( Derived ) { var hasNativeReflectConstruct = _isNativeReflectConstruct ( ) ; return function _createSuperInternal ( ) { var Super = _getPrototypeOf ( Derived ) , result ; if ( hasNativeReflectConstruct ) { var NewTarget = _getPrototypeOf ( this ) . constructor ; result = Reflect . construct ( Super , arguments , NewTarget ) ; } else { result = Super . apply ( this , arguments ) ; } return _possibleConstructorReturn ( this , result ) ; } ; }
19
+
20
+ function _possibleConstructorReturn ( self , call ) { if ( call && ( _typeof ( call ) === "object" || typeof call === "function" ) ) { return call ; } return _assertThisInitialized ( self ) ; }
21
+
22
+ function _assertThisInitialized ( self ) { if ( self === void 0 ) { throw new ReferenceError ( "this hasn't been initialised - super() hasn't been called" ) ; } return self ; }
23
+
24
+ function _wrapNativeSuper ( Class ) { var _cache = typeof Map === "function" ? new Map ( ) : undefined ; _wrapNativeSuper = function _wrapNativeSuper ( Class ) { if ( Class === null || ! _isNativeFunction ( Class ) ) return Class ; if ( typeof Class !== "function" ) { throw new TypeError ( "Super expression must either be null or a function" ) ; } if ( typeof _cache !== "undefined" ) { if ( _cache . has ( Class ) ) return _cache . get ( Class ) ; _cache . set ( Class , Wrapper ) ; } function Wrapper ( ) { return _construct ( Class , arguments , _getPrototypeOf ( this ) . constructor ) ; } Wrapper . prototype = Object . create ( Class . prototype , { constructor : { value : Wrapper , enumerable : false , writable : true , configurable : true } } ) ; return _setPrototypeOf ( Wrapper , Class ) ; } ; return _wrapNativeSuper ( Class ) ; }
25
+
26
+ function _construct ( Parent , args , Class ) { if ( _isNativeReflectConstruct ( ) ) { _construct = Reflect . construct ; } else { _construct = function _construct ( Parent , args , Class ) { var a = [ null ] ; a . push . apply ( a , args ) ; var Constructor = Function . bind . apply ( Parent , a ) ; var instance = new Constructor ( ) ; if ( Class ) _setPrototypeOf ( instance , Class . prototype ) ; return instance ; } ; } return _construct . apply ( null , arguments ) ; }
27
+
28
+ function _isNativeReflectConstruct ( ) { if ( typeof Reflect === "undefined" || ! Reflect . construct ) return false ; if ( Reflect . construct . sham ) return false ; if ( typeof Proxy === "function" ) return true ; try { Boolean . prototype . valueOf . call ( Reflect . construct ( Boolean , [ ] , function ( ) { } ) ) ; return true ; } catch ( e ) { return false ; } }
29
+
30
+ function _isNativeFunction ( fn ) { return Function . toString . call ( fn ) . indexOf ( "[native code]" ) !== - 1 ; }
31
+
32
+ function _setPrototypeOf ( o , p ) { _setPrototypeOf = Object . setPrototypeOf || function _setPrototypeOf ( o , p ) { o . __proto__ = p ; return o ; } ; return _setPrototypeOf ( o , p ) ; }
33
+
34
+ function _getPrototypeOf ( o ) { _getPrototypeOf = Object . setPrototypeOf ? Object . getPrototypeOf : function _getPrototypeOf ( o ) { return o . __proto__ || Object . getPrototypeOf ( o ) ; } ; return _getPrototypeOf ( o ) ; }
35
+
36
+ function _classPrivateMethodGet ( receiver , privateSet , fn ) { if ( ! privateSet . has ( receiver ) ) { throw new TypeError ( "attempted to get private field on non-instance" ) ; } return fn ; }
37
+
38
+ function _classPrivateFieldSet ( receiver , privateMap , value ) { var descriptor = _classExtractFieldDescriptor ( receiver , privateMap , "set" ) ; _classApplyDescriptorSet ( receiver , descriptor , value ) ; return value ; }
39
+
40
+ function _classApplyDescriptorSet ( receiver , descriptor , value ) { if ( descriptor . set ) { descriptor . set . call ( receiver , value ) ; } else { if ( ! descriptor . writable ) { throw new TypeError ( "attempted to set read only private field" ) ; } descriptor . value = value ; } }
41
+
42
+ function _classPrivateFieldGet ( receiver , privateMap ) { var descriptor = _classExtractFieldDescriptor ( receiver , privateMap , "get" ) ; return _classApplyDescriptorGet ( receiver , descriptor ) ; }
43
+
44
+ function _classExtractFieldDescriptor ( receiver , privateMap , action ) { if ( ! privateMap . has ( receiver ) ) { throw new TypeError ( "attempted to " + action + " private field on non-instance" ) ; } return privateMap . get ( receiver ) ; }
45
+
46
+ function _classApplyDescriptorGet ( receiver , descriptor ) { if ( descriptor . get ) { return descriptor . get . call ( receiver ) ; } return descriptor . value ; }
47
+
48
+ var _shadowRoot = /*#__PURE__*/ new WeakMap ( ) ;
49
+
50
+ var _codeBlock = /*#__PURE__*/ new WeakMap ( ) ;
51
+
52
+ var _codeWrap = /*#__PURE__*/ new WeakMap ( ) ;
53
+
54
+ var _value = /*#__PURE__*/ new WeakMap ( ) ;
55
+
56
+ var _language = /*#__PURE__*/ new WeakMap ( ) ;
57
+
58
+ var _render = /*#__PURE__*/ new WeakSet ( ) ;
59
+
60
+ var HTMLCodeBlockElement = /*#__PURE__*/ function ( _HTMLElement ) {
61
+ _inherits ( HTMLCodeBlockElement , _HTMLElement ) ;
62
+
63
+ var _super = _createSuper ( HTMLCodeBlockElement ) ;
64
+
65
+ function HTMLCodeBlockElement ( ) {
66
+ var _classPrivateFieldGet2 ;
67
+
68
+ var _this ;
69
+
70
+ _classCallCheck ( this , HTMLCodeBlockElement ) ;
71
+
72
+ _this = _super . call ( this ) ;
73
+ /**
74
+ * @param name - The value of name attribute for the slot element
75
+ * @returns - The slot element
76
+ */
77
+
78
+ _render . add ( _assertThisInitialized ( _this ) ) ;
79
+
80
+ _shadowRoot . set ( _assertThisInitialized ( _this ) , {
81
+ writable : true ,
82
+ value : void 0
83
+ } ) ;
84
+
85
+ _codeBlock . set ( _assertThisInitialized ( _this ) , {
86
+ writable : true ,
87
+ value : void 0
88
+ } ) ;
89
+
90
+ _codeWrap . set ( _assertThisInitialized ( _this ) , {
91
+ writable : true ,
92
+ value : void 0
93
+ } ) ;
94
+
95
+ _value . set ( _assertThisInitialized ( _this ) , {
96
+ writable : true ,
97
+ value : ''
98
+ } ) ;
99
+
100
+ _language . set ( _assertThisInitialized ( _this ) , {
101
+ writable : true ,
102
+ value : ''
103
+ } ) ;
104
+
105
+ var mkslot = function mkslot ( name ) {
106
+ var slot = document . createElement ( 'slot' ) ;
107
+ slot . name = name ;
108
+ return slot ;
109
+ } ;
110
+
111
+ var slots = [ mkslot ( 'code' ) ] ;
112
+ var pre = document . createElement ( 'pre' ) ;
113
+ var code = document . createElement ( 'code' ) ;
114
+ code . tabIndex = 0 ;
115
+ code . className = 'hljs' ; // TODO: Make it variable
116
+
117
+ pre . slot = 'code' ;
118
+ pre . append ( code ) ; // Hard private props initialize
119
+
120
+ _classPrivateFieldSet ( _assertThisInitialized ( _this ) , _value , ( _this . textContent || '' ) . replace ( / ^ \n / , '' ) ) ;
121
+
122
+ _classPrivateFieldSet ( _assertThisInitialized ( _this ) , _language , _this . getAttribute ( 'language' ) || '' ) ;
123
+
124
+ _classPrivateFieldSet ( _assertThisInitialized ( _this ) , _shadowRoot , _this . attachShadow ( {
125
+ mode : 'closed'
126
+ } ) ) ;
127
+
128
+ _classPrivateFieldSet ( _assertThisInitialized ( _this ) , _codeBlock , code ) ;
129
+
130
+ _classPrivateFieldSet ( _assertThisInitialized ( _this ) , _codeWrap , pre ) ;
131
+
132
+ ( _classPrivateFieldGet2 = _classPrivateFieldGet ( _assertThisInitialized ( _this ) , _shadowRoot ) ) . append . apply ( _classPrivateFieldGet2 , slots ) ;
133
+
134
+ return _this ;
135
+ }
136
+
137
+ _createClass ( HTMLCodeBlockElement , [ {
138
+ key : "value" ,
139
+ get :
140
+ /** @returns - Syntax Highlighted Source Code */
141
+ function get ( ) {
142
+ return _classPrivateFieldGet ( this , _value ) ;
143
+ } ,
144
+ set : function set ( src ) {
145
+ _classPrivateFieldSet ( this , _value , src ) ;
146
+
147
+ _classPrivateMethodGet ( this , _render , _render2 ) . call ( this ) ;
148
+ }
149
+ /**
150
+ * Language Mode
151
+ * @returns - The value of the language attribute
152
+ */
153
+
154
+ } , {
155
+ key : "language" ,
156
+ get : function get ( ) {
157
+ return _classPrivateFieldGet ( this , _language ) ;
158
+ } ,
159
+ set : function set ( name ) {
160
+ _classPrivateFieldSet ( this , _language , name || '' ) ;
161
+
162
+ if ( _classPrivateFieldGet ( this , _language ) ) {
163
+ this . setAttribute ( 'language' , name ) ;
164
+ } else {
165
+ this . removeAttribute ( 'language' ) ;
166
+ }
167
+
168
+ _classPrivateMethodGet ( this , _render , _render2 ) . call ( this ) ;
169
+ }
170
+ } , {
171
+ key : "attributeChangedCallback" ,
172
+ value : function attributeChangedCallback ( attrName , oldValue , newValue ) {
173
+ if ( oldValue === newValue ) {
174
+ return ;
175
+ } // When the value of the attribute being observed changes,
176
+ // pass value to accessors.
177
+
178
+
179
+ switch ( attrName ) {
180
+ case 'language' :
181
+ this [ attrName ] = newValue || '' ;
182
+ break ;
183
+ }
184
+ }
185
+ } , {
186
+ key : "connectedCallback" ,
187
+ value : function connectedCallback ( ) {
188
+ _classPrivateMethodGet ( this , _render , _render2 ) . call ( this ) ;
189
+ }
190
+ } ] , [ {
191
+ key : "highlight" ,
192
+ value :
193
+ /**
194
+ * A library for performing syntax highlighting.
195
+ * Before running `customElements.define()`,
196
+ * you need to assign it directly to `HTMLCodeBlockElement.endgine`.
197
+ * Currently, only highlight.js is assumed.
198
+ */
199
+
200
+ /**
201
+ * Returns the result of highlighting the received source code string.
202
+ * @param src - Source code string for highlight
203
+ * @param options - Option for library of highlight
204
+ * @returns - Object of the highlight result
205
+ */
206
+ function highlight ( src , options ) {
207
+ var endgine = HTMLCodeBlockElement . endgine ;
208
+
209
+ if ( ! endgine ) {
210
+ throw new Error ( 'The syntax highlighting engine is not set to `HTMLCodeBlockElement.endgine`.' ) ;
211
+ }
212
+
213
+ if ( // Verifying the existence of a language
214
+ options !== null && options !== void 0 && options . language && endgine . getLanguage ( options . language ) ) {
215
+ return endgine . highlight ( src , options ) ;
216
+ }
217
+
218
+ return endgine . highlightAuto ( src ) ;
219
+ }
220
+ } , {
221
+ key : "observedAttributes" ,
222
+ get : function get ( ) {
223
+ return [ 'language' // 'controls',
224
+ ] ;
225
+ }
226
+ } ] ) ;
227
+
228
+ return HTMLCodeBlockElement ;
229
+ } ( /*#__PURE__*/ _wrapNativeSuper ( HTMLElement ) ) ; // Protect constructor names from minify
230
+
231
+
232
+ exports [ "default" ] = HTMLCodeBlockElement ;
233
+
234
+ function _render2 ( ) {
235
+ if ( ! this . parentNode ) {
236
+ return ;
237
+ }
238
+ /** The resulting syntax-highlighted markup */
239
+
240
+
241
+ var markup = HTMLCodeBlockElement . highlight ( _classPrivateFieldGet ( this , _value ) , {
242
+ language : _classPrivateFieldGet ( this , _language )
243
+ } ) . value ; // initialize
244
+
245
+ this . textContent = '' ;
246
+ _classPrivateFieldGet ( this , _codeBlock ) . textContent = '' ;
247
+
248
+ _classPrivateFieldGet ( this , _codeBlock ) . insertAdjacentHTML ( 'afterbegin' , markup ) ;
249
+
250
+ this . append ( _classPrivateFieldGet ( this , _codeWrap ) ) ;
251
+ }
252
+
253
+ Object . defineProperty ( HTMLCodeBlockElement , 'name' , {
254
+ value : 'HTMLCodeBlockElement'
255
+ } ) ;
0 commit comments