@vandenberghinc/volt 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.vrepo +28 -0
- package/.vscode/tasks.json +87 -0
- package/README.md +67 -0
- package/backend/dist/cjs/blacklist.d.ts +10 -0
- package/backend/dist/cjs/blacklist.js +53 -0
- package/backend/dist/cjs/cli.d.ts +2 -0
- package/backend/dist/cjs/cli.js +263 -0
- package/backend/dist/cjs/database.d.ts +364 -0
- package/backend/dist/cjs/database.js +1962 -0
- package/backend/dist/cjs/endpoint.d.ts +57 -0
- package/backend/dist/cjs/endpoint.js +425 -0
- package/backend/dist/cjs/file_watcher.d.ts +44 -0
- package/backend/dist/cjs/file_watcher.js +348 -0
- package/backend/dist/cjs/frontend.d.ts +13 -0
- package/backend/dist/cjs/frontend.js +30 -0
- package/backend/dist/cjs/image_endpoint.d.ts +24 -0
- package/backend/dist/cjs/image_endpoint.js +210 -0
- package/backend/dist/cjs/logger.d.ts +5 -0
- package/backend/dist/cjs/logger.js +16 -0
- package/backend/dist/cjs/meta.d.ts +50 -0
- package/backend/dist/cjs/meta.js +153 -0
- package/backend/dist/cjs/mutex.d.ts +24 -0
- package/backend/dist/cjs/mutex.js +52 -0
- package/backend/dist/cjs/package.json +1 -0
- package/backend/dist/cjs/payments/paddle.d.ts +161 -0
- package/backend/dist/cjs/payments/paddle.js +2301 -0
- package/backend/dist/cjs/plugins/browser.d.ts +36 -0
- package/backend/dist/cjs/plugins/browser.js +183 -0
- package/backend/dist/cjs/plugins/communication.d.ts +70 -0
- package/backend/dist/cjs/plugins/communication.js +177 -0
- package/backend/dist/cjs/plugins/css.d.ts +10 -0
- package/backend/dist/cjs/plugins/css.js +71 -0
- package/backend/dist/cjs/plugins/mail.d.ts +277 -0
- package/backend/dist/cjs/plugins/mail.js +1419 -0
- package/backend/dist/cjs/plugins/pdf.d.ts +757 -0
- package/backend/dist/cjs/plugins/pdf.js +1694 -0
- package/backend/dist/cjs/plugins/thread_monitor.d.ts +18 -0
- package/backend/dist/cjs/plugins/thread_monitor.js +127 -0
- package/backend/dist/cjs/plugins/ts/compiler.d.ts +132 -0
- package/backend/dist/cjs/plugins/ts/compiler.js +944 -0
- package/backend/dist/cjs/plugins/ts/preprocessing.d.ts +14 -0
- package/backend/dist/cjs/plugins/ts/preprocessing.js +762 -0
- package/backend/dist/cjs/rate_limit.d.ts +65 -0
- package/backend/dist/cjs/rate_limit.js +463 -0
- package/backend/dist/cjs/request.deprc.d.ts +48 -0
- package/backend/dist/cjs/request.deprc.js +572 -0
- package/backend/dist/cjs/response.deprc.d.ts +55 -0
- package/backend/dist/cjs/response.deprc.js +275 -0
- package/backend/dist/cjs/server.d.ts +311 -0
- package/backend/dist/cjs/server.js +3475 -0
- package/backend/dist/cjs/splash_screen.d.ts +35 -0
- package/backend/dist/cjs/splash_screen.js +152 -0
- package/backend/dist/cjs/status.d.ts +60 -0
- package/backend/dist/cjs/status.js +199 -0
- package/backend/dist/cjs/stream.d.ts +75 -0
- package/backend/dist/cjs/stream.js +954 -0
- package/backend/dist/cjs/users.d.ts +111 -0
- package/backend/dist/cjs/users.js +1945 -0
- package/backend/dist/cjs/utils.d.ts +27 -0
- package/backend/dist/cjs/utils.js +329 -0
- package/backend/dist/cjs/view.d.ts +52 -0
- package/backend/dist/cjs/view.js +568 -0
- package/backend/dist/cjs/vinc.d.ts +2 -0
- package/backend/dist/cjs/vinc.dev.d.ts +2 -0
- package/backend/dist/cjs/vinc.dev.js +42 -0
- package/backend/dist/cjs/vinc.js +42 -0
- package/backend/dist/cjs/volt.d.ts +15 -0
- package/backend/dist/cjs/volt.js +64 -0
- package/backend/dist/css/adyen.css +92 -0
- package/backend/dist/css/volt.css +65 -0
- package/backend/dist/esm/blacklist.d.ts +10 -0
- package/backend/dist/esm/blacklist.js +49 -0
- package/backend/dist/esm/cli.d.ts +2 -0
- package/backend/dist/esm/cli.js +228 -0
- package/backend/dist/esm/database.d.ts +364 -0
- package/backend/dist/esm/database.js +1957 -0
- package/backend/dist/esm/endpoint.d.ts +57 -0
- package/backend/dist/esm/endpoint.js +421 -0
- package/backend/dist/esm/file_watcher.d.ts +44 -0
- package/backend/dist/esm/file_watcher.js +313 -0
- package/backend/dist/esm/frontend.d.ts +13 -0
- package/backend/dist/esm/frontend.js +27 -0
- package/backend/dist/esm/image_endpoint.d.ts +24 -0
- package/backend/dist/esm/image_endpoint.js +206 -0
- package/backend/dist/esm/logger.d.ts +5 -0
- package/backend/dist/esm/logger.js +13 -0
- package/backend/dist/esm/meta.d.ts +50 -0
- package/backend/dist/esm/meta.js +149 -0
- package/backend/dist/esm/mutex.d.ts +24 -0
- package/backend/dist/esm/mutex.js +48 -0
- package/backend/dist/esm/payments/paddle.d.ts +161 -0
- package/backend/dist/esm/payments/paddle.js +2261 -0
- package/backend/dist/esm/plugins/browser.d.ts +36 -0
- package/backend/dist/esm/plugins/browser.js +176 -0
- package/backend/dist/esm/plugins/communication.d.ts +70 -0
- package/backend/dist/esm/plugins/communication.js +169 -0
- package/backend/dist/esm/plugins/css.d.ts +10 -0
- package/backend/dist/esm/plugins/css.js +64 -0
- package/backend/dist/esm/plugins/mail.d.ts +277 -0
- package/backend/dist/esm/plugins/mail.js +1403 -0
- package/backend/dist/esm/plugins/pdf.d.ts +757 -0
- package/backend/dist/esm/plugins/pdf.js +1694 -0
- package/backend/dist/esm/plugins/thread_monitor.d.ts +18 -0
- package/backend/dist/esm/plugins/thread_monitor.js +120 -0
- package/backend/dist/esm/plugins/ts/compiler.d.ts +132 -0
- package/backend/dist/esm/plugins/ts/compiler.js +907 -0
- package/backend/dist/esm/plugins/ts/preprocessing.d.ts +14 -0
- package/backend/dist/esm/plugins/ts/preprocessing.js +724 -0
- package/backend/dist/esm/rate_limit.d.ts +65 -0
- package/backend/dist/esm/rate_limit.js +425 -0
- package/backend/dist/esm/request.deprc.d.ts +48 -0
- package/backend/dist/esm/request.deprc.js +572 -0
- package/backend/dist/esm/response.deprc.d.ts +55 -0
- package/backend/dist/esm/response.deprc.js +275 -0
- package/backend/dist/esm/server.d.ts +311 -0
- package/backend/dist/esm/server.js +3435 -0
- package/backend/dist/esm/splash_screen.d.ts +35 -0
- package/backend/dist/esm/splash_screen.js +148 -0
- package/backend/dist/esm/status.d.ts +60 -0
- package/backend/dist/esm/status.js +196 -0
- package/backend/dist/esm/stream.d.ts +75 -0
- package/backend/dist/esm/stream.js +947 -0
- package/backend/dist/esm/users.d.ts +111 -0
- package/backend/dist/esm/users.js +1908 -0
- package/backend/dist/esm/utils.d.ts +27 -0
- package/backend/dist/esm/utils.js +324 -0
- package/backend/dist/esm/view.d.ts +52 -0
- package/backend/dist/esm/view.js +561 -0
- package/backend/dist/esm/vinc.d.ts +2 -0
- package/backend/dist/esm/vinc.dev.d.ts +2 -0
- package/backend/dist/esm/vinc.dev.js +6 -0
- package/backend/dist/esm/vinc.js +6 -0
- package/backend/dist/esm/volt.d.ts +15 -0
- package/backend/dist/esm/volt.js +23 -0
- package/backend/dist/esm-dev/blacklist.d.ts +10 -0
- package/backend/dist/esm-dev/blacklist.js +49 -0
- package/backend/dist/esm-dev/cli.d.ts +2 -0
- package/backend/dist/esm-dev/cli.js +228 -0
- package/backend/dist/esm-dev/database.d.ts +364 -0
- package/backend/dist/esm-dev/database.js +1957 -0
- package/backend/dist/esm-dev/endpoint.d.ts +57 -0
- package/backend/dist/esm-dev/endpoint.js +421 -0
- package/backend/dist/esm-dev/file_watcher.d.ts +44 -0
- package/backend/dist/esm-dev/file_watcher.js +313 -0
- package/backend/dist/esm-dev/frontend.d.ts +13 -0
- package/backend/dist/esm-dev/frontend.js +27 -0
- package/backend/dist/esm-dev/image_endpoint.d.ts +24 -0
- package/backend/dist/esm-dev/image_endpoint.js +206 -0
- package/backend/dist/esm-dev/logger.d.ts +5 -0
- package/backend/dist/esm-dev/logger.js +13 -0
- package/backend/dist/esm-dev/meta.d.ts +50 -0
- package/backend/dist/esm-dev/meta.js +149 -0
- package/backend/dist/esm-dev/mutex.d.ts +24 -0
- package/backend/dist/esm-dev/mutex.js +48 -0
- package/backend/dist/esm-dev/payments/paddle.d.ts +161 -0
- package/backend/dist/esm-dev/payments/paddle.js +2261 -0
- package/backend/dist/esm-dev/plugins/browser.d.ts +36 -0
- package/backend/dist/esm-dev/plugins/browser.js +176 -0
- package/backend/dist/esm-dev/plugins/communication.d.ts +70 -0
- package/backend/dist/esm-dev/plugins/communication.js +169 -0
- package/backend/dist/esm-dev/plugins/css.d.ts +10 -0
- package/backend/dist/esm-dev/plugins/css.js +64 -0
- package/backend/dist/esm-dev/plugins/mail.d.ts +277 -0
- package/backend/dist/esm-dev/plugins/mail.js +1403 -0
- package/backend/dist/esm-dev/plugins/pdf.d.ts +757 -0
- package/backend/dist/esm-dev/plugins/pdf.js +1694 -0
- package/backend/dist/esm-dev/plugins/thread_monitor.d.ts +18 -0
- package/backend/dist/esm-dev/plugins/thread_monitor.js +120 -0
- package/backend/dist/esm-dev/plugins/ts/compiler.d.ts +132 -0
- package/backend/dist/esm-dev/plugins/ts/compiler.js +907 -0
- package/backend/dist/esm-dev/plugins/ts/preprocessing.d.ts +14 -0
- package/backend/dist/esm-dev/plugins/ts/preprocessing.js +724 -0
- package/backend/dist/esm-dev/rate_limit.d.ts +65 -0
- package/backend/dist/esm-dev/rate_limit.js +425 -0
- package/backend/dist/esm-dev/request.deprc.d.ts +48 -0
- package/backend/dist/esm-dev/request.deprc.js +572 -0
- package/backend/dist/esm-dev/response.deprc.d.ts +55 -0
- package/backend/dist/esm-dev/response.deprc.js +275 -0
- package/backend/dist/esm-dev/server.d.ts +311 -0
- package/backend/dist/esm-dev/server.js +3435 -0
- package/backend/dist/esm-dev/splash_screen.d.ts +35 -0
- package/backend/dist/esm-dev/splash_screen.js +148 -0
- package/backend/dist/esm-dev/status.d.ts +60 -0
- package/backend/dist/esm-dev/status.js +196 -0
- package/backend/dist/esm-dev/stream.d.ts +75 -0
- package/backend/dist/esm-dev/stream.js +947 -0
- package/backend/dist/esm-dev/users.d.ts +111 -0
- package/backend/dist/esm-dev/users.js +1908 -0
- package/backend/dist/esm-dev/utils.d.ts +27 -0
- package/backend/dist/esm-dev/utils.js +324 -0
- package/backend/dist/esm-dev/view.d.ts +52 -0
- package/backend/dist/esm-dev/view.js +561 -0
- package/backend/dist/esm-dev/vinc.d.ts +2 -0
- package/backend/dist/esm-dev/vinc.dev.d.ts +2 -0
- package/backend/dist/esm-dev/vinc.dev.js +6 -0
- package/backend/dist/esm-dev/vinc.js +6 -0
- package/backend/dist/esm-dev/volt.d.ts +15 -0
- package/backend/dist/esm-dev/volt.js +23 -0
- package/backend/src/blacklist.ts +69 -0
- package/backend/src/cli.js +245 -0
- package/backend/src/database.ts +2241 -0
- package/backend/src/endpoint.ts +494 -0
- package/backend/src/file_watcher.ts +359 -0
- package/backend/src/frontend.ts +35 -0
- package/backend/src/globals.d.ts +8 -0
- package/backend/src/image_endpoint.ts +258 -0
- package/backend/src/logger.ts +18 -0
- package/backend/src/meta.ts +202 -0
- package/backend/src/mutex.ts +51 -0
- package/backend/src/payments/paddle.ts +2659 -0
- package/backend/src/plugins/browser.ts +188 -0
- package/backend/src/plugins/communication.ts +204 -0
- package/backend/src/plugins/css.ts +84 -0
- package/backend/src/plugins/fonts/Menlo-Bold.ttf +0 -0
- package/backend/src/plugins/fonts/Menlo-Regular.ttf +0 -0
- package/backend/src/plugins/mail.ts +1720 -0
- package/backend/src/plugins/pdf.js +1932 -0
- package/backend/src/plugins/thread_monitor.ts +164 -0
- package/backend/src/plugins/ts/compiler.ts +1242 -0
- package/backend/src/plugins/ts/preprocessing.ts +812 -0
- package/backend/src/rate_limit.ts +503 -0
- package/backend/src/request.deprc.js +626 -0
- package/backend/src/response.deprc.js +354 -0
- package/backend/src/server.ts +4149 -0
- package/backend/src/splash_screen.ts +192 -0
- package/backend/src/status.ts +199 -0
- package/backend/src/stream.ts +1070 -0
- package/backend/src/users.ts +2077 -0
- package/backend/src/utils.ts +359 -0
- package/backend/src/view.ts +655 -0
- package/backend/src/vinc.dev.js +6 -0
- package/backend/src/vinc.ts +6 -0
- package/backend/src/volt.js +25 -0
- package/backend/tsconfig.cjs.json +29 -0
- package/backend/tsconfig.esm.dev.json +34 -0
- package/backend/tsconfig.esm.json +30 -0
- package/backend/tsconfig.json +2 -0
- package/frontend/compile.js +436 -0
- package/frontend/dist/elements/base.d.ts +9891 -0
- package/frontend/dist/elements/base.js +8818 -0
- package/frontend/dist/elements/module.d.ts +16 -0
- package/frontend/dist/elements/module.js +178 -0
- package/frontend/dist/modules/array.d.ts +37 -0
- package/frontend/dist/modules/array.js +284 -0
- package/frontend/dist/modules/auth.d.ts +45 -0
- package/frontend/dist/modules/auth.js +138 -0
- package/frontend/dist/modules/colors.d.ts +26 -0
- package/frontend/dist/modules/colors.js +340 -0
- package/frontend/dist/modules/compression.d.ts +6 -0
- package/frontend/dist/modules/compression.js +999 -0
- package/frontend/dist/modules/cookies.d.ts +17 -0
- package/frontend/dist/modules/cookies.js +166 -0
- package/frontend/dist/modules/date.d.ts +142 -0
- package/frontend/dist/modules/date.js +493 -0
- package/frontend/dist/modules/events.d.ts +7 -0
- package/frontend/dist/modules/events.js +90 -0
- package/frontend/dist/modules/google.d.ts +10 -0
- package/frontend/dist/modules/google.js +53 -0
- package/frontend/dist/modules/meta.d.ts +9 -0
- package/frontend/dist/modules/meta.js +45 -0
- package/frontend/dist/modules/mutex.d.ts +8 -0
- package/frontend/dist/modules/mutex.js +52 -0
- package/frontend/dist/modules/number.d.ts +12 -0
- package/frontend/dist/modules/number.js +8 -0
- package/frontend/dist/modules/object.d.ts +50 -0
- package/frontend/dist/modules/object.js +147 -0
- package/frontend/dist/modules/paddle.d.ts +1403 -0
- package/frontend/dist/modules/paddle.js +2641 -0
- package/frontend/dist/modules/scheme.d.ts +207 -0
- package/frontend/dist/modules/scheme.js +649 -0
- package/frontend/dist/modules/settings.d.ts +3 -0
- package/frontend/dist/modules/settings.js +4 -0
- package/frontend/dist/modules/statics.d.ts +4 -0
- package/frontend/dist/modules/statics.js +45 -0
- package/frontend/dist/modules/string.d.ts +163 -0
- package/frontend/dist/modules/string.js +291 -0
- package/frontend/dist/modules/support.d.ts +18 -0
- package/frontend/dist/modules/support.js +102 -0
- package/frontend/dist/modules/themes.d.ts +8 -0
- package/frontend/dist/modules/themes.js +17 -0
- package/frontend/dist/modules/user.d.ts +58 -0
- package/frontend/dist/modules/user.js +279 -0
- package/frontend/dist/modules/utils.d.ts +58 -0
- package/frontend/dist/modules/utils.js +1159 -0
- package/frontend/dist/types/gradient.d.ts +12 -0
- package/frontend/dist/types/gradient.js +79 -0
- package/frontend/dist/ui/border_button.d.ts +177 -0
- package/frontend/dist/ui/border_button.js +235 -0
- package/frontend/dist/ui/button.d.ts +42 -0
- package/frontend/dist/ui/button.js +114 -0
- package/frontend/dist/ui/canvas.d.ts +56 -0
- package/frontend/dist/ui/canvas.js +411 -0
- package/frontend/dist/ui/checkbox.d.ts +72 -0
- package/frontend/dist/ui/checkbox.js +277 -0
- package/frontend/dist/ui/code.d.ts +232 -0
- package/frontend/dist/ui/code.js +977 -0
- package/frontend/dist/ui/color.d.ts +1 -0
- package/frontend/dist/ui/color.js +110 -0
- package/frontend/dist/ui/context_menu.d.ts +30 -0
- package/frontend/dist/ui/context_menu.js +211 -0
- package/frontend/dist/ui/css.d.ts +10 -0
- package/frontend/dist/ui/css.js +44 -0
- package/frontend/dist/ui/divider.d.ts +18 -0
- package/frontend/dist/ui/divider.js +82 -0
- package/frontend/dist/ui/dropdown.d.ts +115 -0
- package/frontend/dist/ui/dropdown.js +446 -0
- package/frontend/dist/ui/for_each.d.ts +38 -0
- package/frontend/dist/ui/for_each.js +97 -0
- package/frontend/dist/ui/form.d.ts +25 -0
- package/frontend/dist/ui/form.js +227 -0
- package/frontend/dist/ui/frame_modes.d.ts +28 -0
- package/frontend/dist/ui/frame_modes.js +116 -0
- package/frontend/dist/ui/google_map.d.ts +31 -0
- package/frontend/dist/ui/google_map.js +111 -0
- package/frontend/dist/ui/gradient.d.ts +24 -0
- package/frontend/dist/ui/gradient.js +115 -0
- package/frontend/dist/ui/image.d.ts +138 -0
- package/frontend/dist/ui/image.js +570 -0
- package/frontend/dist/ui/input.d.ts +316 -0
- package/frontend/dist/ui/input.js +1187 -0
- package/frontend/dist/ui/link.d.ts +39 -0
- package/frontend/dist/ui/link.js +146 -0
- package/frontend/dist/ui/list.d.ts +33 -0
- package/frontend/dist/ui/list.js +161 -0
- package/frontend/dist/ui/loader_button.d.ts +108 -0
- package/frontend/dist/ui/loader_button.js +207 -0
- package/frontend/dist/ui/loaders.d.ts +60 -0
- package/frontend/dist/ui/loaders.js +150 -0
- package/frontend/dist/ui/popup.d.ts +84 -0
- package/frontend/dist/ui/popup.js +331 -0
- package/frontend/dist/ui/pseudo.d.ts +16 -0
- package/frontend/dist/ui/pseudo.js +81 -0
- package/frontend/dist/ui/scroller.d.ts +131 -0
- package/frontend/dist/ui/scroller.js +1251 -0
- package/frontend/dist/ui/slider.d.ts +35 -0
- package/frontend/dist/ui/slider.js +203 -0
- package/frontend/dist/ui/spacer.d.ts +20 -0
- package/frontend/dist/ui/spacer.js +83 -0
- package/frontend/dist/ui/span.d.ts +11 -0
- package/frontend/dist/ui/span.js +75 -0
- package/frontend/dist/ui/stack.d.ts +123 -0
- package/frontend/dist/ui/stack.js +344 -0
- package/frontend/dist/ui/steps.d.ts +72 -0
- package/frontend/dist/ui/steps.js +306 -0
- package/frontend/dist/ui/style.d.ts +12 -0
- package/frontend/dist/ui/style.js +78 -0
- package/frontend/dist/ui/switch.d.ts +44 -0
- package/frontend/dist/ui/switch.js +280 -0
- package/frontend/dist/ui/table.d.ts +118 -0
- package/frontend/dist/ui/table.js +411 -0
- package/frontend/dist/ui/tabs.d.ts +85 -0
- package/frontend/dist/ui/tabs.js +392 -0
- package/frontend/dist/ui/text.d.ts +19 -0
- package/frontend/dist/ui/text.js +88 -0
- package/frontend/dist/ui/theme.d.ts +25 -0
- package/frontend/dist/ui/theme.js +237 -0
- package/frontend/dist/ui/title.d.ts +36 -0
- package/frontend/dist/ui/title.js +127 -0
- package/frontend/dist/ui/ui.d.ts +38 -0
- package/frontend/dist/ui/ui.js +41 -0
- package/frontend/dist/ui/view.d.ts +25 -0
- package/frontend/dist/ui/view.js +93 -0
- package/frontend/dist/volt.d.ts +22 -0
- package/frontend/dist/volt.js +27 -0
- package/frontend/exports.json +1340 -0
- package/frontend/src/css/adyen.css +92 -0
- package/frontend/src/css/volt.css +65 -0
- package/frontend/src/elements/base.ts +16790 -0
- package/frontend/src/elements/module.ts +184 -0
- package/frontend/src/elements/types.d.ts +155 -0
- package/frontend/src/modules/array.ts +366 -0
- package/frontend/src/modules/auth.ts +188 -0
- package/frontend/src/modules/colors.ts +449 -0
- package/frontend/src/modules/compression.ts +67 -0
- package/frontend/src/modules/cookies.ts +182 -0
- package/frontend/src/modules/date.js +535 -0
- package/frontend/src/modules/date.ts +583 -0
- package/frontend/src/modules/events.ts +96 -0
- package/frontend/src/modules/google.ts +60 -0
- package/frontend/src/modules/meta.ts +59 -0
- package/frontend/src/modules/mutex.ts +59 -0
- package/frontend/src/modules/number.ts +20 -0
- package/frontend/src/modules/object.ts +212 -0
- package/frontend/src/modules/paddle.ts +2990 -0
- package/frontend/src/modules/scheme.ts +740 -0
- package/frontend/src/modules/settings.ts +5 -0
- package/frontend/src/modules/statics.ts +47 -0
- package/frontend/src/modules/string.ts +500 -0
- package/frontend/src/modules/support.ts +118 -0
- package/frontend/src/modules/themes.ts +24 -0
- package/frontend/src/modules/user.ts +321 -0
- package/frontend/src/modules/utils.ts +1260 -0
- package/frontend/src/static/admin/admin.png +0 -0
- package/frontend/src/static/admin/password.webp +0 -0
- package/frontend/src/static/icons/copy.webp +0 -0
- package/frontend/src/static/payments/arrow.long.webp +0 -0
- package/frontend/src/static/payments/arrow.long2.webp +0 -0
- package/frontend/src/static/payments/cancelled.webp +0 -0
- package/frontend/src/static/payments/check.sign.webp +0 -0
- package/frontend/src/static/payments/check.webp +0 -0
- package/frontend/src/static/payments/close.webp +0 -0
- package/frontend/src/static/payments/error.webp +0 -0
- package/frontend/src/static/payments/exclamation.webp +0 -0
- package/frontend/src/static/payments/minus.webp +0 -0
- package/frontend/src/static/payments/party.webp +0 -0
- package/frontend/src/static/payments/plus.webp +0 -0
- package/frontend/src/static/payments/shopping_cart.webp +0 -0
- package/frontend/src/static/payments/trash.webp +0 -0
- package/frontend/src/types/global.d.ts +4 -0
- package/frontend/src/types/gradient.ts +87 -0
- package/frontend/src/ui/any_element.d.ts +5 -0
- package/frontend/src/ui/border_button.ts +320 -0
- package/frontend/src/ui/button.ts +62 -0
- package/frontend/src/ui/canvas.ts +431 -0
- package/frontend/src/ui/checkbox.ts +284 -0
- package/frontend/src/ui/code.ts +1049 -0
- package/frontend/src/ui/color.ts +117 -0
- package/frontend/src/ui/context_menu.ts +194 -0
- package/frontend/src/ui/css.ts +57 -0
- package/frontend/src/ui/divider.ts +28 -0
- package/frontend/src/ui/dropdown.ts +503 -0
- package/frontend/src/ui/for_each.ts +71 -0
- package/frontend/src/ui/form.ts +208 -0
- package/frontend/src/ui/frame_modes.ts +140 -0
- package/frontend/src/ui/google_map.ts +70 -0
- package/frontend/src/ui/gradient.ts +73 -0
- package/frontend/src/ui/image.ts +587 -0
- package/frontend/src/ui/input.ts +1284 -0
- package/frontend/src/ui/link.ts +77 -0
- package/frontend/src/ui/list.ts +88 -0
- package/frontend/src/ui/loader_button.ts +192 -0
- package/frontend/src/ui/loaders.ts +126 -0
- package/frontend/src/ui/popup.ts +370 -0
- package/frontend/src/ui/pseudo.ts +33 -0
- package/frontend/src/ui/scroller.ts +1324 -0
- package/frontend/src/ui/slider.ts +215 -0
- package/frontend/src/ui/spacer.ts +29 -0
- package/frontend/src/ui/span.ts +23 -0
- package/frontend/src/ui/stack.ts +238 -0
- package/frontend/src/ui/steps.ts +334 -0
- package/frontend/src/ui/style.ts +26 -0
- package/frontend/src/ui/switch.ts +286 -0
- package/frontend/src/ui/table.ts +323 -0
- package/frontend/src/ui/tabs.ts +441 -0
- package/frontend/src/ui/text.ts +38 -0
- package/frontend/src/ui/theme.ts +279 -0
- package/frontend/src/ui/title.ts +64 -0
- package/frontend/src/ui/ui.ts +47 -0
- package/frontend/src/ui/view.ts +44 -0
- package/frontend/src/volt.ts +31 -0
- package/package.json +58 -0
|
@@ -0,0 +1,1932 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Author: Daan van den Bergh
|
|
3
|
+
* Copyright: © 2022 - 2024 Daan van den Bergh.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// ---------------------------------------------------------
|
|
7
|
+
// Imports.
|
|
8
|
+
|
|
9
|
+
const {vlib, vhighlight} = require("../vinc.js");
|
|
10
|
+
const {jsPDF} = require("jspdf");
|
|
11
|
+
const libfs = require("fs");
|
|
12
|
+
|
|
13
|
+
// ---------------------------------------------------------
|
|
14
|
+
// The mail object.
|
|
15
|
+
|
|
16
|
+
const PDF = {
|
|
17
|
+
|
|
18
|
+
// Use pixels instead of points (NOT ADVISED).
|
|
19
|
+
// use_pixels: false,
|
|
20
|
+
|
|
21
|
+
// Get opacity from hex as a floating number 0/1, returns `null` on no opacity.
|
|
22
|
+
hex_opacity(hex) {
|
|
23
|
+
if (
|
|
24
|
+
(typeof hex !== "string" && hex instanceof String === false) ||
|
|
25
|
+
hex.charAt(0) !== "#" ||
|
|
26
|
+
hex.length <= 7
|
|
27
|
+
) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
const opacity = parseInt(hex.slice(-2))/100;
|
|
31
|
+
return isNaN(opacity) ? null : opacity;
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
// Convert hex to rgb(a), since pdfkit does not support a hex with opacity.
|
|
35
|
+
hex_to_rgb(hex) {
|
|
36
|
+
|
|
37
|
+
// Not a string.
|
|
38
|
+
if (typeof hex !== "string" && hex instanceof String === false) {
|
|
39
|
+
return hex;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Not a hex.
|
|
43
|
+
if (hex.charAt(0) !== "#") {
|
|
44
|
+
return hex; // perhaps a normal color like "blue".
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Remove the hash (#).
|
|
48
|
+
hex = hex.slice(1);
|
|
49
|
+
|
|
50
|
+
// Parse alpha
|
|
51
|
+
let alpha = 1;
|
|
52
|
+
if (hex.length > 6) {
|
|
53
|
+
alpha = parseInt(hex.slice(-2)) / 100
|
|
54
|
+
hex = hex.slice(0, -2);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Parse the hex color.
|
|
58
|
+
const bigint = parseInt(hex, 16);
|
|
59
|
+
const r = (bigint >> 16) & 255;
|
|
60
|
+
const g = (bigint >> 8) & 255;
|
|
61
|
+
const b = bigint & 255;
|
|
62
|
+
|
|
63
|
+
// Return the rgb(a) color.
|
|
64
|
+
if (alpha != 1) {
|
|
65
|
+
return [r, g, b, alpha];
|
|
66
|
+
// return `rgba(${r}, ${g}, ${b}, ${alpha})`;
|
|
67
|
+
}
|
|
68
|
+
return [r, g, b];
|
|
69
|
+
// return `rgb(${r}, ${g}, ${b})`;
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
hex_to_cmyk(hex) {
|
|
73
|
+
// Remove the hash if present
|
|
74
|
+
// hex = hex.slice(1);
|
|
75
|
+
|
|
76
|
+
// // Convert hex to decimal
|
|
77
|
+
// const r = parseInt(hex.substring(0, 2), 16) / 255;
|
|
78
|
+
// const g = parseInt(hex.substring(2, 4), 16) / 255;
|
|
79
|
+
// const b = parseInt(hex.substring(4, 6), 16) / 255;
|
|
80
|
+
|
|
81
|
+
// // Calculate CMY
|
|
82
|
+
// let c = 1 - r;
|
|
83
|
+
// let m = 1 - g;
|
|
84
|
+
// let y = 1 - b;
|
|
85
|
+
|
|
86
|
+
// // Calculate K (black)
|
|
87
|
+
// let k = Math.min(c, m, y);
|
|
88
|
+
|
|
89
|
+
// // Adjust CMY values
|
|
90
|
+
// c = (c - k) / (1 - k);
|
|
91
|
+
// m = (m - k) / (1 - k);
|
|
92
|
+
// y = (y - k) / (1 - k);
|
|
93
|
+
|
|
94
|
+
// // Round values to make them more manageable
|
|
95
|
+
// c = Math.round(c * 100);
|
|
96
|
+
// m = Math.round(m * 100);
|
|
97
|
+
// y = Math.round(y * 100);
|
|
98
|
+
// k = Math.round(k * 100);
|
|
99
|
+
|
|
100
|
+
// return [c, m, y, k];
|
|
101
|
+
|
|
102
|
+
// Convert hex to decimal
|
|
103
|
+
// const r = parseInt(hex.substring(0, 2), 16) / 255;
|
|
104
|
+
// const g = parseInt(hex.substring(2, 4), 16) / 255;
|
|
105
|
+
// const b = parseInt(hex.substring(4, 6), 16) / 255;
|
|
106
|
+
|
|
107
|
+
// // Find the maximum of RGB
|
|
108
|
+
// const max = Math.max(r, g, b);
|
|
109
|
+
|
|
110
|
+
// // Calculate K (black)
|
|
111
|
+
// const k = 1 - max;
|
|
112
|
+
|
|
113
|
+
// // Calculate CMY, considering white (1) is subtracted from RGB
|
|
114
|
+
// const c = (1 - r - k) / (1 - k);
|
|
115
|
+
// const m = (1 - g - k) / (1 - k);
|
|
116
|
+
// const y = (1 - b - k) / (1 - k);
|
|
117
|
+
|
|
118
|
+
// // Round values to make them more manageable
|
|
119
|
+
// const cPercent = Math.round(c * 100);
|
|
120
|
+
// const mPercent = Math.round(m * 100);
|
|
121
|
+
// const yPercent = Math.round(y * 100);
|
|
122
|
+
// const kPercent = Math.round(k * 100);
|
|
123
|
+
|
|
124
|
+
// return [cPercent, mPercent, yPercent, kPercent];
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
// TO RGB.
|
|
132
|
+
|
|
133
|
+
// Not a string.
|
|
134
|
+
if (typeof hex !== "string" && hex instanceof String === false) {
|
|
135
|
+
return hex;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Not a hex.
|
|
139
|
+
if (hex.charAt(0) !== "#") {
|
|
140
|
+
return hex; // perhaps a normal color like "blue".
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Remove the hash (#).
|
|
144
|
+
hex = hex.slice(1);
|
|
145
|
+
|
|
146
|
+
// Parse alpha
|
|
147
|
+
let alpha = 1;
|
|
148
|
+
if (hex.length > 6) {
|
|
149
|
+
alpha = parseInt(hex.slice(-2)) / 100
|
|
150
|
+
hex = hex.slice(0, -2);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Parse the hex color.
|
|
154
|
+
const bigint = parseInt(hex, 16);
|
|
155
|
+
let r = (bigint >> 16) & 255;
|
|
156
|
+
let g = (bigint >> 8) & 255;
|
|
157
|
+
let b = bigint & 255;
|
|
158
|
+
|
|
159
|
+
// TO CMYK.
|
|
160
|
+
|
|
161
|
+
var computedC = 0;
|
|
162
|
+
var computedM = 0;
|
|
163
|
+
var computedY = 0;
|
|
164
|
+
var computedK = 0;
|
|
165
|
+
|
|
166
|
+
//remove spaces from input RGB values, convert to int
|
|
167
|
+
r = parseInt( (''+r).replace(/\s/g,''),10 );
|
|
168
|
+
g = parseInt( (''+g).replace(/\s/g,''),10 );
|
|
169
|
+
b = parseInt( (''+b).replace(/\s/g,''),10 );
|
|
170
|
+
|
|
171
|
+
if (
|
|
172
|
+
r==null || g==null || b==null ||
|
|
173
|
+
isNaN(r) || isNaN(g)|| isNaN(b)
|
|
174
|
+
) {
|
|
175
|
+
console.error('Please enter numeric RGB values!');
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
if (r<0 || g<0 || b<0 || r>255 || g>255 || b>255) {
|
|
179
|
+
console.error ('RGB values must be in the range 0 to 255.');
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// BLACK
|
|
184
|
+
if (r==0 && g==0 && b==0) {
|
|
185
|
+
computedK = 1;
|
|
186
|
+
return [0,0,0,1];
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
computedC = 1 - (r/255);
|
|
190
|
+
computedM = 1 - (g/255);
|
|
191
|
+
computedY = 1 - (b/255);
|
|
192
|
+
|
|
193
|
+
var minCMY = Math.min(computedC,
|
|
194
|
+
Math.min(computedM,computedY));
|
|
195
|
+
computedC = Math.round((computedC - minCMY) / (1 - minCMY) * 100) ;
|
|
196
|
+
computedM = Math.round((computedM - minCMY) / (1 - minCMY) * 100) ;
|
|
197
|
+
computedY = Math.round((computedY - minCMY) / (1 - minCMY) * 100 );
|
|
198
|
+
computedK = Math.round(minCMY * 100);
|
|
199
|
+
|
|
200
|
+
// return [93, 2, 91, 6]
|
|
201
|
+
// return [0, 0, 0, 0]
|
|
202
|
+
return [computedC, computedM, computedY, computedK];
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
// ---------------------------------------------------------
|
|
208
|
+
// The pdf base element
|
|
209
|
+
// Element.
|
|
210
|
+
|
|
211
|
+
class Computed {
|
|
212
|
+
static ids = 0;
|
|
213
|
+
constructor({
|
|
214
|
+
start_x,
|
|
215
|
+
start_y,
|
|
216
|
+
resume_x,
|
|
217
|
+
resume_y,
|
|
218
|
+
inner_width = 0, // inner width without padding or margin.
|
|
219
|
+
inner_height = 0, // inner height without padding or margin.
|
|
220
|
+
is_absolute = false,
|
|
221
|
+
is_wrapped = false,
|
|
222
|
+
start_page = 0,
|
|
223
|
+
end_page = 0,
|
|
224
|
+
_padding, _margin,
|
|
225
|
+
}) {
|
|
226
|
+
this.start_x = start_x;
|
|
227
|
+
this.start_y = start_y;
|
|
228
|
+
this.resume_x = resume_x;
|
|
229
|
+
this.resume_y = resume_y;
|
|
230
|
+
this.inner_width = inner_width;
|
|
231
|
+
this.inner_height = inner_height;
|
|
232
|
+
this.is_absolute = is_absolute;
|
|
233
|
+
this.is_wrapped = is_wrapped;
|
|
234
|
+
this.start_page = start_page;
|
|
235
|
+
this.end_page = end_page;
|
|
236
|
+
this.allow_force_same_page = true;
|
|
237
|
+
this._margin = _margin;
|
|
238
|
+
this._padding = _padding;
|
|
239
|
+
|
|
240
|
+
++Computed.ids;
|
|
241
|
+
this._id = Computed.ids;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// Get end x/y.
|
|
245
|
+
get end_x() { return this.start_x + this._margin[1] + this._margin[3] + this._padding[1] + this._padding[3] + this.inner_width; }
|
|
246
|
+
get end_y() { return this.start_y + this._margin[0] + this._margin[2] + this._padding[0] + this._padding[2] + this.inner_height; }
|
|
247
|
+
|
|
248
|
+
// Start and end x/y from AFTER the margin.
|
|
249
|
+
get margin_start_x() { return this.start_x + this._margin[3]; }
|
|
250
|
+
get margin_end_x() { return this.end_x - this._margin[1]; }
|
|
251
|
+
get margin_start_y() { return this.start_y + this._margin[0]; }
|
|
252
|
+
get margin_end_y() { return this.end_y - this._margin[2]; }
|
|
253
|
+
|
|
254
|
+
// Start and end x/y from AFTER the padding and margin.
|
|
255
|
+
get padding_start_x() { return this.start_x + this._margin[3] + this._padding[3]; }
|
|
256
|
+
get padding_end_x() { return this.end_x - this._margin[1] - this._padding[1]; }
|
|
257
|
+
get padding_start_y() { return this.start_y + this._margin[0] + this._padding[0]; }
|
|
258
|
+
get padding_end_y() { return this.end_y - this._margin[2] - this._padding[2]; }
|
|
259
|
+
|
|
260
|
+
// As string for debugging.
|
|
261
|
+
toString() {
|
|
262
|
+
return {
|
|
263
|
+
id: this._id,
|
|
264
|
+
start_x: this.start_x,
|
|
265
|
+
start_y: this.start_y,
|
|
266
|
+
resume_x: this.resume_x,
|
|
267
|
+
resume_y: this.resume_y,
|
|
268
|
+
inner_width: this.inner_width,
|
|
269
|
+
inner_height: this.inner_height,
|
|
270
|
+
is_absolute: this.is_absolute,
|
|
271
|
+
is_wrapped: this.is_wrapped,
|
|
272
|
+
start_page: this.start_page,
|
|
273
|
+
end_page: this.end_page,
|
|
274
|
+
_margin: this._margin,
|
|
275
|
+
_padding: this._padding,
|
|
276
|
+
end_x: this.end_x,
|
|
277
|
+
end_y: this.end_y,
|
|
278
|
+
margin_start_x: this.margin_start_x,
|
|
279
|
+
margin_end_x: this.margin_end_x,
|
|
280
|
+
margin_start_y: this.margin_start_y,
|
|
281
|
+
margin_end_y: this.margin_end_y,
|
|
282
|
+
padding_start_x: this.padding_start_x,
|
|
283
|
+
padding_end_x: this.padding_end_x,
|
|
284
|
+
padding_start_y: this.padding_start_y,
|
|
285
|
+
padding_end_y: this.padding_end_y,
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
function CreateVElementClass({
|
|
292
|
+
type,
|
|
293
|
+
is_text = false,
|
|
294
|
+
is_img = false,
|
|
295
|
+
is_hstack = false,
|
|
296
|
+
is_stack = false,
|
|
297
|
+
}) {
|
|
298
|
+
class E {
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
// ---------------------------------------------------------
|
|
302
|
+
// Constructor.
|
|
303
|
+
|
|
304
|
+
constructor(...children) {
|
|
305
|
+
|
|
306
|
+
// Attributes.
|
|
307
|
+
this.type = type;
|
|
308
|
+
this._parent = null; // will be assigned by `_build().`
|
|
309
|
+
this._children = [];
|
|
310
|
+
this._text = null;
|
|
311
|
+
this._img = null;
|
|
312
|
+
this._options = {}; // for element options.
|
|
313
|
+
this._calls = {}; // for doc calls.
|
|
314
|
+
this._id = null;
|
|
315
|
+
this._width = undefined;
|
|
316
|
+
this._height = undefined;
|
|
317
|
+
this._stretch = undefined;
|
|
318
|
+
this._margin = [0, 0, 0, 0];
|
|
319
|
+
this._padding = [0, 0, 0, 0];
|
|
320
|
+
this._position = [null, null, null, null]; // absolute positioning.
|
|
321
|
+
this._background = null;
|
|
322
|
+
this._border_radius = null;
|
|
323
|
+
this._border_color = null;
|
|
324
|
+
this._border_width = 1;
|
|
325
|
+
this._font = null;
|
|
326
|
+
this._font_weight = null;
|
|
327
|
+
// this._wrap = true;
|
|
328
|
+
this._href = null;
|
|
329
|
+
this._force_same_page = false;
|
|
330
|
+
this._page = undefined;
|
|
331
|
+
this._valign = undefined;
|
|
332
|
+
|
|
333
|
+
// Static attributes but keep as member.
|
|
334
|
+
this.is_text = is_text;
|
|
335
|
+
this.is_img = is_img;
|
|
336
|
+
this.is_hstack = is_hstack;
|
|
337
|
+
this.is_stack = is_stack;
|
|
338
|
+
|
|
339
|
+
// Append.
|
|
340
|
+
this.append(...children);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
copy() {
|
|
344
|
+
|
|
345
|
+
const copy = new this.constructor(this._children);
|
|
346
|
+
|
|
347
|
+
// Attributes.
|
|
348
|
+
copy.type = this.type;
|
|
349
|
+
copy._parent = this._parent;
|
|
350
|
+
copy._children = this._children;
|
|
351
|
+
copy._text = this._text;
|
|
352
|
+
copy._img = this._img;
|
|
353
|
+
copy._style = this._options;
|
|
354
|
+
copy._calls = this._calls;
|
|
355
|
+
copy._id = this._id;
|
|
356
|
+
copy._width = this._width;
|
|
357
|
+
copy._height = this._height;
|
|
358
|
+
copy._stretch = this.stretch;
|
|
359
|
+
copy._margin = this._margin;
|
|
360
|
+
copy._padding = this._padding;
|
|
361
|
+
copy._position = this._position;
|
|
362
|
+
copy._background = this._background;
|
|
363
|
+
copy._border_radius = this._border_radius;
|
|
364
|
+
copy._border_color = this._border_color;
|
|
365
|
+
copy._border_width = this._border_width;
|
|
366
|
+
copy._font = this._font;
|
|
367
|
+
copy._font_weight = this._font_weight;
|
|
368
|
+
// copy._wrap = this._wrap;
|
|
369
|
+
copy._href = this._href;
|
|
370
|
+
copy._force_same_page = this._force_same_page;
|
|
371
|
+
copy._page = this._page;
|
|
372
|
+
copy._valign = this._valign;
|
|
373
|
+
|
|
374
|
+
return copy;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
// ---------------------------------------------------------
|
|
378
|
+
// System.
|
|
379
|
+
|
|
380
|
+
// Set doc styling.
|
|
381
|
+
_set_styling(doc) {
|
|
382
|
+
this._restore = {};
|
|
383
|
+
|
|
384
|
+
// Execute document calls.
|
|
385
|
+
Object.keys(this._calls).iterate((func) => {
|
|
386
|
+
if (func === "setFont") {
|
|
387
|
+
return null;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
// Cache.
|
|
391
|
+
this._restore[func] = doc["g"+func.substr(1)]();
|
|
392
|
+
|
|
393
|
+
// Array.
|
|
394
|
+
if (Array.isArray(this._calls[func])) {
|
|
395
|
+
doc[func](...this._calls[func])
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
// Single arg.
|
|
399
|
+
else {
|
|
400
|
+
doc[func](this._calls[func])
|
|
401
|
+
}
|
|
402
|
+
})
|
|
403
|
+
|
|
404
|
+
// Font.
|
|
405
|
+
if (this._font != null || this._font_weight != null) {
|
|
406
|
+
const font = doc.getFont();
|
|
407
|
+
this._restore.setFont = [font.fontName, font.fontStyle];
|
|
408
|
+
doc.setFont(this._font || doc.fontName, this._font_weight || doc.fontStyle);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
// Restore doc styling.
|
|
413
|
+
_restore_styling(doc) {
|
|
414
|
+
Object.keys(this._restore).iterate((func) => {
|
|
415
|
+
if (Array.isArray(this._restore[func])) {
|
|
416
|
+
doc[func](...this._restore[func])
|
|
417
|
+
} else {
|
|
418
|
+
doc[func](this._restore[func])
|
|
419
|
+
}
|
|
420
|
+
})
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
// Check if the _text attr contains whitespace.
|
|
424
|
+
_has_whitespace() {
|
|
425
|
+
if (!this.is_text) { return false; }
|
|
426
|
+
for (let i = 0; i < this._text.length; i++) {
|
|
427
|
+
const c = this._text.charAt(i);
|
|
428
|
+
if (c === " " || c === "\t") {
|
|
429
|
+
return true;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
return false;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
// Compute.
|
|
436
|
+
_compute(doc, x, y, page, refresh = false) {
|
|
437
|
+
|
|
438
|
+
// Cached.
|
|
439
|
+
if (refresh === false && this._computed !== undefined) {
|
|
440
|
+
return this._computed;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
// Is PDF type.
|
|
444
|
+
if (this.type === "PDF" && doc == null) {
|
|
445
|
+
this._create_doc();
|
|
446
|
+
doc = this._doc;
|
|
447
|
+
x = 0;//doc._volt_margin_left;
|
|
448
|
+
y = 0;//doc._volt_margin_top;
|
|
449
|
+
page = 1;
|
|
450
|
+
refresh = true;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
// Initialize.
|
|
454
|
+
if (this._initialize !== undefined) {
|
|
455
|
+
this._initialize();
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
// Convert text to string, since instance String is also not accepted by jspdf.
|
|
459
|
+
if (this._text != null) {
|
|
460
|
+
this._text = this._text.toString();
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
// --------------------------------------------------------------------------------
|
|
464
|
+
// Pre compute.
|
|
465
|
+
|
|
466
|
+
// Flags.
|
|
467
|
+
const is_absolute = this._position[0] != null || this._position[1] != null || this._position[2] != null || this._position[3] != null
|
|
468
|
+
if (this._page != null) {
|
|
469
|
+
if (!is_absolute) {
|
|
470
|
+
throw Error(`Only absolute positioned elements may define an explicit page using "page()".`);
|
|
471
|
+
}
|
|
472
|
+
page = this._page;
|
|
473
|
+
}
|
|
474
|
+
let computed = new Computed({
|
|
475
|
+
start_x: x,
|
|
476
|
+
start_y: y,
|
|
477
|
+
resume_x: x,
|
|
478
|
+
resume_y: y,
|
|
479
|
+
start_page: page,
|
|
480
|
+
end_page: page,
|
|
481
|
+
is_absolute,
|
|
482
|
+
_margin: this._margin,
|
|
483
|
+
_padding: this._padding,
|
|
484
|
+
})
|
|
485
|
+
|
|
486
|
+
// Add page.
|
|
487
|
+
if (this.type === "Page") {
|
|
488
|
+
computed.start_x = doc._volt_margin_left;
|
|
489
|
+
computed.start_y = doc._volt_margin_top;
|
|
490
|
+
++page;
|
|
491
|
+
++computed.start_page;
|
|
492
|
+
++computed.end_page;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
// Absolute positioning, ignore document margins!
|
|
496
|
+
let is_absolute_right = false;
|
|
497
|
+
let is_absolute_bottom = false;
|
|
498
|
+
if (computed.is_absolute) {
|
|
499
|
+
if (this._position[1] != null && this._position[3] != null) {
|
|
500
|
+
computed.start_x = this._position[3];
|
|
501
|
+
this._width = doc._volt_page_width - this._position[1] - this._position[3];
|
|
502
|
+
} else if (this._position[1] != null) {
|
|
503
|
+
computed.start_x = doc._volt_page_width - this._position[1] - this._margin[1] - this._margin[3] - this._padding[1] - this._padding[3];
|
|
504
|
+
is_absolute_right = true;
|
|
505
|
+
} else if (this._position[3] != null) {
|
|
506
|
+
computed.start_x = this._position[3];
|
|
507
|
+
}
|
|
508
|
+
if (this._position[0] != null && this._position[2] != null) {
|
|
509
|
+
computed.start_y = this._position[0];
|
|
510
|
+
this._height = doc._volt_page_height - this._position[0] - this._position[2];
|
|
511
|
+
} else if (this._position[0] != null) {
|
|
512
|
+
computed.start_y = this._position[0];
|
|
513
|
+
} else if (this._position[2] != null) {
|
|
514
|
+
computed.start_y = doc._volt_page_height - this._position[2] - this._margin[0] - this._margin[2] - this._padding[0] - this._padding[2];
|
|
515
|
+
is_absolute_bottom = true;
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
// Set relative width.
|
|
520
|
+
if (typeof this._width === "string" && this._width.last() === "%") {
|
|
521
|
+
if (this._parent != null && this._parent._max_width != null) {
|
|
522
|
+
this._width = Math.max(
|
|
523
|
+
0,
|
|
524
|
+
this._parent._max_width * (parseInt(this._width.slice(0, -1)) / 100)
|
|
525
|
+
- (this._margin[1] + this._margin[3] + this._padding[1] + this._padding[3])
|
|
526
|
+
);
|
|
527
|
+
} else {
|
|
528
|
+
delete this._width;
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
// Calculate the max X (after padding and margin are added to x) (after calc relative width).
|
|
533
|
+
if (this._parent == null || this._parent._max_x != null) {
|
|
534
|
+
this._max_x = doc._volt_page_width - doc._volt_margin_right;
|
|
535
|
+
} else {
|
|
536
|
+
this._max_x = this._parent._max_x;
|
|
537
|
+
}
|
|
538
|
+
if (this._width != null) {
|
|
539
|
+
this._max_x = Math.min(x + this._width, this._max_x);
|
|
540
|
+
}
|
|
541
|
+
this._max_x -= (this._margin[1] - this._padding[1]);
|
|
542
|
+
|
|
543
|
+
// Calculate the max width (after padding and margin are added to x) (after calc relative width).
|
|
544
|
+
this._max_width = parseInt(this._max_x - x); // round down otherwise some text might overflow its background.
|
|
545
|
+
|
|
546
|
+
// --------------------------------------------------------------------------------
|
|
547
|
+
// Doc styling.
|
|
548
|
+
|
|
549
|
+
this._set_styling(doc);
|
|
550
|
+
|
|
551
|
+
// --------------------------------------------------------------------------------
|
|
552
|
+
// Calculate inner width and height.
|
|
553
|
+
|
|
554
|
+
// Add image / text.
|
|
555
|
+
if (this.is_text || this.is_img) {
|
|
556
|
+
|
|
557
|
+
// Vars.
|
|
558
|
+
let width = 0, height = 0, dimensions;
|
|
559
|
+
const has_whitespace = this._has_whitespace();
|
|
560
|
+
|
|
561
|
+
// Check width & height.
|
|
562
|
+
if (this.is_img) {
|
|
563
|
+
if (this._width == null) {
|
|
564
|
+
throw Error("A defined width is required for an \"Image\" element.");
|
|
565
|
+
}
|
|
566
|
+
if (this._height == null) {
|
|
567
|
+
throw Error("A defined height is required for an \"Image\" element.");
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
// Check wrap.
|
|
572
|
+
if (this._width != null) {
|
|
573
|
+
width = this._width;
|
|
574
|
+
}
|
|
575
|
+
else if (this.is_text) {
|
|
576
|
+
let no_spaces = "", space_count = 0;
|
|
577
|
+
for (let i = 0; i < this._text.length; i++) {
|
|
578
|
+
const c = this._text.charAt(i);
|
|
579
|
+
if (c === " ") {
|
|
580
|
+
++space_count;
|
|
581
|
+
} else if (c === "\t") {
|
|
582
|
+
space_count += 8;
|
|
583
|
+
} else {
|
|
584
|
+
no_spaces += c;
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
dimensions = doc.getTextDimensions(no_spaces);
|
|
588
|
+
width = dimensions.w + (doc.getStringUnitWidth(" ") * doc.getFontSize() * space_count); // does not account for line breaks.
|
|
589
|
+
// width = dimensions.w / doc.internal.scaleFactor
|
|
590
|
+
}
|
|
591
|
+
if (width > this._max_width) {
|
|
592
|
+
width = this._max_width;
|
|
593
|
+
if (this._width != null) { this._width = width; } // prevent inifnite loop.
|
|
594
|
+
if (this.is_text && !has_whitespace && width < this._parent._max_width) {
|
|
595
|
+
this._restore_styling(doc);
|
|
596
|
+
const computed = this._compute(doc, this._parent._wrap_x, this._parent._wrap_y, page, true);
|
|
597
|
+
computed.has_wrapped = true;
|
|
598
|
+
return computed;
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
if (this._font_weight === "bold") {
|
|
602
|
+
width *= 1.04;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
// Get height (must be after width in case of adjustments).
|
|
606
|
+
if (this._height != null) {
|
|
607
|
+
height = this._height;
|
|
608
|
+
}
|
|
609
|
+
else if (this.is_text) {
|
|
610
|
+
if (dimensions === undefined) {
|
|
611
|
+
dimensions = doc.getTextDimensions(this._text);
|
|
612
|
+
}
|
|
613
|
+
// let height_correction = false;
|
|
614
|
+
if (!has_whitespace && width < this._parent._max_width) {
|
|
615
|
+
height = 1 * (dimensions.h * doc.getLineHeightFactor());
|
|
616
|
+
} else {
|
|
617
|
+
const lines = doc.splitTextToSize(this._text, width);
|
|
618
|
+
height = lines.length * (dimensions.h * doc.getLineHeightFactor());
|
|
619
|
+
}
|
|
620
|
+
height += dimensions.h * doc.getLineHeightFactor() * 0.15; // small height correction since the default jspdf padding top is small and padding bottom is none.
|
|
621
|
+
// do not assign to this._height since that causes problems with `copy()` while splitting long text into sub texts.
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
// Adjust coordinates.
|
|
625
|
+
computed.inner_width = width;
|
|
626
|
+
computed.inner_height = height;
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
// Check children, also when length is 0, in order to add the width and height etc.
|
|
630
|
+
else {
|
|
631
|
+
|
|
632
|
+
// Vars.
|
|
633
|
+
let max_child_x = 0, max_child_y = 0;
|
|
634
|
+
let x = computed.padding_start_x;
|
|
635
|
+
let y = computed.padding_start_y;
|
|
636
|
+
let child_page = page;
|
|
637
|
+
let stretch_children = [], row_children = [];
|
|
638
|
+
this._wrap_x = x;
|
|
639
|
+
|
|
640
|
+
// Apply vertical alignment.
|
|
641
|
+
const apply_vertical_alignment = (children) => {
|
|
642
|
+
|
|
643
|
+
// Vars.
|
|
644
|
+
const is_center = this._valign === "center";
|
|
645
|
+
const is_trailing = this._valign === "trailing";
|
|
646
|
+
if (!is_center && !is_trailing) { return ; }
|
|
647
|
+
|
|
648
|
+
// Get highest child.
|
|
649
|
+
let max_height = 0;
|
|
650
|
+
children.iterate((child) => {
|
|
651
|
+
const height = child._computed.inner_height + child._computed._padding[0] + child._computed._padding[2]
|
|
652
|
+
if (!child._computed.is_absolute && height > max_height) {
|
|
653
|
+
max_height = height;
|
|
654
|
+
}
|
|
655
|
+
});
|
|
656
|
+
|
|
657
|
+
// Apply alignment.
|
|
658
|
+
children.iterate((child) => {
|
|
659
|
+
if (!child._computed.is_absolute) {
|
|
660
|
+
const height = child._computed.inner_height + child._computed._padding[0] + child._computed._padding[2]
|
|
661
|
+
if (is_center) {
|
|
662
|
+
child._computed.start_y += (max_height - height) / 2;
|
|
663
|
+
} else if (is_trailing) {
|
|
664
|
+
child._computed.start_y += max_height - height;
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
});
|
|
668
|
+
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
// Iterate.
|
|
672
|
+
this._children.iterate((child) => {
|
|
673
|
+
|
|
674
|
+
// Vars.
|
|
675
|
+
const is_stack = child.is_stack;
|
|
676
|
+
|
|
677
|
+
// Assign parent.
|
|
678
|
+
child._parent = this;
|
|
679
|
+
|
|
680
|
+
// Compute.
|
|
681
|
+
let response = child._compute(doc, x, y, child_page, refresh);
|
|
682
|
+
|
|
683
|
+
// New page.
|
|
684
|
+
if (response.end_page > computed.end_page) {
|
|
685
|
+
|
|
686
|
+
// Apply vertical alignment.
|
|
687
|
+
apply_vertical_alignment(row_children);
|
|
688
|
+
row_children = [];
|
|
689
|
+
|
|
690
|
+
// Reset stretch children.
|
|
691
|
+
stretch_children = [];
|
|
692
|
+
|
|
693
|
+
// Go to next page.
|
|
694
|
+
child_page = response.end_page;
|
|
695
|
+
computed.end_page = response.end_page;
|
|
696
|
+
if (this.is_hstack) {
|
|
697
|
+
x = response.resume_x;
|
|
698
|
+
y = doc._volt_margin_top;
|
|
699
|
+
|
|
700
|
+
// Wrap to new y.
|
|
701
|
+
if (response.has_wrapped || response.resume_x >= this._max_x) {
|
|
702
|
+
x = response.has_wrapped ? response.resume_x : this._wrap_x;
|
|
703
|
+
y = this._wrap_y === undefined ? response.resume_y : this._wrap_y;
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
} else {
|
|
707
|
+
x = this._wrap_x;
|
|
708
|
+
y = response.resume_y;
|
|
709
|
+
}
|
|
710
|
+
max_child_x = x;
|
|
711
|
+
max_child_y = y;
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
// Increment X/Y.
|
|
715
|
+
else if (this.is_hstack) {
|
|
716
|
+
x = response.resume_x;
|
|
717
|
+
|
|
718
|
+
// Wrap to new y.
|
|
719
|
+
if (response.has_wrapped || response.resume_x >= this._max_x) {
|
|
720
|
+
x = response.has_wrapped ? response.resume_x : this._wrap_x;
|
|
721
|
+
y = this._wrap_y === undefined ? response.resume_y : this._wrap_y;
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
// Resume on y.
|
|
727
|
+
else {
|
|
728
|
+
y = response.resume_y;
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
// Cache max y.
|
|
732
|
+
// Must be after increment x/y for wrapping.
|
|
733
|
+
if (response.resume_y > max_child_y) {
|
|
734
|
+
max_child_y = response.resume_y;
|
|
735
|
+
this._wrap_y = max_child_y;
|
|
736
|
+
}
|
|
737
|
+
if (response.resume_x > max_child_x) {
|
|
738
|
+
max_child_x = response.resume_x;
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
// Append stretch child.
|
|
742
|
+
if (child._stretch) {
|
|
743
|
+
stretch_children.append(child)
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
// Append row children.
|
|
747
|
+
row_children.append(child)
|
|
748
|
+
|
|
749
|
+
})
|
|
750
|
+
|
|
751
|
+
// Apply vertical alignment.
|
|
752
|
+
apply_vertical_alignment(row_children);
|
|
753
|
+
|
|
754
|
+
// Stretch.
|
|
755
|
+
if (stretch_children.length > 0) {
|
|
756
|
+
if (this.is_hstack) {
|
|
757
|
+
const step = (this._max_x - max_child_x) / stretch_children.length;
|
|
758
|
+
let incr_x = 0;
|
|
759
|
+
row_children.iterate((child) => {
|
|
760
|
+
child._computed.start_x += incr_x;
|
|
761
|
+
if (child._stretch) {
|
|
762
|
+
child._computed.inner_width += step;
|
|
763
|
+
incr_x += step;
|
|
764
|
+
console.log("Stretch:", child.type, child._text, step)
|
|
765
|
+
}
|
|
766
|
+
})
|
|
767
|
+
} else {
|
|
768
|
+
// still to do.
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
// @todo is still incorrect when one of the children creates a new page.
|
|
773
|
+
// Could fill "stretch" widths over here.
|
|
774
|
+
// Set X/Y to max of children.
|
|
775
|
+
if (this._width == null) {
|
|
776
|
+
computed.inner_width = Math.max(0, max_child_x - computed.padding_start_x);
|
|
777
|
+
} else {
|
|
778
|
+
computed.inner_width = Math.max(this._width, max_child_x - computed.padding_start_x);
|
|
779
|
+
}
|
|
780
|
+
if (this._height == null) {
|
|
781
|
+
computed.inner_height = Math.max(0, max_child_y - computed.padding_start_y);
|
|
782
|
+
} else {
|
|
783
|
+
computed.inner_height = Math.max(this._height, max_child_y - computed.padding_start_y);
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
// --------------------------------------------------------------------------------
|
|
788
|
+
// Post compute.
|
|
789
|
+
|
|
790
|
+
// Decrement start x with width when an absolute right is used.
|
|
791
|
+
if (is_absolute_right) {
|
|
792
|
+
computed.start_x -= computed.inner_width;
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
// Decrement start y with height when an absolute bottom is used.
|
|
796
|
+
if (is_absolute_bottom) {
|
|
797
|
+
computed.start_y -= computed.inner_height;
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
// Set resume x/y.
|
|
801
|
+
if (!computed.is_absolute) {
|
|
802
|
+
computed.resume_x = computed.end_x;
|
|
803
|
+
computed.resume_y = computed.end_y;
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
// Check new page required for non stacks.
|
|
807
|
+
if (
|
|
808
|
+
!is_absolute && computed.resume_y > doc._volt_page_height - doc._volt_margin_bottom &&
|
|
809
|
+
(this.is_text || this.is_img) // not for stacks.
|
|
810
|
+
) {
|
|
811
|
+
|
|
812
|
+
// For texts.
|
|
813
|
+
if (this.is_text) {
|
|
814
|
+
|
|
815
|
+
// Split text into lines.
|
|
816
|
+
const line_height_factor = doc.getLineHeightFactor();
|
|
817
|
+
const dimensions = doc.getTextDimensions(this._text);
|
|
818
|
+
let lines = doc.splitTextToSize(this._text, computed.inner_width);
|
|
819
|
+
const get_break_index = (max_height) => {
|
|
820
|
+
let i, height;
|
|
821
|
+
for (i = 0; i < lines.length; i++) {
|
|
822
|
+
height = (i+1) * (dimensions.h * line_height_factor); // here i+1 is required or it will calc wrong and cause inf loop.
|
|
823
|
+
height += dimensions.h * line_height_factor * 0.15;
|
|
824
|
+
if (height >= max_height) {
|
|
825
|
+
return i - 1;
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
return i;
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
// When the text can not be split since there is not any space to split even a single line, then wrap the entire text to the new page.
|
|
832
|
+
if (
|
|
833
|
+
computed.padding_start_y + dimensions.h > doc._volt_page_height - doc._volt_margin_bottom
|
|
834
|
+
) {
|
|
835
|
+
this._restore_styling(doc);
|
|
836
|
+
return this._compute(doc, this._parent._wrap_x, doc._volt_margin_top, page + 1, true);
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
// Restore styling for new computations.
|
|
840
|
+
this._restore_styling(doc);
|
|
841
|
+
|
|
842
|
+
// Split text into multiple texts.
|
|
843
|
+
let remaining_text = this._text;
|
|
844
|
+
const sub_texts = [];
|
|
845
|
+
let child_page = page;
|
|
846
|
+
for (let i = 0; i < 100000; i++) {
|
|
847
|
+
|
|
848
|
+
// Get break index.
|
|
849
|
+
const max_height = i === 0 ? (doc._volt_page_height - doc._volt_margin_bottom) - computed.padding_start_y : doc._volt_page_height - doc._volt_margin_bottom - doc._volt_margin_top;
|
|
850
|
+
const break_index = get_break_index(max_height)
|
|
851
|
+
const is_last = break_index == lines.length;
|
|
852
|
+
|
|
853
|
+
// Nothing fits.
|
|
854
|
+
if (break_index === 0) {
|
|
855
|
+
++child_page;
|
|
856
|
+
continue;
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
// Create copy.
|
|
860
|
+
const copy = this.copy();
|
|
861
|
+
copy._parent = this._parent;
|
|
862
|
+
|
|
863
|
+
// Remove bottom padding and margin.
|
|
864
|
+
if (!is_last) {
|
|
865
|
+
copy._margin[3] = 0;
|
|
866
|
+
copy._padding[3] = 0;
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
// Remove top padding.
|
|
870
|
+
if (i > 0) {
|
|
871
|
+
copy._margin[0] = 0;
|
|
872
|
+
copy._padding[0] = 0;
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
// Slice text.
|
|
876
|
+
copy._text = lines.slice(0, break_index).join("\n");
|
|
877
|
+
lines = lines.slice(break_index);
|
|
878
|
+
|
|
879
|
+
// Add page.
|
|
880
|
+
if (i > 0) {
|
|
881
|
+
++child_page;
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
// Recompute.
|
|
885
|
+
// process.exit(0)
|
|
886
|
+
copy._compute(
|
|
887
|
+
doc,
|
|
888
|
+
i === 0 ? computed.start_x : this._parent._wrap_x,
|
|
889
|
+
i === 0 ? computed.start_y : doc._volt_margin_top,
|
|
890
|
+
child_page,
|
|
891
|
+
true,
|
|
892
|
+
);
|
|
893
|
+
|
|
894
|
+
// Append.
|
|
895
|
+
sub_texts.append(copy);
|
|
896
|
+
|
|
897
|
+
// Stop.
|
|
898
|
+
if (is_last) {
|
|
899
|
+
break;
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
// Insert.
|
|
905
|
+
this._parent.insert_before(this, sub_texts);
|
|
906
|
+
this._parent.remove_child(this);
|
|
907
|
+
return sub_texts.last()._computed;
|
|
908
|
+
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
// For images that do fit on a single page.
|
|
912
|
+
else if (this.is_img && fits_on_one_page) {
|
|
913
|
+
this._restore_styling(doc);
|
|
914
|
+
return this._compute(doc, this._parent._wrap_x, doc._volt_margin_top, page + 1, true);
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
// Check force same page for stacks.
|
|
919
|
+
const is_stack = this.is_stack;
|
|
920
|
+
if (
|
|
921
|
+
!is_absolute &&
|
|
922
|
+
is_stack &&
|
|
923
|
+
this._force_same_page &&
|
|
924
|
+
computed.start_page !== computed.end_page &&
|
|
925
|
+
computed.end_y - computed.start_y <= doc._volt_page_height - doc._volt_margin_bottom - doc._volt_margin_top // must fit on one page.
|
|
926
|
+
) {
|
|
927
|
+
this._restore_styling(doc);
|
|
928
|
+
return this._compute(doc, this._parent._wrap_x, doc._volt_margin_top, page + 1, true);
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
// Restore func calls and font.
|
|
932
|
+
this._restore_styling(doc);
|
|
933
|
+
|
|
934
|
+
// Response.
|
|
935
|
+
console.log(this.type, this._text, computed.start_y)
|
|
936
|
+
this._computed = computed;
|
|
937
|
+
return this._computed;
|
|
938
|
+
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
// Build element.
|
|
942
|
+
_build(doc) {
|
|
943
|
+
|
|
944
|
+
// Is PDF type.
|
|
945
|
+
if (this.type === "PDF") {
|
|
946
|
+
this._create_doc();
|
|
947
|
+
doc = this._doc;
|
|
948
|
+
this._compute(doc, 0, 0, 1, true)
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
// Compute.
|
|
952
|
+
const computed = this._computed;
|
|
953
|
+
|
|
954
|
+
// Add all pages.
|
|
955
|
+
if (this.type === "PDF") {
|
|
956
|
+
for (let i = 0; i < computed.end_page - 1; i++) { // the first page is already added.
|
|
957
|
+
doc.addPage();
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
// Switch to page.
|
|
962
|
+
doc.setPage(computed.start_page);
|
|
963
|
+
|
|
964
|
+
// Set styling.
|
|
965
|
+
this._set_styling(doc);
|
|
966
|
+
|
|
967
|
+
// Add background.
|
|
968
|
+
if (typeof this._background === "string" || typeof this._border_color === "string") {
|
|
969
|
+
|
|
970
|
+
let x = computed.margin_start_x, rect_width = computed.margin_end_x - computed.margin_start_x;
|
|
971
|
+
let y, rect_height;
|
|
972
|
+
let color;
|
|
973
|
+
for (let i = computed.start_page; i <= computed.end_page; i++) {
|
|
974
|
+
|
|
975
|
+
doc.setPage(i);
|
|
976
|
+
|
|
977
|
+
// Only one page.
|
|
978
|
+
if (computed.start_page === computed.end_page) {
|
|
979
|
+
y = computed.margin_start_y;
|
|
980
|
+
rect_height = computed.margin_end_y - computed.margin_start_y;
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
// On first page.
|
|
984
|
+
else if (i === computed.start_page) {
|
|
985
|
+
y = computed.margin_start_y;
|
|
986
|
+
rect_height = (doc._volt_page_height - doc._volt_margin_bottom) - computed.margin_start_y;
|
|
987
|
+
}
|
|
988
|
+
|
|
989
|
+
// On last page.
|
|
990
|
+
else if (i === computed.end_page) {
|
|
991
|
+
y = doc._volt_margin_top// - this._padding[0];
|
|
992
|
+
rect_height = computed.margin_end_y - doc._volt_margin_bottom// + this._padding[2];
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
// In between pages.
|
|
996
|
+
else {
|
|
997
|
+
y = doc._volt_margin_top// - this._padding[0];
|
|
998
|
+
rect_height = doc._volt_page_height - doc._volt_margin_bottom - doc._volt_margin_top// + this._padding[2];
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
// Check percentage border radius.
|
|
1002
|
+
let border_radius = this._border_radius;
|
|
1003
|
+
if (typeof border_radius === "string" && border_radius.last() === "%") {
|
|
1004
|
+
border_radius = Math.min(rect_width, rect_height) * (parseInt(border_radius.slice(0, -1)) / 100);
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
// Background color.
|
|
1008
|
+
if (typeof this._background === "string") {
|
|
1009
|
+
color = PDF.hex_to_rgb(this._background);
|
|
1010
|
+
let restore = false;
|
|
1011
|
+
if (Array.isArray(color)) {
|
|
1012
|
+
if (color.length === 4) {
|
|
1013
|
+
restore = true;
|
|
1014
|
+
doc.saveGraphicsState();
|
|
1015
|
+
doc.setGState(new doc.GState({opacity: color[3]}));
|
|
1016
|
+
--color.length;
|
|
1017
|
+
}
|
|
1018
|
+
doc.setFillColor(...color);
|
|
1019
|
+
} else {
|
|
1020
|
+
doc.setFillColor(color);
|
|
1021
|
+
}
|
|
1022
|
+
if (border_radius != null) {
|
|
1023
|
+
doc.roundedRect(x, y, rect_width, rect_height, border_radius, border_radius, "F"); // fill.
|
|
1024
|
+
} else {
|
|
1025
|
+
doc.rect(x, y, rect_width, rect_height, "F"); // fill.
|
|
1026
|
+
}
|
|
1027
|
+
if (restore) { doc.restoreGraphicsState(); }
|
|
1028
|
+
}
|
|
1029
|
+
|
|
1030
|
+
// Border color.
|
|
1031
|
+
if (typeof this._border_color === "string") {
|
|
1032
|
+
doc.setLineWidth(this._border_width === undefined ? 1 : this._border_width);
|
|
1033
|
+
color = PDF.hex_to_rgb(this._border_color);
|
|
1034
|
+
let restore = false;
|
|
1035
|
+
if (Array.isArray(color)) {
|
|
1036
|
+
if (color.length === 4) {
|
|
1037
|
+
restore = true;
|
|
1038
|
+
doc.saveGraphicsState();
|
|
1039
|
+
doc.setGState(new doc.GState({"stroke-opacity": color[3]}));
|
|
1040
|
+
--color.length;
|
|
1041
|
+
}
|
|
1042
|
+
doc.setDrawColor(...color);
|
|
1043
|
+
} else {
|
|
1044
|
+
doc.setDrawColor(color);
|
|
1045
|
+
}
|
|
1046
|
+
if (border_radius != null) {
|
|
1047
|
+
doc.roundedRect(x, y, rect_width, rect_height, border_radius, border_radius, "S"); // stroke.
|
|
1048
|
+
} else {
|
|
1049
|
+
doc.rect(x, y, rect_width, rect_height, "S"); // stroke.
|
|
1050
|
+
}
|
|
1051
|
+
if (restore) { doc.restoreGraphicsState(); }
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
// Restore.
|
|
1056
|
+
this._restore_styling(doc);
|
|
1057
|
+
doc.setPage(computed.start_page);
|
|
1058
|
+
this._set_styling(doc);
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
// Id.
|
|
1062
|
+
if (this._id != null) {
|
|
1063
|
+
doc._volt_ids[this._id] = computed.start_page;
|
|
1064
|
+
}
|
|
1065
|
+
|
|
1066
|
+
// Add image / text.
|
|
1067
|
+
if (this.is_text || this.is_img) {
|
|
1068
|
+
|
|
1069
|
+
// Href.
|
|
1070
|
+
if (this._href != null) {
|
|
1071
|
+
if (this._href.startsWith("http")) {
|
|
1072
|
+
doc.link(x, y, width, height, this._href);
|
|
1073
|
+
} else {
|
|
1074
|
+
doc._volt_hrefs.append({
|
|
1075
|
+
page: computed.start_page,
|
|
1076
|
+
href: this._href,
|
|
1077
|
+
args: [x, y, width, height],
|
|
1078
|
+
})
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
// Element.
|
|
1083
|
+
if (this.is_text) {
|
|
1084
|
+
// this._options.maxWidth = computed.inner_width; // sometimes jspdf's width calculation is just a tiny bit off which causes the text to wrap, so this line must remain commented out.
|
|
1085
|
+
const font_size = doc.getFontSize();
|
|
1086
|
+
let x = computed.padding_start_x;
|
|
1087
|
+
let y = computed.padding_start_y + font_size
|
|
1088
|
+
if (this._options.align === "right") {
|
|
1089
|
+
x += computed.inner_width;
|
|
1090
|
+
}
|
|
1091
|
+
y -= font_size * 0.05; // since default top padding is too large.
|
|
1092
|
+
doc.text(this._text, x, y, this._options); // account for baseline y behaviour.
|
|
1093
|
+
} else if (this.is_img) {
|
|
1094
|
+
doc.addImage(
|
|
1095
|
+
libfs.readFileSync(this._img).toString('base64'),
|
|
1096
|
+
new vlib.Path(this._img).extension().slice(1).toUpperCase(),
|
|
1097
|
+
computed.padding_start_x,
|
|
1098
|
+
computed.padding_start_y,
|
|
1099
|
+
this._width,
|
|
1100
|
+
this._height,
|
|
1101
|
+
);
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
// With children.
|
|
1106
|
+
else if (this._children.length > 0) {
|
|
1107
|
+
|
|
1108
|
+
// Add children.
|
|
1109
|
+
this._children.iterate((child) => {
|
|
1110
|
+
child._build(doc);
|
|
1111
|
+
})
|
|
1112
|
+
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
// Restore func calls and font.
|
|
1116
|
+
this._restore_styling(doc);
|
|
1117
|
+
|
|
1118
|
+
// End.
|
|
1119
|
+
if (this.type === "PDF") {
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1124
|
+
// ---------------------------------------------------------
|
|
1125
|
+
// Functions.
|
|
1126
|
+
|
|
1127
|
+
// As string.
|
|
1128
|
+
toString(indent = 0) {
|
|
1129
|
+
let indent_str = "";
|
|
1130
|
+
for (let i = 0; i < indent; i++) { indent_str += " "; }
|
|
1131
|
+
if (this.children.length > 0) {
|
|
1132
|
+
let str = `${indent_str}${this.type}(\n`;
|
|
1133
|
+
str += this._children.iterate_append((c) => c.toString(indent + 4)).join(",\n");
|
|
1134
|
+
str += `\n${indent_str})`;
|
|
1135
|
+
return str;
|
|
1136
|
+
} else if (this.type === "Text") {
|
|
1137
|
+
return `${indent_str}${this.type}("${this._text}")`;
|
|
1138
|
+
} else if (this.type === "Image") {
|
|
1139
|
+
return `${indent_str}${this.type}("${this._img}")`;
|
|
1140
|
+
} else {
|
|
1141
|
+
return `${indent_str}${this.type}()`;
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1144
|
+
|
|
1145
|
+
// Get/set text.
|
|
1146
|
+
text(val) {
|
|
1147
|
+
if (val === undefined) { return this._text; }
|
|
1148
|
+
this._text = val;
|
|
1149
|
+
return this;
|
|
1150
|
+
}
|
|
1151
|
+
|
|
1152
|
+
// Get/set children.
|
|
1153
|
+
get children() {
|
|
1154
|
+
return this._children;
|
|
1155
|
+
}
|
|
1156
|
+
set children(val) {
|
|
1157
|
+
this._children = val;
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
// Append.
|
|
1161
|
+
append(...children) {
|
|
1162
|
+
for (let i = 0; i < children.length; i++) {
|
|
1163
|
+
if (children[i] == null) {
|
|
1164
|
+
continue;
|
|
1165
|
+
} else if (Array.isArray(children[i])) {
|
|
1166
|
+
this.append(...children[i]);
|
|
1167
|
+
} else if (typeof children[i] === "string") {
|
|
1168
|
+
this._children.append(PDF.Text(children[i]));
|
|
1169
|
+
} else if (typeof children[i] !== "object") {
|
|
1170
|
+
this._children.append(PDF.Text(children[i].toString()));
|
|
1171
|
+
} else {
|
|
1172
|
+
this._children.append(children[i]);
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
return this;
|
|
1176
|
+
}
|
|
1177
|
+
|
|
1178
|
+
// Insert before.
|
|
1179
|
+
insert_before(relative, child) {
|
|
1180
|
+
const children = [];
|
|
1181
|
+
this._children.iterate((x) => {
|
|
1182
|
+
if (x === relative) {
|
|
1183
|
+
if (Array.isArray(child)) {
|
|
1184
|
+
children.append(...child);
|
|
1185
|
+
} else {
|
|
1186
|
+
children.append(child);
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
children.append(x);
|
|
1190
|
+
});
|
|
1191
|
+
this._children = children;
|
|
1192
|
+
return this;
|
|
1193
|
+
}
|
|
1194
|
+
|
|
1195
|
+
// Insert after.
|
|
1196
|
+
insert_after(relative, child) {
|
|
1197
|
+
const children = [];
|
|
1198
|
+
this._children.iterate((x) => {
|
|
1199
|
+
children.append(x);
|
|
1200
|
+
if (x === relative) {
|
|
1201
|
+
if (Array.isArray(child)) {
|
|
1202
|
+
children.append(...child);
|
|
1203
|
+
} else {
|
|
1204
|
+
children.append(child);
|
|
1205
|
+
}
|
|
1206
|
+
}
|
|
1207
|
+
});
|
|
1208
|
+
this._children = children;
|
|
1209
|
+
return this;
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1212
|
+
// Remove child.
|
|
1213
|
+
remove_child(child) {
|
|
1214
|
+
this._children = this._children.drop(child);
|
|
1215
|
+
return this;
|
|
1216
|
+
}
|
|
1217
|
+
|
|
1218
|
+
// Remove children.
|
|
1219
|
+
remove_children() {
|
|
1220
|
+
this._children = [];
|
|
1221
|
+
return this;
|
|
1222
|
+
}
|
|
1223
|
+
|
|
1224
|
+
// id.
|
|
1225
|
+
id(val) {
|
|
1226
|
+
if (val === undefined) { return this._id; }
|
|
1227
|
+
this._id = val;
|
|
1228
|
+
return this;
|
|
1229
|
+
}
|
|
1230
|
+
|
|
1231
|
+
// Href.
|
|
1232
|
+
href(val) {
|
|
1233
|
+
if (val === undefined) { return this._href; }
|
|
1234
|
+
this._href = val;
|
|
1235
|
+
return this;
|
|
1236
|
+
}
|
|
1237
|
+
|
|
1238
|
+
// Force same page for HStacks.
|
|
1239
|
+
force_same_page(val) {
|
|
1240
|
+
if (val === undefined) { return this._force_same_page; }
|
|
1241
|
+
this._force_same_page = val;
|
|
1242
|
+
return this;
|
|
1243
|
+
}
|
|
1244
|
+
|
|
1245
|
+
// Set start page.
|
|
1246
|
+
page(val) {
|
|
1247
|
+
if (val === undefined) { return this._page; }
|
|
1248
|
+
this._page = val;
|
|
1249
|
+
return this;
|
|
1250
|
+
}
|
|
1251
|
+
|
|
1252
|
+
// Margin, 1, 2 or 4 args.
|
|
1253
|
+
margin(...values) {
|
|
1254
|
+
if (values.length === 0) {
|
|
1255
|
+
return this._margin;
|
|
1256
|
+
} else {
|
|
1257
|
+
if (values.length === 1) {
|
|
1258
|
+
this._margin = [values[0], values[0], values[0], values[0]];
|
|
1259
|
+
} else if (values.length === 2) {
|
|
1260
|
+
this._margin = [values[0], values[1], values[0], values[1]];
|
|
1261
|
+
} else if (values.length === 4) {
|
|
1262
|
+
this._margin = [values[0], values[1], values[2], values[3]];
|
|
1263
|
+
} else {
|
|
1264
|
+
console.error("Invalid number of arguments for function \"margin()\".");
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
return this;
|
|
1268
|
+
}
|
|
1269
|
+
margin_top(val) {
|
|
1270
|
+
if (val === undefined) { return this._margin[0]; }
|
|
1271
|
+
this._margin[0] = val;
|
|
1272
|
+
return this;
|
|
1273
|
+
}
|
|
1274
|
+
margin_right(val) {
|
|
1275
|
+
if (val === undefined) { return this._margin[1]; }
|
|
1276
|
+
this._margin[1] = val;
|
|
1277
|
+
return this;
|
|
1278
|
+
}
|
|
1279
|
+
margin_bottom(val) {
|
|
1280
|
+
if (val === undefined) { return this._margin[2]; }
|
|
1281
|
+
this._margin[2] = val;
|
|
1282
|
+
return this;
|
|
1283
|
+
}
|
|
1284
|
+
margin_left(val) {
|
|
1285
|
+
if (val === undefined) { return this._margin[3]; }
|
|
1286
|
+
this._margin[3] = val;
|
|
1287
|
+
return this;
|
|
1288
|
+
}
|
|
1289
|
+
|
|
1290
|
+
// Padding, 1, 2 or 4 args.
|
|
1291
|
+
padding(...values) {
|
|
1292
|
+
if (values.length === 0) {
|
|
1293
|
+
return this._padding;
|
|
1294
|
+
} else {
|
|
1295
|
+
if (values.length === 1) {
|
|
1296
|
+
this._padding = [values[0], values[0], values[0], values[0]];
|
|
1297
|
+
} else if (values.length === 2) {
|
|
1298
|
+
this._padding = [values[0], values[1], values[0], values[1]];
|
|
1299
|
+
} else if (values.length === 4) {
|
|
1300
|
+
this._padding = [values[0], values[1], values[2], values[3]];
|
|
1301
|
+
} else {
|
|
1302
|
+
console.error("Invalid number of arguments for function \"padding()\".");
|
|
1303
|
+
}
|
|
1304
|
+
}
|
|
1305
|
+
return this;
|
|
1306
|
+
}
|
|
1307
|
+
padding_top(val) {
|
|
1308
|
+
if (val === undefined) { return this._padding[0]; }
|
|
1309
|
+
this._padding[0] = val;
|
|
1310
|
+
return this;
|
|
1311
|
+
}
|
|
1312
|
+
padding_right(val) {
|
|
1313
|
+
if (val === undefined) { return this._padding[1]; }
|
|
1314
|
+
this._padding[1] = val;
|
|
1315
|
+
return this;
|
|
1316
|
+
}
|
|
1317
|
+
padding_bottom(val) {
|
|
1318
|
+
if (val === undefined) { return this._padding[2]; }
|
|
1319
|
+
this._padding[2] = val;
|
|
1320
|
+
return this;
|
|
1321
|
+
}
|
|
1322
|
+
padding_left(val) {
|
|
1323
|
+
if (val === undefined) { return this._padding[3]; }
|
|
1324
|
+
this._padding[3] = val;
|
|
1325
|
+
return this;
|
|
1326
|
+
}
|
|
1327
|
+
|
|
1328
|
+
// Position, 1 or 4 args.
|
|
1329
|
+
position(...values) {
|
|
1330
|
+
if (values.length === 0) {
|
|
1331
|
+
return this._position;
|
|
1332
|
+
} else if (values.length === 1) {
|
|
1333
|
+
this._position = [values[0], values[0], values[0], values[0]];
|
|
1334
|
+
} else if (values.length === 4) {
|
|
1335
|
+
if (values[0] != null) {
|
|
1336
|
+
this._position[0] = values[0];
|
|
1337
|
+
}
|
|
1338
|
+
if (values[1] != null) {
|
|
1339
|
+
this._position[1] = values[1];
|
|
1340
|
+
}
|
|
1341
|
+
if (values[2] != null) {
|
|
1342
|
+
this._position[2] = values[2];
|
|
1343
|
+
}
|
|
1344
|
+
if (values[3] != null) {
|
|
1345
|
+
this._position[3] = values[3];
|
|
1346
|
+
}
|
|
1347
|
+
} else {
|
|
1348
|
+
console.error("Invalid number of arguments for function \"position()\".");
|
|
1349
|
+
}
|
|
1350
|
+
return this;
|
|
1351
|
+
}
|
|
1352
|
+
top(val) {
|
|
1353
|
+
if (val === undefined) { return this._position[0]; }
|
|
1354
|
+
this._position[0] = val;
|
|
1355
|
+
return this;
|
|
1356
|
+
}
|
|
1357
|
+
right(val) {
|
|
1358
|
+
if (val === undefined) { return this._position[1]; }
|
|
1359
|
+
this._position[1] = val;
|
|
1360
|
+
return this;
|
|
1361
|
+
}
|
|
1362
|
+
bottom(val) {
|
|
1363
|
+
if (val === undefined) { return this._position[2]; }
|
|
1364
|
+
this._position[2] = val;
|
|
1365
|
+
return this;
|
|
1366
|
+
}
|
|
1367
|
+
left(val) {
|
|
1368
|
+
if (val === undefined) { return this._position[3]; }
|
|
1369
|
+
this._position[3] = val;
|
|
1370
|
+
return this;
|
|
1371
|
+
}
|
|
1372
|
+
|
|
1373
|
+
// Align.
|
|
1374
|
+
align(val) {
|
|
1375
|
+
if (val === undefined) { return this._options.align; }
|
|
1376
|
+
this._options.align = val;
|
|
1377
|
+
return this;
|
|
1378
|
+
}
|
|
1379
|
+
leading() {
|
|
1380
|
+
return this.align("left");
|
|
1381
|
+
}
|
|
1382
|
+
center() {
|
|
1383
|
+
return this.align("center");
|
|
1384
|
+
}
|
|
1385
|
+
trailing() {
|
|
1386
|
+
return this.align("right");
|
|
1387
|
+
}
|
|
1388
|
+
justify() {
|
|
1389
|
+
return this.align("justify");
|
|
1390
|
+
}
|
|
1391
|
+
|
|
1392
|
+
// Width.
|
|
1393
|
+
width(val) {
|
|
1394
|
+
if (val == undefined) { return this._width; }
|
|
1395
|
+
this._width = val;
|
|
1396
|
+
return this;
|
|
1397
|
+
}
|
|
1398
|
+
|
|
1399
|
+
// Height.
|
|
1400
|
+
height(val) {
|
|
1401
|
+
if (val == undefined) { return this._height; }
|
|
1402
|
+
if (typeof val === "string" && val.last() === "%") {
|
|
1403
|
+
throw Error("Function \"height()\" does not accept relative percentages.");
|
|
1404
|
+
}
|
|
1405
|
+
this._height = val;
|
|
1406
|
+
return this;
|
|
1407
|
+
}
|
|
1408
|
+
|
|
1409
|
+
// Stretch.
|
|
1410
|
+
stretch(val) {
|
|
1411
|
+
if (val == undefined) { return this._stretch; }
|
|
1412
|
+
this._stretch = val;
|
|
1413
|
+
return this;
|
|
1414
|
+
}
|
|
1415
|
+
|
|
1416
|
+
// Font family.
|
|
1417
|
+
font_family(val) {
|
|
1418
|
+
if (val === undefined) { return this._font; }
|
|
1419
|
+
this._font = val;
|
|
1420
|
+
return this;
|
|
1421
|
+
}
|
|
1422
|
+
|
|
1423
|
+
// Font size.
|
|
1424
|
+
font_size(val) {
|
|
1425
|
+
if (val === undefined) { return this._calls.setFontSize; }
|
|
1426
|
+
this._calls.setFontSize = val;
|
|
1427
|
+
return this;
|
|
1428
|
+
}
|
|
1429
|
+
|
|
1430
|
+
// Font weight, the suffix for the font so: Helvetica-"Bold", can be lowercase.
|
|
1431
|
+
// Suffix might depend per font.
|
|
1432
|
+
font_weight(val) {
|
|
1433
|
+
if (val === undefined) { return this._font_weight; }
|
|
1434
|
+
this._font_weight = val;
|
|
1435
|
+
return this;
|
|
1436
|
+
}
|
|
1437
|
+
|
|
1438
|
+
// Color.
|
|
1439
|
+
color(val) {
|
|
1440
|
+
if (val === undefined) { return this._calls.setTextColor; }
|
|
1441
|
+
this._calls.setTextColor = val;
|
|
1442
|
+
return this;
|
|
1443
|
+
}
|
|
1444
|
+
|
|
1445
|
+
// Background.
|
|
1446
|
+
background(val) {
|
|
1447
|
+
if (val === undefined) { return this._background; }
|
|
1448
|
+
this._background = val;
|
|
1449
|
+
return this;
|
|
1450
|
+
}
|
|
1451
|
+
|
|
1452
|
+
// Border radius.
|
|
1453
|
+
border_radius(val) {
|
|
1454
|
+
if (val === undefined) { return this._border_radius; }
|
|
1455
|
+
this._border_radius = val;
|
|
1456
|
+
return this;
|
|
1457
|
+
}
|
|
1458
|
+
|
|
1459
|
+
// Border color.
|
|
1460
|
+
border_color(val) {
|
|
1461
|
+
if (val === undefined) { return this._border_color; }
|
|
1462
|
+
this._border_color = val;
|
|
1463
|
+
return this;
|
|
1464
|
+
}
|
|
1465
|
+
|
|
1466
|
+
// Border width.
|
|
1467
|
+
border_width(val) {
|
|
1468
|
+
if (val === undefined) { return this._border_width; }
|
|
1469
|
+
this._border_width = val;
|
|
1470
|
+
return this;
|
|
1471
|
+
}
|
|
1472
|
+
|
|
1473
|
+
// Align (for images mainly).
|
|
1474
|
+
align_vertical(val) {
|
|
1475
|
+
if (val === undefined) { return this._valign; }
|
|
1476
|
+
this._valign = val;
|
|
1477
|
+
return this;
|
|
1478
|
+
}
|
|
1479
|
+
leading_vertical() {
|
|
1480
|
+
return this.align_vertical("leading");
|
|
1481
|
+
}
|
|
1482
|
+
center_vertical() {
|
|
1483
|
+
return this.align_vertical("center");
|
|
1484
|
+
}
|
|
1485
|
+
trailing_vertical() {
|
|
1486
|
+
return this.align_vertical("trailing");
|
|
1487
|
+
}
|
|
1488
|
+
|
|
1489
|
+
/*
|
|
1490
|
+
|
|
1491
|
+
// Fit image (for images mainly).
|
|
1492
|
+
fit(width, height) {
|
|
1493
|
+
if (width === undefined) { return this._options.fit; }
|
|
1494
|
+
this._options.fit = [width, height];
|
|
1495
|
+
return this;
|
|
1496
|
+
}
|
|
1497
|
+
|
|
1498
|
+
// Ellipsis overflow.
|
|
1499
|
+
ellipsis_overflow(value) {
|
|
1500
|
+
if (value === undefined) { return this._options.ellipsis; }
|
|
1501
|
+
this._options.ellipsis = value;
|
|
1502
|
+
return this;
|
|
1503
|
+
}
|
|
1504
|
+
|
|
1505
|
+
// Line height.
|
|
1506
|
+
line_height(val) {
|
|
1507
|
+
if (val === undefined) { return this._options.lineGap; }
|
|
1508
|
+
this._options.lineGap = val;
|
|
1509
|
+
return this;
|
|
1510
|
+
}
|
|
1511
|
+
|
|
1512
|
+
// Underine (boolean).
|
|
1513
|
+
underline(val) {
|
|
1514
|
+
if (val === undefined) { return this._options.underline; }
|
|
1515
|
+
this._options.underline = val;
|
|
1516
|
+
return this;
|
|
1517
|
+
}
|
|
1518
|
+
|
|
1519
|
+
// strike (boolean).
|
|
1520
|
+
strike(val) {
|
|
1521
|
+
if (val === undefined) { return this._options.strike; }
|
|
1522
|
+
this._options.strike = val;
|
|
1523
|
+
return this;
|
|
1524
|
+
}
|
|
1525
|
+
|
|
1526
|
+
*/
|
|
1527
|
+
|
|
1528
|
+
// Wrap.
|
|
1529
|
+
// wrap(val) {
|
|
1530
|
+
// if (val === undefined) { return this._wrap; }
|
|
1531
|
+
// this._wrap = val;
|
|
1532
|
+
// return this;
|
|
1533
|
+
// }
|
|
1534
|
+
}
|
|
1535
|
+
return E;
|
|
1536
|
+
}
|
|
1537
|
+
|
|
1538
|
+
// ---------------------------------------------------------
|
|
1539
|
+
// PDF element.
|
|
1540
|
+
|
|
1541
|
+
class PDFElement extends CreateVElementClass({
|
|
1542
|
+
type: "PDF",
|
|
1543
|
+
is_stack: true,
|
|
1544
|
+
}) {
|
|
1545
|
+
|
|
1546
|
+
// Constructor.
|
|
1547
|
+
constructor(...children) {
|
|
1548
|
+
|
|
1549
|
+
// Initialize base class.
|
|
1550
|
+
super(...children);
|
|
1551
|
+
|
|
1552
|
+
// Attributes.
|
|
1553
|
+
this._margin = [50, 50, 50, 50]
|
|
1554
|
+
this._is_built = false;
|
|
1555
|
+
this._fonts = [];
|
|
1556
|
+
this.add_font("Menlo", "normal", `${__dirname}/fonts/Menlo-Regular.ttf`);
|
|
1557
|
+
this.add_font("Menlo", "bold", `${__dirname}/fonts/Menlo-Bold.ttf`);
|
|
1558
|
+
}
|
|
1559
|
+
|
|
1560
|
+
// Create a document.
|
|
1561
|
+
_create_doc() {
|
|
1562
|
+
this._doc = new jsPDF("p", "pt", "a4"); // PDF.use_pixels ? "px" : "pt"
|
|
1563
|
+
this._doc._volt_margin_top = this._margin[0];
|
|
1564
|
+
this._doc._volt_margin_right = this._margin[1];
|
|
1565
|
+
this._doc._volt_margin_bottom = this._margin[2];
|
|
1566
|
+
this._doc._volt_margin_left = this._margin[3];
|
|
1567
|
+
this._doc._volt_page_width = this._doc.getPageWidth();
|
|
1568
|
+
this._doc._volt_page_height = this._doc.getPageHeight();
|
|
1569
|
+
this._doc._volt_ids = {}; // {$id: $page_nr}.
|
|
1570
|
+
this._doc._volt_hrefs = [];
|
|
1571
|
+
this._fonts.iterate((item) => {
|
|
1572
|
+
this._doc.addFileToVFS(item.file_name, item.base64);
|
|
1573
|
+
this._doc.addFont(item.file_name, item.name, item.style);
|
|
1574
|
+
})
|
|
1575
|
+
return this._doc;
|
|
1576
|
+
}
|
|
1577
|
+
|
|
1578
|
+
// Build.
|
|
1579
|
+
build() {
|
|
1580
|
+
this._build(); // refresh in case any edits were made after `iterate_pages` or `switch_page`.
|
|
1581
|
+
this._is_built = true;
|
|
1582
|
+
return this;
|
|
1583
|
+
}
|
|
1584
|
+
|
|
1585
|
+
// Get max page.
|
|
1586
|
+
max_page() {
|
|
1587
|
+
if (this._computed === undefined) {
|
|
1588
|
+
this._compute();
|
|
1589
|
+
}
|
|
1590
|
+
return this._computed.end_page;
|
|
1591
|
+
}
|
|
1592
|
+
|
|
1593
|
+
// Iterate pages.
|
|
1594
|
+
iterate_pages(callback) {
|
|
1595
|
+
this._compute(undefined, undefined, undefined, undefined, true);
|
|
1596
|
+
for (let i = 1; i <= this._computed.end_page; i++) {
|
|
1597
|
+
callback(i)
|
|
1598
|
+
}
|
|
1599
|
+
return this;
|
|
1600
|
+
}
|
|
1601
|
+
|
|
1602
|
+
// Number pages.
|
|
1603
|
+
number_pages({
|
|
1604
|
+
align = "right", // left, center, right
|
|
1605
|
+
margin = 12.5,
|
|
1606
|
+
font_size = 6,
|
|
1607
|
+
color = "black",
|
|
1608
|
+
}) {
|
|
1609
|
+
this.iterate_pages((page) => {
|
|
1610
|
+
const text = PDF.Text(`Page ${page}`)
|
|
1611
|
+
.color(color)
|
|
1612
|
+
.font_size(font_size)
|
|
1613
|
+
.position(
|
|
1614
|
+
null,
|
|
1615
|
+
align === "right" ? margin : null,
|
|
1616
|
+
margin,
|
|
1617
|
+
align === "left" ? margin : null,
|
|
1618
|
+
)
|
|
1619
|
+
.page(page)
|
|
1620
|
+
// if (align === "center") {
|
|
1621
|
+
// text.width("100%").center()
|
|
1622
|
+
// }
|
|
1623
|
+
this.append(text)
|
|
1624
|
+
})
|
|
1625
|
+
return this;
|
|
1626
|
+
}
|
|
1627
|
+
|
|
1628
|
+
// Add font.
|
|
1629
|
+
add_font(name = "Menlo", style = "normal", path = "Menlo-Regular.ttf") {
|
|
1630
|
+
this._fonts.append({
|
|
1631
|
+
name,
|
|
1632
|
+
style,
|
|
1633
|
+
file_name: new vlib.Path(path).name(),
|
|
1634
|
+
base64: Buffer.from(libfs.readFileSync(path)).toString("base64"),
|
|
1635
|
+
})
|
|
1636
|
+
return this;
|
|
1637
|
+
}
|
|
1638
|
+
|
|
1639
|
+
// Save.
|
|
1640
|
+
save(path) {
|
|
1641
|
+
if (!this._is_built) {
|
|
1642
|
+
this.build();
|
|
1643
|
+
}
|
|
1644
|
+
libfs.writeFileSync(path, this._doc.output(), "binary");
|
|
1645
|
+
}
|
|
1646
|
+
|
|
1647
|
+
// Get as bytes.
|
|
1648
|
+
async bytes() {
|
|
1649
|
+
if (!this._is_built) {
|
|
1650
|
+
this.build();
|
|
1651
|
+
}
|
|
1652
|
+
const stream = this._doc.pipe(blobstream());
|
|
1653
|
+
return new Promise((resolve, reject) => {
|
|
1654
|
+
stream.on('finish', () => {
|
|
1655
|
+
const bytes = stream.toBuffer();
|
|
1656
|
+
resolve(bytes);
|
|
1657
|
+
});
|
|
1658
|
+
stream.on('error', (error) => {
|
|
1659
|
+
reject(error);
|
|
1660
|
+
});
|
|
1661
|
+
});
|
|
1662
|
+
}
|
|
1663
|
+
|
|
1664
|
+
// Get as blob stream.
|
|
1665
|
+
stream() {
|
|
1666
|
+
if (!this._is_built) {
|
|
1667
|
+
this.build();
|
|
1668
|
+
}
|
|
1669
|
+
return this._doc.pipe(blobstream());
|
|
1670
|
+
}
|
|
1671
|
+
};
|
|
1672
|
+
PDF.PDFElement = PDFElement;
|
|
1673
|
+
PDF.PDF = function PDF(...args) { return new PDFElement(...args); };
|
|
1674
|
+
|
|
1675
|
+
// ---------------------------------------------------------
|
|
1676
|
+
// Page element.
|
|
1677
|
+
|
|
1678
|
+
PDF.PageElement = class PageElement extends CreateVElementClass({
|
|
1679
|
+
type: "Page",
|
|
1680
|
+
is_stack: true,
|
|
1681
|
+
}) {
|
|
1682
|
+
|
|
1683
|
+
// Constructor.
|
|
1684
|
+
constructor(...children) {
|
|
1685
|
+
|
|
1686
|
+
// Initialize base class.
|
|
1687
|
+
super(...children);
|
|
1688
|
+
}
|
|
1689
|
+
};
|
|
1690
|
+
PDF.Page = function Page(...args) { return new PDF.PageElement(...args); };
|
|
1691
|
+
|
|
1692
|
+
|
|
1693
|
+
// ---------------------------------------------------------
|
|
1694
|
+
// VStack element.
|
|
1695
|
+
|
|
1696
|
+
PDF.VStackElement = class VStackElement extends CreateVElementClass({
|
|
1697
|
+
type: "VStack",
|
|
1698
|
+
is_stack: true,
|
|
1699
|
+
}) {
|
|
1700
|
+
|
|
1701
|
+
// Constructor.
|
|
1702
|
+
constructor(...children) {
|
|
1703
|
+
|
|
1704
|
+
// Initialize base class.
|
|
1705
|
+
super(...children);
|
|
1706
|
+
}
|
|
1707
|
+
};
|
|
1708
|
+
PDF.VStack = function VStack(...args) { return new PDF.VStackElement(...args); };
|
|
1709
|
+
|
|
1710
|
+
// ---------------------------------------------------------
|
|
1711
|
+
// HStack element.
|
|
1712
|
+
|
|
1713
|
+
PDF.HStackElement = class HStackElement extends CreateVElementClass({
|
|
1714
|
+
type: "HStack",
|
|
1715
|
+
is_stack: true,
|
|
1716
|
+
is_hstack: true,
|
|
1717
|
+
}) {
|
|
1718
|
+
|
|
1719
|
+
// Constructor.
|
|
1720
|
+
constructor(...children) {
|
|
1721
|
+
|
|
1722
|
+
// Initialize base class.
|
|
1723
|
+
super(...children);
|
|
1724
|
+
}
|
|
1725
|
+
};
|
|
1726
|
+
PDF.HStack = function HStack(...args) { return new PDF.HStackElement(...args); };
|
|
1727
|
+
|
|
1728
|
+
// ---------------------------------------------------------
|
|
1729
|
+
// Text element.
|
|
1730
|
+
|
|
1731
|
+
PDF.TextElement = class TextElement extends CreateVElementClass({
|
|
1732
|
+
type: "Text",
|
|
1733
|
+
is_text: true,
|
|
1734
|
+
}) {
|
|
1735
|
+
|
|
1736
|
+
// Constructor.
|
|
1737
|
+
constructor(text = "") {
|
|
1738
|
+
|
|
1739
|
+
// Initialize base class.
|
|
1740
|
+
super();
|
|
1741
|
+
|
|
1742
|
+
// Set text.
|
|
1743
|
+
this._text = text;
|
|
1744
|
+
}
|
|
1745
|
+
};
|
|
1746
|
+
PDF.Text = function Text(...args) { return new PDF.TextElement(...args); };
|
|
1747
|
+
|
|
1748
|
+
// ---------------------------------------------------------
|
|
1749
|
+
// Image element.
|
|
1750
|
+
|
|
1751
|
+
PDF.ImageElement = class ImageElement extends CreateVElementClass({
|
|
1752
|
+
type: "Image",
|
|
1753
|
+
is_img: true,
|
|
1754
|
+
}) {
|
|
1755
|
+
|
|
1756
|
+
// Constructor.
|
|
1757
|
+
constructor(img) {
|
|
1758
|
+
|
|
1759
|
+
// Initialize base class.
|
|
1760
|
+
super();
|
|
1761
|
+
|
|
1762
|
+
// Set text.
|
|
1763
|
+
this._img = img;
|
|
1764
|
+
}
|
|
1765
|
+
};
|
|
1766
|
+
PDF.Image = function Image(...args) { return new PDF.ImageElement(...args); };
|
|
1767
|
+
|
|
1768
|
+
// ---------------------------------------------------------
|
|
1769
|
+
// Code block.
|
|
1770
|
+
|
|
1771
|
+
PDF.CodeBlockElement = class CodeBlockElement extends CreateVElementClass({
|
|
1772
|
+
type: "CodeBlock",
|
|
1773
|
+
is_stack: true,
|
|
1774
|
+
}) {
|
|
1775
|
+
|
|
1776
|
+
static menlo_initialized = false;
|
|
1777
|
+
|
|
1778
|
+
// Constructor.
|
|
1779
|
+
constructor(language, code) {
|
|
1780
|
+
|
|
1781
|
+
// Initialize base class.
|
|
1782
|
+
super();
|
|
1783
|
+
|
|
1784
|
+
this._language = language;
|
|
1785
|
+
this._code = code;
|
|
1786
|
+
this._initialized = false;
|
|
1787
|
+
this._calls.setFontSize = 6;
|
|
1788
|
+
this._padding = [12.5, 5, 12.5, 5];
|
|
1789
|
+
this._background = "#00000005";
|
|
1790
|
+
this._border_radius = 5;
|
|
1791
|
+
this._border_color = "#00000020";
|
|
1792
|
+
this._border_width = 0.5;
|
|
1793
|
+
this._font = "Menlo";
|
|
1794
|
+
|
|
1795
|
+
}
|
|
1796
|
+
|
|
1797
|
+
copy() {
|
|
1798
|
+
const copy = super.copy();
|
|
1799
|
+
copy._language = this.language;
|
|
1800
|
+
copy._code = this.code;
|
|
1801
|
+
copy._initialized = this._initialized;
|
|
1802
|
+
return copy;
|
|
1803
|
+
}
|
|
1804
|
+
|
|
1805
|
+
// Initialize.
|
|
1806
|
+
_initialize() {
|
|
1807
|
+
|
|
1808
|
+
// Already initialized.
|
|
1809
|
+
if (this._initialized) {
|
|
1810
|
+
return this;
|
|
1811
|
+
}
|
|
1812
|
+
|
|
1813
|
+
// Tokenize.
|
|
1814
|
+
const tokenizer = vhighlight.init_tokenizer(this._language);
|
|
1815
|
+
if (tokenizer == null) {
|
|
1816
|
+
throw Error(`Language "${language}" is not a supported code language for "PDF.CodeBlock".`);
|
|
1817
|
+
}
|
|
1818
|
+
tokenizer.code = this._code;
|
|
1819
|
+
const tokens = tokenizer.tokenize();
|
|
1820
|
+
|
|
1821
|
+
// Create children.
|
|
1822
|
+
this._children = [];
|
|
1823
|
+
this._children.append(CodeBlockElement.build_tokens(tokens));
|
|
1824
|
+
|
|
1825
|
+
// Initialized.
|
|
1826
|
+
this._initialized = true;
|
|
1827
|
+
return this;
|
|
1828
|
+
}
|
|
1829
|
+
|
|
1830
|
+
// Build tokens.
|
|
1831
|
+
static build_tokens(tokens) {
|
|
1832
|
+
|
|
1833
|
+
// Create token classes.
|
|
1834
|
+
const token_classes = {
|
|
1835
|
+
comment: (text) => {
|
|
1836
|
+
return PDF.Text(text)
|
|
1837
|
+
.color("#818C97")
|
|
1838
|
+
},
|
|
1839
|
+
comment_keyword: (text) => {
|
|
1840
|
+
return PDF.Text(text)
|
|
1841
|
+
.color("#818C97")
|
|
1842
|
+
.font_weight("bold")
|
|
1843
|
+
},
|
|
1844
|
+
comment_codeblock: (text) => {
|
|
1845
|
+
return PDF.Text(text)
|
|
1846
|
+
.color("#818C97")
|
|
1847
|
+
.font_weight("italic")
|
|
1848
|
+
.background("#FFFFFF10")
|
|
1849
|
+
.border_radius(5)
|
|
1850
|
+
},
|
|
1851
|
+
url: (text) => {
|
|
1852
|
+
return PDF.Text(text)
|
|
1853
|
+
.color("#818C97")
|
|
1854
|
+
},
|
|
1855
|
+
string: (text) => {
|
|
1856
|
+
return PDF.Text(text)
|
|
1857
|
+
.color("#D6C986")
|
|
1858
|
+
},
|
|
1859
|
+
numeric: (text) => {
|
|
1860
|
+
return PDF.Text(text)
|
|
1861
|
+
.color("#D6C986")
|
|
1862
|
+
},
|
|
1863
|
+
keyword: (text) => {
|
|
1864
|
+
return PDF.Text(text)
|
|
1865
|
+
.color("#EE8378")
|
|
1866
|
+
.font_weight("bold")
|
|
1867
|
+
},
|
|
1868
|
+
operator: (text) => {
|
|
1869
|
+
return PDF.Text(text)
|
|
1870
|
+
.color("#EE8378")
|
|
1871
|
+
.font_weight("bold")
|
|
1872
|
+
},
|
|
1873
|
+
preprocessor: (text) => {
|
|
1874
|
+
return PDF.Text(text)
|
|
1875
|
+
.color("#EE8378")
|
|
1876
|
+
},
|
|
1877
|
+
type_def: (text) => {
|
|
1878
|
+
return PDF.Text(text)
|
|
1879
|
+
.color("#C78BF0")
|
|
1880
|
+
},
|
|
1881
|
+
type: (text) => {
|
|
1882
|
+
return PDF.Text(text)
|
|
1883
|
+
.color("#5795F3")
|
|
1884
|
+
},
|
|
1885
|
+
parameter: (text) => {
|
|
1886
|
+
return PDF.Text(text)
|
|
1887
|
+
.color("#F9AE58")
|
|
1888
|
+
},
|
|
1889
|
+
}
|
|
1890
|
+
|
|
1891
|
+
// Build.
|
|
1892
|
+
if (tokens.length === 0) { return null; }
|
|
1893
|
+
if (Array.isArray(tokens[0])) {
|
|
1894
|
+
tokens.iterate((line_tokens) => {
|
|
1895
|
+
const hstack = PDF.HStack();
|
|
1896
|
+
line_tokens.iterate((token) => {
|
|
1897
|
+
if (token.is_line_break) {
|
|
1898
|
+
return null;
|
|
1899
|
+
}
|
|
1900
|
+
const token_class = token_classes[token.token];
|
|
1901
|
+
if (token_class == null) {
|
|
1902
|
+
hstack.append(PDF.Text(token.data))
|
|
1903
|
+
} else {
|
|
1904
|
+
hstack.append(token_class(token.data))
|
|
1905
|
+
}
|
|
1906
|
+
})
|
|
1907
|
+
children.append(hstack);
|
|
1908
|
+
})
|
|
1909
|
+
return children;
|
|
1910
|
+
} else {
|
|
1911
|
+
const hstack = PDF.HStack();
|
|
1912
|
+
tokens.iterate((token) => {
|
|
1913
|
+
if (token.is_line_break) {
|
|
1914
|
+
return null;
|
|
1915
|
+
}
|
|
1916
|
+
const token_class = token_classes[token.token];
|
|
1917
|
+
if (token_class == null) {
|
|
1918
|
+
hstack.append(PDF.Text(token.data))
|
|
1919
|
+
} else {
|
|
1920
|
+
hstack.append(token_class(token.data))
|
|
1921
|
+
}
|
|
1922
|
+
})
|
|
1923
|
+
return hstack;
|
|
1924
|
+
}
|
|
1925
|
+
}
|
|
1926
|
+
};
|
|
1927
|
+
PDF.CodeBlock = function CodeBlock(...args) { return new PDF.CodeBlockElement(...args); };
|
|
1928
|
+
|
|
1929
|
+
// ---------------------------------------------------------
|
|
1930
|
+
// Export.
|
|
1931
|
+
|
|
1932
|
+
module.exports = PDF;
|