update file/styles
This commit is contained in:
@ -65,9 +65,6 @@ describe("CharacterStyle", () => {
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
|
||||
{
|
||||
"w:rPr": [{ "w:smallCaps": {} }],
|
||||
},
|
||||
{
|
||||
"w:uiPriority": {
|
||||
_attr: {
|
||||
@ -78,6 +75,9 @@ describe("CharacterStyle", () => {
|
||||
{
|
||||
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||
},
|
||||
{
|
||||
"w:rPr": [{ "w:smallCaps": {} }],
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
@ -93,9 +93,6 @@ describe("CharacterStyle", () => {
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
|
||||
{
|
||||
"w:rPr": [{ "w:caps": {} }],
|
||||
},
|
||||
{
|
||||
"w:uiPriority": {
|
||||
_attr: {
|
||||
@ -106,6 +103,9 @@ describe("CharacterStyle", () => {
|
||||
{
|
||||
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||
},
|
||||
{
|
||||
"w:rPr": [{ "w:caps": {} }],
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
@ -121,9 +121,6 @@ describe("CharacterStyle", () => {
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
|
||||
{
|
||||
"w:rPr": [{ "w:strike": {} }],
|
||||
},
|
||||
{
|
||||
"w:uiPriority": {
|
||||
_attr: {
|
||||
@ -134,6 +131,9 @@ describe("CharacterStyle", () => {
|
||||
{
|
||||
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||
},
|
||||
{
|
||||
"w:rPr": [{ "w:strike": {} }],
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
@ -149,9 +149,6 @@ describe("CharacterStyle", () => {
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
|
||||
{
|
||||
"w:rPr": [{ "w:dstrike": {} }],
|
||||
},
|
||||
{
|
||||
"w:uiPriority": {
|
||||
_attr: {
|
||||
@ -162,6 +159,9 @@ describe("CharacterStyle", () => {
|
||||
{
|
||||
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||
},
|
||||
{
|
||||
"w:rPr": [{ "w:dstrike": {} }],
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
@ -177,6 +177,16 @@ describe("CharacterStyle", () => {
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
|
||||
{
|
||||
"w:uiPriority": {
|
||||
_attr: {
|
||||
"w:val": 99,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||
},
|
||||
{
|
||||
"w:rPr": [
|
||||
{
|
||||
@ -188,16 +198,6 @@ describe("CharacterStyle", () => {
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"w:uiPriority": {
|
||||
_attr: {
|
||||
"w:val": 99,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
@ -213,6 +213,16 @@ describe("CharacterStyle", () => {
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
|
||||
{
|
||||
"w:uiPriority": {
|
||||
_attr: {
|
||||
"w:val": 99,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||
},
|
||||
{
|
||||
"w:rPr": [
|
||||
{
|
||||
@ -227,16 +237,6 @@ describe("CharacterStyle", () => {
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"w:uiPriority": {
|
||||
_attr: {
|
||||
"w:val": 99,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
@ -255,6 +255,16 @@ describe("CharacterStyle", () => {
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
|
||||
{
|
||||
"w:uiPriority": {
|
||||
_attr: {
|
||||
"w:val": 99,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||
},
|
||||
{
|
||||
"w:rPr": [
|
||||
{
|
||||
@ -267,16 +277,6 @@ describe("CharacterStyle", () => {
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"w:uiPriority": {
|
||||
_attr: {
|
||||
"w:val": 99,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
@ -292,9 +292,6 @@ describe("CharacterStyle", () => {
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
|
||||
{
|
||||
"w:rPr": [{ "w:spacing": { _attr: { "w:val": 100 } } }],
|
||||
},
|
||||
{
|
||||
"w:uiPriority": {
|
||||
_attr: {
|
||||
@ -305,6 +302,9 @@ describe("CharacterStyle", () => {
|
||||
{
|
||||
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||
},
|
||||
{
|
||||
"w:rPr": [{ "w:spacing": { _attr: { "w:val": 100 } } }],
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
@ -317,6 +317,7 @@ describe("CharacterStyle", () => {
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
|
||||
{ "w:basedOn": { _attr: { "w:val": "otherId" } } },
|
||||
{
|
||||
"w:uiPriority": {
|
||||
_attr: {
|
||||
@ -327,7 +328,6 @@ describe("CharacterStyle", () => {
|
||||
{
|
||||
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||
},
|
||||
{ "w:basedOn": { _attr: { "w:val": "otherId" } } },
|
||||
],
|
||||
});
|
||||
});
|
||||
@ -365,9 +365,6 @@ describe("CharacterStyle", () => {
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
|
||||
{
|
||||
"w:rPr": expected,
|
||||
},
|
||||
{
|
||||
"w:uiPriority": {
|
||||
_attr: {
|
||||
@ -378,6 +375,9 @@ describe("CharacterStyle", () => {
|
||||
{
|
||||
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||
},
|
||||
{
|
||||
"w:rPr": expected,
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
@ -395,9 +395,6 @@ describe("CharacterStyle", () => {
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
|
||||
{
|
||||
"w:rPr": [{ "w:u": { _attr: { "w:val": "single" } } }],
|
||||
},
|
||||
{
|
||||
"w:uiPriority": {
|
||||
_attr: {
|
||||
@ -408,6 +405,9 @@ describe("CharacterStyle", () => {
|
||||
{
|
||||
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||
},
|
||||
{
|
||||
"w:rPr": [{ "w:u": { _attr: { "w:val": "single" } } }],
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
@ -425,9 +425,6 @@ describe("CharacterStyle", () => {
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
|
||||
{
|
||||
"w:rPr": [{ "w:u": { _attr: { "w:val": "double" } } }],
|
||||
},
|
||||
{
|
||||
"w:uiPriority": {
|
||||
_attr: {
|
||||
@ -438,6 +435,9 @@ describe("CharacterStyle", () => {
|
||||
{
|
||||
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||
},
|
||||
{
|
||||
"w:rPr": [{ "w:u": { _attr: { "w:val": "double" } } }],
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
@ -456,9 +456,6 @@ describe("CharacterStyle", () => {
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
|
||||
{
|
||||
"w:rPr": [{ "w:u": { _attr: { "w:val": "double", "w:color": "005599" } } }],
|
||||
},
|
||||
{
|
||||
"w:uiPriority": {
|
||||
_attr: {
|
||||
@ -469,6 +466,9 @@ describe("CharacterStyle", () => {
|
||||
{
|
||||
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||
},
|
||||
{
|
||||
"w:rPr": [{ "w:u": { _attr: { "w:val": "double", "w:color": "005599" } } }],
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
@ -486,9 +486,6 @@ describe("CharacterStyle", () => {
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
|
||||
{
|
||||
"w:rPr": [{ "w:em": { _attr: { "w:val": "dot" } } }],
|
||||
},
|
||||
{
|
||||
"w:uiPriority": {
|
||||
_attr: {
|
||||
@ -499,6 +496,9 @@ describe("CharacterStyle", () => {
|
||||
{
|
||||
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||
},
|
||||
{
|
||||
"w:rPr": [{ "w:em": { _attr: { "w:val": "dot" } } }],
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
@ -516,9 +516,6 @@ describe("CharacterStyle", () => {
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
|
||||
{
|
||||
"w:rPr": [{ "w:em": { _attr: { "w:val": "dot" } } }],
|
||||
},
|
||||
{
|
||||
"w:uiPriority": {
|
||||
_attr: {
|
||||
@ -529,6 +526,9 @@ describe("CharacterStyle", () => {
|
||||
{
|
||||
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||
},
|
||||
{
|
||||
"w:rPr": [{ "w:em": { _attr: { "w:val": "dot" } } }],
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
@ -545,6 +545,16 @@ describe("CharacterStyle", () => {
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
|
||||
{
|
||||
"w:uiPriority": {
|
||||
_attr: {
|
||||
"w:val": 99,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||
},
|
||||
{
|
||||
"w:rPr": [
|
||||
{
|
||||
@ -556,16 +566,6 @@ describe("CharacterStyle", () => {
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"w:uiPriority": {
|
||||
_attr: {
|
||||
"w:val": 99,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
@ -581,9 +581,6 @@ describe("CharacterStyle", () => {
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
|
||||
{
|
||||
"w:rPr": [{ "w:color": { _attr: { "w:val": "123456" } } }],
|
||||
},
|
||||
{
|
||||
"w:uiPriority": {
|
||||
_attr: {
|
||||
@ -594,6 +591,9 @@ describe("CharacterStyle", () => {
|
||||
{
|
||||
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||
},
|
||||
{
|
||||
"w:rPr": [{ "w:color": { _attr: { "w:val": "123456" } } }],
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
@ -624,9 +624,6 @@ describe("CharacterStyle", () => {
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
|
||||
{
|
||||
"w:rPr": expected,
|
||||
},
|
||||
{
|
||||
"w:uiPriority": {
|
||||
_attr: {
|
||||
@ -637,6 +634,9 @@ describe("CharacterStyle", () => {
|
||||
{
|
||||
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||
},
|
||||
{
|
||||
"w:rPr": expected,
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
@ -668,9 +668,6 @@ describe("CharacterStyle", () => {
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
|
||||
{
|
||||
"w:rPr": expected,
|
||||
},
|
||||
{
|
||||
"w:uiPriority": {
|
||||
_attr: {
|
||||
@ -681,6 +678,9 @@ describe("CharacterStyle", () => {
|
||||
{
|
||||
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||
},
|
||||
{
|
||||
"w:rPr": expected,
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
@ -692,6 +692,7 @@ describe("CharacterStyle", () => {
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
|
||||
{ "w:link": { _attr: { "w:val": "MyLink" } } },
|
||||
{
|
||||
"w:uiPriority": {
|
||||
_attr: {
|
||||
@ -702,7 +703,6 @@ describe("CharacterStyle", () => {
|
||||
{
|
||||
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||
},
|
||||
{ "w:link": { _attr: { "w:val": "MyLink" } } },
|
||||
],
|
||||
});
|
||||
});
|
||||
@ -720,8 +720,8 @@ describe("CharacterStyle", () => {
|
||||
},
|
||||
},
|
||||
},
|
||||
{ "w:unhideWhenUsed": EMPTY_OBJECT },
|
||||
{ "w:semiHidden": EMPTY_OBJECT },
|
||||
{ "w:unhideWhenUsed": EMPTY_OBJECT },
|
||||
],
|
||||
});
|
||||
});
|
||||
@ -757,9 +757,6 @@ describe("CharacterStyle", () => {
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
|
||||
{
|
||||
"w:rPr": expected,
|
||||
},
|
||||
{
|
||||
"w:uiPriority": {
|
||||
_attr: {
|
||||
@ -770,6 +767,9 @@ describe("CharacterStyle", () => {
|
||||
{
|
||||
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||
},
|
||||
{
|
||||
"w:rPr": expected,
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
@ -803,9 +803,6 @@ describe("CharacterStyle", () => {
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [
|
||||
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
|
||||
{
|
||||
"w:rPr": expected,
|
||||
},
|
||||
{
|
||||
"w:uiPriority": {
|
||||
_attr: {
|
||||
@ -816,6 +813,9 @@ describe("CharacterStyle", () => {
|
||||
{
|
||||
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||
},
|
||||
{
|
||||
"w:rPr": expected,
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
@ -1,12 +1,8 @@
|
||||
import { IRunStylePropertiesOptions, RunProperties } from "file/paragraph/run/properties";
|
||||
|
||||
import { BasedOn, Link, SemiHidden, UiPriority, UnhideWhenUsed } from "./components";
|
||||
import { Style } from "./style";
|
||||
import { IStyleOptions, Style } from "./style";
|
||||
|
||||
export interface IBaseCharacterStyleOptions {
|
||||
readonly basedOn?: string;
|
||||
readonly link?: string;
|
||||
readonly semiHidden?: boolean;
|
||||
export interface IBaseCharacterStyleOptions extends IStyleOptions {
|
||||
readonly run?: IRunStylePropertiesOptions;
|
||||
}
|
||||
|
||||
@ -19,24 +15,16 @@ export class StyleForCharacter extends Style {
|
||||
private readonly runProperties: RunProperties;
|
||||
|
||||
constructor(options: ICharacterStyleOptions) {
|
||||
super({ type: "character", styleId: options.id }, options.name);
|
||||
super(
|
||||
{ type: "character", styleId: options.id },
|
||||
{
|
||||
uiPriority: 99,
|
||||
unhideWhenUsed: true,
|
||||
...options,
|
||||
},
|
||||
);
|
||||
|
||||
this.runProperties = new RunProperties(options.run);
|
||||
|
||||
this.root.push(this.runProperties);
|
||||
this.root.push(new UiPriority(99));
|
||||
this.root.push(new UnhideWhenUsed());
|
||||
|
||||
if (options.basedOn) {
|
||||
this.root.push(new BasedOn(options.basedOn));
|
||||
}
|
||||
|
||||
if (options.link) {
|
||||
this.root.push(new Link(options.link));
|
||||
}
|
||||
|
||||
if (options.semiHidden) {
|
||||
this.root.push(new SemiHidden());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,8 +2,6 @@ import { expect } from "chai";
|
||||
import { Formatter } from "export/formatter";
|
||||
import * as components from "./components";
|
||||
|
||||
import { EMPTY_OBJECT } from "file/xml-components";
|
||||
|
||||
describe("Style components", () => {
|
||||
it("Name#constructor", () => {
|
||||
const style = new components.Name("Style Name");
|
||||
@ -11,45 +9,9 @@ describe("Style components", () => {
|
||||
expect(tree).to.deep.equal({ "w:name": { _attr: { "w:val": "Style Name" } } });
|
||||
});
|
||||
|
||||
it("BasedOn#constructor", () => {
|
||||
const style = new components.BasedOn("otherId");
|
||||
const tree = new Formatter().format(style);
|
||||
expect(tree).to.deep.equal({ "w:basedOn": { _attr: { "w:val": "otherId" } } });
|
||||
});
|
||||
|
||||
it("Next#constructor", () => {
|
||||
const style = new components.Next("otherId");
|
||||
const tree = new Formatter().format(style);
|
||||
expect(tree).to.deep.equal({ "w:next": { _attr: { "w:val": "otherId" } } });
|
||||
});
|
||||
|
||||
it("Link#constructor", () => {
|
||||
const style = new components.Link("otherId");
|
||||
const tree = new Formatter().format(style);
|
||||
expect(tree).to.deep.equal({ "w:link": { _attr: { "w:val": "otherId" } } });
|
||||
});
|
||||
|
||||
it("UiPriority#constructor", () => {
|
||||
const style = new components.UiPriority(123);
|
||||
const tree = new Formatter().format(style);
|
||||
expect(tree).to.deep.equal({ "w:uiPriority": { _attr: { "w:val": 123 } } });
|
||||
});
|
||||
|
||||
it("UnhideWhenUsed#constructor", () => {
|
||||
const style = new components.UnhideWhenUsed();
|
||||
const tree = new Formatter().format(style);
|
||||
expect(tree).to.deep.equal({ "w:unhideWhenUsed": EMPTY_OBJECT });
|
||||
});
|
||||
|
||||
it("QuickFormat#constructor", () => {
|
||||
const style = new components.QuickFormat();
|
||||
const tree = new Formatter().format(style);
|
||||
expect(tree).to.deep.equal({ "w:qFormat": EMPTY_OBJECT });
|
||||
});
|
||||
|
||||
it("SemiHidden#constructor", () => {
|
||||
const style = new components.SemiHidden();
|
||||
const tree = new Formatter().format(style);
|
||||
expect(tree).to.deep.equal({ "w:semiHidden": EMPTY_OBJECT });
|
||||
});
|
||||
});
|
||||
|
@ -1,4 +1,5 @@
|
||||
// http://officeopenxml.com/WPstyleGenProps.php
|
||||
import { decimalNumber } from "file/values";
|
||||
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||
|
||||
class ComponentAttributes extends XmlAttributeComponent<{
|
||||
@ -14,53 +15,13 @@ export class Name extends XmlComponent {
|
||||
}
|
||||
}
|
||||
|
||||
export class BasedOn extends XmlComponent {
|
||||
constructor(value: string) {
|
||||
super("w:basedOn");
|
||||
this.root.push(new ComponentAttributes({ val: value }));
|
||||
}
|
||||
}
|
||||
|
||||
export class Next extends XmlComponent {
|
||||
constructor(value: string) {
|
||||
super("w:next");
|
||||
this.root.push(new ComponentAttributes({ val: value }));
|
||||
}
|
||||
}
|
||||
|
||||
export class Link extends XmlComponent {
|
||||
constructor(value: string) {
|
||||
super("w:link");
|
||||
this.root.push(new ComponentAttributes({ val: value }));
|
||||
}
|
||||
}
|
||||
|
||||
export class UiPriority extends XmlComponent {
|
||||
constructor(value: number) {
|
||||
super("w:uiPriority");
|
||||
// TODO: this value should be a ST_DecimalNumber
|
||||
this.root.push(new ComponentAttributes({ val: value }));
|
||||
}
|
||||
}
|
||||
|
||||
export class UnhideWhenUsed extends XmlComponent {
|
||||
constructor() {
|
||||
super("w:unhideWhenUsed");
|
||||
}
|
||||
}
|
||||
|
||||
export class QuickFormat extends XmlComponent {
|
||||
constructor() {
|
||||
super("w:qFormat");
|
||||
this.root.push(new ComponentAttributes({ val: decimalNumber(value) }));
|
||||
}
|
||||
}
|
||||
|
||||
export class TableProperties extends XmlComponent {}
|
||||
|
||||
export class RsId extends XmlComponent {}
|
||||
|
||||
export class SemiHidden extends XmlComponent {
|
||||
constructor() {
|
||||
super("w:semiHidden");
|
||||
}
|
||||
}
|
||||
|
@ -154,6 +154,21 @@ describe("Default Styles", () => {
|
||||
"w:style": [
|
||||
{ _attr: { "w:type": "paragraph", "w:styleId": "FootnoteText" } },
|
||||
{ "w:name": { _attr: { "w:val": "footnote text" } } },
|
||||
{ "w:basedOn": { _attr: { "w:val": "Normal" } } },
|
||||
{ "w:link": { _attr: { "w:val": "FootnoteTextChar" } } },
|
||||
{
|
||||
"w:uiPriority": {
|
||||
_attr: {
|
||||
"w:val": 99,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:semiHidden": EMPTY_OBJECT,
|
||||
},
|
||||
{
|
||||
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||
},
|
||||
{
|
||||
"w:pPr": [
|
||||
{
|
||||
@ -185,21 +200,6 @@ describe("Default Styles", () => {
|
||||
},
|
||||
],
|
||||
},
|
||||
{ "w:basedOn": { _attr: { "w:val": "Normal" } } },
|
||||
{ "w:link": { _attr: { "w:val": "FootnoteTextChar" } } },
|
||||
{
|
||||
"w:semiHidden": EMPTY_OBJECT,
|
||||
},
|
||||
{
|
||||
"w:uiPriority": {
|
||||
_attr: {
|
||||
"w:val": 99,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
@ -211,6 +211,20 @@ describe("Default Styles", () => {
|
||||
"w:style": [
|
||||
{ _attr: { "w:type": "character", "w:styleId": "FootnoteReference" } },
|
||||
{ "w:name": { _attr: { "w:val": "footnote reference" } } },
|
||||
{ "w:basedOn": { _attr: { "w:val": "DefaultParagraphFont" } } },
|
||||
{
|
||||
"w:uiPriority": {
|
||||
_attr: {
|
||||
"w:val": 99,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:semiHidden": EMPTY_OBJECT,
|
||||
},
|
||||
{
|
||||
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||
},
|
||||
{
|
||||
"w:rPr": [
|
||||
{
|
||||
@ -222,21 +236,6 @@ describe("Default Styles", () => {
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"w:uiPriority": {
|
||||
_attr: {
|
||||
"w:val": 99,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||
},
|
||||
{ "w:basedOn": { _attr: { "w:val": "DefaultParagraphFont" } } },
|
||||
|
||||
{
|
||||
"w:semiHidden": EMPTY_OBJECT,
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
@ -248,6 +247,21 @@ describe("Default Styles", () => {
|
||||
"w:style": [
|
||||
{ _attr: { "w:type": "character", "w:styleId": "FootnoteTextChar" } },
|
||||
{ "w:name": { _attr: { "w:val": "Footnote Text Char" } } },
|
||||
{ "w:basedOn": { _attr: { "w:val": "DefaultParagraphFont" } } },
|
||||
{ "w:link": { _attr: { "w:val": "FootnoteText" } } },
|
||||
{
|
||||
"w:uiPriority": {
|
||||
_attr: {
|
||||
"w:val": 99,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:semiHidden": EMPTY_OBJECT,
|
||||
},
|
||||
{
|
||||
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||
},
|
||||
{
|
||||
"w:rPr": [
|
||||
{
|
||||
@ -266,21 +280,6 @@ describe("Default Styles", () => {
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"w:uiPriority": {
|
||||
_attr: {
|
||||
"w:val": 99,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||
},
|
||||
{ "w:basedOn": { _attr: { "w:val": "DefaultParagraphFont" } } },
|
||||
{ "w:link": { _attr: { "w:val": "FootnoteText" } } },
|
||||
{
|
||||
"w:semiHidden": EMPTY_OBJECT,
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
@ -292,6 +291,17 @@ describe("Default Styles", () => {
|
||||
"w:style": [
|
||||
{ _attr: { "w:type": "character", "w:styleId": "Hyperlink" } },
|
||||
{ "w:name": { _attr: { "w:val": "Hyperlink" } } },
|
||||
{ "w:basedOn": { _attr: { "w:val": "DefaultParagraphFont" } } },
|
||||
{
|
||||
"w:uiPriority": {
|
||||
_attr: {
|
||||
"w:val": 99,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||
},
|
||||
{
|
||||
"w:rPr": [
|
||||
{ "w:u": { _attr: { "w:val": "single" } } },
|
||||
@ -304,17 +314,6 @@ describe("Default Styles", () => {
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"w:uiPriority": {
|
||||
_attr: {
|
||||
"w:val": 99,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||
},
|
||||
{ "w:basedOn": { _attr: { "w:val": "DefaultParagraphFont" } } },
|
||||
],
|
||||
});
|
||||
});
|
||||
|
@ -1,17 +1,8 @@
|
||||
import { IParagraphStylePropertiesOptions, IRunStylePropertiesOptions, ParagraphProperties } from "file/paragraph";
|
||||
import { RunProperties } from "file/paragraph/run/properties";
|
||||
import { IStyleOptions, Style } from "./style";
|
||||
|
||||
import { BasedOn, Link, Next, QuickFormat, SemiHidden, UiPriority, UnhideWhenUsed } from "./components";
|
||||
import { Style } from "./style";
|
||||
|
||||
export interface IBaseParagraphStyleOptions {
|
||||
readonly basedOn?: string;
|
||||
readonly next?: string;
|
||||
readonly quickFormat?: boolean;
|
||||
readonly link?: string;
|
||||
readonly semiHidden?: boolean;
|
||||
readonly uiPriority?: number;
|
||||
readonly unhideWhenUsed?: boolean;
|
||||
export interface IBaseParagraphStyleOptions extends IStyleOptions {
|
||||
readonly paragraph?: IParagraphStylePropertiesOptions;
|
||||
readonly run?: IRunStylePropertiesOptions;
|
||||
}
|
||||
@ -26,40 +17,12 @@ export class StyleForParagraph extends Style {
|
||||
private readonly runProperties: RunProperties;
|
||||
|
||||
constructor(options: IParagraphStyleOptions) {
|
||||
super({ type: "paragraph", styleId: options.id }, options.name);
|
||||
super({ type: "paragraph", styleId: options.id }, options);
|
||||
|
||||
this.paragraphProperties = new ParagraphProperties(options.paragraph);
|
||||
this.runProperties = new RunProperties(options.run);
|
||||
|
||||
this.root.push(this.paragraphProperties);
|
||||
this.root.push(this.runProperties);
|
||||
|
||||
if (options.basedOn) {
|
||||
this.root.push(new BasedOn(options.basedOn));
|
||||
}
|
||||
|
||||
if (options.next) {
|
||||
this.root.push(new Next(options.next));
|
||||
}
|
||||
|
||||
if (options.quickFormat) {
|
||||
this.root.push(new QuickFormat());
|
||||
}
|
||||
|
||||
if (options.link) {
|
||||
this.root.push(new Link(options.link));
|
||||
}
|
||||
|
||||
if (options.semiHidden) {
|
||||
this.root.push(new SemiHidden());
|
||||
}
|
||||
|
||||
if (options.uiPriority) {
|
||||
this.root.push(new UiPriority(options.uiPriority));
|
||||
}
|
||||
|
||||
if (options.unhideWhenUsed) {
|
||||
this.root.push(new UnhideWhenUsed());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,11 +5,14 @@ import { Style } from "./style";
|
||||
describe("Style", () => {
|
||||
describe("#constructor()", () => {
|
||||
it("should set the given properties", () => {
|
||||
const style = new Style({
|
||||
type: "paragraph",
|
||||
styleId: "myStyleId",
|
||||
default: true,
|
||||
});
|
||||
const style = new Style(
|
||||
{
|
||||
type: "paragraph",
|
||||
styleId: "myStyleId",
|
||||
default: true,
|
||||
},
|
||||
{},
|
||||
);
|
||||
const tree = new Formatter().format(style);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId", "w:default": true } },
|
||||
@ -22,7 +25,7 @@ describe("Style", () => {
|
||||
type: "paragraph",
|
||||
styleId: "myStyleId",
|
||||
},
|
||||
"Style Name",
|
||||
{ name: "Style Name" },
|
||||
);
|
||||
const tree = new Formatter().format(style);
|
||||
expect(tree).to.deep.equal({
|
||||
|
@ -1,5 +1,36 @@
|
||||
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||
import { Name } from "./components";
|
||||
import { OnOffElement, StringValueElement, XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||
import { Name, UiPriority } from "./components";
|
||||
|
||||
// <xsd:complexType name="CT_Style">
|
||||
// <xsd:sequence>
|
||||
// <xsd:element name="name" type="CT_String" minOccurs="0" maxOccurs="1"/>
|
||||
// <xsd:element name="aliases" type="CT_String" minOccurs="0"/>
|
||||
// <xsd:element name="basedOn" type="CT_String" minOccurs="0"/>
|
||||
// <xsd:element name="next" type="CT_String" minOccurs="0"/>
|
||||
// <xsd:element name="link" type="CT_String" minOccurs="0"/>
|
||||
// <xsd:element name="autoRedefine" type="CT_OnOff" minOccurs="0"/>
|
||||
// <xsd:element name="hidden" type="CT_OnOff" minOccurs="0"/>
|
||||
// <xsd:element name="uiPriority" type="CT_DecimalNumber" minOccurs="0"/>
|
||||
// <xsd:element name="semiHidden" type="CT_OnOff" minOccurs="0"/>
|
||||
// <xsd:element name="unhideWhenUsed" type="CT_OnOff" minOccurs="0"/>
|
||||
// <xsd:element name="qFormat" type="CT_OnOff" minOccurs="0"/>
|
||||
// <xsd:element name="locked" type="CT_OnOff" minOccurs="0"/>
|
||||
// <xsd:element name="personal" type="CT_OnOff" minOccurs="0"/>
|
||||
// <xsd:element name="personalCompose" type="CT_OnOff" minOccurs="0"/>
|
||||
// <xsd:element name="personalReply" type="CT_OnOff" minOccurs="0"/>
|
||||
// <xsd:element name="rsid" type="CT_LongHexNumber" minOccurs="0"/>
|
||||
// <xsd:element name="pPr" type="CT_PPrGeneral" minOccurs="0" maxOccurs="1"/>
|
||||
// <xsd:element name="rPr" type="CT_RPr" minOccurs="0" maxOccurs="1"/>
|
||||
// <xsd:element name="tblPr" type="CT_TblPrBase" minOccurs="0" maxOccurs="1"/>
|
||||
// <xsd:element name="trPr" type="CT_TrPr" minOccurs="0" maxOccurs="1"/>
|
||||
// <xsd:element name="tcPr" type="CT_TcPr" minOccurs="0" maxOccurs="1"/>
|
||||
// <xsd:element name="tblStylePr" type="CT_TblStylePr" minOccurs="0" maxOccurs="unbounded"/>
|
||||
// </xsd:sequence>
|
||||
// <xsd:attribute name="type" type="ST_StyleType" use="optional"/>
|
||||
// <xsd:attribute name="styleId" type="s:ST_String" use="optional"/>
|
||||
// <xsd:attribute name="default" type="s:ST_OnOff" use="optional"/>
|
||||
// <xsd:attribute name="customStyle" type="s:ST_OnOff" use="optional"/>
|
||||
// </xsd:complexType>
|
||||
|
||||
export interface IStyleAttributes {
|
||||
readonly type?: string;
|
||||
@ -8,6 +39,17 @@ export interface IStyleAttributes {
|
||||
readonly customStyle?: string;
|
||||
}
|
||||
|
||||
export interface IStyleOptions {
|
||||
readonly name?: string;
|
||||
readonly basedOn?: string;
|
||||
readonly next?: string;
|
||||
readonly link?: string;
|
||||
readonly uiPriority?: number;
|
||||
readonly semiHidden?: boolean;
|
||||
readonly unhideWhenUsed?: boolean;
|
||||
readonly quickFormat?: boolean;
|
||||
}
|
||||
|
||||
class StyleAttributes extends XmlAttributeComponent<IStyleAttributes> {
|
||||
protected readonly xmlKeys = {
|
||||
type: "w:type",
|
||||
@ -18,11 +60,39 @@ class StyleAttributes extends XmlAttributeComponent<IStyleAttributes> {
|
||||
}
|
||||
|
||||
export class Style extends XmlComponent {
|
||||
constructor(attributes: IStyleAttributes, name?: string) {
|
||||
constructor(attributes: IStyleAttributes, options: IStyleOptions) {
|
||||
super("w:style");
|
||||
this.root.push(new StyleAttributes(attributes));
|
||||
if (name) {
|
||||
this.root.push(new Name(name));
|
||||
if (options.name) {
|
||||
this.root.push(new Name(options.name));
|
||||
}
|
||||
|
||||
if (options.basedOn) {
|
||||
this.root.push(new StringValueElement("w:basedOn", options.basedOn));
|
||||
}
|
||||
|
||||
if (options.next) {
|
||||
this.root.push(new StringValueElement("w:next", options.next));
|
||||
}
|
||||
|
||||
if (options.link) {
|
||||
this.root.push(new StringValueElement("w:link", options.link));
|
||||
}
|
||||
|
||||
if (options.uiPriority !== undefined) {
|
||||
this.root.push(new UiPriority(options.uiPriority));
|
||||
}
|
||||
|
||||
if (options.semiHidden !== undefined) {
|
||||
this.root.push(new OnOffElement("w:semiHidden", options.semiHidden));
|
||||
}
|
||||
|
||||
if (options.unhideWhenUsed !== undefined) {
|
||||
this.root.push(new OnOffElement("w:unhideWhenUsed", options.unhideWhenUsed));
|
||||
}
|
||||
|
||||
if (options.quickFormat !== undefined) {
|
||||
this.root.push(new OnOffElement("w:qFormat", options.quickFormat));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,13 @@ export interface IStylesOptions {
|
||||
readonly importedStyles?: (XmlComponent | StyleForParagraph | StyleForCharacter | ImportedXmlComponent)[];
|
||||
}
|
||||
|
||||
// <xsd:complexType name="CT_Styles">
|
||||
// <xsd:sequence>
|
||||
// <xsd:element name="docDefaults" type="CT_DocDefaults" minOccurs="0"/>
|
||||
// <xsd:element name="latentStyles" type="CT_LatentStyles" minOccurs="0" maxOccurs="1"/>
|
||||
// <xsd:element name="style" type="CT_Style" minOccurs="0" maxOccurs="unbounded"/>
|
||||
// </xsd:sequence>
|
||||
// </xsd:complexType>
|
||||
export class Styles extends XmlComponent {
|
||||
constructor(options: IStylesOptions) {
|
||||
super("w:styles");
|
||||
|
Reference in New Issue
Block a user