-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from zurmokeeper/feature/add_shape_text_func
add shape and text
- Loading branch information
Showing
44 changed files
with
1,947 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const colCache = require('../utils/col-cache'); | ||
const Anchor = require('./anchor'); | ||
|
||
module.exports = { | ||
parseRange: (range, hyperlinks, worksheet) => { | ||
if (typeof range === 'string') { | ||
const decoded = colCache.decode(range); | ||
return { | ||
tl: new Anchor(worksheet, {col: decoded.left, row: decoded.top}, -1), | ||
br: new Anchor(worksheet, {col: decoded.right, row: decoded.bottom}, 0), | ||
editAs: 'oneCell', | ||
}; | ||
} | ||
return { | ||
tl: new Anchor(worksheet, range.tl, 0), | ||
br: range.br && new Anchor(worksheet, range.br, 0), | ||
ext: range.ext, | ||
editAs: range.editAs, | ||
hyperlinks: hyperlinks || range.hyperlinks, | ||
}; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
const {parseRange} = require('./drawing-range'); | ||
|
||
class Shape { | ||
constructor(worksheet, model) { | ||
this.worksheet = worksheet; | ||
this.model = model; | ||
} | ||
|
||
get model() { | ||
return { | ||
props: { | ||
type: this.props.type, | ||
rotation: this.props.rotation, | ||
horizontalFlip: this.props.horizontalFlip, | ||
verticalFlip: this.props.verticalFlip, | ||
fill: this.props.fill, | ||
outline: this.props.outline, | ||
textBody: this.props.textBody, | ||
}, | ||
range: { | ||
tl: this.range.tl.model, | ||
br: this.range.br && this.range.br.model, | ||
ext: this.range.ext, | ||
editAs: this.range.editAs, | ||
}, | ||
hyperlinks: this.hyperlinks, | ||
}; | ||
} | ||
|
||
set model({props, range, hyperlinks}) { | ||
this.props = {type: props.type}; | ||
if (props.rotation) { | ||
this.props.rotation = props.rotation; | ||
} | ||
if (props.horizontalFlip) { | ||
this.props.horizontalFlip = props.horizontalFlip; | ||
} | ||
if (props.verticalFlip) { | ||
this.props.verticalFlip = props.verticalFlip; | ||
} | ||
if (props.fill) { | ||
this.props.fill = props.fill; | ||
} | ||
if (props.outline) { | ||
this.props.outline = props.outline; | ||
} | ||
if (props.textBody) { | ||
this.props.textBody = parseAsTextBody(props.textBody); | ||
} | ||
this.range = parseRange(range, undefined, this.worksheet); | ||
this.hyperlinks = hyperlinks; | ||
} | ||
} | ||
|
||
function parseAsTextBody(input) { | ||
if (typeof input === 'string') { | ||
return { | ||
paragraphs: [parseAsParagraph(input)], | ||
}; | ||
} | ||
if (Array.isArray(input)) { | ||
return { | ||
paragraphs: input.map(parseAsParagraph), | ||
}; | ||
} | ||
const model = { | ||
paragraphs: input.paragraphs.map(parseAsParagraph), | ||
}; | ||
if (input.vertAlign) { | ||
model.vertAlign = input.vertAlign; | ||
} | ||
return model; | ||
} | ||
|
||
function parseAsParagraph(input) { | ||
if (typeof input === 'string') { | ||
return { | ||
runs: [parseAsRun(input)], | ||
}; | ||
} | ||
if (Array.isArray(input)) { | ||
return { | ||
runs: input.map(parseAsRun), | ||
}; | ||
} | ||
const model = { | ||
runs: input.runs.map(parseAsRun), | ||
}; | ||
if (input.alignment) { | ||
model.alignment = input.alignment; | ||
} | ||
return model; | ||
} | ||
|
||
function parseAsRun(input) { | ||
if (typeof input === 'string') { | ||
return { | ||
text: input, | ||
}; | ||
} | ||
const model = { | ||
text: input.text, | ||
}; | ||
if (input.font) { | ||
model.font = input.font; | ||
} | ||
return model; | ||
} | ||
|
||
module.exports = Shape; |
Oops, something went wrong.