/**
 * Copyright 2020 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */ /**
 * Describes notification target for the `Notify` decorators.
 */ interface NotifyTarget { notifyPropertyChanged : ( name : string ) => void ; addObservedAttribute ? : ( name : string ) => void ; [ key ] : any ; } /**
 * Converts a camelCase property name to a kebab-case attribute name.
 */ function getAttributeName ( propertyName ) { return propertyName . replace ( /[A-Z]+/g , sub => `-${ sub }` ) . replace ( /^-/ , '' ) . toLowerCase ( ) ; } param attribute export function NotifyAttribute ( attribute ? ) { return function ( target , key ) : void { const attr = attribute || getAttributeName ( key ) ; if ( target . addObservedAttribute ) { target . addObservedAttribute ( attr ) ; } Object . defineProperty ( target , key , { get ( this ) { return this . getAttribute ( attr ) ; } , set ( this , value ) { if ( value === null || value === undefined ) { this . removeAttribute ( attr ) ; } else { this . setAttribute ( attr , value ) ; } this . notifyPropertyChanged ( key ) ; } , enumerable : true , configurable : true , } ) ; } ; } param attribute export function NotifyBooleanAttribute ( attribute ? ) { return function ( target , key ) : void { const attr = attribute || getAttributeName ( key ) ; if ( target . addObservedAttribute ) { target . addObservedAttribute ( attr ) ; } Object . defineProperty ( target , key , { get ( this ) { return this . hasAttribute ( attr ) ; } , set ( this , value ) { if ( value ) { this . setAttribute ( attr , '' ) ; } else { this . removeAttribute ( attr ) ; } this . notifyPropertyChanged ( key ) ; } , enumerable : true , configurable : true , } ) ; } ; } param attribute export function Notify ( attribute ? ) { if ( attribute ) { return NotifyAttribute ( attribute ) ; } return function ( target , key ) : void { Object . defineProperty ( target , key , { get ( this ) { return this [ `$__${ key }` ] ; } , set ( this , value ) { this [ `$__${ key }` ] = value ; this . notifyPropertyChanged ( key ) ; } , enumerable : true , configurable : true , } ) ; } ; } param alias export function Alias ( alias ) { return function ( target , key ) : void { Object . defineProperty ( target , alias , { get ( this ) { return this [ key ] ; } , set ( this , value ) { this [ key ] = value ; } , enumerable : true , configurable : false , } ) ; } ; }