<commit_before>define [
	"base"
	"ide/pdfng/directives/pdfViewer"
	"text!libs/pdfListView/TextLayer.css"
	"text!libs/pdfListView/AnnotationsLayer.css"
	"text!libs/pdfListView/HighlightsLayer.css"
], (
	App
	pdfViewer
	textLayerCss
	annotationsLayerCss
	highlightsLayerCss
) ->
	if PDFJS?
		PDFJS.workerSrc = window.pdfJsWorkerPath

	style = $("<style/>")
	style.text(textLayerCss + "\n" + annotationsLayerCss + "\n" + highlightsLayerCss)
	$("body").append(style)

	App.directive "pdfng", ["$timeout", ($timeout) ->
		return {
			scope: {
					"pdfSrc": "="
					"highlights": "="
					"position": "="
					"dblClickCallback": "="
			}
			link: (scope, element, attrs) ->
				# pdfListView = new PDFListView element.find(".pdfjs-viewer")[0],
				#		textLayerBuilder: TextLayerBuilder
				#		annotationsLayerBuilder: AnnotationsLayerBuilder
				#		highlightsLayerBuilder: HighlightsLayerBuilder
				#		ondblclick: (e) -> onDoubleClick(e)
				#		# logLevel: PDFListView.Logger.DEBUG
				# pdfListView.listView.pageWidthOffset = 20
				# pdfListView.listView.pageHeightOffset = 20

				scope.loading = false
				scope.pleaseJumpTo = null
				scope.scale = null
				initializedPosition = false
				initializePosition = () ->
					return if initializedPosition
					initializedPosition = true

					if (scale = $.localStorage("pdf.scale"))?
						scope.scale = { scaleMode: scale.scaleMode, scale: +scale.scale}
					else
						scope.scale = { scaleMode: 'scale_mode_fit_width' }

					if (position = $.localStorage("pdf.position.#{attrs.key}"))
						scope.position = { page: +position.page, offset: { "top": +position.offset.top, "left": +position.offset.left } }

					#scope.position = pdfListView.getPdfPosition(true)

					$(window).unload () =>
						$.localStorage "pdf.scale", scope.scale
						$.localStorage "pdf.position.#{attrs.key}", scope.position

				flashControls = () ->
					scope.flashControls = true
					$timeout () ->
						scope.flashControls = false
					, 1000

				scope.$on 'pdfDoubleClick', (event, e) ->
					scope.dblClickCallback?(page: e.page - 1, offset: { top: e.y, left: e.x })

				scope.$watch "pdfSrc", (url) ->
					if url
						scope.loading = true
						# console.log 'pdfSrc =', url
						initializePosition()
						flashControls()
						scope.$broadcast 'layout-ready'
						# pdfListView<commit_msg>save the pdf state when the directive is destroyed<commit_after>define [
	"base"
	"ide/pdfng/directives/pdfViewer"
	"text!libs/pdfListView/TextLayer.css"
	"text!libs/pdfListView/AnnotationsLayer.css"
	"text!libs/pdfListView/HighlightsLayer.css"
], (
	App
	pdfViewer
	textLayerCss
	annotationsLayerCss
	highlightsLayerCss
) ->
	if PDFJS?
		PDFJS.workerSrc = window.pdfJsWorkerPath

	style = $("<style/>")
	style.text(textLayerCss + "\n" + annotationsLayerCss + "\n" + highlightsLayerCss)
	$("body").append(style)

	App.directive "pdfng", ["$timeout", ($timeout) ->
		return {
			scope: {
					"pdfSrc": "="
					"highlights": "="
					"position": "="
					"dblClickCallback": "="
			}
			link: (scope, element, attrs) ->
				# pdfListView = new PDFListView element.find(".pdfjs-viewer")[0],
				#		textLayerBuilder: TextLayerBuilder
				#		annotationsLayerBuilder: AnnotationsLayerBuilder
				#		highlightsLayerBuilder: HighlightsLayerBuilder
				#		ondblclick: (e) -> onDoubleClick(e)
				#		# logLevel: PDFListView.Logger.DEBUG
				# pdfListView.listView.pageWidthOffset = 20
				# pdfListView.listView.pageHeightOffset = 20

				scope.loading = false
				scope.pleaseJumpTo = null
				scope.scale = null
				initializedPosition = false
				initializePosition = () ->
					return if initializedPosition
					initializedPosition = true

					if (scale = $.localStorage("pdf.scale"))?
						scope.scale = { scaleMode: scale.scaleMode, scale: +scale.scale}
					else
						scope.scale = { scaleMode: 'scale_mode_fit_width' }

					if (position = $.localStorage("pdf.position.#{attrs.key}"))
						scope.position = { page: +position.page, offset: { "top": +position.offset.top, "left": +position.offset.left } }

					#scope.position = pdfListView.getPdfPosition(true)

					scope.$on "$destroy", () =>
						$.localStorage "pdf.scale", scope.scale
						$.localStorage "pdf.position.#{attrs.key}", scope.position

					$(window).unload () =>
						$.localStorage "pdf.scale", scope.scale
						$.localStorage "pdf.position.#{attrs.key}", scope.position

				flashControls = () ->
					scope.flashControls = true
					$timeout () ->
						scope.flashControls = false
					, 1000

				scope.$on 'pdfDoubleClick', (event, e) ->
					scope.dblClickCallback?(page: e.page - 1, offset: { top: e.y, left: e.x })

				scope.$watch "pdfSrc", (url) ->
					if url
						scope.loading = true
						# console.log 'pdfSrc =', url
						initializePosition()
						flashControls()
						scope.$broadcast 'layout-ready'
						# pdfListView
{'fraction_non_alphanumeric': 0.14506172839506173, 'fraction_numerical': 0.00411522633744856, 'mean_word_length': 3.2565674255691768, 'pattern_counts': {'":': 12, '<': 5, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '415584', 'n_tokens_mistral': 1980, 'n_tokens_neox': 1548, 'n_words': 287}