-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4cc5299
commit 36dcd21
Showing
279 changed files
with
34,549 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,206 @@ | ||
{ | ||
"$schema": "./node_modules/@angular/cli/lib/config/schema.json", | ||
"version": 1, | ||
"newProjectRoot": "projects", | ||
"projects": { | ||
"sunbird-collection-editor": { | ||
"root": "", | ||
"sourceRoot": "src", | ||
"projectType": "application", | ||
"prefix": "app", | ||
"schematics": { | ||
"@schematics/angular:component": { | ||
"style": "scss" | ||
} | ||
}, | ||
"architect": { | ||
"build": { | ||
"builder": "@angular-devkit/build-angular:browser", | ||
"options": { | ||
"outputPath": "dist/sunbird-collection-editor", | ||
"index": "src/index.html", | ||
"main": "src/main.ts", | ||
"polyfills": "src/polyfills.ts", | ||
"tsConfig": "src/tsconfig.app.json", | ||
"assets": [ | ||
"src/assets", | ||
"src/assets/images", | ||
"src/favicon.ico", | ||
{ | ||
"glob": "**/*", | ||
"input": "./node_modules/@project-sunbird/sunbird-pdf-player-v8/lib/assets/", | ||
"output": "/assets/" | ||
}, | ||
{ | ||
"glob": "**/*", | ||
"input": "node_modules/@project-sunbird/sunbird-video-player-v8/lib/assets/", | ||
"output": "/assets/" | ||
} | ||
], | ||
"styles": [ | ||
"src/styles.scss", | ||
"src/assets/lib/semantic/semantic.min.css", | ||
"src/assets/styles/styles.scss", | ||
"node_modules/font-awesome/css/font-awesome.css", | ||
"node_modules/video.js/dist/video-js.min.css", | ||
"node_modules/@project-sunbird/sb-styles/assets/_styles.scss" | ||
], | ||
"scripts": [ | ||
"node_modules/jquery/dist/jquery.min.js", | ||
"node_modules/jquery.fancytree/dist/jquery.fancytree-all-deps.min.js", | ||
"src/assets/lib/dimmer.min.js", | ||
"src/assets/lib/transition.min.js", | ||
"src/assets/lib/modal.min.js", | ||
"src/assets/lib/semantic-ui-tree-picker.js", | ||
"node_modules/@project-sunbird/telemetry-sdk/index.js", | ||
"node_modules/@project-sunbird/client-services/index.js" | ||
], | ||
"es5BrowserSupport": true | ||
}, | ||
"configurations": { | ||
"production": { | ||
"fileReplacements": [ | ||
{ | ||
"replace": "src/environments/environment.ts", | ||
"with": "src/environments/environment.prod.ts" | ||
} | ||
], | ||
"optimization": true, | ||
"outputHashing": "all", | ||
"sourceMap": false, | ||
"extractCss": true, | ||
"namedChunks": false, | ||
"aot": true, | ||
"extractLicenses": true, | ||
"vendorChunk": false, | ||
"buildOptimizer": true, | ||
"budgets": [ | ||
{ | ||
"type": "initial", | ||
"maximumWarning": "2mb", | ||
"maximumError": "5mb" | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
"serve": { | ||
"builder": "@angular-devkit/build-angular:dev-server", | ||
"options": { | ||
"browserTarget": "sunbird-collection-editor:build", | ||
"proxyConfig": "proxy.conf.json" | ||
}, | ||
"configurations": { | ||
"production": { | ||
"browserTarget": "sunbird-collection-editor:build:production" | ||
} | ||
} | ||
}, | ||
"extract-i18n": { | ||
"builder": "@angular-devkit/build-angular:extract-i18n", | ||
"options": { | ||
"browserTarget": "sunbird-collection-editor:build" | ||
} | ||
}, | ||
"test": { | ||
"builder": "@angular-devkit/build-angular:karma", | ||
"options": { | ||
"main": "src/test.ts", | ||
"polyfills": "src/polyfills.ts", | ||
"tsConfig": "src/tsconfig.spec.json", | ||
"karmaConfig": "src/karma.conf.js", | ||
"styles": [ | ||
"src/styles.scss" | ||
], | ||
"scripts": [], | ||
"assets": [ | ||
"src/favicon.ico", | ||
"src/assets" | ||
] | ||
} | ||
}, | ||
"lint": { | ||
"builder": "@angular-devkit/build-angular:tslint", | ||
"options": { | ||
"tsConfig": [ | ||
"src/tsconfig.app.json", | ||
"src/tsconfig.spec.json" | ||
], | ||
"exclude": [ | ||
"**/node_modules/**" | ||
] | ||
} | ||
} | ||
} | ||
}, | ||
"sunbird-collection-editor-e2e": { | ||
"root": "e2e/", | ||
"projectType": "application", | ||
"prefix": "", | ||
"architect": { | ||
"e2e": { | ||
"builder": "@angular-devkit/build-angular:protractor", | ||
"options": { | ||
"protractorConfig": "e2e/protractor.conf.js", | ||
"devServerTarget": "sunbird-collection-editor:serve" | ||
}, | ||
"configurations": { | ||
"production": { | ||
"devServerTarget": "sunbird-collection-editor:serve:production" | ||
} | ||
} | ||
}, | ||
"lint": { | ||
"builder": "@angular-devkit/build-angular:tslint", | ||
"options": { | ||
"tsConfig": "e2e/tsconfig.e2e.json", | ||
"exclude": [ | ||
"**/node_modules/**" | ||
] | ||
} | ||
} | ||
} | ||
}, | ||
"collection-editor-library": { | ||
"root": "projects/collection-editor-library", | ||
"sourceRoot": "projects/collection-editor-library/src", | ||
"projectType": "library", | ||
"prefix": "lib", | ||
"architect": { | ||
"build": { | ||
"builder": "@angular-devkit/build-ng-packagr:build", | ||
"options": { | ||
"tsConfig": "projects/collection-editor-library/tsconfig.lib.json", | ||
"project": "projects/collection-editor-library/ng-package.json" | ||
}, | ||
"configurations": { | ||
"production": { | ||
"project": "projects/course-editor-library/ng-package.prod.json" | ||
} | ||
} | ||
}, | ||
"test": { | ||
"builder": "@angular-devkit/build-angular:karma", | ||
"options": { | ||
"main": "projects/collection-editor-library/src/test.ts", | ||
"tsConfig": "projects/collection-editor-library/tsconfig.spec.json", | ||
"karmaConfig": "projects/collection-editor-library/karma.conf.js" | ||
} | ||
}, | ||
"lint": { | ||
"builder": "@angular-devkit/build-angular:tslint", | ||
"options": { | ||
"tsConfig": [ | ||
"projects/collection-editor-library/tsconfig.lib.json", | ||
"projects/collection-editor-library/tsconfig.spec.json" | ||
], | ||
"exclude": [ | ||
"**/node_modules/**" | ||
] | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"defaultProject": "sunbird-collection-editor" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Protractor configuration file, see link for more information | ||
// https://github.com/angular/protractor/blob/master/lib/config.ts | ||
|
||
const { SpecReporter } = require('jasmine-spec-reporter'); | ||
|
||
exports.config = { | ||
allScriptsTimeout: 11000, | ||
specs: [ | ||
'./src/**/*.e2e-spec.ts' | ||
], | ||
capabilities: { | ||
'browserName': 'chrome' | ||
}, | ||
directConnect: true, | ||
baseUrl: 'http://localhost:4200/', | ||
framework: 'jasmine', | ||
jasmineNodeOpts: { | ||
showColors: true, | ||
defaultTimeoutInterval: 30000, | ||
print: function() {} | ||
}, | ||
onPrepare() { | ||
require('ts-node').register({ | ||
project: require('path').join(__dirname, './tsconfig.e2e.json') | ||
}); | ||
jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { AppPage } from './app.po'; | ||
import { browser, logging } from 'protractor'; | ||
|
||
describe('workspace-project App', () => { | ||
let page: AppPage; | ||
|
||
beforeEach(() => { | ||
page = new AppPage(); | ||
}); | ||
|
||
it('should display welcome message', () => { | ||
page.navigateTo(); | ||
expect(page.getTitleText()).toEqual('Welcome to sunbird-collection-editor!'); | ||
}); | ||
|
||
afterEach(async () => { | ||
// Assert that there are no errors emitted from the browser | ||
const logs = await browser.manage().logs().get(logging.Type.BROWSER); | ||
expect(logs).not.toContain(jasmine.objectContaining({ | ||
level: logging.Level.SEVERE, | ||
} as logging.Entry)); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { browser, by, element } from 'protractor'; | ||
|
||
export class AppPage { | ||
navigateTo() { | ||
return browser.get(browser.baseUrl) as Promise<any>; | ||
} | ||
|
||
getTitleText() { | ||
return element(by.css('app-root h1')).getText() as Promise<string>; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"extends": "../tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "../out-tsc/app", | ||
"module": "commonjs", | ||
"target": "es5", | ||
"types": [ | ||
"jasmine", | ||
"jasminewd2", | ||
"node" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
const async = require('async'); | ||
const mathjax = require("mathjax-full/js/mathjax"); | ||
const TeX = require("mathjax-full/js/input/tex"); | ||
const SVG = require("mathjax-full/js/output/svg"); | ||
const LiteAdaptor = require("mathjax-full/js/adaptors/liteAdaptor"); | ||
const RegisterHTMLHandler = require("mathjax-full/js/handlers/html"); | ||
const AllPackages = require("mathjax-full/js/input/tex/AllPackages"); | ||
const svg2img = require("svg2img"); | ||
const fs = require('fs'); | ||
|
||
const adaptor = new LiteAdaptor.LiteAdaptor(); | ||
RegisterHTMLHandler.RegisterHTMLHandler(adaptor); | ||
|
||
const html = mathjax.mathjax.document("", { | ||
InputJax: new TeX.TeX({ packages: AllPackages.AllPackages }), | ||
OutputJax: new SVG.SVG({ fontCache: "none" }) | ||
}); | ||
|
||
|
||
function tex2svg(equation, color) { | ||
const svg = adaptor | ||
.innerHTML(html.convert(equation, { display: true })) | ||
.replace(/fill="currentColor"/, `fill="${color}"`); | ||
if (svg.includes("merror")) { | ||
return svg.replace(/<rect.+?><\/rect>/, ""); | ||
} | ||
return svg; | ||
} | ||
|
||
function svg2png(svgString) { | ||
return new Promise(function (resolve, reject) { | ||
var dims = svgString | ||
.match(/width="([\d.]+)ex" height="([\d.]+)ex"/) | ||
.slice(1) | ||
.map(function (s) { return parseFloat(s); }), width = dims[0], height = dims[1]; | ||
var args = { | ||
width: width * 3 + "ex", | ||
height: height * 3 + "ex" | ||
}; | ||
svg2img(svgString, args, function(error, buffer) { | ||
if (error) { | ||
return reject(error); | ||
} | ||
resolve(buffer); | ||
}); | ||
}); | ||
} | ||
|
||
function png2base64(pngString) { | ||
var base64Image = new Buffer(pngString, 'binary').toString('base64'); | ||
return 'data:image/png;base64,'+base64Image; | ||
} | ||
|
||
async function convert(req, res) { | ||
let equation = req.query.equation; | ||
if (!equation) { | ||
equation = req.body.equation; | ||
} | ||
if (!equation) { | ||
res.status(400).send('Bad Request'); | ||
} else { | ||
let color = "black"; | ||
const isPNG = /\.png$/.test(equation); | ||
const normalizedEquation = equation.replace(/\.(svg|png)$/, ""); | ||
const svgString = tex2svg(normalizedEquation, color); | ||
let imageData = svgString; | ||
res.setHeader("cache-control", "s-maxage=604800, maxage=604800"); | ||
// render equation | ||
if (isPNG) { | ||
imageData = await svg2png(svgString); | ||
const base64Image = await png2base64(imageData); | ||
res.contentType("application/json"); | ||
imageData = { 'data': base64Image }; | ||
res.send(imageData); | ||
} else { | ||
res.contentType("image/svg+xml"); | ||
res.write(`<?xml version="1.0" standalone="no" ?> | ||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"> | ||
`); | ||
res.end(imageData); | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
module.exports.convert = convert | ||
module.exports.tex2svg = tex2svg | ||
module.exports.svg2png = svg2png |
Oops, something went wrong.