From e9b84f50e961ee7c3abfb8192de8f4fc778df041 Mon Sep 17 00:00:00 2001 From: Felipe Artur Date: Mon, 11 Feb 2019 15:48:37 -0200 Subject: Migrate issuable states to integer patch 1 Patch 1 that migrates issues/merge requests states from integer to string. On this commit we are only adding the state_id column and syncing it with a backgroud migration. On Patch 2 the code to use the new integer column will be deployed and the old column will be removed. --- app/models/concerns/issuable.rb | 1 + app/models/concerns/issuable_states.rb | 37 +++++++++ app/models/merge_request.rb | 2 + .../20190211131150_add_state_id_to_issuables.rb | 37 +++++++++ db/schema.rb | 4 +- .../sync_issuables_state_id.rb | 29 +++++++ lib/gitlab/database/migration_helpers.rb | 2 +- spec/migrations/add_state_id_to_issuables_spec.rb | 89 ++++++++++++++++++++++ 8 files changed, 199 insertions(+), 2 deletions(-) create mode 100644 app/models/concerns/issuable_states.rb create mode 100644 db/migrate/20190211131150_add_state_id_to_issuables.rb create mode 100644 lib/gitlab/background_migration/sync_issuables_state_id.rb create mode 100644 spec/migrations/add_state_id_to_issuables_spec.rb diff --git a/app/models/concerns/issuable.rb b/app/models/concerns/issuable.rb index 0a77fbeba08..7bf553a0221 100644 --- a/app/models/concerns/issuable.rb +++ b/app/models/concerns/issuable.rb @@ -23,6 +23,7 @@ module Issuable include Sortable include CreatedAtFilterable include UpdatedAtFilterable + include IssuableStates # This object is used to gather issuable meta data for displaying # upvotes, downvotes, notes and closing merge requests count for issues and merge requests diff --git a/app/models/concerns/issuable_states.rb b/app/models/concerns/issuable_states.rb new file mode 100644 index 00000000000..7feaf7e8aac --- /dev/null +++ b/app/models/concerns/issuable_states.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +# == IssuableStates concern +# +# Defines statuses shared by issuables which are persisted on state column +# using the state machine. +# +# Used by EE::Epic, Issue and MergeRequest +# +module IssuableStates + extend ActiveSupport::Concern + + # Override this constant on model where different states are needed + # Check MergeRequest::AVAILABLE_STATES + AVAILABLE_STATES = { opened: 1, closed: 2 }.freeze + + included do + before_save :set_state_id + end + + class_methods do + def states + @states ||= OpenStruct.new(self::AVAILABLE_STATES) + end + end + + # The state:string column is being migrated to state_id:integer column + # This is a temporary hook to populate state_id column with new values + # and can be removed after the complete migration is done. + def set_state_id + return if state.nil? || state.empty? + + states_hash = self.class.states.to_h.with_indifferent_access + + self.state_id = states_hash[state] + end +end diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index 2035bffd829..67600383cf9 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -22,6 +22,8 @@ class MergeRequest < ActiveRecord::Base self.reactive_cache_lifetime = 10.minutes SORTING_PREFERENCE_FIELD = :merge_requests_sort + MERGE_REQUEST_STATES = + AVAILABLE_STATES = AVAILABLE_STATES.merge(merged: 3, locked: 4).freeze ignore_column :locked_at, :ref_fetched, diff --git a/db/migrate/20190211131150_add_state_id_to_issuables.rb b/db/migrate/20190211131150_add_state_id_to_issuables.rb new file mode 100644 index 00000000000..af02aa84afd --- /dev/null +++ b/db/migrate/20190211131150_add_state_id_to_issuables.rb @@ -0,0 +1,37 @@ +class AddStateIdToIssuables < ActiveRecord::Migration[5.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + MIGRATION = 'SyncIssuablesStateId'.freeze + + # TODO - find out how many issues and merge requests in production + # to adapt the batch size and delay interval + # Keep in mind that the migration will be scheduled for issues and merge requests. + BATCH_SIZE = 5000 + DELAY_INTERVAL = 5.minutes.to_i + + class Issue < ActiveRecord::Base + include EachBatch + + self.table_name = 'issues' + end + + class MergeRequest < ActiveRecord::Base + include EachBatch + + self.table_name = 'merge_requests' + end + + def up + add_column :issues, :state_id, :integer, limit: 1 + add_column :merge_requests, :state_id, :integer, limit: 1 + + queue_background_migration_jobs_by_range_at_intervals(Issue.where(state_id: nil), MIGRATION, DELAY_INTERVAL, batch_size: BATCH_SIZE) + queue_background_migration_jobs_by_range_at_intervals(MergeRequest.where(state_id: nil), MIGRATION, DELAY_INTERVAL, batch_size: BATCH_SIZE) + end + + def down + remove_column :issues, :state_id + remove_column :merge_requests, :state_id + end +end diff --git a/db/schema.rb b/db/schema.rb index 023eee5f33e..0fb31ce2ef2 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20190204115450) do +ActiveRecord::Schema.define(version: 20190211131150) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -1046,6 +1046,7 @@ ActiveRecord::Schema.define(version: 20190204115450) do t.boolean "discussion_locked" t.datetime_with_timezone "closed_at" t.integer "closed_by_id" + t.integer "state_id", limit: 2 t.index ["author_id"], name: "index_issues_on_author_id", using: :btree t.index ["closed_by_id"], name: "index_issues_on_closed_by_id", using: :btree t.index ["confidential"], name: "index_issues_on_confidential", using: :btree @@ -1283,6 +1284,7 @@ ActiveRecord::Schema.define(version: 20190204115450) do t.string "rebase_commit_sha" t.boolean "squash", default: false, null: false t.boolean "allow_maintainer_to_push" + t.integer "state_id", limit: 2 t.index ["assignee_id"], name: "index_merge_requests_on_assignee_id", using: :btree t.index ["author_id"], name: "index_merge_requests_on_author_id", using: :btree t.index ["created_at"], name: "index_merge_requests_on_created_at", using: :btree diff --git a/lib/gitlab/background_migration/sync_issuables_state_id.rb b/lib/gitlab/background_migration/sync_issuables_state_id.rb new file mode 100644 index 00000000000..1ac86b8acf2 --- /dev/null +++ b/lib/gitlab/background_migration/sync_issuables_state_id.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true +# rubocop:disable Style/Documentation + +module Gitlab + module BackgroundMigration + class SyncIssuablesStateId + def perform(start_id, end_id, model_class) + populate_new_state_id(start_id, end_id, model_class) + end + + def populate_new_state_id(start_id, end_id, model_class) + Rails.logger.info("#{model_class.model_name.human} - Populating state_id: #{start_id} - #{end_id}") + + ActiveRecord::Base.connection.execute <<~SQL + UPDATE #{model_class.table_name} + SET state_id = + CASE state + WHEN 'opened' THEN 1 + WHEN 'closed' THEN 2 + WHEN 'merged' THEN 3 + WHEN 'locked' THEN 4 + END + WHERE state_id IS NULL + AND id BETWEEN #{start_id} AND #{end_id} + SQL + end + end + end +end diff --git a/lib/gitlab/database/migration_helpers.rb b/lib/gitlab/database/migration_helpers.rb index 3abd0600e9d..20cbb9e096b 100644 --- a/lib/gitlab/database/migration_helpers.rb +++ b/lib/gitlab/database/migration_helpers.rb @@ -1033,7 +1033,7 @@ into similar problems in the future (e.g. when new tables are created). # `BackgroundMigrationWorker.bulk_perform_in` schedules all jobs for # the same time, which is not helpful in most cases where we wish to # spread the work over time. - BackgroundMigrationWorker.perform_in(delay_interval * index, job_class_name, [start_id, end_id]) + BackgroundMigrationWorker.perform_in(delay_interval * index, job_class_name, [start_id, end_id, model_class]) end end diff --git a/spec/migrations/add_state_id_to_issuables_spec.rb b/spec/migrations/add_state_id_to_issuables_spec.rb new file mode 100644 index 00000000000..4416f416c18 --- /dev/null +++ b/spec/migrations/add_state_id_to_issuables_spec.rb @@ -0,0 +1,89 @@ +# frozen_string_literal: true + +require 'spec_helper' +require Rails.root.join('db', 'migrate', '20190206144959_change_issuable_states_to_integer.rb') + +describe AddStateIdToIssuables, :migration do + let(:namespaces) { table(:namespaces) } + let(:projects) { table(:projects) } + let(:merge_requests) { table(:merge_requests) } + let(:issues) { table(:issues) } + let(:migration) { described_class.new } + + before do + @group = namespaces.create!(name: 'gitlab', path: 'gitlab') + @project = projects.create!(namespace_id: @group.id) + end + + describe '#up' do + context 'issues' do + it 'migrates state column to integer' do + opened_issue = issues.create!(description: 'first', state: 'opened') + closed_issue = issues.create!(description: 'second', state: 'closed') + nil_state_issue = issues.create!(description: 'third', state: nil) + + migrate! + + issues.reset_column_information + expect(opened_issue.reload.state).to eq(Issue.states.opened) + expect(closed_issue.reload.state).to eq(Issue.states.closed) + expect(nil_state_issue.reload.state).to eq(nil) + end + end + + context 'merge requests' do + it 'migrates state column to integer' do + opened_merge_request = merge_requests.create!(state: 'opened', target_project_id: @project.id, target_branch: 'feature1', source_branch: 'master') + closed_merge_request = merge_requests.create!(state: 'closed', target_project_id: @project.id, target_branch: 'feature2', source_branch: 'master') + merged_merge_request = merge_requests.create!(state: 'merged', target_project_id: @project.id, target_branch: 'feature3', source_branch: 'master') + locked_merge_request = merge_requests.create!(state: 'locked', target_project_id: @project.id, target_branch: 'feature4', source_branch: 'master') + nil_state_merge_request = merge_requests.create!(state: nil, target_project_id: @project.id, target_branch: 'feature5', source_branch: 'master') + + migrate! + + merge_requests.reset_column_information + expect(opened_merge_request.reload.state).to eq(MergeRequest.states.opened) + expect(closed_merge_request.reload.state).to eq(MergeRequest.states.closed) + expect(merged_merge_request.reload.state).to eq(MergeRequest.states.merged) + expect(locked_merge_request.reload.state).to eq(MergeRequest.states.locked) + expect(nil_state_merge_request.reload.state).to eq(nil) + end + end + end + + describe '#down' do + context 'issues' do + it 'migrates state column to string' do + opened_issue = issues.create!(description: 'first', state: 1) + closed_issue = issues.create!(description: 'second', state: 2) + nil_state_issue = issues.create!(description: 'third', state: nil) + + migration.down + + issues.reset_column_information + expect(opened_issue.reload.state).to eq('opened') + expect(closed_issue.reload.state).to eq('closed') + expect(nil_state_issue.reload.state).to eq(nil) + end + end + + context 'merge requests' do + it 'migrates state column to string' do + opened_merge_request = merge_requests.create!(state: 1, target_project_id: @project.id, target_branch: 'feature1', source_branch: 'master') + closed_merge_request = merge_requests.create!(state: 2, target_project_id: @project.id, target_branch: 'feature2', source_branch: 'master') + merged_merge_request = merge_requests.create!(state: 3, target_project_id: @project.id, target_branch: 'feature3', source_branch: 'master') + locked_merge_request = merge_requests.create!(state: 4, target_project_id: @project.id, target_branch: 'feature4', source_branch: 'master') + nil_state_merge_request = merge_requests.create!(state: nil, target_project_id: @project.id, target_branch: 'feature5', source_branch: 'master') + + migration.down + + merge_requests.reset_column_information + expect(opened_merge_request.reload.state).to eq('opened') + expect(closed_merge_request.reload.state).to eq('closed') + expect(merged_merge_request.reload.state).to eq('merged') + expect(locked_merge_request.reload.state).to eq('locked') + expect(nil_state_merge_request.reload.state).to eq(nil) + end + end + end +end -- cgit v1.2.1 From 362d56e65a0e23fcf4fd5bd4535d258c3659ffd5 Mon Sep 17 00:00:00 2001 From: Felipe Artur Date: Tue, 12 Feb 2019 14:40:37 -0200 Subject: Schedule background migrations and specs --- .../20190211131150_add_state_id_to_issuables.rb | 10 +++- .../sync_issuables_state_id.rb | 10 ++-- lib/gitlab/database/migration_helpers.rb | 3 +- spec/migrations/add_state_id_to_issuables_spec.rb | 60 +++++----------------- 4 files changed, 27 insertions(+), 56 deletions(-) diff --git a/db/migrate/20190211131150_add_state_id_to_issuables.rb b/db/migrate/20190211131150_add_state_id_to_issuables.rb index af02aa84afd..b9d52fe63cd 100644 --- a/db/migrate/20190211131150_add_state_id_to_issuables.rb +++ b/db/migrate/20190211131150_add_state_id_to_issuables.rb @@ -1,5 +1,6 @@ class AddStateIdToIssuables < ActiveRecord::Migration[5.0] include Gitlab::Database::MigrationHelpers + #include AfterCommitQueue DOWNTIME = false MIGRATION = 'SyncIssuablesStateId'.freeze @@ -26,8 +27,13 @@ class AddStateIdToIssuables < ActiveRecord::Migration[5.0] add_column :issues, :state_id, :integer, limit: 1 add_column :merge_requests, :state_id, :integer, limit: 1 - queue_background_migration_jobs_by_range_at_intervals(Issue.where(state_id: nil), MIGRATION, DELAY_INTERVAL, batch_size: BATCH_SIZE) - queue_background_migration_jobs_by_range_at_intervals(MergeRequest.where(state_id: nil), MIGRATION, DELAY_INTERVAL, batch_size: BATCH_SIZE) + # Is this safe? + # Added to avoid an warning about jobs running inside transactions. + # Since we only add a column this should be ok + Sidekiq::Worker.skipping_transaction_check do + queue_background_migration_jobs_by_range_at_intervals(Issue.where(state_id: nil), MIGRATION, DELAY_INTERVAL, batch_size: BATCH_SIZE) + queue_background_migration_jobs_by_range_at_intervals(MergeRequest.where(state_id: nil), MIGRATION, DELAY_INTERVAL, batch_size: BATCH_SIZE) + end end def down diff --git a/lib/gitlab/background_migration/sync_issuables_state_id.rb b/lib/gitlab/background_migration/sync_issuables_state_id.rb index 1ac86b8acf2..95734a7310e 100644 --- a/lib/gitlab/background_migration/sync_issuables_state_id.rb +++ b/lib/gitlab/background_migration/sync_issuables_state_id.rb @@ -4,15 +4,15 @@ module Gitlab module BackgroundMigration class SyncIssuablesStateId - def perform(start_id, end_id, model_class) - populate_new_state_id(start_id, end_id, model_class) + def perform(start_id, end_id, table_name) + populate_new_state_id(start_id, end_id, table_name) end - def populate_new_state_id(start_id, end_id, model_class) - Rails.logger.info("#{model_class.model_name.human} - Populating state_id: #{start_id} - #{end_id}") + def populate_new_state_id(start_id, end_id, table_name) + Rails.logger.info("#{table_name} - Populating state_id: #{start_id} - #{end_id}") ActiveRecord::Base.connection.execute <<~SQL - UPDATE #{model_class.table_name} + UPDATE #{table_name} SET state_id = CASE state WHEN 'opened' THEN 1 diff --git a/lib/gitlab/database/migration_helpers.rb b/lib/gitlab/database/migration_helpers.rb index 20cbb9e096b..46b36d07c20 100644 --- a/lib/gitlab/database/migration_helpers.rb +++ b/lib/gitlab/database/migration_helpers.rb @@ -1029,11 +1029,12 @@ into similar problems in the future (e.g. when new tables are created). model_class.each_batch(of: batch_size) do |relation, index| start_id, end_id = relation.pluck('MIN(id), MAX(id)').first + table_name = relation.base_class.table_name # `BackgroundMigrationWorker.bulk_perform_in` schedules all jobs for # the same time, which is not helpful in most cases where we wish to # spread the work over time. - BackgroundMigrationWorker.perform_in(delay_interval * index, job_class_name, [start_id, end_id, model_class]) + BackgroundMigrationWorker.perform_in(delay_interval * index, job_class_name, [start_id, end_id, table_name]) end end diff --git a/spec/migrations/add_state_id_to_issuables_spec.rb b/spec/migrations/add_state_id_to_issuables_spec.rb index 4416f416c18..b0e285db1f3 100644 --- a/spec/migrations/add_state_id_to_issuables_spec.rb +++ b/spec/migrations/add_state_id_to_issuables_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require 'spec_helper' -require Rails.root.join('db', 'migrate', '20190206144959_change_issuable_states_to_integer.rb') +require Rails.root.join('db', 'migrate', '20190211131150_add_state_id_to_issuables.rb') describe AddStateIdToIssuables, :migration do let(:namespaces) { table(:namespaces) } @@ -20,14 +20,15 @@ describe AddStateIdToIssuables, :migration do it 'migrates state column to integer' do opened_issue = issues.create!(description: 'first', state: 'opened') closed_issue = issues.create!(description: 'second', state: 'closed') + invalid_state_issue = issues.create!(description: 'fourth', state: 'not valid') nil_state_issue = issues.create!(description: 'third', state: nil) migrate! - issues.reset_column_information - expect(opened_issue.reload.state).to eq(Issue.states.opened) - expect(closed_issue.reload.state).to eq(Issue.states.closed) - expect(nil_state_issue.reload.state).to eq(nil) + expect(opened_issue.reload.state_id).to eq(Issue.states.opened) + expect(closed_issue.reload.state_id).to eq(Issue.states.closed) + expect(invalid_state_issue.reload.state_id).to be_nil + expect(nil_state_issue.reload.state_id).to be_nil end end @@ -37,52 +38,15 @@ describe AddStateIdToIssuables, :migration do closed_merge_request = merge_requests.create!(state: 'closed', target_project_id: @project.id, target_branch: 'feature2', source_branch: 'master') merged_merge_request = merge_requests.create!(state: 'merged', target_project_id: @project.id, target_branch: 'feature3', source_branch: 'master') locked_merge_request = merge_requests.create!(state: 'locked', target_project_id: @project.id, target_branch: 'feature4', source_branch: 'master') - nil_state_merge_request = merge_requests.create!(state: nil, target_project_id: @project.id, target_branch: 'feature5', source_branch: 'master') + invalid_state_merge_request = merge_requests.create!(state: 'not valid', target_project_id: @project.id, target_branch: 'feature5', source_branch: 'master') migrate! - merge_requests.reset_column_information - expect(opened_merge_request.reload.state).to eq(MergeRequest.states.opened) - expect(closed_merge_request.reload.state).to eq(MergeRequest.states.closed) - expect(merged_merge_request.reload.state).to eq(MergeRequest.states.merged) - expect(locked_merge_request.reload.state).to eq(MergeRequest.states.locked) - expect(nil_state_merge_request.reload.state).to eq(nil) - end - end - end - - describe '#down' do - context 'issues' do - it 'migrates state column to string' do - opened_issue = issues.create!(description: 'first', state: 1) - closed_issue = issues.create!(description: 'second', state: 2) - nil_state_issue = issues.create!(description: 'third', state: nil) - - migration.down - - issues.reset_column_information - expect(opened_issue.reload.state).to eq('opened') - expect(closed_issue.reload.state).to eq('closed') - expect(nil_state_issue.reload.state).to eq(nil) - end - end - - context 'merge requests' do - it 'migrates state column to string' do - opened_merge_request = merge_requests.create!(state: 1, target_project_id: @project.id, target_branch: 'feature1', source_branch: 'master') - closed_merge_request = merge_requests.create!(state: 2, target_project_id: @project.id, target_branch: 'feature2', source_branch: 'master') - merged_merge_request = merge_requests.create!(state: 3, target_project_id: @project.id, target_branch: 'feature3', source_branch: 'master') - locked_merge_request = merge_requests.create!(state: 4, target_project_id: @project.id, target_branch: 'feature4', source_branch: 'master') - nil_state_merge_request = merge_requests.create!(state: nil, target_project_id: @project.id, target_branch: 'feature5', source_branch: 'master') - - migration.down - - merge_requests.reset_column_information - expect(opened_merge_request.reload.state).to eq('opened') - expect(closed_merge_request.reload.state).to eq('closed') - expect(merged_merge_request.reload.state).to eq('merged') - expect(locked_merge_request.reload.state).to eq('locked') - expect(nil_state_merge_request.reload.state).to eq(nil) + expect(opened_merge_request.reload.state_id).to eq(MergeRequest.states.opened) + expect(closed_merge_request.reload.state_id).to eq(MergeRequest.states.closed) + expect(merged_merge_request.reload.state_id).to eq(MergeRequest.states.merged) + expect(locked_merge_request.reload.state_id).to eq(MergeRequest.states.locked) + expect(invalid_state_merge_request.reload.state_id).to be_nil end end end -- cgit v1.2.1 From e2aa332504f6cd9eebaa30dfeb71edcea6f9495a Mon Sep 17 00:00:00 2001 From: Felipe Artur Date: Tue, 12 Feb 2019 16:39:56 -0200 Subject: Improve batch size --- app/models/concerns/issuable_states.rb | 12 ++++++------ app/models/merge_request.rb | 1 - db/migrate/20190211131150_add_state_id_to_issuables.rb | 10 ++++++---- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/app/models/concerns/issuable_states.rb b/app/models/concerns/issuable_states.rb index 7feaf7e8aac..f9f5797065d 100644 --- a/app/models/concerns/issuable_states.rb +++ b/app/models/concerns/issuable_states.rb @@ -2,7 +2,7 @@ # == IssuableStates concern # -# Defines statuses shared by issuables which are persisted on state column +# Defines states shared by issuables which are persisted on state_id column # using the state machine. # # Used by EE::Epic, Issue and MergeRequest @@ -14,10 +14,6 @@ module IssuableStates # Check MergeRequest::AVAILABLE_STATES AVAILABLE_STATES = { opened: 1, closed: 2 }.freeze - included do - before_save :set_state_id - end - class_methods do def states @states ||= OpenStruct.new(self::AVAILABLE_STATES) @@ -26,7 +22,11 @@ module IssuableStates # The state:string column is being migrated to state_id:integer column # This is a temporary hook to populate state_id column with new values - # and can be removed after the complete migration is done. + # and can be removed after the state column is removed. + included do + before_save :set_state_id + end + def set_state_id return if state.nil? || state.empty? diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index 67600383cf9..ece31b359d1 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -22,7 +22,6 @@ class MergeRequest < ActiveRecord::Base self.reactive_cache_lifetime = 10.minutes SORTING_PREFERENCE_FIELD = :merge_requests_sort - MERGE_REQUEST_STATES = AVAILABLE_STATES = AVAILABLE_STATES.merge(merged: 3, locked: 4).freeze ignore_column :locked_at, diff --git a/db/migrate/20190211131150_add_state_id_to_issuables.rb b/db/migrate/20190211131150_add_state_id_to_issuables.rb index b9d52fe63cd..d23c946cf88 100644 --- a/db/migrate/20190211131150_add_state_id_to_issuables.rb +++ b/db/migrate/20190211131150_add_state_id_to_issuables.rb @@ -5,10 +5,12 @@ class AddStateIdToIssuables < ActiveRecord::Migration[5.0] DOWNTIME = false MIGRATION = 'SyncIssuablesStateId'.freeze - # TODO - find out how many issues and merge requests in production - # to adapt the batch size and delay interval - # Keep in mind that the migration will be scheduled for issues and merge requests. - BATCH_SIZE = 5000 + # 2019-02-12 Gitlab.com issuable numbers + # issues count: 13587305 + # merge requests count: 18925274 + # Using this 50000 as batch size should take around 13 hours + # to migrate both issues and merge requests + BATCH_SIZE = 50000 DELAY_INTERVAL = 5.minutes.to_i class Issue < ActiveRecord::Base -- cgit v1.2.1 From 26f40aefb09b96538fa99f74d46542ad39bb1679 Mon Sep 17 00:00:00 2001 From: Felipe Artur Date: Wed, 13 Feb 2019 17:31:14 -0200 Subject: Code improvements --- app/models/concerns/issuable.rb | 9 +++++++++ app/models/concerns/issuable_states.rb | 21 +-------------------- app/models/merge_request.rb | 5 ++++- .../20190211131150_add_state_id_to_issuables.rb | 8 ++++---- 4 files changed, 18 insertions(+), 25 deletions(-) diff --git a/app/models/concerns/issuable.rb b/app/models/concerns/issuable.rb index 7bf553a0221..83bd8cc6478 100644 --- a/app/models/concerns/issuable.rb +++ b/app/models/concerns/issuable.rb @@ -132,6 +132,15 @@ module Issuable fuzzy_search(query, [:title]) end + # Available state values persisted in state_id column using state machine + # + # Override this on subclasses if different states are needed + # + # Check MergeRequest.available_states for example + def available_states + @available_states ||= { opened: 1, closed: 2 }.with_indifferent_access + end + # Searches for records with a matching title or description. # # This method uses ILIKE on PostgreSQL and LIKE on MySQL. diff --git a/app/models/concerns/issuable_states.rb b/app/models/concerns/issuable_states.rb index f9f5797065d..d7992f8e6db 100644 --- a/app/models/concerns/issuable_states.rb +++ b/app/models/concerns/issuable_states.rb @@ -1,25 +1,6 @@ -# frozen_string_literal: true - -# == IssuableStates concern -# -# Defines states shared by issuables which are persisted on state_id column -# using the state machine. -# -# Used by EE::Epic, Issue and MergeRequest -# module IssuableStates extend ActiveSupport::Concern - # Override this constant on model where different states are needed - # Check MergeRequest::AVAILABLE_STATES - AVAILABLE_STATES = { opened: 1, closed: 2 }.freeze - - class_methods do - def states - @states ||= OpenStruct.new(self::AVAILABLE_STATES) - end - end - # The state:string column is being migrated to state_id:integer column # This is a temporary hook to populate state_id column with new values # and can be removed after the state column is removed. @@ -30,7 +11,7 @@ module IssuableStates def set_state_id return if state.nil? || state.empty? - states_hash = self.class.states.to_h.with_indifferent_access + states_hash = self.class.available_states self.state_id = states_hash[state] end diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index ece31b359d1..6baf479d8d1 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -22,7 +22,6 @@ class MergeRequest < ActiveRecord::Base self.reactive_cache_lifetime = 10.minutes SORTING_PREFERENCE_FIELD = :merge_requests_sort - AVAILABLE_STATES = AVAILABLE_STATES.merge(merged: 3, locked: 4).freeze ignore_column :locked_at, :ref_fetched, @@ -194,6 +193,10 @@ class MergeRequest < ActiveRecord::Base '!' end + def self.available_states + @states ||= super.merge(locked: 3, merged: 4) + end + def rebase_in_progress? strong_memoize(:rebase_in_progress) do # The source project can be deleted diff --git a/db/migrate/20190211131150_add_state_id_to_issuables.rb b/db/migrate/20190211131150_add_state_id_to_issuables.rb index d23c946cf88..440f577e1a3 100644 --- a/db/migrate/20190211131150_add_state_id_to_issuables.rb +++ b/db/migrate/20190211131150_add_state_id_to_issuables.rb @@ -8,9 +8,9 @@ class AddStateIdToIssuables < ActiveRecord::Migration[5.0] # 2019-02-12 Gitlab.com issuable numbers # issues count: 13587305 # merge requests count: 18925274 - # Using this 50000 as batch size should take around 13 hours + # Using this 25000 as batch size should take around 26 hours # to migrate both issues and merge requests - BATCH_SIZE = 50000 + BATCH_SIZE = 25000 DELAY_INTERVAL = 5.minutes.to_i class Issue < ActiveRecord::Base @@ -26,8 +26,8 @@ class AddStateIdToIssuables < ActiveRecord::Migration[5.0] end def up - add_column :issues, :state_id, :integer, limit: 1 - add_column :merge_requests, :state_id, :integer, limit: 1 + add_column :issues, :state_id, :integer, limit: 2 + add_column :merge_requests, :state_id, :integer, limit: 2 # Is this safe? # Added to avoid an warning about jobs running inside transactions. -- cgit v1.2.1 From 37741c59a4daf1b0d6d9f7a6a51337e9d8effb66 Mon Sep 17 00:00:00 2001 From: Felipe Artur Date: Thu, 14 Feb 2019 11:48:20 -0200 Subject: Split background migration for issues and merge requests --- app/models/merge_request.rb | 2 +- .../20190211131150_add_state_id_to_issuables.rb | 30 ------------ ...90214112022_schedule_sync_issuables_state_id.rb | 43 ++++++++++++++++++ db/schema.rb | 2 +- .../sync_issuables_state_id.rb | 29 ------------ .../background_migration/sync_issues_state_id.rb | 23 ++++++++++ .../sync_merge_requests_state_id.rb | 25 ++++++++++ lib/gitlab/database/migration_helpers.rb | 3 +- spec/migrations/add_state_id_to_issuables_spec.rb | 53 ---------------------- .../schedule_sync_issuables_state_id_spec.rb | 53 ++++++++++++++++++++++ 10 files changed, 147 insertions(+), 116 deletions(-) create mode 100644 db/post_migrate/20190214112022_schedule_sync_issuables_state_id.rb delete mode 100644 lib/gitlab/background_migration/sync_issuables_state_id.rb create mode 100644 lib/gitlab/background_migration/sync_issues_state_id.rb create mode 100644 lib/gitlab/background_migration/sync_merge_requests_state_id.rb delete mode 100644 spec/migrations/add_state_id_to_issuables_spec.rb create mode 100644 spec/migrations/schedule_sync_issuables_state_id_spec.rb diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index 6baf479d8d1..0ec0789a24f 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -194,7 +194,7 @@ class MergeRequest < ActiveRecord::Base end def self.available_states - @states ||= super.merge(locked: 3, merged: 4) + @states ||= super.merge(merged: 3, locked: 4) end def rebase_in_progress? diff --git a/db/migrate/20190211131150_add_state_id_to_issuables.rb b/db/migrate/20190211131150_add_state_id_to_issuables.rb index 440f577e1a3..cf3f7671a67 100644 --- a/db/migrate/20190211131150_add_state_id_to_issuables.rb +++ b/db/migrate/20190211131150_add_state_id_to_issuables.rb @@ -1,41 +1,11 @@ class AddStateIdToIssuables < ActiveRecord::Migration[5.0] include Gitlab::Database::MigrationHelpers - #include AfterCommitQueue DOWNTIME = false - MIGRATION = 'SyncIssuablesStateId'.freeze - - # 2019-02-12 Gitlab.com issuable numbers - # issues count: 13587305 - # merge requests count: 18925274 - # Using this 25000 as batch size should take around 26 hours - # to migrate both issues and merge requests - BATCH_SIZE = 25000 - DELAY_INTERVAL = 5.minutes.to_i - - class Issue < ActiveRecord::Base - include EachBatch - - self.table_name = 'issues' - end - - class MergeRequest < ActiveRecord::Base - include EachBatch - - self.table_name = 'merge_requests' - end def up add_column :issues, :state_id, :integer, limit: 2 add_column :merge_requests, :state_id, :integer, limit: 2 - - # Is this safe? - # Added to avoid an warning about jobs running inside transactions. - # Since we only add a column this should be ok - Sidekiq::Worker.skipping_transaction_check do - queue_background_migration_jobs_by_range_at_intervals(Issue.where(state_id: nil), MIGRATION, DELAY_INTERVAL, batch_size: BATCH_SIZE) - queue_background_migration_jobs_by_range_at_intervals(MergeRequest.where(state_id: nil), MIGRATION, DELAY_INTERVAL, batch_size: BATCH_SIZE) - end end def down diff --git a/db/post_migrate/20190214112022_schedule_sync_issuables_state_id.rb b/db/post_migrate/20190214112022_schedule_sync_issuables_state_id.rb new file mode 100644 index 00000000000..d9b77d2f02c --- /dev/null +++ b/db/post_migrate/20190214112022_schedule_sync_issuables_state_id.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +# See http://doc.gitlab.com/ce/development/migration_style_guide.html +# for more information on how to write migrations for GitLab. + +class ScheduleSyncIssuablesStateId < ActiveRecord::Migration[5.0] + include Gitlab::Database::MigrationHelpers + + DOWNTIME = false + + # 2019-02-12 Gitlab.com issuable numbers + # issues count: 13587305 + # merge requests count: 18925274 + # Using this 25000 as batch size should take around 26 hours + # to migrate both issues and merge requests + BATCH_SIZE = 25000 + DELAY_INTERVAL = 5.minutes.to_i + ISSUE_MIGRATION = 'SyncIssuesStateId'.freeze + MERGE_REQUEST_MIGRATION = 'SyncMergeRequestsStateId'.freeze + + class Issue < ActiveRecord::Base + include EachBatch + + self.table_name = 'issues' + end + + class MergeRequest < ActiveRecord::Base + include EachBatch + + self.table_name = 'merge_requests' + end + + def up + Sidekiq::Worker.skipping_transaction_check do + queue_background_migration_jobs_by_range_at_intervals(Issue.where(state_id: nil), ISSUE_MIGRATION, DELAY_INTERVAL, batch_size: BATCH_SIZE) + queue_background_migration_jobs_by_range_at_intervals(MergeRequest.where(state_id: nil), MERGE_REQUEST_MIGRATION, DELAY_INTERVAL, batch_size: BATCH_SIZE) + end + end + + def down + # No op + end +end diff --git a/db/schema.rb b/db/schema.rb index 0fb31ce2ef2..4a347e7289b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20190211131150) do +ActiveRecord::Schema.define(version: 20190214112022) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" diff --git a/lib/gitlab/background_migration/sync_issuables_state_id.rb b/lib/gitlab/background_migration/sync_issuables_state_id.rb deleted file mode 100644 index 95734a7310e..00000000000 --- a/lib/gitlab/background_migration/sync_issuables_state_id.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true -# rubocop:disable Style/Documentation - -module Gitlab - module BackgroundMigration - class SyncIssuablesStateId - def perform(start_id, end_id, table_name) - populate_new_state_id(start_id, end_id, table_name) - end - - def populate_new_state_id(start_id, end_id, table_name) - Rails.logger.info("#{table_name} - Populating state_id: #{start_id} - #{end_id}") - - ActiveRecord::Base.connection.execute <<~SQL - UPDATE #{table_name} - SET state_id = - CASE state - WHEN 'opened' THEN 1 - WHEN 'closed' THEN 2 - WHEN 'merged' THEN 3 - WHEN 'locked' THEN 4 - END - WHERE state_id IS NULL - AND id BETWEEN #{start_id} AND #{end_id} - SQL - end - end - end -end diff --git a/lib/gitlab/background_migration/sync_issues_state_id.rb b/lib/gitlab/background_migration/sync_issues_state_id.rb new file mode 100644 index 00000000000..33b997c8533 --- /dev/null +++ b/lib/gitlab/background_migration/sync_issues_state_id.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true +# rubocop:disable Style/Documentation + +module Gitlab + module BackgroundMigration + class SyncIssuesStateId + def perform(start_id, end_id) + Rails.logger.info("Issues - Populating state_id: #{start_id} - #{end_id}") + + ActiveRecord::Base.connection.execute <<~SQL + UPDATE issues + SET state_id = + CASE state + WHEN 'opened' THEN 1 + WHEN 'closed' THEN 2 + END + WHERE state_id IS NULL + AND id BETWEEN #{start_id} AND #{end_id} + SQL + end + end + end +end diff --git a/lib/gitlab/background_migration/sync_merge_requests_state_id.rb b/lib/gitlab/background_migration/sync_merge_requests_state_id.rb new file mode 100644 index 00000000000..923ceaeec54 --- /dev/null +++ b/lib/gitlab/background_migration/sync_merge_requests_state_id.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true +# rubocop:disable Style/Documentation + +module Gitlab + module BackgroundMigration + class SyncMergeRequestsStateId + def perform(start_id, end_id) + Rails.logger.info("Merge Requests - Populating state_id: #{start_id} - #{end_id}") + + ActiveRecord::Base.connection.execute <<~SQL + UPDATE merge_requests + SET state_id = + CASE state + WHEN 'opened' THEN 1 + WHEN 'closed' THEN 2 + WHEN 'merged' THEN 3 + WHEN 'locked' THEN 4 + END + WHERE state_id IS NULL + AND id BETWEEN #{start_id} AND #{end_id} + SQL + end + end + end +end diff --git a/lib/gitlab/database/migration_helpers.rb b/lib/gitlab/database/migration_helpers.rb index 46b36d07c20..3abd0600e9d 100644 --- a/lib/gitlab/database/migration_helpers.rb +++ b/lib/gitlab/database/migration_helpers.rb @@ -1029,12 +1029,11 @@ into similar problems in the future (e.g. when new tables are created). model_class.each_batch(of: batch_size) do |relation, index| start_id, end_id = relation.pluck('MIN(id), MAX(id)').first - table_name = relation.base_class.table_name # `BackgroundMigrationWorker.bulk_perform_in` schedules all jobs for # the same time, which is not helpful in most cases where we wish to # spread the work over time. - BackgroundMigrationWorker.perform_in(delay_interval * index, job_class_name, [start_id, end_id, table_name]) + BackgroundMigrationWorker.perform_in(delay_interval * index, job_class_name, [start_id, end_id]) end end diff --git a/spec/migrations/add_state_id_to_issuables_spec.rb b/spec/migrations/add_state_id_to_issuables_spec.rb deleted file mode 100644 index b0e285db1f3..00000000000 --- a/spec/migrations/add_state_id_to_issuables_spec.rb +++ /dev/null @@ -1,53 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' -require Rails.root.join('db', 'migrate', '20190211131150_add_state_id_to_issuables.rb') - -describe AddStateIdToIssuables, :migration do - let(:namespaces) { table(:namespaces) } - let(:projects) { table(:projects) } - let(:merge_requests) { table(:merge_requests) } - let(:issues) { table(:issues) } - let(:migration) { described_class.new } - - before do - @group = namespaces.create!(name: 'gitlab', path: 'gitlab') - @project = projects.create!(namespace_id: @group.id) - end - - describe '#up' do - context 'issues' do - it 'migrates state column to integer' do - opened_issue = issues.create!(description: 'first', state: 'opened') - closed_issue = issues.create!(description: 'second', state: 'closed') - invalid_state_issue = issues.create!(description: 'fourth', state: 'not valid') - nil_state_issue = issues.create!(description: 'third', state: nil) - - migrate! - - expect(opened_issue.reload.state_id).to eq(Issue.states.opened) - expect(closed_issue.reload.state_id).to eq(Issue.states.closed) - expect(invalid_state_issue.reload.state_id).to be_nil - expect(nil_state_issue.reload.state_id).to be_nil - end - end - - context 'merge requests' do - it 'migrates state column to integer' do - opened_merge_request = merge_requests.create!(state: 'opened', target_project_id: @project.id, target_branch: 'feature1', source_branch: 'master') - closed_merge_request = merge_requests.create!(state: 'closed', target_project_id: @project.id, target_branch: 'feature2', source_branch: 'master') - merged_merge_request = merge_requests.create!(state: 'merged', target_project_id: @project.id, target_branch: 'feature3', source_branch: 'master') - locked_merge_request = merge_requests.create!(state: 'locked', target_project_id: @project.id, target_branch: 'feature4', source_branch: 'master') - invalid_state_merge_request = merge_requests.create!(state: 'not valid', target_project_id: @project.id, target_branch: 'feature5', source_branch: 'master') - - migrate! - - expect(opened_merge_request.reload.state_id).to eq(MergeRequest.states.opened) - expect(closed_merge_request.reload.state_id).to eq(MergeRequest.states.closed) - expect(merged_merge_request.reload.state_id).to eq(MergeRequest.states.merged) - expect(locked_merge_request.reload.state_id).to eq(MergeRequest.states.locked) - expect(invalid_state_merge_request.reload.state_id).to be_nil - end - end - end -end diff --git a/spec/migrations/schedule_sync_issuables_state_id_spec.rb b/spec/migrations/schedule_sync_issuables_state_id_spec.rb new file mode 100644 index 00000000000..a926ee38387 --- /dev/null +++ b/spec/migrations/schedule_sync_issuables_state_id_spec.rb @@ -0,0 +1,53 @@ +# frozen_string_literal: true + +require 'spec_helper' +require Rails.root.join('db', 'post_migrate', '20190214112022_schedule_sync_issuables_state_id.rb') + +describe ScheduleSyncIssuablesStateId, :migration do + let(:namespaces) { table(:namespaces) } + let(:projects) { table(:projects) } + let(:merge_requests) { table(:merge_requests) } + let(:issues) { table(:issues) } + let(:migration) { described_class.new } + + before do + @group = namespaces.create!(name: 'gitlab', path: 'gitlab') + @project = projects.create!(namespace_id: @group.id) + end + + describe '#up' do + context 'issues' do + it 'migrates state column to integer' do + opened_issue = issues.create!(description: 'first', state: 'opened') + closed_issue = issues.create!(description: 'second', state: 'closed') + invalid_state_issue = issues.create!(description: 'fourth', state: 'not valid') + nil_state_issue = issues.create!(description: 'third', state: nil) + + migrate! + + expect(opened_issue.reload.state_id).to eq(Issue.available_states[:opened]) + expect(closed_issue.reload.state_id).to eq(Issue.available_states[:closed]) + expect(invalid_state_issue.reload.state_id).to be_nil + expect(nil_state_issue.reload.state_id).to be_nil + end + end + + context 'merge requests' do + it 'migrates state column to integer' do + opened_merge_request = merge_requests.create!(state: 'opened', target_project_id: @project.id, target_branch: 'feature1', source_branch: 'master') + closed_merge_request = merge_requests.create!(state: 'closed', target_project_id: @project.id, target_branch: 'feature2', source_branch: 'master') + merged_merge_request = merge_requests.create!(state: 'merged', target_project_id: @project.id, target_branch: 'feature3', source_branch: 'master') + locked_merge_request = merge_requests.create!(state: 'locked', target_project_id: @project.id, target_branch: 'feature4', source_branch: 'master') + invalid_state_merge_request = merge_requests.create!(state: 'not valid', target_project_id: @project.id, target_branch: 'feature5', source_branch: 'master') + + migrate! + + expect(opened_merge_request.reload.state_id).to eq(MergeRequest.available_states[:opened]) + expect(closed_merge_request.reload.state_id).to eq(MergeRequest.available_states[:closed]) + expect(merged_merge_request.reload.state_id).to eq(MergeRequest.available_states[:merged]) + expect(locked_merge_request.reload.state_id).to eq(MergeRequest.available_states[:locked]) + expect(invalid_state_merge_request.reload.state_id).to be_nil + end + end + end +end -- cgit v1.2.1 From d4a5d8d07069acb6f068990633baaf56d20bc18b Mon Sep 17 00:00:00 2001 From: Felipe Artur Date: Thu, 14 Feb 2019 14:24:23 -0200 Subject: Add specs for issuable states sync --- app/models/concerns/issuable_states.rb | 1 + spec/models/concerns/issuable_states_spec.rb | 30 ++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 spec/models/concerns/issuable_states_spec.rb diff --git a/app/models/concerns/issuable_states.rb b/app/models/concerns/issuable_states.rb index d7992f8e6db..a39a0ef77ed 100644 --- a/app/models/concerns/issuable_states.rb +++ b/app/models/concerns/issuable_states.rb @@ -4,6 +4,7 @@ module IssuableStates # The state:string column is being migrated to state_id:integer column # This is a temporary hook to populate state_id column with new values # and can be removed after the state column is removed. + # Check https://gitlab.com/gitlab-org/gitlab-ce/issues/51789 for more information included do before_save :set_state_id end diff --git a/spec/models/concerns/issuable_states_spec.rb b/spec/models/concerns/issuable_states_spec.rb new file mode 100644 index 00000000000..70450159cc0 --- /dev/null +++ b/spec/models/concerns/issuable_states_spec.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +require 'spec_helper' + +# This spec checks if state_id column of issues and merge requests +# are being synced on every save. +# It can be removed in the next release. Check https://gitlab.com/gitlab-org/gitlab-ce/issues/51789 for more information. +describe IssuableStates do + [Issue, MergeRequest].each do |klass| + it "syncs state_id column when #{klass.model_name.human} gets created" do + klass.available_states.each do |state, state_id| + issuable = build(klass.model_name.param_key, state: state.to_s) + + issuable.save! + + expect(issuable.state_id).to eq(state_id) + end + end + + it "syncs state_id column when #{klass.model_name.human} gets updated" do + klass.available_states.each do |state, state_id| + issuable = create(klass.model_name.param_key, state: state.to_s) + + issuable.update(state: state) + + expect(issuable.state_id).to eq(state_id) + end + end + end +end -- cgit v1.2.1 From 2fd784a4c1cb991391399ac369bfb008db697380 Mon Sep 17 00:00:00 2001 From: Nathan Friend Date: Thu, 14 Feb 2019 13:26:17 -0400 Subject: Update border radius of form controls and remove space above page titles This commit makes changes to global CSS styles to bring the product closer to compliance with Pajamas (the GitLab design system). --- app/assets/stylesheets/framework/forms.scss | 2 +- app/assets/stylesheets/framework/page_title.scss | 1 - .../nfriend-css-updates-for-gitlab-design-system-compliance.yml | 5 +++++ 3 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 changelogs/unreleased/nfriend-css-updates-for-gitlab-design-system-compliance.yml diff --git a/app/assets/stylesheets/framework/forms.scss b/app/assets/stylesheets/framework/forms.scss index cbf9ee24ec5..94fc684ca5f 100644 --- a/app/assets/stylesheets/framework/forms.scss +++ b/app/assets/stylesheets/framework/forms.scss @@ -128,7 +128,7 @@ label { .form-control { @include box-shadow(none); - border-radius: 2px; + border-radius: $border-radius-default; padding: $gl-vert-padding $gl-input-padding; &.input-short { diff --git a/app/assets/stylesheets/framework/page_title.scss b/app/assets/stylesheets/framework/page_title.scss index e8302953a63..ad6575761b5 100644 --- a/app/assets/stylesheets/framework/page_title.scss +++ b/app/assets/stylesheets/framework/page_title.scss @@ -2,7 +2,6 @@ @extend .d-flex; @extend .align-items-center; - padding-top: $gl-padding-top; border-bottom: 1px solid $border-color; .page-title { diff --git a/changelogs/unreleased/nfriend-css-updates-for-gitlab-design-system-compliance.yml b/changelogs/unreleased/nfriend-css-updates-for-gitlab-design-system-compliance.yml new file mode 100644 index 00000000000..8cde0958f7a --- /dev/null +++ b/changelogs/unreleased/nfriend-css-updates-for-gitlab-design-system-compliance.yml @@ -0,0 +1,5 @@ +--- +title: Update `border-radius` of form controls and remove extra space above page titles +merge_request: 24497 +author: +type: fixed -- cgit v1.2.1 From 9671a67a4ce58683ca0188ff9e75b1d5dfcc5dec Mon Sep 17 00:00:00 2001 From: Felipe Artur Date: Thu, 14 Feb 2019 16:33:26 -0200 Subject: Fix broken specs --- app/models/concerns/issuable_states.rb | 10 +++++++++- app/models/merge_request.rb | 2 +- db/migrate/20190211131150_add_state_id_to_issuables.rb | 2 ++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/models/concerns/issuable_states.rb b/app/models/concerns/issuable_states.rb index a39a0ef77ed..12fa97a1469 100644 --- a/app/models/concerns/issuable_states.rb +++ b/app/models/concerns/issuable_states.rb @@ -1,9 +1,11 @@ +# frozen_string_literal: true + module IssuableStates extend ActiveSupport::Concern # The state:string column is being migrated to state_id:integer column # This is a temporary hook to populate state_id column with new values - # and can be removed after the state column is removed. + # and should be removed after the state column is removed. # Check https://gitlab.com/gitlab-org/gitlab-ce/issues/51789 for more information included do before_save :set_state_id @@ -12,6 +14,12 @@ module IssuableStates def set_state_id return if state.nil? || state.empty? + # Needed to prevent breaking some migration specs that + # rollback database to a point where state_id does not exist. + # We can use this guard clause for now since this file will should + # be removed in the next release. + return unless self.respond_to?(:state_id) + states_hash = self.class.available_states self.state_id = states_hash[state] diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index 0ec0789a24f..063433111cc 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -194,7 +194,7 @@ class MergeRequest < ActiveRecord::Base end def self.available_states - @states ||= super.merge(merged: 3, locked: 4) + @available_states ||= super.merge(merged: 3, locked: 4) end def rebase_in_progress? diff --git a/db/migrate/20190211131150_add_state_id_to_issuables.rb b/db/migrate/20190211131150_add_state_id_to_issuables.rb index cf3f7671a67..c1173eb4249 100644 --- a/db/migrate/20190211131150_add_state_id_to_issuables.rb +++ b/db/migrate/20190211131150_add_state_id_to_issuables.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class AddStateIdToIssuables < ActiveRecord::Migration[5.0] include Gitlab::Database::MigrationHelpers -- cgit v1.2.1 From 7b79f6ab0d342e335609a7f3eb6cb691d1f03111 Mon Sep 17 00:00:00 2001 From: Felipe Artur Date: Thu, 14 Feb 2019 16:37:12 -0200 Subject: fix typo --- app/models/concerns/issuable_states.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/concerns/issuable_states.rb b/app/models/concerns/issuable_states.rb index 12fa97a1469..2ebd5013a4c 100644 --- a/app/models/concerns/issuable_states.rb +++ b/app/models/concerns/issuable_states.rb @@ -16,8 +16,8 @@ module IssuableStates # Needed to prevent breaking some migration specs that # rollback database to a point where state_id does not exist. - # We can use this guard clause for now since this file will should - # be removed in the next release. + # We can use this guard clause for now since this file will + # be removed on a future the next release. return unless self.respond_to?(:state_id) states_hash = self.class.available_states -- cgit v1.2.1 From bf99ce7bf8bf4bda75ca57f5db4d216f3585615a Mon Sep 17 00:00:00 2001 From: Felipe Artur Date: Fri, 15 Feb 2019 14:37:55 -0200 Subject: Fix specs --- spec/db/schema_spec.rb | 4 ++-- spec/lib/gitlab/import_export/safe_model_attributes.yml | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/spec/db/schema_spec.rb b/spec/db/schema_spec.rb index 897b4411055..40c3a6d90d0 100644 --- a/spec/db/schema_spec.rb +++ b/spec/db/schema_spec.rb @@ -25,12 +25,12 @@ describe 'Database schema' do events: %w[target_id], forked_project_links: %w[forked_from_project_id], identities: %w[user_id], - issues: %w[last_edited_by_id], + issues: %w[last_edited_by_id state_id], keys: %w[user_id], label_links: %w[target_id], lfs_objects_projects: %w[lfs_object_id project_id], members: %w[source_id created_by_id], - merge_requests: %w[last_edited_by_id], + merge_requests: %w[last_edited_by_id state_id], namespaces: %w[owner_id parent_id], notes: %w[author_id commit_id noteable_id updated_by_id resolved_by_id discussion_id], notification_settings: %w[source_id], diff --git a/spec/lib/gitlab/import_export/safe_model_attributes.yml b/spec/lib/gitlab/import_export/safe_model_attributes.yml index baca8f6d542..9cfa29ca7d9 100644 --- a/spec/lib/gitlab/import_export/safe_model_attributes.yml +++ b/spec/lib/gitlab/import_export/safe_model_attributes.yml @@ -11,6 +11,7 @@ Issue: - branch_name - description - state +- state_id - iid - updated_by_id - confidential @@ -158,6 +159,7 @@ MergeRequest: - created_at - updated_at - state +- state_id - merge_status - target_project_id - iid -- cgit v1.2.1 From b1346db3a0b49b295a9702921285fdb30029563c Mon Sep 17 00:00:00 2001 From: Felipe Artur Date: Fri, 15 Feb 2019 17:11:41 -0200 Subject: Add Reschedulable module --- lib/gitlab/background_migration.rb | 2 + .../background_migration/concerns/reschedulable.rb | 50 ++++++++++++++++++++++ .../background_migration/delete_diff_files.rb | 37 +++------------- .../background_migration/delete_diff_files_spec.rb | 10 ++--- 4 files changed, 63 insertions(+), 36 deletions(-) create mode 100644 lib/gitlab/background_migration/concerns/reschedulable.rb diff --git a/lib/gitlab/background_migration.rb b/lib/gitlab/background_migration.rb index 5251e0fadf9..b308e94bfa0 100644 --- a/lib/gitlab/background_migration.rb +++ b/lib/gitlab/background_migration.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +Dir[Rails.root.join("lib/gitlab/background_migration/concerns/*.rb")].each { |f| require f } + module Gitlab module BackgroundMigration def self.queue diff --git a/lib/gitlab/background_migration/concerns/reschedulable.rb b/lib/gitlab/background_migration/concerns/reschedulable.rb new file mode 100644 index 00000000000..fbf3d799743 --- /dev/null +++ b/lib/gitlab/background_migration/concerns/reschedulable.rb @@ -0,0 +1,50 @@ +# frozen_string_literal: true + +module Gitlab + module BackgroundMigration + module Reschedulable + extend ActiveSupport::Concern + + def reschedule_if_needed(args, &block) + if should_reschedule? + BackgroundMigrationWorker.perform_in(vacuum_wait_time, self.class.name.demodulize, args) + else + yield + end + end + + # Override this on base class if you need a different reschedule condition + def should_reschedule? + raise NotImplementedError, "#{self.class} does not implement #{__method__}" + end + + def wait_for_deadtuple_vacuum?(table_name) + return false unless Gitlab::Database.postgresql? + + dead_tuples_count_for(table_name) >= dead_tuples_threshold + end + + def dead_tuples_count_for(table_name) + dead_tuple = + execute_statement("SELECT n_dead_tup FROM pg_stat_all_tables "\ + "WHERE relname = '#{table_name}'")[0] + + dead_tuple&.fetch('n_dead_tup', 0).to_i + end + + def execute_statement(sql) + ActiveRecord::Base.connection.execute(sql) + end + + # Override in subclass if you need a different dead tuple threshold + def dead_tuples_threshold + @dead_tuples_threshold ||= 50_000 + end + + # Override in subclass if you need a different vacuum wait time + def vacuum_wait_time + @vacuum_wait_time ||= 5.minutes + end + end + end +end diff --git a/lib/gitlab/background_migration/delete_diff_files.rb b/lib/gitlab/background_migration/delete_diff_files.rb index 664ead1af44..0a7cbd5c30f 100644 --- a/lib/gitlab/background_migration/delete_diff_files.rb +++ b/lib/gitlab/background_migration/delete_diff_files.rb @@ -4,6 +4,8 @@ module Gitlab module BackgroundMigration class DeleteDiffFiles + include Reschedulable + class MergeRequestDiff < ActiveRecord::Base self.table_name = 'merge_request_diffs' @@ -15,47 +17,24 @@ module Gitlab self.table_name = 'merge_request_diff_files' end - DEAD_TUPLES_THRESHOLD = 50_000 - VACUUM_WAIT_TIME = 5.minutes - def perform(ids) @ids = ids - # We should reschedule until deadtuples get in a desirable - # state (e.g. < 50_000). That may take more than one reschedule. - # - if should_wait_deadtuple_vacuum? - reschedule - return + reschedule_if_needed([ids]) do + prune_diff_files end - - prune_diff_files - end - - def should_wait_deadtuple_vacuum? - return false unless Gitlab::Database.postgresql? - - diff_files_dead_tuples_count >= DEAD_TUPLES_THRESHOLD end private - def reschedule - BackgroundMigrationWorker.perform_in(VACUUM_WAIT_TIME, self.class.name.demodulize, [@ids]) + def should_reschedule? + wait_for_deadtuple_vacuum?(MergeRequestDiffFile.table_name) end def diffs_collection MergeRequestDiff.where(id: @ids) end - def diff_files_dead_tuples_count - dead_tuple = - execute_statement("SELECT n_dead_tup FROM pg_stat_all_tables "\ - "WHERE relname = 'merge_request_diff_files'")[0] - - dead_tuple&.fetch('n_dead_tup', 0).to_i - end - def prune_diff_files removed = 0 updated = 0 @@ -69,10 +48,6 @@ module Gitlab "updated #{updated} merge_request_diffs rows") end - def execute_statement(sql) - ActiveRecord::Base.connection.execute(sql) - end - def log_info(message) Rails.logger.info("BackgroundMigration::DeleteDiffFiles - #{message}") end diff --git a/spec/lib/gitlab/background_migration/delete_diff_files_spec.rb b/spec/lib/gitlab/background_migration/delete_diff_files_spec.rb index 27281333348..690881ab59b 100644 --- a/spec/lib/gitlab/background_migration/delete_diff_files_spec.rb +++ b/spec/lib/gitlab/background_migration/delete_diff_files_spec.rb @@ -40,14 +40,14 @@ describe Gitlab::BackgroundMigration::DeleteDiffFiles, :migration, :sidekiq, sch end end - it 'reschedules itself when should_wait_deadtuple_vacuum' do + it 'reschedules itself when should wait for dead tuple vacuum' do merge_request = create(:merge_request, :merged) first_diff = merge_request.merge_request_diff second_diff = merge_request.create_merge_request_diff Sidekiq::Testing.fake! do worker = described_class.new - allow(worker).to receive(:should_wait_deadtuple_vacuum?) { true } + allow(worker).to receive(:wait_for_deadtuple_vacuum?) { true } worker.perform([first_diff.id, second_diff.id]) @@ -57,10 +57,10 @@ describe Gitlab::BackgroundMigration::DeleteDiffFiles, :migration, :sidekiq, sch end end - describe '#should_wait_deadtuple_vacuum?' do + describe '#wait_for_deadtuple_vacuum?' do it 'returns true when hitting merge_request_diff_files hits DEAD_TUPLES_THRESHOLD', :postgresql do worker = described_class.new - threshold_query_result = [{ "n_dead_tup" => described_class::DEAD_TUPLES_THRESHOLD.to_s }] + threshold_query_result = [{ "n_dead_tup" => 50_000 }] normal_query_result = [{ "n_dead_tup" => '3' }] allow(worker) @@ -68,7 +68,7 @@ describe Gitlab::BackgroundMigration::DeleteDiffFiles, :migration, :sidekiq, sch .with(/SELECT n_dead_tup */) .and_return(threshold_query_result, normal_query_result) - expect(worker.should_wait_deadtuple_vacuum?).to be(true) + expect(worker.wait_for_deadtuple_vacuum?('merge_request_diff_files')).to be(true) end end end -- cgit v1.2.1 From a9886c7dd434d6936c455c9877f6c695cafebe0a Mon Sep 17 00:00:00 2001 From: Felipe Artur Date: Mon, 18 Feb 2019 11:51:44 -0300 Subject: Fix rubocop --- lib/gitlab/background_migration.rb | 2 +- .../background_migration/concerns/reschedulable.rb | 50 ------------------ .../background_migration/delete_diff_files.rb | 2 +- .../background_migration/helpers/reschedulable.rb | 59 ++++++++++++++++++++++ 4 files changed, 61 insertions(+), 52 deletions(-) delete mode 100644 lib/gitlab/background_migration/concerns/reschedulable.rb create mode 100644 lib/gitlab/background_migration/helpers/reschedulable.rb diff --git a/lib/gitlab/background_migration.rb b/lib/gitlab/background_migration.rb index b308e94bfa0..948488c844c 100644 --- a/lib/gitlab/background_migration.rb +++ b/lib/gitlab/background_migration.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -Dir[Rails.root.join("lib/gitlab/background_migration/concerns/*.rb")].each { |f| require f } +Dir[Rails.root.join("lib/gitlab/background_migration/helpers/*.rb")].each { |f| require f } module Gitlab module BackgroundMigration diff --git a/lib/gitlab/background_migration/concerns/reschedulable.rb b/lib/gitlab/background_migration/concerns/reschedulable.rb deleted file mode 100644 index fbf3d799743..00000000000 --- a/lib/gitlab/background_migration/concerns/reschedulable.rb +++ /dev/null @@ -1,50 +0,0 @@ -# frozen_string_literal: true - -module Gitlab - module BackgroundMigration - module Reschedulable - extend ActiveSupport::Concern - - def reschedule_if_needed(args, &block) - if should_reschedule? - BackgroundMigrationWorker.perform_in(vacuum_wait_time, self.class.name.demodulize, args) - else - yield - end - end - - # Override this on base class if you need a different reschedule condition - def should_reschedule? - raise NotImplementedError, "#{self.class} does not implement #{__method__}" - end - - def wait_for_deadtuple_vacuum?(table_name) - return false unless Gitlab::Database.postgresql? - - dead_tuples_count_for(table_name) >= dead_tuples_threshold - end - - def dead_tuples_count_for(table_name) - dead_tuple = - execute_statement("SELECT n_dead_tup FROM pg_stat_all_tables "\ - "WHERE relname = '#{table_name}'")[0] - - dead_tuple&.fetch('n_dead_tup', 0).to_i - end - - def execute_statement(sql) - ActiveRecord::Base.connection.execute(sql) - end - - # Override in subclass if you need a different dead tuple threshold - def dead_tuples_threshold - @dead_tuples_threshold ||= 50_000 - end - - # Override in subclass if you need a different vacuum wait time - def vacuum_wait_time - @vacuum_wait_time ||= 5.minutes - end - end - end -end diff --git a/lib/gitlab/background_migration/delete_diff_files.rb b/lib/gitlab/background_migration/delete_diff_files.rb index 0a7cbd5c30f..11851c23ee3 100644 --- a/lib/gitlab/background_migration/delete_diff_files.rb +++ b/lib/gitlab/background_migration/delete_diff_files.rb @@ -4,7 +4,7 @@ module Gitlab module BackgroundMigration class DeleteDiffFiles - include Reschedulable + include Helpers::Reschedulable class MergeRequestDiff < ActiveRecord::Base self.table_name = 'merge_request_diffs' diff --git a/lib/gitlab/background_migration/helpers/reschedulable.rb b/lib/gitlab/background_migration/helpers/reschedulable.rb new file mode 100644 index 00000000000..7810f2627c8 --- /dev/null +++ b/lib/gitlab/background_migration/helpers/reschedulable.rb @@ -0,0 +1,59 @@ +# frozen_string_literal: true + +module Gitlab + module BackgroundMigration + module Helpers + # == Reschedulable helper + # + # Allows background migrations to be reschedule if a condition is not met. + # + # Check DeleteDiffFiles migration which reschedules itself if dead tuple count + # on DB is not acceptable. + # + module Reschedulable + extend ActiveSupport::Concern + + def reschedule_if_needed(args, &block) + if should_reschedule? + BackgroundMigrationWorker.perform_in(vacuum_wait_time, self.class.name.demodulize, args) + else + yield + end + end + + # Override this on base class if you need a different reschedule condition + def should_reschedule? + raise NotImplementedError, "#{self.class} does not implement #{__method__}" + end + + def wait_for_deadtuple_vacuum?(table_name) + return false unless Gitlab::Database.postgresql? + + dead_tuples_count_for(table_name) >= dead_tuples_threshold + end + + def dead_tuples_count_for(table_name) + dead_tuple = + execute_statement("SELECT n_dead_tup FROM pg_stat_all_tables "\ + "WHERE relname = '#{table_name}'")[0] + + dead_tuple&.fetch('n_dead_tup', 0).to_i + end + + def execute_statement(sql) + ActiveRecord::Base.connection.execute(sql) + end + + # Override in subclass if you need a different dead tuple threshold + def dead_tuples_threshold + @dead_tuples_threshold ||= 50_000 + end + + # Override in subclass if you need a different vacuum wait time + def vacuum_wait_time + @vacuum_wait_time ||= 5.minutes + end + end + end + end +end -- cgit v1.2.1 From d88b44caad35136bc42f245162c99e8bae0a5912 Mon Sep 17 00:00:00 2001 From: Felipe Artur Date: Mon, 18 Feb 2019 12:00:14 -0300 Subject: Fix typo --- lib/gitlab/background_migration/helpers/reschedulable.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/gitlab/background_migration/helpers/reschedulable.rb b/lib/gitlab/background_migration/helpers/reschedulable.rb index 7810f2627c8..3b653059858 100644 --- a/lib/gitlab/background_migration/helpers/reschedulable.rb +++ b/lib/gitlab/background_migration/helpers/reschedulable.rb @@ -5,9 +5,9 @@ module Gitlab module Helpers # == Reschedulable helper # - # Allows background migrations to be reschedule if a condition is not met. + # Allows background migrations to be reschedule itself if a condition is not met. # - # Check DeleteDiffFiles migration which reschedules itself if dead tuple count + # For example, check DeleteDiffFiles migration which is rescheduled if dead tuple count # on DB is not acceptable. # module Reschedulable -- cgit v1.2.1 From cc7a44c8e130a8f3f753ba0ed32e45b0a6b0e6f7 Mon Sep 17 00:00:00 2001 From: Felipe Artur Date: Mon, 18 Feb 2019 17:43:16 -0300 Subject: Make migrations reschedulable --- .../background_migration/delete_diff_files.rb | 2 +- .../background_migration/helpers/reschedulable.rb | 8 ++-- .../background_migration/sync_issues_state_id.rb | 30 ++++++++++----- .../sync_merge_requests_state_id.rb | 34 ++++++++++------ .../schedule_sync_issuables_state_id_spec.rb | 45 ++++++++++++++++++++++ 5 files changed, 92 insertions(+), 27 deletions(-) diff --git a/lib/gitlab/background_migration/delete_diff_files.rb b/lib/gitlab/background_migration/delete_diff_files.rb index 11851c23ee3..4cb068eb71a 100644 --- a/lib/gitlab/background_migration/delete_diff_files.rb +++ b/lib/gitlab/background_migration/delete_diff_files.rb @@ -27,7 +27,7 @@ module Gitlab private - def should_reschedule? + def need_reschedule? wait_for_deadtuple_vacuum?(MergeRequestDiffFile.table_name) end diff --git a/lib/gitlab/background_migration/helpers/reschedulable.rb b/lib/gitlab/background_migration/helpers/reschedulable.rb index 3b653059858..6087181609e 100644 --- a/lib/gitlab/background_migration/helpers/reschedulable.rb +++ b/lib/gitlab/background_migration/helpers/reschedulable.rb @@ -14,7 +14,7 @@ module Gitlab extend ActiveSupport::Concern def reschedule_if_needed(args, &block) - if should_reschedule? + if need_reschedule? BackgroundMigrationWorker.perform_in(vacuum_wait_time, self.class.name.demodulize, args) else yield @@ -22,9 +22,9 @@ module Gitlab end # Override this on base class if you need a different reschedule condition - def should_reschedule? - raise NotImplementedError, "#{self.class} does not implement #{__method__}" - end + # def need_reschedule? + # raise NotImplementedError, "#{self.class} does not implement #{__method__}" + # end def wait_for_deadtuple_vacuum?(table_name) return false unless Gitlab::Database.postgresql? diff --git a/lib/gitlab/background_migration/sync_issues_state_id.rb b/lib/gitlab/background_migration/sync_issues_state_id.rb index 33b997c8533..f95c433c64c 100644 --- a/lib/gitlab/background_migration/sync_issues_state_id.rb +++ b/lib/gitlab/background_migration/sync_issues_state_id.rb @@ -4,19 +4,29 @@ module Gitlab module BackgroundMigration class SyncIssuesStateId + include Helpers::Reschedulable + def perform(start_id, end_id) Rails.logger.info("Issues - Populating state_id: #{start_id} - #{end_id}") - ActiveRecord::Base.connection.execute <<~SQL - UPDATE issues - SET state_id = - CASE state - WHEN 'opened' THEN 1 - WHEN 'closed' THEN 2 - END - WHERE state_id IS NULL - AND id BETWEEN #{start_id} AND #{end_id} - SQL + reschedule_if_needed([start_id, end_id]) do + ActiveRecord::Base.connection.execute <<~SQL + UPDATE issues + SET state_id = + CASE state + WHEN 'opened' THEN 1 + WHEN 'closed' THEN 2 + END + WHERE state_id IS NULL + AND id BETWEEN #{start_id} AND #{end_id} + SQL + end + end + + private + + def need_reschedule? + wait_for_deadtuple_vacuum?('issues') end end end diff --git a/lib/gitlab/background_migration/sync_merge_requests_state_id.rb b/lib/gitlab/background_migration/sync_merge_requests_state_id.rb index 923ceaeec54..5d92553f577 100644 --- a/lib/gitlab/background_migration/sync_merge_requests_state_id.rb +++ b/lib/gitlab/background_migration/sync_merge_requests_state_id.rb @@ -4,21 +4,31 @@ module Gitlab module BackgroundMigration class SyncMergeRequestsStateId + include Helpers::Reschedulable + def perform(start_id, end_id) Rails.logger.info("Merge Requests - Populating state_id: #{start_id} - #{end_id}") - ActiveRecord::Base.connection.execute <<~SQL - UPDATE merge_requests - SET state_id = - CASE state - WHEN 'opened' THEN 1 - WHEN 'closed' THEN 2 - WHEN 'merged' THEN 3 - WHEN 'locked' THEN 4 - END - WHERE state_id IS NULL - AND id BETWEEN #{start_id} AND #{end_id} - SQL + reschedule_if_needed([start_id, end_id]) do + ActiveRecord::Base.connection.execute <<~SQL + UPDATE merge_requests + SET state_id = + CASE state + WHEN 'opened' THEN 1 + WHEN 'closed' THEN 2 + WHEN 'merged' THEN 3 + WHEN 'locked' THEN 4 + END + WHERE state_id IS NULL + AND id BETWEEN #{start_id} AND #{end_id} + SQL + end + end + + private + + def need_reschedule? + wait_for_deadtuple_vacuum?('issues') end end end diff --git a/spec/migrations/schedule_sync_issuables_state_id_spec.rb b/spec/migrations/schedule_sync_issuables_state_id_spec.rb index a926ee38387..a746fb68c30 100644 --- a/spec/migrations/schedule_sync_issuables_state_id_spec.rb +++ b/spec/migrations/schedule_sync_issuables_state_id_spec.rb @@ -15,7 +15,40 @@ describe ScheduleSyncIssuablesStateId, :migration do @project = projects.create!(namespace_id: @group.id) end + shared_examples 'rescheduling migrations' do + before do + Sidekiq::Worker.clear_all + end + + it 'reschedules migrations when should wait for dead tuple vacuum' do + worker = worker_class.new + + Sidekiq::Testing.fake! do + allow(worker).to receive(:wait_for_deadtuple_vacuum?) { true } + + worker.perform(resource_1.id, resource_2.id) + + expect(worker_class.name.demodulize).to be_scheduled_delayed_migration(5.minutes, resource_1.id, resource_2.id) + expect(BackgroundMigrationWorker.jobs.size).to eq(1) + end + end + end + describe '#up' do + # it 'correctly schedules diff file deletion workers' do + # Sidekiq::Testing.fake! do + # Timecop.freeze do + # described_class.new.perform + + # expect(described_class::MIGRATION).to be_scheduled_delayed_migration(5.minutes, [1, 4, 5]) + + # expect(described_class::MIGRATION).to be_scheduled_delayed_migration(10.minutes, [6]) + + # expect(BackgroundMigrationWorker.jobs.size).to eq(2) + # end + # end + # end + context 'issues' do it 'migrates state column to integer' do opened_issue = issues.create!(description: 'first', state: 'opened') @@ -30,6 +63,12 @@ describe ScheduleSyncIssuablesStateId, :migration do expect(invalid_state_issue.reload.state_id).to be_nil expect(nil_state_issue.reload.state_id).to be_nil end + + it_behaves_like 'rescheduling migrations' do + let(:worker_class) { Gitlab::BackgroundMigration::SyncIssuesStateId } + let(:resource_1) { issues.create!(description: 'first', state: 'opened') } + let(:resource_2) { issues.create!(description: 'second', state: 'closed') } + end end context 'merge requests' do @@ -48,6 +87,12 @@ describe ScheduleSyncIssuablesStateId, :migration do expect(locked_merge_request.reload.state_id).to eq(MergeRequest.available_states[:locked]) expect(invalid_state_merge_request.reload.state_id).to be_nil end + + it_behaves_like 'rescheduling migrations' do + let(:worker_class) { Gitlab::BackgroundMigration::SyncMergeRequestsStateId } + let(:resource_1) { merge_requests.create!(state: 'opened', target_project_id: @project.id, target_branch: 'feature1', source_branch: 'master') } + let(:resource_2) { merge_requests.create!(state: 'closed', target_project_id: @project.id, target_branch: 'feature2', source_branch: 'master') } + end end end end -- cgit v1.2.1 From 52155d8cf8374e9184c2ae834cab761b7520db93 Mon Sep 17 00:00:00 2001 From: Felipe Artur Date: Tue, 19 Feb 2019 11:33:30 -0300 Subject: Add more specs and code improvements --- ...90214112022_schedule_sync_issuables_state_id.rb | 31 ++++++++----- .../background_migration/delete_diff_files.rb | 4 +- .../background_migration/helpers/reschedulable.rb | 45 +++++++++--------- .../background_migration/sync_issues_state_id.rb | 6 +-- .../sync_merge_requests_state_id.rb | 6 +-- .../schedule_sync_issuables_state_id_spec.rb | 53 +++++++++++++++------- 6 files changed, 89 insertions(+), 56 deletions(-) diff --git a/db/post_migrate/20190214112022_schedule_sync_issuables_state_id.rb b/db/post_migrate/20190214112022_schedule_sync_issuables_state_id.rb index d9b77d2f02c..898bad043ac 100644 --- a/db/post_migrate/20190214112022_schedule_sync_issuables_state_id.rb +++ b/db/post_migrate/20190214112022_schedule_sync_issuables_state_id.rb @@ -1,22 +1,22 @@ -# frozen_string_literal: true - -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - class ScheduleSyncIssuablesStateId < ActiveRecord::Migration[5.0] + # This migration schedules the sync of state_id for issues and merge requests + # which are converting the state column from string to integer. + # For more information check: https://gitlab.com/gitlab-org/gitlab-ce/issues/51789 + include Gitlab::Database::MigrationHelpers DOWNTIME = false - # 2019-02-12 Gitlab.com issuable numbers + # 2019-02-12 gitlab.com issuable numbers # issues count: 13587305 # merge requests count: 18925274 - # Using this 25000 as batch size should take around 26 hours + # + # Using 25000 as batch size should take around 26 hours # to migrate both issues and merge requests BATCH_SIZE = 25000 DELAY_INTERVAL = 5.minutes.to_i - ISSUE_MIGRATION = 'SyncIssuesStateId'.freeze - MERGE_REQUEST_MIGRATION = 'SyncMergeRequestsStateId'.freeze + ISSUES_MIGRATION = 'SyncIssuesStateId'.freeze + MERGE_REQUESTS_MIGRATION = 'SyncMergeRequestsStateId'.freeze class Issue < ActiveRecord::Base include EachBatch @@ -32,8 +32,17 @@ class ScheduleSyncIssuablesStateId < ActiveRecord::Migration[5.0] def up Sidekiq::Worker.skipping_transaction_check do - queue_background_migration_jobs_by_range_at_intervals(Issue.where(state_id: nil), ISSUE_MIGRATION, DELAY_INTERVAL, batch_size: BATCH_SIZE) - queue_background_migration_jobs_by_range_at_intervals(MergeRequest.where(state_id: nil), MERGE_REQUEST_MIGRATION, DELAY_INTERVAL, batch_size: BATCH_SIZE) + queue_background_migration_jobs_by_range_at_intervals(Issue.where(state_id: nil), + ISSUES_MIGRATION, + DELAY_INTERVAL, + batch_size: BATCH_SIZE + ) + + queue_background_migration_jobs_by_range_at_intervals(MergeRequest.where(state_id: nil), + MERGE_REQUESTS_MIGRATION, + DELAY_INTERVAL, + batch_size: BATCH_SIZE + ) end end diff --git a/lib/gitlab/background_migration/delete_diff_files.rb b/lib/gitlab/background_migration/delete_diff_files.rb index 4cb068eb71a..0066faa23dd 100644 --- a/lib/gitlab/background_migration/delete_diff_files.rb +++ b/lib/gitlab/background_migration/delete_diff_files.rb @@ -20,14 +20,14 @@ module Gitlab def perform(ids) @ids = ids - reschedule_if_needed([ids]) do + reschedule_if_needed(ids) do prune_diff_files end end private - def need_reschedule? + def should_reschedule? wait_for_deadtuple_vacuum?(MergeRequestDiffFile.table_name) end diff --git a/lib/gitlab/background_migration/helpers/reschedulable.rb b/lib/gitlab/background_migration/helpers/reschedulable.rb index 6087181609e..60ab62cd973 100644 --- a/lib/gitlab/background_migration/helpers/reschedulable.rb +++ b/lib/gitlab/background_migration/helpers/reschedulable.rb @@ -5,7 +5,8 @@ module Gitlab module Helpers # == Reschedulable helper # - # Allows background migrations to be reschedule itself if a condition is not met. + # Allows background migrations to be rescheduled if a condition is met, + # the condition should be overridden in classes in #should_reschedule? method. # # For example, check DeleteDiffFiles migration which is rescheduled if dead tuple count # on DB is not acceptable. @@ -13,18 +14,34 @@ module Gitlab module Reschedulable extend ActiveSupport::Concern - def reschedule_if_needed(args, &block) - if need_reschedule? - BackgroundMigrationWorker.perform_in(vacuum_wait_time, self.class.name.demodulize, args) + # Use this method to perform the background migration and it will be rescheduled + # if #should_reschedule? returns true. + def reschedule_if_needed(*args, &block) + if should_reschedule? + BackgroundMigrationWorker.perform_in(wait_time, self.class.name.demodulize, args) else yield end end # Override this on base class if you need a different reschedule condition - # def need_reschedule? - # raise NotImplementedError, "#{self.class} does not implement #{__method__}" - # end + def should_reschedule? + raise NotImplementedError, "#{self.class} does not implement #{__method__}" + end + + # Override in subclass if a different dead tuple threshold + def dead_tuples_threshold + @dead_tuples_threshold ||= 50_000 + end + + # Override in subclass if a different wait time + def wait_time + @wait_time ||= 5.minutes + end + + def execute_statement(sql) + ActiveRecord::Base.connection.execute(sql) + end def wait_for_deadtuple_vacuum?(table_name) return false unless Gitlab::Database.postgresql? @@ -39,20 +56,6 @@ module Gitlab dead_tuple&.fetch('n_dead_tup', 0).to_i end - - def execute_statement(sql) - ActiveRecord::Base.connection.execute(sql) - end - - # Override in subclass if you need a different dead tuple threshold - def dead_tuples_threshold - @dead_tuples_threshold ||= 50_000 - end - - # Override in subclass if you need a different vacuum wait time - def vacuum_wait_time - @vacuum_wait_time ||= 5.minutes - end end end end diff --git a/lib/gitlab/background_migration/sync_issues_state_id.rb b/lib/gitlab/background_migration/sync_issues_state_id.rb index f95c433c64c..50841c3fe4d 100644 --- a/lib/gitlab/background_migration/sync_issues_state_id.rb +++ b/lib/gitlab/background_migration/sync_issues_state_id.rb @@ -9,8 +9,8 @@ module Gitlab def perform(start_id, end_id) Rails.logger.info("Issues - Populating state_id: #{start_id} - #{end_id}") - reschedule_if_needed([start_id, end_id]) do - ActiveRecord::Base.connection.execute <<~SQL + reschedule_if_needed(start_id, end_id) do + execute_statement <<~SQL UPDATE issues SET state_id = CASE state @@ -25,7 +25,7 @@ module Gitlab private - def need_reschedule? + def should_reschedule? wait_for_deadtuple_vacuum?('issues') end end diff --git a/lib/gitlab/background_migration/sync_merge_requests_state_id.rb b/lib/gitlab/background_migration/sync_merge_requests_state_id.rb index 5d92553f577..4cf8e993c52 100644 --- a/lib/gitlab/background_migration/sync_merge_requests_state_id.rb +++ b/lib/gitlab/background_migration/sync_merge_requests_state_id.rb @@ -9,8 +9,8 @@ module Gitlab def perform(start_id, end_id) Rails.logger.info("Merge Requests - Populating state_id: #{start_id} - #{end_id}") - reschedule_if_needed([start_id, end_id]) do - ActiveRecord::Base.connection.execute <<~SQL + reschedule_if_needed(start_id, end_id) do + execute_statement <<~SQL UPDATE merge_requests SET state_id = CASE state @@ -27,7 +27,7 @@ module Gitlab private - def need_reschedule? + def should_reschedule? wait_for_deadtuple_vacuum?('issues') end end diff --git a/spec/migrations/schedule_sync_issuables_state_id_spec.rb b/spec/migrations/schedule_sync_issuables_state_id_spec.rb index a746fb68c30..6c4c31ae554 100644 --- a/spec/migrations/schedule_sync_issuables_state_id_spec.rb +++ b/spec/migrations/schedule_sync_issuables_state_id_spec.rb @@ -15,6 +15,25 @@ describe ScheduleSyncIssuablesStateId, :migration do @project = projects.create!(namespace_id: @group.id) end + shared_examples 'scheduling migrations' do + before do + Sidekiq::Worker.clear_all + stub_const("#{described_class.name}::BATCH_SIZE", 2) + end + + it 'correctly schedules issuable sync background migration' do + Sidekiq::Testing.fake! do + Timecop.freeze do + migrate! + + expect(migration).to be_scheduled_delayed_migration(5.minutes, resource_1.id, resource_2.id) + expect(migration).to be_scheduled_delayed_migration(10.minutes, resource_3.id, resource_4.id) + expect(BackgroundMigrationWorker.jobs.size).to eq(2) + end + end + end + end + shared_examples 'rescheduling migrations' do before do Sidekiq::Worker.clear_all @@ -35,20 +54,6 @@ describe ScheduleSyncIssuablesStateId, :migration do end describe '#up' do - # it 'correctly schedules diff file deletion workers' do - # Sidekiq::Testing.fake! do - # Timecop.freeze do - # described_class.new.perform - - # expect(described_class::MIGRATION).to be_scheduled_delayed_migration(5.minutes, [1, 4, 5]) - - # expect(described_class::MIGRATION).to be_scheduled_delayed_migration(10.minutes, [6]) - - # expect(BackgroundMigrationWorker.jobs.size).to eq(2) - # end - # end - # end - context 'issues' do it 'migrates state column to integer' do opened_issue = issues.create!(description: 'first', state: 'opened') @@ -64,10 +69,18 @@ describe ScheduleSyncIssuablesStateId, :migration do expect(nil_state_issue.reload.state_id).to be_nil end + it_behaves_like 'scheduling migrations' do + let(:migration) { described_class::ISSUES_MIGRATION } + let!(:resource_1) { issues.create!(description: 'first', state: 'opened') } + let!(:resource_2) { issues.create!(description: 'second', state: 'closed') } + let!(:resource_3) { issues.create!(description: 'third', state: 'closed') } + let!(:resource_4) { issues.create!(description: 'fourth', state: 'closed') } + end + it_behaves_like 'rescheduling migrations' do let(:worker_class) { Gitlab::BackgroundMigration::SyncIssuesStateId } - let(:resource_1) { issues.create!(description: 'first', state: 'opened') } - let(:resource_2) { issues.create!(description: 'second', state: 'closed') } + let!(:resource_1) { issues.create!(description: 'first', state: 'opened') } + let!(:resource_2) { issues.create!(description: 'second', state: 'closed') } end end @@ -88,6 +101,14 @@ describe ScheduleSyncIssuablesStateId, :migration do expect(invalid_state_merge_request.reload.state_id).to be_nil end + it_behaves_like 'scheduling migrations' do + let(:migration) { described_class::MERGE_REQUESTS_MIGRATION } + let!(:resource_1) { merge_requests.create!(state: 'opened', target_project_id: @project.id, target_branch: 'feature1', source_branch: 'master') } + let!(:resource_2) { merge_requests.create!(state: 'closed', target_project_id: @project.id, target_branch: 'feature2', source_branch: 'master') } + let!(:resource_3) { merge_requests.create!(state: 'merged', target_project_id: @project.id, target_branch: 'feature3', source_branch: 'master') } + let!(:resource_4) { merge_requests.create!(state: 'locked', target_project_id: @project.id, target_branch: 'feature4', source_branch: 'master') } + end + it_behaves_like 'rescheduling migrations' do let(:worker_class) { Gitlab::BackgroundMigration::SyncMergeRequestsStateId } let(:resource_1) { merge_requests.create!(state: 'opened', target_project_id: @project.id, target_branch: 'feature1', source_branch: 'master') } -- cgit v1.2.1 From 7bd066a1fa51018211e26ca0c5624aecbc364a66 Mon Sep 17 00:00:00 2001 From: Felipe Artur Date: Tue, 19 Feb 2019 14:00:53 -0300 Subject: Address review comments --- ...90214112022_schedule_sync_issuables_state_id.rb | 28 +++++----- lib/gitlab/background_migration.rb | 2 - .../background_migration/delete_diff_files.rb | 37 ++++++++++--- .../background_migration/helpers/reschedulable.rb | 62 ---------------------- lib/gitlab/background_migration/reschedulable.rb | 60 +++++++++++++++++++++ .../background_migration/sync_issues_state_id.rb | 2 +- .../sync_merge_requests_state_id.rb | 2 +- .../background_migration/delete_diff_files_spec.rb | 10 ++-- 8 files changed, 113 insertions(+), 90 deletions(-) delete mode 100644 lib/gitlab/background_migration/helpers/reschedulable.rb create mode 100644 lib/gitlab/background_migration/reschedulable.rb diff --git a/db/post_migrate/20190214112022_schedule_sync_issuables_state_id.rb b/db/post_migrate/20190214112022_schedule_sync_issuables_state_id.rb index 898bad043ac..2167f19e022 100644 --- a/db/post_migrate/20190214112022_schedule_sync_issuables_state_id.rb +++ b/db/post_migrate/20190214112022_schedule_sync_issuables_state_id.rb @@ -18,6 +18,8 @@ class ScheduleSyncIssuablesStateId < ActiveRecord::Migration[5.0] ISSUES_MIGRATION = 'SyncIssuesStateId'.freeze MERGE_REQUESTS_MIGRATION = 'SyncMergeRequestsStateId'.freeze + disable_ddl_transaction! + class Issue < ActiveRecord::Base include EachBatch @@ -31,19 +33,19 @@ class ScheduleSyncIssuablesStateId < ActiveRecord::Migration[5.0] end def up - Sidekiq::Worker.skipping_transaction_check do - queue_background_migration_jobs_by_range_at_intervals(Issue.where(state_id: nil), - ISSUES_MIGRATION, - DELAY_INTERVAL, - batch_size: BATCH_SIZE - ) - - queue_background_migration_jobs_by_range_at_intervals(MergeRequest.where(state_id: nil), - MERGE_REQUESTS_MIGRATION, - DELAY_INTERVAL, - batch_size: BATCH_SIZE - ) - end + queue_background_migration_jobs_by_range_at_intervals( + Issue.where(state_id: nil), + ISSUES_MIGRATION, + DELAY_INTERVAL, + batch_size: BATCH_SIZE + ) + + queue_background_migration_jobs_by_range_at_intervals( + MergeRequest.where(state_id: nil), + MERGE_REQUESTS_MIGRATION, + DELAY_INTERVAL, + batch_size: BATCH_SIZE + ) end def down diff --git a/lib/gitlab/background_migration.rb b/lib/gitlab/background_migration.rb index 948488c844c..5251e0fadf9 100644 --- a/lib/gitlab/background_migration.rb +++ b/lib/gitlab/background_migration.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -Dir[Rails.root.join("lib/gitlab/background_migration/helpers/*.rb")].each { |f| require f } - module Gitlab module BackgroundMigration def self.queue diff --git a/lib/gitlab/background_migration/delete_diff_files.rb b/lib/gitlab/background_migration/delete_diff_files.rb index 0066faa23dd..664ead1af44 100644 --- a/lib/gitlab/background_migration/delete_diff_files.rb +++ b/lib/gitlab/background_migration/delete_diff_files.rb @@ -4,8 +4,6 @@ module Gitlab module BackgroundMigration class DeleteDiffFiles - include Helpers::Reschedulable - class MergeRequestDiff < ActiveRecord::Base self.table_name = 'merge_request_diffs' @@ -17,24 +15,47 @@ module Gitlab self.table_name = 'merge_request_diff_files' end + DEAD_TUPLES_THRESHOLD = 50_000 + VACUUM_WAIT_TIME = 5.minutes + def perform(ids) @ids = ids - reschedule_if_needed(ids) do - prune_diff_files + # We should reschedule until deadtuples get in a desirable + # state (e.g. < 50_000). That may take more than one reschedule. + # + if should_wait_deadtuple_vacuum? + reschedule + return end + + prune_diff_files + end + + def should_wait_deadtuple_vacuum? + return false unless Gitlab::Database.postgresql? + + diff_files_dead_tuples_count >= DEAD_TUPLES_THRESHOLD end private - def should_reschedule? - wait_for_deadtuple_vacuum?(MergeRequestDiffFile.table_name) + def reschedule + BackgroundMigrationWorker.perform_in(VACUUM_WAIT_TIME, self.class.name.demodulize, [@ids]) end def diffs_collection MergeRequestDiff.where(id: @ids) end + def diff_files_dead_tuples_count + dead_tuple = + execute_statement("SELECT n_dead_tup FROM pg_stat_all_tables "\ + "WHERE relname = 'merge_request_diff_files'")[0] + + dead_tuple&.fetch('n_dead_tup', 0).to_i + end + def prune_diff_files removed = 0 updated = 0 @@ -48,6 +69,10 @@ module Gitlab "updated #{updated} merge_request_diffs rows") end + def execute_statement(sql) + ActiveRecord::Base.connection.execute(sql) + end + def log_info(message) Rails.logger.info("BackgroundMigration::DeleteDiffFiles - #{message}") end diff --git a/lib/gitlab/background_migration/helpers/reschedulable.rb b/lib/gitlab/background_migration/helpers/reschedulable.rb deleted file mode 100644 index 60ab62cd973..00000000000 --- a/lib/gitlab/background_migration/helpers/reschedulable.rb +++ /dev/null @@ -1,62 +0,0 @@ -# frozen_string_literal: true - -module Gitlab - module BackgroundMigration - module Helpers - # == Reschedulable helper - # - # Allows background migrations to be rescheduled if a condition is met, - # the condition should be overridden in classes in #should_reschedule? method. - # - # For example, check DeleteDiffFiles migration which is rescheduled if dead tuple count - # on DB is not acceptable. - # - module Reschedulable - extend ActiveSupport::Concern - - # Use this method to perform the background migration and it will be rescheduled - # if #should_reschedule? returns true. - def reschedule_if_needed(*args, &block) - if should_reschedule? - BackgroundMigrationWorker.perform_in(wait_time, self.class.name.demodulize, args) - else - yield - end - end - - # Override this on base class if you need a different reschedule condition - def should_reschedule? - raise NotImplementedError, "#{self.class} does not implement #{__method__}" - end - - # Override in subclass if a different dead tuple threshold - def dead_tuples_threshold - @dead_tuples_threshold ||= 50_000 - end - - # Override in subclass if a different wait time - def wait_time - @wait_time ||= 5.minutes - end - - def execute_statement(sql) - ActiveRecord::Base.connection.execute(sql) - end - - def wait_for_deadtuple_vacuum?(table_name) - return false unless Gitlab::Database.postgresql? - - dead_tuples_count_for(table_name) >= dead_tuples_threshold - end - - def dead_tuples_count_for(table_name) - dead_tuple = - execute_statement("SELECT n_dead_tup FROM pg_stat_all_tables "\ - "WHERE relname = '#{table_name}'")[0] - - dead_tuple&.fetch('n_dead_tup', 0).to_i - end - end - end - end -end diff --git a/lib/gitlab/background_migration/reschedulable.rb b/lib/gitlab/background_migration/reschedulable.rb new file mode 100644 index 00000000000..3d6781c07c0 --- /dev/null +++ b/lib/gitlab/background_migration/reschedulable.rb @@ -0,0 +1,60 @@ +# frozen_string_literal: true + +module Gitlab + module BackgroundMigration + # == Reschedulable helper + # + # Allows background migrations to be rescheduled if a condition is met, + # the condition should be overridden in classes in #should_reschedule? method. + # + # For example, check DeleteDiffFiles migration which is rescheduled if dead tuple count + # on DB is not acceptable. + # + module Reschedulable + extend ActiveSupport::Concern + + # Use this method to perform the background migration and it will be rescheduled + # if #should_reschedule? returns true. + def reschedule_if_needed(*args, &block) + if should_reschedule? + BackgroundMigrationWorker.perform_in(wait_time, self.class.name.demodulize, args) + else + yield + end + end + + # Override this on base class if you need a different reschedule condition + def should_reschedule? + raise NotImplementedError, "#{self.class} does not implement #{__method__}" + end + + # Override in subclass if a different dead tuple threshold + def dead_tuples_threshold + @dead_tuples_threshold ||= 50_000 + end + + # Override in subclass if a different wait time + def wait_time + @wait_time ||= 5.minutes + end + + def execute_statement(sql) + ActiveRecord::Base.connection.execute(sql) + end + + def wait_for_deadtuple_vacuum?(table_name) + return false unless Gitlab::Database.postgresql? + + dead_tuples_count_for(table_name) >= dead_tuples_threshold + end + + def dead_tuples_count_for(table_name) + dead_tuple = + execute_statement("SELECT n_dead_tup FROM pg_stat_all_tables "\ + "WHERE relname = '#{table_name}'")[0] + + dead_tuple&.fetch('n_dead_tup', 0).to_i + end + end + end +end diff --git a/lib/gitlab/background_migration/sync_issues_state_id.rb b/lib/gitlab/background_migration/sync_issues_state_id.rb index 50841c3fe4d..053d154cef8 100644 --- a/lib/gitlab/background_migration/sync_issues_state_id.rb +++ b/lib/gitlab/background_migration/sync_issues_state_id.rb @@ -4,7 +4,7 @@ module Gitlab module BackgroundMigration class SyncIssuesStateId - include Helpers::Reschedulable + include Reschedulable def perform(start_id, end_id) Rails.logger.info("Issues - Populating state_id: #{start_id} - #{end_id}") diff --git a/lib/gitlab/background_migration/sync_merge_requests_state_id.rb b/lib/gitlab/background_migration/sync_merge_requests_state_id.rb index 4cf8e993c52..a94529aaf5c 100644 --- a/lib/gitlab/background_migration/sync_merge_requests_state_id.rb +++ b/lib/gitlab/background_migration/sync_merge_requests_state_id.rb @@ -4,7 +4,7 @@ module Gitlab module BackgroundMigration class SyncMergeRequestsStateId - include Helpers::Reschedulable + include Reschedulable def perform(start_id, end_id) Rails.logger.info("Merge Requests - Populating state_id: #{start_id} - #{end_id}") diff --git a/spec/lib/gitlab/background_migration/delete_diff_files_spec.rb b/spec/lib/gitlab/background_migration/delete_diff_files_spec.rb index 690881ab59b..27281333348 100644 --- a/spec/lib/gitlab/background_migration/delete_diff_files_spec.rb +++ b/spec/lib/gitlab/background_migration/delete_diff_files_spec.rb @@ -40,14 +40,14 @@ describe Gitlab::BackgroundMigration::DeleteDiffFiles, :migration, :sidekiq, sch end end - it 'reschedules itself when should wait for dead tuple vacuum' do + it 'reschedules itself when should_wait_deadtuple_vacuum' do merge_request = create(:merge_request, :merged) first_diff = merge_request.merge_request_diff second_diff = merge_request.create_merge_request_diff Sidekiq::Testing.fake! do worker = described_class.new - allow(worker).to receive(:wait_for_deadtuple_vacuum?) { true } + allow(worker).to receive(:should_wait_deadtuple_vacuum?) { true } worker.perform([first_diff.id, second_diff.id]) @@ -57,10 +57,10 @@ describe Gitlab::BackgroundMigration::DeleteDiffFiles, :migration, :sidekiq, sch end end - describe '#wait_for_deadtuple_vacuum?' do + describe '#should_wait_deadtuple_vacuum?' do it 'returns true when hitting merge_request_diff_files hits DEAD_TUPLES_THRESHOLD', :postgresql do worker = described_class.new - threshold_query_result = [{ "n_dead_tup" => 50_000 }] + threshold_query_result = [{ "n_dead_tup" => described_class::DEAD_TUPLES_THRESHOLD.to_s }] normal_query_result = [{ "n_dead_tup" => '3' }] allow(worker) @@ -68,7 +68,7 @@ describe Gitlab::BackgroundMigration::DeleteDiffFiles, :migration, :sidekiq, sch .with(/SELECT n_dead_tup */) .and_return(threshold_query_result, normal_query_result) - expect(worker.wait_for_deadtuple_vacuum?('merge_request_diff_files')).to be(true) + expect(worker.should_wait_deadtuple_vacuum?).to be(true) end end end -- cgit v1.2.1 From 294c5c41beaac1fbc60c67df2c8745f7583544a1 Mon Sep 17 00:00:00 2001 From: Felipe Artur Date: Fri, 1 Mar 2019 16:24:47 -0300 Subject: Remove auto vacuum logic, decrease batch size and interval --- ...90214112022_schedule_sync_issuables_state_id.rb | 14 ++--- lib/gitlab/background_migration/reschedulable.rb | 60 ---------------------- .../background_migration/sync_issues_state_id.rb | 30 ++++------- .../sync_merge_requests_state_id.rb | 34 +++++------- .../schedule_sync_issuables_state_id_spec.rb | 35 +------------ 5 files changed, 32 insertions(+), 141 deletions(-) delete mode 100644 lib/gitlab/background_migration/reschedulable.rb diff --git a/db/post_migrate/20190214112022_schedule_sync_issuables_state_id.rb b/db/post_migrate/20190214112022_schedule_sync_issuables_state_id.rb index 2167f19e022..6edb0bf2d5e 100644 --- a/db/post_migrate/20190214112022_schedule_sync_issuables_state_id.rb +++ b/db/post_migrate/20190214112022_schedule_sync_issuables_state_id.rb @@ -11,10 +11,12 @@ class ScheduleSyncIssuablesStateId < ActiveRecord::Migration[5.0] # issues count: 13587305 # merge requests count: 18925274 # - # Using 25000 as batch size should take around 26 hours - # to migrate both issues and merge requests - BATCH_SIZE = 25000 - DELAY_INTERVAL = 5.minutes.to_i + # Using 5000 as batch size and 115 seconds interval will give: + # 2718 jobs for issues - taking ~86 hours + # 3786 jobs for merge requests - taking ~120 hours + # + BATCH_SIZE = 5000 + DELAY_INTERVAL = 120.seconds.to_i ISSUES_MIGRATION = 'SyncIssuesStateId'.freeze MERGE_REQUESTS_MIGRATION = 'SyncMergeRequestsStateId'.freeze @@ -34,14 +36,14 @@ class ScheduleSyncIssuablesStateId < ActiveRecord::Migration[5.0] def up queue_background_migration_jobs_by_range_at_intervals( - Issue.where(state_id: nil), + Issue.all, ISSUES_MIGRATION, DELAY_INTERVAL, batch_size: BATCH_SIZE ) queue_background_migration_jobs_by_range_at_intervals( - MergeRequest.where(state_id: nil), + MergeRequest.all, MERGE_REQUESTS_MIGRATION, DELAY_INTERVAL, batch_size: BATCH_SIZE diff --git a/lib/gitlab/background_migration/reschedulable.rb b/lib/gitlab/background_migration/reschedulable.rb deleted file mode 100644 index 3d6781c07c0..00000000000 --- a/lib/gitlab/background_migration/reschedulable.rb +++ /dev/null @@ -1,60 +0,0 @@ -# frozen_string_literal: true - -module Gitlab - module BackgroundMigration - # == Reschedulable helper - # - # Allows background migrations to be rescheduled if a condition is met, - # the condition should be overridden in classes in #should_reschedule? method. - # - # For example, check DeleteDiffFiles migration which is rescheduled if dead tuple count - # on DB is not acceptable. - # - module Reschedulable - extend ActiveSupport::Concern - - # Use this method to perform the background migration and it will be rescheduled - # if #should_reschedule? returns true. - def reschedule_if_needed(*args, &block) - if should_reschedule? - BackgroundMigrationWorker.perform_in(wait_time, self.class.name.demodulize, args) - else - yield - end - end - - # Override this on base class if you need a different reschedule condition - def should_reschedule? - raise NotImplementedError, "#{self.class} does not implement #{__method__}" - end - - # Override in subclass if a different dead tuple threshold - def dead_tuples_threshold - @dead_tuples_threshold ||= 50_000 - end - - # Override in subclass if a different wait time - def wait_time - @wait_time ||= 5.minutes - end - - def execute_statement(sql) - ActiveRecord::Base.connection.execute(sql) - end - - def wait_for_deadtuple_vacuum?(table_name) - return false unless Gitlab::Database.postgresql? - - dead_tuples_count_for(table_name) >= dead_tuples_threshold - end - - def dead_tuples_count_for(table_name) - dead_tuple = - execute_statement("SELECT n_dead_tup FROM pg_stat_all_tables "\ - "WHERE relname = '#{table_name}'")[0] - - dead_tuple&.fetch('n_dead_tup', 0).to_i - end - end - end -end diff --git a/lib/gitlab/background_migration/sync_issues_state_id.rb b/lib/gitlab/background_migration/sync_issues_state_id.rb index 053d154cef8..33b997c8533 100644 --- a/lib/gitlab/background_migration/sync_issues_state_id.rb +++ b/lib/gitlab/background_migration/sync_issues_state_id.rb @@ -4,29 +4,19 @@ module Gitlab module BackgroundMigration class SyncIssuesStateId - include Reschedulable - def perform(start_id, end_id) Rails.logger.info("Issues - Populating state_id: #{start_id} - #{end_id}") - reschedule_if_needed(start_id, end_id) do - execute_statement <<~SQL - UPDATE issues - SET state_id = - CASE state - WHEN 'opened' THEN 1 - WHEN 'closed' THEN 2 - END - WHERE state_id IS NULL - AND id BETWEEN #{start_id} AND #{end_id} - SQL - end - end - - private - - def should_reschedule? - wait_for_deadtuple_vacuum?('issues') + ActiveRecord::Base.connection.execute <<~SQL + UPDATE issues + SET state_id = + CASE state + WHEN 'opened' THEN 1 + WHEN 'closed' THEN 2 + END + WHERE state_id IS NULL + AND id BETWEEN #{start_id} AND #{end_id} + SQL end end end diff --git a/lib/gitlab/background_migration/sync_merge_requests_state_id.rb b/lib/gitlab/background_migration/sync_merge_requests_state_id.rb index a94529aaf5c..923ceaeec54 100644 --- a/lib/gitlab/background_migration/sync_merge_requests_state_id.rb +++ b/lib/gitlab/background_migration/sync_merge_requests_state_id.rb @@ -4,31 +4,21 @@ module Gitlab module BackgroundMigration class SyncMergeRequestsStateId - include Reschedulable - def perform(start_id, end_id) Rails.logger.info("Merge Requests - Populating state_id: #{start_id} - #{end_id}") - reschedule_if_needed(start_id, end_id) do - execute_statement <<~SQL - UPDATE merge_requests - SET state_id = - CASE state - WHEN 'opened' THEN 1 - WHEN 'closed' THEN 2 - WHEN 'merged' THEN 3 - WHEN 'locked' THEN 4 - END - WHERE state_id IS NULL - AND id BETWEEN #{start_id} AND #{end_id} - SQL - end - end - - private - - def should_reschedule? - wait_for_deadtuple_vacuum?('issues') + ActiveRecord::Base.connection.execute <<~SQL + UPDATE merge_requests + SET state_id = + CASE state + WHEN 'opened' THEN 1 + WHEN 'closed' THEN 2 + WHEN 'merged' THEN 3 + WHEN 'locked' THEN 4 + END + WHERE state_id IS NULL + AND id BETWEEN #{start_id} AND #{end_id} + SQL end end end diff --git a/spec/migrations/schedule_sync_issuables_state_id_spec.rb b/spec/migrations/schedule_sync_issuables_state_id_spec.rb index 6c4c31ae554..6b1ea804342 100644 --- a/spec/migrations/schedule_sync_issuables_state_id_spec.rb +++ b/spec/migrations/schedule_sync_issuables_state_id_spec.rb @@ -26,33 +26,14 @@ describe ScheduleSyncIssuablesStateId, :migration do Timecop.freeze do migrate! - expect(migration).to be_scheduled_delayed_migration(5.minutes, resource_1.id, resource_2.id) - expect(migration).to be_scheduled_delayed_migration(10.minutes, resource_3.id, resource_4.id) + expect(migration).to be_scheduled_delayed_migration(120.seconds, resource_1.id, resource_2.id) + expect(migration).to be_scheduled_delayed_migration(240.seconds, resource_3.id, resource_4.id) expect(BackgroundMigrationWorker.jobs.size).to eq(2) end end end end - shared_examples 'rescheduling migrations' do - before do - Sidekiq::Worker.clear_all - end - - it 'reschedules migrations when should wait for dead tuple vacuum' do - worker = worker_class.new - - Sidekiq::Testing.fake! do - allow(worker).to receive(:wait_for_deadtuple_vacuum?) { true } - - worker.perform(resource_1.id, resource_2.id) - - expect(worker_class.name.demodulize).to be_scheduled_delayed_migration(5.minutes, resource_1.id, resource_2.id) - expect(BackgroundMigrationWorker.jobs.size).to eq(1) - end - end - end - describe '#up' do context 'issues' do it 'migrates state column to integer' do @@ -76,12 +57,6 @@ describe ScheduleSyncIssuablesStateId, :migration do let!(:resource_3) { issues.create!(description: 'third', state: 'closed') } let!(:resource_4) { issues.create!(description: 'fourth', state: 'closed') } end - - it_behaves_like 'rescheduling migrations' do - let(:worker_class) { Gitlab::BackgroundMigration::SyncIssuesStateId } - let!(:resource_1) { issues.create!(description: 'first', state: 'opened') } - let!(:resource_2) { issues.create!(description: 'second', state: 'closed') } - end end context 'merge requests' do @@ -108,12 +83,6 @@ describe ScheduleSyncIssuablesStateId, :migration do let!(:resource_3) { merge_requests.create!(state: 'merged', target_project_id: @project.id, target_branch: 'feature3', source_branch: 'master') } let!(:resource_4) { merge_requests.create!(state: 'locked', target_project_id: @project.id, target_branch: 'feature4', source_branch: 'master') } end - - it_behaves_like 'rescheduling migrations' do - let(:worker_class) { Gitlab::BackgroundMigration::SyncMergeRequestsStateId } - let(:resource_1) { merge_requests.create!(state: 'opened', target_project_id: @project.id, target_branch: 'feature1', source_branch: 'master') } - let(:resource_2) { merge_requests.create!(state: 'closed', target_project_id: @project.id, target_branch: 'feature2', source_branch: 'master') } - end end end end -- cgit v1.2.1 From e6e9c10ee1be86301db02cbf7d0e833b2ef6e073 Mon Sep 17 00:00:00 2001 From: Paul Slaughter Date: Tue, 26 Feb 2019 08:43:43 -0600 Subject: Fix XSS in resolve conflicts form The issue arose when the branch name contained Vue template JavaScript. The fix is to use `v-pre` which disables Vue compilation in a template. --- .../merge_requests/conflicts/_submit_form.html.haml | 2 +- .../security-56927-xss-resolve-conflicts-branch-name.yml | 5 +++++ .../merge_request/user_resolves_conflicts_spec.rb | 15 +++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 changelogs/unreleased/security-56927-xss-resolve-conflicts-branch-name.yml diff --git a/app/views/projects/merge_requests/conflicts/_submit_form.html.haml b/app/views/projects/merge_requests/conflicts/_submit_form.html.haml index 8181267184a..55c89f137c5 100644 --- a/app/views/projects/merge_requests/conflicts/_submit_form.html.haml +++ b/app/views/projects/merge_requests/conflicts/_submit_form.html.haml @@ -6,7 +6,7 @@ .form-group.row .col-md-4 %h4= _('Resolve conflicts on source branch') - .resolve-info + .resolve-info{ "v-pre": true } = translation.html_safe .col-md-8 %label.label-bold{ "for" => "commit-message" } diff --git a/changelogs/unreleased/security-56927-xss-resolve-conflicts-branch-name.yml b/changelogs/unreleased/security-56927-xss-resolve-conflicts-branch-name.yml new file mode 100644 index 00000000000..f92d2c0dcb1 --- /dev/null +++ b/changelogs/unreleased/security-56927-xss-resolve-conflicts-branch-name.yml @@ -0,0 +1,5 @@ +--- +title: Fix XSS in resolve conflicts form +merge_request: +author: +type: security diff --git a/spec/features/merge_request/user_resolves_conflicts_spec.rb b/spec/features/merge_request/user_resolves_conflicts_spec.rb index 16c058ab6bd..8fd44b87e5a 100644 --- a/spec/features/merge_request/user_resolves_conflicts_spec.rb +++ b/spec/features/merge_request/user_resolves_conflicts_spec.rb @@ -164,6 +164,21 @@ describe 'Merge request > User resolves conflicts', :js do expect(page).to have_content('Gregor Samsa woke from troubled dreams') end end + + context "with malicious branch name" do + let(:bad_branch_name) { "malicious-branch-{{toString.constructor('alert(/xss/)')()}}" } + let(:branch) { project.repository.create_branch(bad_branch_name, 'conflict-resolvable') } + let(:merge_request) { create_merge_request(branch.name) } + + before do + visit project_merge_request_path(project, merge_request) + click_link('conflicts', href: %r{/conflicts\Z}) + end + + it "renders bad name without xss issues" do + expect(find('.resolve-conflicts-form .resolve-info')).to have_content(bad_branch_name) + end + end end UNRESOLVABLE_CONFLICTS = { -- cgit v1.2.1 From dae55efc640f4fc9a3e41a30ffc4725fdb3c206f Mon Sep 17 00:00:00 2001 From: Natalia Tepluhina Date: Tue, 12 Mar 2019 17:24:02 +0200 Subject: Updated PDF.js to 2.0.943 --- vendor/assets/javascripts/pdf.js | 26262 +++++--- vendor/assets/javascripts/pdf.min.js | 7 +- vendor/assets/javascripts/pdf.worker.js | 84689 ++++++++++++++------------ vendor/assets/javascripts/pdf.worker.min.js | 20 +- 4 files changed, 64837 insertions(+), 46141 deletions(-) mode change 100755 => 100644 vendor/assets/javascripts/pdf.js mode change 100755 => 100644 vendor/assets/javascripts/pdf.min.js mode change 100755 => 100644 vendor/assets/javascripts/pdf.worker.js mode change 100755 => 100644 vendor/assets/javascripts/pdf.worker.min.js diff --git a/vendor/assets/javascripts/pdf.js b/vendor/assets/javascripts/pdf.js old mode 100755 new mode 100644 index 91c43b12716..4d8adb0f2c9 --- a/vendor/assets/javascripts/pdf.js +++ b/vendor/assets/javascripts/pdf.js @@ -1,4 +1,8 @@ -/* Copyright 2017 Mozilla Foundation +/** + * @licstart The following is the entire license notice for the + * Javascript code in this page + * + * Copyright 2018 Mozilla Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -11,6 +15,9 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. + * + * @licend The above is the entire license notice for the + * Javascript code in this page */ (function webpackUniversalModuleDefinition(root, factory) { @@ -21,7 +28,7 @@ else if(typeof exports === 'object') exports["pdfjs-dist/build/pdf"] = factory(); else - root["pdfjs-dist/build/pdf"] = root.pdfjsDistBuildPdf = factory(); + root["pdfjs-dist/build/pdf"] = root.pdfjsLib = factory(); })(this, function() { return /******/ (function(modules) { // webpackBootstrap /******/ // The module cache @@ -31,9 +38,9 @@ return /******/ (function(modules) { // webpackBootstrap /******/ function __w_pdfjs_require__(moduleId) { /******/ /******/ // Check if module is in cache -/******/ if(installedModules[moduleId]) +/******/ if(installedModules[moduleId]) { /******/ return installedModules[moduleId].exports; -/******/ +/******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { /******/ i: moduleId, @@ -58,18 +65,35 @@ return /******/ (function(modules) { // webpackBootstrap /******/ // expose the module cache /******/ __w_pdfjs_require__.c = installedModules; /******/ -/******/ // identity function for calling harmony imports with the correct context -/******/ __w_pdfjs_require__.i = function(value) { return value; }; -/******/ /******/ // define getter function for harmony exports /******/ __w_pdfjs_require__.d = function(exports, name, getter) { /******/ if(!__w_pdfjs_require__.o(exports, name)) { -/******/ Object.defineProperty(exports, name, { -/******/ configurable: false, -/******/ enumerable: true, -/******/ get: getter -/******/ }); +/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); +/******/ } +/******/ }; +/******/ +/******/ // define __esModule on exports +/******/ __w_pdfjs_require__.r = function(exports) { +/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { +/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); /******/ } +/******/ Object.defineProperty(exports, '__esModule', { value: true }); +/******/ }; +/******/ +/******/ // create a fake namespace object +/******/ // mode & 1: value is a module id, require it +/******/ // mode & 2: merge all properties of value into the ns +/******/ // mode & 4: return value when already ns object +/******/ // mode & 8|1: behave like require +/******/ __w_pdfjs_require__.t = function(value, mode) { +/******/ if(mode & 1) value = __w_pdfjs_require__(value); +/******/ if(mode & 8) return value; +/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; +/******/ var ns = Object.create(null); +/******/ __w_pdfjs_require__.r(ns); +/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); +/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __w_pdfjs_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); +/******/ return ns; /******/ }; /******/ /******/ // getDefaultExport function for compatibility with non-harmony modules @@ -87,8 +111,9 @@ return /******/ (function(modules) { // webpackBootstrap /******/ // __webpack_public_path__ /******/ __w_pdfjs_require__.p = ""; /******/ +/******/ /******/ // Load entry module and return exports -/******/ return __w_pdfjs_require__(__w_pdfjs_require__.s = 13); +/******/ return __w_pdfjs_require__(__w_pdfjs_require__.s = 0); /******/ }) /************************************************************************/ /******/ ([ @@ -96,11 +121,109 @@ return /******/ (function(modules) { // webpackBootstrap /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; -/* WEBPACK VAR INJECTION */(function(global) { -var compatibility = __w_pdfjs_require__(14); -var globalScope = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : undefined; + +var pdfjsVersion = '2.0.943'; +var pdfjsBuild = 'dc98bf76'; +var pdfjsSharedUtil = __w_pdfjs_require__(1); +var pdfjsDisplayAPI = __w_pdfjs_require__(129); +var pdfjsDisplayTextLayer = __w_pdfjs_require__(145); +var pdfjsDisplayAnnotationLayer = __w_pdfjs_require__(146); +var pdfjsDisplayDOMUtils = __w_pdfjs_require__(130); +var pdfjsDisplaySVG = __w_pdfjs_require__(147); +var pdfjsDisplayWorkerOptions = __w_pdfjs_require__(135); +var pdfjsDisplayAPICompatibility = __w_pdfjs_require__(132); +{ + var isNodeJS = __w_pdfjs_require__(4); + if (isNodeJS()) { + var PDFNodeStream = __w_pdfjs_require__(148).PDFNodeStream; + pdfjsDisplayAPI.setPDFNetworkStreamFactory(function (params) { + return new PDFNodeStream(params); + }); + } else if (typeof Response !== 'undefined' && 'body' in Response.prototype && typeof ReadableStream !== 'undefined') { + var PDFFetchStream = __w_pdfjs_require__(151).PDFFetchStream; + pdfjsDisplayAPI.setPDFNetworkStreamFactory(function (params) { + return new PDFFetchStream(params); + }); + } else { + var PDFNetworkStream = __w_pdfjs_require__(152).PDFNetworkStream; + pdfjsDisplayAPI.setPDFNetworkStreamFactory(function (params) { + return new PDFNetworkStream(params); + }); + } +} +exports.build = pdfjsDisplayAPI.build; +exports.version = pdfjsDisplayAPI.version; +exports.getDocument = pdfjsDisplayAPI.getDocument; +exports.LoopbackPort = pdfjsDisplayAPI.LoopbackPort; +exports.PDFDataRangeTransport = pdfjsDisplayAPI.PDFDataRangeTransport; +exports.PDFWorker = pdfjsDisplayAPI.PDFWorker; +exports.renderTextLayer = pdfjsDisplayTextLayer.renderTextLayer; +exports.AnnotationLayer = pdfjsDisplayAnnotationLayer.AnnotationLayer; +exports.createPromiseCapability = pdfjsSharedUtil.createPromiseCapability; +exports.PasswordResponses = pdfjsSharedUtil.PasswordResponses; +exports.InvalidPDFException = pdfjsSharedUtil.InvalidPDFException; +exports.MissingPDFException = pdfjsSharedUtil.MissingPDFException; +exports.SVGGraphics = pdfjsDisplaySVG.SVGGraphics; +exports.NativeImageDecoding = pdfjsSharedUtil.NativeImageDecoding; +exports.CMapCompressionType = pdfjsSharedUtil.CMapCompressionType; +exports.PermissionFlag = pdfjsSharedUtil.PermissionFlag; +exports.UnexpectedResponseException = pdfjsSharedUtil.UnexpectedResponseException; +exports.OPS = pdfjsSharedUtil.OPS; +exports.VerbosityLevel = pdfjsSharedUtil.VerbosityLevel; +exports.UNSUPPORTED_FEATURES = pdfjsSharedUtil.UNSUPPORTED_FEATURES; +exports.createValidAbsoluteUrl = pdfjsSharedUtil.createValidAbsoluteUrl; +exports.createObjectURL = pdfjsSharedUtil.createObjectURL; +exports.removeNullCharacters = pdfjsSharedUtil.removeNullCharacters; +exports.shadow = pdfjsSharedUtil.shadow; +exports.Util = pdfjsSharedUtil.Util; +exports.ReadableStream = pdfjsSharedUtil.ReadableStream; +exports.URL = pdfjsSharedUtil.URL; +exports.RenderingCancelledException = pdfjsDisplayDOMUtils.RenderingCancelledException; +exports.getFilenameFromUrl = pdfjsDisplayDOMUtils.getFilenameFromUrl; +exports.LinkTarget = pdfjsDisplayDOMUtils.LinkTarget; +exports.addLinkAttributes = pdfjsDisplayDOMUtils.addLinkAttributes; +exports.loadScript = pdfjsDisplayDOMUtils.loadScript; +exports.GlobalWorkerOptions = pdfjsDisplayWorkerOptions.GlobalWorkerOptions; +exports.apiCompatibilityParams = pdfjsDisplayAPICompatibility.apiCompatibilityParams; + +/***/ }), +/* 1 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.unreachable = exports.warn = exports.utf8StringToString = exports.stringToUTF8String = exports.stringToPDFString = exports.stringToBytes = exports.string32 = exports.shadow = exports.setVerbosityLevel = exports.URL = exports.ReadableStream = exports.removeNullCharacters = exports.readUint32 = exports.readUint16 = exports.readInt8 = exports.log2 = exports.isEvalSupported = exports.isLittleEndian = exports.createValidAbsoluteUrl = exports.isSameOrigin = exports.isSpace = exports.isString = exports.isNum = exports.isEmptyObj = exports.isBool = exports.isArrayBuffer = exports.info = exports.getVerbosityLevel = exports.getLookupTableFactory = exports.getInheritableProperty = exports.deprecated = exports.createObjectURL = exports.createPromiseCapability = exports.bytesToString = exports.assert = exports.arraysToBytes = exports.arrayByteLength = exports.FormatError = exports.XRefParseException = exports.toRomanNumerals = exports.Util = exports.UnknownErrorException = exports.UnexpectedResponseException = exports.TextRenderingMode = exports.StreamType = exports.PermissionFlag = exports.PasswordResponses = exports.PasswordException = exports.NativeImageDecoding = exports.MissingPDFException = exports.MissingDataException = exports.InvalidPDFException = exports.AbortException = exports.CMapCompressionType = exports.ImageKind = exports.FontType = exports.AnnotationType = exports.AnnotationFlag = exports.AnnotationFieldFlag = exports.AnnotationBorderStyleType = exports.UNSUPPORTED_FEATURES = exports.VerbosityLevel = exports.OPS = exports.IDENTITY_MATRIX = exports.FONT_IDENTITY_MATRIX = undefined; + +var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; + +__w_pdfjs_require__(2); + +var _streams_polyfill = __w_pdfjs_require__(125); + +var _url_polyfill = __w_pdfjs_require__(127); + +var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0]; var FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0]; +var NativeImageDecoding = { + NONE: 'none', + DECODE: 'decode', + DISPLAY: 'display' +}; +var PermissionFlag = { + PRINT: 0x04, + MODIFY_CONTENTS: 0x08, + COPY: 0x10, + MODIFY_ANNOTATIONS: 0x20, + FILL_INTERACTIVE_FORMS: 0x100, + COPY_FOR_ACCESSIBILITY: 0x200, + ASSEMBLE: 0x400, + PRINT_HIGH_QUALITY: 0x800 +}; var TextRenderingMode = { FILL: 0, STROKE: 1, @@ -211,10 +334,10 @@ var FontType = { TYPE0: 9, MMTYPE1: 10 }; -var VERBOSITY_LEVELS = { - errors: 0, - warnings: 1, - infos: 5 +var VerbosityLevel = { + ERRORS: 0, + WARNINGS: 1, + INFOS: 5 }; var CMapCompressionType = { NONE: 0, @@ -314,66 +437,61 @@ var OPS = { paintSolidColorImageMask: 90, constructPath: 91 }; -var verbosity = VERBOSITY_LEVELS.warnings; +var UNSUPPORTED_FEATURES = { + unknown: 'unknown', + forms: 'forms', + javaScript: 'javaScript', + smask: 'smask', + shadingPattern: 'shadingPattern', + font: 'font' +}; +var PasswordResponses = { + NEED_PASSWORD: 1, + INCORRECT_PASSWORD: 2 +}; +var verbosity = VerbosityLevel.WARNINGS; function setVerbosityLevel(level) { - verbosity = level; + if (Number.isInteger(level)) { + verbosity = level; + } } function getVerbosityLevel() { return verbosity; } function info(msg) { - if (verbosity >= VERBOSITY_LEVELS.infos) { + if (verbosity >= VerbosityLevel.INFOS) { console.log('Info: ' + msg); } } function warn(msg) { - if (verbosity >= VERBOSITY_LEVELS.warnings) { + if (verbosity >= VerbosityLevel.WARNINGS) { console.log('Warning: ' + msg); } } function deprecated(details) { console.log('Deprecated API usage: ' + details); } -function error(msg) { - if (verbosity >= VERBOSITY_LEVELS.errors) { - console.log('Error: ' + msg); - console.log(backtrace()); - } +function unreachable(msg) { throw new Error(msg); } -function backtrace() { - try { - throw new Error(); - } catch (e) { - return e.stack ? e.stack.split('\n').slice(2).join('\n') : ''; - } -} function assert(cond, msg) { if (!cond) { - error(msg); + unreachable(msg); } } -var UNSUPPORTED_FEATURES = { - unknown: 'unknown', - forms: 'forms', - javaScript: 'javaScript', - smask: 'smask', - shadingPattern: 'shadingPattern', - font: 'font' -}; function isSameOrigin(baseUrl, otherUrl) { try { - var base = new URL(baseUrl); + var base = new _url_polyfill.URL(baseUrl); if (!base.origin || base.origin === 'null') { return false; } } catch (e) { return false; } - var other = new URL(otherUrl, base); + var other = new _url_polyfill.URL(otherUrl, base); return base.origin === other.origin; } -function isValidProtocol(url) { +function _isValidProtocol(url) { if (!url) { return false; } @@ -393,8 +511,8 @@ function createValidAbsoluteUrl(url, baseUrl) { return null; } try { - var absoluteUrl = baseUrl ? new URL(url, baseUrl) : new URL(url); - if (isValidProtocol(absoluteUrl)) { + var absoluteUrl = baseUrl ? new _url_polyfill.URL(url, baseUrl) : new _url_polyfill.URL(url); + if (_isValidProtocol(absoluteUrl)) { return absoluteUrl; } } catch (ex) {} @@ -420,10 +538,6 @@ function getLookupTableFactory(initializer) { return lookup; }; } -var PasswordResponses = { - NEED_PASSWORD: 1, - INCORRECT_PASSWORD: 2 -}; var PasswordException = function PasswordExceptionClosure() { function PasswordException(msg, code) { this.name = 'PasswordException'; @@ -472,15 +586,6 @@ var UnexpectedResponseException = function UnexpectedResponseExceptionClosure() UnexpectedResponseException.constructor = UnexpectedResponseException; return UnexpectedResponseException; }(); -var NotImplementedException = function NotImplementedExceptionClosure() { - function NotImplementedException(msg) { - this.message = msg; - } - NotImplementedException.prototype = new Error(); - NotImplementedException.prototype.name = 'NotImplementedException'; - NotImplementedException.constructor = NotImplementedException; - return NotImplementedException; -}(); var MissingDataException = function MissingDataExceptionClosure() { function MissingDataException(begin, end) { this.begin = begin; @@ -501,6 +606,24 @@ var XRefParseException = function XRefParseExceptionClosure() { XRefParseException.constructor = XRefParseException; return XRefParseException; }(); +var FormatError = function FormatErrorClosure() { + function FormatError(msg) { + this.message = msg; + } + FormatError.prototype = new Error(); + FormatError.prototype.name = 'FormatError'; + FormatError.constructor = FormatError; + return FormatError; +}(); +var AbortException = function AbortExceptionClosure() { + function AbortException(msg) { + this.name = 'AbortException'; + this.message = msg; + } + AbortException.prototype = new Error(); + AbortException.constructor = AbortException; + return AbortException; +}(); var NullCharactersRegExp = /\x00/g; function removeNullCharacters(str) { if (typeof str !== 'string') { @@ -510,7 +633,7 @@ function removeNullCharacters(str) { return str.replace(NullCharactersRegExp, ''); } function bytesToString(bytes) { - assert(bytes !== null && typeof bytes === 'object' && bytes.length !== undefined, 'Invalid argument for bytesToString'); + assert(bytes !== null && (typeof bytes === 'undefined' ? 'undefined' : _typeof(bytes)) === 'object' && bytes.length !== undefined, 'Invalid argument for bytesToString'); var length = bytes.length; var MAX_ARGUMENT_COUNT = 8192; if (length < MAX_ARGUMENT_COUNT) { @@ -574,13 +697,10 @@ function string32(value) { return String.fromCharCode(value >> 24 & 0xff, value >> 16 & 0xff, value >> 8 & 0xff, value & 0xff); } function log2(x) { - var n = 1, - i = 0; - while (x > n) { - n <<= 1; - i++; + if (x <= 0) { + return 0; } - return i; + return Math.ceil(Math.log2(x)); } function readInt8(data, start) { return data[start] << 24 >> 24; @@ -592,10 +712,10 @@ function readUint32(data, offset) { return (data[offset] << 24 | data[offset + 1] << 16 | data[offset + 2] << 8 | data[offset + 3]) >>> 0; } function isLittleEndian() { - var buffer8 = new Uint8Array(2); + var buffer8 = new Uint8Array(4); buffer8[0] = 1; - var buffer16 = new Uint16Array(buffer8.buffer); - return buffer16[0] === 1; + var view32 = new Uint32Array(buffer8.buffer, 0, 1); + return view32[0] === 1; } function isEvalSupported() { try { @@ -605,42 +725,36 @@ function isEvalSupported() { return false; } } -var Uint32ArrayView = function Uint32ArrayViewClosure() { - function Uint32ArrayView(buffer, length) { - this.buffer = buffer; - this.byteLength = buffer.length; - this.length = length === undefined ? this.byteLength >> 2 : length; - ensureUint32ArrayViewProps(this.length); - } - Uint32ArrayView.prototype = Object.create(null); - var uint32ArrayViewSetters = 0; - function createUint32ArrayProp(index) { - return { - get: function () { - var buffer = this.buffer, - offset = index << 2; - return (buffer[offset] | buffer[offset + 1] << 8 | buffer[offset + 2] << 16 | buffer[offset + 3] << 24) >>> 0; - }, - set: function (value) { - var buffer = this.buffer, - offset = index << 2; - buffer[offset] = value & 255; - buffer[offset + 1] = value >> 8 & 255; - buffer[offset + 2] = value >> 16 & 255; - buffer[offset + 3] = value >>> 24 & 255; - } - }; - } - function ensureUint32ArrayViewProps(length) { - while (uint32ArrayViewSetters < length) { - Object.defineProperty(Uint32ArrayView.prototype, uint32ArrayViewSetters, createUint32ArrayProp(uint32ArrayViewSetters)); - uint32ArrayViewSetters++; +function getInheritableProperty(_ref) { + var dict = _ref.dict, + key = _ref.key, + _ref$getArray = _ref.getArray, + getArray = _ref$getArray === undefined ? false : _ref$getArray, + _ref$stopWhenFound = _ref.stopWhenFound, + stopWhenFound = _ref$stopWhenFound === undefined ? true : _ref$stopWhenFound; + + var LOOP_LIMIT = 100; + var loopCount = 0; + var values = void 0; + while (dict) { + var value = getArray ? dict.getArray(key) : dict.get(key); + if (value !== undefined) { + if (stopWhenFound) { + return value; + } + if (!values) { + values = []; + } + values.push(value); + } + if (++loopCount > LOOP_LIMIT) { + warn('getInheritableProperty: maximum loop count exceeded for "' + key + '"'); + break; } + dict = dict.get('Parent'); } - return Uint32ArrayView; -}(); -exports.Uint32ArrayView = Uint32ArrayView; -var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0]; + return values; +} var Util = function UtilClosure() { function Util() {} var rgbBuf = ['rgb(', 0, ',', 0, ',', 0, ')']; @@ -725,152 +839,29 @@ var Util = function UtilClosure() { } return result; }; - Util.sign = function Util_sign(num) { - return num < 0 ? -1 : 1; - }; - var ROMAN_NUMBER_MAP = ['', 'C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM', '', 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC', '', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX']; - Util.toRoman = function Util_toRoman(number, lowerCase) { - assert(isInt(number) && number > 0, 'The number should be a positive integer.'); - var pos, - romanBuf = []; - while (number >= 1000) { - number -= 1000; - romanBuf.push('M'); - } - pos = number / 100 | 0; - number %= 100; - romanBuf.push(ROMAN_NUMBER_MAP[pos]); - pos = number / 10 | 0; - number %= 10; - romanBuf.push(ROMAN_NUMBER_MAP[10 + pos]); - romanBuf.push(ROMAN_NUMBER_MAP[20 + number]); - var romanStr = romanBuf.join(''); - return lowerCase ? romanStr.toLowerCase() : romanStr; - }; - Util.appendToArray = function Util_appendToArray(arr1, arr2) { - Array.prototype.push.apply(arr1, arr2); - }; - Util.prependToArray = function Util_prependToArray(arr1, arr2) { - Array.prototype.unshift.apply(arr1, arr2); - }; - Util.extendObj = function extendObj(obj1, obj2) { - for (var key in obj2) { - obj1[key] = obj2[key]; - } - }; - Util.getInheritableProperty = function Util_getInheritableProperty(dict, name, getArray) { - while (dict && !dict.has(name)) { - dict = dict.get('Parent'); - } - if (!dict) { - return null; - } - return getArray ? dict.getArray(name) : dict.get(name); - }; - Util.inherit = function Util_inherit(sub, base, prototype) { - sub.prototype = Object.create(base.prototype); - sub.prototype.constructor = sub; - for (var prop in prototype) { - sub.prototype[prop] = prototype[prop]; - } - }; - Util.loadScript = function Util_loadScript(src, callback) { - var script = document.createElement('script'); - var loaded = false; - script.setAttribute('src', src); - if (callback) { - script.onload = function () { - if (!loaded) { - callback(); - } - loaded = true; - }; - } - document.getElementsByTagName('head')[0].appendChild(script); - }; return Util; }(); -var PageViewport = function PageViewportClosure() { - function PageViewport(viewBox, scale, rotation, offsetX, offsetY, dontFlip) { - this.viewBox = viewBox; - this.scale = scale; - this.rotation = rotation; - this.offsetX = offsetX; - this.offsetY = offsetY; - var centerX = (viewBox[2] + viewBox[0]) / 2; - var centerY = (viewBox[3] + viewBox[1]) / 2; - var rotateA, rotateB, rotateC, rotateD; - rotation = rotation % 360; - rotation = rotation < 0 ? rotation + 360 : rotation; - switch (rotation) { - case 180: - rotateA = -1; - rotateB = 0; - rotateC = 0; - rotateD = 1; - break; - case 90: - rotateA = 0; - rotateB = 1; - rotateC = 1; - rotateD = 0; - break; - case 270: - rotateA = 0; - rotateB = -1; - rotateC = -1; - rotateD = 0; - break; - default: - rotateA = 1; - rotateB = 0; - rotateC = 0; - rotateD = -1; - break; - } - if (dontFlip) { - rotateC = -rotateC; - rotateD = -rotateD; - } - var offsetCanvasX, offsetCanvasY; - var width, height; - if (rotateA === 0) { - offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX; - offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY; - width = Math.abs(viewBox[3] - viewBox[1]) * scale; - height = Math.abs(viewBox[2] - viewBox[0]) * scale; - } else { - offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX; - offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY; - width = Math.abs(viewBox[2] - viewBox[0]) * scale; - height = Math.abs(viewBox[3] - viewBox[1]) * scale; - } - this.transform = [rotateA * scale, rotateB * scale, rotateC * scale, rotateD * scale, offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY, offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY]; - this.width = width; - this.height = height; - this.fontScale = scale; +var ROMAN_NUMBER_MAP = ['', 'C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM', '', 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC', '', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX']; +function toRomanNumerals(number) { + var lowerCase = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; + + assert(Number.isInteger(number) && number > 0, 'The number should be a positive integer.'); + var pos = void 0, + romanBuf = []; + while (number >= 1000) { + number -= 1000; + romanBuf.push('M'); } - PageViewport.prototype = { - clone: function PageViewPort_clone(args) { - args = args || {}; - var scale = 'scale' in args ? args.scale : this.scale; - var rotation = 'rotation' in args ? args.rotation : this.rotation; - return new PageViewport(this.viewBox.slice(), scale, rotation, this.offsetX, this.offsetY, args.dontFlip); - }, - convertToViewportPoint: function PageViewport_convertToViewportPoint(x, y) { - return Util.applyTransform([x, y], this.transform); - }, - convertToViewportRectangle: function PageViewport_convertToViewportRectangle(rect) { - var tl = Util.applyTransform([rect[0], rect[1]], this.transform); - var br = Util.applyTransform([rect[2], rect[3]], this.transform); - return [tl[0], tl[1], br[0], br[1]]; - }, - convertToPdfPoint: function PageViewport_convertToPdfPoint(x, y) { - return Util.applyInverseTransform([x, y], this.transform); - } - }; - return PageViewport; -}(); + pos = number / 100 | 0; + number %= 100; + romanBuf.push(ROMAN_NUMBER_MAP[pos]); + pos = number / 10 | 0; + number %= 10; + romanBuf.push(ROMAN_NUMBER_MAP[10 + pos]); + romanBuf.push(ROMAN_NUMBER_MAP[20 + number]); + var romanStr = romanBuf.join(''); + return lowerCase ? romanStr.toLowerCase() : romanStr; +} var PDFStringTranslateTable = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2D8, 0x2C7, 0x2C6, 0x2D9, 0x2DD, 0x2DB, 0x2DA, 0x2DC, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014, 0x2013, 0x192, 0x2044, 0x2039, 0x203A, 0x2212, 0x2030, 0x201E, 0x201C, 0x201D, 0x2018, 0x2019, 0x201A, 0x2122, 0xFB01, 0xFB02, 0x141, 0x152, 0x160, 0x178, 0x17D, 0x131, 0x142, 0x153, 0x161, 0x17E, 0, 0x20AC]; function stringToPDFString(str) { var i, @@ -903,30 +894,18 @@ function isEmptyObj(obj) { function isBool(v) { return typeof v === 'boolean'; } -function isInt(v) { - return typeof v === 'number' && (v | 0) === v; -} function isNum(v) { return typeof v === 'number'; } function isString(v) { return typeof v === 'string'; } -function isArray(v) { - return v instanceof Array; -} function isArrayBuffer(v) { - return typeof v === 'object' && v !== null && v.byteLength !== undefined; + return (typeof v === 'undefined' ? 'undefined' : _typeof(v)) === 'object' && v !== null && v.byteLength !== undefined; } function isSpace(ch) { return ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A; } -function isNodeJS() { - if (typeof __pdfjsdev_webpack__ === 'undefined') { - return typeof process === 'object' && process + '' === '[object process]'; - } - return false; -} function createPromiseCapability() { var capability = {}; capability.promise = new Promise(function (resolve, reject) { @@ -935,75 +914,14 @@ function createPromiseCapability() { }); return capability; } -var StatTimer = function StatTimerClosure() { - function rpad(str, pad, length) { - while (str.length < length) { - str += pad; - } - return str; - } - function StatTimer() { - this.started = Object.create(null); - this.times = []; - this.enabled = true; - } - StatTimer.prototype = { - time: function StatTimer_time(name) { - if (!this.enabled) { - return; - } - if (name in this.started) { - warn('Timer is already running for ' + name); - } - this.started[name] = Date.now(); - }, - timeEnd: function StatTimer_timeEnd(name) { - if (!this.enabled) { - return; - } - if (!(name in this.started)) { - warn('Timer has not been started for ' + name); - } - this.times.push({ - 'name': name, - 'start': this.started[name], - 'end': Date.now() - }); - delete this.started[name]; - }, - toString: function StatTimer_toString() { - var i, ii; - var times = this.times; - var out = ''; - var longest = 0; - for (i = 0, ii = times.length; i < ii; ++i) { - var name = times[i]['name']; - if (name.length > longest) { - longest = name.length; - } - } - for (i = 0, ii = times.length; i < ii; ++i) { - var span = times[i]; - var duration = span.end - span.start; - out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n'; - } - return out; - } - }; - return StatTimer; -}(); -var createBlob = function createBlob(data, contentType) { - if (typeof Blob !== 'undefined') { - return new Blob([data], { type: contentType }); - } - warn('The "Blob" constructor is not supported.'); -}; var createObjectURL = function createObjectURLClosure() { var digits = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; - return function createObjectURL(data, contentType, forceDataSchema) { - if (!forceDataSchema && typeof URL !== 'undefined' && URL.createObjectURL) { - var blob = createBlob(data, contentType); - return URL.createObjectURL(blob); + return function createObjectURL(data, contentType) { + var forceDataSchema = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; + + if (!forceDataSchema && _url_polyfill.URL.createObjectURL) { + var blob = new Blob([data], { type: contentType }); + return _url_polyfill.URL.createObjectURL(blob); } var buffer = 'data:' + contentType + ';base64,'; for (var i = 0, ii = data.length; i < ii; i += 3) { @@ -1019,129 +937,10 @@ var createObjectURL = function createObjectURLClosure() { return buffer; }; }(); -function MessageHandler(sourceName, targetName, comObj) { - this.sourceName = sourceName; - this.targetName = targetName; - this.comObj = comObj; - this.callbackIndex = 1; - this.postMessageTransfers = true; - var callbacksCapabilities = this.callbacksCapabilities = Object.create(null); - var ah = this.actionHandler = Object.create(null); - this._onComObjOnMessage = function messageHandlerComObjOnMessage(event) { - var data = event.data; - if (data.targetName !== this.sourceName) { - return; - } - if (data.isReply) { - var callbackId = data.callbackId; - if (data.callbackId in callbacksCapabilities) { - var callback = callbacksCapabilities[callbackId]; - delete callbacksCapabilities[callbackId]; - if ('error' in data) { - callback.reject(data.error); - } else { - callback.resolve(data.data); - } - } else { - error('Cannot resolve callback ' + callbackId); - } - } else if (data.action in ah) { - var action = ah[data.action]; - if (data.callbackId) { - var sourceName = this.sourceName; - var targetName = data.sourceName; - Promise.resolve().then(function () { - return action[0].call(action[1], data.data); - }).then(function (result) { - comObj.postMessage({ - sourceName: sourceName, - targetName: targetName, - isReply: true, - callbackId: data.callbackId, - data: result - }); - }, function (reason) { - if (reason instanceof Error) { - reason = reason + ''; - } - comObj.postMessage({ - sourceName: sourceName, - targetName: targetName, - isReply: true, - callbackId: data.callbackId, - error: reason - }); - }); - } else { - action[0].call(action[1], data.data); - } - } else { - error('Unknown action from worker: ' + data.action); - } - }.bind(this); - comObj.addEventListener('message', this._onComObjOnMessage); -} -MessageHandler.prototype = { - on: function messageHandlerOn(actionName, handler, scope) { - var ah = this.actionHandler; - if (ah[actionName]) { - error('There is already an actionName called "' + actionName + '"'); - } - ah[actionName] = [handler, scope]; - }, - send: function messageHandlerSend(actionName, data, transfers) { - var message = { - sourceName: this.sourceName, - targetName: this.targetName, - action: actionName, - data: data - }; - this.postMessage(message, transfers); - }, - sendWithPromise: function messageHandlerSendWithPromise(actionName, data, transfers) { - var callbackId = this.callbackIndex++; - var message = { - sourceName: this.sourceName, - targetName: this.targetName, - action: actionName, - data: data, - callbackId: callbackId - }; - var capability = createPromiseCapability(); - this.callbacksCapabilities[callbackId] = capability; - try { - this.postMessage(message, transfers); - } catch (e) { - capability.reject(e); - } - return capability.promise; - }, - postMessage: function (message, transfers) { - if (transfers && this.postMessageTransfers) { - this.comObj.postMessage(message, transfers); - } else { - this.comObj.postMessage(message); - } - }, - destroy: function () { - this.comObj.removeEventListener('message', this._onComObjOnMessage); - } -}; -function loadJpegStream(id, imageUrl, objs) { - var img = new Image(); - img.onload = function loadJpegStream_onloadClosure() { - objs.resolve(id, img); - }; - img.onerror = function loadJpegStream_onerrorClosure() { - objs.resolve(id, null); - warn('Error during JPEG image loading'); - }; - img.src = imageUrl; -} exports.FONT_IDENTITY_MATRIX = FONT_IDENTITY_MATRIX; exports.IDENTITY_MATRIX = IDENTITY_MATRIX; exports.OPS = OPS; -exports.VERBOSITY_LEVELS = VERBOSITY_LEVELS; +exports.VerbosityLevel = VerbosityLevel; exports.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES; exports.AnnotationBorderStyleType = AnnotationBorderStyleType; exports.AnnotationFieldFlag = AnnotationFieldFlag; @@ -1150,53 +949,50 @@ exports.AnnotationType = AnnotationType; exports.FontType = FontType; exports.ImageKind = ImageKind; exports.CMapCompressionType = CMapCompressionType; +exports.AbortException = AbortException; exports.InvalidPDFException = InvalidPDFException; -exports.MessageHandler = MessageHandler; exports.MissingDataException = MissingDataException; exports.MissingPDFException = MissingPDFException; -exports.NotImplementedException = NotImplementedException; -exports.PageViewport = PageViewport; +exports.NativeImageDecoding = NativeImageDecoding; exports.PasswordException = PasswordException; exports.PasswordResponses = PasswordResponses; -exports.StatTimer = StatTimer; +exports.PermissionFlag = PermissionFlag; exports.StreamType = StreamType; exports.TextRenderingMode = TextRenderingMode; exports.UnexpectedResponseException = UnexpectedResponseException; exports.UnknownErrorException = UnknownErrorException; exports.Util = Util; +exports.toRomanNumerals = toRomanNumerals; exports.XRefParseException = XRefParseException; +exports.FormatError = FormatError; exports.arrayByteLength = arrayByteLength; exports.arraysToBytes = arraysToBytes; exports.assert = assert; exports.bytesToString = bytesToString; -exports.createBlob = createBlob; exports.createPromiseCapability = createPromiseCapability; exports.createObjectURL = createObjectURL; exports.deprecated = deprecated; -exports.error = error; +exports.getInheritableProperty = getInheritableProperty; exports.getLookupTableFactory = getLookupTableFactory; exports.getVerbosityLevel = getVerbosityLevel; -exports.globalScope = globalScope; exports.info = info; -exports.isArray = isArray; exports.isArrayBuffer = isArrayBuffer; exports.isBool = isBool; exports.isEmptyObj = isEmptyObj; -exports.isInt = isInt; exports.isNum = isNum; exports.isString = isString; exports.isSpace = isSpace; -exports.isNodeJS = isNodeJS; exports.isSameOrigin = isSameOrigin; exports.createValidAbsoluteUrl = createValidAbsoluteUrl; exports.isLittleEndian = isLittleEndian; exports.isEvalSupported = isEvalSupported; -exports.loadJpegStream = loadJpegStream; exports.log2 = log2; exports.readInt8 = readInt8; exports.readUint16 = readUint16; exports.readUint32 = readUint32; exports.removeNullCharacters = removeNullCharacters; +exports.ReadableStream = _streams_polyfill.ReadableStream; +exports.URL = _url_polyfill.URL; exports.setVerbosityLevel = setVerbosityLevel; exports.shadow = shadow; exports.string32 = string32; @@ -1205,8161 +1001,18365 @@ exports.stringToPDFString = stringToPDFString; exports.stringToUTF8String = stringToUTF8String; exports.utf8StringToString = utf8StringToString; exports.warn = warn; -/* WEBPACK VAR INJECTION */}.call(exports, __w_pdfjs_require__(6))) +exports.unreachable = unreachable; /***/ }), -/* 1 */ +/* 2 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; -var sharedUtil = __w_pdfjs_require__(0); -var assert = sharedUtil.assert; -var removeNullCharacters = sharedUtil.removeNullCharacters; -var warn = sharedUtil.warn; -var deprecated = sharedUtil.deprecated; -var createValidAbsoluteUrl = sharedUtil.createValidAbsoluteUrl; -var stringToBytes = sharedUtil.stringToBytes; -var CMapCompressionType = sharedUtil.CMapCompressionType; -var DEFAULT_LINK_REL = 'noopener noreferrer nofollow'; -function DOMCanvasFactory() {} -DOMCanvasFactory.prototype = { - create: function DOMCanvasFactory_create(width, height) { - assert(width > 0 && height > 0, 'invalid canvas size'); - var canvas = document.createElement('canvas'); - var context = canvas.getContext('2d'); - canvas.width = width; - canvas.height = height; - return { - canvas: canvas, - context: context +var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; + +var globalScope = __w_pdfjs_require__(3); +if (!globalScope._pdfjsCompatibilityChecked) { + globalScope._pdfjsCompatibilityChecked = true; + var isNodeJS = __w_pdfjs_require__(4); + var hasDOM = (typeof window === 'undefined' ? 'undefined' : _typeof(window)) === 'object' && (typeof document === 'undefined' ? 'undefined' : _typeof(document)) === 'object'; + (function checkNodeBtoa() { + if (globalScope.btoa || !isNodeJS()) { + return; + } + globalScope.btoa = function (chars) { + return Buffer.from(chars, 'binary').toString('base64'); }; - }, - reset: function DOMCanvasFactory_reset(canvasAndContextPair, width, height) { - assert(canvasAndContextPair.canvas, 'canvas is not specified'); - assert(width > 0 && height > 0, 'invalid canvas size'); - canvasAndContextPair.canvas.width = width; - canvasAndContextPair.canvas.height = height; - }, - destroy: function DOMCanvasFactory_destroy(canvasAndContextPair) { - assert(canvasAndContextPair.canvas, 'canvas is not specified'); - canvasAndContextPair.canvas.width = 0; - canvasAndContextPair.canvas.height = 0; - canvasAndContextPair.canvas = null; - canvasAndContextPair.context = null; - } -}; -var DOMCMapReaderFactory = function DOMCMapReaderFactoryClosure() { - function DOMCMapReaderFactory(params) { - this.baseUrl = params.baseUrl || null; - this.isCompressed = params.isCompressed || false; - } - DOMCMapReaderFactory.prototype = { - fetch: function (params) { - var name = params.name; - if (!name) { - return Promise.reject(new Error('CMap name must be specified.')); + })(); + (function checkNodeAtob() { + if (globalScope.atob || !isNodeJS()) { + return; + } + globalScope.atob = function (input) { + return Buffer.from(input, 'base64').toString('binary'); + }; + })(); + (function checkCurrentScript() { + if (!hasDOM) { + return; + } + if ('currentScript' in document) { + return; + } + Object.defineProperty(document, 'currentScript', { + get: function get() { + var scripts = document.getElementsByTagName('script'); + return scripts[scripts.length - 1]; + }, + + enumerable: true, + configurable: true + }); + })(); + (function checkChildNodeRemove() { + if (!hasDOM) { + return; + } + if (typeof Element.prototype.remove !== 'undefined') { + return; + } + Element.prototype.remove = function () { + if (this.parentNode) { + this.parentNode.removeChild(this); } - return new Promise(function (resolve, reject) { - var url = this.baseUrl + name + (this.isCompressed ? '.bcmap' : ''); - var request = new XMLHttpRequest(); - request.open('GET', url, true); - if (this.isCompressed) { - request.responseType = 'arraybuffer'; - } - request.onreadystatechange = function () { - if (request.readyState !== XMLHttpRequest.DONE) { - return; - } - if (request.status === 200 || request.status === 0) { - var data; - if (this.isCompressed && request.response) { - data = new Uint8Array(request.response); - } else if (!this.isCompressed && request.responseText) { - data = stringToBytes(request.responseText); - } - if (data) { - resolve({ - cMapData: data, - compressionType: this.isCompressed ? CMapCompressionType.BINARY : CMapCompressionType.NONE - }); - return; - } - } - reject(new Error('Unable to load ' + (this.isCompressed ? 'binary ' : '') + 'CMap at: ' + url)); - }.bind(this); - request.send(null); - }.bind(this)); + }; + })(); + (function checkDOMTokenListToggle() { + if (!hasDOM || isNodeJS()) { + return; } - }; - return DOMCMapReaderFactory; -}(); -var CustomStyle = function CustomStyleClosure() { - var prefixes = ['ms', 'Moz', 'Webkit', 'O']; - var _cache = Object.create(null); - function CustomStyle() {} - CustomStyle.getProp = function get(propName, element) { - if (arguments.length === 1 && typeof _cache[propName] === 'string') { - return _cache[propName]; - } - element = element || document.documentElement; - var style = element.style, - prefixed, - uPropName; - if (typeof style[propName] === 'string') { - return _cache[propName] = propName; - } - uPropName = propName.charAt(0).toUpperCase() + propName.slice(1); - for (var i = 0, l = prefixes.length; i < l; i++) { - prefixed = prefixes[i] + uPropName; - if (typeof style[prefixed] === 'string') { - return _cache[propName] = prefixed; - } - } - return _cache[propName] = 'undefined'; - }; - CustomStyle.setProp = function set(propName, element, str) { - var prop = this.getProp(propName); - if (prop !== 'undefined') { - element.style[prop] = str; + var div = document.createElement('div'); + if (div.classList.toggle('test', 0) === false) { + return; } - }; - return CustomStyle; -}(); -var RenderingCancelledException = function RenderingCancelledException() { - function RenderingCancelledException(msg, type) { - this.message = msg; - this.type = type; - } - RenderingCancelledException.prototype = new Error(); - RenderingCancelledException.prototype.name = 'RenderingCancelledException'; - RenderingCancelledException.constructor = RenderingCancelledException; - return RenderingCancelledException; -}(); -var hasCanvasTypedArrays; -hasCanvasTypedArrays = function hasCanvasTypedArrays() { - var canvas = document.createElement('canvas'); - canvas.width = canvas.height = 1; - var ctx = canvas.getContext('2d'); - var imageData = ctx.createImageData(1, 1); - return typeof imageData.data.buffer !== 'undefined'; -}; -var LinkTarget = { - NONE: 0, - SELF: 1, - BLANK: 2, - PARENT: 3, - TOP: 4 -}; -var LinkTargetStringMap = ['', '_self', '_blank', '_parent', '_top']; -function addLinkAttributes(link, params) { - var url = params && params.url; - link.href = link.title = url ? removeNullCharacters(url) : ''; - if (url) { - var target = params.target; - if (typeof target === 'undefined') { - target = getDefaultSetting('externalLinkTarget'); + var originalDOMTokenListToggle = DOMTokenList.prototype.toggle; + DOMTokenList.prototype.toggle = function (token) { + if (arguments.length > 1) { + var force = !!arguments[1]; + return this[force ? 'add' : 'remove'](token), force; + } + return originalDOMTokenListToggle(token); + }; + })(); + (function checkStringIncludes() { + if (String.prototype.includes) { + return; } - link.target = LinkTargetStringMap[target]; - var rel = params.rel; - if (typeof rel === 'undefined') { - rel = getDefaultSetting('externalLinkRel'); + __w_pdfjs_require__(5); + })(); + (function checkArrayIncludes() { + if (Array.prototype.includes) { + return; } - link.rel = rel; - } -} -function getFilenameFromUrl(url) { - var anchor = url.indexOf('#'); - var query = url.indexOf('?'); - var end = Math.min(anchor > 0 ? anchor : url.length, query > 0 ? query : url.length); - return url.substring(url.lastIndexOf('/', end) + 1, end); -} -function getDefaultSetting(id) { - var globalSettings = sharedUtil.globalScope.PDFJS; - switch (id) { - case 'pdfBug': - return globalSettings ? globalSettings.pdfBug : false; - case 'disableAutoFetch': - return globalSettings ? globalSettings.disableAutoFetch : false; - case 'disableStream': - return globalSettings ? globalSettings.disableStream : false; - case 'disableRange': - return globalSettings ? globalSettings.disableRange : false; - case 'disableFontFace': - return globalSettings ? globalSettings.disableFontFace : false; - case 'disableCreateObjectURL': - return globalSettings ? globalSettings.disableCreateObjectURL : false; - case 'disableWebGL': - return globalSettings ? globalSettings.disableWebGL : true; - case 'cMapUrl': - return globalSettings ? globalSettings.cMapUrl : null; - case 'cMapPacked': - return globalSettings ? globalSettings.cMapPacked : false; - case 'postMessageTransfers': - return globalSettings ? globalSettings.postMessageTransfers : true; - case 'workerPort': - return globalSettings ? globalSettings.workerPort : null; - case 'workerSrc': - return globalSettings ? globalSettings.workerSrc : null; - case 'disableWorker': - return globalSettings ? globalSettings.disableWorker : false; - case 'maxImageSize': - return globalSettings ? globalSettings.maxImageSize : -1; - case 'imageResourcesPath': - return globalSettings ? globalSettings.imageResourcesPath : ''; - case 'isEvalSupported': - return globalSettings ? globalSettings.isEvalSupported : true; - case 'externalLinkTarget': - if (!globalSettings) { - return LinkTarget.NONE; - } - switch (globalSettings.externalLinkTarget) { - case LinkTarget.NONE: - case LinkTarget.SELF: - case LinkTarget.BLANK: - case LinkTarget.PARENT: - case LinkTarget.TOP: - return globalSettings.externalLinkTarget; - } - warn('PDFJS.externalLinkTarget is invalid: ' + globalSettings.externalLinkTarget); - globalSettings.externalLinkTarget = LinkTarget.NONE; - return LinkTarget.NONE; - case 'externalLinkRel': - return globalSettings ? globalSettings.externalLinkRel : DEFAULT_LINK_REL; - case 'enableStats': - return !!(globalSettings && globalSettings.enableStats); - case 'pdfjsNext': - return !!(globalSettings && globalSettings.pdfjsNext); - default: - throw new Error('Unknown default setting: ' + id); - } -} -function isExternalLinkTargetSet() { - var externalLinkTarget = getDefaultSetting('externalLinkTarget'); - switch (externalLinkTarget) { - case LinkTarget.NONE: - return false; - case LinkTarget.SELF: - case LinkTarget.BLANK: - case LinkTarget.PARENT: - case LinkTarget.TOP: - return true; - } -} -function isValidUrl(url, allowRelative) { - deprecated('isValidUrl(), please use createValidAbsoluteUrl() instead.'); - var baseUrl = allowRelative ? 'http://example.com' : null; - return createValidAbsoluteUrl(url, baseUrl) !== null; + __w_pdfjs_require__(33); + })(); + (function checkObjectAssign() { + if (Object.assign) { + return; + } + __w_pdfjs_require__(42); + })(); + (function checkMathLog2() { + if (Math.log2) { + return; + } + Math.log2 = __w_pdfjs_require__(52); + })(); + (function checkNumberIsNaN() { + if (Number.isNaN) { + return; + } + Number.isNaN = __w_pdfjs_require__(54); + })(); + (function checkNumberIsInteger() { + if (Number.isInteger) { + return; + } + Number.isInteger = __w_pdfjs_require__(56); + })(); + (function checkPromise() { + if (globalScope.Promise) { + return; + } + globalScope.Promise = __w_pdfjs_require__(59); + })(); + (function checkWeakMap() { + if (globalScope.WeakMap) { + return; + } + globalScope.WeakMap = __w_pdfjs_require__(94); + })(); + (function checkStringCodePointAt() { + if (String.codePointAt) { + return; + } + String.codePointAt = __w_pdfjs_require__(111); + })(); + (function checkStringFromCodePoint() { + if (String.fromCodePoint) { + return; + } + String.fromCodePoint = __w_pdfjs_require__(113); + })(); + (function checkSymbol() { + if (globalScope.Symbol) { + return; + } + __w_pdfjs_require__(115); + })(); + (function checkObjectValues() { + if (Object.values) { + return; + } + Object.values = __w_pdfjs_require__(122); + })(); } -exports.CustomStyle = CustomStyle; -exports.addLinkAttributes = addLinkAttributes; -exports.isExternalLinkTargetSet = isExternalLinkTargetSet; -exports.isValidUrl = isValidUrl; -exports.getFilenameFromUrl = getFilenameFromUrl; -exports.LinkTarget = LinkTarget; -exports.RenderingCancelledException = RenderingCancelledException; -exports.hasCanvasTypedArrays = hasCanvasTypedArrays; -exports.getDefaultSetting = getDefaultSetting; -exports.DEFAULT_LINK_REL = DEFAULT_LINK_REL; -exports.DOMCanvasFactory = DOMCanvasFactory; -exports.DOMCMapReaderFactory = DOMCMapReaderFactory; /***/ }), -/* 2 */ +/* 3 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; -var sharedUtil = __w_pdfjs_require__(0); -var displayDOMUtils = __w_pdfjs_require__(1); -var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType; -var AnnotationType = sharedUtil.AnnotationType; -var stringToPDFString = sharedUtil.stringToPDFString; -var Util = sharedUtil.Util; -var addLinkAttributes = displayDOMUtils.addLinkAttributes; -var LinkTarget = displayDOMUtils.LinkTarget; -var getFilenameFromUrl = displayDOMUtils.getFilenameFromUrl; -var warn = sharedUtil.warn; -var CustomStyle = displayDOMUtils.CustomStyle; -var getDefaultSetting = displayDOMUtils.getDefaultSetting; -function AnnotationElementFactory() {} -AnnotationElementFactory.prototype = { - create: function AnnotationElementFactory_create(parameters) { - var subtype = parameters.data.annotationType; - switch (subtype) { - case AnnotationType.LINK: - return new LinkAnnotationElement(parameters); - case AnnotationType.TEXT: - return new TextAnnotationElement(parameters); - case AnnotationType.WIDGET: - var fieldType = parameters.data.fieldType; - switch (fieldType) { - case 'Tx': - return new TextWidgetAnnotationElement(parameters); - case 'Btn': - if (parameters.data.radioButton) { - return new RadioButtonWidgetAnnotationElement(parameters); - } else if (parameters.data.checkBox) { - return new CheckboxWidgetAnnotationElement(parameters); - } - warn('Unimplemented button widget annotation: pushbutton'); - break; - case 'Ch': - return new ChoiceWidgetAnnotationElement(parameters); - } - return new WidgetAnnotationElement(parameters); - case AnnotationType.POPUP: - return new PopupAnnotationElement(parameters); - case AnnotationType.HIGHLIGHT: - return new HighlightAnnotationElement(parameters); - case AnnotationType.UNDERLINE: - return new UnderlineAnnotationElement(parameters); - case AnnotationType.SQUIGGLY: - return new SquigglyAnnotationElement(parameters); - case AnnotationType.STRIKEOUT: - return new StrikeOutAnnotationElement(parameters); - case AnnotationType.FILEATTACHMENT: - return new FileAttachmentAnnotationElement(parameters); - default: - return new AnnotationElement(parameters); - } - } +module.exports = typeof window !== 'undefined' && window.Math === Math ? window : typeof global !== 'undefined' && global.Math === Math ? global : typeof self !== 'undefined' && self.Math === Math ? self : {}; + +/***/ }), +/* 4 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; + +module.exports = function isNodeJS() { + return (typeof process === 'undefined' ? 'undefined' : _typeof(process)) === 'object' && process + '' === '[object process]'; }; -var AnnotationElement = function AnnotationElementClosure() { - function AnnotationElement(parameters, isRenderable) { - this.isRenderable = isRenderable || false; - this.data = parameters.data; - this.layer = parameters.layer; - this.page = parameters.page; - this.viewport = parameters.viewport; - this.linkService = parameters.linkService; - this.downloadManager = parameters.downloadManager; - this.imageResourcesPath = parameters.imageResourcesPath; - this.renderInteractiveForms = parameters.renderInteractiveForms; - if (isRenderable) { - this.container = this._createContainer(); - } - } - AnnotationElement.prototype = { - _createContainer: function AnnotationElement_createContainer() { - var data = this.data, - page = this.page, - viewport = this.viewport; - var container = document.createElement('section'); - var width = data.rect[2] - data.rect[0]; - var height = data.rect[3] - data.rect[1]; - container.setAttribute('data-annotation-id', data.id); - var rect = Util.normalizeRect([data.rect[0], page.view[3] - data.rect[1] + page.view[1], data.rect[2], page.view[3] - data.rect[3] + page.view[1]]); - CustomStyle.setProp('transform', container, 'matrix(' + viewport.transform.join(',') + ')'); - CustomStyle.setProp('transformOrigin', container, -rect[0] + 'px ' + -rect[1] + 'px'); - if (data.borderStyle.width > 0) { - container.style.borderWidth = data.borderStyle.width + 'px'; - if (data.borderStyle.style !== AnnotationBorderStyleType.UNDERLINE) { - width = width - 2 * data.borderStyle.width; - height = height - 2 * data.borderStyle.width; - } - var horizontalRadius = data.borderStyle.horizontalCornerRadius; - var verticalRadius = data.borderStyle.verticalCornerRadius; - if (horizontalRadius > 0 || verticalRadius > 0) { - var radius = horizontalRadius + 'px / ' + verticalRadius + 'px'; - CustomStyle.setProp('borderRadius', container, radius); - } - switch (data.borderStyle.style) { - case AnnotationBorderStyleType.SOLID: - container.style.borderStyle = 'solid'; - break; - case AnnotationBorderStyleType.DASHED: - container.style.borderStyle = 'dashed'; - break; - case AnnotationBorderStyleType.BEVELED: - warn('Unimplemented border style: beveled'); - break; - case AnnotationBorderStyleType.INSET: - warn('Unimplemented border style: inset'); - break; - case AnnotationBorderStyleType.UNDERLINE: - container.style.borderBottomStyle = 'solid'; - break; - default: - break; - } - if (data.color) { - container.style.borderColor = Util.makeCssRgb(data.color[0] | 0, data.color[1] | 0, data.color[2] | 0); - } else { - container.style.borderWidth = 0; - } - } - container.style.left = rect[0] + 'px'; - container.style.top = rect[1] + 'px'; - container.style.width = width + 'px'; - container.style.height = height + 'px'; - return container; - }, - _createPopup: function AnnotationElement_createPopup(container, trigger, data) { - if (!trigger) { - trigger = document.createElement('div'); - trigger.style.height = container.style.height; - trigger.style.width = container.style.width; - container.appendChild(trigger); - } - var popupElement = new PopupElement({ - container: container, - trigger: trigger, - color: data.color, - title: data.title, - contents: data.contents, - hideWrapper: true - }); - var popup = popupElement.render(); - popup.style.left = container.style.width; - container.appendChild(popup); - }, - render: function AnnotationElement_render() { - throw new Error('Abstract method AnnotationElement.render called'); + +/***/ }), +/* 5 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +__w_pdfjs_require__(6); +module.exports = __w_pdfjs_require__(9).String.includes; + +/***/ }), +/* 6 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var $export = __w_pdfjs_require__(7); +var context = __w_pdfjs_require__(25); +var INCLUDES = 'includes'; +$export($export.P + $export.F * __w_pdfjs_require__(32)(INCLUDES), 'String', { + includes: function includes(searchString) { + return !!~context(this, searchString, INCLUDES).indexOf(searchString, arguments.length > 1 ? arguments[1] : undefined); + } +}); + +/***/ }), +/* 7 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var global = __w_pdfjs_require__(8); +var core = __w_pdfjs_require__(9); +var hide = __w_pdfjs_require__(10); +var redefine = __w_pdfjs_require__(20); +var ctx = __w_pdfjs_require__(23); +var PROTOTYPE = 'prototype'; +var $export = function $export(type, name, source) { + var IS_FORCED = type & $export.F; + var IS_GLOBAL = type & $export.G; + var IS_STATIC = type & $export.S; + var IS_PROTO = type & $export.P; + var IS_BIND = type & $export.B; + var target = IS_GLOBAL ? global : IS_STATIC ? global[name] || (global[name] = {}) : (global[name] || {})[PROTOTYPE]; + var exports = IS_GLOBAL ? core : core[name] || (core[name] = {}); + var expProto = exports[PROTOTYPE] || (exports[PROTOTYPE] = {}); + var key, own, out, exp; + if (IS_GLOBAL) source = name; + for (key in source) { + own = !IS_FORCED && target && target[key] !== undefined; + out = (own ? target : source)[key]; + exp = IS_BIND && own ? ctx(out, global) : IS_PROTO && typeof out == 'function' ? ctx(Function.call, out) : out; + if (target) redefine(target, key, out, type & $export.U); + if (exports[key] != out) hide(exports, key, exp); + if (IS_PROTO && expProto[key] != out) expProto[key] = out; + } +}; +global.core = core; +$export.F = 1; +$export.G = 2; +$export.S = 4; +$export.P = 8; +$export.B = 16; +$export.W = 32; +$export.U = 64; +$export.R = 128; +module.exports = $export; + +/***/ }), +/* 8 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var global = module.exports = typeof window != 'undefined' && window.Math == Math ? window : typeof self != 'undefined' && self.Math == Math ? self : Function('return this')(); +if (typeof __g == 'number') __g = global; + +/***/ }), +/* 9 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var core = module.exports = { version: '2.5.7' }; +if (typeof __e == 'number') __e = core; + +/***/ }), +/* 10 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var dP = __w_pdfjs_require__(11); +var createDesc = __w_pdfjs_require__(19); +module.exports = __w_pdfjs_require__(15) ? function (object, key, value) { + return dP.f(object, key, createDesc(1, value)); +} : function (object, key, value) { + object[key] = value; + return object; +}; + +/***/ }), +/* 11 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var anObject = __w_pdfjs_require__(12); +var IE8_DOM_DEFINE = __w_pdfjs_require__(14); +var toPrimitive = __w_pdfjs_require__(18); +var dP = Object.defineProperty; +exports.f = __w_pdfjs_require__(15) ? Object.defineProperty : function defineProperty(O, P, Attributes) { + anObject(O); + P = toPrimitive(P, true); + anObject(Attributes); + if (IE8_DOM_DEFINE) try { + return dP(O, P, Attributes); + } catch (e) {} + if ('get' in Attributes || 'set' in Attributes) throw TypeError('Accessors not supported!'); + if ('value' in Attributes) O[P] = Attributes.value; + return O; +}; + +/***/ }), +/* 12 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var isObject = __w_pdfjs_require__(13); +module.exports = function (it) { + if (!isObject(it)) throw TypeError(it + ' is not an object!'); + return it; +}; + +/***/ }), +/* 13 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; + +module.exports = function (it) { + return (typeof it === 'undefined' ? 'undefined' : _typeof(it)) === 'object' ? it !== null : typeof it === 'function'; +}; + +/***/ }), +/* 14 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +module.exports = !__w_pdfjs_require__(15) && !__w_pdfjs_require__(16)(function () { + return Object.defineProperty(__w_pdfjs_require__(17)('div'), 'a', { + get: function get() { + return 7; } + }).a != 7; +}); + +/***/ }), +/* 15 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +module.exports = !__w_pdfjs_require__(16)(function () { + return Object.defineProperty({}, 'a', { + get: function get() { + return 7; + } + }).a != 7; +}); + +/***/ }), +/* 16 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +module.exports = function (exec) { + try { + return !!exec(); + } catch (e) { + return true; + } +}; + +/***/ }), +/* 17 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var isObject = __w_pdfjs_require__(13); +var document = __w_pdfjs_require__(8).document; +var is = isObject(document) && isObject(document.createElement); +module.exports = function (it) { + return is ? document.createElement(it) : {}; +}; + +/***/ }), +/* 18 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var isObject = __w_pdfjs_require__(13); +module.exports = function (it, S) { + if (!isObject(it)) return it; + var fn, val; + if (S && typeof (fn = it.toString) == 'function' && !isObject(val = fn.call(it))) return val; + if (typeof (fn = it.valueOf) == 'function' && !isObject(val = fn.call(it))) return val; + if (!S && typeof (fn = it.toString) == 'function' && !isObject(val = fn.call(it))) return val; + throw TypeError("Can't convert object to primitive value"); +}; + +/***/ }), +/* 19 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +module.exports = function (bitmap, value) { + return { + enumerable: !(bitmap & 1), + configurable: !(bitmap & 2), + writable: !(bitmap & 4), + value: value }; - return AnnotationElement; -}(); -var LinkAnnotationElement = function LinkAnnotationElementClosure() { - function LinkAnnotationElement(parameters) { - AnnotationElement.call(this, parameters, true); +}; + +/***/ }), +/* 20 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var global = __w_pdfjs_require__(8); +var hide = __w_pdfjs_require__(10); +var has = __w_pdfjs_require__(21); +var SRC = __w_pdfjs_require__(22)('src'); +var TO_STRING = 'toString'; +var $toString = Function[TO_STRING]; +var TPL = ('' + $toString).split(TO_STRING); +__w_pdfjs_require__(9).inspectSource = function (it) { + return $toString.call(it); +}; +(module.exports = function (O, key, val, safe) { + var isFunction = typeof val == 'function'; + if (isFunction) has(val, 'name') || hide(val, 'name', key); + if (O[key] === val) return; + if (isFunction) has(val, SRC) || hide(val, SRC, O[key] ? '' + O[key] : TPL.join(String(key))); + if (O === global) { + O[key] = val; + } else if (!safe) { + delete O[key]; + hide(O, key, val); + } else if (O[key]) { + O[key] = val; + } else { + hide(O, key, val); } - Util.inherit(LinkAnnotationElement, AnnotationElement, { - render: function LinkAnnotationElement_render() { - this.container.className = 'linkAnnotation'; - var link = document.createElement('a'); - addLinkAttributes(link, { - url: this.data.url, - target: this.data.newWindow ? LinkTarget.BLANK : undefined - }); - if (!this.data.url) { - if (this.data.action) { - this._bindNamedAction(link, this.data.action); - } else { - this._bindLink(link, this.data.dest); - } - } - this.container.appendChild(link); - return this.container; - }, - _bindLink: function LinkAnnotationElement_bindLink(link, destination) { - var self = this; - link.href = this.linkService.getDestinationHash(destination); - link.onclick = function () { - if (destination) { - self.linkService.navigateTo(destination); - } - return false; +})(Function.prototype, TO_STRING, function toString() { + return typeof this == 'function' && this[SRC] || $toString.call(this); +}); + +/***/ }), +/* 21 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var hasOwnProperty = {}.hasOwnProperty; +module.exports = function (it, key) { + return hasOwnProperty.call(it, key); +}; + +/***/ }), +/* 22 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var id = 0; +var px = Math.random(); +module.exports = function (key) { + return 'Symbol('.concat(key === undefined ? '' : key, ')_', (++id + px).toString(36)); +}; + +/***/ }), +/* 23 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var aFunction = __w_pdfjs_require__(24); +module.exports = function (fn, that, length) { + aFunction(fn); + if (that === undefined) return fn; + switch (length) { + case 1: + return function (a) { + return fn.call(that, a); }; - if (destination) { - link.className = 'internalLink'; - } - }, - _bindNamedAction: function LinkAnnotationElement_bindNamedAction(link, action) { - var self = this; - link.href = this.linkService.getAnchorUrl(''); - link.onclick = function () { - self.linkService.executeNamedAction(action); - return false; + case 2: + return function (a, b) { + return fn.call(that, a, b); + }; + case 3: + return function (a, b, c) { + return fn.call(that, a, b, c); }; - link.className = 'internalLink'; - } - }); - return LinkAnnotationElement; -}(); -var TextAnnotationElement = function TextAnnotationElementClosure() { - function TextAnnotationElement(parameters) { - var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents); - AnnotationElement.call(this, parameters, isRenderable); } - Util.inherit(TextAnnotationElement, AnnotationElement, { - render: function TextAnnotationElement_render() { - this.container.className = 'textAnnotation'; - var image = document.createElement('img'); - image.style.height = this.container.style.height; - image.style.width = this.container.style.width; - image.src = this.imageResourcesPath + 'annotation-' + this.data.name.toLowerCase() + '.svg'; - image.alt = '[{{type}} Annotation]'; - image.dataset.l10nId = 'text_annotation_type'; - image.dataset.l10nArgs = JSON.stringify({ type: this.data.name }); - if (!this.data.hasPopup) { - this._createPopup(this.container, image, this.data); - } - this.container.appendChild(image); - return this.container; - } - }); - return TextAnnotationElement; -}(); -var WidgetAnnotationElement = function WidgetAnnotationElementClosure() { - function WidgetAnnotationElement(parameters, isRenderable) { - AnnotationElement.call(this, parameters, isRenderable); + return function () { + return fn.apply(that, arguments); + }; +}; + +/***/ }), +/* 24 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +module.exports = function (it) { + if (typeof it != 'function') throw TypeError(it + ' is not a function!'); + return it; +}; + +/***/ }), +/* 25 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var isRegExp = __w_pdfjs_require__(26); +var defined = __w_pdfjs_require__(31); +module.exports = function (that, searchString, NAME) { + if (isRegExp(searchString)) throw TypeError('String#' + NAME + " doesn't accept regex!"); + return String(defined(that)); +}; + +/***/ }), +/* 26 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var isObject = __w_pdfjs_require__(13); +var cof = __w_pdfjs_require__(27); +var MATCH = __w_pdfjs_require__(28)('match'); +module.exports = function (it) { + var isRegExp; + return isObject(it) && ((isRegExp = it[MATCH]) !== undefined ? !!isRegExp : cof(it) == 'RegExp'); +}; + +/***/ }), +/* 27 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var toString = {}.toString; +module.exports = function (it) { + return toString.call(it).slice(8, -1); +}; + +/***/ }), +/* 28 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var store = __w_pdfjs_require__(29)('wks'); +var uid = __w_pdfjs_require__(22); +var _Symbol = __w_pdfjs_require__(8).Symbol; +var USE_SYMBOL = typeof _Symbol == 'function'; +var $exports = module.exports = function (name) { + return store[name] || (store[name] = USE_SYMBOL && _Symbol[name] || (USE_SYMBOL ? _Symbol : uid)('Symbol.' + name)); +}; +$exports.store = store; + +/***/ }), +/* 29 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var core = __w_pdfjs_require__(9); +var global = __w_pdfjs_require__(8); +var SHARED = '__core-js_shared__'; +var store = global[SHARED] || (global[SHARED] = {}); +(module.exports = function (key, value) { + return store[key] || (store[key] = value !== undefined ? value : {}); +})('versions', []).push({ + version: core.version, + mode: __w_pdfjs_require__(30) ? 'pure' : 'global', + copyright: '© 2018 Denis Pushkarev (zloirock.ru)' +}); + +/***/ }), +/* 30 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +module.exports = false; + +/***/ }), +/* 31 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +module.exports = function (it) { + if (it == undefined) throw TypeError("Can't call method on " + it); + return it; +}; + +/***/ }), +/* 32 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var MATCH = __w_pdfjs_require__(28)('match'); +module.exports = function (KEY) { + var re = /./; + try { + '/./'[KEY](re); + } catch (e) { + try { + re[MATCH] = false; + return !'/./'[KEY](re); + } catch (f) {} } - Util.inherit(WidgetAnnotationElement, AnnotationElement, { - render: function WidgetAnnotationElement_render() { - return this.container; - } - }); - return WidgetAnnotationElement; -}(); -var TextWidgetAnnotationElement = function TextWidgetAnnotationElementClosure() { - var TEXT_ALIGNMENT = ['left', 'center', 'right']; - function TextWidgetAnnotationElement(parameters) { - var isRenderable = parameters.renderInteractiveForms || !parameters.data.hasAppearance && !!parameters.data.fieldValue; - WidgetAnnotationElement.call(this, parameters, isRenderable); + return true; +}; + +/***/ }), +/* 33 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +__w_pdfjs_require__(34); +module.exports = __w_pdfjs_require__(9).Array.includes; + +/***/ }), +/* 34 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var $export = __w_pdfjs_require__(7); +var $includes = __w_pdfjs_require__(35)(true); +$export($export.P, 'Array', { + includes: function includes(el) { + return $includes(this, el, arguments.length > 1 ? arguments[1] : undefined); } - Util.inherit(TextWidgetAnnotationElement, WidgetAnnotationElement, { - render: function TextWidgetAnnotationElement_render() { - this.container.className = 'textWidgetAnnotation'; - var element = null; - if (this.renderInteractiveForms) { - if (this.data.multiLine) { - element = document.createElement('textarea'); - element.textContent = this.data.fieldValue; - } else { - element = document.createElement('input'); - element.type = 'text'; - element.setAttribute('value', this.data.fieldValue); - } - element.disabled = this.data.readOnly; - if (this.data.maxLen !== null) { - element.maxLength = this.data.maxLen; - } - if (this.data.comb) { - var fieldWidth = this.data.rect[2] - this.data.rect[0]; - var combWidth = fieldWidth / this.data.maxLen; - element.classList.add('comb'); - element.style.letterSpacing = 'calc(' + combWidth + 'px - 1ch)'; - } - } else { - element = document.createElement('div'); - element.textContent = this.data.fieldValue; - element.style.verticalAlign = 'middle'; - element.style.display = 'table-cell'; - var font = null; - if (this.data.fontRefName) { - font = this.page.commonObjs.getData(this.data.fontRefName); - } - this._setTextStyle(element, font); - } - if (this.data.textAlignment !== null) { - element.style.textAlign = TEXT_ALIGNMENT[this.data.textAlignment]; - } - this.container.appendChild(element); - return this.container; - }, - _setTextStyle: function TextWidgetAnnotationElement_setTextStyle(element, font) { - var style = element.style; - style.fontSize = this.data.fontSize + 'px'; - style.direction = this.data.fontDirection < 0 ? 'rtl' : 'ltr'; - if (!font) { - return; - } - style.fontWeight = font.black ? font.bold ? '900' : 'bold' : font.bold ? 'bold' : 'normal'; - style.fontStyle = font.italic ? 'italic' : 'normal'; - var fontFamily = font.loadedName ? '"' + font.loadedName + '", ' : ''; - var fallbackName = font.fallbackName || 'Helvetica, sans-serif'; - style.fontFamily = fontFamily + fallbackName; - } +}); +__w_pdfjs_require__(41)('includes'); + +/***/ }), +/* 35 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var toIObject = __w_pdfjs_require__(36); +var toLength = __w_pdfjs_require__(38); +var toAbsoluteIndex = __w_pdfjs_require__(40); +module.exports = function (IS_INCLUDES) { + return function ($this, el, fromIndex) { + var O = toIObject($this); + var length = toLength(O.length); + var index = toAbsoluteIndex(fromIndex, length); + var value; + if (IS_INCLUDES && el != el) while (length > index) { + value = O[index++]; + if (value != value) return true; + } else for (; length > index; index++) { + if (IS_INCLUDES || index in O) { + if (O[index] === el) return IS_INCLUDES || index || 0; + } + }return !IS_INCLUDES && -1; + }; +}; + +/***/ }), +/* 36 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var IObject = __w_pdfjs_require__(37); +var defined = __w_pdfjs_require__(31); +module.exports = function (it) { + return IObject(defined(it)); +}; + +/***/ }), +/* 37 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var cof = __w_pdfjs_require__(27); +module.exports = Object('z').propertyIsEnumerable(0) ? Object : function (it) { + return cof(it) == 'String' ? it.split('') : Object(it); +}; + +/***/ }), +/* 38 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var toInteger = __w_pdfjs_require__(39); +var min = Math.min; +module.exports = function (it) { + return it > 0 ? min(toInteger(it), 0x1fffffffffffff) : 0; +}; + +/***/ }), +/* 39 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var ceil = Math.ceil; +var floor = Math.floor; +module.exports = function (it) { + return isNaN(it = +it) ? 0 : (it > 0 ? floor : ceil)(it); +}; + +/***/ }), +/* 40 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var toInteger = __w_pdfjs_require__(39); +var max = Math.max; +var min = Math.min; +module.exports = function (index, length) { + index = toInteger(index); + return index < 0 ? max(index + length, 0) : min(index, length); +}; + +/***/ }), +/* 41 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var UNSCOPABLES = __w_pdfjs_require__(28)('unscopables'); +var ArrayProto = Array.prototype; +if (ArrayProto[UNSCOPABLES] == undefined) __w_pdfjs_require__(10)(ArrayProto, UNSCOPABLES, {}); +module.exports = function (key) { + ArrayProto[UNSCOPABLES][key] = true; +}; + +/***/ }), +/* 42 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +__w_pdfjs_require__(43); +module.exports = __w_pdfjs_require__(9).Object.assign; + +/***/ }), +/* 43 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var $export = __w_pdfjs_require__(7); +$export($export.S + $export.F, 'Object', { assign: __w_pdfjs_require__(44) }); + +/***/ }), +/* 44 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var getKeys = __w_pdfjs_require__(45); +var gOPS = __w_pdfjs_require__(49); +var pIE = __w_pdfjs_require__(50); +var toObject = __w_pdfjs_require__(51); +var IObject = __w_pdfjs_require__(37); +var $assign = Object.assign; +module.exports = !$assign || __w_pdfjs_require__(16)(function () { + var A = {}; + var B = {}; + var S = Symbol(); + var K = 'abcdefghijklmnopqrst'; + A[S] = 7; + K.split('').forEach(function (k) { + B[k] = k; }); - return TextWidgetAnnotationElement; -}(); -var CheckboxWidgetAnnotationElement = function CheckboxWidgetAnnotationElementClosure() { - function CheckboxWidgetAnnotationElement(parameters) { - WidgetAnnotationElement.call(this, parameters, parameters.renderInteractiveForms); + return $assign({}, A)[S] != 7 || Object.keys($assign({}, B)).join('') != K; +}) ? function assign(target, source) { + var T = toObject(target); + var aLen = arguments.length; + var index = 1; + var getSymbols = gOPS.f; + var isEnum = pIE.f; + while (aLen > index) { + var S = IObject(arguments[index++]); + var keys = getSymbols ? getKeys(S).concat(getSymbols(S)) : getKeys(S); + var length = keys.length; + var j = 0; + var key; + while (length > j) { + if (isEnum.call(S, key = keys[j++])) T[key] = S[key]; + } } - Util.inherit(CheckboxWidgetAnnotationElement, WidgetAnnotationElement, { - render: function CheckboxWidgetAnnotationElement_render() { - this.container.className = 'buttonWidgetAnnotation checkBox'; - var element = document.createElement('input'); - element.disabled = this.data.readOnly; - element.type = 'checkbox'; - if (this.data.fieldValue && this.data.fieldValue !== 'Off') { - element.setAttribute('checked', true); - } - this.container.appendChild(element); - return this.container; - } - }); - return CheckboxWidgetAnnotationElement; -}(); -var RadioButtonWidgetAnnotationElement = function RadioButtonWidgetAnnotationElementClosure() { - function RadioButtonWidgetAnnotationElement(parameters) { - WidgetAnnotationElement.call(this, parameters, parameters.renderInteractiveForms); - } - Util.inherit(RadioButtonWidgetAnnotationElement, WidgetAnnotationElement, { - render: function RadioButtonWidgetAnnotationElement_render() { - this.container.className = 'buttonWidgetAnnotation radioButton'; - var element = document.createElement('input'); - element.disabled = this.data.readOnly; - element.type = 'radio'; - element.name = this.data.fieldName; - if (this.data.fieldValue === this.data.buttonValue) { - element.setAttribute('checked', true); - } - this.container.appendChild(element); - return this.container; - } - }); - return RadioButtonWidgetAnnotationElement; -}(); -var ChoiceWidgetAnnotationElement = function ChoiceWidgetAnnotationElementClosure() { - function ChoiceWidgetAnnotationElement(parameters) { - WidgetAnnotationElement.call(this, parameters, parameters.renderInteractiveForms); - } - Util.inherit(ChoiceWidgetAnnotationElement, WidgetAnnotationElement, { - render: function ChoiceWidgetAnnotationElement_render() { - this.container.className = 'choiceWidgetAnnotation'; - var selectElement = document.createElement('select'); - selectElement.disabled = this.data.readOnly; - if (!this.data.combo) { - selectElement.size = this.data.options.length; - if (this.data.multiSelect) { - selectElement.multiple = true; - } - } - for (var i = 0, ii = this.data.options.length; i < ii; i++) { - var option = this.data.options[i]; - var optionElement = document.createElement('option'); - optionElement.textContent = option.displayValue; - optionElement.value = option.exportValue; - if (this.data.fieldValue.indexOf(option.displayValue) >= 0) { - optionElement.setAttribute('selected', true); - } - selectElement.appendChild(optionElement); - } - this.container.appendChild(selectElement); - return this.container; - } - }); - return ChoiceWidgetAnnotationElement; -}(); -var PopupAnnotationElement = function PopupAnnotationElementClosure() { - function PopupAnnotationElement(parameters) { - var isRenderable = !!(parameters.data.title || parameters.data.contents); - AnnotationElement.call(this, parameters, isRenderable); - } - Util.inherit(PopupAnnotationElement, AnnotationElement, { - render: function PopupAnnotationElement_render() { - this.container.className = 'popupAnnotation'; - var selector = '[data-annotation-id="' + this.data.parentId + '"]'; - var parentElement = this.layer.querySelector(selector); - if (!parentElement) { - return this.container; - } - var popup = new PopupElement({ - container: this.container, - trigger: parentElement, - color: this.data.color, - title: this.data.title, - contents: this.data.contents - }); - var parentLeft = parseFloat(parentElement.style.left); - var parentWidth = parseFloat(parentElement.style.width); - CustomStyle.setProp('transformOrigin', this.container, -(parentLeft + parentWidth) + 'px -' + parentElement.style.top); - this.container.style.left = parentLeft + parentWidth + 'px'; - this.container.appendChild(popup.render()); - return this.container; - } - }); - return PopupAnnotationElement; -}(); -var PopupElement = function PopupElementClosure() { - var BACKGROUND_ENLIGHT = 0.7; - function PopupElement(parameters) { - this.container = parameters.container; - this.trigger = parameters.trigger; - this.color = parameters.color; - this.title = parameters.title; - this.contents = parameters.contents; - this.hideWrapper = parameters.hideWrapper || false; - this.pinned = false; - } - PopupElement.prototype = { - render: function PopupElement_render() { - var wrapper = document.createElement('div'); - wrapper.className = 'popupWrapper'; - this.hideElement = this.hideWrapper ? wrapper : this.container; - this.hideElement.setAttribute('hidden', true); - var popup = document.createElement('div'); - popup.className = 'popup'; - var color = this.color; - if (color) { - var r = BACKGROUND_ENLIGHT * (255 - color[0]) + color[0]; - var g = BACKGROUND_ENLIGHT * (255 - color[1]) + color[1]; - var b = BACKGROUND_ENLIGHT * (255 - color[2]) + color[2]; - popup.style.backgroundColor = Util.makeCssRgb(r | 0, g | 0, b | 0); - } - var contents = this._formatContents(this.contents); - var title = document.createElement('h1'); - title.textContent = this.title; - this.trigger.addEventListener('click', this._toggle.bind(this)); - this.trigger.addEventListener('mouseover', this._show.bind(this, false)); - this.trigger.addEventListener('mouseout', this._hide.bind(this, false)); - popup.addEventListener('click', this._hide.bind(this, true)); - popup.appendChild(title); - popup.appendChild(contents); - wrapper.appendChild(popup); - return wrapper; - }, - _formatContents: function PopupElement_formatContents(contents) { - var p = document.createElement('p'); - var lines = contents.split(/(?:\r\n?|\n)/); - for (var i = 0, ii = lines.length; i < ii; ++i) { - var line = lines[i]; - p.appendChild(document.createTextNode(line)); - if (i < ii - 1) { - p.appendChild(document.createElement('br')); - } - } - return p; - }, - _toggle: function PopupElement_toggle() { - if (this.pinned) { - this._hide(true); - } else { - this._show(true); - } - }, - _show: function PopupElement_show(pin) { - if (pin) { - this.pinned = true; - } - if (this.hideElement.hasAttribute('hidden')) { - this.hideElement.removeAttribute('hidden'); - this.container.style.zIndex += 1; - } - }, - _hide: function PopupElement_hide(unpin) { - if (unpin) { - this.pinned = false; - } - if (!this.hideElement.hasAttribute('hidden') && !this.pinned) { - this.hideElement.setAttribute('hidden', true); - this.container.style.zIndex -= 1; - } - } - }; - return PopupElement; -}(); -var HighlightAnnotationElement = function HighlightAnnotationElementClosure() { - function HighlightAnnotationElement(parameters) { - var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents); - AnnotationElement.call(this, parameters, isRenderable); - } - Util.inherit(HighlightAnnotationElement, AnnotationElement, { - render: function HighlightAnnotationElement_render() { - this.container.className = 'highlightAnnotation'; - if (!this.data.hasPopup) { - this._createPopup(this.container, null, this.data); - } - return this.container; - } - }); - return HighlightAnnotationElement; -}(); -var UnderlineAnnotationElement = function UnderlineAnnotationElementClosure() { - function UnderlineAnnotationElement(parameters) { - var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents); - AnnotationElement.call(this, parameters, isRenderable); - } - Util.inherit(UnderlineAnnotationElement, AnnotationElement, { - render: function UnderlineAnnotationElement_render() { - this.container.className = 'underlineAnnotation'; - if (!this.data.hasPopup) { - this._createPopup(this.container, null, this.data); - } - return this.container; - } - }); - return UnderlineAnnotationElement; -}(); -var SquigglyAnnotationElement = function SquigglyAnnotationElementClosure() { - function SquigglyAnnotationElement(parameters) { - var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents); - AnnotationElement.call(this, parameters, isRenderable); - } - Util.inherit(SquigglyAnnotationElement, AnnotationElement, { - render: function SquigglyAnnotationElement_render() { - this.container.className = 'squigglyAnnotation'; - if (!this.data.hasPopup) { - this._createPopup(this.container, null, this.data); - } - return this.container; - } - }); - return SquigglyAnnotationElement; -}(); -var StrikeOutAnnotationElement = function StrikeOutAnnotationElementClosure() { - function StrikeOutAnnotationElement(parameters) { - var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents); - AnnotationElement.call(this, parameters, isRenderable); - } - Util.inherit(StrikeOutAnnotationElement, AnnotationElement, { - render: function StrikeOutAnnotationElement_render() { - this.container.className = 'strikeoutAnnotation'; - if (!this.data.hasPopup) { - this._createPopup(this.container, null, this.data); - } - return this.container; - } - }); - return StrikeOutAnnotationElement; -}(); -var FileAttachmentAnnotationElement = function FileAttachmentAnnotationElementClosure() { - function FileAttachmentAnnotationElement(parameters) { - AnnotationElement.call(this, parameters, true); - var file = this.data.file; - this.filename = getFilenameFromUrl(file.filename); - this.content = file.content; - this.linkService.onFileAttachmentAnnotation({ - id: stringToPDFString(file.filename), - filename: file.filename, - content: file.content - }); - } - Util.inherit(FileAttachmentAnnotationElement, AnnotationElement, { - render: function FileAttachmentAnnotationElement_render() { - this.container.className = 'fileAttachmentAnnotation'; - var trigger = document.createElement('div'); - trigger.style.height = this.container.style.height; - trigger.style.width = this.container.style.width; - trigger.addEventListener('dblclick', this._download.bind(this)); - if (!this.data.hasPopup && (this.data.title || this.data.contents)) { - this._createPopup(this.container, trigger, this.data); - } - this.container.appendChild(trigger); - return this.container; - }, - _download: function FileAttachmentAnnotationElement_download() { - if (!this.downloadManager) { - warn('Download cannot be started due to unavailable download manager'); - return; - } - this.downloadManager.downloadData(this.content, this.filename, ''); - } - }); - return FileAttachmentAnnotationElement; -}(); -var AnnotationLayer = function AnnotationLayerClosure() { - return { - render: function AnnotationLayer_render(parameters) { - var annotationElementFactory = new AnnotationElementFactory(); - for (var i = 0, ii = parameters.annotations.length; i < ii; i++) { - var data = parameters.annotations[i]; - if (!data) { - continue; - } - var element = annotationElementFactory.create({ - data: data, - layer: parameters.div, - page: parameters.page, - viewport: parameters.viewport, - linkService: parameters.linkService, - downloadManager: parameters.downloadManager, - imageResourcesPath: parameters.imageResourcesPath || getDefaultSetting('imageResourcesPath'), - renderInteractiveForms: parameters.renderInteractiveForms || false - }); - if (element.isRenderable) { - parameters.div.appendChild(element.render()); - } - } - }, - update: function AnnotationLayer_update(parameters) { - for (var i = 0, ii = parameters.annotations.length; i < ii; i++) { - var data = parameters.annotations[i]; - var element = parameters.div.querySelector('[data-annotation-id="' + data.id + '"]'); - if (element) { - CustomStyle.setProp('transform', element, 'matrix(' + parameters.viewport.transform.join(',') + ')'); - } - } - parameters.div.removeAttribute('hidden'); - } - }; -}(); -exports.AnnotationLayer = AnnotationLayer; + return T; +} : $assign; /***/ }), -/* 3 */ +/* 45 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; -var sharedUtil = __w_pdfjs_require__(0); -var displayFontLoader = __w_pdfjs_require__(11); -var displayCanvas = __w_pdfjs_require__(10); -var displayMetadata = __w_pdfjs_require__(7); -var displayDOMUtils = __w_pdfjs_require__(1); -var amdRequire; -var InvalidPDFException = sharedUtil.InvalidPDFException; -var MessageHandler = sharedUtil.MessageHandler; -var MissingPDFException = sharedUtil.MissingPDFException; -var PageViewport = sharedUtil.PageViewport; -var PasswordException = sharedUtil.PasswordException; -var StatTimer = sharedUtil.StatTimer; -var UnexpectedResponseException = sharedUtil.UnexpectedResponseException; -var UnknownErrorException = sharedUtil.UnknownErrorException; -var Util = sharedUtil.Util; -var createPromiseCapability = sharedUtil.createPromiseCapability; -var error = sharedUtil.error; -var deprecated = sharedUtil.deprecated; -var getVerbosityLevel = sharedUtil.getVerbosityLevel; -var info = sharedUtil.info; -var isInt = sharedUtil.isInt; -var isArray = sharedUtil.isArray; -var isArrayBuffer = sharedUtil.isArrayBuffer; -var isSameOrigin = sharedUtil.isSameOrigin; -var loadJpegStream = sharedUtil.loadJpegStream; -var stringToBytes = sharedUtil.stringToBytes; -var globalScope = sharedUtil.globalScope; -var warn = sharedUtil.warn; -var FontFaceObject = displayFontLoader.FontFaceObject; -var FontLoader = displayFontLoader.FontLoader; -var CanvasGraphics = displayCanvas.CanvasGraphics; -var Metadata = displayMetadata.Metadata; -var RenderingCancelledException = displayDOMUtils.RenderingCancelledException; -var getDefaultSetting = displayDOMUtils.getDefaultSetting; -var DOMCanvasFactory = displayDOMUtils.DOMCanvasFactory; -var DOMCMapReaderFactory = displayDOMUtils.DOMCMapReaderFactory; -var DEFAULT_RANGE_CHUNK_SIZE = 65536; -var isWorkerDisabled = false; -var workerSrc; -var isPostMessageTransfersDisabled = false; -var pdfjsFilePath = typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : null; -var fakeWorkerFilesLoader = null; -var useRequireEnsure = false; -if (typeof __pdfjsdev_webpack__ === 'undefined') { - if (typeof window === 'undefined') { - isWorkerDisabled = true; - if (typeof require.ensure === 'undefined') { - require.ensure = require('node-ensure'); - } - useRequireEnsure = true; - } else if (typeof require !== 'undefined' && typeof require.ensure === 'function') { - useRequireEnsure = true; - } - if (typeof requirejs !== 'undefined' && requirejs.toUrl) { - workerSrc = requirejs.toUrl('pdfjs-dist/build/pdf.worker.js'); - } - var dynamicLoaderSupported = typeof requirejs !== 'undefined' && requirejs.load; - fakeWorkerFilesLoader = useRequireEnsure ? function (callback) { - require.ensure([], function () { - var worker = require('./pdf.worker.js'); - callback(worker.WorkerMessageHandler); - }); - } : dynamicLoaderSupported ? function (callback) { - requirejs(['pdfjs-dist/build/pdf.worker'], function (worker) { - callback(worker.WorkerMessageHandler); - }); - } : null; -} -function getDocument(src, pdfDataRangeTransport, passwordCallback, progressCallback) { - var task = new PDFDocumentLoadingTask(); - if (arguments.length > 1) { - deprecated('getDocument is called with pdfDataRangeTransport, ' + 'passwordCallback or progressCallback argument'); - } - if (pdfDataRangeTransport) { - if (!(pdfDataRangeTransport instanceof PDFDataRangeTransport)) { - pdfDataRangeTransport = Object.create(pdfDataRangeTransport); - pdfDataRangeTransport.length = src.length; - pdfDataRangeTransport.initialData = src.initialData; - if (!pdfDataRangeTransport.abort) { - pdfDataRangeTransport.abort = function () {}; - } +var $keys = __w_pdfjs_require__(46); +var enumBugKeys = __w_pdfjs_require__(48); +module.exports = Object.keys || function keys(O) { + return $keys(O, enumBugKeys); +}; + +/***/ }), +/* 46 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var has = __w_pdfjs_require__(21); +var toIObject = __w_pdfjs_require__(36); +var arrayIndexOf = __w_pdfjs_require__(35)(false); +var IE_PROTO = __w_pdfjs_require__(47)('IE_PROTO'); +module.exports = function (object, names) { + var O = toIObject(object); + var i = 0; + var result = []; + var key; + for (key in O) { + if (key != IE_PROTO) has(O, key) && result.push(key); + }while (names.length > i) { + if (has(O, key = names[i++])) { + ~arrayIndexOf(result, key) || result.push(key); } - src = Object.create(src); - src.range = pdfDataRangeTransport; + }return result; +}; + +/***/ }), +/* 47 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var shared = __w_pdfjs_require__(29)('keys'); +var uid = __w_pdfjs_require__(22); +module.exports = function (key) { + return shared[key] || (shared[key] = uid(key)); +}; + +/***/ }), +/* 48 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +module.exports = 'constructor,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,toString,valueOf'.split(','); + +/***/ }), +/* 49 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +exports.f = Object.getOwnPropertySymbols; + +/***/ }), +/* 50 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +exports.f = {}.propertyIsEnumerable; + +/***/ }), +/* 51 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var defined = __w_pdfjs_require__(31); +module.exports = function (it) { + return Object(defined(it)); +}; + +/***/ }), +/* 52 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +__w_pdfjs_require__(53); +module.exports = __w_pdfjs_require__(9).Math.log2; + +/***/ }), +/* 53 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var $export = __w_pdfjs_require__(7); +$export($export.S, 'Math', { + log2: function log2(x) { + return Math.log(x) / Math.LN2; } - task.onPassword = passwordCallback || null; - task.onProgress = progressCallback || null; - var source; - if (typeof src === 'string') { - source = { url: src }; - } else if (isArrayBuffer(src)) { - source = { data: src }; - } else if (src instanceof PDFDataRangeTransport) { - source = { range: src }; - } else { - if (typeof src !== 'object') { - error('Invalid parameter in getDocument, need either Uint8Array, ' + 'string or a parameter object'); - } - if (!src.url && !src.data && !src.range) { - error('Invalid parameter object: need either .data, .range or .url'); - } - source = src; +}); + +/***/ }), +/* 54 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +__w_pdfjs_require__(55); +module.exports = __w_pdfjs_require__(9).Number.isNaN; + +/***/ }), +/* 55 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var $export = __w_pdfjs_require__(7); +$export($export.S, 'Number', { + isNaN: function isNaN(number) { + return number != number; } - var params = {}; - var rangeTransport = null; - var worker = null; - for (var key in source) { - if (key === 'url' && typeof window !== 'undefined') { - params[key] = new URL(source[key], window.location).href; - continue; - } else if (key === 'range') { - rangeTransport = source[key]; - continue; - } else if (key === 'worker') { - worker = source[key]; - continue; - } else if (key === 'data' && !(source[key] instanceof Uint8Array)) { - var pdfBytes = source[key]; - if (typeof pdfBytes === 'string') { - params[key] = stringToBytes(pdfBytes); - } else if (typeof pdfBytes === 'object' && pdfBytes !== null && !isNaN(pdfBytes.length)) { - params[key] = new Uint8Array(pdfBytes); - } else if (isArrayBuffer(pdfBytes)) { - params[key] = new Uint8Array(pdfBytes); - } else { - error('Invalid PDF binary data: either typed array, string or ' + 'array-like object is expected in the data property.'); - } - continue; +}); + +/***/ }), +/* 56 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +__w_pdfjs_require__(57); +module.exports = __w_pdfjs_require__(9).Number.isInteger; + +/***/ }), +/* 57 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var $export = __w_pdfjs_require__(7); +$export($export.S, 'Number', { isInteger: __w_pdfjs_require__(58) }); + +/***/ }), +/* 58 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var isObject = __w_pdfjs_require__(13); +var floor = Math.floor; +module.exports = function isInteger(it) { + return !isObject(it) && isFinite(it) && floor(it) === it; +}; + +/***/ }), +/* 59 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +__w_pdfjs_require__(60); +__w_pdfjs_require__(62); +__w_pdfjs_require__(72); +__w_pdfjs_require__(75); +__w_pdfjs_require__(92); +__w_pdfjs_require__(93); +module.exports = __w_pdfjs_require__(9).Promise; + +/***/ }), +/* 60 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var classof = __w_pdfjs_require__(61); +var test = {}; +test[__w_pdfjs_require__(28)('toStringTag')] = 'z'; +if (test + '' != '[object z]') { + __w_pdfjs_require__(20)(Object.prototype, 'toString', function toString() { + return '[object ' + classof(this) + ']'; + }, true); +} + +/***/ }), +/* 61 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var cof = __w_pdfjs_require__(27); +var TAG = __w_pdfjs_require__(28)('toStringTag'); +var ARG = cof(function () { + return arguments; +}()) == 'Arguments'; +var tryGet = function tryGet(it, key) { + try { + return it[key]; + } catch (e) {} +}; +module.exports = function (it) { + var O, T, B; + return it === undefined ? 'Undefined' : it === null ? 'Null' : typeof (T = tryGet(O = Object(it), TAG)) == 'string' ? T : ARG ? cof(O) : (B = cof(O)) == 'Object' && typeof O.callee == 'function' ? 'Arguments' : B; +}; + +/***/ }), +/* 62 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var $at = __w_pdfjs_require__(63)(true); +__w_pdfjs_require__(64)(String, 'String', function (iterated) { + this._t = String(iterated); + this._i = 0; +}, function () { + var O = this._t; + var index = this._i; + var point; + if (index >= O.length) return { + value: undefined, + done: true + }; + point = $at(O, index); + this._i += point.length; + return { + value: point, + done: false + }; +}); + +/***/ }), +/* 63 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var toInteger = __w_pdfjs_require__(39); +var defined = __w_pdfjs_require__(31); +module.exports = function (TO_STRING) { + return function (that, pos) { + var s = String(defined(that)); + var i = toInteger(pos); + var l = s.length; + var a, b; + if (i < 0 || i >= l) return TO_STRING ? '' : undefined; + a = s.charCodeAt(i); + return a < 0xd800 || a > 0xdbff || i + 1 === l || (b = s.charCodeAt(i + 1)) < 0xdc00 || b > 0xdfff ? TO_STRING ? s.charAt(i) : a : TO_STRING ? s.slice(i, i + 2) : (a - 0xd800 << 10) + (b - 0xdc00) + 0x10000; + }; +}; + +/***/ }), +/* 64 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var LIBRARY = __w_pdfjs_require__(30); +var $export = __w_pdfjs_require__(7); +var redefine = __w_pdfjs_require__(20); +var hide = __w_pdfjs_require__(10); +var Iterators = __w_pdfjs_require__(65); +var $iterCreate = __w_pdfjs_require__(66); +var setToStringTag = __w_pdfjs_require__(70); +var getPrototypeOf = __w_pdfjs_require__(71); +var ITERATOR = __w_pdfjs_require__(28)('iterator'); +var BUGGY = !([].keys && 'next' in [].keys()); +var FF_ITERATOR = '@@iterator'; +var KEYS = 'keys'; +var VALUES = 'values'; +var returnThis = function returnThis() { + return this; +}; +module.exports = function (Base, NAME, Constructor, next, DEFAULT, IS_SET, FORCED) { + $iterCreate(Constructor, NAME, next); + var getMethod = function getMethod(kind) { + if (!BUGGY && kind in proto) return proto[kind]; + switch (kind) { + case KEYS: + return function keys() { + return new Constructor(this, kind); + }; + case VALUES: + return function values() { + return new Constructor(this, kind); + }; } - params[key] = source[key]; - } - params.rangeChunkSize = params.rangeChunkSize || DEFAULT_RANGE_CHUNK_SIZE; - params.disableNativeImageDecoder = params.disableNativeImageDecoder === true; - var CMapReaderFactory = params.CMapReaderFactory || DOMCMapReaderFactory; - if (!worker) { - var workerPort = getDefaultSetting('workerPort'); - worker = workerPort ? new PDFWorker(null, workerPort) : new PDFWorker(); - task._worker = worker; - } - var docId = task.docId; - worker.promise.then(function () { - if (task.destroyed) { - throw new Error('Loading aborted'); + return function entries() { + return new Constructor(this, kind); + }; + }; + var TAG = NAME + ' Iterator'; + var DEF_VALUES = DEFAULT == VALUES; + var VALUES_BUG = false; + var proto = Base.prototype; + var $native = proto[ITERATOR] || proto[FF_ITERATOR] || DEFAULT && proto[DEFAULT]; + var $default = $native || getMethod(DEFAULT); + var $entries = DEFAULT ? !DEF_VALUES ? $default : getMethod('entries') : undefined; + var $anyNative = NAME == 'Array' ? proto.entries || $native : $native; + var methods, key, IteratorPrototype; + if ($anyNative) { + IteratorPrototype = getPrototypeOf($anyNative.call(new Base())); + if (IteratorPrototype !== Object.prototype && IteratorPrototype.next) { + setToStringTag(IteratorPrototype, TAG, true); + if (!LIBRARY && typeof IteratorPrototype[ITERATOR] != 'function') hide(IteratorPrototype, ITERATOR, returnThis); } - return _fetchDocument(worker, params, rangeTransport, docId).then(function (workerId) { - if (task.destroyed) { - throw new Error('Loading aborted'); - } - var messageHandler = new MessageHandler(docId, workerId, worker.port); - var transport = new WorkerTransport(messageHandler, task, rangeTransport, CMapReaderFactory); - task._transport = transport; - messageHandler.send('Ready', null); - }); - }).catch(task._capability.reject); - return task; -} -function _fetchDocument(worker, source, pdfDataRangeTransport, docId) { - if (worker.destroyed) { - return Promise.reject(new Error('Worker was destroyed')); } - source.disableAutoFetch = getDefaultSetting('disableAutoFetch'); - source.disableStream = getDefaultSetting('disableStream'); - source.chunkedViewerLoading = !!pdfDataRangeTransport; - if (pdfDataRangeTransport) { - source.length = pdfDataRangeTransport.length; - source.initialData = pdfDataRangeTransport.initialData; + if (DEF_VALUES && $native && $native.name !== VALUES) { + VALUES_BUG = true; + $default = function values() { + return $native.call(this); + }; } - return worker.messageHandler.sendWithPromise('GetDocRequest', { - docId: docId, - source: source, - disableRange: getDefaultSetting('disableRange'), - maxImageSize: getDefaultSetting('maxImageSize'), - disableFontFace: getDefaultSetting('disableFontFace'), - disableCreateObjectURL: getDefaultSetting('disableCreateObjectURL'), - postMessageTransfers: getDefaultSetting('postMessageTransfers') && !isPostMessageTransfersDisabled, - docBaseUrl: source.docBaseUrl, - disableNativeImageDecoder: source.disableNativeImageDecoder - }).then(function (workerId) { - if (worker.destroyed) { - throw new Error('Worker was destroyed'); - } - return workerId; - }); -} -var PDFDocumentLoadingTask = function PDFDocumentLoadingTaskClosure() { - var nextDocumentId = 0; - function PDFDocumentLoadingTask() { - this._capability = createPromiseCapability(); - this._transport = null; - this._worker = null; - this.docId = 'd' + nextDocumentId++; - this.destroyed = false; - this.onPassword = null; - this.onProgress = null; - this.onUnsupportedFeature = null; + if ((!LIBRARY || FORCED) && (BUGGY || VALUES_BUG || !proto[ITERATOR])) { + hide(proto, ITERATOR, $default); } - PDFDocumentLoadingTask.prototype = { - get promise() { - return this._capability.promise; - }, - destroy: function () { - this.destroyed = true; - var transportDestroyed = !this._transport ? Promise.resolve() : this._transport.destroy(); - return transportDestroyed.then(function () { - this._transport = null; - if (this._worker) { - this._worker.destroy(); - this._worker = null; - } - }.bind(this)); - }, - then: function PDFDocumentLoadingTask_then(onFulfilled, onRejected) { - return this.promise.then.apply(this.promise, arguments); - } - }; - return PDFDocumentLoadingTask; -}(); -var PDFDataRangeTransport = function pdfDataRangeTransportClosure() { - function PDFDataRangeTransport(length, initialData) { - this.length = length; - this.initialData = initialData; - this._rangeListeners = []; - this._progressListeners = []; - this._progressiveReadListeners = []; - this._readyCapability = createPromiseCapability(); + Iterators[NAME] = $default; + Iterators[TAG] = returnThis; + if (DEFAULT) { + methods = { + values: DEF_VALUES ? $default : getMethod(VALUES), + keys: IS_SET ? $default : getMethod(KEYS), + entries: $entries + }; + if (FORCED) for (key in methods) { + if (!(key in proto)) redefine(proto, key, methods[key]); + } else $export($export.P + $export.F * (BUGGY || VALUES_BUG), NAME, methods); } - PDFDataRangeTransport.prototype = { - addRangeListener: function PDFDataRangeTransport_addRangeListener(listener) { - this._rangeListeners.push(listener); - }, - addProgressListener: function PDFDataRangeTransport_addProgressListener(listener) { - this._progressListeners.push(listener); - }, - addProgressiveReadListener: function PDFDataRangeTransport_addProgressiveReadListener(listener) { - this._progressiveReadListeners.push(listener); - }, - onDataRange: function PDFDataRangeTransport_onDataRange(begin, chunk) { - var listeners = this._rangeListeners; - for (var i = 0, n = listeners.length; i < n; ++i) { - listeners[i](begin, chunk); - } - }, - onDataProgress: function PDFDataRangeTransport_onDataProgress(loaded) { - this._readyCapability.promise.then(function () { - var listeners = this._progressListeners; - for (var i = 0, n = listeners.length; i < n; ++i) { - listeners[i](loaded); - } - }.bind(this)); - }, - onDataProgressiveRead: function PDFDataRangeTransport_onDataProgress(chunk) { - this._readyCapability.promise.then(function () { - var listeners = this._progressiveReadListeners; - for (var i = 0, n = listeners.length; i < n; ++i) { - listeners[i](chunk); - } - }.bind(this)); - }, - transportReady: function PDFDataRangeTransport_transportReady() { - this._readyCapability.resolve(); - }, - requestDataRange: function PDFDataRangeTransport_requestDataRange(begin, end) { - throw new Error('Abstract method PDFDataRangeTransport.requestDataRange'); - }, - abort: function PDFDataRangeTransport_abort() {} - }; - return PDFDataRangeTransport; -}(); -var PDFDocumentProxy = function PDFDocumentProxyClosure() { - function PDFDocumentProxy(pdfInfo, transport, loadingTask) { - this.pdfInfo = pdfInfo; - this.transport = transport; - this.loadingTask = loadingTask; + return methods; +}; + +/***/ }), +/* 65 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +module.exports = {}; + +/***/ }), +/* 66 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var create = __w_pdfjs_require__(67); +var descriptor = __w_pdfjs_require__(19); +var setToStringTag = __w_pdfjs_require__(70); +var IteratorPrototype = {}; +__w_pdfjs_require__(10)(IteratorPrototype, __w_pdfjs_require__(28)('iterator'), function () { + return this; +}); +module.exports = function (Constructor, NAME, next) { + Constructor.prototype = create(IteratorPrototype, { next: descriptor(1, next) }); + setToStringTag(Constructor, NAME + ' Iterator'); +}; + +/***/ }), +/* 67 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var anObject = __w_pdfjs_require__(12); +var dPs = __w_pdfjs_require__(68); +var enumBugKeys = __w_pdfjs_require__(48); +var IE_PROTO = __w_pdfjs_require__(47)('IE_PROTO'); +var Empty = function Empty() {}; +var PROTOTYPE = 'prototype'; +var _createDict = function createDict() { + var iframe = __w_pdfjs_require__(17)('iframe'); + var i = enumBugKeys.length; + var lt = '<'; + var gt = '>'; + var iframeDocument; + iframe.style.display = 'none'; + __w_pdfjs_require__(69).appendChild(iframe); + iframe.src = 'javascript:'; + iframeDocument = iframe.contentWindow.document; + iframeDocument.open(); + iframeDocument.write(lt + 'script' + gt + 'document.F=Object' + lt + '/script' + gt); + iframeDocument.close(); + _createDict = iframeDocument.F; + while (i--) { + delete _createDict[PROTOTYPE][enumBugKeys[i]]; + }return _createDict(); +}; +module.exports = Object.create || function create(O, Properties) { + var result; + if (O !== null) { + Empty[PROTOTYPE] = anObject(O); + result = new Empty(); + Empty[PROTOTYPE] = null; + result[IE_PROTO] = O; + } else result = _createDict(); + return Properties === undefined ? result : dPs(result, Properties); +}; + +/***/ }), +/* 68 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var dP = __w_pdfjs_require__(11); +var anObject = __w_pdfjs_require__(12); +var getKeys = __w_pdfjs_require__(45); +module.exports = __w_pdfjs_require__(15) ? Object.defineProperties : function defineProperties(O, Properties) { + anObject(O); + var keys = getKeys(Properties); + var length = keys.length; + var i = 0; + var P; + while (length > i) { + dP.f(O, P = keys[i++], Properties[P]); + }return O; +}; + +/***/ }), +/* 69 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var document = __w_pdfjs_require__(8).document; +module.exports = document && document.documentElement; + +/***/ }), +/* 70 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var def = __w_pdfjs_require__(11).f; +var has = __w_pdfjs_require__(21); +var TAG = __w_pdfjs_require__(28)('toStringTag'); +module.exports = function (it, tag, stat) { + if (it && !has(it = stat ? it : it.prototype, TAG)) def(it, TAG, { + configurable: true, + value: tag + }); +}; + +/***/ }), +/* 71 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var has = __w_pdfjs_require__(21); +var toObject = __w_pdfjs_require__(51); +var IE_PROTO = __w_pdfjs_require__(47)('IE_PROTO'); +var ObjectProto = Object.prototype; +module.exports = Object.getPrototypeOf || function (O) { + O = toObject(O); + if (has(O, IE_PROTO)) return O[IE_PROTO]; + if (typeof O.constructor == 'function' && O instanceof O.constructor) { + return O.constructor.prototype; } - PDFDocumentProxy.prototype = { - get numPages() { - return this.pdfInfo.numPages; - }, - get fingerprint() { - return this.pdfInfo.fingerprint; - }, - getPage: function PDFDocumentProxy_getPage(pageNumber) { - return this.transport.getPage(pageNumber); - }, - getPageIndex: function PDFDocumentProxy_getPageIndex(ref) { - return this.transport.getPageIndex(ref); - }, - getDestinations: function PDFDocumentProxy_getDestinations() { - return this.transport.getDestinations(); - }, - getDestination: function PDFDocumentProxy_getDestination(id) { - return this.transport.getDestination(id); - }, - getPageLabels: function PDFDocumentProxy_getPageLabels() { - return this.transport.getPageLabels(); - }, - getAttachments: function PDFDocumentProxy_getAttachments() { - return this.transport.getAttachments(); - }, - getJavaScript: function PDFDocumentProxy_getJavaScript() { - return this.transport.getJavaScript(); - }, - getOutline: function PDFDocumentProxy_getOutline() { - return this.transport.getOutline(); - }, - getMetadata: function PDFDocumentProxy_getMetadata() { - return this.transport.getMetadata(); - }, - getData: function PDFDocumentProxy_getData() { - return this.transport.getData(); - }, - getDownloadInfo: function PDFDocumentProxy_getDownloadInfo() { - return this.transport.downloadInfoCapability.promise; - }, - getStats: function PDFDocumentProxy_getStats() { - return this.transport.getStats(); - }, - cleanup: function PDFDocumentProxy_cleanup() { - this.transport.startCleanup(); - }, - destroy: function PDFDocumentProxy_destroy() { - return this.loadingTask.destroy(); + return O instanceof Object ? ObjectProto : null; +}; + +/***/ }), +/* 72 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var $iterators = __w_pdfjs_require__(73); +var getKeys = __w_pdfjs_require__(45); +var redefine = __w_pdfjs_require__(20); +var global = __w_pdfjs_require__(8); +var hide = __w_pdfjs_require__(10); +var Iterators = __w_pdfjs_require__(65); +var wks = __w_pdfjs_require__(28); +var ITERATOR = wks('iterator'); +var TO_STRING_TAG = wks('toStringTag'); +var ArrayValues = Iterators.Array; +var DOMIterables = { + CSSRuleList: true, + CSSStyleDeclaration: false, + CSSValueList: false, + ClientRectList: false, + DOMRectList: false, + DOMStringList: false, + DOMTokenList: true, + DataTransferItemList: false, + FileList: false, + HTMLAllCollection: false, + HTMLCollection: false, + HTMLFormElement: false, + HTMLSelectElement: false, + MediaList: true, + MimeTypeArray: false, + NamedNodeMap: false, + NodeList: true, + PaintRequestList: false, + Plugin: false, + PluginArray: false, + SVGLengthList: false, + SVGNumberList: false, + SVGPathSegList: false, + SVGPointList: false, + SVGStringList: false, + SVGTransformList: false, + SourceBufferList: false, + StyleSheetList: true, + TextTrackCueList: false, + TextTrackList: false, + TouchList: false +}; +for (var collections = getKeys(DOMIterables), i = 0; i < collections.length; i++) { + var NAME = collections[i]; + var explicit = DOMIterables[NAME]; + var Collection = global[NAME]; + var proto = Collection && Collection.prototype; + var key; + if (proto) { + if (!proto[ITERATOR]) hide(proto, ITERATOR, ArrayValues); + if (!proto[TO_STRING_TAG]) hide(proto, TO_STRING_TAG, NAME); + Iterators[NAME] = ArrayValues; + if (explicit) for (key in $iterators) { + if (!proto[key]) redefine(proto, key, $iterators[key], true); } + } +} + +/***/ }), +/* 73 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var addToUnscopables = __w_pdfjs_require__(41); +var step = __w_pdfjs_require__(74); +var Iterators = __w_pdfjs_require__(65); +var toIObject = __w_pdfjs_require__(36); +module.exports = __w_pdfjs_require__(64)(Array, 'Array', function (iterated, kind) { + this._t = toIObject(iterated); + this._i = 0; + this._k = kind; +}, function () { + var O = this._t; + var kind = this._k; + var index = this._i++; + if (!O || index >= O.length) { + this._t = undefined; + return step(1); + } + if (kind == 'keys') return step(0, index); + if (kind == 'values') return step(0, O[index]); + return step(0, [index, O[index]]); +}, 'values'); +Iterators.Arguments = Iterators.Array; +addToUnscopables('keys'); +addToUnscopables('values'); +addToUnscopables('entries'); + +/***/ }), +/* 74 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +module.exports = function (done, value) { + return { + value: value, + done: !!done }; - return PDFDocumentProxy; +}; + +/***/ }), +/* 75 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var LIBRARY = __w_pdfjs_require__(30); +var global = __w_pdfjs_require__(8); +var ctx = __w_pdfjs_require__(23); +var classof = __w_pdfjs_require__(61); +var $export = __w_pdfjs_require__(7); +var isObject = __w_pdfjs_require__(13); +var aFunction = __w_pdfjs_require__(24); +var anInstance = __w_pdfjs_require__(76); +var forOf = __w_pdfjs_require__(77); +var speciesConstructor = __w_pdfjs_require__(81); +var task = __w_pdfjs_require__(82).set; +var microtask = __w_pdfjs_require__(84)(); +var newPromiseCapabilityModule = __w_pdfjs_require__(85); +var perform = __w_pdfjs_require__(86); +var userAgent = __w_pdfjs_require__(87); +var promiseResolve = __w_pdfjs_require__(88); +var PROMISE = 'Promise'; +var TypeError = global.TypeError; +var process = global.process; +var versions = process && process.versions; +var v8 = versions && versions.v8 || ''; +var $Promise = global[PROMISE]; +var isNode = classof(process) == 'process'; +var empty = function empty() {}; +var Internal, newGenericPromiseCapability, OwnPromiseCapability, Wrapper; +var newPromiseCapability = newGenericPromiseCapability = newPromiseCapabilityModule.f; +var USE_NATIVE = !!function () { + try { + var promise = $Promise.resolve(1); + var FakePromise = (promise.constructor = {})[__w_pdfjs_require__(28)('species')] = function (exec) { + exec(empty, empty); + }; + return (isNode || typeof PromiseRejectionEvent == 'function') && promise.then(empty) instanceof FakePromise && v8.indexOf('6.6') !== 0 && userAgent.indexOf('Chrome/66') === -1; + } catch (e) {} }(); -var PDFPageProxy = function PDFPageProxyClosure() { - function PDFPageProxy(pageIndex, pageInfo, transport) { - this.pageIndex = pageIndex; - this.pageInfo = pageInfo; - this.transport = transport; - this.stats = new StatTimer(); - this.stats.enabled = getDefaultSetting('enableStats'); - this.commonObjs = transport.commonObjs; - this.objs = new PDFObjects(); - this.cleanupAfterRender = false; - this.pendingCleanup = false; - this.intentStates = Object.create(null); - this.destroyed = false; - } - PDFPageProxy.prototype = { - get pageNumber() { - return this.pageIndex + 1; - }, - get rotate() { - return this.pageInfo.rotate; - }, - get ref() { - return this.pageInfo.ref; - }, - get userUnit() { - return this.pageInfo.userUnit; - }, - get view() { - return this.pageInfo.view; - }, - getViewport: function PDFPageProxy_getViewport(scale, rotate) { - if (arguments.length < 2) { - rotate = this.rotate; - } - return new PageViewport(this.view, scale, rotate, 0, 0); - }, - getAnnotations: function PDFPageProxy_getAnnotations(params) { - var intent = params && params.intent || null; - if (!this.annotationsPromise || this.annotationsIntent !== intent) { - this.annotationsPromise = this.transport.getAnnotations(this.pageIndex, intent); - this.annotationsIntent = intent; - } - return this.annotationsPromise; - }, - render: function PDFPageProxy_render(params) { - var stats = this.stats; - stats.time('Overall'); - this.pendingCleanup = false; - var renderingIntent = params.intent === 'print' ? 'print' : 'display'; - var renderInteractiveForms = params.renderInteractiveForms === true ? true : false; - var canvasFactory = params.canvasFactory || new DOMCanvasFactory(); - if (!this.intentStates[renderingIntent]) { - this.intentStates[renderingIntent] = Object.create(null); - } - var intentState = this.intentStates[renderingIntent]; - if (!intentState.displayReadyCapability) { - intentState.receivingOperatorList = true; - intentState.displayReadyCapability = createPromiseCapability(); - intentState.operatorList = { - fnArray: [], - argsArray: [], - lastChunk: false - }; - this.stats.time('Page Request'); - this.transport.messageHandler.send('RenderPageRequest', { - pageIndex: this.pageNumber - 1, - intent: renderingIntent, - renderInteractiveForms: renderInteractiveForms - }); - } - var internalRenderTask = new InternalRenderTask(complete, params, this.objs, this.commonObjs, intentState.operatorList, this.pageNumber, canvasFactory); - internalRenderTask.useRequestAnimationFrame = renderingIntent !== 'print'; - if (!intentState.renderTasks) { - intentState.renderTasks = []; - } - intentState.renderTasks.push(internalRenderTask); - var renderTask = internalRenderTask.task; - if (params.continueCallback) { - deprecated('render is used with continueCallback parameter'); - renderTask.onContinue = params.continueCallback; +var isThenable = function isThenable(it) { + var then; + return isObject(it) && typeof (then = it.then) == 'function' ? then : false; +}; +var notify = function notify(promise, isReject) { + if (promise._n) return; + promise._n = true; + var chain = promise._c; + microtask(function () { + var value = promise._v; + var ok = promise._s == 1; + var i = 0; + var run = function run(reaction) { + var handler = ok ? reaction.ok : reaction.fail; + var resolve = reaction.resolve; + var reject = reaction.reject; + var domain = reaction.domain; + var result, then, exited; + try { + if (handler) { + if (!ok) { + if (promise._h == 2) onHandleUnhandled(promise); + promise._h = 1; + } + if (handler === true) result = value;else { + if (domain) domain.enter(); + result = handler(value); + if (domain) { + domain.exit(); + exited = true; + } + } + if (result === reaction.promise) { + reject(TypeError('Promise-chain cycle')); + } else if (then = isThenable(result)) { + then.call(result, resolve, reject); + } else resolve(result); + } else reject(value); + } catch (e) { + if (domain && !exited) domain.exit(); + reject(e); } - var self = this; - intentState.displayReadyCapability.promise.then(function pageDisplayReadyPromise(transparency) { - if (self.pendingCleanup) { - complete(); - return; + }; + while (chain.length > i) { + run(chain[i++]); + }promise._c = []; + promise._n = false; + if (isReject && !promise._h) onUnhandled(promise); + }); +}; +var onUnhandled = function onUnhandled(promise) { + task.call(global, function () { + var value = promise._v; + var unhandled = isUnhandled(promise); + var result, handler, console; + if (unhandled) { + result = perform(function () { + if (isNode) { + process.emit('unhandledRejection', value, promise); + } else if (handler = global.onunhandledrejection) { + handler({ + promise: promise, + reason: value + }); + } else if ((console = global.console) && console.error) { + console.error('Unhandled promise rejection', value); } - stats.time('Rendering'); - internalRenderTask.initializeGraphics(transparency); - internalRenderTask.operatorListChanged(); - }, function pageDisplayReadPromiseError(reason) { - complete(reason); }); - function complete(error) { - var i = intentState.renderTasks.indexOf(internalRenderTask); - if (i >= 0) { - intentState.renderTasks.splice(i, 1); - } - if (self.cleanupAfterRender) { - self.pendingCleanup = true; - } - self._tryCleanup(); - if (error) { - internalRenderTask.capability.reject(error); - } else { - internalRenderTask.capability.resolve(); + promise._h = isNode || isUnhandled(promise) ? 2 : 1; + } + promise._a = undefined; + if (unhandled && result.e) throw result.v; + }); +}; +var isUnhandled = function isUnhandled(promise) { + return promise._h !== 1 && (promise._a || promise._c).length === 0; +}; +var onHandleUnhandled = function onHandleUnhandled(promise) { + task.call(global, function () { + var handler; + if (isNode) { + process.emit('rejectionHandled', promise); + } else if (handler = global.onrejectionhandled) { + handler({ + promise: promise, + reason: promise._v + }); + } + }); +}; +var $reject = function $reject(value) { + var promise = this; + if (promise._d) return; + promise._d = true; + promise = promise._w || promise; + promise._v = value; + promise._s = 2; + if (!promise._a) promise._a = promise._c.slice(); + notify(promise, true); +}; +var $resolve = function $resolve(value) { + var promise = this; + var then; + if (promise._d) return; + promise._d = true; + promise = promise._w || promise; + try { + if (promise === value) throw TypeError("Promise can't be resolved itself"); + if (then = isThenable(value)) { + microtask(function () { + var wrapper = { + _w: promise, + _d: false + }; + try { + then.call(value, ctx($resolve, wrapper, 1), ctx($reject, wrapper, 1)); + } catch (e) { + $reject.call(wrapper, e); } - stats.timeEnd('Rendering'); - stats.timeEnd('Overall'); - } - return renderTask; + }); + } else { + promise._v = value; + promise._s = 1; + notify(promise, false); + } + } catch (e) { + $reject.call({ + _w: promise, + _d: false + }, e); + } +}; +if (!USE_NATIVE) { + $Promise = function Promise(executor) { + anInstance(this, $Promise, PROMISE, '_h'); + aFunction(executor); + Internal.call(this); + try { + executor(ctx($resolve, this, 1), ctx($reject, this, 1)); + } catch (err) { + $reject.call(this, err); + } + }; + Internal = function Promise(executor) { + this._c = []; + this._a = undefined; + this._s = 0; + this._d = false; + this._v = undefined; + this._h = 0; + this._n = false; + }; + Internal.prototype = __w_pdfjs_require__(89)($Promise.prototype, { + then: function then(onFulfilled, onRejected) { + var reaction = newPromiseCapability(speciesConstructor(this, $Promise)); + reaction.ok = typeof onFulfilled == 'function' ? onFulfilled : true; + reaction.fail = typeof onRejected == 'function' && onRejected; + reaction.domain = isNode ? process.domain : undefined; + this._c.push(reaction); + if (this._a) this._a.push(reaction); + if (this._s) notify(this, false); + return reaction.promise; }, - getOperatorList: function PDFPageProxy_getOperatorList() { - function operatorListChanged() { - if (intentState.operatorList.lastChunk) { - intentState.opListReadCapability.resolve(intentState.operatorList); - var i = intentState.renderTasks.indexOf(opListTask); - if (i >= 0) { - intentState.renderTasks.splice(i, 1); - } - } - } - var renderingIntent = 'oplist'; - if (!this.intentStates[renderingIntent]) { - this.intentStates[renderingIntent] = Object.create(null); - } - var intentState = this.intentStates[renderingIntent]; - var opListTask; - if (!intentState.opListReadCapability) { - opListTask = {}; - opListTask.operatorListChanged = operatorListChanged; - intentState.receivingOperatorList = true; - intentState.opListReadCapability = createPromiseCapability(); - intentState.renderTasks = []; - intentState.renderTasks.push(opListTask); - intentState.operatorList = { - fnArray: [], - argsArray: [], - lastChunk: false - }; - this.transport.messageHandler.send('RenderPageRequest', { - pageIndex: this.pageIndex, - intent: renderingIntent - }); - } - return intentState.opListReadCapability.promise; - }, - getTextContent: function PDFPageProxy_getTextContent(params) { - return this.transport.messageHandler.sendWithPromise('GetTextContent', { - pageIndex: this.pageNumber - 1, - normalizeWhitespace: params && params.normalizeWhitespace === true ? true : false, - combineTextItems: params && params.disableCombineTextItems === true ? false : true - }); - }, - _destroy: function PDFPageProxy_destroy() { - this.destroyed = true; - this.transport.pageCache[this.pageIndex] = null; - var waitOn = []; - Object.keys(this.intentStates).forEach(function (intent) { - if (intent === 'oplist') { - return; - } - var intentState = this.intentStates[intent]; - intentState.renderTasks.forEach(function (renderTask) { - var renderCompleted = renderTask.capability.promise.catch(function () {}); - waitOn.push(renderCompleted); - renderTask.cancel(); - }); - }, this); - this.objs.clear(); - this.annotationsPromise = null; - this.pendingCleanup = false; - return Promise.all(waitOn); - }, - destroy: function () { - deprecated('page destroy method, use cleanup() instead'); - this.cleanup(); - }, - cleanup: function PDFPageProxy_cleanup() { - this.pendingCleanup = true; - this._tryCleanup(); - }, - _tryCleanup: function PDFPageProxy_tryCleanup() { - if (!this.pendingCleanup || Object.keys(this.intentStates).some(function (intent) { - var intentState = this.intentStates[intent]; - return intentState.renderTasks.length !== 0 || intentState.receivingOperatorList; - }, this)) { - return; - } - Object.keys(this.intentStates).forEach(function (intent) { - delete this.intentStates[intent]; - }, this); - this.objs.clear(); - this.annotationsPromise = null; - this.pendingCleanup = false; - }, - _startRenderPage: function PDFPageProxy_startRenderPage(transparency, intent) { - var intentState = this.intentStates[intent]; - if (intentState.displayReadyCapability) { - intentState.displayReadyCapability.resolve(transparency); - } - }, - _renderPageChunk: function PDFPageProxy_renderPageChunk(operatorListChunk, intent) { - var intentState = this.intentStates[intent]; - var i, ii; - for (i = 0, ii = operatorListChunk.length; i < ii; i++) { - intentState.operatorList.fnArray.push(operatorListChunk.fnArray[i]); - intentState.operatorList.argsArray.push(operatorListChunk.argsArray[i]); - } - intentState.operatorList.lastChunk = operatorListChunk.lastChunk; - for (i = 0; i < intentState.renderTasks.length; i++) { - intentState.renderTasks[i].operatorListChanged(); - } - if (operatorListChunk.lastChunk) { - intentState.receivingOperatorList = false; - this._tryCleanup(); - } + 'catch': function _catch(onRejected) { + return this.then(undefined, onRejected); } + }); + OwnPromiseCapability = function OwnPromiseCapability() { + var promise = new Internal(); + this.promise = promise; + this.resolve = ctx($resolve, promise, 1); + this.reject = ctx($reject, promise, 1); }; - return PDFPageProxy; -}(); -var PDFWorker = function PDFWorkerClosure() { - var nextFakeWorkerId = 0; - function getWorkerSrc() { - if (typeof workerSrc !== 'undefined') { - return workerSrc; - } - if (getDefaultSetting('workerSrc')) { - return getDefaultSetting('workerSrc'); - } - if (pdfjsFilePath) { - return pdfjsFilePath.replace(/\.js$/i, '.worker.js'); - } - error('No PDFJS.workerSrc specified'); + newPromiseCapabilityModule.f = newPromiseCapability = function newPromiseCapability(C) { + return C === $Promise || C === Wrapper ? new OwnPromiseCapability(C) : newGenericPromiseCapability(C); + }; +} +$export($export.G + $export.W + $export.F * !USE_NATIVE, { Promise: $Promise }); +__w_pdfjs_require__(70)($Promise, PROMISE); +__w_pdfjs_require__(90)(PROMISE); +Wrapper = __w_pdfjs_require__(9)[PROMISE]; +$export($export.S + $export.F * !USE_NATIVE, PROMISE, { + reject: function reject(r) { + var capability = newPromiseCapability(this); + var $$reject = capability.reject; + $$reject(r); + return capability.promise; } - var fakeWorkerFilesLoadedCapability; - function setupFakeWorkerGlobal() { - var WorkerMessageHandler; - if (fakeWorkerFilesLoadedCapability) { - return fakeWorkerFilesLoadedCapability.promise; - } - fakeWorkerFilesLoadedCapability = createPromiseCapability(); - var loader = fakeWorkerFilesLoader || function (callback) { - Util.loadScript(getWorkerSrc(), function () { - callback(window.pdfjsDistBuildPdfWorker.WorkerMessageHandler); +}); +$export($export.S + $export.F * (LIBRARY || !USE_NATIVE), PROMISE, { + resolve: function resolve(x) { + return promiseResolve(LIBRARY && this === Wrapper ? $Promise : this, x); + } +}); +$export($export.S + $export.F * !(USE_NATIVE && __w_pdfjs_require__(91)(function (iter) { + $Promise.all(iter)['catch'](empty); +})), PROMISE, { + all: function all(iterable) { + var C = this; + var capability = newPromiseCapability(C); + var resolve = capability.resolve; + var reject = capability.reject; + var result = perform(function () { + var values = []; + var index = 0; + var remaining = 1; + forOf(iterable, false, function (promise) { + var $index = index++; + var alreadyCalled = false; + values.push(undefined); + remaining++; + C.resolve(promise).then(function (value) { + if (alreadyCalled) return; + alreadyCalled = true; + values[$index] = value; + --remaining || resolve(values); + }, reject); }); - }; - loader(fakeWorkerFilesLoadedCapability.resolve); - return fakeWorkerFilesLoadedCapability.promise; + --remaining || resolve(values); + }); + if (result.e) reject(result.v); + return capability.promise; + }, + race: function race(iterable) { + var C = this; + var capability = newPromiseCapability(C); + var reject = capability.reject; + var result = perform(function () { + forOf(iterable, false, function (promise) { + C.resolve(promise).then(capability.resolve, reject); + }); + }); + if (result.e) reject(result.v); + return capability.promise; } - function FakeWorkerPort(defer) { - this._listeners = []; - this._defer = defer; - this._deferred = Promise.resolve(undefined); +}); + +/***/ }), +/* 76 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +module.exports = function (it, Constructor, name, forbiddenField) { + if (!(it instanceof Constructor) || forbiddenField !== undefined && forbiddenField in it) { + throw TypeError(name + ': incorrect invocation!'); } - FakeWorkerPort.prototype = { - postMessage: function (obj, transfers) { - function cloneValue(value) { - if (typeof value !== 'object' || value === null) { - return value; - } - if (cloned.has(value)) { - return cloned.get(value); - } - var result; - var buffer; - if ((buffer = value.buffer) && isArrayBuffer(buffer)) { - var transferable = transfers && transfers.indexOf(buffer) >= 0; - if (value === buffer) { - result = value; - } else if (transferable) { - result = new value.constructor(buffer, value.byteOffset, value.byteLength); - } else { - result = new value.constructor(value); - } - cloned.set(value, result); - return result; - } - result = isArray(value) ? [] : {}; - cloned.set(value, result); - for (var i in value) { - var desc, - p = value; - while (!(desc = Object.getOwnPropertyDescriptor(p, i))) { - p = Object.getPrototypeOf(p); - } - if (typeof desc.value === 'undefined' || typeof desc.value === 'function') { - continue; - } - result[i] = cloneValue(desc.value); - } - return result; - } - if (!this._defer) { - this._listeners.forEach(function (listener) { - listener.call(this, { data: obj }); - }, this); - return; - } - var cloned = new WeakMap(); - var e = { data: cloneValue(obj) }; - this._deferred.then(function () { - this._listeners.forEach(function (listener) { - listener.call(this, e); - }, this); - }.bind(this)); - }, - addEventListener: function (name, listener) { - this._listeners.push(listener); - }, - removeEventListener: function (name, listener) { - var i = this._listeners.indexOf(listener); - this._listeners.splice(i, 1); - }, - terminate: function () { - this._listeners = []; - } - }; - function createCDNWrapper(url) { - var wrapper = 'importScripts(\'' + url + '\');'; - return URL.createObjectURL(new Blob([wrapper])); + return it; +}; + +/***/ }), +/* 77 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var ctx = __w_pdfjs_require__(23); +var call = __w_pdfjs_require__(78); +var isArrayIter = __w_pdfjs_require__(79); +var anObject = __w_pdfjs_require__(12); +var toLength = __w_pdfjs_require__(38); +var getIterFn = __w_pdfjs_require__(80); +var BREAK = {}; +var RETURN = {}; +var _exports = module.exports = function (iterable, entries, fn, that, ITERATOR) { + var iterFn = ITERATOR ? function () { + return iterable; + } : getIterFn(iterable); + var f = ctx(fn, that, entries ? 2 : 1); + var index = 0; + var length, step, iterator, result; + if (typeof iterFn != 'function') throw TypeError(iterable + ' is not iterable!'); + if (isArrayIter(iterFn)) for (length = toLength(iterable.length); length > index; index++) { + result = entries ? f(anObject(step = iterable[index])[0], step[1]) : f(iterable[index]); + if (result === BREAK || result === RETURN) return result; + } else for (iterator = iterFn.call(iterable); !(step = iterator.next()).done;) { + result = call(iterator, f, step.value, entries); + if (result === BREAK || result === RETURN) return result; } - function PDFWorker(name, port) { - this.name = name; - this.destroyed = false; - this._readyCapability = createPromiseCapability(); - this._port = null; - this._webWorker = null; - this._messageHandler = null; - if (port) { - this._initializeFromPort(port); - return; - } - this._initialize(); +}; +_exports.BREAK = BREAK; +_exports.RETURN = RETURN; + +/***/ }), +/* 78 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var anObject = __w_pdfjs_require__(12); +module.exports = function (iterator, fn, value, entries) { + try { + return entries ? fn(anObject(value)[0], value[1]) : fn(value); + } catch (e) { + var ret = iterator['return']; + if (ret !== undefined) anObject(ret.call(iterator)); + throw e; } - PDFWorker.prototype = { - get promise() { - return this._readyCapability.promise; - }, - get port() { - return this._port; - }, - get messageHandler() { - return this._messageHandler; - }, - _initializeFromPort: function PDFWorker_initializeFromPort(port) { - this._port = port; - this._messageHandler = new MessageHandler('main', 'worker', port); - this._messageHandler.on('ready', function () {}); - this._readyCapability.resolve(); - }, - _initialize: function PDFWorker_initialize() { - if (!isWorkerDisabled && !getDefaultSetting('disableWorker') && typeof Worker !== 'undefined') { - var workerSrc = getWorkerSrc(); - try { - if (!isSameOrigin(window.location.href, workerSrc)) { - workerSrc = createCDNWrapper(new URL(workerSrc, window.location).href); - } - var worker = new Worker(workerSrc); - var messageHandler = new MessageHandler('main', 'worker', worker); - var terminateEarly = function () { - worker.removeEventListener('error', onWorkerError); - messageHandler.destroy(); - worker.terminate(); - if (this.destroyed) { - this._readyCapability.reject(new Error('Worker was destroyed')); - } else { - this._setupFakeWorker(); - } - }.bind(this); - var onWorkerError = function (event) { - if (!this._webWorker) { - terminateEarly(); - } - }.bind(this); - worker.addEventListener('error', onWorkerError); - messageHandler.on('test', function PDFWorker_test(data) { - worker.removeEventListener('error', onWorkerError); - if (this.destroyed) { - terminateEarly(); - return; - } - var supportTypedArray = data && data.supportTypedArray; - if (supportTypedArray) { - this._messageHandler = messageHandler; - this._port = worker; - this._webWorker = worker; - if (!data.supportTransfers) { - isPostMessageTransfersDisabled = true; - } - this._readyCapability.resolve(); - messageHandler.send('configure', { verbosity: getVerbosityLevel() }); - } else { - this._setupFakeWorker(); - messageHandler.destroy(); - worker.terminate(); - } - }.bind(this)); - messageHandler.on('console_log', function (data) { - console.log.apply(console, data); - }); - messageHandler.on('console_error', function (data) { - console.error.apply(console, data); - }); - messageHandler.on('ready', function (data) { - worker.removeEventListener('error', onWorkerError); - if (this.destroyed) { - terminateEarly(); - return; - } - try { - sendTest(); - } catch (e) { - this._setupFakeWorker(); - } - }.bind(this)); - var sendTest = function () { - var postMessageTransfers = getDefaultSetting('postMessageTransfers') && !isPostMessageTransfersDisabled; - var testObj = new Uint8Array([postMessageTransfers ? 255 : 0]); - try { - messageHandler.send('test', testObj, [testObj.buffer]); - } catch (ex) { - info('Cannot use postMessage transfers'); - testObj[0] = 0; - messageHandler.send('test', testObj); - } - }; - sendTest(); - return; - } catch (e) { - info('The worker has been disabled.'); - } - } - this._setupFakeWorker(); - }, - _setupFakeWorker: function PDFWorker_setupFakeWorker() { - if (!isWorkerDisabled && !getDefaultSetting('disableWorker')) { - warn('Setting up fake worker.'); - isWorkerDisabled = true; - } - setupFakeWorkerGlobal().then(function (WorkerMessageHandler) { - if (this.destroyed) { - this._readyCapability.reject(new Error('Worker was destroyed')); - return; - } - var isTypedArraysPresent = Uint8Array !== Float32Array; - var port = new FakeWorkerPort(isTypedArraysPresent); - this._port = port; - var id = 'fake' + nextFakeWorkerId++; - var workerHandler = new MessageHandler(id + '_worker', id, port); - WorkerMessageHandler.setup(workerHandler, port); - var messageHandler = new MessageHandler(id, id + '_worker', port); - this._messageHandler = messageHandler; - this._readyCapability.resolve(); - }.bind(this)); - }, - destroy: function PDFWorker_destroy() { - this.destroyed = true; - if (this._webWorker) { - this._webWorker.terminate(); - this._webWorker = null; - } - this._port = null; - if (this._messageHandler) { - this._messageHandler.destroy(); - this._messageHandler = null; +}; + +/***/ }), +/* 79 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var Iterators = __w_pdfjs_require__(65); +var ITERATOR = __w_pdfjs_require__(28)('iterator'); +var ArrayProto = Array.prototype; +module.exports = function (it) { + return it !== undefined && (Iterators.Array === it || ArrayProto[ITERATOR] === it); +}; + +/***/ }), +/* 80 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var classof = __w_pdfjs_require__(61); +var ITERATOR = __w_pdfjs_require__(28)('iterator'); +var Iterators = __w_pdfjs_require__(65); +module.exports = __w_pdfjs_require__(9).getIteratorMethod = function (it) { + if (it != undefined) return it[ITERATOR] || it['@@iterator'] || Iterators[classof(it)]; +}; + +/***/ }), +/* 81 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var anObject = __w_pdfjs_require__(12); +var aFunction = __w_pdfjs_require__(24); +var SPECIES = __w_pdfjs_require__(28)('species'); +module.exports = function (O, D) { + var C = anObject(O).constructor; + var S; + return C === undefined || (S = anObject(C)[SPECIES]) == undefined ? D : aFunction(S); +}; + +/***/ }), +/* 82 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var ctx = __w_pdfjs_require__(23); +var invoke = __w_pdfjs_require__(83); +var html = __w_pdfjs_require__(69); +var cel = __w_pdfjs_require__(17); +var global = __w_pdfjs_require__(8); +var process = global.process; +var setTask = global.setImmediate; +var clearTask = global.clearImmediate; +var MessageChannel = global.MessageChannel; +var Dispatch = global.Dispatch; +var counter = 0; +var queue = {}; +var ONREADYSTATECHANGE = 'onreadystatechange'; +var defer, channel, port; +var run = function run() { + var id = +this; + if (queue.hasOwnProperty(id)) { + var fn = queue[id]; + delete queue[id]; + fn(); + } +}; +var listener = function listener(event) { + run.call(event.data); +}; +if (!setTask || !clearTask) { + setTask = function setImmediate(fn) { + var args = []; + var i = 1; + while (arguments.length > i) { + args.push(arguments[i++]); + }queue[++counter] = function () { + invoke(typeof fn == 'function' ? fn : Function(fn), args); + }; + defer(counter); + return counter; + }; + clearTask = function clearImmediate(id) { + delete queue[id]; + }; + if (__w_pdfjs_require__(27)(process) == 'process') { + defer = function defer(id) { + process.nextTick(ctx(run, id, 1)); + }; + } else if (Dispatch && Dispatch.now) { + defer = function defer(id) { + Dispatch.now(ctx(run, id, 1)); + }; + } else if (MessageChannel) { + channel = new MessageChannel(); + port = channel.port2; + channel.port1.onmessage = listener; + defer = ctx(port.postMessage, port, 1); + } else if (global.addEventListener && typeof postMessage == 'function' && !global.importScripts) { + defer = function defer(id) { + global.postMessage(id + '', '*'); + }; + global.addEventListener('message', listener, false); + } else if (ONREADYSTATECHANGE in cel('script')) { + defer = function defer(id) { + html.appendChild(cel('script'))[ONREADYSTATECHANGE] = function () { + html.removeChild(this); + run.call(id); + }; + }; + } else { + defer = function defer(id) { + setTimeout(ctx(run, id, 1), 0); + }; + } +} +module.exports = { + set: setTask, + clear: clearTask +}; + +/***/ }), +/* 83 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +module.exports = function (fn, args, that) { + var un = that === undefined; + switch (args.length) { + case 0: + return un ? fn() : fn.call(that); + case 1: + return un ? fn(args[0]) : fn.call(that, args[0]); + case 2: + return un ? fn(args[0], args[1]) : fn.call(that, args[0], args[1]); + case 3: + return un ? fn(args[0], args[1], args[2]) : fn.call(that, args[0], args[1], args[2]); + case 4: + return un ? fn(args[0], args[1], args[2], args[3]) : fn.call(that, args[0], args[1], args[2], args[3]); + } + return fn.apply(that, args); +}; + +/***/ }), +/* 84 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var global = __w_pdfjs_require__(8); +var macrotask = __w_pdfjs_require__(82).set; +var Observer = global.MutationObserver || global.WebKitMutationObserver; +var process = global.process; +var Promise = global.Promise; +var isNode = __w_pdfjs_require__(27)(process) == 'process'; +module.exports = function () { + var head, last, notify; + var flush = function flush() { + var parent, fn; + if (isNode && (parent = process.domain)) parent.exit(); + while (head) { + fn = head.fn; + head = head.next; + try { + fn(); + } catch (e) { + if (head) notify();else last = undefined; + throw e; } } + last = undefined; + if (parent) parent.enter(); }; - return PDFWorker; -}(); -var WorkerTransport = function WorkerTransportClosure() { - function WorkerTransport(messageHandler, loadingTask, pdfDataRangeTransport, CMapReaderFactory) { - this.messageHandler = messageHandler; - this.loadingTask = loadingTask; - this.pdfDataRangeTransport = pdfDataRangeTransport; - this.commonObjs = new PDFObjects(); - this.fontLoader = new FontLoader(loadingTask.docId); - this.CMapReaderFactory = new CMapReaderFactory({ - baseUrl: getDefaultSetting('cMapUrl'), - isCompressed: getDefaultSetting('cMapPacked') - }); - this.destroyed = false; - this.destroyCapability = null; - this._passwordCapability = null; - this.pageCache = []; - this.pagePromises = []; - this.downloadInfoCapability = createPromiseCapability(); - this.setupMessageHandler(); + if (isNode) { + notify = function notify() { + process.nextTick(flush); + }; + } else if (Observer && !(global.navigator && global.navigator.standalone)) { + var toggle = true; + var node = document.createTextNode(''); + new Observer(flush).observe(node, { characterData: true }); + notify = function notify() { + node.data = toggle = !toggle; + }; + } else if (Promise && Promise.resolve) { + var promise = Promise.resolve(undefined); + notify = function notify() { + promise.then(flush); + }; + } else { + notify = function notify() { + macrotask.call(global, flush); + }; } - WorkerTransport.prototype = { - destroy: function WorkerTransport_destroy() { - if (this.destroyCapability) { - return this.destroyCapability.promise; - } - this.destroyed = true; - this.destroyCapability = createPromiseCapability(); - if (this._passwordCapability) { - this._passwordCapability.reject(new Error('Worker was destroyed during onPassword callback')); - } - var waitOn = []; - this.pageCache.forEach(function (page) { - if (page) { - waitOn.push(page._destroy()); - } + return function (fn) { + var task = { + fn: fn, + next: undefined + }; + if (last) last.next = task; + if (!head) { + head = task; + notify(); + } + last = task; + }; +}; + +/***/ }), +/* 85 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var aFunction = __w_pdfjs_require__(24); +function PromiseCapability(C) { + var resolve, reject; + this.promise = new C(function ($$resolve, $$reject) { + if (resolve !== undefined || reject !== undefined) throw TypeError('Bad Promise constructor'); + resolve = $$resolve; + reject = $$reject; + }); + this.resolve = aFunction(resolve); + this.reject = aFunction(reject); +} +module.exports.f = function (C) { + return new PromiseCapability(C); +}; + +/***/ }), +/* 86 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +module.exports = function (exec) { + try { + return { + e: false, + v: exec() + }; + } catch (e) { + return { + e: true, + v: e + }; + } +}; + +/***/ }), +/* 87 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var global = __w_pdfjs_require__(8); +var navigator = global.navigator; +module.exports = navigator && navigator.userAgent || ''; + +/***/ }), +/* 88 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var anObject = __w_pdfjs_require__(12); +var isObject = __w_pdfjs_require__(13); +var newPromiseCapability = __w_pdfjs_require__(85); +module.exports = function (C, x) { + anObject(C); + if (isObject(x) && x.constructor === C) return x; + var promiseCapability = newPromiseCapability.f(C); + var resolve = promiseCapability.resolve; + resolve(x); + return promiseCapability.promise; +}; + +/***/ }), +/* 89 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var redefine = __w_pdfjs_require__(20); +module.exports = function (target, src, safe) { + for (var key in src) { + redefine(target, key, src[key], safe); + }return target; +}; + +/***/ }), +/* 90 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var global = __w_pdfjs_require__(8); +var dP = __w_pdfjs_require__(11); +var DESCRIPTORS = __w_pdfjs_require__(15); +var SPECIES = __w_pdfjs_require__(28)('species'); +module.exports = function (KEY) { + var C = global[KEY]; + if (DESCRIPTORS && C && !C[SPECIES]) dP.f(C, SPECIES, { + configurable: true, + get: function get() { + return this; + } + }); +}; + +/***/ }), +/* 91 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var ITERATOR = __w_pdfjs_require__(28)('iterator'); +var SAFE_CLOSING = false; +try { + var riter = [7][ITERATOR](); + riter['return'] = function () { + SAFE_CLOSING = true; + }; + Array.from(riter, function () { + throw 2; + }); +} catch (e) {} +module.exports = function (exec, skipClosing) { + if (!skipClosing && !SAFE_CLOSING) return false; + var safe = false; + try { + var arr = [7]; + var iter = arr[ITERATOR](); + iter.next = function () { + return { done: safe = true }; + }; + arr[ITERATOR] = function () { + return iter; + }; + exec(arr); + } catch (e) {} + return safe; +}; + +/***/ }), +/* 92 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var $export = __w_pdfjs_require__(7); +var core = __w_pdfjs_require__(9); +var global = __w_pdfjs_require__(8); +var speciesConstructor = __w_pdfjs_require__(81); +var promiseResolve = __w_pdfjs_require__(88); +$export($export.P + $export.R, 'Promise', { + 'finally': function _finally(onFinally) { + var C = speciesConstructor(this, core.Promise || global.Promise); + var isFunction = typeof onFinally == 'function'; + return this.then(isFunction ? function (x) { + return promiseResolve(C, onFinally()).then(function () { + return x; }); - this.pageCache = []; - this.pagePromises = []; - var self = this; - var terminated = this.messageHandler.sendWithPromise('Terminate', null); - waitOn.push(terminated); - Promise.all(waitOn).then(function () { - self.fontLoader.clear(); - if (self.pdfDataRangeTransport) { - self.pdfDataRangeTransport.abort(); - self.pdfDataRangeTransport = null; - } - if (self.messageHandler) { - self.messageHandler.destroy(); - self.messageHandler = null; - } - self.destroyCapability.resolve(); - }, this.destroyCapability.reject); - return this.destroyCapability.promise; - }, - setupMessageHandler: function WorkerTransport_setupMessageHandler() { - var messageHandler = this.messageHandler; - var loadingTask = this.loadingTask; - var pdfDataRangeTransport = this.pdfDataRangeTransport; - if (pdfDataRangeTransport) { - pdfDataRangeTransport.addRangeListener(function (begin, chunk) { - messageHandler.send('OnDataRange', { - begin: begin, - chunk: chunk - }); - }); - pdfDataRangeTransport.addProgressListener(function (loaded) { - messageHandler.send('OnDataProgress', { loaded: loaded }); - }); - pdfDataRangeTransport.addProgressiveReadListener(function (chunk) { - messageHandler.send('OnDataRange', { chunk: chunk }); - }); - messageHandler.on('RequestDataRange', function transportDataRange(data) { - pdfDataRangeTransport.requestDataRange(data.begin, data.end); - }, this); - } - messageHandler.on('GetDoc', function transportDoc(data) { - var pdfInfo = data.pdfInfo; - this.numPages = data.pdfInfo.numPages; - var loadingTask = this.loadingTask; - var pdfDocument = new PDFDocumentProxy(pdfInfo, this, loadingTask); - this.pdfDocument = pdfDocument; - loadingTask._capability.resolve(pdfDocument); - }, this); - messageHandler.on('PasswordRequest', function transportPasswordRequest(exception) { - this._passwordCapability = createPromiseCapability(); - if (loadingTask.onPassword) { - var updatePassword = function (password) { - this._passwordCapability.resolve({ password: password }); - }.bind(this); - loadingTask.onPassword(updatePassword, exception.code); - } else { - this._passwordCapability.reject(new PasswordException(exception.message, exception.code)); - } - return this._passwordCapability.promise; - }, this); - messageHandler.on('PasswordException', function transportPasswordException(exception) { - loadingTask._capability.reject(new PasswordException(exception.message, exception.code)); - }, this); - messageHandler.on('InvalidPDF', function transportInvalidPDF(exception) { - this.loadingTask._capability.reject(new InvalidPDFException(exception.message)); - }, this); - messageHandler.on('MissingPDF', function transportMissingPDF(exception) { - this.loadingTask._capability.reject(new MissingPDFException(exception.message)); - }, this); - messageHandler.on('UnexpectedResponse', function transportUnexpectedResponse(exception) { - this.loadingTask._capability.reject(new UnexpectedResponseException(exception.message, exception.status)); - }, this); - messageHandler.on('UnknownError', function transportUnknownError(exception) { - this.loadingTask._capability.reject(new UnknownErrorException(exception.message, exception.details)); - }, this); - messageHandler.on('DataLoaded', function transportPage(data) { - this.downloadInfoCapability.resolve(data); - }, this); - messageHandler.on('PDFManagerReady', function transportPage(data) { - if (this.pdfDataRangeTransport) { - this.pdfDataRangeTransport.transportReady(); - } - }, this); - messageHandler.on('StartRenderPage', function transportRender(data) { - if (this.destroyed) { - return; - } - var page = this.pageCache[data.pageIndex]; - page.stats.timeEnd('Page Request'); - page._startRenderPage(data.transparency, data.intent); - }, this); - messageHandler.on('RenderPageChunk', function transportRender(data) { - if (this.destroyed) { - return; - } - var page = this.pageCache[data.pageIndex]; - page._renderPageChunk(data.operatorList, data.intent); - }, this); - messageHandler.on('commonobj', function transportObj(data) { - if (this.destroyed) { - return; - } - var id = data[0]; - var type = data[1]; - if (this.commonObjs.hasData(id)) { - return; - } - switch (type) { - case 'Font': - var exportedData = data[2]; - if ('error' in exportedData) { - var exportedError = exportedData.error; - warn('Error during font loading: ' + exportedError); - this.commonObjs.resolve(id, exportedError); - break; - } - var fontRegistry = null; - if (getDefaultSetting('pdfBug') && globalScope.FontInspector && globalScope['FontInspector'].enabled) { - fontRegistry = { - registerFont: function (font, url) { - globalScope['FontInspector'].fontAdded(font, url); - } - }; - } - var font = new FontFaceObject(exportedData, { - isEvalSuported: getDefaultSetting('isEvalSupported'), - disableFontFace: getDefaultSetting('disableFontFace'), - fontRegistry: fontRegistry - }); - this.fontLoader.bind([font], function fontReady(fontObjs) { - this.commonObjs.resolve(id, font); - }.bind(this)); - break; - case 'FontPath': - this.commonObjs.resolve(id, data[2]); - break; - default: - error('Got unknown common object type ' + type); - } - }, this); - messageHandler.on('obj', function transportObj(data) { - if (this.destroyed) { - return; - } - var id = data[0]; - var pageIndex = data[1]; - var type = data[2]; - var pageProxy = this.pageCache[pageIndex]; - var imageData; - if (pageProxy.objs.hasData(id)) { - return; - } - switch (type) { - case 'JpegStream': - imageData = data[3]; - loadJpegStream(id, imageData, pageProxy.objs); - break; - case 'Image': - imageData = data[3]; - pageProxy.objs.resolve(id, imageData); - var MAX_IMAGE_SIZE_TO_STORE = 8000000; - if (imageData && 'data' in imageData && imageData.data.length > MAX_IMAGE_SIZE_TO_STORE) { - pageProxy.cleanupAfterRender = true; - } - break; - default: - error('Got unknown object type ' + type); - } - }, this); - messageHandler.on('DocProgress', function transportDocProgress(data) { - if (this.destroyed) { - return; - } - var loadingTask = this.loadingTask; - if (loadingTask.onProgress) { - loadingTask.onProgress({ - loaded: data.loaded, - total: data.total - }); - } - }, this); - messageHandler.on('PageError', function transportError(data) { - if (this.destroyed) { - return; - } - var page = this.pageCache[data.pageNum - 1]; - var intentState = page.intentStates[data.intent]; - if (intentState.displayReadyCapability) { - intentState.displayReadyCapability.reject(data.error); - } else { - error(data.error); - } - if (intentState.operatorList) { - intentState.operatorList.lastChunk = true; - for (var i = 0; i < intentState.renderTasks.length; i++) { - intentState.renderTasks[i].operatorListChanged(); - } - } - }, this); - messageHandler.on('UnsupportedFeature', function transportUnsupportedFeature(data) { - if (this.destroyed) { - return; - } - var featureId = data.featureId; - var loadingTask = this.loadingTask; - if (loadingTask.onUnsupportedFeature) { - loadingTask.onUnsupportedFeature(featureId); - } - _UnsupportedManager.notify(featureId); - }, this); - messageHandler.on('JpegDecode', function (data) { - if (this.destroyed) { - return Promise.reject(new Error('Worker was destroyed')); - } - if (typeof document === 'undefined') { - return Promise.reject(new Error('"document" is not defined.')); - } - var imageUrl = data[0]; - var components = data[1]; - if (components !== 3 && components !== 1) { - return Promise.reject(new Error('Only 3 components or 1 component can be returned')); - } - return new Promise(function (resolve, reject) { - var img = new Image(); - img.onload = function () { - var width = img.width; - var height = img.height; - var size = width * height; - var rgbaLength = size * 4; - var buf = new Uint8Array(size * components); - var tmpCanvas = document.createElement('canvas'); - tmpCanvas.width = width; - tmpCanvas.height = height; - var tmpCtx = tmpCanvas.getContext('2d'); - tmpCtx.drawImage(img, 0, 0); - var data = tmpCtx.getImageData(0, 0, width, height).data; - var i, j; - if (components === 3) { - for (i = 0, j = 0; i < rgbaLength; i += 4, j += 3) { - buf[j] = data[i]; - buf[j + 1] = data[i + 1]; - buf[j + 2] = data[i + 2]; - } - } else if (components === 1) { - for (i = 0, j = 0; i < rgbaLength; i += 4, j++) { - buf[j] = data[i]; - } - } - resolve({ - data: buf, - width: width, - height: height - }); - }; - img.onerror = function () { - reject(new Error('JpegDecode failed to load image')); - }; - img.src = imageUrl; - }); - }, this); - messageHandler.on('FetchBuiltInCMap', function (data) { - if (this.destroyed) { - return Promise.reject(new Error('Worker was destroyed')); - } - return this.CMapReaderFactory.fetch({ name: data.name }); - }, this); - }, - getData: function WorkerTransport_getData() { - return this.messageHandler.sendWithPromise('GetData', null); - }, - getPage: function WorkerTransport_getPage(pageNumber, capability) { - if (!isInt(pageNumber) || pageNumber <= 0 || pageNumber > this.numPages) { - return Promise.reject(new Error('Invalid page request')); - } - var pageIndex = pageNumber - 1; - if (pageIndex in this.pagePromises) { - return this.pagePromises[pageIndex]; - } - var promise = this.messageHandler.sendWithPromise('GetPage', { pageIndex: pageIndex }).then(function (pageInfo) { - if (this.destroyed) { - throw new Error('Transport destroyed'); - } - var page = new PDFPageProxy(pageIndex, pageInfo, this); - this.pageCache[pageIndex] = page; - return page; - }.bind(this)); - this.pagePromises[pageIndex] = promise; - return promise; - }, - getPageIndex: function WorkerTransport_getPageIndexByRef(ref) { - return this.messageHandler.sendWithPromise('GetPageIndex', { ref: ref }).catch(function (reason) { - return Promise.reject(new Error(reason)); - }); - }, - getAnnotations: function WorkerTransport_getAnnotations(pageIndex, intent) { - return this.messageHandler.sendWithPromise('GetAnnotations', { - pageIndex: pageIndex, - intent: intent - }); - }, - getDestinations: function WorkerTransport_getDestinations() { - return this.messageHandler.sendWithPromise('GetDestinations', null); - }, - getDestination: function WorkerTransport_getDestination(id) { - return this.messageHandler.sendWithPromise('GetDestination', { id: id }); - }, - getPageLabels: function WorkerTransport_getPageLabels() { - return this.messageHandler.sendWithPromise('GetPageLabels', null); - }, - getAttachments: function WorkerTransport_getAttachments() { - return this.messageHandler.sendWithPromise('GetAttachments', null); - }, - getJavaScript: function WorkerTransport_getJavaScript() { - return this.messageHandler.sendWithPromise('GetJavaScript', null); - }, - getOutline: function WorkerTransport_getOutline() { - return this.messageHandler.sendWithPromise('GetOutline', null); - }, - getMetadata: function WorkerTransport_getMetadata() { - return this.messageHandler.sendWithPromise('GetMetadata', null).then(function transportMetadata(results) { - return { - info: results[0], - metadata: results[1] ? new Metadata(results[1]) : null - }; + } : onFinally, isFunction ? function (e) { + return promiseResolve(C, onFinally()).then(function () { + throw e; }); - }, - getStats: function WorkerTransport_getStats() { - return this.messageHandler.sendWithPromise('GetStats', null); - }, - startCleanup: function WorkerTransport_startCleanup() { - this.messageHandler.sendWithPromise('Cleanup', null).then(function endCleanup() { - for (var i = 0, ii = this.pageCache.length; i < ii; i++) { - var page = this.pageCache[i]; - if (page) { - page.cleanup(); - } - } - this.commonObjs.clear(); - this.fontLoader.clear(); - }.bind(this)); - } + } : onFinally); + } +}); + +/***/ }), +/* 93 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var $export = __w_pdfjs_require__(7); +var newPromiseCapability = __w_pdfjs_require__(85); +var perform = __w_pdfjs_require__(86); +$export($export.S, 'Promise', { + 'try': function _try(callbackfn) { + var promiseCapability = newPromiseCapability.f(this); + var result = perform(callbackfn); + (result.e ? promiseCapability.reject : promiseCapability.resolve)(result.v); + return promiseCapability.promise; + } +}); + +/***/ }), +/* 94 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +__w_pdfjs_require__(60); +__w_pdfjs_require__(72); +__w_pdfjs_require__(95); +__w_pdfjs_require__(107); +__w_pdfjs_require__(109); +module.exports = __w_pdfjs_require__(9).WeakMap; + +/***/ }), +/* 95 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var each = __w_pdfjs_require__(96)(0); +var redefine = __w_pdfjs_require__(20); +var meta = __w_pdfjs_require__(100); +var assign = __w_pdfjs_require__(44); +var weak = __w_pdfjs_require__(101); +var isObject = __w_pdfjs_require__(13); +var fails = __w_pdfjs_require__(16); +var validate = __w_pdfjs_require__(102); +var WEAK_MAP = 'WeakMap'; +var getWeak = meta.getWeak; +var isExtensible = Object.isExtensible; +var uncaughtFrozenStore = weak.ufstore; +var tmp = {}; +var InternalMap; +var wrapper = function wrapper(get) { + return function WeakMap() { + return get(this, arguments.length > 0 ? arguments[0] : undefined); }; - return WorkerTransport; -}(); -var PDFObjects = function PDFObjectsClosure() { - function PDFObjects() { - this.objs = Object.create(null); +}; +var methods = { + get: function get(key) { + if (isObject(key)) { + var data = getWeak(key); + if (data === true) return uncaughtFrozenStore(validate(this, WEAK_MAP)).get(key); + return data ? data[this._i] : undefined; + } + }, + set: function set(key, value) { + return weak.def(validate(this, WEAK_MAP), key, value); } - PDFObjects.prototype = { - ensureObj: function PDFObjects_ensureObj(objId) { - if (this.objs[objId]) { - return this.objs[objId]; - } - var obj = { - capability: createPromiseCapability(), - data: null, - resolved: false - }; - this.objs[objId] = obj; - return obj; - }, - get: function PDFObjects_get(objId, callback) { - if (callback) { - this.ensureObj(objId).capability.promise.then(callback); - return null; - } - var obj = this.objs[objId]; - if (!obj || !obj.resolved) { - error('Requesting object that isn\'t resolved yet ' + objId); +}; +var $WeakMap = module.exports = __w_pdfjs_require__(103)(WEAK_MAP, wrapper, methods, weak, true, true); +if (fails(function () { + return new $WeakMap().set((Object.freeze || Object)(tmp), 7).get(tmp) != 7; +})) { + InternalMap = weak.getConstructor(wrapper, WEAK_MAP); + assign(InternalMap.prototype, methods); + meta.NEED = true; + each(['delete', 'has', 'get', 'set'], function (key) { + var proto = $WeakMap.prototype; + var method = proto[key]; + redefine(proto, key, function (a, b) { + if (isObject(a) && !isExtensible(a)) { + if (!this._f) this._f = new InternalMap(); + var result = this._f[key](a, b); + return key == 'set' ? this : result; + } + return method.call(this, a, b); + }); + }); +} + +/***/ }), +/* 96 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var ctx = __w_pdfjs_require__(23); +var IObject = __w_pdfjs_require__(37); +var toObject = __w_pdfjs_require__(51); +var toLength = __w_pdfjs_require__(38); +var asc = __w_pdfjs_require__(97); +module.exports = function (TYPE, $create) { + var IS_MAP = TYPE == 1; + var IS_FILTER = TYPE == 2; + var IS_SOME = TYPE == 3; + var IS_EVERY = TYPE == 4; + var IS_FIND_INDEX = TYPE == 6; + var NO_HOLES = TYPE == 5 || IS_FIND_INDEX; + var create = $create || asc; + return function ($this, callbackfn, that) { + var O = toObject($this); + var self = IObject(O); + var f = ctx(callbackfn, that, 3); + var length = toLength(self.length); + var index = 0; + var result = IS_MAP ? create($this, length) : IS_FILTER ? create($this, 0) : undefined; + var val, res; + for (; length > index; index++) { + if (NO_HOLES || index in self) { + val = self[index]; + res = f(val, index, O); + if (TYPE) { + if (IS_MAP) result[index] = res;else if (res) switch (TYPE) { + case 3: + return true; + case 5: + return val; + case 6: + return index; + case 2: + result.push(val); + } else if (IS_EVERY) return false; + } } - return obj.data; - }, - resolve: function PDFObjects_resolve(objId, data) { - var obj = this.ensureObj(objId); - obj.resolved = true; - obj.data = data; - obj.capability.resolve(data); - }, - isResolved: function PDFObjects_isResolved(objId) { - var objs = this.objs; - if (!objs[objId]) { - return false; - } - return objs[objId].resolved; - }, - hasData: function PDFObjects_hasData(objId) { - return this.isResolved(objId); - }, - getData: function PDFObjects_getData(objId) { - var objs = this.objs; - if (!objs[objId] || !objs[objId].resolved) { - return null; - } - return objs[objId].data; - }, - clear: function PDFObjects_clear() { - this.objs = Object.create(null); - } + }return IS_FIND_INDEX ? -1 : IS_SOME || IS_EVERY ? IS_EVERY : result; }; - return PDFObjects; -}(); -var RenderTask = function RenderTaskClosure() { - function RenderTask(internalRenderTask) { - this._internalRenderTask = internalRenderTask; - this.onContinue = null; - } - RenderTask.prototype = { - get promise() { - return this._internalRenderTask.capability.promise; - }, - cancel: function RenderTask_cancel() { - this._internalRenderTask.cancel(); - }, - then: function RenderTask_then(onFulfilled, onRejected) { - return this.promise.then.apply(this.promise, arguments); +}; + +/***/ }), +/* 97 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var speciesConstructor = __w_pdfjs_require__(98); +module.exports = function (original, length) { + return new (speciesConstructor(original))(length); +}; + +/***/ }), +/* 98 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var isObject = __w_pdfjs_require__(13); +var isArray = __w_pdfjs_require__(99); +var SPECIES = __w_pdfjs_require__(28)('species'); +module.exports = function (original) { + var C; + if (isArray(original)) { + C = original.constructor; + if (typeof C == 'function' && (C === Array || isArray(C.prototype))) C = undefined; + if (isObject(C)) { + C = C[SPECIES]; + if (C === null) C = undefined; } - }; - return RenderTask; -}(); -var InternalRenderTask = function InternalRenderTaskClosure() { - function InternalRenderTask(callback, params, objs, commonObjs, operatorList, pageNumber, canvasFactory) { - this.callback = callback; - this.params = params; - this.objs = objs; - this.commonObjs = commonObjs; - this.operatorListIdx = null; - this.operatorList = operatorList; - this.pageNumber = pageNumber; - this.canvasFactory = canvasFactory; - this.running = false; - this.graphicsReadyCallback = null; - this.graphicsReady = false; - this.useRequestAnimationFrame = false; - this.cancelled = false; - this.capability = createPromiseCapability(); - this.task = new RenderTask(this); - this._continueBound = this._continue.bind(this); - this._scheduleNextBound = this._scheduleNext.bind(this); - this._nextBound = this._next.bind(this); } - InternalRenderTask.prototype = { - initializeGraphics: function InternalRenderTask_initializeGraphics(transparency) { - if (this.cancelled) { - return; - } - if (getDefaultSetting('pdfBug') && globalScope.StepperManager && globalScope.StepperManager.enabled) { - this.stepper = globalScope.StepperManager.create(this.pageNumber - 1); - this.stepper.init(this.operatorList); - this.stepper.nextBreakPoint = this.stepper.getNextBreakPoint(); - } - var params = this.params; - this.gfx = new CanvasGraphics(params.canvasContext, this.commonObjs, this.objs, this.canvasFactory, params.imageLayer); - this.gfx.beginDrawing(params.transform, params.viewport, transparency); - this.operatorListIdx = 0; - this.graphicsReady = true; - if (this.graphicsReadyCallback) { - this.graphicsReadyCallback(); - } - }, - cancel: function InternalRenderTask_cancel() { - this.running = false; - this.cancelled = true; - if (getDefaultSetting('pdfjsNext')) { - this.callback(new RenderingCancelledException('Rendering cancelled, page ' + this.pageNumber, 'canvas')); - } else { - this.callback('cancelled'); - } - }, - operatorListChanged: function InternalRenderTask_operatorListChanged() { - if (!this.graphicsReady) { - if (!this.graphicsReadyCallback) { - this.graphicsReadyCallback = this._continueBound; - } - return; - } - if (this.stepper) { - this.stepper.updateOperatorList(this.operatorList); - } - if (this.running) { - return; - } - this._continue(); - }, - _continue: function InternalRenderTask__continue() { - this.running = true; - if (this.cancelled) { - return; - } - if (this.task.onContinue) { - this.task.onContinue(this._scheduleNextBound); - } else { - this._scheduleNext(); - } - }, - _scheduleNext: function InternalRenderTask__scheduleNext() { - if (this.useRequestAnimationFrame && typeof window !== 'undefined') { - window.requestAnimationFrame(this._nextBound); - } else { - Promise.resolve(undefined).then(this._nextBound); - } - }, - _next: function InternalRenderTask__next() { - if (this.cancelled) { - return; - } - this.operatorListIdx = this.gfx.executeOperatorList(this.operatorList, this.operatorListIdx, this._continueBound, this.stepper); - if (this.operatorListIdx === this.operatorList.argsArray.length) { - this.running = false; - if (this.operatorList.lastChunk) { - this.gfx.endDrawing(); - this.callback(); - } - } + return C === undefined ? Array : C; +}; + +/***/ }), +/* 99 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var cof = __w_pdfjs_require__(27); +module.exports = Array.isArray || function isArray(arg) { + return cof(arg) == 'Array'; +}; + +/***/ }), +/* 100 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; + +var META = __w_pdfjs_require__(22)('meta'); +var isObject = __w_pdfjs_require__(13); +var has = __w_pdfjs_require__(21); +var setDesc = __w_pdfjs_require__(11).f; +var id = 0; +var isExtensible = Object.isExtensible || function () { + return true; +}; +var FREEZE = !__w_pdfjs_require__(16)(function () { + return isExtensible(Object.preventExtensions({})); +}); +var setMeta = function setMeta(it) { + setDesc(it, META, { + value: { + i: 'O' + ++id, + w: {} } - }; - return InternalRenderTask; -}(); -var _UnsupportedManager = function UnsupportedManagerClosure() { - var listeners = []; - return { - listen: function (cb) { - deprecated('Global UnsupportedManager.listen is used: ' + ' use PDFDocumentLoadingTask.onUnsupportedFeature instead'); - listeners.push(cb); - }, - notify: function (featureId) { - for (var i = 0, ii = listeners.length; i < ii; i++) { - listeners[i](featureId); + }); +}; +var fastKey = function fastKey(it, create) { + if (!isObject(it)) return (typeof it === 'undefined' ? 'undefined' : _typeof(it)) == 'symbol' ? it : (typeof it == 'string' ? 'S' : 'P') + it; + if (!has(it, META)) { + if (!isExtensible(it)) return 'F'; + if (!create) return 'E'; + setMeta(it); + } + return it[META].i; +}; +var getWeak = function getWeak(it, create) { + if (!has(it, META)) { + if (!isExtensible(it)) return true; + if (!create) return false; + setMeta(it); + } + return it[META].w; +}; +var onFreeze = function onFreeze(it) { + if (FREEZE && meta.NEED && isExtensible(it) && !has(it, META)) setMeta(it); + return it; +}; +var meta = module.exports = { + KEY: META, + NEED: false, + fastKey: fastKey, + getWeak: getWeak, + onFreeze: onFreeze +}; + +/***/ }), +/* 101 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var redefineAll = __w_pdfjs_require__(89); +var getWeak = __w_pdfjs_require__(100).getWeak; +var anObject = __w_pdfjs_require__(12); +var isObject = __w_pdfjs_require__(13); +var anInstance = __w_pdfjs_require__(76); +var forOf = __w_pdfjs_require__(77); +var createArrayMethod = __w_pdfjs_require__(96); +var $has = __w_pdfjs_require__(21); +var validate = __w_pdfjs_require__(102); +var arrayFind = createArrayMethod(5); +var arrayFindIndex = createArrayMethod(6); +var id = 0; +var uncaughtFrozenStore = function uncaughtFrozenStore(that) { + return that._l || (that._l = new UncaughtFrozenStore()); +}; +var UncaughtFrozenStore = function UncaughtFrozenStore() { + this.a = []; +}; +var findUncaughtFrozen = function findUncaughtFrozen(store, key) { + return arrayFind(store.a, function (it) { + return it[0] === key; + }); +}; +UncaughtFrozenStore.prototype = { + get: function get(key) { + var entry = findUncaughtFrozen(this, key); + if (entry) return entry[1]; + }, + has: function has(key) { + return !!findUncaughtFrozen(this, key); + }, + set: function set(key, value) { + var entry = findUncaughtFrozen(this, key); + if (entry) entry[1] = value;else this.a.push([key, value]); + }, + 'delete': function _delete(key) { + var index = arrayFindIndex(this.a, function (it) { + return it[0] === key; + }); + if (~index) this.a.splice(index, 1); + return !!~index; + } +}; +module.exports = { + getConstructor: function getConstructor(wrapper, NAME, IS_MAP, ADDER) { + var C = wrapper(function (that, iterable) { + anInstance(that, C, NAME, '_i'); + that._t = NAME; + that._i = id++; + that._l = undefined; + if (iterable != undefined) forOf(iterable, IS_MAP, that[ADDER], that); + }); + redefineAll(C.prototype, { + 'delete': function _delete(key) { + if (!isObject(key)) return false; + var data = getWeak(key); + if (data === true) return uncaughtFrozenStore(validate(this, NAME))['delete'](key); + return data && $has(data, this._i) && delete data[this._i]; + }, + has: function has(key) { + if (!isObject(key)) return false; + var data = getWeak(key); + if (data === true) return uncaughtFrozenStore(validate(this, NAME)).has(key); + return data && $has(data, this._i); } - } - }; -}(); -exports.version = '1.8.172'; -exports.build = '8ff1fbe7'; -exports.getDocument = getDocument; -exports.PDFDataRangeTransport = PDFDataRangeTransport; -exports.PDFWorker = PDFWorker; -exports.PDFDocumentProxy = PDFDocumentProxy; -exports.PDFPageProxy = PDFPageProxy; -exports._UnsupportedManager = _UnsupportedManager; + }); + return C; + }, + def: function def(that, key, value) { + var data = getWeak(anObject(key), true); + if (data === true) uncaughtFrozenStore(that).set(key, value);else data[that._i] = value; + return that; + }, + ufstore: uncaughtFrozenStore +}; /***/ }), -/* 4 */ +/* 102 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; -var sharedUtil = __w_pdfjs_require__(0); -var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX; -var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX; -var ImageKind = sharedUtil.ImageKind; -var OPS = sharedUtil.OPS; -var Util = sharedUtil.Util; -var isNum = sharedUtil.isNum; -var isArray = sharedUtil.isArray; -var warn = sharedUtil.warn; -var createObjectURL = sharedUtil.createObjectURL; -var SVG_DEFAULTS = { - fontStyle: 'normal', - fontWeight: 'normal', - fillColor: '#000000' -}; -var convertImgDataToPng = function convertImgDataToPngClosure() { - var PNG_HEADER = new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]); - var CHUNK_WRAPPER_SIZE = 12; - var crcTable = new Int32Array(256); - for (var i = 0; i < 256; i++) { - var c = i; - for (var h = 0; h < 8; h++) { - if (c & 1) { - c = 0xedB88320 ^ c >> 1 & 0x7fffffff; - } else { - c = c >> 1 & 0x7fffffff; - } - } - crcTable[i] = c; - } - function crc32(data, start, end) { - var crc = -1; - for (var i = start; i < end; i++) { - var a = (crc ^ data[i]) & 0xff; - var b = crcTable[a]; - crc = crc >>> 8 ^ b; - } - return crc ^ -1; - } - function writePngChunk(type, body, data, offset) { - var p = offset; - var len = body.length; - data[p] = len >> 24 & 0xff; - data[p + 1] = len >> 16 & 0xff; - data[p + 2] = len >> 8 & 0xff; - data[p + 3] = len & 0xff; - p += 4; - data[p] = type.charCodeAt(0) & 0xff; - data[p + 1] = type.charCodeAt(1) & 0xff; - data[p + 2] = type.charCodeAt(2) & 0xff; - data[p + 3] = type.charCodeAt(3) & 0xff; - p += 4; - data.set(body, p); - p += body.length; - var crc = crc32(data, offset + 4, p); - data[p] = crc >> 24 & 0xff; - data[p + 1] = crc >> 16 & 0xff; - data[p + 2] = crc >> 8 & 0xff; - data[p + 3] = crc & 0xff; - } - function adler32(data, start, end) { - var a = 1; - var b = 0; - for (var i = start; i < end; ++i) { - a = (a + (data[i] & 0xff)) % 65521; - b = (b + a) % 65521; - } - return b << 16 | a; - } - function encode(imgData, kind, forceDataSchema) { - var width = imgData.width; - var height = imgData.height; - var bitDepth, colorType, lineSize; - var bytes = imgData.data; - switch (kind) { - case ImageKind.GRAYSCALE_1BPP: - colorType = 0; - bitDepth = 1; - lineSize = width + 7 >> 3; - break; - case ImageKind.RGB_24BPP: - colorType = 2; - bitDepth = 8; - lineSize = width * 3; - break; - case ImageKind.RGBA_32BPP: - colorType = 6; - bitDepth = 8; - lineSize = width * 4; - break; - default: - throw new Error('invalid format'); - } - var literals = new Uint8Array((1 + lineSize) * height); - var offsetLiterals = 0, - offsetBytes = 0; - var y, i; - for (y = 0; y < height; ++y) { - literals[offsetLiterals++] = 0; - literals.set(bytes.subarray(offsetBytes, offsetBytes + lineSize), offsetLiterals); - offsetBytes += lineSize; - offsetLiterals += lineSize; - } - if (kind === ImageKind.GRAYSCALE_1BPP) { - offsetLiterals = 0; - for (y = 0; y < height; y++) { - offsetLiterals++; - for (i = 0; i < lineSize; i++) { - literals[offsetLiterals++] ^= 0xFF; - } - } - } - var ihdr = new Uint8Array([width >> 24 & 0xff, width >> 16 & 0xff, width >> 8 & 0xff, width & 0xff, height >> 24 & 0xff, height >> 16 & 0xff, height >> 8 & 0xff, height & 0xff, bitDepth, colorType, 0x00, 0x00, 0x00]); - var len = literals.length; - var maxBlockLength = 0xFFFF; - var deflateBlocks = Math.ceil(len / maxBlockLength); - var idat = new Uint8Array(2 + len + deflateBlocks * 5 + 4); - var pi = 0; - idat[pi++] = 0x78; - idat[pi++] = 0x9c; - var pos = 0; - while (len > maxBlockLength) { - idat[pi++] = 0x00; - idat[pi++] = 0xff; - idat[pi++] = 0xff; - idat[pi++] = 0x00; - idat[pi++] = 0x00; - idat.set(literals.subarray(pos, pos + maxBlockLength), pi); - pi += maxBlockLength; - pos += maxBlockLength; - len -= maxBlockLength; - } - idat[pi++] = 0x01; - idat[pi++] = len & 0xff; - idat[pi++] = len >> 8 & 0xff; - idat[pi++] = ~len & 0xffff & 0xff; - idat[pi++] = (~len & 0xffff) >> 8 & 0xff; - idat.set(literals.subarray(pos), pi); - pi += literals.length - pos; - var adler = adler32(literals, 0, literals.length); - idat[pi++] = adler >> 24 & 0xff; - idat[pi++] = adler >> 16 & 0xff; - idat[pi++] = adler >> 8 & 0xff; - idat[pi++] = adler & 0xff; - var pngLength = PNG_HEADER.length + CHUNK_WRAPPER_SIZE * 3 + ihdr.length + idat.length; - var data = new Uint8Array(pngLength); - var offset = 0; - data.set(PNG_HEADER, offset); - offset += PNG_HEADER.length; - writePngChunk('IHDR', ihdr, data, offset); - offset += CHUNK_WRAPPER_SIZE + ihdr.length; - writePngChunk('IDATA', idat, data, offset); - offset += CHUNK_WRAPPER_SIZE + idat.length; - writePngChunk('IEND', new Uint8Array(0), data, offset); - return createObjectURL(data, 'image/png', forceDataSchema); - } - return function convertImgDataToPng(imgData, forceDataSchema) { - var kind = imgData.kind === undefined ? ImageKind.GRAYSCALE_1BPP : imgData.kind; - return encode(imgData, kind, forceDataSchema); +var isObject = __w_pdfjs_require__(13); +module.exports = function (it, TYPE) { + if (!isObject(it) || it._t !== TYPE) throw TypeError('Incompatible receiver, ' + TYPE + ' required!'); + return it; +}; + +/***/ }), +/* 103 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var global = __w_pdfjs_require__(8); +var $export = __w_pdfjs_require__(7); +var redefine = __w_pdfjs_require__(20); +var redefineAll = __w_pdfjs_require__(89); +var meta = __w_pdfjs_require__(100); +var forOf = __w_pdfjs_require__(77); +var anInstance = __w_pdfjs_require__(76); +var isObject = __w_pdfjs_require__(13); +var fails = __w_pdfjs_require__(16); +var $iterDetect = __w_pdfjs_require__(91); +var setToStringTag = __w_pdfjs_require__(70); +var inheritIfRequired = __w_pdfjs_require__(104); +module.exports = function (NAME, wrapper, methods, common, IS_MAP, IS_WEAK) { + var Base = global[NAME]; + var C = Base; + var ADDER = IS_MAP ? 'set' : 'add'; + var proto = C && C.prototype; + var O = {}; + var fixMethod = function fixMethod(KEY) { + var fn = proto[KEY]; + redefine(proto, KEY, KEY == 'delete' ? function (a) { + return IS_WEAK && !isObject(a) ? false : fn.call(this, a === 0 ? 0 : a); + } : KEY == 'has' ? function has(a) { + return IS_WEAK && !isObject(a) ? false : fn.call(this, a === 0 ? 0 : a); + } : KEY == 'get' ? function get(a) { + return IS_WEAK && !isObject(a) ? undefined : fn.call(this, a === 0 ? 0 : a); + } : KEY == 'add' ? function add(a) { + fn.call(this, a === 0 ? 0 : a); + return this; + } : function set(a, b) { + fn.call(this, a === 0 ? 0 : a, b); + return this; + }); }; -}(); -var SVGExtraState = function SVGExtraStateClosure() { - function SVGExtraState() { - this.fontSizeScale = 1; - this.fontWeight = SVG_DEFAULTS.fontWeight; - this.fontSize = 0; - this.textMatrix = IDENTITY_MATRIX; - this.fontMatrix = FONT_IDENTITY_MATRIX; - this.leading = 0; - this.x = 0; - this.y = 0; - this.lineX = 0; - this.lineY = 0; - this.charSpacing = 0; - this.wordSpacing = 0; - this.textHScale = 1; - this.textRise = 0; - this.fillColor = SVG_DEFAULTS.fillColor; - this.strokeColor = '#000000'; - this.fillAlpha = 1; - this.strokeAlpha = 1; - this.lineWidth = 1; - this.lineJoin = ''; - this.lineCap = ''; - this.miterLimit = 0; - this.dashArray = []; - this.dashPhase = 0; - this.dependencies = []; - this.activeClipUrl = null; - this.clipGroup = null; - this.maskId = ''; - } - SVGExtraState.prototype = { - clone: function SVGExtraState_clone() { - return Object.create(this); - }, - setCurrentPoint: function SVGExtraState_setCurrentPoint(x, y) { - this.x = x; - this.y = y; + if (typeof C != 'function' || !(IS_WEAK || proto.forEach && !fails(function () { + new C().entries().next(); + }))) { + C = common.getConstructor(wrapper, NAME, IS_MAP, ADDER); + redefineAll(C.prototype, methods); + meta.NEED = true; + } else { + var instance = new C(); + var HASNT_CHAINING = instance[ADDER](IS_WEAK ? {} : -0, 1) != instance; + var THROWS_ON_PRIMITIVES = fails(function () { + instance.has(1); + }); + var ACCEPT_ITERABLES = $iterDetect(function (iter) { + new C(iter); + }); + var BUGGY_ZERO = !IS_WEAK && fails(function () { + var $instance = new C(); + var index = 5; + while (index--) { + $instance[ADDER](index, index); + }return !$instance.has(-0); + }); + if (!ACCEPT_ITERABLES) { + C = wrapper(function (target, iterable) { + anInstance(target, C, NAME); + var that = inheritIfRequired(new Base(), target, C); + if (iterable != undefined) forOf(iterable, IS_MAP, that[ADDER], that); + return that; + }); + C.prototype = proto; + proto.constructor = C; } - }; - return SVGExtraState; -}(); -var SVGGraphics = function SVGGraphicsClosure() { - function opListToTree(opList) { - var opTree = []; - var tmp = []; - var opListLen = opList.length; - for (var x = 0; x < opListLen; x++) { - if (opList[x].fn === 'save') { - opTree.push({ - 'fnId': 92, - 'fn': 'group', - 'items': [] - }); - tmp.push(opTree); - opTree = opTree[opTree.length - 1].items; - continue; - } - if (opList[x].fn === 'restore') { - opTree = tmp.pop(); - } else { - opTree.push(opList[x]); - } + if (THROWS_ON_PRIMITIVES || BUGGY_ZERO) { + fixMethod('delete'); + fixMethod('has'); + IS_MAP && fixMethod('get'); } - return opTree; + if (BUGGY_ZERO || HASNT_CHAINING) fixMethod(ADDER); + if (IS_WEAK && proto.clear) delete proto.clear; } - function pf(value) { - if (value === (value | 0)) { - return value.toString(); - } - var s = value.toFixed(10); - var i = s.length - 1; - if (s[i] !== '0') { - return s; - } - do { - i--; - } while (s[i] === '0'); - return s.substr(0, s[i] === '.' ? i : i + 1); + setToStringTag(C, NAME); + O[NAME] = C; + $export($export.G + $export.W + $export.F * (C != Base), O); + if (!IS_WEAK) common.setStrong(C, NAME, IS_MAP); + return C; +}; + +/***/ }), +/* 104 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var isObject = __w_pdfjs_require__(13); +var setPrototypeOf = __w_pdfjs_require__(105).set; +module.exports = function (that, target, C) { + var S = target.constructor; + var P; + if (S !== C && typeof S == 'function' && (P = S.prototype) !== C.prototype && isObject(P) && setPrototypeOf) { + setPrototypeOf(that, P); } - function pm(m) { - if (m[4] === 0 && m[5] === 0) { - if (m[1] === 0 && m[2] === 0) { - if (m[0] === 1 && m[3] === 1) { - return ''; - } - return 'scale(' + pf(m[0]) + ' ' + pf(m[3]) + ')'; - } - if (m[0] === m[3] && m[1] === -m[2]) { - var a = Math.acos(m[0]) * 180 / Math.PI; - return 'rotate(' + pf(a) + ')'; + return that; +}; + +/***/ }), +/* 105 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var isObject = __w_pdfjs_require__(13); +var anObject = __w_pdfjs_require__(12); +var check = function check(O, proto) { + anObject(O); + if (!isObject(proto) && proto !== null) throw TypeError(proto + ": can't set as prototype!"); +}; +module.exports = { + set: Object.setPrototypeOf || ('__proto__' in {} ? function (test, buggy, set) { + try { + set = __w_pdfjs_require__(23)(Function.call, __w_pdfjs_require__(106).f(Object.prototype, '__proto__').set, 2); + set(test, []); + buggy = !(test instanceof Array); + } catch (e) { + buggy = true; + } + return function setPrototypeOf(O, proto) { + check(O, proto); + if (buggy) O.__proto__ = proto;else set(O, proto); + return O; + }; + }({}, false) : undefined), + check: check +}; + +/***/ }), +/* 106 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var pIE = __w_pdfjs_require__(50); +var createDesc = __w_pdfjs_require__(19); +var toIObject = __w_pdfjs_require__(36); +var toPrimitive = __w_pdfjs_require__(18); +var has = __w_pdfjs_require__(21); +var IE8_DOM_DEFINE = __w_pdfjs_require__(14); +var gOPD = Object.getOwnPropertyDescriptor; +exports.f = __w_pdfjs_require__(15) ? gOPD : function getOwnPropertyDescriptor(O, P) { + O = toIObject(O); + P = toPrimitive(P, true); + if (IE8_DOM_DEFINE) try { + return gOPD(O, P); + } catch (e) {} + if (has(O, P)) return createDesc(!pIE.f.call(O, P), O[P]); +}; + +/***/ }), +/* 107 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +__w_pdfjs_require__(108)('WeakMap'); + +/***/ }), +/* 108 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var $export = __w_pdfjs_require__(7); +module.exports = function (COLLECTION) { + $export($export.S, COLLECTION, { + of: function of() { + var length = arguments.length; + var A = new Array(length); + while (length--) { + A[length] = arguments[length]; + }return new this(A); + } + }); +}; + +/***/ }), +/* 109 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +__w_pdfjs_require__(110)('WeakMap'); + +/***/ }), +/* 110 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var $export = __w_pdfjs_require__(7); +var aFunction = __w_pdfjs_require__(24); +var ctx = __w_pdfjs_require__(23); +var forOf = __w_pdfjs_require__(77); +module.exports = function (COLLECTION) { + $export($export.S, COLLECTION, { + from: function from(source) { + var mapFn = arguments[1]; + var mapping, A, n, cb; + aFunction(this); + mapping = mapFn !== undefined; + if (mapping) aFunction(mapFn); + if (source == undefined) return new this(); + A = []; + if (mapping) { + n = 0; + cb = ctx(mapFn, arguments[2], 2); + forOf(source, false, function (nextItem) { + A.push(cb(nextItem, n++)); + }); + } else { + forOf(source, false, A.push, A); } + return new this(A); + } + }); +}; + +/***/ }), +/* 111 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +__w_pdfjs_require__(112); +module.exports = __w_pdfjs_require__(9).String.codePointAt; + +/***/ }), +/* 112 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var $export = __w_pdfjs_require__(7); +var $at = __w_pdfjs_require__(63)(false); +$export($export.P, 'String', { + codePointAt: function codePointAt(pos) { + return $at(this, pos); + } +}); + +/***/ }), +/* 113 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +__w_pdfjs_require__(114); +module.exports = __w_pdfjs_require__(9).String.fromCodePoint; + +/***/ }), +/* 114 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var $export = __w_pdfjs_require__(7); +var toAbsoluteIndex = __w_pdfjs_require__(40); +var fromCharCode = String.fromCharCode; +var $fromCodePoint = String.fromCodePoint; +$export($export.S + $export.F * (!!$fromCodePoint && $fromCodePoint.length != 1), 'String', { + fromCodePoint: function fromCodePoint(x) { + var res = []; + var aLen = arguments.length; + var i = 0; + var code; + while (aLen > i) { + code = +arguments[i++]; + if (toAbsoluteIndex(code, 0x10ffff) !== code) throw RangeError(code + ' is not a valid code point'); + res.push(code < 0x10000 ? fromCharCode(code) : fromCharCode(((code -= 0x10000) >> 10) + 0xd800, code % 0x400 + 0xdc00)); + } + return res.join(''); + } +}); + +/***/ }), +/* 115 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +__w_pdfjs_require__(116); +__w_pdfjs_require__(60); +module.exports = __w_pdfjs_require__(9).Symbol; + +/***/ }), +/* 116 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; + +var global = __w_pdfjs_require__(8); +var has = __w_pdfjs_require__(21); +var DESCRIPTORS = __w_pdfjs_require__(15); +var $export = __w_pdfjs_require__(7); +var redefine = __w_pdfjs_require__(20); +var META = __w_pdfjs_require__(100).KEY; +var $fails = __w_pdfjs_require__(16); +var shared = __w_pdfjs_require__(29); +var setToStringTag = __w_pdfjs_require__(70); +var uid = __w_pdfjs_require__(22); +var wks = __w_pdfjs_require__(28); +var wksExt = __w_pdfjs_require__(117); +var wksDefine = __w_pdfjs_require__(118); +var enumKeys = __w_pdfjs_require__(119); +var isArray = __w_pdfjs_require__(99); +var anObject = __w_pdfjs_require__(12); +var isObject = __w_pdfjs_require__(13); +var toIObject = __w_pdfjs_require__(36); +var toPrimitive = __w_pdfjs_require__(18); +var createDesc = __w_pdfjs_require__(19); +var _create = __w_pdfjs_require__(67); +var gOPNExt = __w_pdfjs_require__(120); +var $GOPD = __w_pdfjs_require__(106); +var $DP = __w_pdfjs_require__(11); +var $keys = __w_pdfjs_require__(45); +var gOPD = $GOPD.f; +var dP = $DP.f; +var gOPN = gOPNExt.f; +var $Symbol = global.Symbol; +var $JSON = global.JSON; +var _stringify = $JSON && $JSON.stringify; +var PROTOTYPE = 'prototype'; +var HIDDEN = wks('_hidden'); +var TO_PRIMITIVE = wks('toPrimitive'); +var isEnum = {}.propertyIsEnumerable; +var SymbolRegistry = shared('symbol-registry'); +var AllSymbols = shared('symbols'); +var OPSymbols = shared('op-symbols'); +var ObjectProto = Object[PROTOTYPE]; +var USE_NATIVE = typeof $Symbol == 'function'; +var QObject = global.QObject; +var setter = !QObject || !QObject[PROTOTYPE] || !QObject[PROTOTYPE].findChild; +var setSymbolDesc = DESCRIPTORS && $fails(function () { + return _create(dP({}, 'a', { + get: function get() { + return dP(this, 'a', { value: 7 }).a; + } + })).a != 7; +}) ? function (it, key, D) { + var protoDesc = gOPD(ObjectProto, key); + if (protoDesc) delete ObjectProto[key]; + dP(it, key, D); + if (protoDesc && it !== ObjectProto) dP(ObjectProto, key, protoDesc); +} : dP; +var wrap = function wrap(tag) { + var sym = AllSymbols[tag] = _create($Symbol[PROTOTYPE]); + sym._k = tag; + return sym; +}; +var isSymbol = USE_NATIVE && _typeof($Symbol.iterator) == 'symbol' ? function (it) { + return (typeof it === 'undefined' ? 'undefined' : _typeof(it)) == 'symbol'; +} : function (it) { + return it instanceof $Symbol; +}; +var $defineProperty = function defineProperty(it, key, D) { + if (it === ObjectProto) $defineProperty(OPSymbols, key, D); + anObject(it); + key = toPrimitive(key, true); + anObject(D); + if (has(AllSymbols, key)) { + if (!D.enumerable) { + if (!has(it, HIDDEN)) dP(it, HIDDEN, createDesc(1, {})); + it[HIDDEN][key] = true; } else { - if (m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1) { - return 'translate(' + pf(m[4]) + ' ' + pf(m[5]) + ')'; - } + if (has(it, HIDDEN) && it[HIDDEN][key]) it[HIDDEN][key] = false; + D = _create(D, { enumerable: createDesc(0, false) }); } - return 'matrix(' + pf(m[0]) + ' ' + pf(m[1]) + ' ' + pf(m[2]) + ' ' + pf(m[3]) + ' ' + pf(m[4]) + ' ' + pf(m[5]) + ')'; + return setSymbolDesc(it, key, D); } - function SVGGraphics(commonObjs, objs, forceDataSchema) { - this.current = new SVGExtraState(); - this.transformMatrix = IDENTITY_MATRIX; - this.transformStack = []; - this.extraStack = []; - this.commonObjs = commonObjs; - this.objs = objs; - this.pendingEOFill = false; - this.embedFonts = false; - this.embeddedFonts = Object.create(null); - this.cssStyle = null; - this.forceDataSchema = !!forceDataSchema; - } - var NS = 'http://www.w3.org/2000/svg'; - var XML_NS = 'http://www.w3.org/XML/1998/namespace'; - var XLINK_NS = 'http://www.w3.org/1999/xlink'; - var LINE_CAP_STYLES = ['butt', 'round', 'square']; - var LINE_JOIN_STYLES = ['miter', 'round', 'bevel']; - var clipCount = 0; - var maskCount = 0; - SVGGraphics.prototype = { - save: function SVGGraphics_save() { - this.transformStack.push(this.transformMatrix); - var old = this.current; - this.extraStack.push(old); - this.current = old.clone(); - }, - restore: function SVGGraphics_restore() { - this.transformMatrix = this.transformStack.pop(); - this.current = this.extraStack.pop(); - this.tgrp = null; - }, - group: function SVGGraphics_group(items) { - this.save(); - this.executeOpTree(items); - this.restore(); - }, - loadDependencies: function SVGGraphics_loadDependencies(operatorList) { - var fnArray = operatorList.fnArray; - var fnArrayLen = fnArray.length; - var argsArray = operatorList.argsArray; - var self = this; - for (var i = 0; i < fnArrayLen; i++) { - if (OPS.dependency === fnArray[i]) { - var deps = argsArray[i]; - for (var n = 0, nn = deps.length; n < nn; n++) { - var obj = deps[n]; - var common = obj.substring(0, 2) === 'g_'; - var promise; - if (common) { - promise = new Promise(function (resolve) { - self.commonObjs.get(obj, resolve); - }); - } else { - promise = new Promise(function (resolve) { - self.objs.get(obj, resolve); - }); - } - this.current.dependencies.push(promise); - } - } - } - return Promise.all(this.current.dependencies); - }, - transform: function SVGGraphics_transform(a, b, c, d, e, f) { - var transformMatrix = [a, b, c, d, e, f]; - this.transformMatrix = Util.transform(this.transformMatrix, transformMatrix); - this.tgrp = null; - }, - getSVG: function SVGGraphics_getSVG(operatorList, viewport) { - this.viewport = viewport; - var svgElement = this._initialize(viewport); - return this.loadDependencies(operatorList).then(function () { - this.transformMatrix = IDENTITY_MATRIX; - var opTree = this.convertOpList(operatorList); - this.executeOpTree(opTree); - return svgElement; - }.bind(this)); - }, - convertOpList: function SVGGraphics_convertOpList(operatorList) { - var argsArray = operatorList.argsArray; - var fnArray = operatorList.fnArray; - var fnArrayLen = fnArray.length; - var REVOPS = []; - var opList = []; - for (var op in OPS) { - REVOPS[OPS[op]] = op; - } - for (var x = 0; x < fnArrayLen; x++) { - var fnId = fnArray[x]; - opList.push({ - 'fnId': fnId, - 'fn': REVOPS[fnId], - 'args': argsArray[x] - }); + return dP(it, key, D); +}; +var $defineProperties = function defineProperties(it, P) { + anObject(it); + var keys = enumKeys(P = toIObject(P)); + var i = 0; + var l = keys.length; + var key; + while (l > i) { + $defineProperty(it, key = keys[i++], P[key]); + }return it; +}; +var $create = function create(it, P) { + return P === undefined ? _create(it) : $defineProperties(_create(it), P); +}; +var $propertyIsEnumerable = function propertyIsEnumerable(key) { + var E = isEnum.call(this, key = toPrimitive(key, true)); + if (this === ObjectProto && has(AllSymbols, key) && !has(OPSymbols, key)) return false; + return E || !has(this, key) || !has(AllSymbols, key) || has(this, HIDDEN) && this[HIDDEN][key] ? E : true; +}; +var $getOwnPropertyDescriptor = function getOwnPropertyDescriptor(it, key) { + it = toIObject(it); + key = toPrimitive(key, true); + if (it === ObjectProto && has(AllSymbols, key) && !has(OPSymbols, key)) return; + var D = gOPD(it, key); + if (D && has(AllSymbols, key) && !(has(it, HIDDEN) && it[HIDDEN][key])) D.enumerable = true; + return D; +}; +var $getOwnPropertyNames = function getOwnPropertyNames(it) { + var names = gOPN(toIObject(it)); + var result = []; + var i = 0; + var key; + while (names.length > i) { + if (!has(AllSymbols, key = names[i++]) && key != HIDDEN && key != META) result.push(key); + } + return result; +}; +var $getOwnPropertySymbols = function getOwnPropertySymbols(it) { + var IS_OP = it === ObjectProto; + var names = gOPN(IS_OP ? OPSymbols : toIObject(it)); + var result = []; + var i = 0; + var key; + while (names.length > i) { + if (has(AllSymbols, key = names[i++]) && (IS_OP ? has(ObjectProto, key) : true)) result.push(AllSymbols[key]); + } + return result; +}; +if (!USE_NATIVE) { + $Symbol = function _Symbol() { + if (this instanceof $Symbol) throw TypeError('Symbol is not a constructor!'); + var tag = uid(arguments.length > 0 ? arguments[0] : undefined); + var $set = function $set(value) { + if (this === ObjectProto) $set.call(OPSymbols, value); + if (has(this, HIDDEN) && has(this[HIDDEN], tag)) this[HIDDEN][tag] = false; + setSymbolDesc(this, tag, createDesc(1, value)); + }; + if (DESCRIPTORS && setter) setSymbolDesc(ObjectProto, tag, { + configurable: true, + set: $set + }); + return wrap(tag); + }; + redefine($Symbol[PROTOTYPE], 'toString', function toString() { + return this._k; + }); + $GOPD.f = $getOwnPropertyDescriptor; + $DP.f = $defineProperty; + __w_pdfjs_require__(121).f = gOPNExt.f = $getOwnPropertyNames; + __w_pdfjs_require__(50).f = $propertyIsEnumerable; + __w_pdfjs_require__(49).f = $getOwnPropertySymbols; + if (DESCRIPTORS && !__w_pdfjs_require__(30)) { + redefine(ObjectProto, 'propertyIsEnumerable', $propertyIsEnumerable, true); + } + wksExt.f = function (name) { + return wrap(wks(name)); + }; +} +$export($export.G + $export.W + $export.F * !USE_NATIVE, { Symbol: $Symbol }); +for (var es6Symbols = 'hasInstance,isConcatSpreadable,iterator,match,replace,search,species,split,toPrimitive,toStringTag,unscopables'.split(','), j = 0; es6Symbols.length > j;) { + wks(es6Symbols[j++]); +}for (var wellKnownSymbols = $keys(wks.store), k = 0; wellKnownSymbols.length > k;) { + wksDefine(wellKnownSymbols[k++]); +}$export($export.S + $export.F * !USE_NATIVE, 'Symbol', { + 'for': function _for(key) { + return has(SymbolRegistry, key += '') ? SymbolRegistry[key] : SymbolRegistry[key] = $Symbol(key); + }, + keyFor: function keyFor(sym) { + if (!isSymbol(sym)) throw TypeError(sym + ' is not a symbol!'); + for (var key in SymbolRegistry) { + if (SymbolRegistry[key] === sym) return key; + } + }, + useSetter: function useSetter() { + setter = true; + }, + useSimple: function useSimple() { + setter = false; + } +}); +$export($export.S + $export.F * !USE_NATIVE, 'Object', { + create: $create, + defineProperty: $defineProperty, + defineProperties: $defineProperties, + getOwnPropertyDescriptor: $getOwnPropertyDescriptor, + getOwnPropertyNames: $getOwnPropertyNames, + getOwnPropertySymbols: $getOwnPropertySymbols +}); +$JSON && $export($export.S + $export.F * (!USE_NATIVE || $fails(function () { + var S = $Symbol(); + return _stringify([S]) != '[null]' || _stringify({ a: S }) != '{}' || _stringify(Object(S)) != '{}'; +})), 'JSON', { + stringify: function stringify(it) { + var args = [it]; + var i = 1; + var replacer, $replacer; + while (arguments.length > i) { + args.push(arguments[i++]); + }$replacer = replacer = args[1]; + if (!isObject(replacer) && it === undefined || isSymbol(it)) return; + if (!isArray(replacer)) replacer = function replacer(key, value) { + if (typeof $replacer == 'function') value = $replacer.call(this, key, value); + if (!isSymbol(value)) return value; + }; + args[1] = replacer; + return _stringify.apply($JSON, args); + } +}); +$Symbol[PROTOTYPE][TO_PRIMITIVE] || __w_pdfjs_require__(10)($Symbol[PROTOTYPE], TO_PRIMITIVE, $Symbol[PROTOTYPE].valueOf); +setToStringTag($Symbol, 'Symbol'); +setToStringTag(Math, 'Math', true); +setToStringTag(global.JSON, 'JSON', true); + +/***/ }), +/* 117 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +exports.f = __w_pdfjs_require__(28); + +/***/ }), +/* 118 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var global = __w_pdfjs_require__(8); +var core = __w_pdfjs_require__(9); +var LIBRARY = __w_pdfjs_require__(30); +var wksExt = __w_pdfjs_require__(117); +var defineProperty = __w_pdfjs_require__(11).f; +module.exports = function (name) { + var $Symbol = core.Symbol || (core.Symbol = LIBRARY ? {} : global.Symbol || {}); + if (name.charAt(0) != '_' && !(name in $Symbol)) defineProperty($Symbol, name, { value: wksExt.f(name) }); +}; + +/***/ }), +/* 119 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var getKeys = __w_pdfjs_require__(45); +var gOPS = __w_pdfjs_require__(49); +var pIE = __w_pdfjs_require__(50); +module.exports = function (it) { + var result = getKeys(it); + var getSymbols = gOPS.f; + if (getSymbols) { + var symbols = getSymbols(it); + var isEnum = pIE.f; + var i = 0; + var key; + while (symbols.length > i) { + if (isEnum.call(it, key = symbols[i++])) result.push(key); + } + } + return result; +}; + +/***/ }), +/* 120 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; + +var toIObject = __w_pdfjs_require__(36); +var gOPN = __w_pdfjs_require__(121).f; +var toString = {}.toString; +var windowNames = (typeof window === 'undefined' ? 'undefined' : _typeof(window)) == 'object' && window && Object.getOwnPropertyNames ? Object.getOwnPropertyNames(window) : []; +var getWindowNames = function getWindowNames(it) { + try { + return gOPN(it); + } catch (e) { + return windowNames.slice(); + } +}; +module.exports.f = function getOwnPropertyNames(it) { + return windowNames && toString.call(it) == '[object Window]' ? getWindowNames(it) : gOPN(toIObject(it)); +}; + +/***/ }), +/* 121 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var $keys = __w_pdfjs_require__(46); +var hiddenKeys = __w_pdfjs_require__(48).concat('length', 'prototype'); +exports.f = Object.getOwnPropertyNames || function getOwnPropertyNames(O) { + return $keys(O, hiddenKeys); +}; + +/***/ }), +/* 122 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +__w_pdfjs_require__(123); +module.exports = __w_pdfjs_require__(9).Object.values; + +/***/ }), +/* 123 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var $export = __w_pdfjs_require__(7); +var $values = __w_pdfjs_require__(124)(false); +$export($export.S, 'Object', { + values: function values(it) { + return $values(it); + } +}); + +/***/ }), +/* 124 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var getKeys = __w_pdfjs_require__(45); +var toIObject = __w_pdfjs_require__(36); +var isEnum = __w_pdfjs_require__(50).f; +module.exports = function (isEntries) { + return function (it) { + var O = toIObject(it); + var keys = getKeys(O); + var length = keys.length; + var i = 0; + var result = []; + var key; + while (length > i) { + if (isEnum.call(O, key = keys[i++])) { + result.push(isEntries ? [key, O[key]] : O[key]); + } + }return result; + }; +}; + +/***/ }), +/* 125 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var isReadableStreamSupported = false; +if (typeof ReadableStream !== 'undefined') { + try { + new ReadableStream({ + start: function start(controller) { + controller.close(); } - return opListToTree(opList); - }, - executeOpTree: function SVGGraphics_executeOpTree(opTree) { - var opTreeLen = opTree.length; - for (var x = 0; x < opTreeLen; x++) { - var fn = opTree[x].fn; - var fnId = opTree[x].fnId; - var args = opTree[x].args; - switch (fnId | 0) { - case OPS.beginText: - this.beginText(); - break; - case OPS.setLeading: - this.setLeading(args); - break; - case OPS.setLeadingMoveText: - this.setLeadingMoveText(args[0], args[1]); - break; - case OPS.setFont: - this.setFont(args); - break; - case OPS.showText: - this.showText(args[0]); - break; - case OPS.showSpacedText: - this.showText(args[0]); - break; - case OPS.endText: - this.endText(); - break; - case OPS.moveText: - this.moveText(args[0], args[1]); - break; - case OPS.setCharSpacing: - this.setCharSpacing(args[0]); - break; - case OPS.setWordSpacing: - this.setWordSpacing(args[0]); - break; - case OPS.setHScale: - this.setHScale(args[0]); - break; - case OPS.setTextMatrix: - this.setTextMatrix(args[0], args[1], args[2], args[3], args[4], args[5]); - break; - case OPS.setLineWidth: - this.setLineWidth(args[0]); - break; - case OPS.setLineJoin: - this.setLineJoin(args[0]); - break; - case OPS.setLineCap: - this.setLineCap(args[0]); - break; - case OPS.setMiterLimit: - this.setMiterLimit(args[0]); - break; - case OPS.setFillRGBColor: - this.setFillRGBColor(args[0], args[1], args[2]); - break; - case OPS.setStrokeRGBColor: - this.setStrokeRGBColor(args[0], args[1], args[2]); - break; - case OPS.setDash: - this.setDash(args[0], args[1]); - break; - case OPS.setGState: - this.setGState(args[0]); - break; - case OPS.fill: - this.fill(); - break; - case OPS.eoFill: - this.eoFill(); - break; - case OPS.stroke: - this.stroke(); - break; - case OPS.fillStroke: - this.fillStroke(); - break; - case OPS.eoFillStroke: - this.eoFillStroke(); - break; - case OPS.clip: - this.clip('nonzero'); - break; - case OPS.eoClip: - this.clip('evenodd'); - break; - case OPS.paintSolidColorImageMask: - this.paintSolidColorImageMask(); - break; - case OPS.paintJpegXObject: - this.paintJpegXObject(args[0], args[1], args[2]); - break; - case OPS.paintImageXObject: - this.paintImageXObject(args[0]); - break; - case OPS.paintInlineImageXObject: - this.paintInlineImageXObject(args[0]); - break; - case OPS.paintImageMaskXObject: - this.paintImageMaskXObject(args[0]); - break; - case OPS.paintFormXObjectBegin: - this.paintFormXObjectBegin(args[0], args[1]); - break; - case OPS.paintFormXObjectEnd: - this.paintFormXObjectEnd(); - break; - case OPS.closePath: - this.closePath(); - break; - case OPS.closeStroke: - this.closeStroke(); - break; - case OPS.closeFillStroke: - this.closeFillStroke(); - break; - case OPS.nextLine: - this.nextLine(); - break; - case OPS.transform: - this.transform(args[0], args[1], args[2], args[3], args[4], args[5]); - break; - case OPS.constructPath: - this.constructPath(args[0], args[1]); - break; - case OPS.endPath: - this.endPath(); - break; - case 92: - this.group(opTree[x].items); - break; - default: - warn('Unimplemented operator ' + fn); - break; + }); + isReadableStreamSupported = true; + } catch (e) {} +} +if (isReadableStreamSupported) { + exports.ReadableStream = ReadableStream; +} else { + exports.ReadableStream = __w_pdfjs_require__(126).ReadableStream; +} + +/***/ }), +/* 126 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var _typeof2 = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; + +(function (e, a) { + for (var i in a) { + e[i] = a[i]; + } +})(exports, function (modules) { + var installedModules = {}; + function __w_pdfjs_require__(moduleId) { + if (installedModules[moduleId]) return installedModules[moduleId].exports; + var module = installedModules[moduleId] = { + i: moduleId, + l: false, + exports: {} + }; + modules[moduleId].call(module.exports, module, module.exports, __w_pdfjs_require__); + module.l = true; + return module.exports; + } + __w_pdfjs_require__.m = modules; + __w_pdfjs_require__.c = installedModules; + __w_pdfjs_require__.i = function (value) { + return value; + }; + __w_pdfjs_require__.d = function (exports, name, getter) { + if (!__w_pdfjs_require__.o(exports, name)) { + Object.defineProperty(exports, name, { + configurable: false, + enumerable: true, + get: getter + }); + } + }; + __w_pdfjs_require__.n = function (module) { + var getter = module && module.__esModule ? function getDefault() { + return module['default']; + } : function getModuleExports() { + return module; + }; + __w_pdfjs_require__.d(getter, 'a', getter); + return getter; + }; + __w_pdfjs_require__.o = function (object, property) { + return Object.prototype.hasOwnProperty.call(object, property); + }; + __w_pdfjs_require__.p = ""; + return __w_pdfjs_require__(__w_pdfjs_require__.s = 7); +}([function (module, exports, __w_pdfjs_require__) { + "use strict"; + + var _typeof = typeof Symbol === "function" && _typeof2(Symbol.iterator) === "symbol" ? function (obj) { + return typeof obj === 'undefined' ? 'undefined' : _typeof2(obj); + } : function (obj) { + return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj === 'undefined' ? 'undefined' : _typeof2(obj); + }; + var _require = __w_pdfjs_require__(1), + assert = _require.assert; + function IsPropertyKey(argument) { + return typeof argument === 'string' || (typeof argument === 'undefined' ? 'undefined' : _typeof(argument)) === 'symbol'; + } + exports.typeIsObject = function (x) { + return (typeof x === 'undefined' ? 'undefined' : _typeof(x)) === 'object' && x !== null || typeof x === 'function'; + }; + exports.createDataProperty = function (o, p, v) { + assert(exports.typeIsObject(o)); + Object.defineProperty(o, p, { + value: v, + writable: true, + enumerable: true, + configurable: true + }); + }; + exports.createArrayFromList = function (elements) { + return elements.slice(); + }; + exports.ArrayBufferCopy = function (dest, destOffset, src, srcOffset, n) { + new Uint8Array(dest).set(new Uint8Array(src, srcOffset, n), destOffset); + }; + exports.CreateIterResultObject = function (value, done) { + assert(typeof done === 'boolean'); + var obj = {}; + Object.defineProperty(obj, 'value', { + value: value, + enumerable: true, + writable: true, + configurable: true + }); + Object.defineProperty(obj, 'done', { + value: done, + enumerable: true, + writable: true, + configurable: true + }); + return obj; + }; + exports.IsFiniteNonNegativeNumber = function (v) { + if (Number.isNaN(v)) { + return false; + } + if (v === Infinity) { + return false; + } + if (v < 0) { + return false; + } + return true; + }; + function Call(F, V, args) { + if (typeof F !== 'function') { + throw new TypeError('Argument is not a function'); + } + return Function.prototype.apply.call(F, V, args); + } + exports.InvokeOrNoop = function (O, P, args) { + assert(O !== undefined); + assert(IsPropertyKey(P)); + assert(Array.isArray(args)); + var method = O[P]; + if (method === undefined) { + return undefined; + } + return Call(method, O, args); + }; + exports.PromiseInvokeOrNoop = function (O, P, args) { + assert(O !== undefined); + assert(IsPropertyKey(P)); + assert(Array.isArray(args)); + try { + return Promise.resolve(exports.InvokeOrNoop(O, P, args)); + } catch (returnValueE) { + return Promise.reject(returnValueE); + } + }; + exports.PromiseInvokeOrPerformFallback = function (O, P, args, F, argsF) { + assert(O !== undefined); + assert(IsPropertyKey(P)); + assert(Array.isArray(args)); + assert(Array.isArray(argsF)); + var method = void 0; + try { + method = O[P]; + } catch (methodE) { + return Promise.reject(methodE); + } + if (method === undefined) { + return F.apply(null, argsF); + } + try { + return Promise.resolve(Call(method, O, args)); + } catch (e) { + return Promise.reject(e); + } + }; + exports.TransferArrayBuffer = function (O) { + return O.slice(); + }; + exports.ValidateAndNormalizeHighWaterMark = function (highWaterMark) { + highWaterMark = Number(highWaterMark); + if (Number.isNaN(highWaterMark) || highWaterMark < 0) { + throw new RangeError('highWaterMark property of a queuing strategy must be non-negative and non-NaN'); + } + return highWaterMark; + }; + exports.ValidateAndNormalizeQueuingStrategy = function (size, highWaterMark) { + if (size !== undefined && typeof size !== 'function') { + throw new TypeError('size property of a queuing strategy must be a function'); + } + highWaterMark = exports.ValidateAndNormalizeHighWaterMark(highWaterMark); + return { + size: size, + highWaterMark: highWaterMark + }; + }; +}, function (module, exports, __w_pdfjs_require__) { + "use strict"; + + function rethrowAssertionErrorRejection(e) { + if (e && e.constructor === AssertionError) { + setTimeout(function () { + throw e; + }, 0); + } + } + function AssertionError(message) { + this.name = 'AssertionError'; + this.message = message || ''; + this.stack = new Error().stack; + } + AssertionError.prototype = Object.create(Error.prototype); + AssertionError.prototype.constructor = AssertionError; + function assert(value, message) { + if (!value) { + throw new AssertionError(message); + } + } + module.exports = { + rethrowAssertionErrorRejection: rethrowAssertionErrorRejection, + AssertionError: AssertionError, + assert: assert + }; +}, function (module, exports, __w_pdfjs_require__) { + "use strict"; + + var _createClass = function () { + function defineProperties(target, props) { + for (var i = 0; i < props.length; i++) { + var descriptor = props[i]; + descriptor.enumerable = descriptor.enumerable || false; + descriptor.configurable = true; + if ("value" in descriptor) descriptor.writable = true; + Object.defineProperty(target, descriptor.key, descriptor); + } + } + return function (Constructor, protoProps, staticProps) { + if (protoProps) defineProperties(Constructor.prototype, protoProps); + if (staticProps) defineProperties(Constructor, staticProps); + return Constructor; + }; + }(); + function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } + } + var _require = __w_pdfjs_require__(0), + InvokeOrNoop = _require.InvokeOrNoop, + PromiseInvokeOrNoop = _require.PromiseInvokeOrNoop, + ValidateAndNormalizeQueuingStrategy = _require.ValidateAndNormalizeQueuingStrategy, + typeIsObject = _require.typeIsObject; + var _require2 = __w_pdfjs_require__(1), + assert = _require2.assert, + rethrowAssertionErrorRejection = _require2.rethrowAssertionErrorRejection; + var _require3 = __w_pdfjs_require__(3), + DequeueValue = _require3.DequeueValue, + EnqueueValueWithSize = _require3.EnqueueValueWithSize, + PeekQueueValue = _require3.PeekQueueValue, + ResetQueue = _require3.ResetQueue; + var WritableStream = function () { + function WritableStream() { + var underlyingSink = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + size = _ref.size, + _ref$highWaterMark = _ref.highWaterMark, + highWaterMark = _ref$highWaterMark === undefined ? 1 : _ref$highWaterMark; + _classCallCheck(this, WritableStream); + this._state = 'writable'; + this._storedError = undefined; + this._writer = undefined; + this._writableStreamController = undefined; + this._writeRequests = []; + this._inFlightWriteRequest = undefined; + this._closeRequest = undefined; + this._inFlightCloseRequest = undefined; + this._pendingAbortRequest = undefined; + this._backpressure = false; + var type = underlyingSink.type; + if (type !== undefined) { + throw new RangeError('Invalid type is specified'); + } + this._writableStreamController = new WritableStreamDefaultController(this, underlyingSink, size, highWaterMark); + this._writableStreamController.__startSteps(); + } + _createClass(WritableStream, [{ + key: 'abort', + value: function abort(reason) { + if (IsWritableStream(this) === false) { + return Promise.reject(streamBrandCheckException('abort')); + } + if (IsWritableStreamLocked(this) === true) { + return Promise.reject(new TypeError('Cannot abort a stream that already has a writer')); } + return WritableStreamAbort(this, reason); } - }, - setWordSpacing: function SVGGraphics_setWordSpacing(wordSpacing) { - this.current.wordSpacing = wordSpacing; - }, - setCharSpacing: function SVGGraphics_setCharSpacing(charSpacing) { - this.current.charSpacing = charSpacing; - }, - nextLine: function SVGGraphics_nextLine() { - this.moveText(0, this.current.leading); - }, - setTextMatrix: function SVGGraphics_setTextMatrix(a, b, c, d, e, f) { - var current = this.current; - this.current.textMatrix = this.current.lineMatrix = [a, b, c, d, e, f]; - this.current.x = this.current.lineX = 0; - this.current.y = this.current.lineY = 0; - current.xcoords = []; - current.tspan = document.createElementNS(NS, 'svg:tspan'); - current.tspan.setAttributeNS(null, 'font-family', current.fontFamily); - current.tspan.setAttributeNS(null, 'font-size', pf(current.fontSize) + 'px'); - current.tspan.setAttributeNS(null, 'y', pf(-current.y)); - current.txtElement = document.createElementNS(NS, 'svg:text'); - current.txtElement.appendChild(current.tspan); - }, - beginText: function SVGGraphics_beginText() { - this.current.x = this.current.lineX = 0; - this.current.y = this.current.lineY = 0; - this.current.textMatrix = IDENTITY_MATRIX; - this.current.lineMatrix = IDENTITY_MATRIX; - this.current.tspan = document.createElementNS(NS, 'svg:tspan'); - this.current.txtElement = document.createElementNS(NS, 'svg:text'); - this.current.txtgrp = document.createElementNS(NS, 'svg:g'); - this.current.xcoords = []; - }, - moveText: function SVGGraphics_moveText(x, y) { - var current = this.current; - this.current.x = this.current.lineX += x; - this.current.y = this.current.lineY += y; - current.xcoords = []; - current.tspan = document.createElementNS(NS, 'svg:tspan'); - current.tspan.setAttributeNS(null, 'font-family', current.fontFamily); - current.tspan.setAttributeNS(null, 'font-size', pf(current.fontSize) + 'px'); - current.tspan.setAttributeNS(null, 'y', pf(-current.y)); - }, - showText: function SVGGraphics_showText(glyphs) { - var current = this.current; - var font = current.font; - var fontSize = current.fontSize; - if (fontSize === 0) { - return; + }, { + key: 'getWriter', + value: function getWriter() { + if (IsWritableStream(this) === false) { + throw streamBrandCheckException('getWriter'); + } + return AcquireWritableStreamDefaultWriter(this); } - var charSpacing = current.charSpacing; - var wordSpacing = current.wordSpacing; - var fontDirection = current.fontDirection; - var textHScale = current.textHScale * fontDirection; - var glyphsLength = glyphs.length; - var vertical = font.vertical; - var widthAdvanceScale = fontSize * current.fontMatrix[0]; - var x = 0, - i; - for (i = 0; i < glyphsLength; ++i) { - var glyph = glyphs[i]; - if (glyph === null) { - x += fontDirection * wordSpacing; - continue; - } else if (isNum(glyph)) { - x += -glyph * fontSize * 0.001; - continue; + }, { + key: 'locked', + get: function get() { + if (IsWritableStream(this) === false) { + throw streamBrandCheckException('locked'); } - current.xcoords.push(current.x + x * textHScale); - var width = glyph.width; - var character = glyph.fontChar; - var charWidth = width * widthAdvanceScale + charSpacing * fontDirection; - x += charWidth; - current.tspan.textContent += character; + return IsWritableStreamLocked(this); + } + }]); + return WritableStream; + }(); + module.exports = { + AcquireWritableStreamDefaultWriter: AcquireWritableStreamDefaultWriter, + IsWritableStream: IsWritableStream, + IsWritableStreamLocked: IsWritableStreamLocked, + WritableStream: WritableStream, + WritableStreamAbort: WritableStreamAbort, + WritableStreamDefaultControllerError: WritableStreamDefaultControllerError, + WritableStreamDefaultWriterCloseWithErrorPropagation: WritableStreamDefaultWriterCloseWithErrorPropagation, + WritableStreamDefaultWriterRelease: WritableStreamDefaultWriterRelease, + WritableStreamDefaultWriterWrite: WritableStreamDefaultWriterWrite, + WritableStreamCloseQueuedOrInFlight: WritableStreamCloseQueuedOrInFlight + }; + function AcquireWritableStreamDefaultWriter(stream) { + return new WritableStreamDefaultWriter(stream); + } + function IsWritableStream(x) { + if (!typeIsObject(x)) { + return false; + } + if (!Object.prototype.hasOwnProperty.call(x, '_writableStreamController')) { + return false; + } + return true; + } + function IsWritableStreamLocked(stream) { + assert(IsWritableStream(stream) === true, 'IsWritableStreamLocked should only be used on known writable streams'); + if (stream._writer === undefined) { + return false; + } + return true; + } + function WritableStreamAbort(stream, reason) { + var state = stream._state; + if (state === 'closed') { + return Promise.resolve(undefined); + } + if (state === 'errored') { + return Promise.reject(stream._storedError); + } + var error = new TypeError('Requested to abort'); + if (stream._pendingAbortRequest !== undefined) { + return Promise.reject(error); + } + assert(state === 'writable' || state === 'erroring', 'state must be writable or erroring'); + var wasAlreadyErroring = false; + if (state === 'erroring') { + wasAlreadyErroring = true; + reason = undefined; + } + var promise = new Promise(function (resolve, reject) { + stream._pendingAbortRequest = { + _resolve: resolve, + _reject: reject, + _reason: reason, + _wasAlreadyErroring: wasAlreadyErroring + }; + }); + if (wasAlreadyErroring === false) { + WritableStreamStartErroring(stream, error); + } + return promise; + } + function WritableStreamAddWriteRequest(stream) { + assert(IsWritableStreamLocked(stream) === true); + assert(stream._state === 'writable'); + var promise = new Promise(function (resolve, reject) { + var writeRequest = { + _resolve: resolve, + _reject: reject + }; + stream._writeRequests.push(writeRequest); + }); + return promise; + } + function WritableStreamDealWithRejection(stream, error) { + var state = stream._state; + if (state === 'writable') { + WritableStreamStartErroring(stream, error); + return; + } + assert(state === 'erroring'); + WritableStreamFinishErroring(stream); + } + function WritableStreamStartErroring(stream, reason) { + assert(stream._storedError === undefined, 'stream._storedError === undefined'); + assert(stream._state === 'writable', 'state must be writable'); + var controller = stream._writableStreamController; + assert(controller !== undefined, 'controller must not be undefined'); + stream._state = 'erroring'; + stream._storedError = reason; + var writer = stream._writer; + if (writer !== undefined) { + WritableStreamDefaultWriterEnsureReadyPromiseRejected(writer, reason); + } + if (WritableStreamHasOperationMarkedInFlight(stream) === false && controller._started === true) { + WritableStreamFinishErroring(stream); + } + } + function WritableStreamFinishErroring(stream) { + assert(stream._state === 'erroring', 'stream._state === erroring'); + assert(WritableStreamHasOperationMarkedInFlight(stream) === false, 'WritableStreamHasOperationMarkedInFlight(stream) === false'); + stream._state = 'errored'; + stream._writableStreamController.__errorSteps(); + var storedError = stream._storedError; + for (var i = 0; i < stream._writeRequests.length; i++) { + var writeRequest = stream._writeRequests[i]; + writeRequest._reject(storedError); + } + stream._writeRequests = []; + if (stream._pendingAbortRequest === undefined) { + WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream); + return; + } + var abortRequest = stream._pendingAbortRequest; + stream._pendingAbortRequest = undefined; + if (abortRequest._wasAlreadyErroring === true) { + abortRequest._reject(storedError); + WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream); + return; + } + var promise = stream._writableStreamController.__abortSteps(abortRequest._reason); + promise.then(function () { + abortRequest._resolve(); + WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream); + }, function (reason) { + abortRequest._reject(reason); + WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream); + }); + } + function WritableStreamFinishInFlightWrite(stream) { + assert(stream._inFlightWriteRequest !== undefined); + stream._inFlightWriteRequest._resolve(undefined); + stream._inFlightWriteRequest = undefined; + } + function WritableStreamFinishInFlightWriteWithError(stream, error) { + assert(stream._inFlightWriteRequest !== undefined); + stream._inFlightWriteRequest._reject(error); + stream._inFlightWriteRequest = undefined; + assert(stream._state === 'writable' || stream._state === 'erroring'); + WritableStreamDealWithRejection(stream, error); + } + function WritableStreamFinishInFlightClose(stream) { + assert(stream._inFlightCloseRequest !== undefined); + stream._inFlightCloseRequest._resolve(undefined); + stream._inFlightCloseRequest = undefined; + var state = stream._state; + assert(state === 'writable' || state === 'erroring'); + if (state === 'erroring') { + stream._storedError = undefined; + if (stream._pendingAbortRequest !== undefined) { + stream._pendingAbortRequest._resolve(); + stream._pendingAbortRequest = undefined; } - if (vertical) { - current.y -= x * textHScale; + } + stream._state = 'closed'; + var writer = stream._writer; + if (writer !== undefined) { + defaultWriterClosedPromiseResolve(writer); + } + assert(stream._pendingAbortRequest === undefined, 'stream._pendingAbortRequest === undefined'); + assert(stream._storedError === undefined, 'stream._storedError === undefined'); + } + function WritableStreamFinishInFlightCloseWithError(stream, error) { + assert(stream._inFlightCloseRequest !== undefined); + stream._inFlightCloseRequest._reject(error); + stream._inFlightCloseRequest = undefined; + assert(stream._state === 'writable' || stream._state === 'erroring'); + if (stream._pendingAbortRequest !== undefined) { + stream._pendingAbortRequest._reject(error); + stream._pendingAbortRequest = undefined; + } + WritableStreamDealWithRejection(stream, error); + } + function WritableStreamCloseQueuedOrInFlight(stream) { + if (stream._closeRequest === undefined && stream._inFlightCloseRequest === undefined) { + return false; + } + return true; + } + function WritableStreamHasOperationMarkedInFlight(stream) { + if (stream._inFlightWriteRequest === undefined && stream._inFlightCloseRequest === undefined) { + return false; + } + return true; + } + function WritableStreamMarkCloseRequestInFlight(stream) { + assert(stream._inFlightCloseRequest === undefined); + assert(stream._closeRequest !== undefined); + stream._inFlightCloseRequest = stream._closeRequest; + stream._closeRequest = undefined; + } + function WritableStreamMarkFirstWriteRequestInFlight(stream) { + assert(stream._inFlightWriteRequest === undefined, 'there must be no pending write request'); + assert(stream._writeRequests.length !== 0, 'writeRequests must not be empty'); + stream._inFlightWriteRequest = stream._writeRequests.shift(); + } + function WritableStreamRejectCloseAndClosedPromiseIfNeeded(stream) { + assert(stream._state === 'errored', '_stream_.[[state]] is `"errored"`'); + if (stream._closeRequest !== undefined) { + assert(stream._inFlightCloseRequest === undefined); + stream._closeRequest._reject(stream._storedError); + stream._closeRequest = undefined; + } + var writer = stream._writer; + if (writer !== undefined) { + defaultWriterClosedPromiseReject(writer, stream._storedError); + writer._closedPromise.catch(function () {}); + } + } + function WritableStreamUpdateBackpressure(stream, backpressure) { + assert(stream._state === 'writable'); + assert(WritableStreamCloseQueuedOrInFlight(stream) === false); + var writer = stream._writer; + if (writer !== undefined && backpressure !== stream._backpressure) { + if (backpressure === true) { + defaultWriterReadyPromiseReset(writer); } else { - current.x += x * textHScale; + assert(backpressure === false); + defaultWriterReadyPromiseResolve(writer); } - current.tspan.setAttributeNS(null, 'x', current.xcoords.map(pf).join(' ')); - current.tspan.setAttributeNS(null, 'y', pf(-current.y)); - current.tspan.setAttributeNS(null, 'font-family', current.fontFamily); - current.tspan.setAttributeNS(null, 'font-size', pf(current.fontSize) + 'px'); - if (current.fontStyle !== SVG_DEFAULTS.fontStyle) { - current.tspan.setAttributeNS(null, 'font-style', current.fontStyle); + } + stream._backpressure = backpressure; + } + var WritableStreamDefaultWriter = function () { + function WritableStreamDefaultWriter(stream) { + _classCallCheck(this, WritableStreamDefaultWriter); + if (IsWritableStream(stream) === false) { + throw new TypeError('WritableStreamDefaultWriter can only be constructed with a WritableStream instance'); + } + if (IsWritableStreamLocked(stream) === true) { + throw new TypeError('This stream has already been locked for exclusive writing by another writer'); + } + this._ownerWritableStream = stream; + stream._writer = this; + var state = stream._state; + if (state === 'writable') { + if (WritableStreamCloseQueuedOrInFlight(stream) === false && stream._backpressure === true) { + defaultWriterReadyPromiseInitialize(this); + } else { + defaultWriterReadyPromiseInitializeAsResolved(this); + } + defaultWriterClosedPromiseInitialize(this); + } else if (state === 'erroring') { + defaultWriterReadyPromiseInitializeAsRejected(this, stream._storedError); + this._readyPromise.catch(function () {}); + defaultWriterClosedPromiseInitialize(this); + } else if (state === 'closed') { + defaultWriterReadyPromiseInitializeAsResolved(this); + defaultWriterClosedPromiseInitializeAsResolved(this); + } else { + assert(state === 'errored', 'state must be errored'); + var storedError = stream._storedError; + defaultWriterReadyPromiseInitializeAsRejected(this, storedError); + this._readyPromise.catch(function () {}); + defaultWriterClosedPromiseInitializeAsRejected(this, storedError); + this._closedPromise.catch(function () {}); } - if (current.fontWeight !== SVG_DEFAULTS.fontWeight) { - current.tspan.setAttributeNS(null, 'font-weight', current.fontWeight); + } + _createClass(WritableStreamDefaultWriter, [{ + key: 'abort', + value: function abort(reason) { + if (IsWritableStreamDefaultWriter(this) === false) { + return Promise.reject(defaultWriterBrandCheckException('abort')); + } + if (this._ownerWritableStream === undefined) { + return Promise.reject(defaultWriterLockException('abort')); + } + return WritableStreamDefaultWriterAbort(this, reason); } - if (current.fillColor !== SVG_DEFAULTS.fillColor) { - current.tspan.setAttributeNS(null, 'fill', current.fillColor); + }, { + key: 'close', + value: function close() { + if (IsWritableStreamDefaultWriter(this) === false) { + return Promise.reject(defaultWriterBrandCheckException('close')); + } + var stream = this._ownerWritableStream; + if (stream === undefined) { + return Promise.reject(defaultWriterLockException('close')); + } + if (WritableStreamCloseQueuedOrInFlight(stream) === true) { + return Promise.reject(new TypeError('cannot close an already-closing stream')); + } + return WritableStreamDefaultWriterClose(this); } - current.txtElement.setAttributeNS(null, 'transform', pm(current.textMatrix) + ' scale(1, -1)'); - current.txtElement.setAttributeNS(XML_NS, 'xml:space', 'preserve'); - current.txtElement.appendChild(current.tspan); - current.txtgrp.appendChild(current.txtElement); - this._ensureTransformGroup().appendChild(current.txtElement); - }, - setLeadingMoveText: function SVGGraphics_setLeadingMoveText(x, y) { - this.setLeading(-y); - this.moveText(x, y); - }, - addFontStyle: function SVGGraphics_addFontStyle(fontObj) { - if (!this.cssStyle) { - this.cssStyle = document.createElementNS(NS, 'svg:style'); - this.cssStyle.setAttributeNS(null, 'type', 'text/css'); - this.defs.appendChild(this.cssStyle); + }, { + key: 'releaseLock', + value: function releaseLock() { + if (IsWritableStreamDefaultWriter(this) === false) { + throw defaultWriterBrandCheckException('releaseLock'); + } + var stream = this._ownerWritableStream; + if (stream === undefined) { + return; + } + assert(stream._writer !== undefined); + WritableStreamDefaultWriterRelease(this); + } + }, { + key: 'write', + value: function write(chunk) { + if (IsWritableStreamDefaultWriter(this) === false) { + return Promise.reject(defaultWriterBrandCheckException('write')); + } + if (this._ownerWritableStream === undefined) { + return Promise.reject(defaultWriterLockException('write to')); + } + return WritableStreamDefaultWriterWrite(this, chunk); } - var url = createObjectURL(fontObj.data, fontObj.mimetype, this.forceDataSchema); - this.cssStyle.textContent += '@font-face { font-family: "' + fontObj.loadedName + '";' + ' src: url(' + url + '); }\n'; - }, - setFont: function SVGGraphics_setFont(details) { - var current = this.current; - var fontObj = this.commonObjs.get(details[0]); - var size = details[1]; - this.current.font = fontObj; - if (this.embedFonts && fontObj.data && !this.embeddedFonts[fontObj.loadedName]) { - this.addFontStyle(fontObj); - this.embeddedFonts[fontObj.loadedName] = fontObj; + }, { + key: 'closed', + get: function get() { + if (IsWritableStreamDefaultWriter(this) === false) { + return Promise.reject(defaultWriterBrandCheckException('closed')); + } + return this._closedPromise; } - current.fontMatrix = fontObj.fontMatrix ? fontObj.fontMatrix : FONT_IDENTITY_MATRIX; - var bold = fontObj.black ? fontObj.bold ? 'bolder' : 'bold' : fontObj.bold ? 'bold' : 'normal'; - var italic = fontObj.italic ? 'italic' : 'normal'; - if (size < 0) { - size = -size; - current.fontDirection = -1; - } else { - current.fontDirection = 1; + }, { + key: 'desiredSize', + get: function get() { + if (IsWritableStreamDefaultWriter(this) === false) { + throw defaultWriterBrandCheckException('desiredSize'); + } + if (this._ownerWritableStream === undefined) { + throw defaultWriterLockException('desiredSize'); + } + return WritableStreamDefaultWriterGetDesiredSize(this); } - current.fontSize = size; - current.fontFamily = fontObj.loadedName; - current.fontWeight = bold; - current.fontStyle = italic; - current.tspan = document.createElementNS(NS, 'svg:tspan'); - current.tspan.setAttributeNS(null, 'y', pf(-current.y)); - current.xcoords = []; - }, - endText: function SVGGraphics_endText() {}, - setLineWidth: function SVGGraphics_setLineWidth(width) { - this.current.lineWidth = width; - }, - setLineCap: function SVGGraphics_setLineCap(style) { - this.current.lineCap = LINE_CAP_STYLES[style]; - }, - setLineJoin: function SVGGraphics_setLineJoin(style) { - this.current.lineJoin = LINE_JOIN_STYLES[style]; - }, - setMiterLimit: function SVGGraphics_setMiterLimit(limit) { - this.current.miterLimit = limit; - }, - setStrokeRGBColor: function SVGGraphics_setStrokeRGBColor(r, g, b) { - var color = Util.makeCssRgb(r, g, b); - this.current.strokeColor = color; - }, - setFillRGBColor: function SVGGraphics_setFillRGBColor(r, g, b) { - var color = Util.makeCssRgb(r, g, b); - this.current.fillColor = color; - this.current.tspan = document.createElementNS(NS, 'svg:tspan'); - this.current.xcoords = []; - }, - setDash: function SVGGraphics_setDash(dashArray, dashPhase) { - this.current.dashArray = dashArray; - this.current.dashPhase = dashPhase; - }, - constructPath: function SVGGraphics_constructPath(ops, args) { - var current = this.current; - var x = current.x, - y = current.y; - current.path = document.createElementNS(NS, 'svg:path'); - var d = []; - var opLength = ops.length; - for (var i = 0, j = 0; i < opLength; i++) { - switch (ops[i] | 0) { - case OPS.rectangle: - x = args[j++]; - y = args[j++]; - var width = args[j++]; - var height = args[j++]; - var xw = x + width; - var yh = y + height; - d.push('M', pf(x), pf(y), 'L', pf(xw), pf(y), 'L', pf(xw), pf(yh), 'L', pf(x), pf(yh), 'Z'); - break; - case OPS.moveTo: - x = args[j++]; - y = args[j++]; - d.push('M', pf(x), pf(y)); - break; - case OPS.lineTo: - x = args[j++]; - y = args[j++]; - d.push('L', pf(x), pf(y)); - break; - case OPS.curveTo: - x = args[j + 4]; - y = args[j + 5]; - d.push('C', pf(args[j]), pf(args[j + 1]), pf(args[j + 2]), pf(args[j + 3]), pf(x), pf(y)); - j += 6; - break; - case OPS.curveTo2: - x = args[j + 2]; - y = args[j + 3]; - d.push('C', pf(x), pf(y), pf(args[j]), pf(args[j + 1]), pf(args[j + 2]), pf(args[j + 3])); - j += 4; - break; - case OPS.curveTo3: - x = args[j + 2]; - y = args[j + 3]; - d.push('C', pf(args[j]), pf(args[j + 1]), pf(x), pf(y), pf(x), pf(y)); - j += 4; - break; - case OPS.closePath: - d.push('Z'); - break; - } - } - current.path.setAttributeNS(null, 'd', d.join(' ')); - current.path.setAttributeNS(null, 'stroke-miterlimit', pf(current.miterLimit)); - current.path.setAttributeNS(null, 'stroke-linecap', current.lineCap); - current.path.setAttributeNS(null, 'stroke-linejoin', current.lineJoin); - current.path.setAttributeNS(null, 'stroke-width', pf(current.lineWidth) + 'px'); - current.path.setAttributeNS(null, 'stroke-dasharray', current.dashArray.map(pf).join(' ')); - current.path.setAttributeNS(null, 'stroke-dashoffset', pf(current.dashPhase) + 'px'); - current.path.setAttributeNS(null, 'fill', 'none'); - this._ensureTransformGroup().appendChild(current.path); - current.element = current.path; - current.setCurrentPoint(x, y); - }, - endPath: function SVGGraphics_endPath() {}, - clip: function SVGGraphics_clip(type) { - var current = this.current; - var clipId = 'clippath' + clipCount; - clipCount++; - var clipPath = document.createElementNS(NS, 'svg:clipPath'); - clipPath.setAttributeNS(null, 'id', clipId); - clipPath.setAttributeNS(null, 'transform', pm(this.transformMatrix)); - var clipElement = current.element.cloneNode(); - if (type === 'evenodd') { - clipElement.setAttributeNS(null, 'clip-rule', 'evenodd'); - } else { - clipElement.setAttributeNS(null, 'clip-rule', 'nonzero'); - } - clipPath.appendChild(clipElement); - this.defs.appendChild(clipPath); - if (current.activeClipUrl) { - current.clipGroup = null; - this.extraStack.forEach(function (prev) { - prev.clipGroup = null; - }); - } - current.activeClipUrl = 'url(#' + clipId + ')'; - this.tgrp = null; - }, - closePath: function SVGGraphics_closePath() { - var current = this.current; - var d = current.path.getAttributeNS(null, 'd'); - d += 'Z'; - current.path.setAttributeNS(null, 'd', d); - }, - setLeading: function SVGGraphics_setLeading(leading) { - this.current.leading = -leading; - }, - setTextRise: function SVGGraphics_setTextRise(textRise) { - this.current.textRise = textRise; - }, - setHScale: function SVGGraphics_setHScale(scale) { - this.current.textHScale = scale / 100; - }, - setGState: function SVGGraphics_setGState(states) { - for (var i = 0, ii = states.length; i < ii; i++) { - var state = states[i]; - var key = state[0]; - var value = state[1]; - switch (key) { - case 'LW': - this.setLineWidth(value); - break; - case 'LC': - this.setLineCap(value); - break; - case 'LJ': - this.setLineJoin(value); - break; - case 'ML': - this.setMiterLimit(value); - break; - case 'D': - this.setDash(value[0], value[1]); - break; - case 'Font': - this.setFont(value); - break; - default: - warn('Unimplemented graphic state ' + key); - break; - } - } - }, - fill: function SVGGraphics_fill() { - var current = this.current; - current.element.setAttributeNS(null, 'fill', current.fillColor); - }, - stroke: function SVGGraphics_stroke() { - var current = this.current; - current.element.setAttributeNS(null, 'stroke', current.strokeColor); - current.element.setAttributeNS(null, 'fill', 'none'); - }, - eoFill: function SVGGraphics_eoFill() { - var current = this.current; - current.element.setAttributeNS(null, 'fill', current.fillColor); - current.element.setAttributeNS(null, 'fill-rule', 'evenodd'); - }, - fillStroke: function SVGGraphics_fillStroke() { - this.stroke(); - this.fill(); - }, - eoFillStroke: function SVGGraphics_eoFillStroke() { - this.current.element.setAttributeNS(null, 'fill-rule', 'evenodd'); - this.fillStroke(); - }, - closeStroke: function SVGGraphics_closeStroke() { - this.closePath(); - this.stroke(); - }, - closeFillStroke: function SVGGraphics_closeFillStroke() { - this.closePath(); - this.fillStroke(); - }, - paintSolidColorImageMask: function SVGGraphics_paintSolidColorImageMask() { - var current = this.current; - var rect = document.createElementNS(NS, 'svg:rect'); - rect.setAttributeNS(null, 'x', '0'); - rect.setAttributeNS(null, 'y', '0'); - rect.setAttributeNS(null, 'width', '1px'); - rect.setAttributeNS(null, 'height', '1px'); - rect.setAttributeNS(null, 'fill', current.fillColor); - this._ensureTransformGroup().appendChild(rect); - }, - paintJpegXObject: function SVGGraphics_paintJpegXObject(objId, w, h) { - var imgObj = this.objs.get(objId); - var imgEl = document.createElementNS(NS, 'svg:image'); - imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgObj.src); - imgEl.setAttributeNS(null, 'width', imgObj.width + 'px'); - imgEl.setAttributeNS(null, 'height', imgObj.height + 'px'); - imgEl.setAttributeNS(null, 'x', '0'); - imgEl.setAttributeNS(null, 'y', pf(-h)); - imgEl.setAttributeNS(null, 'transform', 'scale(' + pf(1 / w) + ' ' + pf(-1 / h) + ')'); - this._ensureTransformGroup().appendChild(imgEl); - }, - paintImageXObject: function SVGGraphics_paintImageXObject(objId) { - var imgData = this.objs.get(objId); - if (!imgData) { - warn('Dependent image isn\'t ready yet'); - return; - } - this.paintInlineImageXObject(imgData); - }, - paintInlineImageXObject: function SVGGraphics_paintInlineImageXObject(imgData, mask) { - var width = imgData.width; - var height = imgData.height; - var imgSrc = convertImgDataToPng(imgData, this.forceDataSchema); - var cliprect = document.createElementNS(NS, 'svg:rect'); - cliprect.setAttributeNS(null, 'x', '0'); - cliprect.setAttributeNS(null, 'y', '0'); - cliprect.setAttributeNS(null, 'width', pf(width)); - cliprect.setAttributeNS(null, 'height', pf(height)); - this.current.element = cliprect; - this.clip('nonzero'); - var imgEl = document.createElementNS(NS, 'svg:image'); - imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgSrc); - imgEl.setAttributeNS(null, 'x', '0'); - imgEl.setAttributeNS(null, 'y', pf(-height)); - imgEl.setAttributeNS(null, 'width', pf(width) + 'px'); - imgEl.setAttributeNS(null, 'height', pf(height) + 'px'); - imgEl.setAttributeNS(null, 'transform', 'scale(' + pf(1 / width) + ' ' + pf(-1 / height) + ')'); - if (mask) { - mask.appendChild(imgEl); - } else { - this._ensureTransformGroup().appendChild(imgEl); - } - }, - paintImageMaskXObject: function SVGGraphics_paintImageMaskXObject(imgData) { - var current = this.current; - var width = imgData.width; - var height = imgData.height; - var fillColor = current.fillColor; - current.maskId = 'mask' + maskCount++; - var mask = document.createElementNS(NS, 'svg:mask'); - mask.setAttributeNS(null, 'id', current.maskId); - var rect = document.createElementNS(NS, 'svg:rect'); - rect.setAttributeNS(null, 'x', '0'); - rect.setAttributeNS(null, 'y', '0'); - rect.setAttributeNS(null, 'width', pf(width)); - rect.setAttributeNS(null, 'height', pf(height)); - rect.setAttributeNS(null, 'fill', fillColor); - rect.setAttributeNS(null, 'mask', 'url(#' + current.maskId + ')'); - this.defs.appendChild(mask); - this._ensureTransformGroup().appendChild(rect); - this.paintInlineImageXObject(imgData, mask); - }, - paintFormXObjectBegin: function SVGGraphics_paintFormXObjectBegin(matrix, bbox) { - if (isArray(matrix) && matrix.length === 6) { - this.transform(matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]); - } - if (isArray(bbox) && bbox.length === 4) { - var width = bbox[2] - bbox[0]; - var height = bbox[3] - bbox[1]; - var cliprect = document.createElementNS(NS, 'svg:rect'); - cliprect.setAttributeNS(null, 'x', bbox[0]); - cliprect.setAttributeNS(null, 'y', bbox[1]); - cliprect.setAttributeNS(null, 'width', pf(width)); - cliprect.setAttributeNS(null, 'height', pf(height)); - this.current.element = cliprect; - this.clip('nonzero'); - this.endPath(); - } - }, - paintFormXObjectEnd: function SVGGraphics_paintFormXObjectEnd() {}, - _initialize: function SVGGraphics_initialize(viewport) { - var svg = document.createElementNS(NS, 'svg:svg'); - svg.setAttributeNS(null, 'version', '1.1'); - svg.setAttributeNS(null, 'width', viewport.width + 'px'); - svg.setAttributeNS(null, 'height', viewport.height + 'px'); - svg.setAttributeNS(null, 'preserveAspectRatio', 'none'); - svg.setAttributeNS(null, 'viewBox', '0 0 ' + viewport.width + ' ' + viewport.height); - var definitions = document.createElementNS(NS, 'svg:defs'); - svg.appendChild(definitions); - this.defs = definitions; - var rootGroup = document.createElementNS(NS, 'svg:g'); - rootGroup.setAttributeNS(null, 'transform', pm(viewport.transform)); - svg.appendChild(rootGroup); - this.svg = rootGroup; - return svg; - }, - _ensureClipGroup: function SVGGraphics_ensureClipGroup() { - if (!this.current.clipGroup) { - var clipGroup = document.createElementNS(NS, 'svg:g'); - clipGroup.setAttributeNS(null, 'clip-path', this.current.activeClipUrl); - this.svg.appendChild(clipGroup); - this.current.clipGroup = clipGroup; - } - return this.current.clipGroup; - }, - _ensureTransformGroup: function SVGGraphics_ensureTransformGroup() { - if (!this.tgrp) { - this.tgrp = document.createElementNS(NS, 'svg:g'); - this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix)); - if (this.current.activeClipUrl) { - this._ensureClipGroup().appendChild(this.tgrp); - } else { - this.svg.appendChild(this.tgrp); + }, { + key: 'ready', + get: function get() { + if (IsWritableStreamDefaultWriter(this) === false) { + return Promise.reject(defaultWriterBrandCheckException('ready')); } + return this._readyPromise; } - return this.tgrp; + }]); + return WritableStreamDefaultWriter; + }(); + function IsWritableStreamDefaultWriter(x) { + if (!typeIsObject(x)) { + return false; } - }; - return SVGGraphics; -}(); -exports.SVGGraphics = SVGGraphics; - -/***/ }), -/* 5 */ -/***/ (function(module, exports, __w_pdfjs_require__) { - -"use strict"; - - -var sharedUtil = __w_pdfjs_require__(0); -var displayDOMUtils = __w_pdfjs_require__(1); -var Util = sharedUtil.Util; -var createPromiseCapability = sharedUtil.createPromiseCapability; -var CustomStyle = displayDOMUtils.CustomStyle; -var getDefaultSetting = displayDOMUtils.getDefaultSetting; -var renderTextLayer = function renderTextLayerClosure() { - var MAX_TEXT_DIVS_TO_RENDER = 100000; - var NonWhitespaceRegexp = /\S/; - function isAllWhitespace(str) { - return !NonWhitespaceRegexp.test(str); + if (!Object.prototype.hasOwnProperty.call(x, '_ownerWritableStream')) { + return false; + } + return true; } - var styleBuf = ['left: ', 0, 'px; top: ', 0, 'px; font-size: ', 0, 'px; font-family: ', '', ';']; - function appendText(task, geom, styles) { - var textDiv = document.createElement('div'); - var textDivProperties = { - style: null, - angle: 0, - canvasWidth: 0, - isWhitespace: false, - originalTransform: null, - paddingBottom: 0, - paddingLeft: 0, - paddingRight: 0, - paddingTop: 0, - scale: 1 - }; - task._textDivs.push(textDiv); - if (isAllWhitespace(geom.str)) { - textDivProperties.isWhitespace = true; - task._textDivProperties.set(textDiv, textDivProperties); - return; + function WritableStreamDefaultWriterAbort(writer, reason) { + var stream = writer._ownerWritableStream; + assert(stream !== undefined); + return WritableStreamAbort(stream, reason); + } + function WritableStreamDefaultWriterClose(writer) { + var stream = writer._ownerWritableStream; + assert(stream !== undefined); + var state = stream._state; + if (state === 'closed' || state === 'errored') { + return Promise.reject(new TypeError('The stream (in ' + state + ' state) is not in the writable state and cannot be closed')); } - var tx = Util.transform(task._viewport.transform, geom.transform); - var angle = Math.atan2(tx[1], tx[0]); - var style = styles[geom.fontName]; - if (style.vertical) { - angle += Math.PI / 2; + assert(state === 'writable' || state === 'erroring'); + assert(WritableStreamCloseQueuedOrInFlight(stream) === false); + var promise = new Promise(function (resolve, reject) { + var closeRequest = { + _resolve: resolve, + _reject: reject + }; + stream._closeRequest = closeRequest; + }); + if (stream._backpressure === true && state === 'writable') { + defaultWriterReadyPromiseResolve(writer); } - var fontHeight = Math.sqrt(tx[2] * tx[2] + tx[3] * tx[3]); - var fontAscent = fontHeight; - if (style.ascent) { - fontAscent = style.ascent * fontAscent; - } else if (style.descent) { - fontAscent = (1 + style.descent) * fontAscent; + WritableStreamDefaultControllerClose(stream._writableStreamController); + return promise; + } + function WritableStreamDefaultWriterCloseWithErrorPropagation(writer) { + var stream = writer._ownerWritableStream; + assert(stream !== undefined); + var state = stream._state; + if (WritableStreamCloseQueuedOrInFlight(stream) === true || state === 'closed') { + return Promise.resolve(); } - var left; - var top; - if (angle === 0) { - left = tx[4]; - top = tx[5] - fontAscent; + if (state === 'errored') { + return Promise.reject(stream._storedError); + } + assert(state === 'writable' || state === 'erroring'); + return WritableStreamDefaultWriterClose(writer); + } + function WritableStreamDefaultWriterEnsureClosedPromiseRejected(writer, error) { + if (writer._closedPromiseState === 'pending') { + defaultWriterClosedPromiseReject(writer, error); } else { - left = tx[4] + fontAscent * Math.sin(angle); - top = tx[5] - fontAscent * Math.cos(angle); + defaultWriterClosedPromiseResetToRejected(writer, error); } - styleBuf[1] = left; - styleBuf[3] = top; - styleBuf[5] = fontHeight; - styleBuf[7] = style.fontFamily; - textDivProperties.style = styleBuf.join(''); - textDiv.setAttribute('style', textDivProperties.style); - textDiv.textContent = geom.str; - if (getDefaultSetting('pdfBug')) { - textDiv.dataset.fontName = geom.fontName; + writer._closedPromise.catch(function () {}); + } + function WritableStreamDefaultWriterEnsureReadyPromiseRejected(writer, error) { + if (writer._readyPromiseState === 'pending') { + defaultWriterReadyPromiseReject(writer, error); + } else { + defaultWriterReadyPromiseResetToRejected(writer, error); } - if (angle !== 0) { - textDivProperties.angle = angle * (180 / Math.PI); + writer._readyPromise.catch(function () {}); + } + function WritableStreamDefaultWriterGetDesiredSize(writer) { + var stream = writer._ownerWritableStream; + var state = stream._state; + if (state === 'errored' || state === 'erroring') { + return null; } - if (geom.str.length > 1) { - if (style.vertical) { - textDivProperties.canvasWidth = geom.height * task._viewport.scale; - } else { - textDivProperties.canvasWidth = geom.width * task._viewport.scale; - } + if (state === 'closed') { + return 0; } - task._textDivProperties.set(textDiv, textDivProperties); - if (task._enhanceTextSelection) { - var angleCos = 1, - angleSin = 0; - if (angle !== 0) { - angleCos = Math.cos(angle); - angleSin = Math.sin(angle); - } - var divWidth = (style.vertical ? geom.height : geom.width) * task._viewport.scale; - var divHeight = fontHeight; - var m, b; - if (angle !== 0) { - m = [angleCos, angleSin, -angleSin, angleCos, left, top]; - b = Util.getAxialAlignedBoundingBox([0, 0, divWidth, divHeight], m); - } else { - b = [left, top, left + divWidth, top + divHeight]; - } - task._bounds.push({ - left: b[0], - top: b[1], - right: b[2], - bottom: b[3], - div: textDiv, - size: [divWidth, divHeight], - m: m - }); + return WritableStreamDefaultControllerGetDesiredSize(stream._writableStreamController); + } + function WritableStreamDefaultWriterRelease(writer) { + var stream = writer._ownerWritableStream; + assert(stream !== undefined); + assert(stream._writer === writer); + var releasedError = new TypeError('Writer was released and can no longer be used to monitor the stream\'s closedness'); + WritableStreamDefaultWriterEnsureReadyPromiseRejected(writer, releasedError); + WritableStreamDefaultWriterEnsureClosedPromiseRejected(writer, releasedError); + stream._writer = undefined; + writer._ownerWritableStream = undefined; + } + function WritableStreamDefaultWriterWrite(writer, chunk) { + var stream = writer._ownerWritableStream; + assert(stream !== undefined); + var controller = stream._writableStreamController; + var chunkSize = WritableStreamDefaultControllerGetChunkSize(controller, chunk); + if (stream !== writer._ownerWritableStream) { + return Promise.reject(defaultWriterLockException('write to')); + } + var state = stream._state; + if (state === 'errored') { + return Promise.reject(stream._storedError); + } + if (WritableStreamCloseQueuedOrInFlight(stream) === true || state === 'closed') { + return Promise.reject(new TypeError('The stream is closing or closed and cannot be written to')); } + if (state === 'erroring') { + return Promise.reject(stream._storedError); + } + assert(state === 'writable'); + var promise = WritableStreamAddWriteRequest(stream); + WritableStreamDefaultControllerWrite(controller, chunk, chunkSize); + return promise; } - function render(task) { - if (task._canceled) { + var WritableStreamDefaultController = function () { + function WritableStreamDefaultController(stream, underlyingSink, size, highWaterMark) { + _classCallCheck(this, WritableStreamDefaultController); + if (IsWritableStream(stream) === false) { + throw new TypeError('WritableStreamDefaultController can only be constructed with a WritableStream instance'); + } + if (stream._writableStreamController !== undefined) { + throw new TypeError('WritableStreamDefaultController instances can only be created by the WritableStream constructor'); + } + this._controlledWritableStream = stream; + this._underlyingSink = underlyingSink; + this._queue = undefined; + this._queueTotalSize = undefined; + ResetQueue(this); + this._started = false; + var normalizedStrategy = ValidateAndNormalizeQueuingStrategy(size, highWaterMark); + this._strategySize = normalizedStrategy.size; + this._strategyHWM = normalizedStrategy.highWaterMark; + var backpressure = WritableStreamDefaultControllerGetBackpressure(this); + WritableStreamUpdateBackpressure(stream, backpressure); + } + _createClass(WritableStreamDefaultController, [{ + key: 'error', + value: function error(e) { + if (IsWritableStreamDefaultController(this) === false) { + throw new TypeError('WritableStreamDefaultController.prototype.error can only be used on a WritableStreamDefaultController'); + } + var state = this._controlledWritableStream._state; + if (state !== 'writable') { + return; + } + WritableStreamDefaultControllerError(this, e); + } + }, { + key: '__abortSteps', + value: function __abortSteps(reason) { + return PromiseInvokeOrNoop(this._underlyingSink, 'abort', [reason]); + } + }, { + key: '__errorSteps', + value: function __errorSteps() { + ResetQueue(this); + } + }, { + key: '__startSteps', + value: function __startSteps() { + var _this = this; + var startResult = InvokeOrNoop(this._underlyingSink, 'start', [this]); + var stream = this._controlledWritableStream; + Promise.resolve(startResult).then(function () { + assert(stream._state === 'writable' || stream._state === 'erroring'); + _this._started = true; + WritableStreamDefaultControllerAdvanceQueueIfNeeded(_this); + }, function (r) { + assert(stream._state === 'writable' || stream._state === 'erroring'); + _this._started = true; + WritableStreamDealWithRejection(stream, r); + }).catch(rethrowAssertionErrorRejection); + } + }]); + return WritableStreamDefaultController; + }(); + function WritableStreamDefaultControllerClose(controller) { + EnqueueValueWithSize(controller, 'close', 0); + WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller); + } + function WritableStreamDefaultControllerGetChunkSize(controller, chunk) { + var strategySize = controller._strategySize; + if (strategySize === undefined) { + return 1; + } + try { + return strategySize(chunk); + } catch (chunkSizeE) { + WritableStreamDefaultControllerErrorIfNeeded(controller, chunkSizeE); + return 1; + } + } + function WritableStreamDefaultControllerGetDesiredSize(controller) { + return controller._strategyHWM - controller._queueTotalSize; + } + function WritableStreamDefaultControllerWrite(controller, chunk, chunkSize) { + var writeRecord = { chunk: chunk }; + try { + EnqueueValueWithSize(controller, writeRecord, chunkSize); + } catch (enqueueE) { + WritableStreamDefaultControllerErrorIfNeeded(controller, enqueueE); return; } - var textLayerFrag = task._container; - var textDivs = task._textDivs; - var capability = task._capability; - var textDivsLength = textDivs.length; - if (textDivsLength > MAX_TEXT_DIVS_TO_RENDER) { - task._renderingDone = true; - capability.resolve(); + var stream = controller._controlledWritableStream; + if (WritableStreamCloseQueuedOrInFlight(stream) === false && stream._state === 'writable') { + var backpressure = WritableStreamDefaultControllerGetBackpressure(controller); + WritableStreamUpdateBackpressure(stream, backpressure); + } + WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller); + } + function IsWritableStreamDefaultController(x) { + if (!typeIsObject(x)) { + return false; + } + if (!Object.prototype.hasOwnProperty.call(x, '_underlyingSink')) { + return false; + } + return true; + } + function WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller) { + var stream = controller._controlledWritableStream; + if (controller._started === false) { return; } - var canvas = document.createElement('canvas'); - canvas.mozOpaque = true; - var ctx = canvas.getContext('2d', { alpha: false }); - var lastFontSize; - var lastFontFamily; - for (var i = 0; i < textDivsLength; i++) { - var textDiv = textDivs[i]; - var textDivProperties = task._textDivProperties.get(textDiv); - if (textDivProperties.isWhitespace) { - continue; - } - var fontSize = textDiv.style.fontSize; - var fontFamily = textDiv.style.fontFamily; - if (fontSize !== lastFontSize || fontFamily !== lastFontFamily) { - ctx.font = fontSize + ' ' + fontFamily; - lastFontSize = fontSize; - lastFontFamily = fontFamily; - } - var width = ctx.measureText(textDiv.textContent).width; - textLayerFrag.appendChild(textDiv); - var transform = ''; - if (textDivProperties.canvasWidth !== 0 && width > 0) { - textDivProperties.scale = textDivProperties.canvasWidth / width; - transform = 'scaleX(' + textDivProperties.scale + ')'; - } - if (textDivProperties.angle !== 0) { - transform = 'rotate(' + textDivProperties.angle + 'deg) ' + transform; - } - if (transform !== '') { - textDivProperties.originalTransform = transform; - CustomStyle.setProp('transform', textDiv, transform); - } - task._textDivProperties.set(textDiv, textDivProperties); + if (stream._inFlightWriteRequest !== undefined) { + return; + } + var state = stream._state; + if (state === 'closed' || state === 'errored') { + return; + } + if (state === 'erroring') { + WritableStreamFinishErroring(stream); + return; + } + if (controller._queue.length === 0) { + return; + } + var writeRecord = PeekQueueValue(controller); + if (writeRecord === 'close') { + WritableStreamDefaultControllerProcessClose(controller); + } else { + WritableStreamDefaultControllerProcessWrite(controller, writeRecord.chunk); } - task._renderingDone = true; - capability.resolve(); } - function expand(task) { - var bounds = task._bounds; - var viewport = task._viewport; - var expanded = expandBounds(viewport.width, viewport.height, bounds); - for (var i = 0; i < expanded.length; i++) { - var div = bounds[i].div; - var divProperties = task._textDivProperties.get(div); - if (divProperties.angle === 0) { - divProperties.paddingLeft = bounds[i].left - expanded[i].left; - divProperties.paddingTop = bounds[i].top - expanded[i].top; - divProperties.paddingRight = expanded[i].right - bounds[i].right; - divProperties.paddingBottom = expanded[i].bottom - bounds[i].bottom; - task._textDivProperties.set(div, divProperties); - continue; - } - var e = expanded[i], - b = bounds[i]; - var m = b.m, - c = m[0], - s = m[1]; - var points = [[0, 0], [0, b.size[1]], [b.size[0], 0], b.size]; - var ts = new Float64Array(64); - points.forEach(function (p, i) { - var t = Util.applyTransform(p, m); - ts[i + 0] = c && (e.left - t[0]) / c; - ts[i + 4] = s && (e.top - t[1]) / s; - ts[i + 8] = c && (e.right - t[0]) / c; - ts[i + 12] = s && (e.bottom - t[1]) / s; - ts[i + 16] = s && (e.left - t[0]) / -s; - ts[i + 20] = c && (e.top - t[1]) / c; - ts[i + 24] = s && (e.right - t[0]) / -s; - ts[i + 28] = c && (e.bottom - t[1]) / c; - ts[i + 32] = c && (e.left - t[0]) / -c; - ts[i + 36] = s && (e.top - t[1]) / -s; - ts[i + 40] = c && (e.right - t[0]) / -c; - ts[i + 44] = s && (e.bottom - t[1]) / -s; - ts[i + 48] = s && (e.left - t[0]) / s; - ts[i + 52] = c && (e.top - t[1]) / -c; - ts[i + 56] = s && (e.right - t[0]) / s; - ts[i + 60] = c && (e.bottom - t[1]) / -c; - }); - var findPositiveMin = function (ts, offset, count) { - var result = 0; - for (var i = 0; i < count; i++) { - var t = ts[offset++]; - if (t > 0) { - result = result ? Math.min(t, result) : t; - } - } - return result; - }; - var boxScale = 1 + Math.min(Math.abs(c), Math.abs(s)); - divProperties.paddingLeft = findPositiveMin(ts, 32, 16) / boxScale; - divProperties.paddingTop = findPositiveMin(ts, 48, 16) / boxScale; - divProperties.paddingRight = findPositiveMin(ts, 0, 16) / boxScale; - divProperties.paddingBottom = findPositiveMin(ts, 16, 16) / boxScale; - task._textDivProperties.set(div, divProperties); + function WritableStreamDefaultControllerErrorIfNeeded(controller, error) { + if (controller._controlledWritableStream._state === 'writable') { + WritableStreamDefaultControllerError(controller, error); } } - function expandBounds(width, height, boxes) { - var bounds = boxes.map(function (box, i) { - return { - x1: box.left, - y1: box.top, - x2: box.right, - y2: box.bottom, - index: i, - x1New: undefined, - x2New: undefined - }; - }); - expandBoundsLTR(width, bounds); - var expanded = new Array(boxes.length); - bounds.forEach(function (b) { - var i = b.index; - expanded[i] = { - left: b.x1New, - top: 0, - right: b.x2New, - bottom: 0 - }; + function WritableStreamDefaultControllerProcessClose(controller) { + var stream = controller._controlledWritableStream; + WritableStreamMarkCloseRequestInFlight(stream); + DequeueValue(controller); + assert(controller._queue.length === 0, 'queue must be empty once the final write record is dequeued'); + var sinkClosePromise = PromiseInvokeOrNoop(controller._underlyingSink, 'close', []); + sinkClosePromise.then(function () { + WritableStreamFinishInFlightClose(stream); + }, function (reason) { + WritableStreamFinishInFlightCloseWithError(stream, reason); + }).catch(rethrowAssertionErrorRejection); + } + function WritableStreamDefaultControllerProcessWrite(controller, chunk) { + var stream = controller._controlledWritableStream; + WritableStreamMarkFirstWriteRequestInFlight(stream); + var sinkWritePromise = PromiseInvokeOrNoop(controller._underlyingSink, 'write', [chunk, controller]); + sinkWritePromise.then(function () { + WritableStreamFinishInFlightWrite(stream); + var state = stream._state; + assert(state === 'writable' || state === 'erroring'); + DequeueValue(controller); + if (WritableStreamCloseQueuedOrInFlight(stream) === false && state === 'writable') { + var backpressure = WritableStreamDefaultControllerGetBackpressure(controller); + WritableStreamUpdateBackpressure(stream, backpressure); + } + WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller); + }, function (reason) { + WritableStreamFinishInFlightWriteWithError(stream, reason); + }).catch(rethrowAssertionErrorRejection); + } + function WritableStreamDefaultControllerGetBackpressure(controller) { + var desiredSize = WritableStreamDefaultControllerGetDesiredSize(controller); + return desiredSize <= 0; + } + function WritableStreamDefaultControllerError(controller, error) { + var stream = controller._controlledWritableStream; + assert(stream._state === 'writable'); + WritableStreamStartErroring(stream, error); + } + function streamBrandCheckException(name) { + return new TypeError('WritableStream.prototype.' + name + ' can only be used on a WritableStream'); + } + function defaultWriterBrandCheckException(name) { + return new TypeError('WritableStreamDefaultWriter.prototype.' + name + ' can only be used on a WritableStreamDefaultWriter'); + } + function defaultWriterLockException(name) { + return new TypeError('Cannot ' + name + ' a stream using a released writer'); + } + function defaultWriterClosedPromiseInitialize(writer) { + writer._closedPromise = new Promise(function (resolve, reject) { + writer._closedPromise_resolve = resolve; + writer._closedPromise_reject = reject; + writer._closedPromiseState = 'pending'; }); - boxes.map(function (box, i) { - var e = expanded[i], - b = bounds[i]; - b.x1 = box.top; - b.y1 = width - e.right; - b.x2 = box.bottom; - b.y2 = width - e.left; - b.index = i; - b.x1New = undefined; - b.x2New = undefined; + } + function defaultWriterClosedPromiseInitializeAsRejected(writer, reason) { + writer._closedPromise = Promise.reject(reason); + writer._closedPromise_resolve = undefined; + writer._closedPromise_reject = undefined; + writer._closedPromiseState = 'rejected'; + } + function defaultWriterClosedPromiseInitializeAsResolved(writer) { + writer._closedPromise = Promise.resolve(undefined); + writer._closedPromise_resolve = undefined; + writer._closedPromise_reject = undefined; + writer._closedPromiseState = 'resolved'; + } + function defaultWriterClosedPromiseReject(writer, reason) { + assert(writer._closedPromise_resolve !== undefined, 'writer._closedPromise_resolve !== undefined'); + assert(writer._closedPromise_reject !== undefined, 'writer._closedPromise_reject !== undefined'); + assert(writer._closedPromiseState === 'pending', 'writer._closedPromiseState is pending'); + writer._closedPromise_reject(reason); + writer._closedPromise_resolve = undefined; + writer._closedPromise_reject = undefined; + writer._closedPromiseState = 'rejected'; + } + function defaultWriterClosedPromiseResetToRejected(writer, reason) { + assert(writer._closedPromise_resolve === undefined, 'writer._closedPromise_resolve === undefined'); + assert(writer._closedPromise_reject === undefined, 'writer._closedPromise_reject === undefined'); + assert(writer._closedPromiseState !== 'pending', 'writer._closedPromiseState is not pending'); + writer._closedPromise = Promise.reject(reason); + writer._closedPromiseState = 'rejected'; + } + function defaultWriterClosedPromiseResolve(writer) { + assert(writer._closedPromise_resolve !== undefined, 'writer._closedPromise_resolve !== undefined'); + assert(writer._closedPromise_reject !== undefined, 'writer._closedPromise_reject !== undefined'); + assert(writer._closedPromiseState === 'pending', 'writer._closedPromiseState is pending'); + writer._closedPromise_resolve(undefined); + writer._closedPromise_resolve = undefined; + writer._closedPromise_reject = undefined; + writer._closedPromiseState = 'resolved'; + } + function defaultWriterReadyPromiseInitialize(writer) { + writer._readyPromise = new Promise(function (resolve, reject) { + writer._readyPromise_resolve = resolve; + writer._readyPromise_reject = reject; }); - expandBoundsLTR(height, bounds); - bounds.forEach(function (b) { - var i = b.index; - expanded[i].top = b.x1New; - expanded[i].bottom = b.x2New; + writer._readyPromiseState = 'pending'; + } + function defaultWriterReadyPromiseInitializeAsRejected(writer, reason) { + writer._readyPromise = Promise.reject(reason); + writer._readyPromise_resolve = undefined; + writer._readyPromise_reject = undefined; + writer._readyPromiseState = 'rejected'; + } + function defaultWriterReadyPromiseInitializeAsResolved(writer) { + writer._readyPromise = Promise.resolve(undefined); + writer._readyPromise_resolve = undefined; + writer._readyPromise_reject = undefined; + writer._readyPromiseState = 'fulfilled'; + } + function defaultWriterReadyPromiseReject(writer, reason) { + assert(writer._readyPromise_resolve !== undefined, 'writer._readyPromise_resolve !== undefined'); + assert(writer._readyPromise_reject !== undefined, 'writer._readyPromise_reject !== undefined'); + writer._readyPromise_reject(reason); + writer._readyPromise_resolve = undefined; + writer._readyPromise_reject = undefined; + writer._readyPromiseState = 'rejected'; + } + function defaultWriterReadyPromiseReset(writer) { + assert(writer._readyPromise_resolve === undefined, 'writer._readyPromise_resolve === undefined'); + assert(writer._readyPromise_reject === undefined, 'writer._readyPromise_reject === undefined'); + writer._readyPromise = new Promise(function (resolve, reject) { + writer._readyPromise_resolve = resolve; + writer._readyPromise_reject = reject; }); - return expanded; + writer._readyPromiseState = 'pending'; } - function expandBoundsLTR(width, bounds) { - bounds.sort(function (a, b) { - return a.x1 - b.x1 || a.index - b.index; + function defaultWriterReadyPromiseResetToRejected(writer, reason) { + assert(writer._readyPromise_resolve === undefined, 'writer._readyPromise_resolve === undefined'); + assert(writer._readyPromise_reject === undefined, 'writer._readyPromise_reject === undefined'); + writer._readyPromise = Promise.reject(reason); + writer._readyPromiseState = 'rejected'; + } + function defaultWriterReadyPromiseResolve(writer) { + assert(writer._readyPromise_resolve !== undefined, 'writer._readyPromise_resolve !== undefined'); + assert(writer._readyPromise_reject !== undefined, 'writer._readyPromise_reject !== undefined'); + writer._readyPromise_resolve(undefined); + writer._readyPromise_resolve = undefined; + writer._readyPromise_reject = undefined; + writer._readyPromiseState = 'fulfilled'; + } +}, function (module, exports, __w_pdfjs_require__) { + "use strict"; + + var _require = __w_pdfjs_require__(0), + IsFiniteNonNegativeNumber = _require.IsFiniteNonNegativeNumber; + var _require2 = __w_pdfjs_require__(1), + assert = _require2.assert; + exports.DequeueValue = function (container) { + assert('_queue' in container && '_queueTotalSize' in container, 'Spec-level failure: DequeueValue should only be used on containers with [[queue]] and [[queueTotalSize]].'); + assert(container._queue.length > 0, 'Spec-level failure: should never dequeue from an empty queue.'); + var pair = container._queue.shift(); + container._queueTotalSize -= pair.size; + if (container._queueTotalSize < 0) { + container._queueTotalSize = 0; + } + return pair.value; + }; + exports.EnqueueValueWithSize = function (container, value, size) { + assert('_queue' in container && '_queueTotalSize' in container, 'Spec-level failure: EnqueueValueWithSize should only be used on containers with [[queue]] and ' + '[[queueTotalSize]].'); + size = Number(size); + if (!IsFiniteNonNegativeNumber(size)) { + throw new RangeError('Size must be a finite, non-NaN, non-negative number.'); + } + container._queue.push({ + value: value, + size: size }); - var fakeBoundary = { - x1: -Infinity, - y1: -Infinity, - x2: 0, - y2: Infinity, - index: -1, - x1New: 0, - x2New: 0 - }; - var horizon = [{ - start: -Infinity, - end: Infinity, - boundary: fakeBoundary - }]; - bounds.forEach(function (boundary) { - var i = 0; - while (i < horizon.length && horizon[i].end <= boundary.y1) { - i++; - } - var j = horizon.length - 1; - while (j >= 0 && horizon[j].start >= boundary.y2) { - j--; + container._queueTotalSize += size; + }; + exports.PeekQueueValue = function (container) { + assert('_queue' in container && '_queueTotalSize' in container, 'Spec-level failure: PeekQueueValue should only be used on containers with [[queue]] and [[queueTotalSize]].'); + assert(container._queue.length > 0, 'Spec-level failure: should never peek at an empty queue.'); + var pair = container._queue[0]; + return pair.value; + }; + exports.ResetQueue = function (container) { + assert('_queue' in container && '_queueTotalSize' in container, 'Spec-level failure: ResetQueue should only be used on containers with [[queue]] and [[queueTotalSize]].'); + container._queue = []; + container._queueTotalSize = 0; + }; +}, function (module, exports, __w_pdfjs_require__) { + "use strict"; + + var _createClass = function () { + function defineProperties(target, props) { + for (var i = 0; i < props.length; i++) { + var descriptor = props[i]; + descriptor.enumerable = descriptor.enumerable || false; + descriptor.configurable = true; + if ("value" in descriptor) descriptor.writable = true; + Object.defineProperty(target, descriptor.key, descriptor); } - var horizonPart, affectedBoundary; - var q, - k, - maxXNew = -Infinity; - for (q = i; q <= j; q++) { - horizonPart = horizon[q]; - affectedBoundary = horizonPart.boundary; - var xNew; - if (affectedBoundary.x2 > boundary.x1) { - xNew = affectedBoundary.index > boundary.index ? affectedBoundary.x1New : boundary.x1; - } else if (affectedBoundary.x2New === undefined) { - xNew = (affectedBoundary.x2 + boundary.x1) / 2; - } else { - xNew = affectedBoundary.x2New; + } + return function (Constructor, protoProps, staticProps) { + if (protoProps) defineProperties(Constructor.prototype, protoProps); + if (staticProps) defineProperties(Constructor, staticProps); + return Constructor; + }; + }(); + function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } + } + var _require = __w_pdfjs_require__(0), + ArrayBufferCopy = _require.ArrayBufferCopy, + CreateIterResultObject = _require.CreateIterResultObject, + IsFiniteNonNegativeNumber = _require.IsFiniteNonNegativeNumber, + InvokeOrNoop = _require.InvokeOrNoop, + PromiseInvokeOrNoop = _require.PromiseInvokeOrNoop, + TransferArrayBuffer = _require.TransferArrayBuffer, + ValidateAndNormalizeQueuingStrategy = _require.ValidateAndNormalizeQueuingStrategy, + ValidateAndNormalizeHighWaterMark = _require.ValidateAndNormalizeHighWaterMark; + var _require2 = __w_pdfjs_require__(0), + createArrayFromList = _require2.createArrayFromList, + createDataProperty = _require2.createDataProperty, + typeIsObject = _require2.typeIsObject; + var _require3 = __w_pdfjs_require__(1), + assert = _require3.assert, + rethrowAssertionErrorRejection = _require3.rethrowAssertionErrorRejection; + var _require4 = __w_pdfjs_require__(3), + DequeueValue = _require4.DequeueValue, + EnqueueValueWithSize = _require4.EnqueueValueWithSize, + ResetQueue = _require4.ResetQueue; + var _require5 = __w_pdfjs_require__(2), + AcquireWritableStreamDefaultWriter = _require5.AcquireWritableStreamDefaultWriter, + IsWritableStream = _require5.IsWritableStream, + IsWritableStreamLocked = _require5.IsWritableStreamLocked, + WritableStreamAbort = _require5.WritableStreamAbort, + WritableStreamDefaultWriterCloseWithErrorPropagation = _require5.WritableStreamDefaultWriterCloseWithErrorPropagation, + WritableStreamDefaultWriterRelease = _require5.WritableStreamDefaultWriterRelease, + WritableStreamDefaultWriterWrite = _require5.WritableStreamDefaultWriterWrite, + WritableStreamCloseQueuedOrInFlight = _require5.WritableStreamCloseQueuedOrInFlight; + var ReadableStream = function () { + function ReadableStream() { + var underlyingSource = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + size = _ref.size, + highWaterMark = _ref.highWaterMark; + _classCallCheck(this, ReadableStream); + this._state = 'readable'; + this._reader = undefined; + this._storedError = undefined; + this._disturbed = false; + this._readableStreamController = undefined; + var type = underlyingSource.type; + var typeString = String(type); + if (typeString === 'bytes') { + if (highWaterMark === undefined) { + highWaterMark = 0; } - if (xNew > maxXNew) { - maxXNew = xNew; + this._readableStreamController = new ReadableByteStreamController(this, underlyingSource, highWaterMark); + } else if (type === undefined) { + if (highWaterMark === undefined) { + highWaterMark = 1; } + this._readableStreamController = new ReadableStreamDefaultController(this, underlyingSource, size, highWaterMark); + } else { + throw new RangeError('Invalid type is specified'); } - boundary.x1New = maxXNew; - for (q = i; q <= j; q++) { - horizonPart = horizon[q]; - affectedBoundary = horizonPart.boundary; - if (affectedBoundary.x2New === undefined) { - if (affectedBoundary.x2 > boundary.x1) { - if (affectedBoundary.index > boundary.index) { - affectedBoundary.x2New = affectedBoundary.x2; - } - } else { - affectedBoundary.x2New = maxXNew; - } - } else if (affectedBoundary.x2New > maxXNew) { - affectedBoundary.x2New = Math.max(maxXNew, affectedBoundary.x2); + } + _createClass(ReadableStream, [{ + key: 'cancel', + value: function cancel(reason) { + if (IsReadableStream(this) === false) { + return Promise.reject(streamBrandCheckException('cancel')); } - } - var changedHorizon = [], - lastBoundary = null; - for (q = i; q <= j; q++) { - horizonPart = horizon[q]; - affectedBoundary = horizonPart.boundary; - var useBoundary = affectedBoundary.x2 > boundary.x2 ? affectedBoundary : boundary; - if (lastBoundary === useBoundary) { - changedHorizon[changedHorizon.length - 1].end = horizonPart.end; - } else { - changedHorizon.push({ - start: horizonPart.start, - end: horizonPart.end, - boundary: useBoundary - }); - lastBoundary = useBoundary; + if (IsReadableStreamLocked(this) === true) { + return Promise.reject(new TypeError('Cannot cancel a stream that already has a reader')); } - } - if (horizon[i].start < boundary.y1) { - changedHorizon[0].start = boundary.y1; - changedHorizon.unshift({ - start: horizon[i].start, - end: boundary.y1, - boundary: horizon[i].boundary - }); - } - if (boundary.y2 < horizon[j].end) { - changedHorizon[changedHorizon.length - 1].end = boundary.y2; - changedHorizon.push({ - start: boundary.y2, - end: horizon[j].end, - boundary: horizon[j].boundary - }); - } - for (q = i; q <= j; q++) { - horizonPart = horizon[q]; - affectedBoundary = horizonPart.boundary; - if (affectedBoundary.x2New !== undefined) { - continue; + return ReadableStreamCancel(this, reason); + } + }, { + key: 'getReader', + value: function getReader() { + var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, + mode = _ref2.mode; + if (IsReadableStream(this) === false) { + throw streamBrandCheckException('getReader'); } - var used = false; - for (k = i - 1; !used && k >= 0 && horizon[k].start >= affectedBoundary.y1; k--) { - used = horizon[k].boundary === affectedBoundary; + if (mode === undefined) { + return AcquireReadableStreamDefaultReader(this); } - for (k = j + 1; !used && k < horizon.length && horizon[k].end <= affectedBoundary.y2; k++) { - used = horizon[k].boundary === affectedBoundary; + mode = String(mode); + if (mode === 'byob') { + return AcquireReadableStreamBYOBReader(this); } - for (k = 0; !used && k < changedHorizon.length; k++) { - used = changedHorizon[k].boundary === affectedBoundary; + throw new RangeError('Invalid mode is specified'); + } + }, { + key: 'pipeThrough', + value: function pipeThrough(_ref3, options) { + var writable = _ref3.writable, + readable = _ref3.readable; + var promise = this.pipeTo(writable, options); + ifIsObjectAndHasAPromiseIsHandledInternalSlotSetPromiseIsHandledToTrue(promise); + return readable; + } + }, { + key: 'pipeTo', + value: function pipeTo(dest) { + var _this = this; + var _ref4 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + preventClose = _ref4.preventClose, + preventAbort = _ref4.preventAbort, + preventCancel = _ref4.preventCancel; + if (IsReadableStream(this) === false) { + return Promise.reject(streamBrandCheckException('pipeTo')); } - if (!used) { - affectedBoundary.x2New = maxXNew; + if (IsWritableStream(dest) === false) { + return Promise.reject(new TypeError('ReadableStream.prototype.pipeTo\'s first argument must be a WritableStream')); } - } - Array.prototype.splice.apply(horizon, [i, j - i + 1].concat(changedHorizon)); - }); - horizon.forEach(function (horizonPart) { - var affectedBoundary = horizonPart.boundary; - if (affectedBoundary.x2New === undefined) { - affectedBoundary.x2New = Math.max(width, affectedBoundary.x2); - } - }); - } - function TextLayerRenderTask(textContent, container, viewport, textDivs, enhanceTextSelection) { - this._textContent = textContent; - this._container = container; - this._viewport = viewport; - this._textDivs = textDivs || []; - this._textDivProperties = new WeakMap(); - this._renderingDone = false; - this._canceled = false; - this._capability = createPromiseCapability(); - this._renderTimer = null; - this._bounds = []; - this._enhanceTextSelection = !!enhanceTextSelection; - } - TextLayerRenderTask.prototype = { - get promise() { - return this._capability.promise; - }, - cancel: function TextLayer_cancel() { - this._canceled = true; - if (this._renderTimer !== null) { - clearTimeout(this._renderTimer); - this._renderTimer = null; - } - this._capability.reject('canceled'); - }, - _render: function TextLayer_render(timeout) { - var textItems = this._textContent.items; - var textStyles = this._textContent.styles; - for (var i = 0, len = textItems.length; i < len; i++) { - appendText(this, textItems[i], textStyles); - } - if (!timeout) { - render(this); - } else { - var self = this; - this._renderTimer = setTimeout(function () { - render(self); - self._renderTimer = null; - }, timeout); - } - }, - expandTextDivs: function TextLayer_expandTextDivs(expandDivs) { - if (!this._enhanceTextSelection || !this._renderingDone) { - return; - } - if (this._bounds !== null) { - expand(this); - this._bounds = null; - } - for (var i = 0, ii = this._textDivs.length; i < ii; i++) { - var div = this._textDivs[i]; - var divProperties = this._textDivProperties.get(div); - if (divProperties.isWhitespace) { - continue; + preventClose = Boolean(preventClose); + preventAbort = Boolean(preventAbort); + preventCancel = Boolean(preventCancel); + if (IsReadableStreamLocked(this) === true) { + return Promise.reject(new TypeError('ReadableStream.prototype.pipeTo cannot be used on a locked ReadableStream')); } - if (expandDivs) { - var transform = '', - padding = ''; - if (divProperties.scale !== 1) { - transform = 'scaleX(' + divProperties.scale + ')'; + if (IsWritableStreamLocked(dest) === true) { + return Promise.reject(new TypeError('ReadableStream.prototype.pipeTo cannot be used on a locked WritableStream')); + } + var reader = AcquireReadableStreamDefaultReader(this); + var writer = AcquireWritableStreamDefaultWriter(dest); + var shuttingDown = false; + var currentWrite = Promise.resolve(); + return new Promise(function (resolve, reject) { + function pipeLoop() { + currentWrite = Promise.resolve(); + if (shuttingDown === true) { + return Promise.resolve(); + } + return writer._readyPromise.then(function () { + return ReadableStreamDefaultReaderRead(reader).then(function (_ref5) { + var value = _ref5.value, + done = _ref5.done; + if (done === true) { + return; + } + currentWrite = WritableStreamDefaultWriterWrite(writer, value).catch(function () {}); + }); + }).then(pipeLoop); } - if (divProperties.angle !== 0) { - transform = 'rotate(' + divProperties.angle + 'deg) ' + transform; + isOrBecomesErrored(_this, reader._closedPromise, function (storedError) { + if (preventAbort === false) { + shutdownWithAction(function () { + return WritableStreamAbort(dest, storedError); + }, true, storedError); + } else { + shutdown(true, storedError); + } + }); + isOrBecomesErrored(dest, writer._closedPromise, function (storedError) { + if (preventCancel === false) { + shutdownWithAction(function () { + return ReadableStreamCancel(_this, storedError); + }, true, storedError); + } else { + shutdown(true, storedError); + } + }); + isOrBecomesClosed(_this, reader._closedPromise, function () { + if (preventClose === false) { + shutdownWithAction(function () { + return WritableStreamDefaultWriterCloseWithErrorPropagation(writer); + }); + } else { + shutdown(); + } + }); + if (WritableStreamCloseQueuedOrInFlight(dest) === true || dest._state === 'closed') { + var destClosed = new TypeError('the destination writable stream closed before all data could be piped to it'); + if (preventCancel === false) { + shutdownWithAction(function () { + return ReadableStreamCancel(_this, destClosed); + }, true, destClosed); + } else { + shutdown(true, destClosed); + } } - if (divProperties.paddingLeft !== 0) { - padding += ' padding-left: ' + divProperties.paddingLeft / divProperties.scale + 'px;'; - transform += ' translateX(' + -divProperties.paddingLeft / divProperties.scale + 'px)'; + pipeLoop().catch(function (err) { + currentWrite = Promise.resolve(); + rethrowAssertionErrorRejection(err); + }); + function waitForWritesToFinish() { + var oldCurrentWrite = currentWrite; + return currentWrite.then(function () { + return oldCurrentWrite !== currentWrite ? waitForWritesToFinish() : undefined; + }); } - if (divProperties.paddingTop !== 0) { - padding += ' padding-top: ' + divProperties.paddingTop + 'px;'; - transform += ' translateY(' + -divProperties.paddingTop + 'px)'; + function isOrBecomesErrored(stream, promise, action) { + if (stream._state === 'errored') { + action(stream._storedError); + } else { + promise.catch(action).catch(rethrowAssertionErrorRejection); + } } - if (divProperties.paddingRight !== 0) { - padding += ' padding-right: ' + divProperties.paddingRight / divProperties.scale + 'px;'; + function isOrBecomesClosed(stream, promise, action) { + if (stream._state === 'closed') { + action(); + } else { + promise.then(action).catch(rethrowAssertionErrorRejection); + } } - if (divProperties.paddingBottom !== 0) { - padding += ' padding-bottom: ' + divProperties.paddingBottom + 'px;'; + function shutdownWithAction(action, originalIsError, originalError) { + if (shuttingDown === true) { + return; + } + shuttingDown = true; + if (dest._state === 'writable' && WritableStreamCloseQueuedOrInFlight(dest) === false) { + waitForWritesToFinish().then(doTheRest); + } else { + doTheRest(); + } + function doTheRest() { + action().then(function () { + return finalize(originalIsError, originalError); + }, function (newError) { + return finalize(true, newError); + }).catch(rethrowAssertionErrorRejection); + } } - if (padding !== '') { - div.setAttribute('style', divProperties.style + padding); + function shutdown(isError, error) { + if (shuttingDown === true) { + return; + } + shuttingDown = true; + if (dest._state === 'writable' && WritableStreamCloseQueuedOrInFlight(dest) === false) { + waitForWritesToFinish().then(function () { + return finalize(isError, error); + }).catch(rethrowAssertionErrorRejection); + } else { + finalize(isError, error); + } } - if (transform !== '') { - CustomStyle.setProp('transform', div, transform); + function finalize(isError, error) { + WritableStreamDefaultWriterRelease(writer); + ReadableStreamReaderGenericRelease(reader); + if (isError) { + reject(error); + } else { + resolve(undefined); + } } - } else { - div.style.padding = 0; - CustomStyle.setProp('transform', div, divProperties.originalTransform || ''); - } + }); } - } + }, { + key: 'tee', + value: function tee() { + if (IsReadableStream(this) === false) { + throw streamBrandCheckException('tee'); + } + var branches = ReadableStreamTee(this, false); + return createArrayFromList(branches); + } + }, { + key: 'locked', + get: function get() { + if (IsReadableStream(this) === false) { + throw streamBrandCheckException('locked'); + } + return IsReadableStreamLocked(this); + } + }]); + return ReadableStream; + }(); + module.exports = { + ReadableStream: ReadableStream, + IsReadableStreamDisturbed: IsReadableStreamDisturbed, + ReadableStreamDefaultControllerClose: ReadableStreamDefaultControllerClose, + ReadableStreamDefaultControllerEnqueue: ReadableStreamDefaultControllerEnqueue, + ReadableStreamDefaultControllerError: ReadableStreamDefaultControllerError, + ReadableStreamDefaultControllerGetDesiredSize: ReadableStreamDefaultControllerGetDesiredSize }; - function renderTextLayer(renderParameters) { - var task = new TextLayerRenderTask(renderParameters.textContent, renderParameters.container, renderParameters.viewport, renderParameters.textDivs, renderParameters.enhanceTextSelection); - task._render(renderParameters.timeout); - return task; + function AcquireReadableStreamBYOBReader(stream) { + return new ReadableStreamBYOBReader(stream); } - return renderTextLayer; -}(); -exports.renderTextLayer = renderTextLayer; - -/***/ }), -/* 6 */ -/***/ (function(module, exports, __w_pdfjs_require__) { - -"use strict"; - - -var g; -g = function () { - return this; -}(); -try { - g = g || Function("return this")() || (1, eval)("this"); -} catch (e) { - if (typeof window === "object") g = window; -} -module.exports = g; - -/***/ }), -/* 7 */ -/***/ (function(module, exports, __w_pdfjs_require__) { - -"use strict"; - - -var sharedUtil = __w_pdfjs_require__(0); -var error = sharedUtil.error; -function fixMetadata(meta) { - return meta.replace(/>\\376\\377([^<]+)/g, function (all, codes) { - var bytes = codes.replace(/\\([0-3])([0-7])([0-7])/g, function (code, d1, d2, d3) { - return String.fromCharCode(d1 * 64 + d2 * 8 + d3 * 1); - }); - var chars = ''; - for (var i = 0; i < bytes.length; i += 2) { - var code = bytes.charCodeAt(i) * 256 + bytes.charCodeAt(i + 1); - chars += code >= 32 && code < 127 && code !== 60 && code !== 62 && code !== 38 ? String.fromCharCode(code) : '&#x' + (0x10000 + code).toString(16).substring(1) + ';'; + function AcquireReadableStreamDefaultReader(stream) { + return new ReadableStreamDefaultReader(stream); + } + function IsReadableStream(x) { + if (!typeIsObject(x)) { + return false; } - return '>' + chars; - }); -} -function Metadata(meta) { - if (typeof meta === 'string') { - meta = fixMetadata(meta); - var parser = new DOMParser(); - meta = parser.parseFromString(meta, 'application/xml'); - } else if (!(meta instanceof Document)) { - error('Metadata: Invalid metadata object'); - } - this.metaDocument = meta; - this.metadata = Object.create(null); - this.parse(); -} -Metadata.prototype = { - parse: function Metadata_parse() { - var doc = this.metaDocument; - var rdf = doc.documentElement; - if (rdf.nodeName.toLowerCase() !== 'rdf:rdf') { - rdf = rdf.firstChild; - while (rdf && rdf.nodeName.toLowerCase() !== 'rdf:rdf') { - rdf = rdf.nextSibling; - } - } - var nodeName = rdf ? rdf.nodeName.toLowerCase() : null; - if (!rdf || nodeName !== 'rdf:rdf' || !rdf.hasChildNodes()) { - return; + if (!Object.prototype.hasOwnProperty.call(x, '_readableStreamController')) { + return false; } - var children = rdf.childNodes, - desc, - entry, - name, - i, - ii, - length, - iLength; - for (i = 0, length = children.length; i < length; i++) { - desc = children[i]; - if (desc.nodeName.toLowerCase() !== 'rdf:description') { - continue; + return true; + } + function IsReadableStreamDisturbed(stream) { + assert(IsReadableStream(stream) === true, 'IsReadableStreamDisturbed should only be used on known readable streams'); + return stream._disturbed; + } + function IsReadableStreamLocked(stream) { + assert(IsReadableStream(stream) === true, 'IsReadableStreamLocked should only be used on known readable streams'); + if (stream._reader === undefined) { + return false; + } + return true; + } + function ReadableStreamTee(stream, cloneForBranch2) { + assert(IsReadableStream(stream) === true); + assert(typeof cloneForBranch2 === 'boolean'); + var reader = AcquireReadableStreamDefaultReader(stream); + var teeState = { + closedOrErrored: false, + canceled1: false, + canceled2: false, + reason1: undefined, + reason2: undefined + }; + teeState.promise = new Promise(function (resolve) { + teeState._resolve = resolve; + }); + var pull = create_ReadableStreamTeePullFunction(); + pull._reader = reader; + pull._teeState = teeState; + pull._cloneForBranch2 = cloneForBranch2; + var cancel1 = create_ReadableStreamTeeBranch1CancelFunction(); + cancel1._stream = stream; + cancel1._teeState = teeState; + var cancel2 = create_ReadableStreamTeeBranch2CancelFunction(); + cancel2._stream = stream; + cancel2._teeState = teeState; + var underlyingSource1 = Object.create(Object.prototype); + createDataProperty(underlyingSource1, 'pull', pull); + createDataProperty(underlyingSource1, 'cancel', cancel1); + var branch1Stream = new ReadableStream(underlyingSource1); + var underlyingSource2 = Object.create(Object.prototype); + createDataProperty(underlyingSource2, 'pull', pull); + createDataProperty(underlyingSource2, 'cancel', cancel2); + var branch2Stream = new ReadableStream(underlyingSource2); + pull._branch1 = branch1Stream._readableStreamController; + pull._branch2 = branch2Stream._readableStreamController; + reader._closedPromise.catch(function (r) { + if (teeState.closedOrErrored === true) { + return; } - for (ii = 0, iLength = desc.childNodes.length; ii < iLength; ii++) { - if (desc.childNodes[ii].nodeName.toLowerCase() !== '#text') { - entry = desc.childNodes[ii]; - name = entry.nodeName.toLowerCase(); - this.metadata[name] = entry.textContent.trim(); + ReadableStreamDefaultControllerError(pull._branch1, r); + ReadableStreamDefaultControllerError(pull._branch2, r); + teeState.closedOrErrored = true; + }); + return [branch1Stream, branch2Stream]; + } + function create_ReadableStreamTeePullFunction() { + function f() { + var reader = f._reader, + branch1 = f._branch1, + branch2 = f._branch2, + teeState = f._teeState; + return ReadableStreamDefaultReaderRead(reader).then(function (result) { + assert(typeIsObject(result)); + var value = result.value; + var done = result.done; + assert(typeof done === 'boolean'); + if (done === true && teeState.closedOrErrored === false) { + if (teeState.canceled1 === false) { + ReadableStreamDefaultControllerClose(branch1); + } + if (teeState.canceled2 === false) { + ReadableStreamDefaultControllerClose(branch2); + } + teeState.closedOrErrored = true; } - } + if (teeState.closedOrErrored === true) { + return; + } + var value1 = value; + var value2 = value; + if (teeState.canceled1 === false) { + ReadableStreamDefaultControllerEnqueue(branch1, value1); + } + if (teeState.canceled2 === false) { + ReadableStreamDefaultControllerEnqueue(branch2, value2); + } + }); } - }, - get: function Metadata_get(name) { - return this.metadata[name] || null; - }, - has: function Metadata_has(name) { - return typeof this.metadata[name] !== 'undefined'; + return f; } -}; -exports.Metadata = Metadata; - -/***/ }), -/* 8 */ -/***/ (function(module, exports, __w_pdfjs_require__) { - -"use strict"; - - -var sharedUtil = __w_pdfjs_require__(0); -var displayDOMUtils = __w_pdfjs_require__(1); -var shadow = sharedUtil.shadow; -var getDefaultSetting = displayDOMUtils.getDefaultSetting; -var WebGLUtils = function WebGLUtilsClosure() { - function loadShader(gl, code, shaderType) { - var shader = gl.createShader(shaderType); - gl.shaderSource(shader, code); - gl.compileShader(shader); - var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS); - if (!compiled) { - var errorMsg = gl.getShaderInfoLog(shader); - throw new Error('Error during shader compilation: ' + errorMsg); + function create_ReadableStreamTeeBranch1CancelFunction() { + function f(reason) { + var stream = f._stream, + teeState = f._teeState; + teeState.canceled1 = true; + teeState.reason1 = reason; + if (teeState.canceled2 === true) { + var compositeReason = createArrayFromList([teeState.reason1, teeState.reason2]); + var cancelResult = ReadableStreamCancel(stream, compositeReason); + teeState._resolve(cancelResult); + } + return teeState.promise; } - return shader; + return f; } - function createVertexShader(gl, code) { - return loadShader(gl, code, gl.VERTEX_SHADER); + function create_ReadableStreamTeeBranch2CancelFunction() { + function f(reason) { + var stream = f._stream, + teeState = f._teeState; + teeState.canceled2 = true; + teeState.reason2 = reason; + if (teeState.canceled1 === true) { + var compositeReason = createArrayFromList([teeState.reason1, teeState.reason2]); + var cancelResult = ReadableStreamCancel(stream, compositeReason); + teeState._resolve(cancelResult); + } + return teeState.promise; + } + return f; } - function createFragmentShader(gl, code) { - return loadShader(gl, code, gl.FRAGMENT_SHADER); + function ReadableStreamAddReadIntoRequest(stream) { + assert(IsReadableStreamBYOBReader(stream._reader) === true); + assert(stream._state === 'readable' || stream._state === 'closed'); + var promise = new Promise(function (resolve, reject) { + var readIntoRequest = { + _resolve: resolve, + _reject: reject + }; + stream._reader._readIntoRequests.push(readIntoRequest); + }); + return promise; } - function createProgram(gl, shaders) { - var program = gl.createProgram(); - for (var i = 0, ii = shaders.length; i < ii; ++i) { - gl.attachShader(program, shaders[i]); + function ReadableStreamAddReadRequest(stream) { + assert(IsReadableStreamDefaultReader(stream._reader) === true); + assert(stream._state === 'readable'); + var promise = new Promise(function (resolve, reject) { + var readRequest = { + _resolve: resolve, + _reject: reject + }; + stream._reader._readRequests.push(readRequest); + }); + return promise; + } + function ReadableStreamCancel(stream, reason) { + stream._disturbed = true; + if (stream._state === 'closed') { + return Promise.resolve(undefined); } - gl.linkProgram(program); - var linked = gl.getProgramParameter(program, gl.LINK_STATUS); - if (!linked) { - var errorMsg = gl.getProgramInfoLog(program); - throw new Error('Error during program linking: ' + errorMsg); + if (stream._state === 'errored') { + return Promise.reject(stream._storedError); } - return program; + ReadableStreamClose(stream); + var sourceCancelPromise = stream._readableStreamController.__cancelSteps(reason); + return sourceCancelPromise.then(function () { + return undefined; + }); } - function createTexture(gl, image, textureId) { - gl.activeTexture(textureId); - var texture = gl.createTexture(); - gl.bindTexture(gl.TEXTURE_2D, texture); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); - gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image); - return texture; + function ReadableStreamClose(stream) { + assert(stream._state === 'readable'); + stream._state = 'closed'; + var reader = stream._reader; + if (reader === undefined) { + return undefined; + } + if (IsReadableStreamDefaultReader(reader) === true) { + for (var i = 0; i < reader._readRequests.length; i++) { + var _resolve = reader._readRequests[i]._resolve; + _resolve(CreateIterResultObject(undefined, true)); + } + reader._readRequests = []; + } + defaultReaderClosedPromiseResolve(reader); + return undefined; } - var currentGL, currentCanvas; - function generateGL() { - if (currentGL) { - return; + function ReadableStreamError(stream, e) { + assert(IsReadableStream(stream) === true, 'stream must be ReadableStream'); + assert(stream._state === 'readable', 'state must be readable'); + stream._state = 'errored'; + stream._storedError = e; + var reader = stream._reader; + if (reader === undefined) { + return undefined; } - currentCanvas = document.createElement('canvas'); - currentGL = currentCanvas.getContext('webgl', { premultipliedalpha: false }); + if (IsReadableStreamDefaultReader(reader) === true) { + for (var i = 0; i < reader._readRequests.length; i++) { + var readRequest = reader._readRequests[i]; + readRequest._reject(e); + } + reader._readRequests = []; + } else { + assert(IsReadableStreamBYOBReader(reader), 'reader must be ReadableStreamBYOBReader'); + for (var _i = 0; _i < reader._readIntoRequests.length; _i++) { + var readIntoRequest = reader._readIntoRequests[_i]; + readIntoRequest._reject(e); + } + reader._readIntoRequests = []; + } + defaultReaderClosedPromiseReject(reader, e); + reader._closedPromise.catch(function () {}); } - var smaskVertexShaderCode = '\ - attribute vec2 a_position; \ - attribute vec2 a_texCoord; \ - \ - uniform vec2 u_resolution; \ - \ - varying vec2 v_texCoord; \ - \ - void main() { \ - vec2 clipSpace = (a_position / u_resolution) * 2.0 - 1.0; \ - gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \ - \ - v_texCoord = a_texCoord; \ - } '; - var smaskFragmentShaderCode = '\ - precision mediump float; \ - \ - uniform vec4 u_backdrop; \ - uniform int u_subtype; \ - uniform sampler2D u_image; \ - uniform sampler2D u_mask; \ - \ - varying vec2 v_texCoord; \ - \ - void main() { \ - vec4 imageColor = texture2D(u_image, v_texCoord); \ - vec4 maskColor = texture2D(u_mask, v_texCoord); \ - if (u_backdrop.a > 0.0) { \ - maskColor.rgb = maskColor.rgb * maskColor.a + \ - u_backdrop.rgb * (1.0 - maskColor.a); \ - } \ - float lum; \ - if (u_subtype == 0) { \ - lum = maskColor.a; \ - } else { \ - lum = maskColor.r * 0.3 + maskColor.g * 0.59 + \ - maskColor.b * 0.11; \ - } \ - imageColor.a *= lum; \ - imageColor.rgb *= imageColor.a; \ - gl_FragColor = imageColor; \ - } '; - var smaskCache = null; - function initSmaskGL() { - var canvas, gl; - generateGL(); - canvas = currentCanvas; - currentCanvas = null; - gl = currentGL; - currentGL = null; - var vertexShader = createVertexShader(gl, smaskVertexShaderCode); - var fragmentShader = createFragmentShader(gl, smaskFragmentShaderCode); - var program = createProgram(gl, [vertexShader, fragmentShader]); - gl.useProgram(program); - var cache = {}; - cache.gl = gl; - cache.canvas = canvas; - cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution'); - cache.positionLocation = gl.getAttribLocation(program, 'a_position'); - cache.backdropLocation = gl.getUniformLocation(program, 'u_backdrop'); - cache.subtypeLocation = gl.getUniformLocation(program, 'u_subtype'); - var texCoordLocation = gl.getAttribLocation(program, 'a_texCoord'); - var texLayerLocation = gl.getUniformLocation(program, 'u_image'); - var texMaskLocation = gl.getUniformLocation(program, 'u_mask'); - var texCoordBuffer = gl.createBuffer(); - gl.bindBuffer(gl.ARRAY_BUFFER, texCoordBuffer); - gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0]), gl.STATIC_DRAW); - gl.enableVertexAttribArray(texCoordLocation); - gl.vertexAttribPointer(texCoordLocation, 2, gl.FLOAT, false, 0, 0); - gl.uniform1i(texLayerLocation, 0); - gl.uniform1i(texMaskLocation, 1); - smaskCache = cache; + function ReadableStreamFulfillReadIntoRequest(stream, chunk, done) { + var reader = stream._reader; + assert(reader._readIntoRequests.length > 0); + var readIntoRequest = reader._readIntoRequests.shift(); + readIntoRequest._resolve(CreateIterResultObject(chunk, done)); } - function composeSMask(layer, mask, properties) { - var width = layer.width, - height = layer.height; - if (!smaskCache) { - initSmaskGL(); - } - var cache = smaskCache, - canvas = cache.canvas, - gl = cache.gl; - canvas.width = width; - canvas.height = height; - gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight); - gl.uniform2f(cache.resolutionLocation, width, height); - if (properties.backdrop) { - gl.uniform4f(cache.resolutionLocation, properties.backdrop[0], properties.backdrop[1], properties.backdrop[2], 1); - } else { - gl.uniform4f(cache.resolutionLocation, 0, 0, 0, 0); - } - gl.uniform1i(cache.subtypeLocation, properties.subtype === 'Luminosity' ? 1 : 0); - var texture = createTexture(gl, layer, gl.TEXTURE0); - var maskTexture = createTexture(gl, mask, gl.TEXTURE1); - var buffer = gl.createBuffer(); - gl.bindBuffer(gl.ARRAY_BUFFER, buffer); - gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([0, 0, width, 0, 0, height, 0, height, width, 0, width, height]), gl.STATIC_DRAW); - gl.enableVertexAttribArray(cache.positionLocation); - gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0); - gl.clearColor(0, 0, 0, 0); - gl.enable(gl.BLEND); - gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA); - gl.clear(gl.COLOR_BUFFER_BIT); - gl.drawArrays(gl.TRIANGLES, 0, 6); - gl.flush(); - gl.deleteTexture(texture); - gl.deleteTexture(maskTexture); - gl.deleteBuffer(buffer); - return canvas; + function ReadableStreamFulfillReadRequest(stream, chunk, done) { + var reader = stream._reader; + assert(reader._readRequests.length > 0); + var readRequest = reader._readRequests.shift(); + readRequest._resolve(CreateIterResultObject(chunk, done)); } - var figuresVertexShaderCode = '\ - attribute vec2 a_position; \ - attribute vec3 a_color; \ - \ - uniform vec2 u_resolution; \ - uniform vec2 u_scale; \ - uniform vec2 u_offset; \ - \ - varying vec4 v_color; \ - \ - void main() { \ - vec2 position = (a_position + u_offset) * u_scale; \ - vec2 clipSpace = (position / u_resolution) * 2.0 - 1.0; \ - gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \ - \ - v_color = vec4(a_color / 255.0, 1.0); \ - } '; - var figuresFragmentShaderCode = '\ - precision mediump float; \ - \ - varying vec4 v_color; \ - \ - void main() { \ - gl_FragColor = v_color; \ - } '; - var figuresCache = null; - function initFiguresGL() { - var canvas, gl; - generateGL(); - canvas = currentCanvas; - currentCanvas = null; - gl = currentGL; - currentGL = null; - var vertexShader = createVertexShader(gl, figuresVertexShaderCode); - var fragmentShader = createFragmentShader(gl, figuresFragmentShaderCode); - var program = createProgram(gl, [vertexShader, fragmentShader]); - gl.useProgram(program); - var cache = {}; - cache.gl = gl; - cache.canvas = canvas; - cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution'); - cache.scaleLocation = gl.getUniformLocation(program, 'u_scale'); - cache.offsetLocation = gl.getUniformLocation(program, 'u_offset'); - cache.positionLocation = gl.getAttribLocation(program, 'a_position'); - cache.colorLocation = gl.getAttribLocation(program, 'a_color'); - figuresCache = cache; + function ReadableStreamGetNumReadIntoRequests(stream) { + return stream._reader._readIntoRequests.length; } - function drawFigures(width, height, backgroundColor, figures, context) { - if (!figuresCache) { - initFiguresGL(); - } - var cache = figuresCache, - canvas = cache.canvas, - gl = cache.gl; - canvas.width = width; - canvas.height = height; - gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight); - gl.uniform2f(cache.resolutionLocation, width, height); - var count = 0; - var i, ii, rows; - for (i = 0, ii = figures.length; i < ii; i++) { - switch (figures[i].type) { - case 'lattice': - rows = figures[i].coords.length / figures[i].verticesPerRow | 0; - count += (rows - 1) * (figures[i].verticesPerRow - 1) * 6; - break; - case 'triangles': - count += figures[i].coords.length; - break; - } - } - var coords = new Float32Array(count * 2); - var colors = new Uint8Array(count * 3); - var coordsMap = context.coords, - colorsMap = context.colors; - var pIndex = 0, - cIndex = 0; - for (i = 0, ii = figures.length; i < ii; i++) { - var figure = figures[i], - ps = figure.coords, - cs = figure.colors; - switch (figure.type) { - case 'lattice': - var cols = figure.verticesPerRow; - rows = ps.length / cols | 0; - for (var row = 1; row < rows; row++) { - var offset = row * cols + 1; - for (var col = 1; col < cols; col++, offset++) { - coords[pIndex] = coordsMap[ps[offset - cols - 1]]; - coords[pIndex + 1] = coordsMap[ps[offset - cols - 1] + 1]; - coords[pIndex + 2] = coordsMap[ps[offset - cols]]; - coords[pIndex + 3] = coordsMap[ps[offset - cols] + 1]; - coords[pIndex + 4] = coordsMap[ps[offset - 1]]; - coords[pIndex + 5] = coordsMap[ps[offset - 1] + 1]; - colors[cIndex] = colorsMap[cs[offset - cols - 1]]; - colors[cIndex + 1] = colorsMap[cs[offset - cols - 1] + 1]; - colors[cIndex + 2] = colorsMap[cs[offset - cols - 1] + 2]; - colors[cIndex + 3] = colorsMap[cs[offset - cols]]; - colors[cIndex + 4] = colorsMap[cs[offset - cols] + 1]; - colors[cIndex + 5] = colorsMap[cs[offset - cols] + 2]; - colors[cIndex + 6] = colorsMap[cs[offset - 1]]; - colors[cIndex + 7] = colorsMap[cs[offset - 1] + 1]; - colors[cIndex + 8] = colorsMap[cs[offset - 1] + 2]; - coords[pIndex + 6] = coords[pIndex + 2]; - coords[pIndex + 7] = coords[pIndex + 3]; - coords[pIndex + 8] = coords[pIndex + 4]; - coords[pIndex + 9] = coords[pIndex + 5]; - coords[pIndex + 10] = coordsMap[ps[offset]]; - coords[pIndex + 11] = coordsMap[ps[offset] + 1]; - colors[cIndex + 9] = colors[cIndex + 3]; - colors[cIndex + 10] = colors[cIndex + 4]; - colors[cIndex + 11] = colors[cIndex + 5]; - colors[cIndex + 12] = colors[cIndex + 6]; - colors[cIndex + 13] = colors[cIndex + 7]; - colors[cIndex + 14] = colors[cIndex + 8]; - colors[cIndex + 15] = colorsMap[cs[offset]]; - colors[cIndex + 16] = colorsMap[cs[offset] + 1]; - colors[cIndex + 17] = colorsMap[cs[offset] + 2]; - pIndex += 12; - cIndex += 18; - } - } - break; - case 'triangles': - for (var j = 0, jj = ps.length; j < jj; j++) { - coords[pIndex] = coordsMap[ps[j]]; - coords[pIndex + 1] = coordsMap[ps[j] + 1]; - colors[cIndex] = colorsMap[cs[j]]; - colors[cIndex + 1] = colorsMap[cs[j] + 1]; - colors[cIndex + 2] = colorsMap[cs[j] + 2]; - pIndex += 2; - cIndex += 3; - } - break; - } + function ReadableStreamGetNumReadRequests(stream) { + return stream._reader._readRequests.length; + } + function ReadableStreamHasBYOBReader(stream) { + var reader = stream._reader; + if (reader === undefined) { + return false; } - if (backgroundColor) { - gl.clearColor(backgroundColor[0] / 255, backgroundColor[1] / 255, backgroundColor[2] / 255, 1.0); - } else { - gl.clearColor(0, 0, 0, 0); + if (IsReadableStreamBYOBReader(reader) === false) { + return false; } - gl.clear(gl.COLOR_BUFFER_BIT); - var coordsBuffer = gl.createBuffer(); - gl.bindBuffer(gl.ARRAY_BUFFER, coordsBuffer); - gl.bufferData(gl.ARRAY_BUFFER, coords, gl.STATIC_DRAW); - gl.enableVertexAttribArray(cache.positionLocation); - gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0); - var colorsBuffer = gl.createBuffer(); - gl.bindBuffer(gl.ARRAY_BUFFER, colorsBuffer); - gl.bufferData(gl.ARRAY_BUFFER, colors, gl.STATIC_DRAW); - gl.enableVertexAttribArray(cache.colorLocation); - gl.vertexAttribPointer(cache.colorLocation, 3, gl.UNSIGNED_BYTE, false, 0, 0); - gl.uniform2f(cache.scaleLocation, context.scaleX, context.scaleY); - gl.uniform2f(cache.offsetLocation, context.offsetX, context.offsetY); - gl.drawArrays(gl.TRIANGLES, 0, count); - gl.flush(); - gl.deleteBuffer(coordsBuffer); - gl.deleteBuffer(colorsBuffer); - return canvas; + return true; } - function cleanup() { - if (smaskCache && smaskCache.canvas) { - smaskCache.canvas.width = 0; - smaskCache.canvas.height = 0; + function ReadableStreamHasDefaultReader(stream) { + var reader = stream._reader; + if (reader === undefined) { + return false; } - if (figuresCache && figuresCache.canvas) { - figuresCache.canvas.width = 0; - figuresCache.canvas.height = 0; + if (IsReadableStreamDefaultReader(reader) === false) { + return false; } - smaskCache = null; - figuresCache = null; + return true; } - return { - get isEnabled() { - if (getDefaultSetting('disableWebGL')) { - return false; + var ReadableStreamDefaultReader = function () { + function ReadableStreamDefaultReader(stream) { + _classCallCheck(this, ReadableStreamDefaultReader); + if (IsReadableStream(stream) === false) { + throw new TypeError('ReadableStreamDefaultReader can only be constructed with a ReadableStream instance'); } - var enabled = false; - try { - generateGL(); - enabled = !!currentGL; - } catch (e) {} - return shadow(this, 'isEnabled', enabled); - }, - composeSMask: composeSMask, - drawFigures: drawFigures, - clear: cleanup - }; -}(); -exports.WebGLUtils = WebGLUtils; - -/***/ }), -/* 9 */ -/***/ (function(module, exports, __w_pdfjs_require__) { - -"use strict"; - - -var sharedUtil = __w_pdfjs_require__(0); -var displayDOMUtils = __w_pdfjs_require__(1); -var displayAPI = __w_pdfjs_require__(3); -var displayAnnotationLayer = __w_pdfjs_require__(2); -var displayTextLayer = __w_pdfjs_require__(5); -var displayMetadata = __w_pdfjs_require__(7); -var displaySVG = __w_pdfjs_require__(4); -var globalScope = sharedUtil.globalScope; -var deprecated = sharedUtil.deprecated; -var warn = sharedUtil.warn; -var LinkTarget = displayDOMUtils.LinkTarget; -var DEFAULT_LINK_REL = displayDOMUtils.DEFAULT_LINK_REL; -var isWorker = typeof window === 'undefined'; -if (!globalScope.PDFJS) { - globalScope.PDFJS = {}; -} -var PDFJS = globalScope.PDFJS; -PDFJS.version = '1.8.172'; -PDFJS.build = '8ff1fbe7'; -PDFJS.pdfBug = false; -if (PDFJS.verbosity !== undefined) { - sharedUtil.setVerbosityLevel(PDFJS.verbosity); -} -delete PDFJS.verbosity; -Object.defineProperty(PDFJS, 'verbosity', { - get: function () { - return sharedUtil.getVerbosityLevel(); - }, - set: function (level) { - sharedUtil.setVerbosityLevel(level); - }, - enumerable: true, - configurable: true -}); -PDFJS.VERBOSITY_LEVELS = sharedUtil.VERBOSITY_LEVELS; -PDFJS.OPS = sharedUtil.OPS; -PDFJS.UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES; -PDFJS.isValidUrl = displayDOMUtils.isValidUrl; -PDFJS.shadow = sharedUtil.shadow; -PDFJS.createBlob = sharedUtil.createBlob; -PDFJS.createObjectURL = function PDFJS_createObjectURL(data, contentType) { - return sharedUtil.createObjectURL(data, contentType, PDFJS.disableCreateObjectURL); -}; -Object.defineProperty(PDFJS, 'isLittleEndian', { - configurable: true, - get: function PDFJS_isLittleEndian() { - var value = sharedUtil.isLittleEndian(); - return sharedUtil.shadow(PDFJS, 'isLittleEndian', value); - } -}); -PDFJS.removeNullCharacters = sharedUtil.removeNullCharacters; -PDFJS.PasswordResponses = sharedUtil.PasswordResponses; -PDFJS.PasswordException = sharedUtil.PasswordException; -PDFJS.UnknownErrorException = sharedUtil.UnknownErrorException; -PDFJS.InvalidPDFException = sharedUtil.InvalidPDFException; -PDFJS.MissingPDFException = sharedUtil.MissingPDFException; -PDFJS.UnexpectedResponseException = sharedUtil.UnexpectedResponseException; -PDFJS.Util = sharedUtil.Util; -PDFJS.PageViewport = sharedUtil.PageViewport; -PDFJS.createPromiseCapability = sharedUtil.createPromiseCapability; -PDFJS.maxImageSize = PDFJS.maxImageSize === undefined ? -1 : PDFJS.maxImageSize; -PDFJS.cMapUrl = PDFJS.cMapUrl === undefined ? null : PDFJS.cMapUrl; -PDFJS.cMapPacked = PDFJS.cMapPacked === undefined ? false : PDFJS.cMapPacked; -PDFJS.disableFontFace = PDFJS.disableFontFace === undefined ? false : PDFJS.disableFontFace; -PDFJS.imageResourcesPath = PDFJS.imageResourcesPath === undefined ? '' : PDFJS.imageResourcesPath; -PDFJS.disableWorker = PDFJS.disableWorker === undefined ? false : PDFJS.disableWorker; -PDFJS.workerSrc = PDFJS.workerSrc === undefined ? null : PDFJS.workerSrc; -PDFJS.workerPort = PDFJS.workerPort === undefined ? null : PDFJS.workerPort; -PDFJS.disableRange = PDFJS.disableRange === undefined ? false : PDFJS.disableRange; -PDFJS.disableStream = PDFJS.disableStream === undefined ? false : PDFJS.disableStream; -PDFJS.disableAutoFetch = PDFJS.disableAutoFetch === undefined ? false : PDFJS.disableAutoFetch; -PDFJS.pdfBug = PDFJS.pdfBug === undefined ? false : PDFJS.pdfBug; -PDFJS.postMessageTransfers = PDFJS.postMessageTransfers === undefined ? true : PDFJS.postMessageTransfers; -PDFJS.disableCreateObjectURL = PDFJS.disableCreateObjectURL === undefined ? false : PDFJS.disableCreateObjectURL; -PDFJS.disableWebGL = PDFJS.disableWebGL === undefined ? true : PDFJS.disableWebGL; -PDFJS.externalLinkTarget = PDFJS.externalLinkTarget === undefined ? LinkTarget.NONE : PDFJS.externalLinkTarget; -PDFJS.externalLinkRel = PDFJS.externalLinkRel === undefined ? DEFAULT_LINK_REL : PDFJS.externalLinkRel; -PDFJS.isEvalSupported = PDFJS.isEvalSupported === undefined ? true : PDFJS.isEvalSupported; -PDFJS.pdfjsNext = PDFJS.pdfjsNext === undefined ? false : PDFJS.pdfjsNext; -var savedOpenExternalLinksInNewWindow = PDFJS.openExternalLinksInNewWindow; -delete PDFJS.openExternalLinksInNewWindow; -Object.defineProperty(PDFJS, 'openExternalLinksInNewWindow', { - get: function () { - return PDFJS.externalLinkTarget === LinkTarget.BLANK; - }, - set: function (value) { - if (value) { - deprecated('PDFJS.openExternalLinksInNewWindow, please use ' + '"PDFJS.externalLinkTarget = PDFJS.LinkTarget.BLANK" instead.'); - } - if (PDFJS.externalLinkTarget !== LinkTarget.NONE) { - warn('PDFJS.externalLinkTarget is already initialized'); - return; + if (IsReadableStreamLocked(stream) === true) { + throw new TypeError('This stream has already been locked for exclusive reading by another reader'); + } + ReadableStreamReaderGenericInitialize(this, stream); + this._readRequests = []; } - PDFJS.externalLinkTarget = value ? LinkTarget.BLANK : LinkTarget.NONE; - }, - enumerable: true, - configurable: true -}); -if (savedOpenExternalLinksInNewWindow) { - PDFJS.openExternalLinksInNewWindow = savedOpenExternalLinksInNewWindow; -} -PDFJS.getDocument = displayAPI.getDocument; -PDFJS.PDFDataRangeTransport = displayAPI.PDFDataRangeTransport; -PDFJS.PDFWorker = displayAPI.PDFWorker; -Object.defineProperty(PDFJS, 'hasCanvasTypedArrays', { - configurable: true, - get: function PDFJS_hasCanvasTypedArrays() { - var value = displayDOMUtils.hasCanvasTypedArrays(); - return sharedUtil.shadow(PDFJS, 'hasCanvasTypedArrays', value); - } -}); -PDFJS.CustomStyle = displayDOMUtils.CustomStyle; -PDFJS.LinkTarget = LinkTarget; -PDFJS.addLinkAttributes = displayDOMUtils.addLinkAttributes; -PDFJS.getFilenameFromUrl = displayDOMUtils.getFilenameFromUrl; -PDFJS.isExternalLinkTargetSet = displayDOMUtils.isExternalLinkTargetSet; -PDFJS.AnnotationLayer = displayAnnotationLayer.AnnotationLayer; -PDFJS.renderTextLayer = displayTextLayer.renderTextLayer; -PDFJS.Metadata = displayMetadata.Metadata; -PDFJS.SVGGraphics = displaySVG.SVGGraphics; -PDFJS.UnsupportedManager = displayAPI._UnsupportedManager; -exports.globalScope = globalScope; -exports.isWorker = isWorker; -exports.PDFJS = globalScope.PDFJS; - -/***/ }), -/* 10 */ -/***/ (function(module, exports, __w_pdfjs_require__) { - -"use strict"; - - -var sharedUtil = __w_pdfjs_require__(0); -var displayDOMUtils = __w_pdfjs_require__(1); -var displayPatternHelper = __w_pdfjs_require__(12); -var displayWebGL = __w_pdfjs_require__(8); -var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX; -var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX; -var ImageKind = sharedUtil.ImageKind; -var OPS = sharedUtil.OPS; -var TextRenderingMode = sharedUtil.TextRenderingMode; -var Uint32ArrayView = sharedUtil.Uint32ArrayView; -var Util = sharedUtil.Util; -var assert = sharedUtil.assert; -var info = sharedUtil.info; -var isNum = sharedUtil.isNum; -var isArray = sharedUtil.isArray; -var isLittleEndian = sharedUtil.isLittleEndian; -var error = sharedUtil.error; -var shadow = sharedUtil.shadow; -var warn = sharedUtil.warn; -var TilingPattern = displayPatternHelper.TilingPattern; -var getShadingPatternFromIR = displayPatternHelper.getShadingPatternFromIR; -var WebGLUtils = displayWebGL.WebGLUtils; -var hasCanvasTypedArrays = displayDOMUtils.hasCanvasTypedArrays; -var MIN_FONT_SIZE = 16; -var MAX_FONT_SIZE = 100; -var MAX_GROUP_SIZE = 4096; -var MIN_WIDTH_FACTOR = 0.65; -var COMPILE_TYPE3_GLYPHS = true; -var MAX_SIZE_TO_COMPILE = 1000; -var FULL_CHUNK_HEIGHT = 16; -var HasCanvasTypedArraysCached = { - get value() { - return shadow(HasCanvasTypedArraysCached, 'value', hasCanvasTypedArrays()); - } -}; -var IsLittleEndianCached = { - get value() { - return shadow(IsLittleEndianCached, 'value', isLittleEndian()); - } -}; -function addContextCurrentTransform(ctx) { - if (!ctx.mozCurrentTransform) { - ctx._originalSave = ctx.save; - ctx._originalRestore = ctx.restore; - ctx._originalRotate = ctx.rotate; - ctx._originalScale = ctx.scale; - ctx._originalTranslate = ctx.translate; - ctx._originalTransform = ctx.transform; - ctx._originalSetTransform = ctx.setTransform; - ctx._transformMatrix = ctx._transformMatrix || [1, 0, 0, 1, 0, 0]; - ctx._transformStack = []; - Object.defineProperty(ctx, 'mozCurrentTransform', { - get: function getCurrentTransform() { - return this._transformMatrix; + _createClass(ReadableStreamDefaultReader, [{ + key: 'cancel', + value: function cancel(reason) { + if (IsReadableStreamDefaultReader(this) === false) { + return Promise.reject(defaultReaderBrandCheckException('cancel')); + } + if (this._ownerReadableStream === undefined) { + return Promise.reject(readerLockException('cancel')); + } + return ReadableStreamReaderGenericCancel(this, reason); } - }); - Object.defineProperty(ctx, 'mozCurrentTransformInverse', { - get: function getCurrentTransformInverse() { - var m = this._transformMatrix; - var a = m[0], - b = m[1], - c = m[2], - d = m[3], - e = m[4], - f = m[5]; - var ad_bc = a * d - b * c; - var bc_ad = b * c - a * d; - return [d / ad_bc, b / bc_ad, c / bc_ad, a / ad_bc, (d * e - c * f) / bc_ad, (b * e - a * f) / ad_bc]; + }, { + key: 'read', + value: function read() { + if (IsReadableStreamDefaultReader(this) === false) { + return Promise.reject(defaultReaderBrandCheckException('read')); + } + if (this._ownerReadableStream === undefined) { + return Promise.reject(readerLockException('read from')); + } + return ReadableStreamDefaultReaderRead(this); } - }); - ctx.save = function ctxSave() { - var old = this._transformMatrix; - this._transformStack.push(old); - this._transformMatrix = old.slice(0, 6); - this._originalSave(); - }; - ctx.restore = function ctxRestore() { - var prev = this._transformStack.pop(); - if (prev) { - this._transformMatrix = prev; - this._originalRestore(); + }, { + key: 'releaseLock', + value: function releaseLock() { + if (IsReadableStreamDefaultReader(this) === false) { + throw defaultReaderBrandCheckException('releaseLock'); + } + if (this._ownerReadableStream === undefined) { + return; + } + if (this._readRequests.length > 0) { + throw new TypeError('Tried to release a reader lock when that reader has pending read() calls un-settled'); + } + ReadableStreamReaderGenericRelease(this); } - }; - ctx.translate = function ctxTranslate(x, y) { - var m = this._transformMatrix; - m[4] = m[0] * x + m[2] * y + m[4]; - m[5] = m[1] * x + m[3] * y + m[5]; - this._originalTranslate(x, y); - }; - ctx.scale = function ctxScale(x, y) { - var m = this._transformMatrix; - m[0] = m[0] * x; - m[1] = m[1] * x; - m[2] = m[2] * y; - m[3] = m[3] * y; - this._originalScale(x, y); - }; - ctx.transform = function ctxTransform(a, b, c, d, e, f) { - var m = this._transformMatrix; - this._transformMatrix = [m[0] * a + m[2] * b, m[1] * a + m[3] * b, m[0] * c + m[2] * d, m[1] * c + m[3] * d, m[0] * e + m[2] * f + m[4], m[1] * e + m[3] * f + m[5]]; - ctx._originalTransform(a, b, c, d, e, f); - }; - ctx.setTransform = function ctxSetTransform(a, b, c, d, e, f) { - this._transformMatrix = [a, b, c, d, e, f]; - ctx._originalSetTransform(a, b, c, d, e, f); - }; - ctx.rotate = function ctxRotate(angle) { - var cosValue = Math.cos(angle); - var sinValue = Math.sin(angle); - var m = this._transformMatrix; - this._transformMatrix = [m[0] * cosValue + m[2] * sinValue, m[1] * cosValue + m[3] * sinValue, m[0] * -sinValue + m[2] * cosValue, m[1] * -sinValue + m[3] * cosValue, m[4], m[5]]; - this._originalRotate(angle); - }; - } -} -var CachedCanvases = function CachedCanvasesClosure() { - function CachedCanvases(canvasFactory) { - this.canvasFactory = canvasFactory; - this.cache = Object.create(null); - } - CachedCanvases.prototype = { - getCanvas: function CachedCanvases_getCanvas(id, width, height, trackTransform) { - var canvasEntry; - if (this.cache[id] !== undefined) { - canvasEntry = this.cache[id]; - this.canvasFactory.reset(canvasEntry, width, height); - canvasEntry.context.setTransform(1, 0, 0, 1, 0, 0); - } else { - canvasEntry = this.canvasFactory.create(width, height); - this.cache[id] = canvasEntry; + }, { + key: 'closed', + get: function get() { + if (IsReadableStreamDefaultReader(this) === false) { + return Promise.reject(defaultReaderBrandCheckException('closed')); + } + return this._closedPromise; } - if (trackTransform) { - addContextCurrentTransform(canvasEntry.context); + }]); + return ReadableStreamDefaultReader; + }(); + var ReadableStreamBYOBReader = function () { + function ReadableStreamBYOBReader(stream) { + _classCallCheck(this, ReadableStreamBYOBReader); + if (!IsReadableStream(stream)) { + throw new TypeError('ReadableStreamBYOBReader can only be constructed with a ReadableStream instance given a ' + 'byte source'); } - return canvasEntry; - }, - clear: function () { - for (var id in this.cache) { - var canvasEntry = this.cache[id]; - this.canvasFactory.destroy(canvasEntry); - delete this.cache[id]; + if (IsReadableByteStreamController(stream._readableStreamController) === false) { + throw new TypeError('Cannot construct a ReadableStreamBYOBReader for a stream not constructed with a byte ' + 'source'); + } + if (IsReadableStreamLocked(stream)) { + throw new TypeError('This stream has already been locked for exclusive reading by another reader'); } + ReadableStreamReaderGenericInitialize(this, stream); + this._readIntoRequests = []; } - }; - return CachedCanvases; -}(); -function compileType3Glyph(imgData) { - var POINT_TO_PROCESS_LIMIT = 1000; - var width = imgData.width, - height = imgData.height; - var i, - j, - j0, - width1 = width + 1; - var points = new Uint8Array(width1 * (height + 1)); - var POINT_TYPES = new Uint8Array([0, 2, 4, 0, 1, 0, 5, 4, 8, 10, 0, 8, 0, 2, 1, 0]); - var lineSize = width + 7 & ~7, - data0 = imgData.data; - var data = new Uint8Array(lineSize * height), - pos = 0, - ii; - for (i = 0, ii = data0.length; i < ii; i++) { - var mask = 128, - elem = data0[i]; - while (mask > 0) { - data[pos++] = elem & mask ? 0 : 255; - mask >>= 1; + _createClass(ReadableStreamBYOBReader, [{ + key: 'cancel', + value: function cancel(reason) { + if (!IsReadableStreamBYOBReader(this)) { + return Promise.reject(byobReaderBrandCheckException('cancel')); + } + if (this._ownerReadableStream === undefined) { + return Promise.reject(readerLockException('cancel')); + } + return ReadableStreamReaderGenericCancel(this, reason); + } + }, { + key: 'read', + value: function read(view) { + if (!IsReadableStreamBYOBReader(this)) { + return Promise.reject(byobReaderBrandCheckException('read')); + } + if (this._ownerReadableStream === undefined) { + return Promise.reject(readerLockException('read from')); + } + if (!ArrayBuffer.isView(view)) { + return Promise.reject(new TypeError('view must be an array buffer view')); + } + if (view.byteLength === 0) { + return Promise.reject(new TypeError('view must have non-zero byteLength')); + } + return ReadableStreamBYOBReaderRead(this, view); + } + }, { + key: 'releaseLock', + value: function releaseLock() { + if (!IsReadableStreamBYOBReader(this)) { + throw byobReaderBrandCheckException('releaseLock'); + } + if (this._ownerReadableStream === undefined) { + return; + } + if (this._readIntoRequests.length > 0) { + throw new TypeError('Tried to release a reader lock when that reader has pending read() calls un-settled'); + } + ReadableStreamReaderGenericRelease(this); + } + }, { + key: 'closed', + get: function get() { + if (!IsReadableStreamBYOBReader(this)) { + return Promise.reject(byobReaderBrandCheckException('closed')); + } + return this._closedPromise; + } + }]); + return ReadableStreamBYOBReader; + }(); + function IsReadableStreamBYOBReader(x) { + if (!typeIsObject(x)) { + return false; } + if (!Object.prototype.hasOwnProperty.call(x, '_readIntoRequests')) { + return false; + } + return true; } - var count = 0; - pos = 0; - if (data[pos] !== 0) { - points[0] = 1; - ++count; + function IsReadableStreamDefaultReader(x) { + if (!typeIsObject(x)) { + return false; + } + if (!Object.prototype.hasOwnProperty.call(x, '_readRequests')) { + return false; + } + return true; } - for (j = 1; j < width; j++) { - if (data[pos] !== data[pos + 1]) { - points[j] = data[pos] ? 2 : 1; - ++count; + function ReadableStreamReaderGenericInitialize(reader, stream) { + reader._ownerReadableStream = stream; + stream._reader = reader; + if (stream._state === 'readable') { + defaultReaderClosedPromiseInitialize(reader); + } else if (stream._state === 'closed') { + defaultReaderClosedPromiseInitializeAsResolved(reader); + } else { + assert(stream._state === 'errored', 'state must be errored'); + defaultReaderClosedPromiseInitializeAsRejected(reader, stream._storedError); + reader._closedPromise.catch(function () {}); } - pos++; } - if (data[pos] !== 0) { - points[j] = 2; - ++count; + function ReadableStreamReaderGenericCancel(reader, reason) { + var stream = reader._ownerReadableStream; + assert(stream !== undefined); + return ReadableStreamCancel(stream, reason); } - for (i = 1; i < height; i++) { - pos = i * lineSize; - j0 = i * width1; - if (data[pos - lineSize] !== data[pos]) { - points[j0] = data[pos] ? 1 : 8; - ++count; + function ReadableStreamReaderGenericRelease(reader) { + assert(reader._ownerReadableStream !== undefined); + assert(reader._ownerReadableStream._reader === reader); + if (reader._ownerReadableStream._state === 'readable') { + defaultReaderClosedPromiseReject(reader, new TypeError('Reader was released and can no longer be used to monitor the stream\'s closedness')); + } else { + defaultReaderClosedPromiseResetToRejected(reader, new TypeError('Reader was released and can no longer be used to monitor the stream\'s closedness')); } - var sum = (data[pos] ? 4 : 0) + (data[pos - lineSize] ? 8 : 0); - for (j = 1; j < width; j++) { - sum = (sum >> 2) + (data[pos + 1] ? 4 : 0) + (data[pos - lineSize + 1] ? 8 : 0); - if (POINT_TYPES[sum]) { - points[j0 + j] = POINT_TYPES[sum]; - ++count; - } - pos++; + reader._closedPromise.catch(function () {}); + reader._ownerReadableStream._reader = undefined; + reader._ownerReadableStream = undefined; + } + function ReadableStreamBYOBReaderRead(reader, view) { + var stream = reader._ownerReadableStream; + assert(stream !== undefined); + stream._disturbed = true; + if (stream._state === 'errored') { + return Promise.reject(stream._storedError); } - if (data[pos - lineSize] !== data[pos]) { - points[j0 + j] = data[pos] ? 2 : 4; - ++count; + return ReadableByteStreamControllerPullInto(stream._readableStreamController, view); + } + function ReadableStreamDefaultReaderRead(reader) { + var stream = reader._ownerReadableStream; + assert(stream !== undefined); + stream._disturbed = true; + if (stream._state === 'closed') { + return Promise.resolve(CreateIterResultObject(undefined, true)); } - if (count > POINT_TO_PROCESS_LIMIT) { - return null; + if (stream._state === 'errored') { + return Promise.reject(stream._storedError); } + assert(stream._state === 'readable'); + return stream._readableStreamController.__pullSteps(); } - pos = lineSize * (height - 1); - j0 = i * width1; - if (data[pos] !== 0) { - points[j0] = 8; - ++count; - } - for (j = 1; j < width; j++) { - if (data[pos] !== data[pos + 1]) { - points[j0 + j] = data[pos] ? 4 : 8; - ++count; + var ReadableStreamDefaultController = function () { + function ReadableStreamDefaultController(stream, underlyingSource, size, highWaterMark) { + _classCallCheck(this, ReadableStreamDefaultController); + if (IsReadableStream(stream) === false) { + throw new TypeError('ReadableStreamDefaultController can only be constructed with a ReadableStream instance'); + } + if (stream._readableStreamController !== undefined) { + throw new TypeError('ReadableStreamDefaultController instances can only be created by the ReadableStream constructor'); + } + this._controlledReadableStream = stream; + this._underlyingSource = underlyingSource; + this._queue = undefined; + this._queueTotalSize = undefined; + ResetQueue(this); + this._started = false; + this._closeRequested = false; + this._pullAgain = false; + this._pulling = false; + var normalizedStrategy = ValidateAndNormalizeQueuingStrategy(size, highWaterMark); + this._strategySize = normalizedStrategy.size; + this._strategyHWM = normalizedStrategy.highWaterMark; + var controller = this; + var startResult = InvokeOrNoop(underlyingSource, 'start', [this]); + Promise.resolve(startResult).then(function () { + controller._started = true; + assert(controller._pulling === false); + assert(controller._pullAgain === false); + ReadableStreamDefaultControllerCallPullIfNeeded(controller); + }, function (r) { + ReadableStreamDefaultControllerErrorIfNeeded(controller, r); + }).catch(rethrowAssertionErrorRejection); } - pos++; - } - if (data[pos] !== 0) { - points[j0 + j] = 4; - ++count; - } - if (count > POINT_TO_PROCESS_LIMIT) { - return null; + _createClass(ReadableStreamDefaultController, [{ + key: 'close', + value: function close() { + if (IsReadableStreamDefaultController(this) === false) { + throw defaultControllerBrandCheckException('close'); + } + if (this._closeRequested === true) { + throw new TypeError('The stream has already been closed; do not close it again!'); + } + var state = this._controlledReadableStream._state; + if (state !== 'readable') { + throw new TypeError('The stream (in ' + state + ' state) is not in the readable state and cannot be closed'); + } + ReadableStreamDefaultControllerClose(this); + } + }, { + key: 'enqueue', + value: function enqueue(chunk) { + if (IsReadableStreamDefaultController(this) === false) { + throw defaultControllerBrandCheckException('enqueue'); + } + if (this._closeRequested === true) { + throw new TypeError('stream is closed or draining'); + } + var state = this._controlledReadableStream._state; + if (state !== 'readable') { + throw new TypeError('The stream (in ' + state + ' state) is not in the readable state and cannot be enqueued to'); + } + return ReadableStreamDefaultControllerEnqueue(this, chunk); + } + }, { + key: 'error', + value: function error(e) { + if (IsReadableStreamDefaultController(this) === false) { + throw defaultControllerBrandCheckException('error'); + } + var stream = this._controlledReadableStream; + if (stream._state !== 'readable') { + throw new TypeError('The stream is ' + stream._state + ' and so cannot be errored'); + } + ReadableStreamDefaultControllerError(this, e); + } + }, { + key: '__cancelSteps', + value: function __cancelSteps(reason) { + ResetQueue(this); + return PromiseInvokeOrNoop(this._underlyingSource, 'cancel', [reason]); + } + }, { + key: '__pullSteps', + value: function __pullSteps() { + var stream = this._controlledReadableStream; + if (this._queue.length > 0) { + var chunk = DequeueValue(this); + if (this._closeRequested === true && this._queue.length === 0) { + ReadableStreamClose(stream); + } else { + ReadableStreamDefaultControllerCallPullIfNeeded(this); + } + return Promise.resolve(CreateIterResultObject(chunk, false)); + } + var pendingPromise = ReadableStreamAddReadRequest(stream); + ReadableStreamDefaultControllerCallPullIfNeeded(this); + return pendingPromise; + } + }, { + key: 'desiredSize', + get: function get() { + if (IsReadableStreamDefaultController(this) === false) { + throw defaultControllerBrandCheckException('desiredSize'); + } + return ReadableStreamDefaultControllerGetDesiredSize(this); + } + }]); + return ReadableStreamDefaultController; + }(); + function IsReadableStreamDefaultController(x) { + if (!typeIsObject(x)) { + return false; + } + if (!Object.prototype.hasOwnProperty.call(x, '_underlyingSource')) { + return false; + } + return true; } - var steps = new Int32Array([0, width1, -1, 0, -width1, 0, 0, 0, 1]); - var outlines = []; - for (i = 0; count && i <= height; i++) { - var p = i * width1; - var end = p + width; - while (p < end && !points[p]) { - p++; + function ReadableStreamDefaultControllerCallPullIfNeeded(controller) { + var shouldPull = ReadableStreamDefaultControllerShouldCallPull(controller); + if (shouldPull === false) { + return undefined; } - if (p === end) { - continue; + if (controller._pulling === true) { + controller._pullAgain = true; + return undefined; } - var coords = [p % width1, i]; - var type = points[p], - p0 = p, - pp; - do { - var step = steps[type]; - do { - p += step; - } while (!points[p]); - pp = points[p]; - if (pp !== 5 && pp !== 10) { - type = pp; - points[p] = 0; - } else { - type = pp & 0x33 * type >> 4; - points[p] &= type >> 2 | type << 2; - } - coords.push(p % width1); - coords.push(p / width1 | 0); - --count; - } while (p0 !== p); - outlines.push(coords); - --i; + assert(controller._pullAgain === false); + controller._pulling = true; + var pullPromise = PromiseInvokeOrNoop(controller._underlyingSource, 'pull', [controller]); + pullPromise.then(function () { + controller._pulling = false; + if (controller._pullAgain === true) { + controller._pullAgain = false; + return ReadableStreamDefaultControllerCallPullIfNeeded(controller); + } + return undefined; + }, function (e) { + ReadableStreamDefaultControllerErrorIfNeeded(controller, e); + }).catch(rethrowAssertionErrorRejection); + return undefined; } - var drawOutline = function (c) { - c.save(); - c.scale(1 / width, -1 / height); - c.translate(0, -height); - c.beginPath(); - for (var i = 0, ii = outlines.length; i < ii; i++) { - var o = outlines[i]; - c.moveTo(o[0], o[1]); - for (var j = 2, jj = o.length; j < jj; j += 2) { - c.lineTo(o[j], o[j + 1]); + function ReadableStreamDefaultControllerShouldCallPull(controller) { + var stream = controller._controlledReadableStream; + if (stream._state === 'closed' || stream._state === 'errored') { + return false; + } + if (controller._closeRequested === true) { + return false; + } + if (controller._started === false) { + return false; + } + if (IsReadableStreamLocked(stream) === true && ReadableStreamGetNumReadRequests(stream) > 0) { + return true; + } + var desiredSize = ReadableStreamDefaultControllerGetDesiredSize(controller); + if (desiredSize > 0) { + return true; + } + return false; + } + function ReadableStreamDefaultControllerClose(controller) { + var stream = controller._controlledReadableStream; + assert(controller._closeRequested === false); + assert(stream._state === 'readable'); + controller._closeRequested = true; + if (controller._queue.length === 0) { + ReadableStreamClose(stream); + } + } + function ReadableStreamDefaultControllerEnqueue(controller, chunk) { + var stream = controller._controlledReadableStream; + assert(controller._closeRequested === false); + assert(stream._state === 'readable'); + if (IsReadableStreamLocked(stream) === true && ReadableStreamGetNumReadRequests(stream) > 0) { + ReadableStreamFulfillReadRequest(stream, chunk, false); + } else { + var chunkSize = 1; + if (controller._strategySize !== undefined) { + var strategySize = controller._strategySize; + try { + chunkSize = strategySize(chunk); + } catch (chunkSizeE) { + ReadableStreamDefaultControllerErrorIfNeeded(controller, chunkSizeE); + throw chunkSizeE; + } + } + try { + EnqueueValueWithSize(controller, chunk, chunkSize); + } catch (enqueueE) { + ReadableStreamDefaultControllerErrorIfNeeded(controller, enqueueE); + throw enqueueE; } } - c.fill(); - c.beginPath(); - c.restore(); - }; - return drawOutline; -} -var CanvasExtraState = function CanvasExtraStateClosure() { - function CanvasExtraState(old) { - this.alphaIsShape = false; - this.fontSize = 0; - this.fontSizeScale = 1; - this.textMatrix = IDENTITY_MATRIX; - this.textMatrixScale = 1; - this.fontMatrix = FONT_IDENTITY_MATRIX; - this.leading = 0; - this.x = 0; - this.y = 0; - this.lineX = 0; - this.lineY = 0; - this.charSpacing = 0; - this.wordSpacing = 0; - this.textHScale = 1; - this.textRenderingMode = TextRenderingMode.FILL; - this.textRise = 0; - this.fillColor = '#000000'; - this.strokeColor = '#000000'; - this.patternFill = false; - this.fillAlpha = 1; - this.strokeAlpha = 1; - this.lineWidth = 1; - this.activeSMask = null; - this.resumeSMaskCtx = null; - this.old = old; + ReadableStreamDefaultControllerCallPullIfNeeded(controller); + return undefined; } - CanvasExtraState.prototype = { - clone: function CanvasExtraState_clone() { - return Object.create(this); - }, - setCurrentPoint: function CanvasExtraState_setCurrentPoint(x, y) { - this.x = x; - this.y = y; + function ReadableStreamDefaultControllerError(controller, e) { + var stream = controller._controlledReadableStream; + assert(stream._state === 'readable'); + ResetQueue(controller); + ReadableStreamError(stream, e); + } + function ReadableStreamDefaultControllerErrorIfNeeded(controller, e) { + if (controller._controlledReadableStream._state === 'readable') { + ReadableStreamDefaultControllerError(controller, e); } - }; - return CanvasExtraState; -}(); -var CanvasGraphics = function CanvasGraphicsClosure() { - var EXECUTION_TIME = 15; - var EXECUTION_STEPS = 10; - function CanvasGraphics(canvasCtx, commonObjs, objs, canvasFactory, imageLayer) { - this.ctx = canvasCtx; - this.current = new CanvasExtraState(); - this.stateStack = []; - this.pendingClip = null; - this.pendingEOFill = false; - this.res = null; - this.xobjs = null; - this.commonObjs = commonObjs; - this.objs = objs; - this.canvasFactory = canvasFactory; - this.imageLayer = imageLayer; - this.groupStack = []; - this.processingType3 = null; - this.baseTransform = null; - this.baseTransformStack = []; - this.groupLevel = 0; - this.smaskStack = []; - this.smaskCounter = 0; - this.tempSMask = null; - this.cachedCanvases = new CachedCanvases(this.canvasFactory); - if (canvasCtx) { - addContextCurrentTransform(canvasCtx); + } + function ReadableStreamDefaultControllerGetDesiredSize(controller) { + var stream = controller._controlledReadableStream; + var state = stream._state; + if (state === 'errored') { + return null; } - this.cachedGetSinglePixelWidth = null; + if (state === 'closed') { + return 0; + } + return controller._strategyHWM - controller._queueTotalSize; } - function putBinaryImageData(ctx, imgData) { - if (typeof ImageData !== 'undefined' && imgData instanceof ImageData) { - ctx.putImageData(imgData, 0, 0); - return; + var ReadableStreamBYOBRequest = function () { + function ReadableStreamBYOBRequest(controller, view) { + _classCallCheck(this, ReadableStreamBYOBRequest); + this._associatedReadableByteStreamController = controller; + this._view = view; } - var height = imgData.height, - width = imgData.width; - var partialChunkHeight = height % FULL_CHUNK_HEIGHT; - var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT; - var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1; - var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT); - var srcPos = 0, - destPos; - var src = imgData.data; - var dest = chunkImgData.data; - var i, j, thisChunkHeight, elemsInThisChunk; - if (imgData.kind === ImageKind.GRAYSCALE_1BPP) { - var srcLength = src.byteLength; - var dest32 = HasCanvasTypedArraysCached.value ? new Uint32Array(dest.buffer) : new Uint32ArrayView(dest); - var dest32DataLength = dest32.length; - var fullSrcDiff = width + 7 >> 3; - var white = 0xFFFFFFFF; - var black = IsLittleEndianCached.value || !HasCanvasTypedArraysCached.value ? 0xFF000000 : 0x000000FF; - for (i = 0; i < totalChunks; i++) { - thisChunkHeight = i < fullChunks ? FULL_CHUNK_HEIGHT : partialChunkHeight; - destPos = 0; - for (j = 0; j < thisChunkHeight; j++) { - var srcDiff = srcLength - srcPos; - var k = 0; - var kEnd = srcDiff > fullSrcDiff ? width : srcDiff * 8 - 7; - var kEndUnrolled = kEnd & ~7; - var mask = 0; - var srcByte = 0; - for (; k < kEndUnrolled; k += 8) { - srcByte = src[srcPos++]; - dest32[destPos++] = srcByte & 128 ? white : black; - dest32[destPos++] = srcByte & 64 ? white : black; - dest32[destPos++] = srcByte & 32 ? white : black; - dest32[destPos++] = srcByte & 16 ? white : black; - dest32[destPos++] = srcByte & 8 ? white : black; - dest32[destPos++] = srcByte & 4 ? white : black; - dest32[destPos++] = srcByte & 2 ? white : black; - dest32[destPos++] = srcByte & 1 ? white : black; - } - for (; k < kEnd; k++) { - if (mask === 0) { - srcByte = src[srcPos++]; - mask = 128; - } - dest32[destPos++] = srcByte & mask ? white : black; - mask >>= 1; - } + _createClass(ReadableStreamBYOBRequest, [{ + key: 'respond', + value: function respond(bytesWritten) { + if (IsReadableStreamBYOBRequest(this) === false) { + throw byobRequestBrandCheckException('respond'); } - while (destPos < dest32DataLength) { - dest32[destPos++] = 0; + if (this._associatedReadableByteStreamController === undefined) { + throw new TypeError('This BYOB request has been invalidated'); } - ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT); + ReadableByteStreamControllerRespond(this._associatedReadableByteStreamController, bytesWritten); } - } else if (imgData.kind === ImageKind.RGBA_32BPP) { - j = 0; - elemsInThisChunk = width * FULL_CHUNK_HEIGHT * 4; - for (i = 0; i < fullChunks; i++) { - dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk)); - srcPos += elemsInThisChunk; - ctx.putImageData(chunkImgData, 0, j); - j += FULL_CHUNK_HEIGHT; + }, { + key: 'respondWithNewView', + value: function respondWithNewView(view) { + if (IsReadableStreamBYOBRequest(this) === false) { + throw byobRequestBrandCheckException('respond'); + } + if (this._associatedReadableByteStreamController === undefined) { + throw new TypeError('This BYOB request has been invalidated'); + } + if (!ArrayBuffer.isView(view)) { + throw new TypeError('You can only respond with array buffer views'); + } + ReadableByteStreamControllerRespondWithNewView(this._associatedReadableByteStreamController, view); + } + }, { + key: 'view', + get: function get() { + return this._view; + } + }]); + return ReadableStreamBYOBRequest; + }(); + var ReadableByteStreamController = function () { + function ReadableByteStreamController(stream, underlyingByteSource, highWaterMark) { + _classCallCheck(this, ReadableByteStreamController); + if (IsReadableStream(stream) === false) { + throw new TypeError('ReadableByteStreamController can only be constructed with a ReadableStream instance given ' + 'a byte source'); + } + if (stream._readableStreamController !== undefined) { + throw new TypeError('ReadableByteStreamController instances can only be created by the ReadableStream constructor given a byte ' + 'source'); + } + this._controlledReadableStream = stream; + this._underlyingByteSource = underlyingByteSource; + this._pullAgain = false; + this._pulling = false; + ReadableByteStreamControllerClearPendingPullIntos(this); + this._queue = this._queueTotalSize = undefined; + ResetQueue(this); + this._closeRequested = false; + this._started = false; + this._strategyHWM = ValidateAndNormalizeHighWaterMark(highWaterMark); + var autoAllocateChunkSize = underlyingByteSource.autoAllocateChunkSize; + if (autoAllocateChunkSize !== undefined) { + if (Number.isInteger(autoAllocateChunkSize) === false || autoAllocateChunkSize <= 0) { + throw new RangeError('autoAllocateChunkSize must be a positive integer'); + } } - if (i < totalChunks) { - elemsInThisChunk = width * partialChunkHeight * 4; - dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk)); - ctx.putImageData(chunkImgData, 0, j); + this._autoAllocateChunkSize = autoAllocateChunkSize; + this._pendingPullIntos = []; + var controller = this; + var startResult = InvokeOrNoop(underlyingByteSource, 'start', [this]); + Promise.resolve(startResult).then(function () { + controller._started = true; + assert(controller._pulling === false); + assert(controller._pullAgain === false); + ReadableByteStreamControllerCallPullIfNeeded(controller); + }, function (r) { + if (stream._state === 'readable') { + ReadableByteStreamControllerError(controller, r); + } + }).catch(rethrowAssertionErrorRejection); + } + _createClass(ReadableByteStreamController, [{ + key: 'close', + value: function close() { + if (IsReadableByteStreamController(this) === false) { + throw byteStreamControllerBrandCheckException('close'); + } + if (this._closeRequested === true) { + throw new TypeError('The stream has already been closed; do not close it again!'); + } + var state = this._controlledReadableStream._state; + if (state !== 'readable') { + throw new TypeError('The stream (in ' + state + ' state) is not in the readable state and cannot be closed'); + } + ReadableByteStreamControllerClose(this); } - } else if (imgData.kind === ImageKind.RGB_24BPP) { - thisChunkHeight = FULL_CHUNK_HEIGHT; - elemsInThisChunk = width * thisChunkHeight; - for (i = 0; i < totalChunks; i++) { - if (i >= fullChunks) { - thisChunkHeight = partialChunkHeight; - elemsInThisChunk = width * thisChunkHeight; + }, { + key: 'enqueue', + value: function enqueue(chunk) { + if (IsReadableByteStreamController(this) === false) { + throw byteStreamControllerBrandCheckException('enqueue'); } - destPos = 0; - for (j = elemsInThisChunk; j--;) { - dest[destPos++] = src[srcPos++]; - dest[destPos++] = src[srcPos++]; - dest[destPos++] = src[srcPos++]; - dest[destPos++] = 255; + if (this._closeRequested === true) { + throw new TypeError('stream is closed or draining'); } - ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT); + var state = this._controlledReadableStream._state; + if (state !== 'readable') { + throw new TypeError('The stream (in ' + state + ' state) is not in the readable state and cannot be enqueued to'); + } + if (!ArrayBuffer.isView(chunk)) { + throw new TypeError('You can only enqueue array buffer views when using a ReadableByteStreamController'); + } + ReadableByteStreamControllerEnqueue(this, chunk); } - } else { - error('bad image kind: ' + imgData.kind); + }, { + key: 'error', + value: function error(e) { + if (IsReadableByteStreamController(this) === false) { + throw byteStreamControllerBrandCheckException('error'); + } + var stream = this._controlledReadableStream; + if (stream._state !== 'readable') { + throw new TypeError('The stream is ' + stream._state + ' and so cannot be errored'); + } + ReadableByteStreamControllerError(this, e); + } + }, { + key: '__cancelSteps', + value: function __cancelSteps(reason) { + if (this._pendingPullIntos.length > 0) { + var firstDescriptor = this._pendingPullIntos[0]; + firstDescriptor.bytesFilled = 0; + } + ResetQueue(this); + return PromiseInvokeOrNoop(this._underlyingByteSource, 'cancel', [reason]); + } + }, { + key: '__pullSteps', + value: function __pullSteps() { + var stream = this._controlledReadableStream; + assert(ReadableStreamHasDefaultReader(stream) === true); + if (this._queueTotalSize > 0) { + assert(ReadableStreamGetNumReadRequests(stream) === 0); + var entry = this._queue.shift(); + this._queueTotalSize -= entry.byteLength; + ReadableByteStreamControllerHandleQueueDrain(this); + var view = void 0; + try { + view = new Uint8Array(entry.buffer, entry.byteOffset, entry.byteLength); + } catch (viewE) { + return Promise.reject(viewE); + } + return Promise.resolve(CreateIterResultObject(view, false)); + } + var autoAllocateChunkSize = this._autoAllocateChunkSize; + if (autoAllocateChunkSize !== undefined) { + var buffer = void 0; + try { + buffer = new ArrayBuffer(autoAllocateChunkSize); + } catch (bufferE) { + return Promise.reject(bufferE); + } + var pullIntoDescriptor = { + buffer: buffer, + byteOffset: 0, + byteLength: autoAllocateChunkSize, + bytesFilled: 0, + elementSize: 1, + ctor: Uint8Array, + readerType: 'default' + }; + this._pendingPullIntos.push(pullIntoDescriptor); + } + var promise = ReadableStreamAddReadRequest(stream); + ReadableByteStreamControllerCallPullIfNeeded(this); + return promise; + } + }, { + key: 'byobRequest', + get: function get() { + if (IsReadableByteStreamController(this) === false) { + throw byteStreamControllerBrandCheckException('byobRequest'); + } + if (this._byobRequest === undefined && this._pendingPullIntos.length > 0) { + var firstDescriptor = this._pendingPullIntos[0]; + var view = new Uint8Array(firstDescriptor.buffer, firstDescriptor.byteOffset + firstDescriptor.bytesFilled, firstDescriptor.byteLength - firstDescriptor.bytesFilled); + this._byobRequest = new ReadableStreamBYOBRequest(this, view); + } + return this._byobRequest; + } + }, { + key: 'desiredSize', + get: function get() { + if (IsReadableByteStreamController(this) === false) { + throw byteStreamControllerBrandCheckException('desiredSize'); + } + return ReadableByteStreamControllerGetDesiredSize(this); + } + }]); + return ReadableByteStreamController; + }(); + function IsReadableByteStreamController(x) { + if (!typeIsObject(x)) { + return false; } + if (!Object.prototype.hasOwnProperty.call(x, '_underlyingByteSource')) { + return false; + } + return true; } - function putBinaryImageMask(ctx, imgData) { - var height = imgData.height, - width = imgData.width; - var partialChunkHeight = height % FULL_CHUNK_HEIGHT; - var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT; - var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1; - var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT); - var srcPos = 0; - var src = imgData.data; - var dest = chunkImgData.data; - for (var i = 0; i < totalChunks; i++) { - var thisChunkHeight = i < fullChunks ? FULL_CHUNK_HEIGHT : partialChunkHeight; - var destPos = 3; - for (var j = 0; j < thisChunkHeight; j++) { - var mask = 0; - for (var k = 0; k < width; k++) { - if (!mask) { - var elem = src[srcPos++]; - mask = 128; - } - dest[destPos] = elem & mask ? 0 : 255; - destPos += 4; - mask >>= 1; - } + function IsReadableStreamBYOBRequest(x) { + if (!typeIsObject(x)) { + return false; + } + if (!Object.prototype.hasOwnProperty.call(x, '_associatedReadableByteStreamController')) { + return false; + } + return true; + } + function ReadableByteStreamControllerCallPullIfNeeded(controller) { + var shouldPull = ReadableByteStreamControllerShouldCallPull(controller); + if (shouldPull === false) { + return undefined; + } + if (controller._pulling === true) { + controller._pullAgain = true; + return undefined; + } + assert(controller._pullAgain === false); + controller._pulling = true; + var pullPromise = PromiseInvokeOrNoop(controller._underlyingByteSource, 'pull', [controller]); + pullPromise.then(function () { + controller._pulling = false; + if (controller._pullAgain === true) { + controller._pullAgain = false; + ReadableByteStreamControllerCallPullIfNeeded(controller); + } + }, function (e) { + if (controller._controlledReadableStream._state === 'readable') { + ReadableByteStreamControllerError(controller, e); + } + }).catch(rethrowAssertionErrorRejection); + return undefined; + } + function ReadableByteStreamControllerClearPendingPullIntos(controller) { + ReadableByteStreamControllerInvalidateBYOBRequest(controller); + controller._pendingPullIntos = []; + } + function ReadableByteStreamControllerCommitPullIntoDescriptor(stream, pullIntoDescriptor) { + assert(stream._state !== 'errored', 'state must not be errored'); + var done = false; + if (stream._state === 'closed') { + assert(pullIntoDescriptor.bytesFilled === 0); + done = true; + } + var filledView = ReadableByteStreamControllerConvertPullIntoDescriptor(pullIntoDescriptor); + if (pullIntoDescriptor.readerType === 'default') { + ReadableStreamFulfillReadRequest(stream, filledView, done); + } else { + assert(pullIntoDescriptor.readerType === 'byob'); + ReadableStreamFulfillReadIntoRequest(stream, filledView, done); + } + } + function ReadableByteStreamControllerConvertPullIntoDescriptor(pullIntoDescriptor) { + var bytesFilled = pullIntoDescriptor.bytesFilled; + var elementSize = pullIntoDescriptor.elementSize; + assert(bytesFilled <= pullIntoDescriptor.byteLength); + assert(bytesFilled % elementSize === 0); + return new pullIntoDescriptor.ctor(pullIntoDescriptor.buffer, pullIntoDescriptor.byteOffset, bytesFilled / elementSize); + } + function ReadableByteStreamControllerEnqueueChunkToQueue(controller, buffer, byteOffset, byteLength) { + controller._queue.push({ + buffer: buffer, + byteOffset: byteOffset, + byteLength: byteLength + }); + controller._queueTotalSize += byteLength; + } + function ReadableByteStreamControllerFillPullIntoDescriptorFromQueue(controller, pullIntoDescriptor) { + var elementSize = pullIntoDescriptor.elementSize; + var currentAlignedBytes = pullIntoDescriptor.bytesFilled - pullIntoDescriptor.bytesFilled % elementSize; + var maxBytesToCopy = Math.min(controller._queueTotalSize, pullIntoDescriptor.byteLength - pullIntoDescriptor.bytesFilled); + var maxBytesFilled = pullIntoDescriptor.bytesFilled + maxBytesToCopy; + var maxAlignedBytes = maxBytesFilled - maxBytesFilled % elementSize; + var totalBytesToCopyRemaining = maxBytesToCopy; + var ready = false; + if (maxAlignedBytes > currentAlignedBytes) { + totalBytesToCopyRemaining = maxAlignedBytes - pullIntoDescriptor.bytesFilled; + ready = true; + } + var queue = controller._queue; + while (totalBytesToCopyRemaining > 0) { + var headOfQueue = queue[0]; + var bytesToCopy = Math.min(totalBytesToCopyRemaining, headOfQueue.byteLength); + var destStart = pullIntoDescriptor.byteOffset + pullIntoDescriptor.bytesFilled; + ArrayBufferCopy(pullIntoDescriptor.buffer, destStart, headOfQueue.buffer, headOfQueue.byteOffset, bytesToCopy); + if (headOfQueue.byteLength === bytesToCopy) { + queue.shift(); + } else { + headOfQueue.byteOffset += bytesToCopy; + headOfQueue.byteLength -= bytesToCopy; } - ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT); + controller._queueTotalSize -= bytesToCopy; + ReadableByteStreamControllerFillHeadPullIntoDescriptor(controller, bytesToCopy, pullIntoDescriptor); + totalBytesToCopyRemaining -= bytesToCopy; + } + if (ready === false) { + assert(controller._queueTotalSize === 0, 'queue must be empty'); + assert(pullIntoDescriptor.bytesFilled > 0); + assert(pullIntoDescriptor.bytesFilled < pullIntoDescriptor.elementSize); } + return ready; } - function copyCtxState(sourceCtx, destCtx) { - var properties = ['strokeStyle', 'fillStyle', 'fillRule', 'globalAlpha', 'lineWidth', 'lineCap', 'lineJoin', 'miterLimit', 'globalCompositeOperation', 'font']; - for (var i = 0, ii = properties.length; i < ii; i++) { - var property = properties[i]; - if (sourceCtx[property] !== undefined) { - destCtx[property] = sourceCtx[property]; + function ReadableByteStreamControllerFillHeadPullIntoDescriptor(controller, size, pullIntoDescriptor) { + assert(controller._pendingPullIntos.length === 0 || controller._pendingPullIntos[0] === pullIntoDescriptor); + ReadableByteStreamControllerInvalidateBYOBRequest(controller); + pullIntoDescriptor.bytesFilled += size; + } + function ReadableByteStreamControllerHandleQueueDrain(controller) { + assert(controller._controlledReadableStream._state === 'readable'); + if (controller._queueTotalSize === 0 && controller._closeRequested === true) { + ReadableStreamClose(controller._controlledReadableStream); + } else { + ReadableByteStreamControllerCallPullIfNeeded(controller); + } + } + function ReadableByteStreamControllerInvalidateBYOBRequest(controller) { + if (controller._byobRequest === undefined) { + return; + } + controller._byobRequest._associatedReadableByteStreamController = undefined; + controller._byobRequest._view = undefined; + controller._byobRequest = undefined; + } + function ReadableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller) { + assert(controller._closeRequested === false); + while (controller._pendingPullIntos.length > 0) { + if (controller._queueTotalSize === 0) { + return; + } + var pullIntoDescriptor = controller._pendingPullIntos[0]; + if (ReadableByteStreamControllerFillPullIntoDescriptorFromQueue(controller, pullIntoDescriptor) === true) { + ReadableByteStreamControllerShiftPendingPullInto(controller); + ReadableByteStreamControllerCommitPullIntoDescriptor(controller._controlledReadableStream, pullIntoDescriptor); } } - if (sourceCtx.setLineDash !== undefined) { - destCtx.setLineDash(sourceCtx.getLineDash()); - destCtx.lineDashOffset = sourceCtx.lineDashOffset; + } + function ReadableByteStreamControllerPullInto(controller, view) { + var stream = controller._controlledReadableStream; + var elementSize = 1; + if (view.constructor !== DataView) { + elementSize = view.constructor.BYTES_PER_ELEMENT; + } + var ctor = view.constructor; + var pullIntoDescriptor = { + buffer: view.buffer, + byteOffset: view.byteOffset, + byteLength: view.byteLength, + bytesFilled: 0, + elementSize: elementSize, + ctor: ctor, + readerType: 'byob' + }; + if (controller._pendingPullIntos.length > 0) { + pullIntoDescriptor.buffer = TransferArrayBuffer(pullIntoDescriptor.buffer); + controller._pendingPullIntos.push(pullIntoDescriptor); + return ReadableStreamAddReadIntoRequest(stream); + } + if (stream._state === 'closed') { + var emptyView = new view.constructor(pullIntoDescriptor.buffer, pullIntoDescriptor.byteOffset, 0); + return Promise.resolve(CreateIterResultObject(emptyView, true)); + } + if (controller._queueTotalSize > 0) { + if (ReadableByteStreamControllerFillPullIntoDescriptorFromQueue(controller, pullIntoDescriptor) === true) { + var filledView = ReadableByteStreamControllerConvertPullIntoDescriptor(pullIntoDescriptor); + ReadableByteStreamControllerHandleQueueDrain(controller); + return Promise.resolve(CreateIterResultObject(filledView, false)); + } + if (controller._closeRequested === true) { + var e = new TypeError('Insufficient bytes to fill elements in the given buffer'); + ReadableByteStreamControllerError(controller, e); + return Promise.reject(e); + } } + pullIntoDescriptor.buffer = TransferArrayBuffer(pullIntoDescriptor.buffer); + controller._pendingPullIntos.push(pullIntoDescriptor); + var promise = ReadableStreamAddReadIntoRequest(stream); + ReadableByteStreamControllerCallPullIfNeeded(controller); + return promise; } - function composeSMaskBackdrop(bytes, r0, g0, b0) { - var length = bytes.length; - for (var i = 3; i < length; i += 4) { - var alpha = bytes[i]; - if (alpha === 0) { - bytes[i - 3] = r0; - bytes[i - 2] = g0; - bytes[i - 1] = b0; - } else if (alpha < 255) { - var alpha_ = 255 - alpha; - bytes[i - 3] = bytes[i - 3] * alpha + r0 * alpha_ >> 8; - bytes[i - 2] = bytes[i - 2] * alpha + g0 * alpha_ >> 8; - bytes[i - 1] = bytes[i - 1] * alpha + b0 * alpha_ >> 8; + function ReadableByteStreamControllerRespondInClosedState(controller, firstDescriptor) { + firstDescriptor.buffer = TransferArrayBuffer(firstDescriptor.buffer); + assert(firstDescriptor.bytesFilled === 0, 'bytesFilled must be 0'); + var stream = controller._controlledReadableStream; + if (ReadableStreamHasBYOBReader(stream) === true) { + while (ReadableStreamGetNumReadIntoRequests(stream) > 0) { + var pullIntoDescriptor = ReadableByteStreamControllerShiftPendingPullInto(controller); + ReadableByteStreamControllerCommitPullIntoDescriptor(stream, pullIntoDescriptor); } } } - function composeSMaskAlpha(maskData, layerData, transferMap) { - var length = maskData.length; - var scale = 1 / 255; - for (var i = 3; i < length; i += 4) { - var alpha = transferMap ? transferMap[maskData[i]] : maskData[i]; - layerData[i] = layerData[i] * alpha * scale | 0; + function ReadableByteStreamControllerRespondInReadableState(controller, bytesWritten, pullIntoDescriptor) { + if (pullIntoDescriptor.bytesFilled + bytesWritten > pullIntoDescriptor.byteLength) { + throw new RangeError('bytesWritten out of range'); } + ReadableByteStreamControllerFillHeadPullIntoDescriptor(controller, bytesWritten, pullIntoDescriptor); + if (pullIntoDescriptor.bytesFilled < pullIntoDescriptor.elementSize) { + return; + } + ReadableByteStreamControllerShiftPendingPullInto(controller); + var remainderSize = pullIntoDescriptor.bytesFilled % pullIntoDescriptor.elementSize; + if (remainderSize > 0) { + var end = pullIntoDescriptor.byteOffset + pullIntoDescriptor.bytesFilled; + var remainder = pullIntoDescriptor.buffer.slice(end - remainderSize, end); + ReadableByteStreamControllerEnqueueChunkToQueue(controller, remainder, 0, remainder.byteLength); + } + pullIntoDescriptor.buffer = TransferArrayBuffer(pullIntoDescriptor.buffer); + pullIntoDescriptor.bytesFilled -= remainderSize; + ReadableByteStreamControllerCommitPullIntoDescriptor(controller._controlledReadableStream, pullIntoDescriptor); + ReadableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller); } - function composeSMaskLuminosity(maskData, layerData, transferMap) { - var length = maskData.length; - for (var i = 3; i < length; i += 4) { - var y = maskData[i - 3] * 77 + maskData[i - 2] * 152 + maskData[i - 1] * 28; - layerData[i] = transferMap ? layerData[i] * transferMap[y >> 8] >> 8 : layerData[i] * y >> 16; + function ReadableByteStreamControllerRespondInternal(controller, bytesWritten) { + var firstDescriptor = controller._pendingPullIntos[0]; + var stream = controller._controlledReadableStream; + if (stream._state === 'closed') { + if (bytesWritten !== 0) { + throw new TypeError('bytesWritten must be 0 when calling respond() on a closed stream'); + } + ReadableByteStreamControllerRespondInClosedState(controller, firstDescriptor); + } else { + assert(stream._state === 'readable'); + ReadableByteStreamControllerRespondInReadableState(controller, bytesWritten, firstDescriptor); } } - function genericComposeSMask(maskCtx, layerCtx, width, height, subtype, backdrop, transferMap) { - var hasBackdrop = !!backdrop; - var r0 = hasBackdrop ? backdrop[0] : 0; - var g0 = hasBackdrop ? backdrop[1] : 0; - var b0 = hasBackdrop ? backdrop[2] : 0; - var composeFn; - if (subtype === 'Luminosity') { - composeFn = composeSMaskLuminosity; + function ReadableByteStreamControllerShiftPendingPullInto(controller) { + var descriptor = controller._pendingPullIntos.shift(); + ReadableByteStreamControllerInvalidateBYOBRequest(controller); + return descriptor; + } + function ReadableByteStreamControllerShouldCallPull(controller) { + var stream = controller._controlledReadableStream; + if (stream._state !== 'readable') { + return false; + } + if (controller._closeRequested === true) { + return false; + } + if (controller._started === false) { + return false; + } + if (ReadableStreamHasDefaultReader(stream) === true && ReadableStreamGetNumReadRequests(stream) > 0) { + return true; + } + if (ReadableStreamHasBYOBReader(stream) === true && ReadableStreamGetNumReadIntoRequests(stream) > 0) { + return true; + } + if (ReadableByteStreamControllerGetDesiredSize(controller) > 0) { + return true; + } + return false; + } + function ReadableByteStreamControllerClose(controller) { + var stream = controller._controlledReadableStream; + assert(controller._closeRequested === false); + assert(stream._state === 'readable'); + if (controller._queueTotalSize > 0) { + controller._closeRequested = true; + return; + } + if (controller._pendingPullIntos.length > 0) { + var firstPendingPullInto = controller._pendingPullIntos[0]; + if (firstPendingPullInto.bytesFilled > 0) { + var e = new TypeError('Insufficient bytes to fill elements in the given buffer'); + ReadableByteStreamControllerError(controller, e); + throw e; + } + } + ReadableStreamClose(stream); + } + function ReadableByteStreamControllerEnqueue(controller, chunk) { + var stream = controller._controlledReadableStream; + assert(controller._closeRequested === false); + assert(stream._state === 'readable'); + var buffer = chunk.buffer; + var byteOffset = chunk.byteOffset; + var byteLength = chunk.byteLength; + var transferredBuffer = TransferArrayBuffer(buffer); + if (ReadableStreamHasDefaultReader(stream) === true) { + if (ReadableStreamGetNumReadRequests(stream) === 0) { + ReadableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength); + } else { + assert(controller._queue.length === 0); + var transferredView = new Uint8Array(transferredBuffer, byteOffset, byteLength); + ReadableStreamFulfillReadRequest(stream, transferredView, false); + } + } else if (ReadableStreamHasBYOBReader(stream) === true) { + ReadableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength); + ReadableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller); } else { - composeFn = composeSMaskAlpha; + assert(IsReadableStreamLocked(stream) === false, 'stream must not be locked'); + ReadableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength); } - var PIXELS_TO_PROCESS = 1048576; - var chunkSize = Math.min(height, Math.ceil(PIXELS_TO_PROCESS / width)); - for (var row = 0; row < height; row += chunkSize) { - var chunkHeight = Math.min(chunkSize, height - row); - var maskData = maskCtx.getImageData(0, row, width, chunkHeight); - var layerData = layerCtx.getImageData(0, row, width, chunkHeight); - if (hasBackdrop) { - composeSMaskBackdrop(maskData.data, r0, g0, b0); + } + function ReadableByteStreamControllerError(controller, e) { + var stream = controller._controlledReadableStream; + assert(stream._state === 'readable'); + ReadableByteStreamControllerClearPendingPullIntos(controller); + ResetQueue(controller); + ReadableStreamError(stream, e); + } + function ReadableByteStreamControllerGetDesiredSize(controller) { + var stream = controller._controlledReadableStream; + var state = stream._state; + if (state === 'errored') { + return null; + } + if (state === 'closed') { + return 0; + } + return controller._strategyHWM - controller._queueTotalSize; + } + function ReadableByteStreamControllerRespond(controller, bytesWritten) { + bytesWritten = Number(bytesWritten); + if (IsFiniteNonNegativeNumber(bytesWritten) === false) { + throw new RangeError('bytesWritten must be a finite'); + } + assert(controller._pendingPullIntos.length > 0); + ReadableByteStreamControllerRespondInternal(controller, bytesWritten); + } + function ReadableByteStreamControllerRespondWithNewView(controller, view) { + assert(controller._pendingPullIntos.length > 0); + var firstDescriptor = controller._pendingPullIntos[0]; + if (firstDescriptor.byteOffset + firstDescriptor.bytesFilled !== view.byteOffset) { + throw new RangeError('The region specified by view does not match byobRequest'); + } + if (firstDescriptor.byteLength !== view.byteLength) { + throw new RangeError('The buffer of view has different capacity than byobRequest'); + } + firstDescriptor.buffer = view.buffer; + ReadableByteStreamControllerRespondInternal(controller, view.byteLength); + } + function streamBrandCheckException(name) { + return new TypeError('ReadableStream.prototype.' + name + ' can only be used on a ReadableStream'); + } + function readerLockException(name) { + return new TypeError('Cannot ' + name + ' a stream using a released reader'); + } + function defaultReaderBrandCheckException(name) { + return new TypeError('ReadableStreamDefaultReader.prototype.' + name + ' can only be used on a ReadableStreamDefaultReader'); + } + function defaultReaderClosedPromiseInitialize(reader) { + reader._closedPromise = new Promise(function (resolve, reject) { + reader._closedPromise_resolve = resolve; + reader._closedPromise_reject = reject; + }); + } + function defaultReaderClosedPromiseInitializeAsRejected(reader, reason) { + reader._closedPromise = Promise.reject(reason); + reader._closedPromise_resolve = undefined; + reader._closedPromise_reject = undefined; + } + function defaultReaderClosedPromiseInitializeAsResolved(reader) { + reader._closedPromise = Promise.resolve(undefined); + reader._closedPromise_resolve = undefined; + reader._closedPromise_reject = undefined; + } + function defaultReaderClosedPromiseReject(reader, reason) { + assert(reader._closedPromise_resolve !== undefined); + assert(reader._closedPromise_reject !== undefined); + reader._closedPromise_reject(reason); + reader._closedPromise_resolve = undefined; + reader._closedPromise_reject = undefined; + } + function defaultReaderClosedPromiseResetToRejected(reader, reason) { + assert(reader._closedPromise_resolve === undefined); + assert(reader._closedPromise_reject === undefined); + reader._closedPromise = Promise.reject(reason); + } + function defaultReaderClosedPromiseResolve(reader) { + assert(reader._closedPromise_resolve !== undefined); + assert(reader._closedPromise_reject !== undefined); + reader._closedPromise_resolve(undefined); + reader._closedPromise_resolve = undefined; + reader._closedPromise_reject = undefined; + } + function byobReaderBrandCheckException(name) { + return new TypeError('ReadableStreamBYOBReader.prototype.' + name + ' can only be used on a ReadableStreamBYOBReader'); + } + function defaultControllerBrandCheckException(name) { + return new TypeError('ReadableStreamDefaultController.prototype.' + name + ' can only be used on a ReadableStreamDefaultController'); + } + function byobRequestBrandCheckException(name) { + return new TypeError('ReadableStreamBYOBRequest.prototype.' + name + ' can only be used on a ReadableStreamBYOBRequest'); + } + function byteStreamControllerBrandCheckException(name) { + return new TypeError('ReadableByteStreamController.prototype.' + name + ' can only be used on a ReadableByteStreamController'); + } + function ifIsObjectAndHasAPromiseIsHandledInternalSlotSetPromiseIsHandledToTrue(promise) { + try { + Promise.prototype.then.call(promise, undefined, function () {}); + } catch (e) {} + } +}, function (module, exports, __w_pdfjs_require__) { + "use strict"; + + var transformStream = __w_pdfjs_require__(6); + var readableStream = __w_pdfjs_require__(4); + var writableStream = __w_pdfjs_require__(2); + exports.TransformStream = transformStream.TransformStream; + exports.ReadableStream = readableStream.ReadableStream; + exports.IsReadableStreamDisturbed = readableStream.IsReadableStreamDisturbed; + exports.ReadableStreamDefaultControllerClose = readableStream.ReadableStreamDefaultControllerClose; + exports.ReadableStreamDefaultControllerEnqueue = readableStream.ReadableStreamDefaultControllerEnqueue; + exports.ReadableStreamDefaultControllerError = readableStream.ReadableStreamDefaultControllerError; + exports.ReadableStreamDefaultControllerGetDesiredSize = readableStream.ReadableStreamDefaultControllerGetDesiredSize; + exports.AcquireWritableStreamDefaultWriter = writableStream.AcquireWritableStreamDefaultWriter; + exports.IsWritableStream = writableStream.IsWritableStream; + exports.IsWritableStreamLocked = writableStream.IsWritableStreamLocked; + exports.WritableStream = writableStream.WritableStream; + exports.WritableStreamAbort = writableStream.WritableStreamAbort; + exports.WritableStreamDefaultControllerError = writableStream.WritableStreamDefaultControllerError; + exports.WritableStreamDefaultWriterCloseWithErrorPropagation = writableStream.WritableStreamDefaultWriterCloseWithErrorPropagation; + exports.WritableStreamDefaultWriterRelease = writableStream.WritableStreamDefaultWriterRelease; + exports.WritableStreamDefaultWriterWrite = writableStream.WritableStreamDefaultWriterWrite; +}, function (module, exports, __w_pdfjs_require__) { + "use strict"; + + var _createClass = function () { + function defineProperties(target, props) { + for (var i = 0; i < props.length; i++) { + var descriptor = props[i]; + descriptor.enumerable = descriptor.enumerable || false; + descriptor.configurable = true; + if ("value" in descriptor) descriptor.writable = true; + Object.defineProperty(target, descriptor.key, descriptor); } - composeFn(maskData.data, layerData.data, transferMap); - maskCtx.putImageData(layerData, 0, row); + } + return function (Constructor, protoProps, staticProps) { + if (protoProps) defineProperties(Constructor.prototype, protoProps); + if (staticProps) defineProperties(Constructor, staticProps); + return Constructor; + }; + }(); + function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); } } - function composeSMask(ctx, smask, layerCtx) { - var mask = smask.canvas; - var maskCtx = smask.context; - ctx.setTransform(smask.scaleX, 0, 0, smask.scaleY, smask.offsetX, smask.offsetY); - var backdrop = smask.backdrop || null; - if (!smask.transferMap && WebGLUtils.isEnabled) { - var composed = WebGLUtils.composeSMask(layerCtx.canvas, mask, { - subtype: smask.subtype, - backdrop: backdrop - }); - ctx.setTransform(1, 0, 0, 1, 0, 0); - ctx.drawImage(composed, smask.offsetX, smask.offsetY); - return; + var _require = __w_pdfjs_require__(1), + assert = _require.assert; + var _require2 = __w_pdfjs_require__(0), + InvokeOrNoop = _require2.InvokeOrNoop, + PromiseInvokeOrPerformFallback = _require2.PromiseInvokeOrPerformFallback, + PromiseInvokeOrNoop = _require2.PromiseInvokeOrNoop, + typeIsObject = _require2.typeIsObject; + var _require3 = __w_pdfjs_require__(4), + ReadableStream = _require3.ReadableStream, + ReadableStreamDefaultControllerClose = _require3.ReadableStreamDefaultControllerClose, + ReadableStreamDefaultControllerEnqueue = _require3.ReadableStreamDefaultControllerEnqueue, + ReadableStreamDefaultControllerError = _require3.ReadableStreamDefaultControllerError, + ReadableStreamDefaultControllerGetDesiredSize = _require3.ReadableStreamDefaultControllerGetDesiredSize; + var _require4 = __w_pdfjs_require__(2), + WritableStream = _require4.WritableStream, + WritableStreamDefaultControllerError = _require4.WritableStreamDefaultControllerError; + function TransformStreamCloseReadable(transformStream) { + if (transformStream._errored === true) { + throw new TypeError('TransformStream is already errored'); } - genericComposeSMask(maskCtx, layerCtx, mask.width, mask.height, smask.subtype, backdrop, smask.transferMap); - ctx.drawImage(mask, 0, 0); + if (transformStream._readableClosed === true) { + throw new TypeError('Readable side is already closed'); + } + TransformStreamCloseReadableInternal(transformStream); } - var LINE_CAP_STYLES = ['butt', 'round', 'square']; - var LINE_JOIN_STYLES = ['miter', 'round', 'bevel']; - var NORMAL_CLIP = {}; - var EO_CLIP = {}; - CanvasGraphics.prototype = { - beginDrawing: function CanvasGraphics_beginDrawing(transform, viewport, transparency) { - var width = this.ctx.canvas.width; - var height = this.ctx.canvas.height; - this.ctx.save(); - this.ctx.fillStyle = 'rgb(255, 255, 255)'; - this.ctx.fillRect(0, 0, width, height); - this.ctx.restore(); - if (transparency) { - var transparentCanvas = this.cachedCanvases.getCanvas('transparent', width, height, true); - this.compositeCtx = this.ctx; - this.transparentCanvas = transparentCanvas.canvas; - this.ctx = transparentCanvas.context; - this.ctx.save(); - this.ctx.transform.apply(this.ctx, this.compositeCtx.mozCurrentTransform); + function TransformStreamEnqueueToReadable(transformStream, chunk) { + if (transformStream._errored === true) { + throw new TypeError('TransformStream is already errored'); + } + if (transformStream._readableClosed === true) { + throw new TypeError('Readable side is already closed'); + } + var controller = transformStream._readableController; + try { + ReadableStreamDefaultControllerEnqueue(controller, chunk); + } catch (e) { + transformStream._readableClosed = true; + TransformStreamErrorIfNeeded(transformStream, e); + throw transformStream._storedError; + } + var desiredSize = ReadableStreamDefaultControllerGetDesiredSize(controller); + var maybeBackpressure = desiredSize <= 0; + if (maybeBackpressure === true && transformStream._backpressure === false) { + TransformStreamSetBackpressure(transformStream, true); + } + } + function TransformStreamError(transformStream, e) { + if (transformStream._errored === true) { + throw new TypeError('TransformStream is already errored'); + } + TransformStreamErrorInternal(transformStream, e); + } + function TransformStreamCloseReadableInternal(transformStream) { + assert(transformStream._errored === false); + assert(transformStream._readableClosed === false); + try { + ReadableStreamDefaultControllerClose(transformStream._readableController); + } catch (e) { + assert(false); + } + transformStream._readableClosed = true; + } + function TransformStreamErrorIfNeeded(transformStream, e) { + if (transformStream._errored === false) { + TransformStreamErrorInternal(transformStream, e); + } + } + function TransformStreamErrorInternal(transformStream, e) { + assert(transformStream._errored === false); + transformStream._errored = true; + transformStream._storedError = e; + if (transformStream._writableDone === false) { + WritableStreamDefaultControllerError(transformStream._writableController, e); + } + if (transformStream._readableClosed === false) { + ReadableStreamDefaultControllerError(transformStream._readableController, e); + } + } + function TransformStreamReadableReadyPromise(transformStream) { + assert(transformStream._backpressureChangePromise !== undefined, '_backpressureChangePromise should have been initialized'); + if (transformStream._backpressure === false) { + return Promise.resolve(); + } + assert(transformStream._backpressure === true, '_backpressure should have been initialized'); + return transformStream._backpressureChangePromise; + } + function TransformStreamSetBackpressure(transformStream, backpressure) { + assert(transformStream._backpressure !== backpressure, 'TransformStreamSetBackpressure() should be called only when backpressure is changed'); + if (transformStream._backpressureChangePromise !== undefined) { + transformStream._backpressureChangePromise_resolve(backpressure); + } + transformStream._backpressureChangePromise = new Promise(function (resolve) { + transformStream._backpressureChangePromise_resolve = resolve; + }); + transformStream._backpressureChangePromise.then(function (resolution) { + assert(resolution !== backpressure, '_backpressureChangePromise should be fulfilled only when backpressure is changed'); + }); + transformStream._backpressure = backpressure; + } + function TransformStreamDefaultTransform(chunk, transformStreamController) { + var transformStream = transformStreamController._controlledTransformStream; + TransformStreamEnqueueToReadable(transformStream, chunk); + return Promise.resolve(); + } + function TransformStreamTransform(transformStream, chunk) { + assert(transformStream._errored === false); + assert(transformStream._transforming === false); + assert(transformStream._backpressure === false); + transformStream._transforming = true; + var transformer = transformStream._transformer; + var controller = transformStream._transformStreamController; + var transformPromise = PromiseInvokeOrPerformFallback(transformer, 'transform', [chunk, controller], TransformStreamDefaultTransform, [chunk, controller]); + return transformPromise.then(function () { + transformStream._transforming = false; + return TransformStreamReadableReadyPromise(transformStream); + }, function (e) { + TransformStreamErrorIfNeeded(transformStream, e); + return Promise.reject(e); + }); + } + function IsTransformStreamDefaultController(x) { + if (!typeIsObject(x)) { + return false; + } + if (!Object.prototype.hasOwnProperty.call(x, '_controlledTransformStream')) { + return false; + } + return true; + } + function IsTransformStream(x) { + if (!typeIsObject(x)) { + return false; + } + if (!Object.prototype.hasOwnProperty.call(x, '_transformStreamController')) { + return false; + } + return true; + } + var TransformStreamSink = function () { + function TransformStreamSink(transformStream, startPromise) { + _classCallCheck(this, TransformStreamSink); + this._transformStream = transformStream; + this._startPromise = startPromise; + } + _createClass(TransformStreamSink, [{ + key: 'start', + value: function start(c) { + var transformStream = this._transformStream; + transformStream._writableController = c; + return this._startPromise.then(function () { + return TransformStreamReadableReadyPromise(transformStream); + }); } - this.ctx.save(); - if (transform) { - this.ctx.transform.apply(this.ctx, transform); + }, { + key: 'write', + value: function write(chunk) { + var transformStream = this._transformStream; + return TransformStreamTransform(transformStream, chunk); + } + }, { + key: 'abort', + value: function abort() { + var transformStream = this._transformStream; + transformStream._writableDone = true; + TransformStreamErrorInternal(transformStream, new TypeError('Writable side aborted')); + } + }, { + key: 'close', + value: function close() { + var transformStream = this._transformStream; + assert(transformStream._transforming === false); + transformStream._writableDone = true; + var flushPromise = PromiseInvokeOrNoop(transformStream._transformer, 'flush', [transformStream._transformStreamController]); + return flushPromise.then(function () { + if (transformStream._errored === true) { + return Promise.reject(transformStream._storedError); + } + if (transformStream._readableClosed === false) { + TransformStreamCloseReadableInternal(transformStream); + } + return Promise.resolve(); + }).catch(function (r) { + TransformStreamErrorIfNeeded(transformStream, r); + return Promise.reject(transformStream._storedError); + }); } - this.ctx.transform.apply(this.ctx, viewport.transform); - this.baseTransform = this.ctx.mozCurrentTransform.slice(); - if (this.imageLayer) { - this.imageLayer.beginLayout(); + }]); + return TransformStreamSink; + }(); + var TransformStreamSource = function () { + function TransformStreamSource(transformStream, startPromise) { + _classCallCheck(this, TransformStreamSource); + this._transformStream = transformStream; + this._startPromise = startPromise; + } + _createClass(TransformStreamSource, [{ + key: 'start', + value: function start(c) { + var transformStream = this._transformStream; + transformStream._readableController = c; + return this._startPromise.then(function () { + assert(transformStream._backpressureChangePromise !== undefined, '_backpressureChangePromise should have been initialized'); + if (transformStream._backpressure === true) { + return Promise.resolve(); + } + assert(transformStream._backpressure === false, '_backpressure should have been initialized'); + return transformStream._backpressureChangePromise; + }); } - }, - executeOperatorList: function CanvasGraphics_executeOperatorList(operatorList, executionStartIdx, continueCallback, stepper) { - var argsArray = operatorList.argsArray; - var fnArray = operatorList.fnArray; - var i = executionStartIdx || 0; - var argsArrayLen = argsArray.length; - if (argsArrayLen === i) { - return i; + }, { + key: 'pull', + value: function pull() { + var transformStream = this._transformStream; + assert(transformStream._backpressure === true, 'pull() should be never called while _backpressure is false'); + assert(transformStream._backpressureChangePromise !== undefined, '_backpressureChangePromise should have been initialized'); + TransformStreamSetBackpressure(transformStream, false); + return transformStream._backpressureChangePromise; + } + }, { + key: 'cancel', + value: function cancel() { + var transformStream = this._transformStream; + transformStream._readableClosed = true; + TransformStreamErrorInternal(transformStream, new TypeError('Readable side canceled')); + } + }]); + return TransformStreamSource; + }(); + var TransformStreamDefaultController = function () { + function TransformStreamDefaultController(transformStream) { + _classCallCheck(this, TransformStreamDefaultController); + if (IsTransformStream(transformStream) === false) { + throw new TypeError('TransformStreamDefaultController can only be ' + 'constructed with a TransformStream instance'); + } + if (transformStream._transformStreamController !== undefined) { + throw new TypeError('TransformStreamDefaultController instances can ' + 'only be created by the TransformStream constructor'); + } + this._controlledTransformStream = transformStream; + } + _createClass(TransformStreamDefaultController, [{ + key: 'enqueue', + value: function enqueue(chunk) { + if (IsTransformStreamDefaultController(this) === false) { + throw defaultControllerBrandCheckException('enqueue'); + } + TransformStreamEnqueueToReadable(this._controlledTransformStream, chunk); } - var chunkOperations = argsArrayLen - i > EXECUTION_STEPS && typeof continueCallback === 'function'; - var endTime = chunkOperations ? Date.now() + EXECUTION_TIME : 0; - var steps = 0; - var commonObjs = this.commonObjs; - var objs = this.objs; - var fnId; - while (true) { - if (stepper !== undefined && i === stepper.nextBreakPoint) { - stepper.breakIt(i, continueCallback); - return i; + }, { + key: 'close', + value: function close() { + if (IsTransformStreamDefaultController(this) === false) { + throw defaultControllerBrandCheckException('close'); } - fnId = fnArray[i]; - if (fnId !== OPS.dependency) { - this[fnId].apply(this, argsArray[i]); - } else { - var deps = argsArray[i]; - for (var n = 0, nn = deps.length; n < nn; n++) { - var depObjId = deps[n]; - var common = depObjId[0] === 'g' && depObjId[1] === '_'; - var objsPool = common ? commonObjs : objs; - if (!objsPool.isResolved(depObjId)) { - objsPool.get(depObjId, continueCallback); - return i; - } - } + TransformStreamCloseReadable(this._controlledTransformStream); + } + }, { + key: 'error', + value: function error(reason) { + if (IsTransformStreamDefaultController(this) === false) { + throw defaultControllerBrandCheckException('error'); } - i++; - if (i === argsArrayLen) { - return i; + TransformStreamError(this._controlledTransformStream, reason); + } + }, { + key: 'desiredSize', + get: function get() { + if (IsTransformStreamDefaultController(this) === false) { + throw defaultControllerBrandCheckException('desiredSize'); } - if (chunkOperations && ++steps > EXECUTION_STEPS) { - if (Date.now() > endTime) { - continueCallback(); - return i; - } - steps = 0; + var transformStream = this._controlledTransformStream; + var readableController = transformStream._readableController; + return ReadableStreamDefaultControllerGetDesiredSize(readableController); + } + }]); + return TransformStreamDefaultController; + }(); + var TransformStream = function () { + function TransformStream() { + var transformer = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + _classCallCheck(this, TransformStream); + this._transformer = transformer; + var readableStrategy = transformer.readableStrategy, + writableStrategy = transformer.writableStrategy; + this._transforming = false; + this._errored = false; + this._storedError = undefined; + this._writableController = undefined; + this._readableController = undefined; + this._transformStreamController = undefined; + this._writableDone = false; + this._readableClosed = false; + this._backpressure = undefined; + this._backpressureChangePromise = undefined; + this._backpressureChangePromise_resolve = undefined; + this._transformStreamController = new TransformStreamDefaultController(this); + var startPromise_resolve = void 0; + var startPromise = new Promise(function (resolve) { + startPromise_resolve = resolve; + }); + var source = new TransformStreamSource(this, startPromise); + this._readable = new ReadableStream(source, readableStrategy); + var sink = new TransformStreamSink(this, startPromise); + this._writable = new WritableStream(sink, writableStrategy); + assert(this._writableController !== undefined); + assert(this._readableController !== undefined); + var desiredSize = ReadableStreamDefaultControllerGetDesiredSize(this._readableController); + TransformStreamSetBackpressure(this, desiredSize <= 0); + var transformStream = this; + var startResult = InvokeOrNoop(transformer, 'start', [transformStream._transformStreamController]); + startPromise_resolve(startResult); + startPromise.catch(function (e) { + if (transformStream._errored === false) { + transformStream._errored = true; + transformStream._storedError = e; + } + }); + } + _createClass(TransformStream, [{ + key: 'readable', + get: function get() { + if (IsTransformStream(this) === false) { + throw streamBrandCheckException('readable'); } + return this._readable; + } + }, { + key: 'writable', + get: function get() { + if (IsTransformStream(this) === false) { + throw streamBrandCheckException('writable'); + } + return this._writable; + } + }]); + return TransformStream; + }(); + module.exports = { TransformStream: TransformStream }; + function defaultControllerBrandCheckException(name) { + return new TypeError('TransformStreamDefaultController.prototype.' + name + ' can only be used on a TransformStreamDefaultController'); + } + function streamBrandCheckException(name) { + return new TypeError('TransformStream.prototype.' + name + ' can only be used on a TransformStream'); + } +}, function (module, exports, __w_pdfjs_require__) { + module.exports = __w_pdfjs_require__(5); +}])); + +/***/ }), +/* 127 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; + +{ + var isURLSupported = false; + try { + if (typeof URL === 'function' && _typeof(URL.prototype) === 'object' && 'origin' in URL.prototype) { + var u = new URL('b', 'http://a'); + u.pathname = 'c%20d'; + isURLSupported = u.href === 'http://a/c%20d'; + } + } catch (ex) {} + if (isURLSupported) { + exports.URL = URL; + } else { + var PolyfillURL = __w_pdfjs_require__(128).URL; + var OriginalURL = __w_pdfjs_require__(3).URL; + if (OriginalURL) { + PolyfillURL.createObjectURL = function (blob) { + return OriginalURL.createObjectURL.apply(OriginalURL, arguments); + }; + PolyfillURL.revokeObjectURL = function (url) { + OriginalURL.revokeObjectURL(url); + }; + } + exports.URL = PolyfillURL; + } +} + +/***/ }), +/* 128 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +(function URLConstructorClosure() { + 'use strict'; + + var relative = Object.create(null); + relative['ftp'] = 21; + relative['file'] = 0; + relative['gopher'] = 70; + relative['http'] = 80; + relative['https'] = 443; + relative['ws'] = 80; + relative['wss'] = 443; + var relativePathDotMapping = Object.create(null); + relativePathDotMapping['%2e'] = '.'; + relativePathDotMapping['.%2e'] = '..'; + relativePathDotMapping['%2e.'] = '..'; + relativePathDotMapping['%2e%2e'] = '..'; + function isRelativeScheme(scheme) { + return relative[scheme] !== undefined; + } + function invalid() { + clear.call(this); + this._isInvalid = true; + } + function IDNAToASCII(h) { + if (h === '') { + invalid.call(this); + } + return h.toLowerCase(); + } + function percentEscape(c) { + var unicode = c.charCodeAt(0); + if (unicode > 0x20 && unicode < 0x7F && [0x22, 0x23, 0x3C, 0x3E, 0x3F, 0x60].indexOf(unicode) === -1) { + return c; + } + return encodeURIComponent(c); + } + function percentEscapeQuery(c) { + var unicode = c.charCodeAt(0); + if (unicode > 0x20 && unicode < 0x7F && [0x22, 0x23, 0x3C, 0x3E, 0x60].indexOf(unicode) === -1) { + return c; + } + return encodeURIComponent(c); + } + var EOF, + ALPHA = /[a-zA-Z]/, + ALPHANUMERIC = /[a-zA-Z0-9\+\-\.]/; + function parse(input, stateOverride, base) { + function err(message) { + errors.push(message); + } + var state = stateOverride || 'scheme start', + cursor = 0, + buffer = '', + seenAt = false, + seenBracket = false, + errors = []; + loop: while ((input[cursor - 1] !== EOF || cursor === 0) && !this._isInvalid) { + var c = input[cursor]; + switch (state) { + case 'scheme start': + if (c && ALPHA.test(c)) { + buffer += c.toLowerCase(); + state = 'scheme'; + } else if (!stateOverride) { + buffer = ''; + state = 'no scheme'; + continue; + } else { + err('Invalid scheme.'); + break loop; + } + break; + case 'scheme': + if (c && ALPHANUMERIC.test(c)) { + buffer += c.toLowerCase(); + } else if (c === ':') { + this._scheme = buffer; + buffer = ''; + if (stateOverride) { + break loop; + } + if (isRelativeScheme(this._scheme)) { + this._isRelative = true; + } + if (this._scheme === 'file') { + state = 'relative'; + } else if (this._isRelative && base && base._scheme === this._scheme) { + state = 'relative or authority'; + } else if (this._isRelative) { + state = 'authority first slash'; + } else { + state = 'scheme data'; + } + } else if (!stateOverride) { + buffer = ''; + cursor = 0; + state = 'no scheme'; + continue; + } else if (c === EOF) { + break loop; + } else { + err('Code point not allowed in scheme: ' + c); + break loop; + } + break; + case 'scheme data': + if (c === '?') { + this._query = '?'; + state = 'query'; + } else if (c === '#') { + this._fragment = '#'; + state = 'fragment'; + } else { + if (c !== EOF && c !== '\t' && c !== '\n' && c !== '\r') { + this._schemeData += percentEscape(c); + } + } + break; + case 'no scheme': + if (!base || !isRelativeScheme(base._scheme)) { + err('Missing scheme.'); + invalid.call(this); + } else { + state = 'relative'; + continue; + } + break; + case 'relative or authority': + if (c === '/' && input[cursor + 1] === '/') { + state = 'authority ignore slashes'; + } else { + err('Expected /, got: ' + c); + state = 'relative'; + continue; + } + break; + case 'relative': + this._isRelative = true; + if (this._scheme !== 'file') { + this._scheme = base._scheme; + } + if (c === EOF) { + this._host = base._host; + this._port = base._port; + this._path = base._path.slice(); + this._query = base._query; + this._username = base._username; + this._password = base._password; + break loop; + } else if (c === '/' || c === '\\') { + if (c === '\\') { + err('\\ is an invalid code point.'); + } + state = 'relative slash'; + } else if (c === '?') { + this._host = base._host; + this._port = base._port; + this._path = base._path.slice(); + this._query = '?'; + this._username = base._username; + this._password = base._password; + state = 'query'; + } else if (c === '#') { + this._host = base._host; + this._port = base._port; + this._path = base._path.slice(); + this._query = base._query; + this._fragment = '#'; + this._username = base._username; + this._password = base._password; + state = 'fragment'; + } else { + var nextC = input[cursor + 1]; + var nextNextC = input[cursor + 2]; + if (this._scheme !== 'file' || !ALPHA.test(c) || nextC !== ':' && nextC !== '|' || nextNextC !== EOF && nextNextC !== '/' && nextNextC !== '\\' && nextNextC !== '?' && nextNextC !== '#') { + this._host = base._host; + this._port = base._port; + this._username = base._username; + this._password = base._password; + this._path = base._path.slice(); + this._path.pop(); + } + state = 'relative path'; + continue; + } + break; + case 'relative slash': + if (c === '/' || c === '\\') { + if (c === '\\') { + err('\\ is an invalid code point.'); + } + if (this._scheme === 'file') { + state = 'file host'; + } else { + state = 'authority ignore slashes'; + } + } else { + if (this._scheme !== 'file') { + this._host = base._host; + this._port = base._port; + this._username = base._username; + this._password = base._password; + } + state = 'relative path'; + continue; + } + break; + case 'authority first slash': + if (c === '/') { + state = 'authority second slash'; + } else { + err('Expected \'/\', got: ' + c); + state = 'authority ignore slashes'; + continue; + } + break; + case 'authority second slash': + state = 'authority ignore slashes'; + if (c !== '/') { + err('Expected \'/\', got: ' + c); + continue; + } + break; + case 'authority ignore slashes': + if (c !== '/' && c !== '\\') { + state = 'authority'; + continue; + } else { + err('Expected authority, got: ' + c); + } + break; + case 'authority': + if (c === '@') { + if (seenAt) { + err('@ already seen.'); + buffer += '%40'; + } + seenAt = true; + for (var i = 0; i < buffer.length; i++) { + var cp = buffer[i]; + if (cp === '\t' || cp === '\n' || cp === '\r') { + err('Invalid whitespace in authority.'); + continue; + } + if (cp === ':' && this._password === null) { + this._password = ''; + continue; + } + var tempC = percentEscape(cp); + if (this._password !== null) { + this._password += tempC; + } else { + this._username += tempC; + } + } + buffer = ''; + } else if (c === EOF || c === '/' || c === '\\' || c === '?' || c === '#') { + cursor -= buffer.length; + buffer = ''; + state = 'host'; + continue; + } else { + buffer += c; + } + break; + case 'file host': + if (c === EOF || c === '/' || c === '\\' || c === '?' || c === '#') { + if (buffer.length === 2 && ALPHA.test(buffer[0]) && (buffer[1] === ':' || buffer[1] === '|')) { + state = 'relative path'; + } else if (buffer.length === 0) { + state = 'relative path start'; + } else { + this._host = IDNAToASCII.call(this, buffer); + buffer = ''; + state = 'relative path start'; + } + continue; + } else if (c === '\t' || c === '\n' || c === '\r') { + err('Invalid whitespace in file host.'); + } else { + buffer += c; + } + break; + case 'host': + case 'hostname': + if (c === ':' && !seenBracket) { + this._host = IDNAToASCII.call(this, buffer); + buffer = ''; + state = 'port'; + if (stateOverride === 'hostname') { + break loop; + } + } else if (c === EOF || c === '/' || c === '\\' || c === '?' || c === '#') { + this._host = IDNAToASCII.call(this, buffer); + buffer = ''; + state = 'relative path start'; + if (stateOverride) { + break loop; + } + continue; + } else if (c !== '\t' && c !== '\n' && c !== '\r') { + if (c === '[') { + seenBracket = true; + } else if (c === ']') { + seenBracket = false; + } + buffer += c; + } else { + err('Invalid code point in host/hostname: ' + c); + } + break; + case 'port': + if (/[0-9]/.test(c)) { + buffer += c; + } else if (c === EOF || c === '/' || c === '\\' || c === '?' || c === '#' || stateOverride) { + if (buffer !== '') { + var temp = parseInt(buffer, 10); + if (temp !== relative[this._scheme]) { + this._port = temp + ''; + } + buffer = ''; + } + if (stateOverride) { + break loop; + } + state = 'relative path start'; + continue; + } else if (c === '\t' || c === '\n' || c === '\r') { + err('Invalid code point in port: ' + c); + } else { + invalid.call(this); + } + break; + case 'relative path start': + if (c === '\\') { + err('\'\\\' not allowed in path.'); + } + state = 'relative path'; + if (c !== '/' && c !== '\\') { + continue; + } + break; + case 'relative path': + if (c === EOF || c === '/' || c === '\\' || !stateOverride && (c === '?' || c === '#')) { + if (c === '\\') { + err('\\ not allowed in relative path.'); + } + var tmp; + if (tmp = relativePathDotMapping[buffer.toLowerCase()]) { + buffer = tmp; + } + if (buffer === '..') { + this._path.pop(); + if (c !== '/' && c !== '\\') { + this._path.push(''); + } + } else if (buffer === '.' && c !== '/' && c !== '\\') { + this._path.push(''); + } else if (buffer !== '.') { + if (this._scheme === 'file' && this._path.length === 0 && buffer.length === 2 && ALPHA.test(buffer[0]) && buffer[1] === '|') { + buffer = buffer[0] + ':'; + } + this._path.push(buffer); + } + buffer = ''; + if (c === '?') { + this._query = '?'; + state = 'query'; + } else if (c === '#') { + this._fragment = '#'; + state = 'fragment'; + } + } else if (c !== '\t' && c !== '\n' && c !== '\r') { + buffer += percentEscape(c); + } + break; + case 'query': + if (!stateOverride && c === '#') { + this._fragment = '#'; + state = 'fragment'; + } else if (c !== EOF && c !== '\t' && c !== '\n' && c !== '\r') { + this._query += percentEscapeQuery(c); + } + break; + case 'fragment': + if (c !== EOF && c !== '\t' && c !== '\n' && c !== '\r') { + this._fragment += c; + } + break; } + cursor++; + } + } + function clear() { + this._scheme = ''; + this._schemeData = ''; + this._username = ''; + this._password = null; + this._host = ''; + this._port = ''; + this._path = []; + this._query = ''; + this._fragment = ''; + this._isInvalid = false; + this._isRelative = false; + } + function JURL(url, base) { + if (base !== undefined && !(base instanceof JURL)) { + base = new JURL(String(base)); + } + this._url = url; + clear.call(this); + var input = url.replace(/^[ \t\r\n\f]+|[ \t\r\n\f]+$/g, ''); + parse.call(this, input, null, base); + } + JURL.prototype = { + toString: function toString() { + return this.href; }, - endDrawing: function CanvasGraphics_endDrawing() { - if (this.current.activeSMask !== null) { - this.endSMaskGroup(); + + get href() { + if (this._isInvalid) { + return this._url; } - this.ctx.restore(); - if (this.transparentCanvas) { - this.ctx = this.compositeCtx; - this.ctx.save(); - this.ctx.setTransform(1, 0, 0, 1, 0, 0); - this.ctx.drawImage(this.transparentCanvas, 0, 0); - this.ctx.restore(); - this.transparentCanvas = null; + var authority = ''; + if (this._username !== '' || this._password !== null) { + authority = this._username + (this._password !== null ? ':' + this._password : '') + '@'; } - this.cachedCanvases.clear(); - WebGLUtils.clear(); - if (this.imageLayer) { - this.imageLayer.endLayout(); + return this.protocol + (this._isRelative ? '//' + authority + this.host : '') + this.pathname + this._query + this._fragment; + }, + set href(value) { + clear.call(this); + parse.call(this, value); + }, + get protocol() { + return this._scheme + ':'; + }, + set protocol(value) { + if (this._isInvalid) { + return; } + parse.call(this, value + ':', 'scheme start'); }, - setLineWidth: function CanvasGraphics_setLineWidth(width) { - this.current.lineWidth = width; - this.ctx.lineWidth = width; + get host() { + return this._isInvalid ? '' : this._port ? this._host + ':' + this._port : this._host; }, - setLineCap: function CanvasGraphics_setLineCap(style) { - this.ctx.lineCap = LINE_CAP_STYLES[style]; + set host(value) { + if (this._isInvalid || !this._isRelative) { + return; + } + parse.call(this, value, 'host'); }, - setLineJoin: function CanvasGraphics_setLineJoin(style) { - this.ctx.lineJoin = LINE_JOIN_STYLES[style]; + get hostname() { + return this._host; }, - setMiterLimit: function CanvasGraphics_setMiterLimit(limit) { - this.ctx.miterLimit = limit; + set hostname(value) { + if (this._isInvalid || !this._isRelative) { + return; + } + parse.call(this, value, 'hostname'); }, - setDash: function CanvasGraphics_setDash(dashArray, dashPhase) { - var ctx = this.ctx; - if (ctx.setLineDash !== undefined) { - ctx.setLineDash(dashArray); - ctx.lineDashOffset = dashPhase; - } - }, - setRenderingIntent: function CanvasGraphics_setRenderingIntent(intent) {}, - setFlatness: function CanvasGraphics_setFlatness(flatness) {}, - setGState: function CanvasGraphics_setGState(states) { - for (var i = 0, ii = states.length; i < ii; i++) { - var state = states[i]; - var key = state[0]; - var value = state[1]; - switch (key) { - case 'LW': - this.setLineWidth(value); - break; - case 'LC': - this.setLineCap(value); - break; - case 'LJ': - this.setLineJoin(value); - break; - case 'ML': - this.setMiterLimit(value); - break; - case 'D': - this.setDash(value[0], value[1]); - break; - case 'RI': - this.setRenderingIntent(value); - break; - case 'FL': - this.setFlatness(value); - break; - case 'Font': - this.setFont(value[0], value[1]); - break; - case 'CA': - this.current.strokeAlpha = state[1]; - break; - case 'ca': - this.current.fillAlpha = state[1]; - this.ctx.globalAlpha = state[1]; - break; - case 'BM': - if (value && value.name && value.name !== 'Normal') { - var mode = value.name.replace(/([A-Z])/g, function (c) { - return '-' + c.toLowerCase(); - }).substring(1); - this.ctx.globalCompositeOperation = mode; - if (this.ctx.globalCompositeOperation !== mode) { - warn('globalCompositeOperation "' + mode + '" is not supported'); - } - } else { - this.ctx.globalCompositeOperation = 'source-over'; - } - break; - case 'SMask': - if (this.current.activeSMask) { - if (this.stateStack.length > 0 && this.stateStack[this.stateStack.length - 1].activeSMask === this.current.activeSMask) { - this.suspendSMaskGroup(); - } else { - this.endSMaskGroup(); - } - } - this.current.activeSMask = value ? this.tempSMask : null; - if (this.current.activeSMask) { - this.beginSMaskGroup(); - } - this.tempSMask = null; - break; - } - } - }, - beginSMaskGroup: function CanvasGraphics_beginSMaskGroup() { - var activeSMask = this.current.activeSMask; - var drawnWidth = activeSMask.canvas.width; - var drawnHeight = activeSMask.canvas.height; - var cacheId = 'smaskGroupAt' + this.groupLevel; - var scratchCanvas = this.cachedCanvases.getCanvas(cacheId, drawnWidth, drawnHeight, true); - var currentCtx = this.ctx; - var currentTransform = currentCtx.mozCurrentTransform; - this.ctx.save(); - var groupCtx = scratchCanvas.context; - groupCtx.scale(1 / activeSMask.scaleX, 1 / activeSMask.scaleY); - groupCtx.translate(-activeSMask.offsetX, -activeSMask.offsetY); - groupCtx.transform.apply(groupCtx, currentTransform); - activeSMask.startTransformInverse = groupCtx.mozCurrentTransformInverse; - copyCtxState(currentCtx, groupCtx); - this.ctx = groupCtx; - this.setGState([['BM', 'Normal'], ['ca', 1], ['CA', 1]]); - this.groupStack.push(currentCtx); - this.groupLevel++; - }, - suspendSMaskGroup: function CanvasGraphics_endSMaskGroup() { - var groupCtx = this.ctx; - this.groupLevel--; - this.ctx = this.groupStack.pop(); - composeSMask(this.ctx, this.current.activeSMask, groupCtx); - this.ctx.restore(); - this.ctx.save(); - copyCtxState(groupCtx, this.ctx); - this.current.resumeSMaskCtx = groupCtx; - var deltaTransform = Util.transform(this.current.activeSMask.startTransformInverse, groupCtx.mozCurrentTransform); - this.ctx.transform.apply(this.ctx, deltaTransform); - groupCtx.save(); - groupCtx.setTransform(1, 0, 0, 1, 0, 0); - groupCtx.clearRect(0, 0, groupCtx.canvas.width, groupCtx.canvas.height); - groupCtx.restore(); - }, - resumeSMaskGroup: function CanvasGraphics_endSMaskGroup() { - var groupCtx = this.current.resumeSMaskCtx; - var currentCtx = this.ctx; - this.ctx = groupCtx; - this.groupStack.push(currentCtx); - this.groupLevel++; - }, - endSMaskGroup: function CanvasGraphics_endSMaskGroup() { - var groupCtx = this.ctx; - this.groupLevel--; - this.ctx = this.groupStack.pop(); - composeSMask(this.ctx, this.current.activeSMask, groupCtx); - this.ctx.restore(); - copyCtxState(groupCtx, this.ctx); - var deltaTransform = Util.transform(this.current.activeSMask.startTransformInverse, groupCtx.mozCurrentTransform); - this.ctx.transform.apply(this.ctx, deltaTransform); - }, - save: function CanvasGraphics_save() { - this.ctx.save(); - var old = this.current; - this.stateStack.push(old); - this.current = old.clone(); - this.current.resumeSMaskCtx = null; + get port() { + return this._port; }, - restore: function CanvasGraphics_restore() { - if (this.current.resumeSMaskCtx) { - this.resumeSMaskGroup(); - } - if (this.current.activeSMask !== null && (this.stateStack.length === 0 || this.stateStack[this.stateStack.length - 1].activeSMask !== this.current.activeSMask)) { - this.endSMaskGroup(); - } - if (this.stateStack.length !== 0) { - this.current = this.stateStack.pop(); - this.ctx.restore(); - this.pendingClip = null; - this.cachedGetSinglePixelWidth = null; + set port(value) { + if (this._isInvalid || !this._isRelative) { + return; } + parse.call(this, value, 'port'); }, - transform: function CanvasGraphics_transform(a, b, c, d, e, f) { - this.ctx.transform(a, b, c, d, e, f); - this.cachedGetSinglePixelWidth = null; + get pathname() { + return this._isInvalid ? '' : this._isRelative ? '/' + this._path.join('/') : this._schemeData; }, - constructPath: function CanvasGraphics_constructPath(ops, args) { - var ctx = this.ctx; - var current = this.current; - var x = current.x, - y = current.y; - for (var i = 0, j = 0, ii = ops.length; i < ii; i++) { - switch (ops[i] | 0) { - case OPS.rectangle: - x = args[j++]; - y = args[j++]; - var width = args[j++]; - var height = args[j++]; - if (width === 0) { - width = this.getSinglePixelWidth(); - } - if (height === 0) { - height = this.getSinglePixelWidth(); - } - var xw = x + width; - var yh = y + height; - this.ctx.moveTo(x, y); - this.ctx.lineTo(xw, y); - this.ctx.lineTo(xw, yh); - this.ctx.lineTo(x, yh); - this.ctx.lineTo(x, y); - this.ctx.closePath(); - break; - case OPS.moveTo: - x = args[j++]; - y = args[j++]; - ctx.moveTo(x, y); - break; - case OPS.lineTo: - x = args[j++]; - y = args[j++]; - ctx.lineTo(x, y); - break; - case OPS.curveTo: - x = args[j + 4]; - y = args[j + 5]; - ctx.bezierCurveTo(args[j], args[j + 1], args[j + 2], args[j + 3], x, y); - j += 6; - break; - case OPS.curveTo2: - ctx.bezierCurveTo(x, y, args[j], args[j + 1], args[j + 2], args[j + 3]); - x = args[j + 2]; - y = args[j + 3]; - j += 4; - break; - case OPS.curveTo3: - x = args[j + 2]; - y = args[j + 3]; - ctx.bezierCurveTo(args[j], args[j + 1], x, y, x, y); - j += 4; - break; - case OPS.closePath: - ctx.closePath(); - break; - } + set pathname(value) { + if (this._isInvalid || !this._isRelative) { + return; } - current.setCurrentPoint(x, y); + this._path = []; + parse.call(this, value, 'relative path start'); }, - closePath: function CanvasGraphics_closePath() { - this.ctx.closePath(); + get search() { + return this._isInvalid || !this._query || this._query === '?' ? '' : this._query; }, - stroke: function CanvasGraphics_stroke(consumePath) { - consumePath = typeof consumePath !== 'undefined' ? consumePath : true; - var ctx = this.ctx; - var strokeColor = this.current.strokeColor; - ctx.lineWidth = Math.max(this.getSinglePixelWidth() * MIN_WIDTH_FACTOR, this.current.lineWidth); - ctx.globalAlpha = this.current.strokeAlpha; - if (strokeColor && strokeColor.hasOwnProperty('type') && strokeColor.type === 'Pattern') { - ctx.save(); - ctx.strokeStyle = strokeColor.getPattern(ctx, this); - ctx.stroke(); - ctx.restore(); - } else { - ctx.stroke(); + set search(value) { + if (this._isInvalid || !this._isRelative) { + return; } - if (consumePath) { - this.consumePath(); + this._query = '?'; + if (value[0] === '?') { + value = value.slice(1); } - ctx.globalAlpha = this.current.fillAlpha; + parse.call(this, value, 'query'); }, - closeStroke: function CanvasGraphics_closeStroke() { - this.closePath(); - this.stroke(); + get hash() { + return this._isInvalid || !this._fragment || this._fragment === '#' ? '' : this._fragment; }, - fill: function CanvasGraphics_fill(consumePath) { - consumePath = typeof consumePath !== 'undefined' ? consumePath : true; - var ctx = this.ctx; - var fillColor = this.current.fillColor; - var isPatternFill = this.current.patternFill; - var needRestore = false; - if (isPatternFill) { - ctx.save(); - if (this.baseTransform) { - ctx.setTransform.apply(ctx, this.baseTransform); - } - ctx.fillStyle = fillColor.getPattern(ctx, this); - needRestore = true; + set hash(value) { + if (this._isInvalid) { + return; } - if (this.pendingEOFill) { - ctx.fill('evenodd'); - this.pendingEOFill = false; - } else { - ctx.fill(); + this._fragment = '#'; + if (value[0] === '#') { + value = value.slice(1); } - if (needRestore) { - ctx.restore(); + parse.call(this, value, 'fragment'); + }, + get origin() { + var host; + if (this._isInvalid || !this._scheme) { + return ''; + } + switch (this._scheme) { + case 'data': + case 'file': + case 'javascript': + case 'mailto': + return 'null'; + case 'blob': + try { + return new JURL(this._schemeData).origin || 'null'; + } catch (_) {} + return 'null'; } - if (consumePath) { - this.consumePath(); + host = this.host; + if (!host) { + return ''; } - }, - eoFill: function CanvasGraphics_eoFill() { - this.pendingEOFill = true; - this.fill(); - }, - fillStroke: function CanvasGraphics_fillStroke() { - this.fill(false); - this.stroke(false); - this.consumePath(); - }, - eoFillStroke: function CanvasGraphics_eoFillStroke() { - this.pendingEOFill = true; - this.fillStroke(); - }, - closeFillStroke: function CanvasGraphics_closeFillStroke() { - this.closePath(); - this.fillStroke(); - }, - closeEOFillStroke: function CanvasGraphics_closeEOFillStroke() { - this.pendingEOFill = true; - this.closePath(); - this.fillStroke(); - }, - endPath: function CanvasGraphics_endPath() { - this.consumePath(); - }, - clip: function CanvasGraphics_clip() { - this.pendingClip = NORMAL_CLIP; - }, - eoClip: function CanvasGraphics_eoClip() { - this.pendingClip = EO_CLIP; - }, - beginText: function CanvasGraphics_beginText() { - this.current.textMatrix = IDENTITY_MATRIX; - this.current.textMatrixScale = 1; - this.current.x = this.current.lineX = 0; - this.current.y = this.current.lineY = 0; - }, - endText: function CanvasGraphics_endText() { - var paths = this.pendingTextPaths; - var ctx = this.ctx; - if (paths === undefined) { - ctx.beginPath(); - return; - } - ctx.save(); - ctx.beginPath(); - for (var i = 0; i < paths.length; i++) { - var path = paths[i]; - ctx.setTransform.apply(ctx, path.transform); - ctx.translate(path.x, path.y); - path.addToPath(ctx, path.fontSize); - } - ctx.restore(); - ctx.clip(); - ctx.beginPath(); - delete this.pendingTextPaths; - }, - setCharSpacing: function CanvasGraphics_setCharSpacing(spacing) { - this.current.charSpacing = spacing; - }, - setWordSpacing: function CanvasGraphics_setWordSpacing(spacing) { - this.current.wordSpacing = spacing; - }, - setHScale: function CanvasGraphics_setHScale(scale) { - this.current.textHScale = scale / 100; - }, - setLeading: function CanvasGraphics_setLeading(leading) { - this.current.leading = -leading; - }, - setFont: function CanvasGraphics_setFont(fontRefName, size) { - var fontObj = this.commonObjs.get(fontRefName); - var current = this.current; - if (!fontObj) { - error('Can\'t find font for ' + fontRefName); - } - current.fontMatrix = fontObj.fontMatrix ? fontObj.fontMatrix : FONT_IDENTITY_MATRIX; - if (current.fontMatrix[0] === 0 || current.fontMatrix[3] === 0) { - warn('Invalid font matrix for font ' + fontRefName); - } - if (size < 0) { - size = -size; - current.fontDirection = -1; - } else { - current.fontDirection = 1; - } - this.current.font = fontObj; - this.current.fontSize = size; - if (fontObj.isType3Font) { - return; - } - var name = fontObj.loadedName || 'sans-serif'; - var bold = fontObj.black ? '900' : fontObj.bold ? 'bold' : 'normal'; - var italic = fontObj.italic ? 'italic' : 'normal'; - var typeface = '"' + name + '", ' + fontObj.fallbackName; - var browserFontSize = size < MIN_FONT_SIZE ? MIN_FONT_SIZE : size > MAX_FONT_SIZE ? MAX_FONT_SIZE : size; - this.current.fontSizeScale = size / browserFontSize; - var rule = italic + ' ' + bold + ' ' + browserFontSize + 'px ' + typeface; - this.ctx.font = rule; - }, - setTextRenderingMode: function CanvasGraphics_setTextRenderingMode(mode) { - this.current.textRenderingMode = mode; - }, - setTextRise: function CanvasGraphics_setTextRise(rise) { - this.current.textRise = rise; - }, - moveText: function CanvasGraphics_moveText(x, y) { - this.current.x = this.current.lineX += x; - this.current.y = this.current.lineY += y; - }, - setLeadingMoveText: function CanvasGraphics_setLeadingMoveText(x, y) { - this.setLeading(-y); - this.moveText(x, y); - }, - setTextMatrix: function CanvasGraphics_setTextMatrix(a, b, c, d, e, f) { - this.current.textMatrix = [a, b, c, d, e, f]; - this.current.textMatrixScale = Math.sqrt(a * a + b * b); - this.current.x = this.current.lineX = 0; - this.current.y = this.current.lineY = 0; - }, - nextLine: function CanvasGraphics_nextLine() { - this.moveText(0, this.current.leading); - }, - paintChar: function CanvasGraphics_paintChar(character, x, y) { - var ctx = this.ctx; - var current = this.current; - var font = current.font; - var textRenderingMode = current.textRenderingMode; - var fontSize = current.fontSize / current.fontSizeScale; - var fillStrokeMode = textRenderingMode & TextRenderingMode.FILL_STROKE_MASK; - var isAddToPathSet = !!(textRenderingMode & TextRenderingMode.ADD_TO_PATH_FLAG); - var addToPath; - if (font.disableFontFace || isAddToPathSet) { - addToPath = font.getPathGenerator(this.commonObjs, character); - } - if (font.disableFontFace) { - ctx.save(); - ctx.translate(x, y); - ctx.beginPath(); - addToPath(ctx, fontSize); - if (fillStrokeMode === TextRenderingMode.FILL || fillStrokeMode === TextRenderingMode.FILL_STROKE) { - ctx.fill(); + return this._scheme + '://' + host; + } + }; + exports.URL = JURL; +})(); + +/***/ }), +/* 129 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.build = exports.version = exports.setPDFNetworkStreamFactory = exports.PDFPageProxy = exports.PDFDocumentProxy = exports.PDFWorker = exports.PDFDataRangeTransport = exports.LoopbackPort = exports.getDocument = undefined; + +var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); + +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + +var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; + +var _util = __w_pdfjs_require__(1); + +var _dom_utils = __w_pdfjs_require__(130); + +var _font_loader = __w_pdfjs_require__(131); + +var _api_compatibility = __w_pdfjs_require__(132); + +var _canvas = __w_pdfjs_require__(133); + +var _global_scope = __w_pdfjs_require__(3); + +var _global_scope2 = _interopRequireDefault(_global_scope); + +var _worker_options = __w_pdfjs_require__(135); + +var _message_handler = __w_pdfjs_require__(136); + +var _metadata = __w_pdfjs_require__(141); + +var _transport_stream = __w_pdfjs_require__(143); + +var _webgl = __w_pdfjs_require__(144); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var DEFAULT_RANGE_CHUNK_SIZE = 65536; +var isWorkerDisabled = false; +var fallbackWorkerSrc = void 0; +var fakeWorkerFilesLoader = null; +{ + var useRequireEnsure = false; + if (typeof window === 'undefined') { + isWorkerDisabled = true; + if (typeof require.ensure === 'undefined') { + require.ensure = require('node-ensure'); + } + useRequireEnsure = true; + } else if (typeof require !== 'undefined' && typeof require.ensure === 'function') { + useRequireEnsure = true; + } + if (typeof requirejs !== 'undefined' && requirejs.toUrl) { + fallbackWorkerSrc = requirejs.toUrl('pdfjs-dist/build/pdf.worker.js'); + } + var dynamicLoaderSupported = typeof requirejs !== 'undefined' && requirejs.load; + fakeWorkerFilesLoader = useRequireEnsure ? function () { + return new Promise(function (resolve, reject) { + require.ensure([], function () { + try { + var worker = void 0; + worker = require('./pdf.worker.js'); + resolve(worker.WorkerMessageHandler); + } catch (ex) { + reject(ex); } - if (fillStrokeMode === TextRenderingMode.STROKE || fillStrokeMode === TextRenderingMode.FILL_STROKE) { - ctx.stroke(); + }, reject, 'pdfjsWorker'); + }); + } : dynamicLoaderSupported ? function () { + return new Promise(function (resolve, reject) { + requirejs(['pdfjs-dist/build/pdf.worker'], function (worker) { + try { + resolve(worker.WorkerMessageHandler); + } catch (ex) { + reject(ex); } - ctx.restore(); + }, reject); + }); + } : null; + if (!fallbackWorkerSrc && typeof document !== 'undefined') { + var pdfjsFilePath = document.currentScript && document.currentScript.src; + if (pdfjsFilePath) { + fallbackWorkerSrc = pdfjsFilePath.replace(/(\.(?:min\.)?js)(\?.*)?$/i, '.worker$1$2'); + } + } +} +var createPDFNetworkStream; +function setPDFNetworkStreamFactory(pdfNetworkStreamFactory) { + createPDFNetworkStream = pdfNetworkStreamFactory; +} +function getDocument(src) { + var task = new PDFDocumentLoadingTask(); + var source; + if (typeof src === 'string') { + source = { url: src }; + } else if ((0, _util.isArrayBuffer)(src)) { + source = { data: src }; + } else if (src instanceof PDFDataRangeTransport) { + source = { range: src }; + } else { + if ((typeof src === 'undefined' ? 'undefined' : _typeof(src)) !== 'object') { + throw new Error('Invalid parameter in getDocument, ' + 'need either Uint8Array, string or a parameter object'); + } + if (!src.url && !src.data && !src.range) { + throw new Error('Invalid parameter object: need either .data, .range or .url'); + } + source = src; + } + var params = Object.create(null); + var rangeTransport = null; + var worker = null; + for (var key in source) { + if (key === 'url' && typeof window !== 'undefined') { + params[key] = new _util.URL(source[key], window.location).href; + continue; + } else if (key === 'range') { + rangeTransport = source[key]; + continue; + } else if (key === 'worker') { + worker = source[key]; + continue; + } else if (key === 'data' && !(source[key] instanceof Uint8Array)) { + var pdfBytes = source[key]; + if (typeof pdfBytes === 'string') { + params[key] = (0, _util.stringToBytes)(pdfBytes); + } else if ((typeof pdfBytes === 'undefined' ? 'undefined' : _typeof(pdfBytes)) === 'object' && pdfBytes !== null && !isNaN(pdfBytes.length)) { + params[key] = new Uint8Array(pdfBytes); + } else if ((0, _util.isArrayBuffer)(pdfBytes)) { + params[key] = new Uint8Array(pdfBytes); } else { - if (fillStrokeMode === TextRenderingMode.FILL || fillStrokeMode === TextRenderingMode.FILL_STROKE) { - ctx.fillText(character, x, y); - } - if (fillStrokeMode === TextRenderingMode.STROKE || fillStrokeMode === TextRenderingMode.FILL_STROKE) { - ctx.strokeText(character, x, y); - } + throw new Error('Invalid PDF binary data: either typed array, ' + 'string or array-like object is expected in the ' + 'data property.'); } - if (isAddToPathSet) { - var paths = this.pendingTextPaths || (this.pendingTextPaths = []); - paths.push({ - transform: ctx.mozCurrentTransform, - x: x, - y: y, - fontSize: fontSize, - addToPath: addToPath - }); + continue; + } + params[key] = source[key]; + } + params.rangeChunkSize = params.rangeChunkSize || DEFAULT_RANGE_CHUNK_SIZE; + params.CMapReaderFactory = params.CMapReaderFactory || _dom_utils.DOMCMapReaderFactory; + params.ignoreErrors = params.stopAtErrors !== true; + params.pdfBug = params.pdfBug === true; + var NativeImageDecoderValues = Object.values(_util.NativeImageDecoding); + if (params.nativeImageDecoderSupport === undefined || !NativeImageDecoderValues.includes(params.nativeImageDecoderSupport)) { + params.nativeImageDecoderSupport = _api_compatibility.apiCompatibilityParams.nativeImageDecoderSupport || _util.NativeImageDecoding.DECODE; + } + if (!Number.isInteger(params.maxImageSize)) { + params.maxImageSize = -1; + } + if (typeof params.isEvalSupported !== 'boolean') { + params.isEvalSupported = true; + } + if (typeof params.disableFontFace !== 'boolean') { + params.disableFontFace = _api_compatibility.apiCompatibilityParams.disableFontFace || false; + } + if (typeof params.disableRange !== 'boolean') { + params.disableRange = false; + } + if (typeof params.disableStream !== 'boolean') { + params.disableStream = false; + } + if (typeof params.disableAutoFetch !== 'boolean') { + params.disableAutoFetch = false; + } + if (typeof params.disableCreateObjectURL !== 'boolean') { + params.disableCreateObjectURL = _api_compatibility.apiCompatibilityParams.disableCreateObjectURL || false; + } + (0, _util.setVerbosityLevel)(params.verbosity); + if (!worker) { + var workerParams = { + postMessageTransfers: params.postMessageTransfers, + verbosity: params.verbosity + }; + var workerPort = _worker_options.GlobalWorkerOptions.workerPort; + if (workerPort) { + workerParams.port = workerPort; + worker = PDFWorker.fromPort(workerParams); + } else { + worker = new PDFWorker(workerParams); + } + task._worker = worker; + } + var docId = task.docId; + worker.promise.then(function () { + if (task.destroyed) { + throw new Error('Loading aborted'); + } + return _fetchDocument(worker, params, rangeTransport, docId).then(function (workerId) { + if (task.destroyed) { + throw new Error('Loading aborted'); } - }, - get isFontSubpixelAAEnabled() { - var ctx = this.canvasFactory.create(10, 10).context; - ctx.scale(1.5, 1); - ctx.fillText('I', 0, 10); - var data = ctx.getImageData(0, 0, 10, 10).data; - var enabled = false; - for (var i = 3; i < data.length; i += 4) { - if (data[i] > 0 && data[i] < 255) { - enabled = true; - break; - } + var networkStream = void 0; + if (rangeTransport) { + networkStream = new _transport_stream.PDFDataTransportStream({ + length: params.length, + initialData: params.initialData, + disableRange: params.disableRange, + disableStream: params.disableStream + }, rangeTransport); + } else if (!params.data) { + networkStream = createPDFNetworkStream({ + url: params.url, + length: params.length, + httpHeaders: params.httpHeaders, + withCredentials: params.withCredentials, + rangeChunkSize: params.rangeChunkSize, + disableRange: params.disableRange, + disableStream: params.disableStream + }); } - return shadow(this, 'isFontSubpixelAAEnabled', enabled); - }, - showText: function CanvasGraphics_showText(glyphs) { - var current = this.current; - var font = current.font; - if (font.isType3Font) { - return this.showType3Text(glyphs); + var messageHandler = new _message_handler.MessageHandler(docId, workerId, worker.port); + messageHandler.postMessageTransfers = worker.postMessageTransfers; + var transport = new WorkerTransport(messageHandler, task, networkStream, params); + task._transport = transport; + messageHandler.send('Ready', null); + }); + }).catch(task._capability.reject); + return task; +} +function _fetchDocument(worker, source, pdfDataRangeTransport, docId) { + if (worker.destroyed) { + return Promise.reject(new Error('Worker was destroyed')); + } + if (pdfDataRangeTransport) { + source.length = pdfDataRangeTransport.length; + source.initialData = pdfDataRangeTransport.initialData; + } + return worker.messageHandler.sendWithPromise('GetDocRequest', { + docId: docId, + apiVersion: '2.0.943', + source: { + data: source.data, + url: source.url, + password: source.password, + disableAutoFetch: source.disableAutoFetch, + rangeChunkSize: source.rangeChunkSize, + length: source.length + }, + maxImageSize: source.maxImageSize, + disableFontFace: source.disableFontFace, + disableCreateObjectURL: source.disableCreateObjectURL, + postMessageTransfers: worker.postMessageTransfers, + docBaseUrl: source.docBaseUrl, + nativeImageDecoderSupport: source.nativeImageDecoderSupport, + ignoreErrors: source.ignoreErrors, + isEvalSupported: source.isEvalSupported + }).then(function (workerId) { + if (worker.destroyed) { + throw new Error('Worker was destroyed'); + } + return workerId; + }); +} +var PDFDocumentLoadingTask = function PDFDocumentLoadingTaskClosure() { + var nextDocumentId = 0; + function PDFDocumentLoadingTask() { + this._capability = (0, _util.createPromiseCapability)(); + this._transport = null; + this._worker = null; + this.docId = 'd' + nextDocumentId++; + this.destroyed = false; + this.onPassword = null; + this.onProgress = null; + this.onUnsupportedFeature = null; + } + PDFDocumentLoadingTask.prototype = { + get promise() { + return this._capability.promise; + }, + destroy: function destroy() { + var _this = this; + + this.destroyed = true; + var transportDestroyed = !this._transport ? Promise.resolve() : this._transport.destroy(); + return transportDestroyed.then(function () { + _this._transport = null; + if (_this._worker) { + _this._worker.destroy(); + _this._worker = null; + } + }); + }, + + then: function PDFDocumentLoadingTask_then(onFulfilled, onRejected) { + return this.promise.then.apply(this.promise, arguments); + } + }; + return PDFDocumentLoadingTask; +}(); + +var PDFDataRangeTransport = function () { + function PDFDataRangeTransport(length, initialData) { + _classCallCheck(this, PDFDataRangeTransport); + + this.length = length; + this.initialData = initialData; + this._rangeListeners = []; + this._progressListeners = []; + this._progressiveReadListeners = []; + this._readyCapability = (0, _util.createPromiseCapability)(); + } + + _createClass(PDFDataRangeTransport, [{ + key: 'addRangeListener', + value: function addRangeListener(listener) { + this._rangeListeners.push(listener); + } + }, { + key: 'addProgressListener', + value: function addProgressListener(listener) { + this._progressListeners.push(listener); + } + }, { + key: 'addProgressiveReadListener', + value: function addProgressiveReadListener(listener) { + this._progressiveReadListeners.push(listener); + } + }, { + key: 'onDataRange', + value: function onDataRange(begin, chunk) { + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; + + try { + for (var _iterator = this._rangeListeners[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var listener = _step.value; + + listener(begin, chunk); + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally { + try { + if (!_iteratorNormalCompletion && _iterator.return) { + _iterator.return(); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } + } } - var fontSize = current.fontSize; - if (fontSize === 0) { - return; + } + }, { + key: 'onDataProgress', + value: function onDataProgress(loaded) { + var _this2 = this; + + this._readyCapability.promise.then(function () { + var _iteratorNormalCompletion2 = true; + var _didIteratorError2 = false; + var _iteratorError2 = undefined; + + try { + for (var _iterator2 = _this2._progressListeners[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { + var listener = _step2.value; + + listener(loaded); + } + } catch (err) { + _didIteratorError2 = true; + _iteratorError2 = err; + } finally { + try { + if (!_iteratorNormalCompletion2 && _iterator2.return) { + _iterator2.return(); + } + } finally { + if (_didIteratorError2) { + throw _iteratorError2; + } + } + } + }); + } + }, { + key: 'onDataProgressiveRead', + value: function onDataProgressiveRead(chunk) { + var _this3 = this; + + this._readyCapability.promise.then(function () { + var _iteratorNormalCompletion3 = true; + var _didIteratorError3 = false; + var _iteratorError3 = undefined; + + try { + for (var _iterator3 = _this3._progressiveReadListeners[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { + var listener = _step3.value; + + listener(chunk); + } + } catch (err) { + _didIteratorError3 = true; + _iteratorError3 = err; + } finally { + try { + if (!_iteratorNormalCompletion3 && _iterator3.return) { + _iterator3.return(); + } + } finally { + if (_didIteratorError3) { + throw _iteratorError3; + } + } + } + }); + } + }, { + key: 'transportReady', + value: function transportReady() { + this._readyCapability.resolve(); + } + }, { + key: 'requestDataRange', + value: function requestDataRange(begin, end) { + (0, _util.unreachable)('Abstract method PDFDataRangeTransport.requestDataRange'); + } + }, { + key: 'abort', + value: function abort() {} + }]); + + return PDFDataRangeTransport; +}(); + +var PDFDocumentProxy = function () { + function PDFDocumentProxy(pdfInfo, transport, loadingTask) { + _classCallCheck(this, PDFDocumentProxy); + + this.loadingTask = loadingTask; + this._pdfInfo = pdfInfo; + this._transport = transport; + } + + _createClass(PDFDocumentProxy, [{ + key: 'getPage', + value: function getPage(pageNumber) { + return this._transport.getPage(pageNumber); + } + }, { + key: 'getPageIndex', + value: function getPageIndex(ref) { + return this._transport.getPageIndex(ref); + } + }, { + key: 'getDestinations', + value: function getDestinations() { + return this._transport.getDestinations(); + } + }, { + key: 'getDestination', + value: function getDestination(id) { + return this._transport.getDestination(id); + } + }, { + key: 'getPageLabels', + value: function getPageLabels() { + return this._transport.getPageLabels(); + } + }, { + key: 'getPageMode', + value: function getPageMode() { + return this._transport.getPageMode(); + } + }, { + key: 'getAttachments', + value: function getAttachments() { + return this._transport.getAttachments(); + } + }, { + key: 'getJavaScript', + value: function getJavaScript() { + return this._transport.getJavaScript(); + } + }, { + key: 'getOutline', + value: function getOutline() { + return this._transport.getOutline(); + } + }, { + key: 'getPermissions', + value: function getPermissions() { + return this._transport.getPermissions(); + } + }, { + key: 'getMetadata', + value: function getMetadata() { + return this._transport.getMetadata(); + } + }, { + key: 'getData', + value: function getData() { + return this._transport.getData(); + } + }, { + key: 'getDownloadInfo', + value: function getDownloadInfo() { + return this._transport.downloadInfoCapability.promise; + } + }, { + key: 'getStats', + value: function getStats() { + return this._transport.getStats(); + } + }, { + key: 'cleanup', + value: function cleanup() { + this._transport.startCleanup(); + } + }, { + key: 'destroy', + value: function destroy() { + return this.loadingTask.destroy(); + } + }, { + key: 'numPages', + get: function get() { + return this._pdfInfo.numPages; + } + }, { + key: 'fingerprint', + get: function get() { + return this._pdfInfo.fingerprint; + } + }, { + key: 'loadingParams', + get: function get() { + return this._transport.loadingParams; + } + }]); + + return PDFDocumentProxy; +}(); + +var PDFPageProxy = function PDFPageProxyClosure() { + function PDFPageProxy(pageIndex, pageInfo, transport) { + var pdfBug = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false; + + this.pageIndex = pageIndex; + this._pageInfo = pageInfo; + this.transport = transport; + this._stats = pdfBug ? new _dom_utils.StatTimer() : _dom_utils.DummyStatTimer; + this._pdfBug = pdfBug; + this.commonObjs = transport.commonObjs; + this.objs = new PDFObjects(); + this.cleanupAfterRender = false; + this.pendingCleanup = false; + this.intentStates = Object.create(null); + this.destroyed = false; + } + PDFPageProxy.prototype = { + get pageNumber() { + return this.pageIndex + 1; + }, + get rotate() { + return this._pageInfo.rotate; + }, + get ref() { + return this._pageInfo.ref; + }, + get userUnit() { + return this._pageInfo.userUnit; + }, + get view() { + return this._pageInfo.view; + }, + getViewport: function getViewport(scale) { + var rotate = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.rotate; + var dontFlip = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; + + return new _dom_utils.PageViewport({ + viewBox: this.view, + scale: scale, + rotation: rotate, + dontFlip: dontFlip + }); + }, + + getAnnotations: function PDFPageProxy_getAnnotations(params) { + var intent = params && params.intent || null; + if (!this.annotationsPromise || this.annotationsIntent !== intent) { + this.annotationsPromise = this.transport.getAnnotations(this.pageIndex, intent); + this.annotationsIntent = intent; } - var ctx = this.ctx; - var fontSizeScale = current.fontSizeScale; - var charSpacing = current.charSpacing; - var wordSpacing = current.wordSpacing; - var fontDirection = current.fontDirection; - var textHScale = current.textHScale * fontDirection; - var glyphsLength = glyphs.length; - var vertical = font.vertical; - var spacingDir = vertical ? 1 : -1; - var defaultVMetrics = font.defaultVMetrics; - var widthAdvanceScale = fontSize * current.fontMatrix[0]; - var simpleFillText = current.textRenderingMode === TextRenderingMode.FILL && !font.disableFontFace; - ctx.save(); - ctx.transform.apply(ctx, current.textMatrix); - ctx.translate(current.x, current.y + current.textRise); - if (current.patternFill) { - ctx.fillStyle = current.fillColor.getPattern(ctx, this); + return this.annotationsPromise; + }, + render: function PDFPageProxy_render(params) { + var _this4 = this; + + var stats = this._stats; + stats.time('Overall'); + this.pendingCleanup = false; + var renderingIntent = params.intent === 'print' ? 'print' : 'display'; + var canvasFactory = params.canvasFactory || new _dom_utils.DOMCanvasFactory(); + var webGLContext = new _webgl.WebGLContext({ enable: params.enableWebGL }); + if (!this.intentStates[renderingIntent]) { + this.intentStates[renderingIntent] = Object.create(null); } - if (fontDirection > 0) { - ctx.scale(textHScale, -1); - } else { - ctx.scale(textHScale, 1); + var intentState = this.intentStates[renderingIntent]; + if (!intentState.displayReadyCapability) { + intentState.receivingOperatorList = true; + intentState.displayReadyCapability = (0, _util.createPromiseCapability)(); + intentState.operatorList = { + fnArray: [], + argsArray: [], + lastChunk: false + }; + stats.time('Page Request'); + this.transport.messageHandler.send('RenderPageRequest', { + pageIndex: this.pageNumber - 1, + intent: renderingIntent, + renderInteractiveForms: params.renderInteractiveForms === true + }); } - var lineWidth = current.lineWidth; - var scale = current.textMatrixScale; - if (scale === 0 || lineWidth === 0) { - var fillStrokeMode = current.textRenderingMode & TextRenderingMode.FILL_STROKE_MASK; - if (fillStrokeMode === TextRenderingMode.STROKE || fillStrokeMode === TextRenderingMode.FILL_STROKE) { - this.cachedGetSinglePixelWidth = null; - lineWidth = this.getSinglePixelWidth() * MIN_WIDTH_FACTOR; + var complete = function complete(error) { + var i = intentState.renderTasks.indexOf(internalRenderTask); + if (i >= 0) { + intentState.renderTasks.splice(i, 1); } - } else { - lineWidth /= scale; - } - if (fontSizeScale !== 1.0) { - ctx.scale(fontSizeScale, fontSizeScale); - lineWidth /= fontSizeScale; - } - ctx.lineWidth = lineWidth; - var x = 0, - i; - for (i = 0; i < glyphsLength; ++i) { - var glyph = glyphs[i]; - if (isNum(glyph)) { - x += spacingDir * glyph * fontSize / 1000; - continue; + if (_this4.cleanupAfterRender) { + _this4.pendingCleanup = true; } - var restoreNeeded = false; - var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing; - var character = glyph.fontChar; - var accent = glyph.accent; - var scaledX, scaledY, scaledAccentX, scaledAccentY; - var width = glyph.width; - if (vertical) { - var vmetric, vx, vy; - vmetric = glyph.vmetric || defaultVMetrics; - vx = glyph.vmetric ? vmetric[1] : width * 0.5; - vx = -vx * widthAdvanceScale; - vy = vmetric[2] * widthAdvanceScale; - width = vmetric ? -vmetric[0] : width; - scaledX = vx / fontSizeScale; - scaledY = (x + vy) / fontSizeScale; + _this4._tryCleanup(); + if (error) { + internalRenderTask.capability.reject(error); } else { - scaledX = x / fontSizeScale; - scaledY = 0; + internalRenderTask.capability.resolve(); } - if (font.remeasure && width > 0) { - var measuredWidth = ctx.measureText(character).width * 1000 / fontSize * fontSizeScale; - if (width < measuredWidth && this.isFontSubpixelAAEnabled) { - var characterScaleX = width / measuredWidth; - restoreNeeded = true; - ctx.save(); - ctx.scale(characterScaleX, 1); - scaledX /= characterScaleX; - } else if (width !== measuredWidth) { - scaledX += (width - measuredWidth) / 2000 * fontSize / fontSizeScale; + stats.timeEnd('Rendering'); + stats.timeEnd('Overall'); + }; + var internalRenderTask = new InternalRenderTask(complete, params, this.objs, this.commonObjs, intentState.operatorList, this.pageNumber, canvasFactory, webGLContext, this._pdfBug); + internalRenderTask.useRequestAnimationFrame = renderingIntent !== 'print'; + if (!intentState.renderTasks) { + intentState.renderTasks = []; + } + intentState.renderTasks.push(internalRenderTask); + var renderTask = internalRenderTask.task; + intentState.displayReadyCapability.promise.then(function (transparency) { + if (_this4.pendingCleanup) { + complete(); + return; + } + stats.time('Rendering'); + internalRenderTask.initializeGraphics(transparency); + internalRenderTask.operatorListChanged(); + }).catch(complete); + return renderTask; + }, + getOperatorList: function PDFPageProxy_getOperatorList() { + function operatorListChanged() { + if (intentState.operatorList.lastChunk) { + intentState.opListReadCapability.resolve(intentState.operatorList); + var i = intentState.renderTasks.indexOf(opListTask); + if (i >= 0) { + intentState.renderTasks.splice(i, 1); } } - if (glyph.isInFont || font.missingFile) { - if (simpleFillText && !accent) { - ctx.fillText(character, scaledX, scaledY); + } + var renderingIntent = 'oplist'; + if (!this.intentStates[renderingIntent]) { + this.intentStates[renderingIntent] = Object.create(null); + } + var intentState = this.intentStates[renderingIntent]; + var opListTask; + if (!intentState.opListReadCapability) { + opListTask = {}; + opListTask.operatorListChanged = operatorListChanged; + intentState.receivingOperatorList = true; + intentState.opListReadCapability = (0, _util.createPromiseCapability)(); + intentState.renderTasks = []; + intentState.renderTasks.push(opListTask); + intentState.operatorList = { + fnArray: [], + argsArray: [], + lastChunk: false + }; + this._stats.time('Page Request'); + this.transport.messageHandler.send('RenderPageRequest', { + pageIndex: this.pageIndex, + intent: renderingIntent + }); + } + return intentState.opListReadCapability.promise; + }, + streamTextContent: function streamTextContent() { + var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; + + var TEXT_CONTENT_CHUNK_SIZE = 100; + return this.transport.messageHandler.sendWithStream('GetTextContent', { + pageIndex: this.pageNumber - 1, + normalizeWhitespace: params.normalizeWhitespace === true, + combineTextItems: params.disableCombineTextItems !== true + }, { + highWaterMark: TEXT_CONTENT_CHUNK_SIZE, + size: function size(textContent) { + return textContent.items.length; + } + }); + }, + + getTextContent: function PDFPageProxy_getTextContent(params) { + params = params || {}; + var readableStream = this.streamTextContent(params); + return new Promise(function (resolve, reject) { + function pump() { + reader.read().then(function (_ref) { + var _textContent$items; + + var value = _ref.value, + done = _ref.done; + + if (done) { + resolve(textContent); + return; + } + Object.assign(textContent.styles, value.styles); + (_textContent$items = textContent.items).push.apply(_textContent$items, _toConsumableArray(value.items)); + pump(); + }, reject); + } + var reader = readableStream.getReader(); + var textContent = { + items: [], + styles: Object.create(null) + }; + pump(); + }); + }, + _destroy: function PDFPageProxy_destroy() { + this.destroyed = true; + this.transport.pageCache[this.pageIndex] = null; + var waitOn = []; + Object.keys(this.intentStates).forEach(function (intent) { + if (intent === 'oplist') { + return; + } + var intentState = this.intentStates[intent]; + intentState.renderTasks.forEach(function (renderTask) { + var renderCompleted = renderTask.capability.promise.catch(function () {}); + waitOn.push(renderCompleted); + renderTask.cancel(); + }); + }, this); + this.objs.clear(); + this.annotationsPromise = null; + this.pendingCleanup = false; + return Promise.all(waitOn); + }, + cleanup: function cleanup() { + var resetStats = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; + + this.pendingCleanup = true; + this._tryCleanup(resetStats); + }, + _tryCleanup: function _tryCleanup() { + var resetStats = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; + + if (!this.pendingCleanup || Object.keys(this.intentStates).some(function (intent) { + var intentState = this.intentStates[intent]; + return intentState.renderTasks.length !== 0 || intentState.receivingOperatorList; + }, this)) { + return; + } + Object.keys(this.intentStates).forEach(function (intent) { + delete this.intentStates[intent]; + }, this); + this.objs.clear(); + this.annotationsPromise = null; + if (resetStats && this._stats instanceof _dom_utils.StatTimer) { + this._stats = new _dom_utils.StatTimer(); + } + this.pendingCleanup = false; + }, + + _startRenderPage: function PDFPageProxy_startRenderPage(transparency, intent) { + var intentState = this.intentStates[intent]; + if (intentState.displayReadyCapability) { + intentState.displayReadyCapability.resolve(transparency); + } + }, + _renderPageChunk: function PDFPageProxy_renderPageChunk(operatorListChunk, intent) { + var intentState = this.intentStates[intent]; + var i, ii; + for (i = 0, ii = operatorListChunk.length; i < ii; i++) { + intentState.operatorList.fnArray.push(operatorListChunk.fnArray[i]); + intentState.operatorList.argsArray.push(operatorListChunk.argsArray[i]); + } + intentState.operatorList.lastChunk = operatorListChunk.lastChunk; + for (i = 0; i < intentState.renderTasks.length; i++) { + intentState.renderTasks[i].operatorListChanged(); + } + if (operatorListChunk.lastChunk) { + intentState.receivingOperatorList = false; + this._tryCleanup(); + } + }, + get stats() { + return this._stats instanceof _dom_utils.StatTimer ? this._stats : null; + } + }; + return PDFPageProxy; +}(); + +var LoopbackPort = function () { + function LoopbackPort() { + var defer = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true; + + _classCallCheck(this, LoopbackPort); + + this._listeners = []; + this._defer = defer; + this._deferred = Promise.resolve(undefined); + } + + _createClass(LoopbackPort, [{ + key: 'postMessage', + value: function postMessage(obj, transfers) { + var _this5 = this; + + function cloneValue(value) { + if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) !== 'object' || value === null) { + return value; + } + if (cloned.has(value)) { + return cloned.get(value); + } + var result; + var buffer; + if ((buffer = value.buffer) && (0, _util.isArrayBuffer)(buffer)) { + var transferable = transfers && transfers.includes(buffer); + if (value === buffer) { + result = value; + } else if (transferable) { + result = new value.constructor(buffer, value.byteOffset, value.byteLength); } else { - this.paintChar(character, scaledX, scaledY); - if (accent) { - scaledAccentX = scaledX + accent.offset.x / fontSizeScale; - scaledAccentY = scaledY - accent.offset.y / fontSizeScale; - this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY); + result = new value.constructor(value); + } + cloned.set(value, result); + return result; + } + result = Array.isArray(value) ? [] : {}; + cloned.set(value, result); + for (var i in value) { + var desc, + p = value; + while (!(desc = Object.getOwnPropertyDescriptor(p, i))) { + p = Object.getPrototypeOf(p); + } + if (typeof desc.value === 'undefined' || typeof desc.value === 'function') { + continue; + } + result[i] = cloneValue(desc.value); + } + return result; + } + if (!this._defer) { + this._listeners.forEach(function (listener) { + listener.call(this, { data: obj }); + }, this); + return; + } + var cloned = new WeakMap(); + var e = { data: cloneValue(obj) }; + this._deferred.then(function () { + _this5._listeners.forEach(function (listener) { + listener.call(this, e); + }, _this5); + }); + } + }, { + key: 'addEventListener', + value: function addEventListener(name, listener) { + this._listeners.push(listener); + } + }, { + key: 'removeEventListener', + value: function removeEventListener(name, listener) { + var i = this._listeners.indexOf(listener); + this._listeners.splice(i, 1); + } + }, { + key: 'terminate', + value: function terminate() { + this._listeners = []; + } + }]); + + return LoopbackPort; +}(); + +var PDFWorker = function PDFWorkerClosure() { + var nextFakeWorkerId = 0; + function getWorkerSrc() { + if (_worker_options.GlobalWorkerOptions.workerSrc) { + return _worker_options.GlobalWorkerOptions.workerSrc; + } + if (typeof fallbackWorkerSrc !== 'undefined') { + return fallbackWorkerSrc; + } + throw new Error('No "GlobalWorkerOptions.workerSrc" specified.'); + } + function getMainThreadWorkerMessageHandler() { + try { + if (typeof window !== 'undefined') { + return window.pdfjsWorker && window.pdfjsWorker.WorkerMessageHandler; + } + } catch (ex) {} + return null; + } + var fakeWorkerFilesLoadedCapability = void 0; + function setupFakeWorkerGlobal() { + if (fakeWorkerFilesLoadedCapability) { + return fakeWorkerFilesLoadedCapability.promise; + } + fakeWorkerFilesLoadedCapability = (0, _util.createPromiseCapability)(); + var mainWorkerMessageHandler = getMainThreadWorkerMessageHandler(); + if (mainWorkerMessageHandler) { + fakeWorkerFilesLoadedCapability.resolve(mainWorkerMessageHandler); + return fakeWorkerFilesLoadedCapability.promise; + } + var loader = fakeWorkerFilesLoader || function () { + return (0, _dom_utils.loadScript)(getWorkerSrc()).then(function () { + return window.pdfjsWorker.WorkerMessageHandler; + }); + }; + loader().then(fakeWorkerFilesLoadedCapability.resolve, fakeWorkerFilesLoadedCapability.reject); + return fakeWorkerFilesLoadedCapability.promise; + } + function createCDNWrapper(url) { + var wrapper = 'importScripts(\'' + url + '\');'; + return _util.URL.createObjectURL(new Blob([wrapper])); + } + var pdfWorkerPorts = new WeakMap(); + function PDFWorker() { + var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, + _ref2$name = _ref2.name, + name = _ref2$name === undefined ? null : _ref2$name, + _ref2$port = _ref2.port, + port = _ref2$port === undefined ? null : _ref2$port, + _ref2$postMessageTran = _ref2.postMessageTransfers, + postMessageTransfers = _ref2$postMessageTran === undefined ? true : _ref2$postMessageTran, + _ref2$verbosity = _ref2.verbosity, + verbosity = _ref2$verbosity === undefined ? (0, _util.getVerbosityLevel)() : _ref2$verbosity; + + if (port && pdfWorkerPorts.has(port)) { + throw new Error('Cannot use more than one PDFWorker per port'); + } + this.name = name; + this.destroyed = false; + this.postMessageTransfers = postMessageTransfers !== false; + this.verbosity = verbosity; + this._readyCapability = (0, _util.createPromiseCapability)(); + this._port = null; + this._webWorker = null; + this._messageHandler = null; + if (port) { + pdfWorkerPorts.set(port, this); + this._initializeFromPort(port); + return; + } + this._initialize(); + } + PDFWorker.prototype = { + get promise() { + return this._readyCapability.promise; + }, + get port() { + return this._port; + }, + get messageHandler() { + return this._messageHandler; + }, + _initializeFromPort: function PDFWorker_initializeFromPort(port) { + this._port = port; + this._messageHandler = new _message_handler.MessageHandler('main', 'worker', port); + this._messageHandler.on('ready', function () {}); + this._readyCapability.resolve(); + }, + _initialize: function PDFWorker_initialize() { + var _this6 = this; + + if (typeof Worker !== 'undefined' && !isWorkerDisabled && !getMainThreadWorkerMessageHandler()) { + var workerSrc = getWorkerSrc(); + try { + if (!(0, _util.isSameOrigin)(window.location.href, workerSrc)) { + workerSrc = createCDNWrapper(new _util.URL(workerSrc, window.location).href); + } + var worker = new Worker(workerSrc); + var messageHandler = new _message_handler.MessageHandler('main', 'worker', worker); + var terminateEarly = function terminateEarly() { + worker.removeEventListener('error', onWorkerError); + messageHandler.destroy(); + worker.terminate(); + if (_this6.destroyed) { + _this6._readyCapability.reject(new Error('Worker was destroyed')); + } else { + _this6._setupFakeWorker(); + } + }; + var onWorkerError = function onWorkerError() { + if (!_this6._webWorker) { + terminateEarly(); + } + }; + worker.addEventListener('error', onWorkerError); + messageHandler.on('test', function (data) { + worker.removeEventListener('error', onWorkerError); + if (_this6.destroyed) { + terminateEarly(); + return; + } + if (data && data.supportTypedArray) { + _this6._messageHandler = messageHandler; + _this6._port = worker; + _this6._webWorker = worker; + if (!data.supportTransfers) { + _this6.postMessageTransfers = false; + } + _this6._readyCapability.resolve(); + messageHandler.send('configure', { verbosity: _this6.verbosity }); + } else { + _this6._setupFakeWorker(); + messageHandler.destroy(); + worker.terminate(); + } + }); + messageHandler.on('ready', function (data) { + worker.removeEventListener('error', onWorkerError); + if (_this6.destroyed) { + terminateEarly(); + return; + } + try { + sendTest(); + } catch (e) { + _this6._setupFakeWorker(); + } + }); + var sendTest = function sendTest() { + var testObj = new Uint8Array([_this6.postMessageTransfers ? 255 : 0]); + try { + messageHandler.send('test', testObj, [testObj.buffer]); + } catch (ex) { + (0, _util.info)('Cannot use postMessage transfers'); + testObj[0] = 0; + messageHandler.send('test', testObj); + } + }; + sendTest(); + return; + } catch (e) { + (0, _util.info)('The worker has been disabled.'); + } + } + this._setupFakeWorker(); + }, + _setupFakeWorker: function PDFWorker_setupFakeWorker() { + var _this7 = this; + + if (!isWorkerDisabled) { + (0, _util.warn)('Setting up fake worker.'); + isWorkerDisabled = true; + } + setupFakeWorkerGlobal().then(function (WorkerMessageHandler) { + if (_this7.destroyed) { + _this7._readyCapability.reject(new Error('Worker was destroyed')); + return; + } + var port = new LoopbackPort(); + _this7._port = port; + var id = 'fake' + nextFakeWorkerId++; + var workerHandler = new _message_handler.MessageHandler(id + '_worker', id, port); + WorkerMessageHandler.setup(workerHandler, port); + var messageHandler = new _message_handler.MessageHandler(id, id + '_worker', port); + _this7._messageHandler = messageHandler; + _this7._readyCapability.resolve(); + }).catch(function (reason) { + _this7._readyCapability.reject(new Error('Setting up fake worker failed: "' + reason.message + '".')); + }); + }, + destroy: function PDFWorker_destroy() { + this.destroyed = true; + if (this._webWorker) { + this._webWorker.terminate(); + this._webWorker = null; + } + pdfWorkerPorts.delete(this._port); + this._port = null; + if (this._messageHandler) { + this._messageHandler.destroy(); + this._messageHandler = null; + } + } + }; + PDFWorker.fromPort = function (params) { + if (!params || !params.port) { + throw new Error('PDFWorker.fromPort - invalid method signature.'); + } + if (pdfWorkerPorts.has(params.port)) { + return pdfWorkerPorts.get(params.port); + } + return new PDFWorker(params); + }; + PDFWorker.getWorkerSrc = function () { + return getWorkerSrc(); + }; + return PDFWorker; +}(); + +var WorkerTransport = function () { + function WorkerTransport(messageHandler, loadingTask, networkStream, params) { + _classCallCheck(this, WorkerTransport); + + this.messageHandler = messageHandler; + this.loadingTask = loadingTask; + this.commonObjs = new PDFObjects(); + this.fontLoader = new _font_loader.FontLoader(loadingTask.docId); + this._params = params; + this.CMapReaderFactory = new params.CMapReaderFactory({ + baseUrl: params.cMapUrl, + isCompressed: params.cMapPacked + }); + this.destroyed = false; + this.destroyCapability = null; + this._passwordCapability = null; + this._networkStream = networkStream; + this._fullReader = null; + this._lastProgress = null; + this.pageCache = []; + this.pagePromises = []; + this.downloadInfoCapability = (0, _util.createPromiseCapability)(); + this.setupMessageHandler(); + } + + _createClass(WorkerTransport, [{ + key: 'destroy', + value: function destroy() { + var _this8 = this; + + if (this.destroyCapability) { + return this.destroyCapability.promise; + } + this.destroyed = true; + this.destroyCapability = (0, _util.createPromiseCapability)(); + if (this._passwordCapability) { + this._passwordCapability.reject(new Error('Worker was destroyed during onPassword callback')); + } + var waitOn = []; + this.pageCache.forEach(function (page) { + if (page) { + waitOn.push(page._destroy()); + } + }); + this.pageCache = []; + this.pagePromises = []; + var terminated = this.messageHandler.sendWithPromise('Terminate', null); + waitOn.push(terminated); + Promise.all(waitOn).then(function () { + _this8.fontLoader.clear(); + if (_this8._networkStream) { + _this8._networkStream.cancelAllRequests(); + } + if (_this8.messageHandler) { + _this8.messageHandler.destroy(); + _this8.messageHandler = null; + } + _this8.destroyCapability.resolve(); + }, this.destroyCapability.reject); + return this.destroyCapability.promise; + } + }, { + key: 'setupMessageHandler', + value: function setupMessageHandler() { + var messageHandler = this.messageHandler, + loadingTask = this.loadingTask; + + messageHandler.on('GetReader', function (data, sink) { + var _this9 = this; + + (0, _util.assert)(this._networkStream); + this._fullReader = this._networkStream.getFullReader(); + this._fullReader.onProgress = function (evt) { + _this9._lastProgress = { + loaded: evt.loaded, + total: evt.total + }; + }; + sink.onPull = function () { + _this9._fullReader.read().then(function (_ref3) { + var value = _ref3.value, + done = _ref3.done; + + if (done) { + sink.close(); + return; + } + (0, _util.assert)((0, _util.isArrayBuffer)(value)); + sink.enqueue(new Uint8Array(value), 1, [value]); + }).catch(function (reason) { + sink.error(reason); + }); + }; + sink.onCancel = function (reason) { + _this9._fullReader.cancel(reason); + }; + }, this); + messageHandler.on('ReaderHeadersReady', function (data) { + var _this10 = this; + + var headersCapability = (0, _util.createPromiseCapability)(); + var fullReader = this._fullReader; + fullReader.headersReady.then(function () { + if (!fullReader.isStreamingSupported || !fullReader.isRangeSupported) { + if (_this10._lastProgress && loadingTask.onProgress) { + loadingTask.onProgress(_this10._lastProgress); + } + fullReader.onProgress = function (evt) { + if (loadingTask.onProgress) { + loadingTask.onProgress({ + loaded: evt.loaded, + total: evt.total + }); + } + }; + } + headersCapability.resolve({ + isStreamingSupported: fullReader.isStreamingSupported, + isRangeSupported: fullReader.isRangeSupported, + contentLength: fullReader.contentLength + }); + }, headersCapability.reject); + return headersCapability.promise; + }, this); + messageHandler.on('GetRangeReader', function (data, sink) { + (0, _util.assert)(this._networkStream); + var rangeReader = this._networkStream.getRangeReader(data.begin, data.end); + sink.onPull = function () { + rangeReader.read().then(function (_ref4) { + var value = _ref4.value, + done = _ref4.done; + + if (done) { + sink.close(); + return; + } + (0, _util.assert)((0, _util.isArrayBuffer)(value)); + sink.enqueue(new Uint8Array(value), 1, [value]); + }).catch(function (reason) { + sink.error(reason); + }); + }; + sink.onCancel = function (reason) { + rangeReader.cancel(reason); + }; + }, this); + messageHandler.on('GetDoc', function (_ref5) { + var pdfInfo = _ref5.pdfInfo; + + this.numPages = pdfInfo.numPages; + this.pdfDocument = new PDFDocumentProxy(pdfInfo, this, loadingTask); + loadingTask._capability.resolve(this.pdfDocument); + }, this); + messageHandler.on('PasswordRequest', function (exception) { + var _this11 = this; + + this._passwordCapability = (0, _util.createPromiseCapability)(); + if (loadingTask.onPassword) { + var updatePassword = function updatePassword(password) { + _this11._passwordCapability.resolve({ password: password }); + }; + try { + loadingTask.onPassword(updatePassword, exception.code); + } catch (ex) { + this._passwordCapability.reject(ex); + } + } else { + this._passwordCapability.reject(new _util.PasswordException(exception.message, exception.code)); + } + return this._passwordCapability.promise; + }, this); + messageHandler.on('PasswordException', function (exception) { + loadingTask._capability.reject(new _util.PasswordException(exception.message, exception.code)); + }, this); + messageHandler.on('InvalidPDF', function (exception) { + loadingTask._capability.reject(new _util.InvalidPDFException(exception.message)); + }, this); + messageHandler.on('MissingPDF', function (exception) { + loadingTask._capability.reject(new _util.MissingPDFException(exception.message)); + }, this); + messageHandler.on('UnexpectedResponse', function (exception) { + loadingTask._capability.reject(new _util.UnexpectedResponseException(exception.message, exception.status)); + }, this); + messageHandler.on('UnknownError', function (exception) { + loadingTask._capability.reject(new _util.UnknownErrorException(exception.message, exception.details)); + }, this); + messageHandler.on('DataLoaded', function (data) { + if (loadingTask.onProgress) { + loadingTask.onProgress({ + loaded: data.length, + total: data.length + }); + } + this.downloadInfoCapability.resolve(data); + }, this); + messageHandler.on('StartRenderPage', function (data) { + if (this.destroyed) { + return; + } + var page = this.pageCache[data.pageIndex]; + page._stats.timeEnd('Page Request'); + page._startRenderPage(data.transparency, data.intent); + }, this); + messageHandler.on('RenderPageChunk', function (data) { + if (this.destroyed) { + return; + } + var page = this.pageCache[data.pageIndex]; + page._renderPageChunk(data.operatorList, data.intent); + }, this); + messageHandler.on('commonobj', function (data) { + var _this12 = this; + + if (this.destroyed) { + return; + } + + var _data = _slicedToArray(data, 3), + id = _data[0], + type = _data[1], + exportedData = _data[2]; + + if (this.commonObjs.hasData(id)) { + return; + } + switch (type) { + case 'Font': + var params = this._params; + if ('error' in exportedData) { + var exportedError = exportedData.error; + (0, _util.warn)('Error during font loading: ' + exportedError); + this.commonObjs.resolve(id, exportedError); + break; + } + var fontRegistry = null; + if (params.pdfBug && _global_scope2.default.FontInspector && _global_scope2.default.FontInspector.enabled) { + fontRegistry = { + registerFont: function registerFont(font, url) { + _global_scope2.default['FontInspector'].fontAdded(font, url); + } + }; + } + var font = new _font_loader.FontFaceObject(exportedData, { + isEvalSupported: params.isEvalSupported, + disableFontFace: params.disableFontFace, + ignoreErrors: params.ignoreErrors, + onUnsupportedFeature: this._onUnsupportedFeature.bind(this), + fontRegistry: fontRegistry + }); + var fontReady = function fontReady(fontObjs) { + _this12.commonObjs.resolve(id, font); + }; + this.fontLoader.bind([font], fontReady); + break; + case 'FontPath': + this.commonObjs.resolve(id, exportedData); + break; + default: + throw new Error('Got unknown common object type ' + type); + } + }, this); + messageHandler.on('obj', function (data) { + if (this.destroyed) { + return; + } + + var _data2 = _slicedToArray(data, 4), + id = _data2[0], + pageIndex = _data2[1], + type = _data2[2], + imageData = _data2[3]; + + var pageProxy = this.pageCache[pageIndex]; + if (pageProxy.objs.hasData(id)) { + return; + } + switch (type) { + case 'JpegStream': + return new Promise(function (resolve, reject) { + var img = new Image(); + img.onload = function () { + resolve(img); + }; + img.onerror = function () { + reject(new Error('Error during JPEG image loading')); + }; + img.src = imageData; + }).then(function (img) { + pageProxy.objs.resolve(id, img); + }); + case 'Image': + pageProxy.objs.resolve(id, imageData); + var MAX_IMAGE_SIZE_TO_STORE = 8000000; + if (imageData && 'data' in imageData && imageData.data.length > MAX_IMAGE_SIZE_TO_STORE) { + pageProxy.cleanupAfterRender = true; + } + break; + default: + throw new Error('Got unknown object type ' + type); + } + }, this); + messageHandler.on('DocProgress', function (data) { + if (this.destroyed) { + return; + } + if (loadingTask.onProgress) { + loadingTask.onProgress({ + loaded: data.loaded, + total: data.total + }); + } + }, this); + messageHandler.on('PageError', function (data) { + if (this.destroyed) { + return; + } + var page = this.pageCache[data.pageNum - 1]; + var intentState = page.intentStates[data.intent]; + if (intentState.displayReadyCapability) { + intentState.displayReadyCapability.reject(data.error); + } else { + throw new Error(data.error); + } + if (intentState.operatorList) { + intentState.operatorList.lastChunk = true; + for (var i = 0; i < intentState.renderTasks.length; i++) { + intentState.renderTasks[i].operatorListChanged(); + } + } + }, this); + messageHandler.on('UnsupportedFeature', this._onUnsupportedFeature, this); + messageHandler.on('JpegDecode', function (data) { + if (this.destroyed) { + return Promise.reject(new Error('Worker was destroyed')); + } + if (typeof document === 'undefined') { + return Promise.reject(new Error('"document" is not defined.')); + } + + var _data3 = _slicedToArray(data, 2), + imageUrl = _data3[0], + components = _data3[1]; + + if (components !== 3 && components !== 1) { + return Promise.reject(new Error('Only 3 components or 1 component can be returned')); + } + return new Promise(function (resolve, reject) { + var img = new Image(); + img.onload = function () { + var width = img.width; + var height = img.height; + var size = width * height; + var rgbaLength = size * 4; + var buf = new Uint8ClampedArray(size * components); + var tmpCanvas = document.createElement('canvas'); + tmpCanvas.width = width; + tmpCanvas.height = height; + var tmpCtx = tmpCanvas.getContext('2d'); + tmpCtx.drawImage(img, 0, 0); + var data = tmpCtx.getImageData(0, 0, width, height).data; + if (components === 3) { + for (var i = 0, j = 0; i < rgbaLength; i += 4, j += 3) { + buf[j] = data[i]; + buf[j + 1] = data[i + 1]; + buf[j + 2] = data[i + 2]; + } + } else if (components === 1) { + for (var _i = 0, _j = 0; _i < rgbaLength; _i += 4, _j++) { + buf[_j] = data[_i]; + } + } + resolve({ + data: buf, + width: width, + height: height + }); + }; + img.onerror = function () { + reject(new Error('JpegDecode failed to load image')); + }; + img.src = imageUrl; + }); + }, this); + messageHandler.on('FetchBuiltInCMap', function (data) { + if (this.destroyed) { + return Promise.reject(new Error('Worker was destroyed')); + } + return this.CMapReaderFactory.fetch({ name: data.name }); + }, this); + } + }, { + key: '_onUnsupportedFeature', + value: function _onUnsupportedFeature(_ref6) { + var featureId = _ref6.featureId; + + if (this.destroyed) { + return; + } + if (this.loadingTask.onUnsupportedFeature) { + this.loadingTask.onUnsupportedFeature(featureId); + } + } + }, { + key: 'getData', + value: function getData() { + return this.messageHandler.sendWithPromise('GetData', null); + } + }, { + key: 'getPage', + value: function getPage(pageNumber) { + var _this13 = this; + + if (!Number.isInteger(pageNumber) || pageNumber <= 0 || pageNumber > this.numPages) { + return Promise.reject(new Error('Invalid page request')); + } + var pageIndex = pageNumber - 1; + if (pageIndex in this.pagePromises) { + return this.pagePromises[pageIndex]; + } + var promise = this.messageHandler.sendWithPromise('GetPage', { pageIndex: pageIndex }).then(function (pageInfo) { + if (_this13.destroyed) { + throw new Error('Transport destroyed'); + } + var page = new PDFPageProxy(pageIndex, pageInfo, _this13, _this13._params.pdfBug); + _this13.pageCache[pageIndex] = page; + return page; + }); + this.pagePromises[pageIndex] = promise; + return promise; + } + }, { + key: 'getPageIndex', + value: function getPageIndex(ref) { + return this.messageHandler.sendWithPromise('GetPageIndex', { ref: ref }).catch(function (reason) { + return Promise.reject(new Error(reason)); + }); + } + }, { + key: 'getAnnotations', + value: function getAnnotations(pageIndex, intent) { + return this.messageHandler.sendWithPromise('GetAnnotations', { + pageIndex: pageIndex, + intent: intent + }); + } + }, { + key: 'getDestinations', + value: function getDestinations() { + return this.messageHandler.sendWithPromise('GetDestinations', null); + } + }, { + key: 'getDestination', + value: function getDestination(id) { + if (typeof id !== 'string') { + return Promise.reject(new Error('Invalid destination request.')); + } + return this.messageHandler.sendWithPromise('GetDestination', { id: id }); + } + }, { + key: 'getPageLabels', + value: function getPageLabels() { + return this.messageHandler.sendWithPromise('GetPageLabels', null); + } + }, { + key: 'getPageMode', + value: function getPageMode() { + return this.messageHandler.sendWithPromise('GetPageMode', null); + } + }, { + key: 'getAttachments', + value: function getAttachments() { + return this.messageHandler.sendWithPromise('GetAttachments', null); + } + }, { + key: 'getJavaScript', + value: function getJavaScript() { + return this.messageHandler.sendWithPromise('GetJavaScript', null); + } + }, { + key: 'getOutline', + value: function getOutline() { + return this.messageHandler.sendWithPromise('GetOutline', null); + } + }, { + key: 'getPermissions', + value: function getPermissions() { + return this.messageHandler.sendWithPromise('GetPermissions', null); + } + }, { + key: 'getMetadata', + value: function getMetadata() { + var _this14 = this; + + return this.messageHandler.sendWithPromise('GetMetadata', null).then(function (results) { + return { + info: results[0], + metadata: results[1] ? new _metadata.Metadata(results[1]) : null, + contentDispositionFilename: _this14._fullReader ? _this14._fullReader.filename : null + }; + }); + } + }, { + key: 'getStats', + value: function getStats() { + return this.messageHandler.sendWithPromise('GetStats', null); + } + }, { + key: 'startCleanup', + value: function startCleanup() { + var _this15 = this; + + this.messageHandler.sendWithPromise('Cleanup', null).then(function () { + for (var i = 0, ii = _this15.pageCache.length; i < ii; i++) { + var page = _this15.pageCache[i]; + if (page) { + page.cleanup(); + } + } + _this15.commonObjs.clear(); + _this15.fontLoader.clear(); + }); + } + }, { + key: 'loadingParams', + get: function get() { + var params = this._params; + return (0, _util.shadow)(this, 'loadingParams', { + disableAutoFetch: params.disableAutoFetch, + disableCreateObjectURL: params.disableCreateObjectURL, + disableFontFace: params.disableFontFace, + nativeImageDecoderSupport: params.nativeImageDecoderSupport + }); + } + }]); + + return WorkerTransport; +}(); + +var PDFObjects = function PDFObjectsClosure() { + function PDFObjects() { + this.objs = Object.create(null); + } + PDFObjects.prototype = { + ensureObj: function PDFObjects_ensureObj(objId) { + if (this.objs[objId]) { + return this.objs[objId]; + } + var obj = { + capability: (0, _util.createPromiseCapability)(), + data: null, + resolved: false + }; + this.objs[objId] = obj; + return obj; + }, + get: function PDFObjects_get(objId, callback) { + if (callback) { + this.ensureObj(objId).capability.promise.then(callback); + return null; + } + var obj = this.objs[objId]; + if (!obj || !obj.resolved) { + throw new Error('Requesting object that isn\'t resolved yet ' + objId); + } + return obj.data; + }, + resolve: function PDFObjects_resolve(objId, data) { + var obj = this.ensureObj(objId); + obj.resolved = true; + obj.data = data; + obj.capability.resolve(data); + }, + isResolved: function PDFObjects_isResolved(objId) { + var objs = this.objs; + if (!objs[objId]) { + return false; + } + return objs[objId].resolved; + }, + hasData: function PDFObjects_hasData(objId) { + return this.isResolved(objId); + }, + getData: function PDFObjects_getData(objId) { + var objs = this.objs; + if (!objs[objId] || !objs[objId].resolved) { + return null; + } + return objs[objId].data; + }, + clear: function PDFObjects_clear() { + this.objs = Object.create(null); + } + }; + return PDFObjects; +}(); +var RenderTask = function RenderTaskClosure() { + function RenderTask(internalRenderTask) { + this._internalRenderTask = internalRenderTask; + this.onContinue = null; + } + RenderTask.prototype = { + get promise() { + return this._internalRenderTask.capability.promise; + }, + cancel: function RenderTask_cancel() { + this._internalRenderTask.cancel(); + }, + then: function RenderTask_then(onFulfilled, onRejected) { + return this.promise.then.apply(this.promise, arguments); + } + }; + return RenderTask; +}(); +var InternalRenderTask = function InternalRenderTaskClosure() { + var canvasInRendering = new WeakMap(); + function InternalRenderTask(callback, params, objs, commonObjs, operatorList, pageNumber, canvasFactory, webGLContext) { + var pdfBug = arguments.length > 8 && arguments[8] !== undefined ? arguments[8] : false; + + this.callback = callback; + this.params = params; + this.objs = objs; + this.commonObjs = commonObjs; + this.operatorListIdx = null; + this.operatorList = operatorList; + this.pageNumber = pageNumber; + this.canvasFactory = canvasFactory; + this.webGLContext = webGLContext; + this._pdfBug = pdfBug; + this.running = false; + this.graphicsReadyCallback = null; + this.graphicsReady = false; + this.useRequestAnimationFrame = false; + this.cancelled = false; + this.capability = (0, _util.createPromiseCapability)(); + this.task = new RenderTask(this); + this._continueBound = this._continue.bind(this); + this._scheduleNextBound = this._scheduleNext.bind(this); + this._nextBound = this._next.bind(this); + this._canvas = params.canvasContext.canvas; + } + InternalRenderTask.prototype = { + initializeGraphics: function initializeGraphics(transparency) { + if (this.cancelled) { + return; + } + if (this._canvas) { + if (canvasInRendering.has(this._canvas)) { + throw new Error('Cannot use the same canvas during multiple render() operations. ' + 'Use different canvas or ensure previous operations were ' + 'cancelled or completed.'); + } + canvasInRendering.set(this._canvas, this); + } + if (this._pdfBug && _global_scope2.default.StepperManager && _global_scope2.default.StepperManager.enabled) { + this.stepper = _global_scope2.default.StepperManager.create(this.pageNumber - 1); + this.stepper.init(this.operatorList); + this.stepper.nextBreakPoint = this.stepper.getNextBreakPoint(); + } + var params = this.params; + this.gfx = new _canvas.CanvasGraphics(params.canvasContext, this.commonObjs, this.objs, this.canvasFactory, this.webGLContext, params.imageLayer); + this.gfx.beginDrawing({ + transform: params.transform, + viewport: params.viewport, + transparency: transparency, + background: params.background + }); + this.operatorListIdx = 0; + this.graphicsReady = true; + if (this.graphicsReadyCallback) { + this.graphicsReadyCallback(); + } + }, + + cancel: function InternalRenderTask_cancel() { + this.running = false; + this.cancelled = true; + if (this._canvas) { + canvasInRendering.delete(this._canvas); + } + this.callback(new _dom_utils.RenderingCancelledException('Rendering cancelled, page ' + this.pageNumber, 'canvas')); + }, + operatorListChanged: function InternalRenderTask_operatorListChanged() { + if (!this.graphicsReady) { + if (!this.graphicsReadyCallback) { + this.graphicsReadyCallback = this._continueBound; + } + return; + } + if (this.stepper) { + this.stepper.updateOperatorList(this.operatorList); + } + if (this.running) { + return; + } + this._continue(); + }, + _continue: function InternalRenderTask__continue() { + this.running = true; + if (this.cancelled) { + return; + } + if (this.task.onContinue) { + this.task.onContinue(this._scheduleNextBound); + } else { + this._scheduleNext(); + } + }, + _scheduleNext: function InternalRenderTask__scheduleNext() { + var _this16 = this; + + if (this.useRequestAnimationFrame && typeof window !== 'undefined') { + window.requestAnimationFrame(function () { + _this16._nextBound().catch(_this16.callback); + }); + } else { + Promise.resolve().then(this._nextBound).catch(this.callback); + } + }, + _next: function InternalRenderTask__next() { + var _this17 = this; + + return new Promise(function () { + if (_this17.cancelled) { + return; + } + _this17.operatorListIdx = _this17.gfx.executeOperatorList(_this17.operatorList, _this17.operatorListIdx, _this17._continueBound, _this17.stepper); + if (_this17.operatorListIdx === _this17.operatorList.argsArray.length) { + _this17.running = false; + if (_this17.operatorList.lastChunk) { + _this17.gfx.endDrawing(); + if (_this17._canvas) { + canvasInRendering.delete(_this17._canvas); + } + _this17.callback(); + } + } + }); + } + }; + return InternalRenderTask; +}(); +var version, build; +{ + exports.version = version = '2.0.943'; + exports.build = build = 'dc98bf76'; +} +exports.getDocument = getDocument; +exports.LoopbackPort = LoopbackPort; +exports.PDFDataRangeTransport = PDFDataRangeTransport; +exports.PDFWorker = PDFWorker; +exports.PDFDocumentProxy = PDFDocumentProxy; +exports.PDFPageProxy = PDFPageProxy; +exports.setPDFNetworkStreamFactory = setPDFNetworkStreamFactory; +exports.version = version; +exports.build = build; + +/***/ }), +/* 130 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.loadScript = exports.DummyStatTimer = exports.StatTimer = exports.DOMSVGFactory = exports.DOMCMapReaderFactory = exports.DOMCanvasFactory = exports.DEFAULT_LINK_REL = exports.LinkTarget = exports.getFilenameFromUrl = exports.addLinkAttributes = exports.RenderingCancelledException = exports.PageViewport = undefined; + +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + +var _util = __w_pdfjs_require__(1); + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var DEFAULT_LINK_REL = 'noopener noreferrer nofollow'; +var SVG_NS = 'http://www.w3.org/2000/svg'; + +var DOMCanvasFactory = function () { + function DOMCanvasFactory() { + _classCallCheck(this, DOMCanvasFactory); + } + + _createClass(DOMCanvasFactory, [{ + key: 'create', + value: function create(width, height) { + if (width <= 0 || height <= 0) { + throw new Error('invalid canvas size'); + } + var canvas = document.createElement('canvas'); + var context = canvas.getContext('2d'); + canvas.width = width; + canvas.height = height; + return { + canvas: canvas, + context: context + }; + } + }, { + key: 'reset', + value: function reset(canvasAndContext, width, height) { + if (!canvasAndContext.canvas) { + throw new Error('canvas is not specified'); + } + if (width <= 0 || height <= 0) { + throw new Error('invalid canvas size'); + } + canvasAndContext.canvas.width = width; + canvasAndContext.canvas.height = height; + } + }, { + key: 'destroy', + value: function destroy(canvasAndContext) { + if (!canvasAndContext.canvas) { + throw new Error('canvas is not specified'); + } + canvasAndContext.canvas.width = 0; + canvasAndContext.canvas.height = 0; + canvasAndContext.canvas = null; + canvasAndContext.context = null; + } + }]); + + return DOMCanvasFactory; +}(); + +var DOMCMapReaderFactory = function () { + function DOMCMapReaderFactory(_ref) { + var _ref$baseUrl = _ref.baseUrl, + baseUrl = _ref$baseUrl === undefined ? null : _ref$baseUrl, + _ref$isCompressed = _ref.isCompressed, + isCompressed = _ref$isCompressed === undefined ? false : _ref$isCompressed; + + _classCallCheck(this, DOMCMapReaderFactory); + + this.baseUrl = baseUrl; + this.isCompressed = isCompressed; + } + + _createClass(DOMCMapReaderFactory, [{ + key: 'fetch', + value: function fetch(_ref2) { + var _this = this; + + var name = _ref2.name; + + if (!this.baseUrl) { + return Promise.reject(new Error('The CMap "baseUrl" parameter must be specified, ensure that ' + 'the "cMapUrl" and "cMapPacked" API parameters are provided.')); + } + if (!name) { + return Promise.reject(new Error('CMap name must be specified.')); + } + return new Promise(function (resolve, reject) { + var url = _this.baseUrl + name + (_this.isCompressed ? '.bcmap' : ''); + var request = new XMLHttpRequest(); + request.open('GET', url, true); + if (_this.isCompressed) { + request.responseType = 'arraybuffer'; + } + request.onreadystatechange = function () { + if (request.readyState !== XMLHttpRequest.DONE) { + return; + } + if (request.status === 200 || request.status === 0) { + var data = void 0; + if (_this.isCompressed && request.response) { + data = new Uint8Array(request.response); + } else if (!_this.isCompressed && request.responseText) { + data = (0, _util.stringToBytes)(request.responseText); + } + if (data) { + resolve({ + cMapData: data, + compressionType: _this.isCompressed ? _util.CMapCompressionType.BINARY : _util.CMapCompressionType.NONE + }); + return; + } + } + reject(new Error('Unable to load ' + (_this.isCompressed ? 'binary ' : '') + 'CMap at: ' + url)); + }; + request.send(null); + }); + } + }]); + + return DOMCMapReaderFactory; +}(); + +var DOMSVGFactory = function () { + function DOMSVGFactory() { + _classCallCheck(this, DOMSVGFactory); + } + + _createClass(DOMSVGFactory, [{ + key: 'create', + value: function create(width, height) { + (0, _util.assert)(width > 0 && height > 0, 'Invalid SVG dimensions'); + var svg = document.createElementNS(SVG_NS, 'svg:svg'); + svg.setAttribute('version', '1.1'); + svg.setAttribute('width', width + 'px'); + svg.setAttribute('height', height + 'px'); + svg.setAttribute('preserveAspectRatio', 'none'); + svg.setAttribute('viewBox', '0 0 ' + width + ' ' + height); + return svg; + } + }, { + key: 'createElement', + value: function createElement(type) { + (0, _util.assert)(typeof type === 'string', 'Invalid SVG element type'); + return document.createElementNS(SVG_NS, type); + } + }]); + + return DOMSVGFactory; +}(); + +var PageViewport = function () { + function PageViewport(_ref3) { + var viewBox = _ref3.viewBox, + scale = _ref3.scale, + rotation = _ref3.rotation, + _ref3$offsetX = _ref3.offsetX, + offsetX = _ref3$offsetX === undefined ? 0 : _ref3$offsetX, + _ref3$offsetY = _ref3.offsetY, + offsetY = _ref3$offsetY === undefined ? 0 : _ref3$offsetY, + _ref3$dontFlip = _ref3.dontFlip, + dontFlip = _ref3$dontFlip === undefined ? false : _ref3$dontFlip; + + _classCallCheck(this, PageViewport); + + this.viewBox = viewBox; + this.scale = scale; + this.rotation = rotation; + this.offsetX = offsetX; + this.offsetY = offsetY; + var centerX = (viewBox[2] + viewBox[0]) / 2; + var centerY = (viewBox[3] + viewBox[1]) / 2; + var rotateA = void 0, + rotateB = void 0, + rotateC = void 0, + rotateD = void 0; + rotation = rotation % 360; + rotation = rotation < 0 ? rotation + 360 : rotation; + switch (rotation) { + case 180: + rotateA = -1; + rotateB = 0; + rotateC = 0; + rotateD = 1; + break; + case 90: + rotateA = 0; + rotateB = 1; + rotateC = 1; + rotateD = 0; + break; + case 270: + rotateA = 0; + rotateB = -1; + rotateC = -1; + rotateD = 0; + break; + default: + rotateA = 1; + rotateB = 0; + rotateC = 0; + rotateD = -1; + break; + } + if (dontFlip) { + rotateC = -rotateC; + rotateD = -rotateD; + } + var offsetCanvasX = void 0, + offsetCanvasY = void 0; + var width = void 0, + height = void 0; + if (rotateA === 0) { + offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX; + offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY; + width = Math.abs(viewBox[3] - viewBox[1]) * scale; + height = Math.abs(viewBox[2] - viewBox[0]) * scale; + } else { + offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX; + offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY; + width = Math.abs(viewBox[2] - viewBox[0]) * scale; + height = Math.abs(viewBox[3] - viewBox[1]) * scale; + } + this.transform = [rotateA * scale, rotateB * scale, rotateC * scale, rotateD * scale, offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY, offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY]; + this.width = width; + this.height = height; + } + + _createClass(PageViewport, [{ + key: 'clone', + value: function clone() { + var _ref4 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, + _ref4$scale = _ref4.scale, + scale = _ref4$scale === undefined ? this.scale : _ref4$scale, + _ref4$rotation = _ref4.rotation, + rotation = _ref4$rotation === undefined ? this.rotation : _ref4$rotation, + _ref4$dontFlip = _ref4.dontFlip, + dontFlip = _ref4$dontFlip === undefined ? false : _ref4$dontFlip; + + return new PageViewport({ + viewBox: this.viewBox.slice(), + scale: scale, + rotation: rotation, + offsetX: this.offsetX, + offsetY: this.offsetY, + dontFlip: dontFlip + }); + } + }, { + key: 'convertToViewportPoint', + value: function convertToViewportPoint(x, y) { + return _util.Util.applyTransform([x, y], this.transform); + } + }, { + key: 'convertToViewportRectangle', + value: function convertToViewportRectangle(rect) { + var tl = _util.Util.applyTransform([rect[0], rect[1]], this.transform); + var br = _util.Util.applyTransform([rect[2], rect[3]], this.transform); + return [tl[0], tl[1], br[0], br[1]]; + } + }, { + key: 'convertToPdfPoint', + value: function convertToPdfPoint(x, y) { + return _util.Util.applyInverseTransform([x, y], this.transform); + } + }]); + + return PageViewport; +}(); + +var RenderingCancelledException = function RenderingCancelledException() { + function RenderingCancelledException(msg, type) { + this.message = msg; + this.type = type; + } + RenderingCancelledException.prototype = new Error(); + RenderingCancelledException.prototype.name = 'RenderingCancelledException'; + RenderingCancelledException.constructor = RenderingCancelledException; + return RenderingCancelledException; +}(); +var LinkTarget = { + NONE: 0, + SELF: 1, + BLANK: 2, + PARENT: 3, + TOP: 4 +}; +var LinkTargetStringMap = ['', '_self', '_blank', '_parent', '_top']; +function addLinkAttributes(link) { + var _ref5 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + url = _ref5.url, + target = _ref5.target, + rel = _ref5.rel; + + link.href = link.title = url ? (0, _util.removeNullCharacters)(url) : ''; + if (url) { + var LinkTargetValues = Object.values(LinkTarget); + var targetIndex = LinkTargetValues.includes(target) ? target : LinkTarget.NONE; + link.target = LinkTargetStringMap[targetIndex]; + link.rel = typeof rel === 'string' ? rel : DEFAULT_LINK_REL; + } +} +function getFilenameFromUrl(url) { + var anchor = url.indexOf('#'); + var query = url.indexOf('?'); + var end = Math.min(anchor > 0 ? anchor : url.length, query > 0 ? query : url.length); + return url.substring(url.lastIndexOf('/', end) + 1, end); +} + +var StatTimer = function () { + function StatTimer() { + var enable = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true; + + _classCallCheck(this, StatTimer); + + this.enabled = !!enable; + this.started = Object.create(null); + this.times = []; + } + + _createClass(StatTimer, [{ + key: 'time', + value: function time(name) { + if (!this.enabled) { + return; + } + if (name in this.started) { + (0, _util.warn)('Timer is already running for ' + name); + } + this.started[name] = Date.now(); + } + }, { + key: 'timeEnd', + value: function timeEnd(name) { + if (!this.enabled) { + return; + } + if (!(name in this.started)) { + (0, _util.warn)('Timer has not been started for ' + name); + } + this.times.push({ + 'name': name, + 'start': this.started[name], + 'end': Date.now() + }); + delete this.started[name]; + } + }, { + key: 'toString', + value: function toString() { + var times = this.times; + var out = '', + longest = 0; + for (var i = 0, ii = times.length; i < ii; ++i) { + var name = times[i]['name']; + if (name.length > longest) { + longest = name.length; + } + } + for (var _i = 0, _ii = times.length; _i < _ii; ++_i) { + var span = times[_i]; + var duration = span.end - span.start; + out += span['name'].padEnd(longest) + ' ' + duration + 'ms\n'; + } + return out; + } + }]); + + return StatTimer; +}(); + +var DummyStatTimer = function () { + function DummyStatTimer() { + _classCallCheck(this, DummyStatTimer); + + (0, _util.unreachable)('Cannot initialize DummyStatTimer.'); + } + + _createClass(DummyStatTimer, null, [{ + key: 'time', + value: function time(name) {} + }, { + key: 'timeEnd', + value: function timeEnd(name) {} + }, { + key: 'toString', + value: function toString() { + return ''; + } + }]); + + return DummyStatTimer; +}(); + +function loadScript(src) { + return new Promise(function (resolve, reject) { + var script = document.createElement('script'); + script.src = src; + script.onload = resolve; + script.onerror = function () { + reject(new Error('Cannot load script at: ' + script.src)); + }; + (document.head || document.documentElement).appendChild(script); + }); +} +exports.PageViewport = PageViewport; +exports.RenderingCancelledException = RenderingCancelledException; +exports.addLinkAttributes = addLinkAttributes; +exports.getFilenameFromUrl = getFilenameFromUrl; +exports.LinkTarget = LinkTarget; +exports.DEFAULT_LINK_REL = DEFAULT_LINK_REL; +exports.DOMCanvasFactory = DOMCanvasFactory; +exports.DOMCMapReaderFactory = DOMCMapReaderFactory; +exports.DOMSVGFactory = DOMSVGFactory; +exports.StatTimer = StatTimer; +exports.DummyStatTimer = DummyStatTimer; +exports.loadScript = loadScript; + +/***/ }), +/* 131 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.FontLoader = exports.FontFaceObject = undefined; + +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + +var _util = __w_pdfjs_require__(1); + +function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var BaseFontLoader = function () { + function BaseFontLoader(docId) { + _classCallCheck(this, BaseFontLoader); + + if (this.constructor === BaseFontLoader) { + (0, _util.unreachable)('Cannot initialize BaseFontLoader.'); + } + this.docId = docId; + this.nativeFontFaces = []; + this.styleElement = null; + this.loadingContext = { + requests: [], + nextRequestId: 0 + }; + } + + _createClass(BaseFontLoader, [{ + key: 'addNativeFontFace', + value: function addNativeFontFace(nativeFontFace) { + this.nativeFontFaces.push(nativeFontFace); + document.fonts.add(nativeFontFace); + } + }, { + key: 'insertRule', + value: function insertRule(rule) { + var styleElement = this.styleElement; + if (!styleElement) { + styleElement = this.styleElement = document.createElement('style'); + styleElement.id = 'PDFJS_FONT_STYLE_TAG_' + this.docId; + document.documentElement.getElementsByTagName('head')[0].appendChild(styleElement); + } + var styleSheet = styleElement.sheet; + styleSheet.insertRule(rule, styleSheet.cssRules.length); + } + }, { + key: 'clear', + value: function clear() { + this.nativeFontFaces.forEach(function (nativeFontFace) { + document.fonts.delete(nativeFontFace); + }); + this.nativeFontFaces.length = 0; + if (this.styleElement) { + this.styleElement.remove(); + this.styleElement = null; + } + } + }, { + key: 'bind', + value: function bind(fonts, callback) { + var rules = []; + var fontsToLoad = []; + var fontLoadPromises = []; + var getNativeFontPromise = function getNativeFontPromise(nativeFontFace) { + return nativeFontFace.loaded.catch(function (reason) { + (0, _util.warn)('Failed to load font "' + nativeFontFace.family + '": ' + reason); + }); + }; + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; + + try { + for (var _iterator = fonts[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var font = _step.value; + + if (font.attached || font.missingFile) { + continue; + } + font.attached = true; + if (this.isFontLoadingAPISupported) { + var nativeFontFace = font.createNativeFontFace(); + if (nativeFontFace) { + this.addNativeFontFace(nativeFontFace); + fontLoadPromises.push(getNativeFontPromise(nativeFontFace)); + } + } else { + var rule = font.createFontFaceRule(); + if (rule) { + this.insertRule(rule); + rules.push(rule); + fontsToLoad.push(font); + } + } + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally { + try { + if (!_iteratorNormalCompletion && _iterator.return) { + _iterator.return(); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } + } + } + + var request = this._queueLoadingCallback(callback); + if (this.isFontLoadingAPISupported) { + Promise.all(fontLoadPromises).then(request.complete); + } else if (rules.length > 0 && !this.isSyncFontLoadingSupported) { + this._prepareFontLoadEvent(rules, fontsToLoad, request); + } else { + request.complete(); + } + } + }, { + key: '_queueLoadingCallback', + value: function _queueLoadingCallback(callback) { + function completeRequest() { + (0, _util.assert)(!request.done, 'completeRequest() cannot be called twice.'); + request.done = true; + while (context.requests.length > 0 && context.requests[0].done) { + var otherRequest = context.requests.shift(); + setTimeout(otherRequest.callback, 0); + } + } + var context = this.loadingContext; + var request = { + id: 'pdfjs-font-loading-' + context.nextRequestId++, + done: false, + complete: completeRequest, + callback: callback + }; + context.requests.push(request); + return request; + } + }, { + key: '_prepareFontLoadEvent', + value: function _prepareFontLoadEvent(rules, fontsToLoad, request) { + (0, _util.unreachable)('Abstract method `_prepareFontLoadEvent`.'); + } + }, { + key: 'isFontLoadingAPISupported', + get: function get() { + (0, _util.unreachable)('Abstract method `isFontLoadingAPISupported`.'); + } + }, { + key: 'isSyncFontLoadingSupported', + get: function get() { + (0, _util.unreachable)('Abstract method `isSyncFontLoadingSupported`.'); + } + }, { + key: '_loadTestFont', + get: function get() { + (0, _util.unreachable)('Abstract method `_loadTestFont`.'); + } + }]); + + return BaseFontLoader; +}(); + +var FontLoader = void 0; +{ + exports.FontLoader = FontLoader = function (_BaseFontLoader) { + _inherits(GenericFontLoader, _BaseFontLoader); + + function GenericFontLoader(docId) { + _classCallCheck(this, GenericFontLoader); + + var _this = _possibleConstructorReturn(this, (GenericFontLoader.__proto__ || Object.getPrototypeOf(GenericFontLoader)).call(this, docId)); + + _this.loadTestFontId = 0; + return _this; + } + + _createClass(GenericFontLoader, [{ + key: '_prepareFontLoadEvent', + value: function _prepareFontLoadEvent(rules, fonts, request) { + function int32(data, offset) { + return data.charCodeAt(offset) << 24 | data.charCodeAt(offset + 1) << 16 | data.charCodeAt(offset + 2) << 8 | data.charCodeAt(offset + 3) & 0xff; + } + function spliceString(s, offset, remove, insert) { + var chunk1 = s.substring(0, offset); + var chunk2 = s.substring(offset + remove); + return chunk1 + insert + chunk2; + } + var i = void 0, + ii = void 0; + var canvas = document.createElement('canvas'); + canvas.width = 1; + canvas.height = 1; + var ctx = canvas.getContext('2d'); + var called = 0; + function isFontReady(name, callback) { + called++; + if (called > 30) { + (0, _util.warn)('Load test font never loaded.'); + callback(); + return; + } + ctx.font = '30px ' + name; + ctx.fillText('.', 0, 20); + var imageData = ctx.getImageData(0, 0, 1, 1); + if (imageData.data[3] > 0) { + callback(); + return; + } + setTimeout(isFontReady.bind(null, name, callback)); + } + var loadTestFontId = 'lt' + Date.now() + this.loadTestFontId++; + var data = this._loadTestFont; + var COMMENT_OFFSET = 976; + data = spliceString(data, COMMENT_OFFSET, loadTestFontId.length, loadTestFontId); + var CFF_CHECKSUM_OFFSET = 16; + var XXXX_VALUE = 0x58585858; + var checksum = int32(data, CFF_CHECKSUM_OFFSET); + for (i = 0, ii = loadTestFontId.length - 3; i < ii; i += 4) { + checksum = checksum - XXXX_VALUE + int32(loadTestFontId, i) | 0; + } + if (i < loadTestFontId.length) { + checksum = checksum - XXXX_VALUE + int32(loadTestFontId + 'XXX', i) | 0; + } + data = spliceString(data, CFF_CHECKSUM_OFFSET, 4, (0, _util.string32)(checksum)); + var url = 'url(data:font/opentype;base64,' + btoa(data) + ');'; + var rule = '@font-face {font-family:"' + loadTestFontId + '";src:' + url + '}'; + this.insertRule(rule); + var names = []; + for (i = 0, ii = fonts.length; i < ii; i++) { + names.push(fonts[i].loadedName); + } + names.push(loadTestFontId); + var div = document.createElement('div'); + div.setAttribute('style', 'visibility: hidden;' + 'width: 10px; height: 10px;' + 'position: absolute; top: 0px; left: 0px;'); + for (i = 0, ii = names.length; i < ii; ++i) { + var span = document.createElement('span'); + span.textContent = 'Hi'; + span.style.fontFamily = names[i]; + div.appendChild(span); + } + document.body.appendChild(div); + isFontReady(loadTestFontId, function () { + document.body.removeChild(div); + request.complete(); + }); + } + }, { + key: 'isFontLoadingAPISupported', + get: function get() { + var supported = typeof document !== 'undefined' && !!document.fonts; + if (supported && typeof navigator !== 'undefined') { + var m = /Mozilla\/5.0.*?rv:(\d+).*? Gecko/.exec(navigator.userAgent); + if (m && m[1] < 63) { + supported = false; + } + } + return (0, _util.shadow)(this, 'isFontLoadingAPISupported', supported); + } + }, { + key: 'isSyncFontLoadingSupported', + get: function get() { + var supported = false; + if (typeof navigator === 'undefined') { + supported = true; + } else { + var m = /Mozilla\/5.0.*?rv:(\d+).*? Gecko/.exec(navigator.userAgent); + if (m && m[1] >= 14) { + supported = true; + } + } + return (0, _util.shadow)(this, 'isSyncFontLoadingSupported', supported); + } + }, { + key: '_loadTestFont', + get: function get() { + var getLoadTestFont = function getLoadTestFont() { + return atob('T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQA' + 'FQAABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAA' + 'ALwAAAA2aGhlYQdkA+oAAAD0AAAAJGhtdHgD6AAAAAAEWAAAAAZtYXhwAAJQAAAAARgA' + 'AAAGbmFtZVjmdH4AAAGAAAAAsXBvc3T/hgAzAAADeAAAACAAAQAAAAEAALZRFsRfDzz1' + 'AAsD6AAAAADOBOTLAAAAAM4KHDwAAAAAA+gDIQAAAAgAAgAAAAAAAAABAAADIQAAAFoD' + '6AAAAAAD6AABAAAAAAAAAAAAAAAAAAAAAQAAUAAAAgAAAAQD6AH0AAUAAAKKArwAAACM' + 'AooCvAAAAeAAMQECAAACAAYJAAAAAAAAAAAAAQAAAAAAAAAAAAAAAFBmRWQAwAAuAC4D' + 'IP84AFoDIQAAAAAAAQAAAAAAAAAAACAAIAABAAAADgCuAAEAAAAAAAAAAQAAAAEAAAAA' + 'AAEAAQAAAAEAAAAAAAIAAQAAAAEAAAAAAAMAAQAAAAEAAAAAAAQAAQAAAAEAAAAAAAUA' + 'AQAAAAEAAAAAAAYAAQAAAAMAAQQJAAAAAgABAAMAAQQJAAEAAgABAAMAAQQJAAIAAgAB' + 'AAMAAQQJAAMAAgABAAMAAQQJAAQAAgABAAMAAQQJAAUAAgABAAMAAQQJAAYAAgABWABY' + 'AAAAAAAAAwAAAAMAAAAcAAEAAAAAADwAAwABAAAAHAAEACAAAAAEAAQAAQAAAC7//wAA' + 'AC7////TAAEAAAAAAAABBgAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' + 'AAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' + 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' + 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' + 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' + 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAAAAD/gwAyAAAAAQAAAAAAAAAAAAAAAAAA' + 'AAABAAQEAAEBAQJYAAEBASH4DwD4GwHEAvgcA/gXBIwMAYuL+nz5tQXkD5j3CBLnEQAC' + 'AQEBIVhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYAAABAQAADwACAQEEE/t3' + 'Dov6fAH6fAT+fPp8+nwHDosMCvm1Cvm1DAz6fBQAAAAAAAABAAAAAMmJbzEAAAAAzgTj' + 'FQAAAADOBOQpAAEAAAAAAAAADAAUAAQAAAABAAAAAgABAAAAAAAAAAAD6AAAAAAAAA=='); + }; + return (0, _util.shadow)(this, '_loadTestFont', getLoadTestFont()); + } + }]); + + return GenericFontLoader; + }(BaseFontLoader); +} +var IsEvalSupportedCached = { + get value() { + return (0, _util.shadow)(this, 'value', (0, _util.isEvalSupported)()); + } +}; + +var FontFaceObject = function () { + function FontFaceObject(translatedData, _ref) { + var _ref$isEvalSupported = _ref.isEvalSupported, + isEvalSupported = _ref$isEvalSupported === undefined ? true : _ref$isEvalSupported, + _ref$disableFontFace = _ref.disableFontFace, + disableFontFace = _ref$disableFontFace === undefined ? false : _ref$disableFontFace, + _ref$ignoreErrors = _ref.ignoreErrors, + ignoreErrors = _ref$ignoreErrors === undefined ? false : _ref$ignoreErrors, + _ref$onUnsupportedFea = _ref.onUnsupportedFeature, + onUnsupportedFeature = _ref$onUnsupportedFea === undefined ? null : _ref$onUnsupportedFea, + _ref$fontRegistry = _ref.fontRegistry, + fontRegistry = _ref$fontRegistry === undefined ? null : _ref$fontRegistry; + + _classCallCheck(this, FontFaceObject); + + this.compiledGlyphs = Object.create(null); + for (var i in translatedData) { + this[i] = translatedData[i]; + } + this.isEvalSupported = isEvalSupported !== false; + this.disableFontFace = disableFontFace === true; + this.ignoreErrors = ignoreErrors === true; + this._onUnsupportedFeature = onUnsupportedFeature; + this.fontRegistry = fontRegistry; + } + + _createClass(FontFaceObject, [{ + key: 'createNativeFontFace', + value: function createNativeFontFace() { + if (!this.data || this.disableFontFace) { + return null; + } + var nativeFontFace = new FontFace(this.loadedName, this.data, {}); + if (this.fontRegistry) { + this.fontRegistry.registerFont(this); + } + return nativeFontFace; + } + }, { + key: 'createFontFaceRule', + value: function createFontFaceRule() { + if (!this.data || this.disableFontFace) { + return null; + } + var data = (0, _util.bytesToString)(new Uint8Array(this.data)); + var url = 'url(data:' + this.mimetype + ';base64,' + btoa(data) + ');'; + var rule = '@font-face {font-family:"' + this.loadedName + '";src:' + url + '}'; + if (this.fontRegistry) { + this.fontRegistry.registerFont(this, url); + } + return rule; + } + }, { + key: 'getPathGenerator', + value: function getPathGenerator(objs, character) { + if (this.compiledGlyphs[character] !== undefined) { + return this.compiledGlyphs[character]; + } + var cmds = void 0, + current = void 0; + try { + cmds = objs.get(this.loadedName + '_path_' + character); + } catch (ex) { + if (!this.ignoreErrors) { + throw ex; + } + if (this._onUnsupportedFeature) { + this._onUnsupportedFeature({ featureId: _util.UNSUPPORTED_FEATURES.font }); + } + (0, _util.warn)('getPathGenerator - ignoring character: "' + ex + '".'); + return this.compiledGlyphs[character] = function (c, size) {}; + } + if (this.isEvalSupported && IsEvalSupportedCached.value) { + var args = void 0, + js = ''; + for (var i = 0, ii = cmds.length; i < ii; i++) { + current = cmds[i]; + if (current.args !== undefined) { + args = current.args.join(','); + } else { + args = ''; + } + js += 'c.' + current.cmd + '(' + args + ');\n'; + } + return this.compiledGlyphs[character] = new Function('c', 'size', js); + } + return this.compiledGlyphs[character] = function (c, size) { + for (var _i = 0, _ii = cmds.length; _i < _ii; _i++) { + current = cmds[_i]; + if (current.cmd === 'scale') { + current.args = [size, -size]; + } + c[current.cmd].apply(c, current.args); + } + }; + } + }]); + + return FontFaceObject; +}(); + +exports.FontFaceObject = FontFaceObject; +exports.FontLoader = FontLoader; + +/***/ }), +/* 132 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var compatibilityParams = Object.create(null); +{ + var isNodeJS = __w_pdfjs_require__(4); + var userAgent = typeof navigator !== 'undefined' && navigator.userAgent || ''; + var isIE = /Trident/.test(userAgent); + var isIOSChrome = /CriOS/.test(userAgent); + (function checkOnBlobSupport() { + if (isIE || isIOSChrome) { + compatibilityParams.disableCreateObjectURL = true; + } + })(); + (function checkFontFaceAndImage() { + if (isNodeJS()) { + compatibilityParams.disableFontFace = true; + compatibilityParams.nativeImageDecoderSupport = 'none'; + } + })(); +} +exports.apiCompatibilityParams = Object.freeze(compatibilityParams); + +/***/ }), +/* 133 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.CanvasGraphics = undefined; + +var _util = __w_pdfjs_require__(1); + +var _pattern_helper = __w_pdfjs_require__(134); + +var MIN_FONT_SIZE = 16; +var MAX_FONT_SIZE = 100; +var MAX_GROUP_SIZE = 4096; +var MIN_WIDTH_FACTOR = 0.65; +var COMPILE_TYPE3_GLYPHS = true; +var MAX_SIZE_TO_COMPILE = 1000; +var FULL_CHUNK_HEIGHT = 16; +var IsLittleEndianCached = { + get value() { + return (0, _util.shadow)(IsLittleEndianCached, 'value', (0, _util.isLittleEndian)()); + } +}; +function addContextCurrentTransform(ctx) { + if (!ctx.mozCurrentTransform) { + ctx._originalSave = ctx.save; + ctx._originalRestore = ctx.restore; + ctx._originalRotate = ctx.rotate; + ctx._originalScale = ctx.scale; + ctx._originalTranslate = ctx.translate; + ctx._originalTransform = ctx.transform; + ctx._originalSetTransform = ctx.setTransform; + ctx._transformMatrix = ctx._transformMatrix || [1, 0, 0, 1, 0, 0]; + ctx._transformStack = []; + Object.defineProperty(ctx, 'mozCurrentTransform', { + get: function getCurrentTransform() { + return this._transformMatrix; + } + }); + Object.defineProperty(ctx, 'mozCurrentTransformInverse', { + get: function getCurrentTransformInverse() { + var m = this._transformMatrix; + var a = m[0], + b = m[1], + c = m[2], + d = m[3], + e = m[4], + f = m[5]; + var ad_bc = a * d - b * c; + var bc_ad = b * c - a * d; + return [d / ad_bc, b / bc_ad, c / bc_ad, a / ad_bc, (d * e - c * f) / bc_ad, (b * e - a * f) / ad_bc]; + } + }); + ctx.save = function ctxSave() { + var old = this._transformMatrix; + this._transformStack.push(old); + this._transformMatrix = old.slice(0, 6); + this._originalSave(); + }; + ctx.restore = function ctxRestore() { + var prev = this._transformStack.pop(); + if (prev) { + this._transformMatrix = prev; + this._originalRestore(); + } + }; + ctx.translate = function ctxTranslate(x, y) { + var m = this._transformMatrix; + m[4] = m[0] * x + m[2] * y + m[4]; + m[5] = m[1] * x + m[3] * y + m[5]; + this._originalTranslate(x, y); + }; + ctx.scale = function ctxScale(x, y) { + var m = this._transformMatrix; + m[0] = m[0] * x; + m[1] = m[1] * x; + m[2] = m[2] * y; + m[3] = m[3] * y; + this._originalScale(x, y); + }; + ctx.transform = function ctxTransform(a, b, c, d, e, f) { + var m = this._transformMatrix; + this._transformMatrix = [m[0] * a + m[2] * b, m[1] * a + m[3] * b, m[0] * c + m[2] * d, m[1] * c + m[3] * d, m[0] * e + m[2] * f + m[4], m[1] * e + m[3] * f + m[5]]; + ctx._originalTransform(a, b, c, d, e, f); + }; + ctx.setTransform = function ctxSetTransform(a, b, c, d, e, f) { + this._transformMatrix = [a, b, c, d, e, f]; + ctx._originalSetTransform(a, b, c, d, e, f); + }; + ctx.rotate = function ctxRotate(angle) { + var cosValue = Math.cos(angle); + var sinValue = Math.sin(angle); + var m = this._transformMatrix; + this._transformMatrix = [m[0] * cosValue + m[2] * sinValue, m[1] * cosValue + m[3] * sinValue, m[0] * -sinValue + m[2] * cosValue, m[1] * -sinValue + m[3] * cosValue, m[4], m[5]]; + this._originalRotate(angle); + }; + } +} +var CachedCanvases = function CachedCanvasesClosure() { + function CachedCanvases(canvasFactory) { + this.canvasFactory = canvasFactory; + this.cache = Object.create(null); + } + CachedCanvases.prototype = { + getCanvas: function CachedCanvases_getCanvas(id, width, height, trackTransform) { + var canvasEntry; + if (this.cache[id] !== undefined) { + canvasEntry = this.cache[id]; + this.canvasFactory.reset(canvasEntry, width, height); + canvasEntry.context.setTransform(1, 0, 0, 1, 0, 0); + } else { + canvasEntry = this.canvasFactory.create(width, height); + this.cache[id] = canvasEntry; + } + if (trackTransform) { + addContextCurrentTransform(canvasEntry.context); + } + return canvasEntry; + }, + clear: function clear() { + for (var id in this.cache) { + var canvasEntry = this.cache[id]; + this.canvasFactory.destroy(canvasEntry); + delete this.cache[id]; + } + } + }; + return CachedCanvases; +}(); +function compileType3Glyph(imgData) { + var POINT_TO_PROCESS_LIMIT = 1000; + var width = imgData.width, + height = imgData.height; + var i, + j, + j0, + width1 = width + 1; + var points = new Uint8Array(width1 * (height + 1)); + var POINT_TYPES = new Uint8Array([0, 2, 4, 0, 1, 0, 5, 4, 8, 10, 0, 8, 0, 2, 1, 0]); + var lineSize = width + 7 & ~7, + data0 = imgData.data; + var data = new Uint8Array(lineSize * height), + pos = 0, + ii; + for (i = 0, ii = data0.length; i < ii; i++) { + var mask = 128, + elem = data0[i]; + while (mask > 0) { + data[pos++] = elem & mask ? 0 : 255; + mask >>= 1; + } + } + var count = 0; + pos = 0; + if (data[pos] !== 0) { + points[0] = 1; + ++count; + } + for (j = 1; j < width; j++) { + if (data[pos] !== data[pos + 1]) { + points[j] = data[pos] ? 2 : 1; + ++count; + } + pos++; + } + if (data[pos] !== 0) { + points[j] = 2; + ++count; + } + for (i = 1; i < height; i++) { + pos = i * lineSize; + j0 = i * width1; + if (data[pos - lineSize] !== data[pos]) { + points[j0] = data[pos] ? 1 : 8; + ++count; + } + var sum = (data[pos] ? 4 : 0) + (data[pos - lineSize] ? 8 : 0); + for (j = 1; j < width; j++) { + sum = (sum >> 2) + (data[pos + 1] ? 4 : 0) + (data[pos - lineSize + 1] ? 8 : 0); + if (POINT_TYPES[sum]) { + points[j0 + j] = POINT_TYPES[sum]; + ++count; + } + pos++; + } + if (data[pos - lineSize] !== data[pos]) { + points[j0 + j] = data[pos] ? 2 : 4; + ++count; + } + if (count > POINT_TO_PROCESS_LIMIT) { + return null; + } + } + pos = lineSize * (height - 1); + j0 = i * width1; + if (data[pos] !== 0) { + points[j0] = 8; + ++count; + } + for (j = 1; j < width; j++) { + if (data[pos] !== data[pos + 1]) { + points[j0 + j] = data[pos] ? 4 : 8; + ++count; + } + pos++; + } + if (data[pos] !== 0) { + points[j0 + j] = 4; + ++count; + } + if (count > POINT_TO_PROCESS_LIMIT) { + return null; + } + var steps = new Int32Array([0, width1, -1, 0, -width1, 0, 0, 0, 1]); + var outlines = []; + for (i = 0; count && i <= height; i++) { + var p = i * width1; + var end = p + width; + while (p < end && !points[p]) { + p++; + } + if (p === end) { + continue; + } + var coords = [p % width1, i]; + var type = points[p], + p0 = p, + pp; + do { + var step = steps[type]; + do { + p += step; + } while (!points[p]); + pp = points[p]; + if (pp !== 5 && pp !== 10) { + type = pp; + points[p] = 0; + } else { + type = pp & 0x33 * type >> 4; + points[p] &= type >> 2 | type << 2; + } + coords.push(p % width1); + coords.push(p / width1 | 0); + --count; + } while (p0 !== p); + outlines.push(coords); + --i; + } + var drawOutline = function drawOutline(c) { + c.save(); + c.scale(1 / width, -1 / height); + c.translate(0, -height); + c.beginPath(); + for (var i = 0, ii = outlines.length; i < ii; i++) { + var o = outlines[i]; + c.moveTo(o[0], o[1]); + for (var j = 2, jj = o.length; j < jj; j += 2) { + c.lineTo(o[j], o[j + 1]); + } + } + c.fill(); + c.beginPath(); + c.restore(); + }; + return drawOutline; +} +var CanvasExtraState = function CanvasExtraStateClosure() { + function CanvasExtraState() { + this.alphaIsShape = false; + this.fontSize = 0; + this.fontSizeScale = 1; + this.textMatrix = _util.IDENTITY_MATRIX; + this.textMatrixScale = 1; + this.fontMatrix = _util.FONT_IDENTITY_MATRIX; + this.leading = 0; + this.x = 0; + this.y = 0; + this.lineX = 0; + this.lineY = 0; + this.charSpacing = 0; + this.wordSpacing = 0; + this.textHScale = 1; + this.textRenderingMode = _util.TextRenderingMode.FILL; + this.textRise = 0; + this.fillColor = '#000000'; + this.strokeColor = '#000000'; + this.patternFill = false; + this.fillAlpha = 1; + this.strokeAlpha = 1; + this.lineWidth = 1; + this.activeSMask = null; + this.resumeSMaskCtx = null; + } + CanvasExtraState.prototype = { + clone: function CanvasExtraState_clone() { + return Object.create(this); + }, + setCurrentPoint: function CanvasExtraState_setCurrentPoint(x, y) { + this.x = x; + this.y = y; + } + }; + return CanvasExtraState; +}(); +var CanvasGraphics = function CanvasGraphicsClosure() { + var EXECUTION_TIME = 15; + var EXECUTION_STEPS = 10; + function CanvasGraphics(canvasCtx, commonObjs, objs, canvasFactory, webGLContext, imageLayer) { + this.ctx = canvasCtx; + this.current = new CanvasExtraState(); + this.stateStack = []; + this.pendingClip = null; + this.pendingEOFill = false; + this.res = null; + this.xobjs = null; + this.commonObjs = commonObjs; + this.objs = objs; + this.canvasFactory = canvasFactory; + this.webGLContext = webGLContext; + this.imageLayer = imageLayer; + this.groupStack = []; + this.processingType3 = null; + this.baseTransform = null; + this.baseTransformStack = []; + this.groupLevel = 0; + this.smaskStack = []; + this.smaskCounter = 0; + this.tempSMask = null; + this.cachedCanvases = new CachedCanvases(this.canvasFactory); + if (canvasCtx) { + addContextCurrentTransform(canvasCtx); + } + this._cachedGetSinglePixelWidth = null; + } + function putBinaryImageData(ctx, imgData) { + if (typeof ImageData !== 'undefined' && imgData instanceof ImageData) { + ctx.putImageData(imgData, 0, 0); + return; + } + var height = imgData.height, + width = imgData.width; + var partialChunkHeight = height % FULL_CHUNK_HEIGHT; + var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT; + var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1; + var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT); + var srcPos = 0, + destPos; + var src = imgData.data; + var dest = chunkImgData.data; + var i, j, thisChunkHeight, elemsInThisChunk; + if (imgData.kind === _util.ImageKind.GRAYSCALE_1BPP) { + var srcLength = src.byteLength; + var dest32 = new Uint32Array(dest.buffer, 0, dest.byteLength >> 2); + var dest32DataLength = dest32.length; + var fullSrcDiff = width + 7 >> 3; + var white = 0xFFFFFFFF; + var black = IsLittleEndianCached.value ? 0xFF000000 : 0x000000FF; + for (i = 0; i < totalChunks; i++) { + thisChunkHeight = i < fullChunks ? FULL_CHUNK_HEIGHT : partialChunkHeight; + destPos = 0; + for (j = 0; j < thisChunkHeight; j++) { + var srcDiff = srcLength - srcPos; + var k = 0; + var kEnd = srcDiff > fullSrcDiff ? width : srcDiff * 8 - 7; + var kEndUnrolled = kEnd & ~7; + var mask = 0; + var srcByte = 0; + for (; k < kEndUnrolled; k += 8) { + srcByte = src[srcPos++]; + dest32[destPos++] = srcByte & 128 ? white : black; + dest32[destPos++] = srcByte & 64 ? white : black; + dest32[destPos++] = srcByte & 32 ? white : black; + dest32[destPos++] = srcByte & 16 ? white : black; + dest32[destPos++] = srcByte & 8 ? white : black; + dest32[destPos++] = srcByte & 4 ? white : black; + dest32[destPos++] = srcByte & 2 ? white : black; + dest32[destPos++] = srcByte & 1 ? white : black; + } + for (; k < kEnd; k++) { + if (mask === 0) { + srcByte = src[srcPos++]; + mask = 128; + } + dest32[destPos++] = srcByte & mask ? white : black; + mask >>= 1; + } + } + while (destPos < dest32DataLength) { + dest32[destPos++] = 0; + } + ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT); + } + } else if (imgData.kind === _util.ImageKind.RGBA_32BPP) { + j = 0; + elemsInThisChunk = width * FULL_CHUNK_HEIGHT * 4; + for (i = 0; i < fullChunks; i++) { + dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk)); + srcPos += elemsInThisChunk; + ctx.putImageData(chunkImgData, 0, j); + j += FULL_CHUNK_HEIGHT; + } + if (i < totalChunks) { + elemsInThisChunk = width * partialChunkHeight * 4; + dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk)); + ctx.putImageData(chunkImgData, 0, j); + } + } else if (imgData.kind === _util.ImageKind.RGB_24BPP) { + thisChunkHeight = FULL_CHUNK_HEIGHT; + elemsInThisChunk = width * thisChunkHeight; + for (i = 0; i < totalChunks; i++) { + if (i >= fullChunks) { + thisChunkHeight = partialChunkHeight; + elemsInThisChunk = width * thisChunkHeight; + } + destPos = 0; + for (j = elemsInThisChunk; j--;) { + dest[destPos++] = src[srcPos++]; + dest[destPos++] = src[srcPos++]; + dest[destPos++] = src[srcPos++]; + dest[destPos++] = 255; + } + ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT); + } + } else { + throw new Error('bad image kind: ' + imgData.kind); + } + } + function putBinaryImageMask(ctx, imgData) { + var height = imgData.height, + width = imgData.width; + var partialChunkHeight = height % FULL_CHUNK_HEIGHT; + var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT; + var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1; + var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT); + var srcPos = 0; + var src = imgData.data; + var dest = chunkImgData.data; + for (var i = 0; i < totalChunks; i++) { + var thisChunkHeight = i < fullChunks ? FULL_CHUNK_HEIGHT : partialChunkHeight; + var destPos = 3; + for (var j = 0; j < thisChunkHeight; j++) { + var mask = 0; + for (var k = 0; k < width; k++) { + if (!mask) { + var elem = src[srcPos++]; + mask = 128; + } + dest[destPos] = elem & mask ? 0 : 255; + destPos += 4; + mask >>= 1; + } + } + ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT); + } + } + function copyCtxState(sourceCtx, destCtx) { + var properties = ['strokeStyle', 'fillStyle', 'fillRule', 'globalAlpha', 'lineWidth', 'lineCap', 'lineJoin', 'miterLimit', 'globalCompositeOperation', 'font']; + for (var i = 0, ii = properties.length; i < ii; i++) { + var property = properties[i]; + if (sourceCtx[property] !== undefined) { + destCtx[property] = sourceCtx[property]; + } + } + if (sourceCtx.setLineDash !== undefined) { + destCtx.setLineDash(sourceCtx.getLineDash()); + destCtx.lineDashOffset = sourceCtx.lineDashOffset; + } + } + function resetCtxToDefault(ctx) { + ctx.strokeStyle = '#000000'; + ctx.fillStyle = '#000000'; + ctx.fillRule = 'nonzero'; + ctx.globalAlpha = 1; + ctx.lineWidth = 1; + ctx.lineCap = 'butt'; + ctx.lineJoin = 'miter'; + ctx.miterLimit = 10; + ctx.globalCompositeOperation = 'source-over'; + ctx.font = '10px sans-serif'; + if (ctx.setLineDash !== undefined) { + ctx.setLineDash([]); + ctx.lineDashOffset = 0; + } + } + function composeSMaskBackdrop(bytes, r0, g0, b0) { + var length = bytes.length; + for (var i = 3; i < length; i += 4) { + var alpha = bytes[i]; + if (alpha === 0) { + bytes[i - 3] = r0; + bytes[i - 2] = g0; + bytes[i - 1] = b0; + } else if (alpha < 255) { + var alpha_ = 255 - alpha; + bytes[i - 3] = bytes[i - 3] * alpha + r0 * alpha_ >> 8; + bytes[i - 2] = bytes[i - 2] * alpha + g0 * alpha_ >> 8; + bytes[i - 1] = bytes[i - 1] * alpha + b0 * alpha_ >> 8; + } + } + } + function composeSMaskAlpha(maskData, layerData, transferMap) { + var length = maskData.length; + var scale = 1 / 255; + for (var i = 3; i < length; i += 4) { + var alpha = transferMap ? transferMap[maskData[i]] : maskData[i]; + layerData[i] = layerData[i] * alpha * scale | 0; + } + } + function composeSMaskLuminosity(maskData, layerData, transferMap) { + var length = maskData.length; + for (var i = 3; i < length; i += 4) { + var y = maskData[i - 3] * 77 + maskData[i - 2] * 152 + maskData[i - 1] * 28; + layerData[i] = transferMap ? layerData[i] * transferMap[y >> 8] >> 8 : layerData[i] * y >> 16; + } + } + function genericComposeSMask(maskCtx, layerCtx, width, height, subtype, backdrop, transferMap) { + var hasBackdrop = !!backdrop; + var r0 = hasBackdrop ? backdrop[0] : 0; + var g0 = hasBackdrop ? backdrop[1] : 0; + var b0 = hasBackdrop ? backdrop[2] : 0; + var composeFn; + if (subtype === 'Luminosity') { + composeFn = composeSMaskLuminosity; + } else { + composeFn = composeSMaskAlpha; + } + var PIXELS_TO_PROCESS = 1048576; + var chunkSize = Math.min(height, Math.ceil(PIXELS_TO_PROCESS / width)); + for (var row = 0; row < height; row += chunkSize) { + var chunkHeight = Math.min(chunkSize, height - row); + var maskData = maskCtx.getImageData(0, row, width, chunkHeight); + var layerData = layerCtx.getImageData(0, row, width, chunkHeight); + if (hasBackdrop) { + composeSMaskBackdrop(maskData.data, r0, g0, b0); + } + composeFn(maskData.data, layerData.data, transferMap); + maskCtx.putImageData(layerData, 0, row); + } + } + function composeSMask(ctx, smask, layerCtx, webGLContext) { + var mask = smask.canvas; + var maskCtx = smask.context; + ctx.setTransform(smask.scaleX, 0, 0, smask.scaleY, smask.offsetX, smask.offsetY); + var backdrop = smask.backdrop || null; + if (!smask.transferMap && webGLContext.isEnabled) { + var composed = webGLContext.composeSMask({ + layer: layerCtx.canvas, + mask: mask, + properties: { + subtype: smask.subtype, + backdrop: backdrop + } + }); + ctx.setTransform(1, 0, 0, 1, 0, 0); + ctx.drawImage(composed, smask.offsetX, smask.offsetY); + return; + } + genericComposeSMask(maskCtx, layerCtx, mask.width, mask.height, smask.subtype, backdrop, smask.transferMap); + ctx.drawImage(mask, 0, 0); + } + var LINE_CAP_STYLES = ['butt', 'round', 'square']; + var LINE_JOIN_STYLES = ['miter', 'round', 'bevel']; + var NORMAL_CLIP = {}; + var EO_CLIP = {}; + CanvasGraphics.prototype = { + beginDrawing: function beginDrawing(_ref) { + var transform = _ref.transform, + viewport = _ref.viewport, + transparency = _ref.transparency, + _ref$background = _ref.background, + background = _ref$background === undefined ? null : _ref$background; + + var width = this.ctx.canvas.width; + var height = this.ctx.canvas.height; + this.ctx.save(); + this.ctx.fillStyle = background || 'rgb(255, 255, 255)'; + this.ctx.fillRect(0, 0, width, height); + this.ctx.restore(); + if (transparency) { + var transparentCanvas = this.cachedCanvases.getCanvas('transparent', width, height, true); + this.compositeCtx = this.ctx; + this.transparentCanvas = transparentCanvas.canvas; + this.ctx = transparentCanvas.context; + this.ctx.save(); + this.ctx.transform.apply(this.ctx, this.compositeCtx.mozCurrentTransform); + } + this.ctx.save(); + resetCtxToDefault(this.ctx); + if (transform) { + this.ctx.transform.apply(this.ctx, transform); + } + this.ctx.transform.apply(this.ctx, viewport.transform); + this.baseTransform = this.ctx.mozCurrentTransform.slice(); + if (this.imageLayer) { + this.imageLayer.beginLayout(); + } + }, + + executeOperatorList: function CanvasGraphics_executeOperatorList(operatorList, executionStartIdx, continueCallback, stepper) { + var argsArray = operatorList.argsArray; + var fnArray = operatorList.fnArray; + var i = executionStartIdx || 0; + var argsArrayLen = argsArray.length; + if (argsArrayLen === i) { + return i; + } + var chunkOperations = argsArrayLen - i > EXECUTION_STEPS && typeof continueCallback === 'function'; + var endTime = chunkOperations ? Date.now() + EXECUTION_TIME : 0; + var steps = 0; + var commonObjs = this.commonObjs; + var objs = this.objs; + var fnId; + while (true) { + if (stepper !== undefined && i === stepper.nextBreakPoint) { + stepper.breakIt(i, continueCallback); + return i; + } + fnId = fnArray[i]; + if (fnId !== _util.OPS.dependency) { + this[fnId].apply(this, argsArray[i]); + } else { + var deps = argsArray[i]; + for (var n = 0, nn = deps.length; n < nn; n++) { + var depObjId = deps[n]; + var common = depObjId[0] === 'g' && depObjId[1] === '_'; + var objsPool = common ? commonObjs : objs; + if (!objsPool.isResolved(depObjId)) { + objsPool.get(depObjId, continueCallback); + return i; + } + } + } + i++; + if (i === argsArrayLen) { + return i; + } + if (chunkOperations && ++steps > EXECUTION_STEPS) { + if (Date.now() > endTime) { + continueCallback(); + return i; + } + steps = 0; + } + } + }, + endDrawing: function CanvasGraphics_endDrawing() { + if (this.current.activeSMask !== null) { + this.endSMaskGroup(); + } + this.ctx.restore(); + if (this.transparentCanvas) { + this.ctx = this.compositeCtx; + this.ctx.save(); + this.ctx.setTransform(1, 0, 0, 1, 0, 0); + this.ctx.drawImage(this.transparentCanvas, 0, 0); + this.ctx.restore(); + this.transparentCanvas = null; + } + this.cachedCanvases.clear(); + this.webGLContext.clear(); + if (this.imageLayer) { + this.imageLayer.endLayout(); + } + }, + setLineWidth: function CanvasGraphics_setLineWidth(width) { + this.current.lineWidth = width; + this.ctx.lineWidth = width; + }, + setLineCap: function CanvasGraphics_setLineCap(style) { + this.ctx.lineCap = LINE_CAP_STYLES[style]; + }, + setLineJoin: function CanvasGraphics_setLineJoin(style) { + this.ctx.lineJoin = LINE_JOIN_STYLES[style]; + }, + setMiterLimit: function CanvasGraphics_setMiterLimit(limit) { + this.ctx.miterLimit = limit; + }, + setDash: function CanvasGraphics_setDash(dashArray, dashPhase) { + var ctx = this.ctx; + if (ctx.setLineDash !== undefined) { + ctx.setLineDash(dashArray); + ctx.lineDashOffset = dashPhase; + } + }, + setRenderingIntent: function CanvasGraphics_setRenderingIntent(intent) {}, + setFlatness: function CanvasGraphics_setFlatness(flatness) {}, + setGState: function CanvasGraphics_setGState(states) { + for (var i = 0, ii = states.length; i < ii; i++) { + var state = states[i]; + var key = state[0]; + var value = state[1]; + switch (key) { + case 'LW': + this.setLineWidth(value); + break; + case 'LC': + this.setLineCap(value); + break; + case 'LJ': + this.setLineJoin(value); + break; + case 'ML': + this.setMiterLimit(value); + break; + case 'D': + this.setDash(value[0], value[1]); + break; + case 'RI': + this.setRenderingIntent(value); + break; + case 'FL': + this.setFlatness(value); + break; + case 'Font': + this.setFont(value[0], value[1]); + break; + case 'CA': + this.current.strokeAlpha = state[1]; + break; + case 'ca': + this.current.fillAlpha = state[1]; + this.ctx.globalAlpha = state[1]; + break; + case 'BM': + this.ctx.globalCompositeOperation = value; + break; + case 'SMask': + if (this.current.activeSMask) { + if (this.stateStack.length > 0 && this.stateStack[this.stateStack.length - 1].activeSMask === this.current.activeSMask) { + this.suspendSMaskGroup(); + } else { + this.endSMaskGroup(); + } + } + this.current.activeSMask = value ? this.tempSMask : null; + if (this.current.activeSMask) { + this.beginSMaskGroup(); + } + this.tempSMask = null; + break; + } + } + }, + beginSMaskGroup: function CanvasGraphics_beginSMaskGroup() { + var activeSMask = this.current.activeSMask; + var drawnWidth = activeSMask.canvas.width; + var drawnHeight = activeSMask.canvas.height; + var cacheId = 'smaskGroupAt' + this.groupLevel; + var scratchCanvas = this.cachedCanvases.getCanvas(cacheId, drawnWidth, drawnHeight, true); + var currentCtx = this.ctx; + var currentTransform = currentCtx.mozCurrentTransform; + this.ctx.save(); + var groupCtx = scratchCanvas.context; + groupCtx.scale(1 / activeSMask.scaleX, 1 / activeSMask.scaleY); + groupCtx.translate(-activeSMask.offsetX, -activeSMask.offsetY); + groupCtx.transform.apply(groupCtx, currentTransform); + activeSMask.startTransformInverse = groupCtx.mozCurrentTransformInverse; + copyCtxState(currentCtx, groupCtx); + this.ctx = groupCtx; + this.setGState([['BM', 'source-over'], ['ca', 1], ['CA', 1]]); + this.groupStack.push(currentCtx); + this.groupLevel++; + }, + suspendSMaskGroup: function CanvasGraphics_endSMaskGroup() { + var groupCtx = this.ctx; + this.groupLevel--; + this.ctx = this.groupStack.pop(); + composeSMask(this.ctx, this.current.activeSMask, groupCtx, this.webGLContext); + this.ctx.restore(); + this.ctx.save(); + copyCtxState(groupCtx, this.ctx); + this.current.resumeSMaskCtx = groupCtx; + var deltaTransform = _util.Util.transform(this.current.activeSMask.startTransformInverse, groupCtx.mozCurrentTransform); + this.ctx.transform.apply(this.ctx, deltaTransform); + groupCtx.save(); + groupCtx.setTransform(1, 0, 0, 1, 0, 0); + groupCtx.clearRect(0, 0, groupCtx.canvas.width, groupCtx.canvas.height); + groupCtx.restore(); + }, + resumeSMaskGroup: function CanvasGraphics_endSMaskGroup() { + var groupCtx = this.current.resumeSMaskCtx; + var currentCtx = this.ctx; + this.ctx = groupCtx; + this.groupStack.push(currentCtx); + this.groupLevel++; + }, + endSMaskGroup: function CanvasGraphics_endSMaskGroup() { + var groupCtx = this.ctx; + this.groupLevel--; + this.ctx = this.groupStack.pop(); + composeSMask(this.ctx, this.current.activeSMask, groupCtx, this.webGLContext); + this.ctx.restore(); + copyCtxState(groupCtx, this.ctx); + var deltaTransform = _util.Util.transform(this.current.activeSMask.startTransformInverse, groupCtx.mozCurrentTransform); + this.ctx.transform.apply(this.ctx, deltaTransform); + }, + save: function CanvasGraphics_save() { + this.ctx.save(); + var old = this.current; + this.stateStack.push(old); + this.current = old.clone(); + this.current.resumeSMaskCtx = null; + }, + restore: function CanvasGraphics_restore() { + if (this.current.resumeSMaskCtx) { + this.resumeSMaskGroup(); + } + if (this.current.activeSMask !== null && (this.stateStack.length === 0 || this.stateStack[this.stateStack.length - 1].activeSMask !== this.current.activeSMask)) { + this.endSMaskGroup(); + } + if (this.stateStack.length !== 0) { + this.current = this.stateStack.pop(); + this.ctx.restore(); + this.pendingClip = null; + this._cachedGetSinglePixelWidth = null; + } + }, + transform: function CanvasGraphics_transform(a, b, c, d, e, f) { + this.ctx.transform(a, b, c, d, e, f); + this._cachedGetSinglePixelWidth = null; + }, + constructPath: function CanvasGraphics_constructPath(ops, args) { + var ctx = this.ctx; + var current = this.current; + var x = current.x, + y = current.y; + for (var i = 0, j = 0, ii = ops.length; i < ii; i++) { + switch (ops[i] | 0) { + case _util.OPS.rectangle: + x = args[j++]; + y = args[j++]; + var width = args[j++]; + var height = args[j++]; + if (width === 0) { + width = this.getSinglePixelWidth(); + } + if (height === 0) { + height = this.getSinglePixelWidth(); + } + var xw = x + width; + var yh = y + height; + this.ctx.moveTo(x, y); + this.ctx.lineTo(xw, y); + this.ctx.lineTo(xw, yh); + this.ctx.lineTo(x, yh); + this.ctx.lineTo(x, y); + this.ctx.closePath(); + break; + case _util.OPS.moveTo: + x = args[j++]; + y = args[j++]; + ctx.moveTo(x, y); + break; + case _util.OPS.lineTo: + x = args[j++]; + y = args[j++]; + ctx.lineTo(x, y); + break; + case _util.OPS.curveTo: + x = args[j + 4]; + y = args[j + 5]; + ctx.bezierCurveTo(args[j], args[j + 1], args[j + 2], args[j + 3], x, y); + j += 6; + break; + case _util.OPS.curveTo2: + ctx.bezierCurveTo(x, y, args[j], args[j + 1], args[j + 2], args[j + 3]); + x = args[j + 2]; + y = args[j + 3]; + j += 4; + break; + case _util.OPS.curveTo3: + x = args[j + 2]; + y = args[j + 3]; + ctx.bezierCurveTo(args[j], args[j + 1], x, y, x, y); + j += 4; + break; + case _util.OPS.closePath: + ctx.closePath(); + break; + } + } + current.setCurrentPoint(x, y); + }, + closePath: function CanvasGraphics_closePath() { + this.ctx.closePath(); + }, + stroke: function CanvasGraphics_stroke(consumePath) { + consumePath = typeof consumePath !== 'undefined' ? consumePath : true; + var ctx = this.ctx; + var strokeColor = this.current.strokeColor; + ctx.lineWidth = Math.max(this.getSinglePixelWidth() * MIN_WIDTH_FACTOR, this.current.lineWidth); + ctx.globalAlpha = this.current.strokeAlpha; + if (strokeColor && strokeColor.hasOwnProperty('type') && strokeColor.type === 'Pattern') { + ctx.save(); + ctx.strokeStyle = strokeColor.getPattern(ctx, this); + ctx.stroke(); + ctx.restore(); + } else { + ctx.stroke(); + } + if (consumePath) { + this.consumePath(); + } + ctx.globalAlpha = this.current.fillAlpha; + }, + closeStroke: function CanvasGraphics_closeStroke() { + this.closePath(); + this.stroke(); + }, + fill: function CanvasGraphics_fill(consumePath) { + consumePath = typeof consumePath !== 'undefined' ? consumePath : true; + var ctx = this.ctx; + var fillColor = this.current.fillColor; + var isPatternFill = this.current.patternFill; + var needRestore = false; + if (isPatternFill) { + ctx.save(); + if (this.baseTransform) { + ctx.setTransform.apply(ctx, this.baseTransform); + } + ctx.fillStyle = fillColor.getPattern(ctx, this); + needRestore = true; + } + if (this.pendingEOFill) { + ctx.fill('evenodd'); + this.pendingEOFill = false; + } else { + ctx.fill(); + } + if (needRestore) { + ctx.restore(); + } + if (consumePath) { + this.consumePath(); + } + }, + eoFill: function CanvasGraphics_eoFill() { + this.pendingEOFill = true; + this.fill(); + }, + fillStroke: function CanvasGraphics_fillStroke() { + this.fill(false); + this.stroke(false); + this.consumePath(); + }, + eoFillStroke: function CanvasGraphics_eoFillStroke() { + this.pendingEOFill = true; + this.fillStroke(); + }, + closeFillStroke: function CanvasGraphics_closeFillStroke() { + this.closePath(); + this.fillStroke(); + }, + closeEOFillStroke: function CanvasGraphics_closeEOFillStroke() { + this.pendingEOFill = true; + this.closePath(); + this.fillStroke(); + }, + endPath: function CanvasGraphics_endPath() { + this.consumePath(); + }, + clip: function CanvasGraphics_clip() { + this.pendingClip = NORMAL_CLIP; + }, + eoClip: function CanvasGraphics_eoClip() { + this.pendingClip = EO_CLIP; + }, + beginText: function CanvasGraphics_beginText() { + this.current.textMatrix = _util.IDENTITY_MATRIX; + this.current.textMatrixScale = 1; + this.current.x = this.current.lineX = 0; + this.current.y = this.current.lineY = 0; + }, + endText: function CanvasGraphics_endText() { + var paths = this.pendingTextPaths; + var ctx = this.ctx; + if (paths === undefined) { + ctx.beginPath(); + return; + } + ctx.save(); + ctx.beginPath(); + for (var i = 0; i < paths.length; i++) { + var path = paths[i]; + ctx.setTransform.apply(ctx, path.transform); + ctx.translate(path.x, path.y); + path.addToPath(ctx, path.fontSize); + } + ctx.restore(); + ctx.clip(); + ctx.beginPath(); + delete this.pendingTextPaths; + }, + setCharSpacing: function CanvasGraphics_setCharSpacing(spacing) { + this.current.charSpacing = spacing; + }, + setWordSpacing: function CanvasGraphics_setWordSpacing(spacing) { + this.current.wordSpacing = spacing; + }, + setHScale: function CanvasGraphics_setHScale(scale) { + this.current.textHScale = scale / 100; + }, + setLeading: function CanvasGraphics_setLeading(leading) { + this.current.leading = -leading; + }, + setFont: function CanvasGraphics_setFont(fontRefName, size) { + var fontObj = this.commonObjs.get(fontRefName); + var current = this.current; + if (!fontObj) { + throw new Error('Can\'t find font for ' + fontRefName); + } + current.fontMatrix = fontObj.fontMatrix ? fontObj.fontMatrix : _util.FONT_IDENTITY_MATRIX; + if (current.fontMatrix[0] === 0 || current.fontMatrix[3] === 0) { + (0, _util.warn)('Invalid font matrix for font ' + fontRefName); + } + if (size < 0) { + size = -size; + current.fontDirection = -1; + } else { + current.fontDirection = 1; + } + this.current.font = fontObj; + this.current.fontSize = size; + if (fontObj.isType3Font) { + return; + } + var name = fontObj.loadedName || 'sans-serif'; + var bold = fontObj.black ? '900' : fontObj.bold ? 'bold' : 'normal'; + var italic = fontObj.italic ? 'italic' : 'normal'; + var typeface = '"' + name + '", ' + fontObj.fallbackName; + var browserFontSize = size < MIN_FONT_SIZE ? MIN_FONT_SIZE : size > MAX_FONT_SIZE ? MAX_FONT_SIZE : size; + this.current.fontSizeScale = size / browserFontSize; + var rule = italic + ' ' + bold + ' ' + browserFontSize + 'px ' + typeface; + this.ctx.font = rule; + }, + setTextRenderingMode: function CanvasGraphics_setTextRenderingMode(mode) { + this.current.textRenderingMode = mode; + }, + setTextRise: function CanvasGraphics_setTextRise(rise) { + this.current.textRise = rise; + }, + moveText: function CanvasGraphics_moveText(x, y) { + this.current.x = this.current.lineX += x; + this.current.y = this.current.lineY += y; + }, + setLeadingMoveText: function CanvasGraphics_setLeadingMoveText(x, y) { + this.setLeading(-y); + this.moveText(x, y); + }, + setTextMatrix: function CanvasGraphics_setTextMatrix(a, b, c, d, e, f) { + this.current.textMatrix = [a, b, c, d, e, f]; + this.current.textMatrixScale = Math.sqrt(a * a + b * b); + this.current.x = this.current.lineX = 0; + this.current.y = this.current.lineY = 0; + }, + nextLine: function CanvasGraphics_nextLine() { + this.moveText(0, this.current.leading); + }, + paintChar: function paintChar(character, x, y, patternTransform) { + var ctx = this.ctx; + var current = this.current; + var font = current.font; + var textRenderingMode = current.textRenderingMode; + var fontSize = current.fontSize / current.fontSizeScale; + var fillStrokeMode = textRenderingMode & _util.TextRenderingMode.FILL_STROKE_MASK; + var isAddToPathSet = !!(textRenderingMode & _util.TextRenderingMode.ADD_TO_PATH_FLAG); + var patternFill = current.patternFill && font.data; + var addToPath; + if (font.disableFontFace || isAddToPathSet || patternFill) { + addToPath = font.getPathGenerator(this.commonObjs, character); + } + if (font.disableFontFace || patternFill) { + ctx.save(); + ctx.translate(x, y); + ctx.beginPath(); + addToPath(ctx, fontSize); + if (patternTransform) { + ctx.setTransform.apply(ctx, patternTransform); + } + if (fillStrokeMode === _util.TextRenderingMode.FILL || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) { + ctx.fill(); + } + if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) { + ctx.stroke(); + } + ctx.restore(); + } else { + if (fillStrokeMode === _util.TextRenderingMode.FILL || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) { + ctx.fillText(character, x, y); + } + if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) { + ctx.strokeText(character, x, y); + } + } + if (isAddToPathSet) { + var paths = this.pendingTextPaths || (this.pendingTextPaths = []); + paths.push({ + transform: ctx.mozCurrentTransform, + x: x, + y: y, + fontSize: fontSize, + addToPath: addToPath + }); + } + }, + + get isFontSubpixelAAEnabled() { + var ctx = this.canvasFactory.create(10, 10).context; + ctx.scale(1.5, 1); + ctx.fillText('I', 0, 10); + var data = ctx.getImageData(0, 0, 10, 10).data; + var enabled = false; + for (var i = 3; i < data.length; i += 4) { + if (data[i] > 0 && data[i] < 255) { + enabled = true; + break; + } + } + return (0, _util.shadow)(this, 'isFontSubpixelAAEnabled', enabled); + }, + showText: function CanvasGraphics_showText(glyphs) { + var current = this.current; + var font = current.font; + if (font.isType3Font) { + return this.showType3Text(glyphs); + } + var fontSize = current.fontSize; + if (fontSize === 0) { + return; + } + var ctx = this.ctx; + var fontSizeScale = current.fontSizeScale; + var charSpacing = current.charSpacing; + var wordSpacing = current.wordSpacing; + var fontDirection = current.fontDirection; + var textHScale = current.textHScale * fontDirection; + var glyphsLength = glyphs.length; + var vertical = font.vertical; + var spacingDir = vertical ? 1 : -1; + var defaultVMetrics = font.defaultVMetrics; + var widthAdvanceScale = fontSize * current.fontMatrix[0]; + var simpleFillText = current.textRenderingMode === _util.TextRenderingMode.FILL && !font.disableFontFace && !current.patternFill; + ctx.save(); + var patternTransform = void 0; + if (current.patternFill) { + ctx.save(); + var pattern = current.fillColor.getPattern(ctx, this); + patternTransform = ctx.mozCurrentTransform; + ctx.restore(); + ctx.fillStyle = pattern; + } + ctx.transform.apply(ctx, current.textMatrix); + ctx.translate(current.x, current.y + current.textRise); + if (fontDirection > 0) { + ctx.scale(textHScale, -1); + } else { + ctx.scale(textHScale, 1); + } + var lineWidth = current.lineWidth; + var scale = current.textMatrixScale; + if (scale === 0 || lineWidth === 0) { + var fillStrokeMode = current.textRenderingMode & _util.TextRenderingMode.FILL_STROKE_MASK; + if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) { + this._cachedGetSinglePixelWidth = null; + lineWidth = this.getSinglePixelWidth() * MIN_WIDTH_FACTOR; + } + } else { + lineWidth /= scale; + } + if (fontSizeScale !== 1.0) { + ctx.scale(fontSizeScale, fontSizeScale); + lineWidth /= fontSizeScale; + } + ctx.lineWidth = lineWidth; + var x = 0, + i; + for (i = 0; i < glyphsLength; ++i) { + var glyph = glyphs[i]; + if ((0, _util.isNum)(glyph)) { + x += spacingDir * glyph * fontSize / 1000; + continue; + } + var restoreNeeded = false; + var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing; + var character = glyph.fontChar; + var accent = glyph.accent; + var scaledX, scaledY, scaledAccentX, scaledAccentY; + var width = glyph.width; + if (vertical) { + var vmetric, vx, vy; + vmetric = glyph.vmetric || defaultVMetrics; + vx = glyph.vmetric ? vmetric[1] : width * 0.5; + vx = -vx * widthAdvanceScale; + vy = vmetric[2] * widthAdvanceScale; + width = vmetric ? -vmetric[0] : width; + scaledX = vx / fontSizeScale; + scaledY = (x + vy) / fontSizeScale; + } else { + scaledX = x / fontSizeScale; + scaledY = 0; + } + if (font.remeasure && width > 0) { + var measuredWidth = ctx.measureText(character).width * 1000 / fontSize * fontSizeScale; + if (width < measuredWidth && this.isFontSubpixelAAEnabled) { + var characterScaleX = width / measuredWidth; + restoreNeeded = true; + ctx.save(); + ctx.scale(characterScaleX, 1); + scaledX /= characterScaleX; + } else if (width !== measuredWidth) { + scaledX += (width - measuredWidth) / 2000 * fontSize / fontSizeScale; + } + } + if (glyph.isInFont || font.missingFile) { + if (simpleFillText && !accent) { + ctx.fillText(character, scaledX, scaledY); + } else { + this.paintChar(character, scaledX, scaledY, patternTransform); + if (accent) { + scaledAccentX = scaledX + accent.offset.x / fontSizeScale; + scaledAccentY = scaledY - accent.offset.y / fontSizeScale; + this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY, patternTransform); + } + } + } + var charWidth = width * widthAdvanceScale + spacing * fontDirection; + x += charWidth; + if (restoreNeeded) { + ctx.restore(); + } + } + if (vertical) { + current.y -= x * textHScale; + } else { + current.x += x * textHScale; + } + ctx.restore(); + }, + showType3Text: function CanvasGraphics_showType3Text(glyphs) { + var ctx = this.ctx; + var current = this.current; + var font = current.font; + var fontSize = current.fontSize; + var fontDirection = current.fontDirection; + var spacingDir = font.vertical ? 1 : -1; + var charSpacing = current.charSpacing; + var wordSpacing = current.wordSpacing; + var textHScale = current.textHScale * fontDirection; + var fontMatrix = current.fontMatrix || _util.FONT_IDENTITY_MATRIX; + var glyphsLength = glyphs.length; + var isTextInvisible = current.textRenderingMode === _util.TextRenderingMode.INVISIBLE; + var i, glyph, width, spacingLength; + if (isTextInvisible || fontSize === 0) { + return; + } + this._cachedGetSinglePixelWidth = null; + ctx.save(); + ctx.transform.apply(ctx, current.textMatrix); + ctx.translate(current.x, current.y); + ctx.scale(textHScale, fontDirection); + for (i = 0; i < glyphsLength; ++i) { + glyph = glyphs[i]; + if ((0, _util.isNum)(glyph)) { + spacingLength = spacingDir * glyph * fontSize / 1000; + this.ctx.translate(spacingLength, 0); + current.x += spacingLength * textHScale; + continue; + } + var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing; + var operatorList = font.charProcOperatorList[glyph.operatorListId]; + if (!operatorList) { + (0, _util.warn)('Type3 character "' + glyph.operatorListId + '" is not available.'); + continue; + } + this.processingType3 = glyph; + this.save(); + ctx.scale(fontSize, fontSize); + ctx.transform.apply(ctx, fontMatrix); + this.executeOperatorList(operatorList); + this.restore(); + var transformed = _util.Util.applyTransform([glyph.width, 0], fontMatrix); + width = transformed[0] * fontSize + spacing; + ctx.translate(width, 0); + current.x += width * textHScale; + } + ctx.restore(); + this.processingType3 = null; + }, + setCharWidth: function CanvasGraphics_setCharWidth(xWidth, yWidth) {}, + setCharWidthAndBounds: function CanvasGraphics_setCharWidthAndBounds(xWidth, yWidth, llx, lly, urx, ury) { + this.ctx.rect(llx, lly, urx - llx, ury - lly); + this.clip(); + this.endPath(); + }, + getColorN_Pattern: function CanvasGraphics_getColorN_Pattern(IR) { + var _this = this; + + var pattern; + if (IR[0] === 'TilingPattern') { + var color = IR[1]; + var baseTransform = this.baseTransform || this.ctx.mozCurrentTransform.slice(); + var canvasGraphicsFactory = { + createCanvasGraphics: function createCanvasGraphics(ctx) { + return new CanvasGraphics(ctx, _this.commonObjs, _this.objs, _this.canvasFactory, _this.webGLContext); + } + }; + pattern = new _pattern_helper.TilingPattern(IR, color, this.ctx, canvasGraphicsFactory, baseTransform); + } else { + pattern = (0, _pattern_helper.getShadingPatternFromIR)(IR); + } + return pattern; + }, + setStrokeColorN: function CanvasGraphics_setStrokeColorN() { + this.current.strokeColor = this.getColorN_Pattern(arguments); + }, + setFillColorN: function CanvasGraphics_setFillColorN() { + this.current.fillColor = this.getColorN_Pattern(arguments); + this.current.patternFill = true; + }, + setStrokeRGBColor: function CanvasGraphics_setStrokeRGBColor(r, g, b) { + var color = _util.Util.makeCssRgb(r, g, b); + this.ctx.strokeStyle = color; + this.current.strokeColor = color; + }, + setFillRGBColor: function CanvasGraphics_setFillRGBColor(r, g, b) { + var color = _util.Util.makeCssRgb(r, g, b); + this.ctx.fillStyle = color; + this.current.fillColor = color; + this.current.patternFill = false; + }, + shadingFill: function CanvasGraphics_shadingFill(patternIR) { + var ctx = this.ctx; + this.save(); + var pattern = (0, _pattern_helper.getShadingPatternFromIR)(patternIR); + ctx.fillStyle = pattern.getPattern(ctx, this, true); + var inv = ctx.mozCurrentTransformInverse; + if (inv) { + var canvas = ctx.canvas; + var width = canvas.width; + var height = canvas.height; + var bl = _util.Util.applyTransform([0, 0], inv); + var br = _util.Util.applyTransform([0, height], inv); + var ul = _util.Util.applyTransform([width, 0], inv); + var ur = _util.Util.applyTransform([width, height], inv); + var x0 = Math.min(bl[0], br[0], ul[0], ur[0]); + var y0 = Math.min(bl[1], br[1], ul[1], ur[1]); + var x1 = Math.max(bl[0], br[0], ul[0], ur[0]); + var y1 = Math.max(bl[1], br[1], ul[1], ur[1]); + this.ctx.fillRect(x0, y0, x1 - x0, y1 - y0); + } else { + this.ctx.fillRect(-1e10, -1e10, 2e10, 2e10); + } + this.restore(); + }, + beginInlineImage: function CanvasGraphics_beginInlineImage() { + (0, _util.unreachable)('Should not call beginInlineImage'); + }, + beginImageData: function CanvasGraphics_beginImageData() { + (0, _util.unreachable)('Should not call beginImageData'); + }, + paintFormXObjectBegin: function CanvasGraphics_paintFormXObjectBegin(matrix, bbox) { + this.save(); + this.baseTransformStack.push(this.baseTransform); + if (Array.isArray(matrix) && matrix.length === 6) { + this.transform.apply(this, matrix); + } + this.baseTransform = this.ctx.mozCurrentTransform; + if (Array.isArray(bbox) && bbox.length === 4) { + var width = bbox[2] - bbox[0]; + var height = bbox[3] - bbox[1]; + this.ctx.rect(bbox[0], bbox[1], width, height); + this.clip(); + this.endPath(); + } + }, + paintFormXObjectEnd: function CanvasGraphics_paintFormXObjectEnd() { + this.restore(); + this.baseTransform = this.baseTransformStack.pop(); + }, + beginGroup: function CanvasGraphics_beginGroup(group) { + this.save(); + var currentCtx = this.ctx; + if (!group.isolated) { + (0, _util.info)('TODO: Support non-isolated groups.'); + } + if (group.knockout) { + (0, _util.warn)('Knockout groups not supported.'); + } + var currentTransform = currentCtx.mozCurrentTransform; + if (group.matrix) { + currentCtx.transform.apply(currentCtx, group.matrix); + } + if (!group.bbox) { + throw new Error('Bounding box is required.'); + } + var bounds = _util.Util.getAxialAlignedBoundingBox(group.bbox, currentCtx.mozCurrentTransform); + var canvasBounds = [0, 0, currentCtx.canvas.width, currentCtx.canvas.height]; + bounds = _util.Util.intersect(bounds, canvasBounds) || [0, 0, 0, 0]; + var offsetX = Math.floor(bounds[0]); + var offsetY = Math.floor(bounds[1]); + var drawnWidth = Math.max(Math.ceil(bounds[2]) - offsetX, 1); + var drawnHeight = Math.max(Math.ceil(bounds[3]) - offsetY, 1); + var scaleX = 1, + scaleY = 1; + if (drawnWidth > MAX_GROUP_SIZE) { + scaleX = drawnWidth / MAX_GROUP_SIZE; + drawnWidth = MAX_GROUP_SIZE; + } + if (drawnHeight > MAX_GROUP_SIZE) { + scaleY = drawnHeight / MAX_GROUP_SIZE; + drawnHeight = MAX_GROUP_SIZE; + } + var cacheId = 'groupAt' + this.groupLevel; + if (group.smask) { + cacheId += '_smask_' + this.smaskCounter++ % 2; + } + var scratchCanvas = this.cachedCanvases.getCanvas(cacheId, drawnWidth, drawnHeight, true); + var groupCtx = scratchCanvas.context; + groupCtx.scale(1 / scaleX, 1 / scaleY); + groupCtx.translate(-offsetX, -offsetY); + groupCtx.transform.apply(groupCtx, currentTransform); + if (group.smask) { + this.smaskStack.push({ + canvas: scratchCanvas.canvas, + context: groupCtx, + offsetX: offsetX, + offsetY: offsetY, + scaleX: scaleX, + scaleY: scaleY, + subtype: group.smask.subtype, + backdrop: group.smask.backdrop, + transferMap: group.smask.transferMap || null, + startTransformInverse: null + }); + } else { + currentCtx.setTransform(1, 0, 0, 1, 0, 0); + currentCtx.translate(offsetX, offsetY); + currentCtx.scale(scaleX, scaleY); + } + copyCtxState(currentCtx, groupCtx); + this.ctx = groupCtx; + this.setGState([['BM', 'source-over'], ['ca', 1], ['CA', 1]]); + this.groupStack.push(currentCtx); + this.groupLevel++; + this.current.activeSMask = null; + }, + endGroup: function CanvasGraphics_endGroup(group) { + this.groupLevel--; + var groupCtx = this.ctx; + this.ctx = this.groupStack.pop(); + if (this.ctx.imageSmoothingEnabled !== undefined) { + this.ctx.imageSmoothingEnabled = false; + } else { + this.ctx.mozImageSmoothingEnabled = false; + } + if (group.smask) { + this.tempSMask = this.smaskStack.pop(); + } else { + this.ctx.drawImage(groupCtx.canvas, 0, 0); + } + this.restore(); + }, + beginAnnotations: function CanvasGraphics_beginAnnotations() { + this.save(); + if (this.baseTransform) { + this.ctx.setTransform.apply(this.ctx, this.baseTransform); + } + }, + endAnnotations: function CanvasGraphics_endAnnotations() { + this.restore(); + }, + beginAnnotation: function CanvasGraphics_beginAnnotation(rect, transform, matrix) { + this.save(); + resetCtxToDefault(this.ctx); + this.current = new CanvasExtraState(); + if (Array.isArray(rect) && rect.length === 4) { + var width = rect[2] - rect[0]; + var height = rect[3] - rect[1]; + this.ctx.rect(rect[0], rect[1], width, height); + this.clip(); + this.endPath(); + } + this.transform.apply(this, transform); + this.transform.apply(this, matrix); + }, + endAnnotation: function CanvasGraphics_endAnnotation() { + this.restore(); + }, + paintJpegXObject: function CanvasGraphics_paintJpegXObject(objId, w, h) { + var domImage = this.objs.get(objId); + if (!domImage) { + (0, _util.warn)('Dependent image isn\'t ready yet'); + return; + } + this.save(); + var ctx = this.ctx; + ctx.scale(1 / w, -1 / h); + ctx.drawImage(domImage, 0, 0, domImage.width, domImage.height, 0, -h, w, h); + if (this.imageLayer) { + var currentTransform = ctx.mozCurrentTransformInverse; + var position = this.getCanvasPosition(0, 0); + this.imageLayer.appendImage({ + objId: objId, + left: position[0], + top: position[1], + width: w / currentTransform[0], + height: h / currentTransform[3] + }); + } + this.restore(); + }, + paintImageMaskXObject: function CanvasGraphics_paintImageMaskXObject(img) { + var ctx = this.ctx; + var width = img.width, + height = img.height; + var fillColor = this.current.fillColor; + var isPatternFill = this.current.patternFill; + var glyph = this.processingType3; + if (COMPILE_TYPE3_GLYPHS && glyph && glyph.compiled === undefined) { + if (width <= MAX_SIZE_TO_COMPILE && height <= MAX_SIZE_TO_COMPILE) { + glyph.compiled = compileType3Glyph({ + data: img.data, + width: width, + height: height + }); + } else { + glyph.compiled = null; + } + } + if (glyph && glyph.compiled) { + glyph.compiled(ctx); + return; + } + var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas', width, height); + var maskCtx = maskCanvas.context; + maskCtx.save(); + putBinaryImageMask(maskCtx, img); + maskCtx.globalCompositeOperation = 'source-in'; + maskCtx.fillStyle = isPatternFill ? fillColor.getPattern(maskCtx, this) : fillColor; + maskCtx.fillRect(0, 0, width, height); + maskCtx.restore(); + this.paintInlineImageXObject(maskCanvas.canvas); + }, + paintImageMaskXObjectRepeat: function CanvasGraphics_paintImageMaskXObjectRepeat(imgData, scaleX, scaleY, positions) { + var width = imgData.width; + var height = imgData.height; + var fillColor = this.current.fillColor; + var isPatternFill = this.current.patternFill; + var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas', width, height); + var maskCtx = maskCanvas.context; + maskCtx.save(); + putBinaryImageMask(maskCtx, imgData); + maskCtx.globalCompositeOperation = 'source-in'; + maskCtx.fillStyle = isPatternFill ? fillColor.getPattern(maskCtx, this) : fillColor; + maskCtx.fillRect(0, 0, width, height); + maskCtx.restore(); + var ctx = this.ctx; + for (var i = 0, ii = positions.length; i < ii; i += 2) { + ctx.save(); + ctx.transform(scaleX, 0, 0, scaleY, positions[i], positions[i + 1]); + ctx.scale(1, -1); + ctx.drawImage(maskCanvas.canvas, 0, 0, width, height, 0, -1, 1, 1); + ctx.restore(); + } + }, + paintImageMaskXObjectGroup: function CanvasGraphics_paintImageMaskXObjectGroup(images) { + var ctx = this.ctx; + var fillColor = this.current.fillColor; + var isPatternFill = this.current.patternFill; + for (var i = 0, ii = images.length; i < ii; i++) { + var image = images[i]; + var width = image.width, + height = image.height; + var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas', width, height); + var maskCtx = maskCanvas.context; + maskCtx.save(); + putBinaryImageMask(maskCtx, image); + maskCtx.globalCompositeOperation = 'source-in'; + maskCtx.fillStyle = isPatternFill ? fillColor.getPattern(maskCtx, this) : fillColor; + maskCtx.fillRect(0, 0, width, height); + maskCtx.restore(); + ctx.save(); + ctx.transform.apply(ctx, image.transform); + ctx.scale(1, -1); + ctx.drawImage(maskCanvas.canvas, 0, 0, width, height, 0, -1, 1, 1); + ctx.restore(); + } + }, + paintImageXObject: function CanvasGraphics_paintImageXObject(objId) { + var imgData = this.objs.get(objId); + if (!imgData) { + (0, _util.warn)('Dependent image isn\'t ready yet'); + return; + } + this.paintInlineImageXObject(imgData); + }, + paintImageXObjectRepeat: function CanvasGraphics_paintImageXObjectRepeat(objId, scaleX, scaleY, positions) { + var imgData = this.objs.get(objId); + if (!imgData) { + (0, _util.warn)('Dependent image isn\'t ready yet'); + return; + } + var width = imgData.width; + var height = imgData.height; + var map = []; + for (var i = 0, ii = positions.length; i < ii; i += 2) { + map.push({ + transform: [scaleX, 0, 0, scaleY, positions[i], positions[i + 1]], + x: 0, + y: 0, + w: width, + h: height + }); + } + this.paintInlineImageXObjectGroup(imgData, map); + }, + paintInlineImageXObject: function CanvasGraphics_paintInlineImageXObject(imgData) { + var width = imgData.width; + var height = imgData.height; + var ctx = this.ctx; + this.save(); + ctx.scale(1 / width, -1 / height); + var currentTransform = ctx.mozCurrentTransformInverse; + var a = currentTransform[0], + b = currentTransform[1]; + var widthScale = Math.max(Math.sqrt(a * a + b * b), 1); + var c = currentTransform[2], + d = currentTransform[3]; + var heightScale = Math.max(Math.sqrt(c * c + d * d), 1); + var imgToPaint, tmpCanvas; + if (typeof HTMLElement === 'function' && imgData instanceof HTMLElement || !imgData.data) { + imgToPaint = imgData; + } else { + tmpCanvas = this.cachedCanvases.getCanvas('inlineImage', width, height); + var tmpCtx = tmpCanvas.context; + putBinaryImageData(tmpCtx, imgData); + imgToPaint = tmpCanvas.canvas; + } + var paintWidth = width, + paintHeight = height; + var tmpCanvasId = 'prescale1'; + while (widthScale > 2 && paintWidth > 1 || heightScale > 2 && paintHeight > 1) { + var newWidth = paintWidth, + newHeight = paintHeight; + if (widthScale > 2 && paintWidth > 1) { + newWidth = Math.ceil(paintWidth / 2); + widthScale /= paintWidth / newWidth; + } + if (heightScale > 2 && paintHeight > 1) { + newHeight = Math.ceil(paintHeight / 2); + heightScale /= paintHeight / newHeight; + } + tmpCanvas = this.cachedCanvases.getCanvas(tmpCanvasId, newWidth, newHeight); + tmpCtx = tmpCanvas.context; + tmpCtx.clearRect(0, 0, newWidth, newHeight); + tmpCtx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight, 0, 0, newWidth, newHeight); + imgToPaint = tmpCanvas.canvas; + paintWidth = newWidth; + paintHeight = newHeight; + tmpCanvasId = tmpCanvasId === 'prescale1' ? 'prescale2' : 'prescale1'; + } + ctx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight, 0, -height, width, height); + if (this.imageLayer) { + var position = this.getCanvasPosition(0, -height); + this.imageLayer.appendImage({ + imgData: imgData, + left: position[0], + top: position[1], + width: width / currentTransform[0], + height: height / currentTransform[3] + }); + } + this.restore(); + }, + paintInlineImageXObjectGroup: function CanvasGraphics_paintInlineImageXObjectGroup(imgData, map) { + var ctx = this.ctx; + var w = imgData.width; + var h = imgData.height; + var tmpCanvas = this.cachedCanvases.getCanvas('inlineImage', w, h); + var tmpCtx = tmpCanvas.context; + putBinaryImageData(tmpCtx, imgData); + for (var i = 0, ii = map.length; i < ii; i++) { + var entry = map[i]; + ctx.save(); + ctx.transform.apply(ctx, entry.transform); + ctx.scale(1, -1); + ctx.drawImage(tmpCanvas.canvas, entry.x, entry.y, entry.w, entry.h, 0, -1, 1, 1); + if (this.imageLayer) { + var position = this.getCanvasPosition(entry.x, entry.y); + this.imageLayer.appendImage({ + imgData: imgData, + left: position[0], + top: position[1], + width: w, + height: h + }); + } + ctx.restore(); + } + }, + paintSolidColorImageMask: function CanvasGraphics_paintSolidColorImageMask() { + this.ctx.fillRect(0, 0, 1, 1); + }, + paintXObject: function CanvasGraphics_paintXObject() { + (0, _util.warn)('Unsupported \'paintXObject\' command.'); + }, + markPoint: function CanvasGraphics_markPoint(tag) {}, + markPointProps: function CanvasGraphics_markPointProps(tag, properties) {}, + beginMarkedContent: function CanvasGraphics_beginMarkedContent(tag) {}, + beginMarkedContentProps: function CanvasGraphics_beginMarkedContentProps(tag, properties) {}, + endMarkedContent: function CanvasGraphics_endMarkedContent() {}, + beginCompat: function CanvasGraphics_beginCompat() {}, + endCompat: function CanvasGraphics_endCompat() {}, + consumePath: function CanvasGraphics_consumePath() { + var ctx = this.ctx; + if (this.pendingClip) { + if (this.pendingClip === EO_CLIP) { + ctx.clip('evenodd'); + } else { + ctx.clip(); + } + this.pendingClip = null; + } + ctx.beginPath(); + }, + getSinglePixelWidth: function getSinglePixelWidth(scale) { + if (this._cachedGetSinglePixelWidth === null) { + var inverse = this.ctx.mozCurrentTransformInverse; + this._cachedGetSinglePixelWidth = Math.sqrt(Math.max(inverse[0] * inverse[0] + inverse[1] * inverse[1], inverse[2] * inverse[2] + inverse[3] * inverse[3])); + } + return this._cachedGetSinglePixelWidth; + }, + + getCanvasPosition: function CanvasGraphics_getCanvasPosition(x, y) { + var transform = this.ctx.mozCurrentTransform; + return [transform[0] * x + transform[2] * y + transform[4], transform[1] * x + transform[3] * y + transform[5]]; + } + }; + for (var op in _util.OPS) { + CanvasGraphics.prototype[_util.OPS[op]] = CanvasGraphics.prototype[op]; + } + return CanvasGraphics; +}(); +exports.CanvasGraphics = CanvasGraphics; + +/***/ }), +/* 134 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.TilingPattern = exports.getShadingPatternFromIR = undefined; + +var _util = __w_pdfjs_require__(1); + +var ShadingIRs = {}; +ShadingIRs.RadialAxial = { + fromIR: function RadialAxial_fromIR(raw) { + var type = raw[1]; + var colorStops = raw[2]; + var p0 = raw[3]; + var p1 = raw[4]; + var r0 = raw[5]; + var r1 = raw[6]; + return { + type: 'Pattern', + getPattern: function RadialAxial_getPattern(ctx) { + var grad; + if (type === 'axial') { + grad = ctx.createLinearGradient(p0[0], p0[1], p1[0], p1[1]); + } else if (type === 'radial') { + grad = ctx.createRadialGradient(p0[0], p0[1], r0, p1[0], p1[1], r1); + } + for (var i = 0, ii = colorStops.length; i < ii; ++i) { + var c = colorStops[i]; + grad.addColorStop(c[0], c[1]); + } + return grad; + } + }; + } +}; +var createMeshCanvas = function createMeshCanvasClosure() { + function drawTriangle(data, context, p1, p2, p3, c1, c2, c3) { + var coords = context.coords, + colors = context.colors; + var bytes = data.data, + rowSize = data.width * 4; + var tmp; + if (coords[p1 + 1] > coords[p2 + 1]) { + tmp = p1; + p1 = p2; + p2 = tmp; + tmp = c1; + c1 = c2; + c2 = tmp; + } + if (coords[p2 + 1] > coords[p3 + 1]) { + tmp = p2; + p2 = p3; + p3 = tmp; + tmp = c2; + c2 = c3; + c3 = tmp; + } + if (coords[p1 + 1] > coords[p2 + 1]) { + tmp = p1; + p1 = p2; + p2 = tmp; + tmp = c1; + c1 = c2; + c2 = tmp; + } + var x1 = (coords[p1] + context.offsetX) * context.scaleX; + var y1 = (coords[p1 + 1] + context.offsetY) * context.scaleY; + var x2 = (coords[p2] + context.offsetX) * context.scaleX; + var y2 = (coords[p2 + 1] + context.offsetY) * context.scaleY; + var x3 = (coords[p3] + context.offsetX) * context.scaleX; + var y3 = (coords[p3 + 1] + context.offsetY) * context.scaleY; + if (y1 >= y3) { + return; + } + var c1r = colors[c1], + c1g = colors[c1 + 1], + c1b = colors[c1 + 2]; + var c2r = colors[c2], + c2g = colors[c2 + 1], + c2b = colors[c2 + 2]; + var c3r = colors[c3], + c3g = colors[c3 + 1], + c3b = colors[c3 + 2]; + var minY = Math.round(y1), + maxY = Math.round(y3); + var xa, car, cag, cab; + var xb, cbr, cbg, cbb; + var k; + for (var y = minY; y <= maxY; y++) { + if (y < y2) { + k = y < y1 ? 0 : y1 === y2 ? 1 : (y1 - y) / (y1 - y2); + xa = x1 - (x1 - x2) * k; + car = c1r - (c1r - c2r) * k; + cag = c1g - (c1g - c2g) * k; + cab = c1b - (c1b - c2b) * k; + } else { + k = y > y3 ? 1 : y2 === y3 ? 0 : (y2 - y) / (y2 - y3); + xa = x2 - (x2 - x3) * k; + car = c2r - (c2r - c3r) * k; + cag = c2g - (c2g - c3g) * k; + cab = c2b - (c2b - c3b) * k; + } + k = y < y1 ? 0 : y > y3 ? 1 : (y1 - y) / (y1 - y3); + xb = x1 - (x1 - x3) * k; + cbr = c1r - (c1r - c3r) * k; + cbg = c1g - (c1g - c3g) * k; + cbb = c1b - (c1b - c3b) * k; + var x1_ = Math.round(Math.min(xa, xb)); + var x2_ = Math.round(Math.max(xa, xb)); + var j = rowSize * y + x1_ * 4; + for (var x = x1_; x <= x2_; x++) { + k = (xa - x) / (xa - xb); + k = k < 0 ? 0 : k > 1 ? 1 : k; + bytes[j++] = car - (car - cbr) * k | 0; + bytes[j++] = cag - (cag - cbg) * k | 0; + bytes[j++] = cab - (cab - cbb) * k | 0; + bytes[j++] = 255; + } + } + } + function drawFigure(data, figure, context) { + var ps = figure.coords; + var cs = figure.colors; + var i, ii; + switch (figure.type) { + case 'lattice': + var verticesPerRow = figure.verticesPerRow; + var rows = Math.floor(ps.length / verticesPerRow) - 1; + var cols = verticesPerRow - 1; + for (i = 0; i < rows; i++) { + var q = i * verticesPerRow; + for (var j = 0; j < cols; j++, q++) { + drawTriangle(data, context, ps[q], ps[q + 1], ps[q + verticesPerRow], cs[q], cs[q + 1], cs[q + verticesPerRow]); + drawTriangle(data, context, ps[q + verticesPerRow + 1], ps[q + 1], ps[q + verticesPerRow], cs[q + verticesPerRow + 1], cs[q + 1], cs[q + verticesPerRow]); + } + } + break; + case 'triangles': + for (i = 0, ii = ps.length; i < ii; i += 3) { + drawTriangle(data, context, ps[i], ps[i + 1], ps[i + 2], cs[i], cs[i + 1], cs[i + 2]); + } + break; + default: + throw new Error('illegal figure'); + } + } + function createMeshCanvas(bounds, combinesScale, coords, colors, figures, backgroundColor, cachedCanvases, webGLContext) { + var EXPECTED_SCALE = 1.1; + var MAX_PATTERN_SIZE = 3000; + var BORDER_SIZE = 2; + var offsetX = Math.floor(bounds[0]); + var offsetY = Math.floor(bounds[1]); + var boundsWidth = Math.ceil(bounds[2]) - offsetX; + var boundsHeight = Math.ceil(bounds[3]) - offsetY; + var width = Math.min(Math.ceil(Math.abs(boundsWidth * combinesScale[0] * EXPECTED_SCALE)), MAX_PATTERN_SIZE); + var height = Math.min(Math.ceil(Math.abs(boundsHeight * combinesScale[1] * EXPECTED_SCALE)), MAX_PATTERN_SIZE); + var scaleX = boundsWidth / width; + var scaleY = boundsHeight / height; + var context = { + coords: coords, + colors: colors, + offsetX: -offsetX, + offsetY: -offsetY, + scaleX: 1 / scaleX, + scaleY: 1 / scaleY + }; + var paddedWidth = width + BORDER_SIZE * 2; + var paddedHeight = height + BORDER_SIZE * 2; + var canvas, tmpCanvas, i, ii; + if (webGLContext.isEnabled) { + canvas = webGLContext.drawFigures({ + width: width, + height: height, + backgroundColor: backgroundColor, + figures: figures, + context: context + }); + tmpCanvas = cachedCanvases.getCanvas('mesh', paddedWidth, paddedHeight, false); + tmpCanvas.context.drawImage(canvas, BORDER_SIZE, BORDER_SIZE); + canvas = tmpCanvas.canvas; + } else { + tmpCanvas = cachedCanvases.getCanvas('mesh', paddedWidth, paddedHeight, false); + var tmpCtx = tmpCanvas.context; + var data = tmpCtx.createImageData(width, height); + if (backgroundColor) { + var bytes = data.data; + for (i = 0, ii = bytes.length; i < ii; i += 4) { + bytes[i] = backgroundColor[0]; + bytes[i + 1] = backgroundColor[1]; + bytes[i + 2] = backgroundColor[2]; + bytes[i + 3] = 255; + } + } + for (i = 0; i < figures.length; i++) { + drawFigure(data, figures[i], context); + } + tmpCtx.putImageData(data, BORDER_SIZE, BORDER_SIZE); + canvas = tmpCanvas.canvas; + } + return { + canvas: canvas, + offsetX: offsetX - BORDER_SIZE * scaleX, + offsetY: offsetY - BORDER_SIZE * scaleY, + scaleX: scaleX, + scaleY: scaleY + }; + } + return createMeshCanvas; +}(); +ShadingIRs.Mesh = { + fromIR: function Mesh_fromIR(raw) { + var coords = raw[2]; + var colors = raw[3]; + var figures = raw[4]; + var bounds = raw[5]; + var matrix = raw[6]; + var background = raw[8]; + return { + type: 'Pattern', + getPattern: function Mesh_getPattern(ctx, owner, shadingFill) { + var scale; + if (shadingFill) { + scale = _util.Util.singularValueDecompose2dScale(ctx.mozCurrentTransform); + } else { + scale = _util.Util.singularValueDecompose2dScale(owner.baseTransform); + if (matrix) { + var matrixScale = _util.Util.singularValueDecompose2dScale(matrix); + scale = [scale[0] * matrixScale[0], scale[1] * matrixScale[1]]; + } + } + var temporaryPatternCanvas = createMeshCanvas(bounds, scale, coords, colors, figures, shadingFill ? null : background, owner.cachedCanvases, owner.webGLContext); + if (!shadingFill) { + ctx.setTransform.apply(ctx, owner.baseTransform); + if (matrix) { + ctx.transform.apply(ctx, matrix); + } + } + ctx.translate(temporaryPatternCanvas.offsetX, temporaryPatternCanvas.offsetY); + ctx.scale(temporaryPatternCanvas.scaleX, temporaryPatternCanvas.scaleY); + return ctx.createPattern(temporaryPatternCanvas.canvas, 'no-repeat'); + } + }; + } +}; +ShadingIRs.Dummy = { + fromIR: function Dummy_fromIR() { + return { + type: 'Pattern', + getPattern: function Dummy_fromIR_getPattern() { + return 'hotpink'; + } + }; + } +}; +function getShadingPatternFromIR(raw) { + var shadingIR = ShadingIRs[raw[0]]; + if (!shadingIR) { + throw new Error('Unknown IR type: ' + raw[0]); + } + return shadingIR.fromIR(raw); +} +var TilingPattern = function TilingPatternClosure() { + var PaintType = { + COLORED: 1, + UNCOLORED: 2 + }; + var MAX_PATTERN_SIZE = 3000; + function TilingPattern(IR, color, ctx, canvasGraphicsFactory, baseTransform) { + this.operatorList = IR[2]; + this.matrix = IR[3] || [1, 0, 0, 1, 0, 0]; + this.bbox = IR[4]; + this.xstep = IR[5]; + this.ystep = IR[6]; + this.paintType = IR[7]; + this.tilingType = IR[8]; + this.color = color; + this.canvasGraphicsFactory = canvasGraphicsFactory; + this.baseTransform = baseTransform; + this.type = 'Pattern'; + this.ctx = ctx; + } + TilingPattern.prototype = { + createPatternCanvas: function TilinPattern_createPatternCanvas(owner) { + var operatorList = this.operatorList; + var bbox = this.bbox; + var xstep = this.xstep; + var ystep = this.ystep; + var paintType = this.paintType; + var tilingType = this.tilingType; + var color = this.color; + var canvasGraphicsFactory = this.canvasGraphicsFactory; + (0, _util.info)('TilingType: ' + tilingType); + var x0 = bbox[0], + y0 = bbox[1], + x1 = bbox[2], + y1 = bbox[3]; + var topLeft = [x0, y0]; + var botRight = [x0 + xstep, y0 + ystep]; + var width = botRight[0] - topLeft[0]; + var height = botRight[1] - topLeft[1]; + var matrixScale = _util.Util.singularValueDecompose2dScale(this.matrix); + var curMatrixScale = _util.Util.singularValueDecompose2dScale(this.baseTransform); + var combinedScale = [matrixScale[0] * curMatrixScale[0], matrixScale[1] * curMatrixScale[1]]; + width = Math.min(Math.ceil(Math.abs(width * combinedScale[0])), MAX_PATTERN_SIZE); + height = Math.min(Math.ceil(Math.abs(height * combinedScale[1])), MAX_PATTERN_SIZE); + var tmpCanvas = owner.cachedCanvases.getCanvas('pattern', width, height, true); + var tmpCtx = tmpCanvas.context; + var graphics = canvasGraphicsFactory.createCanvasGraphics(tmpCtx); + graphics.groupLevel = owner.groupLevel; + this.setFillAndStrokeStyleToContext(graphics, paintType, color); + this.setScale(width, height, xstep, ystep); + this.transformToScale(graphics); + var tmpTranslate = [1, 0, 0, 1, -topLeft[0], -topLeft[1]]; + graphics.transform.apply(graphics, tmpTranslate); + this.clipBbox(graphics, bbox, x0, y0, x1, y1); + graphics.executeOperatorList(operatorList); + return tmpCanvas.canvas; + }, + setScale: function TilingPattern_setScale(width, height, xstep, ystep) { + this.scale = [width / xstep, height / ystep]; + }, + transformToScale: function TilingPattern_transformToScale(graphics) { + var scale = this.scale; + var tmpScale = [scale[0], 0, 0, scale[1], 0, 0]; + graphics.transform.apply(graphics, tmpScale); + }, + scaleToContext: function TilingPattern_scaleToContext() { + var scale = this.scale; + this.ctx.scale(1 / scale[0], 1 / scale[1]); + }, + clipBbox: function clipBbox(graphics, bbox, x0, y0, x1, y1) { + if (Array.isArray(bbox) && bbox.length === 4) { + var bboxWidth = x1 - x0; + var bboxHeight = y1 - y0; + graphics.ctx.rect(x0, y0, bboxWidth, bboxHeight); + graphics.clip(); + graphics.endPath(); + } + }, + setFillAndStrokeStyleToContext: function setFillAndStrokeStyleToContext(graphics, paintType, color) { + var context = graphics.ctx, + current = graphics.current; + switch (paintType) { + case PaintType.COLORED: + var ctx = this.ctx; + context.fillStyle = ctx.fillStyle; + context.strokeStyle = ctx.strokeStyle; + current.fillColor = ctx.fillStyle; + current.strokeColor = ctx.strokeStyle; + break; + case PaintType.UNCOLORED: + var cssColor = _util.Util.makeCssRgb(color[0], color[1], color[2]); + context.fillStyle = cssColor; + context.strokeStyle = cssColor; + current.fillColor = cssColor; + current.strokeColor = cssColor; + break; + default: + throw new _util.FormatError('Unsupported paint type: ' + paintType); + } + }, + getPattern: function TilingPattern_getPattern(ctx, owner) { + var temporaryPatternCanvas = this.createPatternCanvas(owner); + ctx = this.ctx; + ctx.setTransform.apply(ctx, this.baseTransform); + ctx.transform.apply(ctx, this.matrix); + this.scaleToContext(); + return ctx.createPattern(temporaryPatternCanvas, 'repeat'); + } + }; + return TilingPattern; +}(); +exports.getShadingPatternFromIR = getShadingPatternFromIR; +exports.TilingPattern = TilingPattern; + +/***/ }), +/* 135 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); +var GlobalWorkerOptions = Object.create(null); +GlobalWorkerOptions.workerPort = GlobalWorkerOptions.workerPort === undefined ? null : GlobalWorkerOptions.workerPort; +GlobalWorkerOptions.workerSrc = GlobalWorkerOptions.workerSrc === undefined ? '' : GlobalWorkerOptions.workerSrc; +exports.GlobalWorkerOptions = GlobalWorkerOptions; + +/***/ }), +/* 136 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.MessageHandler = undefined; + +var _regenerator = __w_pdfjs_require__(137); + +var _regenerator2 = _interopRequireDefault(_regenerator); + +var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; + +var resolveCall = function () { + var _ref = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee(fn, args) { + var thisArg = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; + return _regenerator2.default.wrap(function _callee$(_context) { + while (1) { + switch (_context.prev = _context.next) { + case 0: + if (fn) { + _context.next = 2; + break; + } + + return _context.abrupt('return'); + + case 2: + return _context.abrupt('return', fn.apply(thisArg, args)); + + case 3: + case 'end': + return _context.stop(); + } + } + }, _callee, this); + })); + + return function resolveCall(_x2, _x3) { + return _ref.apply(this, arguments); + }; +}(); + +var _util = __w_pdfjs_require__(1); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } + +function wrapReason(reason) { + if ((typeof reason === 'undefined' ? 'undefined' : _typeof(reason)) !== 'object') { + return reason; + } + switch (reason.name) { + case 'AbortException': + return new _util.AbortException(reason.message); + case 'MissingPDFException': + return new _util.MissingPDFException(reason.message); + case 'UnexpectedResponseException': + return new _util.UnexpectedResponseException(reason.message, reason.status); + default: + return new _util.UnknownErrorException(reason.message, reason.details); + } +} +function makeReasonSerializable(reason) { + if (!(reason instanceof Error) || reason instanceof _util.AbortException || reason instanceof _util.MissingPDFException || reason instanceof _util.UnexpectedResponseException || reason instanceof _util.UnknownErrorException) { + return reason; + } + return new _util.UnknownErrorException(reason.message, reason.toString()); +} +function resolveOrReject(capability, success, reason) { + if (success) { + capability.resolve(); + } else { + capability.reject(reason); + } +} +function finalize(promise) { + return Promise.resolve(promise).catch(function () {}); +} +function MessageHandler(sourceName, targetName, comObj) { + var _this = this; + + this.sourceName = sourceName; + this.targetName = targetName; + this.comObj = comObj; + this.callbackId = 1; + this.streamId = 1; + this.postMessageTransfers = true; + this.streamSinks = Object.create(null); + this.streamControllers = Object.create(null); + var callbacksCapabilities = this.callbacksCapabilities = Object.create(null); + var ah = this.actionHandler = Object.create(null); + this._onComObjOnMessage = function (event) { + var data = event.data; + if (data.targetName !== _this.sourceName) { + return; + } + if (data.stream) { + _this._processStreamMessage(data); + } else if (data.isReply) { + var callbackId = data.callbackId; + if (data.callbackId in callbacksCapabilities) { + var callback = callbacksCapabilities[callbackId]; + delete callbacksCapabilities[callbackId]; + if ('error' in data) { + callback.reject(wrapReason(data.error)); + } else { + callback.resolve(data.data); + } + } else { + throw new Error('Cannot resolve callback ' + callbackId); + } + } else if (data.action in ah) { + var action = ah[data.action]; + if (data.callbackId) { + var _sourceName = _this.sourceName; + var _targetName = data.sourceName; + Promise.resolve().then(function () { + return action[0].call(action[1], data.data); + }).then(function (result) { + comObj.postMessage({ + sourceName: _sourceName, + targetName: _targetName, + isReply: true, + callbackId: data.callbackId, + data: result + }); + }, function (reason) { + comObj.postMessage({ + sourceName: _sourceName, + targetName: _targetName, + isReply: true, + callbackId: data.callbackId, + error: makeReasonSerializable(reason) + }); + }); + } else if (data.streamId) { + _this._createStreamSink(data); + } else { + action[0].call(action[1], data.data); + } + } else { + throw new Error('Unknown action from worker: ' + data.action); + } + }; + comObj.addEventListener('message', this._onComObjOnMessage); +} +MessageHandler.prototype = { + on: function on(actionName, handler, scope) { + var ah = this.actionHandler; + if (ah[actionName]) { + throw new Error('There is already an actionName called "' + actionName + '"'); + } + ah[actionName] = [handler, scope]; + }, + send: function send(actionName, data, transfers) { + var message = { + sourceName: this.sourceName, + targetName: this.targetName, + action: actionName, + data: data + }; + this.postMessage(message, transfers); + }, + sendWithPromise: function sendWithPromise(actionName, data, transfers) { + var callbackId = this.callbackId++; + var message = { + sourceName: this.sourceName, + targetName: this.targetName, + action: actionName, + data: data, + callbackId: callbackId + }; + var capability = (0, _util.createPromiseCapability)(); + this.callbacksCapabilities[callbackId] = capability; + try { + this.postMessage(message, transfers); + } catch (e) { + capability.reject(e); + } + return capability.promise; + }, + sendWithStream: function sendWithStream(actionName, data, queueingStrategy, transfers) { + var _this2 = this; + + var streamId = this.streamId++; + var sourceName = this.sourceName; + var targetName = this.targetName; + return new _util.ReadableStream({ + start: function start(controller) { + var startCapability = (0, _util.createPromiseCapability)(); + _this2.streamControllers[streamId] = { + controller: controller, + startCall: startCapability, + isClosed: false + }; + _this2.postMessage({ + sourceName: sourceName, + targetName: targetName, + action: actionName, + streamId: streamId, + data: data, + desiredSize: controller.desiredSize + }); + return startCapability.promise; + }, + pull: function pull(controller) { + var pullCapability = (0, _util.createPromiseCapability)(); + _this2.streamControllers[streamId].pullCall = pullCapability; + _this2.postMessage({ + sourceName: sourceName, + targetName: targetName, + stream: 'pull', + streamId: streamId, + desiredSize: controller.desiredSize + }); + return pullCapability.promise; + }, + cancel: function cancel(reason) { + var cancelCapability = (0, _util.createPromiseCapability)(); + _this2.streamControllers[streamId].cancelCall = cancelCapability; + _this2.streamControllers[streamId].isClosed = true; + _this2.postMessage({ + sourceName: sourceName, + targetName: targetName, + stream: 'cancel', + reason: reason, + streamId: streamId + }); + return cancelCapability.promise; + } + }, queueingStrategy); + }, + _createStreamSink: function _createStreamSink(data) { + var _this3 = this; + + var self = this; + var action = this.actionHandler[data.action]; + var streamId = data.streamId; + var desiredSize = data.desiredSize; + var sourceName = this.sourceName; + var targetName = data.sourceName; + var capability = (0, _util.createPromiseCapability)(); + var sendStreamRequest = function sendStreamRequest(_ref2) { + var stream = _ref2.stream, + chunk = _ref2.chunk, + transfers = _ref2.transfers, + success = _ref2.success, + reason = _ref2.reason; + + _this3.postMessage({ + sourceName: sourceName, + targetName: targetName, + stream: stream, + streamId: streamId, + chunk: chunk, + success: success, + reason: reason + }, transfers); + }; + var streamSink = { + enqueue: function enqueue(chunk) { + var size = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; + var transfers = arguments[2]; + + if (this.isCancelled) { + return; + } + var lastDesiredSize = this.desiredSize; + this.desiredSize -= size; + if (lastDesiredSize > 0 && this.desiredSize <= 0) { + this.sinkCapability = (0, _util.createPromiseCapability)(); + this.ready = this.sinkCapability.promise; + } + sendStreamRequest({ + stream: 'enqueue', + chunk: chunk, + transfers: transfers + }); + }, + close: function close() { + if (this.isCancelled) { + return; + } + this.isCancelled = true; + sendStreamRequest({ stream: 'close' }); + delete self.streamSinks[streamId]; + }, + error: function error(reason) { + if (this.isCancelled) { + return; + } + this.isCancelled = true; + sendStreamRequest({ + stream: 'error', + reason: reason + }); + }, + + sinkCapability: capability, + onPull: null, + onCancel: null, + isCancelled: false, + desiredSize: desiredSize, + ready: null + }; + streamSink.sinkCapability.resolve(); + streamSink.ready = streamSink.sinkCapability.promise; + this.streamSinks[streamId] = streamSink; + resolveCall(action[0], [data.data, streamSink], action[1]).then(function () { + sendStreamRequest({ + stream: 'start_complete', + success: true + }); + }, function (reason) { + sendStreamRequest({ + stream: 'start_complete', + success: false, + reason: reason + }); + }); + }, + _processStreamMessage: function _processStreamMessage(data) { + var _this4 = this; + + var sourceName = this.sourceName; + var targetName = data.sourceName; + var streamId = data.streamId; + var sendStreamResponse = function sendStreamResponse(_ref3) { + var stream = _ref3.stream, + success = _ref3.success, + reason = _ref3.reason; + + _this4.comObj.postMessage({ + sourceName: sourceName, + targetName: targetName, + stream: stream, + success: success, + streamId: streamId, + reason: reason + }); + }; + var deleteStreamController = function deleteStreamController() { + Promise.all([_this4.streamControllers[data.streamId].startCall, _this4.streamControllers[data.streamId].pullCall, _this4.streamControllers[data.streamId].cancelCall].map(function (capability) { + return capability && finalize(capability.promise); + })).then(function () { + delete _this4.streamControllers[data.streamId]; + }); + }; + switch (data.stream) { + case 'start_complete': + resolveOrReject(this.streamControllers[data.streamId].startCall, data.success, wrapReason(data.reason)); + break; + case 'pull_complete': + resolveOrReject(this.streamControllers[data.streamId].pullCall, data.success, wrapReason(data.reason)); + break; + case 'pull': + if (!this.streamSinks[data.streamId]) { + sendStreamResponse({ + stream: 'pull_complete', + success: true + }); + break; + } + if (this.streamSinks[data.streamId].desiredSize <= 0 && data.desiredSize > 0) { + this.streamSinks[data.streamId].sinkCapability.resolve(); + } + this.streamSinks[data.streamId].desiredSize = data.desiredSize; + resolveCall(this.streamSinks[data.streamId].onPull).then(function () { + sendStreamResponse({ + stream: 'pull_complete', + success: true + }); + }, function (reason) { + sendStreamResponse({ + stream: 'pull_complete', + success: false, + reason: reason + }); + }); + break; + case 'enqueue': + (0, _util.assert)(this.streamControllers[data.streamId], 'enqueue should have stream controller'); + if (!this.streamControllers[data.streamId].isClosed) { + this.streamControllers[data.streamId].controller.enqueue(data.chunk); + } + break; + case 'close': + (0, _util.assert)(this.streamControllers[data.streamId], 'close should have stream controller'); + if (this.streamControllers[data.streamId].isClosed) { + break; + } + this.streamControllers[data.streamId].isClosed = true; + this.streamControllers[data.streamId].controller.close(); + deleteStreamController(); + break; + case 'error': + (0, _util.assert)(this.streamControllers[data.streamId], 'error should have stream controller'); + this.streamControllers[data.streamId].controller.error(wrapReason(data.reason)); + deleteStreamController(); + break; + case 'cancel_complete': + resolveOrReject(this.streamControllers[data.streamId].cancelCall, data.success, wrapReason(data.reason)); + deleteStreamController(); + break; + case 'cancel': + if (!this.streamSinks[data.streamId]) { + break; + } + resolveCall(this.streamSinks[data.streamId].onCancel, [wrapReason(data.reason)]).then(function () { + sendStreamResponse({ + stream: 'cancel_complete', + success: true + }); + }, function (reason) { + sendStreamResponse({ + stream: 'cancel_complete', + success: false, + reason: reason + }); + }); + this.streamSinks[data.streamId].sinkCapability.reject(wrapReason(data.reason)); + this.streamSinks[data.streamId].isCancelled = true; + delete this.streamSinks[data.streamId]; + break; + default: + throw new Error('Unexpected stream case'); + } + }, + postMessage: function postMessage(message, transfers) { + if (transfers && this.postMessageTransfers) { + this.comObj.postMessage(message, transfers); + } else { + this.comObj.postMessage(message); + } + }, + destroy: function destroy() { + this.comObj.removeEventListener('message', this._onComObjOnMessage); + } +}; +exports.MessageHandler = MessageHandler; + +/***/ }), +/* 137 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +module.exports = __w_pdfjs_require__(138); + +/***/ }), +/* 138 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +var g = function () { + return this; +}() || Function("return this")(); +var hadRuntime = g.regeneratorRuntime && Object.getOwnPropertyNames(g).indexOf("regeneratorRuntime") >= 0; +var oldRuntime = hadRuntime && g.regeneratorRuntime; +g.regeneratorRuntime = undefined; +module.exports = __w_pdfjs_require__(139); +if (hadRuntime) { + g.regeneratorRuntime = oldRuntime; +} else { + try { + delete g.regeneratorRuntime; + } catch (e) { + g.regeneratorRuntime = undefined; + } +} + +/***/ }), +/* 139 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; +/* WEBPACK VAR INJECTION */(function(module) { + +var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; + +!function (global) { + "use strict"; + + var Op = Object.prototype; + var hasOwn = Op.hasOwnProperty; + var undefined; + var $Symbol = typeof Symbol === "function" ? Symbol : {}; + var iteratorSymbol = $Symbol.iterator || "@@iterator"; + var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator"; + var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; + var inModule = ( false ? undefined : _typeof(module)) === "object"; + var runtime = global.regeneratorRuntime; + if (runtime) { + if (inModule) { + module.exports = runtime; + } + return; + } + runtime = global.regeneratorRuntime = inModule ? module.exports : {}; + function wrap(innerFn, outerFn, self, tryLocsList) { + var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator; + var generator = Object.create(protoGenerator.prototype); + var context = new Context(tryLocsList || []); + generator._invoke = makeInvokeMethod(innerFn, self, context); + return generator; + } + runtime.wrap = wrap; + function tryCatch(fn, obj, arg) { + try { + return { + type: "normal", + arg: fn.call(obj, arg) + }; + } catch (err) { + return { + type: "throw", + arg: err + }; + } + } + var GenStateSuspendedStart = "suspendedStart"; + var GenStateSuspendedYield = "suspendedYield"; + var GenStateExecuting = "executing"; + var GenStateCompleted = "completed"; + var ContinueSentinel = {}; + function Generator() {} + function GeneratorFunction() {} + function GeneratorFunctionPrototype() {} + var IteratorPrototype = {}; + IteratorPrototype[iteratorSymbol] = function () { + return this; + }; + var getProto = Object.getPrototypeOf; + var NativeIteratorPrototype = getProto && getProto(getProto(values([]))); + if (NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) { + IteratorPrototype = NativeIteratorPrototype; + } + var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); + GeneratorFunction.prototype = Gp.constructor = GeneratorFunctionPrototype; + GeneratorFunctionPrototype.constructor = GeneratorFunction; + GeneratorFunctionPrototype[toStringTagSymbol] = GeneratorFunction.displayName = "GeneratorFunction"; + function defineIteratorMethods(prototype) { + ["next", "throw", "return"].forEach(function (method) { + prototype[method] = function (arg) { + return this._invoke(method, arg); + }; + }); + } + runtime.isGeneratorFunction = function (genFun) { + var ctor = typeof genFun === "function" && genFun.constructor; + return ctor ? ctor === GeneratorFunction || (ctor.displayName || ctor.name) === "GeneratorFunction" : false; + }; + runtime.mark = function (genFun) { + if (Object.setPrototypeOf) { + Object.setPrototypeOf(genFun, GeneratorFunctionPrototype); + } else { + genFun.__proto__ = GeneratorFunctionPrototype; + if (!(toStringTagSymbol in genFun)) { + genFun[toStringTagSymbol] = "GeneratorFunction"; + } + } + genFun.prototype = Object.create(Gp); + return genFun; + }; + runtime.awrap = function (arg) { + return { __await: arg }; + }; + function AsyncIterator(generator) { + function invoke(method, arg, resolve, reject) { + var record = tryCatch(generator[method], generator, arg); + if (record.type === "throw") { + reject(record.arg); + } else { + var result = record.arg; + var value = result.value; + if (value && (typeof value === "undefined" ? "undefined" : _typeof(value)) === "object" && hasOwn.call(value, "__await")) { + return Promise.resolve(value.__await).then(function (value) { + invoke("next", value, resolve, reject); + }, function (err) { + invoke("throw", err, resolve, reject); + }); + } + return Promise.resolve(value).then(function (unwrapped) { + result.value = unwrapped; + resolve(result); + }, reject); + } + } + var previousPromise; + function enqueue(method, arg) { + function callInvokeWithMethodAndArg() { + return new Promise(function (resolve, reject) { + invoke(method, arg, resolve, reject); + }); + } + return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); + } + this._invoke = enqueue; + } + defineIteratorMethods(AsyncIterator.prototype); + AsyncIterator.prototype[asyncIteratorSymbol] = function () { + return this; + }; + runtime.AsyncIterator = AsyncIterator; + runtime.async = function (innerFn, outerFn, self, tryLocsList) { + var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList)); + return runtime.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { + return result.done ? result.value : iter.next(); + }); + }; + function makeInvokeMethod(innerFn, self, context) { + var state = GenStateSuspendedStart; + return function invoke(method, arg) { + if (state === GenStateExecuting) { + throw new Error("Generator is already running"); + } + if (state === GenStateCompleted) { + if (method === "throw") { + throw arg; + } + return doneResult(); + } + context.method = method; + context.arg = arg; + while (true) { + var delegate = context.delegate; + if (delegate) { + var delegateResult = maybeInvokeDelegate(delegate, context); + if (delegateResult) { + if (delegateResult === ContinueSentinel) continue; + return delegateResult; + } + } + if (context.method === "next") { + context.sent = context._sent = context.arg; + } else if (context.method === "throw") { + if (state === GenStateSuspendedStart) { + state = GenStateCompleted; + throw context.arg; + } + context.dispatchException(context.arg); + } else if (context.method === "return") { + context.abrupt("return", context.arg); + } + state = GenStateExecuting; + var record = tryCatch(innerFn, self, context); + if (record.type === "normal") { + state = context.done ? GenStateCompleted : GenStateSuspendedYield; + if (record.arg === ContinueSentinel) { + continue; + } + return { + value: record.arg, + done: context.done + }; + } else if (record.type === "throw") { + state = GenStateCompleted; + context.method = "throw"; + context.arg = record.arg; + } + } + }; + } + function maybeInvokeDelegate(delegate, context) { + var method = delegate.iterator[context.method]; + if (method === undefined) { + context.delegate = null; + if (context.method === "throw") { + if (delegate.iterator.return) { + context.method = "return"; + context.arg = undefined; + maybeInvokeDelegate(delegate, context); + if (context.method === "throw") { + return ContinueSentinel; + } + } + context.method = "throw"; + context.arg = new TypeError("The iterator does not provide a 'throw' method"); + } + return ContinueSentinel; + } + var record = tryCatch(method, delegate.iterator, context.arg); + if (record.type === "throw") { + context.method = "throw"; + context.arg = record.arg; + context.delegate = null; + return ContinueSentinel; + } + var info = record.arg; + if (!info) { + context.method = "throw"; + context.arg = new TypeError("iterator result is not an object"); + context.delegate = null; + return ContinueSentinel; + } + if (info.done) { + context[delegate.resultName] = info.value; + context.next = delegate.nextLoc; + if (context.method !== "return") { + context.method = "next"; + context.arg = undefined; + } + } else { + return info; + } + context.delegate = null; + return ContinueSentinel; + } + defineIteratorMethods(Gp); + Gp[toStringTagSymbol] = "Generator"; + Gp[iteratorSymbol] = function () { + return this; + }; + Gp.toString = function () { + return "[object Generator]"; + }; + function pushTryEntry(locs) { + var entry = { tryLoc: locs[0] }; + if (1 in locs) { + entry.catchLoc = locs[1]; + } + if (2 in locs) { + entry.finallyLoc = locs[2]; + entry.afterLoc = locs[3]; + } + this.tryEntries.push(entry); + } + function resetTryEntry(entry) { + var record = entry.completion || {}; + record.type = "normal"; + delete record.arg; + entry.completion = record; + } + function Context(tryLocsList) { + this.tryEntries = [{ tryLoc: "root" }]; + tryLocsList.forEach(pushTryEntry, this); + this.reset(true); + } + runtime.keys = function (object) { + var keys = []; + for (var key in object) { + keys.push(key); + } + keys.reverse(); + return function next() { + while (keys.length) { + var key = keys.pop(); + if (key in object) { + next.value = key; + next.done = false; + return next; + } + } + next.done = true; + return next; + }; + }; + function values(iterable) { + if (iterable) { + var iteratorMethod = iterable[iteratorSymbol]; + if (iteratorMethod) { + return iteratorMethod.call(iterable); + } + if (typeof iterable.next === "function") { + return iterable; + } + if (!isNaN(iterable.length)) { + var i = -1, + next = function next() { + while (++i < iterable.length) { + if (hasOwn.call(iterable, i)) { + next.value = iterable[i]; + next.done = false; + return next; + } + } + next.value = undefined; + next.done = true; + return next; + }; + return next.next = next; + } + } + return { next: doneResult }; + } + runtime.values = values; + function doneResult() { + return { + value: undefined, + done: true + }; + } + Context.prototype = { + constructor: Context, + reset: function reset(skipTempReset) { + this.prev = 0; + this.next = 0; + this.sent = this._sent = undefined; + this.done = false; + this.delegate = null; + this.method = "next"; + this.arg = undefined; + this.tryEntries.forEach(resetTryEntry); + if (!skipTempReset) { + for (var name in this) { + if (name.charAt(0) === "t" && hasOwn.call(this, name) && !isNaN(+name.slice(1))) { + this[name] = undefined; + } + } + } + }, + stop: function stop() { + this.done = true; + var rootEntry = this.tryEntries[0]; + var rootRecord = rootEntry.completion; + if (rootRecord.type === "throw") { + throw rootRecord.arg; + } + return this.rval; + }, + dispatchException: function dispatchException(exception) { + if (this.done) { + throw exception; + } + var context = this; + function handle(loc, caught) { + record.type = "throw"; + record.arg = exception; + context.next = loc; + if (caught) { + context.method = "next"; + context.arg = undefined; + } + return !!caught; + } + for (var i = this.tryEntries.length - 1; i >= 0; --i) { + var entry = this.tryEntries[i]; + var record = entry.completion; + if (entry.tryLoc === "root") { + return handle("end"); + } + if (entry.tryLoc <= this.prev) { + var hasCatch = hasOwn.call(entry, "catchLoc"); + var hasFinally = hasOwn.call(entry, "finallyLoc"); + if (hasCatch && hasFinally) { + if (this.prev < entry.catchLoc) { + return handle(entry.catchLoc, true); + } else if (this.prev < entry.finallyLoc) { + return handle(entry.finallyLoc); + } + } else if (hasCatch) { + if (this.prev < entry.catchLoc) { + return handle(entry.catchLoc, true); + } + } else if (hasFinally) { + if (this.prev < entry.finallyLoc) { + return handle(entry.finallyLoc); + } + } else { + throw new Error("try statement without catch or finally"); + } + } + } + }, + abrupt: function abrupt(type, arg) { + for (var i = this.tryEntries.length - 1; i >= 0; --i) { + var entry = this.tryEntries[i]; + if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { + var finallyEntry = entry; + break; + } + } + if (finallyEntry && (type === "break" || type === "continue") && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc) { + finallyEntry = null; + } + var record = finallyEntry ? finallyEntry.completion : {}; + record.type = type; + record.arg = arg; + if (finallyEntry) { + this.method = "next"; + this.next = finallyEntry.finallyLoc; + return ContinueSentinel; + } + return this.complete(record); + }, + complete: function complete(record, afterLoc) { + if (record.type === "throw") { + throw record.arg; + } + if (record.type === "break" || record.type === "continue") { + this.next = record.arg; + } else if (record.type === "return") { + this.rval = this.arg = record.arg; + this.method = "return"; + this.next = "end"; + } else if (record.type === "normal" && afterLoc) { + this.next = afterLoc; + } + return ContinueSentinel; + }, + finish: function finish(finallyLoc) { + for (var i = this.tryEntries.length - 1; i >= 0; --i) { + var entry = this.tryEntries[i]; + if (entry.finallyLoc === finallyLoc) { + this.complete(entry.completion, entry.afterLoc); + resetTryEntry(entry); + return ContinueSentinel; + } + } + }, + "catch": function _catch(tryLoc) { + for (var i = this.tryEntries.length - 1; i >= 0; --i) { + var entry = this.tryEntries[i]; + if (entry.tryLoc === tryLoc) { + var record = entry.completion; + if (record.type === "throw") { + var thrown = record.arg; + resetTryEntry(entry); + } + return thrown; + } + } + throw new Error("illegal catch attempt"); + }, + delegateYield: function delegateYield(iterable, resultName, nextLoc) { + this.delegate = { + iterator: values(iterable), + resultName: resultName, + nextLoc: nextLoc + }; + if (this.method === "next") { + this.arg = undefined; + } + return ContinueSentinel; + } + }; +}(function () { + return this; +}() || Function("return this")()); +/* WEBPACK VAR INJECTION */}.call(this, __w_pdfjs_require__(140)(module))) + +/***/ }), +/* 140 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +module.exports = function (module) { + if (!module.webpackPolyfill) { + module.deprecate = function () {}; + module.paths = []; + if (!module.children) module.children = []; + Object.defineProperty(module, "loaded", { + enumerable: true, + get: function get() { + return module.l; + } + }); + Object.defineProperty(module, "id", { + enumerable: true, + get: function get() { + return module.i; + } + }); + module.webpackPolyfill = 1; + } + return module; +}; + +/***/ }), +/* 141 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.Metadata = undefined; + +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + +var _util = __w_pdfjs_require__(1); + +var _xml_parser = __w_pdfjs_require__(142); + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var Metadata = function () { + function Metadata(data) { + _classCallCheck(this, Metadata); + + (0, _util.assert)(typeof data === 'string', 'Metadata: input is not a string'); + data = this._repair(data); + var parser = new _xml_parser.SimpleXMLParser(); + var xmlDocument = parser.parseFromString(data); + this._metadata = Object.create(null); + if (xmlDocument) { + this._parse(xmlDocument); + } + } + + _createClass(Metadata, [{ + key: '_repair', + value: function _repair(data) { + return data.replace(/>\\376\\377([^<]+)/g, function (all, codes) { + var bytes = codes.replace(/\\([0-3])([0-7])([0-7])/g, function (code, d1, d2, d3) { + return String.fromCharCode(d1 * 64 + d2 * 8 + d3 * 1); + }).replace(/&(amp|apos|gt|lt|quot);/g, function (str, name) { + switch (name) { + case 'amp': + return '&'; + case 'apos': + return '\''; + case 'gt': + return '>'; + case 'lt': + return '<'; + case 'quot': + return '\"'; + } + throw new Error('_repair: ' + name + ' isn\'t defined.'); + }); + var chars = ''; + for (var i = 0, ii = bytes.length; i < ii; i += 2) { + var code = bytes.charCodeAt(i) * 256 + bytes.charCodeAt(i + 1); + if (code >= 32 && code < 127 && code !== 60 && code !== 62 && code !== 38) { + chars += String.fromCharCode(code); + } else { + chars += '&#x' + (0x10000 + code).toString(16).substring(1) + ';'; + } + } + return '>' + chars; + }); + } + }, { + key: '_parse', + value: function _parse(xmlDocument) { + var rdf = xmlDocument.documentElement; + if (rdf.nodeName.toLowerCase() !== 'rdf:rdf') { + rdf = rdf.firstChild; + while (rdf && rdf.nodeName.toLowerCase() !== 'rdf:rdf') { + rdf = rdf.nextSibling; + } + } + var nodeName = rdf ? rdf.nodeName.toLowerCase() : null; + if (!rdf || nodeName !== 'rdf:rdf' || !rdf.hasChildNodes()) { + return; + } + var children = rdf.childNodes; + for (var i = 0, ii = children.length; i < ii; i++) { + var desc = children[i]; + if (desc.nodeName.toLowerCase() !== 'rdf:description') { + continue; + } + for (var j = 0, jj = desc.childNodes.length; j < jj; j++) { + if (desc.childNodes[j].nodeName.toLowerCase() !== '#text') { + var entry = desc.childNodes[j]; + var name = entry.nodeName.toLowerCase(); + this._metadata[name] = entry.textContent.trim(); + } + } + } + } + }, { + key: 'get', + value: function get(name) { + return this._metadata[name] || null; + } + }, { + key: 'getAll', + value: function getAll() { + return this._metadata; + } + }, { + key: 'has', + value: function has(name) { + return typeof this._metadata[name] !== 'undefined'; + } + }]); + + return Metadata; +}(); + +exports.Metadata = Metadata; + +/***/ }), +/* 142 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); + +var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }; + +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + +function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var XMLParserErrorCode = { + NoError: 0, + EndOfDocument: -1, + UnterminatedCdat: -2, + UnterminatedXmlDeclaration: -3, + UnterminatedDoctypeDeclaration: -4, + UnterminatedComment: -5, + MalformedElement: -6, + OutOfMemory: -7, + UnterminatedAttributeValue: -8, + UnterminatedElement: -9, + ElementNeverBegun: -10 +}; +function isWhitespace(s, index) { + var ch = s[index]; + return ch === ' ' || ch === '\n' || ch === '\r' || ch === '\t'; +} +function isWhitespaceString(s) { + for (var i = 0, ii = s.length; i < ii; i++) { + if (!isWhitespace(s, i)) { + return false; + } + } + return true; +} + +var XMLParserBase = function () { + function XMLParserBase() { + _classCallCheck(this, XMLParserBase); + } + + _createClass(XMLParserBase, [{ + key: '_resolveEntities', + value: function _resolveEntities(s) { + return s.replace(/&([^;]+);/g, function (all, entity) { + if (entity.substring(0, 2) === '#x') { + return String.fromCharCode(parseInt(entity.substring(2), 16)); + } else if (entity.substring(0, 1) === '#') { + return String.fromCharCode(parseInt(entity.substring(1), 10)); + } + switch (entity) { + case 'lt': + return '<'; + case 'gt': + return '>'; + case 'amp': + return '&'; + case 'quot': + return '\"'; + } + return this.onResolveEntity(entity); + }); + } + }, { + key: '_parseContent', + value: function _parseContent(s, start) { + var pos = start, + name = void 0, + attributes = []; + function skipWs() { + while (pos < s.length && isWhitespace(s, pos)) { + ++pos; + } + } + while (pos < s.length && !isWhitespace(s, pos) && s[pos] !== '>' && s[pos] !== '/') { + ++pos; + } + name = s.substring(start, pos); + skipWs(); + while (pos < s.length && s[pos] !== '>' && s[pos] !== '/' && s[pos] !== '?') { + skipWs(); + var attrName = '', + attrValue = ''; + while (pos < s.length && !isWhitespace(s, pos) && s[pos] !== '=') { + attrName += s[pos]; + ++pos; + } + skipWs(); + if (s[pos] !== '=') { + return null; + } + ++pos; + skipWs(); + var attrEndChar = s[pos]; + if (attrEndChar !== '\"' && attrEndChar !== '\'') { + return null; + } + var attrEndIndex = s.indexOf(attrEndChar, ++pos); + if (attrEndIndex < 0) { + return null; + } + attrValue = s.substring(pos, attrEndIndex); + attributes.push({ + name: attrName, + value: this._resolveEntities(attrValue) + }); + pos = attrEndIndex + 1; + skipWs(); + } + return { + name: name, + attributes: attributes, + parsed: pos - start + }; + } + }, { + key: '_parseProcessingInstruction', + value: function _parseProcessingInstruction(s, start) { + var pos = start, + name = void 0, + value = void 0; + function skipWs() { + while (pos < s.length && isWhitespace(s, pos)) { + ++pos; + } + } + while (pos < s.length && !isWhitespace(s, pos) && s[pos] !== '>' && s[pos] !== '/') { + ++pos; + } + name = s.substring(start, pos); + skipWs(); + var attrStart = pos; + while (pos < s.length && (s[pos] !== '?' || s[pos + 1] !== '>')) { + ++pos; + } + value = s.substring(attrStart, pos); + return { + name: name, + value: value, + parsed: pos - start + }; + } + }, { + key: 'parseXml', + value: function parseXml(s) { + var i = 0; + while (i < s.length) { + var ch = s[i]; + var j = i; + if (ch === '<') { + ++j; + var ch2 = s[j]; + var q = void 0; + switch (ch2) { + case '/': + ++j; + q = s.indexOf('>', j); + if (q < 0) { + this.onError(XMLParserErrorCode.UnterminatedElement); + return; + } + this.onEndElement(s.substring(j, q)); + j = q + 1; + break; + case '?': + ++j; + var pi = this._parseProcessingInstruction(s, j); + if (s.substring(j + pi.parsed, j + pi.parsed + 2) !== '?>') { + this.onError(XMLParserErrorCode.UnterminatedXmlDeclaration); + return; + } + this.onPi(pi.name, pi.value); + j += pi.parsed + 2; + break; + case '!': + if (s.substring(j + 1, j + 3) === '--') { + q = s.indexOf('-->', j + 3); + if (q < 0) { + this.onError(XMLParserErrorCode.UnterminatedComment); + return; + } + this.onComment(s.substring(j + 3, q)); + j = q + 3; + } else if (s.substring(j + 1, j + 8) === '[CDATA[') { + q = s.indexOf(']]>', j + 8); + if (q < 0) { + this.onError(XMLParserErrorCode.UnterminatedCdat); + return; + } + this.onCdata(s.substring(j + 8, q)); + j = q + 3; + } else if (s.substring(j + 1, j + 8) === 'DOCTYPE') { + var q2 = s.indexOf('[', j + 8); + var complexDoctype = false; + q = s.indexOf('>', j + 8); + if (q < 0) { + this.onError(XMLParserErrorCode.UnterminatedDoctypeDeclaration); + return; + } + if (q2 > 0 && q > q2) { + q = s.indexOf(']>', j + 8); + if (q < 0) { + this.onError(XMLParserErrorCode.UnterminatedDoctypeDeclaration); + return; + } + complexDoctype = true; + } + var doctypeContent = s.substring(j + 8, q + (complexDoctype ? 1 : 0)); + this.onDoctype(doctypeContent); + j = q + (complexDoctype ? 2 : 1); + } else { + this.onError(XMLParserErrorCode.MalformedElement); + return; + } + break; + default: + var content = this._parseContent(s, j); + if (content === null) { + this.onError(XMLParserErrorCode.MalformedElement); + return; + } + var isClosed = false; + if (s.substring(j + content.parsed, j + content.parsed + 2) === '/>') { + isClosed = true; + } else if (s.substring(j + content.parsed, j + content.parsed + 1) !== '>') { + this.onError(XMLParserErrorCode.UnterminatedElement); + return; + } + this.onBeginElement(content.name, content.attributes, isClosed); + j += content.parsed + (isClosed ? 2 : 1); + break; + } + } else { + while (j < s.length && s[j] !== '<') { + j++; + } + var text = s.substring(i, j); + this.onText(this._resolveEntities(text)); + } + i = j; + } + } + }, { + key: 'onResolveEntity', + value: function onResolveEntity(name) { + return '&' + name + ';'; + } + }, { + key: 'onPi', + value: function onPi(name, value) {} + }, { + key: 'onComment', + value: function onComment(text) {} + }, { + key: 'onCdata', + value: function onCdata(text) {} + }, { + key: 'onDoctype', + value: function onDoctype(doctypeContent) {} + }, { + key: 'onText', + value: function onText(text) {} + }, { + key: 'onBeginElement', + value: function onBeginElement(name, attributes, isEmpty) {} + }, { + key: 'onEndElement', + value: function onEndElement(name) {} + }, { + key: 'onError', + value: function onError(code) {} + }]); + + return XMLParserBase; +}(); + +var SimpleDOMNode = function () { + function SimpleDOMNode(nodeName, nodeValue) { + _classCallCheck(this, SimpleDOMNode); + + this.nodeName = nodeName; + this.nodeValue = nodeValue; + Object.defineProperty(this, 'parentNode', { + value: null, + writable: true + }); + } + + _createClass(SimpleDOMNode, [{ + key: 'hasChildNodes', + value: function hasChildNodes() { + return this.childNodes && this.childNodes.length > 0; + } + }, { + key: 'firstChild', + get: function get() { + return this.childNodes[0]; + } + }, { + key: 'nextSibling', + get: function get() { + var index = this.parentNode.childNodes.indexOf(this); + return this.parentNode.childNodes[index + 1]; + } + }, { + key: 'textContent', + get: function get() { + if (!this.childNodes) { + return this.nodeValue || ''; + } + return this.childNodes.map(function (child) { + return child.textContent; + }).join(''); + } + }]); + + return SimpleDOMNode; +}(); + +var SimpleXMLParser = function (_XMLParserBase) { + _inherits(SimpleXMLParser, _XMLParserBase); + + function SimpleXMLParser() { + _classCallCheck(this, SimpleXMLParser); + + var _this = _possibleConstructorReturn(this, (SimpleXMLParser.__proto__ || Object.getPrototypeOf(SimpleXMLParser)).call(this)); + + _this._currentFragment = null; + _this._stack = null; + _this._errorCode = XMLParserErrorCode.NoError; + return _this; + } + + _createClass(SimpleXMLParser, [{ + key: 'parseFromString', + value: function parseFromString(data) { + this._currentFragment = []; + this._stack = []; + this._errorCode = XMLParserErrorCode.NoError; + this.parseXml(data); + if (this._errorCode !== XMLParserErrorCode.NoError) { + return undefined; + } + + var _currentFragment = _slicedToArray(this._currentFragment, 1), + documentElement = _currentFragment[0]; + + if (!documentElement) { + return undefined; + } + return { documentElement: documentElement }; + } + }, { + key: 'onResolveEntity', + value: function onResolveEntity(name) { + switch (name) { + case 'apos': + return '\''; + } + return _get(SimpleXMLParser.prototype.__proto__ || Object.getPrototypeOf(SimpleXMLParser.prototype), 'onResolveEntity', this).call(this, name); + } + }, { + key: 'onText', + value: function onText(text) { + if (isWhitespaceString(text)) { + return; + } + var node = new SimpleDOMNode('#text', text); + this._currentFragment.push(node); + } + }, { + key: 'onCdata', + value: function onCdata(text) { + var node = new SimpleDOMNode('#text', text); + this._currentFragment.push(node); + } + }, { + key: 'onBeginElement', + value: function onBeginElement(name, attributes, isEmpty) { + var node = new SimpleDOMNode(name); + node.childNodes = []; + this._currentFragment.push(node); + if (isEmpty) { + return; + } + this._stack.push(this._currentFragment); + this._currentFragment = node.childNodes; + } + }, { + key: 'onEndElement', + value: function onEndElement(name) { + this._currentFragment = this._stack.pop(); + var lastElement = this._currentFragment[this._currentFragment.length - 1]; + for (var i = 0, ii = lastElement.childNodes.length; i < ii; i++) { + lastElement.childNodes[i].parentNode = lastElement; + } + } + }, { + key: 'onError', + value: function onError(code) { + this._errorCode = code; + } + }]); + + return SimpleXMLParser; +}(XMLParserBase); + +exports.SimpleXMLParser = SimpleXMLParser; + +/***/ }), +/* 143 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.PDFDataTransportStream = undefined; + +var _regenerator = __w_pdfjs_require__(137); + +var _regenerator2 = _interopRequireDefault(_regenerator); + +var _util = __w_pdfjs_require__(1); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } + +var PDFDataTransportStream = function PDFDataTransportStreamClosure() { + function PDFDataTransportStream(params, pdfDataRangeTransport) { + var _this = this; + + (0, _util.assert)(pdfDataRangeTransport); + this._queuedChunks = []; + var initialData = params.initialData; + if (initialData && initialData.length > 0) { + var buffer = new Uint8Array(initialData).buffer; + this._queuedChunks.push(buffer); + } + this._pdfDataRangeTransport = pdfDataRangeTransport; + this._isStreamingSupported = !params.disableStream; + this._isRangeSupported = !params.disableRange; + this._contentLength = params.length; + this._fullRequestReader = null; + this._rangeReaders = []; + this._pdfDataRangeTransport.addRangeListener(function (begin, chunk) { + _this._onReceiveData({ + begin: begin, + chunk: chunk + }); + }); + this._pdfDataRangeTransport.addProgressListener(function (loaded) { + _this._onProgress({ loaded: loaded }); + }); + this._pdfDataRangeTransport.addProgressiveReadListener(function (chunk) { + _this._onReceiveData({ chunk: chunk }); + }); + this._pdfDataRangeTransport.transportReady(); + } + PDFDataTransportStream.prototype = { + _onReceiveData: function PDFDataTransportStream_onReceiveData(args) { + var buffer = new Uint8Array(args.chunk).buffer; + if (args.begin === undefined) { + if (this._fullRequestReader) { + this._fullRequestReader._enqueue(buffer); + } else { + this._queuedChunks.push(buffer); + } + } else { + var found = this._rangeReaders.some(function (rangeReader) { + if (rangeReader._begin !== args.begin) { + return false; + } + rangeReader._enqueue(buffer); + return true; + }); + (0, _util.assert)(found); + } + }, + _onProgress: function PDFDataTransportStream_onDataProgress(evt) { + if (this._rangeReaders.length > 0) { + var firstReader = this._rangeReaders[0]; + if (firstReader.onProgress) { + firstReader.onProgress({ loaded: evt.loaded }); + } + } + }, + _removeRangeReader: function PDFDataTransportStream_removeRangeReader(reader) { + var i = this._rangeReaders.indexOf(reader); + if (i >= 0) { + this._rangeReaders.splice(i, 1); + } + }, + getFullReader: function PDFDataTransportStream_getFullReader() { + (0, _util.assert)(!this._fullRequestReader); + var queuedChunks = this._queuedChunks; + this._queuedChunks = null; + return new PDFDataTransportStreamReader(this, queuedChunks); + }, + getRangeReader: function PDFDataTransportStream_getRangeReader(begin, end) { + var reader = new PDFDataTransportStreamRangeReader(this, begin, end); + this._pdfDataRangeTransport.requestDataRange(begin, end); + this._rangeReaders.push(reader); + return reader; + }, + cancelAllRequests: function PDFDataTransportStream_cancelAllRequests(reason) { + if (this._fullRequestReader) { + this._fullRequestReader.cancel(reason); + } + var readers = this._rangeReaders.slice(0); + readers.forEach(function (rangeReader) { + rangeReader.cancel(reason); + }); + this._pdfDataRangeTransport.abort(); + } + }; + function PDFDataTransportStreamReader(stream, queuedChunks) { + this._stream = stream; + this._done = false; + this._filename = null; + this._queuedChunks = queuedChunks || []; + this._requests = []; + this._headersReady = Promise.resolve(); + stream._fullRequestReader = this; + this.onProgress = null; + } + PDFDataTransportStreamReader.prototype = { + _enqueue: function PDFDataTransportStreamReader_enqueue(chunk) { + if (this._done) { + return; + } + if (this._requests.length > 0) { + var requestCapability = this._requests.shift(); + requestCapability.resolve({ + value: chunk, + done: false + }); + return; + } + this._queuedChunks.push(chunk); + }, + get headersReady() { + return this._headersReady; + }, + get filename() { + return this._filename; + }, + get isRangeSupported() { + return this._stream._isRangeSupported; + }, + get isStreamingSupported() { + return this._stream._isStreamingSupported; + }, + get contentLength() { + return this._stream._contentLength; + }, + read: function () { + var _ref = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee() { + var chunk, requestCapability; + return _regenerator2.default.wrap(function _callee$(_context) { + while (1) { + switch (_context.prev = _context.next) { + case 0: + if (!(this._queuedChunks.length > 0)) { + _context.next = 3; + break; + } + + chunk = this._queuedChunks.shift(); + return _context.abrupt('return', { + value: chunk, + done: false + }); + + case 3: + if (!this._done) { + _context.next = 5; + break; + } + + return _context.abrupt('return', { + value: undefined, + done: true + }); + + case 5: + requestCapability = (0, _util.createPromiseCapability)(); + + this._requests.push(requestCapability); + return _context.abrupt('return', requestCapability.promise); + + case 8: + case 'end': + return _context.stop(); + } + } + }, _callee, this); + })); + + function read() { + return _ref.apply(this, arguments); + } + + return read; + }(), + + cancel: function PDFDataTransportStreamReader_cancel(reason) { + this._done = true; + this._requests.forEach(function (requestCapability) { + requestCapability.resolve({ + value: undefined, + done: true + }); + }); + this._requests = []; + } + }; + function PDFDataTransportStreamRangeReader(stream, begin, end) { + this._stream = stream; + this._begin = begin; + this._end = end; + this._queuedChunk = null; + this._requests = []; + this._done = false; + this.onProgress = null; + } + PDFDataTransportStreamRangeReader.prototype = { + _enqueue: function PDFDataTransportStreamRangeReader_enqueue(chunk) { + if (this._done) { + return; + } + if (this._requests.length === 0) { + this._queuedChunk = chunk; + } else { + var requestsCapability = this._requests.shift(); + requestsCapability.resolve({ + value: chunk, + done: false + }); + this._requests.forEach(function (requestCapability) { + requestCapability.resolve({ + value: undefined, + done: true + }); + }); + this._requests = []; + } + this._done = true; + this._stream._removeRangeReader(this); + }, + get isStreamingSupported() { + return false; + }, + read: function () { + var _ref2 = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee2() { + var chunk, requestCapability; + return _regenerator2.default.wrap(function _callee2$(_context2) { + while (1) { + switch (_context2.prev = _context2.next) { + case 0: + if (!this._queuedChunk) { + _context2.next = 4; + break; + } + + chunk = this._queuedChunk; + + this._queuedChunk = null; + return _context2.abrupt('return', { + value: chunk, + done: false + }); + + case 4: + if (!this._done) { + _context2.next = 6; + break; + } + + return _context2.abrupt('return', { + value: undefined, + done: true + }); + + case 6: + requestCapability = (0, _util.createPromiseCapability)(); + + this._requests.push(requestCapability); + return _context2.abrupt('return', requestCapability.promise); + + case 9: + case 'end': + return _context2.stop(); + } + } + }, _callee2, this); + })); + + function read() { + return _ref2.apply(this, arguments); + } + + return read; + }(), + + cancel: function PDFDataTransportStreamRangeReader_cancel(reason) { + this._done = true; + this._requests.forEach(function (requestCapability) { + requestCapability.resolve({ + value: undefined, + done: true + }); + }); + this._requests = []; + this._stream._removeRangeReader(this); + } + }; + return PDFDataTransportStream; +}(); +exports.PDFDataTransportStream = PDFDataTransportStream; + +/***/ }), +/* 144 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.WebGLContext = undefined; + +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + +var _util = __w_pdfjs_require__(1); + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var WebGLContext = function () { + function WebGLContext(_ref) { + var _ref$enable = _ref.enable, + enable = _ref$enable === undefined ? false : _ref$enable; + + _classCallCheck(this, WebGLContext); + + this._enabled = enable === true; + } + + _createClass(WebGLContext, [{ + key: 'composeSMask', + value: function composeSMask(_ref2) { + var layer = _ref2.layer, + mask = _ref2.mask, + properties = _ref2.properties; + + return WebGLUtils.composeSMask(layer, mask, properties); + } + }, { + key: 'drawFigures', + value: function drawFigures(_ref3) { + var width = _ref3.width, + height = _ref3.height, + backgroundColor = _ref3.backgroundColor, + figures = _ref3.figures, + context = _ref3.context; + + return WebGLUtils.drawFigures(width, height, backgroundColor, figures, context); + } + }, { + key: 'clear', + value: function clear() { + WebGLUtils.cleanup(); + } + }, { + key: 'isEnabled', + get: function get() { + var enabled = this._enabled; + if (enabled) { + enabled = WebGLUtils.tryInitGL(); + } + return (0, _util.shadow)(this, 'isEnabled', enabled); + } + }]); + + return WebGLContext; +}(); + +var WebGLUtils = function WebGLUtilsClosure() { + function loadShader(gl, code, shaderType) { + var shader = gl.createShader(shaderType); + gl.shaderSource(shader, code); + gl.compileShader(shader); + var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS); + if (!compiled) { + var errorMsg = gl.getShaderInfoLog(shader); + throw new Error('Error during shader compilation: ' + errorMsg); + } + return shader; + } + function createVertexShader(gl, code) { + return loadShader(gl, code, gl.VERTEX_SHADER); + } + function createFragmentShader(gl, code) { + return loadShader(gl, code, gl.FRAGMENT_SHADER); + } + function createProgram(gl, shaders) { + var program = gl.createProgram(); + for (var i = 0, ii = shaders.length; i < ii; ++i) { + gl.attachShader(program, shaders[i]); + } + gl.linkProgram(program); + var linked = gl.getProgramParameter(program, gl.LINK_STATUS); + if (!linked) { + var errorMsg = gl.getProgramInfoLog(program); + throw new Error('Error during program linking: ' + errorMsg); + } + return program; + } + function createTexture(gl, image, textureId) { + gl.activeTexture(textureId); + var texture = gl.createTexture(); + gl.bindTexture(gl.TEXTURE_2D, texture); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); + gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image); + return texture; + } + var currentGL, currentCanvas; + function generateGL() { + if (currentGL) { + return; + } + currentCanvas = document.createElement('canvas'); + currentGL = currentCanvas.getContext('webgl', { premultipliedalpha: false }); + } + var smaskVertexShaderCode = '\ + attribute vec2 a_position; \ + attribute vec2 a_texCoord; \ + \ + uniform vec2 u_resolution; \ + \ + varying vec2 v_texCoord; \ + \ + void main() { \ + vec2 clipSpace = (a_position / u_resolution) * 2.0 - 1.0; \ + gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \ + \ + v_texCoord = a_texCoord; \ + } '; + var smaskFragmentShaderCode = '\ + precision mediump float; \ + \ + uniform vec4 u_backdrop; \ + uniform int u_subtype; \ + uniform sampler2D u_image; \ + uniform sampler2D u_mask; \ + \ + varying vec2 v_texCoord; \ + \ + void main() { \ + vec4 imageColor = texture2D(u_image, v_texCoord); \ + vec4 maskColor = texture2D(u_mask, v_texCoord); \ + if (u_backdrop.a > 0.0) { \ + maskColor.rgb = maskColor.rgb * maskColor.a + \ + u_backdrop.rgb * (1.0 - maskColor.a); \ + } \ + float lum; \ + if (u_subtype == 0) { \ + lum = maskColor.a; \ + } else { \ + lum = maskColor.r * 0.3 + maskColor.g * 0.59 + \ + maskColor.b * 0.11; \ + } \ + imageColor.a *= lum; \ + imageColor.rgb *= imageColor.a; \ + gl_FragColor = imageColor; \ + } '; + var smaskCache = null; + function initSmaskGL() { + var canvas, gl; + generateGL(); + canvas = currentCanvas; + currentCanvas = null; + gl = currentGL; + currentGL = null; + var vertexShader = createVertexShader(gl, smaskVertexShaderCode); + var fragmentShader = createFragmentShader(gl, smaskFragmentShaderCode); + var program = createProgram(gl, [vertexShader, fragmentShader]); + gl.useProgram(program); + var cache = {}; + cache.gl = gl; + cache.canvas = canvas; + cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution'); + cache.positionLocation = gl.getAttribLocation(program, 'a_position'); + cache.backdropLocation = gl.getUniformLocation(program, 'u_backdrop'); + cache.subtypeLocation = gl.getUniformLocation(program, 'u_subtype'); + var texCoordLocation = gl.getAttribLocation(program, 'a_texCoord'); + var texLayerLocation = gl.getUniformLocation(program, 'u_image'); + var texMaskLocation = gl.getUniformLocation(program, 'u_mask'); + var texCoordBuffer = gl.createBuffer(); + gl.bindBuffer(gl.ARRAY_BUFFER, texCoordBuffer); + gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0]), gl.STATIC_DRAW); + gl.enableVertexAttribArray(texCoordLocation); + gl.vertexAttribPointer(texCoordLocation, 2, gl.FLOAT, false, 0, 0); + gl.uniform1i(texLayerLocation, 0); + gl.uniform1i(texMaskLocation, 1); + smaskCache = cache; + } + function composeSMask(layer, mask, properties) { + var width = layer.width, + height = layer.height; + if (!smaskCache) { + initSmaskGL(); + } + var cache = smaskCache, + canvas = cache.canvas, + gl = cache.gl; + canvas.width = width; + canvas.height = height; + gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight); + gl.uniform2f(cache.resolutionLocation, width, height); + if (properties.backdrop) { + gl.uniform4f(cache.resolutionLocation, properties.backdrop[0], properties.backdrop[1], properties.backdrop[2], 1); + } else { + gl.uniform4f(cache.resolutionLocation, 0, 0, 0, 0); + } + gl.uniform1i(cache.subtypeLocation, properties.subtype === 'Luminosity' ? 1 : 0); + var texture = createTexture(gl, layer, gl.TEXTURE0); + var maskTexture = createTexture(gl, mask, gl.TEXTURE1); + var buffer = gl.createBuffer(); + gl.bindBuffer(gl.ARRAY_BUFFER, buffer); + gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([0, 0, width, 0, 0, height, 0, height, width, 0, width, height]), gl.STATIC_DRAW); + gl.enableVertexAttribArray(cache.positionLocation); + gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0); + gl.clearColor(0, 0, 0, 0); + gl.enable(gl.BLEND); + gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA); + gl.clear(gl.COLOR_BUFFER_BIT); + gl.drawArrays(gl.TRIANGLES, 0, 6); + gl.flush(); + gl.deleteTexture(texture); + gl.deleteTexture(maskTexture); + gl.deleteBuffer(buffer); + return canvas; + } + var figuresVertexShaderCode = '\ + attribute vec2 a_position; \ + attribute vec3 a_color; \ + \ + uniform vec2 u_resolution; \ + uniform vec2 u_scale; \ + uniform vec2 u_offset; \ + \ + varying vec4 v_color; \ + \ + void main() { \ + vec2 position = (a_position + u_offset) * u_scale; \ + vec2 clipSpace = (position / u_resolution) * 2.0 - 1.0; \ + gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \ + \ + v_color = vec4(a_color / 255.0, 1.0); \ + } '; + var figuresFragmentShaderCode = '\ + precision mediump float; \ + \ + varying vec4 v_color; \ + \ + void main() { \ + gl_FragColor = v_color; \ + } '; + var figuresCache = null; + function initFiguresGL() { + var canvas, gl; + generateGL(); + canvas = currentCanvas; + currentCanvas = null; + gl = currentGL; + currentGL = null; + var vertexShader = createVertexShader(gl, figuresVertexShaderCode); + var fragmentShader = createFragmentShader(gl, figuresFragmentShaderCode); + var program = createProgram(gl, [vertexShader, fragmentShader]); + gl.useProgram(program); + var cache = {}; + cache.gl = gl; + cache.canvas = canvas; + cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution'); + cache.scaleLocation = gl.getUniformLocation(program, 'u_scale'); + cache.offsetLocation = gl.getUniformLocation(program, 'u_offset'); + cache.positionLocation = gl.getAttribLocation(program, 'a_position'); + cache.colorLocation = gl.getAttribLocation(program, 'a_color'); + figuresCache = cache; + } + function drawFigures(width, height, backgroundColor, figures, context) { + if (!figuresCache) { + initFiguresGL(); + } + var cache = figuresCache, + canvas = cache.canvas, + gl = cache.gl; + canvas.width = width; + canvas.height = height; + gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight); + gl.uniform2f(cache.resolutionLocation, width, height); + var count = 0; + var i, ii, rows; + for (i = 0, ii = figures.length; i < ii; i++) { + switch (figures[i].type) { + case 'lattice': + rows = figures[i].coords.length / figures[i].verticesPerRow | 0; + count += (rows - 1) * (figures[i].verticesPerRow - 1) * 6; + break; + case 'triangles': + count += figures[i].coords.length; + break; + } + } + var coords = new Float32Array(count * 2); + var colors = new Uint8Array(count * 3); + var coordsMap = context.coords, + colorsMap = context.colors; + var pIndex = 0, + cIndex = 0; + for (i = 0, ii = figures.length; i < ii; i++) { + var figure = figures[i], + ps = figure.coords, + cs = figure.colors; + switch (figure.type) { + case 'lattice': + var cols = figure.verticesPerRow; + rows = ps.length / cols | 0; + for (var row = 1; row < rows; row++) { + var offset = row * cols + 1; + for (var col = 1; col < cols; col++, offset++) { + coords[pIndex] = coordsMap[ps[offset - cols - 1]]; + coords[pIndex + 1] = coordsMap[ps[offset - cols - 1] + 1]; + coords[pIndex + 2] = coordsMap[ps[offset - cols]]; + coords[pIndex + 3] = coordsMap[ps[offset - cols] + 1]; + coords[pIndex + 4] = coordsMap[ps[offset - 1]]; + coords[pIndex + 5] = coordsMap[ps[offset - 1] + 1]; + colors[cIndex] = colorsMap[cs[offset - cols - 1]]; + colors[cIndex + 1] = colorsMap[cs[offset - cols - 1] + 1]; + colors[cIndex + 2] = colorsMap[cs[offset - cols - 1] + 2]; + colors[cIndex + 3] = colorsMap[cs[offset - cols]]; + colors[cIndex + 4] = colorsMap[cs[offset - cols] + 1]; + colors[cIndex + 5] = colorsMap[cs[offset - cols] + 2]; + colors[cIndex + 6] = colorsMap[cs[offset - 1]]; + colors[cIndex + 7] = colorsMap[cs[offset - 1] + 1]; + colors[cIndex + 8] = colorsMap[cs[offset - 1] + 2]; + coords[pIndex + 6] = coords[pIndex + 2]; + coords[pIndex + 7] = coords[pIndex + 3]; + coords[pIndex + 8] = coords[pIndex + 4]; + coords[pIndex + 9] = coords[pIndex + 5]; + coords[pIndex + 10] = coordsMap[ps[offset]]; + coords[pIndex + 11] = coordsMap[ps[offset] + 1]; + colors[cIndex + 9] = colors[cIndex + 3]; + colors[cIndex + 10] = colors[cIndex + 4]; + colors[cIndex + 11] = colors[cIndex + 5]; + colors[cIndex + 12] = colors[cIndex + 6]; + colors[cIndex + 13] = colors[cIndex + 7]; + colors[cIndex + 14] = colors[cIndex + 8]; + colors[cIndex + 15] = colorsMap[cs[offset]]; + colors[cIndex + 16] = colorsMap[cs[offset] + 1]; + colors[cIndex + 17] = colorsMap[cs[offset] + 2]; + pIndex += 12; + cIndex += 18; } } - } - var charWidth = width * widthAdvanceScale + spacing * fontDirection; - x += charWidth; - if (restoreNeeded) { - ctx.restore(); - } - } - if (vertical) { - current.y -= x * textHScale; - } else { - current.x += x * textHScale; + break; + case 'triangles': + for (var j = 0, jj = ps.length; j < jj; j++) { + coords[pIndex] = coordsMap[ps[j]]; + coords[pIndex + 1] = coordsMap[ps[j] + 1]; + colors[cIndex] = colorsMap[cs[j]]; + colors[cIndex + 1] = colorsMap[cs[j] + 1]; + colors[cIndex + 2] = colorsMap[cs[j] + 2]; + pIndex += 2; + cIndex += 3; + } + break; } - ctx.restore(); + } + if (backgroundColor) { + gl.clearColor(backgroundColor[0] / 255, backgroundColor[1] / 255, backgroundColor[2] / 255, 1.0); + } else { + gl.clearColor(0, 0, 0, 0); + } + gl.clear(gl.COLOR_BUFFER_BIT); + var coordsBuffer = gl.createBuffer(); + gl.bindBuffer(gl.ARRAY_BUFFER, coordsBuffer); + gl.bufferData(gl.ARRAY_BUFFER, coords, gl.STATIC_DRAW); + gl.enableVertexAttribArray(cache.positionLocation); + gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0); + var colorsBuffer = gl.createBuffer(); + gl.bindBuffer(gl.ARRAY_BUFFER, colorsBuffer); + gl.bufferData(gl.ARRAY_BUFFER, colors, gl.STATIC_DRAW); + gl.enableVertexAttribArray(cache.colorLocation); + gl.vertexAttribPointer(cache.colorLocation, 3, gl.UNSIGNED_BYTE, false, 0, 0); + gl.uniform2f(cache.scaleLocation, context.scaleX, context.scaleY); + gl.uniform2f(cache.offsetLocation, context.offsetX, context.offsetY); + gl.drawArrays(gl.TRIANGLES, 0, count); + gl.flush(); + gl.deleteBuffer(coordsBuffer); + gl.deleteBuffer(colorsBuffer); + return canvas; + } + return { + tryInitGL: function tryInitGL() { + try { + generateGL(); + return !!currentGL; + } catch (ex) {} + return false; }, - showType3Text: function CanvasGraphics_showType3Text(glyphs) { - var ctx = this.ctx; - var current = this.current; - var font = current.font; - var fontSize = current.fontSize; - var fontDirection = current.fontDirection; - var spacingDir = font.vertical ? 1 : -1; - var charSpacing = current.charSpacing; - var wordSpacing = current.wordSpacing; - var textHScale = current.textHScale * fontDirection; - var fontMatrix = current.fontMatrix || FONT_IDENTITY_MATRIX; - var glyphsLength = glyphs.length; - var isTextInvisible = current.textRenderingMode === TextRenderingMode.INVISIBLE; - var i, glyph, width, spacingLength; - if (isTextInvisible || fontSize === 0) { - return; - } - this.cachedGetSinglePixelWidth = null; - ctx.save(); - ctx.transform.apply(ctx, current.textMatrix); - ctx.translate(current.x, current.y); - ctx.scale(textHScale, fontDirection); - for (i = 0; i < glyphsLength; ++i) { - glyph = glyphs[i]; - if (isNum(glyph)) { - spacingLength = spacingDir * glyph * fontSize / 1000; - this.ctx.translate(spacingLength, 0); - current.x += spacingLength * textHScale; - continue; - } - var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing; - var operatorList = font.charProcOperatorList[glyph.operatorListId]; - if (!operatorList) { - warn('Type3 character \"' + glyph.operatorListId + '\" is not available'); - continue; - } - this.processingType3 = glyph; - this.save(); - ctx.scale(fontSize, fontSize); - ctx.transform.apply(ctx, fontMatrix); - this.executeOperatorList(operatorList); - this.restore(); - var transformed = Util.applyTransform([glyph.width, 0], fontMatrix); - width = transformed[0] * fontSize + spacing; - ctx.translate(width, 0); - current.x += width * textHScale; + + composeSMask: composeSMask, + drawFigures: drawFigures, + cleanup: function cleanup() { + if (smaskCache && smaskCache.canvas) { + smaskCache.canvas.width = 0; + smaskCache.canvas.height = 0; } - ctx.restore(); - this.processingType3 = null; - }, - setCharWidth: function CanvasGraphics_setCharWidth(xWidth, yWidth) {}, - setCharWidthAndBounds: function CanvasGraphics_setCharWidthAndBounds(xWidth, yWidth, llx, lly, urx, ury) { - this.ctx.rect(llx, lly, urx - llx, ury - lly); - this.clip(); - this.endPath(); - }, - getColorN_Pattern: function CanvasGraphics_getColorN_Pattern(IR) { - var pattern; - if (IR[0] === 'TilingPattern') { - var color = IR[1]; - var baseTransform = this.baseTransform || this.ctx.mozCurrentTransform.slice(); - var self = this; - var canvasGraphicsFactory = { - createCanvasGraphics: function (ctx) { - return new CanvasGraphics(ctx, self.commonObjs, self.objs, self.canvasFactory); - } - }; - pattern = new TilingPattern(IR, color, this.ctx, canvasGraphicsFactory, baseTransform); - } else { - pattern = getShadingPatternFromIR(IR); + if (figuresCache && figuresCache.canvas) { + figuresCache.canvas.width = 0; + figuresCache.canvas.height = 0; } - return pattern; - }, - setStrokeColorN: function CanvasGraphics_setStrokeColorN() { - this.current.strokeColor = this.getColorN_Pattern(arguments); - }, - setFillColorN: function CanvasGraphics_setFillColorN() { - this.current.fillColor = this.getColorN_Pattern(arguments); - this.current.patternFill = true; - }, - setStrokeRGBColor: function CanvasGraphics_setStrokeRGBColor(r, g, b) { - var color = Util.makeCssRgb(r, g, b); - this.ctx.strokeStyle = color; - this.current.strokeColor = color; - }, - setFillRGBColor: function CanvasGraphics_setFillRGBColor(r, g, b) { - var color = Util.makeCssRgb(r, g, b); - this.ctx.fillStyle = color; - this.current.fillColor = color; - this.current.patternFill = false; - }, - shadingFill: function CanvasGraphics_shadingFill(patternIR) { - var ctx = this.ctx; - this.save(); - var pattern = getShadingPatternFromIR(patternIR); - ctx.fillStyle = pattern.getPattern(ctx, this, true); - var inv = ctx.mozCurrentTransformInverse; - if (inv) { - var canvas = ctx.canvas; - var width = canvas.width; - var height = canvas.height; - var bl = Util.applyTransform([0, 0], inv); - var br = Util.applyTransform([0, height], inv); - var ul = Util.applyTransform([width, 0], inv); - var ur = Util.applyTransform([width, height], inv); - var x0 = Math.min(bl[0], br[0], ul[0], ur[0]); - var y0 = Math.min(bl[1], br[1], ul[1], ur[1]); - var x1 = Math.max(bl[0], br[0], ul[0], ur[0]); - var y1 = Math.max(bl[1], br[1], ul[1], ur[1]); - this.ctx.fillRect(x0, y0, x1 - x0, y1 - y0); + smaskCache = null; + figuresCache = null; + } + }; +}(); +exports.WebGLContext = WebGLContext; + +/***/ }), +/* 145 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.renderTextLayer = undefined; + +var _util = __w_pdfjs_require__(1); + +var _global_scope = __w_pdfjs_require__(3); + +var _global_scope2 = _interopRequireDefault(_global_scope); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +var renderTextLayer = function renderTextLayerClosure() { + var MAX_TEXT_DIVS_TO_RENDER = 100000; + var NonWhitespaceRegexp = /\S/; + function isAllWhitespace(str) { + return !NonWhitespaceRegexp.test(str); + } + var styleBuf = ['left: ', 0, 'px; top: ', 0, 'px; font-size: ', 0, 'px; font-family: ', '', ';']; + function appendText(task, geom, styles) { + var textDiv = document.createElement('div'); + var textDivProperties = { + style: null, + angle: 0, + canvasWidth: 0, + isWhitespace: false, + originalTransform: null, + paddingBottom: 0, + paddingLeft: 0, + paddingRight: 0, + paddingTop: 0, + scale: 1 + }; + task._textDivs.push(textDiv); + if (isAllWhitespace(geom.str)) { + textDivProperties.isWhitespace = true; + task._textDivProperties.set(textDiv, textDivProperties); + return; + } + var tx = _util.Util.transform(task._viewport.transform, geom.transform); + var angle = Math.atan2(tx[1], tx[0]); + var style = styles[geom.fontName]; + if (style.vertical) { + angle += Math.PI / 2; + } + var fontHeight = Math.sqrt(tx[2] * tx[2] + tx[3] * tx[3]); + var fontAscent = fontHeight; + if (style.ascent) { + fontAscent = style.ascent * fontAscent; + } else if (style.descent) { + fontAscent = (1 + style.descent) * fontAscent; + } + var left; + var top; + if (angle === 0) { + left = tx[4]; + top = tx[5] - fontAscent; + } else { + left = tx[4] + fontAscent * Math.sin(angle); + top = tx[5] - fontAscent * Math.cos(angle); + } + styleBuf[1] = left; + styleBuf[3] = top; + styleBuf[5] = fontHeight; + styleBuf[7] = style.fontFamily; + textDivProperties.style = styleBuf.join(''); + textDiv.setAttribute('style', textDivProperties.style); + textDiv.textContent = geom.str; + if (task._fontInspectorEnabled) { + textDiv.dataset.fontName = geom.fontName; + } + if (angle !== 0) { + textDivProperties.angle = angle * (180 / Math.PI); + } + if (geom.str.length > 1) { + if (style.vertical) { + textDivProperties.canvasWidth = geom.height * task._viewport.scale; } else { - this.ctx.fillRect(-1e10, -1e10, 2e10, 2e10); - } - this.restore(); - }, - beginInlineImage: function CanvasGraphics_beginInlineImage() { - error('Should not call beginInlineImage'); - }, - beginImageData: function CanvasGraphics_beginImageData() { - error('Should not call beginImageData'); - }, - paintFormXObjectBegin: function CanvasGraphics_paintFormXObjectBegin(matrix, bbox) { - this.save(); - this.baseTransformStack.push(this.baseTransform); - if (isArray(matrix) && matrix.length === 6) { - this.transform.apply(this, matrix); - } - this.baseTransform = this.ctx.mozCurrentTransform; - if (isArray(bbox) && bbox.length === 4) { - var width = bbox[2] - bbox[0]; - var height = bbox[3] - bbox[1]; - this.ctx.rect(bbox[0], bbox[1], width, height); - this.clip(); - this.endPath(); - } - }, - paintFormXObjectEnd: function CanvasGraphics_paintFormXObjectEnd() { - this.restore(); - this.baseTransform = this.baseTransformStack.pop(); - }, - beginGroup: function CanvasGraphics_beginGroup(group) { - this.save(); - var currentCtx = this.ctx; - if (!group.isolated) { - info('TODO: Support non-isolated groups.'); - } - if (group.knockout) { - warn('Knockout groups not supported.'); + textDivProperties.canvasWidth = geom.width * task._viewport.scale; } - var currentTransform = currentCtx.mozCurrentTransform; - if (group.matrix) { - currentCtx.transform.apply(currentCtx, group.matrix); + } + task._textDivProperties.set(textDiv, textDivProperties); + if (task._textContentStream) { + task._layoutText(textDiv); + } + if (task._enhanceTextSelection) { + var angleCos = 1, + angleSin = 0; + if (angle !== 0) { + angleCos = Math.cos(angle); + angleSin = Math.sin(angle); } - assert(group.bbox, 'Bounding box is required.'); - var bounds = Util.getAxialAlignedBoundingBox(group.bbox, currentCtx.mozCurrentTransform); - var canvasBounds = [0, 0, currentCtx.canvas.width, currentCtx.canvas.height]; - bounds = Util.intersect(bounds, canvasBounds) || [0, 0, 0, 0]; - var offsetX = Math.floor(bounds[0]); - var offsetY = Math.floor(bounds[1]); - var drawnWidth = Math.max(Math.ceil(bounds[2]) - offsetX, 1); - var drawnHeight = Math.max(Math.ceil(bounds[3]) - offsetY, 1); - var scaleX = 1, - scaleY = 1; - if (drawnWidth > MAX_GROUP_SIZE) { - scaleX = drawnWidth / MAX_GROUP_SIZE; - drawnWidth = MAX_GROUP_SIZE; + var divWidth = (style.vertical ? geom.height : geom.width) * task._viewport.scale; + var divHeight = fontHeight; + var m, b; + if (angle !== 0) { + m = [angleCos, angleSin, -angleSin, angleCos, left, top]; + b = _util.Util.getAxialAlignedBoundingBox([0, 0, divWidth, divHeight], m); + } else { + b = [left, top, left + divWidth, top + divHeight]; } - if (drawnHeight > MAX_GROUP_SIZE) { - scaleY = drawnHeight / MAX_GROUP_SIZE; - drawnHeight = MAX_GROUP_SIZE; + task._bounds.push({ + left: b[0], + top: b[1], + right: b[2], + bottom: b[3], + div: textDiv, + size: [divWidth, divHeight], + m: m + }); + } + } + function render(task) { + if (task._canceled) { + return; + } + var textDivs = task._textDivs; + var capability = task._capability; + var textDivsLength = textDivs.length; + if (textDivsLength > MAX_TEXT_DIVS_TO_RENDER) { + task._renderingDone = true; + capability.resolve(); + return; + } + if (!task._textContentStream) { + for (var i = 0; i < textDivsLength; i++) { + task._layoutText(textDivs[i]); } - var cacheId = 'groupAt' + this.groupLevel; - if (group.smask) { - cacheId += '_smask_' + this.smaskCounter++ % 2; + } + task._renderingDone = true; + capability.resolve(); + } + function expand(task) { + var bounds = task._bounds; + var viewport = task._viewport; + var expanded = expandBounds(viewport.width, viewport.height, bounds); + for (var i = 0; i < expanded.length; i++) { + var div = bounds[i].div; + var divProperties = task._textDivProperties.get(div); + if (divProperties.angle === 0) { + divProperties.paddingLeft = bounds[i].left - expanded[i].left; + divProperties.paddingTop = bounds[i].top - expanded[i].top; + divProperties.paddingRight = expanded[i].right - bounds[i].right; + divProperties.paddingBottom = expanded[i].bottom - bounds[i].bottom; + task._textDivProperties.set(div, divProperties); + continue; } - var scratchCanvas = this.cachedCanvases.getCanvas(cacheId, drawnWidth, drawnHeight, true); - var groupCtx = scratchCanvas.context; - groupCtx.scale(1 / scaleX, 1 / scaleY); - groupCtx.translate(-offsetX, -offsetY); - groupCtx.transform.apply(groupCtx, currentTransform); - if (group.smask) { - this.smaskStack.push({ - canvas: scratchCanvas.canvas, - context: groupCtx, - offsetX: offsetX, - offsetY: offsetY, - scaleX: scaleX, - scaleY: scaleY, - subtype: group.smask.subtype, - backdrop: group.smask.backdrop, - transferMap: group.smask.transferMap || null, - startTransformInverse: null - }); - } else { - currentCtx.setTransform(1, 0, 0, 1, 0, 0); - currentCtx.translate(offsetX, offsetY); - currentCtx.scale(scaleX, scaleY); + var e = expanded[i], + b = bounds[i]; + var m = b.m, + c = m[0], + s = m[1]; + var points = [[0, 0], [0, b.size[1]], [b.size[0], 0], b.size]; + var ts = new Float64Array(64); + points.forEach(function (p, i) { + var t = _util.Util.applyTransform(p, m); + ts[i + 0] = c && (e.left - t[0]) / c; + ts[i + 4] = s && (e.top - t[1]) / s; + ts[i + 8] = c && (e.right - t[0]) / c; + ts[i + 12] = s && (e.bottom - t[1]) / s; + ts[i + 16] = s && (e.left - t[0]) / -s; + ts[i + 20] = c && (e.top - t[1]) / c; + ts[i + 24] = s && (e.right - t[0]) / -s; + ts[i + 28] = c && (e.bottom - t[1]) / c; + ts[i + 32] = c && (e.left - t[0]) / -c; + ts[i + 36] = s && (e.top - t[1]) / -s; + ts[i + 40] = c && (e.right - t[0]) / -c; + ts[i + 44] = s && (e.bottom - t[1]) / -s; + ts[i + 48] = s && (e.left - t[0]) / s; + ts[i + 52] = c && (e.top - t[1]) / -c; + ts[i + 56] = s && (e.right - t[0]) / s; + ts[i + 60] = c && (e.bottom - t[1]) / -c; + }); + var findPositiveMin = function findPositiveMin(ts, offset, count) { + var result = 0; + for (var i = 0; i < count; i++) { + var t = ts[offset++]; + if (t > 0) { + result = result ? Math.min(t, result) : t; + } + } + return result; + }; + var boxScale = 1 + Math.min(Math.abs(c), Math.abs(s)); + divProperties.paddingLeft = findPositiveMin(ts, 32, 16) / boxScale; + divProperties.paddingTop = findPositiveMin(ts, 48, 16) / boxScale; + divProperties.paddingRight = findPositiveMin(ts, 0, 16) / boxScale; + divProperties.paddingBottom = findPositiveMin(ts, 16, 16) / boxScale; + task._textDivProperties.set(div, divProperties); + } + } + function expandBounds(width, height, boxes) { + var bounds = boxes.map(function (box, i) { + return { + x1: box.left, + y1: box.top, + x2: box.right, + y2: box.bottom, + index: i, + x1New: undefined, + x2New: undefined + }; + }); + expandBoundsLTR(width, bounds); + var expanded = new Array(boxes.length); + bounds.forEach(function (b) { + var i = b.index; + expanded[i] = { + left: b.x1New, + top: 0, + right: b.x2New, + bottom: 0 + }; + }); + boxes.map(function (box, i) { + var e = expanded[i], + b = bounds[i]; + b.x1 = box.top; + b.y1 = width - e.right; + b.x2 = box.bottom; + b.y2 = width - e.left; + b.index = i; + b.x1New = undefined; + b.x2New = undefined; + }); + expandBoundsLTR(height, bounds); + bounds.forEach(function (b) { + var i = b.index; + expanded[i].top = b.x1New; + expanded[i].bottom = b.x2New; + }); + return expanded; + } + function expandBoundsLTR(width, bounds) { + bounds.sort(function (a, b) { + return a.x1 - b.x1 || a.index - b.index; + }); + var fakeBoundary = { + x1: -Infinity, + y1: -Infinity, + x2: 0, + y2: Infinity, + index: -1, + x1New: 0, + x2New: 0 + }; + var horizon = [{ + start: -Infinity, + end: Infinity, + boundary: fakeBoundary + }]; + bounds.forEach(function (boundary) { + var i = 0; + while (i < horizon.length && horizon[i].end <= boundary.y1) { + i++; } - copyCtxState(currentCtx, groupCtx); - this.ctx = groupCtx; - this.setGState([['BM', 'Normal'], ['ca', 1], ['CA', 1]]); - this.groupStack.push(currentCtx); - this.groupLevel++; - this.current.activeSMask = null; - }, - endGroup: function CanvasGraphics_endGroup(group) { - this.groupLevel--; - var groupCtx = this.ctx; - this.ctx = this.groupStack.pop(); - if (this.ctx.imageSmoothingEnabled !== undefined) { - this.ctx.imageSmoothingEnabled = false; - } else { - this.ctx.mozImageSmoothingEnabled = false; + var j = horizon.length - 1; + while (j >= 0 && horizon[j].start >= boundary.y2) { + j--; } - if (group.smask) { - this.tempSMask = this.smaskStack.pop(); - } else { - this.ctx.drawImage(groupCtx.canvas, 0, 0); + var horizonPart, affectedBoundary; + var q, + k, + maxXNew = -Infinity; + for (q = i; q <= j; q++) { + horizonPart = horizon[q]; + affectedBoundary = horizonPart.boundary; + var xNew; + if (affectedBoundary.x2 > boundary.x1) { + xNew = affectedBoundary.index > boundary.index ? affectedBoundary.x1New : boundary.x1; + } else if (affectedBoundary.x2New === undefined) { + xNew = (affectedBoundary.x2 + boundary.x1) / 2; + } else { + xNew = affectedBoundary.x2New; + } + if (xNew > maxXNew) { + maxXNew = xNew; + } } - this.restore(); - }, - beginAnnotations: function CanvasGraphics_beginAnnotations() { - this.save(); - this.current = new CanvasExtraState(); - if (this.baseTransform) { - this.ctx.setTransform.apply(this.ctx, this.baseTransform); + boundary.x1New = maxXNew; + for (q = i; q <= j; q++) { + horizonPart = horizon[q]; + affectedBoundary = horizonPart.boundary; + if (affectedBoundary.x2New === undefined) { + if (affectedBoundary.x2 > boundary.x1) { + if (affectedBoundary.index > boundary.index) { + affectedBoundary.x2New = affectedBoundary.x2; + } + } else { + affectedBoundary.x2New = maxXNew; + } + } else if (affectedBoundary.x2New > maxXNew) { + affectedBoundary.x2New = Math.max(maxXNew, affectedBoundary.x2); + } } - }, - endAnnotations: function CanvasGraphics_endAnnotations() { - this.restore(); - }, - beginAnnotation: function CanvasGraphics_beginAnnotation(rect, transform, matrix) { - this.save(); - if (isArray(rect) && rect.length === 4) { - var width = rect[2] - rect[0]; - var height = rect[3] - rect[1]; - this.ctx.rect(rect[0], rect[1], width, height); - this.clip(); - this.endPath(); + var changedHorizon = [], + lastBoundary = null; + for (q = i; q <= j; q++) { + horizonPart = horizon[q]; + affectedBoundary = horizonPart.boundary; + var useBoundary = affectedBoundary.x2 > boundary.x2 ? affectedBoundary : boundary; + if (lastBoundary === useBoundary) { + changedHorizon[changedHorizon.length - 1].end = horizonPart.end; + } else { + changedHorizon.push({ + start: horizonPart.start, + end: horizonPart.end, + boundary: useBoundary + }); + lastBoundary = useBoundary; + } } - this.transform.apply(this, transform); - this.transform.apply(this, matrix); - }, - endAnnotation: function CanvasGraphics_endAnnotation() { - this.restore(); - }, - paintJpegXObject: function CanvasGraphics_paintJpegXObject(objId, w, h) { - var domImage = this.objs.get(objId); - if (!domImage) { - warn('Dependent image isn\'t ready yet'); - return; + if (horizon[i].start < boundary.y1) { + changedHorizon[0].start = boundary.y1; + changedHorizon.unshift({ + start: horizon[i].start, + end: boundary.y1, + boundary: horizon[i].boundary + }); } - this.save(); - var ctx = this.ctx; - ctx.scale(1 / w, -1 / h); - ctx.drawImage(domImage, 0, 0, domImage.width, domImage.height, 0, -h, w, h); - if (this.imageLayer) { - var currentTransform = ctx.mozCurrentTransformInverse; - var position = this.getCanvasPosition(0, 0); - this.imageLayer.appendImage({ - objId: objId, - left: position[0], - top: position[1], - width: w / currentTransform[0], - height: h / currentTransform[3] + if (boundary.y2 < horizon[j].end) { + changedHorizon[changedHorizon.length - 1].end = boundary.y2; + changedHorizon.push({ + start: boundary.y2, + end: horizon[j].end, + boundary: horizon[j].boundary }); } - this.restore(); - }, - paintImageMaskXObject: function CanvasGraphics_paintImageMaskXObject(img) { - var ctx = this.ctx; - var width = img.width, - height = img.height; - var fillColor = this.current.fillColor; - var isPatternFill = this.current.patternFill; - var glyph = this.processingType3; - if (COMPILE_TYPE3_GLYPHS && glyph && glyph.compiled === undefined) { - if (width <= MAX_SIZE_TO_COMPILE && height <= MAX_SIZE_TO_COMPILE) { - glyph.compiled = compileType3Glyph({ - data: img.data, - width: width, - height: height - }); - } else { - glyph.compiled = null; + for (q = i; q <= j; q++) { + horizonPart = horizon[q]; + affectedBoundary = horizonPart.boundary; + if (affectedBoundary.x2New !== undefined) { + continue; + } + var used = false; + for (k = i - 1; !used && k >= 0 && horizon[k].start >= affectedBoundary.y1; k--) { + used = horizon[k].boundary === affectedBoundary; + } + for (k = j + 1; !used && k < horizon.length && horizon[k].end <= affectedBoundary.y2; k++) { + used = horizon[k].boundary === affectedBoundary; + } + for (k = 0; !used && k < changedHorizon.length; k++) { + used = changedHorizon[k].boundary === affectedBoundary; + } + if (!used) { + affectedBoundary.x2New = maxXNew; } } - if (glyph && glyph.compiled) { - glyph.compiled(ctx); - return; - } - var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas', width, height); - var maskCtx = maskCanvas.context; - maskCtx.save(); - putBinaryImageMask(maskCtx, img); - maskCtx.globalCompositeOperation = 'source-in'; - maskCtx.fillStyle = isPatternFill ? fillColor.getPattern(maskCtx, this) : fillColor; - maskCtx.fillRect(0, 0, width, height); - maskCtx.restore(); - this.paintInlineImageXObject(maskCanvas.canvas); - }, - paintImageMaskXObjectRepeat: function CanvasGraphics_paintImageMaskXObjectRepeat(imgData, scaleX, scaleY, positions) { - var width = imgData.width; - var height = imgData.height; - var fillColor = this.current.fillColor; - var isPatternFill = this.current.patternFill; - var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas', width, height); - var maskCtx = maskCanvas.context; - maskCtx.save(); - putBinaryImageMask(maskCtx, imgData); - maskCtx.globalCompositeOperation = 'source-in'; - maskCtx.fillStyle = isPatternFill ? fillColor.getPattern(maskCtx, this) : fillColor; - maskCtx.fillRect(0, 0, width, height); - maskCtx.restore(); - var ctx = this.ctx; - for (var i = 0, ii = positions.length; i < ii; i += 2) { - ctx.save(); - ctx.transform(scaleX, 0, 0, scaleY, positions[i], positions[i + 1]); - ctx.scale(1, -1); - ctx.drawImage(maskCanvas.canvas, 0, 0, width, height, 0, -1, 1, 1); - ctx.restore(); + Array.prototype.splice.apply(horizon, [i, j - i + 1].concat(changedHorizon)); + }); + horizon.forEach(function (horizonPart) { + var affectedBoundary = horizonPart.boundary; + if (affectedBoundary.x2New === undefined) { + affectedBoundary.x2New = Math.max(width, affectedBoundary.x2); } + }); + } + function TextLayerRenderTask(_ref) { + var textContent = _ref.textContent, + textContentStream = _ref.textContentStream, + container = _ref.container, + viewport = _ref.viewport, + textDivs = _ref.textDivs, + textContentItemsStr = _ref.textContentItemsStr, + enhanceTextSelection = _ref.enhanceTextSelection; + + this._textContent = textContent; + this._textContentStream = textContentStream; + this._container = container; + this._viewport = viewport; + this._textDivs = textDivs || []; + this._textContentItemsStr = textContentItemsStr || []; + this._enhanceTextSelection = !!enhanceTextSelection; + this._fontInspectorEnabled = !!(_global_scope2.default.FontInspector && _global_scope2.default.FontInspector.enabled); + this._reader = null; + this._layoutTextLastFontSize = null; + this._layoutTextLastFontFamily = null; + this._layoutTextCtx = null; + this._textDivProperties = new WeakMap(); + this._renderingDone = false; + this._canceled = false; + this._capability = (0, _util.createPromiseCapability)(); + this._renderTimer = null; + this._bounds = []; + } + TextLayerRenderTask.prototype = { + get promise() { + return this._capability.promise; }, - paintImageMaskXObjectGroup: function CanvasGraphics_paintImageMaskXObjectGroup(images) { - var ctx = this.ctx; - var fillColor = this.current.fillColor; - var isPatternFill = this.current.patternFill; - for (var i = 0, ii = images.length; i < ii; i++) { - var image = images[i]; - var width = image.width, - height = image.height; - var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas', width, height); - var maskCtx = maskCanvas.context; - maskCtx.save(); - putBinaryImageMask(maskCtx, image); - maskCtx.globalCompositeOperation = 'source-in'; - maskCtx.fillStyle = isPatternFill ? fillColor.getPattern(maskCtx, this) : fillColor; - maskCtx.fillRect(0, 0, width, height); - maskCtx.restore(); - ctx.save(); - ctx.transform.apply(ctx, image.transform); - ctx.scale(1, -1); - ctx.drawImage(maskCanvas.canvas, 0, 0, width, height, 0, -1, 1, 1); - ctx.restore(); + cancel: function TextLayer_cancel() { + if (this._reader) { + this._reader.cancel(new _util.AbortException('text layer task cancelled')); + this._reader = null; } + this._canceled = true; + if (this._renderTimer !== null) { + clearTimeout(this._renderTimer); + this._renderTimer = null; + } + this._capability.reject('canceled'); }, - paintImageXObject: function CanvasGraphics_paintImageXObject(objId) { - var imgData = this.objs.get(objId); - if (!imgData) { - warn('Dependent image isn\'t ready yet'); - return; + _processItems: function _processItems(items, styleCache) { + for (var i = 0, len = items.length; i < len; i++) { + this._textContentItemsStr.push(items[i].str); + appendText(this, items[i], styleCache); } - this.paintInlineImageXObject(imgData); }, - paintImageXObjectRepeat: function CanvasGraphics_paintImageXObjectRepeat(objId, scaleX, scaleY, positions) { - var imgData = this.objs.get(objId); - if (!imgData) { - warn('Dependent image isn\'t ready yet'); + _layoutText: function _layoutText(textDiv) { + var textLayerFrag = this._container; + var textDivProperties = this._textDivProperties.get(textDiv); + if (textDivProperties.isWhitespace) { return; } - var width = imgData.width; - var height = imgData.height; - var map = []; - for (var i = 0, ii = positions.length; i < ii; i += 2) { - map.push({ - transform: [scaleX, 0, 0, scaleY, positions[i], positions[i + 1]], - x: 0, - y: 0, - w: width, - h: height - }); + var fontSize = textDiv.style.fontSize; + var fontFamily = textDiv.style.fontFamily; + if (fontSize !== this._layoutTextLastFontSize || fontFamily !== this._layoutTextLastFontFamily) { + this._layoutTextCtx.font = fontSize + ' ' + fontFamily; + this._layoutTextLastFontSize = fontSize; + this._layoutTextLastFontFamily = fontFamily; } - this.paintInlineImageXObjectGroup(imgData, map); + var width = this._layoutTextCtx.measureText(textDiv.textContent).width; + var transform = ''; + if (textDivProperties.canvasWidth !== 0 && width > 0) { + textDivProperties.scale = textDivProperties.canvasWidth / width; + transform = 'scaleX(' + textDivProperties.scale + ')'; + } + if (textDivProperties.angle !== 0) { + transform = 'rotate(' + textDivProperties.angle + 'deg) ' + transform; + } + if (transform !== '') { + textDivProperties.originalTransform = transform; + textDiv.style.transform = transform; + } + this._textDivProperties.set(textDiv, textDivProperties); + textLayerFrag.appendChild(textDiv); }, - paintInlineImageXObject: function CanvasGraphics_paintInlineImageXObject(imgData) { - var width = imgData.width; - var height = imgData.height; - var ctx = this.ctx; - this.save(); - ctx.scale(1 / width, -1 / height); - var currentTransform = ctx.mozCurrentTransformInverse; - var a = currentTransform[0], - b = currentTransform[1]; - var widthScale = Math.max(Math.sqrt(a * a + b * b), 1); - var c = currentTransform[2], - d = currentTransform[3]; - var heightScale = Math.max(Math.sqrt(c * c + d * d), 1); - var imgToPaint, tmpCanvas; - if (imgData instanceof HTMLElement || !imgData.data) { - imgToPaint = imgData; + + _render: function TextLayer_render(timeout) { + var _this = this; + + var capability = (0, _util.createPromiseCapability)(); + var styleCache = Object.create(null); + var canvas = document.createElement('canvas'); + canvas.mozOpaque = true; + this._layoutTextCtx = canvas.getContext('2d', { alpha: false }); + if (this._textContent) { + var textItems = this._textContent.items; + var textStyles = this._textContent.styles; + this._processItems(textItems, textStyles); + capability.resolve(); + } else if (this._textContentStream) { + var pump = function pump() { + _this._reader.read().then(function (_ref2) { + var value = _ref2.value, + done = _ref2.done; + + if (done) { + capability.resolve(); + return; + } + Object.assign(styleCache, value.styles); + _this._processItems(value.items, styleCache); + pump(); + }, capability.reject); + }; + this._reader = this._textContentStream.getReader(); + pump(); } else { - tmpCanvas = this.cachedCanvases.getCanvas('inlineImage', width, height); - var tmpCtx = tmpCanvas.context; - putBinaryImageData(tmpCtx, imgData); - imgToPaint = tmpCanvas.canvas; + throw new Error('Neither "textContent" nor "textContentStream"' + ' parameters specified.'); + } + capability.promise.then(function () { + styleCache = null; + if (!timeout) { + render(_this); + } else { + _this._renderTimer = setTimeout(function () { + render(_this); + _this._renderTimer = null; + }, timeout); + } + }, this._capability.reject); + }, + expandTextDivs: function TextLayer_expandTextDivs(expandDivs) { + if (!this._enhanceTextSelection || !this._renderingDone) { + return; + } + if (this._bounds !== null) { + expand(this); + this._bounds = null; + } + for (var i = 0, ii = this._textDivs.length; i < ii; i++) { + var div = this._textDivs[i]; + var divProperties = this._textDivProperties.get(div); + if (divProperties.isWhitespace) { + continue; + } + if (expandDivs) { + var transform = '', + padding = ''; + if (divProperties.scale !== 1) { + transform = 'scaleX(' + divProperties.scale + ')'; + } + if (divProperties.angle !== 0) { + transform = 'rotate(' + divProperties.angle + 'deg) ' + transform; + } + if (divProperties.paddingLeft !== 0) { + padding += ' padding-left: ' + divProperties.paddingLeft / divProperties.scale + 'px;'; + transform += ' translateX(' + -divProperties.paddingLeft / divProperties.scale + 'px)'; + } + if (divProperties.paddingTop !== 0) { + padding += ' padding-top: ' + divProperties.paddingTop + 'px;'; + transform += ' translateY(' + -divProperties.paddingTop + 'px)'; + } + if (divProperties.paddingRight !== 0) { + padding += ' padding-right: ' + divProperties.paddingRight / divProperties.scale + 'px;'; + } + if (divProperties.paddingBottom !== 0) { + padding += ' padding-bottom: ' + divProperties.paddingBottom + 'px;'; + } + if (padding !== '') { + div.setAttribute('style', divProperties.style + padding); + } + if (transform !== '') { + div.style.transform = transform; + } + } else { + div.style.padding = 0; + div.style.transform = divProperties.originalTransform || ''; + } + } + } + }; + function renderTextLayer(renderParameters) { + var task = new TextLayerRenderTask({ + textContent: renderParameters.textContent, + textContentStream: renderParameters.textContentStream, + container: renderParameters.container, + viewport: renderParameters.viewport, + textDivs: renderParameters.textDivs, + textContentItemsStr: renderParameters.textContentItemsStr, + enhanceTextSelection: renderParameters.enhanceTextSelection + }); + task._render(renderParameters.timeout); + return task; + } + return renderTextLayer; +}(); +exports.renderTextLayer = renderTextLayer; + +/***/ }), +/* 146 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.AnnotationLayer = undefined; + +var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }; + +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + +var _dom_utils = __w_pdfjs_require__(130); + +var _util = __w_pdfjs_require__(1); + +function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var AnnotationElementFactory = function () { + function AnnotationElementFactory() { + _classCallCheck(this, AnnotationElementFactory); + } + + _createClass(AnnotationElementFactory, null, [{ + key: 'create', + value: function create(parameters) { + var subtype = parameters.data.annotationType; + switch (subtype) { + case _util.AnnotationType.LINK: + return new LinkAnnotationElement(parameters); + case _util.AnnotationType.TEXT: + return new TextAnnotationElement(parameters); + case _util.AnnotationType.WIDGET: + var fieldType = parameters.data.fieldType; + switch (fieldType) { + case 'Tx': + return new TextWidgetAnnotationElement(parameters); + case 'Btn': + if (parameters.data.radioButton) { + return new RadioButtonWidgetAnnotationElement(parameters); + } else if (parameters.data.checkBox) { + return new CheckboxWidgetAnnotationElement(parameters); + } + return new PushButtonWidgetAnnotationElement(parameters); + case 'Ch': + return new ChoiceWidgetAnnotationElement(parameters); + } + return new WidgetAnnotationElement(parameters); + case _util.AnnotationType.POPUP: + return new PopupAnnotationElement(parameters); + case _util.AnnotationType.LINE: + return new LineAnnotationElement(parameters); + case _util.AnnotationType.SQUARE: + return new SquareAnnotationElement(parameters); + case _util.AnnotationType.CIRCLE: + return new CircleAnnotationElement(parameters); + case _util.AnnotationType.POLYLINE: + return new PolylineAnnotationElement(parameters); + case _util.AnnotationType.INK: + return new InkAnnotationElement(parameters); + case _util.AnnotationType.POLYGON: + return new PolygonAnnotationElement(parameters); + case _util.AnnotationType.HIGHLIGHT: + return new HighlightAnnotationElement(parameters); + case _util.AnnotationType.UNDERLINE: + return new UnderlineAnnotationElement(parameters); + case _util.AnnotationType.SQUIGGLY: + return new SquigglyAnnotationElement(parameters); + case _util.AnnotationType.STRIKEOUT: + return new StrikeOutAnnotationElement(parameters); + case _util.AnnotationType.STAMP: + return new StampAnnotationElement(parameters); + case _util.AnnotationType.FILEATTACHMENT: + return new FileAttachmentAnnotationElement(parameters); + default: + return new AnnotationElement(parameters); + } + } + }]); + + return AnnotationElementFactory; +}(); + +var AnnotationElement = function () { + function AnnotationElement(parameters) { + var isRenderable = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; + var ignoreBorder = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; + + _classCallCheck(this, AnnotationElement); + + this.isRenderable = isRenderable; + this.data = parameters.data; + this.layer = parameters.layer; + this.page = parameters.page; + this.viewport = parameters.viewport; + this.linkService = parameters.linkService; + this.downloadManager = parameters.downloadManager; + this.imageResourcesPath = parameters.imageResourcesPath; + this.renderInteractiveForms = parameters.renderInteractiveForms; + this.svgFactory = parameters.svgFactory; + if (isRenderable) { + this.container = this._createContainer(ignoreBorder); + } + } + + _createClass(AnnotationElement, [{ + key: '_createContainer', + value: function _createContainer() { + var ignoreBorder = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; + + var data = this.data, + page = this.page, + viewport = this.viewport; + var container = document.createElement('section'); + var width = data.rect[2] - data.rect[0]; + var height = data.rect[3] - data.rect[1]; + container.setAttribute('data-annotation-id', data.id); + var rect = _util.Util.normalizeRect([data.rect[0], page.view[3] - data.rect[1] + page.view[1], data.rect[2], page.view[3] - data.rect[3] + page.view[1]]); + container.style.transform = 'matrix(' + viewport.transform.join(',') + ')'; + container.style.transformOrigin = -rect[0] + 'px ' + -rect[1] + 'px'; + if (!ignoreBorder && data.borderStyle.width > 0) { + container.style.borderWidth = data.borderStyle.width + 'px'; + if (data.borderStyle.style !== _util.AnnotationBorderStyleType.UNDERLINE) { + width = width - 2 * data.borderStyle.width; + height = height - 2 * data.borderStyle.width; + } + var horizontalRadius = data.borderStyle.horizontalCornerRadius; + var verticalRadius = data.borderStyle.verticalCornerRadius; + if (horizontalRadius > 0 || verticalRadius > 0) { + var radius = horizontalRadius + 'px / ' + verticalRadius + 'px'; + container.style.borderRadius = radius; + } + switch (data.borderStyle.style) { + case _util.AnnotationBorderStyleType.SOLID: + container.style.borderStyle = 'solid'; + break; + case _util.AnnotationBorderStyleType.DASHED: + container.style.borderStyle = 'dashed'; + break; + case _util.AnnotationBorderStyleType.BEVELED: + (0, _util.warn)('Unimplemented border style: beveled'); + break; + case _util.AnnotationBorderStyleType.INSET: + (0, _util.warn)('Unimplemented border style: inset'); + break; + case _util.AnnotationBorderStyleType.UNDERLINE: + container.style.borderBottomStyle = 'solid'; + break; + default: + break; + } + if (data.color) { + container.style.borderColor = _util.Util.makeCssRgb(data.color[0] | 0, data.color[1] | 0, data.color[2] | 0); + } else { + container.style.borderWidth = 0; + } + } + container.style.left = rect[0] + 'px'; + container.style.top = rect[1] + 'px'; + container.style.width = width + 'px'; + container.style.height = height + 'px'; + return container; + } + }, { + key: '_createPopup', + value: function _createPopup(container, trigger, data) { + if (!trigger) { + trigger = document.createElement('div'); + trigger.style.height = container.style.height; + trigger.style.width = container.style.width; + container.appendChild(trigger); + } + var popupElement = new PopupElement({ + container: container, + trigger: trigger, + color: data.color, + title: data.title, + contents: data.contents, + hideWrapper: true + }); + var popup = popupElement.render(); + popup.style.left = container.style.width; + container.appendChild(popup); + } + }, { + key: 'render', + value: function render() { + (0, _util.unreachable)('Abstract method `AnnotationElement.render` called'); + } + }]); + + return AnnotationElement; +}(); + +var LinkAnnotationElement = function (_AnnotationElement) { + _inherits(LinkAnnotationElement, _AnnotationElement); + + function LinkAnnotationElement(parameters) { + _classCallCheck(this, LinkAnnotationElement); + + var isRenderable = !!(parameters.data.url || parameters.data.dest || parameters.data.action); + return _possibleConstructorReturn(this, (LinkAnnotationElement.__proto__ || Object.getPrototypeOf(LinkAnnotationElement)).call(this, parameters, isRenderable)); + } + + _createClass(LinkAnnotationElement, [{ + key: 'render', + value: function render() { + this.container.className = 'linkAnnotation'; + var data = this.data, + linkService = this.linkService; + + var link = document.createElement('a'); + (0, _dom_utils.addLinkAttributes)(link, { + url: data.url, + target: data.newWindow ? _dom_utils.LinkTarget.BLANK : linkService.externalLinkTarget, + rel: linkService.externalLinkRel + }); + if (!data.url) { + if (data.action) { + this._bindNamedAction(link, data.action); + } else { + this._bindLink(link, data.dest); + } + } + this.container.appendChild(link); + return this.container; + } + }, { + key: '_bindLink', + value: function _bindLink(link, destination) { + var _this2 = this; + + link.href = this.linkService.getDestinationHash(destination); + link.onclick = function () { + if (destination) { + _this2.linkService.navigateTo(destination); + } + return false; + }; + if (destination) { + link.className = 'internalLink'; + } + } + }, { + key: '_bindNamedAction', + value: function _bindNamedAction(link, action) { + var _this3 = this; + + link.href = this.linkService.getAnchorUrl(''); + link.onclick = function () { + _this3.linkService.executeNamedAction(action); + return false; + }; + link.className = 'internalLink'; + } + }]); + + return LinkAnnotationElement; +}(AnnotationElement); + +var TextAnnotationElement = function (_AnnotationElement2) { + _inherits(TextAnnotationElement, _AnnotationElement2); + + function TextAnnotationElement(parameters) { + _classCallCheck(this, TextAnnotationElement); + + var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents); + return _possibleConstructorReturn(this, (TextAnnotationElement.__proto__ || Object.getPrototypeOf(TextAnnotationElement)).call(this, parameters, isRenderable)); + } + + _createClass(TextAnnotationElement, [{ + key: 'render', + value: function render() { + this.container.className = 'textAnnotation'; + var image = document.createElement('img'); + image.style.height = this.container.style.height; + image.style.width = this.container.style.width; + image.src = this.imageResourcesPath + 'annotation-' + this.data.name.toLowerCase() + '.svg'; + image.alt = '[{{type}} Annotation]'; + image.dataset.l10nId = 'text_annotation_type'; + image.dataset.l10nArgs = JSON.stringify({ type: this.data.name }); + if (!this.data.hasPopup) { + this._createPopup(this.container, image, this.data); } - var paintWidth = width, - paintHeight = height; - var tmpCanvasId = 'prescale1'; - while (widthScale > 2 && paintWidth > 1 || heightScale > 2 && paintHeight > 1) { - var newWidth = paintWidth, - newHeight = paintHeight; - if (widthScale > 2 && paintWidth > 1) { - newWidth = Math.ceil(paintWidth / 2); - widthScale /= paintWidth / newWidth; + this.container.appendChild(image); + return this.container; + } + }]); + + return TextAnnotationElement; +}(AnnotationElement); + +var WidgetAnnotationElement = function (_AnnotationElement3) { + _inherits(WidgetAnnotationElement, _AnnotationElement3); + + function WidgetAnnotationElement() { + _classCallCheck(this, WidgetAnnotationElement); + + return _possibleConstructorReturn(this, (WidgetAnnotationElement.__proto__ || Object.getPrototypeOf(WidgetAnnotationElement)).apply(this, arguments)); + } + + _createClass(WidgetAnnotationElement, [{ + key: 'render', + value: function render() { + return this.container; + } + }]); + + return WidgetAnnotationElement; +}(AnnotationElement); + +var TextWidgetAnnotationElement = function (_WidgetAnnotationElem) { + _inherits(TextWidgetAnnotationElement, _WidgetAnnotationElem); + + function TextWidgetAnnotationElement(parameters) { + _classCallCheck(this, TextWidgetAnnotationElement); + + var isRenderable = parameters.renderInteractiveForms || !parameters.data.hasAppearance && !!parameters.data.fieldValue; + return _possibleConstructorReturn(this, (TextWidgetAnnotationElement.__proto__ || Object.getPrototypeOf(TextWidgetAnnotationElement)).call(this, parameters, isRenderable)); + } + + _createClass(TextWidgetAnnotationElement, [{ + key: 'render', + value: function render() { + var TEXT_ALIGNMENT = ['left', 'center', 'right']; + this.container.className = 'textWidgetAnnotation'; + var element = null; + if (this.renderInteractiveForms) { + if (this.data.multiLine) { + element = document.createElement('textarea'); + element.textContent = this.data.fieldValue; + } else { + element = document.createElement('input'); + element.type = 'text'; + element.setAttribute('value', this.data.fieldValue); } - if (heightScale > 2 && paintHeight > 1) { - newHeight = Math.ceil(paintHeight / 2); - heightScale /= paintHeight / newHeight; + element.disabled = this.data.readOnly; + if (this.data.maxLen !== null) { + element.maxLength = this.data.maxLen; } - tmpCanvas = this.cachedCanvases.getCanvas(tmpCanvasId, newWidth, newHeight); - tmpCtx = tmpCanvas.context; - tmpCtx.clearRect(0, 0, newWidth, newHeight); - tmpCtx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight, 0, 0, newWidth, newHeight); - imgToPaint = tmpCanvas.canvas; - paintWidth = newWidth; - paintHeight = newHeight; - tmpCanvasId = tmpCanvasId === 'prescale1' ? 'prescale2' : 'prescale1'; + if (this.data.comb) { + var fieldWidth = this.data.rect[2] - this.data.rect[0]; + var combWidth = fieldWidth / this.data.maxLen; + element.classList.add('comb'); + element.style.letterSpacing = 'calc(' + combWidth + 'px - 1ch)'; + } + } else { + element = document.createElement('div'); + element.textContent = this.data.fieldValue; + element.style.verticalAlign = 'middle'; + element.style.display = 'table-cell'; + var font = null; + if (this.data.fontRefName) { + font = this.page.commonObjs.getData(this.data.fontRefName); + } + this._setTextStyle(element, font); } - ctx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight, 0, -height, width, height); - if (this.imageLayer) { - var position = this.getCanvasPosition(0, -height); - this.imageLayer.appendImage({ - imgData: imgData, - left: position[0], - top: position[1], - width: width / currentTransform[0], - height: height / currentTransform[3] - }); + if (this.data.textAlignment !== null) { + element.style.textAlign = TEXT_ALIGNMENT[this.data.textAlignment]; } - this.restore(); - }, - paintInlineImageXObjectGroup: function CanvasGraphics_paintInlineImageXObjectGroup(imgData, map) { - var ctx = this.ctx; - var w = imgData.width; - var h = imgData.height; - var tmpCanvas = this.cachedCanvases.getCanvas('inlineImage', w, h); - var tmpCtx = tmpCanvas.context; - putBinaryImageData(tmpCtx, imgData); - for (var i = 0, ii = map.length; i < ii; i++) { - var entry = map[i]; - ctx.save(); - ctx.transform.apply(ctx, entry.transform); - ctx.scale(1, -1); - ctx.drawImage(tmpCanvas.canvas, entry.x, entry.y, entry.w, entry.h, 0, -1, 1, 1); - if (this.imageLayer) { - var position = this.getCanvasPosition(entry.x, entry.y); - this.imageLayer.appendImage({ - imgData: imgData, - left: position[0], - top: position[1], - width: w, - height: h - }); - } - ctx.restore(); + this.container.appendChild(element); + return this.container; + } + }, { + key: '_setTextStyle', + value: function _setTextStyle(element, font) { + var style = element.style; + style.fontSize = this.data.fontSize + 'px'; + style.direction = this.data.fontDirection < 0 ? 'rtl' : 'ltr'; + if (!font) { + return; } - }, - paintSolidColorImageMask: function CanvasGraphics_paintSolidColorImageMask() { - this.ctx.fillRect(0, 0, 1, 1); - }, - paintXObject: function CanvasGraphics_paintXObject() { - warn('Unsupported \'paintXObject\' command.'); - }, - markPoint: function CanvasGraphics_markPoint(tag) {}, - markPointProps: function CanvasGraphics_markPointProps(tag, properties) {}, - beginMarkedContent: function CanvasGraphics_beginMarkedContent(tag) {}, - beginMarkedContentProps: function CanvasGraphics_beginMarkedContentProps(tag, properties) {}, - endMarkedContent: function CanvasGraphics_endMarkedContent() {}, - beginCompat: function CanvasGraphics_beginCompat() {}, - endCompat: function CanvasGraphics_endCompat() {}, - consumePath: function CanvasGraphics_consumePath() { - var ctx = this.ctx; - if (this.pendingClip) { - if (this.pendingClip === EO_CLIP) { - ctx.clip('evenodd'); - } else { - ctx.clip(); - } - this.pendingClip = null; + style.fontWeight = font.black ? font.bold ? '900' : 'bold' : font.bold ? 'bold' : 'normal'; + style.fontStyle = font.italic ? 'italic' : 'normal'; + var fontFamily = font.loadedName ? '"' + font.loadedName + '", ' : ''; + var fallbackName = font.fallbackName || 'Helvetica, sans-serif'; + style.fontFamily = fontFamily + fallbackName; + } + }]); + + return TextWidgetAnnotationElement; +}(WidgetAnnotationElement); + +var CheckboxWidgetAnnotationElement = function (_WidgetAnnotationElem2) { + _inherits(CheckboxWidgetAnnotationElement, _WidgetAnnotationElem2); + + function CheckboxWidgetAnnotationElement(parameters) { + _classCallCheck(this, CheckboxWidgetAnnotationElement); + + return _possibleConstructorReturn(this, (CheckboxWidgetAnnotationElement.__proto__ || Object.getPrototypeOf(CheckboxWidgetAnnotationElement)).call(this, parameters, parameters.renderInteractiveForms)); + } + + _createClass(CheckboxWidgetAnnotationElement, [{ + key: 'render', + value: function render() { + this.container.className = 'buttonWidgetAnnotation checkBox'; + var element = document.createElement('input'); + element.disabled = this.data.readOnly; + element.type = 'checkbox'; + if (this.data.fieldValue && this.data.fieldValue !== 'Off') { + element.setAttribute('checked', true); } - ctx.beginPath(); - }, - getSinglePixelWidth: function CanvasGraphics_getSinglePixelWidth(scale) { - if (this.cachedGetSinglePixelWidth === null) { - this.ctx.save(); - var inverse = this.ctx.mozCurrentTransformInverse; - this.ctx.restore(); - this.cachedGetSinglePixelWidth = Math.sqrt(Math.max(inverse[0] * inverse[0] + inverse[1] * inverse[1], inverse[2] * inverse[2] + inverse[3] * inverse[3])); + this.container.appendChild(element); + return this.container; + } + }]); + + return CheckboxWidgetAnnotationElement; +}(WidgetAnnotationElement); + +var RadioButtonWidgetAnnotationElement = function (_WidgetAnnotationElem3) { + _inherits(RadioButtonWidgetAnnotationElement, _WidgetAnnotationElem3); + + function RadioButtonWidgetAnnotationElement(parameters) { + _classCallCheck(this, RadioButtonWidgetAnnotationElement); + + return _possibleConstructorReturn(this, (RadioButtonWidgetAnnotationElement.__proto__ || Object.getPrototypeOf(RadioButtonWidgetAnnotationElement)).call(this, parameters, parameters.renderInteractiveForms)); + } + + _createClass(RadioButtonWidgetAnnotationElement, [{ + key: 'render', + value: function render() { + this.container.className = 'buttonWidgetAnnotation radioButton'; + var element = document.createElement('input'); + element.disabled = this.data.readOnly; + element.type = 'radio'; + element.name = this.data.fieldName; + if (this.data.fieldValue === this.data.buttonValue) { + element.setAttribute('checked', true); } - return this.cachedGetSinglePixelWidth; - }, - getCanvasPosition: function CanvasGraphics_getCanvasPosition(x, y) { - var transform = this.ctx.mozCurrentTransform; - return [transform[0] * x + transform[2] * y + transform[4], transform[1] * x + transform[3] * y + transform[5]]; + this.container.appendChild(element); + return this.container; } - }; - for (var op in OPS) { - CanvasGraphics.prototype[OPS[op]] = CanvasGraphics.prototype[op]; + }]); + + return RadioButtonWidgetAnnotationElement; +}(WidgetAnnotationElement); + +var PushButtonWidgetAnnotationElement = function (_LinkAnnotationElemen) { + _inherits(PushButtonWidgetAnnotationElement, _LinkAnnotationElemen); + + function PushButtonWidgetAnnotationElement() { + _classCallCheck(this, PushButtonWidgetAnnotationElement); + + return _possibleConstructorReturn(this, (PushButtonWidgetAnnotationElement.__proto__ || Object.getPrototypeOf(PushButtonWidgetAnnotationElement)).apply(this, arguments)); } - return CanvasGraphics; -}(); -exports.CanvasGraphics = CanvasGraphics; -/***/ }), -/* 11 */ -/***/ (function(module, exports, __w_pdfjs_require__) { + _createClass(PushButtonWidgetAnnotationElement, [{ + key: 'render', + value: function render() { + var container = _get(PushButtonWidgetAnnotationElement.prototype.__proto__ || Object.getPrototypeOf(PushButtonWidgetAnnotationElement.prototype), 'render', this).call(this); + container.className = 'buttonWidgetAnnotation pushButton'; + return container; + } + }]); + + return PushButtonWidgetAnnotationElement; +}(LinkAnnotationElement); + +var ChoiceWidgetAnnotationElement = function (_WidgetAnnotationElem4) { + _inherits(ChoiceWidgetAnnotationElement, _WidgetAnnotationElem4); + + function ChoiceWidgetAnnotationElement(parameters) { + _classCallCheck(this, ChoiceWidgetAnnotationElement); + + return _possibleConstructorReturn(this, (ChoiceWidgetAnnotationElement.__proto__ || Object.getPrototypeOf(ChoiceWidgetAnnotationElement)).call(this, parameters, parameters.renderInteractiveForms)); + } + + _createClass(ChoiceWidgetAnnotationElement, [{ + key: 'render', + value: function render() { + this.container.className = 'choiceWidgetAnnotation'; + var selectElement = document.createElement('select'); + selectElement.disabled = this.data.readOnly; + if (!this.data.combo) { + selectElement.size = this.data.options.length; + if (this.data.multiSelect) { + selectElement.multiple = true; + } + } + for (var i = 0, ii = this.data.options.length; i < ii; i++) { + var option = this.data.options[i]; + var optionElement = document.createElement('option'); + optionElement.textContent = option.displayValue; + optionElement.value = option.exportValue; + if (this.data.fieldValue.includes(option.displayValue)) { + optionElement.setAttribute('selected', true); + } + selectElement.appendChild(optionElement); + } + this.container.appendChild(selectElement); + return this.container; + } + }]); -"use strict"; + return ChoiceWidgetAnnotationElement; +}(WidgetAnnotationElement); +var PopupAnnotationElement = function (_AnnotationElement4) { + _inherits(PopupAnnotationElement, _AnnotationElement4); -var sharedUtil = __w_pdfjs_require__(0); -var assert = sharedUtil.assert; -var bytesToString = sharedUtil.bytesToString; -var string32 = sharedUtil.string32; -var shadow = sharedUtil.shadow; -var warn = sharedUtil.warn; -function FontLoader(docId) { - this.docId = docId; - this.styleElement = null; - this.nativeFontFaces = []; - this.loadTestFontId = 0; - this.loadingContext = { - requests: [], - nextRequestId: 0 - }; -} -FontLoader.prototype = { - insertRule: function fontLoaderInsertRule(rule) { - var styleElement = this.styleElement; - if (!styleElement) { - styleElement = this.styleElement = document.createElement('style'); - styleElement.id = 'PDFJS_FONT_STYLE_TAG_' + this.docId; - document.documentElement.getElementsByTagName('head')[0].appendChild(styleElement); - } - var styleSheet = styleElement.sheet; - styleSheet.insertRule(rule, styleSheet.cssRules.length); - }, - clear: function fontLoaderClear() { - if (this.styleElement) { - this.styleElement.remove(); - this.styleElement = null; - } - this.nativeFontFaces.forEach(function (nativeFontFace) { - document.fonts.delete(nativeFontFace); - }); - this.nativeFontFaces.length = 0; + function PopupAnnotationElement(parameters) { + _classCallCheck(this, PopupAnnotationElement); + + var isRenderable = !!(parameters.data.title || parameters.data.contents); + return _possibleConstructorReturn(this, (PopupAnnotationElement.__proto__ || Object.getPrototypeOf(PopupAnnotationElement)).call(this, parameters, isRenderable)); } -}; -var getLoadTestFont = function () { - return atob('T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQAFQ' + 'AABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAAALwA' + 'AAA2aGhlYQdkA+oAAAD0AAAAJGhtdHgD6AAAAAAEWAAAAAZtYXhwAAJQAAAAARgAAAAGbm' + 'FtZVjmdH4AAAGAAAAAsXBvc3T/hgAzAAADeAAAACAAAQAAAAEAALZRFsRfDzz1AAsD6AAA' + 'AADOBOTLAAAAAM4KHDwAAAAAA+gDIQAAAAgAAgAAAAAAAAABAAADIQAAAFoD6AAAAAAD6A' + 'ABAAAAAAAAAAAAAAAAAAAAAQAAUAAAAgAAAAQD6AH0AAUAAAKKArwAAACMAooCvAAAAeAA' + 'MQECAAACAAYJAAAAAAAAAAAAAQAAAAAAAAAAAAAAAFBmRWQAwAAuAC4DIP84AFoDIQAAAA' + 'AAAQAAAAAAAAAAACAAIAABAAAADgCuAAEAAAAAAAAAAQAAAAEAAAAAAAEAAQAAAAEAAAAA' + 'AAIAAQAAAAEAAAAAAAMAAQAAAAEAAAAAAAQAAQAAAAEAAAAAAAUAAQAAAAEAAAAAAAYAAQ' + 'AAAAMAAQQJAAAAAgABAAMAAQQJAAEAAgABAAMAAQQJAAIAAgABAAMAAQQJAAMAAgABAAMA' + 'AQQJAAQAAgABAAMAAQQJAAUAAgABAAMAAQQJAAYAAgABWABYAAAAAAAAAwAAAAMAAAAcAA' + 'EAAAAAADwAAwABAAAAHAAEACAAAAAEAAQAAQAAAC7//wAAAC7////TAAEAAAAAAAABBgAA' + 'AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAA' + 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' + 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' + 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' + 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAA' + 'AAAAD/gwAyAAAAAQAAAAAAAAAAAAAAAAAAAAABAAQEAAEBAQJYAAEBASH4DwD4GwHEAvgc' + 'A/gXBIwMAYuL+nz5tQXkD5j3CBLnEQACAQEBIVhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWF' + 'hYWFhYWFhYAAABAQAADwACAQEEE/t3Dov6fAH6fAT+fPp8+nwHDosMCvm1Cvm1DAz6fBQA' + 'AAAAAAABAAAAAMmJbzEAAAAAzgTjFQAAAADOBOQpAAEAAAAAAAAADAAUAAQAAAABAAAAAg' + 'ABAAAAAAAAAAAD6AAAAAAAAA=='); -}; -Object.defineProperty(FontLoader.prototype, 'loadTestFont', { - get: function () { - return shadow(this, 'loadTestFont', getLoadTestFont()); - }, - configurable: true -}); -FontLoader.prototype.addNativeFontFace = function fontLoader_addNativeFontFace(nativeFontFace) { - this.nativeFontFaces.push(nativeFontFace); - document.fonts.add(nativeFontFace); -}; -FontLoader.prototype.bind = function fontLoaderBind(fonts, callback) { - var rules = []; - var fontsToLoad = []; - var fontLoadPromises = []; - var getNativeFontPromise = function (nativeFontFace) { - return nativeFontFace.loaded.catch(function (e) { - warn('Failed to load font "' + nativeFontFace.family + '": ' + e); - }); - }; - var isFontLoadingAPISupported = FontLoader.isFontLoadingAPISupported && !FontLoader.isSyncFontLoadingSupported; - for (var i = 0, ii = fonts.length; i < ii; i++) { - var font = fonts[i]; - if (font.attached || font.loading === false) { - continue; - } - font.attached = true; - if (isFontLoadingAPISupported) { - var nativeFontFace = font.createNativeFontFace(); - if (nativeFontFace) { - this.addNativeFontFace(nativeFontFace); - fontLoadPromises.push(getNativeFontPromise(nativeFontFace)); + + _createClass(PopupAnnotationElement, [{ + key: 'render', + value: function render() { + var IGNORE_TYPES = ['Line', 'Square', 'Circle', 'PolyLine', 'Polygon', 'Ink']; + this.container.className = 'popupAnnotation'; + if (IGNORE_TYPES.includes(this.data.parentType)) { + return this.container; } - } else { - var rule = font.createFontFaceRule(); - if (rule) { - this.insertRule(rule); - rules.push(rule); - fontsToLoad.push(font); + var selector = '[data-annotation-id="' + this.data.parentId + '"]'; + var parentElement = this.layer.querySelector(selector); + if (!parentElement) { + return this.container; } + var popup = new PopupElement({ + container: this.container, + trigger: parentElement, + color: this.data.color, + title: this.data.title, + contents: this.data.contents + }); + var parentLeft = parseFloat(parentElement.style.left); + var parentWidth = parseFloat(parentElement.style.width); + this.container.style.transformOrigin = -(parentLeft + parentWidth) + 'px -' + parentElement.style.top; + this.container.style.left = parentLeft + parentWidth + 'px'; + this.container.appendChild(popup.render()); + return this.container; } + }]); + + return PopupAnnotationElement; +}(AnnotationElement); + +var PopupElement = function () { + function PopupElement(parameters) { + _classCallCheck(this, PopupElement); + + this.container = parameters.container; + this.trigger = parameters.trigger; + this.color = parameters.color; + this.title = parameters.title; + this.contents = parameters.contents; + this.hideWrapper = parameters.hideWrapper || false; + this.pinned = false; } - var request = this.queueLoadingCallback(callback); - if (isFontLoadingAPISupported) { - Promise.all(fontLoadPromises).then(function () { - request.complete(); - }); - } else if (rules.length > 0 && !FontLoader.isSyncFontLoadingSupported) { - this.prepareFontLoadEvent(rules, fontsToLoad, request); - } else { - request.complete(); - } -}; -FontLoader.prototype.queueLoadingCallback = function FontLoader_queueLoadingCallback(callback) { - function LoadLoader_completeRequest() { - assert(!request.end, 'completeRequest() cannot be called twice'); - request.end = Date.now(); - while (context.requests.length > 0 && context.requests[0].end) { - var otherRequest = context.requests.shift(); - setTimeout(otherRequest.callback, 0); - } - } - var context = this.loadingContext; - var requestId = 'pdfjs-font-loading-' + context.nextRequestId++; - var request = { - id: requestId, - complete: LoadLoader_completeRequest, - callback: callback, - started: Date.now() - }; - context.requests.push(request); - return request; -}; -FontLoader.prototype.prepareFontLoadEvent = function fontLoaderPrepareFontLoadEvent(rules, fonts, request) { - function int32(data, offset) { - return data.charCodeAt(offset) << 24 | data.charCodeAt(offset + 1) << 16 | data.charCodeAt(offset + 2) << 8 | data.charCodeAt(offset + 3) & 0xff; - } - function spliceString(s, offset, remove, insert) { - var chunk1 = s.substr(0, offset); - var chunk2 = s.substr(offset + remove); - return chunk1 + insert + chunk2; - } - var i, ii; - var canvas = document.createElement('canvas'); - canvas.width = 1; - canvas.height = 1; - var ctx = canvas.getContext('2d'); - var called = 0; - function isFontReady(name, callback) { - called++; - if (called > 30) { - warn('Load test font never loaded.'); - callback(); - return; - } - ctx.font = '30px ' + name; - ctx.fillText('.', 0, 20); - var imageData = ctx.getImageData(0, 0, 1, 1); - if (imageData.data[3] > 0) { - callback(); - return; - } - setTimeout(isFontReady.bind(null, name, callback)); - } - var loadTestFontId = 'lt' + Date.now() + this.loadTestFontId++; - var data = this.loadTestFont; - var COMMENT_OFFSET = 976; - data = spliceString(data, COMMENT_OFFSET, loadTestFontId.length, loadTestFontId); - var CFF_CHECKSUM_OFFSET = 16; - var XXXX_VALUE = 0x58585858; - var checksum = int32(data, CFF_CHECKSUM_OFFSET); - for (i = 0, ii = loadTestFontId.length - 3; i < ii; i += 4) { - checksum = checksum - XXXX_VALUE + int32(loadTestFontId, i) | 0; - } - if (i < loadTestFontId.length) { - checksum = checksum - XXXX_VALUE + int32(loadTestFontId + 'XXX', i) | 0; - } - data = spliceString(data, CFF_CHECKSUM_OFFSET, 4, string32(checksum)); - var url = 'url(data:font/opentype;base64,' + btoa(data) + ');'; - var rule = '@font-face { font-family:"' + loadTestFontId + '";src:' + url + '}'; - this.insertRule(rule); - var names = []; - for (i = 0, ii = fonts.length; i < ii; i++) { - names.push(fonts[i].loadedName); - } - names.push(loadTestFontId); - var div = document.createElement('div'); - div.setAttribute('style', 'visibility: hidden;' + 'width: 10px; height: 10px;' + 'position: absolute; top: 0px; left: 0px;'); - for (i = 0, ii = names.length; i < ii; ++i) { - var span = document.createElement('span'); - span.textContent = 'Hi'; - span.style.fontFamily = names[i]; - div.appendChild(span); - } - document.body.appendChild(div); - isFontReady(loadTestFontId, function () { - document.body.removeChild(div); - request.complete(); - }); -}; -FontLoader.isFontLoadingAPISupported = typeof document !== 'undefined' && !!document.fonts; -var isSyncFontLoadingSupported = function isSyncFontLoadingSupported() { - if (typeof navigator === 'undefined') { - return true; - } - var supported = false; - var m = /Mozilla\/5.0.*?rv:(\d+).*? Gecko/.exec(navigator.userAgent); - if (m && m[1] >= 14) { - supported = true; - } - return supported; -}; -Object.defineProperty(FontLoader, 'isSyncFontLoadingSupported', { - get: function () { - return shadow(FontLoader, 'isSyncFontLoadingSupported', isSyncFontLoadingSupported()); - }, - enumerable: true, - configurable: true -}); -var IsEvalSupportedCached = { - get value() { - return shadow(this, 'value', sharedUtil.isEvalSupported()); - } -}; -var FontFaceObject = function FontFaceObjectClosure() { - function FontFaceObject(translatedData, options) { - this.compiledGlyphs = Object.create(null); - for (var i in translatedData) { - this[i] = translatedData[i]; - } - this.options = options; - } - FontFaceObject.prototype = { - createNativeFontFace: function FontFaceObject_createNativeFontFace() { - if (!this.data) { - return null; + + _createClass(PopupElement, [{ + key: 'render', + value: function render() { + var BACKGROUND_ENLIGHT = 0.7; + var wrapper = document.createElement('div'); + wrapper.className = 'popupWrapper'; + this.hideElement = this.hideWrapper ? wrapper : this.container; + this.hideElement.setAttribute('hidden', true); + var popup = document.createElement('div'); + popup.className = 'popup'; + var color = this.color; + if (color) { + var r = BACKGROUND_ENLIGHT * (255 - color[0]) + color[0]; + var g = BACKGROUND_ENLIGHT * (255 - color[1]) + color[1]; + var b = BACKGROUND_ENLIGHT * (255 - color[2]) + color[2]; + popup.style.backgroundColor = _util.Util.makeCssRgb(r | 0, g | 0, b | 0); } - if (this.options.disableFontFace) { - this.disableFontFace = true; - return null; + var contents = this._formatContents(this.contents); + var title = document.createElement('h1'); + title.textContent = this.title; + this.trigger.addEventListener('click', this._toggle.bind(this)); + this.trigger.addEventListener('mouseover', this._show.bind(this, false)); + this.trigger.addEventListener('mouseout', this._hide.bind(this, false)); + popup.addEventListener('click', this._hide.bind(this, true)); + popup.appendChild(title); + popup.appendChild(contents); + wrapper.appendChild(popup); + return wrapper; + } + }, { + key: '_formatContents', + value: function _formatContents(contents) { + var p = document.createElement('p'); + var lines = contents.split(/(?:\r\n?|\n)/); + for (var i = 0, ii = lines.length; i < ii; ++i) { + var line = lines[i]; + p.appendChild(document.createTextNode(line)); + if (i < ii - 1) { + p.appendChild(document.createElement('br')); + } } - var nativeFontFace = new FontFace(this.loadedName, this.data, {}); - if (this.options.fontRegistry) { - this.options.fontRegistry.registerFont(this); + return p; + } + }, { + key: '_toggle', + value: function _toggle() { + if (this.pinned) { + this._hide(true); + } else { + this._show(true); } - return nativeFontFace; - }, - createFontFaceRule: function FontFaceObject_createFontFaceRule() { - if (!this.data) { - return null; + } + }, { + key: '_show', + value: function _show() { + var pin = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; + + if (pin) { + this.pinned = true; } - if (this.options.disableFontFace) { - this.disableFontFace = true; - return null; + if (this.hideElement.hasAttribute('hidden')) { + this.hideElement.removeAttribute('hidden'); + this.container.style.zIndex += 1; } - var data = bytesToString(new Uint8Array(this.data)); - var fontName = this.loadedName; - var url = 'url(data:' + this.mimetype + ';base64,' + btoa(data) + ');'; - var rule = '@font-face { font-family:"' + fontName + '";src:' + url + '}'; - if (this.options.fontRegistry) { - this.options.fontRegistry.registerFont(this, url); + } + }, { + key: '_hide', + value: function _hide() { + var unpin = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true; + + if (unpin) { + this.pinned = false; } - return rule; - }, - getPathGenerator: function FontFaceObject_getPathGenerator(objs, character) { - if (!(character in this.compiledGlyphs)) { - var cmds = objs.get(this.loadedName + '_path_' + character); - var current, i, len; - if (this.options.isEvalSupported && IsEvalSupportedCached.value) { - var args, - js = ''; - for (i = 0, len = cmds.length; i < len; i++) { - current = cmds[i]; - if (current.args !== undefined) { - args = current.args.join(','); - } else { - args = ''; - } - js += 'c.' + current.cmd + '(' + args + ');\n'; - } - this.compiledGlyphs[character] = new Function('c', 'size', js); - } else { - this.compiledGlyphs[character] = function (c, size) { - for (i = 0, len = cmds.length; i < len; i++) { - current = cmds[i]; - if (current.cmd === 'scale') { - current.args = [size, -size]; - } - c[current.cmd].apply(c, current.args); - } - }; - } + if (!this.hideElement.hasAttribute('hidden') && !this.pinned) { + this.hideElement.setAttribute('hidden', true); + this.container.style.zIndex -= 1; } - return this.compiledGlyphs[character]; } - }; - return FontFaceObject; -}(); -exports.FontFaceObject = FontFaceObject; -exports.FontLoader = FontLoader; + }]); -/***/ }), -/* 12 */ -/***/ (function(module, exports, __w_pdfjs_require__) { + return PopupElement; +}(); -"use strict"; +var LineAnnotationElement = function (_AnnotationElement5) { + _inherits(LineAnnotationElement, _AnnotationElement5); + function LineAnnotationElement(parameters) { + _classCallCheck(this, LineAnnotationElement); -var sharedUtil = __w_pdfjs_require__(0); -var displayWebGL = __w_pdfjs_require__(8); -var Util = sharedUtil.Util; -var info = sharedUtil.info; -var isArray = sharedUtil.isArray; -var error = sharedUtil.error; -var WebGLUtils = displayWebGL.WebGLUtils; -var ShadingIRs = {}; -ShadingIRs.RadialAxial = { - fromIR: function RadialAxial_fromIR(raw) { - var type = raw[1]; - var colorStops = raw[2]; - var p0 = raw[3]; - var p1 = raw[4]; - var r0 = raw[5]; - var r1 = raw[6]; - return { - type: 'Pattern', - getPattern: function RadialAxial_getPattern(ctx) { - var grad; - if (type === 'axial') { - grad = ctx.createLinearGradient(p0[0], p0[1], p1[0], p1[1]); - } else if (type === 'radial') { - grad = ctx.createRadialGradient(p0[0], p0[1], r0, p1[0], p1[1], r1); - } - for (var i = 0, ii = colorStops.length; i < ii; ++i) { - var c = colorStops[i]; - grad.addColorStop(c[0], c[1]); - } - return grad; - } - }; + var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents); + return _possibleConstructorReturn(this, (LineAnnotationElement.__proto__ || Object.getPrototypeOf(LineAnnotationElement)).call(this, parameters, isRenderable, true)); } -}; -var createMeshCanvas = function createMeshCanvasClosure() { - function drawTriangle(data, context, p1, p2, p3, c1, c2, c3) { - var coords = context.coords, - colors = context.colors; - var bytes = data.data, - rowSize = data.width * 4; - var tmp; - if (coords[p1 + 1] > coords[p2 + 1]) { - tmp = p1; - p1 = p2; - p2 = tmp; - tmp = c1; - c1 = c2; - c2 = tmp; + + _createClass(LineAnnotationElement, [{ + key: 'render', + value: function render() { + this.container.className = 'lineAnnotation'; + var data = this.data; + var width = data.rect[2] - data.rect[0]; + var height = data.rect[3] - data.rect[1]; + var svg = this.svgFactory.create(width, height); + var line = this.svgFactory.createElement('svg:line'); + line.setAttribute('x1', data.rect[2] - data.lineCoordinates[0]); + line.setAttribute('y1', data.rect[3] - data.lineCoordinates[1]); + line.setAttribute('x2', data.rect[2] - data.lineCoordinates[2]); + line.setAttribute('y2', data.rect[3] - data.lineCoordinates[3]); + line.setAttribute('stroke-width', data.borderStyle.width); + line.setAttribute('stroke', 'transparent'); + svg.appendChild(line); + this.container.append(svg); + this._createPopup(this.container, line, data); + return this.container; } - if (coords[p2 + 1] > coords[p3 + 1]) { - tmp = p2; - p2 = p3; - p3 = tmp; - tmp = c2; - c2 = c3; - c3 = tmp; + }]); + + return LineAnnotationElement; +}(AnnotationElement); + +var SquareAnnotationElement = function (_AnnotationElement6) { + _inherits(SquareAnnotationElement, _AnnotationElement6); + + function SquareAnnotationElement(parameters) { + _classCallCheck(this, SquareAnnotationElement); + + var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents); + return _possibleConstructorReturn(this, (SquareAnnotationElement.__proto__ || Object.getPrototypeOf(SquareAnnotationElement)).call(this, parameters, isRenderable, true)); + } + + _createClass(SquareAnnotationElement, [{ + key: 'render', + value: function render() { + this.container.className = 'squareAnnotation'; + var data = this.data; + var width = data.rect[2] - data.rect[0]; + var height = data.rect[3] - data.rect[1]; + var svg = this.svgFactory.create(width, height); + var borderWidth = data.borderStyle.width; + var square = this.svgFactory.createElement('svg:rect'); + square.setAttribute('x', borderWidth / 2); + square.setAttribute('y', borderWidth / 2); + square.setAttribute('width', width - borderWidth); + square.setAttribute('height', height - borderWidth); + square.setAttribute('stroke-width', borderWidth); + square.setAttribute('stroke', 'transparent'); + square.setAttribute('fill', 'none'); + svg.appendChild(square); + this.container.append(svg); + this._createPopup(this.container, square, data); + return this.container; } - if (coords[p1 + 1] > coords[p2 + 1]) { - tmp = p1; - p1 = p2; - p2 = tmp; - tmp = c1; - c1 = c2; - c2 = tmp; + }]); + + return SquareAnnotationElement; +}(AnnotationElement); + +var CircleAnnotationElement = function (_AnnotationElement7) { + _inherits(CircleAnnotationElement, _AnnotationElement7); + + function CircleAnnotationElement(parameters) { + _classCallCheck(this, CircleAnnotationElement); + + var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents); + return _possibleConstructorReturn(this, (CircleAnnotationElement.__proto__ || Object.getPrototypeOf(CircleAnnotationElement)).call(this, parameters, isRenderable, true)); + } + + _createClass(CircleAnnotationElement, [{ + key: 'render', + value: function render() { + this.container.className = 'circleAnnotation'; + var data = this.data; + var width = data.rect[2] - data.rect[0]; + var height = data.rect[3] - data.rect[1]; + var svg = this.svgFactory.create(width, height); + var borderWidth = data.borderStyle.width; + var circle = this.svgFactory.createElement('svg:ellipse'); + circle.setAttribute('cx', width / 2); + circle.setAttribute('cy', height / 2); + circle.setAttribute('rx', width / 2 - borderWidth / 2); + circle.setAttribute('ry', height / 2 - borderWidth / 2); + circle.setAttribute('stroke-width', borderWidth); + circle.setAttribute('stroke', 'transparent'); + circle.setAttribute('fill', 'none'); + svg.appendChild(circle); + this.container.append(svg); + this._createPopup(this.container, circle, data); + return this.container; } - var x1 = (coords[p1] + context.offsetX) * context.scaleX; - var y1 = (coords[p1 + 1] + context.offsetY) * context.scaleY; - var x2 = (coords[p2] + context.offsetX) * context.scaleX; - var y2 = (coords[p2 + 1] + context.offsetY) * context.scaleY; - var x3 = (coords[p3] + context.offsetX) * context.scaleX; - var y3 = (coords[p3 + 1] + context.offsetY) * context.scaleY; - if (y1 >= y3) { - return; + }]); + + return CircleAnnotationElement; +}(AnnotationElement); + +var PolylineAnnotationElement = function (_AnnotationElement8) { + _inherits(PolylineAnnotationElement, _AnnotationElement8); + + function PolylineAnnotationElement(parameters) { + _classCallCheck(this, PolylineAnnotationElement); + + var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents); + + var _this15 = _possibleConstructorReturn(this, (PolylineAnnotationElement.__proto__ || Object.getPrototypeOf(PolylineAnnotationElement)).call(this, parameters, isRenderable, true)); + + _this15.containerClassName = 'polylineAnnotation'; + _this15.svgElementName = 'svg:polyline'; + return _this15; + } + + _createClass(PolylineAnnotationElement, [{ + key: 'render', + value: function render() { + this.container.className = this.containerClassName; + var data = this.data; + var width = data.rect[2] - data.rect[0]; + var height = data.rect[3] - data.rect[1]; + var svg = this.svgFactory.create(width, height); + var vertices = data.vertices; + var points = []; + for (var i = 0, ii = vertices.length; i < ii; i++) { + var x = vertices[i].x - data.rect[0]; + var y = data.rect[3] - vertices[i].y; + points.push(x + ',' + y); + } + points = points.join(' '); + var borderWidth = data.borderStyle.width; + var polyline = this.svgFactory.createElement(this.svgElementName); + polyline.setAttribute('points', points); + polyline.setAttribute('stroke-width', borderWidth); + polyline.setAttribute('stroke', 'transparent'); + polyline.setAttribute('fill', 'none'); + svg.appendChild(polyline); + this.container.append(svg); + this._createPopup(this.container, polyline, data); + return this.container; } - var c1r = colors[c1], - c1g = colors[c1 + 1], - c1b = colors[c1 + 2]; - var c2r = colors[c2], - c2g = colors[c2 + 1], - c2b = colors[c2 + 2]; - var c3r = colors[c3], - c3g = colors[c3 + 1], - c3b = colors[c3 + 2]; - var minY = Math.round(y1), - maxY = Math.round(y3); - var xa, car, cag, cab; - var xb, cbr, cbg, cbb; - var k; - for (var y = minY; y <= maxY; y++) { - if (y < y2) { - k = y < y1 ? 0 : y1 === y2 ? 1 : (y1 - y) / (y1 - y2); - xa = x1 - (x1 - x2) * k; - car = c1r - (c1r - c2r) * k; - cag = c1g - (c1g - c2g) * k; - cab = c1b - (c1b - c2b) * k; - } else { - k = y > y3 ? 1 : y2 === y3 ? 0 : (y2 - y) / (y2 - y3); - xa = x2 - (x2 - x3) * k; - car = c2r - (c2r - c3r) * k; - cag = c2g - (c2g - c3g) * k; - cab = c2b - (c2b - c3b) * k; - } - k = y < y1 ? 0 : y > y3 ? 1 : (y1 - y) / (y1 - y3); - xb = x1 - (x1 - x3) * k; - cbr = c1r - (c1r - c3r) * k; - cbg = c1g - (c1g - c3g) * k; - cbb = c1b - (c1b - c3b) * k; - var x1_ = Math.round(Math.min(xa, xb)); - var x2_ = Math.round(Math.max(xa, xb)); - var j = rowSize * y + x1_ * 4; - for (var x = x1_; x <= x2_; x++) { - k = (xa - x) / (xa - xb); - k = k < 0 ? 0 : k > 1 ? 1 : k; - bytes[j++] = car - (car - cbr) * k | 0; - bytes[j++] = cag - (cag - cbg) * k | 0; - bytes[j++] = cab - (cab - cbb) * k | 0; - bytes[j++] = 255; + }]); + + return PolylineAnnotationElement; +}(AnnotationElement); + +var PolygonAnnotationElement = function (_PolylineAnnotationEl) { + _inherits(PolygonAnnotationElement, _PolylineAnnotationEl); + + function PolygonAnnotationElement(parameters) { + _classCallCheck(this, PolygonAnnotationElement); + + var _this16 = _possibleConstructorReturn(this, (PolygonAnnotationElement.__proto__ || Object.getPrototypeOf(PolygonAnnotationElement)).call(this, parameters)); + + _this16.containerClassName = 'polygonAnnotation'; + _this16.svgElementName = 'svg:polygon'; + return _this16; + } + + return PolygonAnnotationElement; +}(PolylineAnnotationElement); + +var InkAnnotationElement = function (_AnnotationElement9) { + _inherits(InkAnnotationElement, _AnnotationElement9); + + function InkAnnotationElement(parameters) { + _classCallCheck(this, InkAnnotationElement); + + var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents); + + var _this17 = _possibleConstructorReturn(this, (InkAnnotationElement.__proto__ || Object.getPrototypeOf(InkAnnotationElement)).call(this, parameters, isRenderable, true)); + + _this17.containerClassName = 'inkAnnotation'; + _this17.svgElementName = 'svg:polyline'; + return _this17; + } + + _createClass(InkAnnotationElement, [{ + key: 'render', + value: function render() { + this.container.className = this.containerClassName; + var data = this.data; + var width = data.rect[2] - data.rect[0]; + var height = data.rect[3] - data.rect[1]; + var svg = this.svgFactory.create(width, height); + var inkLists = data.inkLists; + for (var i = 0, ii = inkLists.length; i < ii; i++) { + var inkList = inkLists[i]; + var points = []; + for (var j = 0, jj = inkList.length; j < jj; j++) { + var x = inkList[j].x - data.rect[0]; + var y = data.rect[3] - inkList[j].y; + points.push(x + ',' + y); + } + points = points.join(' '); + var borderWidth = data.borderStyle.width; + var polyline = this.svgFactory.createElement(this.svgElementName); + polyline.setAttribute('points', points); + polyline.setAttribute('stroke-width', borderWidth); + polyline.setAttribute('stroke', 'transparent'); + polyline.setAttribute('fill', 'none'); + this._createPopup(this.container, polyline, data); + svg.appendChild(polyline); + } + this.container.append(svg); + return this.container; + } + }]); + + return InkAnnotationElement; +}(AnnotationElement); + +var HighlightAnnotationElement = function (_AnnotationElement10) { + _inherits(HighlightAnnotationElement, _AnnotationElement10); + + function HighlightAnnotationElement(parameters) { + _classCallCheck(this, HighlightAnnotationElement); + + var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents); + return _possibleConstructorReturn(this, (HighlightAnnotationElement.__proto__ || Object.getPrototypeOf(HighlightAnnotationElement)).call(this, parameters, isRenderable, true)); + } + + _createClass(HighlightAnnotationElement, [{ + key: 'render', + value: function render() { + this.container.className = 'highlightAnnotation'; + if (!this.data.hasPopup) { + this._createPopup(this.container, null, this.data); } + return this.container; } + }]); + + return HighlightAnnotationElement; +}(AnnotationElement); + +var UnderlineAnnotationElement = function (_AnnotationElement11) { + _inherits(UnderlineAnnotationElement, _AnnotationElement11); + + function UnderlineAnnotationElement(parameters) { + _classCallCheck(this, UnderlineAnnotationElement); + + var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents); + return _possibleConstructorReturn(this, (UnderlineAnnotationElement.__proto__ || Object.getPrototypeOf(UnderlineAnnotationElement)).call(this, parameters, isRenderable, true)); } - function drawFigure(data, figure, context) { - var ps = figure.coords; - var cs = figure.colors; - var i, ii; - switch (figure.type) { - case 'lattice': - var verticesPerRow = figure.verticesPerRow; - var rows = Math.floor(ps.length / verticesPerRow) - 1; - var cols = verticesPerRow - 1; - for (i = 0; i < rows; i++) { - var q = i * verticesPerRow; - for (var j = 0; j < cols; j++, q++) { - drawTriangle(data, context, ps[q], ps[q + 1], ps[q + verticesPerRow], cs[q], cs[q + 1], cs[q + verticesPerRow]); - drawTriangle(data, context, ps[q + verticesPerRow + 1], ps[q + 1], ps[q + verticesPerRow], cs[q + verticesPerRow + 1], cs[q + 1], cs[q + verticesPerRow]); - } - } - break; - case 'triangles': - for (i = 0, ii = ps.length; i < ii; i += 3) { - drawTriangle(data, context, ps[i], ps[i + 1], ps[i + 2], cs[i], cs[i + 1], cs[i + 2]); - } - break; - default: - error('illigal figure'); - break; + + _createClass(UnderlineAnnotationElement, [{ + key: 'render', + value: function render() { + this.container.className = 'underlineAnnotation'; + if (!this.data.hasPopup) { + this._createPopup(this.container, null, this.data); + } + return this.container; } + }]); + + return UnderlineAnnotationElement; +}(AnnotationElement); + +var SquigglyAnnotationElement = function (_AnnotationElement12) { + _inherits(SquigglyAnnotationElement, _AnnotationElement12); + + function SquigglyAnnotationElement(parameters) { + _classCallCheck(this, SquigglyAnnotationElement); + + var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents); + return _possibleConstructorReturn(this, (SquigglyAnnotationElement.__proto__ || Object.getPrototypeOf(SquigglyAnnotationElement)).call(this, parameters, isRenderable, true)); } - function createMeshCanvas(bounds, combinesScale, coords, colors, figures, backgroundColor, cachedCanvases) { - var EXPECTED_SCALE = 1.1; - var MAX_PATTERN_SIZE = 3000; - var BORDER_SIZE = 2; - var offsetX = Math.floor(bounds[0]); - var offsetY = Math.floor(bounds[1]); - var boundsWidth = Math.ceil(bounds[2]) - offsetX; - var boundsHeight = Math.ceil(bounds[3]) - offsetY; - var width = Math.min(Math.ceil(Math.abs(boundsWidth * combinesScale[0] * EXPECTED_SCALE)), MAX_PATTERN_SIZE); - var height = Math.min(Math.ceil(Math.abs(boundsHeight * combinesScale[1] * EXPECTED_SCALE)), MAX_PATTERN_SIZE); - var scaleX = boundsWidth / width; - var scaleY = boundsHeight / height; - var context = { - coords: coords, - colors: colors, - offsetX: -offsetX, - offsetY: -offsetY, - scaleX: 1 / scaleX, - scaleY: 1 / scaleY - }; - var paddedWidth = width + BORDER_SIZE * 2; - var paddedHeight = height + BORDER_SIZE * 2; - var canvas, tmpCanvas, i, ii; - if (WebGLUtils.isEnabled) { - canvas = WebGLUtils.drawFigures(width, height, backgroundColor, figures, context); - tmpCanvas = cachedCanvases.getCanvas('mesh', paddedWidth, paddedHeight, false); - tmpCanvas.context.drawImage(canvas, BORDER_SIZE, BORDER_SIZE); - canvas = tmpCanvas.canvas; - } else { - tmpCanvas = cachedCanvases.getCanvas('mesh', paddedWidth, paddedHeight, false); - var tmpCtx = tmpCanvas.context; - var data = tmpCtx.createImageData(width, height); - if (backgroundColor) { - var bytes = data.data; - for (i = 0, ii = bytes.length; i < ii; i += 4) { - bytes[i] = backgroundColor[0]; - bytes[i + 1] = backgroundColor[1]; - bytes[i + 2] = backgroundColor[2]; - bytes[i + 3] = 255; - } + + _createClass(SquigglyAnnotationElement, [{ + key: 'render', + value: function render() { + this.container.className = 'squigglyAnnotation'; + if (!this.data.hasPopup) { + this._createPopup(this.container, null, this.data); } - for (i = 0; i < figures.length; i++) { - drawFigure(data, figures[i], context); + return this.container; + } + }]); + + return SquigglyAnnotationElement; +}(AnnotationElement); + +var StrikeOutAnnotationElement = function (_AnnotationElement13) { + _inherits(StrikeOutAnnotationElement, _AnnotationElement13); + + function StrikeOutAnnotationElement(parameters) { + _classCallCheck(this, StrikeOutAnnotationElement); + + var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents); + return _possibleConstructorReturn(this, (StrikeOutAnnotationElement.__proto__ || Object.getPrototypeOf(StrikeOutAnnotationElement)).call(this, parameters, isRenderable, true)); + } + + _createClass(StrikeOutAnnotationElement, [{ + key: 'render', + value: function render() { + this.container.className = 'strikeoutAnnotation'; + if (!this.data.hasPopup) { + this._createPopup(this.container, null, this.data); } - tmpCtx.putImageData(data, BORDER_SIZE, BORDER_SIZE); - canvas = tmpCanvas.canvas; + return this.container; } - return { - canvas: canvas, - offsetX: offsetX - BORDER_SIZE * scaleX, - offsetY: offsetY - BORDER_SIZE * scaleY, - scaleX: scaleX, - scaleY: scaleY - }; + }]); + + return StrikeOutAnnotationElement; +}(AnnotationElement); + +var StampAnnotationElement = function (_AnnotationElement14) { + _inherits(StampAnnotationElement, _AnnotationElement14); + + function StampAnnotationElement(parameters) { + _classCallCheck(this, StampAnnotationElement); + + var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents); + return _possibleConstructorReturn(this, (StampAnnotationElement.__proto__ || Object.getPrototypeOf(StampAnnotationElement)).call(this, parameters, isRenderable, true)); } - return createMeshCanvas; -}(); -ShadingIRs.Mesh = { - fromIR: function Mesh_fromIR(raw) { - var coords = raw[2]; - var colors = raw[3]; - var figures = raw[4]; - var bounds = raw[5]; - var matrix = raw[6]; - var background = raw[8]; - return { - type: 'Pattern', - getPattern: function Mesh_getPattern(ctx, owner, shadingFill) { - var scale; - if (shadingFill) { - scale = Util.singularValueDecompose2dScale(ctx.mozCurrentTransform); - } else { - scale = Util.singularValueDecompose2dScale(owner.baseTransform); - if (matrix) { - var matrixScale = Util.singularValueDecompose2dScale(matrix); - scale = [scale[0] * matrixScale[0], scale[1] * matrixScale[1]]; - } - } - var temporaryPatternCanvas = createMeshCanvas(bounds, scale, coords, colors, figures, shadingFill ? null : background, owner.cachedCanvases); - if (!shadingFill) { - ctx.setTransform.apply(ctx, owner.baseTransform); - if (matrix) { - ctx.transform.apply(ctx, matrix); - } - } - ctx.translate(temporaryPatternCanvas.offsetX, temporaryPatternCanvas.offsetY); - ctx.scale(temporaryPatternCanvas.scaleX, temporaryPatternCanvas.scaleY); - return ctx.createPattern(temporaryPatternCanvas.canvas, 'no-repeat'); + + _createClass(StampAnnotationElement, [{ + key: 'render', + value: function render() { + this.container.className = 'stampAnnotation'; + if (!this.data.hasPopup) { + this._createPopup(this.container, null, this.data); } - }; + return this.container; + } + }]); + + return StampAnnotationElement; +}(AnnotationElement); + +var FileAttachmentAnnotationElement = function (_AnnotationElement15) { + _inherits(FileAttachmentAnnotationElement, _AnnotationElement15); + + function FileAttachmentAnnotationElement(parameters) { + _classCallCheck(this, FileAttachmentAnnotationElement); + + var _this23 = _possibleConstructorReturn(this, (FileAttachmentAnnotationElement.__proto__ || Object.getPrototypeOf(FileAttachmentAnnotationElement)).call(this, parameters, true)); + + var _this23$data$file = _this23.data.file, + filename = _this23$data$file.filename, + content = _this23$data$file.content; + + _this23.filename = (0, _dom_utils.getFilenameFromUrl)(filename); + _this23.content = content; + if (_this23.linkService.eventBus) { + _this23.linkService.eventBus.dispatch('fileattachmentannotation', { + source: _this23, + id: (0, _util.stringToPDFString)(filename), + filename: filename, + content: content + }); + } + return _this23; } -}; -ShadingIRs.Dummy = { - fromIR: function Dummy_fromIR() { - return { - type: 'Pattern', - getPattern: function Dummy_fromIR_getPattern() { - return 'hotpink'; + + _createClass(FileAttachmentAnnotationElement, [{ + key: 'render', + value: function render() { + this.container.className = 'fileAttachmentAnnotation'; + var trigger = document.createElement('div'); + trigger.style.height = this.container.style.height; + trigger.style.width = this.container.style.width; + trigger.addEventListener('dblclick', this._download.bind(this)); + if (!this.data.hasPopup && (this.data.title || this.data.contents)) { + this._createPopup(this.container, trigger, this.data); + } + this.container.appendChild(trigger); + return this.container; + } + }, { + key: '_download', + value: function _download() { + if (!this.downloadManager) { + (0, _util.warn)('Download cannot be started due to unavailable download manager'); + return; } - }; - } -}; -function getShadingPatternFromIR(raw) { - var shadingIR = ShadingIRs[raw[0]]; - if (!shadingIR) { - error('Unknown IR type: ' + raw[0]); - } - return shadingIR.fromIR(raw); -} -var TilingPattern = function TilingPatternClosure() { - var PaintType = { - COLORED: 1, - UNCOLORED: 2 - }; - var MAX_PATTERN_SIZE = 3000; - function TilingPattern(IR, color, ctx, canvasGraphicsFactory, baseTransform) { - this.operatorList = IR[2]; - this.matrix = IR[3] || [1, 0, 0, 1, 0, 0]; - this.bbox = Util.normalizeRect(IR[4]); - this.xstep = IR[5]; - this.ystep = IR[6]; - this.paintType = IR[7]; - this.tilingType = IR[8]; - this.color = color; - this.canvasGraphicsFactory = canvasGraphicsFactory; - this.baseTransform = baseTransform; - this.type = 'Pattern'; - this.ctx = ctx; + this.downloadManager.downloadData(this.content, this.filename, ''); + } + }]); + + return FileAttachmentAnnotationElement; +}(AnnotationElement); + +var AnnotationLayer = function () { + function AnnotationLayer() { + _classCallCheck(this, AnnotationLayer); } - TilingPattern.prototype = { - createPatternCanvas: function TilinPattern_createPatternCanvas(owner) { - var operatorList = this.operatorList; - var bbox = this.bbox; - var xstep = this.xstep; - var ystep = this.ystep; - var paintType = this.paintType; - var tilingType = this.tilingType; - var color = this.color; - var canvasGraphicsFactory = this.canvasGraphicsFactory; - info('TilingType: ' + tilingType); - var x0 = bbox[0], - y0 = bbox[1], - x1 = bbox[2], - y1 = bbox[3]; - var topLeft = [x0, y0]; - var botRight = [x0 + xstep, y0 + ystep]; - var width = botRight[0] - topLeft[0]; - var height = botRight[1] - topLeft[1]; - var matrixScale = Util.singularValueDecompose2dScale(this.matrix); - var curMatrixScale = Util.singularValueDecompose2dScale(this.baseTransform); - var combinedScale = [matrixScale[0] * curMatrixScale[0], matrixScale[1] * curMatrixScale[1]]; - width = Math.min(Math.ceil(Math.abs(width * combinedScale[0])), MAX_PATTERN_SIZE); - height = Math.min(Math.ceil(Math.abs(height * combinedScale[1])), MAX_PATTERN_SIZE); - var tmpCanvas = owner.cachedCanvases.getCanvas('pattern', width, height, true); - var tmpCtx = tmpCanvas.context; - var graphics = canvasGraphicsFactory.createCanvasGraphics(tmpCtx); - graphics.groupLevel = owner.groupLevel; - this.setFillAndStrokeStyleToContext(tmpCtx, paintType, color); - this.setScale(width, height, xstep, ystep); - this.transformToScale(graphics); - var tmpTranslate = [1, 0, 0, 1, -topLeft[0], -topLeft[1]]; - graphics.transform.apply(graphics, tmpTranslate); - this.clipBbox(graphics, bbox, x0, y0, x1, y1); - graphics.executeOperatorList(operatorList); - return tmpCanvas.canvas; - }, - setScale: function TilingPattern_setScale(width, height, xstep, ystep) { - this.scale = [width / xstep, height / ystep]; - }, - transformToScale: function TilingPattern_transformToScale(graphics) { - var scale = this.scale; - var tmpScale = [scale[0], 0, 0, scale[1], 0, 0]; - graphics.transform.apply(graphics, tmpScale); - }, - scaleToContext: function TilingPattern_scaleToContext() { - var scale = this.scale; - this.ctx.scale(1 / scale[0], 1 / scale[1]); - }, - clipBbox: function clipBbox(graphics, bbox, x0, y0, x1, y1) { - if (isArray(bbox) && bbox.length === 4) { - var bboxWidth = x1 - x0; - var bboxHeight = y1 - y0; - graphics.ctx.rect(x0, y0, bboxWidth, bboxHeight); - graphics.clip(); - graphics.endPath(); + + _createClass(AnnotationLayer, null, [{ + key: 'render', + value: function render(parameters) { + for (var i = 0, ii = parameters.annotations.length; i < ii; i++) { + var data = parameters.annotations[i]; + if (!data) { + continue; + } + var element = AnnotationElementFactory.create({ + data: data, + layer: parameters.div, + page: parameters.page, + viewport: parameters.viewport, + linkService: parameters.linkService, + downloadManager: parameters.downloadManager, + imageResourcesPath: parameters.imageResourcesPath || '', + renderInteractiveForms: parameters.renderInteractiveForms || false, + svgFactory: new _dom_utils.DOMSVGFactory() + }); + if (element.isRenderable) { + parameters.div.appendChild(element.render()); + } } - }, - setFillAndStrokeStyleToContext: function setFillAndStrokeStyleToContext(context, paintType, color) { - switch (paintType) { - case PaintType.COLORED: - var ctx = this.ctx; - context.fillStyle = ctx.fillStyle; - context.strokeStyle = ctx.strokeStyle; - break; - case PaintType.UNCOLORED: - var cssColor = Util.makeCssRgb(color[0], color[1], color[2]); - context.fillStyle = cssColor; - context.strokeStyle = cssColor; - break; - default: - error('Unsupported paint type: ' + paintType); + } + }, { + key: 'update', + value: function update(parameters) { + for (var i = 0, ii = parameters.annotations.length; i < ii; i++) { + var data = parameters.annotations[i]; + var element = parameters.div.querySelector('[data-annotation-id="' + data.id + '"]'); + if (element) { + element.style.transform = 'matrix(' + parameters.viewport.transform.join(',') + ')'; + } } - }, - getPattern: function TilingPattern_getPattern(ctx, owner) { - var temporaryPatternCanvas = this.createPatternCanvas(owner); - ctx = this.ctx; - ctx.setTransform.apply(ctx, this.baseTransform); - ctx.transform.apply(ctx, this.matrix); - this.scaleToContext(); - return ctx.createPattern(temporaryPatternCanvas, 'repeat'); + parameters.div.removeAttribute('hidden'); } - }; - return TilingPattern; + }]); + + return AnnotationLayer; }(); -exports.getShadingPatternFromIR = getShadingPatternFromIR; -exports.TilingPattern = TilingPattern; + +exports.AnnotationLayer = AnnotationLayer; /***/ }), -/* 13 */ +/* 147 */ /***/ (function(module, exports, __w_pdfjs_require__) { "use strict"; -var pdfjsVersion = '1.8.172'; -var pdfjsBuild = '8ff1fbe7'; -var pdfjsSharedUtil = __w_pdfjs_require__(0); -var pdfjsDisplayGlobal = __w_pdfjs_require__(9); -var pdfjsDisplayAPI = __w_pdfjs_require__(3); -var pdfjsDisplayTextLayer = __w_pdfjs_require__(5); -var pdfjsDisplayAnnotationLayer = __w_pdfjs_require__(2); -var pdfjsDisplayDOMUtils = __w_pdfjs_require__(1); -var pdfjsDisplaySVG = __w_pdfjs_require__(4); -exports.PDFJS = pdfjsDisplayGlobal.PDFJS; -exports.build = pdfjsDisplayAPI.build; -exports.version = pdfjsDisplayAPI.version; -exports.getDocument = pdfjsDisplayAPI.getDocument; -exports.PDFDataRangeTransport = pdfjsDisplayAPI.PDFDataRangeTransport; -exports.PDFWorker = pdfjsDisplayAPI.PDFWorker; -exports.renderTextLayer = pdfjsDisplayTextLayer.renderTextLayer; -exports.AnnotationLayer = pdfjsDisplayAnnotationLayer.AnnotationLayer; -exports.CustomStyle = pdfjsDisplayDOMUtils.CustomStyle; -exports.createPromiseCapability = pdfjsSharedUtil.createPromiseCapability; -exports.PasswordResponses = pdfjsSharedUtil.PasswordResponses; -exports.InvalidPDFException = pdfjsSharedUtil.InvalidPDFException; -exports.MissingPDFException = pdfjsSharedUtil.MissingPDFException; -exports.SVGGraphics = pdfjsDisplaySVG.SVGGraphics; -exports.UnexpectedResponseException = pdfjsSharedUtil.UnexpectedResponseException; -exports.OPS = pdfjsSharedUtil.OPS; -exports.UNSUPPORTED_FEATURES = pdfjsSharedUtil.UNSUPPORTED_FEATURES; -exports.isValidUrl = pdfjsDisplayDOMUtils.isValidUrl; -exports.createValidAbsoluteUrl = pdfjsSharedUtil.createValidAbsoluteUrl; -exports.createObjectURL = pdfjsSharedUtil.createObjectURL; -exports.removeNullCharacters = pdfjsSharedUtil.removeNullCharacters; -exports.shadow = pdfjsSharedUtil.shadow; -exports.createBlob = pdfjsSharedUtil.createBlob; -exports.RenderingCancelledException = pdfjsDisplayDOMUtils.RenderingCancelledException; -exports.getFilenameFromUrl = pdfjsDisplayDOMUtils.getFilenameFromUrl; -exports.addLinkAttributes = pdfjsDisplayDOMUtils.addLinkAttributes; +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.SVGGraphics = undefined; -/***/ }), -/* 14 */ -/***/ (function(module, exports, __w_pdfjs_require__) { +var _util = __w_pdfjs_require__(1); -"use strict"; -/* WEBPACK VAR INJECTION */(function(global) { +var _dom_utils = __w_pdfjs_require__(130); -if (typeof PDFJS === 'undefined' || !PDFJS.compatibilityChecked) { - var globalScope = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : undefined; - var userAgent = typeof navigator !== 'undefined' && navigator.userAgent || ''; - var isAndroid = /Android/.test(userAgent); - var isAndroidPre3 = /Android\s[0-2][^\d]/.test(userAgent); - var isAndroidPre5 = /Android\s[0-4][^\d]/.test(userAgent); - var isChrome = userAgent.indexOf('Chrom') >= 0; - var isChromeWithRangeBug = /Chrome\/(39|40)\./.test(userAgent); - var isIOSChrome = userAgent.indexOf('CriOS') >= 0; - var isIE = userAgent.indexOf('Trident') >= 0; - var isIOS = /\b(iPad|iPhone|iPod)(?=;)/.test(userAgent); - var isOpera = userAgent.indexOf('Opera') >= 0; - var isSafari = /Safari\//.test(userAgent) && !/(Chrome\/|Android\s)/.test(userAgent); - var hasDOM = typeof window === 'object' && typeof document === 'object'; - if (typeof PDFJS === 'undefined') { - globalScope.PDFJS = {}; - } - PDFJS.compatibilityChecked = true; - (function checkTypedArrayCompatibility() { - if (typeof Uint8Array !== 'undefined') { - if (typeof Uint8Array.prototype.subarray === 'undefined') { - Uint8Array.prototype.subarray = function subarray(start, end) { - return new Uint8Array(this.slice(start, end)); - }; - Float32Array.prototype.subarray = function subarray(start, end) { - return new Float32Array(this.slice(start, end)); - }; +var _is_node = __w_pdfjs_require__(4); + +var _is_node2 = _interopRequireDefault(_is_node); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +var SVGGraphics = function SVGGraphics() { + throw new Error('Not implemented: SVGGraphics'); +}; +{ + var SVG_DEFAULTS = { + fontStyle: 'normal', + fontWeight: 'normal', + fillColor: '#000000' + }; + var convertImgDataToPng = function convertImgDataToPngClosure() { + var PNG_HEADER = new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]); + var CHUNK_WRAPPER_SIZE = 12; + var crcTable = new Int32Array(256); + for (var i = 0; i < 256; i++) { + var c = i; + for (var h = 0; h < 8; h++) { + if (c & 1) { + c = 0xedB88320 ^ c >> 1 & 0x7fffffff; + } else { + c = c >> 1 & 0x7fffffff; + } + } + crcTable[i] = c; + } + function crc32(data, start, end) { + var crc = -1; + for (var i = start; i < end; i++) { + var a = (crc ^ data[i]) & 0xff; + var b = crcTable[a]; + crc = crc >>> 8 ^ b; + } + return crc ^ -1; + } + function writePngChunk(type, body, data, offset) { + var p = offset; + var len = body.length; + data[p] = len >> 24 & 0xff; + data[p + 1] = len >> 16 & 0xff; + data[p + 2] = len >> 8 & 0xff; + data[p + 3] = len & 0xff; + p += 4; + data[p] = type.charCodeAt(0) & 0xff; + data[p + 1] = type.charCodeAt(1) & 0xff; + data[p + 2] = type.charCodeAt(2) & 0xff; + data[p + 3] = type.charCodeAt(3) & 0xff; + p += 4; + data.set(body, p); + p += body.length; + var crc = crc32(data, offset + 4, p); + data[p] = crc >> 24 & 0xff; + data[p + 1] = crc >> 16 & 0xff; + data[p + 2] = crc >> 8 & 0xff; + data[p + 3] = crc & 0xff; + } + function adler32(data, start, end) { + var a = 1; + var b = 0; + for (var i = start; i < end; ++i) { + a = (a + (data[i] & 0xff)) % 65521; + b = (b + a) % 65521; + } + return b << 16 | a; + } + function deflateSync(literals) { + if (!(0, _is_node2.default)()) { + return deflateSyncUncompressed(literals); } - if (typeof Float64Array === 'undefined') { - globalScope.Float64Array = Float32Array; + try { + var input; + if (parseInt(process.versions.node) >= 8) { + input = literals; + } else { + input = new Buffer(literals); + } + var output = require('zlib').deflateSync(input, { level: 9 }); + return output instanceof Uint8Array ? output : new Uint8Array(output); + } catch (e) { + (0, _util.warn)('Not compressing PNG because zlib.deflateSync is unavailable: ' + e); } - return; + return deflateSyncUncompressed(literals); + } + function deflateSyncUncompressed(literals) { + var len = literals.length; + var maxBlockLength = 0xFFFF; + var deflateBlocks = Math.ceil(len / maxBlockLength); + var idat = new Uint8Array(2 + len + deflateBlocks * 5 + 4); + var pi = 0; + idat[pi++] = 0x78; + idat[pi++] = 0x9c; + var pos = 0; + while (len > maxBlockLength) { + idat[pi++] = 0x00; + idat[pi++] = 0xff; + idat[pi++] = 0xff; + idat[pi++] = 0x00; + idat[pi++] = 0x00; + idat.set(literals.subarray(pos, pos + maxBlockLength), pi); + pi += maxBlockLength; + pos += maxBlockLength; + len -= maxBlockLength; + } + idat[pi++] = 0x01; + idat[pi++] = len & 0xff; + idat[pi++] = len >> 8 & 0xff; + idat[pi++] = ~len & 0xffff & 0xff; + idat[pi++] = (~len & 0xffff) >> 8 & 0xff; + idat.set(literals.subarray(pos), pi); + pi += literals.length - pos; + var adler = adler32(literals, 0, literals.length); + idat[pi++] = adler >> 24 & 0xff; + idat[pi++] = adler >> 16 & 0xff; + idat[pi++] = adler >> 8 & 0xff; + idat[pi++] = adler & 0xff; + return idat; + } + function encode(imgData, kind, forceDataSchema, isMask) { + var width = imgData.width; + var height = imgData.height; + var bitDepth, colorType, lineSize; + var bytes = imgData.data; + switch (kind) { + case _util.ImageKind.GRAYSCALE_1BPP: + colorType = 0; + bitDepth = 1; + lineSize = width + 7 >> 3; + break; + case _util.ImageKind.RGB_24BPP: + colorType = 2; + bitDepth = 8; + lineSize = width * 3; + break; + case _util.ImageKind.RGBA_32BPP: + colorType = 6; + bitDepth = 8; + lineSize = width * 4; + break; + default: + throw new Error('invalid format'); + } + var literals = new Uint8Array((1 + lineSize) * height); + var offsetLiterals = 0, + offsetBytes = 0; + var y, i; + for (y = 0; y < height; ++y) { + literals[offsetLiterals++] = 0; + literals.set(bytes.subarray(offsetBytes, offsetBytes + lineSize), offsetLiterals); + offsetBytes += lineSize; + offsetLiterals += lineSize; + } + if (kind === _util.ImageKind.GRAYSCALE_1BPP && isMask) { + offsetLiterals = 0; + for (y = 0; y < height; y++) { + offsetLiterals++; + for (i = 0; i < lineSize; i++) { + literals[offsetLiterals++] ^= 0xFF; + } + } + } + var ihdr = new Uint8Array([width >> 24 & 0xff, width >> 16 & 0xff, width >> 8 & 0xff, width & 0xff, height >> 24 & 0xff, height >> 16 & 0xff, height >> 8 & 0xff, height & 0xff, bitDepth, colorType, 0x00, 0x00, 0x00]); + var idat = deflateSync(literals); + var pngLength = PNG_HEADER.length + CHUNK_WRAPPER_SIZE * 3 + ihdr.length + idat.length; + var data = new Uint8Array(pngLength); + var offset = 0; + data.set(PNG_HEADER, offset); + offset += PNG_HEADER.length; + writePngChunk('IHDR', ihdr, data, offset); + offset += CHUNK_WRAPPER_SIZE + ihdr.length; + writePngChunk('IDATA', idat, data, offset); + offset += CHUNK_WRAPPER_SIZE + idat.length; + writePngChunk('IEND', new Uint8Array(0), data, offset); + return (0, _util.createObjectURL)(data, 'image/png', forceDataSchema); } - function subarray(start, end) { - return new TypedArray(this.slice(start, end)); + return function convertImgDataToPng(imgData, forceDataSchema, isMask) { + var kind = imgData.kind === undefined ? _util.ImageKind.GRAYSCALE_1BPP : imgData.kind; + return encode(imgData, kind, forceDataSchema, isMask); + }; + }(); + var SVGExtraState = function SVGExtraStateClosure() { + function SVGExtraState() { + this.fontSizeScale = 1; + this.fontWeight = SVG_DEFAULTS.fontWeight; + this.fontSize = 0; + this.textMatrix = _util.IDENTITY_MATRIX; + this.fontMatrix = _util.FONT_IDENTITY_MATRIX; + this.leading = 0; + this.textRenderingMode = _util.TextRenderingMode.FILL; + this.x = 0; + this.y = 0; + this.lineX = 0; + this.lineY = 0; + this.charSpacing = 0; + this.wordSpacing = 0; + this.textHScale = 1; + this.textRise = 0; + this.fillColor = SVG_DEFAULTS.fillColor; + this.strokeColor = '#000000'; + this.fillAlpha = 1; + this.strokeAlpha = 1; + this.lineWidth = 1; + this.lineJoin = ''; + this.lineCap = ''; + this.miterLimit = 0; + this.dashArray = []; + this.dashPhase = 0; + this.dependencies = []; + this.activeClipUrl = null; + this.clipGroup = null; + this.maskId = ''; } - function setArrayOffset(array, offset) { - if (arguments.length < 2) { - offset = 0; + SVGExtraState.prototype = { + clone: function SVGExtraState_clone() { + return Object.create(this); + }, + setCurrentPoint: function SVGExtraState_setCurrentPoint(x, y) { + this.x = x; + this.y = y; } - for (var i = 0, n = array.length; i < n; ++i, ++offset) { - this[offset] = array[i] & 0xFF; + }; + return SVGExtraState; + }(); + exports.SVGGraphics = SVGGraphics = function SVGGraphicsClosure() { + function opListToTree(opList) { + var opTree = []; + var tmp = []; + var opListLen = opList.length; + for (var x = 0; x < opListLen; x++) { + if (opList[x].fn === 'save') { + opTree.push({ + 'fnId': 92, + 'fn': 'group', + 'items': [] + }); + tmp.push(opTree); + opTree = opTree[opTree.length - 1].items; + continue; + } + if (opList[x].fn === 'restore') { + opTree = tmp.pop(); + } else { + opTree.push(opList[x]); + } } + return opTree; } - function TypedArray(arg1) { - var result, i, n; - if (typeof arg1 === 'number') { - result = []; - for (i = 0; i < arg1; ++i) { - result[i] = 0; + function pf(value) { + if (Number.isInteger(value)) { + return value.toString(); + } + var s = value.toFixed(10); + var i = s.length - 1; + if (s[i] !== '0') { + return s; + } + do { + i--; + } while (s[i] === '0'); + return s.substring(0, s[i] === '.' ? i : i + 1); + } + function pm(m) { + if (m[4] === 0 && m[5] === 0) { + if (m[1] === 0 && m[2] === 0) { + if (m[0] === 1 && m[3] === 1) { + return ''; + } + return 'scale(' + pf(m[0]) + ' ' + pf(m[3]) + ')'; + } + if (m[0] === m[3] && m[1] === -m[2]) { + var a = Math.acos(m[0]) * 180 / Math.PI; + return 'rotate(' + pf(a) + ')'; } - } else if ('slice' in arg1) { - result = arg1.slice(0); } else { - result = []; - for (i = 0, n = arg1.length; i < n; ++i) { - result[i] = arg1[i]; - } - } - result.subarray = subarray; - result.buffer = result; - result.byteLength = result.length; - result.set = setArrayOffset; - if (typeof arg1 === 'object' && arg1.buffer) { - result.buffer = arg1.buffer; - } - return result; - } - globalScope.Uint8Array = TypedArray; - globalScope.Int8Array = TypedArray; - globalScope.Uint32Array = TypedArray; - globalScope.Int32Array = TypedArray; - globalScope.Uint16Array = TypedArray; - globalScope.Float32Array = TypedArray; - globalScope.Float64Array = TypedArray; - })(); - (function normalizeURLObject() { - if (!globalScope.URL) { - globalScope.URL = globalScope.webkitURL; + if (m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1) { + return 'translate(' + pf(m[4]) + ' ' + pf(m[5]) + ')'; + } + } + return 'matrix(' + pf(m[0]) + ' ' + pf(m[1]) + ' ' + pf(m[2]) + ' ' + pf(m[3]) + ' ' + pf(m[4]) + ' ' + pf(m[5]) + ')'; } - })(); - (function checkObjectDefinePropertyCompatibility() { - if (typeof Object.defineProperty !== 'undefined') { - var definePropertyPossible = true; - try { - if (hasDOM) { - Object.defineProperty(new Image(), 'id', { value: 'test' }); + function SVGGraphics(commonObjs, objs, forceDataSchema) { + this.svgFactory = new _dom_utils.DOMSVGFactory(); + this.current = new SVGExtraState(); + this.transformMatrix = _util.IDENTITY_MATRIX; + this.transformStack = []; + this.extraStack = []; + this.commonObjs = commonObjs; + this.objs = objs; + this.pendingClip = null; + this.pendingEOFill = false; + this.embedFonts = false; + this.embeddedFonts = Object.create(null); + this.cssStyle = null; + this.forceDataSchema = !!forceDataSchema; + } + var XML_NS = 'http://www.w3.org/XML/1998/namespace'; + var XLINK_NS = 'http://www.w3.org/1999/xlink'; + var LINE_CAP_STYLES = ['butt', 'round', 'square']; + var LINE_JOIN_STYLES = ['miter', 'round', 'bevel']; + var clipCount = 0; + var maskCount = 0; + SVGGraphics.prototype = { + save: function SVGGraphics_save() { + this.transformStack.push(this.transformMatrix); + var old = this.current; + this.extraStack.push(old); + this.current = old.clone(); + }, + restore: function SVGGraphics_restore() { + this.transformMatrix = this.transformStack.pop(); + this.current = this.extraStack.pop(); + this.pendingClip = null; + this.tgrp = null; + }, + group: function SVGGraphics_group(items) { + this.save(); + this.executeOpTree(items); + this.restore(); + }, + loadDependencies: function SVGGraphics_loadDependencies(operatorList) { + var _this = this; + + var fnArray = operatorList.fnArray; + var fnArrayLen = fnArray.length; + var argsArray = operatorList.argsArray; + for (var i = 0; i < fnArrayLen; i++) { + if (_util.OPS.dependency === fnArray[i]) { + var deps = argsArray[i]; + for (var n = 0, nn = deps.length; n < nn; n++) { + var obj = deps[n]; + var common = obj.substring(0, 2) === 'g_'; + var promise; + if (common) { + promise = new Promise(function (resolve) { + _this.commonObjs.get(obj, resolve); + }); + } else { + promise = new Promise(function (resolve) { + _this.objs.get(obj, resolve); + }); + } + this.current.dependencies.push(promise); + } + } + } + return Promise.all(this.current.dependencies); + }, + transform: function SVGGraphics_transform(a, b, c, d, e, f) { + var transformMatrix = [a, b, c, d, e, f]; + this.transformMatrix = _util.Util.transform(this.transformMatrix, transformMatrix); + this.tgrp = null; + }, + getSVG: function SVGGraphics_getSVG(operatorList, viewport) { + var _this2 = this; + + this.viewport = viewport; + var svgElement = this._initialize(viewport); + return this.loadDependencies(operatorList).then(function () { + _this2.transformMatrix = _util.IDENTITY_MATRIX; + var opTree = _this2.convertOpList(operatorList); + _this2.executeOpTree(opTree); + return svgElement; + }); + }, + convertOpList: function SVGGraphics_convertOpList(operatorList) { + var argsArray = operatorList.argsArray; + var fnArray = operatorList.fnArray; + var fnArrayLen = fnArray.length; + var REVOPS = []; + var opList = []; + for (var op in _util.OPS) { + REVOPS[_util.OPS[op]] = op; + } + for (var x = 0; x < fnArrayLen; x++) { + var fnId = fnArray[x]; + opList.push({ + 'fnId': fnId, + 'fn': REVOPS[fnId], + 'args': argsArray[x] + }); + } + return opListToTree(opList); + }, + executeOpTree: function SVGGraphics_executeOpTree(opTree) { + var opTreeLen = opTree.length; + for (var x = 0; x < opTreeLen; x++) { + var fn = opTree[x].fn; + var fnId = opTree[x].fnId; + var args = opTree[x].args; + switch (fnId | 0) { + case _util.OPS.beginText: + this.beginText(); + break; + case _util.OPS.dependency: + break; + case _util.OPS.setLeading: + this.setLeading(args); + break; + case _util.OPS.setLeadingMoveText: + this.setLeadingMoveText(args[0], args[1]); + break; + case _util.OPS.setFont: + this.setFont(args); + break; + case _util.OPS.showText: + this.showText(args[0]); + break; + case _util.OPS.showSpacedText: + this.showText(args[0]); + break; + case _util.OPS.endText: + this.endText(); + break; + case _util.OPS.moveText: + this.moveText(args[0], args[1]); + break; + case _util.OPS.setCharSpacing: + this.setCharSpacing(args[0]); + break; + case _util.OPS.setWordSpacing: + this.setWordSpacing(args[0]); + break; + case _util.OPS.setHScale: + this.setHScale(args[0]); + break; + case _util.OPS.setTextMatrix: + this.setTextMatrix(args[0], args[1], args[2], args[3], args[4], args[5]); + break; + case _util.OPS.setTextRise: + this.setTextRise(args[0]); + break; + case _util.OPS.setTextRenderingMode: + this.setTextRenderingMode(args[0]); + break; + case _util.OPS.setLineWidth: + this.setLineWidth(args[0]); + break; + case _util.OPS.setLineJoin: + this.setLineJoin(args[0]); + break; + case _util.OPS.setLineCap: + this.setLineCap(args[0]); + break; + case _util.OPS.setMiterLimit: + this.setMiterLimit(args[0]); + break; + case _util.OPS.setFillRGBColor: + this.setFillRGBColor(args[0], args[1], args[2]); + break; + case _util.OPS.setStrokeRGBColor: + this.setStrokeRGBColor(args[0], args[1], args[2]); + break; + case _util.OPS.setDash: + this.setDash(args[0], args[1]); + break; + case _util.OPS.setGState: + this.setGState(args[0]); + break; + case _util.OPS.fill: + this.fill(); + break; + case _util.OPS.eoFill: + this.eoFill(); + break; + case _util.OPS.stroke: + this.stroke(); + break; + case _util.OPS.fillStroke: + this.fillStroke(); + break; + case _util.OPS.eoFillStroke: + this.eoFillStroke(); + break; + case _util.OPS.clip: + this.clip('nonzero'); + break; + case _util.OPS.eoClip: + this.clip('evenodd'); + break; + case _util.OPS.paintSolidColorImageMask: + this.paintSolidColorImageMask(); + break; + case _util.OPS.paintJpegXObject: + this.paintJpegXObject(args[0], args[1], args[2]); + break; + case _util.OPS.paintImageXObject: + this.paintImageXObject(args[0]); + break; + case _util.OPS.paintInlineImageXObject: + this.paintInlineImageXObject(args[0]); + break; + case _util.OPS.paintImageMaskXObject: + this.paintImageMaskXObject(args[0]); + break; + case _util.OPS.paintFormXObjectBegin: + this.paintFormXObjectBegin(args[0], args[1]); + break; + case _util.OPS.paintFormXObjectEnd: + this.paintFormXObjectEnd(); + break; + case _util.OPS.closePath: + this.closePath(); + break; + case _util.OPS.closeStroke: + this.closeStroke(); + break; + case _util.OPS.closeFillStroke: + this.closeFillStroke(); + break; + case _util.OPS.closeEOFillStroke: + this.closeEOFillStroke(); + break; + case _util.OPS.nextLine: + this.nextLine(); + break; + case _util.OPS.transform: + this.transform(args[0], args[1], args[2], args[3], args[4], args[5]); + break; + case _util.OPS.constructPath: + this.constructPath(args[0], args[1]); + break; + case _util.OPS.endPath: + this.endPath(); + break; + case 92: + this.group(opTree[x].items); + break; + default: + (0, _util.warn)('Unimplemented operator ' + fn); + break; + } } - var Test = function Test() {}; - Test.prototype = { - get id() {} - }; - Object.defineProperty(new Test(), 'id', { - value: '', - configurable: true, - enumerable: true, - writable: false - }); - } catch (e) { - definePropertyPossible = false; - } - if (definePropertyPossible) { - return; - } - } - Object.defineProperty = function objectDefineProperty(obj, name, def) { - delete obj[name]; - if ('get' in def) { - obj.__defineGetter__(name, def['get']); - } - if ('set' in def) { - obj.__defineSetter__(name, def['set']); - } - if ('value' in def) { - obj.__defineSetter__(name, function objectDefinePropertySetter(value) { - this.__defineGetter__(name, function objectDefinePropertyGetter() { - return value; - }); - return value; - }); - obj[name] = def.value; - } - }; - })(); - (function checkXMLHttpRequestResponseCompatibility() { - if (typeof XMLHttpRequest === 'undefined') { - return; - } - var xhrPrototype = XMLHttpRequest.prototype; - var xhr = new XMLHttpRequest(); - if (!('overrideMimeType' in xhr)) { - Object.defineProperty(xhrPrototype, 'overrideMimeType', { - value: function xmlHttpRequestOverrideMimeType(mimeType) {} - }); - } - if ('responseType' in xhr) { - return; - } - Object.defineProperty(xhrPrototype, 'responseType', { - get: function xmlHttpRequestGetResponseType() { - return this._responseType || 'text'; }, - set: function xmlHttpRequestSetResponseType(value) { - if (value === 'text' || value === 'arraybuffer') { - this._responseType = value; - if (value === 'arraybuffer' && typeof this.overrideMimeType === 'function') { - this.overrideMimeType('text/plain; charset=x-user-defined'); + setWordSpacing: function SVGGraphics_setWordSpacing(wordSpacing) { + this.current.wordSpacing = wordSpacing; + }, + setCharSpacing: function SVGGraphics_setCharSpacing(charSpacing) { + this.current.charSpacing = charSpacing; + }, + nextLine: function SVGGraphics_nextLine() { + this.moveText(0, this.current.leading); + }, + setTextMatrix: function SVGGraphics_setTextMatrix(a, b, c, d, e, f) { + var current = this.current; + this.current.textMatrix = this.current.lineMatrix = [a, b, c, d, e, f]; + this.current.x = this.current.lineX = 0; + this.current.y = this.current.lineY = 0; + current.xcoords = []; + current.tspan = this.svgFactory.createElement('svg:tspan'); + current.tspan.setAttributeNS(null, 'font-family', current.fontFamily); + current.tspan.setAttributeNS(null, 'font-size', pf(current.fontSize) + 'px'); + current.tspan.setAttributeNS(null, 'y', pf(-current.y)); + current.txtElement = this.svgFactory.createElement('svg:text'); + current.txtElement.appendChild(current.tspan); + }, + beginText: function SVGGraphics_beginText() { + this.current.x = this.current.lineX = 0; + this.current.y = this.current.lineY = 0; + this.current.textMatrix = _util.IDENTITY_MATRIX; + this.current.lineMatrix = _util.IDENTITY_MATRIX; + this.current.tspan = this.svgFactory.createElement('svg:tspan'); + this.current.txtElement = this.svgFactory.createElement('svg:text'); + this.current.txtgrp = this.svgFactory.createElement('svg:g'); + this.current.xcoords = []; + }, + moveText: function SVGGraphics_moveText(x, y) { + var current = this.current; + this.current.x = this.current.lineX += x; + this.current.y = this.current.lineY += y; + current.xcoords = []; + current.tspan = this.svgFactory.createElement('svg:tspan'); + current.tspan.setAttributeNS(null, 'font-family', current.fontFamily); + current.tspan.setAttributeNS(null, 'font-size', pf(current.fontSize) + 'px'); + current.tspan.setAttributeNS(null, 'y', pf(-current.y)); + }, + showText: function SVGGraphics_showText(glyphs) { + var current = this.current; + var font = current.font; + var fontSize = current.fontSize; + if (fontSize === 0) { + return; + } + var charSpacing = current.charSpacing; + var wordSpacing = current.wordSpacing; + var fontDirection = current.fontDirection; + var textHScale = current.textHScale * fontDirection; + var glyphsLength = glyphs.length; + var vertical = font.vertical; + var widthAdvanceScale = fontSize * current.fontMatrix[0]; + var x = 0, + i; + for (i = 0; i < glyphsLength; ++i) { + var glyph = glyphs[i]; + if (glyph === null) { + x += fontDirection * wordSpacing; + continue; + } else if ((0, _util.isNum)(glyph)) { + x += -glyph * fontSize * 0.001; + continue; + } + var width = glyph.width; + var character = glyph.fontChar; + var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing; + var charWidth = width * widthAdvanceScale + spacing * fontDirection; + if (!glyph.isInFont && !font.missingFile) { + x += charWidth; + continue; } + current.xcoords.push(current.x + x * textHScale); + current.tspan.textContent += character; + x += charWidth; } - } - }); - if (typeof VBArray !== 'undefined') { - Object.defineProperty(xhrPrototype, 'response', { - get: function xmlHttpRequestResponseGet() { - if (this.responseType === 'arraybuffer') { - return new Uint8Array(new VBArray(this.responseBody).toArray()); + if (vertical) { + current.y -= x * textHScale; + } else { + current.x += x * textHScale; + } + current.tspan.setAttributeNS(null, 'x', current.xcoords.map(pf).join(' ')); + current.tspan.setAttributeNS(null, 'y', pf(-current.y)); + current.tspan.setAttributeNS(null, 'font-family', current.fontFamily); + current.tspan.setAttributeNS(null, 'font-size', pf(current.fontSize) + 'px'); + if (current.fontStyle !== SVG_DEFAULTS.fontStyle) { + current.tspan.setAttributeNS(null, 'font-style', current.fontStyle); + } + if (current.fontWeight !== SVG_DEFAULTS.fontWeight) { + current.tspan.setAttributeNS(null, 'font-weight', current.fontWeight); + } + var fillStrokeMode = current.textRenderingMode & _util.TextRenderingMode.FILL_STROKE_MASK; + if (fillStrokeMode === _util.TextRenderingMode.FILL || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) { + if (current.fillColor !== SVG_DEFAULTS.fillColor) { + current.tspan.setAttributeNS(null, 'fill', current.fillColor); + } + if (current.fillAlpha < 1) { + current.tspan.setAttributeNS(null, 'fill-opacity', current.fillAlpha); } - return this.responseText; + } else if (current.textRenderingMode === _util.TextRenderingMode.ADD_TO_PATH) { + current.tspan.setAttributeNS(null, 'fill', 'transparent'); + } else { + current.tspan.setAttributeNS(null, 'fill', 'none'); } - }); - return; - } - Object.defineProperty(xhrPrototype, 'response', { - get: function xmlHttpRequestResponseGet() { - if (this.responseType !== 'arraybuffer') { - return this.responseText; + if (fillStrokeMode === _util.TextRenderingMode.STROKE || fillStrokeMode === _util.TextRenderingMode.FILL_STROKE) { + this._setStrokeAttributes(current.tspan); } - var text = this.responseText; - var i, - n = text.length; - var result = new Uint8Array(n); - for (i = 0; i < n; ++i) { - result[i] = text.charCodeAt(i) & 0xFF; + var textMatrix = current.textMatrix; + if (current.textRise !== 0) { + textMatrix = textMatrix.slice(); + textMatrix[5] += current.textRise; } - return result.buffer; - } - }); - })(); - (function checkWindowBtoaCompatibility() { - if ('btoa' in globalScope) { - return; - } - var digits = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; - globalScope.btoa = function (chars) { - var buffer = ''; - var i, n; - for (i = 0, n = chars.length; i < n; i += 3) { - var b1 = chars.charCodeAt(i) & 0xFF; - var b2 = chars.charCodeAt(i + 1) & 0xFF; - var b3 = chars.charCodeAt(i + 2) & 0xFF; - var d1 = b1 >> 2, - d2 = (b1 & 3) << 4 | b2 >> 4; - var d3 = i + 1 < n ? (b2 & 0xF) << 2 | b3 >> 6 : 64; - var d4 = i + 2 < n ? b3 & 0x3F : 64; - buffer += digits.charAt(d1) + digits.charAt(d2) + digits.charAt(d3) + digits.charAt(d4); - } - return buffer; - }; - })(); - (function checkWindowAtobCompatibility() { - if ('atob' in globalScope) { - return; - } - var digits = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; - globalScope.atob = function (input) { - input = input.replace(/=+$/, ''); - if (input.length % 4 === 1) { - throw new Error('bad atob input'); - } - for (var bc = 0, bs, buffer, idx = 0, output = ''; buffer = input.charAt(idx++); ~buffer && (bs = bc % 4 ? bs * 64 + buffer : buffer, bc++ % 4) ? output += String.fromCharCode(255 & bs >> (-2 * bc & 6)) : 0) { - buffer = digits.indexOf(buffer); - } - return output; - }; - })(); - (function checkFunctionPrototypeBindCompatibility() { - if (typeof Function.prototype.bind !== 'undefined') { - return; - } - Function.prototype.bind = function functionPrototypeBind(obj) { - var fn = this, - headArgs = Array.prototype.slice.call(arguments, 1); - var bound = function functionPrototypeBindBound() { - var args = headArgs.concat(Array.prototype.slice.call(arguments)); - return fn.apply(obj, args); - }; - return bound; - }; - })(); - (function checkDatasetProperty() { - if (!hasDOM) { - return; - } - var div = document.createElement('div'); - if ('dataset' in div) { - return; - } - Object.defineProperty(HTMLElement.prototype, 'dataset', { - get: function () { - if (this._dataset) { - return this._dataset; + current.txtElement.setAttributeNS(null, 'transform', pm(textMatrix) + ' scale(1, -1)'); + current.txtElement.setAttributeNS(XML_NS, 'xml:space', 'preserve'); + current.txtElement.appendChild(current.tspan); + current.txtgrp.appendChild(current.txtElement); + this._ensureTransformGroup().appendChild(current.txtElement); + }, + setLeadingMoveText: function SVGGraphics_setLeadingMoveText(x, y) { + this.setLeading(-y); + this.moveText(x, y); + }, + addFontStyle: function SVGGraphics_addFontStyle(fontObj) { + if (!this.cssStyle) { + this.cssStyle = this.svgFactory.createElement('svg:style'); + this.cssStyle.setAttributeNS(null, 'type', 'text/css'); + this.defs.appendChild(this.cssStyle); } - var dataset = {}; - for (var j = 0, jj = this.attributes.length; j < jj; j++) { - var attribute = this.attributes[j]; - if (attribute.name.substring(0, 5) !== 'data-') { - continue; + var url = (0, _util.createObjectURL)(fontObj.data, fontObj.mimetype, this.forceDataSchema); + this.cssStyle.textContent += '@font-face { font-family: "' + fontObj.loadedName + '";' + ' src: url(' + url + '); }\n'; + }, + setFont: function SVGGraphics_setFont(details) { + var current = this.current; + var fontObj = this.commonObjs.get(details[0]); + var size = details[1]; + this.current.font = fontObj; + if (this.embedFonts && fontObj.data && !this.embeddedFonts[fontObj.loadedName]) { + this.addFontStyle(fontObj); + this.embeddedFonts[fontObj.loadedName] = fontObj; + } + current.fontMatrix = fontObj.fontMatrix ? fontObj.fontMatrix : _util.FONT_IDENTITY_MATRIX; + var bold = fontObj.black ? fontObj.bold ? 'bolder' : 'bold' : fontObj.bold ? 'bold' : 'normal'; + var italic = fontObj.italic ? 'italic' : 'normal'; + if (size < 0) { + size = -size; + current.fontDirection = -1; + } else { + current.fontDirection = 1; + } + current.fontSize = size; + current.fontFamily = fontObj.loadedName; + current.fontWeight = bold; + current.fontStyle = italic; + current.tspan = this.svgFactory.createElement('svg:tspan'); + current.tspan.setAttributeNS(null, 'y', pf(-current.y)); + current.xcoords = []; + }, + endText: function endText() { + var current = this.current; + if (current.textRenderingMode & _util.TextRenderingMode.ADD_TO_PATH_FLAG && current.txtElement && current.txtElement.hasChildNodes()) { + current.element = current.txtElement; + this.clip('nonzero'); + this.endPath(); + } + }, + + setLineWidth: function SVGGraphics_setLineWidth(width) { + this.current.lineWidth = width; + }, + setLineCap: function SVGGraphics_setLineCap(style) { + this.current.lineCap = LINE_CAP_STYLES[style]; + }, + setLineJoin: function SVGGraphics_setLineJoin(style) { + this.current.lineJoin = LINE_JOIN_STYLES[style]; + }, + setMiterLimit: function SVGGraphics_setMiterLimit(limit) { + this.current.miterLimit = limit; + }, + setStrokeAlpha: function SVGGraphics_setStrokeAlpha(strokeAlpha) { + this.current.strokeAlpha = strokeAlpha; + }, + setStrokeRGBColor: function SVGGraphics_setStrokeRGBColor(r, g, b) { + var color = _util.Util.makeCssRgb(r, g, b); + this.current.strokeColor = color; + }, + setFillAlpha: function SVGGraphics_setFillAlpha(fillAlpha) { + this.current.fillAlpha = fillAlpha; + }, + setFillRGBColor: function SVGGraphics_setFillRGBColor(r, g, b) { + var color = _util.Util.makeCssRgb(r, g, b); + this.current.fillColor = color; + this.current.tspan = this.svgFactory.createElement('svg:tspan'); + this.current.xcoords = []; + }, + setDash: function SVGGraphics_setDash(dashArray, dashPhase) { + this.current.dashArray = dashArray; + this.current.dashPhase = dashPhase; + }, + constructPath: function SVGGraphics_constructPath(ops, args) { + var current = this.current; + var x = current.x, + y = current.y; + current.path = this.svgFactory.createElement('svg:path'); + var d = []; + var opLength = ops.length; + for (var i = 0, j = 0; i < opLength; i++) { + switch (ops[i] | 0) { + case _util.OPS.rectangle: + x = args[j++]; + y = args[j++]; + var width = args[j++]; + var height = args[j++]; + var xw = x + width; + var yh = y + height; + d.push('M', pf(x), pf(y), 'L', pf(xw), pf(y), 'L', pf(xw), pf(yh), 'L', pf(x), pf(yh), 'Z'); + break; + case _util.OPS.moveTo: + x = args[j++]; + y = args[j++]; + d.push('M', pf(x), pf(y)); + break; + case _util.OPS.lineTo: + x = args[j++]; + y = args[j++]; + d.push('L', pf(x), pf(y)); + break; + case _util.OPS.curveTo: + x = args[j + 4]; + y = args[j + 5]; + d.push('C', pf(args[j]), pf(args[j + 1]), pf(args[j + 2]), pf(args[j + 3]), pf(x), pf(y)); + j += 6; + break; + case _util.OPS.curveTo2: + x = args[j + 2]; + y = args[j + 3]; + d.push('C', pf(x), pf(y), pf(args[j]), pf(args[j + 1]), pf(args[j + 2]), pf(args[j + 3])); + j += 4; + break; + case _util.OPS.curveTo3: + x = args[j + 2]; + y = args[j + 3]; + d.push('C', pf(args[j]), pf(args[j + 1]), pf(x), pf(y), pf(x), pf(y)); + j += 4; + break; + case _util.OPS.closePath: + d.push('Z'); + break; } - var key = attribute.name.substring(5).replace(/\-([a-z])/g, function (all, ch) { - return ch.toUpperCase(); + } + current.path.setAttributeNS(null, 'd', d.join(' ')); + current.path.setAttributeNS(null, 'fill', 'none'); + this._ensureTransformGroup().appendChild(current.path); + current.element = current.path; + current.setCurrentPoint(x, y); + }, + endPath: function SVGGraphics_endPath() { + if (!this.pendingClip) { + return; + } + var current = this.current; + var clipId = 'clippath' + clipCount; + clipCount++; + var clipPath = this.svgFactory.createElement('svg:clipPath'); + clipPath.setAttributeNS(null, 'id', clipId); + clipPath.setAttributeNS(null, 'transform', pm(this.transformMatrix)); + var clipElement = current.element.cloneNode(true); + if (this.pendingClip === 'evenodd') { + clipElement.setAttributeNS(null, 'clip-rule', 'evenodd'); + } else { + clipElement.setAttributeNS(null, 'clip-rule', 'nonzero'); + } + this.pendingClip = null; + clipPath.appendChild(clipElement); + this.defs.appendChild(clipPath); + if (current.activeClipUrl) { + current.clipGroup = null; + this.extraStack.forEach(function (prev) { + prev.clipGroup = null; }); - dataset[key] = attribute.value; + clipPath.setAttributeNS(null, 'clip-path', current.activeClipUrl); } - Object.defineProperty(this, '_dataset', { - value: dataset, - writable: false, - enumerable: false - }); - return dataset; + current.activeClipUrl = 'url(#' + clipId + ')'; + this.tgrp = null; }, - enumerable: true - }); - })(); - (function checkClassListProperty() { - function changeList(element, itemName, add, remove) { - var s = element.className || ''; - var list = s.split(/\s+/g); - if (list[0] === '') { - list.shift(); - } - var index = list.indexOf(itemName); - if (index < 0 && add) { - list.push(itemName); - } - if (index >= 0 && remove) { - list.splice(index, 1); - } - element.className = list.join(' '); - return index >= 0; - } - if (!hasDOM) { - return; - } - var div = document.createElement('div'); - if ('classList' in div) { - return; - } - var classListPrototype = { - add: function (name) { - changeList(this.element, name, true, false); + clip: function SVGGraphics_clip(type) { + this.pendingClip = type; }, - contains: function (name) { - return changeList(this.element, name, false, false); + closePath: function SVGGraphics_closePath() { + var current = this.current; + if (current.path) { + var d = current.path.getAttributeNS(null, 'd'); + d += 'Z'; + current.path.setAttributeNS(null, 'd', d); + } }, - remove: function (name) { - changeList(this.element, name, false, true); + setLeading: function SVGGraphics_setLeading(leading) { + this.current.leading = -leading; }, - toggle: function (name) { - changeList(this.element, name, true, true); - } - }; - Object.defineProperty(HTMLElement.prototype, 'classList', { - get: function () { - if (this._classList) { - return this._classList; - } - var classList = Object.create(classListPrototype, { - element: { - value: this, - writable: false, - enumerable: true + setTextRise: function SVGGraphics_setTextRise(textRise) { + this.current.textRise = textRise; + }, + setTextRenderingMode: function setTextRenderingMode(textRenderingMode) { + this.current.textRenderingMode = textRenderingMode; + }, + + setHScale: function SVGGraphics_setHScale(scale) { + this.current.textHScale = scale / 100; + }, + setGState: function SVGGraphics_setGState(states) { + for (var i = 0, ii = states.length; i < ii; i++) { + var state = states[i]; + var key = state[0]; + var value = state[1]; + switch (key) { + case 'LW': + this.setLineWidth(value); + break; + case 'LC': + this.setLineCap(value); + break; + case 'LJ': + this.setLineJoin(value); + break; + case 'ML': + this.setMiterLimit(value); + break; + case 'D': + this.setDash(value[0], value[1]); + break; + case 'Font': + this.setFont(value); + break; + case 'CA': + this.setStrokeAlpha(value); + break; + case 'ca': + this.setFillAlpha(value); + break; + default: + (0, _util.warn)('Unimplemented graphic state ' + key); + break; } - }); - Object.defineProperty(this, '_classList', { - value: classList, - writable: false, - enumerable: false - }); - return classList; + } }, - enumerable: true - }); - })(); - (function checkWorkerConsoleCompatibility() { - if (typeof importScripts === 'undefined' || 'console' in globalScope) { - return; - } - var consoleTimer = {}; - var workerConsole = { - log: function log() { - var args = Array.prototype.slice.call(arguments); - globalScope.postMessage({ - targetName: 'main', - action: 'console_log', - data: args - }); + fill: function SVGGraphics_fill() { + var current = this.current; + if (current.element) { + current.element.setAttributeNS(null, 'fill', current.fillColor); + current.element.setAttributeNS(null, 'fill-opacity', current.fillAlpha); + this.endPath(); + } }, - error: function error() { - var args = Array.prototype.slice.call(arguments); - globalScope.postMessage({ - targetName: 'main', - action: 'console_error', - data: args - }); + stroke: function SVGGraphics_stroke() { + var current = this.current; + if (current.element) { + this._setStrokeAttributes(current.element); + current.element.setAttributeNS(null, 'fill', 'none'); + this.endPath(); + } + }, + _setStrokeAttributes: function _setStrokeAttributes(element) { + var current = this.current; + element.setAttributeNS(null, 'stroke', current.strokeColor); + element.setAttributeNS(null, 'stroke-opacity', current.strokeAlpha); + element.setAttributeNS(null, 'stroke-miterlimit', pf(current.miterLimit)); + element.setAttributeNS(null, 'stroke-linecap', current.lineCap); + element.setAttributeNS(null, 'stroke-linejoin', current.lineJoin); + element.setAttributeNS(null, 'stroke-width', pf(current.lineWidth) + 'px'); + element.setAttributeNS(null, 'stroke-dasharray', current.dashArray.map(pf).join(' ')); + element.setAttributeNS(null, 'stroke-dashoffset', pf(current.dashPhase) + 'px'); + }, + + eoFill: function SVGGraphics_eoFill() { + if (this.current.element) { + this.current.element.setAttributeNS(null, 'fill-rule', 'evenodd'); + } + this.fill(); + }, + fillStroke: function SVGGraphics_fillStroke() { + this.stroke(); + this.fill(); + }, + eoFillStroke: function SVGGraphics_eoFillStroke() { + if (this.current.element) { + this.current.element.setAttributeNS(null, 'fill-rule', 'evenodd'); + } + this.fillStroke(); + }, + closeStroke: function SVGGraphics_closeStroke() { + this.closePath(); + this.stroke(); + }, + closeFillStroke: function SVGGraphics_closeFillStroke() { + this.closePath(); + this.fillStroke(); + }, + closeEOFillStroke: function closeEOFillStroke() { + this.closePath(); + this.eoFillStroke(); + }, + + paintSolidColorImageMask: function SVGGraphics_paintSolidColorImageMask() { + var current = this.current; + var rect = this.svgFactory.createElement('svg:rect'); + rect.setAttributeNS(null, 'x', '0'); + rect.setAttributeNS(null, 'y', '0'); + rect.setAttributeNS(null, 'width', '1px'); + rect.setAttributeNS(null, 'height', '1px'); + rect.setAttributeNS(null, 'fill', current.fillColor); + this._ensureTransformGroup().appendChild(rect); + }, + paintJpegXObject: function SVGGraphics_paintJpegXObject(objId, w, h) { + var imgObj = this.objs.get(objId); + var imgEl = this.svgFactory.createElement('svg:image'); + imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgObj.src); + imgEl.setAttributeNS(null, 'width', pf(w)); + imgEl.setAttributeNS(null, 'height', pf(h)); + imgEl.setAttributeNS(null, 'x', '0'); + imgEl.setAttributeNS(null, 'y', pf(-h)); + imgEl.setAttributeNS(null, 'transform', 'scale(' + pf(1 / w) + ' ' + pf(-1 / h) + ')'); + this._ensureTransformGroup().appendChild(imgEl); + }, + paintImageXObject: function SVGGraphics_paintImageXObject(objId) { + var imgData = this.objs.get(objId); + if (!imgData) { + (0, _util.warn)('Dependent image isn\'t ready yet'); + return; + } + this.paintInlineImageXObject(imgData); + }, + paintInlineImageXObject: function SVGGraphics_paintInlineImageXObject(imgData, mask) { + var width = imgData.width; + var height = imgData.height; + var imgSrc = convertImgDataToPng(imgData, this.forceDataSchema, !!mask); + var cliprect = this.svgFactory.createElement('svg:rect'); + cliprect.setAttributeNS(null, 'x', '0'); + cliprect.setAttributeNS(null, 'y', '0'); + cliprect.setAttributeNS(null, 'width', pf(width)); + cliprect.setAttributeNS(null, 'height', pf(height)); + this.current.element = cliprect; + this.clip('nonzero'); + var imgEl = this.svgFactory.createElement('svg:image'); + imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgSrc); + imgEl.setAttributeNS(null, 'x', '0'); + imgEl.setAttributeNS(null, 'y', pf(-height)); + imgEl.setAttributeNS(null, 'width', pf(width) + 'px'); + imgEl.setAttributeNS(null, 'height', pf(height) + 'px'); + imgEl.setAttributeNS(null, 'transform', 'scale(' + pf(1 / width) + ' ' + pf(-1 / height) + ')'); + if (mask) { + mask.appendChild(imgEl); + } else { + this._ensureTransformGroup().appendChild(imgEl); + } }, - time: function time(name) { - consoleTimer[name] = Date.now(); + paintImageMaskXObject: function SVGGraphics_paintImageMaskXObject(imgData) { + var current = this.current; + var width = imgData.width; + var height = imgData.height; + var fillColor = current.fillColor; + current.maskId = 'mask' + maskCount++; + var mask = this.svgFactory.createElement('svg:mask'); + mask.setAttributeNS(null, 'id', current.maskId); + var rect = this.svgFactory.createElement('svg:rect'); + rect.setAttributeNS(null, 'x', '0'); + rect.setAttributeNS(null, 'y', '0'); + rect.setAttributeNS(null, 'width', pf(width)); + rect.setAttributeNS(null, 'height', pf(height)); + rect.setAttributeNS(null, 'fill', fillColor); + rect.setAttributeNS(null, 'mask', 'url(#' + current.maskId + ')'); + this.defs.appendChild(mask); + this._ensureTransformGroup().appendChild(rect); + this.paintInlineImageXObject(imgData, mask); }, - timeEnd: function timeEnd(name) { - var time = consoleTimer[name]; - if (!time) { - throw new Error('Unknown timer name ' + name); + paintFormXObjectBegin: function SVGGraphics_paintFormXObjectBegin(matrix, bbox) { + if (Array.isArray(matrix) && matrix.length === 6) { + this.transform(matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]); + } + if (Array.isArray(bbox) && bbox.length === 4) { + var width = bbox[2] - bbox[0]; + var height = bbox[3] - bbox[1]; + var cliprect = this.svgFactory.createElement('svg:rect'); + cliprect.setAttributeNS(null, 'x', bbox[0]); + cliprect.setAttributeNS(null, 'y', bbox[1]); + cliprect.setAttributeNS(null, 'width', pf(width)); + cliprect.setAttributeNS(null, 'height', pf(height)); + this.current.element = cliprect; + this.clip('nonzero'); + this.endPath(); + } + }, + paintFormXObjectEnd: function SVGGraphics_paintFormXObjectEnd() {}, + _initialize: function _initialize(viewport) { + var svg = this.svgFactory.create(viewport.width, viewport.height); + var definitions = this.svgFactory.createElement('svg:defs'); + svg.appendChild(definitions); + this.defs = definitions; + var rootGroup = this.svgFactory.createElement('svg:g'); + rootGroup.setAttributeNS(null, 'transform', pm(viewport.transform)); + svg.appendChild(rootGroup); + this.svg = rootGroup; + return svg; + }, + + _ensureClipGroup: function SVGGraphics_ensureClipGroup() { + if (!this.current.clipGroup) { + var clipGroup = this.svgFactory.createElement('svg:g'); + clipGroup.setAttributeNS(null, 'clip-path', this.current.activeClipUrl); + this.svg.appendChild(clipGroup); + this.current.clipGroup = clipGroup; + } + return this.current.clipGroup; + }, + _ensureTransformGroup: function SVGGraphics_ensureTransformGroup() { + if (!this.tgrp) { + this.tgrp = this.svgFactory.createElement('svg:g'); + this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix)); + if (this.current.activeClipUrl) { + this._ensureClipGroup().appendChild(this.tgrp); + } else { + this.svg.appendChild(this.tgrp); + } } - this.log('Timer:', name, Date.now() - time); + return this.tgrp; } }; - globalScope.console = workerConsole; - })(); - (function checkConsoleCompatibility() { - if (!hasDOM) { - return; - } - if (!('console' in window)) { - window.console = { - log: function () {}, - error: function () {}, - warn: function () {} - }; - return; - } - if (!('bind' in console.log)) { - console.log = function (fn) { - return function (msg) { - return fn(msg); - }; - }(console.log); - console.error = function (fn) { - return function (msg) { - return fn(msg); - }; - }(console.error); - console.warn = function (fn) { - return function (msg) { - return fn(msg); - }; - }(console.warn); - return; - } - })(); - (function checkOnClickCompatibility() { - function ignoreIfTargetDisabled(event) { - if (isDisabled(event.target)) { - event.stopPropagation(); - } - } - function isDisabled(node) { - return node.disabled || node.parentNode && isDisabled(node.parentNode); - } - if (isOpera) { - document.addEventListener('click', ignoreIfTargetDisabled, true); - } - })(); - (function checkOnBlobSupport() { - if (isIE || isIOSChrome) { - PDFJS.disableCreateObjectURL = true; - } - })(); - (function checkNavigatorLanguage() { - if (typeof navigator === 'undefined') { - return; - } - if ('language' in navigator) { - return; - } - PDFJS.locale = navigator.userLanguage || 'en-US'; - })(); - (function checkRangeRequests() { - if (isSafari || isAndroidPre3 || isChromeWithRangeBug || isIOS) { - PDFJS.disableRange = true; - PDFJS.disableStream = true; + return SVGGraphics; + }(); +} +exports.SVGGraphics = SVGGraphics; + +/***/ }), +/* 148 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.PDFNodeStream = undefined; + +var _regenerator = __w_pdfjs_require__(137); + +var _regenerator2 = _interopRequireDefault(_regenerator); + +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + +var _util = __w_pdfjs_require__(1); + +var _network_utils = __w_pdfjs_require__(149); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var fs = require('fs'); +var http = require('http'); +var https = require('https'); +var url = require('url'); + +var fileUriRegex = /^file:\/\/\/[a-zA-Z]:\//; +function parseUrl(sourceUrl) { + var parsedUrl = url.parse(sourceUrl); + if (parsedUrl.protocol === 'file:' || parsedUrl.host) { + return parsedUrl; + } + if (/^[a-z]:[/\\]/i.test(sourceUrl)) { + return url.parse('file:///' + sourceUrl); + } + if (!parsedUrl.host) { + parsedUrl.protocol = 'file:'; + } + return parsedUrl; +} + +var PDFNodeStream = function () { + function PDFNodeStream(source) { + _classCallCheck(this, PDFNodeStream); + + this.source = source; + this.url = parseUrl(source.url); + this.isHttp = this.url.protocol === 'http:' || this.url.protocol === 'https:'; + this.isFsUrl = this.url.protocol === 'file:'; + this.httpHeaders = this.isHttp && source.httpHeaders || {}; + this._fullRequest = null; + this._rangeRequestReaders = []; + } + + _createClass(PDFNodeStream, [{ + key: 'getFullReader', + value: function getFullReader() { + (0, _util.assert)(!this._fullRequest); + this._fullRequest = this.isFsUrl ? new PDFNodeStreamFsFullReader(this) : new PDFNodeStreamFullReader(this); + return this._fullRequest; } - })(); - (function checkHistoryManipulation() { - if (!hasDOM) { - return; + }, { + key: 'getRangeReader', + value: function getRangeReader(start, end) { + var rangeReader = this.isFsUrl ? new PDFNodeStreamFsRangeReader(this, start, end) : new PDFNodeStreamRangeReader(this, start, end); + this._rangeRequestReaders.push(rangeReader); + return rangeReader; } - if (!history.pushState || isAndroidPre3) { - PDFJS.disableHistory = true; + }, { + key: 'cancelAllRequests', + value: function cancelAllRequests(reason) { + if (this._fullRequest) { + this._fullRequest.cancel(reason); + } + var readers = this._rangeRequestReaders.slice(0); + readers.forEach(function (reader) { + reader.cancel(reason); + }); } - })(); - (function checkSetPresenceInImageData() { - if (!hasDOM) { - return; + }]); + + return PDFNodeStream; +}(); + +var BaseFullReader = function () { + function BaseFullReader(stream) { + _classCallCheck(this, BaseFullReader); + + this._url = stream.url; + this._done = false; + this._storedError = null; + this.onProgress = null; + var source = stream.source; + this._contentLength = source.length; + this._loaded = 0; + this._filename = null; + this._disableRange = source.disableRange || false; + this._rangeChunkSize = source.rangeChunkSize; + if (!this._rangeChunkSize && !this._disableRange) { + this._disableRange = true; } - if (window.CanvasPixelArray) { - if (typeof window.CanvasPixelArray.prototype.set !== 'function') { - window.CanvasPixelArray.prototype.set = function (arr) { - for (var i = 0, ii = this.length; i < ii; i++) { - this[i] = arr[i]; + this._isStreamingSupported = !source.disableStream; + this._isRangeSupported = !source.disableRange; + this._readableStream = null; + this._readCapability = (0, _util.createPromiseCapability)(); + this._headersCapability = (0, _util.createPromiseCapability)(); + } + + _createClass(BaseFullReader, [{ + key: 'read', + value: function () { + var _ref = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee() { + var chunk, buffer; + return _regenerator2.default.wrap(function _callee$(_context) { + while (1) { + switch (_context.prev = _context.next) { + case 0: + _context.next = 2; + return this._readCapability.promise; + + case 2: + if (!this._done) { + _context.next = 4; + break; + } + + return _context.abrupt('return', { + value: undefined, + done: true + }); + + case 4: + if (!this._storedError) { + _context.next = 6; + break; + } + + throw this._storedError; + + case 6: + chunk = this._readableStream.read(); + + if (!(chunk === null)) { + _context.next = 10; + break; + } + + this._readCapability = (0, _util.createPromiseCapability)(); + return _context.abrupt('return', this.read()); + + case 10: + this._loaded += chunk.length; + if (this.onProgress) { + this.onProgress({ + loaded: this._loaded, + total: this._contentLength + }); + } + buffer = new Uint8Array(chunk).buffer; + return _context.abrupt('return', { + value: buffer, + done: false + }); + + case 14: + case 'end': + return _context.stop(); + } } - }; + }, _callee, this); + })); + + function read() { + return _ref.apply(this, arguments); } - } else { - var polyfill = false, - versionMatch; - if (isChrome) { - versionMatch = userAgent.match(/Chrom(e|ium)\/([0-9]+)\./); - polyfill = versionMatch && parseInt(versionMatch[2]) < 21; - } else if (isAndroid) { - polyfill = isAndroidPre5; - } else if (isSafari) { - versionMatch = userAgent.match(/Version\/([0-9]+)\.([0-9]+)\.([0-9]+) Safari\//); - polyfill = versionMatch && parseInt(versionMatch[1]) < 6; - } - if (polyfill) { - var contextPrototype = window.CanvasRenderingContext2D.prototype; - var createImageData = contextPrototype.createImageData; - contextPrototype.createImageData = function (w, h) { - var imageData = createImageData.call(this, w, h); - imageData.data.set = function (arr) { - for (var i = 0, ii = this.length; i < ii; i++) { - this[i] = arr[i]; - } - }; - return imageData; - }; - contextPrototype = null; + + return read; + }() + }, { + key: 'cancel', + value: function cancel(reason) { + if (!this._readableStream) { + this._error(reason); + return; } + this._readableStream.destroy(reason); } - })(); - (function checkRequestAnimationFrame() { - function installFakeAnimationFrameFunctions() { - window.requestAnimationFrame = function (callback) { - return window.setTimeout(callback, 20); - }; - window.cancelAnimationFrame = function (timeoutID) { - window.clearTimeout(timeoutID); - }; - } - if (!hasDOM) { - return; - } - if (isIOS) { - installFakeAnimationFrameFunctions(); - return; + }, { + key: '_error', + value: function _error(reason) { + this._storedError = reason; + this._readCapability.resolve(); } - if ('requestAnimationFrame' in window) { - return; + }, { + key: '_setReadableStream', + value: function _setReadableStream(readableStream) { + var _this = this; + + this._readableStream = readableStream; + readableStream.on('readable', function () { + _this._readCapability.resolve(); + }); + readableStream.on('end', function () { + readableStream.destroy(); + _this._done = true; + _this._readCapability.resolve(); + }); + readableStream.on('error', function (reason) { + _this._error(reason); + }); + if (!this._isStreamingSupported && this._isRangeSupported) { + this._error(new _util.AbortException('streaming is disabled')); + } + if (this._storedError) { + this._readableStream.destroy(this._storedError); + } } - window.requestAnimationFrame = window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame; - if (!('requestAnimationFrame' in window)) { - installFakeAnimationFrameFunctions(); + }, { + key: 'headersReady', + get: function get() { + return this._headersCapability.promise; } - })(); - (function checkCanvasSizeLimitation() { - if (isIOS || isAndroid) { - PDFJS.maxCanvasPixels = 5242880; + }, { + key: 'filename', + get: function get() { + return this._filename; } - })(); - (function checkFullscreenSupport() { - if (!hasDOM) { - return; + }, { + key: 'contentLength', + get: function get() { + return this._contentLength; } - if (isIE && window.parent !== window) { - PDFJS.disableFullscreen = true; + }, { + key: 'isRangeSupported', + get: function get() { + return this._isRangeSupported; } - })(); - (function checkCurrentScript() { - if (!hasDOM) { - return; + }, { + key: 'isStreamingSupported', + get: function get() { + return this._isStreamingSupported; } - if ('currentScript' in document) { - return; + }]); + + return BaseFullReader; +}(); + +var BaseRangeReader = function () { + function BaseRangeReader(stream) { + _classCallCheck(this, BaseRangeReader); + + this._url = stream.url; + this._done = false; + this._storedError = null; + this.onProgress = null; + this._loaded = 0; + this._readableStream = null; + this._readCapability = (0, _util.createPromiseCapability)(); + var source = stream.source; + this._isStreamingSupported = !source.disableStream; + } + + _createClass(BaseRangeReader, [{ + key: 'read', + value: function () { + var _ref2 = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee2() { + var chunk, buffer; + return _regenerator2.default.wrap(function _callee2$(_context2) { + while (1) { + switch (_context2.prev = _context2.next) { + case 0: + _context2.next = 2; + return this._readCapability.promise; + + case 2: + if (!this._done) { + _context2.next = 4; + break; + } + + return _context2.abrupt('return', { + value: undefined, + done: true + }); + + case 4: + if (!this._storedError) { + _context2.next = 6; + break; + } + + throw this._storedError; + + case 6: + chunk = this._readableStream.read(); + + if (!(chunk === null)) { + _context2.next = 10; + break; + } + + this._readCapability = (0, _util.createPromiseCapability)(); + return _context2.abrupt('return', this.read()); + + case 10: + this._loaded += chunk.length; + if (this.onProgress) { + this.onProgress({ loaded: this._loaded }); + } + buffer = new Uint8Array(chunk).buffer; + return _context2.abrupt('return', { + value: buffer, + done: false + }); + + case 14: + case 'end': + return _context2.stop(); + } + } + }, _callee2, this); + })); + + function read() { + return _ref2.apply(this, arguments); + } + + return read; + }() + }, { + key: 'cancel', + value: function cancel(reason) { + if (!this._readableStream) { + this._error(reason); + return; + } + this._readableStream.destroy(reason); } - Object.defineProperty(document, 'currentScript', { - get: function () { - var scripts = document.getElementsByTagName('script'); - return scripts[scripts.length - 1]; - }, - enumerable: true, - configurable: true - }); - })(); - (function checkInputTypeNumberAssign() { - if (!hasDOM) { - return; + }, { + key: '_error', + value: function _error(reason) { + this._storedError = reason; + this._readCapability.resolve(); } - var el = document.createElement('input'); - try { - el.type = 'number'; - } catch (ex) { - var inputProto = el.constructor.prototype; - var typeProperty = Object.getOwnPropertyDescriptor(inputProto, 'type'); - Object.defineProperty(inputProto, 'type', { - get: function () { - return typeProperty.get.call(this); - }, - set: function (value) { - typeProperty.set.call(this, value === 'number' ? 'text' : value); - }, - enumerable: true, - configurable: true + }, { + key: '_setReadableStream', + value: function _setReadableStream(readableStream) { + var _this2 = this; + + this._readableStream = readableStream; + readableStream.on('readable', function () { + _this2._readCapability.resolve(); + }); + readableStream.on('end', function () { + readableStream.destroy(); + _this2._done = true; + _this2._readCapability.resolve(); }); + readableStream.on('error', function (reason) { + _this2._error(reason); + }); + if (this._storedError) { + this._readableStream.destroy(this._storedError); + } } - })(); - (function checkDocumentReadyState() { - if (!hasDOM) { - return; + }, { + key: 'isStreamingSupported', + get: function get() { + return this._isStreamingSupported; } - if (!document.attachEvent) { - return; + }]); + + return BaseRangeReader; +}(); + +function createRequestOptions(url, headers) { + return { + protocol: url.protocol, + auth: url.auth, + host: url.hostname, + port: url.port, + path: url.path, + method: 'GET', + headers: headers + }; +} + +var PDFNodeStreamFullReader = function (_BaseFullReader) { + _inherits(PDFNodeStreamFullReader, _BaseFullReader); + + function PDFNodeStreamFullReader(stream) { + _classCallCheck(this, PDFNodeStreamFullReader); + + var _this3 = _possibleConstructorReturn(this, (PDFNodeStreamFullReader.__proto__ || Object.getPrototypeOf(PDFNodeStreamFullReader)).call(this, stream)); + + var handleResponse = function handleResponse(response) { + if (response.statusCode === 404) { + var error = new _util.MissingPDFException('Missing PDF "' + _this3._url + '".'); + _this3._storedError = error; + _this3._headersCapability.reject(error); + return; + } + _this3._headersCapability.resolve(); + _this3._setReadableStream(response); + var getResponseHeader = function getResponseHeader(name) { + return _this3._readableStream.headers[name.toLowerCase()]; + }; + + var _validateRangeRequest = (0, _network_utils.validateRangeRequestCapabilities)({ + getResponseHeader: getResponseHeader, + isHttp: stream.isHttp, + rangeChunkSize: _this3._rangeChunkSize, + disableRange: _this3._disableRange + }), + allowRangeRequests = _validateRangeRequest.allowRangeRequests, + suggestedLength = _validateRangeRequest.suggestedLength; + + _this3._isRangeSupported = allowRangeRequests; + _this3._contentLength = suggestedLength || _this3._contentLength; + _this3._filename = (0, _network_utils.extractFilenameFromHeader)(getResponseHeader); + }; + _this3._request = null; + if (_this3._url.protocol === 'http:') { + _this3._request = http.request(createRequestOptions(_this3._url, stream.httpHeaders), handleResponse); + } else { + _this3._request = https.request(createRequestOptions(_this3._url, stream.httpHeaders), handleResponse); } - var documentProto = document.constructor.prototype; - var readyStateProto = Object.getOwnPropertyDescriptor(documentProto, 'readyState'); - Object.defineProperty(documentProto, 'readyState', { - get: function () { - var value = readyStateProto.get.call(this); - return value === 'interactive' ? 'loading' : value; - }, - set: function (value) { - readyStateProto.set.call(this, value); - }, - enumerable: true, - configurable: true + _this3._request.on('error', function (reason) { + _this3._storedError = reason; + _this3._headersCapability.reject(reason); }); - })(); - (function checkChildNodeRemove() { - if (!hasDOM) { - return; - } - if (typeof Element.prototype.remove !== 'undefined') { - return; + _this3._request.end(); + return _this3; + } + + return PDFNodeStreamFullReader; +}(BaseFullReader); + +var PDFNodeStreamRangeReader = function (_BaseRangeReader) { + _inherits(PDFNodeStreamRangeReader, _BaseRangeReader); + + function PDFNodeStreamRangeReader(stream, start, end) { + _classCallCheck(this, PDFNodeStreamRangeReader); + + var _this4 = _possibleConstructorReturn(this, (PDFNodeStreamRangeReader.__proto__ || Object.getPrototypeOf(PDFNodeStreamRangeReader)).call(this, stream)); + + _this4._httpHeaders = {}; + for (var property in stream.httpHeaders) { + var value = stream.httpHeaders[property]; + if (typeof value === 'undefined') { + continue; + } + _this4._httpHeaders[property] = value; } - Element.prototype.remove = function () { - if (this.parentNode) { - this.parentNode.removeChild(this); + _this4._httpHeaders['Range'] = 'bytes=' + start + '-' + (end - 1); + var handleResponse = function handleResponse(response) { + if (response.statusCode === 404) { + var error = new _util.MissingPDFException('Missing PDF "' + _this4._url + '".'); + _this4._storedError = error; + return; } + _this4._setReadableStream(response); }; - })(); - (function checkPromise() { - if (globalScope.Promise) { - if (typeof globalScope.Promise.all !== 'function') { - globalScope.Promise.all = function (iterable) { - var count = 0, - results = [], - resolve, - reject; - var promise = new globalScope.Promise(function (resolve_, reject_) { - resolve = resolve_; - reject = reject_; - }); - iterable.forEach(function (p, i) { - count++; - p.then(function (result) { - results[i] = result; - count--; - if (count === 0) { - resolve(results); - } - }, reject); - }); - if (count === 0) { - resolve(results); - } - return promise; - }; - } - if (typeof globalScope.Promise.resolve !== 'function') { - globalScope.Promise.resolve = function (value) { - return new globalScope.Promise(function (resolve) { - resolve(value); - }); - }; - } - if (typeof globalScope.Promise.reject !== 'function') { - globalScope.Promise.reject = function (reason) { - return new globalScope.Promise(function (resolve, reject) { - reject(reason); - }); - }; - } - if (typeof globalScope.Promise.prototype.catch !== 'function') { - globalScope.Promise.prototype.catch = function (onReject) { - return globalScope.Promise.prototype.then(undefined, onReject); - }; - } - return; + _this4._request = null; + if (_this4._url.protocol === 'http:') { + _this4._request = http.request(createRequestOptions(_this4._url, _this4._httpHeaders), handleResponse); + } else { + _this4._request = https.request(createRequestOptions(_this4._url, _this4._httpHeaders), handleResponse); } - var STATUS_PENDING = 0; - var STATUS_RESOLVED = 1; - var STATUS_REJECTED = 2; - var REJECTION_TIMEOUT = 500; - var HandlerManager = { - handlers: [], - running: false, - unhandledRejections: [], - pendingRejectionCheck: false, - scheduleHandlers: function scheduleHandlers(promise) { - if (promise._status === STATUS_PENDING) { - return; - } - this.handlers = this.handlers.concat(promise._handlers); - promise._handlers = []; - if (this.running) { - return; - } - this.running = true; - setTimeout(this.runHandlers.bind(this), 0); - }, - runHandlers: function runHandlers() { - var RUN_TIMEOUT = 1; - var timeoutAt = Date.now() + RUN_TIMEOUT; - while (this.handlers.length > 0) { - var handler = this.handlers.shift(); - var nextStatus = handler.thisPromise._status; - var nextValue = handler.thisPromise._value; - try { - if (nextStatus === STATUS_RESOLVED) { - if (typeof handler.onResolve === 'function') { - nextValue = handler.onResolve(nextValue); - } - } else if (typeof handler.onReject === 'function') { - nextValue = handler.onReject(nextValue); - nextStatus = STATUS_RESOLVED; - if (handler.thisPromise._unhandledRejection) { - this.removeUnhandeledRejection(handler.thisPromise); - } - } - } catch (ex) { - nextStatus = STATUS_REJECTED; - nextValue = ex; - } - handler.nextPromise._updateStatus(nextStatus, nextValue); - if (Date.now() >= timeoutAt) { - break; - } - } - if (this.handlers.length > 0) { - setTimeout(this.runHandlers.bind(this), 0); - return; - } - this.running = false; - }, - addUnhandledRejection: function addUnhandledRejection(promise) { - this.unhandledRejections.push({ - promise: promise, - time: Date.now() - }); - this.scheduleRejectionCheck(); - }, - removeUnhandeledRejection: function removeUnhandeledRejection(promise) { - promise._unhandledRejection = false; - for (var i = 0; i < this.unhandledRejections.length; i++) { - if (this.unhandledRejections[i].promise === promise) { - this.unhandledRejections.splice(i); - i--; - } - } - }, - scheduleRejectionCheck: function scheduleRejectionCheck() { - if (this.pendingRejectionCheck) { - return; + _this4._request.on('error', function (reason) { + _this4._storedError = reason; + }); + _this4._request.end(); + return _this4; + } + + return PDFNodeStreamRangeReader; +}(BaseRangeReader); + +var PDFNodeStreamFsFullReader = function (_BaseFullReader2) { + _inherits(PDFNodeStreamFsFullReader, _BaseFullReader2); + + function PDFNodeStreamFsFullReader(stream) { + _classCallCheck(this, PDFNodeStreamFsFullReader); + + var _this5 = _possibleConstructorReturn(this, (PDFNodeStreamFsFullReader.__proto__ || Object.getPrototypeOf(PDFNodeStreamFsFullReader)).call(this, stream)); + + var path = decodeURIComponent(_this5._url.path); + if (fileUriRegex.test(_this5._url.href)) { + path = path.replace(/^\//, ''); + } + fs.lstat(path, function (error, stat) { + if (error) { + if (error.code === 'ENOENT') { + error = new _util.MissingPDFException('Missing PDF "' + path + '".'); } - this.pendingRejectionCheck = true; - setTimeout(function rejectionCheck() { - this.pendingRejectionCheck = false; - var now = Date.now(); - for (var i = 0; i < this.unhandledRejections.length; i++) { - if (now - this.unhandledRejections[i].time > REJECTION_TIMEOUT) { - var unhandled = this.unhandledRejections[i].promise._value; - var msg = 'Unhandled rejection: ' + unhandled; - if (unhandled.stack) { - msg += '\n' + unhandled.stack; - } - try { - throw new Error(msg); - } catch (_) { - console.warn(msg); - } - this.unhandledRejections.splice(i); - i--; - } - } - if (this.unhandledRejections.length) { - this.scheduleRejectionCheck(); - } - }.bind(this), REJECTION_TIMEOUT); + _this5._storedError = error; + _this5._headersCapability.reject(error); + return; + } + _this5._contentLength = stat.size; + _this5._setReadableStream(fs.createReadStream(path)); + _this5._headersCapability.resolve(); + }); + return _this5; + } + + return PDFNodeStreamFsFullReader; +}(BaseFullReader); + +var PDFNodeStreamFsRangeReader = function (_BaseRangeReader2) { + _inherits(PDFNodeStreamFsRangeReader, _BaseRangeReader2); + + function PDFNodeStreamFsRangeReader(stream, start, end) { + _classCallCheck(this, PDFNodeStreamFsRangeReader); + + var _this6 = _possibleConstructorReturn(this, (PDFNodeStreamFsRangeReader.__proto__ || Object.getPrototypeOf(PDFNodeStreamFsRangeReader)).call(this, stream)); + + var path = decodeURIComponent(_this6._url.path); + if (fileUriRegex.test(_this6._url.href)) { + path = path.replace(/^\//, ''); + } + _this6._setReadableStream(fs.createReadStream(path, { + start: start, + end: end - 1 + })); + return _this6; + } + + return PDFNodeStreamFsRangeReader; +}(BaseRangeReader); + +exports.PDFNodeStream = PDFNodeStream; + +/***/ }), +/* 149 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.validateResponseStatus = exports.validateRangeRequestCapabilities = exports.extractFilenameFromHeader = exports.createResponseStatusError = undefined; + +var _util = __w_pdfjs_require__(1); + +var _content_disposition = __w_pdfjs_require__(150); + +function validateRangeRequestCapabilities(_ref) { + var getResponseHeader = _ref.getResponseHeader, + isHttp = _ref.isHttp, + rangeChunkSize = _ref.rangeChunkSize, + disableRange = _ref.disableRange; + + (0, _util.assert)(rangeChunkSize > 0, 'Range chunk size must be larger than zero'); + var returnValues = { + allowRangeRequests: false, + suggestedLength: undefined + }; + var length = parseInt(getResponseHeader('Content-Length'), 10); + if (!Number.isInteger(length)) { + return returnValues; + } + returnValues.suggestedLength = length; + if (length <= 2 * rangeChunkSize) { + return returnValues; + } + if (disableRange || !isHttp) { + return returnValues; + } + if (getResponseHeader('Accept-Ranges') !== 'bytes') { + return returnValues; + } + var contentEncoding = getResponseHeader('Content-Encoding') || 'identity'; + if (contentEncoding !== 'identity') { + return returnValues; + } + returnValues.allowRangeRequests = true; + return returnValues; +} +function extractFilenameFromHeader(getResponseHeader) { + var contentDisposition = getResponseHeader('Content-Disposition'); + if (contentDisposition) { + var filename = (0, _content_disposition.getFilenameFromContentDispositionHeader)(contentDisposition); + if (/\.pdf$/i.test(filename)) { + return filename; + } + } + return null; +} +function createResponseStatusError(status, url) { + if (status === 404 || status === 0 && /^file:/.test(url)) { + return new _util.MissingPDFException('Missing PDF "' + url + '".'); + } + return new _util.UnexpectedResponseException('Unexpected server response (' + status + ') while retrieving PDF "' + url + '".', status); +} +function validateResponseStatus(status) { + return status === 200 || status === 206; +} +exports.createResponseStatusError = createResponseStatusError; +exports.extractFilenameFromHeader = extractFilenameFromHeader; +exports.validateRangeRequestCapabilities = validateRangeRequestCapabilities; +exports.validateResponseStatus = validateResponseStatus; + +/***/ }), +/* 150 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); + +function getFilenameFromContentDispositionHeader(contentDisposition) { + var needsEncodingFixup = true; + var tmp = toParamRegExp('filename\\*', 'i').exec(contentDisposition); + if (tmp) { + tmp = tmp[1]; + var filename = rfc2616unquote(tmp); + filename = unescape(filename); + filename = rfc5987decode(filename); + filename = rfc2047decode(filename); + return fixupEncoding(filename); + } + tmp = rfc2231getparam(contentDisposition); + if (tmp) { + var _filename = rfc2047decode(tmp); + return fixupEncoding(_filename); + } + tmp = toParamRegExp('filename', 'i').exec(contentDisposition); + if (tmp) { + tmp = tmp[1]; + var _filename2 = rfc2616unquote(tmp); + _filename2 = rfc2047decode(_filename2); + return fixupEncoding(_filename2); + } + function toParamRegExp(attributePattern, flags) { + return new RegExp('(?:^|;)\\s*' + attributePattern + '\\s*=\\s*' + '(' + '[^";\\s][^;\\s]*' + '|' + '"(?:[^"\\\\]|\\\\"?)+"?' + ')', flags); + } + function textdecode(encoding, value) { + if (encoding) { + if (!/^[\x00-\xFF]+$/.test(value)) { + return value; } - }; - var Promise = function Promise(resolver) { - this._status = STATUS_PENDING; - this._handlers = []; try { - resolver.call(this, this._resolve.bind(this), this._reject.bind(this)); + var decoder = new TextDecoder(encoding, { fatal: true }); + var bytes = new Array(value.length); + for (var i = 0; i < value.length; ++i) { + bytes[i] = value.charCodeAt(i); + } + value = decoder.decode(new Uint8Array(bytes)); + needsEncodingFixup = false; } catch (e) { - this._reject(e); - } - }; - Promise.all = function Promise_all(promises) { - var resolveAll, rejectAll; - var deferred = new Promise(function (resolve, reject) { - resolveAll = resolve; - rejectAll = reject; - }); - var unresolved = promises.length; - var results = []; - if (unresolved === 0) { - resolveAll(results); - return deferred; - } - function reject(reason) { - if (deferred._status === STATUS_REJECTED) { - return; + if (/^utf-?8$/i.test(encoding)) { + try { + value = decodeURIComponent(escape(value)); + needsEncodingFixup = false; + } catch (err) {} } - results = []; - rejectAll(reason); } - for (var i = 0, ii = promises.length; i < ii; ++i) { - var promise = promises[i]; - var resolve = function (i) { - return function (value) { - if (deferred._status === STATUS_REJECTED) { - return; - } - results[i] = value; - unresolved--; - if (unresolved === 0) { - resolveAll(results); - } - }; - }(i); - if (Promise.isPromise(promise)) { - promise.then(resolve, reject); - } else { - resolve(promise); - } + } + return value; + } + function fixupEncoding(value) { + if (needsEncodingFixup && /[\x80-\xff]/.test(value)) { + value = textdecode('utf-8', value); + if (needsEncodingFixup) { + value = textdecode('iso-8859-1', value); } - return deferred; - }; - Promise.isPromise = function Promise_isPromise(value) { - return value && typeof value.then === 'function'; - }; - Promise.resolve = function Promise_resolve(value) { - return new Promise(function (resolve) { - resolve(value); - }); - }; - Promise.reject = function Promise_reject(reason) { - return new Promise(function (resolve, reject) { - reject(reason); - }); - }; - Promise.prototype = { - _status: null, - _value: null, - _handlers: null, - _unhandledRejection: null, - _updateStatus: function Promise__updateStatus(status, value) { - if (this._status === STATUS_RESOLVED || this._status === STATUS_REJECTED) { - return; + } + return value; + } + function rfc2231getparam(contentDisposition) { + var matches = [], + match = void 0; + var iter = toParamRegExp('filename\\*((?!0\\d)\\d+)(\\*?)', 'ig'); + while ((match = iter.exec(contentDisposition)) !== null) { + var _match = match, + _match2 = _slicedToArray(_match, 4), + n = _match2[1], + quot = _match2[2], + part = _match2[3]; + + n = parseInt(n, 10); + if (n in matches) { + if (n === 0) { + break; } - if (status === STATUS_RESOLVED && Promise.isPromise(value)) { - value.then(this._updateStatus.bind(this, STATUS_RESOLVED), this._updateStatus.bind(this, STATUS_REJECTED)); - return; + continue; + } + matches[n] = [quot, part]; + } + var parts = []; + for (var _n = 0; _n < matches.length; ++_n) { + if (!(_n in matches)) { + break; + } + + var _matches$_n = _slicedToArray(matches[_n], 2), + _quot = _matches$_n[0], + _part = _matches$_n[1]; + + _part = rfc2616unquote(_part); + if (_quot) { + _part = unescape(_part); + if (_n === 0) { + _part = rfc5987decode(_part); } - this._status = status; - this._value = value; - if (status === STATUS_REJECTED && this._handlers.length === 0) { - this._unhandledRejection = true; - HandlerManager.addUnhandledRejection(this); + } + parts.push(_part); + } + return parts.join(''); + } + function rfc2616unquote(value) { + if (value.charAt(0) === '"') { + var parts = value.slice(1).split('\\"'); + for (var i = 0; i < parts.length; ++i) { + var quotindex = parts[i].indexOf('"'); + if (quotindex !== -1) { + parts[i] = parts[i].slice(0, quotindex); + parts.length = i + 1; } - HandlerManager.scheduleHandlers(this); - }, - _resolve: function Promise_resolve(value) { - this._updateStatus(STATUS_RESOLVED, value); - }, - _reject: function Promise_reject(reason) { - this._updateStatus(STATUS_REJECTED, reason); - }, - then: function Promise_then(onResolve, onReject) { - var nextPromise = new Promise(function (resolve, reject) { - this.resolve = resolve; - this.reject = reject; - }); - this._handlers.push({ - thisPromise: this, - onResolve: onResolve, - onReject: onReject, - nextPromise: nextPromise - }); - HandlerManager.scheduleHandlers(this); - return nextPromise; - }, - catch: function Promise_catch(onReject) { - return this.then(undefined, onReject); + parts[i] = parts[i].replace(/\\(.)/g, '$1'); } - }; - globalScope.Promise = Promise; - })(); - (function checkWeakMap() { - if (globalScope.WeakMap) { - return; + value = parts.join('"'); + } + return value; + } + function rfc5987decode(extvalue) { + var encodingend = extvalue.indexOf('\''); + if (encodingend === -1) { + return extvalue; } - var id = 0; - function WeakMap() { - this.id = '$weakmap' + id++; + var encoding = extvalue.slice(0, encodingend); + var langvalue = extvalue.slice(encodingend + 1); + var value = langvalue.replace(/^[^']*'/, ''); + return textdecode(encoding, value); + } + function rfc2047decode(value) { + if (value.slice(0, 2) !== '=?' || /[\x00-\x19\x80-\xff]/.test(value)) { + return value; } - WeakMap.prototype = { - has: function (obj) { - return !!Object.getOwnPropertyDescriptor(obj, this.id); - }, - get: function (obj, defaultValue) { - return this.has(obj) ? obj[this.id] : defaultValue; - }, - set: function (obj, value) { - Object.defineProperty(obj, this.id, { - value: value, - enumerable: false, - configurable: true + return value.replace(/=\?([\w-]*)\?([QqBb])\?((?:[^?]|\?(?!=))*)\?=/g, function (_, charset, encoding, text) { + if (encoding === 'q' || encoding === 'Q') { + text = text.replace(/_/g, ' '); + text = text.replace(/=([0-9a-fA-F]{2})/g, function (_, hex) { + return String.fromCharCode(parseInt(hex, 16)); }); - }, - delete: function (obj) { - delete obj[this.id]; + return textdecode(charset, text); } - }; - globalScope.WeakMap = WeakMap; - })(); - (function checkURLConstructor() { - var hasWorkingUrl = false; - try { - if (typeof URL === 'function' && typeof URL.prototype === 'object' && 'origin' in URL.prototype) { - var u = new URL('b', 'http://a'); - u.pathname = 'c%20d'; - hasWorkingUrl = u.href === 'http://a/c%20d'; + try { + text = atob(text); + } catch (e) {} + return textdecode(charset, text); + }); + } + return ''; +} +exports.getFilenameFromContentDispositionHeader = getFilenameFromContentDispositionHeader; + +/***/ }), +/* 151 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.PDFFetchStream = undefined; + +var _regenerator = __w_pdfjs_require__(137); + +var _regenerator2 = _interopRequireDefault(_regenerator); + +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + +var _util = __w_pdfjs_require__(1); + +var _network_utils = __w_pdfjs_require__(149); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function createFetchOptions(headers, withCredentials, abortController) { + return { + method: 'GET', + headers: headers, + signal: abortController && abortController.signal, + mode: 'cors', + credentials: withCredentials ? 'include' : 'same-origin', + redirect: 'follow' + }; +} + +var PDFFetchStream = function () { + function PDFFetchStream(source) { + _classCallCheck(this, PDFFetchStream); + + this.source = source; + this.isHttp = /^https?:/i.test(source.url); + this.httpHeaders = this.isHttp && source.httpHeaders || {}; + this._fullRequestReader = null; + this._rangeRequestReaders = []; + } + + _createClass(PDFFetchStream, [{ + key: 'getFullReader', + value: function getFullReader() { + (0, _util.assert)(!this._fullRequestReader); + this._fullRequestReader = new PDFFetchStreamReader(this); + return this._fullRequestReader; + } + }, { + key: 'getRangeReader', + value: function getRangeReader(begin, end) { + var reader = new PDFFetchStreamRangeReader(this, begin, end); + this._rangeRequestReaders.push(reader); + return reader; + } + }, { + key: 'cancelAllRequests', + value: function cancelAllRequests(reason) { + if (this._fullRequestReader) { + this._fullRequestReader.cancel(reason); + } + var readers = this._rangeRequestReaders.slice(0); + readers.forEach(function (reader) { + reader.cancel(reason); + }); + } + }]); + + return PDFFetchStream; +}(); + +var PDFFetchStreamReader = function () { + function PDFFetchStreamReader(stream) { + var _this = this; + + _classCallCheck(this, PDFFetchStreamReader); + + this._stream = stream; + this._reader = null; + this._loaded = 0; + this._filename = null; + var source = stream.source; + this._withCredentials = source.withCredentials; + this._contentLength = source.length; + this._headersCapability = (0, _util.createPromiseCapability)(); + this._disableRange = source.disableRange || false; + this._rangeChunkSize = source.rangeChunkSize; + if (!this._rangeChunkSize && !this._disableRange) { + this._disableRange = true; + } + if (typeof AbortController !== 'undefined') { + this._abortController = new AbortController(); + } + this._isStreamingSupported = !source.disableStream; + this._isRangeSupported = !source.disableRange; + this._headers = new Headers(); + for (var property in this._stream.httpHeaders) { + var value = this._stream.httpHeaders[property]; + if (typeof value === 'undefined') { + continue; } - } catch (e) {} - if (hasWorkingUrl) { - return; + this._headers.append(property, value); } - var relative = Object.create(null); - relative['ftp'] = 21; - relative['file'] = 0; - relative['gopher'] = 70; - relative['http'] = 80; - relative['https'] = 443; - relative['ws'] = 80; - relative['wss'] = 443; - var relativePathDotMapping = Object.create(null); - relativePathDotMapping['%2e'] = '.'; - relativePathDotMapping['.%2e'] = '..'; - relativePathDotMapping['%2e.'] = '..'; - relativePathDotMapping['%2e%2e'] = '..'; - function isRelativeScheme(scheme) { - return relative[scheme] !== undefined; - } - function invalid() { - clear.call(this); - this._isInvalid = true; - } - function IDNAToASCII(h) { - if (h === '') { - invalid.call(this); - } - return h.toLowerCase(); - } - function percentEscape(c) { - var unicode = c.charCodeAt(0); - if (unicode > 0x20 && unicode < 0x7F && [0x22, 0x23, 0x3C, 0x3E, 0x3F, 0x60].indexOf(unicode) === -1) { - return c; - } - return encodeURIComponent(c); - } - function percentEscapeQuery(c) { - var unicode = c.charCodeAt(0); - if (unicode > 0x20 && unicode < 0x7F && [0x22, 0x23, 0x3C, 0x3E, 0x60].indexOf(unicode) === -1) { - return c; - } - return encodeURIComponent(c); - } - var EOF, - ALPHA = /[a-zA-Z]/, - ALPHANUMERIC = /[a-zA-Z0-9\+\-\.]/; - function parse(input, stateOverride, base) { - function err(message) { - errors.push(message); - } - var state = stateOverride || 'scheme start', - cursor = 0, - buffer = '', - seenAt = false, - seenBracket = false, - errors = []; - loop: while ((input[cursor - 1] !== EOF || cursor === 0) && !this._isInvalid) { - var c = input[cursor]; - switch (state) { - case 'scheme start': - if (c && ALPHA.test(c)) { - buffer += c.toLowerCase(); - state = 'scheme'; - } else if (!stateOverride) { - buffer = ''; - state = 'no scheme'; - continue; - } else { - err('Invalid scheme.'); - break loop; - } - break; - case 'scheme': - if (c && ALPHANUMERIC.test(c)) { - buffer += c.toLowerCase(); - } else if (c === ':') { - this._scheme = buffer; - buffer = ''; - if (stateOverride) { - break loop; - } - if (isRelativeScheme(this._scheme)) { - this._isRelative = true; - } - if (this._scheme === 'file') { - state = 'relative'; - } else if (this._isRelative && base && base._scheme === this._scheme) { - state = 'relative or authority'; - } else if (this._isRelative) { - state = 'authority first slash'; - } else { - state = 'scheme data'; - } - } else if (!stateOverride) { - buffer = ''; - cursor = 0; - state = 'no scheme'; - continue; - } else if (c === EOF) { - break loop; - } else { - err('Code point not allowed in scheme: ' + c); - break loop; - } - break; - case 'scheme data': - if (c === '?') { - this._query = '?'; - state = 'query'; - } else if (c === '#') { - this._fragment = '#'; - state = 'fragment'; - } else { - if (c !== EOF && c !== '\t' && c !== '\n' && c !== '\r') { - this._schemeData += percentEscape(c); - } - } - break; - case 'no scheme': - if (!base || !isRelativeScheme(base._scheme)) { - err('Missing scheme.'); - invalid.call(this); - } else { - state = 'relative'; - continue; - } - break; - case 'relative or authority': - if (c === '/' && input[cursor + 1] === '/') { - state = 'authority ignore slashes'; - } else { - err('Expected /, got: ' + c); - state = 'relative'; - continue; - } - break; - case 'relative': - this._isRelative = true; - if (this._scheme !== 'file') { - this._scheme = base._scheme; - } - if (c === EOF) { - this._host = base._host; - this._port = base._port; - this._path = base._path.slice(); - this._query = base._query; - this._username = base._username; - this._password = base._password; - break loop; - } else if (c === '/' || c === '\\') { - if (c === '\\') { - err('\\ is an invalid code point.'); - } - state = 'relative slash'; - } else if (c === '?') { - this._host = base._host; - this._port = base._port; - this._path = base._path.slice(); - this._query = '?'; - this._username = base._username; - this._password = base._password; - state = 'query'; - } else if (c === '#') { - this._host = base._host; - this._port = base._port; - this._path = base._path.slice(); - this._query = base._query; - this._fragment = '#'; - this._username = base._username; - this._password = base._password; - state = 'fragment'; - } else { - var nextC = input[cursor + 1]; - var nextNextC = input[cursor + 2]; - if (this._scheme !== 'file' || !ALPHA.test(c) || nextC !== ':' && nextC !== '|' || nextNextC !== EOF && nextNextC !== '/' && nextNextC !== '\\' && nextNextC !== '?' && nextNextC !== '#') { - this._host = base._host; - this._port = base._port; - this._username = base._username; - this._password = base._password; - this._path = base._path.slice(); - this._path.pop(); - } - state = 'relative path'; - continue; - } - break; - case 'relative slash': - if (c === '/' || c === '\\') { - if (c === '\\') { - err('\\ is an invalid code point.'); - } - if (this._scheme === 'file') { - state = 'file host'; - } else { - state = 'authority ignore slashes'; - } - } else { - if (this._scheme !== 'file') { - this._host = base._host; - this._port = base._port; - this._username = base._username; - this._password = base._password; - } - state = 'relative path'; - continue; - } - break; - case 'authority first slash': - if (c === '/') { - state = 'authority second slash'; - } else { - err('Expected \'/\', got: ' + c); - state = 'authority ignore slashes'; - continue; - } - break; - case 'authority second slash': - state = 'authority ignore slashes'; - if (c !== '/') { - err('Expected \'/\', got: ' + c); - continue; - } - break; - case 'authority ignore slashes': - if (c !== '/' && c !== '\\') { - state = 'authority'; - continue; - } else { - err('Expected authority, got: ' + c); - } - break; - case 'authority': - if (c === '@') { - if (seenAt) { - err('@ already seen.'); - buffer += '%40'; - } - seenAt = true; - for (var i = 0; i < buffer.length; i++) { - var cp = buffer[i]; - if (cp === '\t' || cp === '\n' || cp === '\r') { - err('Invalid whitespace in authority.'); - continue; - } - if (cp === ':' && this._password === null) { - this._password = ''; - continue; - } - var tempC = percentEscape(cp); - if (this._password !== null) { - this._password += tempC; - } else { - this._username += tempC; + var url = source.url; + fetch(url, createFetchOptions(this._headers, this._withCredentials, this._abortController)).then(function (response) { + if (!(0, _network_utils.validateResponseStatus)(response.status)) { + throw (0, _network_utils.createResponseStatusError)(response.status, url); + } + _this._reader = response.body.getReader(); + _this._headersCapability.resolve(); + var getResponseHeader = function getResponseHeader(name) { + return response.headers.get(name); + }; + + var _validateRangeRequest = (0, _network_utils.validateRangeRequestCapabilities)({ + getResponseHeader: getResponseHeader, + isHttp: _this._stream.isHttp, + rangeChunkSize: _this._rangeChunkSize, + disableRange: _this._disableRange + }), + allowRangeRequests = _validateRangeRequest.allowRangeRequests, + suggestedLength = _validateRangeRequest.suggestedLength; + + _this._isRangeSupported = allowRangeRequests; + _this._contentLength = suggestedLength || _this._contentLength; + _this._filename = (0, _network_utils.extractFilenameFromHeader)(getResponseHeader); + if (!_this._isStreamingSupported && _this._isRangeSupported) { + _this.cancel(new _util.AbortException('streaming is disabled')); + } + }).catch(this._headersCapability.reject); + this.onProgress = null; + } + + _createClass(PDFFetchStreamReader, [{ + key: 'read', + value: function () { + var _ref = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee() { + var _ref2, value, done, buffer; + + return _regenerator2.default.wrap(function _callee$(_context) { + while (1) { + switch (_context.prev = _context.next) { + case 0: + _context.next = 2; + return this._headersCapability.promise; + + case 2: + _context.next = 4; + return this._reader.read(); + + case 4: + _ref2 = _context.sent; + value = _ref2.value; + done = _ref2.done; + + if (!done) { + _context.next = 9; + break; } - } - buffer = ''; - } else if (c === EOF || c === '/' || c === '\\' || c === '?' || c === '#') { - cursor -= buffer.length; - buffer = ''; - state = 'host'; - continue; - } else { - buffer += c; - } - break; - case 'file host': - if (c === EOF || c === '/' || c === '\\' || c === '?' || c === '#') { - if (buffer.length === 2 && ALPHA.test(buffer[0]) && (buffer[1] === ':' || buffer[1] === '|')) { - state = 'relative path'; - } else if (buffer.length === 0) { - state = 'relative path start'; - } else { - this._host = IDNAToASCII.call(this, buffer); - buffer = ''; - state = 'relative path start'; - } - continue; - } else if (c === '\t' || c === '\n' || c === '\r') { - err('Invalid whitespace in file host.'); - } else { - buffer += c; - } - break; - case 'host': - case 'hostname': - if (c === ':' && !seenBracket) { - this._host = IDNAToASCII.call(this, buffer); - buffer = ''; - state = 'port'; - if (stateOverride === 'hostname') { - break loop; - } - } else if (c === EOF || c === '/' || c === '\\' || c === '?' || c === '#') { - this._host = IDNAToASCII.call(this, buffer); - buffer = ''; - state = 'relative path start'; - if (stateOverride) { - break loop; - } - continue; - } else if (c !== '\t' && c !== '\n' && c !== '\r') { - if (c === '[') { - seenBracket = true; - } else if (c === ']') { - seenBracket = false; - } - buffer += c; - } else { - err('Invalid code point in host/hostname: ' + c); - } - break; - case 'port': - if (/[0-9]/.test(c)) { - buffer += c; - } else if (c === EOF || c === '/' || c === '\\' || c === '?' || c === '#' || stateOverride) { - if (buffer !== '') { - var temp = parseInt(buffer, 10); - if (temp !== relative[this._scheme]) { - this._port = temp + ''; + + return _context.abrupt('return', { + value: value, + done: done + }); + + case 9: + this._loaded += value.byteLength; + if (this.onProgress) { + this.onProgress({ + loaded: this._loaded, + total: this._contentLength + }); } - buffer = ''; - } - if (stateOverride) { - break loop; - } - state = 'relative path start'; - continue; - } else if (c === '\t' || c === '\n' || c === '\r') { - err('Invalid code point in port: ' + c); - } else { - invalid.call(this); - } - break; - case 'relative path start': - if (c === '\\') { - err('\'\\\' not allowed in path.'); - } - state = 'relative path'; - if (c !== '/' && c !== '\\') { - continue; + buffer = new Uint8Array(value).buffer; + return _context.abrupt('return', { + value: buffer, + done: false + }); + + case 13: + case 'end': + return _context.stop(); } - break; - case 'relative path': - if (c === EOF || c === '/' || c === '\\' || !stateOverride && (c === '?' || c === '#')) { - if (c === '\\') { - err('\\ not allowed in relative path.'); - } - var tmp; - if (tmp = relativePathDotMapping[buffer.toLowerCase()]) { - buffer = tmp; - } - if (buffer === '..') { - this._path.pop(); - if (c !== '/' && c !== '\\') { - this._path.push(''); + } + }, _callee, this); + })); + + function read() { + return _ref.apply(this, arguments); + } + + return read; + }() + }, { + key: 'cancel', + value: function cancel(reason) { + if (this._reader) { + this._reader.cancel(reason); + } + if (this._abortController) { + this._abortController.abort(); + } + } + }, { + key: 'headersReady', + get: function get() { + return this._headersCapability.promise; + } + }, { + key: 'filename', + get: function get() { + return this._filename; + } + }, { + key: 'contentLength', + get: function get() { + return this._contentLength; + } + }, { + key: 'isRangeSupported', + get: function get() { + return this._isRangeSupported; + } + }, { + key: 'isStreamingSupported', + get: function get() { + return this._isStreamingSupported; + } + }]); + + return PDFFetchStreamReader; +}(); + +var PDFFetchStreamRangeReader = function () { + function PDFFetchStreamRangeReader(stream, begin, end) { + var _this2 = this; + + _classCallCheck(this, PDFFetchStreamRangeReader); + + this._stream = stream; + this._reader = null; + this._loaded = 0; + var source = stream.source; + this._withCredentials = source.withCredentials; + this._readCapability = (0, _util.createPromiseCapability)(); + this._isStreamingSupported = !source.disableStream; + if (typeof AbortController !== 'undefined') { + this._abortController = new AbortController(); + } + this._headers = new Headers(); + for (var property in this._stream.httpHeaders) { + var value = this._stream.httpHeaders[property]; + if (typeof value === 'undefined') { + continue; + } + this._headers.append(property, value); + } + var rangeStr = begin + '-' + (end - 1); + this._headers.append('Range', 'bytes=' + rangeStr); + var url = source.url; + fetch(url, createFetchOptions(this._headers, this._withCredentials, this._abortController)).then(function (response) { + if (!(0, _network_utils.validateResponseStatus)(response.status)) { + throw (0, _network_utils.createResponseStatusError)(response.status, url); + } + _this2._readCapability.resolve(); + _this2._reader = response.body.getReader(); + }); + this.onProgress = null; + } + + _createClass(PDFFetchStreamRangeReader, [{ + key: 'read', + value: function () { + var _ref3 = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee2() { + var _ref4, value, done, buffer; + + return _regenerator2.default.wrap(function _callee2$(_context2) { + while (1) { + switch (_context2.prev = _context2.next) { + case 0: + _context2.next = 2; + return this._readCapability.promise; + + case 2: + _context2.next = 4; + return this._reader.read(); + + case 4: + _ref4 = _context2.sent; + value = _ref4.value; + done = _ref4.done; + + if (!done) { + _context2.next = 9; + break; } - } else if (buffer === '.' && c !== '/' && c !== '\\') { - this._path.push(''); - } else if (buffer !== '.') { - if (this._scheme === 'file' && this._path.length === 0 && buffer.length === 2 && ALPHA.test(buffer[0]) && buffer[1] === '|') { - buffer = buffer[0] + ':'; + + return _context2.abrupt('return', { + value: value, + done: done + }); + + case 9: + this._loaded += value.byteLength; + if (this.onProgress) { + this.onProgress({ loaded: this._loaded }); } - this._path.push(buffer); - } - buffer = ''; - if (c === '?') { - this._query = '?'; - state = 'query'; - } else if (c === '#') { - this._fragment = '#'; - state = 'fragment'; - } - } else if (c !== '\t' && c !== '\n' && c !== '\r') { - buffer += percentEscape(c); - } - break; - case 'query': - if (!stateOverride && c === '#') { - this._fragment = '#'; - state = 'fragment'; - } else if (c !== EOF && c !== '\t' && c !== '\n' && c !== '\r') { - this._query += percentEscapeQuery(c); - } - break; - case 'fragment': - if (c !== EOF && c !== '\t' && c !== '\n' && c !== '\r') { - this._fragment += c; + buffer = new Uint8Array(value).buffer; + return _context2.abrupt('return', { + value: buffer, + done: false + }); + + case 13: + case 'end': + return _context2.stop(); } - break; - } - cursor++; + } + }, _callee2, this); + })); + + function read() { + return _ref3.apply(this, arguments); + } + + return read; + }() + }, { + key: 'cancel', + value: function cancel(reason) { + if (this._reader) { + this._reader.cancel(reason); + } + if (this._abortController) { + this._abortController.abort(); } } - function clear() { - this._scheme = ''; - this._schemeData = ''; - this._username = ''; - this._password = null; - this._host = ''; - this._port = ''; - this._path = []; - this._query = ''; - this._fragment = ''; - this._isInvalid = false; - this._isRelative = false; + }, { + key: 'isStreamingSupported', + get: function get() { + return this._isStreamingSupported; + } + }]); + + return PDFFetchStreamRangeReader; +}(); + +exports.PDFFetchStream = PDFFetchStream; + +/***/ }), +/* 152 */ +/***/ (function(module, exports, __w_pdfjs_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.NetworkManager = exports.PDFNetworkStream = undefined; + +var _regenerator = __w_pdfjs_require__(137); + +var _regenerator2 = _interopRequireDefault(_regenerator); + +var _util = __w_pdfjs_require__(1); + +var _network_utils = __w_pdfjs_require__(149); + +var _global_scope = __w_pdfjs_require__(3); + +var _global_scope2 = _interopRequireDefault(_global_scope); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } + +; +var OK_RESPONSE = 200; +var PARTIAL_CONTENT_RESPONSE = 206; +function NetworkManager(url, args) { + this.url = url; + args = args || {}; + this.isHttp = /^https?:/i.test(url); + this.httpHeaders = this.isHttp && args.httpHeaders || {}; + this.withCredentials = args.withCredentials || false; + this.getXhr = args.getXhr || function NetworkManager_getXhr() { + return new XMLHttpRequest(); + }; + this.currXhrId = 0; + this.pendingRequests = Object.create(null); + this.loadedRequests = Object.create(null); +} +function getArrayBuffer(xhr) { + var data = xhr.response; + if (typeof data !== 'string') { + return data; + } + var array = (0, _util.stringToBytes)(data); + return array.buffer; +} +var supportsMozChunked = function supportsMozChunkedClosure() { + try { + var x = new XMLHttpRequest(); + x.open('GET', _global_scope2.default.location.href); + x.responseType = 'moz-chunked-arraybuffer'; + return x.responseType === 'moz-chunked-arraybuffer'; + } catch (e) { + return false; + } +}(); +NetworkManager.prototype = { + requestRange: function NetworkManager_requestRange(begin, end, listeners) { + var args = { + begin: begin, + end: end + }; + for (var prop in listeners) { + args[prop] = listeners[prop]; } - function JURL(url, base) { - if (base !== undefined && !(base instanceof JURL)) { - base = new JURL(String(base)); + return this.request(args); + }, + requestFull: function NetworkManager_requestFull(listeners) { + return this.request(listeners); + }, + request: function NetworkManager_request(args) { + var xhr = this.getXhr(); + var xhrId = this.currXhrId++; + var pendingRequest = this.pendingRequests[xhrId] = { xhr: xhr }; + xhr.open('GET', this.url); + xhr.withCredentials = this.withCredentials; + for (var property in this.httpHeaders) { + var value = this.httpHeaders[property]; + if (typeof value === 'undefined') { + continue; } - this._url = url; - clear.call(this); - var input = url.replace(/^[ \t\r\n\f]+|[ \t\r\n\f]+$/g, ''); - parse.call(this, input, null, base); + xhr.setRequestHeader(property, value); } - JURL.prototype = { - toString: function () { - return this.href; - }, - get href() { - if (this._isInvalid) { - return this._url; - } - var authority = ''; - if (this._username !== '' || this._password !== null) { - authority = this._username + (this._password !== null ? ':' + this._password : '') + '@'; - } - return this.protocol + (this._isRelative ? '//' + authority + this.host : '') + this.pathname + this._query + this._fragment; - }, - set href(href) { - clear.call(this); - parse.call(this, href); - }, - get protocol() { - return this._scheme + ':'; - }, - set protocol(protocol) { - if (this._isInvalid) { - return; - } - parse.call(this, protocol + ':', 'scheme start'); - }, - get host() { - return this._isInvalid ? '' : this._port ? this._host + ':' + this._port : this._host; - }, - set host(host) { - if (this._isInvalid || !this._isRelative) { - return; - } - parse.call(this, host, 'host'); - }, - get hostname() { - return this._host; - }, - set hostname(hostname) { - if (this._isInvalid || !this._isRelative) { - return; - } - parse.call(this, hostname, 'hostname'); - }, - get port() { - return this._port; - }, - set port(port) { - if (this._isInvalid || !this._isRelative) { - return; - } - parse.call(this, port, 'port'); - }, - get pathname() { - return this._isInvalid ? '' : this._isRelative ? '/' + this._path.join('/') : this._schemeData; - }, - set pathname(pathname) { - if (this._isInvalid || !this._isRelative) { - return; - } - this._path = []; - parse.call(this, pathname, 'relative path start'); - }, - get search() { - return this._isInvalid || !this._query || this._query === '?' ? '' : this._query; - }, - set search(search) { - if (this._isInvalid || !this._isRelative) { - return; - } - this._query = '?'; - if (search[0] === '?') { - search = search.slice(1); - } - parse.call(this, search, 'query'); - }, - get hash() { - return this._isInvalid || !this._fragment || this._fragment === '#' ? '' : this._fragment; - }, - set hash(hash) { - if (this._isInvalid) { - return; - } - this._fragment = '#'; - if (hash[0] === '#') { - hash = hash.slice(1); - } - parse.call(this, hash, 'fragment'); - }, - get origin() { - var host; - if (this._isInvalid || !this._scheme) { - return ''; - } - switch (this._scheme) { - case 'data': - case 'file': - case 'javascript': - case 'mailto': - return 'null'; - } - host = this.host; - if (!host) { - return ''; - } - return this._scheme + '://' + host; + if (this.isHttp && 'begin' in args && 'end' in args) { + var rangeStr = args.begin + '-' + (args.end - 1); + xhr.setRequestHeader('Range', 'bytes=' + rangeStr); + pendingRequest.expectedStatus = 206; + } else { + pendingRequest.expectedStatus = 200; + } + var useMozChunkedLoading = supportsMozChunked && !!args.onProgressiveData; + if (useMozChunkedLoading) { + xhr.responseType = 'moz-chunked-arraybuffer'; + pendingRequest.onProgressiveData = args.onProgressiveData; + pendingRequest.mozChunked = true; + } else { + xhr.responseType = 'arraybuffer'; + } + if (args.onError) { + xhr.onerror = function (evt) { + args.onError(xhr.status); + }; + } + xhr.onreadystatechange = this.onStateChange.bind(this, xhrId); + xhr.onprogress = this.onProgress.bind(this, xhrId); + pendingRequest.onHeadersReceived = args.onHeadersReceived; + pendingRequest.onDone = args.onDone; + pendingRequest.onError = args.onError; + pendingRequest.onProgress = args.onProgress; + xhr.send(null); + return xhrId; + }, + onProgress: function NetworkManager_onProgress(xhrId, evt) { + var pendingRequest = this.pendingRequests[xhrId]; + if (!pendingRequest) { + return; + } + if (pendingRequest.mozChunked) { + var chunk = getArrayBuffer(pendingRequest.xhr); + pendingRequest.onProgressiveData(chunk); + } + var onProgress = pendingRequest.onProgress; + if (onProgress) { + onProgress(evt); + } + }, + onStateChange: function NetworkManager_onStateChange(xhrId, evt) { + var pendingRequest = this.pendingRequests[xhrId]; + if (!pendingRequest) { + return; + } + var xhr = pendingRequest.xhr; + if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) { + pendingRequest.onHeadersReceived(); + delete pendingRequest.onHeadersReceived; + } + if (xhr.readyState !== 4) { + return; + } + if (!(xhrId in this.pendingRequests)) { + return; + } + delete this.pendingRequests[xhrId]; + if (xhr.status === 0 && this.isHttp) { + if (pendingRequest.onError) { + pendingRequest.onError(xhr.status); } + return; + } + var xhrStatus = xhr.status || OK_RESPONSE; + var ok_response_on_range_request = xhrStatus === OK_RESPONSE && pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE; + if (!ok_response_on_range_request && xhrStatus !== pendingRequest.expectedStatus) { + if (pendingRequest.onError) { + pendingRequest.onError(xhr.status); + } + return; + } + this.loadedRequests[xhrId] = true; + var chunk = getArrayBuffer(xhr); + if (xhrStatus === PARTIAL_CONTENT_RESPONSE) { + var rangeHeader = xhr.getResponseHeader('Content-Range'); + var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader); + var begin = parseInt(matches[1], 10); + pendingRequest.onDone({ + begin: begin, + chunk: chunk + }); + } else if (pendingRequest.onProgressiveData) { + pendingRequest.onDone(null); + } else if (chunk) { + pendingRequest.onDone({ + begin: 0, + chunk: chunk + }); + } else if (pendingRequest.onError) { + pendingRequest.onError(xhr.status); + } + }, + hasPendingRequests: function NetworkManager_hasPendingRequests() { + for (var xhrId in this.pendingRequests) { + return true; + } + return false; + }, + getRequestXhr: function NetworkManager_getXhr(xhrId) { + return this.pendingRequests[xhrId].xhr; + }, + isStreamingRequest: function NetworkManager_isStreamingRequest(xhrId) { + return !!this.pendingRequests[xhrId].onProgressiveData; + }, + isPendingRequest: function NetworkManager_isPendingRequest(xhrId) { + return xhrId in this.pendingRequests; + }, + isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) { + return xhrId in this.loadedRequests; + }, + abortAllRequests: function NetworkManager_abortAllRequests() { + for (var xhrId in this.pendingRequests) { + this.abortRequest(xhrId | 0); + } + }, + abortRequest: function NetworkManager_abortRequest(xhrId) { + var xhr = this.pendingRequests[xhrId].xhr; + delete this.pendingRequests[xhrId]; + xhr.abort(); + } +}; +function PDFNetworkStream(source) { + this._source = source; + this._manager = new NetworkManager(source.url, { + httpHeaders: source.httpHeaders, + withCredentials: source.withCredentials + }); + this._rangeChunkSize = source.rangeChunkSize; + this._fullRequestReader = null; + this._rangeRequestReaders = []; +} +PDFNetworkStream.prototype = { + _onRangeRequestReaderClosed: function PDFNetworkStream_onRangeRequestReaderClosed(reader) { + var i = this._rangeRequestReaders.indexOf(reader); + if (i >= 0) { + this._rangeRequestReaders.splice(i, 1); + } + }, + getFullReader: function PDFNetworkStream_getFullReader() { + (0, _util.assert)(!this._fullRequestReader); + this._fullRequestReader = new PDFNetworkStreamFullRequestReader(this._manager, this._source); + return this._fullRequestReader; + }, + getRangeReader: function PDFNetworkStream_getRangeReader(begin, end) { + var reader = new PDFNetworkStreamRangeRequestReader(this._manager, begin, end); + reader.onClosed = this._onRangeRequestReaderClosed.bind(this); + this._rangeRequestReaders.push(reader); + return reader; + }, + cancelAllRequests: function PDFNetworkStream_cancelAllRequests(reason) { + if (this._fullRequestReader) { + this._fullRequestReader.cancel(reason); + } + var readers = this._rangeRequestReaders.slice(0); + readers.forEach(function (reader) { + reader.cancel(reason); + }); + } +}; +function PDFNetworkStreamFullRequestReader(manager, source) { + this._manager = manager; + var args = { + onHeadersReceived: this._onHeadersReceived.bind(this), + onProgressiveData: source.disableStream ? null : this._onProgressiveData.bind(this), + onDone: this._onDone.bind(this), + onError: this._onError.bind(this), + onProgress: this._onProgress.bind(this) + }; + this._url = source.url; + this._fullRequestId = manager.requestFull(args); + this._headersReceivedCapability = (0, _util.createPromiseCapability)(); + this._disableRange = source.disableRange || false; + this._contentLength = source.length; + this._rangeChunkSize = source.rangeChunkSize; + if (!this._rangeChunkSize && !this._disableRange) { + this._disableRange = true; + } + this._isStreamingSupported = false; + this._isRangeSupported = false; + this._cachedChunks = []; + this._requests = []; + this._done = false; + this._storedError = undefined; + this._filename = null; + this.onProgress = null; +} +PDFNetworkStreamFullRequestReader.prototype = { + _onHeadersReceived: function PDFNetworkStreamFullRequestReader_onHeadersReceived() { + var fullRequestXhrId = this._fullRequestId; + var fullRequestXhr = this._manager.getRequestXhr(fullRequestXhrId); + var getResponseHeader = function getResponseHeader(name) { + return fullRequestXhr.getResponseHeader(name); }; - var OriginalURL = globalScope.URL; - if (OriginalURL) { - JURL.createObjectURL = function (blob) { - return OriginalURL.createObjectURL.apply(OriginalURL, arguments); - }; - JURL.revokeObjectURL = function (url) { - OriginalURL.revokeObjectURL(url); - }; + + var _validateRangeRequest = (0, _network_utils.validateRangeRequestCapabilities)({ + getResponseHeader: getResponseHeader, + isHttp: this._manager.isHttp, + rangeChunkSize: this._rangeChunkSize, + disableRange: this._disableRange + }), + allowRangeRequests = _validateRangeRequest.allowRangeRequests, + suggestedLength = _validateRangeRequest.suggestedLength; + + if (allowRangeRequests) { + this._isRangeSupported = true; } - globalScope.URL = JURL; - })(); + this._contentLength = suggestedLength || this._contentLength; + this._filename = (0, _network_utils.extractFilenameFromHeader)(getResponseHeader); + var networkManager = this._manager; + if (networkManager.isStreamingRequest(fullRequestXhrId)) { + this._isStreamingSupported = true; + } else if (this._isRangeSupported) { + networkManager.abortRequest(fullRequestXhrId); + } + this._headersReceivedCapability.resolve(); + }, + _onProgressiveData: function PDFNetworkStreamFullRequestReader_onProgressiveData(chunk) { + if (this._requests.length > 0) { + var requestCapability = this._requests.shift(); + requestCapability.resolve({ + value: chunk, + done: false + }); + } else { + this._cachedChunks.push(chunk); + } + }, + _onDone: function PDFNetworkStreamFullRequestReader_onDone(args) { + if (args) { + this._onProgressiveData(args.chunk); + } + this._done = true; + if (this._cachedChunks.length > 0) { + return; + } + this._requests.forEach(function (requestCapability) { + requestCapability.resolve({ + value: undefined, + done: true + }); + }); + this._requests = []; + }, + _onError: function PDFNetworkStreamFullRequestReader_onError(status) { + var url = this._url; + var exception = (0, _network_utils.createResponseStatusError)(status, url); + this._storedError = exception; + this._headersReceivedCapability.reject(exception); + this._requests.forEach(function (requestCapability) { + requestCapability.reject(exception); + }); + this._requests = []; + this._cachedChunks = []; + }, + _onProgress: function PDFNetworkStreamFullRequestReader_onProgress(data) { + if (this.onProgress) { + this.onProgress({ + loaded: data.loaded, + total: data.lengthComputable ? data.total : this._contentLength + }); + } + }, + get filename() { + return this._filename; + }, + get isRangeSupported() { + return this._isRangeSupported; + }, + get isStreamingSupported() { + return this._isStreamingSupported; + }, + get contentLength() { + return this._contentLength; + }, + get headersReady() { + return this._headersReceivedCapability.promise; + }, + read: function () { + var _ref = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee() { + var chunk, requestCapability; + return _regenerator2.default.wrap(function _callee$(_context) { + while (1) { + switch (_context.prev = _context.next) { + case 0: + if (!this._storedError) { + _context.next = 2; + break; + } + + throw this._storedError; + + case 2: + if (!(this._cachedChunks.length > 0)) { + _context.next = 5; + break; + } + + chunk = this._cachedChunks.shift(); + return _context.abrupt('return', { + value: chunk, + done: false + }); + + case 5: + if (!this._done) { + _context.next = 7; + break; + } + + return _context.abrupt('return', { + value: undefined, + done: true + }); + + case 7: + requestCapability = (0, _util.createPromiseCapability)(); + + this._requests.push(requestCapability); + return _context.abrupt('return', requestCapability.promise); + + case 10: + case 'end': + return _context.stop(); + } + } + }, _callee, this); + })); + + function read() { + return _ref.apply(this, arguments); + } + + return read; + }(), + + cancel: function PDFNetworkStreamFullRequestReader_cancel(reason) { + this._done = true; + this._headersReceivedCapability.reject(reason); + this._requests.forEach(function (requestCapability) { + requestCapability.resolve({ + value: undefined, + done: true + }); + }); + this._requests = []; + if (this._manager.isPendingRequest(this._fullRequestId)) { + this._manager.abortRequest(this._fullRequestId); + } + this._fullRequestReader = null; + } +}; +function PDFNetworkStreamRangeRequestReader(manager, begin, end) { + this._manager = manager; + var args = { + onDone: this._onDone.bind(this), + onProgress: this._onProgress.bind(this) + }; + this._requestId = manager.requestRange(begin, end, args); + this._requests = []; + this._queuedChunk = null; + this._done = false; + this.onProgress = null; + this.onClosed = null; } -/* WEBPACK VAR INJECTION */}.call(exports, __w_pdfjs_require__(6))) +PDFNetworkStreamRangeRequestReader.prototype = { + _close: function PDFNetworkStreamRangeRequestReader_close() { + if (this.onClosed) { + this.onClosed(this); + } + }, + _onDone: function PDFNetworkStreamRangeRequestReader_onDone(data) { + var chunk = data.chunk; + if (this._requests.length > 0) { + var requestCapability = this._requests.shift(); + requestCapability.resolve({ + value: chunk, + done: false + }); + } else { + this._queuedChunk = chunk; + } + this._done = true; + this._requests.forEach(function (requestCapability) { + requestCapability.resolve({ + value: undefined, + done: true + }); + }); + this._requests = []; + this._close(); + }, + _onProgress: function PDFNetworkStreamRangeRequestReader_onProgress(evt) { + if (!this.isStreamingSupported && this.onProgress) { + this.onProgress({ loaded: evt.loaded }); + } + }, + get isStreamingSupported() { + return false; + }, + read: function () { + var _ref2 = _asyncToGenerator( /*#__PURE__*/_regenerator2.default.mark(function _callee2() { + var chunk, requestCapability; + return _regenerator2.default.wrap(function _callee2$(_context2) { + while (1) { + switch (_context2.prev = _context2.next) { + case 0: + if (!(this._queuedChunk !== null)) { + _context2.next = 4; + break; + } + + chunk = this._queuedChunk; + + this._queuedChunk = null; + return _context2.abrupt('return', { + value: chunk, + done: false + }); + + case 4: + if (!this._done) { + _context2.next = 6; + break; + } + + return _context2.abrupt('return', { + value: undefined, + done: true + }); + + case 6: + requestCapability = (0, _util.createPromiseCapability)(); + + this._requests.push(requestCapability); + return _context2.abrupt('return', requestCapability.promise); + + case 9: + case 'end': + return _context2.stop(); + } + } + }, _callee2, this); + })); + + function read() { + return _ref2.apply(this, arguments); + } + + return read; + }(), + + cancel: function PDFNetworkStreamRangeRequestReader_cancel(reason) { + this._done = true; + this._requests.forEach(function (requestCapability) { + requestCapability.resolve({ + value: undefined, + done: true + }); + }); + this._requests = []; + if (this._manager.isPendingRequest(this._requestId)) { + this._manager.abortRequest(this._requestId); + } + this._close(); + } +}; +exports.PDFNetworkStream = PDFNetworkStream; +exports.NetworkManager = NetworkManager; /***/ }) /******/ ]); -}); \ No newline at end of file +}); +//# sourceMappingURL=pdf.js.map \ No newline at end of file diff --git a/vendor/assets/javascripts/pdf.min.js b/vendor/assets/javascripts/pdf.min.js old mode 100755 new mode 100644 index 271a471fd49..43ab356bfec --- a/vendor/assets/javascripts/pdf.min.js +++ b/vendor/assets/javascripts/pdf.min.js @@ -1,6 +1 @@ -!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("pdfjs-dist/build/pdf",[],e):"object"==typeof exports?exports["pdfjs-dist/build/pdf"]=e():t["pdfjs-dist/build/pdf"]=t.pdfjsDistBuildPdf=e()}(this,function(){return function(t){function e(r){if(n[r])return n[r].exports;var i=n[r]={i:r,l:!1,exports:{}};return t[r].call(i.exports,i,i.exports,e),i.l=!0,i.exports}var n={};return e.m=t,e.c=n,e.i=function(t){return t},e.d=function(t,n,r){e.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:r})},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=13)}([function(t,e,n){"use strict";(function(t){function r(t){nt=t}function i(){return nt}function a(t){nt>=$.infos&&console.log("Info: "+t)}function s(t){nt>=$.warnings&&console.log("Warning: "+t)}function o(t){console.log("Deprecated API usage: "+t)}function c(t){throw nt>=$.errors&&(console.log("Error: "+t),console.log(l())),new Error(t)}function l(){try{throw new Error}catch(t){return t.stack?t.stack.split("\n").slice(2).join("\n"):""}}function h(t,e){t||c(e)}function u(t,e){try{var n=new URL(t);if(!n.origin||"null"===n.origin)return!1}catch(t){return!1}var r=new URL(e,n);return n.origin===r.origin}function d(t){if(!t)return!1;switch(t.protocol){case"http:":case"https:":case"ftp:":case"mailto:":case"tel:":return!0;default:return!1}}function f(t,e){if(!t)return null;try{var n=e?new URL(t,e):new URL(t);if(d(n))return n}catch(t){}return null}function p(t,e,n){return Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!1}),n}function g(t){var e;return function(){return t&&(e=Object.create(null),t(e),t=null),e}}function m(t){return"string"!=typeof t?(s("The argument for removeNullCharacters must be a string."),t):t.replace(ft,"")}function A(t){h(null!==t&&"object"==typeof t&&void 0!==t.length,"Invalid argument for bytesToString");var e=t.length;if(e<8192)return String.fromCharCode.apply(null,t);for(var n=[],r=0;r>24&255,t>>16&255,t>>8&255,255&t)}function S(t){for(var e=1,n=0;t>e;)e<<=1,n++;return n}function w(t,e){return t[e]<<24>>24}function k(t,e){return t[e]<<8|t[e+1]}function C(t,e){return(t[e]<<24|t[e+1]<<16|t[e+2]<<8|t[e+3])>>>0}function _(){var t=new Uint8Array(2);return t[0]=1,1===new Uint16Array(t.buffer)[0]}function T(){try{return new Function(""),!0}catch(t){return!1}}function P(t){var e,n=t.length,r=[];if("þ"===t[0]&&"ÿ"===t[1])for(e=2;e>2:e,n(this.length)}function e(t){return{get:function(){var e=this.buffer,n=t<<2;return(e[n]|e[n+1]<<8|e[n+2]<<16|e[n+3]<<24)>>>0},set:function(e){var n=this.buffer,r=t<<2;n[r]=255&e,n[r+1]=e>>8&255,n[r+2]=e>>16&255,n[r+3]=e>>>24&255}}}function n(n){for(;rt[2]&&(e[0]=t[2],e[2]=t[0]),t[1]>t[3]&&(e[1]=t[3],e[3]=t[1]),e},t.intersect=function(e,n){function r(t,e){return t-e}var i=[e[0],e[2],n[0],n[2]].sort(r),a=[e[1],e[3],n[1],n[3]].sort(r),s=[];return e=t.normalizeRect(e),n=t.normalizeRect(n),(i[0]===e[0]&&i[1]===n[0]||i[0]===n[0]&&i[1]===e[0])&&(s[0]=i[1],s[2]=i[2],(a[0]===e[1]&&a[1]===n[1]||a[0]===n[1]&&a[1]===e[1])&&(s[1]=a[1],s[3]=a[2],s))},t.sign=function(t){return t<0?-1:1};var n=["","C","CC","CCC","CD","D","DC","DCC","DCCC","CM","","X","XX","XXX","XL","L","LX","LXX","LXXX","XC","","I","II","III","IV","V","VI","VII","VIII","IX"];return t.toRoman=function(t,e){h(F(t)&&t>0,"The number should be a positive integer.");for(var r,i=[];t>=1e3;)t-=1e3,i.push("M");r=t/100|0,t%=100,i.push(n[r]),r=t/10|0,t%=10,i.push(n[10+r]),i.push(n[20+t]);var a=i.join("");return e?a.toLowerCase():a},t.appendToArray=function(t,e){Array.prototype.push.apply(t,e)},t.prependToArray=function(t,e){Array.prototype.unshift.apply(t,e)},t.extendObj=function(t,e){for(var n in e)t[n]=e[n]},t.getInheritableProperty=function(t,e,n){for(;t&&!t.has(e);)t=t.get("Parent");return t?n?t.getArray(e):t.get(e):null},t.inherit=function(t,e,n){t.prototype=Object.create(e.prototype),t.prototype.constructor=t;for(var r in n)t.prototype[r]=n[r]},t.loadScript=function(t,e){var n=document.createElement("script"),r=!1;n.setAttribute("src",t),e&&(n.onload=function(){r||e(),r=!0}),document.getElementsByTagName("head")[0].appendChild(n)},t}(),At=function(){function t(t,e,n,r,i,a){this.viewBox=t,this.scale=e,this.rotation=n,this.offsetX=r,this.offsetY=i;var s,o,c,l,h=(t[2]+t[0])/2,u=(t[3]+t[1])/2;switch(n%=360,n=n<0?n+360:n){case 180:s=-1,o=0,c=0,l=1;break;case 90:s=0,o=1,c=1,l=0;break;case 270:s=0,o=-1,c=-1,l=0;break;default:s=1,o=0,c=0,l=-1}a&&(c=-c,l=-l);var d,f,p,g;0===s?(d=Math.abs(u-t[1])*e+r,f=Math.abs(h-t[0])*e+i,p=Math.abs(t[3]-t[1])*e,g=Math.abs(t[2]-t[0])*e):(d=Math.abs(h-t[0])*e+r,f=Math.abs(u-t[1])*e+i,p=Math.abs(t[2]-t[0])*e,g=Math.abs(t[3]-t[1])*e),this.transform=[s*e,o*e,c*e,l*e,d-s*e*h-c*e*u,f-o*e*h-l*e*u],this.width=p,this.height=g,this.fontScale=e}return t.prototype={clone:function(e){e=e||{};var n="scale"in e?e.scale:this.scale,r="rotation"in e?e.rotation:this.rotation;return new t(this.viewBox.slice(),n,r,this.offsetX,this.offsetY,e.dontFlip)},convertToViewportPoint:function(t,e){return mt.applyTransform([t,e],this.transform)},convertToViewportRectangle:function(t){var e=mt.applyTransform([t[0],t[1]],this.transform),n=mt.applyTransform([t[2],t[3]],this.transform);return[e[0],e[1],n[0],n[1]]},convertToPdfPoint:function(t,e){return mt.applyInverseTransform([t,e],this.transform)}},t}(),vt=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,728,711,710,729,733,731,730,732,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8226,8224,8225,8230,8212,8211,402,8260,8249,8250,8722,8240,8222,8220,8221,8216,8217,8218,8482,64257,64258,321,338,352,376,381,305,322,339,353,382,0,8364],bt=function(){function t(t,e,n){for(;t.lengtha&&(a=s.length)}for(e=0,n=r.length;e>2,d=(3&c)<<4|l>>4,f=s+1>6:64,p=s+20?e:t.length,n>0?n:t.length);return t.substring(t.lastIndexOf("/",r)+1,r)}function s(t){var e=l.globalScope.PDFJS;switch(t){case"pdfBug":return!!e&&e.pdfBug;case"disableAutoFetch":return!!e&&e.disableAutoFetch;case"disableStream":return!!e&&e.disableStream;case"disableRange":return!!e&&e.disableRange;case"disableFontFace":return!!e&&e.disableFontFace;case"disableCreateObjectURL":return!!e&&e.disableCreateObjectURL;case"disableWebGL":return!e||e.disableWebGL;case"cMapUrl":return e?e.cMapUrl:null;case"cMapPacked":return!!e&&e.cMapPacked;case"postMessageTransfers":return!e||e.postMessageTransfers;case"workerPort":return e?e.workerPort:null;case"workerSrc":return e?e.workerSrc:null;case"disableWorker":return!!e&&e.disableWorker;case"maxImageSize":return e?e.maxImageSize:-1;case"imageResourcesPath":return e?e.imageResourcesPath:"";case"isEvalSupported":return!e||e.isEvalSupported;case"externalLinkTarget":if(!e)return S.NONE;switch(e.externalLinkTarget){case S.NONE:case S.SELF:case S.BLANK:case S.PARENT:case S.TOP:return e.externalLinkTarget}return d("PDFJS.externalLinkTarget is invalid: "+e.externalLinkTarget),e.externalLinkTarget=S.NONE,S.NONE;case"externalLinkRel":return e?e.externalLinkRel:A;case"enableStats":return!(!e||!e.enableStats);case"pdfjsNext":return!(!e||!e.pdfjsNext);default:throw new Error("Unknown default setting: "+t)}}function o(){switch(s("externalLinkTarget")){case S.NONE:return!1;case S.SELF:case S.BLANK:case S.PARENT:case S.TOP:return!0}}function c(t,e){return f("isValidUrl(), please use createValidAbsoluteUrl() instead."),null!==p(t,e?"http://example.com":null)}var l=n(0),h=l.assert,u=l.removeNullCharacters,d=l.warn,f=l.deprecated,p=l.createValidAbsoluteUrl,g=l.stringToBytes,m=l.CMapCompressionType,A="noopener noreferrer nofollow";r.prototype={create:function(t,e){h(t>0&&e>0,"invalid canvas size");var n=document.createElement("canvas"),r=n.getContext("2d");return n.width=t,n.height=e,{canvas:n,context:r}},reset:function(t,e,n){h(t.canvas,"canvas is not specified"),h(e>0&&n>0,"invalid canvas size"),t.canvas.width=e,t.canvas.height=n},destroy:function(t){h(t.canvas,"canvas is not specified"),t.canvas.width=0,t.canvas.height=0,t.canvas=null,t.context=null}};var v,b=function(){function t(t){this.baseUrl=t.baseUrl||null,this.isCompressed=t.isCompressed||!1}return t.prototype={fetch:function(t){var e=t.name;return e?new Promise(function(t,n){var r=this.baseUrl+e+(this.isCompressed?".bcmap":""),i=new XMLHttpRequest;i.open("GET",r,!0),this.isCompressed&&(i.responseType="arraybuffer"),i.onreadystatechange=function(){if(i.readyState===XMLHttpRequest.DONE){if(200===i.status||0===i.status){var e;if(this.isCompressed&&i.response?e=new Uint8Array(i.response):!this.isCompressed&&i.responseText&&(e=g(i.responseText)),e)return void t({cMapData:e,compressionType:this.isCompressed?m.BINARY:m.NONE})}n(new Error("Unable to load "+(this.isCompressed?"binary ":"")+"CMap at: "+r))}}.bind(this),i.send(null)}.bind(this)):Promise.reject(new Error("CMap name must be specified."))}},t}(),y=function(){function t(){}var e=["ms","Moz","Webkit","O"],n=Object.create(null);return t.getProp=function(t,r){if(1===arguments.length&&"string"==typeof n[t])return n[t];r=r||document.documentElement;var i,a,s=r.style;if("string"==typeof s[t])return n[t]=t;a=t.charAt(0).toUpperCase()+t.slice(1);for(var o=0,c=e.length;o0){r.style.borderWidth=t.borderStyle.width+"px",t.borderStyle.style!==s.UNDERLINE&&(i-=2*t.borderStyle.width,a-=2*t.borderStyle.width);var c=t.borderStyle.horizontalCornerRadius,h=t.borderStyle.verticalCornerRadius;if(c>0||h>0){var u=c+"px / "+h+"px";p.setProp("borderRadius",r,u)}switch(t.borderStyle.style){case s.SOLID:r.style.borderStyle="solid";break;case s.DASHED:r.style.borderStyle="dashed";break;case s.BEVELED:f("Unimplemented border style: beveled");break;case s.INSET:f("Unimplemented border style: inset");break;case s.UNDERLINE:r.style.borderBottomStyle="solid"}t.color?r.style.borderColor=l.makeCssRgb(0|t.color[0],0|t.color[1],0|t.color[2]):r.style.borderWidth=0}return r.style.left=o[0]+"px",r.style.top=o[1]+"px",r.style.width=i+"px",r.style.height=a+"px",r},_createPopup:function(t,e,n){e||(e=document.createElement("div"),e.style.height=t.style.height,e.style.width=t.style.width,t.appendChild(e));var r=new C({container:t,trigger:e,color:n.color,title:n.title,contents:n.contents,hideWrapper:!0}),i=r.render();i.style.left=t.style.width,t.appendChild(i)},render:function(){throw new Error("Abstract method AnnotationElement.render called")}},t}(),A=function(){function t(t){m.call(this,t,!0)}return l.inherit(t,m,{render:function(){this.container.className="linkAnnotation";var t=document.createElement("a");return h(t,{url:this.data.url,target:this.data.newWindow?u.BLANK:void 0}),this.data.url||(this.data.action?this._bindNamedAction(t,this.data.action):this._bindLink(t,this.data.dest)),this.container.appendChild(t),this.container},_bindLink:function(t,e){var n=this;t.href=this.linkService.getDestinationHash(e),t.onclick=function(){return e&&n.linkService.navigateTo(e),!1},e&&(t.className="internalLink")},_bindNamedAction:function(t,e){var n=this;t.href=this.linkService.getAnchorUrl(""),t.onclick=function(){return n.linkService.executeNamedAction(e),!1},t.className="internalLink"}}),t}(),v=function(){function t(t){var e=!!(t.data.hasPopup||t.data.title||t.data.contents);m.call(this,t,e)}return l.inherit(t,m,{render:function(){this.container.className="textAnnotation";var t=document.createElement("img");return t.style.height=this.container.style.height,t.style.width=this.container.style.width,t.src=this.imageResourcesPath+"annotation-"+this.data.name.toLowerCase()+".svg",t.alt="[{{type}} Annotation]",t.dataset.l10nId="text_annotation_type",t.dataset.l10nArgs=JSON.stringify({type:this.data.name}),this.data.hasPopup||this._createPopup(this.container,t,this.data),this.container.appendChild(t),this.container}}),t}(),b=function(){function t(t,e){m.call(this,t,e)}return l.inherit(t,m,{render:function(){return this.container}}),t}(),y=function(){function t(t){var e=t.renderInteractiveForms||!t.data.hasAppearance&&!!t.data.fieldValue;b.call(this,t,e)}var e=["left","center","right"];return l.inherit(t,b,{render:function(){this.container.className="textWidgetAnnotation";var t=null;if(this.renderInteractiveForms){if(this.data.multiLine?(t=document.createElement("textarea"),t.textContent=this.data.fieldValue):(t=document.createElement("input"),t.type="text",t.setAttribute("value",this.data.fieldValue)),t.disabled=this.data.readOnly,null!==this.data.maxLen&&(t.maxLength=this.data.maxLen),this.data.comb){var n=this.data.rect[2]-this.data.rect[0],r=n/this.data.maxLen;t.classList.add("comb"),t.style.letterSpacing="calc("+r+"px - 1ch)"}}else{t=document.createElement("div"),t.textContent=this.data.fieldValue,t.style.verticalAlign="middle",t.style.display="table-cell";var i=null;this.data.fontRefName&&(i=this.page.commonObjs.getData(this.data.fontRefName)),this._setTextStyle(t,i)}return null!==this.data.textAlignment&&(t.style.textAlign=e[this.data.textAlignment]),this.container.appendChild(t),this.container},_setTextStyle:function(t,e){var n=t.style;if(n.fontSize=this.data.fontSize+"px",n.direction=this.data.fontDirection<0?"rtl":"ltr",e){n.fontWeight=e.black?e.bold?"900":"bold":e.bold?"bold":"normal",n.fontStyle=e.italic?"italic":"normal";var r=e.loadedName?'"'+e.loadedName+'", ':"",i=e.fallbackName||"Helvetica, sans-serif";n.fontFamily=r+i}}}),t}(),x=function(){function t(t){b.call(this,t,t.renderInteractiveForms)}return l.inherit(t,b,{render:function(){this.container.className="buttonWidgetAnnotation checkBox";var t=document.createElement("input");return t.disabled=this.data.readOnly,t.type="checkbox",this.data.fieldValue&&"Off"!==this.data.fieldValue&&t.setAttribute("checked",!0),this.container.appendChild(t),this.container}}),t}(),S=function(){function t(t){b.call(this,t,t.renderInteractiveForms)}return l.inherit(t,b,{render:function(){this.container.className="buttonWidgetAnnotation radioButton";var t=document.createElement("input");return t.disabled=this.data.readOnly,t.type="radio",t.name=this.data.fieldName,this.data.fieldValue===this.data.buttonValue&&t.setAttribute("checked",!0),this.container.appendChild(t),this.container}}),t}(),w=function(){function t(t){b.call(this,t,t.renderInteractiveForms)}return l.inherit(t,b,{render:function(){this.container.className="choiceWidgetAnnotation";var t=document.createElement("select");t.disabled=this.data.readOnly,this.data.combo||(t.size=this.data.options.length,this.data.multiSelect&&(t.multiple=!0));for(var e=0,n=this.data.options.length;e=0&&i.setAttribute("selected",!0),t.appendChild(i)}return this.container.appendChild(t),this.container}}),t}(),k=function(){function t(t){var e=!(!t.data.title&&!t.data.contents);m.call(this,t,e)}return l.inherit(t,m,{render:function(){this.container.className="popupAnnotation";var t='[data-annotation-id="'+this.data.parentId+'"]',e=this.layer.querySelector(t);if(!e)return this.container;var n=new C({container:this.container,trigger:e,color:this.data.color,title:this.data.title,contents:this.data.contents}),r=parseFloat(e.style.left),i=parseFloat(e.style.width);return p.setProp("transformOrigin",this.container,-(r+i)+"px -"+e.style.top),this.container.style.left=r+i+"px",this.container.appendChild(n.render()),this.container}}),t}(),C=function(){function t(t){this.container=t.container,this.trigger=t.trigger,this.color=t.color,this.title=t.title,this.contents=t.contents,this.hideWrapper=t.hideWrapper||!1,this.pinned=!1}return t.prototype={render:function(){var t=document.createElement("div");t.className="popupWrapper",this.hideElement=this.hideWrapper?t:this.container,this.hideElement.setAttribute("hidden",!0);var e=document.createElement("div");e.className="popup";var n=this.color;if(n){var r=.7*(255-n[0])+n[0],i=.7*(255-n[1])+n[1],a=.7*(255-n[2])+n[2];e.style.backgroundColor=l.makeCssRgb(0|r,0|i,0|a)}var s=this._formatContents(this.contents),o=document.createElement("h1");return o.textContent=this.title,this.trigger.addEventListener("click",this._toggle.bind(this)),this.trigger.addEventListener("mouseover",this._show.bind(this,!1)),this.trigger.addEventListener("mouseout",this._hide.bind(this,!1)),e.addEventListener("click",this._hide.bind(this,!0)),e.appendChild(o),e.appendChild(s),t.appendChild(e),t},_formatContents:function(t){for(var e=document.createElement("p"),n=t.split(/(?:\r\n?|\n)/),r=0,i=n.length;r1&&S("getDocument is called with pdfDataRangeTransport, passwordCallback or progressCallback argument"),e&&(e instanceof J||(e=Object.create(e),e.length=t.length,e.initialData=t.initialData,e.abort||(e.abort=function(){})),t=Object.create(t),t.range=e),a.onPassword=n||null,a.onProgress=r||null;var s;"string"==typeof t?s={url:t}:T(t)?s={data:t}:t instanceof J?s={range:t}:("object"!=typeof t&&x("Invalid parameter in getDocument, need either Uint8Array, string or a parameter object"),t.url||t.data||t.range||x("Invalid parameter object: need either .data, .range or .url"),s=t);var o={},c=null,l=null;for(var h in s)if("url"!==h||"undefined"==typeof window)if("range"!==h)if("worker"!==h)if("data"!==h||s[h]instanceof Uint8Array)o[h]=s[h];else{var u=s[h];"string"==typeof u?o[h]=E(u):"object"!=typeof u||null===u||isNaN(u.length)?T(u)?o[h]=new Uint8Array(u):x("Invalid PDF binary data: either typed array, string or array-like object is expected in the data property."):o[h]=new Uint8Array(u)}else l=s[h];else c=s[h];else o[h]=new URL(s[h],window.location).href;o.rangeChunkSize=o.rangeChunkSize||W,o.disableNativeImageDecoder=!0===o.disableNativeImageDecoder;var f=o.CMapReaderFactory||B;if(!l){var p=j("workerPort");l=p?new Z(null,p):new Z,a._worker=l}var g=a.docId;return l.promise.then(function(){if(a.destroyed)throw new Error("Loading aborted");return i(l,o,c,g).then(function(t){if(a.destroyed)throw new Error("Loading aborted");var e=new d(g,t,l.port),n=new $(e,a,c,f);a._transport=n,e.send("Ready",null)})}).catch(a._capability.reject),a}function i(t,e,n,r){return t.destroyed?Promise.reject(new Error("Worker was destroyed")):(e.disableAutoFetch=j("disableAutoFetch"),e.disableStream=j("disableStream"),e.chunkedViewerLoading=!!n,n&&(e.length=n.length,e.initialData=n.initialData),t.messageHandler.sendWithPromise("GetDocRequest",{docId:r,source:e,disableRange:j("disableRange"),maxImageSize:j("maxImageSize"),disableFontFace:j("disableFontFace"),disableCreateObjectURL:j("disableCreateObjectURL"),postMessageTransfers:j("postMessageTransfers")&&!X,docBaseUrl:e.docBaseUrl,disableNativeImageDecoder:e.disableNativeImageDecoder}).then(function(e){if(t.destroyed)throw new Error("Worker was destroyed");return e}))}var a,s=n(0),o=n(11),c=n(10),l=n(7),h=n(1),u=s.InvalidPDFException,d=s.MessageHandler,f=s.MissingPDFException,p=s.PageViewport,g=s.PasswordException,m=s.StatTimer,A=s.UnexpectedResponseException,v=s.UnknownErrorException,b=s.Util,y=s.createPromiseCapability,x=s.error,S=s.deprecated,w=s.getVerbosityLevel,k=s.info,C=s.isInt,_=s.isArray,T=s.isArrayBuffer,P=s.isSameOrigin,L=s.loadJpegStream,E=s.stringToBytes,R=s.globalScope,I=s.warn,F=o.FontFaceObject,O=o.FontLoader,M=c.CanvasGraphics,D=l.Metadata,N=h.RenderingCancelledException,j=h.getDefaultSetting,U=h.DOMCanvasFactory,B=h.DOMCMapReaderFactory,W=65536,G=!1,X=!1,H="undefined"!=typeof document&&document.currentScript?document.currentScript.src:null,z=null,Y=!1;if("undefined"==typeof __pdfjsdev_webpack__){"undefined"==typeof window?(G=!0,void 0===require.ensure&&(require.ensure=require("node-ensure")),Y=!0):"undefined"!=typeof require&&"function"==typeof require.ensure&&(Y=!0),"undefined"!=typeof requirejs&&requirejs.toUrl&&(a=requirejs.toUrl("pdfjs-dist/build/pdf.worker.js"));var q="undefined"!=typeof requirejs&&requirejs.load;z=Y?function(t){require.ensure([],function(){var e=require("./pdf.worker.js");t(e.WorkerMessageHandler)})}:q?function(t){requirejs(["pdfjs-dist/build/pdf.worker"],function(e){t(e.WorkerMessageHandler)})}:null}var V=function(){function t(){this._capability=y(),this._transport=null,this._worker=null,this.docId="d"+e++,this.destroyed=!1,this.onPassword=null,this.onProgress=null,this.onUnsupportedFeature=null}var e=0;return t.prototype={get promise(){return this._capability.promise},destroy:function(){return this.destroyed=!0,(this._transport?this._transport.destroy():Promise.resolve()).then(function(){this._transport=null,this._worker&&(this._worker.destroy(),this._worker=null)}.bind(this))},then:function(t,e){return this.promise.then.apply(this.promise,arguments)}},t}(),J=function(){function t(t,e){this.length=t,this.initialData=e,this._rangeListeners=[],this._progressListeners=[],this._progressiveReadListeners=[],this._readyCapability=y()}return t.prototype={addRangeListener:function(t){this._rangeListeners.push(t)},addProgressListener:function(t){this._progressListeners.push(t)},addProgressiveReadListener:function(t){this._progressiveReadListeners.push(t)},onDataRange:function(t,e){for(var n=this._rangeListeners,r=0,i=n.length;r=0&&s.renderTasks.splice(e,1),l.cleanupAfterRender&&(l.pendingCleanup=!0),l._tryCleanup(),t?o.capability.reject(t):o.capability.resolve(),n.timeEnd("Rendering"),n.timeEnd("Overall")}var n=this.stats;n.time("Overall"),this.pendingCleanup=!1;var r="print"===t.intent?"print":"display",i=!0===t.renderInteractiveForms,a=t.canvasFactory||new U;this.intentStates[r]||(this.intentStates[r]=Object.create(null));var s=this.intentStates[r];s.displayReadyCapability||(s.receivingOperatorList=!0,s.displayReadyCapability=y(),s.operatorList={fnArray:[],argsArray:[],lastChunk:!1},this.stats.time("Page Request"),this.transport.messageHandler.send("RenderPageRequest",{pageIndex:this.pageNumber-1,intent:r,renderInteractiveForms:i}));var o=new nt(e,t,this.objs,this.commonObjs,s.operatorList,this.pageNumber,a);o.useRequestAnimationFrame="print"!==r,s.renderTasks||(s.renderTasks=[]),s.renderTasks.push(o);var c=o.task;t.continueCallback&&(S("render is used with continueCallback parameter"),c.onContinue=t.continueCallback);var l=this;return s.displayReadyCapability.promise.then(function(t){if(l.pendingCleanup)return void e();n.time("Rendering"),o.initializeGraphics(t),o.operatorListChanged()},function(t){e(t)}),c},getOperatorList:function(){function t(){if(n.operatorList.lastChunk){n.opListReadCapability.resolve(n.operatorList);var t=n.renderTasks.indexOf(e);t>=0&&n.renderTasks.splice(t,1)}}this.intentStates.oplist||(this.intentStates.oplist=Object.create(null));var e,n=this.intentStates.oplist;return n.opListReadCapability||(e={},e.operatorListChanged=t,n.receivingOperatorList=!0,n.opListReadCapability=y(),n.renderTasks=[],n.renderTasks.push(e),n.operatorList={fnArray:[],argsArray:[],lastChunk:!1},this.transport.messageHandler.send("RenderPageRequest",{pageIndex:this.pageIndex,intent:"oplist"})),n.opListReadCapability.promise},getTextContent:function(t){return this.transport.messageHandler.sendWithPromise("GetTextContent",{pageIndex:this.pageNumber-1,normalizeWhitespace:!(!t||!0!==t.normalizeWhitespace),combineTextItems:!t||!0!==t.disableCombineTextItems})},_destroy:function(){this.destroyed=!0,this.transport.pageCache[this.pageIndex]=null;var t=[];return Object.keys(this.intentStates).forEach(function(e){if("oplist"!==e){this.intentStates[e].renderTasks.forEach(function(e){var n=e.capability.promise.catch(function(){});t.push(n),e.cancel()})}},this),this.objs.clear(),this.annotationsPromise=null,this.pendingCleanup=!1,Promise.all(t)},destroy:function(){S("page destroy method, use cleanup() instead"),this.cleanup()},cleanup:function(){this.pendingCleanup=!0,this._tryCleanup()},_tryCleanup:function(){this.pendingCleanup&&!Object.keys(this.intentStates).some(function(t){var e=this.intentStates[t];return 0!==e.renderTasks.length||e.receivingOperatorList},this)&&(Object.keys(this.intentStates).forEach(function(t){delete this.intentStates[t]},this),this.objs.clear(),this.annotationsPromise=null,this.pendingCleanup=!1)},_startRenderPage:function(t,e){var n=this.intentStates[e];n.displayReadyCapability&&n.displayReadyCapability.resolve(t)},_renderPageChunk:function(t,e){var n,r,i=this.intentStates[e];for(n=0,r=t.length;n=0;return i=t===a?t:s?new t.constructor(a,t.byteOffset,t.byteLength):new t.constructor(t),r.set(t,i),i}i=_(t)?[]:{},r.set(t,i);for(var o in t){for(var c,l=t;!(c=Object.getOwnPropertyDescriptor(l,o));)l=Object.getPrototypeOf(l);void 0!==c.value&&"function"!=typeof c.value&&(i[o]=n(c.value))}return i}if(!this._defer)return void this._listeners.forEach(function(e){e.call(this,{data:t})},this);var r=new WeakMap,i={data:n(t)};this._deferred.then(function(){this._listeners.forEach(function(t){t.call(this,i)},this)}.bind(this))},addEventListener:function(t,e){this._listeners.push(e)},removeEventListener:function(t,e){var n=this._listeners.indexOf(e);this._listeners.splice(n,1)},terminate:function(){this._listeners=[]}},i.prototype={get promise(){return this._readyCapability.promise},get port(){return this._port},get messageHandler(){return this._messageHandler},_initializeFromPort:function(t){this._port=t,this._messageHandler=new d("main","worker",t),this._messageHandler.on("ready",function(){}),this._readyCapability.resolve()},_initialize:function(){if(!G&&!j("disableWorker")&&"undefined"!=typeof Worker){var e=t();try{P(window.location.href,e)||(e=r(new URL(e,window.location).href));var n=new Worker(e),i=new d("main","worker",n),a=function(){n.removeEventListener("error",s),i.destroy(),n.terminate(),this.destroyed?this._readyCapability.reject(new Error("Worker was destroyed")):this._setupFakeWorker()}.bind(this),s=function(t){this._webWorker||a()}.bind(this);n.addEventListener("error",s),i.on("test",function(t){if(n.removeEventListener("error",s),this.destroyed)return void a();t&&t.supportTypedArray?(this._messageHandler=i,this._port=n,this._webWorker=n,t.supportTransfers||(X=!0),this._readyCapability.resolve(),i.send("configure",{verbosity:w()})):(this._setupFakeWorker(),i.destroy(),n.terminate())}.bind(this)),i.on("console_log",function(t){console.log.apply(console,t)}),i.on("console_error",function(t){console.error.apply(console,t)}),i.on("ready",function(t){if(n.removeEventListener("error",s),this.destroyed)return void a();try{o()}catch(t){this._setupFakeWorker()}}.bind(this));var o=function(){var t=j("postMessageTransfers")&&!X,e=new Uint8Array([t?255:0]);try{i.send("test",e,[e.buffer])}catch(t){k("Cannot use postMessage transfers"),e[0]=0,i.send("test",e)}};return void o()}catch(t){k("The worker has been disabled.")}}this._setupFakeWorker()},_setupFakeWorker:function(){G||j("disableWorker")||(I("Setting up fake worker."),G=!0),e().then(function(t){if(this.destroyed)return void this._readyCapability.reject(new Error("Worker was destroyed"));var e=Uint8Array!==Float32Array,r=new n(e);this._port=r;var i="fake"+o++,a=new d(i+"_worker",i,r);t.setup(a,r);var s=new d(i,i+"_worker",r);this._messageHandler=s,this._readyCapability.resolve()}.bind(this))},destroy:function(){this.destroyed=!0,this._webWorker&&(this._webWorker.terminate(),this._webWorker=null),this._port=null,this._messageHandler&&(this._messageHandler.destroy(),this._messageHandler=null)}},i}(),$=function(){function t(t,e,n,r){this.messageHandler=t,this.loadingTask=e,this.pdfDataRangeTransport=n,this.commonObjs=new tt,this.fontLoader=new O(e.docId),this.CMapReaderFactory=new r({baseUrl:j("cMapUrl"),isCompressed:j("cMapPacked")}),this.destroyed=!1,this.destroyCapability=null,this._passwordCapability=null,this.pageCache=[],this.pagePromises=[],this.downloadInfoCapability=y(),this.setupMessageHandler()}return t.prototype={destroy:function(){if(this.destroyCapability)return this.destroyCapability.promise;this.destroyed=!0,this.destroyCapability=y(),this._passwordCapability&&this._passwordCapability.reject(new Error("Worker was destroyed during onPassword callback"));var t=[];this.pageCache.forEach(function(e){e&&t.push(e._destroy())}),this.pageCache=[],this.pagePromises=[];var e=this,n=this.messageHandler.sendWithPromise("Terminate",null);return t.push(n),Promise.all(t).then(function(){e.fontLoader.clear(),e.pdfDataRangeTransport&&(e.pdfDataRangeTransport.abort(),e.pdfDataRangeTransport=null),e.messageHandler&&(e.messageHandler.destroy(),e.messageHandler=null),e.destroyCapability.resolve()},this.destroyCapability.reject),this.destroyCapability.promise},setupMessageHandler:function(){var t=this.messageHandler,e=this.loadingTask,n=this.pdfDataRangeTransport;n&&(n.addRangeListener(function(e,n){t.send("OnDataRange",{begin:e,chunk:n})}),n.addProgressListener(function(e){t.send("OnDataProgress",{loaded:e})}),n.addProgressiveReadListener(function(e){t.send("OnDataRange",{chunk:e})}),t.on("RequestDataRange",function(t){n.requestDataRange(t.begin,t.end)},this)),t.on("GetDoc",function(t){var e=t.pdfInfo;this.numPages=t.pdfInfo.numPages;var n=this.loadingTask,r=new Q(e,this,n);this.pdfDocument=r,n._capability.resolve(r)},this),t.on("PasswordRequest",function(t){if(this._passwordCapability=y(),e.onPassword){var n=function(t){this._passwordCapability.resolve({password:t})}.bind(this);e.onPassword(n,t.code)}else this._passwordCapability.reject(new g(t.message,t.code));return this._passwordCapability.promise},this),t.on("PasswordException",function(t){e._capability.reject(new g(t.message,t.code))},this),t.on("InvalidPDF",function(t){this.loadingTask._capability.reject(new u(t.message))},this),t.on("MissingPDF",function(t){this.loadingTask._capability.reject(new f(t.message))},this),t.on("UnexpectedResponse",function(t){this.loadingTask._capability.reject(new A(t.message,t.status))},this),t.on("UnknownError",function(t){this.loadingTask._capability.reject(new v(t.message,t.details))},this),t.on("DataLoaded",function(t){this.downloadInfoCapability.resolve(t)},this),t.on("PDFManagerReady",function(t){this.pdfDataRangeTransport&&this.pdfDataRangeTransport.transportReady()},this),t.on("StartRenderPage",function(t){if(!this.destroyed){var e=this.pageCache[t.pageIndex];e.stats.timeEnd("Page Request"),e._startRenderPage(t.transparency,t.intent)}},this),t.on("RenderPageChunk",function(t){if(!this.destroyed){this.pageCache[t.pageIndex]._renderPageChunk(t.operatorList,t.intent)}},this),t.on("commonobj",function(t){if(!this.destroyed){var e=t[0],n=t[1];if(!this.commonObjs.hasData(e))switch(n){case"Font":var r=t[2];if("error"in r){var i=r.error;I("Error during font loading: "+i),this.commonObjs.resolve(e,i);break}var a=null;j("pdfBug")&&R.FontInspector&&R.FontInspector.enabled&&(a={registerFont:function(t,e){R.FontInspector.fontAdded(t,e)}});var s=new F(r,{isEvalSuported:j("isEvalSupported"),disableFontFace:j("disableFontFace"),fontRegistry:a});this.fontLoader.bind([s],function(t){this.commonObjs.resolve(e,s)}.bind(this));break;case"FontPath":this.commonObjs.resolve(e,t[2]);break;default:x("Got unknown common object type "+n)}}},this),t.on("obj",function(t){if(!this.destroyed){var e,n=t[0],r=t[1],i=t[2],a=this.pageCache[r];if(!a.objs.hasData(n))switch(i){case"JpegStream":e=t[3],L(n,e,a.objs);break;case"Image":e=t[3],a.objs.resolve(n,e);e&&"data"in e&&e.data.length>8e6&&(a.cleanupAfterRender=!0);break;default:x("Got unknown object type "+i)}}},this),t.on("DocProgress",function(t){if(!this.destroyed){var e=this.loadingTask;e.onProgress&&e.onProgress({loaded:t.loaded,total:t.total})}},this),t.on("PageError",function(t){if(!this.destroyed){var e=this.pageCache[t.pageNum-1],n=e.intentStates[t.intent];if(n.displayReadyCapability?n.displayReadyCapability.reject(t.error):x(t.error),n.operatorList){n.operatorList.lastChunk=!0;for(var r=0;rthis.numPages)return Promise.reject(new Error("Invalid page request"));var n=t-1;if(n in this.pagePromises)return this.pagePromises[n];var r=this.messageHandler.sendWithPromise("GetPage",{pageIndex:n}).then(function(t){if(this.destroyed)throw new Error("Transport destroyed");var e=new K(n,t,this);return this.pageCache[n]=e,e}.bind(this));return this.pagePromises[n]=r,r},getPageIndex:function(t){return this.messageHandler.sendWithPromise("GetPageIndex",{ref:t}).catch(function(t){return Promise.reject(new Error(t))})},getAnnotations:function(t,e){return this.messageHandler.sendWithPromise("GetAnnotations",{pageIndex:t,intent:e})},getDestinations:function(){return this.messageHandler.sendWithPromise("GetDestinations",null)},getDestination:function(t){return this.messageHandler.sendWithPromise("GetDestination",{id:t})},getPageLabels:function(){return this.messageHandler.sendWithPromise("GetPageLabels",null)},getAttachments:function(){return this.messageHandler.sendWithPromise("GetAttachments",null)},getJavaScript:function(){return this.messageHandler.sendWithPromise("GetJavaScript",null)},getOutline:function(){return this.messageHandler.sendWithPromise("GetOutline",null)},getMetadata:function(){return this.messageHandler.sendWithPromise("GetMetadata",null).then(function(t){return{info:t[0],metadata:t[1]?new D(t[1]):null}})},getStats:function(){return this.messageHandler.sendWithPromise("GetStats",null)},startCleanup:function(){this.messageHandler.sendWithPromise("Cleanup",null).then(function(){for(var t=0,e=this.pageCache.length;t>>8^o[a]}return-1^r}function e(e,n,r,i){var a=i,s=n.length;r[a]=s>>24&255,r[a+1]=s>>16&255,r[a+2]=s>>8&255,r[a+3]=255&s,a+=4,r[a]=255&e.charCodeAt(0),r[a+1]=255&e.charCodeAt(1),r[a+2]=255&e.charCodeAt(2),r[a+3]=255&e.charCodeAt(3),a+=4,r.set(n,a),a+=n.length;var o=t(r,i+4,a);r[a]=o>>24&255,r[a+1]=o>>16&255,r[a+2]=o>>8&255,r[a+3]=255&o}function n(t,e,n){for(var r=1,i=0,a=e;a>3;break;case s.RGB_24BPP:l=2,c=8,h=3*u;break;case s.RGBA_32BPP:l=6,c=8,h=4*u;break;default:throw new Error("invalid format")}var g,m,A=new Uint8Array((1+h)*f),v=0,b=0;for(g=0;g>24&255,u>>16&255,u>>8&255,255&u,f>>24&255,f>>16&255,f>>8&255,255&f,c,l,0,0,0]),x=A.length,S=Math.ceil(x/65535),w=new Uint8Array(2+x+5*S+4),k=0;w[k++]=120,w[k++]=156;for(var C=0;x>65535;)w[k++]=0,w[k++]=255,w[k++]=255,w[k++]=0,w[k++]=0,w.set(A.subarray(C,C+65535),k),k+=65535,C+=65535,x-=65535;w[k++]=1,w[k++]=255&x,w[k++]=x>>8&255,w[k++]=255&~x,w[k++]=(65535&~x)>>8&255,w.set(A.subarray(C),k),k+=A.length-C;var _=n(A,0,A.length);w[k++]=_>>24&255,w[k++]=_>>16&255,w[k++]=_>>8&255,w[k++]=255&_;var T=i.length+3*a+y.length+w.length,P=new Uint8Array(T),L=0;return P.set(i,L),L+=i.length,e("IHDR",y,P,L),L+=a+y.length,e("IDATA",w,P,L),L+=a+w.length,e("IEND",new Uint8Array(0),P,L),d(P,"image/png",o)}for(var i=new Uint8Array([137,80,78,71,13,10,26,10]),a=12,o=new Int32Array(256),c=0;c<256;c++){for(var l=c,h=0;h<8;h++)l=1&l?3988292384^l>>1&2147483647:l>>1&2147483647;o[c]=l}return function(t,e){return r(t,void 0===t.kind?s.GRAYSCALE_1BPP:t.kind,e)}}(),g=function(){function t(){this.fontSizeScale=1,this.fontWeight=f.fontWeight,this.fontSize=0,this.textMatrix=a,this.fontMatrix=i,this.leading=0,this.x=0,this.y=0,this.lineX=0,this.lineY=0,this.charSpacing=0,this.wordSpacing=0,this.textHScale=1,this.textRise=0,this.fillColor=f.fillColor,this.strokeColor="#000000",this.fillAlpha=1,this.strokeAlpha=1,this.lineWidth=1,this.lineJoin="",this.lineCap="",this.miterLimit=0,this.dashArray=[],this.dashPhase=0,this.dependencies=[],this.activeClipUrl=null,this.clipGroup=null,this.maskId=""}return t.prototype={clone:function(){return Object.create(this)},setCurrentPoint:function(t,e){this.x=t,this.y=e}},t}(),m=function(){function t(t){for(var e=[],n=[],r=t.length,i=0;i1&&(h.vertical?s.canvasWidth=n.height*e._viewport.scale:s.canvasWidth=n.width*e._viewport.scale),e._textDivProperties.set(i,s),e._enhanceTextSelection){var m=1,A=0;0!==l&&(m=Math.cos(l),A=Math.sin(l));var v,b,y=(h.vertical?n.height:n.width)*e._viewport.scale,x=u;0!==l?(v=[m,A,-A,m,f,g],b=a.getAxialAlignedBoundingBox([0,0,y,x],v)):b=[f,g,f+y,g+x],e._bounds.push({left:b[0],top:b[1],right:b[2],bottom:b[3],div:i,size:[y,x],m:v})}}function n(t){if(!t._canceled){var e=t._container,n=t._textDivs,r=t._capability,i=n.length;if(i>d)return t._renderingDone=!0,void r.resolve();var a=document.createElement("canvas");a.mozOpaque=!0;for(var s,c,l=a.getContext("2d",{alpha:!1}),h=0;h0&&(f.scale=f.canvasWidth/m,A="scaleX("+f.scale+")"),0!==f.angle&&(A="rotate("+f.angle+"deg) "+A),""!==A&&(f.originalTransform=A,o.setProp("transform",u,A)),t._textDivProperties.set(u,f)}}t._renderingDone=!0,r.resolve()}}function r(t){for(var e=t._bounds,n=t._viewport,r=i(n.width,n.height,e),s=0;s0&&(r=r?Math.min(a,r):a)}return r},A=1+Math.min(Math.abs(d),Math.abs(f));c.paddingLeft=m(g,32,16)/A,c.paddingTop=m(g,48,16)/A,c.paddingRight=m(g,0,16)/A,c.paddingBottom=m(g,16,16)/A,t._textDivProperties.set(o,c)}else c.paddingLeft=e[s].left-r[s].left,c.paddingTop=e[s].top-r[s].top,c.paddingRight=r[s].right-e[s].right,c.paddingBottom=r[s].bottom-e[s].bottom,t._textDivProperties.set(o,c)}}function i(t,e,n){var r=n.map(function(t,e){return{x1:t.left,y1:t.top,x2:t.right,y2:t.bottom,index:e,x1New:void 0,x2New:void 0}});l(t,r);var i=new Array(n.length);return r.forEach(function(t){var e=t.index;i[e]={left:t.x1New,top:0,right:t.x2New,bottom:0}}),n.map(function(e,n){var a=i[n],s=r[n];s.x1=e.top,s.y1=t-a.right,s.x2=e.bottom,s.y2=t-a.left,s.index=n,s.x1New=void 0,s.x2New=void 0}),l(e,r),r.forEach(function(t){var e=t.index;i[e].top=t.x1New,i[e].bottom=t.x2New}),i}function l(t,e){e.sort(function(t,e){return t.x1-e.x1||t.index-e.index});var n={x1:-1/0,y1:-1/0,x2:0,y2:1/0,index:-1,x1New:0,x2New:0},r=[{start:-1/0,end:1/0,boundary:n}];e.forEach(function(t){for(var e=0;e=0&&r[n].start>=t.y2;)n--;var i,a,s,o,c=-1/0;for(s=e;s<=n;s++){i=r[s],a=i.boundary;var l;l=a.x2>t.x1?a.index>t.index?a.x1New:t.x1:void 0===a.x2New?(a.x2+t.x1)/2:a.x2New,l>c&&(c=l)}for(t.x1New=c,s=e;s<=n;s++)i=r[s],a=i.boundary,void 0===a.x2New?a.x2>t.x1?a.index>t.index&&(a.x2New=a.x2):a.x2New=c:a.x2New>c&&(a.x2New=Math.max(c,a.x2));var h=[],u=null;for(s=e;s<=n;s++){i=r[s],a=i.boundary;var d=a.x2>t.x2?a:t;u===d?h[h.length-1].end=i.end:(h.push({start:i.start,end:i.end,boundary:d}),u=d)}for(r[e].start=0&&r[o].start>=a.y1;o--)f=r[o].boundary===a;for(o=n+1;!f&&o\\376\\377([^<]+)/g,function(t,e){for(var n=e.replace(/\\([0-3])([0-7])([0-7])/g,function(t,e,n,r){return String.fromCharCode(64*e+8*n+1*r)}),r="",i=0;i=32&&a<127&&60!==a&&62!==a&&38!==a?String.fromCharCode(a):"&#x"+(65536+a).toString(16).substring(1)+";"}return">"+r})}function i(t){if("string"==typeof t){t=r(t);t=(new DOMParser).parseFromString(t,"application/xml")}else t instanceof Document||s("Metadata: Invalid metadata object");this.metaDocument=t,this.metadata=Object.create(null),this.parse()}var a=n(0),s=a.error;i.prototype={parse:function(){var t=this.metaDocument,e=t.documentElement;if("rdf:rdf"!==e.nodeName.toLowerCase())for(e=e.firstChild;e&&"rdf:rdf"!==e.nodeName.toLowerCase();)e=e.nextSibling;var n=e?e.nodeName.toLowerCase():null;if(e&&"rdf:rdf"===n&&e.hasChildNodes()){var r,i,a,s,o,c,l,h=e.childNodes;for(s=0,c=h.length;s0;)d[f++]=g&p?0:255,p>>=1;var m=0;for(f=0,0!==d[f]&&(c[0]=1,++m),n=1;n>2)+(d[f+1]?4:0)+(d[f-h+1]?8:0),l[A]&&(c[r+n]=l[A],++m),f++;if(d[f-h]!==d[f]&&(c[r+n]=d[f]?2:4,++m),m>1e3)return null}for(f=h*(s-1),r=e*o,0!==d[f]&&(c[r]=8,++m),n=1;n1e3)return null;var v=new Int32Array([0,o,-1,0,-o,0,0,0,1]),b=[];for(e=0;m&&e<=s;e++){for(var y=e*o,x=y+a;y>4,c[y]&=k>>2|k<<2),w.push(y%o),w.push(y/o|0),--m}while(C!==y);b.push(w),--e}}return function(t){t.save(),t.scale(1/a,-1/s),t.translate(0,-s),t.beginPath();for(var e=0,n=b.length;e>3,w=4294967295,k=E.value||!L.value?4278190080:255;for(r=0;rS?c:8*C-7,R=-8&T,I=0,F=0;_>=1}for(;n=h&&(a=l,s=c*a),n=0,i=s;i--;)A[n++]=m[g++],A[n++]=m[g++],A[n++]=m[g++],A[n++]=255;t.putImageData(f,0,r*P)}else x("bad image kind: "+e.kind)}function n(t,e){for(var n=e.height,r=e.width,i=n%P,a=(n-i)/P,s=0===i?a:a+1,o=t.createImageData(r,P),c=0,l=e.data,h=o.data,u=0;u>=1}t.putImageData(o,0,u*P)}}function a(t,e){for(var n=["strokeStyle","fillStyle","fillRule","globalAlpha","lineWidth","lineCap","lineJoin","miterLimit","globalCompositeOperation","font"],r=0,i=n.length;r>8,t[a-2]=t[a-2]*s+n*o>>8,t[a-1]=t[a-1]*s+r*o>>8}}}function o(t,e,n){for(var r=t.length,i=3;i>8]>>8:e[i]*a>>16}}function y(t,e,n,r,i,a,l){var h,u=!!a,d=u?a[0]:0,f=u?a[1]:0,p=u?a[2]:0;h="Luminosity"===i?c:o;for(var g=Math.min(r,Math.ceil(1048576/n)),m=0;m10&&"function"==typeof n,h=l?Date.now()+15:0,u=0,f=this.commonObjs,p=this.objs;;){if(void 0!==r&&s===r.nextBreakPoint)return r.breakIt(s,n),s;if((c=a[s])!==d.dependency)this[c].apply(this,i[s]);else for(var g=i[s],m=0,A=g.length;m10){if(Date.now()>h)return n(),s;u=0}}},endDrawing:function(){null!==this.current.activeSMask&&this.endSMaskGroup(),this.ctx.restore(),this.transparentCanvas&&(this.ctx=this.compositeCtx,this.ctx.save(),this.ctx.setTransform(1,0,0,1,0,0),this.ctx.drawImage(this.transparentCanvas,0,0),this.ctx.restore(),this.transparentCanvas=null),this.cachedCanvases.clear(),_.clear(),this.imageLayer&&this.imageLayer.endLayout()},setLineWidth:function(t){this.current.lineWidth=t,this.ctx.lineWidth=t},setLineCap:function(t){this.ctx.lineCap=F[t]},setLineJoin:function(t){this.ctx.lineJoin=O[t]},setMiterLimit:function(t){this.ctx.miterLimit=t},setDash:function(t,e){var n=this.ctx;void 0!==n.setLineDash&&(n.setLineDash(t),n.lineDashOffset=e)},setRenderingIntent:function(t){},setFlatness:function(t){},setGState:function(t){for(var e=0,n=t.length;e0&&this.stateStack[this.stateStack.length-1].activeSMask===this.current.activeSMask?this.suspendSMaskGroup():this.endSMaskGroup()),this.current.activeSMask=a?this.tempSMask:null,this.current.activeSMask&&this.beginSMaskGroup(),this.tempSMask=null}}},beginSMaskGroup:function(){var t=this.current.activeSMask,e=t.canvas.width,n=t.canvas.height,r="smaskGroupAt"+this.groupLevel,i=this.cachedCanvases.getCanvas(r,e,n,!0),s=this.ctx,o=s.mozCurrentTransform;this.ctx.save();var c=i.context;c.scale(1/t.scaleX,1/t.scaleY),c.translate(-t.offsetX,-t.offsetY),c.transform.apply(c,o),t.startTransformInverse=c.mozCurrentTransformInverse,a(s,c),this.ctx=c,this.setGState([["BM","Normal"],["ca",1],["CA",1]]),this.groupStack.push(s),this.groupLevel++},suspendSMaskGroup:function(){var t=this.ctx;this.groupLevel--,this.ctx=this.groupStack.pop(),T(this.ctx,this.current.activeSMask,t),this.ctx.restore(),this.ctx.save(),a(t,this.ctx),this.current.resumeSMaskCtx=t;var e=g.transform(this.current.activeSMask.startTransformInverse,t.mozCurrentTransform);this.ctx.transform.apply(this.ctx,e),t.save(),t.setTransform(1,0,0,1,0,0),t.clearRect(0,0,t.canvas.width,t.canvas.height),t.restore()},resumeSMaskGroup:function(){var t=this.current.resumeSMaskCtx,e=this.ctx;this.ctx=t,this.groupStack.push(e),this.groupLevel++},endSMaskGroup:function(){var t=this.ctx;this.groupLevel--,this.ctx=this.groupStack.pop(),T(this.ctx,this.current.activeSMask,t),this.ctx.restore(),a(t,this.ctx);var e=g.transform(this.current.activeSMask.startTransformInverse,t.mozCurrentTransform);this.ctx.transform.apply(this.ctx,e)},save:function(){this.ctx.save();var t=this.current;this.stateStack.push(t),this.current=t.clone(),this.current.resumeSMaskCtx=null},restore:function(){this.current.resumeSMaskCtx&&this.resumeSMaskGroup(),null===this.current.activeSMask||0!==this.stateStack.length&&this.stateStack[this.stateStack.length-1].activeSMask===this.current.activeSMask||this.endSMaskGroup(),0!==this.stateStack.length&&(this.current=this.stateStack.pop(),this.ctx.restore(),this.pendingClip=null,this.cachedGetSinglePixelWidth=null)},transform:function(t,e,n,r,i,a){this.ctx.transform(t,e,n,r,i,a),this.cachedGetSinglePixelWidth=null},constructPath:function(t,e){for(var n=this.ctx,r=this.current,i=r.x,a=r.y,s=0,o=0,c=t.length;s100?100:e;this.current.fontSizeScale=e/c;var h=s+" "+a+" "+c+"px "+o;this.ctx.font=h}},setTextRenderingMode:function(t){this.current.textRenderingMode=t},setTextRise:function(t){this.current.textRise=t},moveText:function(t,e){this.current.x=this.current.lineX+=t,this.current.y=this.current.lineY+=e},setLeadingMoveText:function(t,e){this.setLeading(-e),this.moveText(t,e)},setTextMatrix:function(t,e,n,r,i,a){this.current.textMatrix=[t,e,n,r,i,a],this.current.textMatrixScale=Math.sqrt(t*t+e*e),this.current.x=this.current.lineX=0,this.current.y=this.current.lineY=0},nextLine:function(){this.moveText(0,this.current.leading)},paintChar:function(t,e,n){var r,i=this.ctx,a=this.current,s=a.font,o=a.textRenderingMode,c=a.fontSize/a.fontSizeScale,l=o&f.FILL_STROKE_MASK,h=!!(o&f.ADD_TO_PATH_FLAG);if((s.disableFontFace||h)&&(r=s.getPathGenerator(this.commonObjs,t)),s.disableFontFace?(i.save(),i.translate(e,n),i.beginPath(),r(i,c),l!==f.FILL&&l!==f.FILL_STROKE||i.fill(),l!==f.STROKE&&l!==f.FILL_STROKE||i.stroke(),i.restore()):(l!==f.FILL&&l!==f.FILL_STROKE||i.fillText(t,e,n),l!==f.STROKE&&l!==f.FILL_STROKE||i.strokeText(t,e,n)),h){(this.pendingTextPaths||(this.pendingTextPaths=[])).push({transform:i.mozCurrentTransform,x:e,y:n,fontSize:c,addToPath:r})}},get isFontSubpixelAAEnabled(){var t=this.canvasFactory.create(10,10).context;t.scale(1.5,1),t.fillText("I",0,10);for(var e=t.getImageData(0,0,10,10).data,n=!1,r=3;r0&&e[r]<255){n=!0;break}return S(this,"isFontSubpixelAAEnabled",n)},showText:function(t){var e=this.current,n=e.font;if(n.isType3Font)return this.showType3Text(t);var r=e.fontSize;if(0!==r){var i=this.ctx,a=e.fontSizeScale,s=e.charSpacing,o=e.wordSpacing,c=e.fontDirection,l=e.textHScale*c,h=t.length,u=n.vertical,d=u?1:-1,p=n.defaultVMetrics,g=r*e.fontMatrix[0],m=e.textRenderingMode===f.FILL&&!n.disableFontFace;i.save(),i.transform.apply(i,e.textMatrix),i.translate(e.x,e.y+e.textRise),e.patternFill&&(i.fillStyle=e.fillColor.getPattern(i,this)),c>0?i.scale(l,-1):i.scale(l,1);var A=e.lineWidth,b=e.textMatrixScale;if(0===b||0===A){var y=e.textRenderingMode&f.FILL_STROKE_MASK;y!==f.STROKE&&y!==f.FILL_STROKE||(this.cachedGetSinglePixelWidth=null,A=.65*this.getSinglePixelWidth())}else A/=b;1!==a&&(i.scale(a,a),A/=a),i.lineWidth=A;var x,S=0;for(x=0;x0){var D=1e3*i.measureText(E).width/r*a;if(I4096&&(h=c/4096,c=4096),l>4096&&(u=l/4096,l=4096);var d="groupAt"+this.groupLevel;t.smask&&(d+="_smask_"+this.smaskCounter++%2);var f=this.cachedCanvases.getCanvas(d,c,l,!0),p=f.context;p.scale(1/h,1/u),p.translate(-s,-o),p.transform.apply(p,n),t.smask?this.smaskStack.push({canvas:f.canvas,context:p,offsetX:s,offsetY:o,scaleX:h,scaleY:u,subtype:t.smask.subtype,backdrop:t.smask.backdrop,transferMap:t.smask.transferMap||null,startTransformInverse:null}):(e.setTransform(1,0,0,1,0,0),e.translate(s,o),e.scale(h,u)),a(e,p),this.ctx=p,this.setGState([["BM","Normal"],["ca",1],["CA",1]]),this.groupStack.push(e),this.groupLevel++,this.current.activeSMask=null},endGroup:function(t){this.groupLevel--;var e=this.ctx;this.ctx=this.groupStack.pop(),void 0!==this.ctx.imageSmoothingEnabled?this.ctx.imageSmoothingEnabled=!1:this.ctx.mozImageSmoothingEnabled=!1,t.smask?this.tempSMask=this.smaskStack.pop():this.ctx.drawImage(e.canvas,0,0),this.restore()},beginAnnotations:function(){this.save(),this.current=new I,this.baseTransform&&this.ctx.setTransform.apply(this.ctx,this.baseTransform)},endAnnotations:function(){this.restore()},beginAnnotation:function(t,e,n){if(this.save(),b(t)&&4===t.length){var r=t[2]-t[0],i=t[3]-t[1];this.ctx.rect(t[0],t[1],r,i),this.clip(),this.endPath()}this.transform.apply(this,e),this.transform.apply(this,n)},endAnnotation:function(){this.restore()},paintJpegXObject:function(t,e,n){var r=this.objs.get(t);if(!r)return void w("Dependent image isn't ready yet");this.save();var i=this.ctx;if(i.scale(1/e,-1/n),i.drawImage(r,0,0,r.width,r.height,0,-n,e,n),this.imageLayer){var a=i.mozCurrentTransformInverse,s=this.getCanvasPosition(0,0);this.imageLayer.appendImage({objId:t,left:s[0],top:s[1],width:e/a[0],height:n/a[3]})}this.restore()},paintImageMaskXObject:function(t){var e=this.ctx,r=t.width,a=t.height,s=this.current.fillColor,o=this.current.patternFill,c=this.processingType3;if(c&&void 0===c.compiled&&(c.compiled=r<=1e3&&a<=1e3?i({data:t.data,width:r,height:a}):null),c&&c.compiled)return void c.compiled(e);var l=this.cachedCanvases.getCanvas("maskCanvas",r,a),h=l.context;h.save(),n(h,t),h.globalCompositeOperation="source-in",h.fillStyle=o?s.getPattern(h,this):s,h.fillRect(0,0,r,a),h.restore(),this.paintInlineImageXObject(l.canvas)},paintImageMaskXObjectRepeat:function(t,e,r,i){var a=t.width,s=t.height,o=this.current.fillColor,c=this.current.patternFill,l=this.cachedCanvases.getCanvas("maskCanvas",a,s),h=l.context;h.save(),n(h,t),h.globalCompositeOperation="source-in",h.fillStyle=c?o.getPattern(h,this):o,h.fillRect(0,0,a,s),h.restore();for(var u=this.ctx,d=0,f=i.length;d2&&g>1||f>2&&m>1;){var v=g,b=m;h>2&&g>1&&(v=Math.ceil(g/2),h/=g/v),f>2&&m>1&&(b=Math.ceil(m/2),f/=m/b),s=this.cachedCanvases.getCanvas(A,v,b),p=s.context,p.clearRect(0,0,v,b),p.drawImage(a,0,0,g,m,0,0,v,b),a=s.canvas,g=v,m=b,A="prescale1"===A?"prescale2":"prescale1"}if(i.drawImage(a,0,0,g,m,0,-r,n,r),this.imageLayer){var y=this.getCanvasPosition(0,-r);this.imageLayer.appendImage({imgData:t,left:y[0],top:y[1],width:n/o[0],height:r/o[3]})}this.restore()},paintInlineImageXObjectGroup:function(t,n){var r=this.ctx,i=t.width,a=t.height,s=this.cachedCanvases.getCanvas("inlineImage",i,a);e(s.context,t);for(var o=0,c=n.length;o0&&!r.isSyncFontLoadingSupported?this.prepareFontLoadEvent(n,i,f):f.complete()},r.prototype.queueLoadingCallback=function(t){function e(){for(a(!i.end,"completeRequest() cannot be called twice"),i.end=Date.now();n.requests.length>0&&n.requests[0].end;){var t=n.requests.shift();setTimeout(t.callback,0)}}var n=this.loadingContext,r="pdfjs-font-loading-"+n.nextRequestId++,i={id:r,complete:e,callback:t,started:Date.now()};return n.requests.push(i),i},r.prototype.prepareFontLoadEvent=function(t,e,n){function r(t,e){return t.charCodeAt(e)<<24|t.charCodeAt(e+1)<<16|t.charCodeAt(e+2)<<8|255&t.charCodeAt(e+3)}function i(t,e,n,r){return t.substr(0,e)+r+t.substr(e+n)}function a(t,e){return++d>30?(l("Load test font never loaded."),void e()):(u.font="30px "+t,u.fillText(".",0,20),u.getImageData(0,0,1,1).data[3]>0?void e():void setTimeout(a.bind(null,t,e)))}var s,c,h=document.createElement("canvas");h.width=1,h.height=1;var u=h.getContext("2d"),d=0,f="lt"+Date.now()+this.loadTestFontId++,p=this.loadTestFont;p=i(p,976,f.length,f);var g=r(p,16);for(s=0,c=f.length-3;s=14&&(t=!0),t};Object.defineProperty(r,"isSyncFontLoadingSupported",{get:function(){return c(r,"isSyncFontLoadingSupported",u())},enumerable:!0,configurable:!0});var d={get value(){return c(this,"value",i.isEvalSupported())}},f=function(){function t(t,e){this.compiledGlyphs=Object.create(null);for(var n in t)this[n]=t[n];this.options=e}return t.prototype={createNativeFontFace:function(){if(!this.data)return null;if(this.options.disableFontFace)return this.disableFontFace=!0,null;var t=new FontFace(this.loadedName,this.data,{});return this.options.fontRegistry&&this.options.fontRegistry.registerFont(this),t},createFontFaceRule:function(){if(!this.data)return null;if(this.options.disableFontFace)return this.disableFontFace=!0,null;var t=s(new Uint8Array(this.data)),e=this.loadedName,n="url(data:"+this.mimetype+";base64,"+btoa(t)+");",r='@font-face { font-family:"'+e+'";src:'+n+"}";return this.options.fontRegistry&&this.options.fontRegistry.registerFont(this,n),r},getPathGenerator:function(t,e){if(!(e in this.compiledGlyphs)){var n,r,i,a=t.get(this.loadedName+"_path_"+e);if(this.options.isEvalSupported&&d.value){var s,o="";for(r=0,i=a.length;rl[r+1]&&(c=n,n=r,r=c,c=a,a=s,s=c),l[r+1]>l[i+1]&&(c=r,r=i,i=c,c=s,s=o,o=c),l[n+1]>l[r+1]&&(c=n,n=r,r=c,c=a,a=s,s=c);var f=(l[n]+e.offsetX)*e.scaleX,p=(l[n+1]+e.offsetY)*e.scaleY,g=(l[r]+e.offsetX)*e.scaleX,m=(l[r+1]+e.offsetY)*e.scaleY,A=(l[i]+e.offsetX)*e.scaleX,v=(l[i+1]+e.offsetY)*e.scaleY;if(!(p>=v))for(var b,y,x,S,w,k,C,_,T,P=h[a],L=h[a+1],E=h[a+2],R=h[s],I=h[s+1],F=h[s+2],O=h[o],M=h[o+1],D=h[o+2],N=Math.round(p),j=Math.round(v),U=N;U<=j;U++){Uv?1:m===v?0:(m-U)/(m-v),b=g-(g-A)*T,y=R-(R-O)*T,x=I-(I-M)*T,S=F-(F-D)*T),T=Uv?1:(p-U)/(p-v),w=f-(f-A)*T,k=P-(P-O)*T,C=L-(L-M)*T,_=E-(E-D)*T;for(var B=Math.round(Math.min(b,w)),W=Math.round(Math.max(b,w)),G=d*U+4*B,X=B;X<=W;X++)T=(b-X)/(b-w),T=T<0?0:T>1?1:T,u[G++]=y-(y-k)*T|0,u[G++]=x-(x-C)*T|0,u[G++]=S-(S-_)*T|0,u[G++]=255}}function e(e,n,r){var i,a,s=n.coords,o=n.colors;switch(n.type){case"lattice":var c=n.verticesPerRow,h=Math.floor(s.length/c)-1,u=c-1;for(i=0;i=0,o=/Chrome\/(39|40)\./.test(n),c=n.indexOf("CriOS")>=0,l=n.indexOf("Trident")>=0,h=/\b(iPad|iPhone|iPod)(?=;)/.test(n),u=n.indexOf("Opera")>=0,d=/Safari\//.test(n)&&!/(Chrome\/|Android\s)/.test(n),f="object"==typeof window&&"object"==typeof document;"undefined"==typeof PDFJS&&(e.PDFJS={}),PDFJS.compatibilityChecked=!0,function(){function t(t,e){return new r(this.slice(t,e))}function n(t,e){arguments.length<2&&(e=0);for(var n=0,r=t.length;n>2,l=(3&a)<<4|s>>4,h=n+1>6:64,u=n+2>(-2*r&6)):0)n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(n);return a}}}(),function(){void 0===Function.prototype.bind&&(Function.prototype.bind=function(t){var e=this,n=Array.prototype.slice.call(arguments,1);return function(){var r=n.concat(Array.prototype.slice.call(arguments));return e.apply(t,r)}})}(),function(){if(f){"dataset"in document.createElement("div")||Object.defineProperty(HTMLElement.prototype,"dataset",{get:function(){if(this._dataset)return this._dataset;for(var t={},e=0,n=this.attributes.length;e=0&&r&&a.splice(s,1),t.className=a.join(" "),s>=0}if(f){if(!("classList"in document.createElement("div"))){var e={add:function(e){t(this.element,e,!0,!1)},contains:function(e){return t(this.element,e,!1,!1)},remove:function(e){t(this.element,e,!1,!0)},toggle:function(e){t(this.element,e,!0,!0)}};Object.defineProperty(HTMLElement.prototype,"classList",{get:function(){if(this._classList)return this._classList;var t=Object.create(e,{element:{value:this,writable:!1,enumerable:!0}});return Object.defineProperty(this,"_classList",{value:t,writable:!1,enumerable:!1}),t},enumerable:!0})}}}(),function(){if(!("undefined"==typeof importScripts||"console"in e)){var t={},n={log:function(){var t=Array.prototype.slice.call(arguments);e.postMessage({targetName:"main",action:"console_log",data:t})},error:function(){var t=Array.prototype.slice.call(arguments);e.postMessage({targetName:"main",action:"console_error",data:t})},time:function(e){t[e]=Date.now()},timeEnd:function(e){var n=t[e];if(!n)throw new Error("Unknown timer name "+e);this.log("Timer:",e,Date.now()-n)}};e.console=n}}(),function(){if(f)"console"in window?"bind"in console.log||(console.log=function(t){return function(e){return t(e)}}(console.log),console.error=function(t){return function(e){return t(e)}}(console.error),console.warn=function(t){return function(e){return t(e)}}(console.warn)):window.console={log:function(){},error:function(){},warn:function(){}}}(),function(){function t(t){e(t.target)&&t.stopPropagation()}function e(t){return t.disabled||t.parentNode&&e(t.parentNode)}u&&document.addEventListener("click",t,!0)}(),function(){(l||c)&&(PDFJS.disableCreateObjectURL=!0)}(),function(){"undefined"!=typeof navigator&&("language"in navigator||(PDFJS.locale=navigator.userLanguage||"en-US"))}(),function(){(d||i||o||h)&&(PDFJS.disableRange=!0,PDFJS.disableStream=!0)}(),function(){f&&(history.pushState&&!i||(PDFJS.disableHistory=!0))}(),function(){if(f)if(window.CanvasPixelArray)"function"!=typeof window.CanvasPixelArray.prototype.set&&(window.CanvasPixelArray.prototype.set=function(t){for(var e=0,n=this.length;e0;){var n=this.handlers.shift(),r=n.thisPromise._status,i=n.thisPromise._value;try{1===r?"function"==typeof n.onResolve&&(i=n.onResolve(i)):"function"==typeof n.onReject&&(i=n.onReject(i),r=1,n.thisPromise._unhandledRejection&&this.removeUnhandeledRejection(n.thisPromise))}catch(e){r=t,i=e}if(n.nextPromise._updateStatus(r,i),Date.now()>=e)break}if(this.handlers.length>0)return void setTimeout(this.runHandlers.bind(this),0);this.running=!1},addUnhandledRejection:function(t){this.unhandledRejections.push({promise:t,time:Date.now()}),this.scheduleRejectionCheck()},removeUnhandeledRejection:function(t){t._unhandledRejection=!1;for(var e=0;e500){var n=this.unhandledRejections[e].promise._value,r="Unhandled rejection: "+n;n.stack&&(r+="\n"+n.stack);try{throw new Error(r)}catch(t){console.warn(r)}this.unhandledRejections.splice(e),e--}this.unhandledRejections.length&&this.scheduleRejectionCheck()}.bind(this),500))}},r=function(t){this._status=0,this._handlers=[];try{t.call(this,this._resolve.bind(this),this._reject.bind(this))}catch(t){this._reject(t)}};r.all=function(e){function n(e){s._status!==t&&(c=[],a(e))}var i,a,s=new r(function(t,e){i=t,a=e}),o=e.length,c=[];if(0===o)return i(c),s;for(var l=0,h=e.length;l32&&e<127&&-1===[34,35,60,62,63,96].indexOf(e)?t:encodeURIComponent(t)}function a(t){var e=t.charCodeAt(0);return e>32&&e<127&&-1===[34,35,60,62,96].indexOf(e)?t:encodeURIComponent(t)}function s(e,s,o){function c(t){b.push(t)}var l=s||"scheme start",h=0,m="",A=!1,v=!1,b=[];t:for(;(e[h-1]!==f||0===h)&&!this._isInvalid;){var y=e[h];switch(l){case"scheme start":if(!y||!p.test(y)){if(s){c("Invalid scheme.");break t}m="",l="no scheme";continue}m+=y.toLowerCase(),l="scheme";break;case"scheme":if(y&&g.test(y))m+=y.toLowerCase();else{if(":"!==y){if(s){if(y===f)break t;c("Code point not allowed in scheme: "+y);break t}m="",h=0,l="no scheme";continue}if(this._scheme=m,m="",s)break t;t(this._scheme)&&(this._isRelative=!0),l="file"===this._scheme?"relative":this._isRelative&&o&&o._scheme===this._scheme?"relative or authority":this._isRelative?"authority first slash":"scheme data"}break;case"scheme data":"?"===y?(this._query="?",l="query"):"#"===y?(this._fragment="#",l="fragment"):y!==f&&"\t"!==y&&"\n"!==y&&"\r"!==y&&(this._schemeData+=i(y));break;case"no scheme":if(o&&t(o._scheme)){l="relative";continue}c("Missing scheme."),n.call(this);break;case"relative or authority":if("/"!==y||"/"!==e[h+1]){c("Expected /, got: "+y),l="relative";continue}l="authority ignore slashes";break;case"relative":if(this._isRelative=!0,"file"!==this._scheme&&(this._scheme=o._scheme),y===f){this._host=o._host,this._port=o._port,this._path=o._path.slice(),this._query=o._query,this._username=o._username,this._password=o._password;break t}if("/"===y||"\\"===y)"\\"===y&&c("\\ is an invalid code point."),l="relative slash";else if("?"===y)this._host=o._host,this._port=o._port,this._path=o._path.slice(),this._query="?",this._username=o._username,this._password=o._password,l="query";else{if("#"!==y){var x=e[h+1],S=e[h+2];("file"!==this._scheme||!p.test(y)||":"!==x&&"|"!==x||S!==f&&"/"!==S&&"\\"!==S&&"?"!==S&&"#"!==S)&&(this._host=o._host,this._port=o._port,this._username=o._username,this._password=o._password,this._path=o._path.slice(),this._path.pop()),l="relative path";continue}this._host=o._host,this._port=o._port,this._path=o._path.slice(),this._query=o._query,this._fragment="#",this._username=o._username,this._password=o._password,l="fragment"}break;case"relative slash":if("/"!==y&&"\\"!==y){"file"!==this._scheme&&(this._host=o._host,this._port=o._port,this._username=o._username,this._password=o._password),l="relative path";continue}"\\"===y&&c("\\ is an invalid code point."),l="file"===this._scheme?"file host":"authority ignore slashes";break;case"authority first slash":if("/"!==y){c("Expected '/', got: "+y),l="authority ignore slashes";continue}l="authority second slash";break;case"authority second slash":if(l="authority ignore slashes","/"!==y){c("Expected '/', got: "+y);continue}break;case"authority ignore slashes":if("/"!==y&&"\\"!==y){l="authority";continue}c("Expected authority, got: "+y);break;case"authority":if("@"===y){A&&(c("@ already seen."),m+="%40"),A=!0;for(var w=0;w=o.WARNINGS&&console.log("Warning: "+e)}function l(e){throw new Error(e)}function c(e,t){e||l(t)}var h=function(){function e(e,t){this.name="PasswordException",this.message=e,this.code=t}return e.prototype=new Error,e.constructor=e,e}(),d=function(){function e(e,t){this.name="UnknownErrorException",this.message=e,this.details=t}return e.prototype=new Error,e.constructor=e,e}(),f=function(){function e(e){this.name="InvalidPDFException",this.message=e}return e.prototype=new Error,e.constructor=e,e}(),p=function(){function e(e){this.name="MissingPDFException",this.message=e}return e.prototype=new Error,e.constructor=e,e}(),v=function(){function e(e,t){this.name="UnexpectedResponseException",this.message=e,this.status=t}return e.prototype=new Error,e.constructor=e,e}(),m=function(){function e(e,t){this.begin=e,this.end=t,this.message="Missing data ["+e+", "+t+")"}return e.prototype=new Error,e.prototype.name="MissingDataException",e.constructor=e,e}(),g=function(){function e(e){this.message=e}return e.prototype=new Error,e.prototype.name="XRefParseException",e.constructor=e,e}(),y=function(){function e(e){this.message=e}return e.prototype=new Error,e.prototype.name="FormatError",e.constructor=e,e}(),b=function(){function e(e){this.name="AbortException",this.message=e}return e.prototype=new Error,e.constructor=e,e}(),_=/\x00/g;function A(e){c("string"==typeof e,"Invalid argument for stringToBytes");for(var t=e.length,r=new Uint8Array(t),n=0;ne[2]&&(t[0]=e[2],t[2]=e[0]),e[1]>e[3]&&(t[1]=e[3],t[3]=e[1]),t},e.intersect=function(t,r){function n(e,t){return e-t}var i=[t[0],t[2],r[0],r[2]].sort(n),a=[t[1],t[3],r[1],r[3]].sort(n),o=[];return t=e.normalizeRect(t),r=e.normalizeRect(r),(i[0]===t[0]&&i[1]===r[0]||i[0]===r[0]&&i[1]===t[0])&&(o[0]=i[1],o[2]=i[2],(a[0]===t[1]&&a[1]===r[1]||a[0]===r[1]&&a[1]===t[1])&&(o[1]=a[1],o[3]=a[2],o))},e}(),k=["","C","CC","CCC","CD","D","DC","DCC","DCCC","CM","","X","XX","XXX","XL","L","LX","LXX","LXXX","XC","","I","II","III","IV","V","VI","VII","VIII","IX"];var P=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,728,711,710,729,733,731,730,732,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8226,8224,8225,8230,8212,8211,402,8260,8249,8250,8722,8240,8222,8220,8221,8216,8217,8218,8482,64257,64258,321,338,352,376,381,305,322,339,353,382,0,8364];var x,C=(x="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",function(e,t){if(!(arguments.length>2&&void 0!==arguments[2]&&arguments[2])&&a.URL.createObjectURL){var r=new Blob([e],{type:t});return a.URL.createObjectURL(r)}for(var n="data:"+t+";base64,",i=0,o=e.length;i>2]+x[(3&s)<<4|u>>4]+x[i+1>6:64]+x[i+21&&void 0!==arguments[1]&&arguments[1];c(Number.isInteger(e)&&e>0,"The number should be a positive integer.");for(var r=void 0,n=[];e>=1e3;)e-=1e3,n.push("M");r=e/100|0,e%=100,n.push(k[r]),r=e/10|0,e%=10,n.push(k[10+r]),n.push(k[20+e]);var i=n.join("");return t?i.toLowerCase():i},t.XRefParseException=g,t.FormatError=y,t.arrayByteLength=S,t.arraysToBytes=function(e){if(1===e.length&&e[0]instanceof Uint8Array)return e[0];var t,r,n,i=0,a=e.length;for(t=0;t100){u('getInheritableProperty: maximum loop count exceeded for "'+r+'"');break}t=t.get("Parent")}return l},t.getLookupTableFactory=function(e){var t;return function(){return e&&(t=Object.create(null),e(t),e=null),t}},t.getVerbosityLevel=function(){return s},t.info=function(e){s>=o.INFOS&&console.log("Info: "+e)},t.isArrayBuffer=function(e){return"object"===(void 0===e?"undefined":n(e))&&null!==e&&void 0!==e.byteLength},t.isBool=function(e){return"boolean"==typeof e},t.isEmptyObj=function(e){for(var t in e)return!1;return!0},t.isNum=function(e){return"number"==typeof e},t.isString=function(e){return"string"==typeof e},t.isSpace=function(e){return 32===e||9===e||13===e||10===e},t.isSameOrigin=function(e,t){try{var r=new a.URL(e);if(!r.origin||"null"===r.origin)return!1}catch(e){return!1}var n=new a.URL(t,r);return r.origin===n.origin},t.createValidAbsoluteUrl=function(e,t){if(!e)return null;try{var r=t?new a.URL(e,t):new a.URL(e);if(function(e){if(!e)return!1;switch(e.protocol){case"http:":case"https:":case"ftp:":case"mailto:":case"tel:":return!0;default:return!1}}(r))return r}catch(e){}return null},t.isLittleEndian=function(){var e=new Uint8Array(4);return e[0]=1,1===new Uint32Array(e.buffer,0,1)[0]},t.isEvalSupported=function(){try{return new Function(""),!0}catch(e){return!1}},t.log2=function(e){return e<=0?0:Math.ceil(Math.log2(e))},t.readInt8=function(e,t){return e[t]<<24>>24},t.readUint16=function(e,t){return e[t]<<8|e[t+1]},t.readUint32=function(e,t){return(e[t]<<24|e[t+1]<<16|e[t+2]<<8|e[t+3])>>>0},t.removeNullCharacters=function(e){return"string"!=typeof e?(u("The argument for removeNullCharacters must be a string."),e):e.replace(_,"")},t.ReadableStream=i.ReadableStream,t.URL=a.URL,t.setVerbosityLevel=function(e){Number.isInteger(e)&&(s=e)},t.shadow=function(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!1}),r},t.string32=function(e){return String.fromCharCode(e>>24&255,e>>16&255,e>>8&255,255&e)},t.stringToBytes=A,t.stringToPDFString=function(e){var t,r=e.length,n=[];if("þ"===e[0]&&"ÿ"===e[1])for(t=2;t1){var r=!!arguments[1];return this[r?"add":"remove"](t),r}return e(t)}}}(),String.prototype.includes||r(5),Array.prototype.includes||r(33),Object.assign||r(42),Math.log2||(Math.log2=r(52)),Number.isNaN||(Number.isNaN=r(54)),Number.isInteger||(Number.isInteger=r(56)),i.Promise||(i.Promise=r(59)),i.WeakMap||(i.WeakMap=r(94)),String.codePointAt||(String.codePointAt=r(111)),String.fromCodePoint||(String.fromCodePoint=r(113)),i.Symbol||r(115),Object.values||(Object.values=r(122))}},function(e,t,r){"use strict";e.exports="undefined"!=typeof window&&window.Math===Math?window:"undefined"!=typeof global&&global.Math===Math?global:"undefined"!=typeof self&&self.Math===Math?self:{}},function(e,t,r){"use strict";var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};e.exports=function(){return"object"===("undefined"==typeof process?"undefined":n(process))&&process+""=="[object process]"}},function(e,t,r){"use strict";r(6),e.exports=r(9).String.includes},function(e,t,r){"use strict";var n=r(7),i=r(25);n(n.P+n.F*r(32)("includes"),"String",{includes:function(e){return!!~i(this,e,"includes").indexOf(e,arguments.length>1?arguments[1]:void 0)}})},function(e,t,r){"use strict";var n=r(8),i=r(9),a=r(10),o=r(20),s=r(23),u=function e(t,r,u){var l,c,h,d,f=t&e.F,p=t&e.G,v=t&e.P,m=t&e.B,g=p?n:t&e.S?n[r]||(n[r]={}):(n[r]||{}).prototype,y=p?i:i[r]||(i[r]={}),b=y.prototype||(y.prototype={});for(l in p&&(u=r),u)h=((c=!f&&g&&void 0!==g[l])?g:u)[l],d=m&&c?s(h,n):v&&"function"==typeof h?s(Function.call,h):h,g&&o(g,l,h,t&e.U),y[l]!=h&&a(y,l,d),v&&b[l]!=h&&(b[l]=h)};n.core=i,u.F=1,u.G=2,u.S=4,u.P=8,u.B=16,u.W=32,u.U=64,u.R=128,e.exports=u},function(e,t,r){"use strict";var n=e.exports="undefined"!=typeof window&&window.Math==Math?window:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")();"number"==typeof __g&&(__g=n)},function(e,t,r){"use strict";var n=e.exports={version:"2.5.7"};"number"==typeof __e&&(__e=n)},function(e,t,r){"use strict";var n=r(11),i=r(19);e.exports=r(15)?function(e,t,r){return n.f(e,t,i(1,r))}:function(e,t,r){return e[t]=r,e}},function(e,t,r){"use strict";var n=r(12),i=r(14),a=r(18),o=Object.defineProperty;t.f=r(15)?Object.defineProperty:function(e,t,r){if(n(e),t=a(t,!0),n(r),i)try{return o(e,t,r)}catch(e){}if("get"in r||"set"in r)throw TypeError("Accessors not supported!");return"value"in r&&(e[t]=r.value),e}},function(e,t,r){"use strict";var n=r(13);e.exports=function(e){if(!n(e))throw TypeError(e+" is not an object!");return e}},function(e,t,r){"use strict";var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};e.exports=function(e){return"object"===(void 0===e?"undefined":n(e))?null!==e:"function"==typeof e}},function(e,t,r){"use strict";e.exports=!r(15)&&!r(16)(function(){return 7!=Object.defineProperty(r(17)("div"),"a",{get:function(){return 7}}).a})},function(e,t,r){"use strict";e.exports=!r(16)(function(){return 7!=Object.defineProperty({},"a",{get:function(){return 7}}).a})},function(e,t,r){"use strict";e.exports=function(e){try{return!!e()}catch(e){return!0}}},function(e,t,r){"use strict";var n=r(13),i=r(8).document,a=n(i)&&n(i.createElement);e.exports=function(e){return a?i.createElement(e):{}}},function(e,t,r){"use strict";var n=r(13);e.exports=function(e,t){if(!n(e))return e;var r,i;if(t&&"function"==typeof(r=e.toString)&&!n(i=r.call(e)))return i;if("function"==typeof(r=e.valueOf)&&!n(i=r.call(e)))return i;if(!t&&"function"==typeof(r=e.toString)&&!n(i=r.call(e)))return i;throw TypeError("Can't convert object to primitive value")}},function(e,t,r){"use strict";e.exports=function(e,t){return{enumerable:!(1&e),configurable:!(2&e),writable:!(4&e),value:t}}},function(e,t,r){"use strict";var n=r(8),i=r(10),a=r(21),o=r(22)("src"),s=Function.toString,u=(""+s).split("toString");r(9).inspectSource=function(e){return s.call(e)},(e.exports=function(e,t,r,s){var l="function"==typeof r;l&&(a(r,"name")||i(r,"name",t)),e[t]!==r&&(l&&(a(r,o)||i(r,o,e[t]?""+e[t]:u.join(String(t)))),e===n?e[t]=r:s?e[t]?e[t]=r:i(e,t,r):(delete e[t],i(e,t,r)))})(Function.prototype,"toString",function(){return"function"==typeof this&&this[o]||s.call(this)})},function(e,t,r){"use strict";var n={}.hasOwnProperty;e.exports=function(e,t){return n.call(e,t)}},function(e,t,r){"use strict";var n=0,i=Math.random();e.exports=function(e){return"Symbol(".concat(void 0===e?"":e,")_",(++n+i).toString(36))}},function(e,t,r){"use strict";var n=r(24);e.exports=function(e,t,r){if(n(e),void 0===t)return e;switch(r){case 1:return function(r){return e.call(t,r)};case 2:return function(r,n){return e.call(t,r,n)};case 3:return function(r,n,i){return e.call(t,r,n,i)}}return function(){return e.apply(t,arguments)}}},function(e,t,r){"use strict";e.exports=function(e){if("function"!=typeof e)throw TypeError(e+" is not a function!");return e}},function(e,t,r){"use strict";var n=r(26),i=r(31);e.exports=function(e,t,r){if(n(t))throw TypeError("String#"+r+" doesn't accept regex!");return String(i(e))}},function(e,t,r){"use strict";var n=r(13),i=r(27),a=r(28)("match");e.exports=function(e){var t;return n(e)&&(void 0!==(t=e[a])?!!t:"RegExp"==i(e))}},function(e,t,r){"use strict";var n={}.toString;e.exports=function(e){return n.call(e).slice(8,-1)}},function(e,t,r){"use strict";var n=r(29)("wks"),i=r(22),a=r(8).Symbol,o="function"==typeof a;(e.exports=function(e){return n[e]||(n[e]=o&&a[e]||(o?a:i)("Symbol."+e))}).store=n},function(e,t,r){"use strict";var n=r(9),i=r(8),a=i["__core-js_shared__"]||(i["__core-js_shared__"]={});(e.exports=function(e,t){return a[e]||(a[e]=void 0!==t?t:{})})("versions",[]).push({version:n.version,mode:r(30)?"pure":"global",copyright:"© 2018 Denis Pushkarev (zloirock.ru)"})},function(e,t,r){"use strict";e.exports=!1},function(e,t,r){"use strict";e.exports=function(e){if(void 0==e)throw TypeError("Can't call method on "+e);return e}},function(e,t,r){"use strict";var n=r(28)("match");e.exports=function(e){var t=/./;try{"/./"[e](t)}catch(r){try{return t[n]=!1,!"/./"[e](t)}catch(e){}}return!0}},function(e,t,r){"use strict";r(34),e.exports=r(9).Array.includes},function(e,t,r){"use strict";var n=r(7),i=r(35)(!0);n(n.P,"Array",{includes:function(e){return i(this,e,arguments.length>1?arguments[1]:void 0)}}),r(41)("includes")},function(e,t,r){"use strict";var n=r(36),i=r(38),a=r(40);e.exports=function(e){return function(t,r,o){var s,u=n(t),l=i(u.length),c=a(o,l);if(e&&r!=r){for(;l>c;)if((s=u[c++])!=s)return!0}else for(;l>c;c++)if((e||c in u)&&u[c]===r)return e||c||0;return!e&&-1}}},function(e,t,r){"use strict";var n=r(37),i=r(31);e.exports=function(e){return n(i(e))}},function(e,t,r){"use strict";var n=r(27);e.exports=Object("z").propertyIsEnumerable(0)?Object:function(e){return"String"==n(e)?e.split(""):Object(e)}},function(e,t,r){"use strict";var n=r(39),i=Math.min;e.exports=function(e){return e>0?i(n(e),9007199254740991):0}},function(e,t,r){"use strict";var n=Math.ceil,i=Math.floor;e.exports=function(e){return isNaN(e=+e)?0:(e>0?i:n)(e)}},function(e,t,r){"use strict";var n=r(39),i=Math.max,a=Math.min;e.exports=function(e,t){return(e=n(e))<0?i(e+t,0):a(e,t)}},function(e,t,r){"use strict";var n=r(28)("unscopables"),i=Array.prototype;void 0==i[n]&&r(10)(i,n,{}),e.exports=function(e){i[n][e]=!0}},function(e,t,r){"use strict";r(43),e.exports=r(9).Object.assign},function(e,t,r){"use strict";var n=r(7);n(n.S+n.F,"Object",{assign:r(44)})},function(e,t,r){"use strict";var n=r(45),i=r(49),a=r(50),o=r(51),s=r(37),u=Object.assign;e.exports=!u||r(16)(function(){var e={},t={},r=Symbol(),n="abcdefghijklmnopqrst";return e[r]=7,n.split("").forEach(function(e){t[e]=e}),7!=u({},e)[r]||Object.keys(u({},t)).join("")!=n})?function(e,t){for(var r=o(e),u=arguments.length,l=1,c=i.f,h=a.f;u>l;)for(var d,f=s(arguments[l++]),p=c?n(f).concat(c(f)):n(f),v=p.length,m=0;v>m;)h.call(f,d=p[m++])&&(r[d]=f[d]);return r}:u},function(e,t,r){"use strict";var n=r(46),i=r(48);e.exports=Object.keys||function(e){return n(e,i)}},function(e,t,r){"use strict";var n=r(21),i=r(36),a=r(35)(!1),o=r(47)("IE_PROTO");e.exports=function(e,t){var r,s=i(e),u=0,l=[];for(r in s)r!=o&&n(s,r)&&l.push(r);for(;t.length>u;)n(s,r=t[u++])&&(~a(l,r)||l.push(r));return l}},function(e,t,r){"use strict";var n=r(29)("keys"),i=r(22);e.exports=function(e){return n[e]||(n[e]=i(e))}},function(e,t,r){"use strict";e.exports="constructor,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,toString,valueOf".split(",")},function(e,t,r){"use strict";t.f=Object.getOwnPropertySymbols},function(e,t,r){"use strict";t.f={}.propertyIsEnumerable},function(e,t,r){"use strict";var n=r(31);e.exports=function(e){return Object(n(e))}},function(e,t,r){"use strict";r(53),e.exports=r(9).Math.log2},function(e,t,r){"use strict";var n=r(7);n(n.S,"Math",{log2:function(e){return Math.log(e)/Math.LN2}})},function(e,t,r){"use strict";r(55),e.exports=r(9).Number.isNaN},function(e,t,r){"use strict";var n=r(7);n(n.S,"Number",{isNaN:function(e){return e!=e}})},function(e,t,r){"use strict";r(57),e.exports=r(9).Number.isInteger},function(e,t,r){"use strict";var n=r(7);n(n.S,"Number",{isInteger:r(58)})},function(e,t,r){"use strict";var n=r(13),i=Math.floor;e.exports=function(e){return!n(e)&&isFinite(e)&&i(e)===e}},function(e,t,r){"use strict";r(60),r(62),r(72),r(75),r(92),r(93),e.exports=r(9).Promise},function(e,t,r){"use strict";var n=r(61),i={};i[r(28)("toStringTag")]="z",i+""!="[object z]"&&r(20)(Object.prototype,"toString",function(){return"[object "+n(this)+"]"},!0)},function(e,t,r){"use strict";var n=r(27),i=r(28)("toStringTag"),a="Arguments"==n(function(){return arguments}());e.exports=function(e){var t,r,o;return void 0===e?"Undefined":null===e?"Null":"string"==typeof(r=function(e,t){try{return e[t]}catch(e){}}(t=Object(e),i))?r:a?n(t):"Object"==(o=n(t))&&"function"==typeof t.callee?"Arguments":o}},function(e,t,r){"use strict";var n=r(63)(!0);r(64)(String,"String",function(e){this._t=String(e),this._i=0},function(){var e,t=this._t,r=this._i;return r>=t.length?{value:void 0,done:!0}:(e=n(t,r),this._i+=e.length,{value:e,done:!1})})},function(e,t,r){"use strict";var n=r(39),i=r(31);e.exports=function(e){return function(t,r){var a,o,s=String(i(t)),u=n(r),l=s.length;return u<0||u>=l?e?"":void 0:(a=s.charCodeAt(u))<55296||a>56319||u+1===l||(o=s.charCodeAt(u+1))<56320||o>57343?e?s.charAt(u):a:e?s.slice(u,u+2):o-56320+(a-55296<<10)+65536}}},function(e,t,r){"use strict";var n=r(30),i=r(7),a=r(20),o=r(10),s=r(65),u=r(66),l=r(70),c=r(71),h=r(28)("iterator"),d=!([].keys&&"next"in[].keys()),f=function(){return this};e.exports=function(e,t,r,p,v,m,g){u(r,t,p);var y,b,_,A=function(e){if(!d&&e in P)return P[e];switch(e){case"keys":case"values":return function(){return new r(this,e)}}return function(){return new r(this,e)}},S=t+" Iterator",w="values"==v,k=!1,P=e.prototype,x=P[h]||P["@@iterator"]||v&&P[v],C=x||A(v),R=v?w?A("entries"):C:void 0,E="Array"==t&&P.entries||x;if(E&&(_=c(E.call(new e)))!==Object.prototype&&_.next&&(l(_,S,!0),n||"function"==typeof _[h]||o(_,h,f)),w&&x&&"values"!==x.name&&(k=!0,C=function(){return x.call(this)}),n&&!g||!d&&!k&&P[h]||o(P,h,C),s[t]=C,s[S]=f,v)if(y={values:w?C:A("values"),keys:m?C:A("keys"),entries:R},g)for(b in y)b in P||a(P,b,y[b]);else i(i.P+i.F*(d||k),t,y);return y}},function(e,t,r){"use strict";e.exports={}},function(e,t,r){"use strict";var n=r(67),i=r(19),a=r(70),o={};r(10)(o,r(28)("iterator"),function(){return this}),e.exports=function(e,t,r){e.prototype=n(o,{next:i(1,r)}),a(e,t+" Iterator")}},function(e,t,r){"use strict";var n=r(12),i=r(68),a=r(48),o=r(47)("IE_PROTO"),s=function(){},u=function(){var e,t=r(17)("iframe"),n=a.length;for(t.style.display="none",r(69).appendChild(t),t.src="javascript:",(e=t.contentWindow.document).open(),e.write(" @@ -171,7 +192,14 @@ export default { class="diff-toggle-caret append-right-5" @click.stop="handleToggle" /> - + { const page = $('body').attr('data-page') || ''; @@ -193,16 +194,24 @@ export const isMetaKey = e => e.metaKey || e.ctrlKey || e.altKey || e.shiftKey; export const isMetaClick = e => e.metaKey || e.ctrlKey || e.which === 2; export const contentTop = () => { - const perfBar = $('#js-peek').height() || 0; - const mrTabsHeight = $('.merge-request-tabs').height() || 0; - const headerHeight = $('.navbar-gitlab').height() || 0; - const diffFilesChanged = $('.js-diff-files-changed').height() || 0; - const diffFileLargeEnoughScreen = - 'matchMedia' in window ? window.matchMedia('min-width: 768') : true; + const perfBar = $('#js-peek').outerHeight() || 0; + const mrTabsHeight = $('.merge-request-tabs').outerHeight() || 0; + const headerHeight = $('.navbar-gitlab').outerHeight() || 0; + const diffFilesChanged = $('.js-diff-files-changed').outerHeight() || 0; + const mdScreenOrBigger = ['lg', 'md'].includes(BreakpointInstance.getBreakpointSize()); const diffFileTitleBar = - (diffFileLargeEnoughScreen && $('.diff-file .file-title-flex-parent:visible').height()) || 0; + (mdScreenOrBigger && $('.diff-file .file-title-flex-parent:visible').outerHeight()) || 0; + const compareVersionsHeaderHeight = + (mdScreenOrBigger && $('.mr-version-controls').outerHeight()) || 0; - return perfBar + mrTabsHeight + headerHeight + diffFilesChanged + diffFileTitleBar; + return ( + perfBar + + mrTabsHeight + + headerHeight + + diffFilesChanged + + diffFileTitleBar + + compareVersionsHeaderHeight + ); }; export const scrollToElement = element => { diff --git a/changelogs/unreleased/57669-fix-bug-clicking-file-header-refreshes-page.yml b/changelogs/unreleased/57669-fix-bug-clicking-file-header-refreshes-page.yml new file mode 100644 index 00000000000..c6161870096 --- /dev/null +++ b/changelogs/unreleased/57669-fix-bug-clicking-file-header-refreshes-page.yml @@ -0,0 +1,6 @@ +--- +title: Scroll to diff file content when clicking on file header name and it is not + a link to other page +merge_request: !26422 +author: +type: fixed diff --git a/spec/javascripts/diffs/components/diff_file_header_spec.js b/spec/javascripts/diffs/components/diff_file_header_spec.js index 66c5b17b825..2d10b8383e2 100644 --- a/spec/javascripts/diffs/components/diff_file_header_spec.js +++ b/spec/javascripts/diffs/components/diff_file_header_spec.js @@ -3,7 +3,7 @@ import Vuex from 'vuex'; import diffsModule from '~/diffs/store/modules'; import notesModule from '~/notes/stores/modules'; import DiffFileHeader from '~/diffs/components/diff_file_header.vue'; -import { mountComponentWithStore } from 'spec/helpers/vue_mount_component_helper'; +import mountComponent, { mountComponentWithStore } from 'spec/helpers/vue_mount_component_helper'; import diffDiscussionsMockData from '../mock_data/diff_discussions'; import { diffViewerModes } from '~/ide/constants'; @@ -252,6 +252,75 @@ describe('diff_file_header', () => { expect(vm.$emit).not.toHaveBeenCalled(); }); }); + + describe('handleFileNameClick', () => { + let e; + + beforeEach(() => { + e = { preventDefault: () => {} }; + spyOn(e, 'preventDefault'); + }); + + describe('when file name links to other page', () => { + it('does not call preventDefault if submodule tree url exists', () => { + vm = mountComponent(Component, { + ...props, + diffFile: { ...props.diffFile, submodule_tree_url: 'foobar.com' }, + }); + + vm.handleFileNameClick(e); + + expect(e.preventDefault).not.toHaveBeenCalled(); + }); + + it('does not call preventDefault if submodule_link exists', () => { + vm = mountComponent(Component, { + ...props, + diffFile: { ...props.diffFile, submodule_link: 'foobar.com' }, + }); + vm.handleFileNameClick(e); + + expect(e.preventDefault).not.toHaveBeenCalled(); + }); + + it('does not call preventDefault if discussionPath exists', () => { + vm = mountComponent(Component, { + ...props, + discussionPath: 'Foo bar', + }); + + vm.handleFileNameClick(e); + + expect(e.preventDefault).not.toHaveBeenCalled(); + }); + }); + + describe('scrolling to diff', () => { + let scrollToElement; + let el; + + beforeEach(() => { + el = document.createElement('div'); + spyOn(document, 'querySelector').and.returnValue(el); + scrollToElement = spyOnDependency(DiffFileHeader, 'scrollToElement'); + vm = mountComponent(Component, props); + + vm.handleFileNameClick(e); + }); + + it('calls scrollToElement with file content', () => { + expect(scrollToElement).toHaveBeenCalledWith(el); + }); + + it('element adds the content id to the window location', () => { + expect(window.location.hash).toContain(props.diffFile.file_hash); + }); + + it('calls preventDefault when button does not link to other page', () => { + expect(e.preventDefault).toHaveBeenCalled(); + }); + }); + }); }); describe('template', () => { diff --git a/spec/javascripts/lib/utils/common_utils_spec.js b/spec/javascripts/lib/utils/common_utils_spec.js index 0bb43c94f6a..2084c36e484 100644 --- a/spec/javascripts/lib/utils/common_utils_spec.js +++ b/spec/javascripts/lib/utils/common_utils_spec.js @@ -2,6 +2,7 @@ import axios from '~/lib/utils/axios_utils'; import * as commonUtils from '~/lib/utils/common_utils'; import MockAdapter from 'axios-mock-adapter'; import { faviconDataUrl, overlayDataUrl, faviconWithOverlayDataUrl } from './mock_data'; +import BreakpointInstance from '~/breakpoints'; const PIXEL_TOLERANCE = 0.2; @@ -380,6 +381,38 @@ describe('common_utils', () => { }); }); + describe('contentTop', () => { + it('does not add height for fileTitle or compareVersionsHeader if screen is too small', () => { + spyOn(BreakpointInstance, 'getBreakpointSize').and.returnValue('sm'); + + setFixtures(` +
+ blah blah blah +
+
+ more blah blah blah +
+ `); + + expect(commonUtils.contentTop()).toBe(0); + }); + + it('adds height for fileTitle and compareVersionsHeader screen is large enough', () => { + spyOn(BreakpointInstance, 'getBreakpointSize').and.returnValue('lg'); + + setFixtures(` +
+ blah blah blah +
+
+ more blah blah blah +
+ `); + + expect(commonUtils.contentTop()).toBe(18); + }); + }); + describe('parseBoolean', () => { const { parseBoolean } = commonUtils; -- cgit v1.2.1 From 02c99ec8ce0449f330f0fd9ca277ea4cdc82be23 Mon Sep 17 00:00:00 2001 From: mfluharty Date: Fri, 29 Mar 2019 12:59:16 -0600 Subject: Remove duplicate environment selector dropdown --- app/views/ci/variables/_variable_row.html.haml | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/views/ci/variables/_variable_row.html.haml b/app/views/ci/variables/_variable_row.html.haml index d4387e68d49..aecfdea10d9 100644 --- a/app/views/ci/variables/_variable_row.html.haml +++ b/app/views/ci/variables/_variable_row.html.haml @@ -49,8 +49,6 @@ %span.toggle-icon = sprite_icon('status_success_borderless', size: 16, css_class: 'toggle-icon-svg toggle-status-checked') = sprite_icon('status_failed_borderless', size: 16, css_class: 'toggle-icon-svg toggle-status-unchecked') - = render_if_exists 'ci/variables/environment_scope', form_field: form_field, variable: variable - - unless only_key_value .ci-variable-body-item.ci-variable-masked-item .append-right-default = s_("CiVariable|Masked") -- cgit v1.2.1 From 98a5976b787fad0797bc5e3231c48ab3f400bce6 Mon Sep 17 00:00:00 2001 From: Nick Thomas Date: Fri, 29 Mar 2019 11:23:05 +0000 Subject: Document ApplicationRecord / pluck_primary_key We also enable the rubocop that makes it mandatory --- .rubocop.yml | 14 ++++++++++++++ doc/development/sql.md | 15 +++++++++++++++ lib/tasks/tokens.rake | 2 +- scripts/insert-rspec-profiling-data | 2 +- 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 9143966b864..648d59e8062 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -146,6 +146,20 @@ Naming/FileName: - XSS - GRPC +Rails/ApplicationRecord: + Enabled: true + Exclude: + # Models in database migrations should not subclass from ApplicationRecord + # as they need to be as decoupled from application code as possible + - db/**/*.rb + - lib/gitlab/background_migration/**/*.rb + - lib/gitlab/database/**/*.rb + - spec/**/*.rb + - ee/db/**/*.rb + - ee/lib/gitlab/background_migration/**/*.rb + - ee/lib/ee/gitlab/background_migration/**/*.rb + - ee/spec/**/*.rb + # GitLab ################################################################### Gitlab/ModuleWithInstanceVariables: diff --git a/doc/development/sql.md b/doc/development/sql.md index 47519d39e74..edeca7fb298 100644 --- a/doc/development/sql.md +++ b/doc/development/sql.md @@ -155,6 +155,21 @@ The _only_ time you should use `pluck` is when you actually need to operate on the values in Ruby itself (e.g. write them to a file). In almost all other cases you should ask yourself "Can I not just use a sub-query?". +In line with our `CodeReuse/ActiveRecord` cop, you should only use forms like +`pluck(:id)` or `pluck(:user_id)` within model code. In the former case, you can +use the `ApplicationRecord`-provided `.pluck_primary_key` helper method instead. +In the latter, you should add a small helper method to the relevant model. + +## Inherit from ApplicationRecord + +Most models in the GitLab codebase should inherit from `ApplicationRecord`, +rather than from `ActiveRecord::Base`. This allows helper methods to be easily +added. + +An exception to this rule exists for models created in database migrations. As +these should be isolated from application code, they should continue to subclass +from `ActiveRecord::Base`. + ## Use UNIONs UNIONs aren't very commonly used in most Rails applications but they're very diff --git a/lib/tasks/tokens.rake b/lib/tasks/tokens.rake index eec024f9bbb..46635cd7c8f 100644 --- a/lib/tasks/tokens.rake +++ b/lib/tasks/tokens.rake @@ -24,7 +24,7 @@ namespace :tokens do end end -class TmpUser < ActiveRecord::Base +class TmpUser < ActiveRecord::Base # rubocop:disable Rails/ApplicationRecord include TokenAuthenticatable self.table_name = 'users' diff --git a/scripts/insert-rspec-profiling-data b/scripts/insert-rspec-profiling-data index 10e337b9972..b34379764e0 100755 --- a/scripts/insert-rspec-profiling-data +++ b/scripts/insert-rspec-profiling-data @@ -22,7 +22,7 @@ module RspecProfiling ENV['RSPEC_PROFILING_POSTGRES_URL'] end - class Result < ActiveRecord::Base + class Result < ActiveRecord::Base # rubocop:disable Rails/ApplicationRecord acts_as_copy_target end end -- cgit v1.2.1 From cedbb3366bf3dd9bafe95dde366c1e28ee70c615 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Fri, 29 Mar 2019 15:16:31 -0700 Subject: Fix API /project/:id/branches not returning correct merge status https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/24034 introduced a regression where only the first 20 branches were used to determine whether a branch has been merged because the pagination was applied incorrectly. Requesting the second page of branches via the API would always have the wrong merge status. We fix this by properly paginating the branches before requesting their merge status. Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/56250 --- .../sh-fix-project-branches-merge-status.yml | 5 +++++ lib/api/branches.rb | 4 ++-- spec/requests/api/branches_spec.rb | 22 +++++++++++++++++++++- 3 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 changelogs/unreleased/sh-fix-project-branches-merge-status.yml diff --git a/changelogs/unreleased/sh-fix-project-branches-merge-status.yml b/changelogs/unreleased/sh-fix-project-branches-merge-status.yml new file mode 100644 index 00000000000..65f41b3faf9 --- /dev/null +++ b/changelogs/unreleased/sh-fix-project-branches-merge-status.yml @@ -0,0 +1,5 @@ +--- +title: Fix API /project/:id/branches not returning correct merge status +merge_request: 26785 +author: +type: fixed diff --git a/lib/api/branches.rb b/lib/api/branches.rb index 07f529b01bb..5c98b0ad56c 100644 --- a/lib/api/branches.rb +++ b/lib/api/branches.rb @@ -34,11 +34,11 @@ module API repository = user_project.repository branches = BranchesFinder.new(repository, declared_params(include_missing: false)).execute - branches = ::Kaminari.paginate_array(branches) + branches = paginate(::Kaminari.paginate_array(branches)) merged_branch_names = repository.merged_branch_names(branches.map(&:name)) present( - paginate(branches), + branches, with: Entities::Branch, current_user: current_user, project: user_project, diff --git a/spec/requests/api/branches_spec.rb b/spec/requests/api/branches_spec.rb index b38cd66986f..75dcedabf96 100644 --- a/spec/requests/api/branches_spec.rb +++ b/spec/requests/api/branches_spec.rb @@ -36,10 +36,30 @@ describe API::Branches do expect(branch_names).to match_array(project.repository.branch_names) end + def check_merge_status(json_response) + merged, unmerged = json_response.partition { |branch| branch['merged'] } + merged_branches = merged.map { |branch| branch['name'] } + unmerged_branches = unmerged.map { |branch| branch['name'] } + expect(Set.new(merged_branches)).to eq(project.repository.merged_branch_names(merged_branches + unmerged_branches)) + expect(project.repository.merged_branch_names(unmerged_branches)).to be_empty + end + it 'determines only a limited number of merged branch names' do - expect(API::Entities::Branch).to receive(:represent).with(anything, has_merged_branch_names_count(2)) + expect(API::Entities::Branch).to receive(:represent).with(anything, has_merged_branch_names_count(1)).and_call_original get api(route, current_user), params: { per_page: 2 } + + expect(response).to have_gitlab_http_status(200) + + check_merge_status(json_response) + end + + it 'merge status matches reality on paginated input' do + get api(route, current_user), params: { per_page: 20, page: 2 } + + expect(response).to have_gitlab_http_status(200) + + check_merge_status(json_response) end context 'when repository is disabled' do -- cgit v1.2.1 From 2675581cb9dbc37c81732ac69e2166da6ced0429 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Sat, 30 Mar 2019 05:28:37 -0700 Subject: Revise merged branch check to green light up to N branches The main point of this check is to ensure we aren't checking all branches, not that we have an exact count. --- spec/requests/api/branches_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/requests/api/branches_spec.rb b/spec/requests/api/branches_spec.rb index 75dcedabf96..8b503777443 100644 --- a/spec/requests/api/branches_spec.rb +++ b/spec/requests/api/branches_spec.rb @@ -20,9 +20,9 @@ describe API::Branches do let(:route) { "/projects/#{project_id}/repository/branches" } shared_examples_for 'repository branches' do - RSpec::Matchers.define :has_merged_branch_names_count do |expected| + RSpec::Matchers.define :has_up_to_merged_branch_names_count do |expected| match do |actual| - actual[:merged_branch_names].count == expected + expected >= actual[:merged_branch_names].count end end @@ -45,7 +45,7 @@ describe API::Branches do end it 'determines only a limited number of merged branch names' do - expect(API::Entities::Branch).to receive(:represent).with(anything, has_merged_branch_names_count(1)).and_call_original + expect(API::Entities::Branch).to receive(:represent).with(anything, has_up_to_merged_branch_names_count(2)).and_call_original get api(route, current_user), params: { per_page: 2 } -- cgit v1.2.1 From 6a25f8bc794d42a744082ae09d7fc4bbbaa5e5a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Lafoucrie=CC=80re?= Date: Sat, 30 Mar 2019 12:05:13 -0400 Subject: Fix Container Scanning for Kubernetes Runners closes https://gitlab.com/gitlab-org/gitlab-ee/issues/6636 closes https://gitlab.com/gitlab-org/gitlab-ee/issues/5763 --- changelogs/unreleased/fix-container-scanning-on-k8s.yml | 5 +++++ lib/gitlab/ci/templates/Auto-DevOps.gitlab-ci.yml | 9 +++++++-- .../templates/Security/Container-Scanning.gitlab-ci.yml | 15 +++++++++++---- 3 files changed, 23 insertions(+), 6 deletions(-) create mode 100644 changelogs/unreleased/fix-container-scanning-on-k8s.yml diff --git a/changelogs/unreleased/fix-container-scanning-on-k8s.yml b/changelogs/unreleased/fix-container-scanning-on-k8s.yml new file mode 100644 index 00000000000..f4500370a0b --- /dev/null +++ b/changelogs/unreleased/fix-container-scanning-on-k8s.yml @@ -0,0 +1,5 @@ +--- +title: Fix Container Scanning in Kubernetes Runners +merge_request: 26793 +author: +type: changed diff --git a/lib/gitlab/ci/templates/Auto-DevOps.gitlab-ci.yml b/lib/gitlab/ci/templates/Auto-DevOps.gitlab-ci.yml index 78872b3bbe3..3116f1a136b 100644 --- a/lib/gitlab/ci/templates/Auto-DevOps.gitlab-ci.yml +++ b/lib/gitlab/ci/templates/Auto-DevOps.gitlab-ci.yml @@ -531,8 +531,8 @@ rollout 100%: touch clair-whitelist.yml retries=0 echo "Waiting for clair daemon to start" - while( ! wget -T 10 -q -O /dev/null http://docker:6060/v1/namespaces ) ; do sleep 1 ; echo -n "." ; if [ $retries -eq 10 ] ; then echo " Timeout, aborting." ; exit 1 ; fi ; retries=$(($retries+1)) ; done - ./clair-scanner -c http://docker:6060 --ip $(hostname -i) -r gl-container-scanning-report.json -l clair.log -w clair-whitelist.yml ${CI_APPLICATION_REPOSITORY}:${CI_APPLICATION_TAG} || true + while( ! wget -T 10 -q -O /dev/null http://${DOCKER_SERVICE}:6060/v1/namespaces ) ; do sleep 1 ; echo -n "." ; if [ $retries -eq 10 ] ; then echo " Timeout, aborting." ; exit 1 ; fi ; retries=$(($retries+1)) ; done + ./clair-scanner -c http://${DOCKER_SERVICE}:6060 --ip $(hostname -i) -r gl-container-scanning-report.json -l clair.log -w clair-whitelist.yml ${CI_APPLICATION_REPOSITORY}:${CI_APPLICATION_TAG} || true } function code_quality() { @@ -800,10 +800,15 @@ rollout 100%: kubectl version --client } + # With the Kubernetes executor, 'localhost' must be used instead + # https://docs.gitlab.com/runner/executors/kubernetes.html function setup_docker() { if ! docker info &>/dev/null; then if [ -z "$DOCKER_HOST" -a "$KUBERNETES_PORT" ]; then export DOCKER_HOST='tcp://localhost:2375' + export DOCKER_SERVICE="localhost" + else + export DOCKER_SERVICE="docker" fi fi } diff --git a/lib/gitlab/ci/templates/Security/Container-Scanning.gitlab-ci.yml b/lib/gitlab/ci/templates/Security/Container-Scanning.gitlab-ci.yml index ea1e6ae5fdc..0b7a531682b 100644 --- a/lib/gitlab/ci/templates/Security/Container-Scanning.gitlab-ci.yml +++ b/lib/gitlab/ci/templates/Security/Container-Scanning.gitlab-ci.yml @@ -17,23 +17,30 @@ container_scanning: # # Container Scanning deals with Docker images only so no need to import the project's Git repository: GIT_STRATEGY: none + # Services and containers running in the same Kubernetes pod are all sharing the same localhost address + # https://docs.gitlab.com/runner/executors/kubernetes.html + DOCKER_SERVICE: docker + DOCKER_HOST: tcp://${DOCKER_SERVICE}:2375/ + # https://hub.docker.com/r/arminc/clair-local-scan/tags + CLAIR_LOCAL_SCAN_VERSION: v2.0.6 allow_failure: true services: - docker:stable-dind script: + - if [ -z "$DOCKER_HOST" -a "$KUBERNETES_PORT" ]; then { export DOCKER_SERVICE="localhost" ; export DOCKER_HOST="tcp://${DOCKER_SERVICE}:2375" ; } fi - docker run -d --name db arminc/clair-db:latest - - docker run -p 6060:6060 --link db:postgres -d --name clair --restart on-failure arminc/clair-local-scan:v2.0.6 + - docker run -p 6060:6060 --link db:postgres -d --name clair --restart on-failure arminc/clair-local-scan:${CLAIR_LOCAL_SCAN_VERSION} - apk add -U wget ca-certificates - docker pull ${CI_APPLICATION_REPOSITORY}:${CI_APPLICATION_TAG} - wget https://github.com/arminc/clair-scanner/releases/download/v8/clair-scanner_linux_amd64 - mv clair-scanner_linux_amd64 clair-scanner - chmod +x clair-scanner - touch clair-whitelist.yml - - while( ! wget -q -O /dev/null http://docker:6060/v1/namespaces ) ; do sleep 1 ; done + - while( ! wget -q -O /dev/null http://${DOCKER_SERVICE}:6060/v1/namespaces ) ; do sleep 1 ; done - retries=0 - echo "Waiting for clair daemon to start" - - while( ! wget -T 10 -q -O /dev/null http://docker:6060/v1/namespaces ) ; do sleep 1 ; echo -n "." ; if [ $retries -eq 10 ] ; then echo " Timeout, aborting." ; exit 1 ; fi ; retries=$(($retries+1)) ; done - - ./clair-scanner -c http://docker:6060 --ip $(hostname -i) -r gl-container-scanning-report.json -l clair.log -w clair-whitelist.yml ${CI_APPLICATION_REPOSITORY}:${CI_APPLICATION_TAG} || true + - while( ! wget -T 10 -q -O /dev/null http://${DOCKER_SERVICE}:6060/v1/namespaces ) ; do sleep 1 ; echo -n "." ; if [ $retries -eq 10 ] ; then echo " Timeout, aborting." ; exit 1 ; fi ; retries=$(($retries+1)) ; done + - ./clair-scanner -c http://${DOCKER_SERVICE}:6060 --ip $(hostname -i) -r gl-container-scanning-report.json -l clair.log -w clair-whitelist.yml ${CI_APPLICATION_REPOSITORY}:${CI_APPLICATION_TAG} || true artifacts: reports: container_scanning: gl-container-scanning-report.json -- cgit v1.2.1 From de6bab915cc080ecbbce5eb827017d46e1f95e1d Mon Sep 17 00:00:00 2001 From: Elias Werberich Date: Sun, 31 Mar 2019 16:09:51 +0200 Subject: Disable inaccessible navigation links upon archiving a project --- app/views/layouts/nav/sidebar/_project.html.haml | 4 +- .../58793-fix-nav-links-archived-project.yml | 5 +++ .../layouts/nav/sidebar/_project.html.haml_spec.rb | 52 ++++++++++++++++++++++ 3 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 changelogs/unreleased/58793-fix-nav-links-archived-project.yml diff --git a/app/views/layouts/nav/sidebar/_project.html.haml b/app/views/layouts/nav/sidebar/_project.html.haml index 6b33189d1cf..3a0c2b9c284 100644 --- a/app/views/layouts/nav/sidebar/_project.html.haml +++ b/app/views/layouts/nav/sidebar/_project.html.haml @@ -357,12 +357,12 @@ = link_to project_settings_repository_path(@project), title: _('Repository') do %span = _('Repository') - - if @project.feature_available?(:builds, current_user) + - if !@project.archived? && @project.feature_available?(:builds, current_user) = nav_link(controller: :ci_cd) do = link_to project_settings_ci_cd_path(@project), title: _('CI / CD') do %span = _('CI / CD') - - if settings_operations_available? + - if !@project.archived? && settings_operations_available? = nav_link(controller: [:operations]) do = link_to project_settings_operations_path(@project), title: _('Operations') do = _('Operations') diff --git a/changelogs/unreleased/58793-fix-nav-links-archived-project.yml b/changelogs/unreleased/58793-fix-nav-links-archived-project.yml new file mode 100644 index 00000000000..a8250804c34 --- /dev/null +++ b/changelogs/unreleased/58793-fix-nav-links-archived-project.yml @@ -0,0 +1,5 @@ +--- +title: "Disable inaccessible navigation links upon archiving a project" +merge_request: 26020 +author: Elias Werberich +type: fixed diff --git a/spec/views/layouts/nav/sidebar/_project.html.haml_spec.rb b/spec/views/layouts/nav/sidebar/_project.html.haml_spec.rb index 2c60ccfb754..c6c10001bc5 100644 --- a/spec/views/layouts/nav/sidebar/_project.html.haml_spec.rb +++ b/spec/views/layouts/nav/sidebar/_project.html.haml_spec.rb @@ -113,4 +113,56 @@ describe 'layouts/nav/sidebar/_project' do end end end + + describe 'ci/cd settings tab' do + before do + project.update!(archived: project_archived) + end + + context 'when project is archived' do + let(:project_archived) { true } + + it 'does not show the ci/cd settings tab' do + render + + expect(rendered).not_to have_link('CI / CD', href: project_settings_ci_cd_path(project)) + end + end + + context 'when project is active' do + let(:project_archived) { false } + + it 'shows the ci/cd settings tab' do + render + + expect(rendered).to have_link('CI / CD', href: project_settings_ci_cd_path(project)) + end + end + end + + describe 'operations settings tab' do + before do + project.update!(archived: project_archived) + end + + context 'when project is archived' do + let(:project_archived) { true } + + it 'does not show the operations settings tab' do + render + + expect(rendered).not_to have_link('Operations', href: project_settings_operations_path(project)) + end + end + + context 'when project is active' do + let(:project_archived) { false } + + it 'shows the operations settings tab' do + render + + expect(rendered).to have_link('Operations', href: project_settings_operations_path(project)) + end + end + end end -- cgit v1.2.1 From a2cfc150cec677b27728a4758e5e40fff5b4c284 Mon Sep 17 00:00:00 2001 From: Thong Kuah Date: Sat, 30 Mar 2019 20:23:56 +1300 Subject: Add # frozen_string_literal to spec/models Adds `# frozen_string_literal: true` to spec/models ruby files --- spec/models/ability_spec.rb | 2 ++ spec/models/abuse_report_spec.rb | 2 ++ spec/models/active_session_spec.rb | 2 ++ spec/models/appearance_spec.rb | 2 ++ spec/models/application_setting/term_spec.rb | 2 ++ spec/models/application_setting_spec.rb | 2 ++ spec/models/award_emoji_spec.rb | 2 ++ spec/models/badge_spec.rb | 2 ++ spec/models/badges/group_badge_spec.rb | 2 ++ spec/models/badges/project_badge_spec.rb | 2 ++ spec/models/blob_spec.rb | 2 ++ spec/models/blob_viewer/base_spec.rb | 2 ++ spec/models/blob_viewer/changelog_spec.rb | 2 ++ spec/models/blob_viewer/composer_json_spec.rb | 2 ++ spec/models/blob_viewer/gemspec_spec.rb | 2 ++ spec/models/blob_viewer/gitlab_ci_yml_spec.rb | 2 ++ spec/models/blob_viewer/license_spec.rb | 2 ++ spec/models/blob_viewer/package_json_spec.rb | 2 ++ spec/models/blob_viewer/podspec_json_spec.rb | 2 ++ spec/models/blob_viewer/podspec_spec.rb | 2 ++ spec/models/blob_viewer/readme_spec.rb | 2 ++ spec/models/blob_viewer/route_map_spec.rb | 2 ++ spec/models/blob_viewer/server_side_spec.rb | 2 ++ spec/models/board_spec.rb | 2 ++ spec/models/broadcast_message_spec.rb | 2 ++ spec/models/chat_name_spec.rb | 2 ++ spec/models/chat_team_spec.rb | 2 ++ spec/models/ci/artifact_blob_spec.rb | 2 ++ spec/models/ci/bridge_spec.rb | 2 ++ spec/models/ci/build_metadata_spec.rb | 2 ++ spec/models/ci/build_runner_session_spec.rb | 2 ++ spec/models/ci/build_spec.rb | 2 ++ spec/models/ci/build_trace_chunk_spec.rb | 2 ++ spec/models/ci/build_trace_chunks/database_spec.rb | 2 ++ spec/models/ci/build_trace_chunks/fog_spec.rb | 2 ++ spec/models/ci/build_trace_chunks/redis_spec.rb | 2 ++ spec/models/ci/build_trace_section_name_spec.rb | 2 ++ spec/models/ci/build_trace_section_spec.rb | 2 ++ spec/models/ci/group_spec.rb | 2 ++ spec/models/ci/group_variable_spec.rb | 2 ++ spec/models/ci/job_artifact_spec.rb | 2 ++ spec/models/ci/legacy_stage_spec.rb | 2 ++ spec/models/ci/pipeline_schedule_spec.rb | 2 ++ spec/models/ci/pipeline_schedule_variable_spec.rb | 2 ++ spec/models/ci/pipeline_spec.rb | 2 ++ spec/models/ci/pipeline_variable_spec.rb | 2 ++ spec/models/ci/runner_spec.rb | 2 ++ spec/models/ci/stage_spec.rb | 2 ++ spec/models/ci/trigger_request_spec.rb | 2 ++ spec/models/ci/trigger_spec.rb | 2 ++ spec/models/ci/variable_spec.rb | 2 ++ spec/models/clusters/applications/cert_manager_spec.rb | 2 ++ spec/models/clusters/applications/helm_spec.rb | 2 ++ spec/models/clusters/applications/ingress_spec.rb | 2 ++ spec/models/clusters/applications/jupyter_spec.rb | 2 ++ spec/models/clusters/applications/knative_spec.rb | 2 ++ spec/models/clusters/applications/prometheus_spec.rb | 2 ++ spec/models/clusters/applications/runner_spec.rb | 2 ++ spec/models/clusters/platforms/kubernetes_spec.rb | 2 ++ spec/models/clusters/project_spec.rb | 2 ++ spec/models/clusters/providers/gcp_spec.rb | 2 ++ spec/models/commit_collection_spec.rb | 2 ++ spec/models/commit_range_spec.rb | 2 ++ spec/models/commit_spec.rb | 2 ++ spec/models/commit_status_spec.rb | 2 ++ spec/models/compare_spec.rb | 2 ++ spec/models/concerns/access_requestable_spec.rb | 2 ++ spec/models/concerns/avatarable_spec.rb | 2 ++ spec/models/concerns/awardable_spec.rb | 2 ++ spec/models/concerns/batch_destroy_dependent_associations_spec.rb | 2 ++ spec/models/concerns/blocks_json_serialization_spec.rb | 2 ++ spec/models/concerns/cache_markdown_field_spec.rb | 2 ++ spec/models/concerns/cacheable_attributes_spec.rb | 2 ++ spec/models/concerns/case_sensitivity_spec.rb | 2 ++ spec/models/concerns/chronic_duration_attribute_spec.rb | 2 ++ spec/models/concerns/deployable_spec.rb | 2 ++ spec/models/concerns/deployment_platform_spec.rb | 2 ++ spec/models/concerns/discussion_on_diff_spec.rb | 2 ++ spec/models/concerns/each_batch_spec.rb | 2 ++ spec/models/concerns/editable_spec.rb | 2 ++ spec/models/concerns/expirable_spec.rb | 2 ++ spec/models/concerns/faster_cache_keys_spec.rb | 2 ++ spec/models/concerns/feature_gate_spec.rb | 2 ++ spec/models/concerns/group_descendant_spec.rb | 2 ++ spec/models/concerns/has_status_spec.rb | 2 ++ spec/models/concerns/has_variable_spec.rb | 2 ++ spec/models/concerns/ignorable_column_spec.rb | 2 ++ spec/models/concerns/issuable_spec.rb | 2 ++ spec/models/concerns/loaded_in_group_list_spec.rb | 2 ++ spec/models/concerns/manual_inverse_association_spec.rb | 2 ++ spec/models/concerns/mentionable_spec.rb | 2 ++ spec/models/concerns/milestoneish_spec.rb | 2 ++ spec/models/concerns/noteable_spec.rb | 2 ++ spec/models/concerns/participable_spec.rb | 2 ++ spec/models/concerns/presentable_spec.rb | 2 ++ spec/models/concerns/project_features_compatibility_spec.rb | 2 ++ spec/models/concerns/prometheus_adapter_spec.rb | 2 ++ spec/models/concerns/protected_ref_access_spec.rb | 2 ++ spec/models/concerns/reactive_caching_spec.rb | 2 ++ spec/models/concerns/redactable_spec.rb | 2 ++ spec/models/concerns/redis_cacheable_spec.rb | 2 ++ spec/models/concerns/relative_positioning_spec.rb | 2 ++ spec/models/concerns/resolvable_discussion_spec.rb | 2 ++ spec/models/concerns/resolvable_note_spec.rb | 2 ++ spec/models/concerns/routable_spec.rb | 2 ++ spec/models/concerns/sha_attribute_spec.rb | 2 ++ spec/models/concerns/sortable_spec.rb | 2 ++ spec/models/concerns/spammable_spec.rb | 2 ++ spec/models/concerns/strip_attribute_spec.rb | 2 ++ spec/models/concerns/subscribable_spec.rb | 2 ++ spec/models/concerns/token_authenticatable_spec.rb | 2 ++ spec/models/concerns/token_authenticatable_strategies/base_spec.rb | 2 ++ spec/models/concerns/token_authenticatable_strategies/encrypted_spec.rb | 2 ++ spec/models/concerns/triggerable_hooks_spec.rb | 2 ++ spec/models/concerns/uniquify_spec.rb | 2 ++ spec/models/container_repository_spec.rb | 2 ++ spec/models/conversational_development_index/metric_spec.rb | 2 ++ spec/models/cycle_analytics/code_spec.rb | 2 ++ spec/models/cycle_analytics/issue_spec.rb | 2 ++ spec/models/cycle_analytics/plan_spec.rb | 2 ++ spec/models/cycle_analytics/production_spec.rb | 2 ++ spec/models/cycle_analytics/review_spec.rb | 2 ++ spec/models/cycle_analytics/staging_spec.rb | 2 ++ spec/models/cycle_analytics/test_spec.rb | 2 ++ spec/models/cycle_analytics_spec.rb | 2 ++ spec/models/deploy_key_spec.rb | 2 ++ spec/models/deploy_keys_project_spec.rb | 2 ++ spec/models/deploy_token_spec.rb | 2 ++ spec/models/deployment_spec.rb | 2 ++ spec/models/diff_discussion_spec.rb | 2 ++ spec/models/diff_note_spec.rb | 2 ++ spec/models/diff_viewer/base_spec.rb | 2 ++ spec/models/diff_viewer/server_side_spec.rb | 2 ++ spec/models/discussion_spec.rb | 2 ++ spec/models/email_spec.rb | 2 ++ spec/models/environment_spec.rb | 2 ++ spec/models/environment_status_spec.rb | 2 ++ spec/models/event_collection_spec.rb | 2 ++ spec/models/event_spec.rb | 2 ++ spec/models/external_issue_spec.rb | 2 ++ spec/models/fork_network_member_spec.rb | 2 ++ spec/models/fork_network_spec.rb | 2 ++ spec/models/generic_commit_status_spec.rb | 2 ++ spec/models/global_milestone_spec.rb | 2 ++ spec/models/gpg_key_spec.rb | 2 ++ spec/models/gpg_key_subkey_spec.rb | 2 ++ spec/models/gpg_signature_spec.rb | 2 ++ spec/models/group_custom_attribute_spec.rb | 2 ++ spec/models/group_label_spec.rb | 2 ++ spec/models/group_milestone_spec.rb | 2 ++ spec/models/group_spec.rb | 2 ++ spec/models/guest_spec.rb | 2 ++ spec/models/hooks/active_hook_filter_spec.rb | 2 ++ spec/models/hooks/project_hook_spec.rb | 2 ++ spec/models/hooks/service_hook_spec.rb | 2 ++ spec/models/hooks/system_hook_spec.rb | 2 ++ spec/models/hooks/web_hook_log_spec.rb | 2 ++ spec/models/hooks/web_hook_spec.rb | 2 ++ spec/models/identity_spec.rb | 2 ++ spec/models/import_export_upload_spec.rb | 2 ++ spec/models/instance_configuration_spec.rb | 2 ++ spec/models/internal_id_spec.rb | 2 ++ spec/models/issue/metrics_spec.rb | 2 ++ spec/models/issue_collection_spec.rb | 2 ++ spec/models/issue_spec.rb | 2 ++ spec/models/key_spec.rb | 2 ++ spec/models/label_link_spec.rb | 2 ++ spec/models/label_priority_spec.rb | 2 ++ spec/models/label_spec.rb | 2 ++ spec/models/legacy_diff_discussion_spec.rb | 2 ++ spec/models/lfs_download_object_spec.rb | 2 ++ spec/models/lfs_file_lock_spec.rb | 2 ++ spec/models/lfs_object_spec.rb | 2 ++ spec/models/lfs_objects_project_spec.rb | 2 ++ spec/models/license_template_spec.rb | 2 ++ spec/models/list_spec.rb | 2 ++ spec/models/member_spec.rb | 2 ++ spec/models/members/group_member_spec.rb | 2 ++ spec/models/members/project_member_spec.rb | 2 ++ spec/models/merge_request/metrics_spec.rb | 2 ++ spec/models/merge_request_diff_commit_spec.rb | 2 ++ spec/models/merge_request_diff_file_spec.rb | 2 ++ spec/models/merge_request_diff_spec.rb | 2 ++ spec/models/merge_request_spec.rb | 2 ++ spec/models/milestone_spec.rb | 2 ++ spec/models/namespace_spec.rb | 2 ++ spec/models/network/graph_spec.rb | 2 ++ spec/models/note_diff_file_spec.rb | 2 ++ spec/models/note_spec.rb | 2 ++ spec/models/notification_recipient_spec.rb | 2 ++ spec/models/notification_setting_spec.rb | 2 ++ spec/models/pages_domain_spec.rb | 2 ++ spec/models/personal_access_token_spec.rb | 2 ++ spec/models/programming_language_spec.rb | 2 ++ spec/models/project_authorization_spec.rb | 2 ++ spec/models/project_auto_devops_spec.rb | 2 ++ spec/models/project_custom_attribute_spec.rb | 2 ++ spec/models/project_deploy_token_spec.rb | 2 ++ spec/models/project_feature_spec.rb | 2 ++ spec/models/project_group_link_spec.rb | 2 ++ spec/models/project_import_state_spec.rb | 2 ++ spec/models/project_label_spec.rb | 2 ++ spec/models/project_services/asana_service_spec.rb | 2 ++ spec/models/project_services/assembla_service_spec.rb | 2 ++ spec/models/project_services/bamboo_service_spec.rb | 2 ++ spec/models/project_services/bugzilla_service_spec.rb | 2 ++ spec/models/project_services/buildkite_service_spec.rb | 2 ++ spec/models/project_services/campfire_service_spec.rb | 2 ++ spec/models/project_services/chat_message/issue_message_spec.rb | 2 ++ spec/models/project_services/chat_message/merge_message_spec.rb | 2 ++ spec/models/project_services/chat_message/note_message_spec.rb | 2 ++ spec/models/project_services/chat_message/pipeline_message_spec.rb | 2 ++ spec/models/project_services/chat_message/push_message_spec.rb | 2 ++ spec/models/project_services/chat_message/wiki_page_message_spec.rb | 2 ++ spec/models/project_services/chat_notification_service_spec.rb | 2 ++ spec/models/project_services/custom_issue_tracker_service_spec.rb | 2 ++ spec/models/project_services/drone_ci_service_spec.rb | 2 ++ spec/models/project_services/emails_on_push_service_spec.rb | 2 ++ spec/models/project_services/external_wiki_service_spec.rb | 2 ++ spec/models/project_services/flowdock_service_spec.rb | 2 ++ spec/models/project_services/gitlab_issue_tracker_service_spec.rb | 2 ++ spec/models/project_services/irker_service_spec.rb | 2 ++ spec/models/project_services/issue_tracker_service_spec.rb | 2 ++ spec/models/project_services/jira_service_spec.rb | 2 ++ spec/models/project_services/kubernetes_service_spec.rb | 2 ++ spec/models/project_services/mattermost_service_spec.rb | 2 ++ spec/models/project_services/mattermost_slash_commands_service_spec.rb | 2 ++ spec/models/project_services/microsoft_teams_service_spec.rb | 2 ++ spec/models/project_services/packagist_service_spec.rb | 2 ++ spec/models/project_services/pipelines_email_service_spec.rb | 2 ++ spec/models/project_services/pivotaltracker_service_spec.rb | 2 ++ spec/models/project_services/pushover_service_spec.rb | 2 ++ spec/models/project_services/redmine_service_spec.rb | 2 ++ spec/models/project_services/slack_service_spec.rb | 2 ++ spec/models/project_services/slack_slash_commands_service_spec.rb | 2 ++ spec/models/project_services/teamcity_service_spec.rb | 2 ++ spec/models/project_services/youtrack_service_spec.rb | 2 ++ spec/models/project_snippet_spec.rb | 2 ++ spec/models/project_spec.rb | 2 ++ spec/models/project_statistics_spec.rb | 2 ++ spec/models/project_team_spec.rb | 2 ++ spec/models/project_wiki_spec.rb | 2 ++ spec/models/protectable_dropdown_spec.rb | 2 ++ spec/models/protected_branch/merge_access_level_spec.rb | 2 ++ spec/models/protected_branch/push_access_level_spec.rb | 2 ++ spec/models/protected_branch_spec.rb | 2 ++ spec/models/protected_tag_spec.rb | 2 ++ spec/models/push_event_payload_spec.rb | 2 ++ spec/models/push_event_spec.rb | 2 ++ spec/models/redirect_route_spec.rb | 2 ++ spec/models/release_spec.rb | 2 ++ spec/models/remote_mirror_spec.rb | 2 ++ spec/models/repository_language_spec.rb | 2 ++ spec/models/repository_spec.rb | 2 ++ spec/models/route_spec.rb | 2 ++ spec/models/sent_notification_spec.rb | 2 ++ spec/models/service_spec.rb | 2 ++ spec/models/snippet_blob_spec.rb | 2 ++ spec/models/snippet_spec.rb | 2 ++ spec/models/spam_log_spec.rb | 2 ++ spec/models/ssh_host_key_spec.rb | 2 ++ spec/models/subscription_spec.rb | 2 ++ spec/models/system_note_metadata_spec.rb | 2 ++ spec/models/term_agreement_spec.rb | 2 ++ spec/models/timelog_spec.rb | 2 ++ spec/models/todo_spec.rb | 2 ++ spec/models/tree_spec.rb | 2 ++ spec/models/trending_project_spec.rb | 2 ++ spec/models/upload_spec.rb | 2 ++ spec/models/user_agent_detail_spec.rb | 2 ++ spec/models/user_callout_spec.rb | 2 ++ spec/models/user_custom_attribute_spec.rb | 2 ++ spec/models/user_interacted_project_spec.rb | 2 ++ spec/models/user_spec.rb | 2 ++ spec/models/wiki_directory_spec.rb | 2 ++ spec/models/wiki_page_spec.rb | 2 ++ 276 files changed, 552 insertions(+) diff --git a/spec/models/ability_spec.rb b/spec/models/ability_spec.rb index eee80e9bad7..d9d60e02a97 100644 --- a/spec/models/ability_spec.rb +++ b/spec/models/ability_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Ability do diff --git a/spec/models/abuse_report_spec.rb b/spec/models/abuse_report_spec.rb index f49a61062c1..a5f8e999d5d 100644 --- a/spec/models/abuse_report_spec.rb +++ b/spec/models/abuse_report_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' describe AbuseReport do diff --git a/spec/models/active_session_spec.rb b/spec/models/active_session_spec.rb index e128fe8a4b7..b523f393ece 100644 --- a/spec/models/active_session_spec.rb +++ b/spec/models/active_session_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' RSpec.describe ActiveSession, :clean_gitlab_redis_shared_state do diff --git a/spec/models/appearance_spec.rb b/spec/models/appearance_spec.rb index 3e95aa2b5dd..209d138f956 100644 --- a/spec/models/appearance_spec.rb +++ b/spec/models/appearance_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' describe Appearance do diff --git a/spec/models/application_setting/term_spec.rb b/spec/models/application_setting/term_spec.rb index aa49594f4d1..dd263335b81 100644 --- a/spec/models/application_setting/term_spec.rb +++ b/spec/models/application_setting/term_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe ApplicationSetting::Term do diff --git a/spec/models/application_setting_spec.rb b/spec/models/application_setting_spec.rb index 314f0728b8e..c5579dafb4a 100644 --- a/spec/models/application_setting_spec.rb +++ b/spec/models/application_setting_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe ApplicationSetting do diff --git a/spec/models/award_emoji_spec.rb b/spec/models/award_emoji_spec.rb index 3f52091698c..8452ac69734 100644 --- a/spec/models/award_emoji_spec.rb +++ b/spec/models/award_emoji_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe AwardEmoji do diff --git a/spec/models/badge_spec.rb b/spec/models/badge_spec.rb index 33dc19e3432..314d7d1e9f4 100644 --- a/spec/models/badge_spec.rb +++ b/spec/models/badge_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Badge do diff --git a/spec/models/badges/group_badge_spec.rb b/spec/models/badges/group_badge_spec.rb index ed7f83d0489..c297bc957ea 100644 --- a/spec/models/badges/group_badge_spec.rb +++ b/spec/models/badges/group_badge_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe GroupBadge do diff --git a/spec/models/badges/project_badge_spec.rb b/spec/models/badges/project_badge_spec.rb index 0e1a8159cb6..e683d110252 100644 --- a/spec/models/badges/project_badge_spec.rb +++ b/spec/models/badges/project_badge_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe ProjectBadge do diff --git a/spec/models/blob_spec.rb b/spec/models/blob_spec.rb index 05cf242e84d..d0e1688cce3 100644 --- a/spec/models/blob_spec.rb +++ b/spec/models/blob_spec.rb @@ -1,4 +1,6 @@ # encoding: utf-8 +# frozen_string_literal: true + require 'rails_helper' describe Blob do diff --git a/spec/models/blob_viewer/base_spec.rb b/spec/models/blob_viewer/base_spec.rb index 7ba28f72215..39c7a34f052 100644 --- a/spec/models/blob_viewer/base_spec.rb +++ b/spec/models/blob_viewer/base_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe BlobViewer::Base do diff --git a/spec/models/blob_viewer/changelog_spec.rb b/spec/models/blob_viewer/changelog_spec.rb index db41eca0fc8..0fcc94182af 100644 --- a/spec/models/blob_viewer/changelog_spec.rb +++ b/spec/models/blob_viewer/changelog_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe BlobViewer::Changelog do diff --git a/spec/models/blob_viewer/composer_json_spec.rb b/spec/models/blob_viewer/composer_json_spec.rb index 85b0d9668a0..eda34779679 100644 --- a/spec/models/blob_viewer/composer_json_spec.rb +++ b/spec/models/blob_viewer/composer_json_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe BlobViewer::ComposerJson do diff --git a/spec/models/blob_viewer/gemspec_spec.rb b/spec/models/blob_viewer/gemspec_spec.rb index d8c4490637f..b6cc82c03ba 100644 --- a/spec/models/blob_viewer/gemspec_spec.rb +++ b/spec/models/blob_viewer/gemspec_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe BlobViewer::Gemspec do diff --git a/spec/models/blob_viewer/gitlab_ci_yml_spec.rb b/spec/models/blob_viewer/gitlab_ci_yml_spec.rb index 16bf947b493..db405ceb4f1 100644 --- a/spec/models/blob_viewer/gitlab_ci_yml_spec.rb +++ b/spec/models/blob_viewer/gitlab_ci_yml_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe BlobViewer::GitlabCiYml do diff --git a/spec/models/blob_viewer/license_spec.rb b/spec/models/blob_viewer/license_spec.rb index 222ed166ee0..e02bfae3829 100644 --- a/spec/models/blob_viewer/license_spec.rb +++ b/spec/models/blob_viewer/license_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe BlobViewer::License do diff --git a/spec/models/blob_viewer/package_json_spec.rb b/spec/models/blob_viewer/package_json_spec.rb index fbaa8d47a71..b317278f3c8 100644 --- a/spec/models/blob_viewer/package_json_spec.rb +++ b/spec/models/blob_viewer/package_json_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe BlobViewer::PackageJson do diff --git a/spec/models/blob_viewer/podspec_json_spec.rb b/spec/models/blob_viewer/podspec_json_spec.rb index 9a23877b23f..7f1fb8666fd 100644 --- a/spec/models/blob_viewer/podspec_json_spec.rb +++ b/spec/models/blob_viewer/podspec_json_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe BlobViewer::PodspecJson do diff --git a/spec/models/blob_viewer/podspec_spec.rb b/spec/models/blob_viewer/podspec_spec.rb index 02d06ea24d6..527ae79d766 100644 --- a/spec/models/blob_viewer/podspec_spec.rb +++ b/spec/models/blob_viewer/podspec_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe BlobViewer::Podspec do diff --git a/spec/models/blob_viewer/readme_spec.rb b/spec/models/blob_viewer/readme_spec.rb index 8d11d58cfca..958927bddb4 100644 --- a/spec/models/blob_viewer/readme_spec.rb +++ b/spec/models/blob_viewer/readme_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe BlobViewer::Readme do diff --git a/spec/models/blob_viewer/route_map_spec.rb b/spec/models/blob_viewer/route_map_spec.rb index c13662427b0..f7ce873c9d1 100644 --- a/spec/models/blob_viewer/route_map_spec.rb +++ b/spec/models/blob_viewer/route_map_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe BlobViewer::RouteMap do diff --git a/spec/models/blob_viewer/server_side_spec.rb b/spec/models/blob_viewer/server_side_spec.rb index 63790486200..f95305abe78 100644 --- a/spec/models/blob_viewer/server_side_spec.rb +++ b/spec/models/blob_viewer/server_side_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe BlobViewer::ServerSide do diff --git a/spec/models/board_spec.rb b/spec/models/board_spec.rb index 12d29540137..54452faa0e1 100644 --- a/spec/models/board_spec.rb +++ b/spec/models/board_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' describe Board do diff --git a/spec/models/broadcast_message_spec.rb b/spec/models/broadcast_message_spec.rb index 30ca07d5d2c..3ab013ddc0e 100644 --- a/spec/models/broadcast_message_spec.rb +++ b/spec/models/broadcast_message_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe BroadcastMessage do diff --git a/spec/models/chat_name_spec.rb b/spec/models/chat_name_spec.rb index 504bc710b25..82991937644 100644 --- a/spec/models/chat_name_spec.rb +++ b/spec/models/chat_name_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe ChatName do diff --git a/spec/models/chat_team_spec.rb b/spec/models/chat_team_spec.rb index 70a9a206faa..76beb3d506b 100644 --- a/spec/models/chat_team_spec.rb +++ b/spec/models/chat_team_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe ChatTeam do diff --git a/spec/models/ci/artifact_blob_spec.rb b/spec/models/ci/artifact_blob_spec.rb index 0014bbcf9f5..f63816fd92a 100644 --- a/spec/models/ci/artifact_blob_spec.rb +++ b/spec/models/ci/artifact_blob_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Ci::ArtifactBlob do diff --git a/spec/models/ci/bridge_spec.rb b/spec/models/ci/bridge_spec.rb index b5ec8991720..aacfbe3f180 100644 --- a/spec/models/ci/bridge_spec.rb +++ b/spec/models/ci/bridge_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Ci::Bridge do diff --git a/spec/models/ci/build_metadata_spec.rb b/spec/models/ci/build_metadata_spec.rb index 016a5899eef..917a65ddf21 100644 --- a/spec/models/ci/build_metadata_spec.rb +++ b/spec/models/ci/build_metadata_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Ci::BuildMetadata do diff --git a/spec/models/ci/build_runner_session_spec.rb b/spec/models/ci/build_runner_session_spec.rb index 35622366829..a52c10019e6 100644 --- a/spec/models/ci/build_runner_session_spec.rb +++ b/spec/models/ci/build_runner_session_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Ci::BuildRunnerSession, model: true do diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index 3ec07143e93..2c41dfa65cd 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Ci::Build do diff --git a/spec/models/ci/build_trace_chunk_spec.rb b/spec/models/ci/build_trace_chunk_spec.rb index 59db347582b..f7ee4614e02 100644 --- a/spec/models/ci/build_trace_chunk_spec.rb +++ b/spec/models/ci/build_trace_chunk_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do diff --git a/spec/models/ci/build_trace_chunks/database_spec.rb b/spec/models/ci/build_trace_chunks/database_spec.rb index d8fc9d57e95..eb94d7dae38 100644 --- a/spec/models/ci/build_trace_chunks/database_spec.rb +++ b/spec/models/ci/build_trace_chunks/database_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Ci::BuildTraceChunks::Database do diff --git a/spec/models/ci/build_trace_chunks/fog_spec.rb b/spec/models/ci/build_trace_chunks/fog_spec.rb index 8f49190af13..b8d78bcd069 100644 --- a/spec/models/ci/build_trace_chunks/fog_spec.rb +++ b/spec/models/ci/build_trace_chunks/fog_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Ci::BuildTraceChunks::Fog do diff --git a/spec/models/ci/build_trace_chunks/redis_spec.rb b/spec/models/ci/build_trace_chunks/redis_spec.rb index 9da1e6a95ee..6cff33d24fa 100644 --- a/spec/models/ci/build_trace_chunks/redis_spec.rb +++ b/spec/models/ci/build_trace_chunks/redis_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Ci::BuildTraceChunks::Redis, :clean_gitlab_redis_shared_state do diff --git a/spec/models/ci/build_trace_section_name_spec.rb b/spec/models/ci/build_trace_section_name_spec.rb index 386ee6880cb..11e2d27ff79 100644 --- a/spec/models/ci/build_trace_section_name_spec.rb +++ b/spec/models/ci/build_trace_section_name_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Ci::BuildTraceSectionName, model: true do diff --git a/spec/models/ci/build_trace_section_spec.rb b/spec/models/ci/build_trace_section_spec.rb index 541a9a36fb8..5bd3a953ec0 100644 --- a/spec/models/ci/build_trace_section_spec.rb +++ b/spec/models/ci/build_trace_section_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Ci::BuildTraceSection, model: true do diff --git a/spec/models/ci/group_spec.rb b/spec/models/ci/group_spec.rb index 838fa63cb1f..36c65d92840 100644 --- a/spec/models/ci/group_spec.rb +++ b/spec/models/ci/group_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Ci::Group do diff --git a/spec/models/ci/group_variable_spec.rb b/spec/models/ci/group_variable_spec.rb index 21d96bf3454..b3999765e5f 100644 --- a/spec/models/ci/group_variable_spec.rb +++ b/spec/models/ci/group_variable_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Ci::GroupVariable do diff --git a/spec/models/ci/job_artifact_spec.rb b/spec/models/ci/job_artifact_spec.rb index c68ba02b8de..d7abd54eec1 100644 --- a/spec/models/ci/job_artifact_spec.rb +++ b/spec/models/ci/job_artifact_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Ci::JobArtifact do diff --git a/spec/models/ci/legacy_stage_spec.rb b/spec/models/ci/legacy_stage_spec.rb index 0c33c1466b7..be0307518eb 100644 --- a/spec/models/ci/legacy_stage_spec.rb +++ b/spec/models/ci/legacy_stage_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Ci::LegacyStage do diff --git a/spec/models/ci/pipeline_schedule_spec.rb b/spec/models/ci/pipeline_schedule_spec.rb index 8ee15f0e734..81913f4a3b6 100644 --- a/spec/models/ci/pipeline_schedule_spec.rb +++ b/spec/models/ci/pipeline_schedule_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Ci::PipelineSchedule do diff --git a/spec/models/ci/pipeline_schedule_variable_spec.rb b/spec/models/ci/pipeline_schedule_variable_spec.rb index dc8427f28bc..3c9379ecb0d 100644 --- a/spec/models/ci/pipeline_schedule_variable_spec.rb +++ b/spec/models/ci/pipeline_schedule_variable_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Ci::PipelineScheduleVariable do diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb index e5f3a9ce67a..e76cf376ed1 100644 --- a/spec/models/ci/pipeline_spec.rb +++ b/spec/models/ci/pipeline_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Ci::Pipeline, :mailer do diff --git a/spec/models/ci/pipeline_variable_spec.rb b/spec/models/ci/pipeline_variable_spec.rb index 03d09cb31d6..2ecb688299a 100644 --- a/spec/models/ci/pipeline_variable_spec.rb +++ b/spec/models/ci/pipeline_variable_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Ci::PipelineVariable do diff --git a/spec/models/ci/runner_spec.rb b/spec/models/ci/runner_spec.rb index eb2daed7f32..b3ab63925dd 100644 --- a/spec/models/ci/runner_spec.rb +++ b/spec/models/ci/runner_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Ci::Runner do diff --git a/spec/models/ci/stage_spec.rb b/spec/models/ci/stage_spec.rb index 3228c400155..661958390e2 100644 --- a/spec/models/ci/stage_spec.rb +++ b/spec/models/ci/stage_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Ci::Stage, :models do diff --git a/spec/models/ci/trigger_request_spec.rb b/spec/models/ci/trigger_request_spec.rb index 7dcf3528f73..d04349bec92 100644 --- a/spec/models/ci/trigger_request_spec.rb +++ b/spec/models/ci/trigger_request_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Ci::TriggerRequest do diff --git a/spec/models/ci/trigger_spec.rb b/spec/models/ci/trigger_spec.rb index d4b72205203..fde8375f2a5 100644 --- a/spec/models/ci/trigger_spec.rb +++ b/spec/models/ci/trigger_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Ci::Trigger do diff --git a/spec/models/ci/variable_spec.rb b/spec/models/ci/variable_spec.rb index 02c07a2bd83..d2df6b3344e 100644 --- a/spec/models/ci/variable_spec.rb +++ b/spec/models/ci/variable_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Ci::Variable do diff --git a/spec/models/clusters/applications/cert_manager_spec.rb b/spec/models/clusters/applications/cert_manager_spec.rb index cf5cbf8ec5c..fefeb8fd75f 100644 --- a/spec/models/clusters/applications/cert_manager_spec.rb +++ b/spec/models/clusters/applications/cert_manager_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' describe Clusters::Applications::CertManager do diff --git a/spec/models/clusters/applications/helm_spec.rb b/spec/models/clusters/applications/helm_spec.rb index f16eff92167..f97d126d918 100644 --- a/spec/models/clusters/applications/helm_spec.rb +++ b/spec/models/clusters/applications/helm_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' describe Clusters::Applications::Helm do diff --git a/spec/models/clusters/applications/ingress_spec.rb b/spec/models/clusters/applications/ingress_spec.rb index a40fa988287..09e60b9a206 100644 --- a/spec/models/clusters/applications/ingress_spec.rb +++ b/spec/models/clusters/applications/ingress_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' describe Clusters::Applications::Ingress do diff --git a/spec/models/clusters/applications/jupyter_spec.rb b/spec/models/clusters/applications/jupyter_spec.rb index 2967c4076c6..5970a1959b5 100644 --- a/spec/models/clusters/applications/jupyter_spec.rb +++ b/spec/models/clusters/applications/jupyter_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' describe Clusters::Applications::Jupyter do diff --git a/spec/models/clusters/applications/knative_spec.rb b/spec/models/clusters/applications/knative_spec.rb index 054ed0be240..25493689fbc 100644 --- a/spec/models/clusters/applications/knative_spec.rb +++ b/spec/models/clusters/applications/knative_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' describe Clusters::Applications::Knative do diff --git a/spec/models/clusters/applications/prometheus_spec.rb b/spec/models/clusters/applications/prometheus_spec.rb index 81708b0c2ed..82a502addd4 100644 --- a/spec/models/clusters/applications/prometheus_spec.rb +++ b/spec/models/clusters/applications/prometheus_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' describe Clusters::Applications::Prometheus do diff --git a/spec/models/clusters/applications/runner_spec.rb b/spec/models/clusters/applications/runner_spec.rb index 3ce8aa1c7bc..7e2f5835279 100644 --- a/spec/models/clusters/applications/runner_spec.rb +++ b/spec/models/clusters/applications/runner_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' describe Clusters::Applications::Runner do diff --git a/spec/models/clusters/platforms/kubernetes_spec.rb b/spec/models/clusters/platforms/kubernetes_spec.rb index a79b436c22a..14bec17a2bd 100644 --- a/spec/models/clusters/platforms/kubernetes_spec.rb +++ b/spec/models/clusters/platforms/kubernetes_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Clusters::Platforms::Kubernetes, :use_clean_rails_memory_store_caching do diff --git a/spec/models/clusters/project_spec.rb b/spec/models/clusters/project_spec.rb index 82ef5a23c18..2f017e69251 100644 --- a/spec/models/clusters/project_spec.rb +++ b/spec/models/clusters/project_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Clusters::Project do diff --git a/spec/models/clusters/providers/gcp_spec.rb b/spec/models/clusters/providers/gcp_spec.rb index 5012e6f15c6..785db4febe0 100644 --- a/spec/models/clusters/providers/gcp_spec.rb +++ b/spec/models/clusters/providers/gcp_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Clusters::Providers::Gcp do diff --git a/spec/models/commit_collection_spec.rb b/spec/models/commit_collection_spec.rb index 30c504ebea8..8a7fcb39fe2 100644 --- a/spec/models/commit_collection_spec.rb +++ b/spec/models/commit_collection_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe CommitCollection do diff --git a/spec/models/commit_range_spec.rb b/spec/models/commit_range_spec.rb index f2efcd9d0e9..b96ca89c893 100644 --- a/spec/models/commit_range_spec.rb +++ b/spec/models/commit_range_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe CommitRange do diff --git a/spec/models/commit_spec.rb b/spec/models/commit_spec.rb index 9d4e18534ae..14f4b4d692f 100644 --- a/spec/models/commit_spec.rb +++ b/spec/models/commit_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Commit do diff --git a/spec/models/commit_status_spec.rb b/spec/models/commit_status_spec.rb index e2b7f5c6ee2..ca2f9e36c98 100644 --- a/spec/models/commit_status_spec.rb +++ b/spec/models/commit_status_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe CommitStatus do diff --git a/spec/models/compare_spec.rb b/spec/models/compare_spec.rb index 0bc3ee014e6..43c3580bed2 100644 --- a/spec/models/compare_spec.rb +++ b/spec/models/compare_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Compare do diff --git a/spec/models/concerns/access_requestable_spec.rb b/spec/models/concerns/access_requestable_spec.rb index 04d6cfa2c02..de2bc3a387b 100644 --- a/spec/models/concerns/access_requestable_spec.rb +++ b/spec/models/concerns/access_requestable_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe AccessRequestable do diff --git a/spec/models/concerns/avatarable_spec.rb b/spec/models/concerns/avatarable_spec.rb index 1ea7f2b9985..c750be6b75c 100644 --- a/spec/models/concerns/avatarable_spec.rb +++ b/spec/models/concerns/avatarable_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Avatarable do diff --git a/spec/models/concerns/awardable_spec.rb b/spec/models/concerns/awardable_spec.rb index 5713106418d..9e7106281ee 100644 --- a/spec/models/concerns/awardable_spec.rb +++ b/spec/models/concerns/awardable_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Awardable do diff --git a/spec/models/concerns/batch_destroy_dependent_associations_spec.rb b/spec/models/concerns/batch_destroy_dependent_associations_spec.rb index e5392fe0462..1fe90d3cc9a 100644 --- a/spec/models/concerns/batch_destroy_dependent_associations_spec.rb +++ b/spec/models/concerns/batch_destroy_dependent_associations_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe BatchDestroyDependentAssociations do diff --git a/spec/models/concerns/blocks_json_serialization_spec.rb b/spec/models/concerns/blocks_json_serialization_spec.rb index 5906b588d0e..e8657c45a93 100644 --- a/spec/models/concerns/blocks_json_serialization_spec.rb +++ b/spec/models/concerns/blocks_json_serialization_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' describe BlocksJsonSerialization do diff --git a/spec/models/concerns/cache_markdown_field_spec.rb b/spec/models/concerns/cache_markdown_field_spec.rb index 7d555f15e39..78637ff10c6 100644 --- a/spec/models/concerns/cache_markdown_field_spec.rb +++ b/spec/models/concerns/cache_markdown_field_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe CacheMarkdownField do diff --git a/spec/models/concerns/cacheable_attributes_spec.rb b/spec/models/concerns/cacheable_attributes_spec.rb index 43a544cfe26..394fac52aa7 100644 --- a/spec/models/concerns/cacheable_attributes_spec.rb +++ b/spec/models/concerns/cacheable_attributes_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe CacheableAttributes do diff --git a/spec/models/concerns/case_sensitivity_spec.rb b/spec/models/concerns/case_sensitivity_spec.rb index 1bf6c9b3404..d6d41a25eac 100644 --- a/spec/models/concerns/case_sensitivity_spec.rb +++ b/spec/models/concerns/case_sensitivity_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe CaseSensitivity do diff --git a/spec/models/concerns/chronic_duration_attribute_spec.rb b/spec/models/concerns/chronic_duration_attribute_spec.rb index 51221e07ca3..e41d75568f7 100644 --- a/spec/models/concerns/chronic_duration_attribute_spec.rb +++ b/spec/models/concerns/chronic_duration_attribute_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' shared_examples 'ChronicDurationAttribute reader' do diff --git a/spec/models/concerns/deployable_spec.rb b/spec/models/concerns/deployable_spec.rb index 6951be903fe..42bed9434f5 100644 --- a/spec/models/concerns/deployable_spec.rb +++ b/spec/models/concerns/deployable_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' describe Deployable do diff --git a/spec/models/concerns/deployment_platform_spec.rb b/spec/models/concerns/deployment_platform_spec.rb index 19ab4382b53..0e34d8fccf3 100644 --- a/spec/models/concerns/deployment_platform_spec.rb +++ b/spec/models/concerns/deployment_platform_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' describe DeploymentPlatform do diff --git a/spec/models/concerns/discussion_on_diff_spec.rb b/spec/models/concerns/discussion_on_diff_spec.rb index 64bf04071e8..baddca47dfa 100644 --- a/spec/models/concerns/discussion_on_diff_spec.rb +++ b/spec/models/concerns/discussion_on_diff_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe DiscussionOnDiff do diff --git a/spec/models/concerns/each_batch_spec.rb b/spec/models/concerns/each_batch_spec.rb index 17224c09693..c4cf8e80f7a 100644 --- a/spec/models/concerns/each_batch_spec.rb +++ b/spec/models/concerns/each_batch_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe EachBatch do diff --git a/spec/models/concerns/editable_spec.rb b/spec/models/concerns/editable_spec.rb index 49a9a8ebcbc..4a4a3ca5687 100644 --- a/spec/models/concerns/editable_spec.rb +++ b/spec/models/concerns/editable_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Editable do diff --git a/spec/models/concerns/expirable_spec.rb b/spec/models/concerns/expirable_spec.rb index f7b436f32e6..f4f5eab5b86 100644 --- a/spec/models/concerns/expirable_spec.rb +++ b/spec/models/concerns/expirable_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Expirable do diff --git a/spec/models/concerns/faster_cache_keys_spec.rb b/spec/models/concerns/faster_cache_keys_spec.rb index 8d3f94267fa..7830acbae3d 100644 --- a/spec/models/concerns/faster_cache_keys_spec.rb +++ b/spec/models/concerns/faster_cache_keys_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe FasterCacheKeys do diff --git a/spec/models/concerns/feature_gate_spec.rb b/spec/models/concerns/feature_gate_spec.rb index 3f601243245..276d3d9e1d5 100644 --- a/spec/models/concerns/feature_gate_spec.rb +++ b/spec/models/concerns/feature_gate_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe FeatureGate do diff --git a/spec/models/concerns/group_descendant_spec.rb b/spec/models/concerns/group_descendant_spec.rb index 28352d8c961..194caac3fce 100644 --- a/spec/models/concerns/group_descendant_spec.rb +++ b/spec/models/concerns/group_descendant_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe GroupDescendant, :nested_groups do diff --git a/spec/models/concerns/has_status_spec.rb b/spec/models/concerns/has_status_spec.rb index e8b1eba67cc..a217dc42537 100644 --- a/spec/models/concerns/has_status_spec.rb +++ b/spec/models/concerns/has_status_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe HasStatus do diff --git a/spec/models/concerns/has_variable_spec.rb b/spec/models/concerns/has_variable_spec.rb index bff96e12ffa..2bb21d7934e 100644 --- a/spec/models/concerns/has_variable_spec.rb +++ b/spec/models/concerns/has_variable_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe HasVariable do diff --git a/spec/models/concerns/ignorable_column_spec.rb b/spec/models/concerns/ignorable_column_spec.rb index b70f2331a0e..6b82825d2cc 100644 --- a/spec/models/concerns/ignorable_column_spec.rb +++ b/spec/models/concerns/ignorable_column_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe IgnorableColumn do diff --git a/spec/models/concerns/issuable_spec.rb b/spec/models/concerns/issuable_spec.rb index 72c6161424b..259ac6852a8 100644 --- a/spec/models/concerns/issuable_spec.rb +++ b/spec/models/concerns/issuable_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Issuable do diff --git a/spec/models/concerns/loaded_in_group_list_spec.rb b/spec/models/concerns/loaded_in_group_list_spec.rb index 7a279547a3a..7c97b580779 100644 --- a/spec/models/concerns/loaded_in_group_list_spec.rb +++ b/spec/models/concerns/loaded_in_group_list_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe LoadedInGroupList do diff --git a/spec/models/concerns/manual_inverse_association_spec.rb b/spec/models/concerns/manual_inverse_association_spec.rb index ff4a04ea573..ee32e3b165b 100644 --- a/spec/models/concerns/manual_inverse_association_spec.rb +++ b/spec/models/concerns/manual_inverse_association_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe ManualInverseAssociation do diff --git a/spec/models/concerns/mentionable_spec.rb b/spec/models/concerns/mentionable_spec.rb index a9b237fa9ea..f31e3e8821d 100644 --- a/spec/models/concerns/mentionable_spec.rb +++ b/spec/models/concerns/mentionable_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Mentionable do diff --git a/spec/models/concerns/milestoneish_spec.rb b/spec/models/concerns/milestoneish_spec.rb index 81ca5b638fe..22d4b2cc517 100644 --- a/spec/models/concerns/milestoneish_spec.rb +++ b/spec/models/concerns/milestoneish_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Milestone, 'Milestoneish' do diff --git a/spec/models/concerns/noteable_spec.rb b/spec/models/concerns/noteable_spec.rb index 485a6e165a1..ee613b199ad 100644 --- a/spec/models/concerns/noteable_spec.rb +++ b/spec/models/concerns/noteable_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Noteable do diff --git a/spec/models/concerns/participable_spec.rb b/spec/models/concerns/participable_spec.rb index 431f1482615..3d5937c4fc6 100644 --- a/spec/models/concerns/participable_spec.rb +++ b/spec/models/concerns/participable_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Participable do diff --git a/spec/models/concerns/presentable_spec.rb b/spec/models/concerns/presentable_spec.rb index 941647a79fb..9db868dd348 100644 --- a/spec/models/concerns/presentable_spec.rb +++ b/spec/models/concerns/presentable_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Presentable do diff --git a/spec/models/concerns/project_features_compatibility_spec.rb b/spec/models/concerns/project_features_compatibility_spec.rb index 9041690023f..5aa43b58217 100644 --- a/spec/models/concerns/project_features_compatibility_spec.rb +++ b/spec/models/concerns/project_features_compatibility_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe ProjectFeaturesCompatibility do diff --git a/spec/models/concerns/prometheus_adapter_spec.rb b/spec/models/concerns/prometheus_adapter_spec.rb index f4b9c57e71a..7148261b1e4 100644 --- a/spec/models/concerns/prometheus_adapter_spec.rb +++ b/spec/models/concerns/prometheus_adapter_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe PrometheusAdapter, :use_clean_rails_memory_store_caching do diff --git a/spec/models/concerns/protected_ref_access_spec.rb b/spec/models/concerns/protected_ref_access_spec.rb index ce602337647..94798f0590d 100644 --- a/spec/models/concerns/protected_ref_access_spec.rb +++ b/spec/models/concerns/protected_ref_access_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe ProtectedRefAccess do diff --git a/spec/models/concerns/reactive_caching_spec.rb b/spec/models/concerns/reactive_caching_spec.rb index 03ae45e6b17..32e13d5abed 100644 --- a/spec/models/concerns/reactive_caching_spec.rb +++ b/spec/models/concerns/reactive_caching_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe ReactiveCaching, :use_clean_rails_memory_store_caching do diff --git a/spec/models/concerns/redactable_spec.rb b/spec/models/concerns/redactable_spec.rb index 7feeaa54069..57c7d2cb767 100644 --- a/spec/models/concerns/redactable_spec.rb +++ b/spec/models/concerns/redactable_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Redactable do diff --git a/spec/models/concerns/redis_cacheable_spec.rb b/spec/models/concerns/redis_cacheable_spec.rb index 23c6c6233e9..a9dca27f258 100644 --- a/spec/models/concerns/redis_cacheable_spec.rb +++ b/spec/models/concerns/redis_cacheable_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe RedisCacheable do diff --git a/spec/models/concerns/relative_positioning_spec.rb b/spec/models/concerns/relative_positioning_spec.rb index ac8da30b6c9..d0ae45f7871 100644 --- a/spec/models/concerns/relative_positioning_spec.rb +++ b/spec/models/concerns/relative_positioning_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe RelativePositioning do diff --git a/spec/models/concerns/resolvable_discussion_spec.rb b/spec/models/concerns/resolvable_discussion_spec.rb index 97b046b0f21..9ea01ca9002 100644 --- a/spec/models/concerns/resolvable_discussion_spec.rb +++ b/spec/models/concerns/resolvable_discussion_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Discussion, ResolvableDiscussion do diff --git a/spec/models/concerns/resolvable_note_spec.rb b/spec/models/concerns/resolvable_note_spec.rb index fcb5250278e..4f46252a044 100644 --- a/spec/models/concerns/resolvable_note_spec.rb +++ b/spec/models/concerns/resolvable_note_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Note, ResolvableNote do diff --git a/spec/models/concerns/routable_spec.rb b/spec/models/concerns/routable_spec.rb index 565266321d3..1fb0dd5030c 100644 --- a/spec/models/concerns/routable_spec.rb +++ b/spec/models/concerns/routable_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Group, 'Routable' do diff --git a/spec/models/concerns/sha_attribute_spec.rb b/spec/models/concerns/sha_attribute_spec.rb index 0d3beb6a6e3..a4a81ae126d 100644 --- a/spec/models/concerns/sha_attribute_spec.rb +++ b/spec/models/concerns/sha_attribute_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe ShaAttribute do diff --git a/spec/models/concerns/sortable_spec.rb b/spec/models/concerns/sortable_spec.rb index 0a9d2021a19..184f7986a6f 100644 --- a/spec/models/concerns/sortable_spec.rb +++ b/spec/models/concerns/sortable_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Sortable do diff --git a/spec/models/concerns/spammable_spec.rb b/spec/models/concerns/spammable_spec.rb index e698207166c..650d49e41a1 100644 --- a/spec/models/concerns/spammable_spec.rb +++ b/spec/models/concerns/spammable_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Spammable do diff --git a/spec/models/concerns/strip_attribute_spec.rb b/spec/models/concerns/strip_attribute_spec.rb index 8c945686b66..5c0d1042e06 100644 --- a/spec/models/concerns/strip_attribute_spec.rb +++ b/spec/models/concerns/strip_attribute_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe StripAttribute do diff --git a/spec/models/concerns/subscribable_spec.rb b/spec/models/concerns/subscribable_spec.rb index 45dfb136aea..2f88adf08dd 100644 --- a/spec/models/concerns/subscribable_spec.rb +++ b/spec/models/concerns/subscribable_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Subscribable, 'Subscribable' do diff --git a/spec/models/concerns/token_authenticatable_spec.rb b/spec/models/concerns/token_authenticatable_spec.rb index 40cb4eef60a..51e28974ae0 100644 --- a/spec/models/concerns/token_authenticatable_spec.rb +++ b/spec/models/concerns/token_authenticatable_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' shared_examples 'TokenAuthenticatable' do diff --git a/spec/models/concerns/token_authenticatable_strategies/base_spec.rb b/spec/models/concerns/token_authenticatable_strategies/base_spec.rb index 2a0182b4294..7332da309d5 100644 --- a/spec/models/concerns/token_authenticatable_strategies/base_spec.rb +++ b/spec/models/concerns/token_authenticatable_strategies/base_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe TokenAuthenticatableStrategies::Base do diff --git a/spec/models/concerns/token_authenticatable_strategies/encrypted_spec.rb b/spec/models/concerns/token_authenticatable_strategies/encrypted_spec.rb index ca38f86c5ab..70f41981b3b 100644 --- a/spec/models/concerns/token_authenticatable_strategies/encrypted_spec.rb +++ b/spec/models/concerns/token_authenticatable_strategies/encrypted_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe TokenAuthenticatableStrategies::Encrypted do diff --git a/spec/models/concerns/triggerable_hooks_spec.rb b/spec/models/concerns/triggerable_hooks_spec.rb index 265abd6bd72..f28e5f56411 100644 --- a/spec/models/concerns/triggerable_hooks_spec.rb +++ b/spec/models/concerns/triggerable_hooks_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' RSpec.describe TriggerableHooks do diff --git a/spec/models/concerns/uniquify_spec.rb b/spec/models/concerns/uniquify_spec.rb index 6cd2de6dcce..9ba35702ba6 100644 --- a/spec/models/concerns/uniquify_spec.rb +++ b/spec/models/concerns/uniquify_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Uniquify do diff --git a/spec/models/container_repository_spec.rb b/spec/models/container_repository_spec.rb index e46945e301e..013112d1d51 100644 --- a/spec/models/container_repository_spec.rb +++ b/spec/models/container_repository_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe ContainerRepository do diff --git a/spec/models/conversational_development_index/metric_spec.rb b/spec/models/conversational_development_index/metric_spec.rb index b3193619503..60b1a860dfd 100644 --- a/spec/models/conversational_development_index/metric_spec.rb +++ b/spec/models/conversational_development_index/metric_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' describe ConversationalDevelopmentIndex::Metric do diff --git a/spec/models/cycle_analytics/code_spec.rb b/spec/models/cycle_analytics/code_spec.rb index 6a6b58fb52b..b22a0340015 100644 --- a/spec/models/cycle_analytics/code_spec.rb +++ b/spec/models/cycle_analytics/code_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'CycleAnalytics#code' do diff --git a/spec/models/cycle_analytics/issue_spec.rb b/spec/models/cycle_analytics/issue_spec.rb index 45f1b4fe8a3..07d60be091a 100644 --- a/spec/models/cycle_analytics/issue_spec.rb +++ b/spec/models/cycle_analytics/issue_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'CycleAnalytics#issue' do diff --git a/spec/models/cycle_analytics/plan_spec.rb b/spec/models/cycle_analytics/plan_spec.rb index d366e2b723a..3d22a284264 100644 --- a/spec/models/cycle_analytics/plan_spec.rb +++ b/spec/models/cycle_analytics/plan_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'CycleAnalytics#plan' do diff --git a/spec/models/cycle_analytics/production_spec.rb b/spec/models/cycle_analytics/production_spec.rb index 156eb96cfce..383727cd8f7 100644 --- a/spec/models/cycle_analytics/production_spec.rb +++ b/spec/models/cycle_analytics/production_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'CycleAnalytics#production' do diff --git a/spec/models/cycle_analytics/review_spec.rb b/spec/models/cycle_analytics/review_spec.rb index 0aedfb49cb5..1af5f9cc1f4 100644 --- a/spec/models/cycle_analytics/review_spec.rb +++ b/spec/models/cycle_analytics/review_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'CycleAnalytics#review' do diff --git a/spec/models/cycle_analytics/staging_spec.rb b/spec/models/cycle_analytics/staging_spec.rb index 0cbda50c688..8375944f03c 100644 --- a/spec/models/cycle_analytics/staging_spec.rb +++ b/spec/models/cycle_analytics/staging_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'CycleAnalytics#staging' do diff --git a/spec/models/cycle_analytics/test_spec.rb b/spec/models/cycle_analytics/test_spec.rb index e58b8fdff58..b78258df564 100644 --- a/spec/models/cycle_analytics/test_spec.rb +++ b/spec/models/cycle_analytics/test_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'CycleAnalytics#test' do diff --git a/spec/models/cycle_analytics_spec.rb b/spec/models/cycle_analytics_spec.rb index 0fe24870f02..5d8b5b573cf 100644 --- a/spec/models/cycle_analytics_spec.rb +++ b/spec/models/cycle_analytics_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe CycleAnalytics do diff --git a/spec/models/deploy_key_spec.rb b/spec/models/deploy_key_spec.rb index 41440c6d288..ec6cfb6b826 100644 --- a/spec/models/deploy_key_spec.rb +++ b/spec/models/deploy_key_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe DeployKey, :mailer do diff --git a/spec/models/deploy_keys_project_spec.rb b/spec/models/deploy_keys_project_spec.rb index fca3090ff4a..c137444763b 100644 --- a/spec/models/deploy_keys_project_spec.rb +++ b/spec/models/deploy_keys_project_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe DeployKeysProject do diff --git a/spec/models/deploy_token_spec.rb b/spec/models/deploy_token_spec.rb index 3435f93c999..05320703e25 100644 --- a/spec/models/deploy_token_spec.rb +++ b/spec/models/deploy_token_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe DeployToken do diff --git a/spec/models/deployment_spec.rb b/spec/models/deployment_spec.rb index 5fce9504334..d9170d5fa07 100644 --- a/spec/models/deployment_spec.rb +++ b/spec/models/deployment_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Deployment do diff --git a/spec/models/diff_discussion_spec.rb b/spec/models/diff_discussion_spec.rb index 50b19000799..cfeb4382927 100644 --- a/spec/models/diff_discussion_spec.rb +++ b/spec/models/diff_discussion_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe DiffDiscussion do diff --git a/spec/models/diff_note_spec.rb b/spec/models/diff_note_spec.rb index 67e5f4f7e41..fa19cb47a0d 100644 --- a/spec/models/diff_note_spec.rb +++ b/spec/models/diff_note_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe DiffNote do diff --git a/spec/models/diff_viewer/base_spec.rb b/spec/models/diff_viewer/base_spec.rb index f4efe5a7b3a..b8bdeb781dc 100644 --- a/spec/models/diff_viewer/base_spec.rb +++ b/spec/models/diff_viewer/base_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe DiffViewer::Base do diff --git a/spec/models/diff_viewer/server_side_spec.rb b/spec/models/diff_viewer/server_side_spec.rb index 86b14b6ebf3..27de0584b8a 100644 --- a/spec/models/diff_viewer/server_side_spec.rb +++ b/spec/models/diff_viewer/server_side_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe DiffViewer::ServerSide do diff --git a/spec/models/discussion_spec.rb b/spec/models/discussion_spec.rb index a46f7ed6507..0d02165787a 100644 --- a/spec/models/discussion_spec.rb +++ b/spec/models/discussion_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Discussion do diff --git a/spec/models/email_spec.rb b/spec/models/email_spec.rb index 47eb0717c0c..cae88f39660 100644 --- a/spec/models/email_spec.rb +++ b/spec/models/email_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Email do diff --git a/spec/models/environment_spec.rb b/spec/models/environment_spec.rb index ab1b306e597..448ed35cb1e 100644 --- a/spec/models/environment_spec.rb +++ b/spec/models/environment_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Environment do diff --git a/spec/models/environment_status_spec.rb b/spec/models/environment_status_spec.rb index 2576a9aba06..c503c35305f 100644 --- a/spec/models/environment_status_spec.rb +++ b/spec/models/environment_status_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe EnvironmentStatus do diff --git a/spec/models/event_collection_spec.rb b/spec/models/event_collection_spec.rb index 6078f429bdc..efe511042c3 100644 --- a/spec/models/event_collection_spec.rb +++ b/spec/models/event_collection_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe EventCollection do diff --git a/spec/models/event_spec.rb b/spec/models/event_spec.rb index ce4f8ee4705..d192fe70506 100644 --- a/spec/models/event_spec.rb +++ b/spec/models/event_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Event do diff --git a/spec/models/external_issue_spec.rb b/spec/models/external_issue_spec.rb index 83ba22caa03..9d064d458f0 100644 --- a/spec/models/external_issue_spec.rb +++ b/spec/models/external_issue_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe ExternalIssue do diff --git a/spec/models/fork_network_member_spec.rb b/spec/models/fork_network_member_spec.rb index 60d04562e6c..eab758248de 100644 --- a/spec/models/fork_network_member_spec.rb +++ b/spec/models/fork_network_member_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe ForkNetworkMember do diff --git a/spec/models/fork_network_spec.rb b/spec/models/fork_network_spec.rb index a43baf1820a..5ec0f8d6b02 100644 --- a/spec/models/fork_network_spec.rb +++ b/spec/models/fork_network_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe ForkNetwork do diff --git a/spec/models/generic_commit_status_spec.rb b/spec/models/generic_commit_status_spec.rb index a3e68d2e646..c851810ffb3 100644 --- a/spec/models/generic_commit_status_spec.rb +++ b/spec/models/generic_commit_status_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe GenericCommitStatus do diff --git a/spec/models/global_milestone_spec.rb b/spec/models/global_milestone_spec.rb index f93904065c7..9d901d01a52 100644 --- a/spec/models/global_milestone_spec.rb +++ b/spec/models/global_milestone_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe GlobalMilestone do diff --git a/spec/models/gpg_key_spec.rb b/spec/models/gpg_key_spec.rb index 58a1d2e4ea2..479b39cd139 100644 --- a/spec/models/gpg_key_spec.rb +++ b/spec/models/gpg_key_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' describe GpgKey do diff --git a/spec/models/gpg_key_subkey_spec.rb b/spec/models/gpg_key_subkey_spec.rb index 3c86837f47f..51d2f9cb9ac 100644 --- a/spec/models/gpg_key_subkey_spec.rb +++ b/spec/models/gpg_key_subkey_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' describe GpgKeySubkey do diff --git a/spec/models/gpg_signature_spec.rb b/spec/models/gpg_signature_spec.rb index e90319c39b1..47c343edf0e 100644 --- a/spec/models/gpg_signature_spec.rb +++ b/spec/models/gpg_signature_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' RSpec.describe GpgSignature do diff --git a/spec/models/group_custom_attribute_spec.rb b/spec/models/group_custom_attribute_spec.rb index 7ecb2022567..7d60c74b62b 100644 --- a/spec/models/group_custom_attribute_spec.rb +++ b/spec/models/group_custom_attribute_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe GroupCustomAttribute do diff --git a/spec/models/group_label_spec.rb b/spec/models/group_label_spec.rb index d0fc1eaa3ec..a3a5c631c3d 100644 --- a/spec/models/group_label_spec.rb +++ b/spec/models/group_label_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe GroupLabel do diff --git a/spec/models/group_milestone_spec.rb b/spec/models/group_milestone_spec.rb index fcc33cd95fe..01856870fe0 100644 --- a/spec/models/group_milestone_spec.rb +++ b/spec/models/group_milestone_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe GroupMilestone do diff --git a/spec/models/group_spec.rb b/spec/models/group_spec.rb index 16624ce47d0..2c6abddca17 100644 --- a/spec/models/group_spec.rb +++ b/spec/models/group_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Group do diff --git a/spec/models/guest_spec.rb b/spec/models/guest_spec.rb index fc30f3056e5..93862e98172 100644 --- a/spec/models/guest_spec.rb +++ b/spec/models/guest_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Guest do diff --git a/spec/models/hooks/active_hook_filter_spec.rb b/spec/models/hooks/active_hook_filter_spec.rb index df7edda2213..1249c793f7f 100644 --- a/spec/models/hooks/active_hook_filter_spec.rb +++ b/spec/models/hooks/active_hook_filter_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe ActiveHookFilter do diff --git a/spec/models/hooks/project_hook_spec.rb b/spec/models/hooks/project_hook_spec.rb index 5dd31b1b5de..a945f0d1516 100644 --- a/spec/models/hooks/project_hook_spec.rb +++ b/spec/models/hooks/project_hook_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe ProjectHook do diff --git a/spec/models/hooks/service_hook_spec.rb b/spec/models/hooks/service_hook_spec.rb index e32eaafc13f..936c2fbad27 100644 --- a/spec/models/hooks/service_hook_spec.rb +++ b/spec/models/hooks/service_hook_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe ServiceHook do diff --git a/spec/models/hooks/system_hook_spec.rb b/spec/models/hooks/system_hook_spec.rb index edd1cb455af..e0d4d2e4858 100644 --- a/spec/models/hooks/system_hook_spec.rb +++ b/spec/models/hooks/system_hook_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "spec_helper" describe SystemHook do diff --git a/spec/models/hooks/web_hook_log_spec.rb b/spec/models/hooks/web_hook_log_spec.rb index 744a6ccae8b..f812149c9be 100644 --- a/spec/models/hooks/web_hook_log_spec.rb +++ b/spec/models/hooks/web_hook_log_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' describe WebHookLog do diff --git a/spec/models/hooks/web_hook_spec.rb b/spec/models/hooks/web_hook_spec.rb index a308ac6e33a..fe08dc4f5e6 100644 --- a/spec/models/hooks/web_hook_spec.rb +++ b/spec/models/hooks/web_hook_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe WebHook do diff --git a/spec/models/identity_spec.rb b/spec/models/identity_spec.rb index e1a7a59dfd1..74ddc2d6284 100644 --- a/spec/models/identity_spec.rb +++ b/spec/models/identity_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Identity do diff --git a/spec/models/import_export_upload_spec.rb b/spec/models/import_export_upload_spec.rb index 58af84b8a08..18a714f4d98 100644 --- a/spec/models/import_export_upload_spec.rb +++ b/spec/models/import_export_upload_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe ImportExportUpload do diff --git a/spec/models/instance_configuration_spec.rb b/spec/models/instance_configuration_spec.rb index cb3d6c7cda2..dd944c43552 100644 --- a/spec/models/instance_configuration_spec.rb +++ b/spec/models/instance_configuration_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe InstanceConfiguration do diff --git a/spec/models/internal_id_spec.rb b/spec/models/internal_id_spec.rb index d32f163f05b..ff2382838ae 100644 --- a/spec/models/internal_id_spec.rb +++ b/spec/models/internal_id_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe InternalId do diff --git a/spec/models/issue/metrics_spec.rb b/spec/models/issue/metrics_spec.rb index b7291eebe64..07858fe8a70 100644 --- a/spec/models/issue/metrics_spec.rb +++ b/spec/models/issue/metrics_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Issue::Metrics do diff --git a/spec/models/issue_collection_spec.rb b/spec/models/issue_collection_spec.rb index 580a98193af..7fc635f100f 100644 --- a/spec/models/issue_collection_spec.rb +++ b/spec/models/issue_collection_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe IssueCollection do diff --git a/spec/models/issue_spec.rb b/spec/models/issue_spec.rb index 6101df2e099..892dd053e39 100644 --- a/spec/models/issue_spec.rb +++ b/spec/models/issue_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Issue do diff --git a/spec/models/key_spec.rb b/spec/models/key_spec.rb index 06d26ef89f1..a0b6eff88d5 100644 --- a/spec/models/key_spec.rb +++ b/spec/models/key_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Key, :mailer do diff --git a/spec/models/label_link_spec.rb b/spec/models/label_link_spec.rb index e2b49bc2de7..b160e72e759 100644 --- a/spec/models/label_link_spec.rb +++ b/spec/models/label_link_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe LabelLink do diff --git a/spec/models/label_priority_spec.rb b/spec/models/label_priority_spec.rb index 9dcb0f06b20..1a93468290f 100644 --- a/spec/models/label_priority_spec.rb +++ b/spec/models/label_priority_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe LabelPriority do diff --git a/spec/models/label_spec.rb b/spec/models/label_spec.rb index 3fc6c06b7fa..5174c590a10 100644 --- a/spec/models/label_spec.rb +++ b/spec/models/label_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Label do diff --git a/spec/models/legacy_diff_discussion_spec.rb b/spec/models/legacy_diff_discussion_spec.rb index dae97b69c84..49ea319fbd1 100644 --- a/spec/models/legacy_diff_discussion_spec.rb +++ b/spec/models/legacy_diff_discussion_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe LegacyDiffDiscussion do diff --git a/spec/models/lfs_download_object_spec.rb b/spec/models/lfs_download_object_spec.rb index 88838b127d2..effd8b08124 100644 --- a/spec/models/lfs_download_object_spec.rb +++ b/spec/models/lfs_download_object_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' describe LfsDownloadObject do diff --git a/spec/models/lfs_file_lock_spec.rb b/spec/models/lfs_file_lock_spec.rb index 41ca1578b94..aa64d66944b 100644 --- a/spec/models/lfs_file_lock_spec.rb +++ b/spec/models/lfs_file_lock_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' describe LfsFileLock do diff --git a/spec/models/lfs_object_spec.rb b/spec/models/lfs_object_spec.rb index 3f929710862..3d4d4b7d795 100644 --- a/spec/models/lfs_object_spec.rb +++ b/spec/models/lfs_object_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe LfsObject do diff --git a/spec/models/lfs_objects_project_spec.rb b/spec/models/lfs_objects_project_spec.rb index 0a3180f43e8..3e86ee38566 100644 --- a/spec/models/lfs_objects_project_spec.rb +++ b/spec/models/lfs_objects_project_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe LfsObjectsProject do diff --git a/spec/models/license_template_spec.rb b/spec/models/license_template_spec.rb index dd912eefac1..a0224ec2f58 100644 --- a/spec/models/license_template_spec.rb +++ b/spec/models/license_template_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe LicenseTemplate do diff --git a/spec/models/list_spec.rb b/spec/models/list_spec.rb index a51580f8292..18d4549977c 100644 --- a/spec/models/list_spec.rb +++ b/spec/models/list_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' describe List do diff --git a/spec/models/member_spec.rb b/spec/models/member_spec.rb index 188beac1582..c68c3ce2abe 100644 --- a/spec/models/member_spec.rb +++ b/spec/models/member_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Member do diff --git a/spec/models/members/group_member_spec.rb b/spec/models/members/group_member_spec.rb index bc937368cff..f227abd3dae 100644 --- a/spec/models/members/group_member_spec.rb +++ b/spec/models/members/group_member_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe GroupMember do diff --git a/spec/models/members/project_member_spec.rb b/spec/models/members/project_member_spec.rb index 36bfff2c339..497764b6825 100644 --- a/spec/models/members/project_member_spec.rb +++ b/spec/models/members/project_member_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe ProjectMember do diff --git a/spec/models/merge_request/metrics_spec.rb b/spec/models/merge_request/metrics_spec.rb index 02ff7839739..49573af0fed 100644 --- a/spec/models/merge_request/metrics_spec.rb +++ b/spec/models/merge_request/metrics_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe MergeRequest::Metrics do diff --git a/spec/models/merge_request_diff_commit_spec.rb b/spec/models/merge_request_diff_commit_spec.rb index 10487190a44..ab2aadf7d88 100644 --- a/spec/models/merge_request_diff_commit_spec.rb +++ b/spec/models/merge_request_diff_commit_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' describe MergeRequestDiffCommit do diff --git a/spec/models/merge_request_diff_file_spec.rb b/spec/models/merge_request_diff_file_spec.rb index faa47660a74..66957c24fdc 100644 --- a/spec/models/merge_request_diff_file_spec.rb +++ b/spec/models/merge_request_diff_file_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' describe MergeRequestDiffFile do diff --git a/spec/models/merge_request_diff_spec.rb b/spec/models/merge_request_diff_spec.rb index 0f00ea7e85e..a53add67066 100644 --- a/spec/models/merge_request_diff_spec.rb +++ b/spec/models/merge_request_diff_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe MergeRequestDiff do diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb index 5adeb616e84..092504cde9e 100644 --- a/spec/models/merge_request_spec.rb +++ b/spec/models/merge_request_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe MergeRequest do diff --git a/spec/models/milestone_spec.rb b/spec/models/milestone_spec.rb index 717d4ae4ec0..b82368318f2 100644 --- a/spec/models/milestone_spec.rb +++ b/spec/models/milestone_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Milestone do diff --git a/spec/models/namespace_spec.rb b/spec/models/namespace_spec.rb index aadc298ae0b..62e7dd3231b 100644 --- a/spec/models/namespace_spec.rb +++ b/spec/models/namespace_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Namespace do diff --git a/spec/models/network/graph_spec.rb b/spec/models/network/graph_spec.rb index c364dd6643b..d1a2bedf542 100644 --- a/spec/models/network/graph_spec.rb +++ b/spec/models/network/graph_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Network::Graph do diff --git a/spec/models/note_diff_file_spec.rb b/spec/models/note_diff_file_spec.rb index 591c1a89748..99eeac8d778 100644 --- a/spec/models/note_diff_file_spec.rb +++ b/spec/models/note_diff_file_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' describe NoteDiffFile do diff --git a/spec/models/note_spec.rb b/spec/models/note_spec.rb index eb6f6ff5faf..7a1ab20186a 100644 --- a/spec/models/note_spec.rb +++ b/spec/models/note_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Note do diff --git a/spec/models/notification_recipient_spec.rb b/spec/models/notification_recipient_spec.rb index 13fe47799ed..3710f2be287 100644 --- a/spec/models/notification_recipient_spec.rb +++ b/spec/models/notification_recipient_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe NotificationRecipient do diff --git a/spec/models/notification_setting_spec.rb b/spec/models/notification_setting_spec.rb index c8ab564e3bc..85128456918 100644 --- a/spec/models/notification_setting_spec.rb +++ b/spec/models/notification_setting_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' RSpec.describe NotificationSetting do diff --git a/spec/models/pages_domain_spec.rb b/spec/models/pages_domain_spec.rb index 4b85c5e8720..142ddebbbf8 100644 --- a/spec/models/pages_domain_spec.rb +++ b/spec/models/pages_domain_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe PagesDomain do diff --git a/spec/models/personal_access_token_spec.rb b/spec/models/personal_access_token_spec.rb index c82ab9c9e62..e0e1101ffc6 100644 --- a/spec/models/personal_access_token_spec.rb +++ b/spec/models/personal_access_token_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe PersonalAccessToken do diff --git a/spec/models/programming_language_spec.rb b/spec/models/programming_language_spec.rb index 99cd358f863..b327d360461 100644 --- a/spec/models/programming_language_spec.rb +++ b/spec/models/programming_language_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe ProgrammingLanguage do diff --git a/spec/models/project_authorization_spec.rb b/spec/models/project_authorization_spec.rb index c289ee0859a..6f06fe4e55a 100644 --- a/spec/models/project_authorization_spec.rb +++ b/spec/models/project_authorization_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe ProjectAuthorization do diff --git a/spec/models/project_auto_devops_spec.rb b/spec/models/project_auto_devops_spec.rb index 7ff64c76e37..8ad28ce68cc 100644 --- a/spec/models/project_auto_devops_spec.rb +++ b/spec/models/project_auto_devops_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe ProjectAutoDevops do diff --git a/spec/models/project_custom_attribute_spec.rb b/spec/models/project_custom_attribute_spec.rb index 669de5506bc..80638676b49 100644 --- a/spec/models/project_custom_attribute_spec.rb +++ b/spec/models/project_custom_attribute_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe ProjectCustomAttribute do diff --git a/spec/models/project_deploy_token_spec.rb b/spec/models/project_deploy_token_spec.rb index 9e2e40c2e8f..2a5fefc1ab0 100644 --- a/spec/models/project_deploy_token_spec.rb +++ b/spec/models/project_deploy_token_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' RSpec.describe ProjectDeployToken, type: :model do diff --git a/spec/models/project_feature_spec.rb b/spec/models/project_feature_spec.rb index fee7d65c217..50c9d5968ac 100644 --- a/spec/models/project_feature_spec.rb +++ b/spec/models/project_feature_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe ProjectFeature do diff --git a/spec/models/project_group_link_spec.rb b/spec/models/project_group_link_spec.rb index 5bea21427d4..dad5506900b 100644 --- a/spec/models/project_group_link_spec.rb +++ b/spec/models/project_group_link_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe ProjectGroupLink do diff --git a/spec/models/project_import_state_spec.rb b/spec/models/project_import_state_spec.rb index e3b2d971419..472bf8f9713 100644 --- a/spec/models/project_import_state_spec.rb +++ b/spec/models/project_import_state_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' describe ProjectImportState, type: :model do diff --git a/spec/models/project_label_spec.rb b/spec/models/project_label_spec.rb index 689d4e505e5..330aab9f856 100644 --- a/spec/models/project_label_spec.rb +++ b/spec/models/project_label_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe ProjectLabel do diff --git a/spec/models/project_services/asana_service_spec.rb b/spec/models/project_services/asana_service_spec.rb index e66109fd98f..18e839bcc64 100644 --- a/spec/models/project_services/asana_service_spec.rb +++ b/spec/models/project_services/asana_service_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe AsanaService do diff --git a/spec/models/project_services/assembla_service_spec.rb b/spec/models/project_services/assembla_service_spec.rb index 5cb6d63659e..7742e33e901 100644 --- a/spec/models/project_services/assembla_service_spec.rb +++ b/spec/models/project_services/assembla_service_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe AssemblaService do diff --git a/spec/models/project_services/bamboo_service_spec.rb b/spec/models/project_services/bamboo_service_spec.rb index b880d90d28f..08c510f09df 100644 --- a/spec/models/project_services/bamboo_service_spec.rb +++ b/spec/models/project_services/bamboo_service_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe BambooService, :use_clean_rails_memory_store_caching do diff --git a/spec/models/project_services/bugzilla_service_spec.rb b/spec/models/project_services/bugzilla_service_spec.rb index 43f7bcb1a19..6818db48fee 100644 --- a/spec/models/project_services/bugzilla_service_spec.rb +++ b/spec/models/project_services/bugzilla_service_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe BugzillaService do diff --git a/spec/models/project_services/buildkite_service_spec.rb b/spec/models/project_services/buildkite_service_spec.rb index 1615a93a4ca..091d4d8f695 100644 --- a/spec/models/project_services/buildkite_service_spec.rb +++ b/spec/models/project_services/buildkite_service_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe BuildkiteService, :use_clean_rails_memory_store_caching do diff --git a/spec/models/project_services/campfire_service_spec.rb b/spec/models/project_services/campfire_service_spec.rb index ed8347edffd..bf4c52fc7ab 100644 --- a/spec/models/project_services/campfire_service_spec.rb +++ b/spec/models/project_services/campfire_service_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe CampfireService do diff --git a/spec/models/project_services/chat_message/issue_message_spec.rb b/spec/models/project_services/chat_message/issue_message_spec.rb index f7a35fdc88a..d3adc62c38e 100644 --- a/spec/models/project_services/chat_message/issue_message_spec.rb +++ b/spec/models/project_services/chat_message/issue_message_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe ChatMessage::IssueMessage do diff --git a/spec/models/project_services/chat_message/merge_message_spec.rb b/spec/models/project_services/chat_message/merge_message_spec.rb index 7997b5bb6b9..b56eb19dd55 100644 --- a/spec/models/project_services/chat_message/merge_message_spec.rb +++ b/spec/models/project_services/chat_message/merge_message_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe ChatMessage::MergeMessage do diff --git a/spec/models/project_services/chat_message/note_message_spec.rb b/spec/models/project_services/chat_message/note_message_spec.rb index 5abbd7bec18..5e7987dc0f6 100644 --- a/spec/models/project_services/chat_message/note_message_spec.rb +++ b/spec/models/project_services/chat_message/note_message_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe ChatMessage::NoteMessage do diff --git a/spec/models/project_services/chat_message/pipeline_message_spec.rb b/spec/models/project_services/chat_message/pipeline_message_spec.rb index 0ff20400999..8f9fa310ad4 100644 --- a/spec/models/project_services/chat_message/pipeline_message_spec.rb +++ b/spec/models/project_services/chat_message/pipeline_message_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe ChatMessage::PipelineMessage do diff --git a/spec/models/project_services/chat_message/push_message_spec.rb b/spec/models/project_services/chat_message/push_message_spec.rb index 973d6bdb2a0..a89645a3ea8 100644 --- a/spec/models/project_services/chat_message/push_message_spec.rb +++ b/spec/models/project_services/chat_message/push_message_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe ChatMessage::PushMessage do diff --git a/spec/models/project_services/chat_message/wiki_page_message_spec.rb b/spec/models/project_services/chat_message/wiki_page_message_spec.rb index 7efcba9bcfd..c3db516f253 100644 --- a/spec/models/project_services/chat_message/wiki_page_message_spec.rb +++ b/spec/models/project_services/chat_message/wiki_page_message_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe ChatMessage::WikiPageMessage do diff --git a/spec/models/project_services/chat_notification_service_spec.rb b/spec/models/project_services/chat_notification_service_spec.rb index 46713df77da..6f4ddd223f6 100644 --- a/spec/models/project_services/chat_notification_service_spec.rb +++ b/spec/models/project_services/chat_notification_service_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe ChatNotificationService do diff --git a/spec/models/project_services/custom_issue_tracker_service_spec.rb b/spec/models/project_services/custom_issue_tracker_service_spec.rb index 7e1b1a4f2af..f0e7551693d 100644 --- a/spec/models/project_services/custom_issue_tracker_service_spec.rb +++ b/spec/models/project_services/custom_issue_tracker_service_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe CustomIssueTrackerService do diff --git a/spec/models/project_services/drone_ci_service_spec.rb b/spec/models/project_services/drone_ci_service_spec.rb index 26597d9b83c..22df19d943f 100644 --- a/spec/models/project_services/drone_ci_service_spec.rb +++ b/spec/models/project_services/drone_ci_service_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe DroneCiService, :use_clean_rails_memory_store_caching do diff --git a/spec/models/project_services/emails_on_push_service_spec.rb b/spec/models/project_services/emails_on_push_service_spec.rb index d9b7010e5e5..0a58eb367e3 100644 --- a/spec/models/project_services/emails_on_push_service_spec.rb +++ b/spec/models/project_services/emails_on_push_service_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe EmailsOnPushService do diff --git a/spec/models/project_services/external_wiki_service_spec.rb b/spec/models/project_services/external_wiki_service_spec.rb index 62fd97b038b..bdd8605436f 100644 --- a/spec/models/project_services/external_wiki_service_spec.rb +++ b/spec/models/project_services/external_wiki_service_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe ExternalWikiService do diff --git a/spec/models/project_services/flowdock_service_spec.rb b/spec/models/project_services/flowdock_service_spec.rb index fabcb142858..c1ebe69ee66 100644 --- a/spec/models/project_services/flowdock_service_spec.rb +++ b/spec/models/project_services/flowdock_service_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe FlowdockService do diff --git a/spec/models/project_services/gitlab_issue_tracker_service_spec.rb b/spec/models/project_services/gitlab_issue_tracker_service_spec.rb index 3237b660a16..11f96c03d46 100644 --- a/spec/models/project_services/gitlab_issue_tracker_service_spec.rb +++ b/spec/models/project_services/gitlab_issue_tracker_service_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe GitlabIssueTrackerService do diff --git a/spec/models/project_services/irker_service_spec.rb b/spec/models/project_services/irker_service_spec.rb index cb9ca76fc3f..2e1f6964692 100644 --- a/spec/models/project_services/irker_service_spec.rb +++ b/spec/models/project_services/irker_service_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' require 'socket' require 'json' diff --git a/spec/models/project_services/issue_tracker_service_spec.rb b/spec/models/project_services/issue_tracker_service_spec.rb index e6a1752576b..2fc4d69c2db 100644 --- a/spec/models/project_services/issue_tracker_service_spec.rb +++ b/spec/models/project_services/issue_tracker_service_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe IssueTrackerService do diff --git a/spec/models/project_services/jira_service_spec.rb b/spec/models/project_services/jira_service_spec.rb index 5428fcb1271..4a7eee1fbf3 100644 --- a/spec/models/project_services/jira_service_spec.rb +++ b/spec/models/project_services/jira_service_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe JiraService do diff --git a/spec/models/project_services/kubernetes_service_spec.rb b/spec/models/project_services/kubernetes_service_spec.rb index 56e587262ef..7bf093b71e7 100644 --- a/spec/models/project_services/kubernetes_service_spec.rb +++ b/spec/models/project_services/kubernetes_service_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe KubernetesService, :use_clean_rails_memory_store_caching do diff --git a/spec/models/project_services/mattermost_service_spec.rb b/spec/models/project_services/mattermost_service_spec.rb index 10c62ca55a7..6261c70f266 100644 --- a/spec/models/project_services/mattermost_service_spec.rb +++ b/spec/models/project_services/mattermost_service_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe MattermostService do diff --git a/spec/models/project_services/mattermost_slash_commands_service_spec.rb b/spec/models/project_services/mattermost_slash_commands_service_spec.rb index 1983e0cc967..87e482059f2 100644 --- a/spec/models/project_services/mattermost_slash_commands_service_spec.rb +++ b/spec/models/project_services/mattermost_slash_commands_service_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe MattermostSlashCommandsService do diff --git a/spec/models/project_services/microsoft_teams_service_spec.rb b/spec/models/project_services/microsoft_teams_service_spec.rb index 3351c6280b4..521d5265753 100644 --- a/spec/models/project_services/microsoft_teams_service_spec.rb +++ b/spec/models/project_services/microsoft_teams_service_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe MicrosoftTeamsService do diff --git a/spec/models/project_services/packagist_service_spec.rb b/spec/models/project_services/packagist_service_spec.rb index 6acee311700..53f18a1bdd9 100644 --- a/spec/models/project_services/packagist_service_spec.rb +++ b/spec/models/project_services/packagist_service_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe PackagistService do diff --git a/spec/models/project_services/pipelines_email_service_spec.rb b/spec/models/project_services/pipelines_email_service_spec.rb index 75ae2207910..ca17e7453b8 100644 --- a/spec/models/project_services/pipelines_email_service_spec.rb +++ b/spec/models/project_services/pipelines_email_service_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe PipelinesEmailService, :mailer do diff --git a/spec/models/project_services/pivotaltracker_service_spec.rb b/spec/models/project_services/pivotaltracker_service_spec.rb index f7d2372eca2..de2c8790405 100644 --- a/spec/models/project_services/pivotaltracker_service_spec.rb +++ b/spec/models/project_services/pivotaltracker_service_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe PivotaltrackerService do diff --git a/spec/models/project_services/pushover_service_spec.rb b/spec/models/project_services/pushover_service_spec.rb index 54b8c658ff6..d2a45f48705 100644 --- a/spec/models/project_services/pushover_service_spec.rb +++ b/spec/models/project_services/pushover_service_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe PushoverService do diff --git a/spec/models/project_services/redmine_service_spec.rb b/spec/models/project_services/redmine_service_spec.rb index 2ac14eab5e1..ac570ac27e1 100644 --- a/spec/models/project_services/redmine_service_spec.rb +++ b/spec/models/project_services/redmine_service_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe RedmineService do diff --git a/spec/models/project_services/slack_service_spec.rb b/spec/models/project_services/slack_service_spec.rb index 13cf4d1915e..01f580c5d01 100644 --- a/spec/models/project_services/slack_service_spec.rb +++ b/spec/models/project_services/slack_service_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe SlackService do diff --git a/spec/models/project_services/slack_slash_commands_service_spec.rb b/spec/models/project_services/slack_slash_commands_service_spec.rb index 5c4bce90ace..8c57907d064 100644 --- a/spec/models/project_services/slack_slash_commands_service_spec.rb +++ b/spec/models/project_services/slack_slash_commands_service_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe SlackSlashCommandsService do diff --git a/spec/models/project_services/teamcity_service_spec.rb b/spec/models/project_services/teamcity_service_spec.rb index 64b4efca43a..96dccae733b 100644 --- a/spec/models/project_services/teamcity_service_spec.rb +++ b/spec/models/project_services/teamcity_service_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe TeamcityService, :use_clean_rails_memory_store_caching do diff --git a/spec/models/project_services/youtrack_service_spec.rb b/spec/models/project_services/youtrack_service_spec.rb index 9524b526a46..bf9d892f66c 100644 --- a/spec/models/project_services/youtrack_service_spec.rb +++ b/spec/models/project_services/youtrack_service_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe YoutrackService do diff --git a/spec/models/project_snippet_spec.rb b/spec/models/project_snippet_spec.rb index 1b439bcfad1..e87b4f41f4d 100644 --- a/spec/models/project_snippet_spec.rb +++ b/spec/models/project_snippet_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe ProjectSnippet do diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 90dcf861849..2158d3cf3e6 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Project do diff --git a/spec/models/project_statistics_spec.rb b/spec/models/project_statistics_spec.rb index 64c39f09e33..c670b6aac56 100644 --- a/spec/models/project_statistics_spec.rb +++ b/spec/models/project_statistics_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' describe ProjectStatistics do diff --git a/spec/models/project_team_spec.rb b/spec/models/project_team_spec.rb index 3537dead5d1..a2d4fad9292 100644 --- a/spec/models/project_team_spec.rb +++ b/spec/models/project_team_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "spec_helper" describe ProjectTeam do diff --git a/spec/models/project_wiki_spec.rb b/spec/models/project_wiki_spec.rb index 7be8d67ba9e..7ea67f31534 100644 --- a/spec/models/project_wiki_spec.rb +++ b/spec/models/project_wiki_spec.rb @@ -1,4 +1,6 @@ # coding: utf-8 +# frozen_string_literal: true + require "spec_helper" describe ProjectWiki do diff --git a/spec/models/protectable_dropdown_spec.rb b/spec/models/protectable_dropdown_spec.rb index d4433a88a15..aca3df9fdde 100644 --- a/spec/models/protectable_dropdown_spec.rb +++ b/spec/models/protectable_dropdown_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe ProtectableDropdown do diff --git a/spec/models/protected_branch/merge_access_level_spec.rb b/spec/models/protected_branch/merge_access_level_spec.rb index 612e4a0e332..39dd586b157 100644 --- a/spec/models/protected_branch/merge_access_level_spec.rb +++ b/spec/models/protected_branch/merge_access_level_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe ProtectedBranch::MergeAccessLevel do diff --git a/spec/models/protected_branch/push_access_level_spec.rb b/spec/models/protected_branch/push_access_level_spec.rb index 9ccdc22fd41..628c8d29ecd 100644 --- a/spec/models/protected_branch/push_access_level_spec.rb +++ b/spec/models/protected_branch/push_access_level_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe ProtectedBranch::PushAccessLevel do diff --git a/spec/models/protected_branch_spec.rb b/spec/models/protected_branch_spec.rb index dafe7646366..267434a4148 100644 --- a/spec/models/protected_branch_spec.rb +++ b/spec/models/protected_branch_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe ProtectedBranch do diff --git a/spec/models/protected_tag_spec.rb b/spec/models/protected_tag_spec.rb index e5a0f6ec23f..79120d17d39 100644 --- a/spec/models/protected_tag_spec.rb +++ b/spec/models/protected_tag_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe ProtectedTag do diff --git a/spec/models/push_event_payload_spec.rb b/spec/models/push_event_payload_spec.rb index 69a4922b6fd..6b59ee5ee57 100644 --- a/spec/models/push_event_payload_spec.rb +++ b/spec/models/push_event_payload_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe PushEventPayload do diff --git a/spec/models/push_event_spec.rb b/spec/models/push_event_spec.rb index bfe7a30b96a..f86500f91cd 100644 --- a/spec/models/push_event_spec.rb +++ b/spec/models/push_event_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe PushEvent do diff --git a/spec/models/redirect_route_spec.rb b/spec/models/redirect_route_spec.rb index 106ae59af29..6ecb5c31c7e 100644 --- a/spec/models/redirect_route_spec.rb +++ b/spec/models/redirect_route_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' describe RedirectRoute do diff --git a/spec/models/release_spec.rb b/spec/models/release_spec.rb index 157c96c1f65..b4b32c95dee 100644 --- a/spec/models/release_spec.rb +++ b/spec/models/release_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' RSpec.describe Release do diff --git a/spec/models/remote_mirror_spec.rb b/spec/models/remote_mirror_spec.rb index c06e9a08ab4..0478094034a 100644 --- a/spec/models/remote_mirror_spec.rb +++ b/spec/models/remote_mirror_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' describe RemoteMirror, :mailer do diff --git a/spec/models/repository_language_spec.rb b/spec/models/repository_language_spec.rb index e2e4beb512f..13a4cd1e7cf 100644 --- a/spec/models/repository_language_spec.rb +++ b/spec/models/repository_language_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe RepositoryLanguage do diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index 6599b4e765a..2578208659a 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Repository do diff --git a/spec/models/route_spec.rb b/spec/models/route_spec.rb index 48799781b87..20289afbeb5 100644 --- a/spec/models/route_spec.rb +++ b/spec/models/route_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Route do diff --git a/spec/models/sent_notification_spec.rb b/spec/models/sent_notification_spec.rb index 6c35ed8f649..09be90b82ed 100644 --- a/spec/models/sent_notification_spec.rb +++ b/spec/models/sent_notification_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe SentNotification do diff --git a/spec/models/service_spec.rb b/spec/models/service_spec.rb index 25eecb3f909..2f025038bab 100644 --- a/spec/models/service_spec.rb +++ b/spec/models/service_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Service do diff --git a/spec/models/snippet_blob_spec.rb b/spec/models/snippet_blob_spec.rb index 7c71c458fcc..88441e39d45 100644 --- a/spec/models/snippet_blob_spec.rb +++ b/spec/models/snippet_blob_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe SnippetBlob do diff --git a/spec/models/snippet_spec.rb b/spec/models/snippet_spec.rb index 664dc3fa145..3524cdae3b8 100644 --- a/spec/models/snippet_spec.rb +++ b/spec/models/snippet_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Snippet do diff --git a/spec/models/spam_log_spec.rb b/spec/models/spam_log_spec.rb index 90a2caaeb88..e9ea234f75d 100644 --- a/spec/models/spam_log_spec.rb +++ b/spec/models/spam_log_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe SpamLog do diff --git a/spec/models/ssh_host_key_spec.rb b/spec/models/ssh_host_key_spec.rb index 4c677569561..a17cd8ba345 100644 --- a/spec/models/ssh_host_key_spec.rb +++ b/spec/models/ssh_host_key_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe SshHostKey do diff --git a/spec/models/subscription_spec.rb b/spec/models/subscription_spec.rb index 9e4c2620d82..41bd48810b2 100644 --- a/spec/models/subscription_spec.rb +++ b/spec/models/subscription_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Subscription do diff --git a/spec/models/system_note_metadata_spec.rb b/spec/models/system_note_metadata_spec.rb index 1e3f587e460..bcd3c03f947 100644 --- a/spec/models/system_note_metadata_spec.rb +++ b/spec/models/system_note_metadata_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe SystemNoteMetadata do diff --git a/spec/models/term_agreement_spec.rb b/spec/models/term_agreement_spec.rb index 950dfa09a6a..42a48048b67 100644 --- a/spec/models/term_agreement_spec.rb +++ b/spec/models/term_agreement_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe TermAgreement do diff --git a/spec/models/timelog_spec.rb b/spec/models/timelog_spec.rb index a0c93c531ea..9d69a0ab148 100644 --- a/spec/models/timelog_spec.rb +++ b/spec/models/timelog_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' RSpec.describe Timelog do diff --git a/spec/models/todo_spec.rb b/spec/models/todo_spec.rb index 3682e21ca40..b5bf294790a 100644 --- a/spec/models/todo_spec.rb +++ b/spec/models/todo_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Todo do diff --git a/spec/models/tree_spec.rb b/spec/models/tree_spec.rb index 6bdb62a0864..c2d5dfdf9c4 100644 --- a/spec/models/tree_spec.rb +++ b/spec/models/tree_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Tree do diff --git a/spec/models/trending_project_spec.rb b/spec/models/trending_project_spec.rb index 3b5e7ca0d39..619fc8e7d38 100644 --- a/spec/models/trending_project_spec.rb +++ b/spec/models/trending_project_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe TrendingProject do diff --git a/spec/models/upload_spec.rb b/spec/models/upload_spec.rb index 5a0df9fbbb0..02702cb2497 100644 --- a/spec/models/upload_spec.rb +++ b/spec/models/upload_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' describe Upload do diff --git a/spec/models/user_agent_detail_spec.rb b/spec/models/user_agent_detail_spec.rb index b4669f8c1c2..f191d245045 100644 --- a/spec/models/user_agent_detail_spec.rb +++ b/spec/models/user_agent_detail_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' describe UserAgentDetail do diff --git a/spec/models/user_callout_spec.rb b/spec/models/user_callout_spec.rb index d54355afe12..b87f6f03d6f 100644 --- a/spec/models/user_callout_spec.rb +++ b/spec/models/user_callout_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' describe UserCallout do diff --git a/spec/models/user_custom_attribute_spec.rb b/spec/models/user_custom_attribute_spec.rb index 37fc3cb64f0..d0981b2d771 100644 --- a/spec/models/user_custom_attribute_spec.rb +++ b/spec/models/user_custom_attribute_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe UserCustomAttribute do diff --git a/spec/models/user_interacted_project_spec.rb b/spec/models/user_interacted_project_spec.rb index cb4bb3372d4..47d919c1d12 100644 --- a/spec/models/user_interacted_project_spec.rb +++ b/spec/models/user_interacted_project_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe UserInteractedProject do diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 1be29d039a7..b7e36748fa2 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe User do diff --git a/spec/models/wiki_directory_spec.rb b/spec/models/wiki_directory_spec.rb index fb8575cfe2b..5fbcccf897e 100644 --- a/spec/models/wiki_directory_spec.rb +++ b/spec/models/wiki_directory_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' RSpec.describe WikiDirectory do diff --git a/spec/models/wiki_page_spec.rb b/spec/models/wiki_page_spec.rb index cba22b2cc4e..e68da67818a 100644 --- a/spec/models/wiki_page_spec.rb +++ b/spec/models/wiki_page_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "spec_helper" describe WikiPage do -- cgit v1.2.1 From 3a1a12b3833e28323347b1021a845a4d85beb563 Mon Sep 17 00:00:00 2001 From: Thong Kuah Date: Mon, 1 Apr 2019 11:55:08 +1300 Subject: Fix cert_manager_spec to not modify String Also break up long string to be readable --- .../clusters/applications/cert_manager_spec.rb | 27 +++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/spec/models/clusters/applications/cert_manager_spec.rb b/spec/models/clusters/applications/cert_manager_spec.rb index fefeb8fd75f..af7eadfc74c 100644 --- a/spec/models/clusters/applications/cert_manager_spec.rb +++ b/spec/models/clusters/applications/cert_manager_spec.rb @@ -11,7 +11,27 @@ describe Clusters::Applications::CertManager do include_examples 'cluster application initial status specs' describe '#install_command' do - let(:cluster_issuer_file) { { "cluster_issuer.yaml": "---\napiVersion: certmanager.k8s.io/v1alpha1\nkind: ClusterIssuer\nmetadata:\n name: letsencrypt-prod\nspec:\n acme:\n server: https://acme-v02.api.letsencrypt.org/directory\n email: admin@example.com\n privateKeySecretRef:\n name: letsencrypt-prod\n http01: {}\n" } } + let(:cert_email) { 'admin@example.com' } + + let(:cluster_issuer_file) do + file_contents = <<~EOF + --- + apiVersion: certmanager.k8s.io/v1alpha1 + kind: ClusterIssuer + metadata: + name: letsencrypt-prod + spec: + acme: + server: https://acme-v02.api.letsencrypt.org/directory + email: #{cert_email} + privateKeySecretRef: + name: letsencrypt-prod + http01: {} + EOF + + { "cluster_issuer.yaml": file_contents } + end + subject { cert_manager.install_command } it { is_expected.to be_an_instance_of(Gitlab::Kubernetes::Helm::InstallCommand) } @@ -26,9 +46,10 @@ describe Clusters::Applications::CertManager do end context 'for a specific user' do + let(:cert_email) { 'abc@xyz.com' } + before do - cert_manager.email = 'abc@xyz.com' - cluster_issuer_file[:'cluster_issuer.yaml'].gsub! 'admin@example.com', 'abc@xyz.com' + cert_manager.email = cert_email end it 'should use his/her email to register issuer with certificate provider' do -- cgit v1.2.1 From 5cd63ace04deee2e6d7c13694bfd8dc46d0edaf4 Mon Sep 17 00:00:00 2001 From: Thong Kuah Date: Mon, 1 Apr 2019 12:07:50 +1300 Subject: Don't modify String in instance_configuration_spec --- spec/models/instance_configuration_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/models/instance_configuration_spec.rb b/spec/models/instance_configuration_spec.rb index dd944c43552..e65f97df3c3 100644 --- a/spec/models/instance_configuration_spec.rb +++ b/spec/models/instance_configuration_spec.rb @@ -32,8 +32,8 @@ describe InstanceConfiguration do end def stub_pub_file(exist: true) - path = 'spec/fixtures/ssh_host_example_key.pub' - path << 'random' unless exist + path = exist ? 'spec/fixtures/ssh_host_example_key.pub' : 'spec/fixtures/ssh_host_example_key.pub.random' + allow(subject).to receive(:ssh_algorithm_file).and_return(Rails.root.join(path)) end end -- cgit v1.2.1 From 32a1277d28a87f92a87218a60c32174f4c7279a9 Mon Sep 17 00:00:00 2001 From: Thong Kuah Date: Mon, 1 Apr 2019 13:25:54 +1300 Subject: Fix license_template_spec to not modify String Revamp how spec verifies proc#call called only once --- spec/models/license_template_spec.rb | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/spec/models/license_template_spec.rb b/spec/models/license_template_spec.rb index a0224ec2f58..7037277e580 100644 --- a/spec/models/license_template_spec.rb +++ b/spec/models/license_template_spec.rb @@ -5,14 +5,15 @@ require 'spec_helper' describe LicenseTemplate do describe '#content' do it 'calls a proc exactly once if provided' do - lazy = build_template(-> { 'bar' }) - content = lazy.content + content_proc = -> { 'bar' } + expect(content_proc).to receive(:call).once.and_call_original - expect(content).to eq('bar') - expect(content.object_id).to eq(lazy.content.object_id) + lazy = build_template(content_proc) - content.replace('foo') - expect(lazy.content).to eq('foo') + expect(lazy.content).to eq('bar') + + # Subsequent calls should not call proc again + expect(lazy.content).to eq('bar') end it 'returns a string if provided' do -- cgit v1.2.1 From ab2047d0e74bbb168a96a8d333fa562ec021cff9 Mon Sep 17 00:00:00 2001 From: Thong Kuah Date: Mon, 1 Apr 2019 13:26:31 +1300 Subject: Don't use frozen_string_literal for now While we debug why this is failing --- spec/models/ci/build_trace_chunk_spec.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/spec/models/ci/build_trace_chunk_spec.rb b/spec/models/ci/build_trace_chunk_spec.rb index f7ee4614e02..59db347582b 100644 --- a/spec/models/ci/build_trace_chunk_spec.rb +++ b/spec/models/ci/build_trace_chunk_spec.rb @@ -1,5 +1,3 @@ -# frozen_string_literal: true - require 'spec_helper' describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do -- cgit v1.2.1 From 22cb8262f37a100dd45f60c67b261a9b6de06c4b Mon Sep 17 00:00:00 2001 From: Thong Kuah Date: Mon, 1 Apr 2019 15:26:02 +1300 Subject: Fix typo in QA auto_devops spec --- .../7_configure/auto_devops/create_project_with_auto_devops_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qa/qa/specs/features/browser_ui/7_configure/auto_devops/create_project_with_auto_devops_spec.rb b/qa/qa/specs/features/browser_ui/7_configure/auto_devops/create_project_with_auto_devops_spec.rb index e9e0b69d7b8..bb1f775da75 100644 --- a/qa/qa/specs/features/browser_ui/7_configure/auto_devops/create_project_with_auto_devops_spec.rb +++ b/qa/qa/specs/features/browser_ui/7_configure/auto_devops/create_project_with_auto_devops_spec.rb @@ -94,7 +94,7 @@ module QA Page::Project::Menu.perform(&:go_to_operations_environments) Page::Project::Operations::Environments::Index.perform do |index| - index.click_environment_linkindex.go_to_environment('production') + index.click_environment_link('production') end Page::Project::Operations::Environments::Show.perform do |show| show.view_deployment do -- cgit v1.2.1 From 90fc362c2d751d1173364c583b1242823128e34d Mon Sep 17 00:00:00 2001 From: Ray Paik Date: Mon, 1 Apr 2019 04:07:04 +0000 Subject: Add details for the first proof reader request --- doc/development/i18n/proofreader.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/development/i18n/proofreader.md b/doc/development/i18n/proofreader.md index dd338f6f67d..131e3edf35e 100644 --- a/doc/development/i18n/proofreader.md +++ b/doc/development/i18n/proofreader.md @@ -126,5 +126,8 @@ are very appreciative of the work done by translators and proofreaders! your previous translations by [GitLab team members](https://about.gitlab.com/team/) or [Core team members](https://about.gitlab.com/core-team/) who are fluent in the language or current proofreaders. + - When a request is made for the first proofreader for a lanuguage and there are no [GitLab team members](https://about.gitlab.com/team/) + or [Core team members](https://about.gitlab.com/core-team/) who speak the language, we will request links to previous translation work in other communities or projects. + [proofreader-src]: https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/development/i18n/proofreader.md -- cgit v1.2.1 From 8686e01250824e475dc9412c399c44100878a71e Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Sun, 31 Mar 2019 22:00:19 -0700 Subject: Avoid excessive recursive calls with Rugged TreeEntries The Rugged implementation was recursively scanning the repository to create `flat_path` because the post-process step was being called from with a loop. For large repositories, this was significantly slowing things down. Break the call to `rugged_populate_flat_path` out of this loop to make this work efficiently. Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/59759 --- changelogs/unreleased/sh-fix-rugged-tree-entries.yml | 5 +++++ lib/gitlab/git/rugged_impl/tree.rb | 20 ++++++++++++-------- spec/lib/gitlab/git/tree_spec.rb | 2 +- 3 files changed, 18 insertions(+), 9 deletions(-) create mode 100644 changelogs/unreleased/sh-fix-rugged-tree-entries.yml diff --git a/changelogs/unreleased/sh-fix-rugged-tree-entries.yml b/changelogs/unreleased/sh-fix-rugged-tree-entries.yml new file mode 100644 index 00000000000..97b27678905 --- /dev/null +++ b/changelogs/unreleased/sh-fix-rugged-tree-entries.yml @@ -0,0 +1,5 @@ +--- +title: Avoid excessive recursive calls with Rugged TreeEntries +merge_request: 26813 +author: +type: fixed diff --git a/lib/gitlab/git/rugged_impl/tree.rb b/lib/gitlab/git/rugged_impl/tree.rb index 0ebfd496695..bb13d114d46 100644 --- a/lib/gitlab/git/rugged_impl/tree.rb +++ b/lib/gitlab/git/rugged_impl/tree.rb @@ -15,12 +15,23 @@ module Gitlab override :tree_entries def tree_entries(repository, sha, path, recursive) if Feature.enabled?(:rugged_tree_entries) - tree_entries_from_rugged(repository, sha, path, recursive) + tree_entries_with_flat_path_from_rugged(repository, sha, path, recursive) else super end end + def tree_entries_with_flat_path_from_rugged(repository, sha, path, recursive) + tree_entries_from_rugged(repository, sha, path, recursive).tap do |entries| + # This was an optimization to reduce N+1 queries for Gitaly + # (https://gitlab.com/gitlab-org/gitaly/issues/530). It + # used to be done lazily in the view via + # TreeHelper#flatten_tree, so it's possible there's a + # performance impact by loading this eagerly. + rugged_populate_flat_path(repository, sha, path, entries) + end + end + def tree_entries_from_rugged(repository, sha, path, recursive) current_path_entries = get_tree_entries_from_rugged(repository, sha, path) ordered_entries = [] @@ -32,13 +43,6 @@ module Gitlab ordered_entries.concat(tree_entries_from_rugged(repository, sha, entry.path, true)) end end - - # This was an optimization to reduce N+1 queries for Gitaly - # (https://gitlab.com/gitlab-org/gitaly/issues/530). It - # used to be done lazily in the view via - # TreeHelper#flatten_tree, so it's possible there's a - # performance impact by loading this eagerly. - rugged_populate_flat_path(repository, sha, path, ordered_entries) end def rugged_populate_flat_path(repository, sha, path, entries) diff --git a/spec/lib/gitlab/git/tree_spec.rb b/spec/lib/gitlab/git/tree_spec.rb index 60060c41616..7ad3cde97f8 100644 --- a/spec/lib/gitlab/git/tree_spec.rb +++ b/spec/lib/gitlab/git/tree_spec.rb @@ -19,7 +19,7 @@ describe Gitlab::Git::Tree, :seed_helper do it 'returns a list of tree objects' do entries = described_class.where(repository, SeedRepo::Commit::ID, 'files', true) - expect(entries.count).to be > 10 + expect(entries.count).to be >= 5 expect(entries).to all(be_a(Gitlab::Git::Tree)) end -- cgit v1.2.1 From a7d4824ded0c5ae6a155d7bdc87a1ba71eb3df5c Mon Sep 17 00:00:00 2001 From: Shinya Maeda Date: Fri, 29 Mar 2019 14:56:40 +0700 Subject: Check mergeability in merge to ref service and add spec Add changelog ok ok --- app/models/merge_request.rb | 3 +- .../merge_requests/merge_to_ref_service.rb | 4 +-- .../check-mergeability-in-merge-to-ref-service.yml | 5 ++++ spec/models/merge_request_spec.rb | 32 ++++++++++++++++++++++ .../merge_requests/merge_to_ref_service_spec.rb | 20 ++++++++------ 5 files changed, 50 insertions(+), 14 deletions(-) create mode 100644 changelogs/unreleased/check-mergeability-in-merge-to-ref-service.yml diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index b52c480a487..4b1b3c365a5 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -807,8 +807,7 @@ class MergeRequest < ApplicationRecord end def mergeable_to_ref? - return false if merged? - return false if broken? + return false unless mergeable_state?(skip_ci_check: true, skip_discussions_check: true) # Given the `merge_ref_path` will have the same # state the `target_branch` would have. Ideally diff --git a/app/services/merge_requests/merge_to_ref_service.rb b/app/services/merge_requests/merge_to_ref_service.rb index 69cc441f1bb..87147d90c32 100644 --- a/app/services/merge_requests/merge_to_ref_service.rb +++ b/app/services/merge_requests/merge_to_ref_service.rb @@ -41,9 +41,7 @@ module MergeRequests super error = - if Feature.disabled?(:merge_to_tmp_merge_ref_path, project) - 'Feature is not enabled' - elsif !hooks_validation_pass?(merge_request) + if !hooks_validation_pass?(merge_request) hooks_validation_error(merge_request) elsif !@merge_request.mergeable_to_ref? "Merge request is not mergeable to #{target_ref}" diff --git a/changelogs/unreleased/check-mergeability-in-merge-to-ref-service.yml b/changelogs/unreleased/check-mergeability-in-merge-to-ref-service.yml new file mode 100644 index 00000000000..9f615bbb54a --- /dev/null +++ b/changelogs/unreleased/check-mergeability-in-merge-to-ref-service.yml @@ -0,0 +1,5 @@ +--- +title: Check mergeability in MergeToRefService +merge_request: 26757 +author: +type: changed diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb index 5adeb616e84..138036ab3c2 100644 --- a/spec/models/merge_request_spec.rb +++ b/spec/models/merge_request_spec.rb @@ -3081,6 +3081,38 @@ describe MergeRequest do end end + describe '#mergeable_to_ref?' do + it 'returns true when merge request is mergeable' do + subject = create(:merge_request) + + expect(subject.mergeable_to_ref?).to be(true) + end + + it 'returns false when merge request is already merged' do + subject = create(:merge_request, :merged) + + expect(subject.mergeable_to_ref?).to be(false) + end + + it 'returns false when merge request is closed' do + subject = create(:merge_request, :closed) + + expect(subject.mergeable_to_ref?).to be(false) + end + + it 'returns false when merge request is work in progress' do + subject = create(:merge_request, title: 'WIP: The feature') + + expect(subject.mergeable_to_ref?).to be(false) + end + + it 'returns false when merge request has no commits' do + subject = create(:merge_request, source_branch: 'empty-branch', target_branch: 'master') + + expect(subject.mergeable_to_ref?).to be(false) + end + end + describe '#merge_participants' do it 'contains author' do expect(subject.merge_participants).to eq([subject.author]) diff --git a/spec/services/merge_requests/merge_to_ref_service_spec.rb b/spec/services/merge_requests/merge_to_ref_service_spec.rb index fabca8f6b4a..a3b48abae26 100644 --- a/spec/services/merge_requests/merge_to_ref_service_spec.rb +++ b/spec/services/merge_requests/merge_to_ref_service_spec.rb @@ -40,15 +40,6 @@ describe MergeRequests::MergeToRefService do end shared_examples_for 'successfully evaluates pre-condition checks' do - it 'returns error when feature is disabled' do - stub_feature_flags(merge_to_tmp_merge_ref_path: false) - - result = service.execute(merge_request) - - expect(result[:status]).to eq(:error) - expect(result[:message]).to eq('Feature is not enabled') - end - it 'returns an error when the failing to process the merge' do allow(project.repository).to receive(:merge_to_ref).and_return(nil) @@ -180,6 +171,17 @@ describe MergeRequests::MergeToRefService do it { expect(todo).not_to be_done } end + context 'when merge request is WIP state' do + it 'fails to merge' do + merge_request = create(:merge_request, title: 'WIP: The feature') + + result = service.execute(merge_request) + + expect(result[:status]).to eq(:error) + expect(result[:message]).to eq("Merge request is not mergeable to #{merge_request.merge_ref_path}") + end + end + it 'returns error when user has no authorization to admin the merge request' do unauthorized_user = create(:user) project.add_reporter(unauthorized_user) -- cgit v1.2.1 From 947acd8142ed61418a88fe333aad2f4d4f99954f Mon Sep 17 00:00:00 2001 From: jk2K <191983-jk2K@users.noreply.gitlab.com> Date: Mon, 1 Apr 2019 07:53:18 +0000 Subject: docs: add gitlab version for list jobs of a runner --- doc/api/runners.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/api/runners.md b/doc/api/runners.md index 7d7215e6b80..0b7ef46888c 100644 --- a/doc/api/runners.md +++ b/doc/api/runners.md @@ -256,6 +256,8 @@ curl --request DELETE --header "PRIVATE-TOKEN: " "https://git ## List runner's jobs +> [Introduced](https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/15432) in GitLab 10.3. + List jobs that are being processed or were processed by specified Runner. ``` -- cgit v1.2.1 From e756dca0c5f32c2507fc2ef23c89c6e36e0e1b4c Mon Sep 17 00:00:00 2001 From: Bob Van Landuyt Date: Mon, 1 Apr 2019 10:55:33 +0200 Subject: Extra permissions in Project & Issue GraphQL Allow extra permissions for the `Types::ProjectType` and `Types:IssueType` GraphQL types. As we'll be adding more permissions in CE. Now this spec only validates if all the expected permissions are present, but it will not fail if there are more. --- spec/graphql/types/permission_types/issue_spec.rb | 4 +++- spec/graphql/types/permission_types/project_spec.rb | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/spec/graphql/types/permission_types/issue_spec.rb b/spec/graphql/types/permission_types/issue_spec.rb index c3f84629aa2..f0fbeda202f 100644 --- a/spec/graphql/types/permission_types/issue_spec.rb +++ b/spec/graphql/types/permission_types/issue_spec.rb @@ -7,6 +7,8 @@ describe Types::PermissionTypes::Issue do :create_note, :reopen_issue ] - expect(described_class).to have_graphql_fields(expected_permissions) + expected_permissions.each do |permission| + expect(described_class).to have_graphql_field(permission) + end end end diff --git a/spec/graphql/types/permission_types/project_spec.rb b/spec/graphql/types/permission_types/project_spec.rb index 4288412eda3..4974995b587 100644 --- a/spec/graphql/types/permission_types/project_spec.rb +++ b/spec/graphql/types/permission_types/project_spec.rb @@ -13,6 +13,8 @@ describe Types::PermissionTypes::Project do :update_wiki, :destroy_wiki, :create_pages, :destroy_pages, :read_pages_content ] - expect(described_class).to have_graphql_fields(expected_permissions) + expected_permissions.each do |permission| + expect(described_class).to have_graphql_field(permission) + end end end -- cgit v1.2.1 From 83fb62d493013973cb90b611d7c741d612ab6caf Mon Sep 17 00:00:00 2001 From: Elias Werberich Date: Mon, 1 Apr 2019 11:07:22 +0200 Subject: Don't sanitize project names on project members page --- app/views/projects/project_members/_groups.html.haml | 2 +- app/views/projects/project_members/_team.html.haml | 2 +- app/views/projects/project_members/index.html.haml | 2 +- changelogs/unreleased/58751-fix-project-name-members-page.yml | 5 +++++ 4 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 changelogs/unreleased/58751-fix-project-name-members-page.yml diff --git a/app/views/projects/project_members/_groups.html.haml b/app/views/projects/project_members/_groups.html.haml index b5d397e3065..00321014f91 100644 --- a/app/views/projects/project_members/_groups.html.haml +++ b/app/views/projects/project_members/_groups.html.haml @@ -1,6 +1,6 @@ .card.project-members-groups .card-header - = _("Groups with access to %{project_name}").html_safe % { project_name: sanitize_project_name(@project.name) } + = _("Groups with access to %{project_name}").html_safe % { project_name: sanitize(@project.name, tags: []) } %span.badge.badge-pill= group_links.size %ul.content-list.members-list = render partial: 'shared/members/group', collection: group_links, as: :group_link diff --git a/app/views/projects/project_members/_team.html.haml b/app/views/projects/project_members/_team.html.haml index e0dd386fc5d..f220299ec30 100644 --- a/app/views/projects/project_members/_team.html.haml +++ b/app/views/projects/project_members/_team.html.haml @@ -4,7 +4,7 @@ .card .card-header.flex-project-members-panel %span.flex-project-title - = _("Members of %{project_name}").html_safe % { project_name: sanitize_project_name(project.name) } + = _("Members of %{project_name}").html_safe % { project_name: sanitize(project.name, tags: []) } %span.badge.badge-pill= members.total_count = form_tag project_project_members_path(project), method: :get, class: 'form-inline member-search-form flex-project-members-form' do .form-group diff --git a/app/views/projects/project_members/index.html.haml b/app/views/projects/project_members/index.html.haml index 242ff91f539..8373903443e 100644 --- a/app/views/projects/project_members/index.html.haml +++ b/app/views/projects/project_members/index.html.haml @@ -6,7 +6,7 @@ = _("Project members") - if can?(current_user, :admin_project_member, @project) %p - = _("You can invite a new member to %{project_name} or invite another group.").html_safe % { project_name: sanitize_project_name(@project.name) } + = _("You can invite a new member to %{project_name} or invite another group.").html_safe % { project_name: sanitize(@project.name, tags: []) } - else %p = _("Members can be added by project Maintainers or Owners").html_safe diff --git a/changelogs/unreleased/58751-fix-project-name-members-page.yml b/changelogs/unreleased/58751-fix-project-name-members-page.yml new file mode 100644 index 00000000000..a295afc5c48 --- /dev/null +++ b/changelogs/unreleased/58751-fix-project-name-members-page.yml @@ -0,0 +1,5 @@ +--- +title: "Fix unwanted character replacement on project members page caused by usage of sanitize function" +merge_request: 25946 +author: Elias Werberich +type: fixed -- cgit v1.2.1 From 904af0164ebf93e166289771eca1701d2949f46f Mon Sep 17 00:00:00 2001 From: Filipa Lacerda Date: Fri, 29 Mar 2019 12:43:06 +0000 Subject: Replaces md-area with position-relative for markdown areas --- app/assets/javascripts/vue_shared/components/markdown/field.vue | 2 +- app/assets/stylesheets/framework/markdown_area.scss | 4 ---- app/views/projects/_md_preview.html.haml | 2 +- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/vue_shared/components/markdown/field.vue b/app/assets/javascripts/vue_shared/components/markdown/field.vue index a4b3131c8e4..eccf73e227c 100644 --- a/app/assets/javascripts/vue_shared/components/markdown/field.vue +++ b/app/assets/javascripts/vue_shared/components/markdown/field.vue @@ -189,7 +189,7 @@ export default {
Date: Mon, 25 Mar 2019 09:25:50 +0000 Subject: Bump Kubectl and Helm in Auto-DevOps.gitlab-ci.yml --- changelogs/unreleased/kube_helm_auto_devops_213.yml | 5 +++++ lib/gitlab/ci/templates/Auto-DevOps.gitlab-ci.yml | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 changelogs/unreleased/kube_helm_auto_devops_213.yml diff --git a/changelogs/unreleased/kube_helm_auto_devops_213.yml b/changelogs/unreleased/kube_helm_auto_devops_213.yml new file mode 100644 index 00000000000..3c718d4a22c --- /dev/null +++ b/changelogs/unreleased/kube_helm_auto_devops_213.yml @@ -0,0 +1,5 @@ +--- +title: Bump kubectl to 1.11.9 and Helm to 2.13.1 in Auto-DevOps.gitlab-ci.yml +merge_request: 26534 +author: +type: other diff --git a/lib/gitlab/ci/templates/Auto-DevOps.gitlab-ci.yml b/lib/gitlab/ci/templates/Auto-DevOps.gitlab-ci.yml index 78872b3bbe3..f5458093fec 100644 --- a/lib/gitlab/ci/templates/Auto-DevOps.gitlab-ci.yml +++ b/lib/gitlab/ci/templates/Auto-DevOps.gitlab-ci.yml @@ -50,8 +50,8 @@ variables: POSTGRES_DB: $CI_ENVIRONMENT_SLUG POSTGRES_VERSION: 9.6.2 - KUBERNETES_VERSION: 1.11.7 - HELM_VERSION: 2.12.3 + KUBERNETES_VERSION: 1.11.9 + HELM_VERSION: 2.13.1 DOCKER_DRIVER: overlay2 -- cgit v1.2.1 From b33e45c77fc307208196ffebbffb279f3dc3791a Mon Sep 17 00:00:00 2001 From: Rick Heil Date: Mon, 1 Apr 2019 11:03:03 +0000 Subject: Update lfs_administration.md to add new line in order to have table draw properly --- doc/workflow/lfs/lfs_administration.md | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/workflow/lfs/lfs_administration.md b/doc/workflow/lfs/lfs_administration.md index 5aa72edac14..6d941135bf2 100644 --- a/doc/workflow/lfs/lfs_administration.md +++ b/doc/workflow/lfs/lfs_administration.md @@ -109,6 +109,7 @@ Here is a configuration example with GCS. _NOTE: The service account must have permission to access the bucket. [See more](https://cloud.google.com/storage/docs/authentication)_ Here is a configuration example with Rackspace Cloud Files. + | Setting | Description | example | |---------|-------------|---------| | `provider` | The provider name | `Rackspace` | -- cgit v1.2.1 From 93c649db54d4c91e5392322a1ee99d52b6ef1503 Mon Sep 17 00:00:00 2001 From: Walmyr Lima Date: Mon, 1 Apr 2019 13:32:55 +0200 Subject: Document click_ vs. go_to_ standard for e2e tests Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/59645. --- qa/README.md | 1 + qa/STYLE_GUIDE.md | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 qa/STYLE_GUIDE.md diff --git a/qa/README.md b/qa/README.md index 7d66f7d5abc..9517d4f42b4 100644 --- a/qa/README.md +++ b/qa/README.md @@ -48,6 +48,7 @@ will need to [modify your GDK setup](https://gitlab.com/gitlab-org/gitlab-qa/blo ### Writing tests 1. [Using page objects](qa/page/README.md) +2. [Style guide](STYLE_GUIDE.md) ### Running specific tests diff --git a/qa/STYLE_GUIDE.md b/qa/STYLE_GUIDE.md new file mode 100644 index 00000000000..f85e7492409 --- /dev/null +++ b/qa/STYLE_GUIDE.md @@ -0,0 +1,46 @@ +# Style guide for writing GUI tests + +This document describes the conventions used at GitLab for writing GUI tests using the GitLab QA project. + +## `click_` versus `go_to_` + +### When to use `click_`? + +When clicking in a single link to navigate, use `click_`. + +E.g.: + +```ruby +def click_ci_cd_pipelines + within_sidebar do + click_element :link_pipelines + end +end +``` + +From a testing perspective, if we want to check that clicking a link, or a button (a single interaction) is working as intended, we would want the test to read as: + +- Click a certain element +- Verify the action took place + +### When to use `go_to_`? + +When interacting with multiple elements to go to a page, use `go_to_`. + +E.g.: + +```ruby +def go_to_operations_environments + hover_operations do + within_submenu do + click_element(:operations_environments_link) + end + end +end +``` + +`go_to_` fits the definition of interacting with multiple elements very well given it's more of a meta-navigation action that includes multiple interactions. + +Notice that in the above example, before clicking the `:operations_environments_link`, another element is hovered over. + +> We can create these methods as helpers to abstrac multi-step navigation. \ No newline at end of file -- cgit v1.2.1 From 5aade0b01c858308fdf8a9ca3f88ac5110dfa7fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Cunha?= Date: Mon, 1 Apr 2019 13:32:20 +0000 Subject: Dry up and remove responsibilities - Dry create_service.rb and update_service.rb duplicated code - Remove known list of applications responsibility from services - Refactor the complex builders->builder call from base_service.rb --- app/models/clusters/cluster.rb | 12 ++++++----- app/services/clusters/applications/base_service.rb | 24 ++++++++++++++++++---- .../clusters/applications/create_service.rb | 22 +++----------------- .../clusters/applications/update_service.rb | 21 ++----------------- 4 files changed, 32 insertions(+), 47 deletions(-) diff --git a/app/models/clusters/cluster.rb b/app/models/clusters/cluster.rb index 7a10b07ee9d..4262c03498d 100644 --- a/app/models/clusters/cluster.rb +++ b/app/models/clusters/cluster.rb @@ -8,15 +8,17 @@ module Clusters self.table_name = 'clusters' + PROJECT_ONLY_APPLICATIONS = { + Applications::Jupyter.application_name => Applications::Jupyter, + Applications::Knative.application_name => Applications::Knative, + Applications::Prometheus.application_name => Applications::Prometheus + }.freeze APPLICATIONS = { Applications::Helm.application_name => Applications::Helm, Applications::Ingress.application_name => Applications::Ingress, Applications::CertManager.application_name => Applications::CertManager, - Applications::Prometheus.application_name => Applications::Prometheus, - Applications::Runner.application_name => Applications::Runner, - Applications::Jupyter.application_name => Applications::Jupyter, - Applications::Knative.application_name => Applications::Knative - }.freeze + Applications::Runner.application_name => Applications::Runner + }.merge(PROJECT_ONLY_APPLICATIONS).freeze DEFAULT_ENVIRONMENT = '*'.freeze KUBE_INGRESS_BASE_DOMAIN = 'KUBE_INGRESS_BASE_DOMAIN'.freeze diff --git a/app/services/clusters/applications/base_service.rb b/app/services/clusters/applications/base_service.rb index cbd1cf03ae1..14a45437287 100644 --- a/app/services/clusters/applications/base_service.rb +++ b/app/services/clusters/applications/base_service.rb @@ -41,7 +41,7 @@ module Clusters raise NotImplementedError end - def builders + def builder raise NotImplementedError end @@ -50,11 +50,27 @@ module Clusters end def instantiate_application - builder.call(@cluster) || raise(InvalidApplicationError, "invalid application: #{application_name}") + raise_invalid_application_error if invalid_application? + + builder || raise(InvalidApplicationError, "invalid application: #{application_name}") end - def builder - builders[application_name] || raise(InvalidApplicationError, "invalid application: #{application_name}") + def raise_invalid_application_error + raise(InvalidApplicationError, "invalid application: #{application_name}") + end + + def invalid_application? + unknown_application? || (!cluster.project_type? && project_only_application?) + end + + def unknown_application? + Clusters::Cluster::APPLICATIONS.keys.exclude?(application_name) + end + + # These applications will need extra configuration to enable them to work + # with groups of projects + def project_only_application? + Clusters::Cluster::PROJECT_ONLY_APPLICATIONS.include?(application_name) end def application_name diff --git a/app/services/clusters/applications/create_service.rb b/app/services/clusters/applications/create_service.rb index c6f729aaa8a..ae36da7b3dd 100644 --- a/app/services/clusters/applications/create_service.rb +++ b/app/services/clusters/applications/create_service.rb @@ -9,25 +9,9 @@ module Clusters application.updateable? ? ClusterUpgradeAppWorker : ClusterInstallAppWorker end - def builders - { - "helm" => -> (cluster) { cluster.application_helm || cluster.build_application_helm }, - "ingress" => -> (cluster) { cluster.application_ingress || cluster.build_application_ingress }, - "cert_manager" => -> (cluster) { cluster.application_cert_manager || cluster.build_application_cert_manager }, - "runner" => -> (cluster) { cluster.application_runner || cluster.build_application_runner } - }.tap do |hash| - hash.merge!(project_builders) if cluster.project_type? - end - end - - # These applications will need extra configuration to enable them to work - # with groups of projects - def project_builders - { - "prometheus" => -> (cluster) { cluster.application_prometheus || cluster.build_application_prometheus }, - "jupyter" => -> (cluster) { cluster.application_jupyter || cluster.build_application_jupyter }, - "knative" => -> (cluster) { cluster.application_knative || cluster.build_application_knative } - } + def builder + cluster.method("application_#{application_name}").call || + cluster.method("build_application_#{application_name}").call end end end diff --git a/app/services/clusters/applications/update_service.rb b/app/services/clusters/applications/update_service.rb index a9d4e609992..5071c31839c 100644 --- a/app/services/clusters/applications/update_service.rb +++ b/app/services/clusters/applications/update_service.rb @@ -9,25 +9,8 @@ module Clusters ClusterPatchAppWorker end - def builders - { - "helm" => -> (cluster) { cluster.application_helm }, - "ingress" => -> (cluster) { cluster.application_ingress }, - "cert_manager" => -> (cluster) { cluster.application_cert_manager } - }.tap do |hash| - hash.merge!(project_builders) if cluster.project_type? - end - end - - # These applications will need extra configuration to enable them to work - # with groups of projects - def project_builders - { - "prometheus" => -> (cluster) { cluster.application_prometheus }, - "runner" => -> (cluster) { cluster.application_runner }, - "jupyter" => -> (cluster) { cluster.application_jupyter }, - "knative" => -> (cluster) { cluster.application_knative } - } + def builder + cluster.method("application_#{application_name}").call end end end -- cgit v1.2.1 From 374d4f17442f9d1f159215e3e4887797620f77de Mon Sep 17 00:00:00 2001 From: Bob Van Landuyt Date: Mon, 1 Apr 2019 12:49:18 +0200 Subject: Refactor pipeline_spec This makes sure we load the page as part of the spec, instead of a before block. So we could still perform setup inside shared examples, avoiding failures caught by data being wrongly cached when loading the page multiple times during a single spec --- spec/features/projects/pipelines/pipeline_spec.rb | 38 +++++++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/spec/features/projects/pipelines/pipeline_spec.rb b/spec/features/projects/pipelines/pipeline_spec.rb index 9fdf78baa1e..b197557039d 100644 --- a/spec/features/projects/pipelines/pipeline_spec.rb +++ b/spec/features/projects/pipelines/pipeline_spec.rb @@ -59,11 +59,11 @@ describe 'Pipeline', :js do let(:project) { create(:project, :repository) } let(:pipeline) { create(:ci_pipeline, project: project, ref: 'master', sha: project.commit.id, user: user) } - before do - visit project_pipeline_path(project, pipeline) - end + subject(:visit_pipeline) { visit project_pipeline_path(project, pipeline) } it 'shows the pipeline graph' do + visit_pipeline + expect(page).to have_selector('.pipeline-visualization') expect(page).to have_content('Build') expect(page).to have_content('Test') @@ -73,14 +73,20 @@ describe 'Pipeline', :js do end it 'shows Pipeline tab pane as active' do + visit_pipeline + expect(page).to have_css('#js-tab-pipeline.active') end it 'shows link to the pipeline ref' do + visit_pipeline + expect(page).to have_link(pipeline.ref) end it 'shows the pipeline information' do + visit_pipeline + within '.pipeline-info' do expect(page).to have_content("#{pipeline.statuses.count} jobs " \ "for #{pipeline.ref} ") @@ -96,6 +102,10 @@ describe 'Pipeline', :js do end describe 'pipeline graph' do + before do + visit_pipeline + end + context 'when pipeline has running builds' do it 'shows a running icon and a cancel action for the running build' do page.within('#ci-badge-deploy') do @@ -227,6 +237,10 @@ describe 'Pipeline', :js do end context 'page tabs' do + before do + visit_pipeline + end + it 'shows Pipeline, Jobs and Failed Jobs tabs with link' do expect(page).to have_link('Pipeline') expect(page).to have_link('Jobs') @@ -253,6 +267,10 @@ describe 'Pipeline', :js do end context 'retrying jobs' do + before do + visit_pipeline + end + it { expect(page).not_to have_content('retried') } context 'when retrying' do @@ -265,6 +283,10 @@ describe 'Pipeline', :js do end context 'canceling jobs' do + before do + visit_pipeline + end + it { expect(page).not_to have_selector('.ci-canceled') } context 'when canceling' do @@ -284,6 +306,10 @@ describe 'Pipeline', :js do user: user) end + before do + visit_pipeline + end + it 'does not render link to the pipeline ref' do expect(page).not_to have_link(pipeline.ref) expect(page).to have_content(pipeline.ref) @@ -305,6 +331,10 @@ describe 'Pipeline', :js do merge_request.all_pipelines.last end + before do + visit_pipeline + end + it 'shows the pipeline information' do within '.pipeline-info' do expect(page).to have_content("#{pipeline.statuses.count} jobs " \ @@ -356,6 +386,8 @@ describe 'Pipeline', :js do before do pipeline.update(user: user) + + visit_pipeline end it 'shows the pipeline information' do -- cgit v1.2.1 From 45293f66facc2792f15bd06bb5b05d55fc155cba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20Javier=20L=C3=B3pez?= Date: Mon, 1 Apr 2019 15:13:22 +0000 Subject: Fix MergeRequest#has_commits? nil comparison --- app/models/merge_request.rb | 2 +- spec/models/merge_request_spec.rb | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index b52c480a487..d3951cd72db 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -1343,7 +1343,7 @@ class MergeRequest < ApplicationRecord end def has_commits? - merge_request_diff && commits_count > 0 + merge_request_diff && commits_count.to_i > 0 end def has_no_commits? diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb index 092504cde9e..4b3a77e6bc2 100644 --- a/spec/models/merge_request_spec.rb +++ b/spec/models/merge_request_spec.rb @@ -2714,14 +2714,21 @@ describe MergeRequest do end describe '#has_commits?' do - before do + it 'returns true when merge request diff has commits' do allow(subject.merge_request_diff).to receive(:commits_count) .and_return(2) - end - it 'returns true when merge request diff has commits' do expect(subject.has_commits?).to be_truthy end + + context 'when commits_count is nil' do + it 'returns false' do + allow(subject.merge_request_diff).to receive(:commits_count) + .and_return(nil) + + expect(subject.has_commits?).to be_falsey + end + end end describe '#has_no_commits?' do -- cgit v1.2.1 From b5e09a26de6afb0c194613c6ee4d22a22a0fce14 Mon Sep 17 00:00:00 2001 From: Mayra Cabrera Date: Mon, 1 Apr 2019 16:29:05 +0000 Subject: Include cluster domain into Project Cluster API Domain was introduced on 11.8 and was not included on the Project Cluster API. With this change user will be able to include domain when adding and updating a cluster. Domain will also be included on the GET calls. Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/59441 --- changelogs/unreleased/59441-add-base-domain-to-cluster-api.yml | 5 +++++ doc/api/project_clusters.md | 7 ++++++- lib/api/entities.rb | 2 +- lib/api/project_clusters.rb | 2 ++ spec/requests/api/project_clusters_spec.rb | 8 +++++++- 5 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 changelogs/unreleased/59441-add-base-domain-to-cluster-api.yml diff --git a/changelogs/unreleased/59441-add-base-domain-to-cluster-api.yml b/changelogs/unreleased/59441-add-base-domain-to-cluster-api.yml new file mode 100644 index 00000000000..cb5cbba4e92 --- /dev/null +++ b/changelogs/unreleased/59441-add-base-domain-to-cluster-api.yml @@ -0,0 +1,5 @@ +--- +title: Add cluster domain to Project Cluster API +merge_request: 26735 +author: +type: other diff --git a/doc/api/project_clusters.md b/doc/api/project_clusters.md index 8efb98fe1fc..02334f0298e 100644 --- a/doc/api/project_clusters.md +++ b/doc/api/project_clusters.md @@ -33,6 +33,7 @@ Example response: { "id":18, "name":"cluster-1", + "domain":"example.com", "created_at":"2019-01-02T20:18:12.563Z", "provider_type":"user", "platform_type":"kubernetes", @@ -90,6 +91,7 @@ Example response: { "id":18, "name":"cluster-1", + "domain":"example.com", "created_at":"2019-01-02T20:18:12.563Z", "provider_type":"user", "platform_type":"kubernetes", @@ -157,6 +159,7 @@ Parameters: | --------- | ---- | -------- | ----------- | | `id` | integer | yes | The ID of the project owned by the authenticated user | | `name` | String | yes | The name of the cluster | +| `domain` | String | no | The [base domain](../user/project/clusters/index.md#base_domain) of the cluster | | `enabled` | Boolean | no | Determines if cluster is active or not, defaults to true | | `platform_kubernetes_attributes[api_url]` | String | yes | The URL to access the Kubernetes API | | `platform_kubernetes_attributes[token]` | String | yes | The token to authenticate against Kubernetes | @@ -247,6 +250,7 @@ Parameters: | `id` | integer | yes | The ID of the project owned by the authenticated user | | `cluster_id` | integer | yes | The ID of the cluster | | `name` | String | no | The name of the cluster | +| `domain` | String | no | The [base domain](../user/project/clusters/index.md#base_domain) of the cluster | | `platform_kubernetes_attributes[api_url]` | String | no | The URL to access the Kubernetes API | | `platform_kubernetes_attributes[token]` | String | no | The token to authenticate against Kubernetes | | `platform_kubernetes_attributes[ca_cert]` | String | no | TLS certificate (needed if API is using a self-signed TLS certificate | @@ -262,7 +266,7 @@ Example request: ```bash curl --header 'Private-Token: ' https://gitlab.example.com/api/v4/projects/26/clusters/24 \ -H "Content-Type:application/json" \ --X PUT --data '{"name":"new-cluster-name","api_url":"https://new-api-url.com"}' +-X PUT --data '{"name":"new-cluster-name","domain":"new-domain.com","api_url":"https://new-api-url.com"}' ``` Example response: @@ -271,6 +275,7 @@ Example response: { "id":24, "name":"new-cluster-name", + "domain":"new-domain.com", "created_at":"2019-01-03T21:53:40.610Z", "provider_type":"user", "platform_type":"kubernetes", diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 0871ea8d21e..4533305bfd3 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -1588,7 +1588,7 @@ module API end class Cluster < Grape::Entity - expose :id, :name, :created_at + expose :id, :name, :created_at, :domain expose :provider_type, :platform_type, :environment_scope, :cluster_type expose :user, using: Entities::UserBasic expose :platform_kubernetes, using: Entities::Platform::Kubernetes diff --git a/lib/api/project_clusters.rb b/lib/api/project_clusters.rb index c96261a7b57..b62ec887183 100644 --- a/lib/api/project_clusters.rb +++ b/lib/api/project_clusters.rb @@ -53,6 +53,7 @@ module API params do requires :name, type: String, desc: 'Cluster name' optional :enabled, type: Boolean, default: true, desc: 'Determines if cluster is active or not, defaults to true' + optional :domain, type: String, desc: 'Cluster base domain' requires :platform_kubernetes_attributes, type: Hash, desc: %q(Platform Kubernetes data) do requires :api_url, type: String, allow_blank: false, desc: 'URL to access the Kubernetes API' requires :token, type: String, desc: 'Token to authenticate against Kubernetes' @@ -83,6 +84,7 @@ module API params do requires :cluster_id, type: Integer, desc: 'The cluster ID' optional :name, type: String, desc: 'Cluster name' + optional :domain, type: String, desc: 'Cluster base domain' optional :platform_kubernetes_attributes, type: Hash, desc: %q(Platform Kubernetes data) do optional :api_url, type: String, desc: 'URL to access the Kubernetes API' optional :token, type: String, desc: 'Token to authenticate against Kubernetes' diff --git a/spec/requests/api/project_clusters_spec.rb b/spec/requests/api/project_clusters_spec.rb index 4e42e233b4c..81442125a1c 100644 --- a/spec/requests/api/project_clusters_spec.rb +++ b/spec/requests/api/project_clusters_spec.rb @@ -60,7 +60,7 @@ describe API::ProjectClusters do end let(:cluster) do - create(:cluster, :project, :provided_by_gcp, + create(:cluster, :project, :provided_by_gcp, :with_domain, platform_kubernetes: platform_kubernetes, user: current_user, projects: [project]) @@ -88,6 +88,7 @@ describe API::ProjectClusters do expect(json_response['platform_type']).to eq('kubernetes') expect(json_response['environment_scope']).to eq('*') expect(json_response['cluster_type']).to eq('project_type') + expect(json_response['domain']).to eq('example.com') end it 'returns project information' do @@ -187,6 +188,7 @@ describe API::ProjectClusters do let(:cluster_params) do { name: 'test-cluster', + domain: 'domain.example.com', platform_kubernetes_attributes: platform_kubernetes_attributes } end @@ -217,6 +219,7 @@ describe API::ProjectClusters do expect(cluster_result).to be_kubernetes expect(cluster_result.project).to eq(project) expect(cluster_result.name).to eq('test-cluster') + expect(cluster_result.domain).to eq('domain.example.com') expect(platform_kubernetes.rbac?).to be_truthy expect(platform_kubernetes.api_url).to eq(api_url) expect(platform_kubernetes.namespace).to eq(namespace) @@ -294,6 +297,7 @@ describe API::ProjectClusters do let(:update_params) do { + domain: 'new-domain.com', platform_kubernetes_attributes: platform_kubernetes_attributes } end @@ -330,6 +334,7 @@ describe API::ProjectClusters do end it 'should update cluster attributes' do + expect(cluster.domain).to eq('new-domain.com') expect(cluster.platform_kubernetes.namespace).to eq('new-namespace') end end @@ -342,6 +347,7 @@ describe API::ProjectClusters do end it 'should not update cluster attributes' do + expect(cluster.domain).not_to eq('new_domain.com') expect(cluster.platform_kubernetes.namespace).not_to eq('invalid_namespace') expect(cluster.kubernetes_namespace.namespace).not_to eq('invalid_namespace') end -- cgit v1.2.1 From d4c6a3af78c0ef8257c453980832c4d419aabb51 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Sun, 31 Mar 2019 06:38:23 -0700 Subject: Force a full GC after importing a project During a project import, it's possible that new branches are created by the importer to handle pull requests that have been created from forked projects, which would increment the `pushes_since_gc` value via `HousekeepingService.increment!` before a full garbage collection gets to run. This causes HousekeepingService to skip the full `git gc` and move to the incremental repack mode. To ensure that a garbage collection is run to pack refs and objects, explicitly execute the task. Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/59477 --- app/services/projects/after_import_service.rb | 2 +- app/services/projects/housekeeping_service.rb | 5 ++++- changelogs/unreleased/sh-force-gc-after-import.yml | 5 +++++ spec/services/projects/after_import_service_spec.rb | 2 +- spec/services/projects/housekeeping_service_spec.rb | 13 +++++++++++++ 5 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 changelogs/unreleased/sh-force-gc-after-import.yml diff --git a/app/services/projects/after_import_service.rb b/app/services/projects/after_import_service.rb index bbdde4408d2..afb9048e87b 100644 --- a/app/services/projects/after_import_service.rb +++ b/app/services/projects/after_import_service.rb @@ -9,7 +9,7 @@ module Projects end def execute - Projects::HousekeepingService.new(@project).execute do + Projects::HousekeepingService.new(@project, :gc).execute do repository.delete_all_refs_except(RESERVED_REF_PREFIXES) end rescue Projects::HousekeepingService::LeaseTaken => e diff --git a/app/services/projects/housekeeping_service.rb b/app/services/projects/housekeeping_service.rb index 2f6dc4207dd..10bd5363b51 100644 --- a/app/services/projects/housekeeping_service.rb +++ b/app/services/projects/housekeeping_service.rb @@ -18,8 +18,9 @@ module Projects end end - def initialize(project) + def initialize(project, task = nil) @project = project + @task = task end def execute @@ -69,6 +70,8 @@ module Projects end def task + return @task if @task + if pushes_since_gc % gc_period == 0 :gc elsif pushes_since_gc % full_repack_period == 0 diff --git a/changelogs/unreleased/sh-force-gc-after-import.yml b/changelogs/unreleased/sh-force-gc-after-import.yml new file mode 100644 index 00000000000..755d66c1607 --- /dev/null +++ b/changelogs/unreleased/sh-force-gc-after-import.yml @@ -0,0 +1,5 @@ +--- +title: Force a full GC after importing a project +merge_request: 26803 +author: +type: performance diff --git a/spec/services/projects/after_import_service_spec.rb b/spec/services/projects/after_import_service_spec.rb index 4dd6c6dab86..765b4ffae8f 100644 --- a/spec/services/projects/after_import_service_spec.rb +++ b/spec/services/projects/after_import_service_spec.rb @@ -13,7 +13,7 @@ describe Projects::AfterImportService do describe '#execute' do before do allow(Projects::HousekeepingService) - .to receive(:new).with(project).and_return(housekeeping_service) + .to receive(:new).with(project, :gc).and_return(housekeeping_service) allow(housekeeping_service) .to receive(:execute).and_yield diff --git a/spec/services/projects/housekeeping_service_spec.rb b/spec/services/projects/housekeeping_service_spec.rb index 18ecef1c0a1..12ae9105627 100644 --- a/spec/services/projects/housekeeping_service_spec.rb +++ b/spec/services/projects/housekeeping_service_spec.rb @@ -88,6 +88,19 @@ describe Projects::HousekeepingService do expect(project.pushes_since_gc).to eq(1) end end + + it 'runs the task specifically requested' do + housekeeping = described_class.new(project, :gc) + + allow(housekeeping).to receive(:try_obtain_lease).and_return(:gc_uuid) + allow(housekeeping).to receive(:lease_key).and_return(:gc_lease_key) + + expect(GitGarbageCollectWorker).to receive(:perform_async).with(project.id, :gc, :gc_lease_key, :gc_uuid).twice + + 2.times do + housekeeping.execute + end + end end describe '#needed?' do -- cgit v1.2.1 From d6b952ad3e2ab3d4e7742f5f767dde30673a2661 Mon Sep 17 00:00:00 2001 From: Thong Kuah Date: Sat, 30 Mar 2019 20:15:48 +1300 Subject: Add frozen_string_literal to spec/workers Adds `# frozen_string_literal: true` to spec/workers ruby files --- spec/workers/admin_email_worker_spec.rb | 2 ++ spec/workers/archive_trace_worker_spec.rb | 2 ++ spec/workers/authorized_projects_worker_spec.rb | 2 ++ spec/workers/background_migration_worker_spec.rb | 2 ++ spec/workers/build_coverage_worker_spec.rb | 2 ++ spec/workers/build_finished_worker_spec.rb | 2 ++ spec/workers/build_hooks_worker_spec.rb | 2 ++ spec/workers/build_success_worker_spec.rb | 2 ++ spec/workers/build_trace_sections_worker_spec.rb | 2 ++ spec/workers/ci/archive_traces_cron_worker_spec.rb | 2 ++ spec/workers/ci/build_schedule_worker_spec.rb | 2 ++ spec/workers/cluster_provision_worker_spec.rb | 2 ++ spec/workers/cluster_wait_for_ingress_ip_address_worker_spec.rb | 2 ++ spec/workers/concerns/application_worker_spec.rb | 2 ++ spec/workers/concerns/cluster_queue_spec.rb | 2 ++ spec/workers/concerns/cronjob_queue_spec.rb | 2 ++ spec/workers/concerns/gitlab/github_import/notify_upon_death_spec.rb | 2 ++ spec/workers/concerns/gitlab/github_import/object_importer_spec.rb | 2 ++ spec/workers/concerns/gitlab/github_import/queue_spec.rb | 2 ++ spec/workers/concerns/gitlab/github_import/rescheduling_methods_spec.rb | 2 ++ spec/workers/concerns/gitlab/github_import/stage_methods_spec.rb | 2 ++ spec/workers/concerns/pipeline_background_queue_spec.rb | 2 ++ spec/workers/concerns/pipeline_queue_spec.rb | 2 ++ spec/workers/concerns/project_import_options_spec.rb | 2 ++ spec/workers/concerns/repository_check_queue_spec.rb | 2 ++ spec/workers/concerns/waitable_worker_spec.rb | 2 ++ spec/workers/create_gpg_signature_worker_spec.rb | 2 ++ spec/workers/create_note_diff_file_worker_spec.rb | 2 ++ spec/workers/create_pipeline_worker_spec.rb | 2 ++ spec/workers/delete_diff_files_worker_spec.rb | 2 ++ spec/workers/delete_merged_branches_worker_spec.rb | 2 ++ spec/workers/delete_user_worker_spec.rb | 2 ++ spec/workers/deployments/success_worker_spec.rb | 2 ++ spec/workers/detect_repository_languages_worker_spec.rb | 2 ++ spec/workers/email_receiver_worker_spec.rb | 2 ++ spec/workers/emails_on_push_worker_spec.rb | 2 ++ spec/workers/every_sidekiq_worker_spec.rb | 2 ++ spec/workers/expire_build_artifacts_worker_spec.rb | 2 ++ spec/workers/expire_build_instance_artifacts_worker_spec.rb | 2 ++ spec/workers/expire_job_cache_worker_spec.rb | 2 ++ spec/workers/expire_pipeline_cache_worker_spec.rb | 2 ++ spec/workers/git_garbage_collect_worker_spec.rb | 2 ++ spec/workers/gitlab/github_import/advance_stage_worker_spec.rb | 2 ++ spec/workers/gitlab/github_import/import_diff_note_worker_spec.rb | 2 ++ spec/workers/gitlab/github_import/import_issue_worker_spec.rb | 2 ++ spec/workers/gitlab/github_import/import_note_worker_spec.rb | 2 ++ spec/workers/gitlab/github_import/import_pull_request_worker_spec.rb | 2 ++ spec/workers/gitlab/github_import/refresh_import_jid_worker_spec.rb | 2 ++ spec/workers/gitlab/github_import/stage/finish_import_worker_spec.rb | 2 ++ spec/workers/gitlab/github_import/stage/import_base_data_worker_spec.rb | 2 ++ .../github_import/stage/import_issues_and_diff_notes_worker_spec.rb | 2 ++ .../gitlab/github_import/stage/import_lfs_objects_worker_spec.rb | 2 ++ spec/workers/gitlab/github_import/stage/import_notes_worker_spec.rb | 2 ++ .../gitlab/github_import/stage/import_pull_requests_worker_spec.rb | 2 ++ .../workers/gitlab/github_import/stage/import_repository_worker_spec.rb | 2 ++ spec/workers/gitlab_shell_worker_spec.rb | 2 ++ spec/workers/gitlab_usage_ping_worker_spec.rb | 2 ++ spec/workers/group_destroy_worker_spec.rb | 2 ++ spec/workers/hashed_storage/migrator_worker_spec.rb | 2 ++ spec/workers/hashed_storage/project_migrate_worker_spec.rb | 2 ++ spec/workers/invalid_gpg_signature_update_worker_spec.rb | 2 ++ spec/workers/issue_due_scheduler_worker_spec.rb | 2 ++ spec/workers/mail_scheduler/issue_due_worker_spec.rb | 2 ++ spec/workers/mail_scheduler/notification_service_worker_spec.rb | 2 ++ spec/workers/merge_worker_spec.rb | 2 ++ spec/workers/namespaceless_project_destroy_worker_spec.rb | 2 ++ spec/workers/new_issue_worker_spec.rb | 2 ++ spec/workers/new_merge_request_worker_spec.rb | 2 ++ spec/workers/new_note_worker_spec.rb | 2 ++ spec/workers/pages_domain_verification_cron_worker_spec.rb | 2 ++ spec/workers/pages_domain_verification_worker_spec.rb | 2 ++ spec/workers/pipeline_hooks_worker_spec.rb | 2 ++ spec/workers/pipeline_metrics_worker_spec.rb | 2 ++ spec/workers/pipeline_notification_worker_spec.rb | 2 ++ spec/workers/pipeline_process_worker_spec.rb | 2 ++ spec/workers/pipeline_schedule_worker_spec.rb | 2 ++ spec/workers/pipeline_success_worker_spec.rb | 2 ++ spec/workers/pipeline_update_worker_spec.rb | 2 ++ spec/workers/plugin_worker_spec.rb | 2 ++ spec/workers/post_receive_spec.rb | 2 ++ spec/workers/process_commit_worker_spec.rb | 2 ++ spec/workers/project_cache_worker_spec.rb | 2 ++ spec/workers/project_destroy_worker_spec.rb | 2 ++ spec/workers/project_export_worker_spec.rb | 2 ++ spec/workers/propagate_service_template_worker_spec.rb | 2 ++ spec/workers/prune_old_events_worker_spec.rb | 2 ++ spec/workers/prune_web_hook_logs_worker_spec.rb | 2 ++ spec/workers/reactive_caching_worker_spec.rb | 2 ++ spec/workers/rebase_worker_spec.rb | 2 ++ spec/workers/remote_mirror_notification_worker_spec.rb | 2 ++ spec/workers/remove_expired_group_links_worker_spec.rb | 2 ++ spec/workers/remove_expired_members_worker_spec.rb | 2 ++ spec/workers/remove_unreferenced_lfs_objects_worker_spec.rb | 2 ++ spec/workers/repository_check/batch_worker_spec.rb | 2 ++ spec/workers/repository_check/clear_worker_spec.rb | 2 ++ spec/workers/repository_check/dispatch_worker_spec.rb | 2 ++ spec/workers/repository_check/single_repository_worker_spec.rb | 2 ++ spec/workers/repository_cleanup_worker_spec.rb | 2 ++ spec/workers/repository_fork_worker_spec.rb | 2 ++ spec/workers/repository_import_worker_spec.rb | 2 ++ spec/workers/repository_remove_remote_worker_spec.rb | 2 ++ spec/workers/repository_update_remote_mirror_worker_spec.rb | 2 ++ spec/workers/run_pipeline_schedule_worker_spec.rb | 2 ++ spec/workers/stage_update_worker_spec.rb | 2 ++ spec/workers/stuck_ci_jobs_worker_spec.rb | 2 ++ spec/workers/stuck_import_jobs_worker_spec.rb | 2 ++ spec/workers/stuck_merge_jobs_worker_spec.rb | 2 ++ spec/workers/system_hook_push_worker_spec.rb | 2 ++ spec/workers/todos_destroyer/confidential_issue_worker_spec.rb | 2 ++ spec/workers/todos_destroyer/entity_leave_worker_spec.rb | 2 ++ spec/workers/todos_destroyer/group_private_worker_spec.rb | 2 ++ spec/workers/todos_destroyer/private_features_worker_spec.rb | 2 ++ spec/workers/todos_destroyer/project_private_worker_spec.rb | 2 ++ spec/workers/trending_projects_worker_spec.rb | 2 ++ spec/workers/update_head_pipeline_for_merge_request_worker_spec.rb | 2 ++ spec/workers/update_merge_requests_worker_spec.rb | 2 ++ spec/workers/upload_checksum_worker_spec.rb | 2 ++ spec/workers/wait_for_cluster_creation_worker_spec.rb | 2 ++ 118 files changed, 236 insertions(+) diff --git a/spec/workers/admin_email_worker_spec.rb b/spec/workers/admin_email_worker_spec.rb index 27687f069ea..f72b932423f 100644 --- a/spec/workers/admin_email_worker_spec.rb +++ b/spec/workers/admin_email_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe AdminEmailWorker do diff --git a/spec/workers/archive_trace_worker_spec.rb b/spec/workers/archive_trace_worker_spec.rb index 7244ad4f199..368ed3f3db1 100644 --- a/spec/workers/archive_trace_worker_spec.rb +++ b/spec/workers/archive_trace_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe ArchiveTraceWorker do diff --git a/spec/workers/authorized_projects_worker_spec.rb b/spec/workers/authorized_projects_worker_spec.rb index d095138f6b7..4c02278de64 100644 --- a/spec/workers/authorized_projects_worker_spec.rb +++ b/spec/workers/authorized_projects_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe AuthorizedProjectsWorker do diff --git a/spec/workers/background_migration_worker_spec.rb b/spec/workers/background_migration_worker_spec.rb index 3bd072e7125..746c858609f 100644 --- a/spec/workers/background_migration_worker_spec.rb +++ b/spec/workers/background_migration_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe BackgroundMigrationWorker, :sidekiq, :clean_gitlab_redis_shared_state do diff --git a/spec/workers/build_coverage_worker_spec.rb b/spec/workers/build_coverage_worker_spec.rb index ba20488f663..25686ae68ca 100644 --- a/spec/workers/build_coverage_worker_spec.rb +++ b/spec/workers/build_coverage_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe BuildCoverageWorker do diff --git a/spec/workers/build_finished_worker_spec.rb b/spec/workers/build_finished_worker_spec.rb index ccb26849e67..33f327d4a0c 100644 --- a/spec/workers/build_finished_worker_spec.rb +++ b/spec/workers/build_finished_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe BuildFinishedWorker do diff --git a/spec/workers/build_hooks_worker_spec.rb b/spec/workers/build_hooks_worker_spec.rb index 97654a93f5c..59b252a8be3 100644 --- a/spec/workers/build_hooks_worker_spec.rb +++ b/spec/workers/build_hooks_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe BuildHooksWorker do diff --git a/spec/workers/build_success_worker_spec.rb b/spec/workers/build_success_worker_spec.rb index 5eb9709ded9..065aeaf2b65 100644 --- a/spec/workers/build_success_worker_spec.rb +++ b/spec/workers/build_success_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe BuildSuccessWorker do diff --git a/spec/workers/build_trace_sections_worker_spec.rb b/spec/workers/build_trace_sections_worker_spec.rb index 45243f45547..97fc0a2da0c 100644 --- a/spec/workers/build_trace_sections_worker_spec.rb +++ b/spec/workers/build_trace_sections_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe BuildTraceSectionsWorker do diff --git a/spec/workers/ci/archive_traces_cron_worker_spec.rb b/spec/workers/ci/archive_traces_cron_worker_spec.rb index 478fb7d2c0f..eca6cf5235f 100644 --- a/spec/workers/ci/archive_traces_cron_worker_spec.rb +++ b/spec/workers/ci/archive_traces_cron_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Ci::ArchiveTracesCronWorker do diff --git a/spec/workers/ci/build_schedule_worker_spec.rb b/spec/workers/ci/build_schedule_worker_spec.rb index 4a3fe84d7f7..647f9763fed 100644 --- a/spec/workers/ci/build_schedule_worker_spec.rb +++ b/spec/workers/ci/build_schedule_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Ci::BuildScheduleWorker do diff --git a/spec/workers/cluster_provision_worker_spec.rb b/spec/workers/cluster_provision_worker_spec.rb index da32f29fec0..9cc2ad12bfc 100644 --- a/spec/workers/cluster_provision_worker_spec.rb +++ b/spec/workers/cluster_provision_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe ClusterProvisionWorker do diff --git a/spec/workers/cluster_wait_for_ingress_ip_address_worker_spec.rb b/spec/workers/cluster_wait_for_ingress_ip_address_worker_spec.rb index 2e2e9afd25a..a9ffdfb085e 100644 --- a/spec/workers/cluster_wait_for_ingress_ip_address_worker_spec.rb +++ b/spec/workers/cluster_wait_for_ingress_ip_address_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe ClusterWaitForIngressIpAddressWorker do diff --git a/spec/workers/concerns/application_worker_spec.rb b/spec/workers/concerns/application_worker_spec.rb index 901d77178bc..ae5244e2f62 100644 --- a/spec/workers/concerns/application_worker_spec.rb +++ b/spec/workers/concerns/application_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe ApplicationWorker do diff --git a/spec/workers/concerns/cluster_queue_spec.rb b/spec/workers/concerns/cluster_queue_spec.rb index 4118b9aa194..732d55dfbde 100644 --- a/spec/workers/concerns/cluster_queue_spec.rb +++ b/spec/workers/concerns/cluster_queue_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe ClusterQueue do diff --git a/spec/workers/concerns/cronjob_queue_spec.rb b/spec/workers/concerns/cronjob_queue_spec.rb index c042a52f41f..cf4d47b7500 100644 --- a/spec/workers/concerns/cronjob_queue_spec.rb +++ b/spec/workers/concerns/cronjob_queue_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe CronjobQueue do diff --git a/spec/workers/concerns/gitlab/github_import/notify_upon_death_spec.rb b/spec/workers/concerns/gitlab/github_import/notify_upon_death_spec.rb index 4b9aa9a7ef8..200cdffd560 100644 --- a/spec/workers/concerns/gitlab/github_import/notify_upon_death_spec.rb +++ b/spec/workers/concerns/gitlab/github_import/notify_upon_death_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::GithubImport::NotifyUponDeath do diff --git a/spec/workers/concerns/gitlab/github_import/object_importer_spec.rb b/spec/workers/concerns/gitlab/github_import/object_importer_spec.rb index 9c187bead0a..51b685b5792 100644 --- a/spec/workers/concerns/gitlab/github_import/object_importer_spec.rb +++ b/spec/workers/concerns/gitlab/github_import/object_importer_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::GithubImport::ObjectImporter do diff --git a/spec/workers/concerns/gitlab/github_import/queue_spec.rb b/spec/workers/concerns/gitlab/github_import/queue_spec.rb index a96f583aff7..d262bc2e05c 100644 --- a/spec/workers/concerns/gitlab/github_import/queue_spec.rb +++ b/spec/workers/concerns/gitlab/github_import/queue_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::GithubImport::Queue do diff --git a/spec/workers/concerns/gitlab/github_import/rescheduling_methods_spec.rb b/spec/workers/concerns/gitlab/github_import/rescheduling_methods_spec.rb index 8de4059c4ae..294eacf09ab 100644 --- a/spec/workers/concerns/gitlab/github_import/rescheduling_methods_spec.rb +++ b/spec/workers/concerns/gitlab/github_import/rescheduling_methods_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::GithubImport::ReschedulingMethods do diff --git a/spec/workers/concerns/gitlab/github_import/stage_methods_spec.rb b/spec/workers/concerns/gitlab/github_import/stage_methods_spec.rb index d85a87f2cb0..f9081a875b5 100644 --- a/spec/workers/concerns/gitlab/github_import/stage_methods_spec.rb +++ b/spec/workers/concerns/gitlab/github_import/stage_methods_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::GithubImport::StageMethods do diff --git a/spec/workers/concerns/pipeline_background_queue_spec.rb b/spec/workers/concerns/pipeline_background_queue_spec.rb index 24c0a3c6a20..78ceafb359f 100644 --- a/spec/workers/concerns/pipeline_background_queue_spec.rb +++ b/spec/workers/concerns/pipeline_background_queue_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe PipelineBackgroundQueue do diff --git a/spec/workers/concerns/pipeline_queue_spec.rb b/spec/workers/concerns/pipeline_queue_spec.rb index a312b307fce..eedfceb8bf0 100644 --- a/spec/workers/concerns/pipeline_queue_spec.rb +++ b/spec/workers/concerns/pipeline_queue_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe PipelineQueue do diff --git a/spec/workers/concerns/project_import_options_spec.rb b/spec/workers/concerns/project_import_options_spec.rb index 3699fd83a9a..c5fbcfb5fb0 100644 --- a/spec/workers/concerns/project_import_options_spec.rb +++ b/spec/workers/concerns/project_import_options_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe ProjectImportOptions do diff --git a/spec/workers/concerns/repository_check_queue_spec.rb b/spec/workers/concerns/repository_check_queue_spec.rb index d2eeecfc9a8..55ed71f124c 100644 --- a/spec/workers/concerns/repository_check_queue_spec.rb +++ b/spec/workers/concerns/repository_check_queue_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe RepositoryCheckQueue do diff --git a/spec/workers/concerns/waitable_worker_spec.rb b/spec/workers/concerns/waitable_worker_spec.rb index ce38cde9208..37fadd6ac02 100644 --- a/spec/workers/concerns/waitable_worker_spec.rb +++ b/spec/workers/concerns/waitable_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe WaitableWorker do diff --git a/spec/workers/create_gpg_signature_worker_spec.rb b/spec/workers/create_gpg_signature_worker_spec.rb index f5479e57260..ae09b4b77f1 100644 --- a/spec/workers/create_gpg_signature_worker_spec.rb +++ b/spec/workers/create_gpg_signature_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe CreateGpgSignatureWorker do diff --git a/spec/workers/create_note_diff_file_worker_spec.rb b/spec/workers/create_note_diff_file_worker_spec.rb index 0ac946a1232..e35aaa7d593 100644 --- a/spec/workers/create_note_diff_file_worker_spec.rb +++ b/spec/workers/create_note_diff_file_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe CreateNoteDiffFileWorker do diff --git a/spec/workers/create_pipeline_worker_spec.rb b/spec/workers/create_pipeline_worker_spec.rb index 02cb0f46cb4..62a17da80c0 100644 --- a/spec/workers/create_pipeline_worker_spec.rb +++ b/spec/workers/create_pipeline_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe CreatePipelineWorker do diff --git a/spec/workers/delete_diff_files_worker_spec.rb b/spec/workers/delete_diff_files_worker_spec.rb index e0edd313922..9f8b20df48e 100644 --- a/spec/workers/delete_diff_files_worker_spec.rb +++ b/spec/workers/delete_diff_files_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe DeleteDiffFilesWorker do diff --git a/spec/workers/delete_merged_branches_worker_spec.rb b/spec/workers/delete_merged_branches_worker_spec.rb index 39009d9e4b2..a218ca921d9 100644 --- a/spec/workers/delete_merged_branches_worker_spec.rb +++ b/spec/workers/delete_merged_branches_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe DeleteMergedBranchesWorker do diff --git a/spec/workers/delete_user_worker_spec.rb b/spec/workers/delete_user_worker_spec.rb index 06d9e125105..c963b886e62 100644 --- a/spec/workers/delete_user_worker_spec.rb +++ b/spec/workers/delete_user_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe DeleteUserWorker do diff --git a/spec/workers/deployments/success_worker_spec.rb b/spec/workers/deployments/success_worker_spec.rb index ba7d45eca01..1c68922b03d 100644 --- a/spec/workers/deployments/success_worker_spec.rb +++ b/spec/workers/deployments/success_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Deployments::SuccessWorker do diff --git a/spec/workers/detect_repository_languages_worker_spec.rb b/spec/workers/detect_repository_languages_worker_spec.rb index ff3878fbc8e..dbf32555985 100644 --- a/spec/workers/detect_repository_languages_worker_spec.rb +++ b/spec/workers/detect_repository_languages_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe DetectRepositoryLanguagesWorker do diff --git a/spec/workers/email_receiver_worker_spec.rb b/spec/workers/email_receiver_worker_spec.rb index 045135255d6..f8a31fcdee6 100644 --- a/spec/workers/email_receiver_worker_spec.rb +++ b/spec/workers/email_receiver_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "spec_helper" describe EmailReceiverWorker, :mailer do diff --git a/spec/workers/emails_on_push_worker_spec.rb b/spec/workers/emails_on_push_worker_spec.rb index 05b4fb49ea3..0f87df89c29 100644 --- a/spec/workers/emails_on_push_worker_spec.rb +++ b/spec/workers/emails_on_push_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe EmailsOnPushWorker, :mailer do diff --git a/spec/workers/every_sidekiq_worker_spec.rb b/spec/workers/every_sidekiq_worker_spec.rb index ebe02373275..8fddd8540ef 100644 --- a/spec/workers/every_sidekiq_worker_spec.rb +++ b/spec/workers/every_sidekiq_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'Every Sidekiq worker' do diff --git a/spec/workers/expire_build_artifacts_worker_spec.rb b/spec/workers/expire_build_artifacts_worker_spec.rb index 27995cf1611..74d6b5605d1 100644 --- a/spec/workers/expire_build_artifacts_worker_spec.rb +++ b/spec/workers/expire_build_artifacts_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe ExpireBuildArtifactsWorker do diff --git a/spec/workers/expire_build_instance_artifacts_worker_spec.rb b/spec/workers/expire_build_instance_artifacts_worker_spec.rb index e1a56c72162..bdb5a3801d9 100644 --- a/spec/workers/expire_build_instance_artifacts_worker_spec.rb +++ b/spec/workers/expire_build_instance_artifacts_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe ExpireBuildInstanceArtifactsWorker do diff --git a/spec/workers/expire_job_cache_worker_spec.rb b/spec/workers/expire_job_cache_worker_spec.rb index 1b614342a18..6ac285ca944 100644 --- a/spec/workers/expire_job_cache_worker_spec.rb +++ b/spec/workers/expire_job_cache_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe ExpireJobCacheWorker do diff --git a/spec/workers/expire_pipeline_cache_worker_spec.rb b/spec/workers/expire_pipeline_cache_worker_spec.rb index 54c9a69d329..c98b69ef76c 100644 --- a/spec/workers/expire_pipeline_cache_worker_spec.rb +++ b/spec/workers/expire_pipeline_cache_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe ExpirePipelineCacheWorker do diff --git a/spec/workers/git_garbage_collect_worker_spec.rb b/spec/workers/git_garbage_collect_worker_spec.rb index 4895a968d6e..2459638c3e6 100644 --- a/spec/workers/git_garbage_collect_worker_spec.rb +++ b/spec/workers/git_garbage_collect_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'fileutils' require 'spec_helper' diff --git a/spec/workers/gitlab/github_import/advance_stage_worker_spec.rb b/spec/workers/gitlab/github_import/advance_stage_worker_spec.rb index fc7aafbc0c9..b1647d8c7df 100644 --- a/spec/workers/gitlab/github_import/advance_stage_worker_spec.rb +++ b/spec/workers/gitlab/github_import/advance_stage_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::GithubImport::AdvanceStageWorker, :clean_gitlab_redis_shared_state do diff --git a/spec/workers/gitlab/github_import/import_diff_note_worker_spec.rb b/spec/workers/gitlab/github_import/import_diff_note_worker_spec.rb index 5b1c6b6010a..42d69ff6166 100644 --- a/spec/workers/gitlab/github_import/import_diff_note_worker_spec.rb +++ b/spec/workers/gitlab/github_import/import_diff_note_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::GithubImport::ImportDiffNoteWorker do diff --git a/spec/workers/gitlab/github_import/import_issue_worker_spec.rb b/spec/workers/gitlab/github_import/import_issue_worker_spec.rb index ab070d6d081..06a573e16b7 100644 --- a/spec/workers/gitlab/github_import/import_issue_worker_spec.rb +++ b/spec/workers/gitlab/github_import/import_issue_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::GithubImport::ImportIssueWorker do diff --git a/spec/workers/gitlab/github_import/import_note_worker_spec.rb b/spec/workers/gitlab/github_import/import_note_worker_spec.rb index 3a30f06bb2d..5110c3ff11b 100644 --- a/spec/workers/gitlab/github_import/import_note_worker_spec.rb +++ b/spec/workers/gitlab/github_import/import_note_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::GithubImport::ImportNoteWorker do diff --git a/spec/workers/gitlab/github_import/import_pull_request_worker_spec.rb b/spec/workers/gitlab/github_import/import_pull_request_worker_spec.rb index 3cccd7cab21..d46e381fc51 100644 --- a/spec/workers/gitlab/github_import/import_pull_request_worker_spec.rb +++ b/spec/workers/gitlab/github_import/import_pull_request_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::GithubImport::ImportPullRequestWorker do diff --git a/spec/workers/gitlab/github_import/refresh_import_jid_worker_spec.rb b/spec/workers/gitlab/github_import/refresh_import_jid_worker_spec.rb index 7ff133f1049..fa4ded8e42f 100644 --- a/spec/workers/gitlab/github_import/refresh_import_jid_worker_spec.rb +++ b/spec/workers/gitlab/github_import/refresh_import_jid_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::GithubImport::RefreshImportJidWorker do diff --git a/spec/workers/gitlab/github_import/stage/finish_import_worker_spec.rb b/spec/workers/gitlab/github_import/stage/finish_import_worker_spec.rb index 91e0cddb5d8..35a856802c2 100644 --- a/spec/workers/gitlab/github_import/stage/finish_import_worker_spec.rb +++ b/spec/workers/gitlab/github_import/stage/finish_import_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::GithubImport::Stage::FinishImportWorker do diff --git a/spec/workers/gitlab/github_import/stage/import_base_data_worker_spec.rb b/spec/workers/gitlab/github_import/stage/import_base_data_worker_spec.rb index ad6154cc4a4..0c7fc2a164e 100644 --- a/spec/workers/gitlab/github_import/stage/import_base_data_worker_spec.rb +++ b/spec/workers/gitlab/github_import/stage/import_base_data_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::GithubImport::Stage::ImportBaseDataWorker do diff --git a/spec/workers/gitlab/github_import/stage/import_issues_and_diff_notes_worker_spec.rb b/spec/workers/gitlab/github_import/stage/import_issues_and_diff_notes_worker_spec.rb index ab347f5b75b..5d96f562c30 100644 --- a/spec/workers/gitlab/github_import/stage/import_issues_and_diff_notes_worker_spec.rb +++ b/spec/workers/gitlab/github_import/stage/import_issues_and_diff_notes_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::GithubImport::Stage::ImportIssuesAndDiffNotesWorker do diff --git a/spec/workers/gitlab/github_import/stage/import_lfs_objects_worker_spec.rb b/spec/workers/gitlab/github_import/stage/import_lfs_objects_worker_spec.rb index b19884d7991..e7c9dabb292 100644 --- a/spec/workers/gitlab/github_import/stage/import_lfs_objects_worker_spec.rb +++ b/spec/workers/gitlab/github_import/stage/import_lfs_objects_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::GithubImport::Stage::ImportLfsObjectsWorker do diff --git a/spec/workers/gitlab/github_import/stage/import_notes_worker_spec.rb b/spec/workers/gitlab/github_import/stage/import_notes_worker_spec.rb index 94cff9e4e80..90590a45900 100644 --- a/spec/workers/gitlab/github_import/stage/import_notes_worker_spec.rb +++ b/spec/workers/gitlab/github_import/stage/import_notes_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::GithubImport::Stage::ImportNotesWorker do diff --git a/spec/workers/gitlab/github_import/stage/import_pull_requests_worker_spec.rb b/spec/workers/gitlab/github_import/stage/import_pull_requests_worker_spec.rb index 1fbb073a34a..15d485f1018 100644 --- a/spec/workers/gitlab/github_import/stage/import_pull_requests_worker_spec.rb +++ b/spec/workers/gitlab/github_import/stage/import_pull_requests_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::GithubImport::Stage::ImportPullRequestsWorker do diff --git a/spec/workers/gitlab/github_import/stage/import_repository_worker_spec.rb b/spec/workers/gitlab/github_import/stage/import_repository_worker_spec.rb index adab535ac05..6d47d73b92e 100644 --- a/spec/workers/gitlab/github_import/stage/import_repository_worker_spec.rb +++ b/spec/workers/gitlab/github_import/stage/import_repository_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::GithubImport::Stage::ImportRepositoryWorker do diff --git a/spec/workers/gitlab_shell_worker_spec.rb b/spec/workers/gitlab_shell_worker_spec.rb index 6b222af454d..0758cfc4ee2 100644 --- a/spec/workers/gitlab_shell_worker_spec.rb +++ b/spec/workers/gitlab_shell_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe GitlabShellWorker do diff --git a/spec/workers/gitlab_usage_ping_worker_spec.rb b/spec/workers/gitlab_usage_ping_worker_spec.rb index 49b4e04dc7c..aff5d112cdd 100644 --- a/spec/workers/gitlab_usage_ping_worker_spec.rb +++ b/spec/workers/gitlab_usage_ping_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe GitlabUsagePingWorker do diff --git a/spec/workers/group_destroy_worker_spec.rb b/spec/workers/group_destroy_worker_spec.rb index a170c84ab12..90a4150a31a 100644 --- a/spec/workers/group_destroy_worker_spec.rb +++ b/spec/workers/group_destroy_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe GroupDestroyWorker do diff --git a/spec/workers/hashed_storage/migrator_worker_spec.rb b/spec/workers/hashed_storage/migrator_worker_spec.rb index a85f820a3eb..a318cdd003e 100644 --- a/spec/workers/hashed_storage/migrator_worker_spec.rb +++ b/spec/workers/hashed_storage/migrator_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe HashedStorage::MigratorWorker do diff --git a/spec/workers/hashed_storage/project_migrate_worker_spec.rb b/spec/workers/hashed_storage/project_migrate_worker_spec.rb index 340e722aa7e..f266c7dbe8c 100644 --- a/spec/workers/hashed_storage/project_migrate_worker_spec.rb +++ b/spec/workers/hashed_storage/project_migrate_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe HashedStorage::ProjectMigrateWorker, :clean_gitlab_redis_shared_state do diff --git a/spec/workers/invalid_gpg_signature_update_worker_spec.rb b/spec/workers/invalid_gpg_signature_update_worker_spec.rb index 5972696515b..4f727469ea8 100644 --- a/spec/workers/invalid_gpg_signature_update_worker_spec.rb +++ b/spec/workers/invalid_gpg_signature_update_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe InvalidGpgSignatureUpdateWorker do diff --git a/spec/workers/issue_due_scheduler_worker_spec.rb b/spec/workers/issue_due_scheduler_worker_spec.rb index 2710267d384..61ad8330840 100644 --- a/spec/workers/issue_due_scheduler_worker_spec.rb +++ b/spec/workers/issue_due_scheduler_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe IssueDueSchedulerWorker do diff --git a/spec/workers/mail_scheduler/issue_due_worker_spec.rb b/spec/workers/mail_scheduler/issue_due_worker_spec.rb index 1026ae5b4bf..fa17775e9f2 100644 --- a/spec/workers/mail_scheduler/issue_due_worker_spec.rb +++ b/spec/workers/mail_scheduler/issue_due_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe MailScheduler::IssueDueWorker do diff --git a/spec/workers/mail_scheduler/notification_service_worker_spec.rb b/spec/workers/mail_scheduler/notification_service_worker_spec.rb index 5cfba01850c..0729c5f9ffb 100644 --- a/spec/workers/mail_scheduler/notification_service_worker_spec.rb +++ b/spec/workers/mail_scheduler/notification_service_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe MailScheduler::NotificationServiceWorker do diff --git a/spec/workers/merge_worker_spec.rb b/spec/workers/merge_worker_spec.rb index b57c275c770..138a99abde6 100644 --- a/spec/workers/merge_worker_spec.rb +++ b/spec/workers/merge_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe MergeWorker do diff --git a/spec/workers/namespaceless_project_destroy_worker_spec.rb b/spec/workers/namespaceless_project_destroy_worker_spec.rb index 2f21a1321e1..4fbda37e268 100644 --- a/spec/workers/namespaceless_project_destroy_worker_spec.rb +++ b/spec/workers/namespaceless_project_destroy_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe NamespacelessProjectDestroyWorker do diff --git a/spec/workers/new_issue_worker_spec.rb b/spec/workers/new_issue_worker_spec.rb index baa8ddb59e5..88a75ce5b70 100644 --- a/spec/workers/new_issue_worker_spec.rb +++ b/spec/workers/new_issue_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe NewIssueWorker do diff --git a/spec/workers/new_merge_request_worker_spec.rb b/spec/workers/new_merge_request_worker_spec.rb index c3f29a40d58..d078ddd07d9 100644 --- a/spec/workers/new_merge_request_worker_spec.rb +++ b/spec/workers/new_merge_request_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe NewMergeRequestWorker do diff --git a/spec/workers/new_note_worker_spec.rb b/spec/workers/new_note_worker_spec.rb index 575361c93d4..2966a201a62 100644 --- a/spec/workers/new_note_worker_spec.rb +++ b/spec/workers/new_note_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "spec_helper" describe NewNoteWorker do diff --git a/spec/workers/pages_domain_verification_cron_worker_spec.rb b/spec/workers/pages_domain_verification_cron_worker_spec.rb index 8f780428c82..9b479da1cb6 100644 --- a/spec/workers/pages_domain_verification_cron_worker_spec.rb +++ b/spec/workers/pages_domain_verification_cron_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe PagesDomainVerificationCronWorker do diff --git a/spec/workers/pages_domain_verification_worker_spec.rb b/spec/workers/pages_domain_verification_worker_spec.rb index 372fc95ab4a..2f23dcb487f 100644 --- a/spec/workers/pages_domain_verification_worker_spec.rb +++ b/spec/workers/pages_domain_verification_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe PagesDomainVerificationWorker do diff --git a/spec/workers/pipeline_hooks_worker_spec.rb b/spec/workers/pipeline_hooks_worker_spec.rb index 035e329839f..60df08f40da 100644 --- a/spec/workers/pipeline_hooks_worker_spec.rb +++ b/spec/workers/pipeline_hooks_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe PipelineHooksWorker do diff --git a/spec/workers/pipeline_metrics_worker_spec.rb b/spec/workers/pipeline_metrics_worker_spec.rb index 896f9e6e7f2..6beecbcd114 100644 --- a/spec/workers/pipeline_metrics_worker_spec.rb +++ b/spec/workers/pipeline_metrics_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe PipelineMetricsWorker do diff --git a/spec/workers/pipeline_notification_worker_spec.rb b/spec/workers/pipeline_notification_worker_spec.rb index eb539ffd893..98b0f139fe2 100644 --- a/spec/workers/pipeline_notification_worker_spec.rb +++ b/spec/workers/pipeline_notification_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe PipelineNotificationWorker, :mailer do diff --git a/spec/workers/pipeline_process_worker_spec.rb b/spec/workers/pipeline_process_worker_spec.rb index 86e9d7f6684..d33cf72e51e 100644 --- a/spec/workers/pipeline_process_worker_spec.rb +++ b/spec/workers/pipeline_process_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe PipelineProcessWorker do diff --git a/spec/workers/pipeline_schedule_worker_spec.rb b/spec/workers/pipeline_schedule_worker_spec.rb index ff408427926..f23910d23be 100644 --- a/spec/workers/pipeline_schedule_worker_spec.rb +++ b/spec/workers/pipeline_schedule_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe PipelineScheduleWorker do diff --git a/spec/workers/pipeline_success_worker_spec.rb b/spec/workers/pipeline_success_worker_spec.rb index d1c84adda6f..4cbe384b47a 100644 --- a/spec/workers/pipeline_success_worker_spec.rb +++ b/spec/workers/pipeline_success_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe PipelineSuccessWorker do diff --git a/spec/workers/pipeline_update_worker_spec.rb b/spec/workers/pipeline_update_worker_spec.rb index 0b456cfd0da..0225e4a9601 100644 --- a/spec/workers/pipeline_update_worker_spec.rb +++ b/spec/workers/pipeline_update_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe PipelineUpdateWorker do diff --git a/spec/workers/plugin_worker_spec.rb b/spec/workers/plugin_worker_spec.rb index 9238a8199bc..ca6c9986131 100644 --- a/spec/workers/plugin_worker_spec.rb +++ b/spec/workers/plugin_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe PluginWorker do diff --git a/spec/workers/post_receive_spec.rb b/spec/workers/post_receive_spec.rb index 9cddad71a51..66958a4c116 100644 --- a/spec/workers/post_receive_spec.rb +++ b/spec/workers/post_receive_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe PostReceive do diff --git a/spec/workers/process_commit_worker_spec.rb b/spec/workers/process_commit_worker_spec.rb index 2d071c181c2..47bac63511e 100644 --- a/spec/workers/process_commit_worker_spec.rb +++ b/spec/workers/process_commit_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe ProcessCommitWorker do diff --git a/spec/workers/project_cache_worker_spec.rb b/spec/workers/project_cache_worker_spec.rb index b9b5445562f..a7353227043 100644 --- a/spec/workers/project_cache_worker_spec.rb +++ b/spec/workers/project_cache_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe ProjectCacheWorker do diff --git a/spec/workers/project_destroy_worker_spec.rb b/spec/workers/project_destroy_worker_spec.rb index 6132f145f8d..ec40900a5b7 100644 --- a/spec/workers/project_destroy_worker_spec.rb +++ b/spec/workers/project_destroy_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe ProjectDestroyWorker do diff --git a/spec/workers/project_export_worker_spec.rb b/spec/workers/project_export_worker_spec.rb index 8899969c178..8065087796c 100644 --- a/spec/workers/project_export_worker_spec.rb +++ b/spec/workers/project_export_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe ProjectExportWorker do diff --git a/spec/workers/propagate_service_template_worker_spec.rb b/spec/workers/propagate_service_template_worker_spec.rb index af1fb80a51d..fb4ced77832 100644 --- a/spec/workers/propagate_service_template_worker_spec.rb +++ b/spec/workers/propagate_service_template_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe PropagateServiceTemplateWorker do diff --git a/spec/workers/prune_old_events_worker_spec.rb b/spec/workers/prune_old_events_worker_spec.rb index ea2b6ae229e..f1eef1923bf 100644 --- a/spec/workers/prune_old_events_worker_spec.rb +++ b/spec/workers/prune_old_events_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe PruneOldEventsWorker do diff --git a/spec/workers/prune_web_hook_logs_worker_spec.rb b/spec/workers/prune_web_hook_logs_worker_spec.rb index b3ec71d4a00..e57334967fd 100644 --- a/spec/workers/prune_web_hook_logs_worker_spec.rb +++ b/spec/workers/prune_web_hook_logs_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe PruneWebHookLogsWorker do diff --git a/spec/workers/reactive_caching_worker_spec.rb b/spec/workers/reactive_caching_worker_spec.rb index 3da851de067..2395e6ec947 100644 --- a/spec/workers/reactive_caching_worker_spec.rb +++ b/spec/workers/reactive_caching_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe ReactiveCachingWorker do diff --git a/spec/workers/rebase_worker_spec.rb b/spec/workers/rebase_worker_spec.rb index 900332ed6b3..578b8cf7451 100644 --- a/spec/workers/rebase_worker_spec.rb +++ b/spec/workers/rebase_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe RebaseWorker, '#perform' do diff --git a/spec/workers/remote_mirror_notification_worker_spec.rb b/spec/workers/remote_mirror_notification_worker_spec.rb index e3db10ed645..5182f67b4af 100644 --- a/spec/workers/remote_mirror_notification_worker_spec.rb +++ b/spec/workers/remote_mirror_notification_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe RemoteMirrorNotificationWorker, :mailer do diff --git a/spec/workers/remove_expired_group_links_worker_spec.rb b/spec/workers/remove_expired_group_links_worker_spec.rb index 689bc3d27b4..10d9aa37dee 100644 --- a/spec/workers/remove_expired_group_links_worker_spec.rb +++ b/spec/workers/remove_expired_group_links_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe RemoveExpiredGroupLinksWorker do diff --git a/spec/workers/remove_expired_members_worker_spec.rb b/spec/workers/remove_expired_members_worker_spec.rb index 058fdf4c009..69a5725bb35 100644 --- a/spec/workers/remove_expired_members_worker_spec.rb +++ b/spec/workers/remove_expired_members_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe RemoveExpiredMembersWorker do diff --git a/spec/workers/remove_unreferenced_lfs_objects_worker_spec.rb b/spec/workers/remove_unreferenced_lfs_objects_worker_spec.rb index 57f83c1dbe9..0e21933a9a5 100644 --- a/spec/workers/remove_unreferenced_lfs_objects_worker_spec.rb +++ b/spec/workers/remove_unreferenced_lfs_objects_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe RemoveUnreferencedLfsObjectsWorker do diff --git a/spec/workers/repository_check/batch_worker_spec.rb b/spec/workers/repository_check/batch_worker_spec.rb index 50b93fce2dc..051c6a5d141 100644 --- a/spec/workers/repository_check/batch_worker_spec.rb +++ b/spec/workers/repository_check/batch_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe RepositoryCheck::BatchWorker do diff --git a/spec/workers/repository_check/clear_worker_spec.rb b/spec/workers/repository_check/clear_worker_spec.rb index 1c49415d46c..7ad9e287204 100644 --- a/spec/workers/repository_check/clear_worker_spec.rb +++ b/spec/workers/repository_check/clear_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe RepositoryCheck::ClearWorker do diff --git a/spec/workers/repository_check/dispatch_worker_spec.rb b/spec/workers/repository_check/dispatch_worker_spec.rb index 7877429aa8f..03efb6a0a80 100644 --- a/spec/workers/repository_check/dispatch_worker_spec.rb +++ b/spec/workers/repository_check/dispatch_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe RepositoryCheck::DispatchWorker do diff --git a/spec/workers/repository_check/single_repository_worker_spec.rb b/spec/workers/repository_check/single_repository_worker_spec.rb index f11875cffd1..65e1c5e9d5d 100644 --- a/spec/workers/repository_check/single_repository_worker_spec.rb +++ b/spec/workers/repository_check/single_repository_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' require 'fileutils' diff --git a/spec/workers/repository_cleanup_worker_spec.rb b/spec/workers/repository_cleanup_worker_spec.rb index 3adae0b6cfa..e58664cf22a 100644 --- a/spec/workers/repository_cleanup_worker_spec.rb +++ b/spec/workers/repository_cleanup_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe RepositoryCleanupWorker do diff --git a/spec/workers/repository_fork_worker_spec.rb b/spec/workers/repository_fork_worker_spec.rb index 31bfe88d0bd..26fd67adfaa 100644 --- a/spec/workers/repository_fork_worker_spec.rb +++ b/spec/workers/repository_fork_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe RepositoryForkWorker do diff --git a/spec/workers/repository_import_worker_spec.rb b/spec/workers/repository_import_worker_spec.rb index 87ac4bc05c1..b8767af8eee 100644 --- a/spec/workers/repository_import_worker_spec.rb +++ b/spec/workers/repository_import_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe RepositoryImportWorker do diff --git a/spec/workers/repository_remove_remote_worker_spec.rb b/spec/workers/repository_remove_remote_worker_spec.rb index 6ddb653d142..6eba5c50960 100644 --- a/spec/workers/repository_remove_remote_worker_spec.rb +++ b/spec/workers/repository_remove_remote_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' describe RepositoryRemoveRemoteWorker do diff --git a/spec/workers/repository_update_remote_mirror_worker_spec.rb b/spec/workers/repository_update_remote_mirror_worker_spec.rb index b582a3650b6..4de51ecb3e9 100644 --- a/spec/workers/repository_update_remote_mirror_worker_spec.rb +++ b/spec/workers/repository_update_remote_mirror_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' describe RepositoryUpdateRemoteMirrorWorker do diff --git a/spec/workers/run_pipeline_schedule_worker_spec.rb b/spec/workers/run_pipeline_schedule_worker_spec.rb index 481a84837f9..690af22f4dc 100644 --- a/spec/workers/run_pipeline_schedule_worker_spec.rb +++ b/spec/workers/run_pipeline_schedule_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe RunPipelineScheduleWorker do diff --git a/spec/workers/stage_update_worker_spec.rb b/spec/workers/stage_update_worker_spec.rb index 7bc76c79464..429d42bac29 100644 --- a/spec/workers/stage_update_worker_spec.rb +++ b/spec/workers/stage_update_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe StageUpdateWorker do diff --git a/spec/workers/stuck_ci_jobs_worker_spec.rb b/spec/workers/stuck_ci_jobs_worker_spec.rb index e09b8e5b964..72de62f1188 100644 --- a/spec/workers/stuck_ci_jobs_worker_spec.rb +++ b/spec/workers/stuck_ci_jobs_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe StuckCiJobsWorker do diff --git a/spec/workers/stuck_import_jobs_worker_spec.rb b/spec/workers/stuck_import_jobs_worker_spec.rb index e94d2be9850..dcb8e59ed28 100644 --- a/spec/workers/stuck_import_jobs_worker_spec.rb +++ b/spec/workers/stuck_import_jobs_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe StuckImportJobsWorker do diff --git a/spec/workers/stuck_merge_jobs_worker_spec.rb b/spec/workers/stuck_merge_jobs_worker_spec.rb index 5aaff27a6b2..09efed6d2cf 100644 --- a/spec/workers/stuck_merge_jobs_worker_spec.rb +++ b/spec/workers/stuck_merge_jobs_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe StuckMergeJobsWorker do diff --git a/spec/workers/system_hook_push_worker_spec.rb b/spec/workers/system_hook_push_worker_spec.rb index b1d446ed25f..890a622d11a 100644 --- a/spec/workers/system_hook_push_worker_spec.rb +++ b/spec/workers/system_hook_push_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe SystemHookPushWorker do diff --git a/spec/workers/todos_destroyer/confidential_issue_worker_spec.rb b/spec/workers/todos_destroyer/confidential_issue_worker_spec.rb index 9d7c0b8f560..18876b71615 100644 --- a/spec/workers/todos_destroyer/confidential_issue_worker_spec.rb +++ b/spec/workers/todos_destroyer/confidential_issue_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe TodosDestroyer::ConfidentialIssueWorker do diff --git a/spec/workers/todos_destroyer/entity_leave_worker_spec.rb b/spec/workers/todos_destroyer/entity_leave_worker_spec.rb index 955447906aa..cb14fac0910 100644 --- a/spec/workers/todos_destroyer/entity_leave_worker_spec.rb +++ b/spec/workers/todos_destroyer/entity_leave_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe TodosDestroyer::EntityLeaveWorker do diff --git a/spec/workers/todos_destroyer/group_private_worker_spec.rb b/spec/workers/todos_destroyer/group_private_worker_spec.rb index fcc38989ced..d9a240136d5 100644 --- a/spec/workers/todos_destroyer/group_private_worker_spec.rb +++ b/spec/workers/todos_destroyer/group_private_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe TodosDestroyer::GroupPrivateWorker do diff --git a/spec/workers/todos_destroyer/private_features_worker_spec.rb b/spec/workers/todos_destroyer/private_features_worker_spec.rb index 9599f5ee071..abd04acc3bd 100644 --- a/spec/workers/todos_destroyer/private_features_worker_spec.rb +++ b/spec/workers/todos_destroyer/private_features_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe TodosDestroyer::PrivateFeaturesWorker do diff --git a/spec/workers/todos_destroyer/project_private_worker_spec.rb b/spec/workers/todos_destroyer/project_private_worker_spec.rb index 15d926fa9d5..c1bb0438ec3 100644 --- a/spec/workers/todos_destroyer/project_private_worker_spec.rb +++ b/spec/workers/todos_destroyer/project_private_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe TodosDestroyer::ProjectPrivateWorker do diff --git a/spec/workers/trending_projects_worker_spec.rb b/spec/workers/trending_projects_worker_spec.rb index c3c6fdcf2d5..6e524085662 100644 --- a/spec/workers/trending_projects_worker_spec.rb +++ b/spec/workers/trending_projects_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe TrendingProjectsWorker do diff --git a/spec/workers/update_head_pipeline_for_merge_request_worker_spec.rb b/spec/workers/update_head_pipeline_for_merge_request_worker_spec.rb index d20d926f5a0..c4af829a5e2 100644 --- a/spec/workers/update_head_pipeline_for_merge_request_worker_spec.rb +++ b/spec/workers/update_head_pipeline_for_merge_request_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe UpdateHeadPipelineForMergeRequestWorker do diff --git a/spec/workers/update_merge_requests_worker_spec.rb b/spec/workers/update_merge_requests_worker_spec.rb index 0b553db0ca4..486dade454a 100644 --- a/spec/workers/update_merge_requests_worker_spec.rb +++ b/spec/workers/update_merge_requests_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe UpdateMergeRequestsWorker do diff --git a/spec/workers/upload_checksum_worker_spec.rb b/spec/workers/upload_checksum_worker_spec.rb index 9e50ce15871..7202c8001b4 100644 --- a/spec/workers/upload_checksum_worker_spec.rb +++ b/spec/workers/upload_checksum_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails_helper' describe UploadChecksumWorker do diff --git a/spec/workers/wait_for_cluster_creation_worker_spec.rb b/spec/workers/wait_for_cluster_creation_worker_spec.rb index 0e92b298178..850eba263a7 100644 --- a/spec/workers/wait_for_cluster_creation_worker_spec.rb +++ b/spec/workers/wait_for_cluster_creation_worker_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe WaitForClusterCreationWorker do -- cgit v1.2.1 From e363e76af242f701263ef2441afd806946110dcf Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Mon, 1 Apr 2019 18:29:10 +0100 Subject: Fixed expand full file button showing on images Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/59695 --- app/serializers/diff_file_entity.rb | 2 +- changelogs/unreleased/fix-expand-full-file-on-image.yml | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 changelogs/unreleased/fix-expand-full-file-on-image.yml diff --git a/app/serializers/diff_file_entity.rb b/app/serializers/diff_file_entity.rb index d3d5883e46b..2a5121a2266 100644 --- a/app/serializers/diff_file_entity.rb +++ b/app/serializers/diff_file_entity.rb @@ -57,7 +57,7 @@ class DiffFileEntity < DiffFileBaseEntity diff_file.diff_lines_for_serializer end - expose :is_fully_expanded, if: -> (diff_file, _) { diff_file.text? } do |diff_file| + expose :is_fully_expanded do |diff_file| diff_file.fully_expanded? end diff --git a/changelogs/unreleased/fix-expand-full-file-on-image.yml b/changelogs/unreleased/fix-expand-full-file-on-image.yml new file mode 100644 index 00000000000..a88d30cfa38 --- /dev/null +++ b/changelogs/unreleased/fix-expand-full-file-on-image.yml @@ -0,0 +1,5 @@ +--- +title: Fixed expand full file button showing on images +merge_request: +author: +type: fixed -- cgit v1.2.1 From f2b7da4bf507691cffd419d3dd759fcf6311cdd6 Mon Sep 17 00:00:00 2001 From: Felipe Artur Date: Mon, 1 Apr 2019 15:04:36 -0300 Subject: Remove additional logging --- lib/gitlab/background_migration/sync_issues_state_id.rb | 2 -- lib/gitlab/background_migration/sync_merge_requests_state_id.rb | 2 -- 2 files changed, 4 deletions(-) diff --git a/lib/gitlab/background_migration/sync_issues_state_id.rb b/lib/gitlab/background_migration/sync_issues_state_id.rb index 33002f58be6..2a0751928b8 100644 --- a/lib/gitlab/background_migration/sync_issues_state_id.rb +++ b/lib/gitlab/background_migration/sync_issues_state_id.rb @@ -5,8 +5,6 @@ module Gitlab module BackgroundMigration class SyncIssuesStateId def perform(start_id, end_id) - Gitlab::AppLogger.info("Issues - Populating state_id: #{start_id} - #{end_id}") - ActiveRecord::Base.connection.execute <<~SQL UPDATE issues SET state_id = diff --git a/lib/gitlab/background_migration/sync_merge_requests_state_id.rb b/lib/gitlab/background_migration/sync_merge_requests_state_id.rb index 923ceaeec54..6707e178d8b 100644 --- a/lib/gitlab/background_migration/sync_merge_requests_state_id.rb +++ b/lib/gitlab/background_migration/sync_merge_requests_state_id.rb @@ -5,8 +5,6 @@ module Gitlab module BackgroundMigration class SyncMergeRequestsStateId def perform(start_id, end_id) - Rails.logger.info("Merge Requests - Populating state_id: #{start_id} - #{end_id}") - ActiveRecord::Base.connection.execute <<~SQL UPDATE merge_requests SET state_id = -- cgit v1.2.1 From 8c5b3d030210cc2659107ec2633a496165470125 Mon Sep 17 00:00:00 2001 From: Bob Van Landuyt Date: Thu, 28 Mar 2019 20:05:27 +0100 Subject: Allow streaming io objects into Gitaly This allows us to set the encoding of an IO passed without reading it into memory. This is useful if we want to stream files into Gitaly. Like we do when uploading a new file to the repository. --- app/controllers/projects/blob_controller.rb | 3 +-- lib/gitlab/encoding_helper.rb | 7 +++++-- lib/gitlab/gitaly_client/conflicts_service.rb | 2 +- lib/gitlab/gitaly_client/operation_service.rb | 4 ++-- lib/gitlab/gitaly_client/wiki_service.rb | 4 ++-- spec/lib/gitlab/encoding_helper_spec.rb | 13 +++++++++++-- 6 files changed, 22 insertions(+), 11 deletions(-) diff --git a/app/controllers/projects/blob_controller.rb b/app/controllers/projects/blob_controller.rb index 909b17e9c8d..7e072788fc9 100644 --- a/app/controllers/projects/blob_controller.rb +++ b/app/controllers/projects/blob_controller.rb @@ -172,8 +172,7 @@ class Projects::BlobController < Projects::ApplicationController end if params[:file].present? - params[:content] = Base64.encode64(params[:file].read) - params[:encoding] = 'base64' + params[:content] = params[:file] end @commit_params = { diff --git a/lib/gitlab/encoding_helper.rb b/lib/gitlab/encoding_helper.rb index a4a154c80f7..5a61a7f5d60 100644 --- a/lib/gitlab/encoding_helper.rb +++ b/lib/gitlab/encoding_helper.rb @@ -76,8 +76,11 @@ module Gitlab str.dup.force_encoding(Encoding::ASCII_8BIT) end - def binary_stringio(str) - StringIO.new(str.freeze || '').tap { |io| io.set_encoding(Encoding::ASCII_8BIT) } + def binary_io(str_or_io) + io = str_or_io.to_io.dup if str_or_io.respond_to?(:to_io) + io ||= StringIO.new(str_or_io.to_s.freeze) + + io.tap { |io| io.set_encoding(Encoding::ASCII_8BIT) } end private diff --git a/lib/gitlab/gitaly_client/conflicts_service.rb b/lib/gitlab/gitaly_client/conflicts_service.rb index 6304f998563..077b63205a8 100644 --- a/lib/gitlab/gitaly_client/conflicts_service.rb +++ b/lib/gitlab/gitaly_client/conflicts_service.rb @@ -37,7 +37,7 @@ module Gitlab end def resolve_conflicts(target_repository, resolution, source_branch, target_branch) - reader = binary_stringio(resolution.files.to_json) + reader = binary_io(resolution.files.to_json) req_enum = Enumerator.new do |y| header = resolve_conflicts_request_header(target_repository, resolution, source_branch, target_branch) diff --git a/lib/gitlab/gitaly_client/operation_service.rb b/lib/gitlab/gitaly_client/operation_service.rb index 2528208440e..b0f328ce3d4 100644 --- a/lib/gitlab/gitaly_client/operation_service.rb +++ b/lib/gitlab/gitaly_client/operation_service.rb @@ -294,7 +294,7 @@ module Gitlab action: Gitaly::UserCommitFilesAction.new(header: action_header) ) - reader = binary_stringio(action[:content]) + reader = binary_io(action[:content]) until reader.eof? chunk = reader.read(MAX_MSG_SIZE) @@ -327,7 +327,7 @@ module Gitlab user: Gitlab::Git::User.from_gitlab(user).to_gitaly, target_branch: encode_binary(branch_name) ) - reader = binary_stringio(patches) + reader = binary_io(patches) chunks = Enumerator.new do |chunk| chunk.yield Gitaly::UserApplyPatchRequest.new(header: header) diff --git a/lib/gitlab/gitaly_client/wiki_service.rb b/lib/gitlab/gitaly_client/wiki_service.rb index 2b3d622af4d..15c9463e2f2 100644 --- a/lib/gitlab/gitaly_client/wiki_service.rb +++ b/lib/gitlab/gitaly_client/wiki_service.rb @@ -22,7 +22,7 @@ module Gitlab commit_details: gitaly_commit_details(commit_details) ) - strio = binary_stringio(content) + strio = binary_io(content) enum = Enumerator.new do |y| until strio.eof? @@ -49,7 +49,7 @@ module Gitlab commit_details: gitaly_commit_details(commit_details) ) - strio = binary_stringio(content) + strio = binary_io(content) enum = Enumerator.new do |y| until strio.eof? diff --git a/spec/lib/gitlab/encoding_helper_spec.rb b/spec/lib/gitlab/encoding_helper_spec.rb index 429816efec3..88ea98eb1e1 100644 --- a/spec/lib/gitlab/encoding_helper_spec.rb +++ b/spec/lib/gitlab/encoding_helper_spec.rb @@ -189,14 +189,23 @@ describe Gitlab::EncodingHelper do end end - describe '#binary_stringio' do + describe '#binary_io' do it 'does not mutate the original string encoding' do test = 'my-test' - io_stream = ext_class.binary_stringio(test) + io_stream = ext_class.binary_io(test) expect(io_stream.external_encoding.name).to eq('ASCII-8BIT') expect(test.encoding.name).to eq('UTF-8') end + + it 'returns a copy of the IO with the correct encoding' do + test = fixture_file_upload('spec/fixtures/doc_sample.txt').to_io + + io_stream = ext_class.binary_io(test) + + expect(io_stream.external_encoding.name).to eq('ASCII-8BIT') + expect(test).not_to eq(io_stream) + end end end -- cgit v1.2.1 From e3465a5dde695f316fec13dfde477660b402fdb8 Mon Sep 17 00:00:00 2001 From: Winnie Hellmann Date: Mon, 1 Apr 2019 18:55:57 +0000 Subject: Add jQuery matchers to Jest --- package.json | 1 + .../reports/components/report_section_spec.js | 200 +++++++++++++++++++++ spec/frontend/test_setup.js | 8 + .../reports/components/report_section_spec.js | 200 --------------------- yarn.lock | 5 + 5 files changed, 214 insertions(+), 200 deletions(-) create mode 100644 spec/frontend/reports/components/report_section_spec.js delete mode 100644 spec/javascripts/reports/components/report_section_spec.js diff --git a/package.json b/package.json index 90fcfe01438..f80f9b3690b 100644 --- a/package.json +++ b/package.json @@ -144,6 +144,7 @@ "babel-plugin-rewire": "^1.2.0", "chalk": "^2.4.1", "commander": "^2.18.0", + "custom-jquery-matchers": "^2.1.0", "docdash": "^1.0.2", "eslint": "~5.9.0", "eslint-import-resolver-jest": "^2.1.1", diff --git a/spec/frontend/reports/components/report_section_spec.js b/spec/frontend/reports/components/report_section_spec.js new file mode 100644 index 00000000000..3b609484b9e --- /dev/null +++ b/spec/frontend/reports/components/report_section_spec.js @@ -0,0 +1,200 @@ +import Vue from 'vue'; +import reportSection from '~/reports/components/report_section.vue'; +import mountComponent, { mountComponentWithSlots } from 'helpers/vue_mount_component_helper'; + +describe('Report section', () => { + let vm; + const ReportSection = Vue.extend(reportSection); + + const resolvedIssues = [ + { + name: 'Insecure Dependency', + fingerprint: 'ca2e59451e98ae60ba2f54e3857c50e5', + path: 'Gemfile.lock', + line: 12, + urlPath: 'foo/Gemfile.lock', + }, + ]; + + afterEach(() => { + vm.$destroy(); + }); + + describe('computed', () => { + beforeEach(() => { + vm = mountComponent(ReportSection, { + component: '', + status: 'SUCCESS', + loadingText: 'Loading codeclimate report', + errorText: 'foo', + successText: 'Code quality improved on 1 point and degraded on 1 point', + resolvedIssues, + hasIssues: false, + alwaysOpen: false, + }); + }); + + describe('isCollapsible', () => { + const testMatrix = [ + { hasIssues: false, alwaysOpen: false, isCollapsible: false }, + { hasIssues: false, alwaysOpen: true, isCollapsible: false }, + { hasIssues: true, alwaysOpen: false, isCollapsible: true }, + { hasIssues: true, alwaysOpen: true, isCollapsible: false }, + ]; + + testMatrix.forEach(({ hasIssues, alwaysOpen, isCollapsible }) => { + const issues = hasIssues ? 'has issues' : 'has no issues'; + const open = alwaysOpen ? 'is always open' : 'is not always open'; + + it(`is ${isCollapsible}, if the report ${issues} and ${open}`, done => { + vm.hasIssues = hasIssues; + vm.alwaysOpen = alwaysOpen; + + Vue.nextTick() + .then(() => { + expect(vm.isCollapsible).toBe(isCollapsible); + }) + .then(done) + .catch(done.fail); + }); + }); + }); + + describe('isExpanded', () => { + const testMatrix = [ + { isCollapsed: false, alwaysOpen: false, isExpanded: true }, + { isCollapsed: false, alwaysOpen: true, isExpanded: true }, + { isCollapsed: true, alwaysOpen: false, isExpanded: false }, + { isCollapsed: true, alwaysOpen: true, isExpanded: true }, + ]; + + testMatrix.forEach(({ isCollapsed, alwaysOpen, isExpanded }) => { + const issues = isCollapsed ? 'is collapsed' : 'is not collapsed'; + const open = alwaysOpen ? 'is always open' : 'is not always open'; + + it(`is ${isExpanded}, if the report ${issues} and ${open}`, done => { + vm.isCollapsed = isCollapsed; + vm.alwaysOpen = alwaysOpen; + + Vue.nextTick() + .then(() => { + expect(vm.isExpanded).toBe(isExpanded); + }) + .then(done) + .catch(done.fail); + }); + }); + }); + }); + + describe('when it is loading', () => { + it('should render loading indicator', () => { + vm = mountComponent(ReportSection, { + component: '', + status: 'LOADING', + loadingText: 'Loading codeclimate report', + errorText: 'foo', + successText: 'Code quality improved on 1 point and degraded on 1 point', + hasIssues: false, + }); + + expect(vm.$el.textContent.trim()).toEqual('Loading codeclimate report'); + }); + }); + + describe('with success status', () => { + beforeEach(() => { + vm = mountComponent(ReportSection, { + component: '', + status: 'SUCCESS', + loadingText: 'Loading codeclimate report', + errorText: 'foo', + successText: 'Code quality improved on 1 point and degraded on 1 point', + resolvedIssues, + hasIssues: true, + }); + }); + + it('should render provided data', () => { + expect(vm.$el.querySelector('.js-code-text').textContent.trim()).toEqual( + 'Code quality improved on 1 point and degraded on 1 point', + ); + + expect(vm.$el.querySelectorAll('.report-block-container li').length).toEqual( + resolvedIssues.length, + ); + }); + + describe('toggleCollapsed', () => { + const hiddenCss = { display: 'none' }; + + it('toggles issues', done => { + vm.$el.querySelector('button').click(); + + Vue.nextTick() + .then(() => { + expect(vm.$el.querySelector('.js-report-section-container')).not.toHaveCss(hiddenCss); + expect(vm.$el.querySelector('button').textContent.trim()).toEqual('Collapse'); + + vm.$el.querySelector('button').click(); + }) + .then(Vue.nextTick) + .then(() => { + expect(vm.$el.querySelector('.js-report-section-container')).toHaveCss(hiddenCss); + expect(vm.$el.querySelector('button').textContent.trim()).toEqual('Expand'); + }) + .then(done) + .catch(done.fail); + }); + + it('is always expanded, if always-open is set to true', done => { + vm.alwaysOpen = true; + Vue.nextTick() + .then(() => { + expect(vm.$el.querySelector('.js-report-section-container')).not.toHaveCss(hiddenCss); + expect(vm.$el.querySelector('button')).toBeNull(); + }) + .then(done) + .catch(done.fail); + }); + }); + }); + + describe('with failed request', () => { + it('should render error indicator', () => { + vm = mountComponent(ReportSection, { + component: '', + status: 'ERROR', + loadingText: 'Loading codeclimate report', + errorText: 'Failed to load codeclimate report', + successText: 'Code quality improved on 1 point and degraded on 1 point', + hasIssues: false, + }); + + expect(vm.$el.textContent.trim()).toEqual('Failed to load codeclimate report'); + }); + }); + + describe('with action buttons passed to the slot', () => { + beforeEach(() => { + vm = mountComponentWithSlots(ReportSection, { + props: { + status: 'SUCCESS', + successText: 'success', + hasIssues: true, + }, + slots: { + actionButtons: ['Action!'], + }, + }); + }); + + it('should render the passed button', () => { + expect(vm.$el.textContent.trim()).toContain('Action!'); + }); + + it('should still render the expand/collapse button', () => { + expect(vm.$el.querySelector('.js-collapse-btn').textContent.trim()).toEqual('Expand'); + }); + }); +}); diff --git a/spec/frontend/test_setup.js b/spec/frontend/test_setup.js index 1e3c28e25eb..f09bcb5407e 100644 --- a/spec/frontend/test_setup.js +++ b/spec/frontend/test_setup.js @@ -1,4 +1,5 @@ import Vue from 'vue'; +import * as jqueryMatchers from 'custom-jquery-matchers'; import Translate from '~/vue_shared/translate'; import axios from '~/lib/utils/axios_utils'; import { initializeTestTimeout } from './helpers/timeout'; @@ -44,3 +45,10 @@ Object.assign(global, { preloadFixtures() {}, setFixtures: setHTMLFixture, }); + +// custom-jquery-matchers was written for an old Jest version, we need to make it compatible +Object.entries(jqueryMatchers).forEach(([matcherName, matcherFactory]) => { + expect.extend({ + [matcherName]: matcherFactory().compare, + }); +}); diff --git a/spec/javascripts/reports/components/report_section_spec.js b/spec/javascripts/reports/components/report_section_spec.js deleted file mode 100644 index b02af8baaec..00000000000 --- a/spec/javascripts/reports/components/report_section_spec.js +++ /dev/null @@ -1,200 +0,0 @@ -import Vue from 'vue'; -import reportSection from '~/reports/components/report_section.vue'; -import mountComponent, { mountComponentWithSlots } from 'spec/helpers/vue_mount_component_helper'; - -describe('Report section', () => { - let vm; - const ReportSection = Vue.extend(reportSection); - - const resolvedIssues = [ - { - name: 'Insecure Dependency', - fingerprint: 'ca2e59451e98ae60ba2f54e3857c50e5', - path: 'Gemfile.lock', - line: 12, - urlPath: 'foo/Gemfile.lock', - }, - ]; - - afterEach(() => { - vm.$destroy(); - }); - - describe('computed', () => { - beforeEach(() => { - vm = mountComponent(ReportSection, { - component: '', - status: 'SUCCESS', - loadingText: 'Loading codeclimate report', - errorText: 'foo', - successText: 'Code quality improved on 1 point and degraded on 1 point', - resolvedIssues, - hasIssues: false, - alwaysOpen: false, - }); - }); - - describe('isCollapsible', () => { - const testMatrix = [ - { hasIssues: false, alwaysOpen: false, isCollapsible: false }, - { hasIssues: false, alwaysOpen: true, isCollapsible: false }, - { hasIssues: true, alwaysOpen: false, isCollapsible: true }, - { hasIssues: true, alwaysOpen: true, isCollapsible: false }, - ]; - - testMatrix.forEach(({ hasIssues, alwaysOpen, isCollapsible }) => { - const issues = hasIssues ? 'has issues' : 'has no issues'; - const open = alwaysOpen ? 'is always open' : 'is not always open'; - - it(`is ${isCollapsible}, if the report ${issues} and ${open}`, done => { - vm.hasIssues = hasIssues; - vm.alwaysOpen = alwaysOpen; - - Vue.nextTick() - .then(() => { - expect(vm.isCollapsible).toBe(isCollapsible); - }) - .then(done) - .catch(done.fail); - }); - }); - }); - - describe('isExpanded', () => { - const testMatrix = [ - { isCollapsed: false, alwaysOpen: false, isExpanded: true }, - { isCollapsed: false, alwaysOpen: true, isExpanded: true }, - { isCollapsed: true, alwaysOpen: false, isExpanded: false }, - { isCollapsed: true, alwaysOpen: true, isExpanded: true }, - ]; - - testMatrix.forEach(({ isCollapsed, alwaysOpen, isExpanded }) => { - const issues = isCollapsed ? 'is collapsed' : 'is not collapsed'; - const open = alwaysOpen ? 'is always open' : 'is not always open'; - - it(`is ${isExpanded}, if the report ${issues} and ${open}`, done => { - vm.isCollapsed = isCollapsed; - vm.alwaysOpen = alwaysOpen; - - Vue.nextTick() - .then(() => { - expect(vm.isExpanded).toBe(isExpanded); - }) - .then(done) - .catch(done.fail); - }); - }); - }); - }); - - describe('when it is loading', () => { - it('should render loading indicator', () => { - vm = mountComponent(ReportSection, { - component: '', - status: 'LOADING', - loadingText: 'Loading codeclimate report', - errorText: 'foo', - successText: 'Code quality improved on 1 point and degraded on 1 point', - hasIssues: false, - }); - - expect(vm.$el.textContent.trim()).toEqual('Loading codeclimate report'); - }); - }); - - describe('with success status', () => { - beforeEach(() => { - vm = mountComponent(ReportSection, { - component: '', - status: 'SUCCESS', - loadingText: 'Loading codeclimate report', - errorText: 'foo', - successText: 'Code quality improved on 1 point and degraded on 1 point', - resolvedIssues, - hasIssues: true, - }); - }); - - it('should render provided data', () => { - expect(vm.$el.querySelector('.js-code-text').textContent.trim()).toEqual( - 'Code quality improved on 1 point and degraded on 1 point', - ); - - expect(vm.$el.querySelectorAll('.report-block-container li').length).toEqual( - resolvedIssues.length, - ); - }); - - describe('toggleCollapsed', () => { - const hiddenCss = { display: 'none' }; - - it('toggles issues', done => { - vm.$el.querySelector('button').click(); - - Vue.nextTick() - .then(() => { - expect(vm.$el.querySelector('.js-report-section-container')).not.toHaveCss(hiddenCss); - expect(vm.$el.querySelector('button').textContent.trim()).toEqual('Collapse'); - - vm.$el.querySelector('button').click(); - }) - .then(Vue.nextTick) - .then(() => { - expect(vm.$el.querySelector('.js-report-section-container')).toHaveCss(hiddenCss); - expect(vm.$el.querySelector('button').textContent.trim()).toEqual('Expand'); - }) - .then(done) - .catch(done.fail); - }); - - it('is always expanded, if always-open is set to true', done => { - vm.alwaysOpen = true; - Vue.nextTick() - .then(() => { - expect(vm.$el.querySelector('.js-report-section-container')).not.toHaveCss(hiddenCss); - expect(vm.$el.querySelector('button')).toBeNull(); - }) - .then(done) - .catch(done.fail); - }); - }); - }); - - describe('with failed request', () => { - it('should render error indicator', () => { - vm = mountComponent(ReportSection, { - component: '', - status: 'ERROR', - loadingText: 'Loading codeclimate report', - errorText: 'Failed to load codeclimate report', - successText: 'Code quality improved on 1 point and degraded on 1 point', - hasIssues: false, - }); - - expect(vm.$el.textContent.trim()).toEqual('Failed to load codeclimate report'); - }); - }); - - describe('with action buttons passed to the slot', () => { - beforeEach(() => { - vm = mountComponentWithSlots(ReportSection, { - props: { - status: 'SUCCESS', - successText: 'success', - hasIssues: true, - }, - slots: { - actionButtons: ['Action!'], - }, - }); - }); - - it('should render the passed button', () => { - expect(vm.$el.textContent.trim()).toContain('Action!'); - }); - - it('should still render the expand/collapse button', () => { - expect(vm.$el.querySelector('.js-collapse-btn').textContent.trim()).toEqual('Expand'); - }); - }); -}); diff --git a/yarn.lock b/yarn.lock index 29f535830ea..846e29862f1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2742,6 +2742,11 @@ custom-event@~1.0.0: resolved "https://registry.yarnpkg.com/custom-event/-/custom-event-1.0.1.tgz#5d02a46850adf1b4a317946a3928fccb5bfd0425" integrity sha1-XQKkaFCt8bSjF5RqOSj8y1v9BCU= +custom-jquery-matchers@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/custom-jquery-matchers/-/custom-jquery-matchers-2.1.0.tgz#e5988fa9715c416b0986b372563f872d9e91e024" + integrity sha512-f2vQrncnwqbeDne9ag/BRjrmG9BxIEKnZ9Z8TyG5l9B8wwyINWd7LvuHDlTkMPqLTd3ghcvqFoTsxjhOP371JQ== + cyclist@~0.2.2: version "0.2.2" resolved "https://registry.yarnpkg.com/cyclist/-/cyclist-0.2.2.tgz#1b33792e11e914a2fd6d6ed6447464444e5fa640" -- cgit v1.2.1 From c702dbffaa97b6063b654cdba10d97c43e92b473 Mon Sep 17 00:00:00 2001 From: Evan Read Date: Mon, 1 Apr 2019 23:15:46 +0000 Subject: Refactor and fix pipeline schedules --- doc/user/project/pipelines/schedules.md | 121 +++++++++++++++++--------------- 1 file changed, 66 insertions(+), 55 deletions(-) diff --git a/doc/user/project/pipelines/schedules.md b/doc/user/project/pipelines/schedules.md index 2911a56cf67..89f1beb6d1f 100644 --- a/doc/user/project/pipelines/schedules.md +++ b/doc/user/project/pipelines/schedules.md @@ -2,29 +2,33 @@ > **Notes**: > -> - This feature was introduced in 9.1 as [Trigger Schedule][ce-10533]. -> - In 9.2, the feature was [renamed to Pipeline Schedule][ce-10853]. +> - Introduced in GitLab 9.1 as [Trigger Schedule](https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/10533). +> - [Renamed to Pipeline Schedule](https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/10853) in GitLab 9.2. > - Cron notation is parsed by [Fugit](https://github.com/floraison/fugit). -Pipeline schedules can be used to run a pipeline at specific intervals, for example every -month on the 22nd for a certain branch. +Pipelines are normally run based on certain conditions being met. For example, when a branch is pushed to repository. -## Using Pipeline schedules +Pipeline schedules can be used to also run [pipelines](../../../ci/pipelines.md) at specific intervals. For example: -In order to schedule a pipeline: +- Every month on the 22nd for a certain branch. +- Once every day. -1. Navigate to your project's **CI / CD ➔ Schedules** and click the - **New Schedule** button. -1. Fill in the form -1. Hit **Save pipeline schedule** for the changes to take effect. +In addition to using the GitLab UI, pipeline schedules can be maintained using the +[Pipeline schedules API](../../../api/pipeline_schedules.md). + +## Configuring pipeline schedules + +To schedule a pipeline for project: + +1. Navigate to the project's **CI / CD > Schedules** page. +1. Click the **New schedule** button. +1. Fill in the **Schedule a new pipeline** form. +1. Click the **Save pipeline schedule** button. ![New Schedule Form](img/pipeline_schedules_new_form.png) -> **Attention:** -The pipelines won't be executed precisely, because schedules are handled by -Sidekiq, which runs according to its interval. -See [advanced admin configuration](#advanced-admin-configuration) for more -information. +NOTE: **Note:** +Pipelines execution [timing is dependent](#advanced-configuration) on Sidekiq's own schedule. In the **Schedules** index page you can see a list of the pipelines that are scheduled to run. The next run is automatically calculated by the server GitLab @@ -32,36 +36,24 @@ is installed on. ![Schedules list](img/pipeline_schedules_list.png) -### Running a scheduled pipeline manually - -> [Introduced][ce-15700] in GitLab 10.4. - -To trigger a pipeline schedule manually, click the "Play" button: - -![Play Pipeline Schedule](img/pipeline_schedule_play.png) - -This will schedule a background job to run the pipeline schedule. A flash -message will provide a link to the CI/CD Pipeline index page. - -To help avoid abuse, users are rate limited to triggering a pipeline once per -minute. - -### Making use of scheduled pipeline variables +### Using variables -> [Introduced][ce-12328] in GitLab 9.4. +> [Introduced](https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/12328) in GitLab 9.4. You can pass any number of arbitrary variables and they will be available in -GitLab CI so that they can be used in your `.gitlab-ci.yml` file. +GitLab CI so that they can be used in your [`.gitlab-ci.yml` file](../../../ci/yaml/README.md). ![Scheduled pipeline variables](img/pipeline_schedule_variables.png) -## Using only and except +### Using only and except To configure that a job can be executed only when the pipeline has been scheduled (or the opposite), you can use [only and except](../../../ci/yaml/README.md#onlyexcept-basic) configuration keywords. -``` +For example: + +```yaml job:on-schedule: only: - schedules @@ -75,11 +67,47 @@ job: - make build ``` -## Taking ownership +### Advanced configuration + +The pipelines won't be executed exactly on schedule because schedules are handled by +Sidekiq, which runs according to its interval. + +For example, only two pipelines will be created per day if: -Pipelines are executed as a user, who owns a schedule. This influences what -projects and other resources the pipeline has access to. If a user does not own -a pipeline, you can take ownership by clicking the **Take ownership** button. +- You set a schedule to create a pipeline every minute (`* * * * *`). +- The Sidekiq worker runs on 00:00 and 12:00 every day (`0 */12 * * *`). + +To change the Sidekiq worker's frequency: + +1. Edit the `pipeline_schedule_worker_cron` value in your instance's `gitlab.rb` file. +1. [Restart GitLab](../../../administration/restart_gitlab.md). + +For GitLab.com, refer to the [dedicated settings page](../../gitlab_com/index.md#cron-jobs). + +## Working with scheduled pipelines + +Once configured, GitLab supports many functions for working with scheduled pipelines. + +### Running manually + +> [Introduced](https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/15700) in GitLab 10.4. + +To trigger a pipeline schedule manually, click the "Play" button: + +![Play Pipeline Schedule](img/pipeline_schedule_play.png) + +This will schedule a background job to run the pipeline schedule. A flash +message will provide a link to the CI/CD Pipeline index page. + +NOTE: **Note:** +To help avoid abuse, users are rate limited to triggering a pipeline once per +minute. + +### Taking ownership + +Pipelines are executed as a user, who owns a schedule. This influences what projects and other resources the pipeline has access to. + +If a user does not own a pipeline, you can take ownership by clicking the **Take ownership** button. The next time a pipeline is scheduled, your credentials will be used. ![Schedules list](img/pipeline_schedules_ownership.png) @@ -90,20 +118,3 @@ on the target branch, the schedule will stop creating new pipelines. This can happen if, for example, the owner is blocked or removed from the project, or the target branch or tag is protected. In this case, someone with sufficient privileges must take ownership of the schedule. - -## Advanced admin configuration - -The pipelines won't be executed precisely, because schedules are handled by -Sidekiq, which runs according to its interval. For example, if you set a -schedule to create a pipeline every minute (`* * * * *`) and the Sidekiq worker -runs on 00:00 and 12:00 every day (`0 */12 * * *`), only 2 pipelines will be -created per day. To change the Sidekiq worker's frequency, you have to edit the -`pipeline_schedule_worker_cron` value in your `gitlab.rb` and restart GitLab. -For GitLab.com, you can check the [dedicated settings page][settings]. If you -don't have admin access to the server, ask your administrator. - -[ce-10533]: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/10533 -[ce-10853]: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/10853 -[ce-12328]: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/12328 -[ce-15700]: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/15700 -[settings]: https://about.gitlab.com/gitlab-com/settings/#cron-jobs -- cgit v1.2.1 From cfc6d2528cc8d632f16b23334795be537511cfef Mon Sep 17 00:00:00 2001 From: Wei-Meng Lee <1081658-weimeng@users.noreply.gitlab.com> Date: Tue, 2 Apr 2019 00:19:22 +0000 Subject: Fix attempting to drop views in PostgreSQL --- lib/tasks/gitlab/db.rake | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/tasks/gitlab/db.rake b/lib/tasks/gitlab/db.rake index b94b21775ee..4e7a8adbef6 100644 --- a/lib/tasks/gitlab/db.rake +++ b/lib/tasks/gitlab/db.rake @@ -29,7 +29,10 @@ namespace :gitlab do # If MySQL, turn off foreign key checks connection.execute('SET FOREIGN_KEY_CHECKS=0') if Gitlab::Database.mysql? - tables = connection.data_sources + # connection.tables is deprecated in MySQLAdapter, but in PostgreSQLAdapter + # data_sources returns both views and tables, so use #tables instead + tables = Gitlab::Database.mysql? ? connection.data_sources : connection.tables + # Removes the entry from the array tables.delete 'schema_migrations' # Truncate schema_migrations to ensure migrations re-run -- cgit v1.2.1 From f0ee57b9dac16739bbb987090568f8903bad648f Mon Sep 17 00:00:00 2001 From: Marcel Amirault Date: Tue, 2 Apr 2019 02:14:00 +0000 Subject: Docs: Fix anchor to deprecated variables doc --- doc/ci/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/ci/README.md b/doc/ci/README.md index 5fe6c78701c..913e9d4d789 100644 --- a/doc/ci/README.md +++ b/doc/ci/README.md @@ -120,7 +120,7 @@ See also the [Why CI/CD?](https://docs.google.com/presentation/d/1OGgk2Tcxbpl7DJ As GitLab CI/CD has evolved, certain breaking changes have been necessary. These are: -- [CI variables renaming for GitLab 9.0](variables/README.md#gitlab-90-renaming). Read about the +- [CI variables renaming for GitLab 9.0](variables/deprecated_variables.md#gitlab-90-renamed-variables). Read about the deprecated CI variables and what you should use for GitLab 9.0+. - [New CI job permissions model](../user/project/new_ci_build_permissions_model.md). See what changed in GitLab 8.12 and how that affects your jobs. -- cgit v1.2.1 From ec5e032a12acd147708d6ef1a44d82efbc04d2d8 Mon Sep 17 00:00:00 2001 From: Tiger Date: Thu, 28 Mar 2019 15:59:09 +1100 Subject: Split non-security Auto-DevOps jobs into templates This allows these templates to be used outside of Auto DevOps, or easily excluded from Auto DevOps. The security jobs in Auto DevOps differ slightly from the ones that are already available as templates, they will be moved next. --- lib/gitlab/ci/templates/Auto-DevOps.gitlab-ci.yml | 668 +-------------------- .../Jobs/Browser-Performance-Testing.gitlab-ci.yml | 38 ++ lib/gitlab/ci/templates/Jobs/Build.gitlab-ci.yml | 10 + .../ci/templates/Jobs/Code-Quality.gitlab-ci.yml | 27 + lib/gitlab/ci/templates/Jobs/Deploy.gitlab-ci.yml | 574 ++++++++++++++++++ lib/gitlab/ci/templates/Jobs/Test.gitlab-ci.yml | 23 + 6 files changed, 678 insertions(+), 662 deletions(-) create mode 100644 lib/gitlab/ci/templates/Jobs/Browser-Performance-Testing.gitlab-ci.yml create mode 100644 lib/gitlab/ci/templates/Jobs/Build.gitlab-ci.yml create mode 100644 lib/gitlab/ci/templates/Jobs/Code-Quality.gitlab-ci.yml create mode 100644 lib/gitlab/ci/templates/Jobs/Deploy.gitlab-ci.yml create mode 100644 lib/gitlab/ci/templates/Jobs/Test.gitlab-ci.yml diff --git a/lib/gitlab/ci/templates/Auto-DevOps.gitlab-ci.yml b/lib/gitlab/ci/templates/Auto-DevOps.gitlab-ci.yml index 3116f1a136b..e1de3e7c914 100644 --- a/lib/gitlab/ci/templates/Auto-DevOps.gitlab-ci.yml +++ b/lib/gitlab/ci/templates/Auto-DevOps.gitlab-ci.yml @@ -72,52 +72,12 @@ stages: - performance - cleanup -build: - stage: build - image: "registry.gitlab.com/gitlab-org/cluster-integration/auto-build-image/master:stable" - services: - - docker:stable-dind - script: - - /build/build.sh - only: - - branches - - tags - -test: - services: - - postgres:latest - variables: - POSTGRES_DB: test - stage: test - image: gliderlabs/herokuish:latest - script: - - setup_test_db - - cp -R . /tmp/app - - /bin/herokuish buildpack test - only: - - branches - - tags - except: - variables: - - $TEST_DISABLED - -code_quality: - stage: test - image: docker:stable - allow_failure: true - services: - - docker:stable-dind - script: - - setup_docker - - code_quality - artifacts: - paths: [gl-code-quality-report.json] - only: - - branches - - tags - except: - variables: - - $CODE_QUALITY_DISABLED +include: + - template: Jobs/Build.gitlab-ci.yml + - template: Jobs/Test.gitlab-ci.yml + - template: Jobs/Code-Quality.gitlab-ci.yml + - template: Jobs/Deploy.gitlab-ci.yml + - template: Jobs/Browser-Performance-Testing.gitlab-ci.yml license_management: stage: test @@ -139,28 +99,6 @@ license_management: variables: - $LICENSE_MANAGEMENT_DISABLED -performance: - stage: performance - image: docker:stable - allow_failure: true - services: - - docker:stable-dind - script: - - setup_docker - - performance - artifacts: - paths: - - performance.json - - sitespeed-results/ - only: - refs: - - branches - - tags - kubernetes: active - except: - variables: - - $PERFORMANCE_DISABLED - sast: stage: test image: docker:stable @@ -249,249 +187,6 @@ dast: variables: - $DAST_DISABLED -review: - stage: review - script: - - check_kube_domain - - install_dependencies - - download_chart - - ensure_namespace - - initialize_tiller - - create_secret - - deploy - - persist_environment_url - environment: - name: review/$CI_COMMIT_REF_NAME - url: http://$CI_PROJECT_ID-$CI_ENVIRONMENT_SLUG.$KUBE_INGRESS_BASE_DOMAIN - on_stop: stop_review - artifacts: - paths: [environment_url.txt] - only: - refs: - - branches - - tags - kubernetes: active - except: - refs: - - master - variables: - - $REVIEW_DISABLED - -stop_review: - stage: cleanup - variables: - GIT_STRATEGY: none - script: - - install_dependencies - - initialize_tiller - - delete - environment: - name: review/$CI_COMMIT_REF_NAME - action: stop - when: manual - allow_failure: true - only: - refs: - - branches - - tags - kubernetes: active - except: - refs: - - master - variables: - - $REVIEW_DISABLED - -# Staging deploys are disabled by default since -# continuous deployment to production is enabled by default -# If you prefer to automatically deploy to staging and -# only manually promote to production, enable this job by setting -# STAGING_ENABLED. - -staging: - stage: staging - script: - - check_kube_domain - - install_dependencies - - download_chart - - ensure_namespace - - initialize_tiller - - create_secret - - deploy - environment: - name: staging - url: http://$CI_PROJECT_PATH_SLUG-staging.$KUBE_INGRESS_BASE_DOMAIN - only: - refs: - - master - kubernetes: active - variables: - - $STAGING_ENABLED - -# Canaries are also disabled by default, but if you want them, -# and know what the downsides are, you can enable this by setting -# CANARY_ENABLED. - -canary: - stage: canary - script: - - check_kube_domain - - install_dependencies - - download_chart - - ensure_namespace - - initialize_tiller - - create_secret - - deploy canary - environment: - name: production - url: http://$CI_PROJECT_PATH_SLUG.$KUBE_INGRESS_BASE_DOMAIN - when: manual - only: - refs: - - master - kubernetes: active - variables: - - $CANARY_ENABLED - -.production: &production_template - stage: production - script: - - check_kube_domain - - install_dependencies - - download_chart - - ensure_namespace - - initialize_tiller - - create_secret - - deploy - - delete canary - - delete rollout - - persist_environment_url - environment: - name: production - url: http://$CI_PROJECT_PATH_SLUG.$KUBE_INGRESS_BASE_DOMAIN - artifacts: - paths: [environment_url.txt] - -production: - <<: *production_template - only: - refs: - - master - kubernetes: active - except: - variables: - - $STAGING_ENABLED - - $CANARY_ENABLED - - $INCREMENTAL_ROLLOUT_ENABLED - - $INCREMENTAL_ROLLOUT_MODE - -production_manual: - <<: *production_template - when: manual - allow_failure: false - only: - refs: - - master - kubernetes: active - variables: - - $STAGING_ENABLED - - $CANARY_ENABLED - except: - variables: - - $INCREMENTAL_ROLLOUT_ENABLED - - $INCREMENTAL_ROLLOUT_MODE - -# This job implements incremental rollout on for every push to `master`. - -.rollout: &rollout_template - script: - - check_kube_domain - - install_dependencies - - download_chart - - ensure_namespace - - initialize_tiller - - create_secret - - deploy rollout $ROLLOUT_PERCENTAGE - - scale stable $((100-ROLLOUT_PERCENTAGE)) - - delete canary - - persist_environment_url - environment: - name: production - url: http://$CI_PROJECT_PATH_SLUG.$KUBE_INGRESS_BASE_DOMAIN - artifacts: - paths: [environment_url.txt] - -.manual_rollout_template: &manual_rollout_template - <<: *rollout_template - stage: production - when: manual - # This selectors are backward compatible mode with $INCREMENTAL_ROLLOUT_ENABLED (before 11.4) - only: - refs: - - master - kubernetes: active - variables: - - $INCREMENTAL_ROLLOUT_MODE == "manual" - - $INCREMENTAL_ROLLOUT_ENABLED - except: - variables: - - $INCREMENTAL_ROLLOUT_MODE == "timed" - -.timed_rollout_template: &timed_rollout_template - <<: *rollout_template - when: delayed - start_in: 5 minutes - only: - refs: - - master - kubernetes: active - variables: - - $INCREMENTAL_ROLLOUT_MODE == "timed" - -timed rollout 10%: - <<: *timed_rollout_template - stage: incremental rollout 10% - variables: - ROLLOUT_PERCENTAGE: 10 - -timed rollout 25%: - <<: *timed_rollout_template - stage: incremental rollout 25% - variables: - ROLLOUT_PERCENTAGE: 25 - -timed rollout 50%: - <<: *timed_rollout_template - stage: incremental rollout 50% - variables: - ROLLOUT_PERCENTAGE: 50 - -timed rollout 100%: - <<: *timed_rollout_template - <<: *production_template - stage: incremental rollout 100% - variables: - ROLLOUT_PERCENTAGE: 100 - -rollout 10%: - <<: *manual_rollout_template - variables: - ROLLOUT_PERCENTAGE: 10 - -rollout 25%: - <<: *manual_rollout_template - variables: - ROLLOUT_PERCENTAGE: 25 - -rollout 50%: - <<: *manual_rollout_template - variables: - ROLLOUT_PERCENTAGE: 50 - -rollout 100%: - <<: *manual_rollout_template - <<: *production_template - allow_failure: false - # --------------------------------------------------------------------------- .auto_devops: &auto_devops | @@ -535,13 +230,6 @@ rollout 100%: ./clair-scanner -c http://${DOCKER_SERVICE}:6060 --ip $(hostname -i) -r gl-container-scanning-report.json -l clair.log -w clair-whitelist.yml ${CI_APPLICATION_REPOSITORY}:${CI_APPLICATION_TAG} || true } - function code_quality() { - docker run --env SOURCE_CODE="$PWD" \ - --volume "$PWD":/code \ - --volume /var/run/docker.sock:/var/run/docker.sock \ - "registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code - } - function license_management() { /run.sh analyze . } @@ -581,225 +269,6 @@ rollout 100%: esac } - function get_replicas() { - track="${1:-stable}" - percentage="${2:-100}" - - env_track=$( echo $track | tr -s '[:lower:]' '[:upper:]' ) - env_slug=$( echo ${CI_ENVIRONMENT_SLUG//-/_} | tr -s '[:lower:]' '[:upper:]' ) - - if [[ "$track" == "stable" ]] || [[ "$track" == "rollout" ]]; then - # for stable track get number of replicas from `PRODUCTION_REPLICAS` - eval new_replicas=\$${env_slug}_REPLICAS - if [[ -z "$new_replicas" ]]; then - new_replicas=$REPLICAS - fi - else - # for all tracks get number of replicas from `CANARY_PRODUCTION_REPLICAS` - eval new_replicas=\$${env_track}_${env_slug}_REPLICAS - if [[ -z "$new_replicas" ]]; then - eval new_replicas=\${env_track}_REPLICAS - fi - fi - - replicas="${new_replicas:-1}" - replicas="$(($replicas * $percentage / 100))" - - # always return at least one replicas - if [[ $replicas -gt 0 ]]; then - echo "$replicas" - else - echo 1 - fi - } - - # Extracts variables prefixed with K8S_SECRET_ - # and creates a Kubernetes secret. - # - # e.g. If we have the following environment variables: - # K8S_SECRET_A=value1 - # K8S_SECRET_B=multi\ word\ value - # - # Then we will create a secret with the following key-value pairs: - # data: - # A: dmFsdWUxCg== - # B: bXVsdGkgd29yZCB2YWx1ZQo= - function create_application_secret() { - track="${1-stable}" - export APPLICATION_SECRET_NAME=$(application_secret_name "$track") - - env | sed -n "s/^K8S_SECRET_\(.*\)$/\1/p" > k8s_prefixed_variables - - kubectl create secret \ - -n "$KUBE_NAMESPACE" generic "$APPLICATION_SECRET_NAME" \ - --from-env-file k8s_prefixed_variables -o yaml --dry-run | - kubectl replace -n "$KUBE_NAMESPACE" --force -f - - - export APPLICATION_SECRET_CHECKSUM=$(cat k8s_prefixed_variables | sha256sum | cut -d ' ' -f 1) - - rm k8s_prefixed_variables - } - - function deploy_name() { - name="$CI_ENVIRONMENT_SLUG" - track="${1-stable}" - - if [[ "$track" != "stable" ]]; then - name="$name-$track" - fi - - echo $name - } - - function application_secret_name() { - track="${1-stable}" - name=$(deploy_name "$track") - - echo "${name}-secret" - } - - function deploy() { - track="${1-stable}" - percentage="${2:-100}" - name=$(deploy_name "$track") - - replicas="1" - service_enabled="true" - postgres_enabled="$POSTGRES_ENABLED" - - # if track is different than stable, - # re-use all attached resources - if [[ "$track" != "stable" ]]; then - service_enabled="false" - postgres_enabled="false" - fi - - replicas=$(get_replicas "$track" "$percentage") - - if [[ "$CI_PROJECT_VISIBILITY" != "public" ]]; then - secret_name='gitlab-registry' - else - secret_name='' - fi - - create_application_secret "$track" - - env_slug=$(echo ${CI_ENVIRONMENT_SLUG//-/_} | tr -s '[:lower:]' '[:upper:]') - eval env_ADDITIONAL_HOSTS=\$${env_slug}_ADDITIONAL_HOSTS - if [ -n "$env_ADDITIONAL_HOSTS" ]; then - additional_hosts="{$env_ADDITIONAL_HOSTS}" - elif [ -n "$ADDITIONAL_HOSTS" ]; then - additional_hosts="{$ADDITIONAL_HOSTS}" - fi - - if [[ -n "$DB_INITIALIZE" && -z "$(helm ls -q "^$name$")" ]]; then - echo "Deploying first release with database initialization..." - helm upgrade --install \ - --wait \ - --set service.enabled="$service_enabled" \ - --set gitlab.app="$CI_PROJECT_PATH_SLUG" \ - --set gitlab.env="$CI_ENVIRONMENT_SLUG" \ - --set releaseOverride="$CI_ENVIRONMENT_SLUG" \ - --set image.repository="$CI_APPLICATION_REPOSITORY" \ - --set image.tag="$CI_APPLICATION_TAG" \ - --set image.pullPolicy=IfNotPresent \ - --set image.secrets[0].name="$secret_name" \ - --set application.track="$track" \ - --set application.database_url="$DATABASE_URL" \ - --set application.secretName="$APPLICATION_SECRET_NAME" \ - --set application.secretChecksum="$APPLICATION_SECRET_CHECKSUM" \ - --set service.commonName="le.$KUBE_INGRESS_BASE_DOMAIN" \ - --set service.url="$CI_ENVIRONMENT_URL" \ - --set service.additionalHosts="$additional_hosts" \ - --set replicaCount="$replicas" \ - --set postgresql.enabled="$postgres_enabled" \ - --set postgresql.nameOverride="postgres" \ - --set postgresql.postgresUser="$POSTGRES_USER" \ - --set postgresql.postgresPassword="$POSTGRES_PASSWORD" \ - --set postgresql.postgresDatabase="$POSTGRES_DB" \ - --set postgresql.imageTag="$POSTGRES_VERSION" \ - --set application.initializeCommand="$DB_INITIALIZE" \ - --namespace="$KUBE_NAMESPACE" \ - "$name" \ - chart/ - - echo "Deploying second release..." - helm upgrade --reuse-values \ - --wait \ - --set application.initializeCommand="" \ - --set application.migrateCommand="$DB_MIGRATE" \ - --namespace="$KUBE_NAMESPACE" \ - "$name" \ - chart/ - else - echo "Deploying new release..." - helm upgrade --install \ - --wait \ - --set service.enabled="$service_enabled" \ - --set gitlab.app="$CI_PROJECT_PATH_SLUG" \ - --set gitlab.env="$CI_ENVIRONMENT_SLUG" \ - --set releaseOverride="$CI_ENVIRONMENT_SLUG" \ - --set image.repository="$CI_APPLICATION_REPOSITORY" \ - --set image.tag="$CI_APPLICATION_TAG" \ - --set image.pullPolicy=IfNotPresent \ - --set image.secrets[0].name="$secret_name" \ - --set application.track="$track" \ - --set application.database_url="$DATABASE_URL" \ - --set application.secretName="$APPLICATION_SECRET_NAME" \ - --set application.secretChecksum="$APPLICATION_SECRET_CHECKSUM" \ - --set service.commonName="le.$KUBE_INGRESS_BASE_DOMAIN" \ - --set service.url="$CI_ENVIRONMENT_URL" \ - --set service.additionalHosts="$additional_hosts" \ - --set replicaCount="$replicas" \ - --set postgresql.enabled="$postgres_enabled" \ - --set postgresql.nameOverride="postgres" \ - --set postgresql.postgresUser="$POSTGRES_USER" \ - --set postgresql.postgresPassword="$POSTGRES_PASSWORD" \ - --set postgresql.postgresDatabase="$POSTGRES_DB" \ - --set application.migrateCommand="$DB_MIGRATE" \ - --namespace="$KUBE_NAMESPACE" \ - "$name" \ - chart/ - fi - - kubectl rollout status -n "$KUBE_NAMESPACE" -w "$ROLLOUT_RESOURCE_TYPE/$name" - } - - function scale() { - track="${1-stable}" - percentage="${2-100}" - name=$(deploy_name "$track") - - replicas=$(get_replicas "$track" "$percentage") - - if [[ -n "$(helm ls -q "^$name$")" ]]; then - helm upgrade --reuse-values \ - --wait \ - --set replicaCount="$replicas" \ - --namespace="$KUBE_NAMESPACE" \ - "$name" \ - chart/ - fi - } - - function install_dependencies() { - apk add -U openssl curl tar gzip bash ca-certificates git - curl -sSL -o /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub - curl -sSL -O https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.28-r0/glibc-2.28-r0.apk - apk add glibc-2.28-r0.apk - rm glibc-2.28-r0.apk - - curl -sS "https://kubernetes-helm.storage.googleapis.com/helm-v${HELM_VERSION}-linux-amd64.tar.gz" | tar zx - mv linux-amd64/helm /usr/bin/ - mv linux-amd64/tiller /usr/bin/ - helm version --client - tiller -version - - curl -sSL -o /usr/bin/kubectl "https://storage.googleapis.com/kubernetes-release/release/v${KUBERNETES_VERSION}/bin/linux/amd64/kubectl" - chmod +x /usr/bin/kubectl - kubectl version --client - } - # With the Kubernetes executor, 'localhost' must be used instead # https://docs.gitlab.com/runner/executors/kubernetes.html function setup_docker() { @@ -813,96 +282,6 @@ rollout 100%: fi } - function setup_test_db() { - if [ -z ${KUBERNETES_PORT+x} ]; then - DB_HOST=postgres - else - DB_HOST=localhost - fi - export DATABASE_URL="postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${DB_HOST}:5432/${POSTGRES_DB}" - } - - function download_chart() { - if [[ ! -d chart ]]; then - auto_chart=${AUTO_DEVOPS_CHART:-gitlab/auto-deploy-app} - auto_chart_name=$(basename $auto_chart) - auto_chart_name=${auto_chart_name%.tgz} - auto_chart_name=${auto_chart_name%.tar.gz} - else - auto_chart="chart" - auto_chart_name="chart" - fi - - helm init --client-only - helm repo add gitlab ${AUTO_DEVOPS_CHART_REPOSITORY:-https://charts.gitlab.io} - if [[ ! -d "$auto_chart" ]]; then - helm fetch ${auto_chart} --untar - fi - if [ "$auto_chart_name" != "chart" ]; then - mv ${auto_chart_name} chart - fi - - helm dependency update chart/ - helm dependency build chart/ - } - - function ensure_namespace() { - kubectl describe namespace "$KUBE_NAMESPACE" || kubectl create namespace "$KUBE_NAMESPACE" - } - - - # Function to ensure backwards compatibility with AUTO_DEVOPS_DOMAIN - function ensure_kube_ingress_base_domain() { - if [ -z ${KUBE_INGRESS_BASE_DOMAIN+x} ] && [ -n "$AUTO_DEVOPS_DOMAIN" ] ; then - export KUBE_INGRESS_BASE_DOMAIN=$AUTO_DEVOPS_DOMAIN - fi - } - - function check_kube_domain() { - ensure_kube_ingress_base_domain - - if [[ -z "$KUBE_INGRESS_BASE_DOMAIN" ]]; then - echo "In order to deploy or use Review Apps," - echo "AUTO_DEVOPS_DOMAIN or KUBE_INGRESS_BASE_DOMAIN variables must be set" - echo "From 11.8, you can set KUBE_INGRESS_BASE_DOMAIN in cluster settings" - echo "or by defining a variable at group or project level." - echo "You can also manually add it in .gitlab-ci.yml" - echo "AUTO_DEVOPS_DOMAIN support will be dropped on 12.0" - false - else - true - fi - } - - function initialize_tiller() { - echo "Checking Tiller..." - - export HELM_HOST="localhost:44134" - tiller -listen ${HELM_HOST} -alsologtostderr > /dev/null 2>&1 & - echo "Tiller is listening on ${HELM_HOST}" - - if ! helm version --debug; then - echo "Failed to init Tiller." - return 1 - fi - echo "" - } - - function create_secret() { - echo "Create secret..." - if [[ "$CI_PROJECT_VISIBILITY" == "public" ]]; then - return - fi - - kubectl create secret -n "$KUBE_NAMESPACE" \ - docker-registry gitlab-registry \ - --docker-server="$CI_REGISTRY" \ - --docker-username="${CI_DEPLOY_USER:-$CI_REGISTRY_USER}" \ - --docker-password="${CI_DEPLOY_PASSWORD:-$CI_REGISTRY_PASSWORD}" \ - --docker-email="$GITLAB_USER_EMAIL" \ - -o yaml --dry-run | kubectl replace -n "$KUBE_NAMESPACE" --force -f - - } - function dast() { export CI_ENVIRONMENT_URL=$(cat environment_url.txt) @@ -911,40 +290,5 @@ rollout 100%: cp /zap/wrk/gl-dast-report.json . } - function performance() { - export CI_ENVIRONMENT_URL=$(cat environment_url.txt) - - mkdir gitlab-exporter - wget -O gitlab-exporter/index.js https://gitlab.com/gitlab-org/gl-performance/raw/10-5/index.js - - mkdir sitespeed-results - - if [ -f .gitlab-urls.txt ] - then - sed -i -e 's@^@'"$CI_ENVIRONMENT_URL"'@' .gitlab-urls.txt - docker run --shm-size=1g --rm -v "$(pwd)":/sitespeed.io sitespeedio/sitespeed.io:6.3.1 --plugins.add ./gitlab-exporter --outputFolder sitespeed-results .gitlab-urls.txt - else - docker run --shm-size=1g --rm -v "$(pwd)":/sitespeed.io sitespeedio/sitespeed.io:6.3.1 --plugins.add ./gitlab-exporter --outputFolder sitespeed-results "$CI_ENVIRONMENT_URL" - fi - - mv sitespeed-results/data/performance.json performance.json - } - - function persist_environment_url() { - echo $CI_ENVIRONMENT_URL > environment_url.txt - } - - function delete() { - track="${1-stable}" - name=$(deploy_name "$track") - - if [[ -n "$(helm ls -q "^$name$")" ]]; then - helm delete --purge "$name" - fi - - secret_name=$(application_secret_name "$track") - kubectl delete secret --ignore-not-found -n "$KUBE_NAMESPACE" "$secret_name" - } - before_script: - *auto_devops diff --git a/lib/gitlab/ci/templates/Jobs/Browser-Performance-Testing.gitlab-ci.yml b/lib/gitlab/ci/templates/Jobs/Browser-Performance-Testing.gitlab-ci.yml new file mode 100644 index 00000000000..546c4affb4e --- /dev/null +++ b/lib/gitlab/ci/templates/Jobs/Browser-Performance-Testing.gitlab-ci.yml @@ -0,0 +1,38 @@ +performance: + stage: performance + image: docker:stable + allow_failure: true + services: + - docker:stable-dind + script: + - | + if ! docker info &>/dev/null; then + if [ -z "$DOCKER_HOST" -a "$KUBERNETES_PORT" ]; then + export DOCKER_HOST='tcp://localhost:2375' + fi + fi + - export CI_ENVIRONMENT_URL=$(cat environment_url.txt) + - mkdir gitlab-exporter + - wget -O gitlab-exporter/index.js https://gitlab.com/gitlab-org/gl-performance/raw/10-5/index.js + - mkdir sitespeed-results + - | + if [ -f .gitlab-urls.txt ] + then + sed -i -e 's@^@'"$CI_ENVIRONMENT_URL"'@' .gitlab-urls.txt + docker run --shm-size=1g --rm -v "$(pwd)":/sitespeed.io sitespeedio/sitespeed.io:6.3.1 --plugins.add ./gitlab-exporter --outputFolder sitespeed-results .gitlab-urls.txt + else + docker run --shm-size=1g --rm -v "$(pwd)":/sitespeed.io sitespeedio/sitespeed.io:6.3.1 --plugins.add ./gitlab-exporter --outputFolder sitespeed-results "$CI_ENVIRONMENT_URL" + fi + - mv sitespeed-results/data/performance.json performance.json + artifacts: + paths: + - performance.json + - sitespeed-results/ + only: + refs: + - branches + - tags + kubernetes: active + except: + variables: + - $PERFORMANCE_DISABLED diff --git a/lib/gitlab/ci/templates/Jobs/Build.gitlab-ci.yml b/lib/gitlab/ci/templates/Jobs/Build.gitlab-ci.yml new file mode 100644 index 00000000000..121ae38216f --- /dev/null +++ b/lib/gitlab/ci/templates/Jobs/Build.gitlab-ci.yml @@ -0,0 +1,10 @@ +build: + stage: build + image: "registry.gitlab.com/gitlab-org/cluster-integration/auto-build-image/master:stable" + services: + - docker:stable-dind + script: + - /build/build.sh + only: + - branches + - tags diff --git a/lib/gitlab/ci/templates/Jobs/Code-Quality.gitlab-ci.yml b/lib/gitlab/ci/templates/Jobs/Code-Quality.gitlab-ci.yml new file mode 100644 index 00000000000..b09a24d8e22 --- /dev/null +++ b/lib/gitlab/ci/templates/Jobs/Code-Quality.gitlab-ci.yml @@ -0,0 +1,27 @@ +code_quality: + stage: test + image: docker:stable + allow_failure: true + services: + - docker:stable-dind + script: + - export CQ_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/') + - | + if ! docker info &>/dev/null; then + if [ -z "$DOCKER_HOST" -a "$KUBERNETES_PORT" ]; then + export DOCKER_HOST='tcp://localhost:2375' + fi + fi + - | + docker run --env SOURCE_CODE="$PWD" \ + --volume "$PWD":/code \ + --volume /var/run/docker.sock:/var/run/docker.sock \ + "registry.gitlab.com/gitlab-org/security-products/codequality:$CQ_VERSION" /code + artifacts: + paths: [gl-code-quality-report.json] + only: + - branches + - tags + except: + variables: + - $CODE_QUALITY_DISABLED diff --git a/lib/gitlab/ci/templates/Jobs/Deploy.gitlab-ci.yml b/lib/gitlab/ci/templates/Jobs/Deploy.gitlab-ci.yml new file mode 100644 index 00000000000..2f6b73910d5 --- /dev/null +++ b/lib/gitlab/ci/templates/Jobs/Deploy.gitlab-ci.yml @@ -0,0 +1,574 @@ +review: + stage: review + script: + - check_kube_domain + - install_dependencies + - download_chart + - ensure_namespace + - initialize_tiller + - create_secret + - deploy + - persist_environment_url + environment: + name: review/$CI_COMMIT_REF_NAME + url: http://$CI_PROJECT_ID-$CI_ENVIRONMENT_SLUG.$KUBE_INGRESS_BASE_DOMAIN + on_stop: stop_review + artifacts: + paths: [environment_url.txt] + only: + refs: + - branches + - tags + kubernetes: active + except: + refs: + - master + variables: + - $REVIEW_DISABLED + +stop_review: + stage: cleanup + variables: + GIT_STRATEGY: none + script: + - install_dependencies + - initialize_tiller + - delete + environment: + name: review/$CI_COMMIT_REF_NAME + action: stop + when: manual + allow_failure: true + only: + refs: + - branches + - tags + kubernetes: active + except: + refs: + - master + variables: + - $REVIEW_DISABLED + +# Staging deploys are disabled by default since +# continuous deployment to production is enabled by default +# If you prefer to automatically deploy to staging and +# only manually promote to production, enable this job by setting +# STAGING_ENABLED. + +staging: + stage: staging + script: + - check_kube_domain + - install_dependencies + - download_chart + - ensure_namespace + - initialize_tiller + - create_secret + - deploy + environment: + name: staging + url: http://$CI_PROJECT_PATH_SLUG-staging.$KUBE_INGRESS_BASE_DOMAIN + only: + refs: + - master + kubernetes: active + variables: + - $STAGING_ENABLED + +# Canaries are disabled by default, but if you want them, +# and know what the downsides are, you can enable this by setting +# CANARY_ENABLED. + +canary: + stage: canary + script: + - check_kube_domain + - install_dependencies + - download_chart + - ensure_namespace + - initialize_tiller + - create_secret + - deploy canary + environment: + name: production + url: http://$CI_PROJECT_PATH_SLUG.$KUBE_INGRESS_BASE_DOMAIN + when: manual + only: + refs: + - master + kubernetes: active + variables: + - $CANARY_ENABLED + +.production: &production_template + stage: production + script: + - check_kube_domain + - install_dependencies + - download_chart + - ensure_namespace + - initialize_tiller + - create_secret + - deploy + - delete canary + - delete rollout + - persist_environment_url + environment: + name: production + url: http://$CI_PROJECT_PATH_SLUG.$KUBE_INGRESS_BASE_DOMAIN + artifacts: + paths: [environment_url.txt] + +production: + <<: *production_template + only: + refs: + - master + kubernetes: active + except: + variables: + - $STAGING_ENABLED + - $CANARY_ENABLED + - $INCREMENTAL_ROLLOUT_ENABLED + - $INCREMENTAL_ROLLOUT_MODE + +production_manual: + <<: *production_template + when: manual + allow_failure: false + only: + refs: + - master + kubernetes: active + variables: + - $STAGING_ENABLED + - $CANARY_ENABLED + except: + variables: + - $INCREMENTAL_ROLLOUT_ENABLED + - $INCREMENTAL_ROLLOUT_MODE + +# This job implements incremental rollout on for every push to `master`. + +.rollout: &rollout_template + script: + - check_kube_domain + - install_dependencies + - download_chart + - ensure_namespace + - initialize_tiller + - create_secret + - deploy rollout $ROLLOUT_PERCENTAGE + - scale stable $((100-ROLLOUT_PERCENTAGE)) + - delete canary + - persist_environment_url + environment: + name: production + url: http://$CI_PROJECT_PATH_SLUG.$KUBE_INGRESS_BASE_DOMAIN + artifacts: + paths: [environment_url.txt] + +.manual_rollout_template: &manual_rollout_template + <<: *rollout_template + stage: production + when: manual + # This selectors are backward compatible mode with $INCREMENTAL_ROLLOUT_ENABLED (before 11.4) + only: + refs: + - master + kubernetes: active + variables: + - $INCREMENTAL_ROLLOUT_MODE == "manual" + - $INCREMENTAL_ROLLOUT_ENABLED + except: + variables: + - $INCREMENTAL_ROLLOUT_MODE == "timed" + +.timed_rollout_template: &timed_rollout_template + <<: *rollout_template + when: delayed + start_in: 5 minutes + only: + refs: + - master + kubernetes: active + variables: + - $INCREMENTAL_ROLLOUT_MODE == "timed" + +timed rollout 10%: + <<: *timed_rollout_template + stage: incremental rollout 10% + variables: + ROLLOUT_PERCENTAGE: 10 + +timed rollout 25%: + <<: *timed_rollout_template + stage: incremental rollout 25% + variables: + ROLLOUT_PERCENTAGE: 25 + +timed rollout 50%: + <<: *timed_rollout_template + stage: incremental rollout 50% + variables: + ROLLOUT_PERCENTAGE: 50 + +timed rollout 100%: + <<: *timed_rollout_template + <<: *production_template + stage: incremental rollout 100% + variables: + ROLLOUT_PERCENTAGE: 100 + +rollout 10%: + <<: *manual_rollout_template + variables: + ROLLOUT_PERCENTAGE: 10 + +rollout 25%: + <<: *manual_rollout_template + variables: + ROLLOUT_PERCENTAGE: 25 + +rollout 50%: + <<: *manual_rollout_template + variables: + ROLLOUT_PERCENTAGE: 50 + +rollout 100%: + <<: *manual_rollout_template + <<: *production_template + allow_failure: false + +.deploy_helpers: &deploy_helpers | + [[ "$TRACE" ]] && set -x + auto_database_url=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${CI_ENVIRONMENT_SLUG}-postgres:5432/${POSTGRES_DB} + export DATABASE_URL=${DATABASE_URL-$auto_database_url} + if [[ -z "$CI_COMMIT_TAG" ]]; then + export CI_APPLICATION_REPOSITORY=$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG + export CI_APPLICATION_TAG=$CI_COMMIT_SHA + else + export CI_APPLICATION_REPOSITORY=$CI_REGISTRY_IMAGE + export CI_APPLICATION_TAG=$CI_COMMIT_TAG + fi + export TILLER_NAMESPACE=$KUBE_NAMESPACE + # Extract "MAJOR.MINOR" from CI_SERVER_VERSION and generate "MAJOR-MINOR-stable" for Security Products + + function get_replicas() { + track="${1:-stable}" + percentage="${2:-100}" + + env_track=$( echo $track | tr -s '[:lower:]' '[:upper:]' ) + env_slug=$( echo ${CI_ENVIRONMENT_SLUG//-/_} | tr -s '[:lower:]' '[:upper:]' ) + + if [[ "$track" == "stable" ]] || [[ "$track" == "rollout" ]]; then + # for stable track get number of replicas from `PRODUCTION_REPLICAS` + eval new_replicas=\$${env_slug}_REPLICAS + if [[ -z "$new_replicas" ]]; then + new_replicas=$REPLICAS + fi + else + # for all tracks get number of replicas from `CANARY_PRODUCTION_REPLICAS` + eval new_replicas=\$${env_track}_${env_slug}_REPLICAS + if [[ -z "$new_replicas" ]]; then + eval new_replicas=\${env_track}_REPLICAS + fi + fi + + replicas="${new_replicas:-1}" + replicas="$(($replicas * $percentage / 100))" + + # always return at least one replicas + if [[ $replicas -gt 0 ]]; then + echo "$replicas" + else + echo 1 + fi + } + + # Extracts variables prefixed with K8S_SECRET_ + # and creates a Kubernetes secret. + # + # e.g. If we have the following environment variables: + # K8S_SECRET_A=value1 + # K8S_SECRET_B=multi\ word\ value + # + # Then we will create a secret with the following key-value pairs: + # data: + # A: dmFsdWUxCg== + # B: bXVsdGkgd29yZCB2YWx1ZQo= + function create_application_secret() { + track="${1-stable}" + export APPLICATION_SECRET_NAME=$(application_secret_name "$track") + + env | sed -n "s/^K8S_SECRET_\(.*\)$/\1/p" > k8s_prefixed_variables + + kubectl create secret \ + -n "$KUBE_NAMESPACE" generic "$APPLICATION_SECRET_NAME" \ + --from-env-file k8s_prefixed_variables -o yaml --dry-run | + kubectl replace -n "$KUBE_NAMESPACE" --force -f - + + export APPLICATION_SECRET_CHECKSUM=$(cat k8s_prefixed_variables | sha256sum | cut -d ' ' -f 1) + + rm k8s_prefixed_variables + } + + function deploy_name() { + name="$CI_ENVIRONMENT_SLUG" + track="${1-stable}" + + if [[ "$track" != "stable" ]]; then + name="$name-$track" + fi + + echo $name + } + + function application_secret_name() { + track="${1-stable}" + name=$(deploy_name "$track") + + echo "${name}-secret" + } + + function deploy() { + track="${1-stable}" + percentage="${2:-100}" + name=$(deploy_name "$track") + + replicas="1" + service_enabled="true" + postgres_enabled="$POSTGRES_ENABLED" + + # if track is different than stable, + # re-use all attached resources + if [[ "$track" != "stable" ]]; then + service_enabled="false" + postgres_enabled="false" + fi + + replicas=$(get_replicas "$track" "$percentage") + + if [[ "$CI_PROJECT_VISIBILITY" != "public" ]]; then + secret_name='gitlab-registry' + else + secret_name='' + fi + + create_application_secret "$track" + + env_slug=$(echo ${CI_ENVIRONMENT_SLUG//-/_} | tr -s '[:lower:]' '[:upper:]') + eval env_ADDITIONAL_HOSTS=\$${env_slug}_ADDITIONAL_HOSTS + if [ -n "$env_ADDITIONAL_HOSTS" ]; then + additional_hosts="{$env_ADDITIONAL_HOSTS}" + elif [ -n "$ADDITIONAL_HOSTS" ]; then + additional_hosts="{$ADDITIONAL_HOSTS}" + fi + + if [[ -n "$DB_INITIALIZE" && -z "$(helm ls -q "^$name$")" ]]; then + echo "Deploying first release with database initialization..." + helm upgrade --install \ + --wait \ + --set service.enabled="$service_enabled" \ + --set gitlab.app="$CI_PROJECT_PATH_SLUG" \ + --set gitlab.env="$CI_ENVIRONMENT_SLUG" \ + --set releaseOverride="$CI_ENVIRONMENT_SLUG" \ + --set image.repository="$CI_APPLICATION_REPOSITORY" \ + --set image.tag="$CI_APPLICATION_TAG" \ + --set image.pullPolicy=IfNotPresent \ + --set image.secrets[0].name="$secret_name" \ + --set application.track="$track" \ + --set application.database_url="$DATABASE_URL" \ + --set application.secretName="$APPLICATION_SECRET_NAME" \ + --set application.secretChecksum="$APPLICATION_SECRET_CHECKSUM" \ + --set service.commonName="le.$KUBE_INGRESS_BASE_DOMAIN" \ + --set service.url="$CI_ENVIRONMENT_URL" \ + --set service.additionalHosts="$additional_hosts" \ + --set replicaCount="$replicas" \ + --set postgresql.enabled="$postgres_enabled" \ + --set postgresql.nameOverride="postgres" \ + --set postgresql.postgresUser="$POSTGRES_USER" \ + --set postgresql.postgresPassword="$POSTGRES_PASSWORD" \ + --set postgresql.postgresDatabase="$POSTGRES_DB" \ + --set postgresql.imageTag="$POSTGRES_VERSION" \ + --set application.initializeCommand="$DB_INITIALIZE" \ + --namespace="$KUBE_NAMESPACE" \ + "$name" \ + chart/ + + echo "Deploying second release..." + helm upgrade --reuse-values \ + --wait \ + --set application.initializeCommand="" \ + --set application.migrateCommand="$DB_MIGRATE" \ + --namespace="$KUBE_NAMESPACE" \ + "$name" \ + chart/ + else + echo "Deploying new release..." + helm upgrade --install \ + --wait \ + --set service.enabled="$service_enabled" \ + --set gitlab.app="$CI_PROJECT_PATH_SLUG" \ + --set gitlab.env="$CI_ENVIRONMENT_SLUG" \ + --set releaseOverride="$CI_ENVIRONMENT_SLUG" \ + --set image.repository="$CI_APPLICATION_REPOSITORY" \ + --set image.tag="$CI_APPLICATION_TAG" \ + --set image.pullPolicy=IfNotPresent \ + --set image.secrets[0].name="$secret_name" \ + --set application.track="$track" \ + --set application.database_url="$DATABASE_URL" \ + --set application.secretName="$APPLICATION_SECRET_NAME" \ + --set application.secretChecksum="$APPLICATION_SECRET_CHECKSUM" \ + --set service.commonName="le.$KUBE_INGRESS_BASE_DOMAIN" \ + --set service.url="$CI_ENVIRONMENT_URL" \ + --set service.additionalHosts="$additional_hosts" \ + --set replicaCount="$replicas" \ + --set postgresql.enabled="$postgres_enabled" \ + --set postgresql.nameOverride="postgres" \ + --set postgresql.postgresUser="$POSTGRES_USER" \ + --set postgresql.postgresPassword="$POSTGRES_PASSWORD" \ + --set postgresql.postgresDatabase="$POSTGRES_DB" \ + --set application.migrateCommand="$DB_MIGRATE" \ + --namespace="$KUBE_NAMESPACE" \ + "$name" \ + chart/ + fi + + kubectl rollout status -n "$KUBE_NAMESPACE" -w "$ROLLOUT_RESOURCE_TYPE/$name" + } + + function scale() { + track="${1-stable}" + percentage="${2-100}" + name=$(deploy_name "$track") + + replicas=$(get_replicas "$track" "$percentage") + + if [[ -n "$(helm ls -q "^$name$")" ]]; then + helm upgrade --reuse-values \ + --wait \ + --set replicaCount="$replicas" \ + --namespace="$KUBE_NAMESPACE" \ + "$name" \ + chart/ + fi + } + + function install_dependencies() { + apk add -U openssl curl tar gzip bash ca-certificates git + curl -sSL -o /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub + curl -sSL -O https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.28-r0/glibc-2.28-r0.apk + apk add glibc-2.28-r0.apk + rm glibc-2.28-r0.apk + + curl -sS "https://kubernetes-helm.storage.googleapis.com/helm-v${HELM_VERSION}-linux-amd64.tar.gz" | tar zx + mv linux-amd64/helm /usr/bin/ + mv linux-amd64/tiller /usr/bin/ + helm version --client + tiller -version + + curl -sSL -o /usr/bin/kubectl "https://storage.googleapis.com/kubernetes-release/release/v${KUBERNETES_VERSION}/bin/linux/amd64/kubectl" + chmod +x /usr/bin/kubectl + kubectl version --client + } + + function download_chart() { + if [[ ! -d chart ]]; then + auto_chart=${AUTO_DEVOPS_CHART:-gitlab/auto-deploy-app} + auto_chart_name=$(basename $auto_chart) + auto_chart_name=${auto_chart_name%.tgz} + auto_chart_name=${auto_chart_name%.tar.gz} + else + auto_chart="chart" + auto_chart_name="chart" + fi + + helm init --client-only + helm repo add gitlab ${AUTO_DEVOPS_CHART_REPOSITORY:-https://charts.gitlab.io} + if [[ ! -d "$auto_chart" ]]; then + helm fetch ${auto_chart} --untar + fi + if [ "$auto_chart_name" != "chart" ]; then + mv ${auto_chart_name} chart + fi + + helm dependency update chart/ + helm dependency build chart/ + } + + function ensure_namespace() { + kubectl describe namespace "$KUBE_NAMESPACE" || kubectl create namespace "$KUBE_NAMESPACE" + } + + # Function to ensure backwards compatibility with AUTO_DEVOPS_DOMAIN + function ensure_kube_ingress_base_domain() { + if [ -z ${KUBE_INGRESS_BASE_DOMAIN+x} ] && [ -n "$AUTO_DEVOPS_DOMAIN" ] ; then + export KUBE_INGRESS_BASE_DOMAIN=$AUTO_DEVOPS_DOMAIN + fi + } + + function check_kube_domain() { + ensure_kube_ingress_base_domain + + if [[ -z "$KUBE_INGRESS_BASE_DOMAIN" ]]; then + echo "In order to deploy or use Review Apps," + echo "AUTO_DEVOPS_DOMAIN or KUBE_INGRESS_BASE_DOMAIN variables must be set" + echo "From 11.8, you can set KUBE_INGRESS_BASE_DOMAIN in cluster settings" + echo "or by defining a variable at group or project level." + echo "You can also manually add it in .gitlab-ci.yml" + echo "AUTO_DEVOPS_DOMAIN support will be dropped on 12.0" + false + else + true + fi + } + + function initialize_tiller() { + echo "Checking Tiller..." + + export HELM_HOST="localhost:44134" + tiller -listen ${HELM_HOST} -alsologtostderr > /dev/null 2>&1 & + echo "Tiller is listening on ${HELM_HOST}" + + if ! helm version --debug; then + echo "Failed to init Tiller." + return 1 + fi + echo "" + } + + function create_secret() { + echo "Create secret..." + if [[ "$CI_PROJECT_VISIBILITY" == "public" ]]; then + return + fi + + kubectl create secret -n "$KUBE_NAMESPACE" \ + docker-registry gitlab-registry \ + --docker-server="$CI_REGISTRY" \ + --docker-username="${CI_DEPLOY_USER:-$CI_REGISTRY_USER}" \ + --docker-password="${CI_DEPLOY_PASSWORD:-$CI_REGISTRY_PASSWORD}" \ + --docker-email="$GITLAB_USER_EMAIL" \ + -o yaml --dry-run | kubectl replace -n "$KUBE_NAMESPACE" --force -f - + } + + function persist_environment_url() { + echo $CI_ENVIRONMENT_URL > environment_url.txt + } + + function delete() { + track="${1-stable}" + name=$(deploy_name "$track") + + if [[ -n "$(helm ls -q "^$name$")" ]]; then + helm delete --purge "$name" + fi + + secret_name=$(application_secret_name "$track") + kubectl delete secret --ignore-not-found -n "$KUBE_NAMESPACE" "$secret_name" + } + +before_script: + - *deploy_helpers diff --git a/lib/gitlab/ci/templates/Jobs/Test.gitlab-ci.yml b/lib/gitlab/ci/templates/Jobs/Test.gitlab-ci.yml new file mode 100644 index 00000000000..b9fe838d1da --- /dev/null +++ b/lib/gitlab/ci/templates/Jobs/Test.gitlab-ci.yml @@ -0,0 +1,23 @@ +test: + services: + - postgres:latest + variables: + POSTGRES_DB: test + stage: test + image: gliderlabs/herokuish:latest + script: + - | + if [ -z ${KUBERNETES_PORT+x} ]; then + DB_HOST=postgres + else + DB_HOST=localhost + fi + - export DATABASE_URL="postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${DB_HOST}:5432/${POSTGRES_DB}" + - cp -R . /tmp/app + - /bin/herokuish buildpack test + only: + - branches + - tags + except: + variables: + - $TEST_DISABLED -- cgit v1.2.1 From 3be46bdf086c4b11ec8c5eccae8d1c345127f2fc Mon Sep 17 00:00:00 2001 From: Tiger Date: Fri, 29 Mar 2019 10:42:19 +1100 Subject: Split Security Auto DevOps jobs into templates Container Scanning, Dependency Scanning, License Management and SAST parts of Auto DevOps now use the preexisting templates. Auto DevOps and the DAST job template will now use a shared job template instead of maintaining two copies of the job. This also allows Auto DevOps to use custom authentication with DAST. --- lib/gitlab/ci/templates/Auto-DevOps.gitlab-ci.yml | 219 +-------------------- lib/gitlab/ci/templates/Jobs/DAST.gitlab-ci.yml | 54 +++++ .../Security/Container-Scanning.gitlab-ci.yml | 7 +- .../ci/templates/Security/DAST.gitlab-ci.yml | 41 +--- .../Security/Dependency-Scanning.gitlab-ci.yml | 6 + .../ci/templates/Security/SAST.gitlab-ci.yml | 6 + spec/lib/gitlab/ci/templates/templates_spec.rb | 6 +- 7 files changed, 86 insertions(+), 253 deletions(-) create mode 100644 lib/gitlab/ci/templates/Jobs/DAST.gitlab-ci.yml diff --git a/lib/gitlab/ci/templates/Auto-DevOps.gitlab-ci.yml b/lib/gitlab/ci/templates/Auto-DevOps.gitlab-ci.yml index e1de3e7c914..f2ee4a30f07 100644 --- a/lib/gitlab/ci/templates/Auto-DevOps.gitlab-ci.yml +++ b/lib/gitlab/ci/templates/Auto-DevOps.gitlab-ci.yml @@ -78,217 +78,8 @@ include: - template: Jobs/Code-Quality.gitlab-ci.yml - template: Jobs/Deploy.gitlab-ci.yml - template: Jobs/Browser-Performance-Testing.gitlab-ci.yml - -license_management: - stage: test - image: - name: "registry.gitlab.com/gitlab-org/security-products/license-management:$CI_SERVER_VERSION_MAJOR-$CI_SERVER_VERSION_MINOR-stable" - entrypoint: [""] - allow_failure: true - script: - - license_management - artifacts: - paths: [gl-license-management-report.json] - only: - refs: - - branches - - tags - variables: - - $GITLAB_FEATURES =~ /\blicense_management\b/ - except: - variables: - - $LICENSE_MANAGEMENT_DISABLED - -sast: - stage: test - image: docker:stable - allow_failure: true - services: - - docker:stable-dind - script: - - setup_docker - - sast - artifacts: - reports: - sast: gl-sast-report.json - only: - refs: - - branches - - tags - variables: - - $GITLAB_FEATURES =~ /\bsast\b/ - except: - variables: - - $SAST_DISABLED - -dependency_scanning: - stage: test - image: docker:stable - allow_failure: true - services: - - docker:stable-dind - script: - - setup_docker - - dependency_scanning - artifacts: - reports: - dependency_scanning: gl-dependency-scanning-report.json - only: - refs: - - branches - - tags - variables: - - $GITLAB_FEATURES =~ /\bdependency_scanning\b/ - except: - variables: - - $DEPENDENCY_SCANNING_DISABLED - -container_scanning: - stage: test - image: docker:stable - allow_failure: true - services: - - docker:stable-dind - script: - - setup_docker - - container_scanning - artifacts: - paths: [gl-container-scanning-report.json] - only: - refs: - - branches - - tags - variables: - - $GITLAB_FEATURES =~ /\bcontainer_scanning\b/ - except: - variables: - - $CONTAINER_SCANNING_DISABLED - -dast: - stage: dast - allow_failure: true - image: registry.gitlab.com/gitlab-org/security-products/zaproxy - variables: - POSTGRES_DB: "false" - script: - - dast - artifacts: - paths: [gl-dast-report.json] - only: - refs: - - branches - - tags - kubernetes: active - variables: - - $GITLAB_FEATURES =~ /\bdast\b/ - except: - refs: - - master - variables: - - $DAST_DISABLED - -# --------------------------------------------------------------------------- - -.auto_devops: &auto_devops | - # Auto DevOps variables and functions - [[ "$TRACE" ]] && set -x - auto_database_url=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${CI_ENVIRONMENT_SLUG}-postgres:5432/${POSTGRES_DB} - export DATABASE_URL=${DATABASE_URL-$auto_database_url} - if [[ -z "$CI_COMMIT_TAG" ]]; then - export CI_APPLICATION_REPOSITORY=$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG - export CI_APPLICATION_TAG=$CI_COMMIT_SHA - else - export CI_APPLICATION_REPOSITORY=$CI_REGISTRY_IMAGE - export CI_APPLICATION_TAG=$CI_COMMIT_TAG - fi - export TILLER_NAMESPACE=$KUBE_NAMESPACE - # Extract "MAJOR.MINOR" from CI_SERVER_VERSION and generate "MAJOR-MINOR-stable" for Security Products - export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/') - - function registry_login() { - if [[ -n "$CI_REGISTRY_USER" ]]; then - echo "Logging to GitLab Container Registry with CI credentials..." - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" "$CI_REGISTRY" - echo "" - fi - } - - function container_scanning() { - registry_login - - docker run -d --name db arminc/clair-db:latest - docker run -p 6060:6060 --link db:postgres -d --name clair --restart on-failure arminc/clair-local-scan:v2.0.6 - apk add -U wget ca-certificates - docker pull ${CI_APPLICATION_REPOSITORY}:${CI_APPLICATION_TAG} - wget https://github.com/arminc/clair-scanner/releases/download/v8/clair-scanner_linux_amd64 - mv clair-scanner_linux_amd64 clair-scanner - chmod +x clair-scanner - touch clair-whitelist.yml - retries=0 - echo "Waiting for clair daemon to start" - while( ! wget -T 10 -q -O /dev/null http://${DOCKER_SERVICE}:6060/v1/namespaces ) ; do sleep 1 ; echo -n "." ; if [ $retries -eq 10 ] ; then echo " Timeout, aborting." ; exit 1 ; fi ; retries=$(($retries+1)) ; done - ./clair-scanner -c http://${DOCKER_SERVICE}:6060 --ip $(hostname -i) -r gl-container-scanning-report.json -l clair.log -w clair-whitelist.yml ${CI_APPLICATION_REPOSITORY}:${CI_APPLICATION_TAG} || true - } - - function license_management() { - /run.sh analyze . - } - - function sast() { - case "$CI_SERVER_VERSION" in - *-ee) - - # Deprecation notice for CONFIDENCE_LEVEL variable - if [ -z "$SAST_CONFIDENCE_LEVEL" -a "$CONFIDENCE_LEVEL" ]; then - SAST_CONFIDENCE_LEVEL="$CONFIDENCE_LEVEL" - echo "WARNING: CONFIDENCE_LEVEL is deprecated and MUST be replaced with SAST_CONFIDENCE_LEVEL" - fi - - docker run --env SAST_CONFIDENCE_LEVEL="${SAST_CONFIDENCE_LEVEL:-3}" \ - --volume "$PWD:/code" \ - --volume /var/run/docker.sock:/var/run/docker.sock \ - "registry.gitlab.com/gitlab-org/security-products/sast:$SP_VERSION" /app/bin/run /code - ;; - *) - echo "GitLab EE is required" - ;; - esac - } - - function dependency_scanning() { - case "$CI_SERVER_VERSION" in - *-ee) - docker run --env DEP_SCAN_DISABLE_REMOTE_CHECKS="${DEP_SCAN_DISABLE_REMOTE_CHECKS:-false}" \ - --volume "$PWD:/code" \ - --volume /var/run/docker.sock:/var/run/docker.sock \ - "registry.gitlab.com/gitlab-org/security-products/dependency-scanning:$SP_VERSION" /code - ;; - *) - echo "GitLab EE is required" - ;; - esac - } - - # With the Kubernetes executor, 'localhost' must be used instead - # https://docs.gitlab.com/runner/executors/kubernetes.html - function setup_docker() { - if ! docker info &>/dev/null; then - if [ -z "$DOCKER_HOST" -a "$KUBERNETES_PORT" ]; then - export DOCKER_HOST='tcp://localhost:2375' - export DOCKER_SERVICE="localhost" - else - export DOCKER_SERVICE="docker" - fi - fi - } - - function dast() { - export CI_ENVIRONMENT_URL=$(cat environment_url.txt) - - mkdir /zap/wrk/ - /zap/zap-baseline.py -J gl-dast-report.json -t "$CI_ENVIRONMENT_URL" || true - cp /zap/wrk/gl-dast-report.json . - } - -before_script: - - *auto_devops + - template: Jobs/DAST.gitlab-ci.yml + - template: Security/Container-Scanning.gitlab-ci.yml + - template: Security/Dependency-Scanning.gitlab-ci.yml + - template: Security/License-Management.gitlab-ci.yml + - template: Security/SAST.gitlab-ci.yml diff --git a/lib/gitlab/ci/templates/Jobs/DAST.gitlab-ci.yml b/lib/gitlab/ci/templates/Jobs/DAST.gitlab-ci.yml new file mode 100644 index 00000000000..aedbbb21674 --- /dev/null +++ b/lib/gitlab/ci/templates/Jobs/DAST.gitlab-ci.yml @@ -0,0 +1,54 @@ +dast: + stage: dast + image: docker:stable + variables: + DOCKER_DRIVER: overlay2 + allow_failure: true + services: + - docker:stable-dind + script: + - export DAST_WEBSITE=${DAST_WEBSITE:-$(cat environment_url.txt)} + - export DAST_VERSION=${SP_VERSION:-$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')} + - | + if ! docker info &>/dev/null; then + if [ -z "$DOCKER_HOST" -a "$KUBERNETES_PORT" ]; then + export DOCKER_HOST='tcp://localhost:2375' + fi + fi + - | + function dast_run() { + docker run \ + --env DAST_TARGET_AVAILABILITY_TIMEOUT \ + --volume "$PWD:/output" \ + --volume /var/run/docker.sock:/var/run/docker.sock \ + -w /output \ + "registry.gitlab.com/gitlab-org/security-products/dast:$DAST_VERSION" \ + /analyze -t $DAST_WEBSITE \ + "$@" + } + - | + if [ -n "$DAST_AUTH_URL" ] + then + dast_run \ + --auth-url $DAST_AUTH_URL \ + --auth-username $DAST_USERNAME \ + --auth-password $DAST_PASSWORD \ + --auth-username-field $DAST_USERNAME_FIELD \ + --auth-password-field $DAST_PASSWORD_FIELD + else + dast_run + fi + artifacts: + reports: + dast: gl-dast-report.json + only: + refs: + - branches + - tags + variables: + - $GITLAB_FEATURES =~ /\bdast\b/ + except: + refs: + - master + variables: + - $DAST_DISABLED diff --git a/lib/gitlab/ci/templates/Security/Container-Scanning.gitlab-ci.yml b/lib/gitlab/ci/templates/Security/Container-Scanning.gitlab-ci.yml index 0b7a531682b..eef361c19e9 100644 --- a/lib/gitlab/ci/templates/Security/Container-Scanning.gitlab-ci.yml +++ b/lib/gitlab/ci/templates/Security/Container-Scanning.gitlab-ci.yml @@ -28,6 +28,12 @@ container_scanning: - docker:stable-dind script: - if [ -z "$DOCKER_HOST" -a "$KUBERNETES_PORT" ]; then { export DOCKER_SERVICE="localhost" ; export DOCKER_HOST="tcp://${DOCKER_SERVICE}:2375" ; } fi + - | + if [[ -n "$CI_REGISTRY_USER" ]]; then + echo "Logging to GitLab Container Registry with CI credentials..." + docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" "$CI_REGISTRY" + echo "" + fi - docker run -d --name db arminc/clair-db:latest - docker run -p 6060:6060 --link db:postgres -d --name clair --restart on-failure arminc/clair-local-scan:${CLAIR_LOCAL_SCAN_VERSION} - apk add -U wget ca-certificates @@ -36,7 +42,6 @@ container_scanning: - mv clair-scanner_linux_amd64 clair-scanner - chmod +x clair-scanner - touch clair-whitelist.yml - - while( ! wget -q -O /dev/null http://${DOCKER_SERVICE}:6060/v1/namespaces ) ; do sleep 1 ; done - retries=0 - echo "Waiting for clair daemon to start" - while( ! wget -T 10 -q -O /dev/null http://${DOCKER_SERVICE}:6060/v1/namespaces ) ; do sleep 1 ; echo -n "." ; if [ $retries -eq 10 ] ; then echo " Timeout, aborting." ; exit 1 ; fi ; retries=$(($retries+1)) ; done diff --git a/lib/gitlab/ci/templates/Security/DAST.gitlab-ci.yml b/lib/gitlab/ci/templates/Security/DAST.gitlab-ci.yml index ef6d7866e85..770340de16f 100644 --- a/lib/gitlab/ci/templates/Security/DAST.gitlab-ci.yml +++ b/lib/gitlab/ci/templates/Security/DAST.gitlab-ci.yml @@ -4,6 +4,9 @@ # List of the variables: https://gitlab.com/gitlab-org/security-products/dast#settings # How to set: https://docs.gitlab.com/ee/ci/yaml/#variables +include: + - template: Jobs/DAST.gitlab-ci.yml + variables: DAST_WEBSITE: http://example.com # Please edit to be your website to scan for vulnerabilities @@ -14,46 +17,10 @@ stages: - dast dast: - stage: dast - image: docker:stable - variables: - DOCKER_DRIVER: overlay2 - allow_failure: true - services: - - docker:stable-dind - script: - - export DAST_VERSION=${SP_VERSION:-$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')} - - | - function dast_run() { - docker run \ - --env DAST_TARGET_AVAILABILITY_TIMEOUT \ - --volume "$PWD:/output" \ - --volume /var/run/docker.sock:/var/run/docker.sock \ - -w /output \ - "registry.gitlab.com/gitlab-org/security-products/dast:$DAST_VERSION" \ - /analyze -t $DAST_WEBSITE \ - "$@" - } - - | - if [ -n "$DAST_AUTH_URL" ] - then - dast_run \ - --auth-url $DAST_AUTH_URL \ - --auth-username $DAST_USERNAME \ - --auth-password $DAST_PASSWORD \ - --auth-username-field $DAST_USERNAME_FIELD \ - --auth-password-field $DAST_PASSWORD_FIELD - else - dast_run - fi - artifacts: - reports: - dast: gl-dast-report.json only: refs: - branches - variables: - - $GITLAB_FEATURES =~ /\bdast\b/ except: + refs: [] # Override default from template variables: - $DAST_DISABLED diff --git a/lib/gitlab/ci/templates/Security/Dependency-Scanning.gitlab-ci.yml b/lib/gitlab/ci/templates/Security/Dependency-Scanning.gitlab-ci.yml index fd666541d41..7f80a6e9285 100644 --- a/lib/gitlab/ci/templates/Security/Dependency-Scanning.gitlab-ci.yml +++ b/lib/gitlab/ci/templates/Security/Dependency-Scanning.gitlab-ci.yml @@ -14,6 +14,12 @@ dependency_scanning: - docker:stable-dind script: - export DS_VERSION=${SP_VERSION:-$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')} + - | + if ! docker info &>/dev/null; then + if [ -z "$DOCKER_HOST" -a "$KUBERNETES_PORT" ]; then + export DOCKER_HOST='tcp://localhost:2375' + fi + fi - | docker run \ --env DS_ANALYZER_IMAGES \ diff --git a/lib/gitlab/ci/templates/Security/SAST.gitlab-ci.yml b/lib/gitlab/ci/templates/Security/SAST.gitlab-ci.yml index 034fba5499c..b941e89991e 100644 --- a/lib/gitlab/ci/templates/Security/SAST.gitlab-ci.yml +++ b/lib/gitlab/ci/templates/Security/SAST.gitlab-ci.yml @@ -14,6 +14,12 @@ sast: - docker:stable-dind script: - export SAST_VERSION=${SP_VERSION:-$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')} + - | + if ! docker info &>/dev/null; then + if [ -z "$DOCKER_HOST" -a "$KUBERNETES_PORT" ]; then + export DOCKER_HOST='tcp://localhost:2375' + fi + fi - | docker run \ --env SAST_ANALYZER_IMAGES \ diff --git a/spec/lib/gitlab/ci/templates/templates_spec.rb b/spec/lib/gitlab/ci/templates/templates_spec.rb index fbbd58280a9..e20a621168c 100644 --- a/spec/lib/gitlab/ci/templates/templates_spec.rb +++ b/spec/lib/gitlab/ci/templates/templates_spec.rb @@ -4,6 +4,7 @@ require 'spec_helper' describe "CI YML Templates" do ABSTRACT_TEMPLATES = %w[Serverless].freeze + PROJECT_DEPENDENT_TEMPLATES = %w[Auto-DevOps].freeze def self.concrete_templates Gitlab::Template::GitlabCiYmlTemplate.all.reject do |template| @@ -20,7 +21,10 @@ describe "CI YML Templates" do describe 'concrete templates with CI/CD jobs' do concrete_templates.each do |template| it "#{template.name} template should be valid" do - expect { Gitlab::Ci::YamlProcessor.new(template.content) } + # Trigger processing of included files + project = create(:project, :test_repo) if PROJECT_DEPENDENT_TEMPLATES.include?(template.name) + + expect { Gitlab::Ci::YamlProcessor.new(template.content, project: project) } .not_to raise_error end end -- cgit v1.2.1 From 04d91f949ecd3dcf0179762b20276d1461dd8494 Mon Sep 17 00:00:00 2001 From: Tiger Date: Mon, 1 Apr 2019 15:59:29 +1100 Subject: Add docs for including individual Auto-DevOps jobs --- changelogs/unreleased/47234-composable-auto-devops.yml | 5 +++++ doc/topics/autodevops/index.md | 15 +++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 changelogs/unreleased/47234-composable-auto-devops.yml diff --git a/changelogs/unreleased/47234-composable-auto-devops.yml b/changelogs/unreleased/47234-composable-auto-devops.yml new file mode 100644 index 00000000000..9403c5ae6d3 --- /dev/null +++ b/changelogs/unreleased/47234-composable-auto-devops.yml @@ -0,0 +1,5 @@ +--- +title: Split Auto-DevOps.gitlab-ci.yml into reusable templates +merge_request: 26520 +author: +type: changed diff --git a/doc/topics/autodevops/index.md b/doc/topics/autodevops/index.md index b9e3e6aea69..dabf1c5f799 100644 --- a/doc/topics/autodevops/index.md +++ b/doc/topics/autodevops/index.md @@ -677,6 +677,21 @@ renaming `.staging` to `staging`. Then make sure to uncomment the `when` key of the `production` job to turn it into a manual action instead of deploying automatically. +### Using components of Auto-DevOps + +If you only require a subset of the features offered by Auto-DevOps, you can include +individual Auto-DevOps jobs into your own `.gitlab-ci.yml`. + +For example, to make use of [Auto Build](#auto-build), you can add the following to +your `.gitlab-ci.yml`: + +```yaml +include: + - template: Jobs/Build.gitlab-ci.yml +``` + +Consult the [Auto DevOps template] for information on available jobs. + ### PostgreSQL database support In order to support applications that require a database, -- cgit v1.2.1 From 343e834330309b200c2d629ec6a4a2de2e5f29c3 Mon Sep 17 00:00:00 2001 From: Tiger Date: Mon, 1 Apr 2019 17:35:43 +1100 Subject: Add required variables to Jobs/Build.gitlab-ci.yml --- lib/gitlab/ci/templates/Jobs/Build.gitlab-ci.yml | 8 ++++++++ lib/gitlab/ci/templates/Jobs/Deploy.gitlab-ci.yml | 23 ++++++++++++----------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/lib/gitlab/ci/templates/Jobs/Build.gitlab-ci.yml b/lib/gitlab/ci/templates/Jobs/Build.gitlab-ci.yml index 121ae38216f..18f7290e1d9 100644 --- a/lib/gitlab/ci/templates/Jobs/Build.gitlab-ci.yml +++ b/lib/gitlab/ci/templates/Jobs/Build.gitlab-ci.yml @@ -4,6 +4,14 @@ build: services: - docker:stable-dind script: + - | + if [[ -z "$CI_COMMIT_TAG" ]]; then + export CI_APPLICATION_REPOSITORY=${CI_APPLICATION_REPOSITORY:-$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG} + export CI_APPLICATION_TAG=${CI_APPLICATION_TAG:-$CI_COMMIT_SHA} + else + export CI_APPLICATION_REPOSITORY=${CI_APPLICATION_REPOSITORY:-$CI_REGISTRY_IMAGE} + export CI_APPLICATION_TAG=${CI_APPLICATION_TAG:-$CI_COMMIT_TAG} + fi - /build/build.sh only: - branches diff --git a/lib/gitlab/ci/templates/Jobs/Deploy.gitlab-ci.yml b/lib/gitlab/ci/templates/Jobs/Deploy.gitlab-ci.yml index 2f6b73910d5..1e9591e113b 100644 --- a/lib/gitlab/ci/templates/Jobs/Deploy.gitlab-ci.yml +++ b/lib/gitlab/ci/templates/Jobs/Deploy.gitlab-ci.yml @@ -245,13 +245,6 @@ rollout 100%: [[ "$TRACE" ]] && set -x auto_database_url=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${CI_ENVIRONMENT_SLUG}-postgres:5432/${POSTGRES_DB} export DATABASE_URL=${DATABASE_URL-$auto_database_url} - if [[ -z "$CI_COMMIT_TAG" ]]; then - export CI_APPLICATION_REPOSITORY=$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG - export CI_APPLICATION_TAG=$CI_COMMIT_SHA - else - export CI_APPLICATION_REPOSITORY=$CI_REGISTRY_IMAGE - export CI_APPLICATION_TAG=$CI_COMMIT_TAG - fi export TILLER_NAMESPACE=$KUBE_NAMESPACE # Extract "MAJOR.MINOR" from CI_SERVER_VERSION and generate "MAJOR-MINOR-stable" for Security Products @@ -337,6 +330,14 @@ rollout 100%: percentage="${2:-100}" name=$(deploy_name "$track") + if [[ -z "$CI_COMMIT_TAG" ]]; then + image_repository=${CI_APPLICATION_REPOSITORY:-$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG} + image_tag=${CI_APPLICATION_TAG:-$CI_COMMIT_SHA} + else + image_repository=${CI_APPLICATION_REPOSITORY:-$CI_REGISTRY_IMAGE} + image_tag=${CI_APPLICATION_TAG:-$CI_COMMIT_TAG} + fi + replicas="1" service_enabled="true" postgres_enabled="$POSTGRES_ENABLED" @@ -374,8 +375,8 @@ rollout 100%: --set gitlab.app="$CI_PROJECT_PATH_SLUG" \ --set gitlab.env="$CI_ENVIRONMENT_SLUG" \ --set releaseOverride="$CI_ENVIRONMENT_SLUG" \ - --set image.repository="$CI_APPLICATION_REPOSITORY" \ - --set image.tag="$CI_APPLICATION_TAG" \ + --set image.repository="$image_repository" \ + --set image.tag="$image_tag" \ --set image.pullPolicy=IfNotPresent \ --set image.secrets[0].name="$secret_name" \ --set application.track="$track" \ @@ -413,8 +414,8 @@ rollout 100%: --set gitlab.app="$CI_PROJECT_PATH_SLUG" \ --set gitlab.env="$CI_ENVIRONMENT_SLUG" \ --set releaseOverride="$CI_ENVIRONMENT_SLUG" \ - --set image.repository="$CI_APPLICATION_REPOSITORY" \ - --set image.tag="$CI_APPLICATION_TAG" \ + --set image.repository="$image_repository" \ + --set image.tag="$image_tag" \ --set image.pullPolicy=IfNotPresent \ --set image.secrets[0].name="$secret_name" \ --set application.track="$track" \ -- cgit v1.2.1 From 93dd6ecca97842ead47c50c09b8369cc095ace21 Mon Sep 17 00:00:00 2001 From: Thong Kuah Date: Tue, 2 Apr 2019 06:16:18 +0000 Subject: Document that local tiller is used for Auto DevOps Also note that apps will be released into the Kubernetes namespace for the environment, and that GitLab < 11.4 used a dedicated Tiller --- doc/topics/autodevops/index.md | 50 ++++++++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/doc/topics/autodevops/index.md b/doc/topics/autodevops/index.md index b9e3e6aea69..fd99b06b863 100644 --- a/doc/topics/autodevops/index.md +++ b/doc/topics/autodevops/index.md @@ -444,13 +444,6 @@ This is an optional step, since many projects do not have a Kubernetes cluster available. If the [requirements](#requirements) are not met, the job will silently be skipped. -CAUTION: **Caution:** -Your apps should *not* be manipulated outside of Helm (using Kubernetes directly.) -This can cause confusion with Helm not detecting the change, and subsequent -deploys with Auto DevOps can undo your changes. Also, if you change something -and want to undo it by deploying again, Helm may not detect that anything changed -in the first place, and thus not realize that it needs to re-apply the old config. - [Review Apps][review-app] are temporary application environments based on the branch's code so developers, designers, QA, product managers, and other reviewers can actually see and interact with code changes as part of the review @@ -466,6 +459,24 @@ up in the merge request widget for easy discovery. When the branch or tag is del for example after the merge request is merged, the Review App will automatically be deleted. +Review apps are deployed using the +[auto-deploy-app](https://gitlab.com/charts/auto-deploy-app) chart with +Helm. The app will be deployed into the [Kubernetes +namespace](../../user/project/clusters/index.md#deployment-variables) +for the environment. + +Since GitLab 11.4, a [local +Tiller](https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/22036) is +used. Previous versions of GitLab had a Tiller installed in the project +namespace. + +CAUTION: **Caution:** +Your apps should *not* be manipulated outside of Helm (using Kubernetes directly). +This can cause confusion with Helm not detecting the change and subsequent +deploys with Auto DevOps can undo your changes. Also, if you change something +and want to undo it by deploying again, Helm may not detect that anything changed +in the first place, and thus not realize that it needs to re-apply the old config. + ### Auto DAST **[ULTIMATE]** > Introduced in [GitLab Ultimate][ee] 10.4. @@ -504,13 +515,6 @@ This is an optional step, since many projects do not have a Kubernetes cluster available. If the [requirements](#requirements) are not met, the job will silently be skipped. -CAUTION: **Caution:** -Your apps should *not* be manipulated outside of Helm (using Kubernetes directly.) -This can cause confusion with Helm not detecting the change, and subsequent -deploys with Auto DevOps can undo your changes. Also, if you change something -and want to undo it by deploying again, Helm may not detect that anything changed -in the first place, and thus not realize that it needs to re-apply the old config. - After a branch or merge request is merged into the project's default branch (usually `master`), Auto Deploy deploys the application to a `production` environment in the Kubernetes cluster, with a namespace based on the project name and unique @@ -523,6 +527,24 @@ enable them. You can make use of [environment variables](#environment-variables) to automatically scale your pod replicas. +Apps are deployed using the +[auto-deploy-app](https://gitlab.com/charts/auto-deploy-app) chart with +Helm. The app will be deployed into the [Kubernetes +namespace](../../user/project/clusters/index.md#deployment-variables) +for the environment. + +Since GitLab 11.4, a [local +Tiller](https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/22036) is +used. Previous versions of GitLab had a Tiller installed in the project +namespace. + +CAUTION: **Caution:** +Your apps should *not* be manipulated outside of Helm (using Kubernetes directly). +This can cause confusion with Helm not detecting the change and subsequent +deploys with Auto DevOps can undo your changes. Also, if you change something +and want to undo it by deploying again, Helm may not detect that anything changed +in the first place, and thus not realize that it needs to re-apply the old config. + > [Introduced][ce-19507] in GitLab 11.0. For internal and private projects a [GitLab Deploy Token](../../user/project/deploy_tokens/index.md#gitlab-deploy-token) -- cgit v1.2.1 From 22fe2fb4c11c16739a3a1bb97569884db70ac546 Mon Sep 17 00:00:00 2001 From: Peter Marko Date: Tue, 2 Apr 2019 06:49:11 +0000 Subject: Fix group transfer selection possibilities --- app/finders/groups_finder.rb | 8 ++++++ app/helpers/groups_helper.rb | 5 ++-- .../fix-transfer-group-possibilities.yml | 5 ++++ spec/helpers/groups_helper_spec.rb | 33 ++++++++++++++++++++++ 4 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 changelogs/unreleased/fix-transfer-group-possibilities.yml diff --git a/app/finders/groups_finder.rb b/app/finders/groups_finder.rb index 0080123407d..7d419103b1c 100644 --- a/app/finders/groups_finder.rb +++ b/app/finders/groups_finder.rb @@ -11,6 +11,7 @@ # parent: Group # all_available: boolean (defaults to true) # min_access_level: integer +# exclude_group_ids: array of integers # # Users with full private access can see all groups. The `owned` and `parent` # params can be used to restrict the groups that are returned. @@ -29,6 +30,7 @@ class GroupsFinder < UnionFinder items = all_groups.map do |item| item = by_parent(item) item = by_custom_attributes(item) + item = exclude_group_ids(item) item end @@ -72,6 +74,12 @@ class GroupsFinder < UnionFinder end # rubocop: enable CodeReuse/ActiveRecord + def exclude_group_ids(groups) + return groups unless params[:exclude_group_ids] + + groups.id_not_in(params[:exclude_group_ids]) + end + # rubocop: disable CodeReuse/ActiveRecord def by_parent(groups) return groups unless params[:parent] diff --git a/app/helpers/groups_helper.rb b/app/helpers/groups_helper.rb index 9d028dccad7..7af766c8544 100644 --- a/app/helpers/groups_helper.rb +++ b/app/helpers/groups_helper.rb @@ -118,11 +118,12 @@ module GroupsHelper end def parent_group_options(current_group) - groups = current_user.owned_groups.sort_by(&:human_name).map do |group| + exclude_groups = current_group.self_and_descendants.pluck_primary_key + exclude_groups << current_group.parent_id if current_group.parent_id + groups = GroupsFinder.new(current_user, min_access_level: Gitlab::Access::OWNER, exclude_group_ids: exclude_groups).execute.sort_by(&:human_name).map do |group| { id: group.id, text: group.human_name } end - groups.delete_if { |group| group[:id] == current_group.id } groups.to_json end diff --git a/changelogs/unreleased/fix-transfer-group-possibilities.yml b/changelogs/unreleased/fix-transfer-group-possibilities.yml new file mode 100644 index 00000000000..ebefb47b3da --- /dev/null +++ b/changelogs/unreleased/fix-transfer-group-possibilities.yml @@ -0,0 +1,5 @@ +--- +title: Fix group transfer selection possibilities +merge_request: 26123 +author: Peter Marko +type: fixed diff --git a/spec/helpers/groups_helper_spec.rb b/spec/helpers/groups_helper_spec.rb index 91541a16c13..1763c46389a 100644 --- a/spec/helpers/groups_helper_spec.rb +++ b/spec/helpers/groups_helper_spec.rb @@ -229,4 +229,37 @@ describe GroupsHelper do expect(helper.group_sidebar_links).not_to include(*cross_project_features) end end + + describe 'parent_group_options', :nested_groups do + let(:current_user) { create(:user) } + let(:group) { create(:group, name: 'group') } + let(:group2) { create(:group, name: 'group2') } + + before do + group.add_owner(current_user) + group2.add_owner(current_user) + end + + it 'includes explicitly owned groups except self' do + expect(parent_group_options(group2)).to eq([{ id: group.id, text: group.human_name }].to_json) + end + + it 'excludes parent group' do + subgroup = create(:group, parent: group2) + + expect(parent_group_options(subgroup)).to eq([{ id: group.id, text: group.human_name }].to_json) + end + + it 'includes subgroups with inherited ownership' do + subgroup = create(:group, parent: group) + + expect(parent_group_options(group2)).to eq([{ id: group.id, text: group.human_name }, { id: subgroup.id, text: subgroup.human_name }].to_json) + end + + it 'excludes own subgroups' do + create(:group, parent: group2) + + expect(parent_group_options(group2)).to eq([{ id: group.id, text: group.human_name }].to_json) + end + end end -- cgit v1.2.1 From 6473f6976124f047a56f9d004e3d0746ab493b29 Mon Sep 17 00:00:00 2001 From: Mayra Cabrera Date: Tue, 2 Apr 2019 06:54:54 +0000 Subject: Add new field to Clusters table Adds boolean field 'managed' to clusters table. This new column will be used to distinguish those clusters that are automatically managed by gitlab. Needed for https://gitlab.com/gitlab-org/gitlab-ce/issues/56557 --- db/migrate/20190325165127_add_managed_to_cluster.rb | 17 +++++++++++++++++ db/schema.rb | 3 ++- spec/factories/clusters/clusters.rb | 5 +++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20190325165127_add_managed_to_cluster.rb diff --git a/db/migrate/20190325165127_add_managed_to_cluster.rb b/db/migrate/20190325165127_add_managed_to_cluster.rb new file mode 100644 index 00000000000..e960df9d502 --- /dev/null +++ b/db/migrate/20190325165127_add_managed_to_cluster.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddManagedToCluster < ActiveRecord::Migration[5.0] + include Gitlab::Database::MigrationHelpers + + disable_ddl_transaction! + + DOWNTIME = false + + def up + add_column_with_default(:clusters, :managed, :boolean, default: true) + end + + def down + remove_column(:clusters, :managed) + end +end diff --git a/db/schema.rb b/db/schema.rb index 7cc09e56285..8197e860996 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20190322132835) do +ActiveRecord::Schema.define(version: 20190325165127) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -670,6 +670,7 @@ ActiveRecord::Schema.define(version: 20190322132835) do t.string "environment_scope", default: "*", null: false t.integer "cluster_type", limit: 2, default: 3, null: false t.string "domain" + t.boolean "managed", default: true, null: false t.index ["enabled"], name: "index_clusters_on_enabled", using: :btree t.index ["user_id"], name: "index_clusters_on_user_id", using: :btree end diff --git a/spec/factories/clusters/clusters.rb b/spec/factories/clusters/clusters.rb index 1cc3c0e03d8..97405ec7c58 100644 --- a/spec/factories/clusters/clusters.rb +++ b/spec/factories/clusters/clusters.rb @@ -3,6 +3,7 @@ FactoryBot.define do user name 'test-cluster' cluster_type :project_type + managed true trait :instance do cluster_type { Clusters::Cluster.cluster_types[:instance_type] } @@ -63,5 +64,9 @@ FactoryBot.define do trait :with_domain do domain 'example.com' end + + trait :user_managed do + managed false + end end end -- cgit v1.2.1 From a466d97e62a89b320713da44d67d452284ad8282 Mon Sep 17 00:00:00 2001 From: Jan Provaznik Date: Tue, 2 Apr 2019 07:48:35 +0000 Subject: Rake task for removing exif from uploads Adds a rake task which can be used for removing EXIF data from existing uploads. --- GITLAB_WORKHORSE_VERSION | 2 +- changelogs/unreleased/security-exif-migration.yml | 5 + doc/administration/raketasks/uploads/sanitize.md | 62 +++++++++ doc/raketasks/README.md | 1 + lib/gitlab/sanitizers/exif.rb | 156 ++++++++++++++++++++++ lib/tasks/gitlab/uploads/sanitize.rake | 18 +++ spec/lib/gitlab/sanitizers/exif_spec.rb | 120 +++++++++++++++++ 7 files changed, 363 insertions(+), 1 deletion(-) create mode 100644 changelogs/unreleased/security-exif-migration.yml create mode 100644 doc/administration/raketasks/uploads/sanitize.md create mode 100644 lib/gitlab/sanitizers/exif.rb create mode 100644 lib/tasks/gitlab/uploads/sanitize.rake create mode 100644 spec/lib/gitlab/sanitizers/exif_spec.rb diff --git a/GITLAB_WORKHORSE_VERSION b/GITLAB_WORKHORSE_VERSION index 56b6be4ebb2..d127a0ff9f1 100644 --- a/GITLAB_WORKHORSE_VERSION +++ b/GITLAB_WORKHORSE_VERSION @@ -1 +1 @@ -8.3.1 +8.3.3 diff --git a/changelogs/unreleased/security-exif-migration.yml b/changelogs/unreleased/security-exif-migration.yml new file mode 100644 index 00000000000..cc529099df5 --- /dev/null +++ b/changelogs/unreleased/security-exif-migration.yml @@ -0,0 +1,5 @@ +--- +title: Added rake task for removing EXIF data from existing uploads. +merge_request: +author: +type: security diff --git a/doc/administration/raketasks/uploads/sanitize.md b/doc/administration/raketasks/uploads/sanitize.md new file mode 100644 index 00000000000..54a423b9571 --- /dev/null +++ b/doc/administration/raketasks/uploads/sanitize.md @@ -0,0 +1,62 @@ +# Uploads Sanitize tasks + +## Requirements + +You need `exiftool` installed on your system. If you installed GitLab: + +- Using the Omnibus package, you're all set. +- From source, make sure `exiftool` is installed: + + ```sh + # Debian/Ubuntu + sudo apt-get install libimage-exiftool-perl + + # RHEL/CentOS + sudo yum install perl-Image-ExifTool + ``` + +## Remove EXIF data from existing uploads + +Since 11.9 EXIF data are automatically stripped from JPG or TIFF image uploads. +Because EXIF data may contain sensitive information (e.g. GPS location), you +can remove EXIF data also from existing images which were uploaded before +with the following command: + +```bash +sudo RAILS_ENV=production -u git -H bundle exec rake gitlab:uploads:sanitize:remove_exif +``` + +This command by default runs in dry mode and it doesn't remove EXIF data. It can be used for +checking if (and how many) images should be sanitized. + +The rake task accepts following parameters. + +Parameter | Type | Description +--------- | ---- | ----------- +`start_id` | integer | Only uploads with equal or greater ID will be processed +`stop_id` | integer | Only uploads with equal or smaller ID will be processed +`dry_run` | boolean | Do not remove EXIF data, only check if EXIF data are present or not, default: true +`sleep_time` | float | Pause for number of seconds after processing each image, default: 0.3 seconds + +If you have too many uploads, you can speed up sanitization by setting +`sleep_time` to a lower value or by running multiple rake tasks in parallel, +each with a separate range of upload IDs (by setting `start_id` and `stop_id`). + +To run the command without dry mode and remove EXIF data from all uploads, you can use: + +```bash +sudo RAILS_ENV=production -u git -H bundle exec rake gitlab:uploads:sanitize:remove_exif[,,false,] 2>&1 | tee exif.log +``` + +To run the command without dry mode on uploads with ID between 100 and 5000 and pause for 0.1 second, you can use: + +```bash +sudo RAILS_ENV=production -u git -H bundle exec rake gitlab:uploads:sanitize:remove_exif[100,5000,false,0.1] 2>&1 | tee exif.log +``` + +Because the output of commands will be probably long, the output is written also into exif.log file. + +If sanitization fails for an upload, an error message should be in the output of the rake task (typical reasons may +be that the file is missing in the storage or it's not a valid image). Please +[report](https://gitlab.com/gitlab-org/gitlab-ce/issues/new) any issues at `gitlab.com` and use +prefix 'EXIF' in issue title with the error output and (if possible) the image. diff --git a/doc/raketasks/README.md b/doc/raketasks/README.md index 90187617c41..0729875daf8 100644 --- a/doc/raketasks/README.md +++ b/doc/raketasks/README.md @@ -15,3 +15,4 @@ comments: false - [Import](import.md) of git repositories in bulk - [Rebuild authorized_keys file](http://docs.gitlab.com/ce/raketasks/maintenance.html#rebuild-authorized_keys-file) task for administrators - [Migrate Uploads](../administration/raketasks/uploads/migrate.md) +- [Sanitize Uploads](../administration/raketasks/uploads/sanitize.md) diff --git a/lib/gitlab/sanitizers/exif.rb b/lib/gitlab/sanitizers/exif.rb new file mode 100644 index 00000000000..0928ccdc324 --- /dev/null +++ b/lib/gitlab/sanitizers/exif.rb @@ -0,0 +1,156 @@ +# frozen_string_literal: true + +module Gitlab + module Sanitizers + class Exif + # these tags are not removed from the image + WHITELISTED_TAGS = %w( + ResolutionUnit + XResolution + YResolution + YCbCrSubSampling + YCbCrPositioning + BitsPerSample + ImageHeight + ImageWidth + ImageSize + Copyright + CopyrightNotice + Orientation + ).freeze + + # these tags are common in exiftool output, these + # do not contain any sensitive information, but + # we don't need to preserve them when removing + # exif tags + IGNORED_TAGS = %w( + ColorComponents + EncodingProcess + ExifByteOrder + ExifToolVersion + JFIFVersion + Directory + FileAccessDate + FileInodeChangeDate + FileModifyDate + FileName + FilePermissions + FileSize + SourceFile + Megapixels + FileType + FileTypeExtension + MIMEType + ).freeze + + ALLOWED_TAGS = WHITELISTED_TAGS + IGNORED_TAGS + EXCLUDE_PARAMS = WHITELISTED_TAGS.map { |tag| "-#{tag}" } + + attr_reader :logger + + def initialize(logger: Rails.logger) + @logger = logger + end + + # rubocop: disable CodeReuse/ActiveRecord + def batch_clean(start_id: nil, stop_id: nil, dry_run: true, sleep_time: nil) + relation = Upload.where('lower(path) like ? or lower(path) like ? or lower(path) like ?', + '%.jpg', '%.jpeg', '%.tiff') + + logger.info "running in dry run mode, no images will be rewritten" if dry_run + + find_params = { + start: start_id.present? ? start_id.to_i : nil, + finish: stop_id.present? ? stop_id.to_i : Upload.last&.id + } + + relation.find_each(find_params) do |upload| + clean(upload.build_uploader, dry_run: dry_run) + sleep sleep_time if sleep_time + rescue => err + logger.error "failed to sanitize #{upload_ref(upload)}: #{err.message}" + logger.debug err.backtrace.join("\n ") + end + end + # rubocop: enable CodeReuse/ActiveRecord + + def clean(uploader, dry_run: true) + Dir.mktmpdir('gitlab-exif') do |tmpdir| + src_path = fetch_upload_to_file(uploader, tmpdir) + + to_remove = extra_tags(src_path) + + if to_remove.empty? + logger.info "#{upload_ref(uploader.upload)}: only whitelisted tags present, skipping" + break + end + + logger.info "#{upload_ref(uploader.upload)}: found exif tags to remove: #{to_remove}" + + break if dry_run + + remove_and_store(tmpdir, src_path, uploader) + end + end + + def extra_tags(path) + exif_tags(path).keys - ALLOWED_TAGS + end + + private + + def remove_and_store(tmpdir, src_path, uploader) + exec_remove_exif!(src_path) + logger.info "#{upload_ref(uploader.upload)}: exif removed, storing" + File.open(src_path, 'r') { |f| uploader.store!(f) } + end + + def exec_remove_exif!(path) + # IPTC and XMP-iptcExt groups may keep copyright information so + # we always preserve them + cmd = ["exiftool", "-all=", "-tagsFromFile", "@", *EXCLUDE_PARAMS, "--IPTC:all", "--XMP-iptcExt:all", path] + output, status = Gitlab::Popen.popen(cmd) + + if status != 0 + raise "exiftool return code is #{status}: #{output}" + end + + if File.size(path) == 0 + raise "size of file is 0" + end + + # exiftool creates backup of the original file in filename_original + old_path = "#{path}_original" + if File.size(path) == File.size(old_path) + raise "size of sanitized file is same as original size" + end + end + + def fetch_upload_to_file(uploader, dir) + # upload is stored into the file with the original name - this filename + # is used by carrierwave when storing the file back to the storage + filename = File.join(dir, uploader.filename) + + File.open(filename, 'w') do |file| + file.binmode + file.write uploader.read + end + + filename + end + + def upload_ref(upload) + "#{upload.id}:#{upload.path}" + end + + def exif_tags(path) + cmd = ["exiftool", "-all", "-j", "-sort", "--IPTC:all", "--XMP-iptcExt:all", path] + output, status = Gitlab::Popen.popen(cmd) + + raise "failed to get exif tags: #{output}" if status != 0 + + JSON.parse(output).first + end + end + end +end diff --git a/lib/tasks/gitlab/uploads/sanitize.rake b/lib/tasks/gitlab/uploads/sanitize.rake new file mode 100644 index 00000000000..12cf5302555 --- /dev/null +++ b/lib/tasks/gitlab/uploads/sanitize.rake @@ -0,0 +1,18 @@ +namespace :gitlab do + namespace :uploads do + namespace :sanitize do + desc 'GitLab | Uploads | Remove EXIF from images.' + task :remove_exif, [:start_id, :stop_id, :dry_run, :sleep_time] => :environment do |task, args| + args.with_defaults(dry_run: 'true') + args.with_defaults(sleep_time: 0.3) + + logger = Logger.new(STDOUT) + + sanitizer = Gitlab::Sanitizers::Exif.new(logger: logger) + sanitizer.batch_clean(start_id: args.start_id, stop_id: args.stop_id, + dry_run: args.dry_run != 'false', + sleep_time: args.sleep_time.to_f) + end + end + end +end diff --git a/spec/lib/gitlab/sanitizers/exif_spec.rb b/spec/lib/gitlab/sanitizers/exif_spec.rb new file mode 100644 index 00000000000..bd5f330c7a1 --- /dev/null +++ b/spec/lib/gitlab/sanitizers/exif_spec.rb @@ -0,0 +1,120 @@ +require 'spec_helper' + +describe Gitlab::Sanitizers::Exif do + let(:sanitizer) { described_class.new } + + describe '#batch_clean' do + context 'with image uploads' do + let!(:uploads) { create_list(:upload, 3, :with_file, :issuable_upload) } + + it 'processes all uploads if range ID is not set' do + expect(sanitizer).to receive(:clean).exactly(3).times + + sanitizer.batch_clean + end + + it 'processes only uploads in the selected range' do + expect(sanitizer).to receive(:clean).once + + sanitizer.batch_clean(start_id: uploads[1].id, stop_id: uploads[1].id) + end + + it 'pauses if sleep_time is set' do + expect(sanitizer).to receive(:sleep).exactly(3).times.with(1.second) + expect(sanitizer).to receive(:clean).exactly(3).times + + sanitizer.batch_clean(sleep_time: 1) + end + end + + it 'filters only jpg/tiff images' do + create(:upload, path: 'filename.jpg') + create(:upload, path: 'filename.jpeg') + create(:upload, path: 'filename.JPG') + create(:upload, path: 'filename.tiff') + create(:upload, path: 'filename.TIFF') + create(:upload, path: 'filename.png') + create(:upload, path: 'filename.txt') + + expect(sanitizer).to receive(:clean).exactly(5).times + sanitizer.batch_clean + end + end + + describe '#clean' do + let(:uploader) { create(:upload, :with_file, :issuable_upload).build_uploader } + + context "no dry run" do + it "removes exif from the image" do + uploader.store!(fixture_file_upload('spec/fixtures/rails_sample.jpg')) + + original_upload = uploader.upload + expected_args = ["exiftool", "-all=", "-tagsFromFile", "@", *Gitlab::Sanitizers::Exif::EXCLUDE_PARAMS, "--IPTC:all", "--XMP-iptcExt:all", kind_of(String)] + + expect(sanitizer).to receive(:extra_tags).and_return(["", 0]) + expect(sanitizer).to receive(:exec_remove_exif!).once.and_call_original + expect(uploader).to receive(:store!).and_call_original + expect(Gitlab::Popen).to receive(:popen).with(expected_args) do |args| + File.write("#{args.last}_original", "foo") if args.last.start_with?(Dir.tmpdir) + + [expected_args, 0] + end + + sanitizer.clean(uploader, dry_run: false) + + expect(uploader.upload.id).not_to eq(original_upload.id) + expect(uploader.upload.path).to eq(original_upload.path) + end + + it "ignores image without exif" do + expected_args = ["exiftool", "-all", "-j", "-sort", "--IPTC:all", "--XMP-iptcExt:all", kind_of(String)] + + expect(Gitlab::Popen).to receive(:popen).with(expected_args).and_return(["[{}]", 0]) + expect(sanitizer).not_to receive(:exec_remove_exif!) + expect(uploader).not_to receive(:store!) + + sanitizer.clean(uploader, dry_run: false) + end + + it "raises an error if the exiftool fails with an error" do + expect(Gitlab::Popen).to receive(:popen).and_return(["error", 1]) + + expect { sanitizer.clean(uploader, dry_run: false) }.to raise_exception(RuntimeError, "failed to get exif tags: error") + end + end + + context "dry run" do + it "doesn't change the image" do + expect(sanitizer).to receive(:extra_tags).and_return({ 'foo' => 'bar' }) + expect(sanitizer).not_to receive(:exec_remove_exif!) + expect(uploader).not_to receive(:store!) + + sanitizer.clean(uploader, dry_run: true) + end + end + end + + describe "#extra_tags" do + it "returns a list of keys for exif file" do + tags = '[{ + "DigitalSourceType": "some source", + "ImageHeight": 654 + }]' + + expect(Gitlab::Popen).to receive(:popen).and_return([tags, 0]) + + expect(sanitizer.extra_tags('filename')).not_to be_empty + end + + it "returns an empty list for file with only whitelisted and ignored tags" do + tags = '[{ + "ImageHeight": 654, + "Megapixels": 0.641 + }]' + + expect(Gitlab::Popen).to receive(:popen).and_return([tags, 0]) + + expect(sanitizer.extra_tags('some file')).to be_empty + end + end +end -- cgit v1.2.1 From 7c26c47cb55613babcbbbd329ffec1ab4b79378f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Coutable?= Date: Mon, 1 Apr 2019 18:49:03 +0200 Subject: [CE] Reduce diff with EE in spec/models/concerns/prometheus_adapter_spec.rb MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rémy Coutable --- spec/models/concerns/prometheus_adapter_spec.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/spec/models/concerns/prometheus_adapter_spec.rb b/spec/models/concerns/prometheus_adapter_spec.rb index 7148261b1e4..db20a8b4701 100644 --- a/spec/models/concerns/prometheus_adapter_spec.rb +++ b/spec/models/concerns/prometheus_adapter_spec.rb @@ -6,14 +6,15 @@ describe PrometheusAdapter, :use_clean_rails_memory_store_caching do include PrometheusHelpers include ReactiveCachingHelpers - class TestClass - include PrometheusAdapter - end - let(:project) { create(:prometheus_project) } let(:service) { project.prometheus_service } - let(:described_class) { TestClass } + let(:described_class) do + Class.new do + include PrometheusAdapter + end + end + let(:environment_query) { Gitlab::Prometheus::Queries::EnvironmentQuery } describe '#query' do -- cgit v1.2.1 From 590129a89238c3683aa8ffa41b72624fd786cbf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Coutable?= Date: Mon, 1 Apr 2019 19:41:36 +0200 Subject: [CE] Reduce diff with EE in spec/models/environment_spec.rb MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rémy Coutable --- spec/models/environment_spec.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spec/models/environment_spec.rb b/spec/models/environment_spec.rb index 448ed35cb1e..ca5eed60b56 100644 --- a/spec/models/environment_spec.rb +++ b/spec/models/environment_spec.rb @@ -592,7 +592,9 @@ describe Environment do shared_examples 'same behavior between KubernetesService and Platform::Kubernetes' do it 'returns the terminals from the deployment service' do - expect(project.deployment_platform) + deployment_platform_target = Gitlab.ee? ? environment : project + + expect(deployment_platform_target.deployment_platform) .to receive(:terminals).with(environment) .and_return(:fake_terminals) -- cgit v1.2.1 From 0f369d145b568fc1e1b6034b42a4b3a6b3652d43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Coutable?= Date: Mon, 1 Apr 2019 19:16:48 +0200 Subject: [CE] Reduce diff with EE in spec/models/project_spec.rb MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rémy Coutable --- spec/models/project_spec.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 2158d3cf3e6..33e514cd7b9 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -2143,6 +2143,15 @@ describe Project do expect(project.add_import_job).to eq(import_jid) end + + context 'without repository' do + it 'schedules RepositoryImportWorker' do + project = create(:project, import_url: generate(:url)) + + expect(RepositoryImportWorker).to receive(:perform_async).with(project.id).and_return(import_jid) + expect(project.add_import_job).to eq(import_jid) + end + end end context 'not forked' do -- cgit v1.2.1 From f3ad4ecb73f66487191160505578d236d9361d18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Coutable?= Date: Mon, 1 Apr 2019 19:20:31 +0200 Subject: [CE] Reduce diff with EE in spec/models/project_team_spec.rb MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rémy Coutable --- spec/models/project_team_spec.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/spec/models/project_team_spec.rb b/spec/models/project_team_spec.rb index a2d4fad9292..77c88a04cde 100644 --- a/spec/models/project_team_spec.rb +++ b/spec/models/project_team_spec.rb @@ -195,6 +195,30 @@ describe ProjectTeam do end end + describe '#add_users' do + let(:user1) { create(:user) } + let(:user2) { create(:user) } + let(:project) { create(:project) } + + it 'add the given users to the team' do + project.team.add_users([user1, user2], :reporter) + + expect(project.team.reporter?(user1)).to be(true) + expect(project.team.reporter?(user2)).to be(true) + end + end + + describe '#add_user' do + let(:user) { create(:user) } + let(:project) { create(:project) } + + it 'add the given user to the team' do + project.team.add_user(user, :reporter) + + expect(project.team.reporter?(user)).to be(true) + end + end + describe "#human_max_access" do it 'returns Maintainer role' do user = create(:user) -- cgit v1.2.1 From 8708c720c5d9a08160658c2ee9fea9796568a1c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Coutable?= Date: Mon, 1 Apr 2019 19:24:21 +0200 Subject: [CE] Reduce diff with EE in spec/models/project_wiki_spec.rb MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rémy Coutable --- spec/models/project_wiki_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/models/project_wiki_spec.rb b/spec/models/project_wiki_spec.rb index 7ea67f31534..2525a6aebe0 100644 --- a/spec/models/project_wiki_spec.rb +++ b/spec/models/project_wiki_spec.rb @@ -1,4 +1,3 @@ -# coding: utf-8 # frozen_string_literal: true require "spec_helper" -- cgit v1.2.1 From 07e61875de710e9162f7a41b71eea8cd0bca3cf3 Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Tue, 2 Apr 2019 08:26:09 +0100 Subject: CE backport of design-management-upload-client --- app/assets/javascripts/lib/graphql.js | 19 +++++--- doc/development/fe_guide/graphql.md | 28 ++++++++---- package.json | 3 +- yarn.lock | 85 ++++++++++++++++++++--------------- 4 files changed, 81 insertions(+), 54 deletions(-) diff --git a/app/assets/javascripts/lib/graphql.js b/app/assets/javascripts/lib/graphql.js index 64e4e899f44..ae02559415c 100644 --- a/app/assets/javascripts/lib/graphql.js +++ b/app/assets/javascripts/lib/graphql.js @@ -1,11 +1,16 @@ -import ApolloClient from 'apollo-boost'; +import { ApolloClient } from 'apollo-client'; +import { InMemoryCache } from 'apollo-cache-inmemory'; +import { createUploadLink } from 'apollo-upload-client'; import csrf from '~/lib/utils/csrf'; -export default (clientState = {}) => +export default (resolvers = {}) => new ApolloClient({ - uri: `${gon.relative_url_root}/api/graphql`, - headers: { - [csrf.headerKey]: csrf.token, - }, - clientState, + link: createUploadLink({ + uri: `${gon.relative_url_root}/api/graphql`, + headers: { + [csrf.headerKey]: csrf.token, + }, + }), + cache: new InMemoryCache(), + resolvers, }); diff --git a/doc/development/fe_guide/graphql.md b/doc/development/fe_guide/graphql.md index 3290f29530a..5f6123b5f9b 100644 --- a/doc/development/fe_guide/graphql.md +++ b/doc/development/fe_guide/graphql.md @@ -46,7 +46,9 @@ Read more about [Vue Apollo][vue-apollo] in the [Vue Apollo documentation][vue-a ### Local state with `apollo-link-state` It is possible to use our Apollo setup with [apollo-link-state][apollo-link-state] by passing -in the client state object when creating the default client. +in a resolvers object when creating the default client. The default state can be set by writing +to the cache after setting up the default client. + ```javascript import Vue from 'vue'; @@ -54,15 +56,23 @@ import VueApollo from 'vue-apollo'; import createDefaultClient from '~/lib/graphql'; Vue.use(VueApollo); +const defaultClient = createDefaultClient({ + Query: { + ... + }, + Mutations: { + ... + }, +}); + +defaultClient.cache.writeData({ + data: { + isLoading: true, + }, +}); + const apolloProvider = new VueApollo({ - defaultClient: createDefaultClient({ - defaults: { - testing: true, - }, - resolvers: { - ... - }, - }), + defaultClient, }); ``` diff --git a/package.json b/package.json index f80f9b3690b..a2d96cc551a 100644 --- a/package.json +++ b/package.json @@ -34,8 +34,9 @@ "@gitlab/csslab": "^1.9.0", "@gitlab/svgs": "^1.57.0", "@gitlab/ui": "^3.0.0", - "apollo-boost": "^0.3.1", + "apollo-cache-inmemory": "^1.5.1", "apollo-client": "^2.5.1", + "apollo-upload-client": "^10.0.0", "at.js": "^1.5.4", "autosize": "^4.0.0", "axios": "^0.17.1", diff --git a/yarn.lock b/yarn.lock index 846e29862f1..5d40bec659d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1114,21 +1114,6 @@ anymatch@^2.0.0: micromatch "^3.1.4" normalize-path "^2.1.1" -apollo-boost@^0.3.1: - version "0.3.1" - resolved "https://registry.yarnpkg.com/apollo-boost/-/apollo-boost-0.3.1.tgz#b6a896e020a0eab7e415032fe565734a955c65f8" - integrity sha512-VdXcTMxLBeNvANW/FtiarEkrRr/cepYKG6wTAURdy8CS33WYpEHtIg9S8tAjxwVzIECpE4lWyDKyPLoESJ072Q== - dependencies: - apollo-cache "^1.2.1" - apollo-cache-inmemory "^1.5.1" - apollo-client "^2.5.1" - apollo-link "^1.0.6" - apollo-link-error "^1.0.3" - apollo-link-http "^1.3.1" - graphql-tag "^2.4.2" - ts-invariant "^0.2.1" - tslib "^1.9.3" - apollo-cache-inmemory@^1.5.1: version "1.5.1" resolved "https://registry.yarnpkg.com/apollo-cache-inmemory/-/apollo-cache-inmemory-1.5.1.tgz#265d1ee67b0bf0aca9c37629d410bfae44e62953" @@ -1170,29 +1155,16 @@ apollo-link-dedup@^1.0.0: dependencies: apollo-link "^1.2.3" -apollo-link-error@^1.0.3: - version "1.1.1" - resolved "https://registry.yarnpkg.com/apollo-link-error/-/apollo-link-error-1.1.1.tgz#69d7124d4dc11ce60f505c940f05d4f1aa0945fb" - integrity sha512-/yPcaQWcBdB94vpJ4FsiCJt1dAGGRm+6Tsj3wKwP+72taBH+UsGRQQZk7U/1cpZwl1yqhHZn+ZNhVOebpPcIlA== +apollo-link-http-common@^0.2.8: + version "0.2.13" + resolved "https://registry.yarnpkg.com/apollo-link-http-common/-/apollo-link-http-common-0.2.13.tgz#c688f6baaffdc7b269b2db7ae89dae7c58b5b350" + integrity sha512-Uyg1ECQpTTA691Fwx5e6Rc/6CPSu4TB4pQRTGIpwZ4l5JDOQ+812Wvi/e3IInmzOZpwx5YrrOfXrtN8BrsDXoA== dependencies: - apollo-link "^1.2.3" - -apollo-link-http-common@^0.2.5: - version "0.2.5" - resolved "https://registry.yarnpkg.com/apollo-link-http-common/-/apollo-link-http-common-0.2.5.tgz#d094beb7971523203359bf830bfbfa7b4e7c30ed" - integrity sha512-6FV1wr5AqAyJ64Em1dq5hhGgiyxZE383VJQmhIoDVc3MyNcFL92TkhxREOs4rnH2a9X2iJMko7nodHSGLC6d8w== - dependencies: - apollo-link "^1.2.3" - -apollo-link-http@^1.3.1: - version "1.5.5" - resolved "https://registry.yarnpkg.com/apollo-link-http/-/apollo-link-http-1.5.5.tgz#7dbe851821771ad67fa29e3900c57f38cbd80da8" - integrity sha512-C5N6N/mRwmepvtzO27dgMEU3MMtRKSqcljBkYNZmWwH11BxkUQ5imBLPM3V4QJXNE7NFuAQAB5PeUd4ligivTQ== - dependencies: - apollo-link "^1.2.3" - apollo-link-http-common "^0.2.5" + apollo-link "^1.2.11" + ts-invariant "^0.3.2" + tslib "^1.9.3" -apollo-link@^1.0.0, apollo-link@^1.0.6, apollo-link@^1.2.3: +apollo-link@^1.0.0, apollo-link@^1.2.3: version "1.2.3" resolved "https://registry.yarnpkg.com/apollo-link/-/apollo-link-1.2.3.tgz#9bd8d5fe1d88d31dc91dae9ecc22474d451fb70d" integrity sha512-iL9yS2OfxYhigme5bpTbmRyC+Htt6tyo2fRMHT3K1XRL/C5IQDDz37OjpPy4ndx7WInSvfSZaaOTKFja9VWqSw== @@ -1200,6 +1172,25 @@ apollo-link@^1.0.0, apollo-link@^1.0.6, apollo-link@^1.2.3: apollo-utilities "^1.0.0" zen-observable-ts "^0.8.10" +apollo-link@^1.2.11, apollo-link@^1.2.6: + version "1.2.11" + resolved "https://registry.yarnpkg.com/apollo-link/-/apollo-link-1.2.11.tgz#493293b747ad3237114ccd22e9f559e5e24a194d" + integrity sha512-PQvRCg13VduLy3X/0L79M6uOpTh5iHdxnxYuo8yL7sJlWybKRJwsv4IcRBJpMFbChOOaHY7Og9wgPo6DLKDKDA== + dependencies: + apollo-utilities "^1.2.1" + ts-invariant "^0.3.2" + tslib "^1.9.3" + zen-observable-ts "^0.8.18" + +apollo-upload-client@^10.0.0: + version "10.0.0" + resolved "https://registry.yarnpkg.com/apollo-upload-client/-/apollo-upload-client-10.0.0.tgz#6cc3d0ea2aef40bc237b655f5042809cacee1859" + integrity sha512-N0SENiEkZXoY4nl9xxrXFcj/cL0AVkSNQ4aYXSaruCBWE0aKpK6aCe4DBmiEHrK3FAsMxZPEJxBRIWNbsXT8dw== + dependencies: + apollo-link "^1.2.6" + apollo-link-http-common "^0.2.8" + extract-files "^5.0.0" + apollo-utilities@1.2.1, apollo-utilities@^1.0.0, apollo-utilities@^1.2.1: version "1.2.1" resolved "https://registry.yarnpkg.com/apollo-utilities/-/apollo-utilities-1.2.1.tgz#1c3a1ebf5607d7c8efe7636daaf58e7463b41b3c" @@ -4134,6 +4125,11 @@ extglob@^2.0.4: snapdragon "^0.8.1" to-regex "^3.0.1" +extract-files@^5.0.0: + version "5.0.1" + resolved "https://registry.yarnpkg.com/extract-files/-/extract-files-5.0.1.tgz#c9492a8410be643e260a376f0151361993d5f659" + integrity sha512-qRW6y9eKF0VbCyOoOEtFhzJ3uykAw8GKwQVXyAIqwocyEWW4m+v+evec34RwtUkkxxHh7NKBLJ6AnXM8W4dH5w== + extract-from-css@^0.4.4: version "0.4.4" resolved "https://registry.yarnpkg.com/extract-from-css/-/extract-from-css-0.4.4.tgz#1ea7df2e7c7c6eb9922fa08e8adaea486f6f8f92" @@ -4778,7 +4774,7 @@ graphlibrary@^2.2.0: dependencies: lodash "^4.17.5" -graphql-tag@^2.10.0, graphql-tag@^2.4.2: +graphql-tag@^2.10.0: version "2.10.0" resolved "https://registry.yarnpkg.com/graphql-tag/-/graphql-tag-2.10.0.tgz#87da024be863e357551b2b8700e496ee2d4353ae" integrity sha512-9FD6cw976TLLf9WYIUPCaaTpniawIjHWZSwIRZSjrfufJamcXbVVYfN2TWvJYbw0Xf2JjYbl1/f2+wDnBVw3/w== @@ -10460,6 +10456,13 @@ ts-invariant@^0.2.1: dependencies: tslib "^1.9.3" +ts-invariant@^0.3.2: + version "0.3.2" + resolved "https://registry.yarnpkg.com/ts-invariant/-/ts-invariant-0.3.2.tgz#89a2ffeb70879b777258df1df1c59383c35209b0" + integrity sha512-QsY8BCaRnHiB5T6iE4DPlJMAKEG3gzMiUco9FEt1jUXQf0XP6zi0idT0i0rMTu8A326JqNSDsmlkA9dRSh1TRg== + dependencies: + tslib "^1.9.3" + ts-jest@24.0.0, ts-jest@^23.10.5: version "24.0.0" resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-24.0.0.tgz#3f26bf2ec1fa584863a5a9c29bd8717d549efbf6" @@ -11540,6 +11543,14 @@ zen-observable-ts@^0.8.10: dependencies: zen-observable "^0.8.0" +zen-observable-ts@^0.8.18: + version "0.8.18" + resolved "https://registry.yarnpkg.com/zen-observable-ts/-/zen-observable-ts-0.8.18.tgz#ade44b1060cc4a800627856ec10b9c67f5f639c8" + integrity sha512-q7d05s75Rn1j39U5Oapg3HI2wzriVwERVo4N7uFGpIYuHB9ff02P/E92P9B8T7QVC93jCMHpbXH7X0eVR5LA7A== + dependencies: + tslib "^1.9.3" + zen-observable "^0.8.0" + zen-observable@^0.8.0: version "0.8.11" resolved "https://registry.yarnpkg.com/zen-observable/-/zen-observable-0.8.11.tgz#d3415885eeeb42ee5abb9821c95bb518fcd6d199" -- cgit v1.2.1 From 70079f1d3f779d94bb497949716a2417e445ff56 Mon Sep 17 00:00:00 2001 From: Agustin Henze Date: Tue, 2 Apr 2019 10:37:57 +0200 Subject: Fix format typo on generate-new-recovery-codes-using-ssh The rendering is broken and it's confusing when you are reading the doc about generate the recovery codes using ssh. Signed-off-by: Agustin Henze --- doc/user/profile/account/two_factor_authentication.md | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/user/profile/account/two_factor_authentication.md b/doc/user/profile/account/two_factor_authentication.md index 8b3ae19b544..69dfad829b4 100644 --- a/doc/user/profile/account/two_factor_authentication.md +++ b/doc/user/profile/account/two_factor_authentication.md @@ -161,6 +161,7 @@ a new set of recovery codes with SSH. 1. Run `ssh git@gitlab.example.com 2fa_recovery_codes`. 1. You are prompted to confirm that you want to generate new codes. Continuing this process invalidates previously saved codes. + ``` bash $ ssh git@gitlab.example.com 2fa_recovery_codes -- cgit v1.2.1 From a04e1d5e32f7ae1740ba8b9daaf3f71a5048126c Mon Sep 17 00:00:00 2001 From: Shinya Maeda Date: Tue, 2 Apr 2019 14:07:11 +0700 Subject: Backport EE change This is for merge request pipelines --- app/models/ci/pipeline.rb | 8 ----- app/serializers/merge_request_widget_entity.rb | 1 + app/serializers/pipeline_entity.rb | 2 ++ spec/models/ci/pipeline_spec.rb | 42 ---------------------- .../merge_request_widget_entity_spec.rb | 4 +++ spec/serializers/pipeline_entity_spec.rb | 10 ++++++ 6 files changed, 17 insertions(+), 50 deletions(-) diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index abac16a138d..01d96754518 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -206,10 +206,6 @@ module Ci triggered_by_merge_request(merge_request).for_source_sha(source_sha) end - scope :mergeable_merge_request_pipelines, -> (merge_request) do - triggered_by_merge_request(merge_request).where(target_sha: merge_request.target_branch_sha) - end - scope :triggered_for_branch, -> (ref) do where(source: branch_pipeline_sources).where(ref: ref, tag: false) end @@ -746,10 +742,6 @@ module Ci triggered_by_merge_request? && target_sha.present? end - def mergeable_merge_request_pipeline? - triggered_by_merge_request? && target_sha == merge_request.target_branch_sha - end - def merge_request_ref? MergeRequest.merge_request_ref?(ref) end diff --git a/app/serializers/merge_request_widget_entity.rb b/app/serializers/merge_request_widget_entity.rb index 2142ceb6122..d673f8ae896 100644 --- a/app/serializers/merge_request_widget_entity.rb +++ b/app/serializers/merge_request_widget_entity.rb @@ -20,6 +20,7 @@ class MergeRequestWidgetEntity < IssuableEntity end expose :squash expose :target_branch + expose :target_branch_sha expose :target_project_id expose :target_project_full_path do |merge_request| merge_request.project&.full_path diff --git a/app/serializers/pipeline_entity.rb b/app/serializers/pipeline_entity.rb index fba72410217..8fe5df81e6c 100644 --- a/app/serializers/pipeline_entity.rb +++ b/app/serializers/pipeline_entity.rb @@ -59,6 +59,8 @@ class PipelineEntity < Grape::Entity end expose :commit, using: CommitEntity + expose :source_sha, if: -> (pipeline, _) { pipeline.merge_request_pipeline? } + expose :target_sha, if: -> (pipeline, _) { pipeline.merge_request_pipeline? } expose :yaml_errors, if: -> (pipeline, _) { pipeline.has_yaml_errors? } expose :failure_reason, if: -> (pipeline, _) { pipeline.failure_reason? } do |pipeline| diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb index e76cf376ed1..83b0f172f03 100644 --- a/spec/models/ci/pipeline_spec.rb +++ b/spec/models/ci/pipeline_spec.rb @@ -322,48 +322,6 @@ describe Ci::Pipeline, :mailer do end end - describe '.mergeable_merge_request_pipelines' do - subject { described_class.mergeable_merge_request_pipelines(merge_request) } - - let!(:pipeline) do - create(:ci_pipeline, source: :merge_request_event, merge_request: merge_request, target_sha: target_sha) - end - - let(:merge_request) { create(:merge_request) } - let(:target_sha) { merge_request.target_branch_sha } - - it 'returns mergeable merge pipelines' do - is_expected.to eq([pipeline]) - end - - context 'when target sha does not point the head of the target branch' do - let(:target_sha) { merge_request.diff_head_sha } - - it 'returns empty array' do - is_expected.to be_empty - end - end - end - - describe '#mergeable_merge_request_pipeline?' do - subject { pipeline.mergeable_merge_request_pipeline? } - - let!(:pipeline) do - create(:ci_pipeline, source: :merge_request_event, merge_request: merge_request, target_sha: target_sha) - end - - let(:merge_request) { create(:merge_request) } - let(:target_sha) { merge_request.target_branch_sha } - - it { is_expected.to be_truthy } - - context 'when target sha does not point the head of the target branch' do - let(:target_sha) { merge_request.diff_head_sha } - - it { is_expected.to be_falsy } - end - end - describe '#merge_request_ref?' do subject { pipeline.merge_request_ref? } diff --git a/spec/serializers/merge_request_widget_entity_spec.rb b/spec/serializers/merge_request_widget_entity_spec.rb index 727fd8951f2..0e99ef38d2f 100644 --- a/spec/serializers/merge_request_widget_entity_spec.rb +++ b/spec/serializers/merge_request_widget_entity_spec.rb @@ -13,6 +13,10 @@ describe MergeRequestWidgetEntity do described_class.new(resource, request: request).as_json end + it 'has the latest sha of the target branch' do + is_expected.to include(:target_branch_sha) + end + describe 'source_project_full_path' do it 'includes the full path of the source project' do expect(subject[:source_project_full_path]).to be_present diff --git a/spec/serializers/pipeline_entity_spec.rb b/spec/serializers/pipeline_entity_spec.rb index 1d992e8a483..dba7fd91747 100644 --- a/spec/serializers/pipeline_entity_spec.rb +++ b/spec/serializers/pipeline_entity_spec.rb @@ -143,6 +143,11 @@ describe PipelineEntity do expect(subject[:flags][:detached_merge_request_pipeline]).to be_truthy end + it 'does not expose source sha and target sha' do + expect(subject[:source_sha]).to be_nil + expect(subject[:target_sha]).to be_nil + end + context 'when user is a developer' do before do project.add_developer(user) @@ -189,6 +194,11 @@ describe PipelineEntity do it 'makes atached flag true' do expect(subject[:flags][:merge_request_pipeline]).to be_truthy end + + it 'exposes source sha and target sha' do + expect(subject[:source_sha]).to be_present + expect(subject[:target_sha]).to be_present + end end end end -- cgit v1.2.1 From 3b988609fd6cf4eda3d0446a84345a09649facf7 Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Tue, 2 Apr 2019 09:58:36 +0100 Subject: Fixed positioning of the diff tree list on mobile Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/59739 --- app/assets/stylesheets/pages/diff.scss | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/assets/stylesheets/pages/diff.scss b/app/assets/stylesheets/pages/diff.scss index 1fedbd8bddb..02364180c35 100644 --- a/app/assets/stylesheets/pages/diff.scss +++ b/app/assets/stylesheets/pages/diff.scss @@ -1059,7 +1059,10 @@ table.code { flex-direction: column; .diff-tree-list { - width: 100%; + position: relative; + top: 0; + // !important is required to override inline styles of resizable sidebar + width: 100% !important; } .tree-list-holder { -- cgit v1.2.1 From 8c7f7236a453029a2c542ebeb44750593cac9656 Mon Sep 17 00:00:00 2001 From: Martin Wortschack Date: Tue, 2 Apr 2019 09:08:23 +0000 Subject: (CE Port) "Follow-up from "(EE port) Externalize strings in projects controllers"" --- app/controllers/projects/pipeline_schedules_controller.rb | 4 ++-- locale/gitlab.pot | 5 +---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/app/controllers/projects/pipeline_schedules_controller.rb b/app/controllers/projects/pipeline_schedules_controller.rb index fd5b89298a7..6b721c8fdf7 100644 --- a/app/controllers/projects/pipeline_schedules_controller.rb +++ b/app/controllers/projects/pipeline_schedules_controller.rb @@ -50,8 +50,8 @@ class Projects::PipelineSchedulesController < Projects::ApplicationController job_id = RunPipelineScheduleWorker.perform_async(schedule.id, current_user.id) if job_id - link_to_pipelines = view_context.link_to(_('Pipelines page'), project_pipelines_path(@project)) - message = _("Successfully scheduled a pipeline to run. Go to the %{link_to_pipelines} for details.").html_safe % { link_to_pipelines: link_to_pipelines } + pipelines_link_start = "" + message = _("Successfully scheduled a pipeline to run. Go to the %{pipelines_link_start}Pipelines page%{pipelines_link_end} for details.") % { pipelines_link_start: pipelines_link_start, pipelines_link_end: "" } flash[:notice] = message.html_safe else flash[:alert] = _('Unable to schedule a pipeline to run immediately') diff --git a/locale/gitlab.pot b/locale/gitlab.pot index 1e6f04c7815..fcbd34a05d5 100644 --- a/locale/gitlab.pot +++ b/locale/gitlab.pot @@ -5833,9 +5833,6 @@ msgstr "" msgid "Pipelines for last year" msgstr "" -msgid "Pipelines page" -msgstr "" - msgid "Pipelines settings for '%{project_name}' were successfully updated." msgstr "" @@ -7708,7 +7705,7 @@ msgstr "" msgid "Successfully removed email." msgstr "" -msgid "Successfully scheduled a pipeline to run. Go to the %{link_to_pipelines} for details." +msgid "Successfully scheduled a pipeline to run. Go to the %{pipelines_link_start}Pipelines page%{pipelines_link_end} for details." msgstr "" msgid "Successfully unblocked" -- cgit v1.2.1 From e540ae798b812bf4b6068fbb0e7f22ade7d5f309 Mon Sep 17 00:00:00 2001 From: Sean McGivern Date: Tue, 2 Apr 2019 10:50:58 +0100 Subject: Remove groups destroy race condition spec This was removed in the below MR in EE only, as it was causing failures related to Geo. https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/3999 --- spec/services/groups/destroy_service_spec.rb | 38 ---------------------------- 1 file changed, 38 deletions(-) diff --git a/spec/services/groups/destroy_service_spec.rb b/spec/services/groups/destroy_service_spec.rb index d80d0f5a8a8..98114ea4919 100644 --- a/spec/services/groups/destroy_service_spec.rb +++ b/spec/services/groups/destroy_service_spec.rb @@ -82,44 +82,6 @@ describe Groups::DestroyService do expect(Group.unscoped.count).to eq(2) end end - - context 'potential race conditions' do - context "when the `GroupDestroyWorker` task runs immediately" do - it "deletes the group" do - # Commit the contents of this spec's transaction so far - # so subsequent db connections can see it. - # - # DO NOT REMOVE THIS LINE, even if you see a WARNING with "No - # transaction is currently in progress". Without this, this - # spec will always be green, since the group created in setup - # cannot be seen by any other connections / threads in this spec. - Group.connection.commit_db_transaction - - group_record = run_with_new_database_connection do |conn| - conn.execute("SELECT * FROM namespaces WHERE id = #{group.id}").first - end - - expect(group_record).not_to be_nil - - # Execute the contents of `GroupDestroyWorker` in a separate thread, to - # simulate data manipulation by the Sidekiq worker (different database - # connection / transaction). - expect(GroupDestroyWorker).to receive(:perform_async).and_wrap_original do |m, group_id, user_id| - Thread.new { m[group_id, user_id] }.join(5) - end - - # Kick off the initial group destroy in a new thread, so that - # it doesn't share this spec's database transaction. - Thread.new { described_class.new(group, user).async_execute }.join(5) - - group_record = run_with_new_database_connection do |conn| - conn.execute("SELECT * FROM namespaces WHERE id = #{group.id}").first - end - - expect(group_record).to be_nil - end - end - end end describe 'synchronous delete' do -- cgit v1.2.1 From 0e66357a3e411b44647cc4d4ca10c2a19b9a3b55 Mon Sep 17 00:00:00 2001 From: Jan Provaznik Date: Tue, 2 Apr 2019 10:26:53 +0000 Subject: Monitor GraphQL with Prometheus Extends graphql's platform tracing class to observe duration of graphql methods. In graphql 1.8.11 is added prometheus class but it's not very useful for us because it uses prometheus_exporter to export results. --- app/graphql/gitlab_schema.rb | 1 + changelogs/unreleased/graphql-prometheus.yml | 5 ++++ lib/gitlab/graphql/tracing.rb | 43 ++++++++++++++++++++++++++++ spec/lib/gitlab/graphql/tracing_spec.rb | 35 ++++++++++++++++++++++ 4 files changed, 84 insertions(+) create mode 100644 changelogs/unreleased/graphql-prometheus.yml create mode 100644 lib/gitlab/graphql/tracing.rb create mode 100644 spec/lib/gitlab/graphql/tracing_spec.rb diff --git a/app/graphql/gitlab_schema.rb b/app/graphql/gitlab_schema.rb index 06d26309b5b..ecc34eacc7d 100644 --- a/app/graphql/gitlab_schema.rb +++ b/app/graphql/gitlab_schema.rb @@ -5,6 +5,7 @@ class GitlabSchema < GraphQL::Schema use Gitlab::Graphql::Authorize use Gitlab::Graphql::Present use Gitlab::Graphql::Connections + use Gitlab::Graphql::Tracing query(Types::QueryType) diff --git a/changelogs/unreleased/graphql-prometheus.yml b/changelogs/unreleased/graphql-prometheus.yml new file mode 100644 index 00000000000..180577f3aec --- /dev/null +++ b/changelogs/unreleased/graphql-prometheus.yml @@ -0,0 +1,5 @@ +--- +title: Added prometheus monitoring to GraphQL +merge_request: +author: +type: added diff --git a/lib/gitlab/graphql/tracing.rb b/lib/gitlab/graphql/tracing.rb new file mode 100644 index 00000000000..6b505e4262b --- /dev/null +++ b/lib/gitlab/graphql/tracing.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +module Gitlab + module Graphql + class Tracing < GraphQL::Tracing::PlatformTracing + self.platform_keys = { + 'lex' => 'graphql.lex', + 'parse' => 'graphql.parse', + 'validate' => 'graphql.validate', + 'analyze_query' => 'graphql.analyze', + 'analyze_multiplex' => 'graphql.analyze', + 'execute_multiplex' => 'graphql.execute', + 'execute_query' => 'graphql.execute', + 'execute_query_lazy' => 'graphql.execute', + 'execute_field' => 'graphql.execute', + 'execute_field_lazy' => 'graphql.execute' + } + + def platform_field_key(type, field) + "#{type.name}.#{field.name}" + end + + def platform_trace(platform_key, key, data, &block) + start = Gitlab::Metrics::System.monotonic_time + + yield + ensure + duration = Gitlab::Metrics::System.monotonic_time - start + + graphql_duration_seconds.observe({ platform_key: platform_key, key: key }, duration) + end + + private + + def graphql_duration_seconds + @graphql_duration_seconds ||= Gitlab::Metrics.histogram( + :graphql_duration_seconds, + 'GraphQL execution time' + ) + end + end + end +end diff --git a/spec/lib/gitlab/graphql/tracing_spec.rb b/spec/lib/gitlab/graphql/tracing_spec.rb new file mode 100644 index 00000000000..6bae737d0f6 --- /dev/null +++ b/spec/lib/gitlab/graphql/tracing_spec.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::Graphql::Tracing do + let!(:graphql_duration_seconds) { double('Gitlab::Metrics::NullMetric') } + + before do + allow(Gitlab::Metrics) + .to receive(:histogram) + .with(:graphql_duration_seconds, 'GraphQL execution time') + .and_return(graphql_duration_seconds) + end + + it 'updates graphql histogram with expected labels' do + query = 'query { users { id } }' + + expect_metric('graphql.lex', 'lex') + expect_metric('graphql.parse', 'parse') + expect_metric('graphql.validate', 'validate') + expect_metric('graphql.analyze', 'analyze_multiplex') + expect_metric('graphql.execute', 'execute_query_lazy') + expect_metric('graphql.execute', 'execute_multiplex') + + GitlabSchema.execute(query) + end + + private + + def expect_metric(platform_key, key) + expect(graphql_duration_seconds) + .to receive(:observe) + .with({ platform_key: platform_key, key: key }, be > 0.0) + end +end -- cgit v1.2.1 From 52f9315192b6aee42f288f53dbd97a9f3faea25a Mon Sep 17 00:00:00 2001 From: Sergiu Marton Date: Tue, 2 Apr 2019 10:33:21 +0000 Subject: Fix comment typo --- app/assets/javascripts/notes/components/noteable_note.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/notes/components/noteable_note.vue b/app/assets/javascripts/notes/components/noteable_note.vue index 5fa0ab3de98..d2cfeff53e8 100644 --- a/app/assets/javascripts/notes/components/noteable_note.vue +++ b/app/assets/javascripts/notes/components/noteable_note.vue @@ -96,7 +96,7 @@ export default { return ''; } - // We need to do this to ensure we have the currect sentence order + // We need to do this to ensure we have the correct sentence order // when translating this as the sentence order may change from one // language to the next. See: // https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/24427#note_133713771 -- cgit v1.2.1 From c14927dcd1568c33c3ae4cc846eff12fc4aa362a Mon Sep 17 00:00:00 2001 From: Lukas Eipert Date: Tue, 2 Apr 2019 12:51:30 +0200 Subject: Resolve CE/EE difference in FE dependency files This resolved the one conflict we have in CE/EE. --- package.json | 2 ++ yarn.lock | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index a2d96cc551a..d672370e9a3 100644 --- a/package.json +++ b/package.json @@ -56,11 +56,13 @@ "d3-array": "^1.2.1", "d3-axis": "^1.0.8", "d3-brush": "^1.0.4", + "d3-ease": "^1.0.3", "d3-scale": "^1.0.7", "d3-selection": "^1.2.0", "d3-shape": "^1.2.0", "d3-time": "^1.0.8", "d3-time-format": "^2.1.1", + "d3-transition": "^1.1.1", "dateformat": "^3.0.3", "deckar01-task_list": "^2.2.0", "diff": "^3.4.0", diff --git a/yarn.lock b/yarn.lock index 5d40bec659d..61f2736cab8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2804,7 +2804,7 @@ d3-dsv@1, d3-dsv@1.0.8: iconv-lite "0.4" rw "1" -d3-ease@1, d3-ease@1.0.3: +d3-ease@1, d3-ease@1.0.3, d3-ease@^1.0.3: version "1.0.3" resolved "https://registry.yarnpkg.com/d3-ease/-/d3-ease-1.0.3.tgz#68bfbc349338a380c44d8acc4fbc3304aa2d8c0e" integrity sha1-aL+8NJM4o4DETYrMT7wzBKotjA4= @@ -2920,7 +2920,7 @@ d3-timer@1, d3-timer@1.0.7: resolved "https://registry.yarnpkg.com/d3-timer/-/d3-timer-1.0.7.tgz#df9650ca587f6c96607ff4e60cc38229e8dd8531" integrity sha512-vMZXR88XujmG/L5oB96NNKH5lCWwiLM/S2HyyAQLcjWJCloK5shxta4CwOFYLZoY3AWX73v8Lgv4cCAdWtRmOA== -d3-transition@1, d3-transition@1.1.1: +d3-transition@1, d3-transition@1.1.1, d3-transition@^1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/d3-transition/-/d3-transition-1.1.1.tgz#d8ef89c3b848735b060e54a39b32aaebaa421039" integrity sha512-xeg8oggyQ+y5eb4J13iDgKIjUcEfIOZs2BqV/eEmXm2twx80wTzJ4tB4vaZ5BKfz7XsI/DFmQL5me6O27/5ykQ== -- cgit v1.2.1 From 5343eb06004217da32260d42e97f57ab438a3278 Mon Sep 17 00:00:00 2001 From: Filipa Lacerda Date: Tue, 2 Apr 2019 10:56:32 +0000 Subject: Adds documentation about the utility classes --- doc/development/fe_guide/style_guide_scss.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/doc/development/fe_guide/style_guide_scss.md b/doc/development/fe_guide/style_guide_scss.md index b09243598d5..6f6b361f423 100644 --- a/doc/development/fe_guide/style_guide_scss.md +++ b/doc/development/fe_guide/style_guide_scss.md @@ -5,6 +5,15 @@ easy to maintain, and performant for the end-user. ## Rules +### Utility Classes +As part of the effort for [cleaning up our CSS and moving our components into GitLab-UI](https://gitlab.com/groups/gitlab-org/-/epics/950) +led by the [GitLab UI WG](https://gitlab.com/gitlab-com/www-gitlab-com/merge_requests/20623) we prefer the use of utility classes over adding new CSS. However, complex CSS can be addressed by adding component classes. + +We have a few internal utility classes in [`common.scss`](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/app/assets/stylesheets/framework/common.scss) +and we use [Bootstrap's Utility Classes](https://getbootstrap.com/docs/4.3/utilities/) + +New utility classes should be added to [`common.scss`](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/app/assets/stylesheets/framework/common.scss). + ### Naming Filenames should use `snake_case`. -- cgit v1.2.1 From 351b39f172bf77f4eb0e84fb2e5a71af9fe72348 Mon Sep 17 00:00:00 2001 From: Igor Date: Tue, 2 Apr 2019 11:01:07 +0000 Subject: Backport splitting approval changes from CE Author and committers approvals are split in EE This commit provides backports for those changes This reverts commit 886f00bcba23d67e2c86591c2eb5359ef457a2f9. --- app/models/commit_collection.rb | 4 ++-- app/models/merge_request.rb | 8 ++------ spec/models/commit_collection_spec.rb | 14 +++++++------- spec/models/merge_request_spec.rb | 27 ++++++--------------------- 4 files changed, 17 insertions(+), 36 deletions(-) diff --git a/app/models/commit_collection.rb b/app/models/commit_collection.rb index 52524456439..e8df46e1cc3 100644 --- a/app/models/commit_collection.rb +++ b/app/models/commit_collection.rb @@ -20,8 +20,8 @@ class CommitCollection commits.each(&block) end - def authors - emails = without_merge_commits.map(&:author_email).uniq + def committers + emails = without_merge_commits.map(&:committer_email).uniq User.by_any_email(emails) end diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index 50e6391a700..b780b67492f 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -323,12 +323,8 @@ class MergeRequest < ApplicationRecord work_in_progress?(title) ? title : "WIP: #{title}" end - def commit_authors - @commit_authors ||= commits.authors - end - - def authors - User.from_union([commit_authors, User.where(id: self.author_id)]) + def committers + @committers ||= commits.committers end # Verifies if title has changed not taking into account WIP prefix diff --git a/spec/models/commit_collection_spec.rb b/spec/models/commit_collection_spec.rb index 8a7fcb39fe2..0bdf83fa90f 100644 --- a/spec/models/commit_collection_spec.rb +++ b/spec/models/commit_collection_spec.rb @@ -14,26 +14,26 @@ describe CommitCollection do end end - describe '.authors' do + describe '.committers' do it 'returns a relation of users when users are found' do - user = create(:user, email: commit.author_email.upcase) + user = create(:user, email: commit.committer_email.upcase) collection = described_class.new(project, [commit]) - expect(collection.authors).to contain_exactly(user) + expect(collection.committers).to contain_exactly(user) end - it 'returns empty array when authors cannot be found' do + it 'returns empty array when committers cannot be found' do collection = described_class.new(project, [commit]) - expect(collection.authors).to be_empty + expect(collection.committers).to be_empty end it 'excludes authors of merge commits' do commit = project.commit("60ecb67744cb56576c30214ff52294f8ce2def98") - create(:user, email: commit.author_email.upcase) + create(:user, email: commit.committer_email.upcase) collection = described_class.new(project, [commit]) - expect(collection.authors).to be_empty + expect(collection.committers).to be_empty end end diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb index fb32f72e2de..892fdc4e4e9 100644 --- a/spec/models/merge_request_spec.rb +++ b/spec/models/merge_request_spec.rb @@ -476,7 +476,6 @@ describe MergeRequest do it 'does not cache issues from external trackers' do issue = ExternalIssue.new('JIRA-123', subject.project) commit = double('commit1', safe_message: "Fixes #{issue.to_reference}") - allow(subject).to receive(:commits).and_return([commit]) expect { subject.cache_merge_request_closes_issues!(subject.author) }.not_to raise_error @@ -1065,31 +1064,17 @@ describe MergeRequest do end end - describe '#commit_authors' do - it 'returns all the authors of every commit in the merge request' do - users = subject.commits.without_merge_commits.map(&:author_email).uniq.map do |email| - create(:user, email: email) - end - - expect(subject.commit_authors).to match_array(users) - end - - it 'returns an empty array if no author is associated with a user' do - expect(subject.commit_authors).to be_empty - end - end - - describe '#authors' do - it 'returns a list with all the commit authors in the merge request and author' do - users = subject.commits.without_merge_commits.map(&:author_email).uniq.map do |email| + describe '#committers' do + it 'returns all the committers of every commit in the merge request' do + users = subject.commits.without_merge_commits.map(&:committer_email).uniq.map do |email| create(:user, email: email) end - expect(subject.authors).to match_array([subject.author, *users]) + expect(subject.committers).to match_array(users) end - it 'returns only the author if no committer is associated with a user' do - expect(subject.authors).to contain_exactly(subject.author) + it 'returns an empty array if no committer is associated with a user' do + expect(subject.committers).to be_empty end end -- cgit v1.2.1 From e37383d45395c0c7cefc1dda3be12bd4c2d6cc4f Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Fri, 29 Mar 2019 09:23:51 -0700 Subject: Cache FindCommit results in pipelines view For each pipeline, the controller will call `Pipeline#latest?` to determine if the pipeline's ref is the latest for that branch. Since it's likely that the same branches are being used in each pipeline, we can reduce Gitaly overhead by caching the results of the FindCommit call. --- app/controllers/projects/pipelines_controller.rb | 14 ++++++++++---- changelogs/unreleased/sh-cache-pipeline-find-commits.yml | 5 +++++ spec/controllers/projects/pipelines_controller_spec.rb | 2 ++ 3 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 changelogs/unreleased/sh-cache-pipeline-find-commits.yml diff --git a/app/controllers/projects/pipelines_controller.rb b/app/controllers/projects/pipelines_controller.rb index 6a86f8ca729..c306ba3ffcf 100644 --- a/app/controllers/projects/pipelines_controller.rb +++ b/app/controllers/projects/pipelines_controller.rb @@ -31,10 +31,7 @@ class Projects::PipelinesController < Projects::ApplicationController Gitlab::PollingInterval.set_header(response, interval: POLLING_INTERVAL) render json: { - pipelines: PipelineSerializer - .new(project: @project, current_user: @current_user) - .with_pagination(request, response) - .represent(@pipelines, disable_coverage: true, preload: true), + pipelines: serialize_pipelines, count: { all: @pipelines_count, running: @running_count, @@ -150,6 +147,15 @@ class Projects::PipelinesController < Projects::ApplicationController private + def serialize_pipelines + ::Gitlab::GitalyClient.allow_ref_name_caching do + PipelineSerializer + .new(project: @project, current_user: @current_user) + .with_pagination(request, response) + .represent(@pipelines, disable_coverage: true, preload: true) + end + end + def render_show respond_to do |format| format.html do diff --git a/changelogs/unreleased/sh-cache-pipeline-find-commits.yml b/changelogs/unreleased/sh-cache-pipeline-find-commits.yml new file mode 100644 index 00000000000..2acf180d6fa --- /dev/null +++ b/changelogs/unreleased/sh-cache-pipeline-find-commits.yml @@ -0,0 +1,5 @@ +--- +title: Cache FindCommit results in pipelines view +merge_request: 26776 +author: +type: performance diff --git a/spec/controllers/projects/pipelines_controller_spec.rb b/spec/controllers/projects/pipelines_controller_spec.rb index ece8532cb84..b64ae552efc 100644 --- a/spec/controllers/projects/pipelines_controller_spec.rb +++ b/spec/controllers/projects/pipelines_controller_spec.rb @@ -28,6 +28,8 @@ describe Projects::PipelinesController do end it 'returns serialized pipelines', :request_store do + expect(::Gitlab::GitalyClient).to receive(:allow_ref_name_caching).and_call_original + queries = ActiveRecord::QueryRecorder.new do get_pipelines_index_json end -- cgit v1.2.1 From eebf24ead51a28863126f0b144e4fcdc5a6b2916 Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Tue, 2 Apr 2019 13:24:36 +0100 Subject: Fixes duplicate diff too large error messages Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/59802 --- app/assets/javascripts/diffs/components/diff_file.vue | 4 ---- changelogs/unreleased/fixed-duplicated-large-text-on-diffs.yml | 5 +++++ locale/gitlab.pot | 3 --- spec/javascripts/diffs/components/diff_file_spec.js | 8 +++----- 4 files changed, 8 insertions(+), 12 deletions(-) create mode 100644 changelogs/unreleased/fixed-duplicated-large-text-on-diffs.yml diff --git a/app/assets/javascripts/diffs/components/diff_file.vue b/app/assets/javascripts/diffs/components/diff_file.vue index 58a9605c181..f5876a73eff 100644 --- a/app/assets/javascripts/diffs/components/diff_file.vue +++ b/app/assets/javascripts/diffs/components/diff_file.vue @@ -188,10 +188,6 @@ export default { />
-
- {{ __('This source diff could not be displayed because it is too large.') }} - -
diff --git a/changelogs/unreleased/fixed-duplicated-large-text-on-diffs.yml b/changelogs/unreleased/fixed-duplicated-large-text-on-diffs.yml new file mode 100644 index 00000000000..770186a64b0 --- /dev/null +++ b/changelogs/unreleased/fixed-duplicated-large-text-on-diffs.yml @@ -0,0 +1,5 @@ +--- +title: Fixed duplicated diff too large error message +merge_request: +author: +type: fixed diff --git a/locale/gitlab.pot b/locale/gitlab.pot index fcbd34a05d5..bb145a0984f 100644 --- a/locale/gitlab.pot +++ b/locale/gitlab.pot @@ -8278,9 +8278,6 @@ msgstr "" msgid "This setting will update the hostname that is used to generate private commit emails. %{learn_more}" msgstr "" -msgid "This source diff could not be displayed because it is too large." -msgstr "" - msgid "This timeout will take precedence when lower than project-defined timeout and accepts a human readable time input language like \"1 hour\". Values without specification represent seconds." msgstr "" diff --git a/spec/javascripts/diffs/components/diff_file_spec.js b/spec/javascripts/diffs/components/diff_file_spec.js index d9b298e84da..ef4589ada48 100644 --- a/spec/javascripts/diffs/components/diff_file_spec.js +++ b/spec/javascripts/diffs/components/diff_file_spec.js @@ -141,18 +141,16 @@ describe('DiffFile', () => { it('should have too large warning and blob link', done => { const BLOB_LINK = '/file/view/path'; vm.file.viewer.error = diffViewerErrors.too_large; + vm.file.viewer.error_message = + 'This source diff could not be displayed because it is too large'; vm.file.view_path = BLOB_LINK; + vm.file.renderIt = true; vm.$nextTick(() => { expect(vm.$el.innerText).toContain( 'This source diff could not be displayed because it is too large', ); - expect(vm.$el.querySelector('.js-too-large-diff')).toBeDefined(); - expect( - vm.$el.querySelector('.js-too-large-diff a').href.indexOf(BLOB_LINK), - ).toBeGreaterThan(-1); - done(); }); }); -- cgit v1.2.1 From 3da182cc753c6c42116ec66da511c13a7ff98a4c Mon Sep 17 00:00:00 2001 From: Walmyr Lima Date: Tue, 2 Apr 2019 14:36:21 +0200 Subject: Fix typo on tests style guide --- qa/STYLE_GUIDE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qa/STYLE_GUIDE.md b/qa/STYLE_GUIDE.md index f85e7492409..900f7456e1a 100644 --- a/qa/STYLE_GUIDE.md +++ b/qa/STYLE_GUIDE.md @@ -43,4 +43,4 @@ end Notice that in the above example, before clicking the `:operations_environments_link`, another element is hovered over. -> We can create these methods as helpers to abstrac multi-step navigation. \ No newline at end of file +> We can create these methods as helpers to abstract multi-step navigation. \ No newline at end of file -- cgit v1.2.1 From 1f4bc814ab91eae9fbfa595fe63fa4bcc6a67204 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Tue, 26 Mar 2019 17:01:19 +0100 Subject: Backport EE changes to gitlab:env:info This backports EE specific changes for the Rake task `gitlab:env:info`, wrapping them in a conditional. There is no way to inject code in the middle of a Rake task in EE, so unfortunately this is the best we can do. --- lib/tasks/gitlab/info.rake | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/lib/tasks/gitlab/info.rake b/lib/tasks/gitlab/info.rake index 7872e5b08c0..8fadadccce9 100644 --- a/lib/tasks/gitlab/info.rake +++ b/lib/tasks/gitlab/info.rake @@ -14,6 +14,12 @@ namespace :gitlab do rake_version = run_and_match(%w(rake --version), /[\d\.]+/).try(:to_s) # check redis version redis_version = run_and_match(%w(redis-cli --version), /redis-cli (\d+\.\d+\.\d+)/).to_a + + # check for system defined proxies + if Gitlab.ee? + proxies = Gitlab::Proxy.detect_proxy.map {|k, v| "#{k}: #{v}"}.join("\n\t\t") + end + # check Git version git_version = run_and_match([Gitlab.config.git.bin_path, '--version'], /git version ([\d\.]+)/).to_a # check Go version @@ -22,6 +28,11 @@ namespace :gitlab do puts "" puts "System information".color(:yellow) puts "System:\t\t#{os_name || "unknown".color(:red)}" + + if Gitlab.ee? + puts "Proxy:\t\t#{proxies.present? ? proxies.color(:green) : "no"}" + end + puts "Current User:\t#{run_command(%w(whoami))}" puts "Using RVM:\t#{rvm_version.present? ? "yes".color(:green) : "no"}" puts "RVM Version:\t#{rvm_version}" if rvm_version.present? @@ -39,6 +50,15 @@ namespace :gitlab do http_clone_url = project.http_url_to_repo ssh_clone_url = project.ssh_url_to_repo + if Gitlab.ee? + geo_node_type = + if Gitlab::Geo.current_node + Gitlab::Geo.current_node.primary ? 'Primary' : 'Secondary' + else + 'Undefined'.color(:red) + end + end + omniauth_providers = Gitlab.config.omniauth.providers.map { |provider| provider['name'] } puts "" @@ -51,6 +71,13 @@ namespace :gitlab do puts "URL:\t\t#{Gitlab.config.gitlab.url}" puts "HTTP Clone URL:\t#{http_clone_url}" puts "SSH Clone URL:\t#{ssh_clone_url}" + + if Gitlab.ee? + puts "Elasticsearch:\t#{Gitlab::CurrentSettings.current_application_settings.elasticsearch_indexing? ? "yes".color(:green) : "no"}" + puts "Geo:\t\t#{Gitlab::Geo.enabled? ? "yes".color(:green) : "no"}" + puts "Geo node:\t#{geo_node_type}" if Gitlab::Geo.enabled? + end + puts "Using LDAP:\t#{Gitlab.config.ldap.enabled ? "yes".color(:green) : "no"}" puts "Using Omniauth:\t#{Gitlab::Auth.omniauth_enabled? ? "yes".color(:green) : "no"}" puts "Omniauth Providers: #{omniauth_providers.join(', ')}" if Gitlab::Auth.omniauth_enabled? -- cgit v1.2.1 From 35b9274f12f29524855237bfdcd864497d62de95 Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Tue, 2 Apr 2019 13:20:26 +0000 Subject: Stop calling UnlinkRepositoryFromObjectPool RPC Fixes https://gitlab.com/gitlab-org/gitlab-ce/issues/59777. In earlier iterations of our implementation of Git object deduplication we thought we would be making extensive use of Git remotes in pool repositories in the future, and that we should manage these remotes carefully from the start. We now expect we only care about one remote, namely the source project. The other remotes are there only for forensic purposes. Before this MR we tried to also remove pool remotes when member projects got deleted, with the UnlinkRepositoryFromObjectPool RPC. This is fragile when there are race conditions (see https://gitlab.com/gitlab-org/gitaly/issues/1568#note_153955926). We have spent some time making this RPC less fragile in https://gitlab.com/gitlab-org/gitaly/merge_requests/1151 but looking at this problem again, I think we should just stop calling it. --- app/models/pool_repository.rb | 5 +---- app/models/project.rb | 2 +- lib/gitlab/git/object_pool.rb | 2 +- lib/gitlab/gitaly_client/object_pool_service.rb | 10 ---------- spec/models/pool_repository_spec.rb | 6 +++--- 5 files changed, 6 insertions(+), 19 deletions(-) diff --git a/app/models/pool_repository.rb b/app/models/pool_repository.rb index 35c718365b4..7934118761e 100644 --- a/app/models/pool_repository.rb +++ b/app/models/pool_repository.rb @@ -81,10 +81,7 @@ class PoolRepository < ApplicationRecord object_pool.link(repository.raw) end - # This RPC can cause data loss, as not all objects are present the local repository - def unlink_repository(repository) - object_pool.unlink_repository(repository.raw) - + def mark_obsolete_if_last(repository) if member_projects.where.not(id: repository.project.id).exists? true else diff --git a/app/models/project.rb b/app/models/project.rb index 82c2f9090c8..e2869fc2ad5 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -2128,7 +2128,7 @@ class Project < ApplicationRecord end def leave_pool_repository - pool_repository&.unlink_repository(repository) && update_column(:pool_repository_id, nil) + pool_repository&.mark_obsolete_if_last(repository) && update_column(:pool_repository_id, nil) end def link_pool_repository diff --git a/lib/gitlab/git/object_pool.rb b/lib/gitlab/git/object_pool.rb index e93ca3e11f8..8eb3c28ab70 100644 --- a/lib/gitlab/git/object_pool.rb +++ b/lib/gitlab/git/object_pool.rb @@ -8,7 +8,7 @@ module Gitlab GL_REPOSITORY = "" delegate :exists?, :size, to: :repository - delegate :unlink_repository, :delete, to: :object_pool_service + delegate :delete, to: :object_pool_service attr_reader :storage, :relative_path, :source_repository, :gl_project_path diff --git a/lib/gitlab/gitaly_client/object_pool_service.rb b/lib/gitlab/gitaly_client/object_pool_service.rb index 6e7ede5fd18..ce1fb4d68ae 100644 --- a/lib/gitlab/gitaly_client/object_pool_service.rb +++ b/lib/gitlab/gitaly_client/object_pool_service.rb @@ -33,16 +33,6 @@ module Gitlab GitalyClient.call(storage, :object_pool_service, :link_repository_to_object_pool, request, timeout: GitalyClient.fast_timeout) end - - def unlink_repository(repository) - request = Gitaly::UnlinkRepositoryFromObjectPoolRequest.new( - object_pool: object_pool, - repository: repository.gitaly_repository - ) - - GitalyClient.call(storage, :object_pool_service, :unlink_repository_from_object_pool, - request, timeout: GitalyClient.fast_timeout) - end end end end diff --git a/spec/models/pool_repository_spec.rb b/spec/models/pool_repository_spec.rb index 112d4ab56fc..e5a3a3ad66e 100644 --- a/spec/models/pool_repository_spec.rb +++ b/spec/models/pool_repository_spec.rb @@ -24,14 +24,14 @@ describe PoolRepository do end end - describe '#unlink_repository' do + describe '#mark_obsolete_if_last' do let(:pool) { create(:pool_repository, :ready) } context 'when the last member leaves' do it 'schedules pool removal' do expect(::ObjectPool::DestroyWorker).to receive(:perform_async).with(pool.id).and_call_original - pool.unlink_repository(pool.source_project.repository) + pool.mark_obsolete_if_last(pool.source_project.repository) end end @@ -40,7 +40,7 @@ describe PoolRepository do create(:project, :repository, pool_repository: pool) expect(::ObjectPool::DestroyWorker).not_to receive(:perform_async).with(pool.id) - pool.unlink_repository(pool.source_project.repository) + pool.mark_obsolete_if_last(pool.source_project.repository) end end end -- cgit v1.2.1 From 88a0eab992a0acd7adbdee1d8cb5ab77053de9dd Mon Sep 17 00:00:00 2001 From: Marcia Ramos Date: Tue, 2 Apr 2019 13:30:26 +0000 Subject: Fix conflicts with master Pull master --- doc/ci/variables/README.md | 102 +--------------------------- doc/ci/variables/predefined_variables.md | 110 +++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+), 101 deletions(-) create mode 100644 doc/ci/variables/predefined_variables.md diff --git a/doc/ci/variables/README.md b/doc/ci/variables/README.md index 8827961d86c..12b027e7d79 100644 --- a/doc/ci/variables/README.md +++ b/doc/ci/variables/README.md @@ -40,107 +40,7 @@ about which variables are [not supported](where_variables_can_be_used.md). ## Predefined environment variables -Some of the predefined environment variables are available only if a minimum -version of [GitLab Runner](https://docs.gitlab.com/runner/) is used. Consult the table below to find the -version of Runner required. - -NOTE: **Note:** -Starting with GitLab 9.0, we have deprecated some variables. -Read the [deprecated variables](deprecated_variables.md) -document to find out their replacements. **You are strongly advised -to use the new variables as we will remove the old ones in future -GitLab releases.** - -| Variable | GitLab | Runner | Description | -|-------------------------------------------|--------|--------|-------------| -| **ARTIFACT_DOWNLOAD_ATTEMPTS** | 8.15 | 1.9 | Number of attempts to download artifacts running a job | -| **CHAT_INPUT** | 10.6 | all | Additional arguments passed in the [ChatOps](../chatops/README.md) command | -| **CHAT_CHANNEL** | 10.6 | all | Source chat channel which triggered the [ChatOps](../chatops/README.md) command | -| **CI** | all | 0.4 | Mark that job is executed in CI environment | -| **CI_COMMIT_BEFORE_SHA** | 11.2 | all | The previous latest commit present on a branch before a push request. | -| **CI_COMMIT_DESCRIPTION** | 10.8 | all | The description of the commit: the message without first line, if the title is shorter than 100 characters; full message in other case. | -| **CI_COMMIT_MESSAGE** | 10.8 | all | The full commit message. | -| **CI_COMMIT_REF_NAME** | 9.0 | all | The branch or tag name for which project is built | -| **CI_COMMIT_REF_SLUG** | 9.0 | all | `$CI_COMMIT_REF_NAME` lowercased, shortened to 63 bytes, and with everything except `0-9` and `a-z` replaced with `-`. No leading / trailing `-`. Use in URLs, host names and domain names. | -| **CI_COMMIT_SHA** | 9.0 | all | The commit revision for which project is built | -| **CI_COMMIT_SHORT_SHA** | 11.7 | all | The first eight characters of `CI_COMMIT_SHA` | -| **CI_COMMIT_TAG** | 9.0 | 0.5 | The commit tag name. Present only when building tags. | -| **CI_COMMIT_TITLE** | 10.8 | all | The title of the commit - the full first line of the message | -| **CI_CONFIG_PATH** | 9.4 | 0.5 | The path to CI config file. Defaults to `.gitlab-ci.yml` | -| **CI_DEBUG_TRACE** | all | 1.7 | Whether [debug tracing](#debug-tracing) is enabled | -| **CI_DEPLOY_PASSWORD** | 10.8 | all | Authentication password of the [GitLab Deploy Token][gitlab-deploy-token], only present if the Project has one related.| -| **CI_DEPLOY_USER** | 10.8 | all | Authentication username of the [GitLab Deploy Token][gitlab-deploy-token], only present if the Project has one related.| -| **CI_DISPOSABLE_ENVIRONMENT** | all | 10.1 | Marks that the job is executed in a disposable environment (something that is created only for this job and disposed of/destroyed after the execution - all executors except `shell` and `ssh`). If the environment is disposable, it is set to true, otherwise it is not defined at all. | -| **CI_ENVIRONMENT_NAME** | 8.15 | all | The name of the environment for this job. Only present if [`environment:name`](../yaml/README.md#environmentname) is set. | -| **CI_ENVIRONMENT_SLUG** | 8.15 | all | A simplified version of the environment name, suitable for inclusion in DNS, URLs, Kubernetes labels, etc. Only present if [`environment:name`](../yaml/README.md#environmentname) is set. | -| **CI_ENVIRONMENT_URL** | 9.3 | all | The URL of the environment for this job. Only present if [`environment:url`](../yaml/README.md#environmenturl) is set. | -| **CI_JOB_ID** | 9.0 | all | The unique id of the current job that GitLab CI uses internally | -| **CI_JOB_MANUAL** | 8.12 | all | The flag to indicate that job was manually started | -| **CI_JOB_NAME** | 9.0 | 0.5 | The name of the job as defined in `.gitlab-ci.yml` | -| **CI_JOB_STAGE** | 9.0 | 0.5 | The name of the stage as defined in `.gitlab-ci.yml` | -| **CI_JOB_TOKEN** | 9.0 | 1.2 | Token used for authenticating with the [GitLab Container Registry][registry] and downloading [dependent repositories][dependent-repositories] | -| **CI_JOB_URL** | 11.1 | 0.5 | Job details URL | -| **CI_MERGE_REQUEST_ID** | 11.6 | all | The ID of the merge request if [the pipelines are for merge requests](../merge_request_pipelines/index.md) | -| **CI_MERGE_REQUEST_IID** | 11.6 | all | The IID of the merge request if [the pipelines are for merge requests](../merge_request_pipelines/index.md) | -| **CI_MERGE_REQUEST_PROJECT_ID** | 11.6 | all | The ID of the project of the merge request if [the pipelines are for merge requests](../merge_request_pipelines/index.md) | -| **CI_MERGE_REQUEST_PROJECT_PATH** | 11.6 | all | The path of the project of the merge request if [the pipelines are for merge requests](../merge_request_pipelines/index.md) (e.g. `namespace/awesome-project`) | -| **CI_MERGE_REQUEST_PROJECT_URL** | 11.6 | all | The URL of the project of the merge request if [the pipelines are for merge requests](../merge_request_pipelines/index.md) (e.g. `http://192.168.10.15:3000/namespace/awesome-project`) | -| **CI_MERGE_REQUEST_REF_PATH** | 11.6 | all | The ref path of the merge request if [the pipelines are for merge requests](../merge_request_pipelines/index.md). (e.g. `refs/merge-requests/1/head`) | -| **CI_MERGE_REQUEST_SOURCE_BRANCH_NAME** | 11.6 | all | The source branch name of the merge request if [the pipelines are for merge requests](../merge_request_pipelines/index.md) | -| **CI_MERGE_REQUEST_SOURCE_BRANCH_SHA** | 11.9 | all | The HEAD sha of the source branch of the merge request if [the pipelines are for merge requests](../merge_request_pipelines/index.md) | -| **CI_MERGE_REQUEST_SOURCE_PROJECT_ID** | 11.6 | all | The ID of the source project of the merge request if [the pipelines are for merge requests](../merge_request_pipelines/index.md) | -| **CI_MERGE_REQUEST_SOURCE_PROJECT_PATH** | 11.6 | all | The path of the source project of the merge request if [the pipelines are for merge requests](../merge_request_pipelines/index.md) | -| **CI_MERGE_REQUEST_SOURCE_PROJECT_URL** | 11.6 | all | The URL of the source project of the merge request if [the pipelines are for merge requests](../merge_request_pipelines/index.md) | -| **CI_MERGE_REQUEST_TARGET_BRANCH_NAME** | 11.6 | all | The target branch name of the merge request if [the pipelines are for merge requests](../merge_request_pipelines/index.md) | -| **CI_MERGE_REQUEST_TARGET_BRANCH_SHA** | 11.9 | all | The HEAD sha of the target branch of the merge request if [the pipelines are for merge requests](../merge_request_pipelines/index.md) | -| **CI_MERGE_REQUEST_TITLE** | 11.9 | all | The title of the merge request if [the pipelines are for merge requests](../merge_request_pipelines/index.md) | -| **CI_MERGE_REQUEST_ASSIGNEES** | 11.9 | all | Comma-separated list of usernames of assignees for the merge request if [the pipelines are for merge requests](../merge_request_pipelines/index.md). [Multiple assignees for merge requests](https://gitlab.com/gitlab-org/gitlab-ee/issues/2004) is scheduled for a future release | -| **CI_MERGE_REQUEST_MILESTONE** | 11.9 | all | The milestone title of the merge request if [the pipelines are for merge requests](../merge_request_pipelines/index.md) | -| **CI_MERGE_REQUEST_LABELS** | 11.9 | all | Comma-separated label names of the merge request if [the pipelines are for merge requests](../merge_request_pipelines/index.md) | -| **CI_NODE_INDEX** | 11.5 | all | Index of the job in the job set. If the job is not parallelized, this variable is not set. | -| **CI_NODE_TOTAL** | 11.5 | all | Total number of instances of this job running in parallel. If the job is not parallelized, this variable is set to `1`. | -| **CI_API_V4_URL** | 11.7 | all | The GitLab API v4 root URL | -| **CI_PAGES_DOMAIN** | 11.8 | all | The configured domain that hosts GitLab Pages. | -| **CI_PAGES_URL** | 11.8 | all | URL to GitLab Pages-built pages. Always belongs to a subdomain of `CI_PAGES_DOMAIN`. | -| **CI_PIPELINE_ID** | 8.10 | all | The unique id of the current pipeline that GitLab CI uses internally | -| **CI_PIPELINE_IID** | 11.0 | all | The unique id of the current pipeline scoped to project | -| **CI_PIPELINE_SOURCE** | 10.0 | all | Indicates how the pipeline was triggered. Possible options are: `push`, `web`, `trigger`, `schedule`, `api`, and `pipeline`. For pipelines created before GitLab 9.5, this will show as `unknown` | -| **CI_PIPELINE_TRIGGERED** | all | all | The flag to indicate that job was [triggered] | -| **CI_PIPELINE_URL** | 11.1 | 0.5 | Pipeline details URL | -| **CI_PROJECT_DIR** | all | all | The full path where the repository is cloned and where the job is run. If the GitLab Runner `builds_dir` parameter is set, this variable is set relative to the value of `builds_dir`. For more information, see [Advanced configuration](https://docs.gitlab.com/runner/configuration/advanced-configuration.html#the-runners-section) for GitLab Runner. | -| **CI_PROJECT_ID** | all | all | The unique id of the current project that GitLab CI uses internally | -| **CI_PROJECT_NAME** | 8.10 | 0.5 | The project name that is currently being built (actually it is project folder name) | -| **CI_PROJECT_NAMESPACE** | 8.10 | 0.5 | The project namespace (username or groupname) that is currently being built | -| **CI_PROJECT_PATH** | 8.10 | 0.5 | The namespace with project name | -| **CI_PROJECT_PATH_SLUG** | 9.3 | all | `$CI_PROJECT_PATH` lowercased and with everything except `0-9` and `a-z` replaced with `-`. Use in URLs and domain names. | -| **CI_PROJECT_URL** | 8.10 | 0.5 | The HTTP(S) address to access project | -| **CI_PROJECT_VISIBILITY** | 10.3 | all | The project visibility (internal, private, public) | -| **CI_REGISTRY** | 8.10 | 0.5 | If the Container Registry is enabled it returns the address of GitLab's Container Registry | -| **CI_REGISTRY_IMAGE** | 8.10 | 0.5 | If the Container Registry is enabled for the project it returns the address of the registry tied to the specific project | -| **CI_REGISTRY_PASSWORD** | 9.0 | all | The password to use to push containers to the GitLab Container Registry | -| **CI_REGISTRY_USER** | 9.0 | all | The username to use to push containers to the GitLab Container Registry | -| **CI_REPOSITORY_URL** | 9.0 | all | The URL to clone the Git repository | -| **CI_RUNNER_DESCRIPTION** | 8.10 | 0.5 | The description of the runner as saved in GitLab | -| **CI_RUNNER_EXECUTABLE_ARCH** | all | 10.6 | The OS/architecture of the GitLab Runner executable (note that this is not necessarily the same as the environment of the executor) | -| **CI_RUNNER_ID** | 8.10 | 0.5 | The unique id of runner being used | -| **CI_RUNNER_REVISION** | all | 10.6 | GitLab Runner revision that is executing the current job | -| **CI_RUNNER_TAGS** | 8.10 | 0.5 | The defined runner tags | -| **CI_RUNNER_VERSION** | all | 10.6 | GitLab Runner version that is executing the current job | -| **CI_SERVER** | all | all | Mark that job is executed in CI environment | -| **CI_SERVER_NAME** | all | all | The name of CI server that is used to coordinate jobs | -| **CI_SERVER_REVISION** | all | all | GitLab revision that is used to schedule jobs | -| **CI_SERVER_VERSION** | all | all | GitLab version that is used to schedule jobs | -| **CI_SERVER_VERSION_MAJOR** | 11.4 | all | GitLab version major component | -| **CI_SERVER_VERSION_MINOR** | 11.4 | all | GitLab version minor component | -| **CI_SERVER_VERSION_PATCH** | 11.4 | all | GitLab version patch component | -| **CI_SHARED_ENVIRONMENT** | all | 10.1 | Marks that the job is executed in a shared environment (something that is persisted across CI invocations like `shell` or `ssh` executor). If the environment is shared, it is set to true, otherwise it is not defined at all. | -| **GET_SOURCES_ATTEMPTS** | 8.15 | 1.9 | Number of attempts to fetch sources running a job | -| **GITLAB_CI** | all | all | Mark that job is executed in GitLab CI environment | -| **GITLAB_USER_EMAIL** | 8.12 | all | The email of the user who started the job | -| **GITLAB_USER_ID** | 8.12 | all | The id of the user who started the job | -| **GITLAB_USER_LOGIN** | 10.0 | all | The login username of the user who started the job | -| **GITLAB_USER_NAME** | 10.0 | all | The real name of the user who started the job | -| **RESTORE_CACHE_ATTEMPTS** | 8.15 | 1.9 | Number of attempts to restore the cache running a job | +See [full reference of predefined environment variables](predefined_variables.md). ## `.gitlab-ci.yml` defined variables diff --git a/doc/ci/variables/predefined_variables.md b/doc/ci/variables/predefined_variables.md new file mode 100644 index 00000000000..416627740d2 --- /dev/null +++ b/doc/ci/variables/predefined_variables.md @@ -0,0 +1,110 @@ +# Predefined environment variables reference + +For an introduction on this subject, read through the +[getting started with environment variables](README.md) document. + +## Overview + +Some of the predefined environment variables are available only if a minimum +version of [GitLab Runner](https://docs.gitlab.com/runner/) is used. Consult the table below to find the +version of Runner required. + +NOTE: **Note:** +Starting with GitLab 9.0, we have deprecated some variables. Read the +[9.0 Renaming](deprecated_variables.md#gitlab-90-renamed-variables) section to find out their replacements. **You are +strongly advised to use the new variables as we will remove the old ones in +future GitLab releases.** + +## Variables reference + +| Variable | GitLab | Runner | Description | +|-------------------------------------------|--------|--------|-------------| +| `ARTIFACT_DOWNLOAD_ATTEMPTS` | 8.15 | 1.9 | Number of attempts to download artifacts running a job | +| `CHAT_INPUT` | 10.6 | all | Additional arguments passed in the [ChatOps](../chatops/README.md) command | +| `CHAT_CHANNEL` | 10.6 | all | Source chat channel which triggered the [ChatOps](../chatops/README.md) command | +| `CI` | all | 0.4 | Mark that job is executed in CI environment | +| `CI_COMMIT_BEFORE_SHA` | 11.2 | all | The previous latest commit present on a branch before a push request. | +| `CI_COMMIT_DESCRIPTION` | 10.8 | all | The description of the commit: the message without first line, if the title is shorter than 100 characters; full message in other case. | +| `CI_COMMIT_MESSAGE` | 10.8 | all | The full commit message. | +| `CI_COMMIT_REF_NAME` | 9.0 | all | The branch or tag name for which project is built | +| `CI_COMMIT_REF_SLUG` | 9.0 | all | `$CI_COMMIT_REF_NAME` lowercased, shortened to 63 bytes, and with everything except `0-9` and `a-z` replaced with `-`. No leading / trailing `-`. Use in URLs, host names and domain names. | +| `CI_COMMIT_SHA` | 9.0 | all | The commit revision for which project is built | +| `CI_COMMIT_SHORT_SHA` | 11.7 | all | The first eight characters of `CI_COMMIT_SHA` | +| `CI_COMMIT_TAG` | 9.0 | 0.5 | The commit tag name. Present only when building tags. | +| `CI_COMMIT_TITLE` | 10.8 | all | The title of the commit - the full first line of the message | +| `CI_CONFIG_PATH` | 9.4 | 0.5 | The path to CI config file. Defaults to `.gitlab-ci.yml` | +| `CI_DEBUG_TRACE` | all | 1.7 | Whether [debug tracing](#debug-tracing) is enabled | +| `CI_DEPLOY_PASSWORD` | 10.8 | all | Authentication password of the [GitLab Deploy Token][gitlab-deploy-token], only present if the Project has one related.| +| `CI_DEPLOY_USER` | 10.8 | all | Authentication username of the [GitLab Deploy Token][gitlab-deploy-token], only present if the Project has one related.| +| `CI_DISPOSABLE_ENVIRONMENT` | all | 10.1 | Marks that the job is executed in a disposable environment (something that is created only for this job and disposed of/destroyed after the execution - all executors except `shell` and `ssh`). If the environment is disposable, it is set to true, otherwise it is not defined at all. | +| `CI_ENVIRONMENT_NAME` | 8.15 | all | The name of the environment for this job. Only present if [`environment:name`](../yaml/README.md#environmentname) is set. | +| `CI_ENVIRONMENT_SLUG` | 8.15 | all | A simplified version of the environment name, suitable for inclusion in DNS, URLs, Kubernetes labels, etc. Only present if [`environment:name`](../yaml/README.md#environmentname) is set. | +| `CI_ENVIRONMENT_URL` | 9.3 | all | The URL of the environment for this job. Only present if [`environment:url`](../yaml/README.md#environmenturl) is set. | +| `CI_JOB_ID` | 9.0 | all | The unique id of the current job that GitLab CI uses internally | +| `CI_JOB_MANUAL` | 8.12 | all | The flag to indicate that job was manually started | +| `CI_JOB_NAME` | 9.0 | 0.5 | The name of the job as defined in `.gitlab-ci.yml` | +| `CI_JOB_STAGE` | 9.0 | 0.5 | The name of the stage as defined in `.gitlab-ci.yml` | +| `CI_JOB_TOKEN` | 9.0 | 1.2 | Token used for authenticating with the [GitLab Container Registry][registry] and downloading [dependent repositories][dependent-repositories] | +| `CI_JOB_URL` | 11.1 | 0.5 | Job details URL | +| `CI_MERGE_REQUEST_ID` | 11.6 | all | The ID of the merge request if [the pipelines are for merge requests](../merge_request_pipelines/index.md) | +| `CI_MERGE_REQUEST_IID` | 11.6 | all | The IID of the merge request if [the pipelines are for merge requests](../merge_request_pipelines/index.md) | +| `CI_MERGE_REQUEST_PROJECT_ID` | 11.6 | all | The ID of the project of the merge request if [the pipelines are for merge requests](../merge_request_pipelines/index.md) | +| `CI_MERGE_REQUEST_PROJECT_PATH` | 11.6 | all | The path of the project of the merge request if [the pipelines are for merge requests](../merge_request_pipelines/index.md) (e.g. `namespace/awesome-project`) | +| `CI_MERGE_REQUEST_PROJECT_URL` | 11.6 | all | The URL of the project of the merge request if [the pipelines are for merge requests](../merge_request_pipelines/index.md) (e.g. `http://192.168.10.15:3000/namespace/awesome-project`) | +| `CI_MERGE_REQUEST_REF_PATH` | 11.6 | all | The ref path of the merge request if [the pipelines are for merge requests](../merge_request_pipelines/index.md). (e.g. `refs/merge-requests/1/head`) | +| `CI_MERGE_REQUEST_SOURCE_BRANCH_NAME` | 11.6 | all | The source branch name of the merge request if [the pipelines are for merge requests](../merge_request_pipelines/index.md) | +| `CI_MERGE_REQUEST_SOURCE_BRANCH_SHA` | 11.9 | all | The HEAD sha of the source branch of the merge request if [the pipelines are for merge requests](../merge_request_pipelines/index.md) | +| `CI_MERGE_REQUEST_SOURCE_PROJECT_ID` | 11.6 | all | The ID of the source project of the merge request if [the pipelines are for merge requests](../merge_request_pipelines/index.md) | +| `CI_MERGE_REQUEST_SOURCE_PROJECT_PATH` | 11.6 | all | The path of the source project of the merge request if [the pipelines are for merge requests](../merge_request_pipelines/index.md) | +| `CI_MERGE_REQUEST_SOURCE_PROJECT_URL` | 11.6 | all | The URL of the source project of the merge request if [the pipelines are for merge requests](../merge_request_pipelines/index.md) | +| `CI_MERGE_REQUEST_TARGET_BRANCH_NAME` | 11.6 | all | The target branch name of the merge request if [the pipelines are for merge requests](../merge_request_pipelines/index.md) | +| `CI_MERGE_REQUEST_TARGET_BRANCH_SHA` | 11.9 | all | The HEAD sha of the target branch of the merge request if [the pipelines are for merge requests](../merge_request_pipelines/index.md) | +| `CI_MERGE_REQUEST_TITLE` | 11.9 | all | The title of the merge request if [the pipelines are for merge requests](../merge_request_pipelines/index.md) | +| `CI_MERGE_REQUEST_ASSIGNEES` | 11.9 | all | Comma-separated list of usernames of assignees for the merge request if [the pipelines are for merge requests](../merge_request_pipelines/index.md). [Multiple assignees for merge requests](https://gitlab.com/gitlab-org/gitlab-ee/issues/2004) is scheduled for a future release | +| `CI_MERGE_REQUEST_MILESTONE` | 11.9 | all | The milestone title of the merge request if [the pipelines are for merge requests](../merge_request_pipelines/index.md) | +| `CI_MERGE_REQUEST_LABELS` | 11.9 | all | Comma-separated label names of the merge request if [the pipelines are for merge requests](../merge_request_pipelines/index.md) | +| `CI_NODE_INDEX` | 11.5 | all | Index of the job in the job set. If the job is not parallelized, this variable is not set. | +| `CI_NODE_TOTAL` | 11.5 | all | Total number of instances of this job running in parallel. If the job is not parallelized, this variable is set to `1`. | +| `CI_API_V4_URL` | 11.7 | all | The GitLab API v4 root URL | +| `CI_PAGES_DOMAIN` | 11.8 | all | The configured domain that hosts GitLab Pages. | +| `CI_PAGES_URL` | 11.8 | all | URL to GitLab Pages-built pages. Always belongs to a subdomain of `CI_PAGES_DOMAIN`. | +| `CI_PIPELINE_ID` | 8.10 | all | The unique id of the current pipeline that GitLab CI uses internally | +| `CI_PIPELINE_IID` | 11.0 | all | The unique id of the current pipeline scoped to project | +| `CI_PIPELINE_SOURCE` | 10.0 | all | Indicates how the pipeline was triggered. Possible options are: `push`, `web`, `trigger`, `schedule`, `api`, and `pipeline`. For pipelines created before GitLab 9.5, this will show as `unknown` | +| `CI_PIPELINE_TRIGGERED` | all | all | The flag to indicate that job was [triggered] | +| `CI_PIPELINE_URL` | 11.1 | 0.5 | Pipeline details URL | +| `CI_PROJECT_DIR` | all | all | The full path where the repository is cloned and where the job is run. If the GitLab Runner `builds_dir` parameter is set, this variable is set relative to the value of `builds_dir`. For more information, see [Advanced configuration](https://docs.gitlab.com/runner/configuration/advanced-configuration.html#the-runners-section) for GitLab Runner. | +| `CI_PROJECT_ID` | all | all | The unique id of the current project that GitLab CI uses internally | +| `CI_PROJECT_NAME` | 8.10 | 0.5 | The project name that is currently being built (actually it is project folder name) | +| `CI_PROJECT_NAMESPACE` | 8.10 | 0.5 | The project namespace (username or groupname) that is currently being built | +| `CI_PROJECT_PATH` | 8.10 | 0.5 | The namespace with project name | +| `CI_PROJECT_PATH_SLUG` | 9.3 | all | `$CI_PROJECT_PATH` lowercased and with everything except `0-9` and `a-z` replaced with `-`. Use in URLs and domain names. | +| `CI_PROJECT_URL` | 8.10 | 0.5 | The HTTP(S) address to access project | +| `CI_PROJECT_VISIBILITY` | 10.3 | all | The project visibility (internal, private, public) | +| `CI_REGISTRY` | 8.10 | 0.5 | If the Container Registry is enabled it returns the address of GitLab's Container Registry | +| `CI_REGISTRY_IMAGE` | 8.10 | 0.5 | If the Container Registry is enabled for the project it returns the address of the registry tied to the specific project | +| `CI_REGISTRY_PASSWORD` | 9.0 | all | The password to use to push containers to the GitLab Container Registry | +| `CI_REGISTRY_USER` | 9.0 | all | The username to use to push containers to the GitLab Container Registry | +| `CI_REPOSITORY_URL` | 9.0 | all | The URL to clone the Git repository | +| `CI_RUNNER_DESCRIPTION` | 8.10 | 0.5 | The description of the runner as saved in GitLab | +| `CI_RUNNER_EXECUTABLE_ARCH` | all | 10.6 | The OS/architecture of the GitLab Runner executable (note that this is not necessarily the same as the environment of the executor) | +| `CI_RUNNER_ID` | 8.10 | 0.5 | The unique id of runner being used | +| `CI_RUNNER_REVISION` | all | 10.6 | GitLab Runner revision that is executing the current job | +| `CI_RUNNER_TAGS` | 8.10 | 0.5 | The defined runner tags | +| `CI_RUNNER_VERSION` | all | 10.6 | GitLab Runner version that is executing the current job | +| `CI_SERVER` | all | all | Mark that job is executed in CI environment | +| `CI_SERVER_NAME` | all | all | The name of CI server that is used to coordinate jobs | +| `CI_SERVER_REVISION` | all | all | GitLab revision that is used to schedule jobs | +| `CI_SERVER_VERSION` | all | all | GitLab version that is used to schedule jobs | +| `CI_SERVER_VERSION_MAJOR` | 11.4 | all | GitLab version major component | +| `CI_SERVER_VERSION_MINOR` | 11.4 | all | GitLab version minor component | +| `CI_SERVER_VERSION_PATCH` | 11.4 | all | GitLab version patch component | +| `CI_SHARED_ENVIRONMENT` | all | 10.1 | Marks that the job is executed in a shared environment (something that is persisted across CI invocations like `shell` or `ssh` executor). If the environment is shared, it is set to true, otherwise it is not defined at all. | +| `GET_SOURCES_ATTEMPTS` | 8.15 | 1.9 | Number of attempts to fetch sources running a job | +| `GITLAB_CI` | all | all | Mark that job is executed in GitLab CI environment | +| `GITLAB_USER_EMAIL` | 8.12 | all | The email of the user who started the job | +| `GITLAB_USER_ID` | 8.12 | all | The id of the user who started the job | +| `GITLAB_USER_LOGIN` | 10.0 | all | The login username of the user who started the job | +| `GITLAB_USER_NAME` | 10.0 | all | The real name of the user who started the job | +| `RESTORE_CACHE_ATTEMPTS` | 8.15 | 1.9 | Number of attempts to restore the cache running a job | +| `GITLAB_FEATURES` | 10.6 | all | The comma separated list of licensed features available for your instance and plan | -- cgit v1.2.1 From 01422c9156bf6ec5bbca172aef55614d4b03703c Mon Sep 17 00:00:00 2001 From: Marcel Amirault Date: Tue, 2 Apr 2019 13:31:18 +0000 Subject: Docs: image realignment --- .../performance/img/request_profiling_token.png | Bin 17425 -> 17396 bytes .../img/variables_page.png | Bin 11836 -> 11827 bytes .../img/pipeline_detail.png | Bin 15561 -> 15556 bytes doc/ci/triggers/img/trigger_variables.png | Bin 10853 -> 10841 bytes .../custom_header_footer.png | Bin 484001 -> 116778 bytes .../sign_up_custom_header_and_footer.png | Bin 360832 -> 78678 bytes doc/img/devops-stages.png | Bin 10666 -> 10654 bytes doc/integration/img/github_app_entry.png | Bin 26765 -> 26749 bytes doc/integration/img/github_register_app.png | Bin 40228 -> 40225 bytes .../high-availability/aws/img/reference-arch2.png | Bin 53523 -> 53510 bytes doc/user/group/img/create_new_group_info.png | Bin 51072 -> 27101 bytes doc/user/img/color_inline_colorchip_render_gfm.png | Bin 4724 -> 4684 bytes doc/user/img/task_list_ordered_render_gfm.png | Bin 2860 -> 2855 bytes doc/user/img/unordered_check_list_render_gfm.png | Bin 2789 -> 2781 bytes .../clusters/runbooks/img/authorize-jupyter.png | Bin 35652 -> 35627 bytes .../clusters/runbooks/img/gitlab-variables.png | Bin 54167 -> 54154 bytes .../project/clusters/runbooks/img/helm-install.png | Bin 71741 -> 71705 bytes .../clusters/runbooks/img/ingress-install.png | Bin 44380 -> 44363 bytes .../clusters/runbooks/img/jupyterhub-install.png | Bin 41655 -> 41588 bytes .../clusters/runbooks/img/postgres-query.png | Bin 63480 -> 63416 bytes .../clusters/runbooks/img/sample-runbook.png | Bin 40947 -> 40941 bytes doc/user/project/img/labels_default.png | Bin 22975 -> 35620 bytes doc/user/project/img/labels_list.png | Bin 71323 -> 75215 bytes .../integrations/img/jira_api_token_menu.png | Bin 25059 -> 25056 bytes .../project/integrations/img/jira_service_page.png | Bin 30398 -> 30395 bytes doc/user/project/issues/img/similar_issues.png | Bin 25407 -> 25390 bytes .../img/comment-on-any-diff-line.png | Bin 55614 -> 55593 bytes doc/user/project/pages/img/icons/click.png | Bin 4863 -> 4683 bytes doc/user/project/pages/img/icons/fork.png | Bin 4562 -> 4380 bytes doc/user/project/pages/img/icons/free.png | Bin 3681 -> 3563 bytes doc/user/project/pages/img/icons/lock.png | Bin 3426 -> 3404 bytes doc/user/project/pages/img/icons/monitor.png | Bin 2025 -> 1982 bytes doc/user/project/pages/img/icons/terminal.png | Bin 1983 -> 1961 bytes .../branches/img/branch_filter_search_box.png | Bin 23539 -> 23522 bytes .../project/repository/img/repository_cleanup.png | Bin 8117 -> 8114 bytes 35 files changed, 0 insertions(+), 0 deletions(-) diff --git a/doc/administration/monitoring/performance/img/request_profiling_token.png b/doc/administration/monitoring/performance/img/request_profiling_token.png index 9f3dd7f08ca..ee819fcb437 100644 Binary files a/doc/administration/monitoring/performance/img/request_profiling_token.png and b/doc/administration/monitoring/performance/img/request_profiling_token.png differ diff --git a/doc/ci/examples/laravel_with_gitlab_and_envoy/img/variables_page.png b/doc/ci/examples/laravel_with_gitlab_and_envoy/img/variables_page.png index 4675e20ef79..edeaa011ada 100644 Binary files a/doc/ci/examples/laravel_with_gitlab_and_envoy/img/variables_page.png and b/doc/ci/examples/laravel_with_gitlab_and_envoy/img/variables_page.png differ diff --git a/doc/ci/merge_request_pipelines/img/pipeline_detail.png b/doc/ci/merge_request_pipelines/img/pipeline_detail.png index 6094a0975fb..90e7c449a66 100644 Binary files a/doc/ci/merge_request_pipelines/img/pipeline_detail.png and b/doc/ci/merge_request_pipelines/img/pipeline_detail.png differ diff --git a/doc/ci/triggers/img/trigger_variables.png b/doc/ci/triggers/img/trigger_variables.png index d273b1fe3a2..910622d74cc 100644 Binary files a/doc/ci/triggers/img/trigger_variables.png and b/doc/ci/triggers/img/trigger_variables.png differ diff --git a/doc/customization/system_header_and_footer_messages/custom_header_footer.png b/doc/customization/system_header_and_footer_messages/custom_header_footer.png index 691ca8a3484..15d19c87dd7 100644 Binary files a/doc/customization/system_header_and_footer_messages/custom_header_footer.png and b/doc/customization/system_header_and_footer_messages/custom_header_footer.png differ diff --git a/doc/customization/system_header_and_footer_messages/sign_up_custom_header_and_footer.png b/doc/customization/system_header_and_footer_messages/sign_up_custom_header_and_footer.png index a9c59bc9f62..51349ddf6f4 100644 Binary files a/doc/customization/system_header_and_footer_messages/sign_up_custom_header_and_footer.png and b/doc/customization/system_header_and_footer_messages/sign_up_custom_header_and_footer.png differ diff --git a/doc/img/devops-stages.png b/doc/img/devops-stages.png index 424bce95607..2fa5357062c 100644 Binary files a/doc/img/devops-stages.png and b/doc/img/devops-stages.png differ diff --git a/doc/integration/img/github_app_entry.png b/doc/integration/img/github_app_entry.png index 0a1fe0ca65a..c736bed3dd6 100644 Binary files a/doc/integration/img/github_app_entry.png and b/doc/integration/img/github_app_entry.png differ diff --git a/doc/integration/img/github_register_app.png b/doc/integration/img/github_register_app.png index 5786b822f53..d03ca5cc2aa 100644 Binary files a/doc/integration/img/github_register_app.png and b/doc/integration/img/github_register_app.png differ diff --git a/doc/university/high-availability/aws/img/reference-arch2.png b/doc/university/high-availability/aws/img/reference-arch2.png index a9cb6663103..0f8790d0f74 100644 Binary files a/doc/university/high-availability/aws/img/reference-arch2.png and b/doc/university/high-availability/aws/img/reference-arch2.png differ diff --git a/doc/user/group/img/create_new_group_info.png b/doc/user/group/img/create_new_group_info.png index c2e6ed43c5b..bd724240c37 100644 Binary files a/doc/user/group/img/create_new_group_info.png and b/doc/user/group/img/create_new_group_info.png differ diff --git a/doc/user/img/color_inline_colorchip_render_gfm.png b/doc/user/img/color_inline_colorchip_render_gfm.png index fed8ca5c34b..6f93dbeeb10 100644 Binary files a/doc/user/img/color_inline_colorchip_render_gfm.png and b/doc/user/img/color_inline_colorchip_render_gfm.png differ diff --git a/doc/user/img/task_list_ordered_render_gfm.png b/doc/user/img/task_list_ordered_render_gfm.png index 0905a8378be..98ec791e958 100644 Binary files a/doc/user/img/task_list_ordered_render_gfm.png and b/doc/user/img/task_list_ordered_render_gfm.png differ diff --git a/doc/user/img/unordered_check_list_render_gfm.png b/doc/user/img/unordered_check_list_render_gfm.png index ccdeab6e62c..2ce0fb95645 100644 Binary files a/doc/user/img/unordered_check_list_render_gfm.png and b/doc/user/img/unordered_check_list_render_gfm.png differ diff --git a/doc/user/project/clusters/runbooks/img/authorize-jupyter.png b/doc/user/project/clusters/runbooks/img/authorize-jupyter.png index 84cce311483..f3e868de802 100644 Binary files a/doc/user/project/clusters/runbooks/img/authorize-jupyter.png and b/doc/user/project/clusters/runbooks/img/authorize-jupyter.png differ diff --git a/doc/user/project/clusters/runbooks/img/gitlab-variables.png b/doc/user/project/clusters/runbooks/img/gitlab-variables.png index 1d338f063a9..7c9c9099851 100644 Binary files a/doc/user/project/clusters/runbooks/img/gitlab-variables.png and b/doc/user/project/clusters/runbooks/img/gitlab-variables.png differ diff --git a/doc/user/project/clusters/runbooks/img/helm-install.png b/doc/user/project/clusters/runbooks/img/helm-install.png index 003e482e756..e67cf317ec1 100644 Binary files a/doc/user/project/clusters/runbooks/img/helm-install.png and b/doc/user/project/clusters/runbooks/img/helm-install.png differ diff --git a/doc/user/project/clusters/runbooks/img/ingress-install.png b/doc/user/project/clusters/runbooks/img/ingress-install.png index 7edc11d5b45..08256a65138 100644 Binary files a/doc/user/project/clusters/runbooks/img/ingress-install.png and b/doc/user/project/clusters/runbooks/img/ingress-install.png differ diff --git a/doc/user/project/clusters/runbooks/img/jupyterhub-install.png b/doc/user/project/clusters/runbooks/img/jupyterhub-install.png index 75c6028a763..784e508ff25 100644 Binary files a/doc/user/project/clusters/runbooks/img/jupyterhub-install.png and b/doc/user/project/clusters/runbooks/img/jupyterhub-install.png differ diff --git a/doc/user/project/clusters/runbooks/img/postgres-query.png b/doc/user/project/clusters/runbooks/img/postgres-query.png index 04315d54d5e..dbb5a62ebba 100644 Binary files a/doc/user/project/clusters/runbooks/img/postgres-query.png and b/doc/user/project/clusters/runbooks/img/postgres-query.png differ diff --git a/doc/user/project/clusters/runbooks/img/sample-runbook.png b/doc/user/project/clusters/runbooks/img/sample-runbook.png index 70011202bf0..545d34fd4ad 100644 Binary files a/doc/user/project/clusters/runbooks/img/sample-runbook.png and b/doc/user/project/clusters/runbooks/img/sample-runbook.png differ diff --git a/doc/user/project/img/labels_default.png b/doc/user/project/img/labels_default.png index 7a7fab611a4..221c5cf55a2 100644 Binary files a/doc/user/project/img/labels_default.png and b/doc/user/project/img/labels_default.png differ diff --git a/doc/user/project/img/labels_list.png b/doc/user/project/img/labels_list.png index 6878349fc0c..6940dde68bf 100644 Binary files a/doc/user/project/img/labels_list.png and b/doc/user/project/img/labels_list.png differ diff --git a/doc/user/project/integrations/img/jira_api_token_menu.png b/doc/user/project/integrations/img/jira_api_token_menu.png index 55c8fb1bdb9..14037bd0b47 100644 Binary files a/doc/user/project/integrations/img/jira_api_token_menu.png and b/doc/user/project/integrations/img/jira_api_token_menu.png differ diff --git a/doc/user/project/integrations/img/jira_service_page.png b/doc/user/project/integrations/img/jira_service_page.png index 3a27b4df841..377b69d9d06 100644 Binary files a/doc/user/project/integrations/img/jira_service_page.png and b/doc/user/project/integrations/img/jira_service_page.png differ diff --git a/doc/user/project/issues/img/similar_issues.png b/doc/user/project/issues/img/similar_issues.png index 0dfb5b00e02..c5b7902b2ac 100644 Binary files a/doc/user/project/issues/img/similar_issues.png and b/doc/user/project/issues/img/similar_issues.png differ diff --git a/doc/user/project/merge_requests/img/comment-on-any-diff-line.png b/doc/user/project/merge_requests/img/comment-on-any-diff-line.png index c2455c2d1e5..5b9844bf02f 100644 Binary files a/doc/user/project/merge_requests/img/comment-on-any-diff-line.png and b/doc/user/project/merge_requests/img/comment-on-any-diff-line.png differ diff --git a/doc/user/project/pages/img/icons/click.png b/doc/user/project/pages/img/icons/click.png index a534ae29e0f..62a997a7591 100644 Binary files a/doc/user/project/pages/img/icons/click.png and b/doc/user/project/pages/img/icons/click.png differ diff --git a/doc/user/project/pages/img/icons/fork.png b/doc/user/project/pages/img/icons/fork.png index 8a3aa46eb37..1ae8fa722b7 100644 Binary files a/doc/user/project/pages/img/icons/fork.png and b/doc/user/project/pages/img/icons/fork.png differ diff --git a/doc/user/project/pages/img/icons/free.png b/doc/user/project/pages/img/icons/free.png index ae455033e94..c74cd90fa1a 100644 Binary files a/doc/user/project/pages/img/icons/free.png and b/doc/user/project/pages/img/icons/free.png differ diff --git a/doc/user/project/pages/img/icons/lock.png b/doc/user/project/pages/img/icons/lock.png index f4c35c84112..f7f32fded45 100644 Binary files a/doc/user/project/pages/img/icons/lock.png and b/doc/user/project/pages/img/icons/lock.png differ diff --git a/doc/user/project/pages/img/icons/monitor.png b/doc/user/project/pages/img/icons/monitor.png index 8bad059a74c..ce27b7e177e 100644 Binary files a/doc/user/project/pages/img/icons/monitor.png and b/doc/user/project/pages/img/icons/monitor.png differ diff --git a/doc/user/project/pages/img/icons/terminal.png b/doc/user/project/pages/img/icons/terminal.png index 377eeb4edc6..5a711f05c4e 100644 Binary files a/doc/user/project/pages/img/icons/terminal.png and b/doc/user/project/pages/img/icons/terminal.png differ diff --git a/doc/user/project/repository/branches/img/branch_filter_search_box.png b/doc/user/project/repository/branches/img/branch_filter_search_box.png index 5dc7eccf189..5dc300cf24e 100644 Binary files a/doc/user/project/repository/branches/img/branch_filter_search_box.png and b/doc/user/project/repository/branches/img/branch_filter_search_box.png differ diff --git a/doc/user/project/repository/img/repository_cleanup.png b/doc/user/project/repository/img/repository_cleanup.png index bda40d3e193..e343f23ac27 100644 Binary files a/doc/user/project/repository/img/repository_cleanup.png and b/doc/user/project/repository/img/repository_cleanup.png differ -- cgit v1.2.1 From 1058bb90459e4521b55b1be6929d36ccffe332db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Coutable?= Date: Tue, 2 Apr 2019 16:10:47 +0200 Subject: Use the default fetch/clone depth for the review-deploy job MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rémy Coutable --- .gitlab-ci.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ab38c87039e..f89a52e7a3e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1018,10 +1018,8 @@ schedule:review-build-cng: .review-deploy-base: &review-deploy-base <<: *review-base - retry: 2 allow_failure: true variables: - GIT_DEPTH: "1" HOST_SUFFIX: "${CI_ENVIRONMENT_SLUG}" DOMAIN: "-${CI_ENVIRONMENT_SLUG}.${REVIEW_APPS_DOMAIN}" GITLAB_HELM_CHART_REF: "master" -- cgit v1.2.1 From 6b24eb9ce6ae42c161ded782971cd72b8836b56f Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Tue, 2 Apr 2019 17:22:29 +0300 Subject: Remove already defined shared example Removing the time traking shared example as it was actually moved under time_tracking_quick_action_shared_examples.rb filename to a different path as part of spec refactorign for quick action https://gitlab.com/gitlab-org/gitlab-ce/issues/50199 https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/26095 --- .../time_tracking_shared_examples.rb | 85 ---------------------- 1 file changed, 85 deletions(-) delete mode 100644 spec/support/shared_examples/time_tracking_shared_examples.rb diff --git a/spec/support/shared_examples/time_tracking_shared_examples.rb b/spec/support/shared_examples/time_tracking_shared_examples.rb deleted file mode 100644 index 909d4e2ee8d..00000000000 --- a/spec/support/shared_examples/time_tracking_shared_examples.rb +++ /dev/null @@ -1,85 +0,0 @@ -shared_examples 'issuable time tracker' do - it 'renders the sidebar component empty state' do - page.within '.time-tracking-no-tracking-pane' do - expect(page).to have_content 'No estimate or time spent' - end - end - - it 'updates the sidebar component when estimate is added' do - submit_time('/estimate 3w 1d 1h') - - wait_for_requests - page.within '.time-tracking-estimate-only-pane' do - expect(page).to have_content '3w 1d 1h' - end - end - - it 'updates the sidebar component when spent is added' do - submit_time('/spend 3w 1d 1h') - - wait_for_requests - page.within '.time-tracking-spend-only-pane' do - expect(page).to have_content '3w 1d 1h' - end - end - - it 'shows the comparison when estimate and spent are added' do - submit_time('/estimate 3w 1d 1h') - submit_time('/spend 3w 1d 1h') - - wait_for_requests - page.within '.time-tracking-comparison-pane' do - expect(page).to have_content '3w 1d 1h' - end - end - - it 'updates the sidebar component when estimate is removed' do - submit_time('/estimate 3w 1d 1h') - submit_time('/remove_estimate') - - page.within '.time-tracking-component-wrap' do - expect(page).to have_content 'No estimate or time spent' - end - end - - it 'updates the sidebar component when spent is removed' do - submit_time('/spend 3w 1d 1h') - submit_time('/remove_time_spent') - - page.within '.time-tracking-component-wrap' do - expect(page).to have_content 'No estimate or time spent' - end - end - - it 'shows the help state when icon is clicked' do - page.within '.time-tracking-component-wrap' do - find('.help-button').click - expect(page).to have_content 'Track time with quick actions' - expect(page).to have_content 'Learn more' - end - end - - it 'hides the help state when close icon is clicked' do - page.within '.time-tracking-component-wrap' do - find('.help-button').click - find('.close-help-button').click - - expect(page).not_to have_content 'Track time with quick actions' - expect(page).not_to have_content 'Learn more' - end - end - - it 'displays the correct help url' do - page.within '.time-tracking-component-wrap' do - find('.help-button').click - - expect(find_link('Learn more')[:href]).to have_content('/help/workflow/time_tracking.md') - end - end -end - -def submit_time(quick_action) - fill_in 'note[note]', with: quick_action - find('.js-comment-submit-button').click - wait_for_requests -end -- cgit v1.2.1 From 65ede29537573836b8958be3feb6abfde163f0fc Mon Sep 17 00:00:00 2001 From: Dennis Tang Date: Tue, 2 Apr 2019 12:49:13 +0000 Subject: Update system message banner font size to 12px --- app/assets/stylesheets/framework/system_messages.scss | 1 + .../59131-set-the-size-of-instance-system-message-text-12px.yml | 5 +++++ 2 files changed, 6 insertions(+) create mode 100644 changelogs/unreleased/59131-set-the-size-of-instance-system-message-text-12px.yml diff --git a/app/assets/stylesheets/framework/system_messages.scss b/app/assets/stylesheets/framework/system_messages.scss index e5edddec71e..6205ccaa52f 100644 --- a/app/assets/stylesheets/framework/system_messages.scss +++ b/app/assets/stylesheets/framework/system_messages.scss @@ -14,6 +14,7 @@ @include str-truncated(100%); margin-top: -1px; margin-bottom: 0; + font-size: $gl-font-size-small; } } diff --git a/changelogs/unreleased/59131-set-the-size-of-instance-system-message-text-12px.yml b/changelogs/unreleased/59131-set-the-size-of-instance-system-message-text-12px.yml new file mode 100644 index 00000000000..688190f4458 --- /dev/null +++ b/changelogs/unreleased/59131-set-the-size-of-instance-system-message-text-12px.yml @@ -0,0 +1,5 @@ +--- +title: Update system message banner font size to 12px +merge_request: 26293 +author: +type: changed -- cgit v1.2.1 From 2614273328972243a0d18b1fca92265946e68c03 Mon Sep 17 00:00:00 2001 From: Dennis Tang Date: Tue, 2 Apr 2019 12:49:36 +0000 Subject: Remove duplicate declaration of $system-header-height --- app/assets/stylesheets/framework/variables.scss | 1 - 1 file changed, 1 deletion(-) diff --git a/app/assets/stylesheets/framework/variables.scss b/app/assets/stylesheets/framework/variables.scss index 5d4c84c494d..7d9781ffb87 100644 --- a/app/assets/stylesheets/framework/variables.scss +++ b/app/assets/stylesheets/framework/variables.scss @@ -289,7 +289,6 @@ $gl-line-height: 16px; $gl-line-height-24: 24px; $gl-line-height-14: 14px; -$system-header-height: 35px; $issue-box-upcoming-bg: #8f8f8f; $pages-group-name-color: #4c4e54; -- cgit v1.2.1 From 0e5dbaf87f4f6f511eee469139e57d896164846c Mon Sep 17 00:00:00 2001 From: Heinrich Lee Yu Date: Thu, 21 Mar 2019 12:08:15 +0800 Subject: Do not show system notes on commits in the MR page --- app/models/merge_request.rb | 19 ++++++++++--------- .../55268-exclude-system-notes-from-commits-in-mr.yml | 5 +++++ spec/models/merge_request_spec.rb | 8 ++++++++ 3 files changed, 23 insertions(+), 9 deletions(-) create mode 100644 changelogs/unreleased/55268-exclude-system-notes-from-commits-in-mr.yml diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index b780b67492f..458c57c1dc6 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -858,15 +858,6 @@ class MergeRequest < ApplicationRecord end def related_notes - # Fetch comments only from last 100 commits - commits_for_notes_limit = 100 - commit_ids = commit_shas.take(commits_for_notes_limit) - - commit_notes = Note - .except(:order) - .where(project_id: [source_project_id, target_project_id]) - .for_commit_id(commit_ids) - # We're using a UNION ALL here since this results in better performance # compared to using OR statements. We're using UNION ALL since the queries # used won't produce any duplicates (e.g. a note for a commit can't also be @@ -878,6 +869,16 @@ class MergeRequest < ApplicationRecord alias_method :discussion_notes, :related_notes + def commit_notes + # Fetch comments only from last 100 commits + commit_ids = commit_shas.take(100) + + Note + .user + .where(project_id: [source_project_id, target_project_id]) + .for_commit_id(commit_ids) + end + def mergeable_discussions_state? return true unless project.only_allow_merge_if_all_discussions_are_resolved? diff --git a/changelogs/unreleased/55268-exclude-system-notes-from-commits-in-mr.yml b/changelogs/unreleased/55268-exclude-system-notes-from-commits-in-mr.yml new file mode 100644 index 00000000000..7af4739136b --- /dev/null +++ b/changelogs/unreleased/55268-exclude-system-notes-from-commits-in-mr.yml @@ -0,0 +1,5 @@ +--- +title: Exclude system notes from commits in merge request discussions +merge_request: 26396 +author: +type: fixed diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb index 892fdc4e4e9..6f34ef9c1bc 100644 --- a/spec/models/merge_request_spec.rb +++ b/spec/models/merge_request_spec.rb @@ -805,6 +805,14 @@ describe MergeRequest do expect(merge_request.commits).not_to be_empty expect(merge_request.related_notes.count).to eq(3) end + + it "excludes system notes for commits" do + system_note = create(:note_on_commit, :system, commit_id: merge_request.commits.first.id, + project: merge_request.project) + + expect(merge_request.related_notes.count).to eq(2) + expect(merge_request.related_notes).not_to include(system_note) + end end describe '#for_fork?' do -- cgit v1.2.1 From 3bc30185180cbb5d7c8e026f6e7f1826617358a3 Mon Sep 17 00:00:00 2001 From: Jacopo Date: Tue, 2 Apr 2019 17:58:52 +0200 Subject: Fix quick actions add label name middle word overlaps Fixes quick actions add label when adding a label which name middle word overlaps with another label name: for example adding "A B C" when also label "B" exists. With the fix only the label "A B C" is correctly added, previously also the label "B" was added due to the middle word overlaps. --- app/services/quick_actions/interpret_service.rb | 19 ++++++++-- ...if-middle-words-overlap-with-existing-label.yml | 5 +++ doc/user/project/quick_actions.md | 2 +- .../quick_actions/interpret_service_spec.rb | 41 ++++++++++++++++++++++ 4 files changed, 63 insertions(+), 4 deletions(-) create mode 100644 changelogs/unreleased/53459-quick-action-adds-multiple-labels-to-issue-if-middle-words-overlap-with-existing-label.yml diff --git a/app/services/quick_actions/interpret_service.rb b/app/services/quick_actions/interpret_service.rb index f463e08ee7e..8ff73522e5f 100644 --- a/app/services/quick_actions/interpret_service.rb +++ b/app/services/quick_actions/interpret_service.rb @@ -96,14 +96,27 @@ module QuickActions end def find_labels(labels_params = nil) + extract_references(labels_params, :label) | find_labels_by_name_no_tilde(labels_params) + end + + def find_labels_by_name_no_tilde(labels_params) + return Label.none if label_with_tilde?(labels_params) + finder_params = { include_ancestor_groups: true } finder_params[:project_id] = project.id if project finder_params[:group_id] = group.id if group - finder_params[:name] = labels_params.split if labels_params + finder_params[:name] = extract_label_names(labels_params) if labels_params - result = LabelsFinder.new(current_user, finder_params).execute + LabelsFinder.new(current_user, finder_params).execute + end + + def label_with_tilde?(labels_params) + labels_params&.include?('~') + end - extract_references(labels_params, :label) | result + def extract_label_names(labels_params) + # '"A" "A B C" A B' => ["A", "A B C", "A", "B"] + labels_params.scan(/"([^"]+)"|([^ ]+)/).flatten.compact end def find_label_references(labels_param) diff --git a/changelogs/unreleased/53459-quick-action-adds-multiple-labels-to-issue-if-middle-words-overlap-with-existing-label.yml b/changelogs/unreleased/53459-quick-action-adds-multiple-labels-to-issue-if-middle-words-overlap-with-existing-label.yml new file mode 100644 index 00000000000..30d8c0e95d7 --- /dev/null +++ b/changelogs/unreleased/53459-quick-action-adds-multiple-labels-to-issue-if-middle-words-overlap-with-existing-label.yml @@ -0,0 +1,5 @@ +--- +title: Fix quick actions add label name middle word overlaps +merge_request: 26602 +author: Jacopo Beschi @jacopo-beschi +type: fixed diff --git a/doc/user/project/quick_actions.md b/doc/user/project/quick_actions.md index 392e72dcc5c..88f4de891a1 100644 --- a/doc/user/project/quick_actions.md +++ b/doc/user/project/quick_actions.md @@ -31,7 +31,7 @@ discussions, and descriptions: | `/reassign @user1 @user2` | Change assignee | ✓ | ✓ | | `/milestone %milestone` | Set milestone | ✓ | ✓ | | `/remove_milestone` | Remove milestone | ✓ | ✓ | -| `/label ~label1 ~label2` | Add label(s) | ✓ | ✓ | +| `/label ~label1 ~label2` | Add label(s). Label names can also start without ~ but mixed syntax is not supported. | ✓ | ✓ | | `/unlabel ~label1 ~label2` | Remove all or specific label(s)| ✓ | ✓ | | `/relabel ~label1 ~label2` | Replace label | ✓ | ✓ | | /copy_metadata #issue | !merge_request | Copy labels and milestone from other issue or merge request | ✓ | ✓ | diff --git a/spec/services/quick_actions/interpret_service_spec.rb b/spec/services/quick_actions/interpret_service_spec.rb index 8b0f9c8ade2..c7e5cca324f 100644 --- a/spec/services/quick_actions/interpret_service_spec.rb +++ b/spec/services/quick_actions/interpret_service_spec.rb @@ -10,6 +10,7 @@ describe QuickActions::InterpretService do let(:milestone) { create(:milestone, project: project, title: '9.10') } let(:commit) { create(:commit, project: project) } let(:inprogress) { create(:label, project: project, title: 'In Progress') } + let(:helmchart) { create(:label, project: project, title: 'Helm Chart Registry') } let(:bug) { create(:label, project: project, title: 'Bug') } let(:note) { build(:note, commit_id: merge_request.diff_head_sha) } let(:service) { described_class.new(project, developer) } @@ -94,6 +95,26 @@ describe QuickActions::InterpretService do end end + shared_examples 'multiword label name starting without ~' do + it 'fetches label ids and populates add_label_ids if content contains /label' do + helmchart # populate the label + _, updates = service.execute(content, issuable) + + expect(updates).to eq(add_label_ids: [helmchart.id]) + end + end + + shared_examples 'label name is included in the middle of another label name' do + it 'ignores the sublabel when the content contains the includer label name' do + helmchart # populate the label + create(:label, project: project, title: 'Chart') + + _, updates = service.execute(content, issuable) + + expect(updates).to eq(add_label_ids: [helmchart.id]) + end + end + shared_examples 'unlabel command' do it 'fetches label ids and populates remove_label_ids if content contains /unlabel' do issuable.update!(label_ids: [inprogress.id]) # populate the label @@ -624,6 +645,26 @@ describe QuickActions::InterpretService do let(:issuable) { issue } end + it_behaves_like 'multiword label name starting without ~' do + let(:content) { %(/label "#{helmchart.title}") } + let(:issuable) { issue } + end + + it_behaves_like 'multiword label name starting without ~' do + let(:content) { %(/label "#{helmchart.title}") } + let(:issuable) { merge_request } + end + + it_behaves_like 'label name is included in the middle of another label name' do + let(:content) { %(/label ~"#{helmchart.title}") } + let(:issuable) { issue } + end + + it_behaves_like 'label name is included in the middle of another label name' do + let(:content) { %(/label ~"#{helmchart.title}") } + let(:issuable) { merge_request } + end + it_behaves_like 'unlabel command' do let(:content) { %(/unlabel ~"#{inprogress.title}") } let(:issuable) { issue } -- cgit v1.2.1 From ea283bbc6bc5d1e4b03259495c7e0e1e1978059e Mon Sep 17 00:00:00 2001 From: Imre Farkas Date: Tue, 2 Apr 2019 16:48:55 +0000 Subject: Remove ignore column for PersonalAccessToken#token --- app/models/personal_access_token.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/models/personal_access_token.rb b/app/models/personal_access_token.rb index 570112b63b7..d5770387872 100644 --- a/app/models/personal_access_token.rb +++ b/app/models/personal_access_token.rb @@ -2,11 +2,9 @@ class PersonalAccessToken < ApplicationRecord include Expirable - include IgnorableColumn include TokenAuthenticatable add_authentication_token_field :token, digest: true - ignore_column :token REDIS_EXPIRY_TIME = 3.minutes -- cgit v1.2.1 From 6fe5d402ea0c9d1db716ea3ffb68acbc570f23b2 Mon Sep 17 00:00:00 2001 From: Marcia Ramos Date: Tue, 2 Apr 2019 17:18:44 +0000 Subject: Add screenshots for variables - Variables overview - Variables triggered via manual pipeline --- doc/ci/variables/README.md | 612 +++++++++++++-------- .../variables/img/ci_job_stage_output_example.png | Bin 0 -> 68964 bytes doc/ci/variables/img/custom_variable_output.png | Bin 0 -> 70552 bytes .../variables/img/new_custom_variable_example.png | Bin 0 -> 44164 bytes .../override_value_via_manual_pipeline_output.png | Bin 0 -> 72420 bytes .../img/override_variable_manual_pipeline.png | Bin 0 -> 29090 bytes 6 files changed, 376 insertions(+), 236 deletions(-) create mode 100755 doc/ci/variables/img/ci_job_stage_output_example.png create mode 100755 doc/ci/variables/img/custom_variable_output.png create mode 100755 doc/ci/variables/img/new_custom_variable_example.png create mode 100755 doc/ci/variables/img/override_value_via_manual_pipeline_output.png create mode 100755 doc/ci/variables/img/override_variable_manual_pipeline.png diff --git a/doc/ci/variables/README.md b/doc/ci/variables/README.md index 12b027e7d79..6532d177d2c 100644 --- a/doc/ci/variables/README.md +++ b/doc/ci/variables/README.md @@ -2,49 +2,244 @@ table_display_block: true --- -# GitLab CI/CD Variables +# GitLab CI/CD environment variables +{: #variables} -When receiving a job from GitLab CI, the [Runner](https://docs.gitlab.com/runner/) prepares the build environment. -It starts by setting a list of: +After a brief overview over the use of environment +variables, this document teaches you how to use GitLab CI/CD's +variables, presents the full reference for predefined variables, +and dives into more advanced applications. -- [Predefined environment variables](#predefined-environment-variables). -- Other variables. +## Overview -## Priority of variables +An environment variable is a dynamic-named value that can +affect the way running processes will behave on an operating +system. -Variables of different types can take precedence over other variables, depending on where they are defined. +They are part of the environment in which a process runs. +For example, a running process can query the value of the +`TEMP` environment variable to discover a suitable location +to store temporary files, or to define a `URL` for a database +that can be reused in different scripts. -The order of precedence for variables is (from highest to lowest): +Variables are useful for customizing your jobs in GitLab +CI/CD's pipelines. Using variables means no hardcoded values. -1. [Trigger variables](../triggers/README.md#making-use-of-trigger-variables) or [scheduled pipeline variables](../../user/project/pipelines/schedules.md#making-use-of-scheduled-pipeline-variables). -1. Project-level [variables](#variables) or [protected variables](#protected-variables). -1. Group-level [variables](#variables) or [protected variables](#protected-variables). -1. YAML-defined [job-level variables](../yaml/README.md#variables). -1. YAML-defined [global variables](../yaml/README.md#variables). -1. [Deployment variables](#deployment-variables). -1. [Predefined environment variables](#predefined-environment-variables). +### Predefined environment variables -For example, you define: +GitLab CI/CD has a default set of +[predefined variables](predefined_variables.md) +which can be used without any specification needed. +You can call issues numbers, user names, branch names, +pipeline and commit IDs, and much more. -- `API_TOKEN=secure` as a project variable. -- `API_TOKEN=yaml` in your `.gitlab-ci.yml`. +Predefined environment variables are the ones that GitLab +provides out of the box for the local environment of the Runner. -`API_TOKEN` will take the value `secure` as the project variables take precedence over those defined -in `.gitlab-ci.yml`. +GitLab reads the .gitlab-ci.yml file, sends the information +to the Runner (which runs the script commands), under which +the variables are exposed. -## Unsupported variables +For example, two jobs under the same pipeline can share the same +`CI_PIPELINE_ID` variable, but each one has its own `CI_JOB_ID` +variable. -There are cases where some variables cannot be used in the context of a -`.gitlab-ci.yml` definition (for example under `script`). Read more -about which variables are [not supported](where_variables_can_be_used.md). +### Custom environment variables + +When your use case requires a specific variable, you can +[set them up easily from the UI](#creating-a-custom-environment-variable) +or directly in the `.gitlab-ci.yml` file and reuse them as you wish. + +That can be very powerful as it can be used for scripting without +the need to specify the value itself. + +## Getting started + +To get started with environment variables in the scope of GitLab +CI/CD, let's go over a few examples. + +### Using predefined environment variables + +To get started, choose one of the existing +[predefined variables](predefined_variables.md) +to be output by the Runner. For example, let's say that you want +a given job you're running through your script to output the +stage that job is running for. In your `.gitlab-ci.yml` file, +call the variable from your script according to the [syntaxes](#syntax-of-variables-in-job-scripts) available. To +output the job stage, use the predefined variable `CI_JOB_STAGE`: + +```yaml +test_variable: + stage: test + script: + - echo $CI_JOB_STAGE +``` + +For this case, the Runner will output the `stage` for the +job `test_variable`, which is `test`: + +![Output `$CI_JOB_STAGE`](img/ci_job_stage_output_example.png) + +As another example, let's say you're using your own GitLab +instance you want to know what domain your GitLab Pages are +served under. You can easily call it with the predefined +variable `$CI_PAGES_DOMAIN` in your script: + +```yaml +pages: + script: + - ... + - echo $CI_PAGES_DOMAIN +``` + +For GitLab.com users, the output will be `gitlab.io`. For your +private instance, the output will be whatever your sysadmin has +defined. + +### Creating a custom environment variable + +Assume you have something you want to repeat through your scripts +in GitLab CI/CD's configuration file. To keep this example simple, +let's say you want to output `HELLO WORLD` for a `TEST` variable. + +You can either set the variable directly in the `.gitlab-ci.yml` +file or through the UI. + +#### Via [`.gitlab-ci.yml`](../yaml/README.md#variables) + +```yaml +variables: + TEST: "HELLO WORLD" +``` + +For a deeper look into them, see [`.gitlab-ci.yml` defined variables](#gitlab-ciyml-defined-variables). + +#### Via the UI + +From the UI, navigate to your project's **Settings > CI/CD** and +expand **Environment variables**. Create a new variable by naming +it in the field **Input variable key**, and define its value in the +**Input variable value** field: + +![CI/CD settings - new variable](img/new_custom_variable_example.png) + +Once you've set the variables, call them from the `.gitlab-ci.yml` file: + +```yaml +test_variable: + stage: test + script: + - echo $CI_JOB_STAGE # calls a predefined variable + - echo $TEST # calls a custom variable +``` + +The output will be: + +![Output custom variable](img/custom_variable_output.png) + +CAUTION: **Important:** +Be aware that variables are not masked, and their values can be shown +in the job logs if explicitly asked to do so. If your project is public or +internal, you can set the pipelines private from your [project's Pipelines +settings](../../user/project/pipelines/settings.md#visibility-of-pipelines). +Follow the discussion in issue [#13784][ce-13784] for masking the variables. + +### Syntax of environment variables in job scripts +{: #syntax-of-variables-in-job-scripts} -## Predefined environment variables +All variables are set as environment variables in the build environment, and +they are accessible with normal methods that are used to access such variables. +In most cases `bash` or `sh` is used to execute the job script. + +To access environment variables, use the syntax for your Runner's [shell][shellexecutors]. + +| Shell | Usage | +|----------------------|-----------------| +| bash/sh | `$variable` | +| windows batch | `%variable%` | +| PowerShell | `$env:variable` | + +To access environment variables in bash, prefix the variable name with (`$`): + +```yaml +job_name: + script: + - echo $CI_JOB_ID +``` + +To access environment variables in **Windows Batch**, surround the variable +with (`%`): + +```yaml +job_name: + script: + - echo %CI_JOB_ID% +``` -See [full reference of predefined environment variables](predefined_variables.md). +To access environment variables in a **Windows PowerShell** environment, prefix +the variable name with (`$env:`): + +```yaml +job_name: + script: + - echo $env:CI_JOB_ID +``` + +You can also list all environment variables with the `export` command, +but be aware that this will also expose the values of all the variables +you set, in the job log: + +```yaml +job_name: + script: + - export +``` + +Example values: + +```bash +export CI_JOB_ID="50" +export CI_COMMIT_SHA="1ecfd275763eff1d6b4844ea3168962458c9f27a" +export CI_COMMIT_SHORT_SHA="1ecfd275" +export CI_COMMIT_REF_NAME="master" +export CI_REPOSITORY_URL="https://gitlab-ci-token:abcde-1234ABCD5678ef@example.com/gitlab-org/gitlab-ce.git" +export CI_COMMIT_TAG="1.0.0" +export CI_JOB_NAME="spec:other" +export CI_JOB_STAGE="test" +export CI_JOB_MANUAL="true" +export CI_JOB_TRIGGERED="true" +export CI_JOB_TOKEN="abcde-1234ABCD5678ef" +export CI_PIPELINE_ID="1000" +export CI_PIPELINE_IID="10" +export CI_PAGES_DOMAIN="gitlab.io" +export CI_PAGES_URL="https://gitlab-org.gitlab.io/gitlab-ce" +export CI_PROJECT_ID="34" +export CI_PROJECT_DIR="/builds/gitlab-org/gitlab-ce" +export CI_PROJECT_NAME="gitlab-ce" +export CI_PROJECT_NAMESPACE="gitlab-org" +export CI_PROJECT_PATH="gitlab-org/gitlab-ce" +export CI_PROJECT_URL="https://example.com/gitlab-org/gitlab-ce" +export CI_REGISTRY="registry.example.com" +export CI_REGISTRY_IMAGE="registry.example.com/gitlab-org/gitlab-ce" +export CI_RUNNER_ID="10" +export CI_RUNNER_DESCRIPTION="my runner" +export CI_RUNNER_TAGS="docker, linux" +export CI_SERVER="yes" +export CI_SERVER_NAME="GitLab" +export CI_SERVER_REVISION="70606bf" +export CI_SERVER_VERSION="8.9.0" +export CI_SERVER_VERSION_MAJOR="8" +export CI_SERVER_VERSION_MINOR="9" +export CI_SERVER_VERSION_PATCH="0" +export GITLAB_USER_ID="42" +export GITLAB_USER_EMAIL="user@example.com" +export CI_REGISTRY_USER="gitlab-ci-token" +export CI_REGISTRY_PASSWORD="longalfanumstring" +``` -## `.gitlab-ci.yml` defined variables +### `.gitlab-ci.yml` defined variables -NOTE **Note:** +NOTE: **Note:** This feature requires GitLab Runner 0.5.0 or higher and GitLab 7.14 or higher. GitLab CI allows you to add to `.gitlab-ci.yml` variables that are set in the @@ -82,42 +277,63 @@ script: - 'eval $LS_CMD' # will execute 'ls -al $TMP_DIR' ``` -## Variables +### Group-level environment variables +{: #group-level-variables} -> Group-level variables were introduced in GitLab 9.4. - -CAUTION: **Important:** -Be aware that variables are not masked, and their values can be shown -in the job logs if explicitly asked to do so. If your project is public or -internal, you can set the pipelines private from your [project's Pipelines -settings](../../user/project/pipelines/settings.md#visibility-of-pipelines). -Follow the discussion in issue [#13784][ce-13784] for masking the variables. +> Introduced in GitLab 9.4. -GitLab CI allows you to define per-project or per-group variables -that are set in the pipeline environment. The variables are stored out of +GitLab CI/CD allows you to define per-project or per-group variables +that are set in the pipeline environment. Group-level variables are stored out of the repository (not in `.gitlab-ci.yml`) and are securely passed to GitLab Runner -making them available during a pipeline run. It's the recommended method to +making them available during a pipeline run. It's the **recommended method** to use for storing things like passwords, SSH keys, and credentials. -Project-level variables can be added by: +Group-level variables can be added by: -1. Navigating to your project's **Settings > CI/CD** page. +1. Navigating to your group's **Settings > CI/CD** page. 1. Inputing variable keys and values in the **Environment variables** section. +Any variables of [subgroups](../../user/group/subgroups/index.md) will be inherited recursively. -Group-level variables can be added by: +Once you set them, they will be available for all subsequent pipelines. -1. Navigating to your group's **Settings > CI/CD** page. -1. Inputing variable keys and values in the **Environment variables** section. Any variables of - [subgroups](../../user/group/subgroups/index.md) will be inherited recursively. +## Priority of environment variables +{: #priority-of-variables} + +Variables of different types can take precedence over other +variables, depending on where they are defined. + +The order of precedence for variables is (from highest to lowest): + +1. [Trigger variables](../triggers/README.md#making-use-of-trigger-variables) or [scheduled pipeline variables](../../user/project/pipelines/schedules.md#making-use-of-scheduled-pipeline-variables). +1. Project-level [variables](#creating-a-custom-environment-variable) or [protected variables](#protected-variables). +1. Group-level [variables](#group-level-variables) or [protected variables](#protected-variables). +1. YAML-defined [job-level variables](../yaml/README.md#variables). +1. YAML-defined [global variables](../yaml/README.md#variables). +1. [Deployment variables](#deployment-variables). +1. [Predefined environment variables](predefined_variables.md). + +For example, if you define: + +- `API_TOKEN=secure` as a project variable. +- `API_TOKEN=yaml` in your `.gitlab-ci.yml`. -Once you set them, they will be available for all subsequent pipelines. You can also -[protect your variables](#protected-variables). +`API_TOKEN` will take the value `secure` as the project +variables take precedence over those defined in `.gitlab-ci.yml`. -### Protected variables +## Unsupported variables + +There are cases where some variables cannot be used in the context of a +`.gitlab-ci.yml` definition (for example under `script`). Read more +about which variables are [not supported](where_variables_can_be_used.md). + +## Advanced use + +### Protected environment variables +{: #protected-variables} > Introduced in GitLab 9.3. -Variables could be protected. Whenever a variable is +Variables can be protected. Whenever a variable is protected, it would only be securely passed to pipelines running on the [protected branches] or [protected tags]. The other pipelines would not get any protected variables. @@ -128,13 +344,8 @@ Protected variables can be added by going to your project's Once you set them, they will be available for all subsequent pipelines. -### Manually-specified variables - -> [Introduced](https://gitlab.com/gitlab-org/gitlab-ce/issues/44059) in GitLab 10.8. - -Variables can be specified for a single pipeline run when a [manual pipeline](../pipelines.md#manually-executing-pipelines) is created. - -## Deployment variables +### Deployment environment variables +{: #deployment-variables} > Introduced in GitLab 8.15. @@ -147,7 +358,7 @@ the project services that you are using to learn which variables they define. An example project service that defines deployment variables is the [Kubernetes integration](../../user/project/clusters/index.md#deployment-variables). -## Auto DevOps application variables +### Auto DevOps environment variables > [Introduced](https://gitlab.com/gitlab-org/gitlab-ce/issues/49056) in GitLab 11.7. @@ -164,6 +375,113 @@ CAUTION: **Caution:** Variables with multiline values are not currently supported due to limitations with the current Auto DevOps scripting environment. +### Environment variables triggered manually + +> [Introduced](https://gitlab.com/gitlab-org/gitlab-ce/issues/44059) in GitLab 10.8. + +[Manually triggered pipelines](../pipelines.md#manually-executing-pipelines) allow you to override the value of a current variable. + +For instance, suppose you added a +[custom variable `$TEST`](#creating-a-custom-variable) +as exemplified above and you want to override it in a manual pipeline. +Navigate to your project's **CI/CD > Pipelines** and click **Run pipeline**. +Choose the branch you want to run the pipeline for, then add a new variable +pair through the UI: + +![Override variable value](img/override_variable_manual_pipeline.png) + +The Runner will override the value previously set and use the custom +value you set for this specific pipeline: + +![Manually overridden variable output](img/override_value_via_manual_pipeline_output.png) + +## Environment variables expressions +{: #variables-expressions} + +> Introduced in GitLab 10.7. + +It is possible to use variables expressions with only / except policies in +`.gitlab-ci.yml`. By using this approach you can limit what jobs are going to +be created within a pipeline after pushing a code to GitLab. + +This is particularly useful in combination with variables and triggered +pipeline variables. + +```yaml +deploy: + script: cap staging deploy + environment: staging + only: + variables: + - $RELEASE == "staging" + - $STAGING +``` + +Each expression provided is going to be evaluated before creating a pipeline. + +If any of the conditions in `variables` evaluates to truth when using `only`, +a new job is going to be created. If any of the expressions evaluates to truth +when `except` is being used, a job is not going to be created. + +This follows usual rules for [`only` / `except` policies](../yaml/README.md#onlyexcept-advanced). + +### Supported syntax + +Below you can find supported syntax reference: + +1. Equality matching using a string + + > Example: `$VARIABLE == "some value"` + + You can use equality operator `==` to compare a variable content to a + string. We support both, double quotes and single quotes to define a string + value, so both `$VARIABLE == "some value"` and `$VARIABLE == 'some value'` + are supported. `"some value" == $VARIABLE` is correct too. + +1. Checking for an undefined value + + > Example: `$VARIABLE == null` + + It sometimes happens that you want to check whether a variable is defined + or not. To do that, you can compare a variable to `null` keyword, like + `$VARIABLE == null`. This expression is going to evaluate to truth if + variable is not defined. + +1. Checking for an empty variable + + > Example: `$VARIABLE == ""` + + If you want to check whether a variable is defined, but is empty, you can + simply compare it against an empty string, like `$VAR == ''`. + +1. Comparing two variables + + > Example: `$VARIABLE_1 == $VARIABLE_2` + + It is possible to compare two variables. This is going to compare values + of these variables. + +1. Variable presence check + + > Example: `$STAGING` + + If you only want to create a job when there is some variable present, + which means that it is defined and non-empty, you can simply use + variable name as an expression, like `$STAGING`. If `$STAGING` variable + is defined, and is non empty, expression will evaluate to truth. + `$STAGING` value needs to a string, with length higher than zero. + Variable that contains only whitespace characters is not an empty variable. + +1. Pattern matching _(added in 11.0)_ + + > Example: `$VARIABLE =~ /^content.*/` + + It is possible perform pattern matching against a variable and regular + expression. Expression like this evaluates to truth if matches are found. + + Pattern matching is case-sensitive by default. Use `i` flag modifier, like + `/pattern/i` to make a pattern case-insensitive. + ## Debug tracing > Introduced in GitLab Runner 1.7. @@ -329,184 +647,6 @@ MIIFQzCCBCugAwIBAgIRAL/ElDjuf15xwja1ZnCocWAwDQYJKoZIhvcNAQELBQAw' ... ``` -## Using the CI variables in your job scripts - -All variables are set as environment variables in the build environment, and -they are accessible with normal methods that are used to access such variables. -In most cases `bash` or `sh` is used to execute the job script. - -To access environment variables, use the syntax for your Runner's [shell][shellexecutors]. - -| Shell | Usage | -|----------------------|-----------------| -| bash/sh | `$variable` | -| windows batch | `%variable%` | -| PowerShell | `$env:variable` | - -To access environment variables in bash, prefix the variable name with (`$`): - -```yaml -job_name: - script: - - echo $CI_JOB_ID -``` - -To access environment variables in **Windows Batch**, surround the variable -with (`%`): - -```yaml -job_name: - script: - - echo %CI_JOB_ID% -``` - -To access environment variables in a **Windows PowerShell** environment, prefix -the variable name with (`$env:`): - -```yaml -job_name: - script: - - echo $env:CI_JOB_ID -``` - -You can also list all environment variables with the `export` command, -but be aware that this will also expose the values of all the variables -you set, in the job log: - -```yaml -job_name: - script: - - export -``` - -Example values: - -```bash -export CI_JOB_ID="50" -export CI_COMMIT_SHA="1ecfd275763eff1d6b4844ea3168962458c9f27a" -export CI_COMMIT_SHORT_SHA="1ecfd275" -export CI_COMMIT_REF_NAME="master" -export CI_REPOSITORY_URL="https://gitlab-ci-token:abcde-1234ABCD5678ef@example.com/gitlab-org/gitlab-ce.git" -export CI_COMMIT_TAG="1.0.0" -export CI_JOB_NAME="spec:other" -export CI_JOB_STAGE="test" -export CI_JOB_MANUAL="true" -export CI_JOB_TRIGGERED="true" -export CI_JOB_TOKEN="abcde-1234ABCD5678ef" -export CI_PIPELINE_ID="1000" -export CI_PIPELINE_IID="10" -export CI_PAGES_DOMAIN="gitlab.io" -export CI_PAGES_URL="https://gitlab-org.gitlab.io/gitlab-ce" -export CI_PROJECT_ID="34" -export CI_PROJECT_DIR="/builds/gitlab-org/gitlab-ce" -export CI_PROJECT_NAME="gitlab-ce" -export CI_PROJECT_NAMESPACE="gitlab-org" -export CI_PROJECT_PATH="gitlab-org/gitlab-ce" -export CI_PROJECT_URL="https://example.com/gitlab-org/gitlab-ce" -export CI_REGISTRY="registry.example.com" -export CI_REGISTRY_IMAGE="registry.example.com/gitlab-org/gitlab-ce" -export CI_RUNNER_ID="10" -export CI_RUNNER_DESCRIPTION="my runner" -export CI_RUNNER_TAGS="docker, linux" -export CI_SERVER="yes" -export CI_SERVER_NAME="GitLab" -export CI_SERVER_REVISION="70606bf" -export CI_SERVER_VERSION="8.9.0" -export CI_SERVER_VERSION_MAJOR="8" -export CI_SERVER_VERSION_MINOR="9" -export CI_SERVER_VERSION_PATCH="0" -export GITLAB_USER_ID="42" -export GITLAB_USER_EMAIL="user@example.com" -export CI_REGISTRY_USER="gitlab-ci-token" -export CI_REGISTRY_PASSWORD="longalfanumstring" -``` - -## Variables expressions - -> Introduced in GitLab 10.7. - -It is possible to use variables expressions with only / except policies in -`.gitlab-ci.yml`. By using this approach you can limit what jobs are going to -be created within a pipeline after pushing a code to GitLab. - -This is particularly useful in combination with variables and triggered -pipeline variables. - -```yaml -deploy: - script: cap staging deploy - environment: staging - only: - variables: - - $RELEASE == "staging" - - $STAGING -``` - -Each expression provided is going to be evaluated before creating a pipeline. - -If any of the conditions in `variables` evaluates to truth when using `only`, -a new job is going to be created. If any of the expressions evaluates to truth -when `except` is being used, a job is not going to be created. - -This follows usual rules for [`only` / `except` policies](../yaml/README.md#onlyexcept-advanced). - -### Supported syntax - -Below you can find supported syntax reference: - -1. Equality matching using a string - - > Example: `$VARIABLE == "some value"` - - You can use equality operator `==` to compare a variable content to a - string. We support both, double quotes and single quotes to define a string - value, so both `$VARIABLE == "some value"` and `$VARIABLE == 'some value'` - are supported. `"some value" == $VARIABLE` is correct too. - -1. Checking for an undefined value - - > Example: `$VARIABLE == null` - - It sometimes happens that you want to check whether a variable is defined - or not. To do that, you can compare a variable to `null` keyword, like - `$VARIABLE == null`. This expression is going to evaluate to truth if - variable is not defined. - -1. Checking for an empty variable - - > Example: `$VARIABLE == ""` - - If you want to check whether a variable is defined, but is empty, you can - simply compare it against an empty string, like `$VAR == ''`. - -1. Comparing two variables - - > Example: `$VARIABLE_1 == $VARIABLE_2` - - It is possible to compare two variables. This is going to compare values - of these variables. - -1. Variable presence check - - > Example: `$STAGING` - - If you only want to create a job when there is some variable present, - which means that it is defined and non-empty, you can simply use - variable name as an expression, like `$STAGING`. If `$STAGING` variable - is defined, and is non empty, expression will evaluate to truth. - `$STAGING` value needs to a string, with length higher than zero. - Variable that contains only whitespace characters is not an empty variable. - -1. Pattern matching _(added in 11.0)_ - - > Example: `$VARIABLE =~ /^content.*/` - - It is possible perform pattern matching against a variable and regular - expression. Expression like this evaluates to truth if matches are found. - - Pattern matching is case-sensitive by default. Use `i` flag modifier, like - `/pattern/i` to make a pattern case-insensitive. - [ce-13784]: https://gitlab.com/gitlab-org/gitlab-ce/issues/13784 "Simple protection of CI variables" [eep]: https://about.gitlab.com/pricing/ "Available only in GitLab Premium" [envs]: ../environments.md diff --git a/doc/ci/variables/img/ci_job_stage_output_example.png b/doc/ci/variables/img/ci_job_stage_output_example.png new file mode 100755 index 00000000000..056238d5693 Binary files /dev/null and b/doc/ci/variables/img/ci_job_stage_output_example.png differ diff --git a/doc/ci/variables/img/custom_variable_output.png b/doc/ci/variables/img/custom_variable_output.png new file mode 100755 index 00000000000..50f3bceff9a Binary files /dev/null and b/doc/ci/variables/img/custom_variable_output.png differ diff --git a/doc/ci/variables/img/new_custom_variable_example.png b/doc/ci/variables/img/new_custom_variable_example.png new file mode 100755 index 00000000000..d169c5f1806 Binary files /dev/null and b/doc/ci/variables/img/new_custom_variable_example.png differ diff --git a/doc/ci/variables/img/override_value_via_manual_pipeline_output.png b/doc/ci/variables/img/override_value_via_manual_pipeline_output.png new file mode 100755 index 00000000000..02369d57fb8 Binary files /dev/null and b/doc/ci/variables/img/override_value_via_manual_pipeline_output.png differ diff --git a/doc/ci/variables/img/override_variable_manual_pipeline.png b/doc/ci/variables/img/override_variable_manual_pipeline.png new file mode 100755 index 00000000000..3bcd354e096 Binary files /dev/null and b/doc/ci/variables/img/override_variable_manual_pipeline.png differ -- cgit v1.2.1 From 3a9e3aa9ef905fd9a2433e79a3c0f2a0954aaeec Mon Sep 17 00:00:00 2001 From: Olliver Schinagl Date: Tue, 2 Apr 2019 19:21:46 +0200 Subject: Add missing 'export' example for CI_API_V4_API_URL In issue #54621 a new variable CI_API_V4_API_URL was introduced, but some of the documentation was omitted. Having an example output is always nice. Signed-off-by: Olliver Schinagl --- doc/ci/variables/README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/ci/variables/README.md b/doc/ci/variables/README.md index 12b027e7d79..e4d826e5919 100644 --- a/doc/ci/variables/README.md +++ b/doc/ci/variables/README.md @@ -228,6 +228,8 @@ $'\''git'\'' "checkout" "-f" "-q" "dd648b2e48ce6518303b0bb580b2ee32fadaf045" Running on runner-8a2f473d-project-1796893-concurrent-0 via runner-8a2f473d-machine-1480971377-317a7d0f-digital-ocean-4gb... ++ export CI=true ++ CI=true +++ export CI_API_V4_API_URL=https://example.com:3000/api/v4 +++ CI_API_V4_API_URL=https://example.com:3000/api/v4 ++ export CI_DEBUG_TRACE=false ++ CI_DEBUG_TRACE=false ++ export CI_COMMIT_SHA=dd648b2e48ce6518303b0bb580b2ee32fadaf045 @@ -266,6 +268,8 @@ Running on runner-8a2f473d-project-1796893-concurrent-0 via runner-8a2f473d-mach ++ GITLAB_CI=true ++ export CI=true ++ CI=true +++ export CI_API_V4_API_URL=https://example.com:3000/api/v4 +++ CI_API_V4_API_URL=https://example.com:3000/api/v4 ++ export GITLAB_CI=true ++ GITLAB_CI=true ++ export CI_JOB_ID=7046507 -- cgit v1.2.1 From f3b81ee6f2b3e7439ab0e5507c024f277fc446bd Mon Sep 17 00:00:00 2001 From: Lukas 'Eipi' Eipert Date: Tue, 2 Apr 2019 19:26:26 +0000 Subject: Update dependency @gitlab/svgs to ^1.58.0 --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index a2d96cc551a..29a3b3d0459 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "@babel/plugin-syntax-import-meta": "^7.2.0", "@babel/preset-env": "^7.3.1", "@gitlab/csslab": "^1.9.0", - "@gitlab/svgs": "^1.57.0", + "@gitlab/svgs": "^1.58.0", "@gitlab/ui": "^3.0.0", "apollo-cache-inmemory": "^1.5.1", "apollo-client": "^2.5.1", diff --git a/yarn.lock b/yarn.lock index 5d40bec659d..581d5818ccc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -658,10 +658,10 @@ eslint-plugin-promise "^4.0.1" eslint-plugin-vue "^5.0.0" -"@gitlab/svgs@^1.57.0": - version "1.57.0" - resolved "https://registry.yarnpkg.com/@gitlab/svgs/-/svgs-1.57.0.tgz#969ac7bf16337d5de3808fee6fb5c13eefd99478" - integrity sha512-AAVvPDaxCsojmOyVVTyaOcob+bPhtYJ+GbtmmNNCHg2dXYDAEgy3+TYzAfV5fQ08TCZ9DPiKEjDIi2ODh0x/8g== +"@gitlab/svgs@^1.58.0": + version "1.58.0" + resolved "https://registry.yarnpkg.com/@gitlab/svgs/-/svgs-1.58.0.tgz#bb05263ff2eb7ca09a25cd14d0b1a932d2ea9c2f" + integrity sha512-RlWSjjBT4lMIFuNC1ziCO1nws9zqZtxCjhrqK2DxDDTgp2W0At9M/BFkHp8RHyMCrO3g1fHTrLPUgzr5oR3Epg== "@gitlab/ui@^3.0.0": version "3.0.0" -- cgit v1.2.1 From 0c45e268a1523797712380eca479e18e5b59cc2e Mon Sep 17 00:00:00 2001 From: Jan Provaznik Date: Tue, 2 Apr 2019 20:05:56 +0000 Subject: Revert "Merge branch 'jprovazn-graphql-prometheus' into 'master'" This reverts merge request !26569 --- app/graphql/gitlab_schema.rb | 1 - changelogs/unreleased/graphql-prometheus.yml | 5 ---- lib/gitlab/graphql/tracing.rb | 43 ---------------------------- spec/lib/gitlab/graphql/tracing_spec.rb | 35 ---------------------- 4 files changed, 84 deletions(-) delete mode 100644 changelogs/unreleased/graphql-prometheus.yml delete mode 100644 lib/gitlab/graphql/tracing.rb delete mode 100644 spec/lib/gitlab/graphql/tracing_spec.rb diff --git a/app/graphql/gitlab_schema.rb b/app/graphql/gitlab_schema.rb index ecc34eacc7d..06d26309b5b 100644 --- a/app/graphql/gitlab_schema.rb +++ b/app/graphql/gitlab_schema.rb @@ -5,7 +5,6 @@ class GitlabSchema < GraphQL::Schema use Gitlab::Graphql::Authorize use Gitlab::Graphql::Present use Gitlab::Graphql::Connections - use Gitlab::Graphql::Tracing query(Types::QueryType) diff --git a/changelogs/unreleased/graphql-prometheus.yml b/changelogs/unreleased/graphql-prometheus.yml deleted file mode 100644 index 180577f3aec..00000000000 --- a/changelogs/unreleased/graphql-prometheus.yml +++ /dev/null @@ -1,5 +0,0 @@ ---- -title: Added prometheus monitoring to GraphQL -merge_request: -author: -type: added diff --git a/lib/gitlab/graphql/tracing.rb b/lib/gitlab/graphql/tracing.rb deleted file mode 100644 index 6b505e4262b..00000000000 --- a/lib/gitlab/graphql/tracing.rb +++ /dev/null @@ -1,43 +0,0 @@ -# frozen_string_literal: true - -module Gitlab - module Graphql - class Tracing < GraphQL::Tracing::PlatformTracing - self.platform_keys = { - 'lex' => 'graphql.lex', - 'parse' => 'graphql.parse', - 'validate' => 'graphql.validate', - 'analyze_query' => 'graphql.analyze', - 'analyze_multiplex' => 'graphql.analyze', - 'execute_multiplex' => 'graphql.execute', - 'execute_query' => 'graphql.execute', - 'execute_query_lazy' => 'graphql.execute', - 'execute_field' => 'graphql.execute', - 'execute_field_lazy' => 'graphql.execute' - } - - def platform_field_key(type, field) - "#{type.name}.#{field.name}" - end - - def platform_trace(platform_key, key, data, &block) - start = Gitlab::Metrics::System.monotonic_time - - yield - ensure - duration = Gitlab::Metrics::System.monotonic_time - start - - graphql_duration_seconds.observe({ platform_key: platform_key, key: key }, duration) - end - - private - - def graphql_duration_seconds - @graphql_duration_seconds ||= Gitlab::Metrics.histogram( - :graphql_duration_seconds, - 'GraphQL execution time' - ) - end - end - end -end diff --git a/spec/lib/gitlab/graphql/tracing_spec.rb b/spec/lib/gitlab/graphql/tracing_spec.rb deleted file mode 100644 index 6bae737d0f6..00000000000 --- a/spec/lib/gitlab/graphql/tracing_spec.rb +++ /dev/null @@ -1,35 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe Gitlab::Graphql::Tracing do - let!(:graphql_duration_seconds) { double('Gitlab::Metrics::NullMetric') } - - before do - allow(Gitlab::Metrics) - .to receive(:histogram) - .with(:graphql_duration_seconds, 'GraphQL execution time') - .and_return(graphql_duration_seconds) - end - - it 'updates graphql histogram with expected labels' do - query = 'query { users { id } }' - - expect_metric('graphql.lex', 'lex') - expect_metric('graphql.parse', 'parse') - expect_metric('graphql.validate', 'validate') - expect_metric('graphql.analyze', 'analyze_multiplex') - expect_metric('graphql.execute', 'execute_query_lazy') - expect_metric('graphql.execute', 'execute_multiplex') - - GitlabSchema.execute(query) - end - - private - - def expect_metric(platform_key, key) - expect(graphql_duration_seconds) - .to receive(:observe) - .with({ platform_key: platform_key, key: key }, be > 0.0) - end -end -- cgit v1.2.1 From 2378dde2e2fa0de41f4f578e56209dc96b5a82c1 Mon Sep 17 00:00:00 2001 From: Donald Cook Date: Tue, 2 Apr 2019 20:23:23 +0000 Subject: Remove non-functional add issue button on welcome list --- app/assets/javascripts/boards/components/board.js | 5 ++++- app/assets/stylesheets/pages/boards.scss | 2 +- .../unreleased/55980-remove-add-issue-on-blank-list.yml | 5 +++++ spec/javascripts/boards/components/board_spec.js | 14 ++++++++++++++ 4 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 changelogs/unreleased/55980-remove-add-issue-on-blank-list.yml diff --git a/app/assets/javascripts/boards/components/board.js b/app/assets/javascripts/boards/components/board.js index fb6e5291a61..45b9e57f9ab 100644 --- a/app/assets/javascripts/boards/components/board.js +++ b/app/assets/javascripts/boards/components/board.js @@ -54,7 +54,10 @@ export default Vue.extend({ return `${n__('%d issue', '%d issues', issuesSize)}`; }, isNewIssueShown() { - return this.list.type === 'backlog' || (!this.disabled && this.list.type !== 'closed'); + return ( + this.list.type === 'backlog' || + (!this.disabled && this.list.type !== 'closed' && this.list.type !== 'blank') + ); }, }, watch: { diff --git a/app/assets/stylesheets/pages/boards.scss b/app/assets/stylesheets/pages/boards.scss index ed0e9db035b..fc1c1bd9962 100644 --- a/app/assets/stylesheets/pages/boards.scss +++ b/app/assets/stylesheets/pages/boards.scss @@ -234,7 +234,7 @@ } .board-title-text { - margin-right: auto; + margin: $gl-vert-padding auto $gl-vert-padding 0; } .board-delete { diff --git a/changelogs/unreleased/55980-remove-add-issue-on-blank-list.yml b/changelogs/unreleased/55980-remove-add-issue-on-blank-list.yml new file mode 100644 index 00000000000..4c16b635297 --- /dev/null +++ b/changelogs/unreleased/55980-remove-add-issue-on-blank-list.yml @@ -0,0 +1,5 @@ +--- +title: Remove non-functional add issue button on welcome list +merge_request: !26742 +author: +type: fixed diff --git a/spec/javascripts/boards/components/board_spec.js b/spec/javascripts/boards/components/board_spec.js index 6e6b3e6950b..d08ee41802b 100644 --- a/spec/javascripts/boards/components/board_spec.js +++ b/spec/javascripts/boards/components/board_spec.js @@ -103,4 +103,18 @@ describe('Board component', () => { }) .catch(done.fail); }); + + it('does render add issue button', () => { + expect(vm.$el.querySelector('.issue-count-badge-add-button')).not.toBeNull(); + }); + + it('does not render add issue button when list type is blank', done => { + vm.list.type = 'blank'; + + Vue.nextTick(() => { + expect(vm.$el.querySelector('.issue-count-badge-add-button')).toBeNull(); + + done(); + }); + }); }); -- cgit v1.2.1 From 0e9b47870710426f98074e508cc2cb432d18a755 Mon Sep 17 00:00:00 2001 From: William Chia Date: Tue, 2 Apr 2019 21:08:25 +0000 Subject: remove html tag --- doc/user/project/clusters/serverless/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/user/project/clusters/serverless/index.md b/doc/user/project/clusters/serverless/index.md index e6804666e22..96bf455116c 100644 --- a/doc/user/project/clusters/serverless/index.md +++ b/doc/user/project/clusters/serverless/index.md @@ -214,7 +214,7 @@ The sample function can now be triggered from any HTTP client using a simple `PO --header "Content-Type: application/json" \ --request POST \ --data '{"GitLab":"FaaS"}' \ - + http://functions-echo.functions-1.functions.example.com ``` 2. Using a web-based tool (ie. postman, restlet, etc) -- cgit v1.2.1 From 4e5fc1949fb86eed92f7af6a2d98b55286d9b0b4 Mon Sep 17 00:00:00 2001 From: Fatih Acet Date: Fri, 29 Mar 2019 16:02:55 +0100 Subject: Show Download diff links in closed MRs Download MR diffs links were only available for open MRs, however it may still be useful for closed MRs. --- .../components/mr_widget_header.vue | 48 +++++++++++----------- ...load-diff-even-when-merge-request-is-closed.yml | 5 +++ .../components/mr_widget_header_spec.js | 32 ++++++--------- 3 files changed, 43 insertions(+), 42 deletions(-) create mode 100644 changelogs/unreleased/29249-show-download-diff-even-when-merge-request-is-closed.yml diff --git a/app/assets/javascripts/vue_merge_request_widget/components/mr_widget_header.vue b/app/assets/javascripts/vue_merge_request_widget/components/mr_widget_header.vue index 50ab7ead582..361441640e1 100644 --- a/app/assets/javascripts/vue_merge_request_widget/components/mr_widget_header.vue +++ b/app/assets/javascripts/vue_merge_request_widget/components/mr_widget_header.vue @@ -109,29 +109,31 @@ export default { > -
- - {{ s__('mrWidget|Open in Web IDE') }} - - +
+
User posts notes', :js do end end - describe 'when reply_to_individual_notes feature flag is disabled' do - before do - stub_feature_flags(reply_to_individual_notes: false) - visit project_merge_request_path(project, merge_request) - end - - it 'does not show a reply button' do - expect(page).to have_no_selector('.js-reply-button') - end - end - - describe 'when reply_to_individual_notes feature flag is not set' do + describe 'reply button' do before do visit project_merge_request_path(project, merge_request) end diff --git a/spec/javascripts/notes/components/note_actions_spec.js b/spec/javascripts/notes/components/note_actions_spec.js index d604e90b529..0cfcc994234 100644 --- a/spec/javascripts/notes/components/note_actions_spec.js +++ b/spec/javascripts/notes/components/note_actions_spec.js @@ -128,87 +128,33 @@ describe('noteActions', () => { }); }); - describe('with feature flag replyToIndividualNotes enabled', () => { + describe('for showReply = true', () => { beforeEach(() => { - gon.features = { - replyToIndividualNotes: true, - }; - }); - - afterEach(() => { - gon.features = {}; - }); - - describe('for showReply = true', () => { - beforeEach(() => { - wrapper = shallowMountNoteActions({ - ...props, - showReply: true, - }); - }); - - it('shows a reply button', () => { - const replyButton = wrapper.find({ ref: 'replyButton' }); - - expect(replyButton.exists()).toBe(true); + wrapper = shallowMountNoteActions({ + ...props, + showReply: true, }); }); - describe('for showReply = false', () => { - beforeEach(() => { - wrapper = shallowMountNoteActions({ - ...props, - showReply: false, - }); - }); - - it('does not show a reply button', () => { - const replyButton = wrapper.find({ ref: 'replyButton' }); + it('shows a reply button', () => { + const replyButton = wrapper.find({ ref: 'replyButton' }); - expect(replyButton.exists()).toBe(false); - }); + expect(replyButton.exists()).toBe(true); }); }); - describe('with feature flag replyToIndividualNotes disabled', () => { + describe('for showReply = false', () => { beforeEach(() => { - gon.features = { - replyToIndividualNotes: false, - }; - }); - - afterEach(() => { - gon.features = {}; - }); - - describe('for showReply = true', () => { - beforeEach(() => { - wrapper = shallowMountNoteActions({ - ...props, - showReply: true, - }); - }); - - it('does not show a reply button', () => { - const replyButton = wrapper.find({ ref: 'replyButton' }); - - expect(replyButton.exists()).toBe(false); + wrapper = shallowMountNoteActions({ + ...props, + showReply: false, }); }); - describe('for showReply = false', () => { - beforeEach(() => { - wrapper = shallowMountNoteActions({ - ...props, - showReply: false, - }); - }); - - it('does not show a reply button', () => { - const replyButton = wrapper.find({ ref: 'replyButton' }); + it('does not show a reply button', () => { + const replyButton = wrapper.find({ ref: 'replyButton' }); - expect(replyButton.exists()).toBe(false); - }); + expect(replyButton.exists()).toBe(false); }); }); }); diff --git a/spec/services/notes/build_service_spec.rb b/spec/services/notes/build_service_spec.rb index af4daff336b..96fff20f7fb 100644 --- a/spec/services/notes/build_service_spec.rb +++ b/spec/services/notes/build_service_spec.rb @@ -128,37 +128,19 @@ describe Notes::BuildService do subject { described_class.new(project, author, note: 'Test', in_reply_to_discussion_id: note.discussion_id).execute } - shared_examples 'an individual note reply' do - it 'builds another individual note' do - expect(subject).to be_valid - expect(subject).to be_a(Note) - expect(subject.discussion_id).not_to eq(note.discussion_id) - end + it 'sets the note up to be in reply to that note' do + expect(subject).to be_valid + expect(subject).to be_a(DiscussionNote) + expect(subject.discussion_id).to eq(note.discussion_id) end - context 'when reply_to_individual_notes is disabled' do - before do - stub_feature_flags(reply_to_individual_notes: false) - end - - it_behaves_like 'an individual note reply' - end + context 'when noteable does not support replies' do + let(:note) { create(:note_on_commit) } - context 'when reply_to_individual_notes is enabled' do - before do - stub_feature_flags(reply_to_individual_notes: true) - end - - it 'sets the note up to be in reply to that note' do + it 'builds another individual note' do expect(subject).to be_valid - expect(subject).to be_a(DiscussionNote) - expect(subject.discussion_id).to eq(note.discussion_id) - end - - context 'when noteable does not support replies' do - let(:note) { create(:note_on_commit) } - - it_behaves_like 'an individual note reply' + expect(subject).to be_a(Note) + expect(subject.discussion_id).not_to eq(note.discussion_id) end end end diff --git a/spec/services/notes/create_service_spec.rb b/spec/services/notes/create_service_spec.rb index 8d8e81173ff..bcbb8950910 100644 --- a/spec/services/notes/create_service_spec.rb +++ b/spec/services/notes/create_service_spec.rb @@ -298,41 +298,20 @@ describe Notes::CreateService do subject { described_class.new(project, user, reply_opts).execute } - context 'when reply_to_individual_notes is disabled' do - before do - stub_feature_flags(reply_to_individual_notes: false) - end - - it 'creates an individual note' do - expect(subject.type).to eq(nil) - expect(subject.discussion_id).not_to eq(existing_note.discussion_id) - end - - it 'does not convert existing note' do - expect { subject }.not_to change { existing_note.reload.type } - end + it 'creates a DiscussionNote in reply to existing note' do + expect(subject).to be_a(DiscussionNote) + expect(subject.discussion_id).to eq(existing_note.discussion_id) end - context 'when reply_to_individual_notes is enabled' do - before do - stub_feature_flags(reply_to_individual_notes: true) - end - - it 'creates a DiscussionNote in reply to existing note' do - expect(subject).to be_a(DiscussionNote) - expect(subject.discussion_id).to eq(existing_note.discussion_id) - end - - it 'converts existing note to DiscussionNote' do - expect do - existing_note + it 'converts existing note to DiscussionNote' do + expect do + existing_note - Timecop.freeze(Time.now + 1.minute) { subject } + Timecop.freeze(Time.now + 1.minute) { subject } - existing_note.reload - end.to change { existing_note.type }.from(nil).to('DiscussionNote') - .and change { existing_note.updated_at } - end + existing_note.reload + end.to change { existing_note.type }.from(nil).to('DiscussionNote') + .and change { existing_note.updated_at } end end end -- cgit v1.2.1 From 00f112157009ab178983beb1ebbea6f890442796 Mon Sep 17 00:00:00 2001 From: Cody Mize Date: Wed, 3 Apr 2019 04:33:55 +0000 Subject: Document matching refs with an at-symbol At-symbols are used to match a ref to a specific repository path. Currently this is done by string splitting the ref pattern on the at-symbol. In order to pattern match a literal `@` you must use ruby's unicode character matching `\u{0040}`. --- doc/ci/yaml/README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/doc/ci/yaml/README.md b/doc/ci/yaml/README.md index 5690729c370..83a226d3577 100644 --- a/doc/ci/yaml/README.md +++ b/doc/ci/yaml/README.md @@ -391,6 +391,11 @@ job: The above example will run `job` for all branches on `gitlab-org/gitlab-ce`, except `master` and those with names prefixed with `release/`. +NOTE: **Note:** +Because `@` is used to denote the beginning of a ref's repository path, +matching a ref name containing the `@` character in a regular expression +requires the use of the hex character code match `\x40`. + If a job does not have an `only` rule, `only: ['branches', 'tags']` is set by default. If it doesn't have an `except` rule, it is empty. -- cgit v1.2.1 From e3b38ae09d8e84023a133d48b038994aa122f4b9 Mon Sep 17 00:00:00 2001 From: Shinya Maeda Date: Wed, 3 Apr 2019 12:23:11 +0700 Subject: Fix Release permission spec We recently changed the permission model to disallow guests to read Releases. The spec should be updated as well according to the expectation. --- spec/support/shared_context/policies/project_policy_shared_context.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/support/shared_context/policies/project_policy_shared_context.rb b/spec/support/shared_context/policies/project_policy_shared_context.rb index 8bcd26ec0cd..3ad6e067674 100644 --- a/spec/support/shared_context/policies/project_policy_shared_context.rb +++ b/spec/support/shared_context/policies/project_policy_shared_context.rb @@ -15,7 +15,7 @@ RSpec.shared_context 'ProjectPolicy context' do read_project_for_iids read_issue_iid read_label read_milestone read_project_snippet read_project_member read_note create_project create_issue create_note upload_file create_merge_request_in - award_emoji read_release + award_emoji ] end @@ -24,7 +24,7 @@ RSpec.shared_context 'ProjectPolicy context' do download_code fork_project create_project_snippet update_issue admin_issue admin_label admin_list read_commit_status read_build read_container_image read_pipeline read_environment read_deployment - read_merge_request download_wiki_code read_sentry_issue + read_merge_request download_wiki_code read_sentry_issue read_release ] end -- cgit v1.2.1 From ac841c37cb667bee637b53d552ce1e71984d7e0a Mon Sep 17 00:00:00 2001 From: Patrick Bajao Date: Wed, 3 Apr 2019 15:06:50 +0800 Subject: Bring back Gitlab::UntrustedRegexp.with_fallback It's still being called in PushRule model. Also still present in 11-9-stable-ee branch. --- lib/gitlab/untrusted_regexp.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/gitlab/untrusted_regexp.rb b/lib/gitlab/untrusted_regexp.rb index 14126b6ec06..c237f4a7404 100644 --- a/lib/gitlab/untrusted_regexp.rb +++ b/lib/gitlab/untrusted_regexp.rb @@ -47,6 +47,19 @@ module Gitlab self.source == other.source end + # Handles regular expressions with the preferred RE2 library where possible + # via UntustedRegex. Falls back to Ruby's built-in regular expression library + # when the syntax would be invalid in RE2. + # + # One difference between these is `(?m)` multi-line mode. Ruby regex enables + # this by default, but also handles `^` and `$` differently. + # See: https://www.regular-expressions.info/modifiers.html + def self.with_fallback(pattern, multiline: false) + UntrustedRegexp.new(pattern, multiline: multiline) + rescue RegexpError + Regexp.new(pattern) + end + private attr_reader :regexp -- cgit v1.2.1 From 46fdec84dd787c5311cf45fcf1967a8907e62458 Mon Sep 17 00:00:00 2001 From: Ezekiel Kigbo Date: Wed, 3 Apr 2019 08:27:16 +0000 Subject: Extend timezone dropdown Adds optional paramters to the constructor to allow reuse of the timezone dropdown on other pages --- .../shared/components/timezone_dropdown.js | 51 ++++--- .../pipeline_schedules/shared/init_form.js | 8 +- .../unreleased/ekigbo-extend-timezone-dropdown.yml | 5 + .../shared/components/timezone_dropdown_spec.js | 167 +++++++++++++++++++++ 4 files changed, 205 insertions(+), 26 deletions(-) create mode 100644 changelogs/unreleased/ekigbo-extend-timezone-dropdown.yml create mode 100644 spec/javascripts/pages/projects/pipeline_schedules/shared/components/timezone_dropdown_spec.js diff --git a/app/assets/javascripts/pages/projects/pipeline_schedules/shared/components/timezone_dropdown.js b/app/assets/javascripts/pages/projects/pipeline_schedules/shared/components/timezone_dropdown.js index 95b57d5e048..c1f6edf2f27 100644 --- a/app/assets/javascripts/pages/projects/pipeline_schedules/shared/components/timezone_dropdown.js +++ b/app/assets/javascripts/pages/projects/pipeline_schedules/shared/components/timezone_dropdown.js @@ -1,17 +1,33 @@ -/* eslint-disable class-methods-use-this */ +const defaultTimezone = 'UTC'; + +export const formatUtcOffset = offset => { + const parsed = parseInt(offset, 10); + if (Number.isNaN(parsed) || parsed === 0) { + return `0`; + } + const prefix = offset > 0 ? '+' : '-'; + return `${prefix} ${Math.abs(offset / 3600)}`; +}; -import $ from 'jquery'; +export const formatTimezone = item => `[UTC ${formatUtcOffset(item.offset)}] ${item.name}`; -const defaultTimezone = 'UTC'; +const defaults = { + $inputEl: null, + $dropdownEl: null, + onSelectTimezone: null, +}; export default class TimezoneDropdown { - constructor() { - this.$dropdown = $('.js-timezone-dropdown'); + constructor({ $dropdownEl, $inputEl, onSelectTimezone } = defaults) { + this.$dropdown = $dropdownEl; this.$dropdownToggle = this.$dropdown.find('.dropdown-toggle-text'); - this.$input = $('#schedule_cron_timezone'); + this.$input = $inputEl; this.timezoneData = this.$dropdown.data('data'); + this.initDefaultTimezone(); this.initDropdown(); + + this.onSelectTimezone = onSelectTimezone; } initDropdown() { @@ -24,28 +40,12 @@ export default class TimezoneDropdown { fields: ['name'], }, clicked: cfg => this.updateInputValue(cfg), - text: item => this.formatTimezone(item), + text: item => formatTimezone(item), }); this.setDropdownToggle(); } - formatUtcOffset(offset) { - let prefix = ''; - - if (offset > 0) { - prefix = '+'; - } else if (offset < 0) { - prefix = '-'; - } - - return `${prefix} ${Math.abs(offset / 3600)}`; - } - - formatTimezone(item) { - return `[UTC ${this.formatUtcOffset(item.offset)}] ${item.name}`; - } - initDefaultTimezone() { const initialValue = this.$input.val(); @@ -56,13 +56,14 @@ export default class TimezoneDropdown { setDropdownToggle() { const initialValue = this.$input.val(); - this.$dropdownToggle.text(initialValue); } updateInputValue({ selectedObj, e }) { e.preventDefault(); this.$input.val(selectedObj.identifier); - gl.pipelineScheduleFieldErrors.updateFormValidityState(); + if (this.onSelectTimezone) { + this.onSelectTimezone({ selectedObj, e }); + } } } diff --git a/app/assets/javascripts/pages/projects/pipeline_schedules/shared/init_form.js b/app/assets/javascripts/pages/projects/pipeline_schedules/shared/init_form.js index 4d494efef6c..dc6df27f1c7 100644 --- a/app/assets/javascripts/pages/projects/pipeline_schedules/shared/init_form.js +++ b/app/assets/javascripts/pages/projects/pipeline_schedules/shared/init_form.js @@ -41,7 +41,13 @@ export default () => { const formElement = document.getElementById('new-pipeline-schedule-form'); - gl.timezoneDropdown = new TimezoneDropdown(); + gl.timezoneDropdown = new TimezoneDropdown({ + $dropdownEl: $('.js-timezone-dropdown'), + $inputEl: $('#schedule_cron_timezone'), + onSelectTimezone: () => { + gl.pipelineScheduleFieldErrors.updateFormValidityState(); + }, + }); gl.targetBranchDropdown = new TargetBranchDropdown(); gl.pipelineScheduleFieldErrors = new GlFieldErrors(formElement); diff --git a/changelogs/unreleased/ekigbo-extend-timezone-dropdown.yml b/changelogs/unreleased/ekigbo-extend-timezone-dropdown.yml new file mode 100644 index 00000000000..42bc320a542 --- /dev/null +++ b/changelogs/unreleased/ekigbo-extend-timezone-dropdown.yml @@ -0,0 +1,5 @@ +--- +title: Extend timezone dropdown +merge_request: 26311 +author: +type: changed diff --git a/spec/javascripts/pages/projects/pipeline_schedules/shared/components/timezone_dropdown_spec.js b/spec/javascripts/pages/projects/pipeline_schedules/shared/components/timezone_dropdown_spec.js new file mode 100644 index 00000000000..a89952ee435 --- /dev/null +++ b/spec/javascripts/pages/projects/pipeline_schedules/shared/components/timezone_dropdown_spec.js @@ -0,0 +1,167 @@ +import $ from 'jquery'; +import GLDropdown from '~/gl_dropdown'; // eslint-disable-line no-unused-vars +import TimezoneDropdown, { + formatUtcOffset, + formatTimezone, +} from '~/pages/projects/pipeline_schedules/shared/components/timezone_dropdown'; + +describe('Timezone Dropdown', function() { + preloadFixtures('pipeline_schedules/edit.html'); + + let $inputEl = null; + let $dropdownEl = null; + let $wrapper = null; + const tzListSel = '.dropdown-content ul li a.is-active'; + + describe('Initialize', () => { + describe('with dropdown already loaded', () => { + beforeEach(() => { + loadFixtures('pipeline_schedules/edit.html'); + $wrapper = $('.dropdown'); + $inputEl = $('#schedule_cron_timezone'); + $dropdownEl = $('.js-timezone-dropdown'); + + // eslint-disable-next-line no-new + new TimezoneDropdown({ + $inputEl, + $dropdownEl, + }); + }); + + it('can take an $inputEl in the constructor', () => { + const tzStr = '[UTC + 5.5] Sri Jayawardenepura'; + const tzValue = 'Asia/Colombo'; + + expect($inputEl.val()).toBe('UTC'); + + $(`${tzListSel}:contains('${tzStr}')`, $wrapper).trigger('click'); + + const val = $inputEl.val(); + + expect(val).toBe(tzValue); + expect(val).not.toBe('UTC'); + }); + + it('will format data array of timezones into a list of offsets', () => { + const data = $dropdownEl.data('data'); + const formatted = $wrapper.find(tzListSel).text(); + + data.forEach(item => { + expect(formatted).toContain(formatTimezone(item)); + }); + }); + + it('will default the timezone to UTC', () => { + const tz = $inputEl.val(); + + expect(tz).toBe('UTC'); + }); + }); + + describe('without dropdown loaded', () => { + beforeEach(() => { + loadFixtures('pipeline_schedules/edit.html'); + $wrapper = $('.dropdown'); + $inputEl = $('#schedule_cron_timezone'); + $dropdownEl = $('.js-timezone-dropdown'); + }); + + it('will populate the list of UTC offsets after the dropdown is loaded', () => { + expect($wrapper.find(tzListSel).length).toEqual(0); + + // eslint-disable-next-line no-new + new TimezoneDropdown({ + $inputEl, + $dropdownEl, + }); + + expect($wrapper.find(tzListSel).length).toEqual($($dropdownEl).data('data').length); + }); + + it('will call a provided handler when a new timezone is selected', () => { + const onSelectTimezone = jasmine.createSpy('onSelectTimezoneMock'); + // eslint-disable-next-line no-new + new TimezoneDropdown({ + $inputEl, + $dropdownEl, + onSelectTimezone, + }); + + $wrapper + .find(tzListSel) + .first() + .trigger('click'); + + expect(onSelectTimezone).toHaveBeenCalled(); + }); + }); + }); + + describe('formatUtcOffset', () => { + it('will convert negative utc offsets in seconds to hours and minutes', () => { + expect(formatUtcOffset(-21600)).toEqual('- 6'); + }); + + it('will convert positive utc offsets in seconds to hours and minutes', () => { + expect(formatUtcOffset(25200)).toEqual('+ 7'); + expect(formatUtcOffset(49500)).toEqual('+ 13.75'); + }); + + it('will return 0 when given a string', () => { + expect(formatUtcOffset('BLAH')).toEqual('0'); + expect(formatUtcOffset('$%$%')).toEqual('0'); + }); + + it('will return 0 when given an array', () => { + expect(formatUtcOffset(['an', 'array'])).toEqual('0'); + }); + + it('will return 0 when given an object', () => { + expect(formatUtcOffset({ some: '', object: '' })).toEqual('0'); + }); + + it('will return 0 when given null', () => { + expect(formatUtcOffset(null)).toEqual('0'); + }); + + it('will return 0 when given undefined', () => { + expect(formatUtcOffset(undefined)).toEqual('0'); + }); + + it('will return 0 when given empty input', () => { + expect(formatUtcOffset('')).toEqual('0'); + }); + }); + + describe('formatTimezone', () => { + it('given name: "Chatham Is.", offset: "49500", will format for display as "[UTC + 13.75] Chatham Is."', () => { + expect( + formatTimezone({ + name: 'Chatham Is.', + offset: 49500, + identifier: 'Pacific/Chatham', + }), + ).toEqual('[UTC + 13.75] Chatham Is.'); + }); + + it('given name: "Saskatchewan", offset: "-21600", will format for display as "[UTC - 6] Saskatchewan"', () => { + expect( + formatTimezone({ + name: 'Saskatchewan', + offset: -21600, + identifier: 'America/Regina', + }), + ).toEqual('[UTC - 6] Saskatchewan'); + }); + + it('given name: "Accra", offset: "0", will format for display as "[UTC 0] Accra"', () => { + expect( + formatTimezone({ + name: 'Accra', + offset: 0, + identifier: 'Africa/Accra', + }), + ).toEqual('[UTC 0] Accra'); + }); + }); +}); -- cgit v1.2.1 From ecae2c48920d76623be0019e19cea919d3e4cb28 Mon Sep 17 00:00:00 2001 From: Alexander Strachan Date: Wed, 3 Apr 2019 09:01:44 +0000 Subject: Resolve "Add troubleshooting section to capture errors with installing applications to a Kubernetes cluster" --- doc/user/project/clusters/index.md | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/doc/user/project/clusters/index.md b/doc/user/project/clusters/index.md index 3a9a3b4a423..c94a3f4d3b5 100644 --- a/doc/user/project/clusters/index.md +++ b/doc/user/project/clusters/index.md @@ -314,12 +314,6 @@ install it manually. ## Installing applications -NOTE: **Note:** -Before starting the installation of applications, make sure that time is synchronized -between your GitLab server and your Kubernetes cluster. Otherwise, installation could fail -and you may get errors like `Error: remote error: tls: bad certificate` -in the `stdout` of pods created by GitLab in your Kubernetes cluster. - GitLab provides a one-click install for various applications which can be added directly to your configured cluster. Those applications are needed for [Review Apps](../../../ci/review_apps/index.md) and @@ -378,6 +372,29 @@ Upgrades will reset values back to the values built into the `runner` chart plus the values set by [`values.yaml`](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/vendor/runner/values.yaml) +### Troubleshooting applications + +Applications can fail with the following error: + +```text +Error: remote error: tls: bad certificate +``` + +To avoid installation errors: + +- Before starting the installation of applications, make sure that time is synchronized + between your GitLab server and your Kubernetes cluster. +- Ensure certificates are not out of sync. When installing applications, GitLab expects a new cluster with no previous installation of Tiller. + + You can confirm that the certificates match via `kubectl`: + + ```sh + kubectl get configmaps/values-content-configuration-ingress -n gitlab-managed-apps -o \ + "jsonpath={.data['cert\.pem']}" | base64 -d > a.pem + kubectl get secrets/tiller-secret -n gitlab-managed-apps -o "jsonpath={.data['ca\.crt']}" | base64 -d > b.pem + diff a.pem b.pem + ``` + ## Getting the external endpoint NOTE: **Note:** -- cgit v1.2.1 From 6ee1d8cf7778ecef0997c10f22b18ab4b61e9b3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20Javier=20L=C3=B3pez?= Date: Wed, 3 Apr 2019 09:50:54 +0000 Subject: Add port section to CI Image object In order to implement https://gitlab.com/gitlab-org/gitlab-ee/issues/10179 we need several modifications on the CI config file. We are adding a new ports section in the default Image object. Each of these ports will accept: number, protocol and name. By default this new configuration will be only enabled in the Web IDE config file. --- lib/api/entities.rb | 5 + lib/gitlab/ci/build/image.rb | 10 +- lib/gitlab/ci/build/port.rb | 32 +++++ lib/gitlab/ci/config/entry/image.rb | 22 ++- lib/gitlab/ci/config/entry/port.rb | 46 ++++++ lib/gitlab/ci/config/entry/ports.rb | 46 ++++++ lib/gitlab/ci/config/entry/service.rb | 4 +- lib/gitlab/ci/config/entry/services.rb | 2 + lib/gitlab/config/entry/configurable.rb | 10 +- lib/gitlab/config/entry/factory.rb | 2 +- lib/gitlab/config/entry/node.rb | 20 +++ lib/gitlab/config/entry/simplifiable.rb | 5 +- lib/gitlab/config/entry/validators.rb | 102 +++++++++++++ spec/lib/api/entities/job_request/image_spec.rb | 31 ++++ spec/lib/api/entities/job_request/port_spec.rb | 22 +++ spec/lib/gitlab/ci/build/image_spec.rb | 25 +++- spec/lib/gitlab/ci/build/port_spec.rb | 27 ++++ spec/lib/gitlab/ci/config/entry/image_spec.rb | 46 +++++- spec/lib/gitlab/ci/config/entry/port_spec.rb | 173 +++++++++++++++++++++++ spec/lib/gitlab/ci/config/entry/ports_spec.rb | 70 +++++++++ spec/lib/gitlab/ci/config/entry/service_spec.rb | 70 ++++++++- spec/lib/gitlab/ci/config/entry/services_spec.rb | 87 ++++++++++++ spec/lib/gitlab/ci/config_spec.rb | 57 ++++++++ spec/lib/gitlab/ci/yaml_processor_spec.rb | 4 +- spec/requests/api/runner_spec.rb | 56 +++++++- spec/services/ci/create_pipeline_service_spec.rb | 50 +++++++ 26 files changed, 997 insertions(+), 27 deletions(-) create mode 100644 lib/gitlab/ci/build/port.rb create mode 100644 lib/gitlab/ci/config/entry/port.rb create mode 100644 lib/gitlab/ci/config/entry/ports.rb create mode 100644 spec/lib/api/entities/job_request/image_spec.rb create mode 100644 spec/lib/api/entities/job_request/port_spec.rb create mode 100644 spec/lib/gitlab/ci/build/port_spec.rb create mode 100644 spec/lib/gitlab/ci/config/entry/port_spec.rb create mode 100644 spec/lib/gitlab/ci/config/entry/ports_spec.rb diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 4533305bfd3..cc62b5a3661 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -1389,8 +1389,13 @@ module API expose :name, :script, :timeout, :when, :allow_failure end + class Port < Grape::Entity + expose :number, :protocol, :name + end + class Image < Grape::Entity expose :name, :entrypoint + expose :ports, using: JobRequest::Port end class Service < Image diff --git a/lib/gitlab/ci/build/image.rb b/lib/gitlab/ci/build/image.rb index 4dd932f61d4..1d7bfba75cd 100644 --- a/lib/gitlab/ci/build/image.rb +++ b/lib/gitlab/ci/build/image.rb @@ -4,7 +4,7 @@ module Gitlab module Ci module Build class Image - attr_reader :alias, :command, :entrypoint, :name + attr_reader :alias, :command, :entrypoint, :name, :ports class << self def from_image(job) @@ -26,17 +26,25 @@ module Gitlab def initialize(image) if image.is_a?(String) @name = image + @ports = [] elsif image.is_a?(Hash) @alias = image[:alias] @command = image[:command] @entrypoint = image[:entrypoint] @name = image[:name] + @ports = build_ports(image).select(&:valid?) end end def valid? @name.present? end + + private + + def build_ports(image) + image[:ports].to_a.map { |port| ::Gitlab::Ci::Build::Port.new(port) } + end end end end diff --git a/lib/gitlab/ci/build/port.rb b/lib/gitlab/ci/build/port.rb new file mode 100644 index 00000000000..6c4656ffea2 --- /dev/null +++ b/lib/gitlab/ci/build/port.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +module Gitlab + module Ci + module Build + class Port + DEFAULT_PORT_NAME = 'default_port'.freeze + DEFAULT_PORT_PROTOCOL = 'http'.freeze + + attr_reader :number, :protocol, :name + + def initialize(port) + @name = DEFAULT_PORT_NAME + @protocol = DEFAULT_PORT_PROTOCOL + + case port + when Integer + @number = port + when Hash + @number = port[:number] + @protocol = port.fetch(:protocol, @protocol) + @name = port.fetch(:name, @name) + end + end + + def valid? + @number.present? + end + end + end + end +end diff --git a/lib/gitlab/ci/config/entry/image.rb b/lib/gitlab/ci/config/entry/image.rb index a13a0625e90..0beeb44c272 100644 --- a/lib/gitlab/ci/config/entry/image.rb +++ b/lib/gitlab/ci/config/entry/image.rb @@ -9,24 +9,24 @@ module Gitlab # class Image < ::Gitlab::Config::Entry::Node include ::Gitlab::Config::Entry::Validatable + include ::Gitlab::Config::Entry::Attributable + include ::Gitlab::Config::Entry::Configurable - ALLOWED_KEYS = %i[name entrypoint].freeze + ALLOWED_KEYS = %i[name entrypoint ports].freeze validations do validates :config, hash_or_string: true validates :config, allowed_keys: ALLOWED_KEYS + validates :config, disallowed_keys: %i[ports], unless: :with_image_ports? validates :name, type: String, presence: true validates :entrypoint, array_of_strings: true, allow_nil: true end - def hash? - @config.is_a?(Hash) - end + entry :ports, Entry::Ports, + description: 'Ports used expose the image' - def string? - @config.is_a?(String) - end + attributes :ports def name value[:name] @@ -42,6 +42,14 @@ module Gitlab {} end + + def with_image_ports? + opt(:with_image_ports) + end + + def skip_config_hash_validation? + true + end end end end diff --git a/lib/gitlab/ci/config/entry/port.rb b/lib/gitlab/ci/config/entry/port.rb new file mode 100644 index 00000000000..c239b1225c5 --- /dev/null +++ b/lib/gitlab/ci/config/entry/port.rb @@ -0,0 +1,46 @@ +# frozen_string_literal: true + +module Gitlab + module Ci + class Config + module Entry + ## + # Entry that represents a configuration of an Image Port. + # + class Port < ::Gitlab::Config::Entry::Node + include ::Gitlab::Config::Entry::Validatable + + ALLOWED_KEYS = %i[number protocol name].freeze + + validations do + validates :config, hash_or_integer: true + validates :config, allowed_keys: ALLOWED_KEYS + + validates :number, type: Integer, presence: true + validates :protocol, type: String, inclusion: { in: %w[http https], message: 'should be http or https' }, allow_blank: true + validates :name, type: String, presence: false, allow_nil: true + end + + def number + value[:number] + end + + def protocol + value[:protocol] + end + + def name + value[:name] + end + + def value + return { number: @config } if integer? + return @config if hash? + + {} + end + end + end + end + end +end diff --git a/lib/gitlab/ci/config/entry/ports.rb b/lib/gitlab/ci/config/entry/ports.rb new file mode 100644 index 00000000000..01ffcc7dd87 --- /dev/null +++ b/lib/gitlab/ci/config/entry/ports.rb @@ -0,0 +1,46 @@ +# frozen_string_literal: true + +module Gitlab + module Ci + class Config + module Entry + ## + # Entry that represents a configuration of the ports of a Docker service. + # + class Ports < ::Gitlab::Config::Entry::Node + include ::Gitlab::Config::Entry::Validatable + + validations do + validates :config, type: Array + validates :config, port_name_present_and_unique: true + validates :config, port_unique: true + end + + def compose!(deps = nil) + super do + @entries = [] + @config.each do |config| + @entries << ::Gitlab::Config::Entry::Factory.new(Entry::Port) + .value(config || {}) + .with(key: "port", parent: self, description: "port definition.") # rubocop:disable CodeReuse/ActiveRecord + .create! + end + + @entries.each do |entry| + entry.compose!(deps) + end + end + end + + def value + @entries.map(&:value) + end + + def descendants + @entries + end + end + end + end + end +end diff --git a/lib/gitlab/ci/config/entry/service.rb b/lib/gitlab/ci/config/entry/service.rb index 6df67083310..084fa4047a4 100644 --- a/lib/gitlab/ci/config/entry/service.rb +++ b/lib/gitlab/ci/config/entry/service.rb @@ -10,16 +10,18 @@ module Gitlab class Service < Image include ::Gitlab::Config::Entry::Validatable - ALLOWED_KEYS = %i[name entrypoint command alias].freeze + ALLOWED_KEYS = %i[name entrypoint command alias ports].freeze validations do validates :config, hash_or_string: true validates :config, allowed_keys: ALLOWED_KEYS + validates :config, disallowed_keys: %i[ports], unless: :with_image_ports? validates :name, type: String, presence: true validates :entrypoint, array_of_strings: true, allow_nil: true validates :command, array_of_strings: true, allow_nil: true validates :alias, type: String, allow_nil: true + validates :alias, type: String, presence: true, unless: ->(record) { record.ports.blank? } end def alias diff --git a/lib/gitlab/ci/config/entry/services.rb b/lib/gitlab/ci/config/entry/services.rb index 71475f69218..83baa83711f 100644 --- a/lib/gitlab/ci/config/entry/services.rb +++ b/lib/gitlab/ci/config/entry/services.rb @@ -12,6 +12,7 @@ module Gitlab validations do validates :config, type: Array + validates :config, services_with_ports_alias_unique: true, if: ->(record) { record.opt(:with_image_ports) } end def compose!(deps = nil) @@ -20,6 +21,7 @@ module Gitlab @config.each do |config| @entries << ::Gitlab::Config::Entry::Factory.new(Entry::Service) .value(config || {}) + .with(key: "service", parent: self, description: "service definition.") # rubocop:disable CodeReuse/ActiveRecord .create! end diff --git a/lib/gitlab/config/entry/configurable.rb b/lib/gitlab/config/entry/configurable.rb index 37ba16dba25..6667a5d3d33 100644 --- a/lib/gitlab/config/entry/configurable.rb +++ b/lib/gitlab/config/entry/configurable.rb @@ -21,7 +21,7 @@ module Gitlab include Validatable validations do - validates :config, type: Hash + validates :config, type: Hash, unless: :skip_config_hash_validation? end end @@ -30,6 +30,10 @@ module Gitlab return unless valid? self.class.nodes.each do |key, factory| + # If we override the config type validation + # we can end with different config types like String + next unless config.is_a?(Hash) + factory .value(config[key]) .with(key: key, parent: self) @@ -45,6 +49,10 @@ module Gitlab end # rubocop: enable CodeReuse/ActiveRecord + def skip_config_hash_validation? + false + end + class_methods do def nodes Hash[(@nodes || {}).map { |key, factory| [key, factory.dup] }] diff --git a/lib/gitlab/config/entry/factory.rb b/lib/gitlab/config/entry/factory.rb index 79f9ff32514..3c06b1e0d24 100644 --- a/lib/gitlab/config/entry/factory.rb +++ b/lib/gitlab/config/entry/factory.rb @@ -61,7 +61,7 @@ module Gitlab end def fabricate(entry, value = nil) - entry.new(value, @metadata).tap do |node| + entry.new(value, @metadata) do |node| node.key = @attributes[:key] node.parent = @attributes[:parent] node.default = @attributes[:default] diff --git a/lib/gitlab/config/entry/node.rb b/lib/gitlab/config/entry/node.rb index 9999ab4ff95..e014f15fbd8 100644 --- a/lib/gitlab/config/entry/node.rb +++ b/lib/gitlab/config/entry/node.rb @@ -17,6 +17,8 @@ module Gitlab @metadata = metadata @entries = {} + yield(self) if block_given? + self.class.aspects.to_a.each do |aspect| instance_exec(&aspect) end @@ -44,6 +46,12 @@ module Gitlab @parent ? @parent.ancestors + [@parent] : [] end + def opt(key) + opt = metadata[key] + opt = @parent.opt(key) if opt.nil? && @parent + opt + end + def valid? errors.none? end @@ -85,6 +93,18 @@ module Gitlab "#<#{self.class.name} #{unspecified}{#{key}: #{val.inspect}}>" end + def hash? + @config.is_a?(Hash) + end + + def string? + @config.is_a?(String) + end + + def integer? + @config.is_a?(Integer) + end + def self.default(**) end diff --git a/lib/gitlab/config/entry/simplifiable.rb b/lib/gitlab/config/entry/simplifiable.rb index 5fbf7565e2a..a56a89adb35 100644 --- a/lib/gitlab/config/entry/simplifiable.rb +++ b/lib/gitlab/config/entry/simplifiable.rb @@ -19,7 +19,10 @@ module Gitlab entry = self.class.entry_class(strategy) - super(@subject = entry.new(config, metadata)) + @subject = entry.new(config, metadata) + + yield(@subject) if block_given? + super(@subject) end def self.strategy(name, **opts) diff --git a/lib/gitlab/config/entry/validators.rb b/lib/gitlab/config/entry/validators.rb index d348e11b753..d0ee94370ba 100644 --- a/lib/gitlab/config/entry/validators.rb +++ b/lib/gitlab/config/entry/validators.rb @@ -15,6 +15,17 @@ module Gitlab end end + class DisallowedKeysValidator < ActiveModel::EachValidator + def validate_each(record, attribute, value) + present_keys = value.try(:keys).to_a & options[:in] + + if present_keys.any? + record.errors.add(attribute, "contains disallowed keys: " + + present_keys.join(', ')) + end + end + end + class AllowedValuesValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) unless options[:in].include?(value.to_s) @@ -186,6 +197,97 @@ module Gitlab end end end + + class PortNamePresentAndUniqueValidator < ActiveModel::EachValidator + def validate_each(record, attribute, value) + return unless value.is_a?(Array) + + ports_size = value.count + return if ports_size <= 1 + + named_ports = value.select { |e| e.is_a?(Hash) }.map { |e| e[:name] }.compact.map(&:downcase) + + if ports_size != named_ports.size + record.errors.add(attribute, 'when there is more than one port, a unique name should be added') + end + + if ports_size != named_ports.uniq.size + record.errors.add(attribute, 'each port name must be different') + end + end + end + + class PortUniqueValidator < ActiveModel::EachValidator + def validate_each(record, attribute, value) + value = ports(value) + return unless value.is_a?(Array) + + ports_size = value.count + return if ports_size <= 1 + + if transform_ports(value).size != ports_size + record.errors.add(attribute, 'each port number can only be referenced once') + end + end + + private + + def ports(current_data) + current_data + end + + def transform_ports(raw_ports) + raw_ports.map do |port| + case port + when Integer + port + when Hash + port[:number] + end + end.uniq + end + end + + class JobPortUniqueValidator < PortUniqueValidator + private + + def ports(current_data) + return unless current_data.is_a?(Hash) + + (image_ports(current_data) + services_ports(current_data)).compact + end + + def image_ports(current_data) + return [] unless current_data[:image].is_a?(Hash) + + current_data.dig(:image, :ports).to_a + end + + def services_ports(current_data) + current_data.dig(:services).to_a.flat_map { |service| service.is_a?(Hash) ? service[:ports] : nil } + end + end + + class ServicesWithPortsAliasUniqueValidator < ActiveModel::EachValidator + def validate_each(record, attribute, value) + current_aliases = aliases(value) + return if current_aliases.empty? + + unless aliases_unique?(current_aliases) + record.errors.add(:config, 'alias must be unique in services with ports') + end + end + + private + + def aliases(value) + value.select { |s| s.is_a?(Hash) && s[:ports] }.pluck(:alias) # rubocop:disable CodeReuse/ActiveRecord + end + + def aliases_unique?(aliases) + aliases.size == aliases.uniq.size + end + end end end end diff --git a/spec/lib/api/entities/job_request/image_spec.rb b/spec/lib/api/entities/job_request/image_spec.rb new file mode 100644 index 00000000000..092c181ae9c --- /dev/null +++ b/spec/lib/api/entities/job_request/image_spec.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe API::Entities::JobRequest::Image do + let(:ports) { [{ number: 80, protocol: 'http', name: 'name' }]} + let(:image) { double(name: 'image_name', entrypoint: ['foo'], ports: ports)} + let(:entity) { described_class.new(image) } + + subject { entity.as_json } + + it 'returns the image name' do + expect(subject[:name]).to eq 'image_name' + end + + it 'returns the entrypoint' do + expect(subject[:entrypoint]).to eq ['foo'] + end + + it 'returns the ports' do + expect(subject[:ports]).to eq ports + end + + context 'when the ports param is nil' do + let(:ports) { nil } + + it 'does not return the ports' do + expect(subject[:ports]).to be_nil + end + end +end diff --git a/spec/lib/api/entities/job_request/port_spec.rb b/spec/lib/api/entities/job_request/port_spec.rb new file mode 100644 index 00000000000..40ab4cd6231 --- /dev/null +++ b/spec/lib/api/entities/job_request/port_spec.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe ::API::Entities::JobRequest::Port do + let(:port) { double(number: 80, protocol: 'http', name: 'name')} + let(:entity) { described_class.new(port) } + + subject { entity.as_json } + + it 'returns the port number' do + expect(subject[:number]).to eq 80 + end + + it 'returns if the port protocol' do + expect(subject[:protocol]).to eq 'http' + end + + it 'returns the port name' do + expect(subject[:name]).to eq 'name' + end +end diff --git a/spec/lib/gitlab/ci/build/image_spec.rb b/spec/lib/gitlab/ci/build/image_spec.rb index 773a52cdfbc..6e20e0ef5c3 100644 --- a/spec/lib/gitlab/ci/build/image_spec.rb +++ b/spec/lib/gitlab/ci/build/image_spec.rb @@ -18,11 +18,16 @@ describe Gitlab::Ci::Build::Image do it 'populates fabricated object with the proper name attribute' do expect(subject.name).to eq(image_name) end + + it 'does not populate the ports' do + expect(subject.ports).to be_empty + end end context 'when image is defined as hash' do let(:entrypoint) { '/bin/sh' } - let(:job) { create(:ci_build, options: { image: { name: image_name, entrypoint: entrypoint } } ) } + + let(:job) { create(:ci_build, options: { image: { name: image_name, entrypoint: entrypoint, ports: [80] } } ) } it 'fabricates an object of the proper class' do is_expected.to be_kind_of(described_class) @@ -32,6 +37,13 @@ describe Gitlab::Ci::Build::Image do expect(subject.name).to eq(image_name) expect(subject.entrypoint).to eq(entrypoint) end + + it 'populates the ports' do + port = subject.ports.first + expect(port.number).to eq 80 + expect(port.protocol).to eq 'http' + expect(port.name).to eq 'default_port' + end end context 'when image name is empty' do @@ -67,6 +79,10 @@ describe Gitlab::Ci::Build::Image do expect(subject.first).to be_kind_of(described_class) expect(subject.first.name).to eq(service_image_name) end + + it 'does not populate the ports' do + expect(subject.first.ports).to be_empty + end end context 'when service is defined as hash' do @@ -75,7 +91,7 @@ describe Gitlab::Ci::Build::Image do let(:service_command) { 'sleep 30' } let(:job) do create(:ci_build, options: { services: [{ name: service_image_name, entrypoint: service_entrypoint, - alias: service_alias, command: service_command }] }) + alias: service_alias, command: service_command, ports: [80] }] }) end it 'fabricates an non-empty array of objects' do @@ -89,6 +105,11 @@ describe Gitlab::Ci::Build::Image do expect(subject.first.entrypoint).to eq(service_entrypoint) expect(subject.first.alias).to eq(service_alias) expect(subject.first.command).to eq(service_command) + + port = subject.first.ports.first + expect(port.number).to eq 80 + expect(port.protocol).to eq 'http' + expect(port.name).to eq 'default_port' end end diff --git a/spec/lib/gitlab/ci/build/port_spec.rb b/spec/lib/gitlab/ci/build/port_spec.rb new file mode 100644 index 00000000000..1413780dfa6 --- /dev/null +++ b/spec/lib/gitlab/ci/build/port_spec.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::Ci::Build::Port do + subject { described_class.new(port) } + + context 'when port is defined as an integer' do + let(:port) { 80 } + + it 'populates the object' do + expect(subject.number).to eq 80 + expect(subject.protocol).to eq described_class::DEFAULT_PORT_PROTOCOL + expect(subject.name).to eq described_class::DEFAULT_PORT_NAME + end + end + + context 'when port is defined as hash' do + let(:port) { { number: 80, protocol: 'https', name: 'port_name' } } + + it 'populates the object' do + expect(subject.number).to eq 80 + expect(subject.protocol).to eq 'https' + expect(subject.name).to eq 'port_name' + end + end +end diff --git a/spec/lib/gitlab/ci/config/entry/image_spec.rb b/spec/lib/gitlab/ci/config/entry/image_spec.rb index 1a4d9ed5517..1ebdda398b9 100644 --- a/spec/lib/gitlab/ci/config/entry/image_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/image_spec.rb @@ -35,6 +35,12 @@ describe Gitlab::Ci::Config::Entry::Image do expect(entry.entrypoint).to be_nil end end + + describe '#ports' do + it "returns image's ports" do + expect(entry.ports).to be_nil + end + end end context 'when configuration is a hash' do @@ -69,6 +75,38 @@ describe Gitlab::Ci::Config::Entry::Image do expect(entry.entrypoint).to eq %w(/bin/sh run) end end + + context 'when configuration has ports' do + let(:ports) { [{ number: 80, protocol: 'http', name: 'foobar' }] } + let(:config) { { name: 'ruby:2.2', entrypoint: %w(/bin/sh run), ports: ports } } + let(:entry) { described_class.new(config, { with_image_ports: image_ports }) } + let(:image_ports) { false } + + context 'when with_image_ports metadata is not enabled' do + describe '#valid?' do + it 'is not valid' do + expect(entry).not_to be_valid + expect(entry.errors).to include("image config contains disallowed keys: ports") + end + end + end + + context 'when with_image_ports metadata is enabled' do + let(:image_ports) { true } + + describe '#valid?' do + it 'is valid' do + expect(entry).to be_valid + end + end + + describe '#ports' do + it "returns image's ports" do + expect(entry.ports).to eq ports + end + end + end + end end context 'when entry value is not correct' do @@ -76,8 +114,8 @@ describe Gitlab::Ci::Config::Entry::Image do describe '#errors' do it 'saves errors' do - expect(entry.errors) - .to include 'image config should be a hash or a string' + expect(entry.errors.first) + .to match /config should be a hash or a string/ end end @@ -93,8 +131,8 @@ describe Gitlab::Ci::Config::Entry::Image do describe '#errors' do it 'saves errors' do - expect(entry.errors) - .to include 'image config contains unknown keys: non_existing' + expect(entry.errors.first) + .to match /config contains unknown keys: non_existing/ end end diff --git a/spec/lib/gitlab/ci/config/entry/port_spec.rb b/spec/lib/gitlab/ci/config/entry/port_spec.rb new file mode 100644 index 00000000000..5f8f294334e --- /dev/null +++ b/spec/lib/gitlab/ci/config/entry/port_spec.rb @@ -0,0 +1,173 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::Ci::Config::Entry::Port do + let(:entry) { described_class.new(config) } + + before do + entry.compose! + end + + context 'when configuration is a string' do + let(:config) { 80 } + + describe '#valid?' do + it 'is valid' do + expect(entry).to be_valid + end + end + + describe '#value' do + it 'returns valid hash' do + expect(entry.value).to eq(number: 80) + end + end + + describe '#number' do + it "returns port number" do + expect(entry.number).to eq 80 + end + end + + describe '#protocol' do + it "is nil" do + expect(entry.protocol).to be_nil + end + end + + describe '#name' do + it "is nil" do + expect(entry.name).to be_nil + end + end + end + + context 'when configuration is a hash' do + context 'with the complete hash' do + let(:config) do + { number: 80, + protocol: 'http', + name: 'foobar' } + end + + describe '#valid?' do + it 'is valid' do + expect(entry).to be_valid + end + end + + describe '#value' do + it 'returns valid hash' do + expect(entry.value).to eq config + end + end + + describe '#number' do + it "returns port number" do + expect(entry.number).to eq 80 + end + end + + describe '#protocol' do + it "returns port protocol" do + expect(entry.protocol).to eq 'http' + end + end + + describe '#name' do + it "returns port name" do + expect(entry.name).to eq 'foobar' + end + end + end + + context 'with only the port number' do + let(:config) { { number: 80 } } + + describe '#valid?' do + it 'is valid' do + expect(entry).to be_valid + end + end + + describe '#value' do + it 'returns valid hash' do + expect(entry.value).to eq(number: 80) + end + end + + describe '#number' do + it "returns port number" do + expect(entry.number).to eq 80 + end + end + + describe '#protocol' do + it "is nil" do + expect(entry.protocol).to be_nil + end + end + + describe '#name' do + it "is nil" do + expect(entry.name).to be_nil + end + end + end + + context 'without the number' do + let(:config) { { protocol: 'http' } } + + describe '#valid?' do + it 'is not valid' do + expect(entry).not_to be_valid + end + end + end + end + + context 'when configuration is invalid' do + let(:config) { '80' } + + describe '#valid?' do + it 'is valid' do + expect(entry).not_to be_valid + end + end + end + + context 'when protocol' do + let(:config) { { number: 80, protocol: protocol, name: 'foobar' } } + + context 'is http' do + let(:protocol) { 'http' } + + describe '#valid?' do + it 'is valid' do + expect(entry).to be_valid + end + end + end + + context 'is https' do + let(:protocol) { 'https' } + + describe '#valid?' do + it 'is valid' do + expect(entry).to be_valid + end + end + end + + context 'is neither http nor https' do + let(:protocol) { 'foo' } + + describe '#valid?' do + it 'is invalid' do + expect(entry.errors).to include("port protocol should be http or https") + end + end + end + end +end diff --git a/spec/lib/gitlab/ci/config/entry/ports_spec.rb b/spec/lib/gitlab/ci/config/entry/ports_spec.rb new file mode 100644 index 00000000000..2063bd1d86c --- /dev/null +++ b/spec/lib/gitlab/ci/config/entry/ports_spec.rb @@ -0,0 +1,70 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::Ci::Config::Entry::Ports do + let(:entry) { described_class.new(config) } + + before do + entry.compose! + end + + context 'when configuration is valid' do + let(:config) { [{ number: 80, protocol: 'http', name: 'foobar' }] } + + describe '#valid?' do + it 'is valid' do + expect(entry).to be_valid + end + end + + describe '#value' do + it 'returns valid array' do + expect(entry.value).to eq(config) + end + end + end + + context 'when configuration is invalid' do + let(:config) { 'postgresql:9.5' } + + describe '#valid?' do + it 'is invalid' do + expect(entry).not_to be_valid + end + end + + context 'when any of the ports' do + before do + expect(entry).not_to be_valid + expect(entry.errors.count).to eq 1 + end + + context 'have the same name' do + let(:config) do + [{ number: 80, protocol: 'http', name: 'foobar' }, + { number: 81, protocol: 'http', name: 'foobar' }] + end + + describe '#valid?' do + it 'is invalid' do + expect(entry.errors.first).to match /each port name must be different/ + end + end + end + + context 'have the same port' do + let(:config) do + [{ number: 80, protocol: 'http', name: 'foobar' }, + { number: 80, protocol: 'http', name: 'foobar1' }] + end + + describe '#valid?' do + it 'is invalid' do + expect(entry.errors.first).to match /each port number can only be referenced once/ + end + end + end + end + end +end diff --git a/spec/lib/gitlab/ci/config/entry/service_spec.rb b/spec/lib/gitlab/ci/config/entry/service_spec.rb index 9ebf947a751..d5bd139b5f1 100644 --- a/spec/lib/gitlab/ci/config/entry/service_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/service_spec.rb @@ -39,6 +39,12 @@ describe Gitlab::Ci::Config::Entry::Service do expect(entry.command).to be_nil end end + + describe '#ports' do + it "returns service's ports" do + expect(entry.ports).to be_nil + end + end end context 'when configuration is a hash' do @@ -81,6 +87,40 @@ describe Gitlab::Ci::Config::Entry::Service do expect(entry.entrypoint).to eq %w(/bin/sh run) end end + + context 'when configuration has ports' do + let(:ports) { [{ number: 80, protocol: 'http', name: 'foobar' }] } + let(:config) do + { name: 'postgresql:9.5', alias: 'db', command: %w(cmd run), entrypoint: %w(/bin/sh run), ports: ports } + end + let(:entry) { described_class.new(config, { with_image_ports: image_ports }) } + let(:image_ports) { false } + + context 'when with_image_ports metadata is not enabled' do + describe '#valid?' do + it 'is not valid' do + expect(entry).not_to be_valid + expect(entry.errors).to include("service config contains disallowed keys: ports") + end + end + end + + context 'when with_image_ports metadata is enabled' do + let(:image_ports) { true } + + describe '#valid?' do + it 'is valid' do + expect(entry).to be_valid + end + end + + describe '#ports' do + it "returns image's ports" do + expect(entry.ports).to eq ports + end + end + end + end end context 'when entry value is not correct' do @@ -88,8 +128,8 @@ describe Gitlab::Ci::Config::Entry::Service do describe '#errors' do it 'saves errors' do - expect(entry.errors) - .to include 'service config should be a hash or a string' + expect(entry.errors.first) + .to match /config should be a hash or a string/ end end @@ -105,8 +145,8 @@ describe Gitlab::Ci::Config::Entry::Service do describe '#errors' do it 'saves errors' do - expect(entry.errors) - .to include 'service config contains unknown keys: non_existing' + expect(entry.errors.first) + .to match /config contains unknown keys: non_existing/ end end @@ -116,4 +156,26 @@ describe Gitlab::Ci::Config::Entry::Service do end end end + + context 'when service has ports' do + let(:ports) { [{ number: 80, protocol: 'http', name: 'foobar' }] } + let(:config) do + { name: 'postgresql:9.5', command: %w(cmd run), entrypoint: %w(/bin/sh run), ports: ports } + end + + it 'alias field is mandatory' do + expect(entry).not_to be_valid + expect(entry.errors).to include("service alias can't be blank") + end + end + + context 'when service does not have ports' do + let(:config) do + { name: 'postgresql:9.5', alias: 'db', command: %w(cmd run), entrypoint: %w(/bin/sh run) } + end + + it 'alias field is optional' do + expect(entry).to be_valid + end + end end diff --git a/spec/lib/gitlab/ci/config/entry/services_spec.rb b/spec/lib/gitlab/ci/config/entry/services_spec.rb index 7c4319aee63..d5a1316f665 100644 --- a/spec/lib/gitlab/ci/config/entry/services_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/services_spec.rb @@ -32,4 +32,91 @@ describe Gitlab::Ci::Config::Entry::Services do end end end + + context 'when configuration has ports' do + let(:ports) { [{ number: 80, protocol: 'http', name: 'foobar' }] } + let(:config) { ['postgresql:9.5', { name: 'postgresql:9.1', alias: 'postgres_old', ports: ports }] } + let(:entry) { described_class.new(config, { with_image_ports: image_ports }) } + let(:image_ports) { false } + + context 'when with_image_ports metadata is not enabled' do + describe '#valid?' do + it 'is not valid' do + expect(entry).not_to be_valid + expect(entry.errors).to include("service config contains disallowed keys: ports") + end + end + end + + context 'when with_image_ports metadata is enabled' do + let(:image_ports) { true } + + describe '#valid?' do + it 'is valid' do + expect(entry).to be_valid + end + end + + describe '#value' do + it 'returns valid array' do + expect(entry.value).to eq([{ name: 'postgresql:9.5' }, { name: 'postgresql:9.1', alias: 'postgres_old', ports: ports }]) + end + end + + describe 'services alias' do + context 'when they are not unique' do + let(:config) do + ['postgresql:9.5', + { name: 'postgresql:9.1', alias: 'postgres_old', ports: [80] }, + { name: 'ruby', alias: 'postgres_old', ports: [81] }] + end + + describe '#valid?' do + it 'is invalid' do + expect(entry).not_to be_valid + expect(entry.errors).to include("services config alias must be unique in services with ports") + end + end + end + + context 'when they are unique' do + let(:config) do + ['postgresql:9.5', + { name: 'postgresql:9.1', alias: 'postgres_old', ports: [80] }, + { name: 'ruby', alias: 'ruby', ports: [81] }] + end + + describe '#valid?' do + it 'is valid' do + expect(entry).to be_valid + end + end + end + + context 'when one of the duplicated alias is in a service without ports' do + let(:config) do + ['postgresql:9.5', + { name: 'postgresql:9.1', alias: 'postgres_old', ports: [80] }, + { name: 'ruby', alias: 'postgres_old' }] + end + + it 'is valid' do + expect(entry).to be_valid + end + end + + context 'when there are not any ports' do + let(:config) do + ['postgresql:9.5', + { name: 'postgresql:9.1', alias: 'postgres_old' }, + { name: 'ruby', alias: 'postgres_old' }] + end + + it 'is valid' do + expect(entry).to be_valid + end + end + end + end + end end diff --git a/spec/lib/gitlab/ci/config_spec.rb b/spec/lib/gitlab/ci/config_spec.rb index 18f255c1ab7..00b2753c5fc 100644 --- a/spec/lib/gitlab/ci/config_spec.rb +++ b/spec/lib/gitlab/ci/config_spec.rb @@ -123,6 +123,63 @@ describe Gitlab::Ci::Config do ) end end + + context 'when ports have been set' do + context 'in the main image' do + let(:yml) do + <<-EOS + image: + name: ruby:2.2 + ports: + - 80 + EOS + end + + it 'raises an error' do + expect(config.errors).to include("image config contains disallowed keys: ports") + end + end + + context 'in the job image' do + let(:yml) do + <<-EOS + image: ruby:2.2 + + test: + script: rspec + image: + name: ruby:2.2 + ports: + - 80 + EOS + end + + it 'raises an error' do + expect(config.errors).to include("jobs:test:image config contains disallowed keys: ports") + end + end + + context 'in the services' do + let(:yml) do + <<-EOS + image: ruby:2.2 + + test: + script: rspec + image: ruby:2.2 + services: + - name: test + alias: test + ports: + - 80 + EOS + end + + it 'raises an error' do + expect(config.errors).to include("jobs:test:services:service config contains disallowed keys: ports") + end + end + end end context "when using 'include' directive" do diff --git a/spec/lib/gitlab/ci/yaml_processor_spec.rb b/spec/lib/gitlab/ci/yaml_processor_spec.rb index 29638ef47c5..63a0d54dcfc 100644 --- a/spec/lib/gitlab/ci/yaml_processor_spec.rb +++ b/spec/lib/gitlab/ci/yaml_processor_spec.rb @@ -1233,7 +1233,7 @@ module Gitlab config = YAML.dump({ services: [10, "test"], rspec: { script: "test" } }) expect do Gitlab::Ci::YamlProcessor.new(config) - end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, "service config should be a hash or a string") + end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, "services:service config should be a hash or a string") end it "returns errors if job services parameter is not an array" do @@ -1247,7 +1247,7 @@ module Gitlab config = YAML.dump({ rspec: { script: "test", services: [10, "test"] } }) expect do Gitlab::Ci::YamlProcessor.new(config) - end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, "service config should be a hash or a string") + end.to raise_error(Gitlab::Ci::YamlProcessor::ValidationError, "jobs:rspec:services:service config should be a hash or a string") end it "returns error if job configuration is invalid" do diff --git a/spec/requests/api/runner_spec.rb b/spec/requests/api/runner_spec.rb index 3ccedd8dd06..5fdc7c64030 100644 --- a/spec/requests/api/runner_spec.rb +++ b/spec/requests/api/runner_spec.rb @@ -470,11 +470,11 @@ describe API::Runner, :clean_gitlab_redis_shared_state do expect(json_response['token']).to eq(job.token) expect(json_response['job_info']).to eq(expected_job_info) expect(json_response['git_info']).to eq(expected_git_info) - expect(json_response['image']).to eq({ 'name' => 'ruby:2.1', 'entrypoint' => '/bin/sh' }) + expect(json_response['image']).to eq({ 'name' => 'ruby:2.1', 'entrypoint' => '/bin/sh', 'ports' => [] }) expect(json_response['services']).to eq([{ 'name' => 'postgres', 'entrypoint' => nil, - 'alias' => nil, 'command' => nil }, + 'alias' => nil, 'command' => nil, 'ports' => [] }, { 'name' => 'docker:stable-dind', 'entrypoint' => '/bin/sh', - 'alias' => 'docker', 'command' => 'sleep 30' }]) + 'alias' => 'docker', 'command' => 'sleep 30', 'ports' => [] }]) expect(json_response['steps']).to eq(expected_steps) expect(json_response['artifacts']).to eq(expected_artifacts) expect(json_response['cache']).to eq(expected_cache) @@ -853,6 +853,56 @@ describe API::Runner, :clean_gitlab_redis_shared_state do end end + describe 'port support' do + let(:job) { create(:ci_build, pipeline: pipeline, options: options) } + + context 'when job image has ports' do + let(:options) do + { + image: { + name: 'ruby', + ports: [80] + }, + services: ['mysql'] + } + end + + it 'returns the image ports' do + request_job + + expect(response).to have_http_status(:created) + expect(json_response).to include( + 'id' => job.id, + 'image' => a_hash_including('name' => 'ruby', 'ports' => [{ 'number' => 80, 'protocol' => 'http', 'name' => 'default_port' }]), + 'services' => all(a_hash_including('name' => 'mysql'))) + end + end + + context 'when job services settings has ports' do + let(:options) do + { + image: 'ruby', + services: [ + { + name: 'tomcat', + ports: [{ number: 8081, protocol: 'http', name: 'custom_port' }] + } + ] + } + end + + it 'returns the service ports' do + request_job + + expect(response).to have_http_status(:created) + expect(json_response).to include( + 'id' => job.id, + 'image' => a_hash_including('name' => 'ruby'), + 'services' => all(a_hash_including('name' => 'tomcat', 'ports' => [{ 'number' => 8081, 'protocol' => 'http', 'name' => 'custom_port' }]))) + end + end + end + def request_job(token = runner.token, **params) new_params = params.merge(token: token, last_update: last_update) post api('/jobs/request'), params: new_params, headers: { 'User-Agent' => user_agent } diff --git a/spec/services/ci/create_pipeline_service_spec.rb b/spec/services/ci/create_pipeline_service_spec.rb index 24707cd2d41..866d709d446 100644 --- a/spec/services/ci/create_pipeline_service_spec.rb +++ b/spec/services/ci/create_pipeline_service_spec.rb @@ -306,6 +306,56 @@ describe Ci::CreatePipelineService do it_behaves_like 'a failed pipeline' end + + context 'when config has ports' do + context 'in the main image' do + let(:ci_yaml) do + <<-EOS + image: + name: ruby:2.2 + ports: + - 80 + EOS + end + + it_behaves_like 'a failed pipeline' + end + + context 'in the job image' do + let(:ci_yaml) do + <<-EOS + image: ruby:2.2 + + test: + script: rspec + image: + name: ruby:2.2 + ports: + - 80 + EOS + end + + it_behaves_like 'a failed pipeline' + end + + context 'in the service' do + let(:ci_yaml) do + <<-EOS + image: ruby:2.2 + + test: + script: rspec + image: ruby:2.2 + services: + - name: test + ports: + - 80 + EOS + end + + it_behaves_like 'a failed pipeline' + end + end end context 'when commit contains a [ci skip] directive' do -- cgit v1.2.1 From ebbcc17f243337581536bd1f34dc7d6b5712ebb9 Mon Sep 17 00:00:00 2001 From: Kieran Andrews Date: Wed, 3 Apr 2019 11:38:46 +0000 Subject: Merge branch 'feature/webide_escaping' of gitlab.com:hiddentiger/gitlab-ce into feature/webide_escaping --- app/assets/javascripts/ide/lib/files.js | 6 ++++-- app/helpers/blob_helper.rb | 6 +++++- changelogs/unreleased/feature-webide_escaping.yml | 5 +++++ spec/frontend/ide/lib/files_spec.js | 17 +++++++++-------- spec/helpers/blob_helper_spec.rb | 13 +++++++++++++ 5 files changed, 36 insertions(+), 11 deletions(-) create mode 100644 changelogs/unreleased/feature-webide_escaping.yml diff --git a/app/assets/javascripts/ide/lib/files.js b/app/assets/javascripts/ide/lib/files.js index 5dfba8fe531..df100f753d7 100644 --- a/app/assets/javascripts/ide/lib/files.js +++ b/app/assets/javascripts/ide/lib/files.js @@ -1,6 +1,8 @@ import { viewerInformationForPath } from '~/vue_shared/components/content_viewer/lib/viewer_utils'; import { decorateData, sortTree } from '../stores/utils'; +export const escapeFileUrl = fileUrl => encodeURIComponent(fileUrl).replace(/%2F/g, '/'); + export const splitParent = path => { const idx = path.lastIndexOf('/'); @@ -45,7 +47,7 @@ export const decorateFiles = ({ id: path, name, path, - url: `/${projectId}/tree/${branchId}/-/${path}/`, + url: `/${projectId}/tree/${branchId}/-/${escapeFileUrl(path)}/`, type: 'tree', parentTreeUrl: parentFolder ? parentFolder.url : `/${projectId}/tree/${branchId}/`, tempFile, @@ -81,7 +83,7 @@ export const decorateFiles = ({ id: path, name, path, - url: `/${projectId}/blob/${branchId}/-/${path}`, + url: `/${projectId}/blob/${branchId}/-/${escapeFileUrl(path)}`, type: 'blob', parentTreeUrl: fileFolder ? fileFolder.url : `/${projectId}/blob/${branchId}`, tempFile, diff --git a/app/helpers/blob_helper.rb b/app/helpers/blob_helper.rb index 3e1bb9af5cc..d6fff1c36da 100644 --- a/app/helpers/blob_helper.rb +++ b/app/helpers/blob_helper.rb @@ -19,10 +19,14 @@ module BlobHelper def ide_edit_path(project = @project, ref = @ref, path = @path, options = {}) segments = [ide_path, 'project', project.full_path, 'edit', ref] - segments.concat(['-', path]) if path.present? + segments.concat(['-', encode_ide_path(path)]) if path.present? File.join(segments) end + def encode_ide_path(path) + url_encode(path).gsub('%2F', '/') + end + def edit_blob_button(project = @project, ref = @ref, path = @path, options = {}) return unless blob = readable_blob(options, path, project, ref) diff --git a/changelogs/unreleased/feature-webide_escaping.yml b/changelogs/unreleased/feature-webide_escaping.yml new file mode 100644 index 00000000000..88fa1bd948e --- /dev/null +++ b/changelogs/unreleased/feature-webide_escaping.yml @@ -0,0 +1,5 @@ +--- +title: Fixed bug with hashes in urls in WebIDE +merge_request: 54376 +author: Kieran Andrews +type: fixed diff --git a/spec/frontend/ide/lib/files_spec.js b/spec/frontend/ide/lib/files_spec.js index fe791aa2b74..aa1fa0373db 100644 --- a/spec/frontend/ide/lib/files_spec.js +++ b/spec/frontend/ide/lib/files_spec.js @@ -1,5 +1,5 @@ import { viewerInformationForPath } from '~/vue_shared/components/content_viewer/lib/viewer_utils'; -import { decorateFiles, splitParent } from '~/ide/lib/files'; +import { decorateFiles, splitParent, escapeFileUrl } from '~/ide/lib/files'; import { decorateData } from '~/ide/stores/utils'; const TEST_BRANCH_ID = 'lorem-ipsum'; @@ -20,7 +20,7 @@ const createEntries = paths => { id: path, name, path, - url: createUrl(`/${TEST_PROJECT_ID}/${type}/${TEST_BRANCH_ID}/-/${path}`), + url: createUrl(`/${TEST_PROJECT_ID}/${type}/${TEST_BRANCH_ID}/-/${escapeFileUrl(path)}`), type, previewMode: viewerInformationForPath(path), parentPath: parent, @@ -28,7 +28,7 @@ const createEntries = paths => { ? parentEntry.url : createUrl(`/${TEST_PROJECT_ID}/${type}/${TEST_BRANCH_ID}`), }), - tree: children.map(childName => jasmine.objectContaining({ name: childName })), + tree: children.map(childName => expect.objectContaining({ name: childName })), }; return acc; @@ -36,10 +36,10 @@ const createEntries = paths => { const entries = paths.reduce(createEntry, {}); - // Wrap entries in jasmine.objectContaining. + // Wrap entries in expect.objectContaining. // We couldn't do this earlier because we still need to select properties from parent entries. return Object.keys(entries).reduce((acc, key) => { - acc[key] = jasmine.objectContaining(entries[key]); + acc[key] = expect.objectContaining(entries[key]); return acc; }, {}); @@ -47,13 +47,14 @@ const createEntries = paths => { describe('IDE lib decorate files', () => { it('creates entries and treeList', () => { - const data = ['app/assets/apples/foo.js', 'app/bugs.js', 'README.md']; + const data = ['app/assets/apples/foo.js', 'app/bugs.js', 'app/#weird#file?.txt', 'README.md']; const expectedEntries = createEntries([ - { path: 'app', type: 'tree', children: ['assets', 'bugs.js'] }, + { path: 'app', type: 'tree', children: ['assets', '#weird#file?.txt', 'bugs.js'] }, { path: 'app/assets', type: 'tree', children: ['apples'] }, { path: 'app/assets/apples', type: 'tree', children: ['foo.js'] }, { path: 'app/assets/apples/foo.js', type: 'blob', children: [] }, { path: 'app/bugs.js', type: 'blob', children: [] }, + { path: 'app/#weird#file?.txt', type: 'blob', children: [] }, { path: 'README.md', type: 'blob', children: [] }, ]); @@ -64,7 +65,7 @@ describe('IDE lib decorate files', () => { }); // Here we test the keys and then each key/value individually because `expect(entries).toEqual(expectedEntries)` - // was taking a very long time for some reason. Probably due to large objects and nested `jasmine.objectContaining`. + // was taking a very long time for some reason. Probably due to large objects and nested `expect.objectContaining`. const entryKeys = Object.keys(entries); expect(entryKeys).toEqual(Object.keys(expectedEntries)); diff --git a/spec/helpers/blob_helper_spec.rb b/spec/helpers/blob_helper_spec.rb index 2bc3933809f..6808ed86c9a 100644 --- a/spec/helpers/blob_helper_spec.rb +++ b/spec/helpers/blob_helper_spec.rb @@ -230,5 +230,18 @@ describe BlobHelper do expect(helper.ide_edit_path(project, "master", "")).to eq("/gitlab/-/ide/project/#{project.namespace.path}/#{project.path}/edit/master") end + + it 'escapes special characters' do + Rails.application.routes.default_url_options[:script_name] = nil + + expect(helper.ide_edit_path(project, "testing/#hashes", "readme.md#test")).to eq("/-/ide/project/#{project.namespace.path}/#{project.path}/edit/testing/#hashes/-/readme.md%23test") + expect(helper.ide_edit_path(project, "testing/#hashes", "src#/readme.md#test")).to eq("/-/ide/project/#{project.namespace.path}/#{project.path}/edit/testing/#hashes/-/src%23/readme.md%23test") + end + + it 'does not escape "/" character' do + Rails.application.routes.default_url_options[:script_name] = nil + + expect(helper.ide_edit_path(project, "testing/slashes", "readme.md/")).to eq("/-/ide/project/#{project.namespace.path}/#{project.path}/edit/testing/slashes/-/readme.md/") + end end end -- cgit v1.2.1 From 7c61fb036e768dd8ed622f3022560d4f851014ff Mon Sep 17 00:00:00 2001 From: ftab Date: Wed, 3 Apr 2019 12:29:22 +0000 Subject: MR image diff swipe view: Disable user-select on drag Fixes https://gitlab.com/gitlab-org/gitlab-ce/issues/59942 --- .../diff_viewer/viewers/image_diff/onion_skin_viewer.vue | 2 +- .../components/diff_viewer/viewers/image_diff/swipe_viewer.vue | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/vue_shared/components/diff_viewer/viewers/image_diff/onion_skin_viewer.vue b/app/assets/javascripts/vue_shared/components/diff_viewer/viewers/image_diff/onion_skin_viewer.vue index f085ef35ccc..b25aebd7c98 100644 --- a/app/assets/javascripts/vue_shared/components/diff_viewer/viewers/image_diff/onion_skin_viewer.vue +++ b/app/assets/javascripts/vue_shared/components/diff_viewer/viewers/image_diff/onion_skin_viewer.vue @@ -102,7 +102,7 @@ export default { :style="{ width: onionMaxPixelWidth, height: onionMaxPixelHeight, - 'user-select': dragging === true ? 'none' : '', + 'user-select': dragging ? 'none' : null, }" class="onion-skin-frame" > diff --git a/app/assets/javascripts/vue_shared/components/diff_viewer/viewers/image_diff/swipe_viewer.vue b/app/assets/javascripts/vue_shared/components/diff_viewer/viewers/image_diff/swipe_viewer.vue index 1c970b72a66..eddafc759a2 100644 --- a/app/assets/javascripts/vue_shared/components/diff_viewer/viewers/image_diff/swipe_viewer.vue +++ b/app/assets/javascripts/vue_shared/components/diff_viewer/viewers/image_diff/swipe_viewer.vue @@ -68,12 +68,10 @@ export default { }, startDrag() { this.dragging = true; - document.body.style.userSelect = 'none'; document.body.addEventListener('mousemove', this.dragMove); }, stopDrag() { this.dragging = false; - document.body.style.userSelect = ''; document.body.removeEventListener('mousemove', this.dragMove); }, prepareSwipe() { @@ -104,7 +102,13 @@ export default {