1.0.0 • Published 6 years ago

story-json v1.0.0

Weekly downloads
2
License
MIT
Repository
-
Last release
6 years ago

story-json

story-json is a JavaScript Object Notation (JSON) platform-agnostic document format that describes interactive content that user can "tap" through. This is an interactive storytelling format, optimized for quick consumption on a smartphone or tablet. See an example here.

A "Story" consists of a set of pages (or slides). Each page can contain various kinds of content. In most cases a page will have an image or short video as a background, with elements overlayed on top. Story-JSON documents can be created once and then transformed into any supported target format. This is based on the AMP Project's design system for Stories, which you can find here.

Story-JSON exists because we expect the Story format will be adopted by more and more platforms over time. Story-JSON serves as a convenient base format from which multi-platform distribution can happen automatically. Our main inspiration for this project was the Article-JSON format we developed to solve an analogous problem for articles.

Target formats

These are currently supported target formats:

AMP story

Video

Layout and styles

story-json uses Flexbox layout and styles that in most cases match CSS (camelCase notation, e.g. justifyContent). Since we want to support platforms other than the web, the list of styles is limited. Our current video implementation uses Yoga, a cross-platform layout engine made by Facebook, used in React Native.

The default value for flexDirection is row.

Validator

This repository includes story-json validator based on JSON Schema.

Install using npm:

npm i story-json -g

Usage:

story-json-validate <story.json>

Format structure

"Hello World" example, one page with "Hello World" text in the center:

{
  "version": 1,
  "title": "Hello World",
  "pages": [
    {
      "layers": [
        {
          "type": "container",
          "styles": {
            "backgroundColor": "#87d687"
          }
        },
        {
          "type": "container",
          "styles": {
            "flexDirection": "column",
            "justifyContent": "center",
            "alignItems": "center",
            "textAlign": "center"
          },
          "elements": [
            {
              "type": "heading",
              "text": "Hello World"
            }
          ]
        }
      ]
    }
  ],
  "defaultStyles": {
    "heading": {
      "fontFamily": "sans-serif"
    }
  }
}

story-json document format example:

{
  "version": 1,
  "title": "Story Title",
  "canonicalUrl": "https://example.com/story",
  "meta": {
    "datePublished": "2017-02-05T22:00:00.000Z",
    "dateModified": "2017-02-05T22:00:00.000Z",
    "author": "John Doe",
    "publisher": {
      "name": "Publisher Name",
      "logo": {
        "url": "https://example.com/publisher-logo",
        "width": 100,
        "height": 100
      }
    },
    "description": "Story description"
  },
  "pages": [
    {
      "annotation": "Page Annotation",
      "autoAdvanceAfter": 5,
      "layers": [
        {
          "type": "video",
          "annotation": "Video Annotation",
          "sources": [
            {
              "source": "https://example.com/video.m3u8",
              "type": "application/x-mpegURL"
            }
          ],
          "width": 1900,
          "height": 600,
          "layout": "responsive",
          "poster": "https://example.com/poster.jpg",
          "loop": true,
          "autoplay": true
        }
      ]
    },
    {
      "type": "container",
      "styles": {
        "justifyContent": "flex-end",
        "alignItems": "flex-end"
      },
      "elements": [
        {
          "type": "heading",
          "text": "This is a heading",
          "styles": {
            "width": 10,
            "height": 10,
            "border": {
              "width": 1,
              "color": "#000000",
              "style": "dashed"
            },
            "borderRadius": 10,
            "boxShadow": {
              "offset": {
                "x": 5,
                "y": 5
              },
              "blurRadius": 5,
              "spread": 10,
              "color": "#000000"
            },
            "textShadow": [
              {
                "offset": {
                  "x": 5,
                  "y": 5
                },
                "blurRadius": 5,
                "color": "#000000"
              }
            ],
            "transform": [
              {
                "rotate": "90deg"
              },
              {
                "translateX": "50%"
              },
              {
                "translateY": 50
              },
              {
                "scale": 2
              }
            ],
            "filter": [
              {
                "blur": 3
              },
              {
                "grayscale": "30%"
              }
            ],
            "backdropFilter": [
              {
                "blur": 3
              },
              {
                "grayscale": "30%"
              }
            ],
            "backgroundLinearGradient": {
              "direction": "50deg",
              "stops": [
                {
                  "color": "red",
                  "distance": 30
                },
                {
                  "color": "blue",
                  "distance": "50%"
                },
                {
                  "color": "black"
                }
              ]
            },
            "fontSize": 500,
            "paddingTop": 500
          }
        }
      ]
    } 
  ]
}

See more examples

Document properties

Top level

PropertyDescriptionTypeRequired
versionFormat version (latest is 1).numberyes
titleStory title.stringno
canonicalUrlPrimary URL associated with the story.stringno
metaStory metadata.Story metadatano
canonicalUrlURL that will point to the story's HTML file.stringno
pagesArray of pages in the story.Array of pagesno
defaultStylesDefault styles for each element.Object with element type keys and style valuesno

Story metadata

PropertyDescriptionTypeRequired
datePublishedStory publish date in UTC.ISO 8601 Dateno
dateModifiedStory last modification date in UTC.ISO 8601 Dateno
authorAuthor name.stringno
publisherStory publisher metadata.Publisher metadatano
descriptionStory description.stringno

Publisher metadata

PropertyDescriptionTypeRequired
namePublisher namestringyes
logoPublisher logoPublisher metadata logono

Publisher metadata logo

PropertyDescriptionTypeRequired
urlLogo image URL.stringyes
widthLogo width in pixels.numberyes
heightLogo height in pixels.numberyes

Page

PropertyDescriptionTypeRequiredNotes
layersContent of the page dataArray of elementsyes
idUnique page identifier.stringno
annotationUser-defined information associated with the page.anynoWill be removed in render.

Element

PropertyDescriptionTypeRequired
typeElement type.'container', 'image', 'video', 'paragraph', 'heading', 'heading1', 'heading2', 'heading3', 'heading4', 'heading5', or 'heading6'yes
idUnique element identifier.stringno
stylesElement styles.Styles objectno
annotationUser-defined information associated with the element; will be removed in render.anyno

Styles

Styles are very similar to CSS styles, but are intended to be usable and easy to reason about on platforms that don't use an HTML renderer; for example, via React Native. Depending on the chosen platform's capabilities, some properties may be ignored.

PropertyDescriptionTypeRequiredNotes
positionElement position.'relative' or 'absolute'no
topTop positionDistanceno
bottomBottom positionDistanceno
leftLeft positionDistanceno
rightRight positionDistanceno
widthElement widthDistanceno
heightElement heightDistanceno
marginElement margin (top, bottom, left and right)DistancenoNot currently supported by amp-story
marginTopElement margin topDistancenoNot currently supported by amp-story
marginBottomElement margin bottomDistancenoNot currently supported by amp-story
marginLeftElement margin leftDistancenoNot currently supported by amp-story
marginRightElement margin rightDistancenoNot currently supported by amp-story
paddingElement padding (top, bottom, left and right)Distanceno
paddingTopElement padding topDistanceno
paddingBottomElement padding bottomDistanceno
paddingLeftElement padding leftDistanceno
paddingRightElement padding rightDistanceno
borderElement border (top, bottom, left and right)Borderno
borderTopElement border topBorderno
borderBottomElement border bottomBorderno
borderLeftElement border leftBorderno
borderRightElement border rightBorderno
borderRadiusElement border radius (top-left, top-right, bottom-left and bottom-right)numberno
borderTopLeftRadiusElement top-left border radiusnumberno
borderTopRightRadiusElement top-right border radiusnumberno
borderBottomLeftRadiusElement bottom-left border radiusnumberno
borderBottomRightRadiusElement bottom-right border radiusnumberno
displayDisplay type'flex', or 'none'no
flexDirection'row', 'row-reverse', 'column', or 'column-reverse'stringno
justifyContent'flex-start', 'center', 'flex-end', 'space-around', or 'space-between'stringno
alignItems'flex-start', 'center', 'flex-end', or 'stretch'stringno
textAlign'auto', 'left', 'right', 'center', or 'justify'stringno
backgroundColorBackground colorRGBA hex string, rgb(r,g,b), rgba(r,g,b,a)no
backgroundLinearGradientLinear gradientLinear Gradientno
colorText colorRGBA hex string, rgb(r,g,b), rgba(r,g,b,a)no
boxShadowShadow effectBox shadow or array of box shadowsno
fontFamilyText fontstringno
fontSizeText font sizenumberno
lineHeightText line heightnumberno
fontStyle'normal' or 'italic'stringno
textShadowShadow effectText shadow or array of text shadowsno
opacityOpacitynumberno
transformTransforms to apply to elementArray of transformsno
filterFilters to apply to elementArray of filtersno
backdropFilterBackdrop filters to apply to elementArray of filtersnohttps://developer.mozilla.org/en-US/docs/Web/CSS/backdrop-filter

Distance Style

Distance - absolute number or percentage string (for example, 10 or '10%')

Border Style

PropertyDescriptionTypeRequired
widthBorder widthnumberyes
colorBorder colorRGBA hex string, rgb(r,g,b), rgba(r,g,b,a)yes
styleBorder style (solid, dotted, dashed)stringyes

Linear Gradient

PropertyDescriptionTypeRequired
directionDirection angleangle stringyes
stopsGradient stopsArray of linear gradient stopsyes

Linear Gradient Stop

PropertyDescriptionTypeRequired
colorGradient stop colorRGBA hex string, rgb(r,g,b), rgba(r,g,b,a)yes
distanceGradient stop distanceDistanceno

Shadow and Box Shadow

PropertyDescriptionTypeRequired
offsetShadow offsets{ x: number, y: number }yes
colorShadow colorRGBA hex string, rgb(r,g,b), rgba(r,g,b,a)no
blurRadiusShadow blur radiusnumberno
spreadShadow spread (Box Shadow only)numberno

Transform

Transform object contains one of the following properties:

PropertyType
perspectivenumber
rotateangle string
rotateXangle string
rotateYangle string
rotateZangle string
scalenumber
scaleXnumber
scaleYnumber
scaleZnumber
translateXDistance
translateYDistance
skewXangle string
skewYangle string

Filter

Filter object contains one of the following properties:

PropertyType
blurDistance
brightnessnumber
grayscalepercentage string