1- import MyScript from 'myscript /dist/myscript .esm' ;
1+ import iink from 'iink-js /dist/iink .esm' ;
22
33// Creating a recognizer
4- const iinkRecognizer = MyScript . DefaultBehaviors . recognizerList . filter ( x => {
4+ const iinkRecognizer = iink . DefaultBehaviors . recognizerList . find ( x => {
55 const infos = x . getInfo ( ) ;
6- return infos . apiVersion === 'V4' && infos . protocol === 'REST' ;
6+ return infos . protocol === 'REST' ;
77} ) ;
88
99const convertBlobToBase64 = ( blob ) => new Promise ( ( resolve , reject ) => {
@@ -16,19 +16,19 @@ const convertBlobToBase64 = (blob) => new Promise((resolve, reject) => {
1616} ) ;
1717
1818
19- export function launchExportAndUpdateStore ( strokeGroups , type , mimeTypes , interpretationOptions , store ) {
20- launchExport ( strokeGroups , type , mimeTypes , interpretationOptions , buildStoreCallback ( store ) )
19+ export async function launchExportAndUpdateStore ( strokeGroups , type , mimeTypes , interpretationOptions , store ) {
20+ await launchExport ( strokeGroups , type , mimeTypes , interpretationOptions , buildStoreCallback ( store ) )
2121}
2222
23- export default function launchExport ( strokeGroups , type , mimeTypes , interpretationOptions , recognitionCallback ) {
23+ export default async function launchExport ( strokeGroups , type , mimeTypes , interpretationOptions , recognitionCallback ) {
2424 // Creating a empty model
25- const model = MyScript . InkModel . createModel ( ) ;
25+ const model = iink . InkModel . createModel ( ) ;
2626 // Filling the model with the stroke groups
2727 model . strokeGroups = strokeGroups ;
2828
2929 // Creating a recognizer context with the configuration attached
30- const recognizerContext = MyScript . RecognizerContext . createEmptyRecognizerContext ( {
31- configuration : MyScript . DefaultConfiguration
30+ const recognizerContext = iink . RecognizerContext . createEmptyRecognizerContext ( {
31+ configuration : iink . DefaultConfiguration
3232 } ) ;
3333
3434 const configuration = recognizerContext . editor . configuration ;
@@ -43,33 +43,42 @@ export default function launchExport(strokeGroups, type, mimeTypes, interpretati
4343
4444 configuration . recognitionParams . type = type ;
4545 configuration . recognitionParams . protocol = 'REST' ;
46- configuration . recognitionParams . v4 . lang = interpretationOptions . lang ;
46+ configuration . recognitionParams . iink . lang = interpretationOptions . lang ;
4747 configuration . recognitionParams . server = {
4848 scheme : 'https' ,
4949 host : 'webdemoapi.myscript.com' ,
5050 applicationKey : '515131ab-35fa-411c-bb4d-3917e00faf60' ,
5151 hmacKey : '54b2ca8a-6752-469d-87dd-553bb450e9ad'
5252 } ;
53- configuration . recognitionParams . v4 . export . jiix [ 'bounding-box' ] = interpretationOptions . jiixWithBoudingBox ;
54- configuration . recognitionParams . v4 . export . jiix . strokes = interpretationOptions . jiixWithStrokes ;
55- configuration . recognitionParams . v4 . export . jiix . text . chars = interpretationOptions . jiixWithChars ;
56- configuration . recognitionParams . v4 . export . jiix . text . words = interpretationOptions . jiixWithWords ;
57- configuration . recognitionParams . v4 [ 'raw-content' ] . recognition . text = interpretationOptions . textRecoOn ;
58- configuration . recognitionParams . v4 [ 'raw-content' ] . recognition . shape = interpretationOptions . shapeRecoOn ;
53+ configuration . recognitionParams . iink . export . jiix [ 'bounding-box' ] = interpretationOptions . jiixWithBoudingBox ;
54+ configuration . recognitionParams . iink . export . jiix . strokes = interpretationOptions . jiixWithStrokes ;
55+ configuration . recognitionParams . iink . export . jiix . text . chars = interpretationOptions . jiixWithChars ;
56+ configuration . recognitionParams . iink . export . jiix . text . words = interpretationOptions . jiixWithWords ;
57+ configuration . recognitionParams . iink [ 'raw-content' ] . recognition . text = interpretationOptions . textRecoOn ;
58+ configuration . recognitionParams . iink [ 'raw-content' ] . recognition . shape = interpretationOptions . shapeRecoOn ;
5959
6060
6161 // Assigning a theme to the document
6262 // FIXME The theme should not be attached to the recognizer context
6363 if ( interpretationOptions . styleshet ) {
6464 recognizerContext . editor . theme = interpretationOptions . styleshet ;
6565 } else {
66- recognizerContext . editor . theme = MyScript . DefaultTheme ;
66+ recognizerContext . editor . theme = iink . DefaultTheme ;
6767 }
6868
6969
7070
7171 // Triggering the recognition
72- iinkRecognizer [ 0 ] . export_ ( recognizerContext , model , recognitionCallback , mimeTypes ) ;
72+ try {
73+ const values = await iinkRecognizer . export_ ( recognizerContext , model , mimeTypes )
74+ if ( values ) {
75+ values . forEach ( ( value ) => {
76+ recognitionCallback ( undefined , value ) ;
77+ } )
78+ }
79+ } catch ( error ) {
80+ recognitionCallback ( error , undefined )
81+ }
7382}
7483
7584function buildStoreCallback ( store ) {
@@ -94,10 +103,10 @@ function buildStoreCallback(store){
94103 exportValue : exp
95104 } ) )
96105 } else {
97- store . commit ( 'persistExportResult' , {
98- type : mimeType ,
99- exportValue : exportValue
100- } )
106+ store . commit ( 'persistExportResult' , {
107+ type : mimeType ,
108+ exportValue : exportValue
109+ } )
101110 }
102111 } )
103112 }
0 commit comments