CS layout WIP, added Jest

This commit is contained in:
Lukas Obermann
2016-10-30 13:30:14 +01:00
parent b0ea6309ce
commit 95ff8caede
5862 changed files with 520275 additions and 1330 deletions
+15 -5
View File
@@ -19,8 +19,8 @@ $border-2px: 1.25pt;
.titlebar, .subtabs {
display: none;
}
section#misc {
section#profile {
padding: 0 !important;
overflow: visible !important;
background: white !important;
@@ -62,12 +62,17 @@ $border-2px: 1.25pt;
> .header {
.attributes {
.attr {
> .attr {
> .value {
border-width: $border-2px !important;
border-width: calc(0.5mm - 0.57pt/2) !important;
> div {
border-width: $border-1px !important;
border-width: 0.57pt !important;
position: relative;
> div {
@include size(100%);
}
}
}
}
@@ -99,6 +104,11 @@ $border-2px: 1.25pt;
> .values {
> div {
border-width: $border-1px !important;
> div {
width: calc(1.2mm - 0.57pt);
height: calc(1.2mm - 0.57pt);
}
}
}
}
+15 -23
View File
@@ -21,7 +21,7 @@
@import "components/content/sheets/TalentsSheet";
@import "components/content/skills/Skills";
#body > main > section {
section {
@extend %max-size-relative;
padding-top: $titlebar-height;
z-index: 0;
@@ -37,6 +37,20 @@
flex: none;
}
.scroll {
flex: 1 1 100%;
.scroll-inner {
padding: 0 35px;
.textfield, .dropdown {
+ .btn-icon {
margin: 10px 0 10px 11px;
}
}
}
}
> .page {
flex: 1 1 auto;
padding: 11px 0 3px;
@@ -49,28 +63,6 @@
overflow: hidden;
height: 100%;
.scroll {
flex: 1 1 100%;
.scroll-inner {
padding: 0 35px;
display: flex;
flex-wrap: wrap;
> div:not(.btn):not(.btn-icon):not(.textfield):not(.dropdown), > h2, > h3, > h4, > ul {
flex: 1 0 auto;
width: 100%;
margin-top: 20px;
}
.textfield, .dropdown {
+ .btn-icon {
margin: 10px 0 10px 11px;
}
}
}
}
> .options {
flex: 1 0 auto;
width: 200px;
+1 -1
View File
@@ -3,7 +3,7 @@
.scroll-inner {
padding-bottom: 22px;
> div.padding {
> .padding {
height: 22px;
}
@@ -85,7 +85,7 @@
}
}
> .btn.primary {
> .btn.btn-primary {
min-width: 140px;
}
}
@@ -80,6 +80,25 @@
}
}
}
.personal-data {
display: flex;
flex-wrap: wrap;
> div {
flex: none;
display: flex;
flex-wrap: wrap;
width: 323px;
margin-right: 22px;
margin-bottom: 10px;
align-items: flex-end;
}
}
.end-char-creation {
margin-top: 20px;
}
}
}
+12 -147
View File
@@ -42,22 +42,22 @@
> .ap-portrait {
flex: none;
width: 290px;
width: 7.6cm;
margin-left: 10px;
display: flex;
flex-wrap: wrap;
> .labelbox {
display: flex;
height: 40px;
margin: 14px 0 0;
width: 170px;
height: 1cm;
margin: 0.38cm 0 0;
width: 4.4cm;
&.el {
width: 100%;
.box {
width: 170px;
width: 4.4cm;
font-size: 20px;
font-weight: 400;
}
@@ -71,7 +71,7 @@
.box {
font: bold 24px/40px Alegreya Sans;
text-align: center;
width: 70px;
width: 2cm;
}
label {
@@ -84,11 +84,16 @@
flex-direction: column;
.box {
width: 120px;
width: 3.2cm;
height: 148px;
.avatar {
@include size(100%);
> img {
object-fit: cover;
@include size(100%);
}
}
}
@@ -195,144 +200,4 @@
}
}
}
> .head {
padding-bottom: 20px;
border-bottom: 2px solid black;
height: 172px;
> * {
float: left;
}
.head-left {
@include size(150px);
.portrait {
@include size(100%);
overflow: hidden;
display: flex;
justify-content: center;
align-items: center;
img {
border: 4px solid black;
max-height: 100%;
max-width: 100%;
border-radius: 50%;
}
}
}
.head-right {
@include size(568px 150px);
padding-left: 20px;
padding-top: 15px;
line-height: 23px;
position: relative;
div.classes {
h1.name {
font: bold 20px/28px Caudex;
margin-bottom: 10px;
letter-spacing: 0.05em;
text-transform: uppercase;
}
h2.race-culture {
font: bold 14px/20px Caudex;
letter-spacing: 0.05em;
margin-bottom: 10px;
}
h2.prof {
font: bold 14px/20px Caudex;
letter-spacing: 0.05em;
}
}
div.main-values {
text-align: right;
padding-top: 5px;
position: absolute;
top: 0;
right: 0;
div.ap > span:not(.level) {
opacity: 0.25;
}
div.so {
padding-top: 10px;
}
}
div.qualities {
width: 100%;
float: left;
margin-top: 10px;
display: flex;
justify-content: space-between;
font: 13px/20px "Source Sans Pro";
.q-available {
opacity: 0.5;
}
}
}
}
> .left {
margin-top: 20px;
border-right: 2px solid black;
width: 200px;
@include calc(height, '100% - 192px');
float: left;
.base-stats {
> div {
height: 16px;
> div {
float: left;
> span:first-child {
display: inline-block;
width: 30px;
}
}
}
}
.vt-list, .nt-list {
list-style: none outside none;
> li {
display: flex;
> div {
flex: 1 0 auto;
&:first-child {
width: 170px;
padding-left: 10px;
text-indent: -10px;
}
&:last-child {
width: 28px;
}
}
}
}
}
> .right {
@include calc(height, '100% - 192px');
float: right;
width: 518px;
margin-top: 20px;
padding-left: 20px;
}
}
+175 -6
View File
@@ -1,3 +1,5 @@
$border: 0.57pt solid black;
@import "layout/Box";
@import "layout/LabelBox";
@import "layout/Plain";
@@ -10,17 +12,18 @@
}
.scroll-inner {
display: flex;
flex-flow: column nowrap;
align-items: center;
justify-content: center;
.sheet {
flex: none;
width: 21cm;
height: 29.7cm;
background: white;
margin-top: 30px;
text-align: left;
padding: 1cm;
padding: 0.89cm;
font: 11px/16px Alegreya;
color: black;
letter-spacing: 0;
@@ -82,12 +85,13 @@
flex: none;
display: flex;
flex-wrap: wrap-reverse;
width: 475px;
width: 12.65cm;
.attr {
flex: none;
margin: 5px 5px 0; // change
margin: 1.5mm 1.5mm 0; // change
position: relative; // change
@include size(13mm);
> .short {
font: bold 10px/14px Alegreya; // change
@@ -101,11 +105,13 @@
}
> .value {
border: 2px solid transparent;
border-width: calc(0.5mm - 0.57pt/2);
border-style: solid;
border-color: transparent;
padding: 0; // change
> div {
border: 1px solid black; // change
border: $border; // change
padding: 0; // change
> div {
@@ -163,3 +169,166 @@
}
}
}
// #sheets {
// flex-flow: column nowrap;
// > .options {
// margin-bottom: 11px;
// }
// .scroll-inner {
// flex-flow: column nowrap;
// align-items: center;
// justify-content: center;
// .sheet {
// flex: none;
// width: 21cm;
// height: 29.7cm;
// background: white;
// margin-top: 30px;
// text-align: left;
// padding: 1cm;
// font: 11px/16px Alegreya;
// color: black;
// letter-spacing: 0;
// display: flex;
// flex-direction: column;
// &:last-child {
// margin-bottom: 30px;
// }
// > div {
// display: flex;
// justify-content: space-between;
// }
// h1, h2, h3 {
// color: black;
// margin: 0;
// }
// h1 {
// font: italic bold 24px/22px Alegreya;
// }
// h2 {
// font: 17px/13px Alegreya SC;
// text-transform: none;
// letter-spacing: 0;
// }
// h3 {
// font: bold 16px Alegreya;
// letter-spacing: 0;
// }
// > .header {
// margin-bottom: 11px;
// align-items: flex-end;
// flex: none;
// height: 110px;
// > .title {
// flex: 1 1 100%;
// height: 50px;
// display: flex;
// flex-direction: column;
// justify-content: center;
// h1, h2 {
// text-align: center;
// }
// h2 {
// margin-top: 5px;
// }
// }
// .attributes {
// flex: none;
// display: flex;
// flex-wrap: wrap-reverse;
// width: 475px;
// .attr {
// flex: none;
// margin: 5px 5px 0; // change
// position: relative; // change
// > .short {
// font: bold 10px/14px Alegreya; // change
// color: black; // change
// letter-spacing: 0.05em;
// text-transform: uppercase;
// text-align: center;
// position: absolute; // change
// top: 0; // change
// padding: 4px 8px 0; // change
// }
// > .value {
// border: 2px solid transparent;
// padding: 0; // change
// > div {
// border: 1px solid black; // change
// padding: 0; // change
// > div {
// @include size(44px);
// text-align: center;
// font: bold 21px/30px Alegreya Sans; // change
// color: black; // change
// letter-spacing: 0.05em;
// text-transform: uppercase;
// background: transparent; // change
// overflow: hidden;
// padding-top: 14px; // change
// }
// }
// }
// &.ATTR_1 > .value {
// border-color: red;
// }
// &.ATTR_2 > .value {
// border-color: #90c;
// }
// &.ATTR_3 > .value {
// border-color: #3c3;
// }
// &.ATTR_4 > .value {
// border-color: black;
// }
// &.ATTR_5 > .value {
// border-color: yellow;
// }
// &.ATTR_6 > .value {
// border-color: blue;
// }
// &.ATTR_7 > .value {
// border-color: white;
// }
// &.ATTR_8 {
// margin-right: 0;
// > .value {
// border-color: #f60;
// }
// }
// }
// }
// }
// }
// }
// }
@@ -1,3 +1,3 @@
#sheets .box {
border: 1px solid black;
border: $border;
}
@@ -5,6 +5,8 @@
> .box {
flex: none;
height: 1cm;
line-height: 1cm;
}
> label {
+1 -7
View File
@@ -3,13 +3,7 @@
margin: 10px 0;
font: 500 13px/30px Alegreya Sans;
label {
color: #a19b8f;
letter-spacing: 0.05em;
display: block;
font: 500 10px/1 Alegreya Sans;
padding-bottom: 6px;
}
@extend %label;
> div {
position: relative;
+2 -9
View File
@@ -17,15 +17,8 @@
visibility: hidden;
}
}
label {
color: #a19b8f;
font-size: 10px;
line-height: 10px;
letter-spacing: 0.05em;
display: block;
padding-bottom: 6px;
}
@extend %label;
input, textarea {
width: 100%;
@@ -0,0 +1,3 @@
.textfield-btn-group {
display: flex;
}
+11
View File
@@ -1,3 +1,13 @@
%label {
label {
color: #a19b8f;
letter-spacing: 0.05em;
display: block;
font: 500 12px/1 Alegreya Sans;
padding-bottom: 6px;
}
}
@import "Avatar";
@import "BorderButton";
@import "Card";
@@ -13,5 +23,6 @@
@import "Slider";
@import "SubTabs";
@import "TextField";
@import "TextFieldButtonGroup";
@import "TitleBar";
@import "ToolBar";
+1250 -707
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
File diff suppressed because one or more lines are too long
+50 -2
View File
@@ -20,13 +20,37 @@ var ProfileActions = {
changeAvatar: function({ source: type, extern, file }) {
WebAPIUtils.changeHeroAvatar(type, type === 'ext' ? extern : file);
},
changeHair: function(option) {
changeFamily: function(value) {
AppDispatcher.dispatch({
actionType: ActionTypes.UPDATE_FAMILY,
value
});
},
changePlaceOfBirth: function(value) {
AppDispatcher.dispatch({
actionType: ActionTypes.UPDATE_PLACEOFBIRTH,
value
});
},
changeDateOfBirth: function(value) {
AppDispatcher.dispatch({
actionType: ActionTypes.UPDATE_DATEOFBIRTH,
value
});
},
changeAge: function(value) {
AppDispatcher.dispatch({
actionType: ActionTypes.UPDATE_AGE,
value
});
},
changeHaircolor: function(option) {
AppDispatcher.dispatch({
actionType: ActionTypes.UPDATE_HAIRCOLOR,
option
});
},
changeEyes: function(option) {
changeEyecolor: function(option) {
AppDispatcher.dispatch({
actionType: ActionTypes.UPDATE_EYECOLOR,
option
@@ -44,6 +68,30 @@ var ProfileActions = {
value
});
},
changeTitle: function(value) {
AppDispatcher.dispatch({
actionType: ActionTypes.UPDATE_TITLE,
value
});
},
changeSocialStatus: function(option) {
AppDispatcher.dispatch({
actionType: ActionTypes.UPDATE_SOCIALSTATUS,
option
});
},
changeCharacteristics: function(value) {
AppDispatcher.dispatch({
actionType: ActionTypes.UPDATE_CHARACTERISTICS,
value
});
},
changeOtherInfo: function(value) {
AppDispatcher.dispatch({
actionType: ActionTypes.UPDATE_OTHERINFO,
value
});
},
rerollHair: function() {
AppDispatcher.dispatch({
actionType: ActionTypes.REROLL_HAIRCOLOR
+1 -1
View File
@@ -16,7 +16,7 @@ var ServerActions = {
});
},
connectionError: function(error) {
reactAlert('Verbindung nicht möglich', 'Die App konnte keine Verbindung zum Server herstellen. Bitte überprüfe deine Internetverbindung! ' + error + ' Es kann bei diesem Problem auch möglich sein, dass etwas im Programmablauf nicht stimmt. Informiere uns bitte über dein Problem, sollte es deiner Erkenntnis nach nicht an der Verbindung liegen!');
reactAlert('Verbindung nicht möglich', 'Die App konnte keine Verbindung zum Server herstellen. Bitte überprüfe deine Internetverbindung! ' + JSON.stringify(error) + ' Es kann bei diesem Problem auch möglich sein, dass etwas im Programmablauf nicht stimmt. Informiere uns bitte über dein Problem, sollte es deiner Erkenntnis nach nicht an der Verbindung liegen!');
AppDispatcher.dispatch({
actionType: ActionTypes.WAIT_END
});
+25 -20
View File
@@ -5,6 +5,7 @@ import IconButton from '../../layout/IconButton';
import React, { Component } from 'react';
import Scroll from '../../layout/Scroll';
import TextField from '../../layout/TextField';
import TextFieldButtonGroup from '../../layout/TextFieldButtonGroup';
class Account extends Component {
@@ -24,29 +25,33 @@ class Account extends Component {
<section id="account">
<div className="page">
<Scroll>
<TextField
hint="Benutzernamen ändern"
value={this.state.newName}
onChange={this.handleName}
/>
<IconButton
icon="&#xE876;"
onClick={this.changeName}
disabled={this.state.newName === '' || this.state.newName.length < 3 || this.state.newName.length > 20}
/>
<TextFieldButtonGroup>
<TextField
hint="Benutzernamen ändern"
value={this.state.newName}
onChange={this.handleName}
/>
<IconButton
icon="&#xE876;"
onClick={this.changeName}
disabled={this.state.newName === '' || this.state.newName.length < 3 || this.state.newName.length > 20}
/>
</TextFieldButtonGroup>
<div className="padding">
{(this.state.newName.length < 3 || this.state.newName.length > 20) && this.state.newName !== '' ? 'Der Benutzername muss mindestens 3 und darf maximal 20 Zeichen umfassen.' : null}
</div>
<TextField
hint="Passwort ändern"
value={this.state.newPassword}
onChange={this.handlePassword}
/>
<IconButton
icon="&#xE876;"
onClick={this.changePassword}
disabled={this.state.newPassword === '' || this.state.newPassword.length < 5 || this.state.newPassword.length > 20}
/>
<TextFieldButtonGroup>
<TextField
hint="Passwort ändern"
value={this.state.newPassword}
onChange={this.handlePassword}
/>
<IconButton
icon="&#xE876;"
onClick={this.changePassword}
disabled={this.state.newPassword === '' || this.state.newPassword.length < 5 || this.state.newPassword.length > 20}
/>
</TextFieldButtonGroup>
<div className="padding">
{(this.state.newPassword.length < 5 || this.state.newPassword.length > 20) && this.state.newPassword !== '' ? 'Das Passwort muss mindestens 5 und darf maximal 20 Zeichen umfassen.' : null}
</div>
+1 -1
View File
@@ -7,7 +7,7 @@ import DisAdvStore from '../../../stores/DisAdvStore';
import ELStore from '../../../stores/ELStore';
import LabelBox from '../../layout/sheets/LabelBox';
import MainSheetCalcItem from './MainSheetCalcItem';
import OverviewDisAdv from './OverviewDisAdv';
import OverviewConstSkills from './OverviewConstSkills';
import Plain from '../../layout/sheets/Plain';
import ProfessionStore from '../../../stores/rcp/ProfessionStore';
import ProfessionVariantStore from '../../../stores/rcp/ProfessionVariantStore';
+1 -1
View File
@@ -7,7 +7,7 @@ import DisAdvStore from '../../../stores/DisAdvStore';
import ELStore from '../../../stores/ELStore';
import LabelBox from '../../layout/sheets/LabelBox';
import MainSheetCalcItem from './MainSheetCalcItem';
import OverviewDisAdv from './OverviewDisAdv';
import OverviewConstSkills from './OverviewConstSkills';
import Plain from '../../layout/sheets/Plain';
import ProfessionStore from '../../../stores/rcp/ProfessionStore';
import ProfessionVariantStore from '../../../stores/rcp/ProfessionVariantStore';
@@ -7,7 +7,6 @@ import DisAdvStore from '../../../stores/DisAdvStore';
import ELStore from '../../../stores/ELStore';
import LabelBox from '../../layout/sheets/LabelBox';
import MainSheetCalcItem from './MainSheetCalcItem';
import OverviewDisAdv from './OverviewDisAdv';
import Plain from '../../layout/sheets/Plain';
import ProfessionStore from '../../../stores/rcp/ProfessionStore';
import ProfessionVariantStore from '../../../stores/rcp/ProfessionVariantStore';
+37 -164
View File
@@ -1,21 +1,19 @@
import AttributeStore from '../../../stores/AttributeStore';
import APStore from '../../../stores/APStore';
import Avatar from '../../layout/Avatar';
import Box from '../../layout/sheets/Box';
import CultureStore from '../../../stores/rcp/CultureStore';
import DisAdvStore from '../../../stores/DisAdvStore';
import ELStore from '../../../stores/ELStore';
import LabelBox from '../../layout/sheets/LabelBox';
import ListStore from '../../../stores/ListStore';
import MainSheetCalcItem from './MainSheetCalcItem';
import OverviewDisAdv from './OverviewDisAdv';
import Plain from '../../layout/sheets/Plain';
import MainSheetCalc from './MainSheetCalc';
import MainSheetPersonalData from './MainSheetPersonalData';
import OverviewConstSkills from './OverviewConstSkills';
import ProfileStore from '../../../stores/ProfileStore';
import ProfessionStore from '../../../stores/rcp/ProfessionStore';
import ProfessionVariantStore from '../../../stores/rcp/ProfessionVariantStore';
import RaceStore from '../../../stores/rcp/RaceStore';
import React, { Component } from 'react';
import SheetHeader from './SheetHeader';
import SpecialAbilitiesStore from '../../../stores/SpecialAbilitiesStore';
import TextBox from '../../layout/sheets/TextBox';
class MainSheet extends Component {
@@ -26,180 +24,55 @@ class MainSheet extends Component {
render() {
const source = {
attributes: AttributeStore.getAllForView(),
baseValues: AttributeStore.getBaseValues(),
race: RaceStore.getCurrentName(),
culture: CultureStore.getCurrentName(),
profession: ProfessionVariantStore.getCurrentName() !== null ? `${ProfessionStore.getCurrentName()} (${ProfessionVariantStore.getCurrentName()})` : ProfessionStore.getCurrentName(),
el: ELStore.getStart().name,
apTotal: APStore.get(),
apUsed: APStore.getUsed(),
advActive: DisAdvStore.getActiveForView(true),
disadvActive: DisAdvStore.getActiveForView(false),
name: ProfileStore.getName(),
portrait: ProfileStore.getPortrait()
};
const ap = APStore.getAll();
const el = ELStore.getStart().name;
const profile = ProfileStore.getAll();
const race = RaceStore.getCurrentName();
const culture = CultureStore.getCurrentName();
const profession = ProfessionVariantStore.getCurrentName() !== null ? `${ProfessionStore.getCurrentName()} (${ProfessionVariantStore.getCurrentName()})` : ProfessionStore.getCurrentName();
const haircolorTags = ProfileStore.getHaircolorTags();
const eyecolorTags = ProfileStore.getEyecolorTags();
const socialstatusTags = ProfileStore.getSocialstatusTags();
const { attributes, baseValues, race, culture, profession, el, apTotal, apUsed, advActive, disadvActive, name, portrait } = source;
const advActive = DisAdvStore.getActiveForView(true);
const disadvActive = DisAdvStore.getActiveForView(false);
const commonsaActive = SpecialAbilitiesStore.getActiveForView(1,2);
const attributes = AttributeStore.getAllForView();
const attrPrimary = [ListStore.getPrimaryAttrID(1), ListStore.getPrimaryAttrID(2)];
const baseValues = AttributeStore.getBaseValues();
return (
<div className="sheet main">
<SheetHeader title="Persönliche Daten" />
<div className="upper">
<div className="info">
<Plain className="name" label="Name" value={name} />
<Plain className="family" label="Familie" />
<Plain className="placeofbirth" label="Geburtsort" />
<Plain className="dateofbirth" label="Geburtsdatum" />
<Plain className="age" label="Alter" />
<Plain className="gender" label="Geschlecht" />
<Plain className="race" label="Spezies" value={race} />
<Plain className="size" label="Größe" />
<Plain className="weight" label="Gewicht" />
<Plain className="haircolor" label="Haarfarbe" />
<Plain className="eyecolor" label="Augenfarbe" />
<Plain className="culture" label="Kultur" value={culture} />
<Plain className="profession" label="Profession" value={profession} />
<Plain className="title" label="Titel" />
<Plain className="socialstatus" label="Sozialstatus" />
<Plain className="characteristics" label="Charakteristika" />
<Plain className="other" label="Sonstiges" />
</div>
<div className="ap-portrait">
<LabelBox className="el" label="Erfahrungsgrad" value={el} />
<LabelBox className="ap-total" label="AP gesamt" value={apTotal} />
<LabelBox className="portrait" label="Porträt/Wappen"><Avatar src={portrait} /></LabelBox>
<LabelBox className="ap-available" label="AP verfügbar" value={apTotal - apUsed} />
<LabelBox className="ap-used" label="AP ausgegeben" value={apUsed} />
</div>
</div>
<MainSheetPersonalData
ap={ap}
culture={culture}
el={el}
eyecolorTags={eyecolorTags}
haircolorTags={haircolorTags}
profession={profession}
profile={profile}
race={race}
socialstatusTags={socialstatusTags}
/>
<div className="lower">
<div className="lists">
<TextBox className="adv" label="Vorteile">
<OverviewDisAdv list={advActive} />
<OverviewConstSkills list={advActive} />
</TextBox>
<TextBox className="disadv" label="Nachteile">
<OverviewDisAdv list={disadvActive} />
<OverviewConstSkills list={disadvActive} />
</TextBox>
<TextBox className="common_special" label="Allgemeine Sonderfertigkeiten">
<div></div>
<OverviewConstSkills list={commonsaActive} />
</TextBox>
</div>
{
attributes.length > 0 ? (
<div className="calculated">
<div className="calc-header">
<div>Wert</div>
<div>Bonus/<br/>Malus</div>
<div>Zukauf</div>
<div>Max</div>
</div>
<MainSheetCalcItem
label="Lebensenergie"
calc="(GW der Spezies + KO + KO)"
value={baseValues.le + attributes[6].value * 2}
add={do {
if (DisAdvStore.get('ADV_25') && DisAdvStore.get('ADV_25').active)
DisAdvStore.get('ADV_25').tier;
else if (DisAdvStore.get('DISADV_28') && DisAdvStore.get('DISADV_28').active)
-DisAdvStore.get('DISADV_28').tier;
else
0;
}}
purchased={baseValues.leAdd}
subLabel="Grundwert"
subArray={[baseValues.le]} />
<MainSheetCalcItem
label="Astralenergie"
calc="(20 durch Zauberer + Leiteigenschaft)"
value={attrPrimary[0] === 'ATTR_0' || !AttributeStore.get(attrPrimary[0]) ? 0 : 20 + AttributeStore.get(attrPrimary[0]).value}
add={do {
if (DisAdvStore.get('ADV_23') && DisAdvStore.get('ADV_23').active)
DisAdvStore.get('ADV_23').tier;
else if (DisAdvStore.get('DISADV_26') && DisAdvStore.get('DISADV_26').active)
-DisAdvStore.get('DISADV_26').tier;
else
0;
}}
purchased={baseValues.aeAdd}
subLabel="perm. eingesetzt/davon zurückgekauft"
subArray={[0,0]}
empty={attrPrimary[0] === 'ATTR_0'} />
<MainSheetCalcItem
label="Karmaenergie"
calc="(20 durch Geweihter + Leiteigenschaft)"
value={attrPrimary[1] === 'ATTR_0' || !AttributeStore.get(attrPrimary[1]) ? 0 : 20 + AttributeStore.get(attrPrimary[1]).value}
add={do {
if (DisAdvStore.get('ADV_24') && DisAdvStore.get('ADV_24').active)
DisAdvStore.get('ADV_24').tier;
else if (DisAdvStore.get('DISADV_27') && DisAdvStore.get('DISADV_27').active)
-DisAdvStore.get('DISADV_27').tier;
else
0;
}}
purchased={baseValues.keAdd}
subLabel="perm. eingesetzt/davon zurückgekauft"
subArray={[0,0]}
empty={attrPrimary[1] === 'ATTR_0'} />
<MainSheetCalcItem
label="Seelenkraft"
calc="(GW der Spezies + (MU + KL + IN)/6)"
value={baseValues.sk + Math.round((attributes[0].value + attributes[1].value + attributes[2].value) / 6)}
add={do {
if (DisAdvStore.get('ADV_26') && DisAdvStore.get('ADV_26').active)
1;
else if (DisAdvStore.get('DISADV_29') && DisAdvStore.get('DISADV_29').active)
-1;
else
0;
}}
purchased={null}
subLabel="Grundwert"
subArray={[baseValues.sk]} />
<MainSheetCalcItem
label="Zähigkeit"
calc="(GW der Spezies + (KO + KO + KK)/6)"
value={baseValues.zk + Math.round((attributes[6].value * 2 + attributes[7].value) / 6)}
add={do {
if (DisAdvStore.get('ADV_27') && DisAdvStore.get('ADV_27').active)
1;
else if (DisAdvStore.get('DISADV_30') && DisAdvStore.get('DISADV_30').active)
-1;
else
0;
}}
purchased={null}
subLabel="Grundwert"
subArray={[baseValues.zk]} />
<MainSheetCalcItem
label="Ausweichen"
calc="(GE/2)"
value={Math.round(attributes[5].value / 2)}
add={0}
purchased={null} />
<MainSheetCalcItem
label="Initiative"
calc="(MU + GE)/2"
value={Math.round((attributes[0].value + attributes[5].value) / 2)}
add={0}
purchased={null} />
<MainSheetCalcItem
label="Geschwindigkeit"
calc="(GW der Spezies, mögl. Einbeinig)"
value={baseValues.gs}
add={0}
purchased={null}
subLabel="Grundwert"
subArray={[baseValues.gs]} />
<div className="fate">
<h3>Schicksalspunkte</h3>
</div>
</div>
) : null
}
<MainSheetCalc
attributes={attributes}
attrPrimary={attrPrimary}
baseValues={baseValues}
/>
</div>
</div>
);
@@ -0,0 +1,130 @@
import ListStore from '../../../stores/ListStore';
import MainSheetCalcItem from './MainSheetCalcItem';
import React, { Component, PropTypes } from 'react';
class MainSheetCalc extends Component {
static propTypes = {
attributes: PropTypes.array.isRequired,
attrPrimary: PropTypes.array.isRequired,
baseValues: PropTypes.object.isRequired
};
render() {
const { attributes, attrPrimary, baseValues } = this.props;
return attributes.length > 0 ? (
<div className="calculated">
<div className="calc-header">
<div>Wert</div>
<div>Bonus/<br/>Malus</div>
<div>Zukauf</div>
<div>Max</div>
</div>
<MainSheetCalcItem
label="Lebensenergie"
calc="(GW der Spezies + KO + KO)"
value={baseValues.le + attributes[6].value * 2}
add={do {
if (ListStore.get('ADV_25') && ListStore.get('ADV_25').active)
ListStore.get('ADV_25').tier;
else if (ListStore.get('DISADV_28') && ListStore.get('DISADV_28').active)
-ListStore.get('DISADV_28').tier;
else
0;
}}
purchased={baseValues.leAdd}
subLabel="Grundwert"
subArray={[baseValues.le]} />
<MainSheetCalcItem
label="Astralenergie"
calc="(20 durch Zauberer + Leiteigenschaft)"
value={attrPrimary[0] === 'ATTR_0' || !ListStore.get(attrPrimary[0]) ? 0 : 20 + ListStore.get(attrPrimary[0]).value}
add={do {
if (ListStore.get('ADV_23') && ListStore.get('ADV_23').active)
ListStore.get('ADV_23').tier;
else if (ListStore.get('DISADV_26') && ListStore.get('DISADV_26').active)
-ListStore.get('DISADV_26').tier;
else
0;
}}
purchased={baseValues.aeAdd}
subLabel="perm. eingesetzt/davon zurückgekauft"
subArray={[0,0]}
empty={attrPrimary[0] === 'ATTR_0'} />
<MainSheetCalcItem
label="Karmaenergie"
calc="(20 durch Geweihter + Leiteigenschaft)"
value={attrPrimary[1] === 'ATTR_0' || !ListStore.get(attrPrimary[1]) ? 0 : 20 + ListStore.get(attrPrimary[1]).value}
add={do {
if (ListStore.get('ADV_24') && ListStore.get('ADV_24').active)
ListStore.get('ADV_24').tier;
else if (ListStore.get('DISADV_27') && ListStore.get('DISADV_27').active)
-ListStore.get('DISADV_27').tier;
else
0;
}}
purchased={baseValues.keAdd}
subLabel="perm. eingesetzt/davon zurückgekauft"
subArray={[0,0]}
empty={attrPrimary[1] === 'ATTR_0'} />
<MainSheetCalcItem
label="Seelenkraft"
calc="(GW der Spezies + (MU + KL + IN)/6)"
value={baseValues.sk + Math.round((attributes[0].value + attributes[1].value + attributes[2].value) / 6)}
add={do {
if (ListStore.get('ADV_26') && ListStore.get('ADV_26').active)
1;
else if (ListStore.get('DISADV_29') && ListStore.get('DISADV_29').active)
-1;
else
0;
}}
purchased={null}
subLabel="Grundwert"
subArray={[baseValues.sk]} />
<MainSheetCalcItem
label="Zähigkeit"
calc="(GW der Spezies + (KO + KO + KK)/6)"
value={baseValues.zk + Math.round((attributes[6].value * 2 + attributes[7].value) / 6)}
add={do {
if (ListStore.get('ADV_27') && ListStore.get('ADV_27').active)
1;
else if (ListStore.get('DISADV_30') && ListStore.get('DISADV_30').active)
-1;
else
0;
}}
purchased={null}
subLabel="Grundwert"
subArray={[baseValues.zk]} />
<MainSheetCalcItem
label="Ausweichen"
calc="(GE/2)"
value={Math.round(attributes[5].value / 2)}
add={0}
purchased={null} />
<MainSheetCalcItem
label="Initiative"
calc="(MU + GE)/2"
value={Math.round((attributes[0].value + attributes[5].value) / 2)}
add={0}
purchased={null} />
<MainSheetCalcItem
label="Geschwindigkeit"
calc="(GW der Spezies, mögl. Einbeinig)"
value={baseValues.gs}
add={0}
purchased={null}
subLabel="Grundwert"
subArray={[baseValues.gs]} />
<div className="fate">
<h3>Schicksalspunkte</h3>
</div>
</div>
) : null;
}
}
export default MainSheetCalc;
@@ -0,0 +1,56 @@
import Avatar from '../../layout/Avatar';
import LabelBox from '../../layout/sheets/LabelBox';
import Plain from '../../layout/sheets/Plain';
import React, { Component, PropTypes } from 'react';
class MainSheetPersonalData extends Component {
static propTypes = {
ap: PropTypes.object.isRequired,
culture: PropTypes.string.isRequired,
el: PropTypes.string.isRequired,
eyecolorTags: PropTypes.array.isRequired,
haircolorTags: PropTypes.array.isRequired,
profession: PropTypes.string.isRequired,
profile: PropTypes.object.isRequired,
race: PropTypes.string.isRequired,
socialstatusTags: PropTypes.array.isRequired
};
render() {
const { ap, culture, el, eyecolorTags, haircolorTags, profession, profile: { name, family, placeofbirth, dateofbirth, age, sex, size, weight, haircolor, eyecolor, title, socialstatus, characteristics, otherinfo, avatar }, race, socialstatusTags } = this.props;
return (
<div className="upper">
<div className="info">
<Plain className="name" label="Name" value={name} />
<Plain className="family" label="Familie" value={family} />
<Plain className="placeofbirth" label="Geburtsort" value={placeofbirth} />
<Plain className="dateofbirth" label="Geburtsdatum" value={dateofbirth} />
<Plain className="age" label="Alter" value={age} />
<Plain className="sex" label="Geschlecht" value={sex} />
<Plain className="race" label="Spezies" value={race} />
<Plain className="size" label="Größe" value={size} />
<Plain className="weight" label="Gewicht" value={weight} />
<Plain className="haircolor" label="Haarfarbe" value={haircolorTags[haircolor - 1]} />
<Plain className="eyecolor" label="Augenfarbe" value={eyecolorTags[eyecolor - 1]} />
<Plain className="culture" label="Kultur" value={culture} />
<Plain className="profession" label="Profession" value={profession} />
<Plain className="title" label="Titel" value={title} />
<Plain className="socialstatus" label="Sozialstatus" value={socialstatusTags[socialstatus - 1]} />
<Plain className="characteristics" label="Charakteristika" value={characteristics} />
<Plain className="otherinfo" label="Sonstiges" value={otherinfo} />
</div>
<div className="ap-portrait">
<LabelBox className="el" label="Erfahrungsgrad" value={el} />
<LabelBox className="ap-total" label="AP gesamt" value={ap.total} />
<LabelBox className="portrait" label="Porträt/Wappen"><Avatar src={avatar} img /></LabelBox>
<LabelBox className="ap-available" label="AP verfügbar" value={ap.total - ap.spent} />
<LabelBox className="ap-used" label="AP ausgegeben" value={ap.spent} />
</div>
</div>
);
}
}
export default MainSheetPersonalData;
+150 -124
View File
@@ -6,7 +6,7 @@ import DisAdvStore from '../../../stores/DisAdvStore';
import Dropdown from '../../layout/Dropdown';
import ELStore from '../../../stores/ELStore';
import IconButton from '../../layout/IconButton';
import OverviewDisAdv from './OverviewDisAdv';
import OverviewConstSkills from './OverviewConstSkills';
import OverviewNameChange from './OverviewNameChange';
import ProfessionStore from '../../../stores/rcp/ProfessionStore';
import ProfessionVariantStore from '../../../stores/rcp/ProfessionVariantStore';
@@ -23,47 +23,15 @@ class Overview extends Component {
state = {
advActive: DisAdvStore.getActiveForView(true),
disadvActive: DisAdvStore.getActiveForView(false),
name: ProfileStore.getName(),
gender: ProfileStore.getGender(),
portrait: ProfileStore.getPortrait(),
hair: ProfileStore.getHair(),
eyes: ProfileStore.getEyes(),
size: ProfileStore.getSize(),
weight: ProfileStore.getWeight(),
...(ProfileStore.getAll()),
phase: PhaseStore.get(),
showImageUpload: false,
editName: false
};
_updateProfileStore = () => this.setState({
name: ProfileStore.getName(),
gender: ProfileStore.getGender(),
portrait: ProfileStore.getPortrait(),
hair: ProfileStore.getHair(),
eyes: ProfileStore.getEyes(),
size: ProfileStore.getSize(),
weight: ProfileStore.getWeight()
});
_updateProfileStore = () => this.setState(ProfileStore.getAll());
_updatePhaseStore = () => this.setState({
phase: PhaseStore.get()
});
showImageUpload = () => ProfileActions.showImageUpload();
changeName = name => {
ProfileActions.changeName(name);
this.setState({ editName: false });
};
editName = () => this.setState({ editName: true });
editNameCancel = () => this.setState({ editName: false });
changeHair = option => ProfileActions.changeHair(option);
changeEyes = option => ProfileActions.changeEyes(option);
changeSize = event => ProfileActions.changeSize(event.target.value);
changeWeight = event => ProfileActions.changeWeight(event.target.value);
rerollHair = () => ProfileActions.rerollHair();
rerollEyes = () => ProfileActions.rerollEyes();
rerollSize = () => ProfileActions.rerollSize();
rerollWeight = () => ProfileActions.rerollWeight();
endCharacterCreation = () => ProfileActions.endCharacterCreation();
componentDidMount() {
PhaseStore.addChangeListener(this._updatePhaseStore );
@@ -75,70 +43,62 @@ class Overview extends Component {
ProfileStore.removeChangeListener(this._updateProfileStore );
}
showImageUpload = () => ProfileActions.showImageUpload();
changeName = name => {
ProfileActions.changeName(name);
this.setState({ editName: false });
};
editName = () => this.setState({ editName: true });
editNameCancel = () => this.setState({ editName: false });
changeFamily = e => ProfileActions.changeFamily(e.target.value);
changePlaceOfBirth = e => ProfileActions.changePlaceOfBirth(e.target.value);
changeDateOfBirth = e => ProfileActions.changeDateOfBirth(e.target.value);
changeAge = e => ProfileActions.changeAge(e.target.value);
changeHaircolor = result => ProfileActions.changeHaircolor(result);
changeEyecolor = result => ProfileActions.changeEyecolor(result);
changeSize = e => ProfileActions.changeSize(e.target.value);
changeWeight = e => ProfileActions.changeWeight(e.target.value);
changeTitle = e => ProfileActions.changeTitle(e.target.value);
changeSocialStatus = result => ProfileActions.changeSocialStatus(result);
changeCharacteristics = e => ProfileActions.changeCharacteristics(e.target.value);
changeOtherInfo = e => ProfileActions.changeOtherInfo(e.target.value);
rerollHair = () => ProfileActions.rerollHair();
rerollEyes = () => ProfileActions.rerollEyes();
rerollSize = () => ProfileActions.rerollSize();
rerollWeight = () => ProfileActions.rerollWeight();
endCharacterCreation = () => ProfileActions.endCharacterCreation();
render() {
const { editName, name, portrait, hair, eyes, size, weight, phase } = this.state;
const { age, avatar, characteristics, editName, eyecolor, dateofbirth, family, haircolor, name, otherinfo, placeofbirth, size, socialstatus, title, weight, phase } = this.state;
const hairArr = RaceStore.getCurrent() ? [
['blauschwarz',1],
['blond',2],
['braun',3],
['dunkelblond',4],
['dunkelbraun',5],
['goldblond',6],
['grau',7],
['hellblond',8],
['hellbraun',9],
['kupferrot',10],
['mittelblond', 11],
['mittelbraun', 12],
['rot', 13],
['rotblond', 14],
['schneeweiß', 15],
['schwarz', 16],
['silbern', 17],
['weißblond', 18],
['dunkelgrau', 19],
['hellgrau', 20],
['salzweiß', 21],
['silberweiß', 22],
['feuerrot', 23]
].filter(e =>
const hairArr = RaceStore.getCurrent() ? ProfileStore.getHaircolorTags().map((e,i) => [ e, i + 1 ]).filter(e =>
RaceStore.getCurrent().hair.indexOf(e[1]) > -1
) : [];
const eyesArr = RaceStore.getCurrent() ? [
['amethystviolett',1],
['bernsteinfarben',2],
['blau',3],
['braun',4],
['dunkelbraun',5],
['dunkelviolett',6],
['eisgrau',7],
['goldgesprenkelt',8],
['grau',9],
['graublau',10],
['grün', 11],
['hellbraun', 12],
['rubinrot', 13],
['saphirblau', 14],
['schwarz', 15],
['schwarzbraun', 16],
['silbergrau', 17],
['smaragdgrün', 18]
].filter(e =>
const eyesArr = RaceStore.getCurrent() ? ProfileStore.getEyecolorTags().map((e,i) => [ e, i + 1 ]).filter(e =>
RaceStore.getCurrent().eyes.indexOf(e[1]) > -1
) : [];
const gender = this.state.gender === 'm' ? 'Männlich' : 'Weiblich';
const socialstatusArr = CultureStore.getCurrent() ? ProfileStore.getSocialstatusTags().map((e,i) => [ e, i + 1 ]).filter(e =>
CultureStore.getCurrent().social.indexOf(e[1]) > -1
) : [];
const sex = this.state.sex === 'm' ? 'Männlich' : 'Weiblich';
const elAp = [ 900, 1000, 1100, 1200, 1400, 1700, 2100 ], ap = APStore.get();
var currentEL = 'EL_7';
var currentEL = 6;
for (let i = 0; i < elAp.length; i++) {
if (elAp[i] >= ap) {
currentEL = `EL_${i > 0 ? i : 1}`;
if (elAp[i] === ap) {
currentEL = i;
break;
} else if (elAp[i] > ap) {
currentEL = i - 1;
break;
}
}
@@ -159,11 +119,11 @@ class Overview extends Component {
<div className="page" id="overview">
<Scroll>
<div className="title-wrapper">
<Avatar src={portrait} onClick={this.showImageUpload} wrapper />
<Avatar src={avatar} onClick={this.showImageUpload} wrapper />
<div className="text-wrapper">
{nameElement}
<div className="rcp">
{ gender } &middot; {
{ sex } &middot; {
RaceStore.getCurrent() !== undefined ? RaceStore.getCurrent().name : null
} &middot; {
CultureStore.getCurrent() !== undefined ? CultureStore.getCurrent().name : null
@@ -172,55 +132,121 @@ class Overview extends Component {
}
</div>
<div className="el">
{ELStore.get(currentEL).name} &middot; {ap} AP
{ELStore.get(`EL_${currentEL + 1}`).name} &middot; {ap} AP
</div>
</div>
</div>
<h3>Aussehen</h3>
<h4>Haarfarbe</h4>
<Dropdown
value={hair}
onChange={this.changeHair}
options={hairArr}
/>
<IconButton icon="&#xE863;" onClick={this.rerollHair} />
<h4>Augenfarbe</h4>
<Dropdown
value={eyes}
onChange={this.changeEyes}
options={eyesArr}
/>
<IconButton icon="&#xE863;" onClick={this.rerollEyes} />
<h4>Körpergröße</h4>
<TextField
value={size}
onChange={this.changeSize}
/>
<IconButton icon="&#xE863;" onClick={this.rerollSize} />
<h4>Gewicht</h4>
<TextField
value={weight}
onChange={this.changeWeight}
/>
<IconButton icon="&#xE863;" onClick={this.rerollWeight} />
<h3>Persönliche Daten</h3>
<div className="personal-data">
<div>
<TextField
labelText="Familie"
value={family}
onChange={this.changeFamily}
/>
</div>
<div>
<TextField
labelText="Geburtsort"
value={placeofbirth}
onChange={this.changePlaceOfBirth}
/>
</div>
<div>
<TextField
labelText="Geburtsdatum"
value={dateofbirth}
onChange={this.changeDateOfBirth}
/>
</div>
<div>
<TextField
labelText="Alter"
value={age}
onChange={this.changeAge}
/>
</div>
<div className="reroll">
<Dropdown
label="Haarfarbe"
value={haircolor}
onChange={this.changeHaircolor}
options={hairArr}
/>
<IconButton icon="&#xE863;" onClick={this.rerollHair} />
</div>
<div className="reroll">
<Dropdown
label="Augenfarbe"
value={eyecolor}
onChange={this.changeEyecolor}
options={eyesArr}
/>
<IconButton icon="&#xE863;" onClick={this.rerollEyes} />
</div>
<div className="reroll">
<TextField
labelText="Körpergröße"
value={size}
onChange={this.changeSize}
/>
<IconButton icon="&#xE863;" onClick={this.rerollSize} />
</div>
<div className="reroll">
<TextField
labelText="Gewicht"
value={weight}
onChange={this.changeWeight}
/>
<IconButton icon="&#xE863;" onClick={this.rerollWeight} />
</div>
<div>
<TextField
labelText="Titel"
value={title}
onChange={this.changeTitle}
/>
</div>
<div>
<Dropdown
label="Sozialstatus"
value={socialstatus}
onChange={this.changeSocialStatus}
options={socialstatusArr}
/>
</div>
<div>
<TextField
labelText="Charakteristika"
value={characteristics}
onChange={this.changeCharacteristics}
/>
</div>
<div>
<TextField
labelText="Sonstiges"
value={otherinfo}
onChange={this.changeOtherInfo}
/>
</div>
</div>
{
phase === 2 ? (
<div>
<BorderButton
label="Heldenerstellung beenden"
onClick={this.endCharacterCreation}
primary
/>
</div>
<BorderButton
className="end-char-creation"
label="Heldenerstellung beenden"
onClick={this.endCharacterCreation}
primary
/>
) : null
}
{
phase === 3 ? (
<div>
<h3>Vorteile</h3>
<OverviewDisAdv list={this.state.advActive} />
<OverviewConstSkills list={this.state.advActive} />
<h3>Nachteile</h3>
<OverviewDisAdv list={this.state.disadvActive} />
<OverviewConstSkills list={this.state.disadvActive} />
</div>
) : null
}
@@ -0,0 +1,49 @@
import React, { Component, PropTypes } from 'react';
class OverviewConstSkills extends Component {
static propTypes = {
list: PropTypes.array
};
constructor(props) {
super(props);
}
render() {
var roman = ['I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX', 'X'];
var langLitc = new Set(['SA_28','SA_30']);
return (
<div className="list">
{
this.props.list.map(obj => {
let { id, name, add, tiers, tier } = obj;
if (langLitc.has(id)) {
return;
}
if (['ADV_28','ADV_29'].indexOf(id) > -1) name = `Immunität gegen ${add}`;
else if (id === 'DISADV_1') name = `Angst vor ${add}`;
else if (['DISADV_34','DISADV_50'].indexOf(id) > -1) name += ` ${roman[tier - 1]} (${add})`;
else if (add) name += ` (${add})`;
if (tiers !== undefined && tiers !== null && ['DISADV_34','DISADV_50'].indexOf(id) === -1) {
if (id === 'SA_30' && tier === 4) {
name += ` MS`;
} else {
name += ` ${roman[tier - 1]}`;
}
}
return name;
}).filter(e => e).join(', ')
}
</div>
);
}
}
export default OverviewConstSkills;
@@ -1,42 +0,0 @@
import React, { Component, PropTypes } from 'react';
class OverviewDisAdv extends Component {
static propTypes = {
list: PropTypes.array
};
constructor(props) {
super(props);
}
render() {
var roman = ['I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX', 'X'];
return (
<div className="list">
{
this.props.list.map(disadv => {
var name = disadv.name;
if (['ADV_28','ADV_29'].indexOf(disadv.id) > -1) name = `Immunität gegen ${disadv.add}`;
else if (disadv.id === 'DISADV_1') name = `Angst vor ${disadv.add}`;
else if (['DISADV_34','DISADV_50'].indexOf(disadv.id) > -1) name += ` ${roman[disadv.tier - 1]} (${disadv.add})`;
else if (disadv.hasOwnProperty('add')) name += ` (${disadv.add})`;
if (disadv.tiers !== undefined && disadv.tiers !== null && ['DISADV_34','DISADV_50'].indexOf(disadv.id) === -1) {
name += ` ${roman[disadv.tier - 1]}`;
}
return name;
}).join(', ')
}
</div>
);
}
}
export default OverviewDisAdv;
+3 -3
View File
@@ -19,9 +19,6 @@ class Sheets extends Component {
render() {
return (
<div className="page" id="sheets">
<div className="options">
<BorderButton className="print-cs" label="Dokument drucken" onClick={this.print} />
</div>
<Scroll className="sheet-wrapper">
<MainSheet />
<TalentsSheet />
@@ -34,5 +31,8 @@ class Sheets extends Component {
);
}
}
// <div className="options">
// <BorderButton className="print-cs" label="Dokument drucken" onClick={this.print} />
// </div>
export default Sheets;
+1 -1
View File
@@ -7,7 +7,7 @@ import DisAdvStore from '../../../stores/DisAdvStore';
import ELStore from '../../../stores/ELStore';
import LabelBox from '../../layout/sheets/LabelBox';
import MainSheetCalcItem from './MainSheetCalcItem';
import OverviewDisAdv from './OverviewDisAdv';
import OverviewConstSkills from './OverviewConstSkills';
import Plain from '../../layout/sheets/Plain';
import ProfessionStore from '../../../stores/rcp/ProfessionStore';
import ProfessionVariantStore from '../../../stores/rcp/ProfessionVariantStore';
@@ -7,7 +7,7 @@ import DisAdvStore from '../../../stores/DisAdvStore';
import ELStore from '../../../stores/ELStore';
import LabelBox from '../../layout/sheets/LabelBox';
import MainSheetCalcItem from './MainSheetCalcItem';
import OverviewDisAdv from './OverviewDisAdv';
import OverviewConstSkills from './OverviewConstSkills';
import Plain from '../../layout/sheets/Plain';
import ProfessionStore from '../../../stores/rcp/ProfessionStore';
import ProfessionVariantStore from '../../../stores/rcp/ProfessionVariantStore';
+10 -2
View File
@@ -9,6 +9,7 @@ class Avatar extends Component {
static propTypes = {
className: PropTypes.any,
img: PropTypes.bool,
src: PropTypes.string,
onClick: PropTypes.func,
wrapper: PropTypes.bool
@@ -17,9 +18,16 @@ class Avatar extends Component {
render() {
const className = classNames('avatar', this.props.className);
const { src, onClick, wrapper } = this.props;
const { src, img, onClick, wrapper } = this.props;
if (wrapper) {
if (img) {
return (
<div className={classNames('avatar-wrapper', !src && 'no-avatar')} onClick={onClick} className={className}>
<img src={src} alt="" />
</div>
);
}
else if (wrapper) {
return (
<div className={classNames('avatar-wrapper', !src && 'no-avatar')} onClick={onClick}>
{this.props.children}
@@ -0,0 +1,13 @@
import React, { Component } from 'react';
class TextFieldButtonGroup extends Component {
render() {
return (
<div className="textfield-btn-group">
{this.props.children}
</div>
);
}
}
export default TextFieldButtonGroup;
+2 -2
View File
@@ -28,7 +28,7 @@ class TitleBar extends Component {
used: APStore.getUsed(),
disadv: APStore.getForDisAdv(),
phase: PhaseStore.get(),
portrait: ProfileStore.getPortrait()
portrait: ProfileStore.getAvatar()
};
constructor(props) {
@@ -38,7 +38,7 @@ class TitleBar extends Component {
_updateAccountStore = () => this.setState({ account: AccountStore.getAll() });
_updateAPStore = () => this.setState({ ap: APStore.get(), used: APStore.getUsed(), disadv: APStore.getForDisAdv() });
_updatePhaseStore = () => this.setState({ phase: PhaseStore.get() });
_updateProfileStore = () => this.setState({ portrait: ProfileStore.getPortrait() });
_updateProfileStore = () => this.setState({ portrait: ProfileStore.getAvatar() });
componentDidMount() {
AccountStore.addChangeListener(this._updateAccountStore);
+8
View File
@@ -37,10 +37,18 @@ export default keyMirror({
// ProfileStore
UPDATE_HERO_NAME: null,
UPDATE_HERO_AVATAR: null,
UPDATE_FAMILY: null,
UPDATE_PLACEOFBIRTH: null,
UPDATE_DATEOFBIRTH: null,
UPDATE_AGE: null,
UPDATE_HAIRCOLOR: null,
UPDATE_EYECOLOR: null,
UPDATE_SIZE: null,
UPDATE_WEIGHT: null,
UPDATE_TITLE: null,
UPDATE_SOCIALSTATUS: null,
UPDATE_CHARACTERISTICS: null,
UPDATE_OTHERINFO: null,
REROLL_HAIRCOLOR: null,
REROLL_EYECOLOR: null,
REROLL_SIZE: null,
+4 -9
View File
@@ -12,15 +12,6 @@ import reqPurchase from '../utils/reqPurchase';
// AP = Adventure Points
const AKTV = [1, 2, 3, 4];
const SKT = [
[1,2,3,4,5,6,7,8,9,10,11,12,13,14],
[2,4,6,8,10,12,14,16,18,20,22,24,26,28],
[3,6,9,12,15,18,21,24,27,30,33,36,39,42],
[4,8,12,16,20,24,28,32,36,40,44,48,52,56],
[15,15,15,30,45,60,75,90,105,120,135,150,165,180]
];
var _max = 0;
var _used = 0;
var _rcp = [0, 0, 0, 0];
@@ -148,6 +139,10 @@ var APStore = Object.assign({}, EventEmitter.prototype, {
return { _max, _used, _rcp, _adv, _adv_mag, _adv_kar, _disadv, _disadv_mag, _disadv_kar };
},
getAll: function() {
return { total: _max, spent: _used };
},
get: function() {
return _max;
},
+9
View File
@@ -239,6 +239,15 @@ var ListStore = Object.assign({}, EventEmitter.prototype, {
if (_list[id].category === category && _list[id].gr === gr) list.push(_list[id]);
}
return list;
},
getObjByCategoryGroup: function(category, ...gr) {
var list = {};
var grs = new Set(gr);
for (let id in _list) {
if (_list[id].category === category && grs.has(_list[id].gr)) list[id] = _list[id];
}
return list;
}
});
+159 -35
View File
@@ -4,14 +4,26 @@ import ActionTypes from '../constants/ActionTypes';
import RaceStore from './rcp/RaceStore';
import dice from '../utils/dice';
const HAIRCOLORS = [ 'blauschwarz', 'blond', 'braun', 'dunkelblond', 'dunkelbraun', 'goldblond', 'grau', 'hellblond', 'hellbraun', 'kupferrot', 'mittelblond', 'mittelbraun', 'rot', 'rotblond', 'schneeweiß', 'schwarz', 'silbern', 'weißblond', 'dunkelgrau', 'hellgrau', 'salzweiß', 'silberweiß', 'feuerrot' ];
const EYECOLORS = [ 'amethystviolett', 'bernsteinfarben', 'blau', 'braun', 'dunkelbraun', 'dunkelviolett', 'eisgrau', 'goldgesprenkelt', 'grau', 'graublau', 'grün', 'hellbraun', 'rubinrot', 'saphirblau', 'schwarz', 'schwarzbraun', 'silbergrau', 'smaragdgrün' ];
const SOCIALSTATUS = [ 'Unfrei', 'Frei', 'Niederadel', 'Adel', 'Hochadel' ];
var _id = null;
var _name = '';
var _gender = '';
var _portrait = '';
var _hair = '';
var _eyes = '';
var _sex = '';
var _avatar = '';
var _family = '';
var _placeofbirth = '';
var _dateofbirth = '';
var _age = '';
var _haircolor = 0;
var _eyecolor = 0;
var _size = '';
var _weight = '';
var _title = '';
var _socialstatus = 0;
var _characteristics = '';
var _otherinfo = '';
function _updateID(id) {
_id = id;
@@ -21,20 +33,36 @@ function _updateName(text) {
_name = text;
}
function _updateGender(id) {
_gender = id;
function _updateSex(id) {
_sex = id;
}
function _updatePortrait(url) {
_portrait = url;
function _updateAvatar(url) {
_avatar = url;
}
function _updateHair(id) {
_hair = id;
function _updateFamily(text) {
_family = text;
}
function _updateEyes(id) {
_eyes = id;
function _updatePlaceOfBirth(text) {
_placeofbirth = text;
}
function _updateDateOfBirth(text) {
_dateofbirth = text;
}
function _updateAge(text) {
_age = text;
}
function _updateHaircolor(id) {
_haircolor = id;
}
function _updateEyecolor(id) {
_eyecolor = id;
}
function _updateSize(text) {
@@ -45,14 +73,30 @@ function _updateWeight(text) {
_weight = text;
}
function _updateTitle(text) {
_title = text;
}
function _updateSocialStatus(id) {
_socialstatus = id;
}
function _updateCharacteristics(text) {
_characteristics = text;
}
function _updateOtherInfo(text) {
_otherinfo = text;
}
function _rerollHair() {
var result = dice(20);
_hair = RaceStore.getCurrent().hair[result - 1];
_haircolor = RaceStore.getCurrent().hair[result - 1];
}
function _rerollEyes() {
var result = dice(20);
_eyes = RaceStore.getCurrent().eyes[result - 1];
_eyecolor = RaceStore.getCurrent().eyes[result - 1];
}
function _rerollSize() {
@@ -89,12 +133,20 @@ function _rerollWeight() {
function _clear() {
_id = null;
_name = '';
_gender = '';
_portrait = '';
_hair = '';
_eyes = '';
_sex = '';
_avatar = '';
_family = '';
_placeofbirth = '';
_dateofbirth = '';
_age = '';
_haircolor = 0;
_eyecolor = 0;
_size = '';
_weight = '';
_title = '';
_socialstatus = 0;
_characteristics = '';
_otherinfo = '';
}
var ProfileStore = Object.assign({}, EventEmitter.prototype, {
@@ -111,6 +163,26 @@ var ProfileStore = Object.assign({}, EventEmitter.prototype, {
this.removeListener('change', callback);
},
getAll: function() {
return {
name: _name,
sex: _sex,
avatar: _avatar,
family: _family,
placeofbirth: _placeofbirth,
dateofbirth: _dateofbirth,
age: _age,
haircolor: _haircolor,
eyecolor: _eyecolor,
size: _size,
weight: _weight,
title: _title,
socialstatus: _socialstatus,
characteristics: _characteristics,
otherinfo: _otherinfo
};
},
getID: function() {
return _id;
},
@@ -119,26 +191,34 @@ var ProfileStore = Object.assign({}, EventEmitter.prototype, {
return _name;
},
getGender: function() {
return _gender;
getSex: function() {
return _sex;
},
getPortrait: function() {
return _portrait;
getAvatar: function() {
return _avatar;
},
getAppearance: function() {
return {
_hair, _eyes, _size, _weight
_haircolor, _eyecolor, _size, _weight
};
},
getHair: function() {
return _hair;
getHaircolor: function() {
return _haircolor;
},
getEyes: function() {
return _eyes;
getHaircolorTags: function() {
return HAIRCOLORS;
},
getEyecolor: function() {
return _eyecolor;
},
getEyecolorTags: function() {
return EYECOLORS;
},
getSize: function() {
@@ -147,6 +227,10 @@ var ProfileStore = Object.assign({}, EventEmitter.prototype, {
getWeight: function() {
return _weight;
},
getSocialstatusTags: function() {
return SOCIALSTATUS;
}
});
@@ -158,7 +242,7 @@ ProfileStore.dispatchToken = AppDispatcher.register( function( payload ) {
case ActionTypes.CREATE_NEW_HERO:
_clear();
_updateName(payload.name);
_updateGender(payload.gender);
_updateSex(payload.gender);
break;
case ActionTypes.CLEAR_HERO:
@@ -168,12 +252,20 @@ ProfileStore.dispatchToken = AppDispatcher.register( function( payload ) {
case ActionTypes.RECEIVE_HERO:
_updateID(payload.id);
_updateName(payload.name);
_updateGender(payload.sex);
_updatePortrait(payload.avatar);
_updateHair(payload.pers._hair);
_updateEyes(payload.pers._eyes);
_updateSex(payload.sex);
_updateAvatar(payload.avatar);
_updateFamily(payload.pers._family);
_updatePlaceOfBirth(payload.pers._placeofbirth);
_updateDateOfBirth(payload.pers._dateofbirth);
_updateAge(payload.pers._age);
_updateHaircolor(payload.pers._haircolor);
_updateEyecolor(payload.pers._eyecolor);
_updateSize(payload.pers._size);
_updateWeight(payload.pers._weight);
_updateTitle(payload.pers._title);
_updateSocialStatus(payload.pers._socialstatus);
_updateCharacteristics(payload.pers._characteristics);
_updateOtherInfo(payload.pers._otherinfo);
break;
case ActionTypes.UPDATE_HERO_NAME:
@@ -181,15 +273,31 @@ ProfileStore.dispatchToken = AppDispatcher.register( function( payload ) {
break;
case ActionTypes.UPDATE_HERO_AVATAR:
_updatePortrait(payload.url);
_updateAvatar(payload.url);
break;
case ActionTypes.UPDATE_FAMILY:
_updateFamily(payload.value);
break;
case ActionTypes.UPDATE_PLACEOFBIRTH:
_updatePlaceOfBirth(payload.value);
break;
case ActionTypes.UPDATE_DATEOFBIRTH:
_updateDateOfBirth(payload.value);
break;
case ActionTypes.UPDATE_AGE:
_updateAge(payload.value);
break;
case ActionTypes.UPDATE_HAIRCOLOR:
_updateHair(payload.option);
_updateHaircolor(payload.option);
break;
case ActionTypes.UPDATE_EYECOLOR:
_updateEyes(payload.option);
_updateEyecolor(payload.option);
break;
case ActionTypes.UPDATE_SIZE:
@@ -200,6 +308,22 @@ ProfileStore.dispatchToken = AppDispatcher.register( function( payload ) {
_updateWeight(payload.value);
break;
case ActionTypes.UPDATE_TITLE:
_updateTitle(payload.value);
break;
case ActionTypes.UPDATE_SOCIALSTATUS:
_updateSocialStatus(payload.option);
break;
case ActionTypes.UPDATE_CHARACTERISTICS:
_updateCharacteristics(payload.value);
break;
case ActionTypes.UPDATE_OTHERINFO:
_updateOtherInfo(payload.value);
break;
case ActionTypes.REROLL_HAIRCOLOR:
_rerollHair();
break;
+20 -3
View File
@@ -3,6 +3,7 @@ import CultureStore from './rcp/CultureStore';
import CombatTechniquesStore from './CombatTechniquesStore';
import { EventEmitter } from 'events';
import ListStore from './ListStore';
import PhaseStore from './PhaseStore';
import ProfessionStore from './rcp/ProfessionStore';
import ProfessionVariantStore from './rcp/ProfessionVariantStore';
import TalentsStore from './TalentsStore';
@@ -292,18 +293,30 @@ var SpecialAbilitiesStore = Object.assign({}, EventEmitter.prototype, {
return ListStore.get(id);
},
getActiveForView: function() {
var sasObj = ListStore.getObjByCategory(CATEGORY), sas = [];
getActiveForView: function(...cgr) {
var sasObj;
if (cgr.length > 0) {
sasObj = ListStore.getObjByCategoryGroup(CATEGORY, ...cgr);
} else {
sasObj = ListStore.getObjByCategory(CATEGORY);
}
var sas = [];
for (let id in sasObj) {
let sa = sasObj[id];
let { name, active, ap, sid, sel, gr, dependencies } = sa;
if (active === true) {
let disabled = dependencies.length > 0;
if (sel.length > 0 && ap === 'sel') {
if (id === 'SA_86' && ListStore.getAllByCategory('spells').some(e => e.active)) disabled = true;
if (id === 'SA_86' && ListStore.getAllByCategory('spells').some(e => e.active)) {
disabled = true;
}
if (id === 'SA_102' && ListStore.getAllByCategory('liturgies').some(e => e.active)) disabled = true;
sas.push({ id, name, add: sel[sid - 1][0], ap: sel[sid - 1][2], gr, disabled });
} else {
let phase = PhaseStore.get();
if (id === 'SA_92' && phase < 3) {
ap += 4;
}
sas.push({ id, name, ap, gr, disabled });
}
} else if (Array.isArray(active) && active.length > 0) {
@@ -427,6 +440,10 @@ var SpecialAbilitiesStore = Object.assign({}, EventEmitter.prototype, {
let _sel = sel.filter(e => dependencies.indexOf(e[1]) === -1);
sas.push({ id, name, sel: _sel, ap, gr });
} else {
let phase = PhaseStore.get();
if (id === 'SA_92' && phase < 3) {
ap += 4;
}
sas.push({ id, name, ap, gr });
}
break;
+20 -6
View File
@@ -253,10 +253,18 @@ var WebAPIUtils = {
ServerActions.loadHeroSuccess(id, `{
"sex":"m",
"pers":{
"_hair": 1,
"_eyes": 1,
"_family": "ibn Rashtul",
"_placeofbirth": "Rashdul",
"_dateofbirth": "10. Boron 1001 BF",
"_age": "6",
"_haircolor": 2,
"_eyecolor": 3,
"_size": 167,
"_weight": 71
"_weight": 71,
"_title": "al'Eshta",
"_socialstatus": 2,
"_characteristics": "Reibt sich die Hände",
"_otherinfo": "Hat einen Golem ..."
},
"attr":{
"values":[
@@ -279,7 +287,7 @@ var WebAPIUtils = {
},
"disadv":{
"active":[
["ADV_3",{}],["ADV_5",{}],["ADV_40",{}],["ADV_47",{"sid":"CT_2"}],["ADV_49",{}],["DISADV_1",[[2,2]]],["DISADV_15",{}],["DISADV_25",{}],["DISADV_40",{"tier":1}]
["ADV_3",{}],["ADV_5",{}],["ADV_40",{}],["ADV_47",{"sid":"CT_2"}],["ADV_49",{}],["ADV_50",{}],["DISADV_1",[[2,2]]],["DISADV_15",{}],["DISADV_25",{}],["DISADV_40",{"tier":1}]
],
"_showRating":true
},
@@ -287,10 +295,16 @@ var WebAPIUtils = {
"active":[["TAL_8",6],["TAL_10",4],["TAL_18",7],["TAL_20",5],["TAL_21",4],["TAL_25",4],["TAL_28",9],["TAL_29",7],["TAL_34",4],["TAL_38",5],["TAL_39",3],["TAL_40",2],["TAL_47",5],["TAL_48",8],["TAL_50",7],["TAL_51",1],["TAL_55",1],["TAL_59",1]],
"_talentRating":true},
"ct":{
"active":[["CT_3",8],["CT_5",8]]},"spells":{"active":[]},"chants":{"active":[]
"active":[["CT_3",8],["CT_5",8]]
},
"spells":{
"active":[]
},
"chants":{
"active":[]
},
"sa":{
"active":[["SA_10",[["TAL_48","Test"]]],["SA_28",[9,14]],["SA_30",[[8,4],[23,2],[6,1]]]]
"active":[["SA_10",[["TAL_48","Test"]]],["SA_28",[9,14]],["SA_30",[[8,4],[23,2],[6,1]]],["SA_86",{"sid":1}]]
},
"history": []
}`);
+11
View File
@@ -0,0 +1,11 @@
import { getAC, getIC } from '../ic.js';
it('returns 45 ap cost for SR 16 IC 5', () => {
const ap = getIC(16, 5);
expect(ap).toBe(45);
});
it('returns 4 ap cost for activating IC 4', () => {
const ap = getAC(4);
expect(ap).toBe(4);
});
+15
View File
@@ -0,0 +1,15 @@
// AC = Activation Cost
// IC = Improvement Cost
export function getAC(ic) {
return ic === 5 ? 15 : ic;
}
export function getIC(sr, ic) {
const f = ic === 5 ? 15 : ic;
if (sr < 12 || (ic === 5 && sr < 14)) {
return f;
} else {
return (sr - (ic === 5 ? 13 : 11)) * f;
}
}
+2 -2
View File
@@ -25,7 +25,7 @@ export default () => {
id: ProfileStore.getID(),
phase: PhaseStore.get(),
name: ProfileStore.getName(),
avatar: ProfileStore.getPortrait(),
avatar: ProfileStore.getAvatar(),
ap: APStore.getForSave(),
el: ELStore.getStartID(),
r: RaceStore.getCurrentID(),
@@ -34,7 +34,7 @@ export default () => {
pv: ProfessionVariantStore.getCurrentID()
},
{
sex: ProfileStore.getGender(),
sex: ProfileStore.getSex(),
pers: ProfileStore.getAppearance(),
attr: AttributeStore.getForSave(),
disadv: DisAdvStore.getForSave(),
Generated Vendored
+15
View File
@@ -0,0 +1,15 @@
#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
case `uname` in
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac
if [ -x "$basedir/node" ]; then
"$basedir/node" "$basedir/../cardinal/bin/cdl.js" "$@"
ret=$?
else
node "$basedir/../cardinal/bin/cdl.js" "$@"
ret=$?
fi
exit $ret
Generated Vendored
+7
View File
@@ -0,0 +1,7 @@
@IF EXIST "%~dp0\node.exe" (
"%~dp0\node.exe" "%~dp0\..\cardinal\bin\cdl.js" %*
) ELSE (
@SETLOCAL
@SET PATHEXT=%PATHEXT:;.JS;=;%
node "%~dp0\..\cardinal\bin\cdl.js" %*
)
Generated Vendored
+15
View File
@@ -0,0 +1,15 @@
#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
case `uname` in
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac
if [ -x "$basedir/node" ]; then
"$basedir/node" "$basedir/../errno/cli.js" "$@"
ret=$?
else
node "$basedir/../errno/cli.js" "$@"
ret=$?
fi
exit $ret
+7
View File
@@ -0,0 +1,7 @@
@IF EXIST "%~dp0\node.exe" (
"%~dp0\node.exe" "%~dp0\..\errno\cli.js" %*
) ELSE (
@SETLOCAL
@SET PATHEXT=%PATHEXT:;.JS;=;%
node "%~dp0\..\errno\cli.js" %*
)
+15
View File
@@ -0,0 +1,15 @@
#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
case `uname` in
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac
if [ -x "$basedir/node" ]; then
"$basedir/node" "$basedir/../escodegen/bin/escodegen.js" "$@"
ret=$?
else
node "$basedir/../escodegen/bin/escodegen.js" "$@"
ret=$?
fi
exit $ret
+7
View File
@@ -0,0 +1,7 @@
@IF EXIST "%~dp0\node.exe" (
"%~dp0\node.exe" "%~dp0\..\escodegen\bin\escodegen.js" %*
) ELSE (
@SETLOCAL
@SET PATHEXT=%PATHEXT:;.JS;=;%
node "%~dp0\..\escodegen\bin\escodegen.js" %*
)
+15
View File
@@ -0,0 +1,15 @@
#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
case `uname` in
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac
if [ -x "$basedir/node" ]; then
"$basedir/node" "$basedir/../escodegen/bin/esgenerate.js" "$@"
ret=$?
else
node "$basedir/../escodegen/bin/esgenerate.js" "$@"
ret=$?
fi
exit $ret
+7
View File
@@ -0,0 +1,7 @@
@IF EXIST "%~dp0\node.exe" (
"%~dp0\node.exe" "%~dp0\..\escodegen\bin\esgenerate.js" %*
) ELSE (
@SETLOCAL
@SET PATHEXT=%PATHEXT:;.JS;=;%
node "%~dp0\..\escodegen\bin\esgenerate.js" %*
)
+15
View File
@@ -0,0 +1,15 @@
#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
case `uname` in
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac
if [ -x "$basedir/node" ]; then
"$basedir/node" "$basedir/../handlebars/bin/handlebars" "$@"
ret=$?
else
node "$basedir/../handlebars/bin/handlebars" "$@"
ret=$?
fi
exit $ret
+7
View File
@@ -0,0 +1,7 @@
@IF EXIST "%~dp0\node.exe" (
"%~dp0\node.exe" "%~dp0\..\handlebars\bin\handlebars" %*
) ELSE (
@SETLOCAL
@SET PATHEXT=%PATHEXT:;.JS;=;%
node "%~dp0\..\handlebars\bin\handlebars" %*
)
+15
View File
@@ -0,0 +1,15 @@
#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
case `uname` in
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac
if [ -x "$basedir/node" ]; then
"$basedir/node" "$basedir/../har-validator/bin/har-validator" "$@"
ret=$?
else
node "$basedir/../har-validator/bin/har-validator" "$@"
ret=$?
fi
exit $ret
+7
View File
@@ -0,0 +1,7 @@
@IF EXIST "%~dp0\node.exe" (
"%~dp0\node.exe" "%~dp0\..\har-validator\bin\har-validator" %*
) ELSE (
@SETLOCAL
@SET PATHEXT=%PATHEXT:;.JS;=;%
node "%~dp0\..\har-validator\bin\har-validator" %*
)
Generated Vendored
+15
View File
@@ -0,0 +1,15 @@
#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
case `uname` in
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac
if [ -x "$basedir/node" ]; then
"$basedir/node" "$basedir/../istanbul/lib/cli.js" "$@"
ret=$?
else
node "$basedir/../istanbul/lib/cli.js" "$@"
ret=$?
fi
exit $ret
+7
View File
@@ -0,0 +1,7 @@
@IF EXIST "%~dp0\node.exe" (
"%~dp0\node.exe" "%~dp0\..\istanbul\lib\cli.js" %*
) ELSE (
@SETLOCAL
@SET PATHEXT=%PATHEXT:;.JS;=;%
node "%~dp0\..\istanbul\lib\cli.js" %*
)
Generated Vendored
+15
View File
@@ -0,0 +1,15 @@
#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
case `uname` in
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac
if [ -x "$basedir/node" ]; then
"$basedir/node" "$basedir/../jest-cli/bin/jest.js" "$@"
ret=$?
else
node "$basedir/../jest-cli/bin/jest.js" "$@"
ret=$?
fi
exit $ret
+15
View File
@@ -0,0 +1,15 @@
#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
case `uname` in
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac
if [ -x "$basedir/node" ]; then
"$basedir/node" "$basedir/../jest-runtime/bin/jest-runtime.js" "$@"
ret=$?
else
node "$basedir/../jest-runtime/bin/jest-runtime.js" "$@"
ret=$?
fi
exit $ret
+7
View File
@@ -0,0 +1,7 @@
@IF EXIST "%~dp0\node.exe" (
"%~dp0\node.exe" "%~dp0\..\jest-runtime\bin\jest-runtime.js" %*
) ELSE (
@SETLOCAL
@SET PATHEXT=%PATHEXT:;.JS;=;%
node "%~dp0\..\jest-runtime\bin\jest-runtime.js" %*
)
Generated Vendored
+7
View File
@@ -0,0 +1,7 @@
@IF EXIST "%~dp0\node.exe" (
"%~dp0\node.exe" "%~dp0\..\jest-cli\bin\jest.js" %*
) ELSE (
@SETLOCAL
@SET PATHEXT=%PATHEXT:;.JS;=;%
node "%~dp0\..\jest-cli\bin\jest.js" %*
)
Generated Vendored
+15
View File
@@ -0,0 +1,15 @@
#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
case `uname` in
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac
if [ -x "$basedir/node" ]; then
"$basedir/node" "$basedir/../marked/bin/marked" "$@"
ret=$?
else
node "$basedir/../marked/bin/marked" "$@"
ret=$?
fi
exit $ret
+7
View File
@@ -0,0 +1,7 @@
@IF EXIST "%~dp0\node.exe" (
"%~dp0\node.exe" "%~dp0\..\marked\bin\marked" %*
) ELSE (
@SETLOCAL
@SET PATHEXT=%PATHEXT:;.JS;=;%
node "%~dp0\..\marked\bin\marked" %*
)
Generated Vendored
+15
View File
@@ -0,0 +1,15 @@
#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
case `uname` in
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac
if [ -x "$basedir/node" ]; then
"$basedir/node" "$basedir/../nopt/bin/nopt.js" "$@"
ret=$?
else
node "$basedir/../nopt/bin/nopt.js" "$@"
ret=$?
fi
exit $ret
Generated Vendored
+7
View File
@@ -0,0 +1,7 @@
@IF EXIST "%~dp0\node.exe" (
"%~dp0\node.exe" "%~dp0\..\nopt\bin\nopt.js" %*
) ELSE (
@SETLOCAL
@SET PATHEXT=%PATHEXT:;.JS;=;%
node "%~dp0\..\nopt\bin\nopt.js" %*
)
Generated Vendored
+15
View File
@@ -0,0 +1,15 @@
#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
case `uname` in
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac
if [ -x "$basedir/node" ]; then
"$basedir/node" "$basedir/../node-notifier/bin.js" "$@"
ret=$?
else
node "$basedir/../node-notifier/bin.js" "$@"
ret=$?
fi
exit $ret
+7
View File
@@ -0,0 +1,7 @@
@IF EXIST "%~dp0\node.exe" (
"%~dp0\node.exe" "%~dp0\..\node-notifier\bin.js" %*
) ELSE (
@SETLOCAL
@SET PATHEXT=%PATHEXT:;.JS;=;%
node "%~dp0\..\node-notifier\bin.js" %*
)
Generated Vendored
+15
View File
@@ -0,0 +1,15 @@
#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
case `uname` in
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac
if [ -x "$basedir/node" ]; then
"$basedir/node" "$basedir/../sane/src/cli.js" "$@"
ret=$?
else
node "$basedir/../sane/src/cli.js" "$@"
ret=$?
fi
exit $ret
Generated Vendored
+7
View File
@@ -0,0 +1,7 @@
@IF EXIST "%~dp0\node.exe" (
"%~dp0\node.exe" "%~dp0\..\sane\src\cli.js" %*
) ELSE (
@SETLOCAL
@SET PATHEXT=%PATHEXT:;.JS;=;%
node "%~dp0\..\sane\src\cli.js" %*
)
+15
View File
@@ -0,0 +1,15 @@
#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
case `uname` in
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac
if [ -x "$basedir/node" ]; then
"$basedir/node" "$basedir/../sshpk/bin/sshpk-conv" "$@"
ret=$?
else
node "$basedir/../sshpk/bin/sshpk-conv" "$@"
ret=$?
fi
exit $ret
+7
View File
@@ -0,0 +1,7 @@
@IF EXIST "%~dp0\node.exe" (
"%~dp0\node.exe" "%~dp0\..\sshpk\bin\sshpk-conv" %*
) ELSE (
@SETLOCAL
@SET PATHEXT=%PATHEXT:;.JS;=;%
node "%~dp0\..\sshpk\bin\sshpk-conv" %*
)
+15
View File
@@ -0,0 +1,15 @@
#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
case `uname` in
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac
if [ -x "$basedir/node" ]; then
"$basedir/node" "$basedir/../sshpk/bin/sshpk-sign" "$@"
ret=$?
else
node "$basedir/../sshpk/bin/sshpk-sign" "$@"
ret=$?
fi
exit $ret
+7
View File
@@ -0,0 +1,7 @@
@IF EXIST "%~dp0\node.exe" (
"%~dp0\node.exe" "%~dp0\..\sshpk\bin\sshpk-sign" %*
) ELSE (
@SETLOCAL
@SET PATHEXT=%PATHEXT:;.JS;=;%
node "%~dp0\..\sshpk\bin\sshpk-sign" %*
)
+15
View File
@@ -0,0 +1,15 @@
#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
case `uname` in
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac
if [ -x "$basedir/node" ]; then
"$basedir/node" "$basedir/../sshpk/bin/sshpk-verify" "$@"
ret=$?
else
node "$basedir/../sshpk/bin/sshpk-verify" "$@"
ret=$?
fi
exit $ret
+7
View File
@@ -0,0 +1,7 @@
@IF EXIST "%~dp0\node.exe" (
"%~dp0\node.exe" "%~dp0\..\sshpk\bin\sshpk-verify" %*
) ELSE (
@SETLOCAL
@SET PATHEXT=%PATHEXT:;.JS;=;%
node "%~dp0\..\sshpk\bin\sshpk-verify" %*
)
Generated Vendored
+15
View File
@@ -0,0 +1,15 @@
#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
case `uname` in
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac
if [ -x "$basedir/node" ]; then
"$basedir/node" "$basedir/../node-uuid/bin/uuid" "$@"
ret=$?
else
node "$basedir/../node-uuid/bin/uuid" "$@"
ret=$?
fi
exit $ret
Generated Vendored
+7
View File
@@ -0,0 +1,7 @@
@IF EXIST "%~dp0\node.exe" (
"%~dp0\node.exe" "%~dp0\..\node-uuid\bin\uuid" %*
) ELSE (
@SETLOCAL
@SET PATHEXT=%PATHEXT:;.JS;=;%
node "%~dp0\..\node-uuid\bin\uuid" %*
)
+11
View File
@@ -0,0 +1,11 @@
## 1.0.3
- Replaced `let` with `var` in `lib/btoa.js`
- Follow up from `1.0.2`
- Resolves https://github.com/jsdom/abab/issues/18
## 1.0.2
- Replaced `const` with `var` in `index.js`
- Allows use of `abab` in the browser without a transpilation step
- Resolves https://github.com/jsdom/abab/issues/15
+52
View File
@@ -0,0 +1,52 @@
# abab
[![npm version](https://badge.fury.io/js/abab.svg)](https://www.npmjs.com/package/abab) [![Build Status](https://travis-ci.org/jsdom/abab.svg?branch=master)](https://travis-ci.org/jsdom/abab)
A module that implements `window.atob` and `window.btoa` according to the [WHATWG spec](https://html.spec.whatwg.org/multipage/webappapis.html#atob). The code is originally from [w3c/web-platform-tests](https://github.com/w3c/web-platform-tests/blob/master/html/webappapis/atob/base64.html).
Compatibility: Node.js version 3+ and all major browsers (using browserify or webpack)
Install with `npm`:
```sh
npm install abab
```
## API
### `btoa` (base64 encode)
```js
const btoa = require('abab').btoa;
btoa('Hello, world!'); // 'SGVsbG8sIHdvcmxkIQ=='
```
### `atob` (base64 decode)
```js
const atob = require('abab').atob;
atob('SGVsbG8sIHdvcmxkIQ=='); // 'Hello, world!'
```
#### Valid characters
[Per the spec](https://html.spec.whatwg.org/multipage/webappapis.html#atob:dom-windowbase64-btoa-3), `btoa` will accept strings "containing only characters in the range `U+0000` to `U+00FF`." If passed a string with characters above `U+00FF`, `btoa` will return `null`. If `atob` is passed a string that is not base64-valid, it will also return `null`. In both cases when `null` is returned, the spec calls for throwing a `DOMException` of type `InvalidCharacterError`.
## Browsers
If you want to include just one of the methods to save bytes in your client-side code, you can `require` the desired module directly.
```js
var atob = require('abab/lib/atob');
var btoa = require('abab/lib/btoa');
```
-----
### Checklists
If you're **submitting a PR** or **deploying to npm**, please use the [checklists in CONTRIBUTING.md](https://github.com/jsdom/abab/blob/master/CONTRIBUTING.md#checklists)
### Remembering `atob` vs. `btoa`
Here's a mnemonic that might be useful: if you have a plain string and want to base64 encode it, then decode it, `btoa` is what you run before (**b**efore - **b**toa), and `atob` is what you run after (**a**fter - **a**tob).
Generated Vendored
+9
View File
@@ -0,0 +1,9 @@
'use strict';
var atob = require('./lib/atob');
var btoa = require('./lib/btoa');
module.exports = {
atob: atob,
btoa: btoa
};
+109
View File
@@ -0,0 +1,109 @@
'use strict';
/**
* Implementation of atob() according to the HTML spec, except that instead of
* throwing INVALID_CHARACTER_ERR we return null.
*/
function atob(input) {
// WebIDL requires DOMStrings to just be converted using ECMAScript
// ToString, which in our case amounts to calling String().
input = String(input);
// "Remove all space characters from input."
input = input.replace(/[ \t\n\f\r]/g, '');
// "If the length of input divides by 4 leaving no remainder, then: if
// input ends with one or two U+003D EQUALS SIGN (=) characters, remove
// them from input."
if (input.length % 4 == 0 && /==?$/.test(input)) {
input = input.replace(/==?$/, '');
}
// "If the length of input divides by 4 leaving a remainder of 1, throw an
// INVALID_CHARACTER_ERR exception and abort these steps."
//
// "If input contains a character that is not in the following list of
// characters and character ranges, throw an INVALID_CHARACTER_ERR
// exception and abort these steps:
//
// U+002B PLUS SIGN (+)
// U+002F SOLIDUS (/)
// U+0030 DIGIT ZERO (0) to U+0039 DIGIT NINE (9)
// U+0041 LATIN CAPITAL LETTER A to U+005A LATIN CAPITAL LETTER Z
// U+0061 LATIN SMALL LETTER A to U+007A LATIN SMALL LETTER Z"
if (input.length % 4 == 1 || !/^[+/0-9A-Za-z]*$/.test(input)) {
return null;
}
// "Let output be a string, initially empty."
var output = '';
// "Let buffer be a buffer that can have bits appended to it, initially
// empty."
//
// We append bits via left-shift and or. accumulatedBits is used to track
// when we've gotten to 24 bits.
var buffer = 0;
var accumulatedBits = 0;
// "While position does not point past the end of input, run these
// substeps:"
for (var i = 0; i < input.length; i++) {
// "Find the character pointed to by position in the first column of
// the following table. Let n be the number given in the second cell of
// the same row."
//
// "Append to buffer the six bits corresponding to number, most
// significant bit first."
//
// atobLookup() implements the table from the spec.
buffer <<= 6;
buffer |= atobLookup(input[i]);
// "If buffer has accumulated 24 bits, interpret them as three 8-bit
// big-endian numbers. Append the three characters with code points
// equal to those numbers to output, in the same order, and then empty
// buffer."
accumulatedBits += 6;
if (accumulatedBits == 24) {
output += String.fromCharCode((buffer & 0xff0000) >> 16);
output += String.fromCharCode((buffer & 0xff00) >> 8);
output += String.fromCharCode(buffer & 0xff);
buffer = accumulatedBits = 0;
}
// "Advance position by one character."
}
// "If buffer is not empty, it contains either 12 or 18 bits. If it
// contains 12 bits, discard the last four and interpret the remaining
// eight as an 8-bit big-endian number. If it contains 18 bits, discard the
// last two and interpret the remaining 16 as two 8-bit big-endian numbers.
// Append the one or two characters with code points equal to those one or
// two numbers to output, in the same order."
if (accumulatedBits == 12) {
buffer >>= 4;
output += String.fromCharCode(buffer);
} else if (accumulatedBits == 18) {
buffer >>= 2;
output += String.fromCharCode((buffer & 0xff00) >> 8);
output += String.fromCharCode(buffer & 0xff);
}
// "Return output."
return output;
}
/**
* A lookup table for atob(), which converts an ASCII character to the
* corresponding six-bit number.
*/
function atobLookup(chr) {
if (/[A-Z]/.test(chr)) {
return chr.charCodeAt(0) - 'A'.charCodeAt(0);
}
if (/[a-z]/.test(chr)) {
return chr.charCodeAt(0) - 'a'.charCodeAt(0) + 26;
}
if (/[0-9]/.test(chr)) {
return chr.charCodeAt(0) - '0'.charCodeAt(0) + 52;
}
if (chr == '+') {
return 62;
}
if (chr == '/') {
return 63;
}
// Throw exception; should not be hit in tests
}
module.exports = atob;
+65
View File
@@ -0,0 +1,65 @@
'use strict';
/**
* btoa() as defined by the HTML5 spec, which mostly just references RFC4648.
*/
function btoa(s) {
var i;
// String conversion as required by WebIDL.
s = String(s);
// "The btoa() method must throw an INVALID_CHARACTER_ERR exception if the
// method's first argument contains any character whose code point is
// greater than U+00FF."
for (i = 0; i < s.length; i++) {
if (s.charCodeAt(i) > 255) {
return null;
}
}
var out = '';
for (i = 0; i < s.length; i += 3) {
var groupsOfSix = [undefined, undefined, undefined, undefined];
groupsOfSix[0] = s.charCodeAt(i) >> 2;
groupsOfSix[1] = (s.charCodeAt(i) & 0x03) << 4;
if (s.length > i + 1) {
groupsOfSix[1] |= s.charCodeAt(i + 1) >> 4;
groupsOfSix[2] = (s.charCodeAt(i + 1) & 0x0f) << 2;
}
if (s.length > i + 2) {
groupsOfSix[2] |= s.charCodeAt(i + 2) >> 6;
groupsOfSix[3] = s.charCodeAt(i + 2) & 0x3f;
}
for (var j = 0; j < groupsOfSix.length; j++) {
if (typeof groupsOfSix[j] == 'undefined') {
out += '=';
} else {
out += btoaLookup(groupsOfSix[j]);
}
}
}
return out;
}
/**
* Lookup table for btoa(), which converts a six-bit number into the
* corresponding ASCII character.
*/
function btoaLookup(idx) {
if (idx < 26) {
return String.fromCharCode(idx + 'A'.charCodeAt(0));
}
if (idx < 52) {
return String.fromCharCode(idx - 26 + 'a'.charCodeAt(0));
}
if (idx < 62) {
return String.fromCharCode(idx - 52 + '0'.charCodeAt(0));
}
if (idx == 62) {
return '+';
}
if (idx == 63) {
return '/';
}
// Throw INVALID_CHARACTER_ERR exception here -- won't be hit in the tests.
}
module.exports = btoa;
+98
View File
@@ -0,0 +1,98 @@
{
"_args": [
[
"abab@^1.0.0",
"C:\\Users\\Lukas Obermann\\Projekte\\Cha5App\\code\\git\\node_modules\\jsdom"
]
],
"_from": "abab@>=1.0.0 <2.0.0",
"_id": "abab@1.0.3",
"_inCache": true,
"_installable": true,
"_location": "/abab",
"_nodeVersion": "4.1.2",
"_npmUser": {
"email": "gcarpenterv@gmail.com",
"name": "jeffcarp"
},
"_npmVersion": "2.14.4",
"_phantomChildren": {},
"_requested": {
"name": "abab",
"raw": "abab@^1.0.0",
"rawSpec": "^1.0.0",
"scope": null,
"spec": ">=1.0.0 <2.0.0",
"type": "range"
},
"_requiredBy": [
"/jsdom"
],
"_resolved": "https://registry.npmjs.org/abab/-/abab-1.0.3.tgz",
"_shasum": "b81de5f7274ec4e756d797cd834f303642724e5d",
"_shrinkwrap": null,
"_spec": "abab@^1.0.0",
"_where": "C:\\Users\\Lukas Obermann\\Projekte\\Cha5App\\code\\git\\node_modules\\jsdom",
"author": {
"email": "gcarpenterv@gmail.com",
"name": "Jeff Carpenter"
},
"bugs": {
"url": "https://github.com/jsdom/abab/issues"
},
"dependencies": {},
"description": "WHATWG spec-compliant implementations of window.atob and window.btoa.",
"devDependencies": {
"babel-core": "^6.1.4",
"babel-loader": "^6.1.0",
"babel-preset-es2015": "^6.1.4",
"eslint": "^1.3.1",
"jscs": "^2.1.1",
"karma": "^0.13.10",
"karma-cli": "^0.1.1",
"karma-firefox-launcher": "^0.1.6",
"karma-mocha": "^0.2.0",
"karma-sauce-launcher": "^0.2.14",
"karma-webpack": "^1.7.0",
"mocha": "^2.2.5",
"webpack": "^1.12.2"
},
"directories": {},
"dist": {
"shasum": "b81de5f7274ec4e756d797cd834f303642724e5d",
"tarball": "https://registry.npmjs.org/abab/-/abab-1.0.3.tgz"
},
"files": [
"index.js",
"lib/"
],
"gitHead": "223c06f29e0e4d4f3bc11164f762898474158c3a",
"homepage": "https://github.com/jsdom/abab#readme",
"keywords": [
"atob",
"btoa",
"browser"
],
"license": "ISC",
"main": "index.js",
"maintainers": [
{
"email": "gcarpenterv@gmail.com",
"name": "jeffcarp"
}
],
"name": "abab",
"optionalDependencies": {},
"readme": "ERROR: No README data found!",
"repository": {
"type": "git",
"url": "git+https://github.com/jsdom/abab.git"
},
"scripts": {
"karma": "karma start",
"lint": "jscs . && eslint .",
"mocha": "mocha test/node",
"test": "npm run lint && npm run mocha && npm run karma"
},
"version": "1.0.3"
}
+15
View File
@@ -0,0 +1,15 @@
The ISC License
Copyright (c) Isaac Z. Schlueter and Contributors
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+23
View File
@@ -0,0 +1,23 @@
# abbrev-js
Just like [ruby's Abbrev](http://apidock.com/ruby/Abbrev).
Usage:
var abbrev = require("abbrev");
abbrev("foo", "fool", "folding", "flop");
// returns:
{ fl: 'flop'
, flo: 'flop'
, flop: 'flop'
, fol: 'folding'
, fold: 'folding'
, foldi: 'folding'
, foldin: 'folding'
, folding: 'folding'
, foo: 'foo'
, fool: 'fool'
}
This is handy for command-line scripts, or other cases where you want to be able to accept shorthands.
+62
View File
@@ -0,0 +1,62 @@
module.exports = exports = abbrev.abbrev = abbrev
abbrev.monkeyPatch = monkeyPatch
function monkeyPatch () {
Object.defineProperty(Array.prototype, 'abbrev', {
value: function () { return abbrev(this) },
enumerable: false, configurable: true, writable: true
})
Object.defineProperty(Object.prototype, 'abbrev', {
value: function () { return abbrev(Object.keys(this)) },
enumerable: false, configurable: true, writable: true
})
}
function abbrev (list) {
if (arguments.length !== 1 || !Array.isArray(list)) {
list = Array.prototype.slice.call(arguments, 0)
}
for (var i = 0, l = list.length, args = [] ; i < l ; i ++) {
args[i] = typeof list[i] === "string" ? list[i] : String(list[i])
}
// sort them lexicographically, so that they're next to their nearest kin
args = args.sort(lexSort)
// walk through each, seeing how much it has in common with the next and previous
var abbrevs = {}
, prev = ""
for (var i = 0, l = args.length ; i < l ; i ++) {
var current = args[i]
, next = args[i + 1] || ""
, nextMatches = true
, prevMatches = true
if (current === next) continue
for (var j = 0, cl = current.length ; j < cl ; j ++) {
var curChar = current.charAt(j)
nextMatches = nextMatches && curChar === next.charAt(j)
prevMatches = prevMatches && curChar === prev.charAt(j)
if (!nextMatches && !prevMatches) {
j ++
break
}
}
prev = current
if (j === cl) {
abbrevs[current] = current
continue
}
for (var a = current.substr(0, j) ; j <= cl ; j ++) {
abbrevs[a] = current
a += current.charAt(j)
}
}
return abbrevs
}
function lexSort (a, b) {
return a === b ? 0 : a > b ? 1 : -1
}
+82
View File
@@ -0,0 +1,82 @@
{
"_args": [
[
"abbrev@1.0.x",
"C:\\Users\\Lukas Obermann\\Projekte\\Cha5App\\code\\git\\node_modules\\istanbul"
]
],
"_from": "abbrev@>=1.0.0 <1.1.0",
"_id": "abbrev@1.0.9",
"_inCache": true,
"_installable": true,
"_location": "/abbrev",
"_nodeVersion": "4.4.4",
"_npmOperationalInternal": {
"host": "packages-16-east.internal.npmjs.com",
"tmp": "tmp/abbrev-1.0.9.tgz_1466016055839_0.7825860097073019"
},
"_npmUser": {
"email": "i@izs.me",
"name": "isaacs"
},
"_npmVersion": "3.9.1",
"_phantomChildren": {},
"_requested": {
"name": "abbrev",
"raw": "abbrev@1.0.x",
"rawSpec": "1.0.x",
"scope": null,
"spec": ">=1.0.0 <1.1.0",
"type": "range"
},
"_requiredBy": [
"/istanbul",
"/nopt"
],
"_resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.0.9.tgz",
"_shasum": "91b4792588a7738c25f35dd6f63752a2f8776135",
"_shrinkwrap": null,
"_spec": "abbrev@1.0.x",
"_where": "C:\\Users\\Lukas Obermann\\Projekte\\Cha5App\\code\\git\\node_modules\\istanbul",
"author": {
"email": "i@izs.me",
"name": "Isaac Z. Schlueter"
},
"bugs": {
"url": "https://github.com/isaacs/abbrev-js/issues"
},
"dependencies": {},
"description": "Like ruby's abbrev module, but in js",
"devDependencies": {
"tap": "^5.7.2"
},
"directories": {},
"dist": {
"shasum": "91b4792588a7738c25f35dd6f63752a2f8776135",
"tarball": "https://registry.npmjs.org/abbrev/-/abbrev-1.0.9.tgz"
},
"files": [
"abbrev.js"
],
"gitHead": "c386cd9dbb1d8d7581718c54d4ba944cc9298d6f",
"homepage": "https://github.com/isaacs/abbrev-js#readme",
"license": "ISC",
"main": "abbrev.js",
"maintainers": [
{
"email": "i@izs.me",
"name": "isaacs"
}
],
"name": "abbrev",
"optionalDependencies": {},
"readme": "ERROR: No README data found!",
"repository": {
"type": "git",
"url": "git+ssh://git@github.com/isaacs/abbrev-js.git"
},
"scripts": {
"test": "tap test.js --cov"
},
"version": "1.0.9"
}
+19
View File
@@ -0,0 +1,19 @@
Copyright (c) 2014 Forbes Lindesay
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
+76
View File
@@ -0,0 +1,76 @@
# acorn-globals
Detect global variables in JavaScript using acorn
[![Build Status](https://img.shields.io/travis/ForbesLindesay/acorn-globals/master.svg)](https://travis-ci.org/ForbesLindesay/acorn-globals)
[![Dependency Status](https://img.shields.io/david/ForbesLindesay/acorn-globals.svg)](https://david-dm.org/ForbesLindesay/acorn-globals)
[![NPM version](https://img.shields.io/npm/v/acorn-globals.svg)](https://www.npmjs.org/package/acorn-globals)
## Installation
npm install acorn-globals
## Usage
detect.js
```js
var fs = require('fs');
var detect = require('acorn-globals');
var src = fs.readFileSync(__dirname + '/input.js', 'utf8');
var scope = detect(src);
console.dir(scope);
```
input.js
```js
var x = 5;
var y = 3, z = 2;
w.foo();
w = 2;
RAWR=444;
RAWR.foo();
BLARG=3;
foo(function () {
var BAR = 3;
process.nextTick(function (ZZZZZZZZZZZZ) {
console.log('beep boop');
var xyz = 4;
x += 10;
x.zzzzzz;
ZZZ=6;
});
function doom () {
}
ZZZ.foo();
});
console.log(xyz);
```
output:
```
$ node example/detect.js
[ { name: 'BLARG', nodes: [ [Object] ] },
{ name: 'RAWR', nodes: [ [Object], [Object] ] },
{ name: 'ZZZ', nodes: [ [Object], [Object] ] },
{ name: 'console', nodes: [ [Object], [Object] ] },
{ name: 'foo', nodes: [ [Object] ] },
{ name: 'process', nodes: [ [Object] ] },
{ name: 'w', nodes: [ [Object], [Object] ] },
{ name: 'xyz', nodes: [ [Object] ] } ]
```
## License
MIT
+180
View File
@@ -0,0 +1,180 @@
'use strict';
var acorn = require('acorn');
var walk = require('acorn/dist/walk');
function isScope(node) {
return node.type === 'FunctionExpression' || node.type === 'FunctionDeclaration' || node.type === 'ArrowFunctionExpression' || node.type === 'Program';
}
function isBlockScope(node) {
return node.type === 'BlockStatement' || isScope(node);
}
function declaresArguments(node) {
return node.type === 'FunctionExpression' || node.type === 'FunctionDeclaration';
}
function declaresThis(node) {
return node.type === 'FunctionExpression' || node.type === 'FunctionDeclaration';
}
function reallyParse(source) {
try {
return acorn.parse(source, {
ecmaVersion: 6,
allowReturnOutsideFunction: true,
allowImportExportEverywhere: true,
allowHashBang: true
});
} catch (ex) {
return acorn.parse(source, {
ecmaVersion: 5,
allowReturnOutsideFunction: true,
allowImportExportEverywhere: true,
allowHashBang: true
});
}
}
module.exports = findGlobals;
module.exports.parse = reallyParse;
function findGlobals(source) {
var globals = [];
var ast;
// istanbul ignore else
if (typeof source === 'string') {
ast = reallyParse(source);
} else {
ast = source;
}
// istanbul ignore if
if (!(ast && typeof ast === 'object' && ast.type === 'Program')) {
throw new TypeError('Source must be either a string of JavaScript or an acorn AST');
}
var declareFunction = function (node) {
var fn = node;
fn.locals = fn.locals || {};
node.params.forEach(function (node) {
declarePattern(node, fn);
});
if (node.id) {
fn.locals[node.id.name] = true;
}
}
var declarePattern = function (node, parent) {
switch (node.type) {
case 'Identifier':
parent.locals[node.name] = true;
break;
case 'ObjectPattern':
node.properties.forEach(function (node) {
declarePattern(node.value, parent);
});
break;
case 'ArrayPattern':
node.elements.forEach(function (node) {
if (node) declarePattern(node, parent);
});
break;
case 'RestElement':
declarePattern(node.argument, parent);
break;
case 'AssignmentPattern':
declarePattern(node.left, parent);
break;
// istanbul ignore next
default:
throw new Error('Unrecognized pattern type: ' + node.type);
}
}
var declareModuleSpecifier = function (node, parents) {
ast.locals = ast.locals || {};
ast.locals[node.local.name] = true;
}
walk.ancestor(ast, {
'VariableDeclaration': function (node, parents) {
var parent = null;
for (var i = parents.length - 1; i >= 0 && parent === null; i--) {
if (node.kind === 'var' ? isScope(parents[i]) : isBlockScope(parents[i])) {
parent = parents[i];
}
}
parent.locals = parent.locals || {};
node.declarations.forEach(function (declaration) {
declarePattern(declaration.id, parent);
});
},
'FunctionDeclaration': function (node, parents) {
var parent = null;
for (var i = parents.length - 2; i >= 0 && parent === null; i--) {
if (isScope(parents[i])) {
parent = parents[i];
}
}
parent.locals = parent.locals || {};
parent.locals[node.id.name] = true;
declareFunction(node);
},
'Function': declareFunction,
'ClassDeclaration': function (node, parents) {
var parent = null;
for (var i = parents.length - 2; i >= 0 && parent === null; i--) {
if (isScope(parents[i])) {
parent = parents[i];
}
}
parent.locals = parent.locals || {};
parent.locals[node.id.name] = true;
},
'TryStatement': function (node) {
if (node.handler === null) return;
node.handler.body.locals = node.handler.body.locals || {};
node.handler.body.locals[node.handler.param.name] = true;
},
'ImportDefaultSpecifier': declareModuleSpecifier,
'ImportSpecifier': declareModuleSpecifier,
'ImportNamespaceSpecifier': declareModuleSpecifier
});
function identifier(node, parents) {
var name = node.name;
if (name === 'undefined') return;
for (var i = 0; i < parents.length; i++) {
if (name === 'arguments' && declaresArguments(parents[i])) {
return;
}
if (parents[i].locals && name in parents[i].locals) {
return;
}
}
if (
parents[parents.length - 2] &&
parents[parents.length - 2].type === 'TryStatement' &&
parents[parents.length - 2].handler &&
node === parents[parents.length - 2].handler.param
) {
return;
}
node.parents = parents;
globals.push(node);
}
walk.ancestor(ast, {
'VariablePattern': identifier,
'Identifier': identifier,
'ThisExpression': function (node, parents) {
for (var i = 0; i < parents.length; i++) {
if (declaresThis(parents[i])) {
return;
}
}
node.parents = parents;
globals.push(node);
}
});
var groupedGlobals = {};
globals.forEach(function (node) {
groupedGlobals[node.name] = (groupedGlobals[node.name] || []);
groupedGlobals[node.name].push(node);
});
return Object.keys(groupedGlobals).sort().map(function (name) {
return {name: name, nodes: groupedGlobals[name]};
});
}
+15
View File
@@ -0,0 +1,15 @@
#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
case `uname` in
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac
if [ -x "$basedir/node" ]; then
"$basedir/node" "$basedir/../acorn/bin/acorn" "$@"
ret=$?
else
node "$basedir/../acorn/bin/acorn" "$@"
ret=$?
fi
exit $ret
+7
View File
@@ -0,0 +1,7 @@
@IF EXIST "%~dp0\node.exe" (
"%~dp0\node.exe" "%~dp0\..\acorn\bin\acorn" %*
) ELSE (
@SETLOCAL
@SET PATHEXT=%PATHEXT:;.JS;=;%
node "%~dp0\..\acorn\bin\acorn" %*
)
+7
View File
@@ -0,0 +1,7 @@
root = true
[*]
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
@@ -0,0 +1 @@
* text eol=lf
+3
View File
@@ -0,0 +1,3 @@
/.tern-port
/test
/local
+6
View File
@@ -0,0 +1,6 @@
{
"plugins": {
"node": true,
"es_modules": true
}
}
+6
View File
@@ -0,0 +1,6 @@
language: node_js
sudo: false
node_js:
- '0.10'
- '0.12'
- '4'
+43
View File
@@ -0,0 +1,43 @@
List of Acorn contributors. Updated before every release.
Adrian Rakovsky
Alistair Braidwood
Andres Suarez
Aparajita Fishman
Arian Stolwijk
Artem Govorov
Brandon Mills
Charles Hughes
Conrad Irwin
David Bonnet
ForbesLindesay
Forbes Lindesay
Gilad Peleg
impinball
Ingvar Stepanyan
Jesse McCarthy
Jiaxing Wang
Joel Kemp
Johannes Herr
Jürg Lehni
keeyipchan
Kevin Kwok
krator
Marijn Haverbeke
Martin Carlberg
Mathias Bynens
Mathieu 'p01' Henri
Max Schaefer
Max Zerzouri
Mihai Bazon
Mike Rennie
Nick Fitzgerald
Oskar Schöldström
Paul Harper
Peter Rust
PlNG
r-e-d
Rich Harris
Sebastian McKenzie
Timothy Gu
zsjforcn
+19
View File
@@ -0,0 +1,19 @@
Copyright (C) 2012-2014 by various contributors (see AUTHORS)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
+396
View File
@@ -0,0 +1,396 @@
# Acorn
[![Build Status](https://travis-ci.org/ternjs/acorn.svg?branch=master)](https://travis-ci.org/ternjs/acorn)
[![NPM version](https://img.shields.io/npm/v/acorn.svg)](https://www.npmjs.com/package/acorn)
[Author funding status: ![maintainer happiness](https://marijnhaverbeke.nl/fund/status_s.png?force)](https://marijnhaverbeke.nl/fund/)
A tiny, fast JavaScript parser, written completely in JavaScript.
## Community
Acorn is open source software released under an
[MIT license](https://github.com/ternjs/acorn/blob/master/LICENSE).
You are welcome to
[report bugs](https://github.com/ternjs/acorn/issues) or create pull
requests on [github](https://github.com/ternjs/acorn). For questions
and discussion, please use the
[Tern discussion forum](https://discuss.ternjs.net).
## Installation
The easiest way to install acorn is with [`npm`][npm].
[npm]: https://www.npmjs.com/
```sh
npm install acorn
```
Alternately, download the source.
```sh
git clone https://github.com/ternjs/acorn.git
```
## Components
When run in a CommonJS (node.js) or AMD environment, exported values
appear in the interfaces exposed by the individual files, as usual.
When loaded in the browser (Acorn works in any JS-enabled browser more
recent than IE5) without any kind of module management, a single
global object `acorn` will be defined, and all the exported properties
will be added to that.
### Main parser
This is implemented in `dist/acorn.js`, and is what you get when you
`require("acorn")` in node.js.
**parse**`(input, options)` is used to parse a JavaScript program.
The `input` parameter is a string, `options` can be undefined or an
object setting some of the options listed below. The return value will
be an abstract syntax tree object as specified by the
[ESTree spec][estree].
When encountering a syntax error, the parser will raise a
`SyntaxError` object with a meaningful message. The error object will
have a `pos` property that indicates the character offset at which the
error occurred, and a `loc` object that contains a `{line, column}`
object referring to that same position.
[estree]: https://github.com/estree/estree
- **ecmaVersion**: Indicates the ECMAScript version to parse. Must be
either 3, 5, or 6. This influences support for strict mode, the set
of reserved words, and support for new syntax features. Default is 5.
- **sourceType**: Indicate the mode the code should be parsed in. Can be
either `"script"` or `"module"`.
- **onInsertedSemicolon**: If given a callback, that callback will be
called whenever a missing semicolon is inserted by the parser. The
callback will be given the character offset of the point where the
semicolon is inserted as argument, and if `locations` is on, also a
`{line, column}` object representing this position.
- **onTrailingComma**: Like `onInsertedSemicolon`, but for trailing
commas.
- **allowReserved**: If `false`, using a reserved word will generate
an error. Defaults to `true` for `ecmaVersion` 3, `false` for higher
versions. When given the value `"never"`, reserved words and
keywords can also not be used as property names (as in Internet
Explorer's old parser).
- **allowReturnOutsideFunction**: By default, a return statement at
the top level raises an error. Set this to `true` to accept such
code.
- **allowImportExportEverywhere**: By default, `import` and `export`
declarations can only appear at a program's top level. Setting this
option to `true` allows them anywhere where a statement is allowed.
- **allowHashBang**: When this is enabled (off by default), if the
code starts with the characters `#!` (as in a shellscript), the
first line will be treated as a comment.
- **locations**: When `true`, each node has a `loc` object attached
with `start` and `end` subobjects, each of which contains the
one-based line and zero-based column numbers in `{line, column}`
form. Default is `false`.
- **onToken**: If a function is passed for this option, each found
token will be passed in same format as tokens returned from
`tokenizer().getToken()`.
If array is passed, each found token is pushed to it.
Note that you are not allowed to call the parser from the
callback—that will corrupt its internal state.
- **onComment**: If a function is passed for this option, whenever a
comment is encountered the function will be called with the
following parameters:
- `block`: `true` if the comment is a block comment, false if it
is a line comment.
- `text`: The content of the comment.
- `start`: Character offset of the start of the comment.
- `end`: Character offset of the end of the comment.
When the `locations` options is on, the `{line, column}` locations
of the comments start and end are passed as two additional
parameters.
If array is passed for this option, each found comment is pushed
to it as object in Esprima format:
```javascript
{
"type": "Line" | "Block",
"value": "comment text",
"start": Number,
"end": Number,
// If `locations` option is on:
"loc": {
"start": {line: Number, column: Number}
"end": {line: Number, column: Number}
},
// If `ranges` option is on:
"range": [Number, Number]
}
```
Note that you are not allowed to call the parser from the
callback—that will corrupt its internal state.
- **ranges**: Nodes have their start and end characters offsets
recorded in `start` and `end` properties (directly on the node,
rather than the `loc` object, which holds line/column data. To also
add a [semi-standardized][range] `range` property holding a
`[start, end]` array with the same numbers, set the `ranges` option
to `true`.
- **program**: It is possible to parse multiple files into a single
AST by passing the tree produced by parsing the first file as the
`program` option in subsequent parses. This will add the toplevel
forms of the parsed file to the "Program" (top) node of an existing
parse tree.
- **sourceFile**: When the `locations` option is `true`, you can pass
this option to add a `source` attribute in every nodes `loc`
object. Note that the contents of this option are not examined or
processed in any way; you are free to use whatever format you
choose.
- **directSourceFile**: Like `sourceFile`, but a `sourceFile` property
will be added directly to the nodes, rather than the `loc` object.
- **preserveParens**: If this option is `true`, parenthesized expressions
are represented by (non-standard) `ParenthesizedExpression` nodes
that have a single `expression` property containing the expression
inside parentheses.
[range]: https://bugzilla.mozilla.org/show_bug.cgi?id=745678
**parseExpressionAt**`(input, offset, options)` will parse a single
expression in a string, and return its AST. It will not complain if
there is more of the string left after the expression.
**getLineInfo**`(input, offset)` can be used to get a `{line,
column}` object for a given program string and character offset.
**tokenizer**`(input, options)` returns an object with a `getToken`
method that can be called repeatedly to get the next token, a `{start,
end, type, value}` object (with added `loc` property when the
`locations` option is enabled and `range` property when the `ranges`
option is enabled). When the token's type is `tokTypes.eof`, you
should stop calling the method, since it will keep returning that same
token forever.
In ES6 environment, returned result can be used as any other
protocol-compliant iterable:
```javascript
for (let token of acorn.tokenizer(str)) {
// iterate over the tokens
}
// transform code to array of tokens:
var tokens = [...acorn.tokenizer(str)];
```
**tokTypes** holds an object mapping names to the token type objects
that end up in the `type` properties of tokens.
#### Note on using with [Escodegen][escodegen]
Escodegen supports generating comments from AST, attached in
Esprima-specific format. In order to simulate same format in
Acorn, consider following example:
```javascript
var comments = [], tokens = [];
var ast = acorn.parse('var x = 42; // answer', {
// collect ranges for each node
ranges: true,
// collect comments in Esprima's format
onComment: comments,
// collect token ranges
onToken: tokens
});
// attach comments using collected information
escodegen.attachComments(ast, comments, tokens);
// generate code
console.log(escodegen.generate(ast, {comment: true}));
// > 'var x = 42; // answer'
```
[escodegen]: https://github.com/estools/escodegen
### dist/acorn_loose.js ###
This file implements an error-tolerant parser. It exposes a single
function. The loose parser is accessible in node.js via `require("acorn/dist/acorn_loose")`.
**parse_dammit**`(input, options)` takes the same arguments and
returns the same syntax tree as the `parse` function in `acorn.js`,
but never raises an error, and will do its best to parse syntactically
invalid code in as meaningful a way as it can. It'll insert identifier
nodes with name `"✖"` as placeholders in places where it can't make
sense of the input. Depends on `acorn.js`, because it uses the same
tokenizer.
### dist/walk.js ###
Implements an abstract syntax tree walker. Will store its interface in
`acorn.walk` when loaded without a module system.
**simple**`(node, visitors, base, state)` does a 'simple' walk over
a tree. `node` should be the AST node to walk, and `visitors` an
object with properties whose names correspond to node types in the
[ESTree spec][estree]. The properties should contain functions
that will be called with the node object and, if applicable the state
at that point. The last two arguments are optional. `base` is a walker
algorithm, and `state` is a start state. The default walker will
simply visit all statements and expressions and not produce a
meaningful state. (An example of a use of state is to track scope at
each point in the tree.)
**ancestor**`(node, visitors, base, state)` does a 'simple' walk over
a tree, building up an array of ancestor nodes (including the current node)
and passing the array to callbacks in the `state` parameter.
**recursive**`(node, state, functions, base)` does a 'recursive'
walk, where the walker functions are responsible for continuing the
walk on the child nodes of their target node. `state` is the start
state, and `functions` should contain an object that maps node types
to walker functions. Such functions are called with `(node, state, c)`
arguments, and can cause the walk to continue on a sub-node by calling
the `c` argument on it with `(node, state)` arguments. The optional
`base` argument provides the fallback walker functions for node types
that aren't handled in the `functions` object. If not given, the
default walkers will be used.
**make**`(functions, base)` builds a new walker object by using the
walker functions in `functions` and filling in the missing ones by
taking defaults from `base`.
**findNodeAt**`(node, start, end, test, base, state)` tries to
locate a node in a tree at the given start and/or end offsets, which
satisfies the predicate `test`. `start` and `end` can be either `null`
(as wildcard) or a number. `test` may be a string (indicating a node
type) or a function that takes `(nodeType, node)` arguments and
returns a boolean indicating whether this node is interesting. `base`
and `state` are optional, and can be used to specify a custom walker.
Nodes are tested from inner to outer, so if two nodes match the
boundaries, the inner one will be preferred.
**findNodeAround**`(node, pos, test, base, state)` is a lot like
`findNodeAt`, but will match any node that exists 'around' (spanning)
the given position.
**findNodeAfter**`(node, pos, test, base, state)` is similar to
`findNodeAround`, but will match all nodes *after* the given position
(testing outer nodes before inner nodes).
## Command line interface
The `bin/acorn` utility can be used to parse a file from the command
line. It accepts as arguments its input file and the following
options:
- `--ecma3|--ecma5|--ecma6`: Sets the ECMAScript version to parse. Default is
version 5.
- `--module`: Sets the parsing mode to `"module"`. Is set to `"script"` otherwise.
- `--locations`: Attaches a "loc" object to each node with "start" and
"end" subobjects, each of which contains the one-based line and
zero-based column numbers in `{line, column}` form.
- `--allow-hash-bang`: If the code starts with the characters #! (as in a shellscript), the first line will be treated as a comment.
- `--compact`: No whitespace is used in the AST output.
- `--silent`: Do not output the AST, just return the exit status.
- `--help`: Print the usage information and quit.
The utility spits out the syntax tree as JSON data.
## Build system
Acorn is written in ECMAScript 6, as a set of small modules, in the
project's `src` directory, and compiled down to bigger ECMAScript 3
files in `dist` using [Browserify](http://browserify.org) and
[Babel](http://babeljs.io/). If you are already using Babel, you can
consider including the modules directly.
The command-line test runner (`npm test`) uses the ES6 modules. The
browser-based test page (`test/index.html`) uses the compiled modules.
The `bin/build-acorn.js` script builds the latter from the former.
If you are working on Acorn, you'll probably want to try the code out
directly, without an intermediate build step. In your scripts, you can
register the Babel require shim like this:
require("babel-core/register")
That will allow you to directly `require` the ES6 modules.
## Plugins
Acorn is designed support allow plugins which, within reasonable
bounds, redefine the way the parser works. Plugins can add new token
types and new tokenizer contexts (if necessary), and extend methods in
the parser object. This is not a clean, elegant API—using it requires
an understanding of Acorn's internals, and plugins are likely to break
whenever those internals are significantly changed. But still, it is
_possible_, in this way, to create parsers for JavaScript dialects
without forking all of Acorn. And in principle it is even possible to
combine such plugins, so that if you have, for example, a plugin for
parsing types and a plugin for parsing JSX-style XML literals, you
could load them both and parse code with both JSX tags and types.
A plugin should register itself by adding a property to
`acorn.plugins`, which holds a function. Calling `acorn.parse`, a
`plugins` option can be passed, holding an object mapping plugin names
to configuration values (or just `true` for plugins that don't take
options). After the parser object has been created, the initialization
functions for the chosen plugins are called with `(parser,
configValue)` arguments. They are expected to use the `parser.extend`
method to extend parser methods. For example, the `readToken` method
could be extended like this:
```javascript
parser.extend("readToken", function(nextMethod) {
return function(code) {
console.log("Reading a token!")
return nextMethod.call(this, code)
}
})
```
The `nextMethod` argument passed to `extend`'s second argument is the
previous value of this method, and should usually be called through to
whenever the extended method does not handle the call itself.
Similarly, the loose parser allows plugins to register themselves via
`acorn.pluginsLoose`. The extension mechanism is the same as for the
normal parser:
```javascript
looseParser.extend("readToken", function(nextMethod) {
return function() {
console.log("Reading a token in the loose parser!")
return nextMethod.call(this)
}
})
```
There is a proof-of-concept JSX plugin in the [`acorn-jsx`](https://github.com/RReverser/acorn-jsx) project.
+71
View File
@@ -0,0 +1,71 @@
#!/usr/bin/env node
"use strict";
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj["default"] = obj; return newObj; } }
var _path = require("path");
var _fs = require("fs");
var _distAcornJs = require("../dist/acorn.js");
var acorn = _interopRequireWildcard(_distAcornJs);
var infile = undefined,
forceFile = undefined,
silent = false,
compact = false,
tokenize = false;
var options = {};
function help(status) {
var print = status == 0 ? console.log : console.error;
print("usage: " + (0, _path.basename)(process.argv[1]) + " [--ecma3|--ecma5|--ecma6]");
print(" [--tokenize] [--locations] [---allow-hash-bang] [--compact] [--silent] [--module] [--help] [--] [infile]");
process.exit(status);
}
for (var i = 2; i < process.argv.length; ++i) {
var arg = process.argv[i];
if ((arg == "-" || arg[0] != "-") && !infile) infile = arg;else if (arg == "--" && !infile && i + 2 == process.argv.length) forceFile = infile = process.argv[++i];else if (arg == "--ecma3") options.ecmaVersion = 3;else if (arg == "--ecma5") options.ecmaVersion = 5;else if (arg == "--ecma6") options.ecmaVersion = 6;else if (arg == "--locations") options.locations = true;else if (arg == "--allow-hash-bang") options.allowHashBang = true;else if (arg == "--silent") silent = true;else if (arg == "--compact") compact = true;else if (arg == "--help") help(0);else if (arg == "--tokenize") tokenize = true;else if (arg == "--module") options.sourceType = 'module';else help(1);
}
function run(code) {
var result = undefined;
if (!tokenize) {
try {
result = acorn.parse(code, options);
} catch (e) {
console.error(e.message);process.exit(1);
}
} else {
result = [];
var tokenizer = acorn.tokenizer(code, options),
token = undefined;
while (true) {
try {
token = tokenizer.getToken();
} catch (e) {
console.error(e.message);process.exit(1);
}
result.push(token);
if (token.type == acorn.tokTypes.eof) break;
}
}
if (!silent) console.log(JSON.stringify(result, null, compact ? null : 2));
}
if (forceFile || infile && infile != "-") {
run((0, _fs.readFileSync)(infile, "utf8"));
} else {
(function () {
var code = "";
process.stdin.resume();
process.stdin.on("data", function (chunk) {
return code += chunk;
});
process.stdin.on("end", function () {
return run(code);
});
})();
}

Some files were not shown because too many files have changed in this diff Show More