eligius 1.1.1 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -274,7 +274,9 @@ engine.init().then(()=> {console.log('Eligius engine ready for business');});
274
274
 
275
275
  ## Configuration API
276
276
 
277
- Obviously having to type all of that JSON by hand can be a tad overwhelming and time consuming. Check out the [ConfigurationFactory](https://rolandzwaga.github.io/eligius/classes/ConfigurationFactory.html) for a strongly typed, fluent API to construct a configuration programmatically.
277
+ Obviously having to type all of that JSON by hand can be a tad overwhelming and time consuming. Check out the [ConfigurationFactory](https://rolandzwaga.github.io/eligius/classes/ConfigurationFactory.html) for a strongly typed, fluent and extensible API to construct a configuration programmatically.
278
+
279
+ It is encouraged to use this API to build specialized DSL's for specific presentations.
278
280
 
279
281
  ## Source documentation
280
282
 
@@ -7,7 +7,7 @@ import { TimelineProvidersSettingsEditor } from './timeline-provider-settings-ed
7
7
  export declare type TEngineConfigurationLists = Pick<IEngineConfiguration, 'availableLanguages' | 'initActions' | 'actions' | 'eventActions' | 'timelines' | 'labels'>;
8
8
  declare type ConfigurationFactoryExtension = (this: ConfigurationFactory, ...rest: any[]) => void;
9
9
  /**
10
- * This class offers a fluent and strongly typed DSL for creating Eligius configurations.
10
+ * This class offers a fluent, extensible and strongly typed DSL for creating Eligius configurations.
11
11
  *
12
12
  * @example Building a configuration using the factory
13
13
  * To initialize a basic configuration to start off of:
@@ -2,4 +2,6 @@ export * from './action-creator-factory';
2
2
  export * from './action-editor';
3
3
  export * from './configuration-factory';
4
4
  export * from './name-providers';
5
+ export * from './subtitle-converter';
6
+ export * from './subtitle-editor';
5
7
  export * from './timeline-provider-settings-editor';
@@ -0,0 +1,11 @@
1
+ import { IStrictDuration, ISubtitle } from '../../types';
2
+ /**
3
+ * This class converts an AVID subtitle file to an `ISubtitle` array.
4
+ */
5
+ export declare class SubtitleImporter {
6
+ importSubtitles(rawLines: string[]): ISubtitle[];
7
+ stripNewlineChars(str: string): string;
8
+ isValidLine(line: string): boolean;
9
+ convertDuration(time: string): IStrictDuration;
10
+ convertTimeToSeconds(time: string): number;
11
+ }
@@ -0,0 +1,14 @@
1
+ import { ISubtitle, ISubtitleCollection } from '../../types';
2
+ /**
3
+ * Used to edit and add to an {@link ISubtitleCollection}.
4
+ */
5
+ export declare class SubtitleEditor {
6
+ private collection;
7
+ constructor(collection?: ISubtitleCollection[]);
8
+ private _getLanguage;
9
+ addLanguage(languageCode: string): this;
10
+ addSubtitle(languageCode: string, subtitle: ISubtitle): this;
11
+ addSubtitles(subtitles: Record<string, ISubtitle>): this;
12
+ setSubtitle(languageCode: string, subtitle: ISubtitle): this;
13
+ export(): ISubtitleCollection[];
14
+ }
@@ -1,11 +1,11 @@
1
1
  /// <reference types="jquery" />
2
2
  import { IEventbus, TEventbusRemover } from '../eventbus/types';
3
- import { TOperationData } from '../operation/types';
3
+ import { ISubtitleCollection } from '../types';
4
4
  import { IController } from './types';
5
5
  export interface ISubtitlesControllerOperationData {
6
6
  selectedElement: JQuery;
7
7
  language: string;
8
- subtitleData: any;
8
+ subtitleData: ISubtitleCollection[];
9
9
  }
10
10
  export declare class SubtitlesController implements IController<ISubtitlesControllerOperationData> {
11
11
  actionLookup: Record<string, any>;
@@ -20,6 +20,6 @@ export declare class SubtitlesController implements IController<ISubtitlesContro
20
20
  onTimeHandler(position: number): void;
21
21
  onSeekedHandler(arg: any): void;
22
22
  setTitle(container: JQuery, titleLanguageLookup: Record<string, string>): void;
23
- createActionLookup(operationData: TOperationData, container: JQuery): Record<number, () => void>;
23
+ createActionLookup(operationData: ISubtitlesControllerOperationData, container: JQuery): Record<number, () => void>;
24
24
  init(operationData: ISubtitlesControllerOperationData): void;
25
25
  }
@@ -3498,7 +3498,7 @@ var TimelineProviderSettingsEditor = /*#__PURE__*/function () {
3498
3498
  }();
3499
3499
 
3500
3500
  /**
3501
- * This class offers a fluent and strongly typed DSL for creating Eligius configurations.
3501
+ * This class offers a fluent, extensible and strongly typed DSL for creating Eligius configurations.
3502
3502
  *
3503
3503
  * @example Building a configuration using the factory
3504
3504
  * To initialize a basic configuration to start off of:
@@ -4897,7 +4897,7 @@ var SubtitlesController = /*#__PURE__*/function () {
4897
4897
 
4898
4898
  for (var j = 0, jj = subtitleData.length; j < jj; j++) {
4899
4899
  var subs = subtitleData[j];
4900
- titleLanguageLookup[subs.lang] = subs.titles[i].text;
4900
+ titleLanguageLookup[subs.languageCode] = subs.titles[i].text;
4901
4901
  }
4902
4902
 
4903
4903
  subtitleTimeLookup[titles[i].duration.start] = this.setTitle.bind(this, container, titleLanguageLookup);
@@ -5613,6 +5613,187 @@ var TimeLineEventNamesProvider = /*#__PURE__*/function () {
5613
5613
  return TimeLineEventNamesProvider;
5614
5614
  }();
5615
5615
 
5616
+ /**
5617
+ * This class converts an AVID subtitle file to an `ISubtitle` array.
5618
+ */
5619
+ var SubtitleImporter = /*#__PURE__*/function () {
5620
+ function SubtitleImporter() {}
5621
+
5622
+ var _proto = SubtitleImporter.prototype;
5623
+
5624
+ _proto.importSubtitles = function importSubtitles(rawLines) {
5625
+ var _this = this;
5626
+
5627
+ var result = [];
5628
+ var lines = [];
5629
+
5630
+ for (var i = 0, l = rawLines.length; i < l; i++) {
5631
+ var rawLine = this.stripNewlineChars(rawLines[i].toString());
5632
+
5633
+ if (this.isValidLine(rawLine)) {
5634
+ lines.push(rawLine);
5635
+ }
5636
+ }
5637
+
5638
+ if (lines[0] === '') {
5639
+ lines.splice(0, 1);
5640
+ }
5641
+
5642
+ while (lines[lines.length - 1] === '') {
5643
+ lines.pop();
5644
+ }
5645
+
5646
+ var caption = null;
5647
+ lines.forEach(function (line) {
5648
+ if (line.length === 0 || !caption) {
5649
+ caption = {
5650
+ text: ''
5651
+ };
5652
+
5653
+ if (line.length) {
5654
+ //this happens for first caption only
5655
+ caption.duration = _this.convertDuration(line);
5656
+ }
5657
+
5658
+ result.push(caption);
5659
+ } else {
5660
+ if (!caption.hasOwnProperty('duration')) {
5661
+ caption.duration = _this.convertDuration(line);
5662
+ } else {
5663
+ caption.text += line;
5664
+ }
5665
+ }
5666
+ });
5667
+ return result;
5668
+ };
5669
+
5670
+ _proto.stripNewlineChars = function stripNewlineChars(str) {
5671
+ var res = '';
5672
+
5673
+ for (var i = 0, l = str.length; i < l; i++) {
5674
+ if (str.charCodeAt(i) !== 13 && str.charCodeAt(i) !== 0) {
5675
+ res += str.charAt(i);
5676
+ }
5677
+ }
5678
+
5679
+ return res;
5680
+ };
5681
+
5682
+ _proto.isValidLine = function isValidLine(line) {
5683
+ return !line.startsWith('@') && !line.startsWith('<begin subtitles>') && !line.startsWith('<end subtitles>');
5684
+ };
5685
+
5686
+ _proto.convertDuration = function convertDuration(time) {
5687
+ var times = time.split(' ');
5688
+ return {
5689
+ start: this.convertTimeToSeconds(times[0]),
5690
+ end: this.convertTimeToSeconds(times[1])
5691
+ };
5692
+ };
5693
+
5694
+ _proto.convertTimeToSeconds = function convertTimeToSeconds(time) {
5695
+ var parts = time.split(':');
5696
+ return parseInt(parts[0], 10) * 3600 + parseInt(parts[1], 10) * 60 + parseInt(parts[2], 10);
5697
+ };
5698
+
5699
+ return SubtitleImporter;
5700
+ }();
5701
+
5702
+ /**
5703
+ * Used to edit and add to an {@link ISubtitleCollection}.
5704
+ */
5705
+
5706
+ var SubtitleEditor = /*#__PURE__*/function () {
5707
+ function SubtitleEditor(collection) {
5708
+ if (collection === void 0) {
5709
+ collection = [];
5710
+ }
5711
+
5712
+ this.collection = void 0;
5713
+ this.collection = collection;
5714
+ }
5715
+
5716
+ var _proto = SubtitleEditor.prototype;
5717
+
5718
+ _proto._getLanguage = function _getLanguage(languageCode) {
5719
+ return this.collection.find(function (x) {
5720
+ return x.languageCode === languageCode;
5721
+ });
5722
+ };
5723
+
5724
+ _proto.addLanguage = function addLanguage(languageCode) {
5725
+ var language = this._getLanguage(languageCode);
5726
+
5727
+ if (language) {
5728
+ throw new Error("Language " + languageCode + " already exists.");
5729
+ }
5730
+
5731
+ var newLanguage = this.collection.length ? _extends({}, this.collection[0], {
5732
+ titles: this.collection[0].titles.map(function (x) {
5733
+ return {
5734
+ id: uuid.v4(),
5735
+ duration: _extends({}, x.duration),
5736
+ text: ''
5737
+ };
5738
+ })
5739
+ }) : {
5740
+ languageCode: languageCode,
5741
+ titles: []
5742
+ };
5743
+ this.collection.push(newLanguage);
5744
+ return this;
5745
+ };
5746
+
5747
+ _proto.addSubtitle = function addSubtitle(languageCode, subtitle) {
5748
+ var language = this._getLanguage(languageCode);
5749
+
5750
+ if (!language) {
5751
+ throw new Error("Language " + languageCode + " does not exist.");
5752
+ }
5753
+
5754
+ language.titles.push(subtitle);
5755
+ return this;
5756
+ };
5757
+
5758
+ _proto.addSubtitles = function addSubtitles(subtitles) {
5759
+ var _this = this;
5760
+
5761
+ Object.entries(subtitles).forEach(function (_ref) {
5762
+ var languageCode = _ref[0],
5763
+ subtitle = _ref[1];
5764
+ return _this.addSubtitle(languageCode, subtitle);
5765
+ });
5766
+ return this;
5767
+ };
5768
+
5769
+ _proto.setSubtitle = function setSubtitle(languageCode, subtitle) {
5770
+ var language = this._getLanguage(languageCode);
5771
+
5772
+ if (!language) {
5773
+ throw new Error("Language " + languageCode + " does not exist.");
5774
+ }
5775
+
5776
+ var titleIdx = language.titles.findIndex(function (x) {
5777
+ return x.id === subtitle.id;
5778
+ });
5779
+
5780
+ if (titleIdx < 0) {
5781
+ throw new Error("Subtitle with id '" + subtitle.id + "' was not found in language with code " + languageCode + ".");
5782
+ }
5783
+
5784
+ language.titles[titleIdx] = _extends({}, subtitle, {
5785
+ duration: _extends({}, subtitle.duration)
5786
+ });
5787
+ return this;
5788
+ };
5789
+
5790
+ _proto["export"] = function _export() {
5791
+ return this.collection;
5792
+ };
5793
+
5794
+ return SubtitleEditor;
5795
+ }();
5796
+
5616
5797
  /**
5617
5798
  * Gets the value for the given property chain. A property chain is defined by a period delimited string.
5618
5799
  *
@@ -7221,6 +7402,8 @@ exports.ProgressbarController = ProgressbarController;
7221
7402
  exports.RequestAnimationFrameTimelineProvider = RequestAnimationFrameTimelineProvider;
7222
7403
  exports.RequestVideoUriInterceptor = RequestVideoUriInterceptor;
7223
7404
  exports.RoutingController = RoutingController;
7405
+ exports.SubtitleEditor = SubtitleEditor;
7406
+ exports.SubtitleImporter = SubtitleImporter;
7224
7407
  exports.SubtitlesController = SubtitlesController;
7225
7408
  exports.TimeLineEventNamesProvider = TimeLineEventNamesProvider;
7226
7409
  exports.TimelineAction = TimelineAction;