├── .circleci └── config.yml ├── .editorconfig ├── .gitignore ├── .vscode └── launch.json ├── LICENSE ├── README.md ├── angular.json ├── ci ├── package.py └── utils.py ├── e2e ├── protractor.conf.js ├── src │ ├── app.e2e-spec.ts │ └── app.po.ts └── tsconfig.e2e.json ├── package-lock.json ├── package.json ├── src ├── app │ ├── app.component.html │ ├── app.component.scss │ ├── app.component.ts │ ├── app.module.ts │ ├── app.routes.ts │ ├── classes │ │ ├── matrix.ts │ │ ├── operator.ts │ │ └── vector.ts │ ├── components │ │ ├── connection.component.svg.html │ │ ├── connection.component.ts │ │ ├── editor-debug-panel.component.html │ │ ├── editor-debug-panel.component.scss │ │ ├── editor-debug-panel.component.ts │ │ ├── editor-sidebar.component.html │ │ ├── editor-sidebar.component.scss │ │ ├── editor-sidebar.component.ts │ │ ├── editor.component.html │ │ ├── editor.component.scss │ │ ├── editor.component.ts │ │ ├── index.component.html │ │ ├── index.component.scss │ │ ├── index.component.ts │ │ ├── instance.component.svg.html │ │ ├── instance.component.ts │ │ ├── operator-list.component.html │ │ ├── operator-list.component.scss │ │ ├── operator-list.component.ts │ │ ├── port.component.svg.html │ │ ├── port.component.ts │ │ ├── preview-object.component.html │ │ ├── preview-object.component.scss │ │ ├── preview-object.component.ts │ │ ├── type-def-form.component.html │ │ ├── type-def-form.component.scss │ │ ├── type-def-form.component.ts │ │ ├── type-value-form.component.html │ │ ├── type-value-form.component.scss │ │ └── type-value-form.component.ts │ ├── initial-def.json │ ├── services │ │ ├── api.service.ts │ │ ├── broadcast.service.ts │ │ ├── mouse.service.ts │ │ ├── operator.service.ts │ │ └── visual.service.ts │ └── utils.ts ├── assets │ ├── .gitkeep │ └── brand │ │ ├── logo_star.png │ │ └── logo_star_inv.png ├── browserslist ├── environments │ ├── environment.prod.ts │ └── environment.ts ├── favicon.ico ├── index.html ├── json-typings.d.ts ├── karma.conf.js ├── main.ts ├── navigator.clipboard.d.ts ├── polyfills.ts ├── styles │ ├── _dark.scss │ ├── _light.scss │ ├── main.scss │ ├── operator.scss │ └── variables.scss ├── test.ts ├── tsconfig.app.json ├── tsconfig.spec.json └── tslint.json ├── tsconfig.json └── tslint.json /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | jobs: 3 | build: 4 | docker: 5 | - image: bitspark/slang-ci:latest 6 | working_directory: ~/slang-ui 7 | steps: 8 | - checkout 9 | - restore_cache: 10 | keys: 11 | - v1-dependencies-{{ checksum "package.json" }} 12 | - v1-dependencies- 13 | - run: 14 | name: Install 15 | command: | 16 | npm install 17 | npm install -g @angular/cli@latest 18 | - save_cache: 19 | paths: 20 | - node_modules 21 | key: v1-dependencies-{{ checksum "package.json" }} 22 | - run: 23 | name: Build 24 | command: ng build --base-href /app/ --prod --output-path=dist 25 | - persist_to_workspace: 26 | root: ~/slang-ui 27 | paths: 28 | - dist 29 | release: 30 | docker: 31 | - image: bitspark/slang-ci:latest 32 | working_directory: ~/slang-ui 33 | steps: 34 | - checkout 35 | - attach_workspace: 36 | at: ~/slang-ui 37 | - run: 38 | name: Package 39 | command: | 40 | python3 ./ci/package.py ${CIRCLE_TAG} 41 | - run: 42 | name: Release 43 | command: ${GOPATH}/bin/ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} ${CIRCLE_TAG} ./ci/release/ 44 | workflows: 45 | version: 2 46 | build-and-release: 47 | jobs: 48 | - build: 49 | filters: 50 | tags: 51 | only: /.*/ 52 | - release: 53 | requires: 54 | - build 55 | filters: 56 | branches: 57 | ignore: /.*/ 58 | tags: 59 | only: /^v.*/ 60 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | max_line_length = off 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | /out-tsc 7 | 8 | # dependencies 9 | /node_modules 10 | 11 | # IDEs and editors 12 | /.idea 13 | .project 14 | .classpath 15 | .c9/ 16 | *.launch 17 | .settings/ 18 | *.sublime-workspace 19 | 20 | # IDE - VSCode 21 | .vscode/* 22 | !.vscode/settings.json 23 | !.vscode/tasks.json 24 | !.vscode/launch.json 25 | !.vscode/extensions.json 26 | 27 | # misc 28 | /.sass-cache 29 | /connect.lock 30 | /coverage 31 | /libpeerconnection.log 32 | npm-debug.log 33 | yarn-error.log 34 | testem.log 35 | /typings 36 | 37 | # System Files 38 | .DS_Store 39 | Thumbs.db 40 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "pwa-node", 9 | "request": "launch", 10 | "name": "Launch Program", 11 | "skipFiles": [ 12 | "/**" 13 | ], 14 | "program": "${file}" 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2018 Bitspark UG (haftungsbeschränkt)) 190 | 191 | Website: www.bitspark.de 192 | Email: info@bitspark.de 193 | 194 | Licensed under the Apache License, Version 2.0 (the "License"); 195 | you may not use this file except in compliance with the License. 196 | You may obtain a copy of the License at 197 | 198 | http://www.apache.org/licenses/LICENSE-2.0 199 | 200 | Unless required by applicable law or agreed to in writing, software 201 | distributed under the License is distributed on an "AS IS" BASIS, 202 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 203 | See the License for the specific language governing permissions and 204 | limitations under the License. 205 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![CircleCI](https://circleci.com/gh/Bitspark/slang-ui/tree/master.svg?style=svg&circle-token=18bfe412b89c2c92e28e339126829e31451d4ee1)](https://circleci.com/gh/Bitspark/slang-ui/tree/master) 2 | 3 | # Slang UI 4 | 5 |

6 | 7 |

8 | 9 | *Powered by [Bitspark](https://bitspark.de)* 10 | 11 | ## About 12 | 13 | Slang is a visual flow-based programming language and programming system. It consists of the YAML-based Slang exchange format, the [Slang daemon](https://github.com/Bitspark/slang) and the **Slang UI**. Visit [TrySlang.com](http://tryslang.com) for more information. 14 | 15 | ## Links 16 | 17 | - [TrySlang website](http://tryslang.com) 18 | - [Slang daemon repository](https://github.com/Bitspark/slang) 19 | - [Bitspark website](https://bitspark.de) 20 | -------------------------------------------------------------------------------- /angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "version": 1, 4 | "newProjectRoot": "projects", 5 | "projects": { 6 | "slang-ui": { 7 | "root": "", 8 | "sourceRoot": "src", 9 | "projectType": "application", 10 | "prefix": "app", 11 | "schematics": { 12 | "@schematics/angular:component": { 13 | "styleext": "scss" 14 | } 15 | }, 16 | "architect": { 17 | "build": { 18 | "builder": "@angular-devkit/build-angular:browser", 19 | "options": { 20 | "outputPath": "dist/slang-ui", 21 | "index": "src/index.html", 22 | "main": "src/main.ts", 23 | "polyfills": "src/polyfills.ts", 24 | "tsConfig": "src/tsconfig.app.json", 25 | "assets": [ 26 | "src/favicon.ico", 27 | "src/assets" 28 | ], 29 | "styles": [ 30 | "src/styles/main.scss" 31 | ], 32 | "scripts": [] 33 | }, 34 | "configurations": { 35 | "production": { 36 | "fileReplacements": [ 37 | { 38 | "replace": "src/environments/environment.ts", 39 | "with": "src/environments/environment.prod.ts" 40 | } 41 | ], 42 | "optimization": true, 43 | "outputHashing": "all", 44 | "sourceMap": false, 45 | "extractCss": true, 46 | "namedChunks": false, 47 | "aot": true, 48 | "extractLicenses": true, 49 | "vendorChunk": false, 50 | "buildOptimizer": true 51 | } 52 | } 53 | }, 54 | "serve": { 55 | "builder": "@angular-devkit/build-angular:dev-server", 56 | "options": { 57 | "browserTarget": "slang-ui:build" 58 | }, 59 | "configurations": { 60 | "production": { 61 | "browserTarget": "slang-ui:build:production" 62 | } 63 | } 64 | }, 65 | "extract-i18n": { 66 | "builder": "@angular-devkit/build-angular:extract-i18n", 67 | "options": { 68 | "browserTarget": "slang-ui:build" 69 | } 70 | }, 71 | "test": { 72 | "builder": "@angular-devkit/build-angular:karma", 73 | "options": { 74 | "main": "src/test.ts", 75 | "polyfills": "src/polyfills.ts", 76 | "tsConfig": "src/tsconfig.spec.json", 77 | "karmaConfig": "src/karma.conf.js", 78 | "styles": [ 79 | "styles/main.scss" 80 | ], 81 | "scripts": [], 82 | "assets": [ 83 | "src/favicon.ico", 84 | "src/assets" 85 | ] 86 | } 87 | }, 88 | "lint": { 89 | "builder": "@angular-devkit/build-angular:tslint", 90 | "options": { 91 | "tsConfig": [ 92 | "src/tsconfig.app.json", 93 | "src/tsconfig.spec.json" 94 | ], 95 | "exclude": [ 96 | "**/node_modules/**" 97 | ] 98 | } 99 | } 100 | } 101 | }, 102 | "slang-ui-e2e": { 103 | "root": "e2e/", 104 | "projectType": "application", 105 | "architect": { 106 | "e2e": { 107 | "builder": "@angular-devkit/build-angular:protractor", 108 | "options": { 109 | "protractorConfig": "e2e/protractor.conf.js", 110 | "devServerTarget": "slang-ui:serve" 111 | } 112 | }, 113 | "lint": { 114 | "builder": "@angular-devkit/build-angular:tslint", 115 | "options": { 116 | "tsConfig": "e2e/tsconfig.e2e.json", 117 | "exclude": [ 118 | "**/node_modules/**" 119 | ] 120 | } 121 | } 122 | } 123 | } 124 | }, 125 | "defaultProject": "slang-ui" 126 | } 127 | -------------------------------------------------------------------------------- /ci/package.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from utils import execute_commands 3 | 4 | name = 'PACKAGE' 5 | 6 | if __name__ == '__main__': 7 | if len(sys.argv) != 2: 8 | print('Usage: python3 package.py vx.y.z') 9 | exit(-1) 10 | 11 | versioned_dist = 'slang-ui-' + sys.argv[1].replace('.', '_') 12 | 13 | print(f'Step: {name}') 14 | execute_commands([ 15 | 'mkdir ci/release', 16 | f'mv dist {versioned_dist}', 17 | f'zip -r ci/release/{versioned_dist}.zip {versioned_dist}', 18 | # f'tar -zcvf ci/{versioned_dist}.zip {versioned_dist}', 19 | ]) 20 | -------------------------------------------------------------------------------- /ci/utils.py: -------------------------------------------------------------------------------- 1 | from os import system 2 | 3 | def execute_commands(cmds, fail=True): 4 | for cmd in cmds: 5 | print(f'>>> {cmd}') 6 | code = system(cmd) 7 | if code < 0 and fail: 8 | exit(code) 9 | -------------------------------------------------------------------------------- /e2e/protractor.conf.js: -------------------------------------------------------------------------------- 1 | // Protractor configuration file, see link for more information 2 | // https://github.com/angular/protractor/blob/master/lib/config.ts 3 | 4 | const { SpecReporter } = require('jasmine-spec-reporter'); 5 | 6 | exports.config = { 7 | allScriptsTimeout: 11000, 8 | specs: [ 9 | './src/**/*.e2e-spec.ts' 10 | ], 11 | capabilities: { 12 | 'browserName': 'chrome' 13 | }, 14 | directConnect: true, 15 | baseUrl: 'http://localhost:4200/', 16 | framework: 'jasmine', 17 | jasmineNodeOpts: { 18 | showColors: true, 19 | defaultTimeoutInterval: 30000, 20 | print: function() {} 21 | }, 22 | onPrepare() { 23 | require('ts-node').register({ 24 | project: require('path').join(__dirname, './tsconfig.e2e.json') 25 | }); 26 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); 27 | } 28 | }; -------------------------------------------------------------------------------- /e2e/src/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { AppPage } from './app.po'; 2 | 3 | describe('workspace-project App', () => { 4 | let page: AppPage; 5 | 6 | beforeEach(() => { 7 | page = new AppPage(); 8 | }); 9 | 10 | it('should display welcome message', () => { 11 | page.navigateTo(); 12 | expect(page.getParagraphText()).toEqual('Welcome to app!'); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /e2e/src/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, by, element } from 'protractor'; 2 | 3 | export class AppPage { 4 | navigateTo() { 5 | return browser.get('/'); 6 | } 7 | 8 | getParagraphText() { 9 | return element(by.css('app-root h1')).getText(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /e2e/tsconfig.e2e.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/app", 5 | "module": "commonjs", 6 | "target": "es5", 7 | "types": [ 8 | "jasmine", 9 | "jasminewd2", 10 | "node" 11 | ] 12 | } 13 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "slang-ui", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "ng": "ng", 6 | "start": "ng serve", 7 | "build": "ng build --base-href /app/ --prod --output-path dist", 8 | "test": "ng test", 9 | "lint": "ng lint", 10 | "e2e": "ng e2e" 11 | }, 12 | "private": true, 13 | "dependencies": { 14 | "@angular/animations": "^6.1.0", 15 | "@angular/common": "^6.1.0", 16 | "@angular/compiler": "^6.1.0", 17 | "@angular/core": "^6.1.0", 18 | "@angular/forms": "^6.1.0", 19 | "@angular/http": "^6.1.0", 20 | "@angular/platform-browser": "^6.1.0", 21 | "@angular/platform-browser-dynamic": "^6.1.0", 22 | "@angular/router": "^6.1.0", 23 | "@ng-bootstrap/ng-bootstrap": "^2.1.0", 24 | "@types/js-yaml": "^3.11.1", 25 | "bootstrap": "^4.1.1", 26 | "core-js": "^2.5.4", 27 | "deep-equal": "^1.0.1", 28 | "js-yaml": "^3.11.0", 29 | "ng2-codemirror": "^1.1.3", 30 | "ng2-file-upload": "^1.3.0", 31 | "rxjs": "^6.1.0", 32 | "zone.js": "^0.8.26" 33 | }, 34 | "devDependencies": { 35 | "@angular-devkit/build-angular": "~0.6.0", 36 | "@angular/cli": "~6.1.0", 37 | "@angular/compiler-cli": "^6.1.0", 38 | "@angular/language-service": "^6.1.0", 39 | "@types/jasmine": "~2.8.6", 40 | "@types/jasminewd2": "~2.0.3", 41 | "@types/node": "~8.9.4", 42 | "codelyzer": "~4.2.1", 43 | "jasmine-core": "~2.99.1", 44 | "jasmine-spec-reporter": "~4.2.1", 45 | "karma": "~1.7.1", 46 | "karma-chrome-launcher": "~2.2.0", 47 | "karma-coverage-istanbul-reporter": "~1.4.2", 48 | "karma-jasmine": "~1.1.1", 49 | "karma-jasmine-html-reporter": "^0.2.2", 50 | "node-sass": "^4.9.0", 51 | "protractor": "~5.3.0", 52 | "ts-node": "~5.0.1", 53 | "tslint": "~5.9.1", 54 | "typescript": "~2.7.2" 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/app/app.component.html: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/app/app.component.scss: -------------------------------------------------------------------------------- 1 | @import "../styles/variables.scss"; 2 | 3 | .navbar { 4 | .navbar-brand { 5 | padding: 0; 6 | img { 7 | height: 30px; 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import {Component} from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-root', 5 | templateUrl: './app.component.html', 6 | styleUrls: ['./app.component.scss'] 7 | }) 8 | export class AppComponent { 9 | } 10 | -------------------------------------------------------------------------------- /src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import {NgModule} from '@angular/core'; 2 | import {RouterModule} from '@angular/router'; 3 | import {BrowserModule} from '@angular/platform-browser'; 4 | import {FormsModule} from '@angular/forms'; 5 | import {HttpClientModule} from '@angular/common/http'; 6 | import {CodemirrorModule} from 'ng2-codemirror'; 7 | import {FileUploadModule} from 'ng2-file-upload'; 8 | 9 | import {AppRoutes} from './app.routes'; 10 | 11 | import {AppComponent} from './app.component'; 12 | import {IndexComponent} from './components/index.component'; 13 | import {EditorComponent} from './components/editor.component'; 14 | import {OperatorListComponent} from './components/operator-list.component'; 15 | import {InstanceComponent} from './components/instance.component'; 16 | import {PortComponent} from './components/port.component'; 17 | import {ConnectionComponent} from './components/connection.component'; 18 | import {TypeDefFormComponent} from './components/type-def-form.component'; 19 | import {TypeValueFormComponent} from './components/type-value-form.component'; 20 | import {PreviewObjectComponent} from './components/preview-object.component'; 21 | import {EditorSidebarComponent} from './components/editor-sidebar.component'; 22 | import {EditorDebugPanelComponent} from './components/editor-debug-panel.component'; 23 | 24 | 25 | import {ApiService} from './services/api.service'; 26 | import {OperatorService} from './services/operator.service'; 27 | import {VisualService} from './services/visual.service'; 28 | import {MouseService} from './services/mouse.service'; 29 | import {BroadcastService} from './services/broadcast.service'; 30 | 31 | import {NgbModule} from '@ng-bootstrap/ng-bootstrap'; 32 | import {BrowserAnimationsModule} from '@angular/platform-browser/animations'; 33 | 34 | @NgModule({ 35 | declarations: [ 36 | AppComponent, IndexComponent, TypeDefFormComponent, TypeValueFormComponent, 37 | OperatorListComponent, EditorComponent, InstanceComponent, PortComponent, ConnectionComponent, 38 | PreviewObjectComponent, EditorSidebarComponent, EditorDebugPanelComponent 39 | ], 40 | imports: [ 41 | NgbModule.forRoot(), 42 | RouterModule.forRoot( 43 | AppRoutes, 44 | {enableTracing: false} 45 | ), 46 | BrowserModule, 47 | BrowserAnimationsModule, 48 | FormsModule, 49 | HttpClientModule, 50 | CodemirrorModule, 51 | FileUploadModule 52 | ], 53 | providers: [ApiService, OperatorService, VisualService, MouseService, BroadcastService], 54 | bootstrap: [AppComponent] 55 | }) 56 | export class AppModule { 57 | } 58 | -------------------------------------------------------------------------------- /src/app/app.routes.ts: -------------------------------------------------------------------------------- 1 | import {Routes} from '@angular/router'; 2 | import {IndexComponent} from './components/index.component'; 3 | import {EditorComponent} from './components/editor.component'; 4 | 5 | export const AppRoutes: Routes = [ 6 | {path: '', component: IndexComponent}, 7 | {path: 'operator/:operatorId', component: EditorComponent} 8 | ]; 9 | -------------------------------------------------------------------------------- /src/app/classes/matrix.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @fileoverview TSM - A TypeScript vector and matrix math library 3 | * @author Matthias Ferch 4 | * @version 0.6 5 | */ 6 | 7 | /* 8 | * Copyright (c) 2012 Matthias Ferch 9 | * 10 | * Project homepage: https://github.com/matthiasferch/tsm 11 | * 12 | * This software is provided 'as-is', without any express or implied 13 | * warranty. In no event will the authors be held liable for any damages 14 | * arising from the use of this software. 15 | * 16 | * Permission is granted to anyone to use this software for any purpose, 17 | * including commercial applications, and to alter it and redistribute it 18 | * freely, subject to the following restrictions: 19 | * 20 | * 1. The origin of this software must not be misrepresented; you must not 21 | * claim that you wrote the original software. If you use this software 22 | * in a product, an acknowledgment in the product documentation would be 23 | * appreciated but is not required. 24 | * 25 | * 2. Altered source versions must be plainly marked as such, and must not 26 | * be misrepresented as being the original software. 27 | * 28 | * 3. This notice may not be removed or altered from any source 29 | * distribution. 30 | */ 31 | 32 | const EPSILON = 0.00001; 33 | 34 | export class Mat2 { 35 | static identity = new Mat2().setIdentity(); 36 | 37 | private values = new Float32Array(4); 38 | 39 | constructor(values: number[] = null) { 40 | if (values) { 41 | this.init(values); 42 | } 43 | } 44 | 45 | static product(m1: Mat2, m2: Mat2, result: Mat2 = null): Mat2 { 46 | const a11 = m1.at(0), 47 | a12 = m1.at(1), 48 | a21 = m1.at(2), 49 | a22 = m1.at(3); 50 | 51 | if (result) { 52 | result.init([ 53 | a11 * m2.at(0) + a12 * m2.at(2), 54 | a11 * m2.at(1) + a12 * m2.at(3), 55 | a21 * m2.at(0) + a22 * m2.at(2), 56 | a21 * m2.at(1) + a22 * m2.at(3) 57 | ]); 58 | 59 | return result; 60 | } else { 61 | return new Mat2([ 62 | a11 * m2.at(0) + a12 * m2.at(2), 63 | a11 * m2.at(1) + a12 * m2.at(3), 64 | a21 * m2.at(0) + a22 * m2.at(2), 65 | a21 * m2.at(1) + a22 * m2.at(3) 66 | ]); 67 | } 68 | } 69 | 70 | at(index: number): number { 71 | return this.values[index]; 72 | } 73 | 74 | init(values: number[]): Mat2 { 75 | for (let i = 0; i < 4; i++) { 76 | this.values[i] = values[i]; 77 | } 78 | 79 | return this; 80 | } 81 | 82 | reset(): void { 83 | for (let i = 0; i < 4; i++) { 84 | this.values[i] = 0; 85 | } 86 | } 87 | 88 | copy(dest: Mat2 = null): Mat2 { 89 | if (!dest) { 90 | dest = new Mat2(); 91 | } 92 | 93 | for (let i = 0; i < 4; i++) { 94 | dest.values[i] = this.values[i]; 95 | } 96 | 97 | return dest; 98 | } 99 | 100 | all(): number[] { 101 | const data: number[] = []; 102 | for (let i = 0; i < 4; i++) { 103 | data[i] = this.values[i]; 104 | } 105 | 106 | return data; 107 | } 108 | 109 | row(index: number): number[] { 110 | return [ 111 | this.values[index * 2 + 0], 112 | this.values[index * 2 + 1] 113 | ]; 114 | } 115 | 116 | col(index: number): number[] { 117 | return [ 118 | this.values[index], 119 | this.values[index + 2] 120 | ]; 121 | } 122 | 123 | equals(matrix: Mat2, threshold = EPSILON): boolean { 124 | for (let i = 0; i < 4; i++) { 125 | if (Math.abs(this.values[i] - matrix.at(i)) > threshold) { 126 | return false; 127 | } 128 | } 129 | 130 | return true; 131 | } 132 | 133 | determinant(): number { 134 | return this.values[0] * this.values[3] - this.values[2] * this.values[1]; 135 | } 136 | 137 | setIdentity(): Mat2 { 138 | this.values[0] = 1; 139 | this.values[1] = 0; 140 | this.values[2] = 0; 141 | this.values[3] = 1; 142 | 143 | return this; 144 | } 145 | 146 | transpose(): Mat2 { 147 | const temp = this.values[1]; 148 | 149 | this.values[1] = this.values[2]; 150 | this.values[2] = temp; 151 | 152 | return this; 153 | } 154 | 155 | inverse(): Mat2 { 156 | let det = this.determinant(); 157 | 158 | if (!det) { 159 | return null; 160 | } 161 | 162 | det = 1.0 / det; 163 | 164 | this.values[0] = det * (this.values[3]); 165 | this.values[1] = det * (-this.values[1]); 166 | this.values[2] = det * (-this.values[2]); 167 | this.values[3] = det * (this.values[0]); 168 | 169 | return this; 170 | } 171 | 172 | multiply(matrix: Mat2): Mat2 { 173 | const a11 = this.values[0], 174 | a12 = this.values[1], 175 | a21 = this.values[2], 176 | a22 = this.values[3]; 177 | 178 | this.values[0] = a11 * matrix.at(0) + a12 * matrix.at(2); 179 | this.values[1] = a11 * matrix.at(1) + a12 * matrix.at(3); 180 | this.values[2] = a21 * matrix.at(0) + a22 * matrix.at(2); 181 | this.values[3] = a21 * matrix.at(1) + a22 * matrix.at(3); 182 | 183 | return this; 184 | } 185 | 186 | rotate(angle: number): Mat2 { 187 | const a11 = this.values[0], 188 | a12 = this.values[1], 189 | a21 = this.values[2], 190 | a22 = this.values[3]; 191 | 192 | const sin = Math.sin(angle), 193 | cos = Math.cos(angle); 194 | 195 | this.values[0] = a11 * cos + a12 * sin; 196 | this.values[1] = a11 * -sin + a12 * cos; 197 | this.values[2] = a21 * cos + a22 * sin; 198 | this.values[3] = a21 * -sin + a22 * cos; 199 | 200 | return this; 201 | } 202 | } 203 | 204 | export class Mat3 { 205 | public static identity = new Mat3().setIdentity(); 206 | private values = new Float32Array(9); 207 | 208 | constructor(values: number[] = null) { 209 | if (values) { 210 | this.init(values); 211 | } 212 | } 213 | 214 | public static fromVec2(v: [number, number]): Mat3 { 215 | return new Mat3([ 216 | 0, 0, v[0], 217 | 0, 0, v[1], 218 | 0, 0, 0 219 | ]); 220 | } 221 | 222 | public static product(m1: Mat3, m2: Mat3, result: Mat3 = null): Mat3 { 223 | const a00 = m1.at(0), a01 = m1.at(1), a02 = m1.at(2), 224 | a10 = m1.at(3), a11 = m1.at(4), a12 = m1.at(5), 225 | a20 = m1.at(6), a21 = m1.at(7), a22 = m1.at(8); 226 | 227 | const b00 = m2.at(0), b01 = m2.at(1), b02 = m2.at(2), 228 | b10 = m2.at(3), b11 = m2.at(4), b12 = m2.at(5), 229 | b20 = m2.at(6), b21 = m2.at(7), b22 = m2.at(8); 230 | 231 | if (result) { 232 | result.init([ 233 | b00 * a00 + b01 * a10 + b02 * a20, 234 | b00 * a01 + b01 * a11 + b02 * a21, 235 | b00 * a02 + b01 * a12 + b02 * a22, 236 | 237 | b10 * a00 + b11 * a10 + b12 * a20, 238 | b10 * a01 + b11 * a11 + b12 * a21, 239 | b10 * a02 + b11 * a12 + b12 * a22, 240 | 241 | b20 * a00 + b21 * a10 + b22 * a20, 242 | b20 * a01 + b21 * a11 + b22 * a21, 243 | b20 * a02 + b21 * a12 + b22 * a22 244 | ]); 245 | 246 | return result; 247 | } else { 248 | return new Mat3([ 249 | b00 * a00 + b01 * a10 + b02 * a20, 250 | b00 * a01 + b01 * a11 + b02 * a21, 251 | b00 * a02 + b01 * a12 + b02 * a22, 252 | 253 | b10 * a00 + b11 * a10 + b12 * a20, 254 | b10 * a01 + b11 * a11 + b12 * a21, 255 | b10 * a02 + b11 * a12 + b12 * a22, 256 | 257 | b20 * a00 + b21 * a10 + b22 * a20, 258 | b20 * a01 + b21 * a11 + b22 * a21, 259 | b20 * a02 + b21 * a12 + b22 * a22 260 | ]); 261 | } 262 | } 263 | 264 | at(index: number): number { 265 | return this.values[index]; 266 | } 267 | 268 | init(values: number[]): Mat3 { 269 | for (let i = 0; i < 9; i++) { 270 | this.values[i] = values[i]; 271 | } 272 | 273 | return this; 274 | } 275 | 276 | reset(): void { 277 | for (let i = 0; i < 9; i++) { 278 | this.values[i] = 0; 279 | } 280 | } 281 | 282 | copy(dest: Mat3 = null): Mat3 { 283 | if (!dest) { 284 | dest = new Mat3(); 285 | } 286 | 287 | for (let i = 0; i < 9; i++) { 288 | dest.values[i] = this.values[i]; 289 | } 290 | 291 | return dest; 292 | } 293 | 294 | all(): number[] { 295 | const data: number[] = []; 296 | for (let i = 0; i < 9; i++) { 297 | data[i] = this.values[i]; 298 | } 299 | 300 | return data; 301 | } 302 | 303 | row(index: number): number[] { 304 | return [ 305 | this.values[index * 3 + 0], 306 | this.values[index * 3 + 1], 307 | this.values[index * 3 + 2] 308 | ]; 309 | } 310 | 311 | col(index: number): number[] { 312 | return [ 313 | this.values[index], 314 | this.values[index + 3], 315 | this.values[index + 6] 316 | ]; 317 | } 318 | 319 | equals(matrix: Mat3, threshold = EPSILON): boolean { 320 | for (let i = 0; i < 9; i++) { 321 | if (Math.abs(this.values[i] - matrix.at(i)) > threshold) { 322 | return false; 323 | } 324 | } 325 | 326 | return true; 327 | } 328 | 329 | determinant(): number { 330 | const a00 = this.values[0], a01 = this.values[1], a02 = this.values[2], 331 | a10 = this.values[3], a11 = this.values[4], a12 = this.values[5], 332 | a20 = this.values[6], a21 = this.values[7], a22 = this.values[8]; 333 | 334 | const det01 = a22 * a11 - a12 * a21, 335 | det11 = -a22 * a10 + a12 * a20, 336 | det21 = a21 * a10 - a11 * a20; 337 | 338 | return a00 * det01 + a01 * det11 + a02 * det21; 339 | } 340 | 341 | setIdentity(): Mat3 { 342 | this.values[0] = 1; 343 | this.values[1] = 0; 344 | this.values[2] = 0; 345 | this.values[3] = 0; 346 | this.values[4] = 1; 347 | this.values[5] = 0; 348 | this.values[6] = 0; 349 | this.values[7] = 0; 350 | this.values[8] = 1; 351 | 352 | return this; 353 | } 354 | 355 | transpose(): Mat3 { 356 | const temp01 = this.values[1], 357 | temp02 = this.values[2], 358 | temp12 = this.values[5]; 359 | 360 | this.values[1] = this.values[3]; 361 | this.values[2] = this.values[6]; 362 | this.values[3] = temp01; 363 | this.values[5] = this.values[7]; 364 | this.values[6] = temp02; 365 | this.values[7] = temp12; 366 | 367 | return this; 368 | } 369 | 370 | inverse(): Mat3 { 371 | const a00 = this.values[0], a01 = this.values[1], a02 = this.values[2], 372 | a10 = this.values[3], a11 = this.values[4], a12 = this.values[5], 373 | a20 = this.values[6], a21 = this.values[7], a22 = this.values[8]; 374 | 375 | const det01 = a22 * a11 - a12 * a21, 376 | det11 = -a22 * a10 + a12 * a20, 377 | det21 = a21 * a10 - a11 * a20; 378 | 379 | let det = a00 * det01 + a01 * det11 + a02 * det21; 380 | 381 | if (!det) { 382 | return null; 383 | } 384 | 385 | det = 1.0 / det; 386 | 387 | this.values[0] = det01 * det; 388 | this.values[1] = (-a22 * a01 + a02 * a21) * det; 389 | this.values[2] = (a12 * a01 - a02 * a11) * det; 390 | this.values[3] = det11 * det; 391 | this.values[4] = (a22 * a00 - a02 * a20) * det; 392 | this.values[5] = (-a12 * a00 + a02 * a10) * det; 393 | this.values[6] = det21 * det; 394 | this.values[7] = (-a21 * a00 + a01 * a20) * det; 395 | this.values[8] = (a11 * a00 - a01 * a10) * det; 396 | 397 | return this; 398 | } 399 | 400 | multiply(matrix: Mat3): Mat3 { 401 | const a00 = this.values[0], a01 = this.values[1], a02 = this.values[2], 402 | a10 = this.values[3], a11 = this.values[4], a12 = this.values[5], 403 | a20 = this.values[6], a21 = this.values[7], a22 = this.values[8]; 404 | 405 | const b00 = matrix.at(0), b01 = matrix.at(1), b02 = matrix.at(2), 406 | b10 = matrix.at(3), b11 = matrix.at(4), b12 = matrix.at(5), 407 | b20 = matrix.at(6), b21 = matrix.at(7), b22 = matrix.at(8); 408 | 409 | this.values[0] = b00 * a00 + b01 * a10 + b02 * a20; 410 | this.values[1] = b00 * a01 + b01 * a11 + b02 * a21; 411 | this.values[2] = b00 * a02 + b01 * a12 + b02 * a22; 412 | 413 | this.values[3] = b10 * a00 + b11 * a10 + b12 * a20; 414 | this.values[4] = b10 * a01 + b11 * a11 + b12 * a21; 415 | this.values[5] = b10 * a02 + b11 * a12 + b12 * a22; 416 | 417 | this.values[6] = b20 * a00 + b21 * a10 + b22 * a20; 418 | this.values[7] = b20 * a01 + b21 * a11 + b22 * a21; 419 | this.values[8] = b20 * a02 + b21 * a12 + b22 * a22; 420 | 421 | return this; 422 | } 423 | } 424 | -------------------------------------------------------------------------------- /src/app/classes/vector.ts: -------------------------------------------------------------------------------- 1 | import {Mat3} from './matrix'; 2 | 3 | export class Orientation { 4 | public static north = 0; 5 | public static east = 1; 6 | public static south = 2; 7 | public static west = 3; 8 | private ori: number; 9 | 10 | constructor(o: number) { 11 | this.ori = o % 4; 12 | } 13 | 14 | public static fromMat3(m: Mat3): Orientation { 15 | let ori = -1; 16 | if (m.at(5) > 0.1) { 17 | ori = 0; // north 18 | } 19 | if (m.at(2) > 0.1) { 20 | ori = 3; // west 21 | } 22 | if (m.at(5) < -0.1) { 23 | ori = 2; // south 24 | } 25 | if (m.at(2) < -0.1) { 26 | ori = 1; // east 27 | } 28 | return new Orientation(ori); 29 | } 30 | 31 | public rotatedBy(rot90DegCount: number): Orientation { 32 | return new Orientation(this.ori + 4 + rot90DegCount); 33 | } 34 | 35 | public name(): string { 36 | switch (this.ori) { 37 | case Orientation.north: 38 | return 'north'; 39 | case Orientation.west: 40 | return 'west'; 41 | case Orientation.south: 42 | return 'south'; 43 | case Orientation.east: 44 | return 'east'; 45 | } 46 | } 47 | 48 | public value(): number { 49 | return this.ori; 50 | } 51 | 52 | public isSame(o: Orientation): boolean { 53 | return this.ori === o.ori; 54 | } 55 | 56 | public isOpposite(o: Orientation): boolean { 57 | return !this.isSame(o) && (this.isVertically() && o.isVertically() || this.isHorizontally() && o.isHorizontally()); 58 | } 59 | 60 | public isHorizontally(): boolean { 61 | return this.ori === Orientation.west || this.ori === Orientation.east; 62 | } 63 | 64 | public isVertically(): boolean { 65 | return this.ori === Orientation.north || this.ori === Orientation.south; 66 | } 67 | 68 | public isNorth(): boolean { 69 | return this.ori === Orientation.north; 70 | } 71 | 72 | public isWest(): boolean { 73 | return this.ori === Orientation.west; 74 | } 75 | 76 | public isSouth(): boolean { 77 | return this.ori === Orientation.south; 78 | } 79 | 80 | public isEast(): boolean { 81 | return this.ori === Orientation.east; 82 | } 83 | } 84 | 85 | export class Vec2 { 86 | public x = 0; 87 | public y = 0; 88 | private o = new Orientation(Orientation.north); 89 | 90 | constructor(p: [number, number], o?: Orientation) { 91 | this.x = p[0]; 92 | this.y = p[1]; 93 | if (o) { 94 | this.o = o; 95 | } 96 | } 97 | 98 | public static combine(v1: Vec2, v2: Vec2): Vec2 { 99 | return new Vec2([v1.x, v2.y], v1.o); 100 | } 101 | 102 | public static copy(v: Vec2): Vec2 { 103 | return new Vec2([v.x, v.y], v.o); 104 | } 105 | 106 | public static null(): Vec2 { 107 | return new Vec2([0, 0], new Orientation(Orientation.north)); 108 | } 109 | 110 | public translate(t: Vec2): Vec2 { 111 | this.x += t.x; 112 | this.y += t.y; 113 | return this; 114 | } 115 | 116 | public rotate(rotBy90deg: number): Vec2 { 117 | rotBy90deg = (4 + rotBy90deg) % 4; 118 | let x = this.x; 119 | let y = this.y; 120 | // rotation to right 121 | for (let i = 0; i < rotBy90deg; i++) { 122 | [x, y] = [-y, x]; 123 | } 124 | 125 | this.x = x; 126 | this.y = y; 127 | this.o = new Orientation(this.o.value() + rotBy90deg); 128 | 129 | return this; 130 | } 131 | 132 | public scale(s: number): Vec2 { 133 | this.x *= s; 134 | this.y *= s; 135 | return this; 136 | } 137 | 138 | public flip(): Vec2 { 139 | [this.x, this.y] = [this.y, this.x]; 140 | return this; 141 | } 142 | 143 | public minus(v: Vec2): Vec2 { 144 | return new Vec2([this.x - v.x, this.y - v.y], this.o); 145 | } 146 | 147 | public plus(v: Vec2): Vec2 { 148 | return new Vec2([this.x + v.x, this.y + v.y], this.o); 149 | } 150 | 151 | public mult(k: number): Vec2 { 152 | return new Vec2([this.x * k, this.y * k], this.o); 153 | } 154 | 155 | public div(k: number): Vec2 { 156 | return this.mult(1 / k); 157 | } 158 | 159 | public neg(): Vec2 { 160 | return new Vec2([-this.x, -this.y], this.o); 161 | } 162 | 163 | public xy(): [number, number] { 164 | return [this.x, this.y]; 165 | } 166 | 167 | public orient(): Orientation { 168 | return this.o; 169 | } 170 | } 171 | -------------------------------------------------------------------------------- /src/app/components/connection.component.svg.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /src/app/components/connection.component.ts: -------------------------------------------------------------------------------- 1 | import {Component, ChangeDetectionStrategy, Input, ChangeDetectorRef, OnDestroy} from '@angular/core'; 2 | import {Connection, OperatorInstance, Type} from '../classes/operator'; 3 | import {VisualService} from '../services/visual.service'; 4 | import {SVGConnectionLineGenerator} from '../utils'; 5 | import {BroadcastService} from "../services/broadcast.service"; 6 | 7 | @Component({ 8 | selector: 'app-connection,[app-connection]', 9 | templateUrl: './connection.component.svg.html', 10 | styleUrls: [], 11 | changeDetection: ChangeDetectionStrategy.OnPush 12 | }) 13 | export class ConnectionComponent implements OnDestroy { 14 | private callback: () => void; 15 | 16 | @Input() 17 | public instance: OperatorInstance; 18 | 19 | private connection_: Connection; 20 | 21 | @Input() 22 | set connection(conn: Connection) { 23 | this.connection_ = conn; 24 | if (this.aspect) { 25 | this.subscribe(); 26 | } 27 | } 28 | 29 | get connection() { 30 | return this.connection_; 31 | } 32 | 33 | public aspect_: string; 34 | 35 | @Input() 36 | set aspect(a: string) { 37 | this.aspect_ = a; 38 | if (this.connection) { 39 | this.subscribe(); 40 | } 41 | } 42 | 43 | get aspect(): string { 44 | return this.aspect_; 45 | } 46 | 47 | constructor(private cd: ChangeDetectorRef, public broadcast: BroadcastService) { 48 | cd.detach(); 49 | } 50 | 51 | public connectionPoints(): string { 52 | return SVGConnectionLineGenerator.generateRoundPath(this.instance, this.connection); 53 | } 54 | 55 | public getCSSClass(): any { 56 | const cssClass = {}; 57 | 58 | cssClass['selected'] = this.broadcast.isSelected(this.connection); 59 | cssClass['hovered'] = this.broadcast.isHovered(this.connection); 60 | cssClass['expandable'] = this.connection.getDestination().getName().startsWith('{'); 61 | 62 | return cssClass; 63 | } 64 | 65 | public normalVisible(): boolean { 66 | return !this.broadcast.isSelected(this.connection) && !this.broadcast.isHovered(this.connection); 67 | } 68 | 69 | private subscribe() { 70 | this.callback = this.broadcast.registerCallback(this.connection, () => { 71 | this.cd.detectChanges(); 72 | }); 73 | this.cd.detectChanges(); 74 | } 75 | 76 | ngOnDestroy(): void { 77 | this.broadcast.unregisterCallback(this.connection, this.callback); 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /src/app/components/editor-debug-panel.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 |

Input

5 |
6 | 7 |
8 | 9 |
10 |
Preview object
11 |
12 | 13 |
14 |
15 |

16 | This operator is directly accessible via HTTP (see debug panel). 17 |

18 |
19 |
20 |

Generics

21 |
22 |
{{ genName }}
23 | 25 | 26 | 29 |
30 |
31 |
32 |
33 |
34 |

Output

35 |
36 |
37 | 38 |
39 |
40 |

41 | This operator is directly accessible via HTTP (see debug panel). 42 |

43 |
44 |
45 |

Properties

46 |
47 |
{{propName}}
48 | 52 | 53 | 56 |
57 |
58 |
59 |
60 |
61 |

Debugging

62 | 63 |

{{ msg }}

64 |
65 |
66 | 67 |
68 |
69 |
70 | -------------------------------------------------------------------------------- /src/app/components/editor-debug-panel.component.scss: -------------------------------------------------------------------------------- 1 | @import "../../styles/variables.scss"; 2 | 3 | #sl-debug-panel { 4 | height: 45vh; 5 | background: $pane-border-color; 6 | overflow: hidden; 7 | padding: 8px 0 8px 0; 8 | display: flex; 9 | width: 100%; 10 | 11 | .preview-object { 12 | font-size: 0.7em; 13 | color: $body-color; 14 | } 15 | 16 | .preview { 17 | border: 1px solid $gray; 18 | padding: 5px; 19 | margin-bottom: 10px; 20 | border-radius: 5px; 21 | background-color: white; 22 | } 23 | 24 | .output-options { 25 | padding: 5px; 26 | } 27 | 28 | h6 { 29 | margin-top: 10px; 30 | } 31 | 32 | > div:nth-child(1) { 33 | width: 37.5%; 34 | } 35 | 36 | > div:nth-child(2) { 37 | width: 37.5%; 38 | } 39 | 40 | > div:nth-child(3) { 41 | width: 25%; 42 | } 43 | 44 | > div { 45 | height: 100%; 46 | background: $body-bg; 47 | overflow: auto; 48 | padding: 5px; 49 | position: relative; 50 | 51 | .close-pane { 52 | font-size: 16px; 53 | display: block; 54 | position: absolute; 55 | right: 5px; 56 | top: 5px; 57 | cursor: pointer; 58 | } 59 | } 60 | 61 | > div:not(:first-child) { 62 | margin-left: 8px; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/app/components/editor-debug-panel.component.ts: -------------------------------------------------------------------------------- 1 | import {ChangeDetectionStrategy, ChangeDetectorRef, Component, EventEmitter, Input, OnInit, Output} from '@angular/core'; 2 | import {createDefaultValue, HTTP_REQUEST_DEF, HTTP_RESPONSE_DEF} from '../utils'; 3 | import {OperatorDef, OperatorInstance} from '../classes/operator'; 4 | import * as deepEqual from 'deep-equal'; 5 | import {HttpClient} from '@angular/common/http'; 6 | import {TypeDefFormComponent} from './type-def-form.component'; 7 | import {ApiService} from '../services/api.service'; 8 | 9 | @Component({ 10 | selector: 'app-editor-debug-panel', 11 | templateUrl: './editor-debug-panel.component.html', 12 | styleUrls: ['./editor-debug-panel.component.scss'], 13 | changeDetection: ChangeDetectionStrategy.OnPush 14 | }) 15 | export class EditorDebugPanelComponent implements OnInit { 16 | public inputValue: any = {}; 17 | public running = false; 18 | public runningHandle = ''; 19 | public debuggingLog: Array = []; 20 | public debuggingReponses: Array = []; 21 | public debuggingGens = {}; 22 | public debuggingPropDefs = {}; 23 | public debuggingInPort = {}; 24 | public debuggingOutPort = {}; 25 | public debuggingProps = {}; 26 | public operatorEndpoint = ''; 27 | public propertyDefs: any = null; 28 | public mainSrvPort: any = null; 29 | public interval: any = null; 30 | 31 | // DEBUG STATE 32 | 33 | // This is the normal cycle: 34 | // 'none' -> 'startDebugging' -> ['specifying'] -> 'debugging' -> 'stopOperator' -> 'startDebugging' 35 | 36 | public debugState_ = null; 37 | 38 | @Input() 39 | set debugState(state: string) { 40 | if (this.debugState_ === state) { 41 | return; 42 | } 43 | 44 | this.debugState_ = state; 45 | this.debugStateChange.emit(this.debugState_); 46 | 47 | if (state === 'startDebugging') { 48 | this.startDebugging(); 49 | } else if (state === 'stopOperator') { 50 | this.stopOperator(); 51 | } 52 | } 53 | 54 | get debugState(): string { 55 | return this.debugState_; 56 | } 57 | 58 | @Output() 59 | public debugStateChange = new EventEmitter(); 60 | 61 | // OPERATOR 62 | 63 | @Input() 64 | public operator: OperatorInstance; 65 | 66 | // DEFINITION 67 | 68 | private definition_: OperatorDef; 69 | 70 | @Input() 71 | public set definition(def: OperatorDef) { 72 | this.definition_ = def; 73 | if (!def) { 74 | return; 75 | } 76 | const opDef = def.getDef(); 77 | if (!opDef) { 78 | return; 79 | } 80 | if (opDef.services) { 81 | this.mainSrvPort = opDef.services.main; 82 | } 83 | if (!opDef.properties) { 84 | opDef.properties = {}; 85 | } 86 | this.propertyDefs = opDef.properties; 87 | } 88 | 89 | public get definition(): OperatorDef { 90 | return this.definition_; 91 | } 92 | 93 | // OPERATOR NAME 94 | 95 | @Input() 96 | public operatorId: string; 97 | 98 | constructor(private ref: ChangeDetectorRef, private http: HttpClient, private api: ApiService) { 99 | ref.detach(); 100 | } 101 | 102 | ngOnInit(): void { 103 | this.ref.detectChanges(); 104 | } 105 | 106 | public genericNames(ins: OperatorInstance): Array { 107 | return Array.from(ins.getGenericNames()); 108 | } 109 | 110 | public specifyGeneric(gens, name) { 111 | gens[name] = TypeDefFormComponent.newDefaultTypeDef('primitive'); 112 | this.ref.detectChanges(); 113 | } 114 | 115 | public specifyProperty(props, name, def) { 116 | props[name] = createDefaultValue(def); 117 | this.ref.detectChanges(); 118 | } 119 | 120 | public debugLog(msg: string) { 121 | this.debuggingLog.push(msg); 122 | } 123 | 124 | public startDebugging() { 125 | this.refreshDebugVariables(); 126 | if (this.operator.getGenericNames().size > 0 || this.operator.getPropertyDefs().size > 0) { 127 | this.specifyOperator(); 128 | } else { 129 | this.runOperator(); 130 | } 131 | } 132 | 133 | public refreshDebugVariables() { 134 | this.debuggingPropDefs = JSON.parse(JSON.stringify(this.propertyDefs)); 135 | for (const propName in this.debuggingPropDefs) { 136 | if (this.debuggingPropDefs.hasOwnProperty(propName)) { 137 | OperatorDef.specifyTypeDef(this.debuggingPropDefs[propName], this.debuggingGens, {}, {}); 138 | this.debuggingProps[propName] = createDefaultValue(this.debuggingPropDefs[propName]); 139 | } 140 | } 141 | 142 | this.refreshPropertyExpansion(); 143 | } 144 | 145 | public refreshPropertyExpansion() { 146 | this.debuggingInPort = JSON.parse(JSON.stringify(this.mainSrvPort.in)); 147 | OperatorDef.specifyTypeDef(this.debuggingInPort, this.debuggingGens, this.debuggingProps, this.propertyDefs); 148 | 149 | this.debuggingOutPort = JSON.parse(JSON.stringify(this.mainSrvPort.out)); 150 | OperatorDef.specifyTypeDef(this.debuggingOutPort, this.debuggingGens, this.debuggingProps, this.propertyDefs); 151 | } 152 | 153 | public httpInput(): boolean { 154 | return deepEqual(this.mainSrvPort.in, HTTP_REQUEST_DEF); 155 | } 156 | 157 | public httpOutput(): boolean { 158 | return deepEqual(this.mainSrvPort.out, HTTP_RESPONSE_DEF); 159 | } 160 | 161 | public async sendInputValue(obj: any) { 162 | await this.api.post(this.operatorEndpoint, {}, obj); 163 | if (this.interval) { 164 | setTimeout(() => this.fetchItems(), 150); 165 | } 166 | } 167 | 168 | public stopOperator() { 169 | this.api.delete('/run/', {}, { 170 | handle: this.runningHandle 171 | }).then(data => { 172 | if (data['status'] === 'success') { 173 | this.running = false; 174 | this.runningHandle = ''; 175 | this.debugLog(`Operator stopped.`); 176 | } else { 177 | const error = data['error']; 178 | this.debugLog(`Error ${error.code} occurred: ${error.msg}`); 179 | } 180 | this.debugState = 'stopped'; 181 | this.ref.detectChanges(); 182 | }); 183 | } 184 | 185 | public specifyOperator() { 186 | this.debugState = 'specifying'; 187 | this.ref.detectChanges(); 188 | } 189 | 190 | private fetchItems() { 191 | this.api.get(this.operatorEndpoint) 192 | .then(responses => { 193 | this.debuggingReponses = responses as Array; 194 | this.ref.detectChanges(); 195 | }) 196 | .catch(() => { 197 | clearInterval(this.interval); 198 | this.interval = null; 199 | }); 200 | } 201 | 202 | public runOperator() { 203 | this.inputValue = createDefaultValue(this.debuggingInPort); 204 | this.debugLog('Request daemon to start operator...'); 205 | this.ref.detectChanges(); 206 | 207 | const isStream = !this.httpInput() && !this.httpOutput(); 208 | 209 | this.api.post('/run/', {}, { 210 | id: this.operatorId, 211 | gens: this.debuggingGens, 212 | props: this.debuggingProps, 213 | stream: isStream 214 | }).then(data => { 215 | if (data['status'] === 'success') { 216 | this.debugState = 'debugging'; 217 | this.operatorEndpoint = data['url']; 218 | this.debugLog('Operator is running at ' + this.operatorEndpoint); 219 | this.runningHandle = data['handle']; 220 | this.interval = null; 221 | 222 | if (isStream) { 223 | const that = this; 224 | this.interval = setInterval(function () { 225 | that.fetchItems(); 226 | }, 2000); 227 | } 228 | } else { 229 | this.debugState = 'stopped'; 230 | const error = data['error']; 231 | this.debugLog(`Error ${error.code} occurred: ${error.msg}`); 232 | } 233 | this.ref.detectChanges(); 234 | }); 235 | } 236 | 237 | public getPropertyNames(): Array { 238 | const names = []; 239 | for (const propName in this.propertyDefs) { 240 | if (this.propertyDefs.hasOwnProperty(propName)) { 241 | names.push(propName); 242 | } 243 | } 244 | return names; 245 | } 246 | 247 | public closeDebugPanel() { 248 | this.debugState = null; 249 | this.ref.detectChanges(); 250 | } 251 | 252 | public inputValueChanged() { 253 | this.ref.detectChanges(); 254 | } 255 | 256 | public setDebuggingProp(name: string, value: any) { 257 | this.debuggingProps[name] = value; 258 | this.refreshPropertyExpansion(); 259 | } 260 | 261 | } 262 | -------------------------------------------------------------------------------- /src/app/components/editor-sidebar.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 | Id: {{broadcast.getSelected().getID()}} 4 | Operator: {{broadcast.getSelected().getOperatorName()}} 5 |
6 |
7 | Nothing selected. 8 |
9 | 10 |
11 |

Main operator

12 |
13 | In-ports 14 |
15 |
16 | 17 |
18 |
19 | Out-ports 20 |
21 |
22 | 23 |
24 |
Properties
25 |
26 |
{{propName}}
27 | 28 | 29 |
30 |
31 |
32 | 33 | 34 |
35 |
36 | 37 |
38 |

{{ instanceName() }}

39 | 40 |
Transform
41 | 42 |
43 | 45 | 47 |
48 |
49 | 51 | 53 |
54 |
55 |
Generics
56 |
57 |
{{ genName }}
58 | 62 | 65 |
66 |
67 |
68 |
Properties
69 |
70 |
{{ prop.name }}
71 | 76 | 77 | 81 |
82 |
83 |
84 |
85 | -------------------------------------------------------------------------------- /src/app/components/editor-sidebar.component.scss: -------------------------------------------------------------------------------- 1 | @import "../../styles/variables.scss"; 2 | 3 | #sl-sidebar { 4 | height: calc(100% - 20px); 5 | } 6 | 7 | .sl-ui-scrollable { 8 | height: 100%; 9 | padding: $spacer; 10 | overflow: auto; 11 | white-space: nowrap; 12 | width: 100%; 13 | .sl-operator-name { 14 | margin-bottom: 8px; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/app/components/editor-sidebar.component.ts: -------------------------------------------------------------------------------- 1 | import {ChangeDetectionStrategy, ChangeDetectorRef, Component, EventEmitter, Input, OnDestroy, OnInit, Output} from '@angular/core'; 2 | 3 | import {BroadcastService} from '../services/broadcast.service'; 4 | 5 | import {TypeDefFormComponent} from './type-def-form.component'; 6 | 7 | import {Identifiable, Identity, OperatorDef, OperatorInstance} from '../classes/operator'; 8 | import {createDefaultValue} from '../utils'; 9 | 10 | @Component({ 11 | selector: 'app-editor-sidebar', 12 | templateUrl: './editor-sidebar.component.html', 13 | styleUrls: ['./editor-sidebar.component.scss'], 14 | changeDetection: ChangeDetectionStrategy.OnPush 15 | }) 16 | export class EditorSidebarComponent implements OnInit, OnDestroy { 17 | 18 | // SURROUNDING INSTANCE 19 | 20 | public surrounding_: OperatorInstance; 21 | 22 | @Input() 23 | public set surrounding(ins: OperatorInstance) { 24 | this.surrounding_ = ins; 25 | } 26 | 27 | public get surrounding(): OperatorInstance { 28 | return this.surrounding_; 29 | } 30 | 31 | public definition_: OperatorDef; 32 | 33 | // OPERATOR DEFINITION 34 | 35 | @Input() 36 | public set definition(def: OperatorDef) { 37 | this.definition_ = def; 38 | if (!def) { 39 | return; 40 | } 41 | const opDef = def.getDef(); 42 | if (opDef) { 43 | if (opDef.services) { 44 | this.mainSrvPort = opDef.services.main; 45 | } 46 | if (opDef.properties) { 47 | this.mainPropertyDefs = opDef.properties; 48 | } 49 | } 50 | } 51 | 52 | public get definition(): OperatorDef { 53 | return this.definition_; 54 | } 55 | 56 | // CHANGE EMITTER 57 | 58 | @Output() 59 | public definitionChange = new EventEmitter(); 60 | 61 | // GENERAL 62 | // Fields needed by both main and child instances 63 | 64 | private callback: (Identifiable) => void; 65 | 66 | // MAIN INSTANCE 67 | // Fields needed by main instance, should be prefixed 'main' 68 | 69 | public mainSrvPort: any; 70 | public mainPropertyDefs: any; 71 | public mainNewPropName: string; 72 | 73 | // CHILD INSTANCE 74 | // Fields needed by child instances, should be prefixed 'ins' 75 | 76 | public insGenericNames: Array = []; 77 | public insGenericSpecs: { [key: string]: any } = {}; 78 | public insPropertyDefs: Array<{ name: string, def: any }> = []; 79 | public insPropertyValues: { [key: string]: any } = {}; 80 | 81 | // This is necessary because we can specify the type and the value in this very same component 82 | // TypeValue components subscribe to this identity and TypeDef components broadcast to it 83 | public insEditorSidebarIdentity = new Identity('editor-sidebar'); 84 | 85 | constructor(private ref: ChangeDetectorRef, public broadcast: BroadcastService) { 86 | ref.detach(); 87 | } 88 | 89 | public ngOnInit() { 90 | this.callback = this.broadcast.subscribeSelect((ins: Identifiable) => { 91 | if (!(ins instanceof OperatorInstance)) { 92 | return; 93 | } 94 | this.insGenericNames = []; 95 | this.insGenericSpecs = {}; 96 | this.insPropertyDefs = []; 97 | this.insPropertyValues = undefined; 98 | if (this.surrounding !== ins) { 99 | this.insUpdateGenerics(ins); 100 | this.insUpdatePropertyDefs(ins); 101 | this.insUpdatePropertyValues(ins); 102 | } 103 | this.ref.detectChanges(); 104 | }); 105 | } 106 | 107 | public ngOnDestroy() { 108 | this.broadcast.unsubscribeSelect(this.callback); 109 | } 110 | 111 | public async copyOperatorID() { 112 | const selected = this.getSelectedInstance(); 113 | if (selected) { 114 | // @ts-nocheck 115 | await navigator.clipboard.writeText(selected.getID()); 116 | } 117 | } 118 | 119 | public isAnyEntitySelected(): boolean { 120 | return !!this.broadcast.getSelected(); 121 | } 122 | 123 | public isInstanceSelected(): boolean { 124 | return this.isAnyEntitySelected() && this.broadcast.getSelected() !== this.surrounding && 125 | this.broadcast.getSelected() instanceof OperatorInstance; 126 | } 127 | 128 | public isSurroundingSelected(): boolean { 129 | return this.isAnyEntitySelected() && this.broadcast.getSelected() === this.surrounding; 130 | } 131 | 132 | public getSelectedInstance(): OperatorInstance { 133 | const selected = this.broadcast.getSelected(); 134 | if (!(selected instanceof OperatorInstance)) { 135 | return null; 136 | } 137 | return selected; 138 | } 139 | 140 | // MAIN INSTANCE 141 | 142 | public instanceName(): string { 143 | const ins = this.getSelectedInstance(); 144 | if (!!ins) { 145 | return ins.getName(); 146 | } 147 | return ''; 148 | } 149 | 150 | public mainPropertyNames(): Array { 151 | const names = []; 152 | for (const propName in this.mainPropertyDefs) { 153 | if (this.mainPropertyDefs.hasOwnProperty(propName)) { 154 | names.push(propName); 155 | } 156 | } 157 | return names; 158 | } 159 | 160 | public mainRemoveProperty(propName: string) { 161 | delete this.mainPropertyDefs[propName]; 162 | this.definitionChange.emit(); 163 | this.ref.detectChanges(); 164 | } 165 | 166 | public mainAddProperty() { 167 | const propName = this.mainNewPropName; 168 | if (this.mainPropertyDefs[propName]) { 169 | return; 170 | } 171 | this.mainPropertyDefs[propName] = TypeDefFormComponent.newDefaultTypeDef('primitive'); 172 | this.mainNewPropName = ''; 173 | this.definitionChange.emit(); 174 | this.ref.detectChanges(); 175 | } 176 | 177 | public mainNewPropNameChange() { 178 | this.ref.detectChanges(); 179 | } 180 | 181 | public mainPropertyNameValid(): boolean { 182 | return !!this.mainNewPropName && !this.mainPropertyDefs[this.mainNewPropName]; 183 | } 184 | 185 | public mainServiceChanged(): void { 186 | this.definitionChange.emit(); 187 | } 188 | 189 | public mainPropertyChanged(): void { 190 | this.definitionChange.emit(); 191 | } 192 | 193 | // CHILD INSTANCES 194 | 195 | public insSpecifyGeneric(genName: string) { 196 | const ins = this.getSelectedInstance(); 197 | const oDef = this.definition.getDef(); 198 | const insDef = oDef.operators[ins.getName()]; 199 | if (!insDef.generics) { 200 | insDef.generics = {}; 201 | } 202 | this.insGenericSpecs = insDef.generics; 203 | this.insGenericSpecs[genName] = TypeDefFormComponent.newDefaultTypeDef('primitive'); 204 | this.insUpdatePropertyDefs(ins); 205 | this.definitionChange.emit(); 206 | this.ref.detectChanges(); 207 | } 208 | 209 | public insSpecifyProperty(prop: { name: string, def: any }): any { 210 | if (!this.insPropertyValues) { 211 | const ins = this.getSelectedInstance(); 212 | const oDef = this.definition.getDef(); 213 | const insDef = oDef.operators[ins.getName()]; 214 | if (!insDef.properties) { 215 | this.insPropertyValues = insDef.properties = {}; 216 | } else { 217 | this.insPropertyValues = insDef.properties; 218 | } 219 | } 220 | this.insPropertyValues[prop.name] = createDefaultValue(prop.def); 221 | this.definitionChange.emit(); 222 | this.ref.detectChanges(); 223 | } 224 | 225 | public insUpdateGenerics(ins: OperatorInstance): any { 226 | this.insGenericNames = Array.from(ins.getGenericNames()); 227 | this.insGenericSpecs = {}; 228 | const oDef = this.definition.getDef(); 229 | const insDef = oDef.operators[ins.getName()]; 230 | if (!insDef) { 231 | return; 232 | } 233 | const insGenSpecs = insDef.generics; 234 | if (!insGenSpecs) { 235 | return; 236 | } 237 | this.insGenericSpecs = insGenSpecs; 238 | } 239 | 240 | private insUpdatePropertyValues(ins: OperatorInstance): void { 241 | const oDef = this.definition.getDef(); 242 | const insDef = oDef.operators[ins.getName()]; 243 | if (!insDef) { 244 | return; 245 | } 246 | if (insDef.properties) { 247 | this.insPropertyValues = insDef.properties; 248 | } 249 | } 250 | 251 | private insUpdatePropertyDefs(ins: OperatorInstance): void { 252 | if (!ins) { 253 | return; 254 | } 255 | if (this.insPropertyDefs.length === 0) { 256 | this.insPropertyDefs = Array.from(ins.getPropertyDefs().entries()).map(each => { 257 | const defCopy = JSON.parse(JSON.stringify(each[1])); 258 | OperatorDef.specifyTypeDef(defCopy, this.insGenericSpecs, {}, {}); 259 | return {name: each[0], def: defCopy}; 260 | }); 261 | } else { 262 | Array.from(ins.getPropertyDefs().entries()).forEach(each => { 263 | const defCopy = JSON.parse(JSON.stringify(each[1])); 264 | OperatorDef.specifyTypeDef(defCopy, this.insGenericSpecs, {}, {}); 265 | 266 | const propName = each[0]; 267 | 268 | // Find entry 269 | for (const prop of this.insPropertyDefs) { 270 | if (prop.name !== propName) { 271 | continue; 272 | } 273 | Object.assign(prop.def, defCopy); 274 | } 275 | }); 276 | } 277 | } 278 | 279 | public insTypeSpecified(propDef: any): boolean { 280 | if (!propDef) { 281 | return false; 282 | } 283 | 284 | if (propDef.type === 'stream') { 285 | return this.insTypeSpecified(propDef.stream); 286 | } 287 | 288 | if (propDef.type === 'map') { 289 | for (const sub in propDef.map) { 290 | if (!propDef.map.hasOwnProperty(sub)) { 291 | continue; 292 | } 293 | if (!this.insTypeSpecified(propDef.map[sub])) { 294 | return false; 295 | } 296 | } 297 | return true; 298 | } 299 | 300 | if (propDef.type !== 'generic') { 301 | // Primitives are always specified 302 | return true; 303 | } 304 | 305 | return !!this.insGenericSpecs[propDef.generic]; 306 | } 307 | 308 | public insPropertyValueSpecified(prop: { name: string, def: any }): boolean { 309 | return this.insPropertyValues && typeof this.insPropertyValues[prop.name] !== 'undefined'; 310 | } 311 | 312 | public insGenericSpecified(genName: string): boolean { 313 | return !!this.insGenericSpecs[genName]; 314 | } 315 | 316 | public insGenericTypeChanged(): void { 317 | this.insUpdatePropertyDefs(this.getSelectedInstance()); 318 | 319 | this.definitionChange.emit(); 320 | this.broadcast.update(this.insEditorSidebarIdentity); 321 | this.broadcast.update(this.getSelectedInstance()); 322 | } 323 | 324 | public insPropertyValueChanged(): void { 325 | this.definitionChange.emit(); 326 | this.broadcast.update(this.getSelectedInstance()); 327 | } 328 | 329 | public insRotateRight() { 330 | const ins = this.getSelectedInstance(); 331 | if (!!ins) { 332 | ins.rotate(Math.PI / 2); 333 | this.updateInstance(ins); 334 | } 335 | } 336 | 337 | public insRotateLeft() { 338 | const ins = this.getSelectedInstance(); 339 | if (!!ins) { 340 | ins.rotate(-Math.PI / 2); 341 | this.updateInstance(ins); 342 | } 343 | } 344 | 345 | public insMirrorVertically() { 346 | const ins = this.getSelectedInstance(); 347 | if (!!ins) { 348 | ins.scale([1, -1]); 349 | this.updateInstance(ins); 350 | } 351 | } 352 | 353 | public insMirrorHorizontally() { 354 | const ins = this.getSelectedInstance(); 355 | if (!!ins) { 356 | ins.scale([-1, 1]); 357 | this.updateInstance(ins); 358 | } 359 | } 360 | 361 | // GENERAL 362 | 363 | // TODO: Move this logic! 364 | private updateInstance(ins: OperatorInstance) { 365 | this.broadcast.update(ins); 366 | // Also update connections 367 | this.surrounding.getConnections().forEach(conn => { 368 | if (conn.getSource().getOperator() === ins || conn.getDestination().getOperator() === ins) { 369 | this.broadcast.update(conn); 370 | } 371 | }); 372 | } 373 | 374 | } 375 | -------------------------------------------------------------------------------- /src/app/components/editor.component.html: -------------------------------------------------------------------------------- 1 | 26 | 27 |
28 | 29 |
30 | 34 | 35 |
36 | 37 |
38 |
39 |
40 | 42 |
43 |
44 |
45 | 46 | 53 | 54 | 55 | 56 | 57 | 58 |
{{ userMessage }}
59 | 60 |
61 |
62 | 63 |
64 |
65 |
66 | 67 |
68 |
69 |
70 |
71 | -------------------------------------------------------------------------------- /src/app/components/editor.component.scss: -------------------------------------------------------------------------------- 1 | @import "../../styles/variables.scss"; 2 | 3 | #sl-svg-container { 4 | width: 100%; 5 | height: 100%; 6 | background: repeating-linear-gradient( 7 | -65deg, 8 | transparentize($body-color, .95), 9 | transparentize($body-color, .95) 5px, 10 | transparentize($body-bg, .95) 5px, 11 | transparentize($body-bg, .95) 10px 12 | ); 13 | } 14 | 15 | .navbar { 16 | padding-top: 0; 17 | padding-bottom: 0; 18 | padding-left: 0; 19 | height: 36px; 20 | 21 | #sl-navbar-op-viewed { 22 | background-color: $orange; 23 | border-bottom-right-radius: $op-border-radius; 24 | padding-left: 0.5em; 25 | * { 26 | color: $white; 27 | display: inline-block; 28 | font-size: 1.2em; 29 | 30 | } 31 | 32 | .sl-operator-name { 33 | display: inline-block; 34 | padding: 0 1em 0 .75em; 35 | font-size: 1.6em; 36 | min-width: 265px; 37 | text-align: center; 38 | } 39 | } 40 | } 41 | 42 | .sl-editor-container { 43 | height: 100%; 44 | } 45 | 46 | .row { 47 | width: 100%; 48 | } 49 | 50 | #sl-visual-ui { 51 | display: inline-block; 52 | width: 100vw; 53 | height: calc(100vh - 36px); 54 | 55 | .row { 56 | height: 100%; 57 | } 58 | } 59 | 60 | .sl-ui-sidebar { 61 | background-color: $pane-border-color; 62 | padding: $spacer; 63 | height: calc(100vh - 36px); 64 | } 65 | 66 | .sl-ui-mainbar { 67 | overflow: hidden; 68 | padding: 0; 69 | 70 | #sl-svg-container { 71 | overflow: hidden; 72 | height: calc(100vh - 36px - 45vh); 73 | 74 | &.large { 75 | height: initial; 76 | } 77 | 78 | #sl-message-box { 79 | position: absolute; 80 | width: 100%; 81 | padding: 5px; 82 | top: 0; 83 | text-align: center; 84 | border: 3px solid $orange; 85 | background-color: $body-bg; 86 | } 87 | } 88 | 89 | #sl-main-bottom { 90 | height: 45vh; 91 | background: $pane-border-color; 92 | overflow: hidden; 93 | padding: 8px 0 8px 0; 94 | display: flex; 95 | 96 | .preview-object { 97 | font-size: 0.7em; 98 | color: $body-color; 99 | } 100 | 101 | .preview { 102 | border: 1px solid $gray; 103 | padding: 5px; 104 | margin-bottom: 10px; 105 | border-radius: 5px; 106 | background-color: white; 107 | } 108 | } 109 | } 110 | 111 | #sl-instance-sidebar { 112 | height: 100%; 113 | } 114 | 115 | .sl-form-box { 116 | padding-top: 8px; 117 | padding-bottom: 8px; 118 | } 119 | 120 | h1, h2, h3, h4, h5, h6 { 121 | label { 122 | margin: 0 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /src/app/components/editor.component.ts: -------------------------------------------------------------------------------- 1 | import {Component, HostListener, OnInit, ChangeDetectionStrategy, ChangeDetectorRef, OnDestroy} from '@angular/core'; 2 | import {ActivatedRoute} from '@angular/router'; 3 | import {HttpClient} from '@angular/common/http'; 4 | import {animate, state, style, transition, trigger} from '@angular/animations'; 5 | 6 | import {ApiService} from '../services/api.service'; 7 | import {BroadcastService} from '../services/broadcast.service'; 8 | import {MouseService} from '../services/mouse.service'; 9 | import {OperatorService} from '../services/operator.service'; 10 | import {VisualService} from '../services/visual.service'; 11 | 12 | import {Connection, OperatorDef, OperatorInstance, Port} from '../classes/operator'; 13 | import {safeDump, safeLoad} from 'js-yaml'; 14 | import {normalizeConnections, stringifyConnections} from '../utils'; 15 | 16 | import 'codemirror/mode/yaml/yaml.js'; 17 | 18 | @Component({ 19 | templateUrl: './editor.component.html', 20 | styleUrls: ['./editor.component.scss'], 21 | animations: [ 22 | trigger('operatorSaved', [ 23 | state('true', style({ 24 | opacity: 1 25 | })), 26 | state('false', style({ 27 | opacity: 0 28 | })), 29 | transition('false => true', animate('250ms ease-in')), 30 | transition('true => false', animate('1000ms 1000ms ease-out')) 31 | ]) 32 | ], 33 | changeDetection: ChangeDetectionStrategy.OnPush 34 | }) 35 | export class EditorComponent implements OnInit, OnDestroy { 36 | // General 37 | public operatorId = ''; 38 | public operatorName = ''; 39 | public operatorDef: OperatorDef = null; 40 | public operator: OperatorInstance = null; 41 | public debugState: string = null; 42 | public newInstanceName = ''; 43 | public userMessage = ''; 44 | public userMessageTimeout: any = null; 45 | 46 | // YAML 47 | public yamlRepr = ''; 48 | public uiMode = 'visual'; 49 | public editorConfig = { 50 | theme: 'slang-dark', 51 | mode: 'text/x-yaml', 52 | lineNumbers: true, 53 | extraKeys: { 54 | Tab: function (cm) { 55 | const spaces = Array(cm.getOption('indentUnit') + 1).join(' '); 56 | cm.replaceSelection(spaces); 57 | } 58 | } 59 | }; 60 | 61 | // Visual 62 | public selectedEntity = {entity: null as any}; 63 | public scale = 0.6; 64 | public isOperatorSaved = false; 65 | public canvasFocus = false; 66 | 67 | private insPropDefs = new Map>(); 68 | 69 | private mouseCallback: (event: string, actionPhase: string) => void; 70 | private callback: (Identifiable) => void; 71 | 72 | // Dragging 73 | private mouseAction(event, phase) { 74 | const update = phase === 'ongoing'; 75 | 76 | if (!update) { 77 | return; 78 | } 79 | 80 | const xDiff = event.screenX - this.mouse.getLastX(); 81 | const yDiff = event.screenY - this.mouse.getLastY(); 82 | 83 | if (this.mouse.isDragging()) { 84 | const selectedInstance = this.broadcast.getSelected(); 85 | if (!selectedInstance || !(selectedInstance instanceof OperatorInstance)) { 86 | return; 87 | } 88 | selectedInstance.translate([xDiff / this.scale, yDiff / this.scale]); 89 | this.updateInstance(selectedInstance); 90 | } else if (this.mouse.isResizing()) { 91 | if (!this.operator) { 92 | return; 93 | } 94 | this.operator.resize([xDiff / this.scale, yDiff / this.scale]); 95 | this.refresh(); 96 | } 97 | } 98 | 99 | @HostListener('window:keydown', ['$event']) 100 | keyEvent(event: KeyboardEvent) { 101 | if (!this.canvasFocus) { 102 | return; 103 | } 104 | switch (event.key) { 105 | case '+': 106 | event.preventDefault(); 107 | this.scale *= 1.1; 108 | this.ref.detectChanges(); 109 | break; 110 | case '-': 111 | event.preventDefault(); 112 | this.scale /= 1.1; 113 | this.ref.detectChanges(); 114 | break; 115 | case 'Delete': 116 | case 'Backspace': 117 | const selectedEntity = this.broadcast.getSelected(); 118 | if (!selectedEntity) { 119 | return; 120 | } 121 | event.preventDefault(); 122 | if (selectedEntity instanceof OperatorInstance) { 123 | this.removeInstance(selectedEntity); 124 | this.broadcast.select(null); 125 | this.broadcast.update(this.operator); 126 | break; 127 | } 128 | if (selectedEntity instanceof Connection) { 129 | this.removeConnection(selectedEntity); 130 | this.broadcast.select(null); 131 | this.broadcast.update(this.operator); 132 | break; 133 | } 134 | break; 135 | } 136 | } 137 | 138 | constructor(private route: ActivatedRoute, 139 | private http: HttpClient, 140 | public operators: OperatorService, 141 | public visual: VisualService, 142 | public broadcast: BroadcastService, 143 | public api: ApiService, 144 | private ref: ChangeDetectorRef, 145 | public mouse: MouseService) { 146 | ref.detach(); 147 | } 148 | 149 | ngOnInit() { 150 | this.route.params.subscribe(routeParams => { 151 | this.loadOperator(routeParams.operatorId); 152 | }); 153 | this.operators.getLoadingObservable().subscribe((success) => { 154 | if (success) { 155 | this.loadOperator(this.operatorId); 156 | } 157 | }); 158 | this.mouseCallback = this.mouse.subscribe((event: any, actionPhase: string) => this.mouseAction(event, actionPhase)); 159 | } 160 | 161 | ngOnDestroy() { 162 | this.mouse.unsubscribe(this.mouseCallback); 163 | this.broadcast.unsubscribeSelect(this.callback); 164 | } 165 | 166 | // General 167 | 168 | public async save() { 169 | 170 | await this.operators.storeDefinition(this.operator.getDef()); 171 | await this.visual.storeVisual(this.operatorName, this.operator.getVisual()); 172 | this.isOperatorSaved = true; 173 | await this.operators.refresh(); 174 | await this.loadOperator(this.operatorId); 175 | this.isOperatorSaved = false; 176 | this.ref.detectChanges(); 177 | } 178 | 179 | public download() { 180 | const url = this.api.downloadUrl(this.operator.getFullyQualifiedName()); 181 | window.location.href = url; 182 | } 183 | 184 | public async loadOperator(operatorId) { 185 | // in this case operator == blueprint 186 | this.operatorId = operatorId; 187 | this.broadcast.clearUpdateCallbacks(); 188 | this.operatorDef = this.operators.getLocal(operatorId); 189 | 190 | if (this.operatorDef) { 191 | const def = this.operatorDef.getDef(); 192 | const geometry = def.geometry = def.geometry?def.geometry:{} 193 | this.operatorName = def.meta.name; 194 | 195 | if (!geometry.size) { 196 | geometry.size = {width:1200, height:1100} 197 | } 198 | 199 | if (!geometry.position) { 200 | geometry.position = {x:50, y:50} 201 | } 202 | 203 | /* 204 | * We compare selectedEntity by identity, so after re-initializing all operators, that comparsion fails 205 | */ 206 | const newOperator = new OperatorInstance(this.operators, operatorId, '', this.operatorDef, {}, null, def); 207 | if (this.isSelected(this.operator)) { 208 | this.selectedEntity.entity = newOperator; 209 | } 210 | 211 | const posxy: [number, number] = [geometry.position.x, geometry.position.y]; 212 | 213 | this.operator = newOperator; 214 | this.operator.translate(posxy); 215 | this.updateDef(def); 216 | this.ref.detectChanges(); 217 | } 218 | if (!this.callback) { 219 | this.callback = this.broadcast.subscribeSelect(obj => { 220 | if (!obj) { 221 | this.selectedEntity.entity = null; 222 | return; 223 | } 224 | if (obj instanceof OperatorInstance) { 225 | this.selectInstance(obj); 226 | } else if (obj instanceof Port) { 227 | this.selectPort(obj); 228 | } else if (obj instanceof Connection) { 229 | this.selectConnection(obj); 230 | } 231 | }); 232 | } 233 | } 234 | 235 | public removeInstance(ins: OperatorInstance) { 236 | if (ins === this.operator) { 237 | return; 238 | } 239 | const def = this.operatorDef.getDef(); 240 | for (const src in def['connections']) { 241 | if (def['connections'].hasOwnProperty(src)) { 242 | if (this.operator.getPort(src).getOperator() === ins) { 243 | delete def['connections'][src]; 244 | continue; 245 | } 246 | def['connections'][src] = def['connections'][src].filter(dst => this.operator.getPort(dst).getOperator() !== ins); 247 | if (def['connections'][src].length === 0) { 248 | delete def['connections'][src]; 249 | } 250 | } 251 | } 252 | delete def['operators'][ins.getName()]; 253 | this.updateDef(def); 254 | } 255 | 256 | public removeConnection(conn: Connection) { 257 | const conns = this.operator.getConnections(); 258 | conns.delete(conn); 259 | const def = this.operatorDef.getDef(); 260 | const connsCpy = new Set(conns); 261 | normalizeConnections(connsCpy); 262 | def['connections'] = stringifyConnections(connsCpy); 263 | this.updateDef(def); 264 | } 265 | 266 | public addConnection(src: Port, dst: Port) { 267 | const conns = this.operator.getConnections(); 268 | conns.forEach(conn => { 269 | if (conn.getDestination() === dst) { 270 | conns.delete(conn); 271 | } 272 | }); 273 | conns.add(new Connection(src, dst)); 274 | const def = this.operatorDef.getDef(); 275 | const connsCpy = new Set(conns); 276 | normalizeConnections(connsCpy); 277 | def['connections'] = stringifyConnections(connsCpy); 278 | this.updateDef(def); 279 | } 280 | 281 | private updateInstance(ins: OperatorInstance) { 282 | this.broadcast.update(ins); 283 | // Also update connections 284 | this.operator.getConnections().forEach(conn => { 285 | if (conn.getSource().getOperator() === ins || conn.getDestination().getOperator() === ins) { 286 | this.broadcast.update(conn); 287 | } 288 | }); 289 | } 290 | 291 | // YAML 292 | public refresh(noPropDefs?: boolean) { 293 | if (!noPropDefs) { 294 | this.insPropDefs = new Map>(); 295 | } 296 | this.displayYaml(); 297 | this.displayVisual(); 298 | } 299 | 300 | public updateYaml(newYaml) { 301 | this.yamlRepr = newYaml; 302 | } 303 | 304 | public storeYaml() { 305 | try { 306 | const newDef = safeLoad(this.yamlRepr); 307 | this.updateDef(newDef); 308 | } catch (e) {} 309 | } 310 | 311 | private updateDef(def: any) { 312 | this.operatorDef.setDef(def); 313 | this.refresh(); 314 | } 315 | 316 | private displayYaml() { 317 | this.yamlRepr = safeDump(this.operatorDef.getDef()); 318 | } 319 | 320 | // Visual 321 | 322 | public selectInstance(ins: OperatorInstance) { 323 | this.mouse.setDragging(); 324 | this.selectedEntity.entity = ins; 325 | this.newInstanceName = ins.getName(); 326 | } 327 | 328 | public selectConnection(conn: Connection) { 329 | this.selectedEntity.entity = conn; 330 | } 331 | 332 | public isAnyEntitySelected(): boolean { 333 | return !!this.broadcast.getSelected(); 334 | } 335 | 336 | public isSelected(entity: any): boolean { 337 | return this.isAnyEntitySelected() && this.broadcast.getSelected() === entity; 338 | } 339 | 340 | public displayUserMessage(msg: string) { 341 | this.userMessage = msg; 342 | this.ref.detectChanges(); 343 | if (this.userMessageTimeout != null) { 344 | clearTimeout(this.userMessageTimeout); 345 | } 346 | const that = this; 347 | this.userMessageTimeout = setTimeout(function () { 348 | that.userMessage = ''; 349 | that.ref.detectChanges(); 350 | }, 5000); 351 | } 352 | 353 | public selectPort(port1: Port) { 354 | if (port1.isUnspecifiedGeneric()) { 355 | this.displayUserMessage(`Cannot connect unspecified generic port. Specify generic type '${port1.getGeneric()}'.`); 356 | return; 357 | } 358 | 359 | if (this.selectedEntity.entity && this.selectedEntity.entity instanceof Port) { 360 | const port2 = this.selectedEntity.entity as Port; 361 | 362 | if (port1.isGeneric() && !port2.isGeneric() && !port2.isTrigger()) { 363 | this.displayUserMessage(`Cannot connect generic port with non-generic port. Specify generic type '${port1.getGeneric()}'.`); 364 | return; 365 | } 366 | if (port2.isGeneric() && !port1.isGeneric() && !port1.isTrigger()) { 367 | this.displayUserMessage(`Cannot connect generic port with non-generic port. Specify generic type '${port2.getGeneric()}'.`); 368 | return; 369 | } 370 | if (port1.isGeneric() && port2.isGeneric() && port1.getGeneric() !== port2.getGeneric()) { 371 | this.displayUserMessage(`Cannot connect generic ports with differing names: ` + 372 | `'${port1.getGeneric()}' is not the same as '${port2.getGeneric()}'.`); 373 | return; 374 | } 375 | 376 | if (port1.getOperator() === this.operator) { 377 | if (port2.getOperator() === this.operator) { 378 | if (port1.isIn() && port2.isOut()) { 379 | this.addConnection(port1, port2); 380 | this.broadcast.select(null); 381 | return; 382 | } else if (port2.isIn() && port1.isOut()) { 383 | this.addConnection(port2, port1); 384 | this.broadcast.select(null); 385 | return; 386 | } 387 | } else { 388 | if (port1.isIn() && port2.isIn()) { 389 | this.addConnection(port1, port2); 390 | this.broadcast.select(null); 391 | return; 392 | } else if (port2.isOut() && port1.isOut()) { 393 | this.addConnection(port2, port1); 394 | this.broadcast.select(null); 395 | return; 396 | } 397 | } 398 | } else { 399 | if (port2.getOperator() === this.operator) { 400 | if (port2.isIn() && port1.isIn()) { 401 | this.addConnection(port2, port1); 402 | this.broadcast.select(null); 403 | return; 404 | } else if (port1.isOut() && port2.isOut()) { 405 | this.addConnection(port1, port2); 406 | this.broadcast.select(null); 407 | return; 408 | } 409 | } else { 410 | if (port1.isOut() && port2.isIn()) { 411 | this.addConnection(port1, port2); 412 | this.broadcast.select(null); 413 | return; 414 | } else if (port2.isOut() && port1.isIn()) { 415 | this.addConnection(port2, port1); 416 | this.broadcast.select(null); 417 | return; 418 | } 419 | } 420 | } 421 | this.selectedEntity.entity = port1; 422 | return; 423 | } else { 424 | this.selectedEntity.entity = port1; 425 | } 426 | } 427 | 428 | private displayVisual() { 429 | const def = this.operatorDef.getDef(); 430 | this.operator.updateOperator(def, undefined); 431 | this.broadcast.update(this.operator); 432 | } 433 | 434 | public addInstance(opr: OperatorDef) { 435 | const def = this.operatorDef.getDef(); 436 | const insName = this.getDistinctInstanceName(opr.getName()); 437 | def.operators[insName] = { 438 | operator: opr.getId() 439 | }; 440 | this.updateDef(def); 441 | } 442 | 443 | public getDistinctInstanceName(oprName: string) { 444 | const def = this.operatorDef.getDef(); 445 | const cleanInsName = oprName.replace(/[^a-zA-Z]+/g, ""); 446 | 447 | let insName = cleanInsName; 448 | let i = 1; 449 | if (!def.operators) { 450 | def.operators = {}; 451 | } 452 | while (def.operators[insName]) { 453 | insName = cleanInsName + i; 454 | i++; 455 | } 456 | 457 | return insName; 458 | } 459 | 460 | public getOperatorList(): Array { 461 | return [] 462 | .concat( 463 | Array.from(this.operators.getLocals().values()).filter(op => !this.operator || op !== this.operator.opDef), 464 | Array.from(this.operators.getLibraries().values()), 465 | Array.from(this.operators.getElementaries().values())); 466 | } 467 | 468 | public setUIMode(mode: string): string { 469 | this.uiMode = mode.toLowerCase(); 470 | this.ref.detectChanges(); 471 | return this.uiMode; 472 | } 473 | 474 | public isUIModeVisual(): boolean { 475 | return this.uiMode === 'visual'; 476 | } 477 | 478 | public isUIModeYAML(): boolean { 479 | return this.uiMode === 'yaml'; 480 | } 481 | 482 | public sidebarDefinitionChange() { 483 | this.refresh(); 484 | } 485 | 486 | public async startDebugging() { 487 | await this.save(); 488 | this.debugState = 'startDebugging'; 489 | this.ref.detectChanges(); 490 | } 491 | 492 | public stopOperator() { 493 | this.debugState = 'stopOperator'; 494 | this.ref.detectChanges(); 495 | } 496 | 497 | public debugStateChanged(newState: string) { 498 | this.ref.detectChanges(); 499 | } 500 | 501 | public running(): boolean { 502 | return ['debugging'].indexOf(this.debugState) !== -1; 503 | } 504 | 505 | } 506 | -------------------------------------------------------------------------------- /src/app/components/index.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 |
5 |
6 | 8 | 9 |
10 |
11 | 12 |
13 | 14 |
15 |
16 |
17 | 18 |
19 | 20 |
21 |
22 |
23 | 24 |
25 | 26 |
27 |

Support & Feedback

28 |

29 | We would love to hear from you! Be it suggestions, questions or remarks - your feedback is always 30 | welcome. 31 |

32 |
Do you have questions or suggestions?
33 | 48 |
Wanna leave us a message?
49 |
50 |
51 | 53 |
54 |
55 | 57 |
58 |
59 | 62 |
63 |
64 |
65 | Thank you!
66 | We really appreciate it 67 |
68 |
69 | 70 |
71 |
72 |
73 |
74 |
75 |
76 | -------------------------------------------------------------------------------- /src/app/components/index.component.scss: -------------------------------------------------------------------------------- 1 | @import "../../styles/variables.scss"; 2 | 3 | #sl-main-box { 4 | height: 100vh; 5 | width: 100%; 6 | border: 2px solid $orange; 7 | box-sizing: border-box; 8 | 9 | > div { 10 | display: inline-block; 11 | height: 100%; 12 | vertical-align: top; 13 | } 14 | 15 | #sl-main-content { 16 | width: 100%; 17 | 18 | > .row { 19 | margin: 0; 20 | } 21 | 22 | #sl-main-row { 23 | height: 100%; 24 | width: 100%; 25 | 26 | .input-group { 27 | margin-top: 10px; 28 | } 29 | 30 | #sl-operator-list { 31 | height: calc(100% - 94px); 32 | } 33 | 34 | .sl-col { 35 | height: 100%; 36 | } 37 | 38 | #sl-info-col { 39 | padding: 0; 40 | color: $dark-gray; 41 | background-color: $light; 42 | 43 | > iframe { 44 | border: 0; 45 | height: 100%; 46 | width: 100%; 47 | } 48 | 49 | #sl-feedback-box { 50 | color: $body-bg; 51 | background-color: $orange; 52 | position: absolute; 53 | right: 0; 54 | bottom: 0; 55 | padding: 15px; 56 | height: 600px; 57 | width: 371px; 58 | border-top-left-radius: 20px; 59 | 60 | h4 { 61 | margin-bottom: 25px; 62 | } 63 | 64 | h5 { 65 | margin-top: 20px; 66 | margin-bottom: 20px; 67 | } 68 | 69 | #sl-info-box { 70 | position: absolute; 71 | padding: 15px; 72 | bottom: 15px; 73 | right: 15px; 74 | width: 250px; 75 | height: 130px; 76 | 77 | #sl-logo { 78 | position: absolute; 79 | height: 85px; 80 | right: 0; 81 | bottom: 0; 82 | } 83 | } 84 | 85 | a { 86 | color: $white; 87 | } 88 | } 89 | } 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/app/components/index.component.ts: -------------------------------------------------------------------------------- 1 | import {Component} from '@angular/core'; 2 | import {OperatorService} from '../services/operator.service'; 3 | import {OperatorDef} from '../classes/operator'; 4 | import {Router} from '@angular/router'; 5 | import {HttpClient, HttpHeaders, HttpParams} from '@angular/common/http'; 6 | import * as initialDef from '../initial-def.json'; 7 | import {FileUploader} from 'ng2-file-upload'; 8 | import {ApiService} from '../services/api.service'; 9 | 10 | 11 | @Component({ 12 | templateUrl: './index.component.html', 13 | styleUrls: ['./index.component.scss'], 14 | }) 15 | export class IndexComponent { 16 | 17 | public newOperatorName = ''; 18 | public creatingOperatorFailed = false; 19 | 20 | public feedbackURL = 'https://bitspark.de/send-email'; 21 | public feedbackEmail = ''; 22 | public feedbackMessage = ''; 23 | public feedbackThankYou = false; 24 | 25 | public uploader: FileUploader; 26 | 27 | constructor(private api: ApiService, private http: HttpClient, private router: Router, public operators: OperatorService) { 28 | this.uploader = new FileUploader({url: this.api.uploadUrl(), itemAlias: 'file'}); 29 | this.uploader.onBeforeUploadItem = (item) => { 30 | item.withCredentials = false; 31 | }; 32 | } 33 | 34 | public async refreshOperators() { 35 | await this.operators.refresh(); 36 | } 37 | 38 | public async newOperator(newOperatorName: string) { 39 | const newOperator = new OperatorDef({ 40 | def: JSON.parse(JSON.stringify(initialDef['default'])), 41 | type: 'local', 42 | saved: false 43 | }); 44 | 45 | newOperator.setName(newOperatorName); 46 | 47 | this.creatingOperatorFailed = !await this.save(newOperator); 48 | if (!this.creatingOperatorFailed) { 49 | this.operators.addLocal(newOperator); 50 | await this.openOperator(newOperator); 51 | } 52 | } 53 | 54 | public async upload() { 55 | await this.uploader.uploadAll(); 56 | const that = this; 57 | setTimeout(async function () { 58 | await that.refreshOperators(); 59 | }, 2000); 60 | } 61 | 62 | public async save(opDef: OperatorDef): Promise { 63 | return await this.operators.storeDefinition(opDef.getDef()); 64 | } 65 | 66 | public async openOperator(operator: OperatorDef) { 67 | await this.router.navigate(['operator', operator.getId()]); 68 | } 69 | 70 | public getLocals(): Array { 71 | return Array 72 | .from(this.operators.getLocals().values()); 73 | } 74 | 75 | public sendFeedback() { 76 | const body = new HttpParams() 77 | .set('email', this.feedbackEmail) 78 | .set('message', this.feedbackMessage); 79 | 80 | this.http.post(this.feedbackURL, body.toString(), { 81 | headers: new HttpHeaders() 82 | .set('Content-Type', 'application/x-www-form-urlencoded') 83 | }).toPromise().then(response => { 84 | if (response) { 85 | this.feedbackEmail = ''; 86 | this.feedbackMessage = ''; 87 | this.feedbackThankYou = true; 88 | } 89 | }); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/app/components/instance.component.svg.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 13 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 88 | 89 | 90 | 91 | 92 | 97 | {{text()}} 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | -------------------------------------------------------------------------------- /src/app/components/instance.component.ts: -------------------------------------------------------------------------------- 1 | import {Component, Input, OnInit, ChangeDetectorRef, ChangeDetectionStrategy, OnDestroy} from '@angular/core'; 2 | import {Connection, OperatorInstance, Transformable} from '../classes/operator'; 3 | import {generateSvgTransform} from '../utils'; 4 | import {MouseService} from '../services/mouse.service'; 5 | import {BroadcastService} from '../services/broadcast.service'; 6 | 7 | @Component({ 8 | selector: 'app-instance,[app-instance]', 9 | templateUrl: './instance.component.svg.html', 10 | styleUrls: [], 11 | changeDetection: ChangeDetectionStrategy.OnPush 12 | }) 13 | export class InstanceComponent implements OnInit, OnDestroy { 14 | private callback: () => void; 15 | 16 | @Input() 17 | public aspect: string; 18 | 19 | public instance_: OperatorInstance; 20 | 21 | @Input() 22 | set instance(ins: OperatorInstance) { 23 | this.instance_ = ins; 24 | this.callback = this.broadcast.registerCallback(ins, () => { 25 | this.ref.detectChanges(); 26 | }); 27 | this.ref.detectChanges(); 28 | } 29 | 30 | get instance() { 31 | return this.instance_; 32 | } 33 | 34 | private fqn = ''; 35 | private id = ''; 36 | 37 | public constructor(private ref: ChangeDetectorRef, public broadcast: BroadcastService, public mouse: MouseService) { 38 | ref.detach(); 39 | } 40 | 41 | public getCSSClass(): any { 42 | const cssClass = {}; 43 | cssClass['selected'] = this.broadcast.isSelected(this.instance); 44 | cssClass['hovered'] = this.broadcast.isHovered(this.instance); 45 | cssClass['sl-svg-op-type'] = true; 46 | cssClass[this.instance.getOperatorType()] = true; 47 | return cssClass; 48 | } 49 | 50 | public ngOnInit() { 51 | this.id = this.instance.getID(); 52 | this.fqn = this.instance.getFullyQualifiedName(); 53 | this.ref.detectChanges(); 54 | } 55 | 56 | ngOnDestroy(): void { 57 | this.broadcast.unregisterCallback(this.instance, this.callback); 58 | } 59 | 60 | public transform(trans: Transformable): string { 61 | return generateSvgTransform(trans); 62 | } 63 | 64 | public form(): string { 65 | switch (this.id) { 66 | //case 'slang.data.Value': 67 | case '8b62495a-e482-4a3e-8020-0ab8a350ad2d': 68 | return 'circle'; 69 | default: 70 | return 'rect'; 71 | } 72 | } 73 | 74 | public radius(): number { 75 | return Math.max(this.instance.getWidth(), this.instance.getHeight()) / 2; 76 | } 77 | 78 | public text(): string { 79 | const props = this.instance.getProperties(); 80 | 81 | switch (this.id) { 82 | //case 'slang.data.Value': 83 | case '8b62495a-e482-4a3e-8020-0ab8a350ad2d': 84 | return !!props ? JSON.stringify(props['value']) : 'value?'; 85 | //case 'slang.data.Evaluate': 86 | case '37ccdc28-67b0-4bb1-8591-4e0e813e3ec1': 87 | return !!props ? props['expression'] : 'eval?'; 88 | //case 'slang.data.Convert': 89 | case 'd1191456-3583-4eaf-8ec1-e486c3818c60': 90 | return ''; 91 | default: 92 | return this.instance.getName(); 93 | } 94 | } 95 | 96 | public visualInstances(): Array { 97 | return Array.from(this.instance.getInstances().values()).filter(ins => ins.isVisible()); 98 | } 99 | 100 | public visualConnections(): Array { 101 | return Array.from(this.instance.getConnections().values()); 102 | } 103 | 104 | } 105 | -------------------------------------------------------------------------------- /src/app/components/operator-list.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 |
5 | 6 |
7 |
8 |
9 |

Your Local Operators

10 |
    11 |
  • 13 | {{ li.name }} 14 | 17 |
  • 18 |
19 |
20 |

Global Operators

21 |
    22 |
  • 24 | {{ li.name }} 25 | 28 |
  • 29 |
30 |
31 |
32 |
33 | -------------------------------------------------------------------------------- /src/app/components/operator-list.component.scss: -------------------------------------------------------------------------------- 1 | @import "../../styles/variables.scss"; 2 | 3 | .sl-ui-form-box { 4 | height: 34px; 5 | margin-bottom: $spacer; 6 | } 7 | 8 | .sl-ui-scrollable { 9 | height: calc(100% - 68px - 1.0rem); 10 | box-sizing: border-box; 11 | margin-bottom: 0.5rem; 12 | overflow: auto; 13 | } 14 | 15 | .list-group-item { 16 | color: $dark-gray; 17 | } 18 | 19 | .sl-form-box { 20 | padding-top: 8px; 21 | padding-bottom: 8px; 22 | } 23 | 24 | .sl-operator-list { 25 | margin-top: 2*$spacer; 26 | li { 27 | position: relative; 28 | padding: 0 $spacer; 29 | line-height: 1.4rem; 30 | overflow-wrap: break-word; 31 | } 32 | button { 33 | position: absolute; 34 | right: 0; 35 | line-height: 0; 36 | } 37 | .badge { 38 | padding: 8px; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/app/components/operator-list.component.ts: -------------------------------------------------------------------------------- 1 | import {ChangeDetectionStrategy, ChangeDetectorRef, Component, EventEmitter, Input, OnInit, Output} from '@angular/core'; 2 | import {OperatorDef} from '../classes/operator'; 3 | import {compareOperatorDefs} from '../utils'; 4 | 5 | @Component({ 6 | selector: 'app-operator-list', 7 | templateUrl: './operator-list.component.html', 8 | styleUrls: ['./operator-list.component.scss'], 9 | changeDetection: ChangeDetectionStrategy.OnPush 10 | }) 11 | export class OperatorListComponent implements OnInit { 12 | private operatorList_: Array; 13 | 14 | @Input() 15 | public set operatorList(list: Array) { 16 | this.operatorList_ = list; 17 | this.ref.detectChanges(); 18 | } 19 | 20 | public get operatorList() { 21 | return this.operatorList_; 22 | } 23 | 24 | @Input() 25 | public buttonIcon = ''; 26 | 27 | @Output() 28 | public operatorSelected = new EventEmitter(); 29 | 30 | public filterString = ''; 31 | 32 | constructor(private ref: ChangeDetectorRef) { 33 | ref.detach(); 34 | } 35 | 36 | private static groupOperatorList(opList: Array, 37 | opName: (n: string[]) => string): Array<{ newGroup: boolean, name: string, opDef: OperatorDef }> { 38 | let grpName = ''; 39 | const listItems: Array<{ newGroup: boolean, name: string, opDef: OperatorDef }> = []; 40 | for (const opDef of opList) { 41 | // "slang", "...", "..." 42 | let isNewGrp = false; 43 | const splitName = opDef.getName().split('.').filter(n => n !== 'slang'); 44 | 45 | if (splitName.length > 1) { 46 | const newGrp = splitName.shift(); 47 | if (isNewGrp = newGrp !== grpName) { 48 | grpName = newGrp; 49 | } 50 | } 51 | 52 | if (isNewGrp) { 53 | listItems.push({ 54 | newGroup: true, 55 | name: grpName, 56 | opDef: null, 57 | }); 58 | } 59 | listItems.push({ 60 | newGroup: false, 61 | name: opName(splitName), 62 | opDef: opDef, 63 | }); 64 | } 65 | return listItems; 66 | } 67 | 68 | ngOnInit() { 69 | this.ref.detectChanges(); 70 | } 71 | 72 | public hasGlobals(): boolean { 73 | return this.operatorList.find(op => op.isGlobal()) !== undefined; 74 | } 75 | 76 | public filteredOperatorList(): Array { 77 | return this.operatorList.filter(opDef => opDef.getName().toLowerCase().indexOf(this.filterString.toLowerCase()) !== -1); 78 | } 79 | 80 | public emitOperatorSelected(op: OperatorDef) { 81 | this.operatorSelected.emit(op); 82 | } 83 | 84 | public localOperatorList(): Array<{ newGroup: boolean, name: string, opDef: OperatorDef }> { 85 | return OperatorListComponent.groupOperatorList( 86 | this.filteredOperatorList() 87 | .filter(op => op.isLocal()) 88 | .sort(compareOperatorDefs), 89 | (opNameList: string[]) => opNameList.join('.')); 90 | } 91 | 92 | public globalOperatorList(): Array<{ newGroup: boolean, name: string, opDef: OperatorDef }> { 93 | return OperatorListComponent.groupOperatorList( 94 | this.filteredOperatorList() 95 | .filter(opDef => opDef.isGlobal()) 96 | .sort(compareOperatorDefs), 97 | (opNameList: string[]) => opNameList[opNameList.length - 1] 98 | ); 99 | } 100 | 101 | public filterStringChanged(filterString: string) { 102 | this.filterString = filterString; 103 | this.ref.detectChanges(); 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /src/app/components/port.component.svg.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 11 | 12 | 17 | 18 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 44 | {{text()}} 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /src/app/components/port.component.ts: -------------------------------------------------------------------------------- 1 | import {Component, Input, ChangeDetectorRef, ChangeDetectionStrategy, OnDestroy} from '@angular/core'; 2 | import {generateSvgTransform} from '../utils'; 3 | import {Port, Transformable, Type} from '../classes/operator'; 4 | import {Orientation} from '../classes/vector'; 5 | import {BroadcastService} from '../services/broadcast.service'; 6 | 7 | @Component({ 8 | selector: 'app-port,[app-port]', 9 | templateUrl: './port.component.svg.html', 10 | styleUrls: [], 11 | changeDetection: ChangeDetectionStrategy.OnPush 12 | }) 13 | export class PortComponent implements OnDestroy { 14 | private callback: () => void; 15 | 16 | constructor(private cd: ChangeDetectorRef, public broadcast: BroadcastService) { 17 | cd.detach(); 18 | } 19 | 20 | ngOnDestroy(): void { 21 | this.broadcast.unregisterCallback(this.port, this.callback); 22 | } 23 | 24 | @Input() 25 | public aspect: string; 26 | 27 | @Input() 28 | public port_: Port; 29 | 30 | @Input() 31 | set port(port: Port) { 32 | this.port_ = port; 33 | this.callback = this.broadcast.registerCallback(port, () => { 34 | this.cd.detectChanges(); 35 | }); 36 | this.cd.detectChanges(); 37 | } 38 | 39 | get port() { 40 | return this.port_; 41 | } 42 | 43 | public getCSSClass(): any { 44 | const cssClass = {}; 45 | 46 | cssClass['selected'] = this.broadcast.isSelected(this.port); 47 | cssClass['hovered'] = this.broadcast.isHovered(this.port); 48 | 49 | cssClass[Type[this.port.getType()]] = true; 50 | cssClass[this.port.getOrientation().name()] = true; 51 | 52 | cssClass['in'] = this.port.isIn(); 53 | cssClass['out'] = this.port.isOut(); 54 | 55 | return cssClass; 56 | } 57 | 58 | public getEntries(): Array { 59 | return Array.from(this.port.getMap().values()); 60 | } 61 | 62 | public transform(trans: Transformable): string { 63 | return generateSvgTransform(trans); 64 | } 65 | 66 | public translatePort(): string { 67 | const outer = this.port.getOperator().getParent() || this.port.getOperator(); 68 | return `translate(${this.port.getCenterX(outer)},${this.port.getCenterY(outer)})`; 69 | } 70 | 71 | public transformLabel(): string { 72 | return `rotate(-55 ${this.getPortLabelX()},${this.getPortLabelY()})`; 73 | } 74 | 75 | public text(): string { 76 | return this.port.getName()? `${this.port.getName()}:${this.port.getTypeName()}` : `${this.port.getTypeName()}`; 77 | } 78 | 79 | public getPortLabelX(): number { 80 | switch (this.port.getOrientation().value()) { 81 | case Orientation.north: 82 | return 0; 83 | case Orientation.west: 84 | return 15; 85 | case Orientation.south: 86 | return 0; 87 | case Orientation.east: 88 | return -15; 89 | } 90 | } 91 | 92 | public getPortLabelY(): number { 93 | switch (this.port.getOrientation().value()) { 94 | case Orientation.north: 95 | return 15; 96 | case Orientation.west: 97 | return 0; 98 | case Orientation.south: 99 | return -15; 100 | case Orientation.east: 101 | return 0; 102 | } 103 | } 104 | 105 | public getPortLabelAnchor(): string { 106 | switch (this.port.getOrientation().value()) { 107 | case Orientation.north: 108 | return 'end'; 109 | case Orientation.west: 110 | return 'begin'; 111 | case Orientation.south: 112 | return 'begin'; 113 | case Orientation.east: 114 | return 'end'; 115 | } 116 | } 117 | 118 | public getPortLabelCSSClass(): any { 119 | const cssClasses = {}; 120 | cssClasses['displayed'] = this.broadcast.isHovered(this.port) || this.broadcast.isSelected(this.port); 121 | return cssClasses; 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /src/app/components/preview-object.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 | 4 |
5 | 6 |
7 | {{toString(object)}} 8 |
9 | 10 | 11 |
12 |
13 | {{object.name}}, 14 |
15 | 16 |
17 |
18 |
19 | No image 20 |
21 |
22 | 23 |
24 |
25 | {{object.name}}, 26 |
27 |
28 | 29 |
30 |
31 |
32 | RGB48: {{colorRGB48(object)}}
33 | HEX: {{colorHex(object)}} 34 |
35 |
36 | 37 |
38 |
39 | 40 |
41 |
42 | 43 |
44 |
45 | {{item.key}}: 46 | 47 |
48 |
49 |
50 | -------------------------------------------------------------------------------- /src/app/components/preview-object.component.scss: -------------------------------------------------------------------------------- 1 | @import "../../styles/variables.scss"; 2 | 3 | .entry { 4 | margin-left: 5px; 5 | border-left: 1px solid $gray; 6 | padding-left: 2px; 7 | } 8 | 9 | .item { 10 | border-bottom: 1px dotted $gray; 11 | } 12 | 13 | div.value { 14 | display: inline-block; 15 | padding: 2px; 16 | margin: 2px; 17 | border-radius: 5px; 18 | } 19 | 20 | textarea.value { 21 | width: 300px; 22 | white-space: nowrap; 23 | overflow: scroll; 24 | } 25 | 26 | .inline { 27 | vertical-align: top; 28 | display: inline-block; 29 | } 30 | 31 | .stream-item { 32 | border: 1px solid $gray; 33 | margin: 5px; 34 | } 35 | 36 | .string { 37 | background-color: #984ea3; 38 | color: white; 39 | } 40 | 41 | .number { 42 | background-color: #377eb8; 43 | color: white; 44 | } 45 | 46 | .boolean { 47 | background-color: #1b9e77; 48 | color: white; 49 | } 50 | 51 | .binary { 52 | background-color: #FBEB56; 53 | color: black; 54 | } 55 | 56 | .primitive { 57 | background-color: #5bcbca; 58 | color: black; 59 | } 60 | 61 | .trigger { 62 | background-color: #767675; 63 | } 64 | 65 | .color-box { 66 | vertical-align: top; 67 | display: inline-block; 68 | width: 60px; 69 | height: 60px; 70 | } 71 | 72 | .color-details { 73 | vertical-align: middle; 74 | display: inline-block; 75 | padding: 5px; 76 | } 77 | -------------------------------------------------------------------------------- /src/app/components/preview-object.component.ts: -------------------------------------------------------------------------------- 1 | import {Component, Input} from '@angular/core'; 2 | import {DomSanitizer, SafeUrl} from '@angular/platform-browser'; 3 | import {isType} from '../utils'; 4 | 5 | @Component({ 6 | selector: 'app-preview-object', 7 | templateUrl: './preview-object.component.html', 8 | styleUrls: ['./preview-object.component.scss'] 9 | }) 10 | export class PreviewObjectComponent { 11 | @Input() 12 | public object: any; 13 | public expand = false; 14 | 15 | constructor(private sanitizer: DomSanitizer) { 16 | } 17 | 18 | public isPrimitive(obj: any): boolean { 19 | return ['string', 'number', 'boolean'].indexOf(typeof obj) !== -1; 20 | } 21 | 22 | public isPlaceholder(obj: any): boolean { 23 | return typeof obj === 'string' && (obj as string).startsWith('@PH '); 24 | } 25 | 26 | public colorClass(obj: any): string { 27 | if (typeof obj === 'string' && (obj as string).startsWith('base64:')) { 28 | return 'binary'; 29 | } 30 | return typeof obj; 31 | } 32 | 33 | public isImage(obj: any): boolean { 34 | return isType(obj, ['image', 'name']); 35 | } 36 | 37 | public isFile(obj: any): boolean { 38 | return isType(obj, ['file', 'name']); 39 | } 40 | 41 | public isColor(obj: any): boolean { 42 | return isType(obj, ['red', 'green', 'blue']); 43 | } 44 | 45 | public colorHex(obj: any): string { 46 | const rgbToHex = function (rgb) { 47 | let hex = Number(rgb).toString(16); 48 | if (hex.length < 2) { 49 | hex = '0' + hex; 50 | } 51 | return hex; 52 | }; 53 | 54 | return '#' + 55 | rgbToHex(Math.floor(obj.red / 256)) + 56 | rgbToHex(Math.floor(obj.green / 256)) + 57 | rgbToHex(Math.floor(obj.blue / 256)); 58 | } 59 | 60 | public colorRGB48(obj: any): string { 61 | return `R: ${Math.floor(obj.red)}, G: ${Math.floor(obj.green)}, B: ${Math.floor(obj.blue)}`; 62 | } 63 | 64 | public colorStyle(obj): any { 65 | return { 66 | 'background-color': `rgb(${obj.red / 255}, ${obj.green / 255}, ${obj.blue / 255})` 67 | }; 68 | } 69 | 70 | public imageSrc(obj: any): SafeUrl { 71 | return this.sanitizer.bypassSecurityTrustUrl('data:image/png;base64,' + (obj as string).substr(7)); 72 | } 73 | 74 | public fileDownload(file: string): SafeUrl { 75 | return this.sanitizer.bypassSecurityTrustUrl('data:image/png;base64,' + file.substr(7)); 76 | } 77 | 78 | public isStream(obj: any): boolean { 79 | return Array.isArray(obj); 80 | } 81 | 82 | public isMap(obj: any): boolean { 83 | return !this.isImage(obj) && !this.isFile(obj) && !this.isColor(obj) && !Array.isArray(obj) && typeof obj === 'object'; 84 | } 85 | 86 | public toString(obj: any): string { 87 | const str = obj.toString(); 88 | if (str.length < 64) { 89 | return str; 90 | } 91 | return `${str.substr(0, 40)}... (${str.length})`; 92 | } 93 | } 94 | 95 | -------------------------------------------------------------------------------- /src/app/components/type-def-form.component.html: -------------------------------------------------------------------------------- 1 |
2 | 7 | 8 |
9 |

10 | 11 | 12 | 13 |

14 |
15 | 16 | 17 | 22 |
23 | 24 | 25 | 26 |
27 | -------------------------------------------------------------------------------- /src/app/components/type-def-form.component.scss: -------------------------------------------------------------------------------- 1 | @import "../../styles/variables.scss"; 2 | 3 | select { 4 | height: 26px; 5 | } 6 | 7 | .sl-map-box { 8 | border-left: 3px solid $pane-border-color; 9 | } 10 | -------------------------------------------------------------------------------- /src/app/components/type-def-form.component.ts: -------------------------------------------------------------------------------- 1 | import {ChangeDetectionStrategy, ChangeDetectorRef, Component, EventEmitter, Input, OnInit, Output} from '@angular/core'; 2 | import {Identifiable, OperatorDef, Type} from '../classes/operator'; 3 | import {BroadcastService} from '../services/broadcast.service'; 4 | 5 | @Component({ 6 | selector: 'app-type-def-form', 7 | templateUrl: './type-def-form.component.html', 8 | styleUrls: ['./type-def-form.component.scss'], 9 | changeDetection: ChangeDetectionStrategy.OnPush 10 | }) 11 | export class TypeDefFormComponent implements OnInit { 12 | public typeDef_: any = TypeDefFormComponent.newDefaultTypeDef('primitive'); 13 | 14 | get typeDef() { 15 | return this.typeDef_; 16 | } 17 | 18 | @Output() typeDefChange: EventEmitter = new EventEmitter(); 19 | 20 | @Input() 21 | set typeDef(val) { 22 | this.typeDef_ = val; 23 | this.mapToSubs(); 24 | this.ref.detectChanges(); 25 | } 26 | 27 | @Input() 28 | public broadcastTo: Identifiable; 29 | 30 | public subs: Array<{ name: string, def: any }> = []; 31 | public types = Object.keys(Type).filter(t => typeof Type[t] === 'number'); 32 | public newSubName = ''; 33 | public newSubType = 'primitive'; 34 | 35 | constructor(private ref: ChangeDetectorRef, private broadcast: BroadcastService) { 36 | ref.detach(); 37 | } 38 | 39 | public static newDefaultTypeDef(type: string): any { 40 | switch (type) { 41 | case 'primitive': 42 | case 'string': 43 | case 'binary': 44 | case 'number': 45 | case 'boolean': 46 | case 'trigger': 47 | return { 48 | type: type 49 | }; 50 | case 'generic': 51 | return { 52 | type: type, 53 | generic: 'itemType' 54 | }; 55 | case 'stream': 56 | return { 57 | type: type, 58 | stream: { 59 | type: 'primitive' 60 | } 61 | }; 62 | case 'map': 63 | return { 64 | type: type, 65 | map: { 66 | defaultEntry: { 67 | type: 'primitive' 68 | } 69 | } 70 | }; 71 | } 72 | } 73 | 74 | ngOnInit() { 75 | this.mapToSubs(); 76 | } 77 | 78 | public mapToSubs(): any { 79 | this.subs = []; 80 | if (OperatorDef.isMap(this.typeDef)) { 81 | this.subs = Object.keys(this.typeDef.map).map(portName => { 82 | return {name: portName, def: this.typeDef.map[portName]}; 83 | }); 84 | } 85 | } 86 | 87 | public subsToMap(): any { 88 | if (OperatorDef.isMap(this.typeDef)) { 89 | this.typeDef.map = {}; 90 | this.subs.forEach(curr => { 91 | this.typeDef.map[curr.name] = curr.def; 92 | }); 93 | } 94 | } 95 | 96 | public setType(tp: string) { 97 | for (const k in this.typeDef) { 98 | if (k !== 'type' && this.typeDef.hasOwnProperty(k)) { 99 | delete this.typeDef[k]; 100 | } 101 | } 102 | switch (tp) { 103 | case 'map': 104 | this.subs = [{name: 'entryName', def: TypeDefFormComponent.newDefaultTypeDef('primitive')}]; 105 | break; 106 | case 'stream': 107 | this.typeDef[tp] = TypeDefFormComponent.newDefaultTypeDef('primitive'); 108 | break; 109 | case 'generic': 110 | this.typeDef[tp] = 'itemType'; 111 | break; 112 | } 113 | this.typeDefChanged(); 114 | this.ref.detectChanges(); 115 | } 116 | 117 | private getSub(name: string): any | null { 118 | return this.subs.find(curr => curr.name === name); 119 | } 120 | 121 | private getMapEntryIndex(name: string): number { 122 | return this.subs.findIndex(curr => curr.name === name); 123 | } 124 | 125 | public addSub(name: string, type: string) { 126 | if (!this.validPortName(name)) { 127 | return; 128 | } 129 | this.subs.push({name: name, def: TypeDefFormComponent.newDefaultTypeDef(type)}); 130 | this.resetNewMapPortName(); 131 | this.typeDefChanged(); 132 | this.ref.detectChanges(); 133 | } 134 | 135 | public renameSubName(oldName, newName: string) { 136 | if (!newName) { 137 | return; 138 | } 139 | const collidingMapEntry = this.getSub(newName); 140 | if (collidingMapEntry) { 141 | return; 142 | } 143 | const existingMapEntry = this.getSub(oldName); 144 | if (!existingMapEntry) { 145 | return; 146 | } 147 | existingMapEntry.name = newName; 148 | this.typeDefChanged(); 149 | } 150 | 151 | public renameGenericName(newName: string) { 152 | this.typeDefChanged(); 153 | } 154 | 155 | public removeSub(name: string) { 156 | const idx = this.getMapEntryIndex(name); 157 | if (idx > -1) { 158 | this.subs.splice(idx, 1); 159 | } 160 | this.typeDefChanged(); 161 | this.ref.detectChanges(); 162 | } 163 | 164 | public setMapPortName(name: string) { 165 | this.newSubName = name; 166 | this.ref.detectChanges(); 167 | } 168 | 169 | public typeDefChanged() { 170 | this.subsToMap(); 171 | this.typeDefChange.emit(this.typeDef); 172 | if (!!this.broadcastTo) { 173 | this.broadcast.update(this.broadcastTo); 174 | } 175 | } 176 | 177 | public resetNewMapPortName() { 178 | this.newSubName = ''; 179 | } 180 | 181 | public isMap(): boolean { 182 | return OperatorDef.isMap(this.typeDef); 183 | } 184 | 185 | public isStream(): boolean { 186 | return OperatorDef.isStream(this.typeDef); 187 | } 188 | 189 | public isGeneric(): boolean { 190 | return OperatorDef.isGeneric(this.typeDef); 191 | } 192 | 193 | public validPortName(name: string): boolean { 194 | return name.length > 0 && !this.getSub(name); 195 | } 196 | 197 | } 198 | -------------------------------------------------------------------------------- /src/app/components/type-value-form.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 | 4 |
5 |
6 |
7 |
8 | 9 |
10 |
11 | 12 |
13 |
14 | 15 |
16 |
17 | 18 |
19 |
20 | 21 |
22 |
23 | 24 |
25 |
26 | • Trigger 27 |
28 | 29 |
30 |
31 | {{key}} 32 | 33 |
34 |
35 | 36 |
37 |
38 | 39 | {{i + 1}}. 40 | 41 |
42 | 43 |
44 |
45 |
46 | Image file: 47 | 48 |
49 |
50 | File: 51 | 52 |
53 |
54 |
55 | -------------------------------------------------------------------------------- /src/app/components/type-value-form.component.scss: -------------------------------------------------------------------------------- 1 | @import "../../styles/variables.scss"; 2 | 3 | select { 4 | height: 26px; 5 | } 6 | 7 | .sl-map-box { 8 | border-left: 3px solid $pane-border-color; 9 | } 10 | -------------------------------------------------------------------------------- /src/app/components/type-value-form.component.ts: -------------------------------------------------------------------------------- 1 | import { 2 | ChangeDetectionStrategy, 3 | ChangeDetectorRef, 4 | Component, 5 | EventEmitter, 6 | Input, 7 | OnChanges, OnDestroy, 8 | OnInit, 9 | Output, 10 | SimpleChanges 11 | } from '@angular/core'; 12 | import {createDefaultValue} from '../utils'; 13 | import {Identifiable} from '../classes/operator'; 14 | import {BroadcastService} from '../services/broadcast.service'; 15 | import * as deepEqual from 'deep-equal'; 16 | 17 | @Component({ 18 | selector: 'app-type-value-form', 19 | templateUrl: './type-value-form.component.html', 20 | styleUrls: ['./type-value-form.component.scss'], 21 | changeDetection: ChangeDetectionStrategy.OnPush 22 | }) 23 | export class TypeValueFormComponent implements OnInit, OnDestroy, OnChanges { 24 | 25 | private specialTypes = { 26 | 'file': { 27 | type: 'map', 28 | map: { 29 | 'file': { 30 | type: 'binary' 31 | }, 32 | 'name': { 33 | type: 'string' 34 | } 35 | } 36 | }, 37 | 'image': { 38 | type: 'map', 39 | map: { 40 | 'image': { 41 | type: 'binary' 42 | }, 43 | 'name': { 44 | type: 'string' 45 | } 46 | } 47 | } 48 | }; 49 | 50 | constructor(private ref: ChangeDetectorRef, private broadcast: BroadcastService) { 51 | ref.detach(); 52 | } 53 | 54 | // TYPE DEF 55 | private oldTypeDef_: any; 56 | private typeDef_: any; 57 | 58 | get typeDef() { 59 | return this.typeDef_; 60 | } 61 | 62 | @Input() 63 | set typeDef(val) { 64 | this.typeDef_ = val; 65 | if (this.typeValue) { 66 | this.ref.detectChanges(); 67 | } 68 | } 69 | 70 | // TYPE VALUE 71 | private typeVal_: any; 72 | 73 | @Output() 74 | public typeValueChange = new EventEmitter(); 75 | 76 | get typeValue() { 77 | return this.typeVal_; 78 | } 79 | 80 | @Input() 81 | set typeValue(val) { 82 | this.typeVal_ = val; 83 | this.ref.detectChanges(); 84 | } 85 | 86 | // TYPE DEF CHANGE CALLBACK 87 | 88 | private callback: any; 89 | 90 | @Input() 91 | public subscribe: Identifiable; 92 | 93 | ngOnInit() { 94 | if (!!this.subscribe) { 95 | this.oldTypeDef_ = JSON.parse(JSON.stringify(this.typeDef)); 96 | this.callback = this.broadcast.registerCallback(this.subscribe, () => { 97 | if (!deepEqual(this.typeDef, this.oldTypeDef_)) { 98 | this.typeValue = createDefaultValue(this.typeDef); 99 | this.emitChange(); 100 | } 101 | this.ref.detectChanges(); 102 | this.oldTypeDef_ = JSON.parse(JSON.stringify(this.typeDef)); 103 | }); 104 | } 105 | } 106 | 107 | ngOnDestroy() { 108 | if (!!this.subscribe) { 109 | this.broadcast.unregisterCallback(this.subscribe, this.callback); 110 | } 111 | } 112 | 113 | ngOnChanges(changes: SimpleChanges): void { 114 | } 115 | 116 | public emitChange() { 117 | this.typeValueChange.emit(this.typeVal_); 118 | } 119 | 120 | public getEntries(): Array { 121 | const entries = []; 122 | if (this.typeDef.type === 'map') { 123 | for (const key in this.typeDef.map) { 124 | if (this.typeDef.map.hasOwnProperty(key)) { 125 | entries.push(key); 126 | } 127 | } 128 | } else if (this.typeValue) { 129 | for (let i = 0; i < this.typeValue.length; i++) { 130 | entries.push(i); 131 | } 132 | } 133 | return entries; 134 | } 135 | 136 | public add(): void { 137 | const ne = createDefaultValue(this.typeDef.stream); 138 | this.typeValue.push(ne); 139 | this.emitChange(); 140 | this.ref.detectChanges(); 141 | } 142 | 143 | public setIndex(i: number, val: any) { 144 | this.typeValue[i] = val; 145 | this.emitChange(); 146 | } 147 | 148 | public removeIndex(i: number) { 149 | this.typeValue.splice(i, 1); 150 | this.emitChange(); 151 | this.ref.detectChanges(); 152 | } 153 | 154 | public selectFile(event) { 155 | const special = this.specialType(); 156 | 157 | const file = event.srcElement.files[0]; 158 | const reader = new FileReader(); 159 | const that = this; 160 | reader.onload = function () { 161 | const data = reader.result; 162 | const base64 = data.substr(data.indexOf(',') + 1); 163 | if (!special) { 164 | that.typeValue = 'base64:' + base64; 165 | } else { 166 | switch (special) { 167 | case 'file': 168 | that.typeValue.name = file.name; 169 | that.typeValue.file = 'base64:' + base64; 170 | break; 171 | case 'image': 172 | that.typeValue.name = file.name; 173 | that.typeValue.image = 'base64:' + base64; 174 | break; 175 | } 176 | } 177 | }; 178 | reader.readAsDataURL(file); 179 | } 180 | 181 | public mapContains(def: any, test: any): boolean { 182 | if (typeof def !== 'object' || typeof test !== 'object') { 183 | return def === test; 184 | } 185 | for (const entry in def) { 186 | if (def.hasOwnProperty(entry)) { 187 | if (!test[entry]) { 188 | return false; 189 | } 190 | if (!this.mapContains(def[entry], test[entry])) { 191 | return false; 192 | } 193 | } 194 | } 195 | return true; 196 | } 197 | 198 | public hasType(def: any, test: any): boolean { 199 | return this.mapContains(def, test) && this.mapContains(test, def); 200 | } 201 | 202 | public specialType(): string { 203 | for (const spec in this.specialTypes) { 204 | if (this.specialTypes.hasOwnProperty(spec)) { 205 | const specType = this.specialTypes[spec]; 206 | if (this.hasType(this.typeDef, specType)) { 207 | return spec; 208 | } 209 | } 210 | } 211 | return undefined; 212 | } 213 | 214 | public propertyRedirect(): boolean { 215 | return typeof this.typeValue === 'string' && this.typeValue.startsWith('$'); 216 | } 217 | 218 | } 219 | -------------------------------------------------------------------------------- /src/app/initial-def.json: -------------------------------------------------------------------------------- 1 | { 2 | "meta": { 3 | "name": "unnamed" 4 | }, 5 | "services": { 6 | "main": { 7 | "in": { 8 | "type": "number" 9 | }, 10 | "out": { 11 | "type": "number" 12 | } 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/app/services/api.service.ts: -------------------------------------------------------------------------------- 1 | import {Injectable} from '@angular/core'; 2 | import {HttpClient} from '@angular/common/http'; 3 | import {environment} from '../../environments/environment'; 4 | 5 | @Injectable() 6 | export class ApiService { 7 | private static host = environment.daemon; 8 | 9 | constructor(private http: HttpClient) { 10 | } 11 | 12 | public async get(path: string, getParams?: any): Promise { 13 | return this.http.get(ApiService.host + path, { 14 | params: getParams 15 | }).toPromise(); 16 | } 17 | 18 | public async post(path: string, getParams: any, postData: any): Promise { 19 | return this.http.post(ApiService.host + path, postData, { 20 | params: getParams, 21 | responseType: 'json' 22 | }).toPromise(); 23 | } 24 | 25 | public async delete(path: string, getParams: any, postData: any): Promise { 26 | return this.http.request('delete', ApiService.host + path, { 27 | body: postData 28 | }).toPromise(); 29 | } 30 | 31 | public downloadUrl(fqop: string): string { 32 | return `${ApiService.host}/share/export?fqop=${fqop}`; 33 | } 34 | 35 | public uploadUrl(): string { 36 | return `${ApiService.host}/share/import`; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/app/services/broadcast.service.ts: -------------------------------------------------------------------------------- 1 | import {Injectable} from '@angular/core'; 2 | import {ApiService} from './api.service'; 3 | import {Identifiable} from '../classes/operator'; 4 | 5 | @Injectable() 6 | export class BroadcastService { 7 | private selectedEntity: Identifiable = null; 8 | private hoveredEntity: Identifiable = null; 9 | 10 | private updateSubscriptions: Map void>>; 11 | private selectEntitySubscriptions: Array<(Identifiable) => void>; 12 | 13 | constructor() { 14 | this.updateSubscriptions = new Map void>>(); 15 | this.selectEntitySubscriptions = []; 16 | } 17 | 18 | // HOVERING AND SELECTING 19 | 20 | public clearUpdateCallbacks() { 21 | this.updateSubscriptions = new Map void>>(); 22 | } 23 | 24 | public hover(obj: Identifiable) { 25 | const oldObj = this.hoveredEntity; 26 | this.hoveredEntity = obj; 27 | this.update(obj); 28 | this.update(oldObj); 29 | } 30 | 31 | public select(obj: Identifiable) { 32 | const oldObj = this.selectedEntity; 33 | this.selectedEntity = obj; 34 | this.update(obj); 35 | this.update(oldObj); 36 | this.broadcastSelect(obj); 37 | } 38 | 39 | public isHovered(obj: Identifiable): boolean { 40 | if (!this.hoveredEntity) { 41 | return false; 42 | } 43 | return this.hoveredEntity.getIdentity() === obj.getIdentity(); 44 | } 45 | 46 | public isSelected(obj: Identifiable): boolean { 47 | if (!this.selectedEntity) { 48 | return false; 49 | } 50 | return this.selectedEntity.getIdentity() === obj.getIdentity(); 51 | } 52 | 53 | public getHovered(): Identifiable { 54 | return this.hoveredEntity; 55 | } 56 | 57 | public getSelected(): Identifiable { 58 | return this.selectedEntity; 59 | } 60 | 61 | public subscribeSelect(callback: (Identifiable) => void): (Identifiable) => void { 62 | this.selectEntitySubscriptions.push(callback); 63 | return callback; 64 | } 65 | 66 | public unsubscribeSelect(callback: (Identifiable) => void) { 67 | const index = this.selectEntitySubscriptions.indexOf(callback); 68 | if (index !== -1) { 69 | this.selectEntitySubscriptions.splice(index, 1); 70 | } 71 | } 72 | 73 | private broadcastSelect(obj: Identifiable): void { 74 | for (const callback of this.selectEntitySubscriptions) { 75 | callback(obj); 76 | } 77 | } 78 | 79 | // CALLBACK HANDLING 80 | 81 | public registerCallback(obj: Identifiable, callback: () => void): () => void { 82 | const id = obj.getIdentity(); 83 | const callbacks = this.updateSubscriptions.get(id); 84 | if (callbacks) { 85 | callbacks.push(callback); 86 | } else { 87 | this.updateSubscriptions.set(id, [callback]); 88 | } 89 | return callback; 90 | } 91 | 92 | public unregisterCallback(obj: Identifiable, callback: () => void) { 93 | const id = obj.getIdentity(); 94 | const callbacks = this.updateSubscriptions.get(id); 95 | if (callbacks) { 96 | const index = callbacks.indexOf(callback); 97 | if (index !== -1) { 98 | callbacks.splice(index, 1); 99 | } 100 | } 101 | } 102 | 103 | public update(obj: Identifiable) { 104 | if (!obj) { 105 | return; 106 | } 107 | const id = obj.getIdentity(); 108 | const callbacks = this.updateSubscriptions.get(id); 109 | if (callbacks) { 110 | for (const callback of callbacks) { 111 | callback(); 112 | } 113 | } 114 | } 115 | 116 | } 117 | -------------------------------------------------------------------------------- /src/app/services/mouse.service.ts: -------------------------------------------------------------------------------- 1 | import {Injectable} from '@angular/core'; 2 | 3 | @Injectable() 4 | export class MouseService { 5 | 6 | private lastX: number; 7 | private lastY: number; 8 | 9 | private moving: boolean; 10 | private actionType = ''; 11 | 12 | private callbacks: Array<(event: string, actionPhase: string) => void>; 13 | 14 | constructor() { 15 | this.callbacks = []; 16 | } 17 | 18 | public getLastX(): number { 19 | return this.lastX; 20 | } 21 | 22 | public getLastY(): number { 23 | return this.lastY; 24 | } 25 | 26 | public setResizing() { 27 | this.actionType = 'resize'; 28 | } 29 | 30 | public setDragging() { 31 | this.actionType = 'drag'; 32 | } 33 | 34 | public isResizing() { 35 | return this.actionType === 'resize'; 36 | } 37 | 38 | public isDragging() { 39 | return this.actionType === 'drag'; 40 | } 41 | 42 | public start(event: any) { 43 | this.moving = true; 44 | this.broadcast(event, 'start'); 45 | this.lastX = event.screenX; 46 | this.lastY = event.screenY; 47 | return false; 48 | } 49 | 50 | public stop(event: any) { 51 | this.moving = false; 52 | this.broadcast(event, 'stop'); 53 | this.lastX = event.screenX; 54 | this.lastY = event.screenY; 55 | this.actionType = ''; 56 | return false; 57 | } 58 | 59 | public track(event: any) { 60 | if (event.buttons === 0) { 61 | this.moving = false; 62 | } 63 | if (this.moving) { 64 | this.broadcast(event, 'ongoing'); 65 | this.lastX = event.screenX; 66 | this.lastY = event.screenY; 67 | } 68 | return false; 69 | } 70 | 71 | public unsubscribe(callback: (event: string, actionPhase: string) => void) { 72 | const index = this.callbacks.indexOf(callback); 73 | if (index !== -1) { 74 | this.callbacks.splice(index, 1); 75 | } 76 | } 77 | 78 | public subscribe(callback: (event: string, actionPhase: string) => void): (event: string, actionPhase: string) => void { 79 | this.callbacks.push(callback); 80 | return callback; 81 | } 82 | 83 | private broadcast(event: string, actionPhase: string) { 84 | for (const callback of this.callbacks) { 85 | callback(event, actionPhase); 86 | } 87 | } 88 | 89 | } 90 | -------------------------------------------------------------------------------- /src/app/services/operator.service.ts: -------------------------------------------------------------------------------- 1 | import {EventEmitter, Injectable} from '@angular/core'; 2 | import {Observable} from 'rxjs'; 3 | import {ApiService} from './api.service'; 4 | import {OperatorDef} from '../classes/operator'; 5 | 6 | @Injectable() 7 | export class OperatorService { 8 | private static pathOperatorDefList = '/operator/'; 9 | private static pathOperatorDef = '/operator/def/'; 10 | 11 | private localOperators = new Set(); 12 | private libraryOperators = new Set(); 13 | private elementaryOperators = new Set(); 14 | private loadedEmitter: EventEmitter; 15 | 16 | constructor(private api: ApiService) { 17 | this.loadedEmitter = new EventEmitter(); 18 | this.refresh(); 19 | } 20 | 21 | public async refresh() { 22 | const response = await this.api.get(OperatorService.pathOperatorDefList); 23 | this.localOperators = new Set(); 24 | this.libraryOperators = new Set(); 25 | this.elementaryOperators = new Set(); 26 | 27 | for (const operatorData of (response['objects'] as Array)) { 28 | operatorData.saved = true; 29 | const operator = new OperatorDef(operatorData); 30 | switch (operator.getType()) { 31 | case 'local': 32 | this.localOperators.add(operator); 33 | break; 34 | case 'library': 35 | this.libraryOperators.add(operator); 36 | break; 37 | case 'elementary': 38 | this.elementaryOperators.add(operator); 39 | break; 40 | default: 41 | // TODO 42 | } 43 | } 44 | this.loadedEmitter.emit(true); 45 | /* } else { 46 | // TODO 47 | this.loadedEmitter.emit(false); 48 | }*/ 49 | } 50 | 51 | public async storeDefinition(def: any): Promise { 52 | return new Promise(async resolve => { 53 | await this.api.post(OperatorService.pathOperatorDef, {}, def) 54 | .catch((err) => { 55 | resolve(false) 56 | }); 57 | resolve(true); 58 | }); 59 | } 60 | 61 | public getLocals(): Set { 62 | return this.localOperators; 63 | } 64 | 65 | public getLibraries(): Set { 66 | return this.libraryOperators; 67 | } 68 | 69 | public getElementaries(): Set { 70 | return this.elementaryOperators; 71 | } 72 | 73 | public addLocal(operator: OperatorDef) { 74 | this.localOperators.add(operator); 75 | } 76 | 77 | public getLocal(operatorId: string): OperatorDef { 78 | return Array.from(this.localOperators.values()).find(op => op.getId() === operatorId); 79 | } 80 | 81 | public getLibrary(operatorId: string): OperatorDef { 82 | return Array.from(this.libraryOperators.values()).find(op => op.getId() === operatorId); 83 | } 84 | 85 | public getElementary(operatorId: string): OperatorDef { 86 | return Array.from(this.elementaryOperators.values()).find(op => op.getId() === operatorId); 87 | } 88 | 89 | public getOperator(operatorId: string): [OperatorDef, string] { 90 | let op = this.getLocal(operatorId); 91 | if (op) { 92 | return [op, 'local']; 93 | } 94 | op = this.getLibrary(operatorId); 95 | if (op) { 96 | return [op, 'library']; 97 | } 98 | op = this.getElementary(operatorId); 99 | if (op) { 100 | return [op, 'elementary']; 101 | } 102 | return null; 103 | } 104 | 105 | public getLoadingObservable(): Observable { 106 | return this.loadedEmitter; 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /src/app/services/visual.service.ts: -------------------------------------------------------------------------------- 1 | import {Injectable} from '@angular/core'; 2 | import {ApiService} from './api.service'; 3 | import {Identifiable} from '../classes/operator'; 4 | import { resolve } from 'url'; 5 | 6 | @Injectable() 7 | export class VisualService { 8 | private static pathMetaVisual = '/operator/meta/visual/'; 9 | 10 | constructor(private api: ApiService) { 11 | } 12 | 13 | public loadVisual(opName: string): Promise { 14 | return new Promise(async resolve => { 15 | const resp = await this.api.get(VisualService.pathMetaVisual, {fqop: opName}).catch( 16 | err => { 17 | return; 18 | } 19 | ); 20 | if (resp) { 21 | resolve(resp['data']); 22 | } 23 | resolve(); 24 | }); 25 | } 26 | 27 | public async storeVisual(opName: string, visual: any) { 28 | return new Promise(async resolve => { 29 | //await this.api.post(VisualService.pathMetaVisual, {fqop: opName}, visual); 30 | resolve(); 31 | }); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/app/utils.ts: -------------------------------------------------------------------------------- 1 | import {Connection, OperatorDef, OperatorInstance, Port, Transformable} from './classes/operator'; 2 | import {Vec2} from './classes/vector'; 3 | 4 | 5 | function expandExpressionPart(exprPart: string, props: any, propDefs: any): Array { 6 | const vals = []; 7 | if (!props) { 8 | return vals; 9 | } 10 | const prop = props[exprPart]; 11 | if (!prop) { 12 | return []; 13 | } 14 | const propDef = propDefs[exprPart]; 15 | if (propDef['type'] === 'stream') { 16 | if (typeof prop === 'string' && (prop as string).startsWith('$')) { 17 | vals.push(`{${prop.substr(1)}}`); 18 | } else { 19 | for (const el of prop) { 20 | if (typeof el !== 'string') { 21 | vals.push(JSON.stringify(el)); 22 | } else { 23 | vals.push(el); 24 | } 25 | } 26 | } 27 | } else { 28 | if (typeof prop !== 'string') { 29 | vals.push(JSON.stringify(prop)); 30 | } else { 31 | vals.push(prop); 32 | } 33 | } 34 | return vals; 35 | } 36 | 37 | export function uuidv4() { 38 | return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { 39 | var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8); 40 | return v.toString(16); 41 | }); 42 | } 43 | 44 | export function expandProperties(str: string, props: any, propDefs: any): Array { 45 | let exprs = [str]; 46 | for (const expr of exprs) { 47 | const parts = /{(.*?)}/.exec(expr); 48 | if (!parts) { 49 | break; 50 | } 51 | 52 | // This could be extended with more complex logic in the future 53 | const vals = expandExpressionPart(parts[1], props, propDefs); 54 | 55 | // Actual replacement 56 | const newExprs = []; 57 | for (const val of vals) { 58 | for (const e of exprs) { 59 | newExprs.push(e.replace(parts[0], val)); 60 | } 61 | } 62 | exprs = newExprs; 63 | } 64 | return exprs; 65 | } 66 | 67 | export function generateSvgTransform(t: Transformable): string { 68 | const cols = t.col(0).slice(0, 2).concat(t.col(1).slice(0, 2).concat(t.col(2).slice(0, 2))); 69 | return `matrix(${cols.join(',')})`; 70 | } 71 | 72 | function normalizeStreams(conns: Set): boolean { 73 | let modified = false; 74 | conns.forEach(conn => { 75 | if (conn.getSource().getParentPort() && conn.getDestination().getParentPort() && 76 | conn.getSource().getParentPort().isStream() && conn.getDestination().getParentPort().isStream()) { 77 | conns.delete(conn); 78 | conns.add(new Connection(conn.getSource().getParentPort(), conn.getDestination().getParentPort())); 79 | modified = true; 80 | } 81 | }); 82 | return modified; 83 | } 84 | 85 | const FoundException = {}; 86 | const NotFoundException = {}; 87 | 88 | function containsConnection(conns: Set, src: Port, dst: Port): boolean { 89 | try { 90 | conns.forEach(searchConn => { 91 | if (searchConn.getSource() === src && searchConn.getDestination() === dst) { 92 | throw FoundException; 93 | } 94 | }); 95 | } catch (e) { 96 | if (e !== FoundException) { 97 | throw e; 98 | } 99 | return true; 100 | } 101 | return false; 102 | } 103 | 104 | function normalizeMaps(conns: Set): boolean { 105 | let modified = false; 106 | conns.forEach(conn => { 107 | const srcMap = conn.getSource().getParentPort(); 108 | const dstMap = conn.getDestination().getParentPort(); 109 | if (srcMap && dstMap && srcMap.isMap() && dstMap.isMap()) { 110 | // First, check if parent map is already connected 111 | // In that case we don't need to do anything 112 | if (containsConnection(conns, srcMap, dstMap)) { 113 | return; 114 | } 115 | 116 | // Look if all siblings are connected as well 117 | 118 | let connected = true; 119 | // Look if source map is completely connected 120 | try { 121 | srcMap.getMap().forEach((entry, entryName) => { 122 | const dstEntry = dstMap.getMap().get(entryName); 123 | if (!dstEntry) { 124 | throw NotFoundException; 125 | } 126 | if (!containsConnection(conns, entry, dstEntry)) { 127 | connected = false; 128 | } 129 | }); 130 | } catch (e) { 131 | if (e !== NotFoundException) { 132 | throw e; 133 | } 134 | return; 135 | } 136 | if (!connected) { 137 | return; 138 | } 139 | 140 | // Look if destination map is completely connected 141 | try { 142 | dstMap.getMap().forEach((entry, entryName) => { 143 | const srcEntry = srcMap.getMap().get(entryName); 144 | if (!srcEntry) { 145 | throw NotFoundException; 146 | } 147 | if (!containsConnection(conns, srcEntry, entry)) { 148 | connected = false; 149 | } 150 | }); 151 | } catch (e) { 152 | if (e !== NotFoundException) { 153 | throw e; 154 | } 155 | return; 156 | } 157 | if (!connected) { 158 | return; 159 | } 160 | 161 | // Remove all the obsolete connections 162 | srcMap.getMap().forEach((entry, entryName) => { 163 | const dstEntry = dstMap.getMap().get(entryName); 164 | conns.forEach(searchConn => { 165 | if (searchConn.getSource() === entry && searchConn.getDestination() === dstEntry) { 166 | conns.delete(searchConn); 167 | } 168 | }); 169 | }); 170 | conns.add(new Connection(srcMap, dstMap)); 171 | modified = true; 172 | } 173 | }); 174 | return modified; 175 | } 176 | 177 | export function normalizeConnections(conns: Set) { 178 | let modified = true; 179 | while (modified) { 180 | modified = false; 181 | modified = normalizeStreams(conns) || modified; 182 | modified = normalizeMaps(conns) || modified; 183 | } 184 | } 185 | 186 | export function connectDeep(op: OperatorInstance, connections: any): Set { 187 | const connSet = new Set(); 188 | for (const src in connections) { 189 | if (connections.hasOwnProperty(src)) { 190 | for (const dst of connections[src]) { 191 | const conns = op.getPort(src).connectDeep(op.getPort(dst)); 192 | conns.forEach(conn => connSet.add(conn)); 193 | } 194 | } 195 | } 196 | return connSet; 197 | } 198 | 199 | export function stringifyConnections(conns: Set): any { 200 | const connObj = {}; 201 | conns.forEach(conn => { 202 | const srcRef = conn.getSource().getRefString(); 203 | const dstRef = conn.getDestination().getRefString(); 204 | if (!connObj[srcRef]) { 205 | connObj[srcRef] = []; 206 | } 207 | connObj[srcRef].push(dstRef); 208 | }); 209 | return connObj; 210 | } 211 | 212 | export function createDefaultValue(typeDef: any): any { 213 | switch (typeDef.type) { 214 | case 'string': 215 | return ''; 216 | case 'number': 217 | return 0; 218 | case 'binary': 219 | return 'base64:'; 220 | case 'boolean': 221 | return false; 222 | case 'trigger': 223 | return null; 224 | case 'primitive': 225 | return ''; 226 | case 'map': 227 | const typeValue = {}; 228 | for (const key in typeDef.map) { 229 | if (typeDef.map.hasOwnProperty(key)) { 230 | typeValue[key] = createDefaultValue(typeDef.map[key]); 231 | } 232 | } 233 | return typeValue; 234 | case 'stream': 235 | return [createDefaultValue(typeDef.stream)]; 236 | case 'generic': 237 | return '$value'; 238 | } 239 | } 240 | 241 | export function compareOperatorDefs(lhs, rhs: OperatorDef): number { 242 | return (lhs.getName() < rhs.getName()) ? -1 : 1; 243 | } 244 | 245 | export function parseRefString(ref: string): { instance: string, delegate: string, service: string, dirIn: boolean, port: string } { 246 | if (ref.length === 0) { 247 | return null; 248 | } 249 | 250 | const ret = { 251 | instance: undefined, 252 | delegate: undefined, 253 | service: undefined, 254 | dirIn: undefined, 255 | port: undefined 256 | }; 257 | 258 | let sep = ''; 259 | let opIdx = 0; 260 | let portIdx = 0; 261 | if (ref.indexOf('(') !== -1) { 262 | ret.dirIn = true; 263 | sep = '('; 264 | opIdx = 1; 265 | portIdx = 0; 266 | } else if (ref.indexOf(')') !== -1) { 267 | ret.dirIn = false; 268 | sep = ')'; 269 | opIdx = 0; 270 | portIdx = 1; 271 | } else { 272 | return null; 273 | } 274 | 275 | const refSplit = ref.split(sep); 276 | if (refSplit.length !== 2) { 277 | return null; 278 | } 279 | const opPart = refSplit[opIdx]; 280 | ret.port = refSplit[portIdx]; 281 | 282 | if (opPart === '') { 283 | ret.instance = ''; 284 | ret.service = 'main'; 285 | } else { 286 | if (opPart.indexOf('.') !== -1 && opPart.indexOf('@') !== -1) { 287 | // Delegate and service must not both occur in string 288 | return null; 289 | } 290 | if (opPart.indexOf('.') !== -1) { 291 | const opSplit = opPart.split('.'); 292 | if (opSplit.length === 2) { 293 | ret.instance = opSplit[0]; 294 | ret.delegate = opSplit[1]; 295 | } 296 | } else if (opPart.indexOf('@') !== -1) { 297 | const opSplit = opPart.split('@'); 298 | if (opSplit.length === 2) { 299 | ret.instance = opSplit[1]; 300 | ret.service = opSplit[0]; 301 | } 302 | } else { 303 | ret.instance = opPart; 304 | ret.service = 'main'; 305 | } 306 | } 307 | 308 | return ret; 309 | } 310 | 311 | export function buildRefString(info: { instance: string, delegate: string, service: string, dirIn: boolean, port: string }): string { 312 | let opStr = ''; 313 | if (typeof info.service !== 'undefined') { 314 | if (info.service === 'main' || info.service === '') { 315 | opStr = info.instance; 316 | } else { 317 | opStr = `${info.service}@${info.instance}`; 318 | } 319 | } else if (typeof info.delegate !== 'undefined') { 320 | opStr = `${info.instance}.${info.delegate}`; 321 | } 322 | 323 | if (info.dirIn) { 324 | return `${info.port}(${opStr}`; 325 | } else { 326 | return `${opStr})${info.port}`; 327 | } 328 | } 329 | 330 | export class SVGConnectionLineGenerator { 331 | private points: Array = []; 332 | private normTrl: Vec2; 333 | private normRot90Deg: number; 334 | 335 | private constructor(private outerOperator, private conn: Connection) { 336 | const src = conn.getSource(); 337 | const dst = conn.getDestination(); 338 | 339 | this.normTrl = new Vec2(src.getCenter(outerOperator)); 340 | this.normRot90Deg = src.getOrientation().value(); 341 | 342 | if (src.getOperator() === this.outerOperator) { 343 | this.normRot90Deg = (this.normRot90Deg + 2) % 4; 344 | } 345 | 346 | const sOrigin = Vec2.null(); 347 | const dOrigin = new Vec2(dst.getCenter(outerOperator), 348 | dst.getOrientation().rotatedBy((dst.getOperator() === this.outerOperator) ? 2 : 0)); 349 | dOrigin.translate(this.normTrl.neg()).rotate(-this.normRot90Deg); 350 | 351 | const padding = new Vec2([20, 20]); 352 | const start = this.calcOffset(sOrigin, padding, (src.getParentPort() && src.getParentPort().isMap()) ? src.getPosX() : 0); 353 | const end = this.calcOffset(dOrigin, padding, (dst.getParentPort() && dst.getParentPort().isMap()) ? dst.getPosX() : 0); 354 | const mid = start.plus(end.minus(start).div(2)); 355 | const dist = end.minus(start); 356 | 357 | this.addPoints([sOrigin, start]); 358 | 359 | const o = dOrigin.orient(); 360 | 361 | /* direct connection */ 362 | if (dist.y <= 0) { 363 | // Upper half 364 | if (o.isWest() && dist.x >= 0) { 365 | // Upper right 366 | /* 367 | .--->O 368 | | 369 | O 370 | */ 371 | this.addPoints([Vec2.combine(start, end)]); 372 | this.addPoints([end, dOrigin]); 373 | return; 374 | } else if (o.isEast() && dist.x <= 0) { 375 | // Upper left 376 | /* 377 | O<---. 378 | | 379 | O 380 | */ 381 | this.addPoints([Vec2.combine(start, end)]); 382 | this.addPoints([end, dOrigin]); 383 | return; 384 | } 385 | // Upper half 386 | } 387 | 388 | /* connection via 1 additional line */ 389 | if (dist.y <= 0) { 390 | if (o.isSouth()) { 391 | /* 392 | O O 393 | A A 394 | '--. .--• 395 | O O 396 | */ 397 | this.addPoints([Vec2.combine(end, start)]); 398 | this.addPoints([end, dOrigin]); 399 | return; 400 | } else if (o.isNorth()) { 401 | if (Math.abs(dist.x) <= 50) { 402 | /* 403 | .---. 404 | V | 405 | O | 406 | .---' 407 | O 408 | */ 409 | const p = new Vec2([Math.sign(dist.x) * 50, 0]); 410 | this.addPoints([Vec2.combine(p, start), Vec2.combine(p, end)]); 411 | this.addPoints([end, dOrigin]); 412 | } else { 413 | /* 414 | .---. .---. 415 | | V V | 416 | | O O | 417 | O O 418 | */ 419 | this.addPoints([Vec2.combine(start, end)]); 420 | this.addPoints([end, dOrigin]); 421 | return; 422 | } 423 | } 424 | } else { 425 | if (o.isNorth()) { 426 | if (Math.abs(dist.x) <= 50) { 427 | /* 428 | .---. 429 | O | 430 | .---' 431 | V 432 | O 433 | */ 434 | const p = new Vec2([Math.sign(dist.x) * 50, 0]); 435 | this.addPoints([Vec2.combine(p, start), Vec2.combine(p, end)]); 436 | this.addPoints([end, dOrigin]); 437 | } else { 438 | /* 439 | .---. .---. 440 | O V V O 441 | O O 442 | */ 443 | this.addPoints([Vec2.combine(end, start)]); 444 | this.addPoints([end, dOrigin]); 445 | return; 446 | } 447 | } 448 | } 449 | 450 | /* connection via 2 additional lines */ 451 | if (dist.y > 0) { 452 | if (o.isHorizontally()) { 453 | if (Math.abs(dist.x) <= 50) { 454 | /* 455 | .--. .--. 456 | O | | O 457 | O<-' `->O 458 | */ 459 | const p = new Vec2([(o.isWest()) ? -50 : 50, 0]); 460 | this.addPoints([Vec2.combine(p, start), Vec2.combine(p, end)]); 461 | this.addPoints([end, dOrigin]); 462 | return; 463 | } else { 464 | /* 465 | .--. .---. .->O 466 | O | O | '---. 467 | `-->O O<-' O 468 | .---. .--. O<-. 469 | | O | O .---' 470 | '->O O<--' O 471 | */ 472 | if (Math.abs(dist.y) <= 50) { 473 | const c = end.y - 50; 474 | const p = new Vec2([c, c]); 475 | this.addPoints([Vec2.combine(start, p), Vec2.combine(end, p)]); 476 | this.addPoints([end, dOrigin]); 477 | return; 478 | } else { 479 | this.addPoints([Vec2.combine(end, start)]); 480 | this.addPoints([end, dOrigin]); 481 | return; 482 | } 483 | } 484 | } 485 | } else { 486 | if (o.isHorizontally()) { 487 | if (Math.abs(dist.y) <= 50) { 488 | /* 489 | .--. .--. 490 | O | | O 491 | O<-' `->O 492 | */ 493 | const c = end.y - 50; 494 | const p = new Vec2([c, c]); 495 | this.addPoints([Vec2.combine(start, p), Vec2.combine(end, p)]); 496 | this.addPoints([end, dOrigin]); 497 | return; 498 | } else { 499 | /* 500 | .--. .---. .->O 501 | O | O | '---. 502 | `-->O O<-' O 503 | .---. .--. O<-. 504 | | O | O .---' 505 | '->O O<--' O 506 | */ 507 | this.addPoints([Vec2.combine(end, start)]); 508 | this.addPoints([end, dOrigin]); 509 | return; 510 | } 511 | } 512 | } 513 | 514 | 515 | /* connection via 3 additional lines */ 516 | if (dist.y > 0) { 517 | if (o.isSouth()) { 518 | if (Math.abs(dist.x) <= 50) { 519 | /* 520 | .--. 521 | | * 522 | | O 523 | '--' 524 | */ 525 | const p = new Vec2([Math.sign(dist.x) * 50 + dist.x, 0]); 526 | this.addPoints([Vec2.combine(p, start), Vec2.combine(p, end)]); 527 | this.addPoints([end, dOrigin]); 528 | return; 529 | } else { 530 | /* 531 | .--. 532 | * | O 533 | '--' 534 | */ 535 | this.addPoints([Vec2.combine(mid, start), Vec2.combine(mid, end)]); 536 | this.addPoints([end, dOrigin]); 537 | return; 538 | } 539 | } 540 | } 541 | } 542 | 543 | private static roundOneCorner(p1: Vec2, corner: Vec2, p2: Vec2): 544 | { lineEnd: Vec2, curveControl: Vec2, curveEnd: Vec2 } { 545 | 546 | const cornerToP1 = p1.minus(corner); 547 | const cornerToP2 = p2.minus(corner); 548 | const [cornerToP1Unit, mag1] = this.vectorToUnitVector(cornerToP1); 549 | const [cornerToP2Unit, mag2] = this.vectorToUnitVector(cornerToP2); 550 | 551 | const radius = Math.min(25, mag1 / 2, mag2 / 2); 552 | 553 | const curveP1 = cornerToP1Unit.mult(radius).plus(corner); 554 | const curveP2 = cornerToP2Unit.mult(radius).plus(corner); 555 | 556 | return { 557 | lineEnd: curveP1, 558 | curveControl: corner, 559 | curveEnd: curveP2 560 | }; 561 | } 562 | 563 | private static vectorToUnitVector(v: Vec2): [Vec2, number] { 564 | const magnitude = Math.sqrt(v.x * v.x + v.y * v.y); 565 | if (magnitude === 0) { 566 | return [v, magnitude]; 567 | } 568 | return [v.div(magnitude), magnitude]; 569 | } 570 | 571 | private static printPath(path) { 572 | 573 | let svgPath = ''; 574 | svgPath += `L ${path.lineEnd.x.toFixed(1)},${path.lineEnd.y.toFixed(1)} ` + 575 | `Q ${path.curveControl.x.toFixed(1)},${path.curveControl.y.toFixed(1)} ` + 576 | `${path.curveEnd.x.toFixed(1)},${path.curveEnd.y.toFixed(1)}`; 577 | return svgPath; 578 | } 579 | 580 | public static generateCorneredPath(op: OperatorInstance, conn: Connection): string { 581 | const svgPolyLine = new SVGConnectionLineGenerator(op, conn); 582 | return svgPolyLine.points.reduce((pointStr: string, point: Vec2) => { 583 | return pointStr + `${point.x},${point.y} `; 584 | }, ''); 585 | } 586 | 587 | public static generateRoundPath(op: OperatorInstance, conn: Connection): string { 588 | const svgPolyLine = new SVGConnectionLineGenerator(op, conn); 589 | const points = svgPolyLine.points; 590 | let svgPath = `M ${points[0].x} ${points[0].y} `; 591 | for (let i = 0; i + 2 < points.length; i++) { 592 | const p1 = points[i]; 593 | const p2 = points[i + 1]; 594 | const p3 = points[i + 2]; 595 | svgPath += this.printPath(this.roundOneCorner(p1, p2, p3)) + ' '; 596 | } 597 | svgPath += `L ${points[points.length - 1].x} ${points[points.length - 1].y}`; 598 | return svgPath; 599 | } 600 | 601 | private addPoints(path: Array) { 602 | path.forEach(p => this.points.push(Vec2.copy(p).rotate(this.normRot90Deg).translate(this.normTrl))); 603 | } 604 | 605 | private calcOffset(p: Vec2, padding: Vec2, margin?: number): Vec2 { 606 | const ori = p.orient(); 607 | const offsetX = padding.x + margin; 608 | const offsetY = padding.y + margin; 609 | 610 | let offset; 611 | if (ori.isNorth()) { 612 | // to north 613 | offset = new Vec2([0, -offsetY]); 614 | } else if (ori.isSouth()) { 615 | // to south 616 | offset = new Vec2([0, offsetY]); 617 | } else if (ori.isWest()) { 618 | // to west 619 | offset = new Vec2([-offsetX, 0]); 620 | } else { 621 | // to east 622 | offset = new Vec2([offsetX, 0]); 623 | } 624 | return p.plus(offset); 625 | } 626 | } 627 | 628 | export function isType(obj: any, entries: Array): boolean { 629 | if (!obj) { 630 | return false; 631 | } 632 | for (const entry of entries) { 633 | if (!obj.hasOwnProperty(entry)) { 634 | return false; 635 | } 636 | } 637 | for (const entry of obj) { 638 | if (obj.hasOwnProperty(entry)) { 639 | if (entries.indexOf(entry) === -1) { 640 | return false; 641 | } 642 | } 643 | } 644 | return true; 645 | } 646 | 647 | export const HTTP_REQUEST_DEF = JSON.parse( 648 | '{"type":"map","map":{"body":{"type":"binary"},"headers":{"type":"stream","stream":{"type":"map","map":{"key":{"type":"strin' + 649 | 'g"},"values":{"type":"stream","stream":{"type":"string"}}}}},"method":{"type":"string"},"params":{"type":"stream","stream":{"typ' + 650 | 'e":"map","map":{"key":{"type":"string"},"values":{"type":"stream","stream":{"type":"string"}}}}},"path":{"type":"string"},"query' + 651 | '":{"type":"string"}}}'); 652 | 653 | export const HTTP_RESPONSE_DEF = JSON.parse( 654 | '{"type":"map","map":{"body":{"type":"binary"},"headers":{"type":"stream","stream":{"type":"map","map":{"key":{"type":"strin' + 655 | 'g"},"value":{"type":"string"}}}},"status":{"type":"number"}}}'); 656 | -------------------------------------------------------------------------------- /src/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Bitspark/slang-ui/e4bb0c7fb13cc24bee2bc33c458c1031d6b32561/src/assets/.gitkeep -------------------------------------------------------------------------------- /src/assets/brand/logo_star.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Bitspark/slang-ui/e4bb0c7fb13cc24bee2bc33c458c1031d6b32561/src/assets/brand/logo_star.png -------------------------------------------------------------------------------- /src/assets/brand/logo_star_inv.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Bitspark/slang-ui/e4bb0c7fb13cc24bee2bc33c458c1031d6b32561/src/assets/brand/logo_star_inv.png -------------------------------------------------------------------------------- /src/browserslist: -------------------------------------------------------------------------------- 1 | # This file is currently used by autoprefixer to adjust CSS to support the below specified browsers 2 | # For additional information regarding the format and rule options, please see: 3 | # https://github.com/browserslist/browserslist#queries 4 | # For IE 9-11 support, please uncomment the last line of the file and adjust as needed 5 | > 0.5% 6 | last 2 versions 7 | Firefox ESR 8 | not dead 9 | # IE 9-11 -------------------------------------------------------------------------------- /src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true, 3 | daemon: '' 4 | }; 5 | -------------------------------------------------------------------------------- /src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // This file can be replaced during build by using the `fileReplacements` array. 2 | // `ng build ---prod` replaces `environment.ts` with `environment.prod.ts`. 3 | // The list of file replacements can be found in `angular.json`. 4 | 5 | export const environment = { 6 | production: false, 7 | daemon: 'http://localhost:5149' 8 | }; 9 | 10 | /* 11 | * In development mode, to ignore zone related error stack frames such as 12 | * `zone.run`, `zoneDelegate.invokeTask` for easier debugging, you can 13 | * import the following file, but please comment it out in production mode 14 | * because it will have performance impact when throw error 15 | */ 16 | // import 'zone.js/dist/zone-error'; // Included with Angular CLI. 17 | -------------------------------------------------------------------------------- /src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Bitspark/slang-ui/e4bb0c7fb13cc24bee2bc33c458c1031d6b32561/src/favicon.ico -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Slang 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/json-typings.d.ts: -------------------------------------------------------------------------------- 1 | declare module '*.json' { 2 | const value: any; 3 | export default value; 4 | } 5 | -------------------------------------------------------------------------------- /src/karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/1.0/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', '@angular-devkit/build-angular'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-chrome-launcher'), 11 | require('karma-jasmine-html-reporter'), 12 | require('karma-coverage-istanbul-reporter'), 13 | require('@angular-devkit/build-angular/plugins/karma') 14 | ], 15 | client: { 16 | clearContext: false // leave Jasmine Spec Runner output visible in browser 17 | }, 18 | coverageIstanbulReporter: { 19 | dir: require('path').join(__dirname, '../coverage'), 20 | reports: ['html', 'lcovonly'], 21 | fixWebpackSourcePaths: true 22 | }, 23 | reporters: ['progress', 'kjhtml'], 24 | port: 9876, 25 | colors: true, 26 | logLevel: config.LOG_INFO, 27 | autoWatch: true, 28 | browsers: ['Chrome'], 29 | singleRun: false 30 | }); 31 | }; -------------------------------------------------------------------------------- /src/main.ts: -------------------------------------------------------------------------------- 1 | import { enableProdMode } from '@angular/core'; 2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 3 | 4 | import { AppModule } from './app/app.module'; 5 | import { environment } from './environments/environment'; 6 | 7 | if (environment.production) { 8 | enableProdMode(); 9 | } 10 | 11 | platformBrowserDynamic().bootstrapModule(AppModule) 12 | .catch(err => console.log(err)); 13 | -------------------------------------------------------------------------------- /src/navigator.clipboard.d.ts: -------------------------------------------------------------------------------- 1 | // Source: https://github.com/Microsoft/TypeScript/issues/26728#issuecomment-453741023 2 | // 3 | // Type declarations for Clipboard API 4 | // https://developer.mozilla.org/en-US/docs/Web/API/Clipboard_API 5 | interface Clipboard { 6 | writeText(newClipText: string): Promise; 7 | // Add any other methods you need here. 8 | } 9 | 10 | interface NavigatorClipboard { 11 | // Only available in a secure context. 12 | readonly clipboard?: Clipboard; 13 | } 14 | 15 | interface Navigator extends NavigatorClipboard {} -------------------------------------------------------------------------------- /src/polyfills.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This file includes polyfills needed by Angular and is loaded before the app. 3 | * You can add your own extra polyfills to this file. 4 | * 5 | * This file is divided into 2 sections: 6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers. 7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main 8 | * file. 9 | * 10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that 11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera), 12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile. 13 | * 14 | * Learn more in https://angular.io/docs/ts/latest/guide/browser-support.html 15 | */ 16 | 17 | /*************************************************************************************************** 18 | * BROWSER POLYFILLS 19 | */ 20 | 21 | /** IE9, IE10 and IE11 requires all of the following polyfills. **/ 22 | // import 'core-js/es6/symbol'; 23 | // import 'core-js/es6/object'; 24 | // import 'core-js/es6/function'; 25 | // import 'core-js/es6/parse-int'; 26 | // import 'core-js/es6/parse-float'; 27 | // import 'core-js/es6/number'; 28 | // import 'core-js/es6/math'; 29 | // import 'core-js/es6/string'; 30 | // import 'core-js/es6/date'; 31 | // import 'core-js/es6/array'; 32 | // import 'core-js/es6/regexp'; 33 | // import 'core-js/es6/map'; 34 | // import 'core-js/es6/weak-map'; 35 | // import 'core-js/es6/set'; 36 | 37 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */ 38 | // import 'classlist.js'; // Run `npm install --save classlist.js`. 39 | 40 | /** IE10 and IE11 requires the following for the Reflect API. */ 41 | // import 'core-js/es6/reflect'; 42 | 43 | 44 | /** Evergreen browsers require these. **/ 45 | // Used for reflect-metadata in JIT. If you use AOT (and only Angular decorators), you can remove. 46 | import 'core-js/es7/reflect'; 47 | 48 | 49 | /** 50 | * Web Animations `@angular/platform-browser/animations` 51 | * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari. 52 | * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0). 53 | **/ 54 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 55 | 56 | /** 57 | * By default, zone.js will patch all possible macroTask and DomEvents 58 | * user can disable parts of macroTask/DomEvents patch by setting following flags 59 | */ 60 | 61 | // (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame 62 | // (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick 63 | // (window as any).__zone_symbol__BLACK_LISTED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames 64 | 65 | /* 66 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js 67 | * with the following flag, it will bypass `zone.js` patch for IE/Edge 68 | */ 69 | // (window as any).__Zone_enable_cross_context_check = true; 70 | 71 | /*************************************************************************************************** 72 | * Zone JS is required by default for Angular itself. 73 | */ 74 | import 'zone.js/dist/zone'; // Included with Angular CLI. 75 | 76 | 77 | 78 | /*************************************************************************************************** 79 | * APPLICATION IMPORTS 80 | */ 81 | -------------------------------------------------------------------------------- /src/styles/_dark.scss: -------------------------------------------------------------------------------- 1 | $body-bg: $dark; 2 | $body-color: $light; 3 | $primary: $orange; 4 | $pane-border-color: $dark-tone; 5 | $svg-bg: transparentize(white, .9); 6 | $svg-selected: $yellow; 7 | $svg-text: $light-gray; 8 | $svg-conn: $light-gray; 9 | $svg-op-stroke: $light-gray; 10 | $svg-op-fill-surr: lighten(desaturate($body-bg, 14%), 12%); 11 | $svg-op-fill-elem: #3E4A54; 12 | $svg-op-fill-lib: lighten($blue, 10%); 13 | $svg-op-fill-loc: #4C5773; 14 | 15 | // YAML Codemirror 16 | 17 | /* 18 | http://lesscss.org/ dark theme 19 | Ported to CodeMirror by Peter Kroon 20 | */ 21 | .cm-s-slang-dark { 22 | line-height: 1.3em; 23 | } 24 | 25 | .cm-s-slang-dark.CodeMirror { 26 | background: #1F3440; 27 | color: #EBEFE7; 28 | text-shadow: 0 -1px 1px #1F3440; 29 | } 30 | 31 | .cm-s-slang-dark div.CodeMirror-selected { 32 | background: #22475C; 33 | } 34 | 35 | /* 33322B*/ 36 | .cm-s-slang-dark .CodeMirror-line::selection, .cm-s-slang-dark .CodeMirror-line > span::selection, .cm-s-slang-dark .CodeMirror-line > span > span::selection { 37 | background: rgba(34, 71, 92, .99); 38 | } 39 | 40 | .cm-s-slang-dark .CodeMirror-line::-moz-selection, .cm-s-slang-dark .CodeMirror-line > span::-moz-selection, .cm-s-slang-dark .CodeMirror-line > span > span::-moz-selection { 41 | background: rgba(34, 71, 92, .99); 42 | } 43 | 44 | .cm-s-slang-dark .CodeMirror-cursor { 45 | border-left: 1px solid white; 46 | } 47 | 48 | .cm-s-slang-dark pre { 49 | padding: 0 8px; 50 | } 51 | 52 | /*editable code holder*/ 53 | 54 | .cm-s-slang-dark.CodeMirror span.CodeMirror-matchingbracket { 55 | color: #7EFC7E; 56 | } 57 | 58 | /*65FC65*/ 59 | 60 | .cm-s-slang-dark .CodeMirror-gutters { 61 | background: #1E333F; 62 | border-right: 1px solid #cdcdcd; 63 | } 64 | 65 | .cm-s-slang-dark .CodeMirror-guttermarker { 66 | color: #599eff; 67 | } 68 | 69 | .cm-s-slang-dark .CodeMirror-guttermarker-subtle { 70 | color: #cdcdcd; 71 | } 72 | 73 | .cm-s-slang-dark .CodeMirror-linenumber { 74 | color: #cdcdcd; 75 | } 76 | 77 | .cm-s-slang-dark span.cm-header { 78 | color: #a0a; 79 | } 80 | 81 | .cm-s-slang-dark span.cm-quote { 82 | color: #090; 83 | } 84 | 85 | .cm-s-slang-dark span.cm-keyword { 86 | color: #599eff; 87 | } 88 | 89 | .cm-s-slang-dark span.cm-atom { 90 | color: #f57d23; 91 | } 92 | 93 | .cm-s-slang-dark span.cm-number { 94 | color: #B35E4D; 95 | } 96 | 97 | .cm-s-slang-dark span.cm-def { 98 | color: white; 99 | } 100 | 101 | .cm-s-slang-dark span.cm-variable { 102 | color: #D9BF8C; 103 | } 104 | 105 | .cm-s-slang-dark span.cm-variable-2 { 106 | color: #669199; 107 | } 108 | 109 | .cm-s-slang-dark span.cm-variable-3, .cm-s-slang-dark span.cm-type { 110 | color: white; 111 | } 112 | 113 | .cm-s-slang-dark span.cm-property { 114 | color: #92A75C; 115 | } 116 | 117 | .cm-s-slang-dark span.cm-operator { 118 | color: #92A75C; 119 | } 120 | 121 | .cm-s-slang-dark span.cm-comment { 122 | color: #666; 123 | } 124 | 125 | .cm-s-slang-dark span.cm-string { 126 | color: #BCD279; 127 | } 128 | 129 | .cm-s-slang-dark span.cm-string-2 { 130 | color: #f50; 131 | } 132 | 133 | .cm-s-slang-dark span.cm-meta { 134 | color: #738C73; 135 | } 136 | 137 | .cm-s-slang-dark span.cm-qualifier { 138 | color: #555; 139 | } 140 | 141 | .cm-s-slang-dark span.cm-builtin { 142 | color: #ff9e59; 143 | } 144 | 145 | .cm-s-slang-dark span.cm-bracket { 146 | color: #EBEFE7; 147 | } 148 | 149 | .cm-s-slang-dark span.cm-tag { 150 | color: #669199; 151 | } 152 | 153 | .cm-s-slang-dark span.cm-attribute { 154 | color: #00c; 155 | } 156 | 157 | .cm-s-slang-dark span.cm-hr { 158 | color: #999; 159 | } 160 | 161 | .cm-s-slang-dark span.cm-link { 162 | color: #00c; 163 | } 164 | 165 | .cm-s-slang-dark span.cm-error { 166 | color: #9d1e15; 167 | } 168 | 169 | .cm-s-slang-dark .CodeMirror-activeline-background { 170 | background: #3C3A3A; 171 | } 172 | 173 | .cm-s-slang-dark .CodeMirror-matchingbracket { 174 | outline: 1px solid grey; 175 | color: white !important; 176 | } 177 | -------------------------------------------------------------------------------- /src/styles/_light.scss: -------------------------------------------------------------------------------- 1 | $body-bg: $light; 2 | $body-color: $dark; 3 | $primary: $orange; 4 | $svg-bg: transparentize($dark, .55); 5 | $pane-border-color: transparentize($dark, .65); 6 | $svg-selected: $orange; 7 | $svg-hovered: lighten(desaturate($orange, 16), 20); 8 | $svg-expandable: $light-purple; 9 | $svg-text: $body-color; 10 | $svg-conn: $white; 11 | $svg-op-stroke: $light-gray; 12 | $svg-op-fill-surr: $light-gray; 13 | $svg-op-fill-elem: $white; 14 | $svg-op-fill-lib: $white; 15 | $svg-op-fill-loc: $white; 16 | 17 | // YAML Codemirror 18 | 19 | /* 20 | http://lesscss.org/ dark theme 21 | Ported to CodeMirror by Peter Kroon 22 | */ 23 | .cm-s-slang-dark { 24 | line-height: 1.3em; 25 | } 26 | 27 | .cm-s-slang-dark.CodeMirror { 28 | background: #1F3440; 29 | color: #EBEFE7; 30 | text-shadow: 0 -1px 1px #1F3440; 31 | } 32 | 33 | .cm-s-slang-dark div.CodeMirror-selected { 34 | background: #22475C; 35 | } 36 | 37 | /* 33322B*/ 38 | .cm-s-slang-dark .CodeMirror-line::selection, .cm-s-slang-dark .CodeMirror-line > span::selection, .cm-s-slang-dark .CodeMirror-line > span > span::selection { 39 | background: rgba(34, 71, 92, .99); 40 | } 41 | 42 | .cm-s-slang-dark .CodeMirror-line::-moz-selection, .cm-s-slang-dark .CodeMirror-line > span::-moz-selection, .cm-s-slang-dark .CodeMirror-line > span > span::-moz-selection { 43 | background: rgba(34, 71, 92, .99); 44 | } 45 | 46 | .cm-s-slang-dark .CodeMirror-cursor { 47 | border-left: 1px solid white; 48 | } 49 | 50 | .cm-s-slang-dark pre { 51 | padding: 0 8px; 52 | } 53 | 54 | /*editable code holder*/ 55 | 56 | .cm-s-slang-dark.CodeMirror span.CodeMirror-matchingbracket { 57 | color: #7EFC7E; 58 | } 59 | 60 | /*65FC65*/ 61 | 62 | .cm-s-slang-dark .CodeMirror-gutters { 63 | background: #1E333F; 64 | border-right: 1px solid #cdcdcd; 65 | } 66 | 67 | .cm-s-slang-dark .CodeMirror-guttermarker { 68 | color: #599eff; 69 | } 70 | 71 | .cm-s-slang-dark .CodeMirror-guttermarker-subtle { 72 | color: #cdcdcd; 73 | } 74 | 75 | .cm-s-slang-dark .CodeMirror-linenumber { 76 | color: #cdcdcd; 77 | } 78 | 79 | .cm-s-slang-dark span.cm-header { 80 | color: #a0a; 81 | } 82 | 83 | .cm-s-slang-dark span.cm-quote { 84 | color: #090; 85 | } 86 | 87 | .cm-s-slang-dark span.cm-keyword { 88 | color: #599eff; 89 | } 90 | 91 | .cm-s-slang-dark span.cm-atom { 92 | color: #f57d23; 93 | } 94 | 95 | .cm-s-slang-dark span.cm-number { 96 | color: #B35E4D; 97 | } 98 | 99 | .cm-s-slang-dark span.cm-def { 100 | color: white; 101 | } 102 | 103 | .cm-s-slang-dark span.cm-variable { 104 | color: #D9BF8C; 105 | } 106 | 107 | .cm-s-slang-dark span.cm-variable-2 { 108 | color: #669199; 109 | } 110 | 111 | .cm-s-slang-dark span.cm-variable-3, .cm-s-slang-dark span.cm-type { 112 | color: white; 113 | } 114 | 115 | .cm-s-slang-dark span.cm-property { 116 | color: #92A75C; 117 | } 118 | 119 | .cm-s-slang-dark span.cm-operator { 120 | color: #92A75C; 121 | } 122 | 123 | .cm-s-slang-dark span.cm-comment { 124 | color: #666; 125 | } 126 | 127 | .cm-s-slang-dark span.cm-string { 128 | color: #BCD279; 129 | } 130 | 131 | .cm-s-slang-dark span.cm-string-2 { 132 | color: #f50; 133 | } 134 | 135 | .cm-s-slang-dark span.cm-meta { 136 | color: #738C73; 137 | } 138 | 139 | .cm-s-slang-dark span.cm-qualifier { 140 | color: #555; 141 | } 142 | 143 | .cm-s-slang-dark span.cm-builtin { 144 | color: #ff9e59; 145 | } 146 | 147 | .cm-s-slang-dark span.cm-bracket { 148 | color: #EBEFE7; 149 | } 150 | 151 | .cm-s-slang-dark span.cm-tag { 152 | color: #669199; 153 | } 154 | 155 | .cm-s-slang-dark span.cm-attribute { 156 | color: #00c; 157 | } 158 | 159 | .cm-s-slang-dark span.cm-hr { 160 | color: #999; 161 | } 162 | 163 | .cm-s-slang-dark span.cm-link { 164 | color: #00c; 165 | } 166 | 167 | .cm-s-slang-dark span.cm-error { 168 | color: #9d1e15; 169 | } 170 | 171 | .cm-s-slang-dark .CodeMirror-activeline-background { 172 | background: #3C3A3A; 173 | } 174 | 175 | .cm-s-slang-dark .CodeMirror-matchingbracket { 176 | outline: 1px solid grey; 177 | color: white !important; 178 | } 179 | -------------------------------------------------------------------------------- /src/styles/main.scss: -------------------------------------------------------------------------------- 1 | @import "variables"; 2 | @import "~bootstrap/scss/bootstrap"; 3 | @import "operator"; 4 | 5 | /*** 6 | * Overriding bootstrap rules 7 | */ 8 | 9 | body { 10 | font-family: $font-text; 11 | max-height: 100vh; 12 | height: 100vh; 13 | max-width: 100vw; 14 | width: 100vw; 15 | overflow: hidden; 16 | } 17 | 18 | h1, h2, h3, h4, h5, h6 { 19 | font-family: $font-title; 20 | } 21 | 22 | .card-title, .modal-title, .card-subtitle, .panel-title, .headertitle { 23 | font-family: $font-text; 24 | } 25 | 26 | /*** 27 | * Defining global rules 28 | */ 29 | 30 | .sl-operator-name { 31 | font-family: $font-mono; 32 | } 33 | 34 | #sl-operators-col { 35 | height: calc(100vh); 36 | padding: 15px; 37 | color: $body-bg; 38 | background-color: $dark-tone; 39 | } 40 | 41 | .CodeMirror { 42 | height: calc(100vh - 50px); 43 | } 44 | -------------------------------------------------------------------------------- /src/styles/operator.scss: -------------------------------------------------------------------------------- 1 | @import "variables"; 2 | 3 | svg { 4 | background-color: $svg-bg; 5 | 6 | text { 7 | /* override browser default */ 8 | -webkit-user-select: none; 9 | -moz-user-select: none; 10 | -ms-user-select: none; 11 | user-select: none; 12 | &::selection { 13 | background: none; 14 | } 15 | 16 | fill: $svg-text; 17 | font-size: 1.4em; 18 | font-weight: lighter; 19 | 20 | &.selected, &.selected.hovered, &.selected:hover { 21 | stroke: $svg-selected; 22 | } 23 | &.hovered { 24 | stroke: $svg-hovered; 25 | } 26 | } 27 | 28 | rect, circle, line, path { 29 | stroke: transparent; 30 | stroke-width: 2px; 31 | stroke-linecap: butt; 32 | &.selected, &.selected.hovered, &.selected:hover { 33 | stroke: $svg-selected; 34 | } 35 | &.hovered { 36 | stroke: $svg-hovered; 37 | } 38 | &.expandable { 39 | stroke: $svg-expandable; 40 | } 41 | } 42 | 43 | .sl-svg-conn { 44 | fill: none; 45 | stroke: $svg-conn; 46 | stroke-width: 6px; 47 | stroke-linejoin: round; 48 | stroke-linecap: round; 49 | } 50 | 51 | .sl-svg-conn-click-overlay { 52 | fill: none; 53 | stroke: transparent; 54 | stroke-width: 14px; 55 | } 56 | 57 | .sl-svg-conn-highlight { 58 | fill: none; 59 | stroke: none; 60 | stroke-width: 6px; 61 | stroke-linejoin: round; 62 | stroke-linecap: round; 63 | &.hovered { 64 | stroke: $svg-hovered; 65 | } 66 | &.selected { 67 | stroke: $svg-selected; 68 | } 69 | } 70 | 71 | .sl-svg-op { 72 | //rx: $op-border-radius; 73 | //ry: $op-border-radius; 74 | stroke: $svg-op-stroke; 75 | stroke-width: 14px; 76 | stroke-opacity: .55; 77 | fill-opacity: .9; 78 | 79 | &.selected, &.selected:hover { 80 | stroke: $svg-selected; 81 | } 82 | &.sl-svg-op-surr { 83 | fill: $svg-op-fill-surr; 84 | fill-opacity: .85; 85 | } 86 | &.sl-svg-op-ins { 87 | &.hovered { 88 | stroke: $svg-hovered; 89 | } 90 | &.selected { 91 | stroke: $svg-selected; 92 | } 93 | &.sl-svg-op-type { 94 | &.elementary { 95 | fill: $svg-op-fill-elem 96 | } 97 | &.library { 98 | fill: $svg-op-fill-lib; 99 | } 100 | &.local { 101 | fill: $svg-op-fill-loc; 102 | } 103 | } 104 | } 105 | } 106 | 107 | .sl-svg-op-resize { 108 | //r: 8px; 109 | fill: $medium; 110 | fill-opacity: .25; 111 | -webkit-transition: r 200ms ease-in-out; 112 | -moz-transition: r 200ms ease-in-out; 113 | transition: r 200ms ease-in-out; 114 | &:hover { 115 | //r: 12px; 116 | fill-opacity: .75; 117 | cursor: nwse-resize; 118 | } 119 | } 120 | 121 | .sl-svg-port { 122 | stroke-width: 8px; 123 | stroke-opacity: .55; 124 | 125 | &.primitive { 126 | fill: #5bcbca; 127 | } 128 | &.number { 129 | fill: #377eb8; 130 | } 131 | &.string { 132 | fill: #984ea3; 133 | } 134 | &.boolean { 135 | fill: #1b9e77; 136 | } 137 | &.binary { 138 | fill: #FBEB56; 139 | } 140 | &.trigger { 141 | fill: #767675; 142 | } 143 | &.generic { 144 | fill: #E20074; 145 | } 146 | } 147 | .sl-svg-port-label { 148 | stroke: none; 149 | fill: none; 150 | &.displayed { 151 | fill: $body-color; 152 | stroke: $svg-hovered; 153 | } 154 | } 155 | .sl-svg-port-click-overlay { 156 | fill: transparent; 157 | stroke: transparent; 158 | stroke-width: 6px; 159 | } 160 | } 161 | 162 | -------------------------------------------------------------------------------- /src/styles/variables.scss: -------------------------------------------------------------------------------- 1 | @import url('https://fonts.googleapis.com/css?family=Share+Tech+Mono|Roboto+Condensed'); 2 | 3 | $font-mono: 'Share Tech Mono', monospace; 4 | $font-title: 'Roboto Condensed', sans-serif; 5 | $font-text: 'Roboto Condensed', sans-serif; 6 | 7 | $font-size-base: 0.95rem; 8 | $font-weight-normal: medium; 9 | $spacer: 0.5rem; 10 | 11 | $op-border-radius: 20px; 12 | 13 | //$blue: #123c94; 14 | $blue: #174B8D; 15 | $cyan: #268aac; 16 | $orange: #F07E26; 17 | $yellow: #FFD559; 18 | $purple: #6050bc; 19 | $light-purple: #eee0ff; 20 | $white: #fffffe; 21 | $light: #eeeeec; 22 | $light-tone: #d4edff; 23 | $medium: #586e7b; 24 | $dark-tone: #1d3648; 25 | $dark: #142a37; 26 | $light-gray: #ccc; 27 | $gray: #888; 28 | $dark-gray: #333; 29 | 30 | 31 | @import "light"; 32 | -------------------------------------------------------------------------------- /src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import 'zone.js/dist/zone-testing'; 4 | import { getTestBed } from '@angular/core/testing'; 5 | import { 6 | BrowserDynamicTestingModule, 7 | platformBrowserDynamicTesting 8 | } from '@angular/platform-browser-dynamic/testing'; 9 | 10 | declare const require: any; 11 | 12 | // First, initialize the Angular testing environment. 13 | getTestBed().initTestEnvironment( 14 | BrowserDynamicTestingModule, 15 | platformBrowserDynamicTesting() 16 | ); 17 | // Then we find all the tests. 18 | const context = require.context('./', true, /\.spec\.ts$/); 19 | // And load the modules. 20 | context.keys().map(context); 21 | -------------------------------------------------------------------------------- /src/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/app", 5 | "module": "es2015", 6 | "types": [] 7 | }, 8 | "exclude": [ 9 | "src/test.ts", 10 | "**/*.spec.ts" 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /src/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/spec", 5 | "module": "commonjs", 6 | "types": [ 7 | "jasmine", 8 | "node" 9 | ] 10 | }, 11 | "files": [ 12 | "test.ts", 13 | "polyfills.ts" 14 | ], 15 | "include": [ 16 | "**/*.spec.ts", 17 | "**/*.d.ts" 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /src/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tslint.json", 3 | "rules": { 4 | "directive-selector": [ 5 | true, 6 | "attribute", 7 | "app", 8 | "camelCase" 9 | ], 10 | "component-selector": [ 11 | true, 12 | "element", 13 | "app", 14 | "kebab-case" 15 | ] 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "baseUrl": "./", 5 | "outDir": "./dist/out-tsc", 6 | "sourceMap": true, 7 | "declaration": false, 8 | "moduleResolution": "node", 9 | "emitDecoratorMetadata": true, 10 | "experimentalDecorators": true, 11 | "target": "es5", 12 | "typeRoots": [ 13 | "node_modules/@types" 14 | ], 15 | "lib": [ 16 | "es2017", 17 | "dom" 18 | ] 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "rulesDirectory": [ 3 | "node_modules/codelyzer" 4 | ], 5 | "rules": { 6 | "arrow-return-shorthand": true, 7 | "callable-types": true, 8 | "class-name": true, 9 | "comment-format": [ 10 | true, 11 | "check-space" 12 | ], 13 | "curly": true, 14 | "deprecation": { 15 | "severity": "warn" 16 | }, 17 | "eofline": true, 18 | "forin": true, 19 | "import-blacklist": [ 20 | true, 21 | "rxjs/Rx" 22 | ], 23 | "import-spacing": true, 24 | "indent": [ 25 | true, 26 | "spaces" 27 | ], 28 | "interface-over-type-literal": true, 29 | "label-position": true, 30 | "max-line-length": [ 31 | true, 32 | 140 33 | ], 34 | "member-access": false, 35 | "member-ordering": [ 36 | true, 37 | { 38 | "order": [ 39 | "static-field", 40 | "instance-field", 41 | "static-method", 42 | "instance-method" 43 | ] 44 | } 45 | ], 46 | "no-arg": true, 47 | "no-bitwise": true, 48 | "no-console": [ 49 | true, 50 | "debug", 51 | "info", 52 | "time", 53 | "timeEnd", 54 | "trace" 55 | ], 56 | "no-construct": true, 57 | "no-debugger": true, 58 | "no-duplicate-super": true, 59 | "no-empty": false, 60 | "no-empty-interface": true, 61 | "no-eval": true, 62 | "no-inferrable-types": [ 63 | true, 64 | "ignore-params" 65 | ], 66 | "no-misused-new": true, 67 | "no-non-null-assertion": true, 68 | "no-shadowed-variable": true, 69 | "no-string-literal": false, 70 | "no-string-throw": true, 71 | "no-switch-case-fall-through": true, 72 | "no-trailing-whitespace": true, 73 | "no-unnecessary-initializer": true, 74 | "no-unused-expression": true, 75 | "no-use-before-declare": true, 76 | "no-var-keyword": true, 77 | "object-literal-sort-keys": false, 78 | "one-line": [ 79 | true, 80 | "check-open-brace", 81 | "check-catch", 82 | "check-else", 83 | "check-whitespace" 84 | ], 85 | "prefer-const": true, 86 | "quotemark": [ 87 | true, 88 | "single" 89 | ], 90 | "radix": true, 91 | "semicolon": [ 92 | true, 93 | "always" 94 | ], 95 | "triple-equals": [ 96 | true, 97 | "allow-null-check" 98 | ], 99 | "typedef-whitespace": [ 100 | true, 101 | { 102 | "call-signature": "nospace", 103 | "index-signature": "nospace", 104 | "parameter": "nospace", 105 | "property-declaration": "nospace", 106 | "variable-declaration": "nospace" 107 | } 108 | ], 109 | "unified-signatures": true, 110 | "variable-name": false, 111 | "whitespace": [ 112 | true, 113 | "check-branch", 114 | "check-decl", 115 | "check-operator", 116 | "check-separator", 117 | "check-type" 118 | ], 119 | "no-output-on-prefix": true, 120 | "use-input-property-decorator": true, 121 | "use-output-property-decorator": true, 122 | "use-host-property-decorator": true, 123 | "no-input-rename": true, 124 | "no-output-rename": true, 125 | "use-life-cycle-interface": true, 126 | "use-pipe-transform-interface": true, 127 | "component-class-suffix": true, 128 | "directive-class-suffix": true 129 | } 130 | } 131 | --------------------------------------------------------------------------------