UNPKG

7.99 kBMarkdownView Raw
1 _ _ _____
2 (_) | | / ____|
3 _ _ __ ___ ___ ___ | | | (___
4 | | | '_ ` _ \ / __| / __| _ | | \___ \
5 | | | | | | | | \__ \ | (__ | |__| | ____) |
6 |_| |_| |_| |_| |___/ \___| \____/ |_____/
7
8
9
10INTRODUCTION
11============
12
13imscJS is a JavaScript library for rendering [IMSC 1.0.1](https://www.w3.org/TR/ttml-imsc1.0.1/) and [IMSC 1.1](https://www.w3.org/TR/ttml-imsc1.1/) documents to HTML5. IMSC is a profile of [TTML 2](https://www.w3.org/TR/ttml2/) designed for subtitle and caption delivery worldwide.
14
15imscJS 1.1.x implements [IMSC 1.0.1](https://www.w3.org/TR/ttml-imsc1.0.1/) and [IMSC 1.1](https://www.w3.org/TR/ttml-imsc1.1/), and is recommended for routine use.
16
17imscJS 1.0.x only implements [IMSC 1.0.1](https://www.w3.org/TR/ttml-imsc1.0.1/), and is no longer being actively developed.
18
19A sample web app that uses imscJS is available at http://sandflow.com/imsc1_1/index.html.
20
21Documentation is available on [MDN](https://developer.mozilla.org/en-US/docs/Related/IMSC).
22
23
24
25KNOWN ISSUES AND LIMITATIONS
26============================
27
28imscJS is primarily developed on Firefox. Latest versions of Chrome, Safari, and Microsoft Edge are intended to be supported nevertheless, albeit with potentially reduced capabilities. In particular, advanced ruby layout is currently only supported by Firefox.
29
30imscJS is intended to reflect the most recent published versions of [IMSC 1.0.1](https://www.w3.org/TR/ttml-imsc1.0.1/) and [IMSC 1.1](https://www.w3.org/TR/ttml-imsc1.1/). These publications are routinely clarified by proposed resolutions to issues captured in their respective bug trackers.
31
32imscJS bugs are tracked at https://github.com/sandflow/imscJS/issues.
33
34
35
36RUNTIME DEPENDENCIES
37====================
38
39(required) [sax-js 1.2.1](https://www.npmjs.com/package/sax)
40
41Rendering to HTML5 requires a browser environment, but parsing an IMSC1 document and tranforming it into ISDs does not.
42
43
44
45DEVELOPMENT DEPENDENCIES
46========================
47
48(required) node.js (see [package.json](package.json) for a complete list of dependencies)
49
50(recommended) git
51
52
53
54QUICK START
55===========
56
57* run the `build` target defined in [Gruntfile.js](Gruntfile.js) using [grunt](http://gruntjs.com/).
58
59* the resulting `imsc.js` and `sax.js` files at `build/public_html/libs` are, respectively, the imscJS library and its sax-js dependency. For example, both libraries can be included in a web page as follows:
60
61```html
62 <script src="libs/sax.js"></script>
63 <script src="libs/imsc.js"></script>
64```
65
66See BUILD ARTIFACTS for a full list of build artifacts, and TESTS AND SAMPLES for a list of samples and tests available.
67
68
69
70ARCHITECTURE
71============
72
73API
74---
75
76imscJS renders an IMSC1 document in three distinct steps:
77
78* `fromXML(xmlstring, errorHandler, metadataHandler)` parses the document and returns a TT object. The latter contains opaque representation of the document and exposes the method `getMediaTimeEvents()` that returns a list of time offsets (in seconds) of the ISD, i.e. the points in time where the visual representation of the document change.
79
80* `generateISD(tt, offset, errorHandler)` creates a canonical representation of the document (provided as a TT object generated by `fromXML()`) at a point in time (`offset` parameter). This point in time does not have to be one of the values returned by `getMediaTimeEvents()`. For example, given an ISOBMFF sample covering the interval `[a, b[`, `generateISD(tt, offset, errorHandler)` would be called first with `offset = a`, then in turn with offset set to each value of `getMediaTimeEvents()` that fall in the interval `]a, b[`.
81
82* `renderHTML(isd, element, imgResolver, eheight, ewidth, displayForcedOnlyMode, errorHandler, previousISDState, enableRollUp)` renders an `isd` object returned by `generateISD()` into a newly-created `div` element that is appended to the `element`. The `element` must be attached to the DOM. The height and width of the child `div` element are equal to `eheight` and `ewidth` if not null, or `clientWidth` and `clientHeight` of the parent `element` otherwise. Images URIs specified in `smpte:background` attributes are mapped to image resource URLs by the `imgResolver` function. The latter takes the value of the `smpte:background` attribute URI and an `img` DOM element as input and is expected to set the `src` attribute of the `img` DOM element to the absolute URI of the image. `displayForcedOnlyMode` sets the (boolean) value of the IMSC1 displayForcedOnlyMode parameter. `enableRollUp` enables roll-up as specified in CEA 708. `previousISDState` maintains states across calls, e.g. for roll-up processing.
83
84In each step, the caller can provide an `errorHandler` to be notified of events during processing. The `errorHandler` may define four methods: `info`, `warn`, `error` and `fatal`. Each is called with a string argument describing the event, and will cause processing to terminate if it returns `true`.
85
86Inline documentation provides additional information.
87
88
89MODULES
90-------
91
92imscJS consists of the following modules, which can be used in a node
93environment using the `require` functionality, or standalone, in which case each module hosts its
94definitions under a global name (the token between parantheses):
95
96* `doc.js` (`imscDoc`): parses an IMSC1 document into an in-memory TT object
97* `isd.js` (`imscISD`): generates an ISD object from a TT object
98* `html.js` (`imscHTML`): generates an HTML fragment from an ISD object
99* `names.js` (`imscNames`): common constants
100* `styles.js` (`imscStyles`): defines TTML styling attributes processing
101* `utils.js` (`imscUtils`): common utility functions
102
103
104
105BUILD
106=====
107
108imscJS is built using the `build:release` or `build:debug` Grunt tasks -- the `build` task is an alias of `build:debug`.
109
110The `dist` directory contains the following build artifacts:
111* `imsc.all.debug.js`: Non-minified build that includes the sax-js dependency.
112* `imsc.all.min.js`: Minified build that includes the sax-js dependency.
113* `imsc.debug.js`: Non-minified build that does not include the sax-js dependency.
114* `imsc.min.js`: Minified build that does not include the sax-js dependency.
115
116The `build/public_html/libs/imsc.js` files is identical to:
117* `imsc.debug.js`, if the `build:debug` task is executed.
118* `imsc.min.js`, if the `build:release` task is executed.
119
120
121
122RELEASES
123========
124
125imscJS is released as an NPM package under [imsc](https://www.npmjs.com/package/imsc). The `dev` distribution tag indicates pre-releases.
126
127All builds are available on the [unpkg](https://unpkg.com/) CDN under the `dist` directory.
128
129EXAMPLE: https://unpkg.com/imsc@1.1.0-beta.2/dist/
130
131
132
133TESTS AND SAMPLES
134=================
135
136
137W3C Test Suite
138--------------
139
140imscJS imports the [IMSC1 test suite](https://github.com/w3c/imsc-tests) as a submodule at `src/test/resources/imsc-tests`. The gen-renders.html web app can be used to generate PNG renderings as as well intermediary files from these tests.
141
142
143Unit tests
144----------
145
146Unit tests run using [QUnit](https://qunitjs.com/) are split between:
147
148* [src/test/webapp/js/unit-tests.js](src/test/webapp/js/unit-tests.js)
149* [src/test/js](src/test/js)
150
151
152NOTABLE DIRECTORIES AND FILES
153=============================
154
155* [package.json](package.json): NPM package definition
156
157* [Gruntfile.js](Gruntfile.js): Grunt build script
158
159* [properties.json](properties.json): General project properties
160
161* [LICENSE](LICENSE): License under which imscJS is made available
162
163* [src/main/js](src/main/js): JavaScript modules
164
165* [src/test](src/test): Test files
166
167* [dist](dist): Built libraries
168
169* [build/public_html](uild/public_html): Test web applications