/**
 * This class is based on the code in the following projects:
 * https://github.com/zenorocha/select
 * https://github.com/zenorocha/clipboard.js/
 *
 * Both released under MIT license - © Zeno Rocha
 */ import { Injectable } from '@angular/core' ; @ Injectable ( { providedIn : 'root' } ) export class FuseCopierService { private textarea : HTMLTextAreaElement ; param { string } text returns { boolean } copyText ( text ) { this . createTextareaAndSelect ( text ) ; const copySuccessful = document . execCommand ( 'copy' ) ; this . _removeFake ( ) ; return copySuccessful ; } param { string } text private createTextareaAndSelect ( text ) { this . textarea = document . createElement ( 'textarea' ) ; this . textarea . style . fontSize = '12pt' ; this . textarea . classList . add ( 'cdk-visually-hidden' ) ; const yPosition = window . pageYOffset || document . documentElement . scrollTop ; this . textarea . style . top = yPosition + 'px' ; this . textarea . setAttribute ( 'readonly' , '' ) ; this . textarea . value = text ; document . body . appendChild ( this . textarea ) ; this . textarea . select ( ) ; this . textarea . setSelectionRange ( 0 , this . textarea . value . length ) ; } private private _removeFake ( ) { if ( this . textarea ) { document . body . removeChild ( this . textarea ) ; this . textarea = null ; } } }