@@ -2011,6 +2011,9 @@ var HyperHTMLElement = (function (exports) {
20112011 } ) ;
20122012 } ;
20132013
2014+ var _attachShadow = HTMLElement . prototype . attachShadow ;
2015+ var sr = new WeakMap ( ) ;
2016+
20142017 var HyperHTMLElement =
20152018 /*#__PURE__*/
20162019 function ( _HTMLElement ) {
@@ -2023,6 +2026,16 @@ var HyperHTMLElement = (function (exports) {
20232026 }
20242027
20252028 _createClass ( HyperHTMLElement , [ {
2029+ key : "attachShadow" ,
2030+ // weakly relate the shadowRoot for refs usage
2031+ value : function attachShadow ( ) {
2032+ var shadowRoot = _attachShadow . apply ( this , arguments ) ;
2033+
2034+ sr . set ( this , shadowRoot ) ;
2035+ return shadowRoot ;
2036+ } // returns elements by ref
2037+
2038+ } , {
20262039 key : "render" ,
20272040 // overwrite this method with your own render
20282041 value : function render ( ) { } // ---------------------//
@@ -2048,19 +2061,36 @@ var HyperHTMLElement = (function (exports) {
20482061 return this ;
20492062 }
20502063 } , {
2051- key : "html" ,
2052- // lazily bind once hyperHTML logic
2064+ key : "refs" ,
2065+ get : function get ( ) {
2066+ var value = { } ;
2067+
2068+ if ( '_html$' in this ) {
2069+ var all = ( sr . get ( this ) || this ) . querySelectorAll ( '[ref]' ) ;
2070+
2071+ for ( var length = all . length , i = 0 ; i < length ; i ++ ) {
2072+ var node = all [ i ] ;
2073+ value [ node . getAttribute ( 'ref' ) ] = node ;
2074+ }
2075+
2076+ Object . defineProperty ( this , 'refs' , {
2077+ value : value
2078+ } ) ;
2079+ return value ;
2080+ }
2081+
2082+ return value ;
2083+ } // lazily bind once hyperHTML logic
20532084 // to either the shadowRoot, if present and open,
20542085 // the _shadowRoot property, if set due closed shadow root,
20552086 // or the custom-element itself if no Shadow DOM is used.
2087+
2088+ } , {
2089+ key : "html" ,
20562090 get : function get ( ) {
2057- return this . _html$ || ( this . html = bind ( // in case of Shadow DOM {mode: "open"}, use it
2058- this . shadowRoot || // in case of Shadow DOM {mode: "close"}, use it
2059- // this needs the following reference created upfront
2060- // this._shadowRoot = this.attachShadow({mode: "close"});
2061- this . _shadowRoot || // if no Shadow DOM is used, simply use the component
2062- // as container for its own content (it just works too)
2063- this ) ) ;
2091+ return this . _html$ || ( this . html = bind ( // in a way or another, bind to the right node
2092+ // backward compatible, first two could probably go already
2093+ this . shadowRoot || this . _shadowRoot || sr . get ( this ) || this ) ) ;
20642094 } // it can be set too if necessary, it won't invoke render()
20652095 ,
20662096 set : function set ( value ) {
0 commit comments