Skip to content
This repository has been archived by the owner on Jan 29, 2019. It is now read-only.

Commit

Permalink
chore: code style format
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsasharegan committed Dec 14, 2017
1 parent d2c4880 commit c73a859
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 122 deletions.
4 changes: 2 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space
indent_style = tab
indent_size = 2
max_line_length = 180
max_line_length = 120
110 changes: 55 additions & 55 deletions src/components/VueTransmit.vue
Original file line number Diff line number Diff line change
@@ -1,62 +1,62 @@
<template>
<component :is="tag">
<div class="v-transmit__upload-area"
:class="[isDraggingClass, uploadAreaClasses]"
draggable="true"
v-bind="uploadAreaAttrs"
v-on="uploadAreaListeners"
@click="handleClickUploaderAction"
@dragstart="handleDragStart"
@dragend="handleDragEnd"
@dragenter.prevent.stop="handleDragEnter"
@dragover.prevent.stop="handleDragOver"
@dragleave="handleDragLeave"
@drop.prevent.stop="handleDrop">
<slot></slot>
</div>
<slot name="files"
v-bind="fileSlotBindings"></slot>
<input type="file"
ref="hiddenFileInput"
:multiple="multiple"
:style="fileInputStyles"
:class="[maxFilesReachedClass]"
:accept="filesToAccept"
:capture="capture"
@change="onFileInputChange">
</component :is="tag">
<component :is="tag">
<div class="v-transmit__upload-area"
:class="[isDraggingClass, uploadAreaClasses]"
draggable="true"
v-bind="uploadAreaAttrs"
v-on="uploadAreaListeners"
@click="handleClickUploaderAction"
@dragstart="handleDragStart"
@dragend="handleDragEnd"
@dragenter.prevent.stop="handleDragEnter"
@dragover.prevent.stop="handleDragOver"
@dragleave="handleDragLeave"
@drop.prevent.stop="handleDrop">
<slot></slot>
</div>
<slot name="files"
v-bind="fileSlotBindings"></slot>
<input type="file"
ref="hiddenFileInput"
:multiple="multiple"
:style="fileInputStyles"
:class="[maxFilesReachedClass]"
:accept="filesToAccept"
:capture="capture"
@change="onFileInputChange">
</component :is="tag">
</template>

<style lang="scss">
$border-color: #bdbdbd;
$drop-color: #e1f5fe;
$drop-color-alt: #fafafa;
.v-transmit__upload-area {
width: 100%;
border-radius: 1rem;
border: 2px dashed $border-color;
min-height: 30vh;
@media (min-height: 1000px) {
min-height: 300px;
}
}
.v-transmit__upload-area--is-dragging {
background: $drop-color
linear-gradient(
-45deg,
$drop-color-alt 25%,
transparent 25%,
transparent 50%,
$drop-color-alt 50%,
$drop-color-alt 75%,
transparent 75%,
transparent
);
background-size: 40px 40px;
}
$border-color: #bdbdbd;
$drop-color: #e1f5fe;
$drop-color-alt: #fafafa;
.v-transmit__upload-area {
width: 100%;
border-radius: 1rem;
border: 2px dashed $border-color;
min-height: 30vh;
@media (min-height: 1000px) {
min-height: 300px;
}
}
.v-transmit__upload-area--is-dragging {
background: $drop-color
linear-gradient(
-45deg,
$drop-color-alt 25%,
transparent 25%,
transparent 50%,
$drop-color-alt 50%,
$drop-color-alt 75%,
transparent 75%,
transparent
);
background-size: 40px 40px;
}
</style>

<script lang="ts">
Expand Down
130 changes: 65 additions & 65 deletions src/core/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,120 +5,120 @@ export const defineProperty = Object.defineProperty

let idCounter = 0
export function uniqueId(prefix: string): string {
var id = ++idCounter
return prefix + id
var id = ++idCounter
return prefix + id
}

export function copyOwnAndInheritedProps(obj: object): object {
let newData = {}
for (let prop in obj) {
if (typeof obj[prop] !== "function") {
newData[prop] = obj[prop]
}
}
return newData
let newData = {}
for (let prop in obj) {
if (typeof obj[prop] !== "function") {
newData[prop] = obj[prop]
}
}
return newData
}

export type Rounding = "round" | "ceil" | "floor" | "trunc"

export function round(number: number, decimals: number = 2, roundStyle: Rounding = "round") {
const roundingFactor = Math.pow(10, decimals)
return Math[roundStyle](number * roundingFactor) / roundingFactor
const roundingFactor = Math.pow(10, decimals)
return Math[roundStyle](number * roundingFactor) / roundingFactor
}

export function fromBytesToKbit(bytes: number): number {
return bytes / 125
return bytes / 125
}

export function fromBytesToMbit(bytes: number): number {
return bytes / 125000
return bytes / 125000
}

export function toKbps(bytes: number, seconds: number): number {
return fromBytesToKbit(bytes) / seconds
return fromBytesToKbit(bytes) / seconds
}

export function toMbps(bytes: number, seconds: number): number {
return fromBytesToMbit(bytes) / seconds
return fromBytesToMbit(bytes) / seconds
}

export const hbsRegex = /{{\s*?([a-zA-Z]+)\s*?}}/g
export function hbsReplacer(context: object = {}) {
return function hbsReplacerFn(match: string, capture: string) {
return context[capture] !== undefined ? context[capture] : match
}
return function hbsReplacerFn(match: string, capture: string) {
return context[capture] !== undefined ? context[capture] : match
}
}

export function objFactory() {
return {}
return {}
}

export function scaleH(ratio: number, width: number): number {
return width / ratio
return width / ratio
}

export function scaleW(ratio: number, height: number): number {
return height * ratio
return height * ratio
}

export function scaleDims(ratio: number, width?: number, height?: number): number[] {
return typeof width === "number" ? [width, scaleH(ratio, width)] : [scaleW(ratio, height), height]
return typeof width === "number" ? [width, scaleH(ratio, width)] : [scaleW(ratio, height), height]
}

export interface IDrawImageArgs {
sx: number
sy: number
sWidth: number
sHeight: number
dx: number
dy: number
dWidth: number
dHeight: number
sx: number
sy: number
sWidth: number
sHeight: number
dx: number
dy: number
dWidth: number
dHeight: number
}

export interface IDimensions {
width: number
height: number
width: number
height: number
}

export function resizeImg(file: VTransmitFile, dims: IDimensions): IDrawImageArgs {
// Extract the object's primitive values so we don't mutate the input
const sRatio = file.width / file.height
const dRatio = dims.width / dims.height
const imgCoords = {
sx: 0,
sy: 0,
sWidth: file.width,
sHeight: file.height,
dx: 0,
dy: 0,
dWidth: dims.width,
dHeight: dims.height
}

let w, h
if (dRatio > sRatio) {
;[w, h] = scaleDims(dRatio, file.width)
} else {
;[w, h] = scaleDims(dRatio, undefined, file.height)
}

if (w < file.width) {
imgCoords.sx = (file.width - w) / 2
imgCoords.sWidth = w
}
if (h < file.height) {
imgCoords.sy = (file.height - h) / 2
imgCoords.sHeight = h
}

return imgCoords
// Extract the object's primitive values so we don't mutate the input
const sRatio = file.width / file.height
const dRatio = dims.width / dims.height
const imgCoords = {
sx: 0,
sy: 0,
sWidth: file.width,
sHeight: file.height,
dx: 0,
dy: 0,
dWidth: dims.width,
dHeight: dims.height,
}

let w, h
if (dRatio > sRatio) {
;[w, h] = scaleDims(dRatio, file.width)
} else {
;[w, h] = scaleDims(dRatio, undefined, file.height)
}

if (w < file.width) {
imgCoords.sx = (file.width - w) / 2
imgCoords.sWidth = w
}
if (h < file.height) {
imgCoords.sy = (file.height - h) / 2
imgCoords.sHeight = h
}

return imgCoords
}

export function webkitIsFile(entry: WebKitFileEntry | WebKitDirectoryEntry): entry is WebKitFileEntry {
return entry.isFile
return entry.isFile
}

export function webkitIsDir(entry: WebKitFileEntry | WebKitDirectoryEntry): entry is WebKitDirectoryEntry {
return entry.isDirectory
return entry.isDirectory
}

0 comments on commit c73a859

Please sign in to comment.