Skip to content

Commit

Permalink
Start action conversion (#160)
Browse files Browse the repository at this point in the history
* start action conversion

* adjust formatting

* combine actions

* fix analysis issue

* remove skynet.yaml

* move CODEOWNERS, include publish workflow

* include additional check
  • Loading branch information
jayudey-wf authored Nov 7, 2023
1 parent cca7597 commit f517f3f
Show file tree
Hide file tree
Showing 15 changed files with 200 additions and 87 deletions.
File renamed without changes.
39 changes: 39 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Dart CI

on:
push:
branches:
- 'master'
- 'test_consume_*'
pull_request:
branches:
- '**'

jobs:
static-analysis:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
sdk: [ 2.18.7, 2.19.6 ]
steps:
- uses: actions/checkout@v2
- uses: dart-lang/setup-dart@v1
with:
sdk: ${{ matrix.sdk }}

- id: install
name: Install dependencies
run: dart pub get

- name: Analyze project source
run: dart analyze
if: always() && steps.install.outcome == 'success'

- name: Verify formatting
run: dart format --output=none --set-exit-if-changed .
if: always() && steps.install.outcome == 'success'

- name: Check dependencies
run: dart run dependency_validator
if: always() && steps.install.outcome == 'success'
15 changes: 15 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Publish to pub.dev

on:
push:
tags:
# Releases
- '[0-9]+.[0-9]+.[0-9]+'
# Release Candidates
- '[0-9]+.[0-9]+.[0-9]+-rc[0-9]+'

jobs:
publish:
permissions:
id-token: write # Required for authentication using OIDC
uses: dart-lang/setup-dart/.github/workflows/publish.yml@v1
22 changes: 14 additions & 8 deletions lib/src/document_init_parameters.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ class DocumentInitParameters {
_jsInternal?['initialData'] = initialData;
}

Map<String, dynamic>? get httpHeaders => _jsInternal?['httpHeaders'] as Map<String, dynamic>?;
Map<String, dynamic>? get httpHeaders =>
_jsInternal?['httpHeaders'] as Map<String, dynamic>?;
set httpHeaders(Map<String, dynamic>? httpHeaders) {
_jsInternal?['httpHeaders'] = httpHeaders;
}
Expand All @@ -54,9 +55,12 @@ class DocumentInitParameters {
}

NativeImageDecoderSupport? get nativeImageDecoderSupport =>
_nativeImageDecoderSupportPdfjsToDart[_jsInternal?['nativeImageDecoderSupport']];
set nativeImageDecoderSupport(NativeImageDecoderSupport? nativeImageDecoderSupport) {
_jsInternal?['nativeImageDecoderSupport'] = _nativeImageDecoderSupportDartToPdfjs[nativeImageDecoderSupport];
_nativeImageDecoderSupportPdfjsToDart[
_jsInternal?['nativeImageDecoderSupport']];
set nativeImageDecoderSupport(
NativeImageDecoderSupport? nativeImageDecoderSupport) {
_jsInternal?['nativeImageDecoderSupport'] =
_nativeImageDecoderSupportDartToPdfjs[nativeImageDecoderSupport];
}

String? get password => _jsInternal?['password'] as String?;
Expand Down Expand Up @@ -109,9 +113,11 @@ class DocumentInitParameters {
NativeImageDecoderSupport.none,
];

static Map<String, NativeImageDecoderSupport> _nativeImageDecoderSupportPdfjsToDart =
Map.fromIterables(_pdfjsNativeImageDecoderSupport, _dartNativeImageDecoderSupport);
static Map<String, NativeImageDecoderSupport>
_nativeImageDecoderSupportPdfjsToDart = Map.fromIterables(
_pdfjsNativeImageDecoderSupport, _dartNativeImageDecoderSupport);

static Map<NativeImageDecoderSupport, String> _nativeImageDecoderSupportDartToPdfjs =
Map.fromIterables(_dartNativeImageDecoderSupport, _pdfjsNativeImageDecoderSupport);
static Map<NativeImageDecoderSupport, String>
_nativeImageDecoderSupportDartToPdfjs = Map.fromIterables(
_dartNativeImageDecoderSupport, _pdfjsNativeImageDecoderSupport);
}
42 changes: 30 additions & 12 deletions lib/src/interfaces.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ class AnnotationLayerBuilderOptions {
_pdfPage = pdfPage;
}

bool? get renderInteractiveForms => _jsInternal['renderInteractiveForms'] as bool?;
bool? get renderInteractiveForms =>
_jsInternal['renderInteractiveForms'] as bool?;
set renderInteractiveForms(bool? renderInteractiveForms) {
_jsInternal['renderInteractiveForms'] = renderInteractiveForms;
}
Expand All @@ -54,9 +55,12 @@ class AnnotationLayerBuilder {
JsObject? _jsInternal;

AnnotationLayerBuilder(AnnotationLayerBuilderOptions options) {
_jsInternal = JsObject(PDFJS.versionSafePdfJsViewerContext?['AnnotationLayerBuilder'] as JsFunction, [
options,
]);
_jsInternal = JsObject(
PDFJS.versionSafePdfJsViewerContext?['AnnotationLayerBuilder']
as JsFunction,
[
options,
]);
}

AnnotationLayerBuilder._withJsInternal(this._jsInternal);
Expand All @@ -71,11 +75,13 @@ abstract class IPDFAnnotationLayerFactory {

IPDFAnnotationLayerFactory() {
_jsInternal?['createAnnotationLayerBuilder'] =
(DivElement pageDiv, JsObject jsPdfPage, [bool? renderInteractiveForms, JsObject? jsL10n]) {
(DivElement pageDiv, JsObject jsPdfPage,
[bool? renderInteractiveForms, JsObject? jsL10n]) {
PDFPageProxy pdfPage = PDFPageProxy._withJsInternal(jsPdfPage);
IL10n l10n = _JsIL10n._withJsInternal(jsL10n);

AnnotationLayerBuilder annotationLayerBuilder = createAnnotationLayerBuilder(
AnnotationLayerBuilder annotationLayerBuilder =
createAnnotationLayerBuilder(
pageDiv,
pdfPage,
l10n: l10n,
Expand All @@ -102,15 +108,21 @@ class DefaultTextLayerFactory implements IPDFTextLayerFactory {
JsObject? _jsInternal;

DefaultTextLayerFactory() {
_jsInternal = JsObject(PDFJS.versionSafePdfJsViewerContext?['DefaultTextLayerFactory'] as JsFunction, []);
_jsInternal = JsObject(
PDFJS.versionSafePdfJsViewerContext?['DefaultTextLayerFactory']
as JsFunction,
[]);
}
}

class DefaultAnnotationLayerFactory implements IPDFAnnotationLayerFactory {
JsObject? _jsInternal;

DefaultAnnotationLayerFactory() {
_jsInternal = JsObject(PDFJS.versionSafePdfJsViewerContext?['DefaultAnnotationLayerFactory'] as JsFunction, []);
_jsInternal = JsObject(
PDFJS.versionSafePdfJsViewerContext?['DefaultAnnotationLayerFactory']
as JsFunction,
[]);
}

AnnotationLayerBuilder createAnnotationLayerBuilder(
Expand All @@ -120,8 +132,12 @@ class DefaultAnnotationLayerFactory implements IPDFAnnotationLayerFactory {
bool? renderInteractiveForms = false,
}) {
JsObject? jsAnnotationLayerBuilder = _jsInternal?.callMethod(
'createAnnotationLayerBuilder', [pageDiv, pdfPage._jsInternal, renderInteractiveForms, l10n?._jsInternal])
as JsObject?;
'createAnnotationLayerBuilder', [
pageDiv,
pdfPage._jsInternal,
renderInteractiveForms,
l10n?._jsInternal
]) as JsObject?;

return AnnotationLayerBuilder._withJsInternal(jsAnnotationLayerBuilder);
}
Expand Down Expand Up @@ -149,13 +165,15 @@ class _JsIL10n implements IL10n {
}

Future<String> get(String key, Map args, String fallback) {
JsObject promise = _jsInternal?.callMethod('get', [key, JsObject.jsify(args), fallback]) as JsObject;
JsObject promise = _jsInternal
?.callMethod('get', [key, JsObject.jsify(args), fallback]) as JsObject;

return _promiseToFuture<String>(promise);
}

Future<Null> translate(HtmlElement element) {
JsObject promise = _jsInternal?.callMethod('translate', [element]) as JsObject;
JsObject promise =
_jsInternal?.callMethod('translate', [element]) as JsObject;

return _promiseToFuture<Null>(promise);
}
Expand Down
3 changes: 2 additions & 1 deletion lib/src/page_viewport.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class PageViewport {
JsObject? _jsInternal;

PageViewport() {
_jsInternal = JsObject(PDFJS.versionSafePdfJsContext?['PageViewport'] as JsFunction);
_jsInternal =
JsObject(PDFJS.versionSafePdfJsContext?['PageViewport'] as JsFunction);
}

PageViewport._withJsInternal(this._jsInternal);
Expand Down
3 changes: 2 additions & 1 deletion lib/src/pdf_data_range_transport.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ abstract class PDFDataRangeTransport {
JsObject? _jsInternal;

PDFDataRangeTransport(int length, Uint8List initialData) {
_jsInternal = JsObject(PDFJS.versionSafePdfJsContext?['PDFDataRangeTransport'] as JsFunction, [
_jsInternal = JsObject(
PDFJS.versionSafePdfJsContext?['PDFDataRangeTransport'] as JsFunction, [
length,
initialData,
]);
Expand Down
15 changes: 10 additions & 5 deletions lib/src/pdf_document_loading_task.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ class PDFDocumentLoadingTask {
JsObject? _jsInternal;

PDFDocumentLoadingTask() {
_jsInternal = JsObject(PDFJS.versionSafePdfJsContext?['PDFDocumentLoadingTask'] as JsFunction);
_jsInternal = JsObject(
PDFJS.versionSafePdfJsContext?['PDFDocumentLoadingTask'] as JsFunction);
_initFuture();
}

Expand All @@ -28,8 +29,10 @@ class PDFDocumentLoadingTask {
}

void _initFuture() {
_future = _promiseToFuture<PDFDocumentProxy>(_jsInternal?['promise'] as JsObject,
transform: (value) => PDFDocumentProxy._withJsInternal(value as JsObject));
_future = _promiseToFuture<PDFDocumentProxy>(
_jsInternal?['promise'] as JsObject,
transform: (value) =>
PDFDocumentProxy._withJsInternal(value as JsObject));
}

bool? get destroyed => _jsInternal?['destroyed'] as bool?;
Expand All @@ -38,8 +41,10 @@ class PDFDocumentLoadingTask {

Future<PDFDocumentProxy>? get future => _future;

Future destroy() => _promiseToFuture(_jsInternal?.callMethod('destroy', []) as JsObject);
Future destroy() =>
_promiseToFuture(_jsInternal?.callMethod('destroy', []) as JsObject);

Future<S> then<S>(FutureOr<S> onValue(PDFDocumentProxy value), {Function? onError}) =>
Future<S> then<S>(FutureOr<S> onValue(PDFDocumentProxy value),
{Function? onError}) =>
_future!.then(onValue, onError: onError);
}
21 changes: 14 additions & 7 deletions lib/src/pdf_document_proxy.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ dynamic _dartifyDestination(dynamic jsDest) {
}

List<dynamic> _dartifyExplicitDestination(List<dynamic> jsDest) {
List<dynamic> dartDest = List<dynamic>.filled(jsDest.length, null, growable: false);
List<dynamic> dartDest =
List<dynamic>.filled(jsDest.length, null, growable: false);

// The first item is always a page ref; create a strongly-typed dart object
// for it
Expand Down Expand Up @@ -116,7 +117,8 @@ class OutlineItem {

Iterable<OutlineItem>? get items {
if (_items == null) {
List<OutlineItem>? convertedItems = _dartifyOutlineItemList(_jsInternal['items'] as List<JsObject>?);
List<OutlineItem>? convertedItems =
_dartifyOutlineItemList(_jsInternal['items'] as List<JsObject>?);

convertedItems ??= [];

Expand All @@ -135,7 +137,8 @@ class PDFDocumentProxy {
JsObject? _jsInternal;

PDFDocumentProxy() {
_jsInternal = JsObject(PDFJS.versionSafePdfJsContext?['PDFDocumentProxy'] as JsFunction);
_jsInternal = JsObject(
PDFJS.versionSafePdfJsContext?['PDFDocumentProxy'] as JsFunction);
}

PDFDocumentProxy._withJsInternal(this._jsInternal);
Expand All @@ -159,9 +162,11 @@ class PDFDocumentProxy {
}

Future<List<dynamic>> getDestination(String id) {
JsObject promise = _jsInternal?.callMethod('getDestination', [id]) as JsObject;
JsObject promise =
_jsInternal?.callMethod('getDestination', [id]) as JsObject;

return _promiseToFuture<List<dynamic>>(promise, transform: (value) => _dartifyExplicitDestination(value as List));
return _promiseToFuture<List<dynamic>>(promise,
transform: (value) => _dartifyExplicitDestination(value as List));
}

Future<List<String>> getJavaScript() {
Expand Down Expand Up @@ -190,14 +195,16 @@ class PDFDocumentProxy {
}

Future<PDFPageProxy> getPage(int pageNumber) {
JsObject promise = _jsInternal?.callMethod('getPage', [pageNumber]) as JsObject;
JsObject promise =
_jsInternal?.callMethod('getPage', [pageNumber]) as JsObject;

return _promiseToFuture<PDFPageProxy>(promise,
transform: (value) => PDFPageProxy._withJsInternal(value as JsObject));
}

Future<int> getPageIndex(PageReference ref) {
JsObject promise = _jsInternal?.callMethod('getPageIndex', [ref._jsInternal]) as JsObject;
JsObject promise =
_jsInternal?.callMethod('getPageIndex', [ref._jsInternal]) as JsObject;

return _promiseToFuture<int>(promise);
}
Expand Down
3 changes: 2 additions & 1 deletion lib/src/pdf_page_proxy.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class PDFPageProxy {
final pdfjsLib = PDFJS.versionSafePdfJsContext;
checkState(pdfjsLib != null, message: 'pdfjsLib was null in PDFPageProxy');
final pdfPageProxyJs = pdfjsLib?['PDFPageProxy'];
checkState(pdfPageProxyJs != null, message: 'pdfPageProxyJs was null in PDFPageProxy');
checkState(pdfPageProxyJs != null,
message: 'pdfPageProxyJs was null in PDFPageProxy');
_jsInternal = JsObject(pdfPageProxyJs as JsFunction);
}

Expand Down
18 changes: 12 additions & 6 deletions lib/src/pdf_page_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@ class PDFPageView {
case PDFPageViewRenderer.svg:
rendererString = 'svg';
break;
case null:
throw Exception('Un-expected error due to null renderer');
}

_jsInternal = JsObject(PDFJS.versionSafePdfJsViewerContext?['PDFPageView'] as JsFunction, [
_jsInternal = JsObject(
PDFJS.versionSafePdfJsViewerContext?['PDFPageView'] as JsFunction, [
JsObject.jsify({
'container': container,
'id': id,
Expand All @@ -47,7 +50,8 @@ class PDFPageView {
'renderer': rendererString,
'annotationLayerFactory': annotationLayerFactory?._jsInternal,
'textLayerFactory': textLayerFactory?._jsInternal,
'eventBus': JsObject(PDFJS.versionSafePdfJsViewerContext?['EventBus'] as JsFunction),
'eventBus': JsObject(
PDFJS.versionSafePdfJsViewerContext?['EventBus'] as JsFunction),
})
]);
}
Expand Down Expand Up @@ -80,10 +84,12 @@ class PDFPageView {

/// v2.11.338+
void _updateV2({num scale = 0, num rotation = 0}) {
_jsInternal.callMethod('update', [JsObject.jsify({
'scale': scale,
'rotation': rotation,
})]);
_jsInternal.callMethod('update', [
JsObject.jsify({
'scale': scale,
'rotation': rotation,
})
]);
}

bool _isUpdated({num scale = 0, num rotation = 0}) {
Expand Down
Loading

0 comments on commit f517f3f

Please sign in to comment.