1+ ( function webpackUniversalModuleDefinition ( root , factory ) {
2+ if ( typeof exports === 'object' && typeof module === 'object' )
3+ module . exports = factory ( ) ;
4+ else if ( typeof define === 'function' && define . amd )
5+ define ( [ ] , factory ) ;
6+ else {
7+ var a = factory ( ) ;
8+ for ( var i in a ) ( typeof exports === 'object' ? exports : root ) [ i ] = a [ i ] ;
9+ }
10+ } ) ( window , function ( ) {
11+ return /******/ ( function ( modules ) { // webpackBootstrap
12+ /******/ // The module cache
13+ /******/ var installedModules = { } ;
14+ /******/
15+ /******/ // The require function
16+ /******/ function __webpack_require__ ( moduleId ) {
17+ /******/
18+ /******/ // Check if module is in cache
19+ /******/ if ( installedModules [ moduleId ] ) {
20+ /******/ return installedModules [ moduleId ] . exports ;
21+ /******/ }
22+ /******/ // Create a new module (and put it into the cache)
23+ /******/ var module = installedModules [ moduleId ] = {
24+ /******/ i : moduleId ,
25+ /******/ l : false ,
26+ /******/ exports : { }
27+ /******/ } ;
28+ /******/
29+ /******/ // Execute the module function
30+ /******/ modules [ moduleId ] . call ( module . exports , module , module . exports , __webpack_require__ ) ;
31+ /******/
32+ /******/ // Flag the module as loaded
33+ /******/ module . l = true ;
34+ /******/
35+ /******/ // Return the exports of the module
36+ /******/ return module . exports ;
37+ /******/ }
38+ /******/
39+ /******/
40+ /******/ // expose the modules object (__webpack_modules__)
41+ /******/ __webpack_require__ . m = modules ;
42+ /******/
43+ /******/ // expose the module cache
44+ /******/ __webpack_require__ . c = installedModules ;
45+ /******/
46+ /******/ // define getter function for harmony exports
47+ /******/ __webpack_require__ . d = function ( exports , name , getter ) {
48+ /******/ if ( ! __webpack_require__ . o ( exports , name ) ) {
49+ /******/ Object . defineProperty ( exports , name , { enumerable : true , get : getter } ) ;
50+ /******/ }
51+ /******/ } ;
52+ /******/
53+ /******/ // define __esModule on exports
54+ /******/ __webpack_require__ . r = function ( exports ) {
55+ /******/ if ( typeof Symbol !== 'undefined' && Symbol . toStringTag ) {
56+ /******/ Object . defineProperty ( exports , Symbol . toStringTag , { value : 'Module' } ) ;
57+ /******/ }
58+ /******/ Object . defineProperty ( exports , '__esModule' , { value : true } ) ;
59+ /******/ } ;
60+ /******/
61+ /******/ // create a fake namespace object
62+ /******/ // mode & 1: value is a module id, require it
63+ /******/ // mode & 2: merge all properties of value into the ns
64+ /******/ // mode & 4: return value when already ns object
65+ /******/ // mode & 8|1: behave like require
66+ /******/ __webpack_require__ . t = function ( value , mode ) {
67+ /******/ if ( mode & 1 ) value = __webpack_require__ ( value ) ;
68+ /******/ if ( mode & 8 ) return value ;
69+ /******/ if ( ( mode & 4 ) && typeof value === 'object' && value && value . __esModule ) return value ;
70+ /******/ var ns = Object . create ( null ) ;
71+ /******/ __webpack_require__ . r ( ns ) ;
72+ /******/ Object . defineProperty ( ns , 'default' , { enumerable : true , value : value } ) ;
73+ /******/ if ( mode & 2 && typeof value != 'string' ) for ( var key in value ) __webpack_require__ . d ( ns , key , function ( key ) { return value [ key ] ; } . bind ( null , key ) ) ;
74+ /******/ return ns ;
75+ /******/ } ;
76+ /******/
77+ /******/ // getDefaultExport function for compatibility with non-harmony modules
78+ /******/ __webpack_require__ . n = function ( module ) {
79+ /******/ var getter = module && module . __esModule ?
80+ /******/ function getDefault ( ) { return module [ 'default' ] ; } :
81+ /******/ function getModuleExports ( ) { return module ; } ;
82+ /******/ __webpack_require__ . d ( getter , 'a' , getter ) ;
83+ /******/ return getter ;
84+ /******/ } ;
85+ /******/
86+ /******/ // Object.prototype.hasOwnProperty.call
87+ /******/ __webpack_require__ . o = function ( object , property ) { return Object . prototype . hasOwnProperty . call ( object , property ) ; } ;
88+ /******/
89+ /******/ // __webpack_public_path__
90+ /******/ __webpack_require__ . p = "/" ;
91+ /******/
92+ /******/
93+ /******/ // Load entry module and return exports
94+ /******/ return __webpack_require__ ( __webpack_require__ . s = 0 ) ;
95+ /******/ } )
96+ /************************************************************************/
97+ /******/ ( {
98+
99+ /***/ "./src/component.js" :
100+ /*!**************************!*\
101+ !*** ./src/component.js ***!
102+ \**************************/
103+ /*! exports provided: default */
104+ /***/ ( function ( module , __webpack_exports__ , __webpack_require__ ) {
105+
106+ "use strict" ;
107+ __webpack_require__ . r ( __webpack_exports__ ) ;
108+ /* harmony export (binding) */ __webpack_require__ . d ( __webpack_exports__ , "default" , function ( ) { return Component ; } ) ;
109+ /* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__ ( /*! ./utils */ "./src/utils.js" ) ;
110+ function _classCallCheck ( instance , Constructor ) { if ( ! ( instance instanceof Constructor ) ) { throw new TypeError ( "Cannot call a class as a function" ) ; } }
111+
112+ 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 ) ; } }
113+
114+ function _createClass ( Constructor , protoProps , staticProps ) { if ( protoProps ) _defineProperties ( Constructor . prototype , protoProps ) ; if ( staticProps ) _defineProperties ( Constructor , staticProps ) ; return Constructor ; }
115+
116+
117+
118+ var Component =
119+ /*#__PURE__*/
120+ function ( ) {
121+ function Component ( el ) {
122+ _classCallCheck ( this , Component ) ;
123+
124+ this . el = el ;
125+ this . data = Object ( _utils__WEBPACK_IMPORTED_MODULE_0__ [ "saferEval" ] ) ( this . el . getAttribute ( 'x-data' ) ) ;
126+ this . registerListeners ( ) ;
127+ this . updateBoundAttributes ( function ( ) {
128+ return true ;
129+ } ) ;
130+ }
131+
132+ _createClass ( Component , [ {
133+ key : "registerListeners" ,
134+ value : function registerListeners ( ) {
135+ var _this = this ;
136+
137+ // Do a sweep through the component, find out what events children are
138+ // listening for so we can do "event delegation" on the root.
139+ // The reason for using event delegation is so that new
140+ // DOM element listeners can potentially be added
141+ // and they will be detected.
142+ this . eventsThisComponentIsListeningFor ( ) . forEach ( function ( eventName ) {
143+ _this . el . addEventListener ( eventName , function ( e ) {
144+ if ( e . target . hasAttribute ( "x-on:" . concat ( eventName ) ) ) {
145+ var mutatedDataItems = [ ] ; // Detect if the listener action mutated some data,
146+ // this way we can selectively update bindings.
147+
148+ var proxiedData = new Proxy ( _this . data , {
149+ set : function set ( obj , property , value ) {
150+ var setWasSuccessful = Reflect . set ( obj , property , value ) ;
151+ mutatedDataItems . push ( property ) ;
152+ return setWasSuccessful ;
153+ }
154+ } ) ;
155+ var expression = e . target . getAttribute ( "x-on:" . concat ( eventName ) ) ;
156+ Object ( _utils__WEBPACK_IMPORTED_MODULE_0__ [ "saferEval" ] ) ( expression , {
157+ '$data' : proxiedData ,
158+ '$event' : e
159+ } ) ;
160+
161+ _this . updateBoundAttributes ( function ( isConscernedWith ) {
162+ return mutatedDataItems . filter ( function ( i ) {
163+ return isConscernedWith . includes ( i ) ;
164+ } ) . length > 0 ;
165+ } ) ;
166+ }
167+ } ) ;
168+ } ) ;
169+ }
170+ } , {
171+ key : "eventsThisComponentIsListeningFor" ,
172+ value : function eventsThisComponentIsListeningFor ( ) {
173+ var eventsToListenFor = [ ] ;
174+ Object ( _utils__WEBPACK_IMPORTED_MODULE_0__ [ "walk" ] ) ( this . el , function ( el ) {
175+ eventsToListenFor = eventsToListenFor . concat ( Array . from ( el . attributes ) . map ( function ( i ) {
176+ return i . name ;
177+ } ) . filter ( function ( i ) {
178+ return i . search ( 'x-on' ) > - 1 ;
179+ } ) . map ( function ( i ) {
180+ return i . replace ( / x - o n : / , '' ) ;
181+ } ) ) ;
182+ } ) ;
183+ return eventsToListenFor . filter ( _utils__WEBPACK_IMPORTED_MODULE_0__ [ "onlyUnique" ] ) ;
184+ }
185+ } , {
186+ key : "updateBoundAttributes" ,
187+ value : function updateBoundAttributes ( ifConcernedWith ) {
188+ var _this2 = this ;
189+
190+ Object ( _utils__WEBPACK_IMPORTED_MODULE_0__ [ "walk" ] ) ( this . el , function ( el ) {
191+ if ( Object ( _utils__WEBPACK_IMPORTED_MODULE_0__ [ "hasXAttr" ] ) ( el , 'bind' ) ) {
192+ Object ( _utils__WEBPACK_IMPORTED_MODULE_0__ [ "getXAttrs" ] ) ( el , 'bind' ) . forEach ( function ( attr ) {
193+ var boundAttribute = attr . name . replace ( / x - b i n d : / , '' ) ;
194+ var expression = attr . value ;
195+ var isConscernedWith = [ ] ;
196+ var proxiedData = new Proxy ( _this2 . data , {
197+ get : function get ( object , prop ) {
198+ isConscernedWith . push ( prop ) ;
199+ return object [ prop ] ;
200+ }
201+ } ) ;
202+ var result = Object ( _utils__WEBPACK_IMPORTED_MODULE_0__ [ "saferEval" ] ) ( expression , {
203+ "$data" : proxiedData
204+ } ) ;
205+
206+ if ( ifConcernedWith ( isConscernedWith ) ) {
207+ _this2 . updateBoundAttributeValue ( el , boundAttribute , result ) ;
208+ }
209+ } ) ;
210+ }
211+ } ) ;
212+ }
213+ } , {
214+ key : "updateBoundAttributeValue" ,
215+ value : function updateBoundAttributeValue ( el , attrName , value ) {
216+ if ( attrName === 'class' ) {
217+ // Use the class object syntax that vue uses to toggle them.
218+ Object . keys ( value ) . forEach ( function ( className ) {
219+ if ( value [ className ] ) {
220+ el . classList . add ( className ) ;
221+ } else {
222+ el . classList . remove ( className ) ;
223+ }
224+ } ) ;
225+ } else if ( [ 'disabled' , 'readonly' , 'required' , 'checked' ] . includes ( attrName ) ) {
226+ // Boolean attributes have to be explicitly added and removed, not just set.
227+ if ( ! ! value ) {
228+ el . setAttribute ( attrName , '' ) ;
229+ } else {
230+ el . removeAttribute ( attrName ) ;
231+ }
232+ } else {
233+ el . setAttribute ( attrName , value ) ;
234+ }
235+ }
236+ } ] ) ;
237+
238+ return Component ;
239+ } ( ) ;
240+
241+
242+
243+ /***/ } ) ,
244+
245+ /***/ "./src/index.js" :
246+ /*!**********************!*\
247+ !*** ./src/index.js ***!
248+ \**********************/
249+ /*! exports provided: default */
250+ /***/ ( function ( module , __webpack_exports__ , __webpack_require__ ) {
251+
252+ "use strict" ;
253+ __webpack_require__ . r ( __webpack_exports__ ) ;
254+ /* harmony import */ var _component__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__ ( /*! ./component */ "./src/component.js" ) ;
255+
256+ var rename = {
257+ start : function start ( ) {
258+ var rootEls = document . querySelectorAll ( '[x-data]' ) ;
259+ rootEls . forEach ( function ( rootEl ) {
260+ window . component = new _component__WEBPACK_IMPORTED_MODULE_0__ [ "default" ] ( rootEl ) ;
261+ } ) ;
262+ }
263+ } ;
264+
265+ if ( ! window . rename ) {
266+ window . rename = rename ;
267+ }
268+
269+ /* harmony default export */ __webpack_exports__ [ "default" ] = ( rename ) ;
270+
271+ /***/ } ) ,
272+
273+ /***/ "./src/utils.js" :
274+ /*!**********************!*\
275+ !*** ./src/utils.js ***!
276+ \**********************/
277+ /*! exports provided: walk, onlyUnique, saferEval, hasXAttr, getXAttrs */
278+ /***/ ( function ( module , __webpack_exports__ , __webpack_require__ ) {
279+
280+ "use strict" ;
281+ __webpack_require__ . r ( __webpack_exports__ ) ;
282+ /* harmony export (binding) */ __webpack_require__ . d ( __webpack_exports__ , "walk" , function ( ) { return walk ; } ) ;
283+ /* harmony export (binding) */ __webpack_require__ . d ( __webpack_exports__ , "onlyUnique" , function ( ) { return onlyUnique ; } ) ;
284+ /* harmony export (binding) */ __webpack_require__ . d ( __webpack_exports__ , "saferEval" , function ( ) { return saferEval ; } ) ;
285+ /* harmony export (binding) */ __webpack_require__ . d ( __webpack_exports__ , "hasXAttr" , function ( ) { return hasXAttr ; } ) ;
286+ /* harmony export (binding) */ __webpack_require__ . d ( __webpack_exports__ , "getXAttrs" , function ( ) { return getXAttrs ; } ) ;
287+ function _toConsumableArray ( arr ) { return _arrayWithoutHoles ( arr ) || _iterableToArray ( arr ) || _nonIterableSpread ( ) ; }
288+
289+ function _nonIterableSpread ( ) { throw new TypeError ( "Invalid attempt to spread non-iterable instance" ) ; }
290+
291+ function _iterableToArray ( iter ) { if ( Symbol . iterator in Object ( iter ) || Object . prototype . toString . call ( iter ) === "[object Arguments]" ) return Array . from ( iter ) ; }
292+
293+ function _arrayWithoutHoles ( arr ) { if ( Array . isArray ( arr ) ) { for ( var i = 0 , arr2 = new Array ( arr . length ) ; i < arr . length ; i ++ ) { arr2 [ i ] = arr [ i ] ; } return arr2 ; } }
294+
295+ function walk ( el , callback ) {
296+ callback ( el ) ;
297+ var node = el . firstElementChild ;
298+
299+ while ( node ) {
300+ walk ( node , callback ) ;
301+ node = node . nextElementSibling ;
302+ }
303+ }
304+ function onlyUnique ( value , index , self ) {
305+ return self . indexOf ( value ) === index ;
306+ }
307+ function saferEval ( expression ) {
308+ var scope = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : { } ;
309+ return new Function ( Object . keys ( scope ) , "\"use strict\"; return " . concat ( expression ) ) . apply ( void 0 , _toConsumableArray ( Object . values ( scope ) ) ) ;
310+ }
311+ function hasXAttr ( el , name ) {
312+ return ! ! Array . from ( el . attributes ) . map ( function ( i ) {
313+ return i . name ;
314+ } ) . filter ( function ( i ) {
315+ return i . search ( new RegExp ( "^x-" . concat ( name ) ) ) > - 1 ;
316+ } ) . length ;
317+ }
318+ function getXAttrs ( el , name ) {
319+ return Array . from ( el . attributes ) . filter ( function ( i ) {
320+ return i . name . search ( new RegExp ( "^x-" . concat ( name ) ) ) > - 1 ;
321+ } ) ;
322+ }
323+
324+ /***/ } ) ,
325+
326+ /***/ 0 :
327+ /*!****************************!*\
328+ !*** multi ./src/index.js ***!
329+ \****************************/
330+ /*! no static exports found */
331+ /***/ ( function ( module , exports , __webpack_require__ ) {
332+
333+ module . exports = __webpack_require__ ( /*! /Users/calebporzio/Documents/Code/sites/minimal/src/index.js */ "./src/index.js" ) ;
334+
335+
336+ /***/ } )
337+
338+ /******/ } ) ;
339+ } ) ;
0 commit comments